teodor-new-chat-ui 4.3.345 → 4.3.346
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/components/ui/resizable.d.ts +1 -1
- package/dist/context/reducers/MessageReducer.d.ts +1 -0
- package/dist/index.esm.js +4351 -4351
- package/dist/index.umd.js +46 -46
- package/dist/lib/index.d.ts +0 -1
- package/package.json +2 -1
- package/dist/context/hooks/useCheckpointMetadataCache.d.ts +0 -24
package/dist/index.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(Ce,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):(Ce=typeof globalThis<"u"?globalThis:Ce||self,w(Ce.NewChatUI={},Ce.React,Ce.LucideReact,Ce.reactSlot,Ce.classVarianceAuthority,Ce.clsx,Ce.tailwindMerge,Ce.ReactDOM))})(this,function(Ce,w,le,
|
|
1
|
+
(function(Ce,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):(Ce=typeof globalThis<"u"?globalThis:Ce||self,w(Ce.NewChatUI={},Ce.React,Ce.LucideReact,Ce.reactSlot,Ce.classVarianceAuthority,Ce.clsx,Ce.tailwindMerge,Ce.ReactDOM))})(this,function(Ce,w,le,Wn,po,Hh,Wh,Gs){"use strict";var ST=Object.defineProperty;var CT=(Ce,w,le)=>w in Ce?ST(Ce,w,{enumerable:!0,configurable:!0,writable:!0,value:le}):Ce[w]=le;var zh=(Ce,w,le)=>CT(Ce,typeof w!="symbol"?w+"":w,le);var Ys=typeof document<"u"?document.currentScript:null;function Wa(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 v=Wa(w),ho=Wa(Gs);var Xs={exports:{}},Nr={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* react-jsx-runtime.production.min.js
|
|
4
4
|
*
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var
|
|
9
|
+
*/var Va;function Vh(){if(Va)return Nr;Va=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,c){var d,f={},h=null,p=null;c!==void 0&&(h=""+c),l.key!==void 0&&(h=""+l.key),l.ref!==void 0&&(p=l.ref);for(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 Nr.Fragment=n,Nr.jsx=i,Nr.jsxs=i,Nr}var _r={};/**
|
|
10
10
|
* @license React
|
|
11
11
|
* react-jsx-runtime.development.js
|
|
12
12
|
*
|
|
@@ -14,33 +14,33 @@
|
|
|
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
|
|
17
|
+
*/var Ka;function Kh(){return Ka||(Ka=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"),c=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"),m=Symbol.iterator,g="@@iterator";function y(E){if(E===null||typeof E!="object")return null;var V=m&&E[m]||E[g];return typeof V=="function"?V:null}var x=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function b(E){{for(var V=arguments.length,ae=new Array(V>1?V-1:0),we=1;we<V;we++)ae[we-1]=arguments[we];S("error",E,ae)}}function S(E,V,ae){{var we=x.ReactDebugCurrentFrame,Ge=we.getStackAddendum();Ge!==""&&(V+="%s",ae=ae.concat([Ge]));var tt=ae.map(function(Fe){return String(Fe)});tt.unshift("Warning: "+V),Function.prototype.apply.call(console[E],console,tt)}}var k=!1,C=!1,T=!1,I=!1,A=!1,N;N=Symbol.for("react.module.reference");function L(E){return!!(typeof E=="string"||typeof E=="function"||E===r||E===s||A||E===o||E===c||E===d||I||E===p||k||C||T||typeof E=="object"&&E!==null&&(E.$$typeof===h||E.$$typeof===f||E.$$typeof===i||E.$$typeof===a||E.$$typeof===l||E.$$typeof===N||E.getModuleId!==void 0))}function R(E,V,ae){var we=E.displayName;if(we)return we;var Ge=V.displayName||V.name||"";return Ge!==""?ae+"("+Ge+")":ae}function O(E){return E.displayName||"Context"}function F(E){if(E==null)return null;if(typeof E.tag=="number"&&b("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof E=="function")return E.displayName||E.name||null;if(typeof E=="string")return E;switch(E){case r:return"Fragment";case n:return"Portal";case s:return"Profiler";case o:return"StrictMode";case c:return"Suspense";case d:return"SuspenseList"}if(typeof E=="object")switch(E.$$typeof){case a:var V=E;return O(V)+".Consumer";case i:var ae=E;return O(ae._context)+".Provider";case l:return R(E,E.render,"ForwardRef");case f:var we=E.displayName||null;return we!==null?we:F(E.type)||"Memo";case h:{var Ge=E,tt=Ge._payload,Fe=Ge._init;try{return F(Fe(tt))}catch{return null}}}return null}var _=Object.assign,B=0,j,K,z,M,G,X,se;function be(){}be.__reactDisabledLog=!0;function Ie(){{if(B===0){j=console.log,K=console.info,z=console.warn,M=console.error,G=console.group,X=console.groupCollapsed,se=console.groupEnd;var E={configurable:!0,enumerable:!0,value:be,writable:!0};Object.defineProperties(console,{info:E,log:E,warn:E,error:E,group:E,groupCollapsed:E,groupEnd:E})}B++}}function Y(){{if(B--,B===0){var E={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:_({},E,{value:j}),info:_({},E,{value:K}),warn:_({},E,{value:z}),error:_({},E,{value:M}),group:_({},E,{value:G}),groupCollapsed:_({},E,{value:X}),groupEnd:_({},E,{value:se})})}B<0&&b("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var U=x.ReactCurrentDispatcher,J;function $(E,V,ae){{if(J===void 0)try{throw Error()}catch(Ge){var we=Ge.stack.trim().match(/\n( *(at )?)/);J=we&&we[1]||""}return`
|
|
18
18
|
`+J+E}}var q=!1,Z;{var ue=typeof WeakMap=="function"?WeakMap:Map;Z=new ue}function ie(E,V){if(!E||q)return"";{var ae=Z.get(E);if(ae!==void 0)return ae}var we;q=!0;var Ge=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var tt;tt=U.current,U.current=null,Ie();try{if(V){var Fe=function(){throw Error()};if(Object.defineProperty(Fe.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(Fe,[])}catch(Ve){we=Ve}Reflect.construct(E,[],Fe)}else{try{Fe.call()}catch(Ve){we=Ve}E.call(Fe.prototype)}}else{try{throw Error()}catch(Ve){we=Ve}E()}}catch(Ve){if(Ve&&we&&typeof Ve.stack=="string"){for(var $e=Ve.stack.split(`
|
|
19
|
-
`),
|
|
20
|
-
`),pt=$e.length-1,xt=
|
|
21
|
-
`+$e[pt].replace(" at new "," at ");return E.displayName&&pe.includes("<anonymous>")&&(pe=pe.replace("<anonymous>",E.displayName)),typeof E=="function"&&Z.set(E,pe),pe}while(pt>=1&&xt>=0);break}}}finally{q=!1,U.current=tt,Y(),Error.prepareStackTrace=Ge}var Se=E?E.displayName||E.name:"",Ee=Se?$(Se):"";return typeof E=="function"&&Z.set(E,Ee),Ee}function _e(E,V,ae){return ie(E,!1)}function He(E){var V=E.prototype;return!!(V&&V.isReactComponent)}function oe(E,V,ae){if(E==null)return"";if(typeof E=="function")return ie(E,He(E));if(typeof E=="string")return $(E);switch(E){case c:return $("Suspense");case d:return $("SuspenseList")}if(typeof E=="object")switch(E.$$typeof){case l:return _e(E.render);case f:return oe(E.type,V,ae);case
|
|
19
|
+
`),It=we.stack.split(`
|
|
20
|
+
`),pt=$e.length-1,xt=It.length-1;pt>=1&&xt>=0&&$e[pt]!==It[xt];)xt--;for(;pt>=1&&xt>=0;pt--,xt--)if($e[pt]!==It[xt]){if(pt!==1||xt!==1)do if(pt--,xt--,xt<0||$e[pt]!==It[xt]){var pe=`
|
|
21
|
+
`+$e[pt].replace(" at new "," at ");return E.displayName&&pe.includes("<anonymous>")&&(pe=pe.replace("<anonymous>",E.displayName)),typeof E=="function"&&Z.set(E,pe),pe}while(pt>=1&&xt>=0);break}}}finally{q=!1,U.current=tt,Y(),Error.prepareStackTrace=Ge}var Se=E?E.displayName||E.name:"",Ee=Se?$(Se):"";return typeof E=="function"&&Z.set(E,Ee),Ee}function _e(E,V,ae){return ie(E,!1)}function He(E){var V=E.prototype;return!!(V&&V.isReactComponent)}function oe(E,V,ae){if(E==null)return"";if(typeof E=="function")return ie(E,He(E));if(typeof E=="string")return $(E);switch(E){case c:return $("Suspense");case d:return $("SuspenseList")}if(typeof E=="object")switch(E.$$typeof){case l:return _e(E.render);case f:return oe(E.type,V,ae);case h:{var we=E,Ge=we._payload,tt=we._init;try{return oe(tt(Ge),V,ae)}catch{}}}return""}var ye=Object.prototype.hasOwnProperty,Oe={},Ye=x.ReactDebugCurrentFrame;function nt(E){if(E){var V=E._owner,ae=oe(E.type,E._source,V?V.type:null);Ye.setExtraStackFrame(ae)}else Ye.setExtraStackFrame(null)}function Xe(E,V,ae,we,Ge){{var tt=Function.call.bind(ye);for(var Fe in E)if(tt(E,Fe)){var $e=void 0;try{if(typeof E[Fe]!="function"){var It=Error((we||"React class")+": "+ae+" type `"+Fe+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof E[Fe]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw It.name="Invariant Violation",It}$e=E[Fe](V,Fe,we,ae,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(pt){$e=pt}$e&&!($e instanceof Error)&&(nt(Ge),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).",we||"React class",ae,Fe,typeof $e),nt(null)),$e instanceof Error&&!($e.message in Oe)&&(Oe[$e.message]=!0,nt(Ge),b("Failed %s type: %s",ae,$e.message),nt(null))}}}var qe=Array.isArray;function it(E){return qe(E)}function Je(E){{var V=typeof Symbol=="function"&&Symbol.toStringTag,ae=V&&E[Symbol.toStringTag]||E.constructor.name||"Object";return ae}}function et(E){try{return at(E),!1}catch{return!0}}function at(E){return""+E}function jt(E){if(et(E))return b("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",Je(E)),at(E)}var ht=x.ReactCurrentOwner,ft={key:!0,ref:!0,__self:!0,__source:!0},mt,St;function Mt(E){if(ye.call(E,"ref")){var V=Object.getOwnPropertyDescriptor(E,"ref").get;if(V&&V.isReactWarning)return!1}return E.ref!==void 0}function Lt(E){if(ye.call(E,"key")){var V=Object.getOwnPropertyDescriptor(E,"key").get;if(V&&V.isReactWarning)return!1}return E.key!==void 0}function Vt(E,V){typeof E.ref=="string"&&ht.current}function Ue(E,V){{var ae=function(){mt||(mt=!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)",V))};ae.isReactWarning=!0,Object.defineProperty(E,"key",{get:ae,configurable:!0})}}function dn(E,V){{var ae=function(){St||(St=!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)",V))};ae.isReactWarning=!0,Object.defineProperty(E,"ref",{get:ae,configurable:!0})}}var rt=function(E,V,ae,we,Ge,tt,Fe){var $e={$$typeof:t,type:E,key:V,ref:ae,props:Fe,_owner:tt};return $e._store={},Object.defineProperty($e._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty($e,"_self",{configurable:!1,enumerable:!1,writable:!1,value:we}),Object.defineProperty($e,"_source",{configurable:!1,enumerable:!1,writable:!1,value:Ge}),Object.freeze&&(Object.freeze($e.props),Object.freeze($e)),$e};function We(E,V,ae,we,Ge){{var tt,Fe={},$e=null,It=null;ae!==void 0&&(jt(ae),$e=""+ae),Lt(V)&&(jt(V.key),$e=""+V.key),Mt(V)&&(It=V.ref,Vt(V,Ge));for(tt in V)ye.call(V,tt)&&!ft.hasOwnProperty(tt)&&(Fe[tt]=V[tt]);if(E&&E.defaultProps){var pt=E.defaultProps;for(tt in pt)Fe[tt]===void 0&&(Fe[tt]=pt[tt])}if($e||It){var xt=typeof E=="function"?E.displayName||E.name||"Unknown":E;$e&&Ue(Fe,xt),It&&dn(Fe,xt)}return rt(E,$e,It,Ge,we,ht.current,Fe)}}var gt=x.ReactCurrentOwner,Rt=x.ReactDebugCurrentFrame;function H(E){if(E){var V=E._owner,ae=oe(E.type,E._source,V?V.type:null);Rt.setExtraStackFrame(ae)}else Rt.setExtraStackFrame(null)}var re;re=!1;function D(E){return typeof E=="object"&&E!==null&&E.$$typeof===t}function Q(){{if(gt.current){var E=F(gt.current.type);if(E)return`
|
|
22
22
|
|
|
23
23
|
Check the render method of \``+E+"`."}return""}}function ne(E){return""}var me={};function xe(E){{var V=Q();if(!V){var ae=typeof E=="string"?E:E.displayName||E.name;ae&&(V=`
|
|
24
24
|
|
|
25
|
-
Check the top-level render call using <`+ae+">.")}return V}}function De(E,V){{if(!E._store||E._store.validated||E.key!=null)return;E._store.validated=!0;var ae=xe(V);if(me[ae])return;me[ae]=!0;var we="";E&&E._owner&&E._owner!==gt.current&&(we=" It was passed a child from "+F(E._owner.type)+"."),H(E),b('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',ae,we),H(null)}}function Re(E,V){{if(typeof E!="object")return;if(it(E))for(var ae=0;ae<E.length;ae++){var we=E[ae];D(we)&&De(we,V)}else if(D(E))E._store&&(E._store.validated=!0);else if(E){var Ge=y(E);if(typeof Ge=="function"&&Ge!==E.entries)for(var tt=Ge.call(E),Fe;!(Fe=tt.next()).done;)D(Fe.value)&&De(Fe.value,V)}}}function je(E){{var V=E.type;if(V==null||typeof V=="string")return;var ae;if(typeof V=="function")ae=V.propTypes;else if(typeof V=="object"&&(V.$$typeof===l||V.$$typeof===f))ae=V.propTypes;else return;if(ae){var we=F(V);Xe(ae,E.props,"prop",we,E)}else if(V.PropTypes!==void 0&&!re){re=!0;var Ge=F(V);b("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",Ge||"Unknown")}typeof V.getDefaultProps=="function"&&!V.getDefaultProps.isReactClassApproved&&b("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function
|
|
25
|
+
Check the top-level render call using <`+ae+">.")}return V}}function De(E,V){{if(!E._store||E._store.validated||E.key!=null)return;E._store.validated=!0;var ae=xe(V);if(me[ae])return;me[ae]=!0;var we="";E&&E._owner&&E._owner!==gt.current&&(we=" It was passed a child from "+F(E._owner.type)+"."),H(E),b('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',ae,we),H(null)}}function Re(E,V){{if(typeof E!="object")return;if(it(E))for(var ae=0;ae<E.length;ae++){var we=E[ae];D(we)&&De(we,V)}else if(D(E))E._store&&(E._store.validated=!0);else if(E){var Ge=y(E);if(typeof Ge=="function"&&Ge!==E.entries)for(var tt=Ge.call(E),Fe;!(Fe=tt.next()).done;)D(Fe.value)&&De(Fe.value,V)}}}function je(E){{var V=E.type;if(V==null||typeof V=="string")return;var ae;if(typeof V=="function")ae=V.propTypes;else if(typeof V=="object"&&(V.$$typeof===l||V.$$typeof===f))ae=V.propTypes;else return;if(ae){var we=F(V);Xe(ae,E.props,"prop",we,E)}else if(V.PropTypes!==void 0&&!re){re=!0;var Ge=F(V);b("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",Ge||"Unknown")}typeof V.getDefaultProps=="function"&&!V.getDefaultProps.isReactClassApproved&&b("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function Kt(E){{for(var V=Object.keys(E.props),ae=0;ae<V.length;ae++){var we=V[ae];if(we!=="children"&&we!=="key"){H(E),b("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",we),H(null);break}}E.ref!==null&&(H(E),b("Invalid attribute `ref` supplied to `React.Fragment`."),H(null))}}var An={};function ar(E,V,ae,we,Ge,tt){{var Fe=L(E);if(!Fe){var $e="";(E===void 0||typeof E=="object"&&E!==null&&Object.keys(E).length===0)&&($e+=" 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 It=ne();It?$e+=It:$e+=Q();var pt;E===null?pt="null":it(E)?pt="array":E!==void 0&&E.$$typeof===t?(pt="<"+(F(E.type)||"Unknown")+" />",$e=" Did you accidentally export a JSX literal instead of a component?"):pt=typeof E,b("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",pt,$e)}var xt=We(E,V,ae,Ge,tt);if(xt==null)return xt;if(Fe){var pe=V.children;if(pe!==void 0)if(we)if(it(pe)){for(var Se=0;Se<pe.length;Se++)Re(pe[Se],E);Object.freeze&&Object.freeze(pe)}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 Re(pe,E)}if(ye.call(V,"key")){var Ee=F(E),Ve=Object.keys(V).filter(function(wT){return wT!=="key"}),Hn=Ve.length>0?"{key: someKey, "+Ve.join(": ..., ")+": ...}":"{key: someKey}";if(!An[Ee+Hn]){var nn=Ve.length>0?"{"+Ve.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} />`,Un,Ee,tn,Ee),En[Ee+Un]=!0}}return E===r?Vt(xt):je(xt),xt}}function Er(E,V,ae){return ir(E,V,ae,!0)}function fo(E,V,ae){return ir(E,V,ae,!1)}var zn=fo,ar=Er;Nr.Fragment=r,Nr.jsx=zn,Nr.jsxs=ar}()),Nr}process.env.NODE_ENV==="production"?Ys.exports=Wh():Ys.exports=Vh();var u=Ys.exports;function Ga(e,t){return function(){return e.apply(t,arguments)}}const{toString:Kh}=Object.prototype,{getPrototypeOf:Xs}=Object,{iterator:mo,toStringTag:Ya}=Symbol,go=(e=>t=>{const n=Kh.call(t);return e[n]||(e[n]=n.slice(8,-1).toLowerCase())})(Object.create(null)),nn=e=>(e=e.toLowerCase(),t=>go(t)===e),xo=e=>t=>typeof t===e,{isArray:lr}=Array,cr=xo("undefined");function _r(e){return e!==null&&!cr(e)&&e.constructor!==null&&!cr(e.constructor)&&Lt(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const Xa=nn("ArrayBuffer");function qh(e){let t;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?t=ArrayBuffer.isView(e):t=e&&e.buffer&&Xa(e.buffer),t}const Gh=xo("string"),Lt=xo("function"),Ja=xo("number"),jr=e=>e!==null&&typeof e=="object",Yh=e=>e===!0||e===!1,yo=e=>{if(go(e)!=="object")return!1;const t=Xs(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Ya in e)&&!(mo in e)},Xh=e=>{if(!jr(e)||_r(e))return!1;try{return Object.keys(e).length===0&&Object.getPrototypeOf(e)===Object.prototype}catch{return!1}},Jh=nn("Date"),Zh=nn("File"),Qh=nn("Blob"),em=nn("FileList"),tm=e=>jr(e)&&Lt(e.pipe),nm=e=>{let t;return e&&(typeof FormData=="function"&&e instanceof FormData||Lt(e.append)&&((t=go(e))==="formdata"||t==="object"&&Lt(e.toString)&&e.toString()==="[object FormData]"))},rm=nn("URLSearchParams"),[om,sm,im,am]=["ReadableStream","Request","Response","Headers"].map(nn),lm=e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function Mr(e,t,{allOwnKeys:n=!1}={}){if(e===null||typeof e>"u")return;let r,o;if(typeof e!="object"&&(e=[e]),lr(e))for(r=0,o=e.length;r<o;r++)t.call(null,e[r],r,e);else{if(_r(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 Za(e,t){if(_r(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 Wn=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global,Qa=e=>!cr(e)&&e!==Wn;function Js(){const{caseless:e,skipUndefined:t}=Qa(this)&&this||{},n={},r=(o,s)=>{const i=e&&Za(n,s)||s;yo(n[i])&&yo(o)?n[i]=Js(n[i],o):yo(o)?n[i]=Js({},o):lr(o)?n[i]=o.slice():(!t||!cr(o))&&(n[i]=o)};for(let o=0,s=arguments.length;o<s;o++)arguments[o]&&Mr(arguments[o],r);return n}const cm=(e,t,n,{allOwnKeys:r}={})=>(Mr(t,(o,s)=>{n&&Lt(o)?e[s]=Ga(o,n):e[s]=o},{allOwnKeys:r}),e),um=e=>(e.charCodeAt(0)===65279&&(e=e.slice(1)),e),dm=(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)},fm=(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&&Xs(e)}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},pm=(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},hm=e=>{if(!e)return null;if(lr(e))return e;let t=e.length;if(!Ja(t))return null;const n=new Array(t);for(;t-- >0;)n[t]=e[t];return n},mm=(e=>t=>e&&t instanceof e)(typeof Uint8Array<"u"&&Xs(Uint8Array)),gm=(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])}},xm=(e,t)=>{let n;const r=[];for(;(n=e.exec(t))!==null;)r.push(n);return r},ym=nn("HTMLFormElement"),vm=e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(n,r,o){return r.toUpperCase()+o}),el=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),bm=nn("RegExp"),tl=(e,t)=>{const n=Object.getOwnPropertyDescriptors(e),r={};Mr(n,(o,s)=>{let i;(i=t(o,s,e))!==!1&&(r[s]=i||o)}),Object.defineProperties(e,r)},wm=e=>{tl(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+"'")})}})},Sm=(e,t)=>{const n={},r=o=>{o.forEach(s=>{n[s]=!0})};return lr(e)?r(e):r(String(e).split(t)),n},Cm=()=>{},Tm=(e,t)=>e!=null&&Number.isFinite(e=+e)?e:t;function km(e){return!!(e&&Lt(e.append)&&e[Ya]==="FormData"&&e[mo])}const Im=e=>{const t=new Array(10),n=(r,o)=>{if(jr(r)){if(t.indexOf(r)>=0)return;if(_r(r))return r;if(!("toJSON"in r)){t[o]=r;const s=lr(r)?[]:{};return Mr(r,(i,a)=>{const l=n(i,o+1);!cr(l)&&(s[a]=l)}),t[o]=void 0,s}}return r};return n(e,0)},Em=nn("AsyncFunction"),Am=e=>e&&(jr(e)||Lt(e))&&Lt(e.then)&&Lt(e.catch),nl=((e,t)=>e?setImmediate:t?((n,r)=>(Wn.addEventListener("message",({source:o,data:s})=>{o===Wn&&s===n&&r.length&&r.shift()()},!1),o=>{r.push(o),Wn.postMessage(n,"*")}))(`axios@${Math.random()}`,[]):n=>setTimeout(n))(typeof setImmediate=="function",Lt(Wn.postMessage)),Nm=typeof queueMicrotask<"u"?queueMicrotask.bind(Wn):typeof process<"u"&&process.nextTick||nl,P={isArray:lr,isArrayBuffer:Xa,isBuffer:_r,isFormData:nm,isArrayBufferView:qh,isString:Gh,isNumber:Ja,isBoolean:Yh,isObject:jr,isPlainObject:yo,isEmptyObject:Xh,isReadableStream:om,isRequest:sm,isResponse:im,isHeaders:am,isUndefined:cr,isDate:Jh,isFile:Zh,isBlob:Qh,isRegExp:bm,isFunction:Lt,isStream:tm,isURLSearchParams:rm,isTypedArray:mm,isFileList:em,forEach:Mr,merge:Js,extend:cm,trim:lm,stripBOM:um,inherits:dm,toFlatObject:fm,kindOf:go,kindOfTest:nn,endsWith:pm,toArray:hm,forEachEntry:gm,matchAll:xm,isHTMLForm:ym,hasOwnProperty:el,hasOwnProp:el,reduceDescriptors:tl,freezeMethods:wm,toObjectSet:Sm,toCamelCase:vm,noop:Cm,toFiniteNumber:Tm,findKey:Za,global:Wn,isContextDefined:Qa,isSpecCompliantForm:km,toJSONObject:Im,isAsyncFn:Em,isThenable:Am,setImmediate:nl,asap:Nm,isIterable:e=>e!=null&&Lt(e[mo])};function Me(e,t,n,r,o){Error.call(this),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=new Error().stack,this.message=e,this.name="AxiosError",t&&(this.code=t),n&&(this.config=n),r&&(this.request=r),o&&(this.response=o,this.status=o.status?o.status:null)}P.inherits(Me,Error,{toJSON:function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:P.toJSONObject(this.config),code:this.code,status:this.status}}});const rl=Me.prototype,ol={};["ERR_BAD_OPTION_VALUE","ERR_BAD_OPTION","ECONNABORTED","ETIMEDOUT","ERR_NETWORK","ERR_FR_TOO_MANY_REDIRECTS","ERR_DEPRECATED","ERR_BAD_RESPONSE","ERR_BAD_REQUEST","ERR_CANCELED","ERR_NOT_SUPPORT","ERR_INVALID_URL"].forEach(e=>{ol[e]={value:e}}),Object.defineProperties(Me,ol),Object.defineProperty(rl,"isAxiosError",{value:!0}),Me.from=(e,t,n,r,o,s)=>{const i=Object.create(rl);P.toFlatObject(e,i,function(d){return d!==Error.prototype},c=>c!=="isAxiosError");const a=e&&e.message?e.message:"Error",l=t==null&&e?e.code:t;return Me.call(i,a,l,n,r,o),e&&i.cause==null&&Object.defineProperty(i,"cause",{value:e,configurable:!0}),i.name=e&&e.name||"Error",s&&Object.assign(i,s),i};const _m=null;function Zs(e){return P.isPlainObject(e)||P.isArray(e)}function sl(e){return P.endsWith(e,"[]")?e.slice(0,-2):e}function il(e,t,n){return e?e.concat(t).map(function(o,s){return o=sl(o),!n&&s?"["+o+"]":o}).join(n?".":""):t}function jm(e){return P.isArray(e)&&!e.some(Zs)}const Mm=P.toFlatObject(P,{},null,function(t){return/^is[A-Z]/.test(t)});function vo(e,t,n){if(!P.isObject(e))throw new TypeError("target must be an object");t=t||new FormData,n=P.toFlatObject(n,{metaTokens:!0,dots:!1,indexes:!1},!1,function(g,y){return!P.isUndefined(y[g])});const r=n.metaTokens,o=n.visitor||d,s=n.dots,i=n.indexes,l=(n.Blob||typeof Blob<"u"&&Blob)&&P.isSpecCompliantForm(t);if(!P.isFunction(o))throw new TypeError("visitor must be a function");function c(m){if(m===null)return"";if(P.isDate(m))return m.toISOString();if(P.isBoolean(m))return m.toString();if(!l&&P.isBlob(m))throw new Me("Blob is not supported. Use a Buffer instead.");return P.isArrayBuffer(m)||P.isTypedArray(m)?l&&typeof Blob=="function"?new Blob([m]):Buffer.from(m):m}function d(m,g,y){let x=m;if(m&&!y&&typeof m=="object"){if(P.endsWith(g,"{}"))g=r?g:g.slice(0,-2),m=JSON.stringify(m);else if(P.isArray(m)&&jm(m)||(P.isFileList(m)||P.endsWith(g,"[]"))&&(x=P.toArray(m)))return g=sl(g),x.forEach(function(C,k){!(P.isUndefined(C)||C===null)&&t.append(i===!0?il([g],k,s):i===null?g:g+"[]",c(C))}),!1}return Zs(m)?!0:(t.append(il(y,g,s),c(m)),!1)}const f=[],p=Object.assign(Mm,{defaultVisitor:d,convertValue:c,isVisitable:Zs});function h(m,g){if(!P.isUndefined(m)){if(f.indexOf(m)!==-1)throw Error("Circular reference detected in "+g.join("."));f.push(m),P.forEach(m,function(x,b){(!(P.isUndefined(x)||x===null)&&o.call(t,x,P.isString(b)?b.trim():b,g,p))===!0&&h(x,g?g.concat(b):[b])}),f.pop()}}if(!P.isObject(e))throw new TypeError("data must be an object");return h(e),t}function al(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,function(r){return t[r]})}function Qs(e,t){this._pairs=[],e&&vo(e,this,t)}const ll=Qs.prototype;ll.append=function(t,n){this._pairs.push([t,n])},ll.toString=function(t){const n=t?function(r){return t.call(this,r,al)}:al;return this._pairs.map(function(o){return n(o[0])+"="+n(o[1])},"").join("&")};function Rm(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+")}function cl(e,t,n){if(!t)return e;const r=n&&n.encode||Rm;P.isFunction(n)&&(n={serialize:n});const o=n&&n.serialize;let s;if(o?s=o(t,n):s=P.isURLSearchParams(t)?t.toString():new Qs(t,n).toString(r),s){const i=e.indexOf("#");i!==-1&&(e=e.slice(0,i)),e+=(e.indexOf("?")===-1?"?":"&")+s}return e}class 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){P.forEach(this.handlers,function(r){r!==null&&t(r)})}}const dl={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},Pm={isBrowser:!0,classes:{URLSearchParams:typeof URLSearchParams<"u"?URLSearchParams:Qs,FormData:typeof FormData<"u"?FormData:null,Blob:typeof Blob<"u"?Blob:null},protocols:["http","https","file","blob","url","data"]},ei=typeof window<"u"&&typeof document<"u",ti=typeof navigator=="object"&&navigator||void 0,Om=ei&&(!ti||["ReactNative","NativeScript","NS"].indexOf(ti.product)<0),Dm=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function",Lm=ei&&window.location.href||"http://localhost",It={...Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv:ei,hasStandardBrowserEnv:Om,hasStandardBrowserWebWorkerEnv:Dm,navigator:ti,origin:Lm},Symbol.toStringTag,{value:"Module"})),...Pm};function $m(e,t){return vo(e,new It.classes.URLSearchParams,{visitor:function(n,r,o,s){return It.isNode&&P.isBuffer(n)?(this.append(r,n.toString("base64")),!1):s.defaultVisitor.apply(this,arguments)},...t})}function Fm(e){return P.matchAll(/\w+|\[(\w*)]/g,e).map(t=>t[0]==="[]"?"":t[1]||t[0])}function Bm(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 fl(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&&P.isArray(o)?o.length:i,l?(P.hasOwnProp(o,i)?o[i]=[o[i],r]:o[i]=r,!a):((!o[i]||!P.isObject(o[i]))&&(o[i]=[]),t(n,r,o[i],s)&&P.isArray(o[i])&&(o[i]=Bm(o[i])),!a)}if(P.isFormData(e)&&P.isFunction(e.entries)){const n={};return P.forEachEntry(e,(r,o)=>{t(Fm(r),o,n,0)}),n}return null}function zm(e,t,n){if(P.isString(e))try{return(t||JSON.parse)(e),P.trim(e)}catch(r){if(r.name!=="SyntaxError")throw r}return(n||JSON.stringify)(e)}const Rr={transitional:dl,adapter:["xhr","http","fetch"],transformRequest:[function(t,n){const r=n.getContentType()||"",o=r.indexOf("application/json")>-1,s=P.isObject(t);if(s&&P.isHTMLForm(t)&&(t=new FormData(t)),P.isFormData(t))return o?JSON.stringify(fl(t)):t;if(P.isArrayBuffer(t)||P.isBuffer(t)||P.isStream(t)||P.isFile(t)||P.isBlob(t)||P.isReadableStream(t))return t;if(P.isArrayBufferView(t))return t.buffer;if(P.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 $m(t,this.formSerializer).toString();if((a=P.isFileList(t))||r.indexOf("multipart/form-data")>-1){const l=this.env&&this.env.FormData;return vo(a?{"files[]":t}:t,l&&new l,this.formSerializer)}}return s||o?(n.setContentType("application/json",!1),zm(t)):t}],transformResponse:[function(t){const n=this.transitional||Rr.transitional,r=n&&n.forcedJSONParsing,o=this.responseType==="json";if(P.isResponse(t)||P.isReadableStream(t))return t;if(t&&P.isString(t)&&(r&&!this.responseType||o)){const i=!(n&&n.silentJSONParsing)&&o;try{return JSON.parse(t,this.parseReviver)}catch(a){if(i)throw a.name==="SyntaxError"?Me.from(a,Me.ERR_BAD_RESPONSE,this,null,this.response):a}}return t}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:It.classes.FormData,Blob:It.classes.Blob},validateStatus:function(t){return t>=200&&t<300},headers:{common:{Accept:"application/json, text/plain, */*","Content-Type":void 0}}};P.forEach(["delete","get","head","post","put","patch"],e=>{Rr.headers[e]={}});const Um=P.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"]),Hm=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]&&
|
|
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[pl]=this[pl]={accessors:{}}).accessors,o=this.prototype;function s(i){const a=Pr(i);r[a]||(qm(o,i),r[a]=!0)}return P.isArray(t)?t.forEach(s):s(t),this}};$t.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),P.reduceDescriptors($t.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(r){this[n]=r}}}),P.freezeMethods($t);function ri(e,t){const n=this||Rr,r=t||n,o=$t.from(r.headers);let s=r.data;return P.forEach(e,function(a){s=a.call(n,s,o.normalize(),t?t.status:void 0)}),o.normalize(),s}function hl(e){return!!(e&&e.__CANCEL__)}function ur(e,t,n){Me.call(this,e??"canceled",Me.ERR_CANCELED,t,n),this.name="CanceledError"}P.inherits(ur,Me,{__CANCEL__:!0});function ml(e,t,n){const r=n.config.validateStatus;!n.status||!r||r(n.status)?e(n):t(new Me("Request failed with status code "+n.status,[Me.ERR_BAD_REQUEST,Me.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n))}function Gm(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function Ym(e,t){e=e||10;const n=new Array(e),r=new Array(e);let o=0,s=0,i;return t=t!==void 0?t:1e3,function(l){const c=Date.now(),d=r[s];i||(i=c),n[o]=l,r[o]=c;let f=s,p=0;for(;f!==o;)p+=n[f++],f=f%e;if(o=(o+1)%e,o===s&&(s=(s+1)%e),c-i<t)return;const h=d&&c-d;return h?Math.round(p*1e3/h):void 0}}function Xm(e,t){let n=0,r=1e3/t,o,s;const i=(c,d=Date.now())=>{n=d,o=null,s&&(clearTimeout(s),s=null),e(...c)};return[(...c)=>{const d=Date.now(),f=d-n;f>=r?i(c,d):(o=c,s||(s=setTimeout(()=>{s=null,i(o)},r-f)))},()=>o&&i(o)]}const wo=(e,t,n=3)=>{let r=0;const o=Ym(50,250);return Xm(s=>{const i=s.loaded,a=s.lengthComputable?s.total:void 0,l=i-r,c=o(l),d=i<=a;r=i;const f={loaded:i,total:a,progress:a?i/a:void 0,bytes:l,rate:c||void 0,estimated:c&&a&&d?(a-i)/c:void 0,event:s,lengthComputable:a!=null,[t?"download":"upload"]:!0};e(f)},n)},gl=(e,t)=>{const n=e!=null;return[r=>t[0]({lengthComputable:n,total:e,loaded:r}),t[1]]},xl=e=>(...t)=>P.asap(()=>e(...t)),Jm=It.hasStandardBrowserEnv?((e,t)=>n=>(n=new URL(n,It.origin),e.protocol===n.protocol&&e.host===n.host&&(t||e.port===n.port)))(new URL(It.origin),It.navigator&&/(msie|trident)/i.test(It.navigator.userAgent)):()=>!0,Zm=It.hasStandardBrowserEnv?{write(e,t,n,r,o,s){const i=[e+"="+encodeURIComponent(t)];P.isNumber(n)&&i.push("expires="+new Date(n).toGMTString()),P.isString(r)&&i.push("path="+r),P.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 Qm(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function eg(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function yl(e,t,n){let r=!Qm(t);return e&&(r||n==!1)?eg(e,t):t}const vl=e=>e instanceof $t?{...e}:e;function Vn(e,t){t=t||{};const n={};function r(c,d,f,p){return P.isPlainObject(c)&&P.isPlainObject(d)?P.merge.call({caseless:p},c,d):P.isPlainObject(d)?P.merge({},d):P.isArray(d)?d.slice():d}function o(c,d,f,p){if(P.isUndefined(d)){if(!P.isUndefined(c))return r(void 0,c,f,p)}else return r(c,d,f,p)}function s(c,d){if(!P.isUndefined(d))return r(void 0,d)}function i(c,d){if(P.isUndefined(d)){if(!P.isUndefined(c))return r(void 0,c)}else return r(void 0,d)}function a(c,d,f){if(f in t)return r(c,d);if(f in e)return r(void 0,c)}const l={url:s,method:s,data:s,baseURL:i,transformRequest:i,transformResponse:i,paramsSerializer:i,timeout:i,timeoutMessage:i,withCredentials:i,withXSRFToken:i,adapter:i,responseType:i,xsrfCookieName:i,xsrfHeaderName:i,onUploadProgress:i,onDownloadProgress:i,decompress:i,maxContentLength:i,maxBodyLength:i,beforeRedirect:i,transport:i,httpAgent:i,httpsAgent:i,cancelToken:i,socketPath:i,responseEncoding:i,validateStatus:a,headers:(c,d,f)=>o(vl(c),vl(d),f,!0)};return P.forEach(Object.keys({...e,...t}),function(d){const f=l[d]||o,p=f(e[d],t[d],d);P.isUndefined(p)&&f!==a||(n[d]=p)}),n}const bl=e=>{const t=Vn({},e);let{data:n,withXSRFToken:r,xsrfHeaderName:o,xsrfCookieName:s,headers:i,auth:a}=t;if(t.headers=i=$t.from(i),t.url=cl(yl(t.baseURL,t.url,t.allowAbsoluteUrls),e.params,e.paramsSerializer),a&&i.set("Authorization","Basic "+btoa((a.username||"")+":"+(a.password?unescape(encodeURIComponent(a.password)):""))),P.isFormData(n)){if(It.hasStandardBrowserEnv||It.hasStandardBrowserWebWorkerEnv)i.setContentType(void 0);else if(P.isFunction(n.getHeaders)){const l=n.getHeaders(),c=["content-type","content-length"];Object.entries(l).forEach(([d,f])=>{c.includes(d.toLowerCase())&&i.set(d,f)})}}if(It.hasStandardBrowserEnv&&(r&&P.isFunction(r)&&(r=r(t)),r||r!==!1&&Jm(t.url))){const l=o&&s&&Zm.read(s);l&&i.set(o,l)}return t},tg=typeof XMLHttpRequest<"u"&&function(e){return new Promise(function(n,r){const o=bl(e);let s=o.data;const i=$t.from(o.headers).normalize();let{responseType:a,onUploadProgress:l,onDownloadProgress:c}=o,d,f,p,h,m;function g(){h&&h(),m&&m(),o.cancelToken&&o.cancelToken.unsubscribe(d),o.signal&&o.signal.removeEventListener("abort",d)}let y=new XMLHttpRequest;y.open(o.method.toUpperCase(),o.url,!0),y.timeout=o.timeout;function x(){if(!y)return;const C=$t.from("getAllResponseHeaders"in y&&y.getAllResponseHeaders()),S={data:!a||a==="text"||a==="json"?y.responseText:y.response,status:y.status,statusText:y.statusText,headers:C,config:e,request:y};ml(function(I){n(I),g()},function(I){r(I),g()},S),y=null}"onloadend"in y?y.onloadend=x:y.onreadystatechange=function(){!y||y.readyState!==4||y.status===0&&!(y.responseURL&&y.responseURL.indexOf("file:")===0)||setTimeout(x)},y.onabort=function(){y&&(r(new Me("Request aborted",Me.ECONNABORTED,e,y)),y=null)},y.onerror=function(k){const S=k&&k.message?k.message:"Network Error",T=new Me(S,Me.ERR_NETWORK,e,y);T.event=k||null,r(T),y=null},y.ontimeout=function(){let k=o.timeout?"timeout of "+o.timeout+"ms exceeded":"timeout exceeded";const S=o.transitional||dl;o.timeoutErrorMessage&&(k=o.timeoutErrorMessage),r(new Me(k,S.clarifyTimeoutError?Me.ETIMEDOUT:Me.ECONNABORTED,e,y)),y=null},s===void 0&&i.setContentType(null),"setRequestHeader"in y&&P.forEach(i.toJSON(),function(k,S){y.setRequestHeader(S,k)}),P.isUndefined(o.withCredentials)||(y.withCredentials=!!o.withCredentials),a&&a!=="json"&&(y.responseType=o.responseType),c&&([p,m]=wo(c,!0),y.addEventListener("progress",p)),l&&y.upload&&([f,h]=wo(l),y.upload.addEventListener("progress",f),y.upload.addEventListener("loadend",h)),(o.cancelToken||o.signal)&&(d=C=>{y&&(r(!C||C.type?new ur(null,e,y):C),y.abort(),y=null)},o.cancelToken&&o.cancelToken.subscribe(d),o.signal&&(o.signal.aborted?d():o.signal.addEventListener("abort",d)));const b=Gm(o.url);if(b&&It.protocols.indexOf(b)===-1){r(new Me("Unsupported protocol "+b+":",Me.ERR_BAD_REQUEST,e));return}y.send(s||null)})},ng=(e,t)=>{const{length:n}=e=e?e.filter(Boolean):[];if(t||n){let r=new AbortController,o;const s=function(c){if(!o){o=!0,a();const d=c instanceof Error?c:this.reason;r.abort(d instanceof Me?d:new ur(d instanceof Error?d.message:d))}};let i=t&&setTimeout(()=>{i=null,s(new Me(`timeout ${t} of ms exceeded`,Me.ETIMEDOUT))},t);const a=()=>{e&&(i&&clearTimeout(i),i=null,e.forEach(c=>{c.unsubscribe?c.unsubscribe(s):c.removeEventListener("abort",s)}),e=null)};e.forEach(c=>c.addEventListener("abort",s));const{signal:l}=r;return l.unsubscribe=()=>P.asap(a),l}},rg=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},og=async function*(e,t){for await(const n of sg(e))yield*rg(n,t)},sg=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()}},wl=(e,t,n,r)=>{const o=og(e,t);let s=0,i,a=l=>{i||(i=!0,r&&r(l))};return new ReadableStream({async pull(l){try{const{done:c,value:d}=await o.next();if(c){a(),l.close();return}let f=d.byteLength;if(n){let p=s+=f;n(p)}l.enqueue(new Uint8Array(d))}catch(c){throw a(c),c}},cancel(l){return a(l),o.return()}},{highWaterMark:2})},Sl=64*1024,{isFunction:So}=P,ig=(({Request:e,Response:t})=>({Request:e,Response:t}))(P.global),{ReadableStream:Cl,TextEncoder:Tl}=P.global,kl=(e,...t)=>{try{return!!e(...t)}catch{return!1}},ag=e=>{e=P.merge.call({skipUndefined:!0},ig,e);const{fetch:t,Request:n,Response:r}=e,o=t?So(t):typeof fetch=="function",s=So(n),i=So(r);if(!o)return!1;const a=o&&So(Cl),l=o&&(typeof Tl=="function"?(m=>g=>m.encode(g))(new Tl):async m=>new Uint8Array(await new n(m).arrayBuffer())),c=s&&a&&kl(()=>{let m=!1;const g=new n(It.origin,{body:new Cl,method:"POST",get duplex(){return m=!0,"half"}}).headers.has("Content-Type");return m&&!g}),d=i&&a&&kl(()=>P.isReadableStream(new r("").body)),f={stream:d&&(m=>m.body)};o&&["text","arrayBuffer","blob","formData","stream"].forEach(m=>{!f[m]&&(f[m]=(g,y)=>{let x=g&&g[m];if(x)return x.call(g);throw new Me(`Response type '${m}' is not supported`,Me.ERR_NOT_SUPPORT,y)})});const p=async m=>{if(m==null)return 0;if(P.isBlob(m))return m.size;if(P.isSpecCompliantForm(m))return(await new n(It.origin,{method:"POST",body:m}).arrayBuffer()).byteLength;if(P.isArrayBufferView(m)||P.isArrayBuffer(m))return m.byteLength;if(P.isURLSearchParams(m)&&(m=m+""),P.isString(m))return(await l(m)).byteLength},h=async(m,g)=>{const y=P.toFiniteNumber(m.getContentLength());return y??p(g)};return async m=>{let{url:g,method:y,data:x,signal:b,cancelToken:C,timeout:k,onDownloadProgress:S,onUploadProgress:T,responseType:I,headers:A,withCredentials:_="same-origin",fetchOptions:L}=bl(m),R=t||fetch;I=I?(I+"").toLowerCase():"text";let O=ng([b,C&&C.toAbortSignal()],k),F=null;const N=O&&O.unsubscribe&&(()=>{O.unsubscribe()});let B;try{if(T&&c&&y!=="get"&&y!=="head"&&(B=await h(A,x))!==0){let X=new n(g,{method:"POST",body:x,duplex:"half"}),se;if(P.isFormData(x)&&(se=X.headers.get("content-type"))&&A.setContentType(se),X.body){const[be,Ie]=gl(B,wo(xl(T)));x=wl(X.body,Sl,be,Ie)}}P.isString(_)||(_=_?"include":"omit");const j=s&&"credentials"in n.prototype,K={...L,signal:O,method:y.toUpperCase(),headers:A.normalize().toJSON(),body:x,duplex:"half",credentials:j?_:void 0};F=s&&new n(g,K);let z=await(s?R(F,L):R(g,K));const M=d&&(I==="stream"||I==="response");if(d&&(S||M&&N)){const X={};["status","statusText","headers"].forEach(Y=>{X[Y]=z[Y]});const se=P.toFiniteNumber(z.headers.get("content-length")),[be,Ie]=S&&gl(se,wo(xl(S),!0))||[];z=new r(wl(z.body,Sl,be,()=>{Ie&&Ie(),N&&N()}),X)}I=I||"text";let G=await f[P.findKey(f,I)||"text"](z,m);return!M&&N&&N(),await new Promise((X,se)=>{ml(X,se,{data:G,headers:$t.from(z.headers),status:z.status,statusText:z.statusText,config:m,request:F})})}catch(j){throw N&&N(),j&&j.name==="TypeError"&&/Load failed|fetch/i.test(j.message)?Object.assign(new Me("Network Error",Me.ERR_NETWORK,m,F),{cause:j.cause||j}):Me.from(j,j&&j.code,m,F)}}},lg=new Map,Il=e=>{let t=e?e.env:{};const{fetch:n,Request:r,Response:o}=t,s=[r,o,n];let i=s.length,a=i,l,c,d=lg;for(;a--;)l=s[a],c=d.get(l),c===void 0&&d.set(l,c=a?new Map:ag(t)),d=c;return c};Il();const oi={http:_m,xhr:tg,fetch:{get:Il}};P.forEach(oi,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const El=e=>`- ${e}`,cg=e=>P.isFunction(e)||e===null||e===!1,Al={getAdapter:(e,t)=>{e=P.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,!cg(r)&&(o=oi[(a=String(r)).toLowerCase()],o===void 0))throw new Me(`Unknown adapter '${a}'`);if(o&&(P.isFunction(o)||(o=o.get(t))))break;s[a||"#"+i]=o}if(!o){const i=Object.entries(s).map(([l,c])=>`adapter ${l} `+(c===!1?"is not supported by the environment":"is not available in the build"));let a=n?i.length>1?`since :
|
|
33
|
-
`+i.map(
|
|
34
|
-
`):" "+
|
|
35
|
-
`+s):r.stack=s}catch{}}throw r}}_request(t,n){typeof t=="string"?(n=n||{},n.url=t):n=t||{},n=Vn(this.defaults,n);const{transitional:r,paramsSerializer:o,headers:s}=n;r!==void 0&&To.assertOptions(r,{silentJSONParsing:dn.transitional(dn.boolean),forcedJSONParsing:dn.transitional(dn.boolean),clarifyTimeoutError:dn.transitional(dn.boolean)},!1),o!=null&&(P.isFunction(o)?n.paramsSerializer={serialize:o}:To.assertOptions(o,{encode:dn.function,serialize:dn.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),To.assertOptions(n,{baseUrl:dn.spelling("baseURL"),withXsrfToken:dn.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let i=s&&P.merge(s.common,s[n.method]);s&&P.forEach(["delete","get","head","post","put","patch","common"],m=>{delete s[m]}),n.headers=$t.concat(i,s);const a=[];let l=!0;this.interceptors.request.forEach(function(g){typeof g.runWhen=="function"&&g.runWhen(n)===!1||(l=l&&g.synchronous,a.unshift(g.fulfilled,g.rejected))});const c=[];this.interceptors.response.forEach(function(g){c.push(g.fulfilled,g.rejected)});let d,f=0,p;if(!l){const m=[Nl.bind(this),void 0];for(m.unshift(...a),m.push(...c),p=m.length,d=Promise.resolve(n);f<p;)d=d.then(m[f++],m[f++]);return d}p=a.length;let h=n;for(;f<p;){const m=a[f++],g=a[f++];try{h=m(h)}catch(y){g.call(this,y);break}}try{d=Nl.call(this,h)}catch(m){return Promise.reject(m)}for(f=0,p=c.length;f<p;)d=d.then(c[f++],c[f++]);return d}getUri(t){t=Vn(this.defaults,t);const n=yl(t.baseURL,t.url,t.allowAbsoluteUrls);return cl(n,t.params,t.paramsSerializer)}};P.forEach(["delete","get","head","options"],function(t){Kn.prototype[t]=function(n,r){return this.request(Vn(r||{},{method:t,url:n,data:(r||{}).data}))}}),P.forEach(["post","put","patch"],function(t){function n(r){return function(s,i,a){return this.request(Vn(a||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:s,data:i}))}}Kn.prototype[t]=n(),Kn.prototype[t+"Form"]=n(!0)});let dg=class zh{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 ur(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 zh(function(o){t=o}),cancel:t}}};function fg(e){return function(n){return e.apply(null,n)}}function pg(e){return P.isObject(e)&&e.isAxiosError===!0}const ii={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(ii).forEach(([e,t])=>{ii[t]=e});function Ml(e){const t=new Kn(e),n=Ga(Kn.prototype.request,t);return P.extend(n,Kn.prototype,t,{allOwnKeys:!0}),P.extend(n,t,null,{allOwnKeys:!0}),n.create=function(o){return Ml(Vn(e,o))},n}const yt=Ml(Rr);yt.Axios=Kn,yt.CanceledError=ur,yt.CancelToken=dg,yt.isCancel=hl,yt.VERSION=_l,yt.toFormData=vo,yt.AxiosError=Me,yt.Cancel=yt.CanceledError,yt.all=function(t){return Promise.all(t)},yt.spread=fg,yt.isAxiosError=pg,yt.mergeConfig=Vn,yt.AxiosHeaders=$t,yt.formToJSON=e=>fl(P.isHTMLForm(e)?new FormData(e):e),yt.getAdapter=Al.getAdapter,yt.HttpStatusCode=ii,yt.default=yt;const{Axios:wT,AxiosError:ST,CanceledError:CT,isCancel:TT,CancelToken:kT,VERSION:IT,all:ET,Cancel:AT,isAxiosError:NT,spread:_T,toFormData:jT,AxiosHeaders:MT,HttpStatusCode:RT,formToJSON:PT,getAdapter:OT,mergeConfig:DT}=yt,Rl=typeof window<"u"?window.__API_BASE_URL__:void 0,Pl=Rl?wn(Rl):void 0;function wn(e){const n=(e!=null&&e.trim()?e.trim():"/api/chat").replace(/\/+$/,"");return n?n.endsWith("/chat")?n:`${n}/chat`:"/api/chat"}let ko=null;const ai=new Set;function Ol(){return ko}function Io(e){ko=e,ai.forEach(t=>t(e))}function Dl(e){return ai.add(e),()=>ai.delete(e)}const hg=3e4,mg=9e4,Kt=yt.create({...Pl?{baseURL:Pl}:{},timeout:hg,withCredentials:!0});Kt.interceptors.request.use(e=>(ko&&(e.headers.Authorization=`Bearer ${ko}`),e)),Kt.interceptors.response.use(e=>{if(typeof window<"u"&&(e!=null&&e.data))try{const t=e.data,n=t.data||{},r=typeof t.token=="string"&&t.token||typeof n.token=="string"&&n.token||null,o=typeof t.expires_at=="number"&&t.expires_at||typeof n.expires_at=="number"&&n.expires_at||typeof t.expiresAt=="number"&&t.expiresAt||typeof n.expiresAt=="number"&&n.expiresAt||null;r&&(localStorage.setItem("authToken",r),Io(r)),o&&localStorage.setItem("authTokenExpiresAt",o.toString()),(r||o)&&window.dispatchEvent(new CustomEvent("smartorg:chat-token-updated",{detail:{token:r,expiresAt:o}}))}catch(t){console.warn("[chat-api] Error storing token:",t)}return e},e=>Promise.reject(e));async function qt(e,t){return Kt.defaults.baseURL?(await Kt.get(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}async function li(e,t,n){return Kt.defaults.baseURL?(await Kt.post(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function Ll(e,t,n){return Kt.defaults.baseURL?(await Kt.put(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function $l(e,t){return Kt.defaults.baseURL?(await Kt.delete(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}function Gt(e){return e&&typeof e=="object"&&"data"in e?e.data:e}class Fl{get baseUrl(){const t=Kt.defaults.baseURL;return t?wn(String(t)):""}updateConfig(t){t.baseUrl&&(Kt.defaults.baseURL=wn(String(t.baseUrl))),t.authToken!==void 0&&Io(t.authToken)}getAuthToken(){return Ol()}setAuthToken(t){Io(t)}onTokenChange(t){return Dl(t)}async listThreads(){const t=await qt("/threads"),n=Gt(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async createThread(t){const r=await li("/threads",t?{title:t}:void 0);return Gt(r)}async updateThread(t,n){const r=await Ll(`/threads/${t}`,{title:n});return Gt(r)}async deleteThread(t){const n=await $l(`/threads/${t}`);return Gt(n)}async threadInfo(t){const n=await qt(`/threads/${t}/info`);return Gt(n)}async listAgents(){const t=await qt("/agents"),n=Gt(t);return(n==null?void 0:n.items)??[]}async getAgent(t){const n=await qt(`/agents/${t}`);return Gt(n)}async getAgentSchema(t){const n=await qt(`/agents/${t}/schema`);return Gt(n)}async getState(t){const n=await qt(`/threads/${t.threadId}/state`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return Gt(n)}async getStateHistory(t){const n=await qt(`/threads/${t.threadId}/state/history`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs},timeout:mg});return Gt(n)}async cancelRun(t){const n=await li("/runs/cancel",{threadId:t});return Gt(n)}async listCheckpointSummaries(t){const n=await qt(`/threads/${t}/state/checkpoints`,{params:{thread_id:t}}),r=Gt(n);return(r==null?void 0:r.items)??[]}}const An=new Fl,Bl=w.createContext(null);function gg({children:e,apiConfig:t}){const n=An;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 u.jsx(Bl.Provider,{value:r,children:e})}function ci(){const e=w.useContext(Bl);if(!e)throw new Error("useApi must be used within ApiProvider");return e}async function xg(e){return await new Promise((t,n)=>{const r=new FileReader;r.onload=()=>{try{const o=r.result,s=new Uint8Array(o);let i="";const a=s.byteLength;for(let l=0;l<a;l++)i+=String.fromCharCode(s[l]);t(btoa(i))}catch(o){n(o)}},r.onerror=o=>n(o),r.readAsArrayBuffer(e)})}async function yg(e,t=[],n,r,o,s){const i=[],a=[];for(const l of t)try{const c=await xg(l);a.push({filename:l.name,data:c,mime_type:l.type||"application/octet-stream"})}catch{}return{contentParts:i,filesInfo:a}}const vg={human:"user",user:"user",ai:"assistant",assistant:"assistant",tool:"tool",function:"tool",system:"system"};function ui(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 bg(e,t){return`${e??""}::${t??""}`}function dr(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(!ui(r))return{threadId:n,latest:null,checkpoints:[],timeline:[],interrupt:null,snapshots:{}};const{orderedSnapshots:o,snapshotMap:s}=Sg(t),i=zl(r,0),a=Cg(o);return{threadId:n,latest:i,checkpoints:o,timeline:a,interrupt:(i==null?void 0:i.interrupt)??null,snapshots:s}}function zl(e,t){if(!ui(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(_=>!!_&&typeof _=="object").map(_=>({..._})):a===null?null:void 0,c=r.map((_,L)=>Mg(_,L)).filter(_=>!!_),d=Rt(e.config),f=Rt(d==null?void 0:d.configurable),p=ut(f,["checkpoint_id","checkpointId"]),h=ut(f,["checkpoint_ns","checkpointNs"]),m=Rt(e==null?void 0:e.parentConfig),g=Rt(m==null?void 0:m.configurable),y=ut(g,["checkpoint_id","checkpointId"])??null,x=ut(g,["checkpoint_ns","checkpointNs"])??null,b=e==null?void 0:e.createdAt,C=typeof b=="string"&&b.trim()?b:new Date(Date.now()-t).toISOString(),k=c.slice().reverse().find(_=>_.role==="user")??null,S=Rt(e==null?void 0:e.metadata),T=ut(S,["branch_label","branchLabel"]),I=ut(g,["checkpoint_id","checkpointId"]),A=Array.isArray(e.next)?[...e.next]:(e==null?void 0:e.next)===null?null:void 0;return{messages:c,checkpointId:p??null,checkpointNs:h??null,nextCursor:y,nextCursorNs:x,interrupt:wg(a,c,t),createdAt:C,parentId:I??null,branchLabel:T??null,lastUserMessageId:(k==null?void 0:k.id)??null,hasMessages:c.length>0,messagesLen:c.length,metadata:S??null,config:d??null,parentConfig:m??null,next:A??null,tasks:l??null,values:i??null}}function wg(e,t,n){const r=_g(e,n);return r||Ng(t,n)}function Sg(e){const t=new Map;e.forEach((o,s)=>{if(!ui(o))return;const i=zl(o,s);if(!(i!=null&&i.checkpointId))return;const a=bg(i.checkpointId,i.checkpointNs??null),l=t.get(a);if(!l){t.set(a,i);return}t.set(a,Ig(l,i))});const n=Array.from(t.values());n.sort((o,s)=>Hl(s.createdAt??"")-Hl(o.createdAt??""));const r={};for(const[o,s]of t.entries())r[o]=s;return{orderedSnapshots:n,snapshotMap:r}}function Cg(e){var n,r;const t=[];for(const o of e){const s=o.checkpointId??null;if(!s)continue;const i=o.metadata??{},a=ut(i,["label"])??ut(i,["branch_label","branchLabel"])??ut(i,["description"])??"User input",l=kg(i,["step"]),c=ut(i,["source"]),d=o.createdAt??null,f=((r=(n=o.messages)==null?void 0:n[o.messages.length-1])==null?void 0:r.id)??null,p=o.lastUserMessageId??f,h=Tg(o.next);t.push({id:s,label:a,messageId:p,step:l,source:c??null,createdAt:d,next:h??void 0,parentConfig:o.parentConfig??null})}return t}function Tg(e){if(!Array.isArray(e)||e.length===0)return null;const t=e.map(n=>{if(typeof n=="string")return n.trim();if(n&&typeof n=="object"&&"type"in n){const r=n;if(typeof r.type=="string")return r.type}return null}).filter(n=>!!(n&&n.length));return t.length?t.join(", "):null}function kg(e,t){if(!e)return null;for(const n of t){const r=e[n];if(typeof r=="number"&&Number.isFinite(r))return r}return null}function Ig(e,t){return{...e,metadata:Eo(e.metadata,t.metadata)??null,config:Eo(e.config,t.config)??null,parentConfig:Eo(e.parentConfig,t.parentConfig)??null,next:Eg(e.next,t.next)??null,tasks:Ag(e.tasks,t.tasks)??null,values:Eo(e.values,t.values)??null}}function Eo(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 Eg(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 Ag(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 Ng(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 _g(e,t){if(!Array.isArray(e)||!e.length)return null;for(let n=e.length-1;n>=0;n--){const r=jg(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=Or(r.interrupts[s],`${o}-interrupt-${s}`);if(i)return i}if(r.state!==void 0&&r.state!==null){const s=Or(r.state,`${o}-state`);if(s)return s}}return null}function jg(e,t){if(!e)return null;if(Array.isArray(e)){const[a,l,c,,d,,f,...p]=e,h=typeof a=="string"&&a.trim()?a:t,m=typeof l=="string"&&l.trim()?l:Array.isArray(c)&&typeof c[0]=="string"?String(c[0]):"task",g=Array.isArray(d)?d:void 0,y=p.length?p[p.length-1]:void 0;return{id:h,name:m,interrupts:g,state:y!==void 0?y:f}}const n=Rt(e);if(!n)return null;const r=ut(n,["id","thread_id","taskId"])??t,o=ut(n,["name"])??"task",s=Array.isArray(n.interrupts)?n.interrupts:void 0,i=Object.prototype.hasOwnProperty.call(n,"state")?n.state:void 0;return{id:r,name:o,interrupts:s,state:i}}function Or(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=Ul(e,t);if(o)return o;if(Array.isArray(e)){for(let s=e.length-1;s>=0;s--){const i=Or(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=Or(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 c=Or(l,t,n+1,r);if(c)return c}}return null}function Ul(e,t){if(!e)return null;if(typeof e=="object"&&!Array.isArray(e)){const n=e,r=ut(n,["type","event","kind"]),o=ut(n,["id","interrupt_id","interruptId","value_id"])??(r&&r.toLowerCase().includes("interrupt")?t:void 0);if(!(Object.prototype.hasOwnProperty.call(n,"value")||Object.prototype.hasOwnProperty.call(n,"data")||Object.prototype.hasOwnProperty.call(n,"payload"))&&!(r&&r.toLowerCase().includes("interrupt")))return null;const i=Object.prototype.hasOwnProperty.call(n,"value")?n.value:Object.prototype.hasOwnProperty.call(n,"data")?n.data:Object.prototype.hasOwnProperty.call(n,"payload")?n.payload:n,a=o&&o.trim()?o:t;return a?{id:a,value:i}:null}if(Array.isArray(e)){for(let n=e.length-1;n>=0;n--){const r=Ul(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 Hl(e){if(!e)return 0;const t=Date.parse(e);return Number.isFinite(t)?t:0}function Mg(e,t){if(!e||typeof e!="object")return null;const n=e,r=Rt(e)??{},o=Rt(n.data)??r,s=String(n.type??o.type??o.role??"").toLowerCase(),i=vg[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}`,c=Rt(o.additional_kwargs)??Rt(o.additionalKwargs),d=Rt(o.response_metadata)??Rt(o.responseMetadata),f=ut(c,["createdAt","created_at"])??ut(o,["created_at","createdAt"]),p=ut(c,["checkpointId","checkpoint_id"]),h=ut(c,["checkpointNs","checkpoint_ns"]),m=Rg(o.content),g={id:l,role:i,content:m};f&&(g.createdAt=f),typeof o.name=="string"&&o.name.trim()&&(g.name=o.name),typeof(d==null?void 0:d.model_name)=="string"&&(g.model=String(d.model_name)),!g.model&&typeof o.model=="string"&&(g.model=o.model),p&&(g.checkpointId=p),h&&(g.checkpointNs=h);const y=Dg(Rt(o.artifact??r.artifact??o.artifacts??r.artifacts));y&&(g.artifact=y);const x=Bg(c,["createdAt","created_at","checkpointId","checkpoint_id","checkpointNs","checkpoint_ns","tool_calls"]),b=d?{...d}:void 0;x&&Object.keys(x).length&&(g.additionalKwargs=x),b&&Object.keys(b).length&&(g.responseMetadata=b);const C=Pg((c==null?void 0:c.tool_calls)??o.tool_calls);if(C.length&&(g.content=[...g.content,...C]),i==="tool"){const k=Og(o,g.content);k&&(g.content=k)}return g}function Rg(e){if(!e)return[];if(Array.isArray(e))return e.map(t=>Wl(t)).filter(t=>!!t);if(typeof e=="string")return e.trim()?[{type:"text",text:e.trim()}]:[];if(typeof e=="object"){const t=Wl(e);return t?[t]:[]}return[]}function Wl(e){if(!e||typeof e!="object")return typeof e=="string"&&e.trim()?{type:"text",text:e}:null;const t=e,n=String(t.type??"").toLowerCase();if(!n||n==="text"){const o=typeof t.text=="string"?t.text:typeof t.value=="string"?t.value:"";return o.trim()?{type:"text",text:o}:null}if(n==="image"||n==="image_url"){const o=ut(t,["url","src"]);if(!o)return null;const s={type:"image_url",url:o};return typeof t.mimeType=="string"&&(s.mimeType=t.mimeType),typeof t.alt=="string"&&(s.alt=t.alt),s}if(n==="file"){const o=ut(t,["url"]);if(!o)return null;const s={type:"file",url:o};return typeof t.mimeType=="string"&&(s.mimeType=t.mimeType),typeof t.name=="string"&&(s.name=t.name),typeof t.size=="number"&&(s.size=t.size),typeof t.sourceType=="string"&&(s.sourceType=t.sourceType),s}if(n==="tool_call")return Vl(t)??null;if(n==="tool_end"){const o="output"in t?t.output:t.content;return o?{type:"text",text:typeof o=="string"?o:JSON.stringify(o)}:null}if(n==="interrupt")return{type:"interrupt",value:t.value,...t};if(n==="tool"){const o=ut(t,["text","content"]);if(o)return{type:"text",text:o}}const r=typeof t.content=="string"?t.content:typeof t.value=="string"?t.value:JSON.stringify(t);return r?{type:"text",text:r}:null}function Vl(e,t){var s;const n=ut(e,["id","call_id"])??t,r=ut(e,["name"])??ut(Rt(e.function),["name"]);if(!n||!r)return null;const o=Fg(e.args??e.arguments??((s=Rt(e.function))==null?void 0:s.arguments));return{type:"tool_call",id:n,name:r,args:o}}function Pg(e){return Array.isArray(e)?e.map((t,n)=>Vl(t,`tool_call_${n}`)).filter(t=>!!t):[]}function Og(e,t){const n=e.content??e.output;if(!n)return t;const o={type:"text",text:typeof n=="string"?n:JSON.stringify(n)};return[...t,o]}function Dg(e){return e?{plots:Lg(e.plots)}:void 0}function Lg(e){return Array.isArray(e)?e.map(t=>$g(t)).filter(t=>!!t):[]}function $g(e){if(!e||typeof e!="object")return null;const t=e,n=typeof t.content_base64=="string"&&t.content_base64.trim()||void 0,r=typeof t.url=="string"&&t.url.trim()||void 0,o=(typeof t.format=="string"?t.format.trim():void 0)||(typeof t.mimeType=="string"?t.mimeType.trim():void 0)||(typeof t.mime_type=="string"?t.mime_type.trim():void 0),s=typeof t.plotId=="string"&&t.plotId.trim()||void 0,i=typeof t.artifactId=="string"&&t.artifactId.trim()||void 0,a={};return n&&(a.content_base64=n),r&&(a.url=r),o&&(a.format=o),s&&(a.plotId=s),i&&(a.artifactId=i),a}function Fg(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 Rt(e){if(!(!e||typeof e!="object"||Array.isArray(e)))return{...e}}function ut(e,t){if(e)for(const n of t){const r=e[n];if(typeof r=="string"&&r.trim())return r}}function Bg(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}const Kl=120;function zg(e){if(!Array.isArray(e))return"";const t=e.filter(r=>!!(r&&r.type==="text")).map(r=>(r.text??"").trim()).filter(Boolean);if(!t.length)return"";const n=t.join(" ").replace(/\s+/g," ").trim();return n?n.length>Kl?`${n.slice(0,Kl-3)}…`:n:""}function ql(e){return zg(e.content)||""}function Ug(e){const t=new Map;for(const n of e){if(!n.id||n.role!=="user")continue;const r=ql(n);r&&t.set(n.id,r)}return t}function Hg(e){var n;const t=new Map;for(const r of e){if(!r.checkpointId)continue;const o=(n=r.messages)==null?void 0:n.find(s=>s.role==="user");if(o){const s=ql(o);s&&t.set(r.checkpointId,s)}}return t}function Gl(e={}){const t=w.useMemo(()=>wn(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),[c,d]=w.useState(null),[f,p]=w.useState(""),[h,m]=w.useState(null),[g,y]=w.useState(0),[x,b]=w.useState(!1),C=w.useRef(null),k=w.useRef(!0),S=w.useRef(0),T=w.useRef(null),I=w.useRef(null),A=w.useRef(null),_=w.useRef(null),L=w.useCallback(N=>{o(N)},[]),R=w.useCallback(()=>{p(""),m(null),d(null),I.current=null,A.current=null,_.current=null},[]),O=w.useCallback(()=>{var N;console.debug("[use-chat] stop() invoked - aborting stream"),(N=C.current)==null||N.abort(),C.current=null,T.current=null,l(!1),b(!1),S.current=0,y(0)},[]),F=w.useCallback((N,B,j)=>{C.current&&(C.current.abort(),C.current=null),l(!0),d(null),e.autoAppendAssistant!==!1&&p(""),m(null),I.current=null,A.current=null,_.current=null;const K=new AbortController;C.current=K;let z=null,M=null,G=!1;return T.current={threadId:N.threadId??null,headers:{}},(async()=>{var se,be,Ie,Y,U,J,$,q,Z,ue,ie,_e,He,oe,ye,Oe,Ye,nt;const X=Xe=>{var qe;try{const it=JSON.parse(JSON.stringify(Xe));return(qe=it==null?void 0:it.payload)!=null&&qe.files_info&&Array.isArray(it.payload.files_info)&&(it.payload.files_info=it.payload.files_info.map(Je=>({...Je,data:Je!=null&&Je.data?`<base64 ${String(Je.data).length} chars>`:Je==null?void 0:Je.data}))),it}catch{return Xe}};try{let Xe={};try{if(r)Xe={Authorization:`Bearer ${r}`};else if(typeof window<"u"){const We=window.__AUTH_TOKEN__,gt=((se=window.localStorage)==null?void 0:se.getItem("authToken"))||null;let Mt=null;try{const re=(be=window.localStorage)==null?void 0:be.getItem("chat-settings");re&&(Mt=((Ie=JSON.parse(re))==null?void 0:Ie.apiKey)||null)}catch{}const H=We||gt||Mt||null;H&&(Xe={Authorization:`Bearer ${H}`})}}catch{}console.debug("[use-chat] POST",t+n,X(N));let qe={};if(typeof window<"u")try{const rt=(Y=window.localStorage)==null?void 0:Y.getItem("authSessionId");rt&&(qe={"X-Session-Id":rt})}catch{}const it={...Xe,...qe,...s.current},Je={"Content-Type":"application/json",Accept:"text/event-stream",...it},et=await fetch(t+n,{method:"POST",headers:Je,body:JSON.stringify(N),signal:K.signal,credentials:i});if(T.current&&(T.current.headers=it),!et.ok||!et.body){const rt=await et.text().catch(()=>"");console.debug("[use-chat] non-OK response",et.status,rt==null?void 0:rt.slice(0,500));const We=`stream ${et.status}${rt?": "+rt:""}`;throw(U=j==null?void 0:j.onConnectionError)==null||U.call(j,We),G=!0,z="error",M=We,new Error(We)}b(!0);const at=et.body.getReader(),_t=new TextDecoder;let ht="",ft=[];S.current=0,y(0);let mt=0,St=null;const jt=()=>{if(ft.length){const rt=ft.join("");ft=[],k.current&&p(We=>We+rt)}St=null},Dt=()=>{typeof window<"u"&&St==null&&(St=requestAnimationFrame(jt))};let Wt=Date.now();const Ue=setInterval(()=>{var rt;if(Date.now()-Wt>18e5){const We="Stream idle timeout";d(We),z="error",M=We,K.abort(),(rt=j==null?void 0:j.onError)==null||rt.call(j,We)}},5e3),un=1024*1024;try{const rt=et.headers.get("X-Thread-Id")||et.headers.get("x-thread-id"),We=et.headers.get("X-Thread-Created")||et.headers.get("x-thread-created"),gt=rt??null,Mt=String(We??"").toLowerCase()==="true";for(T.current&&!T.current.threadId&&(T.current={...T.current,threadId:gt}),(J=j==null?void 0:j.onOpen)==null||J.call(j,{threadId:gt,created:Mt});;){const{value:H,done:re}=await at.read();if(re)break;ht+=_t.decode(H,{stream:!0}),ht.length>un&&(ht="",console.warn("Stream buffer reset: exceeded 1MB"));let D;for(;(D=ht.indexOf(`
|
|
30
|
+
<%s key={someKey} {...props} />`,Hn,Ee,nn,Ee),An[Ee+Hn]=!0}}return E===r?Kt(xt):je(xt),xt}}function Ar(E,V,ae){return ar(E,V,ae,!0)}function fo(E,V,ae){return ar(E,V,ae,!1)}var Un=fo,lr=Ar;_r.Fragment=r,_r.jsx=Un,_r.jsxs=lr}()),_r}process.env.NODE_ENV==="production"?Xs.exports=Vh():Xs.exports=Kh();var u=Xs.exports;function qa(e,t){return function(){return e.apply(t,arguments)}}const{toString:qh}=Object.prototype,{getPrototypeOf:Js}=Object,{iterator:mo,toStringTag:Ga}=Symbol,go=(e=>t=>{const n=qh.call(t);return e[n]||(e[n]=n.slice(8,-1).toLowerCase())})(Object.create(null)),rn=e=>(e=e.toLowerCase(),t=>go(t)===e),xo=e=>t=>typeof t===e,{isArray:cr}=Array,ur=xo("undefined");function jr(e){return e!==null&&!ur(e)&&e.constructor!==null&&!ur(e.constructor)&&$t(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const Ya=rn("ArrayBuffer");function Gh(e){let t;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?t=ArrayBuffer.isView(e):t=e&&e.buffer&&Ya(e.buffer),t}const Yh=xo("string"),$t=xo("function"),Xa=xo("number"),Mr=e=>e!==null&&typeof e=="object",Xh=e=>e===!0||e===!1,yo=e=>{if(go(e)!=="object")return!1;const t=Js(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Ga in e)&&!(mo in e)},Jh=e=>{if(!Mr(e)||jr(e))return!1;try{return Object.keys(e).length===0&&Object.getPrototypeOf(e)===Object.prototype}catch{return!1}},Zh=rn("Date"),Qh=rn("File"),em=rn("Blob"),tm=rn("FileList"),nm=e=>Mr(e)&&$t(e.pipe),rm=e=>{let t;return e&&(typeof FormData=="function"&&e instanceof FormData||$t(e.append)&&((t=go(e))==="formdata"||t==="object"&&$t(e.toString)&&e.toString()==="[object FormData]"))},om=rn("URLSearchParams"),[sm,im,am,lm]=["ReadableStream","Request","Response","Headers"].map(rn),cm=e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function Rr(e,t,{allOwnKeys:n=!1}={}){if(e===null||typeof e>"u")return;let r,o;if(typeof e!="object"&&(e=[e]),cr(e))for(r=0,o=e.length;r<o;r++)t.call(null,e[r],r,e);else{if(jr(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 Ja(e,t){if(jr(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 Vn=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global,Za=e=>!ur(e)&&e!==Vn;function Zs(){const{caseless:e,skipUndefined:t}=Za(this)&&this||{},n={},r=(o,s)=>{const i=e&&Ja(n,s)||s;yo(n[i])&&yo(o)?n[i]=Zs(n[i],o):yo(o)?n[i]=Zs({},o):cr(o)?n[i]=o.slice():(!t||!ur(o))&&(n[i]=o)};for(let o=0,s=arguments.length;o<s;o++)arguments[o]&&Rr(arguments[o],r);return n}const um=(e,t,n,{allOwnKeys:r}={})=>(Rr(t,(o,s)=>{n&&$t(o)?e[s]=qa(o,n):e[s]=o},{allOwnKeys:r}),e),dm=e=>(e.charCodeAt(0)===65279&&(e=e.slice(1)),e),fm=(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)},pm=(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&&Js(e)}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},hm=(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},mm=e=>{if(!e)return null;if(cr(e))return e;let t=e.length;if(!Xa(t))return null;const n=new Array(t);for(;t-- >0;)n[t]=e[t];return n},gm=(e=>t=>e&&t instanceof e)(typeof Uint8Array<"u"&&Js(Uint8Array)),xm=(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])}},ym=(e,t)=>{let n;const r=[];for(;(n=e.exec(t))!==null;)r.push(n);return r},vm=rn("HTMLFormElement"),bm=e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(n,r,o){return r.toUpperCase()+o}),Qa=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),wm=rn("RegExp"),el=(e,t)=>{const n=Object.getOwnPropertyDescriptors(e),r={};Rr(n,(o,s)=>{let i;(i=t(o,s,e))!==!1&&(r[s]=i||o)}),Object.defineProperties(e,r)},Sm=e=>{el(e,(t,n)=>{if($t(e)&&["arguments","caller","callee"].indexOf(n)!==-1)return!1;const r=e[n];if($t(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+"'")})}})},Cm=(e,t)=>{const n={},r=o=>{o.forEach(s=>{n[s]=!0})};return cr(e)?r(e):r(String(e).split(t)),n},Tm=()=>{},km=(e,t)=>e!=null&&Number.isFinite(e=+e)?e:t;function Im(e){return!!(e&&$t(e.append)&&e[Ga]==="FormData"&&e[mo])}const Em=e=>{const t=new Array(10),n=(r,o)=>{if(Mr(r)){if(t.indexOf(r)>=0)return;if(jr(r))return r;if(!("toJSON"in r)){t[o]=r;const s=cr(r)?[]:{};return Rr(r,(i,a)=>{const l=n(i,o+1);!ur(l)&&(s[a]=l)}),t[o]=void 0,s}}return r};return n(e,0)},Am=rn("AsyncFunction"),Nm=e=>e&&(Mr(e)||$t(e))&&$t(e.then)&&$t(e.catch),tl=((e,t)=>e?setImmediate:t?((n,r)=>(Vn.addEventListener("message",({source:o,data:s})=>{o===Vn&&s===n&&r.length&&r.shift()()},!1),o=>{r.push(o),Vn.postMessage(n,"*")}))(`axios@${Math.random()}`,[]):n=>setTimeout(n))(typeof setImmediate=="function",$t(Vn.postMessage)),_m=typeof queueMicrotask<"u"?queueMicrotask.bind(Vn):typeof process<"u"&&process.nextTick||tl,P={isArray:cr,isArrayBuffer:Ya,isBuffer:jr,isFormData:rm,isArrayBufferView:Gh,isString:Yh,isNumber:Xa,isBoolean:Xh,isObject:Mr,isPlainObject:yo,isEmptyObject:Jh,isReadableStream:sm,isRequest:im,isResponse:am,isHeaders:lm,isUndefined:ur,isDate:Zh,isFile:Qh,isBlob:em,isRegExp:wm,isFunction:$t,isStream:nm,isURLSearchParams:om,isTypedArray:gm,isFileList:tm,forEach:Rr,merge:Zs,extend:um,trim:cm,stripBOM:dm,inherits:fm,toFlatObject:pm,kindOf:go,kindOfTest:rn,endsWith:hm,toArray:mm,forEachEntry:xm,matchAll:ym,isHTMLForm:vm,hasOwnProperty:Qa,hasOwnProp:Qa,reduceDescriptors:el,freezeMethods:Sm,toObjectSet:Cm,toCamelCase:bm,noop:Tm,toFiniteNumber:km,findKey:Ja,global:Vn,isContextDefined:Za,isSpecCompliantForm:Im,toJSONObject:Em,isAsyncFn:Am,isThenable:Nm,setImmediate:tl,asap:_m,isIterable:e=>e!=null&&$t(e[mo])};function Me(e,t,n,r,o){Error.call(this),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=new Error().stack,this.message=e,this.name="AxiosError",t&&(this.code=t),n&&(this.config=n),r&&(this.request=r),o&&(this.response=o,this.status=o.status?o.status:null)}P.inherits(Me,Error,{toJSON:function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:P.toJSONObject(this.config),code:this.code,status:this.status}}});const nl=Me.prototype,rl={};["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=>{rl[e]={value:e}}),Object.defineProperties(Me,rl),Object.defineProperty(nl,"isAxiosError",{value:!0}),Me.from=(e,t,n,r,o,s)=>{const i=Object.create(nl);P.toFlatObject(e,i,function(d){return d!==Error.prototype},c=>c!=="isAxiosError");const a=e&&e.message?e.message:"Error",l=t==null&&e?e.code:t;return Me.call(i,a,l,n,r,o),e&&i.cause==null&&Object.defineProperty(i,"cause",{value:e,configurable:!0}),i.name=e&&e.name||"Error",s&&Object.assign(i,s),i};const jm=null;function Qs(e){return P.isPlainObject(e)||P.isArray(e)}function ol(e){return P.endsWith(e,"[]")?e.slice(0,-2):e}function sl(e,t,n){return e?e.concat(t).map(function(o,s){return o=ol(o),!n&&s?"["+o+"]":o}).join(n?".":""):t}function Mm(e){return P.isArray(e)&&!e.some(Qs)}const Rm=P.toFlatObject(P,{},null,function(t){return/^is[A-Z]/.test(t)});function vo(e,t,n){if(!P.isObject(e))throw new TypeError("target must be an object");t=t||new FormData,n=P.toFlatObject(n,{metaTokens:!0,dots:!1,indexes:!1},!1,function(g,y){return!P.isUndefined(y[g])});const r=n.metaTokens,o=n.visitor||d,s=n.dots,i=n.indexes,l=(n.Blob||typeof Blob<"u"&&Blob)&&P.isSpecCompliantForm(t);if(!P.isFunction(o))throw new TypeError("visitor must be a function");function c(m){if(m===null)return"";if(P.isDate(m))return m.toISOString();if(P.isBoolean(m))return m.toString();if(!l&&P.isBlob(m))throw new Me("Blob is not supported. Use a Buffer instead.");return P.isArrayBuffer(m)||P.isTypedArray(m)?l&&typeof Blob=="function"?new Blob([m]):Buffer.from(m):m}function d(m,g,y){let x=m;if(m&&!y&&typeof m=="object"){if(P.endsWith(g,"{}"))g=r?g:g.slice(0,-2),m=JSON.stringify(m);else if(P.isArray(m)&&Mm(m)||(P.isFileList(m)||P.endsWith(g,"[]"))&&(x=P.toArray(m)))return g=ol(g),x.forEach(function(S,k){!(P.isUndefined(S)||S===null)&&t.append(i===!0?sl([g],k,s):i===null?g:g+"[]",c(S))}),!1}return Qs(m)?!0:(t.append(sl(y,g,s),c(m)),!1)}const f=[],h=Object.assign(Rm,{defaultVisitor:d,convertValue:c,isVisitable:Qs});function p(m,g){if(!P.isUndefined(m)){if(f.indexOf(m)!==-1)throw Error("Circular reference detected in "+g.join("."));f.push(m),P.forEach(m,function(x,b){(!(P.isUndefined(x)||x===null)&&o.call(t,x,P.isString(b)?b.trim():b,g,h))===!0&&p(x,g?g.concat(b):[b])}),f.pop()}}if(!P.isObject(e))throw new TypeError("data must be an object");return p(e),t}function il(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,function(r){return t[r]})}function ei(e,t){this._pairs=[],e&&vo(e,this,t)}const al=ei.prototype;al.append=function(t,n){this._pairs.push([t,n])},al.toString=function(t){const n=t?function(r){return t.call(this,r,il)}:il;return this._pairs.map(function(o){return n(o[0])+"="+n(o[1])},"").join("&")};function Pm(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+")}function ll(e,t,n){if(!t)return e;const r=n&&n.encode||Pm;P.isFunction(n)&&(n={serialize:n});const o=n&&n.serialize;let s;if(o?s=o(t,n):s=P.isURLSearchParams(t)?t.toString():new ei(t,n).toString(r),s){const i=e.indexOf("#");i!==-1&&(e=e.slice(0,i)),e+=(e.indexOf("?")===-1?"?":"&")+s}return e}class cl{constructor(){this.handlers=[]}use(t,n,r){return this.handlers.push({fulfilled:t,rejected:n,synchronous:r?r.synchronous:!1,runWhen:r?r.runWhen:null}),this.handlers.length-1}eject(t){this.handlers[t]&&(this.handlers[t]=null)}clear(){this.handlers&&(this.handlers=[])}forEach(t){P.forEach(this.handlers,function(r){r!==null&&t(r)})}}const ul={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},Om={isBrowser:!0,classes:{URLSearchParams:typeof URLSearchParams<"u"?URLSearchParams:ei,FormData:typeof FormData<"u"?FormData:null,Blob:typeof Blob<"u"?Blob:null},protocols:["http","https","file","blob","url","data"]},ti=typeof window<"u"&&typeof document<"u",ni=typeof navigator=="object"&&navigator||void 0,Dm=ti&&(!ni||["ReactNative","NativeScript","NS"].indexOf(ni.product)<0),Lm=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function",$m=ti&&window.location.href||"http://localhost",Et={...Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv:ti,hasStandardBrowserEnv:Dm,hasStandardBrowserWebWorkerEnv:Lm,navigator:ni,origin:$m},Symbol.toStringTag,{value:"Module"})),...Om};function Fm(e,t){return vo(e,new Et.classes.URLSearchParams,{visitor:function(n,r,o,s){return Et.isNode&&P.isBuffer(n)?(this.append(r,n.toString("base64")),!1):s.defaultVisitor.apply(this,arguments)},...t})}function Bm(e){return P.matchAll(/\w+|\[(\w*)]/g,e).map(t=>t[0]==="[]"?"":t[1]||t[0])}function zm(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 dl(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&&P.isArray(o)?o.length:i,l?(P.hasOwnProp(o,i)?o[i]=[o[i],r]:o[i]=r,!a):((!o[i]||!P.isObject(o[i]))&&(o[i]=[]),t(n,r,o[i],s)&&P.isArray(o[i])&&(o[i]=zm(o[i])),!a)}if(P.isFormData(e)&&P.isFunction(e.entries)){const n={};return P.forEachEntry(e,(r,o)=>{t(Bm(r),o,n,0)}),n}return null}function Um(e,t,n){if(P.isString(e))try{return(t||JSON.parse)(e),P.trim(e)}catch(r){if(r.name!=="SyntaxError")throw r}return(n||JSON.stringify)(e)}const Pr={transitional:ul,adapter:["xhr","http","fetch"],transformRequest:[function(t,n){const r=n.getContentType()||"",o=r.indexOf("application/json")>-1,s=P.isObject(t);if(s&&P.isHTMLForm(t)&&(t=new FormData(t)),P.isFormData(t))return o?JSON.stringify(dl(t)):t;if(P.isArrayBuffer(t)||P.isBuffer(t)||P.isStream(t)||P.isFile(t)||P.isBlob(t)||P.isReadableStream(t))return t;if(P.isArrayBufferView(t))return t.buffer;if(P.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 Fm(t,this.formSerializer).toString();if((a=P.isFileList(t))||r.indexOf("multipart/form-data")>-1){const l=this.env&&this.env.FormData;return vo(a?{"files[]":t}:t,l&&new l,this.formSerializer)}}return s||o?(n.setContentType("application/json",!1),Um(t)):t}],transformResponse:[function(t){const n=this.transitional||Pr.transitional,r=n&&n.forcedJSONParsing,o=this.responseType==="json";if(P.isResponse(t)||P.isReadableStream(t))return t;if(t&&P.isString(t)&&(r&&!this.responseType||o)){const i=!(n&&n.silentJSONParsing)&&o;try{return JSON.parse(t,this.parseReviver)}catch(a){if(i)throw a.name==="SyntaxError"?Me.from(a,Me.ERR_BAD_RESPONSE,this,null,this.response):a}}return t}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:Et.classes.FormData,Blob:Et.classes.Blob},validateStatus:function(t){return t>=200&&t<300},headers:{common:{Accept:"application/json, text/plain, */*","Content-Type":void 0}}};P.forEach(["delete","get","head","post","put","patch"],e=>{Pr.headers[e]={}});const Hm=P.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"]),Wm=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]&&Hm[n])&&(n==="set-cookie"?t[n]?t[n].push(r):t[n]=[r]:t[n]=t[n]?t[n]+", "+r:r)}),t},fl=Symbol("internals");function Or(e){return e&&String(e).trim().toLowerCase()}function bo(e){return e===!1||e==null?e:P.isArray(e)?e.map(bo):String(e)}function Vm(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 Km=e=>/^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(e.trim());function ri(e,t,n,r,o){if(P.isFunction(r))return r.call(this,t,n);if(o&&(t=n),!!P.isString(t)){if(P.isString(r))return t.indexOf(r)!==-1;if(P.isRegExp(r))return r.test(t)}}function qm(e){return e.trim().toLowerCase().replace(/([a-z\d])(\w*)/g,(t,n,r)=>n.toUpperCase()+r)}function Gm(e,t){const n=P.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,c){const d=Or(l);if(!d)throw new Error("header name must be a non-empty string");const f=P.findKey(o,d);(!f||o[f]===void 0||c===!0||c===void 0&&o[f]!==!1)&&(o[f||l]=bo(a))}const i=(a,l)=>P.forEach(a,(c,d)=>s(c,d,l));if(P.isPlainObject(t)||t instanceof this.constructor)i(t,n);else if(P.isString(t)&&(t=t.trim())&&!Km(t))i(Wm(t),n);else if(P.isObject(t)&&P.isIterable(t)){let a={},l,c;for(const d of t){if(!P.isArray(d))throw TypeError("Object iterator must return a key-value pair");a[c=d[0]]=(l=a[c])?P.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=Or(t),t){const r=P.findKey(this,t);if(r){const o=this[r];if(!n)return o;if(n===!0)return Vm(o);if(P.isFunction(n))return n.call(this,o,r);if(P.isRegExp(n))return n.exec(o);throw new TypeError("parser must be boolean|regexp|function")}}}has(t,n){if(t=Or(t),t){const r=P.findKey(this,t);return!!(r&&this[r]!==void 0&&(!n||ri(this,this[r],r,n)))}return!1}delete(t,n){const r=this;let o=!1;function s(i){if(i=Or(i),i){const a=P.findKey(r,i);a&&(!n||ri(r,r[a],a,n))&&(delete r[a],o=!0)}}return P.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||ri(this,this[s],s,t,!0))&&(delete this[s],o=!0)}return o}normalize(t){const n=this,r={};return P.forEach(this,(o,s)=>{const i=P.findKey(r,s);if(i){n[i]=bo(o),delete n[s];return}const a=t?qm(s):String(s).trim();a!==s&&delete n[s],n[a]=bo(o),r[a]=!0}),this}concat(...t){return this.constructor.concat(this,...t)}toJSON(t){const n=Object.create(null);return P.forEach(this,(r,o)=>{r!=null&&r!==!1&&(n[o]=t&&P.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[fl]=this[fl]={accessors:{}}).accessors,o=this.prototype;function s(i){const a=Or(i);r[a]||(Gm(o,i),r[a]=!0)}return P.isArray(t)?t.forEach(s):s(t),this}};Ft.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),P.reduceDescriptors(Ft.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(r){this[n]=r}}}),P.freezeMethods(Ft);function oi(e,t){const n=this||Pr,r=t||n,o=Ft.from(r.headers);let s=r.data;return P.forEach(e,function(a){s=a.call(n,s,o.normalize(),t?t.status:void 0)}),o.normalize(),s}function pl(e){return!!(e&&e.__CANCEL__)}function dr(e,t,n){Me.call(this,e??"canceled",Me.ERR_CANCELED,t,n),this.name="CanceledError"}P.inherits(dr,Me,{__CANCEL__:!0});function hl(e,t,n){const r=n.config.validateStatus;!n.status||!r||r(n.status)?e(n):t(new Me("Request failed with status code "+n.status,[Me.ERR_BAD_REQUEST,Me.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n))}function Ym(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function Xm(e,t){e=e||10;const n=new Array(e),r=new Array(e);let o=0,s=0,i;return t=t!==void 0?t:1e3,function(l){const c=Date.now(),d=r[s];i||(i=c),n[o]=l,r[o]=c;let f=s,h=0;for(;f!==o;)h+=n[f++],f=f%e;if(o=(o+1)%e,o===s&&(s=(s+1)%e),c-i<t)return;const p=d&&c-d;return p?Math.round(h*1e3/p):void 0}}function Jm(e,t){let n=0,r=1e3/t,o,s;const i=(c,d=Date.now())=>{n=d,o=null,s&&(clearTimeout(s),s=null),e(...c)};return[(...c)=>{const d=Date.now(),f=d-n;f>=r?i(c,d):(o=c,s||(s=setTimeout(()=>{s=null,i(o)},r-f)))},()=>o&&i(o)]}const wo=(e,t,n=3)=>{let r=0;const o=Xm(50,250);return Jm(s=>{const i=s.loaded,a=s.lengthComputable?s.total:void 0,l=i-r,c=o(l),d=i<=a;r=i;const f={loaded:i,total:a,progress:a?i/a:void 0,bytes:l,rate:c||void 0,estimated:c&&a&&d?(a-i)/c:void 0,event:s,lengthComputable:a!=null,[t?"download":"upload"]:!0};e(f)},n)},ml=(e,t)=>{const n=e!=null;return[r=>t[0]({lengthComputable:n,total:e,loaded:r}),t[1]]},gl=e=>(...t)=>P.asap(()=>e(...t)),Zm=Et.hasStandardBrowserEnv?((e,t)=>n=>(n=new URL(n,Et.origin),e.protocol===n.protocol&&e.host===n.host&&(t||e.port===n.port)))(new URL(Et.origin),Et.navigator&&/(msie|trident)/i.test(Et.navigator.userAgent)):()=>!0,Qm=Et.hasStandardBrowserEnv?{write(e,t,n,r,o,s){const i=[e+"="+encodeURIComponent(t)];P.isNumber(n)&&i.push("expires="+new Date(n).toGMTString()),P.isString(r)&&i.push("path="+r),P.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 eg(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function tg(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function xl(e,t,n){let r=!eg(t);return e&&(r||n==!1)?tg(e,t):t}const yl=e=>e instanceof Ft?{...e}:e;function Kn(e,t){t=t||{};const n={};function r(c,d,f,h){return P.isPlainObject(c)&&P.isPlainObject(d)?P.merge.call({caseless:h},c,d):P.isPlainObject(d)?P.merge({},d):P.isArray(d)?d.slice():d}function o(c,d,f,h){if(P.isUndefined(d)){if(!P.isUndefined(c))return r(void 0,c,f,h)}else return r(c,d,f,h)}function s(c,d){if(!P.isUndefined(d))return r(void 0,d)}function i(c,d){if(P.isUndefined(d)){if(!P.isUndefined(c))return r(void 0,c)}else return r(void 0,d)}function a(c,d,f){if(f in t)return r(c,d);if(f in e)return r(void 0,c)}const l={url:s,method:s,data:s,baseURL:i,transformRequest:i,transformResponse:i,paramsSerializer:i,timeout:i,timeoutMessage:i,withCredentials:i,withXSRFToken:i,adapter:i,responseType:i,xsrfCookieName:i,xsrfHeaderName:i,onUploadProgress:i,onDownloadProgress:i,decompress:i,maxContentLength:i,maxBodyLength:i,beforeRedirect:i,transport:i,httpAgent:i,httpsAgent:i,cancelToken:i,socketPath:i,responseEncoding:i,validateStatus:a,headers:(c,d,f)=>o(yl(c),yl(d),f,!0)};return P.forEach(Object.keys({...e,...t}),function(d){const f=l[d]||o,h=f(e[d],t[d],d);P.isUndefined(h)&&f!==a||(n[d]=h)}),n}const vl=e=>{const t=Kn({},e);let{data:n,withXSRFToken:r,xsrfHeaderName:o,xsrfCookieName:s,headers:i,auth:a}=t;if(t.headers=i=Ft.from(i),t.url=ll(xl(t.baseURL,t.url,t.allowAbsoluteUrls),e.params,e.paramsSerializer),a&&i.set("Authorization","Basic "+btoa((a.username||"")+":"+(a.password?unescape(encodeURIComponent(a.password)):""))),P.isFormData(n)){if(Et.hasStandardBrowserEnv||Et.hasStandardBrowserWebWorkerEnv)i.setContentType(void 0);else if(P.isFunction(n.getHeaders)){const l=n.getHeaders(),c=["content-type","content-length"];Object.entries(l).forEach(([d,f])=>{c.includes(d.toLowerCase())&&i.set(d,f)})}}if(Et.hasStandardBrowserEnv&&(r&&P.isFunction(r)&&(r=r(t)),r||r!==!1&&Zm(t.url))){const l=o&&s&&Qm.read(s);l&&i.set(o,l)}return t},ng=typeof XMLHttpRequest<"u"&&function(e){return new Promise(function(n,r){const o=vl(e);let s=o.data;const i=Ft.from(o.headers).normalize();let{responseType:a,onUploadProgress:l,onDownloadProgress:c}=o,d,f,h,p,m;function g(){p&&p(),m&&m(),o.cancelToken&&o.cancelToken.unsubscribe(d),o.signal&&o.signal.removeEventListener("abort",d)}let y=new XMLHttpRequest;y.open(o.method.toUpperCase(),o.url,!0),y.timeout=o.timeout;function x(){if(!y)return;const S=Ft.from("getAllResponseHeaders"in y&&y.getAllResponseHeaders()),C={data:!a||a==="text"||a==="json"?y.responseText:y.response,status:y.status,statusText:y.statusText,headers:S,config:e,request:y};hl(function(I){n(I),g()},function(I){r(I),g()},C),y=null}"onloadend"in y?y.onloadend=x:y.onreadystatechange=function(){!y||y.readyState!==4||y.status===0&&!(y.responseURL&&y.responseURL.indexOf("file:")===0)||setTimeout(x)},y.onabort=function(){y&&(r(new Me("Request aborted",Me.ECONNABORTED,e,y)),y=null)},y.onerror=function(k){const C=k&&k.message?k.message:"Network Error",T=new Me(C,Me.ERR_NETWORK,e,y);T.event=k||null,r(T),y=null},y.ontimeout=function(){let k=o.timeout?"timeout of "+o.timeout+"ms exceeded":"timeout exceeded";const C=o.transitional||ul;o.timeoutErrorMessage&&(k=o.timeoutErrorMessage),r(new Me(k,C.clarifyTimeoutError?Me.ETIMEDOUT:Me.ECONNABORTED,e,y)),y=null},s===void 0&&i.setContentType(null),"setRequestHeader"in y&&P.forEach(i.toJSON(),function(k,C){y.setRequestHeader(C,k)}),P.isUndefined(o.withCredentials)||(y.withCredentials=!!o.withCredentials),a&&a!=="json"&&(y.responseType=o.responseType),c&&([h,m]=wo(c,!0),y.addEventListener("progress",h)),l&&y.upload&&([f,p]=wo(l),y.upload.addEventListener("progress",f),y.upload.addEventListener("loadend",p)),(o.cancelToken||o.signal)&&(d=S=>{y&&(r(!S||S.type?new dr(null,e,y):S),y.abort(),y=null)},o.cancelToken&&o.cancelToken.subscribe(d),o.signal&&(o.signal.aborted?d():o.signal.addEventListener("abort",d)));const b=Ym(o.url);if(b&&Et.protocols.indexOf(b)===-1){r(new Me("Unsupported protocol "+b+":",Me.ERR_BAD_REQUEST,e));return}y.send(s||null)})},rg=(e,t)=>{const{length:n}=e=e?e.filter(Boolean):[];if(t||n){let r=new AbortController,o;const s=function(c){if(!o){o=!0,a();const d=c instanceof Error?c:this.reason;r.abort(d instanceof Me?d:new dr(d instanceof Error?d.message:d))}};let i=t&&setTimeout(()=>{i=null,s(new Me(`timeout ${t} of ms exceeded`,Me.ETIMEDOUT))},t);const a=()=>{e&&(i&&clearTimeout(i),i=null,e.forEach(c=>{c.unsubscribe?c.unsubscribe(s):c.removeEventListener("abort",s)}),e=null)};e.forEach(c=>c.addEventListener("abort",s));const{signal:l}=r;return l.unsubscribe=()=>P.asap(a),l}},og=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},sg=async function*(e,t){for await(const n of ig(e))yield*og(n,t)},ig=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()}},bl=(e,t,n,r)=>{const o=sg(e,t);let s=0,i,a=l=>{i||(i=!0,r&&r(l))};return new ReadableStream({async pull(l){try{const{done:c,value:d}=await o.next();if(c){a(),l.close();return}let f=d.byteLength;if(n){let h=s+=f;n(h)}l.enqueue(new Uint8Array(d))}catch(c){throw a(c),c}},cancel(l){return a(l),o.return()}},{highWaterMark:2})},wl=64*1024,{isFunction:So}=P,ag=(({Request:e,Response:t})=>({Request:e,Response:t}))(P.global),{ReadableStream:Sl,TextEncoder:Cl}=P.global,Tl=(e,...t)=>{try{return!!e(...t)}catch{return!1}},lg=e=>{e=P.merge.call({skipUndefined:!0},ag,e);const{fetch:t,Request:n,Response:r}=e,o=t?So(t):typeof fetch=="function",s=So(n),i=So(r);if(!o)return!1;const a=o&&So(Sl),l=o&&(typeof Cl=="function"?(m=>g=>m.encode(g))(new Cl):async m=>new Uint8Array(await new n(m).arrayBuffer())),c=s&&a&&Tl(()=>{let m=!1;const g=new n(Et.origin,{body:new Sl,method:"POST",get duplex(){return m=!0,"half"}}).headers.has("Content-Type");return m&&!g}),d=i&&a&&Tl(()=>P.isReadableStream(new r("").body)),f={stream:d&&(m=>m.body)};o&&["text","arrayBuffer","blob","formData","stream"].forEach(m=>{!f[m]&&(f[m]=(g,y)=>{let x=g&&g[m];if(x)return x.call(g);throw new Me(`Response type '${m}' is not supported`,Me.ERR_NOT_SUPPORT,y)})});const h=async m=>{if(m==null)return 0;if(P.isBlob(m))return m.size;if(P.isSpecCompliantForm(m))return(await new n(Et.origin,{method:"POST",body:m}).arrayBuffer()).byteLength;if(P.isArrayBufferView(m)||P.isArrayBuffer(m))return m.byteLength;if(P.isURLSearchParams(m)&&(m=m+""),P.isString(m))return(await l(m)).byteLength},p=async(m,g)=>{const y=P.toFiniteNumber(m.getContentLength());return y??h(g)};return async m=>{let{url:g,method:y,data:x,signal:b,cancelToken:S,timeout:k,onDownloadProgress:C,onUploadProgress:T,responseType:I,headers:A,withCredentials:N="same-origin",fetchOptions:L}=vl(m),R=t||fetch;I=I?(I+"").toLowerCase():"text";let O=rg([b,S&&S.toAbortSignal()],k),F=null;const _=O&&O.unsubscribe&&(()=>{O.unsubscribe()});let B;try{if(T&&c&&y!=="get"&&y!=="head"&&(B=await p(A,x))!==0){let X=new n(g,{method:"POST",body:x,duplex:"half"}),se;if(P.isFormData(x)&&(se=X.headers.get("content-type"))&&A.setContentType(se),X.body){const[be,Ie]=ml(B,wo(gl(T)));x=bl(X.body,wl,be,Ie)}}P.isString(N)||(N=N?"include":"omit");const j=s&&"credentials"in n.prototype,K={...L,signal:O,method:y.toUpperCase(),headers:A.normalize().toJSON(),body:x,duplex:"half",credentials:j?N:void 0};F=s&&new n(g,K);let z=await(s?R(F,L):R(g,K));const M=d&&(I==="stream"||I==="response");if(d&&(C||M&&_)){const X={};["status","statusText","headers"].forEach(Y=>{X[Y]=z[Y]});const se=P.toFiniteNumber(z.headers.get("content-length")),[be,Ie]=C&&ml(se,wo(gl(C),!0))||[];z=new r(bl(z.body,wl,be,()=>{Ie&&Ie(),_&&_()}),X)}I=I||"text";let G=await f[P.findKey(f,I)||"text"](z,m);return!M&&_&&_(),await new Promise((X,se)=>{hl(X,se,{data:G,headers:Ft.from(z.headers),status:z.status,statusText:z.statusText,config:m,request:F})})}catch(j){throw _&&_(),j&&j.name==="TypeError"&&/Load failed|fetch/i.test(j.message)?Object.assign(new Me("Network Error",Me.ERR_NETWORK,m,F),{cause:j.cause||j}):Me.from(j,j&&j.code,m,F)}}},cg=new Map,kl=e=>{let t=e?e.env:{};const{fetch:n,Request:r,Response:o}=t,s=[r,o,n];let i=s.length,a=i,l,c,d=cg;for(;a--;)l=s[a],c=d.get(l),c===void 0&&d.set(l,c=a?new Map:lg(t)),d=c;return c};kl();const si={http:jm,xhr:ng,fetch:{get:kl}};P.forEach(si,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const Il=e=>`- ${e}`,ug=e=>P.isFunction(e)||e===null||e===!1,El={getAdapter:(e,t)=>{e=P.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,!ug(r)&&(o=si[(a=String(r)).toLowerCase()],o===void 0))throw new Me(`Unknown adapter '${a}'`);if(o&&(P.isFunction(o)||(o=o.get(t))))break;s[a||"#"+i]=o}if(!o){const i=Object.entries(s).map(([l,c])=>`adapter ${l} `+(c===!1?"is not supported by the environment":"is not available in the build"));let a=n?i.length>1?`since :
|
|
33
|
+
`+i.map(Il).join(`
|
|
34
|
+
`):" "+Il(i[0]):"as no adapter specified";throw new Me("There is no suitable adapter to dispatch the request "+a,"ERR_NOT_SUPPORT")}return o},adapters:si};function ii(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new dr(null,e)}function Al(e){return ii(e),e.headers=Ft.from(e.headers),e.data=oi.call(e,e.transformRequest),["post","put","patch"].indexOf(e.method)!==-1&&e.headers.setContentType("application/x-www-form-urlencoded",!1),El.getAdapter(e.adapter||Pr.adapter,e)(e).then(function(r){return ii(e),r.data=oi.call(e,e.transformResponse,r),r.headers=Ft.from(r.headers),r},function(r){return pl(r)||(ii(e),r&&r.response&&(r.response.data=oi.call(e,e.transformResponse,r.response),r.response.headers=Ft.from(r.response.headers))),Promise.reject(r)})}const Nl="1.12.2",Co={};["object","boolean","number","function","string","symbol"].forEach((e,t)=>{Co[e]=function(r){return typeof r===e||"a"+(t<1?"n ":" ")+e}});const _l={};Co.transitional=function(t,n,r){function o(s,i){return"[Axios v"+Nl+"] Transitional option '"+s+"'"+i+(r?". "+r:"")}return(s,i,a)=>{if(t===!1)throw new Me(o(i," has been removed"+(n?" in "+n:"")),Me.ERR_DEPRECATED);return n&&!_l[i]&&(_l[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}},Co.spelling=function(t){return(n,r)=>(console.warn(`${r} is likely a misspelling of ${t}`),!0)};function dg(e,t,n){if(typeof e!="object")throw new Me("options must be an object",Me.ERR_BAD_OPTION_VALUE);const r=Object.keys(e);let o=r.length;for(;o-- >0;){const s=r[o],i=t[s];if(i){const a=e[s],l=a===void 0||i(a,s,e);if(l!==!0)throw new Me("option "+s+" must be "+l,Me.ERR_BAD_OPTION_VALUE);continue}if(n!==!0)throw new Me("Unknown option "+s,Me.ERR_BAD_OPTION)}}const To={assertOptions:dg,validators:Co},fn=To.validators;let qn=class{constructor(t){this.defaults=t||{},this.interceptors={request:new cl,response:new cl}}async request(t,n){try{return await this._request(t,n)}catch(r){if(r instanceof Error){let o={};Error.captureStackTrace?Error.captureStackTrace(o):o=new Error;const s=o.stack?o.stack.replace(/^.+\n/,""):"";try{r.stack?s&&!String(r.stack).endsWith(s.replace(/^.+\n.+\n/,""))&&(r.stack+=`
|
|
35
|
+
`+s):r.stack=s}catch{}}throw r}}_request(t,n){typeof t=="string"?(n=n||{},n.url=t):n=t||{},n=Kn(this.defaults,n);const{transitional:r,paramsSerializer:o,headers:s}=n;r!==void 0&&To.assertOptions(r,{silentJSONParsing:fn.transitional(fn.boolean),forcedJSONParsing:fn.transitional(fn.boolean),clarifyTimeoutError:fn.transitional(fn.boolean)},!1),o!=null&&(P.isFunction(o)?n.paramsSerializer={serialize:o}:To.assertOptions(o,{encode:fn.function,serialize:fn.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),To.assertOptions(n,{baseUrl:fn.spelling("baseURL"),withXsrfToken:fn.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let i=s&&P.merge(s.common,s[n.method]);s&&P.forEach(["delete","get","head","post","put","patch","common"],m=>{delete s[m]}),n.headers=Ft.concat(i,s);const a=[];let l=!0;this.interceptors.request.forEach(function(g){typeof g.runWhen=="function"&&g.runWhen(n)===!1||(l=l&&g.synchronous,a.unshift(g.fulfilled,g.rejected))});const c=[];this.interceptors.response.forEach(function(g){c.push(g.fulfilled,g.rejected)});let d,f=0,h;if(!l){const m=[Al.bind(this),void 0];for(m.unshift(...a),m.push(...c),h=m.length,d=Promise.resolve(n);f<h;)d=d.then(m[f++],m[f++]);return d}h=a.length;let p=n;for(;f<h;){const m=a[f++],g=a[f++];try{p=m(p)}catch(y){g.call(this,y);break}}try{d=Al.call(this,p)}catch(m){return Promise.reject(m)}for(f=0,h=c.length;f<h;)d=d.then(c[f++],c[f++]);return d}getUri(t){t=Kn(this.defaults,t);const n=xl(t.baseURL,t.url,t.allowAbsoluteUrls);return ll(n,t.params,t.paramsSerializer)}};P.forEach(["delete","get","head","options"],function(t){qn.prototype[t]=function(n,r){return this.request(Kn(r||{},{method:t,url:n,data:(r||{}).data}))}}),P.forEach(["post","put","patch"],function(t){function n(r){return function(s,i,a){return this.request(Kn(a||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:s,data:i}))}}qn.prototype[t]=n(),qn.prototype[t+"Form"]=n(!0)});let fg=class Uh{constructor(t){if(typeof t!="function")throw new TypeError("executor must be a function.");let n;this.promise=new Promise(function(s){n=s});const r=this;this.promise.then(o=>{if(!r._listeners)return;let s=r._listeners.length;for(;s-- >0;)r._listeners[s](o);r._listeners=null}),this.promise.then=o=>{let s;const i=new Promise(a=>{r.subscribe(a),s=a}).then(o);return i.cancel=function(){r.unsubscribe(s)},i},t(function(s,i,a){r.reason||(r.reason=new dr(s,i,a),n(r.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(t){if(this.reason){t(this.reason);return}this._listeners?this._listeners.push(t):this._listeners=[t]}unsubscribe(t){if(!this._listeners)return;const n=this._listeners.indexOf(t);n!==-1&&this._listeners.splice(n,1)}toAbortSignal(){const t=new AbortController,n=r=>{t.abort(r)};return this.subscribe(n),t.signal.unsubscribe=()=>this.unsubscribe(n),t.signal}static source(){let t;return{token:new Uh(function(o){t=o}),cancel:t}}};function pg(e){return function(n){return e.apply(null,n)}}function hg(e){return P.isObject(e)&&e.isAxiosError===!0}const ai={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(ai).forEach(([e,t])=>{ai[t]=e});function jl(e){const t=new qn(e),n=qa(qn.prototype.request,t);return P.extend(n,qn.prototype,t,{allOwnKeys:!0}),P.extend(n,t,null,{allOwnKeys:!0}),n.create=function(o){return jl(Kn(e,o))},n}const yt=jl(Pr);yt.Axios=qn,yt.CanceledError=dr,yt.CancelToken=fg,yt.isCancel=pl,yt.VERSION=Nl,yt.toFormData=vo,yt.AxiosError=Me,yt.Cancel=yt.CanceledError,yt.all=function(t){return Promise.all(t)},yt.spread=pg,yt.isAxiosError=hg,yt.mergeConfig=Kn,yt.AxiosHeaders=Ft,yt.formToJSON=e=>dl(P.isHTMLForm(e)?new FormData(e):e),yt.getAdapter=El.getAdapter,yt.HttpStatusCode=ai,yt.default=yt;const{Axios:_T,AxiosError:jT,CanceledError:MT,isCancel:RT,CancelToken:PT,VERSION:OT,all:DT,Cancel:LT,isAxiosError:$T,spread:FT,toFormData:BT,AxiosHeaders:zT,HttpStatusCode:UT,formToJSON:HT,getAdapter:WT,mergeConfig:VT}=yt,Ml=typeof window<"u"?window.__API_BASE_URL__:void 0,Rl=Ml?Sn(Ml):void 0;function Sn(e){const n=(e!=null&&e.trim()?e.trim():"/api/chat").replace(/\/+$/,"");return n?n.endsWith("/chat")?n:`${n}/chat`:"/api/chat"}let ko=null;const li=new Set;function Pl(){return ko}function Io(e){ko=e,li.forEach(t=>t(e))}function Ol(e){return li.add(e),()=>li.delete(e)}const mg=3e4,gg=9e4,qt=yt.create({...Rl?{baseURL:Rl}:{},timeout:mg,withCredentials:!0});qt.interceptors.request.use(e=>(ko&&(e.headers.Authorization=`Bearer ${ko}`),e)),qt.interceptors.response.use(e=>{if(typeof window<"u"&&(e!=null&&e.data))try{const t=e.data,n=t.data||{},r=typeof t.token=="string"&&t.token||typeof n.token=="string"&&n.token||null,o=typeof t.expires_at=="number"&&t.expires_at||typeof n.expires_at=="number"&&n.expires_at||typeof t.expiresAt=="number"&&t.expiresAt||typeof n.expiresAt=="number"&&n.expiresAt||null;r&&(localStorage.setItem("authToken",r),Io(r)),o&&localStorage.setItem("authTokenExpiresAt",o.toString()),(r||o)&&window.dispatchEvent(new CustomEvent("smartorg:chat-token-updated",{detail:{token:r,expiresAt:o}}))}catch(t){console.warn("[chat-api] Error storing token:",t)}return e},e=>Promise.reject(e));async function Gt(e,t){return qt.defaults.baseURL?(await qt.get(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}async function ci(e,t,n){return qt.defaults.baseURL?(await qt.post(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function Dl(e,t,n){return qt.defaults.baseURL?(await qt.put(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function Ll(e,t){return qt.defaults.baseURL?(await qt.delete(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}function Yt(e){return e&&typeof e=="object"&&"data"in e?e.data:e}class $l{get baseUrl(){const t=qt.defaults.baseURL;return t?Sn(String(t)):""}updateConfig(t){t.baseUrl&&(qt.defaults.baseURL=Sn(String(t.baseUrl))),t.authToken!==void 0&&Io(t.authToken)}getAuthToken(){return Pl()}setAuthToken(t){Io(t)}onTokenChange(t){return Ol(t)}async listThreads(){const t=await Gt("/threads"),n=Yt(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async createThread(t){const r=await ci("/threads",t?{title:t}:void 0);return Yt(r)}async updateThread(t,n){const r=await Dl(`/threads/${t}`,{title:n});return Yt(r)}async deleteThread(t){const n=await Ll(`/threads/${t}`);return Yt(n)}async threadInfo(t){const n=await Gt(`/threads/${t}/info`);return Yt(n)}async listAgents(){const t=await Gt("/agents"),n=Yt(t);return(n==null?void 0:n.items)??[]}async getAgent(t){const n=await Gt(`/agents/${t}`);return Yt(n)}async getAgentSchema(t){const n=await Gt(`/agents/${t}/schema`);return Yt(n)}async getState(t){const n=await Gt(`/threads/${t.threadId}/state`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return Yt(n)}async getStateHistory(t){const n=await Gt(`/threads/${t.threadId}/state/history`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs},timeout:gg});return Yt(n)}async cancelRun(t){const n=await ci("/runs/cancel",{threadId:t});return Yt(n)}async listCheckpointSummaries(t){const n=await Gt(`/threads/${t}/state/checkpoints`,{params:{thread_id:t}}),r=Yt(n);return(r==null?void 0:r.items)??[]}}const Nn=new $l,Fl=w.createContext(null);function xg({children:e,apiConfig:t}){const n=Nn;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 u.jsx(Fl.Provider,{value:r,children:e})}function ui(){const e=w.useContext(Fl);if(!e)throw new Error("useApi must be used within ApiProvider");return e}async function yg(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 vg(e,t=[],n,r,o,s){const i=[],a=[];for(const l of t)try{const c=await yg(l);a.push({filename:l.name,data:c,mime_type:l.type||"application/octet-stream"})}catch{}return{contentParts:i,filesInfo:a}}const bg={human:"user",user:"user",ai:"assistant",assistant:"assistant",tool:"tool",function:"tool",system:"system"};function di(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 wg(e,t){return`${e??""}::${t??""}`}function fr(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(!di(r))return{threadId:n,latest:null,checkpoints:[],timeline:[],interrupt:null,snapshots:{}};const{orderedSnapshots:o,snapshotMap:s}=Cg(t),i=Bl(r,0),a=Tg(o);return{threadId:n,latest:i,checkpoints:o,timeline:a,interrupt:(i==null?void 0:i.interrupt)??null,snapshots:s}}function Bl(e,t){if(!di(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(N=>!!N&&typeof N=="object").map(N=>({...N})):a===null?null:void 0,c=r.map((N,L)=>Rg(N,L)).filter(N=>!!N),d=Pt(e.config),f=Pt(d==null?void 0:d.configurable),h=ut(f,["checkpoint_id","checkpointId"]),p=ut(f,["checkpoint_ns","checkpointNs"]),m=Pt(e==null?void 0:e.parentConfig),g=Pt(m==null?void 0:m.configurable),y=ut(g,["checkpoint_id","checkpointId"])??null,x=ut(g,["checkpoint_ns","checkpointNs"])??null,b=e==null?void 0:e.createdAt,S=typeof b=="string"&&b.trim()?b:new Date(Date.now()-t).toISOString(),k=c.slice().reverse().find(N=>N.role==="user")??null,C=Pt(e==null?void 0:e.metadata),T=ut(C,["branch_label","branchLabel"]),I=ut(g,["checkpoint_id","checkpointId"]),A=Array.isArray(e.next)?[...e.next]:(e==null?void 0:e.next)===null?null:void 0;return{messages:c,checkpointId:h??null,checkpointNs:p??null,nextCursor:y,nextCursorNs:x,interrupt:Sg(a,c,t),createdAt:S,parentId:I??null,branchLabel:T??null,lastUserMessageId:(k==null?void 0:k.id)??null,hasMessages:c.length>0,messagesLen:c.length,metadata:C??null,config:d??null,parentConfig:m??null,next:A??null,tasks:l??null,values:i??null}}function Sg(e,t,n){const r=jg(e,n);return r||_g(t,n)}function Cg(e){const t=new Map;e.forEach((o,s)=>{if(!di(o))return;const i=Bl(o,s);if(!(i!=null&&i.checkpointId))return;const a=wg(i.checkpointId,i.checkpointNs??null),l=t.get(a);if(!l){t.set(a,i);return}t.set(a,Eg(l,i))});const n=Array.from(t.values());n.sort((o,s)=>Ul(s.createdAt??"")-Ul(o.createdAt??""));const r={};for(const[o,s]of t.entries())r[o]=s;return{orderedSnapshots:n,snapshotMap:r}}function Tg(e){var n,r;const t=[];for(const o of e){const s=o.checkpointId??null;if(!s)continue;const i=o.metadata??{},a=ut(i,["label"])??ut(i,["branch_label","branchLabel"])??ut(i,["description"])??"User input",l=Ig(i,["step"]),c=ut(i,["source"]),d=o.createdAt??null,f=((r=(n=o.messages)==null?void 0:n[o.messages.length-1])==null?void 0:r.id)??null,h=o.lastUserMessageId??f,p=kg(o.next);t.push({id:s,label:a,messageId:h,step:l,source:c??null,createdAt:d,next:p??void 0,parentConfig:o.parentConfig??null})}return t}function kg(e){if(!Array.isArray(e)||e.length===0)return null;const t=e.map(n=>{if(typeof n=="string")return n.trim();if(n&&typeof n=="object"&&"type"in n){const r=n;if(typeof r.type=="string")return r.type}return null}).filter(n=>!!(n&&n.length));return t.length?t.join(", "):null}function Ig(e,t){if(!e)return null;for(const n of t){const r=e[n];if(typeof r=="number"&&Number.isFinite(r))return r}return null}function Eg(e,t){return{...e,metadata:Eo(e.metadata,t.metadata)??null,config:Eo(e.config,t.config)??null,parentConfig:Eo(e.parentConfig,t.parentConfig)??null,next:Ag(e.next,t.next)??null,tasks:Ng(e.tasks,t.tasks)??null,values:Eo(e.values,t.values)??null}}function Eo(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 Ag(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 Ng(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 _g(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 jg(e,t){if(!Array.isArray(e)||!e.length)return null;for(let n=e.length-1;n>=0;n--){const r=Mg(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=Dr(r.interrupts[s],`${o}-interrupt-${s}`);if(i)return i}if(r.state!==void 0&&r.state!==null){const s=Dr(r.state,`${o}-state`);if(s)return s}}return null}function Mg(e,t){if(!e)return null;if(Array.isArray(e)){const[a,l,c,,d,,f,...h]=e,p=typeof a=="string"&&a.trim()?a:t,m=typeof l=="string"&&l.trim()?l:Array.isArray(c)&&typeof c[0]=="string"?String(c[0]):"task",g=Array.isArray(d)?d:void 0,y=h.length?h[h.length-1]:void 0;return{id:p,name:m,interrupts:g,state:y!==void 0?y:f}}const n=Pt(e);if(!n)return null;const r=ut(n,["id","thread_id","taskId"])??t,o=ut(n,["name"])??"task",s=Array.isArray(n.interrupts)?n.interrupts:void 0,i=Object.prototype.hasOwnProperty.call(n,"state")?n.state:void 0;return{id:r,name:o,interrupts:s,state:i}}function Dr(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=zl(e,t);if(o)return o;if(Array.isArray(e)){for(let s=e.length-1;s>=0;s--){const i=Dr(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=Dr(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 c=Dr(l,t,n+1,r);if(c)return c}}return null}function zl(e,t){if(!e)return null;if(typeof e=="object"&&!Array.isArray(e)){const n=e,r=ut(n,["type","event","kind"]),o=ut(n,["id","interrupt_id","interruptId","value_id"])??(r&&r.toLowerCase().includes("interrupt")?t:void 0);if(!(Object.prototype.hasOwnProperty.call(n,"value")||Object.prototype.hasOwnProperty.call(n,"data")||Object.prototype.hasOwnProperty.call(n,"payload"))&&!(r&&r.toLowerCase().includes("interrupt")))return null;const i=Object.prototype.hasOwnProperty.call(n,"value")?n.value:Object.prototype.hasOwnProperty.call(n,"data")?n.data:Object.prototype.hasOwnProperty.call(n,"payload")?n.payload:n,a=o&&o.trim()?o:t;return a?{id:a,value:i}:null}if(Array.isArray(e)){for(let n=e.length-1;n>=0;n--){const r=zl(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 Ul(e){if(!e)return 0;const t=Date.parse(e);return Number.isFinite(t)?t:0}function Rg(e,t){if(!e||typeof e!="object")return null;const n=e,r=Pt(e)??{},o=Pt(n.data)??r,s=String(n.type??o.type??o.role??"").toLowerCase(),i=bg[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}`,c=Pt(o.additional_kwargs)??Pt(o.additionalKwargs),d=Pt(o.response_metadata)??Pt(o.responseMetadata),f=ut(c,["createdAt","created_at"])??ut(o,["created_at","createdAt"]),h=ut(c,["checkpointId","checkpoint_id"]),p=ut(c,["checkpointNs","checkpoint_ns"]),m=Pg(o.content),g={id:l,role:i,content:m};f&&(g.createdAt=f),typeof o.name=="string"&&o.name.trim()&&(g.name=o.name),typeof(d==null?void 0:d.model_name)=="string"&&(g.model=String(d.model_name)),!g.model&&typeof o.model=="string"&&(g.model=o.model),h&&(g.checkpointId=h),p&&(g.checkpointNs=p);const y=Lg(Pt(o.artifact??r.artifact??o.artifacts??r.artifacts));y&&(g.artifact=y);const x=zg(c,["createdAt","created_at","checkpointId","checkpoint_id","checkpointNs","checkpoint_ns","tool_calls"]),b=d?{...d}:void 0;x&&Object.keys(x).length&&(g.additionalKwargs=x),b&&Object.keys(b).length&&(g.responseMetadata=b);const S=Og((c==null?void 0:c.tool_calls)??o.tool_calls);if(S.length&&(g.content=[...g.content,...S]),i==="tool"){const k=Dg(o,g.content);k&&(g.content=k)}return g}function Pg(e){if(!e)return[];if(Array.isArray(e))return e.map(t=>Hl(t)).filter(t=>!!t);if(typeof e=="string")return e.trim()?[{type:"text",text:e.trim()}]:[];if(typeof e=="object"){const t=Hl(e);return t?[t]:[]}return[]}function Hl(e){if(!e||typeof e!="object")return typeof e=="string"&&e.trim()?{type:"text",text:e}:null;const t=e,n=String(t.type??"").toLowerCase();if(!n||n==="text"){const o=typeof t.text=="string"?t.text:typeof t.value=="string"?t.value:"";return o.trim()?{type:"text",text:o}:null}if(n==="image"||n==="image_url"){const o=ut(t,["url","src"]);if(!o)return null;const s={type:"image_url",url:o};return typeof t.mimeType=="string"&&(s.mimeType=t.mimeType),typeof t.alt=="string"&&(s.alt=t.alt),s}if(n==="file"){const o=ut(t,["url"]);if(!o)return null;const s={type:"file",url:o};return typeof t.mimeType=="string"&&(s.mimeType=t.mimeType),typeof t.name=="string"&&(s.name=t.name),typeof t.size=="number"&&(s.size=t.size),typeof t.sourceType=="string"&&(s.sourceType=t.sourceType),s}if(n==="tool_call")return Wl(t)??null;if(n==="tool_end"){const o="output"in t?t.output:t.content;return o?{type:"text",text:typeof o=="string"?o:JSON.stringify(o)}:null}if(n==="interrupt")return{type:"interrupt",value:t.value,...t};if(n==="tool"){const o=ut(t,["text","content"]);if(o)return{type:"text",text:o}}const r=typeof t.content=="string"?t.content:typeof t.value=="string"?t.value:JSON.stringify(t);return r?{type:"text",text:r}:null}function Wl(e,t){var s;const n=ut(e,["id","call_id"])??t,r=ut(e,["name"])??ut(Pt(e.function),["name"]);if(!n||!r)return null;const o=Bg(e.args??e.arguments??((s=Pt(e.function))==null?void 0:s.arguments));return{type:"tool_call",id:n,name:r,args:o}}function Og(e){return Array.isArray(e)?e.map((t,n)=>Wl(t,`tool_call_${n}`)).filter(t=>!!t):[]}function Dg(e,t){const n=e.content??e.output;if(!n)return t;const o={type:"text",text:typeof n=="string"?n:JSON.stringify(n)};return[...t,o]}function Lg(e){return e?{plots:$g(e.plots)}:void 0}function $g(e){return Array.isArray(e)?e.map(t=>Fg(t)).filter(t=>!!t):[]}function Fg(e){if(!e||typeof e!="object")return null;const t=e,n=typeof t.content_base64=="string"&&t.content_base64.trim()||void 0,r=typeof t.url=="string"&&t.url.trim()||void 0,o=(typeof t.format=="string"?t.format.trim():void 0)||(typeof t.mimeType=="string"?t.mimeType.trim():void 0)||(typeof t.mime_type=="string"?t.mime_type.trim():void 0),s=typeof t.plotId=="string"&&t.plotId.trim()||void 0,i=typeof t.artifactId=="string"&&t.artifactId.trim()||void 0,a={};return n&&(a.content_base64=n),r&&(a.url=r),o&&(a.format=o),s&&(a.plotId=s),i&&(a.artifactId=i),a}function Bg(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 Pt(e){if(!(!e||typeof e!="object"||Array.isArray(e)))return{...e}}function ut(e,t){if(e)for(const n of t){const r=e[n];if(typeof r=="string"&&r.trim())return r}}function zg(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}const Vl=120;function Ug(e){if(!Array.isArray(e))return"";const t=e.filter(r=>!!(r&&r.type==="text")).map(r=>(r.text??"").trim()).filter(Boolean);if(!t.length)return"";const n=t.join(" ").replace(/\s+/g," ").trim();return n?n.length>Vl?`${n.slice(0,Vl-3)}…`:n:""}function Kl(e){return Ug(e.content)||""}function Hg(e){const t=new Map;for(const n of e){if(!n.id||n.role!=="user")continue;const r=Kl(n);r&&t.set(n.id,r)}return t}function Wg(e){var n;const t=new Map;for(const r of e){if(!r.checkpointId)continue;const o=(n=r.messages)==null?void 0:n.find(s=>s.role==="user");if(o){const s=Kl(o);s&&t.set(r.checkpointId,s)}}return t}function ql(e={}){const t=w.useMemo(()=>Sn(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),[c,d]=w.useState(null),[f,h]=w.useState(""),[p,m]=w.useState(null),[g,y]=w.useState(0),[x,b]=w.useState(!1),S=w.useRef(null),k=w.useRef(!0),C=w.useRef(0),T=w.useRef(null),I=w.useRef(null),A=w.useRef(null),N=w.useRef(null),L=w.useCallback(_=>{o(_)},[]),R=w.useCallback(()=>{h(""),m(null),d(null),I.current=null,A.current=null,N.current=null},[]),O=w.useCallback(()=>{var _;console.debug("[use-chat] stop() invoked - aborting stream"),(_=S.current)==null||_.abort(),S.current=null,T.current=null,l(!1),b(!1),C.current=0,y(0)},[]),F=w.useCallback((_,B,j)=>{S.current&&(S.current.abort(),S.current=null),l(!0),d(null),e.autoAppendAssistant!==!1&&h(""),m(null),I.current=null,A.current=null,N.current=null;const K=new AbortController;S.current=K;let z=null,M=null,G=!1;return T.current={threadId:_.threadId??null,headers:{}},(async()=>{var se,be,Ie,Y,U,J,$,q,Z,ue,ie,_e,He,oe,ye,Oe,Ye,nt;const X=Xe=>{var qe;try{const it=JSON.parse(JSON.stringify(Xe));return(qe=it==null?void 0:it.payload)!=null&&qe.files_info&&Array.isArray(it.payload.files_info)&&(it.payload.files_info=it.payload.files_info.map(Je=>({...Je,data:Je!=null&&Je.data?`<base64 ${String(Je.data).length} chars>`:Je==null?void 0:Je.data}))),it}catch{return Xe}};try{let Xe={};try{if(r)Xe={Authorization:`Bearer ${r}`};else if(typeof window<"u"){const We=window.__AUTH_TOKEN__,gt=((se=window.localStorage)==null?void 0:se.getItem("authToken"))||null;let Rt=null;try{const re=(be=window.localStorage)==null?void 0:be.getItem("chat-settings");re&&(Rt=((Ie=JSON.parse(re))==null?void 0:Ie.apiKey)||null)}catch{}const H=We||gt||Rt||null;H&&(Xe={Authorization:`Bearer ${H}`})}}catch{}console.debug("[use-chat] POST",t+n,X(_));let qe={};if(typeof window<"u")try{const rt=(Y=window.localStorage)==null?void 0:Y.getItem("authSessionId");rt&&(qe={"X-Session-Id":rt})}catch{}const it={...Xe,...qe,...s.current},Je={"Content-Type":"application/json",Accept:"text/event-stream",...it},et=await fetch(t+n,{method:"POST",headers:Je,body:JSON.stringify(_),signal:K.signal,credentials:i});if(T.current&&(T.current.headers=it),!et.ok||!et.body){const rt=await et.text().catch(()=>"");console.debug("[use-chat] non-OK response",et.status,rt==null?void 0:rt.slice(0,500));const We=`stream ${et.status}${rt?": "+rt:""}`;throw(U=j==null?void 0:j.onConnectionError)==null||U.call(j,We),G=!0,z="error",M=We,new Error(We)}b(!0);const at=et.body.getReader(),jt=new TextDecoder;let ht="",ft=[];C.current=0,y(0);let mt=0,St=null;const Mt=()=>{if(ft.length){const rt=ft.join("");ft=[],k.current&&h(We=>We+rt)}St=null},Lt=()=>{typeof window<"u"&&St==null&&(St=requestAnimationFrame(Mt))};let Vt=Date.now();const Ue=setInterval(()=>{var rt;if(Date.now()-Vt>18e5){const We="Stream idle timeout";d(We),z="error",M=We,K.abort(),(rt=j==null?void 0:j.onError)==null||rt.call(j,We)}},5e3),dn=1024*1024;try{const rt=et.headers.get("X-Thread-Id")||et.headers.get("x-thread-id"),We=et.headers.get("X-Thread-Created")||et.headers.get("x-thread-created"),gt=rt??null,Rt=String(We??"").toLowerCase()==="true";for(T.current&&!T.current.threadId&&(T.current={...T.current,threadId:gt}),(J=j==null?void 0:j.onOpen)==null||J.call(j,{threadId:gt,created:Rt});;){const{value:H,done:re}=await at.read();if(re)break;ht+=jt.decode(H,{stream:!0}),ht.length>dn&&(ht="",console.warn("Stream buffer reset: exceeded 1MB"));let D;for(;(D=ht.indexOf(`
|
|
36
36
|
|
|
37
|
-
`))>=0;){const Q=ht.slice(0,D);ht=ht.slice(D+2);const ne=
|
|
38
|
-
`)}function Kg(e){return e.type!=="token"}const qg={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},toolStreamingMessageId:null,lastBranch:null,messagesStreamMeta:{},pendingInterrupt:null};function Gg(e,t){var n;switch(t.type){case"reset":return{messages:di(((n=t.payload)==null?void 0:n.messages)??[]),assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},toolStreamingMessageId:null,lastBranch:null,pendingInterrupt:null};case"seed":{const r=di(t.payload.messages),o={...e,messages:r,assemblingId:null,pendingInterrupt:t.payload.pendingInterrupt??null,toolStreamingMessageId:null};return Object.prototype.hasOwnProperty.call(t.payload,"checkpointId")&&(o.lastCheckpointId=t.payload.checkpointId??null),Object.prototype.hasOwnProperty.call(t.payload,"checkpointNs")&&(o.lastCheckpointNs=t.payload.checkpointNs??null),o}case"prepend":{const r=di(t.payload.messages);if(!r.length)return e;const o=new Set(e.messages.map(i=>i.id)),s=r.filter(i=>!o.has(i.id));return s.length?{...e,messages:[...s,...e.messages]}: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 Xl(e,t.payload.ev);case"batch":{const{events:r}=t.payload;return r.length?r.reduce((o,s)=>Xl(o,s),e):e}case"interrupt_response":return{...e,messages:Jl(e.messages),pendingInterrupt:null};default:return e}}function Yl(e=[]){const[t,n]=w.useReducer(Gg,{...qg,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 c=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,...c}}function Xl(e,t){var n,r,o,s,i;if(t.type==="message_start"&&t.role==="assistant"){const a=t.id,l=Qg(t.model);if(e.messages.some(f=>f.id===a)){const f=e.messagesStreamMeta??{},p={...f,[a]:f[a]??{lastSeq:t.seq??null,lastText:""}};return{...e,assemblingId:a,messagesStreamMeta:p}}const d={id:a,role:"assistant",name:l||void 0,model:t.model,createdAt:new Date().toISOString(),content:[]};return{...e,assemblingId:a,messages:[...e.messages,d]}}if(t.type==="message_delta"){const a=e.assemblingId??Zl(e.messages);if(!a)return e;const l=e.messages,c=l.findIndex(k=>k.id===a&&k.role==="assistant");if(c===-1)return e;const d=l[c],f=e.messagesStreamMeta??{},p=f[a]??{lastSeq:null,lastText:tc(d.content)},h=t.seq??null;if(h!==null&&typeof h=="number"&&typeof p.lastSeq=="number"&&h<=p.lastSeq)return console.debug("[MessageReducer] skipping delta - seq <= lastSeq",{seq:h,lastSeq:p.lastSeq}),e;const{newParts:m,newMeta:g,changed:y}=Xg(d.content,t.delta,p,h);if(!y)return e;const x={...d,content:m},b=Dr(l,c,x),C={...f,[a]:g};return{...e,messages:b,messagesStreamMeta:C}}if(t.type==="message_end"){const a=e.assemblingId??Zl(e.messages);if(!a)return{...e,assemblingId:null};const l=e.messages,c=l.findIndex(d=>d.id===a&&d.role==="assistant");if(c>=0){const d=l[c];if(!((n=d.content)==null?void 0:n.some(p=>{var h;return(p==null?void 0:p.type)==="text"&&((h=p.text)==null?void 0:h.trim())}))){console.debug("[MessageReducer] pruning assistant message with no visible text",{id:d.id,contentTypes:(r=d.content)==null?void 0:r.map(h=>h==null?void 0:h.type),contentPreview:(o=d.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 p=[...l.slice(0,c),...l.slice(c+1)];return{...e,assemblingId:null,messages:p}}}return e}if(t.type==="tool_start"){const a=Ql(t),l=a[0]??(typeof t.id=="string"?t.id:null)??(typeof t.call_id=="string"?t.call_id:null),c=t.name??t.tool??"tool";!l&&a.length===0&&a.push(`${c}-${Date.now()}`);const d=a.length?a:l?[l]:[],f=ec(e,d,c),p=f>=0?e.messages[f]:null,h=l??d[0]??`${c}-${Date.now()}`,m=(p==null?void 0:p.id)??`tool-${h}`,g=d[0]??h,y={type:"tool_call",id:g,name:c,args:t.args};if(p){const C=pi(p,d,c,t.args),k={...p,name:p.name??c,additionalKwargs:{...C,toolStreaming:!0}},S=f,T=S>=0?Dr(e.messages,S,k):e.messages,I=Ao(k,d),A=hi(e.toolIndex,m,I);return{...e,messages:T,toolIndex:A,toolStreamingMessageId:m}}const x={id:m,role:"tool",name:c,createdAt:new Date().toISOString(),content:[y],additionalKwargs:{...pi(void 0,d.length?d:[g],c,t.args),toolStreaming:!0}},b=Ao(x,d.length?d:[g]);return{...e,messages:[...e.messages,x],toolIndex:hi(e.toolIndex,m,b),toolStreamingMessageId:m}}if(t.type==="tool_end"){const a=Ql(t);if(!a.length&&!(typeof t.id=="string"&&t.id))return e;const l=t.name??null,c=ec(e,a,l),d=c>=0?e.messages[c]:null,f=l??(d==null?void 0:d.name)??((s=d==null?void 0:d.additionalKwargs)==null?void 0:s.toolName)??"tool",p=a[0]??((i=d==null?void 0:d.id)==null?void 0:i.replace(/^tool-/,""))??`${f}-${Date.now()}`,h=(d==null?void 0:d.id)??`tool-${p}`,m=Ao(d,a);let g=t.output;if(typeof t.output=="string")try{const A=t.output.trim();(A.startsWith("{")||A.startsWith("["))&&(g=JSON.parse(A))}catch{g=t.output}const y=t.artifact??(d==null?void 0:d.artifact),x={type:"text",text:typeof g=="string"?g:JSON.stringify(g)},b=(d==null?void 0:d.createdAt)??new Date().toISOString(),k={...pi(d??void 0,m.length?m:a,f)};"toolStreaming"in k&&delete k.toolStreaming;const S={id:h,role:"tool",name:f??(d==null?void 0:d.name)??"tool",content:[x],createdAt:b,artifact:y??void 0,additionalKwargs:k},T=c>=0?Dr(e.messages,c,S):[...e.messages,S],I=Ao(S,a.length?a:m);return{...e,messages:T,toolIndex:hi(e.toolIndex,h,I),toolStreamingMessageId:e.toolStreamingMessageId===h?null:e.toolStreamingMessageId}}if(t.type==="progress"){const a=e.toolStreamingMessageId??Yg(e);if(!a)return e;const l=e.messages.findIndex(g=>g.id===a&&g.role==="tool");if(l===-1)return e;const c=e.messages[l],d={step:t.step??null,title:t.title??null,content:t.content??null,factsFound:typeof t.facts_found=="number"?t.facts_found:null,isSufficient:typeof t.is_sufficient=="boolean"?t.is_sufficient:null,timestamp:new Date().toISOString()},f={...c.additionalKwargs??{}},p=Array.isArray(f.toolProgress)?[...f.toolProgress]:[];p.push(d),f.toolProgress=p.slice(-6),f.toolStreaming=!0;const h={...c,additionalKwargs:f},m=Dr(e.messages,l,h);return{...e,messages:m}}if(t.type==="checkpoint"){const a=t.checkpointNs??e.lastCheckpointNs??null,l=Zg(e.messages,t.checkpointId,a);return{...e,lastCheckpointId:t.checkpointId,lastCheckpointNs:a,messages:l}}if(t.type==="branch"){const a=t.checkpointId??e.lastCheckpointId,l=t.checkpointNs??e.lastCheckpointNs;return{...e,lastBranch:t,lastCheckpointId:a??null,lastCheckpointNs:l??null}}if(t.type==="error"){const a={id:`err-${Date.now()}`,role:"system",content:[{type:"text",text:`Error: ${t.message}`}],createdAt:new Date().toISOString()};return{...e,messages:[...e.messages,a]}}if(t.type==="state_history"){const a=dr(t),l=a.interrupt,c=a.latest,d=l===null?Jl(e.messages):e.messages;return{...e,messages:d,pendingInterrupt:l,lastCheckpointId:(c==null?void 0:c.checkpointId)??e.lastCheckpointId,lastCheckpointNs:(c==null?void 0:c.checkpointNs)??e.lastCheckpointNs}}return t.type==="thread_info",e}function di(e){return e.filter(t=>{var s;if(t.role!=="assistant")return!0;const n=(t.content||[]).some(i=>{var a;return i&&i.type==="text"&&((a=i.text)==null?void 0:a.trim())}),r=(t.content||[]).some(i=>i&&i.type==="image_url"),o=!!((s=t.artifact)!=null&&s.plots&&t.artifact.plots.length>0);return!!(n||r||o)})}function Dr(e,t,n){return t<0||t>=e.length?e:[...e.slice(0,t),n,...e.slice(t+1)]}function Jl(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 Zl(e){for(let t=e.length-1;t>=0;t--)if(e[t].role==="assistant")return e[t].id;return null}function Ql(e){const t=new Set,n=r=>{typeof r=="string"&&r.trim()&&t.add(r.trim())};return n(e.id),n(e==null?void 0:e.call_id),n(e==null?void 0:e.callId),Array.from(t)}function fi(e){if(!e)return[];const t=new Set,n=o=>{typeof o=="string"&&o.trim()&&t.add(o.trim())},r=e.additionalKwargs;if(r){n(r.toolCallId);const o=r.toolCallIds;if(Array.isArray(o))for(const s of o)n(s)}for(const o of e.content??[])(o==null?void 0:o.type)==="tool_call"&&n(o.id);return Array.from(t)}function pi(e,t,n,r){const o=new Set,s=l=>{typeof l=="string"&&l.trim()&&o.add(l.trim())};if(e){const l=fi(e);for(const c of l)s(c)}for(const l of t)s(l);const i=Array.from(o),a={...(e==null?void 0:e.additionalKwargs)??{}};if(i.length){a.toolCallIds=i;const l=typeof a.toolCallId=="string"?a.toolCallId.trim():null;a.toolCallId=l&&o.has(l)?l:i[0]}return n&&(a.toolName=n),r!==void 0&&(a.toolArgs=r),a}function Ao(e,t){const n=new Set;for(const o of t)typeof o=="string"&&o.trim()&&n.add(o.trim());const r=fi(e);for(const o of r)n.add(o);return Array.from(n)}function hi(e,t,n){if(!n.length)return e;let r=!1;const o={...e};for(const s of n)s&&o[s]!==t&&(o[s]=t,r=!0);return r?o:e}function ec(e,t,n){var o,s;const r=new Set(t.filter(i=>typeof i=="string"&&i.trim()));for(const i of r){const a=e.toolIndex[i];if(a){const l=e.messages.findIndex(c=>c.id===a);if(l!==-1)return l}}for(let i=e.messages.length-1;i>=0;i--){const a=e.messages[i];if(a.role!=="tool")continue;if(fi(a).some(c=>r.has(c)))return i}if(typeof n=="string"&&n.trim())for(let i=e.messages.length-1;i>=0;i--){const a=e.messages[i];if(a.role!=="tool"||a.name&&a.name!==n)continue;if(!((o=a.content)==null?void 0:o.some(c=>c.type!=="tool_call")))return i}for(let i=e.messages.length-1;i>=0;i--){const a=e.messages[i];if(a.role!=="tool")continue;if(!((s=a.content)==null?void 0:s.some(c=>c.type!=="tool_call")))return i}return-1}function Yg(e){for(let t=e.messages.length-1;t>=0;t--){const n=e.messages[t];if(n.role!=="tool")continue;if((n.additionalKwargs??{}).toolStreaming)return n.id}return null}function tc(e){return!e||!e.length?"":e.filter(t=>t.type==="text").map(t=>t.text??"").join("")}function Xg(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??tc(e);let l="",c=e.slice();if(s){const f=Jg(a,s);if(f===""?l="":f===s?l=s:l=f,l){const p=c[c.length-1];if((p==null?void 0:p.type)==="text"){const h=p.text??"",m={...p,text:h+l};c=[...c.slice(0,c.length-1),m]}else c=[...c,{type:"text",text:l}];o.lastText=a+l}else o.lastText=a}i.length&&(c=[...c,...i]);const d=!!(l||i.length);return{newParts:c,newMeta:o,changed:d}}function nc(e){return e.replace(/\s+/g," ").trim()}function Jg(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=nc(e),o=nc(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 Zg(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 Dr(e,r,s)}return e}function Qg(e){if(!e)return null;const t=e.split("/");return t[t.length-1]||null}const rc=200;function ex({baseUrl:e,onThreadInfo:t,onMessageEvent:n,onStateHistory:r,onUnhandledEvent:o,onSequenceGap:s,onStreamClosed:i,onConnectionError:a,onAuthError:l,onHeartbeat:c}){const d=w.useRef(null),f=w.useRef(null),p=w.useRef(new Map),h=w.useRef(null),m=w.useRef(null),g=w.useCallback(R=>{try{const O=globalThis.structuredClone;if(typeof O=="function")return O(R)}catch{}try{return JSON.parse(JSON.stringify(R))}catch{return R}},[]),y=w.useCallback((R,O)=>{if(!R)return;const F=p.current.get(R)??[],N=g(O),B=F.length>=rc?[...F.slice(F.length-rc+1),N]:[...F,N];p.current.set(R,B)},[g]),x=w.useCallback(R=>{R&&p.current.set(R,[])},[]),b=w.useCallback(R=>{const O=R??f.current;if(!O)return;const F=p.current.get(O);F!=null&&F.length&&F.forEach(N=>{try{n(N)}catch(B){console.error("[useChatStreamingService] Failed to replay buffered event",B)}})},[n]),C=w.useCallback(R=>{var N,B,j,K,z;const O=R.seq??null;if(O!==null){const M=d.current;if(M!==null){if(O<=M)return;O>M+1&&(s==null||s({from:M,to:O}))}d.current=O}if(R.type==="thread_info"){f.current=R.threadId,h.current&&(h.current.threadIdGuess=R.threadId),m.current=R,x(R.threadId),console.log("[useChatStreamingService] 🎯 Received thread_info event:",R);try{t(R)}catch(M){console.error("[useChatStreamingService] Error in onThreadInfo handler:",M)}return}if(R.type==="heartbeat"){try{c==null||c(R)}catch(M){console.error("[useChatStreamingService] Error in onHeartbeat handler:",M)}return}if(R.type==="error"){const M=R;if(M.error_type==="auth_error"||M.code==="TOKEN_EXPIRED"||((N=M.message)==null?void 0:N.includes("token"))||((B=M.message)==null?void 0:B.includes("401"))||((j=M.message)==null?void 0:j.includes("unauthorized"))||((K=M.message)==null?void 0:K.includes("Unauthorized"))){console.error("[useChatStreamingService] Auth error event detected:",M.message);try{l==null||l(M.message)}catch(X){console.warn("[useChatStreamingService] onAuthError handler failed",X)}}}const F=R.threadId??(R.type==="state_history"?R.threadId:void 0)??f.current??((z=h.current)==null?void 0:z.threadIdGuess)??null;if(R.type==="state_history"){f.current=F??f.current;try{r==null||r(R)}catch(M){console.error("[useChatStreamingService] onStateHistory handler failed",M)}}if(Kg(R)){R.type==="checkpoint"||R.type==="state_history"?x(F??null):y(F??null,R);try{n(R)}catch(M){console.error("[useChatStreamingService] Error in onMessageEvent handler:",M)}return}try{o==null||o(R)}catch(M){console.error("[useChatStreamingService] Error in onUnhandledEvent handler:",M)}},[y,x,n,s,t,r,o]),{stream:k,stop:S,isStreaming:T,error:I,setToken:A}=Gl({baseUrl:e,token:void 0}),_=w.useCallback((R,O)=>{d.current=null,m.current=null,f.current=R.threadId??null,h.current={request:R,callbacks:O,manualStop:!1,threadIdGuess:R.threadId??null},k(R,C,{onOpen:O==null?void 0:O.onOpen,onError:F=>{var N;(N=O==null?void 0:O.onError)==null||N.call(O,F)},onGap:(O==null?void 0:O.onGap)??s,onConnectionError:F=>{var N;a==null||a(F),(N=O==null?void 0:O.onConnectionError)==null||N.call(O,F)},onAuthError:F=>{var N;l==null||l(F),(N=O==null?void 0:O.onAuthError)==null||N.call(O,F)},onHeartbeat:F=>{var N;try{c==null||c(F)}catch(B){console.warn("[useChatStreamingService] onHeartbeat handler failed",B)}try{(N=O==null?void 0:O.onHeartbeat)==null||N.call(O,F)}catch(B){console.warn("[useChatStreamingService] downstream onHeartbeat handler failed",B)}},onClosed:F=>{var K,z,M,G;const N=((K=h.current)==null?void 0:K.manualStop)??!1,B=f.current??((z=h.current)==null?void 0:z.threadIdGuess)??((M=F.lastStateHistory)==null?void 0:M.threadId)??null;(F.reason==="complete"||F.reason==="aborted"&&N)&&x(B);const j={...F,threadId:B,threadInfo:m.current,manualStop:N};try{i==null||i(j)}catch(X){console.warn("[useChatStreamingService] onStreamClosed handler failed",X)}try{(G=O==null?void 0:O.onClosed)==null||G.call(O,j)}catch(X){console.warn("[useChatStreamingService] downstream onClosed handler failed",X)}h.current&&(h.current=null)}})},[x,C,l,a,c,s,i,k]),L=w.useCallback(()=>{h.current&&(h.current.manualStop=!0),S()},[S]);return w.useMemo(()=>({startStream:_,stop:L,isStreaming:T,error:I,setAuthToken:A,replayBufferedEvents:b}),[_,L,T,I,A,b])}const oc=w.createContext(null),sc=w.createContext(null),ic=w.createContext(null);w.createContext(!1);function tx({children:e,initialThreadId:t=null,initialCheckpointId:n=null,initialCheckpointNs:r=null,autoLoadInitial:o=!0,onError:s,onAuthError:i,onThreadChange:a,onConnectionError:l}){const{api:c,baseUrl:d}=ci(),f=w.useMemo(()=>wn(d),[d]),[p,h]=w.useState([]),[m,g]=w.useState(t),[y,x]=w.useState(!1),[b,C]=w.useState(null),[k,S]=w.useState(!1),[T,I]=w.useState(null),{state:A,seed:_,prepend:L,pushUser:R,onEvent:O}=Yl(),[F,N]=w.useState(!1),[B,j]=w.useState(!1),[K,z]=w.useState(null),[M,G]=w.useState([]),[X,se]=w.useState([]),[be,Ie]=w.useState(!1),Y=w.useMemo(()=>Hg(M),[M]),U=w.useRef(m),J=w.useRef(null),$=w.useRef(null),q=w.useRef(null),Z=w.useRef(null),ue=w.useRef(!1),ie=w.useRef(null),_e=w.useRef(new Map),He=w.useRef(new Map);w.useEffect(()=>{U.current=m},[m]);const oe=w.useCallback(async()=>{x(!0),C(null);try{const H=await c.listThreads();h(H??[])}catch(H){const re=String(H);C(re),s==null||s(re)}finally{x(!1)}},[c,s]),ye=w.useCallback(H=>{if(!(H!=null&&H.threadId))return;const re={threadId:H.threadId,title:H.title||`Thread ${H.threadId.slice(0,8)}`,createdAt:H.createdAt||new Date().toISOString(),updatedAt:H.updatedAt||new Date().toISOString(),messageCount:H.messageCount??1};h(D=>{let Q=!1;const ne=D.map(me=>me.threadId===re.threadId?(Q=!0,console.debug("[ChatSessionProvider] thread_info: updating existing thread",re.threadId),{...me,title:re.title??me.title,updatedAt:re.updatedAt??me.updatedAt,messageCount:re.messageCount??me.messageCount}):me);return Q?ne:(console.debug("[ChatSessionProvider] thread_info: adding thread to list",re.threadId),[re,...D])})},[]),Oe=w.useCallback(H=>{const re=H.threadId??U.current;if(!re||U.current&&U.current!==re)return;const{checkpoints:D,timeline:Q}=dr(H);if(!D.length)return;const ne=D.find(me=>me.messages&&me.messages.length>0)??D.find(me=>!!me.checkpointId)??D[0];_((ne==null?void 0:ne.messages)??[],{checkpointId:(ne==null?void 0:ne.checkpointId)??null,checkpointNs:(ne==null?void 0:ne.checkpointNs)??null}),se(Q),G(D),N(!!(ne!=null&&ne.nextCursor)),z((ne==null?void 0:ne.nextCursor)??null),ie.current=`${re}:latest`,$.current=null,q.current=null},[_]),Ye=w.useCallback(H=>{console.log("[ChatSessionProvider] 🎯 Received thread_info:",H.threadId),ye(H),U.current!==H.threadId&&((H.created??!U.current)&&($.current=H.threadId),q.current=H.threadId,console.log("[ChatSessionProvider] thread_info: marking to skip auto-load for new thread"),g(H.threadId))},[ye]),{startStream:nt,stop:Xe,isStreaming:qe,error:it,setAuthToken:Je}=ex({baseUrl:f,onThreadInfo:Ye,onMessageEvent:O,onStateHistory:Oe,onUnhandledEvent:H=>{console.warn("[ChatSessionProvider] Unhandled event:",H.type)},onAuthError:i,onConnectionError:l}),et=w.useCallback(async H=>{try{const re=await c.createThread(H);return g(re.threadId),await oe(),re.threadId}catch(re){return s==null||s(String(re)),null}},[c,oe,s]),at=w.useCallback(async H=>{const re=p;h(Q=>Q.filter(ne=>ne.threadId!==H));const D=new AbortController;He.current.set(H,D);try{await c.deleteThread(H),U.current===H&&(g(null),_([],{})),console.log("[ChatSessionProvider] Thread deleted successfully:",H)}catch(Q){console.error("[ChatSessionProvider] Delete failed, restoring thread:",H,Q),h(re),s==null||s(`Failed to delete thread: ${String(Q)}`)}finally{He.current.delete(H)}},[p,c,_,s]),_t=w.useCallback(async(H,re)=>{try{await c.updateThread(H,re),await oe()}catch(D){s==null||s(String(D))}},[c,oe,s]),ht=w.useCallback(async(H,re)=>{if(!H)return;const D=`${H}:${re??"latest"}`,Q=_e.current.get(D);if(Q)return Q;const ne=(async()=>{const me=H;S(!0),I(null);try{const xe=await c.getStateHistory({threadId:me,checkpointId:re||void 0});if(U.current!==me){console.log(`[ChatSessionProvider] Thread changed during load (was ${me}, now ${U.current}), discarding stale data`);return}const{checkpoints:De,timeline:Re}=dr(xe),je=De.find(Vt=>Vt.messages&&Vt.messages.length>0)??(re?De.find(Vt=>Vt.checkpointId===re):null)??De[0];_((je==null?void 0:je.messages)??[],{checkpointId:(je==null?void 0:je.checkpointId)??null,checkpointNs:(je==null?void 0:je.checkpointNs)??null}),se(Re),G(De),N(!!(je!=null&&je.nextCursor)),z((je==null?void 0:je.nextCursor)??null)}catch(xe){if(U.current===me){const De=String(xe);I(De),s==null||s(De)}}finally{S(!1)}})();_e.current.set(D,ne);try{await ne}finally{_e.current.delete(D)}return U.current===H&&(ie.current=D),ne},[c,_,s]),ft=w.useCallback(async(H,re)=>{Z.current=H;try{await ht(H,re)}finally{Z.current===H&&(Z.current=null)}},[ht]);w.useEffect(()=>{if(!o||!m||k||qe)return;if($.current===m){$.current=null,J.current=m;return}if(q.current===m){J.current=m;return}if(Z.current===m){Z.current=null,J.current=m;return}if(J.current===m)return;J.current=m;const H=!ue.current&&!!n&&m===t;let re;H&&n?(re=n,ue.current=!0,console.log("[ChatSessionProvider] Loading thread with checkpoint:",re,r?`(ns: ${r})`:"")):console.log("[ChatSessionProvider] Loading thread with latest checkpoint");const D=`${m}:${re??"latest"}`;ie.current!==D&&ft(m,re)},[o,m,n,r,t,k,qe,ft]);const mt=w.useCallback(async(H,re)=>{const D=U.current;if(!D)return;const Q=D;Ie(!0);try{const ne=await c.getStateHistory({threadId:Q,checkpointId:H,checkpointNs:re??void 0});if(U.current!==Q){console.log(`[ChatSessionProvider] Thread changed during checkpoint navigation (was ${Q}, now ${U.current}), discarding stale data`);return}const{checkpoints:me,timeline:xe}=dr(ne),De=me.find(Re=>Re.checkpointId===H&&(re?Re.checkpointNs===re:!0));if(!De){console.warn("[ChatSessionProvider] Requested checkpoint not found:",{checkpointId:H,checkpointNs:re});return}se(xe),G(me),_(De.messages??[],{checkpointId:De.checkpointId??null,checkpointNs:De.checkpointNs??null})}catch(ne){U.current===Q&&(s==null||s(String(ne)))}finally{Ie(!1)}},[c,_,s]),St=w.useCallback((H,re)=>{_(A.messages,{checkpointId:H??null,checkpointNs:re??null})},[_,A.messages]),jt=w.useCallback(async()=>{U.current&&await ft(U.current)},[ft]),Dt=w.useCallback(async()=>{if(!U.current||!K)return;const H=U.current;j(!0);try{const re=await c.getStateHistory({threadId:H,checkpointId:K});if(U.current!==H)return;const{checkpoints:D}=dr(re);if(D.length>0){const Q=D[D.length-1];L((Q==null?void 0:Q.messages)??[]),N(!!(Q!=null&&Q.nextCursor)),z((Q==null?void 0:Q.nextCursor)??null)}}catch(re){U.current===H&&(s==null||s(String(re)))}finally{j(!1)}},[c,K,L,s]),Wt=w.useCallback(async()=>{_([],{}),g(null),Xe(),G([]),se([]),N(!1),z(null),S(!1),Ie(!1),j(!1),I(null);try{await c.getAgent("default")}catch(H){console.warn("[ChatSessionProvider] Failed to refetch agent after clearing thread:",H)}},[_,Xe,c]),Ue=w.useCallback(async(H,re,D)=>{const Q=U.current;if(!Q)throw new Error("No active thread to handle interrupt");const ne=re?D??!0:!1;try{const me={threadId:Q,checkpointId:A.lastCheckpointId??void 0,checkpointNs:A.lastCheckpointNs??void 0,command:{kind:"resume",value:ne}};nt(me)}catch(me){throw console.error(`[ChatSessionProvider] Failed to handle interrupt ${H}:`,me),me}},[A.lastCheckpointId,A.lastCheckpointNs,nt]);w.useEffect(()=>{oe()},[oe]),w.useEffect(()=>{a==null||a(m)},[m,a]);const un=w.useCallback(async(H,re)=>{let D=U.current;const Q=(H==null?void 0:H.text)??"",ne=(H==null?void 0:H.attachments)??[],me=(Q==null?void 0:Q.trim())??"",xe={...(H==null?void 0:H.payload)??{}},De=Array.isArray(xe.messages)?xe.messages:void 0;De&&delete xe.messages;const Re=!!(De&&De.length);if(!D&&!me&&ne.length===0&&!Re)return;if(!D){const ae=Math.floor(Date.now()/1e3).toString(16).padStart(8,"0"),we=Array.from({length:4},()=>Math.floor(Math.random()*4294967295).toString(16).padStart(8,"0")).join("").slice(0,16);D=`${ae}${we}`,$.current=D,g(D)}const{contentParts:je,filesInfo:Vt}=await yg(c,ne),En=[...je];me&&En.push({type:"text",text:Q});const ir=re==null?void 0:re.originalMessageId,Er=!!(re!=null&&re.edit&&ir),fo=!Re&&En.length>0;let zn=null;fo&&(zn={id:Er?ir:`msg-${Date.now()}`,role:"user",content:En,createdAt:new Date().toISOString()},Er||R(zn));const ar=Re?De:zn?[zn]:[],E={...xe,...Vt.length?{files_info:Vt}:{}};ar.length?E.messages=ar:"messages"in E||(E.messages=[]);const V={threadId:D,payload:E,checkpointId:(re==null?void 0:re.checkpointId)??A.lastCheckpointId??void 0,checkpointNs:(re==null?void 0:re.checkpointNs)??A.lastCheckpointNs??void 0,edit:!!(re!=null&&re.edit),timelineCheckpoints:X};nt(V)},[c,R,A,nt,X]),rt=w.useMemo(()=>({threads:p,currentThreadId:m,setCurrentThreadId:g,isLoading:y,error:b,actions:{createThread:et,deleteThread:at,renameThread:_t,refreshThreads:oe}}),[p,m,y,b,et,at,_t,oe]),We=w.useMemo(()=>{const H=A.assemblingId??null;return H?{assemblingMessageId:H}:null},[A.assemblingId]),gt=w.useMemo(()=>({threadId:m,messages:A.messages,interrupt:null,checkpoint:{id:A.lastCheckpointId??null,namespace:A.lastCheckpointNs??null},checkpoints:M,timelineCheckpoints:X,metadata:We,isLoading:k,isHistoryLoading:B,isLoadingCheckpoint:be,error:T,hasMore:F,loadOlder:Dt,clearState:Wt,navigateToCheckpoint:mt,setCurrentCheckpointId:St,returnToLatest:jt,loadThread:ft,clearThread:Wt,respondToInterrupt:Ue,messagePreviews:Y}),[m,A,M,X,k,B,be,T,F,Dt,Wt,mt,St,jt,ft,Ue,Y,We]),Mt=w.useMemo(()=>({isStreaming:qe,error:it,connectionState:qe?"connected":"idle",submit:un,send:un,stop:Xe,setAuthToken:Je}),[qe,it,un,Xe,Je]);return u.jsx(oc.Provider,{value:rt,children:u.jsx(sc.Provider,{value:gt,children:u.jsx(ic.Provider,{value:Mt,children:e})})})}function No(){const e=w.useContext(oc);if(!e)throw new Error("useThreads must be used within ChatSessionProvider");return e}function _o(){const e=w.useContext(sc);if(!e)throw new Error("useThreadState must be used within ChatSessionProvider");return e}function ac(){const e=w.useContext(ic);if(!e)throw new Error("useStream must be used within ChatSessionProvider");return e}function jo({children:e,apiConfig:t,initialThreadId:n=null,initialCheckpointId:r=null,initialCheckpointNs:o=null,autoLoadInitial:s=!0,onConnectionError:i,onError:a,onAuthError:l,onThreadChange:c}){return u.jsx(gg,{apiConfig:t,children:u.jsx(tx,{initialThreadId:n,initialCheckpointId:r,initialCheckpointNs:o,autoLoadInitial:s,onError:a,onAuthError:l,onConnectionError:i,onThreadChange:c,children:e})})}function te(...e){return Hh.twMerge(Uh.clsx(e))}const nx=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"}}),Ze=v.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?Hn.Slot:"button";return u.jsx(i,{className:te(nx({variant:t,size:n,className:e})),ref:s,...o})});Ze.displayName="Button";const lc=v.forwardRef(({className:e,...t},n)=>u.jsx("textarea",{className:te("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}));lc.displayName="Textarea";function cc({initialValue:e="",editingMessageId:t=null,placeholder:n="Type your message...",isStreaming:r=!1,disabled:o=!1,maxLength:s=2e4,value:i,onValueChange:a,onSend:l,onCancelEdit:c,onStop:d,className:f="",textareaClassName:p="",allowEmptySend:h=!1}){const m=i!==void 0,[g,y]=w.useState(e),x=(m?i:g)??"",[b,C]=w.useTransition(),k=w.useRef(null),S=w.useRef(0),T=w.useRef(null);w.useEffect(()=>{m||(y(e??""),T.current=null,k.current&&(k.current.style.height="auto",k.current.style.height=`${k.current.scrollHeight}px`))},[e,t,m]);const I=w.useCallback(()=>{const B=k.current;B&&(B.style.height="auto",B.style.height=`${B.scrollHeight}px`)},[]);w.useEffect(()=>{I()},[I,x]);const A=w.useCallback((B,{fromUser:j})=>{m||y(B),j&&(a==null||a(B))},[m,a]),_=w.useCallback(async B=>{B&&B.preventDefault();const j=(x??"").trim();if(!j&&!h)return;const K=++S.current;T.current={id:K,shouldClear:!0},C(()=>{var z,M,G;try{const X=l(j);X&&typeof X.then=="function"?X.then(()=>{var se,be;((se=T.current)==null?void 0:se.id)===K&&T.current.shouldClear&&(m||(y(""),k.current&&(k.current.style.height="auto"),a==null||a(""))),((be=T.current)==null?void 0:be.id)===K&&(T.current=null)}).catch(()=>{var se;((se=T.current)==null?void 0:se.id)===K&&(T.current=null)}):(((z=T.current)==null?void 0:z.id)===K&&T.current.shouldClear&&(m||(y(""),k.current&&(k.current.style.height="auto"),a==null||a(""))),((M=T.current)==null?void 0:M.id)===K&&(T.current=null))}catch{((G=T.current)==null?void 0:G.id)===K&&(T.current=null)}})},[x,l,h,m,a]),L=w.useCallback(B=>{const j=B.target.value;A(j,{fromUser:!0}),T.current&&(T.current.shouldClear=!1),k.current&&(k.current.style.height="auto",k.current.style.height=`${k.current.scrollHeight}px`)},[A]),R=w.useCallback(B=>{B.key==="Enter"&&!B.shiftKey?(B.preventDefault(),_()):B.key==="Escape"&&t&&(B.preventDefault(),c==null||c())},[_,t,c]),N=`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${t?"border-[hsl(var(--ring))] bg-[hsl(var(--card))] text-[hsl(var(--card-foreground))] dark:bg-[hsl(var(--card))] dark:text-[hsl(var(--card-foreground))]":""} ${p}`;return u.jsx("form",{onSubmit:B=>void _(B),className:`w-full ${f}`,children:u.jsxs("div",{className:"flex items-end gap-2",children:[u.jsx("div",{className:"flex-1",children:u.jsx(lc,{ref:k,value:x,onChange:L,onKeyDown:R,placeholder:t?"Edit your message...":n,className:N,disabled:o,maxLength:s,rows:1,spellCheck:!1,autoCorrect:"off"})}),u.jsx("div",{children:r?u.jsx(Ze,{type:"button",onClick:()=>{d==null||d()},size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",disabled:o||!d,children:u.jsx(le.Square,{size:16})}):u.jsx(Ze,{type:"submit",size:"icon",className:"shrink-0",title:t?"Save changes":"Send message",disabled:o||!x.trim()&&!h||b,children:u.jsx(le.Send,{size:16})})})]})})}const rx=w.memo(cc);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 uc(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function mi(...e){return t=>{let n=!1;const r=e.map(o=>{const s=uc(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():uc(e[o],null)}}}}function Be(...e){return v.useCallback(mi(...e),e)}function ox(e,t){const n=v.createContext(t),r=s=>{const{children:i,...a}=s,l=v.useMemo(()=>a,Object.values(a));return u.jsx(n.Provider,{value:l,children:i})};r.displayName=e+"Provider";function o(s){const i=v.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 Sn(e,t=[]){let n=[];function r(s,i){const a=v.createContext(i),l=n.length;n=[...n,i];const c=f=>{var x;const{scope:p,children:h,...m}=f,g=((x=p==null?void 0:p[e])==null?void 0:x[l])||a,y=v.useMemo(()=>m,Object.values(m));return u.jsx(g.Provider,{value:y,children:h})};c.displayName=s+"Provider";function d(f,p){var g;const h=((g=p==null?void 0:p[e])==null?void 0:g[l])||a,m=v.useContext(h);if(m)return m;if(i!==void 0)return i;throw new Error(`\`${f}\` must be used within \`${s}\``)}return[c,d]}const o=()=>{const s=n.map(i=>v.createContext(i));return function(a){const l=(a==null?void 0:a[e])||s;return v.useMemo(()=>({[`__scope${e}`]:{...a,[e]:l}}),[a,l])}};return o.scopeName=e,[r,sx(o,...t)]}function sx(...e){const t=e[0];if(e.length===1)return t;const n=()=>{const r=e.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(s){const i=r.reduce((a,{useScope:l,scopeName:c})=>{const f=l(s)[`__scope${c}`];return{...a,...f}},{});return v.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}var Ct=globalThis!=null&&globalThis.document?v.useLayoutEffect:()=>{},ix=v[" useInsertionEffect ".trim().toString()]||Ct;function fr({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=ax({defaultProp:t,onChange:n}),a=e!==void 0,l=a?e:o;{const d=v.useRef(e!==void 0);v.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 c=v.useCallback(d=>{var f;if(a){const p=lx(d)?d(e):d;p!==e&&((f=i.current)==null||f.call(i,p))}else s(d)},[a,e,s,i]);return[l,c]}function ax({defaultProp:e,onChange:t}){const[n,r]=v.useState(e),o=v.useRef(n),s=v.useRef(t);return ix(()=>{s.current=t},[t]),v.useEffect(()=>{var i;o.current!==n&&((i=s.current)==null||i.call(s,n),o.current=n)},[n,o]),[n,r,s]}function lx(e){return typeof e=="function"}var cx=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Ne=cx.reduce((e,t)=>{const n=Hn.createSlot(`Primitive.${t}`),r=v.forwardRef((o,s)=>{const{asChild:i,...a}=o,l=i?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),u.jsx(l,{...a,ref:s})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function dc(e,t){e&&ho.flushSync(()=>e.dispatchEvent(t))}function gi(e){const t=e+"CollectionProvider",[n,r]=Sn(t),[o,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),i=g=>{const{scope:y,children:x}=g,b=w.useRef(null),C=w.useRef(new Map).current;return u.jsx(o,{scope:y,itemMap:C,collectionRef:b,children:x})};i.displayName=t;const a=e+"CollectionSlot",l=Hn.createSlot(a),c=w.forwardRef((g,y)=>{const{scope:x,children:b}=g,C=s(a,x),k=Be(y,C.collectionRef);return u.jsx(l,{ref:k,children:b})});c.displayName=a;const d=e+"CollectionItemSlot",f="data-radix-collection-item",p=Hn.createSlot(d),h=w.forwardRef((g,y)=>{const{scope:x,children:b,...C}=g,k=w.useRef(null),S=Be(y,k),T=s(d,x);return w.useEffect(()=>(T.itemMap.set(k,{ref:k,...C}),()=>void T.itemMap.delete(k))),u.jsx(p,{[f]:"",ref:S,children:b})});h.displayName=d;function m(g){const y=s(e+"CollectionConsumer",g);return w.useCallback(()=>{const b=y.collectionRef.current;if(!b)return[];const C=Array.from(b.querySelectorAll(`[${f}]`));return Array.from(y.itemMap.values()).sort((T,I)=>C.indexOf(T.ref.current)-C.indexOf(I.ref.current))},[y.collectionRef,y.itemMap])}return[{Provider:i,Slot:c,ItemSlot:h},m,r]}var ux=v.createContext(void 0);function Mo(e){const t=v.useContext(ux);return e||t||"ltr"}function Tt(e){const t=v.useRef(e);return v.useEffect(()=>{t.current=e}),v.useMemo(()=>(...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)},[])}function dx(e,t=globalThis==null?void 0:globalThis.document){const n=Tt(e);v.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 fx="DismissableLayer",xi="dismissableLayer.update",px="dismissableLayer.pointerDownOutside",hx="dismissableLayer.focusOutside",fc,pc=v.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),Ro=v.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:a,...l}=e,c=v.useContext(pc),[d,f]=v.useState(null),p=(d==null?void 0:d.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,h]=v.useState({}),m=Be(t,I=>f(I)),g=Array.from(c.layers),[y]=[...c.layersWithOutsidePointerEventsDisabled].slice(-1),x=g.indexOf(y),b=d?g.indexOf(d):-1,C=c.layersWithOutsidePointerEventsDisabled.size>0,k=b>=x,S=xx(I=>{const A=I.target,_=[...c.branches].some(L=>L.contains(A));!k||_||(o==null||o(I),i==null||i(I),I.defaultPrevented||a==null||a())},p),T=yx(I=>{const A=I.target;[...c.branches].some(L=>L.contains(A))||(s==null||s(I),i==null||i(I),I.defaultPrevented||a==null||a())},p);return dx(I=>{b===c.layers.size-1&&(r==null||r(I),!I.defaultPrevented&&a&&(I.preventDefault(),a()))},p),v.useEffect(()=>{if(d)return n&&(c.layersWithOutsidePointerEventsDisabled.size===0&&(fc=p.body.style.pointerEvents,p.body.style.pointerEvents="none"),c.layersWithOutsidePointerEventsDisabled.add(d)),c.layers.add(d),hc(),()=>{n&&c.layersWithOutsidePointerEventsDisabled.size===1&&(p.body.style.pointerEvents=fc)}},[d,p,n,c]),v.useEffect(()=>()=>{d&&(c.layers.delete(d),c.layersWithOutsidePointerEventsDisabled.delete(d),hc())},[d,c]),v.useEffect(()=>{const I=()=>h({});return document.addEventListener(xi,I),()=>document.removeEventListener(xi,I)},[]),u.jsx(Ne.div,{...l,ref:m,style:{pointerEvents:C?k?"auto":"none":void 0,...e.style},onFocusCapture:fe(e.onFocusCapture,T.onFocusCapture),onBlurCapture:fe(e.onBlurCapture,T.onBlurCapture),onPointerDownCapture:fe(e.onPointerDownCapture,S.onPointerDownCapture)})});Ro.displayName=fx;var mx="DismissableLayerBranch",gx=v.forwardRef((e,t)=>{const n=v.useContext(pc),r=v.useRef(null),o=Be(t,r);return v.useEffect(()=>{const s=r.current;if(s)return n.branches.add(s),()=>{n.branches.delete(s)}},[n.branches]),u.jsx(Ne.div,{...e,ref:o})});gx.displayName=mx;function xx(e,t=globalThis==null?void 0:globalThis.document){const n=Tt(e),r=v.useRef(!1),o=v.useRef(()=>{});return v.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let l=function(){mc(px,n,c,{discrete:!0})};const c={originalEvent:a};a.pointerType==="touch"?(t.removeEventListener("click",o.current),o.current=l,t.addEventListener("click",o.current,{once:!0})):l()}else t.removeEventListener("click",o.current);r.current=!1},i=window.setTimeout(()=>{t.addEventListener("pointerdown",s)},0);return()=>{window.clearTimeout(i),t.removeEventListener("pointerdown",s),t.removeEventListener("click",o.current)}},[t,n]),{onPointerDownCapture:()=>r.current=!0}}function yx(e,t=globalThis==null?void 0:globalThis.document){const n=Tt(e),r=v.useRef(!1);return v.useEffect(()=>{const o=s=>{s.target&&!r.current&&mc(hx,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 hc(){const e=new CustomEvent(xi);document.dispatchEvent(e)}function mc(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?dc(o,s):o.dispatchEvent(s)}var yi=0;function vi(){v.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??gc()),document.body.insertAdjacentElement("beforeend",e[1]??gc()),yi++,()=>{yi===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),yi--}},[])}function gc(){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 bi="focusScope.autoFocusOnMount",wi="focusScope.autoFocusOnUnmount",xc={bubbles:!1,cancelable:!0},vx="FocusScope",Po=v.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:s,...i}=e,[a,l]=v.useState(null),c=Tt(o),d=Tt(s),f=v.useRef(null),p=Be(t,g=>l(g)),h=v.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;v.useEffect(()=>{if(r){let g=function(C){if(h.paused||!a)return;const k=C.target;a.contains(k)?f.current=k:Nn(f.current,{select:!0})},y=function(C){if(h.paused||!a)return;const k=C.relatedTarget;k!==null&&(a.contains(k)||Nn(f.current,{select:!0}))},x=function(C){if(document.activeElement===document.body)for(const S of C)S.removedNodes.length>0&&Nn(a)};document.addEventListener("focusin",g),document.addEventListener("focusout",y);const b=new MutationObserver(x);return a&&b.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",g),document.removeEventListener("focusout",y),b.disconnect()}}},[r,a,h.paused]),v.useEffect(()=>{if(a){bc.add(h);const g=document.activeElement;if(!a.contains(g)){const x=new CustomEvent(bi,xc);a.addEventListener(bi,c),a.dispatchEvent(x),x.defaultPrevented||(bx(kx(yc(a)),{select:!0}),document.activeElement===g&&Nn(a))}return()=>{a.removeEventListener(bi,c),setTimeout(()=>{const x=new CustomEvent(wi,xc);a.addEventListener(wi,d),a.dispatchEvent(x),x.defaultPrevented||Nn(g??document.body,{select:!0}),a.removeEventListener(wi,d),bc.remove(h)},0)}}},[a,c,d,h]);const m=v.useCallback(g=>{if(!n&&!r||h.paused)return;const y=g.key==="Tab"&&!g.altKey&&!g.ctrlKey&&!g.metaKey,x=document.activeElement;if(y&&x){const b=g.currentTarget,[C,k]=wx(b);C&&k?!g.shiftKey&&x===k?(g.preventDefault(),n&&Nn(C,{select:!0})):g.shiftKey&&x===C&&(g.preventDefault(),n&&Nn(k,{select:!0})):x===b&&g.preventDefault()}},[n,r,h.paused]);return u.jsx(Ne.div,{tabIndex:-1,...i,ref:p,onKeyDown:m})});Po.displayName=vx;function bx(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(Nn(r,{select:t}),document.activeElement!==n)return}function wx(e){const t=yc(e),n=vc(t,e),r=vc(t.reverse(),e);return[n,r]}function yc(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 vc(e,t){for(const n of e)if(!Sx(n,{upTo:t}))return n}function Sx(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 Cx(e){return e instanceof HTMLInputElement&&"select"in e}function Nn(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&Cx(e)&&t&&e.select()}}var bc=Tx();function Tx(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=wc(e,t),e.unshift(t)},remove(t){var n;e=wc(e,t),(n=e[0])==null||n.resume()}}}function wc(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function kx(e){return e.filter(t=>t.tagName!=="A")}var Ix=v[" useId ".trim().toString()]||(()=>{}),Ex=0;function Cn(e){const[t,n]=v.useState(Ix());return Ct(()=>{n(r=>r??String(Ex++))},[e]),t?`radix-${t}`:""}const Ax=["top","right","bottom","left"],_n=Math.min,Bt=Math.max,Oo=Math.round,Do=Math.floor,fn=e=>({x:e,y:e}),Nx={left:"right",right:"left",bottom:"top",top:"bottom"},_x={start:"end",end:"start"};function Si(e,t,n){return Bt(e,_n(t,n))}function Tn(e,t){return typeof e=="function"?e(t):e}function kn(e){return e.split("-")[0]}function pr(e){return e.split("-")[1]}function Ci(e){return e==="x"?"y":"x"}function Ti(e){return e==="y"?"height":"width"}const jx=new Set(["top","bottom"]);function pn(e){return jx.has(kn(e))?"y":"x"}function ki(e){return Ci(pn(e))}function Mx(e,t,n){n===void 0&&(n=!1);const r=pr(e),o=ki(e),s=Ti(o);let i=o==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(i=Lo(i)),[i,Lo(i)]}function Rx(e){const t=Lo(e);return[Ii(e),t,Ii(t)]}function Ii(e){return e.replace(/start|end/g,t=>_x[t])}const Sc=["left","right"],Cc=["right","left"],Px=["top","bottom"],Ox=["bottom","top"];function Dx(e,t,n){switch(e){case"top":case"bottom":return n?t?Cc:Sc:t?Sc:Cc;case"left":case"right":return t?Px:Ox;default:return[]}}function Lx(e,t,n,r){const o=pr(e);let s=Dx(kn(e),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(Ii)))),s}function Lo(e){return e.replace(/left|right|bottom|top/g,t=>Nx[t])}function $x(e){return{top:0,right:0,bottom:0,left:0,...e}}function Tc(e){return typeof e!="number"?$x(e):{top:e,right:e,bottom:e,left:e}}function $o(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 kc(e,t,n){let{reference:r,floating:o}=e;const s=pn(t),i=ki(t),a=Ti(i),l=kn(t),c=s==="y",d=r.x+r.width/2-o.width/2,f=r.y+r.height/2-o.height/2,p=r[a]/2-o[a]/2;let h;switch(l){case"top":h={x:d,y:r.y-o.height};break;case"bottom":h={x:d,y:r.y+r.height};break;case"right":h={x:r.x+r.width,y:f};break;case"left":h={x:r.x-o.width,y:f};break;default:h={x:r.x,y:r.y}}switch(pr(t)){case"start":h[i]-=p*(n&&c?-1:1);break;case"end":h[i]+=p*(n&&c?-1:1);break}return h}const Fx=async(e,t,n)=>{const{placement:r="bottom",strategy:o="absolute",middleware:s=[],platform:i}=n,a=s.filter(Boolean),l=await(i.isRTL==null?void 0:i.isRTL(t));let c=await i.getElementRects({reference:e,floating:t,strategy:o}),{x:d,y:f}=kc(c,r,l),p=r,h={},m=0;for(let g=0;g<a.length;g++){const{name:y,fn:x}=a[g],{x:b,y:C,data:k,reset:S}=await x({x:d,y:f,initialPlacement:r,placement:p,strategy:o,middlewareData:h,rects:c,platform:i,elements:{reference:e,floating:t}});d=b??d,f=C??f,h={...h,[y]:{...h[y],...k}},S&&m<=50&&(m++,typeof S=="object"&&(S.placement&&(p=S.placement),S.rects&&(c=S.rects===!0?await i.getElementRects({reference:e,floating:t,strategy:o}):S.rects),{x:d,y:f}=kc(c,p,l)),g=-1)}return{x:d,y:f,placement:p,strategy:o,middlewareData:h}};async function Lr(e,t){var n;t===void 0&&(t={});const{x:r,y:o,platform:s,rects:i,elements:a,strategy:l}=e,{boundary:c="clippingAncestors",rootBoundary:d="viewport",elementContext:f="floating",altBoundary:p=!1,padding:h=0}=Tn(t,e),m=Tc(h),y=a[p?f==="floating"?"reference":"floating":f],x=$o(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(y)))==null||n?y:y.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(a.floating)),boundary:c,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)),k=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},S=$o(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:b,offsetParent:C,strategy:l}):b);return{top:(x.top-S.top+m.top)/k.y,bottom:(S.bottom-x.bottom+m.bottom)/k.y,left:(x.left-S.left+m.left)/k.x,right:(S.right-x.right+m.right)/k.x}}const Bx=e=>({name:"arrow",options:e,async fn(t){const{x:n,y:r,placement:o,rects:s,platform:i,elements:a,middlewareData:l}=t,{element:c,padding:d=0}=Tn(e,t)||{};if(c==null)return{};const f=Tc(d),p={x:n,y:r},h=ki(o),m=Ti(h),g=await i.getDimensions(c),y=h==="y",x=y?"top":"left",b=y?"bottom":"right",C=y?"clientHeight":"clientWidth",k=s.reference[m]+s.reference[h]-p[h]-s.floating[m],S=p[h]-s.reference[h],T=await(i.getOffsetParent==null?void 0:i.getOffsetParent(c));let I=T?T[C]:0;(!I||!await(i.isElement==null?void 0:i.isElement(T)))&&(I=a.floating[C]||s.floating[m]);const A=k/2-S/2,_=I/2-g[m]/2-1,L=_n(f[x],_),R=_n(f[b],_),O=L,F=I-g[m]-R,N=I/2-g[m]/2+A,B=Si(O,N,F),j=!l.arrow&&pr(o)!=null&&N!==B&&s.reference[m]/2-(N<O?L:R)-g[m]/2<0,K=j?N<O?N-O:N-F:0;return{[h]:p[h]+K,data:{[h]:B,centerOffset:N-B-K,...j&&{alignmentOffset:K}},reset:j}}}),zx=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(t){var n,r;const{placement:o,middlewareData:s,rects:i,initialPlacement:a,platform:l,elements:c}=t,{mainAxis:d=!0,crossAxis:f=!0,fallbackPlacements:p,fallbackStrategy:h="bestFit",fallbackAxisSideDirection:m="none",flipAlignment:g=!0,...y}=Tn(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const x=kn(o),b=pn(a),C=kn(a)===a,k=await(l.isRTL==null?void 0:l.isRTL(c.floating)),S=p||(C||!g?[Lo(a)]:Rx(a)),T=m!=="none";!p&&T&&S.push(...Lx(a,g,m,k));const I=[a,...S],A=await Lr(t,y),_=[];let L=((r=s.flip)==null?void 0:r.overflows)||[];if(d&&_.push(A[x]),f){const N=Mx(o,i,k);_.push(A[N[0]],A[N[1]])}if(L=[...L,{placement:o,overflows:_}],!_.every(N=>N<=0)){var R,O;const N=(((R=s.flip)==null?void 0:R.index)||0)+1,B=I[N];if(B&&(!(f==="alignment"?b!==pn(B):!1)||L.every(z=>pn(z.placement)===b?z.overflows[0]>0:!0)))return{data:{index:N,overflows:L},reset:{placement:B}};let j=(O=L.filter(K=>K.overflows[0]<=0).sort((K,z)=>K.overflows[1]-z.overflows[1])[0])==null?void 0:O.placement;if(!j)switch(h){case"bestFit":{var F;const K=(F=L.filter(z=>{if(T){const M=pn(z.placement);return M===b||M==="y"}return!0}).map(z=>[z.placement,z.overflows.filter(M=>M>0).reduce((M,G)=>M+G,0)]).sort((z,M)=>z[1]-M[1])[0])==null?void 0:F[0];K&&(j=K);break}case"initialPlacement":j=a;break}if(o!==j)return{reset:{placement:j}}}return{}}}};function Ic(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function Ec(e){return Ax.some(t=>e[t]>=0)}const Ux=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n}=t,{strategy:r="referenceHidden",...o}=Tn(e,t);switch(r){case"referenceHidden":{const s=await Lr(t,{...o,elementContext:"reference"}),i=Ic(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:Ec(i)}}}case"escaped":{const s=await Lr(t,{...o,altBoundary:!0}),i=Ic(s,n.floating);return{data:{escapedOffsets:i,escaped:Ec(i)}}}default:return{}}}}},Ac=new Set(["left","top"]);async function Hx(e,t){const{placement:n,platform:r,elements:o}=e,s=await(r.isRTL==null?void 0:r.isRTL(o.floating)),i=kn(n),a=pr(n),l=pn(n)==="y",c=Ac.has(i)?-1:1,d=s&&l?-1:1,f=Tn(t,e);let{mainAxis:p,crossAxis:h,alignmentAxis:m}=typeof f=="number"?{mainAxis:f,crossAxis:0,alignmentAxis:null}:{mainAxis:f.mainAxis||0,crossAxis:f.crossAxis||0,alignmentAxis:f.alignmentAxis};return a&&typeof m=="number"&&(h=a==="end"?m*-1:m),l?{x:h*d,y:p*c}:{x:p*c,y:h*d}}const Wx=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 Hx(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}}}}},Vx=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:y=>{let{x,y:b}=y;return{x,y:b}}},...l}=Tn(e,t),c={x:n,y:r},d=await Lr(t,l),f=pn(kn(o)),p=Ci(f);let h=c[p],m=c[f];if(s){const y=p==="y"?"top":"left",x=p==="y"?"bottom":"right",b=h+d[y],C=h-d[x];h=Si(b,h,C)}if(i){const y=f==="y"?"top":"left",x=f==="y"?"bottom":"right",b=m+d[y],C=m-d[x];m=Si(b,m,C)}const g=a.fn({...t,[p]:h,[f]:m});return{...g,data:{x:g.x-n,y:g.y-r,enabled:{[p]:s,[f]:i}}}}}},Kx=function(e){return e===void 0&&(e={}),{options:e,fn(t){const{x:n,y:r,placement:o,rects:s,middlewareData:i}=t,{offset:a=0,mainAxis:l=!0,crossAxis:c=!0}=Tn(e,t),d={x:n,y:r},f=pn(o),p=Ci(f);let h=d[p],m=d[f];const g=Tn(a,t),y=typeof g=="number"?{mainAxis:g,crossAxis:0}:{mainAxis:0,crossAxis:0,...g};if(l){const C=p==="y"?"height":"width",k=s.reference[p]-s.floating[C]+y.mainAxis,S=s.reference[p]+s.reference[C]-y.mainAxis;h<k?h=k:h>S&&(h=S)}if(c){var x,b;const C=p==="y"?"width":"height",k=Ac.has(kn(o)),S=s.reference[f]-s.floating[C]+(k&&((x=i.offset)==null?void 0:x[f])||0)+(k?0:y.crossAxis),T=s.reference[f]+s.reference[C]+(k?0:((b=i.offset)==null?void 0:b[f])||0)-(k?y.crossAxis:0);m<S?m=S:m>T&&(m=T)}return{[p]:h,[f]:m}}}},qx=function(e){return e===void 0&&(e={}),{name:"size",options:e,async fn(t){var n,r;const{placement:o,rects:s,platform:i,elements:a}=t,{apply:l=()=>{},...c}=Tn(e,t),d=await Lr(t,c),f=kn(o),p=pr(o),h=pn(o)==="y",{width:m,height:g}=s.floating;let y,x;f==="top"||f==="bottom"?(y=f,x=p===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(x=f,y=p==="end"?"top":"bottom");const b=g-d.top-d.bottom,C=m-d.left-d.right,k=_n(g-d[y],b),S=_n(m-d[x],C),T=!t.middlewareData.shift;let I=k,A=S;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(A=C),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(I=b),T&&!p){const L=Bt(d.left,0),R=Bt(d.right,0),O=Bt(d.top,0),F=Bt(d.bottom,0);h?A=m-2*(L!==0||R!==0?L+R:Bt(d.left,d.right)):I=g-2*(O!==0||F!==0?O+F:Bt(d.top,d.bottom))}await l({...t,availableWidth:A,availableHeight:I});const _=await i.getDimensions(a.floating);return m!==_.width||g!==_.height?{reset:{rects:!0}}:{}}}};function Fo(){return typeof window<"u"}function hr(e){return Nc(e)?(e.nodeName||"").toLowerCase():"#document"}function zt(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function hn(e){var t;return(t=(Nc(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function Nc(e){return Fo()?e instanceof Node||e instanceof zt(e).Node:!1}function rn(e){return Fo()?e instanceof Element||e instanceof zt(e).Element:!1}function mn(e){return Fo()?e instanceof HTMLElement||e instanceof zt(e).HTMLElement:!1}function _c(e){return!Fo()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof zt(e).ShadowRoot}const Gx=new Set(["inline","contents"]);function $r(e){const{overflow:t,overflowX:n,overflowY:r,display:o}=on(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!Gx.has(o)}const Yx=new Set(["table","td","th"]);function Xx(e){return Yx.has(hr(e))}const Jx=[":popover-open",":modal"];function Bo(e){return Jx.some(t=>{try{return e.matches(t)}catch{return!1}})}const Zx=["transform","translate","scale","rotate","perspective"],Qx=["transform","translate","scale","rotate","perspective","filter"],ey=["paint","layout","strict","content"];function Ei(e){const t=Ai(),n=rn(e)?on(e):e;return Zx.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)||Qx.some(r=>(n.willChange||"").includes(r))||ey.some(r=>(n.contain||"").includes(r))}function ty(e){let t=jn(e);for(;mn(t)&&!mr(t);){if(Ei(t))return t;if(Bo(t))return null;t=jn(t)}return null}function Ai(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const ny=new Set(["html","body","#document"]);function mr(e){return ny.has(hr(e))}function on(e){return zt(e).getComputedStyle(e)}function zo(e){return rn(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function jn(e){if(hr(e)==="html")return e;const t=e.assignedSlot||e.parentNode||_c(e)&&e.host||hn(e);return _c(t)?t.host:t}function jc(e){const t=jn(e);return mr(t)?e.ownerDocument?e.ownerDocument.body:e.body:mn(t)&&$r(t)?t:jc(t)}function Fr(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const o=jc(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=zt(o);if(s){const a=Ni(i);return t.concat(i,i.visualViewport||[],$r(o)?o:[],a&&n?Fr(a):[])}return t.concat(o,Fr(o,[],n))}function Ni(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function Mc(e){const t=on(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const o=mn(e),s=o?e.offsetWidth:n,i=o?e.offsetHeight:r,a=Oo(n)!==s||Oo(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function _i(e){return rn(e)?e:e.contextElement}function gr(e){const t=_i(e);if(!mn(t))return fn(1);const n=t.getBoundingClientRect(),{width:r,height:o,$:s}=Mc(t);let i=(s?Oo(n.width):n.width)/r,a=(s?Oo(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const ry=fn(0);function Rc(e){const t=zt(e);return!Ai()||!t.visualViewport?ry:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function oy(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==zt(e)?!1:t}function qn(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const o=e.getBoundingClientRect(),s=_i(e);let i=fn(1);t&&(r?rn(r)&&(i=gr(r)):i=gr(e));const a=oy(s,n,r)?Rc(s):fn(0);let l=(o.left+a.x)/i.x,c=(o.top+a.y)/i.y,d=o.width/i.x,f=o.height/i.y;if(s){const p=zt(s),h=r&&rn(r)?zt(r):r;let m=p,g=Ni(m);for(;g&&r&&h!==m;){const y=gr(g),x=g.getBoundingClientRect(),b=on(g),C=x.left+(g.clientLeft+parseFloat(b.paddingLeft))*y.x,k=x.top+(g.clientTop+parseFloat(b.paddingTop))*y.y;l*=y.x,c*=y.y,d*=y.x,f*=y.y,l+=C,c+=k,m=zt(g),g=Ni(m)}}return $o({width:d,height:f,x:l,y:c})}function Uo(e,t){const n=zo(e).scrollLeft;return t?t.left+n:qn(hn(e)).left+n}function Pc(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-Uo(e,n),o=n.top+t.scrollTop;return{x:r,y:o}}function sy(e){let{elements:t,rect:n,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=hn(r),a=t?Bo(t.floating):!1;if(r===i||a&&s)return n;let l={scrollLeft:0,scrollTop:0},c=fn(1);const d=fn(0),f=mn(r);if((f||!f&&!s)&&((hr(r)!=="body"||$r(i))&&(l=zo(r)),mn(r))){const h=qn(r);c=gr(r),d.x=h.x+r.clientLeft,d.y=h.y+r.clientTop}const p=i&&!f&&!s?Pc(i,l):fn(0);return{width:n.width*c.x,height:n.height*c.y,x:n.x*c.x-l.scrollLeft*c.x+d.x+p.x,y:n.y*c.y-l.scrollTop*c.y+d.y+p.y}}function iy(e){return Array.from(e.getClientRects())}function ay(e){const t=hn(e),n=zo(e),r=e.ownerDocument.body,o=Bt(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=Bt(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let i=-n.scrollLeft+Uo(e);const a=-n.scrollTop;return on(r).direction==="rtl"&&(i+=Bt(t.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}const Oc=25;function ly(e,t){const n=zt(e),r=hn(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=Ai();(!d||d&&t==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}const c=Uo(r);if(c<=0){const d=r.ownerDocument,f=d.body,p=getComputedStyle(f),h=d.compatMode==="CSS1Compat"&&parseFloat(p.marginLeft)+parseFloat(p.marginRight)||0,m=Math.abs(r.clientWidth-f.clientWidth-h);m<=Oc&&(s-=m)}else c<=Oc&&(s+=c);return{width:s,height:i,x:a,y:l}}const cy=new Set(["absolute","fixed"]);function uy(e,t){const n=qn(e,!0,t==="fixed"),r=n.top+e.clientTop,o=n.left+e.clientLeft,s=mn(e)?gr(e):fn(1),i=e.clientWidth*s.x,a=e.clientHeight*s.y,l=o*s.x,c=r*s.y;return{width:i,height:a,x:l,y:c}}function Dc(e,t,n){let r;if(t==="viewport")r=ly(e,n);else if(t==="document")r=ay(hn(e));else if(rn(t))r=uy(t,n);else{const o=Rc(e);r={x:t.x-o.x,y:t.y-o.y,width:t.width,height:t.height}}return $o(r)}function Lc(e,t){const n=jn(e);return n===t||!rn(n)||mr(n)?!1:on(n).position==="fixed"||Lc(n,t)}function dy(e,t){const n=t.get(e);if(n)return n;let r=Fr(e,[],!1).filter(a=>rn(a)&&hr(a)!=="body"),o=null;const s=on(e).position==="fixed";let i=s?jn(e):e;for(;rn(i)&&!mr(i);){const a=on(i),l=Ei(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&cy.has(o.position)||$r(i)&&!l&&Lc(e,i))?r=r.filter(d=>d!==i):o=a,i=jn(i)}return t.set(e,r),r}function fy(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i=[...n==="clippingAncestors"?Bo(t)?[]:dy(t,this._c):[].concat(n),r],a=i[0],l=i.reduce((c,d)=>{const f=Dc(t,d,o);return c.top=Bt(f.top,c.top),c.right=_n(f.right,c.right),c.bottom=_n(f.bottom,c.bottom),c.left=Bt(f.left,c.left),c},Dc(t,a,o));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function py(e){const{width:t,height:n}=Mc(e);return{width:t,height:n}}function hy(e,t,n){const r=mn(t),o=hn(t),s=n==="fixed",i=qn(e,!0,s,t);let a={scrollLeft:0,scrollTop:0};const l=fn(0);function c(){l.x=Uo(o)}if(r||!r&&!s)if((hr(t)!=="body"||$r(o))&&(a=zo(t)),r){const h=qn(t,!0,s,t);l.x=h.x+t.clientLeft,l.y=h.y+t.clientTop}else o&&c();s&&!r&&o&&c();const d=o&&!r&&!s?Pc(o,a):fn(0),f=i.left+a.scrollLeft-l.x-d.x,p=i.top+a.scrollTop-l.y-d.y;return{x:f,y:p,width:i.width,height:i.height}}function ji(e){return on(e).position==="static"}function $c(e,t){if(!mn(e)||on(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return hn(e)===n&&(n=n.ownerDocument.body),n}function Fc(e,t){const n=zt(e);if(Bo(e))return n;if(!mn(e)){let o=jn(e);for(;o&&!mr(o);){if(rn(o)&&!ji(o))return o;o=jn(o)}return n}let r=$c(e,t);for(;r&&Xx(r)&&ji(r);)r=$c(r,t);return r&&mr(r)&&ji(r)&&!Ei(r)?n:r||ty(e)||n}const my=async function(e){const t=this.getOffsetParent||Fc,n=this.getDimensions,r=await n(e.floating);return{reference:hy(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function gy(e){return on(e).direction==="rtl"}const xy={convertOffsetParentRelativeRectToViewportRelativeRect:sy,getDocumentElement:hn,getClippingRect:fy,getOffsetParent:Fc,getElementRects:my,getClientRects:iy,getDimensions:py,getScale:gr,isElement:rn,isRTL:gy};function Bc(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function yy(e,t){let n=null,r;const o=hn(e);function s(){var a;clearTimeout(r),(a=n)==null||a.disconnect(),n=null}function i(a,l){a===void 0&&(a=!1),l===void 0&&(l=1),s();const c=e.getBoundingClientRect(),{left:d,top:f,width:p,height:h}=c;if(a||t(),!p||!h)return;const m=Do(f),g=Do(o.clientWidth-(d+p)),y=Do(o.clientHeight-(f+h)),x=Do(d),C={rootMargin:-m+"px "+-g+"px "+-y+"px "+-x+"px",threshold:Bt(0,_n(1,l))||1};let k=!0;function S(T){const I=T[0].intersectionRatio;if(I!==l){if(!k)return i();I?i(!1,I):r=setTimeout(()=>{i(!1,1e-7)},1e3)}I===1&&!Bc(c,e.getBoundingClientRect())&&i(),k=!1}try{n=new IntersectionObserver(S,{...C,root:o.ownerDocument})}catch{n=new IntersectionObserver(S,C)}n.observe(e)}return i(!0),s}function vy(e,t,n,r){r===void 0&&(r={});const{ancestorScroll:o=!0,ancestorResize:s=!0,elementResize:i=typeof ResizeObserver=="function",layoutShift:a=typeof IntersectionObserver=="function",animationFrame:l=!1}=r,c=_i(e),d=o||s?[...c?Fr(c):[],...Fr(t)]:[];d.forEach(x=>{o&&x.addEventListener("scroll",n,{passive:!0}),s&&x.addEventListener("resize",n)});const f=c&&a?yy(c,n):null;let p=-1,h=null;i&&(h=new ResizeObserver(x=>{let[b]=x;b&&b.target===c&&h&&(h.unobserve(t),cancelAnimationFrame(p),p=requestAnimationFrame(()=>{var C;(C=h)==null||C.observe(t)})),n()}),c&&!l&&h.observe(c),h.observe(t));let m,g=l?qn(e):null;l&&y();function y(){const x=qn(e);g&&!Bc(g,x)&&n(),g=x,m=requestAnimationFrame(y)}return n(),()=>{var x;d.forEach(b=>{o&&b.removeEventListener("scroll",n),s&&b.removeEventListener("resize",n)}),f==null||f(),(x=h)==null||x.disconnect(),h=null,l&&cancelAnimationFrame(m)}}const by=Wx,wy=Vx,Sy=zx,Cy=qx,Ty=Ux,zc=Bx,ky=Kx,Iy=(e,t,n)=>{const r=new Map,o={platform:xy,...n},s={...o.platform,_c:r};return Fx(e,t,{...o,platform:s})};var Ey=typeof document<"u",Ay=function(){},Ho=Ey?w.useLayoutEffect:Ay;function Wo(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(!Wo(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)&&!Wo(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function Uc(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function Hc(e,t){const n=Uc(e);return Math.round(t*n)/n}function Mi(e){const t=v.useRef(e);return Ho(()=>{t.current=e}),t}function Ny(e){e===void 0&&(e={});const{placement:t="bottom",strategy:n="absolute",middleware:r=[],platform:o,elements:{reference:s,floating:i}={},transform:a=!0,whileElementsMounted:l,open:c}=e,[d,f]=v.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[p,h]=v.useState(r);Wo(p,r)||h(r);const[m,g]=v.useState(null),[y,x]=v.useState(null),b=v.useCallback(z=>{z!==T.current&&(T.current=z,g(z))},[]),C=v.useCallback(z=>{z!==I.current&&(I.current=z,x(z))},[]),k=s||m,S=i||y,T=v.useRef(null),I=v.useRef(null),A=v.useRef(d),_=l!=null,L=Mi(l),R=Mi(o),O=Mi(c),F=v.useCallback(()=>{if(!T.current||!I.current)return;const z={placement:t,strategy:n,middleware:p};R.current&&(z.platform=R.current),Iy(T.current,I.current,z).then(M=>{const G={...M,isPositioned:O.current!==!1};N.current&&!Wo(A.current,G)&&(A.current=G,ho.flushSync(()=>{f(G)}))})},[p,t,n,R,O]);Ho(()=>{c===!1&&A.current.isPositioned&&(A.current.isPositioned=!1,f(z=>({...z,isPositioned:!1})))},[c]);const N=v.useRef(!1);Ho(()=>(N.current=!0,()=>{N.current=!1}),[]),Ho(()=>{if(k&&(T.current=k),S&&(I.current=S),k&&S){if(L.current)return L.current(k,S,F);F()}},[k,S,F,L,_]);const B=v.useMemo(()=>({reference:T,floating:I,setReference:b,setFloating:C}),[b,C]),j=v.useMemo(()=>({reference:k,floating:S}),[k,S]),K=v.useMemo(()=>{const z={position:n,left:0,top:0};if(!j.floating)return z;const M=Hc(j.floating,d.x),G=Hc(j.floating,d.y);return a?{...z,transform:"translate("+M+"px, "+G+"px)",...Uc(j.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:M,top:G}},[n,a,j.floating,d.x,d.y]);return v.useMemo(()=>({...d,update:F,refs:B,elements:j,floatingStyles:K}),[d,F,B,j,K])}const _y=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?zc({element:r.current,padding:o}).fn(n):{}:r?zc({element:r,padding:o}).fn(n):{}}}},jy=(e,t)=>({...by(e),options:[e,t]}),My=(e,t)=>({...wy(e),options:[e,t]}),Ry=(e,t)=>({...ky(e),options:[e,t]}),Py=(e,t)=>({...Sy(e),options:[e,t]}),Oy=(e,t)=>({...Cy(e),options:[e,t]}),Dy=(e,t)=>({...Ty(e),options:[e,t]}),Ly=(e,t)=>({..._y(e),options:[e,t]});var $y="Arrow",Wc=v.forwardRef((e,t)=>{const{children:n,width:r=10,height:o=5,...s}=e;return u.jsx(Ne.svg,{...s,ref:t,width:r,height:o,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:e.asChild?n:u.jsx("polygon",{points:"0,0 30,0 15,10"})})});Wc.displayName=$y;var Fy=Wc;function Vc(e){const[t,n]=v.useState(void 0);return Ct(()=>{if(e){n({width:e.offsetWidth,height:e.offsetHeight});const r=new ResizeObserver(o=>{if(!Array.isArray(o)||!o.length)return;const s=o[0];let i,a;if("borderBoxSize"in s){const l=s.borderBoxSize,c=Array.isArray(l)?l[0]:l;i=c.inlineSize,a=c.blockSize}else i=e.offsetWidth,a=e.offsetHeight;n({width:i,height:a})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else n(void 0)},[e]),t}var Ri="Popper",[Kc,Vo]=Sn(Ri),[By,qc]=Kc(Ri),Gc=e=>{const{__scopePopper:t,children:n}=e,[r,o]=v.useState(null);return u.jsx(By,{scope:t,anchor:r,onAnchorChange:o,children:n})};Gc.displayName=Ri;var Yc="PopperAnchor",Xc=v.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...o}=e,s=qc(Yc,n),i=v.useRef(null),a=Be(t,i),l=v.useRef(null);return v.useEffect(()=>{const c=l.current;l.current=(r==null?void 0:r.current)||i.current,c!==l.current&&s.onAnchorChange(l.current)}),r?null:u.jsx(Ne.div,{...o,ref:a})});Xc.displayName=Yc;var Pi="PopperContent",[zy,Uy]=Kc(Pi),Jc=v.forwardRef((e,t)=>{var J,$,q,Z,ue,ie;const{__scopePopper:n,side:r="bottom",sideOffset:o=0,align:s="center",alignOffset:i=0,arrowPadding:a=0,avoidCollisions:l=!0,collisionBoundary:c=[],collisionPadding:d=0,sticky:f="partial",hideWhenDetached:p=!1,updatePositionStrategy:h="optimized",onPlaced:m,...g}=e,y=qc(Pi,n),[x,b]=v.useState(null),C=Be(t,_e=>b(_e)),[k,S]=v.useState(null),T=Vc(k),I=(T==null?void 0:T.width)??0,A=(T==null?void 0:T.height)??0,_=r+(s!=="center"?"-"+s:""),L=typeof d=="number"?d:{top:0,right:0,bottom:0,left:0,...d},R=Array.isArray(c)?c:[c],O=R.length>0,F={padding:L,boundary:R.filter(Wy),altBoundary:O},{refs:N,floatingStyles:B,placement:j,isPositioned:K,middlewareData:z}=Ny({strategy:"fixed",placement:_,whileElementsMounted:(..._e)=>vy(..._e,{animationFrame:h==="always"}),elements:{reference:y.anchor},middleware:[jy({mainAxis:o+A,alignmentAxis:i}),l&&My({mainAxis:!0,crossAxis:!1,limiter:f==="partial"?Ry():void 0,...F}),l&&Py({...F}),Oy({...F,apply:({elements:_e,rects:He,availableWidth:oe,availableHeight:ye})=>{const{width:Oe,height:Ye}=He.reference,nt=_e.floating.style;nt.setProperty("--radix-popper-available-width",`${oe}px`),nt.setProperty("--radix-popper-available-height",`${ye}px`),nt.setProperty("--radix-popper-anchor-width",`${Oe}px`),nt.setProperty("--radix-popper-anchor-height",`${Ye}px`)}}),k&&Ly({element:k,padding:a}),Vy({arrowWidth:I,arrowHeight:A}),p&&Dy({strategy:"referenceHidden",...F})]}),[M,G]=eu(j),X=Tt(m);Ct(()=>{K&&(X==null||X())},[K,X]);const se=(J=z.arrow)==null?void 0:J.x,be=($=z.arrow)==null?void 0:$.y,Ie=((q=z.arrow)==null?void 0:q.centerOffset)!==0,[Y,U]=v.useState();return Ct(()=>{x&&U(window.getComputedStyle(x).zIndex)},[x]),u.jsx("div",{ref:N.setFloating,"data-radix-popper-content-wrapper":"",style:{...B,transform:K?B.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:Y,"--radix-popper-transform-origin":[(Z=z.transformOrigin)==null?void 0:Z.x,(ue=z.transformOrigin)==null?void 0:ue.y].join(" "),...((ie=z.hide)==null?void 0:ie.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:u.jsx(zy,{scope:n,placedSide:M,onArrowChange:S,arrowX:se,arrowY:be,shouldHideArrow:Ie,children:u.jsx(Ne.div,{"data-side":M,"data-align":G,...g,ref:C,style:{...g.style,animation:K?void 0:"none"}})})})});Jc.displayName=Pi;var Zc="PopperArrow",Hy={top:"bottom",right:"left",bottom:"top",left:"right"},Qc=v.forwardRef(function(t,n){const{__scopePopper:r,...o}=t,s=Uy(Zc,r),i=Hy[s.placedSide];return u.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:u.jsx(Fy,{...o,ref:n,style:{...o.style,display:"block"}})})});Qc.displayName=Zc;function Wy(e){return e!==null}var Vy=e=>({name:"transformOrigin",options:e,fn(t){var y,x,b;const{placement:n,rects:r,middlewareData:o}=t,i=((y=o.arrow)==null?void 0:y.centerOffset)!==0,a=i?0:e.arrowWidth,l=i?0:e.arrowHeight,[c,d]=eu(n),f={start:"0%",center:"50%",end:"100%"}[d],p=(((x=o.arrow)==null?void 0:x.x)??0)+a/2,h=(((b=o.arrow)==null?void 0:b.y)??0)+l/2;let m="",g="";return c==="bottom"?(m=i?f:`${p}px`,g=`${-l}px`):c==="top"?(m=i?f:`${p}px`,g=`${r.floating.height+l}px`):c==="right"?(m=`${-l}px`,g=i?f:`${h}px`):c==="left"&&(m=`${r.floating.width+l}px`,g=i?f:`${h}px`),{data:{x:m,y:g}}}});function eu(e){const[t,n="center"]=e.split("-");return[t,n]}var tu=Gc,nu=Xc,ru=Jc,ou=Qc,Ky="Portal",Ko=v.forwardRef((e,t)=>{var a;const{container:n,...r}=e,[o,s]=v.useState(!1);Ct(()=>s(!0),[]);const i=n||o&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?qs.createPortal(u.jsx(Ne.div,{...r,ref:t}),i):null});Ko.displayName=Ky;function qy(e,t){return v.useReducer((n,r)=>t[n][r]??n,e)}var Yt=e=>{const{present:t,children:n}=e,r=Gy(t),o=typeof n=="function"?n({present:r.isPresent}):v.Children.only(n),s=Be(r.ref,Yy(o));return typeof n=="function"||r.isPresent?v.cloneElement(o,{ref:s}):null};Yt.displayName="Presence";function Gy(e){const[t,n]=v.useState(),r=v.useRef(null),o=v.useRef(e),s=v.useRef("none"),i=e?"mounted":"unmounted",[a,l]=qy(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return v.useEffect(()=>{const c=qo(r.current);s.current=a==="mounted"?c:"none"},[a]),Ct(()=>{const c=r.current,d=o.current;if(d!==e){const p=s.current,h=qo(c);e?l("MOUNT"):h==="none"||(c==null?void 0:c.display)==="none"?l("UNMOUNT"):l(d&&p!==h?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,l]),Ct(()=>{if(t){let c;const d=t.ownerDocument.defaultView??window,f=h=>{const g=qo(r.current).includes(CSS.escape(h.animationName));if(h.target===t&&g&&(l("ANIMATION_END"),!o.current)){const y=t.style.animationFillMode;t.style.animationFillMode="forwards",c=d.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=y)})}},p=h=>{h.target===t&&(s.current=qo(r.current))};return t.addEventListener("animationstart",p),t.addEventListener("animationcancel",f),t.addEventListener("animationend",f),()=>{d.clearTimeout(c),t.removeEventListener("animationstart",p),t.removeEventListener("animationcancel",f),t.removeEventListener("animationend",f)}}else l("ANIMATION_END")},[t,l]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:v.useCallback(c=>{r.current=c?getComputedStyle(c):null,n(c)},[])}}function qo(e){return(e==null?void 0:e.animationName)||"none"}function Yy(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 Oi="rovingFocusGroup.onEntryFocus",Xy={bubbles:!1,cancelable:!0},Br="RovingFocusGroup",[Di,su,Jy]=gi(Br),[Zy,iu]=Sn(Br,[Jy]),[Qy,ev]=Zy(Br),au=v.forwardRef((e,t)=>u.jsx(Di.Provider,{scope:e.__scopeRovingFocusGroup,children:u.jsx(Di.Slot,{scope:e.__scopeRovingFocusGroup,children:u.jsx(tv,{...e,ref:t})})}));au.displayName=Br;var tv=v.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:o=!1,dir:s,currentTabStopId:i,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:l,onEntryFocus:c,preventScrollOnEntryFocus:d=!1,...f}=e,p=v.useRef(null),h=Be(t,p),m=Mo(s),[g,y]=fr({prop:i,defaultProp:a??null,onChange:l,caller:Br}),[x,b]=v.useState(!1),C=Tt(c),k=su(n),S=v.useRef(!1),[T,I]=v.useState(0);return v.useEffect(()=>{const A=p.current;if(A)return A.addEventListener(Oi,C),()=>A.removeEventListener(Oi,C)},[C]),u.jsx(Qy,{scope:n,orientation:r,dir:m,loop:o,currentTabStopId:g,onItemFocus:v.useCallback(A=>y(A),[y]),onItemShiftTab:v.useCallback(()=>b(!0),[]),onFocusableItemAdd:v.useCallback(()=>I(A=>A+1),[]),onFocusableItemRemove:v.useCallback(()=>I(A=>A-1),[]),children:u.jsx(Ne.div,{tabIndex:x||T===0?-1:0,"data-orientation":r,...f,ref:h,style:{outline:"none",...e.style},onMouseDown:fe(e.onMouseDown,()=>{S.current=!0}),onFocus:fe(e.onFocus,A=>{const _=!S.current;if(A.target===A.currentTarget&&_&&!x){const L=new CustomEvent(Oi,Xy);if(A.currentTarget.dispatchEvent(L),!L.defaultPrevented){const R=k().filter(j=>j.focusable),O=R.find(j=>j.active),F=R.find(j=>j.id===g),B=[O,F,...R].filter(Boolean).map(j=>j.ref.current);uu(B,d)}}S.current=!1}),onBlur:fe(e.onBlur,()=>b(!1))})})}),lu="RovingFocusGroupItem",cu=v.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:o=!1,tabStopId:s,children:i,...a}=e,l=Cn(),c=s||l,d=ev(lu,n),f=d.currentTabStopId===c,p=su(n),{onFocusableItemAdd:h,onFocusableItemRemove:m,currentTabStopId:g}=d;return v.useEffect(()=>{if(r)return h(),()=>m()},[r,h,m]),u.jsx(Di.ItemSlot,{scope:n,id:c,focusable:r,active:o,children:u.jsx(Ne.span,{tabIndex:f?0:-1,"data-orientation":d.orientation,...a,ref:t,onMouseDown:fe(e.onMouseDown,y=>{r?d.onItemFocus(c):y.preventDefault()}),onFocus:fe(e.onFocus,()=>d.onItemFocus(c)),onKeyDown:fe(e.onKeyDown,y=>{if(y.key==="Tab"&&y.shiftKey){d.onItemShiftTab();return}if(y.target!==y.currentTarget)return;const x=ov(y,d.orientation,d.dir);if(x!==void 0){if(y.metaKey||y.ctrlKey||y.altKey||y.shiftKey)return;y.preventDefault();let C=p().filter(k=>k.focusable).map(k=>k.ref.current);if(x==="last")C.reverse();else if(x==="prev"||x==="next"){x==="prev"&&C.reverse();const k=C.indexOf(y.currentTarget);C=d.loop?sv(C,k+1):C.slice(k+1)}setTimeout(()=>uu(C))}}),children:typeof i=="function"?i({isCurrentTabStop:f,hasTabStop:g!=null}):i})})});cu.displayName=lu;var nv={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function rv(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function ov(e,t,n){const r=rv(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return nv[r]}function uu(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function sv(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var iv=au,av=cu,lv=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},xr=new WeakMap,Go=new WeakMap,Yo={},Li=0,du=function(e){return e&&(e.host||du(e.parentNode))},cv=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=du(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})},uv=function(e,t,n,r){var o=cv(t,Array.isArray(e)?e:[e]);Yo[n]||(Yo[n]=new WeakMap);var s=Yo[n],i=[],a=new Set,l=new Set(o),c=function(f){!f||a.has(f)||(a.add(f),c(f.parentNode))};o.forEach(c);var d=function(f){!f||l.has(f)||Array.prototype.forEach.call(f.children,function(p){if(a.has(p))d(p);else try{var h=p.getAttribute(r),m=h!==null&&h!=="false",g=(xr.get(p)||0)+1,y=(s.get(p)||0)+1;xr.set(p,g),s.set(p,y),i.push(p),g===1&&m&&Go.set(p,!0),y===1&&p.setAttribute(n,"true"),m||p.setAttribute(r,"true")}catch(x){console.error("aria-hidden: cannot operate on ",p,x)}})};return d(t),a.clear(),Li++,function(){i.forEach(function(f){var p=xr.get(f)-1,h=s.get(f)-1;xr.set(f,p),s.set(f,h),p||(Go.has(f)||f.removeAttribute(r),Go.delete(f)),h||f.removeAttribute(n)}),Li--,Li||(xr=new WeakMap,xr=new WeakMap,Go=new WeakMap,Yo={})}},$i=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),o=lv(e);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live], script"))),uv(r,o,n,"aria-hidden")):function(){return null}},gn=function(){return gn=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},gn.apply(this,arguments)};function fu(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 dv(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 Xo="right-scroll-bar-position",Jo="width-before-scroll-bar",fv="with-scroll-bars-hidden",pv="--removed-body-scroll-bar-size";function Fi(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function hv(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 mv=typeof window<"u"?v.useLayoutEffect:v.useEffect,pu=new WeakMap;function gv(e,t){var n=hv(null,function(r){return e.forEach(function(o){return Fi(o,r)})});return mv(function(){var r=pu.get(n);if(r){var o=new Set(r),s=new Set(e),i=n.current;o.forEach(function(a){s.has(a)||Fi(a,null)}),s.forEach(function(a){o.has(a)||Fi(a,i)})}pu.set(n,e)},[e]),n}function xv(e){return e}function yv(e,t){t===void 0&&(t=xv);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)},c=function(){return Promise.resolve().then(l)};c(),n={push:function(d){i.push(d),c()},filter:function(d){return i=i.filter(d),n}}}};return o}function vv(e){e===void 0&&(e={});var t=yv(null);return t.options=gn({async:!0,ssr:!1},e),t}var hu=function(e){var t=e.sideCar,n=fu(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 v.createElement(r,gn({},n))};hu.isSideCarExport=!0;function bv(e,t){return e.useMedium(t),hu}var mu=vv(),Bi=function(){},Zo=v.forwardRef(function(e,t){var n=v.useRef(null),r=v.useState({onScrollCapture:Bi,onWheelCapture:Bi,onTouchMoveCapture:Bi}),o=r[0],s=r[1],i=e.forwardProps,a=e.children,l=e.className,c=e.removeScrollBar,d=e.enabled,f=e.shards,p=e.sideCar,h=e.noRelative,m=e.noIsolation,g=e.inert,y=e.allowPinchZoom,x=e.as,b=x===void 0?"div":x,C=e.gapMode,k=fu(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),S=p,T=gv([n,t]),I=gn(gn({},k),o);return v.createElement(v.Fragment,null,d&&v.createElement(S,{sideCar:mu,removeScrollBar:c,shards:f,noRelative:h,noIsolation:m,inert:g,setCallbacks:s,allowPinchZoom:!!y,lockRef:n,gapMode:C}),i?v.cloneElement(v.Children.only(a),gn(gn({},I),{ref:T})):v.createElement(b,gn({},I,{className:l,ref:T}),a))});Zo.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},Zo.classNames={fullWidth:Jo,zeroRight:Xo};var wv=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function Sv(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=wv();return t&&e.setAttribute("nonce",t),e}function Cv(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function Tv(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var kv=function(){var e=0,t=null;return{add:function(n){e==0&&(t=Sv())&&(Cv(t,n),Tv(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},Iv=function(){var e=kv();return function(t,n){v.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},gu=function(){var e=Iv(),t=function(n){var r=n.styles,o=n.dynamic;return e(r,o),null};return t},Ev={left:0,top:0,right:0,gap:0},zi=function(e){return parseInt(e||"",10)||0},Av=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[zi(n),zi(r),zi(o)]},Nv=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return Ev;var t=Av(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])}},_v=gu(),yr="data-scroll-locked",jv=function(e,t,n,r){var o=e.left,s=e.top,i=e.right,a=e.gap;return n===void 0&&(n="margin"),`
|
|
39
|
-
.`.concat(
|
|
37
|
+
`))>=0;){const Q=ht.slice(0,D);ht=ht.slice(D+2);const ne=Kg(Q);if(!ne)continue;let me;try{me=JSON.parse(ne)}catch{console.debug("[use-chat] malformed SSE:",ne.slice(0,200));continue}const xe=Vg(me)?me.data:me;Vt=Date.now();const De=xe.seq;if(De!==void 0){if(De<=mt){console.debug("[use-chat] drop duplicate/out-of-order event",{seq:De,lastProcessedSeq:mt,type:xe.type});continue}mt>0&&De>mt+1&&(($=j==null?void 0:j.onGap)==null||$.call(j,{from:mt,to:De})),mt=De,C.current=De,y(De)}if(console.debug("[use-chat] received event",{seq:xe.seq,type:xe.type,preview:(()=>{var Re;try{return xe.type==="message_delta"?{deltaTypes:(Re=xe.delta)==null?void 0:Re.map(je=>je.type),textLen:(xe.delta||[]).filter(je=>je.type==="text").map(je=>String(je.text||"").length)}:xe.content||xe.delta?{hasContent:!0}:{}}catch(je){return{err:String(je)}}})()}),xe.type==="checkpoint")I.current=xe.checkpointId??null,A.current=xe.checkpointNs??null,m(xe.checkpointId??null);else if(xe.type==="state_history"){N.current=xe;try{const je=fr(xe).latest;je&&(I.current=je.checkpointId??null,A.current=je.checkpointNs??null,m(je.checkpointId??null))}catch(Re){console.warn("[use-chat] Failed to hydrate state_history payload",Re)}}try{B==null||B(xe)}catch(Re){console.error("[use-chat] Error in onEvent callback:",Re,"for event:",xe.type)}if(xe.type==="token"&&e.autoAppendAssistant!==!1)ft.push(xe.content),Lt();else if(xe.type==="message_delta"){const Re=xe.delta.filter(je=>je.type==="text").map(je=>je.text).join("");Re&&e.autoAppendAssistant!==!1&&(ft.push(Re),Lt())}else if(xe.type==="heartbeat"){console.debug("[use-chat] heartbeat received");try{(q=j==null?void 0:j.onHeartbeat)==null||q.call(j,xe)}catch(Re){console.warn("[use-chat] heartbeat callback failed",Re)}}else if(St!==null&&cancelAnimationFrame(St),Mt(),xe.type==="checkpoint")m(xe.checkpointId);else if(xe.type==="error"){const Re=xe;if(d(Re.message),z="error",M=Re.message,Re.error_type==="auth_error"||Re.code==="TOKEN_EXPIRED"||((Z=Re.message)==null?void 0:Z.includes("token"))||((ue=Re.message)==null?void 0:ue.includes("401"))||((ie=Re.message)==null?void 0:ie.includes("unauthorized"))||((_e=Re.message)==null?void 0:_e.includes("Unauthorized"))){console.error("[use-chat] Auth error detected:",Re.message);try{(He=j==null?void 0:j.onAuthError)==null||He.call(j,Re.message)}catch(Kt){console.warn("[use-chat] onAuthError handler failed",Kt)}K.abort()}}}}Mt(),z===null&&!K.signal.aborted&&(z="complete")}catch(rt){if(rt.name==="AbortError")z=z??"aborted";else{const We=rt.message||String(rt);z="error",M=We,d(We),(oe=j==null?void 0:j.onError)==null||oe.call(j,We)}}finally{try{await at.cancel()}catch{}finally{(ye=at.releaseLock)==null||ye.call(at)}St!==null&&typeof window<"u"&&window.cancelAnimationFrame(St),clearInterval(Ue)}}catch(Xe){if(Xe.name==="AbortError")z=z??"aborted";else{const qe=Xe.message||String(Xe);z="error",M=qe,d(qe),(Oe=j==null?void 0:j.onError)==null||Oe.call(j,qe),G||((Ye=j==null?void 0:j.onConnectionError)==null||Ye.call(j,qe),G=!0)}}finally{const Xe=C.current,qe=I.current,it=A.current,Je=N.current,et=z??(K.signal.aborted?"aborted":M?"error":"complete");try{(nt=j==null?void 0:j.onClosed)==null||nt.call(j,{reason:et,lastSeq:Xe,lastCheckpointId:qe,lastCheckpointNs:it,lastStateHistory:Je,error:M})}catch(at){console.warn("[use-chat] onClosed callback failed",at)}l(!1),b(!1),S.current=null,C.current=0,y(0),T.current=null}})(),{close:()=>K.abort()}},[t,n,r,e.autoAppendAssistant]);return w.useEffect(()=>()=>{var _;k.current=!1,(_=S.current)==null||_.abort()},[]),{isStreaming:a,error:c,assistantText:f,lastCheckpointId:p,lastSeq:g,connected:x,stream:F,stop:O,clear:R,setToken:L}}function Vg(e){return!!e&&typeof e=="object"&&e.protocolVersion==="v1"&&"data"in e}function Kg(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
|
+
`)}const Ct=[];for(let e=0;e<256;++e)Ct.push((e+256).toString(16).slice(1));function qg(e,t=0){return(Ct[e[t+0]]+Ct[e[t+1]]+Ct[e[t+2]]+Ct[e[t+3]]+"-"+Ct[e[t+4]]+Ct[e[t+5]]+"-"+Ct[e[t+6]]+Ct[e[t+7]]+"-"+Ct[e[t+8]]+Ct[e[t+9]]+"-"+Ct[e[t+10]]+Ct[e[t+11]]+Ct[e[t+12]]+Ct[e[t+13]]+Ct[e[t+14]]+Ct[e[t+15]]).toLowerCase()}let fi;const Gg=new Uint8Array(16);function Yg(){if(!fi){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");fi=crypto.getRandomValues.bind(crypto)}return fi(Gg)}const Gl={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function Xg(e,t,n){var o;e=e||{};const r=e.random??((o=e.rng)==null?void 0:o.call(e))??Yg();if(r.length<16)throw new Error("Random bytes length must be >= 16");return r[6]=r[6]&15|64,r[8]=r[8]&63|128,qg(r)}function Jg(e,t,n){return Gl.randomUUID&&!e?Gl.randomUUID():Xg(e)}function Zg(e){return e.type!=="token"}const Qg={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},toolStreamingMessageId:null,toolStreamingStack:[],lastBranch:null,messagesStreamMeta:{},pendingInterrupt:null};function ex(e,t){var n;switch(t.type){case"reset":return{messages:pi(((n=t.payload)==null?void 0:n.messages)??[]),assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},toolStreamingMessageId:null,toolStreamingStack:[],lastBranch:null,pendingInterrupt:null};case"seed":{const r=pi(t.payload.messages),o={...e,messages:r,assemblingId:null,pendingInterrupt:t.payload.pendingInterrupt??null,toolStreamingMessageId:null,toolStreamingStack:[]};return Object.prototype.hasOwnProperty.call(t.payload,"checkpointId")&&(o.lastCheckpointId=t.payload.checkpointId??null),Object.prototype.hasOwnProperty.call(t.payload,"checkpointNs")&&(o.lastCheckpointNs=t.payload.checkpointNs??null),o}case"prepend":{const r=pi(t.payload.messages);if(!r.length)return e;const o=new Set(e.messages.map(i=>i.id)),s=r.filter(i=>!o.has(i.id));return s.length?{...e,messages:[...s,...e.messages]}: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 Xl(e,t.payload.ev);case"batch":{const{events:r}=t.payload;return r.length?r.reduce((o,s)=>Xl(o,s),e):e}case"interrupt_response":return{...e,messages:Jl(e.messages),pendingInterrupt:null};default:return e}}function Yl(e=[]){const[t,n]=w.useReducer(ex,{...Qg,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 c=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,...c}}function Xl(e,t){var n,r,o,s,i;if(t.type==="message_start"&&t.role==="assistant"){const a=t.id,l=lx(t.model);if(e.messages.some(f=>f.id===a)){const f=e.messagesStreamMeta??{},h={...f,[a]:f[a]??{lastSeq:t.seq??null,lastText:""}};return{...e,assemblingId:a,messagesStreamMeta:h}}const d={id:a,role:"assistant",name:l||void 0,model:t.model,createdAt:new Date().toISOString(),content:[]};return{...e,assemblingId:a,messages:[...e.messages,d]}}if(t.type==="message_delta"){const a=e.assemblingId??Zl(e.messages);if(!a)return e;const l=e.messages,c=l.findIndex(k=>k.id===a&&k.role==="assistant");if(c===-1)return e;const d=l[c],f=e.messagesStreamMeta??{},h=f[a]??{lastSeq:null,lastText:nc(d.content)},p=t.seq??null;if(p!==null&&typeof p=="number"&&typeof h.lastSeq=="number"&&p<=h.lastSeq)return console.debug("[MessageReducer] skipping delta - seq <= lastSeq",{seq:p,lastSeq:h.lastSeq}),e;const{newParts:m,newMeta:g,changed:y}=sx(d.content,t.delta,h,p);if(!y)return e;const x={...d,content:m},b=Ao(l,c,x),S={...f,[a]:g};return{...e,messages:b,messagesStreamMeta:S}}if(t.type==="message_end"){const a=e.assemblingId??Zl(e.messages);if(!a)return{...e,assemblingId:null};const l=e.messages,c=l.findIndex(d=>d.id===a&&d.role==="assistant");if(c>=0){const d=l[c];if(!((n=d.content)==null?void 0:n.some(h=>{var p;return(h==null?void 0:h.type)==="text"&&((p=h.text)==null?void 0:p.trim())}))){console.debug("[MessageReducer] pruning assistant message with no visible text",{id:d.id,contentTypes:(r=d.content)==null?void 0:r.map(p=>p==null?void 0:p.type),contentPreview:(o=d.content)==null?void 0:o.map(p=>(p==null?void 0:p.type)==="text"?String(p.text).slice(0,100):p==null?void 0:p.type)});const h=[...l.slice(0,c),...l.slice(c+1)];return{...e,assemblingId:null,messages:h}}}return e}if(t.type==="tool_start"){const a=Ql(t),l=a[0]??(typeof t.id=="string"?t.id:null)??(typeof t.call_id=="string"?t.call_id:null),c=t.name??t.tool??"tool";!l&&a.length===0&&a.push(`${c}-${Date.now()}`);const d=a.length?a:l?[l]:[],f=d[0]??`${c}-${Date.now()}`,h={type:"tool_call",id:f,name:c,args:t.args},p={type:e.toolStreamingMessageId?"tool_call":"tool_start",toolId:l??f,toolName:c,title:`Invoking ${c}`,metadata:{args:t.args}},m=e.toolStreamingMessageId;if(!m){const x={id:`tool-${f}`,role:"tool",name:c,createdAt:new Date().toISOString(),content:[h],additionalKwargs:{...nx(void 0,d.length?d:[f],c,t.args),toolStreaming:!0}},b=rx(x,d.length?d:[f]),S=[...e.messages,x],k=No(S,x.id,p);return{...e,messages:k,toolIndex:ec(e.toolIndex,x.id,b),toolStreamingMessageId:x.id,toolStreamingStack:tc(e.toolStreamingStack??[],l??f)}}const g=No(e.messages,m,p);return{...e,messages:g,toolIndex:ec(e.toolIndex,m,d),toolStreamingStack:tc(e.toolStreamingStack??[],l??f)}}if(t.type==="tool_end"){const a=Ql(t);if(!a.length&&!(typeof t.id=="string"&&t.id))return e;const l=a[0]??(typeof t.id=="string"?t.id:null);if(!l)return e;const c=e.toolStreamingStack??[],d=c[0]??null,f=ox(c,l),h=f[0]?e.toolIndex[f[0]]:null,p=e.toolStreamingMessageId,m=d===l,g=t.name??((s=e.messages.find(k=>k.id===p))==null?void 0:s.name)??"tool",y=typeof t.output=="string"?t.output.trim():JSON.stringify(t.output??""),x={type:"tool_end",toolId:l,toolName:g,title:`${g} completed`,content:y==null?void 0:y.slice(0,200)};let b=e.messages;if(p&&(b=No(b,p,x)),m&&p){const k=b.findIndex(C=>C.id===p);if(k>=0){const C=b[k],I={type:"text",text:(()=>{if(typeof t.output=="string"){const N=t.output.trim();try{return N}catch{return N}}return JSON.stringify(t.output??"")})()},A={...C,content:[I],artifact:t.artifact??C.artifact,additionalKwargs:{...C.additionalKwargs??{}}};b=Ao(b,k,A)}}return{...e,messages:b,toolStreamingMessageId:m?h:p,toolStreamingStack:f}}if(t.type==="progress"){const a=e.toolStreamingMessageId;if(!a)return e;const l={type:"progress",step:t.step??null,title:t.title??null,content:t.content??null,factsFound:typeof t.facts_found=="number"?t.facts_found:null,isSufficient:typeof t.is_sufficient=="boolean"?t.is_sufficient:null},c=No(e.messages,a,l),d={...((i=e.messages.find(m=>m.id===a))==null?void 0:i.additionalKwargs)??{},toolStreaming:!0},f=c.findIndex(m=>m.id===a),h=f>=0?{...c[f],additionalKwargs:d}:null,p=h?Ao(c,f,h):c;return{...e,messages:p}}if(t.type==="checkpoint"){const a=t.checkpointNs??e.lastCheckpointNs??null,l=ax(e.messages,t.checkpointId,a);return{...e,lastCheckpointId:t.checkpointId,lastCheckpointNs:a,messages:l}}if(t.type==="branch"){const a=t.checkpointId??e.lastCheckpointId,l=t.checkpointNs??e.lastCheckpointNs;return{...e,lastBranch:t,lastCheckpointId:a??null,lastCheckpointNs:l??null}}if(t.type==="error"){const a={id:`err-${Date.now()}`,role:"system",content:[{type:"text",text:`Error: ${t.message}`}],createdAt:new Date().toISOString()};return{...e,messages:[...e.messages,a]}}if(t.type==="state_history"){const a=fr(t),l=a.interrupt,c=a.latest,d=l===null?Jl(e.messages):e.messages;return{...e,messages:d,pendingInterrupt:l,lastCheckpointId:(c==null?void 0:c.checkpointId)??e.lastCheckpointId,lastCheckpointNs:(c==null?void 0:c.checkpointNs)??e.lastCheckpointNs}}return t.type==="thread_info",e}function pi(e){return e.filter(t=>{var s;if(t.role!=="assistant")return!0;const n=(t.content||[]).some(i=>{var a;return i&&i.type==="text"&&((a=i.text)==null?void 0:a.trim())}),r=(t.content||[]).some(i=>i&&i.type==="image_url"),o=!!((s=t.artifact)!=null&&s.plots&&t.artifact.plots.length>0);return!!(n||r||o)})}function Ao(e,t,n){return t<0||t>=e.length?e:[...e.slice(0,t),n,...e.slice(t+1)]}function Jl(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 Zl(e){for(let t=e.length-1;t>=0;t--)if(e[t].role==="assistant")return e[t].id;return null}function Ql(e){const t=new Set,n=r=>{typeof r=="string"&&r.trim()&&t.add(r.trim())};return n(e.id),n(e==null?void 0:e.call_id),n(e==null?void 0:e.callId),Array.from(t)}function tx(e){if(!e)return[];const t=new Set,n=o=>{typeof o=="string"&&o.trim()&&t.add(o.trim())},r=e.additionalKwargs;if(r){n(r.toolCallId);const o=r.toolCallIds;if(Array.isArray(o))for(const s of o)n(s)}for(const o of e.content??[])(o==null?void 0:o.type)==="tool_call"&&n(o.id);return Array.from(t)}function nx(e,t,n,r){const o=new Set,s=l=>{typeof l=="string"&&l.trim()&&o.add(l.trim())};for(const l of t)s(l);const i=Array.from(o),a={};if(i.length){a.toolCallIds=i;const l=typeof a.toolCallId=="string"?a.toolCallId.trim():null;a.toolCallId=l&&o.has(l)?l:i[0]}return n&&(a.toolName=n),r!==void 0&&(a.toolArgs=r),a}function rx(e,t){const n=new Set;for(const o of t)typeof o=="string"&&o.trim()&&n.add(o.trim());const r=tx(e);for(const o of r)n.add(o);return Array.from(n)}function ec(e,t,n){if(!n.length)return e;let r=!1;const o={...e};for(const s of n)s&&o[s]!==t&&(o[s]=t,r=!0);return r?o:e}function No(e,t,n){const r=e.findIndex(c=>c.id===t);if(r===-1)return e;const o=e[r],s=[...e],i={...o.additionalKwargs??{}},a=Array.isArray(i.toolProgress)?[...i.toolProgress]:[],l={id:Jg(),idx:a.length+1,timestamp:new Date().toISOString(),...n};return a.push(l),i.toolProgress=a,s[r]={...o,additionalKwargs:i},s}function tc(e,t){return e.includes(t)?e:[...e,t]}function ox(e,t){const n=[...e],r=n.lastIndexOf(t);return r!==-1&&n.splice(r,1),n}function nc(e){return!e||!e.length?"":e.filter(t=>t.type==="text").map(t=>t.text??"").join("")}function sx(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??nc(e);let l="",c=e.slice();if(s){const f=ix(a,s);if(f===""?l="":f===s?l=s:l=f,l){const h=c[c.length-1];if((h==null?void 0:h.type)==="text"){const p=h.text??"",m={...h,text:p+l};c=[...c.slice(0,c.length-1),m]}else c=[...c,{type:"text",text:l}];o.lastText=a+l}else o.lastText=a}i.length&&(c=[...c,...i]);const d=!!(l||i.length);return{newParts:c,newMeta:o,changed:d}}function rc(e){return e.replace(/\s+/g," ").trim()}function ix(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 ax(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 Ao(e,r,s)}return e}function lx(e){if(!e)return null;const t=e.split("/");return t[t.length-1]||null}const oc=200;function cx({baseUrl:e,onThreadInfo:t,onMessageEvent:n,onStateHistory:r,onUnhandledEvent:o,onSequenceGap:s,onStreamClosed:i,onConnectionError:a,onAuthError:l,onHeartbeat:c}){const d=w.useRef(null),f=w.useRef(null),h=w.useRef(new Map),p=w.useRef(null),m=w.useRef(null),g=w.useCallback(R=>{try{const O=globalThis.structuredClone;if(typeof O=="function")return O(R)}catch{}try{return JSON.parse(JSON.stringify(R))}catch{return R}},[]),y=w.useCallback((R,O)=>{if(!R)return;const F=h.current.get(R)??[],_=g(O),B=F.length>=oc?[...F.slice(F.length-oc+1),_]:[...F,_];h.current.set(R,B)},[g]),x=w.useCallback(R=>{R&&h.current.set(R,[])},[]),b=w.useCallback(R=>{const O=R??f.current;if(!O)return;const F=h.current.get(O);F!=null&&F.length&&F.forEach(_=>{try{n(_)}catch(B){console.error("[useChatStreamingService] Failed to replay buffered event",B)}})},[n]),S=w.useCallback(R=>{var _,B,j,K,z;const O=R.seq??null;if(O!==null){const M=d.current;if(M!==null){if(O<=M)return;O>M+1&&(s==null||s({from:M,to:O}))}d.current=O}if(R.type==="thread_info"){f.current=R.threadId,p.current&&(p.current.threadIdGuess=R.threadId),m.current=R,x(R.threadId),console.log("[useChatStreamingService] 🎯 Received thread_info event:",R);try{t(R)}catch(M){console.error("[useChatStreamingService] Error in onThreadInfo handler:",M)}return}if(R.type==="heartbeat"){try{c==null||c(R)}catch(M){console.error("[useChatStreamingService] Error in onHeartbeat handler:",M)}return}if(R.type==="error"){const M=R;if(M.error_type==="auth_error"||M.code==="TOKEN_EXPIRED"||((_=M.message)==null?void 0:_.includes("token"))||((B=M.message)==null?void 0:B.includes("401"))||((j=M.message)==null?void 0:j.includes("unauthorized"))||((K=M.message)==null?void 0:K.includes("Unauthorized"))){console.error("[useChatStreamingService] Auth error event detected:",M.message);try{l==null||l(M.message)}catch(X){console.warn("[useChatStreamingService] onAuthError handler failed",X)}}}const F=R.threadId??(R.type==="state_history"?R.threadId:void 0)??f.current??((z=p.current)==null?void 0:z.threadIdGuess)??null;if(R.type==="state_history"){f.current=F??f.current;try{r==null||r(R)}catch(M){console.error("[useChatStreamingService] onStateHistory handler failed",M)}}if(Zg(R)){R.type==="checkpoint"||R.type==="state_history"?x(F??null):y(F??null,R);try{n(R)}catch(M){console.error("[useChatStreamingService] Error in onMessageEvent handler:",M)}return}try{o==null||o(R)}catch(M){console.error("[useChatStreamingService] Error in onUnhandledEvent handler:",M)}},[y,x,n,s,t,r,o]),{stream:k,stop:C,isStreaming:T,error:I,setToken:A}=ql({baseUrl:e,token:void 0}),N=w.useCallback((R,O)=>{d.current=null,m.current=null,f.current=R.threadId??null,p.current={request:R,callbacks:O,manualStop:!1,threadIdGuess:R.threadId??null},k(R,S,{onOpen:O==null?void 0:O.onOpen,onError:F=>{var _;(_=O==null?void 0:O.onError)==null||_.call(O,F)},onGap:(O==null?void 0:O.onGap)??s,onConnectionError:F=>{var _;a==null||a(F),(_=O==null?void 0:O.onConnectionError)==null||_.call(O,F)},onAuthError:F=>{var _;l==null||l(F),(_=O==null?void 0:O.onAuthError)==null||_.call(O,F)},onHeartbeat:F=>{var _;try{c==null||c(F)}catch(B){console.warn("[useChatStreamingService] onHeartbeat handler failed",B)}try{(_=O==null?void 0:O.onHeartbeat)==null||_.call(O,F)}catch(B){console.warn("[useChatStreamingService] downstream onHeartbeat handler failed",B)}},onClosed:F=>{var K,z,M,G;const _=((K=p.current)==null?void 0:K.manualStop)??!1,B=f.current??((z=p.current)==null?void 0:z.threadIdGuess)??((M=F.lastStateHistory)==null?void 0:M.threadId)??null;(F.reason==="complete"||F.reason==="aborted"&&_)&&x(B);const j={...F,threadId:B,threadInfo:m.current,manualStop:_};try{i==null||i(j)}catch(X){console.warn("[useChatStreamingService] onStreamClosed handler failed",X)}try{(G=O==null?void 0:O.onClosed)==null||G.call(O,j)}catch(X){console.warn("[useChatStreamingService] downstream onClosed handler failed",X)}p.current&&(p.current=null)}})},[x,S,l,a,c,s,i,k]),L=w.useCallback(()=>{p.current&&(p.current.manualStop=!0),C()},[C]);return w.useMemo(()=>({startStream:N,stop:L,isStreaming:T,error:I,setAuthToken:A,replayBufferedEvents:b}),[N,L,T,I,A,b])}const sc=w.createContext(null),ic=w.createContext(null),ac=w.createContext(null);w.createContext(!1);function ux({children:e,initialThreadId:t=null,initialCheckpointId:n=null,initialCheckpointNs:r=null,autoLoadInitial:o=!0,onError:s,onAuthError:i,onThreadChange:a,onConnectionError:l}){const{api:c,baseUrl:d}=ui(),f=w.useMemo(()=>Sn(d),[d]),[h,p]=w.useState([]),[m,g]=w.useState(t),[y,x]=w.useState(!1),[b,S]=w.useState(null),[k,C]=w.useState(!1),[T,I]=w.useState(null),{state:A,seed:N,prepend:L,pushUser:R,onEvent:O}=Yl(),[F,_]=w.useState(!1),[B,j]=w.useState(!1),[K,z]=w.useState(null),[M,G]=w.useState([]),[X,se]=w.useState([]),[be,Ie]=w.useState(!1),Y=w.useMemo(()=>Wg(M),[M]),U=w.useRef(m),J=w.useRef(null),$=w.useRef(null),q=w.useRef(null),Z=w.useRef(null),ue=w.useRef(!1),ie=w.useRef(null),_e=w.useRef(new Map),He=w.useRef(new Map);w.useEffect(()=>{U.current=m},[m]);const oe=w.useCallback(async()=>{x(!0),S(null);try{const H=await c.listThreads();p(H??[])}catch(H){const re=String(H);S(re),s==null||s(re)}finally{x(!1)}},[c,s]),ye=w.useCallback(H=>{if(!(H!=null&&H.threadId))return;const re={threadId:H.threadId,title:H.title||`Thread ${H.threadId.slice(0,8)}`,createdAt:H.createdAt||new Date().toISOString(),updatedAt:H.updatedAt||new Date().toISOString(),messageCount:H.messageCount??1};p(D=>{let Q=!1;const ne=D.map(me=>me.threadId===re.threadId?(Q=!0,console.debug("[ChatSessionProvider] thread_info: updating existing thread",re.threadId),{...me,title:re.title??me.title,updatedAt:re.updatedAt??me.updatedAt,messageCount:re.messageCount??me.messageCount}):me);return Q?ne:(console.debug("[ChatSessionProvider] thread_info: adding thread to list",re.threadId),[re,...D])})},[]),Oe=w.useCallback(H=>{const re=H.threadId??U.current;if(!re||U.current&&U.current!==re)return;const{checkpoints:D,timeline:Q}=fr(H);if(!D.length)return;const ne=D.find(me=>me.messages&&me.messages.length>0)??D.find(me=>!!me.checkpointId)??D[0];N((ne==null?void 0:ne.messages)??[],{checkpointId:(ne==null?void 0:ne.checkpointId)??null,checkpointNs:(ne==null?void 0:ne.checkpointNs)??null}),se(Q),G(D),_(!!(ne!=null&&ne.nextCursor)),z((ne==null?void 0:ne.nextCursor)??null),ie.current=`${re}:latest`,$.current=null,q.current=null},[N]),Ye=w.useCallback(H=>{console.log("[ChatSessionProvider] 🎯 Received thread_info:",H.threadId),ye(H),U.current!==H.threadId&&((H.created??!U.current)&&($.current=H.threadId),q.current=H.threadId,console.log("[ChatSessionProvider] thread_info: marking to skip auto-load for new thread"),g(H.threadId))},[ye]),{startStream:nt,stop:Xe,isStreaming:qe,error:it,setAuthToken:Je}=cx({baseUrl:f,onThreadInfo:Ye,onMessageEvent:O,onStateHistory:Oe,onUnhandledEvent:H=>{console.warn("[ChatSessionProvider] Unhandled event:",H.type)},onAuthError:i,onConnectionError:l}),et=w.useCallback(async H=>{try{const re=await c.createThread(H);return g(re.threadId),await oe(),re.threadId}catch(re){return s==null||s(String(re)),null}},[c,oe,s]),at=w.useCallback(async H=>{const re=h;p(Q=>Q.filter(ne=>ne.threadId!==H));const D=new AbortController;He.current.set(H,D);try{await c.deleteThread(H),U.current===H&&(g(null),N([],{})),console.log("[ChatSessionProvider] Thread deleted successfully:",H)}catch(Q){console.error("[ChatSessionProvider] Delete failed, restoring thread:",H,Q),p(re),s==null||s(`Failed to delete thread: ${String(Q)}`)}finally{He.current.delete(H)}},[h,c,N,s]),jt=w.useCallback(async(H,re)=>{try{await c.updateThread(H,re),await oe()}catch(D){s==null||s(String(D))}},[c,oe,s]),ht=w.useCallback(async(H,re)=>{if(!H)return;const D=`${H}:${re??"latest"}`,Q=_e.current.get(D);if(Q)return Q;const ne=(async()=>{const me=H;C(!0),I(null);try{const xe=await c.getStateHistory({threadId:me,checkpointId:re||void 0});if(U.current!==me){console.log(`[ChatSessionProvider] Thread changed during load (was ${me}, now ${U.current}), discarding stale data`);return}const{checkpoints:De,timeline:Re}=fr(xe),je=De.find(Kt=>Kt.messages&&Kt.messages.length>0)??(re?De.find(Kt=>Kt.checkpointId===re):null)??De[0];N((je==null?void 0:je.messages)??[],{checkpointId:(je==null?void 0:je.checkpointId)??null,checkpointNs:(je==null?void 0:je.checkpointNs)??null}),se(Re),G(De),_(!!(je!=null&&je.nextCursor)),z((je==null?void 0:je.nextCursor)??null)}catch(xe){if(U.current===me){const De=String(xe);I(De),s==null||s(De)}}finally{C(!1)}})();_e.current.set(D,ne);try{await ne}finally{_e.current.delete(D)}return U.current===H&&(ie.current=D),ne},[c,N,s]),ft=w.useCallback(async(H,re)=>{Z.current=H;try{await ht(H,re)}finally{Z.current===H&&(Z.current=null)}},[ht]);w.useEffect(()=>{if(!o||!m||k||qe)return;if($.current===m){$.current=null,J.current=m;return}if(q.current===m){J.current=m;return}if(Z.current===m){Z.current=null,J.current=m;return}if(J.current===m)return;J.current=m;const H=!ue.current&&!!n&&m===t;let re;H&&n?(re=n,ue.current=!0,console.log("[ChatSessionProvider] Loading thread with checkpoint:",re,r?`(ns: ${r})`:"")):console.log("[ChatSessionProvider] Loading thread with latest checkpoint");const D=`${m}:${re??"latest"}`;ie.current!==D&&ft(m,re)},[o,m,n,r,t,k,qe,ft]);const mt=w.useCallback(async(H,re)=>{const D=U.current;if(!D)return;const Q=D;Ie(!0);try{const ne=await c.getStateHistory({threadId:Q,checkpointId:H,checkpointNs:re??void 0});if(U.current!==Q){console.log(`[ChatSessionProvider] Thread changed during checkpoint navigation (was ${Q}, now ${U.current}), discarding stale data`);return}const{checkpoints:me,timeline:xe}=fr(ne),De=me.find(Re=>Re.checkpointId===H&&(re?Re.checkpointNs===re:!0));if(!De){console.warn("[ChatSessionProvider] Requested checkpoint not found:",{checkpointId:H,checkpointNs:re});return}se(xe),G(me),N(De.messages??[],{checkpointId:De.checkpointId??null,checkpointNs:De.checkpointNs??null})}catch(ne){U.current===Q&&(s==null||s(String(ne)))}finally{Ie(!1)}},[c,N,s]),St=w.useCallback((H,re)=>{N(A.messages,{checkpointId:H??null,checkpointNs:re??null})},[N,A.messages]),Mt=w.useCallback(async()=>{U.current&&await ft(U.current)},[ft]),Lt=w.useCallback(async()=>{if(!U.current||!K)return;const H=U.current;j(!0);try{const re=await c.getStateHistory({threadId:H,checkpointId:K});if(U.current!==H)return;const{checkpoints:D}=fr(re);if(D.length>0){const Q=D[D.length-1];L((Q==null?void 0:Q.messages)??[]),_(!!(Q!=null&&Q.nextCursor)),z((Q==null?void 0:Q.nextCursor)??null)}}catch(re){U.current===H&&(s==null||s(String(re)))}finally{j(!1)}},[c,K,L,s]),Vt=w.useCallback(async()=>{N([],{}),g(null),Xe(),G([]),se([]),_(!1),z(null),C(!1),Ie(!1),j(!1),I(null);try{await c.getAgent("default")}catch(H){console.warn("[ChatSessionProvider] Failed to refetch agent after clearing thread:",H)}},[N,Xe,c]),Ue=w.useCallback(async(H,re,D)=>{const Q=U.current;if(!Q)throw new Error("No active thread to handle interrupt");const ne=re?D??!0:!1;try{const me={threadId:Q,checkpointId:A.lastCheckpointId??void 0,checkpointNs:A.lastCheckpointNs??void 0,command:{kind:"resume",value:ne}};nt(me)}catch(me){throw console.error(`[ChatSessionProvider] Failed to handle interrupt ${H}:`,me),me}},[A.lastCheckpointId,A.lastCheckpointNs,nt]);w.useEffect(()=>{oe()},[oe]),w.useEffect(()=>{a==null||a(m)},[m,a]);const dn=w.useCallback(async(H,re)=>{let D=U.current;const Q=(H==null?void 0:H.text)??"",ne=(H==null?void 0:H.attachments)??[],me=(Q==null?void 0:Q.trim())??"",xe={...(H==null?void 0:H.payload)??{}},De=Array.isArray(xe.messages)?xe.messages:void 0;De&&delete xe.messages;const Re=!!(De&&De.length);if(!D&&!me&&ne.length===0&&!Re)return;if(!D){const ae=Math.floor(Date.now()/1e3).toString(16).padStart(8,"0"),we=Array.from({length:4},()=>Math.floor(Math.random()*4294967295).toString(16).padStart(8,"0")).join("").slice(0,16);D=`${ae}${we}`,$.current=D,g(D)}const{contentParts:je,filesInfo:Kt}=await vg(c,ne),An=[...je];me&&An.push({type:"text",text:Q});const ar=re==null?void 0:re.originalMessageId,Ar=!!(re!=null&&re.edit&&ar),fo=!Re&&An.length>0;let Un=null;fo&&(Un={id:Ar?ar:`msg-${Date.now()}`,role:"user",content:An,createdAt:new Date().toISOString()},Ar||R(Un));const lr=Re?De:Un?[Un]:[],E={...xe,...Kt.length?{files_info:Kt}:{}};lr.length?E.messages=lr:"messages"in E||(E.messages=[]);const V={threadId:D,payload:E,checkpointId:(re==null?void 0:re.checkpointId)??A.lastCheckpointId??void 0,checkpointNs:(re==null?void 0:re.checkpointNs)??A.lastCheckpointNs??void 0,edit:!!(re!=null&&re.edit),timelineCheckpoints:X};nt(V)},[c,R,A,nt,X]),rt=w.useMemo(()=>({threads:h,currentThreadId:m,setCurrentThreadId:g,isLoading:y,error:b,actions:{createThread:et,deleteThread:at,renameThread:jt,refreshThreads:oe}}),[h,m,y,b,et,at,jt,oe]),We=w.useMemo(()=>{const H=A.assemblingId??null;return H?{assemblingMessageId:H}:null},[A.assemblingId]),gt=w.useMemo(()=>({threadId:m,messages:A.messages,interrupt:null,checkpoint:{id:A.lastCheckpointId??null,namespace:A.lastCheckpointNs??null},checkpoints:M,timelineCheckpoints:X,metadata:We,isLoading:k,isHistoryLoading:B,isLoadingCheckpoint:be,error:T,hasMore:F,loadOlder:Lt,clearState:Vt,navigateToCheckpoint:mt,setCurrentCheckpointId:St,returnToLatest:Mt,loadThread:ft,clearThread:Vt,respondToInterrupt:Ue,messagePreviews:Y}),[m,A,M,X,k,B,be,T,F,Lt,Vt,mt,St,Mt,ft,Ue,Y,We]),Rt=w.useMemo(()=>({isStreaming:qe,error:it,connectionState:qe?"connected":"idle",submit:dn,send:dn,stop:Xe,setAuthToken:Je}),[qe,it,dn,Xe,Je]);return u.jsx(sc.Provider,{value:rt,children:u.jsx(ic.Provider,{value:gt,children:u.jsx(ac.Provider,{value:Rt,children:e})})})}function _o(){const e=w.useContext(sc);if(!e)throw new Error("useThreads must be used within ChatSessionProvider");return e}function jo(){const e=w.useContext(ic);if(!e)throw new Error("useThreadState must be used within ChatSessionProvider");return e}function lc(){const e=w.useContext(ac);if(!e)throw new Error("useStream must be used within ChatSessionProvider");return e}function Mo({children:e,apiConfig:t,initialThreadId:n=null,initialCheckpointId:r=null,initialCheckpointNs:o=null,autoLoadInitial:s=!0,onConnectionError:i,onError:a,onAuthError:l,onThreadChange:c}){return u.jsx(xg,{apiConfig:t,children:u.jsx(ux,{initialThreadId:n,initialCheckpointId:r,initialCheckpointNs:o,autoLoadInitial:s,onError:a,onAuthError:l,onConnectionError:i,onThreadChange:c,children:e})})}function te(...e){return Wh.twMerge(Hh.clsx(e))}const dx=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"}}),Ze=v.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?Wn.Slot:"button";return u.jsx(i,{className:te(dx({variant:t,size:n,className:e})),ref:s,...o})});Ze.displayName="Button";const cc=v.forwardRef(({className:e,...t},n)=>u.jsx("textarea",{className:te("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}));cc.displayName="Textarea";function uc({initialValue:e="",editingMessageId:t=null,placeholder:n="Type your message...",isStreaming:r=!1,disabled:o=!1,maxLength:s=2e4,value:i,onValueChange:a,onSend:l,onCancelEdit:c,onStop:d,className:f="",textareaClassName:h="",allowEmptySend:p=!1}){const m=i!==void 0,[g,y]=w.useState(e),x=(m?i:g)??"",[b,S]=w.useTransition(),k=w.useRef(null),C=w.useRef(0),T=w.useRef(null);w.useEffect(()=>{m||(y(e??""),T.current=null,k.current&&(k.current.style.height="auto",k.current.style.height=`${k.current.scrollHeight}px`))},[e,t,m]);const I=w.useCallback(()=>{const B=k.current;B&&(B.style.height="auto",B.style.height=`${B.scrollHeight}px`)},[]);w.useEffect(()=>{I()},[I,x]);const A=w.useCallback((B,{fromUser:j})=>{m||y(B),j&&(a==null||a(B))},[m,a]),N=w.useCallback(async B=>{B&&B.preventDefault();const j=(x??"").trim();if(!j&&!p)return;const K=++C.current;T.current={id:K,shouldClear:!0},S(()=>{var z,M,G;try{const X=l(j);X&&typeof X.then=="function"?X.then(()=>{var se,be;((se=T.current)==null?void 0:se.id)===K&&T.current.shouldClear&&(m||(y(""),k.current&&(k.current.style.height="auto"),a==null||a(""))),((be=T.current)==null?void 0:be.id)===K&&(T.current=null)}).catch(()=>{var se;((se=T.current)==null?void 0:se.id)===K&&(T.current=null)}):(((z=T.current)==null?void 0:z.id)===K&&T.current.shouldClear&&(m||(y(""),k.current&&(k.current.style.height="auto"),a==null||a(""))),((M=T.current)==null?void 0:M.id)===K&&(T.current=null))}catch{((G=T.current)==null?void 0:G.id)===K&&(T.current=null)}})},[x,l,p,m,a]),L=w.useCallback(B=>{const j=B.target.value;A(j,{fromUser:!0}),T.current&&(T.current.shouldClear=!1),k.current&&(k.current.style.height="auto",k.current.style.height=`${k.current.scrollHeight}px`)},[A]),R=w.useCallback(B=>{B.key==="Enter"&&!B.shiftKey?(B.preventDefault(),N()):B.key==="Escape"&&t&&(B.preventDefault(),c==null||c())},[N,t,c]),_=`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${t?"border-[hsl(var(--ring))] bg-[hsl(var(--card))] text-[hsl(var(--card-foreground))] dark:bg-[hsl(var(--card))] dark:text-[hsl(var(--card-foreground))]":""} ${h}`;return u.jsx("form",{onSubmit:B=>void N(B),className:`w-full ${f}`,children:u.jsxs("div",{className:"flex items-end gap-2",children:[u.jsx("div",{className:"flex-1",children:u.jsx(cc,{ref:k,value:x,onChange:L,onKeyDown:R,placeholder:t?"Edit your message...":n,className:_,disabled:o,maxLength:s,rows:1,spellCheck:!1,autoCorrect:"off"})}),u.jsx("div",{children:r?u.jsx(Ze,{type:"button",onClick:()=>{d==null||d()},size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",disabled:o||!d,children:u.jsx(le.Square,{size:16})}):u.jsx(Ze,{type:"submit",size:"icon",className:"shrink-0",title:t?"Save changes":"Send message",disabled:o||!x.trim()&&!p||b,children:u.jsx(le.Send,{size:16})})})]})})}const fx=w.memo(uc);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 dc(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function hi(...e){return t=>{let n=!1;const r=e.map(o=>{const s=dc(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():dc(e[o],null)}}}}function Be(...e){return v.useCallback(hi(...e),e)}function px(e,t){const n=v.createContext(t),r=s=>{const{children:i,...a}=s,l=v.useMemo(()=>a,Object.values(a));return u.jsx(n.Provider,{value:l,children:i})};r.displayName=e+"Provider";function o(s){const i=v.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=v.createContext(i),l=n.length;n=[...n,i];const c=f=>{var x;const{scope:h,children:p,...m}=f,g=((x=h==null?void 0:h[e])==null?void 0:x[l])||a,y=v.useMemo(()=>m,Object.values(m));return u.jsx(g.Provider,{value:y,children:p})};c.displayName=s+"Provider";function d(f,h){var g;const p=((g=h==null?void 0:h[e])==null?void 0:g[l])||a,m=v.useContext(p);if(m)return m;if(i!==void 0)return i;throw new Error(`\`${f}\` must be used within \`${s}\``)}return[c,d]}const o=()=>{const s=n.map(i=>v.createContext(i));return function(a){const l=(a==null?void 0:a[e])||s;return v.useMemo(()=>({[`__scope${e}`]:{...a,[e]:l}}),[a,l])}};return o.scopeName=e,[r,hx(o,...t)]}function hx(...e){const t=e[0];if(e.length===1)return t;const n=()=>{const r=e.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(s){const i=r.reduce((a,{useScope:l,scopeName:c})=>{const f=l(s)[`__scope${c}`];return{...a,...f}},{});return v.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}var Tt=globalThis!=null&&globalThis.document?v.useLayoutEffect:()=>{},mx=v[" useInsertionEffect ".trim().toString()]||Tt;function pr({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=gx({defaultProp:t,onChange:n}),a=e!==void 0,l=a?e:o;{const d=v.useRef(e!==void 0);v.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 c=v.useCallback(d=>{var f;if(a){const h=xx(d)?d(e):d;h!==e&&((f=i.current)==null||f.call(i,h))}else s(d)},[a,e,s,i]);return[l,c]}function gx({defaultProp:e,onChange:t}){const[n,r]=v.useState(e),o=v.useRef(n),s=v.useRef(t);return mx(()=>{s.current=t},[t]),v.useEffect(()=>{var i;o.current!==n&&((i=s.current)==null||i.call(s,n),o.current=n)},[n,o]),[n,r,s]}function xx(e){return typeof e=="function"}var yx=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Ne=yx.reduce((e,t)=>{const n=Wn.createSlot(`Primitive.${t}`),r=v.forwardRef((o,s)=>{const{asChild:i,...a}=o,l=i?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),u.jsx(l,{...a,ref:s})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function fc(e,t){e&&ho.flushSync(()=>e.dispatchEvent(t))}function mi(e){const t=e+"CollectionProvider",[n,r]=Cn(t),[o,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),i=g=>{const{scope:y,children:x}=g,b=w.useRef(null),S=w.useRef(new Map).current;return u.jsx(o,{scope:y,itemMap:S,collectionRef:b,children:x})};i.displayName=t;const a=e+"CollectionSlot",l=Wn.createSlot(a),c=w.forwardRef((g,y)=>{const{scope:x,children:b}=g,S=s(a,x),k=Be(y,S.collectionRef);return u.jsx(l,{ref:k,children:b})});c.displayName=a;const d=e+"CollectionItemSlot",f="data-radix-collection-item",h=Wn.createSlot(d),p=w.forwardRef((g,y)=>{const{scope:x,children:b,...S}=g,k=w.useRef(null),C=Be(y,k),T=s(d,x);return w.useEffect(()=>(T.itemMap.set(k,{ref:k,...S}),()=>void T.itemMap.delete(k))),u.jsx(h,{[f]:"",ref:C,children:b})});p.displayName=d;function m(g){const y=s(e+"CollectionConsumer",g);return w.useCallback(()=>{const b=y.collectionRef.current;if(!b)return[];const S=Array.from(b.querySelectorAll(`[${f}]`));return Array.from(y.itemMap.values()).sort((T,I)=>S.indexOf(T.ref.current)-S.indexOf(I.ref.current))},[y.collectionRef,y.itemMap])}return[{Provider:i,Slot:c,ItemSlot:p},m,r]}var vx=v.createContext(void 0);function Ro(e){const t=v.useContext(vx);return e||t||"ltr"}function kt(e){const t=v.useRef(e);return v.useEffect(()=>{t.current=e}),v.useMemo(()=>(...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)},[])}function bx(e,t=globalThis==null?void 0:globalThis.document){const n=kt(e);v.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 wx="DismissableLayer",gi="dismissableLayer.update",Sx="dismissableLayer.pointerDownOutside",Cx="dismissableLayer.focusOutside",pc,hc=v.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),Po=v.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:a,...l}=e,c=v.useContext(hc),[d,f]=v.useState(null),h=(d==null?void 0:d.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,p]=v.useState({}),m=Be(t,I=>f(I)),g=Array.from(c.layers),[y]=[...c.layersWithOutsidePointerEventsDisabled].slice(-1),x=g.indexOf(y),b=d?g.indexOf(d):-1,S=c.layersWithOutsidePointerEventsDisabled.size>0,k=b>=x,C=Ix(I=>{const A=I.target,N=[...c.branches].some(L=>L.contains(A));!k||N||(o==null||o(I),i==null||i(I),I.defaultPrevented||a==null||a())},h),T=Ex(I=>{const A=I.target;[...c.branches].some(L=>L.contains(A))||(s==null||s(I),i==null||i(I),I.defaultPrevented||a==null||a())},h);return bx(I=>{b===c.layers.size-1&&(r==null||r(I),!I.defaultPrevented&&a&&(I.preventDefault(),a()))},h),v.useEffect(()=>{if(d)return n&&(c.layersWithOutsidePointerEventsDisabled.size===0&&(pc=h.body.style.pointerEvents,h.body.style.pointerEvents="none"),c.layersWithOutsidePointerEventsDisabled.add(d)),c.layers.add(d),mc(),()=>{n&&c.layersWithOutsidePointerEventsDisabled.size===1&&(h.body.style.pointerEvents=pc)}},[d,h,n,c]),v.useEffect(()=>()=>{d&&(c.layers.delete(d),c.layersWithOutsidePointerEventsDisabled.delete(d),mc())},[d,c]),v.useEffect(()=>{const I=()=>p({});return document.addEventListener(gi,I),()=>document.removeEventListener(gi,I)},[]),u.jsx(Ne.div,{...l,ref:m,style:{pointerEvents:S?k?"auto":"none":void 0,...e.style},onFocusCapture:fe(e.onFocusCapture,T.onFocusCapture),onBlurCapture:fe(e.onBlurCapture,T.onBlurCapture),onPointerDownCapture:fe(e.onPointerDownCapture,C.onPointerDownCapture)})});Po.displayName=wx;var Tx="DismissableLayerBranch",kx=v.forwardRef((e,t)=>{const n=v.useContext(hc),r=v.useRef(null),o=Be(t,r);return v.useEffect(()=>{const s=r.current;if(s)return n.branches.add(s),()=>{n.branches.delete(s)}},[n.branches]),u.jsx(Ne.div,{...e,ref:o})});kx.displayName=Tx;function Ix(e,t=globalThis==null?void 0:globalThis.document){const n=kt(e),r=v.useRef(!1),o=v.useRef(()=>{});return v.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let l=function(){gc(Sx,n,c,{discrete:!0})};const c={originalEvent:a};a.pointerType==="touch"?(t.removeEventListener("click",o.current),o.current=l,t.addEventListener("click",o.current,{once:!0})):l()}else t.removeEventListener("click",o.current);r.current=!1},i=window.setTimeout(()=>{t.addEventListener("pointerdown",s)},0);return()=>{window.clearTimeout(i),t.removeEventListener("pointerdown",s),t.removeEventListener("click",o.current)}},[t,n]),{onPointerDownCapture:()=>r.current=!0}}function Ex(e,t=globalThis==null?void 0:globalThis.document){const n=kt(e),r=v.useRef(!1);return v.useEffect(()=>{const o=s=>{s.target&&!r.current&&gc(Cx,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 mc(){const e=new CustomEvent(gi);document.dispatchEvent(e)}function gc(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?fc(o,s):o.dispatchEvent(s)}var xi=0;function yi(){v.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??xc()),document.body.insertAdjacentElement("beforeend",e[1]??xc()),xi++,()=>{xi===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),xi--}},[])}function xc(){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 vi="focusScope.autoFocusOnMount",bi="focusScope.autoFocusOnUnmount",yc={bubbles:!1,cancelable:!0},Ax="FocusScope",Oo=v.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:s,...i}=e,[a,l]=v.useState(null),c=kt(o),d=kt(s),f=v.useRef(null),h=Be(t,g=>l(g)),p=v.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;v.useEffect(()=>{if(r){let g=function(S){if(p.paused||!a)return;const k=S.target;a.contains(k)?f.current=k:_n(f.current,{select:!0})},y=function(S){if(p.paused||!a)return;const k=S.relatedTarget;k!==null&&(a.contains(k)||_n(f.current,{select:!0}))},x=function(S){if(document.activeElement===document.body)for(const C of S)C.removedNodes.length>0&&_n(a)};document.addEventListener("focusin",g),document.addEventListener("focusout",y);const b=new MutationObserver(x);return a&&b.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",g),document.removeEventListener("focusout",y),b.disconnect()}}},[r,a,p.paused]),v.useEffect(()=>{if(a){wc.add(p);const g=document.activeElement;if(!a.contains(g)){const x=new CustomEvent(vi,yc);a.addEventListener(vi,c),a.dispatchEvent(x),x.defaultPrevented||(Nx(Px(vc(a)),{select:!0}),document.activeElement===g&&_n(a))}return()=>{a.removeEventListener(vi,c),setTimeout(()=>{const x=new CustomEvent(bi,yc);a.addEventListener(bi,d),a.dispatchEvent(x),x.defaultPrevented||_n(g??document.body,{select:!0}),a.removeEventListener(bi,d),wc.remove(p)},0)}}},[a,c,d,p]);const m=v.useCallback(g=>{if(!n&&!r||p.paused)return;const y=g.key==="Tab"&&!g.altKey&&!g.ctrlKey&&!g.metaKey,x=document.activeElement;if(y&&x){const b=g.currentTarget,[S,k]=_x(b);S&&k?!g.shiftKey&&x===k?(g.preventDefault(),n&&_n(S,{select:!0})):g.shiftKey&&x===S&&(g.preventDefault(),n&&_n(k,{select:!0})):x===b&&g.preventDefault()}},[n,r,p.paused]);return u.jsx(Ne.div,{tabIndex:-1,...i,ref:h,onKeyDown:m})});Oo.displayName=Ax;function Nx(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(_n(r,{select:t}),document.activeElement!==n)return}function _x(e){const t=vc(e),n=bc(t,e),r=bc(t.reverse(),e);return[n,r]}function vc(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 bc(e,t){for(const n of e)if(!jx(n,{upTo:t}))return n}function jx(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 Mx(e){return e instanceof HTMLInputElement&&"select"in e}function _n(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&Mx(e)&&t&&e.select()}}var wc=Rx();function Rx(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=Sc(e,t),e.unshift(t)},remove(t){var n;e=Sc(e,t),(n=e[0])==null||n.resume()}}}function Sc(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function Px(e){return e.filter(t=>t.tagName!=="A")}var Ox=v[" useId ".trim().toString()]||(()=>{}),Dx=0;function Tn(e){const[t,n]=v.useState(Ox());return Tt(()=>{n(r=>r??String(Dx++))},[e]),t?`radix-${t}`:""}const Lx=["top","right","bottom","left"],jn=Math.min,zt=Math.max,Do=Math.round,Lo=Math.floor,pn=e=>({x:e,y:e}),$x={left:"right",right:"left",bottom:"top",top:"bottom"},Fx={start:"end",end:"start"};function wi(e,t,n){return zt(e,jn(t,n))}function kn(e,t){return typeof e=="function"?e(t):e}function In(e){return e.split("-")[0]}function hr(e){return e.split("-")[1]}function Si(e){return e==="x"?"y":"x"}function Ci(e){return e==="y"?"height":"width"}const Bx=new Set(["top","bottom"]);function hn(e){return Bx.has(In(e))?"y":"x"}function Ti(e){return Si(hn(e))}function zx(e,t,n){n===void 0&&(n=!1);const r=hr(e),o=Ti(e),s=Ci(o);let i=o==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(i=$o(i)),[i,$o(i)]}function Ux(e){const t=$o(e);return[ki(e),t,ki(t)]}function ki(e){return e.replace(/start|end/g,t=>Fx[t])}const Cc=["left","right"],Tc=["right","left"],Hx=["top","bottom"],Wx=["bottom","top"];function Vx(e,t,n){switch(e){case"top":case"bottom":return n?t?Tc:Cc:t?Cc:Tc;case"left":case"right":return t?Hx:Wx;default:return[]}}function Kx(e,t,n,r){const o=hr(e);let s=Vx(In(e),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(ki)))),s}function $o(e){return e.replace(/left|right|bottom|top/g,t=>$x[t])}function qx(e){return{top:0,right:0,bottom:0,left:0,...e}}function kc(e){return typeof e!="number"?qx(e):{top:e,right:e,bottom:e,left:e}}function Fo(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 Ic(e,t,n){let{reference:r,floating:o}=e;const s=hn(t),i=Ti(t),a=Ci(i),l=In(t),c=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(hr(t)){case"start":p[i]-=h*(n&&c?-1:1);break;case"end":p[i]+=h*(n&&c?-1:1);break}return p}const Gx=async(e,t,n)=>{const{placement:r="bottom",strategy:o="absolute",middleware:s=[],platform:i}=n,a=s.filter(Boolean),l=await(i.isRTL==null?void 0:i.isRTL(t));let c=await i.getElementRects({reference:e,floating:t,strategy:o}),{x:d,y:f}=Ic(c,r,l),h=r,p={},m=0;for(let g=0;g<a.length;g++){const{name:y,fn:x}=a[g],{x:b,y:S,data:k,reset:C}=await x({x:d,y:f,initialPlacement:r,placement:h,strategy:o,middlewareData:p,rects:c,platform:i,elements:{reference:e,floating:t}});d=b??d,f=S??f,p={...p,[y]:{...p[y],...k}},C&&m<=50&&(m++,typeof C=="object"&&(C.placement&&(h=C.placement),C.rects&&(c=C.rects===!0?await i.getElementRects({reference:e,floating:t,strategy:o}):C.rects),{x:d,y:f}=Ic(c,h,l)),g=-1)}return{x:d,y:f,placement:h,strategy:o,middlewareData:p}};async function Lr(e,t){var n;t===void 0&&(t={});const{x:r,y:o,platform:s,rects:i,elements:a,strategy:l}=e,{boundary:c="clippingAncestors",rootBoundary:d="viewport",elementContext:f="floating",altBoundary:h=!1,padding:p=0}=kn(t,e),m=kc(p),y=a[h?f==="floating"?"reference":"floating":f],x=Fo(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(y)))==null||n?y:y.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(a.floating)),boundary:c,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)),k=await(s.isElement==null?void 0:s.isElement(S))?await(s.getScale==null?void 0:s.getScale(S))||{x:1,y:1}:{x:1,y:1},C=Fo(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:b,offsetParent:S,strategy:l}):b);return{top:(x.top-C.top+m.top)/k.y,bottom:(C.bottom-x.bottom+m.bottom)/k.y,left:(x.left-C.left+m.left)/k.x,right:(C.right-x.right+m.right)/k.x}}const Yx=e=>({name:"arrow",options:e,async fn(t){const{x:n,y:r,placement:o,rects:s,platform:i,elements:a,middlewareData:l}=t,{element:c,padding:d=0}=kn(e,t)||{};if(c==null)return{};const f=kc(d),h={x:n,y:r},p=Ti(o),m=Ci(p),g=await i.getDimensions(c),y=p==="y",x=y?"top":"left",b=y?"bottom":"right",S=y?"clientHeight":"clientWidth",k=s.reference[m]+s.reference[p]-h[p]-s.floating[m],C=h[p]-s.reference[p],T=await(i.getOffsetParent==null?void 0:i.getOffsetParent(c));let I=T?T[S]:0;(!I||!await(i.isElement==null?void 0:i.isElement(T)))&&(I=a.floating[S]||s.floating[m]);const A=k/2-C/2,N=I/2-g[m]/2-1,L=jn(f[x],N),R=jn(f[b],N),O=L,F=I-g[m]-R,_=I/2-g[m]/2+A,B=wi(O,_,F),j=!l.arrow&&hr(o)!=null&&_!==B&&s.reference[m]/2-(_<O?L:R)-g[m]/2<0,K=j?_<O?_-O:_-F:0;return{[p]:h[p]+K,data:{[p]:B,centerOffset:_-B-K,...j&&{alignmentOffset:K}},reset:j}}}),Xx=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(t){var n,r;const{placement:o,middlewareData:s,rects:i,initialPlacement:a,platform:l,elements:c}=t,{mainAxis:d=!0,crossAxis:f=!0,fallbackPlacements:h,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:m="none",flipAlignment:g=!0,...y}=kn(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const x=In(o),b=hn(a),S=In(a)===a,k=await(l.isRTL==null?void 0:l.isRTL(c.floating)),C=h||(S||!g?[$o(a)]:Ux(a)),T=m!=="none";!h&&T&&C.push(...Kx(a,g,m,k));const I=[a,...C],A=await Lr(t,y),N=[];let L=((r=s.flip)==null?void 0:r.overflows)||[];if(d&&N.push(A[x]),f){const _=zx(o,i,k);N.push(A[_[0]],A[_[1]])}if(L=[...L,{placement:o,overflows:N}],!N.every(_=>_<=0)){var R,O;const _=(((R=s.flip)==null?void 0:R.index)||0)+1,B=I[_];if(B&&(!(f==="alignment"?b!==hn(B):!1)||L.every(z=>hn(z.placement)===b?z.overflows[0]>0:!0)))return{data:{index:_,overflows:L},reset:{placement:B}};let j=(O=L.filter(K=>K.overflows[0]<=0).sort((K,z)=>K.overflows[1]-z.overflows[1])[0])==null?void 0:O.placement;if(!j)switch(p){case"bestFit":{var F;const K=(F=L.filter(z=>{if(T){const M=hn(z.placement);return M===b||M==="y"}return!0}).map(z=>[z.placement,z.overflows.filter(M=>M>0).reduce((M,G)=>M+G,0)]).sort((z,M)=>z[1]-M[1])[0])==null?void 0:F[0];K&&(j=K);break}case"initialPlacement":j=a;break}if(o!==j)return{reset:{placement:j}}}return{}}}};function Ec(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function Ac(e){return Lx.some(t=>e[t]>=0)}const Jx=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n}=t,{strategy:r="referenceHidden",...o}=kn(e,t);switch(r){case"referenceHidden":{const s=await Lr(t,{...o,elementContext:"reference"}),i=Ec(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:Ac(i)}}}case"escaped":{const s=await Lr(t,{...o,altBoundary:!0}),i=Ec(s,n.floating);return{data:{escapedOffsets:i,escaped:Ac(i)}}}default:return{}}}}},Nc=new Set(["left","top"]);async function Zx(e,t){const{placement:n,platform:r,elements:o}=e,s=await(r.isRTL==null?void 0:r.isRTL(o.floating)),i=In(n),a=hr(n),l=hn(n)==="y",c=Nc.has(i)?-1:1,d=s&&l?-1:1,f=kn(t,e);let{mainAxis:h,crossAxis:p,alignmentAxis:m}=typeof f=="number"?{mainAxis:f,crossAxis:0,alignmentAxis:null}:{mainAxis:f.mainAxis||0,crossAxis:f.crossAxis||0,alignmentAxis:f.alignmentAxis};return a&&typeof m=="number"&&(p=a==="end"?m*-1:m),l?{x:p*d,y:h*c}:{x:h*c,y:p*d}}const Qx=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 Zx(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}}}}},ey=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:y=>{let{x,y:b}=y;return{x,y:b}}},...l}=kn(e,t),c={x:n,y:r},d=await Lr(t,l),f=hn(In(o)),h=Si(f);let p=c[h],m=c[f];if(s){const y=h==="y"?"top":"left",x=h==="y"?"bottom":"right",b=p+d[y],S=p-d[x];p=wi(b,p,S)}if(i){const y=f==="y"?"top":"left",x=f==="y"?"bottom":"right",b=m+d[y],S=m-d[x];m=wi(b,m,S)}const g=a.fn({...t,[h]:p,[f]:m});return{...g,data:{x:g.x-n,y:g.y-r,enabled:{[h]:s,[f]:i}}}}}},ty=function(e){return e===void 0&&(e={}),{options:e,fn(t){const{x:n,y:r,placement:o,rects:s,middlewareData:i}=t,{offset:a=0,mainAxis:l=!0,crossAxis:c=!0}=kn(e,t),d={x:n,y:r},f=hn(o),h=Si(f);let p=d[h],m=d[f];const g=kn(a,t),y=typeof g=="number"?{mainAxis:g,crossAxis:0}:{mainAxis:0,crossAxis:0,...g};if(l){const S=h==="y"?"height":"width",k=s.reference[h]-s.floating[S]+y.mainAxis,C=s.reference[h]+s.reference[S]-y.mainAxis;p<k?p=k:p>C&&(p=C)}if(c){var x,b;const S=h==="y"?"width":"height",k=Nc.has(In(o)),C=s.reference[f]-s.floating[S]+(k&&((x=i.offset)==null?void 0:x[f])||0)+(k?0:y.crossAxis),T=s.reference[f]+s.reference[S]+(k?0:((b=i.offset)==null?void 0:b[f])||0)-(k?y.crossAxis:0);m<C?m=C:m>T&&(m=T)}return{[h]:p,[f]:m}}}},ny=function(e){return e===void 0&&(e={}),{name:"size",options:e,async fn(t){var n,r;const{placement:o,rects:s,platform:i,elements:a}=t,{apply:l=()=>{},...c}=kn(e,t),d=await Lr(t,c),f=In(o),h=hr(o),p=hn(o)==="y",{width:m,height:g}=s.floating;let y,x;f==="top"||f==="bottom"?(y=f,x=h===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(x=f,y=h==="end"?"top":"bottom");const b=g-d.top-d.bottom,S=m-d.left-d.right,k=jn(g-d[y],b),C=jn(m-d[x],S),T=!t.middlewareData.shift;let I=k,A=C;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(A=S),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(I=b),T&&!h){const L=zt(d.left,0),R=zt(d.right,0),O=zt(d.top,0),F=zt(d.bottom,0);p?A=m-2*(L!==0||R!==0?L+R:zt(d.left,d.right)):I=g-2*(O!==0||F!==0?O+F:zt(d.top,d.bottom))}await l({...t,availableWidth:A,availableHeight:I});const N=await i.getDimensions(a.floating);return m!==N.width||g!==N.height?{reset:{rects:!0}}:{}}}};function Bo(){return typeof window<"u"}function mr(e){return _c(e)?(e.nodeName||"").toLowerCase():"#document"}function Ut(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function mn(e){var t;return(t=(_c(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function _c(e){return Bo()?e instanceof Node||e instanceof Ut(e).Node:!1}function on(e){return Bo()?e instanceof Element||e instanceof Ut(e).Element:!1}function gn(e){return Bo()?e instanceof HTMLElement||e instanceof Ut(e).HTMLElement:!1}function jc(e){return!Bo()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Ut(e).ShadowRoot}const ry=new Set(["inline","contents"]);function $r(e){const{overflow:t,overflowX:n,overflowY:r,display:o}=sn(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!ry.has(o)}const oy=new Set(["table","td","th"]);function sy(e){return oy.has(mr(e))}const iy=[":popover-open",":modal"];function zo(e){return iy.some(t=>{try{return e.matches(t)}catch{return!1}})}const ay=["transform","translate","scale","rotate","perspective"],ly=["transform","translate","scale","rotate","perspective","filter"],cy=["paint","layout","strict","content"];function Ii(e){const t=Ei(),n=on(e)?sn(e):e;return ay.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)||ly.some(r=>(n.willChange||"").includes(r))||cy.some(r=>(n.contain||"").includes(r))}function uy(e){let t=Mn(e);for(;gn(t)&&!gr(t);){if(Ii(t))return t;if(zo(t))return null;t=Mn(t)}return null}function Ei(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const dy=new Set(["html","body","#document"]);function gr(e){return dy.has(mr(e))}function sn(e){return Ut(e).getComputedStyle(e)}function Uo(e){return on(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Mn(e){if(mr(e)==="html")return e;const t=e.assignedSlot||e.parentNode||jc(e)&&e.host||mn(e);return jc(t)?t.host:t}function Mc(e){const t=Mn(e);return gr(t)?e.ownerDocument?e.ownerDocument.body:e.body:gn(t)&&$r(t)?t:Mc(t)}function Fr(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const o=Mc(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=Ut(o);if(s){const a=Ai(i);return t.concat(i,i.visualViewport||[],$r(o)?o:[],a&&n?Fr(a):[])}return t.concat(o,Fr(o,[],n))}function Ai(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function Rc(e){const t=sn(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const o=gn(e),s=o?e.offsetWidth:n,i=o?e.offsetHeight:r,a=Do(n)!==s||Do(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function Ni(e){return on(e)?e:e.contextElement}function xr(e){const t=Ni(e);if(!gn(t))return pn(1);const n=t.getBoundingClientRect(),{width:r,height:o,$:s}=Rc(t);let i=(s?Do(n.width):n.width)/r,a=(s?Do(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const fy=pn(0);function Pc(e){const t=Ut(e);return!Ei()||!t.visualViewport?fy:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function py(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==Ut(e)?!1:t}function Gn(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const o=e.getBoundingClientRect(),s=Ni(e);let i=pn(1);t&&(r?on(r)&&(i=xr(r)):i=xr(e));const a=py(s,n,r)?Pc(s):pn(0);let l=(o.left+a.x)/i.x,c=(o.top+a.y)/i.y,d=o.width/i.x,f=o.height/i.y;if(s){const h=Ut(s),p=r&&on(r)?Ut(r):r;let m=h,g=Ai(m);for(;g&&r&&p!==m;){const y=xr(g),x=g.getBoundingClientRect(),b=sn(g),S=x.left+(g.clientLeft+parseFloat(b.paddingLeft))*y.x,k=x.top+(g.clientTop+parseFloat(b.paddingTop))*y.y;l*=y.x,c*=y.y,d*=y.x,f*=y.y,l+=S,c+=k,m=Ut(g),g=Ai(m)}}return Fo({width:d,height:f,x:l,y:c})}function Ho(e,t){const n=Uo(e).scrollLeft;return t?t.left+n:Gn(mn(e)).left+n}function Oc(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-Ho(e,n),o=n.top+t.scrollTop;return{x:r,y:o}}function hy(e){let{elements:t,rect:n,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=mn(r),a=t?zo(t.floating):!1;if(r===i||a&&s)return n;let l={scrollLeft:0,scrollTop:0},c=pn(1);const d=pn(0),f=gn(r);if((f||!f&&!s)&&((mr(r)!=="body"||$r(i))&&(l=Uo(r)),gn(r))){const p=Gn(r);c=xr(r),d.x=p.x+r.clientLeft,d.y=p.y+r.clientTop}const h=i&&!f&&!s?Oc(i,l):pn(0);return{width:n.width*c.x,height:n.height*c.y,x:n.x*c.x-l.scrollLeft*c.x+d.x+h.x,y:n.y*c.y-l.scrollTop*c.y+d.y+h.y}}function my(e){return Array.from(e.getClientRects())}function gy(e){const t=mn(e),n=Uo(e),r=e.ownerDocument.body,o=zt(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=zt(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let i=-n.scrollLeft+Ho(e);const a=-n.scrollTop;return sn(r).direction==="rtl"&&(i+=zt(t.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}const Dc=25;function xy(e,t){const n=Ut(e),r=mn(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=Ei();(!d||d&&t==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}const c=Ho(r);if(c<=0){const d=r.ownerDocument,f=d.body,h=getComputedStyle(f),p=d.compatMode==="CSS1Compat"&&parseFloat(h.marginLeft)+parseFloat(h.marginRight)||0,m=Math.abs(r.clientWidth-f.clientWidth-p);m<=Dc&&(s-=m)}else c<=Dc&&(s+=c);return{width:s,height:i,x:a,y:l}}const yy=new Set(["absolute","fixed"]);function vy(e,t){const n=Gn(e,!0,t==="fixed"),r=n.top+e.clientTop,o=n.left+e.clientLeft,s=gn(e)?xr(e):pn(1),i=e.clientWidth*s.x,a=e.clientHeight*s.y,l=o*s.x,c=r*s.y;return{width:i,height:a,x:l,y:c}}function Lc(e,t,n){let r;if(t==="viewport")r=xy(e,n);else if(t==="document")r=gy(mn(e));else if(on(t))r=vy(t,n);else{const o=Pc(e);r={x:t.x-o.x,y:t.y-o.y,width:t.width,height:t.height}}return Fo(r)}function $c(e,t){const n=Mn(e);return n===t||!on(n)||gr(n)?!1:sn(n).position==="fixed"||$c(n,t)}function by(e,t){const n=t.get(e);if(n)return n;let r=Fr(e,[],!1).filter(a=>on(a)&&mr(a)!=="body"),o=null;const s=sn(e).position==="fixed";let i=s?Mn(e):e;for(;on(i)&&!gr(i);){const a=sn(i),l=Ii(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&yy.has(o.position)||$r(i)&&!l&&$c(e,i))?r=r.filter(d=>d!==i):o=a,i=Mn(i)}return t.set(e,r),r}function wy(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i=[...n==="clippingAncestors"?zo(t)?[]:by(t,this._c):[].concat(n),r],a=i[0],l=i.reduce((c,d)=>{const f=Lc(t,d,o);return c.top=zt(f.top,c.top),c.right=jn(f.right,c.right),c.bottom=jn(f.bottom,c.bottom),c.left=zt(f.left,c.left),c},Lc(t,a,o));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function Sy(e){const{width:t,height:n}=Rc(e);return{width:t,height:n}}function Cy(e,t,n){const r=gn(t),o=mn(t),s=n==="fixed",i=Gn(e,!0,s,t);let a={scrollLeft:0,scrollTop:0};const l=pn(0);function c(){l.x=Ho(o)}if(r||!r&&!s)if((mr(t)!=="body"||$r(o))&&(a=Uo(t)),r){const p=Gn(t,!0,s,t);l.x=p.x+t.clientLeft,l.y=p.y+t.clientTop}else o&&c();s&&!r&&o&&c();const d=o&&!r&&!s?Oc(o,a):pn(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 _i(e){return sn(e).position==="static"}function Fc(e,t){if(!gn(e)||sn(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return mn(e)===n&&(n=n.ownerDocument.body),n}function Bc(e,t){const n=Ut(e);if(zo(e))return n;if(!gn(e)){let o=Mn(e);for(;o&&!gr(o);){if(on(o)&&!_i(o))return o;o=Mn(o)}return n}let r=Fc(e,t);for(;r&&sy(r)&&_i(r);)r=Fc(r,t);return r&&gr(r)&&_i(r)&&!Ii(r)?n:r||uy(e)||n}const Ty=async function(e){const t=this.getOffsetParent||Bc,n=this.getDimensions,r=await n(e.floating);return{reference:Cy(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function ky(e){return sn(e).direction==="rtl"}const Iy={convertOffsetParentRelativeRectToViewportRelativeRect:hy,getDocumentElement:mn,getClippingRect:wy,getOffsetParent:Bc,getElementRects:Ty,getClientRects:my,getDimensions:Sy,getScale:xr,isElement:on,isRTL:ky};function zc(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function Ey(e,t){let n=null,r;const o=mn(e);function s(){var a;clearTimeout(r),(a=n)==null||a.disconnect(),n=null}function i(a,l){a===void 0&&(a=!1),l===void 0&&(l=1),s();const c=e.getBoundingClientRect(),{left:d,top:f,width:h,height:p}=c;if(a||t(),!h||!p)return;const m=Lo(f),g=Lo(o.clientWidth-(d+h)),y=Lo(o.clientHeight-(f+p)),x=Lo(d),S={rootMargin:-m+"px "+-g+"px "+-y+"px "+-x+"px",threshold:zt(0,jn(1,l))||1};let k=!0;function C(T){const I=T[0].intersectionRatio;if(I!==l){if(!k)return i();I?i(!1,I):r=setTimeout(()=>{i(!1,1e-7)},1e3)}I===1&&!zc(c,e.getBoundingClientRect())&&i(),k=!1}try{n=new IntersectionObserver(C,{...S,root:o.ownerDocument})}catch{n=new IntersectionObserver(C,S)}n.observe(e)}return i(!0),s}function Ay(e,t,n,r){r===void 0&&(r={});const{ancestorScroll:o=!0,ancestorResize:s=!0,elementResize:i=typeof ResizeObserver=="function",layoutShift:a=typeof IntersectionObserver=="function",animationFrame:l=!1}=r,c=Ni(e),d=o||s?[...c?Fr(c):[],...Fr(t)]:[];d.forEach(x=>{o&&x.addEventListener("scroll",n,{passive:!0}),s&&x.addEventListener("resize",n)});const f=c&&a?Ey(c,n):null;let h=-1,p=null;i&&(p=new ResizeObserver(x=>{let[b]=x;b&&b.target===c&&p&&(p.unobserve(t),cancelAnimationFrame(h),h=requestAnimationFrame(()=>{var S;(S=p)==null||S.observe(t)})),n()}),c&&!l&&p.observe(c),p.observe(t));let m,g=l?Gn(e):null;l&&y();function y(){const x=Gn(e);g&&!zc(g,x)&&n(),g=x,m=requestAnimationFrame(y)}return n(),()=>{var x;d.forEach(b=>{o&&b.removeEventListener("scroll",n),s&&b.removeEventListener("resize",n)}),f==null||f(),(x=p)==null||x.disconnect(),p=null,l&&cancelAnimationFrame(m)}}const Ny=Qx,_y=ey,jy=Xx,My=ny,Ry=Jx,Uc=Yx,Py=ty,Oy=(e,t,n)=>{const r=new Map,o={platform:Iy,...n},s={...o.platform,_c:r};return Gx(e,t,{...o,platform:s})};var Dy=typeof document<"u",Ly=function(){},Wo=Dy?w.useLayoutEffect:Ly;function Vo(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(!Vo(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)&&!Vo(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function Hc(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function Wc(e,t){const n=Hc(e);return Math.round(t*n)/n}function ji(e){const t=v.useRef(e);return Wo(()=>{t.current=e}),t}function $y(e){e===void 0&&(e={});const{placement:t="bottom",strategy:n="absolute",middleware:r=[],platform:o,elements:{reference:s,floating:i}={},transform:a=!0,whileElementsMounted:l,open:c}=e,[d,f]=v.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[h,p]=v.useState(r);Vo(h,r)||p(r);const[m,g]=v.useState(null),[y,x]=v.useState(null),b=v.useCallback(z=>{z!==T.current&&(T.current=z,g(z))},[]),S=v.useCallback(z=>{z!==I.current&&(I.current=z,x(z))},[]),k=s||m,C=i||y,T=v.useRef(null),I=v.useRef(null),A=v.useRef(d),N=l!=null,L=ji(l),R=ji(o),O=ji(c),F=v.useCallback(()=>{if(!T.current||!I.current)return;const z={placement:t,strategy:n,middleware:h};R.current&&(z.platform=R.current),Oy(T.current,I.current,z).then(M=>{const G={...M,isPositioned:O.current!==!1};_.current&&!Vo(A.current,G)&&(A.current=G,ho.flushSync(()=>{f(G)}))})},[h,t,n,R,O]);Wo(()=>{c===!1&&A.current.isPositioned&&(A.current.isPositioned=!1,f(z=>({...z,isPositioned:!1})))},[c]);const _=v.useRef(!1);Wo(()=>(_.current=!0,()=>{_.current=!1}),[]),Wo(()=>{if(k&&(T.current=k),C&&(I.current=C),k&&C){if(L.current)return L.current(k,C,F);F()}},[k,C,F,L,N]);const B=v.useMemo(()=>({reference:T,floating:I,setReference:b,setFloating:S}),[b,S]),j=v.useMemo(()=>({reference:k,floating:C}),[k,C]),K=v.useMemo(()=>{const z={position:n,left:0,top:0};if(!j.floating)return z;const M=Wc(j.floating,d.x),G=Wc(j.floating,d.y);return a?{...z,transform:"translate("+M+"px, "+G+"px)",...Hc(j.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:M,top:G}},[n,a,j.floating,d.x,d.y]);return v.useMemo(()=>({...d,update:F,refs:B,elements:j,floatingStyles:K}),[d,F,B,j,K])}const Fy=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?Uc({element:r.current,padding:o}).fn(n):{}:r?Uc({element:r,padding:o}).fn(n):{}}}},By=(e,t)=>({...Ny(e),options:[e,t]}),zy=(e,t)=>({..._y(e),options:[e,t]}),Uy=(e,t)=>({...Py(e),options:[e,t]}),Hy=(e,t)=>({...jy(e),options:[e,t]}),Wy=(e,t)=>({...My(e),options:[e,t]}),Vy=(e,t)=>({...Ry(e),options:[e,t]}),Ky=(e,t)=>({...Fy(e),options:[e,t]});var qy="Arrow",Vc=v.forwardRef((e,t)=>{const{children:n,width:r=10,height:o=5,...s}=e;return u.jsx(Ne.svg,{...s,ref:t,width:r,height:o,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:e.asChild?n:u.jsx("polygon",{points:"0,0 30,0 15,10"})})});Vc.displayName=qy;var Gy=Vc;function Kc(e){const[t,n]=v.useState(void 0);return Tt(()=>{if(e){n({width:e.offsetWidth,height:e.offsetHeight});const r=new ResizeObserver(o=>{if(!Array.isArray(o)||!o.length)return;const s=o[0];let i,a;if("borderBoxSize"in s){const l=s.borderBoxSize,c=Array.isArray(l)?l[0]:l;i=c.inlineSize,a=c.blockSize}else i=e.offsetWidth,a=e.offsetHeight;n({width:i,height:a})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else n(void 0)},[e]),t}var Mi="Popper",[qc,Ko]=Cn(Mi),[Yy,Gc]=qc(Mi),Yc=e=>{const{__scopePopper:t,children:n}=e,[r,o]=v.useState(null);return u.jsx(Yy,{scope:t,anchor:r,onAnchorChange:o,children:n})};Yc.displayName=Mi;var Xc="PopperAnchor",Jc=v.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...o}=e,s=Gc(Xc,n),i=v.useRef(null),a=Be(t,i),l=v.useRef(null);return v.useEffect(()=>{const c=l.current;l.current=(r==null?void 0:r.current)||i.current,c!==l.current&&s.onAnchorChange(l.current)}),r?null:u.jsx(Ne.div,{...o,ref:a})});Jc.displayName=Xc;var Ri="PopperContent",[Xy,Jy]=qc(Ri),Zc=v.forwardRef((e,t)=>{var J,$,q,Z,ue,ie;const{__scopePopper:n,side:r="bottom",sideOffset:o=0,align:s="center",alignOffset:i=0,arrowPadding:a=0,avoidCollisions:l=!0,collisionBoundary:c=[],collisionPadding:d=0,sticky:f="partial",hideWhenDetached:h=!1,updatePositionStrategy:p="optimized",onPlaced:m,...g}=e,y=Gc(Ri,n),[x,b]=v.useState(null),S=Be(t,_e=>b(_e)),[k,C]=v.useState(null),T=Kc(k),I=(T==null?void 0:T.width)??0,A=(T==null?void 0:T.height)??0,N=r+(s!=="center"?"-"+s:""),L=typeof d=="number"?d:{top:0,right:0,bottom:0,left:0,...d},R=Array.isArray(c)?c:[c],O=R.length>0,F={padding:L,boundary:R.filter(Qy),altBoundary:O},{refs:_,floatingStyles:B,placement:j,isPositioned:K,middlewareData:z}=$y({strategy:"fixed",placement:N,whileElementsMounted:(..._e)=>Ay(..._e,{animationFrame:p==="always"}),elements:{reference:y.anchor},middleware:[By({mainAxis:o+A,alignmentAxis:i}),l&&zy({mainAxis:!0,crossAxis:!1,limiter:f==="partial"?Uy():void 0,...F}),l&&Hy({...F}),Wy({...F,apply:({elements:_e,rects:He,availableWidth:oe,availableHeight:ye})=>{const{width:Oe,height:Ye}=He.reference,nt=_e.floating.style;nt.setProperty("--radix-popper-available-width",`${oe}px`),nt.setProperty("--radix-popper-available-height",`${ye}px`),nt.setProperty("--radix-popper-anchor-width",`${Oe}px`),nt.setProperty("--radix-popper-anchor-height",`${Ye}px`)}}),k&&Ky({element:k,padding:a}),ev({arrowWidth:I,arrowHeight:A}),h&&Vy({strategy:"referenceHidden",...F})]}),[M,G]=tu(j),X=kt(m);Tt(()=>{K&&(X==null||X())},[K,X]);const se=(J=z.arrow)==null?void 0:J.x,be=($=z.arrow)==null?void 0:$.y,Ie=((q=z.arrow)==null?void 0:q.centerOffset)!==0,[Y,U]=v.useState();return Tt(()=>{x&&U(window.getComputedStyle(x).zIndex)},[x]),u.jsx("div",{ref:_.setFloating,"data-radix-popper-content-wrapper":"",style:{...B,transform:K?B.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:Y,"--radix-popper-transform-origin":[(Z=z.transformOrigin)==null?void 0:Z.x,(ue=z.transformOrigin)==null?void 0:ue.y].join(" "),...((ie=z.hide)==null?void 0:ie.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:u.jsx(Xy,{scope:n,placedSide:M,onArrowChange:C,arrowX:se,arrowY:be,shouldHideArrow:Ie,children:u.jsx(Ne.div,{"data-side":M,"data-align":G,...g,ref:S,style:{...g.style,animation:K?void 0:"none"}})})})});Zc.displayName=Ri;var Qc="PopperArrow",Zy={top:"bottom",right:"left",bottom:"top",left:"right"},eu=v.forwardRef(function(t,n){const{__scopePopper:r,...o}=t,s=Jy(Qc,r),i=Zy[s.placedSide];return u.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:u.jsx(Gy,{...o,ref:n,style:{...o.style,display:"block"}})})});eu.displayName=Qc;function Qy(e){return e!==null}var ev=e=>({name:"transformOrigin",options:e,fn(t){var y,x,b;const{placement:n,rects:r,middlewareData:o}=t,i=((y=o.arrow)==null?void 0:y.centerOffset)!==0,a=i?0:e.arrowWidth,l=i?0:e.arrowHeight,[c,d]=tu(n),f={start:"0%",center:"50%",end:"100%"}[d],h=(((x=o.arrow)==null?void 0:x.x)??0)+a/2,p=(((b=o.arrow)==null?void 0:b.y)??0)+l/2;let m="",g="";return c==="bottom"?(m=i?f:`${h}px`,g=`${-l}px`):c==="top"?(m=i?f:`${h}px`,g=`${r.floating.height+l}px`):c==="right"?(m=`${-l}px`,g=i?f:`${p}px`):c==="left"&&(m=`${r.floating.width+l}px`,g=i?f:`${p}px`),{data:{x:m,y:g}}}});function tu(e){const[t,n="center"]=e.split("-");return[t,n]}var nu=Yc,ru=Jc,ou=Zc,su=eu,tv="Portal",qo=v.forwardRef((e,t)=>{var a;const{container:n,...r}=e,[o,s]=v.useState(!1);Tt(()=>s(!0),[]);const i=n||o&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?Gs.createPortal(u.jsx(Ne.div,{...r,ref:t}),i):null});qo.displayName=tv;function nv(e,t){return v.useReducer((n,r)=>t[n][r]??n,e)}var Xt=e=>{const{present:t,children:n}=e,r=rv(t),o=typeof n=="function"?n({present:r.isPresent}):v.Children.only(n),s=Be(r.ref,ov(o));return typeof n=="function"||r.isPresent?v.cloneElement(o,{ref:s}):null};Xt.displayName="Presence";function rv(e){const[t,n]=v.useState(),r=v.useRef(null),o=v.useRef(e),s=v.useRef("none"),i=e?"mounted":"unmounted",[a,l]=nv(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return v.useEffect(()=>{const c=Go(r.current);s.current=a==="mounted"?c:"none"},[a]),Tt(()=>{const c=r.current,d=o.current;if(d!==e){const h=s.current,p=Go(c);e?l("MOUNT"):p==="none"||(c==null?void 0:c.display)==="none"?l("UNMOUNT"):l(d&&h!==p?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,l]),Tt(()=>{if(t){let c;const d=t.ownerDocument.defaultView??window,f=p=>{const g=Go(r.current).includes(CSS.escape(p.animationName));if(p.target===t&&g&&(l("ANIMATION_END"),!o.current)){const y=t.style.animationFillMode;t.style.animationFillMode="forwards",c=d.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=y)})}},h=p=>{p.target===t&&(s.current=Go(r.current))};return t.addEventListener("animationstart",h),t.addEventListener("animationcancel",f),t.addEventListener("animationend",f),()=>{d.clearTimeout(c),t.removeEventListener("animationstart",h),t.removeEventListener("animationcancel",f),t.removeEventListener("animationend",f)}}else l("ANIMATION_END")},[t,l]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:v.useCallback(c=>{r.current=c?getComputedStyle(c):null,n(c)},[])}}function Go(e){return(e==null?void 0:e.animationName)||"none"}function ov(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 Pi="rovingFocusGroup.onEntryFocus",sv={bubbles:!1,cancelable:!0},Br="RovingFocusGroup",[Oi,iu,iv]=mi(Br),[av,au]=Cn(Br,[iv]),[lv,cv]=av(Br),lu=v.forwardRef((e,t)=>u.jsx(Oi.Provider,{scope:e.__scopeRovingFocusGroup,children:u.jsx(Oi.Slot,{scope:e.__scopeRovingFocusGroup,children:u.jsx(uv,{...e,ref:t})})}));lu.displayName=Br;var uv=v.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:o=!1,dir:s,currentTabStopId:i,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:l,onEntryFocus:c,preventScrollOnEntryFocus:d=!1,...f}=e,h=v.useRef(null),p=Be(t,h),m=Ro(s),[g,y]=pr({prop:i,defaultProp:a??null,onChange:l,caller:Br}),[x,b]=v.useState(!1),S=kt(c),k=iu(n),C=v.useRef(!1),[T,I]=v.useState(0);return v.useEffect(()=>{const A=h.current;if(A)return A.addEventListener(Pi,S),()=>A.removeEventListener(Pi,S)},[S]),u.jsx(lv,{scope:n,orientation:r,dir:m,loop:o,currentTabStopId:g,onItemFocus:v.useCallback(A=>y(A),[y]),onItemShiftTab:v.useCallback(()=>b(!0),[]),onFocusableItemAdd:v.useCallback(()=>I(A=>A+1),[]),onFocusableItemRemove:v.useCallback(()=>I(A=>A-1),[]),children:u.jsx(Ne.div,{tabIndex:x||T===0?-1:0,"data-orientation":r,...f,ref:p,style:{outline:"none",...e.style},onMouseDown:fe(e.onMouseDown,()=>{C.current=!0}),onFocus:fe(e.onFocus,A=>{const N=!C.current;if(A.target===A.currentTarget&&N&&!x){const L=new CustomEvent(Pi,sv);if(A.currentTarget.dispatchEvent(L),!L.defaultPrevented){const R=k().filter(j=>j.focusable),O=R.find(j=>j.active),F=R.find(j=>j.id===g),B=[O,F,...R].filter(Boolean).map(j=>j.ref.current);du(B,d)}}C.current=!1}),onBlur:fe(e.onBlur,()=>b(!1))})})}),cu="RovingFocusGroupItem",uu=v.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:o=!1,tabStopId:s,children:i,...a}=e,l=Tn(),c=s||l,d=cv(cu,n),f=d.currentTabStopId===c,h=iu(n),{onFocusableItemAdd:p,onFocusableItemRemove:m,currentTabStopId:g}=d;return v.useEffect(()=>{if(r)return p(),()=>m()},[r,p,m]),u.jsx(Oi.ItemSlot,{scope:n,id:c,focusable:r,active:o,children:u.jsx(Ne.span,{tabIndex:f?0:-1,"data-orientation":d.orientation,...a,ref:t,onMouseDown:fe(e.onMouseDown,y=>{r?d.onItemFocus(c):y.preventDefault()}),onFocus:fe(e.onFocus,()=>d.onItemFocus(c)),onKeyDown:fe(e.onKeyDown,y=>{if(y.key==="Tab"&&y.shiftKey){d.onItemShiftTab();return}if(y.target!==y.currentTarget)return;const x=pv(y,d.orientation,d.dir);if(x!==void 0){if(y.metaKey||y.ctrlKey||y.altKey||y.shiftKey)return;y.preventDefault();let S=h().filter(k=>k.focusable).map(k=>k.ref.current);if(x==="last")S.reverse();else if(x==="prev"||x==="next"){x==="prev"&&S.reverse();const k=S.indexOf(y.currentTarget);S=d.loop?hv(S,k+1):S.slice(k+1)}setTimeout(()=>du(S))}}),children:typeof i=="function"?i({isCurrentTabStop:f,hasTabStop:g!=null}):i})})});uu.displayName=cu;var dv={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function fv(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function pv(e,t,n){const r=fv(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return dv[r]}function du(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function hv(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var mv=lu,gv=uu,xv=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},yr=new WeakMap,Yo=new WeakMap,Xo={},Di=0,fu=function(e){return e&&(e.host||fu(e.parentNode))},yv=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=fu(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})},vv=function(e,t,n,r){var o=yv(t,Array.isArray(e)?e:[e]);Xo[n]||(Xo[n]=new WeakMap);var s=Xo[n],i=[],a=new Set,l=new Set(o),c=function(f){!f||a.has(f)||(a.add(f),c(f.parentNode))};o.forEach(c);var 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),m=p!==null&&p!=="false",g=(yr.get(h)||0)+1,y=(s.get(h)||0)+1;yr.set(h,g),s.set(h,y),i.push(h),g===1&&m&&Yo.set(h,!0),y===1&&h.setAttribute(n,"true"),m||h.setAttribute(r,"true")}catch(x){console.error("aria-hidden: cannot operate on ",h,x)}})};return d(t),a.clear(),Di++,function(){i.forEach(function(f){var h=yr.get(f)-1,p=s.get(f)-1;yr.set(f,h),s.set(f,p),h||(Yo.has(f)||f.removeAttribute(r),Yo.delete(f)),p||f.removeAttribute(n)}),Di--,Di||(yr=new WeakMap,yr=new WeakMap,Yo=new WeakMap,Xo={})}},Li=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),o=xv(e);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live], script"))),vv(r,o,n,"aria-hidden")):function(){return null}},xn=function(){return xn=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},xn.apply(this,arguments)};function pu(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 bv(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 Jo="right-scroll-bar-position",Zo="width-before-scroll-bar",wv="with-scroll-bars-hidden",Sv="--removed-body-scroll-bar-size";function $i(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function Cv(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 Tv=typeof window<"u"?v.useLayoutEffect:v.useEffect,hu=new WeakMap;function kv(e,t){var n=Cv(null,function(r){return e.forEach(function(o){return $i(o,r)})});return Tv(function(){var r=hu.get(n);if(r){var o=new Set(r),s=new Set(e),i=n.current;o.forEach(function(a){s.has(a)||$i(a,null)}),s.forEach(function(a){o.has(a)||$i(a,i)})}hu.set(n,e)},[e]),n}function Iv(e){return e}function Ev(e,t){t===void 0&&(t=Iv);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)},c=function(){return Promise.resolve().then(l)};c(),n={push:function(d){i.push(d),c()},filter:function(d){return i=i.filter(d),n}}}};return o}function Av(e){e===void 0&&(e={});var t=Ev(null);return t.options=xn({async:!0,ssr:!1},e),t}var mu=function(e){var t=e.sideCar,n=pu(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 v.createElement(r,xn({},n))};mu.isSideCarExport=!0;function Nv(e,t){return e.useMedium(t),mu}var gu=Av(),Fi=function(){},Qo=v.forwardRef(function(e,t){var n=v.useRef(null),r=v.useState({onScrollCapture:Fi,onWheelCapture:Fi,onTouchMoveCapture:Fi}),o=r[0],s=r[1],i=e.forwardProps,a=e.children,l=e.className,c=e.removeScrollBar,d=e.enabled,f=e.shards,h=e.sideCar,p=e.noRelative,m=e.noIsolation,g=e.inert,y=e.allowPinchZoom,x=e.as,b=x===void 0?"div":x,S=e.gapMode,k=pu(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),C=h,T=kv([n,t]),I=xn(xn({},k),o);return v.createElement(v.Fragment,null,d&&v.createElement(C,{sideCar:gu,removeScrollBar:c,shards:f,noRelative:p,noIsolation:m,inert:g,setCallbacks:s,allowPinchZoom:!!y,lockRef:n,gapMode:S}),i?v.cloneElement(v.Children.only(a),xn(xn({},I),{ref:T})):v.createElement(b,xn({},I,{className:l,ref:T}),a))});Qo.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},Qo.classNames={fullWidth:Zo,zeroRight:Jo};var _v=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function jv(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=_v();return t&&e.setAttribute("nonce",t),e}function Mv(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function Rv(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var Pv=function(){var e=0,t=null;return{add:function(n){e==0&&(t=jv())&&(Mv(t,n),Rv(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},Ov=function(){var e=Pv();return function(t,n){v.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},xu=function(){var e=Ov(),t=function(n){var r=n.styles,o=n.dynamic;return e(r,o),null};return t},Dv={left:0,top:0,right:0,gap:0},Bi=function(e){return parseInt(e||"",10)||0},Lv=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[Bi(n),Bi(r),Bi(o)]},$v=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return Dv;var t=Lv(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])}},Fv=xu(),vr="data-scroll-locked",Bv=function(e,t,n,r){var o=e.left,s=e.top,i=e.right,a=e.gap;return n===void 0&&(n="margin"),`
|
|
39
|
+
.`.concat(wv,` {
|
|
40
40
|
overflow: hidden `).concat(r,`;
|
|
41
41
|
padding-right: `).concat(a,"px ").concat(r,`;
|
|
42
42
|
}
|
|
43
|
-
body[`).concat(
|
|
43
|
+
body[`).concat(vr,`] {
|
|
44
44
|
overflow: hidden `).concat(r,`;
|
|
45
45
|
overscroll-behavior: contain;
|
|
46
46
|
`).concat([t&&"position: relative ".concat(r,";"),n==="margin"&&`
|
|
@@ -53,29 +53,29 @@ React keys must be passed directly to JSX without using spread:
|
|
|
53
53
|
`),n==="padding"&&"padding-right: ".concat(a,"px ").concat(r,";")].filter(Boolean).join(""),`
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
.`).concat(
|
|
56
|
+
.`).concat(Jo,` {
|
|
57
57
|
right: `).concat(a,"px ").concat(r,`;
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
.`).concat(
|
|
60
|
+
.`).concat(Zo,` {
|
|
61
61
|
margin-right: `).concat(a,"px ").concat(r,`;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
.`).concat(
|
|
64
|
+
.`).concat(Jo," .").concat(Jo,` {
|
|
65
65
|
right: 0 `).concat(r,`;
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
.`).concat(
|
|
68
|
+
.`).concat(Zo," .").concat(Zo,` {
|
|
69
69
|
margin-right: 0 `).concat(r,`;
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
body[`).concat(
|
|
73
|
-
`).concat(
|
|
72
|
+
body[`).concat(vr,`] {
|
|
73
|
+
`).concat(Sv,": ").concat(a,`px;
|
|
74
74
|
}
|
|
75
|
-
`)},
|
|
75
|
+
`)},yu=function(){var e=parseInt(document.body.getAttribute(vr)||"0",10);return isFinite(e)?e:0},zv=function(){v.useEffect(function(){return document.body.setAttribute(vr,(yu()+1).toString()),function(){var e=yu()-1;e<=0?document.body.removeAttribute(vr):document.body.setAttribute(vr,e.toString())}},[])},Uv=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,o=r===void 0?"margin":r;zv();var s=v.useMemo(function(){return $v(o)},[o]);return v.createElement(Fv,{styles:Bv(s,!t,o,n?"":"!important")})},zi=!1;if(typeof window<"u")try{var es=Object.defineProperty({},"passive",{get:function(){return zi=!0,!0}});window.addEventListener("test",es,es),window.removeEventListener("test",es,es)}catch{zi=!1}var br=zi?{passive:!1}:!1,Hv=function(e){return e.tagName==="TEXTAREA"},vu=function(e,t){if(!(e instanceof Element))return!1;var n=window.getComputedStyle(e);return n[t]!=="hidden"&&!(n.overflowY===n.overflowX&&!Hv(e)&&n[t]==="visible")},Wv=function(e){return vu(e,"overflowY")},Vv=function(e){return vu(e,"overflowX")},bu=function(e,t){var n=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var o=wu(e,r);if(o){var s=Su(e,r),i=s[1],a=s[2];if(i>a)return!0}r=r.parentNode}while(r&&r!==n.body);return!1},Kv=function(e){var t=e.scrollTop,n=e.scrollHeight,r=e.clientHeight;return[t,n,r]},qv=function(e){var t=e.scrollLeft,n=e.scrollWidth,r=e.clientWidth;return[t,n,r]},wu=function(e,t){return e==="v"?Wv(t):Vv(t)},Su=function(e,t){return e==="v"?Kv(t):qv(t)},Gv=function(e,t){return e==="h"&&t==="rtl"?-1:1},Yv=function(e,t,n,r,o){var s=Gv(e,window.getComputedStyle(t).direction),i=s*r,a=n.target,l=t.contains(a),c=!1,d=i>0,f=0,h=0;do{if(!a)break;var p=Su(e,a),m=p[0],g=p[1],y=p[2],x=g-y-s*m;(m||x)&&wu(e,a)&&(f+=x,h+=m);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)&&(c=!0),c},ts=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},Cu=function(e){return[e.deltaX,e.deltaY]},Tu=function(e){return e&&"current"in e?e.current:e},Xv=function(e,t){return e[0]===t[0]&&e[1]===t[1]},Jv=function(e){return`
|
|
76
76
|
.block-interactivity-`.concat(e,` {pointer-events: none;}
|
|
77
77
|
.allow-interactivity-`).concat(e,` {pointer-events: all;}
|
|
78
|
-
`)},Hv=0,br=[];function Wv(e){var t=v.useRef([]),n=v.useRef([0,0]),r=v.useRef(),o=v.useState(Hv++)[0],s=v.useState(gu)[0],i=v.useRef(e);v.useEffect(function(){i.current=e},[e]),v.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(o));var g=dv([e.lockRef.current],(e.shards||[]).map(Cu),!0).filter(Boolean);return g.forEach(function(y){return y.classList.add("allow-interactivity-".concat(o))}),function(){document.body.classList.remove("block-interactivity-".concat(o)),g.forEach(function(y){return y.classList.remove("allow-interactivity-".concat(o))})}}},[e.inert,e.lockRef.current,e.shards]);var a=v.useCallback(function(g,y){if("touches"in g&&g.touches.length===2||g.type==="wheel"&&g.ctrlKey)return!i.current.allowPinchZoom;var x=es(g),b=n.current,C="deltaX"in g?g.deltaX:b[0]-x[0],k="deltaY"in g?g.deltaY:b[1]-x[1],S,T=g.target,I=Math.abs(C)>Math.abs(k)?"h":"v";if("touches"in g&&I==="h"&&T.type==="range")return!1;var A=vu(I,T);if(!A)return!0;if(A?S=I:(S=I==="v"?"h":"v",A=vu(I,T)),!A)return!1;if(!r.current&&"changedTouches"in g&&(C||k)&&(r.current=S),!S)return!0;var _=r.current||S;return Bv(_,y,g,_==="h"?C:k)},[]),l=v.useCallback(function(g){var y=g;if(!(!br.length||br[br.length-1]!==s)){var x="deltaY"in y?Su(y):es(y),b=t.current.filter(function(S){return S.name===y.type&&(S.target===y.target||y.target===S.shadowParent)&&zv(S.delta,x)})[0];if(b&&b.should){y.cancelable&&y.preventDefault();return}if(!b){var C=(i.current.shards||[]).map(Cu).filter(Boolean).filter(function(S){return S.contains(y.target)}),k=C.length>0?a(y,C[0]):!i.current.noIsolation;k&&y.cancelable&&y.preventDefault()}}},[]),c=v.useCallback(function(g,y,x,b){var C={name:g,delta:y,target:x,should:b,shadowParent:Vv(x)};t.current.push(C),setTimeout(function(){t.current=t.current.filter(function(k){return k!==C})},1)},[]),d=v.useCallback(function(g){n.current=es(g),r.current=void 0},[]),f=v.useCallback(function(g){c(g.type,Su(g),g.target,a(g,e.lockRef.current))},[]),p=v.useCallback(function(g){c(g.type,es(g),g.target,a(g,e.lockRef.current))},[]);v.useEffect(function(){return br.push(s),e.setCallbacks({onScrollCapture:f,onWheelCapture:f,onTouchMoveCapture:p}),document.addEventListener("wheel",l,vr),document.addEventListener("touchmove",l,vr),document.addEventListener("touchstart",d,vr),function(){br=br.filter(function(g){return g!==s}),document.removeEventListener("wheel",l,vr),document.removeEventListener("touchmove",l,vr),document.removeEventListener("touchstart",d,vr)}},[]);var h=e.removeScrollBar,m=e.inert;return v.createElement(v.Fragment,null,m?v.createElement(s,{styles:Uv(o)}):null,h?v.createElement(Rv,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function Vv(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const Kv=bv(mu,Wv);var ts=v.forwardRef(function(e,t){return v.createElement(Zo,gn({},e,{ref:t,sideCar:Kv}))});ts.classNames=Zo.classNames;var Hi=["Enter"," "],qv=["ArrowDown","PageUp","Home"],Tu=["ArrowUp","PageDown","End"],Gv=[...qv,...Tu],Yv={ltr:[...Hi,"ArrowRight"],rtl:[...Hi,"ArrowLeft"]},Xv={ltr:["ArrowLeft"],rtl:["ArrowRight"]},zr="Menu",[Ur,Jv,Zv]=gi(zr),[Gn,ku]=Sn(zr,[Zv,Vo,iu]),ns=Vo(),Iu=iu(),[Qv,Yn]=Gn(zr),[eb,Hr]=Gn(zr),Eu=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=ns(t),[l,c]=v.useState(null),d=v.useRef(!1),f=Tt(s),p=Mo(o);return v.useEffect(()=>{const h=()=>{d.current=!0,document.addEventListener("pointerdown",m,{capture:!0,once:!0}),document.addEventListener("pointermove",m,{capture:!0,once:!0})},m=()=>d.current=!1;return document.addEventListener("keydown",h,{capture:!0}),()=>{document.removeEventListener("keydown",h,{capture:!0}),document.removeEventListener("pointerdown",m,{capture:!0}),document.removeEventListener("pointermove",m,{capture:!0})}},[]),u.jsx(tu,{...a,children:u.jsx(Qv,{scope:t,open:n,onOpenChange:f,content:l,onContentChange:c,children:u.jsx(eb,{scope:t,onClose:v.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:d,dir:p,modal:i,children:r})})})};Eu.displayName=zr;var tb="MenuAnchor",Wi=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=ns(n);return u.jsx(nu,{...o,...r,ref:t})});Wi.displayName=tb;var Vi="MenuPortal",[nb,Au]=Gn(Vi,{forceMount:void 0}),Nu=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:o}=e,s=Yn(Vi,t);return u.jsx(nb,{scope:t,forceMount:n,children:u.jsx(Yt,{present:n||s.open,children:u.jsx(Ko,{asChild:!0,container:o,children:r})})})};Nu.displayName=Vi;var Xt="MenuContent",[rb,Ki]=Gn(Xt),_u=v.forwardRef((e,t)=>{const n=Au(Xt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Yn(Xt,e.__scopeMenu),i=Hr(Xt,e.__scopeMenu);return u.jsx(Ur.Provider,{scope:e.__scopeMenu,children:u.jsx(Yt,{present:r||s.open,children:u.jsx(Ur.Slot,{scope:e.__scopeMenu,children:i.modal?u.jsx(ob,{...o,ref:t}):u.jsx(sb,{...o,ref:t})})})})}),ob=v.forwardRef((e,t)=>{const n=Yn(Xt,e.__scopeMenu),r=v.useRef(null),o=Be(t,r);return v.useEffect(()=>{const s=r.current;if(s)return $i(s)},[]),u.jsx(qi,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:fe(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),sb=v.forwardRef((e,t)=>{const n=Yn(Xt,e.__scopeMenu);return u.jsx(qi,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),ib=Hn.createSlot("MenuContent.ScrollLock"),qi=v.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:o,onOpenAutoFocus:s,onCloseAutoFocus:i,disableOutsidePointerEvents:a,onEntryFocus:l,onEscapeKeyDown:c,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:p,onDismiss:h,disableOutsideScroll:m,...g}=e,y=Yn(Xt,n),x=Hr(Xt,n),b=ns(n),C=Iu(n),k=Jv(n),[S,T]=v.useState(null),I=v.useRef(null),A=Be(t,I,y.onContentChange),_=v.useRef(0),L=v.useRef(""),R=v.useRef(0),O=v.useRef(null),F=v.useRef("right"),N=v.useRef(0),B=m?ts:v.Fragment,j=m?{as:ib,allowPinchZoom:!0}:void 0,K=M=>{var J,$;const G=L.current+M,X=k().filter(q=>!q.disabled),se=document.activeElement,be=(J=X.find(q=>q.ref.current===se))==null?void 0:J.textValue,Ie=X.map(q=>q.textValue),Y=yb(Ie,G,be),U=($=X.find(q=>q.textValue===Y))==null?void 0:$.ref.current;(function q(Z){L.current=Z,window.clearTimeout(_.current),Z!==""&&(_.current=window.setTimeout(()=>q(""),1e3))})(G),U&&setTimeout(()=>U.focus())};v.useEffect(()=>()=>window.clearTimeout(_.current),[]),vi();const z=v.useCallback(M=>{var X,se;return F.current===((X=O.current)==null?void 0:X.side)&&bb(M,(se=O.current)==null?void 0:se.area)},[]);return u.jsx(rb,{scope:n,searchRef:L,onItemEnter:v.useCallback(M=>{z(M)&&M.preventDefault()},[z]),onItemLeave:v.useCallback(M=>{var G;z(M)||((G=I.current)==null||G.focus(),T(null))},[z]),onTriggerLeave:v.useCallback(M=>{z(M)&&M.preventDefault()},[z]),pointerGraceTimerRef:R,onPointerGraceIntentChange:v.useCallback(M=>{O.current=M},[]),children:u.jsx(B,{...j,children:u.jsx(Po,{asChild:!0,trapped:o,onMountAutoFocus:fe(s,M=>{var G;M.preventDefault(),(G=I.current)==null||G.focus({preventScroll:!0})}),onUnmountAutoFocus:i,children:u.jsx(Ro,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:c,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:p,onDismiss:h,children:u.jsx(iv,{asChild:!0,...C,dir:x.dir,orientation:"vertical",loop:r,currentTabStopId:S,onCurrentTabStopIdChange:T,onEntryFocus:fe(l,M=>{x.isUsingKeyboardRef.current||M.preventDefault()}),preventScrollOnEntryFocus:!0,children:u.jsx(ru,{role:"menu","aria-orientation":"vertical","data-state":qu(y.open),"data-radix-menu-content":"",dir:x.dir,...b,...g,ref:A,style:{outline:"none",...g.style},onKeyDown:fe(g.onKeyDown,M=>{const X=M.target.closest("[data-radix-menu-content]")===M.currentTarget,se=M.ctrlKey||M.altKey||M.metaKey,be=M.key.length===1;X&&(M.key==="Tab"&&M.preventDefault(),!se&&be&&K(M.key));const Ie=I.current;if(M.target!==Ie||!Gv.includes(M.key))return;M.preventDefault();const U=k().filter(J=>!J.disabled).map(J=>J.ref.current);Tu.includes(M.key)&&U.reverse(),gb(U)}),onBlur:fe(e.onBlur,M=>{M.currentTarget.contains(M.target)||(window.clearTimeout(_.current),L.current="")}),onPointerMove:fe(e.onPointerMove,Vr(M=>{const G=M.target,X=N.current!==M.clientX;if(M.currentTarget.contains(G)&&X){const se=M.clientX>N.current?"right":"left";F.current=se,N.current=M.clientX}}))})})})})})})});_u.displayName=Xt;var ab="MenuGroup",Gi=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(Ne.div,{role:"group",...r,ref:t})});Gi.displayName=ab;var lb="MenuLabel",ju=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(Ne.div,{...r,ref:t})});ju.displayName=lb;var rs="MenuItem",Mu="menu.itemSelect",os=v.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...o}=e,s=v.useRef(null),i=Hr(rs,e.__scopeMenu),a=Ki(rs,e.__scopeMenu),l=Be(t,s),c=v.useRef(!1),d=()=>{const f=s.current;if(!n&&f){const p=new CustomEvent(Mu,{bubbles:!0,cancelable:!0});f.addEventListener(Mu,h=>r==null?void 0:r(h),{once:!0}),dc(f,p),p.defaultPrevented?c.current=!1:i.onClose()}};return u.jsx(Ru,{...o,ref:l,disabled:n,onClick:fe(e.onClick,d),onPointerDown:f=>{var p;(p=e.onPointerDown)==null||p.call(e,f),c.current=!0},onPointerUp:fe(e.onPointerUp,f=>{var p;c.current||(p=f.currentTarget)==null||p.click()}),onKeyDown:fe(e.onKeyDown,f=>{const p=a.searchRef.current!=="";n||p&&f.key===" "||Hi.includes(f.key)&&(f.currentTarget.click(),f.preventDefault())})})});os.displayName=rs;var Ru=v.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:o,...s}=e,i=Ki(rs,n),a=Iu(n),l=v.useRef(null),c=Be(t,l),[d,f]=v.useState(!1),[p,h]=v.useState("");return v.useEffect(()=>{const m=l.current;m&&h((m.textContent??"").trim())},[s.children]),u.jsx(Ur.ItemSlot,{scope:n,disabled:r,textValue:o??p,children:u.jsx(av,{asChild:!0,...a,focusable:!r,children:u.jsx(Ne.div,{role:"menuitem","data-highlighted":d?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:c,onPointerMove:fe(e.onPointerMove,Vr(m=>{r?i.onItemLeave(m):(i.onItemEnter(m),m.defaultPrevented||m.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:fe(e.onPointerLeave,Vr(m=>i.onItemLeave(m))),onFocus:fe(e.onFocus,()=>f(!0)),onBlur:fe(e.onBlur,()=>f(!1))})})})}),cb="MenuCheckboxItem",Pu=v.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...o}=e;return u.jsx(Fu,{scope:e.__scopeMenu,checked:n,children:u.jsx(os,{role:"menuitemcheckbox","aria-checked":ss(n)?"mixed":n,...o,ref:t,"data-state":Xi(n),onSelect:fe(o.onSelect,()=>r==null?void 0:r(ss(n)?!0:!n),{checkForDefaultPrevented:!1})})})});Pu.displayName=cb;var Ou="MenuRadioGroup",[ub,db]=Gn(Ou,{value:void 0,onValueChange:()=>{}}),Du=v.forwardRef((e,t)=>{const{value:n,onValueChange:r,...o}=e,s=Tt(r);return u.jsx(ub,{scope:e.__scopeMenu,value:n,onValueChange:s,children:u.jsx(Gi,{...o,ref:t})})});Du.displayName=Ou;var Lu="MenuRadioItem",$u=v.forwardRef((e,t)=>{const{value:n,...r}=e,o=db(Lu,e.__scopeMenu),s=n===o.value;return u.jsx(Fu,{scope:e.__scopeMenu,checked:s,children:u.jsx(os,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":Xi(s),onSelect:fe(r.onSelect,()=>{var i;return(i=o.onValueChange)==null?void 0:i.call(o,n)},{checkForDefaultPrevented:!1})})})});$u.displayName=Lu;var Yi="MenuItemIndicator",[Fu,fb]=Gn(Yi,{checked:!1}),Bu=v.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...o}=e,s=fb(Yi,n);return u.jsx(Yt,{present:r||ss(s.checked)||s.checked===!0,children:u.jsx(Ne.span,{...o,ref:t,"data-state":Xi(s.checked)})})});Bu.displayName=Yi;var pb="MenuSeparator",zu=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(Ne.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});zu.displayName=pb;var hb="MenuArrow",Uu=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=ns(n);return u.jsx(ou,{...o,...r,ref:t})});Uu.displayName=hb;var mb="MenuSub",[LT,Hu]=Gn(mb),Wr="MenuSubTrigger",Wu=v.forwardRef((e,t)=>{const n=Yn(Wr,e.__scopeMenu),r=Hr(Wr,e.__scopeMenu),o=Hu(Wr,e.__scopeMenu),s=Ki(Wr,e.__scopeMenu),i=v.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:l}=s,c={__scopeMenu:e.__scopeMenu},d=v.useCallback(()=>{i.current&&window.clearTimeout(i.current),i.current=null},[]);return v.useEffect(()=>d,[d]),v.useEffect(()=>{const f=a.current;return()=>{window.clearTimeout(f),l(null)}},[a,l]),u.jsx(Wi,{asChild:!0,...c,children:u.jsx(Ru,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":o.contentId,"data-state":qu(n.open),...e,ref:mi(t,o.onTriggerChange),onClick:f=>{var p;(p=e.onClick)==null||p.call(e,f),!(e.disabled||f.defaultPrevented)&&(f.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:fe(e.onPointerMove,Vr(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,Vr(f=>{var h,m;d();const p=(h=n.content)==null?void 0:h.getBoundingClientRect();if(p){const g=(m=n.content)==null?void 0:m.dataset.side,y=g==="right",x=y?-5:5,b=p[y?"left":"right"],C=p[y?"right":"left"];s.onPointerGraceIntentChange({area:[{x:f.clientX+x,y:f.clientY},{x:b,y:p.top},{x:C,y:p.top},{x:C,y:p.bottom},{x:b,y:p.bottom}],side:g}),window.clearTimeout(a.current),a.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(f),f.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:fe(e.onKeyDown,f=>{var h;const p=s.searchRef.current!=="";e.disabled||p&&f.key===" "||Yv[r.dir].includes(f.key)&&(n.onOpenChange(!0),(h=n.content)==null||h.focus(),f.preventDefault())})})})});Wu.displayName=Wr;var Vu="MenuSubContent",Ku=v.forwardRef((e,t)=>{const n=Au(Xt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Yn(Xt,e.__scopeMenu),i=Hr(Xt,e.__scopeMenu),a=Hu(Vu,e.__scopeMenu),l=v.useRef(null),c=Be(t,l);return u.jsx(Ur.Provider,{scope:e.__scopeMenu,children:u.jsx(Yt,{present:r||s.open,children:u.jsx(Ur.Slot,{scope:e.__scopeMenu,children:u.jsx(qi,{id:a.contentId,"aria-labelledby":a.triggerId,...o,ref:c,align:"start",side:i.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus: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 h;const f=d.currentTarget.contains(d.target),p=Xv[i.dir].includes(d.key);f&&p&&(s.onOpenChange(!1),(h=a.trigger)==null||h.focus(),d.preventDefault())})})})})})});Ku.displayName=Vu;function qu(e){return e?"open":"closed"}function ss(e){return e==="indeterminate"}function Xi(e){return ss(e)?"indeterminate":e?"checked":"unchecked"}function gb(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function xb(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function yb(e,t,n){const o=t.length>1&&Array.from(t).every(c=>c===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let i=xb(e,Math.max(s,0));o.length===1&&(i=i.filter(c=>c!==n));const l=i.find(c=>c.toLowerCase().startsWith(o.toLowerCase()));return l!==n?l:void 0}function vb(e,t){const{x:n,y:r}=e;let o=!1;for(let s=0,i=t.length-1;s<t.length;i=s++){const a=t[s],l=t[i],c=a.x,d=a.y,f=l.x,p=l.y;d>r!=p>r&&n<(f-c)*(r-d)/(p-d)+c&&(o=!o)}return o}function bb(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return vb(n,t)}function Vr(e){return t=>t.pointerType==="mouse"?e(t):void 0}var wb=Eu,Sb=Wi,Cb=Nu,Tb=_u,kb=Gi,Ib=ju,Eb=os,Ab=Pu,Nb=Du,_b=$u,jb=Bu,Mb=zu,Rb=Uu,Pb=Wu,Ob=Ku,is="DropdownMenu",[Db,$T]=Sn(is,[ku]),Pt=ku(),[Lb,Gu]=Db(is),Yu=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:o,defaultOpen:s,onOpenChange:i,modal:a=!0}=e,l=Pt(t),c=v.useRef(null),[d,f]=fr({prop:o,defaultProp:s??!1,onChange:i,caller:is});return u.jsx(Lb,{scope:t,triggerId:Cn(),triggerRef:c,contentId:Cn(),open:d,onOpenChange:f,onOpenToggle:v.useCallback(()=>f(p=>!p),[f]),modal:a,children:u.jsx(wb,{...l,open:d,onOpenChange:f,dir:r,modal:a,children:n})})};Yu.displayName=is;var Xu="DropdownMenuTrigger",Ju=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...o}=e,s=Gu(Xu,n),i=Pt(n);return u.jsx(Sb,{asChild:!0,...i,children:u.jsx(Ne.button,{type:"button",id:s.triggerId,"aria-haspopup":"menu","aria-expanded":s.open,"aria-controls":s.open?s.contentId:void 0,"data-state":s.open?"open":"closed","data-disabled":r?"":void 0,disabled:r,...o,ref:mi(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())})})})});Ju.displayName=Xu;var $b="DropdownMenuPortal",Zu=e=>{const{__scopeDropdownMenu:t,...n}=e,r=Pt(t);return u.jsx(Cb,{...r,...n})};Zu.displayName=$b;var Qu="DropdownMenuContent",ed=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Gu(Qu,n),s=Pt(n),i=v.useRef(!1);return u.jsx(Tb,{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,c=l.button===0&&l.ctrlKey===!0,d=l.button===2||c;(!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)"}})});ed.displayName=Qu;var Fb="DropdownMenuGroup",Bb=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Pt(n);return u.jsx(kb,{...o,...r,ref:t})});Bb.displayName=Fb;var zb="DropdownMenuLabel",td=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Pt(n);return u.jsx(Ib,{...o,...r,ref:t})});td.displayName=zb;var Ub="DropdownMenuItem",nd=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Pt(n);return u.jsx(Eb,{...o,...r,ref:t})});nd.displayName=Ub;var Hb="DropdownMenuCheckboxItem",rd=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Pt(n);return u.jsx(Ab,{...o,...r,ref:t})});rd.displayName=Hb;var Wb="DropdownMenuRadioGroup",Vb=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Pt(n);return u.jsx(Nb,{...o,...r,ref:t})});Vb.displayName=Wb;var Kb="DropdownMenuRadioItem",od=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Pt(n);return u.jsx(_b,{...o,...r,ref:t})});od.displayName=Kb;var qb="DropdownMenuItemIndicator",sd=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Pt(n);return u.jsx(jb,{...o,...r,ref:t})});sd.displayName=qb;var Gb="DropdownMenuSeparator",id=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Pt(n);return u.jsx(Mb,{...o,...r,ref:t})});id.displayName=Gb;var Yb="DropdownMenuArrow",Xb=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Pt(n);return u.jsx(Rb,{...o,...r,ref:t})});Xb.displayName=Yb;var Jb="DropdownMenuSubTrigger",ad=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Pt(n);return u.jsx(Pb,{...o,...r,ref:t})});ad.displayName=Jb;var Zb="DropdownMenuSubContent",ld=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Pt(n);return u.jsx(Ob,{...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)"}})});ld.displayName=Zb;var Qb=Yu,ew=Ju,tw=Zu,cd=ed,ud=td,dd=nd,fd=rd,pd=od,hd=sd,md=id,gd=ad,xd=ld;const nw=Qb,rw=ew,ow=v.forwardRef(({className:e,inset:t,children:n,...r},o)=>u.jsxs(gd,{ref:o,className:te("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,u.jsx(le.ChevronRight,{className:"ml-auto h-4 w-4"})]}));ow.displayName=gd.displayName;const sw=v.forwardRef(({className:e,...t},n)=>u.jsx(xd,{ref:n,className:te("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}));sw.displayName=xd.displayName;const yd=v.forwardRef(({className:e,sideOffset:t=4,...n},r)=>u.jsx(tw,{children:u.jsx(cd,{ref:r,sideOffset:t,className:te("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})}));yd.displayName=cd.displayName;const Ji=v.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(dd,{ref:r,className:te("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}));Ji.displayName=dd.displayName;const iw=v.forwardRef(({className:e,children:t,checked:n,...r},o)=>u.jsxs(fd,{ref:o,className:te("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:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(hd,{children:u.jsx(le.Check,{className:"h-4 w-4"})})}),t]}));iw.displayName=fd.displayName;const aw=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(pd,{ref:r,className:te("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:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(hd,{children:u.jsx(le.Circle,{className:"h-2 w-2 fill-current"})})}),t]}));aw.displayName=pd.displayName;const lw=v.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(ud,{ref:r,className:te("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));lw.displayName=ud.displayName;const cw=v.forwardRef(({className:e,...t},n)=>u.jsx(md,{ref:n,className:te("-mx-1 my-1 h-px bg-muted",e),...t}));cw.displayName=md.displayName;function uw(e){const t=new Map;console.log("[attemptDetection] groupCheckpointsByLastUserMessageId processing",e.length,"checkpoints");for(const n of e){const o=[...n.messages??[]].reverse().find(s=>s.role==="user");if(o!=null&&o.id){const s=t.get(o.id)??[];s.push(n),t.set(o.id,s),s.length===1?console.log(`[attemptDetection] New user message group: "${o.id}" checkpoint ${n.checkpointId}`):console.log(`[attemptDetection] Adding to existing group: "${o.id}" now has ${s.length} checkpoints`)}else console.log(`[attemptDetection] Checkpoint ${n.checkpointId} has no user messages`)}return console.log("[attemptDetection] Final grouping:",{totalGroups:t.size,groupSizes:Array.from(t.entries()).map(([n,r])=>({userMessageId:n,count:r.length}))}),t}function dw(e){console.log("[attemptDetection] buildAttemptMetadataMap called with",e.length,"checkpoints");const t=new Map,n=uw(e);console.log("[attemptDetection] Grouped into",n.size,"unique user message IDs");for(const[r,o]of n.entries())o.length>1&&console.log(`[attemptDetection] User message "${r}" found in ${o.length} checkpoints (EDITS DETECTED)`,{checkpointIds:o.map(s=>s.checkpointId),createdAts:o.map(s=>s.createdAt)});for(const[r,o]of n.entries())if(o.length===1){const s=o[0];s.checkpointId&&t.set(s.checkpointId,{attemptIndex:0,attemptCount:1,isLatestAttempt:!0,baseUserMessageId:r})}else{const s=[...o].sort((i,a)=>Date.parse(a.createdAt??"0")-Date.parse(i.createdAt??"0"));console.log(`[attemptDetection] Sorted ${s.length} versions for user message "${r}":`,{versionOrder:s.map((i,a)=>`v${a}: ${i.checkpointId} (${i.createdAt})`)}),s.forEach((i,a)=>{i.checkpointId&&t.set(i.checkpointId,{attemptIndex:a,attemptCount:s.length,isLatestAttempt:a===s.length-1,baseUserMessageId:r})})}return console.log("[attemptDetection] Final versionMetadata:",{totalCheckpoints:t.size,editedMessages:Array.from(t.entries()).filter(([r,o])=>o.attemptCount>1).map(([r,o])=>({checkpointId:r,attemptIndex:o.attemptIndex,attemptCount:o.attemptCount,isLatestAttempt:o.isLatestAttempt}))}),t}function fw(e){const t=new Map;for(const[n,r]of e.entries())if(r.baseUserMessageId&&r.attemptCount>1){const o=t.get(r.baseUserMessageId)??[];o.push({checkpointId:n,attemptIndex:r.attemptIndex,attemptCount:r.attemptCount,isLatestAttempt:r.isLatestAttempt}),t.set(r.baseUserMessageId,o)}return t}function as(e,t){if(!e||typeof e!="object")return null;const n=e[t];return typeof n=="number"?n:null}function pw(e,t){if(!e||typeof e!="object")return null;const n=e[t];return typeof n=="string"&&n.trim()?n:null}function hw(e){if(!Array.isArray(e)||e.length===0)return null;const t=e.map(n=>{if(typeof n=="string")return n.trim();if(n&&typeof n=="object"&&"type"in n){const r=n;if(typeof r.type=="string")return r.type}return null}).filter(n=>!!(n&&n.length));return t.length?t.join(", "):null}function mw(e){const t=Array.isArray(e)?e.map(r=>{const o=hw(r.next);return o?{...r,metadata:{...r.metadata??{},next:o}}:r}):[];return t.some(r=>as(r.metadata,"step")!==null)&&t.sort((r,o)=>{const s=as(r.metadata,"step"),i=as(o.metadata,"step");if(s!==null||i!==null)return(i??Number.NEGATIVE_INFINITY)-(s??Number.NEGATIVE_INFINITY);const a=Date.parse(r.createdAt??""),l=Date.parse(o.createdAt??"");return Number.isNaN(a)||Number.isNaN(l)?0:l-a}),t}function gw(e){const t=w.useMemo(()=>mw(e),[e]),{checkpointMetaById:n,checkpointIndexByKey:r,attemptMetaById:o,userMessageIdToAttempts:s}=w.useMemo(()=>{const i=new Map,a=new Map,l=new Map;for(const f of t){const p=f.checkpointId??null;if(!p)continue;const h=as(f.metadata,"step"),m=pw(f.metadata,"source"),g={id:p,step:h,source:m,createdAt:f.createdAt??null,namespace:f.checkpointNs??null,parentId:f.parentId??null};if(i.set(p,g),h!==null&&m){const y=`${h}:${m}`,x=a.get(y)??[];x.push(g),a.set(y,x)}}console.log("[useCheckpointMetadata] Building attempt metadata for",t.length,"checkpoints");const c=dw(t);for(const[f,p]of i.entries()){const h=c.get(f);h?l.set(f,{...p,attemptIndex:h.attemptIndex,attemptCount:h.attemptCount,isLatestAttempt:h.isLatestAttempt,baseUserMessageId:h.baseUserMessageId??null}):l.set(f,{...p,attemptIndex:0,attemptCount:1,isLatestAttempt:!0,baseUserMessageId:null})}console.log("[useCheckpointMetadata] Final attemptMetaById:",{totalCheckpoints:l.size,withMultipleAttempts:Array.from(l.values()).filter(f=>f.attemptCount>1).length,samples:Array.from(l.entries()).slice(0,3).map(([f,p])=>({checkpointId:f,attemptIndex:p.attemptIndex,attemptCount:p.attemptCount}))});const d=fw(l);return console.log("[useCheckpointMetadata] userMessageIdToAttempts map built with",d.size,"user message IDs with multiple attempts"),{checkpointMetaById:i,checkpointIndexByKey:a,attemptMetaById:l,userMessageIdToAttempts:d}},[t]);return{checkpointMetaById:n,checkpointIndexByKey:r,attemptMetaById:o,userMessageIdToAttempts:s}}const ls=1e4;function xw(e){if(typeof e!="string")return String(e);const t=[/<script[^>]*>.*?<\/script>/gi,/<iframe[^>]*>.*?<\/iframe>/gi,/javascript:/gi,/vbscript:/gi,/on\w+\s*=/gi,/<object[^>]*>.*?<\/object>/gi,/<embed[^>]*>.*?<\/embed>/gi,/<form[^>]*>.*?<\/form>/gi];let n=e;for(const o of t)n=n.replace(o,"");return/<[^>]+>/.test(n)&&!/<(?!\/?(?:code|strong|em|b|i|br|p|ul|ol|li|h[1-6])\b)[^>]+>/i.test(n)?n.replace(/<code>(.*?)<\/code>/gi,"`$1`").replace(/<strong>(.*?)<\/strong>/gi,"**$1**").replace(/<b>(.*?)<\/b>/gi,"**$1**").replace(/<em>(.*?)<\/em>/gi,"*$1*").replace(/<i>(.*?)<\/i>/gi,"*$1*").replace(/<br\s*\/?>/gi,`
|
|
78
|
+
`)},Zv=0,wr=[];function Qv(e){var t=v.useRef([]),n=v.useRef([0,0]),r=v.useRef(),o=v.useState(Zv++)[0],s=v.useState(xu)[0],i=v.useRef(e);v.useEffect(function(){i.current=e},[e]),v.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(o));var g=bv([e.lockRef.current],(e.shards||[]).map(Tu),!0).filter(Boolean);return g.forEach(function(y){return y.classList.add("allow-interactivity-".concat(o))}),function(){document.body.classList.remove("block-interactivity-".concat(o)),g.forEach(function(y){return y.classList.remove("allow-interactivity-".concat(o))})}}},[e.inert,e.lockRef.current,e.shards]);var a=v.useCallback(function(g,y){if("touches"in g&&g.touches.length===2||g.type==="wheel"&&g.ctrlKey)return!i.current.allowPinchZoom;var x=ts(g),b=n.current,S="deltaX"in g?g.deltaX:b[0]-x[0],k="deltaY"in g?g.deltaY:b[1]-x[1],C,T=g.target,I=Math.abs(S)>Math.abs(k)?"h":"v";if("touches"in g&&I==="h"&&T.type==="range")return!1;var A=bu(I,T);if(!A)return!0;if(A?C=I:(C=I==="v"?"h":"v",A=bu(I,T)),!A)return!1;if(!r.current&&"changedTouches"in g&&(S||k)&&(r.current=C),!C)return!0;var N=r.current||C;return Yv(N,y,g,N==="h"?S:k)},[]),l=v.useCallback(function(g){var y=g;if(!(!wr.length||wr[wr.length-1]!==s)){var x="deltaY"in y?Cu(y):ts(y),b=t.current.filter(function(C){return C.name===y.type&&(C.target===y.target||y.target===C.shadowParent)&&Xv(C.delta,x)})[0];if(b&&b.should){y.cancelable&&y.preventDefault();return}if(!b){var S=(i.current.shards||[]).map(Tu).filter(Boolean).filter(function(C){return C.contains(y.target)}),k=S.length>0?a(y,S[0]):!i.current.noIsolation;k&&y.cancelable&&y.preventDefault()}}},[]),c=v.useCallback(function(g,y,x,b){var S={name:g,delta:y,target:x,should:b,shadowParent:eb(x)};t.current.push(S),setTimeout(function(){t.current=t.current.filter(function(k){return k!==S})},1)},[]),d=v.useCallback(function(g){n.current=ts(g),r.current=void 0},[]),f=v.useCallback(function(g){c(g.type,Cu(g),g.target,a(g,e.lockRef.current))},[]),h=v.useCallback(function(g){c(g.type,ts(g),g.target,a(g,e.lockRef.current))},[]);v.useEffect(function(){return wr.push(s),e.setCallbacks({onScrollCapture:f,onWheelCapture:f,onTouchMoveCapture:h}),document.addEventListener("wheel",l,br),document.addEventListener("touchmove",l,br),document.addEventListener("touchstart",d,br),function(){wr=wr.filter(function(g){return g!==s}),document.removeEventListener("wheel",l,br),document.removeEventListener("touchmove",l,br),document.removeEventListener("touchstart",d,br)}},[]);var p=e.removeScrollBar,m=e.inert;return v.createElement(v.Fragment,null,m?v.createElement(s,{styles:Jv(o)}):null,p?v.createElement(Uv,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function eb(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const tb=Nv(gu,Qv);var ns=v.forwardRef(function(e,t){return v.createElement(Qo,xn({},e,{ref:t,sideCar:tb}))});ns.classNames=Qo.classNames;var Ui=["Enter"," "],nb=["ArrowDown","PageUp","Home"],ku=["ArrowUp","PageDown","End"],rb=[...nb,...ku],ob={ltr:[...Ui,"ArrowRight"],rtl:[...Ui,"ArrowLeft"]},sb={ltr:["ArrowLeft"],rtl:["ArrowRight"]},zr="Menu",[Ur,ib,ab]=mi(zr),[Yn,Iu]=Cn(zr,[ab,Ko,au]),rs=Ko(),Eu=au(),[lb,Xn]=Yn(zr),[cb,Hr]=Yn(zr),Au=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=rs(t),[l,c]=v.useState(null),d=v.useRef(!1),f=kt(s),h=Ro(o);return v.useEffect(()=>{const p=()=>{d.current=!0,document.addEventListener("pointerdown",m,{capture:!0,once:!0}),document.addEventListener("pointermove",m,{capture:!0,once:!0})},m=()=>d.current=!1;return document.addEventListener("keydown",p,{capture:!0}),()=>{document.removeEventListener("keydown",p,{capture:!0}),document.removeEventListener("pointerdown",m,{capture:!0}),document.removeEventListener("pointermove",m,{capture:!0})}},[]),u.jsx(nu,{...a,children:u.jsx(lb,{scope:t,open:n,onOpenChange:f,content:l,onContentChange:c,children:u.jsx(cb,{scope:t,onClose:v.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:d,dir:h,modal:i,children:r})})})};Au.displayName=zr;var ub="MenuAnchor",Hi=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=rs(n);return u.jsx(ru,{...o,...r,ref:t})});Hi.displayName=ub;var Wi="MenuPortal",[db,Nu]=Yn(Wi,{forceMount:void 0}),_u=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:o}=e,s=Xn(Wi,t);return u.jsx(db,{scope:t,forceMount:n,children:u.jsx(Xt,{present:n||s.open,children:u.jsx(qo,{asChild:!0,container:o,children:r})})})};_u.displayName=Wi;var Jt="MenuContent",[fb,Vi]=Yn(Jt),ju=v.forwardRef((e,t)=>{const n=Nu(Jt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Xn(Jt,e.__scopeMenu),i=Hr(Jt,e.__scopeMenu);return u.jsx(Ur.Provider,{scope:e.__scopeMenu,children:u.jsx(Xt,{present:r||s.open,children:u.jsx(Ur.Slot,{scope:e.__scopeMenu,children:i.modal?u.jsx(pb,{...o,ref:t}):u.jsx(hb,{...o,ref:t})})})})}),pb=v.forwardRef((e,t)=>{const n=Xn(Jt,e.__scopeMenu),r=v.useRef(null),o=Be(t,r);return v.useEffect(()=>{const s=r.current;if(s)return Li(s)},[]),u.jsx(Ki,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:fe(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),hb=v.forwardRef((e,t)=>{const n=Xn(Jt,e.__scopeMenu);return u.jsx(Ki,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),mb=Wn.createSlot("MenuContent.ScrollLock"),Ki=v.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:o,onOpenAutoFocus:s,onCloseAutoFocus:i,disableOutsidePointerEvents:a,onEntryFocus:l,onEscapeKeyDown:c,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:h,onDismiss:p,disableOutsideScroll:m,...g}=e,y=Xn(Jt,n),x=Hr(Jt,n),b=rs(n),S=Eu(n),k=ib(n),[C,T]=v.useState(null),I=v.useRef(null),A=Be(t,I,y.onContentChange),N=v.useRef(0),L=v.useRef(""),R=v.useRef(0),O=v.useRef(null),F=v.useRef("right"),_=v.useRef(0),B=m?ns:v.Fragment,j=m?{as:mb,allowPinchZoom:!0}:void 0,K=M=>{var J,$;const G=L.current+M,X=k().filter(q=>!q.disabled),se=document.activeElement,be=(J=X.find(q=>q.ref.current===se))==null?void 0:J.textValue,Ie=X.map(q=>q.textValue),Y=Eb(Ie,G,be),U=($=X.find(q=>q.textValue===Y))==null?void 0:$.ref.current;(function q(Z){L.current=Z,window.clearTimeout(N.current),Z!==""&&(N.current=window.setTimeout(()=>q(""),1e3))})(G),U&&setTimeout(()=>U.focus())};v.useEffect(()=>()=>window.clearTimeout(N.current),[]),yi();const z=v.useCallback(M=>{var X,se;return F.current===((X=O.current)==null?void 0:X.side)&&Nb(M,(se=O.current)==null?void 0:se.area)},[]);return u.jsx(fb,{scope:n,searchRef:L,onItemEnter:v.useCallback(M=>{z(M)&&M.preventDefault()},[z]),onItemLeave:v.useCallback(M=>{var G;z(M)||((G=I.current)==null||G.focus(),T(null))},[z]),onTriggerLeave:v.useCallback(M=>{z(M)&&M.preventDefault()},[z]),pointerGraceTimerRef:R,onPointerGraceIntentChange:v.useCallback(M=>{O.current=M},[]),children:u.jsx(B,{...j,children:u.jsx(Oo,{asChild:!0,trapped:o,onMountAutoFocus:fe(s,M=>{var G;M.preventDefault(),(G=I.current)==null||G.focus({preventScroll:!0})}),onUnmountAutoFocus:i,children:u.jsx(Po,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:c,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:h,onDismiss:p,children:u.jsx(mv,{asChild:!0,...S,dir:x.dir,orientation:"vertical",loop:r,currentTabStopId:C,onCurrentTabStopIdChange:T,onEntryFocus:fe(l,M=>{x.isUsingKeyboardRef.current||M.preventDefault()}),preventScrollOnEntryFocus:!0,children:u.jsx(ou,{role:"menu","aria-orientation":"vertical","data-state":Gu(y.open),"data-radix-menu-content":"",dir:x.dir,...b,...g,ref:A,style:{outline:"none",...g.style},onKeyDown:fe(g.onKeyDown,M=>{const X=M.target.closest("[data-radix-menu-content]")===M.currentTarget,se=M.ctrlKey||M.altKey||M.metaKey,be=M.key.length===1;X&&(M.key==="Tab"&&M.preventDefault(),!se&&be&&K(M.key));const Ie=I.current;if(M.target!==Ie||!rb.includes(M.key))return;M.preventDefault();const U=k().filter(J=>!J.disabled).map(J=>J.ref.current);ku.includes(M.key)&&U.reverse(),kb(U)}),onBlur:fe(e.onBlur,M=>{M.currentTarget.contains(M.target)||(window.clearTimeout(N.current),L.current="")}),onPointerMove:fe(e.onPointerMove,Vr(M=>{const G=M.target,X=_.current!==M.clientX;if(M.currentTarget.contains(G)&&X){const se=M.clientX>_.current?"right":"left";F.current=se,_.current=M.clientX}}))})})})})})})});ju.displayName=Jt;var gb="MenuGroup",qi=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(Ne.div,{role:"group",...r,ref:t})});qi.displayName=gb;var xb="MenuLabel",Mu=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(Ne.div,{...r,ref:t})});Mu.displayName=xb;var os="MenuItem",Ru="menu.itemSelect",ss=v.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...o}=e,s=v.useRef(null),i=Hr(os,e.__scopeMenu),a=Vi(os,e.__scopeMenu),l=Be(t,s),c=v.useRef(!1),d=()=>{const f=s.current;if(!n&&f){const h=new CustomEvent(Ru,{bubbles:!0,cancelable:!0});f.addEventListener(Ru,p=>r==null?void 0:r(p),{once:!0}),fc(f,h),h.defaultPrevented?c.current=!1:i.onClose()}};return u.jsx(Pu,{...o,ref:l,disabled:n,onClick:fe(e.onClick,d),onPointerDown:f=>{var h;(h=e.onPointerDown)==null||h.call(e,f),c.current=!0},onPointerUp:fe(e.onPointerUp,f=>{var h;c.current||(h=f.currentTarget)==null||h.click()}),onKeyDown:fe(e.onKeyDown,f=>{const h=a.searchRef.current!=="";n||h&&f.key===" "||Ui.includes(f.key)&&(f.currentTarget.click(),f.preventDefault())})})});ss.displayName=os;var Pu=v.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:o,...s}=e,i=Vi(os,n),a=Eu(n),l=v.useRef(null),c=Be(t,l),[d,f]=v.useState(!1),[h,p]=v.useState("");return v.useEffect(()=>{const m=l.current;m&&p((m.textContent??"").trim())},[s.children]),u.jsx(Ur.ItemSlot,{scope:n,disabled:r,textValue:o??h,children:u.jsx(gv,{asChild:!0,...a,focusable:!r,children:u.jsx(Ne.div,{role:"menuitem","data-highlighted":d?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:c,onPointerMove:fe(e.onPointerMove,Vr(m=>{r?i.onItemLeave(m):(i.onItemEnter(m),m.defaultPrevented||m.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:fe(e.onPointerLeave,Vr(m=>i.onItemLeave(m))),onFocus:fe(e.onFocus,()=>f(!0)),onBlur:fe(e.onBlur,()=>f(!1))})})})}),yb="MenuCheckboxItem",Ou=v.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...o}=e;return u.jsx(Bu,{scope:e.__scopeMenu,checked:n,children:u.jsx(ss,{role:"menuitemcheckbox","aria-checked":is(n)?"mixed":n,...o,ref:t,"data-state":Yi(n),onSelect:fe(o.onSelect,()=>r==null?void 0:r(is(n)?!0:!n),{checkForDefaultPrevented:!1})})})});Ou.displayName=yb;var Du="MenuRadioGroup",[vb,bb]=Yn(Du,{value:void 0,onValueChange:()=>{}}),Lu=v.forwardRef((e,t)=>{const{value:n,onValueChange:r,...o}=e,s=kt(r);return u.jsx(vb,{scope:e.__scopeMenu,value:n,onValueChange:s,children:u.jsx(qi,{...o,ref:t})})});Lu.displayName=Du;var $u="MenuRadioItem",Fu=v.forwardRef((e,t)=>{const{value:n,...r}=e,o=bb($u,e.__scopeMenu),s=n===o.value;return u.jsx(Bu,{scope:e.__scopeMenu,checked:s,children:u.jsx(ss,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":Yi(s),onSelect:fe(r.onSelect,()=>{var i;return(i=o.onValueChange)==null?void 0:i.call(o,n)},{checkForDefaultPrevented:!1})})})});Fu.displayName=$u;var Gi="MenuItemIndicator",[Bu,wb]=Yn(Gi,{checked:!1}),zu=v.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...o}=e,s=wb(Gi,n);return u.jsx(Xt,{present:r||is(s.checked)||s.checked===!0,children:u.jsx(Ne.span,{...o,ref:t,"data-state":Yi(s.checked)})})});zu.displayName=Gi;var Sb="MenuSeparator",Uu=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(Ne.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});Uu.displayName=Sb;var Cb="MenuArrow",Hu=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=rs(n);return u.jsx(su,{...o,...r,ref:t})});Hu.displayName=Cb;var Tb="MenuSub",[qT,Wu]=Yn(Tb),Wr="MenuSubTrigger",Vu=v.forwardRef((e,t)=>{const n=Xn(Wr,e.__scopeMenu),r=Hr(Wr,e.__scopeMenu),o=Wu(Wr,e.__scopeMenu),s=Vi(Wr,e.__scopeMenu),i=v.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:l}=s,c={__scopeMenu:e.__scopeMenu},d=v.useCallback(()=>{i.current&&window.clearTimeout(i.current),i.current=null},[]);return v.useEffect(()=>d,[d]),v.useEffect(()=>{const f=a.current;return()=>{window.clearTimeout(f),l(null)}},[a,l]),u.jsx(Hi,{asChild:!0,...c,children:u.jsx(Pu,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":o.contentId,"data-state":Gu(n.open),...e,ref:hi(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,Vr(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,Vr(f=>{var p,m;d();const h=(p=n.content)==null?void 0:p.getBoundingClientRect();if(h){const g=(m=n.content)==null?void 0:m.dataset.side,y=g==="right",x=y?-5:5,b=h[y?"left":"right"],S=h[y?"right":"left"];s.onPointerGraceIntentChange({area:[{x:f.clientX+x,y:f.clientY},{x:b,y:h.top},{x:S,y:h.top},{x:S,y:h.bottom},{x:b,y:h.bottom}],side:g}),window.clearTimeout(a.current),a.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(f),f.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:fe(e.onKeyDown,f=>{var p;const h=s.searchRef.current!=="";e.disabled||h&&f.key===" "||ob[r.dir].includes(f.key)&&(n.onOpenChange(!0),(p=n.content)==null||p.focus(),f.preventDefault())})})})});Vu.displayName=Wr;var Ku="MenuSubContent",qu=v.forwardRef((e,t)=>{const n=Nu(Jt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Xn(Jt,e.__scopeMenu),i=Hr(Jt,e.__scopeMenu),a=Wu(Ku,e.__scopeMenu),l=v.useRef(null),c=Be(t,l);return u.jsx(Ur.Provider,{scope:e.__scopeMenu,children:u.jsx(Xt,{present:r||s.open,children:u.jsx(Ur.Slot,{scope:e.__scopeMenu,children:u.jsx(Ki,{id:a.contentId,"aria-labelledby":a.triggerId,...o,ref:c,align:"start",side:i.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus: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=sb[i.dir].includes(d.key);f&&h&&(s.onOpenChange(!1),(p=a.trigger)==null||p.focus(),d.preventDefault())})})})})})});qu.displayName=Ku;function Gu(e){return e?"open":"closed"}function is(e){return e==="indeterminate"}function Yi(e){return is(e)?"indeterminate":e?"checked":"unchecked"}function kb(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function Ib(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function Eb(e,t,n){const o=t.length>1&&Array.from(t).every(c=>c===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let i=Ib(e,Math.max(s,0));o.length===1&&(i=i.filter(c=>c!==n));const l=i.find(c=>c.toLowerCase().startsWith(o.toLowerCase()));return l!==n?l:void 0}function Ab(e,t){const{x:n,y:r}=e;let o=!1;for(let s=0,i=t.length-1;s<t.length;i=s++){const a=t[s],l=t[i],c=a.x,d=a.y,f=l.x,h=l.y;d>r!=h>r&&n<(f-c)*(r-d)/(h-d)+c&&(o=!o)}return o}function Nb(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return Ab(n,t)}function Vr(e){return t=>t.pointerType==="mouse"?e(t):void 0}var _b=Au,jb=Hi,Mb=_u,Rb=ju,Pb=qi,Ob=Mu,Db=ss,Lb=Ou,$b=Lu,Fb=Fu,Bb=zu,zb=Uu,Ub=Hu,Hb=Vu,Wb=qu,as="DropdownMenu",[Vb,GT]=Cn(as,[Iu]),Ot=Iu(),[Kb,Yu]=Vb(as),Xu=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:o,defaultOpen:s,onOpenChange:i,modal:a=!0}=e,l=Ot(t),c=v.useRef(null),[d,f]=pr({prop:o,defaultProp:s??!1,onChange:i,caller:as});return u.jsx(Kb,{scope:t,triggerId:Tn(),triggerRef:c,contentId:Tn(),open:d,onOpenChange:f,onOpenToggle:v.useCallback(()=>f(h=>!h),[f]),modal:a,children:u.jsx(_b,{...l,open:d,onOpenChange:f,dir:r,modal:a,children:n})})};Xu.displayName=as;var Ju="DropdownMenuTrigger",Zu=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...o}=e,s=Yu(Ju,n),i=Ot(n);return u.jsx(jb,{asChild:!0,...i,children:u.jsx(Ne.button,{type:"button",id:s.triggerId,"aria-haspopup":"menu","aria-expanded":s.open,"aria-controls":s.open?s.contentId:void 0,"data-state":s.open?"open":"closed","data-disabled":r?"":void 0,disabled:r,...o,ref:hi(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())})})})});Zu.displayName=Ju;var qb="DropdownMenuPortal",Qu=e=>{const{__scopeDropdownMenu:t,...n}=e,r=Ot(t);return u.jsx(Mb,{...r,...n})};Qu.displayName=qb;var ed="DropdownMenuContent",td=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Yu(ed,n),s=Ot(n),i=v.useRef(!1);return u.jsx(Rb,{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,c=l.button===0&&l.ctrlKey===!0,d=l.button===2||c;(!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)"}})});td.displayName=ed;var Gb="DropdownMenuGroup",Yb=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return u.jsx(Pb,{...o,...r,ref:t})});Yb.displayName=Gb;var Xb="DropdownMenuLabel",nd=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return u.jsx(Ob,{...o,...r,ref:t})});nd.displayName=Xb;var Jb="DropdownMenuItem",rd=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return u.jsx(Db,{...o,...r,ref:t})});rd.displayName=Jb;var Zb="DropdownMenuCheckboxItem",od=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return u.jsx(Lb,{...o,...r,ref:t})});od.displayName=Zb;var Qb="DropdownMenuRadioGroup",ew=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return u.jsx($b,{...o,...r,ref:t})});ew.displayName=Qb;var tw="DropdownMenuRadioItem",sd=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return u.jsx(Fb,{...o,...r,ref:t})});sd.displayName=tw;var nw="DropdownMenuItemIndicator",id=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return u.jsx(Bb,{...o,...r,ref:t})});id.displayName=nw;var rw="DropdownMenuSeparator",ad=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return u.jsx(zb,{...o,...r,ref:t})});ad.displayName=rw;var ow="DropdownMenuArrow",sw=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return u.jsx(Ub,{...o,...r,ref:t})});sw.displayName=ow;var iw="DropdownMenuSubTrigger",ld=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return u.jsx(Hb,{...o,...r,ref:t})});ld.displayName=iw;var aw="DropdownMenuSubContent",cd=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return u.jsx(Wb,{...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)"}})});cd.displayName=aw;var lw=Xu,cw=Zu,uw=Qu,ud=td,dd=nd,fd=rd,pd=od,hd=sd,md=id,gd=ad,xd=ld,yd=cd;const dw=lw,fw=cw,pw=v.forwardRef(({className:e,inset:t,children:n,...r},o)=>u.jsxs(xd,{ref:o,className:te("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,u.jsx(le.ChevronRight,{className:"ml-auto h-4 w-4"})]}));pw.displayName=xd.displayName;const hw=v.forwardRef(({className:e,...t},n)=>u.jsx(yd,{ref:n,className:te("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}));hw.displayName=yd.displayName;const vd=v.forwardRef(({className:e,sideOffset:t=4,...n},r)=>u.jsx(uw,{children:u.jsx(ud,{ref:r,sideOffset:t,className:te("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})}));vd.displayName=ud.displayName;const Xi=v.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(fd,{ref:r,className:te("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}));Xi.displayName=fd.displayName;const mw=v.forwardRef(({className:e,children:t,checked:n,...r},o)=>u.jsxs(pd,{ref:o,className:te("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:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(md,{children:u.jsx(le.Check,{className:"h-4 w-4"})})}),t]}));mw.displayName=pd.displayName;const gw=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(hd,{ref:r,className:te("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:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(md,{children:u.jsx(le.Circle,{className:"h-2 w-2 fill-current"})})}),t]}));gw.displayName=hd.displayName;const xw=v.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(dd,{ref:r,className:te("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));xw.displayName=dd.displayName;const yw=v.forwardRef(({className:e,...t},n)=>u.jsx(gd,{ref:n,className:te("-mx-1 my-1 h-px bg-muted",e),...t}));yw.displayName=gd.displayName;function vw(e){const t=new Map;console.log("[attemptDetection] groupCheckpointsByLastUserMessageId processing",e.length,"checkpoints");for(const n of e){const o=[...n.messages??[]].reverse().find(s=>s.role==="user");if(o!=null&&o.id){const s=t.get(o.id)??[];s.push(n),t.set(o.id,s),s.length===1?console.log(`[attemptDetection] New user message group: "${o.id}" checkpoint ${n.checkpointId}`):console.log(`[attemptDetection] Adding to existing group: "${o.id}" now has ${s.length} checkpoints`)}else console.log(`[attemptDetection] Checkpoint ${n.checkpointId} has no user messages`)}return console.log("[attemptDetection] Final grouping:",{totalGroups:t.size,groupSizes:Array.from(t.entries()).map(([n,r])=>({userMessageId:n,count:r.length}))}),t}function bw(e){console.log("[attemptDetection] buildAttemptMetadataMap called with",e.length,"checkpoints");const t=new Map,n=vw(e);console.log("[attemptDetection] Grouped into",n.size,"unique user message IDs");for(const[r,o]of n.entries())o.length>1&&console.log(`[attemptDetection] User message "${r}" found in ${o.length} checkpoints (EDITS DETECTED)`,{checkpointIds:o.map(s=>s.checkpointId),createdAts:o.map(s=>s.createdAt)});for(const[r,o]of n.entries())if(o.length===1){const s=o[0];s.checkpointId&&t.set(s.checkpointId,{attemptIndex:0,attemptCount:1,isLatestAttempt:!0,baseUserMessageId:r})}else{const s=[...o].sort((i,a)=>Date.parse(a.createdAt??"0")-Date.parse(i.createdAt??"0"));console.log(`[attemptDetection] Sorted ${s.length} versions for user message "${r}":`,{versionOrder:s.map((i,a)=>`v${a}: ${i.checkpointId} (${i.createdAt})`)}),s.forEach((i,a)=>{i.checkpointId&&t.set(i.checkpointId,{attemptIndex:a,attemptCount:s.length,isLatestAttempt:a===s.length-1,baseUserMessageId:r})})}return console.log("[attemptDetection] Final versionMetadata:",{totalCheckpoints:t.size,editedMessages:Array.from(t.entries()).filter(([r,o])=>o.attemptCount>1).map(([r,o])=>({checkpointId:r,attemptIndex:o.attemptIndex,attemptCount:o.attemptCount,isLatestAttempt:o.isLatestAttempt}))}),t}function ww(e){const t=new Map;for(const[n,r]of e.entries())if(r.baseUserMessageId&&r.attemptCount>1){const o=t.get(r.baseUserMessageId)??[];o.push({checkpointId:n,attemptIndex:r.attemptIndex,attemptCount:r.attemptCount,isLatestAttempt:r.isLatestAttempt}),t.set(r.baseUserMessageId,o)}return t}function ls(e,t){if(!e||typeof e!="object")return null;const n=e[t];return typeof n=="number"?n:null}function Sw(e,t){if(!e||typeof e!="object")return null;const n=e[t];return typeof n=="string"&&n.trim()?n:null}function Cw(e){if(!Array.isArray(e)||e.length===0)return null;const t=e.map(n=>{if(typeof n=="string")return n.trim();if(n&&typeof n=="object"&&"type"in n){const r=n;if(typeof r.type=="string")return r.type}return null}).filter(n=>!!(n&&n.length));return t.length?t.join(", "):null}function Tw(e){const t=Array.isArray(e)?e.map(r=>{const o=Cw(r.next);return o?{...r,metadata:{...r.metadata??{},next:o}}:r}):[];return t.some(r=>ls(r.metadata,"step")!==null)&&t.sort((r,o)=>{const s=ls(r.metadata,"step"),i=ls(o.metadata,"step");if(s!==null||i!==null)return(i??Number.NEGATIVE_INFINITY)-(s??Number.NEGATIVE_INFINITY);const a=Date.parse(r.createdAt??""),l=Date.parse(o.createdAt??"");return Number.isNaN(a)||Number.isNaN(l)?0:l-a}),t}function kw(e){const t=w.useMemo(()=>Tw(e),[e]),{checkpointMetaById:n,checkpointIndexByKey:r,attemptMetaById:o,userMessageIdToAttempts:s}=w.useMemo(()=>{const i=new Map,a=new Map,l=new Map;for(const f of t){const h=f.checkpointId??null;if(!h)continue;const p=ls(f.metadata,"step"),m=Sw(f.metadata,"source"),g={id:h,step:p,source:m,createdAt:f.createdAt??null,namespace:f.checkpointNs??null,parentId:f.parentId??null};if(i.set(h,g),p!==null&&m){const y=`${p}:${m}`,x=a.get(y)??[];x.push(g),a.set(y,x)}}const c=bw(t);for(const[f,h]of i.entries()){const p=c.get(f);p?l.set(f,{...h,attemptIndex:p.attemptIndex,attemptCount:p.attemptCount,isLatestAttempt:p.isLatestAttempt,baseUserMessageId:p.baseUserMessageId??null}):l.set(f,{...h,attemptIndex:0,attemptCount:1,isLatestAttempt:!0,baseUserMessageId:null})}const d=ww(l);return{checkpointMetaById:i,checkpointIndexByKey:a,attemptMetaById:l,userMessageIdToAttempts:d}},[t]);return{checkpointMetaById:n,checkpointIndexByKey:r,attemptMetaById:o,userMessageIdToAttempts:s}}const cs=1e4;function Iw(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,`
|
|
79
79
|
`).replace(/<p>(.*?)<\/p>/gi,`$1
|
|
80
80
|
|
|
81
81
|
`).replace(/<h([1-6])>(.*?)<\/h[1-6]>/gi,(o,s,i)=>`${"#".repeat(parseInt(s))} ${i}
|
|
@@ -83,25 +83,25 @@ React keys must be passed directly to JSX without using spread:
|
|
|
83
83
|
`).replace(/<ul>/gi,"").replace(/<\/ul>/gi,`
|
|
84
84
|
`).replace(/<ol>/gi,"").replace(/<\/ol>/gi,`
|
|
85
85
|
`).replace(/<li>(.*?)<\/li>/gi,`- $1
|
|
86
|
-
`).trim():n.replace(/</g,"<").replace(/>/g,">").trim()}function yw(e,t=ls){if(!e||typeof e!="string")throw new Error("Invalid content: must be a non-empty string");if(e.length>t)throw new Error(`Message exceeds maximum length of ${t} characters`);return e}function vw(e){let t;return typeof e=="string"?t=e:typeof e=="object"&&e!==null?t=JSON.stringify(e):t=String(e),yw(t),xw(t)}const cs=0,Mn=1,wr=2,vd=4;function bd(e){return()=>e}function bw(e){e()}function wd(e,t){return n=>e(t(n))}function Sd(e,t){return()=>e(t)}function ww(e,t){return n=>e(t,n)}function Zi(e){return e!==void 0}function Sw(...e){return()=>{e.map(bw)}}function Sr(){}function us(e,t){return t(e),e}function Cw(e,t){return t(e)}function lt(...e){return e}function Qe(e,t){return e(Mn,t)}function Pe(e,t){e(cs,t)}function Qi(e){e(wr)}function vt(e){return e(vd)}function he(e,t){return Qe(e,ww(t,cs))}function sn(e,t){const n=e(Mn,r=>{n(),t(r)});return n}function Cd(e){let t,n;return r=>o=>{t=o,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function Td(e,t){return e===t}function ct(e=Td){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function ke(e){return t=>n=>{e(n)&&t(n)}}function ce(e){return t=>wd(t,e)}function xn(e){return t=>()=>{t(e)}}function W(e,...t){const n=Tw(...t);return(r,o)=>{switch(r){case wr:Qi(e);return;case Mn:return Qe(e,n(o))}}}function yn(e,t){return n=>r=>{n(t=e(t,r))}}function Xn(e){return t=>n=>{e>0?e--:t(n)}}function In(e){let t=null,n;return r=>o=>{t=o,!n&&(n=setTimeout(()=>{n=void 0,r(t)},e))}}function Le(...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);Qe(s,l=>{const c=n;n=n|a,t[i]=l,c!==o&&n===o&&r&&(r(),r=null)})}),s=>i=>{const a=()=>{s([i].concat(t))};n===o?a():r=a}}function Tw(...e){return t=>e.reduceRight(Cw,t)}function kw(e){let t,n;const r=()=>t==null?void 0:t();return function(o,s){switch(o){case Mn:return s?n===s?void 0:(r(),n=s,t=Qe(e,s),t):(r(),Sr);case wr:r(),n=null;return}}}function ee(e){let t=e;const n=ze();return(r,o)=>{switch(r){case cs:t=o;break;case Mn:{o(t);break}case vd:return t}return n(r,o)}}function Et(e,t){return us(ee(t),n=>he(e,n))}function ze(){const e=[];return(t,n)=>{switch(t){case cs:e.slice().forEach(r=>{r(n)});return;case wr:e.splice(0,e.length);return;case Mn:return e.push(n),()=>{const r=e.indexOf(n);r>-1&&e.splice(r,1)}}}}function Ut(e){return us(ze(),t=>he(e,t))}function Ke(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:Iw(),singleton:n}}const Iw=()=>Symbol();function Ew(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 bt(...e){const t=ze(),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);Qe(s,l=>{n[i]=l,r=r|a,r===o&&Pe(t,n)})}),function(s,i){switch(s){case wr:{Qi(t);return}case Mn:return r===o&&i(n),Qe(t,i)}}}function Te(e,t=Td){return W(e,ct(t))}function ea(...e){return function(t,n){switch(t){case wr:return;case Mn:return Sw(...e.map(r=>Qe(r,n)))}}}var Ft=(e=>(e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR",e))(Ft||{});const Aw={0:"debug",3:"error",1:"log",2:"warn"},Nw=()=>typeof globalThis>"u"?window:globalThis,Rn=Ke(()=>{const e=ee(3);return{log:ee((t,n,r=1)=>{var o;const s=(o=Nw().VIRTUOSO_LOG_LEVEL)!=null?o:vt(e);r>=s&&console[Aw[r]]("%creact-virtuoso: %c%s %o","color: #0253b3; font-weight: bold","color: initial",t,n)}),logLevel:e}},[],{singleton:!0});function Jn(e,t,n){return ta(e,t,n).callbackRef}function ta(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 _w(e,t,n,r,o,s,i,a,l){const c=w.useCallback(d=>{const f=jw(d.children,t,a?"offsetWidth":"offsetHeight",o);let p=d.parentElement;for(;!p.dataset.virtuosoScroller;)p=p.parentElement;const h=p.lastElementChild.dataset.viewportType==="window";let m;h&&(m=p.ownerDocument.defaultView);const g=i?a?i.scrollLeft:i.scrollTop:h?a?m.scrollX||m.document.documentElement.scrollLeft:m.scrollY||m.document.documentElement.scrollTop:a?p.scrollLeft:p.scrollTop,y=i?a?i.scrollWidth:i.scrollHeight:h?a?m.document.documentElement.scrollWidth:m.document.documentElement.scrollHeight:a?p.scrollWidth:p.scrollHeight,x=i?a?i.offsetWidth:i.offsetHeight:h?a?m.innerWidth:m.innerHeight:a?p.offsetWidth:p.offsetHeight;r({scrollHeight:y,scrollTop:Math.max(g,0),viewportHeight:x}),s==null||s(a?kd("column-gap",getComputedStyle(d).columnGap,o):kd("row-gap",getComputedStyle(d).rowGap,o)),f!==null&&e(f)},[e,t,o,s,i,r,a]);return ta(c,n,l)}function jw(e,t,n,r){const o=e.length;if(o===0)return null;const s=[];for(let i=0;i<o;i++){const a=e.item(i);if(a.dataset.index===void 0)continue;const l=parseInt(a.dataset.index),c=parseFloat(a.dataset.knownSize),d=t(a,n);if(d===0&&r("Zero-sized element, this should not happen",{child:a},Ft.ERROR),d===c)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 kd(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Ft.WARN),t==="normal"?0:parseInt(t??"0",10)}function Id(e,t,n){const r=w.useRef(null),o=w.useCallback(l=>{if(!(l!=null&&l.offsetParent))return;const c=l.getBoundingClientRect(),d=c.width;let f,p;if(t){const h=t.getBoundingClientRect(),m=c.top-h.top;p=h.height-Math.max(0,m),f=m+t.scrollTop}else{const h=i.current.ownerDocument.defaultView;p=h.innerHeight-Math.max(0,c.top),f=c.top+h.scrollY}r.current={offsetTop:f,visibleHeight:p,visibleWidth:d},e(r.current)},[e,t]),{callbackRef:s,ref:i}=ta(o,!0,n),a=w.useCallback(()=>{o(i.current)},[o,i]);return w.useEffect(()=>{var l;if(t){t.addEventListener("scroll",a);const c=new ResizeObserver(()=>{requestAnimationFrame(a)});return c.observe(t),()=>{t.removeEventListener("scroll",a),c.unobserve(t)}}else{const c=(l=i.current)==null?void 0:l.ownerDocument.defaultView;return c==null||c.addEventListener("scroll",a),c==null||c.addEventListener("resize",a),()=>{c==null||c.removeEventListener("scroll",a),c==null||c.removeEventListener("resize",a)}}},[a,t,i]),s}const Ot=Ke(()=>{const e=ze(),t=ze(),n=ee(0),r=ze(),o=ee(0),s=ze(),i=ze(),a=ee(0),l=ee(0),c=ee(0),d=ee(0),f=ze(),p=ze(),h=ee(!1),m=ee(!1),g=ee(!1);return he(W(e,ce(({scrollTop:y})=>y)),t),he(W(e,ce(({scrollHeight:y})=>y)),i),he(t,o),{deviation:n,fixedFooterHeight:c,fixedHeaderHeight:l,footerHeight:d,headerHeight:a,horizontalDirection:m,scrollBy:p,scrollContainerState:e,scrollHeight:i,scrollingInProgress:h,scrollTo:f,scrollTop:t,skipAnimationFrameInResizeObserver:g,smoothScrollTargetReached:r,statefulScrollTop:o,viewportHeight:s}},[],{singleton:!0}),Kr={lvl:0};function Ed(e,t){const n=e.length;if(n===0)return[];let{index:r,value:o}=t(e[0]);const s=[];for(let i=1;i<n;i++){const{index:a,value:l}=t(e[i]);s.push({end:a-1,start:r,value:o}),r=a,o=l}return s.push({end:1/0,start:r,value:o}),s}function ot(e){return e===Kr}function qr(e,t){if(!ot(e))return t===e.k?e.v:t<e.k?qr(e.l,t):qr(e.r,t)}function an(e,t,n="k"){if(ot(e))return[-1/0,void 0];if(Number(e[n])===t)return[e.k,e.v];if(Number(e[n])<t){const r=an(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return an(e.l,t,n)}function Ht(e,t,n){return ot(e)?_d(t,n,1):t===e.k?wt(e,{k:t,v:n}):t<e.k?jd(wt(e,{l:Ht(e.l,t,n)})):jd(wt(e,{r:Ht(e.r,t,n)}))}function Cr(){return Kr}function ds(e,t,n){if(ot(e))return[];const r=an(e,t)[0];return Mw(ra(e,r,n))}function na(e,t){if(ot(e))return Kr;const{k:n,l:r,r:o}=e;if(t===n){if(ot(r))return o;if(ot(o))return r;{const[s,i]=Nd(r);return fs(wt(e,{k:s,l:Ad(r),v:i}))}}else return t<n?fs(wt(e,{l:na(r,t)})):fs(wt(e,{r:na(o,t)}))}function Zn(e){return ot(e)?[]:[...Zn(e.l),{k:e.k,v:e.v},...Zn(e.r)]}function ra(e,t,n){if(ot(e))return[];const{k:r,l:o,r:s,v:i}=e;let a=[];return r>t&&(a=a.concat(ra(o,t,n))),r>=t&&r<=n&&a.push({k:r,v:i}),r<=n&&(a=a.concat(ra(s,t,n))),a}function fs(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(oa(t))return Md(wt(e,{lvl:n-1}));if(!ot(t)&&!ot(t.r))return wt(t.r,{l:wt(t,{r:t.r.l}),lvl:n,r:wt(e,{l:t.r.r,lvl:n-1})});throw new Error("Unexpected empty nodes")}else{if(oa(e))return sa(wt(e,{lvl:n-1}));if(!ot(r)&&!ot(r.l)){const o=r.l,s=oa(o)?r.lvl-1:r.lvl;return wt(o,{l:wt(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:sa(wt(r,{l:o.r,lvl:s}))})}else throw new Error("Unexpected empty nodes")}}function wt(e,t){return _d(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 Ad(e){return ot(e.r)?e.l:fs(wt(e,{r:Ad(e.r)}))}function oa(e){return ot(e)||e.lvl>e.r.lvl}function Nd(e){return ot(e.r)?[e.k,e.v]:Nd(e.r)}function _d(e,t,n,r=Kr,o=Kr){return{k:e,l:r,lvl:n,r:o,v:t}}function jd(e){return sa(Md(e))}function Md(e){const{l:t}=e;return!ot(t)&&t.lvl===e.lvl?wt(t,{r:wt(e,{l:t.r})}):e}function sa(e){const{lvl:t,r:n}=e;return!ot(n)&&!ot(n.r)&&n.lvl===t&&n.r.lvl===t?wt(n,{l:wt(e,{r:n.l}),lvl:t+1}):e}function Mw(e){return Ed(e,({k:t,v:n})=>({index:t,value:n}))}function Rd(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function Gr(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}const ia=Ke(()=>({recalcInProgress:ee(!1)}),[],{singleton:!0});function Pd(e,t,n){return e[ps(e,t,n)]}function ps(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 Rw(e,t,n,r){const o=ps(e,t,r),s=ps(e,n,r,o);return e.slice(o,s+1)}function Pn(e,t){return Math.round(e.getBoundingClientRect()[t])}function hs(e){return!ot(e.groupOffsetTree)}function aa({index:e},t){return t===e?0:t<e?-1:1}function Pw(){return{groupIndices:[],groupOffsetTree:Cr(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:Cr()}}function Ow(e,t){let n=ot(e)?0:1/0;for(const r of t){const{endIndex:o,size:s,startIndex:i}=r;if(n=Math.min(n,i),ot(e)){e=Ht(e,0,s);continue}const a=ds(e,i-1,o+1);if(a.some(Uw(r)))continue;let l=!1,c=!1;for(const{end:d,start:f,value:p}of a)l?(o>=f||s===p)&&(e=na(e,f)):(c=p!==s,l=!0),d>o&&o>=f&&p!==s&&(e=Ht(e,o+1,p));c&&(e=Ht(e,i,s))}return[e,n]}function Dw(e){return typeof e.groupIndex<"u"}function Lw({offset:e},t){return t===e?0:t<e?-1:1}function Yr(e,t,n){if(t.length===0)return 0;const{index:r,offset:o,size:s}=Pd(t,e,aa),i=e-r,a=s*i+(i-1)*n+o;return a>0?a+n:a}function Od(e,t){if(!hs(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function Dd(e,t,n){if(Dw(e))return t.groupIndices[e.groupIndex]+1;{const r=e.index==="LAST"?n:e.index;let o=Od(r,t);return o=Math.max(0,o,Math.min(n,o)),o}}function $w(e,t,n,r=0){return r>0&&(t=Math.max(t,Pd(e,r,aa).offset)),Ed(Rw(e,t,n,Lw),zw)}function Fw(e,[t,n,r,o]){t.length>0&&r("received item sizes",t,Ft.DEBUG);const s=e.sizeTree;let i=s,a=0;if(n.length>0&&ot(s)&&t.length===2){const p=t[0].size,h=t[1].size;i=n.reduce((m,g)=>Ht(Ht(m,g,p),g+1,h),i)}else[i,a]=Ow(i,t);if(i===s)return e;const{lastIndex:l,lastOffset:c,lastSize:d,offsetTree:f}=la(e.offsetTree,a,i,o);return{groupIndices:n,groupOffsetTree:n.reduce((p,h)=>Ht(p,h,Yr(h,f,o)),Cr()),lastIndex:l,lastOffset:c,lastSize:d,offsetTree:f,sizeTree:i}}function Bw(e){return Zn(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 Ld(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 la(e,t,n,r){let o=e,s=0,i=0,a=0,l=0;if(t!==0){l=ps(o,t-1,aa),a=o[l].offset;const c=an(n,t-1);s=c[0],i=c[1],o.length&&o[l].size===an(n,t)[1]&&(l-=1),o=o.slice(0,l+1)}else o=[];for(const{start:c,value:d}of ds(n,t,1/0)){const f=c-s,p=f*i+a+f*r;o.push({index:c,offset:p,size:d}),s=c,a=p,i=d}return{lastIndex:s,lastOffset:a,lastSize:i,offsetTree:o}}function zw(e){return{index:e.index,value:e}}function Uw(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 Hw={offsetHeight:"height",offsetWidth:"width"},vn=Ke(([{log:e},{recalcInProgress:t}])=>{const n=ze(),r=ze(),o=Et(r,0),s=ze(),i=ze(),a=ee(0),l=ee([]),c=ee(void 0),d=ee(void 0),f=ee((S,T)=>Pn(S,Hw[T])),p=ee(void 0),h=ee(0),m=Pw(),g=Et(W(n,Le(l,e,h),yn(Fw,m),ct()),m),y=Et(W(l,ct(),yn((S,T)=>({current:T,prev:S.current}),{current:[],prev:[]}),ce(({prev:S})=>S)),[]);he(W(l,ke(S=>S.length>0),Le(g,h),ce(([S,T,I])=>{const A=S.reduce((_,L,R)=>Ht(_,L,Yr(L,T.offsetTree,I)||R),Cr());return{...T,groupIndices:S,groupOffsetTree:A}})),g),he(W(r,Le(g),ke(([S,{lastIndex:T}])=>S<T),ce(([S,{lastIndex:T,lastSize:I}])=>[{endIndex:T,size:I,startIndex:S}])),n),he(c,d);const x=Et(W(c,ce(S=>S===void 0)),!0);he(W(d,ke(S=>S!==void 0&&ot(vt(g).sizeTree)),ce(S=>[{endIndex:0,size:S,startIndex:0}])),n);const b=Ut(W(n,Le(g),yn(({sizes:S},[T,I])=>({changed:I!==S,sizes:I}),{changed:!1,sizes:m}),ce(S=>S.changed)));Qe(W(a,yn((S,T)=>({diff:S.prev-T,prev:T}),{diff:0,prev:0}),ce(S=>S.diff)),S=>{const{groupIndices:T}=vt(g);if(S>0)Pe(t,!0),Pe(s,S+Ld(S,T));else if(S<0){const I=vt(y);I.length>0&&(S-=Ld(-S,I)),Pe(i,S)}}),Qe(W(a,Le(e)),([S,T])=>{S<0&&T("`firstItemIndex` prop should not be set to less than zero. If you don't know the total count, just use a very high value",{firstItemIndex:a},Ft.ERROR)});const C=Ut(s);he(W(s,Le(g),ce(([S,T])=>{const I=T.groupIndices.length>0,A=[],_=T.lastSize;if(I){const L=qr(T.sizeTree,0);let R=0,O=0;for(;R<S;){const N=T.groupIndices[O],B=T.groupIndices.length===O+1?1/0:T.groupIndices[O+1]-N-1;A.push({endIndex:N,size:L,startIndex:N}),A.push({endIndex:N+1+B-1,size:_,startIndex:N+1}),O++,R+=B+1}const F=Zn(T.sizeTree);return R!==S&&F.shift(),F.reduce((N,{k:B,v:j})=>{let K=N.ranges;return N.prevSize!==0&&(K=[...N.ranges,{endIndex:B+S-1,size:N.prevSize,startIndex:N.prevIndex}]),{prevIndex:B+S,prevSize:j,ranges:K}},{prevIndex:S,prevSize:0,ranges:A}).ranges}return Zn(T.sizeTree).reduce((L,{k:R,v:O})=>({prevIndex:R+S,prevSize:O,ranges:[...L.ranges,{endIndex:R+S-1,size:L.prevSize,startIndex:L.prevIndex}]}),{prevIndex:0,prevSize:_,ranges:[]}).ranges})),n);const k=Ut(W(i,Le(g,h),ce(([S,{offsetTree:T},I])=>{const A=-S;return Yr(A,T,I)})));return he(W(i,Le(g,h),ce(([S,T,I])=>{if(T.groupIndices.length>0){if(ot(T.sizeTree))return T;let A=Cr();const _=vt(y);let L=0,R=0,O=0;for(;L<-S;){O=_[R];const F=_[R+1]-O-1;R++,L+=F+1}if(A=Zn(T.sizeTree).reduce((F,{k:N,v:B})=>Ht(F,Math.max(0,N+S),B),A),L!==-S){const F=qr(T.sizeTree,O);A=Ht(A,0,F);const N=an(T.sizeTree,-S+1)[1];A=Ht(A,1,N)}return{...T,sizeTree:A,...la(T.offsetTree,0,A,I)}}else{const A=Zn(T.sizeTree).reduce((_,{k:L,v:R})=>Ht(_,Math.max(0,L+S),R),Cr());return{...T,sizeTree:A,...la(T.offsetTree,0,A,I)}}})),g),{beforeUnshiftWith:C,data:p,defaultItemSize:d,firstItemIndex:a,fixedItemSize:c,gap:h,groupIndices:l,itemSize:f,listRefresh:b,shiftWith:i,shiftWithOffset:k,sizeRanges:n,sizes:g,statefulTotalCount:o,totalCount:r,trackItemSizes:x,unshiftWith:s}},lt(Rn,ia),{singleton:!0});function Ww(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const $d=Ke(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=ze(),i=ze(),a=Ut(W(s,ce(Ww)));return he(W(a,ce(l=>l.totalCount)),n),he(W(a,ce(l=>l.groupIndices)),e),he(W(bt(o,t,r),ke(([l,c])=>hs(c)),ce(([l,c,d])=>an(c.groupOffsetTree,Math.max(l-d,0),"v")[0]),ct(),ce(l=>[l])),i),{groupCounts:s,topItemsIndexes:i}},lt(vn,Ot)),On=Ke(([{log:e}])=>{const t=ee(!1),n=Ut(W(t,ke(r=>r),ct()));return Qe(t,r=>{r&&vt(e)("props updated",{},Ft.DEBUG)}),{didMount:n,propsReady:t}},lt(Rn),{singleton:!0}),Vw=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function Fd(e){const t=typeof e=="number"?{index:e}:e;return t.align||(t.align="start"),(!t.behavior||!Vw)&&(t.behavior="auto"),t.offset||(t.offset=0),t}const Xr=Ke(([{gap:e,listRefresh:t,sizes:n,totalCount:r},{fixedFooterHeight:o,fixedHeaderHeight:s,footerHeight:i,headerHeight:a,scrollingInProgress:l,scrollTo:c,smoothScrollTargetReached:d,viewportHeight:f},{log:p}])=>{const h=ze(),m=ze(),g=ee(0);let y=null,x=null,b=null;function C(){y&&(y(),y=null),b&&(b(),b=null),x&&(clearTimeout(x),x=null),Pe(l,!1)}return he(W(h,Le(n,f,r,g,a,i,p),Le(e,s,o),ce(([[k,S,T,I,A,_,L,R],O,F,N])=>{const B=Fd(k),{align:j,behavior:K,offset:z}=B,M=I-1,G=Dd(B,S,M);let X=Yr(G,S.offsetTree,O)+_;j==="end"?(X+=F+an(S.sizeTree,G)[1]-T+N,G===M&&(X+=L)):j==="center"?X+=(F+an(S.sizeTree,G)[1]-T+N)/2:X-=A,z&&(X+=z);const se=be=>{C(),be?(R("retrying to scroll to",{location:k},Ft.DEBUG),Pe(h,k)):(Pe(m,!0),R("list did not change, scroll successful",{},Ft.DEBUG))};if(C(),K==="smooth"){let be=!1;b=Qe(t,Ie=>{be=be||Ie}),y=sn(d,()=>{se(be)})}else y=sn(W(t,Kw(150)),se);return x=setTimeout(()=>{C()},1200),Pe(l,!0),R("scrolling from index to",{behavior:K,index:G,top:X},Ft.DEBUG),{behavior:K,top:X}})),c),{scrollTargetReached:m,scrollToIndex:h,topListHeight:g}},lt(vn,Ot,Rn),{singleton:!0});function Kw(e){return t=>{const n=setTimeout(()=>{t(!1)},e);return r=>{r&&(t(!0),clearTimeout(n))}}}function ca(e,t){e==0?t():requestAnimationFrame(()=>{ca(e-1,t)})}function ua(e,t){const n=t-1;return typeof e=="number"?e:e.index==="LAST"?n:e.index}const Jr=Ke(([{defaultItemSize:e,listRefresh:t,sizes:n},{scrollTop:r},{scrollTargetReached:o,scrollToIndex:s},{didMount:i}])=>{const a=ee(!0),l=ee(0),c=ee(!0);return he(W(i,Le(l),ke(([d,f])=>!!f),xn(!1)),a),he(W(i,Le(l),ke(([d,f])=>!!f),xn(!1)),c),Qe(W(bt(t,i),Le(a,n,e,c),ke(([[,d],f,{sizeTree:p},h,m])=>d&&(!ot(p)||Zi(h))&&!f&&!m),Le(l)),([,d])=>{sn(o,()=>{Pe(c,!0)}),ca(4,()=>{sn(r,()=>{Pe(a,!0)}),Pe(s,d)})}),{initialItemFinalLocationReached:c,initialTopMostItemIndex:l,scrolledToInitialItem:a}},lt(vn,Ot,Xr,On),{singleton:!0});function Bd(e,t){return Math.abs(e-t)<1.01}const Zr="up",Qr="down",qw="none",Gw={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},Yw=0,eo=Ke(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:o,viewportHeight:s}])=>{const i=ee(!1),a=ee(!0),l=ze(),c=ze(),d=ee(4),f=ee(Yw),p=Et(W(ea(W(Te(o),Xn(1),xn(!0)),W(Te(o),Xn(1),xn(!1),Cd(100))),ct()),!1),h=Et(W(ea(W(n,xn(!0)),W(n,xn(!1),Cd(200))),ct()),!1);he(W(bt(Te(o),Te(f)),ce(([b,C])=>b<=C),ct()),a),he(W(a,In(50)),c);const m=Ut(W(bt(r,Te(s),Te(t),Te(e),Te(d)),yn((b,[{scrollHeight:C,scrollTop:k},S,T,I,A])=>{const _=k+S-C>-A,L={scrollHeight:C,scrollTop:k,viewportHeight:S};if(_){let O,F;return k>b.state.scrollTop?(O="SCROLLED_DOWN",F=b.state.scrollTop-k):(O="SIZE_DECREASED",F=b.state.scrollTop-k||b.scrollTopDelta),{atBottom:!0,atBottomBecause:O,scrollTopDelta:F,state:L}}let R;return L.scrollHeight>b.state.scrollHeight?R="SIZE_INCREASED":S<b.state.viewportHeight?R="VIEWPORT_HEIGHT_DECREASING":k<b.state.scrollTop?R="SCROLLING_UPWARDS":R="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:R,state:L}},Gw),ct((b,C)=>b&&b.atBottom===C.atBottom))),g=Et(W(r,yn((b,{scrollHeight:C,scrollTop:k,viewportHeight:S})=>{if(Bd(b.scrollHeight,C))return{changed:!1,jump:0,scrollHeight:C,scrollTop:k};{const T=C-(k+S)<1;return b.scrollTop!==k&&T?{changed:!0,jump:b.scrollTop-k,scrollHeight:C,scrollTop:k}:{changed:!0,jump:0,scrollHeight:C,scrollTop:k}}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),ke(b=>b.changed),ce(b=>b.jump)),0);he(W(m,ce(b=>b.atBottom)),i),he(W(i,In(50)),l);const y=ee(Qr);he(W(r,ce(({scrollTop:b})=>b),ct(),yn((b,C)=>vt(h)?{direction:b.direction,prevScrollTop:C}:{direction:C<b.prevScrollTop?Zr:Qr,prevScrollTop:C},{direction:Qr,prevScrollTop:0}),ce(b=>b.direction)),y),he(W(r,In(50),xn(qw)),y);const x=ee(0);return he(W(p,ke(b=>!b),xn(0)),x),he(W(o,In(100),Le(p),ke(([b,C])=>!!C),yn(([b,C],[k])=>[C,k],[0,0]),ce(([b,C])=>C-b)),x),{atBottomState:m,atBottomStateChange:l,atBottomThreshold:d,atTopStateChange:c,atTopThreshold:f,isAtBottom:i,isAtTop:a,isScrolling:p,lastJumpDueToItemResize:g,scrollDirection:y,scrollVelocity:x}},lt(Ot)),ms="top",gs="bottom",zd="none";function Ud(e,t,n){return typeof e=="number"?n===Zr&&t===ms||n===Qr&&t===gs?e:0:n===Zr?t===ms?e.main:e.reverse:t===gs?e.main:e.reverse}function Hd(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const da=Ke(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:o}])=>{const s=ze(),i=ee(0),a=ee(0),l=ee(0),c=Et(W(bt(Te(r),Te(o),Te(n),Te(s,Gr),Te(l),Te(i),Te(t),Te(e),Te(a)),ce(([d,f,p,[h,m],g,y,x,b,C])=>{const k=d-b,S=y+x,T=Math.max(p-k,0);let I=zd;const A=Hd(C,ms),_=Hd(C,gs);return h-=b,h+=p+x,m+=p+x,m-=b,h>d+S-A&&(I=Zr),m<d-T+f+_&&(I=Qr),I!==zd?[Math.max(k-p-Ud(g,ms,I)-A,0),k-T-x+f+Ud(g,gs,I)+_]:null}),ke(d=>d!=null),ct(Gr)),[0,0]);return{increaseViewportBy:a,listBoundary:s,overscan:l,topListHeight:i,visibleRange:c}},lt(Ot),{singleton:!0});function Xw(e,t,n){if(hs(t)){const r=Od(e,t);return[{index:an(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 fa={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function xs(e,t,n,r,o,s){const{lastIndex:i,lastOffset:a,lastSize:l}=o;let c=0,d=0;if(e.length>0){c=e[0].offset;const g=e[e.length-1];d=g.offset+g.size}const f=n-i,p=a+f*l+(f-1)*r,h=c,m=p-d;return{bottom:d,firstItemIndex:s,items:Vd(e,o,s),offsetBottom:m,offsetTop:c,top:h,topItems:Vd(t,o,s),topListHeight:t.reduce((g,y)=>y.size+g,0),totalCount:n}}function Wd(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=ua(t,a),c=Array.from({length:a}).map((d,f)=>({data:s[f+l],index:f+l,offset:0,size:0}));return xs(c,[],a,o,n,r)}function Vd(e,t,n){if(e.length===0)return[];if(!hs(t))return e.map(c=>({...c,index:c.index+n,originalIndex:c.index}));const r=e[0].index,o=e[e.length-1].index,s=[],i=ds(t.groupOffsetTree,r,o);let a,l=0;for(const c of e){(!a||a.end<c.index)&&(a=i.shift(),l=t.groupIndices.indexOf(a.start));let d;c.index===a.start?d={index:l,type:"group"}:d={groupIndex:l,index:c.index-(l+1)+n},s.push({...d,data:c.data,offset:c.offset,originalIndex:c.index,size:c.size})}return s}const Qn=Ke(([{data:e,firstItemIndex:t,gap:n,sizes:r,totalCount:o},s,{listBoundary:i,topListHeight:a,visibleRange:l},{initialTopMostItemIndex:c,scrolledToInitialItem:d},{topListHeight:f},p,{didMount:h},{recalcInProgress:m}])=>{const g=ee([]),y=ee(0),x=ze();he(s.topItemsIndexes,g);const b=Et(W(bt(h,m,Te(l,Gr),Te(o),Te(r),Te(c),d,Te(g),Te(t),Te(n),e),ke(([T,I,,A,,,,,,,_])=>{const L=_&&_.length!==A;return T&&!I&&!L}),ce(([,,[T,I],A,_,L,R,O,F,N,B])=>{const j=_,{offsetTree:K,sizeTree:z}=j,M=vt(y);if(A===0)return{...fa,totalCount:A};if(T===0&&I===0)return M===0?{...fa,totalCount:A}:Wd(M,L,_,F,N,B||[]);if(ot(z))return M>0?null:xs(Xw(ua(L,A),j,B),[],A,N,j,F);const G=[];if(O.length>0){const Y=O[0],U=O[O.length-1];let J=0;for(const $ of ds(z,Y,U)){const q=$.value,Z=Math.max($.start,Y),ue=Math.min($.end,U);for(let ie=Z;ie<=ue;ie++)G.push({data:B==null?void 0:B[ie],index:ie,offset:J,size:q}),J+=q}}if(!R)return xs([],G,A,N,j,F);const X=O.length>0?O[O.length-1]+1:0,se=$w(K,T,I,X);if(se.length===0)return null;const be=A-1,Ie=us([],Y=>{for(const U of se){const J=U.value;let $=J.offset,q=U.start;const Z=J.size;if(J.offset<T){q+=Math.floor((T-J.offset+N)/(Z+N));const ie=q-U.start;$+=ie*Z+ie*N}q<X&&($+=(X-q)*Z,q=X);const ue=Math.min(U.end,be);for(let ie=q;ie<=ue&&!($>=I);ie++)Y.push({data:B==null?void 0:B[ie],index:ie,offset:$,size:Z}),$+=Z+N}});return xs(Ie,G,A,N,j,F)}),ke(T=>T!==null),ct()),fa);he(W(e,ke(Zi),ce(T=>T==null?void 0:T.length)),o),he(W(b,ce(T=>T.topListHeight)),f),he(f,a),he(W(b,ce(T=>[T.top,T.bottom])),i),he(W(b,ce(T=>T.items)),x);const C=Ut(W(b,ke(({items:T})=>T.length>0),Le(o,e),ke(([{items:T},I])=>T[T.length-1].originalIndex===I-1),ce(([,T,I])=>[T-1,I]),ct(Gr),ce(([T])=>T))),k=Ut(W(b,In(200),ke(({items:T,topItems:I})=>T.length>0&&T[0].originalIndex===I.length),ce(({items:T})=>T[0].index),ct())),S=Ut(W(b,ke(({items:T})=>T.length>0),ce(({items:T})=>{let I=0,A=T.length-1;for(;T[I].type==="group"&&I<A;)I++;for(;T[A].type==="group"&&A>I;)A--;return{endIndex:T[A].index,startIndex:T[I].index}}),ct(Rd)));return{endReached:C,initialItemCount:y,itemsRendered:x,listState:b,rangeChanged:S,startReached:k,topItemsIndexes:g,...p}},lt(vn,$d,da,Jr,Xr,eo,On,ia),{singleton:!0}),Kd=Ke(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:o}])=>{const s=ze(),i=Et(W(bt(n,e,r,t,o),ce(([a,l,c,d,f])=>a+l+c+d+f.offsetBottom+f.bottom)),0);return he(Te(i),s),{totalListHeight:i,totalListHeightChanged:s}},lt(Ot,Qn),{singleton:!0}),Jw=Ke(([{viewportHeight:e},{totalListHeight:t}])=>{const n=ee(!1),r=Et(W(bt(n,e,t),ke(([o])=>o),ce(([,o,s])=>Math.max(0,o-s)),In(0),ct()),0);return{alignToBottom:n,paddingTopAddition:r}},lt(Ot,Kd),{singleton:!0}),qd=Ke(()=>({context:ee(null)})),Zw=({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,Gd=Ke(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:s,scrollingInProgress:i,scrollTop:a,viewportHeight:l},{scrollToIndex:c}])=>{const d=ze();return he(W(d,Le(t,l,n,s,o,r,a),Le(e),ce(([[f,p,h,m,g,y,x,b],C])=>{const{align:k,behavior:S,calculateViewLocation:T=Zw,done:I,...A}=f,_=Dd(f,p,m-1),L=Yr(_,p.offsetTree,C)+g+y,R=L+an(p.sizeTree,_)[1],O=b+y,F=b+h-x,N=T({itemBottom:R,itemTop:L,locationParams:{align:k,behavior:S,...A},viewportBottom:F,viewportTop:O});return N?I&&sn(W(i,ke(B=>!B),Xn(vt(i)?1:2)),I):I&&I(),N}),ke(f=>f!==null)),c),{scrollIntoView:d}},lt(vn,Ot,Xr,Qn,Rn),{singleton:!0});function Yd(e){return e?e==="smooth"?"smooth":"auto":!1}const Qw=(e,t)=>typeof e=="function"?Yd(e(t)):t&&Yd(e),e0=Ke(([{listRefresh:e,totalCount:t,fixedItemSize:n,data:r},{atBottomState:o,isAtBottom:s},{scrollToIndex:i},{scrolledToInitialItem:a},{didMount:l,propsReady:c},{log:d},{scrollingInProgress:f},{context:p},{scrollIntoView:h}])=>{const m=ee(!1),g=ze();let y=null;function x(S){Pe(i,{align:"end",behavior:S,index:"LAST"})}Qe(W(bt(W(Te(t),Xn(1)),l),Le(Te(m),s,a,f),ce(([[S,T],I,A,_,L])=>{let R=T&&_,O="auto";return R&&(O=Qw(I,A||L),R=R&&!!O),{followOutputBehavior:O,shouldFollow:R,totalCount:S}}),ke(({shouldFollow:S})=>S)),({followOutputBehavior:S,totalCount:T})=>{y&&(y(),y=null),vt(n)?requestAnimationFrame(()=>{vt(d)("following output to ",{totalCount:T},Ft.DEBUG),x(S)}):y=sn(e,()=>{vt(d)("following output to ",{totalCount:T},Ft.DEBUG),x(S),y=null})});function b(S){const T=sn(o,I=>{S&&!I.atBottom&&I.notAtBottomBecause==="SIZE_INCREASED"&&!y&&(vt(d)("scrolling to bottom due to increased size",{},Ft.DEBUG),x("auto"))});setTimeout(T,100)}Qe(W(bt(Te(m),t,c),ke(([S,,T])=>S&&T),yn(({value:S},[,T])=>({refreshed:S===T,value:T}),{refreshed:!1,value:0}),ke(({refreshed:S})=>S),Le(m,t)),([,S])=>{vt(a)&&b(S!==!1)}),Qe(g,()=>{b(vt(m)!==!1)}),Qe(bt(Te(m),o),([S,T])=>{S&&!T.atBottom&&T.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&x("auto")});const C=ee(null),k=ze();return he(ea(W(Te(r),ce(S=>{var T;return(T=S==null?void 0:S.length)!=null?T:0})),W(Te(t))),k),Qe(W(bt(W(k,Xn(1)),l),Le(Te(C),a,f,p),ce(([[S,T],I,A,_,L])=>T&&A&&(I==null?void 0:I({context:L,totalCount:S,scrollingInProgress:_}))),ke(S=>!!S),In(0)),S=>{y&&(y(),y=null),vt(n)?requestAnimationFrame(()=>{vt(d)("scrolling into view",{}),Pe(h,S)}):y=sn(e,()=>{vt(d)("scrolling into view",{}),Pe(h,S),y=null})}),{autoscrollToBottom:g,followOutput:m,scrollIntoViewOnChange:C}},lt(vn,eo,Xr,Jr,On,Rn,Ot,qd,Gd)),t0=Ke(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:s,listState:i},{didMount:a}])=>(he(W(a,Le(s),ke(([,l])=>l!==0),Le(o,r,t,n,e),ce(([[,l],c,d,f,p,h=[]])=>Wd(l,c,d,f,p,h))),i),{}),lt(vn,Jr,Qn,On),{singleton:!0}),n0=Ke(([{didMount:e},{scrollTo:t},{listState:n}])=>{const r=ee(0);return Qe(W(e,Le(r),ke(([,o])=>o!==0),ce(([,o])=>({top:o}))),o=>{sn(W(n,Xn(1),ke(s=>s.items.length>1)),()=>{requestAnimationFrame(()=>{Pe(t,o)})})}),{initialScrollTop:r}},lt(On,Ot,Qn),{singleton:!0}),Xd=Ke(([{scrollVelocity:e}])=>{const t=ee(!1),n=ze(),r=ee(!1);return he(W(e,Le(r,t,n),ke(([o,s])=>!!s),ce(([o,s,i,a])=>{const{enter:l,exit:c}=s;if(i){if(c(o,a))return!1}else if(l(o,a))return!0;return i}),ct()),t),Qe(W(bt(t,e,n),Le(r)),([[o,s,i],a])=>{o&&a&&a.change&&a.change(s,i)}),{isSeeking:t,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:e}},lt(eo),{singleton:!0}),pa=Ke(([{scrollContainerState:e,scrollTo:t}])=>{const n=ze(),r=ze(),o=ze(),s=ee(!1),i=ee(void 0);return he(W(bt(n,r),ce(([{scrollHeight:a,scrollTop:l,viewportHeight:c},{offsetTop:d}])=>({scrollHeight:a,scrollTop:Math.max(0,l-d),viewportHeight:c}))),e),he(W(t,Le(r),ce(([a,{offsetTop:l}])=>({...a,top:a.top+l}))),o),{customScrollParent:i,useWindowScroll:s,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:r}},lt(Ot)),r0=Ke(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:o},{didMount:s},{useWindowScroll:i,windowScrollContainerState:a,windowViewportRect:l}])=>{const c=ze(),d=ee(void 0),f=ee(null),p=ee(null);return he(a,f),he(l,p),Qe(W(c,Le(t,r,i,f,p,n)),([h,m,g,y,x,b,C])=>{const k=Bw(m.sizeTree);y&&x!==null&&b!==null&&(g=x.scrollTop-b.offsetTop),g-=C,h({ranges:k,scrollTop:g})}),he(W(d,ke(Zi),ce(o0)),o),he(W(s,Le(d),ke(([,h])=>h!==void 0),ct(),ce(([,h])=>h.ranges)),e),{getState:c,restoreStateFrom:d}},lt(vn,Ot,Jr,On,pa));function o0(e){return{align:"start",index:0,offset:e.scrollTop}}const s0=Ke(([{topItemsIndexes:e}])=>{const t=ee(0);return he(W(t,ke(n=>n>=0),ce(n=>Array.from({length:n}).map((r,o)=>o))),e),{topItemCount:t}},lt(Qn));function Jd(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const i0=Jd(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),a0=Ke(([{deviation:e,scrollBy:t,scrollingInProgress:n,scrollTop:r},{isAtBottom:o,isScrolling:s,lastJumpDueToItemResize:i,scrollDirection:a},{listState:l},{beforeUnshiftWith:c,gap:d,shiftWithOffset:f,sizes:p},{log:h},{recalcInProgress:m}])=>{const g=Ut(W(l,Le(i),yn(([,x,b,C],[{bottom:k,items:S,offsetBottom:T,totalCount:I},A])=>{const _=k+T;let L=0;return b===I&&x.length>0&&S.length>0&&(S[0].originalIndex===0&&x[0].originalIndex===0||(L=_-C,L!==0&&(L+=A))),[L,S,I,_]},[0,[],0,0]),ke(([x])=>x!==0),Le(r,a,n,o,h,m),ke(([,x,b,C,,,k])=>!k&&!C&&x!==0&&b===Zr),ce(([[x],,,,,b])=>(b("Upward scrolling compensation",{amount:x},Ft.DEBUG),x))));function y(x){x>0?(Pe(t,{behavior:"auto",top:-x}),Pe(e,0)):(Pe(e,0),Pe(t,{behavior:"auto",top:-x}))}return Qe(W(g,Le(e,s)),([x,b,C])=>{C&&i0()?Pe(e,b-x):y(-x)}),Qe(W(bt(Et(s,!1),e,m),ke(([x,b,C])=>!x&&!C&&b!==0),ce(([x,b])=>b),In(1)),y),he(W(f,ce(x=>({top:-x}))),t),Qe(W(c,Le(p,d),ce(([x,{groupIndices:b,lastSize:C,sizeTree:k},S])=>{function T(I){return I*(C+S)}if(b.length===0)return T(x);{let I=0;const A=qr(k,0);let _=0,L=0;for(;_<x;){_++,I+=A;let R=b.length===L+1?1/0:b[L+1]-b[L]-1;_+R>x&&(I-=A,R=x-_+1),_+=R,I+=T(R),L++}return I}})),x=>{Pe(e,x),requestAnimationFrame(()=>{Pe(t,{top:x}),requestAnimationFrame(()=>{Pe(e,0),Pe(m,!1)})})}),{deviation:e}},lt(Ot,eo,Qn,vn,Rn,ia)),l0=Ke(([e,t,n,r,o,s,i,a,l,c,d])=>({...e,...t,...n,...r,...o,...s,...i,...a,...l,...c,...d}),lt(da,t0,On,Xd,Kd,n0,Jw,pa,Gd,Rn,qd)),Zd=Ke(([{data:e,defaultItemSize:t,firstItemIndex:n,fixedItemSize:r,gap:o,groupIndices:s,itemSize:i,sizeRanges:a,sizes:l,statefulTotalCount:c,totalCount:d,trackItemSizes:f},{initialItemFinalLocationReached:p,initialTopMostItemIndex:h,scrolledToInitialItem:m},g,y,x,{listState:b,topItemsIndexes:C,...k},{scrollToIndex:S},T,{topItemCount:I},{groupCounts:A},_])=>(he(k.rangeChanged,_.scrollSeekRangeChanged),he(W(_.windowViewportRect,ce(L=>L.visibleHeight)),g.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:n,fixedItemHeight:r,gap:o,groupCounts:A,initialItemFinalLocationReached:p,initialTopMostItemIndex:h,scrolledToInitialItem:m,sizeRanges:a,topItemCount:I,topItemsIndexes:C,totalCount:d,...x,groupIndices:s,itemSize:i,listState:b,scrollToIndex:S,statefulTotalCount:c,trackItemSizes:f,...k,..._,...g,sizes:l,...y}),lt(vn,Jr,Ot,r0,e0,Qn,Xr,a0,s0,$d,l0));function c0(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 ys=typeof document<"u"?w.useLayoutEffect:w.useEffect;function Qd(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(y,x){y.propsReady&&Pe(y.propsReady,!1);for(const b of r){const C=y[t.required[b]];Pe(C,x[b])}for(const b of o)if(b in x){const C=y[t.optional[b]];Pe(C,x[b])}y.propsReady&&Pe(y.propsReady,!0)}function c(y){return s.reduce((x,b)=>(x[b]=C=>{const k=y[t.methods[b]];Pe(k,C)},x),{})}function d(y){return i.reduce((x,b)=>(x[b]=kw(y[t.events[b]]),x),{})}const f=w.forwardRef((y,x)=>{const{children:b,...C}=y,[k]=w.useState(()=>us(Ew(e),I=>{l(I,C)})),[S]=w.useState(Sd(d,k));ys(()=>{for(const I of i)I in C&&Qe(S[I],C[I]);return()=>{Object.values(S).map(Qi)}},[C,S,k]),ys(()=>{l(k,C)}),w.useImperativeHandle(x,bd(c(k)));const T=n;return u.jsx(a.Provider,{value:k,children:n?u.jsx(T,{...c0([...r,...o,...i],C),children:b}):b})}),p=y=>{const x=w.useContext(a);return w.useCallback(b=>{Pe(x[y],b)},[x,y])},h=y=>{const x=w.useContext(a)[y],b=w.useCallback(C=>Qe(x,C),[x]);return w.useSyncExternalStore(b,()=>vt(x),()=>vt(x))},m=y=>{const x=w.useContext(a)[y],[b,C]=w.useState(Sd(vt,x));return ys(()=>Qe(x,k=>{k!==b&&C(bd(k))}),[x,b]),b},g=w.version.startsWith("18")?h:m;return{Component:f,useEmitter:(y,x)=>{const b=w.useContext(a)[y];ys(()=>Qe(b,x),[x,b])},useEmitterValue:g,usePublisher:p}}const ef=w.createContext(void 0),tf=w.createContext(void 0),nf=typeof document<"u"?w.useLayoutEffect:w.useEffect;function ha(e){return"self"in e}function u0(e){return"body"in e}function rf(e,t,n,r=Sr,o,s){const i=w.useRef(null),a=w.useRef(null),l=w.useRef(null),c=w.useCallback(p=>{let h,m,g;const y=p.target;if(u0(y)||ha(y)){const b=ha(y)?y:y.defaultView;g=s?b.scrollX:b.scrollY,h=s?b.document.documentElement.scrollWidth:b.document.documentElement.scrollHeight,m=s?b.innerWidth:b.innerHeight}else g=s?y.scrollLeft:y.scrollTop,h=s?y.scrollWidth:y.scrollHeight,m=s?y.offsetWidth:y.offsetHeight;const x=()=>{e({scrollHeight:h,scrollTop:Math.max(g,0),viewportHeight:m})};p.suppressFlushSync?x():qs.flushSync(x),a.current!==null&&(g===a.current||g<=0||g===h-m)&&(a.current=null,t(!0),l.current&&(clearTimeout(l.current),l.current=null))},[e,t,s]);w.useEffect(()=>{const p=o||i.current;return r(o||i.current),c({suppressFlushSync:!0,target:p}),p.addEventListener("scroll",c,{passive:!0}),()=>{r(null),p.removeEventListener("scroll",c)}},[i,c,n,r,o]);function d(p){const h=i.current;if(!h||(s?"offsetWidth"in h&&h.offsetWidth===0:"offsetHeight"in h&&h.offsetHeight===0))return;const m=p.behavior==="smooth";let g,y,x;ha(h)?(y=Math.max(Pn(h.document.documentElement,s?"width":"height"),s?h.document.documentElement.scrollWidth:h.document.documentElement.scrollHeight),g=s?h.innerWidth:h.innerHeight,x=s?window.scrollX:window.scrollY):(y=h[s?"scrollWidth":"scrollHeight"],g=Pn(h,s?"width":"height"),x=h[s?"scrollLeft":"scrollTop"]);const b=y-g;if(p.top=Math.ceil(Math.max(Math.min(b,p.top),0)),Bd(g,y)||p.top===x){e({scrollHeight:y,scrollTop:x,viewportHeight:g}),m&&t(!0);return}m?(a.current=p.top,l.current&&clearTimeout(l.current),l.current=setTimeout(()=>{l.current=null,a.current=null,t(!0)},1e3)):a.current=null,s&&(p={behavior:p.behavior,left:p.top}),h.scrollTo(p)}function f(p){s&&(p={behavior:p.behavior,left:p.top}),i.current.scrollBy(p)}return{scrollByCallback:f,scrollerRef:i,scrollToCallback:d}}const ma="-webkit-sticky",of="sticky",ga=Jd(()=>{if(typeof document>"u")return of;const e=document.createElement("div");return e.style.position=ma,e.style.position===ma?ma:of});function xa(e){return e}const d0=Ke(()=>{const e=ee(a=>`Item ${a}`),t=ee(a=>`Group ${a}`),n=ee({}),r=ee(xa),o=ee("div"),s=ee(Sr),i=(a,l=null)=>Et(W(n,ce(c=>c[a]),ct()),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")}}),f0=Ke(([e,t])=>({...e,...t}),lt(Zd,d0)),p0=({height:e})=>u.jsx("div",{style:{height:e}}),h0={overflowAnchor:"none",position:ga(),zIndex:1},sf={overflowAnchor:"none"},m0={...sf,display:"inline-block",height:"100%"},af=w.memo(function({showTopList:e=!1}){const t=Ae("listState"),n=Jt("sizeRanges"),r=Ae("useWindowScroll"),o=Ae("customScrollParent"),s=Jt("windowScrollContainerState"),i=Jt("scrollContainerState"),a=o||r?s:i,l=Ae("itemContent"),c=Ae("context"),d=Ae("groupContent"),f=Ae("trackItemSizes"),p=Ae("itemSize"),h=Ae("log"),m=Jt("gap"),g=Ae("horizontalDirection"),{callbackRef:y}=_w(n,p,f,e?Sr:a,h,m,o,g,Ae("skipAnimationFrameInResizeObserver")),[x,b]=w.useState(0);ya("deviation",N=>{x!==N&&b(N)});const C=Ae("EmptyPlaceholder"),k=Ae("ScrollSeekPlaceholder")||p0,S=Ae("ListComponent"),T=Ae("ItemComponent"),I=Ae("GroupComponent"),A=Ae("computeItemKey"),_=Ae("isSeeking"),L=Ae("groupIndices").length>0,R=Ae("alignToBottom"),O=Ae("initialItemFinalLocationReached"),F=e?{}:{boxSizing:"border-box",...g?{display:"inline-block",height:"100%",marginLeft:x!==0?x:R?"auto":0,paddingLeft:t.offsetTop,paddingRight:t.offsetBottom,whiteSpace:"nowrap"}:{marginTop:x!==0?x:R?"auto":0,paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},...O?{}:{visibility:"hidden"}};return!e&&t.totalCount===0&&C?u.jsx(C,{...At(C,c)}):u.jsx(S,{...At(S,c),"data-testid":e?"virtuoso-top-item-list":"virtuoso-item-list",ref:y,style:F,children:(e?t.topItems:t.items).map(N=>{const B=N.originalIndex,j=A(B+t.firstItemIndex,N.data,c);return _?w.createElement(k,{...At(k,c),height:N.size,index:N.index,key:j,type:N.type||"item",...N.type==="group"?{}:{groupIndex:N.groupIndex}}):N.type==="group"?w.createElement(I,{...At(I,c),"data-index":B,"data-item-index":N.index,"data-known-size":N.size,key:j,style:h0},d(N.index,c)):w.createElement(T,{...At(T,c),...v0(T,N.data),"data-index":B,"data-item-group-index":N.groupIndex,"data-item-index":N.index,"data-known-size":N.size,key:j,style:g?m0:sf},L?l(N.index,N.groupIndex,N.data,c):l(N.index,N.data,c))})})}),g0={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},x0={outline:"none",overflowX:"auto",position:"relative"},vs=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),y0={position:ga(),top:0,width:"100%",zIndex:1};function At(e,t){if(typeof e!="string")return{context:t}}function v0(e,t){return{item:typeof e=="string"?void 0:t}}const b0=w.memo(function(){const e=Ae("HeaderComponent"),t=Jt("headerHeight"),n=Ae("HeaderFooterTag"),r=Jn(w.useMemo(()=>s=>{t(Pn(s,"height"))},[t]),!0,Ae("skipAnimationFrameInResizeObserver")),o=Ae("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...At(e,o)})}):null}),w0=w.memo(function(){const e=Ae("FooterComponent"),t=Jt("footerHeight"),n=Ae("HeaderFooterTag"),r=Jn(w.useMemo(()=>s=>{t(Pn(s,"height"))},[t]),!0,Ae("skipAnimationFrameInResizeObserver")),o=Ae("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...At(e,o)})}):null});function lf({useEmitter:e,useEmitterValue:t,usePublisher:n}){return w.memo(function({children:r,style:o,context:s,...i}){const a=n("scrollContainerState"),l=t("ScrollerComponent"),c=n("smoothScrollTargetReached"),d=t("scrollerRef"),f=t("horizontalDirection")||!1,{scrollByCallback:p,scrollerRef:h,scrollToCallback:m}=rf(a,c,l,d,void 0,f);return e("scrollTo",m),e("scrollBy",p),u.jsx(l,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:h,style:{...f?x0:g0,...o},tabIndex:0,...i,...At(l,s),children:r})})}function cf({useEmitter:e,useEmitterValue:t,usePublisher:n}){return w.memo(function({children:r,style:o,context:s,...i}){const a=n("windowScrollContainerState"),l=t("ScrollerComponent"),c=n("smoothScrollTargetReached"),d=t("totalListHeight"),f=t("deviation"),p=t("customScrollParent"),h=w.useRef(null),m=t("scrollerRef"),{scrollByCallback:g,scrollerRef:y,scrollToCallback:x}=rf(a,c,l,m,p);return nf(()=>{var b;return y.current=p||((b=h.current)==null?void 0:b.ownerDocument.defaultView),()=>{y.current=null}},[y,p]),e("windowScrollTo",x),e("scrollBy",g),u.jsx(l,{ref:h,"data-virtuoso-scroller":!0,style:{position:"relative",...o,...d!==0?{height:d+f}:{}},...i,...At(l,s),children:r})})}const S0=({children:e})=>{const t=w.useContext(ef),n=Jt("viewportHeight"),r=Jt("fixedItemHeight"),o=Ae("alignToBottom"),s=Ae("horizontalDirection"),i=w.useMemo(()=>wd(n,l=>Pn(l,s?"width":"height")),[n,s]),a=Jn(i,!0,Ae("skipAnimationFrameInResizeObserver"));return w.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),u.jsx("div",{"data-viewport-type":"element",ref:a,style:vs(o),children:e})},C0=({children:e})=>{const t=w.useContext(ef),n=Jt("windowViewportRect"),r=Jt("fixedItemHeight"),o=Ae("customScrollParent"),s=Id(n,o,Ae("skipAnimationFrameInResizeObserver")),i=Ae("alignToBottom");return w.useEffect(()=>{t&&(r(t.itemHeight),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:100}))},[t,n,r]),u.jsx("div",{"data-viewport-type":"window",ref:s,style:vs(i),children:e})},T0=({children:e})=>{const t=Ae("TopItemListComponent")||"div",n=Ae("headerHeight"),r={...y0,marginTop:`${n}px`},o=Ae("context");return u.jsx(t,{style:r,...At(t,o),children:e})},k0=w.memo(function(e){const t=Ae("useWindowScroll"),n=Ae("topItemsIndexes").length>0,r=Ae("customScrollParent"),o=Ae("context");return u.jsxs(r||t?A0:E0,{...e,context:o,children:[n&&u.jsx(T0,{children:u.jsx(af,{showTopList:!0})}),u.jsxs(r||t?C0:S0,{children:[u.jsx(b0,{}),u.jsx(af,{}),u.jsx(w0,{})]})]})}),{Component:I0,useEmitter:ya,useEmitterValue:Ae,usePublisher:Jt}=Qd(f0,{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"}},k0),E0=lf({useEmitter:ya,useEmitterValue:Ae,usePublisher:Jt}),A0=cf({useEmitter:ya,useEmitterValue:Ae,usePublisher:Jt}),N0=I0;lt(Zd,Ke(()=>{const e=ee(c=>u.jsxs("td",{children:["Item $",c]})),t=ee(null),n=ee(c=>u.jsxs("td",{colSpan:1e3,children:["Group ",c]})),r=ee(null),o=ee(null),s=ee({}),i=ee(xa),a=ee(Sr),l=(c,d=null)=>Et(W(s,ce(f=>f[c]),ct()),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")}})),ga();const uf={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},_0={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:df,floor:bs,max:to,min:va,round:ff}=Math;function pf(e,t,n){return Array.from({length:t-e+1}).map((r,o)=>({data:n===null?null:n[o+e],index:o+e}))}function j0(e){return{..._0,items:e}}function ws(e,t){return e&&e.width===t.width&&e.height===t.height}function M0(e,t){return e&&e.column===t.column&&e.row===t.row}const R0=Ke(([{increaseViewportBy:e,listBoundary:t,overscan:n,visibleRange:r},{footerHeight:o,headerHeight:s,scrollBy:i,scrollContainerState:a,scrollTo:l,scrollTop:c,smoothScrollTargetReached:d,viewportHeight:f},p,h,{didMount:m,propsReady:g},{customScrollParent:y,useWindowScroll:x,windowScrollContainerState:b,windowScrollTo:C,windowViewportRect:k},S])=>{const T=ee(0),I=ee(0),A=ee(uf),_=ee({height:0,width:0}),L=ee({height:0,width:0}),R=ze(),O=ze(),F=ee(0),N=ee(null),B=ee({column:0,row:0}),j=ze(),K=ze(),z=ee(!1),M=ee(0),G=ee(!0),X=ee(!1),se=ee(!1);Qe(W(m,Le(M),ke(([$,q])=>!!q)),()=>{Pe(G,!1)}),Qe(W(bt(m,G,L,_,M,X),ke(([$,q,Z,ue,,ie])=>$&&!q&&Z.height!==0&&ue.height!==0&&!ie)),([,,,,$])=>{Pe(X,!0),ca(1,()=>{Pe(R,$)}),sn(W(c),()=>{Pe(t,[0,0]),Pe(G,!0)})}),he(W(K,ke($=>$!=null&&$.scrollTop>0),xn(0)),I),Qe(W(m,Le(K),ke(([,$])=>$!=null)),([,$])=>{$&&(Pe(_,$.viewport),Pe(L,$.item),Pe(B,$.gap),$.scrollTop>0&&(Pe(z,!0),sn(W(c,Xn(1)),q=>{Pe(z,!1)}),Pe(l,{top:$.scrollTop})))}),he(W(_,ce(({height:$})=>$)),f),he(W(bt(Te(_,ws),Te(L,ws),Te(B,($,q)=>$&&$.column===q.column&&$.row===q.row),Te(c)),ce(([$,q,Z,ue])=>({gap:Z,item:q,scrollTop:ue,viewport:$}))),j),he(W(bt(Te(T),r,Te(B,M0),Te(L,ws),Te(_,ws),Te(N),Te(I),Te(z),Te(G),Te(M)),ke(([,,,,,,,$])=>!$),ce(([$,[q,Z],ue,ie,_e,He,oe,,ye,Oe])=>{const{column:Ye,row:nt}=ue,{height:Xe,width:qe}=ie,{width:it}=_e;if(oe===0&&($===0||it===0))return uf;if(qe===0){const jt=ua(Oe,$),Dt=jt+Math.max(oe-1,0);return j0(pf(jt,Dt,He))}const Je=hf(it,qe,Ye);let et,at;ye?q===0&&Z===0&&oe>0?(et=0,at=oe-1):(et=Je*bs((q+nt)/(Xe+nt)),at=Je*df((Z+nt)/(Xe+nt))-1,at=va($-1,to(at,Je-1)),et=va(at,to(0,et))):(et=0,at=-1);const _t=pf(et,at,He),{bottom:ht,top:ft}=mf(_e,ue,ie,_t),mt=df($/Je),St=mt*Xe+(mt-1)*nt-ht;return{bottom:ht,itemHeight:Xe,items:_t,itemWidth:qe,offsetBottom:St,offsetTop:ft,top:ft}})),A),he(W(N,ke($=>$!==null),ce($=>$.length)),T),he(W(bt(_,L,A,B),ke(([$,q,{items:Z}])=>Z.length>0&&q.height!==0&&$.height!==0),ce(([$,q,{items:Z},ue])=>{const{bottom:ie,top:_e}=mf($,ue,q,Z);return[_e,ie]}),ct(Gr)),t);const be=ee(!1);he(W(c,Le(be),ce(([$,q])=>q||$!==0)),be);const Ie=Ut(W(bt(A,T),ke(([{items:$}])=>$.length>0),Le(be),ke(([[$,q],Z])=>{const ue=$.items[$.items.length-1].index===q-1;return(Z||$.bottom>0&&$.itemHeight>0&&$.offsetBottom===0&&$.items.length===q)&&ue}),ce(([[,$]])=>$-1),ct())),Y=Ut(W(Te(A),ke(({items:$})=>$.length>0&&$[0].index===0),xn(0),ct())),U=Ut(W(Te(A),Le(z),ke(([{items:$},q])=>$.length>0&&!q),ce(([{items:$}])=>({endIndex:$[$.length-1].index,startIndex:$[0].index})),ct(Rd),In(0)));he(U,h.scrollSeekRangeChanged),he(W(R,Le(_,L,T,B),ce(([$,q,Z,ue,ie])=>{const _e=Fd($),{align:He,behavior:oe,offset:ye}=_e;let Oe=_e.index;Oe==="LAST"&&(Oe=ue-1),Oe=to(0,Oe,va(ue-1,Oe));let Ye=ba(q,ie,Z,Oe);return He==="end"?Ye=ff(Ye-q.height+Z.height):He==="center"&&(Ye=ff(Ye-q.height/2+Z.height/2)),ye&&(Ye+=ye),{behavior:oe,top:Ye}})),l);const J=Et(W(A,ce($=>$.offsetBottom+$.bottom)),0);return he(W(k,ce($=>({height:$.visibleHeight,width:$.visibleWidth}))),_),{customScrollParent:y,data:N,deviation:F,footerHeight:o,gap:B,headerHeight:s,increaseViewportBy:e,initialItemCount:I,itemDimensions:L,overscan:n,restoreStateFrom:K,scrollBy:i,scrollContainerState:a,scrollHeight:O,scrollTo:l,scrollToIndex:R,scrollTop:c,smoothScrollTargetReached:d,totalCount:T,useWindowScroll:x,viewportDimensions:_,windowScrollContainerState:b,windowScrollTo:C,windowViewportRect:k,...h,gridState:A,horizontalDirection:se,initialTopMostItemIndex:M,totalListHeight:J,...p,endReached:Ie,propsReady:g,rangeChanged:U,startReached:Y,stateChanged:j,stateRestoreInProgress:z,...S}},lt(da,Ot,eo,Xd,On,pa,Rn));function hf(e,t,n){return to(1,bs((e+n)/(bs(t)+n)))}function mf(e,t,n,r){const{height:o}=n;if(o===void 0||r.length===0)return{bottom:0,top:0};const s=ba(e,t,n,r[0].index);return{bottom:ba(e,t,n,r[r.length-1].index)+o,top:s}}function ba(e,t,n,r){const o=hf(e.width,n.width,t.column),s=bs(r/o),i=s*n.height+to(0,s-1)*t.row;return i>0?i+t.row:i}const P0=Ke(()=>{const e=ee(f=>`Item ${f}`),t=ee({}),n=ee(null),r=ee("virtuoso-grid-item"),o=ee("virtuoso-grid-list"),s=ee(xa),i=ee("div"),a=ee(Sr),l=(f,p=null)=>Et(W(t,ce(h=>h[f]),ct()),p),c=ee(!1),d=ee(!1);return he(Te(d),c),{components:t,computeItemKey:s,context:n,FooterComponent:l("Footer"),HeaderComponent:l("Header"),headerFooterTag:i,itemClassName:r,ItemComponent:l("Item","div"),itemContent:e,listClassName:o,ListComponent:l("List","div"),readyStateChanged:c,reportReadyState:d,ScrollerComponent:l("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder","div")}}),O0=Ke(([e,t])=>({...e,...t}),lt(R0,P0)),D0=w.memo(function(){const e=dt("gridState"),t=dt("listClassName"),n=dt("itemClassName"),r=dt("itemContent"),o=dt("computeItemKey"),s=dt("isSeeking"),i=Zt("scrollHeight"),a=dt("ItemComponent"),l=dt("ListComponent"),c=dt("ScrollSeekPlaceholder"),d=dt("context"),f=Zt("itemDimensions"),p=Zt("gap"),h=dt("log"),m=dt("stateRestoreInProgress"),g=Zt("reportReadyState"),y=Jn(w.useMemo(()=>x=>{const b=x.parentElement.parentElement.scrollHeight;i(b);const C=x.firstChild;if(C){const{height:k,width:S}=C.getBoundingClientRect();f({height:k,width:S})}p({column:xf("column-gap",getComputedStyle(x).columnGap,h),row:xf("row-gap",getComputedStyle(x).rowGap,h)})},[i,f,p,h]),!0,!1);return nf(()=>{e.itemHeight>0&&e.itemWidth>0&&g(!0)},[e]),m?null:u.jsx(l,{className:t,ref:y,...At(l,d),"data-testid":"virtuoso-item-list",style:{paddingBottom:e.offsetBottom,paddingTop:e.offsetTop},children:e.items.map(x=>{const b=o(x.index,x.data,d);return s?u.jsx(c,{...At(c,d),height:e.itemHeight,index:x.index,width:e.itemWidth},b):w.createElement(a,{...At(a,d),className:n,"data-index":x.index,key:b},r(x.index,x.data,d))})})}),L0=w.memo(function(){const e=dt("HeaderComponent"),t=Zt("headerHeight"),n=dt("headerFooterTag"),r=Jn(w.useMemo(()=>s=>{t(Pn(s,"height"))},[t]),!0,!1),o=dt("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...At(e,o)})}):null}),$0=w.memo(function(){const e=dt("FooterComponent"),t=Zt("footerHeight"),n=dt("headerFooterTag"),r=Jn(w.useMemo(()=>s=>{t(Pn(s,"height"))},[t]),!0,!1),o=dt("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...At(e,o)})}):null}),F0=({children:e})=>{const t=w.useContext(tf),n=Zt("itemDimensions"),r=Zt("viewportDimensions"),o=Jn(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]),u.jsx("div",{ref:o,style:vs(!1),children:e})},B0=({children:e})=>{const t=w.useContext(tf),n=Zt("windowViewportRect"),r=Zt("itemDimensions"),o=dt("customScrollParent"),s=Id(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]),u.jsx("div",{ref:s,style:vs(!1),children:e})},z0=w.memo(function({...e}){const t=dt("useWindowScroll"),n=dt("customScrollParent"),r=n||t?H0:U0,o=n||t?B0:F0,s=dt("context");return u.jsx(r,{...e,...At(r,s),children:u.jsxs(o,{children:[u.jsx(L0,{}),u.jsx(D0,{}),u.jsx($0,{})]})})}),{useEmitter:gf,useEmitterValue:dt,usePublisher:Zt}=Qd(O0,{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"}},z0),U0=lf({useEmitter:gf,useEmitterValue:dt,usePublisher:Zt}),H0=cf({useEmitter:gf,useEmitterValue:dt,usePublisher:Zt});function xf(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Ft.WARN),t==="normal"?0:parseInt(t??"0",10)}const W0=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 yf({className:e,variant:t,...n}){return u.jsx("div",{className:te(W0({variant:t}),e),...n})}function wa(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 vf(e){return!!(e&&typeof e=="object"&&(e.type==="file"||e.mimeType||e.filename||e.sourceType==="base64"))}function no(e){if(typeof e=="string")return e;if(e&&typeof e=="object"){if(Array.isArray(e)){const n=e.map(no).filter(r=>r!==void 0);if(!n.length){console.debug("[message-utils] sanitizeForDisplay - array emptied -> returning undefined",{originalLength:e.length});return}return n}if(vf(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=no(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 ro(e){if(typeof e=="string")return e;if(vf(e))return"";try{const t=no(e);return t===void 0?"":typeof t=="string"?t:JSON.stringify(t,null,2)}catch{return""}}function V0(e){return typeof e!="string"?!1:/^[\s\n]*[-*]\s|^[\s\n]*#+\s|```|^\s*\[.*\]\(|^>\s/.test(e)}function K0(e){const t=ro(e);return typeof e=="string"&&V0(e)?{content:e,isMarkdown:!0}:{content:t,isMarkdown:!1}}function Ss(e){if(e==null)return e;if(typeof e=="string"){const t=e.trim();if(t.startsWith("{")||t.startsWith("[")){const n=wa(t);if(n!==null)return Ss(n)}return e}return typeof e=="object"&&!Array.isArray(e)&&e.content!==void 0?Ss(e.content):e}function q0(e){return e.filter(t=>t.type==="text").map(t=>t.text).join("")}function bf(e){const t=e.content.find(s=>s.type==="tool_call"),n=e.additionalKwargs??{},r=typeof(t==null?void 0:t.id)=="string"&&t.id||typeof n.toolCallId=="string"&&n.toolCallId||(e.id.startsWith("tool-")?e.id.slice(5):void 0);return{name:(typeof(t==null?void 0:t.name)=="string"&&t.name||typeof n.toolName=="string"&&n.toolName||e.name&&String(e.name))??void 0,toolCallId:r??void 0}}function Cs(e){if(e==null)return null;const t=String(e).trim();return t.length>0?t:null}function G0(e){const t=r=>{try{const o=no(r);return typeof o=="string"?o:JSON.stringify(o??"")}catch{return""}},n=e.filter(r=>r.type==="text");return n.length?t(n.map(r=>r.text).join(`
|
|
87
|
-
`)):t(e)}function
|
|
86
|
+
`).trim():n.replace(/</g,"<").replace(/>/g,">").trim()}function Ew(e,t=cs){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 Aw(e){let t;return typeof e=="string"?t=e:typeof e=="object"&&e!==null?t=JSON.stringify(e):t=String(e),Ew(t),Iw(t)}const us=0,Rn=1,Sr=2,bd=4;function wd(e){return()=>e}function Nw(e){e()}function Sd(e,t){return n=>e(t(n))}function Cd(e,t){return()=>e(t)}function _w(e,t){return n=>e(t,n)}function Ji(e){return e!==void 0}function jw(...e){return()=>{e.map(Nw)}}function Cr(){}function ds(e,t){return t(e),e}function Mw(e,t){return t(e)}function lt(...e){return e}function Qe(e,t){return e(Rn,t)}function Pe(e,t){e(us,t)}function Zi(e){e(Sr)}function vt(e){return e(bd)}function he(e,t){return Qe(e,_w(t,us))}function an(e,t){const n=e(Rn,r=>{n(),t(r)});return n}function Td(e){let t,n;return r=>o=>{t=o,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function kd(e,t){return e===t}function ct(e=kd){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function ke(e){return t=>n=>{e(n)&&t(n)}}function ce(e){return t=>Sd(t,e)}function yn(e){return t=>()=>{t(e)}}function W(e,...t){const n=Rw(...t);return(r,o)=>{switch(r){case Sr:Zi(e);return;case Rn:return Qe(e,n(o))}}}function vn(e,t){return n=>r=>{n(t=e(t,r))}}function Jn(e){return t=>n=>{e>0?e--:t(n)}}function En(e){let t=null,n;return r=>o=>{t=o,!n&&(n=setTimeout(()=>{n=void 0,r(t)},e))}}function Le(...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);Qe(s,l=>{const c=n;n=n|a,t[i]=l,c!==o&&n===o&&r&&(r(),r=null)})}),s=>i=>{const a=()=>{s([i].concat(t))};n===o?a():r=a}}function Rw(...e){return t=>e.reduceRight(Mw,t)}function Pw(e){let t,n;const r=()=>t==null?void 0:t();return function(o,s){switch(o){case Rn:return s?n===s?void 0:(r(),n=s,t=Qe(e,s),t):(r(),Cr);case Sr:r(),n=null;return}}}function ee(e){let t=e;const n=ze();return(r,o)=>{switch(r){case us:t=o;break;case Rn:{o(t);break}case bd:return t}return n(r,o)}}function At(e,t){return ds(ee(t),n=>he(e,n))}function ze(){const e=[];return(t,n)=>{switch(t){case us:e.slice().forEach(r=>{r(n)});return;case Sr:e.splice(0,e.length);return;case Rn:return e.push(n),()=>{const r=e.indexOf(n);r>-1&&e.splice(r,1)}}}}function Ht(e){return ds(ze(),t=>he(e,t))}function Ke(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:Ow(),singleton:n}}const Ow=()=>Symbol();function Dw(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 bt(...e){const t=ze(),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);Qe(s,l=>{n[i]=l,r=r|a,r===o&&Pe(t,n)})}),function(s,i){switch(s){case Sr:{Zi(t);return}case Rn:return r===o&&i(n),Qe(t,i)}}}function Te(e,t=kd){return W(e,ct(t))}function Qi(...e){return function(t,n){switch(t){case Sr:return;case Rn:return jw(...e.map(r=>Qe(r,n)))}}}var Bt=(e=>(e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR",e))(Bt||{});const Lw={0:"debug",3:"error",1:"log",2:"warn"},$w=()=>typeof globalThis>"u"?window:globalThis,Pn=Ke(()=>{const e=ee(3);return{log:ee((t,n,r=1)=>{var o;const s=(o=$w().VIRTUOSO_LOG_LEVEL)!=null?o:vt(e);r>=s&&console[Lw[r]]("%creact-virtuoso: %c%s %o","color: #0253b3; font-weight: bold","color: initial",t,n)}),logLevel:e}},[],{singleton:!0});function Zn(e,t,n){return ea(e,t,n).callbackRef}function ea(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 Fw(e,t,n,r,o,s,i,a,l){const c=w.useCallback(d=>{const f=Bw(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 m;p&&(m=h.ownerDocument.defaultView);const g=i?a?i.scrollLeft:i.scrollTop:p?a?m.scrollX||m.document.documentElement.scrollLeft:m.scrollY||m.document.documentElement.scrollTop:a?h.scrollLeft:h.scrollTop,y=i?a?i.scrollWidth:i.scrollHeight:p?a?m.document.documentElement.scrollWidth:m.document.documentElement.scrollHeight:a?h.scrollWidth:h.scrollHeight,x=i?a?i.offsetWidth:i.offsetHeight:p?a?m.innerWidth:m.innerHeight:a?h.offsetWidth:h.offsetHeight;r({scrollHeight:y,scrollTop:Math.max(g,0),viewportHeight:x}),s==null||s(a?Id("column-gap",getComputedStyle(d).columnGap,o):Id("row-gap",getComputedStyle(d).rowGap,o)),f!==null&&e(f)},[e,t,o,s,i,r,a]);return ea(c,n,l)}function Bw(e,t,n,r){const o=e.length;if(o===0)return null;const s=[];for(let i=0;i<o;i++){const a=e.item(i);if(a.dataset.index===void 0)continue;const l=parseInt(a.dataset.index),c=parseFloat(a.dataset.knownSize),d=t(a,n);if(d===0&&r("Zero-sized element, this should not happen",{child:a},Bt.ERROR),d===c)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 Id(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Bt.WARN),t==="normal"?0:parseInt(t??"0",10)}function Ed(e,t,n){const r=w.useRef(null),o=w.useCallback(l=>{if(!(l!=null&&l.offsetParent))return;const c=l.getBoundingClientRect(),d=c.width;let f,h;if(t){const p=t.getBoundingClientRect(),m=c.top-p.top;h=p.height-Math.max(0,m),f=m+t.scrollTop}else{const p=i.current.ownerDocument.defaultView;h=p.innerHeight-Math.max(0,c.top),f=c.top+p.scrollY}r.current={offsetTop:f,visibleHeight:h,visibleWidth:d},e(r.current)},[e,t]),{callbackRef:s,ref:i}=ea(o,!0,n),a=w.useCallback(()=>{o(i.current)},[o,i]);return w.useEffect(()=>{var l;if(t){t.addEventListener("scroll",a);const c=new ResizeObserver(()=>{requestAnimationFrame(a)});return c.observe(t),()=>{t.removeEventListener("scroll",a),c.unobserve(t)}}else{const c=(l=i.current)==null?void 0:l.ownerDocument.defaultView;return c==null||c.addEventListener("scroll",a),c==null||c.addEventListener("resize",a),()=>{c==null||c.removeEventListener("scroll",a),c==null||c.removeEventListener("resize",a)}}},[a,t,i]),s}const Dt=Ke(()=>{const e=ze(),t=ze(),n=ee(0),r=ze(),o=ee(0),s=ze(),i=ze(),a=ee(0),l=ee(0),c=ee(0),d=ee(0),f=ze(),h=ze(),p=ee(!1),m=ee(!1),g=ee(!1);return he(W(e,ce(({scrollTop:y})=>y)),t),he(W(e,ce(({scrollHeight:y})=>y)),i),he(t,o),{deviation:n,fixedFooterHeight:c,fixedHeaderHeight:l,footerHeight:d,headerHeight:a,horizontalDirection:m,scrollBy:h,scrollContainerState:e,scrollHeight:i,scrollingInProgress:p,scrollTo:f,scrollTop:t,skipAnimationFrameInResizeObserver:g,smoothScrollTargetReached:r,statefulScrollTop:o,viewportHeight:s}},[],{singleton:!0}),Kr={lvl:0};function Ad(e,t){const n=e.length;if(n===0)return[];let{index:r,value:o}=t(e[0]);const s=[];for(let i=1;i<n;i++){const{index:a,value:l}=t(e[i]);s.push({end:a-1,start:r,value:o}),r=a,o=l}return s.push({end:1/0,start:r,value:o}),s}function ot(e){return e===Kr}function qr(e,t){if(!ot(e))return t===e.k?e.v:t<e.k?qr(e.l,t):qr(e.r,t)}function ln(e,t,n="k"){if(ot(e))return[-1/0,void 0];if(Number(e[n])===t)return[e.k,e.v];if(Number(e[n])<t){const r=ln(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return ln(e.l,t,n)}function Wt(e,t,n){return ot(e)?jd(t,n,1):t===e.k?wt(e,{k:t,v:n}):t<e.k?Md(wt(e,{l:Wt(e.l,t,n)})):Md(wt(e,{r:Wt(e.r,t,n)}))}function Tr(){return Kr}function fs(e,t,n){if(ot(e))return[];const r=ln(e,t)[0];return zw(na(e,r,n))}function ta(e,t){if(ot(e))return Kr;const{k:n,l:r,r:o}=e;if(t===n){if(ot(r))return o;if(ot(o))return r;{const[s,i]=_d(r);return ps(wt(e,{k:s,l:Nd(r),v:i}))}}else return t<n?ps(wt(e,{l:ta(r,t)})):ps(wt(e,{r:ta(o,t)}))}function Qn(e){return ot(e)?[]:[...Qn(e.l),{k:e.k,v:e.v},...Qn(e.r)]}function na(e,t,n){if(ot(e))return[];const{k:r,l:o,r:s,v:i}=e;let a=[];return r>t&&(a=a.concat(na(o,t,n))),r>=t&&r<=n&&a.push({k:r,v:i}),r<=n&&(a=a.concat(na(s,t,n))),a}function ps(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(ra(t))return Rd(wt(e,{lvl:n-1}));if(!ot(t)&&!ot(t.r))return wt(t.r,{l:wt(t,{r:t.r.l}),lvl:n,r:wt(e,{l:t.r.r,lvl:n-1})});throw new Error("Unexpected empty nodes")}else{if(ra(e))return oa(wt(e,{lvl:n-1}));if(!ot(r)&&!ot(r.l)){const o=r.l,s=ra(o)?r.lvl-1:r.lvl;return wt(o,{l:wt(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:oa(wt(r,{l:o.r,lvl:s}))})}else throw new Error("Unexpected empty nodes")}}function wt(e,t){return jd(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 Nd(e){return ot(e.r)?e.l:ps(wt(e,{r:Nd(e.r)}))}function ra(e){return ot(e)||e.lvl>e.r.lvl}function _d(e){return ot(e.r)?[e.k,e.v]:_d(e.r)}function jd(e,t,n,r=Kr,o=Kr){return{k:e,l:r,lvl:n,r:o,v:t}}function Md(e){return oa(Rd(e))}function Rd(e){const{l:t}=e;return!ot(t)&&t.lvl===e.lvl?wt(t,{r:wt(e,{l:t.r})}):e}function oa(e){const{lvl:t,r:n}=e;return!ot(n)&&!ot(n.r)&&n.lvl===t&&n.r.lvl===t?wt(n,{l:wt(e,{r:n.l}),lvl:t+1}):e}function zw(e){return Ad(e,({k:t,v:n})=>({index:t,value:n}))}function Pd(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function Gr(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}const sa=Ke(()=>({recalcInProgress:ee(!1)}),[],{singleton:!0});function Od(e,t,n){return e[hs(e,t,n)]}function hs(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 Uw(e,t,n,r){const o=hs(e,t,r),s=hs(e,n,r,o);return e.slice(o,s+1)}function On(e,t){return Math.round(e.getBoundingClientRect()[t])}function ms(e){return!ot(e.groupOffsetTree)}function ia({index:e},t){return t===e?0:t<e?-1:1}function Hw(){return{groupIndices:[],groupOffsetTree:Tr(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:Tr()}}function Ww(e,t){let n=ot(e)?0:1/0;for(const r of t){const{endIndex:o,size:s,startIndex:i}=r;if(n=Math.min(n,i),ot(e)){e=Wt(e,0,s);continue}const a=fs(e,i-1,o+1);if(a.some(Jw(r)))continue;let l=!1,c=!1;for(const{end:d,start:f,value:h}of a)l?(o>=f||s===h)&&(e=ta(e,f)):(c=h!==s,l=!0),d>o&&o>=f&&h!==s&&(e=Wt(e,o+1,h));c&&(e=Wt(e,i,s))}return[e,n]}function Vw(e){return typeof e.groupIndex<"u"}function Kw({offset:e},t){return t===e?0:t<e?-1:1}function Yr(e,t,n){if(t.length===0)return 0;const{index:r,offset:o,size:s}=Od(t,e,ia),i=e-r,a=s*i+(i-1)*n+o;return a>0?a+n:a}function Dd(e,t){if(!ms(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function Ld(e,t,n){if(Vw(e))return t.groupIndices[e.groupIndex]+1;{const r=e.index==="LAST"?n:e.index;let o=Dd(r,t);return o=Math.max(0,o,Math.min(n,o)),o}}function qw(e,t,n,r=0){return r>0&&(t=Math.max(t,Od(e,r,ia).offset)),Ad(Uw(e,t,n,Kw),Xw)}function Gw(e,[t,n,r,o]){t.length>0&&r("received item sizes",t,Bt.DEBUG);const s=e.sizeTree;let i=s,a=0;if(n.length>0&&ot(s)&&t.length===2){const h=t[0].size,p=t[1].size;i=n.reduce((m,g)=>Wt(Wt(m,g,h),g+1,p),i)}else[i,a]=Ww(i,t);if(i===s)return e;const{lastIndex:l,lastOffset:c,lastSize:d,offsetTree:f}=aa(e.offsetTree,a,i,o);return{groupIndices:n,groupOffsetTree:n.reduce((h,p)=>Wt(h,p,Yr(p,f,o)),Tr()),lastIndex:l,lastOffset:c,lastSize:d,offsetTree:f,sizeTree:i}}function Yw(e){return Qn(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 $d(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 aa(e,t,n,r){let o=e,s=0,i=0,a=0,l=0;if(t!==0){l=hs(o,t-1,ia),a=o[l].offset;const c=ln(n,t-1);s=c[0],i=c[1],o.length&&o[l].size===ln(n,t)[1]&&(l-=1),o=o.slice(0,l+1)}else o=[];for(const{start:c,value:d}of fs(n,t,1/0)){const f=c-s,h=f*i+a+f*r;o.push({index:c,offset:h,size:d}),s=c,a=h,i=d}return{lastIndex:s,lastOffset:a,lastSize:i,offsetTree:o}}function Xw(e){return{index:e.index,value:e}}function Jw(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 Zw={offsetHeight:"height",offsetWidth:"width"},bn=Ke(([{log:e},{recalcInProgress:t}])=>{const n=ze(),r=ze(),o=At(r,0),s=ze(),i=ze(),a=ee(0),l=ee([]),c=ee(void 0),d=ee(void 0),f=ee((C,T)=>On(C,Zw[T])),h=ee(void 0),p=ee(0),m=Hw(),g=At(W(n,Le(l,e,p),vn(Gw,m),ct()),m),y=At(W(l,ct(),vn((C,T)=>({current:T,prev:C.current}),{current:[],prev:[]}),ce(({prev:C})=>C)),[]);he(W(l,ke(C=>C.length>0),Le(g,p),ce(([C,T,I])=>{const A=C.reduce((N,L,R)=>Wt(N,L,Yr(L,T.offsetTree,I)||R),Tr());return{...T,groupIndices:C,groupOffsetTree:A}})),g),he(W(r,Le(g),ke(([C,{lastIndex:T}])=>C<T),ce(([C,{lastIndex:T,lastSize:I}])=>[{endIndex:T,size:I,startIndex:C}])),n),he(c,d);const x=At(W(c,ce(C=>C===void 0)),!0);he(W(d,ke(C=>C!==void 0&&ot(vt(g).sizeTree)),ce(C=>[{endIndex:0,size:C,startIndex:0}])),n);const b=Ht(W(n,Le(g),vn(({sizes:C},[T,I])=>({changed:I!==C,sizes:I}),{changed:!1,sizes:m}),ce(C=>C.changed)));Qe(W(a,vn((C,T)=>({diff:C.prev-T,prev:T}),{diff:0,prev:0}),ce(C=>C.diff)),C=>{const{groupIndices:T}=vt(g);if(C>0)Pe(t,!0),Pe(s,C+$d(C,T));else if(C<0){const I=vt(y);I.length>0&&(C-=$d(-C,I)),Pe(i,C)}}),Qe(W(a,Le(e)),([C,T])=>{C<0&&T("`firstItemIndex` prop should not be set to less than zero. If you don't know the total count, just use a very high value",{firstItemIndex:a},Bt.ERROR)});const S=Ht(s);he(W(s,Le(g),ce(([C,T])=>{const I=T.groupIndices.length>0,A=[],N=T.lastSize;if(I){const L=qr(T.sizeTree,0);let R=0,O=0;for(;R<C;){const _=T.groupIndices[O],B=T.groupIndices.length===O+1?1/0:T.groupIndices[O+1]-_-1;A.push({endIndex:_,size:L,startIndex:_}),A.push({endIndex:_+1+B-1,size:N,startIndex:_+1}),O++,R+=B+1}const F=Qn(T.sizeTree);return R!==C&&F.shift(),F.reduce((_,{k:B,v:j})=>{let K=_.ranges;return _.prevSize!==0&&(K=[..._.ranges,{endIndex:B+C-1,size:_.prevSize,startIndex:_.prevIndex}]),{prevIndex:B+C,prevSize:j,ranges:K}},{prevIndex:C,prevSize:0,ranges:A}).ranges}return Qn(T.sizeTree).reduce((L,{k:R,v:O})=>({prevIndex:R+C,prevSize:O,ranges:[...L.ranges,{endIndex:R+C-1,size:L.prevSize,startIndex:L.prevIndex}]}),{prevIndex:0,prevSize:N,ranges:[]}).ranges})),n);const k=Ht(W(i,Le(g,p),ce(([C,{offsetTree:T},I])=>{const A=-C;return Yr(A,T,I)})));return he(W(i,Le(g,p),ce(([C,T,I])=>{if(T.groupIndices.length>0){if(ot(T.sizeTree))return T;let A=Tr();const N=vt(y);let L=0,R=0,O=0;for(;L<-C;){O=N[R];const F=N[R+1]-O-1;R++,L+=F+1}if(A=Qn(T.sizeTree).reduce((F,{k:_,v:B})=>Wt(F,Math.max(0,_+C),B),A),L!==-C){const F=qr(T.sizeTree,O);A=Wt(A,0,F);const _=ln(T.sizeTree,-C+1)[1];A=Wt(A,1,_)}return{...T,sizeTree:A,...aa(T.offsetTree,0,A,I)}}else{const A=Qn(T.sizeTree).reduce((N,{k:L,v:R})=>Wt(N,Math.max(0,L+C),R),Tr());return{...T,sizeTree:A,...aa(T.offsetTree,0,A,I)}}})),g),{beforeUnshiftWith:S,data:h,defaultItemSize:d,firstItemIndex:a,fixedItemSize:c,gap:p,groupIndices:l,itemSize:f,listRefresh:b,shiftWith:i,shiftWithOffset:k,sizeRanges:n,sizes:g,statefulTotalCount:o,totalCount:r,trackItemSizes:x,unshiftWith:s}},lt(Pn,sa),{singleton:!0});function Qw(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const Fd=Ke(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=ze(),i=ze(),a=Ht(W(s,ce(Qw)));return he(W(a,ce(l=>l.totalCount)),n),he(W(a,ce(l=>l.groupIndices)),e),he(W(bt(o,t,r),ke(([l,c])=>ms(c)),ce(([l,c,d])=>ln(c.groupOffsetTree,Math.max(l-d,0),"v")[0]),ct(),ce(l=>[l])),i),{groupCounts:s,topItemsIndexes:i}},lt(bn,Dt)),Dn=Ke(([{log:e}])=>{const t=ee(!1),n=Ht(W(t,ke(r=>r),ct()));return Qe(t,r=>{r&&vt(e)("props updated",{},Bt.DEBUG)}),{didMount:n,propsReady:t}},lt(Pn),{singleton:!0}),e0=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function Bd(e){const t=typeof e=="number"?{index:e}:e;return t.align||(t.align="start"),(!t.behavior||!e0)&&(t.behavior="auto"),t.offset||(t.offset=0),t}const Xr=Ke(([{gap:e,listRefresh:t,sizes:n,totalCount:r},{fixedFooterHeight:o,fixedHeaderHeight:s,footerHeight:i,headerHeight:a,scrollingInProgress:l,scrollTo:c,smoothScrollTargetReached:d,viewportHeight:f},{log:h}])=>{const p=ze(),m=ze(),g=ee(0);let y=null,x=null,b=null;function S(){y&&(y(),y=null),b&&(b(),b=null),x&&(clearTimeout(x),x=null),Pe(l,!1)}return he(W(p,Le(n,f,r,g,a,i,h),Le(e,s,o),ce(([[k,C,T,I,A,N,L,R],O,F,_])=>{const B=Bd(k),{align:j,behavior:K,offset:z}=B,M=I-1,G=Ld(B,C,M);let X=Yr(G,C.offsetTree,O)+N;j==="end"?(X+=F+ln(C.sizeTree,G)[1]-T+_,G===M&&(X+=L)):j==="center"?X+=(F+ln(C.sizeTree,G)[1]-T+_)/2:X-=A,z&&(X+=z);const se=be=>{S(),be?(R("retrying to scroll to",{location:k},Bt.DEBUG),Pe(p,k)):(Pe(m,!0),R("list did not change, scroll successful",{},Bt.DEBUG))};if(S(),K==="smooth"){let be=!1;b=Qe(t,Ie=>{be=be||Ie}),y=an(d,()=>{se(be)})}else y=an(W(t,t0(150)),se);return x=setTimeout(()=>{S()},1200),Pe(l,!0),R("scrolling from index to",{behavior:K,index:G,top:X},Bt.DEBUG),{behavior:K,top:X}})),c),{scrollTargetReached:m,scrollToIndex:p,topListHeight:g}},lt(bn,Dt,Pn),{singleton:!0});function t0(e){return t=>{const n=setTimeout(()=>{t(!1)},e);return r=>{r&&(t(!0),clearTimeout(n))}}}function la(e,t){e==0?t():requestAnimationFrame(()=>{la(e-1,t)})}function ca(e,t){const n=t-1;return typeof e=="number"?e:e.index==="LAST"?n:e.index}const Jr=Ke(([{defaultItemSize:e,listRefresh:t,sizes:n},{scrollTop:r},{scrollTargetReached:o,scrollToIndex:s},{didMount:i}])=>{const a=ee(!0),l=ee(0),c=ee(!0);return he(W(i,Le(l),ke(([d,f])=>!!f),yn(!1)),a),he(W(i,Le(l),ke(([d,f])=>!!f),yn(!1)),c),Qe(W(bt(t,i),Le(a,n,e,c),ke(([[,d],f,{sizeTree:h},p,m])=>d&&(!ot(h)||Ji(p))&&!f&&!m),Le(l)),([,d])=>{an(o,()=>{Pe(c,!0)}),la(4,()=>{an(r,()=>{Pe(a,!0)}),Pe(s,d)})}),{initialItemFinalLocationReached:c,initialTopMostItemIndex:l,scrolledToInitialItem:a}},lt(bn,Dt,Xr,Dn),{singleton:!0});function zd(e,t){return Math.abs(e-t)<1.01}const Zr="up",Qr="down",n0="none",r0={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},o0=0,eo=Ke(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:o,viewportHeight:s}])=>{const i=ee(!1),a=ee(!0),l=ze(),c=ze(),d=ee(4),f=ee(o0),h=At(W(Qi(W(Te(o),Jn(1),yn(!0)),W(Te(o),Jn(1),yn(!1),Td(100))),ct()),!1),p=At(W(Qi(W(n,yn(!0)),W(n,yn(!1),Td(200))),ct()),!1);he(W(bt(Te(o),Te(f)),ce(([b,S])=>b<=S),ct()),a),he(W(a,En(50)),c);const m=Ht(W(bt(r,Te(s),Te(t),Te(e),Te(d)),vn((b,[{scrollHeight:S,scrollTop:k},C,T,I,A])=>{const N=k+C-S>-A,L={scrollHeight:S,scrollTop:k,viewportHeight:C};if(N){let O,F;return k>b.state.scrollTop?(O="SCROLLED_DOWN",F=b.state.scrollTop-k):(O="SIZE_DECREASED",F=b.state.scrollTop-k||b.scrollTopDelta),{atBottom:!0,atBottomBecause:O,scrollTopDelta:F,state:L}}let R;return L.scrollHeight>b.state.scrollHeight?R="SIZE_INCREASED":C<b.state.viewportHeight?R="VIEWPORT_HEIGHT_DECREASING":k<b.state.scrollTop?R="SCROLLING_UPWARDS":R="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:R,state:L}},r0),ct((b,S)=>b&&b.atBottom===S.atBottom))),g=At(W(r,vn((b,{scrollHeight:S,scrollTop:k,viewportHeight:C})=>{if(zd(b.scrollHeight,S))return{changed:!1,jump:0,scrollHeight:S,scrollTop:k};{const T=S-(k+C)<1;return b.scrollTop!==k&&T?{changed:!0,jump:b.scrollTop-k,scrollHeight:S,scrollTop:k}:{changed:!0,jump:0,scrollHeight:S,scrollTop:k}}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),ke(b=>b.changed),ce(b=>b.jump)),0);he(W(m,ce(b=>b.atBottom)),i),he(W(i,En(50)),l);const y=ee(Qr);he(W(r,ce(({scrollTop:b})=>b),ct(),vn((b,S)=>vt(p)?{direction:b.direction,prevScrollTop:S}:{direction:S<b.prevScrollTop?Zr:Qr,prevScrollTop:S},{direction:Qr,prevScrollTop:0}),ce(b=>b.direction)),y),he(W(r,En(50),yn(n0)),y);const x=ee(0);return he(W(h,ke(b=>!b),yn(0)),x),he(W(o,En(100),Le(h),ke(([b,S])=>!!S),vn(([b,S],[k])=>[S,k],[0,0]),ce(([b,S])=>S-b)),x),{atBottomState:m,atBottomStateChange:l,atBottomThreshold:d,atTopStateChange:c,atTopThreshold:f,isAtBottom:i,isAtTop:a,isScrolling:h,lastJumpDueToItemResize:g,scrollDirection:y,scrollVelocity:x}},lt(Dt)),gs="top",xs="bottom",Ud="none";function Hd(e,t,n){return typeof e=="number"?n===Zr&&t===gs||n===Qr&&t===xs?e:0:n===Zr?t===gs?e.main:e.reverse:t===xs?e.main:e.reverse}function Wd(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const ua=Ke(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:o}])=>{const s=ze(),i=ee(0),a=ee(0),l=ee(0),c=At(W(bt(Te(r),Te(o),Te(n),Te(s,Gr),Te(l),Te(i),Te(t),Te(e),Te(a)),ce(([d,f,h,[p,m],g,y,x,b,S])=>{const k=d-b,C=y+x,T=Math.max(h-k,0);let I=Ud;const A=Wd(S,gs),N=Wd(S,xs);return p-=b,p+=h+x,m+=h+x,m-=b,p>d+C-A&&(I=Zr),m<d-T+f+N&&(I=Qr),I!==Ud?[Math.max(k-h-Hd(g,gs,I)-A,0),k-T-x+f+Hd(g,xs,I)+N]:null}),ke(d=>d!=null),ct(Gr)),[0,0]);return{increaseViewportBy:a,listBoundary:s,overscan:l,topListHeight:i,visibleRange:c}},lt(Dt),{singleton:!0});function s0(e,t,n){if(ms(t)){const r=Dd(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 da={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function ys(e,t,n,r,o,s){const{lastIndex:i,lastOffset:a,lastSize:l}=o;let c=0,d=0;if(e.length>0){c=e[0].offset;const g=e[e.length-1];d=g.offset+g.size}const f=n-i,h=a+f*l+(f-1)*r,p=c,m=h-d;return{bottom:d,firstItemIndex:s,items:Kd(e,o,s),offsetBottom:m,offsetTop:c,top:p,topItems:Kd(t,o,s),topListHeight:t.reduce((g,y)=>y.size+g,0),totalCount:n}}function Vd(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=ca(t,a),c=Array.from({length:a}).map((d,f)=>({data:s[f+l],index:f+l,offset:0,size:0}));return ys(c,[],a,o,n,r)}function Kd(e,t,n){if(e.length===0)return[];if(!ms(t))return e.map(c=>({...c,index:c.index+n,originalIndex:c.index}));const r=e[0].index,o=e[e.length-1].index,s=[],i=fs(t.groupOffsetTree,r,o);let a,l=0;for(const c of e){(!a||a.end<c.index)&&(a=i.shift(),l=t.groupIndices.indexOf(a.start));let d;c.index===a.start?d={index:l,type:"group"}:d={groupIndex:l,index:c.index-(l+1)+n},s.push({...d,data:c.data,offset:c.offset,originalIndex:c.index,size:c.size})}return s}const er=Ke(([{data:e,firstItemIndex:t,gap:n,sizes:r,totalCount:o},s,{listBoundary:i,topListHeight:a,visibleRange:l},{initialTopMostItemIndex:c,scrolledToInitialItem:d},{topListHeight:f},h,{didMount:p},{recalcInProgress:m}])=>{const g=ee([]),y=ee(0),x=ze();he(s.topItemsIndexes,g);const b=At(W(bt(p,m,Te(l,Gr),Te(o),Te(r),Te(c),d,Te(g),Te(t),Te(n),e),ke(([T,I,,A,,,,,,,N])=>{const L=N&&N.length!==A;return T&&!I&&!L}),ce(([,,[T,I],A,N,L,R,O,F,_,B])=>{const j=N,{offsetTree:K,sizeTree:z}=j,M=vt(y);if(A===0)return{...da,totalCount:A};if(T===0&&I===0)return M===0?{...da,totalCount:A}:Vd(M,L,N,F,_,B||[]);if(ot(z))return M>0?null:ys(s0(ca(L,A),j,B),[],A,_,j,F);const G=[];if(O.length>0){const Y=O[0],U=O[O.length-1];let J=0;for(const $ of fs(z,Y,U)){const q=$.value,Z=Math.max($.start,Y),ue=Math.min($.end,U);for(let ie=Z;ie<=ue;ie++)G.push({data:B==null?void 0:B[ie],index:ie,offset:J,size:q}),J+=q}}if(!R)return ys([],G,A,_,j,F);const X=O.length>0?O[O.length-1]+1:0,se=qw(K,T,I,X);if(se.length===0)return null;const be=A-1,Ie=ds([],Y=>{for(const U of se){const J=U.value;let $=J.offset,q=U.start;const Z=J.size;if(J.offset<T){q+=Math.floor((T-J.offset+_)/(Z+_));const ie=q-U.start;$+=ie*Z+ie*_}q<X&&($+=(X-q)*Z,q=X);const ue=Math.min(U.end,be);for(let ie=q;ie<=ue&&!($>=I);ie++)Y.push({data:B==null?void 0:B[ie],index:ie,offset:$,size:Z}),$+=Z+_}});return ys(Ie,G,A,_,j,F)}),ke(T=>T!==null),ct()),da);he(W(e,ke(Ji),ce(T=>T==null?void 0:T.length)),o),he(W(b,ce(T=>T.topListHeight)),f),he(f,a),he(W(b,ce(T=>[T.top,T.bottom])),i),he(W(b,ce(T=>T.items)),x);const S=Ht(W(b,ke(({items:T})=>T.length>0),Le(o,e),ke(([{items:T},I])=>T[T.length-1].originalIndex===I-1),ce(([,T,I])=>[T-1,I]),ct(Gr),ce(([T])=>T))),k=Ht(W(b,En(200),ke(({items:T,topItems:I})=>T.length>0&&T[0].originalIndex===I.length),ce(({items:T})=>T[0].index),ct())),C=Ht(W(b,ke(({items:T})=>T.length>0),ce(({items:T})=>{let I=0,A=T.length-1;for(;T[I].type==="group"&&I<A;)I++;for(;T[A].type==="group"&&A>I;)A--;return{endIndex:T[A].index,startIndex:T[I].index}}),ct(Pd)));return{endReached:S,initialItemCount:y,itemsRendered:x,listState:b,rangeChanged:C,startReached:k,topItemsIndexes:g,...h}},lt(bn,Fd,ua,Jr,Xr,eo,Dn,sa),{singleton:!0}),qd=Ke(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:o}])=>{const s=ze(),i=At(W(bt(n,e,r,t,o),ce(([a,l,c,d,f])=>a+l+c+d+f.offsetBottom+f.bottom)),0);return he(Te(i),s),{totalListHeight:i,totalListHeightChanged:s}},lt(Dt,er),{singleton:!0}),i0=Ke(([{viewportHeight:e},{totalListHeight:t}])=>{const n=ee(!1),r=At(W(bt(n,e,t),ke(([o])=>o),ce(([,o,s])=>Math.max(0,o-s)),En(0),ct()),0);return{alignToBottom:n,paddingTopAddition:r}},lt(Dt,qd),{singleton:!0}),Gd=Ke(()=>({context:ee(null)})),a0=({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,Yd=Ke(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:s,scrollingInProgress:i,scrollTop:a,viewportHeight:l},{scrollToIndex:c}])=>{const d=ze();return he(W(d,Le(t,l,n,s,o,r,a),Le(e),ce(([[f,h,p,m,g,y,x,b],S])=>{const{align:k,behavior:C,calculateViewLocation:T=a0,done:I,...A}=f,N=Ld(f,h,m-1),L=Yr(N,h.offsetTree,S)+g+y,R=L+ln(h.sizeTree,N)[1],O=b+y,F=b+p-x,_=T({itemBottom:R,itemTop:L,locationParams:{align:k,behavior:C,...A},viewportBottom:F,viewportTop:O});return _?I&&an(W(i,ke(B=>!B),Jn(vt(i)?1:2)),I):I&&I(),_}),ke(f=>f!==null)),c),{scrollIntoView:d}},lt(bn,Dt,Xr,er,Pn),{singleton:!0});function Xd(e){return e?e==="smooth"?"smooth":"auto":!1}const l0=(e,t)=>typeof e=="function"?Xd(e(t)):t&&Xd(e),c0=Ke(([{listRefresh:e,totalCount:t,fixedItemSize:n,data:r},{atBottomState:o,isAtBottom:s},{scrollToIndex:i},{scrolledToInitialItem:a},{didMount:l,propsReady:c},{log:d},{scrollingInProgress:f},{context:h},{scrollIntoView:p}])=>{const m=ee(!1),g=ze();let y=null;function x(C){Pe(i,{align:"end",behavior:C,index:"LAST"})}Qe(W(bt(W(Te(t),Jn(1)),l),Le(Te(m),s,a,f),ce(([[C,T],I,A,N,L])=>{let R=T&&N,O="auto";return R&&(O=l0(I,A||L),R=R&&!!O),{followOutputBehavior:O,shouldFollow:R,totalCount:C}}),ke(({shouldFollow:C})=>C)),({followOutputBehavior:C,totalCount:T})=>{y&&(y(),y=null),vt(n)?requestAnimationFrame(()=>{vt(d)("following output to ",{totalCount:T},Bt.DEBUG),x(C)}):y=an(e,()=>{vt(d)("following output to ",{totalCount:T},Bt.DEBUG),x(C),y=null})});function b(C){const T=an(o,I=>{C&&!I.atBottom&&I.notAtBottomBecause==="SIZE_INCREASED"&&!y&&(vt(d)("scrolling to bottom due to increased size",{},Bt.DEBUG),x("auto"))});setTimeout(T,100)}Qe(W(bt(Te(m),t,c),ke(([C,,T])=>C&&T),vn(({value:C},[,T])=>({refreshed:C===T,value:T}),{refreshed:!1,value:0}),ke(({refreshed:C})=>C),Le(m,t)),([,C])=>{vt(a)&&b(C!==!1)}),Qe(g,()=>{b(vt(m)!==!1)}),Qe(bt(Te(m),o),([C,T])=>{C&&!T.atBottom&&T.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&x("auto")});const S=ee(null),k=ze();return he(Qi(W(Te(r),ce(C=>{var T;return(T=C==null?void 0:C.length)!=null?T:0})),W(Te(t))),k),Qe(W(bt(W(k,Jn(1)),l),Le(Te(S),a,f,h),ce(([[C,T],I,A,N,L])=>T&&A&&(I==null?void 0:I({context:L,totalCount:C,scrollingInProgress:N}))),ke(C=>!!C),En(0)),C=>{y&&(y(),y=null),vt(n)?requestAnimationFrame(()=>{vt(d)("scrolling into view",{}),Pe(p,C)}):y=an(e,()=>{vt(d)("scrolling into view",{}),Pe(p,C),y=null})}),{autoscrollToBottom:g,followOutput:m,scrollIntoViewOnChange:S}},lt(bn,eo,Xr,Jr,Dn,Pn,Dt,Gd,Yd)),u0=Ke(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:s,listState:i},{didMount:a}])=>(he(W(a,Le(s),ke(([,l])=>l!==0),Le(o,r,t,n,e),ce(([[,l],c,d,f,h,p=[]])=>Vd(l,c,d,f,h,p))),i),{}),lt(bn,Jr,er,Dn),{singleton:!0}),d0=Ke(([{didMount:e},{scrollTo:t},{listState:n}])=>{const r=ee(0);return Qe(W(e,Le(r),ke(([,o])=>o!==0),ce(([,o])=>({top:o}))),o=>{an(W(n,Jn(1),ke(s=>s.items.length>1)),()=>{requestAnimationFrame(()=>{Pe(t,o)})})}),{initialScrollTop:r}},lt(Dn,Dt,er),{singleton:!0}),Jd=Ke(([{scrollVelocity:e}])=>{const t=ee(!1),n=ze(),r=ee(!1);return he(W(e,Le(r,t,n),ke(([o,s])=>!!s),ce(([o,s,i,a])=>{const{enter:l,exit:c}=s;if(i){if(c(o,a))return!1}else if(l(o,a))return!0;return i}),ct()),t),Qe(W(bt(t,e,n),Le(r)),([[o,s,i],a])=>{o&&a&&a.change&&a.change(s,i)}),{isSeeking:t,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:e}},lt(eo),{singleton:!0}),fa=Ke(([{scrollContainerState:e,scrollTo:t}])=>{const n=ze(),r=ze(),o=ze(),s=ee(!1),i=ee(void 0);return he(W(bt(n,r),ce(([{scrollHeight:a,scrollTop:l,viewportHeight:c},{offsetTop:d}])=>({scrollHeight:a,scrollTop:Math.max(0,l-d),viewportHeight:c}))),e),he(W(t,Le(r),ce(([a,{offsetTop:l}])=>({...a,top:a.top+l}))),o),{customScrollParent:i,useWindowScroll:s,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:r}},lt(Dt)),f0=Ke(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:o},{didMount:s},{useWindowScroll:i,windowScrollContainerState:a,windowViewportRect:l}])=>{const c=ze(),d=ee(void 0),f=ee(null),h=ee(null);return he(a,f),he(l,h),Qe(W(c,Le(t,r,i,f,h,n)),([p,m,g,y,x,b,S])=>{const k=Yw(m.sizeTree);y&&x!==null&&b!==null&&(g=x.scrollTop-b.offsetTop),g-=S,p({ranges:k,scrollTop:g})}),he(W(d,ke(Ji),ce(p0)),o),he(W(s,Le(d),ke(([,p])=>p!==void 0),ct(),ce(([,p])=>p.ranges)),e),{getState:c,restoreStateFrom:d}},lt(bn,Dt,Jr,Dn,fa));function p0(e){return{align:"start",index:0,offset:e.scrollTop}}const h0=Ke(([{topItemsIndexes:e}])=>{const t=ee(0);return he(W(t,ke(n=>n>=0),ce(n=>Array.from({length:n}).map((r,o)=>o))),e),{topItemCount:t}},lt(er));function Zd(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const m0=Zd(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),g0=Ke(([{deviation:e,scrollBy:t,scrollingInProgress:n,scrollTop:r},{isAtBottom:o,isScrolling:s,lastJumpDueToItemResize:i,scrollDirection:a},{listState:l},{beforeUnshiftWith:c,gap:d,shiftWithOffset:f,sizes:h},{log:p},{recalcInProgress:m}])=>{const g=Ht(W(l,Le(i),vn(([,x,b,S],[{bottom:k,items:C,offsetBottom:T,totalCount:I},A])=>{const N=k+T;let L=0;return b===I&&x.length>0&&C.length>0&&(C[0].originalIndex===0&&x[0].originalIndex===0||(L=N-S,L!==0&&(L+=A))),[L,C,I,N]},[0,[],0,0]),ke(([x])=>x!==0),Le(r,a,n,o,p,m),ke(([,x,b,S,,,k])=>!k&&!S&&x!==0&&b===Zr),ce(([[x],,,,,b])=>(b("Upward scrolling compensation",{amount:x},Bt.DEBUG),x))));function y(x){x>0?(Pe(t,{behavior:"auto",top:-x}),Pe(e,0)):(Pe(e,0),Pe(t,{behavior:"auto",top:-x}))}return Qe(W(g,Le(e,s)),([x,b,S])=>{S&&m0()?Pe(e,b-x):y(-x)}),Qe(W(bt(At(s,!1),e,m),ke(([x,b,S])=>!x&&!S&&b!==0),ce(([x,b])=>b),En(1)),y),he(W(f,ce(x=>({top:-x}))),t),Qe(W(c,Le(h,d),ce(([x,{groupIndices:b,lastSize:S,sizeTree:k},C])=>{function T(I){return I*(S+C)}if(b.length===0)return T(x);{let I=0;const A=qr(k,0);let N=0,L=0;for(;N<x;){N++,I+=A;let R=b.length===L+1?1/0:b[L+1]-b[L]-1;N+R>x&&(I-=A,R=x-N+1),N+=R,I+=T(R),L++}return I}})),x=>{Pe(e,x),requestAnimationFrame(()=>{Pe(t,{top:x}),requestAnimationFrame(()=>{Pe(e,0),Pe(m,!1)})})}),{deviation:e}},lt(Dt,eo,er,bn,Pn,sa)),x0=Ke(([e,t,n,r,o,s,i,a,l,c,d])=>({...e,...t,...n,...r,...o,...s,...i,...a,...l,...c,...d}),lt(ua,u0,Dn,Jd,qd,d0,i0,fa,Yd,Pn,Gd)),Qd=Ke(([{data:e,defaultItemSize:t,firstItemIndex:n,fixedItemSize:r,gap:o,groupIndices:s,itemSize:i,sizeRanges:a,sizes:l,statefulTotalCount:c,totalCount:d,trackItemSizes:f},{initialItemFinalLocationReached:h,initialTopMostItemIndex:p,scrolledToInitialItem:m},g,y,x,{listState:b,topItemsIndexes:S,...k},{scrollToIndex:C},T,{topItemCount:I},{groupCounts:A},N])=>(he(k.rangeChanged,N.scrollSeekRangeChanged),he(W(N.windowViewportRect,ce(L=>L.visibleHeight)),g.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:n,fixedItemHeight:r,gap:o,groupCounts:A,initialItemFinalLocationReached:h,initialTopMostItemIndex:p,scrolledToInitialItem:m,sizeRanges:a,topItemCount:I,topItemsIndexes:S,totalCount:d,...x,groupIndices:s,itemSize:i,listState:b,scrollToIndex:C,statefulTotalCount:c,trackItemSizes:f,...k,...N,...g,sizes:l,...y}),lt(bn,Jr,Dt,f0,c0,er,Xr,g0,h0,Fd,x0));function y0(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 vs=typeof document<"u"?w.useLayoutEffect:w.useEffect;function ef(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(y,x){y.propsReady&&Pe(y.propsReady,!1);for(const b of r){const S=y[t.required[b]];Pe(S,x[b])}for(const b of o)if(b in x){const S=y[t.optional[b]];Pe(S,x[b])}y.propsReady&&Pe(y.propsReady,!0)}function c(y){return s.reduce((x,b)=>(x[b]=S=>{const k=y[t.methods[b]];Pe(k,S)},x),{})}function d(y){return i.reduce((x,b)=>(x[b]=Pw(y[t.events[b]]),x),{})}const f=w.forwardRef((y,x)=>{const{children:b,...S}=y,[k]=w.useState(()=>ds(Dw(e),I=>{l(I,S)})),[C]=w.useState(Cd(d,k));vs(()=>{for(const I of i)I in S&&Qe(C[I],S[I]);return()=>{Object.values(C).map(Zi)}},[S,C,k]),vs(()=>{l(k,S)}),w.useImperativeHandle(x,wd(c(k)));const T=n;return u.jsx(a.Provider,{value:k,children:n?u.jsx(T,{...y0([...r,...o,...i],S),children:b}):b})}),h=y=>{const x=w.useContext(a);return w.useCallback(b=>{Pe(x[y],b)},[x,y])},p=y=>{const x=w.useContext(a)[y],b=w.useCallback(S=>Qe(x,S),[x]);return w.useSyncExternalStore(b,()=>vt(x),()=>vt(x))},m=y=>{const x=w.useContext(a)[y],[b,S]=w.useState(Cd(vt,x));return vs(()=>Qe(x,k=>{k!==b&&S(wd(k))}),[x,b]),b},g=w.version.startsWith("18")?p:m;return{Component:f,useEmitter:(y,x)=>{const b=w.useContext(a)[y];vs(()=>Qe(b,x),[x,b])},useEmitterValue:g,usePublisher:h}}const tf=w.createContext(void 0),nf=w.createContext(void 0),rf=typeof document<"u"?w.useLayoutEffect:w.useEffect;function pa(e){return"self"in e}function v0(e){return"body"in e}function of(e,t,n,r=Cr,o,s){const i=w.useRef(null),a=w.useRef(null),l=w.useRef(null),c=w.useCallback(h=>{let p,m,g;const y=h.target;if(v0(y)||pa(y)){const b=pa(y)?y:y.defaultView;g=s?b.scrollX:b.scrollY,p=s?b.document.documentElement.scrollWidth:b.document.documentElement.scrollHeight,m=s?b.innerWidth:b.innerHeight}else g=s?y.scrollLeft:y.scrollTop,p=s?y.scrollWidth:y.scrollHeight,m=s?y.offsetWidth:y.offsetHeight;const x=()=>{e({scrollHeight:p,scrollTop:Math.max(g,0),viewportHeight:m})};h.suppressFlushSync?x():Gs.flushSync(x),a.current!==null&&(g===a.current||g<=0||g===p-m)&&(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),c({suppressFlushSync:!0,target:h}),h.addEventListener("scroll",c,{passive:!0}),()=>{r(null),h.removeEventListener("scroll",c)}},[i,c,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 m=h.behavior==="smooth";let g,y,x;pa(p)?(y=Math.max(On(p.document.documentElement,s?"width":"height"),s?p.document.documentElement.scrollWidth:p.document.documentElement.scrollHeight),g=s?p.innerWidth:p.innerHeight,x=s?window.scrollX:window.scrollY):(y=p[s?"scrollWidth":"scrollHeight"],g=On(p,s?"width":"height"),x=p[s?"scrollLeft":"scrollTop"]);const b=y-g;if(h.top=Math.ceil(Math.max(Math.min(b,h.top),0)),zd(g,y)||h.top===x){e({scrollHeight:y,scrollTop:x,viewportHeight:g}),m&&t(!0);return}m?(a.current=h.top,l.current&&clearTimeout(l.current),l.current=setTimeout(()=>{l.current=null,a.current=null,t(!0)},1e3)):a.current=null,s&&(h={behavior:h.behavior,left:h.top}),p.scrollTo(h)}function f(h){s&&(h={behavior:h.behavior,left:h.top}),i.current.scrollBy(h)}return{scrollByCallback:f,scrollerRef:i,scrollToCallback:d}}const ha="-webkit-sticky",sf="sticky",ma=Zd(()=>{if(typeof document>"u")return sf;const e=document.createElement("div");return e.style.position=ha,e.style.position===ha?ha:sf});function ga(e){return e}const b0=Ke(()=>{const e=ee(a=>`Item ${a}`),t=ee(a=>`Group ${a}`),n=ee({}),r=ee(ga),o=ee("div"),s=ee(Cr),i=(a,l=null)=>At(W(n,ce(c=>c[a]),ct()),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")}}),w0=Ke(([e,t])=>({...e,...t}),lt(Qd,b0)),S0=({height:e})=>u.jsx("div",{style:{height:e}}),C0={overflowAnchor:"none",position:ma(),zIndex:1},af={overflowAnchor:"none"},T0={...af,display:"inline-block",height:"100%"},lf=w.memo(function({showTopList:e=!1}){const t=Ae("listState"),n=Zt("sizeRanges"),r=Ae("useWindowScroll"),o=Ae("customScrollParent"),s=Zt("windowScrollContainerState"),i=Zt("scrollContainerState"),a=o||r?s:i,l=Ae("itemContent"),c=Ae("context"),d=Ae("groupContent"),f=Ae("trackItemSizes"),h=Ae("itemSize"),p=Ae("log"),m=Zt("gap"),g=Ae("horizontalDirection"),{callbackRef:y}=Fw(n,h,f,e?Cr:a,p,m,o,g,Ae("skipAnimationFrameInResizeObserver")),[x,b]=w.useState(0);xa("deviation",_=>{x!==_&&b(_)});const S=Ae("EmptyPlaceholder"),k=Ae("ScrollSeekPlaceholder")||S0,C=Ae("ListComponent"),T=Ae("ItemComponent"),I=Ae("GroupComponent"),A=Ae("computeItemKey"),N=Ae("isSeeking"),L=Ae("groupIndices").length>0,R=Ae("alignToBottom"),O=Ae("initialItemFinalLocationReached"),F=e?{}:{boxSizing:"border-box",...g?{display:"inline-block",height:"100%",marginLeft:x!==0?x:R?"auto":0,paddingLeft:t.offsetTop,paddingRight:t.offsetBottom,whiteSpace:"nowrap"}:{marginTop:x!==0?x:R?"auto":0,paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},...O?{}:{visibility:"hidden"}};return!e&&t.totalCount===0&&S?u.jsx(S,{...Nt(S,c)}):u.jsx(C,{...Nt(C,c),"data-testid":e?"virtuoso-top-item-list":"virtuoso-item-list",ref:y,style:F,children:(e?t.topItems:t.items).map(_=>{const B=_.originalIndex,j=A(B+t.firstItemIndex,_.data,c);return N?w.createElement(k,{...Nt(k,c),height:_.size,index:_.index,key:j,type:_.type||"item",..._.type==="group"?{}:{groupIndex:_.groupIndex}}):_.type==="group"?w.createElement(I,{...Nt(I,c),"data-index":B,"data-item-index":_.index,"data-known-size":_.size,key:j,style:C0},d(_.index,c)):w.createElement(T,{...Nt(T,c),...A0(T,_.data),"data-index":B,"data-item-group-index":_.groupIndex,"data-item-index":_.index,"data-known-size":_.size,key:j,style:g?T0:af},L?l(_.index,_.groupIndex,_.data,c):l(_.index,_.data,c))})})}),k0={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},I0={outline:"none",overflowX:"auto",position:"relative"},bs=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),E0={position:ma(),top:0,width:"100%",zIndex:1};function Nt(e,t){if(typeof e!="string")return{context:t}}function A0(e,t){return{item:typeof e=="string"?void 0:t}}const N0=w.memo(function(){const e=Ae("HeaderComponent"),t=Zt("headerHeight"),n=Ae("HeaderFooterTag"),r=Zn(w.useMemo(()=>s=>{t(On(s,"height"))},[t]),!0,Ae("skipAnimationFrameInResizeObserver")),o=Ae("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...Nt(e,o)})}):null}),_0=w.memo(function(){const e=Ae("FooterComponent"),t=Zt("footerHeight"),n=Ae("HeaderFooterTag"),r=Zn(w.useMemo(()=>s=>{t(On(s,"height"))},[t]),!0,Ae("skipAnimationFrameInResizeObserver")),o=Ae("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...Nt(e,o)})}):null});function cf({useEmitter:e,useEmitterValue:t,usePublisher:n}){return w.memo(function({children:r,style:o,context:s,...i}){const a=n("scrollContainerState"),l=t("ScrollerComponent"),c=n("smoothScrollTargetReached"),d=t("scrollerRef"),f=t("horizontalDirection")||!1,{scrollByCallback:h,scrollerRef:p,scrollToCallback:m}=of(a,c,l,d,void 0,f);return e("scrollTo",m),e("scrollBy",h),u.jsx(l,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:p,style:{...f?I0:k0,...o},tabIndex:0,...i,...Nt(l,s),children:r})})}function uf({useEmitter:e,useEmitterValue:t,usePublisher:n}){return w.memo(function({children:r,style:o,context:s,...i}){const a=n("windowScrollContainerState"),l=t("ScrollerComponent"),c=n("smoothScrollTargetReached"),d=t("totalListHeight"),f=t("deviation"),h=t("customScrollParent"),p=w.useRef(null),m=t("scrollerRef"),{scrollByCallback:g,scrollerRef:y,scrollToCallback:x}=of(a,c,l,m,h);return rf(()=>{var b;return y.current=h||((b=p.current)==null?void 0:b.ownerDocument.defaultView),()=>{y.current=null}},[y,h]),e("windowScrollTo",x),e("scrollBy",g),u.jsx(l,{ref:p,"data-virtuoso-scroller":!0,style:{position:"relative",...o,...d!==0?{height:d+f}:{}},...i,...Nt(l,s),children:r})})}const j0=({children:e})=>{const t=w.useContext(tf),n=Zt("viewportHeight"),r=Zt("fixedItemHeight"),o=Ae("alignToBottom"),s=Ae("horizontalDirection"),i=w.useMemo(()=>Sd(n,l=>On(l,s?"width":"height")),[n,s]),a=Zn(i,!0,Ae("skipAnimationFrameInResizeObserver"));return w.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),u.jsx("div",{"data-viewport-type":"element",ref:a,style:bs(o),children:e})},M0=({children:e})=>{const t=w.useContext(tf),n=Zt("windowViewportRect"),r=Zt("fixedItemHeight"),o=Ae("customScrollParent"),s=Ed(n,o,Ae("skipAnimationFrameInResizeObserver")),i=Ae("alignToBottom");return w.useEffect(()=>{t&&(r(t.itemHeight),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:100}))},[t,n,r]),u.jsx("div",{"data-viewport-type":"window",ref:s,style:bs(i),children:e})},R0=({children:e})=>{const t=Ae("TopItemListComponent")||"div",n=Ae("headerHeight"),r={...E0,marginTop:`${n}px`},o=Ae("context");return u.jsx(t,{style:r,...Nt(t,o),children:e})},P0=w.memo(function(e){const t=Ae("useWindowScroll"),n=Ae("topItemsIndexes").length>0,r=Ae("customScrollParent"),o=Ae("context");return u.jsxs(r||t?L0:D0,{...e,context:o,children:[n&&u.jsx(R0,{children:u.jsx(lf,{showTopList:!0})}),u.jsxs(r||t?M0:j0,{children:[u.jsx(N0,{}),u.jsx(lf,{}),u.jsx(_0,{})]})]})}),{Component:O0,useEmitter:xa,useEmitterValue:Ae,usePublisher:Zt}=ef(w0,{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"}},P0),D0=cf({useEmitter:xa,useEmitterValue:Ae,usePublisher:Zt}),L0=uf({useEmitter:xa,useEmitterValue:Ae,usePublisher:Zt}),$0=O0;lt(Qd,Ke(()=>{const e=ee(c=>u.jsxs("td",{children:["Item $",c]})),t=ee(null),n=ee(c=>u.jsxs("td",{colSpan:1e3,children:["Group ",c]})),r=ee(null),o=ee(null),s=ee({}),i=ee(ga),a=ee(Cr),l=(c,d=null)=>At(W(s,ce(f=>f[c]),ct()),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")}})),ma();const df={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},F0={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:ff,floor:ws,max:to,min:ya,round:pf}=Math;function hf(e,t,n){return Array.from({length:t-e+1}).map((r,o)=>({data:n===null?null:n[o+e],index:o+e}))}function B0(e){return{...F0,items:e}}function Ss(e,t){return e&&e.width===t.width&&e.height===t.height}function z0(e,t){return e&&e.column===t.column&&e.row===t.row}const U0=Ke(([{increaseViewportBy:e,listBoundary:t,overscan:n,visibleRange:r},{footerHeight:o,headerHeight:s,scrollBy:i,scrollContainerState:a,scrollTo:l,scrollTop:c,smoothScrollTargetReached:d,viewportHeight:f},h,p,{didMount:m,propsReady:g},{customScrollParent:y,useWindowScroll:x,windowScrollContainerState:b,windowScrollTo:S,windowViewportRect:k},C])=>{const T=ee(0),I=ee(0),A=ee(df),N=ee({height:0,width:0}),L=ee({height:0,width:0}),R=ze(),O=ze(),F=ee(0),_=ee(null),B=ee({column:0,row:0}),j=ze(),K=ze(),z=ee(!1),M=ee(0),G=ee(!0),X=ee(!1),se=ee(!1);Qe(W(m,Le(M),ke(([$,q])=>!!q)),()=>{Pe(G,!1)}),Qe(W(bt(m,G,L,N,M,X),ke(([$,q,Z,ue,,ie])=>$&&!q&&Z.height!==0&&ue.height!==0&&!ie)),([,,,,$])=>{Pe(X,!0),la(1,()=>{Pe(R,$)}),an(W(c),()=>{Pe(t,[0,0]),Pe(G,!0)})}),he(W(K,ke($=>$!=null&&$.scrollTop>0),yn(0)),I),Qe(W(m,Le(K),ke(([,$])=>$!=null)),([,$])=>{$&&(Pe(N,$.viewport),Pe(L,$.item),Pe(B,$.gap),$.scrollTop>0&&(Pe(z,!0),an(W(c,Jn(1)),q=>{Pe(z,!1)}),Pe(l,{top:$.scrollTop})))}),he(W(N,ce(({height:$})=>$)),f),he(W(bt(Te(N,Ss),Te(L,Ss),Te(B,($,q)=>$&&$.column===q.column&&$.row===q.row),Te(c)),ce(([$,q,Z,ue])=>({gap:Z,item:q,scrollTop:ue,viewport:$}))),j),he(W(bt(Te(T),r,Te(B,z0),Te(L,Ss),Te(N,Ss),Te(_),Te(I),Te(z),Te(G),Te(M)),ke(([,,,,,,,$])=>!$),ce(([$,[q,Z],ue,ie,_e,He,oe,,ye,Oe])=>{const{column:Ye,row:nt}=ue,{height:Xe,width:qe}=ie,{width:it}=_e;if(oe===0&&($===0||it===0))return df;if(qe===0){const Mt=ca(Oe,$),Lt=Mt+Math.max(oe-1,0);return B0(hf(Mt,Lt,He))}const Je=mf(it,qe,Ye);let et,at;ye?q===0&&Z===0&&oe>0?(et=0,at=oe-1):(et=Je*ws((q+nt)/(Xe+nt)),at=Je*ff((Z+nt)/(Xe+nt))-1,at=ya($-1,to(at,Je-1)),et=ya(at,to(0,et))):(et=0,at=-1);const jt=hf(et,at,He),{bottom:ht,top:ft}=gf(_e,ue,ie,jt),mt=ff($/Je),St=mt*Xe+(mt-1)*nt-ht;return{bottom:ht,itemHeight:Xe,items:jt,itemWidth:qe,offsetBottom:St,offsetTop:ft,top:ft}})),A),he(W(_,ke($=>$!==null),ce($=>$.length)),T),he(W(bt(N,L,A,B),ke(([$,q,{items:Z}])=>Z.length>0&&q.height!==0&&$.height!==0),ce(([$,q,{items:Z},ue])=>{const{bottom:ie,top:_e}=gf($,ue,q,Z);return[_e,ie]}),ct(Gr)),t);const be=ee(!1);he(W(c,Le(be),ce(([$,q])=>q||$!==0)),be);const Ie=Ht(W(bt(A,T),ke(([{items:$}])=>$.length>0),Le(be),ke(([[$,q],Z])=>{const ue=$.items[$.items.length-1].index===q-1;return(Z||$.bottom>0&&$.itemHeight>0&&$.offsetBottom===0&&$.items.length===q)&&ue}),ce(([[,$]])=>$-1),ct())),Y=Ht(W(Te(A),ke(({items:$})=>$.length>0&&$[0].index===0),yn(0),ct())),U=Ht(W(Te(A),Le(z),ke(([{items:$},q])=>$.length>0&&!q),ce(([{items:$}])=>({endIndex:$[$.length-1].index,startIndex:$[0].index})),ct(Pd),En(0)));he(U,p.scrollSeekRangeChanged),he(W(R,Le(N,L,T,B),ce(([$,q,Z,ue,ie])=>{const _e=Bd($),{align:He,behavior:oe,offset:ye}=_e;let Oe=_e.index;Oe==="LAST"&&(Oe=ue-1),Oe=to(0,Oe,ya(ue-1,Oe));let Ye=va(q,ie,Z,Oe);return He==="end"?Ye=pf(Ye-q.height+Z.height):He==="center"&&(Ye=pf(Ye-q.height/2+Z.height/2)),ye&&(Ye+=ye),{behavior:oe,top:Ye}})),l);const J=At(W(A,ce($=>$.offsetBottom+$.bottom)),0);return he(W(k,ce($=>({height:$.visibleHeight,width:$.visibleWidth}))),N),{customScrollParent:y,data:_,deviation:F,footerHeight:o,gap:B,headerHeight:s,increaseViewportBy:e,initialItemCount:I,itemDimensions:L,overscan:n,restoreStateFrom:K,scrollBy:i,scrollContainerState:a,scrollHeight:O,scrollTo:l,scrollToIndex:R,scrollTop:c,smoothScrollTargetReached:d,totalCount:T,useWindowScroll:x,viewportDimensions:N,windowScrollContainerState:b,windowScrollTo:S,windowViewportRect:k,...p,gridState:A,horizontalDirection:se,initialTopMostItemIndex:M,totalListHeight:J,...h,endReached:Ie,propsReady:g,rangeChanged:U,startReached:Y,stateChanged:j,stateRestoreInProgress:z,...C}},lt(ua,Dt,eo,Jd,Dn,fa,Pn));function mf(e,t,n){return to(1,ws((e+n)/(ws(t)+n)))}function gf(e,t,n,r){const{height:o}=n;if(o===void 0||r.length===0)return{bottom:0,top:0};const s=va(e,t,n,r[0].index);return{bottom:va(e,t,n,r[r.length-1].index)+o,top:s}}function va(e,t,n,r){const o=mf(e.width,n.width,t.column),s=ws(r/o),i=s*n.height+to(0,s-1)*t.row;return i>0?i+t.row:i}const H0=Ke(()=>{const e=ee(f=>`Item ${f}`),t=ee({}),n=ee(null),r=ee("virtuoso-grid-item"),o=ee("virtuoso-grid-list"),s=ee(ga),i=ee("div"),a=ee(Cr),l=(f,h=null)=>At(W(t,ce(p=>p[f]),ct()),h),c=ee(!1),d=ee(!1);return he(Te(d),c),{components:t,computeItemKey:s,context:n,FooterComponent:l("Footer"),HeaderComponent:l("Header"),headerFooterTag:i,itemClassName:r,ItemComponent:l("Item","div"),itemContent:e,listClassName:o,ListComponent:l("List","div"),readyStateChanged:c,reportReadyState:d,ScrollerComponent:l("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder","div")}}),W0=Ke(([e,t])=>({...e,...t}),lt(U0,H0)),V0=w.memo(function(){const e=dt("gridState"),t=dt("listClassName"),n=dt("itemClassName"),r=dt("itemContent"),o=dt("computeItemKey"),s=dt("isSeeking"),i=Qt("scrollHeight"),a=dt("ItemComponent"),l=dt("ListComponent"),c=dt("ScrollSeekPlaceholder"),d=dt("context"),f=Qt("itemDimensions"),h=Qt("gap"),p=dt("log"),m=dt("stateRestoreInProgress"),g=Qt("reportReadyState"),y=Zn(w.useMemo(()=>x=>{const b=x.parentElement.parentElement.scrollHeight;i(b);const S=x.firstChild;if(S){const{height:k,width:C}=S.getBoundingClientRect();f({height:k,width:C})}h({column:yf("column-gap",getComputedStyle(x).columnGap,p),row:yf("row-gap",getComputedStyle(x).rowGap,p)})},[i,f,h,p]),!0,!1);return rf(()=>{e.itemHeight>0&&e.itemWidth>0&&g(!0)},[e]),m?null:u.jsx(l,{className:t,ref:y,...Nt(l,d),"data-testid":"virtuoso-item-list",style:{paddingBottom:e.offsetBottom,paddingTop:e.offsetTop},children:e.items.map(x=>{const b=o(x.index,x.data,d);return s?u.jsx(c,{...Nt(c,d),height:e.itemHeight,index:x.index,width:e.itemWidth},b):w.createElement(a,{...Nt(a,d),className:n,"data-index":x.index,key:b},r(x.index,x.data,d))})})}),K0=w.memo(function(){const e=dt("HeaderComponent"),t=Qt("headerHeight"),n=dt("headerFooterTag"),r=Zn(w.useMemo(()=>s=>{t(On(s,"height"))},[t]),!0,!1),o=dt("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...Nt(e,o)})}):null}),q0=w.memo(function(){const e=dt("FooterComponent"),t=Qt("footerHeight"),n=dt("headerFooterTag"),r=Zn(w.useMemo(()=>s=>{t(On(s,"height"))},[t]),!0,!1),o=dt("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...Nt(e,o)})}):null}),G0=({children:e})=>{const t=w.useContext(nf),n=Qt("itemDimensions"),r=Qt("viewportDimensions"),o=Zn(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]),u.jsx("div",{ref:o,style:bs(!1),children:e})},Y0=({children:e})=>{const t=w.useContext(nf),n=Qt("windowViewportRect"),r=Qt("itemDimensions"),o=dt("customScrollParent"),s=Ed(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]),u.jsx("div",{ref:s,style:bs(!1),children:e})},X0=w.memo(function({...e}){const t=dt("useWindowScroll"),n=dt("customScrollParent"),r=n||t?Z0:J0,o=n||t?Y0:G0,s=dt("context");return u.jsx(r,{...e,...Nt(r,s),children:u.jsxs(o,{children:[u.jsx(K0,{}),u.jsx(V0,{}),u.jsx(q0,{})]})})}),{useEmitter:xf,useEmitterValue:dt,usePublisher:Qt}=ef(W0,{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"}},X0),J0=cf({useEmitter:xf,useEmitterValue:dt,usePublisher:Qt}),Z0=uf({useEmitter:xf,useEmitterValue:dt,usePublisher:Qt});function yf(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Bt.WARN),t==="normal"?0:parseInt(t??"0",10)}const Q0=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 vf({className:e,variant:t,...n}){return u.jsx("div",{className:te(Q0({variant:t}),e),...n})}function ba(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 bf(e){return!!(e&&typeof e=="object"&&(e.type==="file"||e.mimeType||e.filename||e.sourceType==="base64"))}function no(e){if(typeof e=="string")return e;if(e&&typeof e=="object"){if(Array.isArray(e)){const n=e.map(no).filter(r=>r!==void 0);if(!n.length){console.debug("[message-utils] sanitizeForDisplay - array emptied -> returning undefined",{originalLength:e.length});return}return n}if(bf(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=no(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 ro(e){if(typeof e=="string")return e;if(bf(e))return"";try{const t=no(e);return t===void 0?"":typeof t=="string"?t:JSON.stringify(t,null,2)}catch{return""}}function eS(e){return typeof e!="string"?!1:/^[\s\n]*[-*]\s|^[\s\n]*#+\s|```|^\s*\[.*\]\(|^>\s/.test(e)}function tS(e){const t=ro(e);return typeof e=="string"&&eS(e)?{content:e,isMarkdown:!0}:{content:t,isMarkdown:!1}}function Cs(e){if(e==null)return e;if(typeof e=="string"){const t=e.trim();if(t.startsWith("{")||t.startsWith("[")){const n=ba(t);if(n!==null)return Cs(n)}return e}return typeof e=="object"&&!Array.isArray(e)&&e.content!==void 0?Cs(e.content):e}function nS(e){return e.filter(t=>t.type==="text").map(t=>t.text).join("")}function wf(e){const t=e.content.find(s=>s.type==="tool_call"),n=e.additionalKwargs??{},r=typeof(t==null?void 0:t.id)=="string"&&t.id||typeof n.toolCallId=="string"&&n.toolCallId||(e.id.startsWith("tool-")?e.id.slice(5):void 0);return{name:(typeof(t==null?void 0:t.name)=="string"&&t.name||typeof n.toolName=="string"&&n.toolName||e.name&&String(e.name))??void 0,toolCallId:r??void 0}}function Ts(e){if(e==null)return null;const t=String(e).trim();return t.length>0?t:null}function rS(e){const t=r=>{try{const o=no(r);return typeof o=="string"?o:JSON.stringify(o??"")}catch{return""}},n=e.filter(r=>r.type==="text");return n.length?t(n.map(r=>r.text).join(`
|
|
87
|
+
`)):t(e)}function oS(e){return e.name&&e.name.trim()?e.name:e.model&&e.model.includes("/")?e.model.split("/").pop()||null:e.model||null}function Sf(e){if("type"in e&&e.type==="default_message")return`default:${e.content.length}`;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"interrupt":return"interrupt";default:return"unknown"}}).join("|"):"";return`${e.id}:${t}:${n}`}function sS(e){if(!e)return"image/png";const t=e.trim();return t?t.includes("/")?t:`image/${t}`:"image/png"}function iS(e){const t=[],n=r=>{r&&r.trim()&&t.push(r.trim())};return e&&(n(e.plotId),n(e.artifactId)),t}function aS({base64:e,url:t,formatHint:n,extras:r}){const o=typeof e=="string"&&e.length>0,s=sS(n),i=o?`data:${s};base64,${e}`:t,a=iS(r),l=a.length?a.join(" / "):void 0,c=l?`${l} artifact`:"artifact image";return{src:i,alt:c,label:l}}function lS(e){var o,s;const t=((o=e.content_base64)==null?void 0:o.trim())||void 0,n=((s=e.url)==null?void 0:s.trim())||void 0,r=e.format||e.mimeType||e.mime_type;return aS({base64:t,url:n,formatHint:r,extras:{plotId:e.plotId,artifactId:e.artifactId}})}async function Cf(e,t){return await Gt(e,{responseType:"blob",onDownloadProgress:r=>{try{t&&r.lengthComputable}catch{}},maxBodyLength:1/0})}async function Tf(e,t){return await(await Cf(`/files/${e}/view`,t)).text()}async function cS(e,t){const n=await Cf(`/files/${e}/download`,t),r=URL.createObjectURL(n);let o=`file_${e}`;try{const i=await Gt(`/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 uS(e,t=50,n=0){const r={limit:t,offset:n};return e&&(r.thread_id=e),await Gt("/files",{params:r})}var ks="Dialog",[kf,XT]=Cn(ks),[dS,cn]=kf(ks),If=e=>{const{__scopeDialog:t,children:n,open:r,defaultOpen:o,onOpenChange:s,modal:i=!0}=e,a=v.useRef(null),l=v.useRef(null),[c,d]=pr({prop:r,defaultProp:o??!1,onChange:s,caller:ks});return u.jsx(dS,{scope:t,triggerRef:a,contentRef:l,contentId:Tn(),titleId:Tn(),descriptionId:Tn(),open:c,onOpenChange:d,onOpenToggle:v.useCallback(()=>d(f=>!f),[d]),modal:i,children:n})};If.displayName=ks;var Ef="DialogTrigger",Af=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=cn(Ef,n),s=Be(t,o.triggerRef);return u.jsx(Ne.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":Ca(o.open),...r,ref:s,onClick:fe(e.onClick,o.onOpenToggle)})});Af.displayName=Ef;var wa="DialogPortal",[fS,Nf]=kf(wa,{forceMount:void 0}),_f=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:o}=e,s=cn(wa,t);return u.jsx(fS,{scope:t,forceMount:n,children:v.Children.map(r,i=>u.jsx(Xt,{present:n||s.open,children:u.jsx(qo,{asChild:!0,container:o,children:i})}))})};_f.displayName=wa;var Is="DialogOverlay",jf=v.forwardRef((e,t)=>{const n=Nf(Is,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=cn(Is,e.__scopeDialog);return s.modal?u.jsx(Xt,{present:r||s.open,children:u.jsx(hS,{...o,ref:t})}):null});jf.displayName=Is;var pS=Wn.createSlot("DialogOverlay.RemoveScroll"),hS=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=cn(Is,n);return u.jsx(ns,{as:pS,allowPinchZoom:!0,shards:[o.contentRef],children:u.jsx(Ne.div,{"data-state":Ca(o.open),...r,ref:t,style:{pointerEvents:"auto",...r.style}})})}),tr="DialogContent",Mf=v.forwardRef((e,t)=>{const n=Nf(tr,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=cn(tr,e.__scopeDialog);return u.jsx(Xt,{present:r||s.open,children:s.modal?u.jsx(mS,{...o,ref:t}):u.jsx(gS,{...o,ref:t})})});Mf.displayName=tr;var mS=v.forwardRef((e,t)=>{const n=cn(tr,e.__scopeDialog),r=v.useRef(null),o=Be(t,n.contentRef,r);return v.useEffect(()=>{const s=r.current;if(s)return Li(s)},[]),u.jsx(Rf,{...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())})}),gS=v.forwardRef((e,t)=>{const n=cn(tr,e.__scopeDialog),r=v.useRef(!1),o=v.useRef(!1);return u.jsx(Rf,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var i,a;(i=e.onCloseAutoFocus)==null||i.call(e,s),s.defaultPrevented||(r.current||(a=n.triggerRef.current)==null||a.focus(),s.preventDefault()),r.current=!1,o.current=!1},onInteractOutside:s=>{var l,c;(l=e.onInteractOutside)==null||l.call(e,s),s.defaultPrevented||(r.current=!0,s.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const i=s.target;((c=n.triggerRef.current)==null?void 0:c.contains(i))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&o.current&&s.preventDefault()}})}),Rf=v.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:s,...i}=e,a=cn(tr,n),l=v.useRef(null),c=Be(t,l);return yi(),u.jsxs(u.Fragment,{children:[u.jsx(Oo,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s,children:u.jsx(Po,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":Ca(a.open),...i,ref:c,onDismiss:()=>a.onOpenChange(!1)})}),u.jsxs(u.Fragment,{children:[u.jsx(xS,{titleId:a.titleId}),u.jsx(vS,{contentRef:l,descriptionId:a.descriptionId})]})]})}),Sa="DialogTitle",Pf=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=cn(Sa,n);return u.jsx(Ne.h2,{id:o.titleId,...r,ref:t})});Pf.displayName=Sa;var Of="DialogDescription",Df=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=cn(Of,n);return u.jsx(Ne.p,{id:o.descriptionId,...r,ref:t})});Df.displayName=Of;var Lf="DialogClose",$f=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=cn(Lf,n);return u.jsx(Ne.button,{type:"button",...r,ref:t,onClick:fe(e.onClick,()=>o.onOpenChange(!1))})});$f.displayName=Lf;function Ca(e){return e?"open":"closed"}var Ff="DialogTitleWarning",[JT,Bf]=px(Ff,{contentName:tr,titleName:Sa,docsSlug:"dialog"}),xS=({titleId:e})=>{const t=Bf(Ff),n=`\`${t.contentName}\` requires a \`${t.titleName}\` for the component to be accessible for screen reader users.
|
|
88
88
|
|
|
89
89
|
If you want to hide the \`${t.titleName}\`, you can wrap it with our VisuallyHidden component.
|
|
90
90
|
|
|
91
|
-
For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return v.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},cS="DialogDescriptionWarning",uS=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${Ff(cS).contentName}}.`;return v.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},Bf=kf,dS=Ef,zf=Nf,Is=_f,Es=jf,tr=Rf,As=Of,Uf=Lf;const fS=Bf,pS=zf,Hf=v.forwardRef(({className:e,...t},n)=>u.jsx(Is,{ref:n,className:te("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}));Hf.displayName=Is.displayName;const Wf=v.forwardRef(({className:e,children:t,...n},r)=>{const o=v.useMemo(()=>{let s=!1;function i(a){v.Children.forEach(a,l=>{if(s||!v.isValidElement(l))return;const c=l.type;if(c===tr||(c==null?void 0:c.displayName)===tr.displayName||(c==null?void 0:c.name)==="DialogTitle"){s=!0;return}l.props&&l.props.children&&i(l.props.children)})}return i(t),s},[t]);return u.jsxs(pS,{children:[u.jsx(Hf,{}),u.jsxs(Es,{ref:r,className:te("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&&u.jsx(tr,{className:"sr-only",children:"Dialog"}),t,u.jsxs(Uf,{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:[u.jsx(le.X,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]})});Wf.displayName=Es.displayName;const Vf=({className:e,...t})=>u.jsx("div",{className:te("flex flex-col space-y-1.5 text-center sm:text-left",e),...t});Vf.displayName="DialogHeader";const Kf=v.forwardRef(({className:e,...t},n)=>u.jsx(tr,{ref:n,className:te("text-lg font-semibold leading-none tracking-tight",e),...t}));Kf.displayName=tr.displayName;const hS=v.forwardRef(({className:e,...t},n)=>u.jsx(As,{ref:n,className:te("text-sm text-muted-foreground",e),...t}));hS.displayName=As.displayName;const mS=1,gS=1e6;let ka=0;function xS(){return ka=(ka+1)%Number.MAX_SAFE_INTEGER,ka.toString()}const Ia=new Map,qf=e=>{if(Ia.has(e))return;const t=setTimeout(()=>{Ia.delete(e),oo({type:"REMOVE_TOAST",toastId:e})},gS);Ia.set(e,t)},yS=(e,t)=>{switch(t.type){case"ADD_TOAST":return{...e,toasts:[t.toast,...e.toasts].slice(0,mS)};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?qf(n):e.toasts.forEach(r=>{qf(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)}}},Ns=[];let _s={toasts:[]};function oo(e){_s=yS(_s,e),Ns.forEach(t=>{t(_s)})}function vS({...e}){const t=xS(),n=o=>oo({type:"UPDATE_TOAST",toast:{...o,id:t}}),r=()=>oo({type:"DISMISS_TOAST",toastId:t});return oo({type:"ADD_TOAST",toast:{...e,id:t,open:!0,onOpenChange:o=>{o||r()}}}),{id:t,dismiss:r,update:n}}function Ea(){const[e,t]=v.useState(_s);return v.useEffect(()=>(Ns.push(t),()=>{const n=Ns.indexOf(t);n>-1&&Ns.splice(n,1)}),[e]),{...e,toast:vS,dismiss:n=>oo({type:"DISMISS_TOAST",toastId:n})}}function bS({isOpen:e,onClose:t,fileId:n,fileName:r,mimeType:o}){const[s,i]=w.useState(!1),[a,l]=w.useState(null),[c,d]=w.useState(null),{toast:f}=Ea(),p=w.useCallback(async()=>{if(n){i(!0),d(null),l(null);try{const x=await Cf(n);l(x)}catch(x){console.error("Failed to load file:",x),d(x instanceof Error?x.message:"Failed to load file")}finally{i(!1)}}},[n]);w.useEffect(()=>{e&&n&&p()},[e,n,p]);const h=async()=>{if(n)try{await eS(n),f({title:"Download started",description:`Downloading ${r}`})}catch(x){console.error("Failed to download file:",x),f({title:"Download failed",description:String(x),variant:"destructive"})}},m=async()=>{if(n)try{const x=await Cf(n),b=new Blob([x],{type:o}),C=URL.createObjectURL(b);window.open(C,"_blank"),URL.revokeObjectURL(C)}catch(x){console.error("Failed to open file externally:",x),f({title:"Failed to open file",description:String(x),variant:"destructive"})}},g=()=>s?u.jsxs("div",{className:"flex items-center justify-center py-12",children:[u.jsx(le.Loader,{className:"h-8 w-8 animate-spin mr-3"}),u.jsx("span",{children:"Loading file..."})]}):c?u.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[u.jsx("div",{className:"text-red-500 mb-4",children:"⚠️"}),u.jsx("p",{className:"text-red-600 mb-4",children:c}),u.jsx(Ze,{onClick:p,variant:"outline",children:"Try Again"})]}):a?o.startsWith("image/")?u.jsx("div",{className:"flex justify-center",children:u.jsx("img",{src:`data:${o};base64,${a}`,alt:r,className:"max-w-full max-h-[70vh] object-contain rounded-lg"})}):o==="application/pdf"?u.jsx("div",{className:"w-full h-[70vh] border rounded-lg overflow-hidden",children:u.jsx("iframe",{src:`data:application/pdf;base64,${a}`,className:"w-full h-full",title:r})}):o.startsWith("text/")||o.includes("json")||o.includes("xml")?u.jsx("div",{className:"bg-gray-50 dark:bg-gray-900 rounded-lg p-4 max-h-[70vh] overflow-auto",children:u.jsx("pre",{className:"whitespace-pre-wrap font-mono text-sm",children:a})}):u.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[u.jsx(le.FileText,{className:"h-16 w-16 text-gray-400 mb-4"}),u.jsx("p",{className:"text-lg font-medium mb-2",children:r}),u.jsxs("p",{className:"text-sm text-muted-foreground mb-4",children:[o," • ",a.length," bytes"]}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"This file type cannot be previewed. Use download or external view."})]}):u.jsx("div",{className:"flex items-center justify-center py-12",children:u.jsx("p",{className:"text-muted-foreground",children:"No content to display"})}),y=()=>o.startsWith("image/")?u.jsx(le.Image,{className:"h-5 w-5"}):u.jsx(le.FileText,{className:"h-5 w-5"});return u.jsx(fS,{open:e,onOpenChange:t,children:u.jsxs(Wf,{className:"max-w-4xl max-h-[90vh] overflow-hidden",children:[u.jsx(Vf,{children:u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{className:"flex items-center gap-3",children:[y(),u.jsxs("div",{children:[u.jsx(Kf,{className:"text-left",children:r}),u.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:[o," • Click download or external view for full access"]})]})]}),u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsxs(Ze,{variant:"outline",size:"sm",onClick:m,className:"flex items-center gap-2",children:[u.jsx(le.ExternalLink,{className:"h-4 w-4"}),"External"]}),u.jsxs(Ze,{variant:"outline",size:"sm",onClick:h,className:"flex items-center gap-2",children:[u.jsx(le.Download,{className:"h-4 w-4"}),"Download"]})]})]})}),u.jsx("div",{className:"flex-1 overflow-hidden",children:g()})]})})}function Gf(){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 nr=Gf();function wS(e){nr=e}const Yf=/[&<>"']/,SS=new RegExp(Yf.source,"g"),Xf=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,CS=new RegExp(Xf.source,"g"),TS={"&":"&","<":"<",">":">",'"':""","'":"'"},Jf=e=>TS[e];function Nt(e,t){if(t){if(Yf.test(e))return e.replace(SS,Jf)}else if(Xf.test(e))return e.replace(CS,Jf);return e}const kS=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;function Zf(e){return e.replace(kS,(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 IS=/(^|[^\[])\^/g;function st(e,t){e=typeof e=="string"?e:e.source,t=t||"";const n={replace:(r,o)=>(o=o.source||o,o=o.replace(IS,"$1"),e=e.replace(r,o),n),getRegex:()=>new RegExp(e,t)};return n}const ES=/[^\w:]/g,AS=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function Qf(e,t,n){if(e){let r;try{r=decodeURIComponent(Zf(n)).replace(ES,"").toLowerCase()}catch{return null}if(r.indexOf("javascript:")===0||r.indexOf("vbscript:")===0||r.indexOf("data:")===0)return null}t&&!AS.test(n)&&(n=MS(t,n));try{n=encodeURI(n).replace(/%25/g,"%")}catch{return null}return n}const js={},NS=/^[^:]+:\/*[^/]*$/,_S=/^([^:]+:)[\s\S]*$/,jS=/^([^:]+:\/*[^/]*)[\s\S]*$/;function MS(e,t){js[" "+e]||(NS.test(e)?js[" "+e]=e+"/":js[" "+e]=Rs(e,"/",!0)),e=js[" "+e];const n=e.indexOf(":")===-1;return t.substring(0,2)==="//"?n?t:e.replace(_S,"$1")+t:t.charAt(0)==="/"?n?t:e.replace(jS,"$1")+t:e+t}const Ms={exec:function(){}};function ep(e,t){const n=e.replace(/\|/g,(s,i,a)=>{let l=!1,c=i;for(;--c>=0&&a[c]==="\\";)l=!l;return l?"|":" |"}),r=n.split(/ \|/);let o=0;if(r[0].trim()||r.shift(),r.length>0&&!r[r.length-1].trim()&&r.pop(),r.length>t)r.splice(t);else for(;r.length<t;)r.push("");for(;o<r.length;o++)r[o]=r[o].trim().replace(/\\\|/g,"|");return r}function Rs(e,t,n){const r=e.length;if(r===0)return"";let o=0;for(;o<r;){const s=e.charAt(r-o-1);if(s===t&&!n)o++;else if(s!==t&&n)o++;else break}return e.slice(0,r-o)}function RS(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 PS(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 tp(e,t){if(t<1)return"";let n="";for(;t>1;)t&1&&(n+=e),t>>=1,e+=e;return n+e}function np(e,t,n,r){const o=t.href,s=t.title?Nt(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:Nt(i)}}function OS(e,t){const n=e.match(/^(\s+)(?:```)/);if(n===null)return t;const r=n[1];return t.split(`
|
|
91
|
+
For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return v.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},yS="DialogDescriptionWarning",vS=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${Bf(yS).contentName}}.`;return v.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},zf=If,bS=Af,Uf=_f,Es=jf,As=Mf,nr=Pf,Ns=Df,Hf=$f;const wS=zf,SS=Uf,Wf=v.forwardRef(({className:e,...t},n)=>u.jsx(Es,{ref:n,className:te("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}));Wf.displayName=Es.displayName;const Vf=v.forwardRef(({className:e,children:t,...n},r)=>{const o=v.useMemo(()=>{let s=!1;function i(a){v.Children.forEach(a,l=>{if(s||!v.isValidElement(l))return;const c=l.type;if(c===nr||(c==null?void 0:c.displayName)===nr.displayName||(c==null?void 0:c.name)==="DialogTitle"){s=!0;return}l.props&&l.props.children&&i(l.props.children)})}return i(t),s},[t]);return u.jsxs(SS,{children:[u.jsx(Wf,{}),u.jsxs(As,{ref:r,className:te("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&&u.jsx(nr,{className:"sr-only",children:"Dialog"}),t,u.jsxs(Hf,{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:[u.jsx(le.X,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]})});Vf.displayName=As.displayName;const Kf=({className:e,...t})=>u.jsx("div",{className:te("flex flex-col space-y-1.5 text-center sm:text-left",e),...t});Kf.displayName="DialogHeader";const qf=v.forwardRef(({className:e,...t},n)=>u.jsx(nr,{ref:n,className:te("text-lg font-semibold leading-none tracking-tight",e),...t}));qf.displayName=nr.displayName;const CS=v.forwardRef(({className:e,...t},n)=>u.jsx(Ns,{ref:n,className:te("text-sm text-muted-foreground",e),...t}));CS.displayName=Ns.displayName;const TS=1,kS=1e6;let Ta=0;function IS(){return Ta=(Ta+1)%Number.MAX_SAFE_INTEGER,Ta.toString()}const ka=new Map,Gf=e=>{if(ka.has(e))return;const t=setTimeout(()=>{ka.delete(e),oo({type:"REMOVE_TOAST",toastId:e})},kS);ka.set(e,t)},ES=(e,t)=>{switch(t.type){case"ADD_TOAST":return{...e,toasts:[t.toast,...e.toasts].slice(0,TS)};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?Gf(n):e.toasts.forEach(r=>{Gf(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)}}},_s=[];let js={toasts:[]};function oo(e){js=ES(js,e),_s.forEach(t=>{t(js)})}function AS({...e}){const t=IS(),n=o=>oo({type:"UPDATE_TOAST",toast:{...o,id:t}}),r=()=>oo({type:"DISMISS_TOAST",toastId:t});return oo({type:"ADD_TOAST",toast:{...e,id:t,open:!0,onOpenChange:o=>{o||r()}}}),{id:t,dismiss:r,update:n}}function Ia(){const[e,t]=v.useState(js);return v.useEffect(()=>(_s.push(t),()=>{const n=_s.indexOf(t);n>-1&&_s.splice(n,1)}),[e]),{...e,toast:AS,dismiss:n=>oo({type:"DISMISS_TOAST",toastId:n})}}function NS({isOpen:e,onClose:t,fileId:n,fileName:r,mimeType:o}){const[s,i]=w.useState(!1),[a,l]=w.useState(null),[c,d]=w.useState(null),{toast:f}=Ia(),h=w.useCallback(async()=>{if(n){i(!0),d(null),l(null);try{const x=await Tf(n);l(x)}catch(x){console.error("Failed to load file:",x),d(x instanceof Error?x.message:"Failed to load file")}finally{i(!1)}}},[n]);w.useEffect(()=>{e&&n&&h()},[e,n,h]);const p=async()=>{if(n)try{await cS(n),f({title:"Download started",description:`Downloading ${r}`})}catch(x){console.error("Failed to download file:",x),f({title:"Download failed",description:String(x),variant:"destructive"})}},m=async()=>{if(n)try{const x=await Tf(n),b=new Blob([x],{type:o}),S=URL.createObjectURL(b);window.open(S,"_blank"),URL.revokeObjectURL(S)}catch(x){console.error("Failed to open file externally:",x),f({title:"Failed to open file",description:String(x),variant:"destructive"})}},g=()=>s?u.jsxs("div",{className:"flex items-center justify-center py-12",children:[u.jsx(le.Loader,{className:"h-8 w-8 animate-spin mr-3"}),u.jsx("span",{children:"Loading file..."})]}):c?u.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[u.jsx("div",{className:"text-red-500 mb-4",children:"⚠️"}),u.jsx("p",{className:"text-red-600 mb-4",children:c}),u.jsx(Ze,{onClick:h,variant:"outline",children:"Try Again"})]}):a?o.startsWith("image/")?u.jsx("div",{className:"flex justify-center",children:u.jsx("img",{src:`data:${o};base64,${a}`,alt:r,className:"max-w-full max-h-[70vh] object-contain rounded-lg"})}):o==="application/pdf"?u.jsx("div",{className:"w-full h-[70vh] border rounded-lg overflow-hidden",children:u.jsx("iframe",{src:`data:application/pdf;base64,${a}`,className:"w-full h-full",title:r})}):o.startsWith("text/")||o.includes("json")||o.includes("xml")?u.jsx("div",{className:"bg-gray-50 dark:bg-gray-900 rounded-lg p-4 max-h-[70vh] overflow-auto",children:u.jsx("pre",{className:"whitespace-pre-wrap font-mono text-sm",children:a})}):u.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[u.jsx(le.FileText,{className:"h-16 w-16 text-gray-400 mb-4"}),u.jsx("p",{className:"text-lg font-medium mb-2",children:r}),u.jsxs("p",{className:"text-sm text-muted-foreground mb-4",children:[o," • ",a.length," bytes"]}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"This file type cannot be previewed. Use download or external view."})]}):u.jsx("div",{className:"flex items-center justify-center py-12",children:u.jsx("p",{className:"text-muted-foreground",children:"No content to display"})}),y=()=>o.startsWith("image/")?u.jsx(le.Image,{className:"h-5 w-5"}):u.jsx(le.FileText,{className:"h-5 w-5"});return u.jsx(wS,{open:e,onOpenChange:t,children:u.jsxs(Vf,{className:"max-w-4xl max-h-[90vh] overflow-hidden",children:[u.jsx(Kf,{children:u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{className:"flex items-center gap-3",children:[y(),u.jsxs("div",{children:[u.jsx(qf,{className:"text-left",children:r}),u.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:[o," • Click download or external view for full access"]})]})]}),u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsxs(Ze,{variant:"outline",size:"sm",onClick:m,className:"flex items-center gap-2",children:[u.jsx(le.ExternalLink,{className:"h-4 w-4"}),"External"]}),u.jsxs(Ze,{variant:"outline",size:"sm",onClick:p,className:"flex items-center gap-2",children:[u.jsx(le.Download,{className:"h-4 w-4"}),"Download"]})]})]})}),u.jsx("div",{className:"flex-1 overflow-hidden",children:g()})]})})}function Yf(){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 rr=Yf();function _S(e){rr=e}const Xf=/[&<>"']/,jS=new RegExp(Xf.source,"g"),Jf=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,MS=new RegExp(Jf.source,"g"),RS={"&":"&","<":"<",">":">",'"':""","'":"'"},Zf=e=>RS[e];function _t(e,t){if(t){if(Xf.test(e))return e.replace(jS,Zf)}else if(Jf.test(e))return e.replace(MS,Zf);return e}const PS=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;function Qf(e){return e.replace(PS,(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 OS=/(^|[^\[])\^/g;function st(e,t){e=typeof e=="string"?e:e.source,t=t||"";const n={replace:(r,o)=>(o=o.source||o,o=o.replace(OS,"$1"),e=e.replace(r,o),n),getRegex:()=>new RegExp(e,t)};return n}const DS=/[^\w:]/g,LS=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function ep(e,t,n){if(e){let r;try{r=decodeURIComponent(Qf(n)).replace(DS,"").toLowerCase()}catch{return null}if(r.indexOf("javascript:")===0||r.indexOf("vbscript:")===0||r.indexOf("data:")===0)return null}t&&!LS.test(n)&&(n=zS(t,n));try{n=encodeURI(n).replace(/%25/g,"%")}catch{return null}return n}const Ms={},$S=/^[^:]+:\/*[^/]*$/,FS=/^([^:]+:)[\s\S]*$/,BS=/^([^:]+:\/*[^/]*)[\s\S]*$/;function zS(e,t){Ms[" "+e]||($S.test(e)?Ms[" "+e]=e+"/":Ms[" "+e]=Ps(e,"/",!0)),e=Ms[" "+e];const n=e.indexOf(":")===-1;return t.substring(0,2)==="//"?n?t:e.replace(FS,"$1")+t:t.charAt(0)==="/"?n?t:e.replace(BS,"$1")+t:e+t}const Rs={exec:function(){}};function tp(e,t){const n=e.replace(/\|/g,(s,i,a)=>{let l=!1,c=i;for(;--c>=0&&a[c]==="\\";)l=!l;return l?"|":" |"}),r=n.split(/ \|/);let o=0;if(r[0].trim()||r.shift(),r.length>0&&!r[r.length-1].trim()&&r.pop(),r.length>t)r.splice(t);else for(;r.length<t;)r.push("");for(;o<r.length;o++)r[o]=r[o].trim().replace(/\\\|/g,"|");return r}function Ps(e,t,n){const r=e.length;if(r===0)return"";let o=0;for(;o<r;){const s=e.charAt(r-o-1);if(s===t&&!n)o++;else if(s!==t&&n)o++;else break}return e.slice(0,r-o)}function US(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 HS(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 np(e,t){if(t<1)return"";let n="";for(;t>1;)t&1&&(n+=e),t>>=1,e+=e;return n+e}function rp(e,t,n,r){const o=t.href,s=t.title?_t(t.title):null,i=e[1].replace(/\\([\[\]])/g,"$1");if(e[0].charAt(0)!=="!"){r.state.inLink=!0;const a={type:"link",raw:n,href:o,title:s,text:i,tokens:r.inlineTokens(i)};return r.state.inLink=!1,a}return{type:"image",raw:n,href:o,title:s,text:_t(i)}}function WS(e,t){const n=e.match(/^(\s+)(?:```)/);if(n===null)return t;const r=n[1];return t.split(`
|
|
92
92
|
`).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(`
|
|
93
|
-
`)}class
|
|
94
|
-
`)}}}fences(t){const n=this.rules.block.fences.exec(t);if(n){const r=n[0],o=
|
|
93
|
+
`)}class Ea{constructor(t){this.options=t||rr}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:Ps(r,`
|
|
94
|
+
`)}}}fences(t){const n=this.rules.block.fences.exec(t);if(n){const r=n[0],o=WS(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=Ps(r,"#");(this.options.pedantic||!o||/ $/.test(o))&&(r=o.trim())}return{type:"heading",raw:n[0],depth:n[1].length,text:r,tokens:this.lexer.inline(r)}}}hr(t){const n=this.rules.block.hr.exec(t);if(n)return{type:"hr",raw:n[0]}}blockquote(t){const n=this.rules.block.blockquote.exec(t);if(n){const r=n[0].replace(/^ *>[ \t]?/gm,""),o=this.lexer.state.top;this.lexer.state.top=!0;const s=this.lexer.blockTokens(r);return this.lexer.state.top=o,{type:"blockquote",raw:n[0],tokens:s,text:r}}}list(t){let n=this.rules.block.list.exec(t);if(n){let r,o,s,i,a,l,c,d,f,h,p,m,g=n[1].trim();const y=g.length>1,x={type:"list",raw:"",ordered:y,start:y?+g.slice(0,-1):"",loose:!1,items:[]};g=y?`\\d{1,9}\\${g.slice(-1)}`:`\\${g}`,this.options.pedantic&&(g=y?g:"[*+-]");const b=new RegExp(`^( {0,3}${g})((?:[ ][^\\n]*)?(?:\\n|$))`);for(;t&&(m=!1,!(!(n=b.exec(t))||this.rules.block.hr.test(t)));){if(r=n[0],t=t.substring(r.length),d=n[2].split(`
|
|
95
95
|
`,1)[0].replace(/^\t+/,k=>" ".repeat(3*k.length)),f=t.split(`
|
|
96
|
-
`,1)[0],this.options.pedantic?(i=2,
|
|
97
|
-
`,t=t.substring(f.length+1),m=!0),!m){const k=new RegExp(`^ {0,${Math.min(3,i-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),
|
|
98
|
-
`,1)[0],f=
|
|
99
|
-
`+f.slice(i);else{if(l||d.search(/[^ ]/)>=4||T.test(d)||I.test(d)||
|
|
100
|
-
`+f}!l&&!f.trim()&&(l=!0),r+=
|
|
101
|
-
`,t=t.substring(
|
|
102
|
-
`):[]};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]=
|
|
103
|
-
`?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:
|
|
104
|
-
]`).replace("lheading",ve.lheading).replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").getRegex()};const de={escape:/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,autolink:/^<(scheme:[^\s\x00-\x1f<>]*|email)>/,url:
|
|
96
|
+
`,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+`
|
|
97
|
+
`,t=t.substring(f.length+1),m=!0),!m){const k=new RegExp(`^ {0,${Math.min(3,i-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),C=new RegExp(`^ {0,${Math.min(3,i-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),T=new RegExp(`^ {0,${Math.min(3,i-1)}}(?:\`\`\`|~~~)`),I=new RegExp(`^ {0,${Math.min(3,i-1)}}#`);for(;t&&(h=t.split(`
|
|
98
|
+
`,1)[0],f=h,this.options.pedantic&&(f=f.replace(/^ {1,4}(?=( {4})*[^ ])/g," ")),!(T.test(f)||I.test(f)||k.test(f)||C.test(t)));){if(f.search(/[^ ]/)>=i||!f.trim())p+=`
|
|
99
|
+
`+f.slice(i);else{if(l||d.search(/[^ ]/)>=4||T.test(d)||I.test(d)||C.test(d))break;p+=`
|
|
100
|
+
`+f}!l&&!f.trim()&&(l=!0),r+=h+`
|
|
101
|
+
`,t=t.substring(h.length+1),d=f.slice(i)}}x.loose||(c?x.loose=!0:/\n *\n *$/.test(r)&&(c=!0)),this.options.gfm&&(o=/^\[[ xX]\] /.exec(p),o&&(s=o[0]!=="[ ] ",p=p.replace(/^\[[ xX]\] +/,""))),x.items.push({type:"list_item",raw:r,task:!!o,checked:s,loose:!1,text:p}),x.raw+=r}x.items[x.items.length-1].raw=r.trimRight(),x.items[x.items.length-1].text=p.trimRight(),x.raw=x.raw.trimRight();const S=x.items.length;for(a=0;a<S;a++)if(this.lexer.state.top=!1,x.items[a].tokens=this.lexer.blockTokens(x.items[a].text,[]),!x.loose){const k=x.items[a].tokens.filter(T=>T.type==="space"),C=k.length>0&&k.some(T=>/\n.*\n/.test(T.raw));x.loose=C}if(x.loose)for(a=0;a<S;a++)x.items[a].loose=!0;return x}}html(t){const n=this.rules.block.html.exec(t);if(n){const r={type:"html",raw:n[0],pre:!this.options.sanitizer&&(n[1]==="pre"||n[1]==="script"||n[1]==="style"),text:n[0]};if(this.options.sanitize){const o=this.options.sanitizer?this.options.sanitizer(n[0]):_t(n[0]);r.type="paragraph",r.text=o,r.tokens=this.lexer.inline(o)}return r}}def(t){const n=this.rules.block.def.exec(t);if(n){const r=n[1].toLowerCase().replace(/\s+/g," "),o=n[2]?n[2].replace(/^<(.*)>$/,"$1").replace(this.rules.inline._escapes,"$1"):"",s=n[3]?n[3].substring(1,n[3].length-1).replace(this.rules.inline._escapes,"$1"):n[3];return{type:"def",tag:r,raw:n[0],href:o,title:s}}}table(t){const n=this.rules.block.table.exec(t);if(n){const r={type:"table",header:tp(n[1]).map(o=>({text:o})),align:n[2].replace(/^ *|\| *$/g,"").split(/ *\| */),rows:n[3]&&n[3].trim()?n[3].replace(/\n[ \t]*$/,"").split(`
|
|
102
|
+
`):[]};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]=tp(r.rows[s],r.header.length).map(c=>({text:c}));for(o=r.header.length,i=0;i<o;i++)r.header[i].tokens=this.lexer.inline(r.header[i].text);for(o=r.rows.length,i=0;i<o;i++)for(l=r.rows[i],a=0;a<l.length;a++)l[a].tokens=this.lexer.inline(l[a].text);return r}}}lheading(t){const n=this.rules.block.lheading.exec(t);if(n)return{type:"heading",raw:n[0],depth:n[2].charAt(0)==="="?1:2,text:n[1],tokens:this.lexer.inline(n[1])}}paragraph(t){const n=this.rules.block.paragraph.exec(t);if(n){const r=n[1].charAt(n[1].length-1)===`
|
|
103
|
+
`?n[1].slice(0,-1):n[1];return{type:"paragraph",raw:n[0],text:r,tokens:this.lexer.inline(r)}}}text(t){const n=this.rules.block.text.exec(t);if(n)return{type:"text",raw:n[0],text:n[0],tokens:this.lexer.inline(n[0])}}escape(t){const n=this.rules.inline.escape.exec(t);if(n)return{type:"escape",raw:n[0],text:_t(n[1])}}tag(t){const n=this.rules.inline.tag.exec(t);if(n)return!this.lexer.state.inLink&&/^<a /i.test(n[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&/^<\/a>/i.test(n[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&/^<(pre|code|kbd|script)(\s|>)/i.test(n[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&/^<\/(pre|code|kbd|script)(\s|>)/i.test(n[0])&&(this.lexer.state.inRawBlock=!1),{type:this.options.sanitize?"text":"html",raw:n[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,text:this.options.sanitize?this.options.sanitizer?this.options.sanitizer(n[0]):_t(n[0]):n[0]}}link(t){const n=this.rules.inline.link.exec(t);if(n){const r=n[2].trim();if(!this.options.pedantic&&/^</.test(r)){if(!/>$/.test(r))return;const i=Ps(r.slice(0,-1),"\\");if((r.length-i.length)%2===0)return}else{const i=US(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)),rp(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 rp(r,o,r[0],this.lexer)}}emStrong(t,n,r=""){let o=this.rules.inline.emStrong.lDelim.exec(t);if(!o||o[3]&&r.match(/[\p{L}\p{N}]/u))return;const s=o[1]||o[2]||"";if(!s||s&&(r===""||this.rules.inline.punctuation.exec(r))){const i=o[0].length-1;let a,l,c=i,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]){c+=l;continue}else if((o[5]||o[6])&&i%3&&!((i+l)%3)){d+=l;continue}if(c-=l,c>0)continue;l=Math.min(l,l+c+d);const h=t.slice(0,i+o.index+(o[0].length-a.length)+l);if(Math.min(i,l)%2){const m=h.slice(1,-1);return{type:"em",raw:h,text:m,tokens:this.lexer.inlineTokens(m)}}const p=h.slice(2,-2);return{type:"strong",raw:h,text:p,tokens:this.lexer.inlineTokens(p)}}}}codespan(t){const n=this.rules.inline.code.exec(t);if(n){let r=n[2].replace(/\n/g," ");const o=/[^ ]/.test(r),s=/^ /.test(r)&&/ $/.test(r);return o&&s&&(r=r.substring(1,r.length-1)),r=_t(r,!0),{type:"codespan",raw:n[0],text:r}}}br(t){const n=this.rules.inline.br.exec(t);if(n)return{type:"br",raw:n[0]}}del(t){const n=this.rules.inline.del.exec(t);if(n)return{type:"del",raw:n[0],text:n[2],tokens:this.lexer.inlineTokens(n[2])}}autolink(t,n){const r=this.rules.inline.autolink.exec(t);if(r){let o,s;return r[2]==="@"?(o=_t(this.options.mangle?n(r[1]):r[1]),s="mailto:"+o):(o=_t(r[1]),s=o),{type:"link",raw:r[0],text:o,href:s,tokens:[{type:"text",raw:o,text:o}]}}}url(t,n){let r;if(r=this.rules.inline.url.exec(t)){let o,s;if(r[2]==="@")o=_t(this.options.mangle?n(r[0]):r[0]),s="mailto:"+o;else{let i;do i=r[0],r[0]=this.rules.inline._backpedal.exec(r[0])[0];while(i!==r[0]);o=_t(r[0]),r[1]==="www."?s="http://"+r[0]:s=r[0]}return{type:"link",raw:r[0],text:o,href:s,tokens:[{type:"text",raw:o,text:o}]}}}inlineText(t,n){const r=this.rules.inline.text.exec(t);if(r){let o;return this.lexer.state.inRawBlock?o=this.options.sanitize?this.options.sanitizer?this.options.sanitizer(r[0]):_t(r[0]):r[0]:o=_t(this.options.smartypants?n(r[0]):r[0]),{type:"text",raw:r[0],text:o}}}}const ve={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:Rs,lheading:/^((?:.|\n(?!\n))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,_paragraph:/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,text:/^[^\n]+/};ve._label=/(?!\s*\])(?:\\.|[^\[\]\\])+/,ve._title=/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/,ve.def=st(ve.def).replace("label",ve._label).replace("title",ve._title).getRegex(),ve.bullet=/(?:[*+-]|\d{1,9}[.)])/,ve.listItemStart=st(/^( *)(bull) */).replace("bull",ve.bullet).getRegex(),ve.list=st(ve.list).replace(/bull/g,ve.bullet).replace("hr","\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))").replace("def","\\n+(?="+ve.def.source+")").getRegex(),ve._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",ve._comment=/<!--(?!-?>)[\s\S]*?(?:-->|$)/,ve.html=st(ve.html,"i").replace("comment",ve._comment).replace("tag",ve._tag).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),ve.paragraph=st(ve._paragraph).replace("hr",ve.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",ve._tag).getRegex(),ve.blockquote=st(ve.blockquote).replace("paragraph",ve.paragraph).getRegex(),ve.normal={...ve},ve.gfm={...ve.normal,table:"^ *([^\\n ].*\\|.*)\\n {0,3}(?:\\| *)?(:?-+:? *(?:\\| *:?-+:? *)*)(?:\\| *)?(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)"},ve.gfm.table=st(ve.gfm.table).replace("hr",ve.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",ve._tag).getRegex(),ve.gfm.paragraph=st(ve._paragraph).replace("hr",ve.hr).replace("heading"," {0,3}#{1,6} ").replace("|lheading","").replace("table",ve.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",ve._tag).getRegex(),ve.pedantic={...ve.normal,html:st(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",ve._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:Rs,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:st(ve.normal._paragraph).replace("hr",ve.hr).replace("heading",` *#{1,6} *[^
|
|
104
|
+
]`).replace("lheading",ve.lheading).replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").getRegex()};const de={escape:/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,autolink:/^<(scheme:[^\s\x00-\x1f<>]*|email)>/,url:Rs,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:Rs,text:/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,punctuation:/^([\spunctuation])/};de._punctuation="!\"#$%&'()+\\-.,/:;<=>?@\\[\\]`^{|}~",de.punctuation=st(de.punctuation).replace(/punctuation/g,de._punctuation).getRegex(),de.blockSkip=/\[[^\]]*?\]\([^\)]*?\)|`[^`]*?`|<[^>]*?>/g,de.escapedEmSt=/(?:^|[^\\])(?:\\\\)*\\[*_]/g,de._comment=st(ve._comment).replace("(?:-->|$)","-->").getRegex(),de.emStrong.lDelim=st(de.emStrong.lDelim).replace(/punct/g,de._punctuation).getRegex(),de.emStrong.rDelimAst=st(de.emStrong.rDelimAst,"g").replace(/punct/g,de._punctuation).getRegex(),de.emStrong.rDelimUnd=st(de.emStrong.rDelimUnd,"g").replace(/punct/g,de._punctuation).getRegex(),de._escapes=/\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/g,de._scheme=/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/,de._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])?)+(?![-_])/,de.autolink=st(de.autolink).replace("scheme",de._scheme).replace("email",de._email).getRegex(),de._attribute=/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/,de.tag=st(de.tag).replace("comment",de._comment).replace("attribute",de._attribute).getRegex(),de._label=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,de._href=/<(?:\\.|[^\n<>\\])+>|[^\s\x00-\x1f]*/,de._title=/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/,de.link=st(de.link).replace("label",de._label).replace("href",de._href).replace("title",de._title).getRegex(),de.reflink=st(de.reflink).replace("label",de._label).replace("ref",ve._label).getRegex(),de.nolink=st(de.nolink).replace("ref",ve._label).getRegex(),de.reflinkSearch=st(de.reflinkSearch,"g").replace("reflink",de.reflink).replace("nolink",de.nolink).getRegex(),de.normal={...de},de.pedantic={...de.normal,strong:{start:/^__|\*\*/,middle:/^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,endAst:/\*\*(?!\*)/g,endUnd:/__(?!_)/g},em:{start:/^_|\*/,middle:/^()\*(?=\S)([\s\S]*?\S)\*(?!\*)|^_(?=\S)([\s\S]*?\S)_(?!_)/,endAst:/\*(?!\*)/g,endUnd:/_(?!_)/g},link:st(/^!?\[(label)\]\((.*?)\)/).replace("label",de._label).getRegex(),reflink:st(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",de._label).getRegex()},de.gfm={...de.normal,escape:st(de.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.!#$%&'*+\/=?_`{\|}~-]+@)))/},de.gfm.url=st(de.gfm.url,"i").replace("email",de.gfm._extended_email).getRegex(),de.breaks={...de.gfm,br:st(de.br).replace("{2,}","*").getRegex(),text:st(de.gfm.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()};function VS(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 op(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 Ln{constructor(t){this.tokens=[],this.tokens.links=Object.create(null),this.options=t||rr,this.options.tokenizer=this.options.tokenizer||new Ea,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:ve.normal,inline:de.normal};this.options.pedantic?(n.block=ve.pedantic,n.inline=de.pedantic):this.options.gfm&&(n.block=ve.gfm,this.options.breaks?n.inline=de.breaks:n.inline=de.gfm),this.tokenizer.rules=n}static get rules(){return{block:ve,inline:de}}static lex(t,n){return new Ln(n).lex(t)}static lexInline(t,n){return new Ln(n).inlineTokens(t)}lex(t){t=t.replace(/\r\n|\r/g,`
|
|
105
105
|
`),this.blockTokens(t,this.tokens);let n;for(;n=this.inlineQueue.shift();)this.inlineTokens(n.src,n.tokens);return this.tokens}blockTokens(t,n=[]){this.options.pedantic?t=t.replace(/\t/g," ").replace(/^ +$/gm,""):t=t.replace(/^( *)(\t+)/gm,(a,l,c)=>l+" ".repeat(c.length));let r,o,s,i;for(;t;)if(!(this.options.extensions&&this.options.extensions.block&&this.options.extensions.block.some(a=>(r=a.call({lexer:this},t,n))?(t=t.substring(r.raw.length),n.push(r),!0):!1))){if(r=this.tokenizer.space(t)){t=t.substring(r.raw.length),r.raw.length===1&&n.length>0?n[n.length-1].raw+=`
|
|
106
106
|
`: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+=`
|
|
107
107
|
`+r.raw,o.text+=`
|
|
@@ -111,9 +111,9 @@ For more information, see https://radix-ui.com/primitives/docs/components/${t.do
|
|
|
111
111
|
`+r.raw,o.text+=`
|
|
112
112
|
`+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+=`
|
|
113
113
|
`+r.raw,o.text+=`
|
|
114
|
-
`+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,c;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)+"["+
|
|
115
|
-
`,o?'<pre><code class="'+this.options.langPrefix+
|
|
116
|
-
`:"<pre><code>"+(r?t:
|
|
114
|
+
`+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,c;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)+"["+np("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)+"["+np("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||(c=""),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,c)){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,op)){t=t.substring(r.raw.length),n.push(r);continue}if(!this.state.inLink&&(r=this.tokenizer.url(t,op))){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,VS)){t=t.substring(r.raw.length),r.raw.slice(-1)!=="_"&&(c=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 Aa{constructor(t){this.options=t||rr}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$/,"")+`
|
|
115
|
+
`,o?'<pre><code class="'+this.options.langPrefix+_t(o)+'">'+(r?t:_t(t,!0))+`</code></pre>
|
|
116
|
+
`:"<pre><code>"+(r?t:_t(t,!0))+`</code></pre>
|
|
117
117
|
`}blockquote(t){return`<blockquote>
|
|
118
118
|
${t}</blockquote>
|
|
119
119
|
`}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}>
|
|
@@ -131,7 +131,7 @@ ${t}</blockquote>
|
|
|
131
131
|
`}tablerow(t){return`<tr>
|
|
132
132
|
${t}</tr>
|
|
133
133
|
`}tablecell(t,n){const r=n.header?"th":"td";return(n.align?`<${r} align="${n.align}">`:`<${r}>`)+t+`</${r}>
|
|
134
|
-
`}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=
|
|
135
|
-
`+(
|
|
136
|
-
Please report this to https://github.com/markedjs/marked.`,e){const o="<p>An error occurred:</p><pre>"+Nt(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 ip(e,t){return(n,r,o)=>{typeof r=="function"&&(o=r,r=null);const s={...r};r={...ge.defaults,...s};const i=LS(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(PS(r),r.hooks&&(r.hooks.options=r),o){const a=r.highlight;let l;try{r.hooks&&(n=r.hooks.preprocess(n)),l=e(n,r)}catch(f){return i(f)}const c=function(f){let p;if(!f)try{r.walkTokens&&ge.walkTokens(l,r.walkTokens),p=t(l,r),r.hooks&&(p=r.hooks.postprocess(p))}catch(h){f=h}return r.highlight=a,f?i(f):o(null,p)};if(!a||a.length<3||(delete r.highlight,!l.length))return c();let d=0;ge.walkTokens(l,function(f){f.type==="code"&&(d++,setTimeout(()=>{a(f.text,f.lang,function(p,h){if(p)return c(p);h!=null&&h!==f.text&&(f.text=h,f.escaped=!0),d--,d===0&&c()})},0))}),d===0&&c();return}if(r.async)return Promise.resolve(r.hooks?r.hooks.preprocess(n):n).then(a=>e(a,r)).then(a=>r.walkTokens?Promise.all(ge.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&&ge.walkTokens(a,r.walkTokens);let l=t(a,r);return r.hooks&&(l=r.hooks.postprocess(l)),l}catch(a){return i(a)}}}function ge(e,t,n){return ip(Dn.lex,Ln.parse)(e,t,n)}ge.options=ge.setOptions=function(e){return ge.defaults={...ge.defaults,...e},wS(ge.defaults),ge},ge.getDefaults=Gf,ge.defaults=nr,ge.use=function(...e){const t=ge.defaults.extensions||{renderers:{},childTokens:{}};e.forEach(n=>{const r={...n};if(r.async=ge.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=ge.defaults.renderer||new Na;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=ge.defaults.tokenizer||new Aa;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=ge.defaults.hooks||new Ps;for(const s in n.hooks){const i=o[s];Ps.passThroughHooks.has(s)?o[s]=a=>{if(ge.defaults.async)return Promise.resolve(n.hooks[s].call(o,a)).then(c=>i.call(o,c));const l=n.hooks[s].call(o,a);return i.call(o,l)}:o[s]=(...a)=>{let l=n.hooks[s].apply(o,a);return l===!1&&(l=i.apply(o,a)),l}}r.hooks=o}if(n.walkTokens){const o=ge.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}}ge.setOptions(r)})},ge.walkTokens=function(e,t){let n=[];for(const r of e)switch(n=n.concat(t.call(ge,r)),r.type){case"table":{for(const o of r.header)n=n.concat(ge.walkTokens(o.tokens,t));for(const o of r.rows)for(const s of o)n=n.concat(ge.walkTokens(s.tokens,t));break}case"list":{n=n.concat(ge.walkTokens(r.items,t));break}default:ge.defaults.extensions&&ge.defaults.extensions.childTokens&&ge.defaults.extensions.childTokens[r.type]?ge.defaults.extensions.childTokens[r.type].forEach(function(o){n=n.concat(ge.walkTokens(r[o],t))}):r.tokens&&(n=n.concat(ge.walkTokens(r.tokens,t)))}return n},ge.parseInline=ip(Dn.lexInline,Ln.parseInline),ge.Parser=Ln,ge.parser=Ln.parse,ge.Renderer=Na,ge.TextRenderer=op,ge.Lexer=Dn,ge.lexer=Dn.lex,ge.Tokenizer=Aa,ge.Slugger=sp,ge.Hooks=Ps,ge.parse=ge,ge.options,ge.setOptions,ge.use,ge.walkTokens,ge.parseInline,Ln.parse,Dn.lex;function so({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 typeof ge.parse=="function"?ge.parse(i):ge(i)}return typeof ge.parse=="function"?ge.parse(e):ge(e)}catch(i){return console.error("[MarkdownContent] parse error",i),`<pre class="font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words">Error rendering markdown: ${String(i)}</pre>`}},[e,n]),s=w.useMemo(()=>{const i={color:"currentColor",...r};if(r&&r.color){const a=r.color;return{...i,"--tw-prose-body":a,"--tw-prose-headings":a,"--tw-prose-links":a,"--tw-prose-bold":a,"--tw-prose-counters":a,"--tw-prose-bullets":a,"--tw-prose-hr":a,"--tw-prose-quotes":a,"--tw-prose-quote-borders":a,"--tw-prose-captions":a,"--tw-prose-code":a,"--tw-prose-pre-code":a,"--tw-prose-pre-bg":"inherit","--tw-prose-th-borders":a,"--tw-prose-td-borders":a}}return i},[r]);return u.jsx("div",{className:te("markdown prose prose-sm max-w-none break-words","dark:prose-invert","text-current","prose-headings:text-current prose-p:text-current prose-li:text-current prose-a:text-current prose-strong:text-current","prose-em:text-current prose-blockquote:text-current prose-table:text-current prose-td:text-current prose-th:text-current","prose-pre:font-mono prose-pre:text-xs prose-pre:bg-background/50 prose-pre:border prose-pre:rounded prose-pre:p-3 prose-pre:whitespace-pre prose-pre:overflow-x-auto","prose-code:font-mono prose-code:text-sm prose-code:bg-background/50 prose-code:px-1.5 prose-code:py-0.5 prose-code:rounded prose-code:text-current",t),style:s,dangerouslySetInnerHTML:{__html:o}})}const $S={MODE:"library"};function FS(){var i;const e=typeof globalThis<"u"?globalThis.process:void 0,t=typeof((i=e==null?void 0:e.env)==null?void 0:i.NODE_ENV)=="string"?e.env.NODE_ENV:void 0;if(t)return t==="production";const n=typeof{url:typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Gs&&Gs.tagName.toUpperCase()==="SCRIPT"&&Gs.src||new URL("index.umd.js",document.baseURI).href}<"u"?$S:void 0,r=typeof(n==null?void 0:n.MODE)=="string"?n.MODE:void 0,o=typeof(n==null?void 0:n.NODE_ENV)=="string"?n.NODE_ENV:void 0;return(r??o)==="production"}function BS(){return!FS()}function zS(){return typeof window>"u"?!1:window.__ARTIFACT_DEBUG__===!0}function US(){return BS()||zS()}function HS({preview:e,idx:t}){return w.useEffect(()=>{US()&&console.debug(`[MessageComponent] Preview ${t} mounted:`,{src:e.src.substring(0,100),alt:e.alt,label:e.label})},[t,e]),u.jsxs("div",{className:"space-y-2",children:[e.label&&u.jsxs("p",{className:"text-[0.65rem] uppercase tracking-wide text-muted-foreground",children:["Artifact: ",e.label]}),u.jsx("div",{className:"overflow-hidden rounded border border-border/60 bg-background/60 p-1 shadow-sm",children:u.jsx("img",{src:e.src,alt:e.alt,title:e.label,loading:"lazy",className:"h-auto max-h-[420px] w-full rounded object-contain",onLoad:()=>{},onError:n=>{console.error(`[MessageComponent] ❌ Image failed to load for artifact ${t}:`,{alt:e.alt,label:e.label,message:n.target.alt})}})})]})}const io=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:te("rounded-lg border bg-card text-card-foreground shadow-sm",e),...t}));io.displayName="Card";const ao=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:te("flex flex-col space-y-1.5 p-6",e),...t}));ao.displayName="CardHeader";const lo=v.forwardRef(({className:e,...t},n)=>u.jsx("h3",{ref:n,className:te("text-2xl font-semibold leading-none tracking-tight",e),...t}));lo.displayName="CardTitle";const ap=v.forwardRef(({className:e,...t},n)=>u.jsx("p",{ref:n,className:te("text-sm text-muted-foreground",e),...t}));ap.displayName="CardDescription";const co=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:te("p-6 pt-0",e),...t}));co.displayName="CardContent";const lp=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:te("flex items-center p-6 pt-0",e),...t}));lp.displayName="CardFooter";function WS({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=u.jsx("p",{className:"text-sm leading-relaxed text-blue-800/90 dark:text-blue-200/90 whitespace-pre-wrap",children:s});else{const c=ro(s);a=u.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:c})}const l=o?"Please approve or reject this action to resume the workflow.":"Waiting for approval from another participant.";return u.jsxs(io,{className:te("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:[u.jsxs(ao,{className:"pb-3",children:[u.jsx(lo,{className:"text-blue-900 dark:text-blue-100 text-base",children:i}),u.jsx(ap,{className:"text-blue-700 dark:text-blue-300 text-sm",children:l})]}),a&&u.jsx(co,{className:"pt-0 pb-3",children:a}),u.jsx(lp,{className:"pt-0",children:u.jsxs("div",{className:"flex gap-2 ml-auto",children:[u.jsx(Ze,{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"}),u.jsx(Ze,{size:"sm",onClick:()=>t(e),className:"bg-blue-600 hover:bg-blue-700 text-white",disabled:r||!o,children:"Approve"})]})})]})}const VS="prose prose-sm max-w-none break-words dark:prose-invert prose-headings:break-words prose-p:break-words prose-li:break-words prose-td:break-words prose-th:break-words prose-a:break-all prose-code:break-words prose-blockquote:break-words";function cp({data:e}){return Array.isArray(e)?e.every(n=>n===null||["string","number","boolean"].includes(typeof n))?u.jsx("div",{className:VS,children:u.jsx("ul",{className:"list-disc pl-5",children:e.map((n,r)=>u.jsx("li",{children:String(n)},r))})}):u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:ro(e)}):u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:ro(e)})}function KS({message:e,viewMode:t}){const r=bf(e).name||"tool",o=c=>{if(c==null)return null;const d=typeof c=="string"?wa(c)??c:c;if(d&&typeof d=="object")return u.jsx(cp,{data:d});const f=typeof d=="string"?d:(()=>{try{return ro(d)}catch{return String(d??"")}})();return u.jsx("pre",{className:"whitespace-pre-wrap break-words font-sans text-sm text-foreground/90",children:f})},s=c=>{if(c==null)return null;const{content:d,isMarkdown:f}=K0(c);return f?u.jsx(so,{content:d,className:"text-current"}):o(c)};if(t==="preview")return null;const i=e.content.find(c=>c.type!=="tool_call");if(!i)return u.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[u.jsx(le.Loader,{className:"h-4 w-4 animate-spin"}),u.jsxs("span",{children:["Waiting for ",r," output…"]})]});if(i.type==="text"){const d=(i.text??"").trim();if(!d)return null;const f=Ss(d);return s(f)}const a=no(i),l=Ss(a);return s(l)}function qS({message:e,viewMode:t,isStreaming:n=!1}){var a;const r=e.name??"tool",o=w.useMemo(()=>{const l=e.additionalKwargs??{};return(Array.isArray(l.toolProgress)?[...l.toolProgress]:[]).slice(-6)},[e]),s=(a=o[o.length-1])==null?void 0:a.title,i=n||o.length>0;return u.jsxs("div",{className:"space-y-2",children:[i&&u.jsxs("div",{className:"space-y-2",children:[u.jsxs("div",{className:"flex items-center gap-2 text-xs uppercase tracking-wide text-muted-foreground",children:[n&&u.jsx(le.Loader,{className:"h-3 w-3 animate-spin"}),u.jsx("span",{children:s??`Running ${r}…`})]}),o.length>0&&u.jsx("div",{className:"space-y-2 text-xs text-muted-foreground",children:o.map((l,c)=>u.jsxs("div",{className:"rounded border border-current/10 bg-muted/60 p-2 text-[11px] leading-snug",children:[u.jsx("div",{className:"font-semibold text-[11px] uppercase opacity-70",children:l.title??l.step??`Step ${c+1}`}),l.content&&u.jsx("p",{className:"mt-1 text-[12px] text-foreground/90",children:l.content}),u.jsxs("div",{className:"mt-1 flex flex-wrap gap-2 text-[10px] opacity-70",children:[typeof l.factsFound=="number"&&u.jsxs("span",{children:["Facts found: ",l.factsFound]}),typeof l.isSufficient=="boolean"&&u.jsxs("span",{children:["Research ",l.isSufficient?"sufficient":"needs more data"]})]})]},`progress-${r}-${c}`))})]}),u.jsx(KS,{message:e,viewMode:t})]})}function GS(e){const{allowFileOpen:t,currentThreadId:n}=e,{toast:r}=Ea(),[o,s]=w.useState({}),[i,a]=w.useState(null),[l,c]=w.useState(!1),d=w.useCallback(()=>{c(!1),a(null)},[]),f=w.useCallback(h=>{a(h),c(!0)},[]),p=w.useCallback(async(h,m,g)=>{var y,x;if(!t){h.preventDefault();return}if(o[g]){h.preventDefault();return}try{const b=String(m.url??""),C=b.match(/\/chat\/files\/([^/]+)(?:\/(view|download))?/);if(C){h.preventDefault();const k=C[1],S=m.name||`file_${k}`,T=m.mimeType||"application/octet-stream";f({id:k,name:S,mimeType:T});return}if(b.startsWith("data:")){h.preventDefault(),s(S=>({...S,[g]:!0}));const k=r({title:"Fetching file...",description:"",open:!0});try{const S=await tS(n??void 0);if(!S||!Array.isArray(S))throw new Error("Invalid file list response");const T=S.find(I=>!I||typeof I!="object"||!((I.filename??"")===(m.name??""))?!1:typeof m.size=="number"&&typeof I.size=="number"?I.size===m.size:!0);if(!(T!=null&&T.id))throw new Error(`File "${m.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:m.name||T.filename||`file_${T.id}`,mimeType:m.mimeType||T.mime_type||"application/octet-stream"}),(y=k.update)==null||y.call(k,{id:k.id,title:"Success",description:`Opened ${m.name}`,open:!0})}catch(S){console.error("Failed to fetch server file:",S);const T=S instanceof Error?S.message:"Unknown error occurred";(x=k.update)==null||x.call(k,{id:k.id,title:"Failed",description:T}),r({title:"Failed to fetch file",description:T,open:!0})}finally{s(S=>({...S,[g]:!1}))}}}catch(b){console.error("File click error:",b),s(C=>({...C,[g]:!1}))}},[t,o,r,n,f]);return{uploadingFiles:o,handleFileClick:p,fileViewerOpen:l,currentFileInfo:i,closeFileViewer:d}}function YS({text:e,expanded:t,onExpandedChange:n,previewLength:r,isCompact:o}){const s=Math.max(e.length-r,0),i=e.substring(0,r);return u.jsxs("div",{className:"flex flex-col gap-1",children:[u.jsx("div",{className:te("text-sm text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:t?u.jsx(so,{content:e,allowHtml:!1}):u.jsxs("pre",{className:te("font-sans whitespace-pre-wrap break-words bg-transparent p-0 m-0 text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:[i,"..."]})}),u.jsx(Ze,{type:"button",variant:"ghost",size:"sm",className:"h-6 text-xs !text-[hsl(var(--chat-bubble-user-text))]",onClick:()=>n(!t),children:t?u.jsxs(u.Fragment,{children:[u.jsx(le.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):u.jsxs(u.Fragment,{children:[u.jsx(le.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more (",s," chars)"]})})]})}function XS({className:e}){const[t,n]=w.useState(0);return w.useEffect(()=>{const r=setInterval(()=>n(o=>(o+1)%4),500);return()=>clearInterval(r)},[]),u.jsxs("span",{"aria-live":"polite",className:te("inline-block text-xs opacity-70 ml-1",e),children:["Is thinking",".".repeat(t)]})}const Os=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",truncateUserMessages:c=!0,userMessagePreviewLength:d=500,showToolMessages:f=!0,showArtifactPreviews:p=!0,customStyles:h={},onEdit:m,onRegenerate:g,onCancelEdit:y,onCopy:x,activeInterrupt:b,disableInterruptActions:C=!1,onInterruptActionStart:k,onInterruptActionEnd:S,checkpointCandidates:T=[],activeCheckpointId:I=null,onSelectCheckpoint:A,defaultCheckpointId:_=null,messageParentCheckpointId:L=null}){const[R,O]=w.useState(!1),[F,N]=w.useState("preview"),[B,j]=w.useState(!1),{currentThreadId:K}=No(),{respondToInterrupt:z}=_o(),M=l==="phone"||l==="half-screen",G=t.role,X=G==="tool",se=w.useMemo(()=>"type"in t&&t.type==="default_message"?t:null,[t]),be=!!se,Ie=!(r&&G!=="user"),{uploadingFiles:Y,handleFileClick:U,fileViewerOpen:J,currentFileInfo:$,closeFileViewer:q}=GS({allowFileOpen:Ie,currentThreadId:K}),Z=w.useMemo(()=>{switch(G){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))]"}},[G]),ue=w.useMemo(()=>{if(se)return"";const D=t.content;return Array.isArray(D)?q0(D):""},[se,t]),ie=w.useMemo(()=>{if(se)return{};const D=t.content;return Array.isArray(D)?bf(t):{}},[se,t]),_e=w.useMemo(()=>X?!!(t.additionalKwargs??{}).toolStreaming:!1,[X,t]),He=w.useMemo(()=>{if(se)return[];const D=t.content;return Array.isArray(D)?D.filter(Q=>Q.type==="image_url"):[]},[se,t]),oe=w.useMemo(()=>{if(se)return[];const D=t.content;return Array.isArray(D)?D.filter(Q=>Q.type==="file"):[]},[se,t]),ye=w.useMemo(()=>{if(se)return[];const D=t.content;return Array.isArray(D)?D.filter(Q=>Q.type==="interrupt"):[]},[se,t]),Oe=(b==null?void 0:b.id)??(b==null?void 0:b.interrupt_id),Ye=Cs(Oe),nt=b==null?void 0:b.value,Xe=w.useMemo(()=>{if(se)return"";const D=t.content;return Array.isArray(D)?G0(D):""},[se,t]),qe=w.useMemo(()=>{if(se||!p)return[];const Q=t.artifact;if(!Q)return[];const ne=[],me=[...Array.isArray(Q.plots)?Q.plots:[]];for(const xe of me){const De=Q0(xe);De&&ne.push(De)}return ne},[se,t,p]),it=w.useCallback(async()=>{const D=X?Xe:ue;async function Q(ne){if(navigator.clipboard&&typeof navigator.clipboard.writeText=="function"){await navigator.clipboard.writeText(ne);return}if(navigator.clipboard&&typeof navigator.clipboard.write=="function"&&typeof ClipboardItem<"u"){const me=new Blob([ne],{type:"text/plain"});await navigator.clipboard.write([new ClipboardItem({"text/plain":me})]);return}throw new Error("Clipboard API not supported in this context.")}try{await Q(D),O(!0),setTimeout(()=>O(!1),2e3),x==null||x(D)}catch(ne){console.error("Failed to copy:",ne)}},[X,Xe,ue,x]),Je=w.useCallback(()=>{if(!m)return;const D=X?Xe:ue,Q="type"in t&&t.type==="default_message"?void 0:{checkpointId:t.checkpointId??null,checkpointNs:t.checkpointNs??null};m(t.id,D,Q)},[m,t.id,X,Xe,ue,t]),et=w.useCallback(()=>{g==null||g(n)},[g,n]),at=w.useCallback(()=>{const Q=te(M?"h-3 w-3":"h-4 w-4","opacity-60 flex-shrink-0",Z);switch(G){case"user":return u.jsx(le.User,{className:Q});case"assistant":return u.jsx(le.Bot,{className:Q});case"tool":return u.jsx(le.Wrench,{className:Q});default:return u.jsx(le.Bot,{className:Q})}},[M,Z,G]),_t=w.useCallback(()=>{const D="group relative mb-4 flex w-full";switch(G){case"user":return te(D,"justify-end");case"assistant":case"tool":case"system":return te(D,"justify-start");default:return D}},[G]),ht=w.useCallback(()=>{const D=te("rounded-lg px-4 py-3 relative min-w-0 max-w-full break-words",M&&"px-3 py-2 text-sm");if(be)return te(D,"w-full","bg-[hsl(var(--chat-bubble-ai))] text-[hsl(var(--chat-bubble-ai-text))]","border border-border/60 dark:border-border/40 shadow-sm");switch(G){case"user":return te(D,"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 te(D,"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 te(D,"w-full md:max-w-[95%] bg-secondary/50 text-secondary-foreground border border-dashed");case"system":return te(D,"w-full md:max-w-[85%] bg-accent/40 text-muted-foreground border");default:return te(D,"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")}},[M,be,G]),ft=w.useCallback(async D=>{if(C)return;const Q=Cs((D==null?void 0:D.id)??(D==null?void 0:D.interrupt_id));if(!Q){console.warn("Interrupt part missing id",D);return}try{k==null||k(),await z(Q,!0)}catch(ne){console.error("Failed to approve interrupt:",ne)}finally{S==null||S()}},[C,S,k,z]),mt=w.useCallback(async D=>{if(C)return;const Q=Cs((D==null?void 0:D.id)??(D==null?void 0:D.interrupt_id));if(!Q){console.warn("Interrupt part missing id",D);return}try{k==null||k(),await z(Q,!1)}catch(ne){console.error("Failed to reject interrupt:",ne)}finally{S==null||S()}},[C,S,k,z]),St=w.useCallback(({part:D,i:Q})=>{if(D.type==="text"){const ne=D.text??"",me=ne.trim(),xe=wa(me);return xe&&G!=="tool"?u.jsx(cp,{data:xe},Q):G==="user"&&c&&me.length>d?u.jsx(YS,{text:me,expanded:B,onExpandedChange:j,previewLength:d,isCompact:M},Q):u.jsx(so,{content:ne,allowHtml:!1},Q)}if(D.type==="image_url"){const ne=D;return u.jsx("div",{className:"my-2",children:u.jsx("img",{src:ne.url,alt:ne.alt??"",loading:"lazy",className:"border rounded max-h-[420px] w-auto object-contain"})},Q)}if(D.type==="file"){const ne=D,me=ne.name||"file";return u.jsxs("a",{href:ne.url,onClick:xe=>U(xe.nativeEvent,ne,Q),className:`inline-flex items-center gap-2 rounded px-2 py-1 text-xs bg-gray-100 border hover:bg-gray-200
|
|
137
|
-
dark:bg-background/10 dark:border-border/30 dark:hover:bg-background/20`,children:[Y[Q]?u.jsx(le.Loader,{className:"h-4 w-4 animate-spin"}):null,u.jsxs("span",{className:"truncate max-w-[180px]",children:[me,Y[Q]?" (processing)":""]})]},Q)}if(D.type==="interrupt"){const ne=D,me=Cs((ne==null?void 0:ne.id)??(ne==null?void 0:ne.interrupt_id)),xe=!!(Ye&&me&&me===Ye),De=xe?nt??(ne==null?void 0:ne.value):ne==null?void 0:ne.value,Re=me?{...ne,id:me,interrupt_id:me}:ne;return u.jsx(WS,{interruptPart:Re,onApprove:ft,onReject:mt,disabled:C,isActive:xe,payload:De},Q)}return null},[U,Y,ft,mt,G,c,d,B,M,Ye,nt,b,C,ye]),jt=w.useCallback(()=>u.jsxs("div",{className:"flex items-center gap-2 p-2 bg-muted/30 rounded",children:[u.jsx(le.Paperclip,{className:"h-4 w-4 text-muted-foreground"}),u.jsx("span",{className:"text-sm text-muted-foreground",children:"File upload"})]}),[]),Dt=w.useCallback(()=>{const D=ue.trim().length>0||He.length>0||oe.length>0||ye.length>0;if(!X&&oe.length>0&&!r)return jt();if(!X&&!D&&!r)return null;if(X)return!f&&qe.length>0?null:f?u.jsx(qS,{message:t,viewMode:F,isStreaming:_e},t.id):null;if(!X&&!se){const Q=t,ne=u.jsx("div",{className:"space-y-2",children:Q.content.map((me,xe)=>u.jsx(St,{part:me,i:xe},xe))});return r?u.jsxs("div",{"aria-busy":"true",role:"status",children:[ne,u.jsx(XS,{className:Z})]}):ne}},[ue,He.length,oe.length,ye.length,r,X,F,f,qe.length,jt,Z]),Wt=w.useMemo(()=>se?"Assistant":Y0(t),[se,t]),Ue=w.useMemo(()=>se?[]:Array.isArray(T)?T:[],[T,se]),un=w.useMemo(()=>{var D;return Ue.length?_&&Ue.some(Q=>Q.id===_)?_:((D=Ue[0])==null?void 0:D.id)??null:null},[_,Ue]),We=w.useMemo(()=>!Ue.length||!I?null:Ue.some(D=>D.id===I)?I:null,[I,Ue])??un,gt=G==="user"&&Ue.length>0&&typeof A=="function",Mt=w.useCallback((D,Q=!1)=>{if(!A)return;const ne=(D==null?void 0:D.id)??null,me=(D==null?void 0:D.parentId)??L??null;A(ne,me,Q)},[L,A]),H=w.useMemo(()=>We?Ue.findIndex(D=>D.id===We):-1,[We,Ue]),re=w.useMemo(()=>H<0?null:Ue[H]??null,[H,Ue]);return X&&!f&&qe.length===0?null:be&&se?u.jsx("div",{className:te(_t(),h.container),children:u.jsxs("div",{className:te(ht(),h.content),children:[u.jsxs("div",{className:"flex items-center gap-2 mb-2 pb-2 border-b border-current/10",children:[u.jsx(le.Bot,{className:te("h-4 w-4",Z)}),a&&u.jsx("span",{className:"font-medium text-sm",children:"Assistant"})]}),u.jsx(so,{content:se.content,className:"text-current"})]})}):u.jsxs(u.Fragment,{children:[u.jsx("div",{className:te(_t(),h.container),children:u.jsxs("div",{className:te(ht(),h.content),children:[(i||a||X)&&u.jsxs("div",{className:te("flex items-center justify-between mb-2 pb-2 border-b border-current/10",M&&"mb-1 pb-1",Z,h.header),children:[u.jsxs("div",{className:"flex items-center gap-2",children:[at(),a&&Wt&&u.jsx("span",{className:te("font-medium",M?"text-xs":"text-sm"),children:Wt}),X&&u.jsxs(yf,{variant:"outline",className:te("text-xs flex items-center gap-1 cursor-pointer select-none",Z,"border border-current/40",M&&"text-xs h-4"),role:"button",tabIndex:0,"aria-expanded":F==="expanded",onClick:()=>N(D=>D==="expanded"?"preview":"expanded"),onKeyDown:D=>{(D.key==="Enter"||D.key===" ")&&(D.preventDefault(),N(Q=>Q==="expanded"?"preview":"expanded"))},children:[u.jsx("span",{children:ie.name??"Tool Output"}),ie.toolCallId&&u.jsx("span",{className:"opacity-70",children:ie.toolCallId.slice(0,8)}),F==="expanded"?u.jsx(le.ChevronUp,{className:"h-3 w-3"}):u.jsx(le.ChevronDown,{className:"h-3 w-3"})]})]}),u.jsxs("div",{className:"flex items-center gap-2",children:[gt&&re&&H>=0&&u.jsx("div",{className:"flex flex-wrap items-center gap-2 text-xs",children:u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx("button",{type:"button",className:te("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",H<Ue.length-1?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(H>=Ue.length-1)return;const D=Ue[H+1];D&&Mt(D)},"aria-label":"Older checkpoint (back in time)",disabled:H>=Ue.length-1,children:u.jsx(le.ChevronLeft,{className:"h-3 w-3"})}),u.jsx("div",{className:"flex items-center gap-2",children:u.jsxs("span",{className:"whitespace-nowrap",children:[Ue.length-H," / ",Ue.length]})}),u.jsx("button",{type:"button",className:te("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",H>0?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(!(H<=0))if(H===1)Mt(null,!0);else{const D=Ue[H-1];D&&Mt(D,!1)}},"aria-label":"Newer checkpoint (forward in time)",disabled:H<=0,children:u.jsx(le.ChevronRight,{className:"h-3 w-3"})})]})}),i&&t.createdAt&&u.jsx("time",{className:te("text-xs opacity-60",Z,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&&u.jsxs("div",{className:te("opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",h.actions),children:[u.jsx("div",{className:"relative",children:u.jsx(Ze,{variant:"ghost",size:"sm",onClick:()=>it(),className:te("h-6 w-6 p-0 hover:bg-foreground/10",Z,M&&"h-5 w-5"),"aria-label":"Copy message",title:"Copy message",children:u.jsx(le.Copy,{className:te(R?"text-success":Z,M?"h-3 w-3":"h-4 w-4")})})}),G==="user"&&m&&u.jsx(Ze,{variant:"ghost",size:"sm",onClick:Je,className:te("h-6 w-6 p-0 hover:bg-foreground/10",Z,M&&"h-5 w-5"),"aria-label":"Edit message",children:u.jsx(le.Edit,{className:te(Z,M?"h-3 w-3":"h-4 w-4")})}),G==="assistant"&&g&&u.jsx(Ze,{variant:"ghost",size:"sm",onClick:et,className:te("h-6 w-6 p-0 hover:bg-foreground/10",Z,M&&"h-5 w-5"),"aria-label":"Regenerate response",children:u.jsx(le.RotateCcw,{className:te(Z,M?"h-3 w-3":"h-4 w-4")})})]})]})]}),u.jsxs("div",{className:"relative",children:[Dt(),p&&qe.length>0&&u.jsx("div",{className:"mt-3 space-y-4",children:qe.map((D,Q)=>u.jsx(HS,{preview:D,idx:Q},`artifact-${Q}`))})]}),X&&F==="expanded"&&(ie.toolCallId||ie.name)&&u.jsxs("div",{className:te("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",M&&"text-xs"),children:[ie.name&&u.jsxs("div",{children:["Function: ",ie.name]}),ie.toolCallId&&u.jsxs("div",{children:["Call ID: ",ie.toolCallId]})]}),!(i||a||X)&&s&&!o&&u.jsxs("div",{className:te("absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",h.actions),children:[u.jsx(Ze,{variant:"ghost",size:"sm",onClick:()=>it(),className:te("h-6 w-6 p-0 hover:bg-background/50 text-current",M&&"h-5 w-5"),children:u.jsx(le.Copy,{className:te(R?"text-success":"text-current",M?"h-3 w-3":"h-4 w-4")})}),G==="user"&&m&&u.jsx(Ze,{variant:"ghost",size:"sm",onClick:Je,className:te("h-6 w-6 p-0 hover:bg-background/50 text-current",M&&"h-5 w-5"),children:u.jsx(le.Edit,{className:te("text-current",M?"h-3 w-3":"h-4 w-4")})}),G==="assistant"&&g&&u.jsx(Ze,{variant:"ghost",size:"sm",onClick:et,className:te("h-6 w-6 p-0 hover:bg-background/50 text-current",M&&"h-5 w-5"),children:u.jsx(le.RotateCcw,{className:te("text-current",M?"h-3 w-3":"h-4 w-4")})})]})]})}),$&&u.jsx(bS,{isOpen:J,onClose:q,fileId:$.id,fileName:$.name,mimeType:$.mimeType})]})},(e,t)=>{var i,a,l,c,d,f,p,h;if(t.isStreamingMessage||e.isStreamingMessage||!(e.message.id===t.message.id&&wf(e.message)===wf(t.message)))return!1;const o=["isEditing","showActions","layoutSize","showTimestamp","showAgentName","truncateUserMessages","userMessagePreviewLength","showToolMessages","attemptMeta"].every(m=>e[m]===t[m]),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)===((c=t.customStyles)==null?void 0:c.content)&&((d=e.customStyles)==null?void 0:d.actions)===((f=t.customStyles)==null?void 0:f.actions)&&((p=e.customStyles)==null?void 0:p.header)===((h=t.customStyles)==null?void 0:h.header);return o&&s});Os.displayName="MessageComponent";function JS(e,t){return w.useMemo(()=>{var d,f,p,h,m;const n=e&&"type"in e&&e.type==="default_message";let r=[],o=null,s={},i={},a=null,l=null,c=null;if(!n&&e){const g=e,y=g.checkpointId??null;s=g.additionalKwargs??{},i=g.responseMetadata??{};const x=y&&t.checkpointMetaById?t.checkpointMetaById.get(y)??null:null;a=typeof s.step=="number"?s.step:typeof i.step=="number"?i.step:(x==null?void 0:x.step)??null;const b=typeof s.source=="string"?s.source:typeof i.source=="string"?i.source:(x==null?void 0:x.source)??null;l=b?String(b):null;const C=a!==null&&l?`${a}:${l}`:null;if(C&&((d=t.checkpointIndexByKey)!=null&&d.has(C))?r=t.checkpointIndexByKey.get(C)??[]:y&&x&&(r=[x]),o=y??((f=r[0])==null?void 0:f.id)??null,c=y?((p=t.attemptMetaById)==null?void 0:p.get(y))??null:null,!c&&(e==null?void 0:e.role)==="user"&&(e!=null&&e.id)&&t.userMessageIdToAttempts){const k=t.userMessageIdToAttempts.get(e.id);if(k&&k.length>0){const S=k[0].checkpointId;c=((h=t.attemptMetaById)==null?void 0:h.get(S))??null,c&&console.log(`[useMessageMetadata] Found attempt by user message ID "${e.id}":`,k.length,"versions")}}if(!c&&r.length>0&&t.attemptMetaById){const k=t.attemptMetaById.get(r[0].id);k&&(c=k)}if(c&&c.attemptCount>1&&t.attemptMetaById){const k=c.baseUserMessageId;if(k){const S=[];for(const[T,I]of t.attemptMetaById.entries())if(I.baseUserMessageId===k){const A=(m=t.checkpointMetaById)==null?void 0:m.get(T);A&&S.push(A)}S.length>0&&(r=S)}}if(c&&c.attemptCount>1&&t.checkpointMetaById&&t.attemptMetaById){const k=[];for(const[S,T]of t.checkpointMetaById.entries()){const I=t.attemptMetaById.get(S);I&&I.attemptCount===c.attemptCount&&I.baseUserMessageId===c.baseUserMessageId&&k.push(T)}k.sort((S,T)=>{const I=S.createdAt?Date.parse(S.createdAt):0;return(T.createdAt?Date.parse(T.createdAt):0)-I}),k.length>0&&(r=k,console.log("[useMessageMetadata] Populated checkpointCandidates with all attempts:",{messageId:e.id,attemptCount:c.attemptCount,candidateIds:r.map(S=>S.id)}))}}return{checkpointCandidates:r,defaultCheckpointId:o,attemptMeta:c,resolvedStep:a,resolvedSource:l}},[e,t.checkpointMetaById,t.checkpointIndexByKey,t.attemptMetaById,t.userMessageIdToAttempts])}const up=(e,t)=>(e==null?void 0:e.id)??`message-${t}`,dp=w.memo(function({message:t,index:n,isStreaming:r,streamingAssistantId:o,streamingDebounceMs:s,layoutSize:i,enableMessageEditing:a,editingMessageId:l,onEdit:c,onRegenerate:d,onCancelEdit:f,activeInterrupt:p,disableInterruptActions:h,onInterruptActionStart:m,onInterruptActionEnd:g,showToolMessages:y,showArtifactPreviews:x,checkpointMetaById:b,checkpointIndexByKey:C,attemptMetaById:k,userMessageIdToAttempts:S,activeCheckpointId:T,onSelectCheckpoint:I}){const A=up(t,n),_="type"in t&&t.type==="default_message",{checkpointCandidates:L,defaultCheckpointId:R,attemptMeta:O}=JS(t,{checkpointMetaById:b,checkpointIndexByKey:C,attemptMetaById:k,userMessageIdToAttempts:S}),F=t&&!_?t.additionalKwargs??{}:{},N=t&&!_?t.responseMetadata??{}:{},B=(()=>{if(typeof F.parentCheckpointId=="string")return F.parentCheckpointId;if(typeof N.parentCheckpointId=="string")return N.parentCheckpointId})();return u.jsx("div",{className:"relative mb-4 last:mb-0","data-message-id":A,style:{minHeight:"60px",containIntrinsicSize:"auto 120px"},children:u.jsx(Os,{message:t,messageIndex:n,isStreamingMessage:r&&o===t.id,streamingDebounceMs:s,isEditing:l===t.id,showActions:a,showTimestamp:!1,showAgentName:!0,layoutSize:i,onEdit:c,onRegenerate:()=>d(n),onCancelEdit:f,activeInterrupt:p,disableInterruptActions:h,onInterruptActionStart:m,onInterruptActionEnd:g,showToolMessages:y,showArtifactPreviews:x,checkpointCandidates:L,activeCheckpointId:T??null,onSelectCheckpoint:I,defaultCheckpointId:R,messageParentCheckpointId:B,attemptMeta:O})})});dp.displayName="MessageRow";const _a=w.forwardRef(({messages:e,isStreaming:t,streamingAssistantId:n,streamingDebounceMs:r,layoutSize:o,enableMessageEditing:s,editingMessageId:i,onStartReached:a,onEdit:l,onRegenerate:c,onCancelEdit:d,className:f,style:p,emptyMessage:h,followNewMessages:m=!0,isNavigatingCheckpoint:g=!1,onScrollAway:y,onAtBottom:x,activeInterrupt:b,disableInterruptActions:C=!1,onInterruptActionStart:k,onInterruptActionEnd:S,showToolMessages:T=!0,showArtifactPreviews:I=!0,checkpointMetaById:A,checkpointIndexByKey:_,attemptMetaById:L,userMessageIdToAttempts:R,activeCheckpointId:O,onSelectCheckpoint:F,createSyntheticThinkingMessage:N=!1},B)=>{const j=w.useRef(null),K=w.useRef(null),z=w.useRef(!1),M=w.useRef(!1),[G,X]=w.useState(!0),se=w.useMemo(()=>b?e.some(oe=>"type"in oe&&oe.type==="default_message"?!1:Array.isArray(oe==null?void 0:oe.content)&&oe.content.some(ye=>ye&&ye.type==="interrupt"&&(ye.id??ye.interrupt_id)===b.id)):!1,[b,e]),be=w.useMemo(()=>{if(!b||se)return null;const oe=b.id&&String(b.id).trim()?String(b.id).trim():"pending-interrupt";let ye;const Oe=b.value;if(Oe&&typeof Oe=="object"&&!Array.isArray(Oe)){const Ye=Oe.title;typeof Ye=="string"&&Ye.trim()&&(ye=Ye.trim())}return{id:`interrupt-${oe}`,role:"system",createdAt:new Date().toISOString(),content:[{type:"interrupt",id:oe,value:Oe,title:ye}]}},[b,se]),Ie=w.useMemo(()=>be?[...e,be]:e,[e,be]),Y=w.useMemo(()=>!N||!t?Ie:!Ie.some(ye=>ye.role==="assistant")&&Ie.length>0?[...Ie,{id:"thinking-assistant",role:"assistant",content:[],createdAt:new Date().toISOString()}]:Ie,[Ie,t,N]),U=w.useMemo(()=>T?Y:Y.filter(oe=>(oe==null?void 0:oe.role)!=="tool"),[Y,T]),J=w.useCallback(oe=>{X(oe),y&&y(!oe),x&&x(oe)},[y,x]),$=w.useMemo(()=>{if(a)return async()=>{if(!z.current){z.current=!0;try{await a()}finally{z.current=!1}}}},[a]),q=w.useMemo(()=>!m||g?!1:G?"auto":!1,[G,m,g]),Z=w.useMemo(()=>{if(typeof h!="string")return null;const oe=h.trim();return oe?{id:"default-message",role:"assistant",type:"default_message",content:oe,createdAt:new Date().toISOString()}:null},[h]),ue=["flex h-full flex-col md:flex-row",f].filter(Boolean).join(" "),ie=()=>Z?u.jsx("div",{className:"p-6 h-full overflow-y-auto",children:u.jsx("div",{className:"w-full max-w-full",children:u.jsx(Os,{message:Z,messageIndex:0,isStreamingMessage:!1,showActions:!1,showTimestamp:!1,showAgentName:!0,layoutSize:o,onEdit:()=>{},onRegenerate:()=>{},onCancelEdit:()=>{},showArtifactPreviews:I})})}):u.jsx("div",{className:"flex h-full items-center justify-center py-8 text-center text-muted-foreground",children:h??"No messages yet. Start a conversation!"}),_e=U.length,He=_e>0;return w.useEffect(()=>{var oe,ye;if(_e===0){M.current=!1;return}if(!M.current)if(M.current=!0,j.current&&U.length>0){const Oe=U.length-1;(ye=(oe=j.current).scrollToIndex)==null||ye.call(oe,{index:Oe,align:"end",behavior:"auto"})}else K.current&&(K.current.scrollTop=K.current.scrollHeight)},[_e,U.length]),w.useImperativeHandle(B,()=>({scrollToLatest:()=>{var oe,ye;if(j.current&&U.length>0){const Oe=U.length-1;(ye=(oe=j.current).scrollToIndex)==null||ye.call(oe,{index:Oe,align:"end",behavior:"auto"})}else K.current&&(K.current.scrollTop=K.current.scrollHeight)},scrollToTop:()=>{var oe,ye;j.current&&U.length>0?(ye=(oe=j.current).scrollToIndex)==null||ye.call(oe,{index:0,align:"start",behavior:"auto"}):K.current&&(K.current.scrollTop=0)}}),[U]),u.jsx("div",{className:ue,style:p,children:u.jsx("div",{className:"relative flex-1 min-h-0",children:He?u.jsx(N0,{ref:oe=>{j.current=oe},scrollerRef:oe=>{K.current=oe instanceof HTMLDivElement?oe:null},data:U,followOutput:q,overscan:200,increaseViewportBy:{top:100,bottom:200},defaultItemHeight:80,atBottomThreshold:50,startReached:()=>{$&&$()},atBottomStateChange:J,style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:(oe,ye)=>up(ye,oe),itemContent:(oe,ye)=>u.jsx(dp,{message:ye,index:oe,isStreaming:t,streamingAssistantId:n,streamingDebounceMs:r,layoutSize:o,enableMessageEditing:s,editingMessageId:i,onEdit:l,onRegenerate:c,onCancelEdit:d,activeInterrupt:b,disableInterruptActions:C,onInterruptActionStart:k,onInterruptActionEnd:S,showToolMessages:T,showArtifactPreviews:I,checkpointMetaById:A,checkpointIndexByKey:_,attemptMetaById:L,userMessageIdToAttempts:R,activeCheckpointId:O,onSelectCheckpoint:F})}):ie()})})});_a.displayName="MessageList";const fp={value:""};function Ds({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:c=!0,showToolMessages:d=!0,showArtifactPreviews:f=!0,customStyles:p={},onMessageSent:h,onExcelUploadSuccess:m,onError:g}){const{api:y}=ci(),{currentThreadId:x}=No(),{threadId:b,messages:C,isHistoryLoading:k,isLoading:S,navigateToCheckpoint:T,returnToLatest:I,checkpoint:A,checkpoints:_,interrupt:L,metadata:R,timelineCheckpoints:O,messagePreviews:F}=_o(),{isStreaming:N,error:B,connectionState:j,submit:K,stop:z}=ac(),M=b??x??null,G=(A==null?void 0:A.id)??null,X=(A==null?void 0:A.namespace)??null,se=(R==null?void 0:R.assemblingMessageId)??null,be=L,[Ie,Y]=w.useState(!1);w.useEffect(()=>{be||Y(!1)},[be]);const U=w.useCallback(()=>{Y(!0)},[]),J=w.useCallback(()=>{Y(!1)},[]),$=!!be||Ie,[q,Z]=w.useState(null),[ue,ie]=w.useState(""),[_e,He]=w.useState(null),[oe,ye]=w.useState(null),[Oe,Ye]=w.useState([]),[nt,Xe]=w.useState(0),[qe,it]=w.useState(0),[Je,et]=w.useState(!1),[at,_t]=w.useState(null),[ht,ft]=w.useState(null),[mt,St]=w.useState(!1),[jt,Dt]=w.useState(null),Wt=w.useRef(!1),[Ue,un]=w.useState(()=>fp.value),rt=w.useRef(Ue),We=w.useRef(null),gt=w.useCallback(pe=>{fp.value=pe,un(pe)},[]),[Mt,H]=w.useState(!1),re=w.useRef(null),{checkpointMetaById:D,checkpointIndexByKey:Q,attemptMetaById:ne,userMessageIdToAttempts:me}=gw(_),xe=O??[],De=w.useRef(null),Re=w.useRef(null),je=w.useCallback(()=>{De.current&&(De.current.value=""),Re.current&&(Re.current.value=""),Xe(pe=>pe+1),it(pe=>pe+1)},[]),Vt=w.useCallback(pe=>{gt(pe)},[gt]),En=w.useRef(!1);w.useEffect(()=>{En.current&&!N&&(Ye([]),je()),En.current=N},[N,je]);const[ir,Er]=w.useState("desktop");w.useEffect(()=>{const pe=()=>{const Se=window.innerWidth;Er(Se<640?"phone":Se<1024?"tablet":"desktop")};return pe(),window.addEventListener("resize",pe),()=>window.removeEventListener("resize",pe)},[]),w.useEffect(()=>{Wt.current=!1},[M]),w.useEffect(()=>{rt.current=Ue},[Ue]),w.useEffect(()=>{if(!q){We.current=null;return}We.current===null&&(We.current=rt.current),gt(ue??"")},[ue,q,gt]),w.useEffect(()=>{(async()=>{if(!y.baseUrl){Dt(null);return}try{const Ee=(await y.getAgent("default")).uiDefaultMessage||"";Dt(Ee||null)}catch(Se){console.warn("Failed to fetch default message:",Se),Dt(null)}})()},[y.baseUrl]),w.useEffect(()=>{B&&!mt&&(g==null||g(B))},[B,mt,g]);const fo=pe=>{if(pe.length>ls)return`Message too long (${pe.length}/${ls} characters)`;try{return vw(pe),null}catch(Se){return(Se==null?void 0:Se.message)||"Invalid message"}},zn=async pe=>{const Se=pe.trim();if(!(!Se&&Oe.length===0)){if(Se){const Ee=fo(Se);if(Ee){ye(Ee);return}}try{const Ee=q?(_e==null?void 0:_e.checkpointId)??G??void 0:G??void 0,Ve=q?(_e==null?void 0:_e.checkpointNs)??X??void 0:X??void 0;await K({text:Se||"",attachments:Oe},{checkpointId:Ee,checkpointNs:Ve,edit:!!q,originalMessageId:q??void 0}),h==null||h(Se),gt(""),ye(null),Ye([]),je(),Z(null),ie(""),He(null)}catch(Ee){const Ve=(Ee==null?void 0:Ee.message)||"Failed to send message";ye(Ve),g==null||g(Ve)}}},ar=w.useCallback((pe,Se,Ee)=>{c&&(We.current=Ue,Z(pe),ie(Se),gt(Se),ye(null),He({checkpointId:(Ee==null?void 0:Ee.checkpointId)??null,checkpointNs:(Ee==null?void 0:Ee.checkpointNs)??null}))},[Ue,c,gt]),E=w.useCallback(()=>{Z(null),ie(""),He(null),ye(null),gt(We.current??Ue),We.current=null},[Ue,gt]),V=w.useCallback((pe,Se,Ee)=>{ar(pe,Se,Ee)},[ar]),ae=w.useCallback(pe=>{let Se=null;for(let tn=pe-1;tn>=0;tn--)if(C[tn].role==="user"){Se=C[tn];break}if(!Se)return;const Ee=Array.isArray(Se.content)?Se.content:[],Un=Ee.filter(tn=>(tn==null?void 0:tn.type)==="text").map(tn=>tn.text).join("")||(()=>{try{return JSON.stringify(Ee,null,2)}catch{return String(Ee)}})();Un&&K({text:Un},{checkpointId:G??void 0,checkpointNs:X??void 0,edit:!0,originalMessageId:Se.id})},[C,K,G,X]),we=pe=>{const Se=Array.from(pe.target.files||[]);Ye(Ee=>[...Ee,...Se]),pe.target.value=""},Ge=pe=>{Ye(Se=>{const Ee=Se.filter((Ve,Un)=>pe!==Un);return Ee.length===0&&je(),Ee})},tt=async pe=>{const Se=(pe.target.files||[])[0];if(Se){_t(null),ft(null),et(!0);try{await K({attachments:[Se]},{checkpointId:G??void 0,checkpointNs:X??void 0});const Ee=`Uploaded ${Se.name} - processing through chat stream`;ft(Ee)}catch(Ee){const Ve=Ee instanceof Error?Ee.message:"Failed to upload Excel file";console.error("Excel upload failed",Ee),_t(Ve),g==null||g(Ve)}finally{et(!1),pe.target.value="",je()}}},Fe=async pe=>{if(x){H(!0);try{if(!pe){await I(),requestAnimationFrame(()=>{var Ve;(Ve=re.current)==null||Ve.scrollToLatest()});return}const Se=_.find(Ve=>Ve.checkpointId===pe),Ee=(Se==null?void 0:Se.checkpointNs)??null;await T(pe,Ee),requestAnimationFrame(()=>{var Ve;(Ve=re.current)==null||Ve.scrollToTop()})}finally{H(!1)}}},$e=w.useCallback(async(pe,Se,Ee)=>{await Fe(Ee?null:pe)},[Fe]),kt=`flex flex-1 w-full flex-col min-h-0 min-w-0 max-h-full overflow-hidden bg-transparent ${e} ${p.container||""}`,pt=`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 ${p.messagesArea||""}`,xt=`relative flex-shrink-0 w-full border-t p-4 bg-transparent ${p.inputArea||""}`;return u.jsxs("div",{className:kt,children:[!!B&&!mt&&u.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:[u.jsx("span",{children:B}),u.jsx(Ze,{variant:"ghost",size:"sm",onClick:()=>St(!0),className:"text-red-800 hover:bg-red-100","aria-label":"Dismiss error",children:u.jsx(le.X,{size:16})})]}),u.jsxs("div",{className:`relative ${pt}`,style:r?{maxHeight:r}:void 0,children:[u.jsx(_a,{ref:re,className:"h-full",style:{height:"100%"},messages:C,isStreaming:N,streamingAssistantId:se,streamingDebounceMs:typeof s=="number"?s:o,followNewMessages:i,layoutSize:ir,enableMessageEditing:c,editingMessageId:q,onEdit:V,onRegenerate:ae,onCancelEdit:E,emptyMessage:jt??void 0,isNavigatingCheckpoint:Mt,activeInterrupt:be,disableInterruptActions:Ie,onInterruptActionStart:U,onInterruptActionEnd:J,showToolMessages:d,showArtifactPreviews:f,checkpointMetaById:D,checkpointIndexByKey:Q,attemptMetaById:ne,userMessageIdToAttempts:me,activeCheckpointId:G,onSelectCheckpoint:$e,timelineCheckpoints:xe,messagePreviews:F}),(j==="reconnecting"||j==="connecting")&&u.jsx("div",{className:"pointer-events-none absolute top-3 right-3 z-20 rounded-full bg-muted/80 px-3 py-1 text-xs font-medium text-foreground shadow-sm backdrop-blur-sm dark:bg-muted/60",children:u.jsxs("span",{className:"flex items-center gap-2",children:[u.jsx(le.Loader2,{className:"h-3 w-3 animate-spin"}),j==="reconnecting"?"Reconnecting…":"Connecting…"]})}),j==="error"&&u.jsx("div",{className:"pointer-events-none absolute top-3 right-3 z-20 rounded-full bg-destructive/10 px-3 py-1 text-xs font-semibold text-destructive shadow-sm",children:"Connection lost"}),S&&u.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:[u.jsx(le.Loader2,{className:"h-6 w-6 animate-spin"}),u.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:"Loading messages…"})]}),(k||Mt)&&u.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:[u.jsx(le.Loader2,{className:"h-6 w-6 animate-spin"}),u.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:"Loading checkpoint…"})]})]}),u.jsxs("div",{className:xt,children:[q&&u.jsx("div",{className:"mb-3 p-3 bg-blue-50 border border-blue-200 rounded-lg",children:u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx(le.Edit3,{size:16,className:"text-blue-600"}),u.jsx("span",{className:"text-sm font-medium text-blue-800",children:"Editing message"})]}),u.jsx(Ze,{variant:"ghost",size:"sm",onClick:E,className:"text-blue-600 hover:bg-blue-100",children:u.jsx(le.X,{size:16})})]})}),(a||l)&&u.jsxs("div",{className:"mb-3 space-y-3",children:[a&&u.jsxs(u.Fragment,{children:[u.jsx("input",{ref:De,type:"file",multiple:!0,onChange:pe=>we(pe),className:"hidden"},nt),Oe.length>0&&u.jsx("div",{className:"flex flex-wrap gap-2",children:Oe.map((pe,Se)=>u.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:[u.jsx(le.Paperclip,{size:14}),u.jsx("span",{className:"truncate max-w-[150px]",children:pe.name}),u.jsx(Ze,{variant:"ghost",size:"sm",onClick:()=>Ge(Se),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 ${pe.name}`,children:u.jsx(le.X,{size:12})})]},Se))})]}),l&&u.jsxs(u.Fragment,{children:[u.jsx("input",{ref:Re,type:"file",accept:".xls,.xlsx,.xlsm",onChange:tt,className:"hidden"},qe),Je&&u.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[u.jsx(le.Loader2,{className:"h-4 w-4 animate-spin"})," Uploading Excel file..."]}),ht&&!Je&&u.jsx("div",{className:"text-sm rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-emerald-700",children:ht}),at&&!Je&&u.jsx("div",{className:"text-sm rounded border border-red-200 bg-red-50 px-3 py-2 text-red-600",children:at})]})]}),oe&&u.jsx("div",{className:"mb-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2",children:oe}),u.jsxs("div",{className:"flex items-end gap-2",children:[(a||l)&&u.jsxs(nw,{children:[u.jsx(rw,{asChild:!0,children:u.jsx(Ze,{type:"button",size:"icon",variant:"outline",disabled:N||$,title:"More input actions",className:p.moreButton||"",children:u.jsx(le.Plus,{size:16})})}),u.jsxs(yd,{align:"start",sideOffset:6,className:"w-52",children:[a&&u.jsxs(Ji,{onClick:()=>{var pe;return(pe=De.current)==null?void 0:pe.click()},className:"cursor-pointer",children:[u.jsx(le.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]}),l&&u.jsxs(Ji,{onClick:()=>{var pe;Je||(pe=Re.current)==null||pe.click()},className:`cursor-pointer ${Je?"opacity-60 pointer-events-none":""}`,children:[u.jsx(le.FileSpreadsheet,{className:"h-4 w-4 mr-2"})," Upload Excel file"]})]})]}),u.jsx("div",{className:"flex-1",children:u.jsx(rx,{initialValue:ue,editingMessageId:q,value:Ue,onValueChange:Vt,placeholder:q?"Edit your message...":t,isStreaming:N,disabled:$,maxLength:ls,onSend:zn,onCancelEdit:E,onStop:z,allowEmptySend:Oe.length>0,textareaClassName:`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${q?"border-blue-400 bg-blue-50 text-blue-900 dark:border-blue-500 dark:bg-blue-950/60 dark:text-blue-50":""} ${oe?"border-red-400":""} ${p.textarea||""}`})})]})]})]})}const Ls=v.forwardRef(({className:e,type:t,...n},r)=>u.jsx("input",{type:t,className:te("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}));Ls.displayName="Input";function ja(e,[t,n]){return Math.min(n,Math.max(t,e))}function ZS(e,t){return v.useReducer((n,r)=>t[n][r]??n,e)}var Ma="ScrollArea",[pp,UT]=Sn(Ma),[QS,Qt]=pp(Ma),hp=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,type:r="hover",dir:o,scrollHideDelay:s=600,...i}=e,[a,l]=v.useState(null),[c,d]=v.useState(null),[f,p]=v.useState(null),[h,m]=v.useState(null),[g,y]=v.useState(null),[x,b]=v.useState(0),[C,k]=v.useState(0),[S,T]=v.useState(!1),[I,A]=v.useState(!1),_=Be(t,R=>l(R)),L=Mo(o);return u.jsx(QS,{scope:n,type:r,dir:L,scrollHideDelay:s,scrollArea:a,viewport:c,onViewportChange:d,content:f,onContentChange:p,scrollbarX:h,onScrollbarXChange:m,scrollbarXEnabled:S,onScrollbarXEnabledChange:T,scrollbarY:g,onScrollbarYChange:y,scrollbarYEnabled:I,onScrollbarYEnabledChange:A,onCornerWidthChange:b,onCornerHeightChange:k,children:u.jsx(Ne.div,{dir:L,...i,ref:_,style:{position:"relative","--radix-scroll-area-corner-width":x+"px","--radix-scroll-area-corner-height":C+"px",...e.style}})})});hp.displayName=Ma;var mp="ScrollAreaViewport",gp=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,i=Qt(mp,n),a=v.useRef(null),l=Be(t,a,i.onViewportChange);return u.jsxs(u.Fragment,{children:[u.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}),u.jsx(Ne.div,{"data-radix-scroll-area-viewport":"",...s,ref:l,style:{overflowX:i.scrollbarXEnabled?"scroll":"hidden",overflowY:i.scrollbarYEnabled?"scroll":"hidden",...e.style},children:u.jsx("div",{ref:i.onContentChange,style:{minWidth:"100%",display:"table"},children:r})})]})});gp.displayName=mp;var bn="ScrollAreaScrollbar",Ra=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Qt(bn,e.__scopeScrollArea),{onScrollbarXEnabledChange:s,onScrollbarYEnabledChange:i}=o,a=e.orientation==="horizontal";return v.useEffect(()=>(a?s(!0):i(!0),()=>{a?s(!1):i(!1)}),[a,s,i]),o.type==="hover"?u.jsx(eC,{...r,ref:t,forceMount:n}):o.type==="scroll"?u.jsx(tC,{...r,ref:t,forceMount:n}):o.type==="auto"?u.jsx(xp,{...r,ref:t,forceMount:n}):o.type==="always"?u.jsx(Pa,{...r,ref:t}):null});Ra.displayName=bn;var eC=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Qt(bn,e.__scopeScrollArea),[s,i]=v.useState(!1);return v.useEffect(()=>{const a=o.scrollArea;let l=0;if(a){const c=()=>{window.clearTimeout(l),i(!0)},d=()=>{l=window.setTimeout(()=>i(!1),o.scrollHideDelay)};return a.addEventListener("pointerenter",c),a.addEventListener("pointerleave",d),()=>{window.clearTimeout(l),a.removeEventListener("pointerenter",c),a.removeEventListener("pointerleave",d)}}},[o.scrollArea,o.scrollHideDelay]),u.jsx(Yt,{present:n||s,children:u.jsx(xp,{"data-state":s?"visible":"hidden",...r,ref:t})})}),tC=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Qt(bn,e.__scopeScrollArea),s=e.orientation==="horizontal",i=zs(()=>l("SCROLL_END"),100),[a,l]=ZS("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 v.useEffect(()=>{if(a==="idle"){const c=window.setTimeout(()=>l("HIDE"),o.scrollHideDelay);return()=>window.clearTimeout(c)}},[a,o.scrollHideDelay,l]),v.useEffect(()=>{const c=o.viewport,d=s?"scrollLeft":"scrollTop";if(c){let f=c[d];const p=()=>{const h=c[d];f!==h&&(l("SCROLL"),i()),f=h};return c.addEventListener("scroll",p),()=>c.removeEventListener("scroll",p)}},[o.viewport,s,l,i]),u.jsx(Yt,{present:n||a!=="hidden",children:u.jsx(Pa,{"data-state":a==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:fe(e.onPointerEnter,()=>l("POINTER_ENTER")),onPointerLeave:fe(e.onPointerLeave,()=>l("POINTER_LEAVE"))})})}),xp=v.forwardRef((e,t)=>{const n=Qt(bn,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,i]=v.useState(!1),a=e.orientation==="horizontal",l=zs(()=>{if(n.viewport){const c=n.viewport.offsetWidth<n.viewport.scrollWidth,d=n.viewport.offsetHeight<n.viewport.scrollHeight;i(a?c:d)}},10);return Tr(n.viewport,l),Tr(n.content,l),u.jsx(Yt,{present:r||s,children:u.jsx(Pa,{"data-state":s?"visible":"hidden",...o,ref:t})})}),Pa=v.forwardRef((e,t)=>{const{orientation:n="vertical",...r}=e,o=Qt(bn,e.__scopeScrollArea),s=v.useRef(null),i=v.useRef(0),[a,l]=v.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),c=Sp(a.viewport,a.content),d={...r,sizes:a,onSizesChange:l,hasThumb:c>0&&c<1,onThumbChange:p=>s.current=p,onThumbPointerUp:()=>i.current=0,onThumbPointerDown:p=>i.current=p};function f(p,h){return aC(p,i.current,a,h)}return n==="horizontal"?u.jsx(nC,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const p=o.viewport.scrollLeft,h=Cp(p,a,o.dir);s.current.style.transform=`translate3d(${h}px, 0, 0)`}},onWheelScroll:p=>{o.viewport&&(o.viewport.scrollLeft=p)},onDragScroll:p=>{o.viewport&&(o.viewport.scrollLeft=f(p,o.dir))}}):n==="vertical"?u.jsx(rC,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const p=o.viewport.scrollTop,h=Cp(p,a);s.current.style.transform=`translate3d(0, ${h}px, 0)`}},onWheelScroll:p=>{o.viewport&&(o.viewport.scrollTop=p)},onDragScroll:p=>{o.viewport&&(o.viewport.scrollTop=f(p))}}):null}),nC=v.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=Qt(bn,e.__scopeScrollArea),[i,a]=v.useState(),l=v.useRef(null),c=Be(t,l,s.onScrollbarXChange);return v.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(vp,{"data-orientation":"horizontal",...o,ref:c,sizes:n,style:{bottom:0,left:s.dir==="rtl"?"var(--radix-scroll-area-corner-width)":0,right:s.dir==="ltr"?"var(--radix-scroll-area-corner-width)":0,"--radix-scroll-area-thumb-width":Bs(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.x),onDragScroll:d=>e.onDragScroll(d.x),onWheelScroll:(d,f)=>{if(s.viewport){const p=s.viewport.scrollLeft+d.deltaX;e.onWheelScroll(p),kp(p,f)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollWidth,viewport:s.viewport.offsetWidth,scrollbar:{size:l.current.clientWidth,paddingStart:Fs(i.paddingLeft),paddingEnd:Fs(i.paddingRight)}})}})}),rC=v.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=Qt(bn,e.__scopeScrollArea),[i,a]=v.useState(),l=v.useRef(null),c=Be(t,l,s.onScrollbarYChange);return v.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(vp,{"data-orientation":"vertical",...o,ref:c,sizes:n,style:{top:0,right:s.dir==="ltr"?0:void 0,left:s.dir==="rtl"?0:void 0,bottom:"var(--radix-scroll-area-corner-height)","--radix-scroll-area-thumb-height":Bs(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.y),onDragScroll:d=>e.onDragScroll(d.y),onWheelScroll:(d,f)=>{if(s.viewport){const p=s.viewport.scrollTop+d.deltaY;e.onWheelScroll(p),kp(p,f)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollHeight,viewport:s.viewport.offsetHeight,scrollbar:{size:l.current.clientHeight,paddingStart:Fs(i.paddingTop),paddingEnd:Fs(i.paddingBottom)}})}})}),[oC,yp]=pp(bn),vp=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,sizes:r,hasThumb:o,onThumbChange:s,onThumbPointerUp:i,onThumbPointerDown:a,onThumbPositionChange:l,onDragScroll:c,onWheelScroll:d,onResize:f,...p}=e,h=Qt(bn,n),[m,g]=v.useState(null),y=Be(t,_=>g(_)),x=v.useRef(null),b=v.useRef(""),C=h.viewport,k=r.content-r.viewport,S=Tt(d),T=Tt(l),I=zs(f,10);function A(_){if(x.current){const L=_.clientX-x.current.left,R=_.clientY-x.current.top;c({x:L,y:R})}}return v.useEffect(()=>{const _=L=>{const R=L.target;(m==null?void 0:m.contains(R))&&S(L,k)};return document.addEventListener("wheel",_,{passive:!1}),()=>document.removeEventListener("wheel",_,{passive:!1})},[C,m,k,S]),v.useEffect(T,[r,T]),Tr(m,I),Tr(h.content,I),u.jsx(oC,{scope:n,scrollbar:m,hasThumb:o,onThumbChange:Tt(s),onThumbPointerUp:Tt(i),onThumbPositionChange:T,onThumbPointerDown:Tt(a),children:u.jsx(Ne.div,{...p,ref:y,style:{position:"absolute",...p.style},onPointerDown:fe(e.onPointerDown,_=>{_.button===0&&(_.target.setPointerCapture(_.pointerId),x.current=m.getBoundingClientRect(),b.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",h.viewport&&(h.viewport.style.scrollBehavior="auto"),A(_))}),onPointerMove:fe(e.onPointerMove,A),onPointerUp:fe(e.onPointerUp,_=>{const L=_.target;L.hasPointerCapture(_.pointerId)&&L.releasePointerCapture(_.pointerId),document.body.style.webkitUserSelect=b.current,h.viewport&&(h.viewport.style.scrollBehavior=""),x.current=null})})})}),$s="ScrollAreaThumb",bp=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=yp($s,e.__scopeScrollArea);return u.jsx(Yt,{present:n||o.hasThumb,children:u.jsx(sC,{ref:t,...r})})}),sC=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=Qt($s,n),i=yp($s,n),{onThumbPositionChange:a}=i,l=Be(t,f=>i.onThumbChange(f)),c=v.useRef(void 0),d=zs(()=>{c.current&&(c.current(),c.current=void 0)},100);return v.useEffect(()=>{const f=s.viewport;if(f){const p=()=>{if(d(),!c.current){const h=lC(f,a);c.current=h,a()}};return a(),f.addEventListener("scroll",p),()=>f.removeEventListener("scroll",p)}},[s.viewport,d,a]),u.jsx(Ne.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 h=f.target.getBoundingClientRect(),m=f.clientX-h.left,g=f.clientY-h.top;i.onThumbPointerDown({x:m,y:g})}),onPointerUp:fe(e.onPointerUp,i.onThumbPointerUp)})});bp.displayName=$s;var Oa="ScrollAreaCorner",wp=v.forwardRef((e,t)=>{const n=Qt(Oa,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?u.jsx(iC,{...e,ref:t}):null});wp.displayName=Oa;var iC=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=Qt(Oa,n),[s,i]=v.useState(0),[a,l]=v.useState(0),c=!!(s&&a);return Tr(o.scrollbarX,()=>{var f;const d=((f=o.scrollbarX)==null?void 0:f.offsetHeight)||0;o.onCornerHeightChange(d),l(d)}),Tr(o.scrollbarY,()=>{var f;const d=((f=o.scrollbarY)==null?void 0:f.offsetWidth)||0;o.onCornerWidthChange(d),i(d)}),c?u.jsx(Ne.div,{...r,ref:t,style:{width:s,height:a,position:"absolute",right:o.dir==="ltr"?0:void 0,left:o.dir==="rtl"?0:void 0,bottom:0,...e.style}}):null});function Fs(e){return e?parseInt(e,10):0}function Sp(e,t){const n=e/t;return isNaN(n)?0:n}function Bs(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 aC(e,t,n,r="ltr"){const o=Bs(n),s=o/2,i=t||s,a=o-i,l=n.scrollbar.paddingStart+i,c=n.scrollbar.size-n.scrollbar.paddingEnd-a,d=n.content-n.viewport,f=r==="ltr"?[0,d]:[d*-1,0];return Tp([l,c],f)(e)}function Cp(e,t,n="ltr"){const r=Bs(t),o=t.scrollbar.paddingStart+t.scrollbar.paddingEnd,s=t.scrollbar.size-o,i=t.content-t.viewport,a=s-r,l=n==="ltr"?[0,i]:[i*-1,0],c=ja(e,l);return Tp([0,i],[0,a])(c)}function Tp(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 kp(e,t){return e>0&&e<t}var lC=(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 zs(e,t){const n=Tt(e),r=v.useRef(0);return v.useEffect(()=>()=>window.clearTimeout(r.current),[]),v.useCallback(()=>{window.clearTimeout(r.current),r.current=window.setTimeout(n,t)},[n,t])}function Tr(e,t){const n=Tt(t);Ct(()=>{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 Ip=hp,cC=gp,uC=wp;const Ep=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Ip,{ref:r,className:te("relative overflow-hidden",e),...n,children:[u.jsx(cC,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),u.jsx(Ap,{}),u.jsx(uC,{})]}));Ep.displayName=Ip.displayName;const Ap=v.forwardRef(({className:e,orientation:t="vertical",...n},r)=>u.jsx(Ra,{ref:r,orientation:t,className:te("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:u.jsx(bp,{className:"relative flex-1 rounded-full bg-border"})}));Ap.displayName=Ra.displayName;const Np=25;function Da({className:e="",showCreateButton:t=!0,showDeleteButton:n=!0,showEditTitle:r=!0,maxHeight:o="400px",customStyles:s={},currentThreadId:i=null,navigateToThread:a,onThreadSelect:l,onThreadCreate:c,onThreadDelete:d}){const{threads:f,currentThreadId:p,setCurrentThreadId:h,isLoading:m,actions:g}=No(),{loadThread:y}=_o(),{createThread:x,deleteThread:b,renameThread:C}=g,[k,S]=w.useState(Array.isArray(f)?f:[]),T=w.useRef(k.length>0),I=w.useRef(null),A=w.useRef(0),[_,L]=w.useState(null),[R,O]=w.useState(""),[F,N]=w.useState(!1);w.useEffect(()=>{const Y=Array.isArray(f)?f:[];if(Y.length>0){T.current=!0,S(Y);return}m||(T.current=!1,S(Y))},[f,m]),w.useEffect(()=>{if(!I.current)return;const Y=I.current.querySelector("[data-radix-scroll-area-viewport]");if(!Y)return;let U=null,J=null;return U=requestAnimationFrame(()=>{J=requestAnimationFrame(()=>{Y.scrollTop=A.current})}),()=>{U!==null&&cancelAnimationFrame(U),J!==null&&cancelAnimationFrame(J)}},[k]);const B=async Y=>{try{h(Y),await y(Y),a==null||a(Y),l==null||l(Y)}catch(U){console.error("Failed to select thread:",U)}},j=async()=>{try{N(!0);const Y=await x();Y&&(c==null||c(Y),a==null||a(Y))}catch(Y){console.error("Failed to create thread:",Y)}finally{N(!1)}},K=async(Y,U)=>{if(U.stopPropagation(),!!confirm("Delete this thread?")){if(I.current){const J=I.current.querySelector("[data-radix-scroll-area-viewport]");J&&(A.current=J.scrollTop)}try{await b(Y),d==null||d(Y)}catch(J){console.error("Failed to delete thread:",J)}}},z=(Y,U)=>{U.stopPropagation(),L(Y.threadId),O(Y.title||`Thread ${Y.threadId.slice(0,8)}`)},M=async Y=>{if(R.trim())try{await C(Y,R.trim()),L(null),O("")}catch(U){console.error("Failed to update title:",U)}},G=()=>{L(null),O("")},X=(Y,U)=>{Y.key==="Enter"?M(U):Y.key==="Escape"&&G()},se=Y=>{if(!Y)return"";try{const U=new Date(Y),$=new Date().getTime()-U.getTime(),q=Math.floor($/(1e3*60*60*24));return q===0?U.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):q===1?"Yesterday":q<7?`${q} days ago`:U.toLocaleDateString()}catch{return""}},be=Y=>Y.title||`Thread ${Y.threadId.slice(0,8)}`,Ie=Y=>{const U=be(Y);return U.length<=Np?U:`${U.slice(0,Np)}...`};return u.jsxs("div",{className:`flex flex-col h-full ${e} ${s.container||""}`,children:[t&&u.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:u.jsx(Ze,{onClick:j,disabled:F||m,className:s.createButton||"p-2",size:"sm",variant:"ghost",title:F?"Creating...":"New Chat",children:u.jsx(le.MessageSquarePlus,{size:20})})}),u.jsx(Ep,{ref:I,className:`flex-1 min-h-0 ${s.threadList||""}`,style:o?{maxHeight:o}:void 0,children:u.jsx("div",{className:"p-2 space-y-1 pb-4",children:m?u.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 py-8 text-slate-400",children:[u.jsx(le.Loader2,{className:"h-5 w-5 animate-spin"}),u.jsx("span",{className:"text-sm",children:"Loading threads…"})]}):k.length===0?u.jsxs("div",{className:"text-center py-8 text-slate-400",children:[u.jsx(le.MessageSquare,{className:"w-8 h-8 mx-auto mb-2 opacity-40 text-slate-500"}),u.jsx("p",{className:"text-sm text-slate-500",children:"No conversations yet"})]}):k.slice().sort((Y,U)=>new Date(U.updatedAt||U.createdAt||"").getTime()-new Date(Y.updatedAt||Y.createdAt||"").getTime()).map(Y=>u.jsxs("div",{onClick:()=>B(Y.threadId),className:`group relative p-3 rounded-lg cursor-pointer transition-colors border ${(i??p)===Y.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:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx("div",{className:"flex-1 min-w-0",children:_===Y.threadId?u.jsxs("div",{className:"flex items-center gap-2",onClick:U=>U.stopPropagation(),children:[u.jsx(Ls,{value:R,onChange:U=>O(U.target.value),onKeyDown:U=>X(U,Y.threadId),className:"h-6 text-sm",autoFocus:!0}),u.jsx(Ze,{variant:"ghost",size:"sm",onClick:()=>M(Y.threadId),className:"h-6 w-6 p-0",children:u.jsx(le.Check,{size:12})}),u.jsx(Ze,{variant:"ghost",size:"sm",onClick:G,className:"h-6 w-6 p-0",children:u.jsx(le.X,{size:12})})]}):u.jsxs(u.Fragment,{children:[u.jsx("div",{className:"font-medium text-sm truncate text-gray-900 dark:text-slate-100",children:Ie(Y)}),u.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500 dark:text-slate-400 mt-1",children:[u.jsx(le.Calendar,{size:10}),u.jsx("span",{children:se(Y.updatedAt||Y.createdAt)})]})]})}),u.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity ml-2",children:[r&&_!==Y.threadId&&u.jsx(Ze,{variant:"ghost",size:"sm",onClick:U=>z(Y,U),className:"h-6 w-6 p-0",title:"Edit title",children:u.jsx(le.Edit3,{size:12})}),n&&u.jsx(Ze,{variant:"ghost",size:"sm",onClick:U=>K(Y.threadId,U),className:"h-6 w-6 p-0 text-red-400 hover:text-red-300 hover:bg-red-900/20",title:"Delete thread",children:u.jsx(le.Trash2,{size:12})})]})]}),i===Y.threadId&&u.jsx("div",{className:"absolute left-0 top-1/2 -translate-y-1/2 w-1 h-8 bg-blue-400 rounded-r"})]},Y.threadId))})})]})}const dC=({timelineEntries:e,activeCheckpointId:t,onSelectCheckpoint:n,messagePreviews:r,className:o,onHoverStart:s,onHoverEnd:i})=>{const a=e??[],l=a.length>0,c=w.useMemo(()=>l?[...a].reverse():[],[a,l]),d=t??(a.length?a[a.length-1].id:null);if(!l)return null;const p=["w-32 flex-shrink-0 flex-col border-r border-border/40 pr-2 flex bg-white text-gray-900 dark:bg-slate-900 dark:text-slate-100",o].filter(Boolean).join(" ");return u.jsxs("div",{className:p,onMouseEnter:s,onMouseLeave:i,children:[u.jsxs("div",{className:"relative flex-1 overflow-y-auto pt-4 pb-2 pr-1",children:[u.jsx("div",{className:"absolute left-0 right-0 top-1 px-2 pb-3 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground",children:u.jsx("span",{children:"Timeline"})}),u.jsx("div",{className:"pointer-events-none absolute left-3 top-0 bottom-0 w-px bg-border/40"}),u.jsx("div",{className:"flex flex-col gap-3 pt-6 pr-2",children:c.map(h=>{const m=d===h.id,g=(r==null?void 0:r.get(h.id))??null;return u.jsxs("button",{type:"button",disabled:!n,onClick:()=>n==null?void 0:n(h.id),className:`relative flex items-start gap-2 text-left text-[11px] transition ${m?"text-primary":"text-muted-foreground"} ${n?"hover:text-foreground":"cursor-default opacity-70"}`,children:[u.jsx("span",{className:`mt-1 inline-flex h-3 w-3 items-center justify-center rounded-full border ${m?"border-primary bg-primary/10 text-primary":"border-border bg-background"}`,children:u.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${m?"bg-primary":"bg-border"}`})}),u.jsxs("span",{className:"flex-1",children:[u.jsx("span",{className:"block font-medium leading-tight",children:h.label||"User input"}),u.jsxs("span",{className:"text-[9px] uppercase tracking-wide text-muted-foreground/70",children:[h.step!==null?`STEP ${h.step}`:"STEP —",h.next?` - ${h.next}`:""]}),g&&u.jsx("p",{className:"text-[10px] text-muted-foreground/80 mt-1 line-clamp-2",title:g,children:g})]})]},h.id)})})]}),n&&u.jsx("button",{type:"button",onClick:()=>n==null?void 0:n(null),className:"mt-auto mb-3 rounded-md border border-border/70 px-2 py-1 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground transition hover:border-foreground/60 hover:text-foreground",children:"Latest"})]})};function kr(e){if(!(typeof globalThis>"u"))return globalThis[e]}function fC(e){if(typeof e!="string")return;const t=e.trim();if(t)return wn(t)}function _p(){const e=[kr("__API_BASE_URL__"),kr("__CHAT_API_BASE_URL__"),kr("__CHAT_API_URL__")];for(const t of e){const n=fC(t);if(n)return n}}function jp(){const e=[kr("__API_AUTH_TOKEN__"),kr("__CHAT_API_KEY__"),kr("__CHAT_AUTH_TOKEN__")];for(const t of e)if(typeof t=="string"&&t.trim())return t.trim()}function Mp(...e){for(const t of e)if(typeof t=="string"&&t.trim())return wn(t);return wn()}function Rp(){const e={},t=_p(),n=jp();return t&&(e.baseUrl=t),n&&(e.apiKey=n),e}function Pp(){const e=Rp(),t=An.getAuthToken(),n=_p();return{apiBaseUrl:Mp(e.baseUrl,An.baseUrl,n),apiKey:t||e.apiKey||jp()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,darkMode:!1,enableSound:!1,messageHistory:100}}const Op="chat-settings";function pC(){try{const e=localStorage.getItem(Op);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function hC(e){try{const t={...e,apiBaseUrl:wn(e.apiBaseUrl)};localStorage.setItem(Op,JSON.stringify(t)),t.apiKey&&An.setAuthToken(t.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function mC(){const e=Pp(),t=pC(),n=An.getAuthToken(),r=typeof t.apiBaseUrl=="string"?t.apiBaseUrl:void 0;return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:Mp(An.baseUrl,r,e.apiBaseUrl)}}function gC(e){An.updateConfig({baseUrl:e.apiBaseUrl,authToken:e.apiKey??void 0}),hC(e)}var xC="Label",Dp=v.forwardRef((e,t)=>u.jsx(Ne.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())}}));Dp.displayName=xC;var Lp=Dp;const yC=po.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),en=v.forwardRef(({className:e,...t},n)=>u.jsx(Lp,{ref:n,className:te(yC(),e),...t}));en.displayName=Lp.displayName;function $p(e){const t=v.useRef({value:e,previous:e});return v.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}var Fp=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"}),vC="VisuallyHidden",bC=v.forwardRef((e,t)=>u.jsx(Ne.span,{...e,ref:t,style:{...Fp,...e.style}}));bC.displayName=vC;var wC=[" ","Enter","ArrowUp","ArrowDown"],SC=[" ","Enter"],rr="Select",[Us,Hs,CC]=gi(rr),[Ir,HT]=Sn(rr,[CC,Vo]),Ws=Vo(),[TC,$n]=Ir(rr),[kC,IC]=Ir(rr),Bp=e=>{const{__scopeSelect:t,children:n,open:r,defaultOpen:o,onOpenChange:s,value:i,defaultValue:a,onValueChange:l,dir:c,name:d,autoComplete:f,disabled:p,required:h,form:m}=e,g=Ws(t),[y,x]=v.useState(null),[b,C]=v.useState(null),[k,S]=v.useState(!1),T=Mo(c),[I,A]=fr({prop:r,defaultProp:o??!1,onChange:s,caller:rr}),[_,L]=fr({prop:i,defaultProp:a,onChange:l,caller:rr}),R=v.useRef(null),O=y?m||!!y.closest("form"):!0,[F,N]=v.useState(new Set),B=Array.from(F).map(j=>j.props.value).join(";");return u.jsx(tu,{...g,children:u.jsxs(TC,{required:h,scope:t,trigger:y,onTriggerChange:x,valueNode:b,onValueNodeChange:C,valueNodeHasChildren:k,onValueNodeHasChildrenChange:S,contentId:Cn(),value:_,onValueChange:L,open:I,onOpenChange:A,dir:T,triggerPointerDownPosRef:R,disabled:p,children:[u.jsx(Us.Provider,{scope:t,children:u.jsx(kC,{scope:e.__scopeSelect,onNativeOptionAdd:v.useCallback(j=>{N(K=>new Set(K).add(j))},[]),onNativeOptionRemove:v.useCallback(j=>{N(K=>{const z=new Set(K);return z.delete(j),z})},[]),children:n})}),O?u.jsxs(uh,{"aria-hidden":!0,required:h,tabIndex:-1,name:d,autoComplete:f,value:_,onChange:j=>L(j.target.value),disabled:p,form:m,children:[_===void 0?u.jsx("option",{value:""}):null,Array.from(F)]},B):null]})})};Bp.displayName=rr;var zp="SelectTrigger",Up=v.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...o}=e,s=Ws(n),i=$n(zp,n),a=i.disabled||r,l=Be(t,i.onTriggerChange),c=Hs(n),d=v.useRef("touch"),[f,p,h]=fh(g=>{const y=c().filter(C=>!C.disabled),x=y.find(C=>C.value===i.value),b=ph(y,g,x);b!==void 0&&i.onValueChange(b.value)}),m=g=>{a||(i.onOpenChange(!0),h()),g&&(i.triggerPointerDownPosRef.current={x:Math.round(g.pageX),y:Math.round(g.pageY)})};return u.jsx(nu,{asChild:!0,...s,children:u.jsx(Ne.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":dh(i.value)?"":void 0,...o,ref:l,onClick:fe(o.onClick,g=>{g.currentTarget.focus(),d.current!=="mouse"&&m(g)}),onPointerDown:fe(o.onPointerDown,g=>{d.current=g.pointerType;const y=g.target;y.hasPointerCapture(g.pointerId)&&y.releasePointerCapture(g.pointerId),g.button===0&&g.ctrlKey===!1&&g.pointerType==="mouse"&&(m(g),g.preventDefault())}),onKeyDown:fe(o.onKeyDown,g=>{const y=f.current!=="";!(g.ctrlKey||g.altKey||g.metaKey)&&g.key.length===1&&p(g.key),!(y&&g.key===" ")&&wC.includes(g.key)&&(m(),g.preventDefault())})})})});Up.displayName=zp;var Hp="SelectValue",Wp=v.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,children:s,placeholder:i="",...a}=e,l=$n(Hp,n),{onValueNodeHasChildrenChange:c}=l,d=s!==void 0,f=Be(t,l.onValueNodeChange);return Ct(()=>{c(d)},[c,d]),u.jsx(Ne.span,{...a,ref:f,style:{pointerEvents:"none"},children:dh(l.value)?u.jsx(u.Fragment,{children:i}):s})});Wp.displayName=Hp;var EC="SelectIcon",Vp=v.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...o}=e;return u.jsx(Ne.span,{"aria-hidden":!0,...o,ref:t,children:r||"▼"})});Vp.displayName=EC;var AC="SelectPortal",Kp=e=>u.jsx(Ko,{asChild:!0,...e});Kp.displayName=AC;var or="SelectContent",qp=v.forwardRef((e,t)=>{const n=$n(or,e.__scopeSelect),[r,o]=v.useState();if(Ct(()=>{o(new DocumentFragment)},[]),!n.open){const s=r;return s?ho.createPortal(u.jsx(Gp,{scope:e.__scopeSelect,children:u.jsx(Us.Slot,{scope:e.__scopeSelect,children:u.jsx("div",{children:e.children})})}),s):null}return u.jsx(Yp,{...e,ref:t})});qp.displayName=or;var cn=10,[Gp,Fn]=Ir(or),NC="SelectContentImpl",_C=Hn.createSlot("SelectContent.RemoveScroll"),Yp=v.forwardRef((e,t)=>{const{__scopeSelect:n,position:r="item-aligned",onCloseAutoFocus:o,onEscapeKeyDown:s,onPointerDownOutside:i,side:a,sideOffset:l,align:c,alignOffset:d,arrowPadding:f,collisionBoundary:p,collisionPadding:h,sticky:m,hideWhenDetached:g,avoidCollisions:y,...x}=e,b=$n(or,n),[C,k]=v.useState(null),[S,T]=v.useState(null),I=Be(t,J=>k(J)),[A,_]=v.useState(null),[L,R]=v.useState(null),O=Hs(n),[F,N]=v.useState(!1),B=v.useRef(!1);v.useEffect(()=>{if(C)return $i(C)},[C]),vi();const j=v.useCallback(J=>{const[$,...q]=O().map(ie=>ie.ref.current),[Z]=q.slice(-1),ue=document.activeElement;for(const ie of J)if(ie===ue||(ie==null||ie.scrollIntoView({block:"nearest"}),ie===$&&S&&(S.scrollTop=0),ie===Z&&S&&(S.scrollTop=S.scrollHeight),ie==null||ie.focus(),document.activeElement!==ue))return},[O,S]),K=v.useCallback(()=>j([A,C]),[j,A,C]);v.useEffect(()=>{F&&K()},[F,K]);const{onOpenChange:z,triggerPointerDownPosRef:M}=b;v.useEffect(()=>{if(C){let J={x:0,y:0};const $=Z=>{var ue,ie;J={x:Math.abs(Math.round(Z.pageX)-(((ue=M.current)==null?void 0:ue.x)??0)),y:Math.abs(Math.round(Z.pageY)-(((ie=M.current)==null?void 0:ie.y)??0))}},q=Z=>{J.x<=10&&J.y<=10?Z.preventDefault():C.contains(Z.target)||z(!1),document.removeEventListener("pointermove",$),M.current=null};return M.current!==null&&(document.addEventListener("pointermove",$),document.addEventListener("pointerup",q,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",$),document.removeEventListener("pointerup",q,{capture:!0})}}},[C,z,M]),v.useEffect(()=>{const J=()=>z(!1);return window.addEventListener("blur",J),window.addEventListener("resize",J),()=>{window.removeEventListener("blur",J),window.removeEventListener("resize",J)}},[z]);const[G,X]=fh(J=>{const $=O().filter(ue=>!ue.disabled),q=$.find(ue=>ue.ref.current===document.activeElement),Z=ph($,J,q);Z&&setTimeout(()=>Z.ref.current.focus())}),se=v.useCallback((J,$,q)=>{const Z=!B.current&&!q;(b.value!==void 0&&b.value===$||Z)&&(_(J),Z&&(B.current=!0))},[b.value]),be=v.useCallback(()=>C==null?void 0:C.focus(),[C]),Ie=v.useCallback((J,$,q)=>{const Z=!B.current&&!q;(b.value!==void 0&&b.value===$||Z)&&R(J)},[b.value]),Y=r==="popper"?La:Xp,U=Y===La?{side:a,sideOffset:l,align:c,alignOffset:d,arrowPadding:f,collisionBoundary:p,collisionPadding:h,sticky:m,hideWhenDetached:g,avoidCollisions:y}:{};return u.jsx(Gp,{scope:n,content:C,viewport:S,onViewportChange:T,itemRefCallback:se,selectedItem:A,onItemLeave:be,itemTextRefCallback:Ie,focusSelectedItem:K,selectedItemText:L,position:r,isPositioned:F,searchRef:G,children:u.jsx(ts,{as:_C,allowPinchZoom:!0,children:u.jsx(Po,{asChild:!0,trapped:b.open,onMountAutoFocus:J=>{J.preventDefault()},onUnmountAutoFocus:fe(o,J=>{var $;($=b.trigger)==null||$.focus({preventScroll:!0}),J.preventDefault()}),children:u.jsx(Ro,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:J=>J.preventDefault(),onDismiss:()=>b.onOpenChange(!1),children:u.jsx(Y,{role:"listbox",id:b.contentId,"data-state":b.open?"open":"closed",dir:b.dir,onContextMenu:J=>J.preventDefault(),...x,...U,onPlaced:()=>N(!0),ref:I,style:{display:"flex",flexDirection:"column",outline:"none",...x.style},onKeyDown:fe(x.onKeyDown,J=>{const $=J.ctrlKey||J.altKey||J.metaKey;if(J.key==="Tab"&&J.preventDefault(),!$&&J.key.length===1&&X(J.key),["ArrowUp","ArrowDown","Home","End"].includes(J.key)){let Z=O().filter(ue=>!ue.disabled).map(ue=>ue.ref.current);if(["ArrowUp","End"].includes(J.key)&&(Z=Z.slice().reverse()),["ArrowUp","ArrowDown"].includes(J.key)){const ue=J.target,ie=Z.indexOf(ue);Z=Z.slice(ie+1)}setTimeout(()=>j(Z)),J.preventDefault()}})})})})})})});Yp.displayName=NC;var jC="SelectItemAlignedPosition",Xp=v.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...o}=e,s=$n(or,n),i=Fn(or,n),[a,l]=v.useState(null),[c,d]=v.useState(null),f=Be(t,I=>d(I)),p=Hs(n),h=v.useRef(!1),m=v.useRef(!0),{viewport:g,selectedItem:y,selectedItemText:x,focusSelectedItem:b}=i,C=v.useCallback(()=>{if(s.trigger&&s.valueNode&&a&&c&&g&&y&&x){const I=s.trigger.getBoundingClientRect(),A=c.getBoundingClientRect(),_=s.valueNode.getBoundingClientRect(),L=x.getBoundingClientRect();if(s.dir!=="rtl"){const ue=L.left-A.left,ie=_.left-ue,_e=I.left-ie,He=I.width+_e,oe=Math.max(He,A.width),ye=window.innerWidth-cn,Oe=ja(ie,[cn,Math.max(cn,ye-oe)]);a.style.minWidth=He+"px",a.style.left=Oe+"px"}else{const ue=A.right-L.right,ie=window.innerWidth-_.right-ue,_e=window.innerWidth-I.right-ie,He=I.width+_e,oe=Math.max(He,A.width),ye=window.innerWidth-cn,Oe=ja(ie,[cn,Math.max(cn,ye-oe)]);a.style.minWidth=He+"px",a.style.right=Oe+"px"}const R=p(),O=window.innerHeight-cn*2,F=g.scrollHeight,N=window.getComputedStyle(c),B=parseInt(N.borderTopWidth,10),j=parseInt(N.paddingTop,10),K=parseInt(N.borderBottomWidth,10),z=parseInt(N.paddingBottom,10),M=B+j+F+z+K,G=Math.min(y.offsetHeight*5,M),X=window.getComputedStyle(g),se=parseInt(X.paddingTop,10),be=parseInt(X.paddingBottom,10),Ie=I.top+I.height/2-cn,Y=O-Ie,U=y.offsetHeight/2,J=y.offsetTop+U,$=B+j+J,q=M-$;if($<=Ie){const ue=R.length>0&&y===R[R.length-1].ref.current;a.style.bottom="0px";const ie=c.clientHeight-g.offsetTop-g.offsetHeight,_e=Math.max(Y,U+(ue?be:0)+ie+K),He=$+_e;a.style.height=He+"px"}else{const ue=R.length>0&&y===R[0].ref.current;a.style.top="0px";const _e=Math.max(Ie,B+g.offsetTop+(ue?se:0)+U)+q;a.style.height=_e+"px",g.scrollTop=$-Ie+g.offsetTop}a.style.margin=`${cn}px 0`,a.style.minHeight=G+"px",a.style.maxHeight=O+"px",r==null||r(),requestAnimationFrame(()=>h.current=!0)}},[p,s.trigger,s.valueNode,a,c,g,y,x,s.dir,r]);Ct(()=>C(),[C]);const[k,S]=v.useState();Ct(()=>{c&&S(window.getComputedStyle(c).zIndex)},[c]);const T=v.useCallback(I=>{I&&m.current===!0&&(C(),b==null||b(),m.current=!1)},[C,b]);return u.jsx(RC,{scope:n,contentWrapper:a,shouldExpandOnScrollRef:h,onScrollButtonChange:T,children:u.jsx("div",{ref:l,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:k},children:u.jsx(Ne.div,{...o,ref:f,style:{boxSizing:"border-box",maxHeight:"100%",...o.style}})})})});Xp.displayName=jC;var MC="SelectPopperPosition",La=v.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=cn,...s}=e,i=Ws(n);return u.jsx(ru,{...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)"}})});La.displayName=MC;var[RC,$a]=Ir(or,{}),Fa="SelectViewport",Jp=v.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...o}=e,s=Fn(Fa,n),i=$a(Fa,n),a=Be(t,s.onViewportChange),l=v.useRef(0);return u.jsxs(u.Fragment,{children:[u.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}),u.jsx(Us.Slot,{scope:n,children:u.jsx(Ne.div,{"data-radix-select-viewport":"",role:"presentation",...o,ref:a,style:{position:"relative",flex:1,overflow:"hidden auto",...o.style},onScroll:fe(o.onScroll,c=>{const d=c.currentTarget,{contentWrapper:f,shouldExpandOnScrollRef:p}=i;if(p!=null&&p.current&&f){const h=Math.abs(l.current-d.scrollTop);if(h>0){const m=window.innerHeight-cn*2,g=parseFloat(f.style.minHeight),y=parseFloat(f.style.height),x=Math.max(g,y);if(x<m){const b=x+h,C=Math.min(m,b),k=b-C;f.style.height=C+"px",f.style.bottom==="0px"&&(d.scrollTop=k>0?k:0,f.style.justifyContent="flex-end")}}}l.current=d.scrollTop})})})]})});Jp.displayName=Fa;var Zp="SelectGroup",[PC,OC]=Ir(Zp),DC=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Cn();return u.jsx(PC,{scope:n,id:o,children:u.jsx(Ne.div,{role:"group","aria-labelledby":o,...r,ref:t})})});DC.displayName=Zp;var Qp="SelectLabel",eh=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=OC(Qp,n);return u.jsx(Ne.div,{id:o.id,...r,ref:t})});eh.displayName=Qp;var Vs="SelectItem",[LC,th]=Ir(Vs),nh=v.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:s,...i}=e,a=$n(Vs,n),l=Fn(Vs,n),c=a.value===r,[d,f]=v.useState(s??""),[p,h]=v.useState(!1),m=Be(t,b=>{var C;return(C=l.itemRefCallback)==null?void 0:C.call(l,b,r,o)}),g=Cn(),y=v.useRef("touch"),x=()=>{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 u.jsx(LC,{scope:n,value:r,disabled:o,textId:g,isSelected:c,onItemTextChange:v.useCallback(b=>{f(C=>C||((b==null?void 0:b.textContent)??"").trim())},[]),children:u.jsx(Us.ItemSlot,{scope:n,value:r,disabled:o,textValue:d,children:u.jsx(Ne.div,{role:"option","aria-labelledby":g,"data-highlighted":p?"":void 0,"aria-selected":c&&p,"data-state":c?"checked":"unchecked","aria-disabled":o||void 0,"data-disabled":o?"":void 0,tabIndex:o?void 0:-1,...i,ref:m,onFocus:fe(i.onFocus,()=>h(!0)),onBlur:fe(i.onBlur,()=>h(!1)),onClick:fe(i.onClick,()=>{y.current!=="mouse"&&x()}),onPointerUp:fe(i.onPointerUp,()=>{y.current==="mouse"&&x()}),onPointerDown:fe(i.onPointerDown,b=>{y.current=b.pointerType}),onPointerMove:fe(i.onPointerMove,b=>{var C;y.current=b.pointerType,o?(C=l.onItemLeave)==null||C.call(l):y.current==="mouse"&&b.currentTarget.focus({preventScroll:!0})}),onPointerLeave:fe(i.onPointerLeave,b=>{var C;b.currentTarget===document.activeElement&&((C=l.onItemLeave)==null||C.call(l))}),onKeyDown:fe(i.onKeyDown,b=>{var k;((k=l.searchRef)==null?void 0:k.current)!==""&&b.key===" "||(SC.includes(b.key)&&x(),b.key===" "&&b.preventDefault())})})})})});nh.displayName=Vs;var uo="SelectItemText",rh=v.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,...s}=e,i=$n(uo,n),a=Fn(uo,n),l=th(uo,n),c=IC(uo,n),[d,f]=v.useState(null),p=Be(t,x=>f(x),l.onItemTextChange,x=>{var b;return(b=a.itemTextRefCallback)==null?void 0:b.call(a,x,l.value,l.disabled)}),h=d==null?void 0:d.textContent,m=v.useMemo(()=>u.jsx("option",{value:l.value,disabled:l.disabled,children:h},l.value),[l.disabled,l.value,h]),{onNativeOptionAdd:g,onNativeOptionRemove:y}=c;return Ct(()=>(g(m),()=>y(m)),[g,y,m]),u.jsxs(u.Fragment,{children:[u.jsx(Ne.span,{id:l.textId,...s,ref:p}),l.isSelected&&i.valueNode&&!i.valueNodeHasChildren?ho.createPortal(s.children,i.valueNode):null]})});rh.displayName=uo;var oh="SelectItemIndicator",sh=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return th(oh,n).isSelected?u.jsx(Ne.span,{"aria-hidden":!0,...r,ref:t}):null});sh.displayName=oh;var Ba="SelectScrollUpButton",ih=v.forwardRef((e,t)=>{const n=Fn(Ba,e.__scopeSelect),r=$a(Ba,e.__scopeSelect),[o,s]=v.useState(!1),i=Be(t,r.onScrollButtonChange);return Ct(()=>{if(n.viewport&&n.isPositioned){let a=function(){const c=l.scrollTop>0;s(c)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?u.jsx(lh,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop-l.offsetHeight)}}):null});ih.displayName=Ba;var za="SelectScrollDownButton",ah=v.forwardRef((e,t)=>{const n=Fn(za,e.__scopeSelect),r=$a(za,e.__scopeSelect),[o,s]=v.useState(!1),i=Be(t,r.onScrollButtonChange);return Ct(()=>{if(n.viewport&&n.isPositioned){let a=function(){const c=l.scrollHeight-l.clientHeight,d=Math.ceil(l.scrollTop)<c;s(d)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?u.jsx(lh,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop+l.offsetHeight)}}):null});ah.displayName=za;var lh=v.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...o}=e,s=Fn("SelectScrollButton",n),i=v.useRef(null),a=Hs(n),l=v.useCallback(()=>{i.current!==null&&(window.clearInterval(i.current),i.current=null)},[]);return v.useEffect(()=>()=>l(),[l]),Ct(()=>{var d;const c=a().find(f=>f.ref.current===document.activeElement);(d=c==null?void 0:c.ref.current)==null||d.scrollIntoView({block:"nearest"})},[a]),u.jsx(Ne.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 c;(c=s.onItemLeave)==null||c.call(s),i.current===null&&(i.current=window.setInterval(r,50))}),onPointerLeave:fe(o.onPointerLeave,()=>{l()})})}),$C="SelectSeparator",ch=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return u.jsx(Ne.div,{"aria-hidden":!0,...r,ref:t})});ch.displayName=$C;var Ua="SelectArrow",FC=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Ws(n),s=$n(Ua,n),i=Fn(Ua,n);return s.open&&i.position==="popper"?u.jsx(ou,{...o,...r,ref:t}):null});FC.displayName=Ua;var BC="SelectBubbleInput",uh=v.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const o=v.useRef(null),s=Be(r,o),i=$p(t);return v.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]),u.jsx(Ne.select,{...n,style:{...Fp,...n.style},ref:s,defaultValue:t})});uh.displayName=BC;function dh(e){return e===""||e===void 0}function fh(e){const t=Tt(e),n=v.useRef(""),r=v.useRef(0),o=v.useCallback(i=>{const a=n.current+i;t(a),function l(c){n.current=c,window.clearTimeout(r.current),c!==""&&(r.current=window.setTimeout(()=>l(""),1e3))}(a)},[t]),s=v.useCallback(()=>{n.current="",window.clearTimeout(r.current)},[]);return v.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,o,s]}function ph(e,t,n){const o=t.length>1&&Array.from(t).every(c=>c===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let i=zC(e,Math.max(s,0));o.length===1&&(i=i.filter(c=>c!==n));const l=i.find(c=>c.textValue.toLowerCase().startsWith(o.toLowerCase()));return l!==n?l:void 0}function zC(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var UC=Bp,hh=Up,HC=Wp,WC=Vp,VC=Kp,mh=qp,KC=Jp,gh=eh,xh=nh,qC=rh,GC=sh,yh=ih,vh=ah,bh=ch;const wh=UC,Sh=HC,Ha=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(hh,{ref:r,className:te("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,u.jsx(WC,{asChild:!0,children:u.jsx(le.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));Ha.displayName=hh.displayName;const Ch=v.forwardRef(({className:e,...t},n)=>u.jsx(yh,{ref:n,className:te("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(le.ChevronUp,{className:"h-4 w-4"})}));Ch.displayName=yh.displayName;const Th=v.forwardRef(({className:e,...t},n)=>u.jsx(vh,{ref:n,className:te("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(le.ChevronDown,{className:"h-4 w-4"})}));Th.displayName=vh.displayName;const Wa=v.forwardRef(({className:e,children:t,position:n="popper",...r},o)=>u.jsx(VC,{children:u.jsxs(mh,{ref:o,className:te("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:[u.jsx(Ch,{}),u.jsx(KC,{className:te("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),u.jsx(Th,{})]})}));Wa.displayName=mh.displayName;const YC=v.forwardRef(({className:e,...t},n)=>u.jsx(gh,{ref:n,className:te("py-1.5 pl-8 pr-2 text-sm font-semibold",e),...t}));YC.displayName=gh.displayName;const sr=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(xh,{ref:r,className:te("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:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(GC,{children:u.jsx(le.Check,{className:"h-4 w-4"})})}),u.jsx(qC,{children:t})]}));sr.displayName=xh.displayName;const XC=v.forwardRef(({className:e,...t},n)=>u.jsx(bh,{ref:n,className:te("-mx-1 my-1 h-px bg-muted",e),...t}));XC.displayName=bh.displayName;var JC="Separator",kh="horizontal",ZC=["horizontal","vertical"],Ih=v.forwardRef((e,t)=>{const{decorative:n,orientation:r=kh,...o}=e,s=QC(r)?r:kh,a=n?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return u.jsx(Ne.div,{"data-orientation":s,...a,...o,ref:t})});Ih.displayName=JC;function QC(e){return ZC.includes(e)}var Eh=Ih;const Ah=v.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},o)=>u.jsx(Eh,{ref:o,decorative:n,orientation:t,className:te("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));Ah.displayName=Eh.displayName;const eT=Bf,tT=dS,nT=zf,Nh=v.forwardRef(({className:e,...t},n)=>u.jsx(Is,{className:te("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}));Nh.displayName=Is.displayName;const rT=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"}}),_h=v.forwardRef(({side:e="right",className:t,children:n,...r},o)=>u.jsxs(nT,{children:[u.jsx(Nh,{}),u.jsxs(Es,{ref:o,className:te(rT({side:e}),t),...r,children:[n,u.jsxs(Uf,{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:[u.jsx(le.X,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));_h.displayName=Es.displayName;const jh=({className:e,...t})=>u.jsx("div",{className:te("flex flex-col space-y-2 text-center sm:text-left",e),...t});jh.displayName="SheetHeader";const Mh=v.forwardRef(({className:e,...t},n)=>u.jsx(tr,{ref:n,className:te("text-lg font-semibold text-foreground",e),...t}));Mh.displayName=tr.displayName;const Rh=v.forwardRef(({className:e,...t},n)=>u.jsx(As,{ref:n,className:te("text-sm text-muted-foreground",e),...t}));Rh.displayName=As.displayName;var Ks="Switch",[oT,WT]=Sn(Ks),[sT,iT]=oT(Ks),Ph=v.forwardRef((e,t)=>{const{__scopeSwitch:n,name:r,checked:o,defaultChecked:s,required:i,disabled:a,value:l="on",onCheckedChange:c,form:d,...f}=e,[p,h]=v.useState(null),m=Be(t,C=>h(C)),g=v.useRef(!1),y=p?d||!!p.closest("form"):!0,[x,b]=fr({prop:o,defaultProp:s??!1,onChange:c,caller:Ks});return u.jsxs(sT,{scope:n,checked:x,disabled:a,children:[u.jsx(Ne.button,{type:"button",role:"switch","aria-checked":x,"aria-required":i,"data-state":$h(x),"data-disabled":a?"":void 0,disabled:a,value:l,...f,ref:m,onClick:fe(e.onClick,C=>{b(k=>!k),y&&(g.current=C.isPropagationStopped(),g.current||C.stopPropagation())})}),y&&u.jsx(Lh,{control:p,bubbles:!g.current,name:r,value:l,checked:x,required:i,disabled:a,form:d,style:{transform:"translateX(-100%)"}})]})});Ph.displayName=Ks;var Oh="SwitchThumb",Dh=v.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,o=iT(Oh,n);return u.jsx(Ne.span,{"data-state":$h(o.checked),"data-disabled":o.disabled?"":void 0,...r,ref:t})});Dh.displayName=Oh;var aT="SwitchBubbleInput",Lh=v.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...o},s)=>{const i=v.useRef(null),a=Be(i,s),l=$p(n),c=Vc(t);return v.useEffect(()=>{const d=i.current;if(!d)return;const f=window.HTMLInputElement.prototype,h=Object.getOwnPropertyDescriptor(f,"checked").set;if(l!==n&&h){const m=new Event("click",{bubbles:r});h.call(d,n),d.dispatchEvent(m)}},[l,n,r]),u.jsx("input",{type:"checkbox","aria-hidden":!0,defaultChecked:n,...o,tabIndex:-1,ref:a,style:{...o.style,...c,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});Lh.displayName=aT;function $h(e){return e?"checked":"unchecked"}var Fh=Ph,lT=Dh;const Bn=v.forwardRef(({className:e,...t},n)=>u.jsx(Fh,{className:te("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:u.jsx(lT,{className:te("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")})}));Bn.displayName=Fh.displayName;const cT={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 uT({settings:e,onSettingsChange:t,className:n=""}){const[r,o]=w.useState(!1),[s,i]=w.useState(!1),[a,l]=w.useState(e),[c,d]=w.useState(!1),{toast:f}=Ea();w.useEffect(()=>{const y=JSON.stringify(a)!==JSON.stringify(e);d(y)},[a,e]),w.useEffect(()=>{l(e)},[e]);const p=()=>{t(a),d(!1),f({title:"Settings saved",description:"Your chat configuration has been updated successfully."})},h=()=>{l(cT),d(!0),f({title:"Settings reset",description:"Configuration has been reset to defaults."})},m=()=>{l(e),d(!1),o(!1)},g=async()=>{try{const x=await(await fetch(`${a.api.baseUrl}/health`)).json();f({title:"Connection successful",description:`API is ${x.status||"healthy"}`})}catch{f({title:"Connection failed",description:"Unable to connect to the API endpoint.",variant:"destructive"})}};return u.jsxs(eT,{open:r,onOpenChange:o,children:[u.jsx(tT,{asChild:!0,children:u.jsxs(Ze,{variant:"outline",size:"sm",className:n,children:[u.jsx(le.Settings,{className:"h-4 w-4 mr-2"}),"Settings",c&&u.jsx(yf,{variant:"destructive",className:"ml-2 h-4 w-4 p-0"})]})}),u.jsxs(_h,{className:"w-[500px] sm:w-[600px] overflow-y-auto",children:[u.jsxs(jh,{children:[u.jsx(Mh,{children:"Chat Settings"}),u.jsx(Rh,{children:"Configure your chat interface, API connection, and behavior preferences."})]}),u.jsxs("div",{className:"space-y-6 py-6",children:[u.jsxs(io,{children:[u.jsx(ao,{className:"pb-3",children:u.jsxs(lo,{className:"text-lg flex items-center gap-2",children:[u.jsx(le.Server,{className:"h-5 w-5"}),"API Configuration"]})}),u.jsxs(co,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(en,{htmlFor:"api-url",children:"API Base URL"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(Ls,{id:"api-url",value:a.api.baseUrl,onChange:y=>l(x=>({...x,api:{...x.api,baseUrl:y.target.value}})),placeholder:"http://localhost:8000/api"}),u.jsx(Ze,{variant:"outline",onClick:g,children:"Test"})]})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(en,{htmlFor:"enable-auth",children:"Enable Authentication"}),u.jsx(Bn,{id:"enable-auth",checked:a.api.enableAuth,onCheckedChange:y=>l(x=>({...x,api:{...x.api,enableAuth:y}}))})]}),a.api.enableAuth&&u.jsxs("div",{className:"space-y-2",children:[u.jsx(en,{htmlFor:"auth-token",children:"Authentication Token"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(Ls,{id:"auth-token",type:s?"text":"password",value:a.api.authToken,onChange:y=>l(x=>({...x,api:{...x.api,authToken:y.target.value}})),placeholder:"Enter your Bearer token"}),u.jsx(Ze,{variant:"outline",size:"icon",onClick:()=>i(!s),children:s?u.jsx(le.EyeOff,{className:"h-4 w-4"}):u.jsx(le.Eye,{className:"h-4 w-4"})})]})]})]})]}),u.jsxs(io,{children:[u.jsx(ao,{className:"pb-3",children:u.jsxs(lo,{className:"text-lg flex items-center gap-2",children:[u.jsx(le.Layout,{className:"h-5 w-5"}),"Interface Settings"]})}),u.jsxs(co,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(en,{htmlFor:"layout",children:"Layout Style"}),u.jsxs(wh,{value:a.ui.layout,onValueChange:y=>l(x=>({...x,ui:{...x.ui,layout:y}})),children:[u.jsx(Ha,{children:u.jsx(Sh,{})}),u.jsxs(Wa,{children:[u.jsx(sr,{value:"sidebar",children:"Sidebar Layout"}),u.jsx(sr,{value:"fullscreen",children:"Fullscreen"}),u.jsx(sr,{value:"tabs",children:"Tabbed Interface"})]})]})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx(en,{htmlFor:"theme",children:"Theme"}),u.jsxs(wh,{value:a.ui.theme,onValueChange:y=>l(x=>({...x,ui:{...x.ui,theme:y}})),children:[u.jsx(Ha,{children:u.jsx(Sh,{})}),u.jsxs(Wa,{children:[u.jsx(sr,{value:"light",children:"Light"}),u.jsx(sr,{value:"dark",children:"Dark"}),u.jsx(sr,{value:"system",children:"System"})]})]})]}),u.jsx(Ah,{}),u.jsxs("div",{className:"space-y-3",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(en,{htmlFor:"show-timestamps",children:"Show Timestamps"}),u.jsx(Bn,{id:"show-timestamps",checked:a.ui.showTimestamps,onCheckedChange:y=>l(x=>({...x,ui:{...x.ui,showTimestamps:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(en,{htmlFor:"show-agent-names",children:"Show Agent Names"}),u.jsx(Bn,{id:"show-agent-names",checked:a.ui.showAgentNames,onCheckedChange:y=>l(x=>({...x,ui:{...x.ui,showAgentNames:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(en,{htmlFor:"compact-messages",children:"Compact Messages"}),u.jsx(Bn,{id:"compact-messages",checked:a.ui.compactMessages,onCheckedChange:y=>l(x=>({...x,ui:{...x.ui,compactMessages:y}}))})]})]})]})]}),u.jsxs(io,{children:[u.jsx(ao,{className:"pb-3",children:u.jsxs(lo,{className:"text-lg flex items-center gap-2",children:[u.jsx(le.MessageCircle,{className:"h-5 w-5"}),"Behavior Settings"]})}),u.jsxs(co,{className:"space-y-4",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(en,{htmlFor:"auto-save",children:"Auto-save Conversations"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Automatically save messages to threads"})]}),u.jsx(Bn,{id:"auto-save",checked:a.behavior.autoSave,onCheckedChange:y=>l(x=>({...x,behavior:{...x.behavior,autoSave:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(en,{htmlFor:"enable-streaming",children:"Enable Streaming"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Stream responses in real-time"})]}),u.jsx(Bn,{id:"enable-streaming",checked:a.behavior.enableStreaming,onCheckedChange:y=>l(x=>({...x,behavior:{...x.behavior,enableStreaming:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(en,{htmlFor:"typing-indicator",children:"Typing Indicator"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Show typing indicator during responses"})]}),u.jsx(Bn,{id:"typing-indicator",checked:a.behavior.showTypingIndicator,onCheckedChange:y=>l(x=>({...x,behavior:{...x.behavior,showTypingIndicator:y}}))})]})]})]})]}),u.jsxs("div",{className:"flex items-center justify-between pt-6 border-t",children:[u.jsxs(Ze,{variant:"outline",onClick:h,children:[u.jsx(le.RotateCcw,{className:"h-4 w-4 mr-2"}),"Reset"]}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(Ze,{variant:"outline",onClick:m,children:"Cancel"}),u.jsxs(Ze,{onClick:p,disabled:!c,children:[u.jsx(le.Save,{className:"h-4 w-4 mr-2"}),"Save Changes"]})]})]})]})]})}function dT({layout:e="sidebar",layoutSize:t="desktop",showThreads:n=!0,className:r="",customStyles:o={},...s}){const i=c=>{const d="h-full";switch(c){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=c=>({"--chat-sidebar-width":c==="phone"?"100%":c==="tablet"?"280px":c==="half-screen"?"240px":"320px","--chat-message-max-width":c==="phone"?"95%":c==="tablet"?"90%":c==="half-screen"?"85%":"80%","--chat-input-height":c==="phone"?"120px":"100px"}),l=w.useCallback(c=>{var d;(d=s.onThreadChange)==null||d.call(s,c)},[s]);return e==="fullscreen"?u.jsx(jo,{...s,onThreadChange:l,children:u.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:u.jsx(Ds,{className:"flex-1",onError:s.onError,enableFileUpload:!0})})}):e==="tabs"?u.jsx(jo,{...s,onThreadChange:l,children:u.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:u.jsxs("div",{className:"flex-1 flex min-h-0 overflow-hidden",children:[n&&u.jsx("div",{className:`w-80 border-r flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:u.jsx(Da,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),u.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:u.jsx(Ds,{onError:s.onError,enableFileUpload:!0})})]})})}):u.jsx(jo,{...s,onThreadChange:l,children:u.jsxs("div",{className:`${i(t)} flex overflow-hidden ${r} ${o.container||""}`,style:a(t),children:[n&&u.jsx("div",{className:`w-80 border-r bg-gray-50 flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:u.jsx(Da,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),u.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:u.jsx(Ds,{onError:s.onError,enableFileUpload:!0})})]})})}Ce.ChatApi=Fl,Ce.ChatInput=cc,Ce.ChatInterface=Ds,Ce.ChatProviders=jo,Ce.ChatSettings=uT,Ce.MarkdownContent=so,Ce.MessageComponent=Os,Ce.MessageList=_a,Ce.ThreadManager=Da,Ce.TimelineColumn=dC,Ce.applySettings=gC,Ce.buildMessagePreviewMap=Ug,Ce.chatApiClient=An,Ce.default=dT,Ce.del=$l,Ce.get=qt,Ce.getChatToken=Ol,Ce.getCurrentSettings=mC,Ce.getDefaultApiConfig=Rp,Ce.getDefaultChatSettings=Pp,Ce.onChatTokenChanged=Dl,Ce.post=li,Ce.put=Ll,Ce.setChatToken=Io,Ce.useApi=ci,Ce.useChatStream=Gl,Ce.useMessagesReducer=Yl,Ce.useStream=ac,Ce.useThreadState=_o,Ce.useThreads=No,Object.defineProperties(Ce,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
134
|
+
`}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=ep(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=ep(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 sp{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 ip{constructor(){this.seen={}}serialize(t){return t.toLowerCase().trim().replace(/<[!\/a-z].*?>/ig,"").replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g,"").replace(/\s/g,"-")}getNextSafeSlug(t,n){let r=t,o=0;if(this.seen.hasOwnProperty(r)){o=this.seen[t];do o++,r=t+"-"+o;while(this.seen.hasOwnProperty(r))}return n||(this.seen[t]=o,this.seen[r]=0),r}slug(t,n={}){const r=this.serialize(t);return this.getNextSafeSlug(r,n.dryrun)}}class $n{constructor(t){this.options=t||rr,this.options.renderer=this.options.renderer||new Aa,this.renderer=this.options.renderer,this.renderer.options=this.options,this.textRenderer=new sp,this.slugger=new ip}static parse(t,n){return new $n(n).parse(t)}static parseInline(t,n){return new $n(n).parseInline(t)}parse(t,n=!0){let r="",o,s,i,a,l,c,d,f,h,p,m,g,y,x,b,S,k,C,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,Qf(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(c=p.rows[s],d="",l=c.length,i=0;i<l;i++)d+=this.renderer.tablecell(this.parseInline(c[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(m=p.ordered,g=p.start,y=p.loose,a=p.items.length,h="",s=0;s<a;s++)b=p.items[s],S=b.checked,k=b.task,x="",b.task&&(C=this.renderer.checkbox(S),y?b.tokens.length>0&&b.tokens[0].type==="paragraph"?(b.tokens[0].text=C+" "+b.tokens[0].text,b.tokens[0].tokens&&b.tokens[0].tokens.length>0&&b.tokens[0].tokens[0].type==="text"&&(b.tokens[0].tokens[0].text=C+" "+b.tokens[0].tokens[0].text)):b.tokens.unshift({type:"text",text:C}):x+=C),x+=this.parse(b.tokens,y),h+=this.renderer.listitem(x,k,S);r+=this.renderer.list(h,m,g);continue}case"html":{r+=this.renderer.html(p.text);continue}case"paragraph":{r+=this.renderer.paragraph(this.parseInline(p.tokens));continue}case"text":{for(h=p.tokens?this.parseInline(p.tokens):p.text;o+1<I&&t[o+1].type==="text";)p=t[++o],h+=`
|
|
135
|
+
`+(p.tokens?this.parseInline(p.tokens):p.text);r+=n?this.renderer.paragraph(h):h;continue}default:{const A='Token with "'+p.type+'" type was not found.';if(this.options.silent){console.error(A);return}else throw new Error(A)}}}return r}parseInline(t,n){n=n||this.renderer;let r="",o,s,i;const a=t.length;for(o=0;o<a;o++){if(s=t[o],this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[s.type]&&(i=this.options.extensions.renderers[s.type].call({parser:this},s),i!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(s.type))){r+=i||"";continue}switch(s.type){case"escape":{r+=n.text(s.text);break}case"html":{r+=n.html(s.text);break}case"link":{r+=n.link(s.href,s.title,this.parseInline(s.tokens,n));break}case"image":{r+=n.image(s.href,s.title,s.text);break}case"strong":{r+=n.strong(this.parseInline(s.tokens,n));break}case"em":{r+=n.em(this.parseInline(s.tokens,n));break}case"codespan":{r+=n.codespan(s.text);break}case"br":{r+=n.br();break}case"del":{r+=n.del(this.parseInline(s.tokens,n));break}case"text":{r+=n.text(s.text);break}default:{const l='Token with "'+s.type+'" type was not found.';if(this.options.silent){console.error(l);return}else throw new Error(l)}}}return r}}class Os{constructor(t){this.options=t||rr}preprocess(t){return t}postprocess(t){return t}}zh(Os,"passThroughHooks",new Set(["preprocess","postprocess"]));function KS(e,t,n){return r=>{if(r.message+=`
|
|
136
|
+
Please report this to https://github.com/markedjs/marked.`,e){const o="<p>An error occurred:</p><pre>"+_t(r.message+"",!0)+"</pre>";if(t)return Promise.resolve(o);if(n){n(null,o);return}return o}if(t)return Promise.reject(r);if(n){n(r);return}throw r}}function ap(e,t){return(n,r,o)=>{typeof r=="function"&&(o=r,r=null);const s={...r};r={...ge.defaults,...s};const i=KS(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(HS(r),r.hooks&&(r.hooks.options=r),o){const a=r.highlight;let l;try{r.hooks&&(n=r.hooks.preprocess(n)),l=e(n,r)}catch(f){return i(f)}const c=function(f){let h;if(!f)try{r.walkTokens&&ge.walkTokens(l,r.walkTokens),h=t(l,r),r.hooks&&(h=r.hooks.postprocess(h))}catch(p){f=p}return r.highlight=a,f?i(f):o(null,h)};if(!a||a.length<3||(delete r.highlight,!l.length))return c();let d=0;ge.walkTokens(l,function(f){f.type==="code"&&(d++,setTimeout(()=>{a(f.text,f.lang,function(h,p){if(h)return c(h);p!=null&&p!==f.text&&(f.text=p,f.escaped=!0),d--,d===0&&c()})},0))}),d===0&&c();return}if(r.async)return Promise.resolve(r.hooks?r.hooks.preprocess(n):n).then(a=>e(a,r)).then(a=>r.walkTokens?Promise.all(ge.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&&ge.walkTokens(a,r.walkTokens);let l=t(a,r);return r.hooks&&(l=r.hooks.postprocess(l)),l}catch(a){return i(a)}}}function ge(e,t,n){return ap(Ln.lex,$n.parse)(e,t,n)}ge.options=ge.setOptions=function(e){return ge.defaults={...ge.defaults,...e},_S(ge.defaults),ge},ge.getDefaults=Yf,ge.defaults=rr,ge.use=function(...e){const t=ge.defaults.extensions||{renderers:{},childTokens:{}};e.forEach(n=>{const r={...n};if(r.async=ge.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=ge.defaults.renderer||new Aa;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=ge.defaults.tokenizer||new Ea;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=ge.defaults.hooks||new Os;for(const s in n.hooks){const i=o[s];Os.passThroughHooks.has(s)?o[s]=a=>{if(ge.defaults.async)return Promise.resolve(n.hooks[s].call(o,a)).then(c=>i.call(o,c));const l=n.hooks[s].call(o,a);return i.call(o,l)}:o[s]=(...a)=>{let l=n.hooks[s].apply(o,a);return l===!1&&(l=i.apply(o,a)),l}}r.hooks=o}if(n.walkTokens){const o=ge.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}}ge.setOptions(r)})},ge.walkTokens=function(e,t){let n=[];for(const r of e)switch(n=n.concat(t.call(ge,r)),r.type){case"table":{for(const o of r.header)n=n.concat(ge.walkTokens(o.tokens,t));for(const o of r.rows)for(const s of o)n=n.concat(ge.walkTokens(s.tokens,t));break}case"list":{n=n.concat(ge.walkTokens(r.items,t));break}default:ge.defaults.extensions&&ge.defaults.extensions.childTokens&&ge.defaults.extensions.childTokens[r.type]?ge.defaults.extensions.childTokens[r.type].forEach(function(o){n=n.concat(ge.walkTokens(r[o],t))}):r.tokens&&(n=n.concat(ge.walkTokens(r.tokens,t)))}return n},ge.parseInline=ap(Ln.lexInline,$n.parseInline),ge.Parser=$n,ge.parser=$n.parse,ge.Renderer=Aa,ge.TextRenderer=sp,ge.Lexer=Ln,ge.lexer=Ln.lex,ge.Tokenizer=Ea,ge.Slugger=ip,ge.Hooks=Os,ge.parse=ge,ge.options,ge.setOptions,ge.use,ge.walkTokens,ge.parseInline,$n.parse,Ln.lex;function so({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 typeof ge.parse=="function"?ge.parse(i):ge(i)}return typeof ge.parse=="function"?ge.parse(e):ge(e)}catch(i){return console.error("[MarkdownContent] parse error",i),`<pre class="font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words">Error rendering markdown: ${String(i)}</pre>`}},[e,n]),s=w.useMemo(()=>{const i={color:"currentColor",...r};if(r&&r.color){const a=r.color;return{...i,"--tw-prose-body":a,"--tw-prose-headings":a,"--tw-prose-links":a,"--tw-prose-bold":a,"--tw-prose-counters":a,"--tw-prose-bullets":a,"--tw-prose-hr":a,"--tw-prose-quotes":a,"--tw-prose-quote-borders":a,"--tw-prose-captions":a,"--tw-prose-code":a,"--tw-prose-pre-code":a,"--tw-prose-pre-bg":"inherit","--tw-prose-th-borders":a,"--tw-prose-td-borders":a}}return i},[r]);return u.jsx("div",{className:te("markdown prose prose-sm max-w-none break-words","dark:prose-invert","text-current","prose-headings:text-current prose-p:text-current prose-li:text-current prose-a:text-current prose-strong:text-current","prose-em:text-current prose-blockquote:text-current prose-table:text-current prose-td:text-current prose-th:text-current","prose-pre:font-mono prose-pre:text-xs prose-pre:bg-background/50 prose-pre:border prose-pre:rounded prose-pre:p-3 prose-pre:whitespace-pre prose-pre:overflow-x-auto","prose-code:font-mono prose-code:text-sm prose-code:bg-background/50 prose-code:px-1.5 prose-code:py-0.5 prose-code:rounded prose-code:text-current",t),style:s,dangerouslySetInnerHTML:{__html:o}})}const qS={MODE:"library"};function GS(){var i;const e=typeof globalThis<"u"?globalThis.process:void 0,t=typeof((i=e==null?void 0:e.env)==null?void 0:i.NODE_ENV)=="string"?e.env.NODE_ENV:void 0;if(t)return t==="production";const n=typeof{url:typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Ys&&Ys.tagName.toUpperCase()==="SCRIPT"&&Ys.src||new URL("index.umd.js",document.baseURI).href}<"u"?qS:void 0,r=typeof(n==null?void 0:n.MODE)=="string"?n.MODE:void 0,o=typeof(n==null?void 0:n.NODE_ENV)=="string"?n.NODE_ENV:void 0;return(r??o)==="production"}function YS(){return!GS()}function XS(){return typeof window>"u"?!1:window.__ARTIFACT_DEBUG__===!0}function JS(){return YS()||XS()}function ZS({preview:e,idx:t}){return w.useEffect(()=>{JS()&&console.debug(`[MessageComponent] Preview ${t} mounted:`,{src:e.src.substring(0,100),alt:e.alt,label:e.label})},[t,e]),u.jsxs("div",{className:"space-y-2",children:[e.label&&u.jsxs("p",{className:"text-[0.65rem] uppercase tracking-wide text-muted-foreground",children:["Artifact: ",e.label]}),u.jsx("div",{className:"overflow-hidden rounded border border-border/60 bg-background/60 p-1 shadow-sm",children:u.jsx("img",{src:e.src,alt:e.alt,title:e.label,loading:"lazy",className:"h-auto max-h-[420px] w-full rounded object-contain",onLoad:()=>{},onError:n=>{console.error(`[MessageComponent] ❌ Image failed to load for artifact ${t}:`,{alt:e.alt,label:e.label,message:n.target.alt})}})})]})}const io=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:te("rounded-lg border bg-card text-card-foreground shadow-sm",e),...t}));io.displayName="Card";const ao=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:te("flex flex-col space-y-1.5 p-6",e),...t}));ao.displayName="CardHeader";const lo=v.forwardRef(({className:e,...t},n)=>u.jsx("h3",{ref:n,className:te("text-2xl font-semibold leading-none tracking-tight",e),...t}));lo.displayName="CardTitle";const lp=v.forwardRef(({className:e,...t},n)=>u.jsx("p",{ref:n,className:te("text-sm text-muted-foreground",e),...t}));lp.displayName="CardDescription";const co=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:te("p-6 pt-0",e),...t}));co.displayName="CardContent";const cp=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:te("flex items-center p-6 pt-0",e),...t}));cp.displayName="CardFooter";function QS({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=u.jsx("p",{className:"text-sm leading-relaxed text-blue-800/90 dark:text-blue-200/90 whitespace-pre-wrap",children:s});else{const c=ro(s);a=u.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:c})}const l=o?"Please approve or reject this action to resume the workflow.":"Waiting for approval from another participant.";return u.jsxs(io,{className:te("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:[u.jsxs(ao,{className:"pb-3",children:[u.jsx(lo,{className:"text-blue-900 dark:text-blue-100 text-base",children:i}),u.jsx(lp,{className:"text-blue-700 dark:text-blue-300 text-sm",children:l})]}),a&&u.jsx(co,{className:"pt-0 pb-3",children:a}),u.jsx(cp,{className:"pt-0",children:u.jsxs("div",{className:"flex gap-2 ml-auto",children:[u.jsx(Ze,{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"}),u.jsx(Ze,{size:"sm",onClick:()=>t(e),className:"bg-blue-600 hover:bg-blue-700 text-white",disabled:r||!o,children:"Approve"})]})})]})}const eC="prose prose-sm max-w-none break-words dark:prose-invert prose-headings:break-words prose-p:break-words prose-li:break-words prose-td:break-words prose-th:break-words prose-a:break-all prose-code:break-words prose-blockquote:break-words";function up({data:e}){return Array.isArray(e)?e.every(n=>n===null||["string","number","boolean"].includes(typeof n))?u.jsx("div",{className:eC,children:u.jsx("ul",{className:"list-disc pl-5",children:e.map((n,r)=>u.jsx("li",{children:String(n)},r))})}):u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:ro(e)}):u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:ro(e)})}function tC({message:e,viewMode:t}){const r=wf(e).name||"tool",o=c=>{if(c==null)return null;const d=typeof c=="string"?ba(c)??c:c;if(d&&typeof d=="object")return u.jsx(up,{data:d});const f=typeof d=="string"?d:(()=>{try{return ro(d)}catch{return String(d??"")}})();return u.jsx("pre",{className:"whitespace-pre-wrap break-words font-sans text-sm text-foreground/90",children:f})},s=c=>{if(c==null)return null;const{content:d,isMarkdown:f}=tS(c);return f?u.jsx(so,{content:d,className:"text-current"}):o(c)};if(t==="preview")return null;const i=e.content.find(c=>c.type!=="tool_call");if(!i)return u.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[u.jsx(le.Loader,{className:"h-4 w-4 animate-spin"}),u.jsxs("span",{children:["Waiting for ",r," output…"]})]});if(i.type==="text"){const d=(i.text??"").trim();if(!d)return null;const f=Cs(d);return s(f)}const a=no(i),l=Cs(a);return s(l)}function nC({message:e,viewMode:t,isStreaming:n=!1}){var a;const r=e.name??"tool",o=w.useMemo(()=>{const l=e.additionalKwargs??{};return(Array.isArray(l.toolProgress)?[...l.toolProgress]:[]).slice(-6)},[e]),s=(a=o[o.length-1])==null?void 0:a.title,i=n||o.length>0;return u.jsxs("div",{className:"space-y-2",children:[i&&u.jsxs("div",{className:"space-y-2",children:[u.jsxs("div",{className:"flex items-center gap-2 text-xs uppercase tracking-wide text-muted-foreground",children:[n&&u.jsx(le.Loader,{className:"h-3 w-3 animate-spin"}),u.jsx("span",{children:s??`Running ${r}…`})]}),o.length>0&&u.jsx("div",{className:"space-y-2 text-xs text-muted-foreground",children:o.map((l,c)=>u.jsxs("div",{className:"rounded border border-current/10 bg-muted/60 p-2 text-[11px] leading-snug",children:[u.jsxs("div",{className:"flex items-center justify-between gap-2 text-[10px] uppercase opacity-70",children:[u.jsx("span",{children:l.title??l.step??`Step ${l.idx??c+1}`}),u.jsx("span",{className:"text-[8px] lowercase",children:l.type??"progress"})]}),l.content&&u.jsx("p",{className:"mt-1 text-[12px] text-foreground/90",children:l.content}),u.jsxs("div",{className:"mt-1 flex flex-wrap gap-2 text-[10px] opacity-70",children:[typeof l.factsFound=="number"&&u.jsxs("span",{children:["Facts found: ",l.factsFound]}),typeof l.isSufficient=="boolean"&&u.jsxs("span",{children:["Research ",l.isSufficient?"sufficient":"needs more data"]})]})]},`progress-${r}-${c}`))})]}),u.jsx(tC,{message:e,viewMode:t})]})}function rC(e){const{allowFileOpen:t,currentThreadId:n}=e,{toast:r}=Ia(),[o,s]=w.useState({}),[i,a]=w.useState(null),[l,c]=w.useState(!1),d=w.useCallback(()=>{c(!1),a(null)},[]),f=w.useCallback(p=>{a(p),c(!0)},[]),h=w.useCallback(async(p,m,g)=>{var y,x;if(!t){p.preventDefault();return}if(o[g]){p.preventDefault();return}try{const b=String(m.url??""),S=b.match(/\/chat\/files\/([^/]+)(?:\/(view|download))?/);if(S){p.preventDefault();const k=S[1],C=m.name||`file_${k}`,T=m.mimeType||"application/octet-stream";f({id:k,name:C,mimeType:T});return}if(b.startsWith("data:")){p.preventDefault(),s(C=>({...C,[g]:!0}));const k=r({title:"Fetching file...",description:"",open:!0});try{const C=await uS(n??void 0);if(!C||!Array.isArray(C))throw new Error("Invalid file list response");const T=C.find(I=>!I||typeof I!="object"||!((I.filename??"")===(m.name??""))?!1:typeof m.size=="number"&&typeof I.size=="number"?I.size===m.size:!0);if(!(T!=null&&T.id))throw new Error(`File "${m.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:m.name||T.filename||`file_${T.id}`,mimeType:m.mimeType||T.mime_type||"application/octet-stream"}),(y=k.update)==null||y.call(k,{id:k.id,title:"Success",description:`Opened ${m.name}`,open:!0})}catch(C){console.error("Failed to fetch server file:",C);const T=C instanceof Error?C.message:"Unknown error occurred";(x=k.update)==null||x.call(k,{id:k.id,title:"Failed",description:T}),r({title:"Failed to fetch file",description:T,open:!0})}finally{s(C=>({...C,[g]:!1}))}}}catch(b){console.error("File click error:",b),s(S=>({...S,[g]:!1}))}},[t,o,r,n,f]);return{uploadingFiles:o,handleFileClick:h,fileViewerOpen:l,currentFileInfo:i,closeFileViewer:d}}function oC({text:e,expanded:t,onExpandedChange:n,previewLength:r,isCompact:o}){const s=Math.max(e.length-r,0),i=e.substring(0,r);return u.jsxs("div",{className:"flex flex-col gap-1",children:[u.jsx("div",{className:te("text-sm text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:t?u.jsx(so,{content:e,allowHtml:!1}):u.jsxs("pre",{className:te("font-sans whitespace-pre-wrap break-words bg-transparent p-0 m-0 text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:[i,"..."]})}),u.jsx(Ze,{type:"button",variant:"ghost",size:"sm",className:"h-6 text-xs !text-[hsl(var(--chat-bubble-user-text))]",onClick:()=>n(!t),children:t?u.jsxs(u.Fragment,{children:[u.jsx(le.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):u.jsxs(u.Fragment,{children:[u.jsx(le.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more (",s," chars)"]})})]})}function sC({className:e}){const[t,n]=w.useState(0);return w.useEffect(()=>{const r=setInterval(()=>n(o=>(o+1)%4),500);return()=>clearInterval(r)},[]),u.jsxs("span",{"aria-live":"polite",className:te("inline-block text-xs opacity-70 ml-1",e),children:["Is thinking",".".repeat(t)]})}const Ds=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",truncateUserMessages:c=!0,userMessagePreviewLength:d=500,showToolMessages:f=!0,showArtifactPreviews:h=!0,customStyles:p={},onEdit:m,onRegenerate:g,onCancelEdit:y,onCopy:x,activeInterrupt:b,disableInterruptActions:S=!1,onInterruptActionStart:k,onInterruptActionEnd:C,checkpointCandidates:T=[],activeCheckpointId:I=null,onSelectCheckpoint:A,defaultCheckpointId:N=null,messageParentCheckpointId:L=null}){const[R,O]=w.useState(!1),[F,_]=w.useState("preview"),[B,j]=w.useState(!1),{currentThreadId:K}=_o(),{respondToInterrupt:z}=jo(),M=l==="phone"||l==="half-screen",G=t.role,X=G==="tool",se=w.useMemo(()=>"type"in t&&t.type==="default_message"?t:null,[t]),be=!!se,Ie=!(r&&G!=="user"),{uploadingFiles:Y,handleFileClick:U,fileViewerOpen:J,currentFileInfo:$,closeFileViewer:q}=rC({allowFileOpen:Ie,currentThreadId:K}),Z=w.useMemo(()=>{switch(G){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))]"}},[G]),ue=w.useMemo(()=>{if(se)return"";const D=t.content;return Array.isArray(D)?nS(D):""},[se,t]),ie=w.useMemo(()=>{if(se)return{};const D=t.content;return Array.isArray(D)?wf(t):{}},[se,t]),_e=w.useMemo(()=>X?!!(t.additionalKwargs??{}).toolStreaming:!1,[X,t]),He=w.useMemo(()=>{if(se)return[];const D=t.content;return Array.isArray(D)?D.filter(Q=>Q.type==="image_url"):[]},[se,t]),oe=w.useMemo(()=>{if(se)return[];const D=t.content;return Array.isArray(D)?D.filter(Q=>Q.type==="file"):[]},[se,t]),ye=w.useMemo(()=>{if(se)return[];const D=t.content;return Array.isArray(D)?D.filter(Q=>Q.type==="interrupt"):[]},[se,t]),Oe=(b==null?void 0:b.id)??(b==null?void 0:b.interrupt_id),Ye=Ts(Oe),nt=b==null?void 0:b.value,Xe=w.useMemo(()=>{if(se)return"";const D=t.content;return Array.isArray(D)?rS(D):""},[se,t]),qe=w.useMemo(()=>{if(se||!h)return[];const Q=t.artifact;if(!Q)return[];const ne=[],me=[...Array.isArray(Q.plots)?Q.plots:[]];for(const xe of me){const De=lS(xe);De&&ne.push(De)}return ne},[se,t,h]),it=w.useCallback(async()=>{const D=X?Xe:ue;async function Q(ne){if(navigator.clipboard&&typeof navigator.clipboard.writeText=="function"){await navigator.clipboard.writeText(ne);return}if(navigator.clipboard&&typeof navigator.clipboard.write=="function"&&typeof ClipboardItem<"u"){const me=new Blob([ne],{type:"text/plain"});await navigator.clipboard.write([new ClipboardItem({"text/plain":me})]);return}throw new Error("Clipboard API not supported in this context.")}try{await Q(D),O(!0),setTimeout(()=>O(!1),2e3),x==null||x(D)}catch(ne){console.error("Failed to copy:",ne)}},[X,Xe,ue,x]),Je=w.useCallback(()=>{if(!m)return;const D=X?Xe:ue,Q="type"in t&&t.type==="default_message"?void 0:{checkpointId:t.checkpointId??null,checkpointNs:t.checkpointNs??null};m(t.id,D,Q)},[m,t.id,X,Xe,ue,t]),et=w.useCallback(()=>{g==null||g(n)},[g,n]),at=w.useCallback(()=>{const Q=te(M?"h-3 w-3":"h-4 w-4","opacity-60 flex-shrink-0",Z);switch(G){case"user":return u.jsx(le.User,{className:Q});case"assistant":return u.jsx(le.Bot,{className:Q});case"tool":return u.jsx(le.Wrench,{className:Q});default:return u.jsx(le.Bot,{className:Q})}},[M,Z,G]),jt=w.useCallback(()=>{const D="group relative mb-4 flex w-full";switch(G){case"user":return te(D,"justify-end");case"assistant":case"tool":case"system":return te(D,"justify-start");default:return D}},[G]),ht=w.useCallback(()=>{const D=te("rounded-lg px-4 py-3 relative min-w-0 max-w-full break-words",M&&"px-3 py-2 text-sm");if(be)return te(D,"w-full","bg-[hsl(var(--chat-bubble-ai))] text-[hsl(var(--chat-bubble-ai-text))]","border border-border/60 dark:border-border/40 shadow-sm");switch(G){case"user":return te(D,"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 te(D,"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 te(D,"w-full md:max-w-[95%] bg-secondary/50 text-secondary-foreground border border-dashed");case"system":return te(D,"w-full md:max-w-[85%] bg-accent/40 text-muted-foreground border");default:return te(D,"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")}},[M,be,G]),ft=w.useCallback(async D=>{if(S)return;const Q=Ts((D==null?void 0:D.id)??(D==null?void 0:D.interrupt_id));if(!Q){console.warn("Interrupt part missing id",D);return}try{k==null||k(),await z(Q,!0)}catch(ne){console.error("Failed to approve interrupt:",ne)}finally{C==null||C()}},[S,C,k,z]),mt=w.useCallback(async D=>{if(S)return;const Q=Ts((D==null?void 0:D.id)??(D==null?void 0:D.interrupt_id));if(!Q){console.warn("Interrupt part missing id",D);return}try{k==null||k(),await z(Q,!1)}catch(ne){console.error("Failed to reject interrupt:",ne)}finally{C==null||C()}},[S,C,k,z]),St=w.useCallback(({part:D,i:Q})=>{if(D.type==="text"){const ne=D.text??"",me=ne.trim(),xe=ba(me);return xe&&G!=="tool"?u.jsx(up,{data:xe},Q):G==="user"&&c&&me.length>d?u.jsx(oC,{text:me,expanded:B,onExpandedChange:j,previewLength:d,isCompact:M},Q):u.jsx(so,{content:ne,allowHtml:!1},Q)}if(D.type==="image_url"){const ne=D;return u.jsx("div",{className:"my-2",children:u.jsx("img",{src:ne.url,alt:ne.alt??"",loading:"lazy",className:"border rounded max-h-[420px] w-auto object-contain"})},Q)}if(D.type==="file"){const ne=D,me=ne.name||"file";return u.jsxs("a",{href:ne.url,onClick:xe=>U(xe.nativeEvent,ne,Q),className:`inline-flex items-center gap-2 rounded px-2 py-1 text-xs bg-gray-100 border hover:bg-gray-200
|
|
137
|
+
dark:bg-background/10 dark:border-border/30 dark:hover:bg-background/20`,children:[Y[Q]?u.jsx(le.Loader,{className:"h-4 w-4 animate-spin"}):null,u.jsxs("span",{className:"truncate max-w-[180px]",children:[me,Y[Q]?" (processing)":""]})]},Q)}if(D.type==="interrupt"){const ne=D,me=Ts((ne==null?void 0:ne.id)??(ne==null?void 0:ne.interrupt_id)),xe=!!(Ye&&me&&me===Ye),De=xe?nt??(ne==null?void 0:ne.value):ne==null?void 0:ne.value,Re=me?{...ne,id:me,interrupt_id:me}:ne;return u.jsx(QS,{interruptPart:Re,onApprove:ft,onReject:mt,disabled:S,isActive:xe,payload:De},Q)}return null},[U,Y,ft,mt,G,c,d,B,M,Ye,nt,b,S,ye]),Mt=w.useCallback(()=>u.jsxs("div",{className:"flex items-center gap-2 p-2 bg-muted/30 rounded",children:[u.jsx(le.Paperclip,{className:"h-4 w-4 text-muted-foreground"}),u.jsx("span",{className:"text-sm text-muted-foreground",children:"File upload"})]}),[]),Lt=w.useCallback(()=>{const D=ue.trim().length>0||He.length>0||oe.length>0||ye.length>0;if(!X&&oe.length>0&&!r)return Mt();if(!X&&!D&&!r)return null;if(X)return!f&&qe.length>0?null:f?u.jsx(nC,{message:t,viewMode:F,isStreaming:_e},t.id):null;if(!X&&!se){const Q=t,ne=u.jsx("div",{className:"space-y-2",children:Q.content.map((me,xe)=>u.jsx(St,{part:me,i:xe},xe))});return r?u.jsxs("div",{"aria-busy":"true",role:"status",children:[ne,u.jsx(sC,{className:Z})]}):ne}},[ue,He.length,oe.length,ye.length,r,X,F,f,qe.length,Mt,Z]),Vt=w.useMemo(()=>se?"Assistant":oS(t),[se,t]),Ue=w.useMemo(()=>se?[]:Array.isArray(T)?T:[],[T,se]),dn=w.useMemo(()=>{var D;return Ue.length?N&&Ue.some(Q=>Q.id===N)?N:((D=Ue[0])==null?void 0:D.id)??null:null},[N,Ue]),We=w.useMemo(()=>!Ue.length||!I?null:Ue.some(D=>D.id===I)?I:null,[I,Ue])??dn,gt=G==="user"&&Ue.length>0&&typeof A=="function",Rt=w.useCallback((D,Q=!1)=>{if(!A)return;const ne=(D==null?void 0:D.id)??null,me=(D==null?void 0:D.parentId)??L??null;A(ne,me,Q)},[L,A]),H=w.useMemo(()=>We?Ue.findIndex(D=>D.id===We):-1,[We,Ue]),re=w.useMemo(()=>H<0?null:Ue[H]??null,[H,Ue]);return X&&!f&&qe.length===0?null:be&&se?u.jsx("div",{className:te(jt(),p.container),children:u.jsxs("div",{className:te(ht(),p.content),children:[u.jsxs("div",{className:"flex items-center gap-2 mb-2 pb-2 border-b border-current/10",children:[u.jsx(le.Bot,{className:te("h-4 w-4",Z)}),a&&u.jsx("span",{className:"font-medium text-sm",children:"Assistant"})]}),u.jsx(so,{content:se.content,className:"text-current"})]})}):u.jsxs(u.Fragment,{children:[u.jsx("div",{className:te(jt(),p.container),children:u.jsxs("div",{className:te(ht(),p.content),children:[(i||a||X)&&u.jsxs("div",{className:te("flex items-center justify-between mb-2 pb-2 border-b border-current/10",M&&"mb-1 pb-1",Z,p.header),children:[u.jsxs("div",{className:"flex items-center gap-2",children:[at(),a&&Vt&&u.jsx("span",{className:te("font-medium",M?"text-xs":"text-sm"),children:Vt}),X&&u.jsxs(vf,{variant:"outline",className:te("text-xs flex items-center gap-1 cursor-pointer select-none",Z,"border border-current/40",M&&"text-xs h-4"),role:"button",tabIndex:0,"aria-expanded":F==="expanded",onClick:()=>_(D=>D==="expanded"?"preview":"expanded"),onKeyDown:D=>{(D.key==="Enter"||D.key===" ")&&(D.preventDefault(),_(Q=>Q==="expanded"?"preview":"expanded"))},children:[u.jsx("span",{children:ie.name??"Tool Output"}),ie.toolCallId&&u.jsx("span",{className:"opacity-70",children:ie.toolCallId.slice(0,8)}),F==="expanded"?u.jsx(le.ChevronUp,{className:"h-3 w-3"}):u.jsx(le.ChevronDown,{className:"h-3 w-3"})]})]}),u.jsxs("div",{className:"flex items-center gap-2",children:[gt&&re&&H>=0&&u.jsx("div",{className:"flex flex-wrap items-center gap-2 text-xs",children:u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx("button",{type:"button",className:te("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",H<Ue.length-1?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(H>=Ue.length-1)return;const D=Ue[H+1];D&&Rt(D)},"aria-label":"Older checkpoint (back in time)",disabled:H>=Ue.length-1,children:u.jsx(le.ChevronLeft,{className:"h-3 w-3"})}),u.jsx("div",{className:"flex items-center gap-2",children:u.jsxs("span",{className:"whitespace-nowrap",children:[Ue.length-H," / ",Ue.length]})}),u.jsx("button",{type:"button",className:te("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",H>0?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(!(H<=0))if(H===1)Rt(null,!0);else{const D=Ue[H-1];D&&Rt(D,!1)}},"aria-label":"Newer checkpoint (forward in time)",disabled:H<=0,children:u.jsx(le.ChevronRight,{className:"h-3 w-3"})})]})}),i&&t.createdAt&&u.jsx("time",{className:te("text-xs opacity-60",Z,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&&u.jsxs("div",{className:te("opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",p.actions),children:[u.jsx("div",{className:"relative",children:u.jsx(Ze,{variant:"ghost",size:"sm",onClick:()=>it(),className:te("h-6 w-6 p-0 hover:bg-foreground/10",Z,M&&"h-5 w-5"),"aria-label":"Copy message",title:"Copy message",children:u.jsx(le.Copy,{className:te(R?"text-success":Z,M?"h-3 w-3":"h-4 w-4")})})}),G==="user"&&m&&u.jsx(Ze,{variant:"ghost",size:"sm",onClick:Je,className:te("h-6 w-6 p-0 hover:bg-foreground/10",Z,M&&"h-5 w-5"),"aria-label":"Edit message",children:u.jsx(le.Edit,{className:te(Z,M?"h-3 w-3":"h-4 w-4")})}),G==="assistant"&&g&&u.jsx(Ze,{variant:"ghost",size:"sm",onClick:et,className:te("h-6 w-6 p-0 hover:bg-foreground/10",Z,M&&"h-5 w-5"),"aria-label":"Regenerate response",children:u.jsx(le.RotateCcw,{className:te(Z,M?"h-3 w-3":"h-4 w-4")})})]})]})]}),u.jsxs("div",{className:"relative",children:[Lt(),h&&qe.length>0&&u.jsx("div",{className:"mt-3 space-y-4",children:qe.map((D,Q)=>u.jsx(ZS,{preview:D,idx:Q},`artifact-${Q}`))})]}),X&&F==="expanded"&&(ie.toolCallId||ie.name)&&u.jsxs("div",{className:te("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",M&&"text-xs"),children:[ie.name&&u.jsxs("div",{children:["Function: ",ie.name]}),ie.toolCallId&&u.jsxs("div",{children:["Call ID: ",ie.toolCallId]})]}),!(i||a||X)&&s&&!o&&u.jsxs("div",{className:te("absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",p.actions),children:[u.jsx(Ze,{variant:"ghost",size:"sm",onClick:()=>it(),className:te("h-6 w-6 p-0 hover:bg-background/50 text-current",M&&"h-5 w-5"),children:u.jsx(le.Copy,{className:te(R?"text-success":"text-current",M?"h-3 w-3":"h-4 w-4")})}),G==="user"&&m&&u.jsx(Ze,{variant:"ghost",size:"sm",onClick:Je,className:te("h-6 w-6 p-0 hover:bg-background/50 text-current",M&&"h-5 w-5"),children:u.jsx(le.Edit,{className:te("text-current",M?"h-3 w-3":"h-4 w-4")})}),G==="assistant"&&g&&u.jsx(Ze,{variant:"ghost",size:"sm",onClick:et,className:te("h-6 w-6 p-0 hover:bg-background/50 text-current",M&&"h-5 w-5"),children:u.jsx(le.RotateCcw,{className:te("text-current",M?"h-3 w-3":"h-4 w-4")})})]})]})}),$&&u.jsx(NS,{isOpen:J,onClose:q,fileId:$.id,fileName:$.name,mimeType:$.mimeType})]})},(e,t)=>{var i,a,l,c,d,f,h,p;if(t.isStreamingMessage||e.isStreamingMessage||!(e.message.id===t.message.id&&Sf(e.message)===Sf(t.message)))return!1;const o=["isEditing","showActions","layoutSize","showTimestamp","showAgentName","truncateUserMessages","userMessagePreviewLength","showToolMessages","attemptMeta"].every(m=>e[m]===t[m]),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)===((c=t.customStyles)==null?void 0:c.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});Ds.displayName="MessageComponent";function iC(e,t){return w.useMemo(()=>{var d,f,h,p,m;const n=e&&"type"in e&&e.type==="default_message";let r=[],o=null,s={},i={},a=null,l=null,c=null;if(!n&&e){const g=e,y=g.checkpointId??null;s=g.additionalKwargs??{},i=g.responseMetadata??{};const x=y&&t.checkpointMetaById?t.checkpointMetaById.get(y)??null:null;a=typeof s.step=="number"?s.step:typeof i.step=="number"?i.step:(x==null?void 0:x.step)??null;const b=typeof s.source=="string"?s.source:typeof i.source=="string"?i.source:(x==null?void 0:x.source)??null;l=b?String(b):null;const S=a!==null&&l?`${a}:${l}`:null;if(S&&((d=t.checkpointIndexByKey)!=null&&d.has(S))?r=t.checkpointIndexByKey.get(S)??[]:y&&x&&(r=[x]),o=y??((f=r[0])==null?void 0:f.id)??null,c=y?((h=t.attemptMetaById)==null?void 0:h.get(y))??null:null,!c&&(e==null?void 0:e.role)==="user"&&(e!=null&&e.id)&&t.userMessageIdToAttempts){const k=t.userMessageIdToAttempts.get(e.id);if(k&&k.length>0){const C=k[0].checkpointId;c=((p=t.attemptMetaById)==null?void 0:p.get(C))??null,c&&console.log(`[useMessageMetadata] Found attempt by user message ID "${e.id}":`,k.length,"versions")}}if(!c&&r.length>0&&t.attemptMetaById){const k=t.attemptMetaById.get(r[0].id);k&&(c=k)}if(c&&c.attemptCount>1&&t.attemptMetaById){const k=c.baseUserMessageId;if(k){const C=[];for(const[T,I]of t.attemptMetaById.entries())if(I.baseUserMessageId===k){const A=(m=t.checkpointMetaById)==null?void 0:m.get(T);A&&C.push(A)}C.length>0&&(r=C)}}if(c&&c.attemptCount>1&&t.checkpointMetaById&&t.attemptMetaById){const k=[];for(const[C,T]of t.checkpointMetaById.entries()){const I=t.attemptMetaById.get(C);I&&I.attemptCount===c.attemptCount&&I.baseUserMessageId===c.baseUserMessageId&&k.push(T)}k.sort((C,T)=>{const I=C.createdAt?Date.parse(C.createdAt):0;return(T.createdAt?Date.parse(T.createdAt):0)-I}),k.length>0&&(r=k,console.log("[useMessageMetadata] Populated checkpointCandidates with all attempts:",{messageId:e.id,attemptCount:c.attemptCount,candidateIds:r.map(C=>C.id)}))}}return{checkpointCandidates:r,defaultCheckpointId:o,attemptMeta:c,resolvedStep:a,resolvedSource:l}},[e,t.checkpointMetaById,t.checkpointIndexByKey,t.attemptMetaById,t.userMessageIdToAttempts])}const dp=(e,t)=>(e==null?void 0:e.id)??`message-${t}`,fp=w.memo(function({message:t,index:n,isStreaming:r,streamingAssistantId:o,streamingDebounceMs:s,layoutSize:i,enableMessageEditing:a,editingMessageId:l,onEdit:c,onRegenerate:d,onCancelEdit:f,activeInterrupt:h,disableInterruptActions:p,onInterruptActionStart:m,onInterruptActionEnd:g,showToolMessages:y,showArtifactPreviews:x,checkpointMetaById:b,checkpointIndexByKey:S,attemptMetaById:k,userMessageIdToAttempts:C,activeCheckpointId:T,onSelectCheckpoint:I}){const A=dp(t,n),N="type"in t&&t.type==="default_message",{checkpointCandidates:L,defaultCheckpointId:R,attemptMeta:O}=iC(t,{checkpointMetaById:b,checkpointIndexByKey:S,attemptMetaById:k,userMessageIdToAttempts:C}),F=t&&!N?t.additionalKwargs??{}:{},_=t&&!N?t.responseMetadata??{}:{},B=(()=>{if(typeof F.parentCheckpointId=="string")return F.parentCheckpointId;if(typeof _.parentCheckpointId=="string")return _.parentCheckpointId})();return u.jsx("div",{className:"relative mb-4 last:mb-0","data-message-id":A,style:{minHeight:"60px",containIntrinsicSize:"auto 120px"},children:u.jsx(Ds,{message:t,messageIndex:n,isStreamingMessage:r&&o===t.id,streamingDebounceMs:s,isEditing:l===t.id,showActions:a,showTimestamp:!1,showAgentName:!0,layoutSize:i,onEdit:c,onRegenerate:()=>d(n),onCancelEdit:f,activeInterrupt:h,disableInterruptActions:p,onInterruptActionStart:m,onInterruptActionEnd:g,showToolMessages:y,showArtifactPreviews:x,checkpointCandidates:L,activeCheckpointId:T??null,onSelectCheckpoint:I,defaultCheckpointId:R,messageParentCheckpointId:B,attemptMeta:O})})});fp.displayName="MessageRow";const Na=w.forwardRef(({messages:e,isStreaming:t,streamingAssistantId:n,streamingDebounceMs:r,layoutSize:o,enableMessageEditing:s,editingMessageId:i,onStartReached:a,onEdit:l,onRegenerate:c,onCancelEdit:d,className:f,style:h,emptyMessage:p,followNewMessages:m=!0,isNavigatingCheckpoint:g=!1,onScrollAway:y,onAtBottom:x,activeInterrupt:b,disableInterruptActions:S=!1,onInterruptActionStart:k,onInterruptActionEnd:C,showToolMessages:T=!0,showArtifactPreviews:I=!0,checkpointMetaById:A,checkpointIndexByKey:N,attemptMetaById:L,userMessageIdToAttempts:R,activeCheckpointId:O,onSelectCheckpoint:F,createSyntheticThinkingMessage:_=!1},B)=>{const j=w.useRef(null),K=w.useRef(null),z=w.useRef(!1),M=w.useRef(!1),[G,X]=w.useState(!0),se=w.useMemo(()=>b?e.some(oe=>"type"in oe&&oe.type==="default_message"?!1:Array.isArray(oe==null?void 0:oe.content)&&oe.content.some(ye=>ye&&ye.type==="interrupt"&&(ye.id??ye.interrupt_id)===b.id)):!1,[b,e]),be=w.useMemo(()=>{if(!b||se)return null;const oe=b.id&&String(b.id).trim()?String(b.id).trim():"pending-interrupt";let ye;const Oe=b.value;if(Oe&&typeof Oe=="object"&&!Array.isArray(Oe)){const Ye=Oe.title;typeof Ye=="string"&&Ye.trim()&&(ye=Ye.trim())}return{id:`interrupt-${oe}`,role:"system",createdAt:new Date().toISOString(),content:[{type:"interrupt",id:oe,value:Oe,title:ye}]}},[b,se]),Ie=w.useMemo(()=>be?[...e,be]:e,[e,be]),Y=w.useMemo(()=>!_||!t?Ie:!Ie.some(ye=>ye.role==="assistant")&&Ie.length>0?[...Ie,{id:"thinking-assistant",role:"assistant",content:[],createdAt:new Date().toISOString()}]:Ie,[Ie,t,_]),U=w.useMemo(()=>T?Y:Y.filter(oe=>(oe==null?void 0:oe.role)!=="tool"),[Y,T]),J=w.useCallback(oe=>{X(oe),y&&y(!oe),x&&x(oe)},[y,x]),$=w.useMemo(()=>{if(a)return async()=>{if(!z.current){z.current=!0;try{await a()}finally{z.current=!1}}}},[a]),q=w.useMemo(()=>!m||g?!1:G?"auto":!1,[G,m,g]),Z=w.useMemo(()=>{if(typeof p!="string")return null;const oe=p.trim();return oe?{id:"default-message",role:"assistant",type:"default_message",content:oe,createdAt:new Date().toISOString()}:null},[p]),ue=["flex h-full flex-col md:flex-row",f].filter(Boolean).join(" "),ie=()=>Z?u.jsx("div",{className:"p-6 h-full overflow-y-auto",children:u.jsx("div",{className:"w-full max-w-full",children:u.jsx(Ds,{message:Z,messageIndex:0,isStreamingMessage:!1,showActions:!1,showTimestamp:!1,showAgentName:!0,layoutSize:o,onEdit:()=>{},onRegenerate:()=>{},onCancelEdit:()=>{},showArtifactPreviews:I})})}):u.jsx("div",{className:"flex h-full items-center justify-center py-8 text-center text-muted-foreground",children:p??"No messages yet. Start a conversation!"}),_e=U.length,He=_e>0;return w.useEffect(()=>{var oe,ye;if(_e===0){M.current=!1;return}if(!M.current)if(M.current=!0,j.current&&U.length>0){const Oe=U.length-1;(ye=(oe=j.current).scrollToIndex)==null||ye.call(oe,{index:Oe,align:"end",behavior:"auto"})}else K.current&&(K.current.scrollTop=K.current.scrollHeight)},[_e,U.length]),w.useImperativeHandle(B,()=>({scrollToLatest:()=>{var oe,ye;if(j.current&&U.length>0){const Oe=U.length-1;(ye=(oe=j.current).scrollToIndex)==null||ye.call(oe,{index:Oe,align:"end",behavior:"auto"})}else K.current&&(K.current.scrollTop=K.current.scrollHeight)},scrollToTop:()=>{var oe,ye;j.current&&U.length>0?(ye=(oe=j.current).scrollToIndex)==null||ye.call(oe,{index:0,align:"start",behavior:"auto"}):K.current&&(K.current.scrollTop=0)}}),[U]),u.jsx("div",{className:ue,style:h,children:u.jsx("div",{className:"relative flex-1 min-h-0",children:He?u.jsx($0,{ref:oe=>{j.current=oe},scrollerRef:oe=>{K.current=oe instanceof HTMLDivElement?oe:null},data:U,followOutput:q,overscan:200,increaseViewportBy:{top:100,bottom:200},defaultItemHeight:80,atBottomThreshold:50,startReached:()=>{$&&$()},atBottomStateChange:J,style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:(oe,ye)=>dp(ye,oe),itemContent:(oe,ye)=>u.jsx(fp,{message:ye,index:oe,isStreaming:t,streamingAssistantId:n,streamingDebounceMs:r,layoutSize:o,enableMessageEditing:s,editingMessageId:i,onEdit:l,onRegenerate:c,onCancelEdit:d,activeInterrupt:b,disableInterruptActions:S,onInterruptActionStart:k,onInterruptActionEnd:C,showToolMessages:T,showArtifactPreviews:I,checkpointMetaById:A,checkpointIndexByKey:N,attemptMetaById:L,userMessageIdToAttempts:R,activeCheckpointId:O,onSelectCheckpoint:F})}):ie()})})});Na.displayName="MessageList";const pp={value:""};function Ls({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:c=!0,showToolMessages:d=!0,showArtifactPreviews:f=!0,customStyles:h={},onMessageSent:p,onExcelUploadSuccess:m,onError:g}){const{api:y}=ui(),{currentThreadId:x}=_o(),{threadId:b,messages:S,isHistoryLoading:k,isLoading:C,navigateToCheckpoint:T,returnToLatest:I,checkpoint:A,checkpoints:N,interrupt:L,metadata:R,timelineCheckpoints:O,messagePreviews:F}=jo(),{isStreaming:_,error:B,connectionState:j,submit:K,stop:z}=lc(),M=b??x??null,G=(A==null?void 0:A.id)??null,X=(A==null?void 0:A.namespace)??null,se=(R==null?void 0:R.assemblingMessageId)??null,be=L,[Ie,Y]=w.useState(!1);w.useEffect(()=>{be||Y(!1)},[be]);const U=w.useCallback(()=>{Y(!0)},[]),J=w.useCallback(()=>{Y(!1)},[]),$=!!be||Ie,[q,Z]=w.useState(null),[ue,ie]=w.useState(""),[_e,He]=w.useState(null),[oe,ye]=w.useState(null),[Oe,Ye]=w.useState([]),[nt,Xe]=w.useState(0),[qe,it]=w.useState(0),[Je,et]=w.useState(!1),[at,jt]=w.useState(null),[ht,ft]=w.useState(null),[mt,St]=w.useState(!1),[Mt,Lt]=w.useState(null),Vt=w.useRef(!1),[Ue,dn]=w.useState(()=>pp.value),rt=w.useRef(Ue),We=w.useRef(null),gt=w.useCallback(pe=>{pp.value=pe,dn(pe)},[]),[Rt,H]=w.useState(!1),re=w.useRef(null),{checkpointMetaById:D,checkpointIndexByKey:Q,attemptMetaById:ne,userMessageIdToAttempts:me}=kw(N),xe=O??[],De=w.useRef(null),Re=w.useRef(null),je=w.useCallback(()=>{De.current&&(De.current.value=""),Re.current&&(Re.current.value=""),Xe(pe=>pe+1),it(pe=>pe+1)},[]),Kt=w.useCallback(pe=>{gt(pe)},[gt]),An=w.useRef(!1);w.useEffect(()=>{An.current&&!_&&(Ye([]),je()),An.current=_},[_,je]);const[ar,Ar]=w.useState("desktop");w.useEffect(()=>{const pe=()=>{const Se=window.innerWidth;Ar(Se<640?"phone":Se<1024?"tablet":"desktop")};return pe(),window.addEventListener("resize",pe),()=>window.removeEventListener("resize",pe)},[]),w.useEffect(()=>{Vt.current=!1},[M]),w.useEffect(()=>{rt.current=Ue},[Ue]),w.useEffect(()=>{if(!q){We.current=null;return}We.current===null&&(We.current=rt.current),gt(ue??"")},[ue,q,gt]),w.useEffect(()=>{(async()=>{if(!y.baseUrl){Lt(null);return}try{const Ee=(await y.getAgent("default")).uiDefaultMessage||"";Lt(Ee||null)}catch(Se){console.warn("Failed to fetch default message:",Se),Lt(null)}})()},[y.baseUrl]),w.useEffect(()=>{B&&!mt&&(g==null||g(B))},[B,mt,g]);const fo=pe=>{if(pe.length>cs)return`Message too long (${pe.length}/${cs} characters)`;try{return Aw(pe),null}catch(Se){return(Se==null?void 0:Se.message)||"Invalid message"}},Un=async pe=>{const Se=pe.trim();if(!(!Se&&Oe.length===0)){if(Se){const Ee=fo(Se);if(Ee){ye(Ee);return}}try{const Ee=q?(_e==null?void 0:_e.checkpointId)??G??void 0:G??void 0,Ve=q?(_e==null?void 0:_e.checkpointNs)??X??void 0:X??void 0;await K({text:Se||"",attachments:Oe},{checkpointId:Ee,checkpointNs:Ve,edit:!!q,originalMessageId:q??void 0}),p==null||p(Se),gt(""),ye(null),Ye([]),je(),Z(null),ie(""),He(null)}catch(Ee){const Ve=(Ee==null?void 0:Ee.message)||"Failed to send message";ye(Ve),g==null||g(Ve)}}},lr=w.useCallback((pe,Se,Ee)=>{c&&(We.current=Ue,Z(pe),ie(Se),gt(Se),ye(null),He({checkpointId:(Ee==null?void 0:Ee.checkpointId)??null,checkpointNs:(Ee==null?void 0:Ee.checkpointNs)??null}))},[Ue,c,gt]),E=w.useCallback(()=>{Z(null),ie(""),He(null),ye(null),gt(We.current??Ue),We.current=null},[Ue,gt]),V=w.useCallback((pe,Se,Ee)=>{lr(pe,Se,Ee)},[lr]),ae=w.useCallback(pe=>{let Se=null;for(let nn=pe-1;nn>=0;nn--)if(S[nn].role==="user"){Se=S[nn];break}if(!Se)return;const Ee=Array.isArray(Se.content)?Se.content:[],Hn=Ee.filter(nn=>(nn==null?void 0:nn.type)==="text").map(nn=>nn.text).join("")||(()=>{try{return JSON.stringify(Ee,null,2)}catch{return String(Ee)}})();Hn&&K({text:Hn},{checkpointId:G??void 0,checkpointNs:X??void 0,edit:!0,originalMessageId:Se.id})},[S,K,G,X]),we=pe=>{const Se=Array.from(pe.target.files||[]);Ye(Ee=>[...Ee,...Se]),pe.target.value=""},Ge=pe=>{Ye(Se=>{const Ee=Se.filter((Ve,Hn)=>pe!==Hn);return Ee.length===0&&je(),Ee})},tt=async pe=>{const Se=(pe.target.files||[])[0];if(Se){jt(null),ft(null),et(!0);try{await K({attachments:[Se]},{checkpointId:G??void 0,checkpointNs:X??void 0});const Ee=`Uploaded ${Se.name} - processing through chat stream`;ft(Ee)}catch(Ee){const Ve=Ee instanceof Error?Ee.message:"Failed to upload Excel file";console.error("Excel upload failed",Ee),jt(Ve),g==null||g(Ve)}finally{et(!1),pe.target.value="",je()}}},Fe=async pe=>{if(x){H(!0);try{if(!pe){await I(),requestAnimationFrame(()=>{var Ve;(Ve=re.current)==null||Ve.scrollToLatest()});return}const Se=N.find(Ve=>Ve.checkpointId===pe),Ee=(Se==null?void 0:Se.checkpointNs)??null;await T(pe,Ee),requestAnimationFrame(()=>{var Ve;(Ve=re.current)==null||Ve.scrollToTop()})}finally{H(!1)}}},$e=w.useCallback(async(pe,Se,Ee)=>{await Fe(Ee?null:pe)},[Fe]),It=`flex flex-1 w-full flex-col min-h-0 min-w-0 max-h-full overflow-hidden bg-transparent ${e} ${h.container||""}`,pt=`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 ${h.messagesArea||""}`,xt=`relative flex-shrink-0 w-full border-t p-4 bg-transparent ${h.inputArea||""}`;return u.jsxs("div",{className:It,children:[!!B&&!mt&&u.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:[u.jsx("span",{children:B}),u.jsx(Ze,{variant:"ghost",size:"sm",onClick:()=>St(!0),className:"text-red-800 hover:bg-red-100","aria-label":"Dismiss error",children:u.jsx(le.X,{size:16})})]}),u.jsxs("div",{className:`relative ${pt}`,style:r?{maxHeight:r}:void 0,children:[u.jsx(Na,{ref:re,className:"h-full",style:{height:"100%"},messages:S,isStreaming:_,streamingAssistantId:se,streamingDebounceMs:typeof s=="number"?s:o,followNewMessages:i,layoutSize:ar,enableMessageEditing:c,editingMessageId:q,onEdit:V,onRegenerate:ae,onCancelEdit:E,emptyMessage:Mt??void 0,isNavigatingCheckpoint:Rt,activeInterrupt:be,disableInterruptActions:Ie,onInterruptActionStart:U,onInterruptActionEnd:J,showToolMessages:d,showArtifactPreviews:f,checkpointMetaById:D,checkpointIndexByKey:Q,attemptMetaById:ne,userMessageIdToAttempts:me,activeCheckpointId:G,onSelectCheckpoint:$e,timelineCheckpoints:xe,messagePreviews:F}),(j==="reconnecting"||j==="connecting")&&u.jsx("div",{className:"pointer-events-none absolute top-3 right-3 z-20 rounded-full bg-muted/80 px-3 py-1 text-xs font-medium text-foreground shadow-sm backdrop-blur-sm dark:bg-muted/60",children:u.jsxs("span",{className:"flex items-center gap-2",children:[u.jsx(le.Loader2,{className:"h-3 w-3 animate-spin"}),j==="reconnecting"?"Reconnecting…":"Connecting…"]})}),j==="error"&&u.jsx("div",{className:"pointer-events-none absolute top-3 right-3 z-20 rounded-full bg-destructive/10 px-3 py-1 text-xs font-semibold text-destructive shadow-sm",children:"Connection lost"}),C&&u.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:[u.jsx(le.Loader2,{className:"h-6 w-6 animate-spin"}),u.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:"Loading messages…"})]}),(k||Rt)&&u.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:[u.jsx(le.Loader2,{className:"h-6 w-6 animate-spin"}),u.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:"Loading checkpoint…"})]})]}),u.jsxs("div",{className:xt,children:[q&&u.jsx("div",{className:"mb-3 p-3 bg-blue-50 border border-blue-200 rounded-lg",children:u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx(le.Edit3,{size:16,className:"text-blue-600"}),u.jsx("span",{className:"text-sm font-medium text-blue-800",children:"Editing message"})]}),u.jsx(Ze,{variant:"ghost",size:"sm",onClick:E,className:"text-blue-600 hover:bg-blue-100",children:u.jsx(le.X,{size:16})})]})}),(a||l)&&u.jsxs("div",{className:"mb-3 space-y-3",children:[a&&u.jsxs(u.Fragment,{children:[u.jsx("input",{ref:De,type:"file",multiple:!0,onChange:pe=>we(pe),className:"hidden"},nt),Oe.length>0&&u.jsx("div",{className:"flex flex-wrap gap-2",children:Oe.map((pe,Se)=>u.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:[u.jsx(le.Paperclip,{size:14}),u.jsx("span",{className:"truncate max-w-[150px]",children:pe.name}),u.jsx(Ze,{variant:"ghost",size:"sm",onClick:()=>Ge(Se),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 ${pe.name}`,children:u.jsx(le.X,{size:12})})]},Se))})]}),l&&u.jsxs(u.Fragment,{children:[u.jsx("input",{ref:Re,type:"file",accept:".xls,.xlsx,.xlsm",onChange:tt,className:"hidden"},qe),Je&&u.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[u.jsx(le.Loader2,{className:"h-4 w-4 animate-spin"})," Uploading Excel file..."]}),ht&&!Je&&u.jsx("div",{className:"text-sm rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-emerald-700",children:ht}),at&&!Je&&u.jsx("div",{className:"text-sm rounded border border-red-200 bg-red-50 px-3 py-2 text-red-600",children:at})]})]}),oe&&u.jsx("div",{className:"mb-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2",children:oe}),u.jsxs("div",{className:"flex items-end gap-2",children:[(a||l)&&u.jsxs(dw,{children:[u.jsx(fw,{asChild:!0,children:u.jsx(Ze,{type:"button",size:"icon",variant:"outline",disabled:_||$,title:"More input actions",className:h.moreButton||"",children:u.jsx(le.Plus,{size:16})})}),u.jsxs(vd,{align:"start",sideOffset:6,className:"w-52",children:[a&&u.jsxs(Xi,{onClick:()=>{var pe;return(pe=De.current)==null?void 0:pe.click()},className:"cursor-pointer",children:[u.jsx(le.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]}),l&&u.jsxs(Xi,{onClick:()=>{var pe;Je||(pe=Re.current)==null||pe.click()},className:`cursor-pointer ${Je?"opacity-60 pointer-events-none":""}`,children:[u.jsx(le.FileSpreadsheet,{className:"h-4 w-4 mr-2"})," Upload Excel file"]})]})]}),u.jsx("div",{className:"flex-1",children:u.jsx(fx,{initialValue:ue,editingMessageId:q,value:Ue,onValueChange:Kt,placeholder:q?"Edit your message...":t,isStreaming:_,disabled:$,maxLength:cs,onSend:Un,onCancelEdit:E,onStop:z,allowEmptySend:Oe.length>0,textareaClassName:`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${q?"border-blue-400 bg-blue-50 text-blue-900 dark:border-blue-500 dark:bg-blue-950/60 dark:text-blue-50":""} ${oe?"border-red-400":""} ${h.textarea||""}`})})]})]})]})}const $s=v.forwardRef(({className:e,type:t,...n},r)=>u.jsx("input",{type:t,className:te("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}));$s.displayName="Input";function _a(e,[t,n]){return Math.min(n,Math.max(t,e))}function aC(e,t){return v.useReducer((n,r)=>t[n][r]??n,e)}var ja="ScrollArea",[hp,ZT]=Cn(ja),[lC,en]=hp(ja),mp=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,type:r="hover",dir:o,scrollHideDelay:s=600,...i}=e,[a,l]=v.useState(null),[c,d]=v.useState(null),[f,h]=v.useState(null),[p,m]=v.useState(null),[g,y]=v.useState(null),[x,b]=v.useState(0),[S,k]=v.useState(0),[C,T]=v.useState(!1),[I,A]=v.useState(!1),N=Be(t,R=>l(R)),L=Ro(o);return u.jsx(lC,{scope:n,type:r,dir:L,scrollHideDelay:s,scrollArea:a,viewport:c,onViewportChange:d,content:f,onContentChange:h,scrollbarX:p,onScrollbarXChange:m,scrollbarXEnabled:C,onScrollbarXEnabledChange:T,scrollbarY:g,onScrollbarYChange:y,scrollbarYEnabled:I,onScrollbarYEnabledChange:A,onCornerWidthChange:b,onCornerHeightChange:k,children:u.jsx(Ne.div,{dir:L,...i,ref:N,style:{position:"relative","--radix-scroll-area-corner-width":x+"px","--radix-scroll-area-corner-height":S+"px",...e.style}})})});mp.displayName=ja;var gp="ScrollAreaViewport",xp=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,i=en(gp,n),a=v.useRef(null),l=Be(t,a,i.onViewportChange);return u.jsxs(u.Fragment,{children:[u.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}),u.jsx(Ne.div,{"data-radix-scroll-area-viewport":"",...s,ref:l,style:{overflowX:i.scrollbarXEnabled?"scroll":"hidden",overflowY:i.scrollbarYEnabled?"scroll":"hidden",...e.style},children:u.jsx("div",{ref:i.onContentChange,style:{minWidth:"100%",display:"table"},children:r})})]})});xp.displayName=gp;var wn="ScrollAreaScrollbar",Ma=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=en(wn,e.__scopeScrollArea),{onScrollbarXEnabledChange:s,onScrollbarYEnabledChange:i}=o,a=e.orientation==="horizontal";return v.useEffect(()=>(a?s(!0):i(!0),()=>{a?s(!1):i(!1)}),[a,s,i]),o.type==="hover"?u.jsx(cC,{...r,ref:t,forceMount:n}):o.type==="scroll"?u.jsx(uC,{...r,ref:t,forceMount:n}):o.type==="auto"?u.jsx(yp,{...r,ref:t,forceMount:n}):o.type==="always"?u.jsx(Ra,{...r,ref:t}):null});Ma.displayName=wn;var cC=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=en(wn,e.__scopeScrollArea),[s,i]=v.useState(!1);return v.useEffect(()=>{const a=o.scrollArea;let l=0;if(a){const c=()=>{window.clearTimeout(l),i(!0)},d=()=>{l=window.setTimeout(()=>i(!1),o.scrollHideDelay)};return a.addEventListener("pointerenter",c),a.addEventListener("pointerleave",d),()=>{window.clearTimeout(l),a.removeEventListener("pointerenter",c),a.removeEventListener("pointerleave",d)}}},[o.scrollArea,o.scrollHideDelay]),u.jsx(Xt,{present:n||s,children:u.jsx(yp,{"data-state":s?"visible":"hidden",...r,ref:t})})}),uC=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=en(wn,e.__scopeScrollArea),s=e.orientation==="horizontal",i=Us(()=>l("SCROLL_END"),100),[a,l]=aC("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 v.useEffect(()=>{if(a==="idle"){const c=window.setTimeout(()=>l("HIDE"),o.scrollHideDelay);return()=>window.clearTimeout(c)}},[a,o.scrollHideDelay,l]),v.useEffect(()=>{const c=o.viewport,d=s?"scrollLeft":"scrollTop";if(c){let f=c[d];const h=()=>{const p=c[d];f!==p&&(l("SCROLL"),i()),f=p};return c.addEventListener("scroll",h),()=>c.removeEventListener("scroll",h)}},[o.viewport,s,l,i]),u.jsx(Xt,{present:n||a!=="hidden",children:u.jsx(Ra,{"data-state":a==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:fe(e.onPointerEnter,()=>l("POINTER_ENTER")),onPointerLeave:fe(e.onPointerLeave,()=>l("POINTER_LEAVE"))})})}),yp=v.forwardRef((e,t)=>{const n=en(wn,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,i]=v.useState(!1),a=e.orientation==="horizontal",l=Us(()=>{if(n.viewport){const c=n.viewport.offsetWidth<n.viewport.scrollWidth,d=n.viewport.offsetHeight<n.viewport.scrollHeight;i(a?c:d)}},10);return kr(n.viewport,l),kr(n.content,l),u.jsx(Xt,{present:r||s,children:u.jsx(Ra,{"data-state":s?"visible":"hidden",...o,ref:t})})}),Ra=v.forwardRef((e,t)=>{const{orientation:n="vertical",...r}=e,o=en(wn,e.__scopeScrollArea),s=v.useRef(null),i=v.useRef(0),[a,l]=v.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),c=Cp(a.viewport,a.content),d={...r,sizes:a,onSizesChange:l,hasThumb:c>0&&c<1,onThumbChange:h=>s.current=h,onThumbPointerUp:()=>i.current=0,onThumbPointerDown:h=>i.current=h};function f(h,p){return gC(h,i.current,a,p)}return n==="horizontal"?u.jsx(dC,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollLeft,p=Tp(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"?u.jsx(fC,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollTop,p=Tp(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}),dC=v.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=en(wn,e.__scopeScrollArea),[i,a]=v.useState(),l=v.useRef(null),c=Be(t,l,s.onScrollbarXChange);return v.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(bp,{"data-orientation":"horizontal",...o,ref:c,sizes:n,style:{bottom:0,left:s.dir==="rtl"?"var(--radix-scroll-area-corner-width)":0,right:s.dir==="ltr"?"var(--radix-scroll-area-corner-width)":0,"--radix-scroll-area-thumb-width":zs(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.x),onDragScroll:d=>e.onDragScroll(d.x),onWheelScroll:(d,f)=>{if(s.viewport){const h=s.viewport.scrollLeft+d.deltaX;e.onWheelScroll(h),Ip(h,f)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollWidth,viewport:s.viewport.offsetWidth,scrollbar:{size:l.current.clientWidth,paddingStart:Bs(i.paddingLeft),paddingEnd:Bs(i.paddingRight)}})}})}),fC=v.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=en(wn,e.__scopeScrollArea),[i,a]=v.useState(),l=v.useRef(null),c=Be(t,l,s.onScrollbarYChange);return v.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(bp,{"data-orientation":"vertical",...o,ref:c,sizes:n,style:{top:0,right:s.dir==="ltr"?0:void 0,left:s.dir==="rtl"?0:void 0,bottom:"var(--radix-scroll-area-corner-height)","--radix-scroll-area-thumb-height":zs(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.y),onDragScroll:d=>e.onDragScroll(d.y),onWheelScroll:(d,f)=>{if(s.viewport){const h=s.viewport.scrollTop+d.deltaY;e.onWheelScroll(h),Ip(h,f)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollHeight,viewport:s.viewport.offsetHeight,scrollbar:{size:l.current.clientHeight,paddingStart:Bs(i.paddingTop),paddingEnd:Bs(i.paddingBottom)}})}})}),[pC,vp]=hp(wn),bp=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,sizes:r,hasThumb:o,onThumbChange:s,onThumbPointerUp:i,onThumbPointerDown:a,onThumbPositionChange:l,onDragScroll:c,onWheelScroll:d,onResize:f,...h}=e,p=en(wn,n),[m,g]=v.useState(null),y=Be(t,N=>g(N)),x=v.useRef(null),b=v.useRef(""),S=p.viewport,k=r.content-r.viewport,C=kt(d),T=kt(l),I=Us(f,10);function A(N){if(x.current){const L=N.clientX-x.current.left,R=N.clientY-x.current.top;c({x:L,y:R})}}return v.useEffect(()=>{const N=L=>{const R=L.target;(m==null?void 0:m.contains(R))&&C(L,k)};return document.addEventListener("wheel",N,{passive:!1}),()=>document.removeEventListener("wheel",N,{passive:!1})},[S,m,k,C]),v.useEffect(T,[r,T]),kr(m,I),kr(p.content,I),u.jsx(pC,{scope:n,scrollbar:m,hasThumb:o,onThumbChange:kt(s),onThumbPointerUp:kt(i),onThumbPositionChange:T,onThumbPointerDown:kt(a),children:u.jsx(Ne.div,{...h,ref:y,style:{position:"absolute",...h.style},onPointerDown:fe(e.onPointerDown,N=>{N.button===0&&(N.target.setPointerCapture(N.pointerId),x.current=m.getBoundingClientRect(),b.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",p.viewport&&(p.viewport.style.scrollBehavior="auto"),A(N))}),onPointerMove:fe(e.onPointerMove,A),onPointerUp:fe(e.onPointerUp,N=>{const L=N.target;L.hasPointerCapture(N.pointerId)&&L.releasePointerCapture(N.pointerId),document.body.style.webkitUserSelect=b.current,p.viewport&&(p.viewport.style.scrollBehavior=""),x.current=null})})})}),Fs="ScrollAreaThumb",wp=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=vp(Fs,e.__scopeScrollArea);return u.jsx(Xt,{present:n||o.hasThumb,children:u.jsx(hC,{ref:t,...r})})}),hC=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=en(Fs,n),i=vp(Fs,n),{onThumbPositionChange:a}=i,l=Be(t,f=>i.onThumbChange(f)),c=v.useRef(void 0),d=Us(()=>{c.current&&(c.current(),c.current=void 0)},100);return v.useEffect(()=>{const f=s.viewport;if(f){const h=()=>{if(d(),!c.current){const p=xC(f,a);c.current=p,a()}};return a(),f.addEventListener("scroll",h),()=>f.removeEventListener("scroll",h)}},[s.viewport,d,a]),u.jsx(Ne.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(),m=f.clientX-p.left,g=f.clientY-p.top;i.onThumbPointerDown({x:m,y:g})}),onPointerUp:fe(e.onPointerUp,i.onThumbPointerUp)})});wp.displayName=Fs;var Pa="ScrollAreaCorner",Sp=v.forwardRef((e,t)=>{const n=en(Pa,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?u.jsx(mC,{...e,ref:t}):null});Sp.displayName=Pa;var mC=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=en(Pa,n),[s,i]=v.useState(0),[a,l]=v.useState(0),c=!!(s&&a);return kr(o.scrollbarX,()=>{var f;const d=((f=o.scrollbarX)==null?void 0:f.offsetHeight)||0;o.onCornerHeightChange(d),l(d)}),kr(o.scrollbarY,()=>{var f;const d=((f=o.scrollbarY)==null?void 0:f.offsetWidth)||0;o.onCornerWidthChange(d),i(d)}),c?u.jsx(Ne.div,{...r,ref:t,style:{width:s,height:a,position:"absolute",right:o.dir==="ltr"?0:void 0,left:o.dir==="rtl"?0:void 0,bottom:0,...e.style}}):null});function Bs(e){return e?parseInt(e,10):0}function Cp(e,t){const n=e/t;return isNaN(n)?0:n}function zs(e){const t=Cp(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function gC(e,t,n,r="ltr"){const o=zs(n),s=o/2,i=t||s,a=o-i,l=n.scrollbar.paddingStart+i,c=n.scrollbar.size-n.scrollbar.paddingEnd-a,d=n.content-n.viewport,f=r==="ltr"?[0,d]:[d*-1,0];return kp([l,c],f)(e)}function Tp(e,t,n="ltr"){const r=zs(t),o=t.scrollbar.paddingStart+t.scrollbar.paddingEnd,s=t.scrollbar.size-o,i=t.content-t.viewport,a=s-r,l=n==="ltr"?[0,i]:[i*-1,0],c=_a(e,l);return kp([0,i],[0,a])(c)}function kp(e,t){return n=>{if(e[0]===e[1]||t[0]===t[1])return t[0];const r=(t[1]-t[0])/(e[1]-e[0]);return t[0]+r*(n-e[0])}}function Ip(e,t){return e>0&&e<t}var xC=(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 Us(e,t){const n=kt(e),r=v.useRef(0);return v.useEffect(()=>()=>window.clearTimeout(r.current),[]),v.useCallback(()=>{window.clearTimeout(r.current),r.current=window.setTimeout(n,t)},[n,t])}function kr(e,t){const n=kt(t);Tt(()=>{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 Ep=mp,yC=xp,vC=Sp;const Ap=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Ep,{ref:r,className:te("relative overflow-hidden",e),...n,children:[u.jsx(yC,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),u.jsx(Np,{}),u.jsx(vC,{})]}));Ap.displayName=Ep.displayName;const Np=v.forwardRef(({className:e,orientation:t="vertical",...n},r)=>u.jsx(Ma,{ref:r,orientation:t,className:te("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:u.jsx(wp,{className:"relative flex-1 rounded-full bg-border"})}));Np.displayName=Ma.displayName;const _p=25;function Oa({className:e="",showCreateButton:t=!0,showDeleteButton:n=!0,showEditTitle:r=!0,maxHeight:o="400px",customStyles:s={},currentThreadId:i=null,navigateToThread:a,onThreadSelect:l,onThreadCreate:c,onThreadDelete:d}){const{threads:f,currentThreadId:h,setCurrentThreadId:p,isLoading:m,actions:g}=_o(),{loadThread:y}=jo(),{createThread:x,deleteThread:b,renameThread:S}=g,[k,C]=w.useState(Array.isArray(f)?f:[]),T=w.useRef(k.length>0),I=w.useRef(null),A=w.useRef(0),[N,L]=w.useState(null),[R,O]=w.useState(""),[F,_]=w.useState(!1);w.useEffect(()=>{const Y=Array.isArray(f)?f:[];if(Y.length>0){T.current=!0,C(Y);return}m||(T.current=!1,C(Y))},[f,m]),w.useEffect(()=>{if(!I.current)return;const Y=I.current.querySelector("[data-radix-scroll-area-viewport]");if(!Y)return;let U=null,J=null;return U=requestAnimationFrame(()=>{J=requestAnimationFrame(()=>{Y.scrollTop=A.current})}),()=>{U!==null&&cancelAnimationFrame(U),J!==null&&cancelAnimationFrame(J)}},[k]);const B=async Y=>{try{p(Y),await y(Y),a==null||a(Y),l==null||l(Y)}catch(U){console.error("Failed to select thread:",U)}},j=async()=>{try{_(!0);const Y=await x();Y&&(c==null||c(Y),a==null||a(Y))}catch(Y){console.error("Failed to create thread:",Y)}finally{_(!1)}},K=async(Y,U)=>{if(U.stopPropagation(),!!confirm("Delete this thread?")){if(I.current){const J=I.current.querySelector("[data-radix-scroll-area-viewport]");J&&(A.current=J.scrollTop)}try{await b(Y),d==null||d(Y)}catch(J){console.error("Failed to delete thread:",J)}}},z=(Y,U)=>{U.stopPropagation(),L(Y.threadId),O(Y.title||`Thread ${Y.threadId.slice(0,8)}`)},M=async Y=>{if(R.trim())try{await S(Y,R.trim()),L(null),O("")}catch(U){console.error("Failed to update title:",U)}},G=()=>{L(null),O("")},X=(Y,U)=>{Y.key==="Enter"?M(U):Y.key==="Escape"&&G()},se=Y=>{if(!Y)return"";try{const U=new Date(Y),$=new Date().getTime()-U.getTime(),q=Math.floor($/(1e3*60*60*24));return q===0?U.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):q===1?"Yesterday":q<7?`${q} days ago`:U.toLocaleDateString()}catch{return""}},be=Y=>Y.title||`Thread ${Y.threadId.slice(0,8)}`,Ie=Y=>{const U=be(Y);return U.length<=_p?U:`${U.slice(0,_p)}...`};return u.jsxs("div",{className:`flex flex-col h-full ${e} ${s.container||""}`,children:[t&&u.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:u.jsx(Ze,{onClick:j,disabled:F||m,className:s.createButton||"p-2",size:"sm",variant:"ghost",title:F?"Creating...":"New Chat",children:u.jsx(le.MessageSquarePlus,{size:20})})}),u.jsx(Ap,{ref:I,className:`flex-1 min-h-0 ${s.threadList||""}`,style:o?{maxHeight:o}:void 0,children:u.jsx("div",{className:"p-2 space-y-1 pb-4",children:m?u.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 py-8 text-slate-400",children:[u.jsx(le.Loader2,{className:"h-5 w-5 animate-spin"}),u.jsx("span",{className:"text-sm",children:"Loading threads…"})]}):k.length===0?u.jsxs("div",{className:"text-center py-8 text-slate-400",children:[u.jsx(le.MessageSquare,{className:"w-8 h-8 mx-auto mb-2 opacity-40 text-slate-500"}),u.jsx("p",{className:"text-sm text-slate-500",children:"No conversations yet"})]}):k.slice().sort((Y,U)=>new Date(U.updatedAt||U.createdAt||"").getTime()-new Date(Y.updatedAt||Y.createdAt||"").getTime()).map(Y=>u.jsxs("div",{onClick:()=>B(Y.threadId),className:`group relative p-3 rounded-lg cursor-pointer transition-colors border ${(i??h)===Y.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:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx("div",{className:"flex-1 min-w-0",children:N===Y.threadId?u.jsxs("div",{className:"flex items-center gap-2",onClick:U=>U.stopPropagation(),children:[u.jsx($s,{value:R,onChange:U=>O(U.target.value),onKeyDown:U=>X(U,Y.threadId),className:"h-6 text-sm",autoFocus:!0}),u.jsx(Ze,{variant:"ghost",size:"sm",onClick:()=>M(Y.threadId),className:"h-6 w-6 p-0",children:u.jsx(le.Check,{size:12})}),u.jsx(Ze,{variant:"ghost",size:"sm",onClick:G,className:"h-6 w-6 p-0",children:u.jsx(le.X,{size:12})})]}):u.jsxs(u.Fragment,{children:[u.jsx("div",{className:"font-medium text-sm truncate text-gray-900 dark:text-slate-100",children:Ie(Y)}),u.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500 dark:text-slate-400 mt-1",children:[u.jsx(le.Calendar,{size:10}),u.jsx("span",{children:se(Y.updatedAt||Y.createdAt)})]})]})}),u.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity ml-2",children:[r&&N!==Y.threadId&&u.jsx(Ze,{variant:"ghost",size:"sm",onClick:U=>z(Y,U),className:"h-6 w-6 p-0",title:"Edit title",children:u.jsx(le.Edit3,{size:12})}),n&&u.jsx(Ze,{variant:"ghost",size:"sm",onClick:U=>K(Y.threadId,U),className:"h-6 w-6 p-0 text-red-400 hover:text-red-300 hover:bg-red-900/20",title:"Delete thread",children:u.jsx(le.Trash2,{size:12})})]})]}),i===Y.threadId&&u.jsx("div",{className:"absolute left-0 top-1/2 -translate-y-1/2 w-1 h-8 bg-blue-400 rounded-r"})]},Y.threadId))})})]})}const bC=({timelineEntries:e,activeCheckpointId:t,onSelectCheckpoint:n,messagePreviews:r,className:o,onHoverStart:s,onHoverEnd:i})=>{const a=e??[],l=a.length>0,c=w.useMemo(()=>l?[...a].reverse():[],[a,l]),d=t??(a.length?a[a.length-1].id:null);if(!l)return null;const h=["w-32 flex-shrink-0 flex-col border-r border-border/40 pr-2 flex bg-white text-gray-900 dark:bg-slate-900 dark:text-slate-100",o].filter(Boolean).join(" ");return u.jsxs("div",{className:h,onMouseEnter:s,onMouseLeave:i,children:[u.jsxs("div",{className:"relative flex-1 overflow-y-auto pt-4 pb-2 pr-1",children:[u.jsx("div",{className:"absolute left-0 right-0 top-1 px-2 pb-3 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground",children:u.jsx("span",{children:"Timeline"})}),u.jsx("div",{className:"pointer-events-none absolute left-3 top-0 bottom-0 w-px bg-border/40"}),u.jsx("div",{className:"flex flex-col gap-3 pt-6 pr-2",children:c.map(p=>{const m=d===p.id,g=(r==null?void 0:r.get(p.id))??null;return u.jsxs("button",{type:"button",disabled:!n,onClick:()=>n==null?void 0:n(p.id),className:`relative flex items-start gap-2 text-left text-[11px] transition ${m?"text-primary":"text-muted-foreground"} ${n?"hover:text-foreground":"cursor-default opacity-70"}`,children:[u.jsx("span",{className:`mt-1 inline-flex h-3 w-3 items-center justify-center rounded-full border ${m?"border-primary bg-primary/10 text-primary":"border-border bg-background"}`,children:u.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${m?"bg-primary":"bg-border"}`})}),u.jsxs("span",{className:"flex-1",children:[u.jsx("span",{className:"block font-medium leading-tight",children:p.label||"User input"}),u.jsxs("span",{className:"text-[9px] uppercase tracking-wide text-muted-foreground/70",children:[p.step!==null?`STEP ${p.step}`:"STEP —",p.next?` - ${p.next}`:""]}),g&&u.jsx("p",{className:"text-[10px] text-muted-foreground/80 mt-1 line-clamp-2",title:g,children:g})]})]},p.id)})})]}),n&&u.jsx("button",{type:"button",onClick:()=>n==null?void 0:n(null),className:"mt-auto mb-3 rounded-md border border-border/70 px-2 py-1 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground transition hover:border-foreground/60 hover:text-foreground",children:"Latest"})]})};function Ir(e){if(!(typeof globalThis>"u"))return globalThis[e]}function wC(e){if(typeof e!="string")return;const t=e.trim();if(t)return Sn(t)}function jp(){const e=[Ir("__API_BASE_URL__"),Ir("__CHAT_API_BASE_URL__"),Ir("__CHAT_API_URL__")];for(const t of e){const n=wC(t);if(n)return n}}function Mp(){const e=[Ir("__API_AUTH_TOKEN__"),Ir("__CHAT_API_KEY__"),Ir("__CHAT_AUTH_TOKEN__")];for(const t of e)if(typeof t=="string"&&t.trim())return t.trim()}function Rp(...e){for(const t of e)if(typeof t=="string"&&t.trim())return Sn(t);return Sn()}function Pp(){const e={},t=jp(),n=Mp();return t&&(e.baseUrl=t),n&&(e.apiKey=n),e}function Op(){const e=Pp(),t=Nn.getAuthToken(),n=jp();return{apiBaseUrl:Rp(e.baseUrl,Nn.baseUrl,n),apiKey:t||e.apiKey||Mp()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,darkMode:!1,enableSound:!1,messageHistory:100}}const Dp="chat-settings";function SC(){try{const e=localStorage.getItem(Dp);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function CC(e){try{const t={...e,apiBaseUrl:Sn(e.apiBaseUrl)};localStorage.setItem(Dp,JSON.stringify(t)),t.apiKey&&Nn.setAuthToken(t.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function TC(){const e=Op(),t=SC(),n=Nn.getAuthToken(),r=typeof t.apiBaseUrl=="string"?t.apiBaseUrl:void 0;return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:Rp(Nn.baseUrl,r,e.apiBaseUrl)}}function kC(e){Nn.updateConfig({baseUrl:e.apiBaseUrl,authToken:e.apiKey??void 0}),CC(e)}var IC="Label",Lp=v.forwardRef((e,t)=>u.jsx(Ne.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())}}));Lp.displayName=IC;var $p=Lp;const EC=po.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),tn=v.forwardRef(({className:e,...t},n)=>u.jsx($p,{ref:n,className:te(EC(),e),...t}));tn.displayName=$p.displayName;function Fp(e){const t=v.useRef({value:e,previous:e});return v.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}var Bp=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"}),AC="VisuallyHidden",NC=v.forwardRef((e,t)=>u.jsx(Ne.span,{...e,ref:t,style:{...Bp,...e.style}}));NC.displayName=AC;var _C=[" ","Enter","ArrowUp","ArrowDown"],jC=[" ","Enter"],or="Select",[Hs,Ws,MC]=mi(or),[Er,QT]=Cn(or,[MC,Ko]),Vs=Ko(),[RC,Fn]=Er(or),[PC,OC]=Er(or),zp=e=>{const{__scopeSelect:t,children:n,open:r,defaultOpen:o,onOpenChange:s,value:i,defaultValue:a,onValueChange:l,dir:c,name:d,autoComplete:f,disabled:h,required:p,form:m}=e,g=Vs(t),[y,x]=v.useState(null),[b,S]=v.useState(null),[k,C]=v.useState(!1),T=Ro(c),[I,A]=pr({prop:r,defaultProp:o??!1,onChange:s,caller:or}),[N,L]=pr({prop:i,defaultProp:a,onChange:l,caller:or}),R=v.useRef(null),O=y?m||!!y.closest("form"):!0,[F,_]=v.useState(new Set),B=Array.from(F).map(j=>j.props.value).join(";");return u.jsx(nu,{...g,children:u.jsxs(RC,{required:p,scope:t,trigger:y,onTriggerChange:x,valueNode:b,onValueNodeChange:S,valueNodeHasChildren:k,onValueNodeHasChildrenChange:C,contentId:Tn(),value:N,onValueChange:L,open:I,onOpenChange:A,dir:T,triggerPointerDownPosRef:R,disabled:h,children:[u.jsx(Hs.Provider,{scope:t,children:u.jsx(PC,{scope:e.__scopeSelect,onNativeOptionAdd:v.useCallback(j=>{_(K=>new Set(K).add(j))},[]),onNativeOptionRemove:v.useCallback(j=>{_(K=>{const z=new Set(K);return z.delete(j),z})},[]),children:n})}),O?u.jsxs(dh,{"aria-hidden":!0,required:p,tabIndex:-1,name:d,autoComplete:f,value:N,onChange:j=>L(j.target.value),disabled:h,form:m,children:[N===void 0?u.jsx("option",{value:""}):null,Array.from(F)]},B):null]})})};zp.displayName=or;var Up="SelectTrigger",Hp=v.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...o}=e,s=Vs(n),i=Fn(Up,n),a=i.disabled||r,l=Be(t,i.onTriggerChange),c=Ws(n),d=v.useRef("touch"),[f,h,p]=ph(g=>{const y=c().filter(S=>!S.disabled),x=y.find(S=>S.value===i.value),b=hh(y,g,x);b!==void 0&&i.onValueChange(b.value)}),m=g=>{a||(i.onOpenChange(!0),p()),g&&(i.triggerPointerDownPosRef.current={x:Math.round(g.pageX),y:Math.round(g.pageY)})};return u.jsx(ru,{asChild:!0,...s,children:u.jsx(Ne.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":fh(i.value)?"":void 0,...o,ref:l,onClick:fe(o.onClick,g=>{g.currentTarget.focus(),d.current!=="mouse"&&m(g)}),onPointerDown:fe(o.onPointerDown,g=>{d.current=g.pointerType;const y=g.target;y.hasPointerCapture(g.pointerId)&&y.releasePointerCapture(g.pointerId),g.button===0&&g.ctrlKey===!1&&g.pointerType==="mouse"&&(m(g),g.preventDefault())}),onKeyDown:fe(o.onKeyDown,g=>{const y=f.current!=="";!(g.ctrlKey||g.altKey||g.metaKey)&&g.key.length===1&&h(g.key),!(y&&g.key===" ")&&_C.includes(g.key)&&(m(),g.preventDefault())})})})});Hp.displayName=Up;var Wp="SelectValue",Vp=v.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,children:s,placeholder:i="",...a}=e,l=Fn(Wp,n),{onValueNodeHasChildrenChange:c}=l,d=s!==void 0,f=Be(t,l.onValueNodeChange);return Tt(()=>{c(d)},[c,d]),u.jsx(Ne.span,{...a,ref:f,style:{pointerEvents:"none"},children:fh(l.value)?u.jsx(u.Fragment,{children:i}):s})});Vp.displayName=Wp;var DC="SelectIcon",Kp=v.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...o}=e;return u.jsx(Ne.span,{"aria-hidden":!0,...o,ref:t,children:r||"▼"})});Kp.displayName=DC;var LC="SelectPortal",qp=e=>u.jsx(qo,{asChild:!0,...e});qp.displayName=LC;var sr="SelectContent",Gp=v.forwardRef((e,t)=>{const n=Fn(sr,e.__scopeSelect),[r,o]=v.useState();if(Tt(()=>{o(new DocumentFragment)},[]),!n.open){const s=r;return s?ho.createPortal(u.jsx(Yp,{scope:e.__scopeSelect,children:u.jsx(Hs.Slot,{scope:e.__scopeSelect,children:u.jsx("div",{children:e.children})})}),s):null}return u.jsx(Xp,{...e,ref:t})});Gp.displayName=sr;var un=10,[Yp,Bn]=Er(sr),$C="SelectContentImpl",FC=Wn.createSlot("SelectContent.RemoveScroll"),Xp=v.forwardRef((e,t)=>{const{__scopeSelect:n,position:r="item-aligned",onCloseAutoFocus:o,onEscapeKeyDown:s,onPointerDownOutside:i,side:a,sideOffset:l,align:c,alignOffset:d,arrowPadding:f,collisionBoundary:h,collisionPadding:p,sticky:m,hideWhenDetached:g,avoidCollisions:y,...x}=e,b=Fn(sr,n),[S,k]=v.useState(null),[C,T]=v.useState(null),I=Be(t,J=>k(J)),[A,N]=v.useState(null),[L,R]=v.useState(null),O=Ws(n),[F,_]=v.useState(!1),B=v.useRef(!1);v.useEffect(()=>{if(S)return Li(S)},[S]),yi();const j=v.useCallback(J=>{const[$,...q]=O().map(ie=>ie.ref.current),[Z]=q.slice(-1),ue=document.activeElement;for(const ie of J)if(ie===ue||(ie==null||ie.scrollIntoView({block:"nearest"}),ie===$&&C&&(C.scrollTop=0),ie===Z&&C&&(C.scrollTop=C.scrollHeight),ie==null||ie.focus(),document.activeElement!==ue))return},[O,C]),K=v.useCallback(()=>j([A,S]),[j,A,S]);v.useEffect(()=>{F&&K()},[F,K]);const{onOpenChange:z,triggerPointerDownPosRef:M}=b;v.useEffect(()=>{if(S){let J={x:0,y:0};const $=Z=>{var ue,ie;J={x:Math.abs(Math.round(Z.pageX)-(((ue=M.current)==null?void 0:ue.x)??0)),y:Math.abs(Math.round(Z.pageY)-(((ie=M.current)==null?void 0:ie.y)??0))}},q=Z=>{J.x<=10&&J.y<=10?Z.preventDefault():S.contains(Z.target)||z(!1),document.removeEventListener("pointermove",$),M.current=null};return M.current!==null&&(document.addEventListener("pointermove",$),document.addEventListener("pointerup",q,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",$),document.removeEventListener("pointerup",q,{capture:!0})}}},[S,z,M]),v.useEffect(()=>{const J=()=>z(!1);return window.addEventListener("blur",J),window.addEventListener("resize",J),()=>{window.removeEventListener("blur",J),window.removeEventListener("resize",J)}},[z]);const[G,X]=ph(J=>{const $=O().filter(ue=>!ue.disabled),q=$.find(ue=>ue.ref.current===document.activeElement),Z=hh($,J,q);Z&&setTimeout(()=>Z.ref.current.focus())}),se=v.useCallback((J,$,q)=>{const Z=!B.current&&!q;(b.value!==void 0&&b.value===$||Z)&&(N(J),Z&&(B.current=!0))},[b.value]),be=v.useCallback(()=>S==null?void 0:S.focus(),[S]),Ie=v.useCallback((J,$,q)=>{const Z=!B.current&&!q;(b.value!==void 0&&b.value===$||Z)&&R(J)},[b.value]),Y=r==="popper"?Da:Jp,U=Y===Da?{side:a,sideOffset:l,align:c,alignOffset:d,arrowPadding:f,collisionBoundary:h,collisionPadding:p,sticky:m,hideWhenDetached:g,avoidCollisions:y}:{};return u.jsx(Yp,{scope:n,content:S,viewport:C,onViewportChange:T,itemRefCallback:se,selectedItem:A,onItemLeave:be,itemTextRefCallback:Ie,focusSelectedItem:K,selectedItemText:L,position:r,isPositioned:F,searchRef:G,children:u.jsx(ns,{as:FC,allowPinchZoom:!0,children:u.jsx(Oo,{asChild:!0,trapped:b.open,onMountAutoFocus:J=>{J.preventDefault()},onUnmountAutoFocus:fe(o,J=>{var $;($=b.trigger)==null||$.focus({preventScroll:!0}),J.preventDefault()}),children:u.jsx(Po,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:J=>J.preventDefault(),onDismiss:()=>b.onOpenChange(!1),children:u.jsx(Y,{role:"listbox",id:b.contentId,"data-state":b.open?"open":"closed",dir:b.dir,onContextMenu:J=>J.preventDefault(),...x,...U,onPlaced:()=>_(!0),ref:I,style:{display:"flex",flexDirection:"column",outline:"none",...x.style},onKeyDown:fe(x.onKeyDown,J=>{const $=J.ctrlKey||J.altKey||J.metaKey;if(J.key==="Tab"&&J.preventDefault(),!$&&J.key.length===1&&X(J.key),["ArrowUp","ArrowDown","Home","End"].includes(J.key)){let Z=O().filter(ue=>!ue.disabled).map(ue=>ue.ref.current);if(["ArrowUp","End"].includes(J.key)&&(Z=Z.slice().reverse()),["ArrowUp","ArrowDown"].includes(J.key)){const ue=J.target,ie=Z.indexOf(ue);Z=Z.slice(ie+1)}setTimeout(()=>j(Z)),J.preventDefault()}})})})})})})});Xp.displayName=$C;var BC="SelectItemAlignedPosition",Jp=v.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...o}=e,s=Fn(sr,n),i=Bn(sr,n),[a,l]=v.useState(null),[c,d]=v.useState(null),f=Be(t,I=>d(I)),h=Ws(n),p=v.useRef(!1),m=v.useRef(!0),{viewport:g,selectedItem:y,selectedItemText:x,focusSelectedItem:b}=i,S=v.useCallback(()=>{if(s.trigger&&s.valueNode&&a&&c&&g&&y&&x){const I=s.trigger.getBoundingClientRect(),A=c.getBoundingClientRect(),N=s.valueNode.getBoundingClientRect(),L=x.getBoundingClientRect();if(s.dir!=="rtl"){const ue=L.left-A.left,ie=N.left-ue,_e=I.left-ie,He=I.width+_e,oe=Math.max(He,A.width),ye=window.innerWidth-un,Oe=_a(ie,[un,Math.max(un,ye-oe)]);a.style.minWidth=He+"px",a.style.left=Oe+"px"}else{const ue=A.right-L.right,ie=window.innerWidth-N.right-ue,_e=window.innerWidth-I.right-ie,He=I.width+_e,oe=Math.max(He,A.width),ye=window.innerWidth-un,Oe=_a(ie,[un,Math.max(un,ye-oe)]);a.style.minWidth=He+"px",a.style.right=Oe+"px"}const R=h(),O=window.innerHeight-un*2,F=g.scrollHeight,_=window.getComputedStyle(c),B=parseInt(_.borderTopWidth,10),j=parseInt(_.paddingTop,10),K=parseInt(_.borderBottomWidth,10),z=parseInt(_.paddingBottom,10),M=B+j+F+z+K,G=Math.min(y.offsetHeight*5,M),X=window.getComputedStyle(g),se=parseInt(X.paddingTop,10),be=parseInt(X.paddingBottom,10),Ie=I.top+I.height/2-un,Y=O-Ie,U=y.offsetHeight/2,J=y.offsetTop+U,$=B+j+J,q=M-$;if($<=Ie){const ue=R.length>0&&y===R[R.length-1].ref.current;a.style.bottom="0px";const ie=c.clientHeight-g.offsetTop-g.offsetHeight,_e=Math.max(Y,U+(ue?be:0)+ie+K),He=$+_e;a.style.height=He+"px"}else{const ue=R.length>0&&y===R[0].ref.current;a.style.top="0px";const _e=Math.max(Ie,B+g.offsetTop+(ue?se:0)+U)+q;a.style.height=_e+"px",g.scrollTop=$-Ie+g.offsetTop}a.style.margin=`${un}px 0`,a.style.minHeight=G+"px",a.style.maxHeight=O+"px",r==null||r(),requestAnimationFrame(()=>p.current=!0)}},[h,s.trigger,s.valueNode,a,c,g,y,x,s.dir,r]);Tt(()=>S(),[S]);const[k,C]=v.useState();Tt(()=>{c&&C(window.getComputedStyle(c).zIndex)},[c]);const T=v.useCallback(I=>{I&&m.current===!0&&(S(),b==null||b(),m.current=!1)},[S,b]);return u.jsx(UC,{scope:n,contentWrapper:a,shouldExpandOnScrollRef:p,onScrollButtonChange:T,children:u.jsx("div",{ref:l,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:k},children:u.jsx(Ne.div,{...o,ref:f,style:{boxSizing:"border-box",maxHeight:"100%",...o.style}})})})});Jp.displayName=BC;var zC="SelectPopperPosition",Da=v.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=un,...s}=e,i=Vs(n);return u.jsx(ou,{...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)"}})});Da.displayName=zC;var[UC,La]=Er(sr,{}),$a="SelectViewport",Zp=v.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...o}=e,s=Bn($a,n),i=La($a,n),a=Be(t,s.onViewportChange),l=v.useRef(0);return u.jsxs(u.Fragment,{children:[u.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}),u.jsx(Hs.Slot,{scope:n,children:u.jsx(Ne.div,{"data-radix-select-viewport":"",role:"presentation",...o,ref:a,style:{position:"relative",flex:1,overflow:"hidden auto",...o.style},onScroll:fe(o.onScroll,c=>{const d=c.currentTarget,{contentWrapper:f,shouldExpandOnScrollRef:h}=i;if(h!=null&&h.current&&f){const p=Math.abs(l.current-d.scrollTop);if(p>0){const m=window.innerHeight-un*2,g=parseFloat(f.style.minHeight),y=parseFloat(f.style.height),x=Math.max(g,y);if(x<m){const b=x+p,S=Math.min(m,b),k=b-S;f.style.height=S+"px",f.style.bottom==="0px"&&(d.scrollTop=k>0?k:0,f.style.justifyContent="flex-end")}}}l.current=d.scrollTop})})})]})});Zp.displayName=$a;var Qp="SelectGroup",[HC,WC]=Er(Qp),VC=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Tn();return u.jsx(HC,{scope:n,id:o,children:u.jsx(Ne.div,{role:"group","aria-labelledby":o,...r,ref:t})})});VC.displayName=Qp;var eh="SelectLabel",th=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=WC(eh,n);return u.jsx(Ne.div,{id:o.id,...r,ref:t})});th.displayName=eh;var Ks="SelectItem",[KC,nh]=Er(Ks),rh=v.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:s,...i}=e,a=Fn(Ks,n),l=Bn(Ks,n),c=a.value===r,[d,f]=v.useState(s??""),[h,p]=v.useState(!1),m=Be(t,b=>{var S;return(S=l.itemRefCallback)==null?void 0:S.call(l,b,r,o)}),g=Tn(),y=v.useRef("touch"),x=()=>{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 u.jsx(KC,{scope:n,value:r,disabled:o,textId:g,isSelected:c,onItemTextChange:v.useCallback(b=>{f(S=>S||((b==null?void 0:b.textContent)??"").trim())},[]),children:u.jsx(Hs.ItemSlot,{scope:n,value:r,disabled:o,textValue:d,children:u.jsx(Ne.div,{role:"option","aria-labelledby":g,"data-highlighted":h?"":void 0,"aria-selected":c&&h,"data-state":c?"checked":"unchecked","aria-disabled":o||void 0,"data-disabled":o?"":void 0,tabIndex:o?void 0:-1,...i,ref:m,onFocus:fe(i.onFocus,()=>p(!0)),onBlur:fe(i.onBlur,()=>p(!1)),onClick:fe(i.onClick,()=>{y.current!=="mouse"&&x()}),onPointerUp:fe(i.onPointerUp,()=>{y.current==="mouse"&&x()}),onPointerDown:fe(i.onPointerDown,b=>{y.current=b.pointerType}),onPointerMove:fe(i.onPointerMove,b=>{var S;y.current=b.pointerType,o?(S=l.onItemLeave)==null||S.call(l):y.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 k;((k=l.searchRef)==null?void 0:k.current)!==""&&b.key===" "||(jC.includes(b.key)&&x(),b.key===" "&&b.preventDefault())})})})})});rh.displayName=Ks;var uo="SelectItemText",oh=v.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,...s}=e,i=Fn(uo,n),a=Bn(uo,n),l=nh(uo,n),c=OC(uo,n),[d,f]=v.useState(null),h=Be(t,x=>f(x),l.onItemTextChange,x=>{var b;return(b=a.itemTextRefCallback)==null?void 0:b.call(a,x,l.value,l.disabled)}),p=d==null?void 0:d.textContent,m=v.useMemo(()=>u.jsx("option",{value:l.value,disabled:l.disabled,children:p},l.value),[l.disabled,l.value,p]),{onNativeOptionAdd:g,onNativeOptionRemove:y}=c;return Tt(()=>(g(m),()=>y(m)),[g,y,m]),u.jsxs(u.Fragment,{children:[u.jsx(Ne.span,{id:l.textId,...s,ref:h}),l.isSelected&&i.valueNode&&!i.valueNodeHasChildren?ho.createPortal(s.children,i.valueNode):null]})});oh.displayName=uo;var sh="SelectItemIndicator",ih=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return nh(sh,n).isSelected?u.jsx(Ne.span,{"aria-hidden":!0,...r,ref:t}):null});ih.displayName=sh;var Fa="SelectScrollUpButton",ah=v.forwardRef((e,t)=>{const n=Bn(Fa,e.__scopeSelect),r=La(Fa,e.__scopeSelect),[o,s]=v.useState(!1),i=Be(t,r.onScrollButtonChange);return Tt(()=>{if(n.viewport&&n.isPositioned){let a=function(){const c=l.scrollTop>0;s(c)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?u.jsx(ch,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop-l.offsetHeight)}}):null});ah.displayName=Fa;var Ba="SelectScrollDownButton",lh=v.forwardRef((e,t)=>{const n=Bn(Ba,e.__scopeSelect),r=La(Ba,e.__scopeSelect),[o,s]=v.useState(!1),i=Be(t,r.onScrollButtonChange);return Tt(()=>{if(n.viewport&&n.isPositioned){let a=function(){const c=l.scrollHeight-l.clientHeight,d=Math.ceil(l.scrollTop)<c;s(d)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?u.jsx(ch,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop+l.offsetHeight)}}):null});lh.displayName=Ba;var ch=v.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...o}=e,s=Bn("SelectScrollButton",n),i=v.useRef(null),a=Ws(n),l=v.useCallback(()=>{i.current!==null&&(window.clearInterval(i.current),i.current=null)},[]);return v.useEffect(()=>()=>l(),[l]),Tt(()=>{var d;const c=a().find(f=>f.ref.current===document.activeElement);(d=c==null?void 0:c.ref.current)==null||d.scrollIntoView({block:"nearest"})},[a]),u.jsx(Ne.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 c;(c=s.onItemLeave)==null||c.call(s),i.current===null&&(i.current=window.setInterval(r,50))}),onPointerLeave:fe(o.onPointerLeave,()=>{l()})})}),qC="SelectSeparator",uh=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return u.jsx(Ne.div,{"aria-hidden":!0,...r,ref:t})});uh.displayName=qC;var za="SelectArrow",GC=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Vs(n),s=Fn(za,n),i=Bn(za,n);return s.open&&i.position==="popper"?u.jsx(su,{...o,...r,ref:t}):null});GC.displayName=za;var YC="SelectBubbleInput",dh=v.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const o=v.useRef(null),s=Be(r,o),i=Fp(t);return v.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]),u.jsx(Ne.select,{...n,style:{...Bp,...n.style},ref:s,defaultValue:t})});dh.displayName=YC;function fh(e){return e===""||e===void 0}function ph(e){const t=kt(e),n=v.useRef(""),r=v.useRef(0),o=v.useCallback(i=>{const a=n.current+i;t(a),function l(c){n.current=c,window.clearTimeout(r.current),c!==""&&(r.current=window.setTimeout(()=>l(""),1e3))}(a)},[t]),s=v.useCallback(()=>{n.current="",window.clearTimeout(r.current)},[]);return v.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,o,s]}function hh(e,t,n){const o=t.length>1&&Array.from(t).every(c=>c===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let i=XC(e,Math.max(s,0));o.length===1&&(i=i.filter(c=>c!==n));const l=i.find(c=>c.textValue.toLowerCase().startsWith(o.toLowerCase()));return l!==n?l:void 0}function XC(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var JC=zp,mh=Hp,ZC=Vp,QC=Kp,eT=qp,gh=Gp,tT=Zp,xh=th,yh=rh,nT=oh,rT=ih,vh=ah,bh=lh,wh=uh;const Sh=JC,Ch=ZC,Ua=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(mh,{ref:r,className:te("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,u.jsx(QC,{asChild:!0,children:u.jsx(le.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));Ua.displayName=mh.displayName;const Th=v.forwardRef(({className:e,...t},n)=>u.jsx(vh,{ref:n,className:te("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(le.ChevronUp,{className:"h-4 w-4"})}));Th.displayName=vh.displayName;const kh=v.forwardRef(({className:e,...t},n)=>u.jsx(bh,{ref:n,className:te("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(le.ChevronDown,{className:"h-4 w-4"})}));kh.displayName=bh.displayName;const Ha=v.forwardRef(({className:e,children:t,position:n="popper",...r},o)=>u.jsx(eT,{children:u.jsxs(gh,{ref:o,className:te("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:[u.jsx(Th,{}),u.jsx(tT,{className:te("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),u.jsx(kh,{})]})}));Ha.displayName=gh.displayName;const oT=v.forwardRef(({className:e,...t},n)=>u.jsx(xh,{ref:n,className:te("py-1.5 pl-8 pr-2 text-sm font-semibold",e),...t}));oT.displayName=xh.displayName;const ir=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(yh,{ref:r,className:te("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:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(rT,{children:u.jsx(le.Check,{className:"h-4 w-4"})})}),u.jsx(nT,{children:t})]}));ir.displayName=yh.displayName;const sT=v.forwardRef(({className:e,...t},n)=>u.jsx(wh,{ref:n,className:te("-mx-1 my-1 h-px bg-muted",e),...t}));sT.displayName=wh.displayName;var iT="Separator",Ih="horizontal",aT=["horizontal","vertical"],Eh=v.forwardRef((e,t)=>{const{decorative:n,orientation:r=Ih,...o}=e,s=lT(r)?r:Ih,a=n?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return u.jsx(Ne.div,{"data-orientation":s,...a,...o,ref:t})});Eh.displayName=iT;function lT(e){return aT.includes(e)}var Ah=Eh;const Nh=v.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},o)=>u.jsx(Ah,{ref:o,decorative:n,orientation:t,className:te("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));Nh.displayName=Ah.displayName;const cT=zf,uT=bS,dT=Uf,_h=v.forwardRef(({className:e,...t},n)=>u.jsx(Es,{className:te("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}));_h.displayName=Es.displayName;const fT=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"}}),jh=v.forwardRef(({side:e="right",className:t,children:n,...r},o)=>u.jsxs(dT,{children:[u.jsx(_h,{}),u.jsxs(As,{ref:o,className:te(fT({side:e}),t),...r,children:[n,u.jsxs(Hf,{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:[u.jsx(le.X,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));jh.displayName=As.displayName;const Mh=({className:e,...t})=>u.jsx("div",{className:te("flex flex-col space-y-2 text-center sm:text-left",e),...t});Mh.displayName="SheetHeader";const Rh=v.forwardRef(({className:e,...t},n)=>u.jsx(nr,{ref:n,className:te("text-lg font-semibold text-foreground",e),...t}));Rh.displayName=nr.displayName;const Ph=v.forwardRef(({className:e,...t},n)=>u.jsx(Ns,{ref:n,className:te("text-sm text-muted-foreground",e),...t}));Ph.displayName=Ns.displayName;var qs="Switch",[pT,ek]=Cn(qs),[hT,mT]=pT(qs),Oh=v.forwardRef((e,t)=>{const{__scopeSwitch:n,name:r,checked:o,defaultChecked:s,required:i,disabled:a,value:l="on",onCheckedChange:c,form:d,...f}=e,[h,p]=v.useState(null),m=Be(t,S=>p(S)),g=v.useRef(!1),y=h?d||!!h.closest("form"):!0,[x,b]=pr({prop:o,defaultProp:s??!1,onChange:c,caller:qs});return u.jsxs(hT,{scope:n,checked:x,disabled:a,children:[u.jsx(Ne.button,{type:"button",role:"switch","aria-checked":x,"aria-required":i,"data-state":Fh(x),"data-disabled":a?"":void 0,disabled:a,value:l,...f,ref:m,onClick:fe(e.onClick,S=>{b(k=>!k),y&&(g.current=S.isPropagationStopped(),g.current||S.stopPropagation())})}),y&&u.jsx($h,{control:h,bubbles:!g.current,name:r,value:l,checked:x,required:i,disabled:a,form:d,style:{transform:"translateX(-100%)"}})]})});Oh.displayName=qs;var Dh="SwitchThumb",Lh=v.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,o=mT(Dh,n);return u.jsx(Ne.span,{"data-state":Fh(o.checked),"data-disabled":o.disabled?"":void 0,...r,ref:t})});Lh.displayName=Dh;var gT="SwitchBubbleInput",$h=v.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...o},s)=>{const i=v.useRef(null),a=Be(i,s),l=Fp(n),c=Kc(t);return v.useEffect(()=>{const d=i.current;if(!d)return;const f=window.HTMLInputElement.prototype,p=Object.getOwnPropertyDescriptor(f,"checked").set;if(l!==n&&p){const m=new Event("click",{bubbles:r});p.call(d,n),d.dispatchEvent(m)}},[l,n,r]),u.jsx("input",{type:"checkbox","aria-hidden":!0,defaultChecked:n,...o,tabIndex:-1,ref:a,style:{...o.style,...c,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});$h.displayName=gT;function Fh(e){return e?"checked":"unchecked"}var Bh=Oh,xT=Lh;const zn=v.forwardRef(({className:e,...t},n)=>u.jsx(Bh,{className:te("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:u.jsx(xT,{className:te("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=Bh.displayName;const yT={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 vT({settings:e,onSettingsChange:t,className:n=""}){const[r,o]=w.useState(!1),[s,i]=w.useState(!1),[a,l]=w.useState(e),[c,d]=w.useState(!1),{toast:f}=Ia();w.useEffect(()=>{const y=JSON.stringify(a)!==JSON.stringify(e);d(y)},[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(yT),d(!0),f({title:"Settings reset",description:"Configuration has been reset to defaults."})},m=()=>{l(e),d(!1),o(!1)},g=async()=>{try{const x=await(await fetch(`${a.api.baseUrl}/health`)).json();f({title:"Connection successful",description:`API is ${x.status||"healthy"}`})}catch{f({title:"Connection failed",description:"Unable to connect to the API endpoint.",variant:"destructive"})}};return u.jsxs(cT,{open:r,onOpenChange:o,children:[u.jsx(uT,{asChild:!0,children:u.jsxs(Ze,{variant:"outline",size:"sm",className:n,children:[u.jsx(le.Settings,{className:"h-4 w-4 mr-2"}),"Settings",c&&u.jsx(vf,{variant:"destructive",className:"ml-2 h-4 w-4 p-0"})]})}),u.jsxs(jh,{className:"w-[500px] sm:w-[600px] overflow-y-auto",children:[u.jsxs(Mh,{children:[u.jsx(Rh,{children:"Chat Settings"}),u.jsx(Ph,{children:"Configure your chat interface, API connection, and behavior preferences."})]}),u.jsxs("div",{className:"space-y-6 py-6",children:[u.jsxs(io,{children:[u.jsx(ao,{className:"pb-3",children:u.jsxs(lo,{className:"text-lg flex items-center gap-2",children:[u.jsx(le.Server,{className:"h-5 w-5"}),"API Configuration"]})}),u.jsxs(co,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(tn,{htmlFor:"api-url",children:"API Base URL"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx($s,{id:"api-url",value:a.api.baseUrl,onChange:y=>l(x=>({...x,api:{...x.api,baseUrl:y.target.value}})),placeholder:"http://localhost:8000/api"}),u.jsx(Ze,{variant:"outline",onClick:g,children:"Test"})]})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(tn,{htmlFor:"enable-auth",children:"Enable Authentication"}),u.jsx(zn,{id:"enable-auth",checked:a.api.enableAuth,onCheckedChange:y=>l(x=>({...x,api:{...x.api,enableAuth:y}}))})]}),a.api.enableAuth&&u.jsxs("div",{className:"space-y-2",children:[u.jsx(tn,{htmlFor:"auth-token",children:"Authentication Token"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx($s,{id:"auth-token",type:s?"text":"password",value:a.api.authToken,onChange:y=>l(x=>({...x,api:{...x.api,authToken:y.target.value}})),placeholder:"Enter your Bearer token"}),u.jsx(Ze,{variant:"outline",size:"icon",onClick:()=>i(!s),children:s?u.jsx(le.EyeOff,{className:"h-4 w-4"}):u.jsx(le.Eye,{className:"h-4 w-4"})})]})]})]})]}),u.jsxs(io,{children:[u.jsx(ao,{className:"pb-3",children:u.jsxs(lo,{className:"text-lg flex items-center gap-2",children:[u.jsx(le.Layout,{className:"h-5 w-5"}),"Interface Settings"]})}),u.jsxs(co,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(tn,{htmlFor:"layout",children:"Layout Style"}),u.jsxs(Sh,{value:a.ui.layout,onValueChange:y=>l(x=>({...x,ui:{...x.ui,layout:y}})),children:[u.jsx(Ua,{children:u.jsx(Ch,{})}),u.jsxs(Ha,{children:[u.jsx(ir,{value:"sidebar",children:"Sidebar Layout"}),u.jsx(ir,{value:"fullscreen",children:"Fullscreen"}),u.jsx(ir,{value:"tabs",children:"Tabbed Interface"})]})]})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx(tn,{htmlFor:"theme",children:"Theme"}),u.jsxs(Sh,{value:a.ui.theme,onValueChange:y=>l(x=>({...x,ui:{...x.ui,theme:y}})),children:[u.jsx(Ua,{children:u.jsx(Ch,{})}),u.jsxs(Ha,{children:[u.jsx(ir,{value:"light",children:"Light"}),u.jsx(ir,{value:"dark",children:"Dark"}),u.jsx(ir,{value:"system",children:"System"})]})]})]}),u.jsx(Nh,{}),u.jsxs("div",{className:"space-y-3",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(tn,{htmlFor:"show-timestamps",children:"Show Timestamps"}),u.jsx(zn,{id:"show-timestamps",checked:a.ui.showTimestamps,onCheckedChange:y=>l(x=>({...x,ui:{...x.ui,showTimestamps:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(tn,{htmlFor:"show-agent-names",children:"Show Agent Names"}),u.jsx(zn,{id:"show-agent-names",checked:a.ui.showAgentNames,onCheckedChange:y=>l(x=>({...x,ui:{...x.ui,showAgentNames:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(tn,{htmlFor:"compact-messages",children:"Compact Messages"}),u.jsx(zn,{id:"compact-messages",checked:a.ui.compactMessages,onCheckedChange:y=>l(x=>({...x,ui:{...x.ui,compactMessages:y}}))})]})]})]})]}),u.jsxs(io,{children:[u.jsx(ao,{className:"pb-3",children:u.jsxs(lo,{className:"text-lg flex items-center gap-2",children:[u.jsx(le.MessageCircle,{className:"h-5 w-5"}),"Behavior Settings"]})}),u.jsxs(co,{className:"space-y-4",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(tn,{htmlFor:"auto-save",children:"Auto-save Conversations"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Automatically save messages to threads"})]}),u.jsx(zn,{id:"auto-save",checked:a.behavior.autoSave,onCheckedChange:y=>l(x=>({...x,behavior:{...x.behavior,autoSave:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(tn,{htmlFor:"enable-streaming",children:"Enable Streaming"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Stream responses in real-time"})]}),u.jsx(zn,{id:"enable-streaming",checked:a.behavior.enableStreaming,onCheckedChange:y=>l(x=>({...x,behavior:{...x.behavior,enableStreaming:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(tn,{htmlFor:"typing-indicator",children:"Typing Indicator"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Show typing indicator during responses"})]}),u.jsx(zn,{id:"typing-indicator",checked:a.behavior.showTypingIndicator,onCheckedChange:y=>l(x=>({...x,behavior:{...x.behavior,showTypingIndicator:y}}))})]})]})]})]}),u.jsxs("div",{className:"flex items-center justify-between pt-6 border-t",children:[u.jsxs(Ze,{variant:"outline",onClick:p,children:[u.jsx(le.RotateCcw,{className:"h-4 w-4 mr-2"}),"Reset"]}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(Ze,{variant:"outline",onClick:m,children:"Cancel"}),u.jsxs(Ze,{onClick:h,disabled:!c,children:[u.jsx(le.Save,{className:"h-4 w-4 mr-2"}),"Save Changes"]})]})]})]})]})}function bT({layout:e="sidebar",layoutSize:t="desktop",showThreads:n=!0,className:r="",customStyles:o={},...s}){const i=c=>{const d="h-full";switch(c){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=c=>({"--chat-sidebar-width":c==="phone"?"100%":c==="tablet"?"280px":c==="half-screen"?"240px":"320px","--chat-message-max-width":c==="phone"?"95%":c==="tablet"?"90%":c==="half-screen"?"85%":"80%","--chat-input-height":c==="phone"?"120px":"100px"}),l=w.useCallback(c=>{var d;(d=s.onThreadChange)==null||d.call(s,c)},[s]);return e==="fullscreen"?u.jsx(Mo,{...s,onThreadChange:l,children:u.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:u.jsx(Ls,{className:"flex-1",onError:s.onError,enableFileUpload:!0})})}):e==="tabs"?u.jsx(Mo,{...s,onThreadChange:l,children:u.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:u.jsxs("div",{className:"flex-1 flex min-h-0 overflow-hidden",children:[n&&u.jsx("div",{className:`w-80 border-r flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:u.jsx(Oa,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),u.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:u.jsx(Ls,{onError:s.onError,enableFileUpload:!0})})]})})}):u.jsx(Mo,{...s,onThreadChange:l,children:u.jsxs("div",{className:`${i(t)} flex overflow-hidden ${r} ${o.container||""}`,style:a(t),children:[n&&u.jsx("div",{className:`w-80 border-r bg-gray-50 flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:u.jsx(Oa,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),u.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:u.jsx(Ls,{onError:s.onError,enableFileUpload:!0})})]})})}Ce.ChatApi=$l,Ce.ChatInput=uc,Ce.ChatInterface=Ls,Ce.ChatProviders=Mo,Ce.ChatSettings=vT,Ce.MarkdownContent=so,Ce.MessageComponent=Ds,Ce.MessageList=Na,Ce.ThreadManager=Oa,Ce.TimelineColumn=bC,Ce.applySettings=kC,Ce.buildMessagePreviewMap=Hg,Ce.chatApiClient=Nn,Ce.default=bT,Ce.del=Ll,Ce.get=Gt,Ce.getChatToken=Pl,Ce.getCurrentSettings=TC,Ce.getDefaultApiConfig=Pp,Ce.getDefaultChatSettings=Op,Ce.onChatTokenChanged=Ol,Ce.post=ci,Ce.put=Dl,Ce.setChatToken=Io,Ce.useApi=ui,Ce.useChatStream=ql,Ce.useMessagesReducer=Yl,Ce.useStream=lc,Ce.useThreadState=jo,Ce.useThreads=_o,Object.defineProperties(Ce,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|