teodor-new-chat-ui 4.3.363 → 4.3.366
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/threads/ThreadListItem.d.ts +23 -0
- package/dist/hooks/useThreadsState.d.ts +37 -0
- package/dist/index.esm.js +5989 -5901
- package/dist/index.umd.js +47 -47
- package/package.json +1 -1
package/dist/index.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(ke,w){typeof exports=="object"&&typeof module<"u"?w(exports,require("react"),require("lucide-react"),require("@radix-ui/react-slot"),require("class-variance-authority"),require("clsx"),require("tailwind-merge"),require("react-dom")):typeof define=="function"&&define.amd?define(["exports","react","lucide-react","@radix-ui/react-slot","class-variance-authority","clsx","tailwind-merge","react-dom"],w):(ke=typeof globalThis<"u"?globalThis:ke||self,w(ke.NewChatUI={},ke.React,ke.LucideReact,ke.reactSlot,ke.classVarianceAuthority,ke.clsx,ke.tailwindMerge,ke.ReactDOM))})(this,function(ke,w,ae,Wn,bo,jm,_m,si){"use strict";var Yk=Object.defineProperty;var Xk=(ke,w,ae)=>w in ke?Yk(ke,w,{enumerable:!0,configurable:!0,writable:!0,value:ae}):ke[w]=ae;var Nm=(ke,w,ae)=>Xk(ke,typeof w!="symbol"?w+"":w,ae);var ii=typeof document<"u"?document.currentScript:null;function gl(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const m=gl(w),wo=gl(si);var ai={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 xl;function Mm(){if(xl)return
|
|
9
|
+
*/var xl;function Mm(){if(xl)return _r;xl=1;var e=w,t=Symbol.for("react.element"),n=Symbol.for("react.fragment"),r=Object.prototype.hasOwnProperty,o=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,s={key:!0,ref:!0,__self:!0,__source:!0};function i(a,l,c){var d,f={},h=null,p=null;c!==void 0&&(h=""+c),l.key!==void 0&&(h=""+l.key),l.ref!==void 0&&(p=l.ref);for(d in l)r.call(l,d)&&!s.hasOwnProperty(d)&&(f[d]=l[d]);if(a&&a.defaultProps)for(d in l=a.defaultProps,l)f[d]===void 0&&(f[d]=l[d]);return{$$typeof:t,type:a,key:h,ref:p,props:f,_owner:o.current}}return _r.Fragment=n,_r.jsx=i,_r.jsxs=i,_r}var Mr={};/**
|
|
10
10
|
* @license React
|
|
11
11
|
* react-jsx-runtime.development.js
|
|
12
12
|
*
|
|
@@ -14,33 +14,33 @@
|
|
|
14
14
|
*
|
|
15
15
|
* This source code is licensed under the MIT license found in the
|
|
16
16
|
* LICENSE file in the root directory of this source tree.
|
|
17
|
-
*/var yl;function Rm(){return yl||(yl=1,process.env.NODE_ENV!=="production"&&function(){var e=w,t=Symbol.for("react.element"),n=Symbol.for("react.portal"),r=Symbol.for("react.fragment"),o=Symbol.for("react.strict_mode"),s=Symbol.for("react.profiler"),i=Symbol.for("react.provider"),a=Symbol.for("react.context"),l=Symbol.for("react.forward_ref"),c=Symbol.for("react.suspense"),d=Symbol.for("react.suspense_list"),f=Symbol.for("react.memo"),
|
|
18
|
-
`+
|
|
19
|
-
`),
|
|
20
|
-
`),
|
|
21
|
-
`+
|
|
17
|
+
*/var yl;function Rm(){return yl||(yl=1,process.env.NODE_ENV!=="production"&&function(){var e=w,t=Symbol.for("react.element"),n=Symbol.for("react.portal"),r=Symbol.for("react.fragment"),o=Symbol.for("react.strict_mode"),s=Symbol.for("react.profiler"),i=Symbol.for("react.provider"),a=Symbol.for("react.context"),l=Symbol.for("react.forward_ref"),c=Symbol.for("react.suspense"),d=Symbol.for("react.suspense_list"),f=Symbol.for("react.memo"),h=Symbol.for("react.lazy"),p=Symbol.for("react.offscreen"),v=Symbol.iterator,g="@@iterator";function y(N){if(N===null||typeof N!="object")return null;var te=v&&N[v]||N[g];return typeof te=="function"?te:null}var x=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function b(N){{for(var te=arguments.length,ue=new Array(te>1?te-1:0),Ie=1;Ie<te;Ie++)ue[Ie-1]=arguments[Ie];C("error",N,ue)}}function C(N,te,ue){{var Ie=x.ReactDebugCurrentFrame,Ze=Ie.getStackAddendum();Ze!==""&&(te+="%s",ue=ue.concat([Ze]));var st=ue.map(function(Ue){return String(Ue)});st.unshift("Warning: "+te),Function.prototype.apply.call(console[N],console,st)}}var k=!1,S=!1,T=!1,E=!1,j=!1,R;R=Symbol.for("react.module.reference");function O(N){return!!(typeof N=="string"||typeof N=="function"||N===r||N===s||j||N===o||N===c||N===d||E||N===p||k||S||T||typeof N=="object"&&N!==null&&(N.$$typeof===h||N.$$typeof===f||N.$$typeof===i||N.$$typeof===a||N.$$typeof===l||N.$$typeof===R||N.getModuleId!==void 0))}function B(N,te,ue){var Ie=N.displayName;if(Ie)return Ie;var Ze=te.displayName||te.name||"";return Ze!==""?ue+"("+Ze+")":ue}function q(N){return N.displayName||"Context"}function K(N){if(N==null)return null;if(typeof N.tag=="number"&&b("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof N=="function")return N.displayName||N.name||null;if(typeof N=="string")return N;switch(N){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 N=="object")switch(N.$$typeof){case a:var te=N;return q(te)+".Consumer";case i:var ue=N;return q(ue._context)+".Provider";case l:return B(N,N.render,"ForwardRef");case f:var Ie=N.displayName||null;return Ie!==null?Ie:K(N.type)||"Memo";case h:{var Ze=N,st=Ze._payload,Ue=Ze._init;try{return K(Ue(st))}catch{return null}}}return null}var P=Object.assign,M=0,I,z,L,A,$,H,_;function G(){}G.__reactDisabledLog=!0;function re(){{if(M===0){I=console.log,z=console.info,L=console.warn,A=console.error,$=console.group,H=console.groupCollapsed,_=console.groupEnd;var N={configurable:!0,enumerable:!0,value:G,writable:!0};Object.defineProperties(console,{info:N,log:N,warn:N,error:N,group:N,groupCollapsed:N,groupEnd:N})}M++}}function ee(){{if(M--,M===0){var N={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:P({},N,{value:I}),info:P({},N,{value:z}),warn:P({},N,{value:L}),error:P({},N,{value:A}),group:P({},N,{value:$}),groupCollapsed:P({},N,{value:H}),groupEnd:P({},N,{value:_})})}M<0&&b("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var ie=x.ReactCurrentDispatcher,Y;function D(N,te,ue){{if(Y===void 0)try{throw Error()}catch(Ze){var Ie=Ze.stack.trim().match(/\n( *(at )?)/);Y=Ie&&Ie[1]||""}return`
|
|
18
|
+
`+Y+N}}var V=!1,U;{var Z=typeof WeakMap=="function"?WeakMap:Map;U=new Z}function J(N,te){if(!N||V)return"";{var ue=U.get(N);if(ue!==void 0)return ue}var Ie;V=!0;var Ze=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var st;st=ie.current,ie.current=null,re();try{if(te){var Ue=function(){throw Error()};if(Object.defineProperty(Ue.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(Ue,[])}catch(Ye){Ie=Ye}Reflect.construct(N,[],Ue)}else{try{Ue.call()}catch(Ye){Ie=Ye}N.call(Ue.prototype)}}else{try{throw Error()}catch(Ye){Ie=Ye}N()}}catch(Ye){if(Ye&&Ie&&typeof Ye.stack=="string"){for(var ze=Ye.stack.split(`
|
|
19
|
+
`),_t=Ie.stack.split(`
|
|
20
|
+
`),gt=ze.length-1,yt=_t.length-1;gt>=1&&yt>=0&&ze[gt]!==_t[yt];)yt--;for(;gt>=1&&yt>=0;gt--,yt--)if(ze[gt]!==_t[yt]){if(gt!==1||yt!==1)do if(gt--,yt--,yt<0||ze[gt]!==_t[yt]){var me=`
|
|
21
|
+
`+ze[gt].replace(" at new "," at ");return N.displayName&&me.includes("<anonymous>")&&(me=me.replace("<anonymous>",N.displayName)),typeof N=="function"&&U.set(N,me),me}while(gt>=1&&yt>=0);break}}}finally{V=!1,ie.current=st,ee(),Error.prepareStackTrace=Ze}var Te=N?N.displayName||N.name:"",Ae=Te?D(Te):"";return typeof N=="function"&&U.set(N,Ae),Ae}function ge(N,te,ue){return J(N,!1)}function ce(N){var te=N.prototype;return!!(te&&te.isReactComponent)}function ne(N,te,ue){if(N==null)return"";if(typeof N=="function")return J(N,ce(N));if(typeof N=="string")return D(N);switch(N){case c:return D("Suspense");case d:return D("SuspenseList")}if(typeof N=="object")switch(N.$$typeof){case l:return ge(N.render);case f:return ne(N.type,te,ue);case h:{var Ie=N,Ze=Ie._payload,st=Ie._init;try{return ne(st(Ze),te,ue)}catch{}}}return""}var pe=Object.prototype.hasOwnProperty,be={},De=x.ReactDebugCurrentFrame;function je(N){if(N){var te=N._owner,ue=ne(N.type,N._source,te?te.type:null);De.setExtraStackFrame(ue)}else De.setExtraStackFrame(null)}function He(N,te,ue,Ie,Ze){{var st=Function.call.bind(pe);for(var Ue in N)if(st(N,Ue)){var ze=void 0;try{if(typeof N[Ue]!="function"){var _t=Error((Ie||"React class")+": "+ue+" type `"+Ue+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof N[Ue]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw _t.name="Invariant Violation",_t}ze=N[Ue](te,Ue,Ie,ue,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(gt){ze=gt}ze&&!(ze instanceof Error)&&(je(Ze),b("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",Ie||"React class",ue,Ue,typeof ze),je(null)),ze instanceof Error&&!(ze.message in be)&&(be[ze.message]=!0,je(Ze),b("Failed %s type: %s",ue,ze.message),je(null))}}}var qe=Array.isArray;function rt(N){return qe(N)}function Ge(N){{var te=typeof Symbol=="function"&&Symbol.toStringTag,ue=te&&N[Symbol.toStringTag]||N.constructor.name||"Object";return ue}}function Qe(N){try{return lt(N),!1}catch{return!0}}function lt(N){return""+N}function Re(N){if(Qe(N))return b("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",Ge(N)),lt(N)}var Le=x.ReactCurrentOwner,ct={key:!0,ref:!0,__self:!0,__source:!0},ot,pt;function mt(N){if(pe.call(N,"ref")){var te=Object.getOwnPropertyDescriptor(N,"ref").get;if(te&&te.isReactWarning)return!1}return N.ref!==void 0}function kt(N){if(pe.call(N,"key")){var te=Object.getOwnPropertyDescriptor(N,"key").get;if(te&&te.isReactWarning)return!1}return N.key!==void 0}function At(N,te){typeof N.ref=="string"&&Le.current}function Fe(N,te){{var ue=function(){ot||(ot=!0,b("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",te))};ue.isReactWarning=!0,Object.defineProperty(N,"key",{get:ue,configurable:!0})}}function fn(N,te){{var ue=function(){pt||(pt=!0,b("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",te))};ue.isReactWarning=!0,Object.defineProperty(N,"ref",{get:ue,configurable:!0})}}var W=function(N,te,ue,Ie,Ze,st,Ue){var ze={$$typeof:t,type:N,key:te,ref:ue,props:Ue,_owner:st};return ze._store={},Object.defineProperty(ze._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(ze,"_self",{configurable:!1,enumerable:!1,writable:!1,value:Ie}),Object.defineProperty(ze,"_source",{configurable:!1,enumerable:!1,writable:!1,value:Ze}),Object.freeze&&(Object.freeze(ze.props),Object.freeze(ze)),ze};function le(N,te,ue,Ie,Ze){{var st,Ue={},ze=null,_t=null;ue!==void 0&&(Re(ue),ze=""+ue),kt(te)&&(Re(te.key),ze=""+te.key),mt(te)&&(_t=te.ref,At(te,Ze));for(st in te)pe.call(te,st)&&!ct.hasOwnProperty(st)&&(Ue[st]=te[st]);if(N&&N.defaultProps){var gt=N.defaultProps;for(st in gt)Ue[st]===void 0&&(Ue[st]=gt[st])}if(ze||_t){var yt=typeof N=="function"?N.displayName||N.name||"Unknown":N;ze&&Fe(Ue,yt),_t&&fn(Ue,yt)}return W(N,ze,_t,Ze,Ie,Le.current,Ue)}}var Pe=x.ReactCurrentOwner,wt=x.ReactDebugCurrentFrame;function We(N){if(N){var te=N._owner,ue=ne(N.type,N._source,te?te.type:null);wt.setExtraStackFrame(ue)}else wt.setExtraStackFrame(null)}var Tt;Tt=!1;function X(N){return typeof N=="object"&&N!==null&&N.$$typeof===t}function ye(){{if(Pe.current){var N=K(Pe.current.type);if(N)return`
|
|
22
22
|
|
|
23
|
-
Check the render method of \``+
|
|
23
|
+
Check the render method of \``+N+"`."}return""}}function Ce(N){return""}var Je={};function Be(N){{var te=ye();if(!te){var ue=typeof N=="string"?N:N.displayName||N.name;ue&&(te=`
|
|
24
24
|
|
|
25
|
-
Check the top-level render call using <`+
|
|
25
|
+
Check the top-level render call using <`+ue+">.")}return te}}function xt(N,te){{if(!N._store||N._store.validated||N.key!=null)return;N._store.validated=!0;var ue=Be(te);if(Je[ue])return;Je[ue]=!0;var Ie="";N&&N._owner&&N._owner!==Pe.current&&(Ie=" It was passed a child from "+K(N._owner.type)+"."),We(N),b('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',ue,Ie),We(null)}}function nt(N,te){{if(typeof N!="object")return;if(rt(N))for(var ue=0;ue<N.length;ue++){var Ie=N[ue];X(Ie)&&xt(Ie,te)}else if(X(N))N._store&&(N._store.validated=!0);else if(N){var Ze=y(N);if(typeof Ze=="function"&&Ze!==N.entries)for(var st=Ze.call(N),Ue;!(Ue=st.next()).done;)X(Ue.value)&&xt(Ue.value,te)}}}function jt(N){{var te=N.type;if(te==null||typeof te=="string")return;var ue;if(typeof te=="function")ue=te.propTypes;else if(typeof te=="object"&&(te.$$typeof===l||te.$$typeof===f))ue=te.propTypes;else return;if(ue){var Ie=K(te);He(ue,N.props,"prop",Ie,N)}else if(te.PropTypes!==void 0&&!Tt){Tt=!0;var Ze=K(te);b("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",Ze||"Unknown")}typeof te.getDefaultProps=="function"&&!te.getDefaultProps.isReactClassApproved&&b("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function yo(N){{for(var te=Object.keys(N.props),ue=0;ue<te.length;ue++){var Ie=te[ue];if(Ie!=="children"&&Ie!=="key"){We(N),b("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",Ie),We(null);break}}N.ref!==null&&(We(N),b("Invalid attribute `ref` supplied to `React.Fragment`."),We(null))}}var vo={};function ri(N,te,ue,Ie,Ze,st){{var Ue=O(N);if(!Ue){var ze="";(N===void 0||typeof N=="object"&&N!==null&&Object.keys(N).length===0)&&(ze+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var _t=Ce();_t?ze+=_t:ze+=ye();var gt;N===null?gt="null":rt(N)?gt="array":N!==void 0&&N.$$typeof===t?(gt="<"+(K(N.type)||"Unknown")+" />",ze=" Did you accidentally export a JSX literal instead of a component?"):gt=typeof N,b("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",gt,ze)}var yt=le(N,te,ue,Ze,st);if(yt==null)return yt;if(Ue){var me=te.children;if(me!==void 0)if(Ie)if(rt(me)){for(var Te=0;Te<me.length;Te++)nt(me[Te],N);Object.freeze&&Object.freeze(me)}else b("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else nt(me,N)}if(pe.call(te,"key")){var Ae=K(N),Ye=Object.keys(te).filter(function(Gk){return Gk!=="key"}),Hn=Ye.length>0?"{key: someKey, "+Ye.join(": ..., ")+": ...}":"{key: someKey}";if(!vo[Ae+Hn]){var rn=Ye.length>0?"{"+Ye.join(": ..., ")+": ...}":"{}";b(`A props object containing a "key" prop is being spread into JSX:
|
|
26
26
|
let props = %s;
|
|
27
27
|
<%s {...props} />
|
|
28
28
|
React keys must be passed directly to JSX without using spread:
|
|
29
29
|
let props = %s;
|
|
30
|
-
<%s key={someKey} {...props} />`,Vn,Re,on,Re),An[Re+Vn]=!0}}return I===r?Cn(yt):xt(yt),yt}}function Dr(I,J,de){return Or(I,J,de,!0)}function dr(I,J,de){return Or(I,J,de,!1)}var Lr=dr,fr=Dr;Fr.Fragment=r,Fr.jsx=Lr,Fr.jsxs=fr}()),Fr}process.env.NODE_ENV==="production"?ui.exports=Mm():ui.exports=Rm();var u=ui.exports;function vl(e,t){return function(){return e.apply(t,arguments)}}const{toString:Pm}=Object.prototype,{getPrototypeOf:di}=Object,{iterator:Io,toStringTag:bl}=Symbol,No=(e=>t=>{const n=Pm.call(t);return e[n]||(e[n]=n.slice(8,-1).toLowerCase())})(Object.create(null)),sn=e=>(e=e.toLowerCase(),t=>No(t)===e),Ao=e=>t=>typeof t===e,{isArray:pr}=Array,hr=Ao("undefined");function Br(e){return e!==null&&!hr(e)&&e.constructor!==null&&!hr(e.constructor)&&zt(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const wl=sn("ArrayBuffer");function Om(e){let t;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?t=ArrayBuffer.isView(e):t=e&&e.buffer&&wl(e.buffer),t}const Dm=Ao("string"),zt=Ao("function"),Sl=Ao("number"),zr=e=>e!==null&&typeof e=="object",Lm=e=>e===!0||e===!1,jo=e=>{if(No(e)!=="object")return!1;const t=di(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(bl in e)&&!(Io in e)},$m=e=>{if(!zr(e)||Br(e))return!1;try{return Object.keys(e).length===0&&Object.getPrototypeOf(e)===Object.prototype}catch{return!1}},Fm=sn("Date"),Bm=sn("File"),zm=sn("Blob"),Um=sn("FileList"),Hm=e=>zr(e)&&zt(e.pipe),Wm=e=>{let t;return e&&(typeof FormData=="function"&&e instanceof FormData||zt(e.append)&&((t=No(e))==="formdata"||t==="object"&&zt(e.toString)&&e.toString()==="[object FormData]"))},Vm=sn("URLSearchParams"),[Km,qm,Gm,Ym]=["ReadableStream","Request","Response","Headers"].map(sn),Xm=e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function Ur(e,t,{allOwnKeys:n=!1}={}){if(e===null||typeof e>"u")return;let r,o;if(typeof e!="object"&&(e=[e]),pr(e))for(r=0,o=e.length;r<o;r++)t.call(null,e[r],r,e);else{if(Br(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 Cl(e,t){if(Br(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 qn=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global,Tl=e=>!hr(e)&&e!==qn;function fi(){const{caseless:e,skipUndefined:t}=Tl(this)&&this||{},n={},r=(o,s)=>{const i=e&&Cl(n,s)||s;jo(n[i])&&jo(o)?n[i]=fi(n[i],o):jo(o)?n[i]=fi({},o):pr(o)?n[i]=o.slice():(!t||!hr(o))&&(n[i]=o)};for(let o=0,s=arguments.length;o<s;o++)arguments[o]&&Ur(arguments[o],r);return n}const Jm=(e,t,n,{allOwnKeys:r}={})=>(Ur(t,(o,s)=>{n&&zt(o)?e[s]=vl(o,n):e[s]=o},{allOwnKeys:r}),e),Zm=e=>(e.charCodeAt(0)===65279&&(e=e.slice(1)),e),Qm=(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)},eg=(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&&di(e)}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},tg=(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},ng=e=>{if(!e)return null;if(pr(e))return e;let t=e.length;if(!Sl(t))return null;const n=new Array(t);for(;t-- >0;)n[t]=e[t];return n},rg=(e=>t=>e&&t instanceof e)(typeof Uint8Array<"u"&&di(Uint8Array)),og=(e,t)=>{const r=(e&&e[Io]).call(e);let o;for(;(o=r.next())&&!o.done;){const s=o.value;t.call(e,s[0],s[1])}},sg=(e,t)=>{let n;const r=[];for(;(n=e.exec(t))!==null;)r.push(n);return r},ig=sn("HTMLFormElement"),ag=e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(n,r,o){return r.toUpperCase()+o}),kl=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),lg=sn("RegExp"),El=(e,t)=>{const n=Object.getOwnPropertyDescriptors(e),r={};Ur(n,(o,s)=>{let i;(i=t(o,s,e))!==!1&&(r[s]=i||o)}),Object.defineProperties(e,r)},cg=e=>{El(e,(t,n)=>{if(zt(e)&&["arguments","caller","callee"].indexOf(n)!==-1)return!1;const r=e[n];if(zt(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+"'")})}})},ug=(e,t)=>{const n={},r=o=>{o.forEach(s=>{n[s]=!0})};return pr(e)?r(e):r(String(e).split(t)),n},dg=()=>{},fg=(e,t)=>e!=null&&Number.isFinite(e=+e)?e:t;function pg(e){return!!(e&&zt(e.append)&&e[bl]==="FormData"&&e[Io])}const hg=e=>{const t=new Array(10),n=(r,o)=>{if(zr(r)){if(t.indexOf(r)>=0)return;if(Br(r))return r;if(!("toJSON"in r)){t[o]=r;const s=pr(r)?[]:{};return Ur(r,(i,a)=>{const l=n(i,o+1);!hr(l)&&(s[a]=l)}),t[o]=void 0,s}}return r};return n(e,0)},mg=sn("AsyncFunction"),gg=e=>e&&(zr(e)||zt(e))&&zt(e.then)&&zt(e.catch),Il=((e,t)=>e?setImmediate:t?((n,r)=>(qn.addEventListener("message",({source:o,data:s})=>{o===qn&&s===n&&r.length&&r.shift()()},!1),o=>{r.push(o),qn.postMessage(n,"*")}))(`axios@${Math.random()}`,[]):n=>setTimeout(n))(typeof setImmediate=="function",zt(qn.postMessage)),xg=typeof queueMicrotask<"u"?queueMicrotask.bind(qn):typeof process<"u"&&process.nextTick||Il,L={isArray:pr,isArrayBuffer:wl,isBuffer:Br,isFormData:Wm,isArrayBufferView:Om,isString:Dm,isNumber:Sl,isBoolean:Lm,isObject:zr,isPlainObject:jo,isEmptyObject:$m,isReadableStream:Km,isRequest:qm,isResponse:Gm,isHeaders:Ym,isUndefined:hr,isDate:Fm,isFile:Bm,isBlob:zm,isRegExp:lg,isFunction:zt,isStream:Hm,isURLSearchParams:Vm,isTypedArray:rg,isFileList:Um,forEach:Ur,merge:fi,extend:Jm,trim:Xm,stripBOM:Zm,inherits:Qm,toFlatObject:eg,kindOf:No,kindOfTest:sn,endsWith:tg,toArray:ng,forEachEntry:og,matchAll:sg,isHTMLForm:ig,hasOwnProperty:kl,hasOwnProp:kl,reduceDescriptors:El,freezeMethods:cg,toObjectSet:ug,toCamelCase:ag,noop:dg,toFiniteNumber:fg,findKey:Cl,global:qn,isContextDefined:Tl,isSpecCompliantForm:pg,toJSONObject:hg,isAsyncFn:mg,isThenable:gg,setImmediate:Il,asap:xg,isIterable:e=>e!=null&&zt(e[Io])};function De(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)}L.inherits(De,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:L.toJSONObject(this.config),code:this.code,status:this.status}}});const Nl=De.prototype,Al={};["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=>{Al[e]={value:e}}),Object.defineProperties(De,Al),Object.defineProperty(Nl,"isAxiosError",{value:!0}),De.from=(e,t,n,r,o,s)=>{const i=Object.create(Nl);L.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 De.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 yg=null;function pi(e){return L.isPlainObject(e)||L.isArray(e)}function jl(e){return L.endsWith(e,"[]")?e.slice(0,-2):e}function _l(e,t,n){return e?e.concat(t).map(function(o,s){return o=jl(o),!n&&s?"["+o+"]":o}).join(n?".":""):t}function vg(e){return L.isArray(e)&&!e.some(pi)}const bg=L.toFlatObject(L,{},null,function(t){return/^is[A-Z]/.test(t)});function _o(e,t,n){if(!L.isObject(e))throw new TypeError("target must be an object");t=t||new FormData,n=L.toFlatObject(n,{metaTokens:!0,dots:!1,indexes:!1},!1,function(g,y){return!L.isUndefined(y[g])});const r=n.metaTokens,o=n.visitor||d,s=n.dots,i=n.indexes,l=(n.Blob||typeof Blob<"u"&&Blob)&&L.isSpecCompliantForm(t);if(!L.isFunction(o))throw new TypeError("visitor must be a function");function c(v){if(v===null)return"";if(L.isDate(v))return v.toISOString();if(L.isBoolean(v))return v.toString();if(!l&&L.isBlob(v))throw new De("Blob is not supported. Use a Buffer instead.");return L.isArrayBuffer(v)||L.isTypedArray(v)?l&&typeof Blob=="function"?new Blob([v]):Buffer.from(v):v}function d(v,g,y){let x=v;if(v&&!y&&typeof v=="object"){if(L.endsWith(g,"{}"))g=r?g:g.slice(0,-2),v=JSON.stringify(v);else if(L.isArray(v)&&vg(v)||(L.isFileList(v)||L.endsWith(g,"[]"))&&(x=L.toArray(v)))return g=jl(g),x.forEach(function(C,k){!(L.isUndefined(C)||C===null)&&t.append(i===!0?_l([g],k,s):i===null?g:g+"[]",c(C))}),!1}return pi(v)?!0:(t.append(_l(y,g,s),c(v)),!1)}const f=[],p=Object.assign(bg,{defaultVisitor:d,convertValue:c,isVisitable:pi});function h(v,g){if(!L.isUndefined(v)){if(f.indexOf(v)!==-1)throw Error("Circular reference detected in "+g.join("."));f.push(v),L.forEach(v,function(x,b){(!(L.isUndefined(x)||x===null)&&o.call(t,x,L.isString(b)?b.trim():b,g,p))===!0&&h(x,g?g.concat(b):[b])}),f.pop()}}if(!L.isObject(e))throw new TypeError("data must be an object");return h(e),t}function Ml(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,function(r){return t[r]})}function hi(e,t){this._pairs=[],e&&_o(e,this,t)}const Rl=hi.prototype;Rl.append=function(t,n){this._pairs.push([t,n])},Rl.toString=function(t){const n=t?function(r){return t.call(this,r,Ml)}:Ml;return this._pairs.map(function(o){return n(o[0])+"="+n(o[1])},"").join("&")};function wg(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+")}function Pl(e,t,n){if(!t)return e;const r=n&&n.encode||wg;L.isFunction(n)&&(n={serialize:n});const o=n&&n.serialize;let s;if(o?s=o(t,n):s=L.isURLSearchParams(t)?t.toString():new hi(t,n).toString(r),s){const i=e.indexOf("#");i!==-1&&(e=e.slice(0,i)),e+=(e.indexOf("?")===-1?"?":"&")+s}return e}class Ol{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){L.forEach(this.handlers,function(r){r!==null&&t(r)})}}const Dl={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},Sg={isBrowser:!0,classes:{URLSearchParams:typeof URLSearchParams<"u"?URLSearchParams:hi,FormData:typeof FormData<"u"?FormData:null,Blob:typeof Blob<"u"?Blob:null},protocols:["http","https","file","blob","url","data"]},mi=typeof window<"u"&&typeof document<"u",gi=typeof navigator=="object"&&navigator||void 0,Cg=mi&&(!gi||["ReactNative","NativeScript","NS"].indexOf(gi.product)<0),Tg=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function",kg=mi&&window.location.href||"http://localhost",_t={...Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv:mi,hasStandardBrowserEnv:Cg,hasStandardBrowserWebWorkerEnv:Tg,navigator:gi,origin:kg},Symbol.toStringTag,{value:"Module"})),...Sg};function Eg(e,t){return _o(e,new _t.classes.URLSearchParams,{visitor:function(n,r,o,s){return _t.isNode&&L.isBuffer(n)?(this.append(r,n.toString("base64")),!1):s.defaultVisitor.apply(this,arguments)},...t})}function Ig(e){return L.matchAll(/\w+|\[(\w*)]/g,e).map(t=>t[0]==="[]"?"":t[1]||t[0])}function Ng(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 Ll(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&&L.isArray(o)?o.length:i,l?(L.hasOwnProp(o,i)?o[i]=[o[i],r]:o[i]=r,!a):((!o[i]||!L.isObject(o[i]))&&(o[i]=[]),t(n,r,o[i],s)&&L.isArray(o[i])&&(o[i]=Ng(o[i])),!a)}if(L.isFormData(e)&&L.isFunction(e.entries)){const n={};return L.forEachEntry(e,(r,o)=>{t(Ig(r),o,n,0)}),n}return null}function Ag(e,t,n){if(L.isString(e))try{return(t||JSON.parse)(e),L.trim(e)}catch(r){if(r.name!=="SyntaxError")throw r}return(n||JSON.stringify)(e)}const Hr={transitional:Dl,adapter:["xhr","http","fetch"],transformRequest:[function(t,n){const r=n.getContentType()||"",o=r.indexOf("application/json")>-1,s=L.isObject(t);if(s&&L.isHTMLForm(t)&&(t=new FormData(t)),L.isFormData(t))return o?JSON.stringify(Ll(t)):t;if(L.isArrayBuffer(t)||L.isBuffer(t)||L.isStream(t)||L.isFile(t)||L.isBlob(t)||L.isReadableStream(t))return t;if(L.isArrayBufferView(t))return t.buffer;if(L.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 Eg(t,this.formSerializer).toString();if((a=L.isFileList(t))||r.indexOf("multipart/form-data")>-1){const l=this.env&&this.env.FormData;return _o(a?{"files[]":t}:t,l&&new l,this.formSerializer)}}return s||o?(n.setContentType("application/json",!1),Ag(t)):t}],transformResponse:[function(t){const n=this.transitional||Hr.transitional,r=n&&n.forcedJSONParsing,o=this.responseType==="json";if(L.isResponse(t)||L.isReadableStream(t))return t;if(t&&L.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"?De.from(a,De.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:_t.classes.FormData,Blob:_t.classes.Blob},validateStatus:function(t){return t>=200&&t<300},headers:{common:{Accept:"application/json, text/plain, */*","Content-Type":void 0}}};L.forEach(["delete","get","head","post","put","patch"],e=>{Hr.headers[e]={}});const jg=L.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"]),_g=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]&&jg[n])&&(n==="set-cookie"?t[n]?t[n].push(r):t[n]=[r]:t[n]=t[n]?t[n]+", "+r:r)}),t},$l=Symbol("internals");function
|
|
32
|
-
`)}getSetCookie(){return this.get("set-cookie")||[]}get[Symbol.toStringTag](){return"AxiosHeaders"}static from(t){return t instanceof this?t:new this(t)}static concat(t,...n){const r=new this(t);return n.forEach(o=>r.set(o)),r}static accessor(t){const r=(this[$l]=this[$l]={accessors:{}}).accessors,o=this.prototype;function s(i){const a=Wr(i);r[a]||(Og(o,i),r[a]=!0)}return L.isArray(t)?t.forEach(s):s(t),this}};Ut.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),L.reduceDescriptors(Ut.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(r){this[n]=r}}}),L.freezeMethods(Ut);function yi(e,t){const n=this||Hr,r=t||n,o=Ut.from(r.headers);let s=r.data;return L.forEach(e,function(a){s=a.call(n,s,o.normalize(),t?t.status:void 0)}),o.normalize(),s}function Fl(e){return!!(e&&e.__CANCEL__)}function mr(e,t,n){De.call(this,e??"canceled",De.ERR_CANCELED,t,n),this.name="CanceledError"}L.inherits(mr,De,{__CANCEL__:!0});function Bl(e,t,n){const r=n.config.validateStatus;!n.status||!r||r(n.status)?e(n):t(new De("Request failed with status code "+n.status,[De.ERR_BAD_REQUEST,De.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n))}function Dg(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function Lg(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 $g(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 Ro=(e,t,n=3)=>{let r=0;const o=Lg(50,250);return $g(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)},zl=(e,t)=>{const n=e!=null;return[r=>t[0]({lengthComputable:n,total:e,loaded:r}),t[1]]},Ul=e=>(...t)=>L.asap(()=>e(...t)),Fg=_t.hasStandardBrowserEnv?((e,t)=>n=>(n=new URL(n,_t.origin),e.protocol===n.protocol&&e.host===n.host&&(t||e.port===n.port)))(new URL(_t.origin),_t.navigator&&/(msie|trident)/i.test(_t.navigator.userAgent)):()=>!0,Bg=_t.hasStandardBrowserEnv?{write(e,t,n,r,o,s){const i=[e+"="+encodeURIComponent(t)];L.isNumber(n)&&i.push("expires="+new Date(n).toGMTString()),L.isString(r)&&i.push("path="+r),L.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 zg(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function Ug(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function Hl(e,t,n){let r=!zg(t);return e&&(r||n==!1)?Ug(e,t):t}const Wl=e=>e instanceof Ut?{...e}:e;function Gn(e,t){t=t||{};const n={};function r(c,d,f,p){return L.isPlainObject(c)&&L.isPlainObject(d)?L.merge.call({caseless:p},c,d):L.isPlainObject(d)?L.merge({},d):L.isArray(d)?d.slice():d}function o(c,d,f,p){if(L.isUndefined(d)){if(!L.isUndefined(c))return r(void 0,c,f,p)}else return r(c,d,f,p)}function s(c,d){if(!L.isUndefined(d))return r(void 0,d)}function i(c,d){if(L.isUndefined(d)){if(!L.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 L.forEach(Object.keys({...e,...t}),function(d){const f=l[d]||o,p=f(e[d],t[d],d);L.isUndefined(p)&&f!==a||(n[d]=p)}),n}const Vl=e=>{const t=Gn({},e);let{data:n,withXSRFToken:r,xsrfHeaderName:o,xsrfCookieName:s,headers:i,auth:a}=t;if(t.headers=i=Ut.from(i),t.url=Pl(Hl(t.baseURL,t.url,t.allowAbsoluteUrls),e.params,e.paramsSerializer),a&&i.set("Authorization","Basic "+btoa((a.username||"")+":"+(a.password?unescape(encodeURIComponent(a.password)):""))),L.isFormData(n)){if(_t.hasStandardBrowserEnv||_t.hasStandardBrowserWebWorkerEnv)i.setContentType(void 0);else if(L.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(_t.hasStandardBrowserEnv&&(r&&L.isFunction(r)&&(r=r(t)),r||r!==!1&&Fg(t.url))){const l=o&&s&&Bg.read(s);l&&i.set(o,l)}return t},Hg=typeof XMLHttpRequest<"u"&&function(e){return new Promise(function(n,r){const o=Vl(e);let s=o.data;const i=Ut.from(o.headers).normalize();let{responseType:a,onUploadProgress:l,onDownloadProgress:c}=o,d,f,p,h,v;function g(){h&&h(),v&&v(),o.cancelToken&&o.cancelToken.unsubscribe(d),o.signal&&o.signal.removeEventListener("abort",d)}let y=new XMLHttpRequest;y.open(o.method.toUpperCase(),o.url,!0),y.timeout=o.timeout;function x(){if(!y)return;const C=Ut.from("getAllResponseHeaders"in y&&y.getAllResponseHeaders()),T={data:!a||a==="text"||a==="json"?y.responseText:y.response,status:y.status,statusText:y.statusText,headers:C,config:e,request:y};Bl(function(E){n(E),g()},function(E){r(E),g()},T),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 De("Request aborted",De.ECONNABORTED,e,y)),y=null)},y.onerror=function(k){const T=k&&k.message?k.message:"Network Error",S=new De(T,De.ERR_NETWORK,e,y);S.event=k||null,r(S),y=null},y.ontimeout=function(){let k=o.timeout?"timeout of "+o.timeout+"ms exceeded":"timeout exceeded";const T=o.transitional||Dl;o.timeoutErrorMessage&&(k=o.timeoutErrorMessage),r(new De(k,T.clarifyTimeoutError?De.ETIMEDOUT:De.ECONNABORTED,e,y)),y=null},s===void 0&&i.setContentType(null),"setRequestHeader"in y&&L.forEach(i.toJSON(),function(k,T){y.setRequestHeader(T,k)}),L.isUndefined(o.withCredentials)||(y.withCredentials=!!o.withCredentials),a&&a!=="json"&&(y.responseType=o.responseType),c&&([p,v]=Ro(c,!0),y.addEventListener("progress",p)),l&&y.upload&&([f,h]=Ro(l),y.upload.addEventListener("progress",f),y.upload.addEventListener("loadend",h)),(o.cancelToken||o.signal)&&(d=C=>{y&&(r(!C||C.type?new mr(null,e,y):C),y.abort(),y=null)},o.cancelToken&&o.cancelToken.subscribe(d),o.signal&&(o.signal.aborted?d():o.signal.addEventListener("abort",d)));const b=Dg(o.url);if(b&&_t.protocols.indexOf(b)===-1){r(new De("Unsupported protocol "+b+":",De.ERR_BAD_REQUEST,e));return}y.send(s||null)})},Wg=(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 De?d:new mr(d instanceof Error?d.message:d))}};let i=t&&setTimeout(()=>{i=null,s(new De(`timeout ${t} of ms exceeded`,De.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=()=>L.asap(a),l}},Vg=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},Kg=async function*(e,t){for await(const n of qg(e))yield*Vg(n,t)},qg=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()}},Kl=(e,t,n,r)=>{const o=Kg(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})},ql=64*1024,{isFunction:Po}=L,Gg=(({Request:e,Response:t})=>({Request:e,Response:t}))(L.global),{ReadableStream:Gl,TextEncoder:Yl}=L.global,Xl=(e,...t)=>{try{return!!e(...t)}catch{return!1}},Yg=e=>{e=L.merge.call({skipUndefined:!0},Gg,e);const{fetch:t,Request:n,Response:r}=e,o=t?Po(t):typeof fetch=="function",s=Po(n),i=Po(r);if(!o)return!1;const a=o&&Po(Gl),l=o&&(typeof Yl=="function"?(v=>g=>v.encode(g))(new Yl):async v=>new Uint8Array(await new n(v).arrayBuffer())),c=s&&a&&Xl(()=>{let v=!1;const g=new n(_t.origin,{body:new Gl,method:"POST",get duplex(){return v=!0,"half"}}).headers.has("Content-Type");return v&&!g}),d=i&&a&&Xl(()=>L.isReadableStream(new r("").body)),f={stream:d&&(v=>v.body)};o&&["text","arrayBuffer","blob","formData","stream"].forEach(v=>{!f[v]&&(f[v]=(g,y)=>{let x=g&&g[v];if(x)return x.call(g);throw new De(`Response type '${v}' is not supported`,De.ERR_NOT_SUPPORT,y)})});const p=async v=>{if(v==null)return 0;if(L.isBlob(v))return v.size;if(L.isSpecCompliantForm(v))return(await new n(_t.origin,{method:"POST",body:v}).arrayBuffer()).byteLength;if(L.isArrayBufferView(v)||L.isArrayBuffer(v))return v.byteLength;if(L.isURLSearchParams(v)&&(v=v+""),L.isString(v))return(await l(v)).byteLength},h=async(v,g)=>{const y=L.toFiniteNumber(v.getContentLength());return y??p(g)};return async v=>{let{url:g,method:y,data:x,signal:b,cancelToken:C,timeout:k,onDownloadProgress:T,onUploadProgress:S,responseType:E,headers:A,withCredentials:R="same-origin",fetchOptions:D}=Vl(v),B=t||fetch;E=E?(E+"").toLowerCase():"text";let q=Wg([b,C&&C.toAbortSignal()],k),V=null;const j=q&&q.unsubscribe&&(()=>{q.unsubscribe()});let _;try{if(S&&c&&y!=="get"&&y!=="head"&&(_=await h(A,x))!==0){let Q=new n(g,{method:"POST",body:x,duplex:"half"}),M;if(L.isFormData(x)&&(M=Q.headers.get("content-type"))&&A.setContentType(M),Q.body){const[Y,ae]=zl(_,Ro(Ul(S)));x=Kl(Q.body,ql,Y,ae)}}L.isString(R)||(R=R?"include":"omit");const N=s&&"credentials"in n.prototype,z={...D,signal:q,method:y.toUpperCase(),headers:A.normalize().toJSON(),body:x,duplex:"half",credentials:N?R:void 0};V=s&&new n(g,z);let $=await(s?B(V,D):B(g,z));const P=d&&(E==="stream"||E==="response");if(d&&(T||P&&j)){const Q={};["status","statusText","headers"].forEach(ne=>{Q[ne]=$[ne]});const M=L.toFiniteNumber($.headers.get("content-length")),[Y,ae]=T&&zl(M,Ro(Ul(T),!0))||[];$=new r(Kl($.body,ql,Y,()=>{ae&&ae(),j&&j()}),Q)}E=E||"text";let H=await f[L.findKey(f,E)||"text"]($,v);return!P&&j&&j(),await new Promise((Q,M)=>{Bl(Q,M,{data:H,headers:Ut.from($.headers),status:$.status,statusText:$.statusText,config:v,request:V})})}catch(N){throw j&&j(),N&&N.name==="TypeError"&&/Load failed|fetch/i.test(N.message)?Object.assign(new De("Network Error",De.ERR_NETWORK,v,V),{cause:N.cause||N}):De.from(N,N&&N.code,v,V)}}},Xg=new Map,Jl=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=Xg;for(;a--;)l=s[a],c=d.get(l),c===void 0&&d.set(l,c=a?new Map:Yg(t)),d=c;return c};Jl();const vi={http:yg,xhr:Hg,fetch:{get:Jl}};L.forEach(vi,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const Zl=e=>`- ${e}`,Jg=e=>L.isFunction(e)||e===null||e===!1,Ql={getAdapter:(e,t)=>{e=L.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,!Jg(r)&&(o=vi[(a=String(r)).toLowerCase()],o===void 0))throw new De(`Unknown adapter '${a}'`);if(o&&(L.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 :
|
|
30
|
+
<%s key={someKey} {...props} />`,Hn,Ae,rn,Ae),vo[Ae+Hn]=!0}}return N===r?yo(yt):jt(yt),yt}}function hl(N,te,ue){return ri(N,te,ue,!0)}function pl(N,te,ue){return ri(N,te,ue,!1)}var ml=pl,oi=hl;Mr.Fragment=r,Mr.jsx=ml,Mr.jsxs=oi}()),Mr}process.env.NODE_ENV==="production"?ai.exports=Mm():ai.exports=Rm();var u=ai.exports;function vl(e,t){return function(){return e.apply(t,arguments)}}const{toString:Pm}=Object.prototype,{getPrototypeOf:li}=Object,{iterator:So,toStringTag:bl}=Symbol,Co=(e=>t=>{const n=Pm.call(t);return e[n]||(e[n]=n.slice(8,-1).toLowerCase())})(Object.create(null)),on=e=>(e=e.toLowerCase(),t=>Co(t)===e),To=e=>t=>typeof t===e,{isArray:cr}=Array,ur=To("undefined");function Rr(e){return e!==null&&!ur(e)&&e.constructor!==null&&!ur(e.constructor)&&zt(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const wl=on("ArrayBuffer");function Om(e){let t;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?t=ArrayBuffer.isView(e):t=e&&e.buffer&&wl(e.buffer),t}const Dm=To("string"),zt=To("function"),Sl=To("number"),Pr=e=>e!==null&&typeof e=="object",Lm=e=>e===!0||e===!1,ko=e=>{if(Co(e)!=="object")return!1;const t=li(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(bl in e)&&!(So in e)},$m=e=>{if(!Pr(e)||Rr(e))return!1;try{return Object.keys(e).length===0&&Object.getPrototypeOf(e)===Object.prototype}catch{return!1}},Fm=on("Date"),Bm=on("File"),zm=on("Blob"),Um=on("FileList"),Hm=e=>Pr(e)&&zt(e.pipe),Wm=e=>{let t;return e&&(typeof FormData=="function"&&e instanceof FormData||zt(e.append)&&((t=Co(e))==="formdata"||t==="object"&&zt(e.toString)&&e.toString()==="[object FormData]"))},Vm=on("URLSearchParams"),[Km,qm,Gm,Ym]=["ReadableStream","Request","Response","Headers"].map(on),Xm=e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function Or(e,t,{allOwnKeys:n=!1}={}){if(e===null||typeof e>"u")return;let r,o;if(typeof e!="object"&&(e=[e]),cr(e))for(r=0,o=e.length;r<o;r++)t.call(null,e[r],r,e);else{if(Rr(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 Cl(e,t){if(Rr(e))return null;t=t.toLowerCase();const n=Object.keys(e);let r=n.length,o;for(;r-- >0;)if(o=n[r],t===o.toLowerCase())return o;return null}const Vn=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global,Tl=e=>!ur(e)&&e!==Vn;function ci(){const{caseless:e,skipUndefined:t}=Tl(this)&&this||{},n={},r=(o,s)=>{const i=e&&Cl(n,s)||s;ko(n[i])&&ko(o)?n[i]=ci(n[i],o):ko(o)?n[i]=ci({},o):cr(o)?n[i]=o.slice():(!t||!ur(o))&&(n[i]=o)};for(let o=0,s=arguments.length;o<s;o++)arguments[o]&&Or(arguments[o],r);return n}const Jm=(e,t,n,{allOwnKeys:r}={})=>(Or(t,(o,s)=>{n&&zt(o)?e[s]=vl(o,n):e[s]=o},{allOwnKeys:r}),e),Zm=e=>(e.charCodeAt(0)===65279&&(e=e.slice(1)),e),Qm=(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)},eg=(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&&li(e)}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},tg=(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},ng=e=>{if(!e)return null;if(cr(e))return e;let t=e.length;if(!Sl(t))return null;const n=new Array(t);for(;t-- >0;)n[t]=e[t];return n},rg=(e=>t=>e&&t instanceof e)(typeof Uint8Array<"u"&&li(Uint8Array)),og=(e,t)=>{const r=(e&&e[So]).call(e);let o;for(;(o=r.next())&&!o.done;){const s=o.value;t.call(e,s[0],s[1])}},sg=(e,t)=>{let n;const r=[];for(;(n=e.exec(t))!==null;)r.push(n);return r},ig=on("HTMLFormElement"),ag=e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(n,r,o){return r.toUpperCase()+o}),kl=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),lg=on("RegExp"),El=(e,t)=>{const n=Object.getOwnPropertyDescriptors(e),r={};Or(n,(o,s)=>{let i;(i=t(o,s,e))!==!1&&(r[s]=i||o)}),Object.defineProperties(e,r)},cg=e=>{El(e,(t,n)=>{if(zt(e)&&["arguments","caller","callee"].indexOf(n)!==-1)return!1;const r=e[n];if(zt(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+"'")})}})},ug=(e,t)=>{const n={},r=o=>{o.forEach(s=>{n[s]=!0})};return cr(e)?r(e):r(String(e).split(t)),n},dg=()=>{},fg=(e,t)=>e!=null&&Number.isFinite(e=+e)?e:t;function hg(e){return!!(e&&zt(e.append)&&e[bl]==="FormData"&&e[So])}const pg=e=>{const t=new Array(10),n=(r,o)=>{if(Pr(r)){if(t.indexOf(r)>=0)return;if(Rr(r))return r;if(!("toJSON"in r)){t[o]=r;const s=cr(r)?[]:{};return Or(r,(i,a)=>{const l=n(i,o+1);!ur(l)&&(s[a]=l)}),t[o]=void 0,s}}return r};return n(e,0)},mg=on("AsyncFunction"),gg=e=>e&&(Pr(e)||zt(e))&&zt(e.then)&&zt(e.catch),Il=((e,t)=>e?setImmediate:t?((n,r)=>(Vn.addEventListener("message",({source:o,data:s})=>{o===Vn&&s===n&&r.length&&r.shift()()},!1),o=>{r.push(o),Vn.postMessage(n,"*")}))(`axios@${Math.random()}`,[]):n=>setTimeout(n))(typeof setImmediate=="function",zt(Vn.postMessage)),xg=typeof queueMicrotask<"u"?queueMicrotask.bind(Vn):typeof process<"u"&&process.nextTick||Il,F={isArray:cr,isArrayBuffer:wl,isBuffer:Rr,isFormData:Wm,isArrayBufferView:Om,isString:Dm,isNumber:Sl,isBoolean:Lm,isObject:Pr,isPlainObject:ko,isEmptyObject:$m,isReadableStream:Km,isRequest:qm,isResponse:Gm,isHeaders:Ym,isUndefined:ur,isDate:Fm,isFile:Bm,isBlob:zm,isRegExp:lg,isFunction:zt,isStream:Hm,isURLSearchParams:Vm,isTypedArray:rg,isFileList:Um,forEach:Or,merge:ci,extend:Jm,trim:Xm,stripBOM:Zm,inherits:Qm,toFlatObject:eg,kindOf:Co,kindOfTest:on,endsWith:tg,toArray:ng,forEachEntry:og,matchAll:sg,isHTMLForm:ig,hasOwnProperty:kl,hasOwnProp:kl,reduceDescriptors:El,freezeMethods:cg,toObjectSet:ug,toCamelCase:ag,noop:dg,toFiniteNumber:fg,findKey:Cl,global:Vn,isContextDefined:Tl,isSpecCompliantForm:hg,toJSONObject:pg,isAsyncFn:mg,isThenable:gg,setImmediate:Il,asap:xg,isIterable:e=>e!=null&&zt(e[So])};function Me(e,t,n,r,o){Error.call(this),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=new Error().stack,this.message=e,this.name="AxiosError",t&&(this.code=t),n&&(this.config=n),r&&(this.request=r),o&&(this.response=o,this.status=o.status?o.status:null)}F.inherits(Me,Error,{toJSON:function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:F.toJSONObject(this.config),code:this.code,status:this.status}}});const Nl=Me.prototype,Al={};["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=>{Al[e]={value:e}}),Object.defineProperties(Me,Al),Object.defineProperty(Nl,"isAxiosError",{value:!0}),Me.from=(e,t,n,r,o,s)=>{const i=Object.create(Nl);F.toFlatObject(e,i,function(d){return d!==Error.prototype},c=>c!=="isAxiosError");const a=e&&e.message?e.message:"Error",l=t==null&&e?e.code:t;return Me.call(i,a,l,n,r,o),e&&i.cause==null&&Object.defineProperty(i,"cause",{value:e,configurable:!0}),i.name=e&&e.name||"Error",s&&Object.assign(i,s),i};const yg=null;function ui(e){return F.isPlainObject(e)||F.isArray(e)}function jl(e){return F.endsWith(e,"[]")?e.slice(0,-2):e}function _l(e,t,n){return e?e.concat(t).map(function(o,s){return o=jl(o),!n&&s?"["+o+"]":o}).join(n?".":""):t}function vg(e){return F.isArray(e)&&!e.some(ui)}const bg=F.toFlatObject(F,{},null,function(t){return/^is[A-Z]/.test(t)});function Eo(e,t,n){if(!F.isObject(e))throw new TypeError("target must be an object");t=t||new FormData,n=F.toFlatObject(n,{metaTokens:!0,dots:!1,indexes:!1},!1,function(g,y){return!F.isUndefined(y[g])});const r=n.metaTokens,o=n.visitor||d,s=n.dots,i=n.indexes,l=(n.Blob||typeof Blob<"u"&&Blob)&&F.isSpecCompliantForm(t);if(!F.isFunction(o))throw new TypeError("visitor must be a function");function c(v){if(v===null)return"";if(F.isDate(v))return v.toISOString();if(F.isBoolean(v))return v.toString();if(!l&&F.isBlob(v))throw new Me("Blob is not supported. Use a Buffer instead.");return F.isArrayBuffer(v)||F.isTypedArray(v)?l&&typeof Blob=="function"?new Blob([v]):Buffer.from(v):v}function d(v,g,y){let x=v;if(v&&!y&&typeof v=="object"){if(F.endsWith(g,"{}"))g=r?g:g.slice(0,-2),v=JSON.stringify(v);else if(F.isArray(v)&&vg(v)||(F.isFileList(v)||F.endsWith(g,"[]"))&&(x=F.toArray(v)))return g=jl(g),x.forEach(function(C,k){!(F.isUndefined(C)||C===null)&&t.append(i===!0?_l([g],k,s):i===null?g:g+"[]",c(C))}),!1}return ui(v)?!0:(t.append(_l(y,g,s),c(v)),!1)}const f=[],h=Object.assign(bg,{defaultVisitor:d,convertValue:c,isVisitable:ui});function p(v,g){if(!F.isUndefined(v)){if(f.indexOf(v)!==-1)throw Error("Circular reference detected in "+g.join("."));f.push(v),F.forEach(v,function(x,b){(!(F.isUndefined(x)||x===null)&&o.call(t,x,F.isString(b)?b.trim():b,g,h))===!0&&p(x,g?g.concat(b):[b])}),f.pop()}}if(!F.isObject(e))throw new TypeError("data must be an object");return p(e),t}function Ml(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,function(r){return t[r]})}function di(e,t){this._pairs=[],e&&Eo(e,this,t)}const Rl=di.prototype;Rl.append=function(t,n){this._pairs.push([t,n])},Rl.toString=function(t){const n=t?function(r){return t.call(this,r,Ml)}:Ml;return this._pairs.map(function(o){return n(o[0])+"="+n(o[1])},"").join("&")};function wg(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+")}function Pl(e,t,n){if(!t)return e;const r=n&&n.encode||wg;F.isFunction(n)&&(n={serialize:n});const o=n&&n.serialize;let s;if(o?s=o(t,n):s=F.isURLSearchParams(t)?t.toString():new di(t,n).toString(r),s){const i=e.indexOf("#");i!==-1&&(e=e.slice(0,i)),e+=(e.indexOf("?")===-1?"?":"&")+s}return e}class Ol{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){F.forEach(this.handlers,function(r){r!==null&&t(r)})}}const Dl={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},Sg={isBrowser:!0,classes:{URLSearchParams:typeof URLSearchParams<"u"?URLSearchParams:di,FormData:typeof FormData<"u"?FormData:null,Blob:typeof Blob<"u"?Blob:null},protocols:["http","https","file","blob","url","data"]},fi=typeof window<"u"&&typeof document<"u",hi=typeof navigator=="object"&&navigator||void 0,Cg=fi&&(!hi||["ReactNative","NativeScript","NS"].indexOf(hi.product)<0),Tg=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function",kg=fi&&window.location.href||"http://localhost",Mt={...Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv:fi,hasStandardBrowserEnv:Cg,hasStandardBrowserWebWorkerEnv:Tg,navigator:hi,origin:kg},Symbol.toStringTag,{value:"Module"})),...Sg};function Eg(e,t){return Eo(e,new Mt.classes.URLSearchParams,{visitor:function(n,r,o,s){return Mt.isNode&&F.isBuffer(n)?(this.append(r,n.toString("base64")),!1):s.defaultVisitor.apply(this,arguments)},...t})}function Ig(e){return F.matchAll(/\w+|\[(\w*)]/g,e).map(t=>t[0]==="[]"?"":t[1]||t[0])}function Ng(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 Ll(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&&F.isArray(o)?o.length:i,l?(F.hasOwnProp(o,i)?o[i]=[o[i],r]:o[i]=r,!a):((!o[i]||!F.isObject(o[i]))&&(o[i]=[]),t(n,r,o[i],s)&&F.isArray(o[i])&&(o[i]=Ng(o[i])),!a)}if(F.isFormData(e)&&F.isFunction(e.entries)){const n={};return F.forEachEntry(e,(r,o)=>{t(Ig(r),o,n,0)}),n}return null}function Ag(e,t,n){if(F.isString(e))try{return(t||JSON.parse)(e),F.trim(e)}catch(r){if(r.name!=="SyntaxError")throw r}return(n||JSON.stringify)(e)}const Dr={transitional:Dl,adapter:["xhr","http","fetch"],transformRequest:[function(t,n){const r=n.getContentType()||"",o=r.indexOf("application/json")>-1,s=F.isObject(t);if(s&&F.isHTMLForm(t)&&(t=new FormData(t)),F.isFormData(t))return o?JSON.stringify(Ll(t)):t;if(F.isArrayBuffer(t)||F.isBuffer(t)||F.isStream(t)||F.isFile(t)||F.isBlob(t)||F.isReadableStream(t))return t;if(F.isArrayBufferView(t))return t.buffer;if(F.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 Eg(t,this.formSerializer).toString();if((a=F.isFileList(t))||r.indexOf("multipart/form-data")>-1){const l=this.env&&this.env.FormData;return Eo(a?{"files[]":t}:t,l&&new l,this.formSerializer)}}return s||o?(n.setContentType("application/json",!1),Ag(t)):t}],transformResponse:[function(t){const n=this.transitional||Dr.transitional,r=n&&n.forcedJSONParsing,o=this.responseType==="json";if(F.isResponse(t)||F.isReadableStream(t))return t;if(t&&F.isString(t)&&(r&&!this.responseType||o)){const i=!(n&&n.silentJSONParsing)&&o;try{return JSON.parse(t,this.parseReviver)}catch(a){if(i)throw a.name==="SyntaxError"?Me.from(a,Me.ERR_BAD_RESPONSE,this,null,this.response):a}}return t}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:Mt.classes.FormData,Blob:Mt.classes.Blob},validateStatus:function(t){return t>=200&&t<300},headers:{common:{Accept:"application/json, text/plain, */*","Content-Type":void 0}}};F.forEach(["delete","get","head","post","put","patch"],e=>{Dr.headers[e]={}});const jg=F.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"]),_g=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]&&jg[n])&&(n==="set-cookie"?t[n]?t[n].push(r):t[n]=[r]:t[n]=t[n]?t[n]+", "+r:r)}),t},$l=Symbol("internals");function Lr(e){return e&&String(e).trim().toLowerCase()}function Io(e){return e===!1||e==null?e:F.isArray(e)?e.map(Io):String(e)}function Mg(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 Rg=e=>/^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(e.trim());function pi(e,t,n,r,o){if(F.isFunction(r))return r.call(this,t,n);if(o&&(t=n),!!F.isString(t)){if(F.isString(r))return t.indexOf(r)!==-1;if(F.isRegExp(r))return r.test(t)}}function Pg(e){return e.trim().toLowerCase().replace(/([a-z\d])(\w*)/g,(t,n,r)=>n.toUpperCase()+r)}function Og(e,t){const n=F.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 Ut=class{constructor(t){t&&this.set(t)}set(t,n,r){const o=this;function s(a,l,c){const d=Lr(l);if(!d)throw new Error("header name must be a non-empty string");const f=F.findKey(o,d);(!f||o[f]===void 0||c===!0||c===void 0&&o[f]!==!1)&&(o[f||l]=Io(a))}const i=(a,l)=>F.forEach(a,(c,d)=>s(c,d,l));if(F.isPlainObject(t)||t instanceof this.constructor)i(t,n);else if(F.isString(t)&&(t=t.trim())&&!Rg(t))i(_g(t),n);else if(F.isObject(t)&&F.isIterable(t)){let a={},l,c;for(const d of t){if(!F.isArray(d))throw TypeError("Object iterator must return a key-value pair");a[c=d[0]]=(l=a[c])?F.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=Lr(t),t){const r=F.findKey(this,t);if(r){const o=this[r];if(!n)return o;if(n===!0)return Mg(o);if(F.isFunction(n))return n.call(this,o,r);if(F.isRegExp(n))return n.exec(o);throw new TypeError("parser must be boolean|regexp|function")}}}has(t,n){if(t=Lr(t),t){const r=F.findKey(this,t);return!!(r&&this[r]!==void 0&&(!n||pi(this,this[r],r,n)))}return!1}delete(t,n){const r=this;let o=!1;function s(i){if(i=Lr(i),i){const a=F.findKey(r,i);a&&(!n||pi(r,r[a],a,n))&&(delete r[a],o=!0)}}return F.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||pi(this,this[s],s,t,!0))&&(delete this[s],o=!0)}return o}normalize(t){const n=this,r={};return F.forEach(this,(o,s)=>{const i=F.findKey(r,s);if(i){n[i]=Io(o),delete n[s];return}const a=t?Pg(s):String(s).trim();a!==s&&delete n[s],n[a]=Io(o),r[a]=!0}),this}concat(...t){return this.constructor.concat(this,...t)}toJSON(t){const n=Object.create(null);return F.forEach(this,(r,o)=>{r!=null&&r!==!1&&(n[o]=t&&F.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[$l]=this[$l]={accessors:{}}).accessors,o=this.prototype;function s(i){const a=Lr(i);r[a]||(Og(o,i),r[a]=!0)}return F.isArray(t)?t.forEach(s):s(t),this}};Ut.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),F.reduceDescriptors(Ut.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(r){this[n]=r}}}),F.freezeMethods(Ut);function mi(e,t){const n=this||Dr,r=t||n,o=Ut.from(r.headers);let s=r.data;return F.forEach(e,function(a){s=a.call(n,s,o.normalize(),t?t.status:void 0)}),o.normalize(),s}function Fl(e){return!!(e&&e.__CANCEL__)}function dr(e,t,n){Me.call(this,e??"canceled",Me.ERR_CANCELED,t,n),this.name="CanceledError"}F.inherits(dr,Me,{__CANCEL__:!0});function Bl(e,t,n){const r=n.config.validateStatus;!n.status||!r||r(n.status)?e(n):t(new Me("Request failed with status code "+n.status,[Me.ERR_BAD_REQUEST,Me.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n))}function Dg(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function Lg(e,t){e=e||10;const n=new Array(e),r=new Array(e);let o=0,s=0,i;return t=t!==void 0?t:1e3,function(l){const c=Date.now(),d=r[s];i||(i=c),n[o]=l,r[o]=c;let f=s,h=0;for(;f!==o;)h+=n[f++],f=f%e;if(o=(o+1)%e,o===s&&(s=(s+1)%e),c-i<t)return;const p=d&&c-d;return p?Math.round(h*1e3/p):void 0}}function $g(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 No=(e,t,n=3)=>{let r=0;const o=Lg(50,250);return $g(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)},zl=(e,t)=>{const n=e!=null;return[r=>t[0]({lengthComputable:n,total:e,loaded:r}),t[1]]},Ul=e=>(...t)=>F.asap(()=>e(...t)),Fg=Mt.hasStandardBrowserEnv?((e,t)=>n=>(n=new URL(n,Mt.origin),e.protocol===n.protocol&&e.host===n.host&&(t||e.port===n.port)))(new URL(Mt.origin),Mt.navigator&&/(msie|trident)/i.test(Mt.navigator.userAgent)):()=>!0,Bg=Mt.hasStandardBrowserEnv?{write(e,t,n,r,o,s){const i=[e+"="+encodeURIComponent(t)];F.isNumber(n)&&i.push("expires="+new Date(n).toGMTString()),F.isString(r)&&i.push("path="+r),F.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 zg(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function Ug(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function Hl(e,t,n){let r=!zg(t);return e&&(r||n==!1)?Ug(e,t):t}const Wl=e=>e instanceof Ut?{...e}:e;function Kn(e,t){t=t||{};const n={};function r(c,d,f,h){return F.isPlainObject(c)&&F.isPlainObject(d)?F.merge.call({caseless:h},c,d):F.isPlainObject(d)?F.merge({},d):F.isArray(d)?d.slice():d}function o(c,d,f,h){if(F.isUndefined(d)){if(!F.isUndefined(c))return r(void 0,c,f,h)}else return r(c,d,f,h)}function s(c,d){if(!F.isUndefined(d))return r(void 0,d)}function i(c,d){if(F.isUndefined(d)){if(!F.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 F.forEach(Object.keys({...e,...t}),function(d){const f=l[d]||o,h=f(e[d],t[d],d);F.isUndefined(h)&&f!==a||(n[d]=h)}),n}const Vl=e=>{const t=Kn({},e);let{data:n,withXSRFToken:r,xsrfHeaderName:o,xsrfCookieName:s,headers:i,auth:a}=t;if(t.headers=i=Ut.from(i),t.url=Pl(Hl(t.baseURL,t.url,t.allowAbsoluteUrls),e.params,e.paramsSerializer),a&&i.set("Authorization","Basic "+btoa((a.username||"")+":"+(a.password?unescape(encodeURIComponent(a.password)):""))),F.isFormData(n)){if(Mt.hasStandardBrowserEnv||Mt.hasStandardBrowserWebWorkerEnv)i.setContentType(void 0);else if(F.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(Mt.hasStandardBrowserEnv&&(r&&F.isFunction(r)&&(r=r(t)),r||r!==!1&&Fg(t.url))){const l=o&&s&&Bg.read(s);l&&i.set(o,l)}return t},Hg=typeof XMLHttpRequest<"u"&&function(e){return new Promise(function(n,r){const o=Vl(e);let s=o.data;const i=Ut.from(o.headers).normalize();let{responseType:a,onUploadProgress:l,onDownloadProgress:c}=o,d,f,h,p,v;function g(){p&&p(),v&&v(),o.cancelToken&&o.cancelToken.unsubscribe(d),o.signal&&o.signal.removeEventListener("abort",d)}let y=new XMLHttpRequest;y.open(o.method.toUpperCase(),o.url,!0),y.timeout=o.timeout;function x(){if(!y)return;const C=Ut.from("getAllResponseHeaders"in y&&y.getAllResponseHeaders()),S={data:!a||a==="text"||a==="json"?y.responseText:y.response,status:y.status,statusText:y.statusText,headers:C,config:e,request:y};Bl(function(E){n(E),g()},function(E){r(E),g()},S),y=null}"onloadend"in y?y.onloadend=x:y.onreadystatechange=function(){!y||y.readyState!==4||y.status===0&&!(y.responseURL&&y.responseURL.indexOf("file:")===0)||setTimeout(x)},y.onabort=function(){y&&(r(new Me("Request aborted",Me.ECONNABORTED,e,y)),y=null)},y.onerror=function(k){const S=k&&k.message?k.message:"Network Error",T=new Me(S,Me.ERR_NETWORK,e,y);T.event=k||null,r(T),y=null},y.ontimeout=function(){let k=o.timeout?"timeout of "+o.timeout+"ms exceeded":"timeout exceeded";const S=o.transitional||Dl;o.timeoutErrorMessage&&(k=o.timeoutErrorMessage),r(new Me(k,S.clarifyTimeoutError?Me.ETIMEDOUT:Me.ECONNABORTED,e,y)),y=null},s===void 0&&i.setContentType(null),"setRequestHeader"in y&&F.forEach(i.toJSON(),function(k,S){y.setRequestHeader(S,k)}),F.isUndefined(o.withCredentials)||(y.withCredentials=!!o.withCredentials),a&&a!=="json"&&(y.responseType=o.responseType),c&&([h,v]=No(c,!0),y.addEventListener("progress",h)),l&&y.upload&&([f,p]=No(l),y.upload.addEventListener("progress",f),y.upload.addEventListener("loadend",p)),(o.cancelToken||o.signal)&&(d=C=>{y&&(r(!C||C.type?new dr(null,e,y):C),y.abort(),y=null)},o.cancelToken&&o.cancelToken.subscribe(d),o.signal&&(o.signal.aborted?d():o.signal.addEventListener("abort",d)));const b=Dg(o.url);if(b&&Mt.protocols.indexOf(b)===-1){r(new Me("Unsupported protocol "+b+":",Me.ERR_BAD_REQUEST,e));return}y.send(s||null)})},Wg=(e,t)=>{const{length:n}=e=e?e.filter(Boolean):[];if(t||n){let r=new AbortController,o;const s=function(c){if(!o){o=!0,a();const d=c instanceof Error?c:this.reason;r.abort(d instanceof Me?d:new dr(d instanceof Error?d.message:d))}};let i=t&&setTimeout(()=>{i=null,s(new Me(`timeout ${t} of ms exceeded`,Me.ETIMEDOUT))},t);const a=()=>{e&&(i&&clearTimeout(i),i=null,e.forEach(c=>{c.unsubscribe?c.unsubscribe(s):c.removeEventListener("abort",s)}),e=null)};e.forEach(c=>c.addEventListener("abort",s));const{signal:l}=r;return l.unsubscribe=()=>F.asap(a),l}},Vg=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},Kg=async function*(e,t){for await(const n of qg(e))yield*Vg(n,t)},qg=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()}},Kl=(e,t,n,r)=>{const o=Kg(e,t);let s=0,i,a=l=>{i||(i=!0,r&&r(l))};return new ReadableStream({async pull(l){try{const{done:c,value:d}=await o.next();if(c){a(),l.close();return}let f=d.byteLength;if(n){let h=s+=f;n(h)}l.enqueue(new Uint8Array(d))}catch(c){throw a(c),c}},cancel(l){return a(l),o.return()}},{highWaterMark:2})},ql=64*1024,{isFunction:Ao}=F,Gg=(({Request:e,Response:t})=>({Request:e,Response:t}))(F.global),{ReadableStream:Gl,TextEncoder:Yl}=F.global,Xl=(e,...t)=>{try{return!!e(...t)}catch{return!1}},Yg=e=>{e=F.merge.call({skipUndefined:!0},Gg,e);const{fetch:t,Request:n,Response:r}=e,o=t?Ao(t):typeof fetch=="function",s=Ao(n),i=Ao(r);if(!o)return!1;const a=o&&Ao(Gl),l=o&&(typeof Yl=="function"?(v=>g=>v.encode(g))(new Yl):async v=>new Uint8Array(await new n(v).arrayBuffer())),c=s&&a&&Xl(()=>{let v=!1;const g=new n(Mt.origin,{body:new Gl,method:"POST",get duplex(){return v=!0,"half"}}).headers.has("Content-Type");return v&&!g}),d=i&&a&&Xl(()=>F.isReadableStream(new r("").body)),f={stream:d&&(v=>v.body)};o&&["text","arrayBuffer","blob","formData","stream"].forEach(v=>{!f[v]&&(f[v]=(g,y)=>{let x=g&&g[v];if(x)return x.call(g);throw new Me(`Response type '${v}' is not supported`,Me.ERR_NOT_SUPPORT,y)})});const h=async v=>{if(v==null)return 0;if(F.isBlob(v))return v.size;if(F.isSpecCompliantForm(v))return(await new n(Mt.origin,{method:"POST",body:v}).arrayBuffer()).byteLength;if(F.isArrayBufferView(v)||F.isArrayBuffer(v))return v.byteLength;if(F.isURLSearchParams(v)&&(v=v+""),F.isString(v))return(await l(v)).byteLength},p=async(v,g)=>{const y=F.toFiniteNumber(v.getContentLength());return y??h(g)};return async v=>{let{url:g,method:y,data:x,signal:b,cancelToken:C,timeout:k,onDownloadProgress:S,onUploadProgress:T,responseType:E,headers:j,withCredentials:R="same-origin",fetchOptions:O}=Vl(v),B=t||fetch;E=E?(E+"").toLowerCase():"text";let q=Wg([b,C&&C.toAbortSignal()],k),K=null;const P=q&&q.unsubscribe&&(()=>{q.unsubscribe()});let M;try{if(T&&c&&y!=="get"&&y!=="head"&&(M=await p(j,x))!==0){let H=new n(g,{method:"POST",body:x,duplex:"half"}),_;if(F.isFormData(x)&&(_=H.headers.get("content-type"))&&j.setContentType(_),H.body){const[G,re]=zl(M,No(Ul(T)));x=Kl(H.body,ql,G,re)}}F.isString(R)||(R=R?"include":"omit");const I=s&&"credentials"in n.prototype,z={...O,signal:q,method:y.toUpperCase(),headers:j.normalize().toJSON(),body:x,duplex:"half",credentials:I?R:void 0};K=s&&new n(g,z);let L=await(s?B(K,O):B(g,z));const A=d&&(E==="stream"||E==="response");if(d&&(S||A&&P)){const H={};["status","statusText","headers"].forEach(ee=>{H[ee]=L[ee]});const _=F.toFiniteNumber(L.headers.get("content-length")),[G,re]=S&&zl(_,No(Ul(S),!0))||[];L=new r(Kl(L.body,ql,G,()=>{re&&re(),P&&P()}),H)}E=E||"text";let $=await f[F.findKey(f,E)||"text"](L,v);return!A&&P&&P(),await new Promise((H,_)=>{Bl(H,_,{data:$,headers:Ut.from(L.headers),status:L.status,statusText:L.statusText,config:v,request:K})})}catch(I){throw P&&P(),I&&I.name==="TypeError"&&/Load failed|fetch/i.test(I.message)?Object.assign(new Me("Network Error",Me.ERR_NETWORK,v,K),{cause:I.cause||I}):Me.from(I,I&&I.code,v,K)}}},Xg=new Map,Jl=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=Xg;for(;a--;)l=s[a],c=d.get(l),c===void 0&&d.set(l,c=a?new Map:Yg(t)),d=c;return c};Jl();const gi={http:yg,xhr:Hg,fetch:{get:Jl}};F.forEach(gi,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const Zl=e=>`- ${e}`,Jg=e=>F.isFunction(e)||e===null||e===!1,Ql={getAdapter:(e,t)=>{e=F.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,!Jg(r)&&(o=gi[(a=String(r)).toLowerCase()],o===void 0))throw new Me(`Unknown adapter '${a}'`);if(o&&(F.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
33
|
`+i.map(Zl).join(`
|
|
34
|
-
`):" "+Zl(i[0]):"as no adapter specified";throw new
|
|
35
|
-
`+s):r.stack=s}catch{}}throw r}}_request(t,n){typeof t=="string"?(n=n||{},n.url=t):n=t||{},n=Gn(this.defaults,n);const{transitional:r,paramsSerializer:o,headers:s}=n;r!==void 0&&Do.assertOptions(r,{silentJSONParsing:pn.transitional(pn.boolean),forcedJSONParsing:pn.transitional(pn.boolean),clarifyTimeoutError:pn.transitional(pn.boolean)},!1),o!=null&&(L.isFunction(o)?n.paramsSerializer={serialize:o}:Do.assertOptions(o,{encode:pn.function,serialize:pn.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),Do.assertOptions(n,{baseUrl:pn.spelling("baseURL"),withXsrfToken:pn.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let i=s&&L.merge(s.common,s[n.method]);s&&L.forEach(["delete","get","head","post","put","patch","common"],v=>{delete s[v]}),n.headers=Ut.concat(i,s);const a=[];let l=!0;this.interceptors.request.forEach(function(g){typeof g.runWhen=="function"&&g.runWhen(n)===!1||(l=l&&g.synchronous,a.unshift(g.fulfilled,g.rejected))});const c=[];this.interceptors.response.forEach(function(g){c.push(g.fulfilled,g.rejected)});let d,f=0,p;if(!l){const v=[ec.bind(this),void 0];for(v.unshift(...a),v.push(...c),p=v.length,d=Promise.resolve(n);f<p;)d=d.then(v[f++],v[f++]);return d}p=a.length;let h=n;for(;f<p;){const v=a[f++],g=a[f++];try{h=v(h)}catch(y){g.call(this,y);break}}try{d=ec.call(this,h)}catch(v){return Promise.reject(v)}for(f=0,p=c.length;f<p;)d=d.then(c[f++],c[f++]);return d}getUri(t){t=Gn(this.defaults,t);const n=Hl(t.baseURL,t.url,t.allowAbsoluteUrls);return Pl(n,t.params,t.paramsSerializer)}};L.forEach(["delete","get","head","options"],function(t){Yn.prototype[t]=function(n,r){return this.request(Gn(r||{},{method:t,url:n,data:(r||{}).data}))}}),L.forEach(["post","put","patch"],function(t){function n(r){return function(s,i,a){return this.request(Gn(a||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:s,data:i}))}}Yn.prototype[t]=n(),Yn.prototype[t+"Form"]=n(!0)});let Qg=class Am{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 mr(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 Am(function(o){t=o}),cancel:t}}};function ex(e){return function(n){return e.apply(null,n)}}function tx(e){return L.isObject(e)&&e.isAxiosError===!0}const wi={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(wi).forEach(([e,t])=>{wi[t]=e});function rc(e){const t=new Yn(e),n=vl(Yn.prototype.request,t);return L.extend(n,Yn.prototype,t,{allOwnKeys:!0}),L.extend(n,t,null,{allOwnKeys:!0}),n.create=function(o){return rc(Gn(e,o))},n}const vt=rc(Hr);vt.Axios=Yn,vt.CanceledError=mr,vt.CancelToken=Qg,vt.isCancel=Fl,vt.VERSION=tc,vt.toFormData=_o,vt.AxiosError=De,vt.Cancel=vt.CanceledError,vt.all=function(t){return Promise.all(t)},vt.spread=ex,vt.isAxiosError=tx,vt.mergeConfig=Gn,vt.AxiosHeaders=Ut,vt.formToJSON=e=>Ll(L.isHTMLForm(e)?new FormData(e):e),vt.getAdapter=Ql.getAdapter,vt.HttpStatusCode=wi,vt.default=vt;const{Axios:Zk,AxiosError:Qk,CanceledError:eE,isCancel:tE,CancelToken:nE,VERSION:rE,all:oE,Cancel:sE,isAxiosError:iE,spread:aE,toFormData:lE,AxiosHeaders:cE,HttpStatusCode:uE,formToJSON:dE,getAdapter:fE,mergeConfig:pE}=vt,oc=typeof window<"u"?window.__API_BASE_URL__:void 0,sc=oc?Tn(oc):void 0;function Tn(e){const n=(e!=null&&e.trim()?e.trim():"/api/chat").replace(/\/+$/,"");return n?n.endsWith("/chat")?n:`${n}/chat`:"/api/chat"}let Lo=null;const Si=new Set;function ic(){return Lo}function $o(e){Lo=e,Si.forEach(t=>t(e))}function ac(e){return Si.add(e),()=>Si.delete(e)}const nx=3e4,rx=9e4,Ht=vt.create({...sc?{baseURL:sc}:{},timeout:nx,withCredentials:!0});Ht.interceptors.request.use(e=>(Lo&&(e.headers.Authorization=`Bearer ${Lo}`),e)),Ht.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),$o(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 Wt(e,t){return Ht.defaults.baseURL?(await Ht.get(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}async function Fo(e,t,n){return Ht.defaults.baseURL?(await Ht.post(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function lc(e,t,n){return Ht.defaults.baseURL?(await Ht.put(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function Ci(e,t){return Ht.defaults.baseURL?(await Ht.delete(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}function Mt(e){return e&&typeof e=="object"&&"data"in e?e.data:e}class cc{get baseUrl(){const t=Ht.defaults.baseURL;return t?Tn(String(t)):""}updateConfig(t){t.baseUrl&&(Ht.defaults.baseURL=Tn(String(t.baseUrl))),t.authToken!==void 0&&$o(t.authToken)}getAuthToken(){return ic()}setAuthToken(t){$o(t)}onTokenChange(t){return ac(t)}async listThreads(){const t=await Wt("/threads"),n=Mt(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async listSharedThreads(){const t=await Wt("/threads/shared"),n=Mt(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async listSmartOrgUsers(){const t=Ht.defaults.baseURL?Ht.defaults.baseURL.replace(/\/chat\/?$/,""):"/api",n=await Wt("/auth/users",{baseURL:t}),r=Mt(n);return(r==null?void 0:r.users)??[]}async createThread(t){const r=await Fo("/threads",t?{title:t}:void 0);return Mt(r)}async updateThread(t,n){const r=await lc(`/threads/${t}`,{title:n});return Mt(r)}async deleteThread(t){const n=await Ci(`/threads/${t}`);return Mt(n)}async shareThread(t,n){const r=await Fo(`/threads/${t}/share`,{shared_with_user_id:n});return Mt(r)}async threadInfo(t){const n=await Wt(`/threads/${t}/info`);return Mt(n)}async listAgents(){const t=await Wt("/agents"),n=Mt(t);return(n==null?void 0:n.items)??[]}async getAgent(t){const n=await Wt(`/agents/${t}`);return Mt(n)}async getAgentSchema(t){const n=await Wt(`/agents/${t}/schema`);return Mt(n)}async getState(t){const n=await Wt(`/threads/${t.threadId}/state`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return Mt(n)}async getStateHistory(t){const n=await Wt(`/threads/${t.threadId}/state/history`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs},timeout:rx});return Mt(n)}async cancelRun(t){const n=await Fo("/runs/cancel",{threadId:t});return Mt(n)}async listCheckpointSummaries(t){const n=await Wt(`/threads/${t}/state/checkpoints`,{params:{thread_id:t}}),r=Mt(n);return(r==null?void 0:r.items)??[]}async unshareThread(t,n){const r=await Ci(`/threads/${t}/share/${n}`);return Mt(r)}}const jn=new cc,uc=w.createContext(null);function ox({children:e,apiConfig:t}){const n=jn;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(uc.Provider,{value:r,children:e})}function Ti(){const e=w.useContext(uc);if(!e)throw new Error("useApi must be used within ApiProvider");return e}async function sx(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 ix(e,t=[],n,r,o,s){const i=[],a=[];for(const l of t)try{const c=await sx(l);a.push({filename:l.name,data:c,mime_type:l.type||"application/octet-stream"})}catch{}return{contentParts:i,filesInfo:a}}const dc=120;function ax(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>dc?`${n.slice(0,dc-3)}…`:n:""}function fc(e){return ax(e.content)||""}function lx(e){const t=new Map;for(const n of e){if(!n.id||n.role!=="user")continue;const r=fc(n);r&&t.set(n.id,r)}return t}function cx(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=fc(o);s&&t.set(r.checkpointId,s)}}return t}const ux={human:"user",user:"user",ai:"assistant",assistant:"assistant",tool:"tool",function:"tool",system:"system"};function ki(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 dx(e,t){return`${e??""}::${t??""}`}function gr(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(!ki(r))return{threadId:n,latest:null,checkpoints:[],timeline:[],interrupt:null,snapshots:{}};const{orderedSnapshots:o,snapshotMap:s}=px(t),i=pc(r,0),a=hx(o);return{threadId:n,latest:i,checkpoints:o,timeline:a,interrupt:(i==null?void 0:i.interrupt)??null,snapshots:s}}function pc(e,t){if(!ki(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(R=>!!R&&typeof R=="object").map(R=>({...R})):a===null?null:void 0,c=r.map((R,D)=>Cx(R,D)).filter(R=>!!R),d=Lt(e.config),f=Lt(d==null?void 0:d.configurable),p=ft(f,["checkpoint_id","checkpointId"]),h=ft(f,["checkpoint_ns","checkpointNs"]),v=Lt(e==null?void 0:e.parentConfig),g=Lt(v==null?void 0:v.configurable),y=ft(g,["checkpoint_id","checkpointId"])??null,x=ft(g,["checkpoint_ns","checkpointNs"])??null,b=e==null?void 0:e.createdAt,C=typeof b=="string"&&b.trim()?b:new Date(Date.now()-t).toISOString(),k=c.slice().reverse().find(R=>R.role==="user")??null,T=Lt(e==null?void 0:e.metadata),S=ft(T,["branch_label","branchLabel"]),E=ft(g,["checkpoint_id","checkpointId"]),A=Array.isArray(e.next)?[...e.next]:(e==null?void 0:e.next)===null?null:void 0;return{messages:c,checkpointId:p??null,checkpointNs:h??null,nextCursor:y,nextCursorNs:x,interrupt:fx(a,c,t),createdAt:C,parentId:E??null,branchLabel:S??null,lastUserMessageId:(k==null?void 0:k.id)??null,hasMessages:c.length>0,messagesLen:c.length,metadata:T??null,config:d??null,parentConfig:v??null,next:A??null,tasks:l??null,values:i??null}}function fx(e,t,n){const r=wx(e,n);return r||bx(t,n)}function px(e){const t=new Map;e.forEach((o,s)=>{if(!ki(o))return;const i=pc(o,s);if(!(i!=null&&i.checkpointId))return;const a=dx(i.checkpointId,i.checkpointNs??null),l=t.get(a);if(!l){t.set(a,i);return}t.set(a,xx(l,i))});const n=Array.from(t.values());n.sort((o,s)=>mc(s.createdAt??"")-mc(o.createdAt??""));const r={};for(const[o,s]of t.entries())r[o]=s;return{orderedSnapshots:n,snapshotMap:r}}function hx(e){var n,r;const t=[];for(const o of e){const s=o.checkpointId??null;if(!s)continue;const i=o.metadata??{},a=ft(i,["label"])??ft(i,["branch_label","branchLabel"])??ft(i,["description"])??"User input",l=gx(i,["step"]),c=ft(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=mx(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 mx(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 gx(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 xx(e,t){return{...e,metadata:Bo(e.metadata,t.metadata)??null,config:Bo(e.config,t.config)??null,parentConfig:Bo(e.parentConfig,t.parentConfig)??null,next:yx(e.next,t.next)??null,tasks:vx(e.tasks,t.tasks)??null,values:Bo(e.values,t.values)??null}}function Bo(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 yx(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 vx(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 bx(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 wx(e,t){if(!Array.isArray(e)||!e.length)return null;for(let n=e.length-1;n>=0;n--){const r=Sx(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=Vr(r.interrupts[s],`${o}-interrupt-${s}`);if(i)return i}if(r.state!==void 0&&r.state!==null){const s=Vr(r.state,`${o}-state`);if(s)return s}}return null}function Sx(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,v=typeof l=="string"&&l.trim()?l:Array.isArray(c)&&typeof c[0]=="string"?String(c[0]):"task",g=Array.isArray(d)?d:void 0,y=p.length?p[p.length-1]:void 0;return{id:h,name:v,interrupts:g,state:y!==void 0?y:f}}const n=Lt(e);if(!n)return null;const r=ft(n,["id","thread_id","taskId"])??t,o=ft(n,["name"])??"task",s=Array.isArray(n.interrupts)?n.interrupts:void 0,i=Object.prototype.hasOwnProperty.call(n,"state")?n.state:void 0;return{id:r,name:o,interrupts:s,state:i}}function Vr(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=hc(e,t);if(o)return o;if(Array.isArray(e)){for(let s=e.length-1;s>=0;s--){const i=Vr(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=Vr(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=Vr(l,t,n+1,r);if(c)return c}}return null}function hc(e,t){if(!e)return null;if(typeof e=="object"&&!Array.isArray(e)){const n=e,r=ft(n,["type","event","kind"]),o=ft(n,["id","interrupt_id","interruptId","value_id"])??(r&&r.toLowerCase().includes("interrupt")?t:void 0);if(!(Object.prototype.hasOwnProperty.call(n,"value")||Object.prototype.hasOwnProperty.call(n,"data")||Object.prototype.hasOwnProperty.call(n,"payload"))&&!(r&&r.toLowerCase().includes("interrupt")))return null;const i=Object.prototype.hasOwnProperty.call(n,"value")?n.value:Object.prototype.hasOwnProperty.call(n,"data")?n.data:Object.prototype.hasOwnProperty.call(n,"payload")?n.payload:n,a=o&&o.trim()?o:t;return a?{id:a,value:i}:null}if(Array.isArray(e)){for(let n=e.length-1;n>=0;n--){const r=hc(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 mc(e){if(!e)return 0;const t=Date.parse(e);return Number.isFinite(t)?t:0}function Cx(e,t){if(!e||typeof e!="object")return null;const n=e,r=Lt(e)??{},o=Lt(n.data)??r,s=String(n.type??o.type??o.role??"").toLowerCase(),i=ux[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=Lt(o.additional_kwargs)??Lt(o.additionalKwargs),d=Lt(o.response_metadata)??Lt(o.responseMetadata),f=ft(c,["createdAt","created_at"])??ft(o,["created_at","createdAt"]),p=ft(c,["checkpointId","checkpoint_id"]),h=ft(c,["checkpointNs","checkpoint_ns"]),v=Tx(o.content),g={id:l,role:i,content:v};f&&(g.createdAt=f),typeof o.name=="string"&&o.name.trim()&&(g.name=o.name),typeof(d==null?void 0:d.model_name)=="string"&&(g.model=String(d.model_name)),!g.model&&typeof o.model=="string"&&(g.model=o.model),p&&(g.checkpointId=p),h&&(g.checkpointNs=h);const y=Ix(Lt(o.artifact??r.artifact??o.artifacts??r.artifacts));y&&(g.artifact=y);const x=_x(c,["createdAt","created_at","checkpointId","checkpoint_id","checkpointNs","checkpoint_ns","tool_calls"]),b=d?{...d}:void 0;x&&Object.keys(x).length&&(g.additionalKwargs=x),b&&Object.keys(b).length&&(g.responseMetadata=b);const C=kx((c==null?void 0:c.tool_calls)??o.tool_calls);if(C.length&&(g.content=[...g.content,...C]),i==="tool"){const k=Ex(o,g.content);k&&(g.content=k)}return g}function Tx(e){if(!e)return[];if(Array.isArray(e))return e.map(t=>gc(t)).filter(t=>!!t);if(typeof e=="string")return e.trim()?[{type:"text",text:e.trim()}]:[];if(typeof e=="object"){const t=gc(e);return t?[t]:[]}return[]}function gc(e){if(!e||typeof e!="object")return typeof e=="string"&&e.trim()?{type:"text",text:e}:null;const t=e,n=String(t.type??"").toLowerCase();if(!n||n==="text"){const o=typeof t.text=="string"?t.text:typeof t.value=="string"?t.value:"";return o.trim()?{type:"text",text:o}:null}if(n==="image"||n==="image_url"){const o=ft(t,["url","src"]);if(!o)return null;const s={type:"image_url",url:o};return typeof t.mimeType=="string"&&(s.mimeType=t.mimeType),typeof t.alt=="string"&&(s.alt=t.alt),s}if(n==="file"){const o=ft(t,["url"]);if(!o)return null;const s={type:"file",url:o};return typeof t.mimeType=="string"&&(s.mimeType=t.mimeType),typeof t.name=="string"&&(s.name=t.name),typeof t.size=="number"&&(s.size=t.size),typeof t.sourceType=="string"&&(s.sourceType=t.sourceType),s}if(n==="tool_call")return xc(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=ft(t,["text","content"]);if(o)return{type:"text",text:o}}const r=typeof t.content=="string"?t.content:typeof t.value=="string"?t.value:JSON.stringify(t);return r?{type:"text",text:r}:null}function xc(e,t){var s;const n=ft(e,["id","call_id"])??t,r=ft(e,["name"])??ft(Lt(e.function),["name"]);if(!n||!r)return null;const o=jx(e.args??e.arguments??((s=Lt(e.function))==null?void 0:s.arguments));return{type:"tool_call",id:n,name:r,args:o}}function kx(e){return Array.isArray(e)?e.map((t,n)=>xc(t,`tool_call_${n}`)).filter(t=>!!t):[]}function Ex(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 Ix(e){return e?{plots:Nx(e.plots)}:void 0}function Nx(e){return Array.isArray(e)?e.map(t=>Ax(t)).filter(t=>!!t):[]}function Ax(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 jx(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 Lt(e){if(!(!e||typeof e!="object"||Array.isArray(e)))return{...e}}function ft(e,t){if(e)for(const n of t){const r=e[n];if(typeof r=="string"&&r.trim())return r}}function _x(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 yc="aiNav:tool-progress";function Ei(){return typeof window<"u"&&typeof window.localStorage<"u"}function vc(e){return`${yc}:${e}`}function Mx(e,t,n){if(!Ei()||!e)return;const r=vc(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 Rx(e){if(!Ei()||!e)return;const t=vc(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 bc(){if(!Ei())return;const e=[];for(let t=0;t<window.localStorage.length;t+=1){const n=window.localStorage.key(t);n!=null&&n.startsWith(yc)&&e.push(n)}for(const t of e)window.localStorage.removeItem(t)}const Et=[];for(let e=0;e<256;++e)Et.push((e+256).toString(16).slice(1));function Px(e,t=0){return(Et[e[t+0]]+Et[e[t+1]]+Et[e[t+2]]+Et[e[t+3]]+"-"+Et[e[t+4]]+Et[e[t+5]]+"-"+Et[e[t+6]]+Et[e[t+7]]+"-"+Et[e[t+8]]+Et[e[t+9]]+"-"+Et[e[t+10]]+Et[e[t+11]]+Et[e[t+12]]+Et[e[t+13]]+Et[e[t+14]]+Et[e[t+15]]).toLowerCase()}let Ii;const Ox=new Uint8Array(16);function Dx(){if(!Ii){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Ii=crypto.getRandomValues.bind(crypto)}return Ii(Ox)}const wc={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function Lx(e,t,n){var o;e=e||{};const r=e.random??((o=e.rng)==null?void 0:o.call(e))??Dx();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,Px(r)}function $x(e,t,n){return wc.randomUUID&&!e?wc.randomUUID():Lx(e)}function Ni(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 zo(e,t,n){return t<0||t>=e.length?e:[...e.slice(0,t),n,...e.slice(t+1)]}function Sc(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 Cc(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 Fx(e,t){const n=new Set;for(const o of t)typeof o=="string"&&o.trim()&&n.add(o.trim());const r=Kx(e);for(const o of r)n.add(o);return Array.from(n)}function kc(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 Bx(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 Uo(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:$x(),idx:a.length+1,timestamp:new Date().toISOString(),...n};return a.push(l),Mx(o.id,a,{checkpointId:o.checkpointId??null,checkpointNs:o.checkpointNs??null}),i.toolProgress=a,s[r]={...o,additionalKwargs:i},s}function Ec(e,t){return e.includes(t)?e:[...e,t]}function zx(e,t){const n=[...e],r=n.lastIndexOf(t);return r!==-1&&n.splice(r,1),n}function xr(e,t){let n=!1;const r={},o=e.map(s=>{const i=qx(s);if(i.length)return r[s.id]=i,s;const a=t[s.id]??Rx(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 Ux(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=Hx(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??"",v={...p,text:h+l};c=[...c.slice(0,c.length-1),v]}else c=[...c,{type:"text",text:l}];o.lastText=a+l}else o.lastText=a}i.length&&(c=[...c,...i]);const d=!!(l||i.length);return{newParts:c,newMeta:o,changed:d}}function Nc(e){return e.replace(/\s+/g," ").trim()}function Hx(e,t){if(!t)return"";if(!e)return t;if(e===t)return"";const n=Math.min(e.length,t.length);for(let i=n;i>0;i--)if(e.slice(-i)===t.slice(0,i))return t.slice(i);const r=Nc(e),o=Nc(t);if(r===o)return"";const s=Math.min(r.length,o.length);for(let i=s;i>0;i--)if(r.slice(-i)===o.slice(0,i))return t;return t}function Wx(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 zo(e,r,s)}return e}function Vx(e){if(!e)return null;const t=e.split("/");return t[t.length-1]||null}function Kx(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 qx(e){const t=e.additionalKwargs??{};return Array.isArray(t.toolProgress)?[...t.toolProgress]:[]}const Gx={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},toolStreamingMessageId:null,toolStreamingStack:[],messagesStreamMeta:{},pendingInterrupt:null,toolTimelines:{}};function Yx(e,t){var n;switch(t.type){case"reset":return{messages:Ni(((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=Ni(t.payload.messages),{messages:o,toolTimelines:s}=xr(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=Ni(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}=xr(i,e.toolTimelines);return{...e,messages:a,toolTimelines:l}}case"event":return jc(e,t.payload.ev);case"batch":{const{events:r}=t.payload;return r.length?r.reduce((o,s)=>jc(o,s),e):e}case"interrupt_response":return{...e,messages:Sc(e.messages),pendingInterrupt:null};default:return e}}function Ac(e=[]){const[t,n]=w.useReducer(Yx,{...Gx,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 jc(e,t){var n,r,o,s;if(t.type==="message.start"&&t.role==="assistant"){const i=t.id,a=Vx(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??Cc(e.messages);if(!i)return e;const a=e.messages,l=a.findIndex(C=>C.id===i&&C.role==="assistant");if(l===-1)return e;const 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:v,changed:g}=Ux(c.content,t.delta,f,p);if(!g)return e;const y={...c,content:h},x=zo(a,l,y),b={...d,[i]:v};return{...e,messages:x,messagesStreamMeta:b}}if(t.type==="message.end"){const i=e.assemblingId??Cc(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,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:{...Bx(void 0,c.length?c:[d],l,t.args),toolStreaming:!0}},C=Fx(b,c.length?c:[d]),k=[...e.messages,b],T=Uo(k,b.id,p),{messages:S,toolTimelines:E}=xr(T,e.toolTimelines);return{...e,messages:S,toolIndex:kc(e.toolIndex,b.id,C),toolStreamingMessageId:b.id,toolStreamingStack:Ec(e.toolStreamingStack??[],a??d),toolTimelines:E}}const v=Uo(e.messages,h,p),{messages:g,toolTimelines:y}=xr(v,e.toolTimelines);return{...e,messages:g,toolIndex:kc(e.toolIndex,h,c),toolStreamingStack:Ec(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=zx(l,a),f=d[0]?e.toolIndex[d[0]]:null,p=e.toolStreamingMessageId,h=c===a,v=t.name??((s=e.messages.find(T=>T.id===p))==null?void 0:s.name)??"tool",g=typeof t.output=="string"?t.output.trim():JSON.stringify(t.output??""),y={type:"tool.end",toolId:a,toolName:v,content:g==null?void 0:g.slice(0,200)};let x=e.messages;if(p&&(x=Uo(x,p,y)),h&&p){const T=x.findIndex(S=>S.id===p);if(T>=0){const S=x[T],A={type:"text",text:(()=>{if(typeof t.output=="string"){const D=t.output.trim();try{return D}catch{return D}}return JSON.stringify(t.output??"")})()},R={...S,content:[A],artifact:t.artifact??S.artifact,additionalKwargs:{...S.additionalKwargs??{}}};x=zo(x,T,R)}}const b=d,{messages:C,toolTimelines:k}=xr(x,e.toolTimelines);return{...e,messages:C,toolTimelines:k,toolStreamingMessageId:h?f:p,toolStreamingStack:b}}if(t.type==="tool.progress"){const i=e.toolStreamingMessageId;if(!i)return e;const a={type:"tool.progress",content:t.content??null},l=Uo(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=zo(l,c,p),{messages:v,toolTimelines:g}=xr(h,e.toolTimelines);return{...e,messages:v,toolTimelines:g}}if(t.type==="checkpoint"){const i=t.checkpointNs??e.lastCheckpointNs??null,a=Wx(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=gr(t),a=i.interrupt,l=i.latest,c=a===null?Sc(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 _c(e={}){const t=w.useMemo(()=>Tn(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,v]=w.useState(null),[g,y]=w.useState(0),[x,b]=w.useState(!1),C=w.useRef(null),k=w.useRef(!0),T=w.useRef(0),S=w.useRef(null),E=w.useRef(null),A=w.useRef(null),R=w.useRef(null),D=w.useCallback(j=>{o(j)},[]),B=w.useCallback(()=>{p(""),v(null),d(null),E.current=null,A.current=null,R.current=null},[]),q=w.useCallback(()=>{var j;console.debug("[use-chat] stop() invoked - aborting stream"),(j=C.current)==null||j.abort(),C.current=null,S.current=null,l(!1),b(!1),T.current=0,y(0)},[]),V=w.useCallback((j,_,N)=>{C.current&&(C.current.abort(),C.current=null),l(!0),d(null),e.autoAppendAssistant!==!1&&p(""),v(null),E.current=null,A.current=null,R.current=null;const z=new AbortController;C.current=z;let $=null,P=null,H=!1;return S.current={threadId:j.threadId??null,headers:{}},(async()=>{var M,Y,ae,ne,ce,G,O,W,F,ee,Z,ye,fe,oe,xe,Se,$e,_e;const Q=We=>{var Be;try{const qe=JSON.parse(JSON.stringify(We));return(Be=qe==null?void 0:qe.payload)!=null&&Be.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 We}};try{let We={};try{if(r)We={Authorization:`Bearer ${r}`};else if(typeof window<"u"){const ke=window.__AUTH_TOKEN__,st=((M=window.localStorage)==null?void 0:M.getItem("authToken"))||null;let wt=null;try{const Dt=(Y=window.localStorage)==null?void 0:Y.getItem("chat-settings");Dt&&(wt=((ae=JSON.parse(Dt))==null?void 0:ae.apiKey)||null)}catch{}const Qe=ke||st||wt||null;Qe&&(We={Authorization:`Bearer ${Qe}`})}}catch{}console.debug("[use-chat] POST",t+n,Q(j));let Be={};if(typeof window<"u")try{const le=(ne=window.localStorage)==null?void 0:ne.getItem("authSessionId");le&&(Be={"X-Session-Id":le})}catch{}const qe={...We,...Be,...s.current},Ge={"Content-Type":"application/json",Accept:"text/event-stream",...qe},Ze=await fetch(t+n,{method:"POST",headers:Ge,body:JSON.stringify(j),signal:z.signal,credentials:i});if(S.current&&(S.current.headers=qe),!Ze.ok||!Ze.body){const le=await Ze.text().catch(()=>"");console.debug("[use-chat] non-OK response",Ze.status,le==null?void 0:le.slice(0,500));const ke=`stream ${Ze.status}${le?": "+le:""}`;throw(ce=N==null?void 0:N.onConnectionError)==null||ce.call(N,ke),H=!0,$="error",P=ke,new Error(ke)}b(!0);const ot=Ze.body.getReader(),Ct=new TextDecoder;let lt="",ht=[];T.current=0,y(0);let dt=0,gt=null;const kt=()=>{if(ht.length){const le=ht.join("");ht=[],k.current&&p(ke=>ke+le)}gt=null},At=()=>{typeof window<"u"&>==null&&(gt=requestAnimationFrame(kt))};let qt=Date.now();const Ue=setInterval(()=>{var le;if(Date.now()-qt>18e5){const ke="Stream idle timeout";d(ke),$="error",P=ke,z.abort(),(le=N==null?void 0:N.onError)==null||le.call(N,ke)}},5e3),K=1024*1024;try{const le=Ze.headers.get("X-Thread-Id")||Ze.headers.get("x-thread-id"),ke=Ze.headers.get("X-Thread-Created")||Ze.headers.get("x-thread-created"),st=le??null,wt=String(ke??"").toLowerCase()==="true";for(S.current&&!S.current.threadId&&(S.current={...S.current,threadId:st}),(G=N==null?void 0:N.onOpen)==null||G.call(N,{threadId:st,created:wt});;){const{value:Qe,done:Dt}=await ot.read();if(Dt)break;lt+=Ct.decode(Qe,{stream:!0}),lt.length>K&&(lt="",console.warn("Stream buffer reset: exceeded 1MB"));let X;for(;(X=lt.indexOf(`
|
|
34
|
+
`):" "+Zl(i[0]):"as no adapter specified";throw new Me("There is no suitable adapter to dispatch the request "+a,"ERR_NOT_SUPPORT")}return o},adapters:gi};function xi(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new dr(null,e)}function ec(e){return xi(e),e.headers=Ut.from(e.headers),e.data=mi.call(e,e.transformRequest),["post","put","patch"].indexOf(e.method)!==-1&&e.headers.setContentType("application/x-www-form-urlencoded",!1),Ql.getAdapter(e.adapter||Dr.adapter,e)(e).then(function(r){return xi(e),r.data=mi.call(e,e.transformResponse,r),r.headers=Ut.from(r.headers),r},function(r){return Fl(r)||(xi(e),r&&r.response&&(r.response.data=mi.call(e,e.transformResponse,r.response),r.response.headers=Ut.from(r.response.headers))),Promise.reject(r)})}const tc="1.12.2",jo={};["object","boolean","number","function","string","symbol"].forEach((e,t)=>{jo[e]=function(r){return typeof r===e||"a"+(t<1?"n ":" ")+e}});const nc={};jo.transitional=function(t,n,r){function o(s,i){return"[Axios v"+tc+"] Transitional option '"+s+"'"+i+(r?". "+r:"")}return(s,i,a)=>{if(t===!1)throw new Me(o(i," has been removed"+(n?" in "+n:"")),Me.ERR_DEPRECATED);return n&&!nc[i]&&(nc[i]=!0,console.warn(o(i," has been deprecated since v"+n+" and will be removed in the near future"))),t?t(s,i,a):!0}},jo.spelling=function(t){return(n,r)=>(console.warn(`${r} is likely a misspelling of ${t}`),!0)};function Zg(e,t,n){if(typeof e!="object")throw new Me("options must be an object",Me.ERR_BAD_OPTION_VALUE);const r=Object.keys(e);let o=r.length;for(;o-- >0;){const s=r[o],i=t[s];if(i){const a=e[s],l=a===void 0||i(a,s,e);if(l!==!0)throw new Me("option "+s+" must be "+l,Me.ERR_BAD_OPTION_VALUE);continue}if(n!==!0)throw new Me("Unknown option "+s,Me.ERR_BAD_OPTION)}}const _o={assertOptions:Zg,validators:jo},hn=_o.validators;let qn=class{constructor(t){this.defaults=t||{},this.interceptors={request:new Ol,response:new Ol}}async request(t,n){try{return await this._request(t,n)}catch(r){if(r instanceof Error){let o={};Error.captureStackTrace?Error.captureStackTrace(o):o=new Error;const s=o.stack?o.stack.replace(/^.+\n/,""):"";try{r.stack?s&&!String(r.stack).endsWith(s.replace(/^.+\n.+\n/,""))&&(r.stack+=`
|
|
35
|
+
`+s):r.stack=s}catch{}}throw r}}_request(t,n){typeof t=="string"?(n=n||{},n.url=t):n=t||{},n=Kn(this.defaults,n);const{transitional:r,paramsSerializer:o,headers:s}=n;r!==void 0&&_o.assertOptions(r,{silentJSONParsing:hn.transitional(hn.boolean),forcedJSONParsing:hn.transitional(hn.boolean),clarifyTimeoutError:hn.transitional(hn.boolean)},!1),o!=null&&(F.isFunction(o)?n.paramsSerializer={serialize:o}:_o.assertOptions(o,{encode:hn.function,serialize:hn.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),_o.assertOptions(n,{baseUrl:hn.spelling("baseURL"),withXsrfToken:hn.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let i=s&&F.merge(s.common,s[n.method]);s&&F.forEach(["delete","get","head","post","put","patch","common"],v=>{delete s[v]}),n.headers=Ut.concat(i,s);const a=[];let l=!0;this.interceptors.request.forEach(function(g){typeof g.runWhen=="function"&&g.runWhen(n)===!1||(l=l&&g.synchronous,a.unshift(g.fulfilled,g.rejected))});const c=[];this.interceptors.response.forEach(function(g){c.push(g.fulfilled,g.rejected)});let d,f=0,h;if(!l){const v=[ec.bind(this),void 0];for(v.unshift(...a),v.push(...c),h=v.length,d=Promise.resolve(n);f<h;)d=d.then(v[f++],v[f++]);return d}h=a.length;let p=n;for(;f<h;){const v=a[f++],g=a[f++];try{p=v(p)}catch(y){g.call(this,y);break}}try{d=ec.call(this,p)}catch(v){return Promise.reject(v)}for(f=0,h=c.length;f<h;)d=d.then(c[f++],c[f++]);return d}getUri(t){t=Kn(this.defaults,t);const n=Hl(t.baseURL,t.url,t.allowAbsoluteUrls);return Pl(n,t.params,t.paramsSerializer)}};F.forEach(["delete","get","head","options"],function(t){qn.prototype[t]=function(n,r){return this.request(Kn(r||{},{method:t,url:n,data:(r||{}).data}))}}),F.forEach(["post","put","patch"],function(t){function n(r){return function(s,i,a){return this.request(Kn(a||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:s,data:i}))}}qn.prototype[t]=n(),qn.prototype[t+"Form"]=n(!0)});let Qg=class Am{constructor(t){if(typeof t!="function")throw new TypeError("executor must be a function.");let n;this.promise=new Promise(function(s){n=s});const r=this;this.promise.then(o=>{if(!r._listeners)return;let s=r._listeners.length;for(;s-- >0;)r._listeners[s](o);r._listeners=null}),this.promise.then=o=>{let s;const i=new Promise(a=>{r.subscribe(a),s=a}).then(o);return i.cancel=function(){r.unsubscribe(s)},i},t(function(s,i,a){r.reason||(r.reason=new dr(s,i,a),n(r.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(t){if(this.reason){t(this.reason);return}this._listeners?this._listeners.push(t):this._listeners=[t]}unsubscribe(t){if(!this._listeners)return;const n=this._listeners.indexOf(t);n!==-1&&this._listeners.splice(n,1)}toAbortSignal(){const t=new AbortController,n=r=>{t.abort(r)};return this.subscribe(n),t.signal.unsubscribe=()=>this.unsubscribe(n),t.signal}static source(){let t;return{token:new Am(function(o){t=o}),cancel:t}}};function ex(e){return function(n){return e.apply(null,n)}}function tx(e){return F.isObject(e)&&e.isAxiosError===!0}const yi={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(yi).forEach(([e,t])=>{yi[t]=e});function rc(e){const t=new qn(e),n=vl(qn.prototype.request,t);return F.extend(n,qn.prototype,t,{allOwnKeys:!0}),F.extend(n,t,null,{allOwnKeys:!0}),n.create=function(o){return rc(Kn(e,o))},n}const vt=rc(Dr);vt.Axios=qn,vt.CanceledError=dr,vt.CancelToken=Qg,vt.isCancel=Fl,vt.VERSION=tc,vt.toFormData=Eo,vt.AxiosError=Me,vt.Cancel=vt.CanceledError,vt.all=function(t){return Promise.all(t)},vt.spread=ex,vt.isAxiosError=tx,vt.mergeConfig=Kn,vt.AxiosHeaders=Ut,vt.formToJSON=e=>Ll(F.isHTMLForm(e)?new FormData(e):e),vt.getAdapter=Ql.getAdapter,vt.HttpStatusCode=yi,vt.default=vt;const{Axios:rE,AxiosError:oE,CanceledError:sE,isCancel:iE,CancelToken:aE,VERSION:lE,all:cE,Cancel:uE,isAxiosError:dE,spread:fE,toFormData:hE,AxiosHeaders:pE,HttpStatusCode:mE,formToJSON:gE,getAdapter:xE,mergeConfig:yE}=vt,oc=typeof window<"u"?window.__API_BASE_URL__:void 0,sc=oc?Cn(oc):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 Mo=null;const vi=new Set;function ic(){return Mo}function Ro(e){Mo=e,vi.forEach(t=>t(e))}function ac(e){return vi.add(e),()=>vi.delete(e)}const nx=3e4,rx=9e4,Ht=vt.create({...sc?{baseURL:sc}:{},timeout:nx,withCredentials:!0});Ht.interceptors.request.use(e=>(Mo&&(e.headers.Authorization=`Bearer ${Mo}`),e)),Ht.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),Ro(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 Wt(e,t){return Ht.defaults.baseURL?(await Ht.get(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}async function Po(e,t,n){return Ht.defaults.baseURL?(await Ht.post(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function lc(e,t,n){return Ht.defaults.baseURL?(await Ht.put(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function bi(e,t){return Ht.defaults.baseURL?(await Ht.delete(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}function Rt(e){return e&&typeof e=="object"&&"data"in e?e.data:e}class cc{get baseUrl(){const t=Ht.defaults.baseURL;return t?Cn(String(t)):""}updateConfig(t){t.baseUrl&&(Ht.defaults.baseURL=Cn(String(t.baseUrl))),t.authToken!==void 0&&Ro(t.authToken)}getAuthToken(){return ic()}setAuthToken(t){Ro(t)}onTokenChange(t){return ac(t)}async listThreads(){const t=await Wt("/threads"),n=Rt(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async listSharedThreads(){const t=await Wt("/threads/shared"),n=Rt(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async listSmartOrgUsers(){const t=Ht.defaults.baseURL?Ht.defaults.baseURL.replace(/\/chat\/?$/,""):"/api",n=await Wt("/auth/users",{baseURL:t}),r=Rt(n);return(r==null?void 0:r.users)??[]}async createThread(t){const r=await Po("/threads",t?{title:t}:void 0);return Rt(r)}async updateThread(t,n){const r=await lc(`/threads/${t}`,{title:n});return Rt(r)}async deleteThread(t){const n=await bi(`/threads/${t}`);return Rt(n)}async shareThread(t,n){const r=await Po(`/threads/${t}/share`,{shared_with_user_id:n});return Rt(r)}async threadInfo(t){const n=await Wt(`/threads/${t}/info`);return Rt(n)}async listAgents(){const t=await Wt("/agents"),n=Rt(t);return(n==null?void 0:n.items)??[]}async getAgent(t){const n=await Wt(`/agents/${t}`);return Rt(n)}async getAgentSchema(t){const n=await Wt(`/agents/${t}/schema`);return Rt(n)}async getState(t){const n=await Wt(`/threads/${t.threadId}/state`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return Rt(n)}async getStateHistory(t){const n=await Wt(`/threads/${t.threadId}/state/history`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs},timeout:rx});return Rt(n)}async cancelRun(t){const n=await Po("/runs/cancel",{threadId:t});return Rt(n)}async listCheckpointSummaries(t){const n=await Wt(`/threads/${t}/state/checkpoints`,{params:{thread_id:t}}),r=Rt(n);return(r==null?void 0:r.items)??[]}async unshareThread(t,n){const r=await bi(`/threads/${t}/share/${n}`);return Rt(r)}}const Nn=new cc,uc=w.createContext(null);function ox({children:e,apiConfig:t}){const n=Nn;if(t){const o=n.baseUrl,s=n.getAuthToken();t.baseUrl&&t.baseUrl!==o&&n.updateConfig({baseUrl:t.baseUrl}),t.apiKey!==void 0&&t.apiKey!==s&&n.updateConfig({authToken:t.apiKey})}const r={token:n.getAuthToken(),setToken:o=>n.setAuthToken(o),api:n,baseUrl:n.baseUrl};return u.jsx(uc.Provider,{value:r,children:e})}function wi(){const e=w.useContext(uc);if(!e)throw new Error("useApi must be used within ApiProvider");return e}async function sx(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 ix(e,t=[],n,r,o,s){const i=[],a=[];for(const l of t)try{const c=await sx(l);a.push({filename:l.name,data:c,mime_type:l.type||"application/octet-stream"})}catch{}return{contentParts:i,filesInfo:a}}const dc=120;function ax(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>dc?`${n.slice(0,dc-3)}…`:n:""}function fc(e){return ax(e.content)||""}function lx(e){const t=new Map;for(const n of e){if(!n.id||n.role!=="user")continue;const r=fc(n);r&&t.set(n.id,r)}return t}function cx(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=fc(o);s&&t.set(r.checkpointId,s)}}return t}const ux={human:"user",user:"user",ai:"assistant",assistant:"assistant",tool:"tool",function:"tool",system:"system"};function Si(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 dx(e,t){return`${e??""}::${t??""}`}function fr(e){const t=Array.isArray(e==null?void 0:e.checkpoints)?(e==null?void 0:e.checkpoints)??[]:e!=null&&e.checkpoints?Object.values(e.checkpoints):[],n=(e==null?void 0:e.threadId)??"",r=t[0];if(!Si(r))return{threadId:n,latest:null,checkpoints:[],timeline:[],interrupt:null,snapshots:{}};const{orderedSnapshots:o,snapshotMap:s}=hx(t),i=hc(r,0),a=px(o);return{threadId:n,latest:i,checkpoints:o,timeline:a,interrupt:(i==null?void 0:i.interrupt)??null,snapshots:s}}function hc(e,t){if(!Si(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(R=>!!R&&typeof R=="object").map(R=>({...R})):a===null?null:void 0,c=r.map((R,O)=>Cx(R,O)).filter(R=>!!R),d=Lt(e.config),f=Lt(d==null?void 0:d.configurable),h=ft(f,["checkpoint_id","checkpointId"]),p=ft(f,["checkpoint_ns","checkpointNs"]),v=Lt(e==null?void 0:e.parentConfig),g=Lt(v==null?void 0:v.configurable),y=ft(g,["checkpoint_id","checkpointId"])??null,x=ft(g,["checkpoint_ns","checkpointNs"])??null,b=e==null?void 0:e.createdAt,C=typeof b=="string"&&b.trim()?b:new Date(Date.now()-t).toISOString(),k=c.slice().reverse().find(R=>R.role==="user")??null,S=Lt(e==null?void 0:e.metadata),T=ft(S,["branch_label","branchLabel"]),E=ft(g,["checkpoint_id","checkpointId"]),j=Array.isArray(e.next)?[...e.next]:(e==null?void 0:e.next)===null?null:void 0;return{messages:c,checkpointId:h??null,checkpointNs:p??null,nextCursor:y,nextCursorNs:x,interrupt:fx(a,c,t),createdAt:C,parentId:E??null,branchLabel:T??null,lastUserMessageId:(k==null?void 0:k.id)??null,hasMessages:c.length>0,messagesLen:c.length,metadata:S??null,config:d??null,parentConfig:v??null,next:j??null,tasks:l??null,values:i??null}}function fx(e,t,n){const r=wx(e,n);return r||bx(t,n)}function hx(e){const t=new Map;e.forEach((o,s)=>{if(!Si(o))return;const i=hc(o,s);if(!(i!=null&&i.checkpointId))return;const a=dx(i.checkpointId,i.checkpointNs??null),l=t.get(a);if(!l){t.set(a,i);return}t.set(a,xx(l,i))});const n=Array.from(t.values());n.sort((o,s)=>mc(s.createdAt??"")-mc(o.createdAt??""));const r={};for(const[o,s]of t.entries())r[o]=s;return{orderedSnapshots:n,snapshotMap:r}}function px(e){var n,r;const t=[];for(const o of e){const s=o.checkpointId??null;if(!s)continue;const i=o.metadata??{},a=ft(i,["label"])??ft(i,["branch_label","branchLabel"])??ft(i,["description"])??"User input",l=gx(i,["step"]),c=ft(i,["source"]),d=o.createdAt??null,f=((r=(n=o.messages)==null?void 0:n[o.messages.length-1])==null?void 0:r.id)??null,h=o.lastUserMessageId??f,p=mx(o.next);t.push({id:s,label:a,messageId:h,step:l,source:c??null,createdAt:d,next:p??void 0,parentConfig:o.parentConfig??null})}return t}function mx(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 gx(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 xx(e,t){return{...e,metadata:Oo(e.metadata,t.metadata)??null,config:Oo(e.config,t.config)??null,parentConfig:Oo(e.parentConfig,t.parentConfig)??null,next:yx(e.next,t.next)??null,tasks:vx(e.tasks,t.tasks)??null,values:Oo(e.values,t.values)??null}}function Oo(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 yx(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 vx(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 bx(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 wx(e,t){if(!Array.isArray(e)||!e.length)return null;for(let n=e.length-1;n>=0;n--){const r=Sx(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=$r(r.interrupts[s],`${o}-interrupt-${s}`);if(i)return i}if(r.state!==void 0&&r.state!==null){const s=$r(r.state,`${o}-state`);if(s)return s}}return null}function Sx(e,t){if(!e)return null;if(Array.isArray(e)){const[a,l,c,,d,,f,...h]=e,p=typeof a=="string"&&a.trim()?a:t,v=typeof l=="string"&&l.trim()?l:Array.isArray(c)&&typeof c[0]=="string"?String(c[0]):"task",g=Array.isArray(d)?d:void 0,y=h.length?h[h.length-1]:void 0;return{id:p,name:v,interrupts:g,state:y!==void 0?y:f}}const n=Lt(e);if(!n)return null;const r=ft(n,["id","thread_id","taskId"])??t,o=ft(n,["name"])??"task",s=Array.isArray(n.interrupts)?n.interrupts:void 0,i=Object.prototype.hasOwnProperty.call(n,"state")?n.state:void 0;return{id:r,name:o,interrupts:s,state:i}}function $r(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=pc(e,t);if(o)return o;if(Array.isArray(e)){for(let s=e.length-1;s>=0;s--){const i=$r(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=$r(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=$r(l,t,n+1,r);if(c)return c}}return null}function pc(e,t){if(!e)return null;if(typeof e=="object"&&!Array.isArray(e)){const n=e,r=ft(n,["type","event","kind"]),o=ft(n,["id","interrupt_id","interruptId","value_id"])??(r&&r.toLowerCase().includes("interrupt")?t:void 0);if(!(Object.prototype.hasOwnProperty.call(n,"value")||Object.prototype.hasOwnProperty.call(n,"data")||Object.prototype.hasOwnProperty.call(n,"payload"))&&!(r&&r.toLowerCase().includes("interrupt")))return null;const i=Object.prototype.hasOwnProperty.call(n,"value")?n.value:Object.prototype.hasOwnProperty.call(n,"data")?n.data:Object.prototype.hasOwnProperty.call(n,"payload")?n.payload:n,a=o&&o.trim()?o:t;return a?{id:a,value:i}:null}if(Array.isArray(e)){for(let n=e.length-1;n>=0;n--){const r=pc(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 mc(e){if(!e)return 0;const t=Date.parse(e);return Number.isFinite(t)?t:0}function Cx(e,t){if(!e||typeof e!="object")return null;const n=e,r=Lt(e)??{},o=Lt(n.data)??r,s=String(n.type??o.type??o.role??"").toLowerCase(),i=ux[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=Lt(o.additional_kwargs)??Lt(o.additionalKwargs),d=Lt(o.response_metadata)??Lt(o.responseMetadata),f=ft(c,["createdAt","created_at"])??ft(o,["created_at","createdAt"]),h=ft(c,["checkpointId","checkpoint_id"]),p=ft(c,["checkpointNs","checkpoint_ns"]),v=Tx(o.content),g={id:l,role:i,content:v};f&&(g.createdAt=f),typeof o.name=="string"&&o.name.trim()&&(g.name=o.name),typeof(d==null?void 0:d.model_name)=="string"&&(g.model=String(d.model_name)),!g.model&&typeof o.model=="string"&&(g.model=o.model),h&&(g.checkpointId=h),p&&(g.checkpointNs=p);const y=Ix(Lt(o.artifact??r.artifact??o.artifacts??r.artifacts));y&&(g.artifact=y);const x=_x(c,["createdAt","created_at","checkpointId","checkpoint_id","checkpointNs","checkpoint_ns","tool_calls"]),b=d?{...d}:void 0;x&&Object.keys(x).length&&(g.additionalKwargs=x),b&&Object.keys(b).length&&(g.responseMetadata=b);const C=kx((c==null?void 0:c.tool_calls)??o.tool_calls);if(C.length&&(g.content=[...g.content,...C]),i==="tool"){const k=Ex(o,g.content);k&&(g.content=k)}return g}function Tx(e){if(!e)return[];if(Array.isArray(e))return e.map(t=>gc(t)).filter(t=>!!t);if(typeof e=="string")return e.trim()?[{type:"text",text:e.trim()}]:[];if(typeof e=="object"){const t=gc(e);return t?[t]:[]}return[]}function gc(e){if(!e||typeof e!="object")return typeof e=="string"&&e.trim()?{type:"text",text:e}:null;const t=e,n=String(t.type??"").toLowerCase();if(!n||n==="text"){const o=typeof t.text=="string"?t.text:typeof t.value=="string"?t.value:"";return o.trim()?{type:"text",text:o}:null}if(n==="image"||n==="image_url"){const o=ft(t,["url","src"]);if(!o)return null;const s={type:"image_url",url:o};return typeof t.mimeType=="string"&&(s.mimeType=t.mimeType),typeof t.alt=="string"&&(s.alt=t.alt),s}if(n==="file"){const o=ft(t,["url"]);if(!o)return null;const s={type:"file",url:o};return typeof t.mimeType=="string"&&(s.mimeType=t.mimeType),typeof t.name=="string"&&(s.name=t.name),typeof t.size=="number"&&(s.size=t.size),typeof t.sourceType=="string"&&(s.sourceType=t.sourceType),s}if(n==="tool_call")return xc(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=ft(t,["text","content"]);if(o)return{type:"text",text:o}}const r=typeof t.content=="string"?t.content:typeof t.value=="string"?t.value:JSON.stringify(t);return r?{type:"text",text:r}:null}function xc(e,t){var s;const n=ft(e,["id","call_id"])??t,r=ft(e,["name"])??ft(Lt(e.function),["name"]);if(!n||!r)return null;const o=jx(e.args??e.arguments??((s=Lt(e.function))==null?void 0:s.arguments));return{type:"tool_call",id:n,name:r,args:o}}function kx(e){return Array.isArray(e)?e.map((t,n)=>xc(t,`tool_call_${n}`)).filter(t=>!!t):[]}function Ex(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 Ix(e){return e?{plots:Nx(e.plots)}:void 0}function Nx(e){return Array.isArray(e)?e.map(t=>Ax(t)).filter(t=>!!t):[]}function Ax(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 jx(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 Lt(e){if(!(!e||typeof e!="object"||Array.isArray(e)))return{...e}}function ft(e,t){if(e)for(const n of t){const r=e[n];if(typeof r=="string"&&r.trim())return r}}function _x(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 yc="aiNav:tool-progress";function Ci(){return typeof window<"u"&&typeof window.localStorage<"u"}function vc(e){return`${yc}:${e}`}function Mx(e,t,n){if(!Ci()||!e)return;const r=vc(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 Rx(e){if(!Ci()||!e)return;const t=vc(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 bc(){if(!Ci())return;const e=[];for(let t=0;t<window.localStorage.length;t+=1){const n=window.localStorage.key(t);n!=null&&n.startsWith(yc)&&e.push(n)}for(const t of e)window.localStorage.removeItem(t)}const Et=[];for(let e=0;e<256;++e)Et.push((e+256).toString(16).slice(1));function Px(e,t=0){return(Et[e[t+0]]+Et[e[t+1]]+Et[e[t+2]]+Et[e[t+3]]+"-"+Et[e[t+4]]+Et[e[t+5]]+"-"+Et[e[t+6]]+Et[e[t+7]]+"-"+Et[e[t+8]]+Et[e[t+9]]+"-"+Et[e[t+10]]+Et[e[t+11]]+Et[e[t+12]]+Et[e[t+13]]+Et[e[t+14]]+Et[e[t+15]]).toLowerCase()}let Ti;const Ox=new Uint8Array(16);function Dx(){if(!Ti){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Ti=crypto.getRandomValues.bind(crypto)}return Ti(Ox)}const wc={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function Lx(e,t,n){var o;e=e||{};const r=e.random??((o=e.rng)==null?void 0:o.call(e))??Dx();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,Px(r)}function $x(e,t,n){return wc.randomUUID&&!e?wc.randomUUID():Lx(e)}function ki(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 Do(e,t,n){return t<0||t>=e.length?e:[...e.slice(0,t),n,...e.slice(t+1)]}function Sc(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 Cc(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 Fx(e,t){const n=new Set;for(const o of t)typeof o=="string"&&o.trim()&&n.add(o.trim());const r=Kx(e);for(const o of r)n.add(o);return Array.from(n)}function kc(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 Bx(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 Lo(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:$x(),idx:a.length+1,timestamp:new Date().toISOString(),...n};return a.push(l),Mx(o.id,a,{checkpointId:o.checkpointId??null,checkpointNs:o.checkpointNs??null}),i.toolProgress=a,s[r]={...o,additionalKwargs:i},s}function Ec(e,t){return e.includes(t)?e:[...e,t]}function zx(e,t){const n=[...e],r=n.lastIndexOf(t);return r!==-1&&n.splice(r,1),n}function hr(e,t){let n=!1;const r={},o=e.map(s=>{const i=qx(s);if(i.length)return r[s.id]=i,s;const a=t[s.id]??Rx(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 Ux(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=Hx(a,s);if(f===""?l="":f===s?l=s:l=f,l){const h=c[c.length-1];if((h==null?void 0:h.type)==="text"){const p=h.text??"",v={...h,text:p+l};c=[...c.slice(0,c.length-1),v]}else c=[...c,{type:"text",text:l}];o.lastText=a+l}else o.lastText=a}i.length&&(c=[...c,...i]);const d=!!(l||i.length);return{newParts:c,newMeta:o,changed:d}}function Nc(e){return e.replace(/\s+/g," ").trim()}function Hx(e,t){if(!t)return"";if(!e)return t;if(e===t)return"";const n=Math.min(e.length,t.length);for(let i=n;i>0;i--)if(e.slice(-i)===t.slice(0,i))return t.slice(i);const r=Nc(e),o=Nc(t);if(r===o)return"";const s=Math.min(r.length,o.length);for(let i=s;i>0;i--)if(r.slice(-i)===o.slice(0,i))return t;return t}function Wx(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 Do(e,r,s)}return e}function Vx(e){if(!e)return null;const t=e.split("/");return t[t.length-1]||null}function Kx(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 qx(e){const t=e.additionalKwargs??{};return Array.isArray(t.toolProgress)?[...t.toolProgress]:[]}const Gx={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},toolStreamingMessageId:null,toolStreamingStack:[],messagesStreamMeta:{},pendingInterrupt:null,toolTimelines:{}};function Yx(e,t){var n;switch(t.type){case"reset":return{messages:ki(((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=ki(t.payload.messages),{messages:o,toolTimelines:s}=hr(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=ki(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}=hr(i,e.toolTimelines);return{...e,messages:a,toolTimelines:l}}case"event":return jc(e,t.payload.ev);case"batch":{const{events:r}=t.payload;return r.length?r.reduce((o,s)=>jc(o,s),e):e}case"interrupt_response":return{...e,messages:Sc(e.messages),pendingInterrupt:null};default:return e}}function Ac(e=[]){const[t,n]=w.useReducer(Yx,{...Gx,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 jc(e,t){var n,r,o,s;if(t.type==="message.start"&&t.role==="assistant"){const i=t.id,a=Vx(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??Cc(e.messages);if(!i)return e;const a=e.messages,l=a.findIndex(C=>C.id===i&&C.role==="assistant");if(l===-1)return e;const c=a[l],d=e.messagesStreamMeta??{},f=d[i]??{lastSeq:null,lastText:Ic(c.content)},h=t.seq??null;if(h!==null&&typeof h=="number"&&typeof f.lastSeq=="number"&&h<=f.lastSeq)return console.debug("[MessageReducer] skipping delta - seq <= lastSeq",{seq:h,lastSeq:f.lastSeq}),e;const{newParts:p,newMeta:v,changed:g}=Ux(c.content,t.delta,f,h);if(!g)return e;const y={...c,content:p},x=Do(a,l,y),b={...d,[i]:v};return{...e,messages:x,messagesStreamMeta:b}}if(t.type==="message.end"){const i=e.assemblingId??Cc(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 h;return(f==null?void 0:f.type)==="text"&&((h=f.text)==null?void 0:h.trim())}))){console.debug("[MessageReducer] pruning assistant message with no visible text",{id:c.id,contentTypes:(r=c.content)==null?void 0:r.map(h=>h==null?void 0:h.type),contentPreview:(o=c.content)==null?void 0:o.map(h=>(h==null?void 0:h.type)==="text"?String(h.text).slice(0,100):h==null?void 0:h.type)});const f=[...a.slice(0,l),...a.slice(l+1)];return{...e,assemblingId:null,messages:f}}}return e}if(t.type==="tool.start"){const i=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},h={type:e.toolStreamingMessageId?"tool.call":"tool.start",toolId:a??d,toolName:l,metadata:{args:t.args}},p=e.toolStreamingMessageId;if(!p){const b={id:`tool-${d}`,role:"tool",name:l,createdAt:new Date().toISOString(),content:[f],additionalKwargs:{...Bx(void 0,c.length?c:[d],l,t.args),toolStreaming:!0}},C=Fx(b,c.length?c:[d]),k=[...e.messages,b],S=Lo(k,b.id,h),{messages:T,toolTimelines:E}=hr(S,e.toolTimelines);return{...e,messages:T,toolIndex:kc(e.toolIndex,b.id,C),toolStreamingMessageId:b.id,toolStreamingStack:Ec(e.toolStreamingStack??[],a??d),toolTimelines:E}}const v=Lo(e.messages,p,h),{messages:g,toolTimelines:y}=hr(v,e.toolTimelines);return{...e,messages:g,toolIndex:kc(e.toolIndex,p,c),toolStreamingStack:Ec(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=zx(l,a),f=d[0]?e.toolIndex[d[0]]:null,h=e.toolStreamingMessageId,p=c===a,v=t.name??((s=e.messages.find(S=>S.id===h))==null?void 0:s.name)??"tool",g=typeof t.output=="string"?t.output.trim():JSON.stringify(t.output??""),y={type:"tool.end",toolId:a,toolName:v,content:g==null?void 0:g.slice(0,200)};let x=e.messages;if(h&&(x=Lo(x,h,y)),p&&h){const S=x.findIndex(T=>T.id===h);if(S>=0){const T=x[S],j={type:"text",text:(()=>{if(typeof t.output=="string"){const O=t.output.trim();try{return O}catch{return O}}return JSON.stringify(t.output??"")})()},R={...T,content:[j],artifact:t.artifact??T.artifact,additionalKwargs:{...T.additionalKwargs??{}}};x=Do(x,S,R)}}const b=d,{messages:C,toolTimelines:k}=hr(x,e.toolTimelines);return{...e,messages:C,toolTimelines:k,toolStreamingMessageId:p?f:h,toolStreamingStack:b}}if(t.type==="tool.progress"){const i=e.toolStreamingMessageId;if(!i)return e;const a={type:"tool.progress",content:t.content??null},l=Lo(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},h={...d,additionalKwargs:f},p=Do(l,c,h),{messages:v,toolTimelines:g}=hr(p,e.toolTimelines);return{...e,messages:v,toolTimelines:g}}if(t.type==="checkpoint"){const i=t.checkpointNs??e.lastCheckpointNs??null,a=Wx(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=fr(t),a=i.interrupt,l=i.latest,c=a===null?Sc(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 _c(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,h]=w.useState(""),[p,v]=w.useState(null),[g,y]=w.useState(0),[x,b]=w.useState(!1),C=w.useRef(null),k=w.useRef(!0),S=w.useRef(0),T=w.useRef(null),E=w.useRef(null),j=w.useRef(null),R=w.useRef(null),O=w.useCallback(P=>{o(P)},[]),B=w.useCallback(()=>{h(""),v(null),d(null),E.current=null,j.current=null,R.current=null},[]),q=w.useCallback(()=>{var P;console.debug("[use-chat] stop() invoked - aborting stream"),(P=C.current)==null||P.abort(),C.current=null,T.current=null,l(!1),b(!1),S.current=0,y(0)},[]),K=w.useCallback((P,M,I)=>{C.current&&(C.current.abort(),C.current=null),l(!0),d(null),e.autoAppendAssistant!==!1&&h(""),v(null),E.current=null,j.current=null,R.current=null;const z=new AbortController;C.current=z;let L=null,A=null,$=!1;return T.current={threadId:P.threadId??null,headers:{}},(async()=>{var _,G,re,ee,ie,Y,D,V,U,Z,J,ge,ce,ne,pe,be,De,je;const H=He=>{var qe;try{const rt=JSON.parse(JSON.stringify(He));return(qe=rt==null?void 0:rt.payload)!=null&&qe.files_info&&Array.isArray(rt.payload.files_info)&&(rt.payload.files_info=rt.payload.files_info.map(Ge=>({...Ge,data:Ge!=null&&Ge.data?`<base64 ${String(Ge.data).length} chars>`:Ge==null?void 0:Ge.data}))),rt}catch{return He}};try{let He={};try{if(r)He={Authorization:`Bearer ${r}`};else if(typeof window<"u"){const le=window.__AUTH_TOKEN__,Pe=((_=window.localStorage)==null?void 0:_.getItem("authToken"))||null;let wt=null;try{const Tt=(G=window.localStorage)==null?void 0:G.getItem("chat-settings");Tt&&(wt=((re=JSON.parse(Tt))==null?void 0:re.apiKey)||null)}catch{}const We=le||Pe||wt||null;We&&(He={Authorization:`Bearer ${We}`})}}catch{}console.debug("[use-chat] POST",t+n,H(P));let qe={};if(typeof window<"u")try{const W=(ee=window.localStorage)==null?void 0:ee.getItem("authSessionId");W&&(qe={"X-Session-Id":W})}catch{}const rt={...He,...qe,...s.current},Ge={"Content-Type":"application/json",Accept:"text/event-stream",...rt},Qe=await fetch(t+n,{method:"POST",headers:Ge,body:JSON.stringify(P),signal:z.signal,credentials:i});if(T.current&&(T.current.headers=rt),!Qe.ok||!Qe.body){const W=await Qe.text().catch(()=>"");console.debug("[use-chat] non-OK response",Qe.status,W==null?void 0:W.slice(0,500));const le=`stream ${Qe.status}${W?": "+W:""}`;throw(ie=I==null?void 0:I.onConnectionError)==null||ie.call(I,le),$=!0,L="error",A=le,new Error(le)}b(!0);const lt=Qe.body.getReader(),Re=new TextDecoder;let Le="",ct=[];S.current=0,y(0);let ot=0,pt=null;const mt=()=>{if(ct.length){const W=ct.join("");ct=[],k.current&&h(le=>le+W)}pt=null},kt=()=>{typeof window<"u"&&pt==null&&(pt=requestAnimationFrame(mt))};let At=Date.now();const Fe=setInterval(()=>{var W;if(Date.now()-At>18e5){const le="Stream idle timeout";d(le),L="error",A=le,z.abort(),(W=I==null?void 0:I.onError)==null||W.call(I,le)}},5e3),fn=1024*1024;try{const W=Qe.headers.get("X-Thread-Id")||Qe.headers.get("x-thread-id"),le=Qe.headers.get("X-Thread-Created")||Qe.headers.get("x-thread-created"),Pe=W??null,wt=String(le??"").toLowerCase()==="true";for(T.current&&!T.current.threadId&&(T.current={...T.current,threadId:Pe}),(Y=I==null?void 0:I.onOpen)==null||Y.call(I,{threadId:Pe,created:wt});;){const{value:We,done:Tt}=await lt.read();if(Tt)break;Le+=Re.decode(We,{stream:!0}),Le.length>fn&&(Le="",console.warn("Stream buffer reset: exceeded 1MB"));let X;for(;(X=Le.indexOf(`
|
|
36
36
|
|
|
37
|
-
`))>=0;){const
|
|
38
|
-
`)}const Zx=["message.start","message.delta","message.end"],Qx=["tool.start","tool.end","tool.progress"],ey=["thread_info","checkpoint"],ty=["error","interrupt","heartbeat","state_history","cancelled"],ny=[...Zx,...Qx,...ey,...ty],ry=new Set(ny);function oy(e){if(typeof e!="object"||e===null||typeof e.type!="string")return!1;const t=e.type;return ry.has(t)}const Mc=200;function sy({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),v=w.useRef(null),g=w.useCallback(_=>{try{const N=globalThis.structuredClone;if(typeof N=="function")return N(_)}catch{}try{return JSON.parse(JSON.stringify(_))}catch{return _}},[]),y=w.useCallback((_,N)=>{if(!_)return;const z=p.current.get(_)??[],$=g(N),P=z.length>=Mc?[...z.slice(z.length-Mc+1),$]:[...z,$];p.current.set(_,P)},[g]),x=w.useCallback(_=>{_&&p.current.set(_,[])},[]),b=w.useCallback(_=>{const N=_??f.current;if(!N)return;const z=p.current.get(N);z!=null&&z.length&&z.forEach($=>{try{n($)}catch(P){console.error("[useChatStreamingService] Failed to replay buffered event",P)}})},[n]),C=w.useCallback(_=>{f.current=_.threadId,h.current&&(h.current.threadIdGuess=_.threadId),v.current=_,x(_.threadId),console.log("[useChatStreamingService] 🎯 Received thread_info event:",_);try{t(_)}catch(N){console.error("[useChatStreamingService] Error in onThreadInfo handler:",N)}},[x,t]),k=w.useCallback(_=>{try{c==null||c(_)}catch(N){console.error("[useChatStreamingService] Error in onHeartbeat handler:",N)}},[c]),T=w.useCallback(_=>{var $,P,H,Q;const N=_;if(N.error_type==="auth_error"||N.code==="TOKEN_EXPIRED"||(($=N.message)==null?void 0:$.includes("token"))||((P=N.message)==null?void 0:P.includes("401"))||((H=N.message)==null?void 0:H.includes("unauthorized"))||((Q=N.message)==null?void 0:Q.includes("Unauthorized"))){console.error("[useChatStreamingService] Auth error event detected:",N.message);try{l==null||l(N.message)}catch(M){console.warn("[useChatStreamingService] onAuthError handler failed",M)}}},[l]),S=w.useMemo(()=>({thread_info:_=>(C(_),!0),heartbeat:_=>(k(_),!0),error:_=>(T(_),!1)}),[C,k,T]),E=w.useCallback(_=>{var P;const N=_.seq??null;if(N!==null){const H=d.current;if(H!==null){if(N<=H)return;N>H+1&&(s==null||s({from:H,to:N}))}d.current=N}const z=S[_.type];if(z&&z(_))return;const $=_.threadId??(_.type==="state_history"?_.threadId:void 0)??f.current??((P=h.current)==null?void 0:P.threadIdGuess)??null;if(_.type==="state_history"){f.current=$??f.current;try{r==null||r(_)}catch(H){console.error("[useChatStreamingService] onStateHistory handler failed",H)}}if(oy(_)){_.type==="checkpoint"||_.type==="state_history"?x($??null):y($??null,_);try{n(_)}catch(H){console.error("[useChatStreamingService] Error in onMessageEvent handler:",H)}return}try{o==null||o(_)}catch(H){console.error("[useChatStreamingService] Error in onUnhandledEvent handler:",H)}},[y,x,n,s,r,o,S]),{stream:A,stop:R,isStreaming:D,error:B,setToken:q}=_c({baseUrl:e,token:void 0}),V=w.useCallback((_,N)=>{d.current=null,v.current=null,f.current=_.threadId??null,h.current={request:_,callbacks:N,manualStop:!1,threadIdGuess:_.threadId??null},A(_,E,{onOpen:N==null?void 0:N.onOpen,onError:z=>{var $;($=N==null?void 0:N.onError)==null||$.call(N,z)},onGap:(N==null?void 0:N.onGap)??s,onConnectionError:z=>{var $;a==null||a(z),($=N==null?void 0:N.onConnectionError)==null||$.call(N,z)},onAuthError:z=>{var $;l==null||l(z),($=N==null?void 0:N.onAuthError)==null||$.call(N,z)},onHeartbeat:z=>{var $;try{c==null||c(z)}catch(P){console.warn("[useChatStreamingService] onHeartbeat handler failed",P)}try{($=N==null?void 0:N.onHeartbeat)==null||$.call(N,z)}catch(P){console.warn("[useChatStreamingService] downstream onHeartbeat handler failed",P)}},onClosed:z=>{var Q,M,Y,ae;const $=((Q=h.current)==null?void 0:Q.manualStop)??!1,P=f.current??((M=h.current)==null?void 0:M.threadIdGuess)??((Y=z.lastStateHistory)==null?void 0:Y.threadId)??null;(z.reason==="complete"||z.reason==="aborted"&&$)&&x(P);const H={...z,threadId:P,threadInfo:v.current,manualStop:$};try{i==null||i(H)}catch(ne){console.warn("[useChatStreamingService] onStreamClosed handler failed",ne)}try{(ae=N==null?void 0:N.onClosed)==null||ae.call(N,H)}catch(ne){console.warn("[useChatStreamingService] downstream onClosed handler failed",ne)}h.current&&(h.current=null)}})},[x,E,l,a,c,s,i,A]),j=w.useCallback(()=>{h.current&&(h.current.manualStop=!0),R()},[R]);return w.useMemo(()=>({startStream:V,stop:j,isStreaming:D,error:B,setAuthToken:q,replayBufferedEvents:b}),[V,j,D,B,q,b])}function iy({api:e,seed:t,prepend:n,onError:r,currentThreadId:o,initialThreadId:s=null,initialCheckpointId:i=null,initialCheckpointNs:a=null,autoLoadInitial:l=!0,isStreaming:c,getMessages:d}){const[f,p]=w.useState([]),[h,v]=w.useState([]),[g,y]=w.useState(!1),[x,b]=w.useState(null),[C,k]=w.useState(!1),[T,S]=w.useState(!1),[E,A]=w.useState(!1),[R,D]=w.useState(null),B=w.useRef(o),q=w.useRef(null),V=w.useRef(null),j=w.useRef(null),_=w.useRef(null),N=w.useRef(!1),z=w.useRef(null),$=w.useRef(new Map);w.useEffect(()=>{B.current=o},[o]);const P=w.useCallback(async F=>{var Z,ye;if(!F.threadId)return;const ee=F.threadId;(Z=F.onStart)==null||Z.call(F),F.setLoading(!0);try{await F.action(ee)}catch(fe){if(B.current===ee){const oe=String(fe);(ye=F.handleError)==null||ye.call(F,oe),r==null||r(oe)}throw fe}finally{F.setLoading(!1)}},[r]),H=w.useCallback(async(F,ee)=>{if(!F)return;const Z=`${F}:${ee??"latest"}`,ye=$.current.get(Z);if(ye)return ye;const fe=P({threadId:F,setLoading:k,onStart:()=>D(null),handleError:oe=>D(oe),action:async oe=>{const xe=await e.getStateHistory({threadId:oe,checkpointId:ee??void 0});if(B.current!==oe){console.log(`[useThreadHistoryState] Thread changed during load (was ${oe}, now ${B.current}), discarding stale data`);return}const{checkpoints:Se,timeline:$e}=gr(xe),_e=Se.find(We=>We.messages&&We.messages.length>0)??(ee?Se.find(We=>We.checkpointId===ee):null)??Se[0];t((_e==null?void 0:_e.messages)??[],{checkpointId:(_e==null?void 0:_e.checkpointId)??null,checkpointNs:(_e==null?void 0:_e.checkpointNs)??null}),v($e),p(Se),y(!!(_e!=null&&_e.nextCursor)),b((_e==null?void 0:_e.nextCursor)??null)}});$.current.set(Z,fe);try{await fe}finally{$.current.delete(Z)}return B.current===F&&(z.current=Z),fe},[e,t,P]),Q=w.useCallback(async(F,ee,Z)=>{Z!=null&&Z.clearProgress&&bc(),_.current=F;try{await H(F,ee)}finally{_.current===F&&(_.current=null)}},[H]),M=w.useCallback(F=>{V.current=F},[]),Y=w.useCallback(F=>{j.current=F},[]),ae=w.useCallback(F=>{const ee=F.threadId??B.current;if(!ee||B.current&&B.current!==ee)return;const{checkpoints:Z,timeline:ye}=gr(F);if(!Z.length)return;const fe=Z.find(oe=>oe.messages&&oe.messages.length>0)??Z.find(oe=>!!oe.checkpointId)??Z[0];t((fe==null?void 0:fe.messages)??[],{checkpointId:(fe==null?void 0:fe.checkpointId)??null,checkpointNs:(fe==null?void 0:fe.checkpointNs)??null}),v(ye),p(Z),y(!!(fe!=null&&fe.nextCursor)),b((fe==null?void 0:fe.nextCursor)??null),z.current=`${ee}:latest`,V.current=null,j.current=null},[t]),ne=w.useCallback(async(F,ee)=>{bc();const Z=B.current;await P({threadId:Z,setLoading:A,action:async ye=>{const fe=await e.getStateHistory({threadId:ye,checkpointId:F,checkpointNs:ee??void 0});if(B.current!==ye){console.log(`[useThreadHistoryState] Thread changed during checkpoint navigation (was ${ye}, now ${B.current}), discarding stale data`);return}const{checkpoints:oe,timeline:xe}=gr(fe),Se=oe.find($e=>$e.checkpointId===F&&(ee?$e.checkpointNs===ee:!0));if(!Se){console.warn("[useThreadHistoryState] Requested checkpoint not found:",{checkpointId:F,checkpointNs:ee});return}v(xe),p(oe),t(Se.messages??[],{checkpointId:Se.checkpointId??null,checkpointNs:Se.checkpointNs??null})}}).catch(()=>{})},[e,t,P]),ce=w.useCallback((F,ee)=>{t(d(),{checkpointId:F??null,checkpointNs:ee??null})},[d,t]),G=w.useCallback(async()=>{B.current&&await Q(B.current)},[Q]),O=w.useCallback(async()=>{const F=B.current;!F||!x||await P({threadId:F,setLoading:S,action:async ee=>{const Z=await e.getStateHistory({threadId:ee,checkpointId:x});if(B.current!==ee)return;const{checkpoints:ye}=gr(Z);if(ye.length>0){const fe=ye[ye.length-1];n((fe==null?void 0:fe.messages)??[]),y(!!(fe!=null&&fe.nextCursor)),b((fe==null?void 0:fe.nextCursor)??null)}}}).catch(()=>{})},[e,x,r,n,P]);w.useEffect(()=>{if(!l||!o||C||c)return;if(V.current===o){V.current=null,q.current=o;return}if(j.current===o){q.current=o;return}if(_.current===o){_.current=null,q.current=o;return}if(q.current===o)return;q.current=o;const F=!N.current&&!!i&&o===s;let ee;F&&i?(ee=i,N.current=!0,console.log("[useThreadHistoryState] Loading thread with checkpoint:",ee,a?`(ns: ${a})`:"")):console.log("[useThreadHistoryState] Loading thread with latest checkpoint");const Z=`${o}:${ee??"latest"}`;z.current!==Z&&Q(o,ee)},[l,o,i,a,s,C,c,Q]);const W=w.useCallback(()=>{p([]),v([]),y(!1),b(null),k(!1),S(!1),A(!1),D(null),V.current=null,j.current=null,q.current=null,z.current=null,_.current=null},[]);return{threadCheckpoints:f,threadTimeline:h,isLoadingThread:C,isHistoryLoading:T,isLoadingCheckpoint:E,threadStateError:R,hasMoreHistory:g,loadThread:Q,navigateToCheckpoint:ne,loadOlderMessages:O,setCurrentCheckpointId:ce,returnToLatest:G,handleStateHistoryEvent:ae,markSkipNextLoad:M,markStreamPendingThread:Y,resetHistoryState:W}}const Rc=w.createContext(null),Pc=w.createContext(null),Oc=w.createContext(null);w.createContext(!1);const ay=["detail","message","error","description","title"];function Ho(e){if(!e)return null;if(typeof e=="string"){const t=e.trim();return t.length?t:null}if(Array.isArray(e)){for(const t of e){const n=Ho(t);if(n)return n}return null}if(typeof e=="object"){const t=e;for(const n of ay){const r=Ho(t[n]);if(r)return r}if("errors"in t){const n=Ho(t.errors);if(n)return n}}return null}function ly(e){if(!e)return"Request failed";const t=e.response,n=Ho(t==null?void 0:t.data);if(n)return n;if(t!=null&&t.statusText)return t.statusText;if(e instanceof Error&&e.message)return e.message;if(typeof e=="string"){const r=e.trim();if(r.length)return r}return t!=null&&t.status?`Request failed with status code ${t.status}`:"Request failed"}function cy({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}=Ti(),f=w.useMemo(()=>Tn(d),[d]),[p,h]=w.useState([]),[v,g]=w.useState(t),[y,x]=w.useState(!1),[b,C]=w.useState(null),[k,T]=w.useState([]),[S,E]=w.useState(!1),[,A]=w.useState(null),[R,D]=w.useState([]),[B,q]=w.useState(!1),[,V]=w.useState(null),{state:j,seed:_,prepend:N,pushUser:z,onEvent:$}=Ac(),[P,H]=w.useState(!1),Q=w.useCallback(()=>j.messages,[j.messages]),{threadCheckpoints:M,threadTimeline:Y,isLoadingThread:ae,isHistoryLoading:ne,isLoadingCheckpoint:ce,threadStateError:G,hasMoreHistory:O,loadThread:W,navigateToCheckpoint:F,loadOlderMessages:ee,setCurrentCheckpointId:Z,returnToLatest:ye,handleStateHistoryEvent:fe,markSkipNextLoad:oe,markStreamPendingThread:xe,resetHistoryState:Se}=iy({api:c,seed:_,prepend:N,onError:s,currentThreadId:v,initialThreadId:t,initialCheckpointId:n,initialCheckpointNs:r,autoLoadInitial:o,isStreaming:P,getMessages:Q}),$e=w.useMemo(()=>cx(M),[M]),_e=w.useRef(v),We=w.useRef(new Map);w.useEffect(()=>{_e.current=v},[v]);const Be=w.useCallback(async()=>{x(!0),C(null);try{const U=await c.listThreads();h(U??[])}catch(U){const re=String(U);C(re),s==null||s(re)}finally{x(!1)}},[c,s]),qe=w.useCallback(async()=>{E(!0),A(null);try{const U=await c.listSharedThreads();T(U??[])}catch(U){const re=String(U);A(re),s==null||s(re)}finally{E(!1)}},[c,s]),Ge=w.useCallback(async()=>{q(!0),V(null);try{const U=await c.listSmartOrgUsers();D(U??[])}catch(U){const re=String(U);V(re),s==null||s(re)}finally{q(!1)}},[c,s]),Ze=w.useCallback(U=>{if(!(U!=null&&U.threadId))return;const re={threadId:U.threadId,title:U.title||`Thread ${U.threadId.slice(0,8)}`,createdAt:U.createdAt||new Date().toISOString(),updatedAt:U.updatedAt||new Date().toISOString(),messageCount:U.messageCount??1};h(Ie=>{let be=!1;const tt=Ie.map(Pe=>Pe.threadId===re.threadId?(be=!0,console.debug("[ChatSessionProvider] thread_info: updating existing thread",re.threadId),{...Pe,title:re.title??Pe.title,updatedAt:re.updatedAt??Pe.updatedAt,messageCount:re.messageCount??Pe.messageCount}):Pe);return be?tt:(console.debug("[ChatSessionProvider] thread_info: adding thread to list",re.threadId),[re,...Ie])})},[]),ot=w.useCallback(U=>{console.log("[ChatSessionProvider] 🎯 Received thread_info:",U.threadId),Ze(U),_e.current!==U.threadId&&((U.created??!_e.current)&&oe(U.threadId),xe(U.threadId),console.log("[ChatSessionProvider] thread_info: marking to skip auto-load for new thread"),g(U.threadId))},[Ze,oe,xe]),{startStream:Ct,stop:lt,isStreaming:ht,error:dt,setAuthToken:gt}=sy({baseUrl:f,onThreadInfo:ot,onMessageEvent:$,onStateHistory:fe,onUnhandledEvent:U=>{console.warn("[ChatSessionProvider] Unhandled event:",U.type)},onAuthError:i,onConnectionError:l});w.useEffect(()=>{H(ht)},[ht]);const kt=w.useCallback(async U=>{try{const re=await c.createThread(U);return g(re.threadId),await Be(),re.threadId}catch(re){return s==null||s(String(re)),null}},[c,Be,s]),At=w.useCallback(async U=>{const re=p;h(be=>be.filter(tt=>tt.threadId!==U));const Ie=new AbortController;We.current.set(U,Ie);try{await c.deleteThread(U),_e.current===U&&(g(null),_([],{})),console.log("[ChatSessionProvider] Thread deleted successfully:",U)}catch(be){console.error("[ChatSessionProvider] Delete failed, restoring thread:",U,be),h(re),s==null||s(`Failed to delete thread: ${String(be)}`)}finally{We.current.delete(U)}},[p,c,_,s]),qt=w.useCallback(async(U,re)=>{try{await c.updateThread(U,re),await Be()}catch(Ie){s==null||s(String(Ie))}},[c,Be,s]),Ue=w.useCallback(async(U,re)=>{try{await c.shareThread(U,re),await qe()}catch(Ie){const be=ly(Ie);throw s==null||s(be),new Error(be)}},[c,s,qe]),K=w.useCallback(async(U,re)=>{try{await c.unshareThread(U,re),await qe()}catch(Ie){const be=String(Ie);throw s==null||s(be),Ie}},[c,s,qe]),le=w.useCallback(async()=>{_([],{}),g(null),lt(),Se();try{await c.getAgent("default")}catch(U){console.warn("[ChatSessionProvider] Failed to refetch agent after clearing thread:",U)}},[_,lt,c,Se]),ke=w.useCallback(async(U,re,Ie)=>{const be=_e.current;if(!be)throw new Error("No active thread to handle interrupt");const tt=re?Ie??!0:!1;try{const Pe={threadId:be,checkpointId:j.lastCheckpointId??void 0,checkpointNs:j.lastCheckpointNs??void 0,command:{kind:"resume",value:tt}};Ct(Pe)}catch(Pe){throw console.error(`[ChatSessionProvider] Failed to handle interrupt ${U}:`,Pe),Pe}},[j.lastCheckpointId,j.lastCheckpointNs,Ct]);w.useEffect(()=>{Be(),Ge()},[Be,Ge]),w.useEffect(()=>{qe()},[qe]),w.useEffect(()=>{a==null||a(v)},[v,a]);const st=w.useCallback(async(U,re)=>{let Ie=_e.current;const be=(U==null?void 0:U.text)??"",tt=(U==null?void 0:U.attachments)??[],Pe=(be==null?void 0:be.trim())??"",xt={...(U==null?void 0:U.payload)??{}},Cn=Array.isArray(xt.messages)?xt.messages:void 0;Cn&&delete xt.messages;const An=!!(Cn&&Cn.length);if(!Ie&&!Pe&&tt.length===0&&!An)return;if(!Ie){const et=Math.floor(Date.now()/1e3).toString(16).padStart(8,"0"),ze=Array.from({length:4},()=>Math.floor(Math.random()*4294967295).toString(16).padStart(8,"0")).join("").slice(0,16);Ie=`${et}${ze}`,oe(Ie),g(Ie)}const{contentParts:Or,filesInfo:Dr}=await ix(c,tt),dr=[...Or];Pe&&dr.push({type:"text",text:be});const Lr=re==null?void 0:re.originalMessageId,fr=!!(re!=null&&re.edit&&Lr),I=!An&&dr.length>0;let J=null;I&&(J={id:fr?Lr:`msg-${Date.now()}`,role:"user",content:dr,createdAt:new Date().toISOString()},fr||z(J));const de=An?Cn:J?[J]:[],Ce={...xt,...Dr.length?{files_info:Dr}:{}};de.length?Ce.messages=de:"messages"in Ce||(Ce.messages=[]);const Ye={threadId:Ie,payload:Ce,checkpointId:(re==null?void 0:re.checkpointId)??j.lastCheckpointId??void 0,checkpointNs:(re==null?void 0:re.checkpointNs)??j.lastCheckpointNs??void 0,edit:!!(re!=null&&re.edit),timelineCheckpoints:Y};Ct(Ye)},[c,z,j,Ct,Y]),wt=w.useMemo(()=>({threads:p,currentThreadId:v,setCurrentThreadId:g,isLoading:y,error:b,sharedThreads:k,isLoadingSharedThreads:S,smartOrgUsers:R,isLoadingSmartOrgUsers:B,actions:{createThread:kt,deleteThread:At,renameThread:qt,refreshThreads:Be,refreshSharedThreads:qe,refreshSmartOrgUsers:Ge,shareThread:Ue,unshareThread:K}}),[p,v,y,b,k,S,R,B,kt,At,qt,Be,qe,Ge,Ue,K]),Qe=w.useMemo(()=>{const U=j.assemblingId??null;return U?{assemblingMessageId:U}:null},[j.assemblingId]),Dt=w.useMemo(()=>({threadId:v,messages:j.messages,interrupt:null,checkpoint:{id:j.lastCheckpointId??null,namespace:j.lastCheckpointNs??null},checkpoints:M,timelineCheckpoints:Y,metadata:Qe,isLoading:ae,isHistoryLoading:ne,isLoadingCheckpoint:ce,error:G,hasMore:O,loadOlder:ee,clearState:le,navigateToCheckpoint:F,setCurrentCheckpointId:Z,returnToLatest:ye,loadThread:W,clearThread:le,respondToInterrupt:ke,messagePreviews:$e}),[v,j,M,Y,ae,ne,ce,G,O,ee,le,F,Z,ye,W,ke,$e,Qe]),X=w.useMemo(()=>({isStreaming:ht,error:dt,connectionState:ht?"connected":"idle",submit:st,send:st,stop:lt,setAuthToken:gt}),[ht,dt,st,lt,gt]);return u.jsx(Rc.Provider,{value:wt,children:u.jsx(Pc.Provider,{value:Dt,children:u.jsx(Oc.Provider,{value:X,children:e})})})}function Wo(){const e=w.useContext(Rc);if(!e)throw new Error("useThreads must be used within ChatSessionProvider");return e}function Vo(){const e=w.useContext(Pc);if(!e)throw new Error("useThreadState must be used within ChatSessionProvider");return e}function Dc(){const e=w.useContext(Oc);if(!e)throw new Error("useStream must be used within ChatSessionProvider");return e}function Ko({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(ox,{apiConfig:t,children:u.jsx(cy,{initialThreadId:n,initialCheckpointId:r,initialCheckpointNs:o,autoLoadInitial:s,onError:a,onAuthError:l,onConnectionError:i,onThreadChange:c,children:e})})}function se(...e){return _m.twMerge(jm.clsx(e))}const uy=ko.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"}}),nt=m.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?Kn.Slot:"button";return u.jsx(i,{className:se(uy({variant:t,size:n,className:e})),ref:s,...o})});nt.displayName="Button";const Lc=m.forwardRef(({className:e,...t},n)=>u.jsx("textarea",{className:se("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",e),ref:n,...t}));Lc.displayName="Textarea";function $c({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 v=i!==void 0,[g,y]=w.useState(e),x=(v?i:g)??"",[b,C]=w.useTransition(),k=w.useRef(null),T=w.useRef(0),S=w.useRef(null);w.useEffect(()=>{v||(y(e??""),S.current=null,k.current&&(k.current.style.height="auto",k.current.style.height=`${k.current.scrollHeight}px`))},[e,t,v]);const E=w.useCallback(()=>{const _=k.current;_&&(_.style.height="auto",_.style.height=`${_.scrollHeight}px`)},[]);w.useEffect(()=>{E()},[E,x]);const A=w.useCallback((_,{fromUser:N})=>{v||y(_),N&&(a==null||a(_))},[v,a]),R=w.useCallback(async _=>{_&&_.preventDefault();const N=(x??"").trim();if(!N&&!h)return;const z=++T.current;S.current={id:z,shouldClear:!0},C(()=>{var $,P,H;try{const Q=l(N);Q&&typeof Q.then=="function"?Q.then(()=>{var M,Y;((M=S.current)==null?void 0:M.id)===z&&S.current.shouldClear&&(v||(y(""),k.current&&(k.current.style.height="auto"),a==null||a(""))),((Y=S.current)==null?void 0:Y.id)===z&&(S.current=null)}).catch(()=>{var M;((M=S.current)==null?void 0:M.id)===z&&(S.current=null)}):((($=S.current)==null?void 0:$.id)===z&&S.current.shouldClear&&(v||(y(""),k.current&&(k.current.style.height="auto"),a==null||a(""))),((P=S.current)==null?void 0:P.id)===z&&(S.current=null))}catch{((H=S.current)==null?void 0:H.id)===z&&(S.current=null)}})},[x,l,h,v,a]),D=w.useCallback(_=>{const N=_.target.value;A(N,{fromUser:!0}),S.current&&(S.current.shouldClear=!1),k.current&&(k.current.style.height="auto",k.current.style.height=`${k.current.scrollHeight}px`)},[A]),B=w.useCallback(_=>{_.key==="Enter"&&!_.shiftKey?(_.preventDefault(),R()):_.key==="Escape"&&t&&(_.preventDefault(),c==null||c())},[R,t,c]),j=`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:_=>void R(_),className:`w-full ${f}`,children:u.jsxs("div",{className:"flex items-end gap-2",children:[u.jsx("div",{className:"flex-1",children:u.jsx(Lc,{ref:k,value:x,onChange:D,onKeyDown:B,placeholder:t?"Edit your message...":n,className:j,disabled:o,maxLength:s,rows:1,spellCheck:!1,autoCorrect:"off"})}),u.jsx("div",{children:r?u.jsx(nt,{type:"button",onClick:()=>{d==null||d()},size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",disabled:o||!d,children:u.jsx(ue.Square,{size:16})}):u.jsx(nt,{type:"submit",size:"icon",className:"shrink-0",title:t?"Save changes":"Send message",disabled:o||!x.trim()&&!h||b,children:u.jsx(ue.Send,{size:16})})})]})})}const dy=w.memo($c);function me(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 _n(...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 Ve(...e){return m.useCallback(_n(...e),e)}function fy(e,t){const n=m.createContext(t),r=s=>{const{children:i,...a}=s,l=m.useMemo(()=>a,Object.values(a));return u.jsx(n.Provider,{value:l,children:i})};r.displayName=e+"Provider";function o(s){const i=m.useContext(n);if(i)return i;if(t!==void 0)return t;throw new Error(`\`${s}\` must be used within \`${e}\``)}return[r,o]}function kn(e,t=[]){let n=[];function r(s,i){const a=m.createContext(i),l=n.length;n=[...n,i];const c=f=>{var x;const{scope:p,children:h,...v}=f,g=((x=p==null?void 0:p[e])==null?void 0:x[l])||a,y=m.useMemo(()=>v,Object.values(v));return u.jsx(g.Provider,{value:y,children:h})};c.displayName=s+"Provider";function d(f,p){var g;const h=((g=p==null?void 0:p[e])==null?void 0:g[l])||a,v=m.useContext(h);if(v)return v;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=>m.createContext(i));return function(a){const l=(a==null?void 0:a[e])||s;return m.useMemo(()=>({[`__scope${e}`]:{...a,[e]:l}}),[a,l])}};return o.scopeName=e,[r,py(o,...t)]}function py(...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 m.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}var It=globalThis!=null&&globalThis.document?m.useLayoutEffect:()=>{},hy=m[" useInsertionEffect ".trim().toString()]||It;function yr({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=my({defaultProp:t,onChange:n}),a=e!==void 0,l=a?e:o;{const d=m.useRef(e!==void 0);m.useEffect(()=>{const f=d.current;f!==a&&console.warn(`${r} is changing from ${f?"controlled":"uncontrolled"} to ${a?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),d.current=a},[a,r])}const c=m.useCallback(d=>{var f;if(a){const p=gy(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 my({defaultProp:e,onChange:t}){const[n,r]=m.useState(e),o=m.useRef(n),s=m.useRef(t);return hy(()=>{s.current=t},[t]),m.useEffect(()=>{var i;o.current!==n&&((i=s.current)==null||i.call(s,n),o.current=n)},[n,o]),[n,r,s]}function gy(e){return typeof e=="function"}var xy=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Ee=xy.reduce((e,t)=>{const n=Kn.createSlot(`Primitive.${t}`),r=m.forwardRef((o,s)=>{const{asChild:i,...a}=o,l=i?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),u.jsx(l,{...a,ref:s})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function Bc(e,t){e&&Eo.flushSync(()=>e.dispatchEvent(t))}function Ai(e){const t=e+"CollectionProvider",[n,r]=kn(t),[o,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),i=g=>{const{scope:y,children:x}=g,b=w.useRef(null),C=w.useRef(new Map).current;return u.jsx(o,{scope:y,itemMap:C,collectionRef:b,children:x})};i.displayName=t;const a=e+"CollectionSlot",l=Kn.createSlot(a),c=w.forwardRef((g,y)=>{const{scope:x,children:b}=g,C=s(a,x),k=Ve(y,C.collectionRef);return u.jsx(l,{ref:k,children:b})});c.displayName=a;const d=e+"CollectionItemSlot",f="data-radix-collection-item",p=Kn.createSlot(d),h=w.forwardRef((g,y)=>{const{scope:x,children:b,...C}=g,k=w.useRef(null),T=Ve(y,k),S=s(d,x);return w.useEffect(()=>(S.itemMap.set(k,{ref:k,...C}),()=>void S.itemMap.delete(k))),u.jsx(p,{[f]:"",ref:T,children:b})});h.displayName=d;function v(g){const y=s(e+"CollectionConsumer",g);return w.useCallback(()=>{const b=y.collectionRef.current;if(!b)return[];const C=Array.from(b.querySelectorAll(`[${f}]`));return Array.from(y.itemMap.values()).sort((S,E)=>C.indexOf(S.ref.current)-C.indexOf(E.ref.current))},[y.collectionRef,y.itemMap])}return[{Provider:i,Slot:c,ItemSlot:h},v,r]}var yy=m.createContext(void 0);function qo(e){const t=m.useContext(yy);return e||t||"ltr"}function Nt(e){const t=m.useRef(e);return m.useEffect(()=>{t.current=e}),m.useMemo(()=>(...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)},[])}function vy(e,t=globalThis==null?void 0:globalThis.document){const n=Nt(e);m.useEffect(()=>{const r=o=>{o.key==="Escape"&&n(o)};return t.addEventListener("keydown",r,{capture:!0}),()=>t.removeEventListener("keydown",r,{capture:!0})},[n,t])}var by="DismissableLayer",ji="dismissableLayer.update",wy="dismissableLayer.pointerDownOutside",Sy="dismissableLayer.focusOutside",zc,Uc=m.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),Go=m.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:a,...l}=e,c=m.useContext(Uc),[d,f]=m.useState(null),p=(d==null?void 0:d.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,h]=m.useState({}),v=Ve(t,E=>f(E)),g=Array.from(c.layers),[y]=[...c.layersWithOutsidePointerEventsDisabled].slice(-1),x=g.indexOf(y),b=d?g.indexOf(d):-1,C=c.layersWithOutsidePointerEventsDisabled.size>0,k=b>=x,T=ky(E=>{const A=E.target,R=[...c.branches].some(D=>D.contains(A));!k||R||(o==null||o(E),i==null||i(E),E.defaultPrevented||a==null||a())},p),S=Ey(E=>{const A=E.target;[...c.branches].some(D=>D.contains(A))||(s==null||s(E),i==null||i(E),E.defaultPrevented||a==null||a())},p);return vy(E=>{b===c.layers.size-1&&(r==null||r(E),!E.defaultPrevented&&a&&(E.preventDefault(),a()))},p),m.useEffect(()=>{if(d)return n&&(c.layersWithOutsidePointerEventsDisabled.size===0&&(zc=p.body.style.pointerEvents,p.body.style.pointerEvents="none"),c.layersWithOutsidePointerEventsDisabled.add(d)),c.layers.add(d),Hc(),()=>{n&&c.layersWithOutsidePointerEventsDisabled.size===1&&(p.body.style.pointerEvents=zc)}},[d,p,n,c]),m.useEffect(()=>()=>{d&&(c.layers.delete(d),c.layersWithOutsidePointerEventsDisabled.delete(d),Hc())},[d,c]),m.useEffect(()=>{const E=()=>h({});return document.addEventListener(ji,E),()=>document.removeEventListener(ji,E)},[]),u.jsx(Ee.div,{...l,ref:v,style:{pointerEvents:C?k?"auto":"none":void 0,...e.style},onFocusCapture:me(e.onFocusCapture,S.onFocusCapture),onBlurCapture:me(e.onBlurCapture,S.onBlurCapture),onPointerDownCapture:me(e.onPointerDownCapture,T.onPointerDownCapture)})});Go.displayName=by;var Cy="DismissableLayerBranch",Ty=m.forwardRef((e,t)=>{const n=m.useContext(Uc),r=m.useRef(null),o=Ve(t,r);return m.useEffect(()=>{const s=r.current;if(s)return n.branches.add(s),()=>{n.branches.delete(s)}},[n.branches]),u.jsx(Ee.div,{...e,ref:o})});Ty.displayName=Cy;function ky(e,t=globalThis==null?void 0:globalThis.document){const n=Nt(e),r=m.useRef(!1),o=m.useRef(()=>{});return m.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let l=function(){Wc(wy,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 Ey(e,t=globalThis==null?void 0:globalThis.document){const n=Nt(e),r=m.useRef(!1);return m.useEffect(()=>{const o=s=>{s.target&&!r.current&&Wc(Sy,n,{originalEvent:s},{discrete:!1})};return t.addEventListener("focusin",o),()=>t.removeEventListener("focusin",o)},[t,n]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}function Hc(){const e=new CustomEvent(ji);document.dispatchEvent(e)}function Wc(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?Bc(o,s):o.dispatchEvent(s)}var _i=0;function Mi(){m.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??Vc()),document.body.insertAdjacentElement("beforeend",e[1]??Vc()),_i++,()=>{_i===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),_i--}},[])}function Vc(){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 Ri="focusScope.autoFocusOnMount",Pi="focusScope.autoFocusOnUnmount",Kc={bubbles:!1,cancelable:!0},Iy="FocusScope",Yo=m.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:s,...i}=e,[a,l]=m.useState(null),c=Nt(o),d=Nt(s),f=m.useRef(null),p=Ve(t,g=>l(g)),h=m.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;m.useEffect(()=>{if(r){let g=function(C){if(h.paused||!a)return;const k=C.target;a.contains(k)?f.current=k:Mn(f.current,{select:!0})},y=function(C){if(h.paused||!a)return;const k=C.relatedTarget;k!==null&&(a.contains(k)||Mn(f.current,{select:!0}))},x=function(C){if(document.activeElement===document.body)for(const T of C)T.removedNodes.length>0&&Mn(a)};document.addEventListener("focusin",g),document.addEventListener("focusout",y);const b=new MutationObserver(x);return a&&b.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",g),document.removeEventListener("focusout",y),b.disconnect()}}},[r,a,h.paused]),m.useEffect(()=>{if(a){Yc.add(h);const g=document.activeElement;if(!a.contains(g)){const x=new CustomEvent(Ri,Kc);a.addEventListener(Ri,c),a.dispatchEvent(x),x.defaultPrevented||(Ny(Ry(qc(a)),{select:!0}),document.activeElement===g&&Mn(a))}return()=>{a.removeEventListener(Ri,c),setTimeout(()=>{const x=new CustomEvent(Pi,Kc);a.addEventListener(Pi,d),a.dispatchEvent(x),x.defaultPrevented||Mn(g??document.body,{select:!0}),a.removeEventListener(Pi,d),Yc.remove(h)},0)}}},[a,c,d,h]);const v=m.useCallback(g=>{if(!n&&!r||h.paused)return;const y=g.key==="Tab"&&!g.altKey&&!g.ctrlKey&&!g.metaKey,x=document.activeElement;if(y&&x){const b=g.currentTarget,[C,k]=Ay(b);C&&k?!g.shiftKey&&x===k?(g.preventDefault(),n&&Mn(C,{select:!0})):g.shiftKey&&x===C&&(g.preventDefault(),n&&Mn(k,{select:!0})):x===b&&g.preventDefault()}},[n,r,h.paused]);return u.jsx(Ee.div,{tabIndex:-1,...i,ref:p,onKeyDown:v})});Yo.displayName=Iy;function Ny(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(Mn(r,{select:t}),document.activeElement!==n)return}function Ay(e){const t=qc(e),n=Gc(t,e),r=Gc(t.reverse(),e);return[n,r]}function qc(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 Gc(e,t){for(const n of e)if(!jy(n,{upTo:t}))return n}function jy(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 _y(e){return e instanceof HTMLInputElement&&"select"in e}function Mn(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&_y(e)&&t&&e.select()}}var Yc=My();function My(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=Xc(e,t),e.unshift(t)},remove(t){var n;e=Xc(e,t),(n=e[0])==null||n.resume()}}}function Xc(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function Ry(e){return e.filter(t=>t.tagName!=="A")}var Py=m[" useId ".trim().toString()]||(()=>{}),Oy=0;function $t(e){const[t,n]=m.useState(Py());return It(()=>{n(r=>r??String(Oy++))},[e]),t?`radix-${t}`:""}const Dy=["top","right","bottom","left"],Rn=Math.min,Gt=Math.max,Xo=Math.round,Jo=Math.floor,hn=e=>({x:e,y:e}),Ly={left:"right",right:"left",bottom:"top",top:"bottom"},$y={start:"end",end:"start"};function Oi(e,t,n){return Gt(e,Rn(t,n))}function En(e,t){return typeof e=="function"?e(t):e}function In(e){return e.split("-")[0]}function vr(e){return e.split("-")[1]}function Di(e){return e==="x"?"y":"x"}function Li(e){return e==="y"?"height":"width"}const Fy=new Set(["top","bottom"]);function mn(e){return Fy.has(In(e))?"y":"x"}function $i(e){return Di(mn(e))}function By(e,t,n){n===void 0&&(n=!1);const r=vr(e),o=$i(e),s=Li(o);let i=o==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(i=Zo(i)),[i,Zo(i)]}function zy(e){const t=Zo(e);return[Fi(e),t,Fi(t)]}function Fi(e){return e.replace(/start|end/g,t=>$y[t])}const Jc=["left","right"],Zc=["right","left"],Uy=["top","bottom"],Hy=["bottom","top"];function Wy(e,t,n){switch(e){case"top":case"bottom":return n?t?Zc:Jc:t?Jc:Zc;case"left":case"right":return t?Uy:Hy;default:return[]}}function Vy(e,t,n,r){const o=vr(e);let s=Wy(In(e),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(Fi)))),s}function Zo(e){return e.replace(/left|right|bottom|top/g,t=>Ly[t])}function Ky(e){return{top:0,right:0,bottom:0,left:0,...e}}function Qc(e){return typeof e!="number"?Ky(e):{top:e,right:e,bottom:e,left:e}}function Qo(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 eu(e,t,n){let{reference:r,floating:o}=e;const s=mn(t),i=$i(t),a=Li(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(vr(t)){case"start":h[i]-=p*(n&&c?-1:1);break;case"end":h[i]+=p*(n&&c?-1:1);break}return h}const qy=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}=eu(c,r,l),p=r,h={},v=0;for(let g=0;g<a.length;g++){const{name:y,fn:x}=a[g],{x:b,y:C,data:k,reset:T}=await x({x:d,y:f,initialPlacement:r,placement:p,strategy:o,middlewareData:h,rects:c,platform:i,elements:{reference:e,floating:t}});d=b??d,f=C??f,h={...h,[y]:{...h[y],...k}},T&&v<=50&&(v++,typeof T=="object"&&(T.placement&&(p=T.placement),T.rects&&(c=T.rects===!0?await i.getElementRects({reference:e,floating:t,strategy:o}):T.rects),{x:d,y:f}=eu(c,p,l)),g=-1)}return{x:d,y:f,placement:p,strategy:o,middlewareData:h}};async function Kr(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),v=Qc(h),y=a[p?f==="floating"?"reference":"floating":f],x=Qo(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(y)))==null||n?y:y.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(a.floating)),boundary:c,rootBoundary:d,strategy:l})),b=f==="floating"?{x:r,y:o,width:i.floating.width,height:i.floating.height}:i.reference,C=await(s.getOffsetParent==null?void 0:s.getOffsetParent(a.floating)),k=await(s.isElement==null?void 0:s.isElement(C))?await(s.getScale==null?void 0:s.getScale(C))||{x:1,y:1}:{x:1,y:1},T=Qo(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:b,offsetParent:C,strategy:l}):b);return{top:(x.top-T.top+v.top)/k.y,bottom:(T.bottom-x.bottom+v.bottom)/k.y,left:(x.left-T.left+v.left)/k.x,right:(T.right-x.right+v.right)/k.x}}const Gy=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=Qc(d),p={x:n,y:r},h=$i(o),v=Li(h),g=await i.getDimensions(c),y=h==="y",x=y?"top":"left",b=y?"bottom":"right",C=y?"clientHeight":"clientWidth",k=s.reference[v]+s.reference[h]-p[h]-s.floating[v],T=p[h]-s.reference[h],S=await(i.getOffsetParent==null?void 0:i.getOffsetParent(c));let E=S?S[C]:0;(!E||!await(i.isElement==null?void 0:i.isElement(S)))&&(E=a.floating[C]||s.floating[v]);const A=k/2-T/2,R=E/2-g[v]/2-1,D=Rn(f[x],R),B=Rn(f[b],R),q=D,V=E-g[v]-B,j=E/2-g[v]/2+A,_=Oi(q,j,V),N=!l.arrow&&vr(o)!=null&&j!==_&&s.reference[v]/2-(j<q?D:B)-g[v]/2<0,z=N?j<q?j-q:j-V:0;return{[h]:p[h]+z,data:{[h]:_,centerOffset:j-_-z,...N&&{alignmentOffset:z}},reset:N}}}),Yy=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:v="none",flipAlignment:g=!0,...y}=En(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const x=In(o),b=mn(a),C=In(a)===a,k=await(l.isRTL==null?void 0:l.isRTL(c.floating)),T=p||(C||!g?[Zo(a)]:zy(a)),S=v!=="none";!p&&S&&T.push(...Vy(a,g,v,k));const E=[a,...T],A=await Kr(t,y),R=[];let D=((r=s.flip)==null?void 0:r.overflows)||[];if(d&&R.push(A[x]),f){const j=By(o,i,k);R.push(A[j[0]],A[j[1]])}if(D=[...D,{placement:o,overflows:R}],!R.every(j=>j<=0)){var B,q;const j=(((B=s.flip)==null?void 0:B.index)||0)+1,_=E[j];if(_&&(!(f==="alignment"?b!==mn(_):!1)||D.every($=>mn($.placement)===b?$.overflows[0]>0:!0)))return{data:{index:j,overflows:D},reset:{placement:_}};let N=(q=D.filter(z=>z.overflows[0]<=0).sort((z,$)=>z.overflows[1]-$.overflows[1])[0])==null?void 0:q.placement;if(!N)switch(h){case"bestFit":{var V;const z=(V=D.filter($=>{if(S){const P=mn($.placement);return P===b||P==="y"}return!0}).map($=>[$.placement,$.overflows.filter(P=>P>0).reduce((P,H)=>P+H,0)]).sort(($,P)=>$[1]-P[1])[0])==null?void 0:V[0];z&&(N=z);break}case"initialPlacement":N=a;break}if(o!==N)return{reset:{placement:N}}}return{}}}};function tu(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function nu(e){return Dy.some(t=>e[t]>=0)}const Xy=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 Kr(t,{...o,elementContext:"reference"}),i=tu(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:nu(i)}}}case"escaped":{const s=await Kr(t,{...o,altBoundary:!0}),i=tu(s,n.floating);return{data:{escapedOffsets:i,escaped:nu(i)}}}default:return{}}}}},ru=new Set(["left","top"]);async function Jy(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=vr(n),l=mn(n)==="y",c=ru.has(i)?-1:1,d=s&&l?-1:1,f=En(t,e);let{mainAxis:p,crossAxis:h,alignmentAxis:v}=typeof f=="number"?{mainAxis:f,crossAxis:0,alignmentAxis:null}:{mainAxis:f.mainAxis||0,crossAxis:f.crossAxis||0,alignmentAxis:f.alignmentAxis};return a&&typeof v=="number"&&(h=a==="end"?v*-1:v),l?{x:h*d,y:p*c}:{x:p*c,y:h*d}}const Zy=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 Jy(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}}}}},Qy=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 Kr(t,l),f=mn(In(o)),p=Di(f);let h=c[p],v=c[f];if(s){const y=p==="y"?"top":"left",x=p==="y"?"bottom":"right",b=h+d[y],C=h-d[x];h=Oi(b,h,C)}if(i){const y=f==="y"?"top":"left",x=f==="y"?"bottom":"right",b=v+d[y],C=v-d[x];v=Oi(b,v,C)}const g=a.fn({...t,[p]:h,[f]:v});return{...g,data:{x:g.x-n,y:g.y-r,enabled:{[p]:s,[f]:i}}}}}},ev=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=mn(o),p=Di(f);let h=d[p],v=d[f];const g=En(a,t),y=typeof g=="number"?{mainAxis:g,crossAxis:0}:{mainAxis:0,crossAxis:0,...g};if(l){const C=p==="y"?"height":"width",k=s.reference[p]-s.floating[C]+y.mainAxis,T=s.reference[p]+s.reference[C]-y.mainAxis;h<k?h=k:h>T&&(h=T)}if(c){var x,b;const C=p==="y"?"width":"height",k=ru.has(In(o)),T=s.reference[f]-s.floating[C]+(k&&((x=i.offset)==null?void 0:x[f])||0)+(k?0:y.crossAxis),S=s.reference[f]+s.reference[C]+(k?0:((b=i.offset)==null?void 0:b[f])||0)-(k?y.crossAxis:0);v<T?v=T:v>S&&(v=S)}return{[p]:h,[f]:v}}}},tv=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 Kr(t,c),f=In(o),p=vr(o),h=mn(o)==="y",{width:v,height:g}=s.floating;let y,x;f==="top"||f==="bottom"?(y=f,x=p===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(x=f,y=p==="end"?"top":"bottom");const b=g-d.top-d.bottom,C=v-d.left-d.right,k=Rn(g-d[y],b),T=Rn(v-d[x],C),S=!t.middlewareData.shift;let E=k,A=T;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(A=C),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(E=b),S&&!p){const D=Gt(d.left,0),B=Gt(d.right,0),q=Gt(d.top,0),V=Gt(d.bottom,0);h?A=v-2*(D!==0||B!==0?D+B:Gt(d.left,d.right)):E=g-2*(q!==0||V!==0?q+V:Gt(d.top,d.bottom))}await l({...t,availableWidth:A,availableHeight:E});const R=await i.getDimensions(a.floating);return v!==R.width||g!==R.height?{reset:{rects:!0}}:{}}}};function es(){return typeof window<"u"}function br(e){return ou(e)?(e.nodeName||"").toLowerCase():"#document"}function Yt(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function gn(e){var t;return(t=(ou(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function ou(e){return es()?e instanceof Node||e instanceof Yt(e).Node:!1}function an(e){return es()?e instanceof Element||e instanceof Yt(e).Element:!1}function xn(e){return es()?e instanceof HTMLElement||e instanceof Yt(e).HTMLElement:!1}function su(e){return!es()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Yt(e).ShadowRoot}const nv=new Set(["inline","contents"]);function qr(e){const{overflow:t,overflowX:n,overflowY:r,display:o}=ln(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!nv.has(o)}const rv=new Set(["table","td","th"]);function ov(e){return rv.has(br(e))}const sv=[":popover-open",":modal"];function ts(e){return sv.some(t=>{try{return e.matches(t)}catch{return!1}})}const iv=["transform","translate","scale","rotate","perspective"],av=["transform","translate","scale","rotate","perspective","filter"],lv=["paint","layout","strict","content"];function Bi(e){const t=zi(),n=an(e)?ln(e):e;return iv.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)||av.some(r=>(n.willChange||"").includes(r))||lv.some(r=>(n.contain||"").includes(r))}function cv(e){let t=Pn(e);for(;xn(t)&&!wr(t);){if(Bi(t))return t;if(ts(t))return null;t=Pn(t)}return null}function zi(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const uv=new Set(["html","body","#document"]);function wr(e){return uv.has(br(e))}function ln(e){return Yt(e).getComputedStyle(e)}function ns(e){return an(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Pn(e){if(br(e)==="html")return e;const t=e.assignedSlot||e.parentNode||su(e)&&e.host||gn(e);return su(t)?t.host:t}function iu(e){const t=Pn(e);return wr(t)?e.ownerDocument?e.ownerDocument.body:e.body:xn(t)&&qr(t)?t:iu(t)}function Gr(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const o=iu(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=Yt(o);if(s){const a=Ui(i);return t.concat(i,i.visualViewport||[],qr(o)?o:[],a&&n?Gr(a):[])}return t.concat(o,Gr(o,[],n))}function Ui(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function au(e){const t=ln(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const o=xn(e),s=o?e.offsetWidth:n,i=o?e.offsetHeight:r,a=Xo(n)!==s||Xo(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function Hi(e){return an(e)?e:e.contextElement}function Sr(e){const t=Hi(e);if(!xn(t))return hn(1);const n=t.getBoundingClientRect(),{width:r,height:o,$:s}=au(t);let i=(s?Xo(n.width):n.width)/r,a=(s?Xo(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const dv=hn(0);function lu(e){const t=Yt(e);return!zi()||!t.visualViewport?dv:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function fv(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==Yt(e)?!1:t}function Xn(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const o=e.getBoundingClientRect(),s=Hi(e);let i=hn(1);t&&(r?an(r)&&(i=Sr(r)):i=Sr(e));const a=fv(s,n,r)?lu(s):hn(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=Yt(s),h=r&&an(r)?Yt(r):r;let v=p,g=Ui(v);for(;g&&r&&h!==v;){const y=Sr(g),x=g.getBoundingClientRect(),b=ln(g),C=x.left+(g.clientLeft+parseFloat(b.paddingLeft))*y.x,k=x.top+(g.clientTop+parseFloat(b.paddingTop))*y.y;l*=y.x,c*=y.y,d*=y.x,f*=y.y,l+=C,c+=k,v=Yt(g),g=Ui(v)}}return Qo({width:d,height:f,x:l,y:c})}function rs(e,t){const n=ns(e).scrollLeft;return t?t.left+n:Xn(gn(e)).left+n}function cu(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-rs(e,n),o=n.top+t.scrollTop;return{x:r,y:o}}function pv(e){let{elements:t,rect:n,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=gn(r),a=t?ts(t.floating):!1;if(r===i||a&&s)return n;let l={scrollLeft:0,scrollTop:0},c=hn(1);const d=hn(0),f=xn(r);if((f||!f&&!s)&&((br(r)!=="body"||qr(i))&&(l=ns(r)),xn(r))){const h=Xn(r);c=Sr(r),d.x=h.x+r.clientLeft,d.y=h.y+r.clientTop}const p=i&&!f&&!s?cu(i,l):hn(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 hv(e){return Array.from(e.getClientRects())}function mv(e){const t=gn(e),n=ns(e),r=e.ownerDocument.body,o=Gt(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=Gt(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let i=-n.scrollLeft+rs(e);const a=-n.scrollTop;return ln(r).direction==="rtl"&&(i+=Gt(t.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}const uu=25;function gv(e,t){const n=Yt(e),r=gn(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=zi();(!d||d&&t==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}const c=rs(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,v=Math.abs(r.clientWidth-f.clientWidth-h);v<=uu&&(s-=v)}else c<=uu&&(s+=c);return{width:s,height:i,x:a,y:l}}const xv=new Set(["absolute","fixed"]);function yv(e,t){const n=Xn(e,!0,t==="fixed"),r=n.top+e.clientTop,o=n.left+e.clientLeft,s=xn(e)?Sr(e):hn(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 du(e,t,n){let r;if(t==="viewport")r=gv(e,n);else if(t==="document")r=mv(gn(e));else if(an(t))r=yv(t,n);else{const o=lu(e);r={x:t.x-o.x,y:t.y-o.y,width:t.width,height:t.height}}return Qo(r)}function fu(e,t){const n=Pn(e);return n===t||!an(n)||wr(n)?!1:ln(n).position==="fixed"||fu(n,t)}function vv(e,t){const n=t.get(e);if(n)return n;let r=Gr(e,[],!1).filter(a=>an(a)&&br(a)!=="body"),o=null;const s=ln(e).position==="fixed";let i=s?Pn(e):e;for(;an(i)&&!wr(i);){const a=ln(i),l=Bi(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&xv.has(o.position)||qr(i)&&!l&&fu(e,i))?r=r.filter(d=>d!==i):o=a,i=Pn(i)}return t.set(e,r),r}function bv(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i=[...n==="clippingAncestors"?ts(t)?[]:vv(t,this._c):[].concat(n),r],a=i[0],l=i.reduce((c,d)=>{const f=du(t,d,o);return c.top=Gt(f.top,c.top),c.right=Rn(f.right,c.right),c.bottom=Rn(f.bottom,c.bottom),c.left=Gt(f.left,c.left),c},du(t,a,o));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function wv(e){const{width:t,height:n}=au(e);return{width:t,height:n}}function Sv(e,t,n){const r=xn(t),o=gn(t),s=n==="fixed",i=Xn(e,!0,s,t);let a={scrollLeft:0,scrollTop:0};const l=hn(0);function c(){l.x=rs(o)}if(r||!r&&!s)if((br(t)!=="body"||qr(o))&&(a=ns(t)),r){const h=Xn(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?cu(o,a):hn(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 Wi(e){return ln(e).position==="static"}function pu(e,t){if(!xn(e)||ln(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return gn(e)===n&&(n=n.ownerDocument.body),n}function hu(e,t){const n=Yt(e);if(ts(e))return n;if(!xn(e)){let o=Pn(e);for(;o&&!wr(o);){if(an(o)&&!Wi(o))return o;o=Pn(o)}return n}let r=pu(e,t);for(;r&&ov(r)&&Wi(r);)r=pu(r,t);return r&&wr(r)&&Wi(r)&&!Bi(r)?n:r||cv(e)||n}const Cv=async function(e){const t=this.getOffsetParent||hu,n=this.getDimensions,r=await n(e.floating);return{reference:Sv(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function Tv(e){return ln(e).direction==="rtl"}const kv={convertOffsetParentRelativeRectToViewportRelativeRect:pv,getDocumentElement:gn,getClippingRect:bv,getOffsetParent:hu,getElementRects:Cv,getClientRects:hv,getDimensions:wv,getScale:Sr,isElement:an,isRTL:Tv};function mu(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function Ev(e,t){let n=null,r;const o=gn(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 v=Jo(f),g=Jo(o.clientWidth-(d+p)),y=Jo(o.clientHeight-(f+h)),x=Jo(d),C={rootMargin:-v+"px "+-g+"px "+-y+"px "+-x+"px",threshold:Gt(0,Rn(1,l))||1};let k=!0;function T(S){const E=S[0].intersectionRatio;if(E!==l){if(!k)return i();E?i(!1,E):r=setTimeout(()=>{i(!1,1e-7)},1e3)}E===1&&!mu(c,e.getBoundingClientRect())&&i(),k=!1}try{n=new IntersectionObserver(T,{...C,root:o.ownerDocument})}catch{n=new IntersectionObserver(T,C)}n.observe(e)}return i(!0),s}function Iv(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=Hi(e),d=o||s?[...c?Gr(c):[],...Gr(t)]:[];d.forEach(x=>{o&&x.addEventListener("scroll",n,{passive:!0}),s&&x.addEventListener("resize",n)});const f=c&&a?Ev(c,n):null;let p=-1,h=null;i&&(h=new ResizeObserver(x=>{let[b]=x;b&&b.target===c&&h&&(h.unobserve(t),cancelAnimationFrame(p),p=requestAnimationFrame(()=>{var C;(C=h)==null||C.observe(t)})),n()}),c&&!l&&h.observe(c),h.observe(t));let v,g=l?Xn(e):null;l&&y();function y(){const x=Xn(e);g&&!mu(g,x)&&n(),g=x,v=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(v)}}const Nv=Zy,Av=Qy,jv=Yy,_v=tv,Mv=Xy,gu=Gy,Rv=ev,Pv=(e,t,n)=>{const r=new Map,o={platform:kv,...n},s={...o.platform,_c:r};return qy(e,t,{...o,platform:s})};var Ov=typeof document<"u",Dv=function(){},os=Ov?w.useLayoutEffect:Dv;function ss(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(!ss(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)&&!ss(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function xu(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function yu(e,t){const n=xu(e);return Math.round(t*n)/n}function Vi(e){const t=m.useRef(e);return os(()=>{t.current=e}),t}function Lv(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]=m.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[p,h]=m.useState(r);ss(p,r)||h(r);const[v,g]=m.useState(null),[y,x]=m.useState(null),b=m.useCallback($=>{$!==S.current&&(S.current=$,g($))},[]),C=m.useCallback($=>{$!==E.current&&(E.current=$,x($))},[]),k=s||v,T=i||y,S=m.useRef(null),E=m.useRef(null),A=m.useRef(d),R=l!=null,D=Vi(l),B=Vi(o),q=Vi(c),V=m.useCallback(()=>{if(!S.current||!E.current)return;const $={placement:t,strategy:n,middleware:p};B.current&&($.platform=B.current),Pv(S.current,E.current,$).then(P=>{const H={...P,isPositioned:q.current!==!1};j.current&&!ss(A.current,H)&&(A.current=H,Eo.flushSync(()=>{f(H)}))})},[p,t,n,B,q]);os(()=>{c===!1&&A.current.isPositioned&&(A.current.isPositioned=!1,f($=>({...$,isPositioned:!1})))},[c]);const j=m.useRef(!1);os(()=>(j.current=!0,()=>{j.current=!1}),[]),os(()=>{if(k&&(S.current=k),T&&(E.current=T),k&&T){if(D.current)return D.current(k,T,V);V()}},[k,T,V,D,R]);const _=m.useMemo(()=>({reference:S,floating:E,setReference:b,setFloating:C}),[b,C]),N=m.useMemo(()=>({reference:k,floating:T}),[k,T]),z=m.useMemo(()=>{const $={position:n,left:0,top:0};if(!N.floating)return $;const P=yu(N.floating,d.x),H=yu(N.floating,d.y);return a?{...$,transform:"translate("+P+"px, "+H+"px)",...xu(N.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:P,top:H}},[n,a,N.floating,d.x,d.y]);return m.useMemo(()=>({...d,update:V,refs:_,elements:N,floatingStyles:z}),[d,V,_,N,z])}const $v=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?gu({element:r.current,padding:o}).fn(n):{}:r?gu({element:r,padding:o}).fn(n):{}}}},Fv=(e,t)=>({...Nv(e),options:[e,t]}),Bv=(e,t)=>({...Av(e),options:[e,t]}),zv=(e,t)=>({...Rv(e),options:[e,t]}),Uv=(e,t)=>({...jv(e),options:[e,t]}),Hv=(e,t)=>({..._v(e),options:[e,t]}),Wv=(e,t)=>({...Mv(e),options:[e,t]}),Vv=(e,t)=>({...$v(e),options:[e,t]});var Kv="Arrow",vu=m.forwardRef((e,t)=>{const{children:n,width:r=10,height:o=5,...s}=e;return u.jsx(Ee.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"})})});vu.displayName=Kv;var qv=vu;function bu(e){const[t,n]=m.useState(void 0);return It(()=>{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 Ki="Popper",[wu,is]=kn(Ki),[Gv,Su]=wu(Ki),Cu=e=>{const{__scopePopper:t,children:n}=e,[r,o]=m.useState(null);return u.jsx(Gv,{scope:t,anchor:r,onAnchorChange:o,children:n})};Cu.displayName=Ki;var Tu="PopperAnchor",ku=m.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...o}=e,s=Su(Tu,n),i=m.useRef(null),a=Ve(t,i),l=m.useRef(null);return m.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(Ee.div,{...o,ref:a})});ku.displayName=Tu;var qi="PopperContent",[Yv,Xv]=wu(qi),Eu=m.forwardRef((e,t)=>{var G,O,W,F,ee,Z;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:v,...g}=e,y=Su(qi,n),[x,b]=m.useState(null),C=Ve(t,ye=>b(ye)),[k,T]=m.useState(null),S=bu(k),E=(S==null?void 0:S.width)??0,A=(S==null?void 0:S.height)??0,R=r+(s!=="center"?"-"+s:""),D=typeof d=="number"?d:{top:0,right:0,bottom:0,left:0,...d},B=Array.isArray(c)?c:[c],q=B.length>0,V={padding:D,boundary:B.filter(Zv),altBoundary:q},{refs:j,floatingStyles:_,placement:N,isPositioned:z,middlewareData:$}=Lv({strategy:"fixed",placement:R,whileElementsMounted:(...ye)=>Iv(...ye,{animationFrame:h==="always"}),elements:{reference:y.anchor},middleware:[Fv({mainAxis:o+A,alignmentAxis:i}),l&&Bv({mainAxis:!0,crossAxis:!1,limiter:f==="partial"?zv():void 0,...V}),l&&Uv({...V}),Hv({...V,apply:({elements:ye,rects:fe,availableWidth:oe,availableHeight:xe})=>{const{width:Se,height:$e}=fe.reference,_e=ye.floating.style;_e.setProperty("--radix-popper-available-width",`${oe}px`),_e.setProperty("--radix-popper-available-height",`${xe}px`),_e.setProperty("--radix-popper-anchor-width",`${Se}px`),_e.setProperty("--radix-popper-anchor-height",`${$e}px`)}}),k&&Vv({element:k,padding:a}),Qv({arrowWidth:E,arrowHeight:A}),p&&Wv({strategy:"referenceHidden",...V})]}),[P,H]=Au(N),Q=Nt(v);It(()=>{z&&(Q==null||Q())},[z,Q]);const M=(G=$.arrow)==null?void 0:G.x,Y=(O=$.arrow)==null?void 0:O.y,ae=((W=$.arrow)==null?void 0:W.centerOffset)!==0,[ne,ce]=m.useState();return It(()=>{x&&ce(window.getComputedStyle(x).zIndex)},[x]),u.jsx("div",{ref:j.setFloating,"data-radix-popper-content-wrapper":"",style:{..._,transform:z?_.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:ne,"--radix-popper-transform-origin":[(F=$.transformOrigin)==null?void 0:F.x,(ee=$.transformOrigin)==null?void 0:ee.y].join(" "),...((Z=$.hide)==null?void 0:Z.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:u.jsx(Yv,{scope:n,placedSide:P,onArrowChange:T,arrowX:M,arrowY:Y,shouldHideArrow:ae,children:u.jsx(Ee.div,{"data-side":P,"data-align":H,...g,ref:C,style:{...g.style,animation:z?void 0:"none"}})})})});Eu.displayName=qi;var Iu="PopperArrow",Jv={top:"bottom",right:"left",bottom:"top",left:"right"},Nu=m.forwardRef(function(t,n){const{__scopePopper:r,...o}=t,s=Xv(Iu,r),i=Jv[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(qv,{...o,ref:n,style:{...o.style,display:"block"}})})});Nu.displayName=Iu;function Zv(e){return e!==null}var Qv=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]=Au(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 v="",g="";return c==="bottom"?(v=i?f:`${p}px`,g=`${-l}px`):c==="top"?(v=i?f:`${p}px`,g=`${r.floating.height+l}px`):c==="right"?(v=`${-l}px`,g=i?f:`${h}px`):c==="left"&&(v=`${r.floating.width+l}px`,g=i?f:`${h}px`),{data:{x:v,y:g}}}});function Au(e){const[t,n="center"]=e.split("-");return[t,n]}var ju=Cu,_u=ku,Mu=Eu,Ru=Nu,eb="Portal",as=m.forwardRef((e,t)=>{var a;const{container:n,...r}=e,[o,s]=m.useState(!1);It(()=>s(!0),[]);const i=n||o&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?li.createPortal(u.jsx(Ee.div,{...r,ref:t}),i):null});as.displayName=eb;function tb(e,t){return m.useReducer((n,r)=>t[n][r]??n,e)}var Zt=e=>{const{present:t,children:n}=e,r=nb(t),o=typeof n=="function"?n({present:r.isPresent}):m.Children.only(n),s=Ve(r.ref,rb(o));return typeof n=="function"||r.isPresent?m.cloneElement(o,{ref:s}):null};Zt.displayName="Presence";function nb(e){const[t,n]=m.useState(),r=m.useRef(null),o=m.useRef(e),s=m.useRef("none"),i=e?"mounted":"unmounted",[a,l]=tb(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return m.useEffect(()=>{const c=ls(r.current);s.current=a==="mounted"?c:"none"},[a]),It(()=>{const c=r.current,d=o.current;if(d!==e){const p=s.current,h=ls(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]),It(()=>{if(t){let c;const d=t.ownerDocument.defaultView??window,f=h=>{const g=ls(r.current).includes(CSS.escape(h.animationName));if(h.target===t&&g&&(l("ANIMATION_END"),!o.current)){const y=t.style.animationFillMode;t.style.animationFillMode="forwards",c=d.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=y)})}},p=h=>{h.target===t&&(s.current=ls(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:m.useCallback(c=>{r.current=c?getComputedStyle(c):null,n(c)},[])}}function ls(e){return(e==null?void 0:e.animationName)||"none"}function rb(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 Gi="rovingFocusGroup.onEntryFocus",ob={bubbles:!1,cancelable:!0},Yr="RovingFocusGroup",[Yi,Pu,sb]=Ai(Yr),[ib,Ou]=kn(Yr,[sb]),[ab,lb]=ib(Yr),Du=m.forwardRef((e,t)=>u.jsx(Yi.Provider,{scope:e.__scopeRovingFocusGroup,children:u.jsx(Yi.Slot,{scope:e.__scopeRovingFocusGroup,children:u.jsx(cb,{...e,ref:t})})}));Du.displayName=Yr;var cb=m.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=m.useRef(null),h=Ve(t,p),v=qo(s),[g,y]=yr({prop:i,defaultProp:a??null,onChange:l,caller:Yr}),[x,b]=m.useState(!1),C=Nt(c),k=Pu(n),T=m.useRef(!1),[S,E]=m.useState(0);return m.useEffect(()=>{const A=p.current;if(A)return A.addEventListener(Gi,C),()=>A.removeEventListener(Gi,C)},[C]),u.jsx(ab,{scope:n,orientation:r,dir:v,loop:o,currentTabStopId:g,onItemFocus:m.useCallback(A=>y(A),[y]),onItemShiftTab:m.useCallback(()=>b(!0),[]),onFocusableItemAdd:m.useCallback(()=>E(A=>A+1),[]),onFocusableItemRemove:m.useCallback(()=>E(A=>A-1),[]),children:u.jsx(Ee.div,{tabIndex:x||S===0?-1:0,"data-orientation":r,...f,ref:h,style:{outline:"none",...e.style},onMouseDown:me(e.onMouseDown,()=>{T.current=!0}),onFocus:me(e.onFocus,A=>{const R=!T.current;if(A.target===A.currentTarget&&R&&!x){const D=new CustomEvent(Gi,ob);if(A.currentTarget.dispatchEvent(D),!D.defaultPrevented){const B=k().filter(N=>N.focusable),q=B.find(N=>N.active),V=B.find(N=>N.id===g),_=[q,V,...B].filter(Boolean).map(N=>N.ref.current);Fu(_,d)}}T.current=!1}),onBlur:me(e.onBlur,()=>b(!1))})})}),Lu="RovingFocusGroupItem",$u=m.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:o=!1,tabStopId:s,children:i,...a}=e,l=$t(),c=s||l,d=lb(Lu,n),f=d.currentTabStopId===c,p=Pu(n),{onFocusableItemAdd:h,onFocusableItemRemove:v,currentTabStopId:g}=d;return m.useEffect(()=>{if(r)return h(),()=>v()},[r,h,v]),u.jsx(Yi.ItemSlot,{scope:n,id:c,focusable:r,active:o,children:u.jsx(Ee.span,{tabIndex:f?0:-1,"data-orientation":d.orientation,...a,ref:t,onMouseDown:me(e.onMouseDown,y=>{r?d.onItemFocus(c):y.preventDefault()}),onFocus:me(e.onFocus,()=>d.onItemFocus(c)),onKeyDown:me(e.onKeyDown,y=>{if(y.key==="Tab"&&y.shiftKey){d.onItemShiftTab();return}if(y.target!==y.currentTarget)return;const x=fb(y,d.orientation,d.dir);if(x!==void 0){if(y.metaKey||y.ctrlKey||y.altKey||y.shiftKey)return;y.preventDefault();let C=p().filter(k=>k.focusable).map(k=>k.ref.current);if(x==="last")C.reverse();else if(x==="prev"||x==="next"){x==="prev"&&C.reverse();const k=C.indexOf(y.currentTarget);C=d.loop?pb(C,k+1):C.slice(k+1)}setTimeout(()=>Fu(C))}}),children:typeof i=="function"?i({isCurrentTabStop:f,hasTabStop:g!=null}):i})})});$u.displayName=Lu;var ub={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function db(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function fb(e,t,n){const r=db(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return ub[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 pb(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var hb=Du,mb=$u,gb=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},Cr=new WeakMap,cs=new WeakMap,us={},Xi=0,Bu=function(e){return e&&(e.host||Bu(e.parentNode))},xb=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=Bu(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})},yb=function(e,t,n,r){var o=xb(t,Array.isArray(e)?e:[e]);us[n]||(us[n]=new WeakMap);var s=us[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),v=h!==null&&h!=="false",g=(Cr.get(p)||0)+1,y=(s.get(p)||0)+1;Cr.set(p,g),s.set(p,y),i.push(p),g===1&&v&&cs.set(p,!0),y===1&&p.setAttribute(n,"true"),v||p.setAttribute(r,"true")}catch(x){console.error("aria-hidden: cannot operate on ",p,x)}})};return d(t),a.clear(),Xi++,function(){i.forEach(function(f){var p=Cr.get(f)-1,h=s.get(f)-1;Cr.set(f,p),s.set(f,h),p||(cs.has(f)||f.removeAttribute(r),cs.delete(f)),h||f.removeAttribute(n)}),Xi--,Xi||(Cr=new WeakMap,Cr=new WeakMap,cs=new WeakMap,us={})}},Ji=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),o=gb(e);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live], script"))),yb(r,o,n,"aria-hidden")):function(){return null}},yn=function(){return yn=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},yn.apply(this,arguments)};function zu(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 vb(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 ds="right-scroll-bar-position",fs="width-before-scroll-bar",bb="with-scroll-bars-hidden",wb="--removed-body-scroll-bar-size";function Zi(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function Sb(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 Cb=typeof window<"u"?m.useLayoutEffect:m.useEffect,Uu=new WeakMap;function Tb(e,t){var n=Sb(null,function(r){return e.forEach(function(o){return Zi(o,r)})});return Cb(function(){var r=Uu.get(n);if(r){var o=new Set(r),s=new Set(e),i=n.current;o.forEach(function(a){s.has(a)||Zi(a,null)}),s.forEach(function(a){o.has(a)||Zi(a,i)})}Uu.set(n,e)},[e]),n}function kb(e){return e}function Eb(e,t){t===void 0&&(t=kb);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 Ib(e){e===void 0&&(e={});var t=Eb(null);return t.options=yn({async:!0,ssr:!1},e),t}var Hu=function(e){var t=e.sideCar,n=zu(e,["sideCar"]);if(!t)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=t.read();if(!r)throw new Error("Sidecar medium not found");return m.createElement(r,yn({},n))};Hu.isSideCarExport=!0;function Nb(e,t){return e.useMedium(t),Hu}var Wu=Ib(),Qi=function(){},ps=m.forwardRef(function(e,t){var n=m.useRef(null),r=m.useState({onScrollCapture:Qi,onWheelCapture:Qi,onTouchMoveCapture:Qi}),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,v=e.noIsolation,g=e.inert,y=e.allowPinchZoom,x=e.as,b=x===void 0?"div":x,C=e.gapMode,k=zu(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),T=p,S=Tb([n,t]),E=yn(yn({},k),o);return m.createElement(m.Fragment,null,d&&m.createElement(T,{sideCar:Wu,removeScrollBar:c,shards:f,noRelative:h,noIsolation:v,inert:g,setCallbacks:s,allowPinchZoom:!!y,lockRef:n,gapMode:C}),i?m.cloneElement(m.Children.only(a),yn(yn({},E),{ref:S})):m.createElement(b,yn({},E,{className:l,ref:S}),a))});ps.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},ps.classNames={fullWidth:fs,zeroRight:ds};var Ab=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function jb(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=Ab();return t&&e.setAttribute("nonce",t),e}function _b(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function Mb(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var Rb=function(){var e=0,t=null;return{add:function(n){e==0&&(t=jb())&&(_b(t,n),Mb(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},Pb=function(){var e=Rb();return function(t,n){m.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},Vu=function(){var e=Pb(),t=function(n){var r=n.styles,o=n.dynamic;return e(r,o),null};return t},Ob={left:0,top:0,right:0,gap:0},ea=function(e){return parseInt(e||"",10)||0},Db=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[ea(n),ea(r),ea(o)]},Lb=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return Ob;var t=Db(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])}},$b=Vu(),Tr="data-scroll-locked",Fb=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 ye=Le.slice(0,X);Le=Le.slice(X+2);const Ce=Jx(ye);if(!Ce)continue;let Je;try{Je=JSON.parse(Ce)}catch{console.debug("[use-chat] malformed SSE:",Ce.slice(0,200));continue}const Be=Xx(Je)?Je.data:Je;At=Date.now();const xt=Be.seq;if(xt!==void 0){if(xt<=ot){console.debug("[use-chat] drop duplicate/out-of-order event",{seq:xt,lastProcessedSeq:ot,type:Be.type});continue}ot>0&&xt>ot+1&&((D=I==null?void 0:I.onGap)==null||D.call(I,{from:ot,to:xt})),ot=xt,S.current=xt,y(xt)}if(Be.type==="checkpoint")E.current=Be.checkpointId??null,j.current=Be.checkpointNs??null,v(Be.checkpointId??null);else if(Be.type==="state_history"){R.current=Be;try{const jt=fr(Be).latest;jt&&(E.current=jt.checkpointId??null,j.current=jt.checkpointNs??null,v(jt.checkpointId??null))}catch(nt){console.warn("[use-chat] Failed to hydrate state_history payload",nt)}}try{M==null||M(Be)}catch(nt){console.error("[use-chat] Error in onEvent callback:",nt,"for event:",Be.type)}if(Be.type==="message.delta"){const nt=Be.delta.filter(jt=>jt.type==="text").map(jt=>jt.text).join("");nt&&e.autoAppendAssistant!==!1&&(ct.push(nt),kt())}else if(Be.type==="heartbeat"){console.debug("[use-chat] heartbeat received");try{(V=I==null?void 0:I.onHeartbeat)==null||V.call(I,Be)}catch(nt){console.warn("[use-chat] heartbeat callback failed",nt)}}else if(pt!==null&&cancelAnimationFrame(pt),mt(),Be.type==="checkpoint")v(Be.checkpointId);else if(Be.type==="error"){const nt=Be;if(d(nt.message),L="error",A=nt.message,nt.error_type==="auth_error"||nt.code==="TOKEN_EXPIRED"||((U=nt.message)==null?void 0:U.includes("token"))||((Z=nt.message)==null?void 0:Z.includes("401"))||((J=nt.message)==null?void 0:J.includes("unauthorized"))||((ge=nt.message)==null?void 0:ge.includes("Unauthorized"))){console.error("[use-chat] Auth error detected:",nt.message);try{(ce=I==null?void 0:I.onAuthError)==null||ce.call(I,nt.message)}catch(yo){console.warn("[use-chat] onAuthError handler failed",yo)}z.abort()}}}}mt(),L===null&&!z.signal.aborted&&(L="complete")}catch(W){if(W.name==="AbortError")L=L??"aborted";else{const le=W.message||String(W);L="error",A=le,d(le),(ne=I==null?void 0:I.onError)==null||ne.call(I,le)}}finally{try{await lt.cancel()}catch{}finally{(pe=lt.releaseLock)==null||pe.call(lt)}pt!==null&&typeof window<"u"&&window.cancelAnimationFrame(pt),clearInterval(Fe)}}catch(He){if(He.name==="AbortError")L=L??"aborted";else{const qe=He.message||String(He);L="error",A=qe,d(qe),(be=I==null?void 0:I.onError)==null||be.call(I,qe),$||((De=I==null?void 0:I.onConnectionError)==null||De.call(I,qe),$=!0)}}finally{const He=S.current,qe=E.current,rt=j.current,Ge=R.current,Qe=L??(z.signal.aborted?"aborted":A?"error":"complete");try{(je=I==null?void 0:I.onClosed)==null||je.call(I,{reason:Qe,lastSeq:He,lastCheckpointId:qe,lastCheckpointNs:rt,lastStateHistory:Ge,error:A})}catch(lt){console.warn("[use-chat] onClosed callback failed",lt)}l(!1),b(!1),C.current=null,S.current=0,y(0),T.current=null}})(),{close:()=>z.abort()}},[t,n,r,e.autoAppendAssistant]);return w.useEffect(()=>()=>{var P;k.current=!1,(P=C.current)==null||P.abort()},[]),{isStreaming:a,error:c,assistantText:f,lastCheckpointId:p,lastSeq:g,connected:x,stream:K,stop:q,clear:B,setToken:O}}function Xx(e){return!!e&&typeof e=="object"&&e.protocolVersion==="v1"&&"data"in e}function Jx(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 Zx=["message.start","message.delta","message.end"],Qx=["tool.start","tool.end","tool.progress"],ey=["thread_info","checkpoint"],ty=["error","interrupt","heartbeat","state_history","cancelled"],ny=[...Zx,...Qx,...ey,...ty],ry=new Set(ny);function oy(e){if(typeof e!="object"||e===null||typeof e.type!="string")return!1;const t=e.type;return ry.has(t)}const Mc=200;function sy({baseUrl:e,onThreadInfo:t,onMessageEvent:n,onStateHistory:r,onUnhandledEvent:o,onSequenceGap:s,onStreamClosed:i,onConnectionError:a,onAuthError:l,onHeartbeat:c}){const d=w.useRef(null),f=w.useRef(null),h=w.useRef(new Map),p=w.useRef(null),v=w.useRef(null),g=w.useCallback(M=>{try{const I=globalThis.structuredClone;if(typeof I=="function")return I(M)}catch{}try{return JSON.parse(JSON.stringify(M))}catch{return M}},[]),y=w.useCallback((M,I)=>{if(!M)return;const z=h.current.get(M)??[],L=g(I),A=z.length>=Mc?[...z.slice(z.length-Mc+1),L]:[...z,L];h.current.set(M,A)},[g]),x=w.useCallback(M=>{M&&h.current.set(M,[])},[]),b=w.useCallback(M=>{const I=M??f.current;if(!I)return;const z=h.current.get(I);z!=null&&z.length&&z.forEach(L=>{try{n(L)}catch(A){console.error("[useChatStreamingService] Failed to replay buffered event",A)}})},[n]),C=w.useCallback(M=>{f.current=M.threadId,p.current&&(p.current.threadIdGuess=M.threadId),v.current=M,x(M.threadId),console.log("[useChatStreamingService] 🎯 Received thread_info event:",M);try{t(M)}catch(I){console.error("[useChatStreamingService] Error in onThreadInfo handler:",I)}},[x,t]),k=w.useCallback(M=>{try{c==null||c(M)}catch(I){console.error("[useChatStreamingService] Error in onHeartbeat handler:",I)}},[c]),S=w.useCallback(M=>{var L,A,$,H;const I=M;if(I.error_type==="auth_error"||I.code==="TOKEN_EXPIRED"||((L=I.message)==null?void 0:L.includes("token"))||((A=I.message)==null?void 0:A.includes("401"))||(($=I.message)==null?void 0:$.includes("unauthorized"))||((H=I.message)==null?void 0:H.includes("Unauthorized"))){console.error("[useChatStreamingService] Auth error event detected:",I.message);try{l==null||l(I.message)}catch(_){console.warn("[useChatStreamingService] onAuthError handler failed",_)}}},[l]),T=w.useMemo(()=>({thread_info:M=>(C(M),!0),heartbeat:M=>(k(M),!0),error:M=>(S(M),!1)}),[C,k,S]),E=w.useCallback(M=>{var A;const I=M.seq??null;if(I!==null){const $=d.current;if($!==null){if(I<=$)return;I>$+1&&(s==null||s({from:$,to:I}))}d.current=I}const z=T[M.type];if(z&&z(M))return;const L=M.threadId??(M.type==="state_history"?M.threadId:void 0)??f.current??((A=p.current)==null?void 0:A.threadIdGuess)??null;if(M.type==="state_history"){f.current=L??f.current;try{r==null||r(M)}catch($){console.error("[useChatStreamingService] onStateHistory handler failed",$)}}if(oy(M)){M.type==="checkpoint"||M.type==="state_history"?x(L??null):y(L??null,M);try{n(M)}catch($){console.error("[useChatStreamingService] Error in onMessageEvent handler:",$)}return}try{o==null||o(M)}catch($){console.error("[useChatStreamingService] Error in onUnhandledEvent handler:",$)}},[y,x,n,s,r,o,T]),{stream:j,stop:R,isStreaming:O,error:B,setToken:q}=_c({baseUrl:e,token:void 0}),K=w.useCallback((M,I)=>{d.current=null,v.current=null,f.current=M.threadId??null,p.current={request:M,callbacks:I,manualStop:!1,threadIdGuess:M.threadId??null},j(M,E,{onOpen:I==null?void 0:I.onOpen,onError:z=>{var L;(L=I==null?void 0:I.onError)==null||L.call(I,z)},onGap:(I==null?void 0:I.onGap)??s,onConnectionError:z=>{var L;a==null||a(z),(L=I==null?void 0:I.onConnectionError)==null||L.call(I,z)},onAuthError:z=>{var L;l==null||l(z),(L=I==null?void 0:I.onAuthError)==null||L.call(I,z)},onHeartbeat:z=>{var L;try{c==null||c(z)}catch(A){console.warn("[useChatStreamingService] onHeartbeat handler failed",A)}try{(L=I==null?void 0:I.onHeartbeat)==null||L.call(I,z)}catch(A){console.warn("[useChatStreamingService] downstream onHeartbeat handler failed",A)}},onClosed:z=>{var H,_,G,re;const L=((H=p.current)==null?void 0:H.manualStop)??!1,A=f.current??((_=p.current)==null?void 0:_.threadIdGuess)??((G=z.lastStateHistory)==null?void 0:G.threadId)??null;(z.reason==="complete"||z.reason==="aborted"&&L)&&x(A);const $={...z,threadId:A,threadInfo:v.current,manualStop:L};try{i==null||i($)}catch(ee){console.warn("[useChatStreamingService] onStreamClosed handler failed",ee)}try{(re=I==null?void 0:I.onClosed)==null||re.call(I,$)}catch(ee){console.warn("[useChatStreamingService] downstream onClosed handler failed",ee)}p.current&&(p.current=null)}})},[x,E,l,a,c,s,i,j]),P=w.useCallback(()=>{p.current&&(p.current.manualStop=!0),R()},[R]);return w.useMemo(()=>({startStream:K,stop:P,isStreaming:O,error:B,setAuthToken:q,replayBufferedEvents:b}),[K,P,O,B,q,b])}function iy({api:e,seed:t,prepend:n,onError:r,currentThreadId:o,initialThreadId:s=null,initialCheckpointId:i=null,initialCheckpointNs:a=null,autoLoadInitial:l=!0,isStreaming:c,getMessages:d}){const[f,h]=w.useState([]),[p,v]=w.useState([]),[g,y]=w.useState(!1),[x,b]=w.useState(null),[C,k]=w.useState(!1),[S,T]=w.useState(!1),[E,j]=w.useState(!1),[R,O]=w.useState(null),B=w.useRef(o),q=w.useRef(null),K=w.useRef(null),P=w.useRef(null),M=w.useRef(null),I=w.useRef(!1),z=w.useRef(null),L=w.useRef(new Map);w.useEffect(()=>{B.current=o},[o]);const A=w.useCallback(async U=>{var J,ge;if(!U.threadId)return;const Z=U.threadId;(J=U.onStart)==null||J.call(U),U.setLoading(!0);try{await U.action(Z)}catch(ce){if(B.current===Z){const ne=String(ce);(ge=U.handleError)==null||ge.call(U,ne),r==null||r(ne)}throw ce}finally{U.setLoading(!1)}},[r]),$=w.useCallback(async(U,Z)=>{if(!U)return;const J=`${U}:${Z??"latest"}`,ge=L.current.get(J);if(ge)return ge;const ce=A({threadId:U,setLoading:k,onStart:()=>O(null),handleError:ne=>O(ne),action:async ne=>{const pe=await e.getStateHistory({threadId:ne,checkpointId:Z??void 0});if(B.current!==ne){console.log(`[useThreadHistoryState] Thread changed during load (was ${ne}, now ${B.current}), discarding stale data`);return}const{checkpoints:be,timeline:De}=fr(pe),je=be.find(He=>He.messages&&He.messages.length>0)??(Z?be.find(He=>He.checkpointId===Z):null)??be[0];t((je==null?void 0:je.messages)??[],{checkpointId:(je==null?void 0:je.checkpointId)??null,checkpointNs:(je==null?void 0:je.checkpointNs)??null}),v(De),h(be),y(!!(je!=null&&je.nextCursor)),b((je==null?void 0:je.nextCursor)??null)}});L.current.set(J,ce);try{await ce}finally{L.current.delete(J)}return B.current===U&&(z.current=J),ce},[e,t,A]),H=w.useCallback(async(U,Z,J)=>{J!=null&&J.clearProgress&&bc(),M.current=U;try{await $(U,Z)}finally{M.current===U&&(M.current=null)}},[$]),_=w.useCallback(U=>{K.current=U},[]),G=w.useCallback(U=>{P.current=U},[]),re=w.useCallback(U=>{const Z=U.threadId??B.current;if(!Z||B.current&&B.current!==Z)return;const{checkpoints:J,timeline:ge}=fr(U);if(!J.length)return;const ce=J.find(ne=>ne.messages&&ne.messages.length>0)??J.find(ne=>!!ne.checkpointId)??J[0];t((ce==null?void 0:ce.messages)??[],{checkpointId:(ce==null?void 0:ce.checkpointId)??null,checkpointNs:(ce==null?void 0:ce.checkpointNs)??null}),v(ge),h(J),y(!!(ce!=null&&ce.nextCursor)),b((ce==null?void 0:ce.nextCursor)??null),z.current=`${Z}:latest`,K.current=null,P.current=null},[t]),ee=w.useCallback(async(U,Z)=>{bc();const J=B.current;await A({threadId:J,setLoading:j,action:async ge=>{const ce=await e.getStateHistory({threadId:ge,checkpointId:U,checkpointNs:Z??void 0});if(B.current!==ge){console.log(`[useThreadHistoryState] Thread changed during checkpoint navigation (was ${ge}, now ${B.current}), discarding stale data`);return}const{checkpoints:ne,timeline:pe}=fr(ce),be=ne.find(De=>De.checkpointId===U&&(Z?De.checkpointNs===Z:!0));if(!be){console.warn("[useThreadHistoryState] Requested checkpoint not found:",{checkpointId:U,checkpointNs:Z});return}v(pe),h(ne),t(be.messages??[],{checkpointId:be.checkpointId??null,checkpointNs:be.checkpointNs??null})}}).catch(()=>{})},[e,t,A]),ie=w.useCallback((U,Z)=>{t(d(),{checkpointId:U??null,checkpointNs:Z??null})},[d,t]),Y=w.useCallback(async()=>{B.current&&await H(B.current)},[H]),D=w.useCallback(async()=>{const U=B.current;!U||!x||await A({threadId:U,setLoading:T,action:async Z=>{const J=await e.getStateHistory({threadId:Z,checkpointId:x});if(B.current!==Z)return;const{checkpoints:ge}=fr(J);if(ge.length>0){const ce=ge[ge.length-1];n((ce==null?void 0:ce.messages)??[]),y(!!(ce!=null&&ce.nextCursor)),b((ce==null?void 0:ce.nextCursor)??null)}}}).catch(()=>{})},[e,x,r,n,A]);w.useEffect(()=>{if(!l||!o||C||c)return;if(K.current===o){K.current=null,q.current=o;return}if(P.current===o){q.current=o;return}if(M.current===o){M.current=null,q.current=o;return}if(q.current===o)return;q.current=o;const U=!I.current&&!!i&&o===s;let Z;U&&i?(Z=i,I.current=!0,console.log("[useThreadHistoryState] Loading thread with checkpoint:",Z,a?`(ns: ${a})`:"")):console.log("[useThreadHistoryState] Loading thread with latest checkpoint");const J=`${o}:${Z??"latest"}`;z.current!==J&&H(o,Z)},[l,o,i,a,s,C,c,H]);const V=w.useCallback(()=>{h([]),v([]),y(!1),b(null),k(!1),T(!1),j(!1),O(null),K.current=null,P.current=null,q.current=null,z.current=null,M.current=null},[]);return{threadCheckpoints:f,threadTimeline:p,isLoadingThread:C,isHistoryLoading:S,isLoadingCheckpoint:E,threadStateError:R,hasMoreHistory:g,loadThread:H,navigateToCheckpoint:ee,loadOlderMessages:D,setCurrentCheckpointId:ie,returnToLatest:Y,handleStateHistoryEvent:re,markSkipNextLoad:_,markStreamPendingThread:G,resetHistoryState:V}}const ay=["detail","message","error","description","title"];function $o(e){if(!e)return null;if(typeof e=="string"){const t=e.trim();return t.length?t:null}if(Array.isArray(e)){for(const t of e){const n=$o(t);if(n)return n}return null}if(typeof e=="object"){const t=e;for(const n of ay){const r=$o(t[n]);if(r)return r}if("errors"in t){const n=$o(t.errors);if(n)return n}}return null}function ly(e){if(!e)return"Request failed";const t=e.response,n=$o(t==null?void 0:t.data);if(n)return n;if(t!=null&&t.statusText)return t.statusText;if(e instanceof Error&&e.message)return e.message;if(typeof e=="string"){const r=e.trim();if(r.length)return r}return t!=null&&t.status?`Request failed with status code ${t.status}`:"Request failed"}function cy({api:e,initialThreadId:t=null,onError:n,onThreadChange:r,onCurrentThreadDeleted:o}){const[s,i]=w.useState([]),[a,l]=w.useState(t),[c,d]=w.useState(!1),[f,h]=w.useState(null),[p,v]=w.useState([]),[g,y]=w.useState(!1),[,x]=w.useState(null),[b,C]=w.useState([]),[k,S]=w.useState(!1),[,T]=w.useState(null),E=w.useRef(a),j=w.useRef(new Map);w.useEffect(()=>{E.current=a},[a]);const R=w.useCallback(async()=>{d(!0),h(null);try{const A=await e.listThreads();i(A??[])}catch(A){const $=String(A);h($),n==null||n($)}finally{d(!1)}},[e,n]),O=w.useCallback(async()=>{y(!0),x(null);try{const A=await e.listSharedThreads();v(A??[])}catch(A){const $=String(A);x($),n==null||n($)}finally{y(!1)}},[e,n]),B=w.useCallback(async()=>{S(!0),T(null);try{const A=await e.listSmartOrgUsers();C(A??[])}catch(A){const $=String(A);T($),n==null||n($)}finally{S(!1)}},[e,n]);w.useEffect(()=>{R(),B()},[B,R]),w.useEffect(()=>{O()},[O]),w.useEffect(()=>{r==null||r(a)},[a,r]);const q=w.useCallback(async A=>{try{const $=await e.createThread(A);return l($.threadId),await R(),$.threadId}catch($){const H=String($);return n==null||n(H),null}},[e,n,R]),K=w.useCallback(async A=>{const $=s;i(_=>_.filter(G=>G.threadId!==A));const H=new AbortController;j.current.set(A,H);try{await e.deleteThread(A),E.current===A&&(l(null),o==null||o())}catch(_){i($);const G=String(_);n==null||n(G)}finally{j.current.delete(A)}},[e,o,n,s]),P=w.useCallback(async(A,$)=>{try{await e.updateThread(A,$),await R()}catch(H){n==null||n(String(H))}},[e,n,R]),M=w.useCallback(async(A,$)=>{try{await e.shareThread(A,$),await O()}catch(H){const _=ly(H);throw n==null||n(_),new Error(_)}},[e,n,O]),I=w.useCallback(async(A,$)=>{try{await e.unshareThread(A,$),await O()}catch(H){const _=String(H);throw n==null||n(_),H}},[e,n,O]),z=w.useMemo(()=>({createThread:q,deleteThread:K,renameThread:P,refreshThreads:R,refreshSharedThreads:O,refreshSmartOrgUsers:B,shareThread:M,unshareThread:I}),[q,K,P,R,O,B,M,I]),L=w.useCallback(A=>{if(!(A!=null&&A.threadId))return;const $={threadId:A.threadId,title:A.title||`Thread ${A.threadId.slice(0,8)}`,createdAt:A.createdAt||new Date().toISOString(),updatedAt:A.updatedAt||new Date().toISOString(),messageCount:A.messageCount??1};i(H=>{let _=!1;const G=H.map(re=>re.threadId===$.threadId?(_=!0,console.debug("[useThreadsState] thread_info: updating existing thread",$.threadId),{...re,title:$.title??re.title,updatedAt:$.updatedAt??re.updatedAt,messageCount:$.messageCount??re.messageCount}):re);return _?G:(console.debug("[useThreadsState] thread_info: adding thread to list",$.threadId),[$,...H])})},[]);return{threads:s,currentThreadId:a,currentThreadIdRef:E,setCurrentThreadId:l,isLoadingThreads:c,threadsError:f,sharedThreads:p,isLoadingSharedThreads:g,smartOrgUsers:b,isLoadingSmartOrgUsers:k,actions:z,addThreadFromEvent:L}}const Rc=w.createContext(null),Pc=w.createContext(null),Oc=w.createContext(null);w.createContext(!1);function uy({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}=wi(),f=w.useMemo(()=>Cn(d),[d]),{state:h,seed:p,prepend:v,pushUser:g,onEvent:y}=Ac(),{threads:x,currentThreadId:b,setCurrentThreadId:C,currentThreadIdRef:k,isLoadingThreads:S,threadsError:T,sharedThreads:E,isLoadingSharedThreads:j,smartOrgUsers:R,isLoadingSmartOrgUsers:O,actions:B,addThreadFromEvent:q}=cy({api:c,initialThreadId:t,onError:s,onThreadChange:a,onCurrentThreadDeleted:()=>p([],{})}),[K,P]=w.useState(!1),M=w.useCallback(()=>h.messages,[h.messages]),{threadCheckpoints:I,threadTimeline:z,isLoadingThread:L,isHistoryLoading:A,isLoadingCheckpoint:$,threadStateError:H,hasMoreHistory:_,loadThread:G,navigateToCheckpoint:re,loadOlderMessages:ee,setCurrentCheckpointId:ie,returnToLatest:Y,handleStateHistoryEvent:D,markSkipNextLoad:V,markStreamPendingThread:U,resetHistoryState:Z}=iy({api:c,seed:p,prepend:v,onError:s,currentThreadId:b,initialThreadId:t,initialCheckpointId:n,initialCheckpointNs:r,autoLoadInitial:o,isStreaming:K,getMessages:M}),J=w.useMemo(()=>cx(I),[I]),ge=w.useCallback(Re=>{console.log("[ChatSessionProvider] 🎯 Received thread_info:",Re.threadId),q(Re),k.current!==Re.threadId&&((Re.created??!k.current)&&V(Re.threadId),U(Re.threadId),console.log("[ChatSessionProvider] thread_info: marking to skip auto-load for new thread"),C(Re.threadId))},[q,V,U]),{startStream:ce,stop:ne,isStreaming:pe,error:be,setAuthToken:De}=sy({baseUrl:f,onThreadInfo:ge,onMessageEvent:y,onStateHistory:D,onUnhandledEvent:Re=>{console.warn("[ChatSessionProvider] Unhandled event:",Re.type)},onAuthError:i,onConnectionError:l});w.useEffect(()=>{P(pe)},[pe]);const je=w.useCallback(async()=>{p([],{}),C(null),ne(),Z();try{await c.getAgent("default")}catch(Re){console.warn("[ChatSessionProvider] Failed to refetch agent after clearing thread:",Re)}},[p,ne,c,Z]),He=w.useCallback(async(Re,Le,ct)=>{const ot=k.current;if(!ot)throw new Error("No active thread to handle interrupt");const pt=Le?ct??!0:!1;try{const mt={threadId:ot,checkpointId:h.lastCheckpointId??void 0,checkpointNs:h.lastCheckpointNs??void 0,command:{kind:"resume",value:pt}};ce(mt)}catch(mt){throw console.error(`[ChatSessionProvider] Failed to handle interrupt ${Re}:`,mt),mt}},[h.lastCheckpointId,h.lastCheckpointNs,ce]),qe=w.useCallback(async(Re,Le)=>{let ct=k.current;const ot=(Re==null?void 0:Re.text)??"",pt=(Re==null?void 0:Re.attachments)??[],mt=(ot==null?void 0:ot.trim())??"",kt={...(Re==null?void 0:Re.payload)??{}},At=Array.isArray(kt.messages)?kt.messages:void 0;At&&delete kt.messages;const Fe=!!(At&&At.length);if(!ct&&!mt&&pt.length===0&&!Fe)return;if(!ct){const Je=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);ct=`${Je}${Be}`,V(ct),C(ct)}const{contentParts:fn,filesInfo:W}=await ix(c,pt),le=[...fn];mt&&le.push({type:"text",text:ot});const Pe=Le==null?void 0:Le.originalMessageId,wt=!!(Le!=null&&Le.edit&&Pe),We=!Fe&&le.length>0;let Tt=null;We&&(Tt={id:wt?Pe:`msg-${Date.now()}`,role:"user",content:le,createdAt:new Date().toISOString()},wt||g(Tt));const X=Fe?At:Tt?[Tt]:[],ye={...kt,...W.length?{files_info:W}:{}};X.length?ye.messages=X:"messages"in ye||(ye.messages=[]);const Ce={threadId:ct,payload:ye,checkpointId:(Le==null?void 0:Le.checkpointId)??h.lastCheckpointId??void 0,checkpointNs:(Le==null?void 0:Le.checkpointNs)??h.lastCheckpointNs??void 0,edit:!!(Le!=null&&Le.edit),timelineCheckpoints:z};ce(Ce)},[c,g,h,ce,z]),rt=w.useMemo(()=>({threads:x,currentThreadId:b,setCurrentThreadId:C,isLoading:S,error:T,sharedThreads:E,isLoadingSharedThreads:j,smartOrgUsers:R,isLoadingSmartOrgUsers:O,actions:B}),[x,b,C,S,T,E,j,R,O,B]),Ge=w.useMemo(()=>{const Re=h.assemblingId??null;return Re?{assemblingMessageId:Re}:null},[h.assemblingId]),Qe=w.useMemo(()=>({threadId:b,messages:h.messages,interrupt:null,checkpoint:{id:h.lastCheckpointId??null,namespace:h.lastCheckpointNs??null},checkpoints:I,timelineCheckpoints:z,metadata:Ge,isLoading:L,isHistoryLoading:A,isLoadingCheckpoint:$,error:H,hasMore:_,loadOlder:ee,clearState:je,navigateToCheckpoint:re,setCurrentCheckpointId:ie,returnToLatest:Y,loadThread:G,clearThread:je,respondToInterrupt:He,messagePreviews:J}),[b,h,I,z,L,A,$,H,_,ee,je,re,ie,Y,G,He,J,Ge]),lt=w.useMemo(()=>({isStreaming:pe,error:be,connectionState:pe?"connected":"idle",submit:qe,send:qe,stop:ne,setAuthToken:De}),[pe,be,qe,ne,De]);return u.jsx(Rc.Provider,{value:rt,children:u.jsx(Pc.Provider,{value:Qe,children:u.jsx(Oc.Provider,{value:lt,children:e})})})}function Fo(){const e=w.useContext(Rc);if(!e)throw new Error("useThreads must be used within ChatSessionProvider");return e}function Bo(){const e=w.useContext(Pc);if(!e)throw new Error("useThreadState must be used within ChatSessionProvider");return e}function Dc(){const e=w.useContext(Oc);if(!e)throw new Error("useStream must be used within ChatSessionProvider");return e}function zo({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(ox,{apiConfig:t,children:u.jsx(uy,{initialThreadId:n,initialCheckpointId:r,initialCheckpointNs:o,autoLoadInitial:s,onError:a,onAuthError:l,onConnectionError:i,onThreadChange:c,children:e})})}function oe(...e){return _m.twMerge(jm.clsx(e))}const dy=bo.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"}}),et=m.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?Wn.Slot:"button";return u.jsx(i,{className:oe(dy({variant:t,size:n,className:e})),ref:s,...o})});et.displayName="Button";const Lc=m.forwardRef(({className:e,...t},n)=>u.jsx("textarea",{className:oe("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",e),ref:n,...t}));Lc.displayName="Textarea";function $c({initialValue:e="",editingMessageId:t=null,placeholder:n="Type your message...",isStreaming:r=!1,disabled:o=!1,maxLength:s=2e4,value:i,onValueChange:a,onSend:l,onCancelEdit:c,onStop:d,className:f="",textareaClassName:h="",allowEmptySend:p=!1}){const v=i!==void 0,[g,y]=w.useState(e),x=(v?i:g)??"",[b,C]=w.useTransition(),k=w.useRef(null),S=w.useRef(0),T=w.useRef(null);w.useEffect(()=>{v||(y(e??""),T.current=null,k.current&&(k.current.style.height="auto",k.current.style.height=`${k.current.scrollHeight}px`))},[e,t,v]);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 j=w.useCallback((M,{fromUser:I})=>{v||y(M),I&&(a==null||a(M))},[v,a]),R=w.useCallback(async M=>{M&&M.preventDefault();const I=(x??"").trim();if(!I&&!p)return;const z=++S.current;T.current={id:z,shouldClear:!0},C(()=>{var L,A,$;try{const H=l(I);H&&typeof H.then=="function"?H.then(()=>{var _,G;((_=T.current)==null?void 0:_.id)===z&&T.current.shouldClear&&(v||(y(""),k.current&&(k.current.style.height="auto"),a==null||a(""))),((G=T.current)==null?void 0:G.id)===z&&(T.current=null)}).catch(()=>{var _;((_=T.current)==null?void 0:_.id)===z&&(T.current=null)}):(((L=T.current)==null?void 0:L.id)===z&&T.current.shouldClear&&(v||(y(""),k.current&&(k.current.style.height="auto"),a==null||a(""))),((A=T.current)==null?void 0:A.id)===z&&(T.current=null))}catch{(($=T.current)==null?void 0:$.id)===z&&(T.current=null)}})},[x,l,p,v,a]),O=w.useCallback(M=>{const I=M.target.value;j(I,{fromUser:!0}),T.current&&(T.current.shouldClear=!1),k.current&&(k.current.style.height="auto",k.current.style.height=`${k.current.scrollHeight}px`)},[j]),B=w.useCallback(M=>{M.key==="Enter"&&!M.shiftKey?(M.preventDefault(),R()):M.key==="Escape"&&t&&(M.preventDefault(),c==null||c())},[R,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))]":""} ${h}`;return u.jsx("form",{onSubmit:M=>void R(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(Lc,{ref:k,value:x,onChange:O,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(et,{type:"button",onClick:()=>{d==null||d()},size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",disabled:o||!d,children:u.jsx(ae.Square,{size:16})}):u.jsx(et,{type:"submit",size:"icon",className:"shrink-0",title:t?"Save changes":"Send message",disabled:o||!x.trim()&&!p||b,children:u.jsx(ae.Send,{size:16})})})]})})}const fy=w.memo($c);function he(e,t,{checkForDefaultPrevented:n=!0}={}){return function(o){if(e==null||e(o),n===!1||!o.defaultPrevented)return t==null?void 0:t(o)}}function Fc(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function An(...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 Ve(...e){return m.useCallback(An(...e),e)}function hy(e,t){const n=m.createContext(t),r=s=>{const{children:i,...a}=s,l=m.useMemo(()=>a,Object.values(a));return u.jsx(n.Provider,{value:l,children:i})};r.displayName=e+"Provider";function o(s){const i=m.useContext(n);if(i)return i;if(t!==void 0)return t;throw new Error(`\`${s}\` must be used within \`${e}\``)}return[r,o]}function Tn(e,t=[]){let n=[];function r(s,i){const a=m.createContext(i),l=n.length;n=[...n,i];const c=f=>{var x;const{scope:h,children:p,...v}=f,g=((x=h==null?void 0:h[e])==null?void 0:x[l])||a,y=m.useMemo(()=>v,Object.values(v));return u.jsx(g.Provider,{value:y,children:p})};c.displayName=s+"Provider";function d(f,h){var g;const p=((g=h==null?void 0:h[e])==null?void 0:g[l])||a,v=m.useContext(p);if(v)return v;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=>m.createContext(i));return function(a){const l=(a==null?void 0:a[e])||s;return m.useMemo(()=>({[`__scope${e}`]:{...a,[e]:l}}),[a,l])}};return o.scopeName=e,[r,py(o,...t)]}function py(...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 m.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}var It=globalThis!=null&&globalThis.document?m.useLayoutEffect:()=>{},my=m[" useInsertionEffect ".trim().toString()]||It;function pr({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=gy({defaultProp:t,onChange:n}),a=e!==void 0,l=a?e:o;{const d=m.useRef(e!==void 0);m.useEffect(()=>{const f=d.current;f!==a&&console.warn(`${r} is changing from ${f?"controlled":"uncontrolled"} to ${a?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),d.current=a},[a,r])}const c=m.useCallback(d=>{var f;if(a){const h=xy(d)?d(e):d;h!==e&&((f=i.current)==null||f.call(i,h))}else s(d)},[a,e,s,i]);return[l,c]}function gy({defaultProp:e,onChange:t}){const[n,r]=m.useState(e),o=m.useRef(n),s=m.useRef(t);return my(()=>{s.current=t},[t]),m.useEffect(()=>{var i;o.current!==n&&((i=s.current)==null||i.call(s,n),o.current=n)},[n,o]),[n,r,s]}function xy(e){return typeof e=="function"}var yy=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Se=yy.reduce((e,t)=>{const n=Wn.createSlot(`Primitive.${t}`),r=m.forwardRef((o,s)=>{const{asChild:i,...a}=o,l=i?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),u.jsx(l,{...a,ref:s})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function Bc(e,t){e&&wo.flushSync(()=>e.dispatchEvent(t))}function Ei(e){const t=e+"CollectionProvider",[n,r]=Tn(t),[o,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),i=g=>{const{scope:y,children:x}=g,b=w.useRef(null),C=w.useRef(new Map).current;return u.jsx(o,{scope:y,itemMap:C,collectionRef:b,children:x})};i.displayName=t;const a=e+"CollectionSlot",l=Wn.createSlot(a),c=w.forwardRef((g,y)=>{const{scope:x,children:b}=g,C=s(a,x),k=Ve(y,C.collectionRef);return u.jsx(l,{ref:k,children:b})});c.displayName=a;const d=e+"CollectionItemSlot",f="data-radix-collection-item",h=Wn.createSlot(d),p=w.forwardRef((g,y)=>{const{scope:x,children:b,...C}=g,k=w.useRef(null),S=Ve(y,k),T=s(d,x);return w.useEffect(()=>(T.itemMap.set(k,{ref:k,...C}),()=>void T.itemMap.delete(k))),u.jsx(h,{[f]:"",ref:S,children:b})});p.displayName=d;function v(g){const y=s(e+"CollectionConsumer",g);return w.useCallback(()=>{const b=y.collectionRef.current;if(!b)return[];const C=Array.from(b.querySelectorAll(`[${f}]`));return Array.from(y.itemMap.values()).sort((T,E)=>C.indexOf(T.ref.current)-C.indexOf(E.ref.current))},[y.collectionRef,y.itemMap])}return[{Provider:i,Slot:c,ItemSlot:p},v,r]}var vy=m.createContext(void 0);function Uo(e){const t=m.useContext(vy);return e||t||"ltr"}function Nt(e){const t=m.useRef(e);return m.useEffect(()=>{t.current=e}),m.useMemo(()=>(...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)},[])}function by(e,t=globalThis==null?void 0:globalThis.document){const n=Nt(e);m.useEffect(()=>{const r=o=>{o.key==="Escape"&&n(o)};return t.addEventListener("keydown",r,{capture:!0}),()=>t.removeEventListener("keydown",r,{capture:!0})},[n,t])}var wy="DismissableLayer",Ii="dismissableLayer.update",Sy="dismissableLayer.pointerDownOutside",Cy="dismissableLayer.focusOutside",zc,Uc=m.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),Ho=m.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:a,...l}=e,c=m.useContext(Uc),[d,f]=m.useState(null),h=(d==null?void 0:d.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,p]=m.useState({}),v=Ve(t,E=>f(E)),g=Array.from(c.layers),[y]=[...c.layersWithOutsidePointerEventsDisabled].slice(-1),x=g.indexOf(y),b=d?g.indexOf(d):-1,C=c.layersWithOutsidePointerEventsDisabled.size>0,k=b>=x,S=Ey(E=>{const j=E.target,R=[...c.branches].some(O=>O.contains(j));!k||R||(o==null||o(E),i==null||i(E),E.defaultPrevented||a==null||a())},h),T=Iy(E=>{const j=E.target;[...c.branches].some(O=>O.contains(j))||(s==null||s(E),i==null||i(E),E.defaultPrevented||a==null||a())},h);return by(E=>{b===c.layers.size-1&&(r==null||r(E),!E.defaultPrevented&&a&&(E.preventDefault(),a()))},h),m.useEffect(()=>{if(d)return n&&(c.layersWithOutsidePointerEventsDisabled.size===0&&(zc=h.body.style.pointerEvents,h.body.style.pointerEvents="none"),c.layersWithOutsidePointerEventsDisabled.add(d)),c.layers.add(d),Hc(),()=>{n&&c.layersWithOutsidePointerEventsDisabled.size===1&&(h.body.style.pointerEvents=zc)}},[d,h,n,c]),m.useEffect(()=>()=>{d&&(c.layers.delete(d),c.layersWithOutsidePointerEventsDisabled.delete(d),Hc())},[d,c]),m.useEffect(()=>{const E=()=>p({});return document.addEventListener(Ii,E),()=>document.removeEventListener(Ii,E)},[]),u.jsx(Se.div,{...l,ref:v,style:{pointerEvents:C?k?"auto":"none":void 0,...e.style},onFocusCapture:he(e.onFocusCapture,T.onFocusCapture),onBlurCapture:he(e.onBlurCapture,T.onBlurCapture),onPointerDownCapture:he(e.onPointerDownCapture,S.onPointerDownCapture)})});Ho.displayName=wy;var Ty="DismissableLayerBranch",ky=m.forwardRef((e,t)=>{const n=m.useContext(Uc),r=m.useRef(null),o=Ve(t,r);return m.useEffect(()=>{const s=r.current;if(s)return n.branches.add(s),()=>{n.branches.delete(s)}},[n.branches]),u.jsx(Se.div,{...e,ref:o})});ky.displayName=Ty;function Ey(e,t=globalThis==null?void 0:globalThis.document){const n=Nt(e),r=m.useRef(!1),o=m.useRef(()=>{});return m.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let l=function(){Wc(Sy,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 Iy(e,t=globalThis==null?void 0:globalThis.document){const n=Nt(e),r=m.useRef(!1);return m.useEffect(()=>{const o=s=>{s.target&&!r.current&&Wc(Cy,n,{originalEvent:s},{discrete:!1})};return t.addEventListener("focusin",o),()=>t.removeEventListener("focusin",o)},[t,n]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}function Hc(){const e=new CustomEvent(Ii);document.dispatchEvent(e)}function Wc(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?Bc(o,s):o.dispatchEvent(s)}var Ni=0;function Ai(){m.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??Vc()),document.body.insertAdjacentElement("beforeend",e[1]??Vc()),Ni++,()=>{Ni===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),Ni--}},[])}function Vc(){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 ji="focusScope.autoFocusOnMount",_i="focusScope.autoFocusOnUnmount",Kc={bubbles:!1,cancelable:!0},Ny="FocusScope",Wo=m.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:s,...i}=e,[a,l]=m.useState(null),c=Nt(o),d=Nt(s),f=m.useRef(null),h=Ve(t,g=>l(g)),p=m.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;m.useEffect(()=>{if(r){let g=function(C){if(p.paused||!a)return;const k=C.target;a.contains(k)?f.current=k:jn(f.current,{select:!0})},y=function(C){if(p.paused||!a)return;const k=C.relatedTarget;k!==null&&(a.contains(k)||jn(f.current,{select:!0}))},x=function(C){if(document.activeElement===document.body)for(const S of C)S.removedNodes.length>0&&jn(a)};document.addEventListener("focusin",g),document.addEventListener("focusout",y);const b=new MutationObserver(x);return a&&b.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",g),document.removeEventListener("focusout",y),b.disconnect()}}},[r,a,p.paused]),m.useEffect(()=>{if(a){Yc.add(p);const g=document.activeElement;if(!a.contains(g)){const x=new CustomEvent(ji,Kc);a.addEventListener(ji,c),a.dispatchEvent(x),x.defaultPrevented||(Ay(Py(qc(a)),{select:!0}),document.activeElement===g&&jn(a))}return()=>{a.removeEventListener(ji,c),setTimeout(()=>{const x=new CustomEvent(_i,Kc);a.addEventListener(_i,d),a.dispatchEvent(x),x.defaultPrevented||jn(g??document.body,{select:!0}),a.removeEventListener(_i,d),Yc.remove(p)},0)}}},[a,c,d,p]);const v=m.useCallback(g=>{if(!n&&!r||p.paused)return;const y=g.key==="Tab"&&!g.altKey&&!g.ctrlKey&&!g.metaKey,x=document.activeElement;if(y&&x){const b=g.currentTarget,[C,k]=jy(b);C&&k?!g.shiftKey&&x===k?(g.preventDefault(),n&&jn(C,{select:!0})):g.shiftKey&&x===C&&(g.preventDefault(),n&&jn(k,{select:!0})):x===b&&g.preventDefault()}},[n,r,p.paused]);return u.jsx(Se.div,{tabIndex:-1,...i,ref:h,onKeyDown:v})});Wo.displayName=Ny;function Ay(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(jn(r,{select:t}),document.activeElement!==n)return}function jy(e){const t=qc(e),n=Gc(t,e),r=Gc(t.reverse(),e);return[n,r]}function qc(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 Gc(e,t){for(const n of e)if(!_y(n,{upTo:t}))return n}function _y(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 My(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&&My(e)&&t&&e.select()}}var Yc=Ry();function Ry(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=Xc(e,t),e.unshift(t)},remove(t){var n;e=Xc(e,t),(n=e[0])==null||n.resume()}}}function Xc(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function Py(e){return e.filter(t=>t.tagName!=="A")}var Oy=m[" useId ".trim().toString()]||(()=>{}),Dy=0;function $t(e){const[t,n]=m.useState(Oy());return It(()=>{n(r=>r??String(Dy++))},[e]),t?`radix-${t}`:""}const Ly=["top","right","bottom","left"],_n=Math.min,qt=Math.max,Vo=Math.round,Ko=Math.floor,pn=e=>({x:e,y:e}),$y={left:"right",right:"left",bottom:"top",top:"bottom"},Fy={start:"end",end:"start"};function Mi(e,t,n){return qt(e,_n(t,n))}function kn(e,t){return typeof e=="function"?e(t):e}function En(e){return e.split("-")[0]}function mr(e){return e.split("-")[1]}function Ri(e){return e==="x"?"y":"x"}function Pi(e){return e==="y"?"height":"width"}const By=new Set(["top","bottom"]);function mn(e){return By.has(En(e))?"y":"x"}function Oi(e){return Ri(mn(e))}function zy(e,t,n){n===void 0&&(n=!1);const r=mr(e),o=Oi(e),s=Pi(o);let i=o==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(i=qo(i)),[i,qo(i)]}function Uy(e){const t=qo(e);return[Di(e),t,Di(t)]}function Di(e){return e.replace(/start|end/g,t=>Fy[t])}const Jc=["left","right"],Zc=["right","left"],Hy=["top","bottom"],Wy=["bottom","top"];function Vy(e,t,n){switch(e){case"top":case"bottom":return n?t?Zc:Jc:t?Jc:Zc;case"left":case"right":return t?Hy:Wy;default:return[]}}function Ky(e,t,n,r){const o=mr(e);let s=Vy(En(e),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(Di)))),s}function qo(e){return e.replace(/left|right|bottom|top/g,t=>$y[t])}function qy(e){return{top:0,right:0,bottom:0,left:0,...e}}function Qc(e){return typeof e!="number"?qy(e):{top:e,right:e,bottom:e,left:e}}function Go(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 eu(e,t,n){let{reference:r,floating:o}=e;const s=mn(t),i=Oi(t),a=Pi(i),l=En(t),c=s==="y",d=r.x+r.width/2-o.width/2,f=r.y+r.height/2-o.height/2,h=r[a]/2-o[a]/2;let p;switch(l){case"top":p={x:d,y:r.y-o.height};break;case"bottom":p={x:d,y:r.y+r.height};break;case"right":p={x:r.x+r.width,y:f};break;case"left":p={x:r.x-o.width,y:f};break;default:p={x:r.x,y:r.y}}switch(mr(t)){case"start":p[i]-=h*(n&&c?-1:1);break;case"end":p[i]+=h*(n&&c?-1:1);break}return p}const Gy=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}=eu(c,r,l),h=r,p={},v=0;for(let g=0;g<a.length;g++){const{name:y,fn:x}=a[g],{x:b,y:C,data:k,reset:S}=await x({x:d,y:f,initialPlacement:r,placement:h,strategy:o,middlewareData:p,rects:c,platform:i,elements:{reference:e,floating:t}});d=b??d,f=C??f,p={...p,[y]:{...p[y],...k}},S&&v<=50&&(v++,typeof S=="object"&&(S.placement&&(h=S.placement),S.rects&&(c=S.rects===!0?await i.getElementRects({reference:e,floating:t,strategy:o}):S.rects),{x:d,y:f}=eu(c,h,l)),g=-1)}return{x:d,y:f,placement:h,strategy:o,middlewareData:p}};async function Fr(e,t){var n;t===void 0&&(t={});const{x:r,y:o,platform:s,rects:i,elements:a,strategy:l}=e,{boundary:c="clippingAncestors",rootBoundary:d="viewport",elementContext:f="floating",altBoundary:h=!1,padding:p=0}=kn(t,e),v=Qc(p),y=a[h?f==="floating"?"reference":"floating":f],x=Go(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(y)))==null||n?y:y.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(a.floating)),boundary:c,rootBoundary:d,strategy:l})),b=f==="floating"?{x:r,y:o,width:i.floating.width,height:i.floating.height}:i.reference,C=await(s.getOffsetParent==null?void 0:s.getOffsetParent(a.floating)),k=await(s.isElement==null?void 0:s.isElement(C))?await(s.getScale==null?void 0:s.getScale(C))||{x:1,y:1}:{x:1,y:1},S=Go(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:b,offsetParent:C,strategy:l}):b);return{top:(x.top-S.top+v.top)/k.y,bottom:(S.bottom-x.bottom+v.bottom)/k.y,left:(x.left-S.left+v.left)/k.x,right:(S.right-x.right+v.right)/k.x}}const Yy=e=>({name:"arrow",options:e,async fn(t){const{x:n,y:r,placement:o,rects:s,platform:i,elements:a,middlewareData:l}=t,{element:c,padding:d=0}=kn(e,t)||{};if(c==null)return{};const f=Qc(d),h={x:n,y:r},p=Oi(o),v=Pi(p),g=await i.getDimensions(c),y=p==="y",x=y?"top":"left",b=y?"bottom":"right",C=y?"clientHeight":"clientWidth",k=s.reference[v]+s.reference[p]-h[p]-s.floating[v],S=h[p]-s.reference[p],T=await(i.getOffsetParent==null?void 0:i.getOffsetParent(c));let E=T?T[C]:0;(!E||!await(i.isElement==null?void 0:i.isElement(T)))&&(E=a.floating[C]||s.floating[v]);const j=k/2-S/2,R=E/2-g[v]/2-1,O=_n(f[x],R),B=_n(f[b],R),q=O,K=E-g[v]-B,P=E/2-g[v]/2+j,M=Mi(q,P,K),I=!l.arrow&&mr(o)!=null&&P!==M&&s.reference[v]/2-(P<q?O:B)-g[v]/2<0,z=I?P<q?P-q:P-K:0;return{[p]:h[p]+z,data:{[p]:M,centerOffset:P-M-z,...I&&{alignmentOffset:z}},reset:I}}}),Xy=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(t){var n,r;const{placement:o,middlewareData:s,rects:i,initialPlacement:a,platform:l,elements:c}=t,{mainAxis:d=!0,crossAxis:f=!0,fallbackPlacements:h,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:v="none",flipAlignment:g=!0,...y}=kn(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const x=En(o),b=mn(a),C=En(a)===a,k=await(l.isRTL==null?void 0:l.isRTL(c.floating)),S=h||(C||!g?[qo(a)]:Uy(a)),T=v!=="none";!h&&T&&S.push(...Ky(a,g,v,k));const E=[a,...S],j=await Fr(t,y),R=[];let O=((r=s.flip)==null?void 0:r.overflows)||[];if(d&&R.push(j[x]),f){const P=zy(o,i,k);R.push(j[P[0]],j[P[1]])}if(O=[...O,{placement:o,overflows:R}],!R.every(P=>P<=0)){var B,q;const P=(((B=s.flip)==null?void 0:B.index)||0)+1,M=E[P];if(M&&(!(f==="alignment"?b!==mn(M):!1)||O.every(L=>mn(L.placement)===b?L.overflows[0]>0:!0)))return{data:{index:P,overflows:O},reset:{placement:M}};let I=(q=O.filter(z=>z.overflows[0]<=0).sort((z,L)=>z.overflows[1]-L.overflows[1])[0])==null?void 0:q.placement;if(!I)switch(p){case"bestFit":{var K;const z=(K=O.filter(L=>{if(T){const A=mn(L.placement);return A===b||A==="y"}return!0}).map(L=>[L.placement,L.overflows.filter(A=>A>0).reduce((A,$)=>A+$,0)]).sort((L,A)=>L[1]-A[1])[0])==null?void 0:K[0];z&&(I=z);break}case"initialPlacement":I=a;break}if(o!==I)return{reset:{placement:I}}}return{}}}};function tu(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function nu(e){return Ly.some(t=>e[t]>=0)}const Jy=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n}=t,{strategy:r="referenceHidden",...o}=kn(e,t);switch(r){case"referenceHidden":{const s=await Fr(t,{...o,elementContext:"reference"}),i=tu(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:nu(i)}}}case"escaped":{const s=await Fr(t,{...o,altBoundary:!0}),i=tu(s,n.floating);return{data:{escapedOffsets:i,escaped:nu(i)}}}default:return{}}}}},ru=new Set(["left","top"]);async function Zy(e,t){const{placement:n,platform:r,elements:o}=e,s=await(r.isRTL==null?void 0:r.isRTL(o.floating)),i=En(n),a=mr(n),l=mn(n)==="y",c=ru.has(i)?-1:1,d=s&&l?-1:1,f=kn(t,e);let{mainAxis:h,crossAxis:p,alignmentAxis:v}=typeof f=="number"?{mainAxis:f,crossAxis:0,alignmentAxis:null}:{mainAxis:f.mainAxis||0,crossAxis:f.crossAxis||0,alignmentAxis:f.alignmentAxis};return a&&typeof v=="number"&&(p=a==="end"?v*-1:v),l?{x:p*d,y:h*c}:{x:h*c,y:p*d}}const Qy=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 Zy(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}}}}},ev=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(t){const{x:n,y:r,placement:o}=t,{mainAxis:s=!0,crossAxis:i=!1,limiter:a={fn:y=>{let{x,y:b}=y;return{x,y:b}}},...l}=kn(e,t),c={x:n,y:r},d=await Fr(t,l),f=mn(En(o)),h=Ri(f);let p=c[h],v=c[f];if(s){const y=h==="y"?"top":"left",x=h==="y"?"bottom":"right",b=p+d[y],C=p-d[x];p=Mi(b,p,C)}if(i){const y=f==="y"?"top":"left",x=f==="y"?"bottom":"right",b=v+d[y],C=v-d[x];v=Mi(b,v,C)}const g=a.fn({...t,[h]:p,[f]:v});return{...g,data:{x:g.x-n,y:g.y-r,enabled:{[h]:s,[f]:i}}}}}},tv=function(e){return e===void 0&&(e={}),{options:e,fn(t){const{x:n,y:r,placement:o,rects:s,middlewareData:i}=t,{offset:a=0,mainAxis:l=!0,crossAxis:c=!0}=kn(e,t),d={x:n,y:r},f=mn(o),h=Ri(f);let p=d[h],v=d[f];const g=kn(a,t),y=typeof g=="number"?{mainAxis:g,crossAxis:0}:{mainAxis:0,crossAxis:0,...g};if(l){const C=h==="y"?"height":"width",k=s.reference[h]-s.floating[C]+y.mainAxis,S=s.reference[h]+s.reference[C]-y.mainAxis;p<k?p=k:p>S&&(p=S)}if(c){var x,b;const C=h==="y"?"width":"height",k=ru.has(En(o)),S=s.reference[f]-s.floating[C]+(k&&((x=i.offset)==null?void 0:x[f])||0)+(k?0:y.crossAxis),T=s.reference[f]+s.reference[C]+(k?0:((b=i.offset)==null?void 0:b[f])||0)-(k?y.crossAxis:0);v<S?v=S:v>T&&(v=T)}return{[h]:p,[f]:v}}}},nv=function(e){return e===void 0&&(e={}),{name:"size",options:e,async fn(t){var n,r;const{placement:o,rects:s,platform:i,elements:a}=t,{apply:l=()=>{},...c}=kn(e,t),d=await Fr(t,c),f=En(o),h=mr(o),p=mn(o)==="y",{width:v,height:g}=s.floating;let y,x;f==="top"||f==="bottom"?(y=f,x=h===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(x=f,y=h==="end"?"top":"bottom");const b=g-d.top-d.bottom,C=v-d.left-d.right,k=_n(g-d[y],b),S=_n(v-d[x],C),T=!t.middlewareData.shift;let E=k,j=S;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(j=C),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(E=b),T&&!h){const O=qt(d.left,0),B=qt(d.right,0),q=qt(d.top,0),K=qt(d.bottom,0);p?j=v-2*(O!==0||B!==0?O+B:qt(d.left,d.right)):E=g-2*(q!==0||K!==0?q+K:qt(d.top,d.bottom))}await l({...t,availableWidth:j,availableHeight:E});const R=await i.getDimensions(a.floating);return v!==R.width||g!==R.height?{reset:{rects:!0}}:{}}}};function Yo(){return typeof window<"u"}function gr(e){return ou(e)?(e.nodeName||"").toLowerCase():"#document"}function Gt(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function gn(e){var t;return(t=(ou(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function ou(e){return Yo()?e instanceof Node||e instanceof Gt(e).Node:!1}function sn(e){return Yo()?e instanceof Element||e instanceof Gt(e).Element:!1}function xn(e){return Yo()?e instanceof HTMLElement||e instanceof Gt(e).HTMLElement:!1}function su(e){return!Yo()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Gt(e).ShadowRoot}const rv=new Set(["inline","contents"]);function Br(e){const{overflow:t,overflowX:n,overflowY:r,display:o}=an(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!rv.has(o)}const ov=new Set(["table","td","th"]);function sv(e){return ov.has(gr(e))}const iv=[":popover-open",":modal"];function Xo(e){return iv.some(t=>{try{return e.matches(t)}catch{return!1}})}const av=["transform","translate","scale","rotate","perspective"],lv=["transform","translate","scale","rotate","perspective","filter"],cv=["paint","layout","strict","content"];function Li(e){const t=$i(),n=sn(e)?an(e):e;return av.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)||lv.some(r=>(n.willChange||"").includes(r))||cv.some(r=>(n.contain||"").includes(r))}function uv(e){let t=Mn(e);for(;xn(t)&&!xr(t);){if(Li(t))return t;if(Xo(t))return null;t=Mn(t)}return null}function $i(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const dv=new Set(["html","body","#document"]);function xr(e){return dv.has(gr(e))}function an(e){return Gt(e).getComputedStyle(e)}function Jo(e){return sn(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Mn(e){if(gr(e)==="html")return e;const t=e.assignedSlot||e.parentNode||su(e)&&e.host||gn(e);return su(t)?t.host:t}function iu(e){const t=Mn(e);return xr(t)?e.ownerDocument?e.ownerDocument.body:e.body:xn(t)&&Br(t)?t:iu(t)}function zr(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const o=iu(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=Gt(o);if(s){const a=Fi(i);return t.concat(i,i.visualViewport||[],Br(o)?o:[],a&&n?zr(a):[])}return t.concat(o,zr(o,[],n))}function Fi(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function au(e){const t=an(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const o=xn(e),s=o?e.offsetWidth:n,i=o?e.offsetHeight:r,a=Vo(n)!==s||Vo(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function Bi(e){return sn(e)?e:e.contextElement}function yr(e){const t=Bi(e);if(!xn(t))return pn(1);const n=t.getBoundingClientRect(),{width:r,height:o,$:s}=au(t);let i=(s?Vo(n.width):n.width)/r,a=(s?Vo(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const fv=pn(0);function lu(e){const t=Gt(e);return!$i()||!t.visualViewport?fv:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function hv(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==Gt(e)?!1:t}function Gn(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const o=e.getBoundingClientRect(),s=Bi(e);let i=pn(1);t&&(r?sn(r)&&(i=yr(r)):i=yr(e));const a=hv(s,n,r)?lu(s):pn(0);let l=(o.left+a.x)/i.x,c=(o.top+a.y)/i.y,d=o.width/i.x,f=o.height/i.y;if(s){const h=Gt(s),p=r&&sn(r)?Gt(r):r;let v=h,g=Fi(v);for(;g&&r&&p!==v;){const y=yr(g),x=g.getBoundingClientRect(),b=an(g),C=x.left+(g.clientLeft+parseFloat(b.paddingLeft))*y.x,k=x.top+(g.clientTop+parseFloat(b.paddingTop))*y.y;l*=y.x,c*=y.y,d*=y.x,f*=y.y,l+=C,c+=k,v=Gt(g),g=Fi(v)}}return Go({width:d,height:f,x:l,y:c})}function Zo(e,t){const n=Jo(e).scrollLeft;return t?t.left+n:Gn(gn(e)).left+n}function cu(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-Zo(e,n),o=n.top+t.scrollTop;return{x:r,y:o}}function pv(e){let{elements:t,rect:n,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=gn(r),a=t?Xo(t.floating):!1;if(r===i||a&&s)return n;let l={scrollLeft:0,scrollTop:0},c=pn(1);const d=pn(0),f=xn(r);if((f||!f&&!s)&&((gr(r)!=="body"||Br(i))&&(l=Jo(r)),xn(r))){const p=Gn(r);c=yr(r),d.x=p.x+r.clientLeft,d.y=p.y+r.clientTop}const h=i&&!f&&!s?cu(i,l):pn(0);return{width:n.width*c.x,height:n.height*c.y,x:n.x*c.x-l.scrollLeft*c.x+d.x+h.x,y:n.y*c.y-l.scrollTop*c.y+d.y+h.y}}function mv(e){return Array.from(e.getClientRects())}function gv(e){const t=gn(e),n=Jo(e),r=e.ownerDocument.body,o=qt(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=qt(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let i=-n.scrollLeft+Zo(e);const a=-n.scrollTop;return an(r).direction==="rtl"&&(i+=qt(t.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}const uu=25;function xv(e,t){const n=Gt(e),r=gn(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=$i();(!d||d&&t==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}const c=Zo(r);if(c<=0){const d=r.ownerDocument,f=d.body,h=getComputedStyle(f),p=d.compatMode==="CSS1Compat"&&parseFloat(h.marginLeft)+parseFloat(h.marginRight)||0,v=Math.abs(r.clientWidth-f.clientWidth-p);v<=uu&&(s-=v)}else c<=uu&&(s+=c);return{width:s,height:i,x:a,y:l}}const yv=new Set(["absolute","fixed"]);function vv(e,t){const n=Gn(e,!0,t==="fixed"),r=n.top+e.clientTop,o=n.left+e.clientLeft,s=xn(e)?yr(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 du(e,t,n){let r;if(t==="viewport")r=xv(e,n);else if(t==="document")r=gv(gn(e));else if(sn(t))r=vv(t,n);else{const o=lu(e);r={x:t.x-o.x,y:t.y-o.y,width:t.width,height:t.height}}return Go(r)}function fu(e,t){const n=Mn(e);return n===t||!sn(n)||xr(n)?!1:an(n).position==="fixed"||fu(n,t)}function bv(e,t){const n=t.get(e);if(n)return n;let r=zr(e,[],!1).filter(a=>sn(a)&&gr(a)!=="body"),o=null;const s=an(e).position==="fixed";let i=s?Mn(e):e;for(;sn(i)&&!xr(i);){const a=an(i),l=Li(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&yv.has(o.position)||Br(i)&&!l&&fu(e,i))?r=r.filter(d=>d!==i):o=a,i=Mn(i)}return t.set(e,r),r}function wv(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i=[...n==="clippingAncestors"?Xo(t)?[]:bv(t,this._c):[].concat(n),r],a=i[0],l=i.reduce((c,d)=>{const f=du(t,d,o);return c.top=qt(f.top,c.top),c.right=_n(f.right,c.right),c.bottom=_n(f.bottom,c.bottom),c.left=qt(f.left,c.left),c},du(t,a,o));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function Sv(e){const{width:t,height:n}=au(e);return{width:t,height:n}}function Cv(e,t,n){const r=xn(t),o=gn(t),s=n==="fixed",i=Gn(e,!0,s,t);let a={scrollLeft:0,scrollTop:0};const l=pn(0);function c(){l.x=Zo(o)}if(r||!r&&!s)if((gr(t)!=="body"||Br(o))&&(a=Jo(t)),r){const p=Gn(t,!0,s,t);l.x=p.x+t.clientLeft,l.y=p.y+t.clientTop}else o&&c();s&&!r&&o&&c();const d=o&&!r&&!s?cu(o,a):pn(0),f=i.left+a.scrollLeft-l.x-d.x,h=i.top+a.scrollTop-l.y-d.y;return{x:f,y:h,width:i.width,height:i.height}}function zi(e){return an(e).position==="static"}function hu(e,t){if(!xn(e)||an(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return gn(e)===n&&(n=n.ownerDocument.body),n}function pu(e,t){const n=Gt(e);if(Xo(e))return n;if(!xn(e)){let o=Mn(e);for(;o&&!xr(o);){if(sn(o)&&!zi(o))return o;o=Mn(o)}return n}let r=hu(e,t);for(;r&&sv(r)&&zi(r);)r=hu(r,t);return r&&xr(r)&&zi(r)&&!Li(r)?n:r||uv(e)||n}const Tv=async function(e){const t=this.getOffsetParent||pu,n=this.getDimensions,r=await n(e.floating);return{reference:Cv(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function kv(e){return an(e).direction==="rtl"}const Ev={convertOffsetParentRelativeRectToViewportRelativeRect:pv,getDocumentElement:gn,getClippingRect:wv,getOffsetParent:pu,getElementRects:Tv,getClientRects:mv,getDimensions:Sv,getScale:yr,isElement:sn,isRTL:kv};function mu(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function Iv(e,t){let n=null,r;const o=gn(e);function s(){var a;clearTimeout(r),(a=n)==null||a.disconnect(),n=null}function i(a,l){a===void 0&&(a=!1),l===void 0&&(l=1),s();const c=e.getBoundingClientRect(),{left:d,top:f,width:h,height:p}=c;if(a||t(),!h||!p)return;const v=Ko(f),g=Ko(o.clientWidth-(d+h)),y=Ko(o.clientHeight-(f+p)),x=Ko(d),C={rootMargin:-v+"px "+-g+"px "+-y+"px "+-x+"px",threshold:qt(0,_n(1,l))||1};let k=!0;function S(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&&!mu(c,e.getBoundingClientRect())&&i(),k=!1}try{n=new IntersectionObserver(S,{...C,root:o.ownerDocument})}catch{n=new IntersectionObserver(S,C)}n.observe(e)}return i(!0),s}function Nv(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=Bi(e),d=o||s?[...c?zr(c):[],...zr(t)]:[];d.forEach(x=>{o&&x.addEventListener("scroll",n,{passive:!0}),s&&x.addEventListener("resize",n)});const f=c&&a?Iv(c,n):null;let h=-1,p=null;i&&(p=new ResizeObserver(x=>{let[b]=x;b&&b.target===c&&p&&(p.unobserve(t),cancelAnimationFrame(h),h=requestAnimationFrame(()=>{var C;(C=p)==null||C.observe(t)})),n()}),c&&!l&&p.observe(c),p.observe(t));let v,g=l?Gn(e):null;l&&y();function y(){const x=Gn(e);g&&!mu(g,x)&&n(),g=x,v=requestAnimationFrame(y)}return n(),()=>{var x;d.forEach(b=>{o&&b.removeEventListener("scroll",n),s&&b.removeEventListener("resize",n)}),f==null||f(),(x=p)==null||x.disconnect(),p=null,l&&cancelAnimationFrame(v)}}const Av=Qy,jv=ev,_v=Xy,Mv=nv,Rv=Jy,gu=Yy,Pv=tv,Ov=(e,t,n)=>{const r=new Map,o={platform:Ev,...n},s={...o.platform,_c:r};return Gy(e,t,{...o,platform:s})};var Dv=typeof document<"u",Lv=function(){},Qo=Dv?w.useLayoutEffect:Lv;function es(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(!es(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)&&!es(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function xu(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function yu(e,t){const n=xu(e);return Math.round(t*n)/n}function Ui(e){const t=m.useRef(e);return Qo(()=>{t.current=e}),t}function $v(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]=m.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[h,p]=m.useState(r);es(h,r)||p(r);const[v,g]=m.useState(null),[y,x]=m.useState(null),b=m.useCallback(L=>{L!==T.current&&(T.current=L,g(L))},[]),C=m.useCallback(L=>{L!==E.current&&(E.current=L,x(L))},[]),k=s||v,S=i||y,T=m.useRef(null),E=m.useRef(null),j=m.useRef(d),R=l!=null,O=Ui(l),B=Ui(o),q=Ui(c),K=m.useCallback(()=>{if(!T.current||!E.current)return;const L={placement:t,strategy:n,middleware:h};B.current&&(L.platform=B.current),Ov(T.current,E.current,L).then(A=>{const $={...A,isPositioned:q.current!==!1};P.current&&!es(j.current,$)&&(j.current=$,wo.flushSync(()=>{f($)}))})},[h,t,n,B,q]);Qo(()=>{c===!1&&j.current.isPositioned&&(j.current.isPositioned=!1,f(L=>({...L,isPositioned:!1})))},[c]);const P=m.useRef(!1);Qo(()=>(P.current=!0,()=>{P.current=!1}),[]),Qo(()=>{if(k&&(T.current=k),S&&(E.current=S),k&&S){if(O.current)return O.current(k,S,K);K()}},[k,S,K,O,R]);const M=m.useMemo(()=>({reference:T,floating:E,setReference:b,setFloating:C}),[b,C]),I=m.useMemo(()=>({reference:k,floating:S}),[k,S]),z=m.useMemo(()=>{const L={position:n,left:0,top:0};if(!I.floating)return L;const A=yu(I.floating,d.x),$=yu(I.floating,d.y);return a?{...L,transform:"translate("+A+"px, "+$+"px)",...xu(I.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:A,top:$}},[n,a,I.floating,d.x,d.y]);return m.useMemo(()=>({...d,update:K,refs:M,elements:I,floatingStyles:z}),[d,K,M,I,z])}const Fv=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?gu({element:r.current,padding:o}).fn(n):{}:r?gu({element:r,padding:o}).fn(n):{}}}},Bv=(e,t)=>({...Av(e),options:[e,t]}),zv=(e,t)=>({...jv(e),options:[e,t]}),Uv=(e,t)=>({...Pv(e),options:[e,t]}),Hv=(e,t)=>({..._v(e),options:[e,t]}),Wv=(e,t)=>({...Mv(e),options:[e,t]}),Vv=(e,t)=>({...Rv(e),options:[e,t]}),Kv=(e,t)=>({...Fv(e),options:[e,t]});var qv="Arrow",vu=m.forwardRef((e,t)=>{const{children:n,width:r=10,height:o=5,...s}=e;return u.jsx(Se.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"})})});vu.displayName=qv;var Gv=vu;function bu(e){const[t,n]=m.useState(void 0);return It(()=>{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 Hi="Popper",[wu,ts]=Tn(Hi),[Yv,Su]=wu(Hi),Cu=e=>{const{__scopePopper:t,children:n}=e,[r,o]=m.useState(null);return u.jsx(Yv,{scope:t,anchor:r,onAnchorChange:o,children:n})};Cu.displayName=Hi;var Tu="PopperAnchor",ku=m.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...o}=e,s=Su(Tu,n),i=m.useRef(null),a=Ve(t,i),l=m.useRef(null);return m.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(Se.div,{...o,ref:a})});ku.displayName=Tu;var Wi="PopperContent",[Xv,Jv]=wu(Wi),Eu=m.forwardRef((e,t)=>{var Y,D,V,U,Z,J;const{__scopePopper:n,side:r="bottom",sideOffset:o=0,align:s="center",alignOffset:i=0,arrowPadding:a=0,avoidCollisions:l=!0,collisionBoundary:c=[],collisionPadding:d=0,sticky:f="partial",hideWhenDetached:h=!1,updatePositionStrategy:p="optimized",onPlaced:v,...g}=e,y=Su(Wi,n),[x,b]=m.useState(null),C=Ve(t,ge=>b(ge)),[k,S]=m.useState(null),T=bu(k),E=(T==null?void 0:T.width)??0,j=(T==null?void 0:T.height)??0,R=r+(s!=="center"?"-"+s:""),O=typeof d=="number"?d:{top:0,right:0,bottom:0,left:0,...d},B=Array.isArray(c)?c:[c],q=B.length>0,K={padding:O,boundary:B.filter(Qv),altBoundary:q},{refs:P,floatingStyles:M,placement:I,isPositioned:z,middlewareData:L}=$v({strategy:"fixed",placement:R,whileElementsMounted:(...ge)=>Nv(...ge,{animationFrame:p==="always"}),elements:{reference:y.anchor},middleware:[Bv({mainAxis:o+j,alignmentAxis:i}),l&&zv({mainAxis:!0,crossAxis:!1,limiter:f==="partial"?Uv():void 0,...K}),l&&Hv({...K}),Wv({...K,apply:({elements:ge,rects:ce,availableWidth:ne,availableHeight:pe})=>{const{width:be,height:De}=ce.reference,je=ge.floating.style;je.setProperty("--radix-popper-available-width",`${ne}px`),je.setProperty("--radix-popper-available-height",`${pe}px`),je.setProperty("--radix-popper-anchor-width",`${be}px`),je.setProperty("--radix-popper-anchor-height",`${De}px`)}}),k&&Kv({element:k,padding:a}),eb({arrowWidth:E,arrowHeight:j}),h&&Vv({strategy:"referenceHidden",...K})]}),[A,$]=Au(I),H=Nt(v);It(()=>{z&&(H==null||H())},[z,H]);const _=(Y=L.arrow)==null?void 0:Y.x,G=(D=L.arrow)==null?void 0:D.y,re=((V=L.arrow)==null?void 0:V.centerOffset)!==0,[ee,ie]=m.useState();return It(()=>{x&&ie(window.getComputedStyle(x).zIndex)},[x]),u.jsx("div",{ref:P.setFloating,"data-radix-popper-content-wrapper":"",style:{...M,transform:z?M.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:ee,"--radix-popper-transform-origin":[(U=L.transformOrigin)==null?void 0:U.x,(Z=L.transformOrigin)==null?void 0:Z.y].join(" "),...((J=L.hide)==null?void 0:J.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:u.jsx(Xv,{scope:n,placedSide:A,onArrowChange:S,arrowX:_,arrowY:G,shouldHideArrow:re,children:u.jsx(Se.div,{"data-side":A,"data-align":$,...g,ref:C,style:{...g.style,animation:z?void 0:"none"}})})})});Eu.displayName=Wi;var Iu="PopperArrow",Zv={top:"bottom",right:"left",bottom:"top",left:"right"},Nu=m.forwardRef(function(t,n){const{__scopePopper:r,...o}=t,s=Jv(Iu,r),i=Zv[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(Gv,{...o,ref:n,style:{...o.style,display:"block"}})})});Nu.displayName=Iu;function Qv(e){return e!==null}var eb=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]=Au(n),f={start:"0%",center:"50%",end:"100%"}[d],h=(((x=o.arrow)==null?void 0:x.x)??0)+a/2,p=(((b=o.arrow)==null?void 0:b.y)??0)+l/2;let v="",g="";return c==="bottom"?(v=i?f:`${h}px`,g=`${-l}px`):c==="top"?(v=i?f:`${h}px`,g=`${r.floating.height+l}px`):c==="right"?(v=`${-l}px`,g=i?f:`${p}px`):c==="left"&&(v=`${r.floating.width+l}px`,g=i?f:`${p}px`),{data:{x:v,y:g}}}});function Au(e){const[t,n="center"]=e.split("-");return[t,n]}var ju=Cu,_u=ku,Mu=Eu,Ru=Nu,tb="Portal",ns=m.forwardRef((e,t)=>{var a;const{container:n,...r}=e,[o,s]=m.useState(!1);It(()=>s(!0),[]);const i=n||o&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?si.createPortal(u.jsx(Se.div,{...r,ref:t}),i):null});ns.displayName=tb;function nb(e,t){return m.useReducer((n,r)=>t[n][r]??n,e)}var Jt=e=>{const{present:t,children:n}=e,r=rb(t),o=typeof n=="function"?n({present:r.isPresent}):m.Children.only(n),s=Ve(r.ref,ob(o));return typeof n=="function"||r.isPresent?m.cloneElement(o,{ref:s}):null};Jt.displayName="Presence";function rb(e){const[t,n]=m.useState(),r=m.useRef(null),o=m.useRef(e),s=m.useRef("none"),i=e?"mounted":"unmounted",[a,l]=nb(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return m.useEffect(()=>{const c=rs(r.current);s.current=a==="mounted"?c:"none"},[a]),It(()=>{const c=r.current,d=o.current;if(d!==e){const h=s.current,p=rs(c);e?l("MOUNT"):p==="none"||(c==null?void 0:c.display)==="none"?l("UNMOUNT"):l(d&&h!==p?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,l]),It(()=>{if(t){let c;const d=t.ownerDocument.defaultView??window,f=p=>{const g=rs(r.current).includes(CSS.escape(p.animationName));if(p.target===t&&g&&(l("ANIMATION_END"),!o.current)){const y=t.style.animationFillMode;t.style.animationFillMode="forwards",c=d.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=y)})}},h=p=>{p.target===t&&(s.current=rs(r.current))};return t.addEventListener("animationstart",h),t.addEventListener("animationcancel",f),t.addEventListener("animationend",f),()=>{d.clearTimeout(c),t.removeEventListener("animationstart",h),t.removeEventListener("animationcancel",f),t.removeEventListener("animationend",f)}}else l("ANIMATION_END")},[t,l]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:m.useCallback(c=>{r.current=c?getComputedStyle(c):null,n(c)},[])}}function rs(e){return(e==null?void 0:e.animationName)||"none"}function ob(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 Vi="rovingFocusGroup.onEntryFocus",sb={bubbles:!1,cancelable:!0},Ur="RovingFocusGroup",[Ki,Pu,ib]=Ei(Ur),[ab,Ou]=Tn(Ur,[ib]),[lb,cb]=ab(Ur),Du=m.forwardRef((e,t)=>u.jsx(Ki.Provider,{scope:e.__scopeRovingFocusGroup,children:u.jsx(Ki.Slot,{scope:e.__scopeRovingFocusGroup,children:u.jsx(ub,{...e,ref:t})})}));Du.displayName=Ur;var ub=m.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:o=!1,dir:s,currentTabStopId:i,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:l,onEntryFocus:c,preventScrollOnEntryFocus:d=!1,...f}=e,h=m.useRef(null),p=Ve(t,h),v=Uo(s),[g,y]=pr({prop:i,defaultProp:a??null,onChange:l,caller:Ur}),[x,b]=m.useState(!1),C=Nt(c),k=Pu(n),S=m.useRef(!1),[T,E]=m.useState(0);return m.useEffect(()=>{const j=h.current;if(j)return j.addEventListener(Vi,C),()=>j.removeEventListener(Vi,C)},[C]),u.jsx(lb,{scope:n,orientation:r,dir:v,loop:o,currentTabStopId:g,onItemFocus:m.useCallback(j=>y(j),[y]),onItemShiftTab:m.useCallback(()=>b(!0),[]),onFocusableItemAdd:m.useCallback(()=>E(j=>j+1),[]),onFocusableItemRemove:m.useCallback(()=>E(j=>j-1),[]),children:u.jsx(Se.div,{tabIndex:x||T===0?-1:0,"data-orientation":r,...f,ref:p,style:{outline:"none",...e.style},onMouseDown:he(e.onMouseDown,()=>{S.current=!0}),onFocus:he(e.onFocus,j=>{const R=!S.current;if(j.target===j.currentTarget&&R&&!x){const O=new CustomEvent(Vi,sb);if(j.currentTarget.dispatchEvent(O),!O.defaultPrevented){const B=k().filter(I=>I.focusable),q=B.find(I=>I.active),K=B.find(I=>I.id===g),M=[q,K,...B].filter(Boolean).map(I=>I.ref.current);Fu(M,d)}}S.current=!1}),onBlur:he(e.onBlur,()=>b(!1))})})}),Lu="RovingFocusGroupItem",$u=m.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:o=!1,tabStopId:s,children:i,...a}=e,l=$t(),c=s||l,d=cb(Lu,n),f=d.currentTabStopId===c,h=Pu(n),{onFocusableItemAdd:p,onFocusableItemRemove:v,currentTabStopId:g}=d;return m.useEffect(()=>{if(r)return p(),()=>v()},[r,p,v]),u.jsx(Ki.ItemSlot,{scope:n,id:c,focusable:r,active:o,children:u.jsx(Se.span,{tabIndex:f?0:-1,"data-orientation":d.orientation,...a,ref:t,onMouseDown:he(e.onMouseDown,y=>{r?d.onItemFocus(c):y.preventDefault()}),onFocus:he(e.onFocus,()=>d.onItemFocus(c)),onKeyDown:he(e.onKeyDown,y=>{if(y.key==="Tab"&&y.shiftKey){d.onItemShiftTab();return}if(y.target!==y.currentTarget)return;const x=hb(y,d.orientation,d.dir);if(x!==void 0){if(y.metaKey||y.ctrlKey||y.altKey||y.shiftKey)return;y.preventDefault();let C=h().filter(k=>k.focusable).map(k=>k.ref.current);if(x==="last")C.reverse();else if(x==="prev"||x==="next"){x==="prev"&&C.reverse();const k=C.indexOf(y.currentTarget);C=d.loop?pb(C,k+1):C.slice(k+1)}setTimeout(()=>Fu(C))}}),children:typeof i=="function"?i({isCurrentTabStop:f,hasTabStop:g!=null}):i})})});$u.displayName=Lu;var db={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function fb(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function hb(e,t,n){const r=fb(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return db[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 pb(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var mb=Du,gb=$u,xb=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},vr=new WeakMap,os=new WeakMap,ss={},qi=0,Bu=function(e){return e&&(e.host||Bu(e.parentNode))},yb=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=Bu(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})},vb=function(e,t,n,r){var o=yb(t,Array.isArray(e)?e:[e]);ss[n]||(ss[n]=new WeakMap);var s=ss[n],i=[],a=new Set,l=new Set(o),c=function(f){!f||a.has(f)||(a.add(f),c(f.parentNode))};o.forEach(c);var d=function(f){!f||l.has(f)||Array.prototype.forEach.call(f.children,function(h){if(a.has(h))d(h);else try{var p=h.getAttribute(r),v=p!==null&&p!=="false",g=(vr.get(h)||0)+1,y=(s.get(h)||0)+1;vr.set(h,g),s.set(h,y),i.push(h),g===1&&v&&os.set(h,!0),y===1&&h.setAttribute(n,"true"),v||h.setAttribute(r,"true")}catch(x){console.error("aria-hidden: cannot operate on ",h,x)}})};return d(t),a.clear(),qi++,function(){i.forEach(function(f){var h=vr.get(f)-1,p=s.get(f)-1;vr.set(f,h),s.set(f,p),h||(os.has(f)||f.removeAttribute(r),os.delete(f)),p||f.removeAttribute(n)}),qi--,qi||(vr=new WeakMap,vr=new WeakMap,os=new WeakMap,ss={})}},Gi=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),o=xb(e);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live], script"))),vb(r,o,n,"aria-hidden")):function(){return null}},yn=function(){return yn=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},yn.apply(this,arguments)};function zu(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 bb(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 is="right-scroll-bar-position",as="width-before-scroll-bar",wb="with-scroll-bars-hidden",Sb="--removed-body-scroll-bar-size";function Yi(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function Cb(e,t){var n=w.useState(function(){return{value:e,callback:t,facade:{get current(){return n.value},set current(r){var o=n.value;o!==r&&(n.value=r,n.callback(r,o))}}}})[0];return n.callback=t,n.facade}var Tb=typeof window<"u"?m.useLayoutEffect:m.useEffect,Uu=new WeakMap;function kb(e,t){var n=Cb(null,function(r){return e.forEach(function(o){return Yi(o,r)})});return Tb(function(){var r=Uu.get(n);if(r){var o=new Set(r),s=new Set(e),i=n.current;o.forEach(function(a){s.has(a)||Yi(a,null)}),s.forEach(function(a){o.has(a)||Yi(a,i)})}Uu.set(n,e)},[e]),n}function Eb(e){return e}function Ib(e,t){t===void 0&&(t=Eb);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 Nb(e){e===void 0&&(e={});var t=Ib(null);return t.options=yn({async:!0,ssr:!1},e),t}var Hu=function(e){var t=e.sideCar,n=zu(e,["sideCar"]);if(!t)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=t.read();if(!r)throw new Error("Sidecar medium not found");return m.createElement(r,yn({},n))};Hu.isSideCarExport=!0;function Ab(e,t){return e.useMedium(t),Hu}var Wu=Nb(),Xi=function(){},ls=m.forwardRef(function(e,t){var n=m.useRef(null),r=m.useState({onScrollCapture:Xi,onWheelCapture:Xi,onTouchMoveCapture:Xi}),o=r[0],s=r[1],i=e.forwardProps,a=e.children,l=e.className,c=e.removeScrollBar,d=e.enabled,f=e.shards,h=e.sideCar,p=e.noRelative,v=e.noIsolation,g=e.inert,y=e.allowPinchZoom,x=e.as,b=x===void 0?"div":x,C=e.gapMode,k=zu(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),S=h,T=kb([n,t]),E=yn(yn({},k),o);return m.createElement(m.Fragment,null,d&&m.createElement(S,{sideCar:Wu,removeScrollBar:c,shards:f,noRelative:p,noIsolation:v,inert:g,setCallbacks:s,allowPinchZoom:!!y,lockRef:n,gapMode:C}),i?m.cloneElement(m.Children.only(a),yn(yn({},E),{ref:T})):m.createElement(b,yn({},E,{className:l,ref:T}),a))});ls.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},ls.classNames={fullWidth:as,zeroRight:is};var jb=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function _b(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=jb();return t&&e.setAttribute("nonce",t),e}function Mb(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function Rb(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var Pb=function(){var e=0,t=null;return{add:function(n){e==0&&(t=_b())&&(Mb(t,n),Rb(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},Ob=function(){var e=Pb();return function(t,n){m.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},Vu=function(){var e=Ob(),t=function(n){var r=n.styles,o=n.dynamic;return e(r,o),null};return t},Db={left:0,top:0,right:0,gap:0},Ji=function(e){return parseInt(e||"",10)||0},Lb=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[Ji(n),Ji(r),Ji(o)]},$b=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return Db;var t=Lb(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])}},Fb=Vu(),br="data-scroll-locked",Bb=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(wb,` {
|
|
40
40
|
overflow: hidden `).concat(r,`;
|
|
41
41
|
padding-right: `).concat(a,"px ").concat(r,`;
|
|
42
42
|
}
|
|
43
|
-
body[`).concat(
|
|
43
|
+
body[`).concat(br,`] {
|
|
44
44
|
overflow: hidden `).concat(r,`;
|
|
45
45
|
overscroll-behavior: contain;
|
|
46
46
|
`).concat([t&&"position: relative ".concat(r,";"),n==="margin"&&`
|
|
@@ -53,29 +53,29 @@ React keys must be passed directly to JSX without using spread:
|
|
|
53
53
|
`),n==="padding"&&"padding-right: ".concat(a,"px ").concat(r,";")].filter(Boolean).join(""),`
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
.`).concat(
|
|
56
|
+
.`).concat(is,` {
|
|
57
57
|
right: `).concat(a,"px ").concat(r,`;
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
.`).concat(
|
|
60
|
+
.`).concat(as,` {
|
|
61
61
|
margin-right: `).concat(a,"px ").concat(r,`;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
.`).concat(
|
|
64
|
+
.`).concat(is," .").concat(is,` {
|
|
65
65
|
right: 0 `).concat(r,`;
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
.`).concat(
|
|
68
|
+
.`).concat(as," .").concat(as,` {
|
|
69
69
|
margin-right: 0 `).concat(r,`;
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
body[`).concat(
|
|
73
|
-
`).concat(
|
|
72
|
+
body[`).concat(br,`] {
|
|
73
|
+
`).concat(Sb,": ").concat(a,`px;
|
|
74
74
|
}
|
|
75
|
-
`)},Ku=function(){var e=parseInt(document.body.getAttribute(
|
|
75
|
+
`)},Ku=function(){var e=parseInt(document.body.getAttribute(br)||"0",10);return isFinite(e)?e:0},zb=function(){m.useEffect(function(){return document.body.setAttribute(br,(Ku()+1).toString()),function(){var e=Ku()-1;e<=0?document.body.removeAttribute(br):document.body.setAttribute(br,e.toString())}},[])},Ub=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,o=r===void 0?"margin":r;zb();var s=m.useMemo(function(){return $b(o)},[o]);return m.createElement(Fb,{styles:Bb(s,!t,o,n?"":"!important")})},Zi=!1;if(typeof window<"u")try{var cs=Object.defineProperty({},"passive",{get:function(){return Zi=!0,!0}});window.addEventListener("test",cs,cs),window.removeEventListener("test",cs,cs)}catch{Zi=!1}var wr=Zi?{passive:!1}:!1,Hb=function(e){return e.tagName==="TEXTAREA"},qu=function(e,t){if(!(e instanceof Element))return!1;var n=window.getComputedStyle(e);return n[t]!=="hidden"&&!(n.overflowY===n.overflowX&&!Hb(e)&&n[t]==="visible")},Wb=function(e){return qu(e,"overflowY")},Vb=function(e){return qu(e,"overflowX")},Gu=function(e,t){var n=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var o=Yu(e,r);if(o){var s=Xu(e,r),i=s[1],a=s[2];if(i>a)return!0}r=r.parentNode}while(r&&r!==n.body);return!1},Kb=function(e){var t=e.scrollTop,n=e.scrollHeight,r=e.clientHeight;return[t,n,r]},qb=function(e){var t=e.scrollLeft,n=e.scrollWidth,r=e.clientWidth;return[t,n,r]},Yu=function(e,t){return e==="v"?Wb(t):Vb(t)},Xu=function(e,t){return e==="v"?Kb(t):qb(t)},Gb=function(e,t){return e==="h"&&t==="rtl"?-1:1},Yb=function(e,t,n,r,o){var s=Gb(e,window.getComputedStyle(t).direction),i=s*r,a=n.target,l=t.contains(a),c=!1,d=i>0,f=0,h=0;do{if(!a)break;var p=Xu(e,a),v=p[0],g=p[1],y=p[2],x=g-y-s*v;(v||x)&&Yu(e,a)&&(f+=x,h+=v);var b=a.parentNode;a=b&&b.nodeType===Node.DOCUMENT_FRAGMENT_NODE?b.host:b}while(!l&&a!==document.body||l&&(t.contains(a)||t===a));return(d&&Math.abs(f)<1||!d&&Math.abs(h)<1)&&(c=!0),c},us=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},Ju=function(e){return[e.deltaX,e.deltaY]},Zu=function(e){return e&&"current"in e?e.current:e},Xb=function(e,t){return e[0]===t[0]&&e[1]===t[1]},Jb=function(e){return`
|
|
76
76
|
.block-interactivity-`.concat(e,` {pointer-events: none;}
|
|
77
77
|
.allow-interactivity-`).concat(e,` {pointer-events: all;}
|
|
78
|
-
`)},Jb=0,Er=[];function Zb(e){var t=m.useRef([]),n=m.useRef([0,0]),r=m.useRef(),o=m.useState(Jb++)[0],s=m.useState(Vu)[0],i=m.useRef(e);m.useEffect(function(){i.current=e},[e]),m.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(o));var g=vb([e.lockRef.current],(e.shards||[]).map(Zu),!0).filter(Boolean);return g.forEach(function(y){return y.classList.add("allow-interactivity-".concat(o))}),function(){document.body.classList.remove("block-interactivity-".concat(o)),g.forEach(function(y){return y.classList.remove("allow-interactivity-".concat(o))})}}},[e.inert,e.lockRef.current,e.shards]);var a=m.useCallback(function(g,y){if("touches"in g&&g.touches.length===2||g.type==="wheel"&&g.ctrlKey)return!i.current.allowPinchZoom;var x=ms(g),b=n.current,C="deltaX"in g?g.deltaX:b[0]-x[0],k="deltaY"in g?g.deltaY:b[1]-x[1],T,S=g.target,E=Math.abs(C)>Math.abs(k)?"h":"v";if("touches"in g&&E==="h"&&S.type==="range")return!1;var A=Gu(E,S);if(!A)return!0;if(A?T=E:(T=E==="v"?"h":"v",A=Gu(E,S)),!A)return!1;if(!r.current&&"changedTouches"in g&&(C||k)&&(r.current=T),!T)return!0;var R=r.current||T;return Gb(R,y,g,R==="h"?C:k)},[]),l=m.useCallback(function(g){var y=g;if(!(!Er.length||Er[Er.length-1]!==s)){var x="deltaY"in y?Ju(y):ms(y),b=t.current.filter(function(T){return T.name===y.type&&(T.target===y.target||y.target===T.shadowParent)&&Yb(T.delta,x)})[0];if(b&&b.should){y.cancelable&&y.preventDefault();return}if(!b){var C=(i.current.shards||[]).map(Zu).filter(Boolean).filter(function(T){return T.contains(y.target)}),k=C.length>0?a(y,C[0]):!i.current.noIsolation;k&&y.cancelable&&y.preventDefault()}}},[]),c=m.useCallback(function(g,y,x,b){var C={name:g,delta:y,target:x,should:b,shadowParent:Qb(x)};t.current.push(C),setTimeout(function(){t.current=t.current.filter(function(k){return k!==C})},1)},[]),d=m.useCallback(function(g){n.current=ms(g),r.current=void 0},[]),f=m.useCallback(function(g){c(g.type,Ju(g),g.target,a(g,e.lockRef.current))},[]),p=m.useCallback(function(g){c(g.type,ms(g),g.target,a(g,e.lockRef.current))},[]);m.useEffect(function(){return Er.push(s),e.setCallbacks({onScrollCapture:f,onWheelCapture:f,onTouchMoveCapture:p}),document.addEventListener("wheel",l,kr),document.addEventListener("touchmove",l,kr),document.addEventListener("touchstart",d,kr),function(){Er=Er.filter(function(g){return g!==s}),document.removeEventListener("wheel",l,kr),document.removeEventListener("touchmove",l,kr),document.removeEventListener("touchstart",d,kr)}},[]);var h=e.removeScrollBar,v=e.inert;return m.createElement(m.Fragment,null,v?m.createElement(s,{styles:Xb(o)}):null,h?m.createElement(zb,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function Qb(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const ew=Nb(Wu,Zb);var gs=m.forwardRef(function(e,t){return m.createElement(ps,yn({},e,{ref:t,sideCar:ew}))});gs.classNames=ps.classNames;var na=["Enter"," "],tw=["ArrowDown","PageUp","Home"],Qu=["ArrowUp","PageDown","End"],nw=[...tw,...Qu],rw={ltr:[...na,"ArrowRight"],rtl:[...na,"ArrowLeft"]},ow={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Xr="Menu",[Jr,sw,iw]=Ai(Xr),[Jn,ed]=kn(Xr,[iw,is,Ou]),xs=is(),td=Ou(),[aw,Zn]=Jn(Xr),[lw,Zr]=Jn(Xr),nd=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=xs(t),[l,c]=m.useState(null),d=m.useRef(!1),f=Nt(s),p=qo(o);return m.useEffect(()=>{const h=()=>{d.current=!0,document.addEventListener("pointerdown",v,{capture:!0,once:!0}),document.addEventListener("pointermove",v,{capture:!0,once:!0})},v=()=>d.current=!1;return document.addEventListener("keydown",h,{capture:!0}),()=>{document.removeEventListener("keydown",h,{capture:!0}),document.removeEventListener("pointerdown",v,{capture:!0}),document.removeEventListener("pointermove",v,{capture:!0})}},[]),u.jsx(ju,{...a,children:u.jsx(aw,{scope:t,open:n,onOpenChange:f,content:l,onContentChange:c,children:u.jsx(lw,{scope:t,onClose:m.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:d,dir:p,modal:i,children:r})})})};nd.displayName=Xr;var cw="MenuAnchor",ra=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=xs(n);return u.jsx(_u,{...o,...r,ref:t})});ra.displayName=cw;var oa="MenuPortal",[uw,rd]=Jn(oa,{forceMount:void 0}),od=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:o}=e,s=Zn(oa,t);return u.jsx(uw,{scope:t,forceMount:n,children:u.jsx(Zt,{present:n||s.open,children:u.jsx(as,{asChild:!0,container:o,children:r})})})};od.displayName=oa;var Qt="MenuContent",[dw,sa]=Jn(Qt),sd=m.forwardRef((e,t)=>{const n=rd(Qt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Zn(Qt,e.__scopeMenu),i=Zr(Qt,e.__scopeMenu);return u.jsx(Jr.Provider,{scope:e.__scopeMenu,children:u.jsx(Zt,{present:r||s.open,children:u.jsx(Jr.Slot,{scope:e.__scopeMenu,children:i.modal?u.jsx(fw,{...o,ref:t}):u.jsx(pw,{...o,ref:t})})})})}),fw=m.forwardRef((e,t)=>{const n=Zn(Qt,e.__scopeMenu),r=m.useRef(null),o=Ve(t,r);return m.useEffect(()=>{const s=r.current;if(s)return Ji(s)},[]),u.jsx(ia,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:me(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),pw=m.forwardRef((e,t)=>{const n=Zn(Qt,e.__scopeMenu);return u.jsx(ia,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),hw=Kn.createSlot("MenuContent.ScrollLock"),ia=m.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:v,...g}=e,y=Zn(Qt,n),x=Zr(Qt,n),b=xs(n),C=td(n),k=sw(n),[T,S]=m.useState(null),E=m.useRef(null),A=Ve(t,E,y.onContentChange),R=m.useRef(0),D=m.useRef(""),B=m.useRef(0),q=m.useRef(null),V=m.useRef("right"),j=m.useRef(0),_=v?gs:m.Fragment,N=v?{as:hw,allowPinchZoom:!0}:void 0,z=P=>{var G,O;const H=D.current+P,Q=k().filter(W=>!W.disabled),M=document.activeElement,Y=(G=Q.find(W=>W.ref.current===M))==null?void 0:G.textValue,ae=Q.map(W=>W.textValue),ne=Ew(ae,H,Y),ce=(O=Q.find(W=>W.textValue===ne))==null?void 0:O.ref.current;(function W(F){D.current=F,window.clearTimeout(R.current),F!==""&&(R.current=window.setTimeout(()=>W(""),1e3))})(H),ce&&setTimeout(()=>ce.focus())};m.useEffect(()=>()=>window.clearTimeout(R.current),[]),Mi();const $=m.useCallback(P=>{var Q,M;return V.current===((Q=q.current)==null?void 0:Q.side)&&Nw(P,(M=q.current)==null?void 0:M.area)},[]);return u.jsx(dw,{scope:n,searchRef:D,onItemEnter:m.useCallback(P=>{$(P)&&P.preventDefault()},[$]),onItemLeave:m.useCallback(P=>{var H;$(P)||((H=E.current)==null||H.focus(),S(null))},[$]),onTriggerLeave:m.useCallback(P=>{$(P)&&P.preventDefault()},[$]),pointerGraceTimerRef:B,onPointerGraceIntentChange:m.useCallback(P=>{q.current=P},[]),children:u.jsx(_,{...N,children:u.jsx(Yo,{asChild:!0,trapped:o,onMountAutoFocus:me(s,P=>{var H;P.preventDefault(),(H=E.current)==null||H.focus({preventScroll:!0})}),onUnmountAutoFocus:i,children:u.jsx(Go,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:c,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:p,onDismiss:h,children:u.jsx(hb,{asChild:!0,...C,dir:x.dir,orientation:"vertical",loop:r,currentTabStopId:T,onCurrentTabStopIdChange:S,onEntryFocus:me(l,P=>{x.isUsingKeyboardRef.current||P.preventDefault()}),preventScrollOnEntryFocus:!0,children:u.jsx(Mu,{role:"menu","aria-orientation":"vertical","data-state":Sd(y.open),"data-radix-menu-content":"",dir:x.dir,...b,...g,ref:A,style:{outline:"none",...g.style},onKeyDown:me(g.onKeyDown,P=>{const Q=P.target.closest("[data-radix-menu-content]")===P.currentTarget,M=P.ctrlKey||P.altKey||P.metaKey,Y=P.key.length===1;Q&&(P.key==="Tab"&&P.preventDefault(),!M&&Y&&z(P.key));const ae=E.current;if(P.target!==ae||!nw.includes(P.key))return;P.preventDefault();const ce=k().filter(G=>!G.disabled).map(G=>G.ref.current);Qu.includes(P.key)&&ce.reverse(),Tw(ce)}),onBlur:me(e.onBlur,P=>{P.currentTarget.contains(P.target)||(window.clearTimeout(R.current),D.current="")}),onPointerMove:me(e.onPointerMove,eo(P=>{const H=P.target,Q=j.current!==P.clientX;if(P.currentTarget.contains(H)&&Q){const M=P.clientX>j.current?"right":"left";V.current=M,j.current=P.clientX}}))})})})})})})});sd.displayName=Qt;var mw="MenuGroup",aa=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(Ee.div,{role:"group",...r,ref:t})});aa.displayName=mw;var gw="MenuLabel",id=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(Ee.div,{...r,ref:t})});id.displayName=gw;var ys="MenuItem",ad="menu.itemSelect",vs=m.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...o}=e,s=m.useRef(null),i=Zr(ys,e.__scopeMenu),a=sa(ys,e.__scopeMenu),l=Ve(t,s),c=m.useRef(!1),d=()=>{const f=s.current;if(!n&&f){const p=new CustomEvent(ad,{bubbles:!0,cancelable:!0});f.addEventListener(ad,h=>r==null?void 0:r(h),{once:!0}),Bc(f,p),p.defaultPrevented?c.current=!1:i.onClose()}};return u.jsx(ld,{...o,ref:l,disabled:n,onClick:me(e.onClick,d),onPointerDown:f=>{var p;(p=e.onPointerDown)==null||p.call(e,f),c.current=!0},onPointerUp:me(e.onPointerUp,f=>{var p;c.current||(p=f.currentTarget)==null||p.click()}),onKeyDown:me(e.onKeyDown,f=>{const p=a.searchRef.current!=="";n||p&&f.key===" "||na.includes(f.key)&&(f.currentTarget.click(),f.preventDefault())})})});vs.displayName=ys;var ld=m.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:o,...s}=e,i=sa(ys,n),a=td(n),l=m.useRef(null),c=Ve(t,l),[d,f]=m.useState(!1),[p,h]=m.useState("");return m.useEffect(()=>{const v=l.current;v&&h((v.textContent??"").trim())},[s.children]),u.jsx(Jr.ItemSlot,{scope:n,disabled:r,textValue:o??p,children:u.jsx(mb,{asChild:!0,...a,focusable:!r,children:u.jsx(Ee.div,{role:"menuitem","data-highlighted":d?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:c,onPointerMove:me(e.onPointerMove,eo(v=>{r?i.onItemLeave(v):(i.onItemEnter(v),v.defaultPrevented||v.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:me(e.onPointerLeave,eo(v=>i.onItemLeave(v))),onFocus:me(e.onFocus,()=>f(!0)),onBlur:me(e.onBlur,()=>f(!1))})})})}),xw="MenuCheckboxItem",cd=m.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...o}=e;return u.jsx(hd,{scope:e.__scopeMenu,checked:n,children:u.jsx(vs,{role:"menuitemcheckbox","aria-checked":bs(n)?"mixed":n,...o,ref:t,"data-state":ca(n),onSelect:me(o.onSelect,()=>r==null?void 0:r(bs(n)?!0:!n),{checkForDefaultPrevented:!1})})})});cd.displayName=xw;var ud="MenuRadioGroup",[yw,vw]=Jn(ud,{value:void 0,onValueChange:()=>{}}),dd=m.forwardRef((e,t)=>{const{value:n,onValueChange:r,...o}=e,s=Nt(r);return u.jsx(yw,{scope:e.__scopeMenu,value:n,onValueChange:s,children:u.jsx(aa,{...o,ref:t})})});dd.displayName=ud;var fd="MenuRadioItem",pd=m.forwardRef((e,t)=>{const{value:n,...r}=e,o=vw(fd,e.__scopeMenu),s=n===o.value;return u.jsx(hd,{scope:e.__scopeMenu,checked:s,children:u.jsx(vs,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":ca(s),onSelect:me(r.onSelect,()=>{var i;return(i=o.onValueChange)==null?void 0:i.call(o,n)},{checkForDefaultPrevented:!1})})})});pd.displayName=fd;var la="MenuItemIndicator",[hd,bw]=Jn(la,{checked:!1}),md=m.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...o}=e,s=bw(la,n);return u.jsx(Zt,{present:r||bs(s.checked)||s.checked===!0,children:u.jsx(Ee.span,{...o,ref:t,"data-state":ca(s.checked)})})});md.displayName=la;var ww="MenuSeparator",gd=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(Ee.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});gd.displayName=ww;var Sw="MenuArrow",xd=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=xs(n);return u.jsx(Ru,{...o,...r,ref:t})});xd.displayName=Sw;var Cw="MenuSub",[mE,yd]=Jn(Cw),Qr="MenuSubTrigger",vd=m.forwardRef((e,t)=>{const n=Zn(Qr,e.__scopeMenu),r=Zr(Qr,e.__scopeMenu),o=yd(Qr,e.__scopeMenu),s=sa(Qr,e.__scopeMenu),i=m.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:l}=s,c={__scopeMenu:e.__scopeMenu},d=m.useCallback(()=>{i.current&&window.clearTimeout(i.current),i.current=null},[]);return m.useEffect(()=>d,[d]),m.useEffect(()=>{const f=a.current;return()=>{window.clearTimeout(f),l(null)}},[a,l]),u.jsx(ra,{asChild:!0,...c,children:u.jsx(ld,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":o.contentId,"data-state":Sd(n.open),...e,ref:_n(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:me(e.onPointerMove,eo(f=>{s.onItemEnter(f),!f.defaultPrevented&&!e.disabled&&!n.open&&!i.current&&(s.onPointerGraceIntentChange(null),i.current=window.setTimeout(()=>{n.onOpenChange(!0),d()},100))})),onPointerLeave:me(e.onPointerLeave,eo(f=>{var h,v;d();const p=(h=n.content)==null?void 0:h.getBoundingClientRect();if(p){const g=(v=n.content)==null?void 0:v.dataset.side,y=g==="right",x=y?-5:5,b=p[y?"left":"right"],C=p[y?"right":"left"];s.onPointerGraceIntentChange({area:[{x:f.clientX+x,y:f.clientY},{x:b,y:p.top},{x:C,y:p.top},{x:C,y:p.bottom},{x:b,y:p.bottom}],side:g}),window.clearTimeout(a.current),a.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(f),f.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:me(e.onKeyDown,f=>{var h;const p=s.searchRef.current!=="";e.disabled||p&&f.key===" "||rw[r.dir].includes(f.key)&&(n.onOpenChange(!0),(h=n.content)==null||h.focus(),f.preventDefault())})})})});vd.displayName=Qr;var bd="MenuSubContent",wd=m.forwardRef((e,t)=>{const n=rd(Qt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Zn(Qt,e.__scopeMenu),i=Zr(Qt,e.__scopeMenu),a=yd(bd,e.__scopeMenu),l=m.useRef(null),c=Ve(t,l);return u.jsx(Jr.Provider,{scope:e.__scopeMenu,children:u.jsx(Zt,{present:r||s.open,children:u.jsx(Jr.Slot,{scope:e.__scopeMenu,children:u.jsx(ia,{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:me(e.onFocusOutside,d=>{d.target!==a.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:me(e.onEscapeKeyDown,d=>{i.onClose(),d.preventDefault()}),onKeyDown:me(e.onKeyDown,d=>{var h;const f=d.currentTarget.contains(d.target),p=ow[i.dir].includes(d.key);f&&p&&(s.onOpenChange(!1),(h=a.trigger)==null||h.focus(),d.preventDefault())})})})})})});wd.displayName=bd;function Sd(e){return e?"open":"closed"}function bs(e){return e==="indeterminate"}function ca(e){return bs(e)?"indeterminate":e?"checked":"unchecked"}function Tw(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function kw(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function Ew(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=kw(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 Iw(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 Nw(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return Iw(n,t)}function eo(e){return t=>t.pointerType==="mouse"?e(t):void 0}var Aw=nd,jw=ra,_w=od,Mw=sd,Rw=aa,Pw=id,Ow=vs,Dw=cd,Lw=dd,$w=pd,Fw=md,Bw=gd,zw=xd,Uw=vd,Hw=wd,ws="DropdownMenu",[Ww,gE]=kn(ws,[ed]),Ft=ed(),[Vw,Cd]=Ww(ws),Td=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:o,defaultOpen:s,onOpenChange:i,modal:a=!0}=e,l=Ft(t),c=m.useRef(null),[d,f]=yr({prop:o,defaultProp:s??!1,onChange:i,caller:ws});return u.jsx(Vw,{scope:t,triggerId:$t(),triggerRef:c,contentId:$t(),open:d,onOpenChange:f,onOpenToggle:m.useCallback(()=>f(p=>!p),[f]),modal:a,children:u.jsx(Aw,{...l,open:d,onOpenChange:f,dir:r,modal:a,children:n})})};Td.displayName=ws;var kd="DropdownMenuTrigger",Ed=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...o}=e,s=Cd(kd,n),i=Ft(n);return u.jsx(jw,{asChild:!0,...i,children:u.jsx(Ee.button,{type:"button",id:s.triggerId,"aria-haspopup":"menu","aria-expanded":s.open,"aria-controls":s.open?s.contentId:void 0,"data-state":s.open?"open":"closed","data-disabled":r?"":void 0,disabled:r,...o,ref:_n(t,s.triggerRef),onPointerDown:me(e.onPointerDown,a=>{!r&&a.button===0&&a.ctrlKey===!1&&(s.onOpenToggle(),s.open||a.preventDefault())}),onKeyDown:me(e.onKeyDown,a=>{r||(["Enter"," "].includes(a.key)&&s.onOpenToggle(),a.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(a.key)&&a.preventDefault())})})})});Ed.displayName=kd;var Kw="DropdownMenuPortal",Id=e=>{const{__scopeDropdownMenu:t,...n}=e,r=Ft(t);return u.jsx(_w,{...r,...n})};Id.displayName=Kw;var Nd="DropdownMenuContent",Ad=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Cd(Nd,n),s=Ft(n),i=m.useRef(!1);return u.jsx(Mw,{id:o.contentId,"aria-labelledby":o.triggerId,...s,...r,ref:t,onCloseAutoFocus:me(e.onCloseAutoFocus,a=>{var l;i.current||(l=o.triggerRef.current)==null||l.focus(),i.current=!1,a.preventDefault()}),onInteractOutside:me(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)"}})});Ad.displayName=Nd;var qw="DropdownMenuGroup",Gw=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ft(n);return u.jsx(Rw,{...o,...r,ref:t})});Gw.displayName=qw;var Yw="DropdownMenuLabel",jd=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ft(n);return u.jsx(Pw,{...o,...r,ref:t})});jd.displayName=Yw;var Xw="DropdownMenuItem",_d=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ft(n);return u.jsx(Ow,{...o,...r,ref:t})});_d.displayName=Xw;var Jw="DropdownMenuCheckboxItem",Md=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ft(n);return u.jsx(Dw,{...o,...r,ref:t})});Md.displayName=Jw;var Zw="DropdownMenuRadioGroup",Qw=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ft(n);return u.jsx(Lw,{...o,...r,ref:t})});Qw.displayName=Zw;var e0="DropdownMenuRadioItem",Rd=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ft(n);return u.jsx($w,{...o,...r,ref:t})});Rd.displayName=e0;var t0="DropdownMenuItemIndicator",Pd=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ft(n);return u.jsx(Fw,{...o,...r,ref:t})});Pd.displayName=t0;var n0="DropdownMenuSeparator",Od=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ft(n);return u.jsx(Bw,{...o,...r,ref:t})});Od.displayName=n0;var r0="DropdownMenuArrow",o0=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ft(n);return u.jsx(zw,{...o,...r,ref:t})});o0.displayName=r0;var s0="DropdownMenuSubTrigger",Dd=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ft(n);return u.jsx(Uw,{...o,...r,ref:t})});Dd.displayName=s0;var i0="DropdownMenuSubContent",Ld=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ft(n);return u.jsx(Hw,{...o,...r,ref:t,style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});Ld.displayName=i0;var a0=Td,l0=Ed,c0=Id,$d=Ad,Fd=jd,Bd=_d,zd=Md,Ud=Rd,Hd=Pd,Wd=Od,Vd=Dd,Kd=Ld;const ua=a0,da=l0,u0=m.forwardRef(({className:e,inset:t,children:n,...r},o)=>u.jsxs(Vd,{ref:o,className:se("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(ue.ChevronRight,{className:"ml-auto h-4 w-4"})]}));u0.displayName=Vd.displayName;const d0=m.forwardRef(({className:e,...t},n)=>u.jsx(Kd,{ref:n,className:se("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}));d0.displayName=Kd.displayName;const Ss=m.forwardRef(({className:e,sideOffset:t=4,...n},r)=>u.jsx(c0,{children:u.jsx($d,{ref:r,sideOffset:t,className:se("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})}));Ss.displayName=$d.displayName;const Qn=m.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(Bd,{ref:r,className:se("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}));Qn.displayName=Bd.displayName;const f0=m.forwardRef(({className:e,children:t,checked:n,...r},o)=>u.jsxs(zd,{ref:o,className:se("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),checked:n,...r,children:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(Hd,{children:u.jsx(ue.Check,{className:"h-4 w-4"})})}),t]}));f0.displayName=zd.displayName;const p0=m.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Ud,{ref:r,className:se("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(Hd,{children:u.jsx(ue.Circle,{className:"h-2 w-2 fill-current"})})}),t]}));p0.displayName=Ud.displayName;const h0=m.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(Fd,{ref:r,className:se("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));h0.displayName=Fd.displayName;const m0=m.forwardRef(({className:e,...t},n)=>u.jsx(Wd,{ref:n,className:se("-mx-1 my-1 h-px bg-muted",e),...t}));m0.displayName=Wd.displayName;function g0(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 x0(e){const t=new Map,n=g0(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 y0(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 v0(e,t){if(!e||typeof e!="object")return null;const n=e[t];return typeof n=="string"&&n.trim()?n:null}function b0(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 w0(e){const t=Array.isArray(e)?e.map(r=>{const o=b0(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 S0(e){const t=w.useMemo(()=>w0(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"),v=v0(f.metadata,"source"),g={id:p,step:h,source:v,createdAt:f.createdAt??null,namespace:f.checkpointNs??null,parentId:f.parentId??null};if(i.set(p,g),h!==null&&v){const y=`${h}:${v}`,x=a.get(y)??[];x.push(g),a.set(y,x)}}const c=x0(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=y0(l);return{checkpointMetaById:i,checkpointIndexByKey:a,attemptMetaById:l,userMessageIdToAttempts:d}},[t]);return{checkpointMetaById:n,checkpointIndexByKey:r,attemptMetaById:o,userMessageIdToAttempts:s}}const Ts=1e4;function C0(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
|
+
`)},Zb=0,Sr=[];function Qb(e){var t=m.useRef([]),n=m.useRef([0,0]),r=m.useRef(),o=m.useState(Zb++)[0],s=m.useState(Vu)[0],i=m.useRef(e);m.useEffect(function(){i.current=e},[e]),m.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(o));var g=bb([e.lockRef.current],(e.shards||[]).map(Zu),!0).filter(Boolean);return g.forEach(function(y){return y.classList.add("allow-interactivity-".concat(o))}),function(){document.body.classList.remove("block-interactivity-".concat(o)),g.forEach(function(y){return y.classList.remove("allow-interactivity-".concat(o))})}}},[e.inert,e.lockRef.current,e.shards]);var a=m.useCallback(function(g,y){if("touches"in g&&g.touches.length===2||g.type==="wheel"&&g.ctrlKey)return!i.current.allowPinchZoom;var x=us(g),b=n.current,C="deltaX"in g?g.deltaX:b[0]-x[0],k="deltaY"in g?g.deltaY:b[1]-x[1],S,T=g.target,E=Math.abs(C)>Math.abs(k)?"h":"v";if("touches"in g&&E==="h"&&T.type==="range")return!1;var j=Gu(E,T);if(!j)return!0;if(j?S=E:(S=E==="v"?"h":"v",j=Gu(E,T)),!j)return!1;if(!r.current&&"changedTouches"in g&&(C||k)&&(r.current=S),!S)return!0;var R=r.current||S;return Yb(R,y,g,R==="h"?C:k)},[]),l=m.useCallback(function(g){var y=g;if(!(!Sr.length||Sr[Sr.length-1]!==s)){var x="deltaY"in y?Ju(y):us(y),b=t.current.filter(function(S){return S.name===y.type&&(S.target===y.target||y.target===S.shadowParent)&&Xb(S.delta,x)})[0];if(b&&b.should){y.cancelable&&y.preventDefault();return}if(!b){var C=(i.current.shards||[]).map(Zu).filter(Boolean).filter(function(S){return S.contains(y.target)}),k=C.length>0?a(y,C[0]):!i.current.noIsolation;k&&y.cancelable&&y.preventDefault()}}},[]),c=m.useCallback(function(g,y,x,b){var C={name:g,delta:y,target:x,should:b,shadowParent:ew(x)};t.current.push(C),setTimeout(function(){t.current=t.current.filter(function(k){return k!==C})},1)},[]),d=m.useCallback(function(g){n.current=us(g),r.current=void 0},[]),f=m.useCallback(function(g){c(g.type,Ju(g),g.target,a(g,e.lockRef.current))},[]),h=m.useCallback(function(g){c(g.type,us(g),g.target,a(g,e.lockRef.current))},[]);m.useEffect(function(){return Sr.push(s),e.setCallbacks({onScrollCapture:f,onWheelCapture:f,onTouchMoveCapture:h}),document.addEventListener("wheel",l,wr),document.addEventListener("touchmove",l,wr),document.addEventListener("touchstart",d,wr),function(){Sr=Sr.filter(function(g){return g!==s}),document.removeEventListener("wheel",l,wr),document.removeEventListener("touchmove",l,wr),document.removeEventListener("touchstart",d,wr)}},[]);var p=e.removeScrollBar,v=e.inert;return m.createElement(m.Fragment,null,v?m.createElement(s,{styles:Jb(o)}):null,p?m.createElement(Ub,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function ew(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const tw=Ab(Wu,Qb);var ds=m.forwardRef(function(e,t){return m.createElement(ls,yn({},e,{ref:t,sideCar:tw}))});ds.classNames=ls.classNames;var Qi=["Enter"," "],nw=["ArrowDown","PageUp","Home"],Qu=["ArrowUp","PageDown","End"],rw=[...nw,...Qu],ow={ltr:[...Qi,"ArrowRight"],rtl:[...Qi,"ArrowLeft"]},sw={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Hr="Menu",[Wr,iw,aw]=Ei(Hr),[Yn,ed]=Tn(Hr,[aw,ts,Ou]),fs=ts(),td=Ou(),[lw,Xn]=Yn(Hr),[cw,Vr]=Yn(Hr),nd=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=fs(t),[l,c]=m.useState(null),d=m.useRef(!1),f=Nt(s),h=Uo(o);return m.useEffect(()=>{const p=()=>{d.current=!0,document.addEventListener("pointerdown",v,{capture:!0,once:!0}),document.addEventListener("pointermove",v,{capture:!0,once:!0})},v=()=>d.current=!1;return document.addEventListener("keydown",p,{capture:!0}),()=>{document.removeEventListener("keydown",p,{capture:!0}),document.removeEventListener("pointerdown",v,{capture:!0}),document.removeEventListener("pointermove",v,{capture:!0})}},[]),u.jsx(ju,{...a,children:u.jsx(lw,{scope:t,open:n,onOpenChange:f,content:l,onContentChange:c,children:u.jsx(cw,{scope:t,onClose:m.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:d,dir:h,modal:i,children:r})})})};nd.displayName=Hr;var uw="MenuAnchor",ea=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=fs(n);return u.jsx(_u,{...o,...r,ref:t})});ea.displayName=uw;var ta="MenuPortal",[dw,rd]=Yn(ta,{forceMount:void 0}),od=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:o}=e,s=Xn(ta,t);return u.jsx(dw,{scope:t,forceMount:n,children:u.jsx(Jt,{present:n||s.open,children:u.jsx(ns,{asChild:!0,container:o,children:r})})})};od.displayName=ta;var Zt="MenuContent",[fw,na]=Yn(Zt),sd=m.forwardRef((e,t)=>{const n=rd(Zt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Xn(Zt,e.__scopeMenu),i=Vr(Zt,e.__scopeMenu);return u.jsx(Wr.Provider,{scope:e.__scopeMenu,children:u.jsx(Jt,{present:r||s.open,children:u.jsx(Wr.Slot,{scope:e.__scopeMenu,children:i.modal?u.jsx(hw,{...o,ref:t}):u.jsx(pw,{...o,ref:t})})})})}),hw=m.forwardRef((e,t)=>{const n=Xn(Zt,e.__scopeMenu),r=m.useRef(null),o=Ve(t,r);return m.useEffect(()=>{const s=r.current;if(s)return Gi(s)},[]),u.jsx(ra,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:he(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),pw=m.forwardRef((e,t)=>{const n=Xn(Zt,e.__scopeMenu);return u.jsx(ra,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),mw=Wn.createSlot("MenuContent.ScrollLock"),ra=m.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:o,onOpenAutoFocus:s,onCloseAutoFocus:i,disableOutsidePointerEvents:a,onEntryFocus:l,onEscapeKeyDown:c,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:h,onDismiss:p,disableOutsideScroll:v,...g}=e,y=Xn(Zt,n),x=Vr(Zt,n),b=fs(n),C=td(n),k=iw(n),[S,T]=m.useState(null),E=m.useRef(null),j=Ve(t,E,y.onContentChange),R=m.useRef(0),O=m.useRef(""),B=m.useRef(0),q=m.useRef(null),K=m.useRef("right"),P=m.useRef(0),M=v?ds:m.Fragment,I=v?{as:mw,allowPinchZoom:!0}:void 0,z=A=>{var Y,D;const $=O.current+A,H=k().filter(V=>!V.disabled),_=document.activeElement,G=(Y=H.find(V=>V.ref.current===_))==null?void 0:Y.textValue,re=H.map(V=>V.textValue),ee=Iw(re,$,G),ie=(D=H.find(V=>V.textValue===ee))==null?void 0:D.ref.current;(function V(U){O.current=U,window.clearTimeout(R.current),U!==""&&(R.current=window.setTimeout(()=>V(""),1e3))})($),ie&&setTimeout(()=>ie.focus())};m.useEffect(()=>()=>window.clearTimeout(R.current),[]),Ai();const L=m.useCallback(A=>{var H,_;return K.current===((H=q.current)==null?void 0:H.side)&&Aw(A,(_=q.current)==null?void 0:_.area)},[]);return u.jsx(fw,{scope:n,searchRef:O,onItemEnter:m.useCallback(A=>{L(A)&&A.preventDefault()},[L]),onItemLeave:m.useCallback(A=>{var $;L(A)||(($=E.current)==null||$.focus(),T(null))},[L]),onTriggerLeave:m.useCallback(A=>{L(A)&&A.preventDefault()},[L]),pointerGraceTimerRef:B,onPointerGraceIntentChange:m.useCallback(A=>{q.current=A},[]),children:u.jsx(M,{...I,children:u.jsx(Wo,{asChild:!0,trapped:o,onMountAutoFocus:he(s,A=>{var $;A.preventDefault(),($=E.current)==null||$.focus({preventScroll:!0})}),onUnmountAutoFocus:i,children:u.jsx(Ho,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:c,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:h,onDismiss:p,children:u.jsx(mb,{asChild:!0,...C,dir:x.dir,orientation:"vertical",loop:r,currentTabStopId:S,onCurrentTabStopIdChange:T,onEntryFocus:he(l,A=>{x.isUsingKeyboardRef.current||A.preventDefault()}),preventScrollOnEntryFocus:!0,children:u.jsx(Mu,{role:"menu","aria-orientation":"vertical","data-state":Sd(y.open),"data-radix-menu-content":"",dir:x.dir,...b,...g,ref:j,style:{outline:"none",...g.style},onKeyDown:he(g.onKeyDown,A=>{const H=A.target.closest("[data-radix-menu-content]")===A.currentTarget,_=A.ctrlKey||A.altKey||A.metaKey,G=A.key.length===1;H&&(A.key==="Tab"&&A.preventDefault(),!_&&G&&z(A.key));const re=E.current;if(A.target!==re||!rw.includes(A.key))return;A.preventDefault();const ie=k().filter(Y=>!Y.disabled).map(Y=>Y.ref.current);Qu.includes(A.key)&&ie.reverse(),kw(ie)}),onBlur:he(e.onBlur,A=>{A.currentTarget.contains(A.target)||(window.clearTimeout(R.current),O.current="")}),onPointerMove:he(e.onPointerMove,qr(A=>{const $=A.target,H=P.current!==A.clientX;if(A.currentTarget.contains($)&&H){const _=A.clientX>P.current?"right":"left";K.current=_,P.current=A.clientX}}))})})})})})})});sd.displayName=Zt;var gw="MenuGroup",oa=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(Se.div,{role:"group",...r,ref:t})});oa.displayName=gw;var xw="MenuLabel",id=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(Se.div,{...r,ref:t})});id.displayName=xw;var hs="MenuItem",ad="menu.itemSelect",ps=m.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...o}=e,s=m.useRef(null),i=Vr(hs,e.__scopeMenu),a=na(hs,e.__scopeMenu),l=Ve(t,s),c=m.useRef(!1),d=()=>{const f=s.current;if(!n&&f){const h=new CustomEvent(ad,{bubbles:!0,cancelable:!0});f.addEventListener(ad,p=>r==null?void 0:r(p),{once:!0}),Bc(f,h),h.defaultPrevented?c.current=!1:i.onClose()}};return u.jsx(ld,{...o,ref:l,disabled:n,onClick:he(e.onClick,d),onPointerDown:f=>{var h;(h=e.onPointerDown)==null||h.call(e,f),c.current=!0},onPointerUp:he(e.onPointerUp,f=>{var h;c.current||(h=f.currentTarget)==null||h.click()}),onKeyDown:he(e.onKeyDown,f=>{const h=a.searchRef.current!=="";n||h&&f.key===" "||Qi.includes(f.key)&&(f.currentTarget.click(),f.preventDefault())})})});ps.displayName=hs;var ld=m.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:o,...s}=e,i=na(hs,n),a=td(n),l=m.useRef(null),c=Ve(t,l),[d,f]=m.useState(!1),[h,p]=m.useState("");return m.useEffect(()=>{const v=l.current;v&&p((v.textContent??"").trim())},[s.children]),u.jsx(Wr.ItemSlot,{scope:n,disabled:r,textValue:o??h,children:u.jsx(gb,{asChild:!0,...a,focusable:!r,children:u.jsx(Se.div,{role:"menuitem","data-highlighted":d?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:c,onPointerMove:he(e.onPointerMove,qr(v=>{r?i.onItemLeave(v):(i.onItemEnter(v),v.defaultPrevented||v.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:he(e.onPointerLeave,qr(v=>i.onItemLeave(v))),onFocus:he(e.onFocus,()=>f(!0)),onBlur:he(e.onBlur,()=>f(!1))})})})}),yw="MenuCheckboxItem",cd=m.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...o}=e;return u.jsx(pd,{scope:e.__scopeMenu,checked:n,children:u.jsx(ps,{role:"menuitemcheckbox","aria-checked":ms(n)?"mixed":n,...o,ref:t,"data-state":ia(n),onSelect:he(o.onSelect,()=>r==null?void 0:r(ms(n)?!0:!n),{checkForDefaultPrevented:!1})})})});cd.displayName=yw;var ud="MenuRadioGroup",[vw,bw]=Yn(ud,{value:void 0,onValueChange:()=>{}}),dd=m.forwardRef((e,t)=>{const{value:n,onValueChange:r,...o}=e,s=Nt(r);return u.jsx(vw,{scope:e.__scopeMenu,value:n,onValueChange:s,children:u.jsx(oa,{...o,ref:t})})});dd.displayName=ud;var fd="MenuRadioItem",hd=m.forwardRef((e,t)=>{const{value:n,...r}=e,o=bw(fd,e.__scopeMenu),s=n===o.value;return u.jsx(pd,{scope:e.__scopeMenu,checked:s,children:u.jsx(ps,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":ia(s),onSelect:he(r.onSelect,()=>{var i;return(i=o.onValueChange)==null?void 0:i.call(o,n)},{checkForDefaultPrevented:!1})})})});hd.displayName=fd;var sa="MenuItemIndicator",[pd,ww]=Yn(sa,{checked:!1}),md=m.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...o}=e,s=ww(sa,n);return u.jsx(Jt,{present:r||ms(s.checked)||s.checked===!0,children:u.jsx(Se.span,{...o,ref:t,"data-state":ia(s.checked)})})});md.displayName=sa;var Sw="MenuSeparator",gd=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(Se.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});gd.displayName=Sw;var Cw="MenuArrow",xd=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=fs(n);return u.jsx(Ru,{...o,...r,ref:t})});xd.displayName=Cw;var Tw="MenuSub",[bE,yd]=Yn(Tw),Kr="MenuSubTrigger",vd=m.forwardRef((e,t)=>{const n=Xn(Kr,e.__scopeMenu),r=Vr(Kr,e.__scopeMenu),o=yd(Kr,e.__scopeMenu),s=na(Kr,e.__scopeMenu),i=m.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:l}=s,c={__scopeMenu:e.__scopeMenu},d=m.useCallback(()=>{i.current&&window.clearTimeout(i.current),i.current=null},[]);return m.useEffect(()=>d,[d]),m.useEffect(()=>{const f=a.current;return()=>{window.clearTimeout(f),l(null)}},[a,l]),u.jsx(ea,{asChild:!0,...c,children:u.jsx(ld,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":o.contentId,"data-state":Sd(n.open),...e,ref:An(t,o.onTriggerChange),onClick:f=>{var h;(h=e.onClick)==null||h.call(e,f),!(e.disabled||f.defaultPrevented)&&(f.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:he(e.onPointerMove,qr(f=>{s.onItemEnter(f),!f.defaultPrevented&&!e.disabled&&!n.open&&!i.current&&(s.onPointerGraceIntentChange(null),i.current=window.setTimeout(()=>{n.onOpenChange(!0),d()},100))})),onPointerLeave:he(e.onPointerLeave,qr(f=>{var p,v;d();const h=(p=n.content)==null?void 0:p.getBoundingClientRect();if(h){const g=(v=n.content)==null?void 0:v.dataset.side,y=g==="right",x=y?-5:5,b=h[y?"left":"right"],C=h[y?"right":"left"];s.onPointerGraceIntentChange({area:[{x:f.clientX+x,y:f.clientY},{x:b,y:h.top},{x:C,y:h.top},{x:C,y:h.bottom},{x:b,y:h.bottom}],side:g}),window.clearTimeout(a.current),a.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(f),f.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:he(e.onKeyDown,f=>{var p;const h=s.searchRef.current!=="";e.disabled||h&&f.key===" "||ow[r.dir].includes(f.key)&&(n.onOpenChange(!0),(p=n.content)==null||p.focus(),f.preventDefault())})})})});vd.displayName=Kr;var bd="MenuSubContent",wd=m.forwardRef((e,t)=>{const n=rd(Zt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Xn(Zt,e.__scopeMenu),i=Vr(Zt,e.__scopeMenu),a=yd(bd,e.__scopeMenu),l=m.useRef(null),c=Ve(t,l);return u.jsx(Wr.Provider,{scope:e.__scopeMenu,children:u.jsx(Jt,{present:r||s.open,children:u.jsx(Wr.Slot,{scope:e.__scopeMenu,children:u.jsx(ra,{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:he(e.onFocusOutside,d=>{d.target!==a.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:he(e.onEscapeKeyDown,d=>{i.onClose(),d.preventDefault()}),onKeyDown:he(e.onKeyDown,d=>{var p;const f=d.currentTarget.contains(d.target),h=sw[i.dir].includes(d.key);f&&h&&(s.onOpenChange(!1),(p=a.trigger)==null||p.focus(),d.preventDefault())})})})})})});wd.displayName=bd;function Sd(e){return e?"open":"closed"}function ms(e){return e==="indeterminate"}function ia(e){return ms(e)?"indeterminate":e?"checked":"unchecked"}function kw(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function Ew(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function Iw(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=Ew(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 Nw(e,t){const{x:n,y:r}=e;let o=!1;for(let s=0,i=t.length-1;s<t.length;i=s++){const a=t[s],l=t[i],c=a.x,d=a.y,f=l.x,h=l.y;d>r!=h>r&&n<(f-c)*(r-d)/(h-d)+c&&(o=!o)}return o}function Aw(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return Nw(n,t)}function qr(e){return t=>t.pointerType==="mouse"?e(t):void 0}var jw=nd,_w=ea,Mw=od,Rw=sd,Pw=oa,Ow=id,Dw=ps,Lw=cd,$w=dd,Fw=hd,Bw=md,zw=gd,Uw=xd,Hw=vd,Ww=wd,gs="DropdownMenu",[Vw,wE]=Tn(gs,[ed]),Ft=ed(),[Kw,Cd]=Vw(gs),Td=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:o,defaultOpen:s,onOpenChange:i,modal:a=!0}=e,l=Ft(t),c=m.useRef(null),[d,f]=pr({prop:o,defaultProp:s??!1,onChange:i,caller:gs});return u.jsx(Kw,{scope:t,triggerId:$t(),triggerRef:c,contentId:$t(),open:d,onOpenChange:f,onOpenToggle:m.useCallback(()=>f(h=>!h),[f]),modal:a,children:u.jsx(jw,{...l,open:d,onOpenChange:f,dir:r,modal:a,children:n})})};Td.displayName=gs;var kd="DropdownMenuTrigger",Ed=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...o}=e,s=Cd(kd,n),i=Ft(n);return u.jsx(_w,{asChild:!0,...i,children:u.jsx(Se.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:An(t,s.triggerRef),onPointerDown:he(e.onPointerDown,a=>{!r&&a.button===0&&a.ctrlKey===!1&&(s.onOpenToggle(),s.open||a.preventDefault())}),onKeyDown:he(e.onKeyDown,a=>{r||(["Enter"," "].includes(a.key)&&s.onOpenToggle(),a.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(a.key)&&a.preventDefault())})})})});Ed.displayName=kd;var qw="DropdownMenuPortal",Id=e=>{const{__scopeDropdownMenu:t,...n}=e,r=Ft(t);return u.jsx(Mw,{...r,...n})};Id.displayName=qw;var Nd="DropdownMenuContent",Ad=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Cd(Nd,n),s=Ft(n),i=m.useRef(!1);return u.jsx(Rw,{id:o.contentId,"aria-labelledby":o.triggerId,...s,...r,ref:t,onCloseAutoFocus:he(e.onCloseAutoFocus,a=>{var l;i.current||(l=o.triggerRef.current)==null||l.focus(),i.current=!1,a.preventDefault()}),onInteractOutside:he(e.onInteractOutside,a=>{const l=a.detail.originalEvent,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)"}})});Ad.displayName=Nd;var Gw="DropdownMenuGroup",Yw=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ft(n);return u.jsx(Pw,{...o,...r,ref:t})});Yw.displayName=Gw;var Xw="DropdownMenuLabel",jd=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ft(n);return u.jsx(Ow,{...o,...r,ref:t})});jd.displayName=Xw;var Jw="DropdownMenuItem",_d=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ft(n);return u.jsx(Dw,{...o,...r,ref:t})});_d.displayName=Jw;var Zw="DropdownMenuCheckboxItem",Md=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ft(n);return u.jsx(Lw,{...o,...r,ref:t})});Md.displayName=Zw;var Qw="DropdownMenuRadioGroup",e0=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ft(n);return u.jsx($w,{...o,...r,ref:t})});e0.displayName=Qw;var t0="DropdownMenuRadioItem",Rd=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ft(n);return u.jsx(Fw,{...o,...r,ref:t})});Rd.displayName=t0;var n0="DropdownMenuItemIndicator",Pd=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ft(n);return u.jsx(Bw,{...o,...r,ref:t})});Pd.displayName=n0;var r0="DropdownMenuSeparator",Od=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ft(n);return u.jsx(zw,{...o,...r,ref:t})});Od.displayName=r0;var o0="DropdownMenuArrow",s0=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ft(n);return u.jsx(Uw,{...o,...r,ref:t})});s0.displayName=o0;var i0="DropdownMenuSubTrigger",Dd=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ft(n);return u.jsx(Hw,{...o,...r,ref:t})});Dd.displayName=i0;var a0="DropdownMenuSubContent",Ld=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ft(n);return u.jsx(Ww,{...o,...r,ref:t,style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});Ld.displayName=a0;var l0=Td,c0=Ed,u0=Id,$d=Ad,Fd=jd,Bd=_d,zd=Md,Ud=Rd,Hd=Pd,Wd=Od,Vd=Dd,Kd=Ld;const aa=l0,la=c0,d0=m.forwardRef(({className:e,inset:t,children:n,...r},o)=>u.jsxs(Vd,{ref:o,className:oe("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(ae.ChevronRight,{className:"ml-auto h-4 w-4"})]}));d0.displayName=Vd.displayName;const f0=m.forwardRef(({className:e,...t},n)=>u.jsx(Kd,{ref:n,className:oe("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}));f0.displayName=Kd.displayName;const xs=m.forwardRef(({className:e,sideOffset:t=4,...n},r)=>u.jsx(u0,{children:u.jsx($d,{ref:r,sideOffset:t,className:oe("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})}));xs.displayName=$d.displayName;const Jn=m.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(Bd,{ref:r,className:oe("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}));Jn.displayName=Bd.displayName;const h0=m.forwardRef(({className:e,children:t,checked:n,...r},o)=>u.jsxs(zd,{ref:o,className:oe("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),checked:n,...r,children:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(Hd,{children:u.jsx(ae.Check,{className:"h-4 w-4"})})}),t]}));h0.displayName=zd.displayName;const p0=m.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Ud,{ref:r,className:oe("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(Hd,{children:u.jsx(ae.Circle,{className:"h-2 w-2 fill-current"})})}),t]}));p0.displayName=Ud.displayName;const m0=m.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(Fd,{ref:r,className:oe("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));m0.displayName=Fd.displayName;const g0=m.forwardRef(({className:e,...t},n)=>u.jsx(Wd,{ref:n,className:oe("-mx-1 my-1 h-px bg-muted",e),...t}));g0.displayName=Wd.displayName;function x0(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 y0(e){const t=new Map,n=x0(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 v0(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 ys(e,t){if(!e||typeof e!="object")return null;const n=e[t];return typeof n=="number"?n:null}function b0(e,t){if(!e||typeof e!="object")return null;const n=e[t];return typeof n=="string"&&n.trim()?n:null}function w0(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 S0(e){const t=Array.isArray(e)?e.map(r=>{const o=w0(r.next);return o?{...r,metadata:{...r.metadata??{},next:o}}:r}):[];return t.some(r=>ys(r.metadata,"step")!==null)&&t.sort((r,o)=>{const s=ys(r.metadata,"step"),i=ys(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 C0(e){const t=w.useMemo(()=>S0(e),[e]),{checkpointMetaById:n,checkpointIndexByKey:r,attemptMetaById:o,userMessageIdToAttempts:s}=w.useMemo(()=>{const i=new Map,a=new Map,l=new Map;for(const f of t){const h=f.checkpointId??null;if(!h)continue;const p=ys(f.metadata,"step"),v=b0(f.metadata,"source"),g={id:h,step:p,source:v,createdAt:f.createdAt??null,namespace:f.checkpointNs??null,parentId:f.parentId??null};if(i.set(h,g),p!==null&&v){const y=`${p}:${v}`,x=a.get(y)??[];x.push(g),a.set(y,x)}}const c=y0(t);for(const[f,h]of i.entries()){const p=c.get(f);p?l.set(f,{...h,attemptIndex:p.attemptIndex,attemptCount:p.attemptCount,isLatestAttempt:p.isLatestAttempt,baseUserMessageId:p.baseUserMessageId??null}):l.set(f,{...h,attemptIndex:0,attemptCount:1,isLatestAttempt:!0,baseUserMessageId:null})}const d=v0(l);return{checkpointMetaById:i,checkpointIndexByKey:a,attemptMetaById:l,userMessageIdToAttempts:d}},[t]);return{checkpointMetaById:n,checkpointIndexByKey:r,attemptMetaById:o,userMessageIdToAttempts:s}}const vs=1e4;function T0(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 T0(e,t=Ts){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 k0(e){let t;return typeof e=="string"?t=e:typeof e=="object"&&e!==null?t=JSON.stringify(e):t=String(e),T0(t),C0(t)}const ks=0,On=1,Ir=2,qd=4;function Gd(e){return()=>e}function E0(e){e()}function Yd(e,t){return n=>e(t(n))}function Xd(e,t){return()=>e(t)}function I0(e,t){return n=>e(t,n)}function fa(e){return e!==void 0}function N0(...e){return()=>{e.map(E0)}}function Nr(){}function Es(e,t){return t(e),e}function A0(e,t){return t(e)}function ct(...e){return e}function rt(e,t){return e(On,t)}function Le(e,t){e(ks,t)}function pa(e){e(Ir)}function bt(e){return e(qd)}function ve(e,t){return rt(e,I0(t,ks))}function cn(e,t){const n=e(On,r=>{n(),t(r)});return n}function Jd(e){let t,n;return r=>o=>{t=o,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function Zd(e,t){return e===t}function ut(e=Zd){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function Me(e){return t=>n=>{e(n)&&t(n)}}function pe(e){return t=>Yd(t,e)}function vn(e){return t=>()=>{t(e)}}function te(e,...t){const n=j0(...t);return(r,o)=>{switch(r){case Ir:pa(e);return;case On:return rt(e,n(o))}}}function bn(e,t){return n=>r=>{n(t=e(t,r))}}function er(e){return t=>n=>{e>0?e--:t(n)}}function Nn(e){let t=null,n;return r=>o=>{t=o,!n&&(n=setTimeout(()=>{n=void 0,r(t)},e))}}function Fe(...e){const t=new Array(e.length);let n=0,r=null;const o=Math.pow(2,e.length)-1;return e.forEach((s,i)=>{const a=Math.pow(2,i);rt(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 j0(...e){return t=>e.reduceRight(A0,t)}function _0(e){let t,n;const r=()=>t==null?void 0:t();return function(o,s){switch(o){case On:return s?n===s?void 0:(r(),n=s,t=rt(e,s),t):(r(),Nr);case Ir:r(),n=null;return}}}function ie(e){let t=e;const n=Ke();return(r,o)=>{switch(r){case ks:t=o;break;case On:{o(t);break}case qd:return t}return n(r,o)}}function Rt(e,t){return Es(ie(t),n=>ve(e,n))}function Ke(){const e=[];return(t,n)=>{switch(t){case ks:e.slice().forEach(r=>{r(n)});return;case Ir:e.splice(0,e.length);return;case On:return e.push(n),()=>{const r=e.indexOf(n);r>-1&&e.splice(r,1)}}}}function Xt(e){return Es(Ke(),t=>ve(e,t))}function Je(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:M0(),singleton:n}}const M0=()=>Symbol();function R0(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 St(...e){const t=Ke(),n=new Array(e.length);let r=0;const o=Math.pow(2,e.length)-1;return e.forEach((s,i)=>{const a=Math.pow(2,i);rt(s,l=>{n[i]=l,r=r|a,r===o&&Le(t,n)})}),function(s,i){switch(s){case Ir:{pa(t);return}case On:return r===o&&i(n),rt(t,i)}}}function je(e,t=Zd){return te(e,ut(t))}function ha(...e){return function(t,n){switch(t){case Ir:return;case On:return N0(...e.map(r=>rt(r,n)))}}}var Vt=(e=>(e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR",e))(Vt||{});const P0={0:"debug",3:"error",1:"log",2:"warn"},O0=()=>typeof globalThis>"u"?window:globalThis,Dn=Je(()=>{const e=ie(3);return{log:ie((t,n,r=1)=>{var o;const s=(o=O0().VIRTUOSO_LOG_LEVEL)!=null?o:bt(e);r>=s&&console[P0[r]]("%creact-virtuoso: %c%s %o","color: #0253b3; font-weight: bold","color: initial",t,n)}),logLevel:e}},[],{singleton:!0});function tr(e,t,n){return ma(e,t,n).callbackRef}function ma(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 D0(e,t,n,r,o,s,i,a,l){const c=w.useCallback(d=>{const f=L0(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 v;h&&(v=p.ownerDocument.defaultView);const g=i?a?i.scrollLeft:i.scrollTop:h?a?v.scrollX||v.document.documentElement.scrollLeft:v.scrollY||v.document.documentElement.scrollTop:a?p.scrollLeft:p.scrollTop,y=i?a?i.scrollWidth:i.scrollHeight:h?a?v.document.documentElement.scrollWidth:v.document.documentElement.scrollHeight:a?p.scrollWidth:p.scrollHeight,x=i?a?i.offsetWidth:i.offsetHeight:h?a?v.innerWidth:v.innerHeight:a?p.offsetWidth:p.offsetHeight;r({scrollHeight:y,scrollTop:Math.max(g,0),viewportHeight:x}),s==null||s(a?Qd("column-gap",getComputedStyle(d).columnGap,o):Qd("row-gap",getComputedStyle(d).rowGap,o)),f!==null&&e(f)},[e,t,o,s,i,r,a]);return ma(c,n,l)}function L0(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},Vt.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 Qd(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Vt.WARN),t==="normal"?0:parseInt(t??"0",10)}function ef(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(),v=c.top-h.top;p=h.height-Math.max(0,v),f=v+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}=ma(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 Bt=Je(()=>{const e=Ke(),t=Ke(),n=ie(0),r=Ke(),o=ie(0),s=Ke(),i=Ke(),a=ie(0),l=ie(0),c=ie(0),d=ie(0),f=Ke(),p=Ke(),h=ie(!1),v=ie(!1),g=ie(!1);return ve(te(e,pe(({scrollTop:y})=>y)),t),ve(te(e,pe(({scrollHeight:y})=>y)),i),ve(t,o),{deviation:n,fixedFooterHeight:c,fixedHeaderHeight:l,footerHeight:d,headerHeight:a,horizontalDirection:v,scrollBy:p,scrollContainerState:e,scrollHeight:i,scrollingInProgress:h,scrollTo:f,scrollTop:t,skipAnimationFrameInResizeObserver:g,smoothScrollTargetReached:r,statefulScrollTop:o,viewportHeight:s}},[],{singleton:!0}),to={lvl:0};function tf(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 it(e){return e===to}function no(e,t){if(!it(e))return t===e.k?e.v:t<e.k?no(e.l,t):no(e.r,t)}function un(e,t,n="k"){if(it(e))return[-1/0,void 0];if(Number(e[n])===t)return[e.k,e.v];if(Number(e[n])<t){const r=un(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return un(e.l,t,n)}function Jt(e,t,n){return it(e)?of(t,n,1):t===e.k?Tt(e,{k:t,v:n}):t<e.k?sf(Tt(e,{l:Jt(e.l,t,n)})):sf(Tt(e,{r:Jt(e.r,t,n)}))}function Ar(){return to}function Is(e,t,n){if(it(e))return[];const r=un(e,t)[0];return $0(xa(e,r,n))}function ga(e,t){if(it(e))return to;const{k:n,l:r,r:o}=e;if(t===n){if(it(r))return o;if(it(o))return r;{const[s,i]=rf(r);return Ns(Tt(e,{k:s,l:nf(r),v:i}))}}else return t<n?Ns(Tt(e,{l:ga(r,t)})):Ns(Tt(e,{r:ga(o,t)}))}function nr(e){return it(e)?[]:[...nr(e.l),{k:e.k,v:e.v},...nr(e.r)]}function xa(e,t,n){if(it(e))return[];const{k:r,l:o,r:s,v:i}=e;let a=[];return r>t&&(a=a.concat(xa(o,t,n))),r>=t&&r<=n&&a.push({k:r,v:i}),r<=n&&(a=a.concat(xa(s,t,n))),a}function Ns(e){const{l:t,lvl:n,r}=e;if(r.lvl>=n-1&&t.lvl>=n-1)return e;if(n>r.lvl+1){if(ya(t))return af(Tt(e,{lvl:n-1}));if(!it(t)&&!it(t.r))return Tt(t.r,{l:Tt(t,{r:t.r.l}),lvl:n,r:Tt(e,{l:t.r.r,lvl:n-1})});throw new Error("Unexpected empty nodes")}else{if(ya(e))return va(Tt(e,{lvl:n-1}));if(!it(r)&&!it(r.l)){const o=r.l,s=ya(o)?r.lvl-1:r.lvl;return Tt(o,{l:Tt(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:va(Tt(r,{l:o.r,lvl:s}))})}else throw new Error("Unexpected empty nodes")}}function Tt(e,t){return of(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 nf(e){return it(e.r)?e.l:Ns(Tt(e,{r:nf(e.r)}))}function ya(e){return it(e)||e.lvl>e.r.lvl}function rf(e){return it(e.r)?[e.k,e.v]:rf(e.r)}function of(e,t,n,r=to,o=to){return{k:e,l:r,lvl:n,r:o,v:t}}function sf(e){return va(af(e))}function af(e){const{l:t}=e;return!it(t)&&t.lvl===e.lvl?Tt(t,{r:Tt(e,{l:t.r})}):e}function va(e){const{lvl:t,r:n}=e;return!it(n)&&!it(n.r)&&n.lvl===t&&n.r.lvl===t?Tt(n,{l:Tt(e,{r:n.l}),lvl:t+1}):e}function $0(e){return tf(e,({k:t,v:n})=>({index:t,value:n}))}function lf(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function ro(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}const ba=Je(()=>({recalcInProgress:ie(!1)}),[],{singleton:!0});function cf(e,t,n){return e[As(e,t,n)]}function As(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 F0(e,t,n,r){const o=As(e,t,r),s=As(e,n,r,o);return e.slice(o,s+1)}function Ln(e,t){return Math.round(e.getBoundingClientRect()[t])}function js(e){return!it(e.groupOffsetTree)}function wa({index:e},t){return t===e?0:t<e?-1:1}function B0(){return{groupIndices:[],groupOffsetTree:Ar(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:Ar()}}function z0(e,t){let n=it(e)?0:1/0;for(const r of t){const{endIndex:o,size:s,startIndex:i}=r;if(n=Math.min(n,i),it(e)){e=Jt(e,0,s);continue}const a=Is(e,i-1,o+1);if(a.some(G0(r)))continue;let l=!1,c=!1;for(const{end:d,start:f,value:p}of a)l?(o>=f||s===p)&&(e=ga(e,f)):(c=p!==s,l=!0),d>o&&o>=f&&p!==s&&(e=Jt(e,o+1,p));c&&(e=Jt(e,i,s))}return[e,n]}function U0(e){return typeof e.groupIndex<"u"}function H0({offset:e},t){return t===e?0:t<e?-1:1}function oo(e,t,n){if(t.length===0)return 0;const{index:r,offset:o,size:s}=cf(t,e,wa),i=e-r,a=s*i+(i-1)*n+o;return a>0?a+n:a}function uf(e,t){if(!js(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function df(e,t,n){if(U0(e))return t.groupIndices[e.groupIndex]+1;{const r=e.index==="LAST"?n:e.index;let o=uf(r,t);return o=Math.max(0,o,Math.min(n,o)),o}}function W0(e,t,n,r=0){return r>0&&(t=Math.max(t,cf(e,r,wa).offset)),tf(F0(e,t,n,H0),q0)}function V0(e,[t,n,r,o]){t.length>0&&r("received item sizes",t,Vt.DEBUG);const s=e.sizeTree;let i=s,a=0;if(n.length>0&&it(s)&&t.length===2){const p=t[0].size,h=t[1].size;i=n.reduce((v,g)=>Jt(Jt(v,g,p),g+1,h),i)}else[i,a]=z0(i,t);if(i===s)return e;const{lastIndex:l,lastOffset:c,lastSize:d,offsetTree:f}=Sa(e.offsetTree,a,i,o);return{groupIndices:n,groupOffsetTree:n.reduce((p,h)=>Jt(p,h,oo(h,f,o)),Ar()),lastIndex:l,lastOffset:c,lastSize:d,offsetTree:f,sizeTree:i}}function K0(e){return nr(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 ff(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 Sa(e,t,n,r){let o=e,s=0,i=0,a=0,l=0;if(t!==0){l=As(o,t-1,wa),a=o[l].offset;const c=un(n,t-1);s=c[0],i=c[1],o.length&&o[l].size===un(n,t)[1]&&(l-=1),o=o.slice(0,l+1)}else o=[];for(const{start:c,value:d}of Is(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 q0(e){return{index:e.index,value:e}}function G0(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 Y0={offsetHeight:"height",offsetWidth:"width"},wn=Je(([{log:e},{recalcInProgress:t}])=>{const n=Ke(),r=Ke(),o=Rt(r,0),s=Ke(),i=Ke(),a=ie(0),l=ie([]),c=ie(void 0),d=ie(void 0),f=ie((T,S)=>Ln(T,Y0[S])),p=ie(void 0),h=ie(0),v=B0(),g=Rt(te(n,Fe(l,e,h),bn(V0,v),ut()),v),y=Rt(te(l,ut(),bn((T,S)=>({current:S,prev:T.current}),{current:[],prev:[]}),pe(({prev:T})=>T)),[]);ve(te(l,Me(T=>T.length>0),Fe(g,h),pe(([T,S,E])=>{const A=T.reduce((R,D,B)=>Jt(R,D,oo(D,S.offsetTree,E)||B),Ar());return{...S,groupIndices:T,groupOffsetTree:A}})),g),ve(te(r,Fe(g),Me(([T,{lastIndex:S}])=>T<S),pe(([T,{lastIndex:S,lastSize:E}])=>[{endIndex:S,size:E,startIndex:T}])),n),ve(c,d);const x=Rt(te(c,pe(T=>T===void 0)),!0);ve(te(d,Me(T=>T!==void 0&&it(bt(g).sizeTree)),pe(T=>[{endIndex:0,size:T,startIndex:0}])),n);const b=Xt(te(n,Fe(g),bn(({sizes:T},[S,E])=>({changed:E!==T,sizes:E}),{changed:!1,sizes:v}),pe(T=>T.changed)));rt(te(a,bn((T,S)=>({diff:T.prev-S,prev:S}),{diff:0,prev:0}),pe(T=>T.diff)),T=>{const{groupIndices:S}=bt(g);if(T>0)Le(t,!0),Le(s,T+ff(T,S));else if(T<0){const E=bt(y);E.length>0&&(T-=ff(-T,E)),Le(i,T)}}),rt(te(a,Fe(e)),([T,S])=>{T<0&&S("`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},Vt.ERROR)});const C=Xt(s);ve(te(s,Fe(g),pe(([T,S])=>{const E=S.groupIndices.length>0,A=[],R=S.lastSize;if(E){const D=no(S.sizeTree,0);let B=0,q=0;for(;B<T;){const j=S.groupIndices[q],_=S.groupIndices.length===q+1?1/0:S.groupIndices[q+1]-j-1;A.push({endIndex:j,size:D,startIndex:j}),A.push({endIndex:j+1+_-1,size:R,startIndex:j+1}),q++,B+=_+1}const V=nr(S.sizeTree);return B!==T&&V.shift(),V.reduce((j,{k:_,v:N})=>{let z=j.ranges;return j.prevSize!==0&&(z=[...j.ranges,{endIndex:_+T-1,size:j.prevSize,startIndex:j.prevIndex}]),{prevIndex:_+T,prevSize:N,ranges:z}},{prevIndex:T,prevSize:0,ranges:A}).ranges}return nr(S.sizeTree).reduce((D,{k:B,v:q})=>({prevIndex:B+T,prevSize:q,ranges:[...D.ranges,{endIndex:B+T-1,size:D.prevSize,startIndex:D.prevIndex}]}),{prevIndex:0,prevSize:R,ranges:[]}).ranges})),n);const k=Xt(te(i,Fe(g,h),pe(([T,{offsetTree:S},E])=>{const A=-T;return oo(A,S,E)})));return ve(te(i,Fe(g,h),pe(([T,S,E])=>{if(S.groupIndices.length>0){if(it(S.sizeTree))return S;let A=Ar();const R=bt(y);let D=0,B=0,q=0;for(;D<-T;){q=R[B];const V=R[B+1]-q-1;B++,D+=V+1}if(A=nr(S.sizeTree).reduce((V,{k:j,v:_})=>Jt(V,Math.max(0,j+T),_),A),D!==-T){const V=no(S.sizeTree,q);A=Jt(A,0,V);const j=un(S.sizeTree,-T+1)[1];A=Jt(A,1,j)}return{...S,sizeTree:A,...Sa(S.offsetTree,0,A,E)}}else{const A=nr(S.sizeTree).reduce((R,{k:D,v:B})=>Jt(R,Math.max(0,D+T),B),Ar());return{...S,sizeTree:A,...Sa(S.offsetTree,0,A,E)}}})),g),{beforeUnshiftWith:C,data:p,defaultItemSize:d,firstItemIndex:a,fixedItemSize:c,gap:h,groupIndices:l,itemSize:f,listRefresh:b,shiftWith:i,shiftWithOffset:k,sizeRanges:n,sizes:g,statefulTotalCount:o,totalCount:r,trackItemSizes:x,unshiftWith:s}},ct(Dn,ba),{singleton:!0});function X0(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const pf=Je(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=Ke(),i=Ke(),a=Xt(te(s,pe(X0)));return ve(te(a,pe(l=>l.totalCount)),n),ve(te(a,pe(l=>l.groupIndices)),e),ve(te(St(o,t,r),Me(([l,c])=>js(c)),pe(([l,c,d])=>un(c.groupOffsetTree,Math.max(l-d,0),"v")[0]),ut(),pe(l=>[l])),i),{groupCounts:s,topItemsIndexes:i}},ct(wn,Bt)),$n=Je(([{log:e}])=>{const t=ie(!1),n=Xt(te(t,Me(r=>r),ut()));return rt(t,r=>{r&&bt(e)("props updated",{},Vt.DEBUG)}),{didMount:n,propsReady:t}},ct(Dn),{singleton:!0}),J0=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function hf(e){const t=typeof e=="number"?{index:e}:e;return t.align||(t.align="start"),(!t.behavior||!J0)&&(t.behavior="auto"),t.offset||(t.offset=0),t}const so=Je(([{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=Ke(),v=Ke(),g=ie(0);let y=null,x=null,b=null;function C(){y&&(y(),y=null),b&&(b(),b=null),x&&(clearTimeout(x),x=null),Le(l,!1)}return ve(te(h,Fe(n,f,r,g,a,i,p),Fe(e,s,o),pe(([[k,T,S,E,A,R,D,B],q,V,j])=>{const _=hf(k),{align:N,behavior:z,offset:$}=_,P=E-1,H=df(_,T,P);let Q=oo(H,T.offsetTree,q)+R;N==="end"?(Q+=V+un(T.sizeTree,H)[1]-S+j,H===P&&(Q+=D)):N==="center"?Q+=(V+un(T.sizeTree,H)[1]-S+j)/2:Q-=A,$&&(Q+=$);const M=Y=>{C(),Y?(B("retrying to scroll to",{location:k},Vt.DEBUG),Le(h,k)):(Le(v,!0),B("list did not change, scroll successful",{},Vt.DEBUG))};if(C(),z==="smooth"){let Y=!1;b=rt(t,ae=>{Y=Y||ae}),y=cn(d,()=>{M(Y)})}else y=cn(te(t,Z0(150)),M);return x=setTimeout(()=>{C()},1200),Le(l,!0),B("scrolling from index to",{behavior:z,index:H,top:Q},Vt.DEBUG),{behavior:z,top:Q}})),c),{scrollTargetReached:v,scrollToIndex:h,topListHeight:g}},ct(wn,Bt,Dn),{singleton:!0});function Z0(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 Ta(e,t){const n=t-1;return typeof e=="number"?e:e.index==="LAST"?n:e.index}const io=Je(([{defaultItemSize:e,listRefresh:t,sizes:n},{scrollTop:r},{scrollTargetReached:o,scrollToIndex:s},{didMount:i}])=>{const a=ie(!0),l=ie(0),c=ie(!0);return ve(te(i,Fe(l),Me(([d,f])=>!!f),vn(!1)),a),ve(te(i,Fe(l),Me(([d,f])=>!!f),vn(!1)),c),rt(te(St(t,i),Fe(a,n,e,c),Me(([[,d],f,{sizeTree:p},h,v])=>d&&(!it(p)||fa(h))&&!f&&!v),Fe(l)),([,d])=>{cn(o,()=>{Le(c,!0)}),Ca(4,()=>{cn(r,()=>{Le(a,!0)}),Le(s,d)})}),{initialItemFinalLocationReached:c,initialTopMostItemIndex:l,scrolledToInitialItem:a}},ct(wn,Bt,so,$n),{singleton:!0});function mf(e,t){return Math.abs(e-t)<1.01}const ao="up",lo="down",Q0="none",eS={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},tS=0,co=Je(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:o,viewportHeight:s}])=>{const i=ie(!1),a=ie(!0),l=Ke(),c=Ke(),d=ie(4),f=ie(tS),p=Rt(te(ha(te(je(o),er(1),vn(!0)),te(je(o),er(1),vn(!1),Jd(100))),ut()),!1),h=Rt(te(ha(te(n,vn(!0)),te(n,vn(!1),Jd(200))),ut()),!1);ve(te(St(je(o),je(f)),pe(([b,C])=>b<=C),ut()),a),ve(te(a,Nn(50)),c);const v=Xt(te(St(r,je(s),je(t),je(e),je(d)),bn((b,[{scrollHeight:C,scrollTop:k},T,S,E,A])=>{const R=k+T-C>-A,D={scrollHeight:C,scrollTop:k,viewportHeight:T};if(R){let q,V;return k>b.state.scrollTop?(q="SCROLLED_DOWN",V=b.state.scrollTop-k):(q="SIZE_DECREASED",V=b.state.scrollTop-k||b.scrollTopDelta),{atBottom:!0,atBottomBecause:q,scrollTopDelta:V,state:D}}let B;return D.scrollHeight>b.state.scrollHeight?B="SIZE_INCREASED":T<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}},eS),ut((b,C)=>b&&b.atBottom===C.atBottom))),g=Rt(te(r,bn((b,{scrollHeight:C,scrollTop:k,viewportHeight:T})=>{if(mf(b.scrollHeight,C))return{changed:!1,jump:0,scrollHeight:C,scrollTop:k};{const S=C-(k+T)<1;return b.scrollTop!==k&&S?{changed:!0,jump:b.scrollTop-k,scrollHeight:C,scrollTop:k}:{changed:!0,jump:0,scrollHeight:C,scrollTop:k}}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),Me(b=>b.changed),pe(b=>b.jump)),0);ve(te(v,pe(b=>b.atBottom)),i),ve(te(i,Nn(50)),l);const y=ie(lo);ve(te(r,pe(({scrollTop:b})=>b),ut(),bn((b,C)=>bt(h)?{direction:b.direction,prevScrollTop:C}:{direction:C<b.prevScrollTop?ao:lo,prevScrollTop:C},{direction:lo,prevScrollTop:0}),pe(b=>b.direction)),y),ve(te(r,Nn(50),vn(Q0)),y);const x=ie(0);return ve(te(p,Me(b=>!b),vn(0)),x),ve(te(o,Nn(100),Fe(p),Me(([b,C])=>!!C),bn(([b,C],[k])=>[C,k],[0,0]),pe(([b,C])=>C-b)),x),{atBottomState:v,atBottomStateChange:l,atBottomThreshold:d,atTopStateChange:c,atTopThreshold:f,isAtBottom:i,isAtTop:a,isScrolling:p,lastJumpDueToItemResize:g,scrollDirection:y,scrollVelocity:x}},ct(Bt)),_s="top",Ms="bottom",gf="none";function xf(e,t,n){return typeof e=="number"?n===ao&&t===_s||n===lo&&t===Ms?e:0:n===ao?t===_s?e.main:e.reverse:t===Ms?e.main:e.reverse}function yf(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const ka=Je(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:o}])=>{const s=Ke(),i=ie(0),a=ie(0),l=ie(0),c=Rt(te(St(je(r),je(o),je(n),je(s,ro),je(l),je(i),je(t),je(e),je(a)),pe(([d,f,p,[h,v],g,y,x,b,C])=>{const k=d-b,T=y+x,S=Math.max(p-k,0);let E=gf;const A=yf(C,_s),R=yf(C,Ms);return h-=b,h+=p+x,v+=p+x,v-=b,h>d+T-A&&(E=ao),v<d-S+f+R&&(E=lo),E!==gf?[Math.max(k-p-xf(g,_s,E)-A,0),k-S-x+f+xf(g,Ms,E)+R]:null}),Me(d=>d!=null),ut(ro)),[0,0]);return{increaseViewportBy:a,listBoundary:s,overscan:l,topListHeight:i,visibleRange:c}},ct(Bt),{singleton:!0});function nS(e,t,n){if(js(t)){const r=uf(e,t);return[{index:un(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 Ea={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function Rs(e,t,n,r,o,s){const{lastIndex:i,lastOffset:a,lastSize:l}=o;let c=0,d=0;if(e.length>0){c=e[0].offset;const g=e[e.length-1];d=g.offset+g.size}const f=n-i,p=a+f*l+(f-1)*r,h=c,v=p-d;return{bottom:d,firstItemIndex:s,items:bf(e,o,s),offsetBottom:v,offsetTop:c,top:h,topItems:bf(t,o,s),topListHeight:t.reduce((g,y)=>y.size+g,0),totalCount:n}}function vf(e,t,n,r,o,s){let i=0;if(n.groupIndices.length>0)for(const d of n.groupIndices){if(d-i>=e)break;i++}const a=e+i,l=Ta(t,a),c=Array.from({length:a}).map((d,f)=>({data:s[f+l],index:f+l,offset:0,size:0}));return Rs(c,[],a,o,n,r)}function bf(e,t,n){if(e.length===0)return[];if(!js(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=Is(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 rr=Je(([{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:v}])=>{const g=ie([]),y=ie(0),x=Ke();ve(s.topItemsIndexes,g);const b=Rt(te(St(h,v,je(l,ro),je(o),je(r),je(c),d,je(g),je(t),je(n),e),Me(([S,E,,A,,,,,,,R])=>{const D=R&&R.length!==A;return S&&!E&&!D}),pe(([,,[S,E],A,R,D,B,q,V,j,_])=>{const N=R,{offsetTree:z,sizeTree:$}=N,P=bt(y);if(A===0)return{...Ea,totalCount:A};if(S===0&&E===0)return P===0?{...Ea,totalCount:A}:vf(P,D,R,V,j,_||[]);if(it($))return P>0?null:Rs(nS(Ta(D,A),N,_),[],A,j,N,V);const H=[];if(q.length>0){const ne=q[0],ce=q[q.length-1];let G=0;for(const O of Is($,ne,ce)){const W=O.value,F=Math.max(O.start,ne),ee=Math.min(O.end,ce);for(let Z=F;Z<=ee;Z++)H.push({data:_==null?void 0:_[Z],index:Z,offset:G,size:W}),G+=W}}if(!B)return Rs([],H,A,j,N,V);const Q=q.length>0?q[q.length-1]+1:0,M=W0(z,S,E,Q);if(M.length===0)return null;const Y=A-1,ae=Es([],ne=>{for(const ce of M){const G=ce.value;let O=G.offset,W=ce.start;const F=G.size;if(G.offset<S){W+=Math.floor((S-G.offset+j)/(F+j));const Z=W-ce.start;O+=Z*F+Z*j}W<Q&&(O+=(Q-W)*F,W=Q);const ee=Math.min(ce.end,Y);for(let Z=W;Z<=ee&&!(O>=E);Z++)ne.push({data:_==null?void 0:_[Z],index:Z,offset:O,size:F}),O+=F+j}});return Rs(ae,H,A,j,N,V)}),Me(S=>S!==null),ut()),Ea);ve(te(e,Me(fa),pe(S=>S==null?void 0:S.length)),o),ve(te(b,pe(S=>S.topListHeight)),f),ve(f,a),ve(te(b,pe(S=>[S.top,S.bottom])),i),ve(te(b,pe(S=>S.items)),x);const C=Xt(te(b,Me(({items:S})=>S.length>0),Fe(o,e),Me(([{items:S},E])=>S[S.length-1].originalIndex===E-1),pe(([,S,E])=>[S-1,E]),ut(ro),pe(([S])=>S))),k=Xt(te(b,Nn(200),Me(({items:S,topItems:E})=>S.length>0&&S[0].originalIndex===E.length),pe(({items:S})=>S[0].index),ut())),T=Xt(te(b,Me(({items:S})=>S.length>0),pe(({items:S})=>{let E=0,A=S.length-1;for(;S[E].type==="group"&&E<A;)E++;for(;S[A].type==="group"&&A>E;)A--;return{endIndex:S[A].index,startIndex:S[E].index}}),ut(lf)));return{endReached:C,initialItemCount:y,itemsRendered:x,listState:b,rangeChanged:T,startReached:k,topItemsIndexes:g,...p}},ct(wn,pf,ka,io,so,co,$n,ba),{singleton:!0}),wf=Je(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:o}])=>{const s=Ke(),i=Rt(te(St(n,e,r,t,o),pe(([a,l,c,d,f])=>a+l+c+d+f.offsetBottom+f.bottom)),0);return ve(je(i),s),{totalListHeight:i,totalListHeightChanged:s}},ct(Bt,rr),{singleton:!0}),rS=Je(([{viewportHeight:e},{totalListHeight:t}])=>{const n=ie(!1),r=Rt(te(St(n,e,t),Me(([o])=>o),pe(([,o,s])=>Math.max(0,o-s)),Nn(0),ut()),0);return{alignToBottom:n,paddingTopAddition:r}},ct(Bt,wf),{singleton:!0}),Sf=Je(()=>({context:ie(null)})),oS=({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,Cf=Je(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:s,scrollingInProgress:i,scrollTop:a,viewportHeight:l},{scrollToIndex:c}])=>{const d=Ke();return ve(te(d,Fe(t,l,n,s,o,r,a),Fe(e),pe(([[f,p,h,v,g,y,x,b],C])=>{const{align:k,behavior:T,calculateViewLocation:S=oS,done:E,...A}=f,R=df(f,p,v-1),D=oo(R,p.offsetTree,C)+g+y,B=D+un(p.sizeTree,R)[1],q=b+y,V=b+h-x,j=S({itemBottom:B,itemTop:D,locationParams:{align:k,behavior:T,...A},viewportBottom:V,viewportTop:q});return j?E&&cn(te(i,Me(_=>!_),er(bt(i)?1:2)),E):E&&E(),j}),Me(f=>f!==null)),c),{scrollIntoView:d}},ct(wn,Bt,so,rr,Dn),{singleton:!0});function Tf(e){return e?e==="smooth"?"smooth":"auto":!1}const sS=(e,t)=>typeof e=="function"?Tf(e(t)):t&&Tf(e),iS=Je(([{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 v=ie(!1),g=Ke();let y=null;function x(T){Le(i,{align:"end",behavior:T,index:"LAST"})}rt(te(St(te(je(t),er(1)),l),Fe(je(v),s,a,f),pe(([[T,S],E,A,R,D])=>{let B=S&&R,q="auto";return B&&(q=sS(E,A||D),B=B&&!!q),{followOutputBehavior:q,shouldFollow:B,totalCount:T}}),Me(({shouldFollow:T})=>T)),({followOutputBehavior:T,totalCount:S})=>{y&&(y(),y=null),bt(n)?requestAnimationFrame(()=>{bt(d)("following output to ",{totalCount:S},Vt.DEBUG),x(T)}):y=cn(e,()=>{bt(d)("following output to ",{totalCount:S},Vt.DEBUG),x(T),y=null})});function b(T){const S=cn(o,E=>{T&&!E.atBottom&&E.notAtBottomBecause==="SIZE_INCREASED"&&!y&&(bt(d)("scrolling to bottom due to increased size",{},Vt.DEBUG),x("auto"))});setTimeout(S,100)}rt(te(St(je(v),t,c),Me(([T,,S])=>T&&S),bn(({value:T},[,S])=>({refreshed:T===S,value:S}),{refreshed:!1,value:0}),Me(({refreshed:T})=>T),Fe(v,t)),([,T])=>{bt(a)&&b(T!==!1)}),rt(g,()=>{b(bt(v)!==!1)}),rt(St(je(v),o),([T,S])=>{T&&!S.atBottom&&S.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&x("auto")});const C=ie(null),k=Ke();return ve(ha(te(je(r),pe(T=>{var S;return(S=T==null?void 0:T.length)!=null?S:0})),te(je(t))),k),rt(te(St(te(k,er(1)),l),Fe(je(C),a,f,p),pe(([[T,S],E,A,R,D])=>S&&A&&(E==null?void 0:E({context:D,totalCount:T,scrollingInProgress:R}))),Me(T=>!!T),Nn(0)),T=>{y&&(y(),y=null),bt(n)?requestAnimationFrame(()=>{bt(d)("scrolling into view",{}),Le(h,T)}):y=cn(e,()=>{bt(d)("scrolling into view",{}),Le(h,T),y=null})}),{autoscrollToBottom:g,followOutput:v,scrollIntoViewOnChange:C}},ct(wn,co,so,io,$n,Dn,Bt,Sf,Cf)),aS=Je(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:s,listState:i},{didMount:a}])=>(ve(te(a,Fe(s),Me(([,l])=>l!==0),Fe(o,r,t,n,e),pe(([[,l],c,d,f,p,h=[]])=>vf(l,c,d,f,p,h))),i),{}),ct(wn,io,rr,$n),{singleton:!0}),lS=Je(([{didMount:e},{scrollTo:t},{listState:n}])=>{const r=ie(0);return rt(te(e,Fe(r),Me(([,o])=>o!==0),pe(([,o])=>({top:o}))),o=>{cn(te(n,er(1),Me(s=>s.items.length>1)),()=>{requestAnimationFrame(()=>{Le(t,o)})})}),{initialScrollTop:r}},ct($n,Bt,rr),{singleton:!0}),kf=Je(([{scrollVelocity:e}])=>{const t=ie(!1),n=Ke(),r=ie(!1);return ve(te(e,Fe(r,t,n),Me(([o,s])=>!!s),pe(([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}),ut()),t),rt(te(St(t,e,n),Fe(r)),([[o,s,i],a])=>{o&&a&&a.change&&a.change(s,i)}),{isSeeking:t,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:e}},ct(co),{singleton:!0}),Ia=Je(([{scrollContainerState:e,scrollTo:t}])=>{const n=Ke(),r=Ke(),o=Ke(),s=ie(!1),i=ie(void 0);return ve(te(St(n,r),pe(([{scrollHeight:a,scrollTop:l,viewportHeight:c},{offsetTop:d}])=>({scrollHeight:a,scrollTop:Math.max(0,l-d),viewportHeight:c}))),e),ve(te(t,Fe(r),pe(([a,{offsetTop:l}])=>({...a,top:a.top+l}))),o),{customScrollParent:i,useWindowScroll:s,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:r}},ct(Bt)),cS=Je(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:o},{didMount:s},{useWindowScroll:i,windowScrollContainerState:a,windowViewportRect:l}])=>{const c=Ke(),d=ie(void 0),f=ie(null),p=ie(null);return ve(a,f),ve(l,p),rt(te(c,Fe(t,r,i,f,p,n)),([h,v,g,y,x,b,C])=>{const k=K0(v.sizeTree);y&&x!==null&&b!==null&&(g=x.scrollTop-b.offsetTop),g-=C,h({ranges:k,scrollTop:g})}),ve(te(d,Me(fa),pe(uS)),o),ve(te(s,Fe(d),Me(([,h])=>h!==void 0),ut(),pe(([,h])=>h.ranges)),e),{getState:c,restoreStateFrom:d}},ct(wn,Bt,io,$n,Ia));function uS(e){return{align:"start",index:0,offset:e.scrollTop}}const dS=Je(([{topItemsIndexes:e}])=>{const t=ie(0);return ve(te(t,Me(n=>n>=0),pe(n=>Array.from({length:n}).map((r,o)=>o))),e),{topItemCount:t}},ct(rr));function Ef(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const fS=Ef(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),pS=Je(([{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:v}])=>{const g=Xt(te(l,Fe(i),bn(([,x,b,C],[{bottom:k,items:T,offsetBottom:S,totalCount:E},A])=>{const R=k+S;let D=0;return b===E&&x.length>0&&T.length>0&&(T[0].originalIndex===0&&x[0].originalIndex===0||(D=R-C,D!==0&&(D+=A))),[D,T,E,R]},[0,[],0,0]),Me(([x])=>x!==0),Fe(r,a,n,o,h,v),Me(([,x,b,C,,,k])=>!k&&!C&&x!==0&&b===ao),pe(([[x],,,,,b])=>(b("Upward scrolling compensation",{amount:x},Vt.DEBUG),x))));function y(x){x>0?(Le(t,{behavior:"auto",top:-x}),Le(e,0)):(Le(e,0),Le(t,{behavior:"auto",top:-x}))}return rt(te(g,Fe(e,s)),([x,b,C])=>{C&&fS()?Le(e,b-x):y(-x)}),rt(te(St(Rt(s,!1),e,v),Me(([x,b,C])=>!x&&!C&&b!==0),pe(([x,b])=>b),Nn(1)),y),ve(te(f,pe(x=>({top:-x}))),t),rt(te(c,Fe(p,d),pe(([x,{groupIndices:b,lastSize:C,sizeTree:k},T])=>{function S(E){return E*(C+T)}if(b.length===0)return S(x);{let E=0;const A=no(k,0);let R=0,D=0;for(;R<x;){R++,E+=A;let B=b.length===D+1?1/0:b[D+1]-b[D]-1;R+B>x&&(E-=A,B=x-R+1),R+=B,E+=S(B),D++}return E}})),x=>{Le(e,x),requestAnimationFrame(()=>{Le(t,{top:x}),requestAnimationFrame(()=>{Le(e,0),Le(v,!1)})})}),{deviation:e}},ct(Bt,co,rr,wn,Dn,ba)),hS=Je(([e,t,n,r,o,s,i,a,l,c,d])=>({...e,...t,...n,...r,...o,...s,...i,...a,...l,...c,...d}),ct(ka,aS,$n,kf,wf,lS,rS,Ia,Cf,Dn,Sf)),If=Je(([{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:v},g,y,x,{listState:b,topItemsIndexes:C,...k},{scrollToIndex:T},S,{topItemCount:E},{groupCounts:A},R])=>(ve(k.rangeChanged,R.scrollSeekRangeChanged),ve(te(R.windowViewportRect,pe(D=>D.visibleHeight)),g.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:n,fixedItemHeight:r,gap:o,groupCounts:A,initialItemFinalLocationReached:p,initialTopMostItemIndex:h,scrolledToInitialItem:v,sizeRanges:a,topItemCount:E,topItemsIndexes:C,totalCount:d,...x,groupIndices:s,itemSize:i,listState:b,scrollToIndex:T,statefulTotalCount:c,trackItemSizes:f,...k,...R,...g,sizes:l,...y}),ct(wn,io,Bt,cS,iS,rr,so,pS,dS,pf,hS));function mS(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 Ps=typeof document<"u"?w.useLayoutEffect:w.useEffect;function Nf(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&&Le(y.propsReady,!1);for(const b of r){const C=y[t.required[b]];Le(C,x[b])}for(const b of o)if(b in x){const C=y[t.optional[b]];Le(C,x[b])}y.propsReady&&Le(y.propsReady,!0)}function c(y){return s.reduce((x,b)=>(x[b]=C=>{const k=y[t.methods[b]];Le(k,C)},x),{})}function d(y){return i.reduce((x,b)=>(x[b]=_0(y[t.events[b]]),x),{})}const f=w.forwardRef((y,x)=>{const{children:b,...C}=y,[k]=w.useState(()=>Es(R0(e),E=>{l(E,C)})),[T]=w.useState(Xd(d,k));Ps(()=>{for(const E of i)E in C&&rt(T[E],C[E]);return()=>{Object.values(T).map(pa)}},[C,T,k]),Ps(()=>{l(k,C)}),w.useImperativeHandle(x,Gd(c(k)));const S=n;return u.jsx(a.Provider,{value:k,children:n?u.jsx(S,{...mS([...r,...o,...i],C),children:b}):b})}),p=y=>{const x=w.useContext(a);return w.useCallback(b=>{Le(x[y],b)},[x,y])},h=y=>{const x=w.useContext(a)[y],b=w.useCallback(C=>rt(x,C),[x]);return w.useSyncExternalStore(b,()=>bt(x),()=>bt(x))},v=y=>{const x=w.useContext(a)[y],[b,C]=w.useState(Xd(bt,x));return Ps(()=>rt(x,k=>{k!==b&&C(Gd(k))}),[x,b]),b},g=w.version.startsWith("18")?h:v;return{Component:f,useEmitter:(y,x)=>{const b=w.useContext(a)[y];Ps(()=>rt(b,x),[x,b])},useEmitterValue:g,usePublisher:p}}const Af=w.createContext(void 0),jf=w.createContext(void 0),_f=typeof document<"u"?w.useLayoutEffect:w.useEffect;function Na(e){return"self"in e}function gS(e){return"body"in e}function Mf(e,t,n,r=Nr,o,s){const i=w.useRef(null),a=w.useRef(null),l=w.useRef(null),c=w.useCallback(p=>{let h,v,g;const y=p.target;if(gS(y)||Na(y)){const b=Na(y)?y:y.defaultView;g=s?b.scrollX:b.scrollY,h=s?b.document.documentElement.scrollWidth:b.document.documentElement.scrollHeight,v=s?b.innerWidth:b.innerHeight}else g=s?y.scrollLeft:y.scrollTop,h=s?y.scrollWidth:y.scrollHeight,v=s?y.offsetWidth:y.offsetHeight;const x=()=>{e({scrollHeight:h,scrollTop:Math.max(g,0),viewportHeight:v})};p.suppressFlushSync?x():li.flushSync(x),a.current!==null&&(g===a.current||g<=0||g===h-v)&&(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 v=p.behavior==="smooth";let g,y,x;Na(h)?(y=Math.max(Ln(h.document.documentElement,s?"width":"height"),s?h.document.documentElement.scrollWidth:h.document.documentElement.scrollHeight),g=s?h.innerWidth:h.innerHeight,x=s?window.scrollX:window.scrollY):(y=h[s?"scrollWidth":"scrollHeight"],g=Ln(h,s?"width":"height"),x=h[s?"scrollLeft":"scrollTop"]);const b=y-g;if(p.top=Math.ceil(Math.max(Math.min(b,p.top),0)),mf(g,y)||p.top===x){e({scrollHeight:y,scrollTop:x,viewportHeight:g}),v&&t(!0);return}v?(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 Aa="-webkit-sticky",Rf="sticky",ja=Ef(()=>{if(typeof document>"u")return Rf;const e=document.createElement("div");return e.style.position=Aa,e.style.position===Aa?Aa:Rf});function _a(e){return e}const xS=Je(()=>{const e=ie(a=>`Item ${a}`),t=ie(a=>`Group ${a}`),n=ie({}),r=ie(_a),o=ie("div"),s=ie(Nr),i=(a,l=null)=>Rt(te(n,pe(c=>c[a]),ut()),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")}}),yS=Je(([e,t])=>({...e,...t}),ct(If,xS)),vS=({height:e})=>u.jsx("div",{style:{height:e}}),bS={overflowAnchor:"none",position:ja(),zIndex:1},Pf={overflowAnchor:"none"},wS={...Pf,display:"inline-block",height:"100%"},Of=w.memo(function({showTopList:e=!1}){const t=Oe("listState"),n=en("sizeRanges"),r=Oe("useWindowScroll"),o=Oe("customScrollParent"),s=en("windowScrollContainerState"),i=en("scrollContainerState"),a=o||r?s:i,l=Oe("itemContent"),c=Oe("context"),d=Oe("groupContent"),f=Oe("trackItemSizes"),p=Oe("itemSize"),h=Oe("log"),v=en("gap"),g=Oe("horizontalDirection"),{callbackRef:y}=D0(n,p,f,e?Nr:a,h,v,o,g,Oe("skipAnimationFrameInResizeObserver")),[x,b]=w.useState(0);Ma("deviation",j=>{x!==j&&b(j)});const C=Oe("EmptyPlaceholder"),k=Oe("ScrollSeekPlaceholder")||vS,T=Oe("ListComponent"),S=Oe("ItemComponent"),E=Oe("GroupComponent"),A=Oe("computeItemKey"),R=Oe("isSeeking"),D=Oe("groupIndices").length>0,B=Oe("alignToBottom"),q=Oe("initialItemFinalLocationReached"),V=e?{}:{boxSizing:"border-box",...g?{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},...q?{}:{visibility:"hidden"}};return!e&&t.totalCount===0&&C?u.jsx(C,{...Pt(C,c)}):u.jsx(T,{...Pt(T,c),"data-testid":e?"virtuoso-top-item-list":"virtuoso-item-list",ref:y,style:V,children:(e?t.topItems:t.items).map(j=>{const _=j.originalIndex,N=A(_+t.firstItemIndex,j.data,c);return R?w.createElement(k,{...Pt(k,c),height:j.size,index:j.index,key:N,type:j.type||"item",...j.type==="group"?{}:{groupIndex:j.groupIndex}}):j.type==="group"?w.createElement(E,{...Pt(E,c),"data-index":_,"data-item-index":j.index,"data-known-size":j.size,key:N,style:bS},d(j.index,c)):w.createElement(S,{...Pt(S,c),...kS(S,j.data),"data-index":_,"data-item-group-index":j.groupIndex,"data-item-index":j.index,"data-known-size":j.size,key:N,style:g?wS:Pf},D?l(j.index,j.groupIndex,j.data,c):l(j.index,j.data,c))})})}),SS={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},CS={outline:"none",overflowX:"auto",position:"relative"},Os=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),TS={position:ja(),top:0,width:"100%",zIndex:1};function Pt(e,t){if(typeof e!="string")return{context:t}}function kS(e,t){return{item:typeof e=="string"?void 0:t}}const ES=w.memo(function(){const e=Oe("HeaderComponent"),t=en("headerHeight"),n=Oe("HeaderFooterTag"),r=tr(w.useMemo(()=>s=>{t(Ln(s,"height"))},[t]),!0,Oe("skipAnimationFrameInResizeObserver")),o=Oe("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...Pt(e,o)})}):null}),IS=w.memo(function(){const e=Oe("FooterComponent"),t=en("footerHeight"),n=Oe("HeaderFooterTag"),r=tr(w.useMemo(()=>s=>{t(Ln(s,"height"))},[t]),!0,Oe("skipAnimationFrameInResizeObserver")),o=Oe("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...Pt(e,o)})}):null});function Df({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:v}=Mf(a,c,l,d,void 0,f);return e("scrollTo",v),e("scrollBy",p),u.jsx(l,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:h,style:{...f?CS:SS,...o},tabIndex:0,...i,...Pt(l,s),children:r})})}function Lf({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),v=t("scrollerRef"),{scrollByCallback:g,scrollerRef:y,scrollToCallback:x}=Mf(a,c,l,v,p);return _f(()=>{var b;return y.current=p||((b=h.current)==null?void 0:b.ownerDocument.defaultView),()=>{y.current=null}},[y,p]),e("windowScrollTo",x),e("scrollBy",g),u.jsx(l,{ref:h,"data-virtuoso-scroller":!0,style:{position:"relative",...o,...d!==0?{height:d+f}:{}},...i,...Pt(l,s),children:r})})}const NS=({children:e})=>{const t=w.useContext(Af),n=en("viewportHeight"),r=en("fixedItemHeight"),o=Oe("alignToBottom"),s=Oe("horizontalDirection"),i=w.useMemo(()=>Yd(n,l=>Ln(l,s?"width":"height")),[n,s]),a=tr(i,!0,Oe("skipAnimationFrameInResizeObserver"));return w.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),u.jsx("div",{"data-viewport-type":"element",ref:a,style:Os(o),children:e})},AS=({children:e})=>{const t=w.useContext(Af),n=en("windowViewportRect"),r=en("fixedItemHeight"),o=Oe("customScrollParent"),s=ef(n,o,Oe("skipAnimationFrameInResizeObserver")),i=Oe("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:Os(i),children:e})},jS=({children:e})=>{const t=Oe("TopItemListComponent")||"div",n=Oe("headerHeight"),r={...TS,marginTop:`${n}px`},o=Oe("context");return u.jsx(t,{style:r,...Pt(t,o),children:e})},_S=w.memo(function(e){const t=Oe("useWindowScroll"),n=Oe("topItemsIndexes").length>0,r=Oe("customScrollParent"),o=Oe("context");return u.jsxs(r||t?PS:RS,{...e,context:o,children:[n&&u.jsx(jS,{children:u.jsx(Of,{showTopList:!0})}),u.jsxs(r||t?AS:NS,{children:[u.jsx(ES,{}),u.jsx(Of,{}),u.jsx(IS,{})]})]})}),{Component:MS,useEmitter:Ma,useEmitterValue:Oe,usePublisher:en}=Nf(yS,{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"}},_S),RS=Df({useEmitter:Ma,useEmitterValue:Oe,usePublisher:en}),PS=Lf({useEmitter:Ma,useEmitterValue:Oe,usePublisher:en}),OS=MS;ct(If,Je(()=>{const e=ie(c=>u.jsxs("td",{children:["Item $",c]})),t=ie(null),n=ie(c=>u.jsxs("td",{colSpan:1e3,children:["Group ",c]})),r=ie(null),o=ie(null),s=ie({}),i=ie(_a),a=ie(Nr),l=(c,d=null)=>Rt(te(s,pe(f=>f[c]),ut()),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")}})),ja();const $f={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},DS={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:Ff,floor:Ds,max:uo,min:Ra,round:Bf}=Math;function zf(e,t,n){return Array.from({length:t-e+1}).map((r,o)=>({data:n===null?null:n[o+e],index:o+e}))}function LS(e){return{...DS,items:e}}function Ls(e,t){return e&&e.width===t.width&&e.height===t.height}function $S(e,t){return e&&e.column===t.column&&e.row===t.row}const FS=Je(([{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:v,propsReady:g},{customScrollParent:y,useWindowScroll:x,windowScrollContainerState:b,windowScrollTo:C,windowViewportRect:k},T])=>{const S=ie(0),E=ie(0),A=ie($f),R=ie({height:0,width:0}),D=ie({height:0,width:0}),B=Ke(),q=Ke(),V=ie(0),j=ie(null),_=ie({column:0,row:0}),N=Ke(),z=Ke(),$=ie(!1),P=ie(0),H=ie(!0),Q=ie(!1),M=ie(!1);rt(te(v,Fe(P),Me(([O,W])=>!!W)),()=>{Le(H,!1)}),rt(te(St(v,H,D,R,P,Q),Me(([O,W,F,ee,,Z])=>O&&!W&&F.height!==0&&ee.height!==0&&!Z)),([,,,,O])=>{Le(Q,!0),Ca(1,()=>{Le(B,O)}),cn(te(c),()=>{Le(t,[0,0]),Le(H,!0)})}),ve(te(z,Me(O=>O!=null&&O.scrollTop>0),vn(0)),E),rt(te(v,Fe(z),Me(([,O])=>O!=null)),([,O])=>{O&&(Le(R,O.viewport),Le(D,O.item),Le(_,O.gap),O.scrollTop>0&&(Le($,!0),cn(te(c,er(1)),W=>{Le($,!1)}),Le(l,{top:O.scrollTop})))}),ve(te(R,pe(({height:O})=>O)),f),ve(te(St(je(R,Ls),je(D,Ls),je(_,(O,W)=>O&&O.column===W.column&&O.row===W.row),je(c)),pe(([O,W,F,ee])=>({gap:F,item:W,scrollTop:ee,viewport:O}))),N),ve(te(St(je(S),r,je(_,$S),je(D,Ls),je(R,Ls),je(j),je(E),je($),je(H),je(P)),Me(([,,,,,,,O])=>!O),pe(([O,[W,F],ee,Z,ye,fe,oe,,xe,Se])=>{const{column:$e,row:_e}=ee,{height:We,width:Be}=Z,{width:qe}=ye;if(oe===0&&(O===0||qe===0))return $f;if(Be===0){const kt=Ta(Se,O),At=kt+Math.max(oe-1,0);return LS(zf(kt,At,fe))}const Ge=Uf(qe,Be,$e);let Ze,ot;xe?W===0&&F===0&&oe>0?(Ze=0,ot=oe-1):(Ze=Ge*Ds((W+_e)/(We+_e)),ot=Ge*Ff((F+_e)/(We+_e))-1,ot=Ra(O-1,uo(ot,Ge-1)),Ze=Ra(ot,uo(0,Ze))):(Ze=0,ot=-1);const Ct=zf(Ze,ot,fe),{bottom:lt,top:ht}=Hf(ye,ee,Z,Ct),dt=Ff(O/Ge),gt=dt*We+(dt-1)*_e-lt;return{bottom:lt,itemHeight:We,items:Ct,itemWidth:Be,offsetBottom:gt,offsetTop:ht,top:ht}})),A),ve(te(j,Me(O=>O!==null),pe(O=>O.length)),S),ve(te(St(R,D,A,_),Me(([O,W,{items:F}])=>F.length>0&&W.height!==0&&O.height!==0),pe(([O,W,{items:F},ee])=>{const{bottom:Z,top:ye}=Hf(O,ee,W,F);return[ye,Z]}),ut(ro)),t);const Y=ie(!1);ve(te(c,Fe(Y),pe(([O,W])=>W||O!==0)),Y);const ae=Xt(te(St(A,S),Me(([{items:O}])=>O.length>0),Fe(Y),Me(([[O,W],F])=>{const ee=O.items[O.items.length-1].index===W-1;return(F||O.bottom>0&&O.itemHeight>0&&O.offsetBottom===0&&O.items.length===W)&&ee}),pe(([[,O]])=>O-1),ut())),ne=Xt(te(je(A),Me(({items:O})=>O.length>0&&O[0].index===0),vn(0),ut())),ce=Xt(te(je(A),Fe($),Me(([{items:O},W])=>O.length>0&&!W),pe(([{items:O}])=>({endIndex:O[O.length-1].index,startIndex:O[0].index})),ut(lf),Nn(0)));ve(ce,h.scrollSeekRangeChanged),ve(te(B,Fe(R,D,S,_),pe(([O,W,F,ee,Z])=>{const ye=hf(O),{align:fe,behavior:oe,offset:xe}=ye;let Se=ye.index;Se==="LAST"&&(Se=ee-1),Se=uo(0,Se,Ra(ee-1,Se));let $e=Pa(W,Z,F,Se);return fe==="end"?$e=Bf($e-W.height+F.height):fe==="center"&&($e=Bf($e-W.height/2+F.height/2)),xe&&($e+=xe),{behavior:oe,top:$e}})),l);const G=Rt(te(A,pe(O=>O.offsetBottom+O.bottom)),0);return ve(te(k,pe(O=>({height:O.visibleHeight,width:O.visibleWidth}))),R),{customScrollParent:y,data:j,deviation:V,footerHeight:o,gap:_,headerHeight:s,increaseViewportBy:e,initialItemCount:E,itemDimensions:D,overscan:n,restoreStateFrom:z,scrollBy:i,scrollContainerState:a,scrollHeight:q,scrollTo:l,scrollToIndex:B,scrollTop:c,smoothScrollTargetReached:d,totalCount:S,useWindowScroll:x,viewportDimensions:R,windowScrollContainerState:b,windowScrollTo:C,windowViewportRect:k,...h,gridState:A,horizontalDirection:M,initialTopMostItemIndex:P,totalListHeight:G,...p,endReached:ae,propsReady:g,rangeChanged:ce,startReached:ne,stateChanged:N,stateRestoreInProgress:$,...T}},ct(ka,Bt,co,kf,$n,Ia,Dn));function Uf(e,t,n){return uo(1,Ds((e+n)/(Ds(t)+n)))}function Hf(e,t,n,r){const{height:o}=n;if(o===void 0||r.length===0)return{bottom:0,top:0};const s=Pa(e,t,n,r[0].index);return{bottom:Pa(e,t,n,r[r.length-1].index)+o,top:s}}function Pa(e,t,n,r){const o=Uf(e.width,n.width,t.column),s=Ds(r/o),i=s*n.height+uo(0,s-1)*t.row;return i>0?i+t.row:i}const BS=Je(()=>{const e=ie(f=>`Item ${f}`),t=ie({}),n=ie(null),r=ie("virtuoso-grid-item"),o=ie("virtuoso-grid-list"),s=ie(_a),i=ie("div"),a=ie(Nr),l=(f,p=null)=>Rt(te(t,pe(h=>h[f]),ut()),p),c=ie(!1),d=ie(!1);return ve(je(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")}}),zS=Je(([e,t])=>({...e,...t}),ct(FS,BS)),US=w.memo(function(){const e=pt("gridState"),t=pt("listClassName"),n=pt("itemClassName"),r=pt("itemContent"),o=pt("computeItemKey"),s=pt("isSeeking"),i=tn("scrollHeight"),a=pt("ItemComponent"),l=pt("ListComponent"),c=pt("ScrollSeekPlaceholder"),d=pt("context"),f=tn("itemDimensions"),p=tn("gap"),h=pt("log"),v=pt("stateRestoreInProgress"),g=tn("reportReadyState"),y=tr(w.useMemo(()=>x=>{const b=x.parentElement.parentElement.scrollHeight;i(b);const C=x.firstChild;if(C){const{height:k,width:T}=C.getBoundingClientRect();f({height:k,width:T})}p({column:Vf("column-gap",getComputedStyle(x).columnGap,h),row:Vf("row-gap",getComputedStyle(x).rowGap,h)})},[i,f,p,h]),!0,!1);return _f(()=>{e.itemHeight>0&&e.itemWidth>0&&g(!0)},[e]),v?null:u.jsx(l,{className:t,ref:y,...Pt(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,{...Pt(c,d),height:e.itemHeight,index:x.index,width:e.itemWidth},b):w.createElement(a,{...Pt(a,d),className:n,"data-index":x.index,key:b},r(x.index,x.data,d))})})}),HS=w.memo(function(){const e=pt("HeaderComponent"),t=tn("headerHeight"),n=pt("headerFooterTag"),r=tr(w.useMemo(()=>s=>{t(Ln(s,"height"))},[t]),!0,!1),o=pt("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...Pt(e,o)})}):null}),WS=w.memo(function(){const e=pt("FooterComponent"),t=tn("footerHeight"),n=pt("headerFooterTag"),r=tr(w.useMemo(()=>s=>{t(Ln(s,"height"))},[t]),!0,!1),o=pt("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...Pt(e,o)})}):null}),VS=({children:e})=>{const t=w.useContext(jf),n=tn("itemDimensions"),r=tn("viewportDimensions"),o=tr(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:Os(!1),children:e})},KS=({children:e})=>{const t=w.useContext(jf),n=tn("windowViewportRect"),r=tn("itemDimensions"),o=pt("customScrollParent"),s=ef(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:Os(!1),children:e})},qS=w.memo(function({...e}){const t=pt("useWindowScroll"),n=pt("customScrollParent"),r=n||t?YS:GS,o=n||t?KS:VS,s=pt("context");return u.jsx(r,{...e,...Pt(r,s),children:u.jsxs(o,{children:[u.jsx(HS,{}),u.jsx(US,{}),u.jsx(WS,{})]})})}),{useEmitter:Wf,useEmitterValue:pt,usePublisher:tn}=Nf(zS,{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"}},qS),GS=Df({useEmitter:Wf,useEmitterValue:pt,usePublisher:tn}),YS=Lf({useEmitter:Wf,useEmitterValue:pt,usePublisher:tn});function Vf(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Vt.WARN),t==="normal"?0:parseInt(t??"0",10)}const XS=ko.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 Kf({className:e,variant:t,...n}){return u.jsx("div",{className:se(XS({variant:t}),e),...n})}function Oa(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 qf(e){return!!(e&&typeof e=="object"&&(e.type==="file"||e.mimeType||e.filename||e.sourceType==="base64"))}function fo(e){if(typeof e=="string")return e;if(e&&typeof e=="object"){if(Array.isArray(e)){const n=e.map(fo).filter(r=>r!==void 0);if(!n.length){console.debug("[message-utils] sanitizeForDisplay - array emptied -> returning undefined",{originalLength:e.length});return}return n}if(qf(e)){try{console.debug("[message-utils] sanitizeForDisplay - dropping file-like object",{sampleFilename:e&&(e.filename||e.name)?e.filename||e.name:void 0,keys:Object.keys(e||{})})}catch(n){console.debug("[message-utils] sanitizeForDisplay - dropped file-like (unable to inspect)",{err:String(n)})}return}const t={};for(const n of Object.keys(e)){const r=e[n];if(n==="data"&&typeof r=="string"&&r.length>100)t[n]=`[base64 ${r.length} chars omitted]`;else{const o=fo(r);o!==void 0&&(t[n]=o)}}if(Object.keys(t).length)return t;try{console.debug("[message-utils] sanitizeForDisplay - object emptied -> returning undefined",{originalKeys:Object.keys(e||{})})}catch(n){console.debug("[message-utils] sanitizeForDisplay - object emptied -> returning undefined (inspect failed)",{err:String(n)})}return}return e}function po(e){if(typeof e=="string")return e;if(qf(e))return"";try{const t=fo(e);return t===void 0?"":typeof t=="string"?t:JSON.stringify(t,null,2)}catch{return""}}function JS(e){return typeof e!="string"?!1:/^[\s\n]*[-*]\s|^[\s\n]*#+\s|```|^\s*\[.*\]\(|^>\s/.test(e)}function ZS(e){const t=po(e);return typeof e=="string"&&JS(e)?{content:e,isMarkdown:!0}:{content:t,isMarkdown:!1}}function $s(e){if(e==null)return e;if(typeof e=="string"){const t=e.trim();if(t.startsWith("{")||t.startsWith("[")){const n=Oa(t);if(n!==null)return $s(n)}return e}return typeof e=="object"&&!Array.isArray(e)&&e.content!==void 0?$s(e.content):e}function QS(e){return e.filter(t=>t.type==="text").map(t=>t.text).join("")}function Gf(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 Fs(e){if(e==null)return null;const t=String(e).trim();return t.length>0?t:null}function eC(e){const t=r=>{try{const o=fo(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 k0(e,t=vs){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 E0(e){let t;return typeof e=="string"?t=e:typeof e=="object"&&e!==null?t=JSON.stringify(e):t=String(e),k0(t),T0(t)}const bs=0,Rn=1,Cr=2,qd=4;function Gd(e){return()=>e}function I0(e){e()}function Yd(e,t){return n=>e(t(n))}function Xd(e,t){return()=>e(t)}function N0(e,t){return n=>e(t,n)}function ca(e){return e!==void 0}function A0(...e){return()=>{e.map(I0)}}function Tr(){}function ws(e,t){return t(e),e}function j0(e,t){return t(e)}function ut(...e){return e}function tt(e,t){return e(Rn,t)}function Oe(e,t){e(bs,t)}function ua(e){e(Cr)}function bt(e){return e(qd)}function xe(e,t){return tt(e,N0(t,bs))}function ln(e,t){const n=e(Rn,r=>{n(),t(r)});return n}function Jd(e){let t,n;return r=>o=>{t=o,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function Zd(e,t){return e===t}function dt(e=Zd){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function Ne(e){return t=>n=>{e(n)&&t(n)}}function de(e){return t=>Yd(t,e)}function vn(e){return t=>()=>{t(e)}}function Q(e,...t){const n=_0(...t);return(r,o)=>{switch(r){case Cr:ua(e);return;case Rn:return tt(e,n(o))}}}function bn(e,t){return n=>r=>{n(t=e(t,r))}}function Zn(e){return t=>n=>{e>0?e--:t(n)}}function In(e){let t=null,n;return r=>o=>{t=o,!n&&(n=setTimeout(()=>{n=void 0,r(t)},e))}}function $e(...e){const t=new Array(e.length);let n=0,r=null;const o=Math.pow(2,e.length)-1;return e.forEach((s,i)=>{const a=Math.pow(2,i);tt(s,l=>{const 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 _0(...e){return t=>e.reduceRight(j0,t)}function M0(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=tt(e,s),t):(r(),Tr);case Cr:r(),n=null;return}}}function se(e){let t=e;const n=Ke();return(r,o)=>{switch(r){case bs:t=o;break;case Rn:{o(t);break}case qd:return t}return n(r,o)}}function Pt(e,t){return ws(se(t),n=>xe(e,n))}function Ke(){const e=[];return(t,n)=>{switch(t){case bs:e.slice().forEach(r=>{r(n)});return;case Cr:e.splice(0,e.length);return;case Rn:return e.push(n),()=>{const r=e.indexOf(n);r>-1&&e.splice(r,1)}}}}function Yt(e){return ws(Ke(),t=>xe(e,t))}function Xe(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:R0(),singleton:n}}const R0=()=>Symbol();function P0(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 St(...e){const t=Ke(),n=new Array(e.length);let r=0;const o=Math.pow(2,e.length)-1;return e.forEach((s,i)=>{const a=Math.pow(2,i);tt(s,l=>{n[i]=l,r=r|a,r===o&&Oe(t,n)})}),function(s,i){switch(s){case Cr:{ua(t);return}case Rn:return r===o&&i(n),tt(t,i)}}}function Ee(e,t=Zd){return Q(e,dt(t))}function da(...e){return function(t,n){switch(t){case Cr:return;case Rn:return A0(...e.map(r=>tt(r,n)))}}}var Vt=(e=>(e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR",e))(Vt||{});const O0={0:"debug",3:"error",1:"log",2:"warn"},D0=()=>typeof globalThis>"u"?window:globalThis,Pn=Xe(()=>{const e=se(3);return{log:se((t,n,r=1)=>{var o;const s=(o=D0().VIRTUOSO_LOG_LEVEL)!=null?o:bt(e);r>=s&&console[O0[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 fa(e,t,n).callbackRef}function fa(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 L0(e,t,n,r,o,s,i,a,l){const c=w.useCallback(d=>{const f=$0(d.children,t,a?"offsetWidth":"offsetHeight",o);let h=d.parentElement;for(;!h.dataset.virtuosoScroller;)h=h.parentElement;const p=h.lastElementChild.dataset.viewportType==="window";let v;p&&(v=h.ownerDocument.defaultView);const g=i?a?i.scrollLeft:i.scrollTop:p?a?v.scrollX||v.document.documentElement.scrollLeft:v.scrollY||v.document.documentElement.scrollTop:a?h.scrollLeft:h.scrollTop,y=i?a?i.scrollWidth:i.scrollHeight:p?a?v.document.documentElement.scrollWidth:v.document.documentElement.scrollHeight:a?h.scrollWidth:h.scrollHeight,x=i?a?i.offsetWidth:i.offsetHeight:p?a?v.innerWidth:v.innerHeight:a?h.offsetWidth:h.offsetHeight;r({scrollHeight:y,scrollTop:Math.max(g,0),viewportHeight:x}),s==null||s(a?Qd("column-gap",getComputedStyle(d).columnGap,o):Qd("row-gap",getComputedStyle(d).rowGap,o)),f!==null&&e(f)},[e,t,o,s,i,r,a]);return fa(c,n,l)}function $0(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},Vt.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 Qd(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Vt.WARN),t==="normal"?0:parseInt(t??"0",10)}function ef(e,t,n){const r=w.useRef(null),o=w.useCallback(l=>{if(!(l!=null&&l.offsetParent))return;const c=l.getBoundingClientRect(),d=c.width;let f,h;if(t){const p=t.getBoundingClientRect(),v=c.top-p.top;h=p.height-Math.max(0,v),f=v+t.scrollTop}else{const p=i.current.ownerDocument.defaultView;h=p.innerHeight-Math.max(0,c.top),f=c.top+p.scrollY}r.current={offsetTop:f,visibleHeight:h,visibleWidth:d},e(r.current)},[e,t]),{callbackRef:s,ref:i}=fa(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 Bt=Xe(()=>{const e=Ke(),t=Ke(),n=se(0),r=Ke(),o=se(0),s=Ke(),i=Ke(),a=se(0),l=se(0),c=se(0),d=se(0),f=Ke(),h=Ke(),p=se(!1),v=se(!1),g=se(!1);return xe(Q(e,de(({scrollTop:y})=>y)),t),xe(Q(e,de(({scrollHeight:y})=>y)),i),xe(t,o),{deviation:n,fixedFooterHeight:c,fixedHeaderHeight:l,footerHeight:d,headerHeight:a,horizontalDirection:v,scrollBy:h,scrollContainerState:e,scrollHeight:i,scrollingInProgress:p,scrollTo:f,scrollTop:t,skipAnimationFrameInResizeObserver:g,smoothScrollTargetReached:r,statefulScrollTop:o,viewportHeight:s}},[],{singleton:!0}),Gr={lvl:0};function tf(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 it(e){return e===Gr}function Yr(e,t){if(!it(e))return t===e.k?e.v:t<e.k?Yr(e.l,t):Yr(e.r,t)}function cn(e,t,n="k"){if(it(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 Xt(e,t,n){return it(e)?of(t,n,1):t===e.k?Ct(e,{k:t,v:n}):t<e.k?sf(Ct(e,{l:Xt(e.l,t,n)})):sf(Ct(e,{r:Xt(e.r,t,n)}))}function kr(){return Gr}function Ss(e,t,n){if(it(e))return[];const r=cn(e,t)[0];return F0(pa(e,r,n))}function ha(e,t){if(it(e))return Gr;const{k:n,l:r,r:o}=e;if(t===n){if(it(r))return o;if(it(o))return r;{const[s,i]=rf(r);return Cs(Ct(e,{k:s,l:nf(r),v:i}))}}else return t<n?Cs(Ct(e,{l:ha(r,t)})):Cs(Ct(e,{r:ha(o,t)}))}function er(e){return it(e)?[]:[...er(e.l),{k:e.k,v:e.v},...er(e.r)]}function pa(e,t,n){if(it(e))return[];const{k:r,l:o,r:s,v:i}=e;let a=[];return r>t&&(a=a.concat(pa(o,t,n))),r>=t&&r<=n&&a.push({k:r,v:i}),r<=n&&(a=a.concat(pa(s,t,n))),a}function Cs(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(ma(t))return af(Ct(e,{lvl:n-1}));if(!it(t)&&!it(t.r))return Ct(t.r,{l:Ct(t,{r:t.r.l}),lvl:n,r:Ct(e,{l:t.r.r,lvl:n-1})});throw new Error("Unexpected empty nodes")}else{if(ma(e))return ga(Ct(e,{lvl:n-1}));if(!it(r)&&!it(r.l)){const o=r.l,s=ma(o)?r.lvl-1:r.lvl;return Ct(o,{l:Ct(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:ga(Ct(r,{l:o.r,lvl:s}))})}else throw new Error("Unexpected empty nodes")}}function Ct(e,t){return of(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 nf(e){return it(e.r)?e.l:Cs(Ct(e,{r:nf(e.r)}))}function ma(e){return it(e)||e.lvl>e.r.lvl}function rf(e){return it(e.r)?[e.k,e.v]:rf(e.r)}function of(e,t,n,r=Gr,o=Gr){return{k:e,l:r,lvl:n,r:o,v:t}}function sf(e){return ga(af(e))}function af(e){const{l:t}=e;return!it(t)&&t.lvl===e.lvl?Ct(t,{r:Ct(e,{l:t.r})}):e}function ga(e){const{lvl:t,r:n}=e;return!it(n)&&!it(n.r)&&n.lvl===t&&n.r.lvl===t?Ct(n,{l:Ct(e,{r:n.l}),lvl:t+1}):e}function F0(e){return tf(e,({k:t,v:n})=>({index:t,value:n}))}function lf(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function Xr(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}const xa=Xe(()=>({recalcInProgress:se(!1)}),[],{singleton:!0});function cf(e,t,n){return e[Ts(e,t,n)]}function Ts(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 B0(e,t,n,r){const o=Ts(e,t,r),s=Ts(e,n,r,o);return e.slice(o,s+1)}function On(e,t){return Math.round(e.getBoundingClientRect()[t])}function ks(e){return!it(e.groupOffsetTree)}function ya({index:e},t){return t===e?0:t<e?-1:1}function z0(){return{groupIndices:[],groupOffsetTree:kr(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:kr()}}function U0(e,t){let n=it(e)?0:1/0;for(const r of t){const{endIndex:o,size:s,startIndex:i}=r;if(n=Math.min(n,i),it(e)){e=Xt(e,0,s);continue}const a=Ss(e,i-1,o+1);if(a.some(Y0(r)))continue;let l=!1,c=!1;for(const{end:d,start:f,value:h}of a)l?(o>=f||s===h)&&(e=ha(e,f)):(c=h!==s,l=!0),d>o&&o>=f&&h!==s&&(e=Xt(e,o+1,h));c&&(e=Xt(e,i,s))}return[e,n]}function H0(e){return typeof e.groupIndex<"u"}function W0({offset:e},t){return t===e?0:t<e?-1:1}function Jr(e,t,n){if(t.length===0)return 0;const{index:r,offset:o,size:s}=cf(t,e,ya),i=e-r,a=s*i+(i-1)*n+o;return a>0?a+n:a}function uf(e,t){if(!ks(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function df(e,t,n){if(H0(e))return t.groupIndices[e.groupIndex]+1;{const r=e.index==="LAST"?n:e.index;let o=uf(r,t);return o=Math.max(0,o,Math.min(n,o)),o}}function V0(e,t,n,r=0){return r>0&&(t=Math.max(t,cf(e,r,ya).offset)),tf(B0(e,t,n,W0),G0)}function K0(e,[t,n,r,o]){t.length>0&&r("received item sizes",t,Vt.DEBUG);const s=e.sizeTree;let i=s,a=0;if(n.length>0&&it(s)&&t.length===2){const h=t[0].size,p=t[1].size;i=n.reduce((v,g)=>Xt(Xt(v,g,h),g+1,p),i)}else[i,a]=U0(i,t);if(i===s)return e;const{lastIndex:l,lastOffset:c,lastSize:d,offsetTree:f}=va(e.offsetTree,a,i,o);return{groupIndices:n,groupOffsetTree:n.reduce((h,p)=>Xt(h,p,Jr(p,f,o)),kr()),lastIndex:l,lastOffset:c,lastSize:d,offsetTree:f,sizeTree:i}}function q0(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 ff(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 va(e,t,n,r){let o=e,s=0,i=0,a=0,l=0;if(t!==0){l=Ts(o,t-1,ya),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 Ss(n,t,1/0)){const f=c-s,h=f*i+a+f*r;o.push({index:c,offset:h,size:d}),s=c,a=h,i=d}return{lastIndex:s,lastOffset:a,lastSize:i,offsetTree:o}}function G0(e){return{index:e.index,value:e}}function Y0(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 X0={offsetHeight:"height",offsetWidth:"width"},wn=Xe(([{log:e},{recalcInProgress:t}])=>{const n=Ke(),r=Ke(),o=Pt(r,0),s=Ke(),i=Ke(),a=se(0),l=se([]),c=se(void 0),d=se(void 0),f=se((S,T)=>On(S,X0[T])),h=se(void 0),p=se(0),v=z0(),g=Pt(Q(n,$e(l,e,p),bn(K0,v),dt()),v),y=Pt(Q(l,dt(),bn((S,T)=>({current:T,prev:S.current}),{current:[],prev:[]}),de(({prev:S})=>S)),[]);xe(Q(l,Ne(S=>S.length>0),$e(g,p),de(([S,T,E])=>{const j=S.reduce((R,O,B)=>Xt(R,O,Jr(O,T.offsetTree,E)||B),kr());return{...T,groupIndices:S,groupOffsetTree:j}})),g),xe(Q(r,$e(g),Ne(([S,{lastIndex:T}])=>S<T),de(([S,{lastIndex:T,lastSize:E}])=>[{endIndex:T,size:E,startIndex:S}])),n),xe(c,d);const x=Pt(Q(c,de(S=>S===void 0)),!0);xe(Q(d,Ne(S=>S!==void 0&&it(bt(g).sizeTree)),de(S=>[{endIndex:0,size:S,startIndex:0}])),n);const b=Yt(Q(n,$e(g),bn(({sizes:S},[T,E])=>({changed:E!==S,sizes:E}),{changed:!1,sizes:v}),de(S=>S.changed)));tt(Q(a,bn((S,T)=>({diff:S.prev-T,prev:T}),{diff:0,prev:0}),de(S=>S.diff)),S=>{const{groupIndices:T}=bt(g);if(S>0)Oe(t,!0),Oe(s,S+ff(S,T));else if(S<0){const E=bt(y);E.length>0&&(S-=ff(-S,E)),Oe(i,S)}}),tt(Q(a,$e(e)),([S,T])=>{S<0&&T("`firstItemIndex` prop should not be set to less than zero. If you don't know the total count, just use a very high value",{firstItemIndex:a},Vt.ERROR)});const C=Yt(s);xe(Q(s,$e(g),de(([S,T])=>{const E=T.groupIndices.length>0,j=[],R=T.lastSize;if(E){const O=Yr(T.sizeTree,0);let B=0,q=0;for(;B<S;){const P=T.groupIndices[q],M=T.groupIndices.length===q+1?1/0:T.groupIndices[q+1]-P-1;j.push({endIndex:P,size:O,startIndex:P}),j.push({endIndex:P+1+M-1,size:R,startIndex:P+1}),q++,B+=M+1}const K=er(T.sizeTree);return B!==S&&K.shift(),K.reduce((P,{k:M,v:I})=>{let z=P.ranges;return P.prevSize!==0&&(z=[...P.ranges,{endIndex:M+S-1,size:P.prevSize,startIndex:P.prevIndex}]),{prevIndex:M+S,prevSize:I,ranges:z}},{prevIndex:S,prevSize:0,ranges:j}).ranges}return er(T.sizeTree).reduce((O,{k:B,v:q})=>({prevIndex:B+S,prevSize:q,ranges:[...O.ranges,{endIndex:B+S-1,size:O.prevSize,startIndex:O.prevIndex}]}),{prevIndex:0,prevSize:R,ranges:[]}).ranges})),n);const k=Yt(Q(i,$e(g,p),de(([S,{offsetTree:T},E])=>{const j=-S;return Jr(j,T,E)})));return xe(Q(i,$e(g,p),de(([S,T,E])=>{if(T.groupIndices.length>0){if(it(T.sizeTree))return T;let j=kr();const R=bt(y);let O=0,B=0,q=0;for(;O<-S;){q=R[B];const K=R[B+1]-q-1;B++,O+=K+1}if(j=er(T.sizeTree).reduce((K,{k:P,v:M})=>Xt(K,Math.max(0,P+S),M),j),O!==-S){const K=Yr(T.sizeTree,q);j=Xt(j,0,K);const P=cn(T.sizeTree,-S+1)[1];j=Xt(j,1,P)}return{...T,sizeTree:j,...va(T.offsetTree,0,j,E)}}else{const j=er(T.sizeTree).reduce((R,{k:O,v:B})=>Xt(R,Math.max(0,O+S),B),kr());return{...T,sizeTree:j,...va(T.offsetTree,0,j,E)}}})),g),{beforeUnshiftWith:C,data:h,defaultItemSize:d,firstItemIndex:a,fixedItemSize:c,gap:p,groupIndices:l,itemSize:f,listRefresh:b,shiftWith:i,shiftWithOffset:k,sizeRanges:n,sizes:g,statefulTotalCount:o,totalCount:r,trackItemSizes:x,unshiftWith:s}},ut(Pn,xa),{singleton:!0});function J0(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const hf=Xe(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=Ke(),i=Ke(),a=Yt(Q(s,de(J0)));return xe(Q(a,de(l=>l.totalCount)),n),xe(Q(a,de(l=>l.groupIndices)),e),xe(Q(St(o,t,r),Ne(([l,c])=>ks(c)),de(([l,c,d])=>cn(c.groupOffsetTree,Math.max(l-d,0),"v")[0]),dt(),de(l=>[l])),i),{groupCounts:s,topItemsIndexes:i}},ut(wn,Bt)),Dn=Xe(([{log:e}])=>{const t=se(!1),n=Yt(Q(t,Ne(r=>r),dt()));return tt(t,r=>{r&&bt(e)("props updated",{},Vt.DEBUG)}),{didMount:n,propsReady:t}},ut(Pn),{singleton:!0}),Z0=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function pf(e){const t=typeof e=="number"?{index:e}:e;return t.align||(t.align="start"),(!t.behavior||!Z0)&&(t.behavior="auto"),t.offset||(t.offset=0),t}const Zr=Xe(([{gap:e,listRefresh:t,sizes:n,totalCount:r},{fixedFooterHeight:o,fixedHeaderHeight:s,footerHeight:i,headerHeight:a,scrollingInProgress:l,scrollTo:c,smoothScrollTargetReached:d,viewportHeight:f},{log:h}])=>{const p=Ke(),v=Ke(),g=se(0);let y=null,x=null,b=null;function C(){y&&(y(),y=null),b&&(b(),b=null),x&&(clearTimeout(x),x=null),Oe(l,!1)}return xe(Q(p,$e(n,f,r,g,a,i,h),$e(e,s,o),de(([[k,S,T,E,j,R,O,B],q,K,P])=>{const M=pf(k),{align:I,behavior:z,offset:L}=M,A=E-1,$=df(M,S,A);let H=Jr($,S.offsetTree,q)+R;I==="end"?(H+=K+cn(S.sizeTree,$)[1]-T+P,$===A&&(H+=O)):I==="center"?H+=(K+cn(S.sizeTree,$)[1]-T+P)/2:H-=j,L&&(H+=L);const _=G=>{C(),G?(B("retrying to scroll to",{location:k},Vt.DEBUG),Oe(p,k)):(Oe(v,!0),B("list did not change, scroll successful",{},Vt.DEBUG))};if(C(),z==="smooth"){let G=!1;b=tt(t,re=>{G=G||re}),y=ln(d,()=>{_(G)})}else y=ln(Q(t,Q0(150)),_);return x=setTimeout(()=>{C()},1200),Oe(l,!0),B("scrolling from index to",{behavior:z,index:$,top:H},Vt.DEBUG),{behavior:z,top:H}})),c),{scrollTargetReached:v,scrollToIndex:p,topListHeight:g}},ut(wn,Bt,Pn),{singleton:!0});function Q0(e){return t=>{const n=setTimeout(()=>{t(!1)},e);return r=>{r&&(t(!0),clearTimeout(n))}}}function ba(e,t){e==0?t():requestAnimationFrame(()=>{ba(e-1,t)})}function wa(e,t){const n=t-1;return typeof e=="number"?e:e.index==="LAST"?n:e.index}const Qr=Xe(([{defaultItemSize:e,listRefresh:t,sizes:n},{scrollTop:r},{scrollTargetReached:o,scrollToIndex:s},{didMount:i}])=>{const a=se(!0),l=se(0),c=se(!0);return xe(Q(i,$e(l),Ne(([d,f])=>!!f),vn(!1)),a),xe(Q(i,$e(l),Ne(([d,f])=>!!f),vn(!1)),c),tt(Q(St(t,i),$e(a,n,e,c),Ne(([[,d],f,{sizeTree:h},p,v])=>d&&(!it(h)||ca(p))&&!f&&!v),$e(l)),([,d])=>{ln(o,()=>{Oe(c,!0)}),ba(4,()=>{ln(r,()=>{Oe(a,!0)}),Oe(s,d)})}),{initialItemFinalLocationReached:c,initialTopMostItemIndex:l,scrolledToInitialItem:a}},ut(wn,Bt,Zr,Dn),{singleton:!0});function mf(e,t){return Math.abs(e-t)<1.01}const eo="up",to="down",eS="none",tS={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},nS=0,no=Xe(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:o,viewportHeight:s}])=>{const i=se(!1),a=se(!0),l=Ke(),c=Ke(),d=se(4),f=se(nS),h=Pt(Q(da(Q(Ee(o),Zn(1),vn(!0)),Q(Ee(o),Zn(1),vn(!1),Jd(100))),dt()),!1),p=Pt(Q(da(Q(n,vn(!0)),Q(n,vn(!1),Jd(200))),dt()),!1);xe(Q(St(Ee(o),Ee(f)),de(([b,C])=>b<=C),dt()),a),xe(Q(a,In(50)),c);const v=Yt(Q(St(r,Ee(s),Ee(t),Ee(e),Ee(d)),bn((b,[{scrollHeight:C,scrollTop:k},S,T,E,j])=>{const R=k+S-C>-j,O={scrollHeight:C,scrollTop:k,viewportHeight:S};if(R){let q,K;return k>b.state.scrollTop?(q="SCROLLED_DOWN",K=b.state.scrollTop-k):(q="SIZE_DECREASED",K=b.state.scrollTop-k||b.scrollTopDelta),{atBottom:!0,atBottomBecause:q,scrollTopDelta:K,state:O}}let B;return O.scrollHeight>b.state.scrollHeight?B="SIZE_INCREASED":S<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:O}},tS),dt((b,C)=>b&&b.atBottom===C.atBottom))),g=Pt(Q(r,bn((b,{scrollHeight:C,scrollTop:k,viewportHeight:S})=>{if(mf(b.scrollHeight,C))return{changed:!1,jump:0,scrollHeight:C,scrollTop:k};{const T=C-(k+S)<1;return b.scrollTop!==k&&T?{changed:!0,jump:b.scrollTop-k,scrollHeight:C,scrollTop:k}:{changed:!0,jump:0,scrollHeight:C,scrollTop:k}}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),Ne(b=>b.changed),de(b=>b.jump)),0);xe(Q(v,de(b=>b.atBottom)),i),xe(Q(i,In(50)),l);const y=se(to);xe(Q(r,de(({scrollTop:b})=>b),dt(),bn((b,C)=>bt(p)?{direction:b.direction,prevScrollTop:C}:{direction:C<b.prevScrollTop?eo:to,prevScrollTop:C},{direction:to,prevScrollTop:0}),de(b=>b.direction)),y),xe(Q(r,In(50),vn(eS)),y);const x=se(0);return xe(Q(h,Ne(b=>!b),vn(0)),x),xe(Q(o,In(100),$e(h),Ne(([b,C])=>!!C),bn(([b,C],[k])=>[C,k],[0,0]),de(([b,C])=>C-b)),x),{atBottomState:v,atBottomStateChange:l,atBottomThreshold:d,atTopStateChange:c,atTopThreshold:f,isAtBottom:i,isAtTop:a,isScrolling:h,lastJumpDueToItemResize:g,scrollDirection:y,scrollVelocity:x}},ut(Bt)),Es="top",Is="bottom",gf="none";function xf(e,t,n){return typeof e=="number"?n===eo&&t===Es||n===to&&t===Is?e:0:n===eo?t===Es?e.main:e.reverse:t===Is?e.main:e.reverse}function yf(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const Sa=Xe(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:o}])=>{const s=Ke(),i=se(0),a=se(0),l=se(0),c=Pt(Q(St(Ee(r),Ee(o),Ee(n),Ee(s,Xr),Ee(l),Ee(i),Ee(t),Ee(e),Ee(a)),de(([d,f,h,[p,v],g,y,x,b,C])=>{const k=d-b,S=y+x,T=Math.max(h-k,0);let E=gf;const j=yf(C,Es),R=yf(C,Is);return p-=b,p+=h+x,v+=h+x,v-=b,p>d+S-j&&(E=eo),v<d-T+f+R&&(E=to),E!==gf?[Math.max(k-h-xf(g,Es,E)-j,0),k-T-x+f+xf(g,Is,E)+R]:null}),Ne(d=>d!=null),dt(Xr)),[0,0]);return{increaseViewportBy:a,listBoundary:s,overscan:l,topListHeight:i,visibleRange:c}},ut(Bt),{singleton:!0});function rS(e,t,n){if(ks(t)){const r=uf(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 Ca={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function Ns(e,t,n,r,o,s){const{lastIndex:i,lastOffset:a,lastSize:l}=o;let c=0,d=0;if(e.length>0){c=e[0].offset;const g=e[e.length-1];d=g.offset+g.size}const f=n-i,h=a+f*l+(f-1)*r,p=c,v=h-d;return{bottom:d,firstItemIndex:s,items:bf(e,o,s),offsetBottom:v,offsetTop:c,top:p,topItems:bf(t,o,s),topListHeight:t.reduce((g,y)=>y.size+g,0),totalCount:n}}function vf(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=wa(t,a),c=Array.from({length:a}).map((d,f)=>({data:s[f+l],index:f+l,offset:0,size:0}));return Ns(c,[],a,o,n,r)}function bf(e,t,n){if(e.length===0)return[];if(!ks(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=Ss(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=Xe(([{data:e,firstItemIndex:t,gap:n,sizes:r,totalCount:o},s,{listBoundary:i,topListHeight:a,visibleRange:l},{initialTopMostItemIndex:c,scrolledToInitialItem:d},{topListHeight:f},h,{didMount:p},{recalcInProgress:v}])=>{const g=se([]),y=se(0),x=Ke();xe(s.topItemsIndexes,g);const b=Pt(Q(St(p,v,Ee(l,Xr),Ee(o),Ee(r),Ee(c),d,Ee(g),Ee(t),Ee(n),e),Ne(([T,E,,j,,,,,,,R])=>{const O=R&&R.length!==j;return T&&!E&&!O}),de(([,,[T,E],j,R,O,B,q,K,P,M])=>{const I=R,{offsetTree:z,sizeTree:L}=I,A=bt(y);if(j===0)return{...Ca,totalCount:j};if(T===0&&E===0)return A===0?{...Ca,totalCount:j}:vf(A,O,R,K,P,M||[]);if(it(L))return A>0?null:Ns(rS(wa(O,j),I,M),[],j,P,I,K);const $=[];if(q.length>0){const ee=q[0],ie=q[q.length-1];let Y=0;for(const D of Ss(L,ee,ie)){const V=D.value,U=Math.max(D.start,ee),Z=Math.min(D.end,ie);for(let J=U;J<=Z;J++)$.push({data:M==null?void 0:M[J],index:J,offset:Y,size:V}),Y+=V}}if(!B)return Ns([],$,j,P,I,K);const H=q.length>0?q[q.length-1]+1:0,_=V0(z,T,E,H);if(_.length===0)return null;const G=j-1,re=ws([],ee=>{for(const ie of _){const Y=ie.value;let D=Y.offset,V=ie.start;const U=Y.size;if(Y.offset<T){V+=Math.floor((T-Y.offset+P)/(U+P));const J=V-ie.start;D+=J*U+J*P}V<H&&(D+=(H-V)*U,V=H);const Z=Math.min(ie.end,G);for(let J=V;J<=Z&&!(D>=E);J++)ee.push({data:M==null?void 0:M[J],index:J,offset:D,size:U}),D+=U+P}});return Ns(re,$,j,P,I,K)}),Ne(T=>T!==null),dt()),Ca);xe(Q(e,Ne(ca),de(T=>T==null?void 0:T.length)),o),xe(Q(b,de(T=>T.topListHeight)),f),xe(f,a),xe(Q(b,de(T=>[T.top,T.bottom])),i),xe(Q(b,de(T=>T.items)),x);const C=Yt(Q(b,Ne(({items:T})=>T.length>0),$e(o,e),Ne(([{items:T},E])=>T[T.length-1].originalIndex===E-1),de(([,T,E])=>[T-1,E]),dt(Xr),de(([T])=>T))),k=Yt(Q(b,In(200),Ne(({items:T,topItems:E})=>T.length>0&&T[0].originalIndex===E.length),de(({items:T})=>T[0].index),dt())),S=Yt(Q(b,Ne(({items:T})=>T.length>0),de(({items:T})=>{let E=0,j=T.length-1;for(;T[E].type==="group"&&E<j;)E++;for(;T[j].type==="group"&&j>E;)j--;return{endIndex:T[j].index,startIndex:T[E].index}}),dt(lf)));return{endReached:C,initialItemCount:y,itemsRendered:x,listState:b,rangeChanged:S,startReached:k,topItemsIndexes:g,...h}},ut(wn,hf,Sa,Qr,Zr,no,Dn,xa),{singleton:!0}),wf=Xe(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:o}])=>{const s=Ke(),i=Pt(Q(St(n,e,r,t,o),de(([a,l,c,d,f])=>a+l+c+d+f.offsetBottom+f.bottom)),0);return xe(Ee(i),s),{totalListHeight:i,totalListHeightChanged:s}},ut(Bt,tr),{singleton:!0}),oS=Xe(([{viewportHeight:e},{totalListHeight:t}])=>{const n=se(!1),r=Pt(Q(St(n,e,t),Ne(([o])=>o),de(([,o,s])=>Math.max(0,o-s)),In(0),dt()),0);return{alignToBottom:n,paddingTopAddition:r}},ut(Bt,wf),{singleton:!0}),Sf=Xe(()=>({context:se(null)})),sS=({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,Cf=Xe(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:s,scrollingInProgress:i,scrollTop:a,viewportHeight:l},{scrollToIndex:c}])=>{const d=Ke();return xe(Q(d,$e(t,l,n,s,o,r,a),$e(e),de(([[f,h,p,v,g,y,x,b],C])=>{const{align:k,behavior:S,calculateViewLocation:T=sS,done:E,...j}=f,R=df(f,h,v-1),O=Jr(R,h.offsetTree,C)+g+y,B=O+cn(h.sizeTree,R)[1],q=b+y,K=b+p-x,P=T({itemBottom:B,itemTop:O,locationParams:{align:k,behavior:S,...j},viewportBottom:K,viewportTop:q});return P?E&&ln(Q(i,Ne(M=>!M),Zn(bt(i)?1:2)),E):E&&E(),P}),Ne(f=>f!==null)),c),{scrollIntoView:d}},ut(wn,Bt,Zr,tr,Pn),{singleton:!0});function Tf(e){return e?e==="smooth"?"smooth":"auto":!1}const iS=(e,t)=>typeof e=="function"?Tf(e(t)):t&&Tf(e),aS=Xe(([{listRefresh:e,totalCount:t,fixedItemSize:n,data:r},{atBottomState:o,isAtBottom:s},{scrollToIndex:i},{scrolledToInitialItem:a},{didMount:l,propsReady:c},{log:d},{scrollingInProgress:f},{context:h},{scrollIntoView:p}])=>{const v=se(!1),g=Ke();let y=null;function x(S){Oe(i,{align:"end",behavior:S,index:"LAST"})}tt(Q(St(Q(Ee(t),Zn(1)),l),$e(Ee(v),s,a,f),de(([[S,T],E,j,R,O])=>{let B=T&&R,q="auto";return B&&(q=iS(E,j||O),B=B&&!!q),{followOutputBehavior:q,shouldFollow:B,totalCount:S}}),Ne(({shouldFollow:S})=>S)),({followOutputBehavior:S,totalCount:T})=>{y&&(y(),y=null),bt(n)?requestAnimationFrame(()=>{bt(d)("following output to ",{totalCount:T},Vt.DEBUG),x(S)}):y=ln(e,()=>{bt(d)("following output to ",{totalCount:T},Vt.DEBUG),x(S),y=null})});function b(S){const T=ln(o,E=>{S&&!E.atBottom&&E.notAtBottomBecause==="SIZE_INCREASED"&&!y&&(bt(d)("scrolling to bottom due to increased size",{},Vt.DEBUG),x("auto"))});setTimeout(T,100)}tt(Q(St(Ee(v),t,c),Ne(([S,,T])=>S&&T),bn(({value:S},[,T])=>({refreshed:S===T,value:T}),{refreshed:!1,value:0}),Ne(({refreshed:S})=>S),$e(v,t)),([,S])=>{bt(a)&&b(S!==!1)}),tt(g,()=>{b(bt(v)!==!1)}),tt(St(Ee(v),o),([S,T])=>{S&&!T.atBottom&&T.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&x("auto")});const C=se(null),k=Ke();return xe(da(Q(Ee(r),de(S=>{var T;return(T=S==null?void 0:S.length)!=null?T:0})),Q(Ee(t))),k),tt(Q(St(Q(k,Zn(1)),l),$e(Ee(C),a,f,h),de(([[S,T],E,j,R,O])=>T&&j&&(E==null?void 0:E({context:O,totalCount:S,scrollingInProgress:R}))),Ne(S=>!!S),In(0)),S=>{y&&(y(),y=null),bt(n)?requestAnimationFrame(()=>{bt(d)("scrolling into view",{}),Oe(p,S)}):y=ln(e,()=>{bt(d)("scrolling into view",{}),Oe(p,S),y=null})}),{autoscrollToBottom:g,followOutput:v,scrollIntoViewOnChange:C}},ut(wn,no,Zr,Qr,Dn,Pn,Bt,Sf,Cf)),lS=Xe(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:s,listState:i},{didMount:a}])=>(xe(Q(a,$e(s),Ne(([,l])=>l!==0),$e(o,r,t,n,e),de(([[,l],c,d,f,h,p=[]])=>vf(l,c,d,f,h,p))),i),{}),ut(wn,Qr,tr,Dn),{singleton:!0}),cS=Xe(([{didMount:e},{scrollTo:t},{listState:n}])=>{const r=se(0);return tt(Q(e,$e(r),Ne(([,o])=>o!==0),de(([,o])=>({top:o}))),o=>{ln(Q(n,Zn(1),Ne(s=>s.items.length>1)),()=>{requestAnimationFrame(()=>{Oe(t,o)})})}),{initialScrollTop:r}},ut(Dn,Bt,tr),{singleton:!0}),kf=Xe(([{scrollVelocity:e}])=>{const t=se(!1),n=Ke(),r=se(!1);return xe(Q(e,$e(r,t,n),Ne(([o,s])=>!!s),de(([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}),dt()),t),tt(Q(St(t,e,n),$e(r)),([[o,s,i],a])=>{o&&a&&a.change&&a.change(s,i)}),{isSeeking:t,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:e}},ut(no),{singleton:!0}),Ta=Xe(([{scrollContainerState:e,scrollTo:t}])=>{const n=Ke(),r=Ke(),o=Ke(),s=se(!1),i=se(void 0);return xe(Q(St(n,r),de(([{scrollHeight:a,scrollTop:l,viewportHeight:c},{offsetTop:d}])=>({scrollHeight:a,scrollTop:Math.max(0,l-d),viewportHeight:c}))),e),xe(Q(t,$e(r),de(([a,{offsetTop:l}])=>({...a,top:a.top+l}))),o),{customScrollParent:i,useWindowScroll:s,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:r}},ut(Bt)),uS=Xe(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:o},{didMount:s},{useWindowScroll:i,windowScrollContainerState:a,windowViewportRect:l}])=>{const c=Ke(),d=se(void 0),f=se(null),h=se(null);return xe(a,f),xe(l,h),tt(Q(c,$e(t,r,i,f,h,n)),([p,v,g,y,x,b,C])=>{const k=q0(v.sizeTree);y&&x!==null&&b!==null&&(g=x.scrollTop-b.offsetTop),g-=C,p({ranges:k,scrollTop:g})}),xe(Q(d,Ne(ca),de(dS)),o),xe(Q(s,$e(d),Ne(([,p])=>p!==void 0),dt(),de(([,p])=>p.ranges)),e),{getState:c,restoreStateFrom:d}},ut(wn,Bt,Qr,Dn,Ta));function dS(e){return{align:"start",index:0,offset:e.scrollTop}}const fS=Xe(([{topItemsIndexes:e}])=>{const t=se(0);return xe(Q(t,Ne(n=>n>=0),de(n=>Array.from({length:n}).map((r,o)=>o))),e),{topItemCount:t}},ut(tr));function Ef(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const hS=Ef(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),pS=Xe(([{deviation:e,scrollBy:t,scrollingInProgress:n,scrollTop:r},{isAtBottom:o,isScrolling:s,lastJumpDueToItemResize:i,scrollDirection:a},{listState:l},{beforeUnshiftWith:c,gap:d,shiftWithOffset:f,sizes:h},{log:p},{recalcInProgress:v}])=>{const g=Yt(Q(l,$e(i),bn(([,x,b,C],[{bottom:k,items:S,offsetBottom:T,totalCount:E},j])=>{const R=k+T;let O=0;return b===E&&x.length>0&&S.length>0&&(S[0].originalIndex===0&&x[0].originalIndex===0||(O=R-C,O!==0&&(O+=j))),[O,S,E,R]},[0,[],0,0]),Ne(([x])=>x!==0),$e(r,a,n,o,p,v),Ne(([,x,b,C,,,k])=>!k&&!C&&x!==0&&b===eo),de(([[x],,,,,b])=>(b("Upward scrolling compensation",{amount:x},Vt.DEBUG),x))));function y(x){x>0?(Oe(t,{behavior:"auto",top:-x}),Oe(e,0)):(Oe(e,0),Oe(t,{behavior:"auto",top:-x}))}return tt(Q(g,$e(e,s)),([x,b,C])=>{C&&hS()?Oe(e,b-x):y(-x)}),tt(Q(St(Pt(s,!1),e,v),Ne(([x,b,C])=>!x&&!C&&b!==0),de(([x,b])=>b),In(1)),y),xe(Q(f,de(x=>({top:-x}))),t),tt(Q(c,$e(h,d),de(([x,{groupIndices:b,lastSize:C,sizeTree:k},S])=>{function T(E){return E*(C+S)}if(b.length===0)return T(x);{let E=0;const j=Yr(k,0);let R=0,O=0;for(;R<x;){R++,E+=j;let B=b.length===O+1?1/0:b[O+1]-b[O]-1;R+B>x&&(E-=j,B=x-R+1),R+=B,E+=T(B),O++}return E}})),x=>{Oe(e,x),requestAnimationFrame(()=>{Oe(t,{top:x}),requestAnimationFrame(()=>{Oe(e,0),Oe(v,!1)})})}),{deviation:e}},ut(Bt,no,tr,wn,Pn,xa)),mS=Xe(([e,t,n,r,o,s,i,a,l,c,d])=>({...e,...t,...n,...r,...o,...s,...i,...a,...l,...c,...d}),ut(Sa,lS,Dn,kf,wf,cS,oS,Ta,Cf,Pn,Sf)),If=Xe(([{data:e,defaultItemSize:t,firstItemIndex:n,fixedItemSize:r,gap:o,groupIndices:s,itemSize:i,sizeRanges:a,sizes:l,statefulTotalCount:c,totalCount:d,trackItemSizes:f},{initialItemFinalLocationReached:h,initialTopMostItemIndex:p,scrolledToInitialItem:v},g,y,x,{listState:b,topItemsIndexes:C,...k},{scrollToIndex:S},T,{topItemCount:E},{groupCounts:j},R])=>(xe(k.rangeChanged,R.scrollSeekRangeChanged),xe(Q(R.windowViewportRect,de(O=>O.visibleHeight)),g.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:n,fixedItemHeight:r,gap:o,groupCounts:j,initialItemFinalLocationReached:h,initialTopMostItemIndex:p,scrolledToInitialItem:v,sizeRanges:a,topItemCount:E,topItemsIndexes:C,totalCount:d,...x,groupIndices:s,itemSize:i,listState:b,scrollToIndex:S,statefulTotalCount:c,trackItemSizes:f,...k,...R,...g,sizes:l,...y}),ut(wn,Qr,Bt,uS,aS,tr,Zr,pS,fS,hf,mS));function gS(e,t){const n={},r={};let o=0;const s=e.length;for(;o<s;)r[e[o]]=1,o+=1;for(const i in t)Object.hasOwn(r,i)||(n[i]=t[i]);return n}const As=typeof document<"u"?w.useLayoutEffect:w.useEffect;function Nf(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&&Oe(y.propsReady,!1);for(const b of r){const C=y[t.required[b]];Oe(C,x[b])}for(const b of o)if(b in x){const C=y[t.optional[b]];Oe(C,x[b])}y.propsReady&&Oe(y.propsReady,!0)}function c(y){return s.reduce((x,b)=>(x[b]=C=>{const k=y[t.methods[b]];Oe(k,C)},x),{})}function d(y){return i.reduce((x,b)=>(x[b]=M0(y[t.events[b]]),x),{})}const f=w.forwardRef((y,x)=>{const{children:b,...C}=y,[k]=w.useState(()=>ws(P0(e),E=>{l(E,C)})),[S]=w.useState(Xd(d,k));As(()=>{for(const E of i)E in C&&tt(S[E],C[E]);return()=>{Object.values(S).map(ua)}},[C,S,k]),As(()=>{l(k,C)}),w.useImperativeHandle(x,Gd(c(k)));const T=n;return u.jsx(a.Provider,{value:k,children:n?u.jsx(T,{...gS([...r,...o,...i],C),children:b}):b})}),h=y=>{const x=w.useContext(a);return w.useCallback(b=>{Oe(x[y],b)},[x,y])},p=y=>{const x=w.useContext(a)[y],b=w.useCallback(C=>tt(x,C),[x]);return w.useSyncExternalStore(b,()=>bt(x),()=>bt(x))},v=y=>{const x=w.useContext(a)[y],[b,C]=w.useState(Xd(bt,x));return As(()=>tt(x,k=>{k!==b&&C(Gd(k))}),[x,b]),b},g=w.version.startsWith("18")?p:v;return{Component:f,useEmitter:(y,x)=>{const b=w.useContext(a)[y];As(()=>tt(b,x),[x,b])},useEmitterValue:g,usePublisher:h}}const Af=w.createContext(void 0),jf=w.createContext(void 0),_f=typeof document<"u"?w.useLayoutEffect:w.useEffect;function ka(e){return"self"in e}function xS(e){return"body"in e}function Mf(e,t,n,r=Tr,o,s){const i=w.useRef(null),a=w.useRef(null),l=w.useRef(null),c=w.useCallback(h=>{let p,v,g;const y=h.target;if(xS(y)||ka(y)){const b=ka(y)?y:y.defaultView;g=s?b.scrollX:b.scrollY,p=s?b.document.documentElement.scrollWidth:b.document.documentElement.scrollHeight,v=s?b.innerWidth:b.innerHeight}else g=s?y.scrollLeft:y.scrollTop,p=s?y.scrollWidth:y.scrollHeight,v=s?y.offsetWidth:y.offsetHeight;const x=()=>{e({scrollHeight:p,scrollTop:Math.max(g,0),viewportHeight:v})};h.suppressFlushSync?x():si.flushSync(x),a.current!==null&&(g===a.current||g<=0||g===p-v)&&(a.current=null,t(!0),l.current&&(clearTimeout(l.current),l.current=null))},[e,t,s]);w.useEffect(()=>{const h=o||i.current;return r(o||i.current),c({suppressFlushSync:!0,target:h}),h.addEventListener("scroll",c,{passive:!0}),()=>{r(null),h.removeEventListener("scroll",c)}},[i,c,n,r,o]);function d(h){const p=i.current;if(!p||(s?"offsetWidth"in p&&p.offsetWidth===0:"offsetHeight"in p&&p.offsetHeight===0))return;const v=h.behavior==="smooth";let g,y,x;ka(p)?(y=Math.max(On(p.document.documentElement,s?"width":"height"),s?p.document.documentElement.scrollWidth:p.document.documentElement.scrollHeight),g=s?p.innerWidth:p.innerHeight,x=s?window.scrollX:window.scrollY):(y=p[s?"scrollWidth":"scrollHeight"],g=On(p,s?"width":"height"),x=p[s?"scrollLeft":"scrollTop"]);const b=y-g;if(h.top=Math.ceil(Math.max(Math.min(b,h.top),0)),mf(g,y)||h.top===x){e({scrollHeight:y,scrollTop:x,viewportHeight:g}),v&&t(!0);return}v?(a.current=h.top,l.current&&clearTimeout(l.current),l.current=setTimeout(()=>{l.current=null,a.current=null,t(!0)},1e3)):a.current=null,s&&(h={behavior:h.behavior,left:h.top}),p.scrollTo(h)}function f(h){s&&(h={behavior:h.behavior,left:h.top}),i.current.scrollBy(h)}return{scrollByCallback:f,scrollerRef:i,scrollToCallback:d}}const Ea="-webkit-sticky",Rf="sticky",Ia=Ef(()=>{if(typeof document>"u")return Rf;const e=document.createElement("div");return e.style.position=Ea,e.style.position===Ea?Ea:Rf});function Na(e){return e}const yS=Xe(()=>{const e=se(a=>`Item ${a}`),t=se(a=>`Group ${a}`),n=se({}),r=se(Na),o=se("div"),s=se(Tr),i=(a,l=null)=>Pt(Q(n,de(c=>c[a]),dt()),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")}}),vS=Xe(([e,t])=>({...e,...t}),ut(If,yS)),bS=({height:e})=>u.jsx("div",{style:{height:e}}),wS={overflowAnchor:"none",position:Ia(),zIndex:1},Pf={overflowAnchor:"none"},SS={...Pf,display:"inline-block",height:"100%"},Of=w.memo(function({showTopList:e=!1}){const t=_e("listState"),n=Qt("sizeRanges"),r=_e("useWindowScroll"),o=_e("customScrollParent"),s=Qt("windowScrollContainerState"),i=Qt("scrollContainerState"),a=o||r?s:i,l=_e("itemContent"),c=_e("context"),d=_e("groupContent"),f=_e("trackItemSizes"),h=_e("itemSize"),p=_e("log"),v=Qt("gap"),g=_e("horizontalDirection"),{callbackRef:y}=L0(n,h,f,e?Tr:a,p,v,o,g,_e("skipAnimationFrameInResizeObserver")),[x,b]=w.useState(0);Aa("deviation",P=>{x!==P&&b(P)});const C=_e("EmptyPlaceholder"),k=_e("ScrollSeekPlaceholder")||bS,S=_e("ListComponent"),T=_e("ItemComponent"),E=_e("GroupComponent"),j=_e("computeItemKey"),R=_e("isSeeking"),O=_e("groupIndices").length>0,B=_e("alignToBottom"),q=_e("initialItemFinalLocationReached"),K=e?{}:{boxSizing:"border-box",...g?{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},...q?{}:{visibility:"hidden"}};return!e&&t.totalCount===0&&C?u.jsx(C,{...Ot(C,c)}):u.jsx(S,{...Ot(S,c),"data-testid":e?"virtuoso-top-item-list":"virtuoso-item-list",ref:y,style:K,children:(e?t.topItems:t.items).map(P=>{const M=P.originalIndex,I=j(M+t.firstItemIndex,P.data,c);return R?w.createElement(k,{...Ot(k,c),height:P.size,index:P.index,key:I,type:P.type||"item",...P.type==="group"?{}:{groupIndex:P.groupIndex}}):P.type==="group"?w.createElement(E,{...Ot(E,c),"data-index":M,"data-item-index":P.index,"data-known-size":P.size,key:I,style:wS},d(P.index,c)):w.createElement(T,{...Ot(T,c),...ES(T,P.data),"data-index":M,"data-item-group-index":P.groupIndex,"data-item-index":P.index,"data-known-size":P.size,key:I,style:g?SS:Pf},O?l(P.index,P.groupIndex,P.data,c):l(P.index,P.data,c))})})}),CS={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},TS={outline:"none",overflowX:"auto",position:"relative"},js=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),kS={position:Ia(),top:0,width:"100%",zIndex:1};function Ot(e,t){if(typeof e!="string")return{context:t}}function ES(e,t){return{item:typeof e=="string"?void 0:t}}const IS=w.memo(function(){const e=_e("HeaderComponent"),t=Qt("headerHeight"),n=_e("HeaderFooterTag"),r=Qn(w.useMemo(()=>s=>{t(On(s,"height"))},[t]),!0,_e("skipAnimationFrameInResizeObserver")),o=_e("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...Ot(e,o)})}):null}),NS=w.memo(function(){const e=_e("FooterComponent"),t=Qt("footerHeight"),n=_e("HeaderFooterTag"),r=Qn(w.useMemo(()=>s=>{t(On(s,"height"))},[t]),!0,_e("skipAnimationFrameInResizeObserver")),o=_e("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...Ot(e,o)})}):null});function Df({useEmitter:e,useEmitterValue:t,usePublisher:n}){return w.memo(function({children:r,style:o,context:s,...i}){const a=n("scrollContainerState"),l=t("ScrollerComponent"),c=n("smoothScrollTargetReached"),d=t("scrollerRef"),f=t("horizontalDirection")||!1,{scrollByCallback:h,scrollerRef:p,scrollToCallback:v}=Mf(a,c,l,d,void 0,f);return e("scrollTo",v),e("scrollBy",h),u.jsx(l,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:p,style:{...f?TS:CS,...o},tabIndex:0,...i,...Ot(l,s),children:r})})}function Lf({useEmitter:e,useEmitterValue:t,usePublisher:n}){return w.memo(function({children:r,style:o,context:s,...i}){const a=n("windowScrollContainerState"),l=t("ScrollerComponent"),c=n("smoothScrollTargetReached"),d=t("totalListHeight"),f=t("deviation"),h=t("customScrollParent"),p=w.useRef(null),v=t("scrollerRef"),{scrollByCallback:g,scrollerRef:y,scrollToCallback:x}=Mf(a,c,l,v,h);return _f(()=>{var b;return y.current=h||((b=p.current)==null?void 0:b.ownerDocument.defaultView),()=>{y.current=null}},[y,h]),e("windowScrollTo",x),e("scrollBy",g),u.jsx(l,{ref:p,"data-virtuoso-scroller":!0,style:{position:"relative",...o,...d!==0?{height:d+f}:{}},...i,...Ot(l,s),children:r})})}const AS=({children:e})=>{const t=w.useContext(Af),n=Qt("viewportHeight"),r=Qt("fixedItemHeight"),o=_e("alignToBottom"),s=_e("horizontalDirection"),i=w.useMemo(()=>Yd(n,l=>On(l,s?"width":"height")),[n,s]),a=Qn(i,!0,_e("skipAnimationFrameInResizeObserver"));return w.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),u.jsx("div",{"data-viewport-type":"element",ref:a,style:js(o),children:e})},jS=({children:e})=>{const t=w.useContext(Af),n=Qt("windowViewportRect"),r=Qt("fixedItemHeight"),o=_e("customScrollParent"),s=ef(n,o,_e("skipAnimationFrameInResizeObserver")),i=_e("alignToBottom");return w.useEffect(()=>{t&&(r(t.itemHeight),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:100}))},[t,n,r]),u.jsx("div",{"data-viewport-type":"window",ref:s,style:js(i),children:e})},_S=({children:e})=>{const t=_e("TopItemListComponent")||"div",n=_e("headerHeight"),r={...kS,marginTop:`${n}px`},o=_e("context");return u.jsx(t,{style:r,...Ot(t,o),children:e})},MS=w.memo(function(e){const t=_e("useWindowScroll"),n=_e("topItemsIndexes").length>0,r=_e("customScrollParent"),o=_e("context");return u.jsxs(r||t?OS:PS,{...e,context:o,children:[n&&u.jsx(_S,{children:u.jsx(Of,{showTopList:!0})}),u.jsxs(r||t?jS:AS,{children:[u.jsx(IS,{}),u.jsx(Of,{}),u.jsx(NS,{})]})]})}),{Component:RS,useEmitter:Aa,useEmitterValue:_e,usePublisher:Qt}=Nf(vS,{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"}},MS),PS=Df({useEmitter:Aa,useEmitterValue:_e,usePublisher:Qt}),OS=Lf({useEmitter:Aa,useEmitterValue:_e,usePublisher:Qt}),DS=RS;ut(If,Xe(()=>{const e=se(c=>u.jsxs("td",{children:["Item $",c]})),t=se(null),n=se(c=>u.jsxs("td",{colSpan:1e3,children:["Group ",c]})),r=se(null),o=se(null),s=se({}),i=se(Na),a=se(Tr),l=(c,d=null)=>Pt(Q(s,de(f=>f[c]),dt()),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")}})),Ia();const $f={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},LS={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:Ff,floor:_s,max:ro,min:ja,round:Bf}=Math;function zf(e,t,n){return Array.from({length:t-e+1}).map((r,o)=>({data:n===null?null:n[o+e],index:o+e}))}function $S(e){return{...LS,items:e}}function Ms(e,t){return e&&e.width===t.width&&e.height===t.height}function FS(e,t){return e&&e.column===t.column&&e.row===t.row}const BS=Xe(([{increaseViewportBy:e,listBoundary:t,overscan:n,visibleRange:r},{footerHeight:o,headerHeight:s,scrollBy:i,scrollContainerState:a,scrollTo:l,scrollTop:c,smoothScrollTargetReached:d,viewportHeight:f},h,p,{didMount:v,propsReady:g},{customScrollParent:y,useWindowScroll:x,windowScrollContainerState:b,windowScrollTo:C,windowViewportRect:k},S])=>{const T=se(0),E=se(0),j=se($f),R=se({height:0,width:0}),O=se({height:0,width:0}),B=Ke(),q=Ke(),K=se(0),P=se(null),M=se({column:0,row:0}),I=Ke(),z=Ke(),L=se(!1),A=se(0),$=se(!0),H=se(!1),_=se(!1);tt(Q(v,$e(A),Ne(([D,V])=>!!V)),()=>{Oe($,!1)}),tt(Q(St(v,$,O,R,A,H),Ne(([D,V,U,Z,,J])=>D&&!V&&U.height!==0&&Z.height!==0&&!J)),([,,,,D])=>{Oe(H,!0),ba(1,()=>{Oe(B,D)}),ln(Q(c),()=>{Oe(t,[0,0]),Oe($,!0)})}),xe(Q(z,Ne(D=>D!=null&&D.scrollTop>0),vn(0)),E),tt(Q(v,$e(z),Ne(([,D])=>D!=null)),([,D])=>{D&&(Oe(R,D.viewport),Oe(O,D.item),Oe(M,D.gap),D.scrollTop>0&&(Oe(L,!0),ln(Q(c,Zn(1)),V=>{Oe(L,!1)}),Oe(l,{top:D.scrollTop})))}),xe(Q(R,de(({height:D})=>D)),f),xe(Q(St(Ee(R,Ms),Ee(O,Ms),Ee(M,(D,V)=>D&&D.column===V.column&&D.row===V.row),Ee(c)),de(([D,V,U,Z])=>({gap:U,item:V,scrollTop:Z,viewport:D}))),I),xe(Q(St(Ee(T),r,Ee(M,FS),Ee(O,Ms),Ee(R,Ms),Ee(P),Ee(E),Ee(L),Ee($),Ee(A)),Ne(([,,,,,,,D])=>!D),de(([D,[V,U],Z,J,ge,ce,ne,,pe,be])=>{const{column:De,row:je}=Z,{height:He,width:qe}=J,{width:rt}=ge;if(ne===0&&(D===0||rt===0))return $f;if(qe===0){const mt=wa(be,D),kt=mt+Math.max(ne-1,0);return $S(zf(mt,kt,ce))}const Ge=Uf(rt,qe,De);let Qe,lt;pe?V===0&&U===0&&ne>0?(Qe=0,lt=ne-1):(Qe=Ge*_s((V+je)/(He+je)),lt=Ge*Ff((U+je)/(He+je))-1,lt=ja(D-1,ro(lt,Ge-1)),Qe=ja(lt,ro(0,Qe))):(Qe=0,lt=-1);const Re=zf(Qe,lt,ce),{bottom:Le,top:ct}=Hf(ge,Z,J,Re),ot=Ff(D/Ge),pt=ot*He+(ot-1)*je-Le;return{bottom:Le,itemHeight:He,items:Re,itemWidth:qe,offsetBottom:pt,offsetTop:ct,top:ct}})),j),xe(Q(P,Ne(D=>D!==null),de(D=>D.length)),T),xe(Q(St(R,O,j,M),Ne(([D,V,{items:U}])=>U.length>0&&V.height!==0&&D.height!==0),de(([D,V,{items:U},Z])=>{const{bottom:J,top:ge}=Hf(D,Z,V,U);return[ge,J]}),dt(Xr)),t);const G=se(!1);xe(Q(c,$e(G),de(([D,V])=>V||D!==0)),G);const re=Yt(Q(St(j,T),Ne(([{items:D}])=>D.length>0),$e(G),Ne(([[D,V],U])=>{const Z=D.items[D.items.length-1].index===V-1;return(U||D.bottom>0&&D.itemHeight>0&&D.offsetBottom===0&&D.items.length===V)&&Z}),de(([[,D]])=>D-1),dt())),ee=Yt(Q(Ee(j),Ne(({items:D})=>D.length>0&&D[0].index===0),vn(0),dt())),ie=Yt(Q(Ee(j),$e(L),Ne(([{items:D},V])=>D.length>0&&!V),de(([{items:D}])=>({endIndex:D[D.length-1].index,startIndex:D[0].index})),dt(lf),In(0)));xe(ie,p.scrollSeekRangeChanged),xe(Q(B,$e(R,O,T,M),de(([D,V,U,Z,J])=>{const ge=pf(D),{align:ce,behavior:ne,offset:pe}=ge;let be=ge.index;be==="LAST"&&(be=Z-1),be=ro(0,be,ja(Z-1,be));let De=_a(V,J,U,be);return ce==="end"?De=Bf(De-V.height+U.height):ce==="center"&&(De=Bf(De-V.height/2+U.height/2)),pe&&(De+=pe),{behavior:ne,top:De}})),l);const Y=Pt(Q(j,de(D=>D.offsetBottom+D.bottom)),0);return xe(Q(k,de(D=>({height:D.visibleHeight,width:D.visibleWidth}))),R),{customScrollParent:y,data:P,deviation:K,footerHeight:o,gap:M,headerHeight:s,increaseViewportBy:e,initialItemCount:E,itemDimensions:O,overscan:n,restoreStateFrom:z,scrollBy:i,scrollContainerState:a,scrollHeight:q,scrollTo:l,scrollToIndex:B,scrollTop:c,smoothScrollTargetReached:d,totalCount:T,useWindowScroll:x,viewportDimensions:R,windowScrollContainerState:b,windowScrollTo:C,windowViewportRect:k,...p,gridState:j,horizontalDirection:_,initialTopMostItemIndex:A,totalListHeight:Y,...h,endReached:re,propsReady:g,rangeChanged:ie,startReached:ee,stateChanged:I,stateRestoreInProgress:L,...S}},ut(Sa,Bt,no,kf,Dn,Ta,Pn));function Uf(e,t,n){return ro(1,_s((e+n)/(_s(t)+n)))}function Hf(e,t,n,r){const{height:o}=n;if(o===void 0||r.length===0)return{bottom:0,top:0};const s=_a(e,t,n,r[0].index);return{bottom:_a(e,t,n,r[r.length-1].index)+o,top:s}}function _a(e,t,n,r){const o=Uf(e.width,n.width,t.column),s=_s(r/o),i=s*n.height+ro(0,s-1)*t.row;return i>0?i+t.row:i}const zS=Xe(()=>{const e=se(f=>`Item ${f}`),t=se({}),n=se(null),r=se("virtuoso-grid-item"),o=se("virtuoso-grid-list"),s=se(Na),i=se("div"),a=se(Tr),l=(f,h=null)=>Pt(Q(t,de(p=>p[f]),dt()),h),c=se(!1),d=se(!1);return xe(Ee(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")}}),US=Xe(([e,t])=>({...e,...t}),ut(BS,zS)),HS=w.memo(function(){const e=ht("gridState"),t=ht("listClassName"),n=ht("itemClassName"),r=ht("itemContent"),o=ht("computeItemKey"),s=ht("isSeeking"),i=en("scrollHeight"),a=ht("ItemComponent"),l=ht("ListComponent"),c=ht("ScrollSeekPlaceholder"),d=ht("context"),f=en("itemDimensions"),h=en("gap"),p=ht("log"),v=ht("stateRestoreInProgress"),g=en("reportReadyState"),y=Qn(w.useMemo(()=>x=>{const b=x.parentElement.parentElement.scrollHeight;i(b);const C=x.firstChild;if(C){const{height:k,width:S}=C.getBoundingClientRect();f({height:k,width:S})}h({column:Vf("column-gap",getComputedStyle(x).columnGap,p),row:Vf("row-gap",getComputedStyle(x).rowGap,p)})},[i,f,h,p]),!0,!1);return _f(()=>{e.itemHeight>0&&e.itemWidth>0&&g(!0)},[e]),v?null:u.jsx(l,{className:t,ref:y,...Ot(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,{...Ot(c,d),height:e.itemHeight,index:x.index,width:e.itemWidth},b):w.createElement(a,{...Ot(a,d),className:n,"data-index":x.index,key:b},r(x.index,x.data,d))})})}),WS=w.memo(function(){const e=ht("HeaderComponent"),t=en("headerHeight"),n=ht("headerFooterTag"),r=Qn(w.useMemo(()=>s=>{t(On(s,"height"))},[t]),!0,!1),o=ht("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...Ot(e,o)})}):null}),VS=w.memo(function(){const e=ht("FooterComponent"),t=en("footerHeight"),n=ht("headerFooterTag"),r=Qn(w.useMemo(()=>s=>{t(On(s,"height"))},[t]),!0,!1),o=ht("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...Ot(e,o)})}):null}),KS=({children:e})=>{const t=w.useContext(jf),n=en("itemDimensions"),r=en("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:js(!1),children:e})},qS=({children:e})=>{const t=w.useContext(jf),n=en("windowViewportRect"),r=en("itemDimensions"),o=ht("customScrollParent"),s=ef(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:js(!1),children:e})},GS=w.memo(function({...e}){const t=ht("useWindowScroll"),n=ht("customScrollParent"),r=n||t?XS:YS,o=n||t?qS:KS,s=ht("context");return u.jsx(r,{...e,...Ot(r,s),children:u.jsxs(o,{children:[u.jsx(WS,{}),u.jsx(HS,{}),u.jsx(VS,{})]})})}),{useEmitter:Wf,useEmitterValue:ht,usePublisher:en}=Nf(US,{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"}},GS),YS=Df({useEmitter:Wf,useEmitterValue:ht,usePublisher:en}),XS=Lf({useEmitter:Wf,useEmitterValue:ht,usePublisher:en});function Vf(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Vt.WARN),t==="normal"?0:parseInt(t??"0",10)}const JS=bo.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 Kf({className:e,variant:t,...n}){return u.jsx("div",{className:oe(JS({variant:t}),e),...n})}function Ma(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 qf(e){return!!(e&&typeof e=="object"&&(e.type==="file"||e.mimeType||e.filename||e.sourceType==="base64"))}function oo(e){if(typeof e=="string")return e;if(e&&typeof e=="object"){if(Array.isArray(e)){const n=e.map(oo).filter(r=>r!==void 0);if(!n.length){console.debug("[message-utils] sanitizeForDisplay - array emptied -> returning undefined",{originalLength:e.length});return}return n}if(qf(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=oo(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 so(e){if(typeof e=="string")return e;if(qf(e))return"";try{const t=oo(e);return t===void 0?"":typeof t=="string"?t:JSON.stringify(t,null,2)}catch{return""}}function ZS(e){return typeof e!="string"?!1:/^[\s\n]*[-*]\s|^[\s\n]*#+\s|```|^\s*\[.*\]\(|^>\s/.test(e)}function QS(e){const t=so(e);return typeof e=="string"&&ZS(e)?{content:e,isMarkdown:!0}:{content:t,isMarkdown:!1}}function Rs(e){if(e==null)return e;if(typeof e=="string"){const t=e.trim();if(t.startsWith("{")||t.startsWith("[")){const n=Ma(t);if(n!==null)return Rs(n)}return e}return typeof e=="object"&&!Array.isArray(e)&&e.content!==void 0?Rs(e.content):e}function eC(e){return e.filter(t=>t.type==="text").map(t=>t.text).join("")}function Gf(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 Ps(e){if(e==null)return null;const t=String(e).trim();return t.length>0?t:null}function tC(e){const t=r=>{try{const o=oo(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 nC(e){return e.name&&e.name.trim()?e.name:e.model&&e.model.includes("/")?e.model.split("/").pop()||null:e.model||null}function Yf(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 rC(e){if(!e)return"image/png";const t=e.trim();return t?t.includes("/")?t:`image/${t}`:"image/png"}function oC(e){const t=[],n=r=>{r&&r.trim()&&t.push(r.trim())};return e&&(n(e.plotId),n(e.artifactId)),t}function sC({base64:e,url:t,formatHint:n,extras:r}){const o=typeof e=="string"&&e.length>0,s=rC(n),i=o?`data:${s};base64,${e}`:t,a=oC(r),l=a.length?a.join(" / "):void 0,c=l?`${l} artifact`:"artifact image";return{src:i,alt:c,label:l}}function iC(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 sC({base64:t,url:n,formatHint:r,extras:{plotId:e.plotId,artifactId:e.artifactId}})}async function Xf(e,t){return await Wt(e,{responseType:"blob",onDownloadProgress:r=>{try{t&&r.lengthComputable}catch{}},maxBodyLength:1/0})}async function Jf(e,t){return await(await Xf(`/files/${e}/view`,t)).text()}async function aC(e,t){const n=await Xf(`/files/${e}/download`,t),r=URL.createObjectURL(n);let o=`file_${e}`;try{const i=await Wt(`/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 lC(e,t=50,n=0){const r={limit:t,offset:n};return e&&(r.thread_id=e),await Wt("/files",{params:r})}var Os="Dialog",[Zf,CE]=Tn(Os),[cC,un]=Zf(Os),Qf=e=>{const{__scopeDialog:t,children:n,open:r,defaultOpen:o,onOpenChange:s,modal:i=!0}=e,a=m.useRef(null),l=m.useRef(null),[c,d]=pr({prop:r,defaultProp:o??!1,onChange:s,caller:Os});return u.jsx(cC,{scope:t,triggerRef:a,contentRef:l,contentId:$t(),titleId:$t(),descriptionId:$t(),open:c,onOpenChange:d,onOpenToggle:m.useCallback(()=>d(f=>!f),[d]),modal:i,children:n})};Qf.displayName=Os;var eh="DialogTrigger",th=m.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=un(eh,n),s=Ve(t,o.triggerRef);return u.jsx(Se.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":Oa(o.open),...r,ref:s,onClick:he(e.onClick,o.onOpenToggle)})});th.displayName=eh;var Ra="DialogPortal",[uC,nh]=Zf(Ra,{forceMount:void 0}),rh=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:o}=e,s=un(Ra,t);return u.jsx(uC,{scope:t,forceMount:n,children:m.Children.map(r,i=>u.jsx(Jt,{present:n||s.open,children:u.jsx(ns,{asChild:!0,container:o,children:i})}))})};rh.displayName=Ra;var Ds="DialogOverlay",oh=m.forwardRef((e,t)=>{const n=nh(Ds,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=un(Ds,e.__scopeDialog);return s.modal?u.jsx(Jt,{present:r||s.open,children:u.jsx(fC,{...o,ref:t})}):null});oh.displayName=Ds;var dC=Wn.createSlot("DialogOverlay.RemoveScroll"),fC=m.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=un(Ds,n);return u.jsx(ds,{as:dC,allowPinchZoom:!0,shards:[o.contentRef],children:u.jsx(Se.div,{"data-state":Oa(o.open),...r,ref:t,style:{pointerEvents:"auto",...r.style}})})}),nr="DialogContent",sh=m.forwardRef((e,t)=>{const n=nh(nr,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=un(nr,e.__scopeDialog);return u.jsx(Jt,{present:r||s.open,children:s.modal?u.jsx(hC,{...o,ref:t}):u.jsx(pC,{...o,ref:t})})});sh.displayName=nr;var hC=m.forwardRef((e,t)=>{const n=un(nr,e.__scopeDialog),r=m.useRef(null),o=Ve(t,n.contentRef,r);return m.useEffect(()=>{const s=r.current;if(s)return Gi(s)},[]),u.jsx(ih,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:he(e.onCloseAutoFocus,s=>{var i;s.preventDefault(),(i=n.triggerRef.current)==null||i.focus()}),onPointerDownOutside:he(e.onPointerDownOutside,s=>{const i=s.detail.originalEvent,a=i.button===0&&i.ctrlKey===!0;(i.button===2||a)&&s.preventDefault()}),onFocusOutside:he(e.onFocusOutside,s=>s.preventDefault())})}),pC=m.forwardRef((e,t)=>{const n=un(nr,e.__scopeDialog),r=m.useRef(!1),o=m.useRef(!1);return u.jsx(ih,{...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()}})}),ih=m.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:s,...i}=e,a=un(nr,n),l=m.useRef(null),c=Ve(t,l);return Ai(),u.jsxs(u.Fragment,{children:[u.jsx(Wo,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s,children:u.jsx(Ho,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":Oa(a.open),...i,ref:c,onDismiss:()=>a.onOpenChange(!1)})}),u.jsxs(u.Fragment,{children:[u.jsx(mC,{titleId:a.titleId}),u.jsx(xC,{contentRef:l,descriptionId:a.descriptionId})]})]})}),Pa="DialogTitle",ah=m.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=un(Pa,n);return u.jsx(Se.h2,{id:o.titleId,...r,ref:t})});ah.displayName=Pa;var lh="DialogDescription",ch=m.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=un(lh,n);return u.jsx(Se.p,{id:o.descriptionId,...r,ref:t})});ch.displayName=lh;var uh="DialogClose",dh=m.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=un(uh,n);return u.jsx(Se.button,{type:"button",...r,ref:t,onClick:he(e.onClick,()=>o.onOpenChange(!1))})});dh.displayName=uh;function Oa(e){return e?"open":"closed"}var fh="DialogTitleWarning",[TE,hh]=hy(fh,{contentName:nr,titleName:Pa,docsSlug:"dialog"}),mC=({titleId:e})=>{const t=hh(fh),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 m.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},mC="DialogDescriptionWarning",gC=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${pp(mC).contentName}}.`;return m.useEffect(()=>{var s;const o=(s=e.current)==null?void 0:s.getAttribute("aria-describedby");t&&o&&(document.getElementById(t)||console.warn(r))},[r,e,t]),null},Fa=Qf,xC=tp,Ba=rp,ho=op,mo=sp,sr=ap,Us=cp,hp=dp;const mp=Fa,yC=Ba,gp=m.forwardRef(({className:e,...t},n)=>u.jsx(ho,{ref:n,className:se("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}));gp.displayName=ho.displayName;const za=m.forwardRef(({className:e,children:t,...n},r)=>{const o=m.useMemo(()=>{let s=!1;function i(a){m.Children.forEach(a,l=>{if(s||!m.isValidElement(l))return;const c=l.type;if(c===sr||(c==null?void 0:c.displayName)===sr.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(yC,{children:[u.jsx(gp,{}),u.jsxs(mo,{ref:r,className:se("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(sr,{className:"sr-only",children:"Dialog"}),t,u.jsxs(hp,{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(ue.X,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]})});za.displayName=mo.displayName;const Ua=({className:e,...t})=>u.jsx("div",{className:se("flex flex-col space-y-1.5 text-center sm:text-left",e),...t});Ua.displayName="DialogHeader";const Ha=m.forwardRef(({className:e,...t},n)=>u.jsx(sr,{ref:n,className:se("text-lg font-semibold leading-none tracking-tight",e),...t}));Ha.displayName=sr.displayName;const vC=m.forwardRef(({className:e,...t},n)=>u.jsx(Us,{ref:n,className:se("text-sm text-muted-foreground",e),...t}));vC.displayName=Us.displayName;const bC=1,wC=1e6;let Wa=0;function SC(){return Wa=(Wa+1)%Number.MAX_SAFE_INTEGER,Wa.toString()}const Va=new Map,xp=e=>{if(Va.has(e))return;const t=setTimeout(()=>{Va.delete(e),go({type:"REMOVE_TOAST",toastId:e})},wC);Va.set(e,t)},CC=(e,t)=>{switch(t.type){case"ADD_TOAST":return{...e,toasts:[t.toast,...e.toasts].slice(0,bC)};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?xp(n):e.toasts.forEach(r=>{xp(r.id)}),{...e,toasts:e.toasts.map(r=>r.id===n||n===void 0?{...r,open:!1}:r)}}case"REMOVE_TOAST":return t.toastId===void 0?{...e,toasts:[]}:{...e,toasts:e.toasts.filter(n=>n.id!==t.toastId)}}},Hs=[];let Ws={toasts:[]};function go(e){Ws=CC(Ws,e),Hs.forEach(t=>{t(Ws)})}function TC({...e}){const t=SC(),n=o=>go({type:"UPDATE_TOAST",toast:{...o,id:t}}),r=()=>go({type:"DISMISS_TOAST",toastId:t});return go({type:"ADD_TOAST",toast:{...e,id:t,open:!0,onOpenChange:o=>{o||r()}}}),{id:t,dismiss:r,update:n}}function Ka(){const[e,t]=m.useState(Ws);return m.useEffect(()=>(Hs.push(t),()=>{const n=Hs.indexOf(t);n>-1&&Hs.splice(n,1)}),[e]),{...e,toast:TC,dismiss:n=>go({type:"DISMISS_TOAST",toastId:n})}}function kC({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}=Ka(),p=w.useCallback(async()=>{if(n){i(!0),d(null),l(null);try{const x=await Jf(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 iC(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"})}},v=async()=>{if(n)try{const x=await Jf(n),b=new Blob([x],{type:o}),C=URL.createObjectURL(b);window.open(C,"_blank"),URL.revokeObjectURL(C)}catch(x){console.error("Failed to open file externally:",x),f({title:"Failed to open file",description:String(x),variant:"destructive"})}},g=()=>s?u.jsxs("div",{className:"flex items-center justify-center py-12",children:[u.jsx(ue.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(nt,{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(ue.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(ue.Image,{className:"h-5 w-5"}):u.jsx(ue.FileText,{className:"h-5 w-5"});return u.jsx(mp,{open:e,onOpenChange:t,children:u.jsxs(za,{className:"max-w-4xl max-h-[90vh] overflow-hidden",children:[u.jsx(Ua,{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(Ha,{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(nt,{variant:"outline",size:"sm",onClick:v,className:"flex items-center gap-2",children:[u.jsx(ue.ExternalLink,{className:"h-4 w-4"}),"External"]}),u.jsxs(nt,{variant:"outline",size:"sm",onClick:h,className:"flex items-center gap-2",children:[u.jsx(ue.Download,{className:"h-4 w-4"}),"Download"]})]})]})}),u.jsx("div",{className:"flex-1 overflow-hidden",children:g()})]})})}function yp(){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 ir=yp();function EC(e){ir=e}const vp=/[&<>"']/,IC=new RegExp(vp.source,"g"),bp=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,NC=new RegExp(bp.source,"g"),AC={"&":"&","<":"<",">":">",'"':""","'":"'"},wp=e=>AC[e];function Ot(e,t){if(t){if(vp.test(e))return e.replace(IC,wp)}else if(bp.test(e))return e.replace(NC,wp);return e}const jC=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;function Sp(e){return e.replace(jC,(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 _C=/(^|[^\[])\^/g;function at(e,t){e=typeof e=="string"?e:e.source,t=t||"";const n={replace:(r,o)=>(o=o.source||o,o=o.replace(_C,"$1"),e=e.replace(r,o),n),getRegex:()=>new RegExp(e,t)};return n}const MC=/[^\w:]/g,RC=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function Cp(e,t,n){if(e){let r;try{r=decodeURIComponent(Sp(n)).replace(MC,"").toLowerCase()}catch{return null}if(r.indexOf("javascript:")===0||r.indexOf("vbscript:")===0||r.indexOf("data:")===0)return null}t&&!RC.test(n)&&(n=LC(t,n));try{n=encodeURI(n).replace(/%25/g,"%")}catch{return null}return n}const Vs={},PC=/^[^:]+:\/*[^/]*$/,OC=/^([^:]+:)[\s\S]*$/,DC=/^([^:]+:\/*[^/]*)[\s\S]*$/;function LC(e,t){Vs[" "+e]||(PC.test(e)?Vs[" "+e]=e+"/":Vs[" "+e]=qs(e,"/",!0)),e=Vs[" "+e];const n=e.indexOf(":")===-1;return t.substring(0,2)==="//"?n?t:e.replace(OC,"$1")+t:t.charAt(0)==="/"?n?t:e.replace(DC,"$1")+t:e+t}const Ks={exec:function(){}};function Tp(e,t){const n=e.replace(/\|/g,(s,i,a)=>{let l=!1,c=i;for(;--c>=0&&a[c]==="\\";)l=!l;return l?"|":" |"}),r=n.split(/ \|/);let o=0;if(r[0].trim()||r.shift(),r.length>0&&!r[r.length-1].trim()&&r.pop(),r.length>t)r.splice(t);else for(;r.length<t;)r.push("");for(;o<r.length;o++)r[o]=r[o].trim().replace(/\\\|/g,"|");return r}function qs(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 $C(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 FC(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 kp(e,t){if(t<1)return"";let n="";for(;t>1;)t&1&&(n+=e),t>>=1,e+=e;return n+e}function Ep(e,t,n,r){const o=t.href,s=t.title?Ot(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:Ot(i)}}function BC(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 m.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},gC="DialogDescriptionWarning",xC=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${hh(gC).contentName}}.`;return m.useEffect(()=>{var s;const o=(s=e.current)==null?void 0:s.getAttribute("aria-describedby");t&&o&&(document.getElementById(t)||console.warn(r))},[r,e,t]),null},Da=Qf,yC=th,La=rh,io=oh,ao=sh,rr=ah,Ls=ch,ph=dh;const mh=Da,vC=La,gh=m.forwardRef(({className:e,...t},n)=>u.jsx(io,{ref:n,className:oe("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}));gh.displayName=io.displayName;const $a=m.forwardRef(({className:e,children:t,...n},r)=>{const o=m.useMemo(()=>{let s=!1;function i(a){m.Children.forEach(a,l=>{if(s||!m.isValidElement(l))return;const 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(vC,{children:[u.jsx(gh,{}),u.jsxs(ao,{ref:r,className:oe("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(ph,{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(ae.X,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]})});$a.displayName=ao.displayName;const Fa=({className:e,...t})=>u.jsx("div",{className:oe("flex flex-col space-y-1.5 text-center sm:text-left",e),...t});Fa.displayName="DialogHeader";const Ba=m.forwardRef(({className:e,...t},n)=>u.jsx(rr,{ref:n,className:oe("text-lg font-semibold leading-none tracking-tight",e),...t}));Ba.displayName=rr.displayName;const bC=m.forwardRef(({className:e,...t},n)=>u.jsx(Ls,{ref:n,className:oe("text-sm text-muted-foreground",e),...t}));bC.displayName=Ls.displayName;const wC=1,SC=1e6;let za=0;function CC(){return za=(za+1)%Number.MAX_SAFE_INTEGER,za.toString()}const Ua=new Map,xh=e=>{if(Ua.has(e))return;const t=setTimeout(()=>{Ua.delete(e),lo({type:"REMOVE_TOAST",toastId:e})},SC);Ua.set(e,t)},TC=(e,t)=>{switch(t.type){case"ADD_TOAST":return{...e,toasts:[t.toast,...e.toasts].slice(0,wC)};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?xh(n):e.toasts.forEach(r=>{xh(r.id)}),{...e,toasts:e.toasts.map(r=>r.id===n||n===void 0?{...r,open:!1}:r)}}case"REMOVE_TOAST":return t.toastId===void 0?{...e,toasts:[]}:{...e,toasts:e.toasts.filter(n=>n.id!==t.toastId)}}},$s=[];let Fs={toasts:[]};function lo(e){Fs=TC(Fs,e),$s.forEach(t=>{t(Fs)})}function kC({...e}){const t=CC(),n=o=>lo({type:"UPDATE_TOAST",toast:{...o,id:t}}),r=()=>lo({type:"DISMISS_TOAST",toastId:t});return lo({type:"ADD_TOAST",toast:{...e,id:t,open:!0,onOpenChange:o=>{o||r()}}}),{id:t,dismiss:r,update:n}}function Ha(){const[e,t]=m.useState(Fs);return m.useEffect(()=>($s.push(t),()=>{const n=$s.indexOf(t);n>-1&&$s.splice(n,1)}),[e]),{...e,toast:kC,dismiss:n=>lo({type:"DISMISS_TOAST",toastId:n})}}function EC({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}=Ha(),h=w.useCallback(async()=>{if(n){i(!0),d(null),l(null);try{const x=await Jf(n);l(x)}catch(x){console.error("Failed to load file:",x),d(x instanceof Error?x.message:"Failed to load file")}finally{i(!1)}}},[n]);w.useEffect(()=>{e&&n&&h()},[e,n,h]);const p=async()=>{if(n)try{await aC(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"})}},v=async()=>{if(n)try{const x=await Jf(n),b=new Blob([x],{type:o}),C=URL.createObjectURL(b);window.open(C,"_blank"),URL.revokeObjectURL(C)}catch(x){console.error("Failed to open file externally:",x),f({title:"Failed to open file",description:String(x),variant:"destructive"})}},g=()=>s?u.jsxs("div",{className:"flex items-center justify-center py-12",children:[u.jsx(ae.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(et,{onClick:h,variant:"outline",children:"Try Again"})]}):a?o.startsWith("image/")?u.jsx("div",{className:"flex justify-center",children:u.jsx("img",{src:`data:${o};base64,${a}`,alt:r,className:"max-w-full max-h-[70vh] object-contain rounded-lg"})}):o==="application/pdf"?u.jsx("div",{className:"w-full h-[70vh] border rounded-lg overflow-hidden",children:u.jsx("iframe",{src:`data:application/pdf;base64,${a}`,className:"w-full h-full",title:r})}):o.startsWith("text/")||o.includes("json")||o.includes("xml")?u.jsx("div",{className:"bg-gray-50 dark:bg-gray-900 rounded-lg p-4 max-h-[70vh] overflow-auto",children:u.jsx("pre",{className:"whitespace-pre-wrap font-mono text-sm",children:a})}):u.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[u.jsx(ae.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(ae.Image,{className:"h-5 w-5"}):u.jsx(ae.FileText,{className:"h-5 w-5"});return u.jsx(mh,{open:e,onOpenChange:t,children:u.jsxs($a,{className:"max-w-4xl max-h-[90vh] overflow-hidden",children:[u.jsx(Fa,{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(Ba,{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(et,{variant:"outline",size:"sm",onClick:v,className:"flex items-center gap-2",children:[u.jsx(ae.ExternalLink,{className:"h-4 w-4"}),"External"]}),u.jsxs(et,{variant:"outline",size:"sm",onClick:p,className:"flex items-center gap-2",children:[u.jsx(ae.Download,{className:"h-4 w-4"}),"Download"]})]})]})}),u.jsx("div",{className:"flex-1 overflow-hidden",children:g()})]})})}function yh(){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=yh();function IC(e){or=e}const vh=/[&<>"']/,NC=new RegExp(vh.source,"g"),bh=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,AC=new RegExp(bh.source,"g"),jC={"&":"&","<":"<",">":">",'"':""","'":"'"},wh=e=>jC[e];function Dt(e,t){if(t){if(vh.test(e))return e.replace(NC,wh)}else if(bh.test(e))return e.replace(AC,wh);return e}const _C=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;function Sh(e){return e.replace(_C,(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 MC=/(^|[^\[])\^/g;function at(e,t){e=typeof e=="string"?e:e.source,t=t||"";const n={replace:(r,o)=>(o=o.source||o,o=o.replace(MC,"$1"),e=e.replace(r,o),n),getRegex:()=>new RegExp(e,t)};return n}const RC=/[^\w:]/g,PC=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function Ch(e,t,n){if(e){let r;try{r=decodeURIComponent(Sh(n)).replace(RC,"").toLowerCase()}catch{return null}if(r.indexOf("javascript:")===0||r.indexOf("vbscript:")===0||r.indexOf("data:")===0)return null}t&&!PC.test(n)&&(n=$C(t,n));try{n=encodeURI(n).replace(/%25/g,"%")}catch{return null}return n}const Bs={},OC=/^[^:]+:\/*[^/]*$/,DC=/^([^:]+:)[\s\S]*$/,LC=/^([^:]+:\/*[^/]*)[\s\S]*$/;function $C(e,t){Bs[" "+e]||(OC.test(e)?Bs[" "+e]=e+"/":Bs[" "+e]=Us(e,"/",!0)),e=Bs[" "+e];const n=e.indexOf(":")===-1;return t.substring(0,2)==="//"?n?t:e.replace(DC,"$1")+t:t.charAt(0)==="/"?n?t:e.replace(LC,"$1")+t:e+t}const zs={exec:function(){}};function Th(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 Us(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 FC(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 BC(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 kh(e,t){if(t<1)return"";let n="";for(;t>1;)t&1&&(n+=e),t>>=1,e+=e;return n+e}function Eh(e,t,n,r){const o=t.href,s=t.title?Dt(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:Dt(i)}}function zC(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 Wa{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:Us(r,`
|
|
94
|
+
`)}}}fences(t){const n=this.rules.block.fences.exec(t);if(n){const r=n[0],o=zC(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=Us(r,"#");(this.options.pedantic||!o||/ $/.test(o))&&(r=o.trim())}return{type:"heading",raw:n[0],depth:n[1].length,text:r,tokens:this.lexer.inline(r)}}}hr(t){const n=this.rules.block.hr.exec(t);if(n)return{type:"hr",raw:n[0]}}blockquote(t){const n=this.rules.block.blockquote.exec(t);if(n){const r=n[0].replace(/^ *>[ \t]?/gm,""),o=this.lexer.state.top;this.lexer.state.top=!0;const s=this.lexer.blockTokens(r);return this.lexer.state.top=o,{type:"blockquote",raw:n[0],tokens:s,text:r}}}list(t){let n=this.rules.block.list.exec(t);if(n){let r,o,s,i,a,l,c,d,f,h,p,v,g=n[1].trim();const y=g.length>1,x={type:"list",raw:"",ordered:y,start:y?+g.slice(0,-1):"",loose:!1,items:[]};g=y?`\\d{1,9}\\${g.slice(-1)}`:`\\${g}`,this.options.pedantic&&(g=y?g:"[*+-]");const b=new RegExp(`^( {0,3}${g})((?:[ ][^\\n]*)?(?:\\n|$))`);for(;t&&(v=!1,!(!(n=b.exec(t))||this.rules.block.hr.test(t)));){if(r=n[0],t=t.substring(r.length),d=n[2].split(`
|
|
95
95
|
`,1)[0].replace(/^\t+/,k=>" ".repeat(3*k.length)),f=t.split(`
|
|
96
|
-
`,1)[0],this.options.pedantic?(i=2,
|
|
97
|
-
`,t=t.substring(f.length+1),v=!0),!v){const k=new RegExp(`^ {0,${Math.min(3,i-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),
|
|
98
|
-
`,1)[0],f=
|
|
99
|
-
`+f.slice(i);else{if(l||d.search(/[^ ]/)>=4||
|
|
100
|
-
`+f}!l&&!f.trim()&&(l=!0),r+=
|
|
101
|
-
`,t=t.substring(
|
|
102
|
-
`):[]};if(r.header.length===r.align.length){r.raw=n[0];let o=r.align.length,s,i,a,l;for(s=0;s<o;s++)/^ *-+: *$/.test(r.align[s])?r.align[s]="right":/^ *:-+: *$/.test(r.align[s])?r.align[s]="center":/^ *:-+ *$/.test(r.align[s])?r.align[s]="left":r.align[s]=null;for(o=r.rows.length,s=0;s<o;s++)r.rows[s]=
|
|
103
|
-
`?n[1].slice(0,-1):n[1];return{type:"paragraph",raw:n[0],text:r,tokens:this.lexer.inline(r)}}}text(t){const n=this.rules.block.text.exec(t);if(n)return{type:"text",raw:n[0],text:n[0],tokens:this.lexer.inline(n[0])}}escape(t){const n=this.rules.inline.escape.exec(t);if(n)return{type:"escape",raw:n[0],text:
|
|
104
|
-
]`).replace("lheading",
|
|
96
|
+
`,1)[0],this.options.pedantic?(i=2,p=d.trimLeft()):(i=n[2].search(/[^ ]/),i=i>4?1:i,p=d.slice(i),i+=n[1].length),l=!1,!d&&/^ *$/.test(f)&&(r+=f+`
|
|
97
|
+
`,t=t.substring(f.length+1),v=!0),!v){const k=new RegExp(`^ {0,${Math.min(3,i-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),S=new RegExp(`^ {0,${Math.min(3,i-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),T=new RegExp(`^ {0,${Math.min(3,i-1)}}(?:\`\`\`|~~~)`),E=new RegExp(`^ {0,${Math.min(3,i-1)}}#`);for(;t&&(h=t.split(`
|
|
98
|
+
`,1)[0],f=h,this.options.pedantic&&(f=f.replace(/^ {1,4}(?=( {4})*[^ ])/g," ")),!(T.test(f)||E.test(f)||k.test(f)||S.test(t)));){if(f.search(/[^ ]/)>=i||!f.trim())p+=`
|
|
99
|
+
`+f.slice(i);else{if(l||d.search(/[^ ]/)>=4||T.test(d)||E.test(d)||S.test(d))break;p+=`
|
|
100
|
+
`+f}!l&&!f.trim()&&(l=!0),r+=h+`
|
|
101
|
+
`,t=t.substring(h.length+1),d=f.slice(i)}}x.loose||(c?x.loose=!0:/\n *\n *$/.test(r)&&(c=!0)),this.options.gfm&&(o=/^\[[ xX]\] /.exec(p),o&&(s=o[0]!=="[ ] ",p=p.replace(/^\[[ xX]\] +/,""))),x.items.push({type:"list_item",raw:r,task:!!o,checked:s,loose:!1,text:p}),x.raw+=r}x.items[x.items.length-1].raw=r.trimRight(),x.items[x.items.length-1].text=p.trimRight(),x.raw=x.raw.trimRight();const C=x.items.length;for(a=0;a<C;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"),S=k.length>0&&k.some(T=>/\n.*\n/.test(T.raw));x.loose=S}if(x.loose)for(a=0;a<C;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]):Dt(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:Th(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]=Th(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:Dt(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]):Dt(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=Us(r.slice(0,-1),"\\");if((r.length-i.length)%2===0)return}else{const i=FC(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)),Eh(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 Eh(r,o,r[0],this.lexer)}}emStrong(t,n,r=""){let o=this.rules.inline.emStrong.lDelim.exec(t);if(!o||o[3]&&r.match(/[\p{L}\p{N}]/u))return;const s=o[1]||o[2]||"";if(!s||s&&(r===""||this.rules.inline.punctuation.exec(r))){const i=o[0].length-1;let a,l,c=i,d=0;const f=o[0][0]==="*"?this.rules.inline.emStrong.rDelimAst:this.rules.inline.emStrong.rDelimUnd;for(f.lastIndex=0,n=n.slice(-1*t.length+i);(o=f.exec(n))!=null;){if(a=o[1]||o[2]||o[3]||o[4]||o[5]||o[6],!a)continue;if(l=a.length,o[3]||o[4]){c+=l;continue}else if((o[5]||o[6])&&i%3&&!((i+l)%3)){d+=l;continue}if(c-=l,c>0)continue;l=Math.min(l,l+c+d);const h=t.slice(0,i+o.index+(o[0].length-a.length)+l);if(Math.min(i,l)%2){const v=h.slice(1,-1);return{type:"em",raw:h,text:v,tokens:this.lexer.inlineTokens(v)}}const p=h.slice(2,-2);return{type:"strong",raw:h,text:p,tokens:this.lexer.inlineTokens(p)}}}}codespan(t){const n=this.rules.inline.code.exec(t);if(n){let r=n[2].replace(/\n/g," ");const o=/[^ ]/.test(r),s=/^ /.test(r)&&/ $/.test(r);return o&&s&&(r=r.substring(1,r.length-1)),r=Dt(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=Dt(this.options.mangle?n(r[1]):r[1]),s="mailto:"+o):(o=Dt(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=Dt(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=Dt(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]):Dt(r[0]):r[0]:o=Dt(this.options.smartypants?n(r[0]):r[0]),{type:"text",raw:r[0],text:o}}}}const we={newline:/^(?: *(?:\n|$))+/,code:/^( {4}[^\n]+(?:\n(?: *(?:\n|$))*)?)+/,fences:/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,hr:/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,heading:/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,blockquote:/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/,list:/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/,html:"^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n *)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$))",def:/^ {0,3}\[(label)\]: *(?:\n *)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n *)?| *\n *)(title))? *(?:\n+|$)/,table:zs,lheading:/^((?:.|\n(?!\n))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,_paragraph:/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,text:/^[^\n]+/};we._label=/(?!\s*\])(?:\\.|[^\[\]\\])+/,we._title=/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/,we.def=at(we.def).replace("label",we._label).replace("title",we._title).getRegex(),we.bullet=/(?:[*+-]|\d{1,9}[.)])/,we.listItemStart=at(/^( *)(bull) */).replace("bull",we.bullet).getRegex(),we.list=at(we.list).replace(/bull/g,we.bullet).replace("hr","\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))").replace("def","\\n+(?="+we.def.source+")").getRegex(),we._tag="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",we._comment=/<!--(?!-?>)[\s\S]*?(?:-->|$)/,we.html=at(we.html,"i").replace("comment",we._comment).replace("tag",we._tag).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),we.paragraph=at(we._paragraph).replace("hr",we.hr).replace("heading"," {0,3}#{1,6} ").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",we._tag).getRegex(),we.blockquote=at(we.blockquote).replace("paragraph",we.paragraph).getRegex(),we.normal={...we},we.gfm={...we.normal,table:"^ *([^\\n ].*\\|.*)\\n {0,3}(?:\\| *)?(:?-+:? *(?:\\| *:?-+:? *)*)(?:\\| *)?(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)"},we.gfm.table=at(we.gfm.table).replace("hr",we.hr).replace("heading"," {0,3}#{1,6} ").replace("blockquote"," {0,3}>").replace("code"," {4}[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",we._tag).getRegex(),we.gfm.paragraph=at(we._paragraph).replace("hr",we.hr).replace("heading"," {0,3}#{1,6} ").replace("|lheading","").replace("table",we.gfm.table).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",we._tag).getRegex(),we.pedantic={...we.normal,html:at(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",we._comment).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:zs,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:at(we.normal._paragraph).replace("hr",we.hr).replace("heading",` *#{1,6} *[^
|
|
104
|
+
]`).replace("lheading",we.lheading).replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").getRegex()};const fe={escape:/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,autolink:/^<(scheme:[^\s\x00-\x1f<>]*|email)>/,url:zs,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:zs,text:/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,punctuation:/^([\spunctuation])/};fe._punctuation="!\"#$%&'()+\\-.,/:;<=>?@\\[\\]`^{|}~",fe.punctuation=at(fe.punctuation).replace(/punctuation/g,fe._punctuation).getRegex(),fe.blockSkip=/\[[^\]]*?\]\([^\)]*?\)|`[^`]*?`|<[^>]*?>/g,fe.escapedEmSt=/(?:^|[^\\])(?:\\\\)*\\[*_]/g,fe._comment=at(we._comment).replace("(?:-->|$)","-->").getRegex(),fe.emStrong.lDelim=at(fe.emStrong.lDelim).replace(/punct/g,fe._punctuation).getRegex(),fe.emStrong.rDelimAst=at(fe.emStrong.rDelimAst,"g").replace(/punct/g,fe._punctuation).getRegex(),fe.emStrong.rDelimUnd=at(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=at(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=at(fe.tag).replace("comment",fe._comment).replace("attribute",fe._attribute).getRegex(),fe._label=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,fe._href=/<(?:\\.|[^\n<>\\])+>|[^\s\x00-\x1f]*/,fe._title=/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/,fe.link=at(fe.link).replace("label",fe._label).replace("href",fe._href).replace("title",fe._title).getRegex(),fe.reflink=at(fe.reflink).replace("label",fe._label).replace("ref",we._label).getRegex(),fe.nolink=at(fe.nolink).replace("ref",we._label).getRegex(),fe.reflinkSearch=at(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:at(/^!?\[(label)\]\((.*?)\)/).replace("label",fe._label).getRegex(),reflink:at(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",fe._label).getRegex()},fe.gfm={...fe.normal,escape:at(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=at(fe.gfm.url,"i").replace("email",fe.gfm._extended_email).getRegex(),fe.breaks={...fe.gfm,br:at(fe.br).replace("{2,}","*").getRegex(),text:at(fe.gfm.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()};function UC(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 Ih(e){let t="",n,r;const o=e.length;for(n=0;n<o;n++)r=e.charCodeAt(n),Math.random()>.5&&(r="x"+r.toString(16)),t+="&#"+r+";";return t}class Ln{constructor(t){this.tokens=[],this.tokens.links=Object.create(null),this.options=t||or,this.options.tokenizer=this.options.tokenizer||new Wa,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};const n={block:we.normal,inline:fe.normal};this.options.pedantic?(n.block=we.pedantic,n.inline=fe.pedantic):this.options.gfm&&(n.block=we.gfm,this.options.breaks?n.inline=fe.breaks:n.inline=fe.gfm),this.tokenizer.rules=n}static get rules(){return{block:we,inline:fe}}static lex(t,n){return new Ln(n).lex(t)}static lexInline(t,n){return new Ln(n).inlineTokens(t)}lex(t){t=t.replace(/\r\n|\r/g,`
|
|
105
105
|
`),this.blockTokens(t,this.tokens);let n;for(;n=this.inlineQueue.shift();)this.inlineTokens(n.src,n.tokens);return this.tokens}blockTokens(t,n=[]){this.options.pedantic?t=t.replace(/\t/g," ").replace(/^ +$/gm,""):t=t.replace(/^( *)(\t+)/gm,(a,l,c)=>l+" ".repeat(c.length));let r,o,s,i;for(;t;)if(!(this.options.extensions&&this.options.extensions.block&&this.options.extensions.block.some(a=>(r=a.call({lexer:this},t,n))?(t=t.substring(r.raw.length),n.push(r),!0):!1))){if(r=this.tokenizer.space(t)){t=t.substring(r.raw.length),r.raw.length===1&&n.length>0?n[n.length-1].raw+=`
|
|
106
106
|
`:n.push(r);continue}if(r=this.tokenizer.code(t)){t=t.substring(r.raw.length),o=n[n.length-1],o&&(o.type==="paragraph"||o.type==="text")?(o.raw+=`
|
|
107
107
|
`+r.raw,o.text+=`
|
|
@@ -111,9 +111,9 @@ For more information, see https://radix-ui.com/primitives/docs/components/${t.do
|
|
|
111
111
|
`+r.raw,o.text+=`
|
|
112
112
|
`+r.text,this.inlineQueue.pop(),this.inlineQueue[this.inlineQueue.length-1].src=o.text):n.push(r),i=s.length!==t.length,t=t.substring(r.raw.length);continue}if(r=this.tokenizer.text(t)){t=t.substring(r.raw.length),o=n[n.length-1],o&&o.type==="text"?(o.raw+=`
|
|
113
113
|
`+r.raw,o.text+=`
|
|
114
|
-
`+r.text,this.inlineQueue.pop(),this.inlineQueue[this.inlineQueue.length-1].src=o.text):n.push(r);continue}if(t){const a="Infinite loop on byte: "+t.charCodeAt(0);if(this.options.silent){console.error(a);break}else throw new Error(a)}}return this.state.top=!0,n}inline(t,n=[]){return this.inlineQueue.push({src:t,tokens:n}),n}inlineTokens(t,n=[]){let r,o,s,i=t,a,l,c;if(this.tokens.links){const d=Object.keys(this.tokens.links);if(d.length>0)for(;(a=this.tokenizer.rules.inline.reflinkSearch.exec(i))!=null;)d.includes(a[0].slice(a[0].lastIndexOf("[")+1,-1))&&(i=i.slice(0,a.index)+"["+
|
|
115
|
-
`,o?'<pre><code class="'+this.options.langPrefix+
|
|
116
|
-
`:"<pre><code>"+(r?t:
|
|
114
|
+
`+r.text,this.inlineQueue.pop(),this.inlineQueue[this.inlineQueue.length-1].src=o.text):n.push(r);continue}if(t){const a="Infinite loop on byte: "+t.charCodeAt(0);if(this.options.silent){console.error(a);break}else throw new Error(a)}}return this.state.top=!0,n}inline(t,n=[]){return this.inlineQueue.push({src:t,tokens:n}),n}inlineTokens(t,n=[]){let r,o,s,i=t,a,l,c;if(this.tokens.links){const d=Object.keys(this.tokens.links);if(d.length>0)for(;(a=this.tokenizer.rules.inline.reflinkSearch.exec(i))!=null;)d.includes(a[0].slice(a[0].lastIndexOf("[")+1,-1))&&(i=i.slice(0,a.index)+"["+kh("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)+"["+kh("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,Ih)){t=t.substring(r.raw.length),n.push(r);continue}if(!this.state.inLink&&(r=this.tokenizer.url(t,Ih))){t=t.substring(r.raw.length),n.push(r);continue}if(s=t,this.options.extensions&&this.options.extensions.startInline){let d=1/0;const f=t.slice(1);let h;this.options.extensions.startInline.forEach(function(p){h=p.call({lexer:this},f),typeof h=="number"&&h>=0&&(d=Math.min(d,h))}),d<1/0&&d>=0&&(s=t.substring(0,d+1))}if(r=this.tokenizer.inlineText(s,UC)){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 Va{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
|
+
`,o?'<pre><code class="'+this.options.langPrefix+Dt(o)+'">'+(r?t:Dt(t,!0))+`</code></pre>
|
|
116
|
+
`:"<pre><code>"+(r?t:Dt(t,!0))+`</code></pre>
|
|
117
117
|
`}blockquote(t){return`<blockquote>
|
|
118
118
|
${t}</blockquote>
|
|
119
119
|
`}html(t){return t}heading(t,n,r,o){if(this.options.headerIds){const s=this.options.headerPrefix+o.slug(r);return`<h${n} id="${s}">${t}</h${n}>
|
|
@@ -131,7 +131,7 @@ ${t}</blockquote>
|
|
|
131
131
|
`}tablerow(t){return`<tr>
|
|
132
132
|
${t}</tr>
|
|
133
133
|
`}tablecell(t,n){const r=n.header?"th":"td";return(n.align?`<${r} align="${n.align}">`:`<${r}>`)+t+`</${r}>
|
|
134
|
-
`}strong(t){return`<strong>${t}</strong>`}em(t){return`<em>${t}</em>`}codespan(t){return`<code>${t}</code>`}br(){return this.options.xhtml?"<br/>":"<br>"}del(t){return`<del>${t}</del>`}link(t,n,r){if(t=
|
|
135
|
-
`+(
|
|
136
|
-
Please report this to https://github.com/markedjs/marked.`,e){const o="<p>An error occurred:</p><pre>"+Ot(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 jp(e,t){return(n,r,o)=>{typeof r=="function"&&(o=r,r=null);const s={...r};r={...we.defaults,...s};const i=UC(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(FC(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&&we.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;we.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(we.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&&we.walkTokens(a,r.walkTokens);let l=t(a,r);return r.hooks&&(l=r.hooks.postprocess(l)),l}catch(a){return i(a)}}}function we(e,t,n){return jp(Fn.lex,Bn.parse)(e,t,n)}we.options=we.setOptions=function(e){return we.defaults={...we.defaults,...e},EC(we.defaults),we},we.getDefaults=yp,we.defaults=ir,we.use=function(...e){const t=we.defaults.extensions||{renderers:{},childTokens:{}};e.forEach(n=>{const r={...n};if(r.async=we.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=we.defaults.renderer||new Ga;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=we.defaults.tokenizer||new qa;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=we.defaults.hooks||new Gs;for(const s in n.hooks){const i=o[s];Gs.passThroughHooks.has(s)?o[s]=a=>{if(we.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=we.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}}we.setOptions(r)})},we.walkTokens=function(e,t){let n=[];for(const r of e)switch(n=n.concat(t.call(we,r)),r.type){case"table":{for(const o of r.header)n=n.concat(we.walkTokens(o.tokens,t));for(const o of r.rows)for(const s of o)n=n.concat(we.walkTokens(s.tokens,t));break}case"list":{n=n.concat(we.walkTokens(r.items,t));break}default:we.defaults.extensions&&we.defaults.extensions.childTokens&&we.defaults.extensions.childTokens[r.type]?we.defaults.extensions.childTokens[r.type].forEach(function(o){n=n.concat(we.walkTokens(r[o],t))}):r.tokens&&(n=n.concat(we.walkTokens(r.tokens,t)))}return n},we.parseInline=jp(Fn.lexInline,Bn.parseInline),we.Parser=Bn,we.parser=Bn.parse,we.Renderer=Ga,we.TextRenderer=Np,we.Lexer=Fn,we.lexer=Fn.lex,we.Tokenizer=qa,we.Slugger=Ap,we.Hooks=Gs,we.parse=we,we.options,we.setOptions,we.use,we.walkTokens,we.parseInline,Bn.parse,Fn.lex;function xo({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 we.parse=="function"?we.parse(i):we(i)}return typeof we.parse=="function"?we.parse(e):we(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:se("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 HC={MODE:"library"};function WC(){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:ci&&ci.tagName.toUpperCase()==="SCRIPT"&&ci.src||new URL("index.umd.js",document.baseURI).href}<"u"?HC: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 VC(){return!WC()}function KC(){return typeof window>"u"?!1:window.__ARTIFACT_DEBUG__===!0}function qC(){return VC()||KC()}function GC({preview:e,idx:t}){return w.useEffect(()=>{qC()&&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 yo=m.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:se("rounded-lg border bg-card text-card-foreground shadow-sm",e),...t}));yo.displayName="Card";const vo=m.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:se("flex flex-col space-y-1.5 p-6",e),...t}));vo.displayName="CardHeader";const bo=m.forwardRef(({className:e,...t},n)=>u.jsx("h3",{ref:n,className:se("text-2xl font-semibold leading-none tracking-tight",e),...t}));bo.displayName="CardTitle";const _p=m.forwardRef(({className:e,...t},n)=>u.jsx("p",{ref:n,className:se("text-sm text-muted-foreground",e),...t}));_p.displayName="CardDescription";const wo=m.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:se("p-6 pt-0",e),...t}));wo.displayName="CardContent";const Mp=m.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:se("flex items-center p-6 pt-0",e),...t}));Mp.displayName="CardFooter";function YC({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=po(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(yo,{className:se("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(vo,{className:"pb-3",children:[u.jsx(bo,{className:"text-blue-900 dark:text-blue-100 text-base",children:i}),u.jsx(_p,{className:"text-blue-700 dark:text-blue-300 text-sm",children:l})]}),a&&u.jsx(wo,{className:"pt-0 pb-3",children:a}),u.jsx(Mp,{className:"pt-0",children:u.jsxs("div",{className:"flex gap-2 ml-auto",children:[u.jsx(nt,{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(nt,{size:"sm",onClick:()=>t(e),className:"bg-blue-600 hover:bg-blue-700 text-white",disabled:r||!o,children:"Approve"})]})})]})}const XC="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 Rp({data:e}){return Array.isArray(e)?e.every(n=>n===null||["string","number","boolean"].includes(typeof n))?u.jsx("div",{className:XC,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:po(e)}):u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:po(e)})}function JC({message:e,isStreaming:t=!1}){const n=e.name??"tool",r=w.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(ue.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 ZC({message:e,viewMode:t,isStreaming:n=!1}){const o=Gf(e).name||"tool",s=l=>{if(l==null)return null;const c=typeof l=="string"?Oa(l)??l:l;if(c&&typeof c=="object")return u.jsx(Rp,{data:c});const d=typeof c=="string"?c:(()=>{try{return po(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}=ZS(l);return d?u.jsx(xo,{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=$s(p);return i(h)}const c=fo(l),d=$s(c);return i(d)};return u.jsxs("div",{className:"space-y-2",children:[u.jsx(JC,{message:e,isStreaming:n}),t==="expanded"&&a()]})}function QC(e){const{allowFileOpen:t,currentThreadId:n}=e,{toast:r}=Ka(),[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,v,g)=>{var y,x;if(!t){h.preventDefault();return}if(o[g]){h.preventDefault();return}try{const b=String(v.url??""),C=b.match(/\/chat\/files\/([^/]+)(?:\/(view|download))?/);if(C){h.preventDefault();const k=C[1],T=v.name||`file_${k}`,S=v.mimeType||"application/octet-stream";f({id:k,name:T,mimeType:S});return}if(b.startsWith("data:")){h.preventDefault(),s(T=>({...T,[g]:!0}));const k=r({title:"Fetching file...",description:"",open:!0});try{const T=await aC(n??void 0);if(!T||!Array.isArray(T))throw new Error("Invalid file list response");const S=T.find(E=>!E||typeof E!="object"||!((E.filename??"")===(v.name??""))?!1:typeof v.size=="number"&&typeof E.size=="number"?E.size===v.size:!0);if(!(S!=null&&S.id))throw new Error(`File "${v.name}" is not yet available on the server`);if(!S.id||!S.filename)throw new Error("Invalid file data received from server");f({id:S.id,name:v.name||S.filename||`file_${S.id}`,mimeType:v.mimeType||S.mime_type||"application/octet-stream"}),(y=k.update)==null||y.call(k,{id:k.id,title:"Success",description:`Opened ${v.name}`,open:!0})}catch(T){console.error("Failed to fetch server file:",T);const S=T instanceof Error?T.message:"Unknown error occurred";(x=k.update)==null||x.call(k,{id:k.id,title:"Failed",description:S}),r({title:"Failed to fetch file",description:S,open:!0})}finally{s(T=>({...T,[g]:!1}))}}}catch(b){console.error("File click error:",b),s(C=>({...C,[g]:!1}))}},[t,o,r,n,f]);return{uploadingFiles:o,handleFileClick:p,fileViewerOpen:l,currentFileInfo:i,closeFileViewer:d}}function eT({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:se("text-sm text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:t?u.jsx(xo,{content:e,allowHtml:!1}):u.jsxs("pre",{className:se("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(nt,{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(ue.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):u.jsxs(u.Fragment,{children:[u.jsx(ue.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more (",s," chars)"]})})]})}function tT({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:se("inline-block text-xs opacity-70 ml-1",e),children:["Is thinking",".".repeat(t)]})}function Pp(e){var n;const t=(n=e.additionalKwargs)==null?void 0:n.toolProgress;return Array.isArray(t)?t:[]}const Ys=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:v,onRegenerate:g,onCancelEdit:y,onCopy:x,activeInterrupt:b,disableInterruptActions:C=!1,onInterruptActionStart:k,onInterruptActionEnd:T,checkpointCandidates:S=[],activeCheckpointId:E=null,onSelectCheckpoint:A,defaultCheckpointId:R=null,messageParentCheckpointId:D=null}){const[B,q]=w.useState(!1),[V,j]=w.useState("preview"),[_,N]=w.useState(!1),{currentThreadId:z}=Wo(),{respondToInterrupt:$}=Vo(),P=l==="phone"||l==="half-screen",H=t.role,Q=H==="tool",M=w.useMemo(()=>"type"in t&&t.type==="default_message"?t:null,[t]),Y=!!M,ae=!(r&&H!=="user"),{uploadingFiles:ne,handleFileClick:ce,fileViewerOpen:G,currentFileInfo:O,closeFileViewer:W}=QC({allowFileOpen:ae,currentThreadId:z}),F=w.useMemo(()=>{switch(H){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))]"}},[H]),ee=w.useMemo(()=>{if(M)return"";const X=t.content;return Array.isArray(X)?QS(X):""},[M,t]),Z=w.useMemo(()=>{if(M)return{};const X=t.content;return Array.isArray(X)?Gf(t):{}},[M,t]),ye=w.useMemo(()=>Q?!!(t.additionalKwargs??{}).toolStreaming:!1,[Q,t]),fe=w.useMemo(()=>{if(M)return[];const X=t.content;return Array.isArray(X)?X.filter(U=>U.type==="image_url"):[]},[M,t]),oe=w.useMemo(()=>{if(M)return[];const X=t.content;return Array.isArray(X)?X.filter(U=>U.type==="file"):[]},[M,t]),xe=w.useMemo(()=>{if(M)return[];const X=t.content;return Array.isArray(X)?X.filter(U=>U.type==="interrupt"):[]},[M,t]),Se=(b==null?void 0:b.id)??(b==null?void 0:b.interrupt_id),$e=Fs(Se),_e=b==null?void 0:b.value,We=w.useMemo(()=>{if(M)return"";const X=t.content;return Array.isArray(X)?eC(X):""},[M,t]),Be=w.useMemo(()=>{if(M||!p)return[];const U=t.artifact;if(!U)return[];const re=[],Ie=[...Array.isArray(U.plots)?U.plots:[]];for(const be of Ie){const tt=sC(be);tt&&re.push(tt)}return re},[M,t,p]),qe=w.useCallback(async()=>{const X=Q?We:ee;async function U(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 U(X),q(!0),setTimeout(()=>q(!1),2e3),x==null||x(X)}catch(re){console.error("Failed to copy:",re)}},[Q,We,ee,x]),Ge=w.useCallback(()=>{if(!v)return;const X=Q?We:ee,U="type"in t&&t.type==="default_message"?void 0:{checkpointId:t.checkpointId??null,checkpointNs:t.checkpointNs??null};v(t.id,X,U)},[v,t.id,Q,We,ee,t]),Ze=w.useCallback(()=>{g==null||g(n)},[g,n]),ot=w.useCallback(()=>{const U=se(P?"h-3 w-3":"h-4 w-4","opacity-60 flex-shrink-0",F);switch(H){case"user":return u.jsx(ue.User,{className:U});case"assistant":return u.jsx(ue.Bot,{className:U});case"tool":return u.jsx(ue.Wrench,{className:U});default:return u.jsx(ue.Bot,{className:U})}},[P,F,H]),Ct=w.useCallback(()=>{const X="group relative mb-4 flex w-full";switch(H){case"user":return se(X,"justify-end");case"assistant":case"tool":case"system":return se(X,"justify-start");default:return X}},[H]),lt=w.useCallback(()=>{const X=se("rounded-lg px-4 py-3 relative min-w-0 max-w-full break-words",P&&"px-3 py-2 text-sm");if(Y)return se(X,"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(H){case"user":return se(X,"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 se(X,"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 se(X,"w-full md:max-w-[95%] bg-secondary/50 text-secondary-foreground border border-dashed");case"system":return se(X,"w-full md:max-w-[85%] bg-accent/40 text-muted-foreground border");default:return se(X,"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,Y,H]),ht=w.useCallback(async X=>{if(C)return;const U=Fs((X==null?void 0:X.id)??(X==null?void 0:X.interrupt_id));if(!U){console.warn("Interrupt part missing id",X);return}try{k==null||k(),await $(U,!0)}catch(re){console.error("Failed to approve interrupt:",re)}finally{T==null||T()}},[C,T,k,$]),dt=w.useCallback(async X=>{if(C)return;const U=Fs((X==null?void 0:X.id)??(X==null?void 0:X.interrupt_id));if(!U){console.warn("Interrupt part missing id",X);return}try{k==null||k(),await $(U,!1)}catch(re){console.error("Failed to reject interrupt:",re)}finally{T==null||T()}},[C,T,k,$]),gt=w.useCallback(({part:X,i:U})=>{if(X.type==="text"){const re=X.text??"",Ie=re.trim(),be=Oa(Ie);return be&&H!=="tool"?u.jsx(Rp,{data:be},U):H==="user"&&c&&Ie.length>d?u.jsx(eT,{text:Ie,expanded:_,onExpandedChange:N,previewLength:d,isCompact:P},U):u.jsx(xo,{content:re,allowHtml:!1},U)}if(X.type==="image_url"){const re=X;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"})},U)}if(X.type==="file"){const re=X,Ie=re.name||"file";return u.jsxs("a",{href:re.url,onClick:be=>ce(be.nativeEvent,re,U),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:[ne[U]?u.jsx(ue.Loader,{className:"h-4 w-4 animate-spin"}):null,u.jsxs("span",{className:"truncate max-w-[180px]",children:[Ie,ne[U]?" (processing)":""]})]},U)}if(X.type==="interrupt"){const re=X,Ie=Fs((re==null?void 0:re.id)??(re==null?void 0:re.interrupt_id)),be=!!($e&&Ie&&Ie===$e),tt=be?_e??(re==null?void 0:re.value):re==null?void 0:re.value,Pe=Ie?{...re,id:Ie,interrupt_id:Ie}:re;return u.jsx(YC,{interruptPart:Pe,onApprove:ht,onReject:dt,disabled:C,isActive:be,payload:tt},U)}return null},[ce,ne,ht,dt,H,c,d,_,P,$e,_e,b,C,xe]),kt=w.useCallback(()=>u.jsxs("div",{className:"flex items-center gap-2 p-2 bg-muted/30 rounded",children:[u.jsx(ue.Paperclip,{className:"h-4 w-4 text-muted-foreground"}),u.jsx("span",{className:"text-sm text-muted-foreground",children:"File upload"})]}),[]),At=w.useCallback(()=>{const X=ee.trim().length>0||fe.length>0||oe.length>0||xe.length>0;if(!Q&&oe.length>0&&!r)return kt();if(!Q&&!X&&!r)return null;if(Q)return!f&&Be.length>0?null:f?u.jsx(ZC,{message:t,viewMode:V,isStreaming:ye},t.id):null;if(!Q&&!M){const U=t,re=u.jsx("div",{className:"space-y-2",children:U.content.map((Ie,be)=>u.jsx(gt,{part:Ie,i:be},be))});return r?u.jsxs("div",{"aria-busy":"true",role:"status",children:[re,u.jsx(tT,{className:F})]}):re}},[ee,fe.length,oe.length,xe.length,r,Q,V,f,Be.length,kt,F]),qt=w.useMemo(()=>M?"Assistant":tC(t),[M,t]),Ue=w.useMemo(()=>M?[]:Array.isArray(S)?S:[],[S,M]),K=w.useMemo(()=>{var X;return Ue.length?R&&Ue.some(U=>U.id===R)?R:((X=Ue[0])==null?void 0:X.id)??null:null},[R,Ue]),ke=w.useMemo(()=>!Ue.length||!E?null:Ue.some(X=>X.id===E)?E:null,[E,Ue])??K,st=H==="user"&&Ue.length>0&&typeof A=="function",wt=w.useCallback((X,U=!1)=>{if(!A)return;const re=(X==null?void 0:X.id)??null,Ie=(X==null?void 0:X.parentId)??D??null;A(re,Ie,U)},[D,A]),Qe=w.useMemo(()=>ke?Ue.findIndex(X=>X.id===ke):-1,[ke,Ue]),Dt=w.useMemo(()=>Qe<0?null:Ue[Qe]??null,[Qe,Ue]);return Q&&!f&&Be.length===0?null:Y&&M?u.jsx("div",{className:se(Ct(),h.container),children:u.jsxs("div",{className:se(lt(),h.content),children:[u.jsxs("div",{className:"flex items-center gap-2 mb-2 pb-2 border-b border-current/10",children:[u.jsx(ue.Bot,{className:se("h-4 w-4",F)}),a&&u.jsx("span",{className:"font-medium text-sm",children:"Assistant"})]}),u.jsx(xo,{content:M.content,className:"text-current"})]})}):u.jsxs(u.Fragment,{children:[u.jsx("div",{className:se(Ct(),h.container),children:u.jsxs("div",{className:se(lt(),h.content),children:[(i||a||Q)&&u.jsxs("div",{className:se("flex items-center justify-between mb-2 pb-2 border-b border-current/10",P&&"mb-1 pb-1",F,h.header),children:[u.jsxs("div",{className:"flex items-center gap-2",children:[ot(),a&&qt&&u.jsx("span",{className:se("font-medium",P?"text-xs":"text-sm"),children:qt}),Q&&u.jsxs(Kf,{variant:"outline",className:se("text-xs flex items-center gap-1 cursor-pointer select-none",F,"border border-current/40",P&&"text-xs h-4"),role:"button",tabIndex:0,"aria-expanded":V==="expanded",onClick:()=>j(X=>X==="expanded"?"preview":"expanded"),onKeyDown:X=>{(X.key==="Enter"||X.key===" ")&&(X.preventDefault(),j(U=>U==="expanded"?"preview":"expanded"))},children:[u.jsx("span",{children:Z.name??"Tool Output"}),Z.toolCallId&&u.jsx("span",{className:"opacity-70",children:Z.toolCallId.slice(0,8)}),V==="expanded"?u.jsx(ue.ChevronUp,{className:"h-3 w-3"}):u.jsx(ue.ChevronDown,{className:"h-3 w-3"})]})]}),u.jsxs("div",{className:"flex items-center gap-2",children:[st&&Dt&&Qe>=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:se("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",Qe<Ue.length-1?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(Qe>=Ue.length-1)return;const X=Ue[Qe+1];X&&wt(X)},"aria-label":"Older checkpoint (back in time)",disabled:Qe>=Ue.length-1,children:u.jsx(ue.ChevronLeft,{className:"h-3 w-3"})}),u.jsx("div",{className:"flex items-center gap-2",children:u.jsxs("span",{className:"whitespace-nowrap",children:[Ue.length-Qe," / ",Ue.length]})}),u.jsx("button",{type:"button",className:se("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",Qe>0?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(!(Qe<=0))if(Qe===1)wt(null,!0);else{const X=Ue[Qe-1];X&&wt(X,!1)}},"aria-label":"Newer checkpoint (forward in time)",disabled:Qe<=0,children:u.jsx(ue.ChevronRight,{className:"h-3 w-3"})})]})}),i&&t.createdAt&&u.jsx("time",{className:se("text-xs opacity-60",F,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:se("opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",h.actions),children:[u.jsx("div",{className:"relative",children:u.jsx(nt,{variant:"ghost",size:"sm",onClick:()=>qe(),className:se("h-6 w-6 p-0 hover:bg-foreground/10",F,P&&"h-5 w-5"),"aria-label":"Copy message",title:"Copy message",children:u.jsx(ue.Copy,{className:se(B?"text-success":F,P?"h-3 w-3":"h-4 w-4")})})}),H==="user"&&v&&u.jsx(nt,{variant:"ghost",size:"sm",onClick:Ge,className:se("h-6 w-6 p-0 hover:bg-foreground/10",F,P&&"h-5 w-5"),"aria-label":"Edit message",children:u.jsx(ue.Edit,{className:se(F,P?"h-3 w-3":"h-4 w-4")})}),H==="assistant"&&g&&u.jsx(nt,{variant:"ghost",size:"sm",onClick:Ze,className:se("h-6 w-6 p-0 hover:bg-foreground/10",F,P&&"h-5 w-5"),"aria-label":"Regenerate response",children:u.jsx(ue.RotateCcw,{className:se(F,P?"h-3 w-3":"h-4 w-4")})})]})]})]}),u.jsxs("div",{className:"relative",children:[At(),p&&Be.length>0&&u.jsx("div",{className:"mt-3 space-y-4",children:Be.map((X,U)=>u.jsx(GC,{preview:X,idx:U},`artifact-${U}`))})]}),Q&&V==="expanded"&&(Z.toolCallId||Z.name)&&u.jsxs("div",{className:se("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",P&&"text-xs"),children:[Z.name&&u.jsxs("div",{children:["Function: ",Z.name]}),Z.toolCallId&&u.jsxs("div",{children:["Call ID: ",Z.toolCallId]})]}),!(i||a||Q)&&s&&!o&&u.jsxs("div",{className:se("absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",h.actions),children:[u.jsx(nt,{variant:"ghost",size:"sm",onClick:()=>qe(),className:se("h-6 w-6 p-0 hover:bg-background/50 text-current",P&&"h-5 w-5"),children:u.jsx(ue.Copy,{className:se(B?"text-success":"text-current",P?"h-3 w-3":"h-4 w-4")})}),H==="user"&&v&&u.jsx(nt,{variant:"ghost",size:"sm",onClick:Ge,className:se("h-6 w-6 p-0 hover:bg-background/50 text-current",P&&"h-5 w-5"),children:u.jsx(ue.Edit,{className:se("text-current",P?"h-3 w-3":"h-4 w-4")})}),H==="assistant"&&g&&u.jsx(nt,{variant:"ghost",size:"sm",onClick:Ze,className:se("h-6 w-6 p-0 hover:bg-background/50 text-current",P&&"h-5 w-5"),children:u.jsx(ue.RotateCcw,{className:se("text-current",P?"h-3 w-3":"h-4 w-4")})})]})]})}),O&&u.jsx(kC,{isOpen:G,onClose:W,fileId:O.id,fileName:O.name,mimeType:O.mimeType})]})},(e,t)=>{var l,c,d,f,p,h,v,g;if(t.isStreamingMessage||e.isStreamingMessage||!(e.message.id===t.message.id&&Yf(e.message)===Yf(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)&&((v=e.customStyles)==null?void 0:v.header)===((g=t.customStyles)==null?void 0:g.header);if(!o||!s)return!1;const i=Pp(e.message),a=Pp(t.message);return i.length===a.length});Ys.displayName="MessageComponent";function nT(e,t){return w.useMemo(()=>{var d,f,p,h,v;const n=e&&"type"in e&&e.type==="default_message";let r=[],o=null,s={},i={},a=null,l=null,c=null;if(!n&&e){const g=e,y=g.checkpointId??null;s=g.additionalKwargs??{},i=g.responseMetadata??{};const x=y&&t.checkpointMetaById?t.checkpointMetaById.get(y)??null:null;a=typeof s.step=="number"?s.step:typeof i.step=="number"?i.step:(x==null?void 0:x.step)??null;const b=typeof s.source=="string"?s.source:typeof i.source=="string"?i.source:(x==null?void 0:x.source)??null;l=b?String(b):null;const C=a!==null&&l?`${a}:${l}`:null;if(C&&((d=t.checkpointIndexByKey)!=null&&d.has(C))?r=t.checkpointIndexByKey.get(C)??[]:y&&x&&(r=[x]),o=y??((f=r[0])==null?void 0:f.id)??null,c=y?((p=t.attemptMetaById)==null?void 0:p.get(y))??null:null,!c&&(e==null?void 0:e.role)==="user"&&(e!=null&&e.id)&&t.userMessageIdToAttempts){const k=t.userMessageIdToAttempts.get(e.id);if(k&&k.length>0){const T=k[0].checkpointId;c=((h=t.attemptMetaById)==null?void 0:h.get(T))??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 T=[];for(const[S,E]of t.attemptMetaById.entries())if(E.baseUserMessageId===k){const A=(v=t.checkpointMetaById)==null?void 0:v.get(S);A&&T.push(A)}T.length>0&&(r=T)}}if(c&&c.attemptCount>1&&t.checkpointMetaById&&t.attemptMetaById){const k=[];for(const[T,S]of t.checkpointMetaById.entries()){const E=t.attemptMetaById.get(T);E&&E.attemptCount===c.attemptCount&&E.baseUserMessageId===c.baseUserMessageId&&k.push(S)}k.sort((T,S)=>{const E=T.createdAt?Date.parse(T.createdAt):0;return(S.createdAt?Date.parse(S.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(T=>T.id)}))}}return{checkpointCandidates:r,defaultCheckpointId:o,attemptMeta:c,resolvedStep:a,resolvedSource:l}},[e,t.checkpointMetaById,t.checkpointIndexByKey,t.attemptMetaById,t.userMessageIdToAttempts])}const Op=(e,t)=>(e==null?void 0:e.id)??`message-${t}`,Dp=w.memo(function({message:t,index:n,isStreaming:r,streamingAssistantId:o,streamingDebounceMs:s,layoutSize:i,enableMessageEditing:a,editingMessageId:l,onEdit:c,onRegenerate:d,onCancelEdit:f,activeInterrupt:p,disableInterruptActions:h,onInterruptActionStart:v,onInterruptActionEnd:g,showToolMessages:y,showArtifactPreviews:x,checkpointMetaById:b,checkpointIndexByKey:C,attemptMetaById:k,userMessageIdToAttempts:T,activeCheckpointId:S,onSelectCheckpoint:E}){const A=Op(t,n),R="type"in t&&t.type==="default_message",{checkpointCandidates:D,defaultCheckpointId:B,attemptMeta:q}=nT(t,{checkpointMetaById:b,checkpointIndexByKey:C,attemptMetaById:k,userMessageIdToAttempts:T}),V=t&&!R?t.additionalKwargs??{}:{},j=t&&!R?t.responseMetadata??{}:{},_=(()=>{if(typeof V.parentCheckpointId=="string")return V.parentCheckpointId;if(typeof j.parentCheckpointId=="string")return j.parentCheckpointId})();return u.jsx("div",{className:"relative mb-4 last:mb-0","data-message-id":A,style:{minHeight:"60px",containIntrinsicSize:"auto 120px"},children:u.jsx(Ys,{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:v,onInterruptActionEnd:g,showToolMessages:y,showArtifactPreviews:x,checkpointCandidates:D,activeCheckpointId:S??null,onSelectCheckpoint:E,defaultCheckpointId:B,messageParentCheckpointId:_,attemptMeta:q})})});Dp.displayName="MessageRow";const Ya=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:v=!0,isNavigatingCheckpoint:g=!1,onScrollAway:y,onAtBottom:x,activeInterrupt:b,disableInterruptActions:C=!1,onInterruptActionStart:k,onInterruptActionEnd:T,showToolMessages:S=!0,showArtifactPreviews:E=!0,checkpointMetaById:A,checkpointIndexByKey:R,attemptMetaById:D,userMessageIdToAttempts:B,activeCheckpointId:q,onSelectCheckpoint:V,createSyntheticThinkingMessage:j=!1},_)=>{const N=w.useRef(null),z=w.useRef(null),$=w.useRef(!1),P=w.useRef(!1),[H,Q]=w.useState(!0),M=w.useMemo(()=>b?e.some(oe=>"type"in oe&&oe.type==="default_message"?!1:Array.isArray(oe==null?void 0:oe.content)&&oe.content.some(xe=>xe&&xe.type==="interrupt"&&(xe.id??xe.interrupt_id)===b.id)):!1,[b,e]),Y=w.useMemo(()=>{if(!b||M)return null;const oe=b.id&&String(b.id).trim()?String(b.id).trim():"pending-interrupt";let xe;const Se=b.value;if(Se&&typeof Se=="object"&&!Array.isArray(Se)){const $e=Se.title;typeof $e=="string"&&$e.trim()&&(xe=$e.trim())}return{id:`interrupt-${oe}`,role:"system",createdAt:new Date().toISOString(),content:[{type:"interrupt",id:oe,value:Se,title:xe}]}},[b,M]),ae=w.useMemo(()=>Y?[...e,Y]:e,[e,Y]),ne=w.useMemo(()=>!j||!t?ae:!ae.some(xe=>xe.role==="assistant")&&ae.length>0?[...ae,{id:"thinking-assistant",role:"assistant",content:[],createdAt:new Date().toISOString()}]:ae,[ae,t,j]),ce=w.useMemo(()=>S?ne:ne.filter(oe=>(oe==null?void 0:oe.role)!=="tool"),[ne,S]),G=w.useCallback(oe=>{Q(oe),y&&y(!oe),x&&x(oe)},[y,x]),O=w.useMemo(()=>{if(a)return async()=>{if(!$.current){$.current=!0;try{await a()}finally{$.current=!1}}}},[a]),W=w.useMemo(()=>!v||g?!1:H?"auto":!1,[H,v,g]),F=w.useMemo(()=>{if(typeof h!="string")return null;const oe=h.trim();return oe?{id:"default-message",role:"assistant",type:"default_message",content:oe,createdAt:new Date().toISOString()}:null},[h]),ee=["flex h-full flex-col md:flex-row",f].filter(Boolean).join(" "),Z=()=>F?u.jsx("div",{className:"p-6 h-full overflow-y-auto",children:u.jsx("div",{className:"w-full max-w-full",children:u.jsx(Ys,{message:F,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!"}),ye=ce.length,fe=ye>0;return w.useEffect(()=>{var oe,xe;if(ye===0){P.current=!1;return}if(!P.current)if(P.current=!0,N.current&&ce.length>0){const Se=ce.length-1;(xe=(oe=N.current).scrollToIndex)==null||xe.call(oe,{index:Se,align:"end",behavior:"auto"})}else z.current&&(z.current.scrollTop=z.current.scrollHeight)},[ye,ce.length]),w.useImperativeHandle(_,()=>({scrollToLatest:()=>{var oe,xe;if(N.current&&ce.length>0){const Se=ce.length-1;(xe=(oe=N.current).scrollToIndex)==null||xe.call(oe,{index:Se,align:"end",behavior:"auto"})}else z.current&&(z.current.scrollTop=z.current.scrollHeight)},scrollToTop:()=>{var oe,xe;N.current&&ce.length>0?(xe=(oe=N.current).scrollToIndex)==null||xe.call(oe,{index:0,align:"start",behavior:"auto"}):z.current&&(z.current.scrollTop=0)}}),[ce]),u.jsx("div",{className:ee,style:p,children:u.jsx("div",{className:"relative flex-1 min-h-0",children:fe?u.jsx(OS,{ref:oe=>{N.current=oe},scrollerRef:oe=>{z.current=oe instanceof HTMLDivElement?oe:null},data:ce,followOutput:W,overscan:200,increaseViewportBy:{top:100,bottom:200},defaultItemHeight:80,atBottomThreshold:50,startReached:()=>{O&&O()},atBottomStateChange:G,style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:(oe,xe)=>Op(xe,oe),itemContent:(oe,xe)=>u.jsx(Dp,{message:xe,index:oe,isStreaming:t,streamingAssistantId:n,streamingDebounceMs:r,layoutSize:o,enableMessageEditing:s,editingMessageId:i,onEdit:l,onRegenerate:c,onCancelEdit:d,activeInterrupt:b,disableInterruptActions:C,onInterruptActionStart:k,onInterruptActionEnd:T,showToolMessages:S,showArtifactPreviews:E,checkpointMetaById:A,checkpointIndexByKey:R,attemptMetaById:D,userMessageIdToAttempts:B,activeCheckpointId:q,onSelectCheckpoint:V})}):Z()})})});Ya.displayName="MessageList";const Lp={value:""};function Xs({className:e="",placeholder:t="Type your message...",autoFocus:n=!0,maxHeight:r=void 0,streamingDebounceMs:o=500,streamingThrottleMs:s,followNewMessages:i=!0,enableFileUpload:a=!0,enableExcelUpload:l=!1,enableMessageEditing:c=!0,showToolMessages:d=!0,showArtifactPreviews:f=!0,customStyles:p={},onMessageSent:h,onExcelUploadSuccess:v,onError:g}){const{api:y}=Ti(),{currentThreadId:x}=Wo(),{threadId:b,messages:C,isHistoryLoading:k,isLoading:T,navigateToCheckpoint:S,returnToLatest:E,checkpoint:A,checkpoints:R,interrupt:D,metadata:B,timelineCheckpoints:q,messagePreviews:V}=Vo(),{isStreaming:j,error:_,connectionState:N,submit:z,stop:$}=Dc(),P=b??x??null,H=(A==null?void 0:A.id)??null,Q=(A==null?void 0:A.namespace)??null,M=(B==null?void 0:B.assemblingMessageId)??null,Y=D,[ae,ne]=w.useState(!1);w.useEffect(()=>{Y||ne(!1)},[Y]);const ce=w.useCallback(()=>{ne(!0)},[]),G=w.useCallback(()=>{ne(!1)},[]),O=!!Y||ae,[W,F]=w.useState(null),[ee,Z]=w.useState(""),[ye,fe]=w.useState(null),[oe,xe]=w.useState(null),[Se,$e]=w.useState([]),[_e,We]=w.useState(0),[Be,qe]=w.useState(0),[Ge,Ze]=w.useState(!1),[ot,Ct]=w.useState(null),[lt,ht]=w.useState(null),[dt,gt]=w.useState(!1),[kt,At]=w.useState(null),qt=w.useRef(!1),[Ue,K]=w.useState(()=>Lp.value),le=w.useRef(Ue),ke=w.useRef(null),st=w.useCallback(ge=>{Lp.value=ge,K(ge)},[]),[wt,Qe]=w.useState(!1),Dt=w.useRef(null),{checkpointMetaById:X,checkpointIndexByKey:U,attemptMetaById:re,userMessageIdToAttempts:Ie}=S0(R),be=q??[],tt=w.useRef(null),Pe=w.useRef(null),xt=w.useCallback(()=>{tt.current&&(tt.current.value=""),Pe.current&&(Pe.current.value=""),We(ge=>ge+1),qe(ge=>ge+1)},[]),Cn=w.useCallback(ge=>{st(ge)},[st]),An=w.useRef(!1);w.useEffect(()=>{An.current&&!j&&($e([]),xt()),An.current=j},[j,xt]);const[Or,Dr]=w.useState("desktop");w.useEffect(()=>{const ge=()=>{const Ne=window.innerWidth;Dr(Ne<640?"phone":Ne<1024?"tablet":"desktop")};return ge(),window.addEventListener("resize",ge),()=>window.removeEventListener("resize",ge)},[]),w.useEffect(()=>{qt.current=!1},[P]),w.useEffect(()=>{le.current=Ue},[Ue]),w.useEffect(()=>{if(!W){ke.current=null;return}ke.current===null&&(ke.current=le.current),st(ee??"")},[ee,W,st]),w.useEffect(()=>{(async()=>{if(!y.baseUrl){At(null);return}try{const Re=(await y.getAgent("default")).uiDefaultMessage||"";At(Re||null)}catch(Ne){console.warn("Failed to fetch default message:",Ne),At(null)}})()},[y.baseUrl]),w.useEffect(()=>{_&&!dt&&(g==null||g(_))},[_,dt,g]);const dr=ge=>{if(ge.length>Ts)return`Message too long (${ge.length}/${Ts} characters)`;try{return k0(ge),null}catch(Ne){return(Ne==null?void 0:Ne.message)||"Invalid message"}},Lr=async ge=>{const Ne=ge.trim();if(!(!Ne&&Se.length===0)){if(Ne){const Re=dr(Ne);if(Re){xe(Re);return}}try{const Re=W?(ye==null?void 0:ye.checkpointId)??H??void 0:H??void 0,Xe=W?(ye==null?void 0:ye.checkpointNs)??Q??void 0:Q??void 0;await z({text:Ne||"",attachments:Se},{checkpointId:Re,checkpointNs:Xe,edit:!!W,originalMessageId:W??void 0}),h==null||h(Ne),st(""),xe(null),$e([]),xt(),F(null),Z(""),fe(null)}catch(Re){const Xe=(Re==null?void 0:Re.message)||"Failed to send message";xe(Xe),g==null||g(Xe)}}},fr=w.useCallback((ge,Ne,Re)=>{c&&(ke.current=Ue,F(ge),Z(Ne),st(Ne),xe(null),fe({checkpointId:(Re==null?void 0:Re.checkpointId)??null,checkpointNs:(Re==null?void 0:Re.checkpointNs)??null}))},[Ue,c,st]),I=w.useCallback(()=>{F(null),Z(""),fe(null),xe(null),st(ke.current??Ue),ke.current=null},[Ue,st]),J=w.useCallback((ge,Ne,Re)=>{fr(ge,Ne,Re)},[fr]),de=w.useCallback(ge=>{let Ne=null;for(let on=ge-1;on>=0;on--)if(C[on].role==="user"){Ne=C[on];break}if(!Ne)return;const Re=Array.isArray(Ne.content)?Ne.content:[],Vn=Re.filter(on=>(on==null?void 0:on.type)==="text").map(on=>on.text).join("")||(()=>{try{return JSON.stringify(Re,null,2)}catch{return String(Re)}})();Vn&&z({text:Vn},{checkpointId:H??void 0,checkpointNs:Q??void 0,edit:!0,originalMessageId:Ne.id})},[C,z,H,Q]),Ce=ge=>{const Ne=Array.from(ge.target.files||[]);$e(Re=>[...Re,...Ne]),ge.target.value=""},Ye=ge=>{$e(Ne=>{const Re=Ne.filter((Xe,Vn)=>ge!==Vn);return Re.length===0&&xt(),Re})},et=async ge=>{const Ne=(ge.target.files||[])[0];if(Ne){Ct(null),ht(null),Ze(!0);try{await z({attachments:[Ne]},{checkpointId:H??void 0,checkpointNs:Q??void 0});const Re=`Uploaded ${Ne.name} - processing through chat stream`;ht(Re)}catch(Re){const Xe=Re instanceof Error?Re.message:"Failed to upload Excel file";console.error("Excel upload failed",Re),Ct(Xe),g==null||g(Xe)}finally{Ze(!1),ge.target.value="",xt()}}},ze=async ge=>{if(x){Qe(!0);try{if(!ge){await E(),requestAnimationFrame(()=>{var Xe;(Xe=Dt.current)==null||Xe.scrollToLatest()});return}const Ne=R.find(Xe=>Xe.checkpointId===ge),Re=(Ne==null?void 0:Ne.checkpointNs)??null;await S(ge,Re),requestAnimationFrame(()=>{var Xe;(Xe=Dt.current)==null||Xe.scrollToTop()})}finally{Qe(!1)}}},He=w.useCallback(async(ge,Ne,Re)=>{await ze(Re?null:ge)},[ze]),jt=`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||""}`,yt=`relative flex-shrink-0 w-full border-t p-4 bg-transparent ${p.inputArea||""}`;return u.jsxs("div",{className:jt,children:[!!_&&!dt&&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:_}),u.jsx(nt,{variant:"ghost",size:"sm",onClick:()=>gt(!0),className:"text-red-800 hover:bg-red-100","aria-label":"Dismiss error",children:u.jsx(ue.X,{size:16})})]}),u.jsxs("div",{className:`relative ${mt}`,style:r?{maxHeight:r}:void 0,children:[u.jsx(Ya,{ref:Dt,className:"h-full",style:{height:"100%"},messages:C,isStreaming:j,streamingAssistantId:M,streamingDebounceMs:typeof s=="number"?s:o,followNewMessages:i,layoutSize:Or,enableMessageEditing:c,editingMessageId:W,onEdit:J,onRegenerate:de,onCancelEdit:I,emptyMessage:kt??void 0,isNavigatingCheckpoint:wt,activeInterrupt:Y,disableInterruptActions:ae,onInterruptActionStart:ce,onInterruptActionEnd:G,showToolMessages:d,showArtifactPreviews:f,checkpointMetaById:X,checkpointIndexByKey:U,attemptMetaById:re,userMessageIdToAttempts:Ie,activeCheckpointId:H,onSelectCheckpoint:He,timelineCheckpoints:be,messagePreviews:V}),(N==="reconnecting"||N==="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(ue.Loader2,{className:"h-3 w-3 animate-spin"}),N==="reconnecting"?"Reconnecting…":"Connecting…"]})}),N==="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"}),T&&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(ue.Loader2,{className:"h-6 w-6 animate-spin"}),u.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:"Loading messages…"})]}),(k||wt)&&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(ue.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:yt,children:[W&&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(ue.Edit3,{size:16,className:"text-blue-600"}),u.jsx("span",{className:"text-sm font-medium text-blue-800",children:"Editing message"})]}),u.jsx(nt,{variant:"ghost",size:"sm",onClick:I,className:"text-blue-600 hover:bg-blue-100",children:u.jsx(ue.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:tt,type:"file",multiple:!0,onChange:ge=>Ce(ge),className:"hidden"},_e),Se.length>0&&u.jsx("div",{className:"flex flex-wrap gap-2",children:Se.map((ge,Ne)=>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(ue.Paperclip,{size:14}),u.jsx("span",{className:"truncate max-w-[150px]",children:ge.name}),u.jsx(nt,{variant:"ghost",size:"sm",onClick:()=>Ye(Ne),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 ${ge.name}`,children:u.jsx(ue.X,{size:12})})]},Ne))})]}),l&&u.jsxs(u.Fragment,{children:[u.jsx("input",{ref:Pe,type:"file",accept:".xls,.xlsx,.xlsm",onChange:et,className:"hidden"},Be),Ge&&u.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[u.jsx(ue.Loader2,{className:"h-4 w-4 animate-spin"})," Uploading Excel file..."]}),lt&&!Ge&&u.jsx("div",{className:"text-sm rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-emerald-700",children:lt}),ot&&!Ge&&u.jsx("div",{className:"text-sm rounded border border-red-200 bg-red-50 px-3 py-2 text-red-600",children:ot})]})]}),oe&&u.jsx("div",{className:"mb-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2",children:oe}),u.jsxs("div",{className:"flex items-end gap-2",children:[(a||l)&&u.jsxs(ua,{children:[u.jsx(da,{asChild:!0,children:u.jsx(nt,{type:"button",size:"icon",variant:"outline",disabled:j||O,title:"More input actions",className:p.moreButton||"",children:u.jsx(ue.Plus,{size:16})})}),u.jsxs(Ss,{align:"start",sideOffset:6,className:"w-52",children:[a&&u.jsxs(Qn,{onClick:()=>{var ge;return(ge=tt.current)==null?void 0:ge.click()},className:"cursor-pointer",children:[u.jsx(ue.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]}),l&&u.jsxs(Qn,{onClick:()=>{var ge;Ge||(ge=Pe.current)==null||ge.click()},className:`cursor-pointer ${Ge?"opacity-60 pointer-events-none":""}`,children:[u.jsx(ue.FileSpreadsheet,{className:"h-4 w-4 mr-2"})," Upload Excel file"]})]})]}),u.jsx("div",{className:"flex-1",children:u.jsx(dy,{initialValue:ee,editingMessageId:W,value:Ue,onValueChange:Cn,placeholder:W?"Edit your message...":t,isStreaming:j,disabled:O,maxLength:Ts,onSend:Lr,onCancelEdit:I,onStop:$,allowEmptySend:Se.length>0,textareaClassName:`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${W?"border-blue-400 bg-blue-50 text-blue-900 dark:border-blue-500 dark:bg-blue-950/60 dark:text-blue-50":""} ${oe?"border-red-400":""} ${p.textarea||""}`})})]})]})]})}const Js=m.forwardRef(({className:e,type:t,...n},r)=>u.jsx("input",{type:t,className:se("flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",e),ref:r,...n}));Js.displayName="Input";function Xa(e,[t,n]){return Math.min(n,Math.max(t,e))}function rT(e,t){return m.useReducer((n,r)=>t[n][r]??n,e)}var Ja="ScrollArea",[$p,bE]=kn(Ja),[oT,nn]=$p(Ja),Fp=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,type:r="hover",dir:o,scrollHideDelay:s=600,...i}=e,[a,l]=m.useState(null),[c,d]=m.useState(null),[f,p]=m.useState(null),[h,v]=m.useState(null),[g,y]=m.useState(null),[x,b]=m.useState(0),[C,k]=m.useState(0),[T,S]=m.useState(!1),[E,A]=m.useState(!1),R=Ve(t,B=>l(B)),D=qo(o);return u.jsx(oT,{scope:n,type:r,dir:D,scrollHideDelay:s,scrollArea:a,viewport:c,onViewportChange:d,content:f,onContentChange:p,scrollbarX:h,onScrollbarXChange:v,scrollbarXEnabled:T,onScrollbarXEnabledChange:S,scrollbarY:g,onScrollbarYChange:y,scrollbarYEnabled:E,onScrollbarYEnabledChange:A,onCornerWidthChange:b,onCornerHeightChange:k,children:u.jsx(Ee.div,{dir:D,...i,ref:R,style:{position:"relative","--radix-scroll-area-corner-width":x+"px","--radix-scroll-area-corner-height":C+"px",...e.style}})})});Fp.displayName=Ja;var Bp="ScrollAreaViewport",zp=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,i=nn(Bp,n),a=m.useRef(null),l=Ve(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(Ee.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})})]})});zp.displayName=Bp;var Sn="ScrollAreaScrollbar",Za=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=nn(Sn,e.__scopeScrollArea),{onScrollbarXEnabledChange:s,onScrollbarYEnabledChange:i}=o,a=e.orientation==="horizontal";return m.useEffect(()=>(a?s(!0):i(!0),()=>{a?s(!1):i(!1)}),[a,s,i]),o.type==="hover"?u.jsx(sT,{...r,ref:t,forceMount:n}):o.type==="scroll"?u.jsx(iT,{...r,ref:t,forceMount:n}):o.type==="auto"?u.jsx(Up,{...r,ref:t,forceMount:n}):o.type==="always"?u.jsx(Qa,{...r,ref:t}):null});Za.displayName=Sn;var sT=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=nn(Sn,e.__scopeScrollArea),[s,i]=m.useState(!1);return m.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(Zt,{present:n||s,children:u.jsx(Up,{"data-state":s?"visible":"hidden",...r,ref:t})})}),iT=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=nn(Sn,e.__scopeScrollArea),s=e.orientation==="horizontal",i=ti(()=>l("SCROLL_END"),100),[a,l]=rT("hidden",{hidden:{SCROLL:"scrolling"},scrolling:{SCROLL_END:"idle",POINTER_ENTER:"interacting"},interacting:{SCROLL:"interacting",POINTER_LEAVE:"idle"},idle:{HIDE:"hidden",SCROLL:"scrolling",POINTER_ENTER:"interacting"}});return m.useEffect(()=>{if(a==="idle"){const c=window.setTimeout(()=>l("HIDE"),o.scrollHideDelay);return()=>window.clearTimeout(c)}},[a,o.scrollHideDelay,l]),m.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(Zt,{present:n||a!=="hidden",children:u.jsx(Qa,{"data-state":a==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:me(e.onPointerEnter,()=>l("POINTER_ENTER")),onPointerLeave:me(e.onPointerLeave,()=>l("POINTER_LEAVE"))})})}),Up=m.forwardRef((e,t)=>{const n=nn(Sn,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,i]=m.useState(!1),a=e.orientation==="horizontal",l=ti(()=>{if(n.viewport){const c=n.viewport.offsetWidth<n.viewport.scrollWidth,d=n.viewport.offsetHeight<n.viewport.scrollHeight;i(a?c:d)}},10);return jr(n.viewport,l),jr(n.content,l),u.jsx(Zt,{present:r||s,children:u.jsx(Qa,{"data-state":s?"visible":"hidden",...o,ref:t})})}),Qa=m.forwardRef((e,t)=>{const{orientation:n="vertical",...r}=e,o=nn(Sn,e.__scopeScrollArea),s=m.useRef(null),i=m.useRef(0),[a,l]=m.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),c=qp(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 fT(p,i.current,a,h)}return n==="horizontal"?u.jsx(aT,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const p=o.viewport.scrollLeft,h=Gp(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(lT,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const p=o.viewport.scrollTop,h=Gp(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}),aT=m.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=nn(Sn,e.__scopeScrollArea),[i,a]=m.useState(),l=m.useRef(null),c=Ve(t,l,s.onScrollbarXChange);return m.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(Wp,{"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":ei(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),Xp(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:Qs(i.paddingLeft),paddingEnd:Qs(i.paddingRight)}})}})}),lT=m.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=nn(Sn,e.__scopeScrollArea),[i,a]=m.useState(),l=m.useRef(null),c=Ve(t,l,s.onScrollbarYChange);return m.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(Wp,{"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":ei(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),Xp(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:Qs(i.paddingTop),paddingEnd:Qs(i.paddingBottom)}})}})}),[cT,Hp]=$p(Sn),Wp=m.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=nn(Sn,n),[v,g]=m.useState(null),y=Ve(t,R=>g(R)),x=m.useRef(null),b=m.useRef(""),C=h.viewport,k=r.content-r.viewport,T=Nt(d),S=Nt(l),E=ti(f,10);function A(R){if(x.current){const D=R.clientX-x.current.left,B=R.clientY-x.current.top;c({x:D,y:B})}}return m.useEffect(()=>{const R=D=>{const B=D.target;(v==null?void 0:v.contains(B))&&T(D,k)};return document.addEventListener("wheel",R,{passive:!1}),()=>document.removeEventListener("wheel",R,{passive:!1})},[C,v,k,T]),m.useEffect(S,[r,S]),jr(v,E),jr(h.content,E),u.jsx(cT,{scope:n,scrollbar:v,hasThumb:o,onThumbChange:Nt(s),onThumbPointerUp:Nt(i),onThumbPositionChange:S,onThumbPointerDown:Nt(a),children:u.jsx(Ee.div,{...p,ref:y,style:{position:"absolute",...p.style},onPointerDown:me(e.onPointerDown,R=>{R.button===0&&(R.target.setPointerCapture(R.pointerId),x.current=v.getBoundingClientRect(),b.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",h.viewport&&(h.viewport.style.scrollBehavior="auto"),A(R))}),onPointerMove:me(e.onPointerMove,A),onPointerUp:me(e.onPointerUp,R=>{const D=R.target;D.hasPointerCapture(R.pointerId)&&D.releasePointerCapture(R.pointerId),document.body.style.webkitUserSelect=b.current,h.viewport&&(h.viewport.style.scrollBehavior=""),x.current=null})})})}),Zs="ScrollAreaThumb",Vp=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Hp(Zs,e.__scopeScrollArea);return u.jsx(Zt,{present:n||o.hasThumb,children:u.jsx(uT,{ref:t,...r})})}),uT=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=nn(Zs,n),i=Hp(Zs,n),{onThumbPositionChange:a}=i,l=Ve(t,f=>i.onThumbChange(f)),c=m.useRef(void 0),d=ti(()=>{c.current&&(c.current(),c.current=void 0)},100);return m.useEffect(()=>{const f=s.viewport;if(f){const p=()=>{if(d(),!c.current){const h=pT(f,a);c.current=h,a()}};return a(),f.addEventListener("scroll",p),()=>f.removeEventListener("scroll",p)}},[s.viewport,d,a]),u.jsx(Ee.div,{"data-state":i.hasThumb?"visible":"hidden",...o,ref:l,style:{width:"var(--radix-scroll-area-thumb-width)",height:"var(--radix-scroll-area-thumb-height)",...r},onPointerDownCapture:me(e.onPointerDownCapture,f=>{const h=f.target.getBoundingClientRect(),v=f.clientX-h.left,g=f.clientY-h.top;i.onThumbPointerDown({x:v,y:g})}),onPointerUp:me(e.onPointerUp,i.onThumbPointerUp)})});Vp.displayName=Zs;var el="ScrollAreaCorner",Kp=m.forwardRef((e,t)=>{const n=nn(el,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?u.jsx(dT,{...e,ref:t}):null});Kp.displayName=el;var dT=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=nn(el,n),[s,i]=m.useState(0),[a,l]=m.useState(0),c=!!(s&&a);return jr(o.scrollbarX,()=>{var f;const d=((f=o.scrollbarX)==null?void 0:f.offsetHeight)||0;o.onCornerHeightChange(d),l(d)}),jr(o.scrollbarY,()=>{var f;const d=((f=o.scrollbarY)==null?void 0:f.offsetWidth)||0;o.onCornerWidthChange(d),i(d)}),c?u.jsx(Ee.div,{...r,ref:t,style:{width:s,height:a,position:"absolute",right:o.dir==="ltr"?0:void 0,left:o.dir==="rtl"?0:void 0,bottom:0,...e.style}}):null});function Qs(e){return e?parseInt(e,10):0}function qp(e,t){const n=e/t;return isNaN(n)?0:n}function ei(e){const t=qp(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function fT(e,t,n,r="ltr"){const o=ei(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 Yp([l,c],f)(e)}function Gp(e,t,n="ltr"){const r=ei(t),o=t.scrollbar.paddingStart+t.scrollbar.paddingEnd,s=t.scrollbar.size-o,i=t.content-t.viewport,a=s-r,l=n==="ltr"?[0,i]:[i*-1,0],c=Xa(e,l);return Yp([0,i],[0,a])(c)}function Yp(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 Xp(e,t){return e>0&&e<t}var pT=(e,t=()=>{})=>{let n={left:e.scrollLeft,top:e.scrollTop},r=0;return function o(){const s={left:e.scrollLeft,top:e.scrollTop},i=n.left!==s.left,a=n.top!==s.top;(i||a)&&t(),n=s,r=window.requestAnimationFrame(o)}(),()=>window.cancelAnimationFrame(r)};function ti(e,t){const n=Nt(e),r=m.useRef(0);return m.useEffect(()=>()=>window.clearTimeout(r.current),[]),m.useCallback(()=>{window.clearTimeout(r.current),r.current=window.setTimeout(n,t)},[n,t])}function jr(e,t){const n=Nt(t);It(()=>{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 Jp=Fp,hT=zp,mT=Kp;const Zp=m.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Jp,{ref:r,className:se("relative overflow-hidden",e),...n,children:[u.jsx(hT,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),u.jsx(Qp,{}),u.jsx(mT,{})]}));Zp.displayName=Jp.displayName;const Qp=m.forwardRef(({className:e,orientation:t="vertical",...n},r)=>u.jsx(Za,{ref:r,orientation:t,className:se("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(Vp,{className:"relative flex-1 rounded-full bg-border"})}));Qp.displayName=Za.displayName;var eh=1,gT=.9,xT=.8,yT=.17,tl=.1,nl=.999,vT=.9999,bT=.99,wT=/[\\\/_+.#"@\[\(\{&]/,ST=/[\\\/_+.#"@\[\(\{&]/g,CT=/[\s-]/,th=/[\s-]/g;function rl(e,t,n,r,o,s,i){if(s===t.length)return o===e.length?eh:bT;var a=`${o},${s}`;if(i[a]!==void 0)return i[a];for(var l=r.charAt(s),c=n.indexOf(l,o),d=0,f,p,h,v;c>=0;)f=rl(e,t,n,r,c+1,s+1,i),f>d&&(c===o?f*=eh:wT.test(e.charAt(c-1))?(f*=xT,h=e.slice(o,c-1).match(ST),h&&o>0&&(f*=Math.pow(nl,h.length))):CT.test(e.charAt(c-1))?(f*=gT,v=e.slice(o,c-1).match(th),v&&o>0&&(f*=Math.pow(nl,v.length))):(f*=yT,o>0&&(f*=Math.pow(nl,c-o))),e.charAt(c)!==t.charAt(s)&&(f*=vT)),(f<tl&&n.charAt(c-1)===r.charAt(s+1)||r.charAt(s+1)===r.charAt(s)&&n.charAt(c-1)!==r.charAt(s))&&(p=rl(e,t,n,r,c+1,s+2,i),p*tl>f&&(f=p*tl)),f>d&&(d=f),c=n.indexOf(l,c+1);return i[a]=d,d}function nh(e){return e.toLowerCase().replace(th," ")}function TT(e,t,n){return e=n&&n.length>0?`${e+" "+n.join(" ")}`:e,rl(e,t,nh(e),nh(t),0,0,{})}var So='[cmdk-group=""]',ol='[cmdk-group-items=""]',kT='[cmdk-group-heading=""]',rh='[cmdk-item=""]',oh=`${rh}:not([aria-disabled="true"])`,sl="cmdk-item-select",_r="data-value",ET=(e,t,n)=>TT(e,t,n),sh=m.createContext(void 0),Co=()=>m.useContext(sh),ih=m.createContext(void 0),il=()=>m.useContext(ih),ah=m.createContext(void 0),lh=m.forwardRef((e,t)=>{let n=Mr(()=>{var M,Y;return{search:"",value:(Y=(M=e.value)!=null?M:e.defaultValue)!=null?Y:"",selectedItemId:void 0,filtered:{count:0,items:new Map,groups:new Set}}}),r=Mr(()=>new Set),o=Mr(()=>new Map),s=Mr(()=>new Map),i=Mr(()=>new Set),a=ch(e),{label:l,children:c,value:d,onValueChange:f,filter:p,shouldFilter:h,loop:v,disablePointerSelection:g=!1,vimBindings:y=!0,...x}=e,b=$t(),C=$t(),k=$t(),T=m.useRef(null),S=LT();ar(()=>{if(d!==void 0){let M=d.trim();n.current.value=M,E.emit()}},[d]),ar(()=>{S(6,V)},[]);let E=m.useMemo(()=>({subscribe:M=>(i.current.add(M),()=>i.current.delete(M)),snapshot:()=>n.current,setState:(M,Y,ae)=>{var ne,ce,G,O;if(!Object.is(n.current[M],Y)){if(n.current[M]=Y,M==="search")q(),D(),S(1,B);else if(M==="value"){if(document.activeElement.hasAttribute("cmdk-input")||document.activeElement.hasAttribute("cmdk-root")){let W=document.getElementById(k);W?W.focus():(ne=document.getElementById(b))==null||ne.focus()}if(S(7,()=>{var W;n.current.selectedItemId=(W=j())==null?void 0:W.id,E.emit()}),ae||S(5,V),((ce=a.current)==null?void 0:ce.value)!==void 0){let W=Y??"";(O=(G=a.current).onValueChange)==null||O.call(G,W);return}}E.emit()}},emit:()=>{i.current.forEach(M=>M())}}),[]),A=m.useMemo(()=>({value:(M,Y,ae)=>{var ne;Y!==((ne=s.current.get(M))==null?void 0:ne.value)&&(s.current.set(M,{value:Y,keywords:ae}),n.current.filtered.items.set(M,R(Y,ae)),S(2,()=>{D(),E.emit()}))},item:(M,Y)=>(r.current.add(M),Y&&(o.current.has(Y)?o.current.get(Y).add(M):o.current.set(Y,new Set([M]))),S(3,()=>{q(),D(),n.current.value||B(),E.emit()}),()=>{s.current.delete(M),r.current.delete(M),n.current.filtered.items.delete(M);let ae=j();S(4,()=>{q(),(ae==null?void 0:ae.getAttribute("id"))===M&&B(),E.emit()})}),group:M=>(o.current.has(M)||o.current.set(M,new Set),()=>{s.current.delete(M),o.current.delete(M)}),filter:()=>a.current.shouldFilter,label:l||e["aria-label"],getDisablePointerSelection:()=>a.current.disablePointerSelection,listId:b,inputId:k,labelId:C,listInnerRef:T}),[]);function R(M,Y){var ae,ne;let ce=(ne=(ae=a.current)==null?void 0:ae.filter)!=null?ne:ET;return M?ce(M,n.current.search,Y):0}function D(){if(!n.current.search||a.current.shouldFilter===!1)return;let M=n.current.filtered.items,Y=[];n.current.filtered.groups.forEach(ne=>{let ce=o.current.get(ne),G=0;ce.forEach(O=>{let W=M.get(O);G=Math.max(W,G)}),Y.push([ne,G])});let ae=T.current;_().sort((ne,ce)=>{var G,O;let W=ne.getAttribute("id"),F=ce.getAttribute("id");return((G=M.get(F))!=null?G:0)-((O=M.get(W))!=null?O:0)}).forEach(ne=>{let ce=ne.closest(ol);ce?ce.appendChild(ne.parentElement===ce?ne:ne.closest(`${ol} > *`)):ae.appendChild(ne.parentElement===ae?ne:ne.closest(`${ol} > *`))}),Y.sort((ne,ce)=>ce[1]-ne[1]).forEach(ne=>{var ce;let G=(ce=T.current)==null?void 0:ce.querySelector(`${So}[${_r}="${encodeURIComponent(ne[0])}"]`);G==null||G.parentElement.appendChild(G)})}function B(){let M=_().find(ae=>ae.getAttribute("aria-disabled")!=="true"),Y=M==null?void 0:M.getAttribute(_r);E.setState("value",Y||void 0)}function q(){var M,Y,ae,ne;if(!n.current.search||a.current.shouldFilter===!1){n.current.filtered.count=r.current.size;return}n.current.filtered.groups=new Set;let ce=0;for(let G of r.current){let O=(Y=(M=s.current.get(G))==null?void 0:M.value)!=null?Y:"",W=(ne=(ae=s.current.get(G))==null?void 0:ae.keywords)!=null?ne:[],F=R(O,W);n.current.filtered.items.set(G,F),F>0&&ce++}for(let[G,O]of o.current)for(let W of O)if(n.current.filtered.items.get(W)>0){n.current.filtered.groups.add(G);break}n.current.filtered.count=ce}function V(){var M,Y,ae;let ne=j();ne&&(((M=ne.parentElement)==null?void 0:M.firstChild)===ne&&((ae=(Y=ne.closest(So))==null?void 0:Y.querySelector(kT))==null||ae.scrollIntoView({block:"nearest"})),ne.scrollIntoView({block:"nearest"}))}function j(){var M;return(M=T.current)==null?void 0:M.querySelector(`${rh}[aria-selected="true"]`)}function _(){var M;return Array.from(((M=T.current)==null?void 0:M.querySelectorAll(oh))||[])}function N(M){let Y=_()[M];Y&&E.setState("value",Y.getAttribute(_r))}function z(M){var Y;let ae=j(),ne=_(),ce=ne.findIndex(O=>O===ae),G=ne[ce+M];(Y=a.current)!=null&&Y.loop&&(G=ce+M<0?ne[ne.length-1]:ce+M===ne.length?ne[0]:ne[ce+M]),G&&E.setState("value",G.getAttribute(_r))}function $(M){let Y=j(),ae=Y==null?void 0:Y.closest(So),ne;for(;ae&&!ne;)ae=M>0?OT(ae,So):DT(ae,So),ne=ae==null?void 0:ae.querySelector(oh);ne?E.setState("value",ne.getAttribute(_r)):z(M)}let P=()=>N(_().length-1),H=M=>{M.preventDefault(),M.metaKey?P():M.altKey?$(1):z(1)},Q=M=>{M.preventDefault(),M.metaKey?N(0):M.altKey?$(-1):z(-1)};return m.createElement(Ee.div,{ref:t,tabIndex:-1,...x,"cmdk-root":"",onKeyDown:M=>{var Y;(Y=x.onKeyDown)==null||Y.call(x,M);let ae=M.nativeEvent.isComposing||M.keyCode===229;if(!(M.defaultPrevented||ae))switch(M.key){case"n":case"j":{y&&M.ctrlKey&&H(M);break}case"ArrowDown":{H(M);break}case"p":case"k":{y&&M.ctrlKey&&Q(M);break}case"ArrowUp":{Q(M);break}case"Home":{M.preventDefault(),N(0);break}case"End":{M.preventDefault(),P();break}case"Enter":{M.preventDefault();let ne=j();if(ne){let ce=new Event(sl);ne.dispatchEvent(ce)}}}}},m.createElement("label",{"cmdk-label":"",htmlFor:A.inputId,id:A.labelId,style:FT},l),ni(e,M=>m.createElement(ih.Provider,{value:E},m.createElement(sh.Provider,{value:A},M))))}),IT=m.forwardRef((e,t)=>{var n,r;let o=$t(),s=m.useRef(null),i=m.useContext(ah),a=Co(),l=ch(e),c=(r=(n=l.current)==null?void 0:n.forceMount)!=null?r:i==null?void 0:i.forceMount;ar(()=>{if(!c)return a.item(o,i==null?void 0:i.id)},[c]);let d=uh(o,s,[e.value,e.children,s],e.keywords),f=il(),p=zn(S=>S.value&&S.value===d.current),h=zn(S=>c||a.filter()===!1?!0:S.search?S.filtered.items.get(o)>0:!0);m.useEffect(()=>{let S=s.current;if(!(!S||e.disabled))return S.addEventListener(sl,v),()=>S.removeEventListener(sl,v)},[h,e.onSelect,e.disabled]);function v(){var S,E;g(),(E=(S=l.current).onSelect)==null||E.call(S,d.current)}function g(){f.setState("value",d.current,!0)}if(!h)return null;let{disabled:y,value:x,onSelect:b,forceMount:C,keywords:k,...T}=e;return m.createElement(Ee.div,{ref:_n(s,t),...T,id:o,"cmdk-item":"",role:"option","aria-disabled":!!y,"aria-selected":!!p,"data-disabled":!!y,"data-selected":!!p,onPointerMove:y||a.getDisablePointerSelection()?void 0:g,onClick:y?void 0:v},e.children)}),NT=m.forwardRef((e,t)=>{let{heading:n,children:r,forceMount:o,...s}=e,i=$t(),a=m.useRef(null),l=m.useRef(null),c=$t(),d=Co(),f=zn(h=>o||d.filter()===!1?!0:h.search?h.filtered.groups.has(i):!0);ar(()=>d.group(i),[]),uh(i,a,[e.value,e.heading,l]);let p=m.useMemo(()=>({id:i,forceMount:o}),[o]);return m.createElement(Ee.div,{ref:_n(a,t),...s,"cmdk-group":"",role:"presentation",hidden:f?void 0:!0},n&&m.createElement("div",{ref:l,"cmdk-group-heading":"","aria-hidden":!0,id:c},n),ni(e,h=>m.createElement("div",{"cmdk-group-items":"",role:"group","aria-labelledby":n?c:void 0},m.createElement(ah.Provider,{value:p},h))))}),AT=m.forwardRef((e,t)=>{let{alwaysRender:n,...r}=e,o=m.useRef(null),s=zn(i=>!i.search);return!n&&!s?null:m.createElement(Ee.div,{ref:_n(o,t),...r,"cmdk-separator":"",role:"separator"})}),jT=m.forwardRef((e,t)=>{let{onValueChange:n,...r}=e,o=e.value!=null,s=il(),i=zn(c=>c.search),a=zn(c=>c.selectedItemId),l=Co();return m.useEffect(()=>{e.value!=null&&s.setState("search",e.value)},[e.value]),m.createElement(Ee.input,{ref:t,...r,"cmdk-input":"",autoComplete:"off",autoCorrect:"off",spellCheck:!1,"aria-autocomplete":"list",role:"combobox","aria-expanded":!0,"aria-controls":l.listId,"aria-labelledby":l.labelId,"aria-activedescendant":a,id:l.inputId,type:"text",value:o?e.value:i,onChange:c=>{o||s.setState("search",c.target.value),n==null||n(c.target.value)}})}),_T=m.forwardRef((e,t)=>{let{children:n,label:r="Suggestions",...o}=e,s=m.useRef(null),i=m.useRef(null),a=zn(c=>c.selectedItemId),l=Co();return m.useEffect(()=>{if(i.current&&s.current){let c=i.current,d=s.current,f,p=new ResizeObserver(()=>{f=requestAnimationFrame(()=>{let h=c.offsetHeight;d.style.setProperty("--cmdk-list-height",h.toFixed(1)+"px")})});return p.observe(c),()=>{cancelAnimationFrame(f),p.unobserve(c)}}},[]),m.createElement(Ee.div,{ref:_n(s,t),...o,"cmdk-list":"",role:"listbox",tabIndex:-1,"aria-activedescendant":a,"aria-label":r,id:l.listId},ni(e,c=>m.createElement("div",{ref:_n(i,l.listInnerRef),"cmdk-list-sizer":""},c)))}),MT=m.forwardRef((e,t)=>{let{open:n,onOpenChange:r,overlayClassName:o,contentClassName:s,container:i,...a}=e;return m.createElement(Fa,{open:n,onOpenChange:r},m.createElement(Ba,{container:i},m.createElement(ho,{"cmdk-overlay":"",className:o}),m.createElement(mo,{"aria-label":e.label,"cmdk-dialog":"",className:s},m.createElement(lh,{ref:t,...a}))))}),RT=m.forwardRef((e,t)=>zn(n=>n.filtered.count===0)?m.createElement(Ee.div,{ref:t,...e,"cmdk-empty":"",role:"presentation"}):null),PT=m.forwardRef((e,t)=>{let{progress:n,children:r,label:o="Loading...",...s}=e;return m.createElement(Ee.div,{ref:t,...s,"cmdk-loading":"",role:"progressbar","aria-valuenow":n,"aria-valuemin":0,"aria-valuemax":100,"aria-label":o},ni(e,i=>m.createElement("div",{"aria-hidden":!0},i)))}),Kt=Object.assign(lh,{List:_T,Item:IT,Input:jT,Group:NT,Separator:AT,Dialog:MT,Empty:RT,Loading:PT});function OT(e,t){let n=e.nextElementSibling;for(;n;){if(n.matches(t))return n;n=n.nextElementSibling}}function DT(e,t){let n=e.previousElementSibling;for(;n;){if(n.matches(t))return n;n=n.previousElementSibling}}function ch(e){let t=m.useRef(e);return ar(()=>{t.current=e}),t}var ar=typeof window>"u"?m.useEffect:m.useLayoutEffect;function Mr(e){let t=m.useRef();return t.current===void 0&&(t.current=e()),t}function zn(e){let t=il(),n=()=>e(t.snapshot());return m.useSyncExternalStore(t.subscribe,n,n)}function uh(e,t,n,r=[]){let o=m.useRef(),s=Co();return ar(()=>{var i;let a=(()=>{var c;for(let d of n){if(typeof d=="string")return d.trim();if(typeof d=="object"&&"current"in d)return d.current?(c=d.current.textContent)==null?void 0:c.trim():o.current}})(),l=r.map(c=>c.trim());s.value(e,a,l),(i=t.current)==null||i.setAttribute(_r,a),o.current=a}),o}var LT=()=>{let[e,t]=m.useState(),n=Mr(()=>new Map);return ar(()=>{n.current.forEach(r=>r()),n.current=new Map},[e]),(r,o)=>{n.current.set(r,o),t({})}};function $T(e){let t=e.type;return typeof t=="function"?t(e.props):"render"in t?t.render(e.props):e}function ni({asChild:e,children:t},n){return e&&m.isValidElement(t)?m.cloneElement($T(t),{ref:t.ref},n(t.props.children)):n(t)}var FT={position:"absolute",width:"1px",height:"1px",padding:"0",margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",borderWidth:"0"};const dh=m.forwardRef(({className:e,...t},n)=>u.jsx(Kt,{ref:n,className:se("flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",e),...t}));dh.displayName=Kt.displayName;const fh=m.forwardRef(({className:e,...t},n)=>u.jsxs("div",{className:"flex items-center border-b px-3","cmdk-input-wrapper":"",children:[u.jsx(ue.Search,{className:"mr-2 h-4 w-4 shrink-0 opacity-50"}),u.jsx(Kt.Input,{ref:n,className:se("flex h-11 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",e),...t})]}));fh.displayName=Kt.Input.displayName;const ph=m.forwardRef(({className:e,...t},n)=>u.jsx(Kt.List,{ref:n,className:se("max-h-[300px] overflow-y-auto overflow-x-hidden",e),...t}));ph.displayName=Kt.List.displayName;const hh=m.forwardRef((e,t)=>u.jsx(Kt.Empty,{ref:t,className:"py-6 text-center text-sm",...e}));hh.displayName=Kt.Empty.displayName;const mh=m.forwardRef(({className:e,...t},n)=>u.jsx(Kt.Group,{ref:n,className:se("overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",e),...t}));mh.displayName=Kt.Group.displayName;const BT=m.forwardRef(({className:e,...t},n)=>u.jsx(Kt.Separator,{ref:n,className:se("-mx-1 h-px bg-border",e),...t}));BT.displayName=Kt.Separator.displayName;const gh=m.forwardRef(({className:e,...t},n)=>u.jsx(Kt.Item,{ref:n,className:se("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none data-[disabled=true]:pointer-events-none data-[selected='true']:bg-accent data-[selected=true]:text-accent-foreground data-[disabled=true]:opacity-50",e),...t}));gh.displayName=Kt.Item.displayName;const xh=25,zT=[{key:"default",label:"My threads"},{key:"shared",label:"Shared with you"}];function al({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,view:f,defaultView:p,onViewChange:h,viewOptions:v}){const{threads:g,sharedThreads:y,currentThreadId:x,setCurrentThreadId:b,isLoading:C,isLoadingSharedThreads:k,smartOrgUsers:T,isLoadingSmartOrgUsers:S,actions:E}=Wo(),{createThread:A,deleteThread:R,renameThread:D,shareThread:B}=E,{loadThread:q}=Vo(),V=i??x,[j,_]=w.useState(Array.isArray(g)?g:[]),N=w.useRef(j.length>0),z=w.useRef(null),$=w.useRef(0),[P,H]=w.useState(null),[Q,M]=w.useState(""),[Y,ae]=w.useState(!1),[ne,ce]=w.useState(!1),[G,O]=w.useState(null),[W,F]=w.useState(""),ee=v&&v.length>0?v:zT,[Z,ye]=w.useState(p??"default"),fe=f??Z,oe=w.useCallback(K=>{f||ye(K),h==null||h(K)},[f,h]),xe=ee.find(K=>K.key===fe)??ee[0],Se=K=>{O(K),F(""),ce(!0)},$e=()=>{ce(!1),O(null),F("")},_e=async K=>{if(!G)return;const le=K.user_id??K.id??K.username??K.email;if(le)try{await B(G,le),$e()}catch(ke){console.error("Failed to share thread:",ke),alert(ke instanceof Error?ke.message:String(ke))}},We=w.useMemo(()=>{const K=W.trim().toLowerCase();return K?T.filter(le=>`${le.username??""} ${le.user_id??""} ${le.email??""} ${le.name??""}`.toLowerCase().includes(K)):T},[T,W]),Be=fe==="shared",qe=Be||!Be&&(y.length>0||k),Ge=fe==="default",Ze=()=>u.jsxs("div",{className:"space-y-2 rounded-lg border border-slate-700 bg-slate-800/60 p-2",children:[u.jsxs("div",{className:"flex items-center justify-between text-xs uppercase tracking-wide text-muted-foreground",children:[u.jsx("span",{children:"Shared with you"}),k&&u.jsx(ue.Loader2,{className:"h-3 w-3 animate-spin"})]}),u.jsx("div",{className:"space-y-1",children:k?u.jsxs("div",{className:"flex items-center gap-2 py-2 text-xs text-muted-foreground",children:[u.jsx(ue.Loader2,{className:"h-3 w-3 animate-spin"}),"Loading shared threads…"]}):y.length>0?y.map(K=>u.jsx("button",{type:"button",onClick:()=>ot(K.threadId),className:`w-full text-left rounded-lg px-3 py-2 transition-colors border ${V===K.threadId?"bg-slate-600 border-slate-500":"bg-slate-700/40 border-transparent hover:bg-slate-600"} text-gray-100`,children:u.jsxs("div",{className:"flex flex-col gap-1",children:[u.jsx("div",{className:"font-medium text-sm truncate",children:Ue(K)}),u.jsxs("div",{className:"text-[11px] text-muted-foreground",children:["Shared by ",K.sharedByUserId," • ",At(K.sharedAt||K.updatedAt)]})]})},K.shareId)):Be&&u.jsxs("div",{className:"text-center py-6 text-slate-400",children:[u.jsx(ue.MessageSquare,{className:"mx-auto mb-2 h-6 w-6 text-slate-500"}),u.jsx("p",{className:"text-sm text-slate-500",children:"No shared conversations yet"})]})})]});w.useEffect(()=>{const K=Array.isArray(g)?g:[];if(K.length>0){N.current=!0,_(K);return}C||(N.current=!1,_(K))},[g,C]),w.useEffect(()=>{if(!z.current)return;const K=z.current.querySelector("[data-radix-scroll-area-viewport]");if(!K)return;let le=null,ke=null;return le=requestAnimationFrame(()=>{ke=requestAnimationFrame(()=>{K.scrollTop=$.current})}),()=>{le!==null&&cancelAnimationFrame(le),ke!==null&&cancelAnimationFrame(ke)}},[j]);const ot=async K=>{try{b(K),await q(K,void 0,{clearProgress:!0}),a==null||a(K),l==null||l(K)}catch(le){console.error("Failed to select thread:",le)}},Ct=async()=>{try{ae(!0);const K=await A();K&&(c==null||c(K),a==null||a(K))}catch(K){console.error("Failed to create thread:",K)}finally{ae(!1)}},lt=async(K,le)=>{if(le.stopPropagation(),!!confirm("Delete this thread?")){if(z.current){const ke=z.current.querySelector("[data-radix-scroll-area-viewport]");ke&&($.current=ke.scrollTop)}try{await R(K),d==null||d(K)}catch(ke){console.error("Failed to delete thread:",ke)}}},ht=(K,le)=>{le.stopPropagation(),H(K.threadId),M(K.title||`Thread ${K.threadId.slice(0,8)}`)},dt=async K=>{if(Q.trim())try{await D(K,Q.trim()),H(null),M("")}catch(le){console.error("Failed to update title:",le)}},gt=()=>{H(null),M("")},kt=(K,le)=>{K.key==="Enter"?dt(le):K.key==="Escape"&>()},At=K=>{if(!K)return"";try{const le=new Date(K),st=new Date().getTime()-le.getTime(),wt=Math.floor(st/(1e3*60*60*24));return wt===0?le.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):wt===1?"Yesterday":wt<7?`${wt} days ago`:le.toLocaleDateString()}catch{return""}},qt=K=>K.title||`Thread ${K.threadId.slice(0,8)}`,Ue=K=>{const le=qt(K);return le.length<=xh?le:`${le.slice(0,xh)}...`};return u.jsxs("div",{className:`flex flex-col h-full ${e} ${s.container||""}`,children:[u.jsxs("div",{className:s.header||"flex-shrink-0 p-2 border-b bg-slate-800 border-slate-700 text-slate-100 flex items-center justify-between gap-2",children:[u.jsxs("div",{className:"flex items-center gap-2 text-xs uppercase tracking-wide text-muted-foreground",children:[u.jsx("span",{className:"text-[11px] tracking-[0.2em]",children:"View"}),u.jsxs(ua,{children:[u.jsx(da,{asChild:!0,children:u.jsx(nt,{variant:"outline",size:"sm",className:"flex items-center gap-1 px-3 text-[11px] text-slate-200 border-slate-600 hover:border-slate-500",children:xe.label})}),u.jsx(Ss,{align:"start",sideOffset:6,className:"w-48",children:ee.map(K=>u.jsxs(Qn,{className:"justify-between",onClick:le=>{le.preventDefault(),oe(K.key)},children:[u.jsx("span",{className:"text-sm",children:K.label}),fe===K.key&&u.jsx(ue.Check,{className:"h-3 w-3"})]},K.key))})]})]}),t&&u.jsx(nt,{onClick:Ct,disabled:Y||C,className:s.createButton||"p-2",size:"sm",variant:"ghost",title:Y?"Creating...":"New Chat",children:u.jsx(ue.MessageSquarePlus,{size:20})})]}),u.jsx(Zp,{ref:z,className:`flex-1 min-h-0 ${s.threadList||""}`,style:o?{maxHeight:o}:void 0,children:u.jsxs("div",{className:"p-2 space-y-1 pb-4",children:[qe&&Ze(),Ge?C?u.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 py-8 text-slate-400",children:[u.jsx(ue.Loader2,{className:"h-5 w-5 animate-spin"}),u.jsx("span",{className:"text-sm",children:"Loading threads…"})]}):j.length===0?u.jsxs("div",{className:"text-center py-8 text-slate-400",children:[u.jsx(ue.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"})]}):j.slice().sort((K,le)=>new Date(le.updatedAt||le.createdAt||"").getTime()-new Date(K.updatedAt||K.createdAt||"").getTime()).map(K=>u.jsxs("div",{onClick:()=>ot(K.threadId),className:`group relative p-3 rounded-lg cursor-pointer transition-colors border ${V===K.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:P===K.threadId?u.jsxs("div",{className:"flex items-center gap-2",onClick:le=>le.stopPropagation(),children:[u.jsx(Js,{value:Q,onChange:le=>M(le.target.value),onKeyDown:le=>kt(le,K.threadId),className:"h-6 text-sm",autoFocus:!0}),u.jsx(nt,{variant:"ghost",size:"sm",onClick:()=>dt(K.threadId),className:"h-6 w-6 p-0",children:u.jsx(ue.Check,{size:12})}),u.jsx(nt,{variant:"ghost",size:"sm",onClick:gt,className:"h-6 w-6 p-0",children:u.jsx(ue.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:Ue(K)}),u.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500 dark:text-slate-400 mt-1",children:[u.jsx(ue.Calendar,{size:10}),u.jsx("span",{children:At(K.updatedAt||K.createdAt)})]})]})}),u.jsx("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity ml-2",children:u.jsxs(ua,{children:[u.jsx(da,{asChild:!0,children:u.jsx(nt,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",children:u.jsx(ue.MoreHorizontal,{size:12})})}),u.jsxs(Ss,{align:"end",sideOffset:6,className:"w-44",children:[u.jsxs(Qn,{onClick:le=>{le.preventDefault(),Se(K.threadId)},children:[u.jsx(ue.Share2,{className:"mr-2 h-4 w-4"}),"Share thread"]}),r&&P!==K.threadId&&u.jsxs(Qn,{onClick:le=>{le.preventDefault(),ht(K,le)},children:[u.jsx(ue.Edit3,{className:"mr-2 h-4 w-4"}),"Rename"]}),n&&u.jsxs(Qn,{className:"text-red-400 hover:text-red-300",onClick:le=>{le.preventDefault(),lt(K.threadId,le)},children:[u.jsx(ue.Trash2,{className:"mr-2 h-4 w-4"}),"Delete"]})]})]})})]}),V===K.threadId&&u.jsx("div",{className:"absolute left-0 top-1/2 -translate-y-1/2 w-1 h-8 bg-blue-400 rounded-r"})]},K.threadId)):null]})}),u.jsx(mp,{open:ne,onOpenChange:K=>!K&&$e(),children:u.jsxs(za,{className:"max-w-md p-0",children:[u.jsx(Ua,{children:u.jsx(Ha,{children:"Share thread"})}),u.jsxs(dh,{children:[u.jsx(fh,{autoFocus:!0,value:W,onValueChange:K=>F(K),placeholder:"Search for users (name, email, id)..."}),u.jsxs(ph,{children:[u.jsx(hh,{children:S?u.jsxs("span",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[u.jsx(ue.Loader2,{className:"h-4 w-4 animate-spin"}),"Loading users…"]}):"No matching users found"}),u.jsx(mh,{heading:"Users",children:We.map(K=>{const le=K.username??K.user_id??K.email??"Unknown user",ke=[K.email,K.user_id].filter(Boolean).join(" • "),st=K.user_id??K.id??K.username??K.email??le;return u.jsx(gh,{onSelect:()=>_e(K),children:u.jsxs("div",{className:"flex flex-col items-start text-sm",children:[u.jsx("span",{className:"font-medium",children:le}),ke&&u.jsx("span",{className:"text-xs text-muted-foreground",children:ke})]})},st)})})]})]})]})})]})}const UT=({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 v=d===h.id,g=(r==null?void 0:r.get(h.id))??null;return u.jsxs("button",{type:"button",disabled:!n,onClick:()=>n==null?void 0:n(h.id),className:`relative flex items-start gap-2 text-left text-[11px] transition ${v?"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 ${v?"border-primary bg-primary/10 text-primary":"border-border bg-background"}`,children:u.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${v?"bg-primary":"bg-border"}`})}),u.jsxs("span",{className:"flex-1",children:[u.jsx("span",{className:"block font-medium leading-tight",children:h.label||"User input"}),u.jsxs("span",{className:"text-[9px] uppercase tracking-wide text-muted-foreground/70",children:[h.step!==null?`STEP ${h.step}`:"STEP —",h.next?` - ${h.next}`:""]}),g&&u.jsx("p",{className:"text-[10px] text-muted-foreground/80 mt-1 line-clamp-2",title:g,children:g})]})]},h.id)})})]}),n&&u.jsx("button",{type:"button",onClick:()=>n==null?void 0:n(null),className:"mt-auto mb-3 rounded-md border border-border/70 px-2 py-1 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground transition hover:border-foreground/60 hover:text-foreground",children:"Latest"})]})};function Rr(e){if(!(typeof globalThis>"u"))return globalThis[e]}function HT(e){if(typeof e!="string")return;const t=e.trim();if(t)return Tn(t)}function yh(){const e=[Rr("__API_BASE_URL__"),Rr("__CHAT_API_BASE_URL__"),Rr("__CHAT_API_URL__")];for(const t of e){const n=HT(t);if(n)return n}}function vh(){const e=[Rr("__API_AUTH_TOKEN__"),Rr("__CHAT_API_KEY__"),Rr("__CHAT_AUTH_TOKEN__")];for(const t of e)if(typeof t=="string"&&t.trim())return t.trim()}function bh(...e){for(const t of e)if(typeof t=="string"&&t.trim())return Tn(t);return Tn()}function wh(){const e={},t=yh(),n=vh();return t&&(e.baseUrl=t),n&&(e.apiKey=n),e}function Sh(){const e=wh(),t=jn.getAuthToken(),n=yh();return{apiBaseUrl:bh(e.baseUrl,jn.baseUrl,n),apiKey:t||e.apiKey||vh()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,darkMode:!1,enableSound:!1,messageHistory:100}}const Ch="chat-settings";function WT(){try{const e=localStorage.getItem(Ch);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function VT(e){try{const t={...e,apiBaseUrl:Tn(e.apiBaseUrl)};localStorage.setItem(Ch,JSON.stringify(t)),t.apiKey&&jn.setAuthToken(t.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function KT(){const e=Sh(),t=WT(),n=jn.getAuthToken(),r=typeof t.apiBaseUrl=="string"?t.apiBaseUrl:void 0;return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:bh(jn.baseUrl,r,e.apiBaseUrl)}}function qT(e){jn.updateConfig({baseUrl:e.apiBaseUrl,authToken:e.apiKey??void 0}),VT(e)}var GT="Label",Th=m.forwardRef((e,t)=>u.jsx(Ee.label,{...e,ref:t,onMouseDown:n=>{var o;n.target.closest("button, input, select, textarea")||((o=e.onMouseDown)==null||o.call(e,n),!n.defaultPrevented&&n.detail>1&&n.preventDefault())}}));Th.displayName=GT;var kh=Th;const YT=ko.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),rn=m.forwardRef(({className:e,...t},n)=>u.jsx(kh,{ref:n,className:se(YT(),e),...t}));rn.displayName=kh.displayName;function Eh(e){const t=m.useRef({value:e,previous:e});return m.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}var Ih=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"}),XT="VisuallyHidden",JT=m.forwardRef((e,t)=>u.jsx(Ee.span,{...e,ref:t,style:{...Ih,...e.style}}));JT.displayName=XT;var ZT=[" ","Enter","ArrowUp","ArrowDown"],QT=[" ","Enter"],lr="Select",[ri,oi,ek]=Ai(lr),[Pr,wE]=kn(lr,[ek,is]),si=is(),[tk,Un]=Pr(lr),[nk,rk]=Pr(lr),Nh=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:v}=e,g=si(t),[y,x]=m.useState(null),[b,C]=m.useState(null),[k,T]=m.useState(!1),S=qo(c),[E,A]=yr({prop:r,defaultProp:o??!1,onChange:s,caller:lr}),[R,D]=yr({prop:i,defaultProp:a,onChange:l,caller:lr}),B=m.useRef(null),q=y?v||!!y.closest("form"):!0,[V,j]=m.useState(new Set),_=Array.from(V).map(N=>N.props.value).join(";");return u.jsx(ju,{...g,children:u.jsxs(tk,{required:h,scope:t,trigger:y,onTriggerChange:x,valueNode:b,onValueNodeChange:C,valueNodeHasChildren:k,onValueNodeHasChildrenChange:T,contentId:$t(),value:R,onValueChange:D,open:E,onOpenChange:A,dir:S,triggerPointerDownPosRef:B,disabled:p,children:[u.jsx(ri.Provider,{scope:t,children:u.jsx(nk,{scope:e.__scopeSelect,onNativeOptionAdd:m.useCallback(N=>{j(z=>new Set(z).add(N))},[]),onNativeOptionRemove:m.useCallback(N=>{j(z=>{const $=new Set(z);return $.delete(N),$})},[]),children:n})}),q?u.jsxs(Zh,{"aria-hidden":!0,required:h,tabIndex:-1,name:d,autoComplete:f,value:R,onChange:N=>D(N.target.value),disabled:p,form:v,children:[R===void 0?u.jsx("option",{value:""}):null,Array.from(V)]},_):null]})})};Nh.displayName=lr;var Ah="SelectTrigger",jh=m.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...o}=e,s=si(n),i=Un(Ah,n),a=i.disabled||r,l=Ve(t,i.onTriggerChange),c=oi(n),d=m.useRef("touch"),[f,p,h]=em(g=>{const y=c().filter(C=>!C.disabled),x=y.find(C=>C.value===i.value),b=tm(y,g,x);b!==void 0&&i.onValueChange(b.value)}),v=g=>{a||(i.onOpenChange(!0),h()),g&&(i.triggerPointerDownPosRef.current={x:Math.round(g.pageX),y:Math.round(g.pageY)})};return u.jsx(_u,{asChild:!0,...s,children:u.jsx(Ee.button,{type:"button",role:"combobox","aria-controls":i.contentId,"aria-expanded":i.open,"aria-required":i.required,"aria-autocomplete":"none",dir:i.dir,"data-state":i.open?"open":"closed",disabled:a,"data-disabled":a?"":void 0,"data-placeholder":Qh(i.value)?"":void 0,...o,ref:l,onClick:me(o.onClick,g=>{g.currentTarget.focus(),d.current!=="mouse"&&v(g)}),onPointerDown:me(o.onPointerDown,g=>{d.current=g.pointerType;const y=g.target;y.hasPointerCapture(g.pointerId)&&y.releasePointerCapture(g.pointerId),g.button===0&&g.ctrlKey===!1&&g.pointerType==="mouse"&&(v(g),g.preventDefault())}),onKeyDown:me(o.onKeyDown,g=>{const y=f.current!=="";!(g.ctrlKey||g.altKey||g.metaKey)&&g.key.length===1&&p(g.key),!(y&&g.key===" ")&&ZT.includes(g.key)&&(v(),g.preventDefault())})})})});jh.displayName=Ah;var _h="SelectValue",Mh=m.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,children:s,placeholder:i="",...a}=e,l=Un(_h,n),{onValueNodeHasChildrenChange:c}=l,d=s!==void 0,f=Ve(t,l.onValueNodeChange);return It(()=>{c(d)},[c,d]),u.jsx(Ee.span,{...a,ref:f,style:{pointerEvents:"none"},children:Qh(l.value)?u.jsx(u.Fragment,{children:i}):s})});Mh.displayName=_h;var ok="SelectIcon",Rh=m.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...o}=e;return u.jsx(Ee.span,{"aria-hidden":!0,...o,ref:t,children:r||"▼"})});Rh.displayName=ok;var sk="SelectPortal",Ph=e=>u.jsx(as,{asChild:!0,...e});Ph.displayName=sk;var cr="SelectContent",Oh=m.forwardRef((e,t)=>{const n=Un(cr,e.__scopeSelect),[r,o]=m.useState();if(It(()=>{o(new DocumentFragment)},[]),!n.open){const s=r;return s?Eo.createPortal(u.jsx(Dh,{scope:e.__scopeSelect,children:u.jsx(ri.Slot,{scope:e.__scopeSelect,children:u.jsx("div",{children:e.children})})}),s):null}return u.jsx(Lh,{...e,ref:t})});Oh.displayName=cr;var fn=10,[Dh,Hn]=Pr(cr),ik="SelectContentImpl",ak=Kn.createSlot("SelectContent.RemoveScroll"),Lh=m.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:v,hideWhenDetached:g,avoidCollisions:y,...x}=e,b=Un(cr,n),[C,k]=m.useState(null),[T,S]=m.useState(null),E=Ve(t,G=>k(G)),[A,R]=m.useState(null),[D,B]=m.useState(null),q=oi(n),[V,j]=m.useState(!1),_=m.useRef(!1);m.useEffect(()=>{if(C)return Ji(C)},[C]),Mi();const N=m.useCallback(G=>{const[O,...W]=q().map(Z=>Z.ref.current),[F]=W.slice(-1),ee=document.activeElement;for(const Z of G)if(Z===ee||(Z==null||Z.scrollIntoView({block:"nearest"}),Z===O&&T&&(T.scrollTop=0),Z===F&&T&&(T.scrollTop=T.scrollHeight),Z==null||Z.focus(),document.activeElement!==ee))return},[q,T]),z=m.useCallback(()=>N([A,C]),[N,A,C]);m.useEffect(()=>{V&&z()},[V,z]);const{onOpenChange:$,triggerPointerDownPosRef:P}=b;m.useEffect(()=>{if(C){let G={x:0,y:0};const O=F=>{var ee,Z;G={x:Math.abs(Math.round(F.pageX)-(((ee=P.current)==null?void 0:ee.x)??0)),y:Math.abs(Math.round(F.pageY)-(((Z=P.current)==null?void 0:Z.y)??0))}},W=F=>{G.x<=10&&G.y<=10?F.preventDefault():C.contains(F.target)||$(!1),document.removeEventListener("pointermove",O),P.current=null};return P.current!==null&&(document.addEventListener("pointermove",O),document.addEventListener("pointerup",W,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",O),document.removeEventListener("pointerup",W,{capture:!0})}}},[C,$,P]),m.useEffect(()=>{const G=()=>$(!1);return window.addEventListener("blur",G),window.addEventListener("resize",G),()=>{window.removeEventListener("blur",G),window.removeEventListener("resize",G)}},[$]);const[H,Q]=em(G=>{const O=q().filter(ee=>!ee.disabled),W=O.find(ee=>ee.ref.current===document.activeElement),F=tm(O,G,W);F&&setTimeout(()=>F.ref.current.focus())}),M=m.useCallback((G,O,W)=>{const F=!_.current&&!W;(b.value!==void 0&&b.value===O||F)&&(R(G),F&&(_.current=!0))},[b.value]),Y=m.useCallback(()=>C==null?void 0:C.focus(),[C]),ae=m.useCallback((G,O,W)=>{const F=!_.current&&!W;(b.value!==void 0&&b.value===O||F)&&B(G)},[b.value]),ne=r==="popper"?ll:$h,ce=ne===ll?{side:a,sideOffset:l,align:c,alignOffset:d,arrowPadding:f,collisionBoundary:p,collisionPadding:h,sticky:v,hideWhenDetached:g,avoidCollisions:y}:{};return u.jsx(Dh,{scope:n,content:C,viewport:T,onViewportChange:S,itemRefCallback:M,selectedItem:A,onItemLeave:Y,itemTextRefCallback:ae,focusSelectedItem:z,selectedItemText:D,position:r,isPositioned:V,searchRef:H,children:u.jsx(gs,{as:ak,allowPinchZoom:!0,children:u.jsx(Yo,{asChild:!0,trapped:b.open,onMountAutoFocus:G=>{G.preventDefault()},onUnmountAutoFocus:me(o,G=>{var O;(O=b.trigger)==null||O.focus({preventScroll:!0}),G.preventDefault()}),children:u.jsx(Go,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:G=>G.preventDefault(),onDismiss:()=>b.onOpenChange(!1),children:u.jsx(ne,{role:"listbox",id:b.contentId,"data-state":b.open?"open":"closed",dir:b.dir,onContextMenu:G=>G.preventDefault(),...x,...ce,onPlaced:()=>j(!0),ref:E,style:{display:"flex",flexDirection:"column",outline:"none",...x.style},onKeyDown:me(x.onKeyDown,G=>{const O=G.ctrlKey||G.altKey||G.metaKey;if(G.key==="Tab"&&G.preventDefault(),!O&&G.key.length===1&&Q(G.key),["ArrowUp","ArrowDown","Home","End"].includes(G.key)){let F=q().filter(ee=>!ee.disabled).map(ee=>ee.ref.current);if(["ArrowUp","End"].includes(G.key)&&(F=F.slice().reverse()),["ArrowUp","ArrowDown"].includes(G.key)){const ee=G.target,Z=F.indexOf(ee);F=F.slice(Z+1)}setTimeout(()=>N(F)),G.preventDefault()}})})})})})})});Lh.displayName=ik;var lk="SelectItemAlignedPosition",$h=m.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...o}=e,s=Un(cr,n),i=Hn(cr,n),[a,l]=m.useState(null),[c,d]=m.useState(null),f=Ve(t,E=>d(E)),p=oi(n),h=m.useRef(!1),v=m.useRef(!0),{viewport:g,selectedItem:y,selectedItemText:x,focusSelectedItem:b}=i,C=m.useCallback(()=>{if(s.trigger&&s.valueNode&&a&&c&&g&&y&&x){const E=s.trigger.getBoundingClientRect(),A=c.getBoundingClientRect(),R=s.valueNode.getBoundingClientRect(),D=x.getBoundingClientRect();if(s.dir!=="rtl"){const ee=D.left-A.left,Z=R.left-ee,ye=E.left-Z,fe=E.width+ye,oe=Math.max(fe,A.width),xe=window.innerWidth-fn,Se=Xa(Z,[fn,Math.max(fn,xe-oe)]);a.style.minWidth=fe+"px",a.style.left=Se+"px"}else{const ee=A.right-D.right,Z=window.innerWidth-R.right-ee,ye=window.innerWidth-E.right-Z,fe=E.width+ye,oe=Math.max(fe,A.width),xe=window.innerWidth-fn,Se=Xa(Z,[fn,Math.max(fn,xe-oe)]);a.style.minWidth=fe+"px",a.style.right=Se+"px"}const B=p(),q=window.innerHeight-fn*2,V=g.scrollHeight,j=window.getComputedStyle(c),_=parseInt(j.borderTopWidth,10),N=parseInt(j.paddingTop,10),z=parseInt(j.borderBottomWidth,10),$=parseInt(j.paddingBottom,10),P=_+N+V+$+z,H=Math.min(y.offsetHeight*5,P),Q=window.getComputedStyle(g),M=parseInt(Q.paddingTop,10),Y=parseInt(Q.paddingBottom,10),ae=E.top+E.height/2-fn,ne=q-ae,ce=y.offsetHeight/2,G=y.offsetTop+ce,O=_+N+G,W=P-O;if(O<=ae){const ee=B.length>0&&y===B[B.length-1].ref.current;a.style.bottom="0px";const Z=c.clientHeight-g.offsetTop-g.offsetHeight,ye=Math.max(ne,ce+(ee?Y:0)+Z+z),fe=O+ye;a.style.height=fe+"px"}else{const ee=B.length>0&&y===B[0].ref.current;a.style.top="0px";const ye=Math.max(ae,_+g.offsetTop+(ee?M:0)+ce)+W;a.style.height=ye+"px",g.scrollTop=O-ae+g.offsetTop}a.style.margin=`${fn}px 0`,a.style.minHeight=H+"px",a.style.maxHeight=q+"px",r==null||r(),requestAnimationFrame(()=>h.current=!0)}},[p,s.trigger,s.valueNode,a,c,g,y,x,s.dir,r]);It(()=>C(),[C]);const[k,T]=m.useState();It(()=>{c&&T(window.getComputedStyle(c).zIndex)},[c]);const S=m.useCallback(E=>{E&&v.current===!0&&(C(),b==null||b(),v.current=!1)},[C,b]);return u.jsx(uk,{scope:n,contentWrapper:a,shouldExpandOnScrollRef:h,onScrollButtonChange:S,children:u.jsx("div",{ref:l,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:k},children:u.jsx(Ee.div,{...o,ref:f,style:{boxSizing:"border-box",maxHeight:"100%",...o.style}})})})});$h.displayName=lk;var ck="SelectPopperPosition",ll=m.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=fn,...s}=e,i=si(n);return u.jsx(Mu,{...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)"}})});ll.displayName=ck;var[uk,cl]=Pr(cr,{}),ul="SelectViewport",Fh=m.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...o}=e,s=Hn(ul,n),i=cl(ul,n),a=Ve(t,s.onViewportChange),l=m.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(ri.Slot,{scope:n,children:u.jsx(Ee.div,{"data-radix-select-viewport":"",role:"presentation",...o,ref:a,style:{position:"relative",flex:1,overflow:"hidden auto",...o.style},onScroll:me(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 v=window.innerHeight-fn*2,g=parseFloat(f.style.minHeight),y=parseFloat(f.style.height),x=Math.max(g,y);if(x<v){const b=x+h,C=Math.min(v,b),k=b-C;f.style.height=C+"px",f.style.bottom==="0px"&&(d.scrollTop=k>0?k:0,f.style.justifyContent="flex-end")}}}l.current=d.scrollTop})})})]})});Fh.displayName=ul;var Bh="SelectGroup",[dk,fk]=Pr(Bh),pk=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=$t();return u.jsx(dk,{scope:n,id:o,children:u.jsx(Ee.div,{role:"group","aria-labelledby":o,...r,ref:t})})});pk.displayName=Bh;var zh="SelectLabel",Uh=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=fk(zh,n);return u.jsx(Ee.div,{id:o.id,...r,ref:t})});Uh.displayName=zh;var ii="SelectItem",[hk,Hh]=Pr(ii),Wh=m.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:s,...i}=e,a=Un(ii,n),l=Hn(ii,n),c=a.value===r,[d,f]=m.useState(s??""),[p,h]=m.useState(!1),v=Ve(t,b=>{var C;return(C=l.itemRefCallback)==null?void 0:C.call(l,b,r,o)}),g=$t(),y=m.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(hk,{scope:n,value:r,disabled:o,textId:g,isSelected:c,onItemTextChange:m.useCallback(b=>{f(C=>C||((b==null?void 0:b.textContent)??"").trim())},[]),children:u.jsx(ri.ItemSlot,{scope:n,value:r,disabled:o,textValue:d,children:u.jsx(Ee.div,{role:"option","aria-labelledby":g,"data-highlighted":p?"":void 0,"aria-selected":c&&p,"data-state":c?"checked":"unchecked","aria-disabled":o||void 0,"data-disabled":o?"":void 0,tabIndex:o?void 0:-1,...i,ref:v,onFocus:me(i.onFocus,()=>h(!0)),onBlur:me(i.onBlur,()=>h(!1)),onClick:me(i.onClick,()=>{y.current!=="mouse"&&x()}),onPointerUp:me(i.onPointerUp,()=>{y.current==="mouse"&&x()}),onPointerDown:me(i.onPointerDown,b=>{y.current=b.pointerType}),onPointerMove:me(i.onPointerMove,b=>{var C;y.current=b.pointerType,o?(C=l.onItemLeave)==null||C.call(l):y.current==="mouse"&&b.currentTarget.focus({preventScroll:!0})}),onPointerLeave:me(i.onPointerLeave,b=>{var C;b.currentTarget===document.activeElement&&((C=l.onItemLeave)==null||C.call(l))}),onKeyDown:me(i.onKeyDown,b=>{var k;((k=l.searchRef)==null?void 0:k.current)!==""&&b.key===" "||(QT.includes(b.key)&&x(),b.key===" "&&b.preventDefault())})})})})});Wh.displayName=ii;var To="SelectItemText",Vh=m.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,...s}=e,i=Un(To,n),a=Hn(To,n),l=Hh(To,n),c=rk(To,n),[d,f]=m.useState(null),p=Ve(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,v=m.useMemo(()=>u.jsx("option",{value:l.value,disabled:l.disabled,children:h},l.value),[l.disabled,l.value,h]),{onNativeOptionAdd:g,onNativeOptionRemove:y}=c;return It(()=>(g(v),()=>y(v)),[g,y,v]),u.jsxs(u.Fragment,{children:[u.jsx(Ee.span,{id:l.textId,...s,ref:p}),l.isSelected&&i.valueNode&&!i.valueNodeHasChildren?Eo.createPortal(s.children,i.valueNode):null]})});Vh.displayName=To;var Kh="SelectItemIndicator",qh=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return Hh(Kh,n).isSelected?u.jsx(Ee.span,{"aria-hidden":!0,...r,ref:t}):null});qh.displayName=Kh;var dl="SelectScrollUpButton",Gh=m.forwardRef((e,t)=>{const n=Hn(dl,e.__scopeSelect),r=cl(dl,e.__scopeSelect),[o,s]=m.useState(!1),i=Ve(t,r.onScrollButtonChange);return It(()=>{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(Xh,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop-l.offsetHeight)}}):null});Gh.displayName=dl;var fl="SelectScrollDownButton",Yh=m.forwardRef((e,t)=>{const n=Hn(fl,e.__scopeSelect),r=cl(fl,e.__scopeSelect),[o,s]=m.useState(!1),i=Ve(t,r.onScrollButtonChange);return It(()=>{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(Xh,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop+l.offsetHeight)}}):null});Yh.displayName=fl;var Xh=m.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...o}=e,s=Hn("SelectScrollButton",n),i=m.useRef(null),a=oi(n),l=m.useCallback(()=>{i.current!==null&&(window.clearInterval(i.current),i.current=null)},[]);return m.useEffect(()=>()=>l(),[l]),It(()=>{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(Ee.div,{"aria-hidden":!0,...o,ref:t,style:{flexShrink:0,...o.style},onPointerDown:me(o.onPointerDown,()=>{i.current===null&&(i.current=window.setInterval(r,50))}),onPointerMove:me(o.onPointerMove,()=>{var c;(c=s.onItemLeave)==null||c.call(s),i.current===null&&(i.current=window.setInterval(r,50))}),onPointerLeave:me(o.onPointerLeave,()=>{l()})})}),mk="SelectSeparator",Jh=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return u.jsx(Ee.div,{"aria-hidden":!0,...r,ref:t})});Jh.displayName=mk;var pl="SelectArrow",gk=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=si(n),s=Un(pl,n),i=Hn(pl,n);return s.open&&i.position==="popper"?u.jsx(Ru,{...o,...r,ref:t}):null});gk.displayName=pl;var xk="SelectBubbleInput",Zh=m.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const o=m.useRef(null),s=Ve(r,o),i=Eh(t);return m.useEffect(()=>{const a=o.current;if(!a)return;const l=window.HTMLSelectElement.prototype,d=Object.getOwnPropertyDescriptor(l,"value").set;if(i!==t&&d){const f=new Event("change",{bubbles:!0});d.call(a,t),a.dispatchEvent(f)}},[i,t]),u.jsx(Ee.select,{...n,style:{...Ih,...n.style},ref:s,defaultValue:t})});Zh.displayName=xk;function Qh(e){return e===""||e===void 0}function em(e){const t=Nt(e),n=m.useRef(""),r=m.useRef(0),o=m.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=m.useCallback(()=>{n.current="",window.clearTimeout(r.current)},[]);return m.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,o,s]}function tm(e,t,n){const o=t.length>1&&Array.from(t).every(c=>c===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let i=yk(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 yk(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var vk=Nh,nm=jh,bk=Mh,wk=Rh,Sk=Ph,rm=Oh,Ck=Fh,om=Uh,sm=Wh,Tk=Vh,kk=qh,im=Gh,am=Yh,lm=Jh;const cm=vk,um=bk,hl=m.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(nm,{ref:r,className:se("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(wk,{asChild:!0,children:u.jsx(ue.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));hl.displayName=nm.displayName;const dm=m.forwardRef(({className:e,...t},n)=>u.jsx(im,{ref:n,className:se("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(ue.ChevronUp,{className:"h-4 w-4"})}));dm.displayName=im.displayName;const fm=m.forwardRef(({className:e,...t},n)=>u.jsx(am,{ref:n,className:se("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(ue.ChevronDown,{className:"h-4 w-4"})}));fm.displayName=am.displayName;const ml=m.forwardRef(({className:e,children:t,position:n="popper",...r},o)=>u.jsx(Sk,{children:u.jsxs(rm,{ref:o,className:se("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(dm,{}),u.jsx(Ck,{className:se("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),u.jsx(fm,{})]})}));ml.displayName=rm.displayName;const Ek=m.forwardRef(({className:e,...t},n)=>u.jsx(om,{ref:n,className:se("py-1.5 pl-8 pr-2 text-sm font-semibold",e),...t}));Ek.displayName=om.displayName;const ur=m.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(sm,{ref:r,className:se("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(kk,{children:u.jsx(ue.Check,{className:"h-4 w-4"})})}),u.jsx(Tk,{children:t})]}));ur.displayName=sm.displayName;const Ik=m.forwardRef(({className:e,...t},n)=>u.jsx(lm,{ref:n,className:se("-mx-1 my-1 h-px bg-muted",e),...t}));Ik.displayName=lm.displayName;var Nk="Separator",pm="horizontal",Ak=["horizontal","vertical"],hm=m.forwardRef((e,t)=>{const{decorative:n,orientation:r=pm,...o}=e,s=jk(r)?r:pm,a=n?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return u.jsx(Ee.div,{"data-orientation":s,...a,...o,ref:t})});hm.displayName=Nk;function jk(e){return Ak.includes(e)}var mm=hm;const gm=m.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},o)=>u.jsx(mm,{ref:o,decorative:n,orientation:t,className:se("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));gm.displayName=mm.displayName;const _k=Fa,Mk=xC,Rk=Ba,xm=m.forwardRef(({className:e,...t},n)=>u.jsx(ho,{className:se("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",e),...t,ref:n}));xm.displayName=ho.displayName;const Pk=ko.cva("fixed z-50 gap-4 bg-background p-6 shadow-lg transition ease-in-out data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:duration-300 data-[state=open]:duration-500",{variants:{side:{top:"inset-x-0 top-0 border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",bottom:"inset-x-0 bottom-0 border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",left:"inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm",right:"inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm"}},defaultVariants:{side:"right"}}),ym=m.forwardRef(({side:e="right",className:t,children:n,...r},o)=>u.jsxs(Rk,{children:[u.jsx(xm,{}),u.jsxs(mo,{ref:o,className:se(Pk({side:e}),t),...r,children:[n,u.jsxs(hp,{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(ue.X,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));ym.displayName=mo.displayName;const vm=({className:e,...t})=>u.jsx("div",{className:se("flex flex-col space-y-2 text-center sm:text-left",e),...t});vm.displayName="SheetHeader";const bm=m.forwardRef(({className:e,...t},n)=>u.jsx(sr,{ref:n,className:se("text-lg font-semibold text-foreground",e),...t}));bm.displayName=sr.displayName;const wm=m.forwardRef(({className:e,...t},n)=>u.jsx(Us,{ref:n,className:se("text-sm text-muted-foreground",e),...t}));wm.displayName=Us.displayName;var ai="Switch",[Ok,SE]=kn(ai),[Dk,Lk]=Ok(ai),Sm=m.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]=m.useState(null),v=Ve(t,C=>h(C)),g=m.useRef(!1),y=p?d||!!p.closest("form"):!0,[x,b]=yr({prop:o,defaultProp:s??!1,onChange:c,caller:ai});return u.jsxs(Dk,{scope:n,checked:x,disabled:a,children:[u.jsx(Ee.button,{type:"button",role:"switch","aria-checked":x,"aria-required":i,"data-state":Em(x),"data-disabled":a?"":void 0,disabled:a,value:l,...f,ref:v,onClick:me(e.onClick,C=>{b(k=>!k),y&&(g.current=C.isPropagationStopped(),g.current||C.stopPropagation())})}),y&&u.jsx(km,{control:p,bubbles:!g.current,name:r,value:l,checked:x,required:i,disabled:a,form:d,style:{transform:"translateX(-100%)"}})]})});Sm.displayName=ai;var Cm="SwitchThumb",Tm=m.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,o=Lk(Cm,n);return u.jsx(Ee.span,{"data-state":Em(o.checked),"data-disabled":o.disabled?"":void 0,...r,ref:t})});Tm.displayName=Cm;var $k="SwitchBubbleInput",km=m.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...o},s)=>{const i=m.useRef(null),a=Ve(i,s),l=Eh(n),c=bu(t);return m.useEffect(()=>{const d=i.current;if(!d)return;const f=window.HTMLInputElement.prototype,h=Object.getOwnPropertyDescriptor(f,"checked").set;if(l!==n&&h){const v=new Event("click",{bubbles:r});h.call(d,n),d.dispatchEvent(v)}},[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}})});km.displayName=$k;function Em(e){return e?"checked":"unchecked"}var Im=Sm,Fk=Tm;const Wn=m.forwardRef(({className:e,...t},n)=>u.jsx(Im,{className:se("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(Fk,{className:se("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")})}));Wn.displayName=Im.displayName;const Bk={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 zk({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}=Ka();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(Bk),d(!0),f({title:"Settings reset",description:"Configuration has been reset to defaults."})},v=()=>{l(e),d(!1),o(!1)},g=async()=>{try{const x=await(await fetch(`${a.api.baseUrl}/health`)).json();f({title:"Connection successful",description:`API is ${x.status||"healthy"}`})}catch{f({title:"Connection failed",description:"Unable to connect to the API endpoint.",variant:"destructive"})}};return u.jsxs(_k,{open:r,onOpenChange:o,children:[u.jsx(Mk,{asChild:!0,children:u.jsxs(nt,{variant:"outline",size:"sm",className:n,children:[u.jsx(ue.Settings,{className:"h-4 w-4 mr-2"}),"Settings",c&&u.jsx(Kf,{variant:"destructive",className:"ml-2 h-4 w-4 p-0"})]})}),u.jsxs(ym,{className:"w-[500px] sm:w-[600px] overflow-y-auto",children:[u.jsxs(vm,{children:[u.jsx(bm,{children:"Chat Settings"}),u.jsx(wm,{children:"Configure your chat interface, API connection, and behavior preferences."})]}),u.jsxs("div",{className:"space-y-6 py-6",children:[u.jsxs(yo,{children:[u.jsx(vo,{className:"pb-3",children:u.jsxs(bo,{className:"text-lg flex items-center gap-2",children:[u.jsx(ue.Server,{className:"h-5 w-5"}),"API Configuration"]})}),u.jsxs(wo,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(rn,{htmlFor:"api-url",children:"API Base URL"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(Js,{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(nt,{variant:"outline",onClick:g,children:"Test"})]})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(rn,{htmlFor:"enable-auth",children:"Enable Authentication"}),u.jsx(Wn,{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(rn,{htmlFor:"auth-token",children:"Authentication Token"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(Js,{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(nt,{variant:"outline",size:"icon",onClick:()=>i(!s),children:s?u.jsx(ue.EyeOff,{className:"h-4 w-4"}):u.jsx(ue.Eye,{className:"h-4 w-4"})})]})]})]})]}),u.jsxs(yo,{children:[u.jsx(vo,{className:"pb-3",children:u.jsxs(bo,{className:"text-lg flex items-center gap-2",children:[u.jsx(ue.Layout,{className:"h-5 w-5"}),"Interface Settings"]})}),u.jsxs(wo,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(rn,{htmlFor:"layout",children:"Layout Style"}),u.jsxs(cm,{value:a.ui.layout,onValueChange:y=>l(x=>({...x,ui:{...x.ui,layout:y}})),children:[u.jsx(hl,{children:u.jsx(um,{})}),u.jsxs(ml,{children:[u.jsx(ur,{value:"sidebar",children:"Sidebar Layout"}),u.jsx(ur,{value:"fullscreen",children:"Fullscreen"}),u.jsx(ur,{value:"tabs",children:"Tabbed Interface"})]})]})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx(rn,{htmlFor:"theme",children:"Theme"}),u.jsxs(cm,{value:a.ui.theme,onValueChange:y=>l(x=>({...x,ui:{...x.ui,theme:y}})),children:[u.jsx(hl,{children:u.jsx(um,{})}),u.jsxs(ml,{children:[u.jsx(ur,{value:"light",children:"Light"}),u.jsx(ur,{value:"dark",children:"Dark"}),u.jsx(ur,{value:"system",children:"System"})]})]})]}),u.jsx(gm,{}),u.jsxs("div",{className:"space-y-3",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(rn,{htmlFor:"show-timestamps",children:"Show Timestamps"}),u.jsx(Wn,{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(rn,{htmlFor:"show-agent-names",children:"Show Agent Names"}),u.jsx(Wn,{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(rn,{htmlFor:"compact-messages",children:"Compact Messages"}),u.jsx(Wn,{id:"compact-messages",checked:a.ui.compactMessages,onCheckedChange:y=>l(x=>({...x,ui:{...x.ui,compactMessages:y}}))})]})]})]})]}),u.jsxs(yo,{children:[u.jsx(vo,{className:"pb-3",children:u.jsxs(bo,{className:"text-lg flex items-center gap-2",children:[u.jsx(ue.MessageCircle,{className:"h-5 w-5"}),"Behavior Settings"]})}),u.jsxs(wo,{className:"space-y-4",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(rn,{htmlFor:"auto-save",children:"Auto-save Conversations"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Automatically save messages to threads"})]}),u.jsx(Wn,{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(rn,{htmlFor:"enable-streaming",children:"Enable Streaming"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Stream responses in real-time"})]}),u.jsx(Wn,{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(rn,{htmlFor:"typing-indicator",children:"Typing Indicator"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Show typing indicator during responses"})]}),u.jsx(Wn,{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(nt,{variant:"outline",onClick:h,children:[u.jsx(ue.RotateCcw,{className:"h-4 w-4 mr-2"}),"Reset"]}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(nt,{variant:"outline",onClick:v,children:"Cancel"}),u.jsxs(nt,{onClick:p,disabled:!c,children:[u.jsx(ue.Save,{className:"h-4 w-4 mr-2"}),"Save Changes"]})]})]})]})]})}function Uk({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(Ko,{...s,onThreadChange:l,children:u.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:u.jsx(Xs,{className:"flex-1",onError:s.onError,enableFileUpload:!0})})}):e==="tabs"?u.jsx(Ko,{...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(al,{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(Xs,{onError:s.onError,enableFileUpload:!0})})]})})}):u.jsx(Ko,{...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(al,{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(Xs,{onError:s.onError,enableFileUpload:!0})})]})})}Ae.ChatApi=cc,Ae.ChatInput=$c,Ae.ChatInterface=Xs,Ae.ChatProviders=Ko,Ae.ChatSettings=zk,Ae.MarkdownContent=xo,Ae.MessageComponent=Ys,Ae.MessageList=Ya,Ae.ThreadManager=al,Ae.TimelineColumn=UT,Ae.applySettings=qT,Ae.buildMessagePreviewMap=lx,Ae.chatApiClient=jn,Ae.default=Uk,Ae.del=Ci,Ae.get=Wt,Ae.getChatToken=ic,Ae.getCurrentSettings=KT,Ae.getDefaultApiConfig=wh,Ae.getDefaultChatSettings=Sh,Ae.onChatTokenChanged=ac,Ae.post=Fo,Ae.put=lc,Ae.setChatToken=$o,Ae.useApi=Ti,Ae.useChatStream=_c,Ae.useMessagesReducer=Ac,Ae.useStream=Dc,Ae.useThreadState=Vo,Ae.useThreads=Wo,Object.defineProperties(Ae,{__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=Ch(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=Ch(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 Nh{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 Ah{constructor(){this.seen={}}serialize(t){return t.toLowerCase().trim().replace(/<[!\/a-z].*?>/ig,"").replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g,"").replace(/\s/g,"-")}getNextSafeSlug(t,n){let r=t,o=0;if(this.seen.hasOwnProperty(r)){o=this.seen[t];do o++,r=t+"-"+o;while(this.seen.hasOwnProperty(r))}return n||(this.seen[t]=o,this.seen[r]=0),r}slug(t,n={}){const r=this.serialize(t);return this.getNextSafeSlug(r,n.dryrun)}}class $n{constructor(t){this.options=t||or,this.options.renderer=this.options.renderer||new Va,this.renderer=this.options.renderer,this.renderer.options=this.options,this.textRenderer=new Nh,this.slugger=new Ah}static parse(t,n){return new $n(n).parse(t)}static parseInline(t,n){return new $n(n).parseInline(t)}parse(t,n=!0){let r="",o,s,i,a,l,c,d,f,h,p,v,g,y,x,b,C,k,S,T;const E=t.length;for(o=0;o<E;o++){if(p=t[o],this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[p.type]&&(T=this.options.extensions.renderers[p.type].call({parser:this},p),T!==!1||!["space","hr","heading","code","table","blockquote","list","html","paragraph","text"].includes(p.type))){r+=T||"";continue}switch(p.type){case"space":continue;case"hr":{r+=this.renderer.hr();continue}case"heading":{r+=this.renderer.heading(this.parseInline(p.tokens),p.depth,Sh(this.parseInline(p.tokens,this.textRenderer)),this.slugger);continue}case"code":{r+=this.renderer.code(p.text,p.lang,p.escaped);continue}case"table":{for(f="",d="",a=p.header.length,s=0;s<a;s++)d+=this.renderer.tablecell(this.parseInline(p.header[s].tokens),{header:!0,align:p.align[s]});for(f+=this.renderer.tablerow(d),h="",a=p.rows.length,s=0;s<a;s++){for(c=p.rows[s],d="",l=c.length,i=0;i<l;i++)d+=this.renderer.tablecell(this.parseInline(c[i].tokens),{header:!1,align:p.align[i]});h+=this.renderer.tablerow(d)}r+=this.renderer.table(f,h);continue}case"blockquote":{h=this.parse(p.tokens),r+=this.renderer.blockquote(h);continue}case"list":{for(v=p.ordered,g=p.start,y=p.loose,a=p.items.length,h="",s=0;s<a;s++)b=p.items[s],C=b.checked,k=b.task,x="",b.task&&(S=this.renderer.checkbox(C),y?b.tokens.length>0&&b.tokens[0].type==="paragraph"?(b.tokens[0].text=S+" "+b.tokens[0].text,b.tokens[0].tokens&&b.tokens[0].tokens.length>0&&b.tokens[0].tokens[0].type==="text"&&(b.tokens[0].tokens[0].text=S+" "+b.tokens[0].tokens[0].text)):b.tokens.unshift({type:"text",text:S}):x+=S),x+=this.parse(b.tokens,y),h+=this.renderer.listitem(x,k,C);r+=this.renderer.list(h,v,g);continue}case"html":{r+=this.renderer.html(p.text);continue}case"paragraph":{r+=this.renderer.paragraph(this.parseInline(p.tokens));continue}case"text":{for(h=p.tokens?this.parseInline(p.tokens):p.text;o+1<E&&t[o+1].type==="text";)p=t[++o],h+=`
|
|
135
|
+
`+(p.tokens?this.parseInline(p.tokens):p.text);r+=n?this.renderer.paragraph(h):h;continue}default:{const j='Token with "'+p.type+'" type was not found.';if(this.options.silent){console.error(j);return}else throw new Error(j)}}}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 Hs{constructor(t){this.options=t||or}preprocess(t){return t}postprocess(t){return t}}Nm(Hs,"passThroughHooks",new Set(["preprocess","postprocess"]));function HC(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>"+Dt(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 jh(e,t){return(n,r,o)=>{typeof r=="function"&&(o=r,r=null);const s={...r};r={...ve.defaults,...s};const i=HC(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(BC(r),r.hooks&&(r.hooks.options=r),o){const a=r.highlight;let l;try{r.hooks&&(n=r.hooks.preprocess(n)),l=e(n,r)}catch(f){return i(f)}const c=function(f){let h;if(!f)try{r.walkTokens&&ve.walkTokens(l,r.walkTokens),h=t(l,r),r.hooks&&(h=r.hooks.postprocess(h))}catch(p){f=p}return r.highlight=a,f?i(f):o(null,h)};if(!a||a.length<3||(delete r.highlight,!l.length))return c();let d=0;ve.walkTokens(l,function(f){f.type==="code"&&(d++,setTimeout(()=>{a(f.text,f.lang,function(h,p){if(h)return c(h);p!=null&&p!==f.text&&(f.text=p,f.escaped=!0),d--,d===0&&c()})},0))}),d===0&&c();return}if(r.async)return Promise.resolve(r.hooks?r.hooks.preprocess(n):n).then(a=>e(a,r)).then(a=>r.walkTokens?Promise.all(ve.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&&ve.walkTokens(a,r.walkTokens);let l=t(a,r);return r.hooks&&(l=r.hooks.postprocess(l)),l}catch(a){return i(a)}}}function ve(e,t,n){return jh(Ln.lex,$n.parse)(e,t,n)}ve.options=ve.setOptions=function(e){return ve.defaults={...ve.defaults,...e},IC(ve.defaults),ve},ve.getDefaults=yh,ve.defaults=or,ve.use=function(...e){const t=ve.defaults.extensions||{renderers:{},childTokens:{}};e.forEach(n=>{const r={...n};if(r.async=ve.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=ve.defaults.renderer||new Va;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=ve.defaults.tokenizer||new Wa;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=ve.defaults.hooks||new Hs;for(const s in n.hooks){const i=o[s];Hs.passThroughHooks.has(s)?o[s]=a=>{if(ve.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=ve.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}}ve.setOptions(r)})},ve.walkTokens=function(e,t){let n=[];for(const r of e)switch(n=n.concat(t.call(ve,r)),r.type){case"table":{for(const o of r.header)n=n.concat(ve.walkTokens(o.tokens,t));for(const o of r.rows)for(const s of o)n=n.concat(ve.walkTokens(s.tokens,t));break}case"list":{n=n.concat(ve.walkTokens(r.items,t));break}default:ve.defaults.extensions&&ve.defaults.extensions.childTokens&&ve.defaults.extensions.childTokens[r.type]?ve.defaults.extensions.childTokens[r.type].forEach(function(o){n=n.concat(ve.walkTokens(r[o],t))}):r.tokens&&(n=n.concat(ve.walkTokens(r.tokens,t)))}return n},ve.parseInline=jh(Ln.lexInline,$n.parseInline),ve.Parser=$n,ve.parser=$n.parse,ve.Renderer=Va,ve.TextRenderer=Nh,ve.Lexer=Ln,ve.lexer=Ln.lex,ve.Tokenizer=Wa,ve.Slugger=Ah,ve.Hooks=Hs,ve.parse=ve,ve.options,ve.setOptions,ve.use,ve.walkTokens,ve.parseInline,$n.parse,Ln.lex;function co({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 ve.parse=="function"?ve.parse(i):ve(i)}return typeof ve.parse=="function"?ve.parse(e):ve(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:oe("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 WC={MODE:"library"};function VC(){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:ii&&ii.tagName.toUpperCase()==="SCRIPT"&&ii.src||new URL("index.umd.js",document.baseURI).href}<"u"?WC: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 KC(){return!VC()}function qC(){return typeof window>"u"?!1:window.__ARTIFACT_DEBUG__===!0}function GC(){return KC()||qC()}function YC({preview:e,idx:t}){return w.useEffect(()=>{GC()&&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 uo=m.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:oe("rounded-lg border bg-card text-card-foreground shadow-sm",e),...t}));uo.displayName="Card";const fo=m.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:oe("flex flex-col space-y-1.5 p-6",e),...t}));fo.displayName="CardHeader";const ho=m.forwardRef(({className:e,...t},n)=>u.jsx("h3",{ref:n,className:oe("text-2xl font-semibold leading-none tracking-tight",e),...t}));ho.displayName="CardTitle";const _h=m.forwardRef(({className:e,...t},n)=>u.jsx("p",{ref:n,className:oe("text-sm text-muted-foreground",e),...t}));_h.displayName="CardDescription";const po=m.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:oe("p-6 pt-0",e),...t}));po.displayName="CardContent";const Mh=m.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:oe("flex items-center p-6 pt-0",e),...t}));Mh.displayName="CardFooter";function XC({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=so(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(uo,{className:oe("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(fo,{className:"pb-3",children:[u.jsx(ho,{className:"text-blue-900 dark:text-blue-100 text-base",children:i}),u.jsx(_h,{className:"text-blue-700 dark:text-blue-300 text-sm",children:l})]}),a&&u.jsx(po,{className:"pt-0 pb-3",children:a}),u.jsx(Mh,{className:"pt-0",children:u.jsxs("div",{className:"flex gap-2 ml-auto",children:[u.jsx(et,{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(et,{size:"sm",onClick:()=>t(e),className:"bg-blue-600 hover:bg-blue-700 text-white",disabled:r||!o,children:"Approve"})]})})]})}const JC="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 Rh({data:e}){return Array.isArray(e)?e.every(n=>n===null||["string","number","boolean"].includes(typeof n))?u.jsx("div",{className:JC,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:so(e)}):u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:so(e)})}function ZC({message:e,isStreaming:t=!1}){const n=e.name??"tool",r=w.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(ae.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 QC({message:e,viewMode:t,isStreaming:n=!1}){const o=Gf(e).name||"tool",s=l=>{if(l==null)return null;const c=typeof l=="string"?Ma(l)??l:l;if(c&&typeof c=="object")return u.jsx(Rh,{data:c});const d=typeof c=="string"?c:(()=>{try{return so(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}=QS(l);return d?u.jsx(co,{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 h=(l.text??"").trim();if(!h)return null;const p=Rs(h);return i(p)}const c=oo(l),d=Rs(c);return i(d)};return u.jsxs("div",{className:"space-y-2",children:[u.jsx(ZC,{message:e,isStreaming:n}),t==="expanded"&&a()]})}function eT(e){const{allowFileOpen:t,currentThreadId:n}=e,{toast:r}=Ha(),[o,s]=w.useState({}),[i,a]=w.useState(null),[l,c]=w.useState(!1),d=w.useCallback(()=>{c(!1),a(null)},[]),f=w.useCallback(p=>{a(p),c(!0)},[]),h=w.useCallback(async(p,v,g)=>{var y,x;if(!t){p.preventDefault();return}if(o[g]){p.preventDefault();return}try{const b=String(v.url??""),C=b.match(/\/chat\/files\/([^/]+)(?:\/(view|download))?/);if(C){p.preventDefault();const k=C[1],S=v.name||`file_${k}`,T=v.mimeType||"application/octet-stream";f({id:k,name:S,mimeType:T});return}if(b.startsWith("data:")){p.preventDefault(),s(S=>({...S,[g]:!0}));const k=r({title:"Fetching file...",description:"",open:!0});try{const S=await lC(n??void 0);if(!S||!Array.isArray(S))throw new Error("Invalid file list response");const T=S.find(E=>!E||typeof E!="object"||!((E.filename??"")===(v.name??""))?!1:typeof v.size=="number"&&typeof E.size=="number"?E.size===v.size:!0);if(!(T!=null&&T.id))throw new Error(`File "${v.name}" is not yet available on the server`);if(!T.id||!T.filename)throw new Error("Invalid file data received from server");f({id:T.id,name:v.name||T.filename||`file_${T.id}`,mimeType:v.mimeType||T.mime_type||"application/octet-stream"}),(y=k.update)==null||y.call(k,{id:k.id,title:"Success",description:`Opened ${v.name}`,open:!0})}catch(S){console.error("Failed to fetch server file:",S);const T=S instanceof Error?S.message:"Unknown error occurred";(x=k.update)==null||x.call(k,{id:k.id,title:"Failed",description:T}),r({title:"Failed to fetch file",description:T,open:!0})}finally{s(S=>({...S,[g]:!1}))}}}catch(b){console.error("File click error:",b),s(C=>({...C,[g]:!1}))}},[t,o,r,n,f]);return{uploadingFiles:o,handleFileClick:h,fileViewerOpen:l,currentFileInfo:i,closeFileViewer:d}}function tT({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:oe("text-sm text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:t?u.jsx(co,{content:e,allowHtml:!1}):u.jsxs("pre",{className:oe("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(et,{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(ae.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):u.jsxs(u.Fragment,{children:[u.jsx(ae.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more (",s," chars)"]})})]})}function nT({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:oe("inline-block text-xs opacity-70 ml-1",e),children:["Is thinking",".".repeat(t)]})}function Ph(e){var n;const t=(n=e.additionalKwargs)==null?void 0:n.toolProgress;return Array.isArray(t)?t:[]}const Ws=w.memo(function({message:t,messageIndex:n,isStreamingMessage:r=!1,isEditing:o=!1,showActions:s=!0,showTimestamp:i=!0,showAgentName:a=!0,layoutSize:l="desktop",truncateUserMessages:c=!0,userMessagePreviewLength:d=500,showToolMessages:f=!0,showArtifactPreviews:h=!0,customStyles:p={},onEdit:v,onRegenerate:g,onCancelEdit:y,onCopy:x,activeInterrupt:b,disableInterruptActions:C=!1,onInterruptActionStart:k,onInterruptActionEnd:S,checkpointCandidates:T=[],activeCheckpointId:E=null,onSelectCheckpoint:j,defaultCheckpointId:R=null,messageParentCheckpointId:O=null}){const[B,q]=w.useState(!1),[K,P]=w.useState("preview"),[M,I]=w.useState(!1),{currentThreadId:z}=Fo(),{respondToInterrupt:L}=Bo(),A=l==="phone"||l==="half-screen",$=t.role,H=$==="tool",_=w.useMemo(()=>"type"in t&&t.type==="default_message"?t:null,[t]),G=!!_,re=!(r&&$!=="user"),{uploadingFiles:ee,handleFileClick:ie,fileViewerOpen:Y,currentFileInfo:D,closeFileViewer:V}=eT({allowFileOpen:re,currentThreadId:z}),U=w.useMemo(()=>{switch($){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=w.useMemo(()=>{if(_)return"";const X=t.content;return Array.isArray(X)?eC(X):""},[_,t]),J=w.useMemo(()=>{if(_)return{};const X=t.content;return Array.isArray(X)?Gf(t):{}},[_,t]),ge=w.useMemo(()=>H?!!(t.additionalKwargs??{}).toolStreaming:!1,[H,t]),ce=w.useMemo(()=>{if(_)return[];const X=t.content;return Array.isArray(X)?X.filter(ye=>ye.type==="image_url"):[]},[_,t]),ne=w.useMemo(()=>{if(_)return[];const X=t.content;return Array.isArray(X)?X.filter(ye=>ye.type==="file"):[]},[_,t]),pe=w.useMemo(()=>{if(_)return[];const X=t.content;return Array.isArray(X)?X.filter(ye=>ye.type==="interrupt"):[]},[_,t]),be=(b==null?void 0:b.id)??(b==null?void 0:b.interrupt_id),De=Ps(be),je=b==null?void 0:b.value,He=w.useMemo(()=>{if(_)return"";const X=t.content;return Array.isArray(X)?tC(X):""},[_,t]),qe=w.useMemo(()=>{if(_||!h)return[];const ye=t.artifact;if(!ye)return[];const Ce=[],Je=[...Array.isArray(ye.plots)?ye.plots:[]];for(const Be of Je){const xt=iC(Be);xt&&Ce.push(xt)}return Ce},[_,t,h]),rt=w.useCallback(async()=>{const X=H?He:Z;async function ye(Ce){if(navigator.clipboard&&typeof navigator.clipboard.writeText=="function"){await navigator.clipboard.writeText(Ce);return}if(navigator.clipboard&&typeof navigator.clipboard.write=="function"&&typeof ClipboardItem<"u"){const Je=new Blob([Ce],{type:"text/plain"});await navigator.clipboard.write([new ClipboardItem({"text/plain":Je})]);return}throw new Error("Clipboard API not supported in this context.")}try{await ye(X),q(!0),setTimeout(()=>q(!1),2e3),x==null||x(X)}catch(Ce){console.error("Failed to copy:",Ce)}},[H,He,Z,x]),Ge=w.useCallback(()=>{if(!v)return;const X=H?He:Z,ye="type"in t&&t.type==="default_message"?void 0:{checkpointId:t.checkpointId??null,checkpointNs:t.checkpointNs??null};v(t.id,X,ye)},[v,t.id,H,He,Z,t]),Qe=w.useCallback(()=>{g==null||g(n)},[g,n]),lt=w.useCallback(()=>{const ye=oe(A?"h-3 w-3":"h-4 w-4","opacity-60 flex-shrink-0",U);switch($){case"user":return u.jsx(ae.User,{className:ye});case"assistant":return u.jsx(ae.Bot,{className:ye});case"tool":return u.jsx(ae.Wrench,{className:ye});default:return u.jsx(ae.Bot,{className:ye})}},[A,U,$]),Re=w.useCallback(()=>{const X="group relative mb-4 flex w-full";switch($){case"user":return oe(X,"justify-end");case"assistant":case"tool":case"system":return oe(X,"justify-start");default:return X}},[$]),Le=w.useCallback(()=>{const X=oe("rounded-lg px-4 py-3 relative min-w-0 max-w-full break-words",A&&"px-3 py-2 text-sm");if(G)return oe(X,"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($){case"user":return oe(X,"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 oe(X,"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 oe(X,"w-full md:max-w-[95%] bg-secondary/50 text-secondary-foreground border border-dashed");case"system":return oe(X,"w-full md:max-w-[85%] bg-accent/40 text-muted-foreground border");default:return oe(X,"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")}},[A,G,$]),ct=w.useCallback(async X=>{if(C)return;const ye=Ps((X==null?void 0:X.id)??(X==null?void 0:X.interrupt_id));if(!ye){console.warn("Interrupt part missing id",X);return}try{k==null||k(),await L(ye,!0)}catch(Ce){console.error("Failed to approve interrupt:",Ce)}finally{S==null||S()}},[C,S,k,L]),ot=w.useCallback(async X=>{if(C)return;const ye=Ps((X==null?void 0:X.id)??(X==null?void 0:X.interrupt_id));if(!ye){console.warn("Interrupt part missing id",X);return}try{k==null||k(),await L(ye,!1)}catch(Ce){console.error("Failed to reject interrupt:",Ce)}finally{S==null||S()}},[C,S,k,L]),pt=w.useCallback(({part:X,i:ye})=>{if(X.type==="text"){const Ce=X.text??"",Je=Ce.trim(),Be=Ma(Je);return Be&&$!=="tool"?u.jsx(Rh,{data:Be},ye):$==="user"&&c&&Je.length>d?u.jsx(tT,{text:Je,expanded:M,onExpandedChange:I,previewLength:d,isCompact:A},ye):u.jsx(co,{content:Ce,allowHtml:!1},ye)}if(X.type==="image_url"){const Ce=X;return u.jsx("div",{className:"my-2",children:u.jsx("img",{src:Ce.url,alt:Ce.alt??"",loading:"lazy",className:"border rounded max-h-[420px] w-auto object-contain"})},ye)}if(X.type==="file"){const Ce=X,Je=Ce.name||"file";return u.jsxs("a",{href:Ce.url,onClick:Be=>ie(Be.nativeEvent,Ce,ye),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:[ee[ye]?u.jsx(ae.Loader,{className:"h-4 w-4 animate-spin"}):null,u.jsxs("span",{className:"truncate max-w-[180px]",children:[Je,ee[ye]?" (processing)":""]})]},ye)}if(X.type==="interrupt"){const Ce=X,Je=Ps((Ce==null?void 0:Ce.id)??(Ce==null?void 0:Ce.interrupt_id)),Be=!!(De&&Je&&Je===De),xt=Be?je??(Ce==null?void 0:Ce.value):Ce==null?void 0:Ce.value,nt=Je?{...Ce,id:Je,interrupt_id:Je}:Ce;return u.jsx(XC,{interruptPart:nt,onApprove:ct,onReject:ot,disabled:C,isActive:Be,payload:xt},ye)}return null},[ie,ee,ct,ot,$,c,d,M,A,De,je,b,C,pe]),mt=w.useCallback(()=>u.jsxs("div",{className:"flex items-center gap-2 p-2 bg-muted/30 rounded",children:[u.jsx(ae.Paperclip,{className:"h-4 w-4 text-muted-foreground"}),u.jsx("span",{className:"text-sm text-muted-foreground",children:"File upload"})]}),[]),kt=w.useCallback(()=>{const X=Z.trim().length>0||ce.length>0||ne.length>0||pe.length>0;if(!H&&ne.length>0&&!r)return mt();if(!H&&!X&&!r)return null;if(H)return!f&&qe.length>0?null:f?u.jsx(QC,{message:t,viewMode:K,isStreaming:ge},t.id):null;if(!H&&!_){const ye=t,Ce=u.jsx("div",{className:"space-y-2",children:ye.content.map((Je,Be)=>u.jsx(pt,{part:Je,i:Be},Be))});return r?u.jsxs("div",{"aria-busy":"true",role:"status",children:[Ce,u.jsx(nT,{className:U})]}):Ce}},[Z,ce.length,ne.length,pe.length,r,H,K,f,qe.length,mt,U]),At=w.useMemo(()=>_?"Assistant":nC(t),[_,t]),Fe=w.useMemo(()=>_?[]:Array.isArray(T)?T:[],[T,_]),fn=w.useMemo(()=>{var X;return Fe.length?R&&Fe.some(ye=>ye.id===R)?R:((X=Fe[0])==null?void 0:X.id)??null:null},[R,Fe]),le=w.useMemo(()=>!Fe.length||!E?null:Fe.some(X=>X.id===E)?E:null,[E,Fe])??fn,Pe=$==="user"&&Fe.length>0&&typeof j=="function",wt=w.useCallback((X,ye=!1)=>{if(!j)return;const Ce=(X==null?void 0:X.id)??null,Je=(X==null?void 0:X.parentId)??O??null;j(Ce,Je,ye)},[O,j]),We=w.useMemo(()=>le?Fe.findIndex(X=>X.id===le):-1,[le,Fe]),Tt=w.useMemo(()=>We<0?null:Fe[We]??null,[We,Fe]);return H&&!f&&qe.length===0?null:G&&_?u.jsx("div",{className:oe(Re(),p.container),children:u.jsxs("div",{className:oe(Le(),p.content),children:[u.jsxs("div",{className:"flex items-center gap-2 mb-2 pb-2 border-b border-current/10",children:[u.jsx(ae.Bot,{className:oe("h-4 w-4",U)}),a&&u.jsx("span",{className:"font-medium text-sm",children:"Assistant"})]}),u.jsx(co,{content:_.content,className:"text-current"})]})}):u.jsxs(u.Fragment,{children:[u.jsx("div",{className:oe(Re(),p.container),children:u.jsxs("div",{className:oe(Le(),p.content),children:[(i||a||H)&&u.jsxs("div",{className:oe("flex items-center justify-between mb-2 pb-2 border-b border-current/10",A&&"mb-1 pb-1",U,p.header),children:[u.jsxs("div",{className:"flex items-center gap-2",children:[lt(),a&&At&&u.jsx("span",{className:oe("font-medium",A?"text-xs":"text-sm"),children:At}),H&&u.jsxs(Kf,{variant:"outline",className:oe("text-xs flex items-center gap-1 cursor-pointer select-none",U,"border border-current/40",A&&"text-xs h-4"),role:"button",tabIndex:0,"aria-expanded":K==="expanded",onClick:()=>P(X=>X==="expanded"?"preview":"expanded"),onKeyDown:X=>{(X.key==="Enter"||X.key===" ")&&(X.preventDefault(),P(ye=>ye==="expanded"?"preview":"expanded"))},children:[u.jsx("span",{children:J.name??"Tool Output"}),J.toolCallId&&u.jsx("span",{className:"opacity-70",children:J.toolCallId.slice(0,8)}),K==="expanded"?u.jsx(ae.ChevronUp,{className:"h-3 w-3"}):u.jsx(ae.ChevronDown,{className:"h-3 w-3"})]})]}),u.jsxs("div",{className:"flex items-center gap-2",children:[Pe&&Tt&&We>=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:oe("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",We<Fe.length-1?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(We>=Fe.length-1)return;const X=Fe[We+1];X&&wt(X)},"aria-label":"Older checkpoint (back in time)",disabled:We>=Fe.length-1,children:u.jsx(ae.ChevronLeft,{className:"h-3 w-3"})}),u.jsx("div",{className:"flex items-center gap-2",children:u.jsxs("span",{className:"whitespace-nowrap",children:[Fe.length-We," / ",Fe.length]})}),u.jsx("button",{type:"button",className:oe("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",We>0?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(!(We<=0))if(We===1)wt(null,!0);else{const X=Fe[We-1];X&&wt(X,!1)}},"aria-label":"Newer checkpoint (forward in time)",disabled:We<=0,children:u.jsx(ae.ChevronRight,{className:"h-3 w-3"})})]})}),i&&t.createdAt&&u.jsx("time",{className:oe("text-xs opacity-60",U,A&&"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:oe("opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",p.actions),children:[u.jsx("div",{className:"relative",children:u.jsx(et,{variant:"ghost",size:"sm",onClick:()=>rt(),className:oe("h-6 w-6 p-0 hover:bg-foreground/10",U,A&&"h-5 w-5"),"aria-label":"Copy message",title:"Copy message",children:u.jsx(ae.Copy,{className:oe(B?"text-success":U,A?"h-3 w-3":"h-4 w-4")})})}),$==="user"&&v&&u.jsx(et,{variant:"ghost",size:"sm",onClick:Ge,className:oe("h-6 w-6 p-0 hover:bg-foreground/10",U,A&&"h-5 w-5"),"aria-label":"Edit message",children:u.jsx(ae.Edit,{className:oe(U,A?"h-3 w-3":"h-4 w-4")})}),$==="assistant"&&g&&u.jsx(et,{variant:"ghost",size:"sm",onClick:Qe,className:oe("h-6 w-6 p-0 hover:bg-foreground/10",U,A&&"h-5 w-5"),"aria-label":"Regenerate response",children:u.jsx(ae.RotateCcw,{className:oe(U,A?"h-3 w-3":"h-4 w-4")})})]})]})]}),u.jsxs("div",{className:"relative",children:[kt(),h&&qe.length>0&&u.jsx("div",{className:"mt-3 space-y-4",children:qe.map((X,ye)=>u.jsx(YC,{preview:X,idx:ye},`artifact-${ye}`))})]}),H&&K==="expanded"&&(J.toolCallId||J.name)&&u.jsxs("div",{className:oe("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",A&&"text-xs"),children:[J.name&&u.jsxs("div",{children:["Function: ",J.name]}),J.toolCallId&&u.jsxs("div",{children:["Call ID: ",J.toolCallId]})]}),!(i||a||H)&&s&&!o&&u.jsxs("div",{className:oe("absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",p.actions),children:[u.jsx(et,{variant:"ghost",size:"sm",onClick:()=>rt(),className:oe("h-6 w-6 p-0 hover:bg-background/50 text-current",A&&"h-5 w-5"),children:u.jsx(ae.Copy,{className:oe(B?"text-success":"text-current",A?"h-3 w-3":"h-4 w-4")})}),$==="user"&&v&&u.jsx(et,{variant:"ghost",size:"sm",onClick:Ge,className:oe("h-6 w-6 p-0 hover:bg-background/50 text-current",A&&"h-5 w-5"),children:u.jsx(ae.Edit,{className:oe("text-current",A?"h-3 w-3":"h-4 w-4")})}),$==="assistant"&&g&&u.jsx(et,{variant:"ghost",size:"sm",onClick:Qe,className:oe("h-6 w-6 p-0 hover:bg-background/50 text-current",A&&"h-5 w-5"),children:u.jsx(ae.RotateCcw,{className:oe("text-current",A?"h-3 w-3":"h-4 w-4")})})]})]})}),D&&u.jsx(EC,{isOpen:Y,onClose:V,fileId:D.id,fileName:D.name,mimeType:D.mimeType})]})},(e,t)=>{var l,c,d,f,h,p,v,g;if(t.isStreamingMessage||e.isStreamingMessage||!(e.message.id===t.message.id&&Yf(e.message)===Yf(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)&&((h=e.customStyles)==null?void 0:h.actions)===((p=t.customStyles)==null?void 0:p.actions)&&((v=e.customStyles)==null?void 0:v.header)===((g=t.customStyles)==null?void 0:g.header);if(!o||!s)return!1;const i=Ph(e.message),a=Ph(t.message);return i.length===a.length});Ws.displayName="MessageComponent";function rT(e,t){return w.useMemo(()=>{var d,f,h,p,v;const n=e&&"type"in e&&e.type==="default_message";let r=[],o=null,s={},i={},a=null,l=null,c=null;if(!n&&e){const g=e,y=g.checkpointId??null;s=g.additionalKwargs??{},i=g.responseMetadata??{};const x=y&&t.checkpointMetaById?t.checkpointMetaById.get(y)??null:null;a=typeof s.step=="number"?s.step:typeof i.step=="number"?i.step:(x==null?void 0:x.step)??null;const b=typeof s.source=="string"?s.source:typeof i.source=="string"?i.source:(x==null?void 0:x.source)??null;l=b?String(b):null;const C=a!==null&&l?`${a}:${l}`:null;if(C&&((d=t.checkpointIndexByKey)!=null&&d.has(C))?r=t.checkpointIndexByKey.get(C)??[]:y&&x&&(r=[x]),o=y??((f=r[0])==null?void 0:f.id)??null,c=y?((h=t.attemptMetaById)==null?void 0:h.get(y))??null:null,!c&&(e==null?void 0:e.role)==="user"&&(e!=null&&e.id)&&t.userMessageIdToAttempts){const k=t.userMessageIdToAttempts.get(e.id);if(k&&k.length>0){const S=k[0].checkpointId;c=((p=t.attemptMetaById)==null?void 0:p.get(S))??null,c&&console.log(`[useMessageMetadata] Found attempt by user message ID "${e.id}":`,k.length,"versions")}}if(!c&&r.length>0&&t.attemptMetaById){const k=t.attemptMetaById.get(r[0].id);k&&(c=k)}if(c&&c.attemptCount>1&&t.attemptMetaById){const k=c.baseUserMessageId;if(k){const S=[];for(const[T,E]of t.attemptMetaById.entries())if(E.baseUserMessageId===k){const j=(v=t.checkpointMetaById)==null?void 0:v.get(T);j&&S.push(j)}S.length>0&&(r=S)}}if(c&&c.attemptCount>1&&t.checkpointMetaById&&t.attemptMetaById){const k=[];for(const[S,T]of t.checkpointMetaById.entries()){const E=t.attemptMetaById.get(S);E&&E.attemptCount===c.attemptCount&&E.baseUserMessageId===c.baseUserMessageId&&k.push(T)}k.sort((S,T)=>{const E=S.createdAt?Date.parse(S.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(S=>S.id)}))}}return{checkpointCandidates:r,defaultCheckpointId:o,attemptMeta:c,resolvedStep:a,resolvedSource:l}},[e,t.checkpointMetaById,t.checkpointIndexByKey,t.attemptMetaById,t.userMessageIdToAttempts])}const Oh=(e,t)=>(e==null?void 0:e.id)??`message-${t}`,Dh=w.memo(function({message:t,index:n,isStreaming:r,streamingAssistantId:o,streamingDebounceMs:s,layoutSize:i,enableMessageEditing:a,editingMessageId:l,onEdit:c,onRegenerate:d,onCancelEdit:f,activeInterrupt:h,disableInterruptActions:p,onInterruptActionStart:v,onInterruptActionEnd:g,showToolMessages:y,showArtifactPreviews:x,checkpointMetaById:b,checkpointIndexByKey:C,attemptMetaById:k,userMessageIdToAttempts:S,activeCheckpointId:T,onSelectCheckpoint:E}){const j=Oh(t,n),R="type"in t&&t.type==="default_message",{checkpointCandidates:O,defaultCheckpointId:B,attemptMeta:q}=rT(t,{checkpointMetaById:b,checkpointIndexByKey:C,attemptMetaById:k,userMessageIdToAttempts:S}),K=t&&!R?t.additionalKwargs??{}:{},P=t&&!R?t.responseMetadata??{}:{},M=(()=>{if(typeof K.parentCheckpointId=="string")return K.parentCheckpointId;if(typeof P.parentCheckpointId=="string")return P.parentCheckpointId})();return u.jsx("div",{className:"relative mb-4 last:mb-0","data-message-id":j,style:{minHeight:"60px",containIntrinsicSize:"auto 120px"},children:u.jsx(Ws,{message:t,messageIndex:n,isStreamingMessage:r&&o===t.id,streamingDebounceMs:s,isEditing:l===t.id,showActions:a,showTimestamp:!1,showAgentName:!0,layoutSize:i,onEdit:c,onRegenerate:()=>d(n),onCancelEdit:f,activeInterrupt:h,disableInterruptActions:p,onInterruptActionStart:v,onInterruptActionEnd:g,showToolMessages:y,showArtifactPreviews:x,checkpointCandidates:O,activeCheckpointId:T??null,onSelectCheckpoint:E,defaultCheckpointId:B,messageParentCheckpointId:M,attemptMeta:q})})});Dh.displayName="MessageRow";const Ka=w.forwardRef(({messages:e,isStreaming:t,streamingAssistantId:n,streamingDebounceMs:r,layoutSize:o,enableMessageEditing:s,editingMessageId:i,onStartReached:a,onEdit:l,onRegenerate:c,onCancelEdit:d,className:f,style:h,emptyMessage:p,followNewMessages:v=!0,isNavigatingCheckpoint:g=!1,onScrollAway:y,onAtBottom:x,activeInterrupt:b,disableInterruptActions:C=!1,onInterruptActionStart:k,onInterruptActionEnd:S,showToolMessages:T=!0,showArtifactPreviews:E=!0,checkpointMetaById:j,checkpointIndexByKey:R,attemptMetaById:O,userMessageIdToAttempts:B,activeCheckpointId:q,onSelectCheckpoint:K,createSyntheticThinkingMessage:P=!1},M)=>{const I=w.useRef(null),z=w.useRef(null),L=w.useRef(!1),A=w.useRef(!1),[$,H]=w.useState(!0),_=w.useMemo(()=>b?e.some(ne=>"type"in ne&&ne.type==="default_message"?!1:Array.isArray(ne==null?void 0:ne.content)&&ne.content.some(pe=>pe&&pe.type==="interrupt"&&(pe.id??pe.interrupt_id)===b.id)):!1,[b,e]),G=w.useMemo(()=>{if(!b||_)return null;const ne=b.id&&String(b.id).trim()?String(b.id).trim():"pending-interrupt";let pe;const be=b.value;if(be&&typeof be=="object"&&!Array.isArray(be)){const De=be.title;typeof De=="string"&&De.trim()&&(pe=De.trim())}return{id:`interrupt-${ne}`,role:"system",createdAt:new Date().toISOString(),content:[{type:"interrupt",id:ne,value:be,title:pe}]}},[b,_]),re=w.useMemo(()=>G?[...e,G]:e,[e,G]),ee=w.useMemo(()=>!P||!t?re:!re.some(pe=>pe.role==="assistant")&&re.length>0?[...re,{id:"thinking-assistant",role:"assistant",content:[],createdAt:new Date().toISOString()}]:re,[re,t,P]),ie=w.useMemo(()=>T?ee:ee.filter(ne=>(ne==null?void 0:ne.role)!=="tool"),[ee,T]),Y=w.useCallback(ne=>{H(ne),y&&y(!ne),x&&x(ne)},[y,x]),D=w.useMemo(()=>{if(a)return async()=>{if(!L.current){L.current=!0;try{await a()}finally{L.current=!1}}}},[a]),V=w.useMemo(()=>!v||g?!1:$?"auto":!1,[$,v,g]),U=w.useMemo(()=>{if(typeof p!="string")return null;const ne=p.trim();return ne?{id:"default-message",role:"assistant",type:"default_message",content:ne,createdAt:new Date().toISOString()}:null},[p]),Z=["flex h-full flex-col md:flex-row",f].filter(Boolean).join(" "),J=()=>U?u.jsx("div",{className:"p-6 h-full overflow-y-auto",children:u.jsx("div",{className:"w-full max-w-full",children:u.jsx(Ws,{message:U,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:p??"No messages yet. Start a conversation!"}),ge=ie.length,ce=ge>0;return w.useEffect(()=>{var ne,pe;if(ge===0){A.current=!1;return}if(!A.current)if(A.current=!0,I.current&&ie.length>0){const be=ie.length-1;(pe=(ne=I.current).scrollToIndex)==null||pe.call(ne,{index:be,align:"end",behavior:"auto"})}else z.current&&(z.current.scrollTop=z.current.scrollHeight)},[ge,ie.length]),w.useImperativeHandle(M,()=>({scrollToLatest:()=>{var ne,pe;if(I.current&&ie.length>0){const be=ie.length-1;(pe=(ne=I.current).scrollToIndex)==null||pe.call(ne,{index:be,align:"end",behavior:"auto"})}else z.current&&(z.current.scrollTop=z.current.scrollHeight)},scrollToTop:()=>{var ne,pe;I.current&&ie.length>0?(pe=(ne=I.current).scrollToIndex)==null||pe.call(ne,{index:0,align:"start",behavior:"auto"}):z.current&&(z.current.scrollTop=0)}}),[ie]),u.jsx("div",{className:Z,style:h,children:u.jsx("div",{className:"relative flex-1 min-h-0",children:ce?u.jsx(DS,{ref:ne=>{I.current=ne},scrollerRef:ne=>{z.current=ne instanceof HTMLDivElement?ne:null},data:ie,followOutput:V,overscan:200,increaseViewportBy:{top:100,bottom:200},defaultItemHeight:80,atBottomThreshold:50,startReached:()=>{D&&D()},atBottomStateChange:Y,style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:(ne,pe)=>Oh(pe,ne),itemContent:(ne,pe)=>u.jsx(Dh,{message:pe,index:ne,isStreaming:t,streamingAssistantId:n,streamingDebounceMs:r,layoutSize:o,enableMessageEditing:s,editingMessageId:i,onEdit:l,onRegenerate:c,onCancelEdit:d,activeInterrupt:b,disableInterruptActions:C,onInterruptActionStart:k,onInterruptActionEnd:S,showToolMessages:T,showArtifactPreviews:E,checkpointMetaById:j,checkpointIndexByKey:R,attemptMetaById:O,userMessageIdToAttempts:B,activeCheckpointId:q,onSelectCheckpoint:K})}):J()})})});Ka.displayName="MessageList";const Lh={value:""};function Vs({className:e="",placeholder:t="Type your message...",autoFocus:n=!0,maxHeight:r=void 0,streamingDebounceMs:o=500,streamingThrottleMs:s,followNewMessages:i=!0,enableFileUpload:a=!0,enableExcelUpload:l=!1,enableMessageEditing:c=!0,showToolMessages:d=!0,showArtifactPreviews:f=!0,customStyles:h={},onMessageSent:p,onExcelUploadSuccess:v,onError:g}){const{api:y}=wi(),{currentThreadId:x}=Fo(),{threadId:b,messages:C,isHistoryLoading:k,isLoading:S,navigateToCheckpoint:T,returnToLatest:E,checkpoint:j,checkpoints:R,interrupt:O,metadata:B,timelineCheckpoints:q,messagePreviews:K}=Bo(),{isStreaming:P,error:M,connectionState:I,submit:z,stop:L}=Dc(),A=b??x??null,$=(j==null?void 0:j.id)??null,H=(j==null?void 0:j.namespace)??null,_=(B==null?void 0:B.assemblingMessageId)??null,G=O,[re,ee]=w.useState(!1);w.useEffect(()=>{G||ee(!1)},[G]);const ie=w.useCallback(()=>{ee(!0)},[]),Y=w.useCallback(()=>{ee(!1)},[]),D=!!G||re,[V,U]=w.useState(null),[Z,J]=w.useState(""),[ge,ce]=w.useState(null),[ne,pe]=w.useState(null),[be,De]=w.useState([]),[je,He]=w.useState(0),[qe,rt]=w.useState(0),[Ge,Qe]=w.useState(!1),[lt,Re]=w.useState(null),[Le,ct]=w.useState(null),[ot,pt]=w.useState(!1),[mt,kt]=w.useState(null),At=w.useRef(!1),[Fe,fn]=w.useState(()=>Lh.value),W=w.useRef(Fe),le=w.useRef(null),Pe=w.useCallback(me=>{Lh.value=me,fn(me)},[]),[wt,We]=w.useState(!1),Tt=w.useRef(null),{checkpointMetaById:X,checkpointIndexByKey:ye,attemptMetaById:Ce,userMessageIdToAttempts:Je}=C0(R),Be=q??[],xt=w.useRef(null),nt=w.useRef(null),jt=w.useCallback(()=>{xt.current&&(xt.current.value=""),nt.current&&(nt.current.value=""),He(me=>me+1),rt(me=>me+1)},[]),yo=w.useCallback(me=>{Pe(me)},[Pe]),vo=w.useRef(!1);w.useEffect(()=>{vo.current&&!P&&(De([]),jt()),vo.current=P},[P,jt]);const[ri,hl]=w.useState("desktop");w.useEffect(()=>{const me=()=>{const Te=window.innerWidth;hl(Te<640?"phone":Te<1024?"tablet":"desktop")};return me(),window.addEventListener("resize",me),()=>window.removeEventListener("resize",me)},[]),w.useEffect(()=>{At.current=!1},[A]),w.useEffect(()=>{W.current=Fe},[Fe]),w.useEffect(()=>{if(!V){le.current=null;return}le.current===null&&(le.current=W.current),Pe(Z??"")},[Z,V,Pe]),w.useEffect(()=>{(async()=>{if(!y.baseUrl){kt(null);return}try{const Ae=(await y.getAgent("default")).uiDefaultMessage||"";kt(Ae||null)}catch(Te){console.warn("Failed to fetch default message:",Te),kt(null)}})()},[y.baseUrl]),w.useEffect(()=>{M&&!ot&&(g==null||g(M))},[M,ot,g]);const pl=me=>{if(me.length>vs)return`Message too long (${me.length}/${vs} characters)`;try{return E0(me),null}catch(Te){return(Te==null?void 0:Te.message)||"Invalid message"}},ml=async me=>{const Te=me.trim();if(!(!Te&&be.length===0)){if(Te){const Ae=pl(Te);if(Ae){pe(Ae);return}}try{const Ae=V?(ge==null?void 0:ge.checkpointId)??$??void 0:$??void 0,Ye=V?(ge==null?void 0:ge.checkpointNs)??H??void 0:H??void 0;await z({text:Te||"",attachments:be},{checkpointId:Ae,checkpointNs:Ye,edit:!!V,originalMessageId:V??void 0}),p==null||p(Te),Pe(""),pe(null),De([]),jt(),U(null),J(""),ce(null)}catch(Ae){const Ye=(Ae==null?void 0:Ae.message)||"Failed to send message";pe(Ye),g==null||g(Ye)}}},oi=w.useCallback((me,Te,Ae)=>{c&&(le.current=Fe,U(me),J(Te),Pe(Te),pe(null),ce({checkpointId:(Ae==null?void 0:Ae.checkpointId)??null,checkpointNs:(Ae==null?void 0:Ae.checkpointNs)??null}))},[Fe,c,Pe]),N=w.useCallback(()=>{U(null),J(""),ce(null),pe(null),Pe(le.current??Fe),le.current=null},[Fe,Pe]),te=w.useCallback((me,Te,Ae)=>{oi(me,Te,Ae)},[oi]),ue=w.useCallback(me=>{let Te=null;for(let rn=me-1;rn>=0;rn--)if(C[rn].role==="user"){Te=C[rn];break}if(!Te)return;const Ae=Array.isArray(Te.content)?Te.content:[],Hn=Ae.filter(rn=>(rn==null?void 0:rn.type)==="text").map(rn=>rn.text).join("")||(()=>{try{return JSON.stringify(Ae,null,2)}catch{return String(Ae)}})();Hn&&z({text:Hn},{checkpointId:$??void 0,checkpointNs:H??void 0,edit:!0,originalMessageId:Te.id})},[C,z,$,H]),Ie=me=>{const Te=Array.from(me.target.files||[]);De(Ae=>[...Ae,...Te]),me.target.value=""},Ze=me=>{De(Te=>{const Ae=Te.filter((Ye,Hn)=>me!==Hn);return Ae.length===0&&jt(),Ae})},st=async me=>{const Te=(me.target.files||[])[0];if(Te){Re(null),ct(null),Qe(!0);try{await z({attachments:[Te]},{checkpointId:$??void 0,checkpointNs:H??void 0});const Ae=`Uploaded ${Te.name} - processing through chat stream`;ct(Ae)}catch(Ae){const Ye=Ae instanceof Error?Ae.message:"Failed to upload Excel file";console.error("Excel upload failed",Ae),Re(Ye),g==null||g(Ye)}finally{Qe(!1),me.target.value="",jt()}}},Ue=async me=>{if(x){We(!0);try{if(!me){await E(),requestAnimationFrame(()=>{var Ye;(Ye=Tt.current)==null||Ye.scrollToLatest()});return}const Te=R.find(Ye=>Ye.checkpointId===me),Ae=(Te==null?void 0:Te.checkpointNs)??null;await T(me,Ae),requestAnimationFrame(()=>{var Ye;(Ye=Tt.current)==null||Ye.scrollToTop()})}finally{We(!1)}}},ze=w.useCallback(async(me,Te,Ae)=>{await Ue(Ae?null:me)},[Ue]),_t=`flex flex-1 w-full flex-col min-h-0 min-w-0 max-h-full overflow-hidden bg-transparent ${e} ${h.container||""}`,gt=`flex-1 min-h-0 min-w-0 max-h-full w-full overflow-hidden overscroll-contain break-words break-anywhere p-4 bg-transparent ${h.messagesArea||""}`,yt=`relative flex-shrink-0 w-full border-t p-4 bg-transparent ${h.inputArea||""}`;return u.jsxs("div",{className:_t,children:[!!M&&!ot&&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(et,{variant:"ghost",size:"sm",onClick:()=>pt(!0),className:"text-red-800 hover:bg-red-100","aria-label":"Dismiss error",children:u.jsx(ae.X,{size:16})})]}),u.jsxs("div",{className:`relative ${gt}`,style:r?{maxHeight:r}:void 0,children:[u.jsx(Ka,{ref:Tt,className:"h-full",style:{height:"100%"},messages:C,isStreaming:P,streamingAssistantId:_,streamingDebounceMs:typeof s=="number"?s:o,followNewMessages:i,layoutSize:ri,enableMessageEditing:c,editingMessageId:V,onEdit:te,onRegenerate:ue,onCancelEdit:N,emptyMessage:mt??void 0,isNavigatingCheckpoint:wt,activeInterrupt:G,disableInterruptActions:re,onInterruptActionStart:ie,onInterruptActionEnd:Y,showToolMessages:d,showArtifactPreviews:f,checkpointMetaById:X,checkpointIndexByKey:ye,attemptMetaById:Ce,userMessageIdToAttempts:Je,activeCheckpointId:$,onSelectCheckpoint:ze,timelineCheckpoints:Be,messagePreviews:K}),(I==="reconnecting"||I==="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(ae.Loader2,{className:"h-3 w-3 animate-spin"}),I==="reconnecting"?"Reconnecting…":"Connecting…"]})}),I==="error"&&u.jsx("div",{className:"pointer-events-none absolute top-3 right-3 z-20 rounded-full bg-destructive/10 px-3 py-1 text-xs font-semibold text-destructive shadow-sm",children:"Connection lost"}),S&&u.jsxs("div",{className:"absolute inset-0 z-10 flex flex-col items-center justify-center gap-2 bg-background/80 backdrop-blur-sm text-muted-foreground",children:[u.jsx(ae.Loader2,{className:"h-6 w-6 animate-spin"}),u.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:"Loading messages…"})]}),(k||wt)&&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(ae.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:yt,children:[V&&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(ae.Edit3,{size:16,className:"text-blue-600"}),u.jsx("span",{className:"text-sm font-medium text-blue-800",children:"Editing message"})]}),u.jsx(et,{variant:"ghost",size:"sm",onClick:N,className:"text-blue-600 hover:bg-blue-100",children:u.jsx(ae.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:xt,type:"file",multiple:!0,onChange:me=>Ie(me),className:"hidden"},je),be.length>0&&u.jsx("div",{className:"flex flex-wrap gap-2",children:be.map((me,Te)=>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(ae.Paperclip,{size:14}),u.jsx("span",{className:"truncate max-w-[150px]",children:me.name}),u.jsx(et,{variant:"ghost",size:"sm",onClick:()=>Ze(Te),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 ${me.name}`,children:u.jsx(ae.X,{size:12})})]},Te))})]}),l&&u.jsxs(u.Fragment,{children:[u.jsx("input",{ref:nt,type:"file",accept:".xls,.xlsx,.xlsm",onChange:st,className:"hidden"},qe),Ge&&u.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[u.jsx(ae.Loader2,{className:"h-4 w-4 animate-spin"})," Uploading Excel file..."]}),Le&&!Ge&&u.jsx("div",{className:"text-sm rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-emerald-700",children:Le}),lt&&!Ge&&u.jsx("div",{className:"text-sm rounded border border-red-200 bg-red-50 px-3 py-2 text-red-600",children:lt})]})]}),ne&&u.jsx("div",{className:"mb-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2",children:ne}),u.jsxs("div",{className:"flex items-end gap-2",children:[(a||l)&&u.jsxs(aa,{children:[u.jsx(la,{asChild:!0,children:u.jsx(et,{type:"button",size:"icon",variant:"outline",disabled:P||D,title:"More input actions",className:h.moreButton||"",children:u.jsx(ae.Plus,{size:16})})}),u.jsxs(xs,{align:"start",sideOffset:6,className:"w-52",children:[a&&u.jsxs(Jn,{onClick:()=>{var me;return(me=xt.current)==null?void 0:me.click()},className:"cursor-pointer",children:[u.jsx(ae.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]}),l&&u.jsxs(Jn,{onClick:()=>{var me;Ge||(me=nt.current)==null||me.click()},className:`cursor-pointer ${Ge?"opacity-60 pointer-events-none":""}`,children:[u.jsx(ae.FileSpreadsheet,{className:"h-4 w-4 mr-2"})," Upload Excel file"]})]})]}),u.jsx("div",{className:"flex-1",children:u.jsx(fy,{initialValue:Z,editingMessageId:V,value:Fe,onValueChange:yo,placeholder:V?"Edit your message...":t,isStreaming:P,disabled:D,maxLength:vs,onSend:ml,onCancelEdit:N,onStop:L,allowEmptySend:be.length>0,textareaClassName:`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${V?"border-blue-400 bg-blue-50 text-blue-900 dark:border-blue-500 dark:bg-blue-950/60 dark:text-blue-50":""} ${ne?"border-red-400":""} ${h.textarea||""}`})})]})]})]})}function qa(e,[t,n]){return Math.min(n,Math.max(t,e))}function oT(e,t){return m.useReducer((n,r)=>t[n][r]??n,e)}var Ga="ScrollArea",[$h,kE]=Tn(Ga),[sT,tn]=$h(Ga),Fh=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,type:r="hover",dir:o,scrollHideDelay:s=600,...i}=e,[a,l]=m.useState(null),[c,d]=m.useState(null),[f,h]=m.useState(null),[p,v]=m.useState(null),[g,y]=m.useState(null),[x,b]=m.useState(0),[C,k]=m.useState(0),[S,T]=m.useState(!1),[E,j]=m.useState(!1),R=Ve(t,B=>l(B)),O=Uo(o);return u.jsx(sT,{scope:n,type:r,dir:O,scrollHideDelay:s,scrollArea:a,viewport:c,onViewportChange:d,content:f,onContentChange:h,scrollbarX:p,onScrollbarXChange:v,scrollbarXEnabled:S,onScrollbarXEnabledChange:T,scrollbarY:g,onScrollbarYChange:y,scrollbarYEnabled:E,onScrollbarYEnabledChange:j,onCornerWidthChange:b,onCornerHeightChange:k,children:u.jsx(Se.div,{dir:O,...i,ref:R,style:{position:"relative","--radix-scroll-area-corner-width":x+"px","--radix-scroll-area-corner-height":C+"px",...e.style}})})});Fh.displayName=Ga;var Bh="ScrollAreaViewport",zh=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,i=tn(Bh,n),a=m.useRef(null),l=Ve(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(Se.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})})]})});zh.displayName=Bh;var Sn="ScrollAreaScrollbar",Ya=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=tn(Sn,e.__scopeScrollArea),{onScrollbarXEnabledChange:s,onScrollbarYEnabledChange:i}=o,a=e.orientation==="horizontal";return m.useEffect(()=>(a?s(!0):i(!0),()=>{a?s(!1):i(!1)}),[a,s,i]),o.type==="hover"?u.jsx(iT,{...r,ref:t,forceMount:n}):o.type==="scroll"?u.jsx(aT,{...r,ref:t,forceMount:n}):o.type==="auto"?u.jsx(Uh,{...r,ref:t,forceMount:n}):o.type==="always"?u.jsx(Xa,{...r,ref:t}):null});Ya.displayName=Sn;var iT=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=tn(Sn,e.__scopeScrollArea),[s,i]=m.useState(!1);return m.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(Jt,{present:n||s,children:u.jsx(Uh,{"data-state":s?"visible":"hidden",...r,ref:t})})}),aT=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=tn(Sn,e.__scopeScrollArea),s=e.orientation==="horizontal",i=Ys(()=>l("SCROLL_END"),100),[a,l]=oT("hidden",{hidden:{SCROLL:"scrolling"},scrolling:{SCROLL_END:"idle",POINTER_ENTER:"interacting"},interacting:{SCROLL:"interacting",POINTER_LEAVE:"idle"},idle:{HIDE:"hidden",SCROLL:"scrolling",POINTER_ENTER:"interacting"}});return m.useEffect(()=>{if(a==="idle"){const c=window.setTimeout(()=>l("HIDE"),o.scrollHideDelay);return()=>window.clearTimeout(c)}},[a,o.scrollHideDelay,l]),m.useEffect(()=>{const c=o.viewport,d=s?"scrollLeft":"scrollTop";if(c){let f=c[d];const h=()=>{const p=c[d];f!==p&&(l("SCROLL"),i()),f=p};return c.addEventListener("scroll",h),()=>c.removeEventListener("scroll",h)}},[o.viewport,s,l,i]),u.jsx(Jt,{present:n||a!=="hidden",children:u.jsx(Xa,{"data-state":a==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:he(e.onPointerEnter,()=>l("POINTER_ENTER")),onPointerLeave:he(e.onPointerLeave,()=>l("POINTER_LEAVE"))})})}),Uh=m.forwardRef((e,t)=>{const n=tn(Sn,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,i]=m.useState(!1),a=e.orientation==="horizontal",l=Ys(()=>{if(n.viewport){const c=n.viewport.offsetWidth<n.viewport.scrollWidth,d=n.viewport.offsetHeight<n.viewport.scrollHeight;i(a?c:d)}},10);return Er(n.viewport,l),Er(n.content,l),u.jsx(Jt,{present:r||s,children:u.jsx(Xa,{"data-state":s?"visible":"hidden",...o,ref:t})})}),Xa=m.forwardRef((e,t)=>{const{orientation:n="vertical",...r}=e,o=tn(Sn,e.__scopeScrollArea),s=m.useRef(null),i=m.useRef(0),[a,l]=m.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),c=qh(a.viewport,a.content),d={...r,sizes:a,onSizesChange:l,hasThumb:c>0&&c<1,onThumbChange:h=>s.current=h,onThumbPointerUp:()=>i.current=0,onThumbPointerDown:h=>i.current=h};function f(h,p){return hT(h,i.current,a,p)}return n==="horizontal"?u.jsx(lT,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollLeft,p=Gh(h,a,o.dir);s.current.style.transform=`translate3d(${p}px, 0, 0)`}},onWheelScroll:h=>{o.viewport&&(o.viewport.scrollLeft=h)},onDragScroll:h=>{o.viewport&&(o.viewport.scrollLeft=f(h,o.dir))}}):n==="vertical"?u.jsx(cT,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollTop,p=Gh(h,a);s.current.style.transform=`translate3d(0, ${p}px, 0)`}},onWheelScroll:h=>{o.viewport&&(o.viewport.scrollTop=h)},onDragScroll:h=>{o.viewport&&(o.viewport.scrollTop=f(h))}}):null}),lT=m.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=tn(Sn,e.__scopeScrollArea),[i,a]=m.useState(),l=m.useRef(null),c=Ve(t,l,s.onScrollbarXChange);return m.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(Wh,{"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":Gs(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.x),onDragScroll:d=>e.onDragScroll(d.x),onWheelScroll:(d,f)=>{if(s.viewport){const h=s.viewport.scrollLeft+d.deltaX;e.onWheelScroll(h),Xh(h,f)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollWidth,viewport:s.viewport.offsetWidth,scrollbar:{size:l.current.clientWidth,paddingStart:qs(i.paddingLeft),paddingEnd:qs(i.paddingRight)}})}})}),cT=m.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=tn(Sn,e.__scopeScrollArea),[i,a]=m.useState(),l=m.useRef(null),c=Ve(t,l,s.onScrollbarYChange);return m.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(Wh,{"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":Gs(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.y),onDragScroll:d=>e.onDragScroll(d.y),onWheelScroll:(d,f)=>{if(s.viewport){const h=s.viewport.scrollTop+d.deltaY;e.onWheelScroll(h),Xh(h,f)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollHeight,viewport:s.viewport.offsetHeight,scrollbar:{size:l.current.clientHeight,paddingStart:qs(i.paddingTop),paddingEnd:qs(i.paddingBottom)}})}})}),[uT,Hh]=$h(Sn),Wh=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,sizes:r,hasThumb:o,onThumbChange:s,onThumbPointerUp:i,onThumbPointerDown:a,onThumbPositionChange:l,onDragScroll:c,onWheelScroll:d,onResize:f,...h}=e,p=tn(Sn,n),[v,g]=m.useState(null),y=Ve(t,R=>g(R)),x=m.useRef(null),b=m.useRef(""),C=p.viewport,k=r.content-r.viewport,S=Nt(d),T=Nt(l),E=Ys(f,10);function j(R){if(x.current){const O=R.clientX-x.current.left,B=R.clientY-x.current.top;c({x:O,y:B})}}return m.useEffect(()=>{const R=O=>{const B=O.target;(v==null?void 0:v.contains(B))&&S(O,k)};return document.addEventListener("wheel",R,{passive:!1}),()=>document.removeEventListener("wheel",R,{passive:!1})},[C,v,k,S]),m.useEffect(T,[r,T]),Er(v,E),Er(p.content,E),u.jsx(uT,{scope:n,scrollbar:v,hasThumb:o,onThumbChange:Nt(s),onThumbPointerUp:Nt(i),onThumbPositionChange:T,onThumbPointerDown:Nt(a),children:u.jsx(Se.div,{...h,ref:y,style:{position:"absolute",...h.style},onPointerDown:he(e.onPointerDown,R=>{R.button===0&&(R.target.setPointerCapture(R.pointerId),x.current=v.getBoundingClientRect(),b.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",p.viewport&&(p.viewport.style.scrollBehavior="auto"),j(R))}),onPointerMove:he(e.onPointerMove,j),onPointerUp:he(e.onPointerUp,R=>{const O=R.target;O.hasPointerCapture(R.pointerId)&&O.releasePointerCapture(R.pointerId),document.body.style.webkitUserSelect=b.current,p.viewport&&(p.viewport.style.scrollBehavior=""),x.current=null})})})}),Ks="ScrollAreaThumb",Vh=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Hh(Ks,e.__scopeScrollArea);return u.jsx(Jt,{present:n||o.hasThumb,children:u.jsx(dT,{ref:t,...r})})}),dT=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=tn(Ks,n),i=Hh(Ks,n),{onThumbPositionChange:a}=i,l=Ve(t,f=>i.onThumbChange(f)),c=m.useRef(void 0),d=Ys(()=>{c.current&&(c.current(),c.current=void 0)},100);return m.useEffect(()=>{const f=s.viewport;if(f){const h=()=>{if(d(),!c.current){const p=pT(f,a);c.current=p,a()}};return a(),f.addEventListener("scroll",h),()=>f.removeEventListener("scroll",h)}},[s.viewport,d,a]),u.jsx(Se.div,{"data-state":i.hasThumb?"visible":"hidden",...o,ref:l,style:{width:"var(--radix-scroll-area-thumb-width)",height:"var(--radix-scroll-area-thumb-height)",...r},onPointerDownCapture:he(e.onPointerDownCapture,f=>{const p=f.target.getBoundingClientRect(),v=f.clientX-p.left,g=f.clientY-p.top;i.onThumbPointerDown({x:v,y:g})}),onPointerUp:he(e.onPointerUp,i.onThumbPointerUp)})});Vh.displayName=Ks;var Ja="ScrollAreaCorner",Kh=m.forwardRef((e,t)=>{const n=tn(Ja,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?u.jsx(fT,{...e,ref:t}):null});Kh.displayName=Ja;var fT=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=tn(Ja,n),[s,i]=m.useState(0),[a,l]=m.useState(0),c=!!(s&&a);return Er(o.scrollbarX,()=>{var f;const d=((f=o.scrollbarX)==null?void 0:f.offsetHeight)||0;o.onCornerHeightChange(d),l(d)}),Er(o.scrollbarY,()=>{var f;const d=((f=o.scrollbarY)==null?void 0:f.offsetWidth)||0;o.onCornerWidthChange(d),i(d)}),c?u.jsx(Se.div,{...r,ref:t,style:{width:s,height:a,position:"absolute",right:o.dir==="ltr"?0:void 0,left:o.dir==="rtl"?0:void 0,bottom:0,...e.style}}):null});function qs(e){return e?parseInt(e,10):0}function qh(e,t){const n=e/t;return isNaN(n)?0:n}function Gs(e){const t=qh(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function hT(e,t,n,r="ltr"){const o=Gs(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 Yh([l,c],f)(e)}function Gh(e,t,n="ltr"){const r=Gs(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=qa(e,l);return Yh([0,i],[0,a])(c)}function Yh(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 Xh(e,t){return e>0&&e<t}var pT=(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 Ys(e,t){const n=Nt(e),r=m.useRef(0);return m.useEffect(()=>()=>window.clearTimeout(r.current),[]),m.useCallback(()=>{window.clearTimeout(r.current),r.current=window.setTimeout(n,t)},[n,t])}function Er(e,t){const n=Nt(t);It(()=>{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 Jh=Fh,mT=zh,gT=Kh;const Zh=m.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Jh,{ref:r,className:oe("relative overflow-hidden",e),...n,children:[u.jsx(mT,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),u.jsx(Qh,{}),u.jsx(gT,{})]}));Zh.displayName=Jh.displayName;const Qh=m.forwardRef(({className:e,orientation:t="vertical",...n},r)=>u.jsx(Ya,{ref:r,orientation:t,className:oe("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(Vh,{className:"relative flex-1 rounded-full bg-border"})}));Qh.displayName=Ya.displayName;var ep=1,xT=.9,yT=.8,vT=.17,Za=.1,Qa=.999,bT=.9999,wT=.99,ST=/[\\\/_+.#"@\[\(\{&]/,CT=/[\\\/_+.#"@\[\(\{&]/g,TT=/[\s-]/,tp=/[\s-]/g;function el(e,t,n,r,o,s,i){if(s===t.length)return o===e.length?ep:wT;var a=`${o},${s}`;if(i[a]!==void 0)return i[a];for(var l=r.charAt(s),c=n.indexOf(l,o),d=0,f,h,p,v;c>=0;)f=el(e,t,n,r,c+1,s+1,i),f>d&&(c===o?f*=ep:ST.test(e.charAt(c-1))?(f*=yT,p=e.slice(o,c-1).match(CT),p&&o>0&&(f*=Math.pow(Qa,p.length))):TT.test(e.charAt(c-1))?(f*=xT,v=e.slice(o,c-1).match(tp),v&&o>0&&(f*=Math.pow(Qa,v.length))):(f*=vT,o>0&&(f*=Math.pow(Qa,c-o))),e.charAt(c)!==t.charAt(s)&&(f*=bT)),(f<Za&&n.charAt(c-1)===r.charAt(s+1)||r.charAt(s+1)===r.charAt(s)&&n.charAt(c-1)!==r.charAt(s))&&(h=el(e,t,n,r,c+1,s+2,i),h*Za>f&&(f=h*Za)),f>d&&(d=f),c=n.indexOf(l,c+1);return i[a]=d,d}function np(e){return e.toLowerCase().replace(tp," ")}function kT(e,t,n){return e=n&&n.length>0?`${e+" "+n.join(" ")}`:e,el(e,t,np(e),np(t),0,0,{})}var mo='[cmdk-group=""]',tl='[cmdk-group-items=""]',ET='[cmdk-group-heading=""]',rp='[cmdk-item=""]',op=`${rp}:not([aria-disabled="true"])`,nl="cmdk-item-select",Ir="data-value",IT=(e,t,n)=>kT(e,t,n),sp=m.createContext(void 0),go=()=>m.useContext(sp),ip=m.createContext(void 0),rl=()=>m.useContext(ip),ap=m.createContext(void 0),lp=m.forwardRef((e,t)=>{let n=Nr(()=>{var _,G;return{search:"",value:(G=(_=e.value)!=null?_:e.defaultValue)!=null?G:"",selectedItemId:void 0,filtered:{count:0,items:new Map,groups:new Set}}}),r=Nr(()=>new Set),o=Nr(()=>new Map),s=Nr(()=>new Map),i=Nr(()=>new Set),a=cp(e),{label:l,children:c,value:d,onValueChange:f,filter:h,shouldFilter:p,loop:v,disablePointerSelection:g=!1,vimBindings:y=!0,...x}=e,b=$t(),C=$t(),k=$t(),S=m.useRef(null),T=$T();sr(()=>{if(d!==void 0){let _=d.trim();n.current.value=_,E.emit()}},[d]),sr(()=>{T(6,K)},[]);let E=m.useMemo(()=>({subscribe:_=>(i.current.add(_),()=>i.current.delete(_)),snapshot:()=>n.current,setState:(_,G,re)=>{var ee,ie,Y,D;if(!Object.is(n.current[_],G)){if(n.current[_]=G,_==="search")q(),O(),T(1,B);else if(_==="value"){if(document.activeElement.hasAttribute("cmdk-input")||document.activeElement.hasAttribute("cmdk-root")){let V=document.getElementById(k);V?V.focus():(ee=document.getElementById(b))==null||ee.focus()}if(T(7,()=>{var V;n.current.selectedItemId=(V=P())==null?void 0:V.id,E.emit()}),re||T(5,K),((ie=a.current)==null?void 0:ie.value)!==void 0){let V=G??"";(D=(Y=a.current).onValueChange)==null||D.call(Y,V);return}}E.emit()}},emit:()=>{i.current.forEach(_=>_())}}),[]),j=m.useMemo(()=>({value:(_,G,re)=>{var ee;G!==((ee=s.current.get(_))==null?void 0:ee.value)&&(s.current.set(_,{value:G,keywords:re}),n.current.filtered.items.set(_,R(G,re)),T(2,()=>{O(),E.emit()}))},item:(_,G)=>(r.current.add(_),G&&(o.current.has(G)?o.current.get(G).add(_):o.current.set(G,new Set([_]))),T(3,()=>{q(),O(),n.current.value||B(),E.emit()}),()=>{s.current.delete(_),r.current.delete(_),n.current.filtered.items.delete(_);let re=P();T(4,()=>{q(),(re==null?void 0:re.getAttribute("id"))===_&&B(),E.emit()})}),group:_=>(o.current.has(_)||o.current.set(_,new Set),()=>{s.current.delete(_),o.current.delete(_)}),filter:()=>a.current.shouldFilter,label:l||e["aria-label"],getDisablePointerSelection:()=>a.current.disablePointerSelection,listId:b,inputId:k,labelId:C,listInnerRef:S}),[]);function R(_,G){var re,ee;let ie=(ee=(re=a.current)==null?void 0:re.filter)!=null?ee:IT;return _?ie(_,n.current.search,G):0}function O(){if(!n.current.search||a.current.shouldFilter===!1)return;let _=n.current.filtered.items,G=[];n.current.filtered.groups.forEach(ee=>{let ie=o.current.get(ee),Y=0;ie.forEach(D=>{let V=_.get(D);Y=Math.max(V,Y)}),G.push([ee,Y])});let re=S.current;M().sort((ee,ie)=>{var Y,D;let V=ee.getAttribute("id"),U=ie.getAttribute("id");return((Y=_.get(U))!=null?Y:0)-((D=_.get(V))!=null?D:0)}).forEach(ee=>{let ie=ee.closest(tl);ie?ie.appendChild(ee.parentElement===ie?ee:ee.closest(`${tl} > *`)):re.appendChild(ee.parentElement===re?ee:ee.closest(`${tl} > *`))}),G.sort((ee,ie)=>ie[1]-ee[1]).forEach(ee=>{var ie;let Y=(ie=S.current)==null?void 0:ie.querySelector(`${mo}[${Ir}="${encodeURIComponent(ee[0])}"]`);Y==null||Y.parentElement.appendChild(Y)})}function B(){let _=M().find(re=>re.getAttribute("aria-disabled")!=="true"),G=_==null?void 0:_.getAttribute(Ir);E.setState("value",G||void 0)}function q(){var _,G,re,ee;if(!n.current.search||a.current.shouldFilter===!1){n.current.filtered.count=r.current.size;return}n.current.filtered.groups=new Set;let ie=0;for(let Y of r.current){let D=(G=(_=s.current.get(Y))==null?void 0:_.value)!=null?G:"",V=(ee=(re=s.current.get(Y))==null?void 0:re.keywords)!=null?ee:[],U=R(D,V);n.current.filtered.items.set(Y,U),U>0&&ie++}for(let[Y,D]of o.current)for(let V of D)if(n.current.filtered.items.get(V)>0){n.current.filtered.groups.add(Y);break}n.current.filtered.count=ie}function K(){var _,G,re;let ee=P();ee&&(((_=ee.parentElement)==null?void 0:_.firstChild)===ee&&((re=(G=ee.closest(mo))==null?void 0:G.querySelector(ET))==null||re.scrollIntoView({block:"nearest"})),ee.scrollIntoView({block:"nearest"}))}function P(){var _;return(_=S.current)==null?void 0:_.querySelector(`${rp}[aria-selected="true"]`)}function M(){var _;return Array.from(((_=S.current)==null?void 0:_.querySelectorAll(op))||[])}function I(_){let G=M()[_];G&&E.setState("value",G.getAttribute(Ir))}function z(_){var G;let re=P(),ee=M(),ie=ee.findIndex(D=>D===re),Y=ee[ie+_];(G=a.current)!=null&&G.loop&&(Y=ie+_<0?ee[ee.length-1]:ie+_===ee.length?ee[0]:ee[ie+_]),Y&&E.setState("value",Y.getAttribute(Ir))}function L(_){let G=P(),re=G==null?void 0:G.closest(mo),ee;for(;re&&!ee;)re=_>0?DT(re,mo):LT(re,mo),ee=re==null?void 0:re.querySelector(op);ee?E.setState("value",ee.getAttribute(Ir)):z(_)}let A=()=>I(M().length-1),$=_=>{_.preventDefault(),_.metaKey?A():_.altKey?L(1):z(1)},H=_=>{_.preventDefault(),_.metaKey?I(0):_.altKey?L(-1):z(-1)};return m.createElement(Se.div,{ref:t,tabIndex:-1,...x,"cmdk-root":"",onKeyDown:_=>{var G;(G=x.onKeyDown)==null||G.call(x,_);let re=_.nativeEvent.isComposing||_.keyCode===229;if(!(_.defaultPrevented||re))switch(_.key){case"n":case"j":{y&&_.ctrlKey&&$(_);break}case"ArrowDown":{$(_);break}case"p":case"k":{y&&_.ctrlKey&&H(_);break}case"ArrowUp":{H(_);break}case"Home":{_.preventDefault(),I(0);break}case"End":{_.preventDefault(),A();break}case"Enter":{_.preventDefault();let ee=P();if(ee){let ie=new Event(nl);ee.dispatchEvent(ie)}}}}},m.createElement("label",{"cmdk-label":"",htmlFor:j.inputId,id:j.labelId,style:BT},l),Xs(e,_=>m.createElement(ip.Provider,{value:E},m.createElement(sp.Provider,{value:j},_))))}),NT=m.forwardRef((e,t)=>{var n,r;let o=$t(),s=m.useRef(null),i=m.useContext(ap),a=go(),l=cp(e),c=(r=(n=l.current)==null?void 0:n.forceMount)!=null?r:i==null?void 0:i.forceMount;sr(()=>{if(!c)return a.item(o,i==null?void 0:i.id)},[c]);let d=up(o,s,[e.value,e.children,s],e.keywords),f=rl(),h=Fn(T=>T.value&&T.value===d.current),p=Fn(T=>c||a.filter()===!1?!0:T.search?T.filtered.items.get(o)>0:!0);m.useEffect(()=>{let T=s.current;if(!(!T||e.disabled))return T.addEventListener(nl,v),()=>T.removeEventListener(nl,v)},[p,e.onSelect,e.disabled]);function v(){var T,E;g(),(E=(T=l.current).onSelect)==null||E.call(T,d.current)}function g(){f.setState("value",d.current,!0)}if(!p)return null;let{disabled:y,value:x,onSelect:b,forceMount:C,keywords:k,...S}=e;return m.createElement(Se.div,{ref:An(s,t),...S,id:o,"cmdk-item":"",role:"option","aria-disabled":!!y,"aria-selected":!!h,"data-disabled":!!y,"data-selected":!!h,onPointerMove:y||a.getDisablePointerSelection()?void 0:g,onClick:y?void 0:v},e.children)}),AT=m.forwardRef((e,t)=>{let{heading:n,children:r,forceMount:o,...s}=e,i=$t(),a=m.useRef(null),l=m.useRef(null),c=$t(),d=go(),f=Fn(p=>o||d.filter()===!1?!0:p.search?p.filtered.groups.has(i):!0);sr(()=>d.group(i),[]),up(i,a,[e.value,e.heading,l]);let h=m.useMemo(()=>({id:i,forceMount:o}),[o]);return m.createElement(Se.div,{ref:An(a,t),...s,"cmdk-group":"",role:"presentation",hidden:f?void 0:!0},n&&m.createElement("div",{ref:l,"cmdk-group-heading":"","aria-hidden":!0,id:c},n),Xs(e,p=>m.createElement("div",{"cmdk-group-items":"",role:"group","aria-labelledby":n?c:void 0},m.createElement(ap.Provider,{value:h},p))))}),jT=m.forwardRef((e,t)=>{let{alwaysRender:n,...r}=e,o=m.useRef(null),s=Fn(i=>!i.search);return!n&&!s?null:m.createElement(Se.div,{ref:An(o,t),...r,"cmdk-separator":"",role:"separator"})}),_T=m.forwardRef((e,t)=>{let{onValueChange:n,...r}=e,o=e.value!=null,s=rl(),i=Fn(c=>c.search),a=Fn(c=>c.selectedItemId),l=go();return m.useEffect(()=>{e.value!=null&&s.setState("search",e.value)},[e.value]),m.createElement(Se.input,{ref:t,...r,"cmdk-input":"",autoComplete:"off",autoCorrect:"off",spellCheck:!1,"aria-autocomplete":"list",role:"combobox","aria-expanded":!0,"aria-controls":l.listId,"aria-labelledby":l.labelId,"aria-activedescendant":a,id:l.inputId,type:"text",value:o?e.value:i,onChange:c=>{o||s.setState("search",c.target.value),n==null||n(c.target.value)}})}),MT=m.forwardRef((e,t)=>{let{children:n,label:r="Suggestions",...o}=e,s=m.useRef(null),i=m.useRef(null),a=Fn(c=>c.selectedItemId),l=go();return m.useEffect(()=>{if(i.current&&s.current){let c=i.current,d=s.current,f,h=new ResizeObserver(()=>{f=requestAnimationFrame(()=>{let p=c.offsetHeight;d.style.setProperty("--cmdk-list-height",p.toFixed(1)+"px")})});return h.observe(c),()=>{cancelAnimationFrame(f),h.unobserve(c)}}},[]),m.createElement(Se.div,{ref:An(s,t),...o,"cmdk-list":"",role:"listbox",tabIndex:-1,"aria-activedescendant":a,"aria-label":r,id:l.listId},Xs(e,c=>m.createElement("div",{ref:An(i,l.listInnerRef),"cmdk-list-sizer":""},c)))}),RT=m.forwardRef((e,t)=>{let{open:n,onOpenChange:r,overlayClassName:o,contentClassName:s,container:i,...a}=e;return m.createElement(Da,{open:n,onOpenChange:r},m.createElement(La,{container:i},m.createElement(io,{"cmdk-overlay":"",className:o}),m.createElement(ao,{"aria-label":e.label,"cmdk-dialog":"",className:s},m.createElement(lp,{ref:t,...a}))))}),PT=m.forwardRef((e,t)=>Fn(n=>n.filtered.count===0)?m.createElement(Se.div,{ref:t,...e,"cmdk-empty":"",role:"presentation"}):null),OT=m.forwardRef((e,t)=>{let{progress:n,children:r,label:o="Loading...",...s}=e;return m.createElement(Se.div,{ref:t,...s,"cmdk-loading":"",role:"progressbar","aria-valuenow":n,"aria-valuemin":0,"aria-valuemax":100,"aria-label":o},Xs(e,i=>m.createElement("div",{"aria-hidden":!0},i)))}),Kt=Object.assign(lp,{List:MT,Item:NT,Input:_T,Group:AT,Separator:jT,Dialog:RT,Empty:PT,Loading:OT});function DT(e,t){let n=e.nextElementSibling;for(;n;){if(n.matches(t))return n;n=n.nextElementSibling}}function LT(e,t){let n=e.previousElementSibling;for(;n;){if(n.matches(t))return n;n=n.previousElementSibling}}function cp(e){let t=m.useRef(e);return sr(()=>{t.current=e}),t}var sr=typeof window>"u"?m.useEffect:m.useLayoutEffect;function Nr(e){let t=m.useRef();return t.current===void 0&&(t.current=e()),t}function Fn(e){let t=rl(),n=()=>e(t.snapshot());return m.useSyncExternalStore(t.subscribe,n,n)}function up(e,t,n,r=[]){let o=m.useRef(),s=go();return sr(()=>{var i;let a=(()=>{var c;for(let d of n){if(typeof d=="string")return d.trim();if(typeof d=="object"&&"current"in d)return d.current?(c=d.current.textContent)==null?void 0:c.trim():o.current}})(),l=r.map(c=>c.trim());s.value(e,a,l),(i=t.current)==null||i.setAttribute(Ir,a),o.current=a}),o}var $T=()=>{let[e,t]=m.useState(),n=Nr(()=>new Map);return sr(()=>{n.current.forEach(r=>r()),n.current=new Map},[e]),(r,o)=>{n.current.set(r,o),t({})}};function FT(e){let t=e.type;return typeof t=="function"?t(e.props):"render"in t?t.render(e.props):e}function Xs({asChild:e,children:t},n){return e&&m.isValidElement(t)?m.cloneElement(FT(t),{ref:t.ref},n(t.props.children)):n(t)}var BT={position:"absolute",width:"1px",height:"1px",padding:"0",margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",borderWidth:"0"};const dp=m.forwardRef(({className:e,...t},n)=>u.jsx(Kt,{ref:n,className:oe("flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",e),...t}));dp.displayName=Kt.displayName;const fp=m.forwardRef(({className:e,...t},n)=>u.jsxs("div",{className:"flex items-center border-b px-3","cmdk-input-wrapper":"",children:[u.jsx(ae.Search,{className:"mr-2 h-4 w-4 shrink-0 opacity-50"}),u.jsx(Kt.Input,{ref:n,className:oe("flex h-11 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",e),...t})]}));fp.displayName=Kt.Input.displayName;const hp=m.forwardRef(({className:e,...t},n)=>u.jsx(Kt.List,{ref:n,className:oe("max-h-[300px] overflow-y-auto overflow-x-hidden",e),...t}));hp.displayName=Kt.List.displayName;const pp=m.forwardRef((e,t)=>u.jsx(Kt.Empty,{ref:t,className:"py-6 text-center text-sm",...e}));pp.displayName=Kt.Empty.displayName;const mp=m.forwardRef(({className:e,...t},n)=>u.jsx(Kt.Group,{ref:n,className:oe("overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",e),...t}));mp.displayName=Kt.Group.displayName;const zT=m.forwardRef(({className:e,...t},n)=>u.jsx(Kt.Separator,{ref:n,className:oe("-mx-1 h-px bg-border",e),...t}));zT.displayName=Kt.Separator.displayName;const gp=m.forwardRef(({className:e,...t},n)=>u.jsx(Kt.Item,{ref:n,className:oe("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none data-[disabled=true]:pointer-events-none data-[selected='true']:bg-accent data-[selected=true]:text-accent-foreground data-[disabled=true]:opacity-50",e),...t}));gp.displayName=Kt.Item.displayName;const Js=m.forwardRef(({className:e,type:t,...n},r)=>u.jsx("input",{type:t,className:oe("flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",e),ref:r,...n}));Js.displayName="Input";const UT="group relative p-3 rounded-lg cursor-pointer transition-colors border text-gray-900 dark:text-slate-100",HT="bg-slate-700 border-slate-600 hover:bg-slate-600",WT="bg-slate-600 border-slate-500";function VT({thread:e,isActive:t,editingThreadId:n,editingTitle:r,onSelect:o,onStartEditing:s,onEditingTitleChange:i,onSaveEditing:a,onCancelEditing:l,onShare:c,onDelete:d,showEditTitle:f,showDeleteButton:h,formatDate:p,getDisplayThreadTitle:v,secondaryLine:g,itemClassName:y,activeItemClassName:x}){const b=n===e.threadId,C=t?`${x??WT}`:`${y??HT}`,k=S=>{S.stopPropagation(),o(e.threadId)};return u.jsxs("div",{onClick:k,className:`${UT} ${C}`,children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx("div",{className:"flex-1 min-w-0",children:b?u.jsxs("div",{className:"flex items-center gap-2",onClick:S=>S.stopPropagation(),children:[u.jsx(Js,{value:r,onChange:S=>i(S.target.value),onKeyDown:S=>{S.key==="Enter"?a(e.threadId):S.key==="Escape"&&l()},className:"h-6 text-sm",autoFocus:!0}),u.jsx(et,{variant:"ghost",size:"sm",onClick:()=>a(e.threadId),className:"h-6 w-6 p-0",children:u.jsx(ae.Check,{size:12})}),u.jsx(et,{variant:"ghost",size:"sm",onClick:l,className:"h-6 w-6 p-0",children:u.jsx(ae.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:v(e)}),u.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500 dark:text-slate-400 mt-1",children:[u.jsx(ae.Calendar,{size:10}),u.jsx("span",{children:p(e.updatedAt||e.createdAt)})]}),g&&u.jsx("div",{className:"text-[11px] text-muted-foreground mt-1",children:g})]})}),u.jsx("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity ml-2",children:u.jsxs(aa,{children:[u.jsx(la,{asChild:!0,children:u.jsx(et,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",children:u.jsx(ae.MoreHorizontal,{size:12})})}),u.jsxs(xs,{align:"end",sideOffset:6,className:"w-44",children:[u.jsxs(Jn,{onClick:S=>{S.preventDefault(),c(e.threadId)},children:[u.jsx(ae.Share2,{className:"mr-2 h-4 w-4"}),"Share thread"]}),f&&n!==e.threadId&&u.jsxs(Jn,{onClick:S=>{S.preventDefault(),s(e,S)},children:[u.jsx(ae.Edit3,{className:"mr-2 h-4 w-4"}),"Rename"]}),h&&d&&u.jsxs(Jn,{className:"text-red-400 hover:text-red-300",onClick:S=>{S.preventDefault(),d(e.threadId,S)},children:[u.jsx(ae.Trash2,{className:"mr-2 h-4 w-4"}),"Delete"]})]})]})})]}),t&&u.jsx("div",{className:"absolute left-0 top-1/2 -translate-y-1/2 w-1 h-8 bg-blue-400 rounded-r"})]})}const xp=25,KT=[{key:"default",label:"My threads"},{key:"shared",label:"Shared with you"}];function ol({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,view:f,defaultView:h,onViewChange:p,viewOptions:v}){const{threads:g,sharedThreads:y,currentThreadId:x,setCurrentThreadId:b,isLoading:C,isLoadingSharedThreads:k,smartOrgUsers:S,isLoadingSmartOrgUsers:T,actions:E}=Fo(),{createThread:j,deleteThread:R,renameThread:O,shareThread:B}=E,{loadThread:q}=Bo(),K=i??x,[P,M]=w.useState(Array.isArray(g)?g:[]),I=w.useRef(P.length>0),z=w.useRef(null),L=w.useRef(0),[A,$]=w.useState(null),[H,_]=w.useState(""),[G,re]=w.useState(!1),[ee,ie]=w.useState(!1),[Y,D]=w.useState(null),[V,U]=w.useState(""),Z=v&&v.length>0?v:KT,[J,ge]=w.useState(h??"default"),ce=f??J,ne=w.useCallback(W=>{f||ge(W),p==null||p(W)},[f,p]),pe=Z.find(W=>W.key===ce)??Z[0],be=W=>{D(W),U(""),ie(!0)},De=()=>{ie(!1),D(null),U("")},je=async W=>{if(!Y)return;const le=W.user_id??W.id??W.username??W.email;if(le)try{await B(Y,le),De()}catch(Pe){console.error("Failed to share thread:",Pe),alert(Pe instanceof Error?Pe.message:String(Pe))}},He=w.useMemo(()=>{const W=V.trim().toLowerCase();return W?S.filter(le=>`${le.username??""} ${le.user_id??""} ${le.email??""} ${le.name??""}`.toLowerCase().includes(W)):S},[S,V]),qe=ce==="shared",rt=qe?y:P,Ge=qe?k:C,Qe=qe?"No shared conversations yet":"No conversations yet",lt=W=>{const le=W.sharedAt?` • ${At(W.sharedAt)}`:"";return`Shared by ${W.sharedByUserId}${le}`},Re=W=>"sharedByUserId"in W;w.useEffect(()=>{const W=Array.isArray(g)?g:[];if(W.length>0){I.current=!0,M(W);return}C||(I.current=!1,M(W))},[g,C]),w.useEffect(()=>{if(!z.current)return;const W=z.current.querySelector("[data-radix-scroll-area-viewport]");if(!W)return;let le=null,Pe=null;return le=requestAnimationFrame(()=>{Pe=requestAnimationFrame(()=>{W.scrollTop=L.current})}),()=>{le!==null&&cancelAnimationFrame(le),Pe!==null&&cancelAnimationFrame(Pe)}},[P]);const Le=async W=>{try{b(W),await q(W,void 0,{clearProgress:!0}),a==null||a(W),l==null||l(W)}catch(le){console.error("Failed to select thread:",le)}},ct=async()=>{try{re(!0);const W=await j();W&&(c==null||c(W),a==null||a(W))}catch(W){console.error("Failed to create thread:",W)}finally{re(!1)}},ot=async(W,le)=>{if(le.stopPropagation(),!!confirm("Delete this thread?")){if(z.current){const Pe=z.current.querySelector("[data-radix-scroll-area-viewport]");Pe&&(L.current=Pe.scrollTop)}try{await R(W),d==null||d(W)}catch(Pe){console.error("Failed to delete thread:",Pe)}}},pt=(W,le)=>{le.stopPropagation(),$(W.threadId),_(W.title||`Thread ${W.threadId.slice(0,8)}`)},mt=async W=>{if(H.trim())try{await O(W,H.trim()),$(null),_("")}catch(le){console.error("Failed to update title:",le)}},kt=()=>{$(null),_("")},At=W=>{if(!W)return"";try{const le=new Date(W),wt=new Date().getTime()-le.getTime(),We=Math.floor(wt/(1e3*60*60*24));return We===0?le.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):We===1?"Yesterday":We<7?`${We} days ago`:le.toLocaleDateString()}catch{return""}},Fe=W=>W.title||`Thread ${W.threadId.slice(0,8)}`,fn=W=>{const le=Fe(W);return le.length<=xp?le:`${le.slice(0,xp)}...`};return u.jsxs("div",{className:`flex flex-col h-full ${e} ${s.container||""}`,children:[u.jsxs("div",{className:s.header||"flex items-center justify-between gap-2 px-2 py-1 border-b border-slate-200 bg-white shadow-sm",children:[u.jsxs("div",{className:"flex items-center gap-1 text-[11px] font-semibold text-slate-600",children:[u.jsx("span",{children:"Current View"}),u.jsxs(aa,{children:[u.jsx(la,{asChild:!0,children:u.jsx(et,{variant:"outline",size:"sm",className:"text-[11px] text-slate-700 border border-slate-300 bg-white hover:bg-slate-50 px-2 py-0",children:pe.label})}),u.jsx(xs,{align:"start",sideOffset:6,className:"w-40",children:Z.map(W=>u.jsxs(Jn,{className:"justify-between text-[12px]",onClick:le=>{le.preventDefault(),ne(W.key)},children:[u.jsx("span",{children:W.label}),ce===W.key&&u.jsx(ae.Check,{className:"h-3 w-3"})]},W.key))})]})]}),t&&u.jsx(et,{onClick:ct,disabled:G||C,className:s.createButton||"p-2",size:"sm",variant:"ghost",title:G?"Creating...":"New Chat",children:u.jsx(ae.MessageSquarePlus,{size:20})})]}),u.jsx(Zh,{ref:z,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:Ge?u.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 py-8 text-slate-400",children:[u.jsx(ae.Loader2,{className:"h-5 w-5 animate-spin"}),u.jsx("span",{className:"text-sm",children:"Loading threads…"})]}):rt.length===0?u.jsxs("div",{className:"text-center py-8 text-slate-400",children:[u.jsx(ae.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:Qe})]}):rt.slice().sort((W,le)=>new Date(le.updatedAt||le.createdAt||"").getTime()-new Date(W.updatedAt||W.createdAt||"").getTime()).map(W=>u.jsx(VT,{thread:W,isActive:K===W.threadId,editingThreadId:A,editingTitle:H,onSelect:Le,onStartEditing:pt,onEditingTitleChange:le=>_(le),onSaveEditing:mt,onCancelEditing:kt,onShare:()=>be(W.threadId),onDelete:ot,showEditTitle:r,showDeleteButton:n,formatDate:At,getDisplayThreadTitle:fn,secondaryLine:qe&&Re(W)?lt(W):void 0,itemClassName:s.threadItem,activeItemClassName:s.activeThread},W.threadId))})}),u.jsx(mh,{open:ee,onOpenChange:W=>!W&&De(),children:u.jsxs($a,{className:"max-w-md p-0",children:[u.jsx(Fa,{children:u.jsx(Ba,{children:"Share thread"})}),u.jsxs(dp,{children:[u.jsx(fp,{autoFocus:!0,value:V,onValueChange:W=>U(W),placeholder:"Search for users (name, email, id)..."}),u.jsxs(hp,{children:[u.jsx(pp,{children:T?u.jsxs("span",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[u.jsx(ae.Loader2,{className:"h-4 w-4 animate-spin"}),"Loading users…"]}):"No matching users found"}),u.jsx(mp,{heading:"Users",children:He.map(W=>{const le=W.username??W.user_id??W.email??"Unknown user",Pe=[W.email,W.user_id].filter(Boolean).join(" • "),wt=W.user_id??W.id??W.username??W.email??le;return u.jsx(gp,{onSelect:()=>je(W),children:u.jsxs("div",{className:"flex flex-col items-start text-sm",children:[u.jsx("span",{className:"font-medium",children:le}),Pe&&u.jsx("span",{className:"text-xs text-muted-foreground",children:Pe})]})},wt)})})]})]})]})})]})}const qT=({timelineEntries:e,activeCheckpointId:t,onSelectCheckpoint:n,messagePreviews:r,className:o,onHoverStart:s,onHoverEnd:i})=>{const a=e??[],l=a.length>0,c=w.useMemo(()=>l?[...a].reverse():[],[a,l]),d=t??(a.length?a[a.length-1].id:null);if(!l)return null;const h=["w-32 flex-shrink-0 flex-col border-r border-border/40 pr-2 flex bg-white text-gray-900 dark:bg-slate-900 dark:text-slate-100",o].filter(Boolean).join(" ");return u.jsxs("div",{className:h,onMouseEnter:s,onMouseLeave:i,children:[u.jsxs("div",{className:"relative flex-1 overflow-y-auto pt-4 pb-2 pr-1",children:[u.jsx("div",{className:"absolute left-0 right-0 top-1 px-2 pb-3 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground",children:u.jsx("span",{children:"Timeline"})}),u.jsx("div",{className:"pointer-events-none absolute left-3 top-0 bottom-0 w-px bg-border/40"}),u.jsx("div",{className:"flex flex-col gap-3 pt-6 pr-2",children:c.map(p=>{const v=d===p.id,g=(r==null?void 0:r.get(p.id))??null;return u.jsxs("button",{type:"button",disabled:!n,onClick:()=>n==null?void 0:n(p.id),className:`relative flex items-start gap-2 text-left text-[11px] transition ${v?"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 ${v?"border-primary bg-primary/10 text-primary":"border-border bg-background"}`,children:u.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${v?"bg-primary":"bg-border"}`})}),u.jsxs("span",{className:"flex-1",children:[u.jsx("span",{className:"block font-medium leading-tight",children:p.label||"User input"}),u.jsxs("span",{className:"text-[9px] uppercase tracking-wide text-muted-foreground/70",children:[p.step!==null?`STEP ${p.step}`:"STEP —",p.next?` - ${p.next}`:""]}),g&&u.jsx("p",{className:"text-[10px] text-muted-foreground/80 mt-1 line-clamp-2",title:g,children:g})]})]},p.id)})})]}),n&&u.jsx("button",{type:"button",onClick:()=>n==null?void 0:n(null),className:"mt-auto mb-3 rounded-md border border-border/70 px-2 py-1 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground transition hover:border-foreground/60 hover:text-foreground",children:"Latest"})]})};function Ar(e){if(!(typeof globalThis>"u"))return globalThis[e]}function GT(e){if(typeof e!="string")return;const t=e.trim();if(t)return Cn(t)}function yp(){const e=[Ar("__API_BASE_URL__"),Ar("__CHAT_API_BASE_URL__"),Ar("__CHAT_API_URL__")];for(const t of e){const n=GT(t);if(n)return n}}function vp(){const e=[Ar("__API_AUTH_TOKEN__"),Ar("__CHAT_API_KEY__"),Ar("__CHAT_AUTH_TOKEN__")];for(const t of e)if(typeof t=="string"&&t.trim())return t.trim()}function bp(...e){for(const t of e)if(typeof t=="string"&&t.trim())return Cn(t);return Cn()}function wp(){const e={},t=yp(),n=vp();return t&&(e.baseUrl=t),n&&(e.apiKey=n),e}function Sp(){const e=wp(),t=Nn.getAuthToken(),n=yp();return{apiBaseUrl:bp(e.baseUrl,Nn.baseUrl,n),apiKey:t||e.apiKey||vp()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,darkMode:!1,enableSound:!1,messageHistory:100}}const Cp="chat-settings";function YT(){try{const e=localStorage.getItem(Cp);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function XT(e){try{const t={...e,apiBaseUrl:Cn(e.apiBaseUrl)};localStorage.setItem(Cp,JSON.stringify(t)),t.apiKey&&Nn.setAuthToken(t.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function JT(){const e=Sp(),t=YT(),n=Nn.getAuthToken(),r=typeof t.apiBaseUrl=="string"?t.apiBaseUrl:void 0;return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:bp(Nn.baseUrl,r,e.apiBaseUrl)}}function ZT(e){Nn.updateConfig({baseUrl:e.apiBaseUrl,authToken:e.apiKey??void 0}),XT(e)}var QT="Label",Tp=m.forwardRef((e,t)=>u.jsx(Se.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())}}));Tp.displayName=QT;var kp=Tp;const ek=bo.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),nn=m.forwardRef(({className:e,...t},n)=>u.jsx(kp,{ref:n,className:oe(ek(),e),...t}));nn.displayName=kp.displayName;function Ep(e){const t=m.useRef({value:e,previous:e});return m.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}var Ip=Object.freeze({position:"absolute",border:0,width:1,height:1,padding:0,margin:-1,overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",wordWrap:"normal"}),tk="VisuallyHidden",nk=m.forwardRef((e,t)=>u.jsx(Se.span,{...e,ref:t,style:{...Ip,...e.style}}));nk.displayName=tk;var rk=[" ","Enter","ArrowUp","ArrowDown"],ok=[" ","Enter"],ir="Select",[Zs,Qs,sk]=Ei(ir),[jr,EE]=Tn(ir,[sk,ts]),ei=ts(),[ik,Bn]=jr(ir),[ak,lk]=jr(ir),Np=e=>{const{__scopeSelect:t,children:n,open:r,defaultOpen:o,onOpenChange:s,value:i,defaultValue:a,onValueChange:l,dir:c,name:d,autoComplete:f,disabled:h,required:p,form:v}=e,g=ei(t),[y,x]=m.useState(null),[b,C]=m.useState(null),[k,S]=m.useState(!1),T=Uo(c),[E,j]=pr({prop:r,defaultProp:o??!1,onChange:s,caller:ir}),[R,O]=pr({prop:i,defaultProp:a,onChange:l,caller:ir}),B=m.useRef(null),q=y?v||!!y.closest("form"):!0,[K,P]=m.useState(new Set),M=Array.from(K).map(I=>I.props.value).join(";");return u.jsx(ju,{...g,children:u.jsxs(ik,{required:p,scope:t,trigger:y,onTriggerChange:x,valueNode:b,onValueNodeChange:C,valueNodeHasChildren:k,onValueNodeHasChildrenChange:S,contentId:$t(),value:R,onValueChange:O,open:E,onOpenChange:j,dir:T,triggerPointerDownPosRef:B,disabled:h,children:[u.jsx(Zs.Provider,{scope:t,children:u.jsx(ak,{scope:e.__scopeSelect,onNativeOptionAdd:m.useCallback(I=>{P(z=>new Set(z).add(I))},[]),onNativeOptionRemove:m.useCallback(I=>{P(z=>{const L=new Set(z);return L.delete(I),L})},[]),children:n})}),q?u.jsxs(Zp,{"aria-hidden":!0,required:p,tabIndex:-1,name:d,autoComplete:f,value:R,onChange:I=>O(I.target.value),disabled:h,form:v,children:[R===void 0?u.jsx("option",{value:""}):null,Array.from(K)]},M):null]})})};Np.displayName=ir;var Ap="SelectTrigger",jp=m.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...o}=e,s=ei(n),i=Bn(Ap,n),a=i.disabled||r,l=Ve(t,i.onTriggerChange),c=Qs(n),d=m.useRef("touch"),[f,h,p]=em(g=>{const y=c().filter(C=>!C.disabled),x=y.find(C=>C.value===i.value),b=tm(y,g,x);b!==void 0&&i.onValueChange(b.value)}),v=g=>{a||(i.onOpenChange(!0),p()),g&&(i.triggerPointerDownPosRef.current={x:Math.round(g.pageX),y:Math.round(g.pageY)})};return u.jsx(_u,{asChild:!0,...s,children:u.jsx(Se.button,{type:"button",role:"combobox","aria-controls":i.contentId,"aria-expanded":i.open,"aria-required":i.required,"aria-autocomplete":"none",dir:i.dir,"data-state":i.open?"open":"closed",disabled:a,"data-disabled":a?"":void 0,"data-placeholder":Qp(i.value)?"":void 0,...o,ref:l,onClick:he(o.onClick,g=>{g.currentTarget.focus(),d.current!=="mouse"&&v(g)}),onPointerDown:he(o.onPointerDown,g=>{d.current=g.pointerType;const y=g.target;y.hasPointerCapture(g.pointerId)&&y.releasePointerCapture(g.pointerId),g.button===0&&g.ctrlKey===!1&&g.pointerType==="mouse"&&(v(g),g.preventDefault())}),onKeyDown:he(o.onKeyDown,g=>{const y=f.current!=="";!(g.ctrlKey||g.altKey||g.metaKey)&&g.key.length===1&&h(g.key),!(y&&g.key===" ")&&rk.includes(g.key)&&(v(),g.preventDefault())})})})});jp.displayName=Ap;var _p="SelectValue",Mp=m.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,children:s,placeholder:i="",...a}=e,l=Bn(_p,n),{onValueNodeHasChildrenChange:c}=l,d=s!==void 0,f=Ve(t,l.onValueNodeChange);return It(()=>{c(d)},[c,d]),u.jsx(Se.span,{...a,ref:f,style:{pointerEvents:"none"},children:Qp(l.value)?u.jsx(u.Fragment,{children:i}):s})});Mp.displayName=_p;var ck="SelectIcon",Rp=m.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...o}=e;return u.jsx(Se.span,{"aria-hidden":!0,...o,ref:t,children:r||"▼"})});Rp.displayName=ck;var uk="SelectPortal",Pp=e=>u.jsx(ns,{asChild:!0,...e});Pp.displayName=uk;var ar="SelectContent",Op=m.forwardRef((e,t)=>{const n=Bn(ar,e.__scopeSelect),[r,o]=m.useState();if(It(()=>{o(new DocumentFragment)},[]),!n.open){const s=r;return s?wo.createPortal(u.jsx(Dp,{scope:e.__scopeSelect,children:u.jsx(Zs.Slot,{scope:e.__scopeSelect,children:u.jsx("div",{children:e.children})})}),s):null}return u.jsx(Lp,{...e,ref:t})});Op.displayName=ar;var dn=10,[Dp,zn]=jr(ar),dk="SelectContentImpl",fk=Wn.createSlot("SelectContent.RemoveScroll"),Lp=m.forwardRef((e,t)=>{const{__scopeSelect:n,position:r="item-aligned",onCloseAutoFocus:o,onEscapeKeyDown:s,onPointerDownOutside:i,side:a,sideOffset:l,align:c,alignOffset:d,arrowPadding:f,collisionBoundary:h,collisionPadding:p,sticky:v,hideWhenDetached:g,avoidCollisions:y,...x}=e,b=Bn(ar,n),[C,k]=m.useState(null),[S,T]=m.useState(null),E=Ve(t,Y=>k(Y)),[j,R]=m.useState(null),[O,B]=m.useState(null),q=Qs(n),[K,P]=m.useState(!1),M=m.useRef(!1);m.useEffect(()=>{if(C)return Gi(C)},[C]),Ai();const I=m.useCallback(Y=>{const[D,...V]=q().map(J=>J.ref.current),[U]=V.slice(-1),Z=document.activeElement;for(const J of Y)if(J===Z||(J==null||J.scrollIntoView({block:"nearest"}),J===D&&S&&(S.scrollTop=0),J===U&&S&&(S.scrollTop=S.scrollHeight),J==null||J.focus(),document.activeElement!==Z))return},[q,S]),z=m.useCallback(()=>I([j,C]),[I,j,C]);m.useEffect(()=>{K&&z()},[K,z]);const{onOpenChange:L,triggerPointerDownPosRef:A}=b;m.useEffect(()=>{if(C){let Y={x:0,y:0};const D=U=>{var Z,J;Y={x:Math.abs(Math.round(U.pageX)-(((Z=A.current)==null?void 0:Z.x)??0)),y:Math.abs(Math.round(U.pageY)-(((J=A.current)==null?void 0:J.y)??0))}},V=U=>{Y.x<=10&&Y.y<=10?U.preventDefault():C.contains(U.target)||L(!1),document.removeEventListener("pointermove",D),A.current=null};return A.current!==null&&(document.addEventListener("pointermove",D),document.addEventListener("pointerup",V,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",D),document.removeEventListener("pointerup",V,{capture:!0})}}},[C,L,A]),m.useEffect(()=>{const Y=()=>L(!1);return window.addEventListener("blur",Y),window.addEventListener("resize",Y),()=>{window.removeEventListener("blur",Y),window.removeEventListener("resize",Y)}},[L]);const[$,H]=em(Y=>{const D=q().filter(Z=>!Z.disabled),V=D.find(Z=>Z.ref.current===document.activeElement),U=tm(D,Y,V);U&&setTimeout(()=>U.ref.current.focus())}),_=m.useCallback((Y,D,V)=>{const U=!M.current&&!V;(b.value!==void 0&&b.value===D||U)&&(R(Y),U&&(M.current=!0))},[b.value]),G=m.useCallback(()=>C==null?void 0:C.focus(),[C]),re=m.useCallback((Y,D,V)=>{const U=!M.current&&!V;(b.value!==void 0&&b.value===D||U)&&B(Y)},[b.value]),ee=r==="popper"?sl:$p,ie=ee===sl?{side:a,sideOffset:l,align:c,alignOffset:d,arrowPadding:f,collisionBoundary:h,collisionPadding:p,sticky:v,hideWhenDetached:g,avoidCollisions:y}:{};return u.jsx(Dp,{scope:n,content:C,viewport:S,onViewportChange:T,itemRefCallback:_,selectedItem:j,onItemLeave:G,itemTextRefCallback:re,focusSelectedItem:z,selectedItemText:O,position:r,isPositioned:K,searchRef:$,children:u.jsx(ds,{as:fk,allowPinchZoom:!0,children:u.jsx(Wo,{asChild:!0,trapped:b.open,onMountAutoFocus:Y=>{Y.preventDefault()},onUnmountAutoFocus:he(o,Y=>{var D;(D=b.trigger)==null||D.focus({preventScroll:!0}),Y.preventDefault()}),children:u.jsx(Ho,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:Y=>Y.preventDefault(),onDismiss:()=>b.onOpenChange(!1),children:u.jsx(ee,{role:"listbox",id:b.contentId,"data-state":b.open?"open":"closed",dir:b.dir,onContextMenu:Y=>Y.preventDefault(),...x,...ie,onPlaced:()=>P(!0),ref:E,style:{display:"flex",flexDirection:"column",outline:"none",...x.style},onKeyDown:he(x.onKeyDown,Y=>{const D=Y.ctrlKey||Y.altKey||Y.metaKey;if(Y.key==="Tab"&&Y.preventDefault(),!D&&Y.key.length===1&&H(Y.key),["ArrowUp","ArrowDown","Home","End"].includes(Y.key)){let U=q().filter(Z=>!Z.disabled).map(Z=>Z.ref.current);if(["ArrowUp","End"].includes(Y.key)&&(U=U.slice().reverse()),["ArrowUp","ArrowDown"].includes(Y.key)){const Z=Y.target,J=U.indexOf(Z);U=U.slice(J+1)}setTimeout(()=>I(U)),Y.preventDefault()}})})})})})})});Lp.displayName=dk;var hk="SelectItemAlignedPosition",$p=m.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...o}=e,s=Bn(ar,n),i=zn(ar,n),[a,l]=m.useState(null),[c,d]=m.useState(null),f=Ve(t,E=>d(E)),h=Qs(n),p=m.useRef(!1),v=m.useRef(!0),{viewport:g,selectedItem:y,selectedItemText:x,focusSelectedItem:b}=i,C=m.useCallback(()=>{if(s.trigger&&s.valueNode&&a&&c&&g&&y&&x){const E=s.trigger.getBoundingClientRect(),j=c.getBoundingClientRect(),R=s.valueNode.getBoundingClientRect(),O=x.getBoundingClientRect();if(s.dir!=="rtl"){const Z=O.left-j.left,J=R.left-Z,ge=E.left-J,ce=E.width+ge,ne=Math.max(ce,j.width),pe=window.innerWidth-dn,be=qa(J,[dn,Math.max(dn,pe-ne)]);a.style.minWidth=ce+"px",a.style.left=be+"px"}else{const Z=j.right-O.right,J=window.innerWidth-R.right-Z,ge=window.innerWidth-E.right-J,ce=E.width+ge,ne=Math.max(ce,j.width),pe=window.innerWidth-dn,be=qa(J,[dn,Math.max(dn,pe-ne)]);a.style.minWidth=ce+"px",a.style.right=be+"px"}const B=h(),q=window.innerHeight-dn*2,K=g.scrollHeight,P=window.getComputedStyle(c),M=parseInt(P.borderTopWidth,10),I=parseInt(P.paddingTop,10),z=parseInt(P.borderBottomWidth,10),L=parseInt(P.paddingBottom,10),A=M+I+K+L+z,$=Math.min(y.offsetHeight*5,A),H=window.getComputedStyle(g),_=parseInt(H.paddingTop,10),G=parseInt(H.paddingBottom,10),re=E.top+E.height/2-dn,ee=q-re,ie=y.offsetHeight/2,Y=y.offsetTop+ie,D=M+I+Y,V=A-D;if(D<=re){const Z=B.length>0&&y===B[B.length-1].ref.current;a.style.bottom="0px";const J=c.clientHeight-g.offsetTop-g.offsetHeight,ge=Math.max(ee,ie+(Z?G:0)+J+z),ce=D+ge;a.style.height=ce+"px"}else{const Z=B.length>0&&y===B[0].ref.current;a.style.top="0px";const ge=Math.max(re,M+g.offsetTop+(Z?_:0)+ie)+V;a.style.height=ge+"px",g.scrollTop=D-re+g.offsetTop}a.style.margin=`${dn}px 0`,a.style.minHeight=$+"px",a.style.maxHeight=q+"px",r==null||r(),requestAnimationFrame(()=>p.current=!0)}},[h,s.trigger,s.valueNode,a,c,g,y,x,s.dir,r]);It(()=>C(),[C]);const[k,S]=m.useState();It(()=>{c&&S(window.getComputedStyle(c).zIndex)},[c]);const T=m.useCallback(E=>{E&&v.current===!0&&(C(),b==null||b(),v.current=!1)},[C,b]);return u.jsx(mk,{scope:n,contentWrapper:a,shouldExpandOnScrollRef:p,onScrollButtonChange:T,children:u.jsx("div",{ref:l,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:k},children:u.jsx(Se.div,{...o,ref:f,style:{boxSizing:"border-box",maxHeight:"100%",...o.style}})})})});$p.displayName=hk;var pk="SelectPopperPosition",sl=m.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=dn,...s}=e,i=ei(n);return u.jsx(Mu,{...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)"}})});sl.displayName=pk;var[mk,il]=jr(ar,{}),al="SelectViewport",Fp=m.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...o}=e,s=zn(al,n),i=il(al,n),a=Ve(t,s.onViewportChange),l=m.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(Zs.Slot,{scope:n,children:u.jsx(Se.div,{"data-radix-select-viewport":"",role:"presentation",...o,ref:a,style:{position:"relative",flex:1,overflow:"hidden auto",...o.style},onScroll:he(o.onScroll,c=>{const d=c.currentTarget,{contentWrapper:f,shouldExpandOnScrollRef:h}=i;if(h!=null&&h.current&&f){const p=Math.abs(l.current-d.scrollTop);if(p>0){const v=window.innerHeight-dn*2,g=parseFloat(f.style.minHeight),y=parseFloat(f.style.height),x=Math.max(g,y);if(x<v){const b=x+p,C=Math.min(v,b),k=b-C;f.style.height=C+"px",f.style.bottom==="0px"&&(d.scrollTop=k>0?k:0,f.style.justifyContent="flex-end")}}}l.current=d.scrollTop})})})]})});Fp.displayName=al;var Bp="SelectGroup",[gk,xk]=jr(Bp),yk=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=$t();return u.jsx(gk,{scope:n,id:o,children:u.jsx(Se.div,{role:"group","aria-labelledby":o,...r,ref:t})})});yk.displayName=Bp;var zp="SelectLabel",Up=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=xk(zp,n);return u.jsx(Se.div,{id:o.id,...r,ref:t})});Up.displayName=zp;var ti="SelectItem",[vk,Hp]=jr(ti),Wp=m.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:s,...i}=e,a=Bn(ti,n),l=zn(ti,n),c=a.value===r,[d,f]=m.useState(s??""),[h,p]=m.useState(!1),v=Ve(t,b=>{var C;return(C=l.itemRefCallback)==null?void 0:C.call(l,b,r,o)}),g=$t(),y=m.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(vk,{scope:n,value:r,disabled:o,textId:g,isSelected:c,onItemTextChange:m.useCallback(b=>{f(C=>C||((b==null?void 0:b.textContent)??"").trim())},[]),children:u.jsx(Zs.ItemSlot,{scope:n,value:r,disabled:o,textValue:d,children:u.jsx(Se.div,{role:"option","aria-labelledby":g,"data-highlighted":h?"":void 0,"aria-selected":c&&h,"data-state":c?"checked":"unchecked","aria-disabled":o||void 0,"data-disabled":o?"":void 0,tabIndex:o?void 0:-1,...i,ref:v,onFocus:he(i.onFocus,()=>p(!0)),onBlur:he(i.onBlur,()=>p(!1)),onClick:he(i.onClick,()=>{y.current!=="mouse"&&x()}),onPointerUp:he(i.onPointerUp,()=>{y.current==="mouse"&&x()}),onPointerDown:he(i.onPointerDown,b=>{y.current=b.pointerType}),onPointerMove:he(i.onPointerMove,b=>{var C;y.current=b.pointerType,o?(C=l.onItemLeave)==null||C.call(l):y.current==="mouse"&&b.currentTarget.focus({preventScroll:!0})}),onPointerLeave:he(i.onPointerLeave,b=>{var C;b.currentTarget===document.activeElement&&((C=l.onItemLeave)==null||C.call(l))}),onKeyDown:he(i.onKeyDown,b=>{var k;((k=l.searchRef)==null?void 0:k.current)!==""&&b.key===" "||(ok.includes(b.key)&&x(),b.key===" "&&b.preventDefault())})})})})});Wp.displayName=ti;var xo="SelectItemText",Vp=m.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,...s}=e,i=Bn(xo,n),a=zn(xo,n),l=Hp(xo,n),c=lk(xo,n),[d,f]=m.useState(null),h=Ve(t,x=>f(x),l.onItemTextChange,x=>{var b;return(b=a.itemTextRefCallback)==null?void 0:b.call(a,x,l.value,l.disabled)}),p=d==null?void 0:d.textContent,v=m.useMemo(()=>u.jsx("option",{value:l.value,disabled:l.disabled,children:p},l.value),[l.disabled,l.value,p]),{onNativeOptionAdd:g,onNativeOptionRemove:y}=c;return It(()=>(g(v),()=>y(v)),[g,y,v]),u.jsxs(u.Fragment,{children:[u.jsx(Se.span,{id:l.textId,...s,ref:h}),l.isSelected&&i.valueNode&&!i.valueNodeHasChildren?wo.createPortal(s.children,i.valueNode):null]})});Vp.displayName=xo;var Kp="SelectItemIndicator",qp=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return Hp(Kp,n).isSelected?u.jsx(Se.span,{"aria-hidden":!0,...r,ref:t}):null});qp.displayName=Kp;var ll="SelectScrollUpButton",Gp=m.forwardRef((e,t)=>{const n=zn(ll,e.__scopeSelect),r=il(ll,e.__scopeSelect),[o,s]=m.useState(!1),i=Ve(t,r.onScrollButtonChange);return It(()=>{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(Xp,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop-l.offsetHeight)}}):null});Gp.displayName=ll;var cl="SelectScrollDownButton",Yp=m.forwardRef((e,t)=>{const n=zn(cl,e.__scopeSelect),r=il(cl,e.__scopeSelect),[o,s]=m.useState(!1),i=Ve(t,r.onScrollButtonChange);return It(()=>{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(Xp,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop+l.offsetHeight)}}):null});Yp.displayName=cl;var Xp=m.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...o}=e,s=zn("SelectScrollButton",n),i=m.useRef(null),a=Qs(n),l=m.useCallback(()=>{i.current!==null&&(window.clearInterval(i.current),i.current=null)},[]);return m.useEffect(()=>()=>l(),[l]),It(()=>{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(Se.div,{"aria-hidden":!0,...o,ref:t,style:{flexShrink:0,...o.style},onPointerDown:he(o.onPointerDown,()=>{i.current===null&&(i.current=window.setInterval(r,50))}),onPointerMove:he(o.onPointerMove,()=>{var c;(c=s.onItemLeave)==null||c.call(s),i.current===null&&(i.current=window.setInterval(r,50))}),onPointerLeave:he(o.onPointerLeave,()=>{l()})})}),bk="SelectSeparator",Jp=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return u.jsx(Se.div,{"aria-hidden":!0,...r,ref:t})});Jp.displayName=bk;var ul="SelectArrow",wk=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=ei(n),s=Bn(ul,n),i=zn(ul,n);return s.open&&i.position==="popper"?u.jsx(Ru,{...o,...r,ref:t}):null});wk.displayName=ul;var Sk="SelectBubbleInput",Zp=m.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const o=m.useRef(null),s=Ve(r,o),i=Ep(t);return m.useEffect(()=>{const a=o.current;if(!a)return;const l=window.HTMLSelectElement.prototype,d=Object.getOwnPropertyDescriptor(l,"value").set;if(i!==t&&d){const f=new Event("change",{bubbles:!0});d.call(a,t),a.dispatchEvent(f)}},[i,t]),u.jsx(Se.select,{...n,style:{...Ip,...n.style},ref:s,defaultValue:t})});Zp.displayName=Sk;function Qp(e){return e===""||e===void 0}function em(e){const t=Nt(e),n=m.useRef(""),r=m.useRef(0),o=m.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=m.useCallback(()=>{n.current="",window.clearTimeout(r.current)},[]);return m.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,o,s]}function tm(e,t,n){const o=t.length>1&&Array.from(t).every(c=>c===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let i=Ck(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 Ck(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Tk=Np,nm=jp,kk=Mp,Ek=Rp,Ik=Pp,rm=Op,Nk=Fp,om=Up,sm=Wp,Ak=Vp,jk=qp,im=Gp,am=Yp,lm=Jp;const cm=Tk,um=kk,dl=m.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(nm,{ref:r,className:oe("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(Ek,{asChild:!0,children:u.jsx(ae.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));dl.displayName=nm.displayName;const dm=m.forwardRef(({className:e,...t},n)=>u.jsx(im,{ref:n,className:oe("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(ae.ChevronUp,{className:"h-4 w-4"})}));dm.displayName=im.displayName;const fm=m.forwardRef(({className:e,...t},n)=>u.jsx(am,{ref:n,className:oe("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(ae.ChevronDown,{className:"h-4 w-4"})}));fm.displayName=am.displayName;const fl=m.forwardRef(({className:e,children:t,position:n="popper",...r},o)=>u.jsx(Ik,{children:u.jsxs(rm,{ref:o,className:oe("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(dm,{}),u.jsx(Nk,{className:oe("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),u.jsx(fm,{})]})}));fl.displayName=rm.displayName;const _k=m.forwardRef(({className:e,...t},n)=>u.jsx(om,{ref:n,className:oe("py-1.5 pl-8 pr-2 text-sm font-semibold",e),...t}));_k.displayName=om.displayName;const lr=m.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(sm,{ref:r,className:oe("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(jk,{children:u.jsx(ae.Check,{className:"h-4 w-4"})})}),u.jsx(Ak,{children:t})]}));lr.displayName=sm.displayName;const Mk=m.forwardRef(({className:e,...t},n)=>u.jsx(lm,{ref:n,className:oe("-mx-1 my-1 h-px bg-muted",e),...t}));Mk.displayName=lm.displayName;var Rk="Separator",hm="horizontal",Pk=["horizontal","vertical"],pm=m.forwardRef((e,t)=>{const{decorative:n,orientation:r=hm,...o}=e,s=Ok(r)?r:hm,a=n?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return u.jsx(Se.div,{"data-orientation":s,...a,...o,ref:t})});pm.displayName=Rk;function Ok(e){return Pk.includes(e)}var mm=pm;const gm=m.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},o)=>u.jsx(mm,{ref:o,decorative:n,orientation:t,className:oe("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));gm.displayName=mm.displayName;const Dk=Da,Lk=yC,$k=La,xm=m.forwardRef(({className:e,...t},n)=>u.jsx(io,{className:oe("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",e),...t,ref:n}));xm.displayName=io.displayName;const Fk=bo.cva("fixed z-50 gap-4 bg-background p-6 shadow-lg transition ease-in-out data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:duration-300 data-[state=open]:duration-500",{variants:{side:{top:"inset-x-0 top-0 border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",bottom:"inset-x-0 bottom-0 border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",left:"inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm",right:"inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm"}},defaultVariants:{side:"right"}}),ym=m.forwardRef(({side:e="right",className:t,children:n,...r},o)=>u.jsxs($k,{children:[u.jsx(xm,{}),u.jsxs(ao,{ref:o,className:oe(Fk({side:e}),t),...r,children:[n,u.jsxs(ph,{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(ae.X,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));ym.displayName=ao.displayName;const vm=({className:e,...t})=>u.jsx("div",{className:oe("flex flex-col space-y-2 text-center sm:text-left",e),...t});vm.displayName="SheetHeader";const bm=m.forwardRef(({className:e,...t},n)=>u.jsx(rr,{ref:n,className:oe("text-lg font-semibold text-foreground",e),...t}));bm.displayName=rr.displayName;const wm=m.forwardRef(({className:e,...t},n)=>u.jsx(Ls,{ref:n,className:oe("text-sm text-muted-foreground",e),...t}));wm.displayName=Ls.displayName;var ni="Switch",[Bk,IE]=Tn(ni),[zk,Uk]=Bk(ni),Sm=m.forwardRef((e,t)=>{const{__scopeSwitch:n,name:r,checked:o,defaultChecked:s,required:i,disabled:a,value:l="on",onCheckedChange:c,form:d,...f}=e,[h,p]=m.useState(null),v=Ve(t,C=>p(C)),g=m.useRef(!1),y=h?d||!!h.closest("form"):!0,[x,b]=pr({prop:o,defaultProp:s??!1,onChange:c,caller:ni});return u.jsxs(zk,{scope:n,checked:x,disabled:a,children:[u.jsx(Se.button,{type:"button",role:"switch","aria-checked":x,"aria-required":i,"data-state":Em(x),"data-disabled":a?"":void 0,disabled:a,value:l,...f,ref:v,onClick:he(e.onClick,C=>{b(k=>!k),y&&(g.current=C.isPropagationStopped(),g.current||C.stopPropagation())})}),y&&u.jsx(km,{control:h,bubbles:!g.current,name:r,value:l,checked:x,required:i,disabled:a,form:d,style:{transform:"translateX(-100%)"}})]})});Sm.displayName=ni;var Cm="SwitchThumb",Tm=m.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,o=Uk(Cm,n);return u.jsx(Se.span,{"data-state":Em(o.checked),"data-disabled":o.disabled?"":void 0,...r,ref:t})});Tm.displayName=Cm;var Hk="SwitchBubbleInput",km=m.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...o},s)=>{const i=m.useRef(null),a=Ve(i,s),l=Ep(n),c=bu(t);return m.useEffect(()=>{const d=i.current;if(!d)return;const f=window.HTMLInputElement.prototype,p=Object.getOwnPropertyDescriptor(f,"checked").set;if(l!==n&&p){const v=new Event("click",{bubbles:r});p.call(d,n),d.dispatchEvent(v)}},[l,n,r]),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}})});km.displayName=Hk;function Em(e){return e?"checked":"unchecked"}var Im=Sm,Wk=Tm;const Un=m.forwardRef(({className:e,...t},n)=>u.jsx(Im,{className:oe("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(Wk,{className:oe("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=Im.displayName;const Vk={api:{baseUrl:"http://localhost:8000/api",authToken:"",enableAuth:!1},ui:{layout:"sidebar",theme:"light",showTimestamps:!0,showAgentNames:!0,compactMessages:!1},behavior:{autoSave:!0,enableStreaming:!0,showTypingIndicator:!0}};function Kk({settings:e,onSettingsChange:t,className:n=""}){const[r,o]=w.useState(!1),[s,i]=w.useState(!1),[a,l]=w.useState(e),[c,d]=w.useState(!1),{toast:f}=Ha();w.useEffect(()=>{const y=JSON.stringify(a)!==JSON.stringify(e);d(y)},[a,e]),w.useEffect(()=>{l(e)},[e]);const h=()=>{t(a),d(!1),f({title:"Settings saved",description:"Your chat configuration has been updated successfully."})},p=()=>{l(Vk),d(!0),f({title:"Settings reset",description:"Configuration has been reset to defaults."})},v=()=>{l(e),d(!1),o(!1)},g=async()=>{try{const x=await(await fetch(`${a.api.baseUrl}/health`)).json();f({title:"Connection successful",description:`API is ${x.status||"healthy"}`})}catch{f({title:"Connection failed",description:"Unable to connect to the API endpoint.",variant:"destructive"})}};return u.jsxs(Dk,{open:r,onOpenChange:o,children:[u.jsx(Lk,{asChild:!0,children:u.jsxs(et,{variant:"outline",size:"sm",className:n,children:[u.jsx(ae.Settings,{className:"h-4 w-4 mr-2"}),"Settings",c&&u.jsx(Kf,{variant:"destructive",className:"ml-2 h-4 w-4 p-0"})]})}),u.jsxs(ym,{className:"w-[500px] sm:w-[600px] overflow-y-auto",children:[u.jsxs(vm,{children:[u.jsx(bm,{children:"Chat Settings"}),u.jsx(wm,{children:"Configure your chat interface, API connection, and behavior preferences."})]}),u.jsxs("div",{className:"space-y-6 py-6",children:[u.jsxs(uo,{children:[u.jsx(fo,{className:"pb-3",children:u.jsxs(ho,{className:"text-lg flex items-center gap-2",children:[u.jsx(ae.Server,{className:"h-5 w-5"}),"API Configuration"]})}),u.jsxs(po,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(nn,{htmlFor:"api-url",children:"API Base URL"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(Js,{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(et,{variant:"outline",onClick:g,children:"Test"})]})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(nn,{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(nn,{htmlFor:"auth-token",children:"Authentication Token"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(Js,{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(et,{variant:"outline",size:"icon",onClick:()=>i(!s),children:s?u.jsx(ae.EyeOff,{className:"h-4 w-4"}):u.jsx(ae.Eye,{className:"h-4 w-4"})})]})]})]})]}),u.jsxs(uo,{children:[u.jsx(fo,{className:"pb-3",children:u.jsxs(ho,{className:"text-lg flex items-center gap-2",children:[u.jsx(ae.Layout,{className:"h-5 w-5"}),"Interface Settings"]})}),u.jsxs(po,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(nn,{htmlFor:"layout",children:"Layout Style"}),u.jsxs(cm,{value:a.ui.layout,onValueChange:y=>l(x=>({...x,ui:{...x.ui,layout:y}})),children:[u.jsx(dl,{children:u.jsx(um,{})}),u.jsxs(fl,{children:[u.jsx(lr,{value:"sidebar",children:"Sidebar Layout"}),u.jsx(lr,{value:"fullscreen",children:"Fullscreen"}),u.jsx(lr,{value:"tabs",children:"Tabbed Interface"})]})]})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx(nn,{htmlFor:"theme",children:"Theme"}),u.jsxs(cm,{value:a.ui.theme,onValueChange:y=>l(x=>({...x,ui:{...x.ui,theme:y}})),children:[u.jsx(dl,{children:u.jsx(um,{})}),u.jsxs(fl,{children:[u.jsx(lr,{value:"light",children:"Light"}),u.jsx(lr,{value:"dark",children:"Dark"}),u.jsx(lr,{value:"system",children:"System"})]})]})]}),u.jsx(gm,{}),u.jsxs("div",{className:"space-y-3",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(nn,{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(nn,{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(nn,{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(uo,{children:[u.jsx(fo,{className:"pb-3",children:u.jsxs(ho,{className:"text-lg flex items-center gap-2",children:[u.jsx(ae.MessageCircle,{className:"h-5 w-5"}),"Behavior Settings"]})}),u.jsxs(po,{className:"space-y-4",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(nn,{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(nn,{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(nn,{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(et,{variant:"outline",onClick:p,children:[u.jsx(ae.RotateCcw,{className:"h-4 w-4 mr-2"}),"Reset"]}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(et,{variant:"outline",onClick:v,children:"Cancel"}),u.jsxs(et,{onClick:h,disabled:!c,children:[u.jsx(ae.Save,{className:"h-4 w-4 mr-2"}),"Save Changes"]})]})]})]})]})}function qk({layout:e="sidebar",layoutSize:t="desktop",showThreads:n=!0,className:r="",customStyles:o={},...s}){const i=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(zo,{...s,onThreadChange:l,children:u.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:u.jsx(Vs,{className:"flex-1",onError:s.onError,enableFileUpload:!0})})}):e==="tabs"?u.jsx(zo,{...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(ol,{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(Vs,{onError:s.onError,enableFileUpload:!0})})]})})}):u.jsx(zo,{...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(ol,{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(Vs,{onError:s.onError,enableFileUpload:!0})})]})})}ke.ChatApi=cc,ke.ChatInput=$c,ke.ChatInterface=Vs,ke.ChatProviders=zo,ke.ChatSettings=Kk,ke.MarkdownContent=co,ke.MessageComponent=Ws,ke.MessageList=Ka,ke.ThreadManager=ol,ke.TimelineColumn=qT,ke.applySettings=ZT,ke.buildMessagePreviewMap=lx,ke.chatApiClient=Nn,ke.default=qk,ke.del=bi,ke.get=Wt,ke.getChatToken=ic,ke.getCurrentSettings=JT,ke.getDefaultApiConfig=wp,ke.getDefaultChatSettings=Sp,ke.onChatTokenChanged=ac,ke.post=Po,ke.put=lc,ke.setChatToken=Ro,ke.useApi=wi,ke.useChatStream=_c,ke.useMessagesReducer=Ac,ke.useStream=Dc,ke.useThreadState=Bo,ke.useThreads=Fo,Object.defineProperties(ke,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|