teodor-new-chat-ui 4.3.353 → 4.3.355
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/chat/message-components/StreamProgress.d.ts +7 -0
- package/dist/components/chat/message-components/ToolComponent.d.ts +2 -1
- package/dist/components/chat/message-components/index.d.ts +1 -1
- package/dist/components/ui/resizable.d.ts +1 -1
- package/dist/context/providers/ChatSessionProvider.d.ts +3 -1
- package/dist/context/reducers/MessageReducer.d.ts +1 -19
- package/dist/index.esm.js +2717 -2670
- package/dist/index.umd.js +34 -34
- package/dist/lib/toolProgressStorage.d.ts +8 -0
- package/dist/types/context.d.ts +0 -2
- package/dist/types/events.d.ts +0 -9
- package/dist/types/toolStream.d.ts +11 -0
- package/package.json +1 -1
- package/dist/components/chat/message-components/StreamComponent.d.ts +0 -8
package/dist/index.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(Se,
|
|
1
|
+
(function(Se,b){typeof exports=="object"&&typeof module<"u"?b(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"],b):(Se=typeof globalThis<"u"?globalThis:Se||self,b(Se.NewChatUI={},Se.React,Se.LucideReact,Se.reactSlot,Se.classVarianceAuthority,Se.clsx,Se.tailwindMerge,Se.ReactDOM))})(this,function(Se,b,le,Vn,ho,Yh,Xh,Ys){"use strict";var LT=Object.defineProperty;var $T=(Se,b,le)=>b in Se?LT(Se,b,{enumerable:!0,configurable:!0,writable:!0,value:le}):Se[b]=le;var qh=(Se,b,le)=>$T(Se,typeof b!="symbol"?b+"":b,le);var Xs=typeof document<"u"?document.currentScript:null;function Ka(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=Ka(b),mo=Ka(Ys);var Js={exports:{}},_r={};/**
|
|
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 qa;function Jh(){if(qa)return _r;qa=1;var e=b,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={},p=null,h=null;c!==void 0&&(p=""+c),l.key!==void 0&&(p=""+l.key),l.ref!==void 0&&(h=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:p,ref:h,props:f,_owner:o.current}}return _r.Fragment=n,_r.jsx=i,_r.jsxs=i,_r}var jr={};/**
|
|
10
10
|
* @license React
|
|
11
11
|
* react-jsx-runtime.development.js
|
|
12
12
|
*
|
|
@@ -14,29 +14,29 @@
|
|
|
14
14
|
*
|
|
15
15
|
* This source code is licensed under the MIT license found in the
|
|
16
16
|
* LICENSE file in the root directory of this source tree.
|
|
17
|
-
*/var
|
|
18
|
-
`+
|
|
19
|
-
`),It=
|
|
17
|
+
*/var Ga;function Zh(){return Ga||(Ga=1,process.env.NODE_ENV!=="production"&&function(){var e=b,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"),p=Symbol.for("react.lazy"),h=Symbol.for("react.offscreen"),g=Symbol.iterator,m="@@iterator";function y(I){if(I===null||typeof I!="object")return null;var W=g&&I[g]||I[m];return typeof W=="function"?W:null}var x=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function w(I){{for(var W=arguments.length,ae=new Array(W>1?W-1:0),we=1;we<W;we++)ae[we-1]=arguments[we];S("error",I,ae)}}function S(I,W,ae){{var we=x.ReactDebugCurrentFrame,Be=we.getStackAddendum();Be!==""&&(W+="%s",ae=ae.concat([Be]));var nt=ae.map(function(De){return String(De)});nt.unshift("Warning: "+W),Function.prototype.apply.call(console[I],console,nt)}}var k=!1,C=!1,T=!1,E=!1,N=!1,_;_=Symbol.for("react.module.reference");function D(I){return!!(typeof I=="string"||typeof I=="function"||I===r||I===s||N||I===o||I===c||I===d||E||I===h||k||C||T||typeof I=="object"&&I!==null&&(I.$$typeof===p||I.$$typeof===f||I.$$typeof===i||I.$$typeof===a||I.$$typeof===l||I.$$typeof===_||I.getModuleId!==void 0))}function B(I,W,ae){var we=I.displayName;if(we)return we;var Be=W.displayName||W.name||"";return Be!==""?ae+"("+Be+")":ae}function G(I){return I.displayName||"Context"}function V(I){if(I==null)return null;if(typeof I.tag=="number"&&w("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof I=="function")return I.displayName||I.name||null;if(typeof I=="string")return I;switch(I){case r:return"Fragment";case n:return"Portal";case s:return"Profiler";case o:return"StrictMode";case c:return"Suspense";case d:return"SuspenseList"}if(typeof I=="object")switch(I.$$typeof){case a:var W=I;return G(W)+".Consumer";case i:var ae=I;return G(ae._context)+".Provider";case l:return B(I,I.render,"ForwardRef");case f:var we=I.displayName||null;return we!==null?we:V(I.type)||"Memo";case p:{var Be=I,nt=Be._payload,De=Be._init;try{return V(De(nt))}catch{return null}}}return null}var P=Object.assign,M=0,A,F,L,R,z,X,ne;function ye(){}ye.__reactDisabledLog=!0;function Te(){{if(M===0){A=console.log,F=console.info,L=console.warn,R=console.error,z=console.group,X=console.groupCollapsed,ne=console.groupEnd;var I={configurable:!0,enumerable:!0,value:ye,writable:!0};Object.defineProperties(console,{info:I,log:I,warn:I,error:I,group:I,groupCollapsed:I,groupEnd:I})}M++}}function q(){{if(M--,M===0){var I={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:P({},I,{value:A}),info:P({},I,{value:F}),warn:P({},I,{value:L}),error:P({},I,{value:R}),group:P({},I,{value:z}),groupCollapsed:P({},I,{value:X}),groupEnd:P({},I,{value:ne})})}M<0&&w("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var U=x.ReactCurrentDispatcher,Z;function $(I,W,ae){{if(Z===void 0)try{throw Error()}catch(Be){var we=Be.stack.trim().match(/\n( *(at )?)/);Z=we&&we[1]||""}return`
|
|
18
|
+
`+Z+I}}var Y=!1,Q;{var de=typeof WeakMap=="function"?WeakMap:Map;Q=new de}function oe(I,W){if(!I||Y)return"";{var ae=Q.get(I);if(ae!==void 0)return ae}var we;Y=!0;var Be=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var nt;nt=U.current,U.current=null,Te();try{if(W){var De=function(){throw Error()};if(Object.defineProperty(De.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(De,[])}catch(Ue){we=Ue}Reflect.construct(I,[],De)}else{try{De.call()}catch(Ue){we=Ue}I.call(De.prototype)}}else{try{throw Error()}catch(Ue){we=Ue}I()}}catch(Ue){if(Ue&&we&&typeof Ue.stack=="string"){for(var Oe=Ue.stack.split(`
|
|
19
|
+
`),It=we.stack.split(`
|
|
20
20
|
`),mt=Oe.length-1,xt=It.length-1;mt>=1&&xt>=0&&Oe[mt]!==It[xt];)xt--;for(;mt>=1&&xt>=0;mt--,xt--)if(Oe[mt]!==It[xt]){if(mt!==1||xt!==1)do if(mt--,xt--,xt<0||Oe[mt]!==It[xt]){var he=`
|
|
21
|
-
`+Oe[mt].replace(" at new "," at ");return I.displayName&&he.includes("<anonymous>")&&(he=he.replace("<anonymous>",I.displayName)),typeof I=="function"&&
|
|
21
|
+
`+Oe[mt].replace(" at new "," at ");return I.displayName&&he.includes("<anonymous>")&&(he=he.replace("<anonymous>",I.displayName)),typeof I=="function"&&Q.set(I,he),he}while(mt>=1&&xt>=0);break}}}finally{Y=!1,U.current=nt,q(),Error.prepareStackTrace=Be}var be=I?I.displayName||I.name:"",Ee=be?$(be):"";return typeof I=="function"&&Q.set(I,Ee),Ee}function _e(I,W,ae){return oe(I,!1)}function ze(I){var W=I.prototype;return!!(W&&W.isReactComponent)}function se(I,W,ae){if(I==null)return"";if(typeof I=="function")return oe(I,ze(I));if(typeof I=="string")return $(I);switch(I){case c:return $("Suspense");case d:return $("SuspenseList")}if(typeof I=="object")switch(I.$$typeof){case l:return _e(I.render);case f:return se(I.type,W,ae);case p:{var we=I,Be=we._payload,nt=we._init;try{return se(nt(Be),W,ae)}catch{}}}return""}var me=Object.prototype.hasOwnProperty,Pe={},Ve=x.ReactDebugCurrentFrame;function ut(I){if(I){var W=I._owner,ae=se(I.type,I._source,W?W.type:null);Ve.setExtraStackFrame(ae)}else Ve.setExtraStackFrame(null)}function Ke(I,W,ae,we,Be){{var nt=Function.call.bind(me);for(var De in I)if(nt(I,De)){var Oe=void 0;try{if(typeof I[De]!="function"){var It=Error((we||"React class")+": "+ae+" type `"+De+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof I[De]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw It.name="Invariant Violation",It}Oe=I[De](W,De,we,ae,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(mt){Oe=mt}Oe&&!(Oe instanceof Error)&&(ut(Be),w("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",we||"React class",ae,De,typeof Oe),ut(null)),Oe instanceof Error&&!(Oe.message in Pe)&&(Pe[Oe.message]=!0,ut(Be),w("Failed %s type: %s",ae,Oe.message),ut(null))}}}var qe=Array.isArray;function Qe(I){return qe(I)}function Ge(I){{var W=typeof Symbol=="function"&&Symbol.toStringTag,ae=W&&I[Symbol.toStringTag]||I.constructor.name||"Object";return ae}}function et(I){try{return st(I),!1}catch{return!0}}function st(I){return""+I}function Mt(I){if(et(I))return w("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",Ge(I)),st(I)}var gt=x.ReactCurrentOwner,Ct={key:!0,ref:!0,__self:!0,__source:!0},it,St;function Pt(I){if(me.call(I,"ref")){var W=Object.getOwnPropertyDescriptor(I,"ref").get;if(W&&W.isReactWarning)return!1}return I.ref!==void 0}function zt(I){if(me.call(I,"key")){var W=Object.getOwnPropertyDescriptor(I,"key").get;if(W&&W.isReactWarning)return!1}return I.key!==void 0}function nn(I,W){typeof I.ref=="string"&>.current}function Le(I,W){{var ae=function(){it||(it=!0,w("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",W))};ae.isReactWarning=!0,Object.defineProperty(I,"key",{get:ae,configurable:!0})}}function Sn(I,W){{var ae=function(){St||(St=!0,w("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",W))};ae.isReactWarning=!0,Object.defineProperty(I,"ref",{get:ae,configurable:!0})}}var tt=function(I,W,ae,we,Be,nt,De){var Oe={$$typeof:t,type:I,key:W,ref:ae,props:De,_owner:nt};return Oe._store={},Object.defineProperty(Oe._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(Oe,"_self",{configurable:!1,enumerable:!1,writable:!1,value:we}),Object.defineProperty(Oe,"_source",{configurable:!1,enumerable:!1,writable:!1,value:Be}),Object.freeze&&(Object.freeze(Oe.props),Object.freeze(Oe)),Oe};function We(I,W,ae,we,Be){{var nt,De={},Oe=null,It=null;ae!==void 0&&(Mt(ae),Oe=""+ae),zt(W)&&(Mt(W.key),Oe=""+W.key),Pt(W)&&(It=W.ref,nn(W,Be));for(nt in W)me.call(W,nt)&&!Ct.hasOwnProperty(nt)&&(De[nt]=W[nt]);if(I&&I.defaultProps){var mt=I.defaultProps;for(nt in mt)De[nt]===void 0&&(De[nt]=mt[nt])}if(Oe||It){var xt=typeof I=="function"?I.displayName||I.name||"Unknown":I;Oe&&Le(De,xt),It&&Sn(De,xt)}return tt(I,Oe,It,Be,we,gt.current,De)}}var pt=x.ReactCurrentOwner,Rt=x.ReactDebugCurrentFrame;function Ye(I){if(I){var W=I._owner,ae=se(I.type,I._source,W?W.type:null);Rt.setExtraStackFrame(ae)}else Rt.setExtraStackFrame(null)}var H;H=!1;function j(I){return typeof I=="object"&&I!==null&&I.$$typeof===t}function J(){{if(pt.current){var I=V(pt.current.type);if(I)return`
|
|
22
22
|
|
|
23
|
-
Check the render method of \``+I+"`."}return""}}function re(I){return""}var ie={};function ce(I){{var W=
|
|
23
|
+
Check the render method of \``+I+"`."}return""}}function re(I){return""}var ie={};function ce(I){{var W=J();if(!W){var ae=typeof I=="string"?I:I.displayName||I.name;ae&&(W=`
|
|
24
24
|
|
|
25
|
-
Check the top-level render call using <`+ae+">.")}return W}}function Xe(I,W){{if(!I._store||I._store.validated||I.key!=null)return;I._store.validated=!0;var ae=ce(W);if(ie[ae])return;ie[ae]=!0;var
|
|
25
|
+
Check the top-level render call using <`+ae+">.")}return W}}function Xe(I,W){{if(!I._store||I._store.validated||I.key!=null)return;I._store.validated=!0;var ae=ce(W);if(ie[ae])return;ie[ae]=!0;var we="";I&&I._owner&&I._owner!==pt.current&&(we=" It was passed a child from "+V(I._owner.type)+"."),Ye(I),w('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),Ye(null)}}function Ie(I,W){{if(typeof I!="object")return;if(Qe(I))for(var ae=0;ae<I.length;ae++){var we=I[ae];j(we)&&Xe(we,W)}else if(j(I))I._store&&(I._store.validated=!0);else if(I){var Be=y(I);if(typeof Be=="function"&&Be!==I.entries)for(var nt=Be.call(I),De;!(De=nt.next()).done;)j(De.value)&&Xe(De.value,W)}}}function at(I){{var W=I.type;if(W==null||typeof W=="string")return;var ae;if(typeof W=="function")ae=W.propTypes;else if(typeof W=="object"&&(W.$$typeof===l||W.$$typeof===f))ae=W.propTypes;else return;if(ae){var we=V(W);Ke(ae,I.props,"prop",we,I)}else if(W.PropTypes!==void 0&&!H){H=!0;var Be=V(W);w("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",Be||"Unknown")}typeof W.getDefaultProps=="function"&&!W.getDefaultProps.isReactClassApproved&&w("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function ht(I){{for(var W=Object.keys(I.props),ae=0;ae<W.length;ae++){var we=W[ae];if(we!=="children"&&we!=="key"){Ye(I),w("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",we),Ye(null);break}}I.ref!==null&&(Ye(I),w("Invalid attribute `ref` supplied to `React.Fragment`."),Ye(null))}}var Kt={};function Hn(I,W,ae,we,Be,nt){{var De=D(I);if(!De){var Oe="";(I===void 0||typeof I=="object"&&I!==null&&Object.keys(I).length===0)&&(Oe+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var It=re();It?Oe+=It:Oe+=J();var mt;I===null?mt="null":Qe(I)?mt="array":I!==void 0&&I.$$typeof===t?(mt="<"+(V(I.type)||"Unknown")+" />",Oe=" Did you accidentally export a JSX literal instead of a component?"):mt=typeof I,w("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",mt,Oe)}var xt=We(I,W,ae,Be,nt);if(xt==null)return xt;if(De){var he=W.children;if(he!==void 0)if(we)if(Qe(he)){for(var be=0;be<he.length;be++)Ie(he[be],I);Object.freeze&&Object.freeze(he)}else w("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else Ie(he,I)}if(me.call(W,"key")){var Ee=V(I),Ue=Object.keys(W).filter(function(DT){return DT!=="key"}),Wn=Ue.length>0?"{key: someKey, "+Ue.join(": ..., ")+": ...}":"{key: someKey}";if(!Kt[Ee+Wn]){var rn=Ue.length>0?"{"+Ue.join(": ..., ")+": ...}":"{}";w(`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} />`,Wn,Ee,rn,Ee),Kt[Ee+Wn]=!0}}return I===r?ht(xt):at(xt),xt}}function Ar(I,W,ae){return Hn(I,W,ae,!0)}function Nr(I,W,ae){return Hn(I,W,ae,!1)}var po=Nr,Nn=Ar;jr.Fragment=r,jr.jsx=po,jr.jsxs=Nn}()),jr}process.env.NODE_ENV==="production"?Js.exports=qh():Js.exports=Gh();var u=Js.exports;function Ga(e,t){return function(){return e.apply(t,arguments)}}const{toString:Yh}=Object.prototype,{getPrototypeOf:Zs}=Object,{iterator:go,toStringTag:Ya}=Symbol,xo=(e=>t=>{const n=Yh.call(t);return e[n]||(e[n]=n.slice(8,-1).toLowerCase())})(Object.create(null)),on=e=>(e=e.toLowerCase(),t=>xo(t)===e),yo=e=>t=>typeof t===e,{isArray:lr}=Array,cr=yo("undefined");function Mr(e){return e!==null&&!cr(e)&&e.constructor!==null&&!cr(e.constructor)&&$t(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const Xa=on("ArrayBuffer");function Xh(e){let t;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?t=ArrayBuffer.isView(e):t=e&&e.buffer&&Xa(e.buffer),t}const Jh=yo("string"),$t=yo("function"),Ja=yo("number"),Rr=e=>e!==null&&typeof e=="object",Zh=e=>e===!0||e===!1,vo=e=>{if(xo(e)!=="object")return!1;const t=Zs(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Ya in e)&&!(go in e)},Qh=e=>{if(!Rr(e)||Mr(e))return!1;try{return Object.keys(e).length===0&&Object.getPrototypeOf(e)===Object.prototype}catch{return!1}},em=on("Date"),tm=on("File"),nm=on("Blob"),rm=on("FileList"),om=e=>Rr(e)&&$t(e.pipe),sm=e=>{let t;return e&&(typeof FormData=="function"&&e instanceof FormData||$t(e.append)&&((t=xo(e))==="formdata"||t==="object"&&$t(e.toString)&&e.toString()==="[object FormData]"))},im=on("URLSearchParams"),[am,lm,cm,um]=["ReadableStream","Request","Response","Headers"].map(on),dm=e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function Pr(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(Mr(e))return;const s=n?Object.getOwnPropertyNames(e):Object.keys(e),i=s.length;let a;for(r=0;r<i;r++)a=s[r],t.call(null,e[a],a,e)}}function Za(e,t){if(Mr(e))return null;t=t.toLowerCase();const n=Object.keys(e);let r=n.length,o;for(;r-- >0;)if(o=n[r],t===o.toLowerCase())return o;return null}const Kn=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global,Qa=e=>!cr(e)&&e!==Kn;function Qs(){const{caseless:e,skipUndefined:t}=Qa(this)&&this||{},n={},r=(o,s)=>{const i=e&&Za(n,s)||s;vo(n[i])&&vo(o)?n[i]=Qs(n[i],o):vo(o)?n[i]=Qs({},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]&&Pr(arguments[o],r);return n}const fm=(e,t,n,{allOwnKeys:r}={})=>(Pr(t,(o,s)=>{n&&$t(o)?e[s]=Ga(o,n):e[s]=o},{allOwnKeys:r}),e),pm=e=>(e.charCodeAt(0)===65279&&(e=e.slice(1)),e),hm=(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)},mm=(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&&Zs(e)}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},gm=(e,t,n)=>{e=String(e),(n===void 0||n>e.length)&&(n=e.length),n-=t.length;const r=e.indexOf(t,n);return r!==-1&&r===n},xm=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},ym=(e=>t=>e&&t instanceof e)(typeof Uint8Array<"u"&&Zs(Uint8Array)),vm=(e,t)=>{const r=(e&&e[go]).call(e);let o;for(;(o=r.next())&&!o.done;){const s=o.value;t.call(e,s[0],s[1])}},bm=(e,t)=>{let n;const r=[];for(;(n=e.exec(t))!==null;)r.push(n);return r},wm=on("HTMLFormElement"),Sm=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),Cm=on("RegExp"),tl=(e,t)=>{const n=Object.getOwnPropertyDescriptors(e),r={};Pr(n,(o,s)=>{let i;(i=t(o,s,e))!==!1&&(r[s]=i||o)}),Object.defineProperties(e,r)},Tm=e=>{tl(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+"'")})}})},km=(e,t)=>{const n={},r=o=>{o.forEach(s=>{n[s]=!0})};return lr(e)?r(e):r(String(e).split(t)),n},Em=()=>{},Im=(e,t)=>e!=null&&Number.isFinite(e=+e)?e:t;function Am(e){return!!(e&&$t(e.append)&&e[Ya]==="FormData"&&e[go])}const Nm=e=>{const t=new Array(10),n=(r,o)=>{if(Rr(r)){if(t.indexOf(r)>=0)return;if(Mr(r))return r;if(!("toJSON"in r)){t[o]=r;const s=lr(r)?[]:{};return Pr(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)},_m=on("AsyncFunction"),jm=e=>e&&(Rr(e)||$t(e))&&$t(e.then)&&$t(e.catch),nl=((e,t)=>e?setImmediate:t?((n,r)=>(Kn.addEventListener("message",({source:o,data:s})=>{o===Kn&&s===n&&r.length&&r.shift()()},!1),o=>{r.push(o),Kn.postMessage(n,"*")}))(`axios@${Math.random()}`,[]):n=>setTimeout(n))(typeof setImmediate=="function",$t(Kn.postMessage)),Mm=typeof queueMicrotask<"u"?queueMicrotask.bind(Kn):typeof process<"u"&&process.nextTick||nl,O={isArray:lr,isArrayBuffer:Xa,isBuffer:Mr,isFormData:sm,isArrayBufferView:Xh,isString:Jh,isNumber:Ja,isBoolean:Zh,isObject:Rr,isPlainObject:vo,isEmptyObject:Qh,isReadableStream:am,isRequest:lm,isResponse:cm,isHeaders:um,isUndefined:cr,isDate:em,isFile:tm,isBlob:nm,isRegExp:Cm,isFunction:$t,isStream:om,isURLSearchParams:im,isTypedArray:ym,isFileList:rm,forEach:Pr,merge:Qs,extend:fm,trim:dm,stripBOM:pm,inherits:hm,toFlatObject:mm,kindOf:xo,kindOfTest:on,endsWith:gm,toArray:xm,forEachEntry:vm,matchAll:bm,isHTMLForm:wm,hasOwnProperty:el,hasOwnProp:el,reduceDescriptors:tl,freezeMethods:Tm,toObjectSet:km,toCamelCase:Sm,noop:Em,toFiniteNumber:Im,findKey:Za,global:Kn,isContextDefined:Qa,isSpecCompliantForm:Am,toJSONObject:Nm,isAsyncFn:_m,isThenable:jm,setImmediate:nl,asap:Mm,isIterable:e=>e!=null&&$t(e[go])};function je(e,t,n,r,o){Error.call(this),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=new Error().stack,this.message=e,this.name="AxiosError",t&&(this.code=t),n&&(this.config=n),r&&(this.request=r),o&&(this.response=o,this.status=o.status?o.status:null)}O.inherits(je,Error,{toJSON:function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:O.toJSONObject(this.config),code:this.code,status:this.status}}});const rl=je.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(je,ol),Object.defineProperty(rl,"isAxiosError",{value:!0}),je.from=(e,t,n,r,o,s)=>{const i=Object.create(rl);O.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 je.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 Rm=null;function ei(e){return O.isPlainObject(e)||O.isArray(e)}function sl(e){return O.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 Pm(e){return O.isArray(e)&&!e.some(ei)}const Om=O.toFlatObject(O,{},null,function(t){return/^is[A-Z]/.test(t)});function bo(e,t,n){if(!O.isObject(e))throw new TypeError("target must be an object");t=t||new FormData,n=O.toFlatObject(n,{metaTokens:!0,dots:!1,indexes:!1},!1,function(m,y){return!O.isUndefined(y[m])});const r=n.metaTokens,o=n.visitor||d,s=n.dots,i=n.indexes,l=(n.Blob||typeof Blob<"u"&&Blob)&&O.isSpecCompliantForm(t);if(!O.isFunction(o))throw new TypeError("visitor must be a function");function c(g){if(g===null)return"";if(O.isDate(g))return g.toISOString();if(O.isBoolean(g))return g.toString();if(!l&&O.isBlob(g))throw new je("Blob is not supported. Use a Buffer instead.");return O.isArrayBuffer(g)||O.isTypedArray(g)?l&&typeof Blob=="function"?new Blob([g]):Buffer.from(g):g}function d(g,m,y){let x=g;if(g&&!y&&typeof g=="object"){if(O.endsWith(m,"{}"))m=r?m:m.slice(0,-2),g=JSON.stringify(g);else if(O.isArray(g)&&Pm(g)||(O.isFileList(g)||O.endsWith(m,"[]"))&&(x=O.toArray(g)))return m=sl(m),x.forEach(function(S,k){!(O.isUndefined(S)||S===null)&&t.append(i===!0?il([m],k,s):i===null?m:m+"[]",c(S))}),!1}return ei(g)?!0:(t.append(il(y,m,s),c(g)),!1)}const f=[],p=Object.assign(Om,{defaultVisitor:d,convertValue:c,isVisitable:ei});function h(g,m){if(!O.isUndefined(g)){if(f.indexOf(g)!==-1)throw Error("Circular reference detected in "+m.join("."));f.push(g),O.forEach(g,function(x,b){(!(O.isUndefined(x)||x===null)&&o.call(t,x,O.isString(b)?b.trim():b,m,p))===!0&&h(x,m?m.concat(b):[b])}),f.pop()}}if(!O.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 ti(e,t){this._pairs=[],e&&bo(e,this,t)}const ll=ti.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 Dm(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||Dm;O.isFunction(n)&&(n={serialize:n});const o=n&&n.serialize;let s;if(o?s=o(t,n):s=O.isURLSearchParams(t)?t.toString():new ti(t,n).toString(r),s){const i=e.indexOf("#");i!==-1&&(e=e.slice(0,i)),e+=(e.indexOf("?")===-1?"?":"&")+s}return e}class ul{constructor(){this.handlers=[]}use(t,n,r){return this.handlers.push({fulfilled:t,rejected:n,synchronous:r?r.synchronous:!1,runWhen:r?r.runWhen:null}),this.handlers.length-1}eject(t){this.handlers[t]&&(this.handlers[t]=null)}clear(){this.handlers&&(this.handlers=[])}forEach(t){O.forEach(this.handlers,function(r){r!==null&&t(r)})}}const dl={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},Lm={isBrowser:!0,classes:{URLSearchParams:typeof URLSearchParams<"u"?URLSearchParams:ti,FormData:typeof FormData<"u"?FormData:null,Blob:typeof Blob<"u"?Blob:null},protocols:["http","https","file","blob","url","data"]},ni=typeof window<"u"&&typeof document<"u",ri=typeof navigator=="object"&&navigator||void 0,$m=ni&&(!ri||["ReactNative","NativeScript","NS"].indexOf(ri.product)<0),Fm=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function",Bm=ni&&window.location.href||"http://localhost",At={...Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv:ni,hasStandardBrowserEnv:$m,hasStandardBrowserWebWorkerEnv:Fm,navigator:ri,origin:Bm},Symbol.toStringTag,{value:"Module"})),...Lm};function zm(e,t){return bo(e,new At.classes.URLSearchParams,{visitor:function(n,r,o,s){return At.isNode&&O.isBuffer(n)?(this.append(r,n.toString("base64")),!1):s.defaultVisitor.apply(this,arguments)},...t})}function Um(e){return O.matchAll(/\w+|\[(\w*)]/g,e).map(t=>t[0]==="[]"?"":t[1]||t[0])}function Hm(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&&O.isArray(o)?o.length:i,l?(O.hasOwnProp(o,i)?o[i]=[o[i],r]:o[i]=r,!a):((!o[i]||!O.isObject(o[i]))&&(o[i]=[]),t(n,r,o[i],s)&&O.isArray(o[i])&&(o[i]=Hm(o[i])),!a)}if(O.isFormData(e)&&O.isFunction(e.entries)){const n={};return O.forEachEntry(e,(r,o)=>{t(Um(r),o,n,0)}),n}return null}function Wm(e,t,n){if(O.isString(e))try{return(t||JSON.parse)(e),O.trim(e)}catch(r){if(r.name!=="SyntaxError")throw r}return(n||JSON.stringify)(e)}const Or={transitional:dl,adapter:["xhr","http","fetch"],transformRequest:[function(t,n){const r=n.getContentType()||"",o=r.indexOf("application/json")>-1,s=O.isObject(t);if(s&&O.isHTMLForm(t)&&(t=new FormData(t)),O.isFormData(t))return o?JSON.stringify(fl(t)):t;if(O.isArrayBuffer(t)||O.isBuffer(t)||O.isStream(t)||O.isFile(t)||O.isBlob(t)||O.isReadableStream(t))return t;if(O.isArrayBufferView(t))return t.buffer;if(O.isURLSearchParams(t))return n.setContentType("application/x-www-form-urlencoded;charset=utf-8",!1),t.toString();let a;if(s){if(r.indexOf("application/x-www-form-urlencoded")>-1)return zm(t,this.formSerializer).toString();if((a=O.isFileList(t))||r.indexOf("multipart/form-data")>-1){const l=this.env&&this.env.FormData;return bo(a?{"files[]":t}:t,l&&new l,this.formSerializer)}}return s||o?(n.setContentType("application/json",!1),Wm(t)):t}],transformResponse:[function(t){const n=this.transitional||Or.transitional,r=n&&n.forcedJSONParsing,o=this.responseType==="json";if(O.isResponse(t)||O.isReadableStream(t))return t;if(t&&O.isString(t)&&(r&&!this.responseType||o)){const i=!(n&&n.silentJSONParsing)&&o;try{return JSON.parse(t,this.parseReviver)}catch(a){if(i)throw a.name==="SyntaxError"?je.from(a,je.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:At.classes.FormData,Blob:At.classes.Blob},validateStatus:function(t){return t>=200&&t<300},headers:{common:{Accept:"application/json, text/plain, */*","Content-Type":void 0}}};O.forEach(["delete","get","head","post","put","patch"],e=>{Or.headers[e]={}});const Vm=O.toObjectSet(["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"]),Km=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=Dr(i);r[a]||(Xm(o,i),r[a]=!0)}return O.isArray(t)?t.forEach(s):s(t),this}};Ft.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),O.reduceDescriptors(Ft.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(r){this[n]=r}}}),O.freezeMethods(Ft);function si(e,t){const n=this||Or,r=t||n,o=Ft.from(r.headers);let s=r.data;return O.forEach(e,function(a){s=a.call(n,s,o.normalize(),t?t.status:void 0)}),o.normalize(),s}function hl(e){return!!(e&&e.__CANCEL__)}function ur(e,t,n){je.call(this,e??"canceled",je.ERR_CANCELED,t,n),this.name="CanceledError"}O.inherits(ur,je,{__CANCEL__:!0});function ml(e,t,n){const r=n.config.validateStatus;!n.status||!r||r(n.status)?e(n):t(new je("Request failed with status code "+n.status,[je.ERR_BAD_REQUEST,je.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n))}function Jm(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function Zm(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 Qm(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 So=(e,t,n=3)=>{let r=0;const o=Zm(50,250);return Qm(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)=>O.asap(()=>e(...t)),eg=At.hasStandardBrowserEnv?((e,t)=>n=>(n=new URL(n,At.origin),e.protocol===n.protocol&&e.host===n.host&&(t||e.port===n.port)))(new URL(At.origin),At.navigator&&/(msie|trident)/i.test(At.navigator.userAgent)):()=>!0,tg=At.hasStandardBrowserEnv?{write(e,t,n,r,o,s){const i=[e+"="+encodeURIComponent(t)];O.isNumber(n)&&i.push("expires="+new Date(n).toGMTString()),O.isString(r)&&i.push("path="+r),O.isString(o)&&i.push("domain="+o),s===!0&&i.push("secure"),document.cookie=i.join("; ")},read(e){const t=document.cookie.match(new RegExp("(^|;\\s*)("+e+")=([^;]*)"));return t?decodeURIComponent(t[3]):null},remove(e){this.write(e,"",Date.now()-864e5)}}:{write(){},read(){return null},remove(){}};function ng(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function rg(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function yl(e,t,n){let r=!ng(t);return e&&(r||n==!1)?rg(e,t):t}const vl=e=>e instanceof Ft?{...e}:e;function qn(e,t){t=t||{};const n={};function r(c,d,f,p){return O.isPlainObject(c)&&O.isPlainObject(d)?O.merge.call({caseless:p},c,d):O.isPlainObject(d)?O.merge({},d):O.isArray(d)?d.slice():d}function o(c,d,f,p){if(O.isUndefined(d)){if(!O.isUndefined(c))return r(void 0,c,f,p)}else return r(c,d,f,p)}function s(c,d){if(!O.isUndefined(d))return r(void 0,d)}function i(c,d){if(O.isUndefined(d)){if(!O.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 O.forEach(Object.keys({...e,...t}),function(d){const f=l[d]||o,p=f(e[d],t[d],d);O.isUndefined(p)&&f!==a||(n[d]=p)}),n}const bl=e=>{const t=qn({},e);let{data:n,withXSRFToken:r,xsrfHeaderName:o,xsrfCookieName:s,headers:i,auth:a}=t;if(t.headers=i=Ft.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)):""))),O.isFormData(n)){if(At.hasStandardBrowserEnv||At.hasStandardBrowserWebWorkerEnv)i.setContentType(void 0);else if(O.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(At.hasStandardBrowserEnv&&(r&&O.isFunction(r)&&(r=r(t)),r||r!==!1&&eg(t.url))){const l=o&&s&&tg.read(s);l&&i.set(o,l)}return t},og=typeof XMLHttpRequest<"u"&&function(e){return new Promise(function(n,r){const o=bl(e);let s=o.data;const i=Ft.from(o.headers).normalize();let{responseType:a,onUploadProgress:l,onDownloadProgress:c}=o,d,f,p,h,g;function m(){h&&h(),g&&g(),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};ml(function(E){n(E),m()},function(E){r(E),m()},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 je("Request aborted",je.ECONNABORTED,e,y)),y=null)},y.onerror=function(k){const C=k&&k.message?k.message:"Network Error",T=new je(C,je.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||dl;o.timeoutErrorMessage&&(k=o.timeoutErrorMessage),r(new je(k,C.clarifyTimeoutError?je.ETIMEDOUT:je.ECONNABORTED,e,y)),y=null},s===void 0&&i.setContentType(null),"setRequestHeader"in y&&O.forEach(i.toJSON(),function(k,C){y.setRequestHeader(C,k)}),O.isUndefined(o.withCredentials)||(y.withCredentials=!!o.withCredentials),a&&a!=="json"&&(y.responseType=o.responseType),c&&([p,g]=So(c,!0),y.addEventListener("progress",p)),l&&y.upload&&([f,h]=So(l),y.upload.addEventListener("progress",f),y.upload.addEventListener("loadend",h)),(o.cancelToken||o.signal)&&(d=S=>{y&&(r(!S||S.type?new ur(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=Jm(o.url);if(b&&At.protocols.indexOf(b)===-1){r(new je("Unsupported protocol "+b+":",je.ERR_BAD_REQUEST,e));return}y.send(s||null)})},sg=(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 je?d:new ur(d instanceof Error?d.message:d))}};let i=t&&setTimeout(()=>{i=null,s(new je(`timeout ${t} of ms exceeded`,je.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=()=>O.asap(a),l}},ig=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},ag=async function*(e,t){for await(const n of lg(e))yield*ig(n,t)},lg=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=ag(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:Co}=O,cg=(({Request:e,Response:t})=>({Request:e,Response:t}))(O.global),{ReadableStream:Cl,TextEncoder:Tl}=O.global,kl=(e,...t)=>{try{return!!e(...t)}catch{return!1}},ug=e=>{e=O.merge.call({skipUndefined:!0},cg,e);const{fetch:t,Request:n,Response:r}=e,o=t?Co(t):typeof fetch=="function",s=Co(n),i=Co(r);if(!o)return!1;const a=o&&Co(Cl),l=o&&(typeof Tl=="function"?(g=>m=>g.encode(m))(new Tl):async g=>new Uint8Array(await new n(g).arrayBuffer())),c=s&&a&&kl(()=>{let g=!1;const m=new n(At.origin,{body:new Cl,method:"POST",get duplex(){return g=!0,"half"}}).headers.has("Content-Type");return g&&!m}),d=i&&a&&kl(()=>O.isReadableStream(new r("").body)),f={stream:d&&(g=>g.body)};o&&["text","arrayBuffer","blob","formData","stream"].forEach(g=>{!f[g]&&(f[g]=(m,y)=>{let x=m&&m[g];if(x)return x.call(m);throw new je(`Response type '${g}' is not supported`,je.ERR_NOT_SUPPORT,y)})});const p=async g=>{if(g==null)return 0;if(O.isBlob(g))return g.size;if(O.isSpecCompliantForm(g))return(await new n(At.origin,{method:"POST",body:g}).arrayBuffer()).byteLength;if(O.isArrayBufferView(g)||O.isArrayBuffer(g))return g.byteLength;if(O.isURLSearchParams(g)&&(g=g+""),O.isString(g))return(await l(g)).byteLength},h=async(g,m)=>{const y=O.toFiniteNumber(g.getContentLength());return y??p(m)};return async g=>{let{url:m,method:y,data:x,signal:b,cancelToken:S,timeout:k,onDownloadProgress:C,onUploadProgress:T,responseType:E,headers:N,withCredentials:_="same-origin",fetchOptions:D}=bl(g),B=t||fetch;E=E?(E+"").toLowerCase():"text";let G=sg([b,S&&S.toAbortSignal()],k),V=null;const R=G&&G.unsubscribe&&(()=>{G.unsubscribe()});let M;try{if(T&&c&&y!=="get"&&y!=="head"&&(M=await h(N,x))!==0){let X=new n(m,{method:"POST",body:x,duplex:"half"}),ne;if(O.isFormData(x)&&(ne=X.headers.get("content-type"))&&N.setContentType(ne),X.body){const[ye,Te]=gl(M,So(xl(T)));x=wl(X.body,Sl,ye,Te)}}O.isString(_)||(_=_?"include":"omit");const A=s&&"credentials"in n.prototype,F={...D,signal:G,method:y.toUpperCase(),headers:N.normalize().toJSON(),body:x,duplex:"half",credentials:A?_:void 0};V=s&&new n(m,F);let L=await(s?B(V,D):B(m,F));const P=d&&(E==="stream"||E==="response");if(d&&(C||P&&R)){const X={};["status","statusText","headers"].forEach(q=>{X[q]=L[q]});const ne=O.toFiniteNumber(L.headers.get("content-length")),[ye,Te]=C&&gl(ne,So(xl(C),!0))||[];L=new r(wl(L.body,Sl,ye,()=>{Te&&Te(),R&&R()}),X)}E=E||"text";let z=await f[O.findKey(f,E)||"text"](L,g);return!P&&R&&R(),await new Promise((X,ne)=>{ml(X,ne,{data:z,headers:Ft.from(L.headers),status:L.status,statusText:L.statusText,config:g,request:V})})}catch(A){throw R&&R(),A&&A.name==="TypeError"&&/Load failed|fetch/i.test(A.message)?Object.assign(new je("Network Error",je.ERR_NETWORK,g,V),{cause:A.cause||A}):je.from(A,A&&A.code,g,V)}}},dg=new Map,El=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=dg;for(;a--;)l=s[a],c=d.get(l),c===void 0&&d.set(l,c=a?new Map:ug(t)),d=c;return c};El();const ii={http:Rm,xhr:og,fetch:{get:El}};O.forEach(ii,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const Il=e=>`- ${e}`,fg=e=>O.isFunction(e)||e===null||e===!1,Al={getAdapter:(e,t)=>{e=O.isArray(e)?e:[e];const{length:n}=e;let r,o;const s={};for(let i=0;i<n;i++){r=e[i];let a;if(o=r,!fg(r)&&(o=ii[(a=String(r)).toLowerCase()],o===void 0))throw new je(`Unknown adapter '${a}'`);if(o&&(O.isFunction(o)||(o=o.get(t))))break;s[a||"#"+i]=o}if(!o){const i=Object.entries(s).map(([l,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=qn(this.defaults,n);const{transitional:r,paramsSerializer:o,headers:s}=n;r!==void 0&&ko.assertOptions(r,{silentJSONParsing:fn.transitional(fn.boolean),forcedJSONParsing:fn.transitional(fn.boolean),clarifyTimeoutError:fn.transitional(fn.boolean)},!1),o!=null&&(O.isFunction(o)?n.paramsSerializer={serialize:o}:ko.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),ko.assertOptions(n,{baseUrl:fn.spelling("baseURL"),withXsrfToken:fn.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let i=s&&O.merge(s.common,s[n.method]);s&&O.forEach(["delete","get","head","post","put","patch","common"],g=>{delete s[g]}),n.headers=Ft.concat(i,s);const a=[];let l=!0;this.interceptors.request.forEach(function(m){typeof m.runWhen=="function"&&m.runWhen(n)===!1||(l=l&&m.synchronous,a.unshift(m.fulfilled,m.rejected))});const c=[];this.interceptors.response.forEach(function(m){c.push(m.fulfilled,m.rejected)});let d,f=0,p;if(!l){const g=[Nl.bind(this),void 0];for(g.unshift(...a),g.push(...c),p=g.length,d=Promise.resolve(n);f<p;)d=d.then(g[f++],g[f++]);return d}p=a.length;let h=n;for(;f<p;){const g=a[f++],m=a[f++];try{h=g(h)}catch(y){m.call(this,y);break}}try{d=Nl.call(this,h)}catch(g){return Promise.reject(g)}for(f=0,p=c.length;f<p;)d=d.then(c[f++],c[f++]);return d}getUri(t){t=qn(this.defaults,t);const n=yl(t.baseURL,t.url,t.allowAbsoluteUrls);return cl(n,t.params,t.paramsSerializer)}};O.forEach(["delete","get","head","options"],function(t){Gn.prototype[t]=function(n,r){return this.request(qn(r||{},{method:t,url:n,data:(r||{}).data}))}}),O.forEach(["post","put","patch"],function(t){function n(r){return function(s,i,a){return this.request(qn(a||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:s,data:i}))}}Gn.prototype[t]=n(),Gn.prototype[t+"Form"]=n(!0)});let hg=class Wh{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 Wh(function(o){t=o}),cancel:t}}};function mg(e){return function(n){return e.apply(null,n)}}function gg(e){return O.isObject(e)&&e.isAxiosError===!0}const li={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(li).forEach(([e,t])=>{li[t]=e});function Ml(e){const t=new Gn(e),n=Ga(Gn.prototype.request,t);return O.extend(n,Gn.prototype,t,{allOwnKeys:!0}),O.extend(n,t,null,{allOwnKeys:!0}),n.create=function(o){return Ml(qn(e,o))},n}const yt=Ml(Or);yt.Axios=Gn,yt.CanceledError=ur,yt.CancelToken=hg,yt.isCancel=hl,yt.VERSION=_l,yt.toFormData=bo,yt.AxiosError=je,yt.Cancel=yt.CanceledError,yt.all=function(t){return Promise.all(t)},yt.spread=mg,yt.isAxiosError=gg,yt.mergeConfig=qn,yt.AxiosHeaders=Ft,yt.formToJSON=e=>fl(O.isHTMLForm(e)?new FormData(e):e),yt.getAdapter=Al.getAdapter,yt.HttpStatusCode=li,yt.default=yt;const{Axios:FT,AxiosError:BT,CanceledError:zT,isCancel:UT,CancelToken:HT,VERSION:WT,all:VT,Cancel:KT,isAxiosError:qT,spread:GT,toFormData:YT,AxiosHeaders:XT,HttpStatusCode:JT,formToJSON:ZT,getAdapter:QT,mergeConfig:ek}=yt,Rl=typeof window<"u"?window.__API_BASE_URL__:void 0,Pl=Rl?Cn(Rl):void 0;function Cn(e){const n=(e!=null&&e.trim()?e.trim():"/api/chat").replace(/\/+$/,"");return n?n.endsWith("/chat")?n:`${n}/chat`:"/api/chat"}let Eo=null;const ci=new Set;function Ol(){return Eo}function Io(e){Eo=e,ci.forEach(t=>t(e))}function Dl(e){return ci.add(e),()=>ci.delete(e)}const xg=3e4,yg=9e4,qt=yt.create({...Pl?{baseURL:Pl}:{},timeout:xg,withCredentials:!0});qt.interceptors.request.use(e=>(Eo&&(e.headers.Authorization=`Bearer ${Eo}`),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 ui(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 Ll(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 $l(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 Fl{get baseUrl(){const t=qt.defaults.baseURL;return t?Cn(String(t)):""}updateConfig(t){t.baseUrl&&(qt.defaults.baseURL=Cn(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 Gt("/threads"),n=Yt(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async createThread(t){const r=await ui("/threads",t?{title:t}:void 0);return Yt(r)}async updateThread(t,n){const r=await Ll(`/threads/${t}`,{title:n});return Yt(r)}async deleteThread(t){const n=await $l(`/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:yg});return Yt(n)}async cancelRun(t){const n=await ui("/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 _n=new Fl,Bl=w.createContext(null);function vg({children:e,apiConfig:t}){const n=_n;if(t){const o=n.baseUrl,s=n.getAuthToken();t.baseUrl&&t.baseUrl!==o&&n.updateConfig({baseUrl:t.baseUrl}),t.apiKey!==void 0&&t.apiKey!==s&&n.updateConfig({authToken:t.apiKey})}const r={token:n.getAuthToken(),setToken:o=>n.setAuthToken(o),api:n,baseUrl:n.baseUrl};return u.jsx(Bl.Provider,{value:r,children:e})}function di(){const e=w.useContext(Bl);if(!e)throw new Error("useApi must be used within ApiProvider");return e}async function bg(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 wg(e,t=[],n,r,o,s){const i=[],a=[];for(const l of t)try{const c=await bg(l);a.push({filename:l.name,data:c,mime_type:l.type||"application/octet-stream"})}catch{}return{contentParts:i,filesInfo:a}}const Sg={human:"user",user:"user",ai:"assistant",assistant:"assistant",tool:"tool",function:"tool",system:"system"};function fi(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 Cg(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(!fi(r))return{threadId:n,latest:null,checkpoints:[],timeline:[],interrupt:null,snapshots:{}};const{orderedSnapshots:o,snapshotMap:s}=kg(t),i=zl(r,0),a=Eg(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(!fi(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((_,D)=>Og(_,D)).filter(_=>!!_),d=Ot(e.config),f=Ot(d==null?void 0:d.configurable),p=dt(f,["checkpoint_id","checkpointId"]),h=dt(f,["checkpoint_ns","checkpointNs"]),g=Ot(e==null?void 0:e.parentConfig),m=Ot(g==null?void 0:g.configurable),y=dt(m,["checkpoint_id","checkpointId"])??null,x=dt(m,["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(_=>_.role==="user")??null,C=Ot(e==null?void 0:e.metadata),T=dt(C,["branch_label","branchLabel"]),E=dt(m,["checkpoint_id","checkpointId"]),N=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:Tg(a,c,t),createdAt:S,parentId:E??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:g??null,next:N??null,tasks:l??null,values:i??null}}function Tg(e,t,n){const r=Rg(e,n);return r||Mg(t,n)}function kg(e){const t=new Map;e.forEach((o,s)=>{if(!fi(o))return;const i=zl(o,s);if(!(i!=null&&i.checkpointId))return;const a=Cg(i.checkpointId,i.checkpointNs??null),l=t.get(a);if(!l){t.set(a,i);return}t.set(a,Ng(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 Eg(e){var n,r;const t=[];for(const o of e){const s=o.checkpointId??null;if(!s)continue;const i=o.metadata??{},a=dt(i,["label"])??dt(i,["branch_label","branchLabel"])??dt(i,["description"])??"User input",l=Ag(i,["step"]),c=dt(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=Ig(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 Ig(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 Ag(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 Ng(e,t){return{...e,metadata:Ao(e.metadata,t.metadata)??null,config:Ao(e.config,t.config)??null,parentConfig:Ao(e.parentConfig,t.parentConfig)??null,next:_g(e.next,t.next)??null,tasks:jg(e.tasks,t.tasks)??null,values:Ao(e.values,t.values)??null}}function Ao(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 _g(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 jg(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 Mg(e,t){var n;for(let r=e.length-1;r>=0;r--){const o=((n=e[r])==null?void 0:n.content)??[];for(let s=o.length-1;s>=0;s--){const i=o[s];if((i==null?void 0:i.type)==="interrupt"){const a=i;return{id:typeof a.id=="string"&&a.id.trim()?a.id:`interrupt-${t}-${r}-${s}`,value:a.value}}}}return null}function Rg(e,t){if(!Array.isArray(e)||!e.length)return null;for(let n=e.length-1;n>=0;n--){const r=Pg(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=Lr(r.interrupts[s],`${o}-interrupt-${s}`);if(i)return i}if(r.state!==void 0&&r.state!==null){const s=Lr(r.state,`${o}-state`);if(s)return s}}return null}function Pg(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,g=typeof l=="string"&&l.trim()?l:Array.isArray(c)&&typeof c[0]=="string"?String(c[0]):"task",m=Array.isArray(d)?d:void 0,y=p.length?p[p.length-1]:void 0;return{id:h,name:g,interrupts:m,state:y!==void 0?y:f}}const n=Ot(e);if(!n)return null;const r=dt(n,["id","thread_id","taskId"])??t,o=dt(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 Lr(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=Lr(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=Lr(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=Lr(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=dt(n,["type","event","kind"]),o=dt(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 Og(e,t){if(!e||typeof e!="object")return null;const n=e,r=Ot(e)??{},o=Ot(n.data)??r,s=String(n.type??o.type??o.role??"").toLowerCase(),i=Sg[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=Ot(o.additional_kwargs)??Ot(o.additionalKwargs),d=Ot(o.response_metadata)??Ot(o.responseMetadata),f=dt(c,["createdAt","created_at"])??dt(o,["created_at","createdAt"]),p=dt(c,["checkpointId","checkpoint_id"]),h=dt(c,["checkpointNs","checkpoint_ns"]),g=Dg(o.content),m={id:l,role:i,content:g};f&&(m.createdAt=f),typeof o.name=="string"&&o.name.trim()&&(m.name=o.name),typeof(d==null?void 0:d.model_name)=="string"&&(m.model=String(d.model_name)),!m.model&&typeof o.model=="string"&&(m.model=o.model),p&&(m.checkpointId=p),h&&(m.checkpointNs=h);const y=Fg(Ot(o.artifact??r.artifact??o.artifacts??r.artifacts));y&&(m.artifact=y);const x=Hg(c,["createdAt","created_at","checkpointId","checkpoint_id","checkpointNs","checkpoint_ns","tool_calls"]),b=d?{...d}:void 0;x&&Object.keys(x).length&&(m.additionalKwargs=x),b&&Object.keys(b).length&&(m.responseMetadata=b);const S=Lg((c==null?void 0:c.tool_calls)??o.tool_calls);if(S.length&&(m.content=[...m.content,...S]),i==="tool"){const k=$g(o,m.content);k&&(m.content=k)}return m}function Dg(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=dt(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=dt(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=dt(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=dt(e,["id","call_id"])??t,r=dt(e,["name"])??dt(Ot(e.function),["name"]);if(!n||!r)return null;const o=Ug(e.args??e.arguments??((s=Ot(e.function))==null?void 0:s.arguments));return{type:"tool_call",id:n,name:r,args:o}}function Lg(e){return Array.isArray(e)?e.map((t,n)=>Vl(t,`tool_call_${n}`)).filter(t=>!!t):[]}function $g(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 Fg(e){return e?{plots:Bg(e.plots)}:void 0}function Bg(e){return Array.isArray(e)?e.map(t=>zg(t)).filter(t=>!!t):[]}function zg(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 Ug(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 Ot(e){if(!(!e||typeof e!="object"||Array.isArray(e)))return{...e}}function dt(e,t){if(e)for(const n of t){const r=e[n];if(typeof r=="string"&&r.trim())return r}}function Hg(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 Wg(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 Wg(e.content)||""}function Vg(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 Kg(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(()=>Cn(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,g]=w.useState(null),[m,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),E=w.useRef(null),N=w.useRef(null),_=w.useRef(null),D=w.useCallback(R=>{o(R)},[]),B=w.useCallback(()=>{p(""),g(null),d(null),E.current=null,N.current=null,_.current=null},[]),G=w.useCallback(()=>{var R;console.debug("[use-chat] stop() invoked - aborting stream"),(R=S.current)==null||R.abort(),S.current=null,T.current=null,l(!1),b(!1),C.current=0,y(0)},[]),V=w.useCallback((R,M,A)=>{S.current&&(S.current.abort(),S.current=null),l(!0),d(null),e.autoAppendAssistant!==!1&&p(""),g(null),E.current=null,N.current=null,_.current=null;const F=new AbortController;S.current=F;let L=null,P=null,z=!1;return T.current={threadId:R.threadId??null,headers:{}},(async()=>{var ne,ye,Te,q,U,J,$,Y,Z,de,oe,_e,ze,se,me,Re,Ve,ut;const X=Ke=>{var qe;try{const Qe=JSON.parse(JSON.stringify(Ke));return(qe=Qe==null?void 0:Qe.payload)!=null&&qe.files_info&&Array.isArray(Qe.payload.files_info)&&(Qe.payload.files_info=Qe.payload.files_info.map(Ge=>({...Ge,data:Ge!=null&&Ge.data?`<base64 ${String(Ge.data).length} chars>`:Ge==null?void 0:Ge.data}))),Qe}catch{return Ke}};try{let Ke={};try{if(r)Ke={Authorization:`Bearer ${r}`};else if(typeof window<"u"){const We=window.__AUTH_TOKEN__,pt=((ne=window.localStorage)==null?void 0:ne.getItem("authToken"))||null;let Pt=null;try{const H=(ye=window.localStorage)==null?void 0:ye.getItem("chat-settings");H&&(Pt=((Te=JSON.parse(H))==null?void 0:Te.apiKey)||null)}catch{}const Ye=We||pt||Pt||null;Ye&&(Ke={Authorization:`Bearer ${Ye}`})}}catch{}console.debug("[use-chat] POST",t+n,X(R));let qe={};if(typeof window<"u")try{const tt=(q=window.localStorage)==null?void 0:q.getItem("authSessionId");tt&&(qe={"X-Session-Id":tt})}catch{}const Qe={...Ke,...qe,...s.current},Ge={"Content-Type":"application/json",Accept:"text/event-stream",...Qe},et=await fetch(t+n,{method:"POST",headers:Ge,body:JSON.stringify(R),signal:F.signal,credentials:i});if(T.current&&(T.current.headers=Qe),!et.ok||!et.body){const tt=await et.text().catch(()=>"");console.debug("[use-chat] non-OK response",et.status,tt==null?void 0:tt.slice(0,500));const We=`stream ${et.status}${tt?": "+tt:""}`;throw(U=A==null?void 0:A.onConnectionError)==null||U.call(A,We),z=!0,L="error",P=We,new Error(We)}b(!0);const st=et.body.getReader(),Mt=new TextDecoder;let gt="",Ct=[];C.current=0,y(0);let it=0,St=null;const Rt=()=>{if(Ct.length){const tt=Ct.join("");Ct=[],k.current&&p(We=>We+tt)}St=null},zt=()=>{typeof window<"u"&&St==null&&(St=requestAnimationFrame(Rt))};let nn=Date.now();const Le=setInterval(()=>{var tt;if(Date.now()-nn>18e5){const We="Stream idle timeout";d(We),L="error",P=We,F.abort(),(tt=A==null?void 0:A.onError)==null||tt.call(A,We)}},5e3),Sn=1024*1024;try{const tt=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"),pt=tt??null,Pt=String(We??"").toLowerCase()==="true";for(T.current&&!T.current.threadId&&(T.current={...T.current,threadId:pt}),(J=A==null?void 0:A.onOpen)==null||J.call(A,{threadId:pt,created:Pt});;){const{value:Ye,done:H}=await st.read();if(H)break;gt+=Mt.decode(Ye,{stream:!0}),gt.length>Sn&&(gt="",console.warn("Stream buffer reset: exceeded 1MB"));let j;for(;(j=gt.indexOf(`
|
|
30
|
+
<%s key={someKey} {...props} />`,Wn,Ee,rn,Ee),Kt[Ee+Wn]=!0}}return I===r?ht(xt):at(xt),xt}}function Ar(I,W,ae){return Hn(I,W,ae,!0)}function Nr(I,W,ae){return Hn(I,W,ae,!1)}var po=Nr,Nn=Ar;jr.Fragment=r,jr.jsx=po,jr.jsxs=Nn}()),jr}process.env.NODE_ENV==="production"?Js.exports=Jh():Js.exports=Zh();var u=Js.exports;function Ya(e,t){return function(){return e.apply(t,arguments)}}const{toString:Qh}=Object.prototype,{getPrototypeOf:Zs}=Object,{iterator:go,toStringTag:Xa}=Symbol,xo=(e=>t=>{const n=Qh.call(t);return e[n]||(e[n]=n.slice(8,-1).toLowerCase())})(Object.create(null)),on=e=>(e=e.toLowerCase(),t=>xo(t)===e),yo=e=>t=>typeof t===e,{isArray:lr}=Array,cr=yo("undefined");function Mr(e){return e!==null&&!cr(e)&&e.constructor!==null&&!cr(e.constructor)&&$t(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const Ja=on("ArrayBuffer");function em(e){let t;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?t=ArrayBuffer.isView(e):t=e&&e.buffer&&Ja(e.buffer),t}const tm=yo("string"),$t=yo("function"),Za=yo("number"),Pr=e=>e!==null&&typeof e=="object",nm=e=>e===!0||e===!1,vo=e=>{if(xo(e)!=="object")return!1;const t=Zs(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Xa in e)&&!(go in e)},rm=e=>{if(!Pr(e)||Mr(e))return!1;try{return Object.keys(e).length===0&&Object.getPrototypeOf(e)===Object.prototype}catch{return!1}},om=on("Date"),sm=on("File"),im=on("Blob"),am=on("FileList"),lm=e=>Pr(e)&&$t(e.pipe),cm=e=>{let t;return e&&(typeof FormData=="function"&&e instanceof FormData||$t(e.append)&&((t=xo(e))==="formdata"||t==="object"&&$t(e.toString)&&e.toString()==="[object FormData]"))},um=on("URLSearchParams"),[dm,fm,pm,hm]=["ReadableStream","Request","Response","Headers"].map(on),mm=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]),lr(e))for(r=0,o=e.length;r<o;r++)t.call(null,e[r],r,e);else{if(Mr(e))return;const s=n?Object.getOwnPropertyNames(e):Object.keys(e),i=s.length;let a;for(r=0;r<i;r++)a=s[r],t.call(null,e[a],a,e)}}function Qa(e,t){if(Mr(e))return null;t=t.toLowerCase();const n=Object.keys(e);let r=n.length,o;for(;r-- >0;)if(o=n[r],t===o.toLowerCase())return o;return null}const Kn=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global,el=e=>!cr(e)&&e!==Kn;function Qs(){const{caseless:e,skipUndefined:t}=el(this)&&this||{},n={},r=(o,s)=>{const i=e&&Qa(n,s)||s;vo(n[i])&&vo(o)?n[i]=Qs(n[i],o):vo(o)?n[i]=Qs({},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]&&Rr(arguments[o],r);return n}const gm=(e,t,n,{allOwnKeys:r}={})=>(Rr(t,(o,s)=>{n&&$t(o)?e[s]=Ya(o,n):e[s]=o},{allOwnKeys:r}),e),xm=e=>(e.charCodeAt(0)===65279&&(e=e.slice(1)),e),ym=(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)},vm=(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&&Zs(e)}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},wm=(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},bm=e=>{if(!e)return null;if(lr(e))return e;let t=e.length;if(!Za(t))return null;const n=new Array(t);for(;t-- >0;)n[t]=e[t];return n},Sm=(e=>t=>e&&t instanceof e)(typeof Uint8Array<"u"&&Zs(Uint8Array)),Cm=(e,t)=>{const r=(e&&e[go]).call(e);let o;for(;(o=r.next())&&!o.done;){const s=o.value;t.call(e,s[0],s[1])}},Tm=(e,t)=>{let n;const r=[];for(;(n=e.exec(t))!==null;)r.push(n);return r},km=on("HTMLFormElement"),Em=e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(n,r,o){return r.toUpperCase()+o}),tl=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),Im=on("RegExp"),nl=(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)},Am=e=>{nl(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+"'")})}})},Nm=(e,t)=>{const n={},r=o=>{o.forEach(s=>{n[s]=!0})};return lr(e)?r(e):r(String(e).split(t)),n},_m=()=>{},jm=(e,t)=>e!=null&&Number.isFinite(e=+e)?e:t;function Mm(e){return!!(e&&$t(e.append)&&e[Xa]==="FormData"&&e[go])}const Pm=e=>{const t=new Array(10),n=(r,o)=>{if(Pr(r)){if(t.indexOf(r)>=0)return;if(Mr(r))return r;if(!("toJSON"in r)){t[o]=r;const s=lr(r)?[]:{};return Rr(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)},Rm=on("AsyncFunction"),Om=e=>e&&(Pr(e)||$t(e))&&$t(e.then)&&$t(e.catch),rl=((e,t)=>e?setImmediate:t?((n,r)=>(Kn.addEventListener("message",({source:o,data:s})=>{o===Kn&&s===n&&r.length&&r.shift()()},!1),o=>{r.push(o),Kn.postMessage(n,"*")}))(`axios@${Math.random()}`,[]):n=>setTimeout(n))(typeof setImmediate=="function",$t(Kn.postMessage)),Dm=typeof queueMicrotask<"u"?queueMicrotask.bind(Kn):typeof process<"u"&&process.nextTick||rl,O={isArray:lr,isArrayBuffer:Ja,isBuffer:Mr,isFormData:cm,isArrayBufferView:em,isString:tm,isNumber:Za,isBoolean:nm,isObject:Pr,isPlainObject:vo,isEmptyObject:rm,isReadableStream:dm,isRequest:fm,isResponse:pm,isHeaders:hm,isUndefined:cr,isDate:om,isFile:sm,isBlob:im,isRegExp:Im,isFunction:$t,isStream:lm,isURLSearchParams:um,isTypedArray:Sm,isFileList:am,forEach:Rr,merge:Qs,extend:gm,trim:mm,stripBOM:xm,inherits:ym,toFlatObject:vm,kindOf:xo,kindOfTest:on,endsWith:wm,toArray:bm,forEachEntry:Cm,matchAll:Tm,isHTMLForm:km,hasOwnProperty:tl,hasOwnProp:tl,reduceDescriptors:nl,freezeMethods:Am,toObjectSet:Nm,toCamelCase:Em,noop:_m,toFiniteNumber:jm,findKey:Qa,global:Kn,isContextDefined:el,isSpecCompliantForm:Mm,toJSONObject:Pm,isAsyncFn:Rm,isThenable:Om,setImmediate:rl,asap:Dm,isIterable:e=>e!=null&&$t(e[go])};function je(e,t,n,r,o){Error.call(this),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=new Error().stack,this.message=e,this.name="AxiosError",t&&(this.code=t),n&&(this.config=n),r&&(this.request=r),o&&(this.response=o,this.status=o.status?o.status:null)}O.inherits(je,Error,{toJSON:function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:O.toJSONObject(this.config),code:this.code,status:this.status}}});const ol=je.prototype,sl={};["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=>{sl[e]={value:e}}),Object.defineProperties(je,sl),Object.defineProperty(ol,"isAxiosError",{value:!0}),je.from=(e,t,n,r,o,s)=>{const i=Object.create(ol);O.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 je.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 Lm=null;function ei(e){return O.isPlainObject(e)||O.isArray(e)}function il(e){return O.endsWith(e,"[]")?e.slice(0,-2):e}function al(e,t,n){return e?e.concat(t).map(function(o,s){return o=il(o),!n&&s?"["+o+"]":o}).join(n?".":""):t}function $m(e){return O.isArray(e)&&!e.some(ei)}const Fm=O.toFlatObject(O,{},null,function(t){return/^is[A-Z]/.test(t)});function wo(e,t,n){if(!O.isObject(e))throw new TypeError("target must be an object");t=t||new FormData,n=O.toFlatObject(n,{metaTokens:!0,dots:!1,indexes:!1},!1,function(m,y){return!O.isUndefined(y[m])});const r=n.metaTokens,o=n.visitor||d,s=n.dots,i=n.indexes,l=(n.Blob||typeof Blob<"u"&&Blob)&&O.isSpecCompliantForm(t);if(!O.isFunction(o))throw new TypeError("visitor must be a function");function c(g){if(g===null)return"";if(O.isDate(g))return g.toISOString();if(O.isBoolean(g))return g.toString();if(!l&&O.isBlob(g))throw new je("Blob is not supported. Use a Buffer instead.");return O.isArrayBuffer(g)||O.isTypedArray(g)?l&&typeof Blob=="function"?new Blob([g]):Buffer.from(g):g}function d(g,m,y){let x=g;if(g&&!y&&typeof g=="object"){if(O.endsWith(m,"{}"))m=r?m:m.slice(0,-2),g=JSON.stringify(g);else if(O.isArray(g)&&$m(g)||(O.isFileList(g)||O.endsWith(m,"[]"))&&(x=O.toArray(g)))return m=il(m),x.forEach(function(S,k){!(O.isUndefined(S)||S===null)&&t.append(i===!0?al([m],k,s):i===null?m:m+"[]",c(S))}),!1}return ei(g)?!0:(t.append(al(y,m,s),c(g)),!1)}const f=[],p=Object.assign(Fm,{defaultVisitor:d,convertValue:c,isVisitable:ei});function h(g,m){if(!O.isUndefined(g)){if(f.indexOf(g)!==-1)throw Error("Circular reference detected in "+m.join("."));f.push(g),O.forEach(g,function(x,w){(!(O.isUndefined(x)||x===null)&&o.call(t,x,O.isString(w)?w.trim():w,m,p))===!0&&h(x,m?m.concat(w):[w])}),f.pop()}}if(!O.isObject(e))throw new TypeError("data must be an object");return h(e),t}function ll(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,function(r){return t[r]})}function ti(e,t){this._pairs=[],e&&wo(e,this,t)}const cl=ti.prototype;cl.append=function(t,n){this._pairs.push([t,n])},cl.toString=function(t){const n=t?function(r){return t.call(this,r,ll)}:ll;return this._pairs.map(function(o){return n(o[0])+"="+n(o[1])},"").join("&")};function Bm(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+")}function ul(e,t,n){if(!t)return e;const r=n&&n.encode||Bm;O.isFunction(n)&&(n={serialize:n});const o=n&&n.serialize;let s;if(o?s=o(t,n):s=O.isURLSearchParams(t)?t.toString():new ti(t,n).toString(r),s){const i=e.indexOf("#");i!==-1&&(e=e.slice(0,i)),e+=(e.indexOf("?")===-1?"?":"&")+s}return e}class dl{constructor(){this.handlers=[]}use(t,n,r){return this.handlers.push({fulfilled:t,rejected:n,synchronous:r?r.synchronous:!1,runWhen:r?r.runWhen:null}),this.handlers.length-1}eject(t){this.handlers[t]&&(this.handlers[t]=null)}clear(){this.handlers&&(this.handlers=[])}forEach(t){O.forEach(this.handlers,function(r){r!==null&&t(r)})}}const fl={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},zm={isBrowser:!0,classes:{URLSearchParams:typeof URLSearchParams<"u"?URLSearchParams:ti,FormData:typeof FormData<"u"?FormData:null,Blob:typeof Blob<"u"?Blob:null},protocols:["http","https","file","blob","url","data"]},ni=typeof window<"u"&&typeof document<"u",ri=typeof navigator=="object"&&navigator||void 0,Um=ni&&(!ri||["ReactNative","NativeScript","NS"].indexOf(ri.product)<0),Hm=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function",Wm=ni&&window.location.href||"http://localhost",At={...Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv:ni,hasStandardBrowserEnv:Um,hasStandardBrowserWebWorkerEnv:Hm,navigator:ri,origin:Wm},Symbol.toStringTag,{value:"Module"})),...zm};function Vm(e,t){return wo(e,new At.classes.URLSearchParams,{visitor:function(n,r,o,s){return At.isNode&&O.isBuffer(n)?(this.append(r,n.toString("base64")),!1):s.defaultVisitor.apply(this,arguments)},...t})}function Km(e){return O.matchAll(/\w+|\[(\w*)]/g,e).map(t=>t[0]==="[]"?"":t[1]||t[0])}function qm(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 pl(e){function t(n,r,o,s){let i=n[s++];if(i==="__proto__")return!0;const a=Number.isFinite(+i),l=s>=n.length;return i=!i&&O.isArray(o)?o.length:i,l?(O.hasOwnProp(o,i)?o[i]=[o[i],r]:o[i]=r,!a):((!o[i]||!O.isObject(o[i]))&&(o[i]=[]),t(n,r,o[i],s)&&O.isArray(o[i])&&(o[i]=qm(o[i])),!a)}if(O.isFormData(e)&&O.isFunction(e.entries)){const n={};return O.forEachEntry(e,(r,o)=>{t(Km(r),o,n,0)}),n}return null}function Gm(e,t,n){if(O.isString(e))try{return(t||JSON.parse)(e),O.trim(e)}catch(r){if(r.name!=="SyntaxError")throw r}return(n||JSON.stringify)(e)}const Or={transitional:fl,adapter:["xhr","http","fetch"],transformRequest:[function(t,n){const r=n.getContentType()||"",o=r.indexOf("application/json")>-1,s=O.isObject(t);if(s&&O.isHTMLForm(t)&&(t=new FormData(t)),O.isFormData(t))return o?JSON.stringify(pl(t)):t;if(O.isArrayBuffer(t)||O.isBuffer(t)||O.isStream(t)||O.isFile(t)||O.isBlob(t)||O.isReadableStream(t))return t;if(O.isArrayBufferView(t))return t.buffer;if(O.isURLSearchParams(t))return n.setContentType("application/x-www-form-urlencoded;charset=utf-8",!1),t.toString();let a;if(s){if(r.indexOf("application/x-www-form-urlencoded")>-1)return Vm(t,this.formSerializer).toString();if((a=O.isFileList(t))||r.indexOf("multipart/form-data")>-1){const l=this.env&&this.env.FormData;return wo(a?{"files[]":t}:t,l&&new l,this.formSerializer)}}return s||o?(n.setContentType("application/json",!1),Gm(t)):t}],transformResponse:[function(t){const n=this.transitional||Or.transitional,r=n&&n.forcedJSONParsing,o=this.responseType==="json";if(O.isResponse(t)||O.isReadableStream(t))return t;if(t&&O.isString(t)&&(r&&!this.responseType||o)){const i=!(n&&n.silentJSONParsing)&&o;try{return JSON.parse(t,this.parseReviver)}catch(a){if(i)throw a.name==="SyntaxError"?je.from(a,je.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:At.classes.FormData,Blob:At.classes.Blob},validateStatus:function(t){return t>=200&&t<300},headers:{common:{Accept:"application/json, text/plain, */*","Content-Type":void 0}}};O.forEach(["delete","get","head","post","put","patch"],e=>{Or.headers[e]={}});const Ym=O.toObjectSet(["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"]),Xm=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]&&Ym[n])&&(n==="set-cookie"?t[n]?t[n].push(r):t[n]=[r]:t[n]=t[n]?t[n]+", "+r:r)}),t},hl=Symbol("internals");function Dr(e){return e&&String(e).trim().toLowerCase()}function bo(e){return e===!1||e==null?e:O.isArray(e)?e.map(bo):String(e)}function Jm(e){const t=Object.create(null),n=/([^\s,;=]+)\s*(?:=\s*([^,;]+))?/g;let r;for(;r=n.exec(e);)t[r[1]]=r[2];return t}const Zm=e=>/^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(e.trim());function oi(e,t,n,r,o){if(O.isFunction(r))return r.call(this,t,n);if(o&&(t=n),!!O.isString(t)){if(O.isString(r))return t.indexOf(r)!==-1;if(O.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 eg(e,t){const n=O.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=Dr(l);if(!d)throw new Error("header name must be a non-empty string");const f=O.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)=>O.forEach(a,(c,d)=>s(c,d,l));if(O.isPlainObject(t)||t instanceof this.constructor)i(t,n);else if(O.isString(t)&&(t=t.trim())&&!Zm(t))i(Xm(t),n);else if(O.isObject(t)&&O.isIterable(t)){let a={},l,c;for(const d of t){if(!O.isArray(d))throw TypeError("Object iterator must return a key-value pair");a[c=d[0]]=(l=a[c])?O.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=Dr(t),t){const r=O.findKey(this,t);if(r){const o=this[r];if(!n)return o;if(n===!0)return Jm(o);if(O.isFunction(n))return n.call(this,o,r);if(O.isRegExp(n))return n.exec(o);throw new TypeError("parser must be boolean|regexp|function")}}}has(t,n){if(t=Dr(t),t){const r=O.findKey(this,t);return!!(r&&this[r]!==void 0&&(!n||oi(this,this[r],r,n)))}return!1}delete(t,n){const r=this;let o=!1;function s(i){if(i=Dr(i),i){const a=O.findKey(r,i);a&&(!n||oi(r,r[a],a,n))&&(delete r[a],o=!0)}}return O.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||oi(this,this[s],s,t,!0))&&(delete this[s],o=!0)}return o}normalize(t){const n=this,r={};return O.forEach(this,(o,s)=>{const i=O.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 O.forEach(this,(r,o)=>{r!=null&&r!==!1&&(n[o]=t&&O.isArray(r)?r.join(", "):r)}),n}[Symbol.iterator](){return Object.entries(this.toJSON())[Symbol.iterator]()}toString(){return Object.entries(this.toJSON()).map(([t,n])=>t+": "+n).join(`
|
|
32
|
+
`)}getSetCookie(){return this.get("set-cookie")||[]}get[Symbol.toStringTag](){return"AxiosHeaders"}static from(t){return t instanceof this?t:new this(t)}static concat(t,...n){const r=new this(t);return n.forEach(o=>r.set(o)),r}static accessor(t){const r=(this[hl]=this[hl]={accessors:{}}).accessors,o=this.prototype;function s(i){const a=Dr(i);r[a]||(eg(o,i),r[a]=!0)}return O.isArray(t)?t.forEach(s):s(t),this}};Ft.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),O.reduceDescriptors(Ft.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(r){this[n]=r}}}),O.freezeMethods(Ft);function si(e,t){const n=this||Or,r=t||n,o=Ft.from(r.headers);let s=r.data;return O.forEach(e,function(a){s=a.call(n,s,o.normalize(),t?t.status:void 0)}),o.normalize(),s}function ml(e){return!!(e&&e.__CANCEL__)}function ur(e,t,n){je.call(this,e??"canceled",je.ERR_CANCELED,t,n),this.name="CanceledError"}O.inherits(ur,je,{__CANCEL__:!0});function gl(e,t,n){const r=n.config.validateStatus;!n.status||!r||r(n.status)?e(n):t(new je("Request failed with status code "+n.status,[je.ERR_BAD_REQUEST,je.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n))}function tg(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function ng(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 rg(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 So=(e,t,n=3)=>{let r=0;const o=ng(50,250);return rg(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)},xl=(e,t)=>{const n=e!=null;return[r=>t[0]({lengthComputable:n,total:e,loaded:r}),t[1]]},yl=e=>(...t)=>O.asap(()=>e(...t)),og=At.hasStandardBrowserEnv?((e,t)=>n=>(n=new URL(n,At.origin),e.protocol===n.protocol&&e.host===n.host&&(t||e.port===n.port)))(new URL(At.origin),At.navigator&&/(msie|trident)/i.test(At.navigator.userAgent)):()=>!0,sg=At.hasStandardBrowserEnv?{write(e,t,n,r,o,s){const i=[e+"="+encodeURIComponent(t)];O.isNumber(n)&&i.push("expires="+new Date(n).toGMTString()),O.isString(r)&&i.push("path="+r),O.isString(o)&&i.push("domain="+o),s===!0&&i.push("secure"),document.cookie=i.join("; ")},read(e){const t=document.cookie.match(new RegExp("(^|;\\s*)("+e+")=([^;]*)"));return t?decodeURIComponent(t[3]):null},remove(e){this.write(e,"",Date.now()-864e5)}}:{write(){},read(){return null},remove(){}};function ig(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function ag(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function vl(e,t,n){let r=!ig(t);return e&&(r||n==!1)?ag(e,t):t}const wl=e=>e instanceof Ft?{...e}:e;function qn(e,t){t=t||{};const n={};function r(c,d,f,p){return O.isPlainObject(c)&&O.isPlainObject(d)?O.merge.call({caseless:p},c,d):O.isPlainObject(d)?O.merge({},d):O.isArray(d)?d.slice():d}function o(c,d,f,p){if(O.isUndefined(d)){if(!O.isUndefined(c))return r(void 0,c,f,p)}else return r(c,d,f,p)}function s(c,d){if(!O.isUndefined(d))return r(void 0,d)}function i(c,d){if(O.isUndefined(d)){if(!O.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(wl(c),wl(d),f,!0)};return O.forEach(Object.keys({...e,...t}),function(d){const f=l[d]||o,p=f(e[d],t[d],d);O.isUndefined(p)&&f!==a||(n[d]=p)}),n}const bl=e=>{const t=qn({},e);let{data:n,withXSRFToken:r,xsrfHeaderName:o,xsrfCookieName:s,headers:i,auth:a}=t;if(t.headers=i=Ft.from(i),t.url=ul(vl(t.baseURL,t.url,t.allowAbsoluteUrls),e.params,e.paramsSerializer),a&&i.set("Authorization","Basic "+btoa((a.username||"")+":"+(a.password?unescape(encodeURIComponent(a.password)):""))),O.isFormData(n)){if(At.hasStandardBrowserEnv||At.hasStandardBrowserWebWorkerEnv)i.setContentType(void 0);else if(O.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(At.hasStandardBrowserEnv&&(r&&O.isFunction(r)&&(r=r(t)),r||r!==!1&&og(t.url))){const l=o&&s&&sg.read(s);l&&i.set(o,l)}return t},lg=typeof XMLHttpRequest<"u"&&function(e){return new Promise(function(n,r){const o=bl(e);let s=o.data;const i=Ft.from(o.headers).normalize();let{responseType:a,onUploadProgress:l,onDownloadProgress:c}=o,d,f,p,h,g;function m(){h&&h(),g&&g(),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};gl(function(E){n(E),m()},function(E){r(E),m()},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 je("Request aborted",je.ECONNABORTED,e,y)),y=null)},y.onerror=function(k){const C=k&&k.message?k.message:"Network Error",T=new je(C,je.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||fl;o.timeoutErrorMessage&&(k=o.timeoutErrorMessage),r(new je(k,C.clarifyTimeoutError?je.ETIMEDOUT:je.ECONNABORTED,e,y)),y=null},s===void 0&&i.setContentType(null),"setRequestHeader"in y&&O.forEach(i.toJSON(),function(k,C){y.setRequestHeader(C,k)}),O.isUndefined(o.withCredentials)||(y.withCredentials=!!o.withCredentials),a&&a!=="json"&&(y.responseType=o.responseType),c&&([p,g]=So(c,!0),y.addEventListener("progress",p)),l&&y.upload&&([f,h]=So(l),y.upload.addEventListener("progress",f),y.upload.addEventListener("loadend",h)),(o.cancelToken||o.signal)&&(d=S=>{y&&(r(!S||S.type?new ur(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 w=tg(o.url);if(w&&At.protocols.indexOf(w)===-1){r(new je("Unsupported protocol "+w+":",je.ERR_BAD_REQUEST,e));return}y.send(s||null)})},cg=(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 je?d:new ur(d instanceof Error?d.message:d))}};let i=t&&setTimeout(()=>{i=null,s(new je(`timeout ${t} of ms exceeded`,je.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=()=>O.asap(a),l}},ug=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},dg=async function*(e,t){for await(const n of fg(e))yield*ug(n,t)},fg=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()}},Sl=(e,t,n,r)=>{const o=dg(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})},Cl=64*1024,{isFunction:Co}=O,pg=(({Request:e,Response:t})=>({Request:e,Response:t}))(O.global),{ReadableStream:Tl,TextEncoder:kl}=O.global,El=(e,...t)=>{try{return!!e(...t)}catch{return!1}},hg=e=>{e=O.merge.call({skipUndefined:!0},pg,e);const{fetch:t,Request:n,Response:r}=e,o=t?Co(t):typeof fetch=="function",s=Co(n),i=Co(r);if(!o)return!1;const a=o&&Co(Tl),l=o&&(typeof kl=="function"?(g=>m=>g.encode(m))(new kl):async g=>new Uint8Array(await new n(g).arrayBuffer())),c=s&&a&&El(()=>{let g=!1;const m=new n(At.origin,{body:new Tl,method:"POST",get duplex(){return g=!0,"half"}}).headers.has("Content-Type");return g&&!m}),d=i&&a&&El(()=>O.isReadableStream(new r("").body)),f={stream:d&&(g=>g.body)};o&&["text","arrayBuffer","blob","formData","stream"].forEach(g=>{!f[g]&&(f[g]=(m,y)=>{let x=m&&m[g];if(x)return x.call(m);throw new je(`Response type '${g}' is not supported`,je.ERR_NOT_SUPPORT,y)})});const p=async g=>{if(g==null)return 0;if(O.isBlob(g))return g.size;if(O.isSpecCompliantForm(g))return(await new n(At.origin,{method:"POST",body:g}).arrayBuffer()).byteLength;if(O.isArrayBufferView(g)||O.isArrayBuffer(g))return g.byteLength;if(O.isURLSearchParams(g)&&(g=g+""),O.isString(g))return(await l(g)).byteLength},h=async(g,m)=>{const y=O.toFiniteNumber(g.getContentLength());return y??p(m)};return async g=>{let{url:m,method:y,data:x,signal:w,cancelToken:S,timeout:k,onDownloadProgress:C,onUploadProgress:T,responseType:E,headers:N,withCredentials:_="same-origin",fetchOptions:D}=bl(g),B=t||fetch;E=E?(E+"").toLowerCase():"text";let G=cg([w,S&&S.toAbortSignal()],k),V=null;const P=G&&G.unsubscribe&&(()=>{G.unsubscribe()});let M;try{if(T&&c&&y!=="get"&&y!=="head"&&(M=await h(N,x))!==0){let X=new n(m,{method:"POST",body:x,duplex:"half"}),ne;if(O.isFormData(x)&&(ne=X.headers.get("content-type"))&&N.setContentType(ne),X.body){const[ye,Te]=xl(M,So(yl(T)));x=Sl(X.body,Cl,ye,Te)}}O.isString(_)||(_=_?"include":"omit");const A=s&&"credentials"in n.prototype,F={...D,signal:G,method:y.toUpperCase(),headers:N.normalize().toJSON(),body:x,duplex:"half",credentials:A?_:void 0};V=s&&new n(m,F);let L=await(s?B(V,D):B(m,F));const R=d&&(E==="stream"||E==="response");if(d&&(C||R&&P)){const X={};["status","statusText","headers"].forEach(q=>{X[q]=L[q]});const ne=O.toFiniteNumber(L.headers.get("content-length")),[ye,Te]=C&&xl(ne,So(yl(C),!0))||[];L=new r(Sl(L.body,Cl,ye,()=>{Te&&Te(),P&&P()}),X)}E=E||"text";let z=await f[O.findKey(f,E)||"text"](L,g);return!R&&P&&P(),await new Promise((X,ne)=>{gl(X,ne,{data:z,headers:Ft.from(L.headers),status:L.status,statusText:L.statusText,config:g,request:V})})}catch(A){throw P&&P(),A&&A.name==="TypeError"&&/Load failed|fetch/i.test(A.message)?Object.assign(new je("Network Error",je.ERR_NETWORK,g,V),{cause:A.cause||A}):je.from(A,A&&A.code,g,V)}}},mg=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=mg;for(;a--;)l=s[a],c=d.get(l),c===void 0&&d.set(l,c=a?new Map:hg(t)),d=c;return c};Il();const ii={http:Lm,xhr:lg,fetch:{get:Il}};O.forEach(ii,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const Al=e=>`- ${e}`,gg=e=>O.isFunction(e)||e===null||e===!1,Nl={getAdapter:(e,t)=>{e=O.isArray(e)?e:[e];const{length:n}=e;let r,o;const s={};for(let i=0;i<n;i++){r=e[i];let a;if(o=r,!gg(r)&&(o=ii[(a=String(r)).toLowerCase()],o===void 0))throw new je(`Unknown adapter '${a}'`);if(o&&(O.isFunction(o)||(o=o.get(t))))break;s[a||"#"+i]=o}if(!o){const i=Object.entries(s).map(([l,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(Al).join(`
|
|
34
|
+
`):" "+Al(i[0]):"as no adapter specified";throw new je("There is no suitable adapter to dispatch the request "+a,"ERR_NOT_SUPPORT")}return o},adapters:ii};function ai(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new ur(null,e)}function _l(e){return ai(e),e.headers=Ft.from(e.headers),e.data=si.call(e,e.transformRequest),["post","put","patch"].indexOf(e.method)!==-1&&e.headers.setContentType("application/x-www-form-urlencoded",!1),Nl.getAdapter(e.adapter||Or.adapter,e)(e).then(function(r){return ai(e),r.data=si.call(e,e.transformResponse,r),r.headers=Ft.from(r.headers),r},function(r){return ml(r)||(ai(e),r&&r.response&&(r.response.data=si.call(e,e.transformResponse,r.response),r.response.headers=Ft.from(r.response.headers))),Promise.reject(r)})}const jl="1.12.2",To={};["object","boolean","number","function","string","symbol"].forEach((e,t)=>{To[e]=function(r){return typeof r===e||"a"+(t<1?"n ":" ")+e}});const Ml={};To.transitional=function(t,n,r){function o(s,i){return"[Axios v"+jl+"] Transitional option '"+s+"'"+i+(r?". "+r:"")}return(s,i,a)=>{if(t===!1)throw new je(o(i," has been removed"+(n?" in "+n:"")),je.ERR_DEPRECATED);return n&&!Ml[i]&&(Ml[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}},To.spelling=function(t){return(n,r)=>(console.warn(`${r} is likely a misspelling of ${t}`),!0)};function xg(e,t,n){if(typeof e!="object")throw new je("options must be an object",je.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 je("option "+s+" must be "+l,je.ERR_BAD_OPTION_VALUE);continue}if(n!==!0)throw new je("Unknown option "+s,je.ERR_BAD_OPTION)}}const ko={assertOptions:xg,validators:To},fn=ko.validators;let Gn=class{constructor(t){this.defaults=t||{},this.interceptors={request:new dl,response:new dl}}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=qn(this.defaults,n);const{transitional:r,paramsSerializer:o,headers:s}=n;r!==void 0&&ko.assertOptions(r,{silentJSONParsing:fn.transitional(fn.boolean),forcedJSONParsing:fn.transitional(fn.boolean),clarifyTimeoutError:fn.transitional(fn.boolean)},!1),o!=null&&(O.isFunction(o)?n.paramsSerializer={serialize:o}:ko.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),ko.assertOptions(n,{baseUrl:fn.spelling("baseURL"),withXsrfToken:fn.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let i=s&&O.merge(s.common,s[n.method]);s&&O.forEach(["delete","get","head","post","put","patch","common"],g=>{delete s[g]}),n.headers=Ft.concat(i,s);const a=[];let l=!0;this.interceptors.request.forEach(function(m){typeof m.runWhen=="function"&&m.runWhen(n)===!1||(l=l&&m.synchronous,a.unshift(m.fulfilled,m.rejected))});const c=[];this.interceptors.response.forEach(function(m){c.push(m.fulfilled,m.rejected)});let d,f=0,p;if(!l){const g=[_l.bind(this),void 0];for(g.unshift(...a),g.push(...c),p=g.length,d=Promise.resolve(n);f<p;)d=d.then(g[f++],g[f++]);return d}p=a.length;let h=n;for(;f<p;){const g=a[f++],m=a[f++];try{h=g(h)}catch(y){m.call(this,y);break}}try{d=_l.call(this,h)}catch(g){return Promise.reject(g)}for(f=0,p=c.length;f<p;)d=d.then(c[f++],c[f++]);return d}getUri(t){t=qn(this.defaults,t);const n=vl(t.baseURL,t.url,t.allowAbsoluteUrls);return ul(n,t.params,t.paramsSerializer)}};O.forEach(["delete","get","head","options"],function(t){Gn.prototype[t]=function(n,r){return this.request(qn(r||{},{method:t,url:n,data:(r||{}).data}))}}),O.forEach(["post","put","patch"],function(t){function n(r){return function(s,i,a){return this.request(qn(a||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:s,data:i}))}}Gn.prototype[t]=n(),Gn.prototype[t+"Form"]=n(!0)});let yg=class Gh{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 Gh(function(o){t=o}),cancel:t}}};function vg(e){return function(n){return e.apply(null,n)}}function wg(e){return O.isObject(e)&&e.isAxiosError===!0}const li={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(li).forEach(([e,t])=>{li[t]=e});function Pl(e){const t=new Gn(e),n=Ya(Gn.prototype.request,t);return O.extend(n,Gn.prototype,t,{allOwnKeys:!0}),O.extend(n,t,null,{allOwnKeys:!0}),n.create=function(o){return Pl(qn(e,o))},n}const yt=Pl(Or);yt.Axios=Gn,yt.CanceledError=ur,yt.CancelToken=yg,yt.isCancel=ml,yt.VERSION=jl,yt.toFormData=wo,yt.AxiosError=je,yt.Cancel=yt.CanceledError,yt.all=function(t){return Promise.all(t)},yt.spread=vg,yt.isAxiosError=wg,yt.mergeConfig=qn,yt.AxiosHeaders=Ft,yt.formToJSON=e=>pl(O.isHTMLForm(e)?new FormData(e):e),yt.getAdapter=Nl.getAdapter,yt.HttpStatusCode=li,yt.default=yt;const{Axios:VT,AxiosError:KT,CanceledError:qT,isCancel:GT,CancelToken:YT,VERSION:XT,all:JT,Cancel:ZT,isAxiosError:QT,spread:ek,toFormData:tk,AxiosHeaders:nk,HttpStatusCode:rk,formToJSON:ok,getAdapter:sk,mergeConfig:ik}=yt,Rl=typeof window<"u"?window.__API_BASE_URL__:void 0,Ol=Rl?Cn(Rl):void 0;function Cn(e){const n=(e!=null&&e.trim()?e.trim():"/api/chat").replace(/\/+$/,"");return n?n.endsWith("/chat")?n:`${n}/chat`:"/api/chat"}let Eo=null;const ci=new Set;function Dl(){return Eo}function Io(e){Eo=e,ci.forEach(t=>t(e))}function Ll(e){return ci.add(e),()=>ci.delete(e)}const bg=3e4,Sg=9e4,qt=yt.create({...Ol?{baseURL:Ol}:{},timeout:bg,withCredentials:!0});qt.interceptors.request.use(e=>(Eo&&(e.headers.Authorization=`Bearer ${Eo}`),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 ui(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 $l(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 Fl(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 Bl{get baseUrl(){const t=qt.defaults.baseURL;return t?Cn(String(t)):""}updateConfig(t){t.baseUrl&&(qt.defaults.baseURL=Cn(String(t.baseUrl))),t.authToken!==void 0&&Io(t.authToken)}getAuthToken(){return Dl()}setAuthToken(t){Io(t)}onTokenChange(t){return Ll(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 ui("/threads",t?{title:t}:void 0);return Yt(r)}async updateThread(t,n){const r=await $l(`/threads/${t}`,{title:n});return Yt(r)}async deleteThread(t){const n=await Fl(`/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:Sg});return Yt(n)}async cancelRun(t){const n=await ui("/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 _n=new Bl,zl=b.createContext(null);function Cg({children:e,apiConfig:t}){const n=_n;if(t){const o=n.baseUrl,s=n.getAuthToken();t.baseUrl&&t.baseUrl!==o&&n.updateConfig({baseUrl:t.baseUrl}),t.apiKey!==void 0&&t.apiKey!==s&&n.updateConfig({authToken:t.apiKey})}const r={token:n.getAuthToken(),setToken:o=>n.setAuthToken(o),api:n,baseUrl:n.baseUrl};return u.jsx(zl.Provider,{value:r,children:e})}function di(){const e=b.useContext(zl);if(!e)throw new Error("useApi must be used within ApiProvider");return e}async function Tg(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 kg(e,t=[],n,r,o,s){const i=[],a=[];for(const l of t)try{const c=await Tg(l);a.push({filename:l.name,data:c,mime_type:l.type||"application/octet-stream"})}catch{}return{contentParts:i,filesInfo:a}}const Eg={human:"user",user:"user",ai:"assistant",assistant:"assistant",tool:"tool",function:"tool",system:"system"};function fi(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 Ig(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(!fi(r))return{threadId:n,latest:null,checkpoints:[],timeline:[],interrupt:null,snapshots:{}};const{orderedSnapshots:o,snapshotMap:s}=Ng(t),i=Ul(r,0),a=_g(o);return{threadId:n,latest:i,checkpoints:o,timeline:a,interrupt:(i==null?void 0:i.interrupt)??null,snapshots:s}}function Ul(e,t){if(!fi(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((_,D)=>Fg(_,D)).filter(_=>!!_),d=Ot(e.config),f=Ot(d==null?void 0:d.configurable),p=dt(f,["checkpoint_id","checkpointId"]),h=dt(f,["checkpoint_ns","checkpointNs"]),g=Ot(e==null?void 0:e.parentConfig),m=Ot(g==null?void 0:g.configurable),y=dt(m,["checkpoint_id","checkpointId"])??null,x=dt(m,["checkpoint_ns","checkpointNs"])??null,w=e==null?void 0:e.createdAt,S=typeof w=="string"&&w.trim()?w:new Date(Date.now()-t).toISOString(),k=c.slice().reverse().find(_=>_.role==="user")??null,C=Ot(e==null?void 0:e.metadata),T=dt(C,["branch_label","branchLabel"]),E=dt(m,["checkpoint_id","checkpointId"]),N=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:Ag(a,c,t),createdAt:S,parentId:E??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:g??null,next:N??null,tasks:l??null,values:i??null}}function Ag(e,t,n){const r=Lg(e,n);return r||Dg(t,n)}function Ng(e){const t=new Map;e.forEach((o,s)=>{if(!fi(o))return;const i=Ul(o,s);if(!(i!=null&&i.checkpointId))return;const a=Ig(i.checkpointId,i.checkpointNs??null),l=t.get(a);if(!l){t.set(a,i);return}t.set(a,Pg(l,i))});const n=Array.from(t.values());n.sort((o,s)=>Wl(s.createdAt??"")-Wl(o.createdAt??""));const r={};for(const[o,s]of t.entries())r[o]=s;return{orderedSnapshots:n,snapshotMap:r}}function _g(e){var n,r;const t=[];for(const o of e){const s=o.checkpointId??null;if(!s)continue;const i=o.metadata??{},a=dt(i,["label"])??dt(i,["branch_label","branchLabel"])??dt(i,["description"])??"User input",l=Mg(i,["step"]),c=dt(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=jg(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 jg(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 Mg(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 Pg(e,t){return{...e,metadata:Ao(e.metadata,t.metadata)??null,config:Ao(e.config,t.config)??null,parentConfig:Ao(e.parentConfig,t.parentConfig)??null,next:Rg(e.next,t.next)??null,tasks:Og(e.tasks,t.tasks)??null,values:Ao(e.values,t.values)??null}}function Ao(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 Rg(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 Og(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 Dg(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 Lg(e,t){if(!Array.isArray(e)||!e.length)return null;for(let n=e.length-1;n>=0;n--){const r=$g(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=Lr(r.interrupts[s],`${o}-interrupt-${s}`);if(i)return i}if(r.state!==void 0&&r.state!==null){const s=Lr(r.state,`${o}-state`);if(s)return s}}return null}function $g(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,g=typeof l=="string"&&l.trim()?l:Array.isArray(c)&&typeof c[0]=="string"?String(c[0]):"task",m=Array.isArray(d)?d:void 0,y=p.length?p[p.length-1]:void 0;return{id:h,name:g,interrupts:m,state:y!==void 0?y:f}}const n=Ot(e);if(!n)return null;const r=dt(n,["id","thread_id","taskId"])??t,o=dt(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 Lr(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=Hl(e,t);if(o)return o;if(Array.isArray(e)){for(let s=e.length-1;s>=0;s--){const i=Lr(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=Lr(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=Lr(l,t,n+1,r);if(c)return c}}return null}function Hl(e,t){if(!e)return null;if(typeof e=="object"&&!Array.isArray(e)){const n=e,r=dt(n,["type","event","kind"]),o=dt(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=Hl(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 Wl(e){if(!e)return 0;const t=Date.parse(e);return Number.isFinite(t)?t:0}function Fg(e,t){if(!e||typeof e!="object")return null;const n=e,r=Ot(e)??{},o=Ot(n.data)??r,s=String(n.type??o.type??o.role??"").toLowerCase(),i=Eg[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=Ot(o.additional_kwargs)??Ot(o.additionalKwargs),d=Ot(o.response_metadata)??Ot(o.responseMetadata),f=dt(c,["createdAt","created_at"])??dt(o,["created_at","createdAt"]),p=dt(c,["checkpointId","checkpoint_id"]),h=dt(c,["checkpointNs","checkpoint_ns"]),g=Bg(o.content),m={id:l,role:i,content:g};f&&(m.createdAt=f),typeof o.name=="string"&&o.name.trim()&&(m.name=o.name),typeof(d==null?void 0:d.model_name)=="string"&&(m.model=String(d.model_name)),!m.model&&typeof o.model=="string"&&(m.model=o.model),p&&(m.checkpointId=p),h&&(m.checkpointNs=h);const y=Hg(Ot(o.artifact??r.artifact??o.artifacts??r.artifacts));y&&(m.artifact=y);const x=qg(c,["createdAt","created_at","checkpointId","checkpoint_id","checkpointNs","checkpoint_ns","tool_calls"]),w=d?{...d}:void 0;x&&Object.keys(x).length&&(m.additionalKwargs=x),w&&Object.keys(w).length&&(m.responseMetadata=w);const S=zg((c==null?void 0:c.tool_calls)??o.tool_calls);if(S.length&&(m.content=[...m.content,...S]),i==="tool"){const k=Ug(o,m.content);k&&(m.content=k)}return m}function Bg(e){if(!e)return[];if(Array.isArray(e))return e.map(t=>Vl(t)).filter(t=>!!t);if(typeof e=="string")return e.trim()?[{type:"text",text:e.trim()}]:[];if(typeof e=="object"){const t=Vl(e);return t?[t]:[]}return[]}function Vl(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=dt(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=dt(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 Kl(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=dt(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 Kl(e,t){var s;const n=dt(e,["id","call_id"])??t,r=dt(e,["name"])??dt(Ot(e.function),["name"]);if(!n||!r)return null;const o=Kg(e.args??e.arguments??((s=Ot(e.function))==null?void 0:s.arguments));return{type:"tool_call",id:n,name:r,args:o}}function zg(e){return Array.isArray(e)?e.map((t,n)=>Kl(t,`tool_call_${n}`)).filter(t=>!!t):[]}function Ug(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 Hg(e){return e?{plots:Wg(e.plots)}:void 0}function Wg(e){return Array.isArray(e)?e.map(t=>Vg(t)).filter(t=>!!t):[]}function Vg(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 Kg(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 Ot(e){if(!(!e||typeof e!="object"||Array.isArray(e)))return{...e}}function dt(e,t){if(e)for(const n of t){const r=e[n];if(typeof r=="string"&&r.trim())return r}}function qg(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 ql=120;function Gg(e){if(!Array.isArray(e))return"";const t=e.filter(r=>!!(r&&r.type==="text")).map(r=>(r.text??"").trim()).filter(Boolean);if(!t.length)return"";const n=t.join(" ").replace(/\s+/g," ").trim();return n?n.length>ql?`${n.slice(0,ql-3)}…`:n:""}function Gl(e){return Gg(e.content)||""}function Yg(e){const t=new Map;for(const n of e){if(!n.id||n.role!=="user")continue;const r=Gl(n);r&&t.set(n.id,r)}return t}function Xg(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=Gl(o);s&&t.set(r.checkpointId,s)}}return t}const Yl="aiNav:tool-progress";function pi(){return typeof window<"u"&&typeof window.localStorage<"u"}function Xl(e){return`${Yl}:${e}`}function Jg(e,t,n){if(!pi()||!e)return;const r=Xl(e);if(!t.length){window.localStorage.removeItem(r);return}const o={messageId:e,entries:t,updatedAt:Date.now(),...n??{}};try{window.localStorage.setItem(r,JSON.stringify(o))}catch{}}function Zg(e){if(!pi()||!e)return;const t=Xl(e),n=window.localStorage.getItem(t);if(n)try{const r=JSON.parse(n);return!(r!=null&&r.entries)||!Array.isArray(r.entries)?void 0:r.entries}catch{window.localStorage.removeItem(t);return}}function Jl(){if(!pi())return;const e=[];for(let t=0;t<window.localStorage.length;t+=1){const n=window.localStorage.key(t);n!=null&&n.startsWith(Yl)&&e.push(n)}for(const t of e)window.localStorage.removeItem(t)}const Tt=[];for(let e=0;e<256;++e)Tt.push((e+256).toString(16).slice(1));function Qg(e,t=0){return(Tt[e[t+0]]+Tt[e[t+1]]+Tt[e[t+2]]+Tt[e[t+3]]+"-"+Tt[e[t+4]]+Tt[e[t+5]]+"-"+Tt[e[t+6]]+Tt[e[t+7]]+"-"+Tt[e[t+8]]+Tt[e[t+9]]+"-"+Tt[e[t+10]]+Tt[e[t+11]]+Tt[e[t+12]]+Tt[e[t+13]]+Tt[e[t+14]]+Tt[e[t+15]]).toLowerCase()}let hi;const ex=new Uint8Array(16);function tx(){if(!hi){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");hi=crypto.getRandomValues.bind(crypto)}return hi(ex)}const Zl={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function nx(e,t,n){var o;e=e||{};const r=e.random??((o=e.rng)==null?void 0:o.call(e))??tx();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 rx(e,t,n){return Zl.randomUUID&&!e?Zl.randomUUID():nx(e)}const ox={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},toolStreamingMessageId:null,toolStreamingStack:[],messagesStreamMeta:{},pendingInterrupt:null,toolTimelines:{}};function sx(e,t){var n;switch(t.type){case"reset":return{messages:mi(((n=t.payload)==null?void 0:n.messages)??[]),assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},toolStreamingMessageId:null,toolStreamingStack:[],pendingInterrupt:null,toolTimelines:{}};case"seed":{const r=mi(t.payload.messages),{messages:o,toolTimelines:s}=fr(r,e.toolTimelines),i={...e,messages:o,assemblingId:null,pendingInterrupt:t.payload.pendingInterrupt??null,toolStreamingMessageId:null,toolStreamingStack:[],toolTimelines:s};return Object.prototype.hasOwnProperty.call(t.payload,"checkpointId")&&(i.lastCheckpointId=t.payload.checkpointId??null),Object.prototype.hasOwnProperty.call(t.payload,"checkpointNs")&&(i.lastCheckpointNs=t.payload.checkpointNs??null),i}case"prepend":{const r=mi(t.payload.messages);if(!r.length)return e;const o=new Set(e.messages.map(c=>c.id)),s=r.filter(c=>!o.has(c.id));if(!s.length)return e;const i=[...s,...e.messages],{messages:a,toolTimelines:l}=fr(i,e.toolTimelines);return{...e,messages:a,toolTimelines:l}}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 ec(e,t.payload.ev);case"batch":{const{events:r}=t.payload;return r.length?r.reduce((o,s)=>ec(o,s),e):e}case"interrupt_response":return{...e,messages:tc(e.messages),pendingInterrupt:null};default:return e}}function Ql(e=[]){const[t,n]=b.useReducer(sx,{...ox,messages:e}),r=b.useRef([]),o=b.useRef(null),s=b.useRef(null),i=b.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=b.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=b.useCallback(d=>{r.current.push(d),a()},[a]);b.useEffect(()=>()=>{o.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.current),s.current!==null&&clearTimeout(s.current),r.current=[]},[]);const c=b.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 ec(e,t){var n,r,o,s;if(t.type==="message.start"&&t.role==="assistant"){const i=t.id,a=hx(t.model);if(e.messages.some(d=>d.id===i)){const d=e.messagesStreamMeta??{},f={...d,[i]:d[i]??{lastSeq:t.seq??null,lastText:""}};return{...e,assemblingId:i,messagesStreamMeta:f}}const c={id:i,role:"assistant",name:a||void 0,model:t.model,createdAt:new Date().toISOString(),content:[]};return{...e,assemblingId:i,messages:[...e.messages,c]}}if(t.type==="message.delta"){const i=e.assemblingId??nc(e.messages);if(!i)return e;const a=e.messages,l=a.findIndex(S=>S.id===i&&S.role==="assistant");if(l===-1)return e;const c=a[l],d=e.messagesStreamMeta??{},f=d[i]??{lastSeq:null,lastText:ic(c.content)},p=t.seq??null;if(p!==null&&typeof p=="number"&&typeof f.lastSeq=="number"&&p<=f.lastSeq)return console.debug("[MessageReducer] skipping delta - seq <= lastSeq",{seq:p,lastSeq:f.lastSeq}),e;const{newParts:h,newMeta:g,changed:m}=dx(c.content,t.delta,f,p);if(!m)return e;const y={...c,content:h},x=No(a,l,y),w={...d,[i]:g};return{...e,messages:x,messagesStreamMeta:w}}if(t.type==="message.end"){const i=e.assemblingId??nc(e.messages);if(!i)return{...e,assemblingId:null};const a=e.messages,l=a.findIndex(c=>c.id===i&&c.role==="assistant");if(l>=0){const c=a[l];if(!((n=c.content)==null?void 0:n.some(f=>{var p;return(f==null?void 0:f.type)==="text"&&((p=f.text)==null?void 0:p.trim())}))){console.debug("[MessageReducer] pruning assistant message with no visible text",{id:c.id,contentTypes:(r=c.content)==null?void 0:r.map(p=>p==null?void 0:p.type),contentPreview:(o=c.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 f=[...a.slice(0,l),...a.slice(l+1)];return{...e,assemblingId:null,messages:f}}}return e}if(t.type==="tool.start"){const i=rc(t),a=i[0]??(typeof t.id=="string"?t.id:null)??(typeof t.call_id=="string"?t.call_id:null),l=t.name??t.tool??"tool";!a&&i.length===0&&i.push(`${l}-${Date.now()}`);const c=i.length?i:a?[a]:[],d=c[0]??`${l}-${Date.now()}`,f={type:"tool_call",id:d,name:l,args:t.args},p={type:e.toolStreamingMessageId?"tool.call":"tool.start",toolId:a??d,toolName:l,metadata:{args:t.args}},h=e.toolStreamingMessageId;if(!h){const w={id:`tool-${d}`,role:"tool",name:l,createdAt:new Date().toISOString(),content:[f],additionalKwargs:{...ax(void 0,c.length?c:[d],l,t.args),toolStreaming:!0}},S=lx(w,c.length?c:[d]),k=[...e.messages,w],C=_o(k,w.id,p),{messages:T,toolTimelines:E}=fr(C,e.toolTimelines);return{...e,messages:T,toolIndex:oc(e.toolIndex,w.id,S),toolStreamingMessageId:w.id,toolStreamingStack:sc(e.toolStreamingStack??[],a??d),toolTimelines:E}}const g=_o(e.messages,h,p),{messages:m,toolTimelines:y}=fr(g,e.toolTimelines);return{...e,messages:m,toolIndex:oc(e.toolIndex,h,c),toolStreamingStack:sc(e.toolStreamingStack??[],a??d),toolTimelines:y}}if(t.type==="tool.end"){const i=rc(t);if(!i.length&&!(typeof t.id=="string"&&t.id))return e;const a=i[0]??(typeof t.id=="string"?t.id:null);if(!a)return e;const l=e.toolStreamingStack??[],c=l[0]??null,d=cx(l,a),f=d[0]?e.toolIndex[d[0]]:null,p=e.toolStreamingMessageId,h=c===a,g=t.name??((s=e.messages.find(C=>C.id===p))==null?void 0:s.name)??"tool",m=typeof t.output=="string"?t.output.trim():JSON.stringify(t.output??""),y={type:"tool.end",toolId:a,toolName:g,content:m==null?void 0:m.slice(0,200)};let x=e.messages;if(p&&(x=_o(x,p,y)),h&&p){const C=x.findIndex(T=>T.id===p);if(C>=0){const T=x[C],N={type:"text",text:(()=>{if(typeof t.output=="string"){const D=t.output.trim();try{return D}catch{return D}}return JSON.stringify(t.output??"")})()},_={...T,content:[N],artifact:t.artifact??T.artifact,additionalKwargs:{...T.additionalKwargs??{}}};x=No(x,C,_)}}const w=d,{messages:S,toolTimelines:k}=fr(x,e.toolTimelines);return{...e,messages:S,toolTimelines:k,toolStreamingMessageId:h?f:p,toolStreamingStack:w}}if(t.type==="progress"){const i=e.toolStreamingMessageId;if(!i)return e;const a={type:"progress",content:t.content??null},l=_o(e.messages,i,a),c=l.findIndex(y=>y.id===i);if(c===-1)return e;const d=l[c],f={...d.additionalKwargs??{},toolStreaming:!0},p={...d,additionalKwargs:f},h=No(l,c,p),{messages:g,toolTimelines:m}=fr(h,e.toolTimelines);return{...e,messages:g,toolTimelines:m}}if(t.type==="checkpoint"){const i=t.checkpointNs??e.lastCheckpointNs??null,a=px(e.messages,t.checkpointId,i);return{...e,lastCheckpointId:t.checkpointId,lastCheckpointNs:i,messages:a}}if(t.type==="error"){const i={id:`err-${Date.now()}`,role:"system",content:[{type:"text",text:`Error: ${t.message}`}],createdAt:new Date().toISOString()};return{...e,messages:[...e.messages,i]}}if(t.type==="state_history"){const i=dr(t),a=i.interrupt,l=i.latest,c=a===null?tc(e.messages):e.messages;return{...e,messages:c,pendingInterrupt:a,lastCheckpointId:(l==null?void 0:l.checkpointId)??e.lastCheckpointId,lastCheckpointNs:(l==null?void 0:l.checkpointNs)??e.lastCheckpointNs}}return t.type==="thread_info",e}function mi(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 No(e,t,n){return t<0||t>=e.length?e:[...e.slice(0,t),n,...e.slice(t+1)]}function tc(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 nc(e){for(let t=e.length-1;t>=0;t--)if(e[t].role==="assistant")return e[t].id;return null}function rc(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 ix(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 ax(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 lx(e,t){const n=new Set;for(const o of t)typeof o=="string"&&o.trim()&&n.add(o.trim());const r=ix(e);for(const o of r)n.add(o);return Array.from(n)}function oc(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 _o(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:rx(),idx:a.length+1,timestamp:new Date().toISOString(),...n};return a.push(l),Jg(o.id,a,{checkpointId:o.checkpointId??null,checkpointNs:o.checkpointNs??null}),i.toolProgress=a,s[r]={...o,additionalKwargs:i},s}function sc(e,t){return e.includes(t)?e:[...e,t]}function cx(e,t){const n=[...e],r=n.lastIndexOf(t);return r!==-1&&n.splice(r,1),n}function ux(e){const t=e.additionalKwargs??{};return Array.isArray(t.toolProgress)?[...t.toolProgress]:[]}function fr(e,t){let n=!1;const r={},o=e.map(s=>{const i=ux(s);if(i.length)return r[s.id]=i,s;const a=t[s.id]??Zg(s.id);if(a!=null&&a.length){const l=[...a];r[s.id]=l,n=!0;const c={...s.additionalKwargs??{},toolProgress:l};return{...s,additionalKwargs:c}}return s});return{messages:n?o:e,toolTimelines:r}}function ic(e){return!e||!e.length?"":e.filter(t=>t.type==="text").map(t=>t.text??"").join("")}function dx(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??ic(e);let l="",c=e.slice();if(s){const f=fx(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??"",g={...p,text:h+l};c=[...c.slice(0,c.length-1),g]}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 ac(e){return e.replace(/\s+/g," ").trim()}function fx(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=ac(e),o=ac(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 px(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 No(e,r,s)}return e}function hx(e){if(!e)return null;const t=e.split("/");return t[t.length-1]||null}function lc(e={}){const t=b.useMemo(()=>Cn(e.baseUrl),[e.baseUrl]),n=e.streamPath??"/runs/stream",[r,o]=b.useState(e.token??null),s=b.useRef(e.headers??{}),i=e.credentials??"include",[a,l]=b.useState(!1),[c,d]=b.useState(null),[f,p]=b.useState(""),[h,g]=b.useState(null),[m,y]=b.useState(0),[x,w]=b.useState(!1),S=b.useRef(null),k=b.useRef(!0),C=b.useRef(0),T=b.useRef(null),E=b.useRef(null),N=b.useRef(null),_=b.useRef(null),D=b.useCallback(P=>{o(P)},[]),B=b.useCallback(()=>{p(""),g(null),d(null),E.current=null,N.current=null,_.current=null},[]),G=b.useCallback(()=>{var P;console.debug("[use-chat] stop() invoked - aborting stream"),(P=S.current)==null||P.abort(),S.current=null,T.current=null,l(!1),w(!1),C.current=0,y(0)},[]),V=b.useCallback((P,M,A)=>{S.current&&(S.current.abort(),S.current=null),l(!0),d(null),e.autoAppendAssistant!==!1&&p(""),g(null),E.current=null,N.current=null,_.current=null;const F=new AbortController;S.current=F;let L=null,R=null,z=!1;return T.current={threadId:P.threadId??null,headers:{}},(async()=>{var ne,ye,Te,q,U,Z,$,Y,Q,de,oe,_e,ze,se,me,Pe,Ve,ut;const X=Ke=>{var qe;try{const Qe=JSON.parse(JSON.stringify(Ke));return(qe=Qe==null?void 0:Qe.payload)!=null&&qe.files_info&&Array.isArray(Qe.payload.files_info)&&(Qe.payload.files_info=Qe.payload.files_info.map(Ge=>({...Ge,data:Ge!=null&&Ge.data?`<base64 ${String(Ge.data).length} chars>`:Ge==null?void 0:Ge.data}))),Qe}catch{return Ke}};try{let Ke={};try{if(r)Ke={Authorization:`Bearer ${r}`};else if(typeof window<"u"){const We=window.__AUTH_TOKEN__,pt=((ne=window.localStorage)==null?void 0:ne.getItem("authToken"))||null;let Rt=null;try{const H=(ye=window.localStorage)==null?void 0:ye.getItem("chat-settings");H&&(Rt=((Te=JSON.parse(H))==null?void 0:Te.apiKey)||null)}catch{}const Ye=We||pt||Rt||null;Ye&&(Ke={Authorization:`Bearer ${Ye}`})}}catch{}console.debug("[use-chat] POST",t+n,X(P));let qe={};if(typeof window<"u")try{const tt=(q=window.localStorage)==null?void 0:q.getItem("authSessionId");tt&&(qe={"X-Session-Id":tt})}catch{}const Qe={...Ke,...qe,...s.current},Ge={"Content-Type":"application/json",Accept:"text/event-stream",...Qe},et=await fetch(t+n,{method:"POST",headers:Ge,body:JSON.stringify(P),signal:F.signal,credentials:i});if(T.current&&(T.current.headers=Qe),!et.ok||!et.body){const tt=await et.text().catch(()=>"");console.debug("[use-chat] non-OK response",et.status,tt==null?void 0:tt.slice(0,500));const We=`stream ${et.status}${tt?": "+tt:""}`;throw(U=A==null?void 0:A.onConnectionError)==null||U.call(A,We),z=!0,L="error",R=We,new Error(We)}w(!0);const st=et.body.getReader(),Mt=new TextDecoder;let gt="",Ct=[];C.current=0,y(0);let it=0,St=null;const Pt=()=>{if(Ct.length){const tt=Ct.join("");Ct=[],k.current&&p(We=>We+tt)}St=null},zt=()=>{typeof window<"u"&&St==null&&(St=requestAnimationFrame(Pt))};let nn=Date.now();const Le=setInterval(()=>{var tt;if(Date.now()-nn>18e5){const We="Stream idle timeout";d(We),L="error",R=We,F.abort(),(tt=A==null?void 0:A.onError)==null||tt.call(A,We)}},5e3),Sn=1024*1024;try{const tt=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"),pt=tt??null,Rt=String(We??"").toLowerCase()==="true";for(T.current&&!T.current.threadId&&(T.current={...T.current,threadId:pt}),(Z=A==null?void 0:A.onOpen)==null||Z.call(A,{threadId:pt,created:Rt});;){const{value:Ye,done:H}=await st.read();if(H)break;gt+=Mt.decode(Ye,{stream:!0}),gt.length>Sn&&(gt="",console.warn("Stream buffer reset: exceeded 1MB"));let j;for(;(j=gt.indexOf(`
|
|
36
36
|
|
|
37
|
-
`))>=0;){const
|
|
38
|
-
`)}const Yg=["message.start","message.delta","message.end","progress"],Xg=["tool.start","tool.end"],Jg=["thread_info","checkpoint","branch"],Zg=["error","interrupt","heartbeat","state_history","cancelled"],Qg=[...Yg,...Xg,...Jg,...Zg],ex=new Set(Qg);function tx(e){if(typeof e!="object"||e===null||typeof e.type!="string")return!1;const t=e.type;return ex.has(t)}const Yl=200;function nx({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),g=w.useRef(null),m=w.useCallback(M=>{try{const A=globalThis.structuredClone;if(typeof A=="function")return A(M)}catch{}try{return JSON.parse(JSON.stringify(M))}catch{return M}},[]),y=w.useCallback((M,A)=>{if(!M)return;const F=p.current.get(M)??[],L=m(A),P=F.length>=Yl?[...F.slice(F.length-Yl+1),L]:[...F,L];p.current.set(M,P)},[m]),x=w.useCallback(M=>{M&&p.current.set(M,[])},[]),b=w.useCallback(M=>{const A=M??f.current;if(!A)return;const F=p.current.get(A);F!=null&&F.length&&F.forEach(L=>{try{n(L)}catch(P){console.error("[useChatStreamingService] Failed to replay buffered event",P)}})},[n]),S=w.useCallback(M=>{f.current=M.threadId,h.current&&(h.current.threadIdGuess=M.threadId),g.current=M,x(M.threadId),console.log("[useChatStreamingService] 🎯 Received thread_info event:",M);try{t(M)}catch(A){console.error("[useChatStreamingService] Error in onThreadInfo handler:",A)}},[x,t]),k=w.useCallback(M=>{try{c==null||c(M)}catch(A){console.error("[useChatStreamingService] Error in onHeartbeat handler:",A)}},[c]),C=w.useCallback(M=>{var L,P,z,X;const A=M;if(A.error_type==="auth_error"||A.code==="TOKEN_EXPIRED"||((L=A.message)==null?void 0:L.includes("token"))||((P=A.message)==null?void 0:P.includes("401"))||((z=A.message)==null?void 0:z.includes("unauthorized"))||((X=A.message)==null?void 0:X.includes("Unauthorized"))){console.error("[useChatStreamingService] Auth error event detected:",A.message);try{l==null||l(A.message)}catch(ne){console.warn("[useChatStreamingService] onAuthError handler failed",ne)}}},[l]),T=w.useMemo(()=>({thread_info:M=>(S(M),!0),heartbeat:M=>(k(M),!0),error:M=>(C(M),!1)}),[S,k,C]),E=w.useCallback(M=>{var P;const A=M.seq??null;if(A!==null){const z=d.current;if(z!==null){if(A<=z)return;A>z+1&&(s==null||s({from:z,to:A}))}d.current=A}const F=T[M.type];if(F&&F(M))return;const L=M.threadId??(M.type==="state_history"?M.threadId:void 0)??f.current??((P=h.current)==null?void 0:P.threadIdGuess)??null;if(M.type==="state_history"){f.current=L??f.current;try{r==null||r(M)}catch(z){console.error("[useChatStreamingService] onStateHistory handler failed",z)}}if(tx(M)){M.type==="checkpoint"||M.type==="state_history"?x(L??null):y(L??null,M);try{n(M)}catch(z){console.error("[useChatStreamingService] Error in onMessageEvent handler:",z)}return}try{o==null||o(M)}catch(z){console.error("[useChatStreamingService] Error in onUnhandledEvent handler:",z)}},[y,x,n,s,r,o,T]),{stream:N,stop:_,isStreaming:D,error:B,setToken:G}=Gl({baseUrl:e,token:void 0}),V=w.useCallback((M,A)=>{d.current=null,g.current=null,f.current=M.threadId??null,h.current={request:M,callbacks:A,manualStop:!1,threadIdGuess:M.threadId??null},N(M,E,{onOpen:A==null?void 0:A.onOpen,onError:F=>{var L;(L=A==null?void 0:A.onError)==null||L.call(A,F)},onGap:(A==null?void 0:A.onGap)??s,onConnectionError:F=>{var L;a==null||a(F),(L=A==null?void 0:A.onConnectionError)==null||L.call(A,F)},onAuthError:F=>{var L;l==null||l(F),(L=A==null?void 0:A.onAuthError)==null||L.call(A,F)},onHeartbeat:F=>{var L;try{c==null||c(F)}catch(P){console.warn("[useChatStreamingService] onHeartbeat handler failed",P)}try{(L=A==null?void 0:A.onHeartbeat)==null||L.call(A,F)}catch(P){console.warn("[useChatStreamingService] downstream onHeartbeat handler failed",P)}},onClosed:F=>{var X,ne,ye,Te;const L=((X=h.current)==null?void 0:X.manualStop)??!1,P=f.current??((ne=h.current)==null?void 0:ne.threadIdGuess)??((ye=F.lastStateHistory)==null?void 0:ye.threadId)??null;(F.reason==="complete"||F.reason==="aborted"&&L)&&x(P);const z={...F,threadId:P,threadInfo:g.current,manualStop:L};try{i==null||i(z)}catch(q){console.warn("[useChatStreamingService] onStreamClosed handler failed",q)}try{(Te=A==null?void 0:A.onClosed)==null||Te.call(A,z)}catch(q){console.warn("[useChatStreamingService] downstream onClosed handler failed",q)}h.current&&(h.current=null)}})},[x,E,l,a,c,s,i,N]),R=w.useCallback(()=>{h.current&&(h.current.manualStop=!0),_()},[_]);return w.useMemo(()=>({startStream:V,stop:R,isStreaming:D,error:B,setAuthToken:G,replayBufferedEvents:b}),[V,R,D,B,G,b])}const Tt=[];for(let e=0;e<256;++e)Tt.push((e+256).toString(16).slice(1));function rx(e,t=0){return(Tt[e[t+0]]+Tt[e[t+1]]+Tt[e[t+2]]+Tt[e[t+3]]+"-"+Tt[e[t+4]]+Tt[e[t+5]]+"-"+Tt[e[t+6]]+Tt[e[t+7]]+"-"+Tt[e[t+8]]+Tt[e[t+9]]+"-"+Tt[e[t+10]]+Tt[e[t+11]]+Tt[e[t+12]]+Tt[e[t+13]]+Tt[e[t+14]]+Tt[e[t+15]]).toLowerCase()}let pi;const ox=new Uint8Array(16);function sx(){if(!pi){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");pi=crypto.getRandomValues.bind(crypto)}return pi(ox)}const Xl={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function ix(e,t,n){var o;e=e||{};const r=e.random??((o=e.rng)==null?void 0:o.call(e))??sx();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,rx(r)}function ax(e,t,n){return Xl.randomUUID&&!e?Xl.randomUUID():ix(e)}const lx={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},toolStreamingMessageId:null,toolStreamingStack:[],lastBranch:null,messagesStreamMeta:{},pendingInterrupt:null,toolTimelines:{}};function cx(e,t){var n;switch(t.type){case"reset":return{messages:hi(((n=t.payload)==null?void 0:n.messages)??[]),assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},toolStreamingMessageId:null,toolStreamingStack:[],lastBranch:null,pendingInterrupt:null,toolTimelines:{}};case"seed":{const r=hi(t.payload.messages),{messages:o,toolTimelines:s}=fr(r,e.toolTimelines),i={...e,messages:o,assemblingId:null,pendingInterrupt:t.payload.pendingInterrupt??null,toolStreamingMessageId:null,toolStreamingStack:[],toolTimelines:s};return Object.prototype.hasOwnProperty.call(t.payload,"checkpointId")&&(i.lastCheckpointId=t.payload.checkpointId??null),Object.prototype.hasOwnProperty.call(t.payload,"checkpointNs")&&(i.lastCheckpointNs=t.payload.checkpointNs??null),i}case"prepend":{const r=hi(t.payload.messages);if(!r.length)return e;const o=new Set(e.messages.map(c=>c.id)),s=r.filter(c=>!o.has(c.id));if(!s.length)return e;const i=[...s,...e.messages],{messages:a,toolTimelines:l}=fr(i,e.toolTimelines);return{...e,messages:a,toolTimelines:l}}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 Zl(e,t.payload.ev);case"batch":{const{events:r}=t.payload;return r.length?r.reduce((o,s)=>Zl(o,s),e):e}case"interrupt_response":return{...e,messages:Ql(e.messages),pendingInterrupt:null};default:return e}}function Jl(e=[]){const[t,n]=w.useReducer(cx,{...lx,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 Zl(e,t){var n,r,o,s;if(t.type==="message.start"&&t.role==="assistant"){const i=t.id,a=yx(t.model);if(e.messages.some(d=>d.id===i)){const d=e.messagesStreamMeta??{},f={...d,[i]:d[i]??{lastSeq:t.seq??null,lastText:""}};return{...e,assemblingId:i,messagesStreamMeta:f}}const c={id:i,role:"assistant",name:a||void 0,model:t.model,createdAt:new Date().toISOString(),content:[]};return{...e,assemblingId:i,messages:[...e.messages,c]}}if(t.type==="message.delta"){const i=e.assemblingId??ec(e.messages);if(!i)return e;const a=e.messages,l=a.findIndex(S=>S.id===i&&S.role==="assistant");if(l===-1)return e;const c=a[l],d=e.messagesStreamMeta??{},f=d[i]??{lastSeq:null,lastText:oc(c.content)},p=t.seq??null;if(p!==null&&typeof p=="number"&&typeof f.lastSeq=="number"&&p<=f.lastSeq)return console.debug("[MessageReducer] skipping delta - seq <= lastSeq",{seq:p,lastSeq:f.lastSeq}),e;const{newParts:h,newMeta:g,changed:m}=mx(c.content,t.delta,f,p);if(!m)return e;const y={...c,content:h},x=No(a,l,y),b={...d,[i]:g};return{...e,messages:x,messagesStreamMeta:b}}if(t.type==="message.end"){const i=e.assemblingId??ec(e.messages);if(!i)return{...e,assemblingId:null};const a=e.messages,l=a.findIndex(c=>c.id===i&&c.role==="assistant");if(l>=0){const c=a[l];if(!((n=c.content)==null?void 0:n.some(f=>{var p;return(f==null?void 0:f.type)==="text"&&((p=f.text)==null?void 0:p.trim())}))){console.debug("[MessageReducer] pruning assistant message with no visible text",{id:c.id,contentTypes:(r=c.content)==null?void 0:r.map(p=>p==null?void 0:p.type),contentPreview:(o=c.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 f=[...a.slice(0,l),...a.slice(l+1)];return{...e,assemblingId:null,messages:f}}}return e}if(t.type==="tool.start"){const i=tc(t),a=i[0]??(typeof t.id=="string"?t.id:null)??(typeof t.call_id=="string"?t.call_id:null),l=t.name??t.tool??"tool";!a&&i.length===0&&i.push(`${l}-${Date.now()}`);const c=i.length?i:a?[a]:[],d=c[0]??`${l}-${Date.now()}`,f={type:"tool_call",id:d,name:l,args:t.args},p={type:e.toolStreamingMessageId?"tool.call":"tool.start",toolId:a??d,toolName:l,title:`Invoking ${l}`,metadata:{args:t.args}},h=e.toolStreamingMessageId;if(!h){const b={id:`tool-${d}`,role:"tool",name:l,createdAt:new Date().toISOString(),content:[f],additionalKwargs:{...dx(void 0,c.length?c:[d],l,t.args),toolStreaming:!0}},S=fx(b,c.length?c:[d]),k=[...e.messages,b],C=_o(k,b.id,p),{messages:T,toolTimelines:E}=fr(C,e.toolTimelines);return{...e,messages:T,toolIndex:nc(e.toolIndex,b.id,S),toolStreamingMessageId:b.id,toolStreamingStack:rc(e.toolStreamingStack??[],a??d),toolTimelines:E}}const g=_o(e.messages,h,p),{messages:m,toolTimelines:y}=fr(g,e.toolTimelines);return{...e,messages:m,toolIndex:nc(e.toolIndex,h,c),toolStreamingStack:rc(e.toolStreamingStack??[],a??d),toolTimelines:y}}if(t.type==="tool.end"){const i=tc(t);if(!i.length&&!(typeof t.id=="string"&&t.id))return e;const a=i[0]??(typeof t.id=="string"?t.id:null);if(!a)return e;const l=e.toolStreamingStack??[],c=l[0]??null,d=px(l,a),f=d[0]?e.toolIndex[d[0]]:null,p=e.toolStreamingMessageId,h=c===a,g=t.name??((s=e.messages.find(C=>C.id===p))==null?void 0:s.name)??"tool",m=typeof t.output=="string"?t.output.trim():JSON.stringify(t.output??""),y={type:"tool.end",toolId:a,toolName:g,title:`${g} completed`,content:m==null?void 0:m.slice(0,200)};let x=e.messages;if(p&&(x=_o(x,p,y)),h&&p){const C=x.findIndex(T=>T.id===p);if(C>=0){const T=x[C],N={type:"text",text:(()=>{if(typeof t.output=="string"){const D=t.output.trim();try{return D}catch{return D}}return JSON.stringify(t.output??"")})()},_={...T,content:[N],artifact:t.artifact??T.artifact,additionalKwargs:{...T.additionalKwargs??{}}};x=No(x,C,_)}}const b=d,{messages:S,toolTimelines:k}=fr(x,e.toolTimelines);return{...e,messages:S,toolTimelines:k,toolStreamingMessageId:h?f:p,toolStreamingStack:b}}if(t.type==="progress"){const i=e.toolStreamingMessageId;if(!i)return e;const a={type:"progress",content:t.content??null},l=_o(e.messages,i,a),c=l.findIndex(y=>y.id===i);if(c===-1)return e;const d=l[c],f={...d.additionalKwargs??{},toolStreaming:!0},p={...d,additionalKwargs:f},h=No(l,c,p),{messages:g,toolTimelines:m}=fr(h,e.toolTimelines);return{...e,messages:g,toolTimelines:m}}if(t.type==="checkpoint"){const i=t.checkpointNs??e.lastCheckpointNs??null,a=xx(e.messages,t.checkpointId,i);return{...e,lastCheckpointId:t.checkpointId,lastCheckpointNs:i,messages:a}}if(t.type==="branch"){const i=t.checkpointId??e.lastCheckpointId,a=t.checkpointNs??e.lastCheckpointNs;return{...e,lastBranch:t,lastCheckpointId:i??null,lastCheckpointNs:a??null}}if(t.type==="error"){const i={id:`err-${Date.now()}`,role:"system",content:[{type:"text",text:`Error: ${t.message}`}],createdAt:new Date().toISOString()};return{...e,messages:[...e.messages,i]}}if(t.type==="state_history"){const i=dr(t),a=i.interrupt,l=i.latest,c=a===null?Ql(e.messages):e.messages;return{...e,messages:c,pendingInterrupt:a,lastCheckpointId:(l==null?void 0:l.checkpointId)??e.lastCheckpointId,lastCheckpointNs:(l==null?void 0:l.checkpointNs)??e.lastCheckpointNs}}return t.type==="thread_info",e}function hi(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 No(e,t,n){return t<0||t>=e.length?e:[...e.slice(0,t),n,...e.slice(t+1)]}function Ql(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 ec(e){for(let t=e.length-1;t>=0;t--)if(e[t].role==="assistant")return e[t].id;return null}function tc(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 ux(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 dx(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 fx(e,t){const n=new Set;for(const o of t)typeof o=="string"&&o.trim()&&n.add(o.trim());const r=ux(e);for(const o of r)n.add(o);return Array.from(n)}function nc(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 _o(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:ax(),idx:a.length+1,timestamp:new Date().toISOString(),...n};return a.push(l),i.toolProgress=a,s[r]={...o,additionalKwargs:i},s}function rc(e,t){return e.includes(t)?e:[...e,t]}function px(e,t){const n=[...e],r=n.lastIndexOf(t);return r!==-1&&n.splice(r,1),n}function hx(e){const t=e.additionalKwargs??{};return Array.isArray(t.toolProgress)?[...t.toolProgress]:[]}function fr(e,t){let n=!1;const r={},o=e.map(s=>{const i=hx(s);if(i.length)return r[s.id]=i,s;const a=t[s.id];if(a!=null&&a.length){r[s.id]=a,n=!0;const l={...s.additionalKwargs??{},toolProgress:a};return{...s,additionalKwargs:l}}return s});return{messages:n?o:e,toolTimelines:r}}function oc(e){return!e||!e.length?"":e.filter(t=>t.type==="text").map(t=>t.text??"").join("")}function mx(e,t,n,r){const o={...n};if(r!==null&&typeof r=="number"){if(typeof o.lastSeq=="number"&&r<=o.lastSeq)return{newParts:e,newMeta:o,changed:!1};o.lastSeq=r}const s=t.filter(f=>f.type==="text").map(f=>f.text??"").join(""),i=t.filter(f=>f.type!=="text"),a=o.lastText??oc(e);let l="",c=e.slice();if(s){const f=gx(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??"",g={...p,text:h+l};c=[...c.slice(0,c.length-1),g]}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 sc(e){return e.replace(/\s+/g," ").trim()}function gx(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=sc(e),o=sc(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 xx(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 No(e,r,s)}return e}function yx(e){if(!e)return null;const t=e.split("/");return t[t.length-1]||null}const ic=w.createContext(null),ac=w.createContext(null),lc=w.createContext(null);w.createContext(!1);function vx({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}=di(),f=w.useMemo(()=>Cn(d),[d]),[p,h]=w.useState([]),[g,m]=w.useState(t),[y,x]=w.useState(!1),[b,S]=w.useState(null),[k,C]=w.useState(!1),[T,E]=w.useState(null),{state:N,seed:_,prepend:D,pushUser:B,onEvent:G}=Jl(),[V,R]=w.useState(!1),[M,A]=w.useState(!1),[F,L]=w.useState(null),[P,z]=w.useState([]),[X,ne]=w.useState([]),[ye,Te]=w.useState(!1),q=w.useMemo(()=>Kg(P),[P]),U=w.useRef(g),J=w.useRef(null),$=w.useRef(null),Y=w.useRef(null),Z=w.useRef(null),de=w.useRef(!1),oe=w.useRef(null),_e=w.useRef(new Map),ze=w.useRef(new Map);w.useEffect(()=>{U.current=g},[g]);const se=w.useCallback(async H=>{var Q,re;if(!H.threadId)return;const j=H.threadId;(Q=H.onStart)==null||Q.call(H),H.setLoading(!0);try{await H.action(j)}catch(ie){if(U.current===j){const ce=String(ie);(re=H.handleError)==null||re.call(H,ce),s==null||s(ce)}throw ie}finally{H.setLoading(!1)}},[s]),me=w.useCallback(async()=>{x(!0),S(null);try{const H=await c.listThreads();h(H??[])}catch(H){const j=String(H);S(j),s==null||s(j)}finally{x(!1)}},[c,s]),Re=w.useCallback(H=>{if(!(H!=null&&H.threadId))return;const j={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(Q=>{let re=!1;const ie=Q.map(ce=>ce.threadId===j.threadId?(re=!0,console.debug("[ChatSessionProvider] thread_info: updating existing thread",j.threadId),{...ce,title:j.title??ce.title,updatedAt:j.updatedAt??ce.updatedAt,messageCount:j.messageCount??ce.messageCount}):ce);return re?ie:(console.debug("[ChatSessionProvider] thread_info: adding thread to list",j.threadId),[j,...Q])})},[]),Ve=w.useCallback(H=>{const j=H.threadId??U.current;if(!j||U.current&&U.current!==j)return;const{checkpoints:Q,timeline:re}=dr(H);if(!Q.length)return;const ie=Q.find(ce=>ce.messages&&ce.messages.length>0)??Q.find(ce=>!!ce.checkpointId)??Q[0];_((ie==null?void 0:ie.messages)??[],{checkpointId:(ie==null?void 0:ie.checkpointId)??null,checkpointNs:(ie==null?void 0:ie.checkpointNs)??null}),ne(re),z(Q),R(!!(ie!=null&&ie.nextCursor)),L((ie==null?void 0:ie.nextCursor)??null),oe.current=`${j}:latest`,$.current=null,Y.current=null},[_]),ut=w.useCallback(H=>{console.log("[ChatSessionProvider] 🎯 Received thread_info:",H.threadId),Re(H),U.current!==H.threadId&&((H.created??!U.current)&&($.current=H.threadId),Y.current=H.threadId,console.log("[ChatSessionProvider] thread_info: marking to skip auto-load for new thread"),m(H.threadId))},[Re]),{startStream:Ke,stop:qe,isStreaming:Qe,error:Ge,setAuthToken:et}=nx({baseUrl:f,onThreadInfo:ut,onMessageEvent:G,onStateHistory:Ve,onUnhandledEvent:H=>{console.warn("[ChatSessionProvider] Unhandled event:",H.type)},onAuthError:i,onConnectionError:l}),st=w.useCallback(async H=>{try{const j=await c.createThread(H);return m(j.threadId),await me(),j.threadId}catch(j){return s==null||s(String(j)),null}},[c,me,s]),Mt=w.useCallback(async H=>{const j=p;h(re=>re.filter(ie=>ie.threadId!==H));const Q=new AbortController;ze.current.set(H,Q);try{await c.deleteThread(H),U.current===H&&(m(null),_([],{})),console.log("[ChatSessionProvider] Thread deleted successfully:",H)}catch(re){console.error("[ChatSessionProvider] Delete failed, restoring thread:",H,re),h(j),s==null||s(`Failed to delete thread: ${String(re)}`)}finally{ze.current.delete(H)}},[p,c,_,s]),gt=w.useCallback(async(H,j)=>{try{await c.updateThread(H,j),await me()}catch(Q){s==null||s(String(Q))}},[c,me,s]),Ct=w.useCallback(async(H,j)=>{if(!H)return;const Q=`${H}:${j??"latest"}`,re=_e.current.get(Q);if(re)return re;const ie=se({threadId:H,setLoading:C,onStart:()=>E(null),handleError:ce=>E(ce),action:async ce=>{const Xe=await c.getStateHistory({threadId:ce,checkpointId:j||void 0});if(U.current!==ce){console.log(`[ChatSessionProvider] Thread changed during load (was ${ce}, now ${U.current}), discarding stale data`);return}const{checkpoints:Ie,timeline:at}=dr(Xe),ht=Ie.find(Kt=>Kt.messages&&Kt.messages.length>0)??(j?Ie.find(Kt=>Kt.checkpointId===j):null)??Ie[0];_((ht==null?void 0:ht.messages)??[],{checkpointId:(ht==null?void 0:ht.checkpointId)??null,checkpointNs:(ht==null?void 0:ht.checkpointNs)??null}),ne(at),z(Ie),R(!!(ht!=null&&ht.nextCursor)),L((ht==null?void 0:ht.nextCursor)??null)}});_e.current.set(Q,ie);try{await ie}finally{_e.current.delete(Q)}return U.current===H&&(oe.current=Q),ie},[c,_,s,se]),it=w.useCallback(async(H,j)=>{Z.current=H;try{await Ct(H,j)}finally{Z.current===H&&(Z.current=null)}},[Ct]);w.useEffect(()=>{if(!o||!g||k||Qe)return;if($.current===g){$.current=null,J.current=g;return}if(Y.current===g){J.current=g;return}if(Z.current===g){Z.current=null,J.current=g;return}if(J.current===g)return;J.current=g;const H=!de.current&&!!n&&g===t;let j;H&&n?(j=n,de.current=!0,console.log("[ChatSessionProvider] Loading thread with checkpoint:",j,r?`(ns: ${r})`:"")):console.log("[ChatSessionProvider] Loading thread with latest checkpoint");const Q=`${g}:${j??"latest"}`;oe.current!==Q&&it(g,j)},[o,g,n,r,t,k,Qe,it]);const St=w.useCallback(async(H,j)=>{const Q=U.current;await se({threadId:Q,setLoading:Te,action:async re=>{const ie=await c.getStateHistory({threadId:re,checkpointId:H,checkpointNs:j??void 0});if(U.current!==re){console.log(`[ChatSessionProvider] Thread changed during checkpoint navigation (was ${re}, now ${U.current}), discarding stale data`);return}const{checkpoints:ce,timeline:Xe}=dr(ie),Ie=ce.find(at=>at.checkpointId===H&&(j?at.checkpointNs===j:!0));if(!Ie){console.warn("[ChatSessionProvider] Requested checkpoint not found:",{checkpointId:H,checkpointNs:j});return}ne(Xe),z(ce),_(Ie.messages??[],{checkpointId:Ie.checkpointId??null,checkpointNs:Ie.checkpointNs??null})}}).catch(()=>{})},[c,_,s,se]),Rt=w.useCallback((H,j)=>{_(N.messages,{checkpointId:H??null,checkpointNs:j??null})},[_,N.messages]),zt=w.useCallback(async()=>{U.current&&await it(U.current)},[it]),nn=w.useCallback(async()=>{const H=U.current;!H||!F||await se({threadId:H,setLoading:A,action:async j=>{const Q=await c.getStateHistory({threadId:j,checkpointId:F});if(U.current!==j)return;const{checkpoints:re}=dr(Q);if(re.length>0){const ie=re[re.length-1];D((ie==null?void 0:ie.messages)??[]),R(!!(ie!=null&&ie.nextCursor)),L((ie==null?void 0:ie.nextCursor)??null)}}}).catch(()=>{})},[c,F,D,s,se]),Le=w.useCallback(async()=>{_([],{}),m(null),qe(),z([]),ne([]),R(!1),L(null),C(!1),Te(!1),A(!1),E(null);try{await c.getAgent("default")}catch(H){console.warn("[ChatSessionProvider] Failed to refetch agent after clearing thread:",H)}},[_,qe,c]),Sn=w.useCallback(async(H,j,Q)=>{const re=U.current;if(!re)throw new Error("No active thread to handle interrupt");const ie=j?Q??!0:!1;try{const ce={threadId:re,checkpointId:N.lastCheckpointId??void 0,checkpointNs:N.lastCheckpointNs??void 0,command:{kind:"resume",value:ie}};Ke(ce)}catch(ce){throw console.error(`[ChatSessionProvider] Failed to handle interrupt ${H}:`,ce),ce}},[N.lastCheckpointId,N.lastCheckpointNs,Ke]);w.useEffect(()=>{me()},[me]),w.useEffect(()=>{a==null||a(g)},[g,a]);const tt=w.useCallback(async(H,j)=>{let Q=U.current;const re=(H==null?void 0:H.text)??"",ie=(H==null?void 0:H.attachments)??[],ce=(re==null?void 0:re.trim())??"",Xe={...(H==null?void 0:H.payload)??{}},Ie=Array.isArray(Xe.messages)?Xe.messages:void 0;Ie&&delete Xe.messages;const at=!!(Ie&&Ie.length);if(!Q&&!ce&&ie.length===0&&!at)return;if(!Q){const be=Math.floor(Date.now()/1e3).toString(16).padStart(8,"0"),Be=Array.from({length:4},()=>Math.floor(Math.random()*4294967295).toString(16).padStart(8,"0")).join("").slice(0,16);Q=`${be}${Be}`,$.current=Q,m(Q)}const{contentParts:ht,filesInfo:Kt}=await wg(c,ie),Hn=[...ht];ce&&Hn.push({type:"text",text:re});const Ar=j==null?void 0:j.originalMessageId,Nr=!!(j!=null&&j.edit&&Ar),po=!at&&Hn.length>0;let Nn=null;po&&(Nn={id:Nr?Ar:`msg-${Date.now()}`,role:"user",content:Hn,createdAt:new Date().toISOString()},Nr||B(Nn));const I=at?Ie:Nn?[Nn]:[],W={...Xe,...Kt.length?{files_info:Kt}:{}};I.length?W.messages=I:"messages"in W||(W.messages=[]);const ae={threadId:Q,payload:W,checkpointId:(j==null?void 0:j.checkpointId)??N.lastCheckpointId??void 0,checkpointNs:(j==null?void 0:j.checkpointNs)??N.lastCheckpointNs??void 0,edit:!!(j!=null&&j.edit),timelineCheckpoints:X};Ke(ae)},[c,B,N,Ke,X]),We=w.useMemo(()=>({threads:p,currentThreadId:g,setCurrentThreadId:m,isLoading:y,error:b,actions:{createThread:st,deleteThread:Mt,renameThread:gt,refreshThreads:me}}),[p,g,y,b,st,Mt,gt,me]),pt=w.useMemo(()=>{const H=N.assemblingId??null;return H?{assemblingMessageId:H}:null},[N.assemblingId]),Pt=w.useMemo(()=>({threadId:g,messages:N.messages,interrupt:null,checkpoint:{id:N.lastCheckpointId??null,namespace:N.lastCheckpointNs??null},checkpoints:P,timelineCheckpoints:X,metadata:pt,isLoading:k,isHistoryLoading:M,isLoadingCheckpoint:ye,error:T,hasMore:V,loadOlder:nn,clearState:Le,navigateToCheckpoint:St,setCurrentCheckpointId:Rt,returnToLatest:zt,loadThread:it,clearThread:Le,respondToInterrupt:Sn,messagePreviews:q}),[g,N,P,X,k,M,ye,T,V,nn,Le,St,Rt,zt,it,Sn,q,pt]),Ye=w.useMemo(()=>({isStreaming:Qe,error:Ge,connectionState:Qe?"connected":"idle",submit:tt,send:tt,stop:qe,setAuthToken:et}),[Qe,Ge,tt,qe,et]);return u.jsx(ic.Provider,{value:We,children:u.jsx(ac.Provider,{value:Pt,children:u.jsx(lc.Provider,{value:Ye,children:e})})})}function jo(){const e=w.useContext(ic);if(!e)throw new Error("useThreads must be used within ChatSessionProvider");return e}function Mo(){const e=w.useContext(ac);if(!e)throw new Error("useThreadState must be used within ChatSessionProvider");return e}function cc(){const e=w.useContext(lc);if(!e)throw new Error("useStream must be used within ChatSessionProvider");return e}function Ro({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(vg,{apiConfig:t,children:u.jsx(vx,{initialThreadId:n,initialCheckpointId:r,initialCheckpointNs:o,autoLoadInitial:s,onError:a,onAuthError:l,onConnectionError:i,onThreadChange:c,children:e})})}function te(...e){return Kh.twMerge(Vh.clsx(e))}const bx=ho.cva("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-10 w-10"}},defaultVariants:{variant:"default",size:"default"}}),Je=v.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?Vn.Slot:"button";return u.jsx(i,{className:te(bx({variant:t,size:n,className:e})),ref:s,...o})});Je.displayName="Button";const uc=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}));uc.displayName="Textarea";function dc({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 g=i!==void 0,[m,y]=w.useState(e),x=(g?i:m)??"",[b,S]=w.useTransition(),k=w.useRef(null),C=w.useRef(0),T=w.useRef(null);w.useEffect(()=>{g||(y(e??""),T.current=null,k.current&&(k.current.style.height="auto",k.current.style.height=`${k.current.scrollHeight}px`))},[e,t,g]);const E=w.useCallback(()=>{const M=k.current;M&&(M.style.height="auto",M.style.height=`${M.scrollHeight}px`)},[]);w.useEffect(()=>{E()},[E,x]);const N=w.useCallback((M,{fromUser:A})=>{g||y(M),A&&(a==null||a(M))},[g,a]),_=w.useCallback(async M=>{M&&M.preventDefault();const A=(x??"").trim();if(!A&&!h)return;const F=++C.current;T.current={id:F,shouldClear:!0},S(()=>{var L,P,z;try{const X=l(A);X&&typeof X.then=="function"?X.then(()=>{var ne,ye;((ne=T.current)==null?void 0:ne.id)===F&&T.current.shouldClear&&(g||(y(""),k.current&&(k.current.style.height="auto"),a==null||a(""))),((ye=T.current)==null?void 0:ye.id)===F&&(T.current=null)}).catch(()=>{var ne;((ne=T.current)==null?void 0:ne.id)===F&&(T.current=null)}):(((L=T.current)==null?void 0:L.id)===F&&T.current.shouldClear&&(g||(y(""),k.current&&(k.current.style.height="auto"),a==null||a(""))),((P=T.current)==null?void 0:P.id)===F&&(T.current=null))}catch{((z=T.current)==null?void 0:z.id)===F&&(T.current=null)}})},[x,l,h,g,a]),D=w.useCallback(M=>{const A=M.target.value;N(A,{fromUser:!0}),T.current&&(T.current.shouldClear=!1),k.current&&(k.current.style.height="auto",k.current.style.height=`${k.current.scrollHeight}px`)},[N]),B=w.useCallback(M=>{M.key==="Enter"&&!M.shiftKey?(M.preventDefault(),_()):M.key==="Escape"&&t&&(M.preventDefault(),c==null||c())},[_,t,c]),R=`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:M=>void _(M),className:`w-full ${f}`,children:u.jsxs("div",{className:"flex items-end gap-2",children:[u.jsx("div",{className:"flex-1",children:u.jsx(uc,{ref:k,value:x,onChange:D,onKeyDown:B,placeholder:t?"Edit your message...":n,className:R,disabled:o,maxLength:s,rows:1,spellCheck:!1,autoCorrect:"off"})}),u.jsx("div",{children:r?u.jsx(Je,{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(Je,{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 wx=w.memo(dc);function pe(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 fc(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=fc(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():fc(e[o],null)}}}}function $e(...e){return v.useCallback(mi(...e),e)}function Sx(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 Tn(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,...g}=f,m=((x=p==null?void 0:p[e])==null?void 0:x[l])||a,y=v.useMemo(()=>g,Object.values(g));return u.jsx(m.Provider,{value:y,children:h})};c.displayName=s+"Provider";function d(f,p){var m;const h=((m=p==null?void 0:p[e])==null?void 0:m[l])||a,g=v.useContext(h);if(g)return g;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,Cx(o,...t)]}function Cx(...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 kt=globalThis!=null&&globalThis.document?v.useLayoutEffect:()=>{},Tx=v[" useInsertionEffect ".trim().toString()]||kt;function pr({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=kx({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=Ex(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 kx({defaultProp:e,onChange:t}){const[n,r]=v.useState(e),o=v.useRef(n),s=v.useRef(t);return Tx(()=>{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 Ex(e){return typeof e=="function"}var Ix=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Ne=Ix.reduce((e,t)=>{const n=Vn.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 pc(e,t){e&&mo.flushSync(()=>e.dispatchEvent(t))}function gi(e){const t=e+"CollectionProvider",[n,r]=Tn(t),[o,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),i=m=>{const{scope:y,children:x}=m,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=Vn.createSlot(a),c=w.forwardRef((m,y)=>{const{scope:x,children:b}=m,S=s(a,x),k=$e(y,S.collectionRef);return u.jsx(l,{ref:k,children:b})});c.displayName=a;const d=e+"CollectionItemSlot",f="data-radix-collection-item",p=Vn.createSlot(d),h=w.forwardRef((m,y)=>{const{scope:x,children:b,...S}=m,k=w.useRef(null),C=$e(y,k),T=s(d,x);return w.useEffect(()=>(T.itemMap.set(k,{ref:k,...S}),()=>void T.itemMap.delete(k))),u.jsx(p,{[f]:"",ref:C,children:b})});h.displayName=d;function g(m){const y=s(e+"CollectionConsumer",m);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,E)=>S.indexOf(T.ref.current)-S.indexOf(E.ref.current))},[y.collectionRef,y.itemMap])}return[{Provider:i,Slot:c,ItemSlot:h},g,r]}var Ax=v.createContext(void 0);function Po(e){const t=v.useContext(Ax);return e||t||"ltr"}function Et(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 Nx(e,t=globalThis==null?void 0:globalThis.document){const n=Et(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 _x="DismissableLayer",xi="dismissableLayer.update",jx="dismissableLayer.pointerDownOutside",Mx="dismissableLayer.focusOutside",hc,mc=v.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),Oo=v.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:a,...l}=e,c=v.useContext(mc),[d,f]=v.useState(null),p=(d==null?void 0:d.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,h]=v.useState({}),g=$e(t,E=>f(E)),m=Array.from(c.layers),[y]=[...c.layersWithOutsidePointerEventsDisabled].slice(-1),x=m.indexOf(y),b=d?m.indexOf(d):-1,S=c.layersWithOutsidePointerEventsDisabled.size>0,k=b>=x,C=Ox(E=>{const N=E.target,_=[...c.branches].some(D=>D.contains(N));!k||_||(o==null||o(E),i==null||i(E),E.defaultPrevented||a==null||a())},p),T=Dx(E=>{const N=E.target;[...c.branches].some(D=>D.contains(N))||(s==null||s(E),i==null||i(E),E.defaultPrevented||a==null||a())},p);return Nx(E=>{b===c.layers.size-1&&(r==null||r(E),!E.defaultPrevented&&a&&(E.preventDefault(),a()))},p),v.useEffect(()=>{if(d)return n&&(c.layersWithOutsidePointerEventsDisabled.size===0&&(hc=p.body.style.pointerEvents,p.body.style.pointerEvents="none"),c.layersWithOutsidePointerEventsDisabled.add(d)),c.layers.add(d),gc(),()=>{n&&c.layersWithOutsidePointerEventsDisabled.size===1&&(p.body.style.pointerEvents=hc)}},[d,p,n,c]),v.useEffect(()=>()=>{d&&(c.layers.delete(d),c.layersWithOutsidePointerEventsDisabled.delete(d),gc())},[d,c]),v.useEffect(()=>{const E=()=>h({});return document.addEventListener(xi,E),()=>document.removeEventListener(xi,E)},[]),u.jsx(Ne.div,{...l,ref:g,style:{pointerEvents:S?k?"auto":"none":void 0,...e.style},onFocusCapture:pe(e.onFocusCapture,T.onFocusCapture),onBlurCapture:pe(e.onBlurCapture,T.onBlurCapture),onPointerDownCapture:pe(e.onPointerDownCapture,C.onPointerDownCapture)})});Oo.displayName=_x;var Rx="DismissableLayerBranch",Px=v.forwardRef((e,t)=>{const n=v.useContext(mc),r=v.useRef(null),o=$e(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})});Px.displayName=Rx;function Ox(e,t=globalThis==null?void 0:globalThis.document){const n=Et(e),r=v.useRef(!1),o=v.useRef(()=>{});return v.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let l=function(){xc(jx,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 Dx(e,t=globalThis==null?void 0:globalThis.document){const n=Et(e),r=v.useRef(!1);return v.useEffect(()=>{const o=s=>{s.target&&!r.current&&xc(Mx,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 gc(){const e=new CustomEvent(xi);document.dispatchEvent(e)}function xc(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?pc(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]??yc()),document.body.insertAdjacentElement("beforeend",e[1]??yc()),yi++,()=>{yi===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),yi--}},[])}function yc(){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",vc={bubbles:!1,cancelable:!0},Lx="FocusScope",Do=v.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:s,...i}=e,[a,l]=v.useState(null),c=Et(o),d=Et(s),f=v.useRef(null),p=$e(t,m=>l(m)),h=v.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;v.useEffect(()=>{if(r){let m=function(S){if(h.paused||!a)return;const k=S.target;a.contains(k)?f.current=k:jn(f.current,{select:!0})},y=function(S){if(h.paused||!a)return;const k=S.relatedTarget;k!==null&&(a.contains(k)||jn(f.current,{select:!0}))},x=function(S){if(document.activeElement===document.body)for(const C of S)C.removedNodes.length>0&&jn(a)};document.addEventListener("focusin",m),document.addEventListener("focusout",y);const b=new MutationObserver(x);return a&&b.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",m),document.removeEventListener("focusout",y),b.disconnect()}}},[r,a,h.paused]),v.useEffect(()=>{if(a){Sc.add(h);const m=document.activeElement;if(!a.contains(m)){const x=new CustomEvent(bi,vc);a.addEventListener(bi,c),a.dispatchEvent(x),x.defaultPrevented||($x(Hx(bc(a)),{select:!0}),document.activeElement===m&&jn(a))}return()=>{a.removeEventListener(bi,c),setTimeout(()=>{const x=new CustomEvent(wi,vc);a.addEventListener(wi,d),a.dispatchEvent(x),x.defaultPrevented||jn(m??document.body,{select:!0}),a.removeEventListener(wi,d),Sc.remove(h)},0)}}},[a,c,d,h]);const g=v.useCallback(m=>{if(!n&&!r||h.paused)return;const y=m.key==="Tab"&&!m.altKey&&!m.ctrlKey&&!m.metaKey,x=document.activeElement;if(y&&x){const b=m.currentTarget,[S,k]=Fx(b);S&&k?!m.shiftKey&&x===k?(m.preventDefault(),n&&jn(S,{select:!0})):m.shiftKey&&x===S&&(m.preventDefault(),n&&jn(k,{select:!0})):x===b&&m.preventDefault()}},[n,r,h.paused]);return u.jsx(Ne.div,{tabIndex:-1,...i,ref:p,onKeyDown:g})});Do.displayName=Lx;function $x(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(jn(r,{select:t}),document.activeElement!==n)return}function Fx(e){const t=bc(e),n=wc(t,e),r=wc(t.reverse(),e);return[n,r]}function bc(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 wc(e,t){for(const n of e)if(!Bx(n,{upTo:t}))return n}function Bx(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 zx(e){return e instanceof HTMLInputElement&&"select"in e}function jn(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&zx(e)&&t&&e.select()}}var Sc=Ux();function Ux(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=Cc(e,t),e.unshift(t)},remove(t){var n;e=Cc(e,t),(n=e[0])==null||n.resume()}}}function Cc(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function Hx(e){return e.filter(t=>t.tagName!=="A")}var Wx=v[" useId ".trim().toString()]||(()=>{}),Vx=0;function kn(e){const[t,n]=v.useState(Wx());return kt(()=>{n(r=>r??String(Vx++))},[e]),t?`radix-${t}`:""}const Kx=["top","right","bottom","left"],Mn=Math.min,Ut=Math.max,Lo=Math.round,$o=Math.floor,pn=e=>({x:e,y:e}),qx={left:"right",right:"left",bottom:"top",top:"bottom"},Gx={start:"end",end:"start"};function Si(e,t,n){return Ut(e,Mn(t,n))}function En(e,t){return typeof e=="function"?e(t):e}function In(e){return e.split("-")[0]}function hr(e){return e.split("-")[1]}function Ci(e){return e==="x"?"y":"x"}function Ti(e){return e==="y"?"height":"width"}const Yx=new Set(["top","bottom"]);function hn(e){return Yx.has(In(e))?"y":"x"}function ki(e){return Ci(hn(e))}function Xx(e,t,n){n===void 0&&(n=!1);const r=hr(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=Fo(i)),[i,Fo(i)]}function Jx(e){const t=Fo(e);return[Ei(e),t,Ei(t)]}function Ei(e){return e.replace(/start|end/g,t=>Gx[t])}const Tc=["left","right"],kc=["right","left"],Zx=["top","bottom"],Qx=["bottom","top"];function ey(e,t,n){switch(e){case"top":case"bottom":return n?t?kc:Tc:t?Tc:kc;case"left":case"right":return t?Zx:Qx;default:return[]}}function ty(e,t,n,r){const o=hr(e);let s=ey(In(e),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(Ei)))),s}function Fo(e){return e.replace(/left|right|bottom|top/g,t=>qx[t])}function ny(e){return{top:0,right:0,bottom:0,left:0,...e}}function Ec(e){return typeof e!="number"?ny(e):{top:e,right:e,bottom:e,left:e}}function Bo(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=ki(t),a=Ti(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,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(hr(t)){case"start":h[i]-=p*(n&&c?-1:1);break;case"end":h[i]+=p*(n&&c?-1:1);break}return h}const ry=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),p=r,h={},g=0;for(let m=0;m<a.length;m++){const{name:y,fn:x}=a[m],{x:b,y:S,data:k,reset:C}=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=S??f,h={...h,[y]:{...h[y],...k}},C&&g<=50&&(g++,typeof C=="object"&&(C.placement&&(p=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,p,l)),m=-1)}return{x:d,y:f,placement:p,strategy:o,middlewareData:h}};async function $r(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}=En(t,e),g=Ec(h),y=a[p?f==="floating"?"reference":"floating":f],x=Bo(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=Bo(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:b,offsetParent:S,strategy:l}):b);return{top:(x.top-C.top+g.top)/k.y,bottom:(C.bottom-x.bottom+g.bottom)/k.y,left:(x.left-C.left+g.left)/k.x,right:(C.right-x.right+g.right)/k.x}}const oy=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}=En(e,t)||{};if(c==null)return{};const f=Ec(d),p={x:n,y:r},h=ki(o),g=Ti(h),m=await i.getDimensions(c),y=h==="y",x=y?"top":"left",b=y?"bottom":"right",S=y?"clientHeight":"clientWidth",k=s.reference[g]+s.reference[h]-p[h]-s.floating[g],C=p[h]-s.reference[h],T=await(i.getOffsetParent==null?void 0:i.getOffsetParent(c));let E=T?T[S]:0;(!E||!await(i.isElement==null?void 0:i.isElement(T)))&&(E=a.floating[S]||s.floating[g]);const N=k/2-C/2,_=E/2-m[g]/2-1,D=Mn(f[x],_),B=Mn(f[b],_),G=D,V=E-m[g]-B,R=E/2-m[g]/2+N,M=Si(G,R,V),A=!l.arrow&&hr(o)!=null&&R!==M&&s.reference[g]/2-(R<G?D:B)-m[g]/2<0,F=A?R<G?R-G:R-V:0;return{[h]:p[h]+F,data:{[h]:M,centerOffset:R-M-F,...A&&{alignmentOffset:F}},reset:A}}}),sy=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:g="none",flipAlignment:m=!0,...y}=En(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=p||(S||!m?[Fo(a)]:Jx(a)),T=g!=="none";!p&&T&&C.push(...ty(a,m,g,k));const E=[a,...C],N=await $r(t,y),_=[];let D=((r=s.flip)==null?void 0:r.overflows)||[];if(d&&_.push(N[x]),f){const R=Xx(o,i,k);_.push(N[R[0]],N[R[1]])}if(D=[...D,{placement:o,overflows:_}],!_.every(R=>R<=0)){var B,G;const R=(((B=s.flip)==null?void 0:B.index)||0)+1,M=E[R];if(M&&(!(f==="alignment"?b!==hn(M):!1)||D.every(L=>hn(L.placement)===b?L.overflows[0]>0:!0)))return{data:{index:R,overflows:D},reset:{placement:M}};let A=(G=D.filter(F=>F.overflows[0]<=0).sort((F,L)=>F.overflows[1]-L.overflows[1])[0])==null?void 0:G.placement;if(!A)switch(h){case"bestFit":{var V;const F=(V=D.filter(L=>{if(T){const P=hn(L.placement);return P===b||P==="y"}return!0}).map(L=>[L.placement,L.overflows.filter(P=>P>0).reduce((P,z)=>P+z,0)]).sort((L,P)=>L[1]-P[1])[0])==null?void 0:V[0];F&&(A=F);break}case"initialPlacement":A=a;break}if(o!==A)return{reset:{placement:A}}}return{}}}};function Ac(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function Nc(e){return Kx.some(t=>e[t]>=0)}const iy=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n}=t,{strategy:r="referenceHidden",...o}=En(e,t);switch(r){case"referenceHidden":{const s=await $r(t,{...o,elementContext:"reference"}),i=Ac(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:Nc(i)}}}case"escaped":{const s=await $r(t,{...o,altBoundary:!0}),i=Ac(s,n.floating);return{data:{escapedOffsets:i,escaped:Nc(i)}}}default:return{}}}}},_c=new Set(["left","top"]);async function ay(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=_c.has(i)?-1:1,d=s&&l?-1:1,f=En(t,e);let{mainAxis:p,crossAxis:h,alignmentAxis:g}=typeof f=="number"?{mainAxis:f,crossAxis:0,alignmentAxis:null}:{mainAxis:f.mainAxis||0,crossAxis:f.crossAxis||0,alignmentAxis:f.alignmentAxis};return a&&typeof g=="number"&&(h=a==="end"?g*-1:g),l?{x:h*d,y:p*c}:{x:p*c,y:h*d}}const ly=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 ay(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}}}}},cy=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}=En(e,t),c={x:n,y:r},d=await $r(t,l),f=hn(In(o)),p=Ci(f);let h=c[p],g=c[f];if(s){const y=p==="y"?"top":"left",x=p==="y"?"bottom":"right",b=h+d[y],S=h-d[x];h=Si(b,h,S)}if(i){const y=f==="y"?"top":"left",x=f==="y"?"bottom":"right",b=g+d[y],S=g-d[x];g=Si(b,g,S)}const m=a.fn({...t,[p]:h,[f]:g});return{...m,data:{x:m.x-n,y:m.y-r,enabled:{[p]:s,[f]:i}}}}}},uy=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}=En(e,t),d={x:n,y:r},f=hn(o),p=Ci(f);let h=d[p],g=d[f];const m=En(a,t),y=typeof m=="number"?{mainAxis:m,crossAxis:0}:{mainAxis:0,crossAxis:0,...m};if(l){const S=p==="y"?"height":"width",k=s.reference[p]-s.floating[S]+y.mainAxis,C=s.reference[p]+s.reference[S]-y.mainAxis;h<k?h=k:h>C&&(h=C)}if(c){var x,b;const S=p==="y"?"width":"height",k=_c.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);g<C?g=C:g>T&&(g=T)}return{[p]:h,[f]:g}}}},dy=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}=En(e,t),d=await $r(t,c),f=In(o),p=hr(o),h=hn(o)==="y",{width:g,height:m}=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=m-d.top-d.bottom,S=g-d.left-d.right,k=Mn(m-d[y],b),C=Mn(g-d[x],S),T=!t.middlewareData.shift;let E=k,N=C;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(N=S),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(E=b),T&&!p){const D=Ut(d.left,0),B=Ut(d.right,0),G=Ut(d.top,0),V=Ut(d.bottom,0);h?N=g-2*(D!==0||B!==0?D+B:Ut(d.left,d.right)):E=m-2*(G!==0||V!==0?G+V:Ut(d.top,d.bottom))}await l({...t,availableWidth:N,availableHeight:E});const _=await i.getDimensions(a.floating);return g!==_.width||m!==_.height?{reset:{rects:!0}}:{}}}};function zo(){return typeof window<"u"}function mr(e){return jc(e)?(e.nodeName||"").toLowerCase():"#document"}function Ht(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function mn(e){var t;return(t=(jc(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function jc(e){return zo()?e instanceof Node||e instanceof Ht(e).Node:!1}function sn(e){return zo()?e instanceof Element||e instanceof Ht(e).Element:!1}function gn(e){return zo()?e instanceof HTMLElement||e instanceof Ht(e).HTMLElement:!1}function Mc(e){return!zo()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Ht(e).ShadowRoot}const fy=new Set(["inline","contents"]);function Fr(e){const{overflow:t,overflowX:n,overflowY:r,display:o}=an(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!fy.has(o)}const py=new Set(["table","td","th"]);function hy(e){return py.has(mr(e))}const my=[":popover-open",":modal"];function Uo(e){return my.some(t=>{try{return e.matches(t)}catch{return!1}})}const gy=["transform","translate","scale","rotate","perspective"],xy=["transform","translate","scale","rotate","perspective","filter"],yy=["paint","layout","strict","content"];function Ii(e){const t=Ai(),n=sn(e)?an(e):e;return gy.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)||xy.some(r=>(n.willChange||"").includes(r))||yy.some(r=>(n.contain||"").includes(r))}function vy(e){let t=Rn(e);for(;gn(t)&&!gr(t);){if(Ii(t))return t;if(Uo(t))return null;t=Rn(t)}return null}function Ai(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const by=new Set(["html","body","#document"]);function gr(e){return by.has(mr(e))}function an(e){return Ht(e).getComputedStyle(e)}function Ho(e){return sn(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Rn(e){if(mr(e)==="html")return e;const t=e.assignedSlot||e.parentNode||Mc(e)&&e.host||mn(e);return Mc(t)?t.host:t}function Rc(e){const t=Rn(e);return gr(t)?e.ownerDocument?e.ownerDocument.body:e.body:gn(t)&&Fr(t)?t:Rc(t)}function Br(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const o=Rc(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=Ht(o);if(s){const a=Ni(i);return t.concat(i,i.visualViewport||[],Fr(o)?o:[],a&&n?Br(a):[])}return t.concat(o,Br(o,[],n))}function Ni(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function Pc(e){const t=an(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=Lo(n)!==s||Lo(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function _i(e){return sn(e)?e:e.contextElement}function xr(e){const t=_i(e);if(!gn(t))return pn(1);const n=t.getBoundingClientRect(),{width:r,height:o,$:s}=Pc(t);let i=(s?Lo(n.width):n.width)/r,a=(s?Lo(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const wy=pn(0);function Oc(e){const t=Ht(e);return!Ai()||!t.visualViewport?wy:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function Sy(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==Ht(e)?!1:t}function Yn(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const o=e.getBoundingClientRect(),s=_i(e);let i=pn(1);t&&(r?sn(r)&&(i=xr(r)):i=xr(e));const a=Sy(s,n,r)?Oc(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 p=Ht(s),h=r&&sn(r)?Ht(r):r;let g=p,m=Ni(g);for(;m&&r&&h!==g;){const y=xr(m),x=m.getBoundingClientRect(),b=an(m),S=x.left+(m.clientLeft+parseFloat(b.paddingLeft))*y.x,k=x.top+(m.clientTop+parseFloat(b.paddingTop))*y.y;l*=y.x,c*=y.y,d*=y.x,f*=y.y,l+=S,c+=k,g=Ht(m),m=Ni(g)}}return Bo({width:d,height:f,x:l,y:c})}function Wo(e,t){const n=Ho(e).scrollLeft;return t?t.left+n:Yn(mn(e)).left+n}function Dc(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-Wo(e,n),o=n.top+t.scrollTop;return{x:r,y:o}}function Cy(e){let{elements:t,rect:n,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=mn(r),a=t?Uo(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"||Fr(i))&&(l=Ho(r)),gn(r))){const h=Yn(r);c=xr(r),d.x=h.x+r.clientLeft,d.y=h.y+r.clientTop}const p=i&&!f&&!s?Dc(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+p.x,y:n.y*c.y-l.scrollTop*c.y+d.y+p.y}}function Ty(e){return Array.from(e.getClientRects())}function ky(e){const t=mn(e),n=Ho(e),r=e.ownerDocument.body,o=Ut(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=Ut(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let i=-n.scrollLeft+Wo(e);const a=-n.scrollTop;return an(r).direction==="rtl"&&(i+=Ut(t.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}const Lc=25;function Ey(e,t){const n=Ht(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=Ai();(!d||d&&t==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}const c=Wo(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,g=Math.abs(r.clientWidth-f.clientWidth-h);g<=Lc&&(s-=g)}else c<=Lc&&(s+=c);return{width:s,height:i,x:a,y:l}}const Iy=new Set(["absolute","fixed"]);function Ay(e,t){const n=Yn(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 $c(e,t,n){let r;if(t==="viewport")r=Ey(e,n);else if(t==="document")r=ky(mn(e));else if(sn(t))r=Ay(t,n);else{const o=Oc(e);r={x:t.x-o.x,y:t.y-o.y,width:t.width,height:t.height}}return Bo(r)}function Fc(e,t){const n=Rn(e);return n===t||!sn(n)||gr(n)?!1:an(n).position==="fixed"||Fc(n,t)}function Ny(e,t){const n=t.get(e);if(n)return n;let r=Br(e,[],!1).filter(a=>sn(a)&&mr(a)!=="body"),o=null;const s=an(e).position==="fixed";let i=s?Rn(e):e;for(;sn(i)&&!gr(i);){const a=an(i),l=Ii(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&Iy.has(o.position)||Fr(i)&&!l&&Fc(e,i))?r=r.filter(d=>d!==i):o=a,i=Rn(i)}return t.set(e,r),r}function _y(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i=[...n==="clippingAncestors"?Uo(t)?[]:Ny(t,this._c):[].concat(n),r],a=i[0],l=i.reduce((c,d)=>{const f=$c(t,d,o);return c.top=Ut(f.top,c.top),c.right=Mn(f.right,c.right),c.bottom=Mn(f.bottom,c.bottom),c.left=Ut(f.left,c.left),c},$c(t,a,o));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function jy(e){const{width:t,height:n}=Pc(e);return{width:t,height:n}}function My(e,t,n){const r=gn(t),o=mn(t),s=n==="fixed",i=Yn(e,!0,s,t);let a={scrollLeft:0,scrollTop:0};const l=pn(0);function c(){l.x=Wo(o)}if(r||!r&&!s)if((mr(t)!=="body"||Fr(o))&&(a=Ho(t)),r){const h=Yn(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?Dc(o,a):pn(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 an(e).position==="static"}function Bc(e,t){if(!gn(e)||an(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return mn(e)===n&&(n=n.ownerDocument.body),n}function zc(e,t){const n=Ht(e);if(Uo(e))return n;if(!gn(e)){let o=Rn(e);for(;o&&!gr(o);){if(sn(o)&&!ji(o))return o;o=Rn(o)}return n}let r=Bc(e,t);for(;r&&hy(r)&&ji(r);)r=Bc(r,t);return r&&gr(r)&&ji(r)&&!Ii(r)?n:r||vy(e)||n}const Ry=async function(e){const t=this.getOffsetParent||zc,n=this.getDimensions,r=await n(e.floating);return{reference:My(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function Py(e){return an(e).direction==="rtl"}const Oy={convertOffsetParentRelativeRectToViewportRelativeRect:Cy,getDocumentElement:mn,getClippingRect:_y,getOffsetParent:zc,getElementRects:Ry,getClientRects:Ty,getDimensions:jy,getScale:xr,isElement:sn,isRTL:Py};function Uc(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function Dy(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:p,height:h}=c;if(a||t(),!p||!h)return;const g=$o(f),m=$o(o.clientWidth-(d+p)),y=$o(o.clientHeight-(f+h)),x=$o(d),S={rootMargin:-g+"px "+-m+"px "+-y+"px "+-x+"px",threshold:Ut(0,Mn(1,l))||1};let k=!0;function C(T){const E=T[0].intersectionRatio;if(E!==l){if(!k)return i();E?i(!1,E):r=setTimeout(()=>{i(!1,1e-7)},1e3)}E===1&&!Uc(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 Ly(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?Br(c):[],...Br(t)]:[];d.forEach(x=>{o&&x.addEventListener("scroll",n,{passive:!0}),s&&x.addEventListener("resize",n)});const f=c&&a?Dy(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 S;(S=h)==null||S.observe(t)})),n()}),c&&!l&&h.observe(c),h.observe(t));let g,m=l?Yn(e):null;l&&y();function y(){const x=Yn(e);m&&!Uc(m,x)&&n(),m=x,g=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(g)}}const $y=ly,Fy=cy,By=sy,zy=dy,Uy=iy,Hc=oy,Hy=uy,Wy=(e,t,n)=>{const r=new Map,o={platform:Oy,...n},s={...o.platform,_c:r};return ry(e,t,{...o,platform:s})};var Vy=typeof document<"u",Ky=function(){},Vo=Vy?w.useLayoutEffect:Ky;function Ko(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(!Ko(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)&&!Ko(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function Wc(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function Vc(e,t){const n=Wc(e);return Math.round(t*n)/n}function Mi(e){const t=v.useRef(e);return Vo(()=>{t.current=e}),t}function qy(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);Ko(p,r)||h(r);const[g,m]=v.useState(null),[y,x]=v.useState(null),b=v.useCallback(L=>{L!==T.current&&(T.current=L,m(L))},[]),S=v.useCallback(L=>{L!==E.current&&(E.current=L,x(L))},[]),k=s||g,C=i||y,T=v.useRef(null),E=v.useRef(null),N=v.useRef(d),_=l!=null,D=Mi(l),B=Mi(o),G=Mi(c),V=v.useCallback(()=>{if(!T.current||!E.current)return;const L={placement:t,strategy:n,middleware:p};B.current&&(L.platform=B.current),Wy(T.current,E.current,L).then(P=>{const z={...P,isPositioned:G.current!==!1};R.current&&!Ko(N.current,z)&&(N.current=z,mo.flushSync(()=>{f(z)}))})},[p,t,n,B,G]);Vo(()=>{c===!1&&N.current.isPositioned&&(N.current.isPositioned=!1,f(L=>({...L,isPositioned:!1})))},[c]);const R=v.useRef(!1);Vo(()=>(R.current=!0,()=>{R.current=!1}),[]),Vo(()=>{if(k&&(T.current=k),C&&(E.current=C),k&&C){if(D.current)return D.current(k,C,V);V()}},[k,C,V,D,_]);const M=v.useMemo(()=>({reference:T,floating:E,setReference:b,setFloating:S}),[b,S]),A=v.useMemo(()=>({reference:k,floating:C}),[k,C]),F=v.useMemo(()=>{const L={position:n,left:0,top:0};if(!A.floating)return L;const P=Vc(A.floating,d.x),z=Vc(A.floating,d.y);return a?{...L,transform:"translate("+P+"px, "+z+"px)",...Wc(A.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:P,top:z}},[n,a,A.floating,d.x,d.y]);return v.useMemo(()=>({...d,update:V,refs:M,elements:A,floatingStyles:F}),[d,V,M,A,F])}const Gy=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?Hc({element:r.current,padding:o}).fn(n):{}:r?Hc({element:r,padding:o}).fn(n):{}}}},Yy=(e,t)=>({...$y(e),options:[e,t]}),Xy=(e,t)=>({...Fy(e),options:[e,t]}),Jy=(e,t)=>({...Hy(e),options:[e,t]}),Zy=(e,t)=>({...By(e),options:[e,t]}),Qy=(e,t)=>({...zy(e),options:[e,t]}),ev=(e,t)=>({...Uy(e),options:[e,t]}),tv=(e,t)=>({...Gy(e),options:[e,t]});var nv="Arrow",Kc=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"})})});Kc.displayName=nv;var rv=Kc;function qc(e){const[t,n]=v.useState(void 0);return kt(()=>{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",[Gc,qo]=Tn(Ri),[ov,Yc]=Gc(Ri),Xc=e=>{const{__scopePopper:t,children:n}=e,[r,o]=v.useState(null);return u.jsx(ov,{scope:t,anchor:r,onAnchorChange:o,children:n})};Xc.displayName=Ri;var Jc="PopperAnchor",Zc=v.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...o}=e,s=Yc(Jc,n),i=v.useRef(null),a=$e(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})});Zc.displayName=Jc;var Pi="PopperContent",[sv,iv]=Gc(Pi),Qc=v.forwardRef((e,t)=>{var J,$,Y,Z,de,oe;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:g,...m}=e,y=Yc(Pi,n),[x,b]=v.useState(null),S=$e(t,_e=>b(_e)),[k,C]=v.useState(null),T=qc(k),E=(T==null?void 0:T.width)??0,N=(T==null?void 0:T.height)??0,_=r+(s!=="center"?"-"+s:""),D=typeof d=="number"?d:{top:0,right:0,bottom:0,left:0,...d},B=Array.isArray(c)?c:[c],G=B.length>0,V={padding:D,boundary:B.filter(lv),altBoundary:G},{refs:R,floatingStyles:M,placement:A,isPositioned:F,middlewareData:L}=qy({strategy:"fixed",placement:_,whileElementsMounted:(..._e)=>Ly(..._e,{animationFrame:h==="always"}),elements:{reference:y.anchor},middleware:[Yy({mainAxis:o+N,alignmentAxis:i}),l&&Xy({mainAxis:!0,crossAxis:!1,limiter:f==="partial"?Jy():void 0,...V}),l&&Zy({...V}),Qy({...V,apply:({elements:_e,rects:ze,availableWidth:se,availableHeight:me})=>{const{width:Re,height:Ve}=ze.reference,ut=_e.floating.style;ut.setProperty("--radix-popper-available-width",`${se}px`),ut.setProperty("--radix-popper-available-height",`${me}px`),ut.setProperty("--radix-popper-anchor-width",`${Re}px`),ut.setProperty("--radix-popper-anchor-height",`${Ve}px`)}}),k&&tv({element:k,padding:a}),cv({arrowWidth:E,arrowHeight:N}),p&&ev({strategy:"referenceHidden",...V})]}),[P,z]=nu(A),X=Et(g);kt(()=>{F&&(X==null||X())},[F,X]);const ne=(J=L.arrow)==null?void 0:J.x,ye=($=L.arrow)==null?void 0:$.y,Te=((Y=L.arrow)==null?void 0:Y.centerOffset)!==0,[q,U]=v.useState();return kt(()=>{x&&U(window.getComputedStyle(x).zIndex)},[x]),u.jsx("div",{ref:R.setFloating,"data-radix-popper-content-wrapper":"",style:{...M,transform:F?M.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:q,"--radix-popper-transform-origin":[(Z=L.transformOrigin)==null?void 0:Z.x,(de=L.transformOrigin)==null?void 0:de.y].join(" "),...((oe=L.hide)==null?void 0:oe.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:u.jsx(sv,{scope:n,placedSide:P,onArrowChange:C,arrowX:ne,arrowY:ye,shouldHideArrow:Te,children:u.jsx(Ne.div,{"data-side":P,"data-align":z,...m,ref:S,style:{...m.style,animation:F?void 0:"none"}})})})});Qc.displayName=Pi;var eu="PopperArrow",av={top:"bottom",right:"left",bottom:"top",left:"right"},tu=v.forwardRef(function(t,n){const{__scopePopper:r,...o}=t,s=iv(eu,r),i=av[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(rv,{...o,ref:n,style:{...o.style,display:"block"}})})});tu.displayName=eu;function lv(e){return e!==null}var cv=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]=nu(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 g="",m="";return c==="bottom"?(g=i?f:`${p}px`,m=`${-l}px`):c==="top"?(g=i?f:`${p}px`,m=`${r.floating.height+l}px`):c==="right"?(g=`${-l}px`,m=i?f:`${h}px`):c==="left"&&(g=`${r.floating.width+l}px`,m=i?f:`${h}px`),{data:{x:g,y:m}}}});function nu(e){const[t,n="center"]=e.split("-");return[t,n]}var ru=Xc,ou=Zc,su=Qc,iu=tu,uv="Portal",Go=v.forwardRef((e,t)=>{var a;const{container:n,...r}=e,[o,s]=v.useState(!1);kt(()=>s(!0),[]);const i=n||o&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?Ys.createPortal(u.jsx(Ne.div,{...r,ref:t}),i):null});Go.displayName=uv;function dv(e,t){return v.useReducer((n,r)=>t[n][r]??n,e)}var Xt=e=>{const{present:t,children:n}=e,r=fv(t),o=typeof n=="function"?n({present:r.isPresent}):v.Children.only(n),s=$e(r.ref,pv(o));return typeof n=="function"||r.isPresent?v.cloneElement(o,{ref:s}):null};Xt.displayName="Presence";function fv(e){const[t,n]=v.useState(),r=v.useRef(null),o=v.useRef(e),s=v.useRef("none"),i=e?"mounted":"unmounted",[a,l]=dv(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return v.useEffect(()=>{const c=Yo(r.current);s.current=a==="mounted"?c:"none"},[a]),kt(()=>{const c=r.current,d=o.current;if(d!==e){const p=s.current,h=Yo(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]),kt(()=>{if(t){let c;const d=t.ownerDocument.defaultView??window,f=h=>{const m=Yo(r.current).includes(CSS.escape(h.animationName));if(h.target===t&&m&&(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=Yo(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 Yo(e){return(e==null?void 0:e.animationName)||"none"}function pv(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",hv={bubbles:!1,cancelable:!0},zr="RovingFocusGroup",[Di,au,mv]=gi(zr),[gv,lu]=Tn(zr,[mv]),[xv,yv]=gv(zr),cu=v.forwardRef((e,t)=>u.jsx(Di.Provider,{scope:e.__scopeRovingFocusGroup,children:u.jsx(Di.Slot,{scope:e.__scopeRovingFocusGroup,children:u.jsx(vv,{...e,ref:t})})}));cu.displayName=zr;var vv=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=$e(t,p),g=Po(s),[m,y]=pr({prop:i,defaultProp:a??null,onChange:l,caller:zr}),[x,b]=v.useState(!1),S=Et(c),k=au(n),C=v.useRef(!1),[T,E]=v.useState(0);return v.useEffect(()=>{const N=p.current;if(N)return N.addEventListener(Oi,S),()=>N.removeEventListener(Oi,S)},[S]),u.jsx(xv,{scope:n,orientation:r,dir:g,loop:o,currentTabStopId:m,onItemFocus:v.useCallback(N=>y(N),[y]),onItemShiftTab:v.useCallback(()=>b(!0),[]),onFocusableItemAdd:v.useCallback(()=>E(N=>N+1),[]),onFocusableItemRemove:v.useCallback(()=>E(N=>N-1),[]),children:u.jsx(Ne.div,{tabIndex:x||T===0?-1:0,"data-orientation":r,...f,ref:h,style:{outline:"none",...e.style},onMouseDown:pe(e.onMouseDown,()=>{C.current=!0}),onFocus:pe(e.onFocus,N=>{const _=!C.current;if(N.target===N.currentTarget&&_&&!x){const D=new CustomEvent(Oi,hv);if(N.currentTarget.dispatchEvent(D),!D.defaultPrevented){const B=k().filter(A=>A.focusable),G=B.find(A=>A.active),V=B.find(A=>A.id===m),M=[G,V,...B].filter(Boolean).map(A=>A.ref.current);fu(M,d)}}C.current=!1}),onBlur:pe(e.onBlur,()=>b(!1))})})}),uu="RovingFocusGroupItem",du=v.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:o=!1,tabStopId:s,children:i,...a}=e,l=kn(),c=s||l,d=yv(uu,n),f=d.currentTabStopId===c,p=au(n),{onFocusableItemAdd:h,onFocusableItemRemove:g,currentTabStopId:m}=d;return v.useEffect(()=>{if(r)return h(),()=>g()},[r,h,g]),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:pe(e.onMouseDown,y=>{r?d.onItemFocus(c):y.preventDefault()}),onFocus:pe(e.onFocus,()=>d.onItemFocus(c)),onKeyDown:pe(e.onKeyDown,y=>{if(y.key==="Tab"&&y.shiftKey){d.onItemShiftTab();return}if(y.target!==y.currentTarget)return;const x=Sv(y,d.orientation,d.dir);if(x!==void 0){if(y.metaKey||y.ctrlKey||y.altKey||y.shiftKey)return;y.preventDefault();let S=p().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?Cv(S,k+1):S.slice(k+1)}setTimeout(()=>fu(S))}}),children:typeof i=="function"?i({isCurrentTabStop:f,hasTabStop:m!=null}):i})})});du.displayName=uu;var bv={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function wv(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function Sv(e,t,n){const r=wv(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return bv[r]}function fu(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function Cv(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Tv=cu,kv=du,Ev=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},yr=new WeakMap,Xo=new WeakMap,Jo={},Li=0,pu=function(e){return e&&(e.host||pu(e.parentNode))},Iv=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=pu(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})},Av=function(e,t,n,r){var o=Iv(t,Array.isArray(e)?e:[e]);Jo[n]||(Jo[n]=new WeakMap);var s=Jo[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),g=h!==null&&h!=="false",m=(yr.get(p)||0)+1,y=(s.get(p)||0)+1;yr.set(p,m),s.set(p,y),i.push(p),m===1&&g&&Xo.set(p,!0),y===1&&p.setAttribute(n,"true"),g||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=yr.get(f)-1,h=s.get(f)-1;yr.set(f,p),s.set(f,h),p||(Xo.has(f)||f.removeAttribute(r),Xo.delete(f)),h||f.removeAttribute(n)}),Li--,Li||(yr=new WeakMap,yr=new WeakMap,Xo=new WeakMap,Jo={})}},$i=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),o=Ev(e);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live], script"))),Av(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 hu(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 Nv(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 Zo="right-scroll-bar-position",Qo="width-before-scroll-bar",_v="with-scroll-bars-hidden",jv="--removed-body-scroll-bar-size";function Fi(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function Mv(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 Rv=typeof window<"u"?v.useLayoutEffect:v.useEffect,mu=new WeakMap;function Pv(e,t){var n=Mv(null,function(r){return e.forEach(function(o){return Fi(o,r)})});return Rv(function(){var r=mu.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)})}mu.set(n,e)},[e]),n}function Ov(e){return e}function Dv(e,t){t===void 0&&(t=Ov);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 Lv(e){e===void 0&&(e={});var t=Dv(null);return t.options=xn({async:!0,ssr:!1},e),t}var gu=function(e){var t=e.sideCar,n=hu(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))};gu.isSideCarExport=!0;function $v(e,t){return e.useMedium(t),gu}var xu=Lv(),Bi=function(){},es=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,g=e.noIsolation,m=e.inert,y=e.allowPinchZoom,x=e.as,b=x===void 0?"div":x,S=e.gapMode,k=hu(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),C=p,T=Pv([n,t]),E=xn(xn({},k),o);return v.createElement(v.Fragment,null,d&&v.createElement(C,{sideCar:xu,removeScrollBar:c,shards:f,noRelative:h,noIsolation:g,inert:m,setCallbacks:s,allowPinchZoom:!!y,lockRef:n,gapMode:S}),i?v.cloneElement(v.Children.only(a),xn(xn({},E),{ref:T})):v.createElement(b,xn({},E,{className:l,ref:T}),a))});es.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},es.classNames={fullWidth:Qo,zeroRight:Zo};var Fv=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function Bv(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=Fv();return t&&e.setAttribute("nonce",t),e}function zv(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function Uv(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var Hv=function(){var e=0,t=null;return{add:function(n){e==0&&(t=Bv())&&(zv(t,n),Uv(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},Wv=function(){var e=Hv();return function(t,n){v.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},yu=function(){var e=Wv(),t=function(n){var r=n.styles,o=n.dynamic;return e(r,o),null};return t},Vv={left:0,top:0,right:0,gap:0},zi=function(e){return parseInt(e||"",10)||0},Kv=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)]},qv=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return Vv;var t=Kv(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])}},Gv=yu(),vr="data-scroll-locked",Yv=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 J=gt.slice(0,j);gt=gt.slice(j+2);const re=gx(J);if(!re)continue;let ie;try{ie=JSON.parse(re)}catch{console.debug("[use-chat] malformed SSE:",re.slice(0,200));continue}const ce=mx(ie)?ie.data:ie;nn=Date.now();const Xe=ce.seq;if(Xe!==void 0){if(Xe<=it){console.debug("[use-chat] drop duplicate/out-of-order event",{seq:Xe,lastProcessedSeq:it,type:ce.type});continue}it>0&&Xe>it+1&&(($=A==null?void 0:A.onGap)==null||$.call(A,{from:it,to:Xe})),it=Xe,C.current=Xe,y(Xe)}if(ce.type==="checkpoint")E.current=ce.checkpointId??null,N.current=ce.checkpointNs??null,g(ce.checkpointId??null);else if(ce.type==="state_history"){_.current=ce;try{const at=dr(ce).latest;at&&(E.current=at.checkpointId??null,N.current=at.checkpointNs??null,g(at.checkpointId??null))}catch(Ie){console.warn("[use-chat] Failed to hydrate state_history payload",Ie)}}try{M==null||M(ce)}catch(Ie){console.error("[use-chat] Error in onEvent callback:",Ie,"for event:",ce.type)}if(ce.type==="message.delta"){const Ie=ce.delta.filter(at=>at.type==="text").map(at=>at.text).join("");Ie&&e.autoAppendAssistant!==!1&&(Ct.push(Ie),zt())}else if(ce.type==="heartbeat"){console.debug("[use-chat] heartbeat received");try{(Y=A==null?void 0:A.onHeartbeat)==null||Y.call(A,ce)}catch(Ie){console.warn("[use-chat] heartbeat callback failed",Ie)}}else if(St!==null&&cancelAnimationFrame(St),Pt(),ce.type==="checkpoint")g(ce.checkpointId);else if(ce.type==="error"){const Ie=ce;if(d(Ie.message),L="error",R=Ie.message,Ie.error_type==="auth_error"||Ie.code==="TOKEN_EXPIRED"||((Q=Ie.message)==null?void 0:Q.includes("token"))||((de=Ie.message)==null?void 0:de.includes("401"))||((oe=Ie.message)==null?void 0:oe.includes("unauthorized"))||((_e=Ie.message)==null?void 0:_e.includes("Unauthorized"))){console.error("[use-chat] Auth error detected:",Ie.message);try{(ze=A==null?void 0:A.onAuthError)==null||ze.call(A,Ie.message)}catch(ht){console.warn("[use-chat] onAuthError handler failed",ht)}F.abort()}}}}Pt(),L===null&&!F.signal.aborted&&(L="complete")}catch(tt){if(tt.name==="AbortError")L=L??"aborted";else{const We=tt.message||String(tt);L="error",R=We,d(We),(se=A==null?void 0:A.onError)==null||se.call(A,We)}}finally{try{await st.cancel()}catch{}finally{(me=st.releaseLock)==null||me.call(st)}St!==null&&typeof window<"u"&&window.cancelAnimationFrame(St),clearInterval(Le)}}catch(Ke){if(Ke.name==="AbortError")L=L??"aborted";else{const qe=Ke.message||String(Ke);L="error",R=qe,d(qe),(Pe=A==null?void 0:A.onError)==null||Pe.call(A,qe),z||((Ve=A==null?void 0:A.onConnectionError)==null||Ve.call(A,qe),z=!0)}}finally{const Ke=C.current,qe=E.current,Qe=N.current,Ge=_.current,et=L??(F.signal.aborted?"aborted":R?"error":"complete");try{(ut=A==null?void 0:A.onClosed)==null||ut.call(A,{reason:et,lastSeq:Ke,lastCheckpointId:qe,lastCheckpointNs:Qe,lastStateHistory:Ge,error:R})}catch(st){console.warn("[use-chat] onClosed callback failed",st)}l(!1),w(!1),S.current=null,C.current=0,y(0),T.current=null}})(),{close:()=>F.abort()}},[t,n,r,e.autoAppendAssistant]);return b.useEffect(()=>()=>{var P;k.current=!1,(P=S.current)==null||P.abort()},[]),{isStreaming:a,error:c,assistantText:f,lastCheckpointId:h,lastSeq:m,connected:x,stream:V,stop:G,clear:B,setToken:D}}function mx(e){return!!e&&typeof e=="object"&&e.protocolVersion==="v1"&&"data"in e}function gx(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 xx=["message.start","message.delta","message.end","progress"],yx=["tool.start","tool.end"],vx=["thread_info","checkpoint"],wx=["error","interrupt","heartbeat","state_history","cancelled"],bx=[...xx,...yx,...vx,...wx],Sx=new Set(bx);function Cx(e){if(typeof e!="object"||e===null||typeof e.type!="string")return!1;const t=e.type;return Sx.has(t)}const cc=200;function Tx({baseUrl:e,onThreadInfo:t,onMessageEvent:n,onStateHistory:r,onUnhandledEvent:o,onSequenceGap:s,onStreamClosed:i,onConnectionError:a,onAuthError:l,onHeartbeat:c}){const d=b.useRef(null),f=b.useRef(null),p=b.useRef(new Map),h=b.useRef(null),g=b.useRef(null),m=b.useCallback(M=>{try{const A=globalThis.structuredClone;if(typeof A=="function")return A(M)}catch{}try{return JSON.parse(JSON.stringify(M))}catch{return M}},[]),y=b.useCallback((M,A)=>{if(!M)return;const F=p.current.get(M)??[],L=m(A),R=F.length>=cc?[...F.slice(F.length-cc+1),L]:[...F,L];p.current.set(M,R)},[m]),x=b.useCallback(M=>{M&&p.current.set(M,[])},[]),w=b.useCallback(M=>{const A=M??f.current;if(!A)return;const F=p.current.get(A);F!=null&&F.length&&F.forEach(L=>{try{n(L)}catch(R){console.error("[useChatStreamingService] Failed to replay buffered event",R)}})},[n]),S=b.useCallback(M=>{f.current=M.threadId,h.current&&(h.current.threadIdGuess=M.threadId),g.current=M,x(M.threadId),console.log("[useChatStreamingService] 🎯 Received thread_info event:",M);try{t(M)}catch(A){console.error("[useChatStreamingService] Error in onThreadInfo handler:",A)}},[x,t]),k=b.useCallback(M=>{try{c==null||c(M)}catch(A){console.error("[useChatStreamingService] Error in onHeartbeat handler:",A)}},[c]),C=b.useCallback(M=>{var L,R,z,X;const A=M;if(A.error_type==="auth_error"||A.code==="TOKEN_EXPIRED"||((L=A.message)==null?void 0:L.includes("token"))||((R=A.message)==null?void 0:R.includes("401"))||((z=A.message)==null?void 0:z.includes("unauthorized"))||((X=A.message)==null?void 0:X.includes("Unauthorized"))){console.error("[useChatStreamingService] Auth error event detected:",A.message);try{l==null||l(A.message)}catch(ne){console.warn("[useChatStreamingService] onAuthError handler failed",ne)}}},[l]),T=b.useMemo(()=>({thread_info:M=>(S(M),!0),heartbeat:M=>(k(M),!0),error:M=>(C(M),!1)}),[S,k,C]),E=b.useCallback(M=>{var R;const A=M.seq??null;if(A!==null){const z=d.current;if(z!==null){if(A<=z)return;A>z+1&&(s==null||s({from:z,to:A}))}d.current=A}const F=T[M.type];if(F&&F(M))return;const L=M.threadId??(M.type==="state_history"?M.threadId:void 0)??f.current??((R=h.current)==null?void 0:R.threadIdGuess)??null;if(M.type==="state_history"){f.current=L??f.current;try{r==null||r(M)}catch(z){console.error("[useChatStreamingService] onStateHistory handler failed",z)}}if(Cx(M)){M.type==="checkpoint"||M.type==="state_history"?x(L??null):y(L??null,M);try{n(M)}catch(z){console.error("[useChatStreamingService] Error in onMessageEvent handler:",z)}return}try{o==null||o(M)}catch(z){console.error("[useChatStreamingService] Error in onUnhandledEvent handler:",z)}},[y,x,n,s,r,o,T]),{stream:N,stop:_,isStreaming:D,error:B,setToken:G}=lc({baseUrl:e,token:void 0}),V=b.useCallback((M,A)=>{d.current=null,g.current=null,f.current=M.threadId??null,h.current={request:M,callbacks:A,manualStop:!1,threadIdGuess:M.threadId??null},N(M,E,{onOpen:A==null?void 0:A.onOpen,onError:F=>{var L;(L=A==null?void 0:A.onError)==null||L.call(A,F)},onGap:(A==null?void 0:A.onGap)??s,onConnectionError:F=>{var L;a==null||a(F),(L=A==null?void 0:A.onConnectionError)==null||L.call(A,F)},onAuthError:F=>{var L;l==null||l(F),(L=A==null?void 0:A.onAuthError)==null||L.call(A,F)},onHeartbeat:F=>{var L;try{c==null||c(F)}catch(R){console.warn("[useChatStreamingService] onHeartbeat handler failed",R)}try{(L=A==null?void 0:A.onHeartbeat)==null||L.call(A,F)}catch(R){console.warn("[useChatStreamingService] downstream onHeartbeat handler failed",R)}},onClosed:F=>{var X,ne,ye,Te;const L=((X=h.current)==null?void 0:X.manualStop)??!1,R=f.current??((ne=h.current)==null?void 0:ne.threadIdGuess)??((ye=F.lastStateHistory)==null?void 0:ye.threadId)??null;(F.reason==="complete"||F.reason==="aborted"&&L)&&x(R);const z={...F,threadId:R,threadInfo:g.current,manualStop:L};try{i==null||i(z)}catch(q){console.warn("[useChatStreamingService] onStreamClosed handler failed",q)}try{(Te=A==null?void 0:A.onClosed)==null||Te.call(A,z)}catch(q){console.warn("[useChatStreamingService] downstream onClosed handler failed",q)}h.current&&(h.current=null)}})},[x,E,l,a,c,s,i,N]),P=b.useCallback(()=>{h.current&&(h.current.manualStop=!0),_()},[_]);return b.useMemo(()=>({startStream:V,stop:P,isStreaming:D,error:B,setAuthToken:G,replayBufferedEvents:w}),[V,P,D,B,G,w])}const uc=b.createContext(null),dc=b.createContext(null),fc=b.createContext(null);b.createContext(!1);function kx({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}=di(),f=b.useMemo(()=>Cn(d),[d]),[p,h]=b.useState([]),[g,m]=b.useState(t),[y,x]=b.useState(!1),[w,S]=b.useState(null),[k,C]=b.useState(!1),[T,E]=b.useState(null),{state:N,seed:_,prepend:D,pushUser:B,onEvent:G}=Ql(),[V,P]=b.useState(!1),[M,A]=b.useState(!1),[F,L]=b.useState(null),[R,z]=b.useState([]),[X,ne]=b.useState([]),[ye,Te]=b.useState(!1),q=b.useMemo(()=>Xg(R),[R]),U=b.useRef(g),Z=b.useRef(null),$=b.useRef(null),Y=b.useRef(null),Q=b.useRef(null),de=b.useRef(!1),oe=b.useRef(null),_e=b.useRef(new Map),ze=b.useRef(new Map);b.useEffect(()=>{U.current=g},[g]);const se=b.useCallback(async H=>{var J,re;if(!H.threadId)return;const j=H.threadId;(J=H.onStart)==null||J.call(H),H.setLoading(!0);try{await H.action(j)}catch(ie){if(U.current===j){const ce=String(ie);(re=H.handleError)==null||re.call(H,ce),s==null||s(ce)}throw ie}finally{H.setLoading(!1)}},[s]),me=b.useCallback(async()=>{x(!0),S(null);try{const H=await c.listThreads();h(H??[])}catch(H){const j=String(H);S(j),s==null||s(j)}finally{x(!1)}},[c,s]),Pe=b.useCallback(H=>{if(!(H!=null&&H.threadId))return;const j={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(J=>{let re=!1;const ie=J.map(ce=>ce.threadId===j.threadId?(re=!0,console.debug("[ChatSessionProvider] thread_info: updating existing thread",j.threadId),{...ce,title:j.title??ce.title,updatedAt:j.updatedAt??ce.updatedAt,messageCount:j.messageCount??ce.messageCount}):ce);return re?ie:(console.debug("[ChatSessionProvider] thread_info: adding thread to list",j.threadId),[j,...J])})},[]),Ve=b.useCallback(H=>{const j=H.threadId??U.current;if(!j||U.current&&U.current!==j)return;const{checkpoints:J,timeline:re}=dr(H);if(!J.length)return;const ie=J.find(ce=>ce.messages&&ce.messages.length>0)??J.find(ce=>!!ce.checkpointId)??J[0];_((ie==null?void 0:ie.messages)??[],{checkpointId:(ie==null?void 0:ie.checkpointId)??null,checkpointNs:(ie==null?void 0:ie.checkpointNs)??null}),ne(re),z(J),P(!!(ie!=null&&ie.nextCursor)),L((ie==null?void 0:ie.nextCursor)??null),oe.current=`${j}:latest`,$.current=null,Y.current=null},[_]),ut=b.useCallback(H=>{console.log("[ChatSessionProvider] 🎯 Received thread_info:",H.threadId),Pe(H),U.current!==H.threadId&&((H.created??!U.current)&&($.current=H.threadId),Y.current=H.threadId,console.log("[ChatSessionProvider] thread_info: marking to skip auto-load for new thread"),m(H.threadId))},[Pe]),{startStream:Ke,stop:qe,isStreaming:Qe,error:Ge,setAuthToken:et}=Tx({baseUrl:f,onThreadInfo:ut,onMessageEvent:G,onStateHistory:Ve,onUnhandledEvent:H=>{console.warn("[ChatSessionProvider] Unhandled event:",H.type)},onAuthError:i,onConnectionError:l}),st=b.useCallback(async H=>{try{const j=await c.createThread(H);return m(j.threadId),await me(),j.threadId}catch(j){return s==null||s(String(j)),null}},[c,me,s]),Mt=b.useCallback(async H=>{const j=p;h(re=>re.filter(ie=>ie.threadId!==H));const J=new AbortController;ze.current.set(H,J);try{await c.deleteThread(H),U.current===H&&(m(null),_([],{})),console.log("[ChatSessionProvider] Thread deleted successfully:",H)}catch(re){console.error("[ChatSessionProvider] Delete failed, restoring thread:",H,re),h(j),s==null||s(`Failed to delete thread: ${String(re)}`)}finally{ze.current.delete(H)}},[p,c,_,s]),gt=b.useCallback(async(H,j)=>{try{await c.updateThread(H,j),await me()}catch(J){s==null||s(String(J))}},[c,me,s]),Ct=b.useCallback(async(H,j)=>{if(!H)return;const J=`${H}:${j??"latest"}`,re=_e.current.get(J);if(re)return re;const ie=se({threadId:H,setLoading:C,onStart:()=>E(null),handleError:ce=>E(ce),action:async ce=>{const Xe=await c.getStateHistory({threadId:ce,checkpointId:j||void 0});if(U.current!==ce){console.log(`[ChatSessionProvider] Thread changed during load (was ${ce}, now ${U.current}), discarding stale data`);return}const{checkpoints:Ie,timeline:at}=dr(Xe),ht=Ie.find(Kt=>Kt.messages&&Kt.messages.length>0)??(j?Ie.find(Kt=>Kt.checkpointId===j):null)??Ie[0];_((ht==null?void 0:ht.messages)??[],{checkpointId:(ht==null?void 0:ht.checkpointId)??null,checkpointNs:(ht==null?void 0:ht.checkpointNs)??null}),ne(at),z(Ie),P(!!(ht!=null&&ht.nextCursor)),L((ht==null?void 0:ht.nextCursor)??null)}});_e.current.set(J,ie);try{await ie}finally{_e.current.delete(J)}return U.current===H&&(oe.current=J),ie},[c,_,s,se]),it=b.useCallback(async(H,j,J)=>{J!=null&&J.clearProgress&&Jl(),Q.current=H;try{await Ct(H,j)}finally{Q.current===H&&(Q.current=null)}},[Ct]);b.useEffect(()=>{if(!o||!g||k||Qe)return;if($.current===g){$.current=null,Z.current=g;return}if(Y.current===g){Z.current=g;return}if(Q.current===g){Q.current=null,Z.current=g;return}if(Z.current===g)return;Z.current=g;const H=!de.current&&!!n&&g===t;let j;H&&n?(j=n,de.current=!0,console.log("[ChatSessionProvider] Loading thread with checkpoint:",j,r?`(ns: ${r})`:"")):console.log("[ChatSessionProvider] Loading thread with latest checkpoint");const J=`${g}:${j??"latest"}`;oe.current!==J&&it(g,j)},[o,g,n,r,t,k,Qe,it]);const St=b.useCallback(async(H,j)=>{Jl();const J=U.current;await se({threadId:J,setLoading:Te,action:async re=>{const ie=await c.getStateHistory({threadId:re,checkpointId:H,checkpointNs:j??void 0});if(U.current!==re){console.log(`[ChatSessionProvider] Thread changed during checkpoint navigation (was ${re}, now ${U.current}), discarding stale data`);return}const{checkpoints:ce,timeline:Xe}=dr(ie),Ie=ce.find(at=>at.checkpointId===H&&(j?at.checkpointNs===j:!0));if(!Ie){console.warn("[ChatSessionProvider] Requested checkpoint not found:",{checkpointId:H,checkpointNs:j});return}ne(Xe),z(ce),_(Ie.messages??[],{checkpointId:Ie.checkpointId??null,checkpointNs:Ie.checkpointNs??null})}}).catch(()=>{})},[c,_,s,se]),Pt=b.useCallback((H,j)=>{_(N.messages,{checkpointId:H??null,checkpointNs:j??null})},[_,N.messages]),zt=b.useCallback(async()=>{U.current&&await it(U.current)},[it]),nn=b.useCallback(async()=>{const H=U.current;!H||!F||await se({threadId:H,setLoading:A,action:async j=>{const J=await c.getStateHistory({threadId:j,checkpointId:F});if(U.current!==j)return;const{checkpoints:re}=dr(J);if(re.length>0){const ie=re[re.length-1];D((ie==null?void 0:ie.messages)??[]),P(!!(ie!=null&&ie.nextCursor)),L((ie==null?void 0:ie.nextCursor)??null)}}}).catch(()=>{})},[c,F,D,s,se]),Le=b.useCallback(async()=>{_([],{}),m(null),qe(),z([]),ne([]),P(!1),L(null),C(!1),Te(!1),A(!1),E(null);try{await c.getAgent("default")}catch(H){console.warn("[ChatSessionProvider] Failed to refetch agent after clearing thread:",H)}},[_,qe,c]),Sn=b.useCallback(async(H,j,J)=>{const re=U.current;if(!re)throw new Error("No active thread to handle interrupt");const ie=j?J??!0:!1;try{const ce={threadId:re,checkpointId:N.lastCheckpointId??void 0,checkpointNs:N.lastCheckpointNs??void 0,command:{kind:"resume",value:ie}};Ke(ce)}catch(ce){throw console.error(`[ChatSessionProvider] Failed to handle interrupt ${H}:`,ce),ce}},[N.lastCheckpointId,N.lastCheckpointNs,Ke]);b.useEffect(()=>{me()},[me]),b.useEffect(()=>{a==null||a(g)},[g,a]);const tt=b.useCallback(async(H,j)=>{let J=U.current;const re=(H==null?void 0:H.text)??"",ie=(H==null?void 0:H.attachments)??[],ce=(re==null?void 0:re.trim())??"",Xe={...(H==null?void 0:H.payload)??{}},Ie=Array.isArray(Xe.messages)?Xe.messages:void 0;Ie&&delete Xe.messages;const at=!!(Ie&&Ie.length);if(!J&&!ce&&ie.length===0&&!at)return;if(!J){const we=Math.floor(Date.now()/1e3).toString(16).padStart(8,"0"),Be=Array.from({length:4},()=>Math.floor(Math.random()*4294967295).toString(16).padStart(8,"0")).join("").slice(0,16);J=`${we}${Be}`,$.current=J,m(J)}const{contentParts:ht,filesInfo:Kt}=await kg(c,ie),Hn=[...ht];ce&&Hn.push({type:"text",text:re});const Ar=j==null?void 0:j.originalMessageId,Nr=!!(j!=null&&j.edit&&Ar),po=!at&&Hn.length>0;let Nn=null;po&&(Nn={id:Nr?Ar:`msg-${Date.now()}`,role:"user",content:Hn,createdAt:new Date().toISOString()},Nr||B(Nn));const I=at?Ie:Nn?[Nn]:[],W={...Xe,...Kt.length?{files_info:Kt}:{}};I.length?W.messages=I:"messages"in W||(W.messages=[]);const ae={threadId:J,payload:W,checkpointId:(j==null?void 0:j.checkpointId)??N.lastCheckpointId??void 0,checkpointNs:(j==null?void 0:j.checkpointNs)??N.lastCheckpointNs??void 0,edit:!!(j!=null&&j.edit),timelineCheckpoints:X};Ke(ae)},[c,B,N,Ke,X]),We=b.useMemo(()=>({threads:p,currentThreadId:g,setCurrentThreadId:m,isLoading:y,error:w,actions:{createThread:st,deleteThread:Mt,renameThread:gt,refreshThreads:me}}),[p,g,y,w,st,Mt,gt,me]),pt=b.useMemo(()=>{const H=N.assemblingId??null;return H?{assemblingMessageId:H}:null},[N.assemblingId]),Rt=b.useMemo(()=>({threadId:g,messages:N.messages,interrupt:null,checkpoint:{id:N.lastCheckpointId??null,namespace:N.lastCheckpointNs??null},checkpoints:R,timelineCheckpoints:X,metadata:pt,isLoading:k,isHistoryLoading:M,isLoadingCheckpoint:ye,error:T,hasMore:V,loadOlder:nn,clearState:Le,navigateToCheckpoint:St,setCurrentCheckpointId:Pt,returnToLatest:zt,loadThread:it,clearThread:Le,respondToInterrupt:Sn,messagePreviews:q}),[g,N,R,X,k,M,ye,T,V,nn,Le,St,Pt,zt,it,Sn,q,pt]),Ye=b.useMemo(()=>({isStreaming:Qe,error:Ge,connectionState:Qe?"connected":"idle",submit:tt,send:tt,stop:qe,setAuthToken:et}),[Qe,Ge,tt,qe,et]);return u.jsx(uc.Provider,{value:We,children:u.jsx(dc.Provider,{value:Rt,children:u.jsx(fc.Provider,{value:Ye,children:e})})})}function jo(){const e=b.useContext(uc);if(!e)throw new Error("useThreads must be used within ChatSessionProvider");return e}function Mo(){const e=b.useContext(dc);if(!e)throw new Error("useThreadState must be used within ChatSessionProvider");return e}function pc(){const e=b.useContext(fc);if(!e)throw new Error("useStream must be used within ChatSessionProvider");return e}function Po({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(Cg,{apiConfig:t,children:u.jsx(kx,{initialThreadId:n,initialCheckpointId:r,initialCheckpointNs:o,autoLoadInitial:s,onError:a,onAuthError:l,onConnectionError:i,onThreadChange:c,children:e})})}function te(...e){return Xh.twMerge(Yh.clsx(e))}const Ex=ho.cva("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-10 w-10"}},defaultVariants:{variant:"default",size:"default"}}),Je=v.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?Vn.Slot:"button";return u.jsx(i,{className:te(Ex({variant:t,size:n,className:e})),ref:s,...o})});Je.displayName="Button";const hc=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}));hc.displayName="Textarea";function mc({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 g=i!==void 0,[m,y]=b.useState(e),x=(g?i:m)??"",[w,S]=b.useTransition(),k=b.useRef(null),C=b.useRef(0),T=b.useRef(null);b.useEffect(()=>{g||(y(e??""),T.current=null,k.current&&(k.current.style.height="auto",k.current.style.height=`${k.current.scrollHeight}px`))},[e,t,g]);const E=b.useCallback(()=>{const M=k.current;M&&(M.style.height="auto",M.style.height=`${M.scrollHeight}px`)},[]);b.useEffect(()=>{E()},[E,x]);const N=b.useCallback((M,{fromUser:A})=>{g||y(M),A&&(a==null||a(M))},[g,a]),_=b.useCallback(async M=>{M&&M.preventDefault();const A=(x??"").trim();if(!A&&!h)return;const F=++C.current;T.current={id:F,shouldClear:!0},S(()=>{var L,R,z;try{const X=l(A);X&&typeof X.then=="function"?X.then(()=>{var ne,ye;((ne=T.current)==null?void 0:ne.id)===F&&T.current.shouldClear&&(g||(y(""),k.current&&(k.current.style.height="auto"),a==null||a(""))),((ye=T.current)==null?void 0:ye.id)===F&&(T.current=null)}).catch(()=>{var ne;((ne=T.current)==null?void 0:ne.id)===F&&(T.current=null)}):(((L=T.current)==null?void 0:L.id)===F&&T.current.shouldClear&&(g||(y(""),k.current&&(k.current.style.height="auto"),a==null||a(""))),((R=T.current)==null?void 0:R.id)===F&&(T.current=null))}catch{((z=T.current)==null?void 0:z.id)===F&&(T.current=null)}})},[x,l,h,g,a]),D=b.useCallback(M=>{const A=M.target.value;N(A,{fromUser:!0}),T.current&&(T.current.shouldClear=!1),k.current&&(k.current.style.height="auto",k.current.style.height=`${k.current.scrollHeight}px`)},[N]),B=b.useCallback(M=>{M.key==="Enter"&&!M.shiftKey?(M.preventDefault(),_()):M.key==="Escape"&&t&&(M.preventDefault(),c==null||c())},[_,t,c]),P=`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${t?"border-[hsl(var(--ring))] bg-[hsl(var(--card))] text-[hsl(var(--card-foreground))] dark:bg-[hsl(var(--card))] dark:text-[hsl(var(--card-foreground))]":""} ${p}`;return u.jsx("form",{onSubmit:M=>void _(M),className:`w-full ${f}`,children:u.jsxs("div",{className:"flex items-end gap-2",children:[u.jsx("div",{className:"flex-1",children:u.jsx(hc,{ref:k,value:x,onChange:D,onKeyDown:B,placeholder:t?"Edit your message...":n,className:P,disabled:o,maxLength:s,rows:1,spellCheck:!1,autoCorrect:"off"})}),u.jsx("div",{children:r?u.jsx(Je,{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(Je,{type:"submit",size:"icon",className:"shrink-0",title:t?"Save changes":"Send message",disabled:o||!x.trim()&&!h||w,children:u.jsx(le.Send,{size:16})})})]})})}const Ix=b.memo(mc);function pe(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 gc(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function gi(...e){return t=>{let n=!1;const r=e.map(o=>{const s=gc(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():gc(e[o],null)}}}}function $e(...e){return v.useCallback(gi(...e),e)}function Ax(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 Tn(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,...g}=f,m=((x=p==null?void 0:p[e])==null?void 0:x[l])||a,y=v.useMemo(()=>g,Object.values(g));return u.jsx(m.Provider,{value:y,children:h})};c.displayName=s+"Provider";function d(f,p){var m;const h=((m=p==null?void 0:p[e])==null?void 0:m[l])||a,g=v.useContext(h);if(g)return g;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,Nx(o,...t)]}function Nx(...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 kt=globalThis!=null&&globalThis.document?v.useLayoutEffect:()=>{},_x=v[" useInsertionEffect ".trim().toString()]||kt;function pr({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=jx({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=Mx(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 jx({defaultProp:e,onChange:t}){const[n,r]=v.useState(e),o=v.useRef(n),s=v.useRef(t);return _x(()=>{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 Mx(e){return typeof e=="function"}var Px=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Ne=Px.reduce((e,t)=>{const n=Vn.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 xc(e,t){e&&mo.flushSync(()=>e.dispatchEvent(t))}function xi(e){const t=e+"CollectionProvider",[n,r]=Tn(t),[o,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),i=m=>{const{scope:y,children:x}=m,w=b.useRef(null),S=b.useRef(new Map).current;return u.jsx(o,{scope:y,itemMap:S,collectionRef:w,children:x})};i.displayName=t;const a=e+"CollectionSlot",l=Vn.createSlot(a),c=b.forwardRef((m,y)=>{const{scope:x,children:w}=m,S=s(a,x),k=$e(y,S.collectionRef);return u.jsx(l,{ref:k,children:w})});c.displayName=a;const d=e+"CollectionItemSlot",f="data-radix-collection-item",p=Vn.createSlot(d),h=b.forwardRef((m,y)=>{const{scope:x,children:w,...S}=m,k=b.useRef(null),C=$e(y,k),T=s(d,x);return b.useEffect(()=>(T.itemMap.set(k,{ref:k,...S}),()=>void T.itemMap.delete(k))),u.jsx(p,{[f]:"",ref:C,children:w})});h.displayName=d;function g(m){const y=s(e+"CollectionConsumer",m);return b.useCallback(()=>{const w=y.collectionRef.current;if(!w)return[];const S=Array.from(w.querySelectorAll(`[${f}]`));return Array.from(y.itemMap.values()).sort((T,E)=>S.indexOf(T.ref.current)-S.indexOf(E.ref.current))},[y.collectionRef,y.itemMap])}return[{Provider:i,Slot:c,ItemSlot:h},g,r]}var Rx=v.createContext(void 0);function Ro(e){const t=v.useContext(Rx);return e||t||"ltr"}function Et(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 Ox(e,t=globalThis==null?void 0:globalThis.document){const n=Et(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 Dx="DismissableLayer",yi="dismissableLayer.update",Lx="dismissableLayer.pointerDownOutside",$x="dismissableLayer.focusOutside",yc,vc=v.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),Oo=v.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:a,...l}=e,c=v.useContext(vc),[d,f]=v.useState(null),p=(d==null?void 0:d.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,h]=v.useState({}),g=$e(t,E=>f(E)),m=Array.from(c.layers),[y]=[...c.layersWithOutsidePointerEventsDisabled].slice(-1),x=m.indexOf(y),w=d?m.indexOf(d):-1,S=c.layersWithOutsidePointerEventsDisabled.size>0,k=w>=x,C=zx(E=>{const N=E.target,_=[...c.branches].some(D=>D.contains(N));!k||_||(o==null||o(E),i==null||i(E),E.defaultPrevented||a==null||a())},p),T=Ux(E=>{const N=E.target;[...c.branches].some(D=>D.contains(N))||(s==null||s(E),i==null||i(E),E.defaultPrevented||a==null||a())},p);return Ox(E=>{w===c.layers.size-1&&(r==null||r(E),!E.defaultPrevented&&a&&(E.preventDefault(),a()))},p),v.useEffect(()=>{if(d)return n&&(c.layersWithOutsidePointerEventsDisabled.size===0&&(yc=p.body.style.pointerEvents,p.body.style.pointerEvents="none"),c.layersWithOutsidePointerEventsDisabled.add(d)),c.layers.add(d),wc(),()=>{n&&c.layersWithOutsidePointerEventsDisabled.size===1&&(p.body.style.pointerEvents=yc)}},[d,p,n,c]),v.useEffect(()=>()=>{d&&(c.layers.delete(d),c.layersWithOutsidePointerEventsDisabled.delete(d),wc())},[d,c]),v.useEffect(()=>{const E=()=>h({});return document.addEventListener(yi,E),()=>document.removeEventListener(yi,E)},[]),u.jsx(Ne.div,{...l,ref:g,style:{pointerEvents:S?k?"auto":"none":void 0,...e.style},onFocusCapture:pe(e.onFocusCapture,T.onFocusCapture),onBlurCapture:pe(e.onBlurCapture,T.onBlurCapture),onPointerDownCapture:pe(e.onPointerDownCapture,C.onPointerDownCapture)})});Oo.displayName=Dx;var Fx="DismissableLayerBranch",Bx=v.forwardRef((e,t)=>{const n=v.useContext(vc),r=v.useRef(null),o=$e(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})});Bx.displayName=Fx;function zx(e,t=globalThis==null?void 0:globalThis.document){const n=Et(e),r=v.useRef(!1),o=v.useRef(()=>{});return v.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let l=function(){bc(Lx,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 Ux(e,t=globalThis==null?void 0:globalThis.document){const n=Et(e),r=v.useRef(!1);return v.useEffect(()=>{const o=s=>{s.target&&!r.current&&bc($x,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 wc(){const e=new CustomEvent(yi);document.dispatchEvent(e)}function bc(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?xc(o,s):o.dispatchEvent(s)}var vi=0;function wi(){v.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??Sc()),document.body.insertAdjacentElement("beforeend",e[1]??Sc()),vi++,()=>{vi===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),vi--}},[])}function Sc(){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",Si="focusScope.autoFocusOnUnmount",Cc={bubbles:!1,cancelable:!0},Hx="FocusScope",Do=v.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:s,...i}=e,[a,l]=v.useState(null),c=Et(o),d=Et(s),f=v.useRef(null),p=$e(t,m=>l(m)),h=v.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;v.useEffect(()=>{if(r){let m=function(S){if(h.paused||!a)return;const k=S.target;a.contains(k)?f.current=k:jn(f.current,{select:!0})},y=function(S){if(h.paused||!a)return;const k=S.relatedTarget;k!==null&&(a.contains(k)||jn(f.current,{select:!0}))},x=function(S){if(document.activeElement===document.body)for(const C of S)C.removedNodes.length>0&&jn(a)};document.addEventListener("focusin",m),document.addEventListener("focusout",y);const w=new MutationObserver(x);return a&&w.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",m),document.removeEventListener("focusout",y),w.disconnect()}}},[r,a,h.paused]),v.useEffect(()=>{if(a){Ec.add(h);const m=document.activeElement;if(!a.contains(m)){const x=new CustomEvent(bi,Cc);a.addEventListener(bi,c),a.dispatchEvent(x),x.defaultPrevented||(Wx(Yx(Tc(a)),{select:!0}),document.activeElement===m&&jn(a))}return()=>{a.removeEventListener(bi,c),setTimeout(()=>{const x=new CustomEvent(Si,Cc);a.addEventListener(Si,d),a.dispatchEvent(x),x.defaultPrevented||jn(m??document.body,{select:!0}),a.removeEventListener(Si,d),Ec.remove(h)},0)}}},[a,c,d,h]);const g=v.useCallback(m=>{if(!n&&!r||h.paused)return;const y=m.key==="Tab"&&!m.altKey&&!m.ctrlKey&&!m.metaKey,x=document.activeElement;if(y&&x){const w=m.currentTarget,[S,k]=Vx(w);S&&k?!m.shiftKey&&x===k?(m.preventDefault(),n&&jn(S,{select:!0})):m.shiftKey&&x===S&&(m.preventDefault(),n&&jn(k,{select:!0})):x===w&&m.preventDefault()}},[n,r,h.paused]);return u.jsx(Ne.div,{tabIndex:-1,...i,ref:p,onKeyDown:g})});Do.displayName=Hx;function Wx(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(jn(r,{select:t}),document.activeElement!==n)return}function Vx(e){const t=Tc(e),n=kc(t,e),r=kc(t.reverse(),e);return[n,r]}function Tc(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 kc(e,t){for(const n of e)if(!Kx(n,{upTo:t}))return n}function Kx(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 qx(e){return e instanceof HTMLInputElement&&"select"in e}function jn(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&qx(e)&&t&&e.select()}}var Ec=Gx();function Gx(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=Ic(e,t),e.unshift(t)},remove(t){var n;e=Ic(e,t),(n=e[0])==null||n.resume()}}}function Ic(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function Yx(e){return e.filter(t=>t.tagName!=="A")}var Xx=v[" useId ".trim().toString()]||(()=>{}),Jx=0;function kn(e){const[t,n]=v.useState(Xx());return kt(()=>{n(r=>r??String(Jx++))},[e]),t?`radix-${t}`:""}const Zx=["top","right","bottom","left"],Mn=Math.min,Ut=Math.max,Lo=Math.round,$o=Math.floor,pn=e=>({x:e,y:e}),Qx={left:"right",right:"left",bottom:"top",top:"bottom"},ey={start:"end",end:"start"};function Ci(e,t,n){return Ut(e,Mn(t,n))}function En(e,t){return typeof e=="function"?e(t):e}function In(e){return e.split("-")[0]}function hr(e){return e.split("-")[1]}function Ti(e){return e==="x"?"y":"x"}function ki(e){return e==="y"?"height":"width"}const ty=new Set(["top","bottom"]);function hn(e){return ty.has(In(e))?"y":"x"}function Ei(e){return Ti(hn(e))}function ny(e,t,n){n===void 0&&(n=!1);const r=hr(e),o=Ei(e),s=ki(o);let i=o==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(i=Fo(i)),[i,Fo(i)]}function ry(e){const t=Fo(e);return[Ii(e),t,Ii(t)]}function Ii(e){return e.replace(/start|end/g,t=>ey[t])}const Ac=["left","right"],Nc=["right","left"],oy=["top","bottom"],sy=["bottom","top"];function iy(e,t,n){switch(e){case"top":case"bottom":return n?t?Nc:Ac:t?Ac:Nc;case"left":case"right":return t?oy:sy;default:return[]}}function ay(e,t,n,r){const o=hr(e);let s=iy(In(e),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(Ii)))),s}function Fo(e){return e.replace(/left|right|bottom|top/g,t=>Qx[t])}function ly(e){return{top:0,right:0,bottom:0,left:0,...e}}function _c(e){return typeof e!="number"?ly(e):{top:e,right:e,bottom:e,left:e}}function Bo(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 jc(e,t,n){let{reference:r,floating:o}=e;const s=hn(t),i=Ei(t),a=ki(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,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(hr(t)){case"start":h[i]-=p*(n&&c?-1:1);break;case"end":h[i]+=p*(n&&c?-1:1);break}return h}const cy=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}=jc(c,r,l),p=r,h={},g=0;for(let m=0;m<a.length;m++){const{name:y,fn:x}=a[m],{x:w,y:S,data:k,reset:C}=await x({x:d,y:f,initialPlacement:r,placement:p,strategy:o,middlewareData:h,rects:c,platform:i,elements:{reference:e,floating:t}});d=w??d,f=S??f,h={...h,[y]:{...h[y],...k}},C&&g<=50&&(g++,typeof C=="object"&&(C.placement&&(p=C.placement),C.rects&&(c=C.rects===!0?await i.getElementRects({reference:e,floating:t,strategy:o}):C.rects),{x:d,y:f}=jc(c,p,l)),m=-1)}return{x:d,y:f,placement:p,strategy:o,middlewareData:h}};async function $r(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}=En(t,e),g=_c(h),y=a[p?f==="floating"?"reference":"floating":f],x=Bo(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})),w=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=Bo(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:w,offsetParent:S,strategy:l}):w);return{top:(x.top-C.top+g.top)/k.y,bottom:(C.bottom-x.bottom+g.bottom)/k.y,left:(x.left-C.left+g.left)/k.x,right:(C.right-x.right+g.right)/k.x}}const uy=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}=En(e,t)||{};if(c==null)return{};const f=_c(d),p={x:n,y:r},h=Ei(o),g=ki(h),m=await i.getDimensions(c),y=h==="y",x=y?"top":"left",w=y?"bottom":"right",S=y?"clientHeight":"clientWidth",k=s.reference[g]+s.reference[h]-p[h]-s.floating[g],C=p[h]-s.reference[h],T=await(i.getOffsetParent==null?void 0:i.getOffsetParent(c));let E=T?T[S]:0;(!E||!await(i.isElement==null?void 0:i.isElement(T)))&&(E=a.floating[S]||s.floating[g]);const N=k/2-C/2,_=E/2-m[g]/2-1,D=Mn(f[x],_),B=Mn(f[w],_),G=D,V=E-m[g]-B,P=E/2-m[g]/2+N,M=Ci(G,P,V),A=!l.arrow&&hr(o)!=null&&P!==M&&s.reference[g]/2-(P<G?D:B)-m[g]/2<0,F=A?P<G?P-G:P-V:0;return{[h]:p[h]+F,data:{[h]:M,centerOffset:P-M-F,...A&&{alignmentOffset:F}},reset:A}}}),dy=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:g="none",flipAlignment:m=!0,...y}=En(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const x=In(o),w=hn(a),S=In(a)===a,k=await(l.isRTL==null?void 0:l.isRTL(c.floating)),C=p||(S||!m?[Fo(a)]:ry(a)),T=g!=="none";!p&&T&&C.push(...ay(a,m,g,k));const E=[a,...C],N=await $r(t,y),_=[];let D=((r=s.flip)==null?void 0:r.overflows)||[];if(d&&_.push(N[x]),f){const P=ny(o,i,k);_.push(N[P[0]],N[P[1]])}if(D=[...D,{placement:o,overflows:_}],!_.every(P=>P<=0)){var B,G;const P=(((B=s.flip)==null?void 0:B.index)||0)+1,M=E[P];if(M&&(!(f==="alignment"?w!==hn(M):!1)||D.every(L=>hn(L.placement)===w?L.overflows[0]>0:!0)))return{data:{index:P,overflows:D},reset:{placement:M}};let A=(G=D.filter(F=>F.overflows[0]<=0).sort((F,L)=>F.overflows[1]-L.overflows[1])[0])==null?void 0:G.placement;if(!A)switch(h){case"bestFit":{var V;const F=(V=D.filter(L=>{if(T){const R=hn(L.placement);return R===w||R==="y"}return!0}).map(L=>[L.placement,L.overflows.filter(R=>R>0).reduce((R,z)=>R+z,0)]).sort((L,R)=>L[1]-R[1])[0])==null?void 0:V[0];F&&(A=F);break}case"initialPlacement":A=a;break}if(o!==A)return{reset:{placement:A}}}return{}}}};function Mc(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function Pc(e){return Zx.some(t=>e[t]>=0)}const fy=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n}=t,{strategy:r="referenceHidden",...o}=En(e,t);switch(r){case"referenceHidden":{const s=await $r(t,{...o,elementContext:"reference"}),i=Mc(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:Pc(i)}}}case"escaped":{const s=await $r(t,{...o,altBoundary:!0}),i=Mc(s,n.floating);return{data:{escapedOffsets:i,escaped:Pc(i)}}}default:return{}}}}},Rc=new Set(["left","top"]);async function py(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=Rc.has(i)?-1:1,d=s&&l?-1:1,f=En(t,e);let{mainAxis:p,crossAxis:h,alignmentAxis:g}=typeof f=="number"?{mainAxis:f,crossAxis:0,alignmentAxis:null}:{mainAxis:f.mainAxis||0,crossAxis:f.crossAxis||0,alignmentAxis:f.alignmentAxis};return a&&typeof g=="number"&&(h=a==="end"?g*-1:g),l?{x:h*d,y:p*c}:{x:p*c,y:h*d}}const hy=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 py(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}}}}},my=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:w}=y;return{x,y:w}}},...l}=En(e,t),c={x:n,y:r},d=await $r(t,l),f=hn(In(o)),p=Ti(f);let h=c[p],g=c[f];if(s){const y=p==="y"?"top":"left",x=p==="y"?"bottom":"right",w=h+d[y],S=h-d[x];h=Ci(w,h,S)}if(i){const y=f==="y"?"top":"left",x=f==="y"?"bottom":"right",w=g+d[y],S=g-d[x];g=Ci(w,g,S)}const m=a.fn({...t,[p]:h,[f]:g});return{...m,data:{x:m.x-n,y:m.y-r,enabled:{[p]:s,[f]:i}}}}}},gy=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}=En(e,t),d={x:n,y:r},f=hn(o),p=Ti(f);let h=d[p],g=d[f];const m=En(a,t),y=typeof m=="number"?{mainAxis:m,crossAxis:0}:{mainAxis:0,crossAxis:0,...m};if(l){const S=p==="y"?"height":"width",k=s.reference[p]-s.floating[S]+y.mainAxis,C=s.reference[p]+s.reference[S]-y.mainAxis;h<k?h=k:h>C&&(h=C)}if(c){var x,w;const S=p==="y"?"width":"height",k=Rc.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:((w=i.offset)==null?void 0:w[f])||0)-(k?y.crossAxis:0);g<C?g=C:g>T&&(g=T)}return{[p]:h,[f]:g}}}},xy=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}=En(e,t),d=await $r(t,c),f=In(o),p=hr(o),h=hn(o)==="y",{width:g,height:m}=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 w=m-d.top-d.bottom,S=g-d.left-d.right,k=Mn(m-d[y],w),C=Mn(g-d[x],S),T=!t.middlewareData.shift;let E=k,N=C;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(N=S),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(E=w),T&&!p){const D=Ut(d.left,0),B=Ut(d.right,0),G=Ut(d.top,0),V=Ut(d.bottom,0);h?N=g-2*(D!==0||B!==0?D+B:Ut(d.left,d.right)):E=m-2*(G!==0||V!==0?G+V:Ut(d.top,d.bottom))}await l({...t,availableWidth:N,availableHeight:E});const _=await i.getDimensions(a.floating);return g!==_.width||m!==_.height?{reset:{rects:!0}}:{}}}};function zo(){return typeof window<"u"}function mr(e){return Oc(e)?(e.nodeName||"").toLowerCase():"#document"}function Ht(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function mn(e){var t;return(t=(Oc(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function Oc(e){return zo()?e instanceof Node||e instanceof Ht(e).Node:!1}function sn(e){return zo()?e instanceof Element||e instanceof Ht(e).Element:!1}function gn(e){return zo()?e instanceof HTMLElement||e instanceof Ht(e).HTMLElement:!1}function Dc(e){return!zo()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Ht(e).ShadowRoot}const yy=new Set(["inline","contents"]);function Fr(e){const{overflow:t,overflowX:n,overflowY:r,display:o}=an(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!yy.has(o)}const vy=new Set(["table","td","th"]);function wy(e){return vy.has(mr(e))}const by=[":popover-open",":modal"];function Uo(e){return by.some(t=>{try{return e.matches(t)}catch{return!1}})}const Sy=["transform","translate","scale","rotate","perspective"],Cy=["transform","translate","scale","rotate","perspective","filter"],Ty=["paint","layout","strict","content"];function Ai(e){const t=Ni(),n=sn(e)?an(e):e;return Sy.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)||Cy.some(r=>(n.willChange||"").includes(r))||Ty.some(r=>(n.contain||"").includes(r))}function ky(e){let t=Pn(e);for(;gn(t)&&!gr(t);){if(Ai(t))return t;if(Uo(t))return null;t=Pn(t)}return null}function Ni(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const Ey=new Set(["html","body","#document"]);function gr(e){return Ey.has(mr(e))}function an(e){return Ht(e).getComputedStyle(e)}function Ho(e){return sn(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Pn(e){if(mr(e)==="html")return e;const t=e.assignedSlot||e.parentNode||Dc(e)&&e.host||mn(e);return Dc(t)?t.host:t}function Lc(e){const t=Pn(e);return gr(t)?e.ownerDocument?e.ownerDocument.body:e.body:gn(t)&&Fr(t)?t:Lc(t)}function Br(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const o=Lc(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=Ht(o);if(s){const a=_i(i);return t.concat(i,i.visualViewport||[],Fr(o)?o:[],a&&n?Br(a):[])}return t.concat(o,Br(o,[],n))}function _i(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function $c(e){const t=an(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=Lo(n)!==s||Lo(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function ji(e){return sn(e)?e:e.contextElement}function xr(e){const t=ji(e);if(!gn(t))return pn(1);const n=t.getBoundingClientRect(),{width:r,height:o,$:s}=$c(t);let i=(s?Lo(n.width):n.width)/r,a=(s?Lo(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const Iy=pn(0);function Fc(e){const t=Ht(e);return!Ni()||!t.visualViewport?Iy:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function Ay(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==Ht(e)?!1:t}function Yn(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const o=e.getBoundingClientRect(),s=ji(e);let i=pn(1);t&&(r?sn(r)&&(i=xr(r)):i=xr(e));const a=Ay(s,n,r)?Fc(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 p=Ht(s),h=r&&sn(r)?Ht(r):r;let g=p,m=_i(g);for(;m&&r&&h!==g;){const y=xr(m),x=m.getBoundingClientRect(),w=an(m),S=x.left+(m.clientLeft+parseFloat(w.paddingLeft))*y.x,k=x.top+(m.clientTop+parseFloat(w.paddingTop))*y.y;l*=y.x,c*=y.y,d*=y.x,f*=y.y,l+=S,c+=k,g=Ht(m),m=_i(g)}}return Bo({width:d,height:f,x:l,y:c})}function Wo(e,t){const n=Ho(e).scrollLeft;return t?t.left+n:Yn(mn(e)).left+n}function Bc(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-Wo(e,n),o=n.top+t.scrollTop;return{x:r,y:o}}function Ny(e){let{elements:t,rect:n,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=mn(r),a=t?Uo(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"||Fr(i))&&(l=Ho(r)),gn(r))){const h=Yn(r);c=xr(r),d.x=h.x+r.clientLeft,d.y=h.y+r.clientTop}const p=i&&!f&&!s?Bc(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+p.x,y:n.y*c.y-l.scrollTop*c.y+d.y+p.y}}function _y(e){return Array.from(e.getClientRects())}function jy(e){const t=mn(e),n=Ho(e),r=e.ownerDocument.body,o=Ut(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=Ut(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let i=-n.scrollLeft+Wo(e);const a=-n.scrollTop;return an(r).direction==="rtl"&&(i+=Ut(t.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}const zc=25;function My(e,t){const n=Ht(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=Ni();(!d||d&&t==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}const c=Wo(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,g=Math.abs(r.clientWidth-f.clientWidth-h);g<=zc&&(s-=g)}else c<=zc&&(s+=c);return{width:s,height:i,x:a,y:l}}const Py=new Set(["absolute","fixed"]);function Ry(e,t){const n=Yn(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 Uc(e,t,n){let r;if(t==="viewport")r=My(e,n);else if(t==="document")r=jy(mn(e));else if(sn(t))r=Ry(t,n);else{const o=Fc(e);r={x:t.x-o.x,y:t.y-o.y,width:t.width,height:t.height}}return Bo(r)}function Hc(e,t){const n=Pn(e);return n===t||!sn(n)||gr(n)?!1:an(n).position==="fixed"||Hc(n,t)}function Oy(e,t){const n=t.get(e);if(n)return n;let r=Br(e,[],!1).filter(a=>sn(a)&&mr(a)!=="body"),o=null;const s=an(e).position==="fixed";let i=s?Pn(e):e;for(;sn(i)&&!gr(i);){const a=an(i),l=Ai(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&Py.has(o.position)||Fr(i)&&!l&&Hc(e,i))?r=r.filter(d=>d!==i):o=a,i=Pn(i)}return t.set(e,r),r}function Dy(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i=[...n==="clippingAncestors"?Uo(t)?[]:Oy(t,this._c):[].concat(n),r],a=i[0],l=i.reduce((c,d)=>{const f=Uc(t,d,o);return c.top=Ut(f.top,c.top),c.right=Mn(f.right,c.right),c.bottom=Mn(f.bottom,c.bottom),c.left=Ut(f.left,c.left),c},Uc(t,a,o));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function Ly(e){const{width:t,height:n}=$c(e);return{width:t,height:n}}function $y(e,t,n){const r=gn(t),o=mn(t),s=n==="fixed",i=Yn(e,!0,s,t);let a={scrollLeft:0,scrollTop:0};const l=pn(0);function c(){l.x=Wo(o)}if(r||!r&&!s)if((mr(t)!=="body"||Fr(o))&&(a=Ho(t)),r){const h=Yn(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?Bc(o,a):pn(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 Mi(e){return an(e).position==="static"}function Wc(e,t){if(!gn(e)||an(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return mn(e)===n&&(n=n.ownerDocument.body),n}function Vc(e,t){const n=Ht(e);if(Uo(e))return n;if(!gn(e)){let o=Pn(e);for(;o&&!gr(o);){if(sn(o)&&!Mi(o))return o;o=Pn(o)}return n}let r=Wc(e,t);for(;r&&wy(r)&&Mi(r);)r=Wc(r,t);return r&&gr(r)&&Mi(r)&&!Ai(r)?n:r||ky(e)||n}const Fy=async function(e){const t=this.getOffsetParent||Vc,n=this.getDimensions,r=await n(e.floating);return{reference:$y(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function By(e){return an(e).direction==="rtl"}const zy={convertOffsetParentRelativeRectToViewportRelativeRect:Ny,getDocumentElement:mn,getClippingRect:Dy,getOffsetParent:Vc,getElementRects:Fy,getClientRects:_y,getDimensions:Ly,getScale:xr,isElement:sn,isRTL:By};function Kc(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function Uy(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:p,height:h}=c;if(a||t(),!p||!h)return;const g=$o(f),m=$o(o.clientWidth-(d+p)),y=$o(o.clientHeight-(f+h)),x=$o(d),S={rootMargin:-g+"px "+-m+"px "+-y+"px "+-x+"px",threshold:Ut(0,Mn(1,l))||1};let k=!0;function C(T){const E=T[0].intersectionRatio;if(E!==l){if(!k)return i();E?i(!1,E):r=setTimeout(()=>{i(!1,1e-7)},1e3)}E===1&&!Kc(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 Hy(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=ji(e),d=o||s?[...c?Br(c):[],...Br(t)]:[];d.forEach(x=>{o&&x.addEventListener("scroll",n,{passive:!0}),s&&x.addEventListener("resize",n)});const f=c&&a?Uy(c,n):null;let p=-1,h=null;i&&(h=new ResizeObserver(x=>{let[w]=x;w&&w.target===c&&h&&(h.unobserve(t),cancelAnimationFrame(p),p=requestAnimationFrame(()=>{var S;(S=h)==null||S.observe(t)})),n()}),c&&!l&&h.observe(c),h.observe(t));let g,m=l?Yn(e):null;l&&y();function y(){const x=Yn(e);m&&!Kc(m,x)&&n(),m=x,g=requestAnimationFrame(y)}return n(),()=>{var x;d.forEach(w=>{o&&w.removeEventListener("scroll",n),s&&w.removeEventListener("resize",n)}),f==null||f(),(x=h)==null||x.disconnect(),h=null,l&&cancelAnimationFrame(g)}}const Wy=hy,Vy=my,Ky=dy,qy=xy,Gy=fy,qc=uy,Yy=gy,Xy=(e,t,n)=>{const r=new Map,o={platform:zy,...n},s={...o.platform,_c:r};return cy(e,t,{...o,platform:s})};var Jy=typeof document<"u",Zy=function(){},Vo=Jy?b.useLayoutEffect:Zy;function Ko(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(!Ko(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)&&!Ko(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function Gc(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function Yc(e,t){const n=Gc(e);return Math.round(t*n)/n}function Pi(e){const t=v.useRef(e);return Vo(()=>{t.current=e}),t}function Qy(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);Ko(p,r)||h(r);const[g,m]=v.useState(null),[y,x]=v.useState(null),w=v.useCallback(L=>{L!==T.current&&(T.current=L,m(L))},[]),S=v.useCallback(L=>{L!==E.current&&(E.current=L,x(L))},[]),k=s||g,C=i||y,T=v.useRef(null),E=v.useRef(null),N=v.useRef(d),_=l!=null,D=Pi(l),B=Pi(o),G=Pi(c),V=v.useCallback(()=>{if(!T.current||!E.current)return;const L={placement:t,strategy:n,middleware:p};B.current&&(L.platform=B.current),Xy(T.current,E.current,L).then(R=>{const z={...R,isPositioned:G.current!==!1};P.current&&!Ko(N.current,z)&&(N.current=z,mo.flushSync(()=>{f(z)}))})},[p,t,n,B,G]);Vo(()=>{c===!1&&N.current.isPositioned&&(N.current.isPositioned=!1,f(L=>({...L,isPositioned:!1})))},[c]);const P=v.useRef(!1);Vo(()=>(P.current=!0,()=>{P.current=!1}),[]),Vo(()=>{if(k&&(T.current=k),C&&(E.current=C),k&&C){if(D.current)return D.current(k,C,V);V()}},[k,C,V,D,_]);const M=v.useMemo(()=>({reference:T,floating:E,setReference:w,setFloating:S}),[w,S]),A=v.useMemo(()=>({reference:k,floating:C}),[k,C]),F=v.useMemo(()=>{const L={position:n,left:0,top:0};if(!A.floating)return L;const R=Yc(A.floating,d.x),z=Yc(A.floating,d.y);return a?{...L,transform:"translate("+R+"px, "+z+"px)",...Gc(A.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:R,top:z}},[n,a,A.floating,d.x,d.y]);return v.useMemo(()=>({...d,update:V,refs:M,elements:A,floatingStyles:F}),[d,V,M,A,F])}const ev=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?qc({element:r.current,padding:o}).fn(n):{}:r?qc({element:r,padding:o}).fn(n):{}}}},tv=(e,t)=>({...Wy(e),options:[e,t]}),nv=(e,t)=>({...Vy(e),options:[e,t]}),rv=(e,t)=>({...Yy(e),options:[e,t]}),ov=(e,t)=>({...Ky(e),options:[e,t]}),sv=(e,t)=>({...qy(e),options:[e,t]}),iv=(e,t)=>({...Gy(e),options:[e,t]}),av=(e,t)=>({...ev(e),options:[e,t]});var lv="Arrow",Xc=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"})})});Xc.displayName=lv;var cv=Xc;function Jc(e){const[t,n]=v.useState(void 0);return kt(()=>{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",[Zc,qo]=Tn(Ri),[uv,Qc]=Zc(Ri),eu=e=>{const{__scopePopper:t,children:n}=e,[r,o]=v.useState(null);return u.jsx(uv,{scope:t,anchor:r,onAnchorChange:o,children:n})};eu.displayName=Ri;var tu="PopperAnchor",nu=v.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...o}=e,s=Qc(tu,n),i=v.useRef(null),a=$e(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})});nu.displayName=tu;var Oi="PopperContent",[dv,fv]=Zc(Oi),ru=v.forwardRef((e,t)=>{var Z,$,Y,Q,de,oe;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:g,...m}=e,y=Qc(Oi,n),[x,w]=v.useState(null),S=$e(t,_e=>w(_e)),[k,C]=v.useState(null),T=Jc(k),E=(T==null?void 0:T.width)??0,N=(T==null?void 0:T.height)??0,_=r+(s!=="center"?"-"+s:""),D=typeof d=="number"?d:{top:0,right:0,bottom:0,left:0,...d},B=Array.isArray(c)?c:[c],G=B.length>0,V={padding:D,boundary:B.filter(hv),altBoundary:G},{refs:P,floatingStyles:M,placement:A,isPositioned:F,middlewareData:L}=Qy({strategy:"fixed",placement:_,whileElementsMounted:(..._e)=>Hy(..._e,{animationFrame:h==="always"}),elements:{reference:y.anchor},middleware:[tv({mainAxis:o+N,alignmentAxis:i}),l&&nv({mainAxis:!0,crossAxis:!1,limiter:f==="partial"?rv():void 0,...V}),l&&ov({...V}),sv({...V,apply:({elements:_e,rects:ze,availableWidth:se,availableHeight:me})=>{const{width:Pe,height:Ve}=ze.reference,ut=_e.floating.style;ut.setProperty("--radix-popper-available-width",`${se}px`),ut.setProperty("--radix-popper-available-height",`${me}px`),ut.setProperty("--radix-popper-anchor-width",`${Pe}px`),ut.setProperty("--radix-popper-anchor-height",`${Ve}px`)}}),k&&av({element:k,padding:a}),mv({arrowWidth:E,arrowHeight:N}),p&&iv({strategy:"referenceHidden",...V})]}),[R,z]=iu(A),X=Et(g);kt(()=>{F&&(X==null||X())},[F,X]);const ne=(Z=L.arrow)==null?void 0:Z.x,ye=($=L.arrow)==null?void 0:$.y,Te=((Y=L.arrow)==null?void 0:Y.centerOffset)!==0,[q,U]=v.useState();return kt(()=>{x&&U(window.getComputedStyle(x).zIndex)},[x]),u.jsx("div",{ref:P.setFloating,"data-radix-popper-content-wrapper":"",style:{...M,transform:F?M.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:q,"--radix-popper-transform-origin":[(Q=L.transformOrigin)==null?void 0:Q.x,(de=L.transformOrigin)==null?void 0:de.y].join(" "),...((oe=L.hide)==null?void 0:oe.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:u.jsx(dv,{scope:n,placedSide:R,onArrowChange:C,arrowX:ne,arrowY:ye,shouldHideArrow:Te,children:u.jsx(Ne.div,{"data-side":R,"data-align":z,...m,ref:S,style:{...m.style,animation:F?void 0:"none"}})})})});ru.displayName=Oi;var ou="PopperArrow",pv={top:"bottom",right:"left",bottom:"top",left:"right"},su=v.forwardRef(function(t,n){const{__scopePopper:r,...o}=t,s=fv(ou,r),i=pv[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(cv,{...o,ref:n,style:{...o.style,display:"block"}})})});su.displayName=ou;function hv(e){return e!==null}var mv=e=>({name:"transformOrigin",options:e,fn(t){var y,x,w;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]=iu(n),f={start:"0%",center:"50%",end:"100%"}[d],p=(((x=o.arrow)==null?void 0:x.x)??0)+a/2,h=(((w=o.arrow)==null?void 0:w.y)??0)+l/2;let g="",m="";return c==="bottom"?(g=i?f:`${p}px`,m=`${-l}px`):c==="top"?(g=i?f:`${p}px`,m=`${r.floating.height+l}px`):c==="right"?(g=`${-l}px`,m=i?f:`${h}px`):c==="left"&&(g=`${r.floating.width+l}px`,m=i?f:`${h}px`),{data:{x:g,y:m}}}});function iu(e){const[t,n="center"]=e.split("-");return[t,n]}var au=eu,lu=nu,cu=ru,uu=su,gv="Portal",Go=v.forwardRef((e,t)=>{var a;const{container:n,...r}=e,[o,s]=v.useState(!1);kt(()=>s(!0),[]);const i=n||o&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?Ys.createPortal(u.jsx(Ne.div,{...r,ref:t}),i):null});Go.displayName=gv;function xv(e,t){return v.useReducer((n,r)=>t[n][r]??n,e)}var Xt=e=>{const{present:t,children:n}=e,r=yv(t),o=typeof n=="function"?n({present:r.isPresent}):v.Children.only(n),s=$e(r.ref,vv(o));return typeof n=="function"||r.isPresent?v.cloneElement(o,{ref:s}):null};Xt.displayName="Presence";function yv(e){const[t,n]=v.useState(),r=v.useRef(null),o=v.useRef(e),s=v.useRef("none"),i=e?"mounted":"unmounted",[a,l]=xv(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return v.useEffect(()=>{const c=Yo(r.current);s.current=a==="mounted"?c:"none"},[a]),kt(()=>{const c=r.current,d=o.current;if(d!==e){const p=s.current,h=Yo(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]),kt(()=>{if(t){let c;const d=t.ownerDocument.defaultView??window,f=h=>{const m=Yo(r.current).includes(CSS.escape(h.animationName));if(h.target===t&&m&&(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=Yo(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 Yo(e){return(e==null?void 0:e.animationName)||"none"}function vv(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 Di="rovingFocusGroup.onEntryFocus",wv={bubbles:!1,cancelable:!0},zr="RovingFocusGroup",[Li,du,bv]=xi(zr),[Sv,fu]=Tn(zr,[bv]),[Cv,Tv]=Sv(zr),pu=v.forwardRef((e,t)=>u.jsx(Li.Provider,{scope:e.__scopeRovingFocusGroup,children:u.jsx(Li.Slot,{scope:e.__scopeRovingFocusGroup,children:u.jsx(kv,{...e,ref:t})})}));pu.displayName=zr;var kv=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=$e(t,p),g=Ro(s),[m,y]=pr({prop:i,defaultProp:a??null,onChange:l,caller:zr}),[x,w]=v.useState(!1),S=Et(c),k=du(n),C=v.useRef(!1),[T,E]=v.useState(0);return v.useEffect(()=>{const N=p.current;if(N)return N.addEventListener(Di,S),()=>N.removeEventListener(Di,S)},[S]),u.jsx(Cv,{scope:n,orientation:r,dir:g,loop:o,currentTabStopId:m,onItemFocus:v.useCallback(N=>y(N),[y]),onItemShiftTab:v.useCallback(()=>w(!0),[]),onFocusableItemAdd:v.useCallback(()=>E(N=>N+1),[]),onFocusableItemRemove:v.useCallback(()=>E(N=>N-1),[]),children:u.jsx(Ne.div,{tabIndex:x||T===0?-1:0,"data-orientation":r,...f,ref:h,style:{outline:"none",...e.style},onMouseDown:pe(e.onMouseDown,()=>{C.current=!0}),onFocus:pe(e.onFocus,N=>{const _=!C.current;if(N.target===N.currentTarget&&_&&!x){const D=new CustomEvent(Di,wv);if(N.currentTarget.dispatchEvent(D),!D.defaultPrevented){const B=k().filter(A=>A.focusable),G=B.find(A=>A.active),V=B.find(A=>A.id===m),M=[G,V,...B].filter(Boolean).map(A=>A.ref.current);gu(M,d)}}C.current=!1}),onBlur:pe(e.onBlur,()=>w(!1))})})}),hu="RovingFocusGroupItem",mu=v.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:o=!1,tabStopId:s,children:i,...a}=e,l=kn(),c=s||l,d=Tv(hu,n),f=d.currentTabStopId===c,p=du(n),{onFocusableItemAdd:h,onFocusableItemRemove:g,currentTabStopId:m}=d;return v.useEffect(()=>{if(r)return h(),()=>g()},[r,h,g]),u.jsx(Li.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:pe(e.onMouseDown,y=>{r?d.onItemFocus(c):y.preventDefault()}),onFocus:pe(e.onFocus,()=>d.onItemFocus(c)),onKeyDown:pe(e.onKeyDown,y=>{if(y.key==="Tab"&&y.shiftKey){d.onItemShiftTab();return}if(y.target!==y.currentTarget)return;const x=Av(y,d.orientation,d.dir);if(x!==void 0){if(y.metaKey||y.ctrlKey||y.altKey||y.shiftKey)return;y.preventDefault();let S=p().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?Nv(S,k+1):S.slice(k+1)}setTimeout(()=>gu(S))}}),children:typeof i=="function"?i({isCurrentTabStop:f,hasTabStop:m!=null}):i})})});mu.displayName=hu;var Ev={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function Iv(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function Av(e,t,n){const r=Iv(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return Ev[r]}function gu(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function Nv(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var _v=pu,jv=mu,Mv=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},yr=new WeakMap,Xo=new WeakMap,Jo={},$i=0,xu=function(e){return e&&(e.host||xu(e.parentNode))},Pv=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=xu(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})},Rv=function(e,t,n,r){var o=Pv(t,Array.isArray(e)?e:[e]);Jo[n]||(Jo[n]=new WeakMap);var s=Jo[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),g=h!==null&&h!=="false",m=(yr.get(p)||0)+1,y=(s.get(p)||0)+1;yr.set(p,m),s.set(p,y),i.push(p),m===1&&g&&Xo.set(p,!0),y===1&&p.setAttribute(n,"true"),g||p.setAttribute(r,"true")}catch(x){console.error("aria-hidden: cannot operate on ",p,x)}})};return d(t),a.clear(),$i++,function(){i.forEach(function(f){var p=yr.get(f)-1,h=s.get(f)-1;yr.set(f,p),s.set(f,h),p||(Xo.has(f)||f.removeAttribute(r),Xo.delete(f)),h||f.removeAttribute(n)}),$i--,$i||(yr=new WeakMap,yr=new WeakMap,Xo=new WeakMap,Jo={})}},Fi=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),o=Mv(e);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live], script"))),Rv(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 yu(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 Ov(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 Zo="right-scroll-bar-position",Qo="width-before-scroll-bar",Dv="with-scroll-bars-hidden",Lv="--removed-body-scroll-bar-size";function Bi(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function $v(e,t){var n=b.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 Fv=typeof window<"u"?v.useLayoutEffect:v.useEffect,vu=new WeakMap;function Bv(e,t){var n=$v(null,function(r){return e.forEach(function(o){return Bi(o,r)})});return Fv(function(){var r=vu.get(n);if(r){var o=new Set(r),s=new Set(e),i=n.current;o.forEach(function(a){s.has(a)||Bi(a,null)}),s.forEach(function(a){o.has(a)||Bi(a,i)})}vu.set(n,e)},[e]),n}function zv(e){return e}function Uv(e,t){t===void 0&&(t=zv);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 Hv(e){e===void 0&&(e={});var t=Uv(null);return t.options=xn({async:!0,ssr:!1},e),t}var wu=function(e){var t=e.sideCar,n=yu(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))};wu.isSideCarExport=!0;function Wv(e,t){return e.useMedium(t),wu}var bu=Hv(),zi=function(){},es=v.forwardRef(function(e,t){var n=v.useRef(null),r=v.useState({onScrollCapture:zi,onWheelCapture:zi,onTouchMoveCapture:zi}),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,g=e.noIsolation,m=e.inert,y=e.allowPinchZoom,x=e.as,w=x===void 0?"div":x,S=e.gapMode,k=yu(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),C=p,T=Bv([n,t]),E=xn(xn({},k),o);return v.createElement(v.Fragment,null,d&&v.createElement(C,{sideCar:bu,removeScrollBar:c,shards:f,noRelative:h,noIsolation:g,inert:m,setCallbacks:s,allowPinchZoom:!!y,lockRef:n,gapMode:S}),i?v.cloneElement(v.Children.only(a),xn(xn({},E),{ref:T})):v.createElement(w,xn({},E,{className:l,ref:T}),a))});es.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},es.classNames={fullWidth:Qo,zeroRight:Zo};var Vv=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function Kv(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=Vv();return t&&e.setAttribute("nonce",t),e}function qv(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function Gv(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var Yv=function(){var e=0,t=null;return{add:function(n){e==0&&(t=Kv())&&(qv(t,n),Gv(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},Xv=function(){var e=Yv();return function(t,n){v.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},Su=function(){var e=Xv(),t=function(n){var r=n.styles,o=n.dynamic;return e(r,o),null};return t},Jv={left:0,top:0,right:0,gap:0},Ui=function(e){return parseInt(e||"",10)||0},Zv=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[Ui(n),Ui(r),Ui(o)]},Qv=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return Jv;var t=Zv(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])}},ew=Su(),vr="data-scroll-locked",tw=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(Dv,` {
|
|
40
40
|
overflow: hidden `).concat(r,`;
|
|
41
41
|
padding-right: `).concat(a,"px ").concat(r,`;
|
|
42
42
|
}
|
|
@@ -70,12 +70,12 @@ React keys must be passed directly to JSX without using spread:
|
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
body[`).concat(vr,`] {
|
|
73
|
-
`).concat(
|
|
73
|
+
`).concat(Lv,": ").concat(a,`px;
|
|
74
74
|
}
|
|
75
|
-
`)},
|
|
75
|
+
`)},Cu=function(){var e=parseInt(document.body.getAttribute(vr)||"0",10);return isFinite(e)?e:0},nw=function(){v.useEffect(function(){return document.body.setAttribute(vr,(Cu()+1).toString()),function(){var e=Cu()-1;e<=0?document.body.removeAttribute(vr):document.body.setAttribute(vr,e.toString())}},[])},rw=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,o=r===void 0?"margin":r;nw();var s=v.useMemo(function(){return Qv(o)},[o]);return v.createElement(ew,{styles:tw(s,!t,o,n?"":"!important")})},Hi=!1;if(typeof window<"u")try{var ts=Object.defineProperty({},"passive",{get:function(){return Hi=!0,!0}});window.addEventListener("test",ts,ts),window.removeEventListener("test",ts,ts)}catch{Hi=!1}var wr=Hi?{passive:!1}:!1,ow=function(e){return e.tagName==="TEXTAREA"},Tu=function(e,t){if(!(e instanceof Element))return!1;var n=window.getComputedStyle(e);return n[t]!=="hidden"&&!(n.overflowY===n.overflowX&&!ow(e)&&n[t]==="visible")},sw=function(e){return Tu(e,"overflowY")},iw=function(e){return Tu(e,"overflowX")},ku=function(e,t){var n=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var o=Eu(e,r);if(o){var s=Iu(e,r),i=s[1],a=s[2];if(i>a)return!0}r=r.parentNode}while(r&&r!==n.body);return!1},aw=function(e){var t=e.scrollTop,n=e.scrollHeight,r=e.clientHeight;return[t,n,r]},lw=function(e){var t=e.scrollLeft,n=e.scrollWidth,r=e.clientWidth;return[t,n,r]},Eu=function(e,t){return e==="v"?sw(t):iw(t)},Iu=function(e,t){return e==="v"?aw(t):lw(t)},cw=function(e,t){return e==="h"&&t==="rtl"?-1:1},uw=function(e,t,n,r,o){var s=cw(e,window.getComputedStyle(t).direction),i=s*r,a=n.target,l=t.contains(a),c=!1,d=i>0,f=0,p=0;do{if(!a)break;var h=Iu(e,a),g=h[0],m=h[1],y=h[2],x=m-y-s*g;(g||x)&&Eu(e,a)&&(f+=x,p+=g);var w=a.parentNode;a=w&&w.nodeType===Node.DOCUMENT_FRAGMENT_NODE?w.host:w}while(!l&&a!==document.body||l&&(t.contains(a)||t===a));return(d&&Math.abs(f)<1||!d&&Math.abs(p)<1)&&(c=!0),c},ns=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},Au=function(e){return[e.deltaX,e.deltaY]},Nu=function(e){return e&&"current"in e?e.current:e},dw=function(e,t){return e[0]===t[0]&&e[1]===t[1]},fw=function(e){return`
|
|
76
76
|
.block-interactivity-`.concat(e,` {pointer-events: none;}
|
|
77
77
|
.allow-interactivity-`).concat(e,` {pointer-events: all;}
|
|
78
|
-
`)},ab=0,wr=[];function lb(e){var t=v.useRef([]),n=v.useRef([0,0]),r=v.useRef(),o=v.useState(ab++)[0],s=v.useState(yu)[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 m=Nv([e.lockRef.current],(e.shards||[]).map(ku),!0).filter(Boolean);return m.forEach(function(y){return y.classList.add("allow-interactivity-".concat(o))}),function(){document.body.classList.remove("block-interactivity-".concat(o)),m.forEach(function(y){return y.classList.remove("allow-interactivity-".concat(o))})}}},[e.inert,e.lockRef.current,e.shards]);var a=v.useCallback(function(m,y){if("touches"in m&&m.touches.length===2||m.type==="wheel"&&m.ctrlKey)return!i.current.allowPinchZoom;var x=ns(m),b=n.current,S="deltaX"in m?m.deltaX:b[0]-x[0],k="deltaY"in m?m.deltaY:b[1]-x[1],C,T=m.target,E=Math.abs(S)>Math.abs(k)?"h":"v";if("touches"in m&&E==="h"&&T.type==="range")return!1;var N=wu(E,T);if(!N)return!0;if(N?C=E:(C=E==="v"?"h":"v",N=wu(E,T)),!N)return!1;if(!r.current&&"changedTouches"in m&&(S||k)&&(r.current=C),!C)return!0;var _=r.current||C;return ob(_,y,m,_==="h"?S:k)},[]),l=v.useCallback(function(m){var y=m;if(!(!wr.length||wr[wr.length-1]!==s)){var x="deltaY"in y?Tu(y):ns(y),b=t.current.filter(function(C){return C.name===y.type&&(C.target===y.target||y.target===C.shadowParent)&&sb(C.delta,x)})[0];if(b&&b.should){y.cancelable&&y.preventDefault();return}if(!b){var S=(i.current.shards||[]).map(ku).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(m,y,x,b){var S={name:m,delta:y,target:x,should:b,shadowParent:cb(x)};t.current.push(S),setTimeout(function(){t.current=t.current.filter(function(k){return k!==S})},1)},[]),d=v.useCallback(function(m){n.current=ns(m),r.current=void 0},[]),f=v.useCallback(function(m){c(m.type,Tu(m),m.target,a(m,e.lockRef.current))},[]),p=v.useCallback(function(m){c(m.type,ns(m),m.target,a(m,e.lockRef.current))},[]);v.useEffect(function(){return wr.push(s),e.setCallbacks({onScrollCapture:f,onWheelCapture:f,onTouchMoveCapture:p}),document.addEventListener("wheel",l,br),document.addEventListener("touchmove",l,br),document.addEventListener("touchstart",d,br),function(){wr=wr.filter(function(m){return m!==s}),document.removeEventListener("wheel",l,br),document.removeEventListener("touchmove",l,br),document.removeEventListener("touchstart",d,br)}},[]);var h=e.removeScrollBar,g=e.inert;return v.createElement(v.Fragment,null,g?v.createElement(s,{styles:ib(o)}):null,h?v.createElement(Jv,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function cb(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const ub=$v(xu,lb);var rs=v.forwardRef(function(e,t){return v.createElement(es,xn({},e,{ref:t,sideCar:ub}))});rs.classNames=es.classNames;var Hi=["Enter"," "],db=["ArrowDown","PageUp","Home"],Eu=["ArrowUp","PageDown","End"],fb=[...db,...Eu],pb={ltr:[...Hi,"ArrowRight"],rtl:[...Hi,"ArrowLeft"]},hb={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Ur="Menu",[Hr,mb,gb]=gi(Ur),[Xn,Iu]=Tn(Ur,[gb,qo,lu]),os=qo(),Au=lu(),[xb,Jn]=Xn(Ur),[yb,Wr]=Xn(Ur),Nu=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=os(t),[l,c]=v.useState(null),d=v.useRef(!1),f=Et(s),p=Po(o);return v.useEffect(()=>{const h=()=>{d.current=!0,document.addEventListener("pointerdown",g,{capture:!0,once:!0}),document.addEventListener("pointermove",g,{capture:!0,once:!0})},g=()=>d.current=!1;return document.addEventListener("keydown",h,{capture:!0}),()=>{document.removeEventListener("keydown",h,{capture:!0}),document.removeEventListener("pointerdown",g,{capture:!0}),document.removeEventListener("pointermove",g,{capture:!0})}},[]),u.jsx(ru,{...a,children:u.jsx(xb,{scope:t,open:n,onOpenChange:f,content:l,onContentChange:c,children:u.jsx(yb,{scope:t,onClose:v.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:d,dir:p,modal:i,children:r})})})};Nu.displayName=Ur;var vb="MenuAnchor",Wi=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=os(n);return u.jsx(ou,{...o,...r,ref:t})});Wi.displayName=vb;var Vi="MenuPortal",[bb,_u]=Xn(Vi,{forceMount:void 0}),ju=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:o}=e,s=Jn(Vi,t);return u.jsx(bb,{scope:t,forceMount:n,children:u.jsx(Xt,{present:n||s.open,children:u.jsx(Go,{asChild:!0,container:o,children:r})})})};ju.displayName=Vi;var Jt="MenuContent",[wb,Ki]=Xn(Jt),Mu=v.forwardRef((e,t)=>{const n=_u(Jt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Jn(Jt,e.__scopeMenu),i=Wr(Jt,e.__scopeMenu);return u.jsx(Hr.Provider,{scope:e.__scopeMenu,children:u.jsx(Xt,{present:r||s.open,children:u.jsx(Hr.Slot,{scope:e.__scopeMenu,children:i.modal?u.jsx(Sb,{...o,ref:t}):u.jsx(Cb,{...o,ref:t})})})})}),Sb=v.forwardRef((e,t)=>{const n=Jn(Jt,e.__scopeMenu),r=v.useRef(null),o=$e(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:pe(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),Cb=v.forwardRef((e,t)=>{const n=Jn(Jt,e.__scopeMenu);return u.jsx(qi,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),Tb=Vn.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:g,...m}=e,y=Jn(Jt,n),x=Wr(Jt,n),b=os(n),S=Au(n),k=mb(n),[C,T]=v.useState(null),E=v.useRef(null),N=$e(t,E,y.onContentChange),_=v.useRef(0),D=v.useRef(""),B=v.useRef(0),G=v.useRef(null),V=v.useRef("right"),R=v.useRef(0),M=g?rs:v.Fragment,A=g?{as:Tb,allowPinchZoom:!0}:void 0,F=P=>{var J,$;const z=D.current+P,X=k().filter(Y=>!Y.disabled),ne=document.activeElement,ye=(J=X.find(Y=>Y.ref.current===ne))==null?void 0:J.textValue,Te=X.map(Y=>Y.textValue),q=Db(Te,z,ye),U=($=X.find(Y=>Y.textValue===q))==null?void 0:$.ref.current;(function Y(Z){D.current=Z,window.clearTimeout(_.current),Z!==""&&(_.current=window.setTimeout(()=>Y(""),1e3))})(z),U&&setTimeout(()=>U.focus())};v.useEffect(()=>()=>window.clearTimeout(_.current),[]),vi();const L=v.useCallback(P=>{var X,ne;return V.current===((X=G.current)==null?void 0:X.side)&&$b(P,(ne=G.current)==null?void 0:ne.area)},[]);return u.jsx(wb,{scope:n,searchRef:D,onItemEnter:v.useCallback(P=>{L(P)&&P.preventDefault()},[L]),onItemLeave:v.useCallback(P=>{var z;L(P)||((z=E.current)==null||z.focus(),T(null))},[L]),onTriggerLeave:v.useCallback(P=>{L(P)&&P.preventDefault()},[L]),pointerGraceTimerRef:B,onPointerGraceIntentChange:v.useCallback(P=>{G.current=P},[]),children:u.jsx(M,{...A,children:u.jsx(Do,{asChild:!0,trapped:o,onMountAutoFocus:pe(s,P=>{var z;P.preventDefault(),(z=E.current)==null||z.focus({preventScroll:!0})}),onUnmountAutoFocus:i,children:u.jsx(Oo,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:c,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:p,onDismiss:h,children:u.jsx(Tv,{asChild:!0,...S,dir:x.dir,orientation:"vertical",loop:r,currentTabStopId:C,onCurrentTabStopIdChange:T,onEntryFocus:pe(l,P=>{x.isUsingKeyboardRef.current||P.preventDefault()}),preventScrollOnEntryFocus:!0,children:u.jsx(su,{role:"menu","aria-orientation":"vertical","data-state":Yu(y.open),"data-radix-menu-content":"",dir:x.dir,...b,...m,ref:N,style:{outline:"none",...m.style},onKeyDown:pe(m.onKeyDown,P=>{const X=P.target.closest("[data-radix-menu-content]")===P.currentTarget,ne=P.ctrlKey||P.altKey||P.metaKey,ye=P.key.length===1;X&&(P.key==="Tab"&&P.preventDefault(),!ne&&ye&&F(P.key));const Te=E.current;if(P.target!==Te||!fb.includes(P.key))return;P.preventDefault();const U=k().filter(J=>!J.disabled).map(J=>J.ref.current);Eu.includes(P.key)&&U.reverse(),Pb(U)}),onBlur:pe(e.onBlur,P=>{P.currentTarget.contains(P.target)||(window.clearTimeout(_.current),D.current="")}),onPointerMove:pe(e.onPointerMove,Kr(P=>{const z=P.target,X=R.current!==P.clientX;if(P.currentTarget.contains(z)&&X){const ne=P.clientX>R.current?"right":"left";V.current=ne,R.current=P.clientX}}))})})})})})})});Mu.displayName=Jt;var kb="MenuGroup",Gi=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(Ne.div,{role:"group",...r,ref:t})});Gi.displayName=kb;var Eb="MenuLabel",Ru=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(Ne.div,{...r,ref:t})});Ru.displayName=Eb;var ss="MenuItem",Pu="menu.itemSelect",is=v.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...o}=e,s=v.useRef(null),i=Wr(ss,e.__scopeMenu),a=Ki(ss,e.__scopeMenu),l=$e(t,s),c=v.useRef(!1),d=()=>{const f=s.current;if(!n&&f){const p=new CustomEvent(Pu,{bubbles:!0,cancelable:!0});f.addEventListener(Pu,h=>r==null?void 0:r(h),{once:!0}),pc(f,p),p.defaultPrevented?c.current=!1:i.onClose()}};return u.jsx(Ou,{...o,ref:l,disabled:n,onClick:pe(e.onClick,d),onPointerDown:f=>{var p;(p=e.onPointerDown)==null||p.call(e,f),c.current=!0},onPointerUp:pe(e.onPointerUp,f=>{var p;c.current||(p=f.currentTarget)==null||p.click()}),onKeyDown:pe(e.onKeyDown,f=>{const p=a.searchRef.current!=="";n||p&&f.key===" "||Hi.includes(f.key)&&(f.currentTarget.click(),f.preventDefault())})})});is.displayName=ss;var Ou=v.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:o,...s}=e,i=Ki(ss,n),a=Au(n),l=v.useRef(null),c=$e(t,l),[d,f]=v.useState(!1),[p,h]=v.useState("");return v.useEffect(()=>{const g=l.current;g&&h((g.textContent??"").trim())},[s.children]),u.jsx(Hr.ItemSlot,{scope:n,disabled:r,textValue:o??p,children:u.jsx(kv,{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:pe(e.onPointerMove,Kr(g=>{r?i.onItemLeave(g):(i.onItemEnter(g),g.defaultPrevented||g.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:pe(e.onPointerLeave,Kr(g=>i.onItemLeave(g))),onFocus:pe(e.onFocus,()=>f(!0)),onBlur:pe(e.onBlur,()=>f(!1))})})})}),Ib="MenuCheckboxItem",Du=v.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...o}=e;return u.jsx(zu,{scope:e.__scopeMenu,checked:n,children:u.jsx(is,{role:"menuitemcheckbox","aria-checked":as(n)?"mixed":n,...o,ref:t,"data-state":Xi(n),onSelect:pe(o.onSelect,()=>r==null?void 0:r(as(n)?!0:!n),{checkForDefaultPrevented:!1})})})});Du.displayName=Ib;var Lu="MenuRadioGroup",[Ab,Nb]=Xn(Lu,{value:void 0,onValueChange:()=>{}}),$u=v.forwardRef((e,t)=>{const{value:n,onValueChange:r,...o}=e,s=Et(r);return u.jsx(Ab,{scope:e.__scopeMenu,value:n,onValueChange:s,children:u.jsx(Gi,{...o,ref:t})})});$u.displayName=Lu;var Fu="MenuRadioItem",Bu=v.forwardRef((e,t)=>{const{value:n,...r}=e,o=Nb(Fu,e.__scopeMenu),s=n===o.value;return u.jsx(zu,{scope:e.__scopeMenu,checked:s,children:u.jsx(is,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":Xi(s),onSelect:pe(r.onSelect,()=>{var i;return(i=o.onValueChange)==null?void 0:i.call(o,n)},{checkForDefaultPrevented:!1})})})});Bu.displayName=Fu;var Yi="MenuItemIndicator",[zu,_b]=Xn(Yi,{checked:!1}),Uu=v.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...o}=e,s=_b(Yi,n);return u.jsx(Xt,{present:r||as(s.checked)||s.checked===!0,children:u.jsx(Ne.span,{...o,ref:t,"data-state":Xi(s.checked)})})});Uu.displayName=Yi;var jb="MenuSeparator",Hu=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(Ne.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});Hu.displayName=jb;var Mb="MenuArrow",Wu=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=os(n);return u.jsx(iu,{...o,...r,ref:t})});Wu.displayName=Mb;var Rb="MenuSub",[nk,Vu]=Xn(Rb),Vr="MenuSubTrigger",Ku=v.forwardRef((e,t)=>{const n=Jn(Vr,e.__scopeMenu),r=Wr(Vr,e.__scopeMenu),o=Vu(Vr,e.__scopeMenu),s=Ki(Vr,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(Ou,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":o.contentId,"data-state":Yu(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:pe(e.onPointerMove,Kr(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:pe(e.onPointerLeave,Kr(f=>{var h,g;d();const p=(h=n.content)==null?void 0:h.getBoundingClientRect();if(p){const m=(g=n.content)==null?void 0:g.dataset.side,y=m==="right",x=y?-5:5,b=p[y?"left":"right"],S=p[y?"right":"left"];s.onPointerGraceIntentChange({area:[{x:f.clientX+x,y:f.clientY},{x:b,y:p.top},{x:S,y:p.top},{x:S,y:p.bottom},{x:b,y:p.bottom}],side:m}),window.clearTimeout(a.current),a.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(f),f.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:pe(e.onKeyDown,f=>{var h;const p=s.searchRef.current!=="";e.disabled||p&&f.key===" "||pb[r.dir].includes(f.key)&&(n.onOpenChange(!0),(h=n.content)==null||h.focus(),f.preventDefault())})})})});Ku.displayName=Vr;var qu="MenuSubContent",Gu=v.forwardRef((e,t)=>{const n=_u(Jt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Jn(Jt,e.__scopeMenu),i=Wr(Jt,e.__scopeMenu),a=Vu(qu,e.__scopeMenu),l=v.useRef(null),c=$e(t,l);return u.jsx(Hr.Provider,{scope:e.__scopeMenu,children:u.jsx(Xt,{present:r||s.open,children:u.jsx(Hr.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:pe(e.onFocusOutside,d=>{d.target!==a.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:pe(e.onEscapeKeyDown,d=>{i.onClose(),d.preventDefault()}),onKeyDown:pe(e.onKeyDown,d=>{var h;const f=d.currentTarget.contains(d.target),p=hb[i.dir].includes(d.key);f&&p&&(s.onOpenChange(!1),(h=a.trigger)==null||h.focus(),d.preventDefault())})})})})})});Gu.displayName=qu;function Yu(e){return e?"open":"closed"}function as(e){return e==="indeterminate"}function Xi(e){return as(e)?"indeterminate":e?"checked":"unchecked"}function Pb(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function Ob(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function Db(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=Ob(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 Lb(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 $b(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return Lb(n,t)}function Kr(e){return t=>t.pointerType==="mouse"?e(t):void 0}var Fb=Nu,Bb=Wi,zb=ju,Ub=Mu,Hb=Gi,Wb=Ru,Vb=is,Kb=Du,qb=$u,Gb=Bu,Yb=Uu,Xb=Hu,Jb=Wu,Zb=Ku,Qb=Gu,ls="DropdownMenu",[ew,rk]=Tn(ls,[Iu]),Dt=Iu(),[tw,Xu]=ew(ls),Ju=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:o,defaultOpen:s,onOpenChange:i,modal:a=!0}=e,l=Dt(t),c=v.useRef(null),[d,f]=pr({prop:o,defaultProp:s??!1,onChange:i,caller:ls});return u.jsx(tw,{scope:t,triggerId:kn(),triggerRef:c,contentId:kn(),open:d,onOpenChange:f,onOpenToggle:v.useCallback(()=>f(p=>!p),[f]),modal:a,children:u.jsx(Fb,{...l,open:d,onOpenChange:f,dir:r,modal:a,children:n})})};Ju.displayName=ls;var Zu="DropdownMenuTrigger",Qu=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...o}=e,s=Xu(Zu,n),i=Dt(n);return u.jsx(Bb,{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:pe(e.onPointerDown,a=>{!r&&a.button===0&&a.ctrlKey===!1&&(s.onOpenToggle(),s.open||a.preventDefault())}),onKeyDown:pe(e.onKeyDown,a=>{r||(["Enter"," "].includes(a.key)&&s.onOpenToggle(),a.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(a.key)&&a.preventDefault())})})})});Qu.displayName=Zu;var nw="DropdownMenuPortal",ed=e=>{const{__scopeDropdownMenu:t,...n}=e,r=Dt(t);return u.jsx(zb,{...r,...n})};ed.displayName=nw;var td="DropdownMenuContent",nd=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Xu(td,n),s=Dt(n),i=v.useRef(!1);return u.jsx(Ub,{id:o.contentId,"aria-labelledby":o.triggerId,...s,...r,ref:t,onCloseAutoFocus:pe(e.onCloseAutoFocus,a=>{var l;i.current||(l=o.triggerRef.current)==null||l.focus(),i.current=!1,a.preventDefault()}),onInteractOutside:pe(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)"}})});nd.displayName=td;var rw="DropdownMenuGroup",ow=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Dt(n);return u.jsx(Hb,{...o,...r,ref:t})});ow.displayName=rw;var sw="DropdownMenuLabel",rd=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Dt(n);return u.jsx(Wb,{...o,...r,ref:t})});rd.displayName=sw;var iw="DropdownMenuItem",od=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Dt(n);return u.jsx(Vb,{...o,...r,ref:t})});od.displayName=iw;var aw="DropdownMenuCheckboxItem",sd=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Dt(n);return u.jsx(Kb,{...o,...r,ref:t})});sd.displayName=aw;var lw="DropdownMenuRadioGroup",cw=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Dt(n);return u.jsx(qb,{...o,...r,ref:t})});cw.displayName=lw;var uw="DropdownMenuRadioItem",id=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Dt(n);return u.jsx(Gb,{...o,...r,ref:t})});id.displayName=uw;var dw="DropdownMenuItemIndicator",ad=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Dt(n);return u.jsx(Yb,{...o,...r,ref:t})});ad.displayName=dw;var fw="DropdownMenuSeparator",ld=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Dt(n);return u.jsx(Xb,{...o,...r,ref:t})});ld.displayName=fw;var pw="DropdownMenuArrow",hw=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Dt(n);return u.jsx(Jb,{...o,...r,ref:t})});hw.displayName=pw;var mw="DropdownMenuSubTrigger",cd=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Dt(n);return u.jsx(Zb,{...o,...r,ref:t})});cd.displayName=mw;var gw="DropdownMenuSubContent",ud=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Dt(n);return u.jsx(Qb,{...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)"}})});ud.displayName=gw;var xw=Ju,yw=Qu,vw=ed,dd=nd,fd=rd,pd=od,hd=sd,md=id,gd=ad,xd=ld,yd=cd,vd=ud;const bw=xw,ww=yw,Sw=v.forwardRef(({className:e,inset:t,children:n,...r},o)=>u.jsxs(yd,{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"})]}));Sw.displayName=yd.displayName;const Cw=v.forwardRef(({className:e,...t},n)=>u.jsx(vd,{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}));Cw.displayName=vd.displayName;const bd=v.forwardRef(({className:e,sideOffset:t=4,...n},r)=>u.jsx(vw,{children:u.jsx(dd,{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})}));bd.displayName=dd.displayName;const Ji=v.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(pd,{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=pd.displayName;const Tw=v.forwardRef(({className:e,children:t,checked:n,...r},o)=>u.jsxs(hd,{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(gd,{children:u.jsx(le.Check,{className:"h-4 w-4"})})}),t]}));Tw.displayName=hd.displayName;const kw=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(md,{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(gd,{children:u.jsx(le.Circle,{className:"h-2 w-2 fill-current"})})}),t]}));kw.displayName=md.displayName;const Ew=v.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(fd,{ref:r,className:te("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));Ew.displayName=fd.displayName;const Iw=v.forwardRef(({className:e,...t},n)=>u.jsx(xd,{ref:n,className:te("-mx-1 my-1 h-px bg-muted",e),...t}));Iw.displayName=xd.displayName;function Aw(e){const t=new Map;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)}}return t}function Nw(e){const t=new Map,n=Aw(e),r=Array.from(n.entries());for(const[o,s]of r)if(s.length===1){const i=s[0];i.checkpointId&&t.set(i.checkpointId,{attemptIndex:0,attemptCount:1,isLatestAttempt:!0,baseUserMessageId:o})}else{const i=[...s].sort((a,l)=>Date.parse(l.createdAt??"0")-Date.parse(a.createdAt??"0"));i.forEach((a,l)=>{a.checkpointId&&t.set(a.checkpointId,{attemptIndex:l,attemptCount:i.length,isLatestAttempt:l===i.length-1,baseUserMessageId:o})})}return t}function _w(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 cs(e,t){if(!e||typeof e!="object")return null;const n=e[t];return typeof n=="number"?n:null}function jw(e,t){if(!e||typeof e!="object")return null;const n=e[t];return typeof n=="string"&&n.trim()?n:null}function Mw(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 Rw(e){const t=Array.isArray(e)?e.map(r=>{const o=Mw(r.next);return o?{...r,metadata:{...r.metadata??{},next:o}}:r}):[];return t.some(r=>cs(r.metadata,"step")!==null)&&t.sort((r,o)=>{const s=cs(r.metadata,"step"),i=cs(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 Pw(e){const t=w.useMemo(()=>Rw(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=cs(f.metadata,"step"),g=jw(f.metadata,"source"),m={id:p,step:h,source:g,createdAt:f.createdAt??null,namespace:f.checkpointNs??null,parentId:f.parentId??null};if(i.set(p,m),h!==null&&g){const y=`${h}:${g}`,x=a.get(y)??[];x.push(m),a.set(y,x)}}const c=Nw(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})}const d=_w(l);return{checkpointMetaById:i,checkpointIndexByKey:a,attemptMetaById:l,userMessageIdToAttempts:d}},[t]);return{checkpointMetaById:n,checkpointIndexByKey:r,attemptMetaById:o,userMessageIdToAttempts:s}}const us=1e4;function Ow(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
|
+
`)},pw=0,br=[];function hw(e){var t=v.useRef([]),n=v.useRef([0,0]),r=v.useRef(),o=v.useState(pw++)[0],s=v.useState(Su)[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 m=Ov([e.lockRef.current],(e.shards||[]).map(Nu),!0).filter(Boolean);return m.forEach(function(y){return y.classList.add("allow-interactivity-".concat(o))}),function(){document.body.classList.remove("block-interactivity-".concat(o)),m.forEach(function(y){return y.classList.remove("allow-interactivity-".concat(o))})}}},[e.inert,e.lockRef.current,e.shards]);var a=v.useCallback(function(m,y){if("touches"in m&&m.touches.length===2||m.type==="wheel"&&m.ctrlKey)return!i.current.allowPinchZoom;var x=ns(m),w=n.current,S="deltaX"in m?m.deltaX:w[0]-x[0],k="deltaY"in m?m.deltaY:w[1]-x[1],C,T=m.target,E=Math.abs(S)>Math.abs(k)?"h":"v";if("touches"in m&&E==="h"&&T.type==="range")return!1;var N=ku(E,T);if(!N)return!0;if(N?C=E:(C=E==="v"?"h":"v",N=ku(E,T)),!N)return!1;if(!r.current&&"changedTouches"in m&&(S||k)&&(r.current=C),!C)return!0;var _=r.current||C;return uw(_,y,m,_==="h"?S:k)},[]),l=v.useCallback(function(m){var y=m;if(!(!br.length||br[br.length-1]!==s)){var x="deltaY"in y?Au(y):ns(y),w=t.current.filter(function(C){return C.name===y.type&&(C.target===y.target||y.target===C.shadowParent)&&dw(C.delta,x)})[0];if(w&&w.should){y.cancelable&&y.preventDefault();return}if(!w){var S=(i.current.shards||[]).map(Nu).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(m,y,x,w){var S={name:m,delta:y,target:x,should:w,shadowParent:mw(x)};t.current.push(S),setTimeout(function(){t.current=t.current.filter(function(k){return k!==S})},1)},[]),d=v.useCallback(function(m){n.current=ns(m),r.current=void 0},[]),f=v.useCallback(function(m){c(m.type,Au(m),m.target,a(m,e.lockRef.current))},[]),p=v.useCallback(function(m){c(m.type,ns(m),m.target,a(m,e.lockRef.current))},[]);v.useEffect(function(){return br.push(s),e.setCallbacks({onScrollCapture:f,onWheelCapture:f,onTouchMoveCapture:p}),document.addEventListener("wheel",l,wr),document.addEventListener("touchmove",l,wr),document.addEventListener("touchstart",d,wr),function(){br=br.filter(function(m){return m!==s}),document.removeEventListener("wheel",l,wr),document.removeEventListener("touchmove",l,wr),document.removeEventListener("touchstart",d,wr)}},[]);var h=e.removeScrollBar,g=e.inert;return v.createElement(v.Fragment,null,g?v.createElement(s,{styles:fw(o)}):null,h?v.createElement(rw,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function mw(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const gw=Wv(bu,hw);var rs=v.forwardRef(function(e,t){return v.createElement(es,xn({},e,{ref:t,sideCar:gw}))});rs.classNames=es.classNames;var Wi=["Enter"," "],xw=["ArrowDown","PageUp","Home"],_u=["ArrowUp","PageDown","End"],yw=[...xw,..._u],vw={ltr:[...Wi,"ArrowRight"],rtl:[...Wi,"ArrowLeft"]},ww={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Ur="Menu",[Hr,bw,Sw]=xi(Ur),[Xn,ju]=Tn(Ur,[Sw,qo,fu]),os=qo(),Mu=fu(),[Cw,Jn]=Xn(Ur),[Tw,Wr]=Xn(Ur),Pu=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=os(t),[l,c]=v.useState(null),d=v.useRef(!1),f=Et(s),p=Ro(o);return v.useEffect(()=>{const h=()=>{d.current=!0,document.addEventListener("pointerdown",g,{capture:!0,once:!0}),document.addEventListener("pointermove",g,{capture:!0,once:!0})},g=()=>d.current=!1;return document.addEventListener("keydown",h,{capture:!0}),()=>{document.removeEventListener("keydown",h,{capture:!0}),document.removeEventListener("pointerdown",g,{capture:!0}),document.removeEventListener("pointermove",g,{capture:!0})}},[]),u.jsx(au,{...a,children:u.jsx(Cw,{scope:t,open:n,onOpenChange:f,content:l,onContentChange:c,children:u.jsx(Tw,{scope:t,onClose:v.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:d,dir:p,modal:i,children:r})})})};Pu.displayName=Ur;var kw="MenuAnchor",Vi=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=os(n);return u.jsx(lu,{...o,...r,ref:t})});Vi.displayName=kw;var Ki="MenuPortal",[Ew,Ru]=Xn(Ki,{forceMount:void 0}),Ou=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:o}=e,s=Jn(Ki,t);return u.jsx(Ew,{scope:t,forceMount:n,children:u.jsx(Xt,{present:n||s.open,children:u.jsx(Go,{asChild:!0,container:o,children:r})})})};Ou.displayName=Ki;var Jt="MenuContent",[Iw,qi]=Xn(Jt),Du=v.forwardRef((e,t)=>{const n=Ru(Jt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Jn(Jt,e.__scopeMenu),i=Wr(Jt,e.__scopeMenu);return u.jsx(Hr.Provider,{scope:e.__scopeMenu,children:u.jsx(Xt,{present:r||s.open,children:u.jsx(Hr.Slot,{scope:e.__scopeMenu,children:i.modal?u.jsx(Aw,{...o,ref:t}):u.jsx(Nw,{...o,ref:t})})})})}),Aw=v.forwardRef((e,t)=>{const n=Jn(Jt,e.__scopeMenu),r=v.useRef(null),o=$e(t,r);return v.useEffect(()=>{const s=r.current;if(s)return Fi(s)},[]),u.jsx(Gi,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:pe(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),Nw=v.forwardRef((e,t)=>{const n=Jn(Jt,e.__scopeMenu);return u.jsx(Gi,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),_w=Vn.createSlot("MenuContent.ScrollLock"),Gi=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:g,...m}=e,y=Jn(Jt,n),x=Wr(Jt,n),w=os(n),S=Mu(n),k=bw(n),[C,T]=v.useState(null),E=v.useRef(null),N=$e(t,E,y.onContentChange),_=v.useRef(0),D=v.useRef(""),B=v.useRef(0),G=v.useRef(null),V=v.useRef("right"),P=v.useRef(0),M=g?rs:v.Fragment,A=g?{as:_w,allowPinchZoom:!0}:void 0,F=R=>{var Z,$;const z=D.current+R,X=k().filter(Y=>!Y.disabled),ne=document.activeElement,ye=(Z=X.find(Y=>Y.ref.current===ne))==null?void 0:Z.textValue,Te=X.map(Y=>Y.textValue),q=Uw(Te,z,ye),U=($=X.find(Y=>Y.textValue===q))==null?void 0:$.ref.current;(function Y(Q){D.current=Q,window.clearTimeout(_.current),Q!==""&&(_.current=window.setTimeout(()=>Y(""),1e3))})(z),U&&setTimeout(()=>U.focus())};v.useEffect(()=>()=>window.clearTimeout(_.current),[]),wi();const L=v.useCallback(R=>{var X,ne;return V.current===((X=G.current)==null?void 0:X.side)&&Ww(R,(ne=G.current)==null?void 0:ne.area)},[]);return u.jsx(Iw,{scope:n,searchRef:D,onItemEnter:v.useCallback(R=>{L(R)&&R.preventDefault()},[L]),onItemLeave:v.useCallback(R=>{var z;L(R)||((z=E.current)==null||z.focus(),T(null))},[L]),onTriggerLeave:v.useCallback(R=>{L(R)&&R.preventDefault()},[L]),pointerGraceTimerRef:B,onPointerGraceIntentChange:v.useCallback(R=>{G.current=R},[]),children:u.jsx(M,{...A,children:u.jsx(Do,{asChild:!0,trapped:o,onMountAutoFocus:pe(s,R=>{var z;R.preventDefault(),(z=E.current)==null||z.focus({preventScroll:!0})}),onUnmountAutoFocus:i,children:u.jsx(Oo,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:c,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:p,onDismiss:h,children:u.jsx(_v,{asChild:!0,...S,dir:x.dir,orientation:"vertical",loop:r,currentTabStopId:C,onCurrentTabStopIdChange:T,onEntryFocus:pe(l,R=>{x.isUsingKeyboardRef.current||R.preventDefault()}),preventScrollOnEntryFocus:!0,children:u.jsx(cu,{role:"menu","aria-orientation":"vertical","data-state":Qu(y.open),"data-radix-menu-content":"",dir:x.dir,...w,...m,ref:N,style:{outline:"none",...m.style},onKeyDown:pe(m.onKeyDown,R=>{const X=R.target.closest("[data-radix-menu-content]")===R.currentTarget,ne=R.ctrlKey||R.altKey||R.metaKey,ye=R.key.length===1;X&&(R.key==="Tab"&&R.preventDefault(),!ne&&ye&&F(R.key));const Te=E.current;if(R.target!==Te||!yw.includes(R.key))return;R.preventDefault();const U=k().filter(Z=>!Z.disabled).map(Z=>Z.ref.current);_u.includes(R.key)&&U.reverse(),Bw(U)}),onBlur:pe(e.onBlur,R=>{R.currentTarget.contains(R.target)||(window.clearTimeout(_.current),D.current="")}),onPointerMove:pe(e.onPointerMove,Kr(R=>{const z=R.target,X=P.current!==R.clientX;if(R.currentTarget.contains(z)&&X){const ne=R.clientX>P.current?"right":"left";V.current=ne,P.current=R.clientX}}))})})})})})})});Du.displayName=Jt;var jw="MenuGroup",Yi=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(Ne.div,{role:"group",...r,ref:t})});Yi.displayName=jw;var Mw="MenuLabel",Lu=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(Ne.div,{...r,ref:t})});Lu.displayName=Mw;var ss="MenuItem",$u="menu.itemSelect",is=v.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...o}=e,s=v.useRef(null),i=Wr(ss,e.__scopeMenu),a=qi(ss,e.__scopeMenu),l=$e(t,s),c=v.useRef(!1),d=()=>{const f=s.current;if(!n&&f){const p=new CustomEvent($u,{bubbles:!0,cancelable:!0});f.addEventListener($u,h=>r==null?void 0:r(h),{once:!0}),xc(f,p),p.defaultPrevented?c.current=!1:i.onClose()}};return u.jsx(Fu,{...o,ref:l,disabled:n,onClick:pe(e.onClick,d),onPointerDown:f=>{var p;(p=e.onPointerDown)==null||p.call(e,f),c.current=!0},onPointerUp:pe(e.onPointerUp,f=>{var p;c.current||(p=f.currentTarget)==null||p.click()}),onKeyDown:pe(e.onKeyDown,f=>{const p=a.searchRef.current!=="";n||p&&f.key===" "||Wi.includes(f.key)&&(f.currentTarget.click(),f.preventDefault())})})});is.displayName=ss;var Fu=v.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:o,...s}=e,i=qi(ss,n),a=Mu(n),l=v.useRef(null),c=$e(t,l),[d,f]=v.useState(!1),[p,h]=v.useState("");return v.useEffect(()=>{const g=l.current;g&&h((g.textContent??"").trim())},[s.children]),u.jsx(Hr.ItemSlot,{scope:n,disabled:r,textValue:o??p,children:u.jsx(jv,{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:pe(e.onPointerMove,Kr(g=>{r?i.onItemLeave(g):(i.onItemEnter(g),g.defaultPrevented||g.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:pe(e.onPointerLeave,Kr(g=>i.onItemLeave(g))),onFocus:pe(e.onFocus,()=>f(!0)),onBlur:pe(e.onBlur,()=>f(!1))})})})}),Pw="MenuCheckboxItem",Bu=v.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...o}=e;return u.jsx(Vu,{scope:e.__scopeMenu,checked:n,children:u.jsx(is,{role:"menuitemcheckbox","aria-checked":as(n)?"mixed":n,...o,ref:t,"data-state":Ji(n),onSelect:pe(o.onSelect,()=>r==null?void 0:r(as(n)?!0:!n),{checkForDefaultPrevented:!1})})})});Bu.displayName=Pw;var zu="MenuRadioGroup",[Rw,Ow]=Xn(zu,{value:void 0,onValueChange:()=>{}}),Uu=v.forwardRef((e,t)=>{const{value:n,onValueChange:r,...o}=e,s=Et(r);return u.jsx(Rw,{scope:e.__scopeMenu,value:n,onValueChange:s,children:u.jsx(Yi,{...o,ref:t})})});Uu.displayName=zu;var Hu="MenuRadioItem",Wu=v.forwardRef((e,t)=>{const{value:n,...r}=e,o=Ow(Hu,e.__scopeMenu),s=n===o.value;return u.jsx(Vu,{scope:e.__scopeMenu,checked:s,children:u.jsx(is,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":Ji(s),onSelect:pe(r.onSelect,()=>{var i;return(i=o.onValueChange)==null?void 0:i.call(o,n)},{checkForDefaultPrevented:!1})})})});Wu.displayName=Hu;var Xi="MenuItemIndicator",[Vu,Dw]=Xn(Xi,{checked:!1}),Ku=v.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...o}=e,s=Dw(Xi,n);return u.jsx(Xt,{present:r||as(s.checked)||s.checked===!0,children:u.jsx(Ne.span,{...o,ref:t,"data-state":Ji(s.checked)})})});Ku.displayName=Xi;var Lw="MenuSeparator",qu=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(Ne.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});qu.displayName=Lw;var $w="MenuArrow",Gu=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=os(n);return u.jsx(uu,{...o,...r,ref:t})});Gu.displayName=$w;var Fw="MenuSub",[lk,Yu]=Xn(Fw),Vr="MenuSubTrigger",Xu=v.forwardRef((e,t)=>{const n=Jn(Vr,e.__scopeMenu),r=Wr(Vr,e.__scopeMenu),o=Yu(Vr,e.__scopeMenu),s=qi(Vr,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(Vi,{asChild:!0,...c,children:u.jsx(Fu,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":o.contentId,"data-state":Qu(n.open),...e,ref:gi(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:pe(e.onPointerMove,Kr(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:pe(e.onPointerLeave,Kr(f=>{var h,g;d();const p=(h=n.content)==null?void 0:h.getBoundingClientRect();if(p){const m=(g=n.content)==null?void 0:g.dataset.side,y=m==="right",x=y?-5:5,w=p[y?"left":"right"],S=p[y?"right":"left"];s.onPointerGraceIntentChange({area:[{x:f.clientX+x,y:f.clientY},{x:w,y:p.top},{x:S,y:p.top},{x:S,y:p.bottom},{x:w,y:p.bottom}],side:m}),window.clearTimeout(a.current),a.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(f),f.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:pe(e.onKeyDown,f=>{var h;const p=s.searchRef.current!=="";e.disabled||p&&f.key===" "||vw[r.dir].includes(f.key)&&(n.onOpenChange(!0),(h=n.content)==null||h.focus(),f.preventDefault())})})})});Xu.displayName=Vr;var Ju="MenuSubContent",Zu=v.forwardRef((e,t)=>{const n=Ru(Jt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Jn(Jt,e.__scopeMenu),i=Wr(Jt,e.__scopeMenu),a=Yu(Ju,e.__scopeMenu),l=v.useRef(null),c=$e(t,l);return u.jsx(Hr.Provider,{scope:e.__scopeMenu,children:u.jsx(Xt,{present:r||s.open,children:u.jsx(Hr.Slot,{scope:e.__scopeMenu,children:u.jsx(Gi,{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:pe(e.onFocusOutside,d=>{d.target!==a.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:pe(e.onEscapeKeyDown,d=>{i.onClose(),d.preventDefault()}),onKeyDown:pe(e.onKeyDown,d=>{var h;const f=d.currentTarget.contains(d.target),p=ww[i.dir].includes(d.key);f&&p&&(s.onOpenChange(!1),(h=a.trigger)==null||h.focus(),d.preventDefault())})})})})})});Zu.displayName=Ju;function Qu(e){return e?"open":"closed"}function as(e){return e==="indeterminate"}function Ji(e){return as(e)?"indeterminate":e?"checked":"unchecked"}function Bw(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function zw(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function Uw(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=zw(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 Hw(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 Ww(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return Hw(n,t)}function Kr(e){return t=>t.pointerType==="mouse"?e(t):void 0}var Vw=Pu,Kw=Vi,qw=Ou,Gw=Du,Yw=Yi,Xw=Lu,Jw=is,Zw=Bu,Qw=Uu,eb=Wu,tb=Ku,nb=qu,rb=Gu,ob=Xu,sb=Zu,ls="DropdownMenu",[ib,ck]=Tn(ls,[ju]),Dt=ju(),[ab,ed]=ib(ls),td=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:o,defaultOpen:s,onOpenChange:i,modal:a=!0}=e,l=Dt(t),c=v.useRef(null),[d,f]=pr({prop:o,defaultProp:s??!1,onChange:i,caller:ls});return u.jsx(ab,{scope:t,triggerId:kn(),triggerRef:c,contentId:kn(),open:d,onOpenChange:f,onOpenToggle:v.useCallback(()=>f(p=>!p),[f]),modal:a,children:u.jsx(Vw,{...l,open:d,onOpenChange:f,dir:r,modal:a,children:n})})};td.displayName=ls;var nd="DropdownMenuTrigger",rd=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...o}=e,s=ed(nd,n),i=Dt(n);return u.jsx(Kw,{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:gi(t,s.triggerRef),onPointerDown:pe(e.onPointerDown,a=>{!r&&a.button===0&&a.ctrlKey===!1&&(s.onOpenToggle(),s.open||a.preventDefault())}),onKeyDown:pe(e.onKeyDown,a=>{r||(["Enter"," "].includes(a.key)&&s.onOpenToggle(),a.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(a.key)&&a.preventDefault())})})})});rd.displayName=nd;var lb="DropdownMenuPortal",od=e=>{const{__scopeDropdownMenu:t,...n}=e,r=Dt(t);return u.jsx(qw,{...r,...n})};od.displayName=lb;var sd="DropdownMenuContent",id=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=ed(sd,n),s=Dt(n),i=v.useRef(!1);return u.jsx(Gw,{id:o.contentId,"aria-labelledby":o.triggerId,...s,...r,ref:t,onCloseAutoFocus:pe(e.onCloseAutoFocus,a=>{var l;i.current||(l=o.triggerRef.current)==null||l.focus(),i.current=!1,a.preventDefault()}),onInteractOutside:pe(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)"}})});id.displayName=sd;var cb="DropdownMenuGroup",ub=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Dt(n);return u.jsx(Yw,{...o,...r,ref:t})});ub.displayName=cb;var db="DropdownMenuLabel",ad=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Dt(n);return u.jsx(Xw,{...o,...r,ref:t})});ad.displayName=db;var fb="DropdownMenuItem",ld=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Dt(n);return u.jsx(Jw,{...o,...r,ref:t})});ld.displayName=fb;var pb="DropdownMenuCheckboxItem",cd=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Dt(n);return u.jsx(Zw,{...o,...r,ref:t})});cd.displayName=pb;var hb="DropdownMenuRadioGroup",mb=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Dt(n);return u.jsx(Qw,{...o,...r,ref:t})});mb.displayName=hb;var gb="DropdownMenuRadioItem",ud=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Dt(n);return u.jsx(eb,{...o,...r,ref:t})});ud.displayName=gb;var xb="DropdownMenuItemIndicator",dd=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Dt(n);return u.jsx(tb,{...o,...r,ref:t})});dd.displayName=xb;var yb="DropdownMenuSeparator",fd=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Dt(n);return u.jsx(nb,{...o,...r,ref:t})});fd.displayName=yb;var vb="DropdownMenuArrow",wb=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Dt(n);return u.jsx(rb,{...o,...r,ref:t})});wb.displayName=vb;var bb="DropdownMenuSubTrigger",pd=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Dt(n);return u.jsx(ob,{...o,...r,ref:t})});pd.displayName=bb;var Sb="DropdownMenuSubContent",hd=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Dt(n);return u.jsx(sb,{...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)"}})});hd.displayName=Sb;var Cb=td,Tb=rd,kb=od,md=id,gd=ad,xd=ld,yd=cd,vd=ud,wd=dd,bd=fd,Sd=pd,Cd=hd;const Eb=Cb,Ib=Tb,Ab=v.forwardRef(({className:e,inset:t,children:n,...r},o)=>u.jsxs(Sd,{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"})]}));Ab.displayName=Sd.displayName;const Nb=v.forwardRef(({className:e,...t},n)=>u.jsx(Cd,{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}));Nb.displayName=Cd.displayName;const Td=v.forwardRef(({className:e,sideOffset:t=4,...n},r)=>u.jsx(kb,{children:u.jsx(md,{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})}));Td.displayName=md.displayName;const Zi=v.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(xd,{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}));Zi.displayName=xd.displayName;const _b=v.forwardRef(({className:e,children:t,checked:n,...r},o)=>u.jsxs(yd,{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(wd,{children:u.jsx(le.Check,{className:"h-4 w-4"})})}),t]}));_b.displayName=yd.displayName;const jb=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(vd,{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(wd,{children:u.jsx(le.Circle,{className:"h-2 w-2 fill-current"})})}),t]}));jb.displayName=vd.displayName;const Mb=v.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(gd,{ref:r,className:te("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));Mb.displayName=gd.displayName;const Pb=v.forwardRef(({className:e,...t},n)=>u.jsx(bd,{ref:n,className:te("-mx-1 my-1 h-px bg-muted",e),...t}));Pb.displayName=bd.displayName;function Rb(e){const t=new Map;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)}}return t}function Ob(e){const t=new Map,n=Rb(e),r=Array.from(n.entries());for(const[o,s]of r)if(s.length===1){const i=s[0];i.checkpointId&&t.set(i.checkpointId,{attemptIndex:0,attemptCount:1,isLatestAttempt:!0,baseUserMessageId:o})}else{const i=[...s].sort((a,l)=>Date.parse(l.createdAt??"0")-Date.parse(a.createdAt??"0"));i.forEach((a,l)=>{a.checkpointId&&t.set(a.checkpointId,{attemptIndex:l,attemptCount:i.length,isLatestAttempt:l===i.length-1,baseUserMessageId:o})})}return t}function Db(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 cs(e,t){if(!e||typeof e!="object")return null;const n=e[t];return typeof n=="number"?n:null}function Lb(e,t){if(!e||typeof e!="object")return null;const n=e[t];return typeof n=="string"&&n.trim()?n:null}function $b(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 Fb(e){const t=Array.isArray(e)?e.map(r=>{const o=$b(r.next);return o?{...r,metadata:{...r.metadata??{},next:o}}:r}):[];return t.some(r=>cs(r.metadata,"step")!==null)&&t.sort((r,o)=>{const s=cs(r.metadata,"step"),i=cs(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 Bb(e){const t=b.useMemo(()=>Fb(e),[e]),{checkpointMetaById:n,checkpointIndexByKey:r,attemptMetaById:o,userMessageIdToAttempts:s}=b.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=cs(f.metadata,"step"),g=Lb(f.metadata,"source"),m={id:p,step:h,source:g,createdAt:f.createdAt??null,namespace:f.checkpointNs??null,parentId:f.parentId??null};if(i.set(p,m),h!==null&&g){const y=`${h}:${g}`,x=a.get(y)??[];x.push(m),a.set(y,x)}}const c=Ob(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})}const d=Db(l);return{checkpointMetaById:i,checkpointIndexByKey:a,attemptMetaById:l,userMessageIdToAttempts:d}},[t]);return{checkpointMetaById:n,checkpointIndexByKey:r,attemptMetaById:o,userMessageIdToAttempts:s}}const us=1e4;function zb(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 Dw(e,t=us){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 Lw(e){let t;return typeof e=="string"?t=e:typeof e=="object"&&e!==null?t=JSON.stringify(e):t=String(e),Dw(t),Ow(t)}const ds=0,Pn=1,Sr=2,wd=4;function Sd(e){return()=>e}function $w(e){e()}function Cd(e,t){return n=>e(t(n))}function Td(e,t){return()=>e(t)}function Fw(e,t){return n=>e(t,n)}function Zi(e){return e!==void 0}function Bw(...e){return()=>{e.map($w)}}function Cr(){}function fs(e,t){return t(e),e}function zw(e,t){return t(e)}function lt(...e){return e}function Ze(e,t){return e(Pn,t)}function Me(e,t){e(ds,t)}function Qi(e){e(Sr)}function vt(e){return e(wd)}function ge(e,t){return Ze(e,Fw(t,ds))}function ln(e,t){const n=e(Pn,r=>{n(),t(r)});return n}function kd(e){let t,n;return r=>o=>{t=o,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function Ed(e,t){return e===t}function ct(e=Ed){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function ke(e){return t=>n=>{e(n)&&t(n)}}function ue(e){return t=>Cd(t,e)}function yn(e){return t=>()=>{t(e)}}function K(e,...t){const n=Uw(...t);return(r,o)=>{switch(r){case Sr:Qi(e);return;case Pn:return Ze(e,n(o))}}}function vn(e,t){return n=>r=>{n(t=e(t,r))}}function Zn(e){return t=>n=>{e>0?e--:t(n)}}function An(e){let t=null,n;return r=>o=>{t=o,!n&&(n=setTimeout(()=>{n=void 0,r(t)},e))}}function Pe(...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);Ze(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 Uw(...e){return t=>e.reduceRight(zw,t)}function Hw(e){let t,n;const r=()=>t==null?void 0:t();return function(o,s){switch(o){case Pn:return s?n===s?void 0:(r(),n=s,t=Ze(e,s),t):(r(),Cr);case Sr:r(),n=null;return}}}function ee(e){let t=e;const n=Fe();return(r,o)=>{switch(r){case ds:t=o;break;case Pn:{o(t);break}case wd:return t}return n(r,o)}}function Nt(e,t){return fs(ee(t),n=>ge(e,n))}function Fe(){const e=[];return(t,n)=>{switch(t){case ds:e.slice().forEach(r=>{r(n)});return;case Sr:e.splice(0,e.length);return;case Pn:return e.push(n),()=>{const r=e.indexOf(n);r>-1&&e.splice(r,1)}}}}function Wt(e){return fs(Fe(),t=>ge(e,t))}function He(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:Ww(),singleton:n}}const Ww=()=>Symbol();function Vw(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=Fe(),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);Ze(s,l=>{n[i]=l,r=r|a,r===o&&Me(t,n)})}),function(s,i){switch(s){case Sr:{Qi(t);return}case Pn:return r===o&&i(n),Ze(t,i)}}}function Ce(e,t=Ed){return K(e,ct(t))}function ea(...e){return function(t,n){switch(t){case Sr:return;case Pn:return Bw(...e.map(r=>Ze(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 Kw={0:"debug",3:"error",1:"log",2:"warn"},qw=()=>typeof globalThis>"u"?window:globalThis,On=He(()=>{const e=ee(3);return{log:ee((t,n,r=1)=>{var o;const s=(o=qw().VIRTUOSO_LOG_LEVEL)!=null?o:vt(e);r>=s&&console[Kw[r]]("%creact-virtuoso: %c%s %o","color: #0253b3; font-weight: bold","color: initial",t,n)}),logLevel:e}},[],{singleton:!0});function Qn(e,t,n){return 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 Gw(e,t,n,r,o,s,i,a,l){const c=w.useCallback(d=>{const f=Yw(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 g;h&&(g=p.ownerDocument.defaultView);const m=i?a?i.scrollLeft:i.scrollTop:h?a?g.scrollX||g.document.documentElement.scrollLeft:g.scrollY||g.document.documentElement.scrollTop:a?p.scrollLeft:p.scrollTop,y=i?a?i.scrollWidth:i.scrollHeight:h?a?g.document.documentElement.scrollWidth:g.document.documentElement.scrollHeight:a?p.scrollWidth:p.scrollHeight,x=i?a?i.offsetWidth:i.offsetHeight:h?a?g.innerWidth:g.innerHeight:a?p.offsetWidth:p.offsetHeight;r({scrollHeight:y,scrollTop:Math.max(m,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 ta(c,n,l)}function Yw(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 Ad(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(),g=c.top-h.top;p=h.height-Math.max(0,g),f=g+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 Lt=He(()=>{const e=Fe(),t=Fe(),n=ee(0),r=Fe(),o=ee(0),s=Fe(),i=Fe(),a=ee(0),l=ee(0),c=ee(0),d=ee(0),f=Fe(),p=Fe(),h=ee(!1),g=ee(!1),m=ee(!1);return ge(K(e,ue(({scrollTop:y})=>y)),t),ge(K(e,ue(({scrollHeight:y})=>y)),i),ge(t,o),{deviation:n,fixedFooterHeight:c,fixedHeaderHeight:l,footerHeight:d,headerHeight:a,horizontalDirection:g,scrollBy:p,scrollContainerState:e,scrollHeight:i,scrollingInProgress:h,scrollTo:f,scrollTop:t,skipAnimationFrameInResizeObserver:m,smoothScrollTargetReached:r,statefulScrollTop:o,viewportHeight:s}},[],{singleton:!0}),qr={lvl:0};function Nd(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 rt(e){return e===qr}function Gr(e,t){if(!rt(e))return t===e.k?e.v:t<e.k?Gr(e.l,t):Gr(e.r,t)}function cn(e,t,n="k"){if(rt(e))return[-1/0,void 0];if(Number(e[n])===t)return[e.k,e.v];if(Number(e[n])<t){const r=cn(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return cn(e.l,t,n)}function Vt(e,t,n){return rt(e)?Md(t,n,1):t===e.k?wt(e,{k:t,v:n}):t<e.k?Rd(wt(e,{l:Vt(e.l,t,n)})):Rd(wt(e,{r:Vt(e.r,t,n)}))}function Tr(){return qr}function ps(e,t,n){if(rt(e))return[];const r=cn(e,t)[0];return Xw(ra(e,r,n))}function na(e,t){if(rt(e))return qr;const{k:n,l:r,r:o}=e;if(t===n){if(rt(r))return o;if(rt(o))return r;{const[s,i]=jd(r);return hs(wt(e,{k:s,l:_d(r),v:i}))}}else return t<n?hs(wt(e,{l:na(r,t)})):hs(wt(e,{r:na(o,t)}))}function er(e){return rt(e)?[]:[...er(e.l),{k:e.k,v:e.v},...er(e.r)]}function ra(e,t,n){if(rt(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 hs(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 Pd(wt(e,{lvl:n-1}));if(!rt(t)&&!rt(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(!rt(r)&&!rt(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 Md(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 _d(e){return rt(e.r)?e.l:hs(wt(e,{r:_d(e.r)}))}function oa(e){return rt(e)||e.lvl>e.r.lvl}function jd(e){return rt(e.r)?[e.k,e.v]:jd(e.r)}function Md(e,t,n,r=qr,o=qr){return{k:e,l:r,lvl:n,r:o,v:t}}function Rd(e){return sa(Pd(e))}function Pd(e){const{l:t}=e;return!rt(t)&&t.lvl===e.lvl?wt(t,{r:wt(e,{l:t.r})}):e}function sa(e){const{lvl:t,r:n}=e;return!rt(n)&&!rt(n.r)&&n.lvl===t&&n.r.lvl===t?wt(n,{l:wt(e,{r:n.l}),lvl:t+1}):e}function Xw(e){return Nd(e,({k:t,v:n})=>({index:t,value:n}))}function Od(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function Yr(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}const ia=He(()=>({recalcInProgress:ee(!1)}),[],{singleton:!0});function Dd(e,t,n){return e[ms(e,t,n)]}function ms(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 Jw(e,t,n,r){const o=ms(e,t,r),s=ms(e,n,r,o);return e.slice(o,s+1)}function Dn(e,t){return Math.round(e.getBoundingClientRect()[t])}function gs(e){return!rt(e.groupOffsetTree)}function aa({index:e},t){return t===e?0:t<e?-1:1}function Zw(){return{groupIndices:[],groupOffsetTree:Tr(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:Tr()}}function Qw(e,t){let n=rt(e)?0:1/0;for(const r of t){const{endIndex:o,size:s,startIndex:i}=r;if(n=Math.min(n,i),rt(e)){e=Vt(e,0,s);continue}const a=ps(e,i-1,o+1);if(a.some(i0(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=Vt(e,o+1,p));c&&(e=Vt(e,i,s))}return[e,n]}function e0(e){return typeof e.groupIndex<"u"}function t0({offset:e},t){return t===e?0:t<e?-1:1}function Xr(e,t,n){if(t.length===0)return 0;const{index:r,offset:o,size:s}=Dd(t,e,aa),i=e-r,a=s*i+(i-1)*n+o;return a>0?a+n:a}function Ld(e,t){if(!gs(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function $d(e,t,n){if(e0(e))return t.groupIndices[e.groupIndex]+1;{const r=e.index==="LAST"?n:e.index;let o=Ld(r,t);return o=Math.max(0,o,Math.min(n,o)),o}}function n0(e,t,n,r=0){return r>0&&(t=Math.max(t,Dd(e,r,aa).offset)),Nd(Jw(e,t,n,t0),s0)}function r0(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&&rt(s)&&t.length===2){const p=t[0].size,h=t[1].size;i=n.reduce((g,m)=>Vt(Vt(g,m,p),m+1,h),i)}else[i,a]=Qw(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)=>Vt(p,h,Xr(h,f,o)),Tr()),lastIndex:l,lastOffset:c,lastSize:d,offsetTree:f,sizeTree:i}}function o0(e){return er(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 Fd(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=ms(o,t-1,aa),a=o[l].offset;const c=cn(n,t-1);s=c[0],i=c[1],o.length&&o[l].size===cn(n,t)[1]&&(l-=1),o=o.slice(0,l+1)}else o=[];for(const{start:c,value:d}of ps(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 s0(e){return{index:e.index,value:e}}function i0(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 a0={offsetHeight:"height",offsetWidth:"width"},bn=He(([{log:e},{recalcInProgress:t}])=>{const n=Fe(),r=Fe(),o=Nt(r,0),s=Fe(),i=Fe(),a=ee(0),l=ee([]),c=ee(void 0),d=ee(void 0),f=ee((C,T)=>Dn(C,a0[T])),p=ee(void 0),h=ee(0),g=Zw(),m=Nt(K(n,Pe(l,e,h),vn(r0,g),ct()),g),y=Nt(K(l,ct(),vn((C,T)=>({current:T,prev:C.current}),{current:[],prev:[]}),ue(({prev:C})=>C)),[]);ge(K(l,ke(C=>C.length>0),Pe(m,h),ue(([C,T,E])=>{const N=C.reduce((_,D,B)=>Vt(_,D,Xr(D,T.offsetTree,E)||B),Tr());return{...T,groupIndices:C,groupOffsetTree:N}})),m),ge(K(r,Pe(m),ke(([C,{lastIndex:T}])=>C<T),ue(([C,{lastIndex:T,lastSize:E}])=>[{endIndex:T,size:E,startIndex:C}])),n),ge(c,d);const x=Nt(K(c,ue(C=>C===void 0)),!0);ge(K(d,ke(C=>C!==void 0&&rt(vt(m).sizeTree)),ue(C=>[{endIndex:0,size:C,startIndex:0}])),n);const b=Wt(K(n,Pe(m),vn(({sizes:C},[T,E])=>({changed:E!==C,sizes:E}),{changed:!1,sizes:g}),ue(C=>C.changed)));Ze(K(a,vn((C,T)=>({diff:C.prev-T,prev:T}),{diff:0,prev:0}),ue(C=>C.diff)),C=>{const{groupIndices:T}=vt(m);if(C>0)Me(t,!0),Me(s,C+Fd(C,T));else if(C<0){const E=vt(y);E.length>0&&(C-=Fd(-C,E)),Me(i,C)}}),Ze(K(a,Pe(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=Wt(s);ge(K(s,Pe(m),ue(([C,T])=>{const E=T.groupIndices.length>0,N=[],_=T.lastSize;if(E){const D=Gr(T.sizeTree,0);let B=0,G=0;for(;B<C;){const R=T.groupIndices[G],M=T.groupIndices.length===G+1?1/0:T.groupIndices[G+1]-R-1;N.push({endIndex:R,size:D,startIndex:R}),N.push({endIndex:R+1+M-1,size:_,startIndex:R+1}),G++,B+=M+1}const V=er(T.sizeTree);return B!==C&&V.shift(),V.reduce((R,{k:M,v:A})=>{let F=R.ranges;return R.prevSize!==0&&(F=[...R.ranges,{endIndex:M+C-1,size:R.prevSize,startIndex:R.prevIndex}]),{prevIndex:M+C,prevSize:A,ranges:F}},{prevIndex:C,prevSize:0,ranges:N}).ranges}return er(T.sizeTree).reduce((D,{k:B,v:G})=>({prevIndex:B+C,prevSize:G,ranges:[...D.ranges,{endIndex:B+C-1,size:D.prevSize,startIndex:D.prevIndex}]}),{prevIndex:0,prevSize:_,ranges:[]}).ranges})),n);const k=Wt(K(i,Pe(m,h),ue(([C,{offsetTree:T},E])=>{const N=-C;return Xr(N,T,E)})));return ge(K(i,Pe(m,h),ue(([C,T,E])=>{if(T.groupIndices.length>0){if(rt(T.sizeTree))return T;let N=Tr();const _=vt(y);let D=0,B=0,G=0;for(;D<-C;){G=_[B];const V=_[B+1]-G-1;B++,D+=V+1}if(N=er(T.sizeTree).reduce((V,{k:R,v:M})=>Vt(V,Math.max(0,R+C),M),N),D!==-C){const V=Gr(T.sizeTree,G);N=Vt(N,0,V);const R=cn(T.sizeTree,-C+1)[1];N=Vt(N,1,R)}return{...T,sizeTree:N,...la(T.offsetTree,0,N,E)}}else{const N=er(T.sizeTree).reduce((_,{k:D,v:B})=>Vt(_,Math.max(0,D+C),B),Tr());return{...T,sizeTree:N,...la(T.offsetTree,0,N,E)}}})),m),{beforeUnshiftWith:S,data:p,defaultItemSize:d,firstItemIndex:a,fixedItemSize:c,gap:h,groupIndices:l,itemSize:f,listRefresh:b,shiftWith:i,shiftWithOffset:k,sizeRanges:n,sizes:m,statefulTotalCount:o,totalCount:r,trackItemSizes:x,unshiftWith:s}},lt(On,ia),{singleton:!0});function l0(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const Bd=He(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=Fe(),i=Fe(),a=Wt(K(s,ue(l0)));return ge(K(a,ue(l=>l.totalCount)),n),ge(K(a,ue(l=>l.groupIndices)),e),ge(K(bt(o,t,r),ke(([l,c])=>gs(c)),ue(([l,c,d])=>cn(c.groupOffsetTree,Math.max(l-d,0),"v")[0]),ct(),ue(l=>[l])),i),{groupCounts:s,topItemsIndexes:i}},lt(bn,Lt)),Ln=He(([{log:e}])=>{const t=ee(!1),n=Wt(K(t,ke(r=>r),ct()));return Ze(t,r=>{r&&vt(e)("props updated",{},Bt.DEBUG)}),{didMount:n,propsReady:t}},lt(On),{singleton:!0}),c0=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function zd(e){const t=typeof e=="number"?{index:e}:e;return t.align||(t.align="start"),(!t.behavior||!c0)&&(t.behavior="auto"),t.offset||(t.offset=0),t}const Jr=He(([{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=Fe(),g=Fe(),m=ee(0);let y=null,x=null,b=null;function S(){y&&(y(),y=null),b&&(b(),b=null),x&&(clearTimeout(x),x=null),Me(l,!1)}return ge(K(h,Pe(n,f,r,m,a,i,p),Pe(e,s,o),ue(([[k,C,T,E,N,_,D,B],G,V,R])=>{const M=zd(k),{align:A,behavior:F,offset:L}=M,P=E-1,z=$d(M,C,P);let X=Xr(z,C.offsetTree,G)+_;A==="end"?(X+=V+cn(C.sizeTree,z)[1]-T+R,z===P&&(X+=D)):A==="center"?X+=(V+cn(C.sizeTree,z)[1]-T+R)/2:X-=N,L&&(X+=L);const ne=ye=>{S(),ye?(B("retrying to scroll to",{location:k},Bt.DEBUG),Me(h,k)):(Me(g,!0),B("list did not change, scroll successful",{},Bt.DEBUG))};if(S(),F==="smooth"){let ye=!1;b=Ze(t,Te=>{ye=ye||Te}),y=ln(d,()=>{ne(ye)})}else y=ln(K(t,u0(150)),ne);return x=setTimeout(()=>{S()},1200),Me(l,!0),B("scrolling from index to",{behavior:F,index:z,top:X},Bt.DEBUG),{behavior:F,top:X}})),c),{scrollTargetReached:g,scrollToIndex:h,topListHeight:m}},lt(bn,Lt,On),{singleton:!0});function u0(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 Zr=He(([{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 ge(K(i,Pe(l),ke(([d,f])=>!!f),yn(!1)),a),ge(K(i,Pe(l),ke(([d,f])=>!!f),yn(!1)),c),Ze(K(bt(t,i),Pe(a,n,e,c),ke(([[,d],f,{sizeTree:p},h,g])=>d&&(!rt(p)||Zi(h))&&!f&&!g),Pe(l)),([,d])=>{ln(o,()=>{Me(c,!0)}),ca(4,()=>{ln(r,()=>{Me(a,!0)}),Me(s,d)})}),{initialItemFinalLocationReached:c,initialTopMostItemIndex:l,scrolledToInitialItem:a}},lt(bn,Lt,Jr,Ln),{singleton:!0});function Ud(e,t){return Math.abs(e-t)<1.01}const Qr="up",eo="down",d0="none",f0={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},p0=0,to=He(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:o,viewportHeight:s}])=>{const i=ee(!1),a=ee(!0),l=Fe(),c=Fe(),d=ee(4),f=ee(p0),p=Nt(K(ea(K(Ce(o),Zn(1),yn(!0)),K(Ce(o),Zn(1),yn(!1),kd(100))),ct()),!1),h=Nt(K(ea(K(n,yn(!0)),K(n,yn(!1),kd(200))),ct()),!1);ge(K(bt(Ce(o),Ce(f)),ue(([b,S])=>b<=S),ct()),a),ge(K(a,An(50)),c);const g=Wt(K(bt(r,Ce(s),Ce(t),Ce(e),Ce(d)),vn((b,[{scrollHeight:S,scrollTop:k},C,T,E,N])=>{const _=k+C-S>-N,D={scrollHeight:S,scrollTop:k,viewportHeight:C};if(_){let G,V;return k>b.state.scrollTop?(G="SCROLLED_DOWN",V=b.state.scrollTop-k):(G="SIZE_DECREASED",V=b.state.scrollTop-k||b.scrollTopDelta),{atBottom:!0,atBottomBecause:G,scrollTopDelta:V,state:D}}let B;return D.scrollHeight>b.state.scrollHeight?B="SIZE_INCREASED":C<b.state.viewportHeight?B="VIEWPORT_HEIGHT_DECREASING":k<b.state.scrollTop?B="SCROLLING_UPWARDS":B="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:B,state:D}},f0),ct((b,S)=>b&&b.atBottom===S.atBottom))),m=Nt(K(r,vn((b,{scrollHeight:S,scrollTop:k,viewportHeight:C})=>{if(Ud(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),ue(b=>b.jump)),0);ge(K(g,ue(b=>b.atBottom)),i),ge(K(i,An(50)),l);const y=ee(eo);ge(K(r,ue(({scrollTop:b})=>b),ct(),vn((b,S)=>vt(h)?{direction:b.direction,prevScrollTop:S}:{direction:S<b.prevScrollTop?Qr:eo,prevScrollTop:S},{direction:eo,prevScrollTop:0}),ue(b=>b.direction)),y),ge(K(r,An(50),yn(d0)),y);const x=ee(0);return ge(K(p,ke(b=>!b),yn(0)),x),ge(K(o,An(100),Pe(p),ke(([b,S])=>!!S),vn(([b,S],[k])=>[S,k],[0,0]),ue(([b,S])=>S-b)),x),{atBottomState:g,atBottomStateChange:l,atBottomThreshold:d,atTopStateChange:c,atTopThreshold:f,isAtBottom:i,isAtTop:a,isScrolling:p,lastJumpDueToItemResize:m,scrollDirection:y,scrollVelocity:x}},lt(Lt)),xs="top",ys="bottom",Hd="none";function Wd(e,t,n){return typeof e=="number"?n===Qr&&t===xs||n===eo&&t===ys?e:0:n===Qr?t===xs?e.main:e.reverse:t===ys?e.main:e.reverse}function Vd(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const da=He(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:o}])=>{const s=Fe(),i=ee(0),a=ee(0),l=ee(0),c=Nt(K(bt(Ce(r),Ce(o),Ce(n),Ce(s,Yr),Ce(l),Ce(i),Ce(t),Ce(e),Ce(a)),ue(([d,f,p,[h,g],m,y,x,b,S])=>{const k=d-b,C=y+x,T=Math.max(p-k,0);let E=Hd;const N=Vd(S,xs),_=Vd(S,ys);return h-=b,h+=p+x,g+=p+x,g-=b,h>d+C-N&&(E=Qr),g<d-T+f+_&&(E=eo),E!==Hd?[Math.max(k-p-Wd(m,xs,E)-N,0),k-T-x+f+Wd(m,ys,E)+_]:null}),ke(d=>d!=null),ct(Yr)),[0,0]);return{increaseViewportBy:a,listBoundary:s,overscan:l,topListHeight:i,visibleRange:c}},lt(Lt),{singleton:!0});function h0(e,t,n){if(gs(t)){const r=Ld(e,t);return[{index:cn(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 vs(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 m=e[e.length-1];d=m.offset+m.size}const f=n-i,p=a+f*l+(f-1)*r,h=c,g=p-d;return{bottom:d,firstItemIndex:s,items:qd(e,o,s),offsetBottom:g,offsetTop:c,top:h,topItems:qd(t,o,s),topListHeight:t.reduce((m,y)=>y.size+m,0),totalCount:n}}function Kd(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 vs(c,[],a,o,n,r)}function qd(e,t,n){if(e.length===0)return[];if(!gs(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=ps(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 tr=He(([{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:g}])=>{const m=ee([]),y=ee(0),x=Fe();ge(s.topItemsIndexes,m);const b=Nt(K(bt(h,g,Ce(l,Yr),Ce(o),Ce(r),Ce(c),d,Ce(m),Ce(t),Ce(n),e),ke(([T,E,,N,,,,,,,_])=>{const D=_&&_.length!==N;return T&&!E&&!D}),ue(([,,[T,E],N,_,D,B,G,V,R,M])=>{const A=_,{offsetTree:F,sizeTree:L}=A,P=vt(y);if(N===0)return{...fa,totalCount:N};if(T===0&&E===0)return P===0?{...fa,totalCount:N}:Kd(P,D,_,V,R,M||[]);if(rt(L))return P>0?null:vs(h0(ua(D,N),A,M),[],N,R,A,V);const z=[];if(G.length>0){const q=G[0],U=G[G.length-1];let J=0;for(const $ of ps(L,q,U)){const Y=$.value,Z=Math.max($.start,q),de=Math.min($.end,U);for(let oe=Z;oe<=de;oe++)z.push({data:M==null?void 0:M[oe],index:oe,offset:J,size:Y}),J+=Y}}if(!B)return vs([],z,N,R,A,V);const X=G.length>0?G[G.length-1]+1:0,ne=n0(F,T,E,X);if(ne.length===0)return null;const ye=N-1,Te=fs([],q=>{for(const U of ne){const J=U.value;let $=J.offset,Y=U.start;const Z=J.size;if(J.offset<T){Y+=Math.floor((T-J.offset+R)/(Z+R));const oe=Y-U.start;$+=oe*Z+oe*R}Y<X&&($+=(X-Y)*Z,Y=X);const de=Math.min(U.end,ye);for(let oe=Y;oe<=de&&!($>=E);oe++)q.push({data:M==null?void 0:M[oe],index:oe,offset:$,size:Z}),$+=Z+R}});return vs(Te,z,N,R,A,V)}),ke(T=>T!==null),ct()),fa);ge(K(e,ke(Zi),ue(T=>T==null?void 0:T.length)),o),ge(K(b,ue(T=>T.topListHeight)),f),ge(f,a),ge(K(b,ue(T=>[T.top,T.bottom])),i),ge(K(b,ue(T=>T.items)),x);const S=Wt(K(b,ke(({items:T})=>T.length>0),Pe(o,e),ke(([{items:T},E])=>T[T.length-1].originalIndex===E-1),ue(([,T,E])=>[T-1,E]),ct(Yr),ue(([T])=>T))),k=Wt(K(b,An(200),ke(({items:T,topItems:E})=>T.length>0&&T[0].originalIndex===E.length),ue(({items:T})=>T[0].index),ct())),C=Wt(K(b,ke(({items:T})=>T.length>0),ue(({items:T})=>{let E=0,N=T.length-1;for(;T[E].type==="group"&&E<N;)E++;for(;T[N].type==="group"&&N>E;)N--;return{endIndex:T[N].index,startIndex:T[E].index}}),ct(Od)));return{endReached:S,initialItemCount:y,itemsRendered:x,listState:b,rangeChanged:C,startReached:k,topItemsIndexes:m,...p}},lt(bn,Bd,da,Zr,Jr,to,Ln,ia),{singleton:!0}),Gd=He(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:o}])=>{const s=Fe(),i=Nt(K(bt(n,e,r,t,o),ue(([a,l,c,d,f])=>a+l+c+d+f.offsetBottom+f.bottom)),0);return ge(Ce(i),s),{totalListHeight:i,totalListHeightChanged:s}},lt(Lt,tr),{singleton:!0}),m0=He(([{viewportHeight:e},{totalListHeight:t}])=>{const n=ee(!1),r=Nt(K(bt(n,e,t),ke(([o])=>o),ue(([,o,s])=>Math.max(0,o-s)),An(0),ct()),0);return{alignToBottom:n,paddingTopAddition:r}},lt(Lt,Gd),{singleton:!0}),Yd=He(()=>({context:ee(null)})),g0=({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,Xd=He(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:s,scrollingInProgress:i,scrollTop:a,viewportHeight:l},{scrollToIndex:c}])=>{const d=Fe();return ge(K(d,Pe(t,l,n,s,o,r,a),Pe(e),ue(([[f,p,h,g,m,y,x,b],S])=>{const{align:k,behavior:C,calculateViewLocation:T=g0,done:E,...N}=f,_=$d(f,p,g-1),D=Xr(_,p.offsetTree,S)+m+y,B=D+cn(p.sizeTree,_)[1],G=b+y,V=b+h-x,R=T({itemBottom:B,itemTop:D,locationParams:{align:k,behavior:C,...N},viewportBottom:V,viewportTop:G});return R?E&&ln(K(i,ke(M=>!M),Zn(vt(i)?1:2)),E):E&&E(),R}),ke(f=>f!==null)),c),{scrollIntoView:d}},lt(bn,Lt,Jr,tr,On),{singleton:!0});function Jd(e){return e?e==="smooth"?"smooth":"auto":!1}const x0=(e,t)=>typeof e=="function"?Jd(e(t)):t&&Jd(e),y0=He(([{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 g=ee(!1),m=Fe();let y=null;function x(C){Me(i,{align:"end",behavior:C,index:"LAST"})}Ze(K(bt(K(Ce(t),Zn(1)),l),Pe(Ce(g),s,a,f),ue(([[C,T],E,N,_,D])=>{let B=T&&_,G="auto";return B&&(G=x0(E,N||D),B=B&&!!G),{followOutputBehavior:G,shouldFollow:B,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=ln(e,()=>{vt(d)("following output to ",{totalCount:T},Bt.DEBUG),x(C),y=null})});function b(C){const T=ln(o,E=>{C&&!E.atBottom&&E.notAtBottomBecause==="SIZE_INCREASED"&&!y&&(vt(d)("scrolling to bottom due to increased size",{},Bt.DEBUG),x("auto"))});setTimeout(T,100)}Ze(K(bt(Ce(g),t,c),ke(([C,,T])=>C&&T),vn(({value:C},[,T])=>({refreshed:C===T,value:T}),{refreshed:!1,value:0}),ke(({refreshed:C})=>C),Pe(g,t)),([,C])=>{vt(a)&&b(C!==!1)}),Ze(m,()=>{b(vt(g)!==!1)}),Ze(bt(Ce(g),o),([C,T])=>{C&&!T.atBottom&&T.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&x("auto")});const S=ee(null),k=Fe();return ge(ea(K(Ce(r),ue(C=>{var T;return(T=C==null?void 0:C.length)!=null?T:0})),K(Ce(t))),k),Ze(K(bt(K(k,Zn(1)),l),Pe(Ce(S),a,f,p),ue(([[C,T],E,N,_,D])=>T&&N&&(E==null?void 0:E({context:D,totalCount:C,scrollingInProgress:_}))),ke(C=>!!C),An(0)),C=>{y&&(y(),y=null),vt(n)?requestAnimationFrame(()=>{vt(d)("scrolling into view",{}),Me(h,C)}):y=ln(e,()=>{vt(d)("scrolling into view",{}),Me(h,C),y=null})}),{autoscrollToBottom:m,followOutput:g,scrollIntoViewOnChange:S}},lt(bn,to,Jr,Zr,Ln,On,Lt,Yd,Xd)),v0=He(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:s,listState:i},{didMount:a}])=>(ge(K(a,Pe(s),ke(([,l])=>l!==0),Pe(o,r,t,n,e),ue(([[,l],c,d,f,p,h=[]])=>Kd(l,c,d,f,p,h))),i),{}),lt(bn,Zr,tr,Ln),{singleton:!0}),b0=He(([{didMount:e},{scrollTo:t},{listState:n}])=>{const r=ee(0);return Ze(K(e,Pe(r),ke(([,o])=>o!==0),ue(([,o])=>({top:o}))),o=>{ln(K(n,Zn(1),ke(s=>s.items.length>1)),()=>{requestAnimationFrame(()=>{Me(t,o)})})}),{initialScrollTop:r}},lt(Ln,Lt,tr),{singleton:!0}),Zd=He(([{scrollVelocity:e}])=>{const t=ee(!1),n=Fe(),r=ee(!1);return ge(K(e,Pe(r,t,n),ke(([o,s])=>!!s),ue(([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),Ze(K(bt(t,e,n),Pe(r)),([[o,s,i],a])=>{o&&a&&a.change&&a.change(s,i)}),{isSeeking:t,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:e}},lt(to),{singleton:!0}),pa=He(([{scrollContainerState:e,scrollTo:t}])=>{const n=Fe(),r=Fe(),o=Fe(),s=ee(!1),i=ee(void 0);return ge(K(bt(n,r),ue(([{scrollHeight:a,scrollTop:l,viewportHeight:c},{offsetTop:d}])=>({scrollHeight:a,scrollTop:Math.max(0,l-d),viewportHeight:c}))),e),ge(K(t,Pe(r),ue(([a,{offsetTop:l}])=>({...a,top:a.top+l}))),o),{customScrollParent:i,useWindowScroll:s,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:r}},lt(Lt)),w0=He(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:o},{didMount:s},{useWindowScroll:i,windowScrollContainerState:a,windowViewportRect:l}])=>{const c=Fe(),d=ee(void 0),f=ee(null),p=ee(null);return ge(a,f),ge(l,p),Ze(K(c,Pe(t,r,i,f,p,n)),([h,g,m,y,x,b,S])=>{const k=o0(g.sizeTree);y&&x!==null&&b!==null&&(m=x.scrollTop-b.offsetTop),m-=S,h({ranges:k,scrollTop:m})}),ge(K(d,ke(Zi),ue(S0)),o),ge(K(s,Pe(d),ke(([,h])=>h!==void 0),ct(),ue(([,h])=>h.ranges)),e),{getState:c,restoreStateFrom:d}},lt(bn,Lt,Zr,Ln,pa));function S0(e){return{align:"start",index:0,offset:e.scrollTop}}const C0=He(([{topItemsIndexes:e}])=>{const t=ee(0);return ge(K(t,ke(n=>n>=0),ue(n=>Array.from({length:n}).map((r,o)=>o))),e),{topItemCount:t}},lt(tr));function Qd(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const T0=Qd(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),k0=He(([{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:g}])=>{const m=Wt(K(l,Pe(i),vn(([,x,b,S],[{bottom:k,items:C,offsetBottom:T,totalCount:E},N])=>{const _=k+T;let D=0;return b===E&&x.length>0&&C.length>0&&(C[0].originalIndex===0&&x[0].originalIndex===0||(D=_-S,D!==0&&(D+=N))),[D,C,E,_]},[0,[],0,0]),ke(([x])=>x!==0),Pe(r,a,n,o,h,g),ke(([,x,b,S,,,k])=>!k&&!S&&x!==0&&b===Qr),ue(([[x],,,,,b])=>(b("Upward scrolling compensation",{amount:x},Bt.DEBUG),x))));function y(x){x>0?(Me(t,{behavior:"auto",top:-x}),Me(e,0)):(Me(e,0),Me(t,{behavior:"auto",top:-x}))}return Ze(K(m,Pe(e,s)),([x,b,S])=>{S&&T0()?Me(e,b-x):y(-x)}),Ze(K(bt(Nt(s,!1),e,g),ke(([x,b,S])=>!x&&!S&&b!==0),ue(([x,b])=>b),An(1)),y),ge(K(f,ue(x=>({top:-x}))),t),Ze(K(c,Pe(p,d),ue(([x,{groupIndices:b,lastSize:S,sizeTree:k},C])=>{function T(E){return E*(S+C)}if(b.length===0)return T(x);{let E=0;const N=Gr(k,0);let _=0,D=0;for(;_<x;){_++,E+=N;let B=b.length===D+1?1/0:b[D+1]-b[D]-1;_+B>x&&(E-=N,B=x-_+1),_+=B,E+=T(B),D++}return E}})),x=>{Me(e,x),requestAnimationFrame(()=>{Me(t,{top:x}),requestAnimationFrame(()=>{Me(e,0),Me(g,!1)})})}),{deviation:e}},lt(Lt,to,tr,bn,On,ia)),E0=He(([e,t,n,r,o,s,i,a,l,c,d])=>({...e,...t,...n,...r,...o,...s,...i,...a,...l,...c,...d}),lt(da,v0,Ln,Zd,Gd,b0,m0,pa,Xd,On,Yd)),ef=He(([{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:g},m,y,x,{listState:b,topItemsIndexes:S,...k},{scrollToIndex:C},T,{topItemCount:E},{groupCounts:N},_])=>(ge(k.rangeChanged,_.scrollSeekRangeChanged),ge(K(_.windowViewportRect,ue(D=>D.visibleHeight)),m.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:n,fixedItemHeight:r,gap:o,groupCounts:N,initialItemFinalLocationReached:p,initialTopMostItemIndex:h,scrolledToInitialItem:g,sizeRanges:a,topItemCount:E,topItemsIndexes:S,totalCount:d,...x,groupIndices:s,itemSize:i,listState:b,scrollToIndex:C,statefulTotalCount:c,trackItemSizes:f,...k,..._,...m,sizes:l,...y}),lt(bn,Zr,Lt,w0,y0,tr,Jr,k0,C0,Bd,E0));function I0(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 bs=typeof document<"u"?w.useLayoutEffect:w.useEffect;function tf(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&&Me(y.propsReady,!1);for(const b of r){const S=y[t.required[b]];Me(S,x[b])}for(const b of o)if(b in x){const S=y[t.optional[b]];Me(S,x[b])}y.propsReady&&Me(y.propsReady,!0)}function c(y){return s.reduce((x,b)=>(x[b]=S=>{const k=y[t.methods[b]];Me(k,S)},x),{})}function d(y){return i.reduce((x,b)=>(x[b]=Hw(y[t.events[b]]),x),{})}const f=w.forwardRef((y,x)=>{const{children:b,...S}=y,[k]=w.useState(()=>fs(Vw(e),E=>{l(E,S)})),[C]=w.useState(Td(d,k));bs(()=>{for(const E of i)E in S&&Ze(C[E],S[E]);return()=>{Object.values(C).map(Qi)}},[S,C,k]),bs(()=>{l(k,S)}),w.useImperativeHandle(x,Sd(c(k)));const T=n;return u.jsx(a.Provider,{value:k,children:n?u.jsx(T,{...I0([...r,...o,...i],S),children:b}):b})}),p=y=>{const x=w.useContext(a);return w.useCallback(b=>{Me(x[y],b)},[x,y])},h=y=>{const x=w.useContext(a)[y],b=w.useCallback(S=>Ze(x,S),[x]);return w.useSyncExternalStore(b,()=>vt(x),()=>vt(x))},g=y=>{const x=w.useContext(a)[y],[b,S]=w.useState(Td(vt,x));return bs(()=>Ze(x,k=>{k!==b&&S(Sd(k))}),[x,b]),b},m=w.version.startsWith("18")?h:g;return{Component:f,useEmitter:(y,x)=>{const b=w.useContext(a)[y];bs(()=>Ze(b,x),[x,b])},useEmitterValue:m,usePublisher:p}}const nf=w.createContext(void 0),rf=w.createContext(void 0),of=typeof document<"u"?w.useLayoutEffect:w.useEffect;function ha(e){return"self"in e}function A0(e){return"body"in e}function sf(e,t,n,r=Cr,o,s){const i=w.useRef(null),a=w.useRef(null),l=w.useRef(null),c=w.useCallback(p=>{let h,g,m;const y=p.target;if(A0(y)||ha(y)){const b=ha(y)?y:y.defaultView;m=s?b.scrollX:b.scrollY,h=s?b.document.documentElement.scrollWidth:b.document.documentElement.scrollHeight,g=s?b.innerWidth:b.innerHeight}else m=s?y.scrollLeft:y.scrollTop,h=s?y.scrollWidth:y.scrollHeight,g=s?y.offsetWidth:y.offsetHeight;const x=()=>{e({scrollHeight:h,scrollTop:Math.max(m,0),viewportHeight:g})};p.suppressFlushSync?x():Ys.flushSync(x),a.current!==null&&(m===a.current||m<=0||m===h-g)&&(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 g=p.behavior==="smooth";let m,y,x;ha(h)?(y=Math.max(Dn(h.document.documentElement,s?"width":"height"),s?h.document.documentElement.scrollWidth:h.document.documentElement.scrollHeight),m=s?h.innerWidth:h.innerHeight,x=s?window.scrollX:window.scrollY):(y=h[s?"scrollWidth":"scrollHeight"],m=Dn(h,s?"width":"height"),x=h[s?"scrollLeft":"scrollTop"]);const b=y-m;if(p.top=Math.ceil(Math.max(Math.min(b,p.top),0)),Ud(m,y)||p.top===x){e({scrollHeight:y,scrollTop:x,viewportHeight:m}),g&&t(!0);return}g?(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",af="sticky",ga=Qd(()=>{if(typeof document>"u")return af;const e=document.createElement("div");return e.style.position=ma,e.style.position===ma?ma:af});function xa(e){return e}const N0=He(()=>{const e=ee(a=>`Item ${a}`),t=ee(a=>`Group ${a}`),n=ee({}),r=ee(xa),o=ee("div"),s=ee(Cr),i=(a,l=null)=>Nt(K(n,ue(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")}}),_0=He(([e,t])=>({...e,...t}),lt(ef,N0)),j0=({height:e})=>u.jsx("div",{style:{height:e}}),M0={overflowAnchor:"none",position:ga(),zIndex:1},lf={overflowAnchor:"none"},R0={...lf,display:"inline-block",height:"100%"},cf=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"),p=Ae("itemSize"),h=Ae("log"),g=Zt("gap"),m=Ae("horizontalDirection"),{callbackRef:y}=Gw(n,p,f,e?Cr:a,h,g,o,m,Ae("skipAnimationFrameInResizeObserver")),[x,b]=w.useState(0);ya("deviation",R=>{x!==R&&b(R)});const S=Ae("EmptyPlaceholder"),k=Ae("ScrollSeekPlaceholder")||j0,C=Ae("ListComponent"),T=Ae("ItemComponent"),E=Ae("GroupComponent"),N=Ae("computeItemKey"),_=Ae("isSeeking"),D=Ae("groupIndices").length>0,B=Ae("alignToBottom"),G=Ae("initialItemFinalLocationReached"),V=e?{}:{boxSizing:"border-box",...m?{display:"inline-block",height:"100%",marginLeft:x!==0?x:B?"auto":0,paddingLeft:t.offsetTop,paddingRight:t.offsetBottom,whiteSpace:"nowrap"}:{marginTop:x!==0?x:B?"auto":0,paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},...G?{}:{visibility:"hidden"}};return!e&&t.totalCount===0&&S?u.jsx(S,{..._t(S,c)}):u.jsx(C,{..._t(C,c),"data-testid":e?"virtuoso-top-item-list":"virtuoso-item-list",ref:y,style:V,children:(e?t.topItems:t.items).map(R=>{const M=R.originalIndex,A=N(M+t.firstItemIndex,R.data,c);return _?w.createElement(k,{..._t(k,c),height:R.size,index:R.index,key:A,type:R.type||"item",...R.type==="group"?{}:{groupIndex:R.groupIndex}}):R.type==="group"?w.createElement(E,{..._t(E,c),"data-index":M,"data-item-index":R.index,"data-known-size":R.size,key:A,style:M0},d(R.index,c)):w.createElement(T,{..._t(T,c),...L0(T,R.data),"data-index":M,"data-item-group-index":R.groupIndex,"data-item-index":R.index,"data-known-size":R.size,key:A,style:m?R0:lf},D?l(R.index,R.groupIndex,R.data,c):l(R.index,R.data,c))})})}),P0={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},O0={outline:"none",overflowX:"auto",position:"relative"},ws=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),D0={position:ga(),top:0,width:"100%",zIndex:1};function _t(e,t){if(typeof e!="string")return{context:t}}function L0(e,t){return{item:typeof e=="string"?void 0:t}}const $0=w.memo(function(){const e=Ae("HeaderComponent"),t=Zt("headerHeight"),n=Ae("HeaderFooterTag"),r=Qn(w.useMemo(()=>s=>{t(Dn(s,"height"))},[t]),!0,Ae("skipAnimationFrameInResizeObserver")),o=Ae("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{..._t(e,o)})}):null}),F0=w.memo(function(){const e=Ae("FooterComponent"),t=Zt("footerHeight"),n=Ae("HeaderFooterTag"),r=Qn(w.useMemo(()=>s=>{t(Dn(s,"height"))},[t]),!0,Ae("skipAnimationFrameInResizeObserver")),o=Ae("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{..._t(e,o)})}):null});function uf({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:g}=sf(a,c,l,d,void 0,f);return e("scrollTo",g),e("scrollBy",p),u.jsx(l,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:h,style:{...f?O0:P0,...o},tabIndex:0,...i,..._t(l,s),children:r})})}function df({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),g=t("scrollerRef"),{scrollByCallback:m,scrollerRef:y,scrollToCallback:x}=sf(a,c,l,g,p);return of(()=>{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",m),u.jsx(l,{ref:h,"data-virtuoso-scroller":!0,style:{position:"relative",...o,...d!==0?{height:d+f}:{}},...i,..._t(l,s),children:r})})}const B0=({children:e})=>{const t=w.useContext(nf),n=Zt("viewportHeight"),r=Zt("fixedItemHeight"),o=Ae("alignToBottom"),s=Ae("horizontalDirection"),i=w.useMemo(()=>Cd(n,l=>Dn(l,s?"width":"height")),[n,s]),a=Qn(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:ws(o),children:e})},z0=({children:e})=>{const t=w.useContext(nf),n=Zt("windowViewportRect"),r=Zt("fixedItemHeight"),o=Ae("customScrollParent"),s=Ad(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:ws(i),children:e})},U0=({children:e})=>{const t=Ae("TopItemListComponent")||"div",n=Ae("headerHeight"),r={...D0,marginTop:`${n}px`},o=Ae("context");return u.jsx(t,{style:r,..._t(t,o),children:e})},H0=w.memo(function(e){const t=Ae("useWindowScroll"),n=Ae("topItemsIndexes").length>0,r=Ae("customScrollParent"),o=Ae("context");return u.jsxs(r||t?K0:V0,{...e,context:o,children:[n&&u.jsx(U0,{children:u.jsx(cf,{showTopList:!0})}),u.jsxs(r||t?z0:B0,{children:[u.jsx($0,{}),u.jsx(cf,{}),u.jsx(F0,{})]})]})}),{Component:W0,useEmitter:ya,useEmitterValue:Ae,usePublisher:Zt}=tf(_0,{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"}},H0),V0=uf({useEmitter:ya,useEmitterValue:Ae,usePublisher:Zt}),K0=df({useEmitter:ya,useEmitterValue:Ae,usePublisher:Zt}),q0=W0;lt(ef,He(()=>{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(Cr),l=(c,d=null)=>Nt(K(s,ue(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 ff={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},G0={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:pf,floor:Ss,max:no,min:va,round:hf}=Math;function mf(e,t,n){return Array.from({length:t-e+1}).map((r,o)=>({data:n===null?null:n[o+e],index:o+e}))}function Y0(e){return{...G0,items:e}}function Cs(e,t){return e&&e.width===t.width&&e.height===t.height}function X0(e,t){return e&&e.column===t.column&&e.row===t.row}const J0=He(([{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:g,propsReady:m},{customScrollParent:y,useWindowScroll:x,windowScrollContainerState:b,windowScrollTo:S,windowViewportRect:k},C])=>{const T=ee(0),E=ee(0),N=ee(ff),_=ee({height:0,width:0}),D=ee({height:0,width:0}),B=Fe(),G=Fe(),V=ee(0),R=ee(null),M=ee({column:0,row:0}),A=Fe(),F=Fe(),L=ee(!1),P=ee(0),z=ee(!0),X=ee(!1),ne=ee(!1);Ze(K(g,Pe(P),ke(([$,Y])=>!!Y)),()=>{Me(z,!1)}),Ze(K(bt(g,z,D,_,P,X),ke(([$,Y,Z,de,,oe])=>$&&!Y&&Z.height!==0&&de.height!==0&&!oe)),([,,,,$])=>{Me(X,!0),ca(1,()=>{Me(B,$)}),ln(K(c),()=>{Me(t,[0,0]),Me(z,!0)})}),ge(K(F,ke($=>$!=null&&$.scrollTop>0),yn(0)),E),Ze(K(g,Pe(F),ke(([,$])=>$!=null)),([,$])=>{$&&(Me(_,$.viewport),Me(D,$.item),Me(M,$.gap),$.scrollTop>0&&(Me(L,!0),ln(K(c,Zn(1)),Y=>{Me(L,!1)}),Me(l,{top:$.scrollTop})))}),ge(K(_,ue(({height:$})=>$)),f),ge(K(bt(Ce(_,Cs),Ce(D,Cs),Ce(M,($,Y)=>$&&$.column===Y.column&&$.row===Y.row),Ce(c)),ue(([$,Y,Z,de])=>({gap:Z,item:Y,scrollTop:de,viewport:$}))),A),ge(K(bt(Ce(T),r,Ce(M,X0),Ce(D,Cs),Ce(_,Cs),Ce(R),Ce(E),Ce(L),Ce(z),Ce(P)),ke(([,,,,,,,$])=>!$),ue(([$,[Y,Z],de,oe,_e,ze,se,,me,Re])=>{const{column:Ve,row:ut}=de,{height:Ke,width:qe}=oe,{width:Qe}=_e;if(se===0&&($===0||Qe===0))return ff;if(qe===0){const Rt=ua(Re,$),zt=Rt+Math.max(se-1,0);return Y0(mf(Rt,zt,ze))}const Ge=gf(Qe,qe,Ve);let et,st;me?Y===0&&Z===0&&se>0?(et=0,st=se-1):(et=Ge*Ss((Y+ut)/(Ke+ut)),st=Ge*pf((Z+ut)/(Ke+ut))-1,st=va($-1,no(st,Ge-1)),et=va(st,no(0,et))):(et=0,st=-1);const Mt=mf(et,st,ze),{bottom:gt,top:Ct}=xf(_e,de,oe,Mt),it=pf($/Ge),St=it*Ke+(it-1)*ut-gt;return{bottom:gt,itemHeight:Ke,items:Mt,itemWidth:qe,offsetBottom:St,offsetTop:Ct,top:Ct}})),N),ge(K(R,ke($=>$!==null),ue($=>$.length)),T),ge(K(bt(_,D,N,M),ke(([$,Y,{items:Z}])=>Z.length>0&&Y.height!==0&&$.height!==0),ue(([$,Y,{items:Z},de])=>{const{bottom:oe,top:_e}=xf($,de,Y,Z);return[_e,oe]}),ct(Yr)),t);const ye=ee(!1);ge(K(c,Pe(ye),ue(([$,Y])=>Y||$!==0)),ye);const Te=Wt(K(bt(N,T),ke(([{items:$}])=>$.length>0),Pe(ye),ke(([[$,Y],Z])=>{const de=$.items[$.items.length-1].index===Y-1;return(Z||$.bottom>0&&$.itemHeight>0&&$.offsetBottom===0&&$.items.length===Y)&&de}),ue(([[,$]])=>$-1),ct())),q=Wt(K(Ce(N),ke(({items:$})=>$.length>0&&$[0].index===0),yn(0),ct())),U=Wt(K(Ce(N),Pe(L),ke(([{items:$},Y])=>$.length>0&&!Y),ue(([{items:$}])=>({endIndex:$[$.length-1].index,startIndex:$[0].index})),ct(Od),An(0)));ge(U,h.scrollSeekRangeChanged),ge(K(B,Pe(_,D,T,M),ue(([$,Y,Z,de,oe])=>{const _e=zd($),{align:ze,behavior:se,offset:me}=_e;let Re=_e.index;Re==="LAST"&&(Re=de-1),Re=no(0,Re,va(de-1,Re));let Ve=ba(Y,oe,Z,Re);return ze==="end"?Ve=hf(Ve-Y.height+Z.height):ze==="center"&&(Ve=hf(Ve-Y.height/2+Z.height/2)),me&&(Ve+=me),{behavior:se,top:Ve}})),l);const J=Nt(K(N,ue($=>$.offsetBottom+$.bottom)),0);return ge(K(k,ue($=>({height:$.visibleHeight,width:$.visibleWidth}))),_),{customScrollParent:y,data:R,deviation:V,footerHeight:o,gap:M,headerHeight:s,increaseViewportBy:e,initialItemCount:E,itemDimensions:D,overscan:n,restoreStateFrom:F,scrollBy:i,scrollContainerState:a,scrollHeight:G,scrollTo:l,scrollToIndex:B,scrollTop:c,smoothScrollTargetReached:d,totalCount:T,useWindowScroll:x,viewportDimensions:_,windowScrollContainerState:b,windowScrollTo:S,windowViewportRect:k,...h,gridState:N,horizontalDirection:ne,initialTopMostItemIndex:P,totalListHeight:J,...p,endReached:Te,propsReady:m,rangeChanged:U,startReached:q,stateChanged:A,stateRestoreInProgress:L,...C}},lt(da,Lt,to,Zd,Ln,pa,On));function gf(e,t,n){return no(1,Ss((e+n)/(Ss(t)+n)))}function xf(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=gf(e.width,n.width,t.column),s=Ss(r/o),i=s*n.height+no(0,s-1)*t.row;return i>0?i+t.row:i}const Z0=He(()=>{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(Cr),l=(f,p=null)=>Nt(K(t,ue(h=>h[f]),ct()),p),c=ee(!1),d=ee(!1);return ge(Ce(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")}}),Q0=He(([e,t])=>({...e,...t}),lt(J0,Z0)),eS=w.memo(function(){const e=ft("gridState"),t=ft("listClassName"),n=ft("itemClassName"),r=ft("itemContent"),o=ft("computeItemKey"),s=ft("isSeeking"),i=Qt("scrollHeight"),a=ft("ItemComponent"),l=ft("ListComponent"),c=ft("ScrollSeekPlaceholder"),d=ft("context"),f=Qt("itemDimensions"),p=Qt("gap"),h=ft("log"),g=ft("stateRestoreInProgress"),m=Qt("reportReadyState"),y=Qn(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})}p({column:vf("column-gap",getComputedStyle(x).columnGap,h),row:vf("row-gap",getComputedStyle(x).rowGap,h)})},[i,f,p,h]),!0,!1);return of(()=>{e.itemHeight>0&&e.itemWidth>0&&m(!0)},[e]),g?null:u.jsx(l,{className:t,ref:y,..._t(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,{..._t(c,d),height:e.itemHeight,index:x.index,width:e.itemWidth},b):w.createElement(a,{..._t(a,d),className:n,"data-index":x.index,key:b},r(x.index,x.data,d))})})}),tS=w.memo(function(){const e=ft("HeaderComponent"),t=Qt("headerHeight"),n=ft("headerFooterTag"),r=Qn(w.useMemo(()=>s=>{t(Dn(s,"height"))},[t]),!0,!1),o=ft("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{..._t(e,o)})}):null}),nS=w.memo(function(){const e=ft("FooterComponent"),t=Qt("footerHeight"),n=ft("headerFooterTag"),r=Qn(w.useMemo(()=>s=>{t(Dn(s,"height"))},[t]),!0,!1),o=ft("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{..._t(e,o)})}):null}),rS=({children:e})=>{const t=w.useContext(rf),n=Qt("itemDimensions"),r=Qt("viewportDimensions"),o=Qn(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:ws(!1),children:e})},oS=({children:e})=>{const t=w.useContext(rf),n=Qt("windowViewportRect"),r=Qt("itemDimensions"),o=ft("customScrollParent"),s=Ad(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:ws(!1),children:e})},sS=w.memo(function({...e}){const t=ft("useWindowScroll"),n=ft("customScrollParent"),r=n||t?aS:iS,o=n||t?oS:rS,s=ft("context");return u.jsx(r,{...e,..._t(r,s),children:u.jsxs(o,{children:[u.jsx(tS,{}),u.jsx(eS,{}),u.jsx(nS,{})]})})}),{useEmitter:yf,useEmitterValue:ft,usePublisher:Qt}=tf(Q0,{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"}},sS),iS=uf({useEmitter:yf,useEmitterValue:ft,usePublisher:Qt}),aS=df({useEmitter:yf,useEmitterValue:ft,usePublisher:Qt});function vf(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 lS=ho.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 bf({className:e,variant:t,...n}){return u.jsx("div",{className:te(lS({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 wf(e){return!!(e&&typeof e=="object"&&(e.type==="file"||e.mimeType||e.filename||e.sourceType==="base64"))}function ro(e){if(typeof e=="string")return e;if(e&&typeof e=="object"){if(Array.isArray(e)){const n=e.map(ro).filter(r=>r!==void 0);if(!n.length){console.debug("[message-utils] sanitizeForDisplay - array emptied -> returning undefined",{originalLength:e.length});return}return n}if(wf(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=ro(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 oo(e){if(typeof e=="string")return e;if(wf(e))return"";try{const t=ro(e);return t===void 0?"":typeof t=="string"?t:JSON.stringify(t,null,2)}catch{return""}}function cS(e){return typeof e!="string"?!1:/^[\s\n]*[-*]\s|^[\s\n]*#+\s|```|^\s*\[.*\]\(|^>\s/.test(e)}function uS(e){const t=oo(e);return typeof e=="string"&&cS(e)?{content:e,isMarkdown:!0}:{content:t,isMarkdown:!1}}function Ts(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 Ts(n)}return e}return typeof e=="object"&&!Array.isArray(e)&&e.content!==void 0?Ts(e.content):e}function dS(e){return e.filter(t=>t.type==="text").map(t=>t.text).join("")}function Sf(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 ks(e){if(e==null)return null;const t=String(e).trim();return t.length>0?t:null}function fS(e){const t=r=>{try{const o=ro(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 Ub(e,t=us){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 Hb(e){let t;return typeof e=="string"?t=e:typeof e=="object"&&e!==null?t=JSON.stringify(e):t=String(e),Ub(t),zb(t)}const ds=0,Rn=1,Sr=2,kd=4;function Ed(e){return()=>e}function Wb(e){e()}function Id(e,t){return n=>e(t(n))}function Ad(e,t){return()=>e(t)}function Vb(e,t){return n=>e(t,n)}function Qi(e){return e!==void 0}function Kb(...e){return()=>{e.map(Wb)}}function Cr(){}function fs(e,t){return t(e),e}function qb(e,t){return t(e)}function lt(...e){return e}function Ze(e,t){return e(Rn,t)}function Me(e,t){e(ds,t)}function ea(e){e(Sr)}function vt(e){return e(kd)}function ge(e,t){return Ze(e,Vb(t,ds))}function ln(e,t){const n=e(Rn,r=>{n(),t(r)});return n}function Nd(e){let t,n;return r=>o=>{t=o,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function _d(e,t){return e===t}function ct(e=_d){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function ke(e){return t=>n=>{e(n)&&t(n)}}function ue(e){return t=>Id(t,e)}function yn(e){return t=>()=>{t(e)}}function K(e,...t){const n=Gb(...t);return(r,o)=>{switch(r){case Sr:ea(e);return;case Rn:return Ze(e,n(o))}}}function vn(e,t){return n=>r=>{n(t=e(t,r))}}function Zn(e){return t=>n=>{e>0?e--:t(n)}}function An(e){let t=null,n;return r=>o=>{t=o,!n&&(n=setTimeout(()=>{n=void 0,r(t)},e))}}function Re(...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);Ze(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 Gb(...e){return t=>e.reduceRight(qb,t)}function Yb(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=Ze(e,s),t):(r(),Cr);case Sr:r(),n=null;return}}}function ee(e){let t=e;const n=Fe();return(r,o)=>{switch(r){case ds:t=o;break;case Rn:{o(t);break}case kd:return t}return n(r,o)}}function Nt(e,t){return fs(ee(t),n=>ge(e,n))}function Fe(){const e=[];return(t,n)=>{switch(t){case ds: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 Wt(e){return fs(Fe(),t=>ge(e,t))}function He(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:Xb(),singleton:n}}const Xb=()=>Symbol();function Jb(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 wt(...e){const t=Fe(),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);Ze(s,l=>{n[i]=l,r=r|a,r===o&&Me(t,n)})}),function(s,i){switch(s){case Sr:{ea(t);return}case Rn:return r===o&&i(n),Ze(t,i)}}}function Ce(e,t=_d){return K(e,ct(t))}function ta(...e){return function(t,n){switch(t){case Sr:return;case Rn:return Kb(...e.map(r=>Ze(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 Zb={0:"debug",3:"error",1:"log",2:"warn"},Qb=()=>typeof globalThis>"u"?window:globalThis,On=He(()=>{const e=ee(3);return{log:ee((t,n,r=1)=>{var o;const s=(o=Qb().VIRTUOSO_LOG_LEVEL)!=null?o:vt(e);r>=s&&console[Zb[r]]("%creact-virtuoso: %c%s %o","color: #0253b3; font-weight: bold","color: initial",t,n)}),logLevel:e}},[],{singleton:!0});function Qn(e,t,n){return na(e,t,n).callbackRef}function na(e,t,n){const r=b.useRef(null);let o=i=>{};const s=b.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 e0(e,t,n,r,o,s,i,a,l){const c=b.useCallback(d=>{const f=t0(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 g;h&&(g=p.ownerDocument.defaultView);const m=i?a?i.scrollLeft:i.scrollTop:h?a?g.scrollX||g.document.documentElement.scrollLeft:g.scrollY||g.document.documentElement.scrollTop:a?p.scrollLeft:p.scrollTop,y=i?a?i.scrollWidth:i.scrollHeight:h?a?g.document.documentElement.scrollWidth:g.document.documentElement.scrollHeight:a?p.scrollWidth:p.scrollHeight,x=i?a?i.offsetWidth:i.offsetHeight:h?a?g.innerWidth:g.innerHeight:a?p.offsetWidth:p.offsetHeight;r({scrollHeight:y,scrollTop:Math.max(m,0),viewportHeight:x}),s==null||s(a?jd("column-gap",getComputedStyle(d).columnGap,o):jd("row-gap",getComputedStyle(d).rowGap,o)),f!==null&&e(f)},[e,t,o,s,i,r,a]);return na(c,n,l)}function t0(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 jd(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 Md(e,t,n){const r=b.useRef(null),o=b.useCallback(l=>{if(!(l!=null&&l.offsetParent))return;const c=l.getBoundingClientRect(),d=c.width;let f,p;if(t){const h=t.getBoundingClientRect(),g=c.top-h.top;p=h.height-Math.max(0,g),f=g+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}=na(o,!0,n),a=b.useCallback(()=>{o(i.current)},[o,i]);return b.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 Lt=He(()=>{const e=Fe(),t=Fe(),n=ee(0),r=Fe(),o=ee(0),s=Fe(),i=Fe(),a=ee(0),l=ee(0),c=ee(0),d=ee(0),f=Fe(),p=Fe(),h=ee(!1),g=ee(!1),m=ee(!1);return ge(K(e,ue(({scrollTop:y})=>y)),t),ge(K(e,ue(({scrollHeight:y})=>y)),i),ge(t,o),{deviation:n,fixedFooterHeight:c,fixedHeaderHeight:l,footerHeight:d,headerHeight:a,horizontalDirection:g,scrollBy:p,scrollContainerState:e,scrollHeight:i,scrollingInProgress:h,scrollTo:f,scrollTop:t,skipAnimationFrameInResizeObserver:m,smoothScrollTargetReached:r,statefulScrollTop:o,viewportHeight:s}},[],{singleton:!0}),qr={lvl:0};function Pd(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 rt(e){return e===qr}function Gr(e,t){if(!rt(e))return t===e.k?e.v:t<e.k?Gr(e.l,t):Gr(e.r,t)}function cn(e,t,n="k"){if(rt(e))return[-1/0,void 0];if(Number(e[n])===t)return[e.k,e.v];if(Number(e[n])<t){const r=cn(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return cn(e.l,t,n)}function Vt(e,t,n){return rt(e)?Dd(t,n,1):t===e.k?bt(e,{k:t,v:n}):t<e.k?Ld(bt(e,{l:Vt(e.l,t,n)})):Ld(bt(e,{r:Vt(e.r,t,n)}))}function Tr(){return qr}function ps(e,t,n){if(rt(e))return[];const r=cn(e,t)[0];return n0(oa(e,r,n))}function ra(e,t){if(rt(e))return qr;const{k:n,l:r,r:o}=e;if(t===n){if(rt(r))return o;if(rt(o))return r;{const[s,i]=Od(r);return hs(bt(e,{k:s,l:Rd(r),v:i}))}}else return t<n?hs(bt(e,{l:ra(r,t)})):hs(bt(e,{r:ra(o,t)}))}function er(e){return rt(e)?[]:[...er(e.l),{k:e.k,v:e.v},...er(e.r)]}function oa(e,t,n){if(rt(e))return[];const{k:r,l:o,r:s,v:i}=e;let a=[];return r>t&&(a=a.concat(oa(o,t,n))),r>=t&&r<=n&&a.push({k:r,v:i}),r<=n&&(a=a.concat(oa(s,t,n))),a}function hs(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(sa(t))return $d(bt(e,{lvl:n-1}));if(!rt(t)&&!rt(t.r))return bt(t.r,{l:bt(t,{r:t.r.l}),lvl:n,r:bt(e,{l:t.r.r,lvl:n-1})});throw new Error("Unexpected empty nodes")}else{if(sa(e))return ia(bt(e,{lvl:n-1}));if(!rt(r)&&!rt(r.l)){const o=r.l,s=sa(o)?r.lvl-1:r.lvl;return bt(o,{l:bt(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:ia(bt(r,{l:o.r,lvl:s}))})}else throw new Error("Unexpected empty nodes")}}function bt(e,t){return Dd(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 Rd(e){return rt(e.r)?e.l:hs(bt(e,{r:Rd(e.r)}))}function sa(e){return rt(e)||e.lvl>e.r.lvl}function Od(e){return rt(e.r)?[e.k,e.v]:Od(e.r)}function Dd(e,t,n,r=qr,o=qr){return{k:e,l:r,lvl:n,r:o,v:t}}function Ld(e){return ia($d(e))}function $d(e){const{l:t}=e;return!rt(t)&&t.lvl===e.lvl?bt(t,{r:bt(e,{l:t.r})}):e}function ia(e){const{lvl:t,r:n}=e;return!rt(n)&&!rt(n.r)&&n.lvl===t&&n.r.lvl===t?bt(n,{l:bt(e,{r:n.l}),lvl:t+1}):e}function n0(e){return Pd(e,({k:t,v:n})=>({index:t,value:n}))}function Fd(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function Yr(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}const aa=He(()=>({recalcInProgress:ee(!1)}),[],{singleton:!0});function Bd(e,t,n){return e[ms(e,t,n)]}function ms(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 r0(e,t,n,r){const o=ms(e,t,r),s=ms(e,n,r,o);return e.slice(o,s+1)}function Dn(e,t){return Math.round(e.getBoundingClientRect()[t])}function gs(e){return!rt(e.groupOffsetTree)}function la({index:e},t){return t===e?0:t<e?-1:1}function o0(){return{groupIndices:[],groupOffsetTree:Tr(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:Tr()}}function s0(e,t){let n=rt(e)?0:1/0;for(const r of t){const{endIndex:o,size:s,startIndex:i}=r;if(n=Math.min(n,i),rt(e)){e=Vt(e,0,s);continue}const a=ps(e,i-1,o+1);if(a.some(f0(r)))continue;let l=!1,c=!1;for(const{end:d,start:f,value:p}of a)l?(o>=f||s===p)&&(e=ra(e,f)):(c=p!==s,l=!0),d>o&&o>=f&&p!==s&&(e=Vt(e,o+1,p));c&&(e=Vt(e,i,s))}return[e,n]}function i0(e){return typeof e.groupIndex<"u"}function a0({offset:e},t){return t===e?0:t<e?-1:1}function Xr(e,t,n){if(t.length===0)return 0;const{index:r,offset:o,size:s}=Bd(t,e,la),i=e-r,a=s*i+(i-1)*n+o;return a>0?a+n:a}function zd(e,t){if(!gs(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function Ud(e,t,n){if(i0(e))return t.groupIndices[e.groupIndex]+1;{const r=e.index==="LAST"?n:e.index;let o=zd(r,t);return o=Math.max(0,o,Math.min(n,o)),o}}function l0(e,t,n,r=0){return r>0&&(t=Math.max(t,Bd(e,r,la).offset)),Pd(r0(e,t,n,a0),d0)}function c0(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&&rt(s)&&t.length===2){const p=t[0].size,h=t[1].size;i=n.reduce((g,m)=>Vt(Vt(g,m,p),m+1,h),i)}else[i,a]=s0(i,t);if(i===s)return e;const{lastIndex:l,lastOffset:c,lastSize:d,offsetTree:f}=ca(e.offsetTree,a,i,o);return{groupIndices:n,groupOffsetTree:n.reduce((p,h)=>Vt(p,h,Xr(h,f,o)),Tr()),lastIndex:l,lastOffset:c,lastSize:d,offsetTree:f,sizeTree:i}}function u0(e){return er(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 Hd(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 ca(e,t,n,r){let o=e,s=0,i=0,a=0,l=0;if(t!==0){l=ms(o,t-1,la),a=o[l].offset;const c=cn(n,t-1);s=c[0],i=c[1],o.length&&o[l].size===cn(n,t)[1]&&(l-=1),o=o.slice(0,l+1)}else o=[];for(const{start:c,value:d}of ps(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 d0(e){return{index:e.index,value:e}}function f0(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 p0={offsetHeight:"height",offsetWidth:"width"},wn=He(([{log:e},{recalcInProgress:t}])=>{const n=Fe(),r=Fe(),o=Nt(r,0),s=Fe(),i=Fe(),a=ee(0),l=ee([]),c=ee(void 0),d=ee(void 0),f=ee((C,T)=>Dn(C,p0[T])),p=ee(void 0),h=ee(0),g=o0(),m=Nt(K(n,Re(l,e,h),vn(c0,g),ct()),g),y=Nt(K(l,ct(),vn((C,T)=>({current:T,prev:C.current}),{current:[],prev:[]}),ue(({prev:C})=>C)),[]);ge(K(l,ke(C=>C.length>0),Re(m,h),ue(([C,T,E])=>{const N=C.reduce((_,D,B)=>Vt(_,D,Xr(D,T.offsetTree,E)||B),Tr());return{...T,groupIndices:C,groupOffsetTree:N}})),m),ge(K(r,Re(m),ke(([C,{lastIndex:T}])=>C<T),ue(([C,{lastIndex:T,lastSize:E}])=>[{endIndex:T,size:E,startIndex:C}])),n),ge(c,d);const x=Nt(K(c,ue(C=>C===void 0)),!0);ge(K(d,ke(C=>C!==void 0&&rt(vt(m).sizeTree)),ue(C=>[{endIndex:0,size:C,startIndex:0}])),n);const w=Wt(K(n,Re(m),vn(({sizes:C},[T,E])=>({changed:E!==C,sizes:E}),{changed:!1,sizes:g}),ue(C=>C.changed)));Ze(K(a,vn((C,T)=>({diff:C.prev-T,prev:T}),{diff:0,prev:0}),ue(C=>C.diff)),C=>{const{groupIndices:T}=vt(m);if(C>0)Me(t,!0),Me(s,C+Hd(C,T));else if(C<0){const E=vt(y);E.length>0&&(C-=Hd(-C,E)),Me(i,C)}}),Ze(K(a,Re(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=Wt(s);ge(K(s,Re(m),ue(([C,T])=>{const E=T.groupIndices.length>0,N=[],_=T.lastSize;if(E){const D=Gr(T.sizeTree,0);let B=0,G=0;for(;B<C;){const P=T.groupIndices[G],M=T.groupIndices.length===G+1?1/0:T.groupIndices[G+1]-P-1;N.push({endIndex:P,size:D,startIndex:P}),N.push({endIndex:P+1+M-1,size:_,startIndex:P+1}),G++,B+=M+1}const V=er(T.sizeTree);return B!==C&&V.shift(),V.reduce((P,{k:M,v:A})=>{let F=P.ranges;return P.prevSize!==0&&(F=[...P.ranges,{endIndex:M+C-1,size:P.prevSize,startIndex:P.prevIndex}]),{prevIndex:M+C,prevSize:A,ranges:F}},{prevIndex:C,prevSize:0,ranges:N}).ranges}return er(T.sizeTree).reduce((D,{k:B,v:G})=>({prevIndex:B+C,prevSize:G,ranges:[...D.ranges,{endIndex:B+C-1,size:D.prevSize,startIndex:D.prevIndex}]}),{prevIndex:0,prevSize:_,ranges:[]}).ranges})),n);const k=Wt(K(i,Re(m,h),ue(([C,{offsetTree:T},E])=>{const N=-C;return Xr(N,T,E)})));return ge(K(i,Re(m,h),ue(([C,T,E])=>{if(T.groupIndices.length>0){if(rt(T.sizeTree))return T;let N=Tr();const _=vt(y);let D=0,B=0,G=0;for(;D<-C;){G=_[B];const V=_[B+1]-G-1;B++,D+=V+1}if(N=er(T.sizeTree).reduce((V,{k:P,v:M})=>Vt(V,Math.max(0,P+C),M),N),D!==-C){const V=Gr(T.sizeTree,G);N=Vt(N,0,V);const P=cn(T.sizeTree,-C+1)[1];N=Vt(N,1,P)}return{...T,sizeTree:N,...ca(T.offsetTree,0,N,E)}}else{const N=er(T.sizeTree).reduce((_,{k:D,v:B})=>Vt(_,Math.max(0,D+C),B),Tr());return{...T,sizeTree:N,...ca(T.offsetTree,0,N,E)}}})),m),{beforeUnshiftWith:S,data:p,defaultItemSize:d,firstItemIndex:a,fixedItemSize:c,gap:h,groupIndices:l,itemSize:f,listRefresh:w,shiftWith:i,shiftWithOffset:k,sizeRanges:n,sizes:m,statefulTotalCount:o,totalCount:r,trackItemSizes:x,unshiftWith:s}},lt(On,aa),{singleton:!0});function h0(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const Wd=He(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=Fe(),i=Fe(),a=Wt(K(s,ue(h0)));return ge(K(a,ue(l=>l.totalCount)),n),ge(K(a,ue(l=>l.groupIndices)),e),ge(K(wt(o,t,r),ke(([l,c])=>gs(c)),ue(([l,c,d])=>cn(c.groupOffsetTree,Math.max(l-d,0),"v")[0]),ct(),ue(l=>[l])),i),{groupCounts:s,topItemsIndexes:i}},lt(wn,Lt)),Ln=He(([{log:e}])=>{const t=ee(!1),n=Wt(K(t,ke(r=>r),ct()));return Ze(t,r=>{r&&vt(e)("props updated",{},Bt.DEBUG)}),{didMount:n,propsReady:t}},lt(On),{singleton:!0}),m0=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function Vd(e){const t=typeof e=="number"?{index:e}:e;return t.align||(t.align="start"),(!t.behavior||!m0)&&(t.behavior="auto"),t.offset||(t.offset=0),t}const Jr=He(([{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=Fe(),g=Fe(),m=ee(0);let y=null,x=null,w=null;function S(){y&&(y(),y=null),w&&(w(),w=null),x&&(clearTimeout(x),x=null),Me(l,!1)}return ge(K(h,Re(n,f,r,m,a,i,p),Re(e,s,o),ue(([[k,C,T,E,N,_,D,B],G,V,P])=>{const M=Vd(k),{align:A,behavior:F,offset:L}=M,R=E-1,z=Ud(M,C,R);let X=Xr(z,C.offsetTree,G)+_;A==="end"?(X+=V+cn(C.sizeTree,z)[1]-T+P,z===R&&(X+=D)):A==="center"?X+=(V+cn(C.sizeTree,z)[1]-T+P)/2:X-=N,L&&(X+=L);const ne=ye=>{S(),ye?(B("retrying to scroll to",{location:k},Bt.DEBUG),Me(h,k)):(Me(g,!0),B("list did not change, scroll successful",{},Bt.DEBUG))};if(S(),F==="smooth"){let ye=!1;w=Ze(t,Te=>{ye=ye||Te}),y=ln(d,()=>{ne(ye)})}else y=ln(K(t,g0(150)),ne);return x=setTimeout(()=>{S()},1200),Me(l,!0),B("scrolling from index to",{behavior:F,index:z,top:X},Bt.DEBUG),{behavior:F,top:X}})),c),{scrollTargetReached:g,scrollToIndex:h,topListHeight:m}},lt(wn,Lt,On),{singleton:!0});function g0(e){return t=>{const n=setTimeout(()=>{t(!1)},e);return r=>{r&&(t(!0),clearTimeout(n))}}}function ua(e,t){e==0?t():requestAnimationFrame(()=>{ua(e-1,t)})}function da(e,t){const n=t-1;return typeof e=="number"?e:e.index==="LAST"?n:e.index}const Zr=He(([{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 ge(K(i,Re(l),ke(([d,f])=>!!f),yn(!1)),a),ge(K(i,Re(l),ke(([d,f])=>!!f),yn(!1)),c),Ze(K(wt(t,i),Re(a,n,e,c),ke(([[,d],f,{sizeTree:p},h,g])=>d&&(!rt(p)||Qi(h))&&!f&&!g),Re(l)),([,d])=>{ln(o,()=>{Me(c,!0)}),ua(4,()=>{ln(r,()=>{Me(a,!0)}),Me(s,d)})}),{initialItemFinalLocationReached:c,initialTopMostItemIndex:l,scrolledToInitialItem:a}},lt(wn,Lt,Jr,Ln),{singleton:!0});function Kd(e,t){return Math.abs(e-t)<1.01}const Qr="up",eo="down",x0="none",y0={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},v0=0,to=He(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:o,viewportHeight:s}])=>{const i=ee(!1),a=ee(!0),l=Fe(),c=Fe(),d=ee(4),f=ee(v0),p=Nt(K(ta(K(Ce(o),Zn(1),yn(!0)),K(Ce(o),Zn(1),yn(!1),Nd(100))),ct()),!1),h=Nt(K(ta(K(n,yn(!0)),K(n,yn(!1),Nd(200))),ct()),!1);ge(K(wt(Ce(o),Ce(f)),ue(([w,S])=>w<=S),ct()),a),ge(K(a,An(50)),c);const g=Wt(K(wt(r,Ce(s),Ce(t),Ce(e),Ce(d)),vn((w,[{scrollHeight:S,scrollTop:k},C,T,E,N])=>{const _=k+C-S>-N,D={scrollHeight:S,scrollTop:k,viewportHeight:C};if(_){let G,V;return k>w.state.scrollTop?(G="SCROLLED_DOWN",V=w.state.scrollTop-k):(G="SIZE_DECREASED",V=w.state.scrollTop-k||w.scrollTopDelta),{atBottom:!0,atBottomBecause:G,scrollTopDelta:V,state:D}}let B;return D.scrollHeight>w.state.scrollHeight?B="SIZE_INCREASED":C<w.state.viewportHeight?B="VIEWPORT_HEIGHT_DECREASING":k<w.state.scrollTop?B="SCROLLING_UPWARDS":B="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:B,state:D}},y0),ct((w,S)=>w&&w.atBottom===S.atBottom))),m=Nt(K(r,vn((w,{scrollHeight:S,scrollTop:k,viewportHeight:C})=>{if(Kd(w.scrollHeight,S))return{changed:!1,jump:0,scrollHeight:S,scrollTop:k};{const T=S-(k+C)<1;return w.scrollTop!==k&&T?{changed:!0,jump:w.scrollTop-k,scrollHeight:S,scrollTop:k}:{changed:!0,jump:0,scrollHeight:S,scrollTop:k}}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),ke(w=>w.changed),ue(w=>w.jump)),0);ge(K(g,ue(w=>w.atBottom)),i),ge(K(i,An(50)),l);const y=ee(eo);ge(K(r,ue(({scrollTop:w})=>w),ct(),vn((w,S)=>vt(h)?{direction:w.direction,prevScrollTop:S}:{direction:S<w.prevScrollTop?Qr:eo,prevScrollTop:S},{direction:eo,prevScrollTop:0}),ue(w=>w.direction)),y),ge(K(r,An(50),yn(x0)),y);const x=ee(0);return ge(K(p,ke(w=>!w),yn(0)),x),ge(K(o,An(100),Re(p),ke(([w,S])=>!!S),vn(([w,S],[k])=>[S,k],[0,0]),ue(([w,S])=>S-w)),x),{atBottomState:g,atBottomStateChange:l,atBottomThreshold:d,atTopStateChange:c,atTopThreshold:f,isAtBottom:i,isAtTop:a,isScrolling:p,lastJumpDueToItemResize:m,scrollDirection:y,scrollVelocity:x}},lt(Lt)),xs="top",ys="bottom",qd="none";function Gd(e,t,n){return typeof e=="number"?n===Qr&&t===xs||n===eo&&t===ys?e:0:n===Qr?t===xs?e.main:e.reverse:t===ys?e.main:e.reverse}function Yd(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const fa=He(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:o}])=>{const s=Fe(),i=ee(0),a=ee(0),l=ee(0),c=Nt(K(wt(Ce(r),Ce(o),Ce(n),Ce(s,Yr),Ce(l),Ce(i),Ce(t),Ce(e),Ce(a)),ue(([d,f,p,[h,g],m,y,x,w,S])=>{const k=d-w,C=y+x,T=Math.max(p-k,0);let E=qd;const N=Yd(S,xs),_=Yd(S,ys);return h-=w,h+=p+x,g+=p+x,g-=w,h>d+C-N&&(E=Qr),g<d-T+f+_&&(E=eo),E!==qd?[Math.max(k-p-Gd(m,xs,E)-N,0),k-T-x+f+Gd(m,ys,E)+_]:null}),ke(d=>d!=null),ct(Yr)),[0,0]);return{increaseViewportBy:a,listBoundary:s,overscan:l,topListHeight:i,visibleRange:c}},lt(Lt),{singleton:!0});function w0(e,t,n){if(gs(t)){const r=zd(e,t);return[{index:cn(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 pa={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function vs(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 m=e[e.length-1];d=m.offset+m.size}const f=n-i,p=a+f*l+(f-1)*r,h=c,g=p-d;return{bottom:d,firstItemIndex:s,items:Jd(e,o,s),offsetBottom:g,offsetTop:c,top:h,topItems:Jd(t,o,s),topListHeight:t.reduce((m,y)=>y.size+m,0),totalCount:n}}function Xd(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=da(t,a),c=Array.from({length:a}).map((d,f)=>({data:s[f+l],index:f+l,offset:0,size:0}));return vs(c,[],a,o,n,r)}function Jd(e,t,n){if(e.length===0)return[];if(!gs(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=ps(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 tr=He(([{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:g}])=>{const m=ee([]),y=ee(0),x=Fe();ge(s.topItemsIndexes,m);const w=Nt(K(wt(h,g,Ce(l,Yr),Ce(o),Ce(r),Ce(c),d,Ce(m),Ce(t),Ce(n),e),ke(([T,E,,N,,,,,,,_])=>{const D=_&&_.length!==N;return T&&!E&&!D}),ue(([,,[T,E],N,_,D,B,G,V,P,M])=>{const A=_,{offsetTree:F,sizeTree:L}=A,R=vt(y);if(N===0)return{...pa,totalCount:N};if(T===0&&E===0)return R===0?{...pa,totalCount:N}:Xd(R,D,_,V,P,M||[]);if(rt(L))return R>0?null:vs(w0(da(D,N),A,M),[],N,P,A,V);const z=[];if(G.length>0){const q=G[0],U=G[G.length-1];let Z=0;for(const $ of ps(L,q,U)){const Y=$.value,Q=Math.max($.start,q),de=Math.min($.end,U);for(let oe=Q;oe<=de;oe++)z.push({data:M==null?void 0:M[oe],index:oe,offset:Z,size:Y}),Z+=Y}}if(!B)return vs([],z,N,P,A,V);const X=G.length>0?G[G.length-1]+1:0,ne=l0(F,T,E,X);if(ne.length===0)return null;const ye=N-1,Te=fs([],q=>{for(const U of ne){const Z=U.value;let $=Z.offset,Y=U.start;const Q=Z.size;if(Z.offset<T){Y+=Math.floor((T-Z.offset+P)/(Q+P));const oe=Y-U.start;$+=oe*Q+oe*P}Y<X&&($+=(X-Y)*Q,Y=X);const de=Math.min(U.end,ye);for(let oe=Y;oe<=de&&!($>=E);oe++)q.push({data:M==null?void 0:M[oe],index:oe,offset:$,size:Q}),$+=Q+P}});return vs(Te,z,N,P,A,V)}),ke(T=>T!==null),ct()),pa);ge(K(e,ke(Qi),ue(T=>T==null?void 0:T.length)),o),ge(K(w,ue(T=>T.topListHeight)),f),ge(f,a),ge(K(w,ue(T=>[T.top,T.bottom])),i),ge(K(w,ue(T=>T.items)),x);const S=Wt(K(w,ke(({items:T})=>T.length>0),Re(o,e),ke(([{items:T},E])=>T[T.length-1].originalIndex===E-1),ue(([,T,E])=>[T-1,E]),ct(Yr),ue(([T])=>T))),k=Wt(K(w,An(200),ke(({items:T,topItems:E})=>T.length>0&&T[0].originalIndex===E.length),ue(({items:T})=>T[0].index),ct())),C=Wt(K(w,ke(({items:T})=>T.length>0),ue(({items:T})=>{let E=0,N=T.length-1;for(;T[E].type==="group"&&E<N;)E++;for(;T[N].type==="group"&&N>E;)N--;return{endIndex:T[N].index,startIndex:T[E].index}}),ct(Fd)));return{endReached:S,initialItemCount:y,itemsRendered:x,listState:w,rangeChanged:C,startReached:k,topItemsIndexes:m,...p}},lt(wn,Wd,fa,Zr,Jr,to,Ln,aa),{singleton:!0}),Zd=He(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:o}])=>{const s=Fe(),i=Nt(K(wt(n,e,r,t,o),ue(([a,l,c,d,f])=>a+l+c+d+f.offsetBottom+f.bottom)),0);return ge(Ce(i),s),{totalListHeight:i,totalListHeightChanged:s}},lt(Lt,tr),{singleton:!0}),b0=He(([{viewportHeight:e},{totalListHeight:t}])=>{const n=ee(!1),r=Nt(K(wt(n,e,t),ke(([o])=>o),ue(([,o,s])=>Math.max(0,o-s)),An(0),ct()),0);return{alignToBottom:n,paddingTopAddition:r}},lt(Lt,Zd),{singleton:!0}),Qd=He(()=>({context:ee(null)})),S0=({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,ef=He(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:s,scrollingInProgress:i,scrollTop:a,viewportHeight:l},{scrollToIndex:c}])=>{const d=Fe();return ge(K(d,Re(t,l,n,s,o,r,a),Re(e),ue(([[f,p,h,g,m,y,x,w],S])=>{const{align:k,behavior:C,calculateViewLocation:T=S0,done:E,...N}=f,_=Ud(f,p,g-1),D=Xr(_,p.offsetTree,S)+m+y,B=D+cn(p.sizeTree,_)[1],G=w+y,V=w+h-x,P=T({itemBottom:B,itemTop:D,locationParams:{align:k,behavior:C,...N},viewportBottom:V,viewportTop:G});return P?E&&ln(K(i,ke(M=>!M),Zn(vt(i)?1:2)),E):E&&E(),P}),ke(f=>f!==null)),c),{scrollIntoView:d}},lt(wn,Lt,Jr,tr,On),{singleton:!0});function tf(e){return e?e==="smooth"?"smooth":"auto":!1}const C0=(e,t)=>typeof e=="function"?tf(e(t)):t&&tf(e),T0=He(([{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 g=ee(!1),m=Fe();let y=null;function x(C){Me(i,{align:"end",behavior:C,index:"LAST"})}Ze(K(wt(K(Ce(t),Zn(1)),l),Re(Ce(g),s,a,f),ue(([[C,T],E,N,_,D])=>{let B=T&&_,G="auto";return B&&(G=C0(E,N||D),B=B&&!!G),{followOutputBehavior:G,shouldFollow:B,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=ln(e,()=>{vt(d)("following output to ",{totalCount:T},Bt.DEBUG),x(C),y=null})});function w(C){const T=ln(o,E=>{C&&!E.atBottom&&E.notAtBottomBecause==="SIZE_INCREASED"&&!y&&(vt(d)("scrolling to bottom due to increased size",{},Bt.DEBUG),x("auto"))});setTimeout(T,100)}Ze(K(wt(Ce(g),t,c),ke(([C,,T])=>C&&T),vn(({value:C},[,T])=>({refreshed:C===T,value:T}),{refreshed:!1,value:0}),ke(({refreshed:C})=>C),Re(g,t)),([,C])=>{vt(a)&&w(C!==!1)}),Ze(m,()=>{w(vt(g)!==!1)}),Ze(wt(Ce(g),o),([C,T])=>{C&&!T.atBottom&&T.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&x("auto")});const S=ee(null),k=Fe();return ge(ta(K(Ce(r),ue(C=>{var T;return(T=C==null?void 0:C.length)!=null?T:0})),K(Ce(t))),k),Ze(K(wt(K(k,Zn(1)),l),Re(Ce(S),a,f,p),ue(([[C,T],E,N,_,D])=>T&&N&&(E==null?void 0:E({context:D,totalCount:C,scrollingInProgress:_}))),ke(C=>!!C),An(0)),C=>{y&&(y(),y=null),vt(n)?requestAnimationFrame(()=>{vt(d)("scrolling into view",{}),Me(h,C)}):y=ln(e,()=>{vt(d)("scrolling into view",{}),Me(h,C),y=null})}),{autoscrollToBottom:m,followOutput:g,scrollIntoViewOnChange:S}},lt(wn,to,Jr,Zr,Ln,On,Lt,Qd,ef)),k0=He(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:s,listState:i},{didMount:a}])=>(ge(K(a,Re(s),ke(([,l])=>l!==0),Re(o,r,t,n,e),ue(([[,l],c,d,f,p,h=[]])=>Xd(l,c,d,f,p,h))),i),{}),lt(wn,Zr,tr,Ln),{singleton:!0}),E0=He(([{didMount:e},{scrollTo:t},{listState:n}])=>{const r=ee(0);return Ze(K(e,Re(r),ke(([,o])=>o!==0),ue(([,o])=>({top:o}))),o=>{ln(K(n,Zn(1),ke(s=>s.items.length>1)),()=>{requestAnimationFrame(()=>{Me(t,o)})})}),{initialScrollTop:r}},lt(Ln,Lt,tr),{singleton:!0}),nf=He(([{scrollVelocity:e}])=>{const t=ee(!1),n=Fe(),r=ee(!1);return ge(K(e,Re(r,t,n),ke(([o,s])=>!!s),ue(([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),Ze(K(wt(t,e,n),Re(r)),([[o,s,i],a])=>{o&&a&&a.change&&a.change(s,i)}),{isSeeking:t,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:e}},lt(to),{singleton:!0}),ha=He(([{scrollContainerState:e,scrollTo:t}])=>{const n=Fe(),r=Fe(),o=Fe(),s=ee(!1),i=ee(void 0);return ge(K(wt(n,r),ue(([{scrollHeight:a,scrollTop:l,viewportHeight:c},{offsetTop:d}])=>({scrollHeight:a,scrollTop:Math.max(0,l-d),viewportHeight:c}))),e),ge(K(t,Re(r),ue(([a,{offsetTop:l}])=>({...a,top:a.top+l}))),o),{customScrollParent:i,useWindowScroll:s,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:r}},lt(Lt)),I0=He(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:o},{didMount:s},{useWindowScroll:i,windowScrollContainerState:a,windowViewportRect:l}])=>{const c=Fe(),d=ee(void 0),f=ee(null),p=ee(null);return ge(a,f),ge(l,p),Ze(K(c,Re(t,r,i,f,p,n)),([h,g,m,y,x,w,S])=>{const k=u0(g.sizeTree);y&&x!==null&&w!==null&&(m=x.scrollTop-w.offsetTop),m-=S,h({ranges:k,scrollTop:m})}),ge(K(d,ke(Qi),ue(A0)),o),ge(K(s,Re(d),ke(([,h])=>h!==void 0),ct(),ue(([,h])=>h.ranges)),e),{getState:c,restoreStateFrom:d}},lt(wn,Lt,Zr,Ln,ha));function A0(e){return{align:"start",index:0,offset:e.scrollTop}}const N0=He(([{topItemsIndexes:e}])=>{const t=ee(0);return ge(K(t,ke(n=>n>=0),ue(n=>Array.from({length:n}).map((r,o)=>o))),e),{topItemCount:t}},lt(tr));function rf(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const _0=rf(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),j0=He(([{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:g}])=>{const m=Wt(K(l,Re(i),vn(([,x,w,S],[{bottom:k,items:C,offsetBottom:T,totalCount:E},N])=>{const _=k+T;let D=0;return w===E&&x.length>0&&C.length>0&&(C[0].originalIndex===0&&x[0].originalIndex===0||(D=_-S,D!==0&&(D+=N))),[D,C,E,_]},[0,[],0,0]),ke(([x])=>x!==0),Re(r,a,n,o,h,g),ke(([,x,w,S,,,k])=>!k&&!S&&x!==0&&w===Qr),ue(([[x],,,,,w])=>(w("Upward scrolling compensation",{amount:x},Bt.DEBUG),x))));function y(x){x>0?(Me(t,{behavior:"auto",top:-x}),Me(e,0)):(Me(e,0),Me(t,{behavior:"auto",top:-x}))}return Ze(K(m,Re(e,s)),([x,w,S])=>{S&&_0()?Me(e,w-x):y(-x)}),Ze(K(wt(Nt(s,!1),e,g),ke(([x,w,S])=>!x&&!S&&w!==0),ue(([x,w])=>w),An(1)),y),ge(K(f,ue(x=>({top:-x}))),t),Ze(K(c,Re(p,d),ue(([x,{groupIndices:w,lastSize:S,sizeTree:k},C])=>{function T(E){return E*(S+C)}if(w.length===0)return T(x);{let E=0;const N=Gr(k,0);let _=0,D=0;for(;_<x;){_++,E+=N;let B=w.length===D+1?1/0:w[D+1]-w[D]-1;_+B>x&&(E-=N,B=x-_+1),_+=B,E+=T(B),D++}return E}})),x=>{Me(e,x),requestAnimationFrame(()=>{Me(t,{top:x}),requestAnimationFrame(()=>{Me(e,0),Me(g,!1)})})}),{deviation:e}},lt(Lt,to,tr,wn,On,aa)),M0=He(([e,t,n,r,o,s,i,a,l,c,d])=>({...e,...t,...n,...r,...o,...s,...i,...a,...l,...c,...d}),lt(fa,k0,Ln,nf,Zd,E0,b0,ha,ef,On,Qd)),of=He(([{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:g},m,y,x,{listState:w,topItemsIndexes:S,...k},{scrollToIndex:C},T,{topItemCount:E},{groupCounts:N},_])=>(ge(k.rangeChanged,_.scrollSeekRangeChanged),ge(K(_.windowViewportRect,ue(D=>D.visibleHeight)),m.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:n,fixedItemHeight:r,gap:o,groupCounts:N,initialItemFinalLocationReached:p,initialTopMostItemIndex:h,scrolledToInitialItem:g,sizeRanges:a,topItemCount:E,topItemsIndexes:S,totalCount:d,...x,groupIndices:s,itemSize:i,listState:w,scrollToIndex:C,statefulTotalCount:c,trackItemSizes:f,...k,..._,...m,sizes:l,...y}),lt(wn,Zr,Lt,I0,T0,tr,Jr,j0,N0,Wd,M0));function P0(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 ws=typeof document<"u"?b.useLayoutEffect:b.useEffect;function sf(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=b.createContext({});function l(y,x){y.propsReady&&Me(y.propsReady,!1);for(const w of r){const S=y[t.required[w]];Me(S,x[w])}for(const w of o)if(w in x){const S=y[t.optional[w]];Me(S,x[w])}y.propsReady&&Me(y.propsReady,!0)}function c(y){return s.reduce((x,w)=>(x[w]=S=>{const k=y[t.methods[w]];Me(k,S)},x),{})}function d(y){return i.reduce((x,w)=>(x[w]=Yb(y[t.events[w]]),x),{})}const f=b.forwardRef((y,x)=>{const{children:w,...S}=y,[k]=b.useState(()=>fs(Jb(e),E=>{l(E,S)})),[C]=b.useState(Ad(d,k));ws(()=>{for(const E of i)E in S&&Ze(C[E],S[E]);return()=>{Object.values(C).map(ea)}},[S,C,k]),ws(()=>{l(k,S)}),b.useImperativeHandle(x,Ed(c(k)));const T=n;return u.jsx(a.Provider,{value:k,children:n?u.jsx(T,{...P0([...r,...o,...i],S),children:w}):w})}),p=y=>{const x=b.useContext(a);return b.useCallback(w=>{Me(x[y],w)},[x,y])},h=y=>{const x=b.useContext(a)[y],w=b.useCallback(S=>Ze(x,S),[x]);return b.useSyncExternalStore(w,()=>vt(x),()=>vt(x))},g=y=>{const x=b.useContext(a)[y],[w,S]=b.useState(Ad(vt,x));return ws(()=>Ze(x,k=>{k!==w&&S(Ed(k))}),[x,w]),w},m=b.version.startsWith("18")?h:g;return{Component:f,useEmitter:(y,x)=>{const w=b.useContext(a)[y];ws(()=>Ze(w,x),[x,w])},useEmitterValue:m,usePublisher:p}}const af=b.createContext(void 0),lf=b.createContext(void 0),cf=typeof document<"u"?b.useLayoutEffect:b.useEffect;function ma(e){return"self"in e}function R0(e){return"body"in e}function uf(e,t,n,r=Cr,o,s){const i=b.useRef(null),a=b.useRef(null),l=b.useRef(null),c=b.useCallback(p=>{let h,g,m;const y=p.target;if(R0(y)||ma(y)){const w=ma(y)?y:y.defaultView;m=s?w.scrollX:w.scrollY,h=s?w.document.documentElement.scrollWidth:w.document.documentElement.scrollHeight,g=s?w.innerWidth:w.innerHeight}else m=s?y.scrollLeft:y.scrollTop,h=s?y.scrollWidth:y.scrollHeight,g=s?y.offsetWidth:y.offsetHeight;const x=()=>{e({scrollHeight:h,scrollTop:Math.max(m,0),viewportHeight:g})};p.suppressFlushSync?x():Ys.flushSync(x),a.current!==null&&(m===a.current||m<=0||m===h-g)&&(a.current=null,t(!0),l.current&&(clearTimeout(l.current),l.current=null))},[e,t,s]);b.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 g=p.behavior==="smooth";let m,y,x;ma(h)?(y=Math.max(Dn(h.document.documentElement,s?"width":"height"),s?h.document.documentElement.scrollWidth:h.document.documentElement.scrollHeight),m=s?h.innerWidth:h.innerHeight,x=s?window.scrollX:window.scrollY):(y=h[s?"scrollWidth":"scrollHeight"],m=Dn(h,s?"width":"height"),x=h[s?"scrollLeft":"scrollTop"]);const w=y-m;if(p.top=Math.ceil(Math.max(Math.min(w,p.top),0)),Kd(m,y)||p.top===x){e({scrollHeight:y,scrollTop:x,viewportHeight:m}),g&&t(!0);return}g?(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 ga="-webkit-sticky",df="sticky",xa=rf(()=>{if(typeof document>"u")return df;const e=document.createElement("div");return e.style.position=ga,e.style.position===ga?ga:df});function ya(e){return e}const O0=He(()=>{const e=ee(a=>`Item ${a}`),t=ee(a=>`Group ${a}`),n=ee({}),r=ee(ya),o=ee("div"),s=ee(Cr),i=(a,l=null)=>Nt(K(n,ue(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")}}),D0=He(([e,t])=>({...e,...t}),lt(of,O0)),L0=({height:e})=>u.jsx("div",{style:{height:e}}),$0={overflowAnchor:"none",position:xa(),zIndex:1},ff={overflowAnchor:"none"},F0={...ff,display:"inline-block",height:"100%"},pf=b.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"),p=Ae("itemSize"),h=Ae("log"),g=Zt("gap"),m=Ae("horizontalDirection"),{callbackRef:y}=e0(n,p,f,e?Cr:a,h,g,o,m,Ae("skipAnimationFrameInResizeObserver")),[x,w]=b.useState(0);va("deviation",P=>{x!==P&&w(P)});const S=Ae("EmptyPlaceholder"),k=Ae("ScrollSeekPlaceholder")||L0,C=Ae("ListComponent"),T=Ae("ItemComponent"),E=Ae("GroupComponent"),N=Ae("computeItemKey"),_=Ae("isSeeking"),D=Ae("groupIndices").length>0,B=Ae("alignToBottom"),G=Ae("initialItemFinalLocationReached"),V=e?{}:{boxSizing:"border-box",...m?{display:"inline-block",height:"100%",marginLeft:x!==0?x:B?"auto":0,paddingLeft:t.offsetTop,paddingRight:t.offsetBottom,whiteSpace:"nowrap"}:{marginTop:x!==0?x:B?"auto":0,paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},...G?{}:{visibility:"hidden"}};return!e&&t.totalCount===0&&S?u.jsx(S,{..._t(S,c)}):u.jsx(C,{..._t(C,c),"data-testid":e?"virtuoso-top-item-list":"virtuoso-item-list",ref:y,style:V,children:(e?t.topItems:t.items).map(P=>{const M=P.originalIndex,A=N(M+t.firstItemIndex,P.data,c);return _?b.createElement(k,{..._t(k,c),height:P.size,index:P.index,key:A,type:P.type||"item",...P.type==="group"?{}:{groupIndex:P.groupIndex}}):P.type==="group"?b.createElement(E,{..._t(E,c),"data-index":M,"data-item-index":P.index,"data-known-size":P.size,key:A,style:$0},d(P.index,c)):b.createElement(T,{..._t(T,c),...H0(T,P.data),"data-index":M,"data-item-group-index":P.groupIndex,"data-item-index":P.index,"data-known-size":P.size,key:A,style:m?F0:ff},D?l(P.index,P.groupIndex,P.data,c):l(P.index,P.data,c))})})}),B0={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},z0={outline:"none",overflowX:"auto",position:"relative"},bs=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),U0={position:xa(),top:0,width:"100%",zIndex:1};function _t(e,t){if(typeof e!="string")return{context:t}}function H0(e,t){return{item:typeof e=="string"?void 0:t}}const W0=b.memo(function(){const e=Ae("HeaderComponent"),t=Zt("headerHeight"),n=Ae("HeaderFooterTag"),r=Qn(b.useMemo(()=>s=>{t(Dn(s,"height"))},[t]),!0,Ae("skipAnimationFrameInResizeObserver")),o=Ae("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{..._t(e,o)})}):null}),V0=b.memo(function(){const e=Ae("FooterComponent"),t=Zt("footerHeight"),n=Ae("HeaderFooterTag"),r=Qn(b.useMemo(()=>s=>{t(Dn(s,"height"))},[t]),!0,Ae("skipAnimationFrameInResizeObserver")),o=Ae("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{..._t(e,o)})}):null});function hf({useEmitter:e,useEmitterValue:t,usePublisher:n}){return b.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:g}=uf(a,c,l,d,void 0,f);return e("scrollTo",g),e("scrollBy",p),u.jsx(l,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:h,style:{...f?z0:B0,...o},tabIndex:0,...i,..._t(l,s),children:r})})}function mf({useEmitter:e,useEmitterValue:t,usePublisher:n}){return b.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=b.useRef(null),g=t("scrollerRef"),{scrollByCallback:m,scrollerRef:y,scrollToCallback:x}=uf(a,c,l,g,p);return cf(()=>{var w;return y.current=p||((w=h.current)==null?void 0:w.ownerDocument.defaultView),()=>{y.current=null}},[y,p]),e("windowScrollTo",x),e("scrollBy",m),u.jsx(l,{ref:h,"data-virtuoso-scroller":!0,style:{position:"relative",...o,...d!==0?{height:d+f}:{}},...i,..._t(l,s),children:r})})}const K0=({children:e})=>{const t=b.useContext(af),n=Zt("viewportHeight"),r=Zt("fixedItemHeight"),o=Ae("alignToBottom"),s=Ae("horizontalDirection"),i=b.useMemo(()=>Id(n,l=>Dn(l,s?"width":"height")),[n,s]),a=Qn(i,!0,Ae("skipAnimationFrameInResizeObserver"));return b.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})},q0=({children:e})=>{const t=b.useContext(af),n=Zt("windowViewportRect"),r=Zt("fixedItemHeight"),o=Ae("customScrollParent"),s=Md(n,o,Ae("skipAnimationFrameInResizeObserver")),i=Ae("alignToBottom");return b.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})},G0=({children:e})=>{const t=Ae("TopItemListComponent")||"div",n=Ae("headerHeight"),r={...U0,marginTop:`${n}px`},o=Ae("context");return u.jsx(t,{style:r,..._t(t,o),children:e})},Y0=b.memo(function(e){const t=Ae("useWindowScroll"),n=Ae("topItemsIndexes").length>0,r=Ae("customScrollParent"),o=Ae("context");return u.jsxs(r||t?Z0:J0,{...e,context:o,children:[n&&u.jsx(G0,{children:u.jsx(pf,{showTopList:!0})}),u.jsxs(r||t?q0:K0,{children:[u.jsx(W0,{}),u.jsx(pf,{}),u.jsx(V0,{})]})]})}),{Component:X0,useEmitter:va,useEmitterValue:Ae,usePublisher:Zt}=sf(D0,{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"}},Y0),J0=hf({useEmitter:va,useEmitterValue:Ae,usePublisher:Zt}),Z0=mf({useEmitter:va,useEmitterValue:Ae,usePublisher:Zt}),Q0=X0;lt(of,He(()=>{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(ya),a=ee(Cr),l=(c,d=null)=>Nt(K(s,ue(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")}})),xa();const gf={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},eS={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:xf,floor:Ss,max:no,min:wa,round:yf}=Math;function vf(e,t,n){return Array.from({length:t-e+1}).map((r,o)=>({data:n===null?null:n[o+e],index:o+e}))}function tS(e){return{...eS,items:e}}function Cs(e,t){return e&&e.width===t.width&&e.height===t.height}function nS(e,t){return e&&e.column===t.column&&e.row===t.row}const rS=He(([{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:g,propsReady:m},{customScrollParent:y,useWindowScroll:x,windowScrollContainerState:w,windowScrollTo:S,windowViewportRect:k},C])=>{const T=ee(0),E=ee(0),N=ee(gf),_=ee({height:0,width:0}),D=ee({height:0,width:0}),B=Fe(),G=Fe(),V=ee(0),P=ee(null),M=ee({column:0,row:0}),A=Fe(),F=Fe(),L=ee(!1),R=ee(0),z=ee(!0),X=ee(!1),ne=ee(!1);Ze(K(g,Re(R),ke(([$,Y])=>!!Y)),()=>{Me(z,!1)}),Ze(K(wt(g,z,D,_,R,X),ke(([$,Y,Q,de,,oe])=>$&&!Y&&Q.height!==0&&de.height!==0&&!oe)),([,,,,$])=>{Me(X,!0),ua(1,()=>{Me(B,$)}),ln(K(c),()=>{Me(t,[0,0]),Me(z,!0)})}),ge(K(F,ke($=>$!=null&&$.scrollTop>0),yn(0)),E),Ze(K(g,Re(F),ke(([,$])=>$!=null)),([,$])=>{$&&(Me(_,$.viewport),Me(D,$.item),Me(M,$.gap),$.scrollTop>0&&(Me(L,!0),ln(K(c,Zn(1)),Y=>{Me(L,!1)}),Me(l,{top:$.scrollTop})))}),ge(K(_,ue(({height:$})=>$)),f),ge(K(wt(Ce(_,Cs),Ce(D,Cs),Ce(M,($,Y)=>$&&$.column===Y.column&&$.row===Y.row),Ce(c)),ue(([$,Y,Q,de])=>({gap:Q,item:Y,scrollTop:de,viewport:$}))),A),ge(K(wt(Ce(T),r,Ce(M,nS),Ce(D,Cs),Ce(_,Cs),Ce(P),Ce(E),Ce(L),Ce(z),Ce(R)),ke(([,,,,,,,$])=>!$),ue(([$,[Y,Q],de,oe,_e,ze,se,,me,Pe])=>{const{column:Ve,row:ut}=de,{height:Ke,width:qe}=oe,{width:Qe}=_e;if(se===0&&($===0||Qe===0))return gf;if(qe===0){const Pt=da(Pe,$),zt=Pt+Math.max(se-1,0);return tS(vf(Pt,zt,ze))}const Ge=wf(Qe,qe,Ve);let et,st;me?Y===0&&Q===0&&se>0?(et=0,st=se-1):(et=Ge*Ss((Y+ut)/(Ke+ut)),st=Ge*xf((Q+ut)/(Ke+ut))-1,st=wa($-1,no(st,Ge-1)),et=wa(st,no(0,et))):(et=0,st=-1);const Mt=vf(et,st,ze),{bottom:gt,top:Ct}=bf(_e,de,oe,Mt),it=xf($/Ge),St=it*Ke+(it-1)*ut-gt;return{bottom:gt,itemHeight:Ke,items:Mt,itemWidth:qe,offsetBottom:St,offsetTop:Ct,top:Ct}})),N),ge(K(P,ke($=>$!==null),ue($=>$.length)),T),ge(K(wt(_,D,N,M),ke(([$,Y,{items:Q}])=>Q.length>0&&Y.height!==0&&$.height!==0),ue(([$,Y,{items:Q},de])=>{const{bottom:oe,top:_e}=bf($,de,Y,Q);return[_e,oe]}),ct(Yr)),t);const ye=ee(!1);ge(K(c,Re(ye),ue(([$,Y])=>Y||$!==0)),ye);const Te=Wt(K(wt(N,T),ke(([{items:$}])=>$.length>0),Re(ye),ke(([[$,Y],Q])=>{const de=$.items[$.items.length-1].index===Y-1;return(Q||$.bottom>0&&$.itemHeight>0&&$.offsetBottom===0&&$.items.length===Y)&&de}),ue(([[,$]])=>$-1),ct())),q=Wt(K(Ce(N),ke(({items:$})=>$.length>0&&$[0].index===0),yn(0),ct())),U=Wt(K(Ce(N),Re(L),ke(([{items:$},Y])=>$.length>0&&!Y),ue(([{items:$}])=>({endIndex:$[$.length-1].index,startIndex:$[0].index})),ct(Fd),An(0)));ge(U,h.scrollSeekRangeChanged),ge(K(B,Re(_,D,T,M),ue(([$,Y,Q,de,oe])=>{const _e=Vd($),{align:ze,behavior:se,offset:me}=_e;let Pe=_e.index;Pe==="LAST"&&(Pe=de-1),Pe=no(0,Pe,wa(de-1,Pe));let Ve=ba(Y,oe,Q,Pe);return ze==="end"?Ve=yf(Ve-Y.height+Q.height):ze==="center"&&(Ve=yf(Ve-Y.height/2+Q.height/2)),me&&(Ve+=me),{behavior:se,top:Ve}})),l);const Z=Nt(K(N,ue($=>$.offsetBottom+$.bottom)),0);return ge(K(k,ue($=>({height:$.visibleHeight,width:$.visibleWidth}))),_),{customScrollParent:y,data:P,deviation:V,footerHeight:o,gap:M,headerHeight:s,increaseViewportBy:e,initialItemCount:E,itemDimensions:D,overscan:n,restoreStateFrom:F,scrollBy:i,scrollContainerState:a,scrollHeight:G,scrollTo:l,scrollToIndex:B,scrollTop:c,smoothScrollTargetReached:d,totalCount:T,useWindowScroll:x,viewportDimensions:_,windowScrollContainerState:w,windowScrollTo:S,windowViewportRect:k,...h,gridState:N,horizontalDirection:ne,initialTopMostItemIndex:R,totalListHeight:Z,...p,endReached:Te,propsReady:m,rangeChanged:U,startReached:q,stateChanged:A,stateRestoreInProgress:L,...C}},lt(fa,Lt,to,nf,Ln,ha,On));function wf(e,t,n){return no(1,Ss((e+n)/(Ss(t)+n)))}function bf(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=wf(e.width,n.width,t.column),s=Ss(r/o),i=s*n.height+no(0,s-1)*t.row;return i>0?i+t.row:i}const oS=He(()=>{const e=ee(f=>`Item ${f}`),t=ee({}),n=ee(null),r=ee("virtuoso-grid-item"),o=ee("virtuoso-grid-list"),s=ee(ya),i=ee("div"),a=ee(Cr),l=(f,p=null)=>Nt(K(t,ue(h=>h[f]),ct()),p),c=ee(!1),d=ee(!1);return ge(Ce(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")}}),sS=He(([e,t])=>({...e,...t}),lt(rS,oS)),iS=b.memo(function(){const e=ft("gridState"),t=ft("listClassName"),n=ft("itemClassName"),r=ft("itemContent"),o=ft("computeItemKey"),s=ft("isSeeking"),i=Qt("scrollHeight"),a=ft("ItemComponent"),l=ft("ListComponent"),c=ft("ScrollSeekPlaceholder"),d=ft("context"),f=Qt("itemDimensions"),p=Qt("gap"),h=ft("log"),g=ft("stateRestoreInProgress"),m=Qt("reportReadyState"),y=Qn(b.useMemo(()=>x=>{const w=x.parentElement.parentElement.scrollHeight;i(w);const S=x.firstChild;if(S){const{height:k,width:C}=S.getBoundingClientRect();f({height:k,width:C})}p({column:Cf("column-gap",getComputedStyle(x).columnGap,h),row:Cf("row-gap",getComputedStyle(x).rowGap,h)})},[i,f,p,h]),!0,!1);return cf(()=>{e.itemHeight>0&&e.itemWidth>0&&m(!0)},[e]),g?null:u.jsx(l,{className:t,ref:y,..._t(l,d),"data-testid":"virtuoso-item-list",style:{paddingBottom:e.offsetBottom,paddingTop:e.offsetTop},children:e.items.map(x=>{const w=o(x.index,x.data,d);return s?u.jsx(c,{..._t(c,d),height:e.itemHeight,index:x.index,width:e.itemWidth},w):b.createElement(a,{..._t(a,d),className:n,"data-index":x.index,key:w},r(x.index,x.data,d))})})}),aS=b.memo(function(){const e=ft("HeaderComponent"),t=Qt("headerHeight"),n=ft("headerFooterTag"),r=Qn(b.useMemo(()=>s=>{t(Dn(s,"height"))},[t]),!0,!1),o=ft("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{..._t(e,o)})}):null}),lS=b.memo(function(){const e=ft("FooterComponent"),t=Qt("footerHeight"),n=ft("headerFooterTag"),r=Qn(b.useMemo(()=>s=>{t(Dn(s,"height"))},[t]),!0,!1),o=ft("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{..._t(e,o)})}):null}),cS=({children:e})=>{const t=b.useContext(lf),n=Qt("itemDimensions"),r=Qt("viewportDimensions"),o=Qn(b.useMemo(()=>s=>{r(s.getBoundingClientRect())},[r]),!0,!1);return b.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})},uS=({children:e})=>{const t=b.useContext(lf),n=Qt("windowViewportRect"),r=Qt("itemDimensions"),o=ft("customScrollParent"),s=Md(n,o,!1);return b.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})},dS=b.memo(function({...e}){const t=ft("useWindowScroll"),n=ft("customScrollParent"),r=n||t?pS:fS,o=n||t?uS:cS,s=ft("context");return u.jsx(r,{...e,..._t(r,s),children:u.jsxs(o,{children:[u.jsx(aS,{}),u.jsx(iS,{}),u.jsx(lS,{})]})})}),{useEmitter:Sf,useEmitterValue:ft,usePublisher:Qt}=sf(sS,{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"}},dS),fS=hf({useEmitter:Sf,useEmitterValue:ft,usePublisher:Qt}),pS=mf({useEmitter:Sf,useEmitterValue:ft,usePublisher:Qt});function Cf(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 hS=ho.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 Tf({className:e,variant:t,...n}){return u.jsx("div",{className:te(hS({variant:t}),e),...n})}function Sa(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 kf(e){return!!(e&&typeof e=="object"&&(e.type==="file"||e.mimeType||e.filename||e.sourceType==="base64"))}function ro(e){if(typeof e=="string")return e;if(e&&typeof e=="object"){if(Array.isArray(e)){const n=e.map(ro).filter(r=>r!==void 0);if(!n.length){console.debug("[message-utils] sanitizeForDisplay - array emptied -> returning undefined",{originalLength:e.length});return}return n}if(kf(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=ro(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 oo(e){if(typeof e=="string")return e;if(kf(e))return"";try{const t=ro(e);return t===void 0?"":typeof t=="string"?t:JSON.stringify(t,null,2)}catch{return""}}function mS(e){return typeof e!="string"?!1:/^[\s\n]*[-*]\s|^[\s\n]*#+\s|```|^\s*\[.*\]\(|^>\s/.test(e)}function gS(e){const t=oo(e);return typeof e=="string"&&mS(e)?{content:e,isMarkdown:!0}:{content:t,isMarkdown:!1}}function Ts(e){if(e==null)return e;if(typeof e=="string"){const t=e.trim();if(t.startsWith("{")||t.startsWith("[")){const n=Sa(t);if(n!==null)return Ts(n)}return e}return typeof e=="object"&&!Array.isArray(e)&&e.content!==void 0?Ts(e.content):e}function xS(e){return e.filter(t=>t.type==="text").map(t=>t.text).join("")}function Ef(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 ks(e){if(e==null)return null;const t=String(e).trim();return t.length>0?t:null}function yS(e){const t=r=>{try{const o=ro(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 vS(e){return e.name&&e.name.trim()?e.name:e.model&&e.model.includes("/")?e.model.split("/").pop()||null:e.model||null}function If(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 wS(e){if(!e)return"image/png";const t=e.trim();return t?t.includes("/")?t:`image/${t}`:"image/png"}function bS(e){const t=[],n=r=>{r&&r.trim()&&t.push(r.trim())};return e&&(n(e.plotId),n(e.artifactId)),t}function SS({base64:e,url:t,formatHint:n,extras:r}){const o=typeof e=="string"&&e.length>0,s=wS(n),i=o?`data:${s};base64,${e}`:t,a=bS(r),l=a.length?a.join(" / "):void 0,c=l?`${l} artifact`:"artifact image";return{src:i,alt:c,label:l}}function CS(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 SS({base64:t,url:n,formatHint:r,extras:{plotId:e.plotId,artifactId:e.artifactId}})}async function Af(e,t){return await Gt(e,{responseType:"blob",onDownloadProgress:r=>{try{t&&r.lengthComputable}catch{}},maxBodyLength:1/0})}async function Nf(e,t){return await(await Af(`/files/${e}/view`,t)).text()}async function TS(e,t){const n=await Af(`/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 kS(e,t=50,n=0){const r={limit:t,offset:n};return e&&(r.thread_id=e),await Gt("/files",{params:r})}var Es="Dialog",[_f,dk]=Tn(Es),[ES,un]=_f(Es),jf=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:Es});return u.jsx(ES,{scope:t,triggerRef:a,contentRef:l,contentId:kn(),titleId:kn(),descriptionId:kn(),open:c,onOpenChange:d,onOpenToggle:v.useCallback(()=>d(f=>!f),[d]),modal:i,children:n})};jf.displayName=Es;var Mf="DialogTrigger",Pf=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=un(Mf,n),s=$e(t,o.triggerRef);return u.jsx(Ne.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":ka(o.open),...r,ref:s,onClick:pe(e.onClick,o.onOpenToggle)})});Pf.displayName=Mf;var Ca="DialogPortal",[IS,Rf]=_f(Ca,{forceMount:void 0}),Of=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:o}=e,s=un(Ca,t);return u.jsx(IS,{scope:t,forceMount:n,children:v.Children.map(r,i=>u.jsx(Xt,{present:n||s.open,children:u.jsx(Go,{asChild:!0,container:o,children:i})}))})};Of.displayName=Ca;var Is="DialogOverlay",Df=v.forwardRef((e,t)=>{const n=Rf(Is,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=un(Is,e.__scopeDialog);return s.modal?u.jsx(Xt,{present:r||s.open,children:u.jsx(NS,{...o,ref:t})}):null});Df.displayName=Is;var AS=Vn.createSlot("DialogOverlay.RemoveScroll"),NS=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=un(Is,n);return u.jsx(rs,{as:AS,allowPinchZoom:!0,shards:[o.contentRef],children:u.jsx(Ne.div,{"data-state":ka(o.open),...r,ref:t,style:{pointerEvents:"auto",...r.style}})})}),nr="DialogContent",Lf=v.forwardRef((e,t)=>{const n=Rf(nr,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=un(nr,e.__scopeDialog);return u.jsx(Xt,{present:r||s.open,children:s.modal?u.jsx(_S,{...o,ref:t}):u.jsx(jS,{...o,ref:t})})});Lf.displayName=nr;var _S=v.forwardRef((e,t)=>{const n=un(nr,e.__scopeDialog),r=v.useRef(null),o=$e(t,n.contentRef,r);return v.useEffect(()=>{const s=r.current;if(s)return Fi(s)},[]),u.jsx($f,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:pe(e.onCloseAutoFocus,s=>{var i;s.preventDefault(),(i=n.triggerRef.current)==null||i.focus()}),onPointerDownOutside:pe(e.onPointerDownOutside,s=>{const i=s.detail.originalEvent,a=i.button===0&&i.ctrlKey===!0;(i.button===2||a)&&s.preventDefault()}),onFocusOutside:pe(e.onFocusOutside,s=>s.preventDefault())})}),jS=v.forwardRef((e,t)=>{const n=un(nr,e.__scopeDialog),r=v.useRef(!1),o=v.useRef(!1);return u.jsx($f,{...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()}})}),$f=v.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:s,...i}=e,a=un(nr,n),l=v.useRef(null),c=$e(t,l);return wi(),u.jsxs(u.Fragment,{children:[u.jsx(Do,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s,children:u.jsx(Oo,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":ka(a.open),...i,ref:c,onDismiss:()=>a.onOpenChange(!1)})}),u.jsxs(u.Fragment,{children:[u.jsx(MS,{titleId:a.titleId}),u.jsx(RS,{contentRef:l,descriptionId:a.descriptionId})]})]})}),Ta="DialogTitle",Ff=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=un(Ta,n);return u.jsx(Ne.h2,{id:o.titleId,...r,ref:t})});Ff.displayName=Ta;var Bf="DialogDescription",zf=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=un(Bf,n);return u.jsx(Ne.p,{id:o.descriptionId,...r,ref:t})});zf.displayName=Bf;var Uf="DialogClose",Hf=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=un(Uf,n);return u.jsx(Ne.button,{type:"button",...r,ref:t,onClick:pe(e.onClick,()=>o.onOpenChange(!1))})});Hf.displayName=Uf;function ka(e){return e?"open":"closed"}var Wf="DialogTitleWarning",[fk,Vf]=Ax(Wf,{contentName:nr,titleName:Ta,docsSlug:"dialog"}),MS=({titleId:e})=>{const t=Vf(Wf),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},IS="DialogDescriptionWarning",AS=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${zf(IS).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},Uf=If,NS=Nf,Hf=jf,As=Mf,Ns=Rf,rr=Of,_s=Lf,Wf=Ff;const _S=Uf,jS=Hf,Vf=v.forwardRef(({className:e,...t},n)=>u.jsx(As,{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}));Vf.displayName=As.displayName;const Kf=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===rr||(c==null?void 0:c.displayName)===rr.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(jS,{children:[u.jsx(Vf,{}),u.jsxs(Ns,{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(rr,{className:"sr-only",children:"Dialog"}),t,u.jsxs(Wf,{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"})]})]})]})});Kf.displayName=Ns.displayName;const qf=({className:e,...t})=>u.jsx("div",{className:te("flex flex-col space-y-1.5 text-center sm:text-left",e),...t});qf.displayName="DialogHeader";const Gf=v.forwardRef(({className:e,...t},n)=>u.jsx(rr,{ref:n,className:te("text-lg font-semibold leading-none tracking-tight",e),...t}));Gf.displayName=rr.displayName;const MS=v.forwardRef(({className:e,...t},n)=>u.jsx(_s,{ref:n,className:te("text-sm text-muted-foreground",e),...t}));MS.displayName=_s.displayName;const RS=1,PS=1e6;let ka=0;function OS(){return ka=(ka+1)%Number.MAX_SAFE_INTEGER,ka.toString()}const Ea=new Map,Yf=e=>{if(Ea.has(e))return;const t=setTimeout(()=>{Ea.delete(e),so({type:"REMOVE_TOAST",toastId:e})},PS);Ea.set(e,t)},DS=(e,t)=>{switch(t.type){case"ADD_TOAST":return{...e,toasts:[t.toast,...e.toasts].slice(0,RS)};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?Yf(n):e.toasts.forEach(r=>{Yf(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)}}},js=[];let Ms={toasts:[]};function so(e){Ms=DS(Ms,e),js.forEach(t=>{t(Ms)})}function LS({...e}){const t=OS(),n=o=>so({type:"UPDATE_TOAST",toast:{...o,id:t}}),r=()=>so({type:"DISMISS_TOAST",toastId:t});return so({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(Ms);return v.useEffect(()=>(js.push(t),()=>{const n=js.indexOf(t);n>-1&&js.splice(n,1)}),[e]),{...e,toast:LS,dismiss:n=>so({type:"DISMISS_TOAST",toastId:n})}}function $S({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(),p=w.useCallback(async()=>{if(n){i(!0),d(null),l(null);try{const x=await kf(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 yS(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"})}},g=async()=>{if(n)try{const x=await kf(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"})}},m=()=>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(Je,{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(_S,{open:e,onOpenChange:t,children:u.jsxs(Kf,{className:"max-w-4xl max-h-[90vh] overflow-hidden",children:[u.jsx(qf,{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(Gf,{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(Je,{variant:"outline",size:"sm",onClick:g,className:"flex items-center gap-2",children:[u.jsx(le.ExternalLink,{className:"h-4 w-4"}),"External"]}),u.jsxs(Je,{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:m()})]})})}function Xf(){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 or=Xf();function FS(e){or=e}const Jf=/[&<>"']/,BS=new RegExp(Jf.source,"g"),Zf=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,zS=new RegExp(Zf.source,"g"),US={"&":"&","<":"<",">":">",'"':""","'":"'"},Qf=e=>US[e];function jt(e,t){if(t){if(Jf.test(e))return e.replace(BS,Qf)}else if(Zf.test(e))return e.replace(zS,Qf);return e}const HS=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;function ep(e){return e.replace(HS,(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 WS=/(^|[^\[])\^/g;function ot(e,t){e=typeof e=="string"?e:e.source,t=t||"";const n={replace:(r,o)=>(o=o.source||o,o=o.replace(WS,"$1"),e=e.replace(r,o),n),getRegex:()=>new RegExp(e,t)};return n}const VS=/[^\w:]/g,KS=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function tp(e,t,n){if(e){let r;try{r=decodeURIComponent(ep(n)).replace(VS,"").toLowerCase()}catch{return null}if(r.indexOf("javascript:")===0||r.indexOf("vbscript:")===0||r.indexOf("data:")===0)return null}t&&!KS.test(n)&&(n=XS(t,n));try{n=encodeURI(n).replace(/%25/g,"%")}catch{return null}return n}const Rs={},qS=/^[^:]+:\/*[^/]*$/,GS=/^([^:]+:)[\s\S]*$/,YS=/^([^:]+:\/*[^/]*)[\s\S]*$/;function XS(e,t){Rs[" "+e]||(qS.test(e)?Rs[" "+e]=e+"/":Rs[" "+e]=Os(e,"/",!0)),e=Rs[" "+e];const n=e.indexOf(":")===-1;return t.substring(0,2)==="//"?n?t:e.replace(GS,"$1")+t:t.charAt(0)==="/"?n?t:e.replace(YS,"$1")+t:e+t}const Ps={exec:function(){}};function np(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 Os(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 JS(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 ZS(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 rp(e,t){if(t<1)return"";let n="";for(;t>1;)t&1&&(n+=e),t>>=1,e+=e;return n+e}function op(e,t,n,r){const o=t.href,s=t.title?jt(t.title):null,i=e[1].replace(/\\([\[\]])/g,"$1");if(e[0].charAt(0)!=="!"){r.state.inLink=!0;const a={type:"link",raw:n,href:o,title:s,text:i,tokens:r.inlineTokens(i)};return r.state.inLink=!1,a}return{type:"image",raw:n,href:o,title:s,text:jt(i)}}function QS(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},PS="DialogDescriptionWarning",RS=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${Vf(PS).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},Kf=jf,OS=Pf,qf=Of,As=Df,Ns=Lf,rr=Ff,_s=zf,Gf=Hf;const DS=Kf,LS=qf,Yf=v.forwardRef(({className:e,...t},n)=>u.jsx(As,{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}));Yf.displayName=As.displayName;const Xf=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===rr||(c==null?void 0:c.displayName)===rr.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(LS,{children:[u.jsx(Yf,{}),u.jsxs(Ns,{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(rr,{className:"sr-only",children:"Dialog"}),t,u.jsxs(Gf,{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"})]})]})]})});Xf.displayName=Ns.displayName;const Jf=({className:e,...t})=>u.jsx("div",{className:te("flex flex-col space-y-1.5 text-center sm:text-left",e),...t});Jf.displayName="DialogHeader";const Zf=v.forwardRef(({className:e,...t},n)=>u.jsx(rr,{ref:n,className:te("text-lg font-semibold leading-none tracking-tight",e),...t}));Zf.displayName=rr.displayName;const $S=v.forwardRef(({className:e,...t},n)=>u.jsx(_s,{ref:n,className:te("text-sm text-muted-foreground",e),...t}));$S.displayName=_s.displayName;const FS=1,BS=1e6;let Ea=0;function zS(){return Ea=(Ea+1)%Number.MAX_SAFE_INTEGER,Ea.toString()}const Ia=new Map,Qf=e=>{if(Ia.has(e))return;const t=setTimeout(()=>{Ia.delete(e),so({type:"REMOVE_TOAST",toastId:e})},BS);Ia.set(e,t)},US=(e,t)=>{switch(t.type){case"ADD_TOAST":return{...e,toasts:[t.toast,...e.toasts].slice(0,FS)};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)}}},js=[];let Ms={toasts:[]};function so(e){Ms=US(Ms,e),js.forEach(t=>{t(Ms)})}function HS({...e}){const t=zS(),n=o=>so({type:"UPDATE_TOAST",toast:{...o,id:t}}),r=()=>so({type:"DISMISS_TOAST",toastId:t});return so({type:"ADD_TOAST",toast:{...e,id:t,open:!0,onOpenChange:o=>{o||r()}}}),{id:t,dismiss:r,update:n}}function Aa(){const[e,t]=v.useState(Ms);return v.useEffect(()=>(js.push(t),()=>{const n=js.indexOf(t);n>-1&&js.splice(n,1)}),[e]),{...e,toast:HS,dismiss:n=>so({type:"DISMISS_TOAST",toastId:n})}}function WS({isOpen:e,onClose:t,fileId:n,fileName:r,mimeType:o}){const[s,i]=b.useState(!1),[a,l]=b.useState(null),[c,d]=b.useState(null),{toast:f}=Aa(),p=b.useCallback(async()=>{if(n){i(!0),d(null),l(null);try{const x=await Nf(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]);b.useEffect(()=>{e&&n&&p()},[e,n,p]);const h=async()=>{if(n)try{await TS(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"})}},g=async()=>{if(n)try{const x=await Nf(n),w=new Blob([x],{type:o}),S=URL.createObjectURL(w);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"})}},m=()=>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(Je,{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(DS,{open:e,onOpenChange:t,children:u.jsxs(Xf,{className:"max-w-4xl max-h-[90vh] overflow-hidden",children:[u.jsx(Jf,{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(Zf,{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(Je,{variant:"outline",size:"sm",onClick:g,className:"flex items-center gap-2",children:[u.jsx(le.ExternalLink,{className:"h-4 w-4"}),"External"]}),u.jsxs(Je,{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:m()})]})})}function ep(){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 or=ep();function VS(e){or=e}const tp=/[&<>"']/,KS=new RegExp(tp.source,"g"),np=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,qS=new RegExp(np.source,"g"),GS={"&":"&","<":"<",">":">",'"':""","'":"'"},rp=e=>GS[e];function jt(e,t){if(t){if(tp.test(e))return e.replace(KS,rp)}else if(np.test(e))return e.replace(qS,rp);return e}const YS=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;function op(e){return e.replace(YS,(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 XS=/(^|[^\[])\^/g;function ot(e,t){e=typeof e=="string"?e:e.source,t=t||"";const n={replace:(r,o)=>(o=o.source||o,o=o.replace(XS,"$1"),e=e.replace(r,o),n),getRegex:()=>new RegExp(e,t)};return n}const JS=/[^\w:]/g,ZS=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function sp(e,t,n){if(e){let r;try{r=decodeURIComponent(op(n)).replace(JS,"").toLowerCase()}catch{return null}if(r.indexOf("javascript:")===0||r.indexOf("vbscript:")===0||r.indexOf("data:")===0)return null}t&&!ZS.test(n)&&(n=nC(t,n));try{n=encodeURI(n).replace(/%25/g,"%")}catch{return null}return n}const Ps={},QS=/^[^:]+:\/*[^/]*$/,eC=/^([^:]+:)[\s\S]*$/,tC=/^([^:]+:\/*[^/]*)[\s\S]*$/;function nC(e,t){Ps[" "+e]||(QS.test(e)?Ps[" "+e]=e+"/":Ps[" "+e]=Os(e,"/",!0)),e=Ps[" "+e];const n=e.indexOf(":")===-1;return t.substring(0,2)==="//"?n?t:e.replace(eC,"$1")+t:t.charAt(0)==="/"?n?t:e.replace(tC,"$1")+t:e+t}const Rs={exec:function(){}};function ip(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 Os(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 rC(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 oC(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 ap(e,t){if(t<1)return"";let n="";for(;t>1;)t&1&&(n+=e),t>>=1,e+=e;return n+e}function lp(e,t,n,r){const o=t.href,s=t.title?jt(t.title):null,i=e[1].replace(/\\([\[\]])/g,"$1");if(e[0].charAt(0)!=="!"){r.state.inLink=!0;const a={type:"link",raw:n,href:o,title:s,text:i,tokens:r.inlineTokens(i)};return r.state.inLink=!1,a}return{type:"image",raw:n,href:o,title:s,text:jt(i)}}function sC(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 Na{constructor(t){this.options=t||or}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:Os(r,`
|
|
94
|
+
`)}}}fences(t){const n=this.rules.block.fences.exec(t);if(n){const r=n[0],o=sC(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=Os(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,p,h,g,m=n[1].trim();const y=m.length>1,x={type:"list",raw:"",ordered:y,start:y?+m.slice(0,-1):"",loose:!1,items:[]};m=y?`\\d{1,9}\\${m.slice(-1)}`:`\\${m}`,this.options.pedantic&&(m=y?m:"[*+-]");const w=new RegExp(`^( {0,3}${m})((?:[ ][^\\n]*)?(?:\\n|$))`);for(;t&&(g=!1,!(!(n=w.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
96
|
`,1)[0],this.options.pedantic?(i=2,h=d.trimLeft()):(i=n[2].search(/[^ ]/),i=i>4?1:i,h=d.slice(i),i+=n[1].length),l=!1,!d&&/^ *$/.test(f)&&(r+=f+`
|
|
97
97
|
`,t=t.substring(f.length+1),g=!0),!g){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)}}(?:\`\`\`|~~~)`),E=new RegExp(`^ {0,${Math.min(3,i-1)}}#`);for(;t&&(p=t.split(`
|
|
98
98
|
`,1)[0],f=p,this.options.pedantic&&(f=f.replace(/^ {1,4}(?=( {4})*[^ ])/g," ")),!(T.test(f)||E.test(f)||k.test(f)||C.test(t)));){if(f.search(/[^ ]/)>=i||!f.trim())h+=`
|
|
99
99
|
`+f.slice(i);else{if(l||d.search(/[^ ]/)>=4||T.test(d)||E.test(d)||C.test(d))break;h+=`
|
|
100
100
|
`+f}!l&&!f.trim()&&(l=!0),r+=p+`
|
|
101
|
-
`,t=t.substring(p.length+1),d=f.slice(i)}}x.loose||(c?x.loose=!0:/\n *\n *$/.test(r)&&(c=!0)),this.options.gfm&&(o=/^\[[ xX]\] /.exec(h),o&&(s=o[0]!=="[ ] ",h=h.replace(/^\[[ xX]\] +/,""))),x.items.push({type:"list_item",raw:r,task:!!o,checked:s,loose:!1,text:h}),x.raw+=r}x.items[x.items.length-1].raw=r.trimRight(),x.items[x.items.length-1].text=h.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]):jt(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:
|
|
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:jt(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]):jt(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=Os(r.slice(0,-1),"\\");if((r.length-i.length)%2===0)return}else{const i=
|
|
104
|
-
]`).replace("lheading",ve.lheading).replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").getRegex()};const fe={escape:/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,autolink:/^<(scheme:[^\s\x00-\x1f<>]*|email)>/,url:
|
|
101
|
+
`,t=t.substring(p.length+1),d=f.slice(i)}}x.loose||(c?x.loose=!0:/\n *\n *$/.test(r)&&(c=!0)),this.options.gfm&&(o=/^\[[ xX]\] /.exec(h),o&&(s=o[0]!=="[ ] ",h=h.replace(/^\[[ xX]\] +/,""))),x.items.push({type:"list_item",raw:r,task:!!o,checked:s,loose:!1,text:h}),x.raw+=r}x.items[x.items.length-1].raw=r.trimRight(),x.items[x.items.length-1].text=h.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]):jt(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:ip(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]=ip(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:jt(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]):jt(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=Os(r.slice(0,-1),"\\");if((r.length-i.length)%2===0)return}else{const i=rC(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)),lp(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 lp(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 p=t.slice(0,i+o.index+(o[0].length-a.length)+l);if(Math.min(i,l)%2){const g=p.slice(1,-1);return{type:"em",raw:p,text:g,tokens:this.lexer.inlineTokens(g)}}const h=p.slice(2,-2);return{type:"strong",raw:p,text:h,tokens:this.lexer.inlineTokens(h)}}}}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=jt(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=jt(this.options.mangle?n(r[1]):r[1]),s="mailto:"+o):(o=jt(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=jt(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=jt(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]):jt(r[0]):r[0]:o=jt(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=ot(ve.def).replace("label",ve._label).replace("title",ve._title).getRegex(),ve.bullet=/(?:[*+-]|\d{1,9}[.)])/,ve.listItemStart=ot(/^( *)(bull) */).replace("bull",ve.bullet).getRegex(),ve.list=ot(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=ot(ve.html,"i").replace("comment",ve._comment).replace("tag",ve._tag).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),ve.paragraph=ot(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=ot(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=ot(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=ot(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:ot(`^ *(?: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:ot(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 fe={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])/};fe._punctuation="!\"#$%&'()+\\-.,/:;<=>?@\\[\\]`^{|}~",fe.punctuation=ot(fe.punctuation).replace(/punctuation/g,fe._punctuation).getRegex(),fe.blockSkip=/\[[^\]]*?\]\([^\)]*?\)|`[^`]*?`|<[^>]*?>/g,fe.escapedEmSt=/(?:^|[^\\])(?:\\\\)*\\[*_]/g,fe._comment=ot(ve._comment).replace("(?:-->|$)","-->").getRegex(),fe.emStrong.lDelim=ot(fe.emStrong.lDelim).replace(/punct/g,fe._punctuation).getRegex(),fe.emStrong.rDelimAst=ot(fe.emStrong.rDelimAst,"g").replace(/punct/g,fe._punctuation).getRegex(),fe.emStrong.rDelimUnd=ot(fe.emStrong.rDelimUnd,"g").replace(/punct/g,fe._punctuation).getRegex(),fe._escapes=/\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/g,fe._scheme=/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/,fe._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])?)+(?![-_])/,fe.autolink=ot(fe.autolink).replace("scheme",fe._scheme).replace("email",fe._email).getRegex(),fe._attribute=/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/,fe.tag=ot(fe.tag).replace("comment",fe._comment).replace("attribute",fe._attribute).getRegex(),fe._label=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,fe._href=/<(?:\\.|[^\n<>\\])+>|[^\s\x00-\x1f]*/,fe._title=/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/,fe.link=ot(fe.link).replace("label",fe._label).replace("href",fe._href).replace("title",fe._title).getRegex(),fe.reflink=ot(fe.reflink).replace("label",fe._label).replace("ref",ve._label).getRegex(),fe.nolink=ot(fe.nolink).replace("ref",ve._label).getRegex(),fe.reflinkSearch=ot(fe.reflinkSearch,"g").replace("reflink",fe.reflink).replace("nolink",fe.nolink).getRegex(),fe.normal={...fe},fe.pedantic={...fe.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:ot(/^!?\[(label)\]\((.*?)\)/).replace("label",fe._label).getRegex(),reflink:ot(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",fe._label).getRegex()},fe.gfm={...fe.normal,escape:ot(fe.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.!#$%&'*+\/=?_`{\|}~-]+@)))/},fe.gfm.url=ot(fe.gfm.url,"i").replace("email",fe.gfm._extended_email).getRegex(),fe.breaks={...fe.gfm,br:ot(fe.br).replace("{2,}","*").getRegex(),text:ot(fe.gfm.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()};function iC(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 cp(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 $n{constructor(t){this.tokens=[],this.tokens.links=Object.create(null),this.options=t||or,this.options.tokenizer=this.options.tokenizer||new Na,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:fe.normal};this.options.pedantic?(n.block=ve.pedantic,n.inline=fe.pedantic):this.options.gfm&&(n.block=ve.gfm,this.options.breaks?n.inline=fe.breaks:n.inline=fe.gfm),this.tokenizer.rules=n}static get rules(){return{block:ve,inline:fe}}static lex(t,n){return new $n(n).lex(t)}static lexInline(t,n){return new $n(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,7 +111,7 @@ 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)+"["+
|
|
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)+"["+ap("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)+"["+ap("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,cp)){t=t.substring(r.raw.length),n.push(r);continue}if(!this.state.inLink&&(r=this.tokenizer.url(t,cp))){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 p;this.options.extensions.startInline.forEach(function(h){p=h.call({lexer:this},f),typeof p=="number"&&p>=0&&(d=Math.min(d,p))}),d<1/0&&d>=0&&(s=t.substring(0,d+1))}if(r=this.tokenizer.inlineText(s,iC)){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 _a{constructor(t){this.options=t||or}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
115
|
`,o?'<pre><code class="'+this.options.langPrefix+jt(o)+'">'+(r?t:jt(t,!0))+`</code></pre>
|
|
116
116
|
`:"<pre><code>"+(r?t:jt(t,!0))+`</code></pre>
|
|
117
117
|
`}blockquote(t){return`<blockquote>
|
|
@@ -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
|
-
`+(h.tokens?this.parseInline(h.tokens):h.text);r+=n?this.renderer.paragraph(p):p;continue}default:{const N='Token with "'+h.type+'" type was not found.';if(this.options.silent){console.error(N);return}else throw new Error(N)}}}return r}parseInline(t,n){n=n||this.renderer;let r="",o,s,i;const a=t.length;for(o=0;o<a;o++){if(s=t[o],this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[s.type]&&(i=this.options.extensions.renderers[s.type].call({parser:this},s),i!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(s.type))){r+=i||"";continue}switch(s.type){case"escape":{r+=n.text(s.text);break}case"html":{r+=n.html(s.text);break}case"link":{r+=n.link(s.href,s.title,this.parseInline(s.tokens,n));break}case"image":{r+=n.image(s.href,s.title,s.text);break}case"strong":{r+=n.strong(this.parseInline(s.tokens,n));break}case"em":{r+=n.em(this.parseInline(s.tokens,n));break}case"codespan":{r+=n.codespan(s.text);break}case"br":{r+=n.br();break}case"del":{r+=n.del(this.parseInline(s.tokens,n));break}case"text":{r+=n.text(s.text);break}default:{const l='Token with "'+s.type+'" type was not found.';if(this.options.silent){console.error(l);return}else throw new Error(l)}}}return r}}class Ds{constructor(t){this.options=t||or}preprocess(t){return t}postprocess(t){return t}}
|
|
136
|
-
Please report this to https://github.com/markedjs/marked.`,e){const o="<p>An error occurred:</p><pre>"+jt(r.message+"",!0)+"</pre>";if(t)return Promise.resolve(o);if(n){n(null,o);return}return o}if(t)return Promise.reject(r);if(n){n(r);return}throw r}}function lp(e,t){return(n,r,o)=>{typeof r=="function"&&(o=r,r=null);const s={...r};r={...xe.defaults,...s};const i=tC(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(ZS(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&&xe.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;xe.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(xe.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&&xe.walkTokens(a,r.walkTokens);let l=t(a,r);return r.hooks&&(l=r.hooks.postprocess(l)),l}catch(a){return i(a)}}}function xe(e,t,n){return lp($n.lex,Fn.parse)(e,t,n)}xe.options=xe.setOptions=function(e){return xe.defaults={...xe.defaults,...e},FS(xe.defaults),xe},xe.getDefaults=Xf,xe.defaults=or,xe.use=function(...e){const t=xe.defaults.extensions||{renderers:{},childTokens:{}};e.forEach(n=>{const r={...n};if(r.async=xe.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=xe.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=xe.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=xe.defaults.hooks||new Ds;for(const s in n.hooks){const i=o[s];Ds.passThroughHooks.has(s)?o[s]=a=>{if(xe.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=xe.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}}xe.setOptions(r)})},xe.walkTokens=function(e,t){let n=[];for(const r of e)switch(n=n.concat(t.call(xe,r)),r.type){case"table":{for(const o of r.header)n=n.concat(xe.walkTokens(o.tokens,t));for(const o of r.rows)for(const s of o)n=n.concat(xe.walkTokens(s.tokens,t));break}case"list":{n=n.concat(xe.walkTokens(r.items,t));break}default:xe.defaults.extensions&&xe.defaults.extensions.childTokens&&xe.defaults.extensions.childTokens[r.type]?xe.defaults.extensions.childTokens[r.type].forEach(function(o){n=n.concat(xe.walkTokens(r[o],t))}):r.tokens&&(n=n.concat(xe.walkTokens(r.tokens,t)))}return n},xe.parseInline=lp($n.lexInline,Fn.parseInline),xe.Parser=Fn,xe.parser=Fn.parse,xe.Renderer=Na,xe.TextRenderer=ip,xe.Lexer=$n,xe.lexer=$n.lex,xe.Tokenizer=Aa,xe.Slugger=ap,xe.Hooks=Ds,xe.parse=xe,xe.options,xe.setOptions,xe.use,xe.walkTokens,xe.parseInline,Fn.parse,$n.lex;function io({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 xe.parse=="function"?xe.parse(i):xe(i)}return typeof xe.parse=="function"?xe.parse(e):xe(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 nC={MODE:"library"};function rC(){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:Xs&&Xs.tagName.toUpperCase()==="SCRIPT"&&Xs.src||new URL("index.umd.js",document.baseURI).href}<"u"?nC: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 oC(){return!rC()}function sC(){return typeof window>"u"?!1:window.__ARTIFACT_DEBUG__===!0}function iC(){return oC()||sC()}function aC({preview:e,idx:t}){return w.useEffect(()=>{iC()&&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 ao=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}));ao.displayName="Card";const lo=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:te("flex flex-col space-y-1.5 p-6",e),...t}));lo.displayName="CardHeader";const co=v.forwardRef(({className:e,...t},n)=>u.jsx("h3",{ref:n,className:te("text-2xl font-semibold leading-none tracking-tight",e),...t}));co.displayName="CardTitle";const cp=v.forwardRef(({className:e,...t},n)=>u.jsx("p",{ref:n,className:te("text-sm text-muted-foreground",e),...t}));cp.displayName="CardDescription";const uo=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:te("p-6 pt-0",e),...t}));uo.displayName="CardContent";const up=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:te("flex items-center p-6 pt-0",e),...t}));up.displayName="CardFooter";function lC({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=oo(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(ao,{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(lo,{className:"pb-3",children:[u.jsx(co,{className:"text-blue-900 dark:text-blue-100 text-base",children:i}),u.jsx(cp,{className:"text-blue-700 dark:text-blue-300 text-sm",children:l})]}),a&&u.jsx(uo,{className:"pt-0 pb-3",children:a}),u.jsx(up,{className:"pt-0",children:u.jsxs("div",{className:"flex gap-2 ml-auto",children:[u.jsx(Je,{size:"sm",variant:"outline",onClick:()=>n(e),className:"border-red-300 text-red-700 hover:bg-red-50 dark:border-red-700 dark:text-red-300 dark:hover:bg-red-950/50",disabled:r||!o,children:"Reject"}),u.jsx(Je,{size:"sm",onClick:()=>t(e),className:"bg-blue-600 hover:bg-blue-700 text-white",disabled:r||!o,children:"Approve"})]})})]})}const cC="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 dp({data:e}){return Array.isArray(e)?e.every(n=>n===null||["string","number","boolean"].includes(typeof n))?u.jsx("div",{className:cC,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:oo(e)}):u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:oo(e)})}function uC({message:e,viewMode:t}){const r=Sf(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(dp,{data:d});const f=typeof d=="string"?d:(()=>{try{return oo(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}=uS(c);return f?u.jsx(io,{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.jsx("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:u.jsxs("span",{children:["Running ",r,"…"]})});if(i.type==="text"){const d=(i.text??"").trim();if(!d)return null;const f=Ts(d);return s(f)}const a=ro(i),l=Ts(a);return s(l)}function dC({message:e,viewMode:t,isStreaming:n=!1}){const r=e.name??"tool",o=w.useMemo(()=>{const l=e.additionalKwargs??{};return Array.isArray(l.toolProgress)?[...l.toolProgress]:[]},[e]),i=o.some(l=>l.type==="tool.start"||l.type==="tool.call"||l.type==="message.start")?`Running ${r}…`:void 0,a=n||o.length>0;return u.jsxs("div",{className:"space-y-2",children:[a&&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:i??`Running ${r}…`})]}),o.length>0&&u.jsx("div",{className:"space-y-2 text-xs text-muted-foreground",children:o.map((l,c)=>{var d;return u.jsxs("div",{className:"rounded border border-current/10 bg-muted/60 p-2 text-[11px] leading-snug",children:[u.jsxs("div",{className:"mb-1 flex items-center justify-between text-[8px] uppercase tracking-wide text-muted-foreground",children:[u.jsx("span",{children:((d=l.type)==null?void 0:d.replace(/\./g," "))??"progress"}),u.jsx("span",{children:l.idx??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"]})]})]},`tool-progress-${r}-${c}`)})})]}),u.jsx(uC,{message:e,viewMode:t})]})}function fC(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(h=>{a(h),c(!0)},[]),p=w.useCallback(async(h,g,m)=>{var y,x;if(!t){h.preventDefault();return}if(o[m]){h.preventDefault();return}try{const b=String(g.url??""),S=b.match(/\/chat\/files\/([^/]+)(?:\/(view|download))?/);if(S){h.preventDefault();const k=S[1],C=g.name||`file_${k}`,T=g.mimeType||"application/octet-stream";f({id:k,name:C,mimeType:T});return}if(b.startsWith("data:")){h.preventDefault(),s(C=>({...C,[m]:!0}));const k=r({title:"Fetching file...",description:"",open:!0});try{const C=await vS(n??void 0);if(!C||!Array.isArray(C))throw new Error("Invalid file list response");const T=C.find(E=>!E||typeof E!="object"||!((E.filename??"")===(g.name??""))?!1:typeof g.size=="number"&&typeof E.size=="number"?E.size===g.size:!0);if(!(T!=null&&T.id))throw new Error(`File "${g.name}" is not yet available on the server`);if(!T.id||!T.filename)throw new Error("Invalid file data received from server");f({id:T.id,name:g.name||T.filename||`file_${T.id}`,mimeType:g.mimeType||T.mime_type||"application/octet-stream"}),(y=k.update)==null||y.call(k,{id:k.id,title:"Success",description:`Opened ${g.name}`,open:!0})}catch(C){console.error("Failed to fetch server file:",C);const T=C instanceof Error?C.message:"Unknown error occurred";(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,[m]:!1}))}}}catch(b){console.error("File click error:",b),s(S=>({...S,[m]:!1}))}},[t,o,r,n,f]);return{uploadingFiles:o,handleFileClick:p,fileViewerOpen:l,currentFileInfo:i,closeFileViewer:d}}function pC({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(io,{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(Je,{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 hC({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)]})}function fp(e){var n;const t=(n=e.additionalKwargs)==null?void 0:n.toolProgress;return Array.isArray(t)?t:[]}const Ls=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:g,onRegenerate:m,onCancelEdit:y,onCopy:x,activeInterrupt:b,disableInterruptActions:S=!1,onInterruptActionStart:k,onInterruptActionEnd:C,checkpointCandidates:T=[],activeCheckpointId:E=null,onSelectCheckpoint:N,defaultCheckpointId:_=null,messageParentCheckpointId:D=null}){const[B,G]=w.useState(!1),[V,R]=w.useState("preview"),[M,A]=w.useState(!1),{currentThreadId:F}=jo(),{respondToInterrupt:L}=Mo(),P=l==="phone"||l==="half-screen",z=t.role,X=z==="tool",ne=w.useMemo(()=>"type"in t&&t.type==="default_message"?t:null,[t]),ye=!!ne,Te=!(r&&z!=="user"),{uploadingFiles:q,handleFileClick:U,fileViewerOpen:J,currentFileInfo:$,closeFileViewer:Y}=fC({allowFileOpen:Te,currentThreadId:F}),Z=w.useMemo(()=>{switch(z){case"user":return"text-[hsl(var(--chat-bubble-user-text))]";case"assistant":return"text-[hsl(var(--chat-bubble-ai-text))]";case"tool":return"text-secondary-foreground";case"system":return"text-muted-foreground";default:return"text-[hsl(var(--chat-bubble-ai-text))]"}},[z]),de=w.useMemo(()=>{if(ne)return"";const j=t.content;return Array.isArray(j)?dS(j):""},[ne,t]),oe=w.useMemo(()=>{if(ne)return{};const j=t.content;return Array.isArray(j)?Sf(t):{}},[ne,t]),_e=w.useMemo(()=>X?!!(t.additionalKwargs??{}).toolStreaming:!1,[X,t]),ze=w.useMemo(()=>{if(ne)return[];const j=t.content;return Array.isArray(j)?j.filter(Q=>Q.type==="image_url"):[]},[ne,t]),se=w.useMemo(()=>{if(ne)return[];const j=t.content;return Array.isArray(j)?j.filter(Q=>Q.type==="file"):[]},[ne,t]),me=w.useMemo(()=>{if(ne)return[];const j=t.content;return Array.isArray(j)?j.filter(Q=>Q.type==="interrupt"):[]},[ne,t]),Re=(b==null?void 0:b.id)??(b==null?void 0:b.interrupt_id),Ve=ks(Re),ut=b==null?void 0:b.value,Ke=w.useMemo(()=>{if(ne)return"";const j=t.content;return Array.isArray(j)?fS(j):""},[ne,t]),qe=w.useMemo(()=>{if(ne||!p)return[];const Q=t.artifact;if(!Q)return[];const re=[],ie=[...Array.isArray(Q.plots)?Q.plots:[]];for(const ce of ie){const Xe=xS(ce);Xe&&re.push(Xe)}return re},[ne,t,p]),Qe=w.useCallback(async()=>{const j=X?Ke:de;async function Q(re){if(navigator.clipboard&&typeof navigator.clipboard.writeText=="function"){await navigator.clipboard.writeText(re);return}if(navigator.clipboard&&typeof navigator.clipboard.write=="function"&&typeof ClipboardItem<"u"){const ie=new Blob([re],{type:"text/plain"});await navigator.clipboard.write([new ClipboardItem({"text/plain":ie})]);return}throw new Error("Clipboard API not supported in this context.")}try{await Q(j),G(!0),setTimeout(()=>G(!1),2e3),x==null||x(j)}catch(re){console.error("Failed to copy:",re)}},[X,Ke,de,x]),Ge=w.useCallback(()=>{if(!g)return;const j=X?Ke:de,Q="type"in t&&t.type==="default_message"?void 0:{checkpointId:t.checkpointId??null,checkpointNs:t.checkpointNs??null};g(t.id,j,Q)},[g,t.id,X,Ke,de,t]),et=w.useCallback(()=>{m==null||m(n)},[m,n]),st=w.useCallback(()=>{const Q=te(P?"h-3 w-3":"h-4 w-4","opacity-60 flex-shrink-0",Z);switch(z){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})}},[P,Z,z]),Mt=w.useCallback(()=>{const j="group relative mb-4 flex w-full";switch(z){case"user":return te(j,"justify-end");case"assistant":case"tool":case"system":return te(j,"justify-start");default:return j}},[z]),gt=w.useCallback(()=>{const j=te("rounded-lg px-4 py-3 relative min-w-0 max-w-full break-words",P&&"px-3 py-2 text-sm");if(ye)return te(j,"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(z){case"user":return te(j,"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(j,"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(j,"w-full md:max-w-[95%] bg-secondary/50 text-secondary-foreground border border-dashed");case"system":return te(j,"w-full md:max-w-[85%] bg-accent/40 text-muted-foreground border");default:return te(j,"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")}},[P,ye,z]),Ct=w.useCallback(async j=>{if(S)return;const Q=ks((j==null?void 0:j.id)??(j==null?void 0:j.interrupt_id));if(!Q){console.warn("Interrupt part missing id",j);return}try{k==null||k(),await L(Q,!0)}catch(re){console.error("Failed to approve interrupt:",re)}finally{C==null||C()}},[S,C,k,L]),it=w.useCallback(async j=>{if(S)return;const Q=ks((j==null?void 0:j.id)??(j==null?void 0:j.interrupt_id));if(!Q){console.warn("Interrupt part missing id",j);return}try{k==null||k(),await L(Q,!1)}catch(re){console.error("Failed to reject interrupt:",re)}finally{C==null||C()}},[S,C,k,L]),St=w.useCallback(({part:j,i:Q})=>{if(j.type==="text"){const re=j.text??"",ie=re.trim(),ce=wa(ie);return ce&&z!=="tool"?u.jsx(dp,{data:ce},Q):z==="user"&&c&&ie.length>d?u.jsx(pC,{text:ie,expanded:M,onExpandedChange:A,previewLength:d,isCompact:P},Q):u.jsx(io,{content:re,allowHtml:!1},Q)}if(j.type==="image_url"){const re=j;return u.jsx("div",{className:"my-2",children:u.jsx("img",{src:re.url,alt:re.alt??"",loading:"lazy",className:"border rounded max-h-[420px] w-auto object-contain"})},Q)}if(j.type==="file"){const re=j,ie=re.name||"file";return u.jsxs("a",{href:re.url,onClick:ce=>U(ce.nativeEvent,re,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:[q[Q]?u.jsx(le.Loader,{className:"h-4 w-4 animate-spin"}):null,u.jsxs("span",{className:"truncate max-w-[180px]",children:[ie,q[Q]?" (processing)":""]})]},Q)}if(j.type==="interrupt"){const re=j,ie=ks((re==null?void 0:re.id)??(re==null?void 0:re.interrupt_id)),ce=!!(Ve&&ie&&ie===Ve),Xe=ce?ut??(re==null?void 0:re.value):re==null?void 0:re.value,Ie=ie?{...re,id:ie,interrupt_id:ie}:re;return u.jsx(lC,{interruptPart:Ie,onApprove:Ct,onReject:it,disabled:S,isActive:ce,payload:Xe},Q)}return null},[U,q,Ct,it,z,c,d,M,P,Ve,ut,b,S,me]),Rt=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"})]}),[]),zt=w.useCallback(()=>{const j=de.trim().length>0||ze.length>0||se.length>0||me.length>0;if(!X&&se.length>0&&!r)return Rt();if(!X&&!j&&!r)return null;if(X)return!f&&qe.length>0?null:f?u.jsx(dC,{message:t,viewMode:V,isStreaming:_e},t.id):null;if(!X&&!ne){const Q=t,re=u.jsx("div",{className:"space-y-2",children:Q.content.map((ie,ce)=>u.jsx(St,{part:ie,i:ce},ce))});return r?u.jsxs("div",{"aria-busy":"true",role:"status",children:[re,u.jsx(hC,{className:Z})]}):re}},[de,ze.length,se.length,me.length,r,X,V,f,qe.length,Rt,Z]),nn=w.useMemo(()=>ne?"Assistant":pS(t),[ne,t]),Le=w.useMemo(()=>ne?[]:Array.isArray(T)?T:[],[T,ne]),Sn=w.useMemo(()=>{var j;return Le.length?_&&Le.some(Q=>Q.id===_)?_:((j=Le[0])==null?void 0:j.id)??null:null},[_,Le]),We=w.useMemo(()=>!Le.length||!E?null:Le.some(j=>j.id===E)?E:null,[E,Le])??Sn,pt=z==="user"&&Le.length>0&&typeof N=="function",Pt=w.useCallback((j,Q=!1)=>{if(!N)return;const re=(j==null?void 0:j.id)??null,ie=(j==null?void 0:j.parentId)??D??null;N(re,ie,Q)},[D,N]),Ye=w.useMemo(()=>We?Le.findIndex(j=>j.id===We):-1,[We,Le]),H=w.useMemo(()=>Ye<0?null:Le[Ye]??null,[Ye,Le]);return X&&!f&&qe.length===0?null:ye&&ne?u.jsx("div",{className:te(Mt(),h.container),children:u.jsxs("div",{className:te(gt(),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(io,{content:ne.content,className:"text-current"})]})}):u.jsxs(u.Fragment,{children:[u.jsx("div",{className:te(Mt(),h.container),children:u.jsxs("div",{className:te(gt(),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",P&&"mb-1 pb-1",Z,h.header),children:[u.jsxs("div",{className:"flex items-center gap-2",children:[st(),a&&nn&&u.jsx("span",{className:te("font-medium",P?"text-xs":"text-sm"),children:nn}),X&&u.jsxs(bf,{variant:"outline",className:te("text-xs flex items-center gap-1 cursor-pointer select-none",Z,"border border-current/40",P&&"text-xs h-4"),role:"button",tabIndex:0,"aria-expanded":V==="expanded",onClick:()=>R(j=>j==="expanded"?"preview":"expanded"),onKeyDown:j=>{(j.key==="Enter"||j.key===" ")&&(j.preventDefault(),R(Q=>Q==="expanded"?"preview":"expanded"))},children:[u.jsx("span",{children:oe.name??"Tool Output"}),oe.toolCallId&&u.jsx("span",{className:"opacity-70",children:oe.toolCallId.slice(0,8)}),V==="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:[pt&&H&&Ye>=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",Ye<Le.length-1?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(Ye>=Le.length-1)return;const j=Le[Ye+1];j&&Pt(j)},"aria-label":"Older checkpoint (back in time)",disabled:Ye>=Le.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:[Le.length-Ye," / ",Le.length]})}),u.jsx("button",{type:"button",className:te("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",Ye>0?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(!(Ye<=0))if(Ye===1)Pt(null,!0);else{const j=Le[Ye-1];j&&Pt(j,!1)}},"aria-label":"Newer checkpoint (forward in time)",disabled:Ye<=0,children:u.jsx(le.ChevronRight,{className:"h-3 w-3"})})]})}),i&&t.createdAt&&u.jsx("time",{className:te("text-xs opacity-60",Z,P&&"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(Je,{variant:"ghost",size:"sm",onClick:()=>Qe(),className:te("h-6 w-6 p-0 hover:bg-foreground/10",Z,P&&"h-5 w-5"),"aria-label":"Copy message",title:"Copy message",children:u.jsx(le.Copy,{className:te(B?"text-success":Z,P?"h-3 w-3":"h-4 w-4")})})}),z==="user"&&g&&u.jsx(Je,{variant:"ghost",size:"sm",onClick:Ge,className:te("h-6 w-6 p-0 hover:bg-foreground/10",Z,P&&"h-5 w-5"),"aria-label":"Edit message",children:u.jsx(le.Edit,{className:te(Z,P?"h-3 w-3":"h-4 w-4")})}),z==="assistant"&&m&&u.jsx(Je,{variant:"ghost",size:"sm",onClick:et,className:te("h-6 w-6 p-0 hover:bg-foreground/10",Z,P&&"h-5 w-5"),"aria-label":"Regenerate response",children:u.jsx(le.RotateCcw,{className:te(Z,P?"h-3 w-3":"h-4 w-4")})})]})]})]}),u.jsxs("div",{className:"relative",children:[zt(),p&&qe.length>0&&u.jsx("div",{className:"mt-3 space-y-4",children:qe.map((j,Q)=>u.jsx(aC,{preview:j,idx:Q},`artifact-${Q}`))})]}),X&&V==="expanded"&&(oe.toolCallId||oe.name)&&u.jsxs("div",{className:te("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",P&&"text-xs"),children:[oe.name&&u.jsxs("div",{children:["Function: ",oe.name]}),oe.toolCallId&&u.jsxs("div",{children:["Call ID: ",oe.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(Je,{variant:"ghost",size:"sm",onClick:()=>Qe(),className:te("h-6 w-6 p-0 hover:bg-background/50 text-current",P&&"h-5 w-5"),children:u.jsx(le.Copy,{className:te(B?"text-success":"text-current",P?"h-3 w-3":"h-4 w-4")})}),z==="user"&&g&&u.jsx(Je,{variant:"ghost",size:"sm",onClick:Ge,className:te("h-6 w-6 p-0 hover:bg-background/50 text-current",P&&"h-5 w-5"),children:u.jsx(le.Edit,{className:te("text-current",P?"h-3 w-3":"h-4 w-4")})}),z==="assistant"&&m&&u.jsx(Je,{variant:"ghost",size:"sm",onClick:et,className:te("h-6 w-6 p-0 hover:bg-background/50 text-current",P&&"h-5 w-5"),children:u.jsx(le.RotateCcw,{className:te("text-current",P?"h-3 w-3":"h-4 w-4")})})]})]})}),$&&u.jsx($S,{isOpen:J,onClose:Y,fileId:$.id,fileName:$.name,mimeType:$.mimeType})]})},(e,t)=>{var l,c,d,f,p,h,g,m;if(t.isStreamingMessage||e.isStreamingMessage||!(e.message.id===t.message.id&&Cf(e.message)===Cf(t.message)))return!1;const o=["isEditing","showActions","layoutSize","showTimestamp","showAgentName","truncateUserMessages","userMessagePreviewLength","showToolMessages","attemptMeta"].every(y=>e[y]===t[y]),s=((l=e.customStyles)==null?void 0:l.container)===((c=t.customStyles)==null?void 0:c.container)&&((d=e.customStyles)==null?void 0:d.content)===((f=t.customStyles)==null?void 0:f.content)&&((p=e.customStyles)==null?void 0:p.actions)===((h=t.customStyles)==null?void 0:h.actions)&&((g=e.customStyles)==null?void 0:g.header)===((m=t.customStyles)==null?void 0:m.header);if(!o||!s)return!1;const i=fp(e.message),a=fp(t.message);return i.length===a.length});Ls.displayName="MessageComponent";function mC(e,t){return w.useMemo(()=>{var d,f,p,h,g;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 m=e,y=m.checkpointId??null;s=m.additionalKwargs??{},i=m.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?((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 C=k[0].checkpointId;c=((h=t.attemptMetaById)==null?void 0:h.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,E]of t.attemptMetaById.entries())if(E.baseUserMessageId===k){const N=(g=t.checkpointMetaById)==null?void 0:g.get(T);N&&C.push(N)}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 E=t.attemptMetaById.get(C);E&&E.attemptCount===c.attemptCount&&E.baseUserMessageId===c.baseUserMessageId&&k.push(T)}k.sort((C,T)=>{const E=C.createdAt?Date.parse(C.createdAt):0;return(T.createdAt?Date.parse(T.createdAt):0)-E}),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 pp=(e,t)=>(e==null?void 0:e.id)??`message-${t}`,hp=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:g,onInterruptActionEnd:m,showToolMessages:y,showArtifactPreviews:x,checkpointMetaById:b,checkpointIndexByKey:S,attemptMetaById:k,userMessageIdToAttempts:C,activeCheckpointId:T,onSelectCheckpoint:E}){const N=pp(t,n),_="type"in t&&t.type==="default_message",{checkpointCandidates:D,defaultCheckpointId:B,attemptMeta:G}=mC(t,{checkpointMetaById:b,checkpointIndexByKey:S,attemptMetaById:k,userMessageIdToAttempts:C}),V=t&&!_?t.additionalKwargs??{}:{},R=t&&!_?t.responseMetadata??{}:{},M=(()=>{if(typeof V.parentCheckpointId=="string")return V.parentCheckpointId;if(typeof R.parentCheckpointId=="string")return R.parentCheckpointId})();return u.jsx("div",{className:"relative mb-4 last:mb-0","data-message-id":N,style:{minHeight:"60px",containIntrinsicSize:"auto 120px"},children:u.jsx(Ls,{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:g,onInterruptActionEnd:m,showToolMessages:y,showArtifactPreviews:x,checkpointCandidates:D,activeCheckpointId:T??null,onSelectCheckpoint:E,defaultCheckpointId:B,messageParentCheckpointId:M,attemptMeta:G})})});hp.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:g=!0,isNavigatingCheckpoint:m=!1,onScrollAway:y,onAtBottom:x,activeInterrupt:b,disableInterruptActions:S=!1,onInterruptActionStart:k,onInterruptActionEnd:C,showToolMessages:T=!0,showArtifactPreviews:E=!0,checkpointMetaById:N,checkpointIndexByKey:_,attemptMetaById:D,userMessageIdToAttempts:B,activeCheckpointId:G,onSelectCheckpoint:V,createSyntheticThinkingMessage:R=!1},M)=>{const A=w.useRef(null),F=w.useRef(null),L=w.useRef(!1),P=w.useRef(!1),[z,X]=w.useState(!0),ne=w.useMemo(()=>b?e.some(se=>"type"in se&&se.type==="default_message"?!1:Array.isArray(se==null?void 0:se.content)&&se.content.some(me=>me&&me.type==="interrupt"&&(me.id??me.interrupt_id)===b.id)):!1,[b,e]),ye=w.useMemo(()=>{if(!b||ne)return null;const se=b.id&&String(b.id).trim()?String(b.id).trim():"pending-interrupt";let me;const Re=b.value;if(Re&&typeof Re=="object"&&!Array.isArray(Re)){const Ve=Re.title;typeof Ve=="string"&&Ve.trim()&&(me=Ve.trim())}return{id:`interrupt-${se}`,role:"system",createdAt:new Date().toISOString(),content:[{type:"interrupt",id:se,value:Re,title:me}]}},[b,ne]),Te=w.useMemo(()=>ye?[...e,ye]:e,[e,ye]),q=w.useMemo(()=>!R||!t?Te:!Te.some(me=>me.role==="assistant")&&Te.length>0?[...Te,{id:"thinking-assistant",role:"assistant",content:[],createdAt:new Date().toISOString()}]:Te,[Te,t,R]),U=w.useMemo(()=>T?q:q.filter(se=>(se==null?void 0:se.role)!=="tool"),[q,T]),J=w.useCallback(se=>{X(se),y&&y(!se),x&&x(se)},[y,x]),$=w.useMemo(()=>{if(a)return async()=>{if(!L.current){L.current=!0;try{await a()}finally{L.current=!1}}}},[a]),Y=w.useMemo(()=>!g||m?!1:z?"auto":!1,[z,g,m]),Z=w.useMemo(()=>{if(typeof h!="string")return null;const se=h.trim();return se?{id:"default-message",role:"assistant",type:"default_message",content:se,createdAt:new Date().toISOString()}:null},[h]),de=["flex h-full flex-col md:flex-row",f].filter(Boolean).join(" "),oe=()=>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(Ls,{message:Z,messageIndex:0,isStreamingMessage:!1,showActions:!1,showTimestamp:!1,showAgentName:!0,layoutSize:o,onEdit:()=>{},onRegenerate:()=>{},onCancelEdit:()=>{},showArtifactPreviews:E})})}):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,ze=_e>0;return w.useEffect(()=>{var se,me;if(_e===0){P.current=!1;return}if(!P.current)if(P.current=!0,A.current&&U.length>0){const Re=U.length-1;(me=(se=A.current).scrollToIndex)==null||me.call(se,{index:Re,align:"end",behavior:"auto"})}else F.current&&(F.current.scrollTop=F.current.scrollHeight)},[_e,U.length]),w.useImperativeHandle(M,()=>({scrollToLatest:()=>{var se,me;if(A.current&&U.length>0){const Re=U.length-1;(me=(se=A.current).scrollToIndex)==null||me.call(se,{index:Re,align:"end",behavior:"auto"})}else F.current&&(F.current.scrollTop=F.current.scrollHeight)},scrollToTop:()=>{var se,me;A.current&&U.length>0?(me=(se=A.current).scrollToIndex)==null||me.call(se,{index:0,align:"start",behavior:"auto"}):F.current&&(F.current.scrollTop=0)}}),[U]),u.jsx("div",{className:de,style:p,children:u.jsx("div",{className:"relative flex-1 min-h-0",children:ze?u.jsx(q0,{ref:se=>{A.current=se},scrollerRef:se=>{F.current=se instanceof HTMLDivElement?se:null},data:U,followOutput:Y,overscan:200,increaseViewportBy:{top:100,bottom:200},defaultItemHeight:80,atBottomThreshold:50,startReached:()=>{$&&$()},atBottomStateChange:J,style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:(se,me)=>pp(me,se),itemContent:(se,me)=>u.jsx(hp,{message:me,index:se,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:E,checkpointMetaById:N,checkpointIndexByKey:_,attemptMetaById:D,userMessageIdToAttempts:B,activeCheckpointId:G,onSelectCheckpoint:V})}):oe()})})});_a.displayName="MessageList";const mp={value:""};function $s({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:g,onError:m}){const{api:y}=di(),{currentThreadId:x}=jo(),{threadId:b,messages:S,isHistoryLoading:k,isLoading:C,navigateToCheckpoint:T,returnToLatest:E,checkpoint:N,checkpoints:_,interrupt:D,metadata:B,timelineCheckpoints:G,messagePreviews:V}=Mo(),{isStreaming:R,error:M,connectionState:A,submit:F,stop:L}=cc(),P=b??x??null,z=(N==null?void 0:N.id)??null,X=(N==null?void 0:N.namespace)??null,ne=(B==null?void 0:B.assemblingMessageId)??null,ye=D,[Te,q]=w.useState(!1);w.useEffect(()=>{ye||q(!1)},[ye]);const U=w.useCallback(()=>{q(!0)},[]),J=w.useCallback(()=>{q(!1)},[]),$=!!ye||Te,[Y,Z]=w.useState(null),[de,oe]=w.useState(""),[_e,ze]=w.useState(null),[se,me]=w.useState(null),[Re,Ve]=w.useState([]),[ut,Ke]=w.useState(0),[qe,Qe]=w.useState(0),[Ge,et]=w.useState(!1),[st,Mt]=w.useState(null),[gt,Ct]=w.useState(null),[it,St]=w.useState(!1),[Rt,zt]=w.useState(null),nn=w.useRef(!1),[Le,Sn]=w.useState(()=>mp.value),tt=w.useRef(Le),We=w.useRef(null),pt=w.useCallback(he=>{mp.value=he,Sn(he)},[]),[Pt,Ye]=w.useState(!1),H=w.useRef(null),{checkpointMetaById:j,checkpointIndexByKey:Q,attemptMetaById:re,userMessageIdToAttempts:ie}=Pw(_),ce=G??[],Xe=w.useRef(null),Ie=w.useRef(null),at=w.useCallback(()=>{Xe.current&&(Xe.current.value=""),Ie.current&&(Ie.current.value=""),Ke(he=>he+1),Qe(he=>he+1)},[]),ht=w.useCallback(he=>{pt(he)},[pt]),Kt=w.useRef(!1);w.useEffect(()=>{Kt.current&&!R&&(Ve([]),at()),Kt.current=R},[R,at]);const[Hn,Ar]=w.useState("desktop");w.useEffect(()=>{const he=()=>{const we=window.innerWidth;Ar(we<640?"phone":we<1024?"tablet":"desktop")};return he(),window.addEventListener("resize",he),()=>window.removeEventListener("resize",he)},[]),w.useEffect(()=>{nn.current=!1},[P]),w.useEffect(()=>{tt.current=Le},[Le]),w.useEffect(()=>{if(!Y){We.current=null;return}We.current===null&&(We.current=tt.current),pt(de??"")},[de,Y,pt]),w.useEffect(()=>{(async()=>{if(!y.baseUrl){zt(null);return}try{const Ee=(await y.getAgent("default")).uiDefaultMessage||"";zt(Ee||null)}catch(we){console.warn("Failed to fetch default message:",we),zt(null)}})()},[y.baseUrl]),w.useEffect(()=>{M&&!it&&(m==null||m(M))},[M,it,m]);const Nr=he=>{if(he.length>us)return`Message too long (${he.length}/${us} characters)`;try{return Lw(he),null}catch(we){return(we==null?void 0:we.message)||"Invalid message"}},po=async he=>{const we=he.trim();if(!(!we&&Re.length===0)){if(we){const Ee=Nr(we);if(Ee){me(Ee);return}}try{const Ee=Y?(_e==null?void 0:_e.checkpointId)??z??void 0:z??void 0,Ue=Y?(_e==null?void 0:_e.checkpointNs)??X??void 0:X??void 0;await F({text:we||"",attachments:Re},{checkpointId:Ee,checkpointNs:Ue,edit:!!Y,originalMessageId:Y??void 0}),h==null||h(we),pt(""),me(null),Ve([]),at(),Z(null),oe(""),ze(null)}catch(Ee){const Ue=(Ee==null?void 0:Ee.message)||"Failed to send message";me(Ue),m==null||m(Ue)}}},Nn=w.useCallback((he,we,Ee)=>{c&&(We.current=Le,Z(he),oe(we),pt(we),me(null),ze({checkpointId:(Ee==null?void 0:Ee.checkpointId)??null,checkpointNs:(Ee==null?void 0:Ee.checkpointNs)??null}))},[Le,c,pt]),I=w.useCallback(()=>{Z(null),oe(""),ze(null),me(null),pt(We.current??Le),We.current=null},[Le,pt]),W=w.useCallback((he,we,Ee)=>{Nn(he,we,Ee)},[Nn]),ae=w.useCallback(he=>{let we=null;for(let rn=he-1;rn>=0;rn--)if(S[rn].role==="user"){we=S[rn];break}if(!we)return;const Ee=Array.isArray(we.content)?we.content:[],Wn=Ee.filter(rn=>(rn==null?void 0:rn.type)==="text").map(rn=>rn.text).join("")||(()=>{try{return JSON.stringify(Ee,null,2)}catch{return String(Ee)}})();Wn&&F({text:Wn},{checkpointId:z??void 0,checkpointNs:X??void 0,edit:!0,originalMessageId:we.id})},[S,F,z,X]),be=he=>{const we=Array.from(he.target.files||[]);Ve(Ee=>[...Ee,...we]),he.target.value=""},Be=he=>{Ve(we=>{const Ee=we.filter((Ue,Wn)=>he!==Wn);return Ee.length===0&&at(),Ee})},nt=async he=>{const we=(he.target.files||[])[0];if(we){Mt(null),Ct(null),et(!0);try{await F({attachments:[we]},{checkpointId:z??void 0,checkpointNs:X??void 0});const Ee=`Uploaded ${we.name} - processing through chat stream`;Ct(Ee)}catch(Ee){const Ue=Ee instanceof Error?Ee.message:"Failed to upload Excel file";console.error("Excel upload failed",Ee),Mt(Ue),m==null||m(Ue)}finally{et(!1),he.target.value="",at()}}},De=async he=>{if(x){Ye(!0);try{if(!he){await E(),requestAnimationFrame(()=>{var Ue;(Ue=H.current)==null||Ue.scrollToLatest()});return}const we=_.find(Ue=>Ue.checkpointId===he),Ee=(we==null?void 0:we.checkpointNs)??null;await T(he,Ee),requestAnimationFrame(()=>{var Ue;(Ue=H.current)==null||Ue.scrollToTop()})}finally{Ye(!1)}}},Oe=w.useCallback(async(he,we,Ee)=>{await De(Ee?null:he)},[De]),It=`flex flex-1 w-full flex-col min-h-0 min-w-0 max-h-full overflow-hidden bg-transparent ${e} ${p.container||""}`,mt=`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:It,children:[!!M&&!it&&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:M}),u.jsx(Je,{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 ${mt}`,style:r?{maxHeight:r}:void 0,children:[u.jsx(_a,{ref:H,className:"h-full",style:{height:"100%"},messages:S,isStreaming:R,streamingAssistantId:ne,streamingDebounceMs:typeof s=="number"?s:o,followNewMessages:i,layoutSize:Hn,enableMessageEditing:c,editingMessageId:Y,onEdit:W,onRegenerate:ae,onCancelEdit:I,emptyMessage:Rt??void 0,isNavigatingCheckpoint:Pt,activeInterrupt:ye,disableInterruptActions:Te,onInterruptActionStart:U,onInterruptActionEnd:J,showToolMessages:d,showArtifactPreviews:f,checkpointMetaById:j,checkpointIndexByKey:Q,attemptMetaById:re,userMessageIdToAttempts:ie,activeCheckpointId:z,onSelectCheckpoint:Oe,timelineCheckpoints:ce,messagePreviews:V}),(A==="reconnecting"||A==="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"}),A==="reconnecting"?"Reconnecting…":"Connecting…"]})}),A==="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||Pt)&&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:[Y&&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(Je,{variant:"ghost",size:"sm",onClick:I,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:Xe,type:"file",multiple:!0,onChange:he=>be(he),className:"hidden"},ut),Re.length>0&&u.jsx("div",{className:"flex flex-wrap gap-2",children:Re.map((he,we)=>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:he.name}),u.jsx(Je,{variant:"ghost",size:"sm",onClick:()=>Be(we),className:"h-4 w-4 p-0 text-gray-500 dark:text-gray-400 hover:text-red-500 dark:hover:text-red-400","aria-label":`Remove ${he.name}`,children:u.jsx(le.X,{size:12})})]},we))})]}),l&&u.jsxs(u.Fragment,{children:[u.jsx("input",{ref:Ie,type:"file",accept:".xls,.xlsx,.xlsm",onChange:nt,className:"hidden"},qe),Ge&&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..."]}),gt&&!Ge&&u.jsx("div",{className:"text-sm rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-emerald-700",children:gt}),st&&!Ge&&u.jsx("div",{className:"text-sm rounded border border-red-200 bg-red-50 px-3 py-2 text-red-600",children:st})]})]}),se&&u.jsx("div",{className:"mb-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2",children:se}),u.jsxs("div",{className:"flex items-end gap-2",children:[(a||l)&&u.jsxs(bw,{children:[u.jsx(ww,{asChild:!0,children:u.jsx(Je,{type:"button",size:"icon",variant:"outline",disabled:R||$,title:"More input actions",className:p.moreButton||"",children:u.jsx(le.Plus,{size:16})})}),u.jsxs(bd,{align:"start",sideOffset:6,className:"w-52",children:[a&&u.jsxs(Ji,{onClick:()=>{var he;return(he=Xe.current)==null?void 0:he.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 he;Ge||(he=Ie.current)==null||he.click()},className:`cursor-pointer ${Ge?"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(wx,{initialValue:de,editingMessageId:Y,value:Le,onValueChange:ht,placeholder:Y?"Edit your message...":t,isStreaming:R,disabled:$,maxLength:us,onSend:po,onCancelEdit:I,onStop:L,allowEmptySend:Re.length>0,textareaClassName:`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${Y?"border-blue-400 bg-blue-50 text-blue-900 dark:border-blue-500 dark:bg-blue-950/60 dark:text-blue-50":""} ${se?"border-red-400":""} ${p.textarea||""}`})})]})]})]})}const Fs=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}));Fs.displayName="Input";function ja(e,[t,n]){return Math.min(n,Math.max(t,e))}function gC(e,t){return v.useReducer((n,r)=>t[n][r]??n,e)}var Ma="ScrollArea",[gp,ak]=Tn(Ma),[xC,en]=gp(Ma),xp=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,g]=v.useState(null),[m,y]=v.useState(null),[x,b]=v.useState(0),[S,k]=v.useState(0),[C,T]=v.useState(!1),[E,N]=v.useState(!1),_=$e(t,B=>l(B)),D=Po(o);return u.jsx(xC,{scope:n,type:r,dir:D,scrollHideDelay:s,scrollArea:a,viewport:c,onViewportChange:d,content:f,onContentChange:p,scrollbarX:h,onScrollbarXChange:g,scrollbarXEnabled:C,onScrollbarXEnabledChange:T,scrollbarY:m,onScrollbarYChange:y,scrollbarYEnabled:E,onScrollbarYEnabledChange:N,onCornerWidthChange:b,onCornerHeightChange:k,children:u.jsx(Ne.div,{dir:D,...i,ref:_,style:{position:"relative","--radix-scroll-area-corner-width":x+"px","--radix-scroll-area-corner-height":S+"px",...e.style}})})});xp.displayName=Ma;var yp="ScrollAreaViewport",vp=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,i=en(yp,n),a=v.useRef(null),l=$e(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})})]})});vp.displayName=yp;var wn="ScrollAreaScrollbar",Ra=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(yC,{...r,ref:t,forceMount:n}):o.type==="scroll"?u.jsx(vC,{...r,ref:t,forceMount:n}):o.type==="auto"?u.jsx(bp,{...r,ref:t,forceMount:n}):o.type==="always"?u.jsx(Pa,{...r,ref:t}):null});Ra.displayName=wn;var yC=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(bp,{"data-state":s?"visible":"hidden",...r,ref:t})})}),vC=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=en(wn,e.__scopeScrollArea),s=e.orientation==="horizontal",i=Hs(()=>l("SCROLL_END"),100),[a,l]=gC("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(Xt,{present:n||a!=="hidden",children:u.jsx(Pa,{"data-state":a==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:pe(e.onPointerEnter,()=>l("POINTER_ENTER")),onPointerLeave:pe(e.onPointerLeave,()=>l("POINTER_LEAVE"))})})}),bp=v.forwardRef((e,t)=>{const n=en(wn,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,i]=v.useState(!1),a=e.orientation==="horizontal",l=Hs(()=>{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(Pa,{"data-state":s?"visible":"hidden",...o,ref:t})})}),Pa=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=kp(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 kC(p,i.current,a,h)}return n==="horizontal"?u.jsx(bC,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const p=o.viewport.scrollLeft,h=Ep(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(wC,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const p=o.viewport.scrollTop,h=Ep(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}),bC=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=$e(t,l,s.onScrollbarXChange);return v.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(Sp,{"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":Us(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),Ap(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:zs(i.paddingLeft),paddingEnd:zs(i.paddingRight)}})}})}),wC=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=$e(t,l,s.onScrollbarYChange);return v.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(Sp,{"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":Us(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),Ap(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:zs(i.paddingTop),paddingEnd:zs(i.paddingBottom)}})}})}),[SC,wp]=gp(wn),Sp=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=en(wn,n),[g,m]=v.useState(null),y=$e(t,_=>m(_)),x=v.useRef(null),b=v.useRef(""),S=h.viewport,k=r.content-r.viewport,C=Et(d),T=Et(l),E=Hs(f,10);function N(_){if(x.current){const D=_.clientX-x.current.left,B=_.clientY-x.current.top;c({x:D,y:B})}}return v.useEffect(()=>{const _=D=>{const B=D.target;(g==null?void 0:g.contains(B))&&C(D,k)};return document.addEventListener("wheel",_,{passive:!1}),()=>document.removeEventListener("wheel",_,{passive:!1})},[S,g,k,C]),v.useEffect(T,[r,T]),kr(g,E),kr(h.content,E),u.jsx(SC,{scope:n,scrollbar:g,hasThumb:o,onThumbChange:Et(s),onThumbPointerUp:Et(i),onThumbPositionChange:T,onThumbPointerDown:Et(a),children:u.jsx(Ne.div,{...p,ref:y,style:{position:"absolute",...p.style},onPointerDown:pe(e.onPointerDown,_=>{_.button===0&&(_.target.setPointerCapture(_.pointerId),x.current=g.getBoundingClientRect(),b.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",h.viewport&&(h.viewport.style.scrollBehavior="auto"),N(_))}),onPointerMove:pe(e.onPointerMove,N),onPointerUp:pe(e.onPointerUp,_=>{const D=_.target;D.hasPointerCapture(_.pointerId)&&D.releasePointerCapture(_.pointerId),document.body.style.webkitUserSelect=b.current,h.viewport&&(h.viewport.style.scrollBehavior=""),x.current=null})})})}),Bs="ScrollAreaThumb",Cp=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=wp(Bs,e.__scopeScrollArea);return u.jsx(Xt,{present:n||o.hasThumb,children:u.jsx(CC,{ref:t,...r})})}),CC=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=en(Bs,n),i=wp(Bs,n),{onThumbPositionChange:a}=i,l=$e(t,f=>i.onThumbChange(f)),c=v.useRef(void 0),d=Hs(()=>{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=EC(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:pe(e.onPointerDownCapture,f=>{const h=f.target.getBoundingClientRect(),g=f.clientX-h.left,m=f.clientY-h.top;i.onThumbPointerDown({x:g,y:m})}),onPointerUp:pe(e.onPointerUp,i.onThumbPointerUp)})});Cp.displayName=Bs;var Oa="ScrollAreaCorner",Tp=v.forwardRef((e,t)=>{const n=en(Oa,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?u.jsx(TC,{...e,ref:t}):null});Tp.displayName=Oa;var TC=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=en(Oa,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 zs(e){return e?parseInt(e,10):0}function kp(e,t){const n=e/t;return isNaN(n)?0:n}function Us(e){const t=kp(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function kC(e,t,n,r="ltr"){const o=Us(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 Ip([l,c],f)(e)}function Ep(e,t,n="ltr"){const r=Us(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 Ip([0,i],[0,a])(c)}function Ip(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 Ap(e,t){return e>0&&e<t}var EC=(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 Hs(e,t){const n=Et(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=Et(t);kt(()=>{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 Np=xp,IC=vp,AC=Tp;const _p=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Np,{ref:r,className:te("relative overflow-hidden",e),...n,children:[u.jsx(IC,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),u.jsx(jp,{}),u.jsx(AC,{})]}));_p.displayName=Np.displayName;const jp=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(Cp,{className:"relative flex-1 rounded-full bg-border"})}));jp.displayName=Ra.displayName;const Mp=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:g,actions:m}=jo(),{loadThread:y}=Mo(),{createThread:x,deleteThread:b,renameThread:S}=m,[k,C]=w.useState(Array.isArray(f)?f:[]),T=w.useRef(k.length>0),E=w.useRef(null),N=w.useRef(0),[_,D]=w.useState(null),[B,G]=w.useState(""),[V,R]=w.useState(!1);w.useEffect(()=>{const q=Array.isArray(f)?f:[];if(q.length>0){T.current=!0,C(q);return}g||(T.current=!1,C(q))},[f,g]),w.useEffect(()=>{if(!E.current)return;const q=E.current.querySelector("[data-radix-scroll-area-viewport]");if(!q)return;let U=null,J=null;return U=requestAnimationFrame(()=>{J=requestAnimationFrame(()=>{q.scrollTop=N.current})}),()=>{U!==null&&cancelAnimationFrame(U),J!==null&&cancelAnimationFrame(J)}},[k]);const M=async q=>{try{h(q),await y(q),a==null||a(q),l==null||l(q)}catch(U){console.error("Failed to select thread:",U)}},A=async()=>{try{R(!0);const q=await x();q&&(c==null||c(q),a==null||a(q))}catch(q){console.error("Failed to create thread:",q)}finally{R(!1)}},F=async(q,U)=>{if(U.stopPropagation(),!!confirm("Delete this thread?")){if(E.current){const J=E.current.querySelector("[data-radix-scroll-area-viewport]");J&&(N.current=J.scrollTop)}try{await b(q),d==null||d(q)}catch(J){console.error("Failed to delete thread:",J)}}},L=(q,U)=>{U.stopPropagation(),D(q.threadId),G(q.title||`Thread ${q.threadId.slice(0,8)}`)},P=async q=>{if(B.trim())try{await S(q,B.trim()),D(null),G("")}catch(U){console.error("Failed to update title:",U)}},z=()=>{D(null),G("")},X=(q,U)=>{q.key==="Enter"?P(U):q.key==="Escape"&&z()},ne=q=>{if(!q)return"";try{const U=new Date(q),$=new Date().getTime()-U.getTime(),Y=Math.floor($/(1e3*60*60*24));return Y===0?U.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):Y===1?"Yesterday":Y<7?`${Y} days ago`:U.toLocaleDateString()}catch{return""}},ye=q=>q.title||`Thread ${q.threadId.slice(0,8)}`,Te=q=>{const U=ye(q);return U.length<=Mp?U:`${U.slice(0,Mp)}...`};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(Je,{onClick:A,disabled:V||g,className:s.createButton||"p-2",size:"sm",variant:"ghost",title:V?"Creating...":"New Chat",children:u.jsx(le.MessageSquarePlus,{size:20})})}),u.jsx(_p,{ref:E,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:g?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((q,U)=>new Date(U.updatedAt||U.createdAt||"").getTime()-new Date(q.updatedAt||q.createdAt||"").getTime()).map(q=>u.jsxs("div",{onClick:()=>M(q.threadId),className:`group relative p-3 rounded-lg cursor-pointer transition-colors border ${(i??p)===q.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:_===q.threadId?u.jsxs("div",{className:"flex items-center gap-2",onClick:U=>U.stopPropagation(),children:[u.jsx(Fs,{value:B,onChange:U=>G(U.target.value),onKeyDown:U=>X(U,q.threadId),className:"h-6 text-sm",autoFocus:!0}),u.jsx(Je,{variant:"ghost",size:"sm",onClick:()=>P(q.threadId),className:"h-6 w-6 p-0",children:u.jsx(le.Check,{size:12})}),u.jsx(Je,{variant:"ghost",size:"sm",onClick:z,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:Te(q)}),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:ne(q.updatedAt||q.createdAt)})]})]})}),u.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity ml-2",children:[r&&_!==q.threadId&&u.jsx(Je,{variant:"ghost",size:"sm",onClick:U=>L(q,U),className:"h-6 w-6 p-0",title:"Edit title",children:u.jsx(le.Edit3,{size:12})}),n&&u.jsx(Je,{variant:"ghost",size:"sm",onClick:U=>F(q.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===q.threadId&&u.jsx("div",{className:"absolute left-0 top-1/2 -translate-y-1/2 w-1 h-8 bg-blue-400 rounded-r"})]},q.threadId))})})]})}const NC=({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 g=d===h.id,m=(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 ${g?"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 ${g?"border-primary bg-primary/10 text-primary":"border-border bg-background"}`,children:u.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${g?"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}`:""]}),m&&u.jsx("p",{className:"text-[10px] text-muted-foreground/80 mt-1 line-clamp-2",title:m,children:m})]})]},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 Er(e){if(!(typeof globalThis>"u"))return globalThis[e]}function _C(e){if(typeof e!="string")return;const t=e.trim();if(t)return Cn(t)}function Rp(){const e=[Er("__API_BASE_URL__"),Er("__CHAT_API_BASE_URL__"),Er("__CHAT_API_URL__")];for(const t of e){const n=_C(t);if(n)return n}}function Pp(){const e=[Er("__API_AUTH_TOKEN__"),Er("__CHAT_API_KEY__"),Er("__CHAT_AUTH_TOKEN__")];for(const t of e)if(typeof t=="string"&&t.trim())return t.trim()}function Op(...e){for(const t of e)if(typeof t=="string"&&t.trim())return Cn(t);return Cn()}function Dp(){const e={},t=Rp(),n=Pp();return t&&(e.baseUrl=t),n&&(e.apiKey=n),e}function Lp(){const e=Dp(),t=_n.getAuthToken(),n=Rp();return{apiBaseUrl:Op(e.baseUrl,_n.baseUrl,n),apiKey:t||e.apiKey||Pp()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,darkMode:!1,enableSound:!1,messageHistory:100}}const $p="chat-settings";function jC(){try{const e=localStorage.getItem($p);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function MC(e){try{const t={...e,apiBaseUrl:Cn(e.apiBaseUrl)};localStorage.setItem($p,JSON.stringify(t)),t.apiKey&&_n.setAuthToken(t.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function RC(){const e=Lp(),t=jC(),n=_n.getAuthToken(),r=typeof t.apiBaseUrl=="string"?t.apiBaseUrl:void 0;return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:Op(_n.baseUrl,r,e.apiBaseUrl)}}function PC(e){_n.updateConfig({baseUrl:e.apiBaseUrl,authToken:e.apiKey??void 0}),MC(e)}var OC="Label",Fp=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())}}));Fp.displayName=OC;var Bp=Fp;const DC=ho.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(Bp,{ref:n,className:te(DC(),e),...t}));tn.displayName=Bp.displayName;function zp(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 Up=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"}),LC="VisuallyHidden",$C=v.forwardRef((e,t)=>u.jsx(Ne.span,{...e,ref:t,style:{...Up,...e.style}}));$C.displayName=LC;var FC=[" ","Enter","ArrowUp","ArrowDown"],BC=[" ","Enter"],sr="Select",[Ws,Vs,zC]=gi(sr),[Ir,lk]=Tn(sr,[zC,qo]),Ks=qo(),[UC,Bn]=Ir(sr),[HC,WC]=Ir(sr),Hp=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:g}=e,m=Ks(t),[y,x]=v.useState(null),[b,S]=v.useState(null),[k,C]=v.useState(!1),T=Po(c),[E,N]=pr({prop:r,defaultProp:o??!1,onChange:s,caller:sr}),[_,D]=pr({prop:i,defaultProp:a,onChange:l,caller:sr}),B=v.useRef(null),G=y?g||!!y.closest("form"):!0,[V,R]=v.useState(new Set),M=Array.from(V).map(A=>A.props.value).join(";");return u.jsx(ru,{...m,children:u.jsxs(UC,{required:h,scope:t,trigger:y,onTriggerChange:x,valueNode:b,onValueNodeChange:S,valueNodeHasChildren:k,onValueNodeHasChildrenChange:C,contentId:kn(),value:_,onValueChange:D,open:E,onOpenChange:N,dir:T,triggerPointerDownPosRef:B,disabled:p,children:[u.jsx(Ws.Provider,{scope:t,children:u.jsx(HC,{scope:e.__scopeSelect,onNativeOptionAdd:v.useCallback(A=>{R(F=>new Set(F).add(A))},[]),onNativeOptionRemove:v.useCallback(A=>{R(F=>{const L=new Set(F);return L.delete(A),L})},[]),children:n})}),G?u.jsxs(ph,{"aria-hidden":!0,required:h,tabIndex:-1,name:d,autoComplete:f,value:_,onChange:A=>D(A.target.value),disabled:p,form:g,children:[_===void 0?u.jsx("option",{value:""}):null,Array.from(V)]},M):null]})})};Hp.displayName=sr;var Wp="SelectTrigger",Vp=v.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...o}=e,s=Ks(n),i=Bn(Wp,n),a=i.disabled||r,l=$e(t,i.onTriggerChange),c=Vs(n),d=v.useRef("touch"),[f,p,h]=mh(m=>{const y=c().filter(S=>!S.disabled),x=y.find(S=>S.value===i.value),b=gh(y,m,x);b!==void 0&&i.onValueChange(b.value)}),g=m=>{a||(i.onOpenChange(!0),h()),m&&(i.triggerPointerDownPosRef.current={x:Math.round(m.pageX),y:Math.round(m.pageY)})};return u.jsx(ou,{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":hh(i.value)?"":void 0,...o,ref:l,onClick:pe(o.onClick,m=>{m.currentTarget.focus(),d.current!=="mouse"&&g(m)}),onPointerDown:pe(o.onPointerDown,m=>{d.current=m.pointerType;const y=m.target;y.hasPointerCapture(m.pointerId)&&y.releasePointerCapture(m.pointerId),m.button===0&&m.ctrlKey===!1&&m.pointerType==="mouse"&&(g(m),m.preventDefault())}),onKeyDown:pe(o.onKeyDown,m=>{const y=f.current!=="";!(m.ctrlKey||m.altKey||m.metaKey)&&m.key.length===1&&p(m.key),!(y&&m.key===" ")&&FC.includes(m.key)&&(g(),m.preventDefault())})})})});Vp.displayName=Wp;var Kp="SelectValue",qp=v.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,children:s,placeholder:i="",...a}=e,l=Bn(Kp,n),{onValueNodeHasChildrenChange:c}=l,d=s!==void 0,f=$e(t,l.onValueNodeChange);return kt(()=>{c(d)},[c,d]),u.jsx(Ne.span,{...a,ref:f,style:{pointerEvents:"none"},children:hh(l.value)?u.jsx(u.Fragment,{children:i}):s})});qp.displayName=Kp;var VC="SelectIcon",Gp=v.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...o}=e;return u.jsx(Ne.span,{"aria-hidden":!0,...o,ref:t,children:r||"▼"})});Gp.displayName=VC;var KC="SelectPortal",Yp=e=>u.jsx(Go,{asChild:!0,...e});Yp.displayName=KC;var ir="SelectContent",Xp=v.forwardRef((e,t)=>{const n=Bn(ir,e.__scopeSelect),[r,o]=v.useState();if(kt(()=>{o(new DocumentFragment)},[]),!n.open){const s=r;return s?mo.createPortal(u.jsx(Jp,{scope:e.__scopeSelect,children:u.jsx(Ws.Slot,{scope:e.__scopeSelect,children:u.jsx("div",{children:e.children})})}),s):null}return u.jsx(Zp,{...e,ref:t})});Xp.displayName=ir;var dn=10,[Jp,zn]=Ir(ir),qC="SelectContentImpl",GC=Vn.createSlot("SelectContent.RemoveScroll"),Zp=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:g,hideWhenDetached:m,avoidCollisions:y,...x}=e,b=Bn(ir,n),[S,k]=v.useState(null),[C,T]=v.useState(null),E=$e(t,J=>k(J)),[N,_]=v.useState(null),[D,B]=v.useState(null),G=Vs(n),[V,R]=v.useState(!1),M=v.useRef(!1);v.useEffect(()=>{if(S)return $i(S)},[S]),vi();const A=v.useCallback(J=>{const[$,...Y]=G().map(oe=>oe.ref.current),[Z]=Y.slice(-1),de=document.activeElement;for(const oe of J)if(oe===de||(oe==null||oe.scrollIntoView({block:"nearest"}),oe===$&&C&&(C.scrollTop=0),oe===Z&&C&&(C.scrollTop=C.scrollHeight),oe==null||oe.focus(),document.activeElement!==de))return},[G,C]),F=v.useCallback(()=>A([N,S]),[A,N,S]);v.useEffect(()=>{V&&F()},[V,F]);const{onOpenChange:L,triggerPointerDownPosRef:P}=b;v.useEffect(()=>{if(S){let J={x:0,y:0};const $=Z=>{var de,oe;J={x:Math.abs(Math.round(Z.pageX)-(((de=P.current)==null?void 0:de.x)??0)),y:Math.abs(Math.round(Z.pageY)-(((oe=P.current)==null?void 0:oe.y)??0))}},Y=Z=>{J.x<=10&&J.y<=10?Z.preventDefault():S.contains(Z.target)||L(!1),document.removeEventListener("pointermove",$),P.current=null};return P.current!==null&&(document.addEventListener("pointermove",$),document.addEventListener("pointerup",Y,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",$),document.removeEventListener("pointerup",Y,{capture:!0})}}},[S,L,P]),v.useEffect(()=>{const J=()=>L(!1);return window.addEventListener("blur",J),window.addEventListener("resize",J),()=>{window.removeEventListener("blur",J),window.removeEventListener("resize",J)}},[L]);const[z,X]=mh(J=>{const $=G().filter(de=>!de.disabled),Y=$.find(de=>de.ref.current===document.activeElement),Z=gh($,J,Y);Z&&setTimeout(()=>Z.ref.current.focus())}),ne=v.useCallback((J,$,Y)=>{const Z=!M.current&&!Y;(b.value!==void 0&&b.value===$||Z)&&(_(J),Z&&(M.current=!0))},[b.value]),ye=v.useCallback(()=>S==null?void 0:S.focus(),[S]),Te=v.useCallback((J,$,Y)=>{const Z=!M.current&&!Y;(b.value!==void 0&&b.value===$||Z)&&B(J)},[b.value]),q=r==="popper"?La:Qp,U=q===La?{side:a,sideOffset:l,align:c,alignOffset:d,arrowPadding:f,collisionBoundary:p,collisionPadding:h,sticky:g,hideWhenDetached:m,avoidCollisions:y}:{};return u.jsx(Jp,{scope:n,content:S,viewport:C,onViewportChange:T,itemRefCallback:ne,selectedItem:N,onItemLeave:ye,itemTextRefCallback:Te,focusSelectedItem:F,selectedItemText:D,position:r,isPositioned:V,searchRef:z,children:u.jsx(rs,{as:GC,allowPinchZoom:!0,children:u.jsx(Do,{asChild:!0,trapped:b.open,onMountAutoFocus:J=>{J.preventDefault()},onUnmountAutoFocus:pe(o,J=>{var $;($=b.trigger)==null||$.focus({preventScroll:!0}),J.preventDefault()}),children:u.jsx(Oo,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:J=>J.preventDefault(),onDismiss:()=>b.onOpenChange(!1),children:u.jsx(q,{role:"listbox",id:b.contentId,"data-state":b.open?"open":"closed",dir:b.dir,onContextMenu:J=>J.preventDefault(),...x,...U,onPlaced:()=>R(!0),ref:E,style:{display:"flex",flexDirection:"column",outline:"none",...x.style},onKeyDown:pe(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=G().filter(de=>!de.disabled).map(de=>de.ref.current);if(["ArrowUp","End"].includes(J.key)&&(Z=Z.slice().reverse()),["ArrowUp","ArrowDown"].includes(J.key)){const de=J.target,oe=Z.indexOf(de);Z=Z.slice(oe+1)}setTimeout(()=>A(Z)),J.preventDefault()}})})})})})})});Zp.displayName=qC;var YC="SelectItemAlignedPosition",Qp=v.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...o}=e,s=Bn(ir,n),i=zn(ir,n),[a,l]=v.useState(null),[c,d]=v.useState(null),f=$e(t,E=>d(E)),p=Vs(n),h=v.useRef(!1),g=v.useRef(!0),{viewport:m,selectedItem:y,selectedItemText:x,focusSelectedItem:b}=i,S=v.useCallback(()=>{if(s.trigger&&s.valueNode&&a&&c&&m&&y&&x){const E=s.trigger.getBoundingClientRect(),N=c.getBoundingClientRect(),_=s.valueNode.getBoundingClientRect(),D=x.getBoundingClientRect();if(s.dir!=="rtl"){const de=D.left-N.left,oe=_.left-de,_e=E.left-oe,ze=E.width+_e,se=Math.max(ze,N.width),me=window.innerWidth-dn,Re=ja(oe,[dn,Math.max(dn,me-se)]);a.style.minWidth=ze+"px",a.style.left=Re+"px"}else{const de=N.right-D.right,oe=window.innerWidth-_.right-de,_e=window.innerWidth-E.right-oe,ze=E.width+_e,se=Math.max(ze,N.width),me=window.innerWidth-dn,Re=ja(oe,[dn,Math.max(dn,me-se)]);a.style.minWidth=ze+"px",a.style.right=Re+"px"}const B=p(),G=window.innerHeight-dn*2,V=m.scrollHeight,R=window.getComputedStyle(c),M=parseInt(R.borderTopWidth,10),A=parseInt(R.paddingTop,10),F=parseInt(R.borderBottomWidth,10),L=parseInt(R.paddingBottom,10),P=M+A+V+L+F,z=Math.min(y.offsetHeight*5,P),X=window.getComputedStyle(m),ne=parseInt(X.paddingTop,10),ye=parseInt(X.paddingBottom,10),Te=E.top+E.height/2-dn,q=G-Te,U=y.offsetHeight/2,J=y.offsetTop+U,$=M+A+J,Y=P-$;if($<=Te){const de=B.length>0&&y===B[B.length-1].ref.current;a.style.bottom="0px";const oe=c.clientHeight-m.offsetTop-m.offsetHeight,_e=Math.max(q,U+(de?ye:0)+oe+F),ze=$+_e;a.style.height=ze+"px"}else{const de=B.length>0&&y===B[0].ref.current;a.style.top="0px";const _e=Math.max(Te,M+m.offsetTop+(de?ne:0)+U)+Y;a.style.height=_e+"px",m.scrollTop=$-Te+m.offsetTop}a.style.margin=`${dn}px 0`,a.style.minHeight=z+"px",a.style.maxHeight=G+"px",r==null||r(),requestAnimationFrame(()=>h.current=!0)}},[p,s.trigger,s.valueNode,a,c,m,y,x,s.dir,r]);kt(()=>S(),[S]);const[k,C]=v.useState();kt(()=>{c&&C(window.getComputedStyle(c).zIndex)},[c]);const T=v.useCallback(E=>{E&&g.current===!0&&(S(),b==null||b(),g.current=!1)},[S,b]);return u.jsx(JC,{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}})})})});Qp.displayName=YC;var XC="SelectPopperPosition",La=v.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=dn,...s}=e,i=Ks(n);return u.jsx(su,{...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=XC;var[JC,$a]=Ir(ir,{}),Fa="SelectViewport",eh=v.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...o}=e,s=zn(Fa,n),i=$a(Fa,n),a=$e(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(Ws.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:pe(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 g=window.innerHeight-dn*2,m=parseFloat(f.style.minHeight),y=parseFloat(f.style.height),x=Math.max(m,y);if(x<g){const b=x+h,S=Math.min(g,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})})})]})});eh.displayName=Fa;var th="SelectGroup",[ZC,QC]=Ir(th),eT=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=kn();return u.jsx(ZC,{scope:n,id:o,children:u.jsx(Ne.div,{role:"group","aria-labelledby":o,...r,ref:t})})});eT.displayName=th;var nh="SelectLabel",rh=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=QC(nh,n);return u.jsx(Ne.div,{id:o.id,...r,ref:t})});rh.displayName=nh;var qs="SelectItem",[tT,oh]=Ir(qs),sh=v.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:s,...i}=e,a=Bn(qs,n),l=zn(qs,n),c=a.value===r,[d,f]=v.useState(s??""),[p,h]=v.useState(!1),g=$e(t,b=>{var S;return(S=l.itemRefCallback)==null?void 0:S.call(l,b,r,o)}),m=kn(),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(tT,{scope:n,value:r,disabled:o,textId:m,isSelected:c,onItemTextChange:v.useCallback(b=>{f(S=>S||((b==null?void 0:b.textContent)??"").trim())},[]),children:u.jsx(Ws.ItemSlot,{scope:n,value:r,disabled:o,textValue:d,children:u.jsx(Ne.div,{role:"option","aria-labelledby":m,"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:g,onFocus:pe(i.onFocus,()=>h(!0)),onBlur:pe(i.onBlur,()=>h(!1)),onClick:pe(i.onClick,()=>{y.current!=="mouse"&&x()}),onPointerUp:pe(i.onPointerUp,()=>{y.current==="mouse"&&x()}),onPointerDown:pe(i.onPointerDown,b=>{y.current=b.pointerType}),onPointerMove:pe(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:pe(i.onPointerLeave,b=>{var S;b.currentTarget===document.activeElement&&((S=l.onItemLeave)==null||S.call(l))}),onKeyDown:pe(i.onKeyDown,b=>{var k;((k=l.searchRef)==null?void 0:k.current)!==""&&b.key===" "||(BC.includes(b.key)&&x(),b.key===" "&&b.preventDefault())})})})})});sh.displayName=qs;var fo="SelectItemText",ih=v.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,...s}=e,i=Bn(fo,n),a=zn(fo,n),l=oh(fo,n),c=WC(fo,n),[d,f]=v.useState(null),p=$e(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,g=v.useMemo(()=>u.jsx("option",{value:l.value,disabled:l.disabled,children:h},l.value),[l.disabled,l.value,h]),{onNativeOptionAdd:m,onNativeOptionRemove:y}=c;return kt(()=>(m(g),()=>y(g)),[m,y,g]),u.jsxs(u.Fragment,{children:[u.jsx(Ne.span,{id:l.textId,...s,ref:p}),l.isSelected&&i.valueNode&&!i.valueNodeHasChildren?mo.createPortal(s.children,i.valueNode):null]})});ih.displayName=fo;var ah="SelectItemIndicator",lh=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return oh(ah,n).isSelected?u.jsx(Ne.span,{"aria-hidden":!0,...r,ref:t}):null});lh.displayName=ah;var Ba="SelectScrollUpButton",ch=v.forwardRef((e,t)=>{const n=zn(Ba,e.__scopeSelect),r=$a(Ba,e.__scopeSelect),[o,s]=v.useState(!1),i=$e(t,r.onScrollButtonChange);return kt(()=>{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(dh,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop-l.offsetHeight)}}):null});ch.displayName=Ba;var za="SelectScrollDownButton",uh=v.forwardRef((e,t)=>{const n=zn(za,e.__scopeSelect),r=$a(za,e.__scopeSelect),[o,s]=v.useState(!1),i=$e(t,r.onScrollButtonChange);return kt(()=>{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(dh,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop+l.offsetHeight)}}):null});uh.displayName=za;var dh=v.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...o}=e,s=zn("SelectScrollButton",n),i=v.useRef(null),a=Vs(n),l=v.useCallback(()=>{i.current!==null&&(window.clearInterval(i.current),i.current=null)},[]);return v.useEffect(()=>()=>l(),[l]),kt(()=>{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:pe(o.onPointerDown,()=>{i.current===null&&(i.current=window.setInterval(r,50))}),onPointerMove:pe(o.onPointerMove,()=>{var c;(c=s.onItemLeave)==null||c.call(s),i.current===null&&(i.current=window.setInterval(r,50))}),onPointerLeave:pe(o.onPointerLeave,()=>{l()})})}),nT="SelectSeparator",fh=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return u.jsx(Ne.div,{"aria-hidden":!0,...r,ref:t})});fh.displayName=nT;var Ua="SelectArrow",rT=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Ks(n),s=Bn(Ua,n),i=zn(Ua,n);return s.open&&i.position==="popper"?u.jsx(iu,{...o,...r,ref:t}):null});rT.displayName=Ua;var oT="SelectBubbleInput",ph=v.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const o=v.useRef(null),s=$e(r,o),i=zp(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:{...Up,...n.style},ref:s,defaultValue:t})});ph.displayName=oT;function hh(e){return e===""||e===void 0}function mh(e){const t=Et(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 gh(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=sT(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 sT(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var iT=Hp,xh=Vp,aT=qp,lT=Gp,cT=Yp,yh=Xp,uT=eh,vh=rh,bh=sh,dT=ih,fT=lh,wh=ch,Sh=uh,Ch=fh;const Th=iT,kh=aT,Ha=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(xh,{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(lT,{asChild:!0,children:u.jsx(le.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));Ha.displayName=xh.displayName;const Eh=v.forwardRef(({className:e,...t},n)=>u.jsx(wh,{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"})}));Eh.displayName=wh.displayName;const Ih=v.forwardRef(({className:e,...t},n)=>u.jsx(Sh,{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"})}));Ih.displayName=Sh.displayName;const Wa=v.forwardRef(({className:e,children:t,position:n="popper",...r},o)=>u.jsx(cT,{children:u.jsxs(yh,{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(Eh,{}),u.jsx(uT,{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(Ih,{})]})}));Wa.displayName=yh.displayName;const pT=v.forwardRef(({className:e,...t},n)=>u.jsx(vh,{ref:n,className:te("py-1.5 pl-8 pr-2 text-sm font-semibold",e),...t}));pT.displayName=vh.displayName;const ar=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(bh,{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(fT,{children:u.jsx(le.Check,{className:"h-4 w-4"})})}),u.jsx(dT,{children:t})]}));ar.displayName=bh.displayName;const hT=v.forwardRef(({className:e,...t},n)=>u.jsx(Ch,{ref:n,className:te("-mx-1 my-1 h-px bg-muted",e),...t}));hT.displayName=Ch.displayName;var mT="Separator",Ah="horizontal",gT=["horizontal","vertical"],Nh=v.forwardRef((e,t)=>{const{decorative:n,orientation:r=Ah,...o}=e,s=xT(r)?r:Ah,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})});Nh.displayName=mT;function xT(e){return gT.includes(e)}var _h=Nh;const jh=v.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},o)=>u.jsx(_h,{ref:o,decorative:n,orientation:t,className:te("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));jh.displayName=_h.displayName;const yT=Uf,vT=NS,bT=Hf,Mh=v.forwardRef(({className:e,...t},n)=>u.jsx(As,{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}));Mh.displayName=As.displayName;const wT=ho.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"}}),Rh=v.forwardRef(({side:e="right",className:t,children:n,...r},o)=>u.jsxs(bT,{children:[u.jsx(Mh,{}),u.jsxs(Ns,{ref:o,className:te(wT({side:e}),t),...r,children:[n,u.jsxs(Wf,{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"})]})]})]}));Rh.displayName=Ns.displayName;const Ph=({className:e,...t})=>u.jsx("div",{className:te("flex flex-col space-y-2 text-center sm:text-left",e),...t});Ph.displayName="SheetHeader";const Oh=v.forwardRef(({className:e,...t},n)=>u.jsx(rr,{ref:n,className:te("text-lg font-semibold text-foreground",e),...t}));Oh.displayName=rr.displayName;const Dh=v.forwardRef(({className:e,...t},n)=>u.jsx(_s,{ref:n,className:te("text-sm text-muted-foreground",e),...t}));Dh.displayName=_s.displayName;var Gs="Switch",[ST,ck]=Tn(Gs),[CT,TT]=ST(Gs),Lh=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),g=$e(t,S=>h(S)),m=v.useRef(!1),y=p?d||!!p.closest("form"):!0,[x,b]=pr({prop:o,defaultProp:s??!1,onChange:c,caller:Gs});return u.jsxs(CT,{scope:n,checked:x,disabled:a,children:[u.jsx(Ne.button,{type:"button",role:"switch","aria-checked":x,"aria-required":i,"data-state":zh(x),"data-disabled":a?"":void 0,disabled:a,value:l,...f,ref:g,onClick:pe(e.onClick,S=>{b(k=>!k),y&&(m.current=S.isPropagationStopped(),m.current||S.stopPropagation())})}),y&&u.jsx(Bh,{control:p,bubbles:!m.current,name:r,value:l,checked:x,required:i,disabled:a,form:d,style:{transform:"translateX(-100%)"}})]})});Lh.displayName=Gs;var $h="SwitchThumb",Fh=v.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,o=TT($h,n);return u.jsx(Ne.span,{"data-state":zh(o.checked),"data-disabled":o.disabled?"":void 0,...r,ref:t})});Fh.displayName=$h;var kT="SwitchBubbleInput",Bh=v.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...o},s)=>{const i=v.useRef(null),a=$e(i,s),l=zp(n),c=qc(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 g=new Event("click",{bubbles:r});h.call(d,n),d.dispatchEvent(g)}},[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}})});Bh.displayName=kT;function zh(e){return e?"checked":"unchecked"}var Uh=Lh,ET=Fh;const Un=v.forwardRef(({className:e,...t},n)=>u.jsx(Uh,{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(ET,{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")})}));Un.displayName=Uh.displayName;const IT={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 AT({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 p=()=>{t(a),d(!1),f({title:"Settings saved",description:"Your chat configuration has been updated successfully."})},h=()=>{l(IT),d(!0),f({title:"Settings reset",description:"Configuration has been reset to defaults."})},g=()=>{l(e),d(!1),o(!1)},m=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(yT,{open:r,onOpenChange:o,children:[u.jsx(vT,{asChild:!0,children:u.jsxs(Je,{variant:"outline",size:"sm",className:n,children:[u.jsx(le.Settings,{className:"h-4 w-4 mr-2"}),"Settings",c&&u.jsx(bf,{variant:"destructive",className:"ml-2 h-4 w-4 p-0"})]})}),u.jsxs(Rh,{className:"w-[500px] sm:w-[600px] overflow-y-auto",children:[u.jsxs(Ph,{children:[u.jsx(Oh,{children:"Chat Settings"}),u.jsx(Dh,{children:"Configure your chat interface, API connection, and behavior preferences."})]}),u.jsxs("div",{className:"space-y-6 py-6",children:[u.jsxs(ao,{children:[u.jsx(lo,{className:"pb-3",children:u.jsxs(co,{className:"text-lg flex items-center gap-2",children:[u.jsx(le.Server,{className:"h-5 w-5"}),"API Configuration"]})}),u.jsxs(uo,{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(Fs,{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(Je,{variant:"outline",onClick:m,children:"Test"})]})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(tn,{htmlFor:"enable-auth",children:"Enable Authentication"}),u.jsx(Un,{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(Fs,{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(Je,{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(ao,{children:[u.jsx(lo,{className:"pb-3",children:u.jsxs(co,{className:"text-lg flex items-center gap-2",children:[u.jsx(le.Layout,{className:"h-5 w-5"}),"Interface Settings"]})}),u.jsxs(uo,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(tn,{htmlFor:"layout",children:"Layout Style"}),u.jsxs(Th,{value:a.ui.layout,onValueChange:y=>l(x=>({...x,ui:{...x.ui,layout:y}})),children:[u.jsx(Ha,{children:u.jsx(kh,{})}),u.jsxs(Wa,{children:[u.jsx(ar,{value:"sidebar",children:"Sidebar Layout"}),u.jsx(ar,{value:"fullscreen",children:"Fullscreen"}),u.jsx(ar,{value:"tabs",children:"Tabbed Interface"})]})]})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx(tn,{htmlFor:"theme",children:"Theme"}),u.jsxs(Th,{value:a.ui.theme,onValueChange:y=>l(x=>({...x,ui:{...x.ui,theme:y}})),children:[u.jsx(Ha,{children:u.jsx(kh,{})}),u.jsxs(Wa,{children:[u.jsx(ar,{value:"light",children:"Light"}),u.jsx(ar,{value:"dark",children:"Dark"}),u.jsx(ar,{value:"system",children:"System"})]})]})]}),u.jsx(jh,{}),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(Un,{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(Un,{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(Un,{id:"compact-messages",checked:a.ui.compactMessages,onCheckedChange:y=>l(x=>({...x,ui:{...x.ui,compactMessages:y}}))})]})]})]})]}),u.jsxs(ao,{children:[u.jsx(lo,{className:"pb-3",children:u.jsxs(co,{className:"text-lg flex items-center gap-2",children:[u.jsx(le.MessageCircle,{className:"h-5 w-5"}),"Behavior Settings"]})}),u.jsxs(uo,{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(Un,{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(Un,{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(Un,{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(Je,{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(Je,{variant:"outline",onClick:g,children:"Cancel"}),u.jsxs(Je,{onClick:p,disabled:!c,children:[u.jsx(le.Save,{className:"h-4 w-4 mr-2"}),"Save Changes"]})]})]})]})]})}function NT({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(Ro,{...s,onThreadChange:l,children:u.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:u.jsx($s,{className:"flex-1",onError:s.onError,enableFileUpload:!0})})}):e==="tabs"?u.jsx(Ro,{...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($s,{onError:s.onError,enableFileUpload:!0})})]})})}):u.jsx(Ro,{...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($s,{onError:s.onError,enableFileUpload:!0})})]})})}Se.ChatApi=Fl,Se.ChatInput=dc,Se.ChatInterface=$s,Se.ChatProviders=Ro,Se.ChatSettings=AT,Se.MarkdownContent=io,Se.MessageComponent=Ls,Se.MessageList=_a,Se.ThreadManager=Da,Se.TimelineColumn=NC,Se.applySettings=PC,Se.buildMessagePreviewMap=Vg,Se.chatApiClient=_n,Se.default=NT,Se.del=$l,Se.get=Gt,Se.getChatToken=Ol,Se.getCurrentSettings=RC,Se.getDefaultApiConfig=Dp,Se.getDefaultChatSettings=Lp,Se.onChatTokenChanged=Dl,Se.post=ui,Se.put=Ll,Se.setChatToken=Io,Se.useApi=di,Se.useChatStream=Gl,Se.useMessagesReducer=Jl,Se.useStream=cc,Se.useThreadState=Mo,Se.useThreads=jo,Object.defineProperties(Se,{__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=sp(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=sp(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 up{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 dp{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 Fn{constructor(t){this.options=t||or,this.options.renderer=this.options.renderer||new _a,this.renderer=this.options.renderer,this.renderer.options=this.options,this.textRenderer=new up,this.slugger=new dp}static parse(t,n){return new Fn(n).parse(t)}static parseInline(t,n){return new Fn(n).parseInline(t)}parse(t,n=!0){let r="",o,s,i,a,l,c,d,f,p,h,g,m,y,x,w,S,k,C,T;const E=t.length;for(o=0;o<E;o++){if(h=t[o],this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[h.type]&&(T=this.options.extensions.renderers[h.type].call({parser:this},h),T!==!1||!["space","hr","heading","code","table","blockquote","list","html","paragraph","text"].includes(h.type))){r+=T||"";continue}switch(h.type){case"space":continue;case"hr":{r+=this.renderer.hr();continue}case"heading":{r+=this.renderer.heading(this.parseInline(h.tokens),h.depth,op(this.parseInline(h.tokens,this.textRenderer)),this.slugger);continue}case"code":{r+=this.renderer.code(h.text,h.lang,h.escaped);continue}case"table":{for(f="",d="",a=h.header.length,s=0;s<a;s++)d+=this.renderer.tablecell(this.parseInline(h.header[s].tokens),{header:!0,align:h.align[s]});for(f+=this.renderer.tablerow(d),p="",a=h.rows.length,s=0;s<a;s++){for(c=h.rows[s],d="",l=c.length,i=0;i<l;i++)d+=this.renderer.tablecell(this.parseInline(c[i].tokens),{header:!1,align:h.align[i]});p+=this.renderer.tablerow(d)}r+=this.renderer.table(f,p);continue}case"blockquote":{p=this.parse(h.tokens),r+=this.renderer.blockquote(p);continue}case"list":{for(g=h.ordered,m=h.start,y=h.loose,a=h.items.length,p="",s=0;s<a;s++)w=h.items[s],S=w.checked,k=w.task,x="",w.task&&(C=this.renderer.checkbox(S),y?w.tokens.length>0&&w.tokens[0].type==="paragraph"?(w.tokens[0].text=C+" "+w.tokens[0].text,w.tokens[0].tokens&&w.tokens[0].tokens.length>0&&w.tokens[0].tokens[0].type==="text"&&(w.tokens[0].tokens[0].text=C+" "+w.tokens[0].tokens[0].text)):w.tokens.unshift({type:"text",text:C}):x+=C),x+=this.parse(w.tokens,y),p+=this.renderer.listitem(x,k,S);r+=this.renderer.list(p,g,m);continue}case"html":{r+=this.renderer.html(h.text);continue}case"paragraph":{r+=this.renderer.paragraph(this.parseInline(h.tokens));continue}case"text":{for(p=h.tokens?this.parseInline(h.tokens):h.text;o+1<E&&t[o+1].type==="text";)h=t[++o],p+=`
|
|
135
|
+
`+(h.tokens?this.parseInline(h.tokens):h.text);r+=n?this.renderer.paragraph(p):p;continue}default:{const N='Token with "'+h.type+'" type was not found.';if(this.options.silent){console.error(N);return}else throw new Error(N)}}}return r}parseInline(t,n){n=n||this.renderer;let r="",o,s,i;const a=t.length;for(o=0;o<a;o++){if(s=t[o],this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[s.type]&&(i=this.options.extensions.renderers[s.type].call({parser:this},s),i!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(s.type))){r+=i||"";continue}switch(s.type){case"escape":{r+=n.text(s.text);break}case"html":{r+=n.html(s.text);break}case"link":{r+=n.link(s.href,s.title,this.parseInline(s.tokens,n));break}case"image":{r+=n.image(s.href,s.title,s.text);break}case"strong":{r+=n.strong(this.parseInline(s.tokens,n));break}case"em":{r+=n.em(this.parseInline(s.tokens,n));break}case"codespan":{r+=n.codespan(s.text);break}case"br":{r+=n.br();break}case"del":{r+=n.del(this.parseInline(s.tokens,n));break}case"text":{r+=n.text(s.text);break}default:{const l='Token with "'+s.type+'" type was not found.';if(this.options.silent){console.error(l);return}else throw new Error(l)}}}return r}}class Ds{constructor(t){this.options=t||or}preprocess(t){return t}postprocess(t){return t}}qh(Ds,"passThroughHooks",new Set(["preprocess","postprocess"]));function aC(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>"+jt(r.message+"",!0)+"</pre>";if(t)return Promise.resolve(o);if(n){n(null,o);return}return o}if(t)return Promise.reject(r);if(n){n(r);return}throw r}}function fp(e,t){return(n,r,o)=>{typeof r=="function"&&(o=r,r=null);const s={...r};r={...xe.defaults,...s};const i=aC(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(oC(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&&xe.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;xe.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(xe.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&&xe.walkTokens(a,r.walkTokens);let l=t(a,r);return r.hooks&&(l=r.hooks.postprocess(l)),l}catch(a){return i(a)}}}function xe(e,t,n){return fp($n.lex,Fn.parse)(e,t,n)}xe.options=xe.setOptions=function(e){return xe.defaults={...xe.defaults,...e},VS(xe.defaults),xe},xe.getDefaults=ep,xe.defaults=or,xe.use=function(...e){const t=xe.defaults.extensions||{renderers:{},childTokens:{}};e.forEach(n=>{const r={...n};if(r.async=xe.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=xe.defaults.renderer||new _a;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=xe.defaults.tokenizer||new Na;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=xe.defaults.hooks||new Ds;for(const s in n.hooks){const i=o[s];Ds.passThroughHooks.has(s)?o[s]=a=>{if(xe.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=xe.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}}xe.setOptions(r)})},xe.walkTokens=function(e,t){let n=[];for(const r of e)switch(n=n.concat(t.call(xe,r)),r.type){case"table":{for(const o of r.header)n=n.concat(xe.walkTokens(o.tokens,t));for(const o of r.rows)for(const s of o)n=n.concat(xe.walkTokens(s.tokens,t));break}case"list":{n=n.concat(xe.walkTokens(r.items,t));break}default:xe.defaults.extensions&&xe.defaults.extensions.childTokens&&xe.defaults.extensions.childTokens[r.type]?xe.defaults.extensions.childTokens[r.type].forEach(function(o){n=n.concat(xe.walkTokens(r[o],t))}):r.tokens&&(n=n.concat(xe.walkTokens(r.tokens,t)))}return n},xe.parseInline=fp($n.lexInline,Fn.parseInline),xe.Parser=Fn,xe.parser=Fn.parse,xe.Renderer=_a,xe.TextRenderer=up,xe.Lexer=$n,xe.lexer=$n.lex,xe.Tokenizer=Na,xe.Slugger=dp,xe.Hooks=Ds,xe.parse=xe,xe.options,xe.setOptions,xe.use,xe.walkTokens,xe.parseInline,Fn.parse,$n.lex;function io({content:e,className:t="",allowHtml:n=!1,style:r}){const o=b.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 xe.parse=="function"?xe.parse(i):xe(i)}return typeof xe.parse=="function"?xe.parse(e):xe(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=b.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 lC={MODE:"library"};function cC(){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:Xs&&Xs.tagName.toUpperCase()==="SCRIPT"&&Xs.src||new URL("index.umd.js",document.baseURI).href}<"u"?lC: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 uC(){return!cC()}function dC(){return typeof window>"u"?!1:window.__ARTIFACT_DEBUG__===!0}function fC(){return uC()||dC()}function pC({preview:e,idx:t}){return b.useEffect(()=>{fC()&&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 ao=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}));ao.displayName="Card";const lo=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:te("flex flex-col space-y-1.5 p-6",e),...t}));lo.displayName="CardHeader";const co=v.forwardRef(({className:e,...t},n)=>u.jsx("h3",{ref:n,className:te("text-2xl font-semibold leading-none tracking-tight",e),...t}));co.displayName="CardTitle";const pp=v.forwardRef(({className:e,...t},n)=>u.jsx("p",{ref:n,className:te("text-sm text-muted-foreground",e),...t}));pp.displayName="CardDescription";const uo=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:te("p-6 pt-0",e),...t}));uo.displayName="CardContent";const hp=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:te("flex items-center p-6 pt-0",e),...t}));hp.displayName="CardFooter";function hC({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=oo(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(ao,{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(lo,{className:"pb-3",children:[u.jsx(co,{className:"text-blue-900 dark:text-blue-100 text-base",children:i}),u.jsx(pp,{className:"text-blue-700 dark:text-blue-300 text-sm",children:l})]}),a&&u.jsx(uo,{className:"pt-0 pb-3",children:a}),u.jsx(hp,{className:"pt-0",children:u.jsxs("div",{className:"flex gap-2 ml-auto",children:[u.jsx(Je,{size:"sm",variant:"outline",onClick:()=>n(e),className:"border-red-300 text-red-700 hover:bg-red-50 dark:border-red-700 dark:text-red-300 dark:hover:bg-red-950/50",disabled:r||!o,children:"Reject"}),u.jsx(Je,{size:"sm",onClick:()=>t(e),className:"bg-blue-600 hover:bg-blue-700 text-white",disabled:r||!o,children:"Approve"})]})})]})}const mC="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 mp({data:e}){return Array.isArray(e)?e.every(n=>n===null||["string","number","boolean"].includes(typeof n))?u.jsx("div",{className:mC,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:oo(e)}):u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:oo(e)})}function gC({message:e,isStreaming:t=!1}){const n=e.name??"tool",r=b.useMemo(()=>{const a=e.additionalKwargs??{};return Array.isArray(a.toolProgress)?[...a.toolProgress]:[]},[e]),s=r.some(a=>a.type==="tool.start"||a.type==="tool.call"||a.type==="message.start")?`Running ${n}…`:void 0;return t||r.length>0?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:[t&&u.jsx(le.Loader,{className:"h-3 w-3 animate-spin"}),u.jsx("span",{children:s??`Running ${n}…`})]}),r.length>0&&u.jsx("div",{className:"space-y-2 text-xs text-muted-foreground",children:r.map((a,l)=>{var c;return u.jsxs("div",{className:"rounded border border-current/10 bg-muted/60 p-2 text-[11px] leading-snug",children:[u.jsxs("div",{className:"mb-1 flex items-center justify-between text-[8px] uppercase tracking-wide text-muted-foreground",children:[u.jsx("span",{children:((c=a.type)==null?void 0:c.replace(/\./g," "))??"progress"}),u.jsx("span",{children:a.idx??l+1})]}),a.content&&u.jsx("p",{className:"mt-1 text-[12px] text-foreground/90",children:a.content}),u.jsxs("div",{className:"mt-1 flex flex-wrap gap-2 text-[10px] opacity-70",children:[typeof a.factsFound=="number"&&u.jsxs("span",{children:["Facts found: ",a.factsFound]}),typeof a.isSufficient=="boolean"&&u.jsxs("span",{children:["Research ",a.isSufficient?"sufficient":"needs more data"]})]})]},`tool-progress-${n}-${l}`)})})]}):null}function xC({message:e,viewMode:t,isStreaming:n=!1}){const o=Ef(e).name||"tool",s=l=>{if(l==null)return null;const c=typeof l=="string"?Sa(l)??l:l;if(c&&typeof c=="object")return u.jsx(mp,{data:c});const d=typeof c=="string"?c:(()=>{try{return oo(c)}catch{return String(c??"")}})();return u.jsx("pre",{className:"whitespace-pre-wrap break-words font-sans text-sm text-foreground/90",children:d})},i=l=>{if(l==null)return null;const{content:c,isMarkdown:d}=gS(l);return d?u.jsx(io,{content:c,className:"text-current"}):s(l)},a=()=>{const l=e.content.find(f=>f.type!=="tool_call");if(!l)return u.jsx("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:u.jsxs("span",{children:["Running ",o,"…"]})});if(l.type==="text"){const p=(l.text??"").trim();if(!p)return null;const h=Ts(p);return i(h)}const c=ro(l),d=Ts(c);return i(d)};return u.jsxs("div",{className:"space-y-2",children:[u.jsx(gC,{message:e,isStreaming:n}),t==="expanded"&&a()]})}function yC(e){const{allowFileOpen:t,currentThreadId:n}=e,{toast:r}=Aa(),[o,s]=b.useState({}),[i,a]=b.useState(null),[l,c]=b.useState(!1),d=b.useCallback(()=>{c(!1),a(null)},[]),f=b.useCallback(h=>{a(h),c(!0)},[]),p=b.useCallback(async(h,g,m)=>{var y,x;if(!t){h.preventDefault();return}if(o[m]){h.preventDefault();return}try{const w=String(g.url??""),S=w.match(/\/chat\/files\/([^/]+)(?:\/(view|download))?/);if(S){h.preventDefault();const k=S[1],C=g.name||`file_${k}`,T=g.mimeType||"application/octet-stream";f({id:k,name:C,mimeType:T});return}if(w.startsWith("data:")){h.preventDefault(),s(C=>({...C,[m]:!0}));const k=r({title:"Fetching file...",description:"",open:!0});try{const C=await kS(n??void 0);if(!C||!Array.isArray(C))throw new Error("Invalid file list response");const T=C.find(E=>!E||typeof E!="object"||!((E.filename??"")===(g.name??""))?!1:typeof g.size=="number"&&typeof E.size=="number"?E.size===g.size:!0);if(!(T!=null&&T.id))throw new Error(`File "${g.name}" is not yet available on the server`);if(!T.id||!T.filename)throw new Error("Invalid file data received from server");f({id:T.id,name:g.name||T.filename||`file_${T.id}`,mimeType:g.mimeType||T.mime_type||"application/octet-stream"}),(y=k.update)==null||y.call(k,{id:k.id,title:"Success",description:`Opened ${g.name}`,open:!0})}catch(C){console.error("Failed to fetch server file:",C);const T=C instanceof Error?C.message:"Unknown error occurred";(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,[m]:!1}))}}}catch(w){console.error("File click error:",w),s(S=>({...S,[m]:!1}))}},[t,o,r,n,f]);return{uploadingFiles:o,handleFileClick:p,fileViewerOpen:l,currentFileInfo:i,closeFileViewer:d}}function vC({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(io,{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(Je,{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 wC({className:e}){const[t,n]=b.useState(0);return b.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)]})}function gp(e){var n;const t=(n=e.additionalKwargs)==null?void 0:n.toolProgress;return Array.isArray(t)?t:[]}const Ls=b.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:g,onRegenerate:m,onCancelEdit:y,onCopy:x,activeInterrupt:w,disableInterruptActions:S=!1,onInterruptActionStart:k,onInterruptActionEnd:C,checkpointCandidates:T=[],activeCheckpointId:E=null,onSelectCheckpoint:N,defaultCheckpointId:_=null,messageParentCheckpointId:D=null}){const[B,G]=b.useState(!1),[V,P]=b.useState("preview"),[M,A]=b.useState(!1),{currentThreadId:F}=jo(),{respondToInterrupt:L}=Mo(),R=l==="phone"||l==="half-screen",z=t.role,X=z==="tool",ne=b.useMemo(()=>"type"in t&&t.type==="default_message"?t:null,[t]),ye=!!ne,Te=!(r&&z!=="user"),{uploadingFiles:q,handleFileClick:U,fileViewerOpen:Z,currentFileInfo:$,closeFileViewer:Y}=yC({allowFileOpen:Te,currentThreadId:F}),Q=b.useMemo(()=>{switch(z){case"user":return"text-[hsl(var(--chat-bubble-user-text))]";case"assistant":return"text-[hsl(var(--chat-bubble-ai-text))]";case"tool":return"text-secondary-foreground";case"system":return"text-muted-foreground";default:return"text-[hsl(var(--chat-bubble-ai-text))]"}},[z]),de=b.useMemo(()=>{if(ne)return"";const j=t.content;return Array.isArray(j)?xS(j):""},[ne,t]),oe=b.useMemo(()=>{if(ne)return{};const j=t.content;return Array.isArray(j)?Ef(t):{}},[ne,t]),_e=b.useMemo(()=>X?!!(t.additionalKwargs??{}).toolStreaming:!1,[X,t]),ze=b.useMemo(()=>{if(ne)return[];const j=t.content;return Array.isArray(j)?j.filter(J=>J.type==="image_url"):[]},[ne,t]),se=b.useMemo(()=>{if(ne)return[];const j=t.content;return Array.isArray(j)?j.filter(J=>J.type==="file"):[]},[ne,t]),me=b.useMemo(()=>{if(ne)return[];const j=t.content;return Array.isArray(j)?j.filter(J=>J.type==="interrupt"):[]},[ne,t]),Pe=(w==null?void 0:w.id)??(w==null?void 0:w.interrupt_id),Ve=ks(Pe),ut=w==null?void 0:w.value,Ke=b.useMemo(()=>{if(ne)return"";const j=t.content;return Array.isArray(j)?yS(j):""},[ne,t]),qe=b.useMemo(()=>{if(ne||!p)return[];const J=t.artifact;if(!J)return[];const re=[],ie=[...Array.isArray(J.plots)?J.plots:[]];for(const ce of ie){const Xe=CS(ce);Xe&&re.push(Xe)}return re},[ne,t,p]),Qe=b.useCallback(async()=>{const j=X?Ke:de;async function J(re){if(navigator.clipboard&&typeof navigator.clipboard.writeText=="function"){await navigator.clipboard.writeText(re);return}if(navigator.clipboard&&typeof navigator.clipboard.write=="function"&&typeof ClipboardItem<"u"){const ie=new Blob([re],{type:"text/plain"});await navigator.clipboard.write([new ClipboardItem({"text/plain":ie})]);return}throw new Error("Clipboard API not supported in this context.")}try{await J(j),G(!0),setTimeout(()=>G(!1),2e3),x==null||x(j)}catch(re){console.error("Failed to copy:",re)}},[X,Ke,de,x]),Ge=b.useCallback(()=>{if(!g)return;const j=X?Ke:de,J="type"in t&&t.type==="default_message"?void 0:{checkpointId:t.checkpointId??null,checkpointNs:t.checkpointNs??null};g(t.id,j,J)},[g,t.id,X,Ke,de,t]),et=b.useCallback(()=>{m==null||m(n)},[m,n]),st=b.useCallback(()=>{const J=te(R?"h-3 w-3":"h-4 w-4","opacity-60 flex-shrink-0",Q);switch(z){case"user":return u.jsx(le.User,{className:J});case"assistant":return u.jsx(le.Bot,{className:J});case"tool":return u.jsx(le.Wrench,{className:J});default:return u.jsx(le.Bot,{className:J})}},[R,Q,z]),Mt=b.useCallback(()=>{const j="group relative mb-4 flex w-full";switch(z){case"user":return te(j,"justify-end");case"assistant":case"tool":case"system":return te(j,"justify-start");default:return j}},[z]),gt=b.useCallback(()=>{const j=te("rounded-lg px-4 py-3 relative min-w-0 max-w-full break-words",R&&"px-3 py-2 text-sm");if(ye)return te(j,"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(z){case"user":return te(j,"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(j,"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(j,"w-full md:max-w-[95%] bg-secondary/50 text-secondary-foreground border border-dashed");case"system":return te(j,"w-full md:max-w-[85%] bg-accent/40 text-muted-foreground border");default:return te(j,"w-full md:max-w-[95%]","bg-[hsl(var(--chat-bubble-ai))] text-[hsl(var(--chat-bubble-ai-text))]","border border-border/60 dark:border-border/40")}},[R,ye,z]),Ct=b.useCallback(async j=>{if(S)return;const J=ks((j==null?void 0:j.id)??(j==null?void 0:j.interrupt_id));if(!J){console.warn("Interrupt part missing id",j);return}try{k==null||k(),await L(J,!0)}catch(re){console.error("Failed to approve interrupt:",re)}finally{C==null||C()}},[S,C,k,L]),it=b.useCallback(async j=>{if(S)return;const J=ks((j==null?void 0:j.id)??(j==null?void 0:j.interrupt_id));if(!J){console.warn("Interrupt part missing id",j);return}try{k==null||k(),await L(J,!1)}catch(re){console.error("Failed to reject interrupt:",re)}finally{C==null||C()}},[S,C,k,L]),St=b.useCallback(({part:j,i:J})=>{if(j.type==="text"){const re=j.text??"",ie=re.trim(),ce=Sa(ie);return ce&&z!=="tool"?u.jsx(mp,{data:ce},J):z==="user"&&c&&ie.length>d?u.jsx(vC,{text:ie,expanded:M,onExpandedChange:A,previewLength:d,isCompact:R},J):u.jsx(io,{content:re,allowHtml:!1},J)}if(j.type==="image_url"){const re=j;return u.jsx("div",{className:"my-2",children:u.jsx("img",{src:re.url,alt:re.alt??"",loading:"lazy",className:"border rounded max-h-[420px] w-auto object-contain"})},J)}if(j.type==="file"){const re=j,ie=re.name||"file";return u.jsxs("a",{href:re.url,onClick:ce=>U(ce.nativeEvent,re,J),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:[q[J]?u.jsx(le.Loader,{className:"h-4 w-4 animate-spin"}):null,u.jsxs("span",{className:"truncate max-w-[180px]",children:[ie,q[J]?" (processing)":""]})]},J)}if(j.type==="interrupt"){const re=j,ie=ks((re==null?void 0:re.id)??(re==null?void 0:re.interrupt_id)),ce=!!(Ve&&ie&&ie===Ve),Xe=ce?ut??(re==null?void 0:re.value):re==null?void 0:re.value,Ie=ie?{...re,id:ie,interrupt_id:ie}:re;return u.jsx(hC,{interruptPart:Ie,onApprove:Ct,onReject:it,disabled:S,isActive:ce,payload:Xe},J)}return null},[U,q,Ct,it,z,c,d,M,R,Ve,ut,w,S,me]),Pt=b.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"})]}),[]),zt=b.useCallback(()=>{const j=de.trim().length>0||ze.length>0||se.length>0||me.length>0;if(!X&&se.length>0&&!r)return Pt();if(!X&&!j&&!r)return null;if(X)return!f&&qe.length>0?null:f?u.jsx(xC,{message:t,viewMode:V,isStreaming:_e},t.id):null;if(!X&&!ne){const J=t,re=u.jsx("div",{className:"space-y-2",children:J.content.map((ie,ce)=>u.jsx(St,{part:ie,i:ce},ce))});return r?u.jsxs("div",{"aria-busy":"true",role:"status",children:[re,u.jsx(wC,{className:Q})]}):re}},[de,ze.length,se.length,me.length,r,X,V,f,qe.length,Pt,Q]),nn=b.useMemo(()=>ne?"Assistant":vS(t),[ne,t]),Le=b.useMemo(()=>ne?[]:Array.isArray(T)?T:[],[T,ne]),Sn=b.useMemo(()=>{var j;return Le.length?_&&Le.some(J=>J.id===_)?_:((j=Le[0])==null?void 0:j.id)??null:null},[_,Le]),We=b.useMemo(()=>!Le.length||!E?null:Le.some(j=>j.id===E)?E:null,[E,Le])??Sn,pt=z==="user"&&Le.length>0&&typeof N=="function",Rt=b.useCallback((j,J=!1)=>{if(!N)return;const re=(j==null?void 0:j.id)??null,ie=(j==null?void 0:j.parentId)??D??null;N(re,ie,J)},[D,N]),Ye=b.useMemo(()=>We?Le.findIndex(j=>j.id===We):-1,[We,Le]),H=b.useMemo(()=>Ye<0?null:Le[Ye]??null,[Ye,Le]);return X&&!f&&qe.length===0?null:ye&&ne?u.jsx("div",{className:te(Mt(),h.container),children:u.jsxs("div",{className:te(gt(),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",Q)}),a&&u.jsx("span",{className:"font-medium text-sm",children:"Assistant"})]}),u.jsx(io,{content:ne.content,className:"text-current"})]})}):u.jsxs(u.Fragment,{children:[u.jsx("div",{className:te(Mt(),h.container),children:u.jsxs("div",{className:te(gt(),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",R&&"mb-1 pb-1",Q,h.header),children:[u.jsxs("div",{className:"flex items-center gap-2",children:[st(),a&&nn&&u.jsx("span",{className:te("font-medium",R?"text-xs":"text-sm"),children:nn}),X&&u.jsxs(Tf,{variant:"outline",className:te("text-xs flex items-center gap-1 cursor-pointer select-none",Q,"border border-current/40",R&&"text-xs h-4"),role:"button",tabIndex:0,"aria-expanded":V==="expanded",onClick:()=>P(j=>j==="expanded"?"preview":"expanded"),onKeyDown:j=>{(j.key==="Enter"||j.key===" ")&&(j.preventDefault(),P(J=>J==="expanded"?"preview":"expanded"))},children:[u.jsx("span",{children:oe.name??"Tool Output"}),oe.toolCallId&&u.jsx("span",{className:"opacity-70",children:oe.toolCallId.slice(0,8)}),V==="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:[pt&&H&&Ye>=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",Ye<Le.length-1?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(Ye>=Le.length-1)return;const j=Le[Ye+1];j&&Rt(j)},"aria-label":"Older checkpoint (back in time)",disabled:Ye>=Le.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:[Le.length-Ye," / ",Le.length]})}),u.jsx("button",{type:"button",className:te("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",Ye>0?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(!(Ye<=0))if(Ye===1)Rt(null,!0);else{const j=Le[Ye-1];j&&Rt(j,!1)}},"aria-label":"Newer checkpoint (forward in time)",disabled:Ye<=0,children:u.jsx(le.ChevronRight,{className:"h-3 w-3"})})]})}),i&&t.createdAt&&u.jsx("time",{className:te("text-xs opacity-60",Q,R&&"text-xs"),dateTime:new Date(t.createdAt).toISOString(),title:new Date(t.createdAt).toLocaleString(),children:new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit"}).format(new Date(t.createdAt))}),s&&!o&&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(Je,{variant:"ghost",size:"sm",onClick:()=>Qe(),className:te("h-6 w-6 p-0 hover:bg-foreground/10",Q,R&&"h-5 w-5"),"aria-label":"Copy message",title:"Copy message",children:u.jsx(le.Copy,{className:te(B?"text-success":Q,R?"h-3 w-3":"h-4 w-4")})})}),z==="user"&&g&&u.jsx(Je,{variant:"ghost",size:"sm",onClick:Ge,className:te("h-6 w-6 p-0 hover:bg-foreground/10",Q,R&&"h-5 w-5"),"aria-label":"Edit message",children:u.jsx(le.Edit,{className:te(Q,R?"h-3 w-3":"h-4 w-4")})}),z==="assistant"&&m&&u.jsx(Je,{variant:"ghost",size:"sm",onClick:et,className:te("h-6 w-6 p-0 hover:bg-foreground/10",Q,R&&"h-5 w-5"),"aria-label":"Regenerate response",children:u.jsx(le.RotateCcw,{className:te(Q,R?"h-3 w-3":"h-4 w-4")})})]})]})]}),u.jsxs("div",{className:"relative",children:[zt(),p&&qe.length>0&&u.jsx("div",{className:"mt-3 space-y-4",children:qe.map((j,J)=>u.jsx(pC,{preview:j,idx:J},`artifact-${J}`))})]}),X&&V==="expanded"&&(oe.toolCallId||oe.name)&&u.jsxs("div",{className:te("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",R&&"text-xs"),children:[oe.name&&u.jsxs("div",{children:["Function: ",oe.name]}),oe.toolCallId&&u.jsxs("div",{children:["Call ID: ",oe.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(Je,{variant:"ghost",size:"sm",onClick:()=>Qe(),className:te("h-6 w-6 p-0 hover:bg-background/50 text-current",R&&"h-5 w-5"),children:u.jsx(le.Copy,{className:te(B?"text-success":"text-current",R?"h-3 w-3":"h-4 w-4")})}),z==="user"&&g&&u.jsx(Je,{variant:"ghost",size:"sm",onClick:Ge,className:te("h-6 w-6 p-0 hover:bg-background/50 text-current",R&&"h-5 w-5"),children:u.jsx(le.Edit,{className:te("text-current",R?"h-3 w-3":"h-4 w-4")})}),z==="assistant"&&m&&u.jsx(Je,{variant:"ghost",size:"sm",onClick:et,className:te("h-6 w-6 p-0 hover:bg-background/50 text-current",R&&"h-5 w-5"),children:u.jsx(le.RotateCcw,{className:te("text-current",R?"h-3 w-3":"h-4 w-4")})})]})]})}),$&&u.jsx(WS,{isOpen:Z,onClose:Y,fileId:$.id,fileName:$.name,mimeType:$.mimeType})]})},(e,t)=>{var l,c,d,f,p,h,g,m;if(t.isStreamingMessage||e.isStreamingMessage||!(e.message.id===t.message.id&&If(e.message)===If(t.message)))return!1;const o=["isEditing","showActions","layoutSize","showTimestamp","showAgentName","truncateUserMessages","userMessagePreviewLength","showToolMessages","attemptMeta"].every(y=>e[y]===t[y]),s=((l=e.customStyles)==null?void 0:l.container)===((c=t.customStyles)==null?void 0:c.container)&&((d=e.customStyles)==null?void 0:d.content)===((f=t.customStyles)==null?void 0:f.content)&&((p=e.customStyles)==null?void 0:p.actions)===((h=t.customStyles)==null?void 0:h.actions)&&((g=e.customStyles)==null?void 0:g.header)===((m=t.customStyles)==null?void 0:m.header);if(!o||!s)return!1;const i=gp(e.message),a=gp(t.message);return i.length===a.length});Ls.displayName="MessageComponent";function bC(e,t){return b.useMemo(()=>{var d,f,p,h,g;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 m=e,y=m.checkpointId??null;s=m.additionalKwargs??{},i=m.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 w=typeof s.source=="string"?s.source:typeof i.source=="string"?i.source:(x==null?void 0:x.source)??null;l=w?String(w):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?((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 C=k[0].checkpointId;c=((h=t.attemptMetaById)==null?void 0:h.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,E]of t.attemptMetaById.entries())if(E.baseUserMessageId===k){const N=(g=t.checkpointMetaById)==null?void 0:g.get(T);N&&C.push(N)}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 E=t.attemptMetaById.get(C);E&&E.attemptCount===c.attemptCount&&E.baseUserMessageId===c.baseUserMessageId&&k.push(T)}k.sort((C,T)=>{const E=C.createdAt?Date.parse(C.createdAt):0;return(T.createdAt?Date.parse(T.createdAt):0)-E}),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 xp=(e,t)=>(e==null?void 0:e.id)??`message-${t}`,yp=b.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:g,onInterruptActionEnd:m,showToolMessages:y,showArtifactPreviews:x,checkpointMetaById:w,checkpointIndexByKey:S,attemptMetaById:k,userMessageIdToAttempts:C,activeCheckpointId:T,onSelectCheckpoint:E}){const N=xp(t,n),_="type"in t&&t.type==="default_message",{checkpointCandidates:D,defaultCheckpointId:B,attemptMeta:G}=bC(t,{checkpointMetaById:w,checkpointIndexByKey:S,attemptMetaById:k,userMessageIdToAttempts:C}),V=t&&!_?t.additionalKwargs??{}:{},P=t&&!_?t.responseMetadata??{}:{},M=(()=>{if(typeof V.parentCheckpointId=="string")return V.parentCheckpointId;if(typeof P.parentCheckpointId=="string")return P.parentCheckpointId})();return u.jsx("div",{className:"relative mb-4 last:mb-0","data-message-id":N,style:{minHeight:"60px",containIntrinsicSize:"auto 120px"},children:u.jsx(Ls,{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:g,onInterruptActionEnd:m,showToolMessages:y,showArtifactPreviews:x,checkpointCandidates:D,activeCheckpointId:T??null,onSelectCheckpoint:E,defaultCheckpointId:B,messageParentCheckpointId:M,attemptMeta:G})})});yp.displayName="MessageRow";const ja=b.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:g=!0,isNavigatingCheckpoint:m=!1,onScrollAway:y,onAtBottom:x,activeInterrupt:w,disableInterruptActions:S=!1,onInterruptActionStart:k,onInterruptActionEnd:C,showToolMessages:T=!0,showArtifactPreviews:E=!0,checkpointMetaById:N,checkpointIndexByKey:_,attemptMetaById:D,userMessageIdToAttempts:B,activeCheckpointId:G,onSelectCheckpoint:V,createSyntheticThinkingMessage:P=!1},M)=>{const A=b.useRef(null),F=b.useRef(null),L=b.useRef(!1),R=b.useRef(!1),[z,X]=b.useState(!0),ne=b.useMemo(()=>w?e.some(se=>"type"in se&&se.type==="default_message"?!1:Array.isArray(se==null?void 0:se.content)&&se.content.some(me=>me&&me.type==="interrupt"&&(me.id??me.interrupt_id)===w.id)):!1,[w,e]),ye=b.useMemo(()=>{if(!w||ne)return null;const se=w.id&&String(w.id).trim()?String(w.id).trim():"pending-interrupt";let me;const Pe=w.value;if(Pe&&typeof Pe=="object"&&!Array.isArray(Pe)){const Ve=Pe.title;typeof Ve=="string"&&Ve.trim()&&(me=Ve.trim())}return{id:`interrupt-${se}`,role:"system",createdAt:new Date().toISOString(),content:[{type:"interrupt",id:se,value:Pe,title:me}]}},[w,ne]),Te=b.useMemo(()=>ye?[...e,ye]:e,[e,ye]),q=b.useMemo(()=>!P||!t?Te:!Te.some(me=>me.role==="assistant")&&Te.length>0?[...Te,{id:"thinking-assistant",role:"assistant",content:[],createdAt:new Date().toISOString()}]:Te,[Te,t,P]),U=b.useMemo(()=>T?q:q.filter(se=>(se==null?void 0:se.role)!=="tool"),[q,T]),Z=b.useCallback(se=>{X(se),y&&y(!se),x&&x(se)},[y,x]),$=b.useMemo(()=>{if(a)return async()=>{if(!L.current){L.current=!0;try{await a()}finally{L.current=!1}}}},[a]),Y=b.useMemo(()=>!g||m?!1:z?"auto":!1,[z,g,m]),Q=b.useMemo(()=>{if(typeof h!="string")return null;const se=h.trim();return se?{id:"default-message",role:"assistant",type:"default_message",content:se,createdAt:new Date().toISOString()}:null},[h]),de=["flex h-full flex-col md:flex-row",f].filter(Boolean).join(" "),oe=()=>Q?u.jsx("div",{className:"p-6 h-full overflow-y-auto",children:u.jsx("div",{className:"w-full max-w-full",children:u.jsx(Ls,{message:Q,messageIndex:0,isStreamingMessage:!1,showActions:!1,showTimestamp:!1,showAgentName:!0,layoutSize:o,onEdit:()=>{},onRegenerate:()=>{},onCancelEdit:()=>{},showArtifactPreviews:E})})}):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,ze=_e>0;return b.useEffect(()=>{var se,me;if(_e===0){R.current=!1;return}if(!R.current)if(R.current=!0,A.current&&U.length>0){const Pe=U.length-1;(me=(se=A.current).scrollToIndex)==null||me.call(se,{index:Pe,align:"end",behavior:"auto"})}else F.current&&(F.current.scrollTop=F.current.scrollHeight)},[_e,U.length]),b.useImperativeHandle(M,()=>({scrollToLatest:()=>{var se,me;if(A.current&&U.length>0){const Pe=U.length-1;(me=(se=A.current).scrollToIndex)==null||me.call(se,{index:Pe,align:"end",behavior:"auto"})}else F.current&&(F.current.scrollTop=F.current.scrollHeight)},scrollToTop:()=>{var se,me;A.current&&U.length>0?(me=(se=A.current).scrollToIndex)==null||me.call(se,{index:0,align:"start",behavior:"auto"}):F.current&&(F.current.scrollTop=0)}}),[U]),u.jsx("div",{className:de,style:p,children:u.jsx("div",{className:"relative flex-1 min-h-0",children:ze?u.jsx(Q0,{ref:se=>{A.current=se},scrollerRef:se=>{F.current=se instanceof HTMLDivElement?se:null},data:U,followOutput:Y,overscan:200,increaseViewportBy:{top:100,bottom:200},defaultItemHeight:80,atBottomThreshold:50,startReached:()=>{$&&$()},atBottomStateChange:Z,style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:(se,me)=>xp(me,se),itemContent:(se,me)=>u.jsx(yp,{message:me,index:se,isStreaming:t,streamingAssistantId:n,streamingDebounceMs:r,layoutSize:o,enableMessageEditing:s,editingMessageId:i,onEdit:l,onRegenerate:c,onCancelEdit:d,activeInterrupt:w,disableInterruptActions:S,onInterruptActionStart:k,onInterruptActionEnd:C,showToolMessages:T,showArtifactPreviews:E,checkpointMetaById:N,checkpointIndexByKey:_,attemptMetaById:D,userMessageIdToAttempts:B,activeCheckpointId:G,onSelectCheckpoint:V})}):oe()})})});ja.displayName="MessageList";const vp={value:""};function $s({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:g,onError:m}){const{api:y}=di(),{currentThreadId:x}=jo(),{threadId:w,messages:S,isHistoryLoading:k,isLoading:C,navigateToCheckpoint:T,returnToLatest:E,checkpoint:N,checkpoints:_,interrupt:D,metadata:B,timelineCheckpoints:G,messagePreviews:V}=Mo(),{isStreaming:P,error:M,connectionState:A,submit:F,stop:L}=pc(),R=w??x??null,z=(N==null?void 0:N.id)??null,X=(N==null?void 0:N.namespace)??null,ne=(B==null?void 0:B.assemblingMessageId)??null,ye=D,[Te,q]=b.useState(!1);b.useEffect(()=>{ye||q(!1)},[ye]);const U=b.useCallback(()=>{q(!0)},[]),Z=b.useCallback(()=>{q(!1)},[]),$=!!ye||Te,[Y,Q]=b.useState(null),[de,oe]=b.useState(""),[_e,ze]=b.useState(null),[se,me]=b.useState(null),[Pe,Ve]=b.useState([]),[ut,Ke]=b.useState(0),[qe,Qe]=b.useState(0),[Ge,et]=b.useState(!1),[st,Mt]=b.useState(null),[gt,Ct]=b.useState(null),[it,St]=b.useState(!1),[Pt,zt]=b.useState(null),nn=b.useRef(!1),[Le,Sn]=b.useState(()=>vp.value),tt=b.useRef(Le),We=b.useRef(null),pt=b.useCallback(he=>{vp.value=he,Sn(he)},[]),[Rt,Ye]=b.useState(!1),H=b.useRef(null),{checkpointMetaById:j,checkpointIndexByKey:J,attemptMetaById:re,userMessageIdToAttempts:ie}=Bb(_),ce=G??[],Xe=b.useRef(null),Ie=b.useRef(null),at=b.useCallback(()=>{Xe.current&&(Xe.current.value=""),Ie.current&&(Ie.current.value=""),Ke(he=>he+1),Qe(he=>he+1)},[]),ht=b.useCallback(he=>{pt(he)},[pt]),Kt=b.useRef(!1);b.useEffect(()=>{Kt.current&&!P&&(Ve([]),at()),Kt.current=P},[P,at]);const[Hn,Ar]=b.useState("desktop");b.useEffect(()=>{const he=()=>{const be=window.innerWidth;Ar(be<640?"phone":be<1024?"tablet":"desktop")};return he(),window.addEventListener("resize",he),()=>window.removeEventListener("resize",he)},[]),b.useEffect(()=>{nn.current=!1},[R]),b.useEffect(()=>{tt.current=Le},[Le]),b.useEffect(()=>{if(!Y){We.current=null;return}We.current===null&&(We.current=tt.current),pt(de??"")},[de,Y,pt]),b.useEffect(()=>{(async()=>{if(!y.baseUrl){zt(null);return}try{const Ee=(await y.getAgent("default")).uiDefaultMessage||"";zt(Ee||null)}catch(be){console.warn("Failed to fetch default message:",be),zt(null)}})()},[y.baseUrl]),b.useEffect(()=>{M&&!it&&(m==null||m(M))},[M,it,m]);const Nr=he=>{if(he.length>us)return`Message too long (${he.length}/${us} characters)`;try{return Hb(he),null}catch(be){return(be==null?void 0:be.message)||"Invalid message"}},po=async he=>{const be=he.trim();if(!(!be&&Pe.length===0)){if(be){const Ee=Nr(be);if(Ee){me(Ee);return}}try{const Ee=Y?(_e==null?void 0:_e.checkpointId)??z??void 0:z??void 0,Ue=Y?(_e==null?void 0:_e.checkpointNs)??X??void 0:X??void 0;await F({text:be||"",attachments:Pe},{checkpointId:Ee,checkpointNs:Ue,edit:!!Y,originalMessageId:Y??void 0}),h==null||h(be),pt(""),me(null),Ve([]),at(),Q(null),oe(""),ze(null)}catch(Ee){const Ue=(Ee==null?void 0:Ee.message)||"Failed to send message";me(Ue),m==null||m(Ue)}}},Nn=b.useCallback((he,be,Ee)=>{c&&(We.current=Le,Q(he),oe(be),pt(be),me(null),ze({checkpointId:(Ee==null?void 0:Ee.checkpointId)??null,checkpointNs:(Ee==null?void 0:Ee.checkpointNs)??null}))},[Le,c,pt]),I=b.useCallback(()=>{Q(null),oe(""),ze(null),me(null),pt(We.current??Le),We.current=null},[Le,pt]),W=b.useCallback((he,be,Ee)=>{Nn(he,be,Ee)},[Nn]),ae=b.useCallback(he=>{let be=null;for(let rn=he-1;rn>=0;rn--)if(S[rn].role==="user"){be=S[rn];break}if(!be)return;const Ee=Array.isArray(be.content)?be.content:[],Wn=Ee.filter(rn=>(rn==null?void 0:rn.type)==="text").map(rn=>rn.text).join("")||(()=>{try{return JSON.stringify(Ee,null,2)}catch{return String(Ee)}})();Wn&&F({text:Wn},{checkpointId:z??void 0,checkpointNs:X??void 0,edit:!0,originalMessageId:be.id})},[S,F,z,X]),we=he=>{const be=Array.from(he.target.files||[]);Ve(Ee=>[...Ee,...be]),he.target.value=""},Be=he=>{Ve(be=>{const Ee=be.filter((Ue,Wn)=>he!==Wn);return Ee.length===0&&at(),Ee})},nt=async he=>{const be=(he.target.files||[])[0];if(be){Mt(null),Ct(null),et(!0);try{await F({attachments:[be]},{checkpointId:z??void 0,checkpointNs:X??void 0});const Ee=`Uploaded ${be.name} - processing through chat stream`;Ct(Ee)}catch(Ee){const Ue=Ee instanceof Error?Ee.message:"Failed to upload Excel file";console.error("Excel upload failed",Ee),Mt(Ue),m==null||m(Ue)}finally{et(!1),he.target.value="",at()}}},De=async he=>{if(x){Ye(!0);try{if(!he){await E(),requestAnimationFrame(()=>{var Ue;(Ue=H.current)==null||Ue.scrollToLatest()});return}const be=_.find(Ue=>Ue.checkpointId===he),Ee=(be==null?void 0:be.checkpointNs)??null;await T(he,Ee),requestAnimationFrame(()=>{var Ue;(Ue=H.current)==null||Ue.scrollToTop()})}finally{Ye(!1)}}},Oe=b.useCallback(async(he,be,Ee)=>{await De(Ee?null:he)},[De]),It=`flex flex-1 w-full flex-col min-h-0 min-w-0 max-h-full overflow-hidden bg-transparent ${e} ${p.container||""}`,mt=`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:It,children:[!!M&&!it&&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:M}),u.jsx(Je,{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 ${mt}`,style:r?{maxHeight:r}:void 0,children:[u.jsx(ja,{ref:H,className:"h-full",style:{height:"100%"},messages:S,isStreaming:P,streamingAssistantId:ne,streamingDebounceMs:typeof s=="number"?s:o,followNewMessages:i,layoutSize:Hn,enableMessageEditing:c,editingMessageId:Y,onEdit:W,onRegenerate:ae,onCancelEdit:I,emptyMessage:Pt??void 0,isNavigatingCheckpoint:Rt,activeInterrupt:ye,disableInterruptActions:Te,onInterruptActionStart:U,onInterruptActionEnd:Z,showToolMessages:d,showArtifactPreviews:f,checkpointMetaById:j,checkpointIndexByKey:J,attemptMetaById:re,userMessageIdToAttempts:ie,activeCheckpointId:z,onSelectCheckpoint:Oe,timelineCheckpoints:ce,messagePreviews:V}),(A==="reconnecting"||A==="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"}),A==="reconnecting"?"Reconnecting…":"Connecting…"]})}),A==="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:[Y&&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(Je,{variant:"ghost",size:"sm",onClick:I,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:Xe,type:"file",multiple:!0,onChange:he=>we(he),className:"hidden"},ut),Pe.length>0&&u.jsx("div",{className:"flex flex-wrap gap-2",children:Pe.map((he,be)=>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:he.name}),u.jsx(Je,{variant:"ghost",size:"sm",onClick:()=>Be(be),className:"h-4 w-4 p-0 text-gray-500 dark:text-gray-400 hover:text-red-500 dark:hover:text-red-400","aria-label":`Remove ${he.name}`,children:u.jsx(le.X,{size:12})})]},be))})]}),l&&u.jsxs(u.Fragment,{children:[u.jsx("input",{ref:Ie,type:"file",accept:".xls,.xlsx,.xlsm",onChange:nt,className:"hidden"},qe),Ge&&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..."]}),gt&&!Ge&&u.jsx("div",{className:"text-sm rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-emerald-700",children:gt}),st&&!Ge&&u.jsx("div",{className:"text-sm rounded border border-red-200 bg-red-50 px-3 py-2 text-red-600",children:st})]})]}),se&&u.jsx("div",{className:"mb-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2",children:se}),u.jsxs("div",{className:"flex items-end gap-2",children:[(a||l)&&u.jsxs(Eb,{children:[u.jsx(Ib,{asChild:!0,children:u.jsx(Je,{type:"button",size:"icon",variant:"outline",disabled:P||$,title:"More input actions",className:p.moreButton||"",children:u.jsx(le.Plus,{size:16})})}),u.jsxs(Td,{align:"start",sideOffset:6,className:"w-52",children:[a&&u.jsxs(Zi,{onClick:()=>{var he;return(he=Xe.current)==null?void 0:he.click()},className:"cursor-pointer",children:[u.jsx(le.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]}),l&&u.jsxs(Zi,{onClick:()=>{var he;Ge||(he=Ie.current)==null||he.click()},className:`cursor-pointer ${Ge?"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(Ix,{initialValue:de,editingMessageId:Y,value:Le,onValueChange:ht,placeholder:Y?"Edit your message...":t,isStreaming:P,disabled:$,maxLength:us,onSend:po,onCancelEdit:I,onStop:L,allowEmptySend:Pe.length>0,textareaClassName:`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${Y?"border-blue-400 bg-blue-50 text-blue-900 dark:border-blue-500 dark:bg-blue-950/60 dark:text-blue-50":""} ${se?"border-red-400":""} ${p.textarea||""}`})})]})]})]})}const Fs=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}));Fs.displayName="Input";function Ma(e,[t,n]){return Math.min(n,Math.max(t,e))}function SC(e,t){return v.useReducer((n,r)=>t[n][r]??n,e)}var Pa="ScrollArea",[wp,pk]=Tn(Pa),[CC,en]=wp(Pa),bp=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,g]=v.useState(null),[m,y]=v.useState(null),[x,w]=v.useState(0),[S,k]=v.useState(0),[C,T]=v.useState(!1),[E,N]=v.useState(!1),_=$e(t,B=>l(B)),D=Ro(o);return u.jsx(CC,{scope:n,type:r,dir:D,scrollHideDelay:s,scrollArea:a,viewport:c,onViewportChange:d,content:f,onContentChange:p,scrollbarX:h,onScrollbarXChange:g,scrollbarXEnabled:C,onScrollbarXEnabledChange:T,scrollbarY:m,onScrollbarYChange:y,scrollbarYEnabled:E,onScrollbarYEnabledChange:N,onCornerWidthChange:w,onCornerHeightChange:k,children:u.jsx(Ne.div,{dir:D,...i,ref:_,style:{position:"relative","--radix-scroll-area-corner-width":x+"px","--radix-scroll-area-corner-height":S+"px",...e.style}})})});bp.displayName=Pa;var Sp="ScrollAreaViewport",Cp=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,i=en(Sp,n),a=v.useRef(null),l=$e(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})})]})});Cp.displayName=Sp;var bn="ScrollAreaScrollbar",Ra=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=en(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(TC,{...r,ref:t,forceMount:n}):o.type==="scroll"?u.jsx(kC,{...r,ref:t,forceMount:n}):o.type==="auto"?u.jsx(Tp,{...r,ref:t,forceMount:n}):o.type==="always"?u.jsx(Oa,{...r,ref:t}):null});Ra.displayName=bn;var TC=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=en(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(Xt,{present:n||s,children:u.jsx(Tp,{"data-state":s?"visible":"hidden",...r,ref:t})})}),kC=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=en(bn,e.__scopeScrollArea),s=e.orientation==="horizontal",i=Hs(()=>l("SCROLL_END"),100),[a,l]=SC("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(Xt,{present:n||a!=="hidden",children:u.jsx(Oa,{"data-state":a==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:pe(e.onPointerEnter,()=>l("POINTER_ENTER")),onPointerLeave:pe(e.onPointerLeave,()=>l("POINTER_LEAVE"))})})}),Tp=v.forwardRef((e,t)=>{const n=en(bn,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,i]=v.useState(!1),a=e.orientation==="horizontal",l=Hs(()=>{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(Oa,{"data-state":s?"visible":"hidden",...o,ref:t})})}),Oa=v.forwardRef((e,t)=>{const{orientation:n="vertical",...r}=e,o=en(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=Np(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 jC(p,i.current,a,h)}return n==="horizontal"?u.jsx(EC,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const p=o.viewport.scrollLeft,h=_p(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(IC,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const p=o.viewport.scrollTop,h=_p(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}),EC=v.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=en(bn,e.__scopeScrollArea),[i,a]=v.useState(),l=v.useRef(null),c=$e(t,l,s.onScrollbarXChange);return v.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(Ep,{"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":Us(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),Mp(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:zs(i.paddingLeft),paddingEnd:zs(i.paddingRight)}})}})}),IC=v.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=en(bn,e.__scopeScrollArea),[i,a]=v.useState(),l=v.useRef(null),c=$e(t,l,s.onScrollbarYChange);return v.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(Ep,{"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":Us(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),Mp(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:zs(i.paddingTop),paddingEnd:zs(i.paddingBottom)}})}})}),[AC,kp]=wp(bn),Ep=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=en(bn,n),[g,m]=v.useState(null),y=$e(t,_=>m(_)),x=v.useRef(null),w=v.useRef(""),S=h.viewport,k=r.content-r.viewport,C=Et(d),T=Et(l),E=Hs(f,10);function N(_){if(x.current){const D=_.clientX-x.current.left,B=_.clientY-x.current.top;c({x:D,y:B})}}return v.useEffect(()=>{const _=D=>{const B=D.target;(g==null?void 0:g.contains(B))&&C(D,k)};return document.addEventListener("wheel",_,{passive:!1}),()=>document.removeEventListener("wheel",_,{passive:!1})},[S,g,k,C]),v.useEffect(T,[r,T]),kr(g,E),kr(h.content,E),u.jsx(AC,{scope:n,scrollbar:g,hasThumb:o,onThumbChange:Et(s),onThumbPointerUp:Et(i),onThumbPositionChange:T,onThumbPointerDown:Et(a),children:u.jsx(Ne.div,{...p,ref:y,style:{position:"absolute",...p.style},onPointerDown:pe(e.onPointerDown,_=>{_.button===0&&(_.target.setPointerCapture(_.pointerId),x.current=g.getBoundingClientRect(),w.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",h.viewport&&(h.viewport.style.scrollBehavior="auto"),N(_))}),onPointerMove:pe(e.onPointerMove,N),onPointerUp:pe(e.onPointerUp,_=>{const D=_.target;D.hasPointerCapture(_.pointerId)&&D.releasePointerCapture(_.pointerId),document.body.style.webkitUserSelect=w.current,h.viewport&&(h.viewport.style.scrollBehavior=""),x.current=null})})})}),Bs="ScrollAreaThumb",Ip=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=kp(Bs,e.__scopeScrollArea);return u.jsx(Xt,{present:n||o.hasThumb,children:u.jsx(NC,{ref:t,...r})})}),NC=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=en(Bs,n),i=kp(Bs,n),{onThumbPositionChange:a}=i,l=$e(t,f=>i.onThumbChange(f)),c=v.useRef(void 0),d=Hs(()=>{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=MC(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:pe(e.onPointerDownCapture,f=>{const h=f.target.getBoundingClientRect(),g=f.clientX-h.left,m=f.clientY-h.top;i.onThumbPointerDown({x:g,y:m})}),onPointerUp:pe(e.onPointerUp,i.onThumbPointerUp)})});Ip.displayName=Bs;var Da="ScrollAreaCorner",Ap=v.forwardRef((e,t)=>{const n=en(Da,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?u.jsx(_C,{...e,ref:t}):null});Ap.displayName=Da;var _C=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=en(Da,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 zs(e){return e?parseInt(e,10):0}function Np(e,t){const n=e/t;return isNaN(n)?0:n}function Us(e){const t=Np(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function jC(e,t,n,r="ltr"){const o=Us(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 jp([l,c],f)(e)}function _p(e,t,n="ltr"){const r=Us(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=Ma(e,l);return jp([0,i],[0,a])(c)}function jp(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 Mp(e,t){return e>0&&e<t}var MC=(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 Hs(e,t){const n=Et(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=Et(t);kt(()=>{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 Pp=bp,PC=Cp,RC=Ap;const Rp=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Pp,{ref:r,className:te("relative overflow-hidden",e),...n,children:[u.jsx(PC,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),u.jsx(Op,{}),u.jsx(RC,{})]}));Rp.displayName=Pp.displayName;const Op=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(Ip,{className:"relative flex-1 rounded-full bg-border"})}));Op.displayName=Ra.displayName;const Dp=25;function La({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:g,actions:m}=jo(),{loadThread:y}=Mo(),{createThread:x,deleteThread:w,renameThread:S}=m,[k,C]=b.useState(Array.isArray(f)?f:[]),T=b.useRef(k.length>0),E=b.useRef(null),N=b.useRef(0),[_,D]=b.useState(null),[B,G]=b.useState(""),[V,P]=b.useState(!1);b.useEffect(()=>{const q=Array.isArray(f)?f:[];if(q.length>0){T.current=!0,C(q);return}g||(T.current=!1,C(q))},[f,g]),b.useEffect(()=>{if(!E.current)return;const q=E.current.querySelector("[data-radix-scroll-area-viewport]");if(!q)return;let U=null,Z=null;return U=requestAnimationFrame(()=>{Z=requestAnimationFrame(()=>{q.scrollTop=N.current})}),()=>{U!==null&&cancelAnimationFrame(U),Z!==null&&cancelAnimationFrame(Z)}},[k]);const M=async q=>{try{h(q),await y(q,void 0,{clearProgress:!0}),a==null||a(q),l==null||l(q)}catch(U){console.error("Failed to select thread:",U)}},A=async()=>{try{P(!0);const q=await x();q&&(c==null||c(q),a==null||a(q))}catch(q){console.error("Failed to create thread:",q)}finally{P(!1)}},F=async(q,U)=>{if(U.stopPropagation(),!!confirm("Delete this thread?")){if(E.current){const Z=E.current.querySelector("[data-radix-scroll-area-viewport]");Z&&(N.current=Z.scrollTop)}try{await w(q),d==null||d(q)}catch(Z){console.error("Failed to delete thread:",Z)}}},L=(q,U)=>{U.stopPropagation(),D(q.threadId),G(q.title||`Thread ${q.threadId.slice(0,8)}`)},R=async q=>{if(B.trim())try{await S(q,B.trim()),D(null),G("")}catch(U){console.error("Failed to update title:",U)}},z=()=>{D(null),G("")},X=(q,U)=>{q.key==="Enter"?R(U):q.key==="Escape"&&z()},ne=q=>{if(!q)return"";try{const U=new Date(q),$=new Date().getTime()-U.getTime(),Y=Math.floor($/(1e3*60*60*24));return Y===0?U.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):Y===1?"Yesterday":Y<7?`${Y} days ago`:U.toLocaleDateString()}catch{return""}},ye=q=>q.title||`Thread ${q.threadId.slice(0,8)}`,Te=q=>{const U=ye(q);return U.length<=Dp?U:`${U.slice(0,Dp)}...`};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(Je,{onClick:A,disabled:V||g,className:s.createButton||"p-2",size:"sm",variant:"ghost",title:V?"Creating...":"New Chat",children:u.jsx(le.MessageSquarePlus,{size:20})})}),u.jsx(Rp,{ref:E,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:g?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((q,U)=>new Date(U.updatedAt||U.createdAt||"").getTime()-new Date(q.updatedAt||q.createdAt||"").getTime()).map(q=>u.jsxs("div",{onClick:()=>M(q.threadId),className:`group relative p-3 rounded-lg cursor-pointer transition-colors border ${(i??p)===q.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:_===q.threadId?u.jsxs("div",{className:"flex items-center gap-2",onClick:U=>U.stopPropagation(),children:[u.jsx(Fs,{value:B,onChange:U=>G(U.target.value),onKeyDown:U=>X(U,q.threadId),className:"h-6 text-sm",autoFocus:!0}),u.jsx(Je,{variant:"ghost",size:"sm",onClick:()=>R(q.threadId),className:"h-6 w-6 p-0",children:u.jsx(le.Check,{size:12})}),u.jsx(Je,{variant:"ghost",size:"sm",onClick:z,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:Te(q)}),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:ne(q.updatedAt||q.createdAt)})]})]})}),u.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity ml-2",children:[r&&_!==q.threadId&&u.jsx(Je,{variant:"ghost",size:"sm",onClick:U=>L(q,U),className:"h-6 w-6 p-0",title:"Edit title",children:u.jsx(le.Edit3,{size:12})}),n&&u.jsx(Je,{variant:"ghost",size:"sm",onClick:U=>F(q.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===q.threadId&&u.jsx("div",{className:"absolute left-0 top-1/2 -translate-y-1/2 w-1 h-8 bg-blue-400 rounded-r"})]},q.threadId))})})]})}const OC=({timelineEntries:e,activeCheckpointId:t,onSelectCheckpoint:n,messagePreviews:r,className:o,onHoverStart:s,onHoverEnd:i})=>{const a=e??[],l=a.length>0,c=b.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 g=d===h.id,m=(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 ${g?"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 ${g?"border-primary bg-primary/10 text-primary":"border-border bg-background"}`,children:u.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${g?"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}`:""]}),m&&u.jsx("p",{className:"text-[10px] text-muted-foreground/80 mt-1 line-clamp-2",title:m,children:m})]})]},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 Er(e){if(!(typeof globalThis>"u"))return globalThis[e]}function DC(e){if(typeof e!="string")return;const t=e.trim();if(t)return Cn(t)}function Lp(){const e=[Er("__API_BASE_URL__"),Er("__CHAT_API_BASE_URL__"),Er("__CHAT_API_URL__")];for(const t of e){const n=DC(t);if(n)return n}}function $p(){const e=[Er("__API_AUTH_TOKEN__"),Er("__CHAT_API_KEY__"),Er("__CHAT_AUTH_TOKEN__")];for(const t of e)if(typeof t=="string"&&t.trim())return t.trim()}function Fp(...e){for(const t of e)if(typeof t=="string"&&t.trim())return Cn(t);return Cn()}function Bp(){const e={},t=Lp(),n=$p();return t&&(e.baseUrl=t),n&&(e.apiKey=n),e}function zp(){const e=Bp(),t=_n.getAuthToken(),n=Lp();return{apiBaseUrl:Fp(e.baseUrl,_n.baseUrl,n),apiKey:t||e.apiKey||$p()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,darkMode:!1,enableSound:!1,messageHistory:100}}const Up="chat-settings";function LC(){try{const e=localStorage.getItem(Up);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function $C(e){try{const t={...e,apiBaseUrl:Cn(e.apiBaseUrl)};localStorage.setItem(Up,JSON.stringify(t)),t.apiKey&&_n.setAuthToken(t.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function FC(){const e=zp(),t=LC(),n=_n.getAuthToken(),r=typeof t.apiBaseUrl=="string"?t.apiBaseUrl:void 0;return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:Fp(_n.baseUrl,r,e.apiBaseUrl)}}function BC(e){_n.updateConfig({baseUrl:e.apiBaseUrl,authToken:e.apiKey??void 0}),$C(e)}var zC="Label",Hp=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())}}));Hp.displayName=zC;var Wp=Hp;const UC=ho.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(Wp,{ref:n,className:te(UC(),e),...t}));tn.displayName=Wp.displayName;function Vp(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 Kp=Object.freeze({position:"absolute",border:0,width:1,height:1,padding:0,margin:-1,overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",wordWrap:"normal"}),HC="VisuallyHidden",WC=v.forwardRef((e,t)=>u.jsx(Ne.span,{...e,ref:t,style:{...Kp,...e.style}}));WC.displayName=HC;var VC=[" ","Enter","ArrowUp","ArrowDown"],KC=[" ","Enter"],sr="Select",[Ws,Vs,qC]=xi(sr),[Ir,hk]=Tn(sr,[qC,qo]),Ks=qo(),[GC,Bn]=Ir(sr),[YC,XC]=Ir(sr),qp=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:g}=e,m=Ks(t),[y,x]=v.useState(null),[w,S]=v.useState(null),[k,C]=v.useState(!1),T=Ro(c),[E,N]=pr({prop:r,defaultProp:o??!1,onChange:s,caller:sr}),[_,D]=pr({prop:i,defaultProp:a,onChange:l,caller:sr}),B=v.useRef(null),G=y?g||!!y.closest("form"):!0,[V,P]=v.useState(new Set),M=Array.from(V).map(A=>A.props.value).join(";");return u.jsx(au,{...m,children:u.jsxs(GC,{required:h,scope:t,trigger:y,onTriggerChange:x,valueNode:w,onValueNodeChange:S,valueNodeHasChildren:k,onValueNodeHasChildrenChange:C,contentId:kn(),value:_,onValueChange:D,open:E,onOpenChange:N,dir:T,triggerPointerDownPosRef:B,disabled:p,children:[u.jsx(Ws.Provider,{scope:t,children:u.jsx(YC,{scope:e.__scopeSelect,onNativeOptionAdd:v.useCallback(A=>{P(F=>new Set(F).add(A))},[]),onNativeOptionRemove:v.useCallback(A=>{P(F=>{const L=new Set(F);return L.delete(A),L})},[]),children:n})}),G?u.jsxs(xh,{"aria-hidden":!0,required:h,tabIndex:-1,name:d,autoComplete:f,value:_,onChange:A=>D(A.target.value),disabled:p,form:g,children:[_===void 0?u.jsx("option",{value:""}):null,Array.from(V)]},M):null]})})};qp.displayName=sr;var Gp="SelectTrigger",Yp=v.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...o}=e,s=Ks(n),i=Bn(Gp,n),a=i.disabled||r,l=$e(t,i.onTriggerChange),c=Vs(n),d=v.useRef("touch"),[f,p,h]=vh(m=>{const y=c().filter(S=>!S.disabled),x=y.find(S=>S.value===i.value),w=wh(y,m,x);w!==void 0&&i.onValueChange(w.value)}),g=m=>{a||(i.onOpenChange(!0),h()),m&&(i.triggerPointerDownPosRef.current={x:Math.round(m.pageX),y:Math.round(m.pageY)})};return u.jsx(lu,{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":yh(i.value)?"":void 0,...o,ref:l,onClick:pe(o.onClick,m=>{m.currentTarget.focus(),d.current!=="mouse"&&g(m)}),onPointerDown:pe(o.onPointerDown,m=>{d.current=m.pointerType;const y=m.target;y.hasPointerCapture(m.pointerId)&&y.releasePointerCapture(m.pointerId),m.button===0&&m.ctrlKey===!1&&m.pointerType==="mouse"&&(g(m),m.preventDefault())}),onKeyDown:pe(o.onKeyDown,m=>{const y=f.current!=="";!(m.ctrlKey||m.altKey||m.metaKey)&&m.key.length===1&&p(m.key),!(y&&m.key===" ")&&VC.includes(m.key)&&(g(),m.preventDefault())})})})});Yp.displayName=Gp;var Xp="SelectValue",Jp=v.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,children:s,placeholder:i="",...a}=e,l=Bn(Xp,n),{onValueNodeHasChildrenChange:c}=l,d=s!==void 0,f=$e(t,l.onValueNodeChange);return kt(()=>{c(d)},[c,d]),u.jsx(Ne.span,{...a,ref:f,style:{pointerEvents:"none"},children:yh(l.value)?u.jsx(u.Fragment,{children:i}):s})});Jp.displayName=Xp;var JC="SelectIcon",Zp=v.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...o}=e;return u.jsx(Ne.span,{"aria-hidden":!0,...o,ref:t,children:r||"▼"})});Zp.displayName=JC;var ZC="SelectPortal",Qp=e=>u.jsx(Go,{asChild:!0,...e});Qp.displayName=ZC;var ir="SelectContent",eh=v.forwardRef((e,t)=>{const n=Bn(ir,e.__scopeSelect),[r,o]=v.useState();if(kt(()=>{o(new DocumentFragment)},[]),!n.open){const s=r;return s?mo.createPortal(u.jsx(th,{scope:e.__scopeSelect,children:u.jsx(Ws.Slot,{scope:e.__scopeSelect,children:u.jsx("div",{children:e.children})})}),s):null}return u.jsx(nh,{...e,ref:t})});eh.displayName=ir;var dn=10,[th,zn]=Ir(ir),QC="SelectContentImpl",eT=Vn.createSlot("SelectContent.RemoveScroll"),nh=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:g,hideWhenDetached:m,avoidCollisions:y,...x}=e,w=Bn(ir,n),[S,k]=v.useState(null),[C,T]=v.useState(null),E=$e(t,Z=>k(Z)),[N,_]=v.useState(null),[D,B]=v.useState(null),G=Vs(n),[V,P]=v.useState(!1),M=v.useRef(!1);v.useEffect(()=>{if(S)return Fi(S)},[S]),wi();const A=v.useCallback(Z=>{const[$,...Y]=G().map(oe=>oe.ref.current),[Q]=Y.slice(-1),de=document.activeElement;for(const oe of Z)if(oe===de||(oe==null||oe.scrollIntoView({block:"nearest"}),oe===$&&C&&(C.scrollTop=0),oe===Q&&C&&(C.scrollTop=C.scrollHeight),oe==null||oe.focus(),document.activeElement!==de))return},[G,C]),F=v.useCallback(()=>A([N,S]),[A,N,S]);v.useEffect(()=>{V&&F()},[V,F]);const{onOpenChange:L,triggerPointerDownPosRef:R}=w;v.useEffect(()=>{if(S){let Z={x:0,y:0};const $=Q=>{var de,oe;Z={x:Math.abs(Math.round(Q.pageX)-(((de=R.current)==null?void 0:de.x)??0)),y:Math.abs(Math.round(Q.pageY)-(((oe=R.current)==null?void 0:oe.y)??0))}},Y=Q=>{Z.x<=10&&Z.y<=10?Q.preventDefault():S.contains(Q.target)||L(!1),document.removeEventListener("pointermove",$),R.current=null};return R.current!==null&&(document.addEventListener("pointermove",$),document.addEventListener("pointerup",Y,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",$),document.removeEventListener("pointerup",Y,{capture:!0})}}},[S,L,R]),v.useEffect(()=>{const Z=()=>L(!1);return window.addEventListener("blur",Z),window.addEventListener("resize",Z),()=>{window.removeEventListener("blur",Z),window.removeEventListener("resize",Z)}},[L]);const[z,X]=vh(Z=>{const $=G().filter(de=>!de.disabled),Y=$.find(de=>de.ref.current===document.activeElement),Q=wh($,Z,Y);Q&&setTimeout(()=>Q.ref.current.focus())}),ne=v.useCallback((Z,$,Y)=>{const Q=!M.current&&!Y;(w.value!==void 0&&w.value===$||Q)&&(_(Z),Q&&(M.current=!0))},[w.value]),ye=v.useCallback(()=>S==null?void 0:S.focus(),[S]),Te=v.useCallback((Z,$,Y)=>{const Q=!M.current&&!Y;(w.value!==void 0&&w.value===$||Q)&&B(Z)},[w.value]),q=r==="popper"?$a:rh,U=q===$a?{side:a,sideOffset:l,align:c,alignOffset:d,arrowPadding:f,collisionBoundary:p,collisionPadding:h,sticky:g,hideWhenDetached:m,avoidCollisions:y}:{};return u.jsx(th,{scope:n,content:S,viewport:C,onViewportChange:T,itemRefCallback:ne,selectedItem:N,onItemLeave:ye,itemTextRefCallback:Te,focusSelectedItem:F,selectedItemText:D,position:r,isPositioned:V,searchRef:z,children:u.jsx(rs,{as:eT,allowPinchZoom:!0,children:u.jsx(Do,{asChild:!0,trapped:w.open,onMountAutoFocus:Z=>{Z.preventDefault()},onUnmountAutoFocus:pe(o,Z=>{var $;($=w.trigger)==null||$.focus({preventScroll:!0}),Z.preventDefault()}),children:u.jsx(Oo,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:Z=>Z.preventDefault(),onDismiss:()=>w.onOpenChange(!1),children:u.jsx(q,{role:"listbox",id:w.contentId,"data-state":w.open?"open":"closed",dir:w.dir,onContextMenu:Z=>Z.preventDefault(),...x,...U,onPlaced:()=>P(!0),ref:E,style:{display:"flex",flexDirection:"column",outline:"none",...x.style},onKeyDown:pe(x.onKeyDown,Z=>{const $=Z.ctrlKey||Z.altKey||Z.metaKey;if(Z.key==="Tab"&&Z.preventDefault(),!$&&Z.key.length===1&&X(Z.key),["ArrowUp","ArrowDown","Home","End"].includes(Z.key)){let Q=G().filter(de=>!de.disabled).map(de=>de.ref.current);if(["ArrowUp","End"].includes(Z.key)&&(Q=Q.slice().reverse()),["ArrowUp","ArrowDown"].includes(Z.key)){const de=Z.target,oe=Q.indexOf(de);Q=Q.slice(oe+1)}setTimeout(()=>A(Q)),Z.preventDefault()}})})})})})})});nh.displayName=QC;var tT="SelectItemAlignedPosition",rh=v.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...o}=e,s=Bn(ir,n),i=zn(ir,n),[a,l]=v.useState(null),[c,d]=v.useState(null),f=$e(t,E=>d(E)),p=Vs(n),h=v.useRef(!1),g=v.useRef(!0),{viewport:m,selectedItem:y,selectedItemText:x,focusSelectedItem:w}=i,S=v.useCallback(()=>{if(s.trigger&&s.valueNode&&a&&c&&m&&y&&x){const E=s.trigger.getBoundingClientRect(),N=c.getBoundingClientRect(),_=s.valueNode.getBoundingClientRect(),D=x.getBoundingClientRect();if(s.dir!=="rtl"){const de=D.left-N.left,oe=_.left-de,_e=E.left-oe,ze=E.width+_e,se=Math.max(ze,N.width),me=window.innerWidth-dn,Pe=Ma(oe,[dn,Math.max(dn,me-se)]);a.style.minWidth=ze+"px",a.style.left=Pe+"px"}else{const de=N.right-D.right,oe=window.innerWidth-_.right-de,_e=window.innerWidth-E.right-oe,ze=E.width+_e,se=Math.max(ze,N.width),me=window.innerWidth-dn,Pe=Ma(oe,[dn,Math.max(dn,me-se)]);a.style.minWidth=ze+"px",a.style.right=Pe+"px"}const B=p(),G=window.innerHeight-dn*2,V=m.scrollHeight,P=window.getComputedStyle(c),M=parseInt(P.borderTopWidth,10),A=parseInt(P.paddingTop,10),F=parseInt(P.borderBottomWidth,10),L=parseInt(P.paddingBottom,10),R=M+A+V+L+F,z=Math.min(y.offsetHeight*5,R),X=window.getComputedStyle(m),ne=parseInt(X.paddingTop,10),ye=parseInt(X.paddingBottom,10),Te=E.top+E.height/2-dn,q=G-Te,U=y.offsetHeight/2,Z=y.offsetTop+U,$=M+A+Z,Y=R-$;if($<=Te){const de=B.length>0&&y===B[B.length-1].ref.current;a.style.bottom="0px";const oe=c.clientHeight-m.offsetTop-m.offsetHeight,_e=Math.max(q,U+(de?ye:0)+oe+F),ze=$+_e;a.style.height=ze+"px"}else{const de=B.length>0&&y===B[0].ref.current;a.style.top="0px";const _e=Math.max(Te,M+m.offsetTop+(de?ne:0)+U)+Y;a.style.height=_e+"px",m.scrollTop=$-Te+m.offsetTop}a.style.margin=`${dn}px 0`,a.style.minHeight=z+"px",a.style.maxHeight=G+"px",r==null||r(),requestAnimationFrame(()=>h.current=!0)}},[p,s.trigger,s.valueNode,a,c,m,y,x,s.dir,r]);kt(()=>S(),[S]);const[k,C]=v.useState();kt(()=>{c&&C(window.getComputedStyle(c).zIndex)},[c]);const T=v.useCallback(E=>{E&&g.current===!0&&(S(),w==null||w(),g.current=!1)},[S,w]);return u.jsx(rT,{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}})})})});rh.displayName=tT;var nT="SelectPopperPosition",$a=v.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=dn,...s}=e,i=Ks(n);return u.jsx(cu,{...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)"}})});$a.displayName=nT;var[rT,Fa]=Ir(ir,{}),Ba="SelectViewport",oh=v.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...o}=e,s=zn(Ba,n),i=Fa(Ba,n),a=$e(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(Ws.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:pe(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 g=window.innerHeight-dn*2,m=parseFloat(f.style.minHeight),y=parseFloat(f.style.height),x=Math.max(m,y);if(x<g){const w=x+h,S=Math.min(g,w),k=w-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})})})]})});oh.displayName=Ba;var sh="SelectGroup",[oT,sT]=Ir(sh),iT=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=kn();return u.jsx(oT,{scope:n,id:o,children:u.jsx(Ne.div,{role:"group","aria-labelledby":o,...r,ref:t})})});iT.displayName=sh;var ih="SelectLabel",ah=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=sT(ih,n);return u.jsx(Ne.div,{id:o.id,...r,ref:t})});ah.displayName=ih;var qs="SelectItem",[aT,lh]=Ir(qs),ch=v.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:s,...i}=e,a=Bn(qs,n),l=zn(qs,n),c=a.value===r,[d,f]=v.useState(s??""),[p,h]=v.useState(!1),g=$e(t,w=>{var S;return(S=l.itemRefCallback)==null?void 0:S.call(l,w,r,o)}),m=kn(),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(aT,{scope:n,value:r,disabled:o,textId:m,isSelected:c,onItemTextChange:v.useCallback(w=>{f(S=>S||((w==null?void 0:w.textContent)??"").trim())},[]),children:u.jsx(Ws.ItemSlot,{scope:n,value:r,disabled:o,textValue:d,children:u.jsx(Ne.div,{role:"option","aria-labelledby":m,"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:g,onFocus:pe(i.onFocus,()=>h(!0)),onBlur:pe(i.onBlur,()=>h(!1)),onClick:pe(i.onClick,()=>{y.current!=="mouse"&&x()}),onPointerUp:pe(i.onPointerUp,()=>{y.current==="mouse"&&x()}),onPointerDown:pe(i.onPointerDown,w=>{y.current=w.pointerType}),onPointerMove:pe(i.onPointerMove,w=>{var S;y.current=w.pointerType,o?(S=l.onItemLeave)==null||S.call(l):y.current==="mouse"&&w.currentTarget.focus({preventScroll:!0})}),onPointerLeave:pe(i.onPointerLeave,w=>{var S;w.currentTarget===document.activeElement&&((S=l.onItemLeave)==null||S.call(l))}),onKeyDown:pe(i.onKeyDown,w=>{var k;((k=l.searchRef)==null?void 0:k.current)!==""&&w.key===" "||(KC.includes(w.key)&&x(),w.key===" "&&w.preventDefault())})})})})});ch.displayName=qs;var fo="SelectItemText",uh=v.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,...s}=e,i=Bn(fo,n),a=zn(fo,n),l=lh(fo,n),c=XC(fo,n),[d,f]=v.useState(null),p=$e(t,x=>f(x),l.onItemTextChange,x=>{var w;return(w=a.itemTextRefCallback)==null?void 0:w.call(a,x,l.value,l.disabled)}),h=d==null?void 0:d.textContent,g=v.useMemo(()=>u.jsx("option",{value:l.value,disabled:l.disabled,children:h},l.value),[l.disabled,l.value,h]),{onNativeOptionAdd:m,onNativeOptionRemove:y}=c;return kt(()=>(m(g),()=>y(g)),[m,y,g]),u.jsxs(u.Fragment,{children:[u.jsx(Ne.span,{id:l.textId,...s,ref:p}),l.isSelected&&i.valueNode&&!i.valueNodeHasChildren?mo.createPortal(s.children,i.valueNode):null]})});uh.displayName=fo;var dh="SelectItemIndicator",fh=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return lh(dh,n).isSelected?u.jsx(Ne.span,{"aria-hidden":!0,...r,ref:t}):null});fh.displayName=dh;var za="SelectScrollUpButton",ph=v.forwardRef((e,t)=>{const n=zn(za,e.__scopeSelect),r=Fa(za,e.__scopeSelect),[o,s]=v.useState(!1),i=$e(t,r.onScrollButtonChange);return kt(()=>{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(mh,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop-l.offsetHeight)}}):null});ph.displayName=za;var Ua="SelectScrollDownButton",hh=v.forwardRef((e,t)=>{const n=zn(Ua,e.__scopeSelect),r=Fa(Ua,e.__scopeSelect),[o,s]=v.useState(!1),i=$e(t,r.onScrollButtonChange);return kt(()=>{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(mh,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop+l.offsetHeight)}}):null});hh.displayName=Ua;var mh=v.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...o}=e,s=zn("SelectScrollButton",n),i=v.useRef(null),a=Vs(n),l=v.useCallback(()=>{i.current!==null&&(window.clearInterval(i.current),i.current=null)},[]);return v.useEffect(()=>()=>l(),[l]),kt(()=>{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:pe(o.onPointerDown,()=>{i.current===null&&(i.current=window.setInterval(r,50))}),onPointerMove:pe(o.onPointerMove,()=>{var c;(c=s.onItemLeave)==null||c.call(s),i.current===null&&(i.current=window.setInterval(r,50))}),onPointerLeave:pe(o.onPointerLeave,()=>{l()})})}),lT="SelectSeparator",gh=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return u.jsx(Ne.div,{"aria-hidden":!0,...r,ref:t})});gh.displayName=lT;var Ha="SelectArrow",cT=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Ks(n),s=Bn(Ha,n),i=zn(Ha,n);return s.open&&i.position==="popper"?u.jsx(uu,{...o,...r,ref:t}):null});cT.displayName=Ha;var uT="SelectBubbleInput",xh=v.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const o=v.useRef(null),s=$e(r,o),i=Vp(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:{...Kp,...n.style},ref:s,defaultValue:t})});xh.displayName=uT;function yh(e){return e===""||e===void 0}function vh(e){const t=Et(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 wh(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=dT(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 dT(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var fT=qp,bh=Yp,pT=Jp,hT=Zp,mT=Qp,Sh=eh,gT=oh,Ch=ah,Th=ch,xT=uh,yT=fh,kh=ph,Eh=hh,Ih=gh;const Ah=fT,Nh=pT,Wa=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(bh,{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(hT,{asChild:!0,children:u.jsx(le.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));Wa.displayName=bh.displayName;const _h=v.forwardRef(({className:e,...t},n)=>u.jsx(kh,{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"})}));_h.displayName=kh.displayName;const jh=v.forwardRef(({className:e,...t},n)=>u.jsx(Eh,{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"})}));jh.displayName=Eh.displayName;const Va=v.forwardRef(({className:e,children:t,position:n="popper",...r},o)=>u.jsx(mT,{children:u.jsxs(Sh,{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(_h,{}),u.jsx(gT,{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(jh,{})]})}));Va.displayName=Sh.displayName;const vT=v.forwardRef(({className:e,...t},n)=>u.jsx(Ch,{ref:n,className:te("py-1.5 pl-8 pr-2 text-sm font-semibold",e),...t}));vT.displayName=Ch.displayName;const ar=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Th,{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(yT,{children:u.jsx(le.Check,{className:"h-4 w-4"})})}),u.jsx(xT,{children:t})]}));ar.displayName=Th.displayName;const wT=v.forwardRef(({className:e,...t},n)=>u.jsx(Ih,{ref:n,className:te("-mx-1 my-1 h-px bg-muted",e),...t}));wT.displayName=Ih.displayName;var bT="Separator",Mh="horizontal",ST=["horizontal","vertical"],Ph=v.forwardRef((e,t)=>{const{decorative:n,orientation:r=Mh,...o}=e,s=CT(r)?r:Mh,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})});Ph.displayName=bT;function CT(e){return ST.includes(e)}var Rh=Ph;const Oh=v.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},o)=>u.jsx(Rh,{ref:o,decorative:n,orientation:t,className:te("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));Oh.displayName=Rh.displayName;const TT=Kf,kT=OS,ET=qf,Dh=v.forwardRef(({className:e,...t},n)=>u.jsx(As,{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}));Dh.displayName=As.displayName;const IT=ho.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"}}),Lh=v.forwardRef(({side:e="right",className:t,children:n,...r},o)=>u.jsxs(ET,{children:[u.jsx(Dh,{}),u.jsxs(Ns,{ref:o,className:te(IT({side:e}),t),...r,children:[n,u.jsxs(Gf,{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"})]})]})]}));Lh.displayName=Ns.displayName;const $h=({className:e,...t})=>u.jsx("div",{className:te("flex flex-col space-y-2 text-center sm:text-left",e),...t});$h.displayName="SheetHeader";const Fh=v.forwardRef(({className:e,...t},n)=>u.jsx(rr,{ref:n,className:te("text-lg font-semibold text-foreground",e),...t}));Fh.displayName=rr.displayName;const Bh=v.forwardRef(({className:e,...t},n)=>u.jsx(_s,{ref:n,className:te("text-sm text-muted-foreground",e),...t}));Bh.displayName=_s.displayName;var Gs="Switch",[AT,mk]=Tn(Gs),[NT,_T]=AT(Gs),zh=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),g=$e(t,S=>h(S)),m=v.useRef(!1),y=p?d||!!p.closest("form"):!0,[x,w]=pr({prop:o,defaultProp:s??!1,onChange:c,caller:Gs});return u.jsxs(NT,{scope:n,checked:x,disabled:a,children:[u.jsx(Ne.button,{type:"button",role:"switch","aria-checked":x,"aria-required":i,"data-state":Vh(x),"data-disabled":a?"":void 0,disabled:a,value:l,...f,ref:g,onClick:pe(e.onClick,S=>{w(k=>!k),y&&(m.current=S.isPropagationStopped(),m.current||S.stopPropagation())})}),y&&u.jsx(Wh,{control:p,bubbles:!m.current,name:r,value:l,checked:x,required:i,disabled:a,form:d,style:{transform:"translateX(-100%)"}})]})});zh.displayName=Gs;var Uh="SwitchThumb",Hh=v.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,o=_T(Uh,n);return u.jsx(Ne.span,{"data-state":Vh(o.checked),"data-disabled":o.disabled?"":void 0,...r,ref:t})});Hh.displayName=Uh;var jT="SwitchBubbleInput",Wh=v.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...o},s)=>{const i=v.useRef(null),a=$e(i,s),l=Vp(n),c=Jc(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 g=new Event("click",{bubbles:r});h.call(d,n),d.dispatchEvent(g)}},[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}})});Wh.displayName=jT;function Vh(e){return e?"checked":"unchecked"}var Kh=zh,MT=Hh;const Un=v.forwardRef(({className:e,...t},n)=>u.jsx(Kh,{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(MT,{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")})}));Un.displayName=Kh.displayName;const PT={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 RT({settings:e,onSettingsChange:t,className:n=""}){const[r,o]=b.useState(!1),[s,i]=b.useState(!1),[a,l]=b.useState(e),[c,d]=b.useState(!1),{toast:f}=Aa();b.useEffect(()=>{const y=JSON.stringify(a)!==JSON.stringify(e);d(y)},[a,e]),b.useEffect(()=>{l(e)},[e]);const p=()=>{t(a),d(!1),f({title:"Settings saved",description:"Your chat configuration has been updated successfully."})},h=()=>{l(PT),d(!0),f({title:"Settings reset",description:"Configuration has been reset to defaults."})},g=()=>{l(e),d(!1),o(!1)},m=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(TT,{open:r,onOpenChange:o,children:[u.jsx(kT,{asChild:!0,children:u.jsxs(Je,{variant:"outline",size:"sm",className:n,children:[u.jsx(le.Settings,{className:"h-4 w-4 mr-2"}),"Settings",c&&u.jsx(Tf,{variant:"destructive",className:"ml-2 h-4 w-4 p-0"})]})}),u.jsxs(Lh,{className:"w-[500px] sm:w-[600px] overflow-y-auto",children:[u.jsxs($h,{children:[u.jsx(Fh,{children:"Chat Settings"}),u.jsx(Bh,{children:"Configure your chat interface, API connection, and behavior preferences."})]}),u.jsxs("div",{className:"space-y-6 py-6",children:[u.jsxs(ao,{children:[u.jsx(lo,{className:"pb-3",children:u.jsxs(co,{className:"text-lg flex items-center gap-2",children:[u.jsx(le.Server,{className:"h-5 w-5"}),"API Configuration"]})}),u.jsxs(uo,{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(Fs,{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(Je,{variant:"outline",onClick:m,children:"Test"})]})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(tn,{htmlFor:"enable-auth",children:"Enable Authentication"}),u.jsx(Un,{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(Fs,{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(Je,{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(ao,{children:[u.jsx(lo,{className:"pb-3",children:u.jsxs(co,{className:"text-lg flex items-center gap-2",children:[u.jsx(le.Layout,{className:"h-5 w-5"}),"Interface Settings"]})}),u.jsxs(uo,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(tn,{htmlFor:"layout",children:"Layout Style"}),u.jsxs(Ah,{value:a.ui.layout,onValueChange:y=>l(x=>({...x,ui:{...x.ui,layout:y}})),children:[u.jsx(Wa,{children:u.jsx(Nh,{})}),u.jsxs(Va,{children:[u.jsx(ar,{value:"sidebar",children:"Sidebar Layout"}),u.jsx(ar,{value:"fullscreen",children:"Fullscreen"}),u.jsx(ar,{value:"tabs",children:"Tabbed Interface"})]})]})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx(tn,{htmlFor:"theme",children:"Theme"}),u.jsxs(Ah,{value:a.ui.theme,onValueChange:y=>l(x=>({...x,ui:{...x.ui,theme:y}})),children:[u.jsx(Wa,{children:u.jsx(Nh,{})}),u.jsxs(Va,{children:[u.jsx(ar,{value:"light",children:"Light"}),u.jsx(ar,{value:"dark",children:"Dark"}),u.jsx(ar,{value:"system",children:"System"})]})]})]}),u.jsx(Oh,{}),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(Un,{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(Un,{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(Un,{id:"compact-messages",checked:a.ui.compactMessages,onCheckedChange:y=>l(x=>({...x,ui:{...x.ui,compactMessages:y}}))})]})]})]})]}),u.jsxs(ao,{children:[u.jsx(lo,{className:"pb-3",children:u.jsxs(co,{className:"text-lg flex items-center gap-2",children:[u.jsx(le.MessageCircle,{className:"h-5 w-5"}),"Behavior Settings"]})}),u.jsxs(uo,{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(Un,{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(Un,{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(Un,{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(Je,{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(Je,{variant:"outline",onClick:g,children:"Cancel"}),u.jsxs(Je,{onClick:p,disabled:!c,children:[u.jsx(le.Save,{className:"h-4 w-4 mr-2"}),"Save Changes"]})]})]})]})]})}function OT({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=b.useCallback(c=>{var d;(d=s.onThreadChange)==null||d.call(s,c)},[s]);return e==="fullscreen"?u.jsx(Po,{...s,onThreadChange:l,children:u.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:u.jsx($s,{className:"flex-1",onError:s.onError,enableFileUpload:!0})})}):e==="tabs"?u.jsx(Po,{...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(La,{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($s,{onError:s.onError,enableFileUpload:!0})})]})})}):u.jsx(Po,{...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(La,{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($s,{onError:s.onError,enableFileUpload:!0})})]})})}Se.ChatApi=Bl,Se.ChatInput=mc,Se.ChatInterface=$s,Se.ChatProviders=Po,Se.ChatSettings=RT,Se.MarkdownContent=io,Se.MessageComponent=Ls,Se.MessageList=ja,Se.ThreadManager=La,Se.TimelineColumn=OC,Se.applySettings=BC,Se.buildMessagePreviewMap=Yg,Se.chatApiClient=_n,Se.default=OT,Se.del=Fl,Se.get=Gt,Se.getChatToken=Dl,Se.getCurrentSettings=FC,Se.getDefaultApiConfig=Bp,Se.getDefaultChatSettings=zp,Se.onChatTokenChanged=Ll,Se.post=ui,Se.put=$l,Se.setChatToken=Io,Se.useApi=di,Se.useChatStream=lc,Se.useMessagesReducer=Ql,Se.useStream=pc,Se.useThreadState=Mo,Se.useThreads=jo,Object.defineProperties(Se,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|