teodor-new-chat-ui 4.2.8 → 4.3.3
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/context/reducers/MessageReducer.d.ts +9 -1
- package/dist/index.esm.js +5480 -5293
- package/dist/index.umd.js +49 -49
- package/dist/lib/historyUtils.d.ts +17 -7
- package/dist/types/api.d.ts +8 -0
- package/package.json +1 -1
package/dist/index.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(je,y){typeof exports=="object"&&typeof module<"u"?y(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"],y):(je=typeof globalThis<"u"?globalThis:je||self,y(je.NewChatUI={},je.React,je.LucideReact,je.reactSlot,je.classVarianceAuthority,je.clsx,je.tailwindMerge,je.ReactDOM))})(this,function(je,y,
|
|
1
|
+
(function(je,y){typeof exports=="object"&&typeof module<"u"?y(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"],y):(je=typeof globalThis<"u"?globalThis:je||self,y(je.NewChatUI={},je.React,je.LucideReact,je.reactSlot,je.classVarianceAuthority,je.clsx,je.tailwindMerge,je.ReactDOM))})(this,function(je,y,se,Jn,To,hm,pm,ii){"use strict";var xT=Object.defineProperty;var vT=(je,y,se)=>y in je?xT(je,y,{enumerable:!0,configurable:!0,writable:!0,value:se}):je[y]=se;var dm=(je,y,se)=>vT(je,typeof y!="symbol"?y+"":y,se);function ml(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=ml(y),ko=ml(ii);var ai={exports:{}},Hr={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* react-jsx-runtime.production.min.js
|
|
4
4
|
*
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var
|
|
9
|
+
*/var gl;function mm(){if(gl)return Hr;gl=1;var e=y,t=Symbol.for("react.element"),n=Symbol.for("react.fragment"),r=Object.prototype.hasOwnProperty,o=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,s={key:!0,ref:!0,__self:!0,__source:!0};function i(a,l,u){var d,f={},h=null,p=null;u!==void 0&&(h=""+u),l.key!==void 0&&(h=""+l.key),l.ref!==void 0&&(p=l.ref);for(d in l)r.call(l,d)&&!s.hasOwnProperty(d)&&(f[d]=l[d]);if(a&&a.defaultProps)for(d in l=a.defaultProps,l)f[d]===void 0&&(f[d]=l[d]);return{$$typeof:t,type:a,key:h,ref:p,props:f,_owner:o.current}}return Hr.Fragment=n,Hr.jsx=i,Hr.jsxs=i,Hr}var Ur={};/**
|
|
10
10
|
* @license React
|
|
11
11
|
* react-jsx-runtime.development.js
|
|
12
12
|
*
|
|
@@ -14,42 +14,42 @@
|
|
|
14
14
|
*
|
|
15
15
|
* This source code is licensed under the MIT license found in the
|
|
16
16
|
* LICENSE file in the root directory of this source tree.
|
|
17
|
-
*/var
|
|
18
|
-
`+
|
|
19
|
-
`),
|
|
20
|
-
`),
|
|
21
|
-
`+ze[
|
|
17
|
+
*/var xl;function gm(){return xl||(xl=1,process.env.NODE_ENV!=="production"&&function(){var e=y,t=Symbol.for("react.element"),n=Symbol.for("react.portal"),r=Symbol.for("react.fragment"),o=Symbol.for("react.strict_mode"),s=Symbol.for("react.profiler"),i=Symbol.for("react.provider"),a=Symbol.for("react.context"),l=Symbol.for("react.forward_ref"),u=Symbol.for("react.suspense"),d=Symbol.for("react.suspense_list"),f=Symbol.for("react.memo"),h=Symbol.for("react.lazy"),p=Symbol.for("react.offscreen"),b=Symbol.iterator,x="@@iterator";function g(I){if(I===null||typeof I!="object")return null;var H=b&&I[b]||I[x];return typeof H=="function"?H:null}var v=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function w(I){{for(var H=arguments.length,J=new Array(H>1?H-1:0),Ee=1;Ee<H;Ee++)J[Ee-1]=arguments[Ee];S("error",I,J)}}function S(I,H,J){{var Ee=v.ReactDebugCurrentFrame,$e=Ee.getStackAddendum();$e!==""&&(H+="%s",J=J.concat([$e]));var Xe=J.map(function(Ve){return String(Ve)});Xe.unshift("Warning: "+H),Function.prototype.apply.call(console[I],console,Xe)}}var N=!1,T=!1,k=!1,E=!1,A=!1,j;j=Symbol.for("react.module.reference");function P(I){return!!(typeof I=="string"||typeof I=="function"||I===r||I===s||A||I===o||I===u||I===d||E||I===p||N||T||k||typeof I=="object"&&I!==null&&(I.$$typeof===h||I.$$typeof===f||I.$$typeof===i||I.$$typeof===a||I.$$typeof===l||I.$$typeof===j||I.getModuleId!==void 0))}function L(I,H,J){var Ee=I.displayName;if(Ee)return Ee;var $e=H.displayName||H.name||"";return $e!==""?J+"("+$e+")":J}function $(I){return I.displayName||"Context"}function V(I){if(I==null)return null;if(typeof I.tag=="number"&&w("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof I=="function")return I.displayName||I.name||null;if(typeof I=="string")return I;switch(I){case r:return"Fragment";case n:return"Portal";case s:return"Profiler";case o:return"StrictMode";case u:return"Suspense";case d:return"SuspenseList"}if(typeof I=="object")switch(I.$$typeof){case a:var H=I;return $(H)+".Consumer";case i:var J=I;return $(J._context)+".Provider";case l:return L(I,I.render,"ForwardRef");case f:var Ee=I.displayName||null;return Ee!==null?Ee:V(I.type)||"Memo";case h:{var $e=I,Xe=$e._payload,Ve=$e._init;try{return V(Ve(Xe))}catch{return null}}}return null}var M=Object.assign,G=0,K,W,B,F,ue,D,ee;function fe(){}fe.__reactDisabledLog=!0;function we(){{if(G===0){K=console.log,W=console.info,B=console.warn,F=console.error,ue=console.group,D=console.groupCollapsed,ee=console.groupEnd;var I={configurable:!0,enumerable:!0,value:fe,writable:!0};Object.defineProperties(console,{info:I,log:I,warn:I,error:I,group:I,groupCollapsed:I,groupEnd:I})}G++}}function ye(){{if(G--,G===0){var I={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:M({},I,{value:K}),info:M({},I,{value:W}),warn:M({},I,{value:B}),error:M({},I,{value:F}),group:M({},I,{value:ue}),groupCollapsed:M({},I,{value:D}),groupEnd:M({},I,{value:ee})})}G<0&&w("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var Ce=v.ReactCurrentDispatcher,q;function O(I,H,J){{if(q===void 0)try{throw Error()}catch($e){var Ee=$e.stack.trim().match(/\n( *(at )?)/);q=Ee&&Ee[1]||""}return`
|
|
18
|
+
`+q+I}}var X=!1,te;{var he=typeof WeakMap=="function"?WeakMap:Map;te=new he}function re(I,H){if(!I||X)return"";{var J=te.get(I);if(J!==void 0)return J}var Ee;X=!0;var $e=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var Xe;Xe=Ce.current,Ce.current=null,we();try{if(H){var Ve=function(){throw Error()};if(Object.defineProperty(Ve.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(Ve,[])}catch(jt){Ee=jt}Reflect.construct(I,[],Ve)}else{try{Ve.call()}catch(jt){Ee=jt}I.call(Ve.prototype)}}else{try{throw Error()}catch(jt){Ee=jt}I()}}catch(jt){if(jt&&Ee&&typeof jt.stack=="string"){for(var ze=jt.stack.split(`
|
|
19
|
+
`),Tt=Ee.stack.split(`
|
|
20
|
+
`),ht=ze.length-1,dt=Tt.length-1;ht>=1&&dt>=0&&ze[ht]!==Tt[dt];)dt--;for(;ht>=1&&dt>=0;ht--,dt--)if(ze[ht]!==Tt[dt]){if(ht!==1||dt!==1)do if(ht--,dt--,dt<0||ze[ht]!==Tt[dt]){var Dt=`
|
|
21
|
+
`+ze[ht].replace(" at new "," at ");return I.displayName&&Dt.includes("<anonymous>")&&(Dt=Dt.replace("<anonymous>",I.displayName)),typeof I=="function"&&te.set(I,Dt),Dt}while(ht>=1&&dt>=0);break}}}finally{X=!1,Ce.current=Xe,ye(),Error.prepareStackTrace=$e}var Gn=I?I.displayName||I.name:"",Pn=Gn?O(Gn):"";return typeof I=="function"&&te.set(I,Pn),Pn}function pe(I,H,J){return re(I,!1)}function tt(I){var H=I.prototype;return!!(H&&H.isReactComponent)}function nt(I,H,J){if(I==null)return"";if(typeof I=="function")return re(I,tt(I));if(typeof I=="string")return O(I);switch(I){case u:return O("Suspense");case d:return O("SuspenseList")}if(typeof I=="object")switch(I.$$typeof){case l:return pe(I.render);case f:return nt(I.type,H,J);case h:{var Ee=I,$e=Ee._payload,Xe=Ee._init;try{return nt(Xe($e),H,J)}catch{}}}return""}var Pe=Object.prototype.hasOwnProperty,He={},ut=v.ReactDebugCurrentFrame;function rt(I){if(I){var H=I._owner,J=nt(I.type,I._source,H?H.type:null);ut.setExtraStackFrame(J)}else ut.setExtraStackFrame(null)}function Ue(I,H,J,Ee,$e){{var Xe=Function.call.bind(Pe);for(var Ve in I)if(Xe(I,Ve)){var ze=void 0;try{if(typeof I[Ve]!="function"){var Tt=Error((Ee||"React class")+": "+J+" type `"+Ve+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof I[Ve]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw Tt.name="Invariant Violation",Tt}ze=I[Ve](H,Ve,Ee,J,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(ht){ze=ht}ze&&!(ze instanceof Error)&&(rt($e),w("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",Ee||"React class",J,Ve,typeof ze),rt(null)),ze instanceof Error&&!(ze.message in He)&&(He[ze.message]=!0,rt($e),w("Failed %s type: %s",J,ze.message),rt(null))}}}var bt=Array.isArray;function Z(I){return bt(I)}function oe(I){{var H=typeof Symbol=="function"&&Symbol.toStringTag,J=H&&I[Symbol.toStringTag]||I.constructor.name||"Object";return J}}function me(I){try{return Te(I),!1}catch{return!0}}function Te(I){return""+I}function ge(I){if(me(I))return w("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",oe(I)),Te(I)}var Oe=v.ReactCurrentOwner,at={key:!0,ref:!0,__self:!0,__source:!0},Me,it;function mt(I){if(Pe.call(I,"ref")){var H=Object.getOwnPropertyDescriptor(I,"ref").get;if(H&&H.isReactWarning)return!1}return I.ref!==void 0}function Ct(I){if(Pe.call(I,"key")){var H=Object.getOwnPropertyDescriptor(I,"key").get;if(H&&H.isReactWarning)return!1}return I.key!==void 0}function Bt(I,H){typeof I.ref=="string"&&Oe.current}function gr(I,H){{var J=function(){Me||(Me=!0,w("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",H))};J.isReactWarning=!0,Object.defineProperty(I,"key",{get:J,configurable:!0})}}function ri(I,H){{var J=function(){it||(it=!0,w("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",H))};J.isReactWarning=!0,Object.defineProperty(I,"ref",{get:J,configurable:!0})}}var So=function(I,H,J,Ee,$e,Xe,Ve){var ze={$$typeof:t,type:I,key:H,ref:J,props:Ve,_owner:Xe};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:Ee}),Object.defineProperty(ze,"_source",{configurable:!1,enumerable:!1,writable:!1,value:$e}),Object.freeze&&(Object.freeze(ze.props),Object.freeze(ze)),ze};function xr(I,H,J,Ee,$e){{var Xe,Ve={},ze=null,Tt=null;J!==void 0&&(ge(J),ze=""+J),Ct(H)&&(ge(H.key),ze=""+H.key),mt(H)&&(Tt=H.ref,Bt(H,$e));for(Xe in H)Pe.call(H,Xe)&&!at.hasOwnProperty(Xe)&&(Ve[Xe]=H[Xe]);if(I&&I.defaultProps){var ht=I.defaultProps;for(Xe in ht)Ve[Xe]===void 0&&(Ve[Xe]=ht[Xe])}if(ze||Tt){var dt=typeof I=="function"?I.displayName||I.name||"Unknown":I;ze&&gr(Ve,dt),Tt&&ri(Ve,dt)}return So(I,ze,Tt,$e,Ee,Oe.current,Ve)}}var It=v.ReactCurrentOwner,Br=v.ReactDebugCurrentFrame;function qt(I){if(I){var H=I._owner,J=nt(I.type,I._source,H?H.type:null);Br.setExtraStackFrame(J)}else Br.setExtraStackFrame(null)}var gt;gt=!1;function tn(I){return typeof I=="object"&&I!==null&&I.$$typeof===t}function Nn(){{if(It.current){var I=V(It.current.type);if(I)return`
|
|
22
22
|
|
|
23
|
-
Check the render method of \``+
|
|
23
|
+
Check the render method of \``+I+"`."}return""}}function zr(I){return""}var Gt={};function vr(I){{var H=Nn();if(!H){var J=typeof I=="string"?I:I.displayName||I.name;J&&(H=`
|
|
24
24
|
|
|
25
|
-
Check the top-level render call using <`+
|
|
25
|
+
Check the top-level render call using <`+J+">.")}return H}}function hn(I,H){{if(!I._store||I._store.validated||I.key!=null)return;I._store.validated=!0;var J=vr(H);if(Gt[J])return;Gt[J]=!0;var Ee="";I&&I._owner&&I._owner!==It.current&&(Ee=" It was passed a child from "+V(I._owner.type)+"."),qt(I),w('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',J,Ee),qt(null)}}function pn(I,H){{if(typeof I!="object")return;if(Z(I))for(var J=0;J<I.length;J++){var Ee=I[J];tn(Ee)&&hn(Ee,H)}else if(tn(I))I._store&&(I._store.validated=!0);else if(I){var $e=g(I);if(typeof $e=="function"&&$e!==I.entries)for(var Xe=$e.call(I),Ve;!(Ve=Xe.next()).done;)tn(Ve.value)&&hn(Ve.value,H)}}}function br(I){{var H=I.type;if(H==null||typeof H=="string")return;var J;if(typeof H=="function")J=H.propTypes;else if(typeof H=="object"&&(H.$$typeof===l||H.$$typeof===f))J=H.propTypes;else return;if(J){var Ee=V(H);Ue(J,I.props,"prop",Ee,I)}else if(H.PropTypes!==void 0&&!gt){gt=!0;var $e=V(H);w("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",$e||"Unknown")}typeof H.getDefaultProps=="function"&&!H.getDefaultProps.isReactClassApproved&&w("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function Co(I){{for(var H=Object.keys(I.props),J=0;J<H.length;J++){var Ee=H[J];if(Ee!=="children"&&Ee!=="key"){qt(I),w("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",Ee),qt(null);break}}I.ref!==null&&(qt(I),w("Invalid attribute `ref` supplied to `React.Fragment`."),qt(null))}}var wr={};function ie(I,H,J,Ee,$e,Xe){{var Ve=P(I);if(!Ve){var ze="";(I===void 0||typeof I=="object"&&I!==null&&Object.keys(I).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 Tt=zr();Tt?ze+=Tt:ze+=Nn();var ht;I===null?ht="null":Z(I)?ht="array":I!==void 0&&I.$$typeof===t?(ht="<"+(V(I.type)||"Unknown")+" />",ze=" Did you accidentally export a JSX literal instead of a component?"):ht=typeof I,w("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",ht,ze)}var dt=xr(I,H,J,$e,Xe);if(dt==null)return dt;if(Ve){var Dt=H.children;if(Dt!==void 0)if(Ee)if(Z(Dt)){for(var Gn=0;Gn<Dt.length;Gn++)pn(Dt[Gn],I);Object.freeze&&Object.freeze(Dt)}else w("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else pn(Dt,I)}if(Pe.call(H,"key")){var Pn=V(I),jt=Object.keys(H).filter(function(z){return z!=="key"}),C=jt.length>0?"{key: someKey, "+jt.join(": ..., ")+": ...}":"{key: someKey}";if(!wr[Pn+C]){var _=jt.length>0?"{"+jt.join(": ..., ")+": ...}":"{}";w(`A props object containing a "key" prop is being spread into JSX:
|
|
26
26
|
let props = %s;
|
|
27
27
|
<%s {...props} />
|
|
28
28
|
React keys must be passed directly to JSX without using spread:
|
|
29
29
|
let props = %s;
|
|
30
|
-
<%s key={someKey} {...props} />`,W,T,xe,T),jn[T+W]=!0}}return E===r?Fr(ht):Lr(ht),ht}}function be(E,z,te){return se(E,z,te,!0)}function Ue(E,z,te){return se(E,z,te,!1)}var ot=Ue,Pt=be;zr.Fragment=r,zr.jsx=ot,zr.jsxs=Pt}()),zr}process.env.NODE_ENV==="production"?ni.exports=um():ni.exports=dm();var c=ni.exports;function pl(e,t){return function(){return e.apply(t,arguments)}}const{toString:fm}=Object.prototype,{getPrototypeOf:ri}=Object,{iterator:So,toStringTag:ml}=Symbol,Co=(e=>t=>{const n=fm.call(t);return e[n]||(e[n]=n.slice(8,-1).toLowerCase())})(Object.create(null)),tn=e=>(e=e.toLowerCase(),t=>Co(t)===e),To=e=>t=>typeof t===e,{isArray:xr}=Array,vr=To("undefined");function Hr(e){return e!==null&&!vr(e)&&e.constructor!==null&&!vr(e.constructor)&&Ot(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const gl=tn("ArrayBuffer");function hm(e){let t;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?t=ArrayBuffer.isView(e):t=e&&e.buffer&&gl(e.buffer),t}const pm=To("string"),Ot=To("function"),xl=To("number"),Ur=e=>e!==null&&typeof e=="object",mm=e=>e===!0||e===!1,ko=e=>{if(Co(e)!=="object")return!1;const t=ri(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(ml in e)&&!(So in e)},gm=e=>{if(!Ur(e)||Hr(e))return!1;try{return Object.keys(e).length===0&&Object.getPrototypeOf(e)===Object.prototype}catch{return!1}},xm=tn("Date"),vm=tn("File"),wm=tn("Blob"),bm=tn("FileList"),ym=e=>Ur(e)&&Ot(e.pipe),Sm=e=>{let t;return e&&(typeof FormData=="function"&&e instanceof FormData||Ot(e.append)&&((t=Co(e))==="formdata"||t==="object"&&Ot(e.toString)&&e.toString()==="[object FormData]"))},Cm=tn("URLSearchParams"),[Tm,km,Em,Im]=["ReadableStream","Request","Response","Headers"].map(tn),Nm=e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function Wr(e,t,{allOwnKeys:n=!1}={}){if(e===null||typeof e>"u")return;let r,o;if(typeof e!="object"&&(e=[e]),xr(e))for(r=0,o=e.length;r<o;r++)t.call(null,e[r],r,e);else{if(Hr(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 vl(e,t){if(Hr(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 Jn=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global,wl=e=>!vr(e)&&e!==Jn;function oi(){const{caseless:e,skipUndefined:t}=wl(this)&&this||{},n={},r=(o,s)=>{const i=e&&vl(n,s)||s;ko(n[i])&&ko(o)?n[i]=oi(n[i],o):ko(o)?n[i]=oi({},o):xr(o)?n[i]=o.slice():(!t||!vr(o))&&(n[i]=o)};for(let o=0,s=arguments.length;o<s;o++)arguments[o]&&Wr(arguments[o],r);return n}const Am=(e,t,n,{allOwnKeys:r}={})=>(Wr(t,(o,s)=>{n&&Ot(o)?e[s]=pl(o,n):e[s]=o},{allOwnKeys:r}),e),_m=e=>(e.charCodeAt(0)===65279&&(e=e.slice(1)),e),jm=(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)},Rm=(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&&ri(e)}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},Pm=(e,t,n)=>{e=String(e),(n===void 0||n>e.length)&&(n=e.length),n-=t.length;const r=e.indexOf(t,n);return r!==-1&&r===n},Om=e=>{if(!e)return null;if(xr(e))return e;let t=e.length;if(!xl(t))return null;const n=new Array(t);for(;t-- >0;)n[t]=e[t];return n},Mm=(e=>t=>e&&t instanceof e)(typeof Uint8Array<"u"&&ri(Uint8Array)),Dm=(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])}},Lm=(e,t)=>{let n;const r=[];for(;(n=e.exec(t))!==null;)r.push(n);return r},Fm=tn("HTMLFormElement"),$m=e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(n,r,o){return r.toUpperCase()+o}),bl=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),Bm=tn("RegExp"),yl=(e,t)=>{const n=Object.getOwnPropertyDescriptors(e),r={};Wr(n,(o,s)=>{let i;(i=t(o,s,e))!==!1&&(r[s]=i||o)}),Object.defineProperties(e,r)},zm=e=>{yl(e,(t,n)=>{if(Ot(e)&&["arguments","caller","callee"].indexOf(n)!==-1)return!1;const r=e[n];if(Ot(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+"'")})}})},Hm=(e,t)=>{const n={},r=o=>{o.forEach(s=>{n[s]=!0})};return xr(e)?r(e):r(String(e).split(t)),n},Um=()=>{},Wm=(e,t)=>e!=null&&Number.isFinite(e=+e)?e:t;function Vm(e){return!!(e&&Ot(e.append)&&e[ml]==="FormData"&&e[So])}const qm=e=>{const t=new Array(10),n=(r,o)=>{if(Ur(r)){if(t.indexOf(r)>=0)return;if(Hr(r))return r;if(!("toJSON"in r)){t[o]=r;const s=xr(r)?[]:{};return Wr(r,(i,a)=>{const l=n(i,o+1);!vr(l)&&(s[a]=l)}),t[o]=void 0,s}}return r};return n(e,0)},Km=tn("AsyncFunction"),Gm=e=>e&&(Ur(e)||Ot(e))&&Ot(e.then)&&Ot(e.catch),Sl=((e,t)=>e?setImmediate:t?((n,r)=>(Jn.addEventListener("message",({source:o,data:s})=>{o===Jn&&s===n&&r.length&&r.shift()()},!1),o=>{r.push(o),Jn.postMessage(n,"*")}))(`axios@${Math.random()}`,[]):n=>setTimeout(n))(typeof setImmediate=="function",Ot(Jn.postMessage)),Ym=typeof queueMicrotask<"u"?queueMicrotask.bind(Jn):typeof process<"u"&&process.nextTick||Sl,R={isArray:xr,isArrayBuffer:gl,isBuffer:Hr,isFormData:Sm,isArrayBufferView:hm,isString:pm,isNumber:xl,isBoolean:mm,isObject:Ur,isPlainObject:ko,isEmptyObject:gm,isReadableStream:Tm,isRequest:km,isResponse:Em,isHeaders:Im,isUndefined:vr,isDate:xm,isFile:vm,isBlob:wm,isRegExp:Bm,isFunction:Ot,isStream:ym,isURLSearchParams:Cm,isTypedArray:Mm,isFileList:bm,forEach:Wr,merge:oi,extend:Am,trim:Nm,stripBOM:_m,inherits:jm,toFlatObject:Rm,kindOf:Co,kindOfTest:tn,endsWith:Pm,toArray:Om,forEachEntry:Dm,matchAll:Lm,isHTMLForm:Fm,hasOwnProperty:bl,hasOwnProp:bl,reduceDescriptors:yl,freezeMethods:zm,toObjectSet:Hm,toCamelCase:$m,noop:Um,toFiniteNumber:Wm,findKey:vl,global:Jn,isContextDefined:wl,isSpecCompliantForm:Vm,toJSONObject:qm,isAsyncFn:Km,isThenable:Gm,setImmediate:Sl,asap:Ym,isIterable:e=>e!=null&&Ot(e[So])};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)}R.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:R.toJSONObject(this.config),code:this.code,status:this.status}}});const Cl=De.prototype,Tl={};["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=>{Tl[e]={value:e}}),Object.defineProperties(De,Tl),Object.defineProperty(Cl,"isAxiosError",{value:!0}),De.from=(e,t,n,r,o,s)=>{const i=Object.create(Cl);R.toFlatObject(e,i,function(d){return d!==Error.prototype},u=>u!=="isAxiosError");const a=e&&e.message?e.message:"Error",l=t==null&&e?e.code:t;return 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 Xm=null;function si(e){return R.isPlainObject(e)||R.isArray(e)}function kl(e){return R.endsWith(e,"[]")?e.slice(0,-2):e}function El(e,t,n){return e?e.concat(t).map(function(o,s){return o=kl(o),!n&&s?"["+o+"]":o}).join(n?".":""):t}function Jm(e){return R.isArray(e)&&!e.some(si)}const Zm=R.toFlatObject(R,{},null,function(t){return/^is[A-Z]/.test(t)});function Eo(e,t,n){if(!R.isObject(e))throw new TypeError("target must be an object");t=t||new FormData,n=R.toFlatObject(n,{metaTokens:!0,dots:!1,indexes:!1},!1,function(x,g){return!R.isUndefined(g[x])});const r=n.metaTokens,o=n.visitor||d,s=n.dots,i=n.indexes,l=(n.Blob||typeof Blob<"u"&&Blob)&&R.isSpecCompliantForm(t);if(!R.isFunction(o))throw new TypeError("visitor must be a function");function u(w){if(w===null)return"";if(R.isDate(w))return w.toISOString();if(R.isBoolean(w))return w.toString();if(!l&&R.isBlob(w))throw new De("Blob is not supported. Use a Buffer instead.");return R.isArrayBuffer(w)||R.isTypedArray(w)?l&&typeof Blob=="function"?new Blob([w]):Buffer.from(w):w}function d(w,x,g){let v=w;if(w&&!g&&typeof w=="object"){if(R.endsWith(x,"{}"))x=r?x:x.slice(0,-2),w=JSON.stringify(w);else if(R.isArray(w)&&Jm(w)||(R.isFileList(w)||R.endsWith(x,"[]"))&&(v=R.toArray(w)))return x=kl(x),v.forEach(function(S,N){!(R.isUndefined(S)||S===null)&&t.append(i===!0?El([x],N,s):i===null?x:x+"[]",u(S))}),!1}return si(w)?!0:(t.append(El(g,x,s),u(w)),!1)}const f=[],h=Object.assign(Zm,{defaultVisitor:d,convertValue:u,isVisitable:si});function p(w,x){if(!R.isUndefined(w)){if(f.indexOf(w)!==-1)throw Error("Circular reference detected in "+x.join("."));f.push(w),R.forEach(w,function(v,b){(!(R.isUndefined(v)||v===null)&&o.call(t,v,R.isString(b)?b.trim():b,x,h))===!0&&p(v,x?x.concat(b):[b])}),f.pop()}}if(!R.isObject(e))throw new TypeError("data must be an object");return p(e),t}function Il(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,function(r){return t[r]})}function ii(e,t){this._pairs=[],e&&Eo(e,this,t)}const Nl=ii.prototype;Nl.append=function(t,n){this._pairs.push([t,n])},Nl.toString=function(t){const n=t?function(r){return t.call(this,r,Il)}:Il;return this._pairs.map(function(o){return n(o[0])+"="+n(o[1])},"").join("&")};function Qm(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+")}function Al(e,t,n){if(!t)return e;const r=n&&n.encode||Qm;R.isFunction(n)&&(n={serialize:n});const o=n&&n.serialize;let s;if(o?s=o(t,n):s=R.isURLSearchParams(t)?t.toString():new ii(t,n).toString(r),s){const i=e.indexOf("#");i!==-1&&(e=e.slice(0,i)),e+=(e.indexOf("?")===-1?"?":"&")+s}return e}class _l{constructor(){this.handlers=[]}use(t,n,r){return this.handlers.push({fulfilled:t,rejected:n,synchronous:r?r.synchronous:!1,runWhen:r?r.runWhen:null}),this.handlers.length-1}eject(t){this.handlers[t]&&(this.handlers[t]=null)}clear(){this.handlers&&(this.handlers=[])}forEach(t){R.forEach(this.handlers,function(r){r!==null&&t(r)})}}const jl={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},eg={isBrowser:!0,classes:{URLSearchParams:typeof URLSearchParams<"u"?URLSearchParams:ii,FormData:typeof FormData<"u"?FormData:null,Blob:typeof Blob<"u"?Blob:null},protocols:["http","https","file","blob","url","data"]},ai=typeof window<"u"&&typeof document<"u",li=typeof navigator=="object"&&navigator||void 0,tg=ai&&(!li||["ReactNative","NativeScript","NS"].indexOf(li.product)<0),ng=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function",rg=ai&&window.location.href||"http://localhost",kt={...Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv:ai,hasStandardBrowserEnv:tg,hasStandardBrowserWebWorkerEnv:ng,navigator:li,origin:rg},Symbol.toStringTag,{value:"Module"})),...eg};function og(e,t){return Eo(e,new kt.classes.URLSearchParams,{visitor:function(n,r,o,s){return kt.isNode&&R.isBuffer(n)?(this.append(r,n.toString("base64")),!1):s.defaultVisitor.apply(this,arguments)},...t})}function sg(e){return R.matchAll(/\w+|\[(\w*)]/g,e).map(t=>t[0]==="[]"?"":t[1]||t[0])}function ig(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 Rl(e){function t(n,r,o,s){let i=n[s++];if(i==="__proto__")return!0;const a=Number.isFinite(+i),l=s>=n.length;return i=!i&&R.isArray(o)?o.length:i,l?(R.hasOwnProp(o,i)?o[i]=[o[i],r]:o[i]=r,!a):((!o[i]||!R.isObject(o[i]))&&(o[i]=[]),t(n,r,o[i],s)&&R.isArray(o[i])&&(o[i]=ig(o[i])),!a)}if(R.isFormData(e)&&R.isFunction(e.entries)){const n={};return R.forEachEntry(e,(r,o)=>{t(sg(r),o,n,0)}),n}return null}function ag(e,t,n){if(R.isString(e))try{return(t||JSON.parse)(e),R.trim(e)}catch(r){if(r.name!=="SyntaxError")throw r}return(n||JSON.stringify)(e)}const Vr={transitional:jl,adapter:["xhr","http","fetch"],transformRequest:[function(t,n){const r=n.getContentType()||"",o=r.indexOf("application/json")>-1,s=R.isObject(t);if(s&&R.isHTMLForm(t)&&(t=new FormData(t)),R.isFormData(t))return o?JSON.stringify(Rl(t)):t;if(R.isArrayBuffer(t)||R.isBuffer(t)||R.isStream(t)||R.isFile(t)||R.isBlob(t)||R.isReadableStream(t))return t;if(R.isArrayBufferView(t))return t.buffer;if(R.isURLSearchParams(t))return n.setContentType("application/x-www-form-urlencoded;charset=utf-8",!1),t.toString();let a;if(s){if(r.indexOf("application/x-www-form-urlencoded")>-1)return og(t,this.formSerializer).toString();if((a=R.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||Vr.transitional,r=n&&n.forcedJSONParsing,o=this.responseType==="json";if(R.isResponse(t)||R.isReadableStream(t))return t;if(t&&R.isString(t)&&(r&&!this.responseType||o)){const i=!(n&&n.silentJSONParsing)&&o;try{return JSON.parse(t,this.parseReviver)}catch(a){if(i)throw a.name==="SyntaxError"?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:kt.classes.FormData,Blob:kt.classes.Blob},validateStatus:function(t){return t>=200&&t<300},headers:{common:{Accept:"application/json, text/plain, */*","Content-Type":void 0}}};R.forEach(["delete","get","head","post","put","patch"],e=>{Vr.headers[e]={}});const lg=R.toObjectSet(["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"]),cg=e=>{const t={};let n,r,o;return e&&e.split(`
|
|
31
|
-
`).forEach(function(i){o=i.indexOf(":"),n=i.substring(0,o).trim().toLowerCase(),r=i.substring(o+1).trim(),!(!n||t[n]&&
|
|
32
|
-
`)}getSetCookie(){return this.get("set-cookie")||[]}get[Symbol.toStringTag](){return"AxiosHeaders"}static from(t){return t instanceof this?t:new this(t)}static concat(t,...n){const r=new this(t);return n.forEach(o=>r.set(o)),r}static accessor(t){const r=(this[Pl]=this[Pl]={accessors:{}}).accessors,o=this.prototype;function s(i){const a=qr(i);r[a]||(hg(o,i),r[a]=!0)}return R.isArray(t)?t.forEach(s):s(t),this}};Mt.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),R.reduceDescriptors(Mt.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(r){this[n]=r}}}),R.freezeMethods(Mt);function ui(e,t){const n=this||Vr,r=t||n,o=Mt.from(r.headers);let s=r.data;return R.forEach(e,function(a){s=a.call(n,s,o.normalize(),t?t.status:void 0)}),o.normalize(),s}function Ol(e){return!!(e&&e.__CANCEL__)}function wr(e,t,n){De.call(this,e??"canceled",De.ERR_CANCELED,t,n),this.name="CanceledError"}R.inherits(wr,De,{__CANCEL__:!0});function Ml(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 pg(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function mg(e,t){e=e||10;const n=new Array(e),r=new Array(e);let o=0,s=0,i;return t=t!==void 0?t:1e3,function(l){const u=Date.now(),d=r[s];i||(i=u),n[o]=l,r[o]=u;let f=s,h=0;for(;f!==o;)h+=n[f++],f=f%e;if(o=(o+1)%e,o===s&&(s=(s+1)%e),u-i<t)return;const p=d&&u-d;return p?Math.round(h*1e3/p):void 0}}function gg(e,t){let n=0,r=1e3/t,o,s;const i=(u,d=Date.now())=>{n=d,o=null,s&&(clearTimeout(s),s=null),e(...u)};return[(...u)=>{const d=Date.now(),f=d-n;f>=r?i(u,d):(o=u,s||(s=setTimeout(()=>{s=null,i(o)},r-f)))},()=>o&&i(o)]}const No=(e,t,n=3)=>{let r=0;const o=mg(50,250);return gg(s=>{const i=s.loaded,a=s.lengthComputable?s.total:void 0,l=i-r,u=o(l),d=i<=a;r=i;const f={loaded:i,total:a,progress:a?i/a:void 0,bytes:l,rate:u||void 0,estimated:u&&a&&d?(a-i)/u:void 0,event:s,lengthComputable:a!=null,[t?"download":"upload"]:!0};e(f)},n)},Dl=(e,t)=>{const n=e!=null;return[r=>t[0]({lengthComputable:n,total:e,loaded:r}),t[1]]},Ll=e=>(...t)=>R.asap(()=>e(...t)),xg=kt.hasStandardBrowserEnv?((e,t)=>n=>(n=new URL(n,kt.origin),e.protocol===n.protocol&&e.host===n.host&&(t||e.port===n.port)))(new URL(kt.origin),kt.navigator&&/(msie|trident)/i.test(kt.navigator.userAgent)):()=>!0,vg=kt.hasStandardBrowserEnv?{write(e,t,n,r,o,s){const i=[e+"="+encodeURIComponent(t)];R.isNumber(n)&&i.push("expires="+new Date(n).toGMTString()),R.isString(r)&&i.push("path="+r),R.isString(o)&&i.push("domain="+o),s===!0&&i.push("secure"),document.cookie=i.join("; ")},read(e){const t=document.cookie.match(new RegExp("(^|;\\s*)("+e+")=([^;]*)"));return t?decodeURIComponent(t[3]):null},remove(e){this.write(e,"",Date.now()-864e5)}}:{write(){},read(){return null},remove(){}};function wg(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function bg(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function Fl(e,t,n){let r=!wg(t);return e&&(r||n==!1)?bg(e,t):t}const $l=e=>e instanceof Mt?{...e}:e;function Zn(e,t){t=t||{};const n={};function r(u,d,f,h){return R.isPlainObject(u)&&R.isPlainObject(d)?R.merge.call({caseless:h},u,d):R.isPlainObject(d)?R.merge({},d):R.isArray(d)?d.slice():d}function o(u,d,f,h){if(R.isUndefined(d)){if(!R.isUndefined(u))return r(void 0,u,f,h)}else return r(u,d,f,h)}function s(u,d){if(!R.isUndefined(d))return r(void 0,d)}function i(u,d){if(R.isUndefined(d)){if(!R.isUndefined(u))return r(void 0,u)}else return r(void 0,d)}function a(u,d,f){if(f in t)return r(u,d);if(f in e)return r(void 0,u)}const l={url:s,method:s,data:s,baseURL:i,transformRequest:i,transformResponse:i,paramsSerializer:i,timeout:i,timeoutMessage:i,withCredentials:i,withXSRFToken:i,adapter:i,responseType:i,xsrfCookieName:i,xsrfHeaderName:i,onUploadProgress:i,onDownloadProgress:i,decompress:i,maxContentLength:i,maxBodyLength:i,beforeRedirect:i,transport:i,httpAgent:i,httpsAgent:i,cancelToken:i,socketPath:i,responseEncoding:i,validateStatus:a,headers:(u,d,f)=>o($l(u),$l(d),f,!0)};return R.forEach(Object.keys({...e,...t}),function(d){const f=l[d]||o,h=f(e[d],t[d],d);R.isUndefined(h)&&f!==a||(n[d]=h)}),n}const Bl=e=>{const t=Zn({},e);let{data:n,withXSRFToken:r,xsrfHeaderName:o,xsrfCookieName:s,headers:i,auth:a}=t;if(t.headers=i=Mt.from(i),t.url=Al(Fl(t.baseURL,t.url,t.allowAbsoluteUrls),e.params,e.paramsSerializer),a&&i.set("Authorization","Basic "+btoa((a.username||"")+":"+(a.password?unescape(encodeURIComponent(a.password)):""))),R.isFormData(n)){if(kt.hasStandardBrowserEnv||kt.hasStandardBrowserWebWorkerEnv)i.setContentType(void 0);else if(R.isFunction(n.getHeaders)){const l=n.getHeaders(),u=["content-type","content-length"];Object.entries(l).forEach(([d,f])=>{u.includes(d.toLowerCase())&&i.set(d,f)})}}if(kt.hasStandardBrowserEnv&&(r&&R.isFunction(r)&&(r=r(t)),r||r!==!1&&xg(t.url))){const l=o&&s&&vg.read(s);l&&i.set(o,l)}return t},yg=typeof XMLHttpRequest<"u"&&function(e){return new Promise(function(n,r){const o=Bl(e);let s=o.data;const i=Mt.from(o.headers).normalize();let{responseType:a,onUploadProgress:l,onDownloadProgress:u}=o,d,f,h,p,w;function x(){p&&p(),w&&w(),o.cancelToken&&o.cancelToken.unsubscribe(d),o.signal&&o.signal.removeEventListener("abort",d)}let g=new XMLHttpRequest;g.open(o.method.toUpperCase(),o.url,!0),g.timeout=o.timeout;function v(){if(!g)return;const S=Mt.from("getAllResponseHeaders"in g&&g.getAllResponseHeaders()),C={data:!a||a==="text"||a==="json"?g.responseText:g.response,status:g.status,statusText:g.statusText,headers:S,config:e,request:g};Ml(function(I){n(I),x()},function(I){r(I),x()},C),g=null}"onloadend"in g?g.onloadend=v:g.onreadystatechange=function(){!g||g.readyState!==4||g.status===0&&!(g.responseURL&&g.responseURL.indexOf("file:")===0)||setTimeout(v)},g.onabort=function(){g&&(r(new De("Request aborted",De.ECONNABORTED,e,g)),g=null)},g.onerror=function(N){const C=N&&N.message?N.message:"Network Error",k=new De(C,De.ERR_NETWORK,e,g);k.event=N||null,r(k),g=null},g.ontimeout=function(){let N=o.timeout?"timeout of "+o.timeout+"ms exceeded":"timeout exceeded";const C=o.transitional||jl;o.timeoutErrorMessage&&(N=o.timeoutErrorMessage),r(new De(N,C.clarifyTimeoutError?De.ETIMEDOUT:De.ECONNABORTED,e,g)),g=null},s===void 0&&i.setContentType(null),"setRequestHeader"in g&&R.forEach(i.toJSON(),function(N,C){g.setRequestHeader(C,N)}),R.isUndefined(o.withCredentials)||(g.withCredentials=!!o.withCredentials),a&&a!=="json"&&(g.responseType=o.responseType),u&&([h,w]=No(u,!0),g.addEventListener("progress",h)),l&&g.upload&&([f,p]=No(l),g.upload.addEventListener("progress",f),g.upload.addEventListener("loadend",p)),(o.cancelToken||o.signal)&&(d=S=>{g&&(r(!S||S.type?new wr(null,e,g):S),g.abort(),g=null)},o.cancelToken&&o.cancelToken.subscribe(d),o.signal&&(o.signal.aborted?d():o.signal.addEventListener("abort",d)));const b=pg(o.url);if(b&&kt.protocols.indexOf(b)===-1){r(new De("Unsupported protocol "+b+":",De.ERR_BAD_REQUEST,e));return}g.send(s||null)})},Sg=(e,t)=>{const{length:n}=e=e?e.filter(Boolean):[];if(t||n){let r=new AbortController,o;const s=function(u){if(!o){o=!0,a();const d=u instanceof Error?u:this.reason;r.abort(d instanceof De?d:new wr(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(u=>{u.unsubscribe?u.unsubscribe(s):u.removeEventListener("abort",s)}),e=null)};e.forEach(u=>u.addEventListener("abort",s));const{signal:l}=r;return l.unsubscribe=()=>R.asap(a),l}},Cg=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},Tg=async function*(e,t){for await(const n of kg(e))yield*Cg(n,t)},kg=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()}},zl=(e,t,n,r)=>{const o=Tg(e,t);let s=0,i,a=l=>{i||(i=!0,r&&r(l))};return new ReadableStream({async pull(l){try{const{done:u,value:d}=await o.next();if(u){a(),l.close();return}let f=d.byteLength;if(n){let h=s+=f;n(h)}l.enqueue(new Uint8Array(d))}catch(u){throw a(u),u}},cancel(l){return a(l),o.return()}},{highWaterMark:2})},Hl=64*1024,{isFunction:Ao}=R,Eg=(({Request:e,Response:t})=>({Request:e,Response:t}))(R.global),{ReadableStream:Ul,TextEncoder:Wl}=R.global,Vl=(e,...t)=>{try{return!!e(...t)}catch{return!1}},Ig=e=>{e=R.merge.call({skipUndefined:!0},Eg,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(Ul),l=o&&(typeof Wl=="function"?(w=>x=>w.encode(x))(new Wl):async w=>new Uint8Array(await new n(w).arrayBuffer())),u=s&&a&&Vl(()=>{let w=!1;const x=new n(kt.origin,{body:new Ul,method:"POST",get duplex(){return w=!0,"half"}}).headers.has("Content-Type");return w&&!x}),d=i&&a&&Vl(()=>R.isReadableStream(new r("").body)),f={stream:d&&(w=>w.body)};o&&["text","arrayBuffer","blob","formData","stream"].forEach(w=>{!f[w]&&(f[w]=(x,g)=>{let v=x&&x[w];if(v)return v.call(x);throw new De(`Response type '${w}' is not supported`,De.ERR_NOT_SUPPORT,g)})});const h=async w=>{if(w==null)return 0;if(R.isBlob(w))return w.size;if(R.isSpecCompliantForm(w))return(await new n(kt.origin,{method:"POST",body:w}).arrayBuffer()).byteLength;if(R.isArrayBufferView(w)||R.isArrayBuffer(w))return w.byteLength;if(R.isURLSearchParams(w)&&(w=w+""),R.isString(w))return(await l(w)).byteLength},p=async(w,x)=>{const g=R.toFiniteNumber(w.getContentLength());return g??h(x)};return async w=>{let{url:x,method:g,data:v,signal:b,cancelToken:S,timeout:N,onDownloadProgress:C,onUploadProgress:k,responseType:I,headers:A,withCredentials:j="same-origin",fetchOptions:P}=Bl(w),L=t||fetch;I=I?(I+"").toLowerCase():"text";let F=Sg([b,S&&S.toAbortSignal()],N),V=null;const M=F&&F.unsubscribe&&(()=>{F.unsubscribe()});let G;try{if(k&&u&&g!=="get"&&g!=="head"&&(G=await p(A,v))!==0){let D=new n(x,{method:"POST",body:v,duplex:"half"}),Q;if(R.isFormData(v)&&(Q=D.headers.get("content-type"))&&A.setContentType(Q),D.body){const[de,we]=Dl(G,No(Ll(k)));v=zl(D.body,Hl,de,we)}}R.isString(j)||(j=j?"include":"omit");const q=s&&"credentials"in n.prototype,U={...P,signal:F,method:g.toUpperCase(),headers:A.normalize().toJSON(),body:v,duplex:"half",credentials:q?j:void 0};V=s&&new n(x,U);let B=await(s?L(V,P):L(x,U));const $=d&&(I==="stream"||I==="response");if(d&&(C||$&&M)){const D={};["status","statusText","headers"].forEach(ye=>{D[ye]=B[ye]});const Q=R.toFiniteNumber(B.headers.get("content-length")),[de,we]=C&&Dl(Q,No(Ll(C),!0))||[];B=new r(zl(B.body,Hl,de,()=>{we&&we(),M&&M()}),D)}I=I||"text";let ce=await f[R.findKey(f,I)||"text"](B,w);return!$&&M&&M(),await new Promise((D,Q)=>{Ml(D,Q,{data:ce,headers:Mt.from(B.headers),status:B.status,statusText:B.statusText,config:w,request:V})})}catch(q){throw M&&M(),q&&q.name==="TypeError"&&/Load failed|fetch/i.test(q.message)?Object.assign(new De("Network Error",De.ERR_NETWORK,w,V),{cause:q.cause||q}):De.from(q,q&&q.code,w,V)}}},Ng=new Map,ql=e=>{let t=e?e.env:{};const{fetch:n,Request:r,Response:o}=t,s=[r,o,n];let i=s.length,a=i,l,u,d=Ng;for(;a--;)l=s[a],u=d.get(l),u===void 0&&d.set(l,u=a?new Map:Ig(t)),d=u;return u};ql();const di={http:Xm,xhr:yg,fetch:{get:ql}};R.forEach(di,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const Kl=e=>`- ${e}`,Ag=e=>R.isFunction(e)||e===null||e===!1,Gl={getAdapter:(e,t)=>{e=R.isArray(e)?e:[e];const{length:n}=e;let r,o;const s={};for(let i=0;i<n;i++){r=e[i];let a;if(o=r,!Ag(r)&&(o=di[(a=String(r)).toLowerCase()],o===void 0))throw new De(`Unknown adapter '${a}'`);if(o&&(R.isFunction(o)||(o=o.get(t))))break;s[a||"#"+i]=o}if(!o){const i=Object.entries(s).map(([l,u])=>`adapter ${l} `+(u===!1?"is not supported by the environment":"is not available in the build"));let a=n?i.length>1?`since :
|
|
33
|
-
`+i.map(
|
|
34
|
-
`):" "+
|
|
35
|
-
`+s):r.stack=s}catch{}}throw r}}_request(t,n){typeof t=="string"?(n=n||{},n.url=t):n=t||{},n=Zn(this.defaults,n);const{transitional:r,paramsSerializer:o,headers:s}=n;r!==void 0&&jo.assertOptions(r,{silentJSONParsing:hn.transitional(hn.boolean),forcedJSONParsing:hn.transitional(hn.boolean),clarifyTimeoutError:hn.transitional(hn.boolean)},!1),o!=null&&(R.isFunction(o)?n.paramsSerializer={serialize:o}:jo.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),jo.assertOptions(n,{baseUrl:hn.spelling("baseURL"),withXsrfToken:hn.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let i=s&&R.merge(s.common,s[n.method]);s&&R.forEach(["delete","get","head","post","put","patch","common"],w=>{delete s[w]}),n.headers=Mt.concat(i,s);const a=[];let l=!0;this.interceptors.request.forEach(function(x){typeof x.runWhen=="function"&&x.runWhen(n)===!1||(l=l&&x.synchronous,a.unshift(x.fulfilled,x.rejected))});const u=[];this.interceptors.response.forEach(function(x){u.push(x.fulfilled,x.rejected)});let d,f=0,h;if(!l){const w=[Yl.bind(this),void 0];for(w.unshift(...a),w.push(...u),h=w.length,d=Promise.resolve(n);f<h;)d=d.then(w[f++],w[f++]);return d}h=a.length;let p=n;for(;f<h;){const w=a[f++],x=a[f++];try{p=w(p)}catch(g){x.call(this,g);break}}try{d=Yl.call(this,p)}catch(w){return Promise.reject(w)}for(f=0,h=u.length;f<h;)d=d.then(u[f++],u[f++]);return d}getUri(t){t=Zn(this.defaults,t);const n=Fl(t.baseURL,t.url,t.allowAbsoluteUrls);return Al(n,t.params,t.paramsSerializer)}};R.forEach(["delete","get","head","options"],function(t){Qn.prototype[t]=function(n,r){return this.request(Zn(r||{},{method:t,url:n,data:(r||{}).data}))}}),R.forEach(["post","put","patch"],function(t){function n(r){return function(s,i,a){return this.request(Zn(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 jg=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 wr(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 Rg(e){return function(n){return e.apply(null,n)}}function Pg(e){return R.isObject(e)&&e.isAxiosError===!0}const hi={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(hi).forEach(([e,t])=>{hi[t]=e});function Zl(e){const t=new Qn(e),n=pl(Qn.prototype.request,t);return R.extend(n,Qn.prototype,t,{allOwnKeys:!0}),R.extend(n,t,null,{allOwnKeys:!0}),n.create=function(o){return Zl(Zn(e,o))},n}const pt=Zl(Vr);pt.Axios=Qn,pt.CanceledError=wr,pt.CancelToken=jg,pt.isCancel=Ol,pt.VERSION=Xl,pt.toFormData=Eo,pt.AxiosError=De,pt.Cancel=pt.CanceledError,pt.all=function(t){return Promise.all(t)},pt.spread=Rg,pt.isAxiosError=Pg,pt.mergeConfig=Zn,pt.AxiosHeaders=Mt,pt.formToJSON=e=>Rl(R.isHTMLForm(e)?new FormData(e):e),pt.getAdapter=Gl.getAdapter,pt.HttpStatusCode=hi,pt.default=pt;const{Axios:xT,AxiosError:vT,CanceledError:wT,isCancel:bT,CancelToken:yT,VERSION:ST,all:CT,Cancel:TT,isAxiosError:kT,spread:ET,toFormData:IT,AxiosHeaders:NT,HttpStatusCode:AT,formToJSON:_T,getAdapter:jT,mergeConfig:RT}=pt,Ql=typeof window<"u"?window.__API_BASE_URL__:void 0,ec=Ql?En(Ql):void 0;function En(e){const n=(e!=null&&e.trim()?e.trim():"/api/chat").replace(/\/+$/,"");return n?n.endsWith("/chat")?n:`${n}/chat`:"/api/chat"}let Ro=null;const pi=new Set;function tc(){return Ro}function mi(e){Ro=e,pi.forEach(t=>t(e))}function nc(e){return pi.add(e),()=>pi.delete(e)}const Vt=pt.create({...ec?{baseURL:ec}:{},timeout:3e4,withCredentials:!0});Vt.interceptors.request.use(e=>(Ro&&(e.headers.Authorization=`Bearer ${Ro}`),e)),Vt.interceptors.response.use(e=>e,e=>Promise.reject(e));async function nn(e,t){return Vt.defaults.baseURL?(await Vt.get(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}async function gi(e,t,n){return Vt.defaults.baseURL?(await Vt.post(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function rc(e,t,n){return Vt.defaults.baseURL?(await Vt.put(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function oc(e,t){return Vt.defaults.baseURL?(await Vt.delete(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}function rn(e){return e&&typeof e=="object"&&"data"in e?e.data:e}class sc{get baseUrl(){const t=Vt.defaults.baseURL;return t?En(String(t)):""}updateConfig(t){t.baseUrl&&(Vt.defaults.baseURL=En(String(t.baseUrl))),t.authToken!==void 0&&mi(t.authToken)}getAuthToken(){return tc()}setAuthToken(t){mi(t)}onTokenChange(t){return nc(t)}async listThreads(){const t=await nn("/threads"),n=rn(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async createThread(t){const r=await gi("/threads",t?{title:t}:void 0);return rn(r)}async updateThread(t,n){const r=await rc(`/threads/${t}`,{title:n});return rn(r)}async deleteThread(t){const n=await oc(`/threads/${t}`);return rn(n)}async threadInfo(t){const n=await nn(`/threads/${t}/info`);return rn(n)}async listAgents(){const t=await nn("/agents"),n=rn(t);return(n==null?void 0:n.items)??[]}async getAgent(t){const n=await nn(`/agents/${t}`);return rn(n)}async getAgentSchema(t){const n=await nn(`/agents/${t}/schema`);return rn(n)}async getMessages(t){const n=await nn(`/threads/${t.threadId}/messages`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs,limit:t.limit,before_id:t.beforeId??void 0}});return rn(n)}async getStateHistory(t){const n=await nn(`/threads/${t.threadId}/state/history`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return rn(n)}resumeStream(t){}async resume(t){const n=await gi("/runs/resume",{thread_id:t.threadId,value:t.value});return rn(n)}}const Pn=new sc,ic=y.createContext(null);function Og({children:e,apiConfig:t}){const n=Pn;if(t){const o=n.baseUrl,s=n.getAuthToken();t.baseUrl&&t.baseUrl!==o&&n.updateConfig({baseUrl:t.baseUrl}),t.apiKey!==void 0&&t.apiKey!==s&&n.updateConfig({authToken:t.apiKey})}const r={token:n.getAuthToken(),setToken:o=>n.setAuthToken(o),api:n,baseUrl:n.baseUrl};return c.jsx(ic.Provider,{value:r,children:e})}function xi(){const e=y.useContext(ic);if(!e)throw new Error("useApi must be used within ApiProvider");return e}async function Mg(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 Dg(e,t=[],n,r,o,s){const i=[],a=[];for(const l of t)try{const u=await Mg(l);a.push({filename:l.name,data:u,mime_type:l.type||"application/octet-stream"})}catch{}return{contentParts:i,filesInfo:a}}const Lg={human:"user",user:"user",ai:"assistant",assistant:"assistant",tool:"tool",function:"tool",system:"system"};function vi(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 wi(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(!vi(r))return{payload:{threadId:n,checkpointId:void 0,checkpointNs:void 0,messages:[],hasMore:!1,nextCursor:null,nextCursorNs:null},checkpoints:[],interrupt:null};const o=Fg(t),s=ac(r,0);return{payload:{threadId:n,checkpointId:(s==null?void 0:s.checkpointId)??void 0,checkpointNs:(s==null?void 0:s.checkpointNs)??void 0,messages:(s==null?void 0:s.messages)??[],hasMore:!!(s!=null&&s.nextCursor),nextCursor:(s==null?void 0:s.nextCursor)??null,nextCursorNs:(s==null?void 0:s.nextCursorNs)??null},checkpoints:o,interrupt:(s==null?void 0:s.interrupt)??null}}function ac(e,t){var f,h;if(!vi(e))return null;const n=e.values??{},o=(Array.isArray(n==null?void 0:n.messages)?n.messages:[]).map((p,w)=>zg(p,w)).filter(p=>!!p),s=qt((f=e.config)==null?void 0:f.configurable),i=bt(s,["checkpoint_id","checkpointId"]),a=bt(s,["checkpoint_ns","checkpointNs"]),l=qt((h=e.parentConfig)==null?void 0:h.configurable),u=bt(l,["checkpoint_id","checkpointId"])??null,d=bt(l,["checkpoint_ns","checkpointNs"])??null;return{messages:o,checkpointId:i??null,checkpointNs:a??null,nextCursor:u,nextCursorNs:d,interrupt:Bg(o,t)}}function Fg(e){const t=new Map;e.forEach((r,o)=>{if(!vi(r))return;const s=ac(r,o);if(!(s!=null&&s.checkpointId))return;const i=r==null?void 0:r.createdAt,a=typeof i=="string"&&i.trim()?i:new Date(Date.now()-o).toISOString(),l=$g(s.messages),u=s.messages[s.messages.length-1],d=qt(r==null?void 0:r.metadata),f=bt(d,["branch_label","branchLabel"]),h=qt(r==null?void 0:r.parentConfig),p=qt(h==null?void 0:h.configurable),w=bt(p,["checkpoint_id","checkpointId"]),x={checkpointId:s.checkpointId,checkpointNs:s.checkpointNs??"",createdAt:a,messagesLen:s.messages.length,preview:l??null,role:(u==null?void 0:u.role)??null,parentId:w??null,branchLabel:f??null,lastMessageId:(u==null?void 0:u.id)??null,hasMessages:s.messages.length>0},g=`${x.checkpointId}::${x.checkpointNs}`;t.has(g)||t.set(g,x)});const n=Array.from(t.values());return n.sort((r,o)=>lc(o.createdAt)-lc(r.createdAt)),n}function $g(e){var t;for(let n=e.length-1;n>=0;n--){const r=((t=e[n])==null?void 0:t.content)??[];for(let o=0;o<r.length;o++){const s=r[o];if(s&&s.type==="text"&&typeof s.text=="string"){const i=s.text.trim();if(i)return i}}}return null}function Bg(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 lc(e){if(!e)return 0;const t=Date.parse(e);return Number.isFinite(t)?t:0}function zg(e,t){if(!e||typeof e!="object")return null;const n=e,r=qt(e)??{},o=qt(n.data)??r,s=String(n.type??o.type??o.role??"").toLowerCase(),i=Lg[s];if(!i)return null;const a=o.id??o.message_id??o.run_id??null,l=typeof a=="string"&&a.trim()?a:`history-${i}-${t}`,u=qt(o.additional_kwargs)??qt(o.additionalKwargs),d=qt(o.response_metadata)??qt(o.responseMetadata),f=bt(u,["createdAt","created_at"])??bt(o,["created_at","createdAt"]),h=bt(u,["checkpointId","checkpoint_id"]),p=bt(u,["checkpointNs","checkpoint_ns"]),w=Hg(o.content),x={id:l,role:i,content:w};f&&(x.createdAt=f),typeof o.name=="string"&&o.name.trim()&&(x.name=o.name),typeof(d==null?void 0:d.model_name)=="string"&&(x.model=String(d.model_name)),!x.model&&typeof o.model=="string"&&(x.model=o.model),h&&(x.checkpointId=h),p&&(x.checkpointNs=p);const g=Kg(u,["createdAt","created_at","checkpointId","checkpoint_id","checkpointNs","checkpoint_ns","tool_calls"]),v=d?{...d}:void 0;g&&Object.keys(g).length&&(x.additionalKwargs=g),v&&Object.keys(v).length&&(x.responseMetadata=v);const b=Ug((u==null?void 0:u.tool_calls)??o.tool_calls);if(b.length&&(x.content=[...x.content,...b]),i==="tool"){const S=Vg(o,x.content);S&&(x.content=S)}return x}function Hg(e){if(!e)return[];if(Array.isArray(e))return e.map(t=>cc(t)).filter(t=>!!t);if(typeof e=="string")return e.trim()?[{type:"text",text:e.trim()}]:[];if(typeof e=="object"){const t=cc(e);return t?[t]:[]}return[]}function cc(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=bt(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=bt(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 Wg(t)??null;if(n==="tool_end"){const o=bt(t,["tool_call_id","toolCallId","id"]);if(!o)return null;const s={type:"tool_end",toolCallId:o,output:"output"in t?t.output:t.content};return typeof t.error=="string"&&(s.error=t.error),s}if(n==="interrupt")return{type:"interrupt",value:t.value,...t};if(n==="tool"){const o=bt(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 Ug(e){return Array.isArray(e)?e.map((t,n)=>{if(!t||typeof t!="object")return null;const r=t,o=bt(r,["id","call_id"]),s=qt(r.function),i=bt(s,["name"])??"tool",a=s==null?void 0:s.arguments,l=uc(a);return{type:"tool_call",id:o??`tool_call_${n}`,name:i,args:l}}).filter(t=>!!t):[]}function Wg(e){const t=bt(e,["id","call_id"]),n=bt(e,["name"]);if(!t||!n)return null;const r=uc(e.args??e.arguments);return{type:"tool_call",id:t,name:n,args:r}}function Vg(e,t){const n=bt(e,["tool_call_id","toolCallId","id"]);if(!n)return t;const r=e.content??e.output,o=typeof r=="string"?qg(r):r,s={type:"tool_end",toolCallId:n,output:o};return typeof e.error=="string"&&(s.error=e.error),[s]}function uc(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 qg(e){try{return JSON.parse(e)}catch{return e}}function qt(e){if(!(!e||typeof e!="object"||Array.isArray(e)))return{...e}}function bt(e,t){if(e)for(const n of t){const r=e[n];if(typeof r=="string"&&r.trim())return r}}function Kg(e,t){if(!e)return;const n={};let r=!1;for(const[o,s]of Object.entries(e)){if(t.includes(o)){r=!0;continue}s!==void 0&&(n[o]=s)}return r?Object.keys(n).length?n:void 0:e}function Gg(e){return e.type!=="thread_info"&&e.type!=="token"}const Yg={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null,messagesStreamMeta:{}};function Xg(e,t){var n;switch(t.type){case"reset":{console.log("[MessageReducer] 🔄 RESET action received"),console.log("[MessageReducer] 📊 Before reset - messages count:",e.messages.length);const r={messages:bi(((n=t.payload)==null?void 0:n.messages)??[]),assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null};return console.log("[MessageReducer] 📊 After reset - messages count:",r.messages.length),r}case"seed":{const r=bi(t.payload.messages),o={...e,messages:r,assemblingId:null};return Object.prototype.hasOwnProperty.call(t.payload,"checkpointId")&&(o.lastCheckpointId=t.payload.checkpointId??null),Object.prototype.hasOwnProperty.call(t.payload,"checkpointNs")&&(o.lastCheckpointNs=t.payload.checkpointNs??null),console.log("[MessageReducer] seed action (REPLACE mode):",{incomingCount:t.payload.messages.length,sanitizedCount:r.length,previousCount:e.messages.length,checkpointId:o.lastCheckpointId}),o}case"prepend":{const r=bi(t.payload.messages);if(!r.length)return console.log("[MessageReducer] No incoming messages after sanitize - skipping"),e;const o=new Set(e.messages.map(i=>i.id)),s=r.filter(i=>!o.has(i.id));return console.log("[MessageReducer] After dedup:",{uniqueCount:s.length,duplicates:r.length-s.length,finalTotal:s.length+e.messages.length}),s.length?{...e,messages:[...s,...e.messages]}:(console.log("[MessageReducer] All messages were duplicates - skipping"),e)}case"user_message":{const r=t.payload.message;return e.messages.some(o=>o.id===r.id)?e:{...e,messages:[...e.messages,r]}}case"event":return fc(e,t.payload.ev);case"batch":{const{events:r}=t.payload;return r.length?r.reduce((o,s)=>fc(o,s),e):e}case"interrupt_response":{const{interruptId:r}=t.payload,o=e.messages.map(s=>({...s,content:s.content.filter(i=>i.type!=="interrupt")}));return{...e,messages:o,pendingInterrupt:null}}default:return e}}function dc(e=[]){const[t,n]=y.useReducer(Xg,{...Yg,messages:e}),r=y.useRef([]),o=y.useRef(null),s=y.useRef(null),i=y.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=y.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=y.useCallback(d=>{r.current.push(d),a()},[a]);y.useEffect(()=>()=>{o.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.current),s.current!==null&&clearTimeout(s.current),r.current=[]},[]);const u=y.useMemo(()=>({reset:d=>n({type:"reset",payload:{messages:d}}),seed:(d,f)=>n({type:"seed",payload:{messages:d,...f??{}}}),prepend:d=>n({type:"prepend",payload:{messages:d}}),pushUser:d=>n({type:"user_message",payload:{message:d}}),onEvent:l}),[l]);return{state:t,dispatch:n,...u}}function fc(e,t){var n,r,o,s;if(t.type==="message_start"&&t.role==="assistant"){const i=t.id,a=Qg(t.model);if(e.messages.some(d=>d.id===i)){const d=e.messagesStreamMeta??{},f={...d,[i]:d[i]??{lastSeq:t.seq??null,lastText:""}};return{...e,assemblingId:i,messagesStreamMeta:f}}const u={id:i,role:"assistant",name:a||void 0,model:t.model,createdAt:new Date().toISOString(),content:[]};return{...e,assemblingId:i,messages:[...e.messages,u]}}if(t.type==="message_delta"){const i=e.assemblingId??yi(e.messages);if(!i)return e;const a=e.messages,l=a.findIndex(S=>S.id===i&&S.role==="assistant");if(l===-1)return e;const u=a[l],d=e.messagesStreamMeta??{},f=d[i]??{lastSeq:null,lastText:xc(u.content)},h=t.seq??null;if(h!==null&&typeof h=="number"&&typeof f.lastSeq=="number"&&h<=f.lastSeq)return console.debug("[MessageReducer] skipping delta - seq <= lastSeq",{seq:h,lastSeq:f.lastSeq}),e;const{newParts:p,newMeta:w,changed:x}=Jg(u.content,t.delta,f,h);if(!x)return e;const g={...u,content:p},v=hc(a,l,g),b={...d,[i]:w};return{...e,messages:v,messagesStreamMeta:b}}if(t.type==="message_end"){const i=e.assemblingId??yi(e.messages);if(!i)return{...e,assemblingId:null};const a=e.messages,l=a.findIndex(u=>u.id===i&&u.role==="assistant");if(l>=0){const u=a[l];if(!((n=u.content)==null?void 0:n.some(f=>{var h;return(f==null?void 0:f.type)==="text"&&((h=f.text)==null?void 0:h.trim())}))){console.debug("[MessageReducer] pruning assistant message with no visible text",{id:u.id,contentTypes:(r=u.content)==null?void 0:r.map(h=>h==null?void 0:h.type),contentPreview:(o=u.content)==null?void 0:o.map(h=>(h==null?void 0:h.type)==="text"?String(h.text).slice(0,100):h==null?void 0:h.type)});const f=[...a.slice(0,l),...a.slice(l+1)];return{...e,assemblingId:null,messages:f}}}return e}if(t.type==="tool_start"){const i=t.id??t.call_id,a=t.name??t.tool??"tool";if(!i)return e;const l=`tool-${i}`,u={type:"tool_call",id:i,name:a,args:t.args};if(e.messages.find(h=>h.id===l))return{...e,toolIndex:{...e.toolIndex,[i]:l}};const f={id:l,role:"tool",name:a,createdAt:new Date().toISOString(),content:[u]};return{...e,messages:[...e.messages,f],toolIndex:{...e.toolIndex,[i]:l}}}if(t.type==="tool_end"){const i=t.id??t.call_id;if(!i)return e;const a=e.toolIndex[i]??`tool-${i}`,l={type:"tool_end",toolCallId:i,output:t.output,error:t.error},u=e.messages.find(h=>h.id===a),d={id:a,role:"tool",name:t.name??((s=e.messages.find(h=>h.id===a))==null?void 0:s.name),content:[l],createdAt:new Date().toISOString()},f=u?mc(e.messages,a,[l]):[...e.messages,d];return{...e,messages:f,toolIndex:{...e.toolIndex,[i]:a}}}if(t.type==="checkpoint"){const i=t.checkpointNs??e.lastCheckpointNs??null,a=Zg(e.messages,t.checkpointId,i);return{...e,lastCheckpointId:t.checkpointId,lastCheckpointNs:i,messages:a}}if(t.type==="branch"){const i=t.checkpointId??e.lastCheckpointId,a=t.checkpointNs??e.lastCheckpointNs;return{...e,lastBranch:t,lastCheckpointId:i??null,lastCheckpointNs:a??null}}if(t.type==="error"){const i={id:`err-${Date.now()}`,role:"system",content:[{type:"text",text:`Error: ${t.message}`}],createdAt:new Date().toISOString()};return{...e,messages:[...e.messages,i]}}if(t.type==="interrupt"){const i=e.assemblingId??yi(e.messages),a={type:"interrupt",value:t.value,id:t.id};if(i)return{...e,assemblingId:null,messages:mc(e.messages,i,[a]),pendingInterrupt:{id:t.id,value:t.value}};const l=`interrupt-${t.id}`;if(e.messages.findIndex(f=>f.id===l)!==-1)return{...e,assemblingId:null,messages:pc(e.messages,l,f=>({...f,content:gc(f.content??[],[a])})),pendingInterrupt:{id:t.id,value:t.value}};const d={id:l,role:"system",createdAt:new Date().toISOString(),content:[a]};return{...e,messages:[...e.messages,d],pendingInterrupt:{id:t.id,value:t.value}}}return e}function bi(e){return e.filter(t=>{if(t.role!=="assistant")return!0;const n=(t.content||[]).some(o=>{var s;return o&&o.type==="text"&&((s=o.text)==null?void 0:s.trim())}),r=(t.content||[]).some(o=>o&&o.type==="image_url");return!!(n||r)})}function hc(e,t,n){return t<0||t>=e.length?e:[...e.slice(0,t),n,...e.slice(t+1)]}function yi(e){for(let t=e.length-1;t>=0;t--)if(e[t].role==="assistant")return e[t].id;return null}function pc(e,t,n){const r=e.findIndex(i=>i.id===t);if(r===-1)return e;const o=e[r],s=n(o);return s===o?e:[...e.slice(0,r),s,...e.slice(r+1)]}function mc(e,t,n){return pc(e,t,r=>({...r,content:gc(r.content,n)}))}function gc(e,t){const n=e.slice();for(const r of t)if(r.type==="text"){const o=n[n.length-1],s=r.text??"";if(!s)continue;if((o==null?void 0:o.type)==="text"){let i=function(p){return p.replace(/\s+/g," ").trim()};const a=o,l=a.text??"";if(console.debug("[MessageReducer] mergeParts",{incomingLength:s.length,previousLength:l.length,incomingSnippet:s.slice(0,100),previousSnippet:l.slice(-100)}),!l){a.text=s;continue}const u=i(s),d=i(l);if(u.startsWith(d)||s.startsWith(l)){console.debug("[MessageReducer] incoming startsWith previous (norm/raw) - replacing",{incomingLength:s.length,previousLength:l.length}),a.text=s;continue}if(u.includes(d)){console.debug("[MessageReducer] incoming includes previous (normalized) - replacing",{incomingLength:s.length,previousLength:l.length}),a.text=s;continue}if(d.includes(u)&&u.length<=3){console.debug("[MessageReducer] previous includes incoming (normalized) - skipping trivial incoming",{incomingLength:s.length,previousLength:l.length});continue}const h=wc(l,s);h?(console.debug("[MessageReducer] suffix computed",{suffixLength:h.length}),a.text=l+h):(console.debug("[MessageReducer] no overlap detected - appending incoming",{incomingLength:s.length}),a.text=l+s)}else n.push({type:"text",text:s})}else n.push(r);return n}function xc(e){return!e||!e.length?"":e.filter(t=>t.type==="text").map(t=>t.text??"").join("")}function Jg(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??xc(e);let l="",u=e.slice();if(s){const f=wc(a,s);if(f===""?l="":f===s?l=s:l=f,l){const h=u[u.length-1];if((h==null?void 0:h.type)==="text"){const p=h.text??"",w={...h,text:p+l};u=[...u.slice(0,u.length-1),w]}else u=[...u,{type:"text",text:l}];o.lastText=a+l}else o.lastText=a}i.length&&(u=[...u,...i]);const d=!!(l||i.length);return{newParts:u,newMeta:o,changed:d}}function vc(e){return e.replace(/\s+/g," ").trim()}function wc(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=vc(e),o=vc(t);if(r===o)return"";const s=Math.min(r.length,o.length);for(let i=s;i>0;i--)if(r.slice(-i)===o.slice(0,i))return t;return t}function Zg(e,t,n){for(let r=e.length-1;r>=0;r--)if(e[r].role==="assistant"){const s={...e[r],checkpointId:t,checkpointNs:n??void 0};return hc(e,r,s)}return e}function Qg(e){if(!e)return null;const t=e.split("/");return t[t.length-1]||null}function bc(e={}){const t=y.useMemo(()=>En(e.baseUrl),[e.baseUrl]),n=e.streamPath??"/runs/stream",[r,o]=y.useState(e.token??null),s=y.useRef(e.headers??{}),i=e.credentials??"include",[a,l]=y.useState(!1),[u,d]=y.useState(null),[f,h]=y.useState(""),[p,w]=y.useState(null),[x,g]=y.useState(0),[v,b]=y.useState(!1),S=y.useRef(null),N=y.useRef(!0),C=y.useRef(0),k=y.useCallback(P=>{o(P)},[]),I=y.useCallback(()=>{var P;(P=S.current)==null||P.abort(),S.current=null,l(!1),b(!1),C.current=0,g(0)},[]),A=y.useCallback(()=>{h(""),w(null),d(null)},[]),j=y.useCallback((P,L,F)=>{S.current&&(S.current.abort(),S.current=null),l(!0),d(null),e.autoAppendAssistant!==!1&&h("");const V=new AbortController;return S.current=V,(async()=>{var G,q,U,B,$,ce,D,Q;const M=de=>{var we;try{const ye=JSON.parse(JSON.stringify(de));return(we=ye==null?void 0:ye.payload)!=null&&we.files_info&&Array.isArray(ye.payload.files_info)&&(ye.payload.files_info=ye.payload.files_info.map(Se=>({...Se,data:Se!=null&&Se.data?`<base64 ${String(Se.data).length} chars>`:Se==null?void 0:Se.data}))),ye}catch{return de}};try{let de={};try{if(r)de={Authorization:`Bearer ${r}`};else if(typeof window<"u"){const He=window.__AUTH_TOKEN__,ct=((G=window.localStorage)==null?void 0:G.getItem("authToken"))||null;let tt=null;try{const gt=(q=window.localStorage)==null?void 0:q.getItem("chat-settings");gt&&(tt=((U=JSON.parse(gt))==null?void 0:U.apiKey)||null)}catch{}const Be=He||ct||tt||null;Be&&(de={Authorization:`Bearer ${Be}`})}}catch{}console.debug("[use-chat] POST",t+n,M(P));const we=await fetch(t+n,{method:"POST",headers:{"Content-Type":"application/json",Accept:"text/event-stream",...de,...s.current},body:JSON.stringify(P),signal:V.signal,credentials:i});if(!we.ok||!we.body){const Pe=await we.text().catch(()=>"");throw console.debug("[use-chat] non-OK response",we.status,Pe==null?void 0:Pe.slice(0,500)),new Error(`stream ${we.status}${Pe?": "+Pe:""}`)}b(!0);const ye=we.body.getReader(),Se=new TextDecoder;let K="",O=[];C.current=0,g(0);let X=0,ee=null;const fe=()=>{if(O.length){const Pe=O.join("");O=[],N.current&&h(He=>He+Pe)}ee=null},ne=()=>{typeof window<"u"&&ee==null&&(ee=requestAnimationFrame(fe))};let pe=Date.now();const Ze=setInterval(()=>{var Pe;if(Date.now()-pe>6e4){const He="Stream idle timeout";d(He),V.abort(),(Pe=F==null?void 0:F.onError)==null||Pe.call(F,He)}},5e3),Qe=1024*1024;try{const Pe=we.headers.get("X-Thread-Id")||we.headers.get("x-thread-id"),He=we.headers.get("X-Thread-Created")||we.headers.get("x-thread-created"),ct=Pe??null,tt=String(He??"").toLowerCase()==="true";for((B=F==null?void 0:F.onOpen)==null||B.call(F,{threadId:ct,created:tt});;){const{value:Be,done:gt}=await ye.read();if(gt)break;K+=Se.decode(Be,{stream:!0}),K.length>Qe&&(K="",console.warn("Stream buffer reset: exceeded 1MB"));let J;for(;(J=K.indexOf(`
|
|
30
|
+
<%s key={someKey} {...props} />`,C,Pn,_,Pn),wr[Pn+C]=!0}}return I===r?Co(dt):br(dt),dt}}function Se(I,H,J){return ie(I,H,J,!0)}function We(I,H,J){return ie(I,H,J,!1)}var et=We,Mt=Se;Ur.Fragment=r,Ur.jsx=et,Ur.jsxs=Mt}()),Ur}process.env.NODE_ENV==="production"?ai.exports=mm():ai.exports=gm();var c=ai.exports;function vl(e,t){return function(){return e.apply(t,arguments)}}const{toString:xm}=Object.prototype,{getPrototypeOf:li}=Object,{iterator:Io,toStringTag:bl}=Symbol,Eo=(e=>t=>{const n=xm.call(t);return e[n]||(e[n]=n.slice(8,-1).toLowerCase())})(Object.create(null)),rn=e=>(e=e.toLowerCase(),t=>Eo(t)===e),No=e=>t=>typeof t===e,{isArray:Sr}=Array,Cr=No("undefined");function Wr(e){return e!==null&&!Cr(e)&&e.constructor!==null&&!Cr(e.constructor)&&Lt(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const wl=rn("ArrayBuffer");function vm(e){let t;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?t=ArrayBuffer.isView(e):t=e&&e.buffer&&wl(e.buffer),t}const bm=No("string"),Lt=No("function"),yl=No("number"),Vr=e=>e!==null&&typeof e=="object",wm=e=>e===!0||e===!1,Ao=e=>{if(Eo(e)!=="object")return!1;const t=li(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(bl in e)&&!(Io in e)},ym=e=>{if(!Vr(e)||Wr(e))return!1;try{return Object.keys(e).length===0&&Object.getPrototypeOf(e)===Object.prototype}catch{return!1}},Sm=rn("Date"),Cm=rn("File"),Tm=rn("Blob"),km=rn("FileList"),Im=e=>Vr(e)&&Lt(e.pipe),Em=e=>{let t;return e&&(typeof FormData=="function"&&e instanceof FormData||Lt(e.append)&&((t=Eo(e))==="formdata"||t==="object"&&Lt(e.toString)&&e.toString()==="[object FormData]"))},Nm=rn("URLSearchParams"),[Am,_m,jm,Rm]=["ReadableStream","Request","Response","Headers"].map(rn),Pm=e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function Kr(e,t,{allOwnKeys:n=!1}={}){if(e===null||typeof e>"u")return;let r,o;if(typeof e!="object"&&(e=[e]),Sr(e))for(r=0,o=e.length;r<o;r++)t.call(null,e[r],r,e);else{if(Wr(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 Sl(e,t){if(Wr(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 Zn=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global,Cl=e=>!Cr(e)&&e!==Zn;function ci(){const{caseless:e,skipUndefined:t}=Cl(this)&&this||{},n={},r=(o,s)=>{const i=e&&Sl(n,s)||s;Ao(n[i])&&Ao(o)?n[i]=ci(n[i],o):Ao(o)?n[i]=ci({},o):Sr(o)?n[i]=o.slice():(!t||!Cr(o))&&(n[i]=o)};for(let o=0,s=arguments.length;o<s;o++)arguments[o]&&Kr(arguments[o],r);return n}const Om=(e,t,n,{allOwnKeys:r}={})=>(Kr(t,(o,s)=>{n&&Lt(o)?e[s]=vl(o,n):e[s]=o},{allOwnKeys:r}),e),Mm=e=>(e.charCodeAt(0)===65279&&(e=e.slice(1)),e),Dm=(e,t,n,r)=>{e.prototype=Object.create(t.prototype,r),e.prototype.constructor=e,Object.defineProperty(e,"super",{value:t.prototype}),n&&Object.assign(e.prototype,n)},Lm=(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},$m=(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},Fm=e=>{if(!e)return null;if(Sr(e))return e;let t=e.length;if(!yl(t))return null;const n=new Array(t);for(;t-- >0;)n[t]=e[t];return n},Bm=(e=>t=>e&&t instanceof e)(typeof Uint8Array<"u"&&li(Uint8Array)),zm=(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])}},Hm=(e,t)=>{let n;const r=[];for(;(n=e.exec(t))!==null;)r.push(n);return r},Um=rn("HTMLFormElement"),Wm=e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(n,r,o){return r.toUpperCase()+o}),Tl=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),Vm=rn("RegExp"),kl=(e,t)=>{const n=Object.getOwnPropertyDescriptors(e),r={};Kr(n,(o,s)=>{let i;(i=t(o,s,e))!==!1&&(r[s]=i||o)}),Object.defineProperties(e,r)},Km=e=>{kl(e,(t,n)=>{if(Lt(e)&&["arguments","caller","callee"].indexOf(n)!==-1)return!1;const r=e[n];if(Lt(r)){if(t.enumerable=!1,"writable"in t){t.writable=!1;return}t.set||(t.set=()=>{throw Error("Can not rewrite read-only method '"+n+"'")})}})},qm=(e,t)=>{const n={},r=o=>{o.forEach(s=>{n[s]=!0})};return Sr(e)?r(e):r(String(e).split(t)),n},Gm=()=>{},Ym=(e,t)=>e!=null&&Number.isFinite(e=+e)?e:t;function Xm(e){return!!(e&&Lt(e.append)&&e[bl]==="FormData"&&e[Io])}const Jm=e=>{const t=new Array(10),n=(r,o)=>{if(Vr(r)){if(t.indexOf(r)>=0)return;if(Wr(r))return r;if(!("toJSON"in r)){t[o]=r;const s=Sr(r)?[]:{};return Kr(r,(i,a)=>{const l=n(i,o+1);!Cr(l)&&(s[a]=l)}),t[o]=void 0,s}}return r};return n(e,0)},Zm=rn("AsyncFunction"),Qm=e=>e&&(Vr(e)||Lt(e))&&Lt(e.then)&&Lt(e.catch),Il=((e,t)=>e?setImmediate:t?((n,r)=>(Zn.addEventListener("message",({source:o,data:s})=>{o===Zn&&s===n&&r.length&&r.shift()()},!1),o=>{r.push(o),Zn.postMessage(n,"*")}))(`axios@${Math.random()}`,[]):n=>setTimeout(n))(typeof setImmediate=="function",Lt(Zn.postMessage)),eg=typeof queueMicrotask<"u"?queueMicrotask.bind(Zn):typeof process<"u"&&process.nextTick||Il,R={isArray:Sr,isArrayBuffer:wl,isBuffer:Wr,isFormData:Em,isArrayBufferView:vm,isString:bm,isNumber:yl,isBoolean:wm,isObject:Vr,isPlainObject:Ao,isEmptyObject:ym,isReadableStream:Am,isRequest:_m,isResponse:jm,isHeaders:Rm,isUndefined:Cr,isDate:Sm,isFile:Cm,isBlob:Tm,isRegExp:Vm,isFunction:Lt,isStream:Im,isURLSearchParams:Nm,isTypedArray:Bm,isFileList:km,forEach:Kr,merge:ci,extend:Om,trim:Pm,stripBOM:Mm,inherits:Dm,toFlatObject:Lm,kindOf:Eo,kindOfTest:rn,endsWith:$m,toArray:Fm,forEachEntry:zm,matchAll:Hm,isHTMLForm:Um,hasOwnProperty:Tl,hasOwnProp:Tl,reduceDescriptors:kl,freezeMethods:Km,toObjectSet:qm,toCamelCase:Wm,noop:Gm,toFiniteNumber:Ym,findKey:Sl,global:Zn,isContextDefined:Cl,isSpecCompliantForm:Xm,toJSONObject:Jm,isAsyncFn:Zm,isThenable:Qm,setImmediate:Il,asap:eg,isIterable:e=>e!=null&&Lt(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)}R.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:R.toJSONObject(this.config),code:this.code,status:this.status}}});const El=De.prototype,Nl={};["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=>{Nl[e]={value:e}}),Object.defineProperties(De,Nl),Object.defineProperty(El,"isAxiosError",{value:!0}),De.from=(e,t,n,r,o,s)=>{const i=Object.create(El);R.toFlatObject(e,i,function(d){return d!==Error.prototype},u=>u!=="isAxiosError");const a=e&&e.message?e.message:"Error",l=t==null&&e?e.code:t;return 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 tg=null;function ui(e){return R.isPlainObject(e)||R.isArray(e)}function Al(e){return R.endsWith(e,"[]")?e.slice(0,-2):e}function _l(e,t,n){return e?e.concat(t).map(function(o,s){return o=Al(o),!n&&s?"["+o+"]":o}).join(n?".":""):t}function ng(e){return R.isArray(e)&&!e.some(ui)}const rg=R.toFlatObject(R,{},null,function(t){return/^is[A-Z]/.test(t)});function _o(e,t,n){if(!R.isObject(e))throw new TypeError("target must be an object");t=t||new FormData,n=R.toFlatObject(n,{metaTokens:!0,dots:!1,indexes:!1},!1,function(x,g){return!R.isUndefined(g[x])});const r=n.metaTokens,o=n.visitor||d,s=n.dots,i=n.indexes,l=(n.Blob||typeof Blob<"u"&&Blob)&&R.isSpecCompliantForm(t);if(!R.isFunction(o))throw new TypeError("visitor must be a function");function u(b){if(b===null)return"";if(R.isDate(b))return b.toISOString();if(R.isBoolean(b))return b.toString();if(!l&&R.isBlob(b))throw new De("Blob is not supported. Use a Buffer instead.");return R.isArrayBuffer(b)||R.isTypedArray(b)?l&&typeof Blob=="function"?new Blob([b]):Buffer.from(b):b}function d(b,x,g){let v=b;if(b&&!g&&typeof b=="object"){if(R.endsWith(x,"{}"))x=r?x:x.slice(0,-2),b=JSON.stringify(b);else if(R.isArray(b)&&ng(b)||(R.isFileList(b)||R.endsWith(x,"[]"))&&(v=R.toArray(b)))return x=Al(x),v.forEach(function(S,N){!(R.isUndefined(S)||S===null)&&t.append(i===!0?_l([x],N,s):i===null?x:x+"[]",u(S))}),!1}return ui(b)?!0:(t.append(_l(g,x,s),u(b)),!1)}const f=[],h=Object.assign(rg,{defaultVisitor:d,convertValue:u,isVisitable:ui});function p(b,x){if(!R.isUndefined(b)){if(f.indexOf(b)!==-1)throw Error("Circular reference detected in "+x.join("."));f.push(b),R.forEach(b,function(v,w){(!(R.isUndefined(v)||v===null)&&o.call(t,v,R.isString(w)?w.trim():w,x,h))===!0&&p(v,x?x.concat(w):[w])}),f.pop()}}if(!R.isObject(e))throw new TypeError("data must be an object");return p(e),t}function jl(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&&_o(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,jl)}:jl;return this._pairs.map(function(o){return n(o[0])+"="+n(o[1])},"").join("&")};function og(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||og;R.isFunction(n)&&(n={serialize:n});const o=n&&n.serialize;let s;if(o?s=o(t,n):s=R.isURLSearchParams(t)?t.toString():new 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){R.forEach(this.handlers,function(r){r!==null&&t(r)})}}const Ml={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,ig=fi&&(!hi||["ReactNative","NativeScript","NS"].indexOf(hi.product)<0),ag=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function",lg=fi&&window.location.href||"http://localhost",Et={...Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv:fi,hasStandardBrowserEnv:ig,hasStandardBrowserWebWorkerEnv:ag,navigator:hi,origin:lg},Symbol.toStringTag,{value:"Module"})),...sg};function cg(e,t){return _o(e,new Et.classes.URLSearchParams,{visitor:function(n,r,o,s){return Et.isNode&&R.isBuffer(n)?(this.append(r,n.toString("base64")),!1):s.defaultVisitor.apply(this,arguments)},...t})}function ug(e){return R.matchAll(/\w+|\[(\w*)]/g,e).map(t=>t[0]==="[]"?"":t[1]||t[0])}function dg(e){const t={},n=Object.keys(e);let r;const o=n.length;let s;for(r=0;r<o;r++)s=n[r],t[s]=e[s];return t}function Dl(e){function t(n,r,o,s){let i=n[s++];if(i==="__proto__")return!0;const a=Number.isFinite(+i),l=s>=n.length;return i=!i&&R.isArray(o)?o.length:i,l?(R.hasOwnProp(o,i)?o[i]=[o[i],r]:o[i]=r,!a):((!o[i]||!R.isObject(o[i]))&&(o[i]=[]),t(n,r,o[i],s)&&R.isArray(o[i])&&(o[i]=dg(o[i])),!a)}if(R.isFormData(e)&&R.isFunction(e.entries)){const n={};return R.forEachEntry(e,(r,o)=>{t(ug(r),o,n,0)}),n}return null}function fg(e,t,n){if(R.isString(e))try{return(t||JSON.parse)(e),R.trim(e)}catch(r){if(r.name!=="SyntaxError")throw r}return(n||JSON.stringify)(e)}const qr={transitional:Ml,adapter:["xhr","http","fetch"],transformRequest:[function(t,n){const r=n.getContentType()||"",o=r.indexOf("application/json")>-1,s=R.isObject(t);if(s&&R.isHTMLForm(t)&&(t=new FormData(t)),R.isFormData(t))return o?JSON.stringify(Dl(t)):t;if(R.isArrayBuffer(t)||R.isBuffer(t)||R.isStream(t)||R.isFile(t)||R.isBlob(t)||R.isReadableStream(t))return t;if(R.isArrayBufferView(t))return t.buffer;if(R.isURLSearchParams(t))return n.setContentType("application/x-www-form-urlencoded;charset=utf-8",!1),t.toString();let a;if(s){if(r.indexOf("application/x-www-form-urlencoded")>-1)return cg(t,this.formSerializer).toString();if((a=R.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),fg(t)):t}],transformResponse:[function(t){const n=this.transitional||qr.transitional,r=n&&n.forcedJSONParsing,o=this.responseType==="json";if(R.isResponse(t)||R.isReadableStream(t))return t;if(t&&R.isString(t)&&(r&&!this.responseType||o)){const i=!(n&&n.silentJSONParsing)&&o;try{return JSON.parse(t,this.parseReviver)}catch(a){if(i)throw a.name==="SyntaxError"?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:Et.classes.FormData,Blob:Et.classes.Blob},validateStatus:function(t){return t>=200&&t<300},headers:{common:{Accept:"application/json, text/plain, */*","Content-Type":void 0}}};R.forEach(["delete","get","head","post","put","patch"],e=>{qr.headers[e]={}});const hg=R.toObjectSet(["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"]),pg=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]&&hg[n])&&(n==="set-cookie"?t[n]?t[n].push(r):t[n]=[r]:t[n]=t[n]?t[n]+", "+r:r)}),t},Ll=Symbol("internals");function Gr(e){return e&&String(e).trim().toLowerCase()}function jo(e){return e===!1||e==null?e:R.isArray(e)?e.map(jo):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 gg=e=>/^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(e.trim());function pi(e,t,n,r,o){if(R.isFunction(r))return r.call(this,t,n);if(o&&(t=n),!!R.isString(t)){if(R.isString(r))return t.indexOf(r)!==-1;if(R.isRegExp(r))return r.test(t)}}function xg(e){return e.trim().toLowerCase().replace(/([a-z\d])(\w*)/g,(t,n,r)=>n.toUpperCase()+r)}function vg(e,t){const n=R.toCamelCase(" "+t);["get","set","has"].forEach(r=>{Object.defineProperty(e,r+n,{value:function(o,s,i){return this[r].call(this,t,o,s,i)},configurable:!0})})}let $t=class{constructor(t){t&&this.set(t)}set(t,n,r){const o=this;function s(a,l,u){const d=Gr(l);if(!d)throw new Error("header name must be a non-empty string");const f=R.findKey(o,d);(!f||o[f]===void 0||u===!0||u===void 0&&o[f]!==!1)&&(o[f||l]=jo(a))}const i=(a,l)=>R.forEach(a,(u,d)=>s(u,d,l));if(R.isPlainObject(t)||t instanceof this.constructor)i(t,n);else if(R.isString(t)&&(t=t.trim())&&!gg(t))i(pg(t),n);else if(R.isObject(t)&&R.isIterable(t)){let a={},l,u;for(const d of t){if(!R.isArray(d))throw TypeError("Object iterator must return a key-value pair");a[u=d[0]]=(l=a[u])?R.isArray(l)?[...l,d[1]]:[l,d[1]]:d[1]}i(a,n)}else t!=null&&s(n,t,r);return this}get(t,n){if(t=Gr(t),t){const r=R.findKey(this,t);if(r){const o=this[r];if(!n)return o;if(n===!0)return mg(o);if(R.isFunction(n))return n.call(this,o,r);if(R.isRegExp(n))return n.exec(o);throw new TypeError("parser must be boolean|regexp|function")}}}has(t,n){if(t=Gr(t),t){const r=R.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=Gr(i),i){const a=R.findKey(r,i);a&&(!n||pi(r,r[a],a,n))&&(delete r[a],o=!0)}}return R.isArray(t)?t.forEach(s):s(t),o}clear(t){const n=Object.keys(this);let r=n.length,o=!1;for(;r--;){const s=n[r];(!t||pi(this,this[s],s,t,!0))&&(delete this[s],o=!0)}return o}normalize(t){const n=this,r={};return R.forEach(this,(o,s)=>{const i=R.findKey(r,s);if(i){n[i]=jo(o),delete n[s];return}const a=t?xg(s):String(s).trim();a!==s&&delete n[s],n[a]=jo(o),r[a]=!0}),this}concat(...t){return this.constructor.concat(this,...t)}toJSON(t){const n=Object.create(null);return R.forEach(this,(r,o)=>{r!=null&&r!==!1&&(n[o]=t&&R.isArray(r)?r.join(", "):r)}),n}[Symbol.iterator](){return Object.entries(this.toJSON())[Symbol.iterator]()}toString(){return Object.entries(this.toJSON()).map(([t,n])=>t+": "+n).join(`
|
|
32
|
+
`)}getSetCookie(){return this.get("set-cookie")||[]}get[Symbol.toStringTag](){return"AxiosHeaders"}static from(t){return t instanceof this?t:new this(t)}static concat(t,...n){const r=new this(t);return n.forEach(o=>r.set(o)),r}static accessor(t){const r=(this[Ll]=this[Ll]={accessors:{}}).accessors,o=this.prototype;function s(i){const a=Gr(i);r[a]||(vg(o,i),r[a]=!0)}return R.isArray(t)?t.forEach(s):s(t),this}};$t.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),R.reduceDescriptors($t.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(r){this[n]=r}}}),R.freezeMethods($t);function mi(e,t){const n=this||qr,r=t||n,o=$t.from(r.headers);let s=r.data;return R.forEach(e,function(a){s=a.call(n,s,o.normalize(),t?t.status:void 0)}),o.normalize(),s}function $l(e){return!!(e&&e.__CANCEL__)}function Tr(e,t,n){De.call(this,e??"canceled",De.ERR_CANCELED,t,n),this.name="CanceledError"}R.inherits(Tr,De,{__CANCEL__:!0});function Fl(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 bg(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function wg(e,t){e=e||10;const n=new Array(e),r=new Array(e);let o=0,s=0,i;return t=t!==void 0?t:1e3,function(l){const u=Date.now(),d=r[s];i||(i=u),n[o]=l,r[o]=u;let f=s,h=0;for(;f!==o;)h+=n[f++],f=f%e;if(o=(o+1)%e,o===s&&(s=(s+1)%e),u-i<t)return;const p=d&&u-d;return p?Math.round(h*1e3/p):void 0}}function yg(e,t){let n=0,r=1e3/t,o,s;const i=(u,d=Date.now())=>{n=d,o=null,s&&(clearTimeout(s),s=null),e(...u)};return[(...u)=>{const d=Date.now(),f=d-n;f>=r?i(u,d):(o=u,s||(s=setTimeout(()=>{s=null,i(o)},r-f)))},()=>o&&i(o)]}const Ro=(e,t,n=3)=>{let r=0;const o=wg(50,250);return yg(s=>{const i=s.loaded,a=s.lengthComputable?s.total:void 0,l=i-r,u=o(l),d=i<=a;r=i;const f={loaded:i,total:a,progress:a?i/a:void 0,bytes:l,rate:u||void 0,estimated:u&&a&&d?(a-i)/u:void 0,event:s,lengthComputable:a!=null,[t?"download":"upload"]:!0};e(f)},n)},Bl=(e,t)=>{const n=e!=null;return[r=>t[0]({lengthComputable:n,total:e,loaded:r}),t[1]]},zl=e=>(...t)=>R.asap(()=>e(...t)),Sg=Et.hasStandardBrowserEnv?((e,t)=>n=>(n=new URL(n,Et.origin),e.protocol===n.protocol&&e.host===n.host&&(t||e.port===n.port)))(new URL(Et.origin),Et.navigator&&/(msie|trident)/i.test(Et.navigator.userAgent)):()=>!0,Cg=Et.hasStandardBrowserEnv?{write(e,t,n,r,o,s){const i=[e+"="+encodeURIComponent(t)];R.isNumber(n)&&i.push("expires="+new Date(n).toGMTString()),R.isString(r)&&i.push("path="+r),R.isString(o)&&i.push("domain="+o),s===!0&&i.push("secure"),document.cookie=i.join("; ")},read(e){const t=document.cookie.match(new RegExp("(^|;\\s*)("+e+")=([^;]*)"));return t?decodeURIComponent(t[3]):null},remove(e){this.write(e,"",Date.now()-864e5)}}:{write(){},read(){return null},remove(){}};function Tg(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function kg(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function Hl(e,t,n){let r=!Tg(t);return e&&(r||n==!1)?kg(e,t):t}const Ul=e=>e instanceof $t?{...e}:e;function Qn(e,t){t=t||{};const n={};function r(u,d,f,h){return R.isPlainObject(u)&&R.isPlainObject(d)?R.merge.call({caseless:h},u,d):R.isPlainObject(d)?R.merge({},d):R.isArray(d)?d.slice():d}function o(u,d,f,h){if(R.isUndefined(d)){if(!R.isUndefined(u))return r(void 0,u,f,h)}else return r(u,d,f,h)}function s(u,d){if(!R.isUndefined(d))return r(void 0,d)}function i(u,d){if(R.isUndefined(d)){if(!R.isUndefined(u))return r(void 0,u)}else return r(void 0,d)}function a(u,d,f){if(f in t)return r(u,d);if(f in e)return r(void 0,u)}const l={url:s,method:s,data:s,baseURL:i,transformRequest:i,transformResponse:i,paramsSerializer:i,timeout:i,timeoutMessage:i,withCredentials:i,withXSRFToken:i,adapter:i,responseType:i,xsrfCookieName:i,xsrfHeaderName:i,onUploadProgress:i,onDownloadProgress:i,decompress:i,maxContentLength:i,maxBodyLength:i,beforeRedirect:i,transport:i,httpAgent:i,httpsAgent:i,cancelToken:i,socketPath:i,responseEncoding:i,validateStatus:a,headers:(u,d,f)=>o(Ul(u),Ul(d),f,!0)};return R.forEach(Object.keys({...e,...t}),function(d){const f=l[d]||o,h=f(e[d],t[d],d);R.isUndefined(h)&&f!==a||(n[d]=h)}),n}const Wl=e=>{const t=Qn({},e);let{data:n,withXSRFToken:r,xsrfHeaderName:o,xsrfCookieName:s,headers:i,auth:a}=t;if(t.headers=i=$t.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)):""))),R.isFormData(n)){if(Et.hasStandardBrowserEnv||Et.hasStandardBrowserWebWorkerEnv)i.setContentType(void 0);else if(R.isFunction(n.getHeaders)){const l=n.getHeaders(),u=["content-type","content-length"];Object.entries(l).forEach(([d,f])=>{u.includes(d.toLowerCase())&&i.set(d,f)})}}if(Et.hasStandardBrowserEnv&&(r&&R.isFunction(r)&&(r=r(t)),r||r!==!1&&Sg(t.url))){const l=o&&s&&Cg.read(s);l&&i.set(o,l)}return t},Ig=typeof XMLHttpRequest<"u"&&function(e){return new Promise(function(n,r){const o=Wl(e);let s=o.data;const i=$t.from(o.headers).normalize();let{responseType:a,onUploadProgress:l,onDownloadProgress:u}=o,d,f,h,p,b;function x(){p&&p(),b&&b(),o.cancelToken&&o.cancelToken.unsubscribe(d),o.signal&&o.signal.removeEventListener("abort",d)}let g=new XMLHttpRequest;g.open(o.method.toUpperCase(),o.url,!0),g.timeout=o.timeout;function v(){if(!g)return;const S=$t.from("getAllResponseHeaders"in g&&g.getAllResponseHeaders()),T={data:!a||a==="text"||a==="json"?g.responseText:g.response,status:g.status,statusText:g.statusText,headers:S,config:e,request:g};Fl(function(E){n(E),x()},function(E){r(E),x()},T),g=null}"onloadend"in g?g.onloadend=v:g.onreadystatechange=function(){!g||g.readyState!==4||g.status===0&&!(g.responseURL&&g.responseURL.indexOf("file:")===0)||setTimeout(v)},g.onabort=function(){g&&(r(new De("Request aborted",De.ECONNABORTED,e,g)),g=null)},g.onerror=function(N){const T=N&&N.message?N.message:"Network Error",k=new De(T,De.ERR_NETWORK,e,g);k.event=N||null,r(k),g=null},g.ontimeout=function(){let N=o.timeout?"timeout of "+o.timeout+"ms exceeded":"timeout exceeded";const T=o.transitional||Ml;o.timeoutErrorMessage&&(N=o.timeoutErrorMessage),r(new De(N,T.clarifyTimeoutError?De.ETIMEDOUT:De.ECONNABORTED,e,g)),g=null},s===void 0&&i.setContentType(null),"setRequestHeader"in g&&R.forEach(i.toJSON(),function(N,T){g.setRequestHeader(T,N)}),R.isUndefined(o.withCredentials)||(g.withCredentials=!!o.withCredentials),a&&a!=="json"&&(g.responseType=o.responseType),u&&([h,b]=Ro(u,!0),g.addEventListener("progress",h)),l&&g.upload&&([f,p]=Ro(l),g.upload.addEventListener("progress",f),g.upload.addEventListener("loadend",p)),(o.cancelToken||o.signal)&&(d=S=>{g&&(r(!S||S.type?new Tr(null,e,g):S),g.abort(),g=null)},o.cancelToken&&o.cancelToken.subscribe(d),o.signal&&(o.signal.aborted?d():o.signal.addEventListener("abort",d)));const w=bg(o.url);if(w&&Et.protocols.indexOf(w)===-1){r(new De("Unsupported protocol "+w+":",De.ERR_BAD_REQUEST,e));return}g.send(s||null)})},Eg=(e,t)=>{const{length:n}=e=e?e.filter(Boolean):[];if(t||n){let r=new AbortController,o;const s=function(u){if(!o){o=!0,a();const d=u instanceof Error?u:this.reason;r.abort(d instanceof De?d:new Tr(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(u=>{u.unsubscribe?u.unsubscribe(s):u.removeEventListener("abort",s)}),e=null)};e.forEach(u=>u.addEventListener("abort",s));const{signal:l}=r;return l.unsubscribe=()=>R.asap(a),l}},Ng=function*(e,t){let n=e.byteLength;if(n<t){yield e;return}let r=0,o;for(;r<n;)o=r+t,yield e.slice(r,o),r=o},Ag=async function*(e,t){for await(const n of _g(e))yield*Ng(n,t)},_g=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()}},Vl=(e,t,n,r)=>{const o=Ag(e,t);let s=0,i,a=l=>{i||(i=!0,r&&r(l))};return new ReadableStream({async pull(l){try{const{done:u,value:d}=await o.next();if(u){a(),l.close();return}let f=d.byteLength;if(n){let h=s+=f;n(h)}l.enqueue(new Uint8Array(d))}catch(u){throw a(u),u}},cancel(l){return a(l),o.return()}},{highWaterMark:2})},Kl=64*1024,{isFunction:Po}=R,jg=(({Request:e,Response:t})=>({Request:e,Response:t}))(R.global),{ReadableStream:ql,TextEncoder:Gl}=R.global,Yl=(e,...t)=>{try{return!!e(...t)}catch{return!1}},Rg=e=>{e=R.merge.call({skipUndefined:!0},jg,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(ql),l=o&&(typeof Gl=="function"?(b=>x=>b.encode(x))(new Gl):async b=>new Uint8Array(await new n(b).arrayBuffer())),u=s&&a&&Yl(()=>{let b=!1;const x=new n(Et.origin,{body:new ql,method:"POST",get duplex(){return b=!0,"half"}}).headers.has("Content-Type");return b&&!x}),d=i&&a&&Yl(()=>R.isReadableStream(new r("").body)),f={stream:d&&(b=>b.body)};o&&["text","arrayBuffer","blob","formData","stream"].forEach(b=>{!f[b]&&(f[b]=(x,g)=>{let v=x&&x[b];if(v)return v.call(x);throw new De(`Response type '${b}' is not supported`,De.ERR_NOT_SUPPORT,g)})});const h=async b=>{if(b==null)return 0;if(R.isBlob(b))return b.size;if(R.isSpecCompliantForm(b))return(await new n(Et.origin,{method:"POST",body:b}).arrayBuffer()).byteLength;if(R.isArrayBufferView(b)||R.isArrayBuffer(b))return b.byteLength;if(R.isURLSearchParams(b)&&(b=b+""),R.isString(b))return(await l(b)).byteLength},p=async(b,x)=>{const g=R.toFiniteNumber(b.getContentLength());return g??h(x)};return async b=>{let{url:x,method:g,data:v,signal:w,cancelToken:S,timeout:N,onDownloadProgress:T,onUploadProgress:k,responseType:E,headers:A,withCredentials:j="same-origin",fetchOptions:P}=Wl(b),L=t||fetch;E=E?(E+"").toLowerCase():"text";let $=Eg([w,S&&S.toAbortSignal()],N),V=null;const M=$&&$.unsubscribe&&(()=>{$.unsubscribe()});let G;try{if(k&&u&&g!=="get"&&g!=="head"&&(G=await p(A,v))!==0){let D=new n(x,{method:"POST",body:v,duplex:"half"}),ee;if(R.isFormData(v)&&(ee=D.headers.get("content-type"))&&A.setContentType(ee),D.body){const[fe,we]=Bl(G,Ro(zl(k)));v=Vl(D.body,Kl,fe,we)}}R.isString(j)||(j=j?"include":"omit");const K=s&&"credentials"in n.prototype,W={...P,signal:$,method:g.toUpperCase(),headers:A.normalize().toJSON(),body:v,duplex:"half",credentials:K?j:void 0};V=s&&new n(x,W);let B=await(s?L(V,P):L(x,W));const F=d&&(E==="stream"||E==="response");if(d&&(T||F&&M)){const D={};["status","statusText","headers"].forEach(ye=>{D[ye]=B[ye]});const ee=R.toFiniteNumber(B.headers.get("content-length")),[fe,we]=T&&Bl(ee,Ro(zl(T),!0))||[];B=new r(Vl(B.body,Kl,fe,()=>{we&&we(),M&&M()}),D)}E=E||"text";let ue=await f[R.findKey(f,E)||"text"](B,b);return!F&&M&&M(),await new Promise((D,ee)=>{Fl(D,ee,{data:ue,headers:$t.from(B.headers),status:B.status,statusText:B.statusText,config:b,request:V})})}catch(K){throw M&&M(),K&&K.name==="TypeError"&&/Load failed|fetch/i.test(K.message)?Object.assign(new De("Network Error",De.ERR_NETWORK,b,V),{cause:K.cause||K}):De.from(K,K&&K.code,b,V)}}},Pg=new Map,Xl=e=>{let t=e?e.env:{};const{fetch:n,Request:r,Response:o}=t,s=[r,o,n];let i=s.length,a=i,l,u,d=Pg;for(;a--;)l=s[a],u=d.get(l),u===void 0&&d.set(l,u=a?new Map:Rg(t)),d=u;return u};Xl();const gi={http:tg,xhr:Ig,fetch:{get:Xl}};R.forEach(gi,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const Jl=e=>`- ${e}`,Og=e=>R.isFunction(e)||e===null||e===!1,Zl={getAdapter:(e,t)=>{e=R.isArray(e)?e:[e];const{length:n}=e;let r,o;const s={};for(let i=0;i<n;i++){r=e[i];let a;if(o=r,!Og(r)&&(o=gi[(a=String(r)).toLowerCase()],o===void 0))throw new De(`Unknown adapter '${a}'`);if(o&&(R.isFunction(o)||(o=o.get(t))))break;s[a||"#"+i]=o}if(!o){const i=Object.entries(s).map(([l,u])=>`adapter ${l} `+(u===!1?"is not supported by the environment":"is not available in the build"));let a=n?i.length>1?`since :
|
|
33
|
+
`+i.map(Jl).join(`
|
|
34
|
+
`):" "+Jl(i[0]):"as no adapter specified";throw new De("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 Tr(null,e)}function Ql(e){return xi(e),e.headers=$t.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),Zl.getAdapter(e.adapter||qr.adapter,e)(e).then(function(r){return xi(e),r.data=mi.call(e,e.transformResponse,r),r.headers=$t.from(r.headers),r},function(r){return $l(r)||(xi(e),r&&r.response&&(r.response.data=mi.call(e,e.transformResponse,r.response),r.response.headers=$t.from(r.response.headers))),Promise.reject(r)})}const ec="1.12.2",Oo={};["object","boolean","number","function","string","symbol"].forEach((e,t)=>{Oo[e]=function(r){return typeof r===e||"a"+(t<1?"n ":" ")+e}});const tc={};Oo.transitional=function(t,n,r){function o(s,i){return"[Axios v"+ec+"] Transitional option '"+s+"'"+i+(r?". "+r:"")}return(s,i,a)=>{if(t===!1)throw new De(o(i," has been removed"+(n?" in "+n:"")),De.ERR_DEPRECATED);return n&&!tc[i]&&(tc[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}},Oo.spelling=function(t){return(n,r)=>(console.warn(`${r} is likely a misspelling of ${t}`),!0)};function Mg(e,t,n){if(typeof e!="object")throw new De("options must be an object",De.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 De("option "+s+" must be "+l,De.ERR_BAD_OPTION_VALUE);continue}if(n!==!0)throw new De("Unknown option "+s,De.ERR_BAD_OPTION)}}const Mo={assertOptions:Mg,validators:Oo},gn=Mo.validators;let er=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=Qn(this.defaults,n);const{transitional:r,paramsSerializer:o,headers:s}=n;r!==void 0&&Mo.assertOptions(r,{silentJSONParsing:gn.transitional(gn.boolean),forcedJSONParsing:gn.transitional(gn.boolean),clarifyTimeoutError:gn.transitional(gn.boolean)},!1),o!=null&&(R.isFunction(o)?n.paramsSerializer={serialize:o}:Mo.assertOptions(o,{encode:gn.function,serialize:gn.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),Mo.assertOptions(n,{baseUrl:gn.spelling("baseURL"),withXsrfToken:gn.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let i=s&&R.merge(s.common,s[n.method]);s&&R.forEach(["delete","get","head","post","put","patch","common"],b=>{delete s[b]}),n.headers=$t.concat(i,s);const a=[];let l=!0;this.interceptors.request.forEach(function(x){typeof x.runWhen=="function"&&x.runWhen(n)===!1||(l=l&&x.synchronous,a.unshift(x.fulfilled,x.rejected))});const u=[];this.interceptors.response.forEach(function(x){u.push(x.fulfilled,x.rejected)});let d,f=0,h;if(!l){const b=[Ql.bind(this),void 0];for(b.unshift(...a),b.push(...u),h=b.length,d=Promise.resolve(n);f<h;)d=d.then(b[f++],b[f++]);return d}h=a.length;let p=n;for(;f<h;){const b=a[f++],x=a[f++];try{p=b(p)}catch(g){x.call(this,g);break}}try{d=Ql.call(this,p)}catch(b){return Promise.reject(b)}for(f=0,h=u.length;f<h;)d=d.then(u[f++],u[f++]);return d}getUri(t){t=Qn(this.defaults,t);const n=Hl(t.baseURL,t.url,t.allowAbsoluteUrls);return Pl(n,t.params,t.paramsSerializer)}};R.forEach(["delete","get","head","options"],function(t){er.prototype[t]=function(n,r){return this.request(Qn(r||{},{method:t,url:n,data:(r||{}).data}))}}),R.forEach(["post","put","patch"],function(t){function n(r){return function(s,i,a){return this.request(Qn(a||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:s,data:i}))}}er.prototype[t]=n(),er.prototype[t+"Form"]=n(!0)});let Dg=class fm{constructor(t){if(typeof t!="function")throw new TypeError("executor must be a function.");let n;this.promise=new Promise(function(s){n=s});const r=this;this.promise.then(o=>{if(!r._listeners)return;let s=r._listeners.length;for(;s-- >0;)r._listeners[s](o);r._listeners=null}),this.promise.then=o=>{let s;const i=new Promise(a=>{r.subscribe(a),s=a}).then(o);return i.cancel=function(){r.unsubscribe(s)},i},t(function(s,i,a){r.reason||(r.reason=new Tr(s,i,a),n(r.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(t){if(this.reason){t(this.reason);return}this._listeners?this._listeners.push(t):this._listeners=[t]}unsubscribe(t){if(!this._listeners)return;const n=this._listeners.indexOf(t);n!==-1&&this._listeners.splice(n,1)}toAbortSignal(){const t=new AbortController,n=r=>{t.abort(r)};return this.subscribe(n),t.signal.unsubscribe=()=>this.unsubscribe(n),t.signal}static source(){let t;return{token:new fm(function(o){t=o}),cancel:t}}};function Lg(e){return function(n){return e.apply(null,n)}}function $g(e){return R.isObject(e)&&e.isAxiosError===!0}const vi={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(vi).forEach(([e,t])=>{vi[t]=e});function nc(e){const t=new er(e),n=vl(er.prototype.request,t);return R.extend(n,er.prototype,t,{allOwnKeys:!0}),R.extend(n,t,null,{allOwnKeys:!0}),n.create=function(o){return nc(Qn(e,o))},n}const xt=nc(qr);xt.Axios=er,xt.CanceledError=Tr,xt.CancelToken=Dg,xt.isCancel=$l,xt.VERSION=ec,xt.toFormData=_o,xt.AxiosError=De,xt.Cancel=xt.CanceledError,xt.all=function(t){return Promise.all(t)},xt.spread=Lg,xt.isAxiosError=$g,xt.mergeConfig=Qn,xt.AxiosHeaders=$t,xt.formToJSON=e=>Dl(R.isHTMLForm(e)?new FormData(e):e),xt.getAdapter=Zl.getAdapter,xt.HttpStatusCode=vi,xt.default=xt;const{Axios:kT,AxiosError:IT,CanceledError:ET,isCancel:NT,CancelToken:AT,VERSION:_T,all:jT,Cancel:RT,isAxiosError:PT,spread:OT,toFormData:MT,AxiosHeaders:DT,HttpStatusCode:LT,formToJSON:$T,getAdapter:FT,mergeConfig:BT}=xt,rc=typeof window<"u"?window.__API_BASE_URL__:void 0,oc=rc?An(rc):void 0;function An(e){const n=(e!=null&&e.trim()?e.trim():"/api/chat").replace(/\/+$/,"");return n?n.endsWith("/chat")?n:`${n}/chat`:"/api/chat"}let Do=null;const bi=new Set;function sc(){return Do}function wi(e){Do=e,bi.forEach(t=>t(e))}function ic(e){return bi.add(e),()=>bi.delete(e)}const Yt=xt.create({...oc?{baseURL:oc}:{},timeout:3e4,withCredentials:!0});Yt.interceptors.request.use(e=>(Do&&(e.headers.Authorization=`Bearer ${Do}`),e)),Yt.interceptors.response.use(e=>e,e=>Promise.reject(e));async function on(e,t){return Yt.defaults.baseURL?(await Yt.get(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}async function yi(e,t,n){return Yt.defaults.baseURL?(await Yt.post(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function ac(e,t,n){return Yt.defaults.baseURL?(await Yt.put(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function lc(e,t){return Yt.defaults.baseURL?(await Yt.delete(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}function sn(e){return e&&typeof e=="object"&&"data"in e?e.data:e}class cc{get baseUrl(){const t=Yt.defaults.baseURL;return t?An(String(t)):""}updateConfig(t){t.baseUrl&&(Yt.defaults.baseURL=An(String(t.baseUrl))),t.authToken!==void 0&&wi(t.authToken)}getAuthToken(){return sc()}setAuthToken(t){wi(t)}onTokenChange(t){return ic(t)}async listThreads(){const t=await on("/threads"),n=sn(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async createThread(t){const r=await yi("/threads",t?{title:t}:void 0);return sn(r)}async updateThread(t,n){const r=await ac(`/threads/${t}`,{title:n});return sn(r)}async deleteThread(t){const n=await lc(`/threads/${t}`);return sn(n)}async threadInfo(t){const n=await on(`/threads/${t}/info`);return sn(n)}async listAgents(){const t=await on("/agents"),n=sn(t);return(n==null?void 0:n.items)??[]}async getAgent(t){const n=await on(`/agents/${t}`);return sn(n)}async getAgentSchema(t){const n=await on(`/agents/${t}/schema`);return sn(n)}async getMessages(t){const n=await on(`/threads/${t.threadId}/messages`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs,limit:t.limit,before_id:t.beforeId??void 0}});return sn(n)}async getStateHistory(t){const n=await on(`/threads/${t.threadId}/state/history`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return sn(n)}resumeStream(t){}async resume(t){const n=await yi("/runs/resume",{thread_id:t.threadId,value:t.value});return sn(n)}}const Mn=new cc,uc=y.createContext(null);function Fg({children:e,apiConfig:t}){const n=Mn;if(t){const o=n.baseUrl,s=n.getAuthToken();t.baseUrl&&t.baseUrl!==o&&n.updateConfig({baseUrl:t.baseUrl}),t.apiKey!==void 0&&t.apiKey!==s&&n.updateConfig({authToken:t.apiKey})}const r={token:n.getAuthToken(),setToken:o=>n.setAuthToken(o),api:n,baseUrl:n.baseUrl};return c.jsx(uc.Provider,{value:r,children:e})}function Si(){const e=y.useContext(uc);if(!e)throw new Error("useApi must be used within ApiProvider");return e}async function Bg(e){return await new Promise((t,n)=>{const r=new FileReader;r.onload=()=>{try{const o=r.result,s=new Uint8Array(o);let i="";const a=s.byteLength;for(let l=0;l<a;l++)i+=String.fromCharCode(s[l]);t(btoa(i))}catch(o){n(o)}},r.onerror=o=>n(o),r.readAsArrayBuffer(e)})}async function zg(e,t=[],n,r,o,s){const i=[],a=[];for(const l of t)try{const u=await Bg(l);a.push({filename:l.name,data:u,mime_type:l.type||"application/octet-stream"})}catch{}return{contentParts:i,filesInfo:a}}const Hg={human:"user",user:"user",ai:"assistant",assistant:"assistant",tool:"tool",function:"tool",system:"system"};function Ci(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 Lo(e,t){return`${e??""}::${t??""}`}function Ti(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(!Ci(r))return{payload:{threadId:n,checkpointId:void 0,checkpointNs:void 0,messages:[],hasMore:!1,nextCursor:null,nextCursorNs:null},checkpoints:[],interrupt:null,snapshots:{}};const{summaries:o,snapshots:s}=Wg(t),i=dc(r,0);return{payload:{threadId:n,checkpointId:(i==null?void 0:i.checkpointId)??void 0,checkpointNs:(i==null?void 0:i.checkpointNs)??void 0,messages:(i==null?void 0:i.messages)??[],hasMore:!!(i!=null&&i.nextCursor),nextCursor:(i==null?void 0:i.nextCursor)??null,nextCursorNs:(i==null?void 0:i.nextCursorNs)??null,pendingInterrupt:(i==null?void 0:i.interrupt)??null},checkpoints:o,interrupt:(i==null?void 0:i.interrupt)??null,snapshots:s}}function dc(e,t){var h,p;if(!Ci(e))return null;const n=e.values??{},r=Array.isArray(n==null?void 0:n.messages)?n.messages:[],o=e.tasks,s=r.map((b,x)=>Yg(b,x)).filter(b=>!!b),i=zt((h=e.config)==null?void 0:h.configurable),a=pt(i,["checkpoint_id","checkpointId"]),l=pt(i,["checkpoint_ns","checkpointNs"]),u=zt((p=e.parentConfig)==null?void 0:p.configurable),d=pt(u,["checkpoint_id","checkpointId"])??null,f=pt(u,["checkpoint_ns","checkpointNs"])??null;return{messages:s,checkpointId:a??null,checkpointNs:l??null,nextCursor:d,nextCursorNs:f,interrupt:Ug(o,s,t)}}function Ug(e,t,n){const r=qg(e,n);return r||Kg(t,n)}function Wg(e){const t=new Map,n={};e.forEach((o,s)=>{if(!Ci(o))return;const i=dc(o,s);if(!(i!=null&&i.checkpointId))return;const a=o==null?void 0:o.createdAt,l=typeof a=="string"&&a.trim()?a:new Date(Date.now()-s).toISOString(),u=Vg(i.messages),d=i.messages[i.messages.length-1],f=zt(o==null?void 0:o.metadata),h=pt(f,["branch_label","branchLabel"]),p=zt(o==null?void 0:o.parentConfig),b=zt(p==null?void 0:p.configurable),x=pt(b,["checkpoint_id","checkpointId"]),g={checkpointId:i.checkpointId,checkpointNs:i.checkpointNs??"",createdAt:l,messagesLen:i.messages.length,preview:u??null,role:(d==null?void 0:d.role)??null,parentId:x??null,branchLabel:h??null,lastMessageId:(d==null?void 0:d.id)??null,hasMessages:i.messages.length>0},v=Lo(g.checkpointId,g.checkpointNs);t.has(v)||t.set(v,g),n[v]||(n[v]=i)});const r=Array.from(t.values());return r.sort((o,s)=>hc(s.createdAt)-hc(o.createdAt)),{summaries:r,snapshots:n}}function Vg(e){var t;for(let n=e.length-1;n>=0;n--){const r=((t=e[n])==null?void 0:t.content)??[];for(let o=0;o<r.length;o++){const s=r[o];if(s&&s.type==="text"&&typeof s.text=="string"){const i=s.text.trim();if(i)return i}}}return null}function Kg(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 qg(e,t){if(!Array.isArray(e)||!e.length)return null;for(let n=e.length-1;n>=0;n--){const r=Gg(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=Yr(r.interrupts[s],`${o}-interrupt-${s}`);if(i)return i}if(r.state!==void 0&&r.state!==null){const s=Yr(r.state,`${o}-state`);if(s)return s}}return null}function Gg(e,t){if(!e)return null;if(Array.isArray(e)){const[a,l,u,,d,,f,...h]=e,p=typeof a=="string"&&a.trim()?a:t,b=typeof l=="string"&&l.trim()?l:Array.isArray(u)&&typeof u[0]=="string"?String(u[0]):"task",x=Array.isArray(d)?d:void 0,g=h.length?h[h.length-1]:void 0;return{id:p,name:b,interrupts:x,state:g!==void 0?g:f}}const n=zt(e);if(!n)return null;const r=pt(n,["id","task_id","taskId"])??t,o=pt(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 Yr(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=fc(e,t);if(o)return o;if(Array.isArray(e)){for(let s=e.length-1;s>=0;s--){const i=Yr(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=Yr(s[a],t,n+1,r);if(l)return l}for(const[a,l]of Object.entries(s)){if(i.includes(a)||a==="messages"||a==="results")continue;const u=Yr(l,t,n+1,r);if(u)return u}}return null}function fc(e,t){if(!e)return null;if(typeof e=="object"&&!Array.isArray(e)){const n=e,r=pt(n,["type","event","kind"]),o=pt(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=fc(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 hc(e){if(!e)return 0;const t=Date.parse(e);return Number.isFinite(t)?t:0}function Yg(e,t){if(!e||typeof e!="object")return null;const n=e,r=zt(e)??{},o=zt(n.data)??r,s=String(n.type??o.type??o.role??"").toLowerCase(),i=Hg[s];if(!i)return null;const a=o.id??o.message_id??o.run_id??null,l=typeof a=="string"&&a.trim()?a:`history-${i}-${t}`,u=zt(o.additional_kwargs)??zt(o.additionalKwargs),d=zt(o.response_metadata)??zt(o.responseMetadata),f=pt(u,["createdAt","created_at"])??pt(o,["created_at","createdAt"]),h=pt(u,["checkpointId","checkpoint_id"]),p=pt(u,["checkpointNs","checkpoint_ns"]),b=Xg(o.content),x={id:l,role:i,content:b};f&&(x.createdAt=f),typeof o.name=="string"&&o.name.trim()&&(x.name=o.name),typeof(d==null?void 0:d.model_name)=="string"&&(x.model=String(d.model_name)),!x.model&&typeof o.model=="string"&&(x.model=o.model),h&&(x.checkpointId=h),p&&(x.checkpointNs=p);const g=tx(u,["createdAt","created_at","checkpointId","checkpoint_id","checkpointNs","checkpoint_ns","tool_calls"]),v=d?{...d}:void 0;g&&Object.keys(g).length&&(x.additionalKwargs=g),v&&Object.keys(v).length&&(x.responseMetadata=v);const w=Jg((u==null?void 0:u.tool_calls)??o.tool_calls);if(w.length&&(x.content=[...x.content,...w]),i==="tool"){const S=Qg(o,x.content);S&&(x.content=S)}return x}function Xg(e){if(!e)return[];if(Array.isArray(e))return e.map(t=>pc(t)).filter(t=>!!t);if(typeof e=="string")return e.trim()?[{type:"text",text:e.trim()}]:[];if(typeof e=="object"){const t=pc(e);return t?[t]:[]}return[]}function pc(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=pt(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=pt(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 Zg(t)??null;if(n==="tool_end"){const o=pt(t,["tool_call_id","toolCallId","id"]);if(!o)return null;const s={type:"tool_end",toolCallId:o,output:"output"in t?t.output:t.content};return typeof t.error=="string"&&(s.error=t.error),s}if(n==="interrupt")return{type:"interrupt",value:t.value,...t};if(n==="tool"){const o=pt(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 Jg(e){return Array.isArray(e)?e.map((t,n)=>{if(!t||typeof t!="object")return null;const r=t,o=pt(r,["id","call_id"]),s=zt(r.function),i=pt(s,["name"])??"tool",a=s==null?void 0:s.arguments,l=mc(a);return{type:"tool_call",id:o??`tool_call_${n}`,name:i,args:l}}).filter(t=>!!t):[]}function Zg(e){const t=pt(e,["id","call_id"]),n=pt(e,["name"]);if(!t||!n)return null;const r=mc(e.args??e.arguments);return{type:"tool_call",id:t,name:n,args:r}}function Qg(e,t){const n=pt(e,["tool_call_id","toolCallId","id"]);if(!n)return t;const r=e.content??e.output,o=typeof r=="string"?ex(r):r,s={type:"tool_end",toolCallId:n,output:o};return typeof e.error=="string"&&(s.error=e.error),[s]}function mc(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 ex(e){try{return JSON.parse(e)}catch{return e}}function zt(e){if(!(!e||typeof e!="object"||Array.isArray(e)))return{...e}}function pt(e,t){if(e)for(const n of t){const r=e[n];if(typeof r=="string"&&r.trim())return r}}function tx(e,t){if(!e)return;const n={};let r=!1;for(const[o,s]of Object.entries(e)){if(t.includes(o)){r=!0;continue}s!==void 0&&(n[o]=s)}return r?Object.keys(n).length?n:void 0:e}function nx(e){return e.type!=="thread_info"&&e.type!=="token"}const rx={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null,messagesStreamMeta:{},pendingInterrupt:null};function ox(e,t){var n;switch(t.type){case"reset":{console.log("[MessageReducer] 🔄 RESET action received"),console.log("[MessageReducer] 📊 Before reset - messages count:",e.messages.length);const r={messages:ki(((n=t.payload)==null?void 0:n.messages)??[]),assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null,pendingInterrupt:null};return console.log("[MessageReducer] 📊 After reset - messages count:",r.messages.length),r}case"seed":{const r=ki(t.payload.messages),o={...e,messages:r,assemblingId:null,pendingInterrupt:t.payload.pendingInterrupt??null};return Object.prototype.hasOwnProperty.call(t.payload,"checkpointId")&&(o.lastCheckpointId=t.payload.checkpointId??null),Object.prototype.hasOwnProperty.call(t.payload,"checkpointNs")&&(o.lastCheckpointNs=t.payload.checkpointNs??null),console.log("[MessageReducer] seed action (REPLACE mode):",{incomingCount:t.payload.messages.length,sanitizedCount:r.length,previousCount:e.messages.length,checkpointId:o.lastCheckpointId}),o}case"prepend":{const r=ki(t.payload.messages);if(!r.length)return console.log("[MessageReducer] No incoming messages after sanitize - skipping"),e;const o=new Set(e.messages.map(i=>i.id)),s=r.filter(i=>!o.has(i.id));return console.log("[MessageReducer] After dedup:",{uniqueCount:s.length,duplicates:r.length-s.length,finalTotal:s.length+e.messages.length}),s.length?{...e,messages:[...s,...e.messages]}:(console.log("[MessageReducer] All messages were duplicates - skipping"),e)}case"user_message":{const r=t.payload.message;return e.messages.some(o=>o.id===r.id)?e:{...e,messages:[...e.messages,r]}}case"event":return xc(e,t.payload.ev);case"batch":{const{events:r}=t.payload;return r.length?r.reduce((o,s)=>xc(o,s),e):e}case"interrupt_response":{const{interruptId:r}=t.payload,o=e.messages.map(s=>({...s,content:s.content.filter(i=>i.type!=="interrupt")}));return{...e,messages:o,pendingInterrupt:null}}default:return e}}function gc(e=[]){const[t,n]=y.useReducer(ox,{...rx,messages:e}),r=y.useRef([]),o=y.useRef(null),s=y.useRef(null),i=y.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=y.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=y.useCallback(d=>{r.current.push(d),a()},[a]);y.useEffect(()=>()=>{o.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.current),s.current!==null&&clearTimeout(s.current),r.current=[]},[]);const u=y.useMemo(()=>({reset:d=>n({type:"reset",payload:{messages:d}}),seed:(d,f)=>n({type:"seed",payload:{messages:d,...f??{}}}),prepend:d=>n({type:"prepend",payload:{messages:d}}),pushUser:d=>n({type:"user_message",payload:{message:d}}),onEvent:l}),[l]);return{state:t,dispatch:n,...u}}function xc(e,t){var n,r,o,s;if(t.type==="message_start"&&t.role==="assistant"){const i=t.id,a=ax(t.model);if(e.messages.some(d=>d.id===i)){const d=e.messagesStreamMeta??{},f={...d,[i]:d[i]??{lastSeq:t.seq??null,lastText:""}};return{...e,assemblingId:i,messagesStreamMeta:f}}const u={id:i,role:"assistant",name:a||void 0,model:t.model,createdAt:new Date().toISOString(),content:[]};return{...e,assemblingId:i,messages:[...e.messages,u]}}if(t.type==="message_delta"){const i=e.assemblingId??Ii(e.messages);if(!i)return e;const a=e.messages,l=a.findIndex(S=>S.id===i&&S.role==="assistant");if(l===-1)return e;const u=a[l],d=e.messagesStreamMeta??{},f=d[i]??{lastSeq:null,lastText:Sc(u.content)},h=t.seq??null;if(h!==null&&typeof h=="number"&&typeof f.lastSeq=="number"&&h<=f.lastSeq)return console.debug("[MessageReducer] skipping delta - seq <= lastSeq",{seq:h,lastSeq:f.lastSeq}),e;const{newParts:p,newMeta:b,changed:x}=sx(u.content,t.delta,f,h);if(!x)return e;const g={...u,content:p},v=vc(a,l,g),w={...d,[i]:b};return{...e,messages:v,messagesStreamMeta:w}}if(t.type==="message_end"){const i=e.assemblingId??Ii(e.messages);if(!i)return{...e,assemblingId:null};const a=e.messages,l=a.findIndex(u=>u.id===i&&u.role==="assistant");if(l>=0){const u=a[l];if(!((n=u.content)==null?void 0:n.some(f=>{var h;return(f==null?void 0:f.type)==="text"&&((h=f.text)==null?void 0:h.trim())}))){console.debug("[MessageReducer] pruning assistant message with no visible text",{id:u.id,contentTypes:(r=u.content)==null?void 0:r.map(h=>h==null?void 0:h.type),contentPreview:(o=u.content)==null?void 0:o.map(h=>(h==null?void 0:h.type)==="text"?String(h.text).slice(0,100):h==null?void 0:h.type)});const f=[...a.slice(0,l),...a.slice(l+1)];return{...e,assemblingId:null,messages:f}}}return e}if(t.type==="tool_start"){const i=t.id??t.call_id,a=t.name??t.tool??"tool";if(!i)return e;const l=`tool-${i}`,u={type:"tool_call",id:i,name:a,args:t.args};if(e.messages.find(h=>h.id===l))return{...e,toolIndex:{...e.toolIndex,[i]:l}};const f={id:l,role:"tool",name:a,createdAt:new Date().toISOString(),content:[u]};return{...e,messages:[...e.messages,f],toolIndex:{...e.toolIndex,[i]:l}}}if(t.type==="tool_end"){const i=t.id??t.call_id;if(!i)return e;const a=e.toolIndex[i]??`tool-${i}`,l={type:"tool_end",toolCallId:i,output:t.output,error:t.error},u=e.messages.find(h=>h.id===a),d={id:a,role:"tool",name:t.name??((s=e.messages.find(h=>h.id===a))==null?void 0:s.name),content:[l],createdAt:new Date().toISOString()},f=u?wc(e.messages,a,[l]):[...e.messages,d];return{...e,messages:f,toolIndex:{...e.toolIndex,[i]:a}}}if(t.type==="checkpoint"){const i=t.checkpointNs??e.lastCheckpointNs??null,a=ix(e.messages,t.checkpointId,i);return{...e,lastCheckpointId:t.checkpointId,lastCheckpointNs:i,messages:a}}if(t.type==="branch"){const i=t.checkpointId??e.lastCheckpointId,a=t.checkpointNs??e.lastCheckpointNs;return{...e,lastBranch:t,lastCheckpointId:i??null,lastCheckpointNs:a??null}}if(t.type==="error"){const i={id:`err-${Date.now()}`,role:"system",content:[{type:"text",text:`Error: ${t.message}`}],createdAt:new Date().toISOString()};return{...e,messages:[...e.messages,i]}}if(t.type==="interrupt"){const i=e.assemblingId??Ii(e.messages),a={type:"interrupt",value:t.value,id:t.id};if(i)return{...e,assemblingId:null,messages:wc(e.messages,i,[a]),pendingInterrupt:{id:t.id,value:t.value}};const l=`interrupt-${t.id}`;if(e.messages.findIndex(f=>f.id===l)!==-1)return{...e,assemblingId:null,messages:bc(e.messages,l,f=>({...f,content:yc(f.content??[],[a])})),pendingInterrupt:{id:t.id,value:t.value}};const d={id:l,role:"system",createdAt:new Date().toISOString(),content:[a]};return{...e,messages:[...e.messages,d],pendingInterrupt:{id:t.id,value:t.value}}}return e}function ki(e){return e.filter(t=>{if(t.role!=="assistant")return!0;const n=(t.content||[]).some(o=>{var s;return o&&o.type==="text"&&((s=o.text)==null?void 0:s.trim())}),r=(t.content||[]).some(o=>o&&o.type==="image_url");return!!(n||r)})}function vc(e,t,n){return t<0||t>=e.length?e:[...e.slice(0,t),n,...e.slice(t+1)]}function Ii(e){for(let t=e.length-1;t>=0;t--)if(e[t].role==="assistant")return e[t].id;return null}function bc(e,t,n){const r=e.findIndex(i=>i.id===t);if(r===-1)return e;const o=e[r],s=n(o);return s===o?e:[...e.slice(0,r),s,...e.slice(r+1)]}function wc(e,t,n){return bc(e,t,r=>({...r,content:yc(r.content,n)}))}function yc(e,t){const n=e.slice();for(const r of t)if(r.type==="text"){const o=n[n.length-1],s=r.text??"";if(!s)continue;if((o==null?void 0:o.type)==="text"){let i=function(p){return p.replace(/\s+/g," ").trim()};const a=o,l=a.text??"";if(console.debug("[MessageReducer] mergeParts",{incomingLength:s.length,previousLength:l.length,incomingSnippet:s.slice(0,100),previousSnippet:l.slice(-100)}),!l){a.text=s;continue}const u=i(s),d=i(l);if(u.startsWith(d)||s.startsWith(l)){console.debug("[MessageReducer] incoming startsWith previous (norm/raw) - replacing",{incomingLength:s.length,previousLength:l.length}),a.text=s;continue}if(u.includes(d)){console.debug("[MessageReducer] incoming includes previous (normalized) - replacing",{incomingLength:s.length,previousLength:l.length}),a.text=s;continue}if(d.includes(u)&&u.length<=3){console.debug("[MessageReducer] previous includes incoming (normalized) - skipping trivial incoming",{incomingLength:s.length,previousLength:l.length});continue}const h=Tc(l,s);h?(console.debug("[MessageReducer] suffix computed",{suffixLength:h.length}),a.text=l+h):(console.debug("[MessageReducer] no overlap detected - appending incoming",{incomingLength:s.length}),a.text=l+s)}else n.push({type:"text",text:s})}else n.push(r);return n}function Sc(e){return!e||!e.length?"":e.filter(t=>t.type==="text").map(t=>t.text??"").join("")}function sx(e,t,n,r){const o={...n};if(r!==null&&typeof r=="number"){if(typeof o.lastSeq=="number"&&r<=o.lastSeq)return{newParts:e,newMeta:o,changed:!1};o.lastSeq=r}const s=t.filter(f=>f.type==="text").map(f=>f.text??"").join(""),i=t.filter(f=>f.type!=="text"),a=o.lastText??Sc(e);let l="",u=e.slice();if(s){const f=Tc(a,s);if(f===""?l="":f===s?l=s:l=f,l){const h=u[u.length-1];if((h==null?void 0:h.type)==="text"){const p=h.text??"",b={...h,text:p+l};u=[...u.slice(0,u.length-1),b]}else u=[...u,{type:"text",text:l}];o.lastText=a+l}else o.lastText=a}i.length&&(u=[...u,...i]);const d=!!(l||i.length);return{newParts:u,newMeta:o,changed:d}}function Cc(e){return e.replace(/\s+/g," ").trim()}function Tc(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=Cc(e),o=Cc(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 ix(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 vc(e,r,s)}return e}function ax(e){if(!e)return null;const t=e.split("/");return t[t.length-1]||null}function kc(e={}){const t=y.useMemo(()=>An(e.baseUrl),[e.baseUrl]),n=e.streamPath??"/runs/stream",[r,o]=y.useState(e.token??null),s=y.useRef(e.headers??{}),i=e.credentials??"include",[a,l]=y.useState(!1),[u,d]=y.useState(null),[f,h]=y.useState(""),[p,b]=y.useState(null),[x,g]=y.useState(0),[v,w]=y.useState(!1),S=y.useRef(null),N=y.useRef(!0),T=y.useRef(0),k=y.useCallback(P=>{o(P)},[]),E=y.useCallback(()=>{var P;(P=S.current)==null||P.abort(),S.current=null,l(!1),w(!1),T.current=0,g(0)},[]),A=y.useCallback(()=>{h(""),b(null),d(null)},[]),j=y.useCallback((P,L,$)=>{S.current&&(S.current.abort(),S.current=null),l(!0),d(null),e.autoAppendAssistant!==!1&&h("");const V=new AbortController;return S.current=V,(async()=>{var G,K,W,B,F,ue,D,ee;const M=fe=>{var we;try{const ye=JSON.parse(JSON.stringify(fe));return(we=ye==null?void 0:ye.payload)!=null&&we.files_info&&Array.isArray(ye.payload.files_info)&&(ye.payload.files_info=ye.payload.files_info.map(Ce=>({...Ce,data:Ce!=null&&Ce.data?`<base64 ${String(Ce.data).length} chars>`:Ce==null?void 0:Ce.data}))),ye}catch{return fe}};try{let fe={};try{if(r)fe={Authorization:`Bearer ${r}`};else if(typeof window<"u"){const He=window.__AUTH_TOKEN__,ut=((G=window.localStorage)==null?void 0:G.getItem("authToken"))||null;let rt=null;try{const bt=(K=window.localStorage)==null?void 0:K.getItem("chat-settings");bt&&(rt=((W=JSON.parse(bt))==null?void 0:W.apiKey)||null)}catch{}const Ue=He||ut||rt||null;Ue&&(fe={Authorization:`Bearer ${Ue}`})}}catch{}console.debug("[use-chat] POST",t+n,M(P));const we=await fetch(t+n,{method:"POST",headers:{"Content-Type":"application/json",Accept:"text/event-stream",...fe,...s.current},body:JSON.stringify(P),signal:V.signal,credentials:i});if(!we.ok||!we.body){const Pe=await we.text().catch(()=>"");throw console.debug("[use-chat] non-OK response",we.status,Pe==null?void 0:Pe.slice(0,500)),new Error(`stream ${we.status}${Pe?": "+Pe:""}`)}w(!0);const ye=we.body.getReader(),Ce=new TextDecoder;let q="",O=[];T.current=0,g(0);let X=0,te=null;const he=()=>{if(O.length){const Pe=O.join("");O=[],N.current&&h(He=>He+Pe)}te=null},re=()=>{typeof window<"u"&&te==null&&(te=requestAnimationFrame(he))};let pe=Date.now();const tt=setInterval(()=>{var Pe;if(Date.now()-pe>6e4){const He="Stream idle timeout";d(He),V.abort(),(Pe=$==null?void 0:$.onError)==null||Pe.call($,He)}},5e3),nt=1024*1024;try{const Pe=we.headers.get("X-Thread-Id")||we.headers.get("x-thread-id"),He=we.headers.get("X-Thread-Created")||we.headers.get("x-thread-created"),ut=Pe??null,rt=String(He??"").toLowerCase()==="true";for((B=$==null?void 0:$.onOpen)==null||B.call($,{threadId:ut,created:rt});;){const{value:Ue,done:bt}=await ye.read();if(bt)break;q+=Ce.decode(Ue,{stream:!0}),q.length>nt&&(q="",console.warn("Stream buffer reset: exceeded 1MB"));let Z;for(;(Z=q.indexOf(`
|
|
36
36
|
|
|
37
|
-
`))>=0;){const
|
|
38
|
-
`)}function nx({baseUrl:e,onThreadInfo:t,onMessageEvent:n,onUnhandledEvent:r,onSequenceGap:o}){const s=y.useRef(null),i=y.useCallback(p=>{const w=p.seq??null;if(w!==null){const x=s.current;if(x!==null){if(w<=x)return;w>x+1&&(o==null||o({from:x,to:w}))}s.current=w}if(p.type==="thread_info"){console.log("[useChatStreamingService] 🎯 Received thread_info event:",p),t(p);return}if(Gg(p)){n(p);return}r==null||r(p)},[n,o,t,r]),{stream:a,stop:l,isStreaming:u,error:d,setToken:f}=bc({baseUrl:e,token:null}),h=y.useCallback((p,w)=>{s.current=null,a(p,i,{onOpen:w==null?void 0:w.onOpen,onError:x=>{var g;(g=w==null?void 0:w.onError)==null||g.call(w,x)},onGap:(w==null?void 0:w.onGap)??o})},[i,o,a]);return y.useMemo(()=>({startStream:h,stop:l,isStreaming:u,error:d,setAuthToken:f}),[h,l,u,d,f])}const yc=y.createContext(null),Sc=y.createContext(null),Cc=y.createContext(null),rx=y.createContext(!1),ox="cachedThreads",sx="v1",Po=300,Si=200;function ix(e,t){if(!e&&!t)return!0;if(!e||!t||e.id!==t.id)return!1;try{return JSON.stringify(e.value)===JSON.stringify(t.value)}catch{return e.value===t.value}}function ax(e){var t;for(let n=e.length-1;n>=0;n--){const r=((t=e[n])==null?void 0:t.content)??[];for(let o=r.length-1;o>=0;o--){const s=r[o];if((s==null?void 0:s.type)==="interrupt"){const i=s.id;return{id:(typeof i=="string"?i:null)??`interrupt-${e[n].id??o}`,value:s.value}}}}return null}function Tc(e){if(typeof window<"u"&&"requestIdleCallback"in window)try{window.requestIdleCallback(e,{timeout:1e3});return}catch{}window.setTimeout(e,Po)}function br(){return typeof window<"u"&&typeof window.localStorage<"u"}function Ci(e){if(!br())return null;try{return window.localStorage.getItem(e)}catch{return null}}function kc(e,t){if(br())try{window.localStorage.setItem(e,t)}catch{}}function Ti(e){if(br())try{window.localStorage.removeItem(e)}catch{}}function lx(){const e=Ci(ox);if(!e)return[];try{const t=JSON.parse(e);return Array.isArray(t)?t.filter(n=>{if(!n||typeof n!="object")return!1;const r=n;return typeof r.threadId=="string"&&typeof r.title=="string"}):[]}catch{return[]}}function cx(e){let t=5381;for(let n=0;n<e.length;n++)t=(t<<5)+t^e.charCodeAt(n);return(t>>>0).toString(36)}function ki(e,t){return`cachedThreads:v1:${e}:${cx(t||"anon")}`}function ux(e){const t=Ci(e);if(!t)return[];try{const n=JSON.parse(t);return Array.isArray(n)?n.filter(r=>{if(!r||typeof r!="object")return!1;const o=r;return typeof o.threadId=="string"&&typeof o.title=="string"}):[]}catch{return[]}}function Ei(e,t){try{kc(e,JSON.stringify(t))}catch{}}function Ii(e){const t=ux(e);if(t.length>0)return t;const n=lx();if(n.length>0)try{Ei(e,n.slice(0,Si))}catch{}return n}function Oo(e){const t={},n=[];for(const r of e)!r||typeof r.threadId!="string"||t[r.threadId]||(t[r.threadId]=r,n.push(r.threadId));return{byId:t,order:n}}function Ni(e){return e.order.map(t=>e.byId[t]).filter(Boolean)}function dx({children:e,initialThreadId:t=null,autoLoadInitial:n=!0,disableAutoRestore:r=!1,enableFileAgentRouting:o=!1,fileAgentId:s="invoice_reader",onError:i,onThreadChange:a}){const{api:l,baseUrl:u}=xi(),d=y.useMemo(()=>En(u),[u]),f=y.useMemo(()=>{try{return new URL(u).host}catch{return"unknown"}},[u]),h=y.useMemo(()=>`threadPayload:${sx}:${f}:`,[f]),p=y.useCallback(T=>`${h}${T}`,[h]),w=y.useCallback(T=>{if(!T||typeof T!="object")return null;const _=T;return typeof _.threadId!="string"||!Array.isArray(_.messages)?null:{threadId:_.threadId,messages:_.messages,hasMore:!!_.hasMore,nextCursor:_.nextCursor??null,checkpointId:_.checkpointId??null,checkpointNs:_.checkpointNs??null,nextCursorNs:_.nextCursorNs??null}},[]),x=y.useCallback(T=>{const _=Ci(p(T));if(!_)return null;try{const W=JSON.parse(_);return w(W)}catch{return null}},[p,w]),g=y.useCallback((T,_=100)=>{const W={...T,messages:Array.isArray(T.messages)?T.messages.slice(-_):[]};try{kc(p(T.threadId),JSON.stringify(W))}catch{}},[p]),v=y.useCallback(T=>{Ti(p(T))},[p]),b=y.useCallback(()=>{if(br())try{const T=h;for(let _=0;_<window.localStorage.length;_++){const W=window.localStorage.key(_);W&&W.startsWith(T)&&window.localStorage.removeItem(W)}}catch{}},[h]),[S,N]=y.useState(()=>{var T;return ki(f,(T=l.getAuthToken)==null?void 0:T.call(l))}),[C,k]=y.useState(()=>{var _;const T=Ii(ki(f,(_=l.getAuthToken)==null?void 0:_.call(l)));return Oo(T)}),I=y.useMemo(()=>Ni(C),[C]),[A,j]=y.useState(t),[P,L]=y.useState(!1),[F,V]=y.useState(!1),[M,G]=y.useState(null),[q,U]=y.useState(null),[B,$]=y.useState(null),ce=y.useCallback(()=>{const T=Ii(S);y.startTransition(()=>{k(Oo(T))})},[S]),[D,Q]=y.useState(!1),[de,we]=y.useState(!1),[ye,Se]=y.useState(null),[K,O]=y.useState(void 0),[X,ee]=y.useState(void 0),[fe,ne]=y.useState(void 0),{state:pe,dispatch:Ze,seed:Qe,prepend:Pe,pushUser:He,onEvent:ct,reset:tt}=dc(),Be=y.useRef(A);y.useEffect(()=>{Be.current=A},[A]);const gt=y.useRef(!1),J=y.useRef([]),re=y.useRef(null),he=y.useRef(null),Ce=y.useRef(new Map),me=y.useRef(A),Oe=y.useRef(!1),it=y.useRef(null),Me=y.useRef(new Map),et=y.useCallback((T,_,W)=>{if(!T)return;const xe=W==="replace"?[]:Me.current.get(T)??[],ie=W==="replace"?_:[..._,...xe];if(!ie.length){W==="replace"&&Me.current.set(T,[]);return}const Ie=new Map;for(const st of ie){if(!(st!=null&&st.checkpointId))continue;const Xe=`${st.checkpointId}::${st.checkpointNs??""}`;Ie.has(Xe)||Ie.set(Xe,st)}const ge=Array.from(Ie.values()).sort((st,Xe)=>{const ut=Number.isFinite(Date.parse(st.createdAt))?Date.parse(st.createdAt):0;return(Number.isFinite(Date.parse(Xe.createdAt))?Date.parse(Xe.createdAt):0)-ut});Me.current.set(T,ge)},[]),vt=y.useCallback((T,_)=>new Promise((W,xe)=>{const ie=async()=>{gt.current=!0;try{await T(),W()}catch(Ie){xe(Ie)}finally{gt.current=!1;const Ie=J.current.shift();Ie&&Ie().catch(()=>{})}};gt.current?J.current.push(ie):ie().catch(Ie=>{xe(Ie)})}),[]),Zt=y.useRef(I.length),[qn,Mr]=y.useState(!1),mr=y.useRef(!1);y.useEffect(()=>{Zt.current=I.length},[I.length]),y.useEffect(()=>{const T=pe.pendingInterrupt??ax(pe.messages);ix(B,T)||$(T??null)},[B,pe.messages,pe.pendingInterrupt]);const Rt=y.useCallback(async()=>{const T=Zt.current>0;T||L(!0);try{const _=await l.listThreads();y.startTransition(()=>{k(W=>{const xe=ge=>ge.map(st=>`${st.threadId}:${st.updatedAt??""}:${st.messageCount??""}`).join("|"),ie=Ni(W);return xe(ie)===xe(_)||_.length===0&&ie.length>0&&!mr.current?W:Oo(_)})}),G(null),mr.current||(mr.current=!0,Mr(!0))}catch(_){i==null||i(String(_)),console.error("[ChatSessionProvider] Failed to refresh threads:",_),G(String(_))}finally{T||L(!1)}},[l,i]),wo=y.useRef(!1),_n=y.useRef(null),St=y.useRef(null),At=y.useRef(""),Ut=y.useCallback((T,_)=>{if(!br())return;St.current!==null&&(window.clearTimeout(St.current),St.current=null);const W=T.map(ie=>`${ie.threadId}:${ie.updatedAt??""}:${ie.messageCount??""}`).join("|");if(T.length===0){try{Ti(S)}catch{}At.current="";return}if(W===At.current)return;const xe=()=>{try{const ie=T.slice(0,Si);Ei(S,ie),At.current=W}catch{}finally{St.current=null}};if(_!=null&&_.immediate){xe();return}St.current=window.setTimeout(()=>{Tc(xe)},Po)},[S]),Kn=y.useCallback(()=>{Ut(I,{immediate:!0})},[Ut,I]),dn=y.useCallback((T,_,W)=>{const xe=Array.isArray(T==null?void 0:T.messages)?T.messages:[],ie=W??(T==null?void 0:T.threadId)??Be.current,Ie=ie!=null&&ie===Be.current;if(_==="replace"){if(ie){const ge={threadId:ie,messages:xe.slice(),hasMore:!!(T!=null&&T.hasMore),nextCursor:(T==null?void 0:T.nextCursor)??null,checkpointId:(T==null?void 0:T.checkpointId)??null,checkpointNs:(T==null?void 0:T.checkpointNs)??null,nextCursorNs:(T==null?void 0:T.nextCursorNs)??null};Ce.current.set(ie,ge),me.current=ie}if(!Ie)return;Qe(xe,{checkpointId:(T==null?void 0:T.checkpointId)??null,checkpointNs:(T==null?void 0:T.checkpointNs)??null})}else if(_==="prepend"&&xe.length&&ie){const ge=Ce.current.get(ie),st=(ge==null?void 0:ge.messages)??[],Xe=new Set,ut=[...xe,...st].filter(Qt=>{const en=Qt==null?void 0:Qt.id;return en?Xe.has(en)?!1:(Xe.add(en),!0):!0}),Wt={threadId:ie,messages:ut,hasMore:(T==null?void 0:T.hasMore)??(ge==null?void 0:ge.hasMore)??!1,nextCursor:(T==null?void 0:T.nextCursor)??(ge==null?void 0:ge.nextCursor)??null,checkpointId:(ge==null?void 0:ge.checkpointId)??(T==null?void 0:T.checkpointId)??null,checkpointNs:(ge==null?void 0:ge.checkpointNs)??(T==null?void 0:T.checkpointNs)??null,nextCursorNs:(T==null?void 0:T.nextCursorNs)??(ge==null?void 0:ge.nextCursorNs)??null};if(Ce.current.set(ie,Wt),!Ie)return;Pe(xe)}else _==="prepend"&&xe.length&&Pe(xe);Ie&&(_==="replace"?(Se((T==null?void 0:T.nextCursor)??null),Q(!!(T!=null&&T.hasMore)),O((T==null?void 0:T.checkpointId)??void 0),ee((T==null?void 0:T.checkpointNs)??void 0),ne((T==null?void 0:T.nextCursorNs)??void 0)):(Se(ge=>(T==null?void 0:T.nextCursor)??ge??null),Q(ge=>(T==null?void 0:T.hasMore)!==void 0?!!(T!=null&&T.hasMore):ge),O(ge=>(T==null?void 0:T.checkpointId)??ge??void 0),ee(ge=>(T==null?void 0:T.checkpointNs)??ge??void 0),ne(ge=>(T==null?void 0:T.nextCursorNs)!==void 0?T.nextCursorNs??void 0:ge)))},[Pe,Qe]),gr=y.useCallback(T=>{T.threadId!=null&&T.threadId!==Be.current||(Qe(T.messages,{checkpointId:T.checkpointId,checkpointNs:T.checkpointNs}),Se(T.nextCursor),Q(T.hasMore),O(T.checkpointId??void 0),ee(T.checkpointNs??void 0),ne(T.nextCursorNs??void 0),me.current=T.threadId)},[Qe]),fn=y.useCallback(T=>{T&&(Ce.current.delete(T),v(T),Me.current.delete(T),me.current===T&&(me.current=null))},[v]),kn=y.useCallback(()=>{const T=Be.current;T&&fn(T),tt([]),Q(!1),we(!1),Se(null),O(void 0),ee(void 0),ne(void 0)},[fn,tt]),Gn=y.useCallback(({from:T,to:_})=>{const W=Be.current;W&&console.warn(`[ChatSessionProvider] Stream sequence gap detected (${T} -> ${_}) for thread ${W}`)},[]),Dr=y.useCallback(T=>{const _=T.threadId;console.log("[ChatSessionProvider] 📥 Handling thread_info event:",{threadId:_,title:T.title,created:T.created,currentThreads:I.length});const W={threadId:_,title:T.title||`Thread ${_.slice(0,8)}`,createdAt:T.createdAt||new Date().toISOString(),updatedAt:T.updatedAt||new Date().toISOString(),messageCount:T.messageCount||0};Be.current!==_&&(!Be.current&&pe.messages.length<=1&&(he.current=_),j(_)),y.startTransition(()=>{k(xe=>{const ie=xe.byId[_];return ie?ie.title===W.title&&ie.updatedAt===W.updatedAt&&ie.messageCount===W.messageCount?xe:{byId:{...xe.byId,[_]:W},order:xe.order}:{byId:{...xe.byId,[_]:W},order:[_,...xe.order]}})})},[pe.messages.length]),{startStream:Lr,stop:Fr,isStreaming:jn,error:se,setAuthToken:be}=nx({baseUrl:d,onThreadInfo:Dr,onMessageEvent:ct,onUnhandledEvent:T=>{console.warn(`[ChatSessionProvider] Unhandled stream event: ${T.type}`,T)},onSequenceGap:Gn});y.useEffect(()=>{wo.current=jn},[jn]),y.useEffect(()=>{if(!br())return;St.current!==null&&(window.clearTimeout(St.current),St.current=null);const T=I.map(W=>`${W.threadId}:${W.updatedAt??""}:${W.messageCount??""}`).join("|");if(I.length===0){try{Ti(S)}catch{}At.current="";return}if(T===At.current)return;const _=()=>{try{const W=I.slice(0,Si);Ei(S,W),At.current=T}catch{}finally{St.current=null}};return St.current=window.setTimeout(()=>{Tc(_),St.current=null},Po),()=>{St.current!==null&&(window.clearTimeout(St.current),St.current=null)}},[I,Ut]),y.useEffect(()=>{var xe;const T=l.getAuthToken();be(T);const _=ie=>{const Ie=ki(f,ie);it.current!==Ie&&(it.current=Ie,Oe.current=!1),N(Ie);const ge=Ii(Ie);y.startTransition(()=>{k(Oo(ge))}),Oe.current||(Oe.current=!0,Rt().catch(()=>{}))};_(T);const W=(xe=l.onTokenChange)==null?void 0:xe.call(l,ie=>{be(ie),b(),_(ie)});return()=>{W==null||W()}},[l,f,be,b,Rt]);const Ue=y.useCallback(async T=>{var xe;const _=`Thread ${(xe=crypto.randomUUID)==null?void 0:xe.call(crypto)}`,W={threadId:_,title:T||"New Chat",createdAt:new Date().toISOString(),updatedAt:new Date().toISOString(),messageCount:0};k(ie=>({byId:{...ie.byId,[_]:W},order:[_,...ie.order]})),j(_);try{const ie=await l.createThread(T),Ie=typeof ie=="string"?ie:ie.threadId;return k(ge=>{const st=ge.byId[_];if(!st)return ge;const Xe={...ge.byId};delete Xe[_],Xe[Ie]={...st,threadId:Ie};const ut=ge.order.map(Wt=>Wt===_?Ie:Wt);return{byId:Xe,order:ut}}),j(Ie),setTimeout(()=>Rt(),10),G(null),Ie}catch(ie){throw k(Ie=>{if(!Ie.byId[_])return Ie;const ge={...Ie.byId};delete ge[_];const st=Ie.order.filter(Xe=>Xe!==_);return{byId:ge,order:st}}),j(null),G(String(ie)),ie}},[l,Rt]),ot=y.useCallback(async T=>{try{await l.deleteThread(T);let _=null;k(W=>{if(!W.byId[T])return W;const xe={...W.byId};delete xe[T];const ie=W.order.filter(ge=>ge!==T),Ie={byId:xe,order:ie};return _=Ni(Ie),Ie}),_&&Ut(_,{immediate:!0}),fn(T),Be.current===T&&(he.current=T,j(null),Be.current=null,me.current=null,kn()),await Rt(),G(null)}catch(_){throw G(String(_)),_}},[l,kn,fn,Rt,Ut]),Pt=y.useCallback(async(T,_)=>{try{await l.updateThread(T,_),k(W=>{const xe=W.byId[T];return xe?{byId:{...W.byId,[T]:{...xe,title:_}},order:W.order}:W}),G(null)}catch(W){throw await Rt(),G(String(W)),W}},[l,Rt]),E=y.useCallback(async(T,_,W,xe=!1)=>{await vt(async()=>{if(he.current===T&&!xe){he.current=null;return}if(re.current===T&&!xe)return;j(Xe=>Xe===T?Xe:T),Be.current=T;const ie=!xe&&!_&&!W;let Ie=!1;if(ie){const Xe=Ce.current.get(T);if(Xe)gr(Xe),Ie=!0;else{const ut=x(T);ut&&(Ce.current.set(T,ut),gr(ut),Ie=!0)}}const ge=xe||!Ie||!!_||!!W,st=async Xe=>{Xe&&V(!0),re.current=T;try{const ut=await l.getStateHistory({threadId:T,checkpointId:_,checkpointNs:W}),{payload:Wt,checkpoints:Qt}=wi(ut);dn(Wt,"replace",T),et(T,Qt,"replace"),U(null)}catch(ut){throw(!Ie||xe||Xe)&&(i==null||i(String(ut))),U(String(ut)),ut}finally{re.current=null,Xe&&V(!1)}};ge?await st(!0):ie&&Ie&&st(!1).catch(Xe=>{console.warn("[ChatSessionProvider] Background refresh failed:",Xe)})},`loadThread-${T}`)},[l,gr,dn,vt,i,et]),z=y.useCallback(async()=>{await vt(async()=>{const T=Be.current;T&&fn(T),he.current=null,j(null),Be.current=null,me.current=null,kn(),O(void 0),ee(void 0),ne(void 0);try{localStorage.removeItem("lastThreadId")}catch(_){console.warn("[ChatSessionProvider] Failed to clear lastThreadId:",_)}},"clearCurrentThread")},[kn,fn,vt]),te=y.useCallback(async T=>{const _=Me.current.get(T);if(_)return{threadId:T,checkpoints:_.slice()};const W=await l.getStateHistory({threadId:T}),{checkpoints:xe}=wi(W);et(T,xe,"replace");const ie=Me.current.get(T)??[];return{threadId:T,checkpoints:ie.slice()}},[l,et]),Ee=y.useCallback(async(T,_)=>{if(!Be.current)throw new Error("No active thread");await E(Be.current,T,_??void 0,!0)},[E]),Fe=y.useCallback(async()=>{if(!Be.current)throw new Error("No active thread");await E(Be.current,void 0,void 0,!0)},[E]),Ke=y.useCallback(async()=>{if(!Be.current)throw new Error("No active thread");if(de||!D)return;const T=ye;if(T){we(!0);try{const _=Be.current,W=await l.getStateHistory({threadId:_,checkpointId:T??K,checkpointNs:fe??X}),{payload:xe,checkpoints:ie}=wi(W);dn(xe,"prepend",_??void 0),_&&et(_,ie,"prepend"),U(null)}catch(_){throw U(String(_)),_}finally{we(!1)}}},[l,dn,D,K,X,fe,ye,de,et]),We=y.useCallback(T=>{if(!(T!=null&&T.threadId))return;const _={threadId:T.threadId,checkpointId:T.checkpointId??void 0,checkpointNs:T.checkpointNs??void 0,messages:T.messages??[],hasMore:T.hasMore,nextCursor:T.nextCursor??null,nextCursorNs:T.nextCursorNs??null};dn(_,"replace",T.threadId)},[dn]),ze=y.useCallback(async(T,_)=>{var ei;const W=Be.current,xe=(T==null?void 0:T.text)??"",ie=(T==null?void 0:T.attachments)??[],Ie=ie.length?ie:(_==null?void 0:_.attachments)??[],ge={...(_==null?void 0:_.payloadExtras)??{},...(T==null?void 0:T.payload)??{}};if(!W&&!Object.keys(ge).length&&Ie.length===0&&!xe.trim()){console.warn("[ChatSessionProvider] Nothing to submit - skipping");return}!W&&!ge.messages&&console.warn("[ChatSessionProvider] No thread ID - message will create new thread");const{contentParts:st,filesInfo:Xe}=await Dg(l,Ie),ut=[...st];xe&&xe.trim()&&ut.push({type:"text",text:xe.trim()});const Wt=!!W,Qt=Wt?(_==null?void 0:_.checkpointId)??pe.lastCheckpointId??void 0:void 0,en=Wt?(_==null?void 0:_.checkpointNs)??pe.lastCheckpointNs??void 0:void 0,$r={id:((ei=crypto.randomUUID)==null?void 0:ei.call(crypto))||`user-${Date.now()}`,role:"user",content:ut,createdAt:new Date().toISOString(),...Qt!=null?{checkpointId:Qt}:{},...en!=null?{checkpointNs:en}:{}};ut.length>0&&He($r);const ul={...$r,content:ut},Zs=Ie.length>0,Qs={...W?{threadId:W}:{},payload:{messages:ut.length>0?[ul]:[],files_info:Xe,...o&&Zs&&s?{active_agent:s}:{},...ge},...Qt!=null?{checkpointId:Qt}:{},...en!=null?{checkpointNs:en}:{},nodeFilter:_==null?void 0:_.nodeFilter,config:_==null?void 0:_.config};Lr(Qs,{onError:Rn=>{console.warn("[ChatSessionProvider] Stream error:",Rn)},onOpen:({threadId:Rn})=>{!Be.current&&Rn&&(pe.messages.length<=1&&(he.current=Rn),j(Rn))},onGap:Gn})},[l,o,s,Gn,pe.lastCheckpointId,pe.lastCheckpointNs,pe.messages.length,He,Lr]),wt=y.useCallback(async(T,_,W)=>{var ie,Ie;const xe=Be.current;if(!xe)throw new Error("No active thread to handle interrupt");try{const ge=_?W??!0:!1;try{Ze({type:"interrupt_response",payload:{interruptId:T}})}catch($r){console.warn("[ChatSessionProvider] optimistic interrupt_response dispatch failed:",$r)}const st=`${d}/runs/resume`,Xe=(ie=l.getAuthToken)==null?void 0:ie.call(l),ut=await fetch(st,{method:"POST",headers:{"Content-Type":"application/json",...Xe?{Authorization:`Bearer ${Xe}`}:{}},body:JSON.stringify({thread_id:xe,value:ge})});if(!ut.ok)throw new Error(`Resume failed with status ${ut.status}`);const Wt=(Ie=ut.body)==null?void 0:Ie.getReader();if(!Wt)throw new Error("No response body for resume stream");const Qt=new TextDecoder;let en="";for(;;){const{done:$r,value:ul}=await Wt.read();if($r)break;en+=Qt.decode(ul,{stream:!0});const Zs=en.split(`
|
|
39
|
-
`);en=Zs.pop()||"";for(const Qs of Zs)if(Qs.startsWith("data: ")){const ei=Qs.slice(6);try{const Rn=JSON.parse(ei);Ze({type:"event",payload:{ev:Rn}})}catch(Rn){console.warn("[ChatSessionProvider] Failed to parse resume SSE event:",Rn)}}}$(null)}catch(ge){throw console.error(`[ChatSessionProvider] Failed to handle interrupt ${T}:`,ge),ge}},[l,Ze,d]),ft=y.useCallback(T=>wt(T.interruptId,T.approved,T.value),[wt]);y.useEffect(()=>{if(a==null||a(A),A)try{localStorage.setItem("lastThreadId",A)}catch(T){console.warn("[ChatSessionProvider] Failed to persist lastThreadId:",T)}},[A,a]),y.useEffect(()=>((async()=>{try{if(Rt().catch(_=>{console.error("[ChatSessionProvider] Failed to refresh threads (background):",_),i==null||i(String(_))}),!r&&!t)try{const _=localStorage.getItem("lastThreadId");_&&(j(_),n&&await E(_))}catch(_){console.warn("[ChatSessionProvider] Failed to restore last thread:",_)}else t&&n&&await E(t)}catch(_){console.error("[ChatSessionProvider] Initialization failed:",_),i==null||i(String(_))}})(),()=>{}),[]),y.useEffect(()=>{const T=Be.current;if(!T||me.current!==T)return;const _={threadId:T,messages:pe.messages.slice(),hasMore:D,nextCursor:ye,checkpointId:pe.lastCheckpointId??null,checkpointNs:pe.lastCheckpointNs??null,nextCursorNs:fe??null},W=Ce.current.get(T);(!W||W.messages.length!==_.messages.length||W.messages.some((ie,Ie)=>{var ge;return(ie==null?void 0:ie.id)!==((ge=_.messages[Ie])==null?void 0:ge.id)})||(W==null?void 0:W.hasMore)!==_.hasMore||(W==null?void 0:W.nextCursor)!==_.nextCursor||(W==null?void 0:W.nextCursorNs)!==_.nextCursorNs||(W==null?void 0:W.checkpointId)!==_.checkpointId||(W==null?void 0:W.checkpointNs)!==_.checkpointNs)&&(Ce.current.set(T,_),_n.current&&window.clearTimeout(_n.current),_n.current=window.setTimeout(()=>{try{g(_,100)}catch(ie){console.warn("[ChatSessionProvider] Failed to persist thread payload:",ie)}},Po))},[D,ye,fe,pe.lastCheckpointId,pe.lastCheckpointNs,pe.messages]);const ht=y.useMemo(()=>({threads:I,currentThreadId:A,setCurrentThreadId:j,isLoading:P,error:M,actions:{createThread:Ue,deleteThread:ot,renameThread:Pt,refreshThreads:()=>Rt()},persistThreadsCache:Kn,hydrateFromCache:ce}),[I,A,P,M,Ue,ot,Pt,Rt,Kn,ce,j]),Lt=y.useMemo(()=>{const T=pe.lastBranch??null,_=pe.assemblingId??null,W=T||_?{branchLabel:(T==null?void 0:T.branchLabel)??null,lastBranch:T,assemblingMessageId:_}:null;return{threadId:A,messages:pe.messages,interrupt:B,checkpoint:{id:pe.lastCheckpointId??null,namespace:pe.lastCheckpointNs??null},metadata:W,isLoading:F,isHistoryLoading:de,error:q,hasMore:D,loadOlder:Ke,seedFromSnapshot:We,clearState:kn,listCheckpoints:te,navigateToCheckpoint:Ee,returnToLatest:Fe,loadThread:E,clearThread:z,respondToInterrupt:wt}},[z,kn,A,B,D,de,F,te,Ke,E,pe.assemblingId,pe.lastBranch,pe.lastCheckpointId,pe.lastCheckpointNs,pe.messages,Ee,wt,Fe,We,q]),Yn=y.useMemo(()=>({isStreaming:jn,error:se,submit:ze,stop:Fr,resume:ft,setAuthToken:be}),[jn,se,ze,Fr,ft,be]);return c.jsx(rx.Provider,{value:!0,children:c.jsx(Cc.Provider,{value:Yn,children:c.jsx(yc.Provider,{value:ht,children:c.jsx(Sc.Provider,{value:Lt,children:e})})})})}function Mo(){const e=y.useContext(yc);if(!e)throw new Error("useThreads must be used within ChatSessionProvider");return e}function Do(){const e=y.useContext(Sc);if(!e)throw new Error("useThreadState must be used within ChatSessionProvider");return e}function Ec(){const e=y.useContext(Cc);if(!e)throw new Error("useStream must be used within ChatSessionProvider");return e}function Lo({children:e,apiConfig:t,initialThreadId:n=null,autoLoadInitial:r=!0,disableAutoRestore:o=!1,enableFileAgentRouting:s=!1,fileAgentId:i="invoice_reader",onError:a,onThreadChange:l}){return c.jsx(Og,{apiConfig:t,children:c.jsx(dx,{initialThreadId:n,autoLoadInitial:r,disableAutoRestore:o,enableFileAgentRouting:s,fileAgentId:i,onError:a,onThreadChange:l,children:e})})}function Z(...e){return cm.twMerge(lm.clsx(e))}const fx=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"}}),Ge=m.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?Xn.Slot:"button";return c.jsx(i,{className:Z(fx({variant:t,size:n,className:e})),ref:s,...o})});Ge.displayName="Button";const Ic=m.forwardRef(({className:e,...t},n)=>c.jsx("textarea",{className:Z("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}));Ic.displayName="Textarea";function hx({initialValue:e="",editingMessageId:t=null,placeholder:n="Type your message...",isStreaming:r=!1,disabled:o=!1,maxLength:s=2e4,onSend:i,onCancelEdit:a,onStop:l,className:u="",textareaClassName:d="",allowEmptySend:f=!1}){const[h,p]=y.useState(e),[w,x]=y.useTransition(),g=y.useRef(null);y.useEffect(()=>{p(e??""),g.current&&(g.current.style.height="auto",g.current.style.height=`${g.current.scrollHeight}px`)},[e,t]);const v=y.useCallback(()=>{const A=g.current;A&&(A.style.height="auto",A.style.height=`${A.scrollHeight}px`)},[]);y.useEffect(()=>{v()},[v]);const b=y.useCallback(async A=>{A&&A.preventDefault();const j=(h??"").trim();!j&&!f||x(()=>{try{const P=i(j);P&&typeof P.then=="function"?P.then(()=>{p(""),g.current&&(g.current.style.height="auto")}).catch(()=>{}):(p(""),g.current&&(g.current.style.height="auto"))}catch{}})},[h,i,f]),S=y.useCallback(A=>{p(A.target.value),g.current&&(g.current.style.height="auto",g.current.style.height=`${g.current.scrollHeight}px`)},[]),N=y.useCallback(A=>{A.key==="Enter"&&!A.shiftKey?(A.preventDefault(),b()):A.key==="Escape"&&t&&(A.preventDefault(),a==null||a())},[b,t,a]),I=`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${t?"border-[hsl(var(--ring))] bg-[hsl(var(--card))] text-[hsl(var(--card-foreground))] dark:bg-[hsl(var(--card))] dark:text-[hsl(var(--card-foreground))]":""} ${d}`;return c.jsx("form",{onSubmit:A=>void b(A),className:`w-full ${u}`,children:c.jsxs("div",{className:"flex items-end gap-2",children:[c.jsx("div",{className:"flex-1",children:c.jsx(Ic,{ref:g,value:h,onChange:S,onKeyDown:N,placeholder:t?"Edit your message...":n,className:I,disabled:o,maxLength:s,rows:1,spellCheck:!1,autoCorrect:"off"})}),c.jsx("div",{children:r?c.jsx(Ge,{type:"button",onClick:()=>{l==null||l()},size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",disabled:o||!l,children:c.jsx(oe.Square,{size:16})}):c.jsx(Ge,{type:"submit",size:"icon",className:"shrink-0",title:t?"Save changes":"Send message",disabled:o||!h.trim()&&!f||w,children:c.jsx(oe.Send,{size:16})})})]})})}const px=y.memo(hx),Fo=0,On=1,yr=2,Nc=4;function Ac(e){return()=>e}function mx(e){e()}function _c(e,t){return n=>e(t(n))}function jc(e,t){return()=>e(t)}function gx(e,t){return n=>e(t,n)}function Ai(e){return e!==void 0}function xx(...e){return()=>{e.map(mx)}}function Sr(){}function $o(e,t){return t(e),e}function vx(e,t){return t(e)}function at(...e){return e}function Je(e,t){return e(On,t)}function Le(e,t){e(Fo,t)}function _i(e){e(yr)}function mt(e){return e(Nc)}function ve(e,t){return Je(e,gx(t,Fo))}function on(e,t){const n=e(On,r=>{n(),t(r)});return n}function Rc(e){let t,n;return r=>o=>{t=o,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function Pc(e,t){return e===t}function lt(e=Pc){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function Ae(e){return t=>n=>{e(n)&&t(n)}}function ae(e){return t=>_c(t,e)}function pn(e){return t=>()=>{t(e)}}function H(e,...t){const n=wx(...t);return(r,o)=>{switch(r){case yr:_i(e);return;case On:return Je(e,n(o))}}}function mn(e,t){return n=>r=>{n(t=e(t,r))}}function er(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);Je(s,l=>{const u=n;n=n|a,t[i]=l,u!==o&&n===o&&r&&(r(),r=null)})}),s=>i=>{const a=()=>{s([i].concat(t))};n===o?a():r=a}}function wx(...e){return t=>e.reduceRight(vx,t)}function bx(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=Je(e,s),t):(r(),Sr);case yr:r(),n=null;return}}}function Y(e){let t=e;const n=qe();return(r,o)=>{switch(r){case Fo:t=o;break;case On:{o(t);break}case Nc:return t}return n(r,o)}}function Et(e,t){return $o(Y(t),n=>ve(e,n))}function qe(){const e=[];return(t,n)=>{switch(t){case Fo:e.slice().forEach(r=>{r(n)});return;case yr:e.splice(0,e.length);return;case On:return e.push(n),()=>{const r=e.indexOf(n);r>-1&&e.splice(r,1)}}}}function Ft(e){return $o(qe(),t=>ve(e,t))}function Ye(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:yx(),singleton:n}}const yx=()=>Symbol();function Sx(e){const t=new Map,n=({constructor:r,dependencies:o,id:s,singleton:i})=>{if(i&&t.has(s))return t.get(s);const a=r(o.map(l=>n(l)));return i&&t.set(s,a),a};return n(e)}function xt(...e){const t=qe(),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);Je(s,l=>{n[i]=l,r=r|a,r===o&&Le(t,n)})}),function(s,i){switch(s){case yr:{_i(t);return}case On:return r===o&&i(n),Je(t,i)}}}function Ne(e,t=Pc){return H(e,lt(t))}function ji(...e){return function(t,n){switch(t){case yr:return;case On:return xx(...e.map(r=>Je(r,n)))}}}var Dt=(e=>(e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR",e))(Dt||{});const Cx={0:"debug",3:"error",1:"log",2:"warn"},Tx=()=>typeof globalThis>"u"?window:globalThis,Mn=Ye(()=>{const e=Y(3);return{log:Y((t,n,r=1)=>{var o;const s=(o=Tx().VIRTUOSO_LOG_LEVEL)!=null?o:mt(e);r>=s&&console[Cx[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 Ri(e,t,n).callbackRef}function Ri(e,t,n){const r=y.useRef(null);let o=i=>{};const s=y.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 kx(e,t,n,r,o,s,i,a,l){const u=y.useCallback(d=>{const f=Ex(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 w;p&&(w=h.ownerDocument.defaultView);const x=i?a?i.scrollLeft:i.scrollTop:p?a?w.scrollX||w.document.documentElement.scrollLeft:w.scrollY||w.document.documentElement.scrollTop:a?h.scrollLeft:h.scrollTop,g=i?a?i.scrollWidth:i.scrollHeight:p?a?w.document.documentElement.scrollWidth:w.document.documentElement.scrollHeight:a?h.scrollWidth:h.scrollHeight,v=i?a?i.offsetWidth:i.offsetHeight:p?a?w.innerWidth:w.innerHeight:a?h.offsetWidth:h.offsetHeight;r({scrollHeight:g,scrollTop:Math.max(x,0),viewportHeight:v}),s==null||s(a?Oc("column-gap",getComputedStyle(d).columnGap,o):Oc("row-gap",getComputedStyle(d).rowGap,o)),f!==null&&e(f)},[e,t,o,s,i,r,a]);return Ri(u,n,l)}function Ex(e,t,n,r){const o=e.length;if(o===0)return null;const s=[];for(let i=0;i<o;i++){const a=e.item(i);if(a.dataset.index===void 0)continue;const l=parseInt(a.dataset.index),u=parseFloat(a.dataset.knownSize),d=t(a,n);if(d===0&&r("Zero-sized element, this should not happen",{child:a},Dt.ERROR),d===u)continue;const f=s[s.length-1];s.length===0||f.size!==d||f.endIndex!==l-1?s.push({endIndex:l,size:d,startIndex:l}):s[s.length-1].endIndex++}return s}function Oc(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Dt.WARN),t==="normal"?0:parseInt(t??"0",10)}function Mc(e,t,n){const r=y.useRef(null),o=y.useCallback(l=>{if(!(l!=null&&l.offsetParent))return;const u=l.getBoundingClientRect(),d=u.width;let f,h;if(t){const p=t.getBoundingClientRect(),w=u.top-p.top;h=p.height-Math.max(0,w),f=w+t.scrollTop}else{const p=i.current.ownerDocument.defaultView;h=p.innerHeight-Math.max(0,u.top),f=u.top+p.scrollY}r.current={offsetTop:f,visibleHeight:h,visibleWidth:d},e(r.current)},[e,t]),{callbackRef:s,ref:i}=Ri(o,!0,n),a=y.useCallback(()=>{o(i.current)},[o,i]);return y.useEffect(()=>{var l;if(t){t.addEventListener("scroll",a);const u=new ResizeObserver(()=>{requestAnimationFrame(a)});return u.observe(t),()=>{t.removeEventListener("scroll",a),u.unobserve(t)}}else{const u=(l=i.current)==null?void 0:l.ownerDocument.defaultView;return u==null||u.addEventListener("scroll",a),u==null||u.addEventListener("resize",a),()=>{u==null||u.removeEventListener("scroll",a),u==null||u.removeEventListener("resize",a)}}},[a,t,i]),s}const _t=Ye(()=>{const e=qe(),t=qe(),n=Y(0),r=qe(),o=Y(0),s=qe(),i=qe(),a=Y(0),l=Y(0),u=Y(0),d=Y(0),f=qe(),h=qe(),p=Y(!1),w=Y(!1),x=Y(!1);return ve(H(e,ae(({scrollTop:g})=>g)),t),ve(H(e,ae(({scrollHeight:g})=>g)),i),ve(t,o),{deviation:n,fixedFooterHeight:u,fixedHeaderHeight:l,footerHeight:d,headerHeight:a,horizontalDirection:w,scrollBy:h,scrollContainerState:e,scrollHeight:i,scrollingInProgress:p,scrollTo:f,scrollTop:t,skipAnimationFrameInResizeObserver:x,smoothScrollTargetReached:r,statefulScrollTop:o,viewportHeight:s}},[],{singleton:!0}),Kr={lvl:0};function Dc(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 nt(e){return e===Kr}function Gr(e,t){if(!nt(e))return t===e.k?e.v:t<e.k?Gr(e.l,t):Gr(e.r,t)}function sn(e,t,n="k"){if(nt(e))return[-1/0,void 0];if(Number(e[n])===t)return[e.k,e.v];if(Number(e[n])<t){const r=sn(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return sn(e.l,t,n)}function $t(e,t,n){return nt(e)?$c(t,n,1):t===e.k?yt(e,{k:t,v:n}):t<e.k?Bc(yt(e,{l:$t(e.l,t,n)})):Bc(yt(e,{r:$t(e.r,t,n)}))}function Cr(){return Kr}function Bo(e,t,n){if(nt(e))return[];const r=sn(e,t)[0];return Ix(Oi(e,r,n))}function Pi(e,t){if(nt(e))return Kr;const{k:n,l:r,r:o}=e;if(t===n){if(nt(r))return o;if(nt(o))return r;{const[s,i]=Fc(r);return zo(yt(e,{k:s,l:Lc(r),v:i}))}}else return t<n?zo(yt(e,{l:Pi(r,t)})):zo(yt(e,{r:Pi(o,t)}))}function nr(e){return nt(e)?[]:[...nr(e.l),{k:e.k,v:e.v},...nr(e.r)]}function Oi(e,t,n){if(nt(e))return[];const{k:r,l:o,r:s,v:i}=e;let a=[];return r>t&&(a=a.concat(Oi(o,t,n))),r>=t&&r<=n&&a.push({k:r,v:i}),r<=n&&(a=a.concat(Oi(s,t,n))),a}function zo(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(Mi(t))return zc(yt(e,{lvl:n-1}));if(!nt(t)&&!nt(t.r))return yt(t.r,{l:yt(t,{r:t.r.l}),lvl:n,r:yt(e,{l:t.r.r,lvl:n-1})});throw new Error("Unexpected empty nodes")}else{if(Mi(e))return Di(yt(e,{lvl:n-1}));if(!nt(r)&&!nt(r.l)){const o=r.l,s=Mi(o)?r.lvl-1:r.lvl;return yt(o,{l:yt(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:Di(yt(r,{l:o.r,lvl:s}))})}else throw new Error("Unexpected empty nodes")}}function yt(e,t){return $c(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 Lc(e){return nt(e.r)?e.l:zo(yt(e,{r:Lc(e.r)}))}function Mi(e){return nt(e)||e.lvl>e.r.lvl}function Fc(e){return nt(e.r)?[e.k,e.v]:Fc(e.r)}function $c(e,t,n,r=Kr,o=Kr){return{k:e,l:r,lvl:n,r:o,v:t}}function Bc(e){return Di(zc(e))}function zc(e){const{l:t}=e;return!nt(t)&&t.lvl===e.lvl?yt(t,{r:yt(e,{l:t.r})}):e}function Di(e){const{lvl:t,r:n}=e;return!nt(n)&&!nt(n.r)&&n.lvl===t&&n.r.lvl===t?yt(n,{l:yt(e,{r:n.l}),lvl:t+1}):e}function Ix(e){return Dc(e,({k:t,v:n})=>({index:t,value:n}))}function Hc(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function Yr(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}const Li=Ye(()=>({recalcInProgress:Y(!1)}),[],{singleton:!0});function Uc(e,t,n){return e[Ho(e,t,n)]}function Ho(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 Nx(e,t,n,r){const o=Ho(e,t,r),s=Ho(e,n,r,o);return e.slice(o,s+1)}function Dn(e,t){return Math.round(e.getBoundingClientRect()[t])}function Uo(e){return!nt(e.groupOffsetTree)}function Fi({index:e},t){return t===e?0:t<e?-1:1}function Ax(){return{groupIndices:[],groupOffsetTree:Cr(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:Cr()}}function _x(e,t){let n=nt(e)?0:1/0;for(const r of t){const{endIndex:o,size:s,startIndex:i}=r;if(n=Math.min(n,i),nt(e)){e=$t(e,0,s);continue}const a=Bo(e,i-1,o+1);if(a.some(Lx(r)))continue;let l=!1,u=!1;for(const{end:d,start:f,value:h}of a)l?(o>=f||s===h)&&(e=Pi(e,f)):(u=h!==s,l=!0),d>o&&o>=f&&h!==s&&(e=$t(e,o+1,h));u&&(e=$t(e,i,s))}return[e,n]}function jx(e){return typeof e.groupIndex<"u"}function Rx({offset:e},t){return t===e?0:t<e?-1:1}function Xr(e,t,n){if(t.length===0)return 0;const{index:r,offset:o,size:s}=Uc(t,e,Fi),i=e-r,a=s*i+(i-1)*n+o;return a>0?a+n:a}function Wc(e,t){if(!Uo(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function Vc(e,t,n){if(jx(e))return t.groupIndices[e.groupIndex]+1;{const r=e.index==="LAST"?n:e.index;let o=Wc(r,t);return o=Math.max(0,o,Math.min(n,o)),o}}function Px(e,t,n,r=0){return r>0&&(t=Math.max(t,Uc(e,r,Fi).offset)),Dc(Nx(e,t,n,Rx),Dx)}function Ox(e,[t,n,r,o]){t.length>0&&r("received item sizes",t,Dt.DEBUG);const s=e.sizeTree;let i=s,a=0;if(n.length>0&&nt(s)&&t.length===2){const h=t[0].size,p=t[1].size;i=n.reduce((w,x)=>$t($t(w,x,h),x+1,p),i)}else[i,a]=_x(i,t);if(i===s)return e;const{lastIndex:l,lastOffset:u,lastSize:d,offsetTree:f}=$i(e.offsetTree,a,i,o);return{groupIndices:n,groupOffsetTree:n.reduce((h,p)=>$t(h,p,Xr(p,f,o)),Cr()),lastIndex:l,lastOffset:u,lastSize:d,offsetTree:f,sizeTree:i}}function Mx(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 qc(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 $i(e,t,n,r){let o=e,s=0,i=0,a=0,l=0;if(t!==0){l=Ho(o,t-1,Fi),a=o[l].offset;const u=sn(n,t-1);s=u[0],i=u[1],o.length&&o[l].size===sn(n,t)[1]&&(l-=1),o=o.slice(0,l+1)}else o=[];for(const{start:u,value:d}of Bo(n,t,1/0)){const f=u-s,h=f*i+a+f*r;o.push({index:u,offset:h,size:d}),s=u,a=h,i=d}return{lastIndex:s,lastOffset:a,lastSize:i,offsetTree:o}}function Dx(e){return{index:e.index,value:e}}function Lx(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 Fx={offsetHeight:"height",offsetWidth:"width"},gn=Ye(([{log:e},{recalcInProgress:t}])=>{const n=qe(),r=qe(),o=Et(r,0),s=qe(),i=qe(),a=Y(0),l=Y([]),u=Y(void 0),d=Y(void 0),f=Y((C,k)=>Dn(C,Fx[k])),h=Y(void 0),p=Y(0),w=Ax(),x=Et(H(n,$e(l,e,p),mn(Ox,w),lt()),w),g=Et(H(l,lt(),mn((C,k)=>({current:k,prev:C.current}),{current:[],prev:[]}),ae(({prev:C})=>C)),[]);ve(H(l,Ae(C=>C.length>0),$e(x,p),ae(([C,k,I])=>{const A=C.reduce((j,P,L)=>$t(j,P,Xr(P,k.offsetTree,I)||L),Cr());return{...k,groupIndices:C,groupOffsetTree:A}})),x),ve(H(r,$e(x),Ae(([C,{lastIndex:k}])=>C<k),ae(([C,{lastIndex:k,lastSize:I}])=>[{endIndex:k,size:I,startIndex:C}])),n),ve(u,d);const v=Et(H(u,ae(C=>C===void 0)),!0);ve(H(d,Ae(C=>C!==void 0&&nt(mt(x).sizeTree)),ae(C=>[{endIndex:0,size:C,startIndex:0}])),n);const b=Ft(H(n,$e(x),mn(({sizes:C},[k,I])=>({changed:I!==C,sizes:I}),{changed:!1,sizes:w}),ae(C=>C.changed)));Je(H(a,mn((C,k)=>({diff:C.prev-k,prev:k}),{diff:0,prev:0}),ae(C=>C.diff)),C=>{const{groupIndices:k}=mt(x);if(C>0)Le(t,!0),Le(s,C+qc(C,k));else if(C<0){const I=mt(g);I.length>0&&(C-=qc(-C,I)),Le(i,C)}}),Je(H(a,$e(e)),([C,k])=>{C<0&&k("`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},Dt.ERROR)});const S=Ft(s);ve(H(s,$e(x),ae(([C,k])=>{const I=k.groupIndices.length>0,A=[],j=k.lastSize;if(I){const P=Gr(k.sizeTree,0);let L=0,F=0;for(;L<C;){const M=k.groupIndices[F],G=k.groupIndices.length===F+1?1/0:k.groupIndices[F+1]-M-1;A.push({endIndex:M,size:P,startIndex:M}),A.push({endIndex:M+1+G-1,size:j,startIndex:M+1}),F++,L+=G+1}const V=nr(k.sizeTree);return L!==C&&V.shift(),V.reduce((M,{k:G,v:q})=>{let U=M.ranges;return M.prevSize!==0&&(U=[...M.ranges,{endIndex:G+C-1,size:M.prevSize,startIndex:M.prevIndex}]),{prevIndex:G+C,prevSize:q,ranges:U}},{prevIndex:C,prevSize:0,ranges:A}).ranges}return nr(k.sizeTree).reduce((P,{k:L,v:F})=>({prevIndex:L+C,prevSize:F,ranges:[...P.ranges,{endIndex:L+C-1,size:P.prevSize,startIndex:P.prevIndex}]}),{prevIndex:0,prevSize:j,ranges:[]}).ranges})),n);const N=Ft(H(i,$e(x,p),ae(([C,{offsetTree:k},I])=>{const A=-C;return Xr(A,k,I)})));return ve(H(i,$e(x,p),ae(([C,k,I])=>{if(k.groupIndices.length>0){if(nt(k.sizeTree))return k;let A=Cr();const j=mt(g);let P=0,L=0,F=0;for(;P<-C;){F=j[L];const V=j[L+1]-F-1;L++,P+=V+1}if(A=nr(k.sizeTree).reduce((V,{k:M,v:G})=>$t(V,Math.max(0,M+C),G),A),P!==-C){const V=Gr(k.sizeTree,F);A=$t(A,0,V);const M=sn(k.sizeTree,-C+1)[1];A=$t(A,1,M)}return{...k,sizeTree:A,...$i(k.offsetTree,0,A,I)}}else{const A=nr(k.sizeTree).reduce((j,{k:P,v:L})=>$t(j,Math.max(0,P+C),L),Cr());return{...k,sizeTree:A,...$i(k.offsetTree,0,A,I)}}})),x),{beforeUnshiftWith:S,data:h,defaultItemSize:d,firstItemIndex:a,fixedItemSize:u,gap:p,groupIndices:l,itemSize:f,listRefresh:b,shiftWith:i,shiftWithOffset:N,sizeRanges:n,sizes:x,statefulTotalCount:o,totalCount:r,trackItemSizes:v,unshiftWith:s}},at(Mn,Li),{singleton:!0});function $x(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const Kc=Ye(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=qe(),i=qe(),a=Ft(H(s,ae($x)));return ve(H(a,ae(l=>l.totalCount)),n),ve(H(a,ae(l=>l.groupIndices)),e),ve(H(xt(o,t,r),Ae(([l,u])=>Uo(u)),ae(([l,u,d])=>sn(u.groupOffsetTree,Math.max(l-d,0),"v")[0]),lt(),ae(l=>[l])),i),{groupCounts:s,topItemsIndexes:i}},at(gn,_t)),Ln=Ye(([{log:e}])=>{const t=Y(!1),n=Ft(H(t,Ae(r=>r),lt()));return Je(t,r=>{r&&mt(e)("props updated",{},Dt.DEBUG)}),{didMount:n,propsReady:t}},at(Mn),{singleton:!0}),Bx=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function Gc(e){const t=typeof e=="number"?{index:e}:e;return t.align||(t.align="start"),(!t.behavior||!Bx)&&(t.behavior="auto"),t.offset||(t.offset=0),t}const Jr=Ye(([{gap:e,listRefresh:t,sizes:n,totalCount:r},{fixedFooterHeight:o,fixedHeaderHeight:s,footerHeight:i,headerHeight:a,scrollingInProgress:l,scrollTo:u,smoothScrollTargetReached:d,viewportHeight:f},{log:h}])=>{const p=qe(),w=qe(),x=Y(0);let g=null,v=null,b=null;function S(){g&&(g(),g=null),b&&(b(),b=null),v&&(clearTimeout(v),v=null),Le(l,!1)}return ve(H(p,$e(n,f,r,x,a,i,h),$e(e,s,o),ae(([[N,C,k,I,A,j,P,L],F,V,M])=>{const G=Gc(N),{align:q,behavior:U,offset:B}=G,$=I-1,ce=Vc(G,C,$);let D=Xr(ce,C.offsetTree,F)+j;q==="end"?(D+=V+sn(C.sizeTree,ce)[1]-k+M,ce===$&&(D+=P)):q==="center"?D+=(V+sn(C.sizeTree,ce)[1]-k+M)/2:D-=A,B&&(D+=B);const Q=de=>{S(),de?(L("retrying to scroll to",{location:N},Dt.DEBUG),Le(p,N)):(Le(w,!0),L("list did not change, scroll successful",{},Dt.DEBUG))};if(S(),U==="smooth"){let de=!1;b=Je(t,we=>{de=de||we}),g=on(d,()=>{Q(de)})}else g=on(H(t,zx(150)),Q);return v=setTimeout(()=>{S()},1200),Le(l,!0),L("scrolling from index to",{behavior:U,index:ce,top:D},Dt.DEBUG),{behavior:U,top:D}})),u),{scrollTargetReached:w,scrollToIndex:p,topListHeight:x}},at(gn,_t,Mn),{singleton:!0});function zx(e){return t=>{const n=setTimeout(()=>{t(!1)},e);return r=>{r&&(t(!0),clearTimeout(n))}}}function Bi(e,t){e==0?t():requestAnimationFrame(()=>{Bi(e-1,t)})}function zi(e,t){const n=t-1;return typeof e=="number"?e:e.index==="LAST"?n:e.index}const Zr=Ye(([{defaultItemSize:e,listRefresh:t,sizes:n},{scrollTop:r},{scrollTargetReached:o,scrollToIndex:s},{didMount:i}])=>{const a=Y(!0),l=Y(0),u=Y(!0);return ve(H(i,$e(l),Ae(([d,f])=>!!f),pn(!1)),a),ve(H(i,$e(l),Ae(([d,f])=>!!f),pn(!1)),u),Je(H(xt(t,i),$e(a,n,e,u),Ae(([[,d],f,{sizeTree:h},p,w])=>d&&(!nt(h)||Ai(p))&&!f&&!w),$e(l)),([,d])=>{on(o,()=>{Le(u,!0)}),Bi(4,()=>{on(r,()=>{Le(a,!0)}),Le(s,d)})}),{initialItemFinalLocationReached:u,initialTopMostItemIndex:l,scrolledToInitialItem:a}},at(gn,_t,Jr,Ln),{singleton:!0});function Yc(e,t){return Math.abs(e-t)<1.01}const Qr="up",eo="down",Hx="none",Ux={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},Wx=0,to=Ye(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:o,viewportHeight:s}])=>{const i=Y(!1),a=Y(!0),l=qe(),u=qe(),d=Y(4),f=Y(Wx),h=Et(H(ji(H(Ne(o),er(1),pn(!0)),H(Ne(o),er(1),pn(!1),Rc(100))),lt()),!1),p=Et(H(ji(H(n,pn(!0)),H(n,pn(!1),Rc(200))),lt()),!1);ve(H(xt(Ne(o),Ne(f)),ae(([b,S])=>b<=S),lt()),a),ve(H(a,In(50)),u);const w=Ft(H(xt(r,Ne(s),Ne(t),Ne(e),Ne(d)),mn((b,[{scrollHeight:S,scrollTop:N},C,k,I,A])=>{const j=N+C-S>-A,P={scrollHeight:S,scrollTop:N,viewportHeight:C};if(j){let F,V;return N>b.state.scrollTop?(F="SCROLLED_DOWN",V=b.state.scrollTop-N):(F="SIZE_DECREASED",V=b.state.scrollTop-N||b.scrollTopDelta),{atBottom:!0,atBottomBecause:F,scrollTopDelta:V,state:P}}let L;return P.scrollHeight>b.state.scrollHeight?L="SIZE_INCREASED":C<b.state.viewportHeight?L="VIEWPORT_HEIGHT_DECREASING":N<b.state.scrollTop?L="SCROLLING_UPWARDS":L="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:L,state:P}},Ux),lt((b,S)=>b&&b.atBottom===S.atBottom))),x=Et(H(r,mn((b,{scrollHeight:S,scrollTop:N,viewportHeight:C})=>{if(Yc(b.scrollHeight,S))return{changed:!1,jump:0,scrollHeight:S,scrollTop:N};{const k=S-(N+C)<1;return b.scrollTop!==N&&k?{changed:!0,jump:b.scrollTop-N,scrollHeight:S,scrollTop:N}:{changed:!0,jump:0,scrollHeight:S,scrollTop:N}}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),Ae(b=>b.changed),ae(b=>b.jump)),0);ve(H(w,ae(b=>b.atBottom)),i),ve(H(i,In(50)),l);const g=Y(eo);ve(H(r,ae(({scrollTop:b})=>b),lt(),mn((b,S)=>mt(p)?{direction:b.direction,prevScrollTop:S}:{direction:S<b.prevScrollTop?Qr:eo,prevScrollTop:S},{direction:eo,prevScrollTop:0}),ae(b=>b.direction)),g),ve(H(r,In(50),pn(Hx)),g);const v=Y(0);return ve(H(h,Ae(b=>!b),pn(0)),v),ve(H(o,In(100),$e(h),Ae(([b,S])=>!!S),mn(([b,S],[N])=>[S,N],[0,0]),ae(([b,S])=>S-b)),v),{atBottomState:w,atBottomStateChange:l,atBottomThreshold:d,atTopStateChange:u,atTopThreshold:f,isAtBottom:i,isAtTop:a,isScrolling:h,lastJumpDueToItemResize:x,scrollDirection:g,scrollVelocity:v}},at(_t)),Wo="top",Vo="bottom",Xc="none";function Jc(e,t,n){return typeof e=="number"?n===Qr&&t===Wo||n===eo&&t===Vo?e:0:n===Qr?t===Wo?e.main:e.reverse:t===Vo?e.main:e.reverse}function Zc(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const Hi=Ye(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:o}])=>{const s=qe(),i=Y(0),a=Y(0),l=Y(0),u=Et(H(xt(Ne(r),Ne(o),Ne(n),Ne(s,Yr),Ne(l),Ne(i),Ne(t),Ne(e),Ne(a)),ae(([d,f,h,[p,w],x,g,v,b,S])=>{const N=d-b,C=g+v,k=Math.max(h-N,0);let I=Xc;const A=Zc(S,Wo),j=Zc(S,Vo);return p-=b,p+=h+v,w+=h+v,w-=b,p>d+C-A&&(I=Qr),w<d-k+f+j&&(I=eo),I!==Xc?[Math.max(N-h-Jc(x,Wo,I)-A,0),N-k-v+f+Jc(x,Vo,I)+j]:null}),Ae(d=>d!=null),lt(Yr)),[0,0]);return{increaseViewportBy:a,listBoundary:s,overscan:l,topListHeight:i,visibleRange:u}},at(_t),{singleton:!0});function Vx(e,t,n){if(Uo(t)){const r=Wc(e,t);return[{index:sn(t.groupOffsetTree,r)[0],offset:0,size:0},{data:n==null?void 0:n[0],index:r,offset:0,size:0}]}return[{data:n==null?void 0:n[0],index:e,offset:0,size:0}]}const Ui={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function qo(e,t,n,r,o,s){const{lastIndex:i,lastOffset:a,lastSize:l}=o;let u=0,d=0;if(e.length>0){u=e[0].offset;const x=e[e.length-1];d=x.offset+x.size}const f=n-i,h=a+f*l+(f-1)*r,p=u,w=h-d;return{bottom:d,firstItemIndex:s,items:eu(e,o,s),offsetBottom:w,offsetTop:u,top:p,topItems:eu(t,o,s),topListHeight:t.reduce((x,g)=>g.size+x,0),totalCount:n}}function Qc(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=zi(t,a),u=Array.from({length:a}).map((d,f)=>({data:s[f+l],index:f+l,offset:0,size:0}));return qo(u,[],a,o,n,r)}function eu(e,t,n){if(e.length===0)return[];if(!Uo(t))return e.map(u=>({...u,index:u.index+n,originalIndex:u.index}));const r=e[0].index,o=e[e.length-1].index,s=[],i=Bo(t.groupOffsetTree,r,o);let a,l=0;for(const u of e){(!a||a.end<u.index)&&(a=i.shift(),l=t.groupIndices.indexOf(a.start));let d;u.index===a.start?d={index:l,type:"group"}:d={groupIndex:l,index:u.index-(l+1)+n},s.push({...d,data:u.data,offset:u.offset,originalIndex:u.index,size:u.size})}return s}const rr=Ye(([{data:e,firstItemIndex:t,gap:n,sizes:r,totalCount:o},s,{listBoundary:i,topListHeight:a,visibleRange:l},{initialTopMostItemIndex:u,scrolledToInitialItem:d},{topListHeight:f},h,{didMount:p},{recalcInProgress:w}])=>{const x=Y([]),g=Y(0),v=qe();ve(s.topItemsIndexes,x);const b=Et(H(xt(p,w,Ne(l,Yr),Ne(o),Ne(r),Ne(u),d,Ne(x),Ne(t),Ne(n),e),Ae(([k,I,,A,,,,,,,j])=>{const P=j&&j.length!==A;return k&&!I&&!P}),ae(([,,[k,I],A,j,P,L,F,V,M,G])=>{const q=j,{offsetTree:U,sizeTree:B}=q,$=mt(g);if(A===0)return{...Ui,totalCount:A};if(k===0&&I===0)return $===0?{...Ui,totalCount:A}:Qc($,P,j,V,M,G||[]);if(nt(B))return $>0?null:qo(Vx(zi(P,A),q,G),[],A,M,q,V);const ce=[];if(F.length>0){const ye=F[0],Se=F[F.length-1];let K=0;for(const O of Bo(B,ye,Se)){const X=O.value,ee=Math.max(O.start,ye),fe=Math.min(O.end,Se);for(let ne=ee;ne<=fe;ne++)ce.push({data:G==null?void 0:G[ne],index:ne,offset:K,size:X}),K+=X}}if(!L)return qo([],ce,A,M,q,V);const D=F.length>0?F[F.length-1]+1:0,Q=Px(U,k,I,D);if(Q.length===0)return null;const de=A-1,we=$o([],ye=>{for(const Se of Q){const K=Se.value;let O=K.offset,X=Se.start;const ee=K.size;if(K.offset<k){X+=Math.floor((k-K.offset+M)/(ee+M));const ne=X-Se.start;O+=ne*ee+ne*M}X<D&&(O+=(D-X)*ee,X=D);const fe=Math.min(Se.end,de);for(let ne=X;ne<=fe&&!(O>=I);ne++)ye.push({data:G==null?void 0:G[ne],index:ne,offset:O,size:ee}),O+=ee+M}});return qo(we,ce,A,M,q,V)}),Ae(k=>k!==null),lt()),Ui);ve(H(e,Ae(Ai),ae(k=>k==null?void 0:k.length)),o),ve(H(b,ae(k=>k.topListHeight)),f),ve(f,a),ve(H(b,ae(k=>[k.top,k.bottom])),i),ve(H(b,ae(k=>k.items)),v);const S=Ft(H(b,Ae(({items:k})=>k.length>0),$e(o,e),Ae(([{items:k},I])=>k[k.length-1].originalIndex===I-1),ae(([,k,I])=>[k-1,I]),lt(Yr),ae(([k])=>k))),N=Ft(H(b,In(200),Ae(({items:k,topItems:I})=>k.length>0&&k[0].originalIndex===I.length),ae(({items:k})=>k[0].index),lt())),C=Ft(H(b,Ae(({items:k})=>k.length>0),ae(({items:k})=>{let I=0,A=k.length-1;for(;k[I].type==="group"&&I<A;)I++;for(;k[A].type==="group"&&A>I;)A--;return{endIndex:k[A].index,startIndex:k[I].index}}),lt(Hc)));return{endReached:S,initialItemCount:g,itemsRendered:v,listState:b,rangeChanged:C,startReached:N,topItemsIndexes:x,...h}},at(gn,Kc,Hi,Zr,Jr,to,Ln,Li),{singleton:!0}),tu=Ye(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:o}])=>{const s=qe(),i=Et(H(xt(n,e,r,t,o),ae(([a,l,u,d,f])=>a+l+u+d+f.offsetBottom+f.bottom)),0);return ve(Ne(i),s),{totalListHeight:i,totalListHeightChanged:s}},at(_t,rr),{singleton:!0}),qx=Ye(([{viewportHeight:e},{totalListHeight:t}])=>{const n=Y(!1),r=Et(H(xt(n,e,t),Ae(([o])=>o),ae(([,o,s])=>Math.max(0,o-s)),In(0),lt()),0);return{alignToBottom:n,paddingTopAddition:r}},at(_t,tu),{singleton:!0}),nu=Ye(()=>({context:Y(null)})),Kx=({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,ru=Ye(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:s,scrollingInProgress:i,scrollTop:a,viewportHeight:l},{scrollToIndex:u}])=>{const d=qe();return ve(H(d,$e(t,l,n,s,o,r,a),$e(e),ae(([[f,h,p,w,x,g,v,b],S])=>{const{align:N,behavior:C,calculateViewLocation:k=Kx,done:I,...A}=f,j=Vc(f,h,w-1),P=Xr(j,h.offsetTree,S)+x+g,L=P+sn(h.sizeTree,j)[1],F=b+g,V=b+p-v,M=k({itemBottom:L,itemTop:P,locationParams:{align:N,behavior:C,...A},viewportBottom:V,viewportTop:F});return M?I&&on(H(i,Ae(G=>!G),er(mt(i)?1:2)),I):I&&I(),M}),Ae(f=>f!==null)),u),{scrollIntoView:d}},at(gn,_t,Jr,rr,Mn),{singleton:!0});function ou(e){return e?e==="smooth"?"smooth":"auto":!1}const Gx=(e,t)=>typeof e=="function"?ou(e(t)):t&&ou(e),Yx=Ye(([{listRefresh:e,totalCount:t,fixedItemSize:n,data:r},{atBottomState:o,isAtBottom:s},{scrollToIndex:i},{scrolledToInitialItem:a},{didMount:l,propsReady:u},{log:d},{scrollingInProgress:f},{context:h},{scrollIntoView:p}])=>{const w=Y(!1),x=qe();let g=null;function v(C){Le(i,{align:"end",behavior:C,index:"LAST"})}Je(H(xt(H(Ne(t),er(1)),l),$e(Ne(w),s,a,f),ae(([[C,k],I,A,j,P])=>{let L=k&&j,F="auto";return L&&(F=Gx(I,A||P),L=L&&!!F),{followOutputBehavior:F,shouldFollow:L,totalCount:C}}),Ae(({shouldFollow:C})=>C)),({followOutputBehavior:C,totalCount:k})=>{g&&(g(),g=null),mt(n)?requestAnimationFrame(()=>{mt(d)("following output to ",{totalCount:k},Dt.DEBUG),v(C)}):g=on(e,()=>{mt(d)("following output to ",{totalCount:k},Dt.DEBUG),v(C),g=null})});function b(C){const k=on(o,I=>{C&&!I.atBottom&&I.notAtBottomBecause==="SIZE_INCREASED"&&!g&&(mt(d)("scrolling to bottom due to increased size",{},Dt.DEBUG),v("auto"))});setTimeout(k,100)}Je(H(xt(Ne(w),t,u),Ae(([C,,k])=>C&&k),mn(({value:C},[,k])=>({refreshed:C===k,value:k}),{refreshed:!1,value:0}),Ae(({refreshed:C})=>C),$e(w,t)),([,C])=>{mt(a)&&b(C!==!1)}),Je(x,()=>{b(mt(w)!==!1)}),Je(xt(Ne(w),o),([C,k])=>{C&&!k.atBottom&&k.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&v("auto")});const S=Y(null),N=qe();return ve(ji(H(Ne(r),ae(C=>{var k;return(k=C==null?void 0:C.length)!=null?k:0})),H(Ne(t))),N),Je(H(xt(H(N,er(1)),l),$e(Ne(S),a,f,h),ae(([[C,k],I,A,j,P])=>k&&A&&(I==null?void 0:I({context:P,totalCount:C,scrollingInProgress:j}))),Ae(C=>!!C),In(0)),C=>{g&&(g(),g=null),mt(n)?requestAnimationFrame(()=>{mt(d)("scrolling into view",{}),Le(p,C)}):g=on(e,()=>{mt(d)("scrolling into view",{}),Le(p,C),g=null})}),{autoscrollToBottom:x,followOutput:w,scrollIntoViewOnChange:S}},at(gn,to,Jr,Zr,Ln,Mn,_t,nu,ru)),Xx=Ye(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:s,listState:i},{didMount:a}])=>(ve(H(a,$e(s),Ae(([,l])=>l!==0),$e(o,r,t,n,e),ae(([[,l],u,d,f,h,p=[]])=>Qc(l,u,d,f,h,p))),i),{}),at(gn,Zr,rr,Ln),{singleton:!0}),Jx=Ye(([{didMount:e},{scrollTo:t},{listState:n}])=>{const r=Y(0);return Je(H(e,$e(r),Ae(([,o])=>o!==0),ae(([,o])=>({top:o}))),o=>{on(H(n,er(1),Ae(s=>s.items.length>1)),()=>{requestAnimationFrame(()=>{Le(t,o)})})}),{initialScrollTop:r}},at(Ln,_t,rr),{singleton:!0}),su=Ye(([{scrollVelocity:e}])=>{const t=Y(!1),n=qe(),r=Y(!1);return ve(H(e,$e(r,t,n),Ae(([o,s])=>!!s),ae(([o,s,i,a])=>{const{enter:l,exit:u}=s;if(i){if(u(o,a))return!1}else if(l(o,a))return!0;return i}),lt()),t),Je(H(xt(t,e,n),$e(r)),([[o,s,i],a])=>{o&&a&&a.change&&a.change(s,i)}),{isSeeking:t,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:e}},at(to),{singleton:!0}),Wi=Ye(([{scrollContainerState:e,scrollTo:t}])=>{const n=qe(),r=qe(),o=qe(),s=Y(!1),i=Y(void 0);return ve(H(xt(n,r),ae(([{scrollHeight:a,scrollTop:l,viewportHeight:u},{offsetTop:d}])=>({scrollHeight:a,scrollTop:Math.max(0,l-d),viewportHeight:u}))),e),ve(H(t,$e(r),ae(([a,{offsetTop:l}])=>({...a,top:a.top+l}))),o),{customScrollParent:i,useWindowScroll:s,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:r}},at(_t)),Zx=Ye(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:o},{didMount:s},{useWindowScroll:i,windowScrollContainerState:a,windowViewportRect:l}])=>{const u=qe(),d=Y(void 0),f=Y(null),h=Y(null);return ve(a,f),ve(l,h),Je(H(u,$e(t,r,i,f,h,n)),([p,w,x,g,v,b,S])=>{const N=Mx(w.sizeTree);g&&v!==null&&b!==null&&(x=v.scrollTop-b.offsetTop),x-=S,p({ranges:N,scrollTop:x})}),ve(H(d,Ae(Ai),ae(Qx)),o),ve(H(s,$e(d),Ae(([,p])=>p!==void 0),lt(),ae(([,p])=>p.ranges)),e),{getState:u,restoreStateFrom:d}},at(gn,_t,Zr,Ln,Wi));function Qx(e){return{align:"start",index:0,offset:e.scrollTop}}const ev=Ye(([{topItemsIndexes:e}])=>{const t=Y(0);return ve(H(t,Ae(n=>n>=0),ae(n=>Array.from({length:n}).map((r,o)=>o))),e),{topItemCount:t}},at(rr));function iu(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const tv=iu(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),nv=Ye(([{deviation:e,scrollBy:t,scrollingInProgress:n,scrollTop:r},{isAtBottom:o,isScrolling:s,lastJumpDueToItemResize:i,scrollDirection:a},{listState:l},{beforeUnshiftWith:u,gap:d,shiftWithOffset:f,sizes:h},{log:p},{recalcInProgress:w}])=>{const x=Ft(H(l,$e(i),mn(([,v,b,S],[{bottom:N,items:C,offsetBottom:k,totalCount:I},A])=>{const j=N+k;let P=0;return b===I&&v.length>0&&C.length>0&&(C[0].originalIndex===0&&v[0].originalIndex===0||(P=j-S,P!==0&&(P+=A))),[P,C,I,j]},[0,[],0,0]),Ae(([v])=>v!==0),$e(r,a,n,o,p,w),Ae(([,v,b,S,,,N])=>!N&&!S&&v!==0&&b===Qr),ae(([[v],,,,,b])=>(b("Upward scrolling compensation",{amount:v},Dt.DEBUG),v))));function g(v){v>0?(Le(t,{behavior:"auto",top:-v}),Le(e,0)):(Le(e,0),Le(t,{behavior:"auto",top:-v}))}return Je(H(x,$e(e,s)),([v,b,S])=>{S&&tv()?Le(e,b-v):g(-v)}),Je(H(xt(Et(s,!1),e,w),Ae(([v,b,S])=>!v&&!S&&b!==0),ae(([v,b])=>b),In(1)),g),ve(H(f,ae(v=>({top:-v}))),t),Je(H(u,$e(h,d),ae(([v,{groupIndices:b,lastSize:S,sizeTree:N},C])=>{function k(I){return I*(S+C)}if(b.length===0)return k(v);{let I=0;const A=Gr(N,0);let j=0,P=0;for(;j<v;){j++,I+=A;let L=b.length===P+1?1/0:b[P+1]-b[P]-1;j+L>v&&(I-=A,L=v-j+1),j+=L,I+=k(L),P++}return I}})),v=>{Le(e,v),requestAnimationFrame(()=>{Le(t,{top:v}),requestAnimationFrame(()=>{Le(e,0),Le(w,!1)})})}),{deviation:e}},at(_t,to,rr,gn,Mn,Li)),rv=Ye(([e,t,n,r,o,s,i,a,l,u,d])=>({...e,...t,...n,...r,...o,...s,...i,...a,...l,...u,...d}),at(Hi,Xx,Ln,su,tu,Jx,qx,Wi,ru,Mn,nu)),au=Ye(([{data:e,defaultItemSize:t,firstItemIndex:n,fixedItemSize:r,gap:o,groupIndices:s,itemSize:i,sizeRanges:a,sizes:l,statefulTotalCount:u,totalCount:d,trackItemSizes:f},{initialItemFinalLocationReached:h,initialTopMostItemIndex:p,scrolledToInitialItem:w},x,g,v,{listState:b,topItemsIndexes:S,...N},{scrollToIndex:C},k,{topItemCount:I},{groupCounts:A},j])=>(ve(N.rangeChanged,j.scrollSeekRangeChanged),ve(H(j.windowViewportRect,ae(P=>P.visibleHeight)),x.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:n,fixedItemHeight:r,gap:o,groupCounts:A,initialItemFinalLocationReached:h,initialTopMostItemIndex:p,scrolledToInitialItem:w,sizeRanges:a,topItemCount:I,topItemsIndexes:S,totalCount:d,...v,groupIndices:s,itemSize:i,listState:b,scrollToIndex:C,statefulTotalCount:u,trackItemSizes:f,...N,...j,...x,sizes:l,...g}),at(gn,Zr,_t,Zx,Yx,rr,Jr,nv,ev,Kc,rv));function ov(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 Ko=typeof document<"u"?y.useLayoutEffect:y.useEffect;function lu(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=y.createContext({});function l(g,v){g.propsReady&&Le(g.propsReady,!1);for(const b of r){const S=g[t.required[b]];Le(S,v[b])}for(const b of o)if(b in v){const S=g[t.optional[b]];Le(S,v[b])}g.propsReady&&Le(g.propsReady,!0)}function u(g){return s.reduce((v,b)=>(v[b]=S=>{const N=g[t.methods[b]];Le(N,S)},v),{})}function d(g){return i.reduce((v,b)=>(v[b]=bx(g[t.events[b]]),v),{})}const f=y.forwardRef((g,v)=>{const{children:b,...S}=g,[N]=y.useState(()=>$o(Sx(e),I=>{l(I,S)})),[C]=y.useState(jc(d,N));Ko(()=>{for(const I of i)I in S&&Je(C[I],S[I]);return()=>{Object.values(C).map(_i)}},[S,C,N]),Ko(()=>{l(N,S)}),y.useImperativeHandle(v,Ac(u(N)));const k=n;return c.jsx(a.Provider,{value:N,children:n?c.jsx(k,{...ov([...r,...o,...i],S),children:b}):b})}),h=g=>{const v=y.useContext(a);return y.useCallback(b=>{Le(v[g],b)},[v,g])},p=g=>{const v=y.useContext(a)[g],b=y.useCallback(S=>Je(v,S),[v]);return y.useSyncExternalStore(b,()=>mt(v),()=>mt(v))},w=g=>{const v=y.useContext(a)[g],[b,S]=y.useState(jc(mt,v));return Ko(()=>Je(v,N=>{N!==b&&S(Ac(N))}),[v,b]),b},x=y.version.startsWith("18")?p:w;return{Component:f,useEmitter:(g,v)=>{const b=y.useContext(a)[g];Ko(()=>Je(b,v),[v,b])},useEmitterValue:x,usePublisher:h}}const cu=y.createContext(void 0),uu=y.createContext(void 0),du=typeof document<"u"?y.useLayoutEffect:y.useEffect;function Vi(e){return"self"in e}function sv(e){return"body"in e}function fu(e,t,n,r=Sr,o,s){const i=y.useRef(null),a=y.useRef(null),l=y.useRef(null),u=y.useCallback(h=>{let p,w,x;const g=h.target;if(sv(g)||Vi(g)){const b=Vi(g)?g:g.defaultView;x=s?b.scrollX:b.scrollY,p=s?b.document.documentElement.scrollWidth:b.document.documentElement.scrollHeight,w=s?b.innerWidth:b.innerHeight}else x=s?g.scrollLeft:g.scrollTop,p=s?g.scrollWidth:g.scrollHeight,w=s?g.offsetWidth:g.offsetHeight;const v=()=>{e({scrollHeight:p,scrollTop:Math.max(x,0),viewportHeight:w})};h.suppressFlushSync?v():ti.flushSync(v),a.current!==null&&(x===a.current||x<=0||x===p-w)&&(a.current=null,t(!0),l.current&&(clearTimeout(l.current),l.current=null))},[e,t,s]);y.useEffect(()=>{const h=o||i.current;return r(o||i.current),u({suppressFlushSync:!0,target:h}),h.addEventListener("scroll",u,{passive:!0}),()=>{r(null),h.removeEventListener("scroll",u)}},[i,u,n,r,o]);function d(h){const p=i.current;if(!p||(s?"offsetWidth"in p&&p.offsetWidth===0:"offsetHeight"in p&&p.offsetHeight===0))return;const w=h.behavior==="smooth";let x,g,v;Vi(p)?(g=Math.max(Dn(p.document.documentElement,s?"width":"height"),s?p.document.documentElement.scrollWidth:p.document.documentElement.scrollHeight),x=s?p.innerWidth:p.innerHeight,v=s?window.scrollX:window.scrollY):(g=p[s?"scrollWidth":"scrollHeight"],x=Dn(p,s?"width":"height"),v=p[s?"scrollLeft":"scrollTop"]);const b=g-x;if(h.top=Math.ceil(Math.max(Math.min(b,h.top),0)),Yc(x,g)||h.top===v){e({scrollHeight:g,scrollTop:v,viewportHeight:x}),w&&t(!0);return}w?(a.current=h.top,l.current&&clearTimeout(l.current),l.current=setTimeout(()=>{l.current=null,a.current=null,t(!0)},1e3)):a.current=null,s&&(h={behavior:h.behavior,left:h.top}),p.scrollTo(h)}function f(h){s&&(h={behavior:h.behavior,left:h.top}),i.current.scrollBy(h)}return{scrollByCallback:f,scrollerRef:i,scrollToCallback:d}}const qi="-webkit-sticky",hu="sticky",Ki=iu(()=>{if(typeof document>"u")return hu;const e=document.createElement("div");return e.style.position=qi,e.style.position===qi?qi:hu});function Gi(e){return e}const iv=Ye(()=>{const e=Y(a=>`Item ${a}`),t=Y(a=>`Group ${a}`),n=Y({}),r=Y(Gi),o=Y("div"),s=Y(Sr),i=(a,l=null)=>Et(H(n,ae(u=>u[a]),lt()),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")}}),av=Ye(([e,t])=>({...e,...t}),at(au,iv)),lv=({height:e})=>c.jsx("div",{style:{height:e}}),cv={overflowAnchor:"none",position:Ki(),zIndex:1},pu={overflowAnchor:"none"},uv={...pu,display:"inline-block",height:"100%"},mu=y.memo(function({showTopList:e=!1}){const t=Re("listState"),n=Kt("sizeRanges"),r=Re("useWindowScroll"),o=Re("customScrollParent"),s=Kt("windowScrollContainerState"),i=Kt("scrollContainerState"),a=o||r?s:i,l=Re("itemContent"),u=Re("context"),d=Re("groupContent"),f=Re("trackItemSizes"),h=Re("itemSize"),p=Re("log"),w=Kt("gap"),x=Re("horizontalDirection"),{callbackRef:g}=kx(n,h,f,e?Sr:a,p,w,o,x,Re("skipAnimationFrameInResizeObserver")),[v,b]=y.useState(0);Yi("deviation",M=>{v!==M&&b(M)});const S=Re("EmptyPlaceholder"),N=Re("ScrollSeekPlaceholder")||lv,C=Re("ListComponent"),k=Re("ItemComponent"),I=Re("GroupComponent"),A=Re("computeItemKey"),j=Re("isSeeking"),P=Re("groupIndices").length>0,L=Re("alignToBottom"),F=Re("initialItemFinalLocationReached"),V=e?{}:{boxSizing:"border-box",...x?{display:"inline-block",height:"100%",marginLeft:v!==0?v:L?"auto":0,paddingLeft:t.offsetTop,paddingRight:t.offsetBottom,whiteSpace:"nowrap"}:{marginTop:v!==0?v:L?"auto":0,paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},...F?{}:{visibility:"hidden"}};return!e&&t.totalCount===0&&S?c.jsx(S,{...It(S,u)}):c.jsx(C,{...It(C,u),"data-testid":e?"virtuoso-top-item-list":"virtuoso-item-list",ref:g,style:V,children:(e?t.topItems:t.items).map(M=>{const G=M.originalIndex,q=A(G+t.firstItemIndex,M.data,u);return j?y.createElement(N,{...It(N,u),height:M.size,index:M.index,key:q,type:M.type||"item",...M.type==="group"?{}:{groupIndex:M.groupIndex}}):M.type==="group"?y.createElement(I,{...It(I,u),"data-index":G,"data-item-index":M.index,"data-known-size":M.size,key:q,style:cv},d(M.index,u)):y.createElement(k,{...It(k,u),...pv(k,M.data),"data-index":G,"data-item-group-index":M.groupIndex,"data-item-index":M.index,"data-known-size":M.size,key:q,style:x?uv:pu},P?l(M.index,M.groupIndex,M.data,u):l(M.index,M.data,u))})})}),dv={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},fv={outline:"none",overflowX:"auto",position:"relative"},Go=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),hv={position:Ki(),top:0,width:"100%",zIndex:1};function It(e,t){if(typeof e!="string")return{context:t}}function pv(e,t){return{item:typeof e=="string"?void 0:t}}const mv=y.memo(function(){const e=Re("HeaderComponent"),t=Kt("headerHeight"),n=Re("HeaderFooterTag"),r=tr(y.useMemo(()=>s=>{t(Dn(s,"height"))},[t]),!0,Re("skipAnimationFrameInResizeObserver")),o=Re("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...It(e,o)})}):null}),gv=y.memo(function(){const e=Re("FooterComponent"),t=Kt("footerHeight"),n=Re("HeaderFooterTag"),r=tr(y.useMemo(()=>s=>{t(Dn(s,"height"))},[t]),!0,Re("skipAnimationFrameInResizeObserver")),o=Re("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...It(e,o)})}):null});function gu({useEmitter:e,useEmitterValue:t,usePublisher:n}){return y.memo(function({children:r,style:o,context:s,...i}){const a=n("scrollContainerState"),l=t("ScrollerComponent"),u=n("smoothScrollTargetReached"),d=t("scrollerRef"),f=t("horizontalDirection")||!1,{scrollByCallback:h,scrollerRef:p,scrollToCallback:w}=fu(a,u,l,d,void 0,f);return e("scrollTo",w),e("scrollBy",h),c.jsx(l,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:p,style:{...f?fv:dv,...o},tabIndex:0,...i,...It(l,s),children:r})})}function xu({useEmitter:e,useEmitterValue:t,usePublisher:n}){return y.memo(function({children:r,style:o,context:s,...i}){const a=n("windowScrollContainerState"),l=t("ScrollerComponent"),u=n("smoothScrollTargetReached"),d=t("totalListHeight"),f=t("deviation"),h=t("customScrollParent"),p=y.useRef(null),w=t("scrollerRef"),{scrollByCallback:x,scrollerRef:g,scrollToCallback:v}=fu(a,u,l,w,h);return du(()=>{var b;return g.current=h||((b=p.current)==null?void 0:b.ownerDocument.defaultView),()=>{g.current=null}},[g,h]),e("windowScrollTo",v),e("scrollBy",x),c.jsx(l,{ref:p,"data-virtuoso-scroller":!0,style:{position:"relative",...o,...d!==0?{height:d+f}:{}},...i,...It(l,s),children:r})})}const xv=({children:e})=>{const t=y.useContext(cu),n=Kt("viewportHeight"),r=Kt("fixedItemHeight"),o=Re("alignToBottom"),s=Re("horizontalDirection"),i=y.useMemo(()=>_c(n,l=>Dn(l,s?"width":"height")),[n,s]),a=tr(i,!0,Re("skipAnimationFrameInResizeObserver"));return y.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),c.jsx("div",{"data-viewport-type":"element",ref:a,style:Go(o),children:e})},vv=({children:e})=>{const t=y.useContext(cu),n=Kt("windowViewportRect"),r=Kt("fixedItemHeight"),o=Re("customScrollParent"),s=Mc(n,o,Re("skipAnimationFrameInResizeObserver")),i=Re("alignToBottom");return y.useEffect(()=>{t&&(r(t.itemHeight),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:100}))},[t,n,r]),c.jsx("div",{"data-viewport-type":"window",ref:s,style:Go(i),children:e})},wv=({children:e})=>{const t=Re("TopItemListComponent")||"div",n=Re("headerHeight"),r={...hv,marginTop:`${n}px`},o=Re("context");return c.jsx(t,{style:r,...It(t,o),children:e})},bv=y.memo(function(e){const t=Re("useWindowScroll"),n=Re("topItemsIndexes").length>0,r=Re("customScrollParent"),o=Re("context");return c.jsxs(r||t?Cv:Sv,{...e,context:o,children:[n&&c.jsx(wv,{children:c.jsx(mu,{showTopList:!0})}),c.jsxs(r||t?vv:xv,{children:[c.jsx(mv,{}),c.jsx(mu,{}),c.jsx(gv,{})]})]})}),{Component:yv,useEmitter:Yi,useEmitterValue:Re,usePublisher:Kt}=lu(av,{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"}},bv),Sv=gu({useEmitter:Yi,useEmitterValue:Re,usePublisher:Kt}),Cv=xu({useEmitter:Yi,useEmitterValue:Re,usePublisher:Kt}),Tv=yv;at(au,Ye(()=>{const e=Y(u=>c.jsxs("td",{children:["Item $",u]})),t=Y(null),n=Y(u=>c.jsxs("td",{colSpan:1e3,children:["Group ",u]})),r=Y(null),o=Y(null),s=Y({}),i=Y(Gi),a=Y(Sr),l=(u,d=null)=>Et(H(s,ae(f=>f[u]),lt()),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")}})),Ki();const vu={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},kv={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:wu,floor:Yo,max:no,min:Xi,round:bu}=Math;function yu(e,t,n){return Array.from({length:t-e+1}).map((r,o)=>({data:n===null?null:n[o+e],index:o+e}))}function Ev(e){return{...kv,items:e}}function Xo(e,t){return e&&e.width===t.width&&e.height===t.height}function Iv(e,t){return e&&e.column===t.column&&e.row===t.row}const Nv=Ye(([{increaseViewportBy:e,listBoundary:t,overscan:n,visibleRange:r},{footerHeight:o,headerHeight:s,scrollBy:i,scrollContainerState:a,scrollTo:l,scrollTop:u,smoothScrollTargetReached:d,viewportHeight:f},h,p,{didMount:w,propsReady:x},{customScrollParent:g,useWindowScroll:v,windowScrollContainerState:b,windowScrollTo:S,windowViewportRect:N},C])=>{const k=Y(0),I=Y(0),A=Y(vu),j=Y({height:0,width:0}),P=Y({height:0,width:0}),L=qe(),F=qe(),V=Y(0),M=Y(null),G=Y({column:0,row:0}),q=qe(),U=qe(),B=Y(!1),$=Y(0),ce=Y(!0),D=Y(!1),Q=Y(!1);Je(H(w,$e($),Ae(([O,X])=>!!X)),()=>{Le(ce,!1)}),Je(H(xt(w,ce,P,j,$,D),Ae(([O,X,ee,fe,,ne])=>O&&!X&&ee.height!==0&&fe.height!==0&&!ne)),([,,,,O])=>{Le(D,!0),Bi(1,()=>{Le(L,O)}),on(H(u),()=>{Le(t,[0,0]),Le(ce,!0)})}),ve(H(U,Ae(O=>O!=null&&O.scrollTop>0),pn(0)),I),Je(H(w,$e(U),Ae(([,O])=>O!=null)),([,O])=>{O&&(Le(j,O.viewport),Le(P,O.item),Le(G,O.gap),O.scrollTop>0&&(Le(B,!0),on(H(u,er(1)),X=>{Le(B,!1)}),Le(l,{top:O.scrollTop})))}),ve(H(j,ae(({height:O})=>O)),f),ve(H(xt(Ne(j,Xo),Ne(P,Xo),Ne(G,(O,X)=>O&&O.column===X.column&&O.row===X.row),Ne(u)),ae(([O,X,ee,fe])=>({gap:ee,item:X,scrollTop:fe,viewport:O}))),q),ve(H(xt(Ne(k),r,Ne(G,Iv),Ne(P,Xo),Ne(j,Xo),Ne(M),Ne(I),Ne(B),Ne(ce),Ne($)),Ae(([,,,,,,,O])=>!O),ae(([O,[X,ee],fe,ne,pe,Ze,Qe,,Pe,He])=>{const{column:ct,row:tt}=fe,{height:Be,width:gt}=ne,{width:J}=pe;if(Qe===0&&(O===0||J===0))return vu;if(gt===0){const vt=zi(He,O),Zt=vt+Math.max(Qe-1,0);return Ev(yu(vt,Zt,Ze))}const re=Su(J,gt,ct);let he,Ce;Pe?X===0&&ee===0&&Qe>0?(he=0,Ce=Qe-1):(he=re*Yo((X+tt)/(Be+tt)),Ce=re*wu((ee+tt)/(Be+tt))-1,Ce=Xi(O-1,no(Ce,re-1)),he=Xi(Ce,no(0,he))):(he=0,Ce=-1);const me=yu(he,Ce,Ze),{bottom:Oe,top:it}=Cu(pe,fe,ne,me),Me=wu(O/re),et=Me*Be+(Me-1)*tt-Oe;return{bottom:Oe,itemHeight:Be,items:me,itemWidth:gt,offsetBottom:et,offsetTop:it,top:it}})),A),ve(H(M,Ae(O=>O!==null),ae(O=>O.length)),k),ve(H(xt(j,P,A,G),Ae(([O,X,{items:ee}])=>ee.length>0&&X.height!==0&&O.height!==0),ae(([O,X,{items:ee},fe])=>{const{bottom:ne,top:pe}=Cu(O,fe,X,ee);return[pe,ne]}),lt(Yr)),t);const de=Y(!1);ve(H(u,$e(de),ae(([O,X])=>X||O!==0)),de);const we=Ft(H(xt(A,k),Ae(([{items:O}])=>O.length>0),$e(de),Ae(([[O,X],ee])=>{const fe=O.items[O.items.length-1].index===X-1;return(ee||O.bottom>0&&O.itemHeight>0&&O.offsetBottom===0&&O.items.length===X)&&fe}),ae(([[,O]])=>O-1),lt())),ye=Ft(H(Ne(A),Ae(({items:O})=>O.length>0&&O[0].index===0),pn(0),lt())),Se=Ft(H(Ne(A),$e(B),Ae(([{items:O},X])=>O.length>0&&!X),ae(([{items:O}])=>({endIndex:O[O.length-1].index,startIndex:O[0].index})),lt(Hc),In(0)));ve(Se,p.scrollSeekRangeChanged),ve(H(L,$e(j,P,k,G),ae(([O,X,ee,fe,ne])=>{const pe=Gc(O),{align:Ze,behavior:Qe,offset:Pe}=pe;let He=pe.index;He==="LAST"&&(He=fe-1),He=no(0,He,Xi(fe-1,He));let ct=Ji(X,ne,ee,He);return Ze==="end"?ct=bu(ct-X.height+ee.height):Ze==="center"&&(ct=bu(ct-X.height/2+ee.height/2)),Pe&&(ct+=Pe),{behavior:Qe,top:ct}})),l);const K=Et(H(A,ae(O=>O.offsetBottom+O.bottom)),0);return ve(H(N,ae(O=>({height:O.visibleHeight,width:O.visibleWidth}))),j),{customScrollParent:g,data:M,deviation:V,footerHeight:o,gap:G,headerHeight:s,increaseViewportBy:e,initialItemCount:I,itemDimensions:P,overscan:n,restoreStateFrom:U,scrollBy:i,scrollContainerState:a,scrollHeight:F,scrollTo:l,scrollToIndex:L,scrollTop:u,smoothScrollTargetReached:d,totalCount:k,useWindowScroll:v,viewportDimensions:j,windowScrollContainerState:b,windowScrollTo:S,windowViewportRect:N,...p,gridState:A,horizontalDirection:Q,initialTopMostItemIndex:$,totalListHeight:K,...h,endReached:we,propsReady:x,rangeChanged:Se,startReached:ye,stateChanged:q,stateRestoreInProgress:B,...C}},at(Hi,_t,to,su,Ln,Wi,Mn));function Su(e,t,n){return no(1,Yo((e+n)/(Yo(t)+n)))}function Cu(e,t,n,r){const{height:o}=n;if(o===void 0||r.length===0)return{bottom:0,top:0};const s=Ji(e,t,n,r[0].index);return{bottom:Ji(e,t,n,r[r.length-1].index)+o,top:s}}function Ji(e,t,n,r){const o=Su(e.width,n.width,t.column),s=Yo(r/o),i=s*n.height+no(0,s-1)*t.row;return i>0?i+t.row:i}const Av=Ye(()=>{const e=Y(f=>`Item ${f}`),t=Y({}),n=Y(null),r=Y("virtuoso-grid-item"),o=Y("virtuoso-grid-list"),s=Y(Gi),i=Y("div"),a=Y(Sr),l=(f,h=null)=>Et(H(t,ae(p=>p[f]),lt()),h),u=Y(!1),d=Y(!1);return ve(Ne(d),u),{components:t,computeItemKey:s,context:n,FooterComponent:l("Footer"),HeaderComponent:l("Header"),headerFooterTag:i,itemClassName:r,ItemComponent:l("Item","div"),itemContent:e,listClassName:o,ListComponent:l("List","div"),readyStateChanged:u,reportReadyState:d,ScrollerComponent:l("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder","div")}}),_v=Ye(([e,t])=>({...e,...t}),at(Nv,Av)),jv=y.memo(function(){const e=dt("gridState"),t=dt("listClassName"),n=dt("itemClassName"),r=dt("itemContent"),o=dt("computeItemKey"),s=dt("isSeeking"),i=Gt("scrollHeight"),a=dt("ItemComponent"),l=dt("ListComponent"),u=dt("ScrollSeekPlaceholder"),d=dt("context"),f=Gt("itemDimensions"),h=Gt("gap"),p=dt("log"),w=dt("stateRestoreInProgress"),x=Gt("reportReadyState"),g=tr(y.useMemo(()=>v=>{const b=v.parentElement.parentElement.scrollHeight;i(b);const S=v.firstChild;if(S){const{height:N,width:C}=S.getBoundingClientRect();f({height:N,width:C})}h({column:ku("column-gap",getComputedStyle(v).columnGap,p),row:ku("row-gap",getComputedStyle(v).rowGap,p)})},[i,f,h,p]),!0,!1);return du(()=>{e.itemHeight>0&&e.itemWidth>0&&x(!0)},[e]),w?null:c.jsx(l,{className:t,ref:g,...It(l,d),"data-testid":"virtuoso-item-list",style:{paddingBottom:e.offsetBottom,paddingTop:e.offsetTop},children:e.items.map(v=>{const b=o(v.index,v.data,d);return s?c.jsx(u,{...It(u,d),height:e.itemHeight,index:v.index,width:e.itemWidth},b):y.createElement(a,{...It(a,d),className:n,"data-index":v.index,key:b},r(v.index,v.data,d))})})}),Rv=y.memo(function(){const e=dt("HeaderComponent"),t=Gt("headerHeight"),n=dt("headerFooterTag"),r=tr(y.useMemo(()=>s=>{t(Dn(s,"height"))},[t]),!0,!1),o=dt("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...It(e,o)})}):null}),Pv=y.memo(function(){const e=dt("FooterComponent"),t=Gt("footerHeight"),n=dt("headerFooterTag"),r=tr(y.useMemo(()=>s=>{t(Dn(s,"height"))},[t]),!0,!1),o=dt("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...It(e,o)})}):null}),Ov=({children:e})=>{const t=y.useContext(uu),n=Gt("itemDimensions"),r=Gt("viewportDimensions"),o=tr(y.useMemo(()=>s=>{r(s.getBoundingClientRect())},[r]),!0,!1);return y.useEffect(()=>{t&&(r({height:t.viewportHeight,width:t.viewportWidth}),n({height:t.itemHeight,width:t.itemWidth}))},[t,r,n]),c.jsx("div",{ref:o,style:Go(!1),children:e})},Mv=({children:e})=>{const t=y.useContext(uu),n=Gt("windowViewportRect"),r=Gt("itemDimensions"),o=dt("customScrollParent"),s=Mc(n,o,!1);return y.useEffect(()=>{t&&(r({height:t.itemHeight,width:t.itemWidth}),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:t.viewportWidth}))},[t,n,r]),c.jsx("div",{ref:s,style:Go(!1),children:e})},Dv=y.memo(function({...e}){const t=dt("useWindowScroll"),n=dt("customScrollParent"),r=n||t?Fv:Lv,o=n||t?Mv:Ov,s=dt("context");return c.jsx(r,{...e,...It(r,s),children:c.jsxs(o,{children:[c.jsx(Rv,{}),c.jsx(jv,{}),c.jsx(Pv,{})]})})}),{useEmitter:Tu,useEmitterValue:dt,usePublisher:Gt}=lu(_v,{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"}},Dv),Lv=gu({useEmitter:Tu,useEmitterValue:dt,usePublisher:Gt}),Fv=xu({useEmitter:Tu,useEmitterValue:dt,usePublisher:Gt});function ku(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Dt.WARN),t==="normal"?0:parseInt(t??"0",10)}const $v=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 Zi({className:e,variant:t,...n}){return c.jsx("div",{className:Z($v({variant:t}),e),...n})}function ue(e,t,{checkForDefaultPrevented:n=!0}={}){return function(o){if(e==null||e(o),n===!1||!o.defaultPrevented)return t==null?void 0:t(o)}}function Bv(e,t){const n=m.createContext(t),r=s=>{const{children:i,...a}=s,l=m.useMemo(()=>a,Object.values(a));return c.jsx(n.Provider,{value:l,children:i})};r.displayName=e+"Provider";function o(s){const i=m.useContext(n);if(i)return i;if(t!==void 0)return t;throw new Error(`\`${s}\` must be used within \`${e}\``)}return[r,o]}function xn(e,t=[]){let n=[];function r(s,i){const a=m.createContext(i),l=n.length;n=[...n,i];const u=f=>{var v;const{scope:h,children:p,...w}=f,x=((v=h==null?void 0:h[e])==null?void 0:v[l])||a,g=m.useMemo(()=>w,Object.values(w));return c.jsx(x.Provider,{value:g,children:p})};u.displayName=s+"Provider";function d(f,h){var x;const p=((x=h==null?void 0:h[e])==null?void 0:x[l])||a,w=m.useContext(p);if(w)return w;if(i!==void 0)return i;throw new Error(`\`${f}\` must be used within \`${s}\``)}return[u,d]}const o=()=>{const s=n.map(i=>m.createContext(i));return function(a){const l=(a==null?void 0:a[e])||s;return m.useMemo(()=>({[`__scope${e}`]:{...a,[e]:l}}),[a,l])}};return o.scopeName=e,[r,zv(o,...t)]}function zv(...e){const t=e[0];if(e.length===1)return t;const n=()=>{const r=e.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(s){const i=r.reduce((a,{useScope:l,scopeName:u})=>{const f=l(s)[`__scope${u}`];return{...a,...f}},{});return m.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}var Ct=globalThis!=null&&globalThis.document?m.useLayoutEffect:()=>{},Hv=m[" useInsertionEffect ".trim().toString()]||Ct;function or({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=Uv({defaultProp:t,onChange:n}),a=e!==void 0,l=a?e:o;{const d=m.useRef(e!==void 0);m.useEffect(()=>{const f=d.current;f!==a&&console.warn(`${r} is changing from ${f?"controlled":"uncontrolled"} to ${a?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),d.current=a},[a,r])}const u=m.useCallback(d=>{var f;if(a){const h=Wv(d)?d(e):d;h!==e&&((f=i.current)==null||f.call(i,h))}else s(d)},[a,e,s,i]);return[l,u]}function Uv({defaultProp:e,onChange:t}){const[n,r]=m.useState(e),o=m.useRef(n),s=m.useRef(t);return Hv(()=>{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 Wv(e){return typeof e=="function"}function Eu(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function Qi(...e){return t=>{let n=!1;const r=e.map(o=>{const s=Eu(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():Eu(e[o],null)}}}}function Ve(...e){return m.useCallback(Qi(...e),e)}var Vv=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],_e=Vv.reduce((e,t)=>{const n=Xn.createSlot(`Primitive.${t}`),r=m.forwardRef((o,s)=>{const{asChild:i,...a}=o,l=i?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),c.jsx(l,{...a,ref:s})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function Iu(e,t){e&&yo.flushSync(()=>e.dispatchEvent(t))}function qv(e,t){return m.useReducer((n,r)=>t[n][r]??n,e)}var Bt=e=>{const{present:t,children:n}=e,r=Kv(t),o=typeof n=="function"?n({present:r.isPresent}):m.Children.only(n),s=Ve(r.ref,Gv(o));return typeof n=="function"||r.isPresent?m.cloneElement(o,{ref:s}):null};Bt.displayName="Presence";function Kv(e){const[t,n]=m.useState(),r=m.useRef(null),o=m.useRef(e),s=m.useRef("none"),i=e?"mounted":"unmounted",[a,l]=qv(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return m.useEffect(()=>{const u=Jo(r.current);s.current=a==="mounted"?u:"none"},[a]),Ct(()=>{const u=r.current,d=o.current;if(d!==e){const h=s.current,p=Jo(u);e?l("MOUNT"):p==="none"||(u==null?void 0:u.display)==="none"?l("UNMOUNT"):l(d&&h!==p?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,l]),Ct(()=>{if(t){let u;const d=t.ownerDocument.defaultView??window,f=p=>{const x=Jo(r.current).includes(CSS.escape(p.animationName));if(p.target===t&&x&&(l("ANIMATION_END"),!o.current)){const g=t.style.animationFillMode;t.style.animationFillMode="forwards",u=d.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=g)})}},h=p=>{p.target===t&&(s.current=Jo(r.current))};return t.addEventListener("animationstart",h),t.addEventListener("animationcancel",f),t.addEventListener("animationend",f),()=>{d.clearTimeout(u),t.removeEventListener("animationstart",h),t.removeEventListener("animationcancel",f),t.removeEventListener("animationend",f)}}else l("ANIMATION_END")},[t,l]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:m.useCallback(u=>{r.current=u?getComputedStyle(u):null,n(u)},[])}}function Jo(e){return(e==null?void 0:e.animationName)||"none"}function Gv(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 Yv=m[" useId ".trim().toString()]||(()=>{}),Xv=0;function vn(e){const[t,n]=m.useState(Yv());return Ct(()=>{n(r=>r??String(Xv++))},[e]),e||(t?`radix-${t}`:"")}var Zo="Collapsible",[Jv,OT]=xn(Zo),[Zv,ea]=Jv(Zo),Nu=m.forwardRef((e,t)=>{const{__scopeCollapsible:n,open:r,defaultOpen:o,disabled:s,onOpenChange:i,...a}=e,[l,u]=or({prop:r,defaultProp:o??!1,onChange:i,caller:Zo});return c.jsx(Zv,{scope:n,disabled:s,contentId:vn(),open:l,onOpenToggle:m.useCallback(()=>u(d=>!d),[u]),children:c.jsx(_e.div,{"data-state":na(l),"data-disabled":s?"":void 0,...a,ref:t})})});Nu.displayName=Zo;var Au="CollapsibleTrigger",_u=m.forwardRef((e,t)=>{const{__scopeCollapsible:n,...r}=e,o=ea(Au,n);return c.jsx(_e.button,{type:"button","aria-controls":o.contentId,"aria-expanded":o.open||!1,"data-state":na(o.open),"data-disabled":o.disabled?"":void 0,disabled:o.disabled,...r,ref:t,onClick:ue(e.onClick,o.onOpenToggle)})});_u.displayName=Au;var ta="CollapsibleContent",Qv=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=ea(ta,e.__scopeCollapsible);return c.jsx(Bt,{present:n||o.open,children:({present:s})=>c.jsx(ew,{...r,ref:t,present:s})})});Qv.displayName=ta;var ew=m.forwardRef((e,t)=>{const{__scopeCollapsible:n,present:r,children:o,...s}=e,i=ea(ta,n),[a,l]=m.useState(r),u=m.useRef(null),d=Ve(t,u),f=m.useRef(0),h=f.current,p=m.useRef(0),w=p.current,x=i.open||a,g=m.useRef(x),v=m.useRef(void 0);return m.useEffect(()=>{const b=requestAnimationFrame(()=>g.current=!1);return()=>cancelAnimationFrame(b)},[]),Ct(()=>{const b=u.current;if(b){v.current=v.current||{transitionDuration:b.style.transitionDuration,animationName:b.style.animationName},b.style.transitionDuration="0s",b.style.animationName="none";const S=b.getBoundingClientRect();f.current=S.height,p.current=S.width,g.current||(b.style.transitionDuration=v.current.transitionDuration,b.style.animationName=v.current.animationName),l(r)}},[i.open,r]),c.jsx(_e.div,{"data-state":na(i.open),"data-disabled":i.disabled?"":void 0,id:i.contentId,hidden:!x,...s,ref:d,style:{"--radix-collapsible-content-height":h?`${h}px`:void 0,"--radix-collapsible-content-width":w?`${w}px`:void 0,...e.style},children:x&&o})});function na(e){return e?"open":"closed"}var tw=Nu;const ju=tw,Ru=_u,ro=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:Z("rounded-lg border bg-card text-card-foreground shadow-sm",e),...t}));ro.displayName="Card";const oo=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:Z("flex flex-col space-y-1.5 p-6",e),...t}));oo.displayName="CardHeader";const so=m.forwardRef(({className:e,...t},n)=>c.jsx("h3",{ref:n,className:Z("text-2xl font-semibold leading-none tracking-tight",e),...t}));so.displayName="CardTitle";const Pu=m.forwardRef(({className:e,...t},n)=>c.jsx("p",{ref:n,className:Z("text-sm text-muted-foreground",e),...t}));Pu.displayName="CardDescription";const Qo=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:Z("p-6 pt-0",e),...t}));Qo.displayName="CardContent";const Ou=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:Z("flex items-center p-6 pt-0",e),...t}));Ou.displayName="CardFooter";function Mu(){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 sr=Mu();function nw(e){sr=e}const Du=/[&<>"']/,rw=new RegExp(Du.source,"g"),Lu=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,ow=new RegExp(Lu.source,"g"),sw={"&":"&","<":"<",">":">",'"':""","'":"'"},Fu=e=>sw[e];function Nt(e,t){if(t){if(Du.test(e))return e.replace(rw,Fu)}else if(Lu.test(e))return e.replace(ow,Fu);return e}const iw=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;function $u(e){return e.replace(iw,(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 aw=/(^|[^\[])\^/g;function rt(e,t){e=typeof e=="string"?e:e.source,t=t||"";const n={replace:(r,o)=>(o=o.source||o,o=o.replace(aw,"$1"),e=e.replace(r,o),n),getRegex:()=>new RegExp(e,t)};return n}const lw=/[^\w:]/g,cw=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function Bu(e,t,n){if(e){let r;try{r=decodeURIComponent($u(n)).replace(lw,"").toLowerCase()}catch{return null}if(r.indexOf("javascript:")===0||r.indexOf("vbscript:")===0||r.indexOf("data:")===0)return null}t&&!cw.test(n)&&(n=hw(t,n));try{n=encodeURI(n).replace(/%25/g,"%")}catch{return null}return n}const es={},uw=/^[^:]+:\/*[^/]*$/,dw=/^([^:]+:)[\s\S]*$/,fw=/^([^:]+:\/*[^/]*)[\s\S]*$/;function hw(e,t){es[" "+e]||(uw.test(e)?es[" "+e]=e+"/":es[" "+e]=ns(e,"/",!0)),e=es[" "+e];const n=e.indexOf(":")===-1;return t.substring(0,2)==="//"?n?t:e.replace(dw,"$1")+t:t.charAt(0)==="/"?n?t:e.replace(fw,"$1")+t:e+t}const ts={exec:function(){}};function zu(e,t){const n=e.replace(/\|/g,(s,i,a)=>{let l=!1,u=i;for(;--u>=0&&a[u]==="\\";)l=!l;return l?"|":" |"}),r=n.split(/ \|/);let o=0;if(r[0].trim()||r.shift(),r.length>0&&!r[r.length-1].trim()&&r.pop(),r.length>t)r.splice(t);else for(;r.length<t;)r.push("");for(;o<r.length;o++)r[o]=r[o].trim().replace(/\\\|/g,"|");return r}function ns(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 pw(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 mw(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 Hu(e,t){if(t<1)return"";let n="";for(;t>1;)t&1&&(n+=e),t>>=1,e+=e;return n+e}function Uu(e,t,n,r){const o=t.href,s=t.title?Nt(t.title):null,i=e[1].replace(/\\([\[\]])/g,"$1");if(e[0].charAt(0)!=="!"){r.state.inLink=!0;const a={type:"link",raw:n,href:o,title:s,text:i,tokens:r.inlineTokens(i)};return r.state.inLink=!1,a}return{type:"image",raw:n,href:o,title:s,text:Nt(i)}}function gw(e,t){const n=e.match(/^(\s+)(?:```)/);if(n===null)return t;const r=n[1];return t.split(`
|
|
37
|
+
`))>=0;){const oe=q.slice(0,Z);q=q.slice(Z+2);const me=cx(oe);if(!me)continue;let Te;try{Te=JSON.parse(me)}catch{console.debug("[use-chat] malformed SSE:",me.slice(0,200));continue}const ge=lx(Te)?Te.data:Te;pe=Date.now();const Oe=ge.seq;if(Oe!==void 0){if(Oe<=X){console.debug("[use-chat] drop duplicate/out-of-order event",{seq:Oe,lastProcessedSeq:X,type:ge.type});continue}X>0&&Oe>X+1&&((F=$==null?void 0:$.onGap)==null||F.call($,{from:X,to:Oe})),X=Oe,T.current=Oe,g(Oe)}if(console.debug("[use-chat] received event",{seq:ge.seq,type:ge.type,preview:(()=>{var at;try{return ge.type==="message_delta"?{deltaTypes:(at=ge.delta)==null?void 0:at.map(Me=>Me.type),textLen:(ge.delta||[]).filter(Me=>Me.type==="text").map(Me=>String(Me.text||"").length)}:ge.content||ge.delta?{hasContent:!0}:{}}catch(Me){return{err:String(Me)}}})()}),L==null||L(ge),ge.type==="token"&&e.autoAppendAssistant!==!1)O.push(ge.content),re();else if(ge.type==="message_delta"){const at=ge.delta.filter(Me=>Me.type==="text").map(Me=>Me.text).join("");at&&e.autoAppendAssistant!==!1&&(O.push(at),re())}else ge.type==="heartbeat"?console.debug("[use-chat] heartbeat received"):(te!==null&&cancelAnimationFrame(te),he(),ge.type==="checkpoint"?b(ge.checkpointId):ge.type==="error"&&d(ge.message))}}he()}catch(Pe){if(Pe.name!=="AbortError"){const He=Pe.message||String(Pe);d(He),(ue=$==null?void 0:$.onError)==null||ue.call($,He)}}finally{try{await ye.cancel()}catch{}finally{(D=ye.releaseLock)==null||D.call(ye)}te!==null&&typeof window<"u"&&window.cancelAnimationFrame(te),clearInterval(tt),l(!1),w(!1),S.current=null,T.current=0,g(0)}}catch(fe){if(fe.name!=="AbortError"){const we=fe.message||String(fe);d(we),(ee=$==null?void 0:$.onError)==null||ee.call($,we)}}finally{l(!1),w(!1),S.current=null,T.current=0,g(0)}})(),{close:()=>V.abort()}},[t,n,r,e.autoAppendAssistant]);return y.useEffect(()=>()=>{var P;N.current=!1,(P=S.current)==null||P.abort()},[]),{isStreaming:a,error:u,assistantText:f,lastCheckpointId:p,lastSeq:x,connected:v,stream:j,stop:E,clear:A,setToken:k}}function lx(e){return!!e&&typeof e=="object"&&e.protocolVersion==="v1"&&"data"in e}function cx(e){const t=e.split(/\r?\n/),n=[];for(const r of t)if(r&&!r.startsWith(":")&&r.startsWith("data:")){const o=r.slice(5);n.push(o.startsWith(" ")?o.slice(1):o)}return n.length===0?null:n.join(`
|
|
38
|
+
`)}function ux({baseUrl:e,onThreadInfo:t,onMessageEvent:n,onUnhandledEvent:r,onSequenceGap:o}){const s=y.useRef(null),i=y.useCallback(p=>{const b=p.seq??null;if(b!==null){const x=s.current;if(x!==null){if(b<=x)return;b>x+1&&(o==null||o({from:x,to:b}))}s.current=b}if(p.type==="thread_info"){console.log("[useChatStreamingService] 🎯 Received thread_info event:",p),t(p);return}if(nx(p)){n(p);return}r==null||r(p)},[n,o,t,r]),{stream:a,stop:l,isStreaming:u,error:d,setToken:f}=kc({baseUrl:e,token:null}),h=y.useCallback((p,b)=>{s.current=null,a(p,i,{onOpen:b==null?void 0:b.onOpen,onError:x=>{var g;(g=b==null?void 0:b.onError)==null||g.call(b,x)},onGap:(b==null?void 0:b.onGap)??o})},[i,o,a]);return y.useMemo(()=>({startStream:h,stop:l,isStreaming:u,error:d,setAuthToken:f}),[h,l,u,d,f])}const Ic=y.createContext(null),Ec=y.createContext(null),Nc=y.createContext(null),dx=y.createContext(!1),fx="cachedThreads",hx="v1",$o=300,Ei=200;function px(e,t){if(!e&&!t)return!0;if(!e||!t||e.id!==t.id)return!1;try{return JSON.stringify(e.value)===JSON.stringify(t.value)}catch{return e.value===t.value}}function mx(e){var t;for(let n=e.length-1;n>=0;n--){const r=((t=e[n])==null?void 0:t.content)??[];for(let o=r.length-1;o>=0;o--){const s=r[o];if((s==null?void 0:s.type)==="interrupt"){const i=s.id;return{id:(typeof i=="string"?i:null)??`interrupt-${e[n].id??o}`,value:s.value}}}}return null}function Ac(e){if(typeof window<"u"&&"requestIdleCallback"in window)try{window.requestIdleCallback(e,{timeout:1e3});return}catch{}window.setTimeout(e,$o)}function kr(){return typeof window<"u"&&typeof window.localStorage<"u"}function Ni(e){if(!kr())return null;try{return window.localStorage.getItem(e)}catch{return null}}function _c(e,t){if(kr())try{window.localStorage.setItem(e,t)}catch{}}function Ai(e){if(kr())try{window.localStorage.removeItem(e)}catch{}}function gx(){const e=Ni(fx);if(!e)return[];try{const t=JSON.parse(e);return Array.isArray(t)?t.filter(n=>{if(!n||typeof n!="object")return!1;const r=n;return typeof r.threadId=="string"&&typeof r.title=="string"}):[]}catch{return[]}}function xx(e){let t=5381;for(let n=0;n<e.length;n++)t=(t<<5)+t^e.charCodeAt(n);return(t>>>0).toString(36)}function _i(e,t){return`cachedThreads:v1:${e}:${xx(t||"anon")}`}function vx(e){const t=Ni(e);if(!t)return[];try{const n=JSON.parse(t);return Array.isArray(n)?n.filter(r=>{if(!r||typeof r!="object")return!1;const o=r;return typeof o.threadId=="string"&&typeof o.title=="string"}):[]}catch{return[]}}function ji(e,t){try{_c(e,JSON.stringify(t))}catch{}}function Ri(e){const t=vx(e);if(t.length>0)return t;const n=gx();if(n.length>0)try{ji(e,n.slice(0,Ei))}catch{}return n}function Fo(e){const t={},n=[];for(const r of e)!r||typeof r.threadId!="string"||t[r.threadId]||(t[r.threadId]=r,n.push(r.threadId));return{byId:t,order:n}}function Pi(e){return e.order.map(t=>e.byId[t]).filter(Boolean)}function bx({children:e,initialThreadId:t=null,autoLoadInitial:n=!0,disableAutoRestore:r=!1,enableFileAgentRouting:o=!1,fileAgentId:s="invoice_reader",onError:i,onThreadChange:a}){const{api:l,baseUrl:u}=Si(),d=y.useMemo(()=>An(u),[u]),f=y.useMemo(()=>{try{return new URL(u).host}catch{return"unknown"}},[u]),h=y.useMemo(()=>`threadPayload:${hx}:${f}:`,[f]),p=y.useCallback(C=>`${h}${C}`,[h]),b=y.useCallback(C=>{if(!C||typeof C!="object")return null;const _=C;return typeof _.threadId!="string"||!Array.isArray(_.messages)?null:{threadId:_.threadId,messages:_.messages,hasMore:!!_.hasMore,nextCursor:_.nextCursor??null,checkpointId:_.checkpointId??null,checkpointNs:_.checkpointNs??null,nextCursorNs:_.nextCursorNs??null,pendingInterrupt:_.pendingInterrupt??null}},[]),x=y.useCallback(C=>{const _=Ni(p(C));if(!_)return null;try{const z=JSON.parse(_);return b(z)}catch{return null}},[p,b]),g=y.useCallback((C,_=100)=>{const z={...C,messages:Array.isArray(C.messages)?C.messages.slice(-_):[]};try{_c(p(C.threadId),JSON.stringify(z))}catch{}},[p]),v=y.useCallback(C=>{Ai(p(C))},[p]),w=y.useCallback(()=>{if(kr())try{const C=h;for(let _=0;_<window.localStorage.length;_++){const z=window.localStorage.key(_);z&&z.startsWith(C)&&window.localStorage.removeItem(z)}}catch{}},[h]),[S,N]=y.useState(()=>{var C;return _i(f,(C=l.getAuthToken)==null?void 0:C.call(l))}),[T,k]=y.useState(()=>{var _;const C=Ri(_i(f,(_=l.getAuthToken)==null?void 0:_.call(l)));return Fo(C)}),E=y.useMemo(()=>Pi(T),[T]),[A,j]=y.useState(t),[P,L]=y.useState(!1),[$,V]=y.useState(!1),[M,G]=y.useState(null),[K,W]=y.useState(null),[B,F]=y.useState(null),ue=y.useCallback(()=>{const C=Ri(S);y.startTransition(()=>{k(Fo(C))})},[S]),[D,ee]=y.useState(!1),[fe,we]=y.useState(!1),[ye,Ce]=y.useState(null),[q,O]=y.useState(void 0),[X,te]=y.useState(void 0),[he,re]=y.useState(void 0),{state:pe,dispatch:tt,seed:nt,prepend:Pe,pushUser:He,onEvent:ut,reset:rt}=gc(),Ue=y.useRef(A);y.useEffect(()=>{Ue.current=A},[A]);const bt=y.useRef(!1),Z=y.useRef([]),oe=y.useRef(null),me=y.useRef(null),Te=y.useRef(new Map),ge=y.useRef(A),Oe=y.useRef(!1),at=y.useRef(null),Me=y.useRef(new Map),it=y.useRef(new Map),mt=y.useCallback((C,_,z)=>{if(!C)return;const xe=z==="replace"?[]:Me.current.get(C)??[],ne=z==="replace"?_:[..._,...xe];if(!ne.length){z==="replace"&&Me.current.set(C,[]);return}const le=new Map;for(const Ye of ne){if(!(Ye!=null&&Ye.checkpointId))continue;const qe=`${Ye.checkpointId}::${Ye.checkpointNs??""}`;le.has(qe)||le.set(qe,Ye)}const Fe=Array.from(le.values()).sort((Ye,qe)=>{const ve=Number.isFinite(Date.parse(Ye.createdAt))?Date.parse(Ye.createdAt):0;return(Number.isFinite(Date.parse(qe.createdAt))?Date.parse(qe.createdAt):0)-ve});Me.current.set(C,Fe)},[]),Ct=y.useCallback((C,_,z)=>{if(!C)return;const xe=it.current.get(C),ne=z==="replace"||!xe?new Map:new Map(xe);if(_&&typeof _=="object")for(const[le,Fe]of Object.entries(_)){if(!(Fe!=null&&Fe.checkpointId))continue;const Ye=le||Lo(Fe.checkpointId,Fe.checkpointNs??null);ne.set(Ye,Fe)}it.current.set(C,ne)},[]),Bt=y.useCallback((C,_)=>new Promise((z,xe)=>{const ne=async()=>{bt.current=!0;try{await C(),z()}catch(le){xe(le)}finally{bt.current=!1;const le=Z.current.shift();le&&le().catch(()=>{})}};bt.current?Z.current.push(ne):ne().catch(le=>{xe(le)})}),[]),gr=y.useRef(E.length),[ri,So]=y.useState(!1),xr=y.useRef(!1);y.useEffect(()=>{gr.current=E.length},[E.length]),y.useEffect(()=>{const C=pe.pendingInterrupt??mx(pe.messages);px(B,C)||F(C??null)},[B,pe.messages,pe.pendingInterrupt]);const It=y.useCallback(async()=>{const C=gr.current>0;C||L(!0);try{const _=await l.listThreads();y.startTransition(()=>{k(z=>{const xe=Fe=>Fe.map(Ye=>`${Ye.threadId}:${Ye.updatedAt??""}:${Ye.messageCount??""}`).join("|"),ne=Pi(z);return xe(ne)===xe(_)||_.length===0&&ne.length>0&&!xr.current?z:Fo(_)})}),G(null),xr.current||(xr.current=!0,So(!0))}catch(_){i==null||i(String(_)),console.error("[ChatSessionProvider] Failed to refresh threads:",_),G(String(_))}finally{C||L(!1)}},[l,i]),Br=y.useRef(!1),qt=y.useRef(null),gt=y.useRef(null),tn=y.useRef(""),Nn=y.useCallback((C,_)=>{if(!kr())return;gt.current!==null&&(window.clearTimeout(gt.current),gt.current=null);const z=C.map(ne=>`${ne.threadId}:${ne.updatedAt??""}:${ne.messageCount??""}`).join("|");if(C.length===0){try{Ai(S)}catch{}tn.current="";return}if(z===tn.current)return;const xe=()=>{try{const ne=C.slice(0,Ei);ji(S,ne),tn.current=z}catch{}finally{gt.current=null}};if(_!=null&&_.immediate){xe();return}gt.current=window.setTimeout(()=>{Ac(xe)},$o)},[S]),zr=y.useCallback(()=>{Nn(E,{immediate:!0})},[Nn,E]),Gt=y.useCallback((C,_,z,xe)=>{const ne=Array.isArray(C==null?void 0:C.messages)?C.messages:[],le=z??(C==null?void 0:C.threadId)??Ue.current,Fe=le!=null&&le===Ue.current,Ye=(C==null?void 0:C.pendingInterrupt)??null,qe=(xe==null?void 0:xe.persist)!==!1;if(_==="replace"){if(qe&&le){const ve={threadId:le,messages:ne.slice(),hasMore:!!(C!=null&&C.hasMore),nextCursor:(C==null?void 0:C.nextCursor)??null,checkpointId:(C==null?void 0:C.checkpointId)??null,checkpointNs:(C==null?void 0:C.checkpointNs)??null,nextCursorNs:(C==null?void 0:C.nextCursorNs)??null,pendingInterrupt:Ye};Te.current.set(le,ve),ge.current=le}if(!Fe)return;nt(ne,{checkpointId:(C==null?void 0:C.checkpointId)??null,checkpointNs:(C==null?void 0:C.checkpointNs)??null,pendingInterrupt:Ye}),F(Ye??null)}else if(_==="prepend"&&ne.length&&le){const ve=Te.current.get(le),Rt=(ve==null?void 0:ve.messages)??[],mn=new Set,nn=[...ne,...Rt].filter(yr=>{const Xn=yr==null?void 0:yr.id;return Xn?mn.has(Xn)?!1:(mn.add(Xn),!0):!0}),Yn={threadId:le,messages:nn,hasMore:(C==null?void 0:C.hasMore)??(ve==null?void 0:ve.hasMore)??!1,nextCursor:(C==null?void 0:C.nextCursor)??(ve==null?void 0:ve.nextCursor)??null,checkpointId:(ve==null?void 0:ve.checkpointId)??(C==null?void 0:C.checkpointId)??null,checkpointNs:(ve==null?void 0:ve.checkpointNs)??(C==null?void 0:C.checkpointNs)??null,nextCursorNs:(C==null?void 0:C.nextCursorNs)??(ve==null?void 0:ve.nextCursorNs)??null,pendingInterrupt:(ve==null?void 0:ve.pendingInterrupt)??Ye??null};if(Te.current.set(le,Yn),!Fe)return;Pe(ne)}else _==="prepend"&&ne.length&&Pe(ne);Fe&&(_==="replace"?(Ce((C==null?void 0:C.nextCursor)??null),ee(!!(C!=null&&C.hasMore)),O((C==null?void 0:C.checkpointId)??void 0),te((C==null?void 0:C.checkpointNs)??void 0),re((C==null?void 0:C.nextCursorNs)??void 0)):(Ce(ve=>(C==null?void 0:C.nextCursor)??ve??null),ee(ve=>(C==null?void 0:C.hasMore)!==void 0?!!(C!=null&&C.hasMore):ve),O(ve=>(C==null?void 0:C.checkpointId)??ve??void 0),te(ve=>(C==null?void 0:C.checkpointNs)??ve??void 0),re(ve=>(C==null?void 0:C.nextCursorNs)!==void 0?C.nextCursorNs??void 0:ve)))},[Pe,nt,F]),vr=y.useCallback(C=>{C.threadId!=null&&C.threadId!==Ue.current||(nt(C.messages,{checkpointId:C.checkpointId,checkpointNs:C.checkpointNs,pendingInterrupt:C.pendingInterrupt??null}),F(C.pendingInterrupt??null),Ce(C.nextCursor),ee(C.hasMore),O(C.checkpointId??void 0),te(C.checkpointNs??void 0),re(C.nextCursorNs??void 0),ge.current=C.threadId)},[nt,F]),hn=y.useCallback(C=>{C&&(Te.current.delete(C),v(C),Me.current.delete(C),it.current.delete(C),ge.current===C&&(ge.current=null))},[v]),pn=y.useCallback(()=>{const C=Ue.current;C&&hn(C),rt([]),ee(!1),we(!1),Ce(null),O(void 0),te(void 0),re(void 0)},[hn,rt]),br=y.useCallback(({from:C,to:_})=>{const z=Ue.current;z&&console.warn(`[ChatSessionProvider] Stream sequence gap detected (${C} -> ${_}) for thread ${z}`)},[]),Co=y.useCallback(C=>{const _=C.threadId;console.log("[ChatSessionProvider] 📥 Handling thread_info event:",{threadId:_,title:C.title,created:C.created,currentThreads:E.length});const z={threadId:_,title:C.title||`Thread ${_.slice(0,8)}`,createdAt:C.createdAt||new Date().toISOString(),updatedAt:C.updatedAt||new Date().toISOString(),messageCount:C.messageCount||0};Ue.current!==_&&(!Ue.current&&pe.messages.length<=1&&(me.current=_),j(_)),y.startTransition(()=>{k(xe=>{const ne=xe.byId[_];return ne?ne.title===z.title&&ne.updatedAt===z.updatedAt&&ne.messageCount===z.messageCount?xe:{byId:{...xe.byId,[_]:z},order:xe.order}:{byId:{...xe.byId,[_]:z},order:[_,...xe.order]}})})},[pe.messages.length]),{startStream:wr,stop:ie,isStreaming:Se,error:We,setAuthToken:et}=ux({baseUrl:d,onThreadInfo:Co,onMessageEvent:ut,onUnhandledEvent:C=>{console.warn(`[ChatSessionProvider] Unhandled stream event: ${C.type}`,C)},onSequenceGap:br});y.useEffect(()=>{Br.current=Se},[Se]),y.useEffect(()=>{if(!kr())return;gt.current!==null&&(window.clearTimeout(gt.current),gt.current=null);const C=E.map(z=>`${z.threadId}:${z.updatedAt??""}:${z.messageCount??""}`).join("|");if(E.length===0){try{Ai(S)}catch{}tn.current="";return}if(C===tn.current)return;const _=()=>{try{const z=E.slice(0,Ei);ji(S,z),tn.current=C}catch{}finally{gt.current=null}};return gt.current=window.setTimeout(()=>{Ac(_),gt.current=null},$o),()=>{gt.current!==null&&(window.clearTimeout(gt.current),gt.current=null)}},[E,Nn]),y.useEffect(()=>{var xe;const C=l.getAuthToken();et(C);const _=ne=>{const le=_i(f,ne);at.current!==le&&(at.current=le,Oe.current=!1),N(le);const Fe=Ri(le);y.startTransition(()=>{k(Fo(Fe))}),Oe.current||(Oe.current=!0,It().catch(()=>{}))};_(C);const z=(xe=l.onTokenChange)==null?void 0:xe.call(l,ne=>{et(ne),w(),_(ne)});return()=>{z==null||z()}},[l,f,et,w,It]);const Mt=y.useCallback(async C=>{var xe;const _=`Thread ${(xe=crypto.randomUUID)==null?void 0:xe.call(crypto)}`,z={threadId:_,title:C||"New Chat",createdAt:new Date().toISOString(),updatedAt:new Date().toISOString(),messageCount:0};k(ne=>({byId:{...ne.byId,[_]:z},order:[_,...ne.order]})),j(_);try{const ne=await l.createThread(C),le=typeof ne=="string"?ne:ne.threadId;return k(Fe=>{const Ye=Fe.byId[_];if(!Ye)return Fe;const qe={...Fe.byId};delete qe[_],qe[le]={...Ye,threadId:le};const ve=Fe.order.map(Rt=>Rt===_?le:Rt);return{byId:qe,order:ve}}),j(le),setTimeout(()=>It(),10),G(null),le}catch(ne){throw k(le=>{if(!le.byId[_])return le;const Fe={...le.byId};delete Fe[_];const Ye=le.order.filter(qe=>qe!==_);return{byId:Fe,order:Ye}}),j(null),G(String(ne)),ne}},[l,It]),I=y.useCallback(async C=>{try{await l.deleteThread(C);let _=null;k(z=>{if(!z.byId[C])return z;const xe={...z.byId};delete xe[C];const ne=z.order.filter(Fe=>Fe!==C),le={byId:xe,order:ne};return _=Pi(le),le}),_&&Nn(_,{immediate:!0}),hn(C),Ue.current===C&&(me.current=C,j(null),Ue.current=null,ge.current=null,pn()),await It(),G(null)}catch(_){throw G(String(_)),_}},[l,pn,hn,It,Nn]),H=y.useCallback(async(C,_)=>{try{await l.updateThread(C,_),k(z=>{const xe=z.byId[C];return xe?{byId:{...z.byId,[C]:{...xe,title:_}},order:z.order}:z}),G(null)}catch(z){throw await It(),G(String(z)),z}},[l,It]),J=y.useCallback(async(C,_,z,xe=!1)=>{await Bt(async()=>{if(me.current===C&&!xe){me.current=null;return}if(oe.current===C&&!xe)return;j(qe=>qe===C?qe:C),Ue.current=C;const ne=!xe&&!_&&!z;let le=!1;if(ne){const qe=Te.current.get(C);if(qe)vr(qe),le=!0;else{const ve=x(C);ve&&(Te.current.set(C,ve),vr(ve),le=!0)}}const Fe=xe||!le||!!_||!!z,Ye=async qe=>{qe&&V(!0),oe.current=C;try{const ve=await l.getStateHistory({threadId:C,checkpointId:_,checkpointNs:z}),{payload:Rt,checkpoints:mn,snapshots:nn}=Ti(ve);Gt(Rt,"replace",C),mt(C,mn,"replace"),Ct(C,nn,"replace"),W(null)}catch(ve){throw(!le||xe||qe)&&(i==null||i(String(ve))),W(String(ve)),ve}finally{oe.current=null,qe&&V(!1)}};Fe?await Ye(!0):ne&&le&&Ye(!1).catch(qe=>{console.warn("[ChatSessionProvider] Background refresh failed:",qe)})},`loadThread-${C}`)},[l,vr,Gt,Bt,i,mt,Ct]),Ee=y.useCallback(async()=>{await Bt(async()=>{const C=Ue.current;C&&hn(C),me.current=null,j(null),Ue.current=null,ge.current=null,pn(),O(void 0),te(void 0),re(void 0);try{localStorage.removeItem("lastThreadId")}catch(_){console.warn("[ChatSessionProvider] Failed to clear lastThreadId:",_)}},"clearCurrentThread")},[pn,hn,Bt]),$e=y.useCallback(async C=>{const _=Me.current.get(C);if(_)return{threadId:C,checkpoints:_.slice()};const z=await l.getStateHistory({threadId:C}),{checkpoints:xe,snapshots:ne}=Ti(z);mt(C,xe,"replace"),Ct(C,ne,"replace");const le=Me.current.get(C)??[];return{threadId:C,checkpoints:le.slice()}},[l,mt,Ct]),Xe=y.useCallback(async(C,_)=>{var le;const z=Ue.current;if(!z)throw new Error("No active thread");const xe=Lo(C,_??null),ne=(le=it.current.get(z))==null?void 0:le.get(xe);if(ne){await Bt(async()=>{Gt({threadId:z,checkpointId:ne.checkpointId??void 0,checkpointNs:ne.checkpointNs??void 0,messages:ne.messages??[],hasMore:!!ne.nextCursor,nextCursor:ne.nextCursor??null,nextCursorNs:ne.nextCursorNs??null,pendingInterrupt:ne.interrupt??null},"replace",z,{persist:!1})},`navigateToCheckpoint-${z}-${xe}`);return}await J(z,C,_??void 0,!0)},[Gt,Bt,J]),Ve=y.useCallback(async()=>{if(!Ue.current)throw new Error("No active thread");await J(Ue.current,void 0,void 0,!0)},[J]),ze=y.useCallback(async()=>{if(!Ue.current)throw new Error("No active thread");if(fe||!D)return;const C=ye;if(C){we(!0);try{const _=Ue.current,z=await l.getStateHistory({threadId:_,checkpointId:C??q,checkpointNs:he??X}),{payload:xe,checkpoints:ne,snapshots:le}=Ti(z);Gt(xe,"prepend",_??void 0),_&&(mt(_,ne,"prepend"),Ct(_,le,"prepend")),W(null)}catch(_){throw W(String(_)),_}finally{we(!1)}}},[l,Gt,D,q,X,he,ye,fe,mt,Ct]),Tt=y.useCallback(C=>{if(!(C!=null&&C.threadId))return;const _={threadId:C.threadId,checkpointId:C.checkpointId??void 0,checkpointNs:C.checkpointNs??void 0,messages:C.messages??[],hasMore:C.hasMore,nextCursor:C.nextCursor??null,nextCursorNs:C.nextCursorNs??null,pendingInterrupt:C.pendingInterrupt??null};if(C.checkpointId){const z=Lo(C.checkpointId,C.checkpointNs??null);Ct(C.threadId,{[z]:{messages:C.messages??[],checkpointId:C.checkpointId??null,checkpointNs:C.checkpointNs??null,nextCursor:C.nextCursor??null,nextCursorNs:C.nextCursorNs??null,interrupt:C.pendingInterrupt??null}},"prepend")}Gt(_,"replace",C.threadId)},[Gt,Ct]),ht=y.useCallback(async(C,_)=>{var si;const z=Ue.current,xe=(C==null?void 0:C.text)??"",ne=(C==null?void 0:C.attachments)??[],le=ne.length?ne:(_==null?void 0:_.attachments)??[],Fe={...(_==null?void 0:_.payloadExtras)??{},...(C==null?void 0:C.payload)??{}};if(!z&&!Object.keys(Fe).length&&le.length===0&&!xe.trim()){console.warn("[ChatSessionProvider] Nothing to submit - skipping");return}!z&&!Fe.messages&&console.warn("[ChatSessionProvider] No thread ID - message will create new thread");const{contentParts:Ye,filesInfo:qe}=await zg(l,le),ve=[...Ye];xe&&xe.trim()&&ve.push({type:"text",text:xe.trim()});const Rt=!!z,mn=Rt?(_==null?void 0:_.checkpointId)??pe.lastCheckpointId??void 0:void 0,nn=Rt?(_==null?void 0:_.checkpointNs)??pe.lastCheckpointNs??void 0:void 0,Yn={id:((si=crypto.randomUUID)==null?void 0:si.call(crypto))||`user-${Date.now()}`,role:"user",content:ve,createdAt:new Date().toISOString(),...mn!=null?{checkpointId:mn}:{},...nn!=null?{checkpointNs:nn}:{}};ve.length>0&&He(Yn);const yr={...Yn,content:ve},Xn=le.length>0,oi={...z?{threadId:z}:{},payload:{messages:ve.length>0?[yr]:[],files_info:qe,...o&&Xn&&s?{active_agent:s}:{},...Fe},...mn!=null?{checkpointId:mn}:{},...nn!=null?{checkpointNs:nn}:{},nodeFilter:_==null?void 0:_.nodeFilter,config:_==null?void 0:_.config};wr(oi,{onError:On=>{console.warn("[ChatSessionProvider] Stream error:",On)},onOpen:({threadId:On})=>{!Ue.current&&On&&(pe.messages.length<=1&&(me.current=On),j(On))},onGap:br})},[l,o,s,br,pe.lastCheckpointId,pe.lastCheckpointNs,pe.messages.length,He,wr]),dt=y.useCallback(async(C,_,z)=>{var ne,le;const xe=Ue.current;if(!xe)throw new Error("No active thread to handle interrupt");try{const Fe=_?z??!0:!1;try{tt({type:"interrupt_response",payload:{interruptId:C}})}catch(Yn){console.warn("[ChatSessionProvider] optimistic interrupt_response dispatch failed:",Yn)}const Ye=`${d}/runs/resume`,qe=(ne=l.getAuthToken)==null?void 0:ne.call(l),ve=await fetch(Ye,{method:"POST",headers:{"Content-Type":"application/json",...qe?{Authorization:`Bearer ${qe}`}:{}},body:JSON.stringify({thread_id:xe,value:Fe})});if(!ve.ok)throw new Error(`Resume failed with status ${ve.status}`);const Rt=(le=ve.body)==null?void 0:le.getReader();if(!Rt)throw new Error("No response body for resume stream");const mn=new TextDecoder;let nn="";for(;;){const{done:Yn,value:yr}=await Rt.read();if(Yn)break;nn+=mn.decode(yr,{stream:!0});const Xn=nn.split(`
|
|
39
|
+
`);nn=Xn.pop()||"";for(const oi of Xn)if(oi.startsWith("data: ")){const si=oi.slice(6);try{const On=JSON.parse(si);tt({type:"event",payload:{ev:On}})}catch(On){console.warn("[ChatSessionProvider] Failed to parse resume SSE event:",On)}}}F(null)}catch(Fe){throw console.error(`[ChatSessionProvider] Failed to handle interrupt ${C}:`,Fe),Fe}},[l,tt,d]),Dt=y.useCallback(C=>dt(C.interruptId,C.approved,C.value),[dt]);y.useEffect(()=>{if(a==null||a(A),A)try{localStorage.setItem("lastThreadId",A)}catch(C){console.warn("[ChatSessionProvider] Failed to persist lastThreadId:",C)}},[A,a]),y.useEffect(()=>((async()=>{try{if(It().catch(_=>{console.error("[ChatSessionProvider] Failed to refresh threads (background):",_),i==null||i(String(_))}),!r&&!t)try{const _=localStorage.getItem("lastThreadId");_&&(j(_),n&&await J(_))}catch(_){console.warn("[ChatSessionProvider] Failed to restore last thread:",_)}else t&&n&&await J(t)}catch(_){console.error("[ChatSessionProvider] Initialization failed:",_),i==null||i(String(_))}})(),()=>{}),[]),y.useEffect(()=>{var ne,le,Fe,Ye;const C=Ue.current;if(!C||ge.current!==C)return;const _={threadId:C,messages:pe.messages.slice(),hasMore:D,nextCursor:ye,checkpointId:pe.lastCheckpointId??null,checkpointNs:pe.lastCheckpointNs??null,nextCursorNs:he??null,pendingInterrupt:pe.pendingInterrupt??B??null},z=Te.current.get(C);(!z||z.messages.length!==_.messages.length||z.messages.some((qe,ve)=>{var Rt;return(qe==null?void 0:qe.id)!==((Rt=_.messages[ve])==null?void 0:Rt.id)})||(z==null?void 0:z.hasMore)!==_.hasMore||(z==null?void 0:z.nextCursor)!==_.nextCursor||(z==null?void 0:z.nextCursorNs)!==_.nextCursorNs||(z==null?void 0:z.checkpointId)!==_.checkpointId||(z==null?void 0:z.checkpointNs)!==_.checkpointNs||(((ne=z==null?void 0:z.pendingInterrupt)==null?void 0:ne.id)??null)!==(((le=_.pendingInterrupt)==null?void 0:le.id)??null)||JSON.stringify((Fe=z==null?void 0:z.pendingInterrupt)==null?void 0:Fe.value)!==JSON.stringify((Ye=_.pendingInterrupt)==null?void 0:Ye.value))&&(Te.current.set(C,_),qt.current&&window.clearTimeout(qt.current),qt.current=window.setTimeout(()=>{try{g(_,100)}catch(qe){console.warn("[ChatSessionProvider] Failed to persist thread payload:",qe)}},$o))},[D,ye,he,pe.lastCheckpointId,pe.lastCheckpointNs,pe.messages,pe.pendingInterrupt,B]);const Gn=y.useMemo(()=>({threads:E,currentThreadId:A,setCurrentThreadId:j,isLoading:P,error:M,actions:{createThread:Mt,deleteThread:I,renameThread:H,refreshThreads:()=>It()},persistThreadsCache:zr,hydrateFromCache:ue}),[E,A,P,M,Mt,I,H,It,zr,ue,j]),Pn=y.useMemo(()=>{const C=pe.lastBranch??null,_=pe.assemblingId??null,z=C||_?{branchLabel:(C==null?void 0:C.branchLabel)??null,lastBranch:C,assemblingMessageId:_}:null;return{threadId:A,messages:pe.messages,interrupt:B,checkpoint:{id:pe.lastCheckpointId??null,namespace:pe.lastCheckpointNs??null},metadata:z,isLoading:$,isHistoryLoading:fe,error:K,hasMore:D,loadOlder:ze,seedFromSnapshot:Tt,clearState:pn,listCheckpoints:$e,navigateToCheckpoint:Xe,returnToLatest:Ve,loadThread:J,clearThread:Ee,respondToInterrupt:dt}},[Ee,pn,A,B,D,fe,$,$e,ze,J,pe.assemblingId,pe.lastBranch,pe.lastCheckpointId,pe.lastCheckpointNs,pe.messages,Xe,dt,Ve,Tt,K]),jt=y.useMemo(()=>({isStreaming:Se,error:We,submit:ht,stop:ie,resume:Dt,setAuthToken:et}),[Se,We,ht,ie,Dt,et]);return c.jsx(dx.Provider,{value:!0,children:c.jsx(Nc.Provider,{value:jt,children:c.jsx(Ic.Provider,{value:Gn,children:c.jsx(Ec.Provider,{value:Pn,children:e})})})})}function Bo(){const e=y.useContext(Ic);if(!e)throw new Error("useThreads must be used within ChatSessionProvider");return e}function zo(){const e=y.useContext(Ec);if(!e)throw new Error("useThreadState must be used within ChatSessionProvider");return e}function jc(){const e=y.useContext(Nc);if(!e)throw new Error("useStream must be used within ChatSessionProvider");return e}function Ho({children:e,apiConfig:t,initialThreadId:n=null,autoLoadInitial:r=!0,disableAutoRestore:o=!1,enableFileAgentRouting:s=!1,fileAgentId:i="invoice_reader",onError:a,onThreadChange:l}){return c.jsx(Fg,{apiConfig:t,children:c.jsx(bx,{initialThreadId:n,autoLoadInitial:r,disableAutoRestore:o,enableFileAgentRouting:s,fileAgentId:i,onError:a,onThreadChange:l,children:e})})}function Q(...e){return pm.twMerge(hm.clsx(e))}const wx=To.cva("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-10 w-10"}},defaultVariants:{variant:"default",size:"default"}}),Je=m.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?Jn.Slot:"button";return c.jsx(i,{className:Q(wx({variant:t,size:n,className:e})),ref:s,...o})});Je.displayName="Button";const Rc=m.forwardRef(({className:e,...t},n)=>c.jsx("textarea",{className:Q("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}));Rc.displayName="Textarea";function yx({initialValue:e="",editingMessageId:t=null,placeholder:n="Type your message...",isStreaming:r=!1,disabled:o=!1,maxLength:s=2e4,onSend:i,onCancelEdit:a,onStop:l,className:u="",textareaClassName:d="",allowEmptySend:f=!1}){const[h,p]=y.useState(e),[b,x]=y.useTransition(),g=y.useRef(null);y.useEffect(()=>{p(e??""),g.current&&(g.current.style.height="auto",g.current.style.height=`${g.current.scrollHeight}px`)},[e,t]);const v=y.useCallback(()=>{const A=g.current;A&&(A.style.height="auto",A.style.height=`${A.scrollHeight}px`)},[]);y.useEffect(()=>{v()},[v]);const w=y.useCallback(async A=>{A&&A.preventDefault();const j=(h??"").trim();!j&&!f||x(()=>{try{const P=i(j);P&&typeof P.then=="function"?P.then(()=>{p(""),g.current&&(g.current.style.height="auto")}).catch(()=>{}):(p(""),g.current&&(g.current.style.height="auto"))}catch{}})},[h,i,f]),S=y.useCallback(A=>{p(A.target.value),g.current&&(g.current.style.height="auto",g.current.style.height=`${g.current.scrollHeight}px`)},[]),N=y.useCallback(A=>{A.key==="Enter"&&!A.shiftKey?(A.preventDefault(),w()):A.key==="Escape"&&t&&(A.preventDefault(),a==null||a())},[w,t,a]),E=`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${t?"border-[hsl(var(--ring))] bg-[hsl(var(--card))] text-[hsl(var(--card-foreground))] dark:bg-[hsl(var(--card))] dark:text-[hsl(var(--card-foreground))]":""} ${d}`;return c.jsx("form",{onSubmit:A=>void w(A),className:`w-full ${u}`,children:c.jsxs("div",{className:"flex items-end gap-2",children:[c.jsx("div",{className:"flex-1",children:c.jsx(Rc,{ref:g,value:h,onChange:S,onKeyDown:N,placeholder:t?"Edit your message...":n,className:E,disabled:o,maxLength:s,rows:1,spellCheck:!1,autoCorrect:"off"})}),c.jsx("div",{children:r?c.jsx(Je,{type:"button",onClick:()=>{l==null||l()},size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",disabled:o||!l,children:c.jsx(se.Square,{size:16})}):c.jsx(Je,{type:"submit",size:"icon",className:"shrink-0",title:t?"Save changes":"Send message",disabled:o||!h.trim()&&!f||b,children:c.jsx(se.Send,{size:16})})})]})})}const Sx=y.memo(yx),Uo=0,Dn=1,Ir=2,Pc=4;function Oc(e){return()=>e}function Cx(e){e()}function Mc(e,t){return n=>e(t(n))}function Dc(e,t){return()=>e(t)}function Tx(e,t){return n=>e(t,n)}function Oi(e){return e!==void 0}function kx(...e){return()=>{e.map(Cx)}}function Er(){}function Wo(e,t){return t(e),e}function Ix(e,t){return t(e)}function lt(...e){return e}function Qe(e,t){return e(Dn,t)}function Le(e,t){e(Uo,t)}function Mi(e){e(Ir)}function vt(e){return e(Pc)}function be(e,t){return Qe(e,Tx(t,Uo))}function an(e,t){const n=e(Dn,r=>{n(),t(r)});return n}function Lc(e){let t,n;return r=>o=>{t=o,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function $c(e,t){return e===t}function ct(e=$c){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function Ae(e){return t=>n=>{e(n)&&t(n)}}function ae(e){return t=>Mc(t,e)}function xn(e){return t=>()=>{t(e)}}function U(e,...t){const n=Ex(...t);return(r,o)=>{switch(r){case Ir:Mi(e);return;case Dn:return Qe(e,n(o))}}}function vn(e,t){return n=>r=>{n(t=e(t,r))}}function tr(e){return t=>n=>{e>0?e--:t(n)}}function _n(e){let t=null,n;return r=>o=>{t=o,!n&&(n=setTimeout(()=>{n=void 0,r(t)},e))}}function Be(...e){const t=new Array(e.length);let n=0,r=null;const o=Math.pow(2,e.length)-1;return e.forEach((s,i)=>{const a=Math.pow(2,i);Qe(s,l=>{const u=n;n=n|a,t[i]=l,u!==o&&n===o&&r&&(r(),r=null)})}),s=>i=>{const a=()=>{s([i].concat(t))};n===o?a():r=a}}function Ex(...e){return t=>e.reduceRight(Ix,t)}function Nx(e){let t,n;const r=()=>t==null?void 0:t();return function(o,s){switch(o){case Dn:return s?n===s?void 0:(r(),n=s,t=Qe(e,s),t):(r(),Er);case Ir:r(),n=null;return}}}function Y(e){let t=e;const n=Ge();return(r,o)=>{switch(r){case Uo:t=o;break;case Dn:{o(t);break}case Pc:return t}return n(r,o)}}function Nt(e,t){return Wo(Y(t),n=>be(e,n))}function Ge(){const e=[];return(t,n)=>{switch(t){case Uo:e.slice().forEach(r=>{r(n)});return;case Ir:e.splice(0,e.length);return;case Dn:return e.push(n),()=>{const r=e.indexOf(n);r>-1&&e.splice(r,1)}}}}function Ht(e){return Wo(Ge(),t=>be(e,t))}function Ze(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:Ax(),singleton:n}}const Ax=()=>Symbol();function _x(e){const t=new Map,n=({constructor:r,dependencies:o,id:s,singleton:i})=>{if(i&&t.has(s))return t.get(s);const a=r(o.map(l=>n(l)));return i&&t.set(s,a),a};return n(e)}function wt(...e){const t=Ge(),n=new Array(e.length);let r=0;const o=Math.pow(2,e.length)-1;return e.forEach((s,i)=>{const a=Math.pow(2,i);Qe(s,l=>{n[i]=l,r=r|a,r===o&&Le(t,n)})}),function(s,i){switch(s){case Ir:{Mi(t);return}case Dn:return r===o&&i(n),Qe(t,i)}}}function Ne(e,t=$c){return U(e,ct(t))}function Di(...e){return function(t,n){switch(t){case Ir:return;case Dn:return kx(...e.map(r=>Qe(r,n)))}}}var Ft=(e=>(e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR",e))(Ft||{});const jx={0:"debug",3:"error",1:"log",2:"warn"},Rx=()=>typeof globalThis>"u"?window:globalThis,Ln=Ze(()=>{const e=Y(3);return{log:Y((t,n,r=1)=>{var o;const s=(o=Rx().VIRTUOSO_LOG_LEVEL)!=null?o:vt(e);r>=s&&console[jx[r]]("%creact-virtuoso: %c%s %o","color: #0253b3; font-weight: bold","color: initial",t,n)}),logLevel:e}},[],{singleton:!0});function nr(e,t,n){return Li(e,t,n).callbackRef}function Li(e,t,n){const r=y.useRef(null);let o=i=>{};const s=y.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 Px(e,t,n,r,o,s,i,a,l){const u=y.useCallback(d=>{const f=Ox(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 b;p&&(b=h.ownerDocument.defaultView);const x=i?a?i.scrollLeft:i.scrollTop:p?a?b.scrollX||b.document.documentElement.scrollLeft:b.scrollY||b.document.documentElement.scrollTop:a?h.scrollLeft:h.scrollTop,g=i?a?i.scrollWidth:i.scrollHeight:p?a?b.document.documentElement.scrollWidth:b.document.documentElement.scrollHeight:a?h.scrollWidth:h.scrollHeight,v=i?a?i.offsetWidth:i.offsetHeight:p?a?b.innerWidth:b.innerHeight:a?h.offsetWidth:h.offsetHeight;r({scrollHeight:g,scrollTop:Math.max(x,0),viewportHeight:v}),s==null||s(a?Fc("column-gap",getComputedStyle(d).columnGap,o):Fc("row-gap",getComputedStyle(d).rowGap,o)),f!==null&&e(f)},[e,t,o,s,i,r,a]);return Li(u,n,l)}function Ox(e,t,n,r){const o=e.length;if(o===0)return null;const s=[];for(let i=0;i<o;i++){const a=e.item(i);if(a.dataset.index===void 0)continue;const l=parseInt(a.dataset.index),u=parseFloat(a.dataset.knownSize),d=t(a,n);if(d===0&&r("Zero-sized element, this should not happen",{child:a},Ft.ERROR),d===u)continue;const f=s[s.length-1];s.length===0||f.size!==d||f.endIndex!==l-1?s.push({endIndex:l,size:d,startIndex:l}):s[s.length-1].endIndex++}return s}function Fc(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Ft.WARN),t==="normal"?0:parseInt(t??"0",10)}function Bc(e,t,n){const r=y.useRef(null),o=y.useCallback(l=>{if(!(l!=null&&l.offsetParent))return;const u=l.getBoundingClientRect(),d=u.width;let f,h;if(t){const p=t.getBoundingClientRect(),b=u.top-p.top;h=p.height-Math.max(0,b),f=b+t.scrollTop}else{const p=i.current.ownerDocument.defaultView;h=p.innerHeight-Math.max(0,u.top),f=u.top+p.scrollY}r.current={offsetTop:f,visibleHeight:h,visibleWidth:d},e(r.current)},[e,t]),{callbackRef:s,ref:i}=Li(o,!0,n),a=y.useCallback(()=>{o(i.current)},[o,i]);return y.useEffect(()=>{var l;if(t){t.addEventListener("scroll",a);const u=new ResizeObserver(()=>{requestAnimationFrame(a)});return u.observe(t),()=>{t.removeEventListener("scroll",a),u.unobserve(t)}}else{const u=(l=i.current)==null?void 0:l.ownerDocument.defaultView;return u==null||u.addEventListener("scroll",a),u==null||u.addEventListener("resize",a),()=>{u==null||u.removeEventListener("scroll",a),u==null||u.removeEventListener("resize",a)}}},[a,t,i]),s}const Pt=Ze(()=>{const e=Ge(),t=Ge(),n=Y(0),r=Ge(),o=Y(0),s=Ge(),i=Ge(),a=Y(0),l=Y(0),u=Y(0),d=Y(0),f=Ge(),h=Ge(),p=Y(!1),b=Y(!1),x=Y(!1);return be(U(e,ae(({scrollTop:g})=>g)),t),be(U(e,ae(({scrollHeight:g})=>g)),i),be(t,o),{deviation:n,fixedFooterHeight:u,fixedHeaderHeight:l,footerHeight:d,headerHeight:a,horizontalDirection:b,scrollBy:h,scrollContainerState:e,scrollHeight:i,scrollingInProgress:p,scrollTo:f,scrollTop:t,skipAnimationFrameInResizeObserver:x,smoothScrollTargetReached:r,statefulScrollTop:o,viewportHeight:s}},[],{singleton:!0}),Xr={lvl:0};function zc(e,t){const n=e.length;if(n===0)return[];let{index:r,value:o}=t(e[0]);const s=[];for(let i=1;i<n;i++){const{index:a,value:l}=t(e[i]);s.push({end:a-1,start:r,value:o}),r=a,o=l}return s.push({end:1/0,start:r,value:o}),s}function ot(e){return e===Xr}function Jr(e,t){if(!ot(e))return t===e.k?e.v:t<e.k?Jr(e.l,t):Jr(e.r,t)}function ln(e,t,n="k"){if(ot(e))return[-1/0,void 0];if(Number(e[n])===t)return[e.k,e.v];if(Number(e[n])<t){const r=ln(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return ln(e.l,t,n)}function Ut(e,t,n){return ot(e)?Wc(t,n,1):t===e.k?yt(e,{k:t,v:n}):t<e.k?Vc(yt(e,{l:Ut(e.l,t,n)})):Vc(yt(e,{r:Ut(e.r,t,n)}))}function Nr(){return Xr}function Vo(e,t,n){if(ot(e))return[];const r=ln(e,t)[0];return Mx(Fi(e,r,n))}function $i(e,t){if(ot(e))return Xr;const{k:n,l:r,r:o}=e;if(t===n){if(ot(r))return o;if(ot(o))return r;{const[s,i]=Uc(r);return Ko(yt(e,{k:s,l:Hc(r),v:i}))}}else return t<n?Ko(yt(e,{l:$i(r,t)})):Ko(yt(e,{r:$i(o,t)}))}function rr(e){return ot(e)?[]:[...rr(e.l),{k:e.k,v:e.v},...rr(e.r)]}function Fi(e,t,n){if(ot(e))return[];const{k:r,l:o,r:s,v:i}=e;let a=[];return r>t&&(a=a.concat(Fi(o,t,n))),r>=t&&r<=n&&a.push({k:r,v:i}),r<=n&&(a=a.concat(Fi(s,t,n))),a}function Ko(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(Bi(t))return Kc(yt(e,{lvl:n-1}));if(!ot(t)&&!ot(t.r))return yt(t.r,{l:yt(t,{r:t.r.l}),lvl:n,r:yt(e,{l:t.r.r,lvl:n-1})});throw new Error("Unexpected empty nodes")}else{if(Bi(e))return zi(yt(e,{lvl:n-1}));if(!ot(r)&&!ot(r.l)){const o=r.l,s=Bi(o)?r.lvl-1:r.lvl;return yt(o,{l:yt(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:zi(yt(r,{l:o.r,lvl:s}))})}else throw new Error("Unexpected empty nodes")}}function yt(e,t){return Wc(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 Hc(e){return ot(e.r)?e.l:Ko(yt(e,{r:Hc(e.r)}))}function Bi(e){return ot(e)||e.lvl>e.r.lvl}function Uc(e){return ot(e.r)?[e.k,e.v]:Uc(e.r)}function Wc(e,t,n,r=Xr,o=Xr){return{k:e,l:r,lvl:n,r:o,v:t}}function Vc(e){return zi(Kc(e))}function Kc(e){const{l:t}=e;return!ot(t)&&t.lvl===e.lvl?yt(t,{r:yt(e,{l:t.r})}):e}function zi(e){const{lvl:t,r:n}=e;return!ot(n)&&!ot(n.r)&&n.lvl===t&&n.r.lvl===t?yt(n,{l:yt(e,{r:n.l}),lvl:t+1}):e}function Mx(e){return zc(e,({k:t,v:n})=>({index:t,value:n}))}function qc(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function Zr(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}const Hi=Ze(()=>({recalcInProgress:Y(!1)}),[],{singleton:!0});function Gc(e,t,n){return e[qo(e,t,n)]}function qo(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 Dx(e,t,n,r){const o=qo(e,t,r),s=qo(e,n,r,o);return e.slice(o,s+1)}function $n(e,t){return Math.round(e.getBoundingClientRect()[t])}function Go(e){return!ot(e.groupOffsetTree)}function Ui({index:e},t){return t===e?0:t<e?-1:1}function Lx(){return{groupIndices:[],groupOffsetTree:Nr(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:Nr()}}function $x(e,t){let n=ot(e)?0:1/0;for(const r of t){const{endIndex:o,size:s,startIndex:i}=r;if(n=Math.min(n,i),ot(e)){e=Ut(e,0,s);continue}const a=Vo(e,i-1,o+1);if(a.some(Vx(r)))continue;let l=!1,u=!1;for(const{end:d,start:f,value:h}of a)l?(o>=f||s===h)&&(e=$i(e,f)):(u=h!==s,l=!0),d>o&&o>=f&&h!==s&&(e=Ut(e,o+1,h));u&&(e=Ut(e,i,s))}return[e,n]}function Fx(e){return typeof e.groupIndex<"u"}function Bx({offset:e},t){return t===e?0:t<e?-1:1}function Qr(e,t,n){if(t.length===0)return 0;const{index:r,offset:o,size:s}=Gc(t,e,Ui),i=e-r,a=s*i+(i-1)*n+o;return a>0?a+n:a}function Yc(e,t){if(!Go(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function Xc(e,t,n){if(Fx(e))return t.groupIndices[e.groupIndex]+1;{const r=e.index==="LAST"?n:e.index;let o=Yc(r,t);return o=Math.max(0,o,Math.min(n,o)),o}}function zx(e,t,n,r=0){return r>0&&(t=Math.max(t,Gc(e,r,Ui).offset)),zc(Dx(e,t,n,Bx),Wx)}function Hx(e,[t,n,r,o]){t.length>0&&r("received item sizes",t,Ft.DEBUG);const s=e.sizeTree;let i=s,a=0;if(n.length>0&&ot(s)&&t.length===2){const h=t[0].size,p=t[1].size;i=n.reduce((b,x)=>Ut(Ut(b,x,h),x+1,p),i)}else[i,a]=$x(i,t);if(i===s)return e;const{lastIndex:l,lastOffset:u,lastSize:d,offsetTree:f}=Wi(e.offsetTree,a,i,o);return{groupIndices:n,groupOffsetTree:n.reduce((h,p)=>Ut(h,p,Qr(p,f,o)),Nr()),lastIndex:l,lastOffset:u,lastSize:d,offsetTree:f,sizeTree:i}}function Ux(e){return rr(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 Jc(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 Wi(e,t,n,r){let o=e,s=0,i=0,a=0,l=0;if(t!==0){l=qo(o,t-1,Ui),a=o[l].offset;const u=ln(n,t-1);s=u[0],i=u[1],o.length&&o[l].size===ln(n,t)[1]&&(l-=1),o=o.slice(0,l+1)}else o=[];for(const{start:u,value:d}of Vo(n,t,1/0)){const f=u-s,h=f*i+a+f*r;o.push({index:u,offset:h,size:d}),s=u,a=h,i=d}return{lastIndex:s,lastOffset:a,lastSize:i,offsetTree:o}}function Wx(e){return{index:e.index,value:e}}function Vx(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 Kx={offsetHeight:"height",offsetWidth:"width"},bn=Ze(([{log:e},{recalcInProgress:t}])=>{const n=Ge(),r=Ge(),o=Nt(r,0),s=Ge(),i=Ge(),a=Y(0),l=Y([]),u=Y(void 0),d=Y(void 0),f=Y((T,k)=>$n(T,Kx[k])),h=Y(void 0),p=Y(0),b=Lx(),x=Nt(U(n,Be(l,e,p),vn(Hx,b),ct()),b),g=Nt(U(l,ct(),vn((T,k)=>({current:k,prev:T.current}),{current:[],prev:[]}),ae(({prev:T})=>T)),[]);be(U(l,Ae(T=>T.length>0),Be(x,p),ae(([T,k,E])=>{const A=T.reduce((j,P,L)=>Ut(j,P,Qr(P,k.offsetTree,E)||L),Nr());return{...k,groupIndices:T,groupOffsetTree:A}})),x),be(U(r,Be(x),Ae(([T,{lastIndex:k}])=>T<k),ae(([T,{lastIndex:k,lastSize:E}])=>[{endIndex:k,size:E,startIndex:T}])),n),be(u,d);const v=Nt(U(u,ae(T=>T===void 0)),!0);be(U(d,Ae(T=>T!==void 0&&ot(vt(x).sizeTree)),ae(T=>[{endIndex:0,size:T,startIndex:0}])),n);const w=Ht(U(n,Be(x),vn(({sizes:T},[k,E])=>({changed:E!==T,sizes:E}),{changed:!1,sizes:b}),ae(T=>T.changed)));Qe(U(a,vn((T,k)=>({diff:T.prev-k,prev:k}),{diff:0,prev:0}),ae(T=>T.diff)),T=>{const{groupIndices:k}=vt(x);if(T>0)Le(t,!0),Le(s,T+Jc(T,k));else if(T<0){const E=vt(g);E.length>0&&(T-=Jc(-T,E)),Le(i,T)}}),Qe(U(a,Be(e)),([T,k])=>{T<0&&k("`firstItemIndex` prop should not be set to less than zero. If you don't know the total count, just use a very high value",{firstItemIndex:a},Ft.ERROR)});const S=Ht(s);be(U(s,Be(x),ae(([T,k])=>{const E=k.groupIndices.length>0,A=[],j=k.lastSize;if(E){const P=Jr(k.sizeTree,0);let L=0,$=0;for(;L<T;){const M=k.groupIndices[$],G=k.groupIndices.length===$+1?1/0:k.groupIndices[$+1]-M-1;A.push({endIndex:M,size:P,startIndex:M}),A.push({endIndex:M+1+G-1,size:j,startIndex:M+1}),$++,L+=G+1}const V=rr(k.sizeTree);return L!==T&&V.shift(),V.reduce((M,{k:G,v:K})=>{let W=M.ranges;return M.prevSize!==0&&(W=[...M.ranges,{endIndex:G+T-1,size:M.prevSize,startIndex:M.prevIndex}]),{prevIndex:G+T,prevSize:K,ranges:W}},{prevIndex:T,prevSize:0,ranges:A}).ranges}return rr(k.sizeTree).reduce((P,{k:L,v:$})=>({prevIndex:L+T,prevSize:$,ranges:[...P.ranges,{endIndex:L+T-1,size:P.prevSize,startIndex:P.prevIndex}]}),{prevIndex:0,prevSize:j,ranges:[]}).ranges})),n);const N=Ht(U(i,Be(x,p),ae(([T,{offsetTree:k},E])=>{const A=-T;return Qr(A,k,E)})));return be(U(i,Be(x,p),ae(([T,k,E])=>{if(k.groupIndices.length>0){if(ot(k.sizeTree))return k;let A=Nr();const j=vt(g);let P=0,L=0,$=0;for(;P<-T;){$=j[L];const V=j[L+1]-$-1;L++,P+=V+1}if(A=rr(k.sizeTree).reduce((V,{k:M,v:G})=>Ut(V,Math.max(0,M+T),G),A),P!==-T){const V=Jr(k.sizeTree,$);A=Ut(A,0,V);const M=ln(k.sizeTree,-T+1)[1];A=Ut(A,1,M)}return{...k,sizeTree:A,...Wi(k.offsetTree,0,A,E)}}else{const A=rr(k.sizeTree).reduce((j,{k:P,v:L})=>Ut(j,Math.max(0,P+T),L),Nr());return{...k,sizeTree:A,...Wi(k.offsetTree,0,A,E)}}})),x),{beforeUnshiftWith:S,data:h,defaultItemSize:d,firstItemIndex:a,fixedItemSize:u,gap:p,groupIndices:l,itemSize:f,listRefresh:w,shiftWith:i,shiftWithOffset:N,sizeRanges:n,sizes:x,statefulTotalCount:o,totalCount:r,trackItemSizes:v,unshiftWith:s}},lt(Ln,Hi),{singleton:!0});function qx(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const Zc=Ze(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=Ge(),i=Ge(),a=Ht(U(s,ae(qx)));return be(U(a,ae(l=>l.totalCount)),n),be(U(a,ae(l=>l.groupIndices)),e),be(U(wt(o,t,r),Ae(([l,u])=>Go(u)),ae(([l,u,d])=>ln(u.groupOffsetTree,Math.max(l-d,0),"v")[0]),ct(),ae(l=>[l])),i),{groupCounts:s,topItemsIndexes:i}},lt(bn,Pt)),Fn=Ze(([{log:e}])=>{const t=Y(!1),n=Ht(U(t,Ae(r=>r),ct()));return Qe(t,r=>{r&&vt(e)("props updated",{},Ft.DEBUG)}),{didMount:n,propsReady:t}},lt(Ln),{singleton:!0}),Gx=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function Qc(e){const t=typeof e=="number"?{index:e}:e;return t.align||(t.align="start"),(!t.behavior||!Gx)&&(t.behavior="auto"),t.offset||(t.offset=0),t}const eo=Ze(([{gap:e,listRefresh:t,sizes:n,totalCount:r},{fixedFooterHeight:o,fixedHeaderHeight:s,footerHeight:i,headerHeight:a,scrollingInProgress:l,scrollTo:u,smoothScrollTargetReached:d,viewportHeight:f},{log:h}])=>{const p=Ge(),b=Ge(),x=Y(0);let g=null,v=null,w=null;function S(){g&&(g(),g=null),w&&(w(),w=null),v&&(clearTimeout(v),v=null),Le(l,!1)}return be(U(p,Be(n,f,r,x,a,i,h),Be(e,s,o),ae(([[N,T,k,E,A,j,P,L],$,V,M])=>{const G=Qc(N),{align:K,behavior:W,offset:B}=G,F=E-1,ue=Xc(G,T,F);let D=Qr(ue,T.offsetTree,$)+j;K==="end"?(D+=V+ln(T.sizeTree,ue)[1]-k+M,ue===F&&(D+=P)):K==="center"?D+=(V+ln(T.sizeTree,ue)[1]-k+M)/2:D-=A,B&&(D+=B);const ee=fe=>{S(),fe?(L("retrying to scroll to",{location:N},Ft.DEBUG),Le(p,N)):(Le(b,!0),L("list did not change, scroll successful",{},Ft.DEBUG))};if(S(),W==="smooth"){let fe=!1;w=Qe(t,we=>{fe=fe||we}),g=an(d,()=>{ee(fe)})}else g=an(U(t,Yx(150)),ee);return v=setTimeout(()=>{S()},1200),Le(l,!0),L("scrolling from index to",{behavior:W,index:ue,top:D},Ft.DEBUG),{behavior:W,top:D}})),u),{scrollTargetReached:b,scrollToIndex:p,topListHeight:x}},lt(bn,Pt,Ln),{singleton:!0});function Yx(e){return t=>{const n=setTimeout(()=>{t(!1)},e);return r=>{r&&(t(!0),clearTimeout(n))}}}function Vi(e,t){e==0?t():requestAnimationFrame(()=>{Vi(e-1,t)})}function Ki(e,t){const n=t-1;return typeof e=="number"?e:e.index==="LAST"?n:e.index}const to=Ze(([{defaultItemSize:e,listRefresh:t,sizes:n},{scrollTop:r},{scrollTargetReached:o,scrollToIndex:s},{didMount:i}])=>{const a=Y(!0),l=Y(0),u=Y(!0);return be(U(i,Be(l),Ae(([d,f])=>!!f),xn(!1)),a),be(U(i,Be(l),Ae(([d,f])=>!!f),xn(!1)),u),Qe(U(wt(t,i),Be(a,n,e,u),Ae(([[,d],f,{sizeTree:h},p,b])=>d&&(!ot(h)||Oi(p))&&!f&&!b),Be(l)),([,d])=>{an(o,()=>{Le(u,!0)}),Vi(4,()=>{an(r,()=>{Le(a,!0)}),Le(s,d)})}),{initialItemFinalLocationReached:u,initialTopMostItemIndex:l,scrolledToInitialItem:a}},lt(bn,Pt,eo,Fn),{singleton:!0});function eu(e,t){return Math.abs(e-t)<1.01}const no="up",ro="down",Xx="none",Jx={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},Zx=0,oo=Ze(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:o,viewportHeight:s}])=>{const i=Y(!1),a=Y(!0),l=Ge(),u=Ge(),d=Y(4),f=Y(Zx),h=Nt(U(Di(U(Ne(o),tr(1),xn(!0)),U(Ne(o),tr(1),xn(!1),Lc(100))),ct()),!1),p=Nt(U(Di(U(n,xn(!0)),U(n,xn(!1),Lc(200))),ct()),!1);be(U(wt(Ne(o),Ne(f)),ae(([w,S])=>w<=S),ct()),a),be(U(a,_n(50)),u);const b=Ht(U(wt(r,Ne(s),Ne(t),Ne(e),Ne(d)),vn((w,[{scrollHeight:S,scrollTop:N},T,k,E,A])=>{const j=N+T-S>-A,P={scrollHeight:S,scrollTop:N,viewportHeight:T};if(j){let $,V;return N>w.state.scrollTop?($="SCROLLED_DOWN",V=w.state.scrollTop-N):($="SIZE_DECREASED",V=w.state.scrollTop-N||w.scrollTopDelta),{atBottom:!0,atBottomBecause:$,scrollTopDelta:V,state:P}}let L;return P.scrollHeight>w.state.scrollHeight?L="SIZE_INCREASED":T<w.state.viewportHeight?L="VIEWPORT_HEIGHT_DECREASING":N<w.state.scrollTop?L="SCROLLING_UPWARDS":L="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:L,state:P}},Jx),ct((w,S)=>w&&w.atBottom===S.atBottom))),x=Nt(U(r,vn((w,{scrollHeight:S,scrollTop:N,viewportHeight:T})=>{if(eu(w.scrollHeight,S))return{changed:!1,jump:0,scrollHeight:S,scrollTop:N};{const k=S-(N+T)<1;return w.scrollTop!==N&&k?{changed:!0,jump:w.scrollTop-N,scrollHeight:S,scrollTop:N}:{changed:!0,jump:0,scrollHeight:S,scrollTop:N}}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),Ae(w=>w.changed),ae(w=>w.jump)),0);be(U(b,ae(w=>w.atBottom)),i),be(U(i,_n(50)),l);const g=Y(ro);be(U(r,ae(({scrollTop:w})=>w),ct(),vn((w,S)=>vt(p)?{direction:w.direction,prevScrollTop:S}:{direction:S<w.prevScrollTop?no:ro,prevScrollTop:S},{direction:ro,prevScrollTop:0}),ae(w=>w.direction)),g),be(U(r,_n(50),xn(Xx)),g);const v=Y(0);return be(U(h,Ae(w=>!w),xn(0)),v),be(U(o,_n(100),Be(h),Ae(([w,S])=>!!S),vn(([w,S],[N])=>[S,N],[0,0]),ae(([w,S])=>S-w)),v),{atBottomState:b,atBottomStateChange:l,atBottomThreshold:d,atTopStateChange:u,atTopThreshold:f,isAtBottom:i,isAtTop:a,isScrolling:h,lastJumpDueToItemResize:x,scrollDirection:g,scrollVelocity:v}},lt(Pt)),Yo="top",Xo="bottom",tu="none";function nu(e,t,n){return typeof e=="number"?n===no&&t===Yo||n===ro&&t===Xo?e:0:n===no?t===Yo?e.main:e.reverse:t===Xo?e.main:e.reverse}function ru(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const qi=Ze(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:o}])=>{const s=Ge(),i=Y(0),a=Y(0),l=Y(0),u=Nt(U(wt(Ne(r),Ne(o),Ne(n),Ne(s,Zr),Ne(l),Ne(i),Ne(t),Ne(e),Ne(a)),ae(([d,f,h,[p,b],x,g,v,w,S])=>{const N=d-w,T=g+v,k=Math.max(h-N,0);let E=tu;const A=ru(S,Yo),j=ru(S,Xo);return p-=w,p+=h+v,b+=h+v,b-=w,p>d+T-A&&(E=no),b<d-k+f+j&&(E=ro),E!==tu?[Math.max(N-h-nu(x,Yo,E)-A,0),N-k-v+f+nu(x,Xo,E)+j]:null}),Ae(d=>d!=null),ct(Zr)),[0,0]);return{increaseViewportBy:a,listBoundary:s,overscan:l,topListHeight:i,visibleRange:u}},lt(Pt),{singleton:!0});function Qx(e,t,n){if(Go(t)){const r=Yc(e,t);return[{index:ln(t.groupOffsetTree,r)[0],offset:0,size:0},{data:n==null?void 0:n[0],index:r,offset:0,size:0}]}return[{data:n==null?void 0:n[0],index:e,offset:0,size:0}]}const Gi={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function Jo(e,t,n,r,o,s){const{lastIndex:i,lastOffset:a,lastSize:l}=o;let u=0,d=0;if(e.length>0){u=e[0].offset;const x=e[e.length-1];d=x.offset+x.size}const f=n-i,h=a+f*l+(f-1)*r,p=u,b=h-d;return{bottom:d,firstItemIndex:s,items:su(e,o,s),offsetBottom:b,offsetTop:u,top:p,topItems:su(t,o,s),topListHeight:t.reduce((x,g)=>g.size+x,0),totalCount:n}}function ou(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=Ki(t,a),u=Array.from({length:a}).map((d,f)=>({data:s[f+l],index:f+l,offset:0,size:0}));return Jo(u,[],a,o,n,r)}function su(e,t,n){if(e.length===0)return[];if(!Go(t))return e.map(u=>({...u,index:u.index+n,originalIndex:u.index}));const r=e[0].index,o=e[e.length-1].index,s=[],i=Vo(t.groupOffsetTree,r,o);let a,l=0;for(const u of e){(!a||a.end<u.index)&&(a=i.shift(),l=t.groupIndices.indexOf(a.start));let d;u.index===a.start?d={index:l,type:"group"}:d={groupIndex:l,index:u.index-(l+1)+n},s.push({...d,data:u.data,offset:u.offset,originalIndex:u.index,size:u.size})}return s}const or=Ze(([{data:e,firstItemIndex:t,gap:n,sizes:r,totalCount:o},s,{listBoundary:i,topListHeight:a,visibleRange:l},{initialTopMostItemIndex:u,scrolledToInitialItem:d},{topListHeight:f},h,{didMount:p},{recalcInProgress:b}])=>{const x=Y([]),g=Y(0),v=Ge();be(s.topItemsIndexes,x);const w=Nt(U(wt(p,b,Ne(l,Zr),Ne(o),Ne(r),Ne(u),d,Ne(x),Ne(t),Ne(n),e),Ae(([k,E,,A,,,,,,,j])=>{const P=j&&j.length!==A;return k&&!E&&!P}),ae(([,,[k,E],A,j,P,L,$,V,M,G])=>{const K=j,{offsetTree:W,sizeTree:B}=K,F=vt(g);if(A===0)return{...Gi,totalCount:A};if(k===0&&E===0)return F===0?{...Gi,totalCount:A}:ou(F,P,j,V,M,G||[]);if(ot(B))return F>0?null:Jo(Qx(Ki(P,A),K,G),[],A,M,K,V);const ue=[];if($.length>0){const ye=$[0],Ce=$[$.length-1];let q=0;for(const O of Vo(B,ye,Ce)){const X=O.value,te=Math.max(O.start,ye),he=Math.min(O.end,Ce);for(let re=te;re<=he;re++)ue.push({data:G==null?void 0:G[re],index:re,offset:q,size:X}),q+=X}}if(!L)return Jo([],ue,A,M,K,V);const D=$.length>0?$[$.length-1]+1:0,ee=zx(W,k,E,D);if(ee.length===0)return null;const fe=A-1,we=Wo([],ye=>{for(const Ce of ee){const q=Ce.value;let O=q.offset,X=Ce.start;const te=q.size;if(q.offset<k){X+=Math.floor((k-q.offset+M)/(te+M));const re=X-Ce.start;O+=re*te+re*M}X<D&&(O+=(D-X)*te,X=D);const he=Math.min(Ce.end,fe);for(let re=X;re<=he&&!(O>=E);re++)ye.push({data:G==null?void 0:G[re],index:re,offset:O,size:te}),O+=te+M}});return Jo(we,ue,A,M,K,V)}),Ae(k=>k!==null),ct()),Gi);be(U(e,Ae(Oi),ae(k=>k==null?void 0:k.length)),o),be(U(w,ae(k=>k.topListHeight)),f),be(f,a),be(U(w,ae(k=>[k.top,k.bottom])),i),be(U(w,ae(k=>k.items)),v);const S=Ht(U(w,Ae(({items:k})=>k.length>0),Be(o,e),Ae(([{items:k},E])=>k[k.length-1].originalIndex===E-1),ae(([,k,E])=>[k-1,E]),ct(Zr),ae(([k])=>k))),N=Ht(U(w,_n(200),Ae(({items:k,topItems:E})=>k.length>0&&k[0].originalIndex===E.length),ae(({items:k})=>k[0].index),ct())),T=Ht(U(w,Ae(({items:k})=>k.length>0),ae(({items:k})=>{let E=0,A=k.length-1;for(;k[E].type==="group"&&E<A;)E++;for(;k[A].type==="group"&&A>E;)A--;return{endIndex:k[A].index,startIndex:k[E].index}}),ct(qc)));return{endReached:S,initialItemCount:g,itemsRendered:v,listState:w,rangeChanged:T,startReached:N,topItemsIndexes:x,...h}},lt(bn,Zc,qi,to,eo,oo,Fn,Hi),{singleton:!0}),iu=Ze(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:o}])=>{const s=Ge(),i=Nt(U(wt(n,e,r,t,o),ae(([a,l,u,d,f])=>a+l+u+d+f.offsetBottom+f.bottom)),0);return be(Ne(i),s),{totalListHeight:i,totalListHeightChanged:s}},lt(Pt,or),{singleton:!0}),ev=Ze(([{viewportHeight:e},{totalListHeight:t}])=>{const n=Y(!1),r=Nt(U(wt(n,e,t),Ae(([o])=>o),ae(([,o,s])=>Math.max(0,o-s)),_n(0),ct()),0);return{alignToBottom:n,paddingTopAddition:r}},lt(Pt,iu),{singleton:!0}),au=Ze(()=>({context:Y(null)})),tv=({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,lu=Ze(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:s,scrollingInProgress:i,scrollTop:a,viewportHeight:l},{scrollToIndex:u}])=>{const d=Ge();return be(U(d,Be(t,l,n,s,o,r,a),Be(e),ae(([[f,h,p,b,x,g,v,w],S])=>{const{align:N,behavior:T,calculateViewLocation:k=tv,done:E,...A}=f,j=Xc(f,h,b-1),P=Qr(j,h.offsetTree,S)+x+g,L=P+ln(h.sizeTree,j)[1],$=w+g,V=w+p-v,M=k({itemBottom:L,itemTop:P,locationParams:{align:N,behavior:T,...A},viewportBottom:V,viewportTop:$});return M?E&&an(U(i,Ae(G=>!G),tr(vt(i)?1:2)),E):E&&E(),M}),Ae(f=>f!==null)),u),{scrollIntoView:d}},lt(bn,Pt,eo,or,Ln),{singleton:!0});function cu(e){return e?e==="smooth"?"smooth":"auto":!1}const nv=(e,t)=>typeof e=="function"?cu(e(t)):t&&cu(e),rv=Ze(([{listRefresh:e,totalCount:t,fixedItemSize:n,data:r},{atBottomState:o,isAtBottom:s},{scrollToIndex:i},{scrolledToInitialItem:a},{didMount:l,propsReady:u},{log:d},{scrollingInProgress:f},{context:h},{scrollIntoView:p}])=>{const b=Y(!1),x=Ge();let g=null;function v(T){Le(i,{align:"end",behavior:T,index:"LAST"})}Qe(U(wt(U(Ne(t),tr(1)),l),Be(Ne(b),s,a,f),ae(([[T,k],E,A,j,P])=>{let L=k&&j,$="auto";return L&&($=nv(E,A||P),L=L&&!!$),{followOutputBehavior:$,shouldFollow:L,totalCount:T}}),Ae(({shouldFollow:T})=>T)),({followOutputBehavior:T,totalCount:k})=>{g&&(g(),g=null),vt(n)?requestAnimationFrame(()=>{vt(d)("following output to ",{totalCount:k},Ft.DEBUG),v(T)}):g=an(e,()=>{vt(d)("following output to ",{totalCount:k},Ft.DEBUG),v(T),g=null})});function w(T){const k=an(o,E=>{T&&!E.atBottom&&E.notAtBottomBecause==="SIZE_INCREASED"&&!g&&(vt(d)("scrolling to bottom due to increased size",{},Ft.DEBUG),v("auto"))});setTimeout(k,100)}Qe(U(wt(Ne(b),t,u),Ae(([T,,k])=>T&&k),vn(({value:T},[,k])=>({refreshed:T===k,value:k}),{refreshed:!1,value:0}),Ae(({refreshed:T})=>T),Be(b,t)),([,T])=>{vt(a)&&w(T!==!1)}),Qe(x,()=>{w(vt(b)!==!1)}),Qe(wt(Ne(b),o),([T,k])=>{T&&!k.atBottom&&k.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&v("auto")});const S=Y(null),N=Ge();return be(Di(U(Ne(r),ae(T=>{var k;return(k=T==null?void 0:T.length)!=null?k:0})),U(Ne(t))),N),Qe(U(wt(U(N,tr(1)),l),Be(Ne(S),a,f,h),ae(([[T,k],E,A,j,P])=>k&&A&&(E==null?void 0:E({context:P,totalCount:T,scrollingInProgress:j}))),Ae(T=>!!T),_n(0)),T=>{g&&(g(),g=null),vt(n)?requestAnimationFrame(()=>{vt(d)("scrolling into view",{}),Le(p,T)}):g=an(e,()=>{vt(d)("scrolling into view",{}),Le(p,T),g=null})}),{autoscrollToBottom:x,followOutput:b,scrollIntoViewOnChange:S}},lt(bn,oo,eo,to,Fn,Ln,Pt,au,lu)),ov=Ze(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:s,listState:i},{didMount:a}])=>(be(U(a,Be(s),Ae(([,l])=>l!==0),Be(o,r,t,n,e),ae(([[,l],u,d,f,h,p=[]])=>ou(l,u,d,f,h,p))),i),{}),lt(bn,to,or,Fn),{singleton:!0}),sv=Ze(([{didMount:e},{scrollTo:t},{listState:n}])=>{const r=Y(0);return Qe(U(e,Be(r),Ae(([,o])=>o!==0),ae(([,o])=>({top:o}))),o=>{an(U(n,tr(1),Ae(s=>s.items.length>1)),()=>{requestAnimationFrame(()=>{Le(t,o)})})}),{initialScrollTop:r}},lt(Fn,Pt,or),{singleton:!0}),uu=Ze(([{scrollVelocity:e}])=>{const t=Y(!1),n=Ge(),r=Y(!1);return be(U(e,Be(r,t,n),Ae(([o,s])=>!!s),ae(([o,s,i,a])=>{const{enter:l,exit:u}=s;if(i){if(u(o,a))return!1}else if(l(o,a))return!0;return i}),ct()),t),Qe(U(wt(t,e,n),Be(r)),([[o,s,i],a])=>{o&&a&&a.change&&a.change(s,i)}),{isSeeking:t,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:e}},lt(oo),{singleton:!0}),Yi=Ze(([{scrollContainerState:e,scrollTo:t}])=>{const n=Ge(),r=Ge(),o=Ge(),s=Y(!1),i=Y(void 0);return be(U(wt(n,r),ae(([{scrollHeight:a,scrollTop:l,viewportHeight:u},{offsetTop:d}])=>({scrollHeight:a,scrollTop:Math.max(0,l-d),viewportHeight:u}))),e),be(U(t,Be(r),ae(([a,{offsetTop:l}])=>({...a,top:a.top+l}))),o),{customScrollParent:i,useWindowScroll:s,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:r}},lt(Pt)),iv=Ze(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:o},{didMount:s},{useWindowScroll:i,windowScrollContainerState:a,windowViewportRect:l}])=>{const u=Ge(),d=Y(void 0),f=Y(null),h=Y(null);return be(a,f),be(l,h),Qe(U(u,Be(t,r,i,f,h,n)),([p,b,x,g,v,w,S])=>{const N=Ux(b.sizeTree);g&&v!==null&&w!==null&&(x=v.scrollTop-w.offsetTop),x-=S,p({ranges:N,scrollTop:x})}),be(U(d,Ae(Oi),ae(av)),o),be(U(s,Be(d),Ae(([,p])=>p!==void 0),ct(),ae(([,p])=>p.ranges)),e),{getState:u,restoreStateFrom:d}},lt(bn,Pt,to,Fn,Yi));function av(e){return{align:"start",index:0,offset:e.scrollTop}}const lv=Ze(([{topItemsIndexes:e}])=>{const t=Y(0);return be(U(t,Ae(n=>n>=0),ae(n=>Array.from({length:n}).map((r,o)=>o))),e),{topItemCount:t}},lt(or));function du(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const cv=du(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),uv=Ze(([{deviation:e,scrollBy:t,scrollingInProgress:n,scrollTop:r},{isAtBottom:o,isScrolling:s,lastJumpDueToItemResize:i,scrollDirection:a},{listState:l},{beforeUnshiftWith:u,gap:d,shiftWithOffset:f,sizes:h},{log:p},{recalcInProgress:b}])=>{const x=Ht(U(l,Be(i),vn(([,v,w,S],[{bottom:N,items:T,offsetBottom:k,totalCount:E},A])=>{const j=N+k;let P=0;return w===E&&v.length>0&&T.length>0&&(T[0].originalIndex===0&&v[0].originalIndex===0||(P=j-S,P!==0&&(P+=A))),[P,T,E,j]},[0,[],0,0]),Ae(([v])=>v!==0),Be(r,a,n,o,p,b),Ae(([,v,w,S,,,N])=>!N&&!S&&v!==0&&w===no),ae(([[v],,,,,w])=>(w("Upward scrolling compensation",{amount:v},Ft.DEBUG),v))));function g(v){v>0?(Le(t,{behavior:"auto",top:-v}),Le(e,0)):(Le(e,0),Le(t,{behavior:"auto",top:-v}))}return Qe(U(x,Be(e,s)),([v,w,S])=>{S&&cv()?Le(e,w-v):g(-v)}),Qe(U(wt(Nt(s,!1),e,b),Ae(([v,w,S])=>!v&&!S&&w!==0),ae(([v,w])=>w),_n(1)),g),be(U(f,ae(v=>({top:-v}))),t),Qe(U(u,Be(h,d),ae(([v,{groupIndices:w,lastSize:S,sizeTree:N},T])=>{function k(E){return E*(S+T)}if(w.length===0)return k(v);{let E=0;const A=Jr(N,0);let j=0,P=0;for(;j<v;){j++,E+=A;let L=w.length===P+1?1/0:w[P+1]-w[P]-1;j+L>v&&(E-=A,L=v-j+1),j+=L,E+=k(L),P++}return E}})),v=>{Le(e,v),requestAnimationFrame(()=>{Le(t,{top:v}),requestAnimationFrame(()=>{Le(e,0),Le(b,!1)})})}),{deviation:e}},lt(Pt,oo,or,bn,Ln,Hi)),dv=Ze(([e,t,n,r,o,s,i,a,l,u,d])=>({...e,...t,...n,...r,...o,...s,...i,...a,...l,...u,...d}),lt(qi,ov,Fn,uu,iu,sv,ev,Yi,lu,Ln,au)),fu=Ze(([{data:e,defaultItemSize:t,firstItemIndex:n,fixedItemSize:r,gap:o,groupIndices:s,itemSize:i,sizeRanges:a,sizes:l,statefulTotalCount:u,totalCount:d,trackItemSizes:f},{initialItemFinalLocationReached:h,initialTopMostItemIndex:p,scrolledToInitialItem:b},x,g,v,{listState:w,topItemsIndexes:S,...N},{scrollToIndex:T},k,{topItemCount:E},{groupCounts:A},j])=>(be(N.rangeChanged,j.scrollSeekRangeChanged),be(U(j.windowViewportRect,ae(P=>P.visibleHeight)),x.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:n,fixedItemHeight:r,gap:o,groupCounts:A,initialItemFinalLocationReached:h,initialTopMostItemIndex:p,scrolledToInitialItem:b,sizeRanges:a,topItemCount:E,topItemsIndexes:S,totalCount:d,...v,groupIndices:s,itemSize:i,listState:w,scrollToIndex:T,statefulTotalCount:u,trackItemSizes:f,...N,...j,...x,sizes:l,...g}),lt(bn,to,Pt,iv,rv,or,eo,uv,lv,Zc,dv));function fv(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 Zo=typeof document<"u"?y.useLayoutEffect:y.useEffect;function hu(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=y.createContext({});function l(g,v){g.propsReady&&Le(g.propsReady,!1);for(const w of r){const S=g[t.required[w]];Le(S,v[w])}for(const w of o)if(w in v){const S=g[t.optional[w]];Le(S,v[w])}g.propsReady&&Le(g.propsReady,!0)}function u(g){return s.reduce((v,w)=>(v[w]=S=>{const N=g[t.methods[w]];Le(N,S)},v),{})}function d(g){return i.reduce((v,w)=>(v[w]=Nx(g[t.events[w]]),v),{})}const f=y.forwardRef((g,v)=>{const{children:w,...S}=g,[N]=y.useState(()=>Wo(_x(e),E=>{l(E,S)})),[T]=y.useState(Dc(d,N));Zo(()=>{for(const E of i)E in S&&Qe(T[E],S[E]);return()=>{Object.values(T).map(Mi)}},[S,T,N]),Zo(()=>{l(N,S)}),y.useImperativeHandle(v,Oc(u(N)));const k=n;return c.jsx(a.Provider,{value:N,children:n?c.jsx(k,{...fv([...r,...o,...i],S),children:w}):w})}),h=g=>{const v=y.useContext(a);return y.useCallback(w=>{Le(v[g],w)},[v,g])},p=g=>{const v=y.useContext(a)[g],w=y.useCallback(S=>Qe(v,S),[v]);return y.useSyncExternalStore(w,()=>vt(v),()=>vt(v))},b=g=>{const v=y.useContext(a)[g],[w,S]=y.useState(Dc(vt,v));return Zo(()=>Qe(v,N=>{N!==w&&S(Oc(N))}),[v,w]),w},x=y.version.startsWith("18")?p:b;return{Component:f,useEmitter:(g,v)=>{const w=y.useContext(a)[g];Zo(()=>Qe(w,v),[v,w])},useEmitterValue:x,usePublisher:h}}const pu=y.createContext(void 0),mu=y.createContext(void 0),gu=typeof document<"u"?y.useLayoutEffect:y.useEffect;function Xi(e){return"self"in e}function hv(e){return"body"in e}function xu(e,t,n,r=Er,o,s){const i=y.useRef(null),a=y.useRef(null),l=y.useRef(null),u=y.useCallback(h=>{let p,b,x;const g=h.target;if(hv(g)||Xi(g)){const w=Xi(g)?g:g.defaultView;x=s?w.scrollX:w.scrollY,p=s?w.document.documentElement.scrollWidth:w.document.documentElement.scrollHeight,b=s?w.innerWidth:w.innerHeight}else x=s?g.scrollLeft:g.scrollTop,p=s?g.scrollWidth:g.scrollHeight,b=s?g.offsetWidth:g.offsetHeight;const v=()=>{e({scrollHeight:p,scrollTop:Math.max(x,0),viewportHeight:b})};h.suppressFlushSync?v():ii.flushSync(v),a.current!==null&&(x===a.current||x<=0||x===p-b)&&(a.current=null,t(!0),l.current&&(clearTimeout(l.current),l.current=null))},[e,t,s]);y.useEffect(()=>{const h=o||i.current;return r(o||i.current),u({suppressFlushSync:!0,target:h}),h.addEventListener("scroll",u,{passive:!0}),()=>{r(null),h.removeEventListener("scroll",u)}},[i,u,n,r,o]);function d(h){const p=i.current;if(!p||(s?"offsetWidth"in p&&p.offsetWidth===0:"offsetHeight"in p&&p.offsetHeight===0))return;const b=h.behavior==="smooth";let x,g,v;Xi(p)?(g=Math.max($n(p.document.documentElement,s?"width":"height"),s?p.document.documentElement.scrollWidth:p.document.documentElement.scrollHeight),x=s?p.innerWidth:p.innerHeight,v=s?window.scrollX:window.scrollY):(g=p[s?"scrollWidth":"scrollHeight"],x=$n(p,s?"width":"height"),v=p[s?"scrollLeft":"scrollTop"]);const w=g-x;if(h.top=Math.ceil(Math.max(Math.min(w,h.top),0)),eu(x,g)||h.top===v){e({scrollHeight:g,scrollTop:v,viewportHeight:x}),b&&t(!0);return}b?(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 Ji="-webkit-sticky",vu="sticky",Zi=du(()=>{if(typeof document>"u")return vu;const e=document.createElement("div");return e.style.position=Ji,e.style.position===Ji?Ji:vu});function Qi(e){return e}const pv=Ze(()=>{const e=Y(a=>`Item ${a}`),t=Y(a=>`Group ${a}`),n=Y({}),r=Y(Qi),o=Y("div"),s=Y(Er),i=(a,l=null)=>Nt(U(n,ae(u=>u[a]),ct()),l);return{components:n,computeItemKey:r,EmptyPlaceholder:i("EmptyPlaceholder"),FooterComponent:i("Footer"),GroupComponent:i("Group","div"),groupContent:t,HeaderComponent:i("Header"),HeaderFooterTag:o,ItemComponent:i("Item","div"),itemContent:e,ListComponent:i("List","div"),ScrollerComponent:i("Scroller","div"),scrollerRef:s,ScrollSeekPlaceholder:i("ScrollSeekPlaceholder"),TopItemListComponent:i("TopItemList")}}),mv=Ze(([e,t])=>({...e,...t}),lt(fu,pv)),gv=({height:e})=>c.jsx("div",{style:{height:e}}),xv={overflowAnchor:"none",position:Zi(),zIndex:1},bu={overflowAnchor:"none"},vv={...bu,display:"inline-block",height:"100%"},wu=y.memo(function({showTopList:e=!1}){const t=Re("listState"),n=Xt("sizeRanges"),r=Re("useWindowScroll"),o=Re("customScrollParent"),s=Xt("windowScrollContainerState"),i=Xt("scrollContainerState"),a=o||r?s:i,l=Re("itemContent"),u=Re("context"),d=Re("groupContent"),f=Re("trackItemSizes"),h=Re("itemSize"),p=Re("log"),b=Xt("gap"),x=Re("horizontalDirection"),{callbackRef:g}=Px(n,h,f,e?Er:a,p,b,o,x,Re("skipAnimationFrameInResizeObserver")),[v,w]=y.useState(0);ea("deviation",M=>{v!==M&&w(M)});const S=Re("EmptyPlaceholder"),N=Re("ScrollSeekPlaceholder")||gv,T=Re("ListComponent"),k=Re("ItemComponent"),E=Re("GroupComponent"),A=Re("computeItemKey"),j=Re("isSeeking"),P=Re("groupIndices").length>0,L=Re("alignToBottom"),$=Re("initialItemFinalLocationReached"),V=e?{}:{boxSizing:"border-box",...x?{display:"inline-block",height:"100%",marginLeft:v!==0?v:L?"auto":0,paddingLeft:t.offsetTop,paddingRight:t.offsetBottom,whiteSpace:"nowrap"}:{marginTop:v!==0?v:L?"auto":0,paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},...$?{}:{visibility:"hidden"}};return!e&&t.totalCount===0&&S?c.jsx(S,{...At(S,u)}):c.jsx(T,{...At(T,u),"data-testid":e?"virtuoso-top-item-list":"virtuoso-item-list",ref:g,style:V,children:(e?t.topItems:t.items).map(M=>{const G=M.originalIndex,K=A(G+t.firstItemIndex,M.data,u);return j?y.createElement(N,{...At(N,u),height:M.size,index:M.index,key:K,type:M.type||"item",...M.type==="group"?{}:{groupIndex:M.groupIndex}}):M.type==="group"?y.createElement(E,{...At(E,u),"data-index":G,"data-item-index":M.index,"data-known-size":M.size,key:K,style:xv},d(M.index,u)):y.createElement(k,{...At(k,u),...Sv(k,M.data),"data-index":G,"data-item-group-index":M.groupIndex,"data-item-index":M.index,"data-known-size":M.size,key:K,style:x?vv:bu},P?l(M.index,M.groupIndex,M.data,u):l(M.index,M.data,u))})})}),bv={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},wv={outline:"none",overflowX:"auto",position:"relative"},Qo=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),yv={position:Zi(),top:0,width:"100%",zIndex:1};function At(e,t){if(typeof e!="string")return{context:t}}function Sv(e,t){return{item:typeof e=="string"?void 0:t}}const Cv=y.memo(function(){const e=Re("HeaderComponent"),t=Xt("headerHeight"),n=Re("HeaderFooterTag"),r=nr(y.useMemo(()=>s=>{t($n(s,"height"))},[t]),!0,Re("skipAnimationFrameInResizeObserver")),o=Re("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...At(e,o)})}):null}),Tv=y.memo(function(){const e=Re("FooterComponent"),t=Xt("footerHeight"),n=Re("HeaderFooterTag"),r=nr(y.useMemo(()=>s=>{t($n(s,"height"))},[t]),!0,Re("skipAnimationFrameInResizeObserver")),o=Re("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...At(e,o)})}):null});function yu({useEmitter:e,useEmitterValue:t,usePublisher:n}){return y.memo(function({children:r,style:o,context:s,...i}){const a=n("scrollContainerState"),l=t("ScrollerComponent"),u=n("smoothScrollTargetReached"),d=t("scrollerRef"),f=t("horizontalDirection")||!1,{scrollByCallback:h,scrollerRef:p,scrollToCallback:b}=xu(a,u,l,d,void 0,f);return e("scrollTo",b),e("scrollBy",h),c.jsx(l,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:p,style:{...f?wv:bv,...o},tabIndex:0,...i,...At(l,s),children:r})})}function Su({useEmitter:e,useEmitterValue:t,usePublisher:n}){return y.memo(function({children:r,style:o,context:s,...i}){const a=n("windowScrollContainerState"),l=t("ScrollerComponent"),u=n("smoothScrollTargetReached"),d=t("totalListHeight"),f=t("deviation"),h=t("customScrollParent"),p=y.useRef(null),b=t("scrollerRef"),{scrollByCallback:x,scrollerRef:g,scrollToCallback:v}=xu(a,u,l,b,h);return gu(()=>{var w;return g.current=h||((w=p.current)==null?void 0:w.ownerDocument.defaultView),()=>{g.current=null}},[g,h]),e("windowScrollTo",v),e("scrollBy",x),c.jsx(l,{ref:p,"data-virtuoso-scroller":!0,style:{position:"relative",...o,...d!==0?{height:d+f}:{}},...i,...At(l,s),children:r})})}const kv=({children:e})=>{const t=y.useContext(pu),n=Xt("viewportHeight"),r=Xt("fixedItemHeight"),o=Re("alignToBottom"),s=Re("horizontalDirection"),i=y.useMemo(()=>Mc(n,l=>$n(l,s?"width":"height")),[n,s]),a=nr(i,!0,Re("skipAnimationFrameInResizeObserver"));return y.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),c.jsx("div",{"data-viewport-type":"element",ref:a,style:Qo(o),children:e})},Iv=({children:e})=>{const t=y.useContext(pu),n=Xt("windowViewportRect"),r=Xt("fixedItemHeight"),o=Re("customScrollParent"),s=Bc(n,o,Re("skipAnimationFrameInResizeObserver")),i=Re("alignToBottom");return y.useEffect(()=>{t&&(r(t.itemHeight),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:100}))},[t,n,r]),c.jsx("div",{"data-viewport-type":"window",ref:s,style:Qo(i),children:e})},Ev=({children:e})=>{const t=Re("TopItemListComponent")||"div",n=Re("headerHeight"),r={...yv,marginTop:`${n}px`},o=Re("context");return c.jsx(t,{style:r,...At(t,o),children:e})},Nv=y.memo(function(e){const t=Re("useWindowScroll"),n=Re("topItemsIndexes").length>0,r=Re("customScrollParent"),o=Re("context");return c.jsxs(r||t?jv:_v,{...e,context:o,children:[n&&c.jsx(Ev,{children:c.jsx(wu,{showTopList:!0})}),c.jsxs(r||t?Iv:kv,{children:[c.jsx(Cv,{}),c.jsx(wu,{}),c.jsx(Tv,{})]})]})}),{Component:Av,useEmitter:ea,useEmitterValue:Re,usePublisher:Xt}=hu(mv,{required:{},optional:{restoreStateFrom:"restoreStateFrom",context:"context",followOutput:"followOutput",scrollIntoViewOnChange:"scrollIntoViewOnChange",itemContent:"itemContent",groupContent:"groupContent",overscan:"overscan",increaseViewportBy:"increaseViewportBy",totalCount:"totalCount",groupCounts:"groupCounts",topItemCount:"topItemCount",firstItemIndex:"firstItemIndex",initialTopMostItemIndex:"initialTopMostItemIndex",components:"components",atBottomThreshold:"atBottomThreshold",atTopThreshold:"atTopThreshold",computeItemKey:"computeItemKey",defaultItemHeight:"defaultItemHeight",fixedItemHeight:"fixedItemHeight",itemSize:"itemSize",scrollSeekConfiguration:"scrollSeekConfiguration",headerFooterTag:"HeaderFooterTag",data:"data",initialItemCount:"initialItemCount",initialScrollTop:"initialScrollTop",alignToBottom:"alignToBottom",useWindowScroll:"useWindowScroll",customScrollParent:"customScrollParent",scrollerRef:"scrollerRef",logLevel:"logLevel",horizontalDirection:"horizontalDirection",skipAnimationFrameInResizeObserver:"skipAnimationFrameInResizeObserver"},methods:{scrollToIndex:"scrollToIndex",scrollIntoView:"scrollIntoView",scrollTo:"scrollTo",scrollBy:"scrollBy",autoscrollToBottom:"autoscrollToBottom",getState:"getState"},events:{isScrolling:"isScrolling",endReached:"endReached",startReached:"startReached",rangeChanged:"rangeChanged",atBottomStateChange:"atBottomStateChange",atTopStateChange:"atTopStateChange",totalListHeightChanged:"totalListHeightChanged",itemsRendered:"itemsRendered",groupIndices:"groupIndices"}},Nv),_v=yu({useEmitter:ea,useEmitterValue:Re,usePublisher:Xt}),jv=Su({useEmitter:ea,useEmitterValue:Re,usePublisher:Xt}),Rv=Av;lt(fu,Ze(()=>{const e=Y(u=>c.jsxs("td",{children:["Item $",u]})),t=Y(null),n=Y(u=>c.jsxs("td",{colSpan:1e3,children:["Group ",u]})),r=Y(null),o=Y(null),s=Y({}),i=Y(Qi),a=Y(Er),l=(u,d=null)=>Nt(U(s,ae(f=>f[u]),ct()),d);return{components:s,computeItemKey:i,context:t,EmptyPlaceholder:l("EmptyPlaceholder"),FillerRow:l("FillerRow"),fixedFooterContent:o,fixedHeaderContent:r,itemContent:e,groupContent:n,ScrollerComponent:l("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder"),TableBodyComponent:l("TableBody","tbody"),TableComponent:l("Table","table"),TableFooterComponent:l("TableFoot","tfoot"),TableHeadComponent:l("TableHead","thead"),TableRowComponent:l("TableRow","tr"),GroupComponent:l("Group","tr")}})),Zi();const Cu={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},Pv={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:Tu,floor:es,max:so,min:ta,round:ku}=Math;function Iu(e,t,n){return Array.from({length:t-e+1}).map((r,o)=>({data:n===null?null:n[o+e],index:o+e}))}function Ov(e){return{...Pv,items:e}}function ts(e,t){return e&&e.width===t.width&&e.height===t.height}function Mv(e,t){return e&&e.column===t.column&&e.row===t.row}const Dv=Ze(([{increaseViewportBy:e,listBoundary:t,overscan:n,visibleRange:r},{footerHeight:o,headerHeight:s,scrollBy:i,scrollContainerState:a,scrollTo:l,scrollTop:u,smoothScrollTargetReached:d,viewportHeight:f},h,p,{didMount:b,propsReady:x},{customScrollParent:g,useWindowScroll:v,windowScrollContainerState:w,windowScrollTo:S,windowViewportRect:N},T])=>{const k=Y(0),E=Y(0),A=Y(Cu),j=Y({height:0,width:0}),P=Y({height:0,width:0}),L=Ge(),$=Ge(),V=Y(0),M=Y(null),G=Y({column:0,row:0}),K=Ge(),W=Ge(),B=Y(!1),F=Y(0),ue=Y(!0),D=Y(!1),ee=Y(!1);Qe(U(b,Be(F),Ae(([O,X])=>!!X)),()=>{Le(ue,!1)}),Qe(U(wt(b,ue,P,j,F,D),Ae(([O,X,te,he,,re])=>O&&!X&&te.height!==0&&he.height!==0&&!re)),([,,,,O])=>{Le(D,!0),Vi(1,()=>{Le(L,O)}),an(U(u),()=>{Le(t,[0,0]),Le(ue,!0)})}),be(U(W,Ae(O=>O!=null&&O.scrollTop>0),xn(0)),E),Qe(U(b,Be(W),Ae(([,O])=>O!=null)),([,O])=>{O&&(Le(j,O.viewport),Le(P,O.item),Le(G,O.gap),O.scrollTop>0&&(Le(B,!0),an(U(u,tr(1)),X=>{Le(B,!1)}),Le(l,{top:O.scrollTop})))}),be(U(j,ae(({height:O})=>O)),f),be(U(wt(Ne(j,ts),Ne(P,ts),Ne(G,(O,X)=>O&&O.column===X.column&&O.row===X.row),Ne(u)),ae(([O,X,te,he])=>({gap:te,item:X,scrollTop:he,viewport:O}))),K),be(U(wt(Ne(k),r,Ne(G,Mv),Ne(P,ts),Ne(j,ts),Ne(M),Ne(E),Ne(B),Ne(ue),Ne(F)),Ae(([,,,,,,,O])=>!O),ae(([O,[X,te],he,re,pe,tt,nt,,Pe,He])=>{const{column:ut,row:rt}=he,{height:Ue,width:bt}=re,{width:Z}=pe;if(nt===0&&(O===0||Z===0))return Cu;if(bt===0){const mt=Ki(He,O),Ct=mt+Math.max(nt-1,0);return Ov(Iu(mt,Ct,tt))}const oe=Eu(Z,bt,ut);let me,Te;Pe?X===0&&te===0&&nt>0?(me=0,Te=nt-1):(me=oe*es((X+rt)/(Ue+rt)),Te=oe*Tu((te+rt)/(Ue+rt))-1,Te=ta(O-1,so(Te,oe-1)),me=ta(Te,so(0,me))):(me=0,Te=-1);const ge=Iu(me,Te,tt),{bottom:Oe,top:at}=Nu(pe,he,re,ge),Me=Tu(O/oe),it=Me*Ue+(Me-1)*rt-Oe;return{bottom:Oe,itemHeight:Ue,items:ge,itemWidth:bt,offsetBottom:it,offsetTop:at,top:at}})),A),be(U(M,Ae(O=>O!==null),ae(O=>O.length)),k),be(U(wt(j,P,A,G),Ae(([O,X,{items:te}])=>te.length>0&&X.height!==0&&O.height!==0),ae(([O,X,{items:te},he])=>{const{bottom:re,top:pe}=Nu(O,he,X,te);return[pe,re]}),ct(Zr)),t);const fe=Y(!1);be(U(u,Be(fe),ae(([O,X])=>X||O!==0)),fe);const we=Ht(U(wt(A,k),Ae(([{items:O}])=>O.length>0),Be(fe),Ae(([[O,X],te])=>{const he=O.items[O.items.length-1].index===X-1;return(te||O.bottom>0&&O.itemHeight>0&&O.offsetBottom===0&&O.items.length===X)&&he}),ae(([[,O]])=>O-1),ct())),ye=Ht(U(Ne(A),Ae(({items:O})=>O.length>0&&O[0].index===0),xn(0),ct())),Ce=Ht(U(Ne(A),Be(B),Ae(([{items:O},X])=>O.length>0&&!X),ae(([{items:O}])=>({endIndex:O[O.length-1].index,startIndex:O[0].index})),ct(qc),_n(0)));be(Ce,p.scrollSeekRangeChanged),be(U(L,Be(j,P,k,G),ae(([O,X,te,he,re])=>{const pe=Qc(O),{align:tt,behavior:nt,offset:Pe}=pe;let He=pe.index;He==="LAST"&&(He=he-1),He=so(0,He,ta(he-1,He));let ut=na(X,re,te,He);return tt==="end"?ut=ku(ut-X.height+te.height):tt==="center"&&(ut=ku(ut-X.height/2+te.height/2)),Pe&&(ut+=Pe),{behavior:nt,top:ut}})),l);const q=Nt(U(A,ae(O=>O.offsetBottom+O.bottom)),0);return be(U(N,ae(O=>({height:O.visibleHeight,width:O.visibleWidth}))),j),{customScrollParent:g,data:M,deviation:V,footerHeight:o,gap:G,headerHeight:s,increaseViewportBy:e,initialItemCount:E,itemDimensions:P,overscan:n,restoreStateFrom:W,scrollBy:i,scrollContainerState:a,scrollHeight:$,scrollTo:l,scrollToIndex:L,scrollTop:u,smoothScrollTargetReached:d,totalCount:k,useWindowScroll:v,viewportDimensions:j,windowScrollContainerState:w,windowScrollTo:S,windowViewportRect:N,...p,gridState:A,horizontalDirection:ee,initialTopMostItemIndex:F,totalListHeight:q,...h,endReached:we,propsReady:x,rangeChanged:Ce,startReached:ye,stateChanged:K,stateRestoreInProgress:B,...T}},lt(qi,Pt,oo,uu,Fn,Yi,Ln));function Eu(e,t,n){return so(1,es((e+n)/(es(t)+n)))}function Nu(e,t,n,r){const{height:o}=n;if(o===void 0||r.length===0)return{bottom:0,top:0};const s=na(e,t,n,r[0].index);return{bottom:na(e,t,n,r[r.length-1].index)+o,top:s}}function na(e,t,n,r){const o=Eu(e.width,n.width,t.column),s=es(r/o),i=s*n.height+so(0,s-1)*t.row;return i>0?i+t.row:i}const Lv=Ze(()=>{const e=Y(f=>`Item ${f}`),t=Y({}),n=Y(null),r=Y("virtuoso-grid-item"),o=Y("virtuoso-grid-list"),s=Y(Qi),i=Y("div"),a=Y(Er),l=(f,h=null)=>Nt(U(t,ae(p=>p[f]),ct()),h),u=Y(!1),d=Y(!1);return be(Ne(d),u),{components:t,computeItemKey:s,context:n,FooterComponent:l("Footer"),HeaderComponent:l("Header"),headerFooterTag:i,itemClassName:r,ItemComponent:l("Item","div"),itemContent:e,listClassName:o,ListComponent:l("List","div"),readyStateChanged:u,reportReadyState:d,ScrollerComponent:l("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder","div")}}),$v=Ze(([e,t])=>({...e,...t}),lt(Dv,Lv)),Fv=y.memo(function(){const e=ft("gridState"),t=ft("listClassName"),n=ft("itemClassName"),r=ft("itemContent"),o=ft("computeItemKey"),s=ft("isSeeking"),i=Jt("scrollHeight"),a=ft("ItemComponent"),l=ft("ListComponent"),u=ft("ScrollSeekPlaceholder"),d=ft("context"),f=Jt("itemDimensions"),h=Jt("gap"),p=ft("log"),b=ft("stateRestoreInProgress"),x=Jt("reportReadyState"),g=nr(y.useMemo(()=>v=>{const w=v.parentElement.parentElement.scrollHeight;i(w);const S=v.firstChild;if(S){const{height:N,width:T}=S.getBoundingClientRect();f({height:N,width:T})}h({column:_u("column-gap",getComputedStyle(v).columnGap,p),row:_u("row-gap",getComputedStyle(v).rowGap,p)})},[i,f,h,p]),!0,!1);return gu(()=>{e.itemHeight>0&&e.itemWidth>0&&x(!0)},[e]),b?null:c.jsx(l,{className:t,ref:g,...At(l,d),"data-testid":"virtuoso-item-list",style:{paddingBottom:e.offsetBottom,paddingTop:e.offsetTop},children:e.items.map(v=>{const w=o(v.index,v.data,d);return s?c.jsx(u,{...At(u,d),height:e.itemHeight,index:v.index,width:e.itemWidth},w):y.createElement(a,{...At(a,d),className:n,"data-index":v.index,key:w},r(v.index,v.data,d))})})}),Bv=y.memo(function(){const e=ft("HeaderComponent"),t=Jt("headerHeight"),n=ft("headerFooterTag"),r=nr(y.useMemo(()=>s=>{t($n(s,"height"))},[t]),!0,!1),o=ft("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...At(e,o)})}):null}),zv=y.memo(function(){const e=ft("FooterComponent"),t=Jt("footerHeight"),n=ft("headerFooterTag"),r=nr(y.useMemo(()=>s=>{t($n(s,"height"))},[t]),!0,!1),o=ft("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...At(e,o)})}):null}),Hv=({children:e})=>{const t=y.useContext(mu),n=Jt("itemDimensions"),r=Jt("viewportDimensions"),o=nr(y.useMemo(()=>s=>{r(s.getBoundingClientRect())},[r]),!0,!1);return y.useEffect(()=>{t&&(r({height:t.viewportHeight,width:t.viewportWidth}),n({height:t.itemHeight,width:t.itemWidth}))},[t,r,n]),c.jsx("div",{ref:o,style:Qo(!1),children:e})},Uv=({children:e})=>{const t=y.useContext(mu),n=Jt("windowViewportRect"),r=Jt("itemDimensions"),o=ft("customScrollParent"),s=Bc(n,o,!1);return y.useEffect(()=>{t&&(r({height:t.itemHeight,width:t.itemWidth}),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:t.viewportWidth}))},[t,n,r]),c.jsx("div",{ref:s,style:Qo(!1),children:e})},Wv=y.memo(function({...e}){const t=ft("useWindowScroll"),n=ft("customScrollParent"),r=n||t?Kv:Vv,o=n||t?Uv:Hv,s=ft("context");return c.jsx(r,{...e,...At(r,s),children:c.jsxs(o,{children:[c.jsx(Bv,{}),c.jsx(Fv,{}),c.jsx(zv,{})]})})}),{useEmitter:Au,useEmitterValue:ft,usePublisher:Jt}=hu($v,{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"}},Wv),Vv=yu({useEmitter:Au,useEmitterValue:ft,usePublisher:Jt}),Kv=Su({useEmitter:Au,useEmitterValue:ft,usePublisher:Jt});function _u(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Ft.WARN),t==="normal"?0:parseInt(t??"0",10)}const qv=To.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 ra({className:e,variant:t,...n}){return c.jsx("div",{className:Q(qv({variant:t}),e),...n})}function de(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 Gv(e,t){const n=m.createContext(t),r=s=>{const{children:i,...a}=s,l=m.useMemo(()=>a,Object.values(a));return c.jsx(n.Provider,{value:l,children:i})};r.displayName=e+"Provider";function o(s){const i=m.useContext(n);if(i)return i;if(t!==void 0)return t;throw new Error(`\`${s}\` must be used within \`${e}\``)}return[r,o]}function wn(e,t=[]){let n=[];function r(s,i){const a=m.createContext(i),l=n.length;n=[...n,i];const u=f=>{var v;const{scope:h,children:p,...b}=f,x=((v=h==null?void 0:h[e])==null?void 0:v[l])||a,g=m.useMemo(()=>b,Object.values(b));return c.jsx(x.Provider,{value:g,children:p})};u.displayName=s+"Provider";function d(f,h){var x;const p=((x=h==null?void 0:h[e])==null?void 0:x[l])||a,b=m.useContext(p);if(b)return b;if(i!==void 0)return i;throw new Error(`\`${f}\` must be used within \`${s}\``)}return[u,d]}const o=()=>{const s=n.map(i=>m.createContext(i));return function(a){const l=(a==null?void 0:a[e])||s;return m.useMemo(()=>({[`__scope${e}`]:{...a,[e]:l}}),[a,l])}};return o.scopeName=e,[r,Yv(o,...t)]}function Yv(...e){const t=e[0];if(e.length===1)return t;const n=()=>{const r=e.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(s){const i=r.reduce((a,{useScope:l,scopeName:u})=>{const f=l(s)[`__scope${u}`];return{...a,...f}},{});return m.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}var St=globalThis!=null&&globalThis.document?m.useLayoutEffect:()=>{},Xv=m[" useInsertionEffect ".trim().toString()]||St;function sr({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=Jv({defaultProp:t,onChange:n}),a=e!==void 0,l=a?e:o;{const d=m.useRef(e!==void 0);m.useEffect(()=>{const f=d.current;f!==a&&console.warn(`${r} is changing from ${f?"controlled":"uncontrolled"} to ${a?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),d.current=a},[a,r])}const u=m.useCallback(d=>{var f;if(a){const h=Zv(d)?d(e):d;h!==e&&((f=i.current)==null||f.call(i,h))}else s(d)},[a,e,s,i]);return[l,u]}function Jv({defaultProp:e,onChange:t}){const[n,r]=m.useState(e),o=m.useRef(n),s=m.useRef(t);return Xv(()=>{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 Zv(e){return typeof e=="function"}function ju(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function oa(...e){return t=>{let n=!1;const r=e.map(o=>{const s=ju(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():ju(e[o],null)}}}}function Ke(...e){return m.useCallback(oa(...e),e)}var Qv=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],_e=Qv.reduce((e,t)=>{const n=Jn.createSlot(`Primitive.${t}`),r=m.forwardRef((o,s)=>{const{asChild:i,...a}=o,l=i?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),c.jsx(l,{...a,ref:s})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function Ru(e,t){e&&ko.flushSync(()=>e.dispatchEvent(t))}function eb(e,t){return m.useReducer((n,r)=>t[n][r]??n,e)}var Wt=e=>{const{present:t,children:n}=e,r=tb(t),o=typeof n=="function"?n({present:r.isPresent}):m.Children.only(n),s=Ke(r.ref,nb(o));return typeof n=="function"||r.isPresent?m.cloneElement(o,{ref:s}):null};Wt.displayName="Presence";function tb(e){const[t,n]=m.useState(),r=m.useRef(null),o=m.useRef(e),s=m.useRef("none"),i=e?"mounted":"unmounted",[a,l]=eb(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return m.useEffect(()=>{const u=ns(r.current);s.current=a==="mounted"?u:"none"},[a]),St(()=>{const u=r.current,d=o.current;if(d!==e){const h=s.current,p=ns(u);e?l("MOUNT"):p==="none"||(u==null?void 0:u.display)==="none"?l("UNMOUNT"):l(d&&h!==p?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,l]),St(()=>{if(t){let u;const d=t.ownerDocument.defaultView??window,f=p=>{const x=ns(r.current).includes(CSS.escape(p.animationName));if(p.target===t&&x&&(l("ANIMATION_END"),!o.current)){const g=t.style.animationFillMode;t.style.animationFillMode="forwards",u=d.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=g)})}},h=p=>{p.target===t&&(s.current=ns(r.current))};return t.addEventListener("animationstart",h),t.addEventListener("animationcancel",f),t.addEventListener("animationend",f),()=>{d.clearTimeout(u),t.removeEventListener("animationstart",h),t.removeEventListener("animationcancel",f),t.removeEventListener("animationend",f)}}else l("ANIMATION_END")},[t,l]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:m.useCallback(u=>{r.current=u?getComputedStyle(u):null,n(u)},[])}}function ns(e){return(e==null?void 0:e.animationName)||"none"}function nb(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 rb=m[" useId ".trim().toString()]||(()=>{}),ob=0;function yn(e){const[t,n]=m.useState(rb());return St(()=>{n(r=>r??String(ob++))},[e]),e||(t?`radix-${t}`:"")}var rs="Collapsible",[sb,HT]=wn(rs),[ib,sa]=sb(rs),Pu=m.forwardRef((e,t)=>{const{__scopeCollapsible:n,open:r,defaultOpen:o,disabled:s,onOpenChange:i,...a}=e,[l,u]=sr({prop:r,defaultProp:o??!1,onChange:i,caller:rs});return c.jsx(ib,{scope:n,disabled:s,contentId:yn(),open:l,onOpenToggle:m.useCallback(()=>u(d=>!d),[u]),children:c.jsx(_e.div,{"data-state":aa(l),"data-disabled":s?"":void 0,...a,ref:t})})});Pu.displayName=rs;var Ou="CollapsibleTrigger",Mu=m.forwardRef((e,t)=>{const{__scopeCollapsible:n,...r}=e,o=sa(Ou,n);return c.jsx(_e.button,{type:"button","aria-controls":o.contentId,"aria-expanded":o.open||!1,"data-state":aa(o.open),"data-disabled":o.disabled?"":void 0,disabled:o.disabled,...r,ref:t,onClick:de(e.onClick,o.onOpenToggle)})});Mu.displayName=Ou;var ia="CollapsibleContent",ab=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=sa(ia,e.__scopeCollapsible);return c.jsx(Wt,{present:n||o.open,children:({present:s})=>c.jsx(lb,{...r,ref:t,present:s})})});ab.displayName=ia;var lb=m.forwardRef((e,t)=>{const{__scopeCollapsible:n,present:r,children:o,...s}=e,i=sa(ia,n),[a,l]=m.useState(r),u=m.useRef(null),d=Ke(t,u),f=m.useRef(0),h=f.current,p=m.useRef(0),b=p.current,x=i.open||a,g=m.useRef(x),v=m.useRef(void 0);return m.useEffect(()=>{const w=requestAnimationFrame(()=>g.current=!1);return()=>cancelAnimationFrame(w)},[]),St(()=>{const w=u.current;if(w){v.current=v.current||{transitionDuration:w.style.transitionDuration,animationName:w.style.animationName},w.style.transitionDuration="0s",w.style.animationName="none";const S=w.getBoundingClientRect();f.current=S.height,p.current=S.width,g.current||(w.style.transitionDuration=v.current.transitionDuration,w.style.animationName=v.current.animationName),l(r)}},[i.open,r]),c.jsx(_e.div,{"data-state":aa(i.open),"data-disabled":i.disabled?"":void 0,id:i.contentId,hidden:!x,...s,ref:d,style:{"--radix-collapsible-content-height":h?`${h}px`:void 0,"--radix-collapsible-content-width":b?`${b}px`:void 0,...e.style},children:x&&o})});function aa(e){return e?"open":"closed"}var cb=Pu;const Du=cb,Lu=Mu,io=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:Q("rounded-lg border bg-card text-card-foreground shadow-sm",e),...t}));io.displayName="Card";const ao=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:Q("flex flex-col space-y-1.5 p-6",e),...t}));ao.displayName="CardHeader";const lo=m.forwardRef(({className:e,...t},n)=>c.jsx("h3",{ref:n,className:Q("text-2xl font-semibold leading-none tracking-tight",e),...t}));lo.displayName="CardTitle";const $u=m.forwardRef(({className:e,...t},n)=>c.jsx("p",{ref:n,className:Q("text-sm text-muted-foreground",e),...t}));$u.displayName="CardDescription";const os=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:Q("p-6 pt-0",e),...t}));os.displayName="CardContent";const Fu=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:Q("flex items-center p-6 pt-0",e),...t}));Fu.displayName="CardFooter";function Bu(){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=Bu();function ub(e){ir=e}const zu=/[&<>"']/,db=new RegExp(zu.source,"g"),Hu=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,fb=new RegExp(Hu.source,"g"),hb={"&":"&","<":"<",">":">",'"':""","'":"'"},Uu=e=>hb[e];function _t(e,t){if(t){if(zu.test(e))return e.replace(db,Uu)}else if(Hu.test(e))return e.replace(fb,Uu);return e}const pb=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;function Wu(e){return e.replace(pb,(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 mb=/(^|[^\[])\^/g;function st(e,t){e=typeof e=="string"?e:e.source,t=t||"";const n={replace:(r,o)=>(o=o.source||o,o=o.replace(mb,"$1"),e=e.replace(r,o),n),getRegex:()=>new RegExp(e,t)};return n}const gb=/[^\w:]/g,xb=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function Vu(e,t,n){if(e){let r;try{r=decodeURIComponent(Wu(n)).replace(gb,"").toLowerCase()}catch{return null}if(r.indexOf("javascript:")===0||r.indexOf("vbscript:")===0||r.indexOf("data:")===0)return null}t&&!xb.test(n)&&(n=yb(t,n));try{n=encodeURI(n).replace(/%25/g,"%")}catch{return null}return n}const ss={},vb=/^[^:]+:\/*[^/]*$/,bb=/^([^:]+:)[\s\S]*$/,wb=/^([^:]+:\/*[^/]*)[\s\S]*$/;function yb(e,t){ss[" "+e]||(vb.test(e)?ss[" "+e]=e+"/":ss[" "+e]=as(e,"/",!0)),e=ss[" "+e];const n=e.indexOf(":")===-1;return t.substring(0,2)==="//"?n?t:e.replace(bb,"$1")+t:t.charAt(0)==="/"?n?t:e.replace(wb,"$1")+t:e+t}const is={exec:function(){}};function Ku(e,t){const n=e.replace(/\|/g,(s,i,a)=>{let l=!1,u=i;for(;--u>=0&&a[u]==="\\";)l=!l;return l?"|":" |"}),r=n.split(/ \|/);let o=0;if(r[0].trim()||r.shift(),r.length>0&&!r[r.length-1].trim()&&r.pop(),r.length>t)r.splice(t);else for(;r.length<t;)r.push("");for(;o<r.length;o++)r[o]=r[o].trim().replace(/\\\|/g,"|");return r}function as(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 Sb(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 Cb(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 qu(e,t){if(t<1)return"";let n="";for(;t>1;)t&1&&(n+=e),t>>=1,e+=e;return n+e}function Gu(e,t,n,r){const o=t.href,s=t.title?_t(t.title):null,i=e[1].replace(/\\([\[\]])/g,"$1");if(e[0].charAt(0)!=="!"){r.state.inLink=!0;const a={type:"link",raw:n,href:o,title:s,text:i,tokens:r.inlineTokens(i)};return r.state.inLink=!1,a}return{type:"image",raw:n,href:o,title:s,text:_t(i)}}function Tb(e,t){const n=e.match(/^(\s+)(?:```)/);if(n===null)return t;const r=n[1];return t.split(`
|
|
40
40
|
`).map(o=>{const s=o.match(/^\s+/);if(s===null)return o;const[i]=s;return i.length>=r.length?o.slice(r.length):o}).join(`
|
|
41
|
-
`)}class
|
|
42
|
-
`)}}}fences(t){const n=this.rules.block.fences.exec(t);if(n){const r=n[0],o=
|
|
41
|
+
`)}class la{constructor(t){this.options=t||ir}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:as(r,`
|
|
42
|
+
`)}}}fences(t){const n=this.rules.block.fences.exec(t);if(n){const r=n[0],o=Tb(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=as(r,"#");(this.options.pedantic||!o||/ $/.test(o))&&(r=o.trim())}return{type:"heading",raw:n[0],depth:n[1].length,text:r,tokens:this.lexer.inline(r)}}}hr(t){const n=this.rules.block.hr.exec(t);if(n)return{type:"hr",raw:n[0]}}blockquote(t){const n=this.rules.block.blockquote.exec(t);if(n){const r=n[0].replace(/^ *>[ \t]?/gm,""),o=this.lexer.state.top;this.lexer.state.top=!0;const s=this.lexer.blockTokens(r);return this.lexer.state.top=o,{type:"blockquote",raw:n[0],tokens:s,text:r}}}list(t){let n=this.rules.block.list.exec(t);if(n){let r,o,s,i,a,l,u,d,f,h,p,b,x=n[1].trim();const g=x.length>1,v={type:"list",raw:"",ordered:g,start:g?+x.slice(0,-1):"",loose:!1,items:[]};x=g?`\\d{1,9}\\${x.slice(-1)}`:`\\${x}`,this.options.pedantic&&(x=g?x:"[*+-]");const w=new RegExp(`^( {0,3}${x})((?:[ ][^\\n]*)?(?:\\n|$))`);for(;t&&(b=!1,!(!(n=w.exec(t))||this.rules.block.hr.test(t)));){if(r=n[0],t=t.substring(r.length),d=n[2].split(`
|
|
43
43
|
`,1)[0].replace(/^\t+/,N=>" ".repeat(3*N.length)),f=t.split(`
|
|
44
44
|
`,1)[0],this.options.pedantic?(i=2,p=d.trimLeft()):(i=n[2].search(/[^ ]/),i=i>4?1:i,p=d.slice(i),i+=n[1].length),l=!1,!d&&/^ *$/.test(f)&&(r+=f+`
|
|
45
|
-
`,t=t.substring(f.length+1),
|
|
46
|
-
`,1)[0],f=h,this.options.pedantic&&(f=f.replace(/^ {1,4}(?=( {4})*[^ ])/g," ")),!(k.test(f)||
|
|
47
|
-
`+f.slice(i);else{if(l||d.search(/[^ ]/)>=4||k.test(d)||
|
|
45
|
+
`,t=t.substring(f.length+1),b=!0),!b){const N=new RegExp(`^ {0,${Math.min(3,i-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),T=new RegExp(`^ {0,${Math.min(3,i-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),k=new RegExp(`^ {0,${Math.min(3,i-1)}}(?:\`\`\`|~~~)`),E=new RegExp(`^ {0,${Math.min(3,i-1)}}#`);for(;t&&(h=t.split(`
|
|
46
|
+
`,1)[0],f=h,this.options.pedantic&&(f=f.replace(/^ {1,4}(?=( {4})*[^ ])/g," ")),!(k.test(f)||E.test(f)||N.test(f)||T.test(t)));){if(f.search(/[^ ]/)>=i||!f.trim())p+=`
|
|
47
|
+
`+f.slice(i);else{if(l||d.search(/[^ ]/)>=4||k.test(d)||E.test(d)||T.test(d))break;p+=`
|
|
48
48
|
`+f}!l&&!f.trim()&&(l=!0),r+=h+`
|
|
49
|
-
`,t=t.substring(h.length+1),d=f.slice(i)}}v.loose||(u?v.loose=!0:/\n *\n *$/.test(r)&&(u=!0)),this.options.gfm&&(o=/^\[[ xX]\] /.exec(p),o&&(s=o[0]!=="[ ] ",p=p.replace(/^\[[ xX]\] +/,""))),v.items.push({type:"list_item",raw:r,task:!!o,checked:s,loose:!1,text:p}),v.raw+=r}v.items[v.items.length-1].raw=r.trimRight(),v.items[v.items.length-1].text=p.trimRight(),v.raw=v.raw.trimRight();const S=v.items.length;for(a=0;a<S;a++)if(this.lexer.state.top=!1,v.items[a].tokens=this.lexer.blockTokens(v.items[a].text,[]),!v.loose){const N=v.items[a].tokens.filter(k=>k.type==="space"),
|
|
50
|
-
`):[]};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]=
|
|
51
|
-
`?n[1].slice(0,-1):n[1];return{type:"paragraph",raw:n[0],text:r,tokens:this.lexer.inline(r)}}}text(t){const n=this.rules.block.text.exec(t);if(n)return{type:"text",raw:n[0],text:n[0],tokens:this.lexer.inline(n[0])}}escape(t){const n=this.rules.inline.escape.exec(t);if(n)return{type:"escape",raw:n[0],text:
|
|
52
|
-
]`).replace("lheading",
|
|
49
|
+
`,t=t.substring(h.length+1),d=f.slice(i)}}v.loose||(u?v.loose=!0:/\n *\n *$/.test(r)&&(u=!0)),this.options.gfm&&(o=/^\[[ xX]\] /.exec(p),o&&(s=o[0]!=="[ ] ",p=p.replace(/^\[[ xX]\] +/,""))),v.items.push({type:"list_item",raw:r,task:!!o,checked:s,loose:!1,text:p}),v.raw+=r}v.items[v.items.length-1].raw=r.trimRight(),v.items[v.items.length-1].text=p.trimRight(),v.raw=v.raw.trimRight();const S=v.items.length;for(a=0;a<S;a++)if(this.lexer.state.top=!1,v.items[a].tokens=this.lexer.blockTokens(v.items[a].text,[]),!v.loose){const N=v.items[a].tokens.filter(k=>k.type==="space"),T=N.length>0&&N.some(k=>/\n.*\n/.test(k.raw));v.loose=T}if(v.loose)for(a=0;a<S;a++)v.items[a].loose=!0;return v}}html(t){const n=this.rules.block.html.exec(t);if(n){const r={type:"html",raw:n[0],pre:!this.options.sanitizer&&(n[1]==="pre"||n[1]==="script"||n[1]==="style"),text:n[0]};if(this.options.sanitize){const o=this.options.sanitizer?this.options.sanitizer(n[0]):_t(n[0]);r.type="paragraph",r.text=o,r.tokens=this.lexer.inline(o)}return r}}def(t){const n=this.rules.block.def.exec(t);if(n){const r=n[1].toLowerCase().replace(/\s+/g," "),o=n[2]?n[2].replace(/^<(.*)>$/,"$1").replace(this.rules.inline._escapes,"$1"):"",s=n[3]?n[3].substring(1,n[3].length-1).replace(this.rules.inline._escapes,"$1"):n[3];return{type:"def",tag:r,raw:n[0],href:o,title:s}}}table(t){const n=this.rules.block.table.exec(t);if(n){const r={type:"table",header:Ku(n[1]).map(o=>({text:o})),align:n[2].replace(/^ *|\| *$/g,"").split(/ *\| */),rows:n[3]&&n[3].trim()?n[3].replace(/\n[ \t]*$/,"").split(`
|
|
50
|
+
`):[]};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]=Ku(r.rows[s],r.header.length).map(u=>({text:u}));for(o=r.header.length,i=0;i<o;i++)r.header[i].tokens=this.lexer.inline(r.header[i].text);for(o=r.rows.length,i=0;i<o;i++)for(l=r.rows[i],a=0;a<l.length;a++)l[a].tokens=this.lexer.inline(l[a].text);return r}}}lheading(t){const n=this.rules.block.lheading.exec(t);if(n)return{type:"heading",raw:n[0],depth:n[2].charAt(0)==="="?1:2,text:n[1],tokens:this.lexer.inline(n[1])}}paragraph(t){const n=this.rules.block.paragraph.exec(t);if(n){const r=n[1].charAt(n[1].length-1)===`
|
|
51
|
+
`?n[1].slice(0,-1):n[1];return{type:"paragraph",raw:n[0],text:r,tokens:this.lexer.inline(r)}}}text(t){const n=this.rules.block.text.exec(t);if(n)return{type:"text",raw:n[0],text:n[0],tokens:this.lexer.inline(n[0])}}escape(t){const n=this.rules.inline.escape.exec(t);if(n)return{type:"escape",raw:n[0],text:_t(n[1])}}tag(t){const n=this.rules.inline.tag.exec(t);if(n)return!this.lexer.state.inLink&&/^<a /i.test(n[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&/^<\/a>/i.test(n[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&/^<(pre|code|kbd|script)(\s|>)/i.test(n[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&/^<\/(pre|code|kbd|script)(\s|>)/i.test(n[0])&&(this.lexer.state.inRawBlock=!1),{type:this.options.sanitize?"text":"html",raw:n[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,text:this.options.sanitize?this.options.sanitizer?this.options.sanitizer(n[0]):_t(n[0]):n[0]}}link(t){const n=this.rules.inline.link.exec(t);if(n){const r=n[2].trim();if(!this.options.pedantic&&/^</.test(r)){if(!/>$/.test(r))return;const i=as(r.slice(0,-1),"\\");if((r.length-i.length)%2===0)return}else{const i=Sb(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)),Gu(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 Gu(r,o,r[0],this.lexer)}}emStrong(t,n,r=""){let o=this.rules.inline.emStrong.lDelim.exec(t);if(!o||o[3]&&r.match(/[\p{L}\p{N}]/u))return;const s=o[1]||o[2]||"";if(!s||s&&(r===""||this.rules.inline.punctuation.exec(r))){const i=o[0].length-1;let a,l,u=i,d=0;const f=o[0][0]==="*"?this.rules.inline.emStrong.rDelimAst:this.rules.inline.emStrong.rDelimUnd;for(f.lastIndex=0,n=n.slice(-1*t.length+i);(o=f.exec(n))!=null;){if(a=o[1]||o[2]||o[3]||o[4]||o[5]||o[6],!a)continue;if(l=a.length,o[3]||o[4]){u+=l;continue}else if((o[5]||o[6])&&i%3&&!((i+l)%3)){d+=l;continue}if(u-=l,u>0)continue;l=Math.min(l,l+u+d);const h=t.slice(0,i+o.index+(o[0].length-a.length)+l);if(Math.min(i,l)%2){const b=h.slice(1,-1);return{type:"em",raw:h,text:b,tokens:this.lexer.inlineTokens(b)}}const p=h.slice(2,-2);return{type:"strong",raw:h,text:p,tokens:this.lexer.inlineTokens(p)}}}}codespan(t){const n=this.rules.inline.code.exec(t);if(n){let r=n[2].replace(/\n/g," ");const o=/[^ ]/.test(r),s=/^ /.test(r)&&/ $/.test(r);return o&&s&&(r=r.substring(1,r.length-1)),r=_t(r,!0),{type:"codespan",raw:n[0],text:r}}}br(t){const n=this.rules.inline.br.exec(t);if(n)return{type:"br",raw:n[0]}}del(t){const n=this.rules.inline.del.exec(t);if(n)return{type:"del",raw:n[0],text:n[2],tokens:this.lexer.inlineTokens(n[2])}}autolink(t,n){const r=this.rules.inline.autolink.exec(t);if(r){let o,s;return r[2]==="@"?(o=_t(this.options.mangle?n(r[1]):r[1]),s="mailto:"+o):(o=_t(r[1]),s=o),{type:"link",raw:r[0],text:o,href:s,tokens:[{type:"text",raw:o,text:o}]}}}url(t,n){let r;if(r=this.rules.inline.url.exec(t)){let o,s;if(r[2]==="@")o=_t(this.options.mangle?n(r[0]):r[0]),s="mailto:"+o;else{let i;do i=r[0],r[0]=this.rules.inline._backpedal.exec(r[0])[0];while(i!==r[0]);o=_t(r[0]),r[1]==="www."?s="http://"+r[0]:s=r[0]}return{type:"link",raw:r[0],text:o,href:s,tokens:[{type:"text",raw:o,text:o}]}}}inlineText(t,n){const r=this.rules.inline.text.exec(t);if(r){let o;return this.lexer.state.inRawBlock?o=this.options.sanitize?this.options.sanitizer?this.options.sanitizer(r[0]):_t(r[0]):r[0]:o=_t(this.options.smartypants?n(r[0]):r[0]),{type:"text",raw:r[0],text:o}}}}const ke={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:is,lheading:/^((?:.|\n(?!\n))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,_paragraph:/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,text:/^[^\n]+/};ke._label=/(?!\s*\])(?:\\.|[^\[\]\\])+/,ke._title=/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/,ke.def=st(ke.def).replace("label",ke._label).replace("title",ke._title).getRegex(),ke.bullet=/(?:[*+-]|\d{1,9}[.)])/,ke.listItemStart=st(/^( *)(bull) */).replace("bull",ke.bullet).getRegex(),ke.list=st(ke.list).replace(/bull/g,ke.bullet).replace("hr","\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))").replace("def","\\n+(?="+ke.def.source+")").getRegex(),ke._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",ke._comment=/<!--(?!-?>)[\s\S]*?(?:-->|$)/,ke.html=st(ke.html,"i").replace("comment",ke._comment).replace("tag",ke._tag).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),ke.paragraph=st(ke._paragraph).replace("hr",ke.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",ke._tag).getRegex(),ke.blockquote=st(ke.blockquote).replace("paragraph",ke.paragraph).getRegex(),ke.normal={...ke},ke.gfm={...ke.normal,table:"^ *([^\\n ].*\\|.*)\\n {0,3}(?:\\| *)?(:?-+:? *(?:\\| *:?-+:? *)*)(?:\\| *)?(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)"},ke.gfm.table=st(ke.gfm.table).replace("hr",ke.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",ke._tag).getRegex(),ke.gfm.paragraph=st(ke._paragraph).replace("hr",ke.hr).replace("heading"," {0,3}#{1,6} ").replace("|lheading","").replace("table",ke.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",ke._tag).getRegex(),ke.pedantic={...ke.normal,html:st(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",ke._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:is,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:st(ke.normal._paragraph).replace("hr",ke.hr).replace("heading",` *#{1,6} *[^
|
|
52
|
+
]`).replace("lheading",ke.lheading).replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").getRegex()};const ce={escape:/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,autolink:/^<(scheme:[^\s\x00-\x1f<>]*|email)>/,url:is,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:is,text:/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,punctuation:/^([\spunctuation])/};ce._punctuation="!\"#$%&'()+\\-.,/:;<=>?@\\[\\]`^{|}~",ce.punctuation=st(ce.punctuation).replace(/punctuation/g,ce._punctuation).getRegex(),ce.blockSkip=/\[[^\]]*?\]\([^\)]*?\)|`[^`]*?`|<[^>]*?>/g,ce.escapedEmSt=/(?:^|[^\\])(?:\\\\)*\\[*_]/g,ce._comment=st(ke._comment).replace("(?:-->|$)","-->").getRegex(),ce.emStrong.lDelim=st(ce.emStrong.lDelim).replace(/punct/g,ce._punctuation).getRegex(),ce.emStrong.rDelimAst=st(ce.emStrong.rDelimAst,"g").replace(/punct/g,ce._punctuation).getRegex(),ce.emStrong.rDelimUnd=st(ce.emStrong.rDelimUnd,"g").replace(/punct/g,ce._punctuation).getRegex(),ce._escapes=/\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/g,ce._scheme=/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/,ce._email=/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/,ce.autolink=st(ce.autolink).replace("scheme",ce._scheme).replace("email",ce._email).getRegex(),ce._attribute=/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/,ce.tag=st(ce.tag).replace("comment",ce._comment).replace("attribute",ce._attribute).getRegex(),ce._label=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,ce._href=/<(?:\\.|[^\n<>\\])+>|[^\s\x00-\x1f]*/,ce._title=/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/,ce.link=st(ce.link).replace("label",ce._label).replace("href",ce._href).replace("title",ce._title).getRegex(),ce.reflink=st(ce.reflink).replace("label",ce._label).replace("ref",ke._label).getRegex(),ce.nolink=st(ce.nolink).replace("ref",ke._label).getRegex(),ce.reflinkSearch=st(ce.reflinkSearch,"g").replace("reflink",ce.reflink).replace("nolink",ce.nolink).getRegex(),ce.normal={...ce},ce.pedantic={...ce.normal,strong:{start:/^__|\*\*/,middle:/^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,endAst:/\*\*(?!\*)/g,endUnd:/__(?!_)/g},em:{start:/^_|\*/,middle:/^()\*(?=\S)([\s\S]*?\S)\*(?!\*)|^_(?=\S)([\s\S]*?\S)_(?!_)/,endAst:/\*(?!\*)/g,endUnd:/_(?!_)/g},link:st(/^!?\[(label)\]\((.*?)\)/).replace("label",ce._label).getRegex(),reflink:st(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",ce._label).getRegex()},ce.gfm={...ce.normal,escape:st(ce.escape).replace("])","~|])").getRegex(),_extended_email:/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/,url:/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])([\s\S]*?[^\s~])\1(?=[^~]|$)/,text:/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/},ce.gfm.url=st(ce.gfm.url,"i").replace("email",ce.gfm._extended_email).getRegex(),ce.breaks={...ce.gfm,br:st(ce.br).replace("{2,}","*").getRegex(),text:st(ce.gfm.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()};function kb(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 Yu(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 Bn{constructor(t){this.tokens=[],this.tokens.links=Object.create(null),this.options=t||ir,this.options.tokenizer=this.options.tokenizer||new la,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:ke.normal,inline:ce.normal};this.options.pedantic?(n.block=ke.pedantic,n.inline=ce.pedantic):this.options.gfm&&(n.block=ke.gfm,this.options.breaks?n.inline=ce.breaks:n.inline=ce.gfm),this.tokenizer.rules=n}static get rules(){return{block:ke,inline:ce}}static lex(t,n){return new Bn(n).lex(t)}static lexInline(t,n){return new Bn(n).inlineTokens(t)}lex(t){t=t.replace(/\r\n|\r/g,`
|
|
53
53
|
`),this.blockTokens(t,this.tokens);let n;for(;n=this.inlineQueue.shift();)this.inlineTokens(n.src,n.tokens);return this.tokens}blockTokens(t,n=[]){this.options.pedantic?t=t.replace(/\t/g," ").replace(/^ +$/gm,""):t=t.replace(/^( *)(\t+)/gm,(a,l,u)=>l+" ".repeat(u.length));let r,o,s,i;for(;t;)if(!(this.options.extensions&&this.options.extensions.block&&this.options.extensions.block.some(a=>(r=a.call({lexer:this},t,n))?(t=t.substring(r.raw.length),n.push(r),!0):!1))){if(r=this.tokenizer.space(t)){t=t.substring(r.raw.length),r.raw.length===1&&n.length>0?n[n.length-1].raw+=`
|
|
54
54
|
`:n.push(r);continue}if(r=this.tokenizer.code(t)){t=t.substring(r.raw.length),o=n[n.length-1],o&&(o.type==="paragraph"||o.type==="text")?(o.raw+=`
|
|
55
55
|
`+r.raw,o.text+=`
|
|
@@ -59,9 +59,9 @@ React keys must be passed directly to JSX without using spread:
|
|
|
59
59
|
`+r.raw,o.text+=`
|
|
60
60
|
`+r.text,this.inlineQueue.pop(),this.inlineQueue[this.inlineQueue.length-1].src=o.text):n.push(r),i=s.length!==t.length,t=t.substring(r.raw.length);continue}if(r=this.tokenizer.text(t)){t=t.substring(r.raw.length),o=n[n.length-1],o&&o.type==="text"?(o.raw+=`
|
|
61
61
|
`+r.raw,o.text+=`
|
|
62
|
-
`+r.text,this.inlineQueue.pop(),this.inlineQueue[this.inlineQueue.length-1].src=o.text):n.push(r);continue}if(t){const a="Infinite loop on byte: "+t.charCodeAt(0);if(this.options.silent){console.error(a);break}else throw new Error(a)}}return this.state.top=!0,n}inline(t,n=[]){return this.inlineQueue.push({src:t,tokens:n}),n}inlineTokens(t,n=[]){let r,o,s,i=t,a,l,u;if(this.tokens.links){const d=Object.keys(this.tokens.links);if(d.length>0)for(;(a=this.tokenizer.rules.inline.reflinkSearch.exec(i))!=null;)d.includes(a[0].slice(a[0].lastIndexOf("[")+1,-1))&&(i=i.slice(0,a.index)+"["+
|
|
63
|
-
`,o?'<pre><code class="'+this.options.langPrefix+
|
|
64
|
-
`:"<pre><code>"+(r?t:
|
|
62
|
+
`+r.text,this.inlineQueue.pop(),this.inlineQueue[this.inlineQueue.length-1].src=o.text):n.push(r);continue}if(t){const a="Infinite loop on byte: "+t.charCodeAt(0);if(this.options.silent){console.error(a);break}else throw new Error(a)}}return this.state.top=!0,n}inline(t,n=[]){return this.inlineQueue.push({src:t,tokens:n}),n}inlineTokens(t,n=[]){let r,o,s,i=t,a,l,u;if(this.tokens.links){const d=Object.keys(this.tokens.links);if(d.length>0)for(;(a=this.tokenizer.rules.inline.reflinkSearch.exec(i))!=null;)d.includes(a[0].slice(a[0].lastIndexOf("[")+1,-1))&&(i=i.slice(0,a.index)+"["+qu("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)+"["+qu("a",a[0].length-2)+"]"+i.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);for(;(a=this.tokenizer.rules.inline.escapedEmSt.exec(i))!=null;)i=i.slice(0,a.index+a[0].length-2)+"++"+i.slice(this.tokenizer.rules.inline.escapedEmSt.lastIndex),this.tokenizer.rules.inline.escapedEmSt.lastIndex--;for(;t;)if(l||(u=""),l=!1,!(this.options.extensions&&this.options.extensions.inline&&this.options.extensions.inline.some(d=>(r=d.call({lexer:this},t,n))?(t=t.substring(r.raw.length),n.push(r),!0):!1))){if(r=this.tokenizer.escape(t)){t=t.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.tag(t)){t=t.substring(r.raw.length),o=n[n.length-1],o&&r.type==="text"&&o.type==="text"?(o.raw+=r.raw,o.text+=r.text):n.push(r);continue}if(r=this.tokenizer.link(t)){t=t.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.reflink(t,this.tokens.links)){t=t.substring(r.raw.length),o=n[n.length-1],o&&r.type==="text"&&o.type==="text"?(o.raw+=r.raw,o.text+=r.text):n.push(r);continue}if(r=this.tokenizer.emStrong(t,i,u)){t=t.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.codespan(t)){t=t.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.br(t)){t=t.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.del(t)){t=t.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.autolink(t,Yu)){t=t.substring(r.raw.length),n.push(r);continue}if(!this.state.inLink&&(r=this.tokenizer.url(t,Yu))){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,kb)){t=t.substring(r.raw.length),r.raw.slice(-1)!=="_"&&(u=r.raw.slice(-1)),l=!0,o=n[n.length-1],o&&o.type==="text"?(o.raw+=r.raw,o.text+=r.text):n.push(r);continue}if(t){const d="Infinite loop on byte: "+t.charCodeAt(0);if(this.options.silent){console.error(d);break}else throw new Error(d)}}return n}}class ca{constructor(t){this.options=t||ir}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$/,"")+`
|
|
63
|
+
`,o?'<pre><code class="'+this.options.langPrefix+_t(o)+'">'+(r?t:_t(t,!0))+`</code></pre>
|
|
64
|
+
`:"<pre><code>"+(r?t:_t(t,!0))+`</code></pre>
|
|
65
65
|
`}blockquote(t){return`<blockquote>
|
|
66
66
|
${t}</blockquote>
|
|
67
67
|
`}html(t){return t}heading(t,n,r,o){if(this.options.headerIds){const s=this.options.headerPrefix+o.slug(r);return`<h${n} id="${s}">${t}</h${n}>
|
|
@@ -79,14 +79,14 @@ ${t}</blockquote>
|
|
|
79
79
|
`}tablerow(t){return`<tr>
|
|
80
80
|
${t}</tr>
|
|
81
81
|
`}tablecell(t,n){const r=n.header?"th":"td";return(n.align?`<${r} align="${n.align}">`:`<${r}>`)+t+`</${r}>
|
|
82
|
-
`}strong(t){return`<strong>${t}</strong>`}em(t){return`<em>${t}</em>`}codespan(t){return`<code>${t}</code>`}br(){return this.options.xhtml?"<br/>":"<br>"}del(t){return`<del>${t}</del>`}link(t,n,r){if(t=
|
|
83
|
-
`+(p.tokens?this.parseInline(p.tokens):p.text);r+=n?this.renderer.paragraph(h):h;continue}default:{const A='Token with "'+p.type+'" type was not found.';if(this.options.silent){console.error(A);return}else throw new Error(A)}}}return r}parseInline(t,n){n=n||this.renderer;let r="",o,s,i;const a=t.length;for(o=0;o<a;o++){if(s=t[o],this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[s.type]&&(i=this.options.extensions.renderers[s.type].call({parser:this},s),i!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(s.type))){r+=i||"";continue}switch(s.type){case"escape":{r+=n.text(s.text);break}case"html":{r+=n.html(s.text);break}case"link":{r+=n.link(s.href,s.title,this.parseInline(s.tokens,n));break}case"image":{r+=n.image(s.href,s.title,s.text);break}case"strong":{r+=n.strong(this.parseInline(s.tokens,n));break}case"em":{r+=n.em(this.parseInline(s.tokens,n));break}case"codespan":{r+=n.codespan(s.text);break}case"br":{r+=n.br();break}case"del":{r+=n.del(this.parseInline(s.tokens,n));break}case"text":{r+=n.text(s.text);break}default:{const l='Token with "'+s.type+'" type was not found.';if(this.options.silent){console.error(l);return}else throw new Error(l)}}}return r}}class
|
|
84
|
-
Please report this to https://github.com/markedjs/marked.`,e){const o="<p>An error occurred:</p><pre>"+Nt(r.message+"",!0)+"</pre>";if(t)return Promise.resolve(o);if(n){n(null,o);return}return o}if(t)return Promise.reject(r);if(n){n(r);return}throw r}}function Ku(e,t){return(n,r,o)=>{typeof r=="function"&&(o=r,r=null);const s={...r};r={...ke.defaults,...s};const i=vw(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(mw(r),r.hooks&&(r.hooks.options=r),o){const a=r.highlight;let l;try{r.hooks&&(n=r.hooks.preprocess(n)),l=e(n,r)}catch(f){return i(f)}const u=function(f){let h;if(!f)try{r.walkTokens&&ke.walkTokens(l,r.walkTokens),h=t(l,r),r.hooks&&(h=r.hooks.postprocess(h))}catch(p){f=p}return r.highlight=a,f?i(f):o(null,h)};if(!a||a.length<3||(delete r.highlight,!l.length))return u();let d=0;ke.walkTokens(l,function(f){f.type==="code"&&(d++,setTimeout(()=>{a(f.text,f.lang,function(h,p){if(h)return u(h);p!=null&&p!==f.text&&(f.text=p,f.escaped=!0),d--,d===0&&u()})},0))}),d===0&&u();return}if(r.async)return Promise.resolve(r.hooks?r.hooks.preprocess(n):n).then(a=>e(a,r)).then(a=>r.walkTokens?Promise.all(ke.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&&ke.walkTokens(a,r.walkTokens);let l=t(a,r);return r.hooks&&(l=r.hooks.postprocess(l)),l}catch(a){return i(a)}}}function ke(e,t,n){return Ku(Fn.lex,$n.parse)(e,t,n)}ke.options=ke.setOptions=function(e){return ke.defaults={...ke.defaults,...e},nw(ke.defaults),ke},ke.getDefaults=Mu,ke.defaults=sr,ke.use=function(...e){const t=ke.defaults.extensions||{renderers:{},childTokens:{}};e.forEach(n=>{const r={...n};if(r.async=ke.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=ke.defaults.renderer||new oa;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=ke.defaults.tokenizer||new ra;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=ke.defaults.hooks||new rs;for(const s in n.hooks){const i=o[s];rs.passThroughHooks.has(s)?o[s]=a=>{if(ke.defaults.async)return Promise.resolve(n.hooks[s].call(o,a)).then(u=>i.call(o,u));const l=n.hooks[s].call(o,a);return i.call(o,l)}:o[s]=(...a)=>{let l=n.hooks[s].apply(o,a);return l===!1&&(l=i.apply(o,a)),l}}r.hooks=o}if(n.walkTokens){const o=ke.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}}ke.setOptions(r)})},ke.walkTokens=function(e,t){let n=[];for(const r of e)switch(n=n.concat(t.call(ke,r)),r.type){case"table":{for(const o of r.header)n=n.concat(ke.walkTokens(o.tokens,t));for(const o of r.rows)for(const s of o)n=n.concat(ke.walkTokens(s.tokens,t));break}case"list":{n=n.concat(ke.walkTokens(r.items,t));break}default:ke.defaults.extensions&&ke.defaults.extensions.childTokens&&ke.defaults.extensions.childTokens[r.type]?ke.defaults.extensions.childTokens[r.type].forEach(function(o){n=n.concat(ke.walkTokens(r[o],t))}):r.tokens&&(n=n.concat(ke.walkTokens(r.tokens,t)))}return n},ke.parseInline=Ku(Fn.lexInline,$n.parseInline),ke.Parser=$n,ke.parser=$n.parse,ke.Renderer=oa,ke.TextRenderer=Vu,ke.Lexer=Fn,ke.lexer=Fn.lex,ke.Tokenizer=ra,ke.Slugger=qu,ke.Hooks=rs,ke.parse=ke,ke.options,ke.setOptions,ke.use,ke.walkTokens,ke.parseInline,$n.parse,Fn.lex;function sa({content:e,className:t="",allowHtml:n=!1,style:r}){const o=y.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 ke.parse(i)}return ke.parse(e)}catch(i){return console.error("[MarkdownContent] parse error",i),`<pre>Error rendering markdown: ${String(i)}</pre>`}},[e,n]),s=y.useMemo(()=>{if(r&&r.color){const i=r.color;return{...r,"--tw-prose-body":i,"--tw-prose-headings":i,"--tw-prose-links":i,"--tw-prose-bold":i,"--tw-prose-counters":i,"--tw-prose-bullets":i,"--tw-prose-hr":i,"--tw-prose-quotes":i,"--tw-prose-quote-borders":i,"--tw-prose-captions":i,"--tw-prose-code":i,"--tw-prose-pre-code":i,"--tw-prose-pre-bg":"inherit","--tw-prose-th-borders":i,"--tw-prose-td-borders":i}}return r},[r]);return c.jsx("div",{className:Z("markdown prose max-w-none break-words dark:prose-invert",t),style:s,dangerouslySetInnerHTML:{__html:o}})}async function Gu(e,t){return await nn(e,{responseType:"blob",onDownloadProgress:r=>{try{t&&r.lengthComputable}catch{}},maxBodyLength:1/0})}async function Yu(e,t){return await(await Gu(`/files/${e}/view`,t)).text()}async function ww(e,t){const n=await Gu(`/files/${e}/download`,t),r=URL.createObjectURL(n);let o=`file_${e}`;try{const i=await nn(`/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 bw(e,t=50,n=0){const r={limit:t,offset:n};return e&&(r.thread_id=e),await nn("/files",{params:r})}const yw=1,Sw=1e6;let ia=0;function Cw(){return ia=(ia+1)%Number.MAX_SAFE_INTEGER,ia.toString()}const aa=new Map,Xu=e=>{if(aa.has(e))return;const t=setTimeout(()=>{aa.delete(e),io({type:"REMOVE_TOAST",toastId:e})},Sw);aa.set(e,t)},Tw=(e,t)=>{switch(t.type){case"ADD_TOAST":return{...e,toasts:[t.toast,...e.toasts].slice(0,yw)};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?Xu(n):e.toasts.forEach(r=>{Xu(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)}}},os=[];let ss={toasts:[]};function io(e){ss=Tw(ss,e),os.forEach(t=>{t(ss)})}function kw({...e}){const t=Cw(),n=o=>io({type:"UPDATE_TOAST",toast:{...o,id:t}}),r=()=>io({type:"DISMISS_TOAST",toastId:t});return io({type:"ADD_TOAST",toast:{...e,id:t,open:!0,onOpenChange:o=>{o||r()}}}),{id:t,dismiss:r,update:n}}function la(){const[e,t]=m.useState(ss);return m.useEffect(()=>(os.push(t),()=>{const n=os.indexOf(t);n>-1&&os.splice(n,1)}),[e]),{...e,toast:kw,dismiss:n=>io({type:"DISMISS_TOAST",toastId:n})}}function Tt(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 Ew(e,t=globalThis==null?void 0:globalThis.document){const n=Tt(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 Iw="DismissableLayer",ca="dismissableLayer.update",Nw="dismissableLayer.pointerDownOutside",Aw="dismissableLayer.focusOutside",Ju,Zu=m.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),is=m.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:a,...l}=e,u=m.useContext(Zu),[d,f]=m.useState(null),h=(d==null?void 0:d.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,p]=m.useState({}),w=Ve(t,I=>f(I)),x=Array.from(u.layers),[g]=[...u.layersWithOutsidePointerEventsDisabled].slice(-1),v=x.indexOf(g),b=d?x.indexOf(d):-1,S=u.layersWithOutsidePointerEventsDisabled.size>0,N=b>=v,C=Rw(I=>{const A=I.target,j=[...u.branches].some(P=>P.contains(A));!N||j||(o==null||o(I),i==null||i(I),I.defaultPrevented||a==null||a())},h),k=Pw(I=>{const A=I.target;[...u.branches].some(P=>P.contains(A))||(s==null||s(I),i==null||i(I),I.defaultPrevented||a==null||a())},h);return Ew(I=>{b===u.layers.size-1&&(r==null||r(I),!I.defaultPrevented&&a&&(I.preventDefault(),a()))},h),m.useEffect(()=>{if(d)return n&&(u.layersWithOutsidePointerEventsDisabled.size===0&&(Ju=h.body.style.pointerEvents,h.body.style.pointerEvents="none"),u.layersWithOutsidePointerEventsDisabled.add(d)),u.layers.add(d),Qu(),()=>{n&&u.layersWithOutsidePointerEventsDisabled.size===1&&(h.body.style.pointerEvents=Ju)}},[d,h,n,u]),m.useEffect(()=>()=>{d&&(u.layers.delete(d),u.layersWithOutsidePointerEventsDisabled.delete(d),Qu())},[d,u]),m.useEffect(()=>{const I=()=>p({});return document.addEventListener(ca,I),()=>document.removeEventListener(ca,I)},[]),c.jsx(_e.div,{...l,ref:w,style:{pointerEvents:S?N?"auto":"none":void 0,...e.style},onFocusCapture:ue(e.onFocusCapture,k.onFocusCapture),onBlurCapture:ue(e.onBlurCapture,k.onBlurCapture),onPointerDownCapture:ue(e.onPointerDownCapture,C.onPointerDownCapture)})});is.displayName=Iw;var _w="DismissableLayerBranch",jw=m.forwardRef((e,t)=>{const n=m.useContext(Zu),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]),c.jsx(_e.div,{...e,ref:o})});jw.displayName=_w;function Rw(e,t=globalThis==null?void 0:globalThis.document){const n=Tt(e),r=m.useRef(!1),o=m.useRef(()=>{});return m.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let l=function(){ed(Nw,n,u,{discrete:!0})};const u={originalEvent:a};a.pointerType==="touch"?(t.removeEventListener("click",o.current),o.current=l,t.addEventListener("click",o.current,{once:!0})):l()}else t.removeEventListener("click",o.current);r.current=!1},i=window.setTimeout(()=>{t.addEventListener("pointerdown",s)},0);return()=>{window.clearTimeout(i),t.removeEventListener("pointerdown",s),t.removeEventListener("click",o.current)}},[t,n]),{onPointerDownCapture:()=>r.current=!0}}function Pw(e,t=globalThis==null?void 0:globalThis.document){const n=Tt(e),r=m.useRef(!1);return m.useEffect(()=>{const o=s=>{s.target&&!r.current&&ed(Aw,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 Qu(){const e=new CustomEvent(ca);document.dispatchEvent(e)}function ed(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?Iu(o,s):o.dispatchEvent(s)}var ua="focusScope.autoFocusOnMount",da="focusScope.autoFocusOnUnmount",td={bubbles:!1,cancelable:!0},Ow="FocusScope",as=m.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:s,...i}=e,[a,l]=m.useState(null),u=Tt(o),d=Tt(s),f=m.useRef(null),h=Ve(t,x=>l(x)),p=m.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;m.useEffect(()=>{if(r){let x=function(S){if(p.paused||!a)return;const N=S.target;a.contains(N)?f.current=N:Bn(f.current,{select:!0})},g=function(S){if(p.paused||!a)return;const N=S.relatedTarget;N!==null&&(a.contains(N)||Bn(f.current,{select:!0}))},v=function(S){if(document.activeElement===document.body)for(const C of S)C.removedNodes.length>0&&Bn(a)};document.addEventListener("focusin",x),document.addEventListener("focusout",g);const b=new MutationObserver(v);return a&&b.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",x),document.removeEventListener("focusout",g),b.disconnect()}}},[r,a,p.paused]),m.useEffect(()=>{if(a){od.add(p);const x=document.activeElement;if(!a.contains(x)){const v=new CustomEvent(ua,td);a.addEventListener(ua,u),a.dispatchEvent(v),v.defaultPrevented||(Mw(Bw(nd(a)),{select:!0}),document.activeElement===x&&Bn(a))}return()=>{a.removeEventListener(ua,u),setTimeout(()=>{const v=new CustomEvent(da,td);a.addEventListener(da,d),a.dispatchEvent(v),v.defaultPrevented||Bn(x??document.body,{select:!0}),a.removeEventListener(da,d),od.remove(p)},0)}}},[a,u,d,p]);const w=m.useCallback(x=>{if(!n&&!r||p.paused)return;const g=x.key==="Tab"&&!x.altKey&&!x.ctrlKey&&!x.metaKey,v=document.activeElement;if(g&&v){const b=x.currentTarget,[S,N]=Dw(b);S&&N?!x.shiftKey&&v===N?(x.preventDefault(),n&&Bn(S,{select:!0})):x.shiftKey&&v===S&&(x.preventDefault(),n&&Bn(N,{select:!0})):v===b&&x.preventDefault()}},[n,r,p.paused]);return c.jsx(_e.div,{tabIndex:-1,...i,ref:h,onKeyDown:w})});as.displayName=Ow;function Mw(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(Bn(r,{select:t}),document.activeElement!==n)return}function Dw(e){const t=nd(e),n=rd(t,e),r=rd(t.reverse(),e);return[n,r]}function nd(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 rd(e,t){for(const n of e)if(!Lw(n,{upTo:t}))return n}function Lw(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 Fw(e){return e instanceof HTMLInputElement&&"select"in e}function Bn(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&Fw(e)&&t&&e.select()}}var od=$w();function $w(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=sd(e,t),e.unshift(t)},remove(t){var n;e=sd(e,t),(n=e[0])==null||n.resume()}}}function sd(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function Bw(e){return e.filter(t=>t.tagName!=="A")}var zw="Portal",ls=m.forwardRef((e,t)=>{var a;const{container:n,...r}=e,[o,s]=m.useState(!1);Ct(()=>s(!0),[]);const i=n||o&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?ti.createPortal(c.jsx(_e.div,{...r,ref:t}),i):null});ls.displayName=zw;var fa=0;function ha(){m.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??id()),document.body.insertAdjacentElement("beforeend",e[1]??id()),fa++,()=>{fa===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),fa--}},[])}function id(){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 wn=function(){return wn=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},wn.apply(this,arguments)};function ad(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 Hw(e,t,n){if(n||arguments.length===2)for(var r=0,o=t.length,s;r<o;r++)(s||!(r in t))&&(s||(s=Array.prototype.slice.call(t,0,r)),s[r]=t[r]);return e.concat(s||Array.prototype.slice.call(t))}typeof SuppressedError=="function"&&SuppressedError;var cs="right-scroll-bar-position",us="width-before-scroll-bar",Uw="with-scroll-bars-hidden",Ww="--removed-body-scroll-bar-size";function pa(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function Vw(e,t){var n=y.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 qw=typeof window<"u"?m.useLayoutEffect:m.useEffect,ld=new WeakMap;function Kw(e,t){var n=Vw(null,function(r){return e.forEach(function(o){return pa(o,r)})});return qw(function(){var r=ld.get(n);if(r){var o=new Set(r),s=new Set(e),i=n.current;o.forEach(function(a){s.has(a)||pa(a,null)}),s.forEach(function(a){o.has(a)||pa(a,i)})}ld.set(n,e)},[e]),n}function Gw(e){return e}function Yw(e,t){t===void 0&&(t=Gw);var n=[],r=!1,o={read:function(){if(r)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return n.length?n[n.length-1]:e},useMedium:function(s){var i=t(s,r);return n.push(i),function(){n=n.filter(function(a){return a!==i})}},assignSyncMedium:function(s){for(r=!0;n.length;){var i=n;n=[],i.forEach(s)}n={push:function(a){return s(a)},filter:function(){return n}}},assignMedium:function(s){r=!0;var i=[];if(n.length){var a=n;n=[],a.forEach(s),i=n}var l=function(){var d=i;i=[],d.forEach(s)},u=function(){return Promise.resolve().then(l)};u(),n={push:function(d){i.push(d),u()},filter:function(d){return i=i.filter(d),n}}}};return o}function Xw(e){e===void 0&&(e={});var t=Yw(null);return t.options=wn({async:!0,ssr:!1},e),t}var cd=function(e){var t=e.sideCar,n=ad(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,wn({},n))};cd.isSideCarExport=!0;function Jw(e,t){return e.useMedium(t),cd}var ud=Xw(),ma=function(){},ds=m.forwardRef(function(e,t){var n=m.useRef(null),r=m.useState({onScrollCapture:ma,onWheelCapture:ma,onTouchMoveCapture:ma}),o=r[0],s=r[1],i=e.forwardProps,a=e.children,l=e.className,u=e.removeScrollBar,d=e.enabled,f=e.shards,h=e.sideCar,p=e.noRelative,w=e.noIsolation,x=e.inert,g=e.allowPinchZoom,v=e.as,b=v===void 0?"div":v,S=e.gapMode,N=ad(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),C=h,k=Kw([n,t]),I=wn(wn({},N),o);return m.createElement(m.Fragment,null,d&&m.createElement(C,{sideCar:ud,removeScrollBar:u,shards:f,noRelative:p,noIsolation:w,inert:x,setCallbacks:s,allowPinchZoom:!!g,lockRef:n,gapMode:S}),i?m.cloneElement(m.Children.only(a),wn(wn({},I),{ref:k})):m.createElement(b,wn({},I,{className:l,ref:k}),a))});ds.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},ds.classNames={fullWidth:us,zeroRight:cs};var Zw=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function Qw(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=Zw();return t&&e.setAttribute("nonce",t),e}function eb(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function tb(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var nb=function(){var e=0,t=null;return{add:function(n){e==0&&(t=Qw())&&(eb(t,n),tb(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},rb=function(){var e=nb();return function(t,n){m.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},dd=function(){var e=rb(),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},ga=function(e){return parseInt(e||"",10)||0},sb=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[ga(n),ga(r),ga(o)]},ib=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return ob;var t=sb(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])}},ab=dd(),Tr="data-scroll-locked",lb=function(e,t,n,r){var o=e.left,s=e.top,i=e.right,a=e.gap;return n===void 0&&(n="margin"),`
|
|
85
|
-
.`.concat(
|
|
82
|
+
`}strong(t){return`<strong>${t}</strong>`}em(t){return`<em>${t}</em>`}codespan(t){return`<code>${t}</code>`}br(){return this.options.xhtml?"<br/>":"<br>"}del(t){return`<del>${t}</del>`}link(t,n,r){if(t=Vu(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=Vu(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 Xu{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 Ju{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 zn{constructor(t){this.options=t||ir,this.options.renderer=this.options.renderer||new ca,this.renderer=this.options.renderer,this.renderer.options=this.options,this.textRenderer=new Xu,this.slugger=new Ju}static parse(t,n){return new zn(n).parse(t)}static parseInline(t,n){return new zn(n).parseInline(t)}parse(t,n=!0){let r="",o,s,i,a,l,u,d,f,h,p,b,x,g,v,w,S,N,T,k;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]&&(k=this.options.extensions.renderers[p.type].call({parser:this},p),k!==!1||!["space","hr","heading","code","table","blockquote","list","html","paragraph","text"].includes(p.type))){r+=k||"";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,Wu(this.parseInline(p.tokens,this.textRenderer)),this.slugger);continue}case"code":{r+=this.renderer.code(p.text,p.lang,p.escaped);continue}case"table":{for(f="",d="",a=p.header.length,s=0;s<a;s++)d+=this.renderer.tablecell(this.parseInline(p.header[s].tokens),{header:!0,align:p.align[s]});for(f+=this.renderer.tablerow(d),h="",a=p.rows.length,s=0;s<a;s++){for(u=p.rows[s],d="",l=u.length,i=0;i<l;i++)d+=this.renderer.tablecell(this.parseInline(u[i].tokens),{header:!1,align:p.align[i]});h+=this.renderer.tablerow(d)}r+=this.renderer.table(f,h);continue}case"blockquote":{h=this.parse(p.tokens),r+=this.renderer.blockquote(h);continue}case"list":{for(b=p.ordered,x=p.start,g=p.loose,a=p.items.length,h="",s=0;s<a;s++)w=p.items[s],S=w.checked,N=w.task,v="",w.task&&(T=this.renderer.checkbox(S),g?w.tokens.length>0&&w.tokens[0].type==="paragraph"?(w.tokens[0].text=T+" "+w.tokens[0].text,w.tokens[0].tokens&&w.tokens[0].tokens.length>0&&w.tokens[0].tokens[0].type==="text"&&(w.tokens[0].tokens[0].text=T+" "+w.tokens[0].tokens[0].text)):w.tokens.unshift({type:"text",text:T}):v+=T),v+=this.parse(w.tokens,g),h+=this.renderer.listitem(v,N,S);r+=this.renderer.list(h,b,x);continue}case"html":{r+=this.renderer.html(p.text);continue}case"paragraph":{r+=this.renderer.paragraph(this.parseInline(p.tokens));continue}case"text":{for(h=p.tokens?this.parseInline(p.tokens):p.text;o+1<E&&t[o+1].type==="text";)p=t[++o],h+=`
|
|
83
|
+
`+(p.tokens?this.parseInline(p.tokens):p.text);r+=n?this.renderer.paragraph(h):h;continue}default:{const A='Token with "'+p.type+'" type was not found.';if(this.options.silent){console.error(A);return}else throw new Error(A)}}}return r}parseInline(t,n){n=n||this.renderer;let r="",o,s,i;const a=t.length;for(o=0;o<a;o++){if(s=t[o],this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[s.type]&&(i=this.options.extensions.renderers[s.type].call({parser:this},s),i!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(s.type))){r+=i||"";continue}switch(s.type){case"escape":{r+=n.text(s.text);break}case"html":{r+=n.html(s.text);break}case"link":{r+=n.link(s.href,s.title,this.parseInline(s.tokens,n));break}case"image":{r+=n.image(s.href,s.title,s.text);break}case"strong":{r+=n.strong(this.parseInline(s.tokens,n));break}case"em":{r+=n.em(this.parseInline(s.tokens,n));break}case"codespan":{r+=n.codespan(s.text);break}case"br":{r+=n.br();break}case"del":{r+=n.del(this.parseInline(s.tokens,n));break}case"text":{r+=n.text(s.text);break}default:{const l='Token with "'+s.type+'" type was not found.';if(this.options.silent){console.error(l);return}else throw new Error(l)}}}return r}}class ls{constructor(t){this.options=t||ir}preprocess(t){return t}postprocess(t){return t}}dm(ls,"passThroughHooks",new Set(["preprocess","postprocess"]));function Ib(e,t,n){return r=>{if(r.message+=`
|
|
84
|
+
Please report this to https://github.com/markedjs/marked.`,e){const o="<p>An error occurred:</p><pre>"+_t(r.message+"",!0)+"</pre>";if(t)return Promise.resolve(o);if(n){n(null,o);return}return o}if(t)return Promise.reject(r);if(n){n(r);return}throw r}}function Zu(e,t){return(n,r,o)=>{typeof r=="function"&&(o=r,r=null);const s={...r};r={...Ie.defaults,...s};const i=Ib(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(Cb(r),r.hooks&&(r.hooks.options=r),o){const a=r.highlight;let l;try{r.hooks&&(n=r.hooks.preprocess(n)),l=e(n,r)}catch(f){return i(f)}const u=function(f){let h;if(!f)try{r.walkTokens&&Ie.walkTokens(l,r.walkTokens),h=t(l,r),r.hooks&&(h=r.hooks.postprocess(h))}catch(p){f=p}return r.highlight=a,f?i(f):o(null,h)};if(!a||a.length<3||(delete r.highlight,!l.length))return u();let d=0;Ie.walkTokens(l,function(f){f.type==="code"&&(d++,setTimeout(()=>{a(f.text,f.lang,function(h,p){if(h)return u(h);p!=null&&p!==f.text&&(f.text=p,f.escaped=!0),d--,d===0&&u()})},0))}),d===0&&u();return}if(r.async)return Promise.resolve(r.hooks?r.hooks.preprocess(n):n).then(a=>e(a,r)).then(a=>r.walkTokens?Promise.all(Ie.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&&Ie.walkTokens(a,r.walkTokens);let l=t(a,r);return r.hooks&&(l=r.hooks.postprocess(l)),l}catch(a){return i(a)}}}function Ie(e,t,n){return Zu(Bn.lex,zn.parse)(e,t,n)}Ie.options=Ie.setOptions=function(e){return Ie.defaults={...Ie.defaults,...e},ub(Ie.defaults),Ie},Ie.getDefaults=Bu,Ie.defaults=ir,Ie.use=function(...e){const t=Ie.defaults.extensions||{renderers:{},childTokens:{}};e.forEach(n=>{const r={...n};if(r.async=Ie.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=Ie.defaults.renderer||new ca;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=Ie.defaults.tokenizer||new la;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=Ie.defaults.hooks||new ls;for(const s in n.hooks){const i=o[s];ls.passThroughHooks.has(s)?o[s]=a=>{if(Ie.defaults.async)return Promise.resolve(n.hooks[s].call(o,a)).then(u=>i.call(o,u));const l=n.hooks[s].call(o,a);return i.call(o,l)}:o[s]=(...a)=>{let l=n.hooks[s].apply(o,a);return l===!1&&(l=i.apply(o,a)),l}}r.hooks=o}if(n.walkTokens){const o=Ie.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}}Ie.setOptions(r)})},Ie.walkTokens=function(e,t){let n=[];for(const r of e)switch(n=n.concat(t.call(Ie,r)),r.type){case"table":{for(const o of r.header)n=n.concat(Ie.walkTokens(o.tokens,t));for(const o of r.rows)for(const s of o)n=n.concat(Ie.walkTokens(s.tokens,t));break}case"list":{n=n.concat(Ie.walkTokens(r.items,t));break}default:Ie.defaults.extensions&&Ie.defaults.extensions.childTokens&&Ie.defaults.extensions.childTokens[r.type]?Ie.defaults.extensions.childTokens[r.type].forEach(function(o){n=n.concat(Ie.walkTokens(r[o],t))}):r.tokens&&(n=n.concat(Ie.walkTokens(r.tokens,t)))}return n},Ie.parseInline=Zu(Bn.lexInline,zn.parseInline),Ie.Parser=zn,Ie.parser=zn.parse,Ie.Renderer=ca,Ie.TextRenderer=Xu,Ie.Lexer=Bn,Ie.lexer=Bn.lex,Ie.Tokenizer=la,Ie.Slugger=Ju,Ie.Hooks=ls,Ie.parse=Ie,Ie.options,Ie.setOptions,Ie.use,Ie.walkTokens,Ie.parseInline,zn.parse,Bn.lex;function ua({content:e,className:t="",allowHtml:n=!1,style:r}){const o=y.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 Ie.parse(i)}return Ie.parse(e)}catch(i){return console.error("[MarkdownContent] parse error",i),`<pre>Error rendering markdown: ${String(i)}</pre>`}},[e,n]),s=y.useMemo(()=>{if(r&&r.color){const i=r.color;return{...r,"--tw-prose-body":i,"--tw-prose-headings":i,"--tw-prose-links":i,"--tw-prose-bold":i,"--tw-prose-counters":i,"--tw-prose-bullets":i,"--tw-prose-hr":i,"--tw-prose-quotes":i,"--tw-prose-quote-borders":i,"--tw-prose-captions":i,"--tw-prose-code":i,"--tw-prose-pre-code":i,"--tw-prose-pre-bg":"inherit","--tw-prose-th-borders":i,"--tw-prose-td-borders":i}}return r},[r]);return c.jsx("div",{className:Q("markdown prose max-w-none break-words dark:prose-invert",t),style:s,dangerouslySetInnerHTML:{__html:o}})}async function Qu(e,t){return await on(e,{responseType:"blob",onDownloadProgress:r=>{try{t&&r.lengthComputable}catch{}},maxBodyLength:1/0})}async function ed(e,t){return await(await Qu(`/files/${e}/view`,t)).text()}async function Eb(e,t){const n=await Qu(`/files/${e}/download`,t),r=URL.createObjectURL(n);let o=`file_${e}`;try{const i=await on(`/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 Nb(e,t=50,n=0){const r={limit:t,offset:n};return e&&(r.thread_id=e),await on("/files",{params:r})}const Ab=1,_b=1e6;let da=0;function jb(){return da=(da+1)%Number.MAX_SAFE_INTEGER,da.toString()}const fa=new Map,td=e=>{if(fa.has(e))return;const t=setTimeout(()=>{fa.delete(e),co({type:"REMOVE_TOAST",toastId:e})},_b);fa.set(e,t)},Rb=(e,t)=>{switch(t.type){case"ADD_TOAST":return{...e,toasts:[t.toast,...e.toasts].slice(0,Ab)};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?td(n):e.toasts.forEach(r=>{td(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)}}},cs=[];let us={toasts:[]};function co(e){us=Rb(us,e),cs.forEach(t=>{t(us)})}function Pb({...e}){const t=jb(),n=o=>co({type:"UPDATE_TOAST",toast:{...o,id:t}}),r=()=>co({type:"DISMISS_TOAST",toastId:t});return co({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(us);return m.useEffect(()=>(cs.push(t),()=>{const n=cs.indexOf(t);n>-1&&cs.splice(n,1)}),[e]),{...e,toast:Pb,dismiss:n=>co({type:"DISMISS_TOAST",toastId:n})}}function kt(e){const t=m.useRef(e);return m.useEffect(()=>{t.current=e}),m.useMemo(()=>(...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)},[])}function Ob(e,t=globalThis==null?void 0:globalThis.document){const n=kt(e);m.useEffect(()=>{const r=o=>{o.key==="Escape"&&n(o)};return t.addEventListener("keydown",r,{capture:!0}),()=>t.removeEventListener("keydown",r,{capture:!0})},[n,t])}var Mb="DismissableLayer",pa="dismissableLayer.update",Db="dismissableLayer.pointerDownOutside",Lb="dismissableLayer.focusOutside",nd,rd=m.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),ds=m.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:a,...l}=e,u=m.useContext(rd),[d,f]=m.useState(null),h=(d==null?void 0:d.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,p]=m.useState({}),b=Ke(t,E=>f(E)),x=Array.from(u.layers),[g]=[...u.layersWithOutsidePointerEventsDisabled].slice(-1),v=x.indexOf(g),w=d?x.indexOf(d):-1,S=u.layersWithOutsidePointerEventsDisabled.size>0,N=w>=v,T=Bb(E=>{const A=E.target,j=[...u.branches].some(P=>P.contains(A));!N||j||(o==null||o(E),i==null||i(E),E.defaultPrevented||a==null||a())},h),k=zb(E=>{const A=E.target;[...u.branches].some(P=>P.contains(A))||(s==null||s(E),i==null||i(E),E.defaultPrevented||a==null||a())},h);return Ob(E=>{w===u.layers.size-1&&(r==null||r(E),!E.defaultPrevented&&a&&(E.preventDefault(),a()))},h),m.useEffect(()=>{if(d)return n&&(u.layersWithOutsidePointerEventsDisabled.size===0&&(nd=h.body.style.pointerEvents,h.body.style.pointerEvents="none"),u.layersWithOutsidePointerEventsDisabled.add(d)),u.layers.add(d),od(),()=>{n&&u.layersWithOutsidePointerEventsDisabled.size===1&&(h.body.style.pointerEvents=nd)}},[d,h,n,u]),m.useEffect(()=>()=>{d&&(u.layers.delete(d),u.layersWithOutsidePointerEventsDisabled.delete(d),od())},[d,u]),m.useEffect(()=>{const E=()=>p({});return document.addEventListener(pa,E),()=>document.removeEventListener(pa,E)},[]),c.jsx(_e.div,{...l,ref:b,style:{pointerEvents:S?N?"auto":"none":void 0,...e.style},onFocusCapture:de(e.onFocusCapture,k.onFocusCapture),onBlurCapture:de(e.onBlurCapture,k.onBlurCapture),onPointerDownCapture:de(e.onPointerDownCapture,T.onPointerDownCapture)})});ds.displayName=Mb;var $b="DismissableLayerBranch",Fb=m.forwardRef((e,t)=>{const n=m.useContext(rd),r=m.useRef(null),o=Ke(t,r);return m.useEffect(()=>{const s=r.current;if(s)return n.branches.add(s),()=>{n.branches.delete(s)}},[n.branches]),c.jsx(_e.div,{...e,ref:o})});Fb.displayName=$b;function Bb(e,t=globalThis==null?void 0:globalThis.document){const n=kt(e),r=m.useRef(!1),o=m.useRef(()=>{});return m.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let l=function(){sd(Db,n,u,{discrete:!0})};const u={originalEvent:a};a.pointerType==="touch"?(t.removeEventListener("click",o.current),o.current=l,t.addEventListener("click",o.current,{once:!0})):l()}else t.removeEventListener("click",o.current);r.current=!1},i=window.setTimeout(()=>{t.addEventListener("pointerdown",s)},0);return()=>{window.clearTimeout(i),t.removeEventListener("pointerdown",s),t.removeEventListener("click",o.current)}},[t,n]),{onPointerDownCapture:()=>r.current=!0}}function zb(e,t=globalThis==null?void 0:globalThis.document){const n=kt(e),r=m.useRef(!1);return m.useEffect(()=>{const o=s=>{s.target&&!r.current&&sd(Lb,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 od(){const e=new CustomEvent(pa);document.dispatchEvent(e)}function sd(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?Ru(o,s):o.dispatchEvent(s)}var ma="focusScope.autoFocusOnMount",ga="focusScope.autoFocusOnUnmount",id={bubbles:!1,cancelable:!0},Hb="FocusScope",fs=m.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:s,...i}=e,[a,l]=m.useState(null),u=kt(o),d=kt(s),f=m.useRef(null),h=Ke(t,x=>l(x)),p=m.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;m.useEffect(()=>{if(r){let x=function(S){if(p.paused||!a)return;const N=S.target;a.contains(N)?f.current=N:Hn(f.current,{select:!0})},g=function(S){if(p.paused||!a)return;const N=S.relatedTarget;N!==null&&(a.contains(N)||Hn(f.current,{select:!0}))},v=function(S){if(document.activeElement===document.body)for(const T of S)T.removedNodes.length>0&&Hn(a)};document.addEventListener("focusin",x),document.addEventListener("focusout",g);const w=new MutationObserver(v);return a&&w.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",x),document.removeEventListener("focusout",g),w.disconnect()}}},[r,a,p.paused]),m.useEffect(()=>{if(a){cd.add(p);const x=document.activeElement;if(!a.contains(x)){const v=new CustomEvent(ma,id);a.addEventListener(ma,u),a.dispatchEvent(v),v.defaultPrevented||(Ub(Gb(ad(a)),{select:!0}),document.activeElement===x&&Hn(a))}return()=>{a.removeEventListener(ma,u),setTimeout(()=>{const v=new CustomEvent(ga,id);a.addEventListener(ga,d),a.dispatchEvent(v),v.defaultPrevented||Hn(x??document.body,{select:!0}),a.removeEventListener(ga,d),cd.remove(p)},0)}}},[a,u,d,p]);const b=m.useCallback(x=>{if(!n&&!r||p.paused)return;const g=x.key==="Tab"&&!x.altKey&&!x.ctrlKey&&!x.metaKey,v=document.activeElement;if(g&&v){const w=x.currentTarget,[S,N]=Wb(w);S&&N?!x.shiftKey&&v===N?(x.preventDefault(),n&&Hn(S,{select:!0})):x.shiftKey&&v===S&&(x.preventDefault(),n&&Hn(N,{select:!0})):v===w&&x.preventDefault()}},[n,r,p.paused]);return c.jsx(_e.div,{tabIndex:-1,...i,ref:h,onKeyDown:b})});fs.displayName=Hb;function Ub(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(Hn(r,{select:t}),document.activeElement!==n)return}function Wb(e){const t=ad(e),n=ld(t,e),r=ld(t.reverse(),e);return[n,r]}function ad(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 ld(e,t){for(const n of e)if(!Vb(n,{upTo:t}))return n}function Vb(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 Kb(e){return e instanceof HTMLInputElement&&"select"in e}function Hn(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&Kb(e)&&t&&e.select()}}var cd=qb();function qb(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=ud(e,t),e.unshift(t)},remove(t){var n;e=ud(e,t),(n=e[0])==null||n.resume()}}}function ud(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function Gb(e){return e.filter(t=>t.tagName!=="A")}var Yb="Portal",hs=m.forwardRef((e,t)=>{var a;const{container:n,...r}=e,[o,s]=m.useState(!1);St(()=>s(!0),[]);const i=n||o&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?ii.createPortal(c.jsx(_e.div,{...r,ref:t}),i):null});hs.displayName=Yb;var xa=0;function va(){m.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??dd()),document.body.insertAdjacentElement("beforeend",e[1]??dd()),xa++,()=>{xa===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),xa--}},[])}function dd(){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 Sn=function(){return Sn=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},Sn.apply(this,arguments)};function fd(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 Xb(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 ps="right-scroll-bar-position",ms="width-before-scroll-bar",Jb="with-scroll-bars-hidden",Zb="--removed-body-scroll-bar-size";function ba(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function Qb(e,t){var n=y.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 ew=typeof window<"u"?m.useLayoutEffect:m.useEffect,hd=new WeakMap;function tw(e,t){var n=Qb(null,function(r){return e.forEach(function(o){return ba(o,r)})});return ew(function(){var r=hd.get(n);if(r){var o=new Set(r),s=new Set(e),i=n.current;o.forEach(function(a){s.has(a)||ba(a,null)}),s.forEach(function(a){o.has(a)||ba(a,i)})}hd.set(n,e)},[e]),n}function nw(e){return e}function rw(e,t){t===void 0&&(t=nw);var n=[],r=!1,o={read:function(){if(r)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return n.length?n[n.length-1]:e},useMedium:function(s){var i=t(s,r);return n.push(i),function(){n=n.filter(function(a){return a!==i})}},assignSyncMedium:function(s){for(r=!0;n.length;){var i=n;n=[],i.forEach(s)}n={push:function(a){return s(a)},filter:function(){return n}}},assignMedium:function(s){r=!0;var i=[];if(n.length){var a=n;n=[],a.forEach(s),i=n}var l=function(){var d=i;i=[],d.forEach(s)},u=function(){return Promise.resolve().then(l)};u(),n={push:function(d){i.push(d),u()},filter:function(d){return i=i.filter(d),n}}}};return o}function ow(e){e===void 0&&(e={});var t=rw(null);return t.options=Sn({async:!0,ssr:!1},e),t}var pd=function(e){var t=e.sideCar,n=fd(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,Sn({},n))};pd.isSideCarExport=!0;function sw(e,t){return e.useMedium(t),pd}var md=ow(),wa=function(){},gs=m.forwardRef(function(e,t){var n=m.useRef(null),r=m.useState({onScrollCapture:wa,onWheelCapture:wa,onTouchMoveCapture:wa}),o=r[0],s=r[1],i=e.forwardProps,a=e.children,l=e.className,u=e.removeScrollBar,d=e.enabled,f=e.shards,h=e.sideCar,p=e.noRelative,b=e.noIsolation,x=e.inert,g=e.allowPinchZoom,v=e.as,w=v===void 0?"div":v,S=e.gapMode,N=fd(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),T=h,k=tw([n,t]),E=Sn(Sn({},N),o);return m.createElement(m.Fragment,null,d&&m.createElement(T,{sideCar:md,removeScrollBar:u,shards:f,noRelative:p,noIsolation:b,inert:x,setCallbacks:s,allowPinchZoom:!!g,lockRef:n,gapMode:S}),i?m.cloneElement(m.Children.only(a),Sn(Sn({},E),{ref:k})):m.createElement(w,Sn({},E,{className:l,ref:k}),a))});gs.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},gs.classNames={fullWidth:ms,zeroRight:ps};var iw=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function aw(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=iw();return t&&e.setAttribute("nonce",t),e}function lw(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function cw(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var uw=function(){var e=0,t=null;return{add:function(n){e==0&&(t=aw())&&(lw(t,n),cw(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},dw=function(){var e=uw();return function(t,n){m.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},gd=function(){var e=dw(),t=function(n){var r=n.styles,o=n.dynamic;return e(r,o),null};return t},fw={left:0,top:0,right:0,gap:0},ya=function(e){return parseInt(e||"",10)||0},hw=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[ya(n),ya(r),ya(o)]},pw=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return fw;var t=hw(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])}},mw=gd(),Ar="data-scroll-locked",gw=function(e,t,n,r){var o=e.left,s=e.top,i=e.right,a=e.gap;return n===void 0&&(n="margin"),`
|
|
85
|
+
.`.concat(Jb,` {
|
|
86
86
|
overflow: hidden `).concat(r,`;
|
|
87
87
|
padding-right: `).concat(a,"px ").concat(r,`;
|
|
88
88
|
}
|
|
89
|
-
body[`).concat(
|
|
89
|
+
body[`).concat(Ar,`] {
|
|
90
90
|
overflow: hidden `).concat(r,`;
|
|
91
91
|
overscroll-behavior: contain;
|
|
92
92
|
`).concat([t&&"position: relative ".concat(r,";"),n==="margin"&&`
|
|
@@ -99,37 +99,37 @@ Please report this to https://github.com/markedjs/marked.`,e){const o="<p>An err
|
|
|
99
99
|
`),n==="padding"&&"padding-right: ".concat(a,"px ").concat(r,";")].filter(Boolean).join(""),`
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
.`).concat(
|
|
102
|
+
.`).concat(ps,` {
|
|
103
103
|
right: `).concat(a,"px ").concat(r,`;
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
.`).concat(
|
|
106
|
+
.`).concat(ms,` {
|
|
107
107
|
margin-right: `).concat(a,"px ").concat(r,`;
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
.`).concat(
|
|
110
|
+
.`).concat(ps," .").concat(ps,` {
|
|
111
111
|
right: 0 `).concat(r,`;
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
-
.`).concat(
|
|
114
|
+
.`).concat(ms," .").concat(ms,` {
|
|
115
115
|
margin-right: 0 `).concat(r,`;
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
-
body[`).concat(
|
|
119
|
-
`).concat(
|
|
118
|
+
body[`).concat(Ar,`] {
|
|
119
|
+
`).concat(Zb,": ").concat(a,`px;
|
|
120
120
|
}
|
|
121
|
-
`)},
|
|
121
|
+
`)},xd=function(){var e=parseInt(document.body.getAttribute(Ar)||"0",10);return isFinite(e)?e:0},xw=function(){m.useEffect(function(){return document.body.setAttribute(Ar,(xd()+1).toString()),function(){var e=xd()-1;e<=0?document.body.removeAttribute(Ar):document.body.setAttribute(Ar,e.toString())}},[])},vw=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,o=r===void 0?"margin":r;xw();var s=m.useMemo(function(){return pw(o)},[o]);return m.createElement(mw,{styles:gw(s,!t,o,n?"":"!important")})},Sa=!1;if(typeof window<"u")try{var xs=Object.defineProperty({},"passive",{get:function(){return Sa=!0,!0}});window.addEventListener("test",xs,xs),window.removeEventListener("test",xs,xs)}catch{Sa=!1}var _r=Sa?{passive:!1}:!1,bw=function(e){return e.tagName==="TEXTAREA"},vd=function(e,t){if(!(e instanceof Element))return!1;var n=window.getComputedStyle(e);return n[t]!=="hidden"&&!(n.overflowY===n.overflowX&&!bw(e)&&n[t]==="visible")},ww=function(e){return vd(e,"overflowY")},yw=function(e){return vd(e,"overflowX")},bd=function(e,t){var n=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var o=wd(e,r);if(o){var s=yd(e,r),i=s[1],a=s[2];if(i>a)return!0}r=r.parentNode}while(r&&r!==n.body);return!1},Sw=function(e){var t=e.scrollTop,n=e.scrollHeight,r=e.clientHeight;return[t,n,r]},Cw=function(e){var t=e.scrollLeft,n=e.scrollWidth,r=e.clientWidth;return[t,n,r]},wd=function(e,t){return e==="v"?ww(t):yw(t)},yd=function(e,t){return e==="v"?Sw(t):Cw(t)},Tw=function(e,t){return e==="h"&&t==="rtl"?-1:1},kw=function(e,t,n,r,o){var s=Tw(e,window.getComputedStyle(t).direction),i=s*r,a=n.target,l=t.contains(a),u=!1,d=i>0,f=0,h=0;do{if(!a)break;var p=yd(e,a),b=p[0],x=p[1],g=p[2],v=x-g-s*b;(b||v)&&wd(e,a)&&(f+=v,h+=b);var w=a.parentNode;a=w&&w.nodeType===Node.DOCUMENT_FRAGMENT_NODE?w.host:w}while(!l&&a!==document.body||l&&(t.contains(a)||t===a));return(d&&Math.abs(f)<1||!d&&Math.abs(h)<1)&&(u=!0),u},vs=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},Sd=function(e){return[e.deltaX,e.deltaY]},Cd=function(e){return e&&"current"in e?e.current:e},Iw=function(e,t){return e[0]===t[0]&&e[1]===t[1]},Ew=function(e){return`
|
|
122
122
|
.block-interactivity-`.concat(e,` {pointer-events: none;}
|
|
123
123
|
.allow-interactivity-`).concat(e,` {pointer-events: all;}
|
|
124
|
-
`)},
|
|
124
|
+
`)},Nw=0,jr=[];function Aw(e){var t=m.useRef([]),n=m.useRef([0,0]),r=m.useRef(),o=m.useState(Nw++)[0],s=m.useState(gd)[0],i=m.useRef(e);m.useEffect(function(){i.current=e},[e]),m.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(o));var x=Xb([e.lockRef.current],(e.shards||[]).map(Cd),!0).filter(Boolean);return x.forEach(function(g){return g.classList.add("allow-interactivity-".concat(o))}),function(){document.body.classList.remove("block-interactivity-".concat(o)),x.forEach(function(g){return g.classList.remove("allow-interactivity-".concat(o))})}}},[e.inert,e.lockRef.current,e.shards]);var a=m.useCallback(function(x,g){if("touches"in x&&x.touches.length===2||x.type==="wheel"&&x.ctrlKey)return!i.current.allowPinchZoom;var v=vs(x),w=n.current,S="deltaX"in x?x.deltaX:w[0]-v[0],N="deltaY"in x?x.deltaY:w[1]-v[1],T,k=x.target,E=Math.abs(S)>Math.abs(N)?"h":"v";if("touches"in x&&E==="h"&&k.type==="range")return!1;var A=bd(E,k);if(!A)return!0;if(A?T=E:(T=E==="v"?"h":"v",A=bd(E,k)),!A)return!1;if(!r.current&&"changedTouches"in x&&(S||N)&&(r.current=T),!T)return!0;var j=r.current||T;return kw(j,g,x,j==="h"?S:N)},[]),l=m.useCallback(function(x){var g=x;if(!(!jr.length||jr[jr.length-1]!==s)){var v="deltaY"in g?Sd(g):vs(g),w=t.current.filter(function(T){return T.name===g.type&&(T.target===g.target||g.target===T.shadowParent)&&Iw(T.delta,v)})[0];if(w&&w.should){g.cancelable&&g.preventDefault();return}if(!w){var S=(i.current.shards||[]).map(Cd).filter(Boolean).filter(function(T){return T.contains(g.target)}),N=S.length>0?a(g,S[0]):!i.current.noIsolation;N&&g.cancelable&&g.preventDefault()}}},[]),u=m.useCallback(function(x,g,v,w){var S={name:x,delta:g,target:v,should:w,shadowParent:_w(v)};t.current.push(S),setTimeout(function(){t.current=t.current.filter(function(N){return N!==S})},1)},[]),d=m.useCallback(function(x){n.current=vs(x),r.current=void 0},[]),f=m.useCallback(function(x){u(x.type,Sd(x),x.target,a(x,e.lockRef.current))},[]),h=m.useCallback(function(x){u(x.type,vs(x),x.target,a(x,e.lockRef.current))},[]);m.useEffect(function(){return jr.push(s),e.setCallbacks({onScrollCapture:f,onWheelCapture:f,onTouchMoveCapture:h}),document.addEventListener("wheel",l,_r),document.addEventListener("touchmove",l,_r),document.addEventListener("touchstart",d,_r),function(){jr=jr.filter(function(x){return x!==s}),document.removeEventListener("wheel",l,_r),document.removeEventListener("touchmove",l,_r),document.removeEventListener("touchstart",d,_r)}},[]);var p=e.removeScrollBar,b=e.inert;return m.createElement(m.Fragment,null,b?m.createElement(s,{styles:Ew(o)}):null,p?m.createElement(vw,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function _w(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const jw=sw(md,Aw);var bs=m.forwardRef(function(e,t){return m.createElement(gs,Sn({},e,{ref:t,sideCar:jw}))});bs.classNames=gs.classNames;var Rw=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},Rr=new WeakMap,ws=new WeakMap,ys={},Ca=0,Td=function(e){return e&&(e.host||Td(e.parentNode))},Pw=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=Td(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})},Ow=function(e,t,n,r){var o=Pw(t,Array.isArray(e)?e:[e]);ys[n]||(ys[n]=new WeakMap);var s=ys[n],i=[],a=new Set,l=new Set(o),u=function(f){!f||a.has(f)||(a.add(f),u(f.parentNode))};o.forEach(u);var d=function(f){!f||l.has(f)||Array.prototype.forEach.call(f.children,function(h){if(a.has(h))d(h);else try{var p=h.getAttribute(r),b=p!==null&&p!=="false",x=(Rr.get(h)||0)+1,g=(s.get(h)||0)+1;Rr.set(h,x),s.set(h,g),i.push(h),x===1&&b&&ws.set(h,!0),g===1&&h.setAttribute(n,"true"),b||h.setAttribute(r,"true")}catch(v){console.error("aria-hidden: cannot operate on ",h,v)}})};return d(t),a.clear(),Ca++,function(){i.forEach(function(f){var h=Rr.get(f)-1,p=s.get(f)-1;Rr.set(f,h),s.set(f,p),h||(ws.has(f)||f.removeAttribute(r),ws.delete(f)),p||f.removeAttribute(n)}),Ca--,Ca||(Rr=new WeakMap,Rr=new WeakMap,ws=new WeakMap,ys={})}},Ta=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),o=Rw(e);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live], script"))),Ow(r,o,n,"aria-hidden")):function(){return null}},Ss="Dialog",[kd,UT]=wn(Ss),[Mw,cn]=kd(Ss),Id=e=>{const{__scopeDialog:t,children:n,open:r,defaultOpen:o,onOpenChange:s,modal:i=!0}=e,a=m.useRef(null),l=m.useRef(null),[u,d]=sr({prop:r,defaultProp:o??!1,onChange:s,caller:Ss});return c.jsx(Mw,{scope:t,triggerRef:a,contentRef:l,contentId:yn(),titleId:yn(),descriptionId:yn(),open:u,onOpenChange:d,onOpenToggle:m.useCallback(()=>d(f=>!f),[d]),modal:i,children:n})};Id.displayName=Ss;var Ed="DialogTrigger",Nd=m.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=cn(Ed,n),s=Ke(t,o.triggerRef);return c.jsx(_e.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":Ea(o.open),...r,ref:s,onClick:de(e.onClick,o.onOpenToggle)})});Nd.displayName=Ed;var ka="DialogPortal",[Dw,Ad]=kd(ka,{forceMount:void 0}),_d=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:o}=e,s=cn(ka,t);return c.jsx(Dw,{scope:t,forceMount:n,children:m.Children.map(r,i=>c.jsx(Wt,{present:n||s.open,children:c.jsx(hs,{asChild:!0,container:o,children:i})}))})};_d.displayName=ka;var Cs="DialogOverlay",jd=m.forwardRef((e,t)=>{const n=Ad(Cs,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=cn(Cs,e.__scopeDialog);return s.modal?c.jsx(Wt,{present:r||s.open,children:c.jsx($w,{...o,ref:t})}):null});jd.displayName=Cs;var Lw=Jn.createSlot("DialogOverlay.RemoveScroll"),$w=m.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=cn(Cs,n);return c.jsx(bs,{as:Lw,allowPinchZoom:!0,shards:[o.contentRef],children:c.jsx(_e.div,{"data-state":Ea(o.open),...r,ref:t,style:{pointerEvents:"auto",...r.style}})})}),ar="DialogContent",Rd=m.forwardRef((e,t)=>{const n=Ad(ar,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=cn(ar,e.__scopeDialog);return c.jsx(Wt,{present:r||s.open,children:s.modal?c.jsx(Fw,{...o,ref:t}):c.jsx(Bw,{...o,ref:t})})});Rd.displayName=ar;var Fw=m.forwardRef((e,t)=>{const n=cn(ar,e.__scopeDialog),r=m.useRef(null),o=Ke(t,n.contentRef,r);return m.useEffect(()=>{const s=r.current;if(s)return Ta(s)},[]),c.jsx(Pd,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:de(e.onCloseAutoFocus,s=>{var i;s.preventDefault(),(i=n.triggerRef.current)==null||i.focus()}),onPointerDownOutside:de(e.onPointerDownOutside,s=>{const i=s.detail.originalEvent,a=i.button===0&&i.ctrlKey===!0;(i.button===2||a)&&s.preventDefault()}),onFocusOutside:de(e.onFocusOutside,s=>s.preventDefault())})}),Bw=m.forwardRef((e,t)=>{const n=cn(ar,e.__scopeDialog),r=m.useRef(!1),o=m.useRef(!1);return c.jsx(Pd,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var i,a;(i=e.onCloseAutoFocus)==null||i.call(e,s),s.defaultPrevented||(r.current||(a=n.triggerRef.current)==null||a.focus(),s.preventDefault()),r.current=!1,o.current=!1},onInteractOutside:s=>{var l,u;(l=e.onInteractOutside)==null||l.call(e,s),s.defaultPrevented||(r.current=!0,s.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const i=s.target;((u=n.triggerRef.current)==null?void 0:u.contains(i))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&o.current&&s.preventDefault()}})}),Pd=m.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:s,...i}=e,a=cn(ar,n),l=m.useRef(null),u=Ke(t,l);return va(),c.jsxs(c.Fragment,{children:[c.jsx(fs,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s,children:c.jsx(ds,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":Ea(a.open),...i,ref:u,onDismiss:()=>a.onOpenChange(!1)})}),c.jsxs(c.Fragment,{children:[c.jsx(zw,{titleId:a.titleId}),c.jsx(Uw,{contentRef:l,descriptionId:a.descriptionId})]})]})}),Ia="DialogTitle",Od=m.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=cn(Ia,n);return c.jsx(_e.h2,{id:o.titleId,...r,ref:t})});Od.displayName=Ia;var Md="DialogDescription",Dd=m.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=cn(Md,n);return c.jsx(_e.p,{id:o.descriptionId,...r,ref:t})});Dd.displayName=Md;var Ld="DialogClose",$d=m.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=cn(Ld,n);return c.jsx(_e.button,{type:"button",...r,ref:t,onClick:de(e.onClick,()=>o.onOpenChange(!1))})});$d.displayName=Ld;function Ea(e){return e?"open":"closed"}var Fd="DialogTitleWarning",[WT,Bd]=Gv(Fd,{contentName:ar,titleName:Ia,docsSlug:"dialog"}),zw=({titleId:e})=>{const t=Bd(Fd),n=`\`${t.contentName}\` requires a \`${t.titleName}\` for the component to be accessible for screen reader users.
|
|
125
125
|
|
|
126
126
|
If you want to hide the \`${t.titleName}\`, you can wrap it with our VisuallyHidden component.
|
|
127
127
|
|
|
128
|
-
For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return m.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},
|
|
129
|
-
… [truncated ${i.length-o} chars]`}catch{return""}},n=e.filter(r=>r.type==="tool_end");if(n.length)try{return n.length===1?t(n[0].output):t(n.map(r=>({toolCallId:r.toolCallId,output:r.output})))}catch{}return t(e)}function
|
|
130
|
-
… [truncated ${
|
|
131
|
-
dark:bg-background/10 dark:border-border/30 dark:hover:bg-background/20`,children:[L[
|
|
132
|
-
… [truncated ${me.length-lr} chars]`:me,it=N==="expanded";return c.jsxs(ju,{open:it,onOpenChange:Me=>C(Me?"expanded":"preview"),children:[c.jsx("div",{className:"flex items-center gap-2 text-xs",children:c.jsx(Zi,{variant:"outline",children:(he.name??"tool")+(he.toolCallId?` • ${he.toolCallId.slice(0,8)}`:"")})}),c.jsx("div",{className:"font-mono text-sm mt-1",children:c.jsx("pre",{className:"whitespace-pre-wrap break-words",children:it?Oe:Oe.slice(0,d)+(Oe.length>d?"...":"")})}),c.jsx(Ru,{asChild:!0,children:c.jsx(Ge,{variant:"ghost",size:"sm",className:"h-6 text-xs",children:it?c.jsxs(c.Fragment,{children:[" ",c.jsx(oe.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):c.jsxs(c.Fragment,{children:[c.jsx(oe.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more"]})})})]},he.toolCallId??Ce)})})}if(!$){const re=c.jsx("div",{className:"space-y-2",children:t.content.map((he,Ce)=>c.jsx(ct,{part:he,i:Ce},Ce))});return r?c.jsxs("div",{"aria-busy":"true",role:"status",children:[re,c.jsx(Kb,{className:D})]}):re}},[Q,we.length,ye.length,Se.length,r,t.model,$,de.name,K,N,u,tt,D]),gt=y.useMemo(()=>qb(t),[t]);return c.jsxs(c.Fragment,{children:[c.jsx("div",{className:Z(Ze(),p.container),children:c.jsxs("div",{className:Z(Qe(),p.content),children:[(i||a||$)&&c.jsxs("div",{className:Z("flex items-center justify-between mb-2 pb-2 border-b border-current/10",U&&"mb-1 pb-1",D,p.header),children:[c.jsxs("div",{className:"flex items-center gap-2",children:[pe(),a&>&&c.jsx("span",{className:Z("font-medium",U?"text-xs":"text-sm"),children:gt}),$&&de.name&&c.jsxs(Zi,{variant:"outline",className:Z("text-xs flex items-center gap-1 cursor-pointer",D,"border border-current/40",U&&"text-xs h-4"),role:"button",tabIndex:0,"aria-expanded":N!=="collapsed",onKeyDown:J=>{(J.key==="Enter"||J.key===" ")&&(J.preventDefault(),C(re=>re==="collapsed"?"preview":"collapsed"))},onClick:()=>C(J=>J==="collapsed"?"preview":"collapsed"),children:[c.jsx("span",{children:de.name}),c.jsx("span",{className:"inline-flex items-center",children:N!=="collapsed"?c.jsx(oe.ChevronUp,{className:"h-3 w-3"}):c.jsx(oe.ChevronDown,{className:"h-3 w-3"})})]}),$&&!de.name&&c.jsx(Ge,{variant:"ghost",size:"sm",className:Z("h-6 px-1",D,"hover:bg-foreground/10"),onClick:()=>C(J=>J==="collapsed"?"preview":"collapsed"),children:c.jsxs("span",{className:"text-xs flex items-center gap-1",children:["Tool Output ",N!=="collapsed"?c.jsx(oe.ChevronUp,{className:"h-3 w-3"}):c.jsx(oe.ChevronDown,{className:"h-3 w-3"})]})})]}),c.jsxs("div",{className:"flex items-center gap-2",children:[i&&t.createdAt&&c.jsx("time",{className:Z("text-xs opacity-60",D,U&&"text-xs"),dateTime:new Date(t.createdAt).toISOString(),title:new Date(t.createdAt).toLocaleString(),children:new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit"}).format(new Date(t.createdAt))}),s&&!o&&c.jsxs("div",{className:Z("opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",p.actions),children:[c.jsxs("div",{className:"relative",children:[c.jsx(Ge,{variant:"ghost",size:"sm",onClick:()=>X($?"visible":"all"),className:Z("h-6 w-6 p-0 hover:bg-foreground/10",D,U&&"h-5 w-5"),"aria-label":$?"Copy visible":"Copy message",title:$?"Copy visible portion":"Copy message",children:c.jsx(oe.Copy,{className:Z(b?"text-success":D,U?"h-3 w-3":"h-4 w-4")})}),$&&c.jsx(Ge,{variant:"ghost",size:"sm",onClick:()=>X("all"),className:Z("h-6 px-1 text-xs hover:bg-foreground/10",D),"aria-label":"Copy all (may be large)",title:"Copy all (may be large)",children:"all"})]}),B==="user"&&w&&c.jsx(Ge,{variant:"ghost",size:"sm",onClick:ee,className:Z("h-6 w-6 p-0 hover:bg-foreground/10",D,U&&"h-5 w-5"),"aria-label":"Edit message",children:c.jsx(oe.Edit,{className:Z(D,U?"h-3 w-3":"h-4 w-4")})}),B==="assistant"&&x&&c.jsx(Ge,{variant:"ghost",size:"sm",onClick:fe,className:Z("h-6 w-6 p-0 hover:bg-foreground/10",D,U&&"h-5 w-5"),"aria-label":"Regenerate response",children:c.jsx(oe.RotateCcw,{className:Z(D,U?"h-3 w-3":"h-4 w-4")})})]})]})]}),c.jsx("div",{className:"relative",children:Be()}),$&&N==="expanded"&&(de.toolCallId||de.name)&&c.jsxs("div",{className:Z("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",U&&"text-xs"),children:[de.name&&c.jsxs("div",{children:["Function: ",de.name]}),de.toolCallId&&c.jsxs("div",{children:["Call ID: ",de.toolCallId]})]}),!(i||a||$)&&s&&!o&&c.jsxs("div",{className:Z("absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",p.actions),children:[c.jsx(Ge,{variant:"ghost",size:"sm",onClick:()=>X(),className:Z("h-6 w-6 p-0 hover:bg-background/50 text-current",U&&"h-5 w-5"),children:c.jsx(oe.Copy,{className:Z(b?"text-success":"text-current",U?"h-3 w-3":"h-4 w-4")})}),B==="user"&&w&&c.jsx(Ge,{variant:"ghost",size:"sm",onClick:ee,className:Z("h-6 w-6 p-0 hover:bg-background/50 text-current",U&&"h-5 w-5"),children:c.jsx(oe.Edit,{className:Z("text-current",U?"h-3 w-3":"h-4 w-4")})}),B==="assistant"&&x&&c.jsx(Ge,{variant:"ghost",size:"sm",onClick:fe,className:Z("h-6 w-6 p-0 hover:bg-background/50 text-current",U&&"h-5 w-5"),children:c.jsx(oe.RotateCcw,{className:Z("text-current",U?"h-3 w-3":"h-4 w-4")})})]})]})}),G&&c.jsx(Bb,{isOpen:V,onClose:()=>{M(!1),q(null)},fileId:G.id,fileName:G.name,mimeType:G.mimeType})]})},(e,t)=>{var i,a,l,u,d,f,h,p;if(t.isStreamingMessage||e.isStreamingMessage||!(e.message.id===t.message.id&&qd(e.message)===qd(t.message)))return!1;const o=["isEditing","showActions","layoutSize","showTimestamp","showAgentName","truncateToolMessages","toolMessagePreviewLength","truncateUserMessages","userMessagePreviewLength"].every(w=>e[w]===t[w]),s=((i=e.customStyles)==null?void 0:i.container)===((a=t.customStyles)==null?void 0:a.container)&&((l=e.customStyles)==null?void 0:l.content)===((u=t.customStyles)==null?void 0:u.content)&&((d=e.customStyles)==null?void 0:d.actions)===((f=t.customStyles)==null?void 0:f.actions)&&((h=e.customStyles)==null?void 0:h.header)===((p=t.customStyles)==null?void 0:p.header);return o&&s});function Gb({data:e}){if(Array.isArray(e))return e.every(n=>n===null||["string","number","boolean"].includes(typeof n))?c.jsx("div",{className:Ss,children:c.jsx("ul",{className:"list-disc pl-5",children:e.map((n,r)=>c.jsx("li",{children:String(n)},r))})}):c.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:Ca(e)});if(e&&typeof e=="object"){const t=Array.isArray(e.distilled_facts)?e.distilled_facts:null,n=Array.isArray(e.follow_up_queries)?e.follow_up_queries:null,r=typeof e.is_sufficient=="boolean"?e.is_sufficient:void 0;if(t||n||typeof r=="boolean")return c.jsxs("div",{className:Ss,children:[typeof r=="boolean"&&c.jsxs("p",{children:[c.jsx("strong",{children:"Is sufficient:"})," ",r?"Yes":"No"]}),n&&n.length>0&&c.jsxs("div",{children:[c.jsx("p",{children:c.jsx("strong",{children:"Follow-up queries:"})}),c.jsx("ul",{className:"list-disc pl-5",children:n.map((s,i)=>c.jsx("li",{children:String(s)},i))})]}),t&&t.length>0&&c.jsxs("div",{children:[c.jsx("p",{children:c.jsx("strong",{children:"Facts:"})}),c.jsx("ul",{className:"list-disc pl-5",children:t.map((s,i)=>c.jsx("li",{children:String(s)},i))})]})]});const o=Object.entries(e);return c.jsx("div",{className:Ss,children:c.jsx("dl",{className:"mt-0",children:o.map(([s,i])=>c.jsxs("div",{className:"mb-1",children:[c.jsxs("dt",{className:"inline font-medium mr-1",children:[s,":"]}),c.jsx("dd",{className:"inline",children:Yb(i)})]},s))})})}return c.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:Ca(e)})}function Yb(e){if(e==null)return String(e);const t=typeof e;if(t==="string"||t==="number"||t==="boolean")return String(e);if(Array.isArray(e)&&e.every(r=>r===null||["string","number","boolean"].includes(typeof r)))return e.join(", ");try{return c.jsx("code",{className:"text-xs",children:JSON.stringify(ao(e))})}catch{return String(e)}}function Xb({interruptPart:e,onApprove:t,onReject:n}){const r=e.title??"Approve the result?";return c.jsxs(ro,{className:"border-blue-200 dark:border-blue-800 bg-blue-50/50 dark:bg-blue-950/10",children:[c.jsxs(oo,{className:"pb-3",children:[c.jsx(so,{className:"text-blue-900 dark:text-blue-100 text-base",children:r}),c.jsx(Pu,{className:"text-blue-700 dark:text-blue-300",children:"Please approve or reject this action to continue."})]}),c.jsx(Ou,{className:"pt-0",children:c.jsxs("div",{className:"flex gap-2 ml-auto",children:[c.jsx(Ge,{size:"sm",variant:"outline",onClick:()=>n(e),className:"border-red-300 text-red-700 hover:bg-red-50 dark:border-red-700 dark:text-red-300 dark:hover:bg-red-950/50",children:"Reject"}),c.jsx(Ge,{size:"sm",onClick:()=>t(e),className:"bg-blue-600 hover:bg-blue-700 text-white",children:"Approve"})]})})]})}function Jb({data:e}){return c.jsx("dl",{className:"grid grid-cols-1 gap-y-2",children:Object.entries(e).map(([t,n])=>c.jsxs("div",{className:"flex",children:[c.jsxs("dt",{className:"font-semibold mr-2",children:[t,":"]}),c.jsx("dd",{className:"flex-1 break-words",children:Array.isArray(n)?n.map((r,o)=>c.jsxs("div",{className:"ml-4 break-words",children:["- ",String(r)]},o)):String(n)})]},t))})}function Zb({issues:e}){const t=[{key:"desirability",title:"Desirability"},{key:"feasibility",title:"Feasibility"},{key:"viability",title:"Viability"},{key:"other",title:"Other"}];return c.jsx("div",{className:Ss,children:t.map(n=>{const r=e[n.key];return!r||!r.length?null:c.jsxs("div",{className:"mb-4",children:[c.jsxs("h4",{className:"font-semibold mb-2",children:[n.title," (",r.length,")"]}),c.jsx("ol",{className:"list-decimal pl-5 space-y-2",children:r.map((o,s)=>c.jsxs("li",{children:[c.jsx("div",{className:"font-medium",children:o.title}),c.jsx("div",{className:"text-sm text-muted-foreground",children:o.description})]},s))})]},n.key)})})}const Gd=(e,t)=>(e==null?void 0:e.id)??`message-${t}`,Ta=y.forwardRef(({messages:e,isStreaming:t,streamingAssistantId:n,streamingDebounceMs:r,layoutSize:o,enableMessageEditing:s,editingMessageId:i,onStartReached:a,onEdit:l,onRegenerate:u,onCancelEdit:d,className:f,style:h,emptyMessage:p,followNewMessages:w=!0,isNavigatingCheckpoint:x=!1,onScrollAway:g,onAtBottom:v},b)=>{const S=y.useRef(null),N=y.useRef(null),C=y.useRef(!1),[k,I]=y.useState(!0),A=y.useCallback(L=>{I(L),g&&g(!L),v&&v(L)},[g,v]),j=y.useMemo(()=>{if(a)return async()=>{if(!C.current){C.current=!0;try{await a()}finally{C.current=!1}}}},[a]),P=y.useMemo(()=>!w||x?!1:k?"auto":!1,[k,w,x]);return e.length===0?c.jsx("div",{className:f,style:h,children:c.jsx("div",{className:"flex items-center justify-center py-8 text-muted-foreground text-center max-w-md mx-auto",children:p||"No messages yet. Start a conversation!"})}):c.jsx("div",{className:f,style:h,children:c.jsx(Tv,{ref:L=>{S.current=L},scrollerRef:L=>{N.current=L instanceof HTMLDivElement?L:null},data:e,followOutput:P,overscan:200,increaseViewportBy:{top:100,bottom:200},defaultItemHeight:80,atBottomThreshold:50,alignToBottom:!1,startReached:()=>{j&&j()},atBottomStateChange:A,style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:(L,F)=>Gd(F,L),itemContent:(L,F)=>{const V=Gd(F,L);return c.jsx("div",{className:"mb-4 last:mb-0","data-message-id":V,style:{minHeight:"60px",containIntrinsicSize:"auto 120px"},children:c.jsx(Kd,{message:F,messageIndex:L,isStreamingMessage:t&&n===F.id,streamingDebounceMs:r,isEditing:i===F.id,showActions:s,showTimestamp:!1,showAgentName:!0,layoutSize:o,truncateToolMessages:!1,toolMessagePreviewLength:200,onEdit:l,onRegenerate:()=>u(L),onCancelEdit:d})})}})})});Ta.displayName="MessageList";const Cs=1e4;function Qb(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,`
|
|
128
|
+
For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return m.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},Hw="DialogDescriptionWarning",Uw=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${Bd(Hw).contentName}}.`;return m.useEffect(()=>{var s;const o=(s=e.current)==null?void 0:s.getAttribute("aria-describedby");t&&o&&(document.getElementById(t)||console.warn(r))},[r,e,t]),null},zd=Id,Ww=Nd,Hd=_d,Ts=jd,ks=Rd,lr=Od,Is=Dd,Ud=$d;const Vw=zd,Kw=Hd,Wd=m.forwardRef(({className:e,...t},n)=>c.jsx(Ts,{ref:n,className:Q("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}));Wd.displayName=Ts.displayName;const Vd=m.forwardRef(({className:e,children:t,...n},r)=>{const o=m.useMemo(()=>{let s=!1;function i(a){m.Children.forEach(a,l=>{if(s||!m.isValidElement(l))return;const u=l.type;if(u===lr||(u==null?void 0:u.displayName)===lr.displayName||(u==null?void 0:u.name)==="DialogTitle"){s=!0;return}l.props&&l.props.children&&i(l.props.children)})}return i(t),s},[t]);return c.jsxs(Kw,{children:[c.jsx(Wd,{}),c.jsxs(ks,{ref:r,className:Q("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",e),...n,children:[!o&&c.jsx(lr,{className:"sr-only",children:"Dialog"}),t,c.jsxs(Ud,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground",children:[c.jsx(se.X,{className:"h-4 w-4"}),c.jsx("span",{className:"sr-only",children:"Close"})]})]})]})});Vd.displayName=ks.displayName;const Kd=({className:e,...t})=>c.jsx("div",{className:Q("flex flex-col space-y-1.5 text-center sm:text-left",e),...t});Kd.displayName="DialogHeader";const qd=m.forwardRef(({className:e,...t},n)=>c.jsx(lr,{ref:n,className:Q("text-lg font-semibold leading-none tracking-tight",e),...t}));qd.displayName=lr.displayName;const qw=m.forwardRef(({className:e,...t},n)=>c.jsx(Is,{ref:n,className:Q("text-sm text-muted-foreground",e),...t}));qw.displayName=Is.displayName;function Gw({isOpen:e,onClose:t,fileId:n,fileName:r,mimeType:o}){const[s,i]=y.useState(!1),[a,l]=y.useState(null),[u,d]=y.useState(null),{toast:f}=ha(),h=y.useCallback(async()=>{if(n){i(!0),d(null),l(null);try{const v=await ed(n);l(v)}catch(v){console.error("Failed to load file:",v),d(v instanceof Error?v.message:"Failed to load file")}finally{i(!1)}}},[n]);y.useEffect(()=>{e&&n&&h()},[e,n,h]);const p=async()=>{if(n)try{await Eb(n),f({title:"Download started",description:`Downloading ${r}`})}catch(v){console.error("Failed to download file:",v),f({title:"Download failed",description:String(v),variant:"destructive"})}},b=async()=>{if(n)try{const v=await ed(n),w=new Blob([v],{type:o}),S=URL.createObjectURL(w);window.open(S,"_blank"),URL.revokeObjectURL(S)}catch(v){console.error("Failed to open file externally:",v),f({title:"Failed to open file",description:String(v),variant:"destructive"})}},x=()=>s?c.jsxs("div",{className:"flex items-center justify-center py-12",children:[c.jsx(se.Loader,{className:"h-8 w-8 animate-spin mr-3"}),c.jsx("span",{children:"Loading file..."})]}):u?c.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[c.jsx("div",{className:"text-red-500 mb-4",children:"⚠️"}),c.jsx("p",{className:"text-red-600 mb-4",children:u}),c.jsx(Je,{onClick:h,variant:"outline",children:"Try Again"})]}):a?o.startsWith("image/")?c.jsx("div",{className:"flex justify-center",children:c.jsx("img",{src:`data:${o};base64,${a}`,alt:r,className:"max-w-full max-h-[70vh] object-contain rounded-lg"})}):o==="application/pdf"?c.jsx("div",{className:"w-full h-[70vh] border rounded-lg overflow-hidden",children:c.jsx("iframe",{src:`data:application/pdf;base64,${a}`,className:"w-full h-full",title:r})}):o.startsWith("text/")||o.includes("json")||o.includes("xml")?c.jsx("div",{className:"bg-gray-50 dark:bg-gray-900 rounded-lg p-4 max-h-[70vh] overflow-auto",children:c.jsx("pre",{className:"whitespace-pre-wrap font-mono text-sm",children:a})}):c.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[c.jsx(se.FileText,{className:"h-16 w-16 text-gray-400 mb-4"}),c.jsx("p",{className:"text-lg font-medium mb-2",children:r}),c.jsxs("p",{className:"text-sm text-muted-foreground mb-4",children:[o," • ",a.length," bytes"]}),c.jsx("p",{className:"text-sm text-muted-foreground",children:"This file type cannot be previewed. Use download or external view."})]}):c.jsx("div",{className:"flex items-center justify-center py-12",children:c.jsx("p",{className:"text-muted-foreground",children:"No content to display"})}),g=()=>o.startsWith("image/")?c.jsx(se.Image,{className:"h-5 w-5"}):c.jsx(se.FileText,{className:"h-5 w-5"});return c.jsx(Vw,{open:e,onOpenChange:t,children:c.jsxs(Vd,{className:"max-w-4xl max-h-[90vh] overflow-hidden",children:[c.jsx(Kd,{children:c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"flex items-center gap-3",children:[g(),c.jsxs("div",{children:[c.jsx(qd,{className:"text-left",children:r}),c.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:[o," • Click download or external view for full access"]})]})]}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsxs(Je,{variant:"outline",size:"sm",onClick:b,className:"flex items-center gap-2",children:[c.jsx(se.ExternalLink,{className:"h-4 w-4"}),"External"]}),c.jsxs(Je,{variant:"outline",size:"sm",onClick:p,className:"flex items-center gap-2",children:[c.jsx(se.Download,{className:"h-4 w-4"}),"Download"]})]})]})}),c.jsx("div",{className:"flex-1 overflow-hidden",children:x()})]})})}function Gd(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 Yd(e){return!!(e&&typeof e=="object"&&(e.type==="file"||e.mimeType||e.filename||e.sourceType==="base64"))}function uo(e){if(typeof e=="string")return e.length>2e3?e.slice(0,2e3)+"... [truncated]":e;if(e&&typeof e=="object"){if(Array.isArray(e)){const n=e.map(uo).filter(r=>r!==void 0);if(!n.length){console.debug("[message-utils] sanitizeForDisplay - array emptied -> returning undefined",{originalLength:e.length});return}return n}if(Yd(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=uo(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 Na(e){if(typeof e=="string")return e;if(Yd(e))return"";try{const t=uo(e);return t===void 0?"":typeof t=="string"?t:JSON.stringify(t,null,2)}catch{return""}}function Xd(e){if(!e)return null;if(typeof e=="object"&&!Array.isArray(e)){if(e.desirability||e.feasibility||e.viability||e.other)return{desirability:Array.isArray(e.desirability)?e.desirability:[],feasibility:Array.isArray(e.feasibility)?e.feasibility:[],viability:Array.isArray(e.viability)?e.viability:[],other:Array.isArray(e.other)?e.other:[]};if(e.output&&typeof e.output!="object")e=e.output;else if(e.output&&typeof e.output=="object")return Xd(e.output)}const t=String(e),n={desirability:[],feasibility:[],viability:[],other:[]};let r=t;const o=Math.min(...["desirability=","feasibility=","viability=","other="].map(i=>{const a=r.toLowerCase().indexOf(i);return a===-1?Number.MAX_SAFE_INTEGER:a}));o!==Number.MAX_SAFE_INTEGER&&(r=r.slice(o));for(const i of Object.keys(n)){const l=new RegExp(i+"\\s*=\\s*\\[([\\s\\S]*?)\\]","i").exec(r);if(!l)continue;const u=l[1],d=/Issue\(([\s\S]*?)\)(?:,|$)/g;let f=null;for(;(f=d.exec(u))!==null;){const h=f[1],p=/title\s*=\s*(['"])([\s\S]*?)\1/.exec(h),b=/description\s*=\s*(['"])([\s\S]*?)\1/.exec(h),x=p?p[2].trim():"",g=b?b[2].trim():"";n[i].push({title:x,description:g})}}return Object.values(n).some(i=>i.length>0)?n:null}const Es="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",cr=1e5;function Yw(e){return e.filter(t=>t.type==="text").map(t=>t.text).join("")}function Xw(e){const t=e.find(r=>r.type==="tool_call"),n=e.find(r=>r.type==="tool_end");return{name:t==null?void 0:t.name,toolCallId:(n==null?void 0:n.toolCallId)??(t==null?void 0:t.id)}}function Jw(e){const t=e.filter(r=>r.type==="tool_call");return e.filter(r=>r.type==="tool_end").map(r=>{var o;return{name:(o=t.find(s=>s.id===r.toolCallId))==null?void 0:o.name,toolCallId:r.toolCallId,output:r.output}})}function Zw(e){const t=(r,o=cr)=>{try{const s=uo(r),i=typeof s=="string"?s:JSON.stringify(s??"");return i.length<=o?i:i.slice(0,o)+`
|
|
129
|
+
… [truncated ${i.length-o} chars]`}catch{return""}},n=e.filter(r=>r.type==="tool_end");if(n.length)try{return n.length===1?t(n[0].output):t(n.map(r=>({toolCallId:r.toolCallId,output:r.output})))}catch{}return t(e)}function Qw(e){const t=e.find(r=>r.type==="tool_end");if(!t)return null;const n=t.output;return typeof n=="string"?n:null}function ey(e){return e.name&&e.name.trim()?e.name:e.model&&e.model.includes("/")?e.model.split("/").pop()||null:e.model||null}function Jd(e){const t=e.updatedAt??e.createdAt??"",n=Array.isArray(e.content)?e.content.map(r=>{switch(r.type){case"text":return`t:${r.text.length}`;case"image_url":return"img";case"file":return"file";case"tool_call":return"call";case"tool_end":return"end";default:return"unknown"}}).join("|"):"";return`${e.id}:${t}:${n}`}function ty({className:e}){const[t,n]=y.useState(0);return y.useEffect(()=>{const r=setInterval(()=>n(o=>(o+1)%4),500);return()=>clearInterval(r)},[]),c.jsxs("span",{"aria-live":"polite",className:Q("inline-block text-xs opacity-70 ml-1",e),children:["Is thinking",".".repeat(t)]})}const Zd=y.memo(function({message:t,messageIndex:n,isStreamingMessage:r=!1,isEditing:o=!1,showActions:s=!0,showTimestamp:i=!0,showAgentName:a=!0,layoutSize:l="desktop",truncateToolMessages:u=!0,toolMessagePreviewLength:d=200,truncateUserMessages:f=!0,userMessagePreviewLength:h=200,customStyles:p={},onEdit:b,onRegenerate:x,onCancelEdit:g,onCopy:v}){const[w,S]=y.useState(!1),[N,T]=y.useState("collapsed"),[k,E]=y.useState(!1),{currentThreadId:A}=Bo(),{respondToInterrupt:j}=zo(),{toast:P}=ha(),[L,$]=y.useState({}),[V,M]=y.useState(!1),[G,K]=y.useState(null),W=l==="phone"||l==="half-screen",B=t.role,F=B==="tool",ue=!(r&&B!=="user"),D=y.useMemo(()=>{switch(B){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))]"}},[B]),ee=y.useMemo(()=>Yw(t.content),[t.content]),fe=y.useMemo(()=>Xw(t.content),[t.content]),we=y.useMemo(()=>t.content.filter(Z=>Z.type==="image_url"),[t.content]),ye=y.useMemo(()=>t.content.filter(Z=>Z.type==="file"),[t.content]),Ce=y.useMemo(()=>t.content.filter(Z=>Z.type==="interrupt"),[t.content]),q=y.useMemo(()=>Zw(t.content),[t.content]);y.useMemo(()=>Qw(t.content),[t.content]);const O=y.useMemo(()=>q.length<=cr?q:`${q.slice(0,cr)}
|
|
130
|
+
… [truncated ${q.length-cr} chars]`,[q]),X=y.useCallback(async(Z="all")=>{const me=Z==="visible"&&F?O:F?q:ee;async function Te(ge){try{await navigator.clipboard.writeText(ge)}catch{try{const Oe=document.createElement("textarea");Oe.value=ge,Oe.setAttribute("readonly",""),Oe.style.position="absolute",Oe.style.left="-9999px",document.body.appendChild(Oe),Oe.select(),document.execCommand("copy"),document.body.removeChild(Oe)}catch(Oe){throw console.error("Failed to copy:",Oe),Oe}}}try{await Te(me),S(!0),setTimeout(()=>S(!1),2e3),v==null||v(me)}catch(ge){console.error("Failed to copy:",ge)}},[F,q,ee,O,v]),te=y.useCallback(()=>{if(!b)return;const Z=F?q:ee;b(t.id,Z)},[b,t.id,F,q,ee]),he=y.useCallback(()=>{x==null||x(n)},[x,n]),re=y.useCallback(async(Z,oe,me)=>{if(!ue){Z.preventDefault();return}if(L[me]){Z.preventDefault();return}try{const Te=String(oe.url??""),ge=Te.match(/\/chat\/files\/([^/]+)(?:\/(view|download))?/);if(ge){Z.preventDefault();const Oe=ge[1],at=oe.name||`file_${Oe}`,Me=oe.mimeType||"application/octet-stream";K({id:Oe,name:at,mimeType:Me}),M(!0);return}if(Te.startsWith("data:")){Z.preventDefault(),$(Me=>({...Me,[me]:!0}));const Oe=`${oe.name}_${oe.size}_${Date.now()}`,at=P({title:"Fetching file...",description:"",open:!0});try{const Me=await Nb(A??void 0);if(!Me||!Array.isArray(Me))throw new Error("Invalid file list response");const it=Me.find(mt=>!mt||typeof mt!="object"||!((mt.filename??"")===(oe.name??""))?!1:typeof oe.size=="number"&&typeof mt.size=="number"?mt.size===oe.size:!0);if(!(it!=null&&it.id))throw new Error(`File "${oe.name}" is not yet available on the server`);if(!it.id||!it.filename)throw new Error("Invalid file data received from server");K({id:it.id,name:oe.name||it.filename||`file_${it.id}`,mimeType:oe.mimeType||it.mime_type||"application/octet-stream"}),M(!0),at.update({id:at.id,title:"Success",description:`Opened ${oe.name}`,open:!0})}catch(Me){console.error("Failed to fetch server file:",Me);const it=Me instanceof Error?Me.message:"Unknown error occurred";at.update({id:at.id,title:"Failed",description:it}),P({title:"Failed to fetch file",description:it,open:!0})}finally{$(Me=>({...Me,[me]:!1}))}}}catch(Te){console.error("File click error:",Te),$(ge=>({...ge,[me]:!1}))}},[ue,L,P,A]),pe=y.useCallback(()=>{const oe=Q(W?"h-3 w-3":"h-4 w-4","opacity-60 flex-shrink-0",D);switch(B){case"user":return c.jsx(se.User,{className:oe});case"assistant":return c.jsx(se.Bot,{className:oe});case"tool":return c.jsx(se.Wrench,{className:oe});default:return c.jsx(se.Bot,{className:oe})}},[W,D,B]),tt=y.useCallback(()=>{const Z="group relative mb-4 flex w-full";switch(B){case"user":return Q(Z,"justify-end");case"assistant":case"tool":case"system":return Q(Z,"justify-start");default:return Z}},[B]),nt=y.useCallback(()=>{const Z=Q("rounded-lg px-4 py-3 relative min-w-0 max-w-full break-words",W&&"px-3 py-2 text-sm");switch(B){case"user":return Q(Z,"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 Q(Z,"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 Q(Z,"w-full md:max-w-[95%] bg-secondary/50 text-secondary-foreground border border-dashed");case"system":return Q(Z,"w-full md:max-w-[85%] bg-accent/40 text-muted-foreground border");default:return Q(Z,"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")}},[W,B]),Pe=y.useCallback(async Z=>{try{const oe=(Z==null?void 0:Z.id)||(Z==null?void 0:Z.interrupt_id);if(!oe){console.warn("Interrupt part missing id",Z);return}await j(oe,!0)}catch(oe){console.error("Failed to approve interrupt:",oe)}},[j]),He=y.useCallback(async Z=>{try{const oe=(Z==null?void 0:Z.id)||(Z==null?void 0:Z.interrupt_id);if(!oe){console.warn("Interrupt part missing id",Z);return}await j(oe,!1)}catch(oe){console.error("Failed to reject interrupt:",oe)}},[j]),ut=y.useCallback(({part:Z,i:oe})=>{if(Z.type==="text"){const me=Z.text??"",Te=me.trim(),ge=Gd(Te);return ge&&B!=="tool"?c.jsx(ny,{data:ge},oe):B==="user"&&f&&Te.length>h?c.jsxs(Du,{open:k,onOpenChange:E,children:[c.jsx("div",{className:Q("text-sm text-[hsl(var(--chat-bubble-user-text))]",W&&"text-xs"),children:k?c.jsx(ua,{content:Te,allowHtml:!1}):c.jsxs("pre",{className:Q("font-sans whitespace-pre-wrap break-words bg-transparent p-0 m-0 text-[hsl(var(--chat-bubble-user-text))]",W&&"text-xs"),children:[Te.substring(0,h),"..."]})}),c.jsx(Lu,{asChild:!0,children:c.jsx(Je,{variant:"ghost",size:"sm",className:"h-6 text-xs !text-[hsl(var(--chat-bubble-user-text))]",children:k?c.jsxs(c.Fragment,{children:[c.jsx(se.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):c.jsxs(c.Fragment,{children:[c.jsx(se.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more (",Te.length-h," chars)"]})})})]},oe):c.jsx(ua,{content:me,allowHtml:!1},oe)}if(Z.type==="image_url"){const me=Z;return c.jsx("div",{className:"my-2",children:c.jsx("img",{src:me.url,alt:me.alt??"",loading:"lazy",className:"border rounded max-h-[420px] w-auto object-contain"})},oe)}if(Z.type==="file"){const me=Z,Te=me.name||"file";return c.jsxs("a",{href:me.url,onClick:ge=>re(ge,me,oe),className:`inline-flex items-center gap-2 rounded px-2 py-1 text-xs bg-gray-100 border hover:bg-gray-200
|
|
131
|
+
dark:bg-background/10 dark:border-border/30 dark:hover:bg-background/20`,children:[L[oe]?c.jsx(se.Loader,{className:"h-4 w-4 animate-spin"}):null,c.jsxs("span",{className:"truncate max-w-[180px]",children:[Te,L[oe]?" (processing)":""]})]},oe)}return Z.type==="interrupt"?c.jsx(oy,{interruptPart:Z,onApprove:Pe,onReject:He},oe):null},[re,L,Pe,He,B,f,h,k,W]),rt=y.useCallback(()=>c.jsxs("div",{className:"flex items-center gap-2 p-2 bg-muted/30 rounded",children:[c.jsx(se.Paperclip,{className:"h-4 w-4 text-muted-foreground"}),c.jsx("span",{className:"text-sm text-muted-foreground",children:"File upload"})]}),[]),Ue=y.useCallback(()=>{const Z=ee.trim().length>0||we.length>0||ye.length>0||Ce.length>0;if(!F&&!Z&&!r)return rt();if(t.model==="reflection"){const oe=ee.trim(),me=Gd(oe);if(me&&typeof me=="object")return c.jsx(sy,{data:me})}if(F&&fe.name==="get_issues"){const oe=t.content.find(ge=>ge.type==="tool_end"),me=(oe==null?void 0:oe.output)??q,Te=Xd(me);if(Te)return c.jsx(iy,{issues:Te})}if(F){const oe=Jw(t.content);if(oe.length>0)return c.jsx("div",{className:"space-y-2",children:oe.map((me,Te)=>{const ge=typeof me.output=="string"?me.output:Na(me.output),Oe=ge.length>cr?`${ge.slice(0,cr)}
|
|
132
|
+
… [truncated ${ge.length-cr} chars]`:ge,at=N==="expanded";return c.jsxs(Du,{open:at,onOpenChange:Me=>T(Me?"expanded":"preview"),children:[c.jsx("div",{className:"flex items-center gap-2 text-xs",children:c.jsx(ra,{variant:"outline",children:(me.name??"tool")+(me.toolCallId?` • ${me.toolCallId.slice(0,8)}`:"")})}),c.jsx("div",{className:"font-mono text-sm mt-1",children:c.jsx("pre",{className:"whitespace-pre-wrap break-words",children:at?Oe:Oe.slice(0,d)+(Oe.length>d?"...":"")})}),c.jsx(Lu,{asChild:!0,children:c.jsx(Je,{variant:"ghost",size:"sm",className:"h-6 text-xs",children:at?c.jsxs(c.Fragment,{children:[" ",c.jsx(se.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):c.jsxs(c.Fragment,{children:[c.jsx(se.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more"]})})})]},me.toolCallId??Te)})})}if(!F){const oe=c.jsx("div",{className:"space-y-2",children:t.content.map((me,Te)=>c.jsx(ut,{part:me,i:Te},Te))});return r?c.jsxs("div",{"aria-busy":"true",role:"status",children:[oe,c.jsx(ty,{className:D})]}):oe}},[ee,we.length,ye.length,Ce.length,r,t.model,F,fe.name,q,N,u,rt,D]),bt=y.useMemo(()=>ey(t),[t]);return c.jsxs(c.Fragment,{children:[c.jsx("div",{className:Q(tt(),p.container),children:c.jsxs("div",{className:Q(nt(),p.content),children:[(i||a||F)&&c.jsxs("div",{className:Q("flex items-center justify-between mb-2 pb-2 border-b border-current/10",W&&"mb-1 pb-1",D,p.header),children:[c.jsxs("div",{className:"flex items-center gap-2",children:[pe(),a&&bt&&c.jsx("span",{className:Q("font-medium",W?"text-xs":"text-sm"),children:bt}),F&&fe.name&&c.jsxs(ra,{variant:"outline",className:Q("text-xs flex items-center gap-1 cursor-pointer",D,"border border-current/40",W&&"text-xs h-4"),role:"button",tabIndex:0,"aria-expanded":N!=="collapsed",onKeyDown:Z=>{(Z.key==="Enter"||Z.key===" ")&&(Z.preventDefault(),T(oe=>oe==="collapsed"?"preview":"collapsed"))},onClick:()=>T(Z=>Z==="collapsed"?"preview":"collapsed"),children:[c.jsx("span",{children:fe.name}),c.jsx("span",{className:"inline-flex items-center",children:N!=="collapsed"?c.jsx(se.ChevronUp,{className:"h-3 w-3"}):c.jsx(se.ChevronDown,{className:"h-3 w-3"})})]}),F&&!fe.name&&c.jsx(Je,{variant:"ghost",size:"sm",className:Q("h-6 px-1",D,"hover:bg-foreground/10"),onClick:()=>T(Z=>Z==="collapsed"?"preview":"collapsed"),children:c.jsxs("span",{className:"text-xs flex items-center gap-1",children:["Tool Output ",N!=="collapsed"?c.jsx(se.ChevronUp,{className:"h-3 w-3"}):c.jsx(se.ChevronDown,{className:"h-3 w-3"})]})})]}),c.jsxs("div",{className:"flex items-center gap-2",children:[i&&t.createdAt&&c.jsx("time",{className:Q("text-xs opacity-60",D,W&&"text-xs"),dateTime:new Date(t.createdAt).toISOString(),title:new Date(t.createdAt).toLocaleString(),children:new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit"}).format(new Date(t.createdAt))}),s&&!o&&c.jsxs("div",{className:Q("opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",p.actions),children:[c.jsxs("div",{className:"relative",children:[c.jsx(Je,{variant:"ghost",size:"sm",onClick:()=>X(F?"visible":"all"),className:Q("h-6 w-6 p-0 hover:bg-foreground/10",D,W&&"h-5 w-5"),"aria-label":F?"Copy visible":"Copy message",title:F?"Copy visible portion":"Copy message",children:c.jsx(se.Copy,{className:Q(w?"text-success":D,W?"h-3 w-3":"h-4 w-4")})}),F&&c.jsx(Je,{variant:"ghost",size:"sm",onClick:()=>X("all"),className:Q("h-6 px-1 text-xs hover:bg-foreground/10",D),"aria-label":"Copy all (may be large)",title:"Copy all (may be large)",children:"all"})]}),B==="user"&&b&&c.jsx(Je,{variant:"ghost",size:"sm",onClick:te,className:Q("h-6 w-6 p-0 hover:bg-foreground/10",D,W&&"h-5 w-5"),"aria-label":"Edit message",children:c.jsx(se.Edit,{className:Q(D,W?"h-3 w-3":"h-4 w-4")})}),B==="assistant"&&x&&c.jsx(Je,{variant:"ghost",size:"sm",onClick:he,className:Q("h-6 w-6 p-0 hover:bg-foreground/10",D,W&&"h-5 w-5"),"aria-label":"Regenerate response",children:c.jsx(se.RotateCcw,{className:Q(D,W?"h-3 w-3":"h-4 w-4")})})]})]})]}),c.jsx("div",{className:"relative",children:Ue()}),F&&N==="expanded"&&(fe.toolCallId||fe.name)&&c.jsxs("div",{className:Q("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",W&&"text-xs"),children:[fe.name&&c.jsxs("div",{children:["Function: ",fe.name]}),fe.toolCallId&&c.jsxs("div",{children:["Call ID: ",fe.toolCallId]})]}),!(i||a||F)&&s&&!o&&c.jsxs("div",{className:Q("absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",p.actions),children:[c.jsx(Je,{variant:"ghost",size:"sm",onClick:()=>X(),className:Q("h-6 w-6 p-0 hover:bg-background/50 text-current",W&&"h-5 w-5"),children:c.jsx(se.Copy,{className:Q(w?"text-success":"text-current",W?"h-3 w-3":"h-4 w-4")})}),B==="user"&&b&&c.jsx(Je,{variant:"ghost",size:"sm",onClick:te,className:Q("h-6 w-6 p-0 hover:bg-background/50 text-current",W&&"h-5 w-5"),children:c.jsx(se.Edit,{className:Q("text-current",W?"h-3 w-3":"h-4 w-4")})}),B==="assistant"&&x&&c.jsx(Je,{variant:"ghost",size:"sm",onClick:he,className:Q("h-6 w-6 p-0 hover:bg-background/50 text-current",W&&"h-5 w-5"),children:c.jsx(se.RotateCcw,{className:Q("text-current",W?"h-3 w-3":"h-4 w-4")})})]})]})}),G&&c.jsx(Gw,{isOpen:V,onClose:()=>{M(!1),K(null)},fileId:G.id,fileName:G.name,mimeType:G.mimeType})]})},(e,t)=>{var i,a,l,u,d,f,h,p;if(t.isStreamingMessage||e.isStreamingMessage||!(e.message.id===t.message.id&&Jd(e.message)===Jd(t.message)))return!1;const o=["isEditing","showActions","layoutSize","showTimestamp","showAgentName","truncateToolMessages","toolMessagePreviewLength","truncateUserMessages","userMessagePreviewLength"].every(b=>e[b]===t[b]),s=((i=e.customStyles)==null?void 0:i.container)===((a=t.customStyles)==null?void 0:a.container)&&((l=e.customStyles)==null?void 0:l.content)===((u=t.customStyles)==null?void 0:u.content)&&((d=e.customStyles)==null?void 0:d.actions)===((f=t.customStyles)==null?void 0:f.actions)&&((h=e.customStyles)==null?void 0:h.header)===((p=t.customStyles)==null?void 0:p.header);return o&&s});function ny({data:e}){if(Array.isArray(e))return e.every(n=>n===null||["string","number","boolean"].includes(typeof n))?c.jsx("div",{className:Es,children:c.jsx("ul",{className:"list-disc pl-5",children:e.map((n,r)=>c.jsx("li",{children:String(n)},r))})}):c.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:Na(e)});if(e&&typeof e=="object"){const t=Array.isArray(e.distilled_facts)?e.distilled_facts:null,n=Array.isArray(e.follow_up_queries)?e.follow_up_queries:null,r=typeof e.is_sufficient=="boolean"?e.is_sufficient:void 0;if(t||n||typeof r=="boolean")return c.jsxs("div",{className:Es,children:[typeof r=="boolean"&&c.jsxs("p",{children:[c.jsx("strong",{children:"Is sufficient:"})," ",r?"Yes":"No"]}),n&&n.length>0&&c.jsxs("div",{children:[c.jsx("p",{children:c.jsx("strong",{children:"Follow-up queries:"})}),c.jsx("ul",{className:"list-disc pl-5",children:n.map((s,i)=>c.jsx("li",{children:String(s)},i))})]}),t&&t.length>0&&c.jsxs("div",{children:[c.jsx("p",{children:c.jsx("strong",{children:"Facts:"})}),c.jsx("ul",{className:"list-disc pl-5",children:t.map((s,i)=>c.jsx("li",{children:String(s)},i))})]})]});const o=Object.entries(e);return c.jsx("div",{className:Es,children:c.jsx("dl",{className:"mt-0",children:o.map(([s,i])=>c.jsxs("div",{className:"mb-1",children:[c.jsxs("dt",{className:"inline font-medium mr-1",children:[s,":"]}),c.jsx("dd",{className:"inline",children:ry(i)})]},s))})})}return c.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:Na(e)})}function ry(e){if(e==null)return String(e);const t=typeof e;if(t==="string"||t==="number"||t==="boolean")return String(e);if(Array.isArray(e)&&e.every(r=>r===null||["string","number","boolean"].includes(typeof r)))return e.join(", ");try{return c.jsx("code",{className:"text-xs",children:JSON.stringify(uo(e))})}catch{return String(e)}}function oy({interruptPart:e,onApprove:t,onReject:n}){const r=e.title??"Approve the result?";return c.jsxs(io,{className:"border-blue-200 dark:border-blue-800 bg-blue-50/50 dark:bg-blue-950/10",children:[c.jsxs(ao,{className:"pb-3",children:[c.jsx(lo,{className:"text-blue-900 dark:text-blue-100 text-base",children:r}),c.jsx($u,{className:"text-blue-700 dark:text-blue-300",children:"Please approve or reject this action to continue."})]}),c.jsx(Fu,{className:"pt-0",children:c.jsxs("div",{className:"flex gap-2 ml-auto",children:[c.jsx(Je,{size:"sm",variant:"outline",onClick:()=>n(e),className:"border-red-300 text-red-700 hover:bg-red-50 dark:border-red-700 dark:text-red-300 dark:hover:bg-red-950/50",children:"Reject"}),c.jsx(Je,{size:"sm",onClick:()=>t(e),className:"bg-blue-600 hover:bg-blue-700 text-white",children:"Approve"})]})})]})}function sy({data:e}){return c.jsx("dl",{className:"grid grid-cols-1 gap-y-2",children:Object.entries(e).map(([t,n])=>c.jsxs("div",{className:"flex",children:[c.jsxs("dt",{className:"font-semibold mr-2",children:[t,":"]}),c.jsx("dd",{className:"flex-1 break-words",children:Array.isArray(n)?n.map((r,o)=>c.jsxs("div",{className:"ml-4 break-words",children:["- ",String(r)]},o)):String(n)})]},t))})}function iy({issues:e}){const t=[{key:"desirability",title:"Desirability"},{key:"feasibility",title:"Feasibility"},{key:"viability",title:"Viability"},{key:"other",title:"Other"}];return c.jsx("div",{className:Es,children:t.map(n=>{const r=e[n.key];return!r||!r.length?null:c.jsxs("div",{className:"mb-4",children:[c.jsxs("h4",{className:"font-semibold mb-2",children:[n.title," (",r.length,")"]}),c.jsx("ol",{className:"list-decimal pl-5 space-y-2",children:r.map((o,s)=>c.jsxs("li",{children:[c.jsx("div",{className:"font-medium",children:o.title}),c.jsx("div",{className:"text-sm text-muted-foreground",children:o.description})]},s))})]},n.key)})})}const Qd=(e,t)=>(e==null?void 0:e.id)??`message-${t}`,Aa=y.forwardRef(({messages:e,isStreaming:t,streamingAssistantId:n,streamingDebounceMs:r,layoutSize:o,enableMessageEditing:s,editingMessageId:i,onStartReached:a,onEdit:l,onRegenerate:u,onCancelEdit:d,className:f,style:h,emptyMessage:p,followNewMessages:b=!0,isNavigatingCheckpoint:x=!1,onScrollAway:g,onAtBottom:v},w)=>{const S=y.useRef(null),N=y.useRef(null),T=y.useRef(!1),[k,E]=y.useState(!0),A=y.useCallback(L=>{E(L),g&&g(!L),v&&v(L)},[g,v]),j=y.useMemo(()=>{if(a)return async()=>{if(!T.current){T.current=!0;try{await a()}finally{T.current=!1}}}},[a]),P=y.useMemo(()=>!b||x?!1:k?"auto":!1,[k,b,x]);return e.length===0?c.jsx("div",{className:f,style:h,children:c.jsx("div",{className:"flex items-center justify-center py-8 text-muted-foreground text-center max-w-md mx-auto",children:p||"No messages yet. Start a conversation!"})}):c.jsx("div",{className:f,style:h,children:c.jsx(Rv,{ref:L=>{S.current=L},scrollerRef:L=>{N.current=L instanceof HTMLDivElement?L:null},data:e,followOutput:P,overscan:200,increaseViewportBy:{top:100,bottom:200},defaultItemHeight:80,atBottomThreshold:50,alignToBottom:!1,startReached:()=>{j&&j()},atBottomStateChange:A,style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:(L,$)=>Qd($,L),itemContent:(L,$)=>{const V=Qd($,L);return c.jsx("div",{className:"mb-4 last:mb-0","data-message-id":V,style:{minHeight:"60px",containIntrinsicSize:"auto 120px"},children:c.jsx(Zd,{message:$,messageIndex:L,isStreamingMessage:t&&n===$.id,streamingDebounceMs:r,isEditing:i===$.id,showActions:s,showTimestamp:!1,showAgentName:!0,layoutSize:o,truncateToolMessages:!1,toolMessagePreviewLength:200,onEdit:l,onRegenerate:()=>u(L),onCancelEdit:d})})}})})});Aa.displayName="MessageList";const Ns=1e4;function ay(e){if(typeof e!="string")return String(e);const t=[/<script[^>]*>.*?<\/script>/gi,/<iframe[^>]*>.*?<\/iframe>/gi,/javascript:/gi,/vbscript:/gi,/on\w+\s*=/gi,/<object[^>]*>.*?<\/object>/gi,/<embed[^>]*>.*?<\/embed>/gi,/<form[^>]*>.*?<\/form>/gi];let n=e;for(const o of t)n=n.replace(o,"");return/<[^>]+>/.test(n)&&!/<(?!\/?(?:code|strong|em|b|i|br|p|ul|ol|li|h[1-6])\b)[^>]+>/i.test(n)?n.replace(/<code>(.*?)<\/code>/gi,"`$1`").replace(/<strong>(.*?)<\/strong>/gi,"**$1**").replace(/<b>(.*?)<\/b>/gi,"**$1**").replace(/<em>(.*?)<\/em>/gi,"*$1*").replace(/<i>(.*?)<\/i>/gi,"*$1*").replace(/<br\s*\/?>/gi,`
|
|
133
133
|
`).replace(/<p>(.*?)<\/p>/gi,`$1
|
|
134
134
|
|
|
135
135
|
`).replace(/<h([1-6])>(.*?)<\/h[1-6]>/gi,(o,s,i)=>`${"#".repeat(parseInt(s))} ${i}
|
|
@@ -137,4 +137,4 @@ For more information, see https://radix-ui.com/primitives/docs/components/${t.do
|
|
|
137
137
|
`).replace(/<ul>/gi,"").replace(/<\/ul>/gi,`
|
|
138
138
|
`).replace(/<ol>/gi,"").replace(/<\/ol>/gi,`
|
|
139
139
|
`).replace(/<li>(.*?)<\/li>/gi,`- $1
|
|
140
|
-
`).trim():n.replace(/</g,"<").replace(/>/g,">").trim()}function ey(e,t=Cs){if(!e||typeof e!="string")throw new Error("Invalid content: must be a non-empty string");if(e.length>t)throw new Error(`Message exceeds maximum length of ${t} characters`);return e}function ty(e){let t;return typeof e=="string"?t=e:typeof e=="object"&&e!==null?t=JSON.stringify(e):t=String(e),ey(t),Qb(t)}function ka(e){const t=e+"CollectionProvider",[n,r]=xn(t),[o,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),i=x=>{const{scope:g,children:v}=x,b=y.useRef(null),S=y.useRef(new Map).current;return c.jsx(o,{scope:g,itemMap:S,collectionRef:b,children:v})};i.displayName=t;const a=e+"CollectionSlot",l=Xn.createSlot(a),u=y.forwardRef((x,g)=>{const{scope:v,children:b}=x,S=s(a,v),N=Ve(g,S.collectionRef);return c.jsx(l,{ref:N,children:b})});u.displayName=a;const d=e+"CollectionItemSlot",f="data-radix-collection-item",h=Xn.createSlot(d),p=y.forwardRef((x,g)=>{const{scope:v,children:b,...S}=x,N=y.useRef(null),C=Ve(g,N),k=s(d,v);return y.useEffect(()=>(k.itemMap.set(N,{ref:N,...S}),()=>void k.itemMap.delete(N))),c.jsx(h,{[f]:"",ref:C,children:b})});p.displayName=d;function w(x){const g=s(e+"CollectionConsumer",x);return y.useCallback(()=>{const b=g.collectionRef.current;if(!b)return[];const S=Array.from(b.querySelectorAll(`[${f}]`));return Array.from(g.itemMap.values()).sort((k,I)=>S.indexOf(k.ref.current)-S.indexOf(I.ref.current))},[g.collectionRef,g.itemMap])}return[{Provider:i,Slot:u,ItemSlot:p},w,r]}var ny=m.createContext(void 0);function Ts(e){const t=m.useContext(ny);return e||t||"ltr"}const ry=["top","right","bottom","left"],zn=Math.min,zt=Math.max,ks=Math.round,Es=Math.floor,bn=e=>({x:e,y:e}),oy={left:"right",right:"left",bottom:"top",top:"bottom"},sy={start:"end",end:"start"};function Ea(e,t,n){return zt(e,zn(t,n))}function Nn(e,t){return typeof e=="function"?e(t):e}function An(e){return e.split("-")[0]}function Nr(e){return e.split("-")[1]}function Ia(e){return e==="x"?"y":"x"}function Na(e){return e==="y"?"height":"width"}const iy=new Set(["top","bottom"]);function yn(e){return iy.has(An(e))?"y":"x"}function Aa(e){return Ia(yn(e))}function ay(e,t,n){n===void 0&&(n=!1);const r=Nr(e),o=Aa(e),s=Na(o);let i=o==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(i=Is(i)),[i,Is(i)]}function ly(e){const t=Is(e);return[_a(e),t,_a(t)]}function _a(e){return e.replace(/start|end/g,t=>sy[t])}const Yd=["left","right"],Xd=["right","left"],cy=["top","bottom"],uy=["bottom","top"];function dy(e,t,n){switch(e){case"top":case"bottom":return n?t?Xd:Yd:t?Yd:Xd;case"left":case"right":return t?cy:uy;default:return[]}}function fy(e,t,n,r){const o=Nr(e);let s=dy(An(e),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(_a)))),s}function Is(e){return e.replace(/left|right|bottom|top/g,t=>oy[t])}function hy(e){return{top:0,right:0,bottom:0,left:0,...e}}function Jd(e){return typeof e!="number"?hy(e):{top:e,right:e,bottom:e,left:e}}function Ns(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 Zd(e,t,n){let{reference:r,floating:o}=e;const s=yn(t),i=Aa(t),a=Na(i),l=An(t),u=s==="y",d=r.x+r.width/2-o.width/2,f=r.y+r.height/2-o.height/2,h=r[a]/2-o[a]/2;let p;switch(l){case"top":p={x:d,y:r.y-o.height};break;case"bottom":p={x:d,y:r.y+r.height};break;case"right":p={x:r.x+r.width,y:f};break;case"left":p={x:r.x-o.width,y:f};break;default:p={x:r.x,y:r.y}}switch(Nr(t)){case"start":p[i]-=h*(n&&u?-1:1);break;case"end":p[i]+=h*(n&&u?-1:1);break}return p}const py=async(e,t,n)=>{const{placement:r="bottom",strategy:o="absolute",middleware:s=[],platform:i}=n,a=s.filter(Boolean),l=await(i.isRTL==null?void 0:i.isRTL(t));let u=await i.getElementRects({reference:e,floating:t,strategy:o}),{x:d,y:f}=Zd(u,r,l),h=r,p={},w=0;for(let x=0;x<a.length;x++){const{name:g,fn:v}=a[x],{x:b,y:S,data:N,reset:C}=await v({x:d,y:f,initialPlacement:r,placement:h,strategy:o,middlewareData:p,rects:u,platform:i,elements:{reference:e,floating:t}});d=b??d,f=S??f,p={...p,[g]:{...p[g],...N}},C&&w<=50&&(w++,typeof C=="object"&&(C.placement&&(h=C.placement),C.rects&&(u=C.rects===!0?await i.getElementRects({reference:e,floating:t,strategy:o}):C.rects),{x:d,y:f}=Zd(u,h,l)),x=-1)}return{x:d,y:f,placement:h,strategy:o,middlewareData:p}};async function lo(e,t){var n;t===void 0&&(t={});const{x:r,y:o,platform:s,rects:i,elements:a,strategy:l}=e,{boundary:u="clippingAncestors",rootBoundary:d="viewport",elementContext:f="floating",altBoundary:h=!1,padding:p=0}=Nn(t,e),w=Jd(p),g=a[h?f==="floating"?"reference":"floating":f],v=Ns(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(g)))==null||n?g:g.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(a.floating)),boundary:u,rootBoundary:d,strategy:l})),b=f==="floating"?{x:r,y:o,width:i.floating.width,height:i.floating.height}:i.reference,S=await(s.getOffsetParent==null?void 0:s.getOffsetParent(a.floating)),N=await(s.isElement==null?void 0:s.isElement(S))?await(s.getScale==null?void 0:s.getScale(S))||{x:1,y:1}:{x:1,y:1},C=Ns(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:b,offsetParent:S,strategy:l}):b);return{top:(v.top-C.top+w.top)/N.y,bottom:(C.bottom-v.bottom+w.bottom)/N.y,left:(v.left-C.left+w.left)/N.x,right:(C.right-v.right+w.right)/N.x}}const my=e=>({name:"arrow",options:e,async fn(t){const{x:n,y:r,placement:o,rects:s,platform:i,elements:a,middlewareData:l}=t,{element:u,padding:d=0}=Nn(e,t)||{};if(u==null)return{};const f=Jd(d),h={x:n,y:r},p=Aa(o),w=Na(p),x=await i.getDimensions(u),g=p==="y",v=g?"top":"left",b=g?"bottom":"right",S=g?"clientHeight":"clientWidth",N=s.reference[w]+s.reference[p]-h[p]-s.floating[w],C=h[p]-s.reference[p],k=await(i.getOffsetParent==null?void 0:i.getOffsetParent(u));let I=k?k[S]:0;(!I||!await(i.isElement==null?void 0:i.isElement(k)))&&(I=a.floating[S]||s.floating[w]);const A=N/2-C/2,j=I/2-x[w]/2-1,P=zn(f[v],j),L=zn(f[b],j),F=P,V=I-x[w]-L,M=I/2-x[w]/2+A,G=Ea(F,M,V),q=!l.arrow&&Nr(o)!=null&&M!==G&&s.reference[w]/2-(M<F?P:L)-x[w]/2<0,U=q?M<F?M-F:M-V:0;return{[p]:h[p]+U,data:{[p]:G,centerOffset:M-G-U,...q&&{alignmentOffset:U}},reset:q}}}),gy=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(t){var n,r;const{placement:o,middlewareData:s,rects:i,initialPlacement:a,platform:l,elements:u}=t,{mainAxis:d=!0,crossAxis:f=!0,fallbackPlacements:h,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:w="none",flipAlignment:x=!0,...g}=Nn(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const v=An(o),b=yn(a),S=An(a)===a,N=await(l.isRTL==null?void 0:l.isRTL(u.floating)),C=h||(S||!x?[Is(a)]:ly(a)),k=w!=="none";!h&&k&&C.push(...fy(a,x,w,N));const I=[a,...C],A=await lo(t,g),j=[];let P=((r=s.flip)==null?void 0:r.overflows)||[];if(d&&j.push(A[v]),f){const M=ay(o,i,N);j.push(A[M[0]],A[M[1]])}if(P=[...P,{placement:o,overflows:j}],!j.every(M=>M<=0)){var L,F;const M=(((L=s.flip)==null?void 0:L.index)||0)+1,G=I[M];if(G&&(!(f==="alignment"?b!==yn(G):!1)||P.every(B=>yn(B.placement)===b?B.overflows[0]>0:!0)))return{data:{index:M,overflows:P},reset:{placement:G}};let q=(F=P.filter(U=>U.overflows[0]<=0).sort((U,B)=>U.overflows[1]-B.overflows[1])[0])==null?void 0:F.placement;if(!q)switch(p){case"bestFit":{var V;const U=(V=P.filter(B=>{if(k){const $=yn(B.placement);return $===b||$==="y"}return!0}).map(B=>[B.placement,B.overflows.filter($=>$>0).reduce(($,ce)=>$+ce,0)]).sort((B,$)=>B[1]-$[1])[0])==null?void 0:V[0];U&&(q=U);break}case"initialPlacement":q=a;break}if(o!==q)return{reset:{placement:q}}}return{}}}};function Qd(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function ef(e){return ry.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}=Nn(e,t);switch(r){case"referenceHidden":{const s=await lo(t,{...o,elementContext:"reference"}),i=Qd(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:ef(i)}}}case"escaped":{const s=await lo(t,{...o,altBoundary:!0}),i=Qd(s,n.floating);return{data:{escapedOffsets:i,escaped:ef(i)}}}default:return{}}}}},tf=new Set(["left","top"]);async function vy(e,t){const{placement:n,platform:r,elements:o}=e,s=await(r.isRTL==null?void 0:r.isRTL(o.floating)),i=An(n),a=Nr(n),l=yn(n)==="y",u=tf.has(i)?-1:1,d=s&&l?-1:1,f=Nn(t,e);let{mainAxis:h,crossAxis:p,alignmentAxis:w}=typeof f=="number"?{mainAxis:f,crossAxis:0,alignmentAxis:null}:{mainAxis:f.mainAxis||0,crossAxis:f.crossAxis||0,alignmentAxis:f.alignmentAxis};return a&&typeof w=="number"&&(p=a==="end"?w*-1:w),l?{x:p*d,y:h*u}:{x:h*u,y:p*d}}const wy=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 vy(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}}}}},by=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(t){const{x:n,y:r,placement:o}=t,{mainAxis:s=!0,crossAxis:i=!1,limiter:a={fn:g=>{let{x:v,y:b}=g;return{x:v,y:b}}},...l}=Nn(e,t),u={x:n,y:r},d=await lo(t,l),f=yn(An(o)),h=Ia(f);let p=u[h],w=u[f];if(s){const g=h==="y"?"top":"left",v=h==="y"?"bottom":"right",b=p+d[g],S=p-d[v];p=Ea(b,p,S)}if(i){const g=f==="y"?"top":"left",v=f==="y"?"bottom":"right",b=w+d[g],S=w-d[v];w=Ea(b,w,S)}const x=a.fn({...t,[h]:p,[f]:w});return{...x,data:{x:x.x-n,y:x.y-r,enabled:{[h]:s,[f]:i}}}}}},yy=function(e){return e===void 0&&(e={}),{options:e,fn(t){const{x:n,y:r,placement:o,rects:s,middlewareData:i}=t,{offset:a=0,mainAxis:l=!0,crossAxis:u=!0}=Nn(e,t),d={x:n,y:r},f=yn(o),h=Ia(f);let p=d[h],w=d[f];const x=Nn(a,t),g=typeof x=="number"?{mainAxis:x,crossAxis:0}:{mainAxis:0,crossAxis:0,...x};if(l){const S=h==="y"?"height":"width",N=s.reference[h]-s.floating[S]+g.mainAxis,C=s.reference[h]+s.reference[S]-g.mainAxis;p<N?p=N:p>C&&(p=C)}if(u){var v,b;const S=h==="y"?"width":"height",N=tf.has(An(o)),C=s.reference[f]-s.floating[S]+(N&&((v=i.offset)==null?void 0:v[f])||0)+(N?0:g.crossAxis),k=s.reference[f]+s.reference[S]+(N?0:((b=i.offset)==null?void 0:b[f])||0)-(N?g.crossAxis:0);w<C?w=C:w>k&&(w=k)}return{[h]:p,[f]:w}}}},Sy=function(e){return e===void 0&&(e={}),{name:"size",options:e,async fn(t){var n,r;const{placement:o,rects:s,platform:i,elements:a}=t,{apply:l=()=>{},...u}=Nn(e,t),d=await lo(t,u),f=An(o),h=Nr(o),p=yn(o)==="y",{width:w,height:x}=s.floating;let g,v;f==="top"||f==="bottom"?(g=f,v=h===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(v=f,g=h==="end"?"top":"bottom");const b=x-d.top-d.bottom,S=w-d.left-d.right,N=zn(x-d[g],b),C=zn(w-d[v],S),k=!t.middlewareData.shift;let I=N,A=C;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(A=S),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(I=b),k&&!h){const P=zt(d.left,0),L=zt(d.right,0),F=zt(d.top,0),V=zt(d.bottom,0);p?A=w-2*(P!==0||L!==0?P+L:zt(d.left,d.right)):I=x-2*(F!==0||V!==0?F+V:zt(d.top,d.bottom))}await l({...t,availableWidth:A,availableHeight:I});const j=await i.getDimensions(a.floating);return w!==j.width||x!==j.height?{reset:{rects:!0}}:{}}}};function As(){return typeof window<"u"}function Ar(e){return nf(e)?(e.nodeName||"").toLowerCase():"#document"}function Ht(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function Sn(e){var t;return(t=(nf(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function nf(e){return As()?e instanceof Node||e instanceof Ht(e).Node:!1}function ln(e){return As()?e instanceof Element||e instanceof Ht(e).Element:!1}function Cn(e){return As()?e instanceof HTMLElement||e instanceof Ht(e).HTMLElement:!1}function rf(e){return!As()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Ht(e).ShadowRoot}const Cy=new Set(["inline","contents"]);function co(e){const{overflow:t,overflowX:n,overflowY:r,display:o}=cn(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!Cy.has(o)}const Ty=new Set(["table","td","th"]);function ky(e){return Ty.has(Ar(e))}const Ey=[":popover-open",":modal"];function _s(e){return Ey.some(t=>{try{return e.matches(t)}catch{return!1}})}const Iy=["transform","translate","scale","rotate","perspective"],Ny=["transform","translate","scale","rotate","perspective","filter"],Ay=["paint","layout","strict","content"];function ja(e){const t=Ra(),n=ln(e)?cn(e):e;return Iy.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)||Ny.some(r=>(n.willChange||"").includes(r))||Ay.some(r=>(n.contain||"").includes(r))}function _y(e){let t=Hn(e);for(;Cn(t)&&!_r(t);){if(ja(t))return t;if(_s(t))return null;t=Hn(t)}return null}function Ra(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const jy=new Set(["html","body","#document"]);function _r(e){return jy.has(Ar(e))}function cn(e){return Ht(e).getComputedStyle(e)}function js(e){return ln(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Hn(e){if(Ar(e)==="html")return e;const t=e.assignedSlot||e.parentNode||rf(e)&&e.host||Sn(e);return rf(t)?t.host:t}function of(e){const t=Hn(e);return _r(t)?e.ownerDocument?e.ownerDocument.body:e.body:Cn(t)&&co(t)?t:of(t)}function uo(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const o=of(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=Ht(o);if(s){const a=Pa(i);return t.concat(i,i.visualViewport||[],co(o)?o:[],a&&n?uo(a):[])}return t.concat(o,uo(o,[],n))}function Pa(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function sf(e){const t=cn(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const o=Cn(e),s=o?e.offsetWidth:n,i=o?e.offsetHeight:r,a=ks(n)!==s||ks(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function Oa(e){return ln(e)?e:e.contextElement}function jr(e){const t=Oa(e);if(!Cn(t))return bn(1);const n=t.getBoundingClientRect(),{width:r,height:o,$:s}=sf(t);let i=(s?ks(n.width):n.width)/r,a=(s?ks(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const Ry=bn(0);function af(e){const t=Ht(e);return!Ra()||!t.visualViewport?Ry:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function Py(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==Ht(e)?!1:t}function cr(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const o=e.getBoundingClientRect(),s=Oa(e);let i=bn(1);t&&(r?ln(r)&&(i=jr(r)):i=jr(e));const a=Py(s,n,r)?af(s):bn(0);let l=(o.left+a.x)/i.x,u=(o.top+a.y)/i.y,d=o.width/i.x,f=o.height/i.y;if(s){const h=Ht(s),p=r&&ln(r)?Ht(r):r;let w=h,x=Pa(w);for(;x&&r&&p!==w;){const g=jr(x),v=x.getBoundingClientRect(),b=cn(x),S=v.left+(x.clientLeft+parseFloat(b.paddingLeft))*g.x,N=v.top+(x.clientTop+parseFloat(b.paddingTop))*g.y;l*=g.x,u*=g.y,d*=g.x,f*=g.y,l+=S,u+=N,w=Ht(x),x=Pa(w)}}return Ns({width:d,height:f,x:l,y:u})}function Rs(e,t){const n=js(e).scrollLeft;return t?t.left+n:cr(Sn(e)).left+n}function lf(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 Oy(e){let{elements:t,rect:n,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=Sn(r),a=t?_s(t.floating):!1;if(r===i||a&&s)return n;let l={scrollLeft:0,scrollTop:0},u=bn(1);const d=bn(0),f=Cn(r);if((f||!f&&!s)&&((Ar(r)!=="body"||co(i))&&(l=js(r)),Cn(r))){const p=cr(r);u=jr(r),d.x=p.x+r.clientLeft,d.y=p.y+r.clientTop}const h=i&&!f&&!s?lf(i,l):bn(0);return{width:n.width*u.x,height:n.height*u.y,x:n.x*u.x-l.scrollLeft*u.x+d.x+h.x,y:n.y*u.y-l.scrollTop*u.y+d.y+h.y}}function My(e){return Array.from(e.getClientRects())}function Dy(e){const t=Sn(e),n=js(e),r=e.ownerDocument.body,o=zt(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=zt(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let i=-n.scrollLeft+Rs(e);const a=-n.scrollTop;return cn(r).direction==="rtl"&&(i+=zt(t.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}const cf=25;function Ly(e,t){const n=Ht(e),r=Sn(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=Ra();(!d||d&&t==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}const u=Rs(r);if(u<=0){const d=r.ownerDocument,f=d.body,h=getComputedStyle(f),p=d.compatMode==="CSS1Compat"&&parseFloat(h.marginLeft)+parseFloat(h.marginRight)||0,w=Math.abs(r.clientWidth-f.clientWidth-p);w<=cf&&(s-=w)}else u<=cf&&(s+=u);return{width:s,height:i,x:a,y:l}}const Fy=new Set(["absolute","fixed"]);function $y(e,t){const n=cr(e,!0,t==="fixed"),r=n.top+e.clientTop,o=n.left+e.clientLeft,s=Cn(e)?jr(e):bn(1),i=e.clientWidth*s.x,a=e.clientHeight*s.y,l=o*s.x,u=r*s.y;return{width:i,height:a,x:l,y:u}}function uf(e,t,n){let r;if(t==="viewport")r=Ly(e,n);else if(t==="document")r=Dy(Sn(e));else if(ln(t))r=$y(t,n);else{const o=af(e);r={x:t.x-o.x,y:t.y-o.y,width:t.width,height:t.height}}return Ns(r)}function df(e,t){const n=Hn(e);return n===t||!ln(n)||_r(n)?!1:cn(n).position==="fixed"||df(n,t)}function By(e,t){const n=t.get(e);if(n)return n;let r=uo(e,[],!1).filter(a=>ln(a)&&Ar(a)!=="body"),o=null;const s=cn(e).position==="fixed";let i=s?Hn(e):e;for(;ln(i)&&!_r(i);){const a=cn(i),l=ja(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&Fy.has(o.position)||co(i)&&!l&&df(e,i))?r=r.filter(d=>d!==i):o=a,i=Hn(i)}return t.set(e,r),r}function zy(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i=[...n==="clippingAncestors"?_s(t)?[]:By(t,this._c):[].concat(n),r],a=i[0],l=i.reduce((u,d)=>{const f=uf(t,d,o);return u.top=zt(f.top,u.top),u.right=zn(f.right,u.right),u.bottom=zn(f.bottom,u.bottom),u.left=zt(f.left,u.left),u},uf(t,a,o));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function Hy(e){const{width:t,height:n}=sf(e);return{width:t,height:n}}function Uy(e,t,n){const r=Cn(t),o=Sn(t),s=n==="fixed",i=cr(e,!0,s,t);let a={scrollLeft:0,scrollTop:0};const l=bn(0);function u(){l.x=Rs(o)}if(r||!r&&!s)if((Ar(t)!=="body"||co(o))&&(a=js(t)),r){const p=cr(t,!0,s,t);l.x=p.x+t.clientLeft,l.y=p.y+t.clientTop}else o&&u();s&&!r&&o&&u();const d=o&&!r&&!s?lf(o,a):bn(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 Ma(e){return cn(e).position==="static"}function ff(e,t){if(!Cn(e)||cn(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return Sn(e)===n&&(n=n.ownerDocument.body),n}function hf(e,t){const n=Ht(e);if(_s(e))return n;if(!Cn(e)){let o=Hn(e);for(;o&&!_r(o);){if(ln(o)&&!Ma(o))return o;o=Hn(o)}return n}let r=ff(e,t);for(;r&&ky(r)&&Ma(r);)r=ff(r,t);return r&&_r(r)&&Ma(r)&&!ja(r)?n:r||_y(e)||n}const Wy=async function(e){const t=this.getOffsetParent||hf,n=this.getDimensions,r=await n(e.floating);return{reference:Uy(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function Vy(e){return cn(e).direction==="rtl"}const qy={convertOffsetParentRelativeRectToViewportRelativeRect:Oy,getDocumentElement:Sn,getClippingRect:zy,getOffsetParent:hf,getElementRects:Wy,getClientRects:My,getDimensions:Hy,getScale:jr,isElement:ln,isRTL:Vy};function pf(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function Ky(e,t){let n=null,r;const o=Sn(e);function s(){var a;clearTimeout(r),(a=n)==null||a.disconnect(),n=null}function i(a,l){a===void 0&&(a=!1),l===void 0&&(l=1),s();const u=e.getBoundingClientRect(),{left:d,top:f,width:h,height:p}=u;if(a||t(),!h||!p)return;const w=Es(f),x=Es(o.clientWidth-(d+h)),g=Es(o.clientHeight-(f+p)),v=Es(d),S={rootMargin:-w+"px "+-x+"px "+-g+"px "+-v+"px",threshold:zt(0,zn(1,l))||1};let N=!0;function C(k){const I=k[0].intersectionRatio;if(I!==l){if(!N)return i();I?i(!1,I):r=setTimeout(()=>{i(!1,1e-7)},1e3)}I===1&&!pf(u,e.getBoundingClientRect())&&i(),N=!1}try{n=new IntersectionObserver(C,{...S,root:o.ownerDocument})}catch{n=new IntersectionObserver(C,S)}n.observe(e)}return i(!0),s}function Gy(e,t,n,r){r===void 0&&(r={});const{ancestorScroll:o=!0,ancestorResize:s=!0,elementResize:i=typeof ResizeObserver=="function",layoutShift:a=typeof IntersectionObserver=="function",animationFrame:l=!1}=r,u=Oa(e),d=o||s?[...u?uo(u):[],...uo(t)]:[];d.forEach(v=>{o&&v.addEventListener("scroll",n,{passive:!0}),s&&v.addEventListener("resize",n)});const f=u&&a?Ky(u,n):null;let h=-1,p=null;i&&(p=new ResizeObserver(v=>{let[b]=v;b&&b.target===u&&p&&(p.unobserve(t),cancelAnimationFrame(h),h=requestAnimationFrame(()=>{var S;(S=p)==null||S.observe(t)})),n()}),u&&!l&&p.observe(u),p.observe(t));let w,x=l?cr(e):null;l&&g();function g(){const v=cr(e);x&&!pf(x,v)&&n(),x=v,w=requestAnimationFrame(g)}return n(),()=>{var v;d.forEach(b=>{o&&b.removeEventListener("scroll",n),s&&b.removeEventListener("resize",n)}),f==null||f(),(v=p)==null||v.disconnect(),p=null,l&&cancelAnimationFrame(w)}}const Yy=wy,Xy=by,Jy=gy,Zy=Sy,Qy=xy,mf=my,e0=yy,t0=(e,t,n)=>{const r=new Map,o={platform:qy,...n},s={...o.platform,_c:r};return py(e,t,{...o,platform:s})};var n0=typeof document<"u",r0=function(){},Ps=n0?y.useLayoutEffect:r0;function Os(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(!Os(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)&&!Os(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function gf(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function xf(e,t){const n=gf(e);return Math.round(t*n)/n}function Da(e){const t=m.useRef(e);return Ps(()=>{t.current=e}),t}function o0(e){e===void 0&&(e={});const{placement:t="bottom",strategy:n="absolute",middleware:r=[],platform:o,elements:{reference:s,floating:i}={},transform:a=!0,whileElementsMounted:l,open:u}=e,[d,f]=m.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[h,p]=m.useState(r);Os(h,r)||p(r);const[w,x]=m.useState(null),[g,v]=m.useState(null),b=m.useCallback(B=>{B!==k.current&&(k.current=B,x(B))},[]),S=m.useCallback(B=>{B!==I.current&&(I.current=B,v(B))},[]),N=s||w,C=i||g,k=m.useRef(null),I=m.useRef(null),A=m.useRef(d),j=l!=null,P=Da(l),L=Da(o),F=Da(u),V=m.useCallback(()=>{if(!k.current||!I.current)return;const B={placement:t,strategy:n,middleware:h};L.current&&(B.platform=L.current),t0(k.current,I.current,B).then($=>{const ce={...$,isPositioned:F.current!==!1};M.current&&!Os(A.current,ce)&&(A.current=ce,yo.flushSync(()=>{f(ce)}))})},[h,t,n,L,F]);Ps(()=>{u===!1&&A.current.isPositioned&&(A.current.isPositioned=!1,f(B=>({...B,isPositioned:!1})))},[u]);const M=m.useRef(!1);Ps(()=>(M.current=!0,()=>{M.current=!1}),[]),Ps(()=>{if(N&&(k.current=N),C&&(I.current=C),N&&C){if(P.current)return P.current(N,C,V);V()}},[N,C,V,P,j]);const G=m.useMemo(()=>({reference:k,floating:I,setReference:b,setFloating:S}),[b,S]),q=m.useMemo(()=>({reference:N,floating:C}),[N,C]),U=m.useMemo(()=>{const B={position:n,left:0,top:0};if(!q.floating)return B;const $=xf(q.floating,d.x),ce=xf(q.floating,d.y);return a?{...B,transform:"translate("+$+"px, "+ce+"px)",...gf(q.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:$,top:ce}},[n,a,q.floating,d.x,d.y]);return m.useMemo(()=>({...d,update:V,refs:G,elements:q,floatingStyles:U}),[d,V,G,q,U])}const s0=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?mf({element:r.current,padding:o}).fn(n):{}:r?mf({element:r,padding:o}).fn(n):{}}}},i0=(e,t)=>({...Yy(e),options:[e,t]}),a0=(e,t)=>({...Xy(e),options:[e,t]}),l0=(e,t)=>({...e0(e),options:[e,t]}),c0=(e,t)=>({...Jy(e),options:[e,t]}),u0=(e,t)=>({...Zy(e),options:[e,t]}),d0=(e,t)=>({...Qy(e),options:[e,t]}),f0=(e,t)=>({...s0(e),options:[e,t]});var h0="Arrow",vf=m.forwardRef((e,t)=>{const{children:n,width:r=10,height:o=5,...s}=e;return c.jsx(_e.svg,{...s,ref:t,width:r,height:o,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:e.asChild?n:c.jsx("polygon",{points:"0,0 30,0 15,10"})})});vf.displayName=h0;var p0=vf;function wf(e){const[t,n]=m.useState(void 0);return Ct(()=>{if(e){n({width:e.offsetWidth,height:e.offsetHeight});const r=new ResizeObserver(o=>{if(!Array.isArray(o)||!o.length)return;const s=o[0];let i,a;if("borderBoxSize"in s){const l=s.borderBoxSize,u=Array.isArray(l)?l[0]:l;i=u.inlineSize,a=u.blockSize}else i=e.offsetWidth,a=e.offsetHeight;n({width:i,height:a})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else n(void 0)},[e]),t}var La="Popper",[bf,Ms]=xn(La),[m0,yf]=bf(La),Sf=e=>{const{__scopePopper:t,children:n}=e,[r,o]=m.useState(null);return c.jsx(m0,{scope:t,anchor:r,onAnchorChange:o,children:n})};Sf.displayName=La;var Cf="PopperAnchor",Tf=m.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...o}=e,s=yf(Cf,n),i=m.useRef(null),a=Ve(t,i),l=m.useRef(null);return m.useEffect(()=>{const u=l.current;l.current=(r==null?void 0:r.current)||i.current,u!==l.current&&s.onAnchorChange(l.current)}),r?null:c.jsx(_e.div,{...o,ref:a})});Tf.displayName=Cf;var Fa="PopperContent",[g0,x0]=bf(Fa),kf=m.forwardRef((e,t)=>{var K,O,X,ee,fe,ne;const{__scopePopper:n,side:r="bottom",sideOffset:o=0,align:s="center",alignOffset:i=0,arrowPadding:a=0,avoidCollisions:l=!0,collisionBoundary:u=[],collisionPadding:d=0,sticky:f="partial",hideWhenDetached:h=!1,updatePositionStrategy:p="optimized",onPlaced:w,...x}=e,g=yf(Fa,n),[v,b]=m.useState(null),S=Ve(t,pe=>b(pe)),[N,C]=m.useState(null),k=wf(N),I=(k==null?void 0:k.width)??0,A=(k==null?void 0:k.height)??0,j=r+(s!=="center"?"-"+s:""),P=typeof d=="number"?d:{top:0,right:0,bottom:0,left:0,...d},L=Array.isArray(u)?u:[u],F=L.length>0,V={padding:P,boundary:L.filter(w0),altBoundary:F},{refs:M,floatingStyles:G,placement:q,isPositioned:U,middlewareData:B}=o0({strategy:"fixed",placement:j,whileElementsMounted:(...pe)=>Gy(...pe,{animationFrame:p==="always"}),elements:{reference:g.anchor},middleware:[i0({mainAxis:o+A,alignmentAxis:i}),l&&a0({mainAxis:!0,crossAxis:!1,limiter:f==="partial"?l0():void 0,...V}),l&&c0({...V}),u0({...V,apply:({elements:pe,rects:Ze,availableWidth:Qe,availableHeight:Pe})=>{const{width:He,height:ct}=Ze.reference,tt=pe.floating.style;tt.setProperty("--radix-popper-available-width",`${Qe}px`),tt.setProperty("--radix-popper-available-height",`${Pe}px`),tt.setProperty("--radix-popper-anchor-width",`${He}px`),tt.setProperty("--radix-popper-anchor-height",`${ct}px`)}}),N&&f0({element:N,padding:a}),b0({arrowWidth:I,arrowHeight:A}),h&&d0({strategy:"referenceHidden",...V})]}),[$,ce]=Nf(q),D=Tt(w);Ct(()=>{U&&(D==null||D())},[U,D]);const Q=(K=B.arrow)==null?void 0:K.x,de=(O=B.arrow)==null?void 0:O.y,we=((X=B.arrow)==null?void 0:X.centerOffset)!==0,[ye,Se]=m.useState();return Ct(()=>{v&&Se(window.getComputedStyle(v).zIndex)},[v]),c.jsx("div",{ref:M.setFloating,"data-radix-popper-content-wrapper":"",style:{...G,transform:U?G.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:ye,"--radix-popper-transform-origin":[(ee=B.transformOrigin)==null?void 0:ee.x,(fe=B.transformOrigin)==null?void 0:fe.y].join(" "),...((ne=B.hide)==null?void 0:ne.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:c.jsx(g0,{scope:n,placedSide:$,onArrowChange:C,arrowX:Q,arrowY:de,shouldHideArrow:we,children:c.jsx(_e.div,{"data-side":$,"data-align":ce,...x,ref:S,style:{...x.style,animation:U?void 0:"none"}})})})});kf.displayName=Fa;var Ef="PopperArrow",v0={top:"bottom",right:"left",bottom:"top",left:"right"},If=m.forwardRef(function(t,n){const{__scopePopper:r,...o}=t,s=x0(Ef,r),i=v0[s.placedSide];return c.jsx("span",{ref:s.onArrowChange,style:{position:"absolute",left:s.arrowX,top:s.arrowY,[i]:0,transformOrigin:{top:"",right:"0 0",bottom:"center 0",left:"100% 0"}[s.placedSide],transform:{top:"translateY(100%)",right:"translateY(50%) rotate(90deg) translateX(-50%)",bottom:"rotate(180deg)",left:"translateY(50%) rotate(-90deg) translateX(50%)"}[s.placedSide],visibility:s.shouldHideArrow?"hidden":void 0},children:c.jsx(p0,{...o,ref:n,style:{...o.style,display:"block"}})})});If.displayName=Ef;function w0(e){return e!==null}var b0=e=>({name:"transformOrigin",options:e,fn(t){var g,v,b;const{placement:n,rects:r,middlewareData:o}=t,i=((g=o.arrow)==null?void 0:g.centerOffset)!==0,a=i?0:e.arrowWidth,l=i?0:e.arrowHeight,[u,d]=Nf(n),f={start:"0%",center:"50%",end:"100%"}[d],h=(((v=o.arrow)==null?void 0:v.x)??0)+a/2,p=(((b=o.arrow)==null?void 0:b.y)??0)+l/2;let w="",x="";return u==="bottom"?(w=i?f:`${h}px`,x=`${-l}px`):u==="top"?(w=i?f:`${h}px`,x=`${r.floating.height+l}px`):u==="right"?(w=`${-l}px`,x=i?f:`${p}px`):u==="left"&&(w=`${r.floating.width+l}px`,x=i?f:`${p}px`),{data:{x:w,y:x}}}});function Nf(e){const[t,n="center"]=e.split("-");return[t,n]}var Af=Sf,_f=Tf,jf=kf,Rf=If,$a="rovingFocusGroup.onEntryFocus",y0={bubbles:!1,cancelable:!0},fo="RovingFocusGroup",[Ba,Pf,S0]=ka(fo),[C0,Of]=xn(fo,[S0]),[T0,k0]=C0(fo),Mf=m.forwardRef((e,t)=>c.jsx(Ba.Provider,{scope:e.__scopeRovingFocusGroup,children:c.jsx(Ba.Slot,{scope:e.__scopeRovingFocusGroup,children:c.jsx(E0,{...e,ref:t})})}));Mf.displayName=fo;var E0=m.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:o=!1,dir:s,currentTabStopId:i,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:l,onEntryFocus:u,preventScrollOnEntryFocus:d=!1,...f}=e,h=m.useRef(null),p=Ve(t,h),w=Ts(s),[x,g]=or({prop:i,defaultProp:a??null,onChange:l,caller:fo}),[v,b]=m.useState(!1),S=Tt(u),N=Pf(n),C=m.useRef(!1),[k,I]=m.useState(0);return m.useEffect(()=>{const A=h.current;if(A)return A.addEventListener($a,S),()=>A.removeEventListener($a,S)},[S]),c.jsx(T0,{scope:n,orientation:r,dir:w,loop:o,currentTabStopId:x,onItemFocus:m.useCallback(A=>g(A),[g]),onItemShiftTab:m.useCallback(()=>b(!0),[]),onFocusableItemAdd:m.useCallback(()=>I(A=>A+1),[]),onFocusableItemRemove:m.useCallback(()=>I(A=>A-1),[]),children:c.jsx(_e.div,{tabIndex:v||k===0?-1:0,"data-orientation":r,...f,ref:p,style:{outline:"none",...e.style},onMouseDown:ue(e.onMouseDown,()=>{C.current=!0}),onFocus:ue(e.onFocus,A=>{const j=!C.current;if(A.target===A.currentTarget&&j&&!v){const P=new CustomEvent($a,y0);if(A.currentTarget.dispatchEvent(P),!P.defaultPrevented){const L=N().filter(q=>q.focusable),F=L.find(q=>q.active),V=L.find(q=>q.id===x),G=[F,V,...L].filter(Boolean).map(q=>q.ref.current);Ff(G,d)}}C.current=!1}),onBlur:ue(e.onBlur,()=>b(!1))})})}),Df="RovingFocusGroupItem",Lf=m.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:o=!1,tabStopId:s,children:i,...a}=e,l=vn(),u=s||l,d=k0(Df,n),f=d.currentTabStopId===u,h=Pf(n),{onFocusableItemAdd:p,onFocusableItemRemove:w,currentTabStopId:x}=d;return m.useEffect(()=>{if(r)return p(),()=>w()},[r,p,w]),c.jsx(Ba.ItemSlot,{scope:n,id:u,focusable:r,active:o,children:c.jsx(_e.span,{tabIndex:f?0:-1,"data-orientation":d.orientation,...a,ref:t,onMouseDown:ue(e.onMouseDown,g=>{r?d.onItemFocus(u):g.preventDefault()}),onFocus:ue(e.onFocus,()=>d.onItemFocus(u)),onKeyDown:ue(e.onKeyDown,g=>{if(g.key==="Tab"&&g.shiftKey){d.onItemShiftTab();return}if(g.target!==g.currentTarget)return;const v=A0(g,d.orientation,d.dir);if(v!==void 0){if(g.metaKey||g.ctrlKey||g.altKey||g.shiftKey)return;g.preventDefault();let S=h().filter(N=>N.focusable).map(N=>N.ref.current);if(v==="last")S.reverse();else if(v==="prev"||v==="next"){v==="prev"&&S.reverse();const N=S.indexOf(g.currentTarget);S=d.loop?_0(S,N+1):S.slice(N+1)}setTimeout(()=>Ff(S))}}),children:typeof i=="function"?i({isCurrentTabStop:f,hasTabStop:x!=null}):i})})});Lf.displayName=Df;var I0={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function N0(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function A0(e,t,n){const r=N0(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return I0[r]}function Ff(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function _0(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var j0=Mf,R0=Lf,za=["Enter"," "],P0=["ArrowDown","PageUp","Home"],$f=["ArrowUp","PageDown","End"],O0=[...P0,...$f],M0={ltr:[...za,"ArrowRight"],rtl:[...za,"ArrowLeft"]},D0={ltr:["ArrowLeft"],rtl:["ArrowRight"]},ho="Menu",[po,L0,F0]=ka(ho),[ur,Bf]=xn(ho,[F0,Ms,Of]),Ds=Ms(),zf=Of(),[$0,dr]=ur(ho),[B0,mo]=ur(ho),Hf=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=Ds(t),[l,u]=m.useState(null),d=m.useRef(!1),f=Tt(s),h=Ts(o);return m.useEffect(()=>{const p=()=>{d.current=!0,document.addEventListener("pointerdown",w,{capture:!0,once:!0}),document.addEventListener("pointermove",w,{capture:!0,once:!0})},w=()=>d.current=!1;return document.addEventListener("keydown",p,{capture:!0}),()=>{document.removeEventListener("keydown",p,{capture:!0}),document.removeEventListener("pointerdown",w,{capture:!0}),document.removeEventListener("pointermove",w,{capture:!0})}},[]),c.jsx(Af,{...a,children:c.jsx($0,{scope:t,open:n,onOpenChange:f,content:l,onContentChange:u,children:c.jsx(B0,{scope:t,onClose:m.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:d,dir:h,modal:i,children:r})})})};Hf.displayName=ho;var z0="MenuAnchor",Ha=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=Ds(n);return c.jsx(_f,{...o,...r,ref:t})});Ha.displayName=z0;var Ua="MenuPortal",[H0,Uf]=ur(Ua,{forceMount:void 0}),Wf=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:o}=e,s=dr(Ua,t);return c.jsx(H0,{scope:t,forceMount:n,children:c.jsx(Bt,{present:n||s.open,children:c.jsx(ls,{asChild:!0,container:o,children:r})})})};Wf.displayName=Ua;var Yt="MenuContent",[U0,Wa]=ur(Yt),Vf=m.forwardRef((e,t)=>{const n=Uf(Yt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=dr(Yt,e.__scopeMenu),i=mo(Yt,e.__scopeMenu);return c.jsx(po.Provider,{scope:e.__scopeMenu,children:c.jsx(Bt,{present:r||s.open,children:c.jsx(po.Slot,{scope:e.__scopeMenu,children:i.modal?c.jsx(W0,{...o,ref:t}):c.jsx(V0,{...o,ref:t})})})})}),W0=m.forwardRef((e,t)=>{const n=dr(Yt,e.__scopeMenu),r=m.useRef(null),o=Ve(t,r);return m.useEffect(()=>{const s=r.current;if(s)return wa(s)},[]),c.jsx(Va,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:ue(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),V0=m.forwardRef((e,t)=>{const n=dr(Yt,e.__scopeMenu);return c.jsx(Va,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),q0=Xn.createSlot("MenuContent.ScrollLock"),Va=m.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:o,onOpenAutoFocus:s,onCloseAutoFocus:i,disableOutsidePointerEvents:a,onEntryFocus:l,onEscapeKeyDown:u,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:h,onDismiss:p,disableOutsideScroll:w,...x}=e,g=dr(Yt,n),v=mo(Yt,n),b=Ds(n),S=zf(n),N=L0(n),[C,k]=m.useState(null),I=m.useRef(null),A=Ve(t,I,g.onContentChange),j=m.useRef(0),P=m.useRef(""),L=m.useRef(0),F=m.useRef(null),V=m.useRef("right"),M=m.useRef(0),G=w?ps:m.Fragment,q=w?{as:q0,allowPinchZoom:!0}:void 0,U=$=>{var K,O;const ce=P.current+$,D=N().filter(X=>!X.disabled),Q=document.activeElement,de=(K=D.find(X=>X.ref.current===Q))==null?void 0:K.textValue,we=D.map(X=>X.textValue),ye=oS(we,ce,de),Se=(O=D.find(X=>X.textValue===ye))==null?void 0:O.ref.current;(function X(ee){P.current=ee,window.clearTimeout(j.current),ee!==""&&(j.current=window.setTimeout(()=>X(""),1e3))})(ce),Se&&setTimeout(()=>Se.focus())};m.useEffect(()=>()=>window.clearTimeout(j.current),[]),ha();const B=m.useCallback($=>{var D,Q;return V.current===((D=F.current)==null?void 0:D.side)&&iS($,(Q=F.current)==null?void 0:Q.area)},[]);return c.jsx(U0,{scope:n,searchRef:P,onItemEnter:m.useCallback($=>{B($)&&$.preventDefault()},[B]),onItemLeave:m.useCallback($=>{var ce;B($)||((ce=I.current)==null||ce.focus(),k(null))},[B]),onTriggerLeave:m.useCallback($=>{B($)&&$.preventDefault()},[B]),pointerGraceTimerRef:L,onPointerGraceIntentChange:m.useCallback($=>{F.current=$},[]),children:c.jsx(G,{...q,children:c.jsx(as,{asChild:!0,trapped:o,onMountAutoFocus:ue(s,$=>{var ce;$.preventDefault(),(ce=I.current)==null||ce.focus({preventScroll:!0})}),onUnmountAutoFocus:i,children:c.jsx(is,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:u,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:h,onDismiss:p,children:c.jsx(j0,{asChild:!0,...S,dir:v.dir,orientation:"vertical",loop:r,currentTabStopId:C,onCurrentTabStopIdChange:k,onEntryFocus:ue(l,$=>{v.isUsingKeyboardRef.current||$.preventDefault()}),preventScrollOnEntryFocus:!0,children:c.jsx(jf,{role:"menu","aria-orientation":"vertical","data-state":lh(g.open),"data-radix-menu-content":"",dir:v.dir,...b,...x,ref:A,style:{outline:"none",...x.style},onKeyDown:ue(x.onKeyDown,$=>{const D=$.target.closest("[data-radix-menu-content]")===$.currentTarget,Q=$.ctrlKey||$.altKey||$.metaKey,de=$.key.length===1;D&&($.key==="Tab"&&$.preventDefault(),!Q&&de&&U($.key));const we=I.current;if($.target!==we||!O0.includes($.key))return;$.preventDefault();const Se=N().filter(K=>!K.disabled).map(K=>K.ref.current);$f.includes($.key)&&Se.reverse(),nS(Se)}),onBlur:ue(e.onBlur,$=>{$.currentTarget.contains($.target)||(window.clearTimeout(j.current),P.current="")}),onPointerMove:ue(e.onPointerMove,xo($=>{const ce=$.target,D=M.current!==$.clientX;if($.currentTarget.contains(ce)&&D){const Q=$.clientX>M.current?"right":"left";V.current=Q,M.current=$.clientX}}))})})})})})})});Vf.displayName=Yt;var K0="MenuGroup",qa=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return c.jsx(_e.div,{role:"group",...r,ref:t})});qa.displayName=K0;var G0="MenuLabel",qf=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return c.jsx(_e.div,{...r,ref:t})});qf.displayName=G0;var Ls="MenuItem",Kf="menu.itemSelect",Fs=m.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...o}=e,s=m.useRef(null),i=mo(Ls,e.__scopeMenu),a=Wa(Ls,e.__scopeMenu),l=Ve(t,s),u=m.useRef(!1),d=()=>{const f=s.current;if(!n&&f){const h=new CustomEvent(Kf,{bubbles:!0,cancelable:!0});f.addEventListener(Kf,p=>r==null?void 0:r(p),{once:!0}),Iu(f,h),h.defaultPrevented?u.current=!1:i.onClose()}};return c.jsx(Gf,{...o,ref:l,disabled:n,onClick:ue(e.onClick,d),onPointerDown:f=>{var h;(h=e.onPointerDown)==null||h.call(e,f),u.current=!0},onPointerUp:ue(e.onPointerUp,f=>{var h;u.current||(h=f.currentTarget)==null||h.click()}),onKeyDown:ue(e.onKeyDown,f=>{const h=a.searchRef.current!=="";n||h&&f.key===" "||za.includes(f.key)&&(f.currentTarget.click(),f.preventDefault())})})});Fs.displayName=Ls;var Gf=m.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:o,...s}=e,i=Wa(Ls,n),a=zf(n),l=m.useRef(null),u=Ve(t,l),[d,f]=m.useState(!1),[h,p]=m.useState("");return m.useEffect(()=>{const w=l.current;w&&p((w.textContent??"").trim())},[s.children]),c.jsx(po.ItemSlot,{scope:n,disabled:r,textValue:o??h,children:c.jsx(R0,{asChild:!0,...a,focusable:!r,children:c.jsx(_e.div,{role:"menuitem","data-highlighted":d?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:u,onPointerMove:ue(e.onPointerMove,xo(w=>{r?i.onItemLeave(w):(i.onItemEnter(w),w.defaultPrevented||w.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:ue(e.onPointerLeave,xo(w=>i.onItemLeave(w))),onFocus:ue(e.onFocus,()=>f(!0)),onBlur:ue(e.onBlur,()=>f(!1))})})})}),Y0="MenuCheckboxItem",Yf=m.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...o}=e;return c.jsx(eh,{scope:e.__scopeMenu,checked:n,children:c.jsx(Fs,{role:"menuitemcheckbox","aria-checked":$s(n)?"mixed":n,...o,ref:t,"data-state":Ga(n),onSelect:ue(o.onSelect,()=>r==null?void 0:r($s(n)?!0:!n),{checkForDefaultPrevented:!1})})})});Yf.displayName=Y0;var Xf="MenuRadioGroup",[X0,J0]=ur(Xf,{value:void 0,onValueChange:()=>{}}),Jf=m.forwardRef((e,t)=>{const{value:n,onValueChange:r,...o}=e,s=Tt(r);return c.jsx(X0,{scope:e.__scopeMenu,value:n,onValueChange:s,children:c.jsx(qa,{...o,ref:t})})});Jf.displayName=Xf;var Zf="MenuRadioItem",Qf=m.forwardRef((e,t)=>{const{value:n,...r}=e,o=J0(Zf,e.__scopeMenu),s=n===o.value;return c.jsx(eh,{scope:e.__scopeMenu,checked:s,children:c.jsx(Fs,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":Ga(s),onSelect:ue(r.onSelect,()=>{var i;return(i=o.onValueChange)==null?void 0:i.call(o,n)},{checkForDefaultPrevented:!1})})})});Qf.displayName=Zf;var Ka="MenuItemIndicator",[eh,Z0]=ur(Ka,{checked:!1}),th=m.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...o}=e,s=Z0(Ka,n);return c.jsx(Bt,{present:r||$s(s.checked)||s.checked===!0,children:c.jsx(_e.span,{...o,ref:t,"data-state":Ga(s.checked)})})});th.displayName=Ka;var Q0="MenuSeparator",nh=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return c.jsx(_e.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});nh.displayName=Q0;var eS="MenuArrow",rh=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=Ds(n);return c.jsx(Rf,{...o,...r,ref:t})});rh.displayName=eS;var tS="MenuSub",[LT,oh]=ur(tS),go="MenuSubTrigger",sh=m.forwardRef((e,t)=>{const n=dr(go,e.__scopeMenu),r=mo(go,e.__scopeMenu),o=oh(go,e.__scopeMenu),s=Wa(go,e.__scopeMenu),i=m.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:l}=s,u={__scopeMenu:e.__scopeMenu},d=m.useCallback(()=>{i.current&&window.clearTimeout(i.current),i.current=null},[]);return m.useEffect(()=>d,[d]),m.useEffect(()=>{const f=a.current;return()=>{window.clearTimeout(f),l(null)}},[a,l]),c.jsx(Ha,{asChild:!0,...u,children:c.jsx(Gf,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":o.contentId,"data-state":lh(n.open),...e,ref:Qi(t,o.onTriggerChange),onClick:f=>{var h;(h=e.onClick)==null||h.call(e,f),!(e.disabled||f.defaultPrevented)&&(f.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:ue(e.onPointerMove,xo(f=>{s.onItemEnter(f),!f.defaultPrevented&&!e.disabled&&!n.open&&!i.current&&(s.onPointerGraceIntentChange(null),i.current=window.setTimeout(()=>{n.onOpenChange(!0),d()},100))})),onPointerLeave:ue(e.onPointerLeave,xo(f=>{var p,w;d();const h=(p=n.content)==null?void 0:p.getBoundingClientRect();if(h){const x=(w=n.content)==null?void 0:w.dataset.side,g=x==="right",v=g?-5:5,b=h[g?"left":"right"],S=h[g?"right":"left"];s.onPointerGraceIntentChange({area:[{x:f.clientX+v,y:f.clientY},{x:b,y:h.top},{x:S,y:h.top},{x:S,y:h.bottom},{x:b,y:h.bottom}],side:x}),window.clearTimeout(a.current),a.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(f),f.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:ue(e.onKeyDown,f=>{var p;const h=s.searchRef.current!=="";e.disabled||h&&f.key===" "||M0[r.dir].includes(f.key)&&(n.onOpenChange(!0),(p=n.content)==null||p.focus(),f.preventDefault())})})})});sh.displayName=go;var ih="MenuSubContent",ah=m.forwardRef((e,t)=>{const n=Uf(Yt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=dr(Yt,e.__scopeMenu),i=mo(Yt,e.__scopeMenu),a=oh(ih,e.__scopeMenu),l=m.useRef(null),u=Ve(t,l);return c.jsx(po.Provider,{scope:e.__scopeMenu,children:c.jsx(Bt,{present:r||s.open,children:c.jsx(po.Slot,{scope:e.__scopeMenu,children:c.jsx(Va,{id:a.contentId,"aria-labelledby":a.triggerId,...o,ref:u,align:"start",side:i.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:d=>{var f;i.isUsingKeyboardRef.current&&((f=l.current)==null||f.focus()),d.preventDefault()},onCloseAutoFocus:d=>d.preventDefault(),onFocusOutside:ue(e.onFocusOutside,d=>{d.target!==a.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:ue(e.onEscapeKeyDown,d=>{i.onClose(),d.preventDefault()}),onKeyDown:ue(e.onKeyDown,d=>{var p;const f=d.currentTarget.contains(d.target),h=D0[i.dir].includes(d.key);f&&h&&(s.onOpenChange(!1),(p=a.trigger)==null||p.focus(),d.preventDefault())})})})})})});ah.displayName=ih;function lh(e){return e?"open":"closed"}function $s(e){return e==="indeterminate"}function Ga(e){return $s(e)?"indeterminate":e?"checked":"unchecked"}function nS(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function rS(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function oS(e,t,n){const o=t.length>1&&Array.from(t).every(u=>u===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let i=rS(e,Math.max(s,0));o.length===1&&(i=i.filter(u=>u!==n));const l=i.find(u=>u.toLowerCase().startsWith(o.toLowerCase()));return l!==n?l:void 0}function sS(e,t){const{x:n,y:r}=e;let o=!1;for(let s=0,i=t.length-1;s<t.length;i=s++){const a=t[s],l=t[i],u=a.x,d=a.y,f=l.x,h=l.y;d>r!=h>r&&n<(f-u)*(r-d)/(h-d)+u&&(o=!o)}return o}function iS(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return sS(n,t)}function xo(e){return t=>t.pointerType==="mouse"?e(t):void 0}var aS=Hf,lS=Ha,cS=Wf,uS=Vf,dS=qa,fS=qf,hS=Fs,pS=Yf,mS=Jf,gS=Qf,xS=th,vS=nh,wS=rh,bS=sh,yS=ah,Bs="DropdownMenu",[SS,FT]=xn(Bs,[Bf]),jt=Bf(),[CS,ch]=SS(Bs),uh=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:o,defaultOpen:s,onOpenChange:i,modal:a=!0}=e,l=jt(t),u=m.useRef(null),[d,f]=or({prop:o,defaultProp:s??!1,onChange:i,caller:Bs});return c.jsx(CS,{scope:t,triggerId:vn(),triggerRef:u,contentId:vn(),open:d,onOpenChange:f,onOpenToggle:m.useCallback(()=>f(h=>!h),[f]),modal:a,children:c.jsx(aS,{...l,open:d,onOpenChange:f,dir:r,modal:a,children:n})})};uh.displayName=Bs;var dh="DropdownMenuTrigger",fh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...o}=e,s=ch(dh,n),i=jt(n);return c.jsx(lS,{asChild:!0,...i,children:c.jsx(_e.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:Qi(t,s.triggerRef),onPointerDown:ue(e.onPointerDown,a=>{!r&&a.button===0&&a.ctrlKey===!1&&(s.onOpenToggle(),s.open||a.preventDefault())}),onKeyDown:ue(e.onKeyDown,a=>{r||(["Enter"," "].includes(a.key)&&s.onOpenToggle(),a.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(a.key)&&a.preventDefault())})})})});fh.displayName=dh;var TS="DropdownMenuPortal",hh=e=>{const{__scopeDropdownMenu:t,...n}=e,r=jt(t);return c.jsx(cS,{...r,...n})};hh.displayName=TS;var ph="DropdownMenuContent",mh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=ch(ph,n),s=jt(n),i=m.useRef(!1);return c.jsx(uS,{id:o.contentId,"aria-labelledby":o.triggerId,...s,...r,ref:t,onCloseAutoFocus:ue(e.onCloseAutoFocus,a=>{var l;i.current||(l=o.triggerRef.current)==null||l.focus(),i.current=!1,a.preventDefault()}),onInteractOutside:ue(e.onInteractOutside,a=>{const l=a.detail.originalEvent,u=l.button===0&&l.ctrlKey===!0,d=l.button===2||u;(!o.modal||d)&&(i.current=!0)}),style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});mh.displayName=ph;var kS="DropdownMenuGroup",ES=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=jt(n);return c.jsx(dS,{...o,...r,ref:t})});ES.displayName=kS;var IS="DropdownMenuLabel",gh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=jt(n);return c.jsx(fS,{...o,...r,ref:t})});gh.displayName=IS;var NS="DropdownMenuItem",xh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=jt(n);return c.jsx(hS,{...o,...r,ref:t})});xh.displayName=NS;var AS="DropdownMenuCheckboxItem",vh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=jt(n);return c.jsx(pS,{...o,...r,ref:t})});vh.displayName=AS;var _S="DropdownMenuRadioGroup",jS=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=jt(n);return c.jsx(mS,{...o,...r,ref:t})});jS.displayName=_S;var RS="DropdownMenuRadioItem",wh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=jt(n);return c.jsx(gS,{...o,...r,ref:t})});wh.displayName=RS;var PS="DropdownMenuItemIndicator",bh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=jt(n);return c.jsx(xS,{...o,...r,ref:t})});bh.displayName=PS;var OS="DropdownMenuSeparator",yh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=jt(n);return c.jsx(vS,{...o,...r,ref:t})});yh.displayName=OS;var MS="DropdownMenuArrow",DS=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=jt(n);return c.jsx(wS,{...o,...r,ref:t})});DS.displayName=MS;var LS="DropdownMenuSubTrigger",Sh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=jt(n);return c.jsx(bS,{...o,...r,ref:t})});Sh.displayName=LS;var FS="DropdownMenuSubContent",Ch=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=jt(n);return c.jsx(yS,{...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)"}})});Ch.displayName=FS;var $S=uh,BS=fh,zS=hh,Th=mh,kh=gh,Eh=xh,Ih=vh,Nh=wh,Ah=bh,_h=yh,jh=Sh,Rh=Ch;const HS=$S,US=BS,WS=m.forwardRef(({className:e,inset:t,children:n,...r},o)=>c.jsxs(jh,{ref:o,className:Z("flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent",t&&"pl-8",e),...r,children:[n,c.jsx(oe.ChevronRight,{className:"ml-auto h-4 w-4"})]}));WS.displayName=jh.displayName;const VS=m.forwardRef(({className:e,...t},n)=>c.jsx(Rh,{ref:n,className:Z("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}));VS.displayName=Rh.displayName;const Ph=m.forwardRef(({className:e,sideOffset:t=4,...n},r)=>c.jsx(zS,{children:c.jsx(Th,{ref:r,sideOffset:t,className:Z("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})}));Ph.displayName=Th.displayName;const Ya=m.forwardRef(({className:e,inset:t,...n},r)=>c.jsx(Eh,{ref:r,className:Z("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}));Ya.displayName=Eh.displayName;const qS=m.forwardRef(({className:e,children:t,checked:n,...r},o)=>c.jsxs(Ih,{ref:o,className:Z("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),checked:n,...r,children:[c.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:c.jsx(Ah,{children:c.jsx(oe.Check,{className:"h-4 w-4"})})}),t]}));qS.displayName=Ih.displayName;const KS=m.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(Nh,{ref:r,className:Z("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[c.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:c.jsx(Ah,{children:c.jsx(oe.Circle,{className:"h-2 w-2 fill-current"})})}),t]}));KS.displayName=Nh.displayName;const GS=m.forwardRef(({className:e,inset:t,...n},r)=>c.jsx(kh,{ref:r,className:Z("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));GS.displayName=kh.displayName;const YS=m.forwardRef(({className:e,...t},n)=>c.jsx(_h,{ref:n,className:Z("-mx-1 my-1 h-px bg-muted",e),...t}));YS.displayName=_h.displayName;function zs({className:e="",placeholder:t="Type your message...",autoFocus:n=!0,maxHeight:r=void 0,streamingDebounceMs:o=500,streamingThrottleMs:s,followNewMessages:i=!0,enableFileUpload:a=!0,enableExcelUpload:l=!1,enableMessageEditing:u=!0,customStyles:d={},onMessageSent:f,onExcelUploadSuccess:h,onError:p}){const{api:w}=xi(),{currentThreadId:x}=Mo(),{threadId:g,messages:v,hasMore:b,isHistoryLoading:S,isLoading:N,loadOlder:C,listCheckpoints:k,navigateToCheckpoint:I,returnToLatest:A,checkpoint:j,respondToInterrupt:P,metadata:L}=Do(),{isStreaming:F,error:V,submit:M,stop:G}=Ec(),q=g??x??null,U=(j==null?void 0:j.id)??null,B=(j==null?void 0:j.namespace)??null,$=(L==null?void 0:L.assemblingMessageId)??null,[ce,D]=y.useState(null),[Q,de]=y.useState(""),[we,ye]=y.useState(null),[Se,K]=y.useState([]),[O,X]=y.useState(0),[ee,fe]=y.useState(0),[ne,pe]=y.useState(!1),[Ze,Qe]=y.useState(null),[Pe,He]=y.useState(null),[ct,tt]=y.useState(!1),[Be,gt]=y.useState(null),[J,re]=y.useState([]),[he,Ce]=y.useState(null),[me,Oe]=y.useState(null),[it,Me]=y.useState(!1),et=y.useRef(null),vt=y.useRef(null),Zt=y.useRef(null),qn=y.useCallback(()=>{et.current&&(et.current.value=""),vt.current&&(vt.current.value=""),X(se=>se+1),fe(se=>se+1)},[]),Mr=y.useRef(!1);y.useEffect(()=>{Mr.current&&!F&&(K([]),qn()),Mr.current=F},[F,qn]);const[mr,Rt]=y.useState("desktop");y.useEffect(()=>{const se=()=>{const be=window.innerWidth;Rt(be<640?"phone":be<1024?"tablet":"desktop")};return se(),window.addEventListener("resize",se),()=>window.removeEventListener("resize",se)},[]),y.useEffect(()=>{let se=!1;if(!q){re([]),Ce(null),Oe(null),Zt.current=null;return}const be={threadId:q,checkpointId:U??null,checkpointNs:B??null},Ue=Zt.current;if(!(Ue&&Ue.threadId===be.threadId&&Ue.checkpointId===be.checkpointId&&Ue.checkpointNs===be.checkpointNs))return k(q).then(ot=>{var Ee;if(se)return;const Pt=((ot==null?void 0:ot.checkpoints)??[]).slice().sort((Fe,Ke)=>new Date(Ke.createdAt).getTime()-new Date(Fe.createdAt).getTime());re(Pt);const E=he,z=E&&Pt.some(Fe=>Fe.checkpointId===E)?E:((Ee=Pt[0])==null?void 0:Ee.checkpointId)??null;let te=null;if(z){const Fe=Pt.find(Ke=>Ke.checkpointId===z);te=(Fe==null?void 0:Fe.checkpointNs)??null}Ce(z),Oe(te),Zt.current=be}).catch(ot=>{console.error("ChatInterface - listCheckpoints error:",ot),se||(re([]),Zt.current=null)}),()=>{se=!0}},[q,U,B,he,k]),y.useEffect(()=>{U&&(Ce(U),Oe(B??null))},[U,B]);const wo=y.useCallback(async()=>{if(!(!b||S))try{await C()}catch(se){console.warn("loadOlder failed",se)}},[b,S,C]);y.useEffect(()=>{(async()=>{if(!w.baseUrl){gt(null);return}try{const be=await w.getAgent("default");gt(be.uiDefaultMessage||null)}catch(be){console.warn("Failed to fetch default message:",be),gt(null)}})()},[w]),y.useEffect(()=>{V&&!ct&&(p==null||p(V))},[V,ct,p]);const _n=se=>{if(se.length>Cs)return`Message too long (${se.length}/${Cs} characters)`;try{return ty(se),null}catch(be){return(be==null?void 0:be.message)||"Invalid message"}},St=async se=>{const be=se.trim();if(!(!be&&Se.length===0)){if(be){const Ue=_n(be);if(Ue){ye(Ue);return}}try{await M({text:be||"",attachments:Se,payload:ce?{edit:!0,originalMessageId:ce}:void 0},{checkpointId:he??U??void 0,checkpointNs:me??B??void 0}),f==null||f(be),ye(null),K([]),qn(),D(null),de("")}catch(Ue){const ot=(Ue==null?void 0:Ue.message)||"Failed to send message";ye(ot),p==null||p(ot)}}},At=y.useCallback((se,be)=>{u&&(D(se),de(be),ye(null))},[u]),Ut=y.useCallback(()=>{D(null),de(""),ye(null)},[]),Kn=y.useCallback((se,be)=>{At(se,be)},[At]),dn=y.useCallback(se=>{const be=Ue=>{const ot=Ue.content||[],Pt=ot.filter(E=>E.type==="text").map(E=>E.text).join("");if(Pt)return Pt;try{return JSON.stringify(ot,null,2)}catch{return String(ot)}};for(let Ue=se-1;Ue>=0;Ue--)if(v[Ue].role==="user"){const ot=be(v[Ue]);ot&&M({text:ot},{checkpointId:he??U??void 0,checkpointNs:me??B??void 0});break}},[v,M,he,me,U,B]),gr=se=>{const be=Array.from(se.target.files||[]);K(Ue=>[...Ue,...be]),se.target.value=""},fn=se=>{K(be=>{const Ue=be.filter((ot,Pt)=>se!==Pt);return Ue.length===0&&qn(),Ue})},kn=async se=>{const be=(se.target.files||[])[0];if(be){Qe(null),He(null),pe(!0);try{await M({attachments:[be]},{checkpointId:he??U??void 0,checkpointNs:me??B??void 0});const Ue=`Uploaded ${be.name} - processing through chat stream`;He(Ue)}catch(Ue){const ot=Ue instanceof Error?Ue.message:"Failed to upload Excel file";console.error("Excel upload failed",Ue),Qe(ot),p==null||p(ot)}finally{pe(!1),se.target.value="",qn()}}},Gn=se=>{if(!se)return"Unknown";const be=Date.parse(se);return Number.isNaN(be)?se:new Date(be).toLocaleString()},Dr=async se=>{if(x){Me(!0);try{if(!se){await A(),Ce(null),Oe(null);return}const be=J.find(ot=>ot.checkpointId===se),Ue=(be==null?void 0:be.checkpointNs)??null;await I(se,Ue),Ce(se),Oe(Ue)}finally{Me(!1)}}},Lr=`flex flex-1 w-full flex-col min-h-0 min-w-0 max-h-full overflow-hidden bg-transparent ${e} ${d.container||""}`,Fr=`flex-1 min-h-0 min-w-0 max-h-full w-full overflow-hidden overscroll-contain break-words break-anywhere p-4 bg-transparent ${d.messagesArea||""}`,jn=`flex-shrink-0 w-full border-t p-4 bg-transparent ${d.inputArea||""}`;return c.jsxs("div",{className:Lr,children:[!!V&&!ct&&c.jsxs("div",{className:"flex-shrink-0 bg-red-50 border border-red-200 text-red-800 px-4 py-2 text-sm flex items-center justify-between",children:[c.jsx("span",{children:V}),c.jsx(Ge,{variant:"ghost",size:"sm",onClick:()=>tt(!0),className:"text-red-800 hover:bg-red-100","aria-label":"Dismiss error",children:c.jsx(oe.X,{size:16})})]}),x&&J.length>0&&c.jsxs("div",{className:"flex-shrink-0 flex items-center gap-2 px-4 py-2 border-b border-border bg-muted/60 text-xs dark:bg-muted/50",children:[c.jsx("span",{className:"opacity-70",children:"Checkpoint:"}),c.jsxs("select",{className:"border border-border rounded px-2 py-1 text-xs bg-card text-foreground focus:outline-none focus:ring-1 focus:ring-ring dark:bg-secondary",value:he??"",onChange:se=>{const be=se.target.value||null;Dr(be)},children:[c.jsx("option",{value:"",children:"Latest"}),J.map(se=>c.jsxs("option",{value:se.checkpointId,children:[Gn(se.createdAt),se.preview?` — ${se.preview.slice(0,40)}`:""]},se.checkpointId))]})]}),c.jsxs("div",{className:`relative ${Fr}`,style:r?{maxHeight:r}:void 0,children:[c.jsx(Ta,{className:"h-full",style:{height:"100%"},messages:v,isStreaming:F,streamingAssistantId:$,streamingDebounceMs:typeof s=="number"?s:o,followNewMessages:i,layoutSize:mr,enableMessageEditing:u,editingMessageId:ce,onStartReached:()=>{wo()},onEdit:Kn,onRegenerate:dn,onCancelEdit:Ut,emptyMessage:Be??void 0,isNavigatingCheckpoint:it}),N&&c.jsxs("div",{className:"absolute inset-0 z-10 flex flex-col items-center justify-center gap-2 bg-background/80 backdrop-blur-sm text-muted-foreground",children:[c.jsx(oe.Loader2,{className:"h-6 w-6 animate-spin"}),c.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:"Loading messages…"})]})]}),c.jsxs("div",{className:jn,children:[ce&&c.jsx("div",{className:"mb-3 p-3 bg-blue-50 border border-blue-200 rounded-lg",children:c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(oe.Edit3,{size:16,className:"text-blue-600"}),c.jsx("span",{className:"text-sm font-medium text-blue-800",children:"Editing message"})]}),c.jsx(Ge,{variant:"ghost",size:"sm",onClick:Ut,className:"text-blue-600 hover:bg-blue-100",children:c.jsx(oe.X,{size:16})})]})}),(a||l)&&c.jsxs("div",{className:"mb-3 space-y-3",children:[a&&c.jsxs(c.Fragment,{children:[c.jsx("input",{ref:et,type:"file",multiple:!0,onChange:se=>gr(se),className:"hidden"},O),Se.length>0&&c.jsx("div",{className:"flex flex-wrap gap-2",children:Se.map((se,be)=>c.jsxs("div",{className:"flex items-center gap-2 bg-gray-100 dark:bg-gray-800 rounded-lg px-3 py-2 text-sm text-gray-900 dark:text-gray-100",children:[c.jsx(oe.Paperclip,{size:14}),c.jsx("span",{className:"truncate max-w-[150px]",children:se.name}),c.jsx(Ge,{variant:"ghost",size:"sm",onClick:()=>fn(be),className:"h-4 w-4 p-0 text-gray-500 dark:text-gray-400 hover:text-red-500 dark:hover:text-red-400","aria-label":`Remove ${se.name}`,children:c.jsx(oe.X,{size:12})})]},be))})]}),l&&c.jsxs(c.Fragment,{children:[c.jsx("input",{ref:vt,type:"file",accept:".xls,.xlsx,.xlsm",onChange:kn,className:"hidden"},ee),ne&&c.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[c.jsx(oe.Loader2,{className:"h-4 w-4 animate-spin"})," Uploading Excel file..."]}),Pe&&!ne&&c.jsx("div",{className:"text-sm rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-emerald-700",children:Pe}),Ze&&!ne&&c.jsx("div",{className:"text-sm rounded border border-red-200 bg-red-50 px-3 py-2 text-red-600",children:Ze})]})]}),we&&c.jsx("div",{className:"mb-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2",children:we}),c.jsxs("div",{className:"flex items-end gap-2",children:[(a||l)&&c.jsxs(HS,{children:[c.jsx(US,{asChild:!0,children:c.jsx(Ge,{type:"button",size:"icon",variant:"outline",disabled:F,title:"More input actions",className:d.moreButton||"",children:c.jsx(oe.Plus,{size:16})})}),c.jsxs(Ph,{align:"start",sideOffset:6,className:"w-52",children:[a&&c.jsxs(Ya,{onClick:()=>{var se;return(se=et.current)==null?void 0:se.click()},className:"cursor-pointer",children:[c.jsx(oe.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]}),l&&c.jsxs(Ya,{onClick:()=>{var se;ne||(se=vt.current)==null||se.click()},className:`cursor-pointer ${ne?"opacity-60 pointer-events-none":""}`,children:[c.jsx(oe.FileSpreadsheet,{className:"h-4 w-4 mr-2"})," Upload Excel file"]})]})]}),c.jsx("div",{className:"flex-1",children:c.jsx(px,{initialValue:Q,editingMessageId:ce,placeholder:ce?"Edit your message...":t,isStreaming:F,disabled:!1,maxLength:Cs,onSend:St,onCancelEdit:Ut,onStop:G,allowEmptySend:Se.length>0,textareaClassName:`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${ce?"border-blue-400 bg-blue-50 text-blue-900 dark:border-blue-500 dark:bg-blue-950/60 dark:text-blue-50":""} ${we?"border-red-400":""} ${d.textarea||""}`})})]})]})]})}const Hs=m.forwardRef(({className:e,type:t,...n},r)=>c.jsx("input",{type:t,className:Z("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}));Hs.displayName="Input";function Xa(e,[t,n]){return Math.min(n,Math.max(t,e))}function XS(e,t){return m.useReducer((n,r)=>t[n][r]??n,e)}var Ja="ScrollArea",[Oh,$T]=xn(Ja),[JS,Xt]=Oh(Ja),Mh=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,type:r="hover",dir:o,scrollHideDelay:s=600,...i}=e,[a,l]=m.useState(null),[u,d]=m.useState(null),[f,h]=m.useState(null),[p,w]=m.useState(null),[x,g]=m.useState(null),[v,b]=m.useState(0),[S,N]=m.useState(0),[C,k]=m.useState(!1),[I,A]=m.useState(!1),j=Ve(t,L=>l(L)),P=Ts(o);return c.jsx(JS,{scope:n,type:r,dir:P,scrollHideDelay:s,scrollArea:a,viewport:u,onViewportChange:d,content:f,onContentChange:h,scrollbarX:p,onScrollbarXChange:w,scrollbarXEnabled:C,onScrollbarXEnabledChange:k,scrollbarY:x,onScrollbarYChange:g,scrollbarYEnabled:I,onScrollbarYEnabledChange:A,onCornerWidthChange:b,onCornerHeightChange:N,children:c.jsx(_e.div,{dir:P,...i,ref:j,style:{position:"relative","--radix-scroll-area-corner-width":v+"px","--radix-scroll-area-corner-height":S+"px",...e.style}})})});Mh.displayName=Ja;var Dh="ScrollAreaViewport",Lh=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,i=Xt(Dh,n),a=m.useRef(null),l=Ve(t,a,i.onViewportChange);return c.jsxs(c.Fragment,{children:[c.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-scroll-area-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-scroll-area-viewport]::-webkit-scrollbar{display:none}"},nonce:o}),c.jsx(_e.div,{"data-radix-scroll-area-viewport":"",...s,ref:l,style:{overflowX:i.scrollbarXEnabled?"scroll":"hidden",overflowY:i.scrollbarYEnabled?"scroll":"hidden",...e.style},children:c.jsx("div",{ref:i.onContentChange,style:{minWidth:"100%",display:"table"},children:r})})]})});Lh.displayName=Dh;var Tn="ScrollAreaScrollbar",Za=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Xt(Tn,e.__scopeScrollArea),{onScrollbarXEnabledChange:s,onScrollbarYEnabledChange:i}=o,a=e.orientation==="horizontal";return m.useEffect(()=>(a?s(!0):i(!0),()=>{a?s(!1):i(!1)}),[a,s,i]),o.type==="hover"?c.jsx(ZS,{...r,ref:t,forceMount:n}):o.type==="scroll"?c.jsx(QS,{...r,ref:t,forceMount:n}):o.type==="auto"?c.jsx(Fh,{...r,ref:t,forceMount:n}):o.type==="always"?c.jsx(Qa,{...r,ref:t}):null});Za.displayName=Tn;var ZS=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Xt(Tn,e.__scopeScrollArea),[s,i]=m.useState(!1);return m.useEffect(()=>{const a=o.scrollArea;let l=0;if(a){const u=()=>{window.clearTimeout(l),i(!0)},d=()=>{l=window.setTimeout(()=>i(!1),o.scrollHideDelay)};return a.addEventListener("pointerenter",u),a.addEventListener("pointerleave",d),()=>{window.clearTimeout(l),a.removeEventListener("pointerenter",u),a.removeEventListener("pointerleave",d)}}},[o.scrollArea,o.scrollHideDelay]),c.jsx(Bt,{present:n||s,children:c.jsx(Fh,{"data-state":s?"visible":"hidden",...r,ref:t})})}),QS=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Xt(Tn,e.__scopeScrollArea),s=e.orientation==="horizontal",i=qs(()=>l("SCROLL_END"),100),[a,l]=XS("hidden",{hidden:{SCROLL:"scrolling"},scrolling:{SCROLL_END:"idle",POINTER_ENTER:"interacting"},interacting:{SCROLL:"interacting",POINTER_LEAVE:"idle"},idle:{HIDE:"hidden",SCROLL:"scrolling",POINTER_ENTER:"interacting"}});return m.useEffect(()=>{if(a==="idle"){const u=window.setTimeout(()=>l("HIDE"),o.scrollHideDelay);return()=>window.clearTimeout(u)}},[a,o.scrollHideDelay,l]),m.useEffect(()=>{const u=o.viewport,d=s?"scrollLeft":"scrollTop";if(u){let f=u[d];const h=()=>{const p=u[d];f!==p&&(l("SCROLL"),i()),f=p};return u.addEventListener("scroll",h),()=>u.removeEventListener("scroll",h)}},[o.viewport,s,l,i]),c.jsx(Bt,{present:n||a!=="hidden",children:c.jsx(Qa,{"data-state":a==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:ue(e.onPointerEnter,()=>l("POINTER_ENTER")),onPointerLeave:ue(e.onPointerLeave,()=>l("POINTER_LEAVE"))})})}),Fh=m.forwardRef((e,t)=>{const n=Xt(Tn,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,i]=m.useState(!1),a=e.orientation==="horizontal",l=qs(()=>{if(n.viewport){const u=n.viewport.offsetWidth<n.viewport.scrollWidth,d=n.viewport.offsetHeight<n.viewport.scrollHeight;i(a?u:d)}},10);return Rr(n.viewport,l),Rr(n.content,l),c.jsx(Bt,{present:r||s,children:c.jsx(Qa,{"data-state":s?"visible":"hidden",...o,ref:t})})}),Qa=m.forwardRef((e,t)=>{const{orientation:n="vertical",...r}=e,o=Xt(Tn,e.__scopeScrollArea),s=m.useRef(null),i=m.useRef(0),[a,l]=m.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),u=Uh(a.viewport,a.content),d={...r,sizes:a,onSizesChange:l,hasThumb:u>0&&u<1,onThumbChange:h=>s.current=h,onThumbPointerUp:()=>i.current=0,onThumbPointerDown:h=>i.current=h};function f(h,p){return sC(h,i.current,a,p)}return n==="horizontal"?c.jsx(eC,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollLeft,p=Wh(h,a,o.dir);s.current.style.transform=`translate3d(${p}px, 0, 0)`}},onWheelScroll:h=>{o.viewport&&(o.viewport.scrollLeft=h)},onDragScroll:h=>{o.viewport&&(o.viewport.scrollLeft=f(h,o.dir))}}):n==="vertical"?c.jsx(tC,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollTop,p=Wh(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}),eC=m.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=Xt(Tn,e.__scopeScrollArea),[i,a]=m.useState(),l=m.useRef(null),u=Ve(t,l,s.onScrollbarXChange);return m.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),c.jsx(Bh,{"data-orientation":"horizontal",...o,ref:u,sizes:n,style:{bottom:0,left:s.dir==="rtl"?"var(--radix-scroll-area-corner-width)":0,right:s.dir==="ltr"?"var(--radix-scroll-area-corner-width)":0,"--radix-scroll-area-thumb-width":Vs(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),qh(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:Ws(i.paddingLeft),paddingEnd:Ws(i.paddingRight)}})}})}),tC=m.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=Xt(Tn,e.__scopeScrollArea),[i,a]=m.useState(),l=m.useRef(null),u=Ve(t,l,s.onScrollbarYChange);return m.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),c.jsx(Bh,{"data-orientation":"vertical",...o,ref:u,sizes:n,style:{top:0,right:s.dir==="ltr"?0:void 0,left:s.dir==="rtl"?0:void 0,bottom:"var(--radix-scroll-area-corner-height)","--radix-scroll-area-thumb-height":Vs(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),qh(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:Ws(i.paddingTop),paddingEnd:Ws(i.paddingBottom)}})}})}),[nC,$h]=Oh(Tn),Bh=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,sizes:r,hasThumb:o,onThumbChange:s,onThumbPointerUp:i,onThumbPointerDown:a,onThumbPositionChange:l,onDragScroll:u,onWheelScroll:d,onResize:f,...h}=e,p=Xt(Tn,n),[w,x]=m.useState(null),g=Ve(t,j=>x(j)),v=m.useRef(null),b=m.useRef(""),S=p.viewport,N=r.content-r.viewport,C=Tt(d),k=Tt(l),I=qs(f,10);function A(j){if(v.current){const P=j.clientX-v.current.left,L=j.clientY-v.current.top;u({x:P,y:L})}}return m.useEffect(()=>{const j=P=>{const L=P.target;(w==null?void 0:w.contains(L))&&C(P,N)};return document.addEventListener("wheel",j,{passive:!1}),()=>document.removeEventListener("wheel",j,{passive:!1})},[S,w,N,C]),m.useEffect(k,[r,k]),Rr(w,I),Rr(p.content,I),c.jsx(nC,{scope:n,scrollbar:w,hasThumb:o,onThumbChange:Tt(s),onThumbPointerUp:Tt(i),onThumbPositionChange:k,onThumbPointerDown:Tt(a),children:c.jsx(_e.div,{...h,ref:g,style:{position:"absolute",...h.style},onPointerDown:ue(e.onPointerDown,j=>{j.button===0&&(j.target.setPointerCapture(j.pointerId),v.current=w.getBoundingClientRect(),b.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",p.viewport&&(p.viewport.style.scrollBehavior="auto"),A(j))}),onPointerMove:ue(e.onPointerMove,A),onPointerUp:ue(e.onPointerUp,j=>{const P=j.target;P.hasPointerCapture(j.pointerId)&&P.releasePointerCapture(j.pointerId),document.body.style.webkitUserSelect=b.current,p.viewport&&(p.viewport.style.scrollBehavior=""),v.current=null})})})}),Us="ScrollAreaThumb",zh=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=$h(Us,e.__scopeScrollArea);return c.jsx(Bt,{present:n||o.hasThumb,children:c.jsx(rC,{ref:t,...r})})}),rC=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=Xt(Us,n),i=$h(Us,n),{onThumbPositionChange:a}=i,l=Ve(t,f=>i.onThumbChange(f)),u=m.useRef(void 0),d=qs(()=>{u.current&&(u.current(),u.current=void 0)},100);return m.useEffect(()=>{const f=s.viewport;if(f){const h=()=>{if(d(),!u.current){const p=iC(f,a);u.current=p,a()}};return a(),f.addEventListener("scroll",h),()=>f.removeEventListener("scroll",h)}},[s.viewport,d,a]),c.jsx(_e.div,{"data-state":i.hasThumb?"visible":"hidden",...o,ref:l,style:{width:"var(--radix-scroll-area-thumb-width)",height:"var(--radix-scroll-area-thumb-height)",...r},onPointerDownCapture:ue(e.onPointerDownCapture,f=>{const p=f.target.getBoundingClientRect(),w=f.clientX-p.left,x=f.clientY-p.top;i.onThumbPointerDown({x:w,y:x})}),onPointerUp:ue(e.onPointerUp,i.onThumbPointerUp)})});zh.displayName=Us;var el="ScrollAreaCorner",Hh=m.forwardRef((e,t)=>{const n=Xt(el,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?c.jsx(oC,{...e,ref:t}):null});Hh.displayName=el;var oC=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=Xt(el,n),[s,i]=m.useState(0),[a,l]=m.useState(0),u=!!(s&&a);return Rr(o.scrollbarX,()=>{var f;const d=((f=o.scrollbarX)==null?void 0:f.offsetHeight)||0;o.onCornerHeightChange(d),l(d)}),Rr(o.scrollbarY,()=>{var f;const d=((f=o.scrollbarY)==null?void 0:f.offsetWidth)||0;o.onCornerWidthChange(d),i(d)}),u?c.jsx(_e.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 Ws(e){return e?parseInt(e,10):0}function Uh(e,t){const n=e/t;return isNaN(n)?0:n}function Vs(e){const t=Uh(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function sC(e,t,n,r="ltr"){const o=Vs(n),s=o/2,i=t||s,a=o-i,l=n.scrollbar.paddingStart+i,u=n.scrollbar.size-n.scrollbar.paddingEnd-a,d=n.content-n.viewport,f=r==="ltr"?[0,d]:[d*-1,0];return Vh([l,u],f)(e)}function Wh(e,t,n="ltr"){const r=Vs(t),o=t.scrollbar.paddingStart+t.scrollbar.paddingEnd,s=t.scrollbar.size-o,i=t.content-t.viewport,a=s-r,l=n==="ltr"?[0,i]:[i*-1,0],u=Xa(e,l);return Vh([0,i],[0,a])(u)}function Vh(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 qh(e,t){return e>0&&e<t}var iC=(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 qs(e,t){const n=Tt(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 Rr(e,t){const n=Tt(t);Ct(()=>{let r=0;if(e){const o=new ResizeObserver(()=>{cancelAnimationFrame(r),r=window.requestAnimationFrame(n)});return o.observe(e),()=>{window.cancelAnimationFrame(r),o.unobserve(e)}}},[e,n])}var Kh=Mh,aC=Lh,lC=Hh;const Gh=m.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(Kh,{ref:r,className:Z("relative overflow-hidden",e),...n,children:[c.jsx(aC,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),c.jsx(Yh,{}),c.jsx(lC,{})]}));Gh.displayName=Kh.displayName;const Yh=m.forwardRef(({className:e,orientation:t="vertical",...n},r)=>c.jsx(Za,{ref:r,orientation:t,className:Z("flex touch-none select-none transition-colors",t==="vertical"&&"h-full w-2.5 border-l border-l-transparent p-[1px]",t==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent p-[1px]",e),...n,children:c.jsx(zh,{className:"relative flex-1 rounded-full bg-border"})}));Yh.displayName=Za.displayName;function tl({className:e="",showCreateButton:t=!0,showDeleteButton:n=!0,showEditTitle:r=!0,maxHeight:o="400px",customStyles:s={},currentThreadId:i=null,navigateToThread:a,onThreadSelect:l,onThreadCreate:u,onThreadDelete:d}){const{threads:f,currentThreadId:h,isLoading:p,actions:w}=Mo(),{loadThread:x}=Do(),{createThread:g,deleteThread:v,renameThread:b}=w,[S,N]=y.useState(Array.isArray(f)?f:[]),C=y.useRef(S.length>0),[k,I]=y.useState(null),[A,j]=y.useState(""),[P,L]=y.useState(!1);y.useEffect(()=>{const D=Array.isArray(f)?f:[];if(D.length>0){C.current=!0,N(D);return}p||(C.current=!1,N(D))},[f,p]);const F=async D=>{try{await x(D),a==null||a(D),l==null||l(D)}catch(Q){console.error("Failed to select thread:",Q)}},V=async()=>{try{L(!0);const D=await g();u==null||u(D),a==null||a(D)}catch(D){console.error("Failed to create thread:",D)}finally{L(!1)}},M=async(D,Q)=>{if(Q.stopPropagation(),!!confirm("Delete this thread?"))try{await v(D),d==null||d(D)}catch(de){console.error("Failed to delete thread:",de)}},G=(D,Q)=>{Q.stopPropagation(),I(D.threadId),j(D.title||`Thread ${D.threadId.slice(0,8)}`)},q=async D=>{if(A.trim())try{await b(D,A.trim()),I(null),j("")}catch(Q){console.error("Failed to update title:",Q)}},U=()=>{I(null),j("")},B=(D,Q)=>{D.key==="Enter"?q(Q):D.key==="Escape"&&U()},$=D=>{if(!D)return"";try{const Q=new Date(D),we=new Date().getTime()-Q.getTime(),ye=Math.floor(we/(1e3*60*60*24));return ye===0?Q.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):ye===1?"Yesterday":ye<7?`${ye} days ago`:Q.toLocaleDateString()}catch{return""}},ce=D=>D.title||`Thread ${D.threadId.slice(0,8)}`;return c.jsxs("div",{className:`flex flex-col h-full ${e} ${s.container||""}`,children:[t&&c.jsx("div",{className:s.header||"flex-shrink-0 p-2 border-b bg-slate-800 border-slate-700 text-slate-100 flex justify-end",children:c.jsx(Ge,{onClick:V,disabled:P||p,className:s.createButton||"p-2",size:"sm",variant:"ghost",title:P?"Creating...":"New Chat",children:c.jsx(oe.MessageSquarePlus,{size:20})})}),c.jsx(Gh,{className:`flex-1 min-h-0 ${s.threadList||""}`,style:o?{maxHeight:o}:void 0,children:c.jsx("div",{className:"p-2 space-y-1 pb-4",children:p?c.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 py-8 text-slate-400",children:[c.jsx(oe.Loader2,{className:"h-5 w-5 animate-spin"}),c.jsx("span",{className:"text-sm",children:"Loading threads…"})]}):S.length===0?c.jsxs("div",{className:"text-center py-8 text-slate-400",children:[c.jsx(oe.MessageSquare,{className:"w-8 h-8 mx-auto mb-2 opacity-40 text-slate-500"}),c.jsx("p",{className:"text-sm text-slate-500",children:"No conversations yet"})]}):S.slice().sort((D,Q)=>new Date(Q.updatedAt||Q.createdAt||"").getTime()-new Date(D.updatedAt||D.createdAt||"").getTime()).map(D=>c.jsxs("div",{onClick:()=>F(D.threadId),className:`group relative p-3 rounded-lg cursor-pointer transition-colors border ${(i??h)===D.threadId?`${s.activeThread||"bg-slate-600 border-slate-500"} `:`${s.threadItem||"bg-slate-700 border-slate-600 hover:bg-slate-600 text-gray-900 dark:text-slate-100"}`} ${s.threadItem||""} text-gray-900 dark:text-slate-100`,children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("div",{className:"flex-1 min-w-0",children:k===D.threadId?c.jsxs("div",{className:"flex items-center gap-2",onClick:Q=>Q.stopPropagation(),children:[c.jsx(Hs,{value:A,onChange:Q=>j(Q.target.value),onKeyDown:Q=>B(Q,D.threadId),className:"h-6 text-sm",autoFocus:!0}),c.jsx(Ge,{variant:"ghost",size:"sm",onClick:()=>q(D.threadId),className:"h-6 w-6 p-0",children:c.jsx(oe.Check,{size:12})}),c.jsx(Ge,{variant:"ghost",size:"sm",onClick:U,className:"h-6 w-6 p-0",children:c.jsx(oe.X,{size:12})})]}):c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"font-medium text-sm truncate text-gray-900 dark:text-slate-100",children:ce(D)}),c.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500 dark:text-slate-400 mt-1",children:[c.jsx(oe.Calendar,{size:10}),c.jsx("span",{children:$(D.updatedAt||D.createdAt)})]})]})}),c.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity ml-2",children:[r&&k!==D.threadId&&c.jsx(Ge,{variant:"ghost",size:"sm",onClick:Q=>G(D,Q),className:"h-6 w-6 p-0",title:"Edit title",children:c.jsx(oe.Edit3,{size:12})}),n&&c.jsx(Ge,{variant:"ghost",size:"sm",onClick:Q=>M(D.threadId,Q),className:"h-6 w-6 p-0 text-red-400 hover:text-red-300 hover:bg-red-900/20",title:"Delete thread",children:c.jsx(oe.Trash2,{size:12})})]})]}),i===D.threadId&&c.jsx("div",{className:"absolute left-0 top-1/2 -translate-y-1/2 w-1 h-8 bg-blue-400 rounded-r"})]},D.threadId))})})]})}function Pr(e){if(!(typeof globalThis>"u"))return globalThis[e]}function cC(e){if(typeof e!="string")return;const t=e.trim();if(t)return En(t)}function Xh(){const e=[Pr("__API_BASE_URL__"),Pr("__CHAT_API_BASE_URL__"),Pr("__CHAT_API_URL__")];for(const t of e){const n=cC(t);if(n)return n}}function Jh(){const e=[Pr("__API_AUTH_TOKEN__"),Pr("__CHAT_API_KEY__"),Pr("__CHAT_AUTH_TOKEN__")];for(const t of e)if(typeof t=="string"&&t.trim())return t.trim()}function Zh(...e){for(const t of e)if(typeof t=="string"&&t.trim())return En(t);return En()}function Qh(){const e={},t=Xh(),n=Jh();return t&&(e.baseUrl=t),n&&(e.apiKey=n),e}function ep(){const e=Qh(),t=Pn.getAuthToken(),n=Xh();return{apiBaseUrl:Zh(e.baseUrl,Pn.baseUrl,n),apiKey:t||e.apiKey||Jh()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,truncateToolMessages:!0,toolMessagePreviewLength:200,darkMode:!1,enableSound:!1,messageHistory:100}}const tp="chat-settings";function uC(){try{const e=localStorage.getItem(tp);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function dC(e){try{const t={...e,apiBaseUrl:En(e.apiBaseUrl)};localStorage.setItem(tp,JSON.stringify(t)),t.apiKey&&Pn.setAuthToken(t.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function fC(){const e=ep(),t=uC(),n=Pn.getAuthToken(),r=typeof t.apiBaseUrl=="string"?t.apiBaseUrl:void 0;return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:Zh(Pn.baseUrl,r,e.apiBaseUrl)}}function hC(e){Pn.updateConfig({baseUrl:e.apiBaseUrl,authToken:e.apiKey??void 0}),dC(e)}var pC="Label",np=m.forwardRef((e,t)=>c.jsx(_e.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())}}));np.displayName=pC;var rp=np;const mC=bo.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),Jt=m.forwardRef(({className:e,...t},n)=>c.jsx(rp,{ref:n,className:Z(mC(),e),...t}));Jt.displayName=rp.displayName;function op(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 Ks="Switch",[gC,BT]=xn(Ks),[xC,vC]=gC(Ks),sp=m.forwardRef((e,t)=>{const{__scopeSwitch:n,name:r,checked:o,defaultChecked:s,required:i,disabled:a,value:l="on",onCheckedChange:u,form:d,...f}=e,[h,p]=m.useState(null),w=Ve(t,S=>p(S)),x=m.useRef(!1),g=h?d||!!h.closest("form"):!0,[v,b]=or({prop:o,defaultProp:s??!1,onChange:u,caller:Ks});return c.jsxs(xC,{scope:n,checked:v,disabled:a,children:[c.jsx(_e.button,{type:"button",role:"switch","aria-checked":v,"aria-required":i,"data-state":cp(v),"data-disabled":a?"":void 0,disabled:a,value:l,...f,ref:w,onClick:ue(e.onClick,S=>{b(N=>!N),g&&(x.current=S.isPropagationStopped(),x.current||S.stopPropagation())})}),g&&c.jsx(lp,{control:h,bubbles:!x.current,name:r,value:l,checked:v,required:i,disabled:a,form:d,style:{transform:"translateX(-100%)"}})]})});sp.displayName=Ks;var ip="SwitchThumb",ap=m.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,o=vC(ip,n);return c.jsx(_e.span,{"data-state":cp(o.checked),"data-disabled":o.disabled?"":void 0,...r,ref:t})});ap.displayName=ip;var wC="SwitchBubbleInput",lp=m.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...o},s)=>{const i=m.useRef(null),a=Ve(i,s),l=op(n),u=wf(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 w=new Event("click",{bubbles:r});p.call(d,n),d.dispatchEvent(w)}},[l,n,r]),c.jsx("input",{type:"checkbox","aria-hidden":!0,defaultChecked:n,...o,tabIndex:-1,ref:a,style:{...o.style,...u,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});lp.displayName=wC;function cp(e){return e?"checked":"unchecked"}var up=sp,bC=ap;const Un=m.forwardRef(({className:e,...t},n)=>c.jsx(up,{className:Z("peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",e),...t,ref:n,children:c.jsx(bC,{className:Z("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=up.displayName;var dp=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"}),yC="VisuallyHidden",SC=m.forwardRef((e,t)=>c.jsx(_e.span,{...e,ref:t,style:{...dp,...e.style}}));SC.displayName=yC;var CC=[" ","Enter","ArrowUp","ArrowDown"],TC=[" ","Enter"],fr="Select",[Gs,Ys,kC]=ka(fr),[Or,zT]=xn(fr,[kC,Ms]),Xs=Ms(),[EC,Wn]=Or(fr),[IC,NC]=Or(fr),fp=e=>{const{__scopeSelect:t,children:n,open:r,defaultOpen:o,onOpenChange:s,value:i,defaultValue:a,onValueChange:l,dir:u,name:d,autoComplete:f,disabled:h,required:p,form:w}=e,x=Xs(t),[g,v]=m.useState(null),[b,S]=m.useState(null),[N,C]=m.useState(!1),k=Ts(u),[I,A]=or({prop:r,defaultProp:o??!1,onChange:s,caller:fr}),[j,P]=or({prop:i,defaultProp:a,onChange:l,caller:fr}),L=m.useRef(null),F=g?w||!!g.closest("form"):!0,[V,M]=m.useState(new Set),G=Array.from(V).map(q=>q.props.value).join(";");return c.jsx(Af,{...x,children:c.jsxs(EC,{required:p,scope:t,trigger:g,onTriggerChange:v,valueNode:b,onValueNodeChange:S,valueNodeHasChildren:N,onValueNodeHasChildrenChange:C,contentId:vn(),value:j,onValueChange:P,open:I,onOpenChange:A,dir:k,triggerPointerDownPosRef:L,disabled:h,children:[c.jsx(Gs.Provider,{scope:t,children:c.jsx(IC,{scope:e.__scopeSelect,onNativeOptionAdd:m.useCallback(q=>{M(U=>new Set(U).add(q))},[]),onNativeOptionRemove:m.useCallback(q=>{M(U=>{const B=new Set(U);return B.delete(q),B})},[]),children:n})}),F?c.jsxs(Dp,{"aria-hidden":!0,required:p,tabIndex:-1,name:d,autoComplete:f,value:j,onChange:q=>P(q.target.value),disabled:h,form:w,children:[j===void 0?c.jsx("option",{value:""}):null,Array.from(V)]},G):null]})})};fp.displayName=fr;var hp="SelectTrigger",pp=m.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...o}=e,s=Xs(n),i=Wn(hp,n),a=i.disabled||r,l=Ve(t,i.onTriggerChange),u=Ys(n),d=m.useRef("touch"),[f,h,p]=Fp(x=>{const g=u().filter(S=>!S.disabled),v=g.find(S=>S.value===i.value),b=$p(g,x,v);b!==void 0&&i.onValueChange(b.value)}),w=x=>{a||(i.onOpenChange(!0),p()),x&&(i.triggerPointerDownPosRef.current={x:Math.round(x.pageX),y:Math.round(x.pageY)})};return c.jsx(_f,{asChild:!0,...s,children:c.jsx(_e.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":Lp(i.value)?"":void 0,...o,ref:l,onClick:ue(o.onClick,x=>{x.currentTarget.focus(),d.current!=="mouse"&&w(x)}),onPointerDown:ue(o.onPointerDown,x=>{d.current=x.pointerType;const g=x.target;g.hasPointerCapture(x.pointerId)&&g.releasePointerCapture(x.pointerId),x.button===0&&x.ctrlKey===!1&&x.pointerType==="mouse"&&(w(x),x.preventDefault())}),onKeyDown:ue(o.onKeyDown,x=>{const g=f.current!=="";!(x.ctrlKey||x.altKey||x.metaKey)&&x.key.length===1&&h(x.key),!(g&&x.key===" ")&&CC.includes(x.key)&&(w(),x.preventDefault())})})})});pp.displayName=hp;var mp="SelectValue",gp=m.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,children:s,placeholder:i="",...a}=e,l=Wn(mp,n),{onValueNodeHasChildrenChange:u}=l,d=s!==void 0,f=Ve(t,l.onValueNodeChange);return Ct(()=>{u(d)},[u,d]),c.jsx(_e.span,{...a,ref:f,style:{pointerEvents:"none"},children:Lp(l.value)?c.jsx(c.Fragment,{children:i}):s})});gp.displayName=mp;var AC="SelectIcon",xp=m.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...o}=e;return c.jsx(_e.span,{"aria-hidden":!0,...o,ref:t,children:r||"▼"})});xp.displayName=AC;var _C="SelectPortal",vp=e=>c.jsx(ls,{asChild:!0,...e});vp.displayName=_C;var hr="SelectContent",wp=m.forwardRef((e,t)=>{const n=Wn(hr,e.__scopeSelect),[r,o]=m.useState();if(Ct(()=>{o(new DocumentFragment)},[]),!n.open){const s=r;return s?yo.createPortal(c.jsx(bp,{scope:e.__scopeSelect,children:c.jsx(Gs.Slot,{scope:e.__scopeSelect,children:c.jsx("div",{children:e.children})})}),s):null}return c.jsx(yp,{...e,ref:t})});wp.displayName=hr;var un=10,[bp,Vn]=Or(hr),jC="SelectContentImpl",RC=Xn.createSlot("SelectContent.RemoveScroll"),yp=m.forwardRef((e,t)=>{const{__scopeSelect:n,position:r="item-aligned",onCloseAutoFocus:o,onEscapeKeyDown:s,onPointerDownOutside:i,side:a,sideOffset:l,align:u,alignOffset:d,arrowPadding:f,collisionBoundary:h,collisionPadding:p,sticky:w,hideWhenDetached:x,avoidCollisions:g,...v}=e,b=Wn(hr,n),[S,N]=m.useState(null),[C,k]=m.useState(null),I=Ve(t,K=>N(K)),[A,j]=m.useState(null),[P,L]=m.useState(null),F=Ys(n),[V,M]=m.useState(!1),G=m.useRef(!1);m.useEffect(()=>{if(S)return wa(S)},[S]),ha();const q=m.useCallback(K=>{const[O,...X]=F().map(ne=>ne.ref.current),[ee]=X.slice(-1),fe=document.activeElement;for(const ne of K)if(ne===fe||(ne==null||ne.scrollIntoView({block:"nearest"}),ne===O&&C&&(C.scrollTop=0),ne===ee&&C&&(C.scrollTop=C.scrollHeight),ne==null||ne.focus(),document.activeElement!==fe))return},[F,C]),U=m.useCallback(()=>q([A,S]),[q,A,S]);m.useEffect(()=>{V&&U()},[V,U]);const{onOpenChange:B,triggerPointerDownPosRef:$}=b;m.useEffect(()=>{if(S){let K={x:0,y:0};const O=ee=>{var fe,ne;K={x:Math.abs(Math.round(ee.pageX)-(((fe=$.current)==null?void 0:fe.x)??0)),y:Math.abs(Math.round(ee.pageY)-(((ne=$.current)==null?void 0:ne.y)??0))}},X=ee=>{K.x<=10&&K.y<=10?ee.preventDefault():S.contains(ee.target)||B(!1),document.removeEventListener("pointermove",O),$.current=null};return $.current!==null&&(document.addEventListener("pointermove",O),document.addEventListener("pointerup",X,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",O),document.removeEventListener("pointerup",X,{capture:!0})}}},[S,B,$]),m.useEffect(()=>{const K=()=>B(!1);return window.addEventListener("blur",K),window.addEventListener("resize",K),()=>{window.removeEventListener("blur",K),window.removeEventListener("resize",K)}},[B]);const[ce,D]=Fp(K=>{const O=F().filter(fe=>!fe.disabled),X=O.find(fe=>fe.ref.current===document.activeElement),ee=$p(O,K,X);ee&&setTimeout(()=>ee.ref.current.focus())}),Q=m.useCallback((K,O,X)=>{const ee=!G.current&&!X;(b.value!==void 0&&b.value===O||ee)&&(j(K),ee&&(G.current=!0))},[b.value]),de=m.useCallback(()=>S==null?void 0:S.focus(),[S]),we=m.useCallback((K,O,X)=>{const ee=!G.current&&!X;(b.value!==void 0&&b.value===O||ee)&&L(K)},[b.value]),ye=r==="popper"?nl:Sp,Se=ye===nl?{side:a,sideOffset:l,align:u,alignOffset:d,arrowPadding:f,collisionBoundary:h,collisionPadding:p,sticky:w,hideWhenDetached:x,avoidCollisions:g}:{};return c.jsx(bp,{scope:n,content:S,viewport:C,onViewportChange:k,itemRefCallback:Q,selectedItem:A,onItemLeave:de,itemTextRefCallback:we,focusSelectedItem:U,selectedItemText:P,position:r,isPositioned:V,searchRef:ce,children:c.jsx(ps,{as:RC,allowPinchZoom:!0,children:c.jsx(as,{asChild:!0,trapped:b.open,onMountAutoFocus:K=>{K.preventDefault()},onUnmountAutoFocus:ue(o,K=>{var O;(O=b.trigger)==null||O.focus({preventScroll:!0}),K.preventDefault()}),children:c.jsx(is,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:K=>K.preventDefault(),onDismiss:()=>b.onOpenChange(!1),children:c.jsx(ye,{role:"listbox",id:b.contentId,"data-state":b.open?"open":"closed",dir:b.dir,onContextMenu:K=>K.preventDefault(),...v,...Se,onPlaced:()=>M(!0),ref:I,style:{display:"flex",flexDirection:"column",outline:"none",...v.style},onKeyDown:ue(v.onKeyDown,K=>{const O=K.ctrlKey||K.altKey||K.metaKey;if(K.key==="Tab"&&K.preventDefault(),!O&&K.key.length===1&&D(K.key),["ArrowUp","ArrowDown","Home","End"].includes(K.key)){let ee=F().filter(fe=>!fe.disabled).map(fe=>fe.ref.current);if(["ArrowUp","End"].includes(K.key)&&(ee=ee.slice().reverse()),["ArrowUp","ArrowDown"].includes(K.key)){const fe=K.target,ne=ee.indexOf(fe);ee=ee.slice(ne+1)}setTimeout(()=>q(ee)),K.preventDefault()}})})})})})})});yp.displayName=jC;var PC="SelectItemAlignedPosition",Sp=m.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...o}=e,s=Wn(hr,n),i=Vn(hr,n),[a,l]=m.useState(null),[u,d]=m.useState(null),f=Ve(t,I=>d(I)),h=Ys(n),p=m.useRef(!1),w=m.useRef(!0),{viewport:x,selectedItem:g,selectedItemText:v,focusSelectedItem:b}=i,S=m.useCallback(()=>{if(s.trigger&&s.valueNode&&a&&u&&x&&g&&v){const I=s.trigger.getBoundingClientRect(),A=u.getBoundingClientRect(),j=s.valueNode.getBoundingClientRect(),P=v.getBoundingClientRect();if(s.dir!=="rtl"){const fe=P.left-A.left,ne=j.left-fe,pe=I.left-ne,Ze=I.width+pe,Qe=Math.max(Ze,A.width),Pe=window.innerWidth-un,He=Xa(ne,[un,Math.max(un,Pe-Qe)]);a.style.minWidth=Ze+"px",a.style.left=He+"px"}else{const fe=A.right-P.right,ne=window.innerWidth-j.right-fe,pe=window.innerWidth-I.right-ne,Ze=I.width+pe,Qe=Math.max(Ze,A.width),Pe=window.innerWidth-un,He=Xa(ne,[un,Math.max(un,Pe-Qe)]);a.style.minWidth=Ze+"px",a.style.right=He+"px"}const L=h(),F=window.innerHeight-un*2,V=x.scrollHeight,M=window.getComputedStyle(u),G=parseInt(M.borderTopWidth,10),q=parseInt(M.paddingTop,10),U=parseInt(M.borderBottomWidth,10),B=parseInt(M.paddingBottom,10),$=G+q+V+B+U,ce=Math.min(g.offsetHeight*5,$),D=window.getComputedStyle(x),Q=parseInt(D.paddingTop,10),de=parseInt(D.paddingBottom,10),we=I.top+I.height/2-un,ye=F-we,Se=g.offsetHeight/2,K=g.offsetTop+Se,O=G+q+K,X=$-O;if(O<=we){const fe=L.length>0&&g===L[L.length-1].ref.current;a.style.bottom="0px";const ne=u.clientHeight-x.offsetTop-x.offsetHeight,pe=Math.max(ye,Se+(fe?de:0)+ne+U),Ze=O+pe;a.style.height=Ze+"px"}else{const fe=L.length>0&&g===L[0].ref.current;a.style.top="0px";const pe=Math.max(we,G+x.offsetTop+(fe?Q:0)+Se)+X;a.style.height=pe+"px",x.scrollTop=O-we+x.offsetTop}a.style.margin=`${un}px 0`,a.style.minHeight=ce+"px",a.style.maxHeight=F+"px",r==null||r(),requestAnimationFrame(()=>p.current=!0)}},[h,s.trigger,s.valueNode,a,u,x,g,v,s.dir,r]);Ct(()=>S(),[S]);const[N,C]=m.useState();Ct(()=>{u&&C(window.getComputedStyle(u).zIndex)},[u]);const k=m.useCallback(I=>{I&&w.current===!0&&(S(),b==null||b(),w.current=!1)},[S,b]);return c.jsx(MC,{scope:n,contentWrapper:a,shouldExpandOnScrollRef:p,onScrollButtonChange:k,children:c.jsx("div",{ref:l,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:N},children:c.jsx(_e.div,{...o,ref:f,style:{boxSizing:"border-box",maxHeight:"100%",...o.style}})})})});Sp.displayName=PC;var OC="SelectPopperPosition",nl=m.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=un,...s}=e,i=Xs(n);return c.jsx(jf,{...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)"}})});nl.displayName=OC;var[MC,rl]=Or(hr,{}),ol="SelectViewport",Cp=m.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...o}=e,s=Vn(ol,n),i=rl(ol,n),a=Ve(t,s.onViewportChange),l=m.useRef(0);return c.jsxs(c.Fragment,{children:[c.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}"},nonce:r}),c.jsx(Gs.Slot,{scope:n,children:c.jsx(_e.div,{"data-radix-select-viewport":"",role:"presentation",...o,ref:a,style:{position:"relative",flex:1,overflow:"hidden auto",...o.style},onScroll:ue(o.onScroll,u=>{const d=u.currentTarget,{contentWrapper:f,shouldExpandOnScrollRef:h}=i;if(h!=null&&h.current&&f){const p=Math.abs(l.current-d.scrollTop);if(p>0){const w=window.innerHeight-un*2,x=parseFloat(f.style.minHeight),g=parseFloat(f.style.height),v=Math.max(x,g);if(v<w){const b=v+p,S=Math.min(w,b),N=b-S;f.style.height=S+"px",f.style.bottom==="0px"&&(d.scrollTop=N>0?N:0,f.style.justifyContent="flex-end")}}}l.current=d.scrollTop})})})]})});Cp.displayName=ol;var Tp="SelectGroup",[DC,LC]=Or(Tp),FC=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=vn();return c.jsx(DC,{scope:n,id:o,children:c.jsx(_e.div,{role:"group","aria-labelledby":o,...r,ref:t})})});FC.displayName=Tp;var kp="SelectLabel",Ep=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=LC(kp,n);return c.jsx(_e.div,{id:o.id,...r,ref:t})});Ep.displayName=kp;var Js="SelectItem",[$C,Ip]=Or(Js),Np=m.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:s,...i}=e,a=Wn(Js,n),l=Vn(Js,n),u=a.value===r,[d,f]=m.useState(s??""),[h,p]=m.useState(!1),w=Ve(t,b=>{var S;return(S=l.itemRefCallback)==null?void 0:S.call(l,b,r,o)}),x=vn(),g=m.useRef("touch"),v=()=>{o||(a.onValueChange(r),a.onOpenChange(!1))};if(r==="")throw new Error("A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.");return c.jsx($C,{scope:n,value:r,disabled:o,textId:x,isSelected:u,onItemTextChange:m.useCallback(b=>{f(S=>S||((b==null?void 0:b.textContent)??"").trim())},[]),children:c.jsx(Gs.ItemSlot,{scope:n,value:r,disabled:o,textValue:d,children:c.jsx(_e.div,{role:"option","aria-labelledby":x,"data-highlighted":h?"":void 0,"aria-selected":u&&h,"data-state":u?"checked":"unchecked","aria-disabled":o||void 0,"data-disabled":o?"":void 0,tabIndex:o?void 0:-1,...i,ref:w,onFocus:ue(i.onFocus,()=>p(!0)),onBlur:ue(i.onBlur,()=>p(!1)),onClick:ue(i.onClick,()=>{g.current!=="mouse"&&v()}),onPointerUp:ue(i.onPointerUp,()=>{g.current==="mouse"&&v()}),onPointerDown:ue(i.onPointerDown,b=>{g.current=b.pointerType}),onPointerMove:ue(i.onPointerMove,b=>{var S;g.current=b.pointerType,o?(S=l.onItemLeave)==null||S.call(l):g.current==="mouse"&&b.currentTarget.focus({preventScroll:!0})}),onPointerLeave:ue(i.onPointerLeave,b=>{var S;b.currentTarget===document.activeElement&&((S=l.onItemLeave)==null||S.call(l))}),onKeyDown:ue(i.onKeyDown,b=>{var N;((N=l.searchRef)==null?void 0:N.current)!==""&&b.key===" "||(TC.includes(b.key)&&v(),b.key===" "&&b.preventDefault())})})})})});Np.displayName=Js;var vo="SelectItemText",Ap=m.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,...s}=e,i=Wn(vo,n),a=Vn(vo,n),l=Ip(vo,n),u=NC(vo,n),[d,f]=m.useState(null),h=Ve(t,v=>f(v),l.onItemTextChange,v=>{var b;return(b=a.itemTextRefCallback)==null?void 0:b.call(a,v,l.value,l.disabled)}),p=d==null?void 0:d.textContent,w=m.useMemo(()=>c.jsx("option",{value:l.value,disabled:l.disabled,children:p},l.value),[l.disabled,l.value,p]),{onNativeOptionAdd:x,onNativeOptionRemove:g}=u;return Ct(()=>(x(w),()=>g(w)),[x,g,w]),c.jsxs(c.Fragment,{children:[c.jsx(_e.span,{id:l.textId,...s,ref:h}),l.isSelected&&i.valueNode&&!i.valueNodeHasChildren?yo.createPortal(s.children,i.valueNode):null]})});Ap.displayName=vo;var _p="SelectItemIndicator",jp=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return Ip(_p,n).isSelected?c.jsx(_e.span,{"aria-hidden":!0,...r,ref:t}):null});jp.displayName=_p;var sl="SelectScrollUpButton",Rp=m.forwardRef((e,t)=>{const n=Vn(sl,e.__scopeSelect),r=rl(sl,e.__scopeSelect),[o,s]=m.useState(!1),i=Ve(t,r.onScrollButtonChange);return Ct(()=>{if(n.viewport&&n.isPositioned){let a=function(){const u=l.scrollTop>0;s(u)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?c.jsx(Op,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop-l.offsetHeight)}}):null});Rp.displayName=sl;var il="SelectScrollDownButton",Pp=m.forwardRef((e,t)=>{const n=Vn(il,e.__scopeSelect),r=rl(il,e.__scopeSelect),[o,s]=m.useState(!1),i=Ve(t,r.onScrollButtonChange);return Ct(()=>{if(n.viewport&&n.isPositioned){let a=function(){const u=l.scrollHeight-l.clientHeight,d=Math.ceil(l.scrollTop)<u;s(d)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?c.jsx(Op,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop+l.offsetHeight)}}):null});Pp.displayName=il;var Op=m.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...o}=e,s=Vn("SelectScrollButton",n),i=m.useRef(null),a=Ys(n),l=m.useCallback(()=>{i.current!==null&&(window.clearInterval(i.current),i.current=null)},[]);return m.useEffect(()=>()=>l(),[l]),Ct(()=>{var d;const u=a().find(f=>f.ref.current===document.activeElement);(d=u==null?void 0:u.ref.current)==null||d.scrollIntoView({block:"nearest"})},[a]),c.jsx(_e.div,{"aria-hidden":!0,...o,ref:t,style:{flexShrink:0,...o.style},onPointerDown:ue(o.onPointerDown,()=>{i.current===null&&(i.current=window.setInterval(r,50))}),onPointerMove:ue(o.onPointerMove,()=>{var u;(u=s.onItemLeave)==null||u.call(s),i.current===null&&(i.current=window.setInterval(r,50))}),onPointerLeave:ue(o.onPointerLeave,()=>{l()})})}),BC="SelectSeparator",Mp=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return c.jsx(_e.div,{"aria-hidden":!0,...r,ref:t})});Mp.displayName=BC;var al="SelectArrow",zC=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Xs(n),s=Wn(al,n),i=Vn(al,n);return s.open&&i.position==="popper"?c.jsx(Rf,{...o,...r,ref:t}):null});zC.displayName=al;var HC="SelectBubbleInput",Dp=m.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const o=m.useRef(null),s=Ve(r,o),i=op(t);return m.useEffect(()=>{const a=o.current;if(!a)return;const l=window.HTMLSelectElement.prototype,d=Object.getOwnPropertyDescriptor(l,"value").set;if(i!==t&&d){const f=new Event("change",{bubbles:!0});d.call(a,t),a.dispatchEvent(f)}},[i,t]),c.jsx(_e.select,{...n,style:{...dp,...n.style},ref:s,defaultValue:t})});Dp.displayName=HC;function Lp(e){return e===""||e===void 0}function Fp(e){const t=Tt(e),n=m.useRef(""),r=m.useRef(0),o=m.useCallback(i=>{const a=n.current+i;t(a),function l(u){n.current=u,window.clearTimeout(r.current),u!==""&&(r.current=window.setTimeout(()=>l(""),1e3))}(a)},[t]),s=m.useCallback(()=>{n.current="",window.clearTimeout(r.current)},[]);return m.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,o,s]}function $p(e,t,n){const o=t.length>1&&Array.from(t).every(u=>u===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let i=UC(e,Math.max(s,0));o.length===1&&(i=i.filter(u=>u!==n));const l=i.find(u=>u.textValue.toLowerCase().startsWith(o.toLowerCase()));return l!==n?l:void 0}function UC(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var WC=fp,Bp=pp,VC=gp,qC=xp,KC=vp,zp=wp,GC=Cp,Hp=Ep,Up=Np,YC=Ap,XC=jp,Wp=Rp,Vp=Pp,qp=Mp;const Kp=WC,Gp=VC,ll=m.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(Bp,{ref:r,className:Z("flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",e),...n,children:[t,c.jsx(qC,{asChild:!0,children:c.jsx(oe.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));ll.displayName=Bp.displayName;const Yp=m.forwardRef(({className:e,...t},n)=>c.jsx(Wp,{ref:n,className:Z("flex cursor-default items-center justify-center py-1",e),...t,children:c.jsx(oe.ChevronUp,{className:"h-4 w-4"})}));Yp.displayName=Wp.displayName;const Xp=m.forwardRef(({className:e,...t},n)=>c.jsx(Vp,{ref:n,className:Z("flex cursor-default items-center justify-center py-1",e),...t,children:c.jsx(oe.ChevronDown,{className:"h-4 w-4"})}));Xp.displayName=Vp.displayName;const cl=m.forwardRef(({className:e,children:t,position:n="popper",...r},o)=>c.jsx(KC,{children:c.jsxs(zp,{ref:o,className:Z("relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",n==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",e),position:n,...r,children:[c.jsx(Yp,{}),c.jsx(GC,{className:Z("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),c.jsx(Xp,{})]})}));cl.displayName=zp.displayName;const JC=m.forwardRef(({className:e,...t},n)=>c.jsx(Hp,{ref:n,className:Z("py-1.5 pl-8 pr-2 text-sm font-semibold",e),...t}));JC.displayName=Hp.displayName;const pr=m.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(Up,{ref:r,className:Z("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[c.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:c.jsx(XC,{children:c.jsx(oe.Check,{className:"h-4 w-4"})})}),c.jsx(YC,{children:t})]}));pr.displayName=Up.displayName;const ZC=m.forwardRef(({className:e,...t},n)=>c.jsx(qp,{ref:n,className:Z("-mx-1 my-1 h-px bg-muted",e),...t}));ZC.displayName=qp.displayName;var QC="Separator",Jp="horizontal",eT=["horizontal","vertical"],Zp=m.forwardRef((e,t)=>{const{decorative:n,orientation:r=Jp,...o}=e,s=tT(r)?r:Jp,a=n?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return c.jsx(_e.div,{"data-orientation":s,...a,...o,ref:t})});Zp.displayName=QC;function tT(e){return eT.includes(e)}var Qp=Zp;const em=m.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},o)=>c.jsx(Qp,{ref:o,decorative:n,orientation:t,className:Z("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));em.displayName=Qp.displayName;const nT=Dd,rT=Db,oT=Ld,tm=m.forwardRef(({className:e,...t},n)=>c.jsx(ws,{className:Z("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}));tm.displayName=ws.displayName;const sT=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"}}),nm=m.forwardRef(({side:e="right",className:t,children:n,...r},o)=>c.jsxs(oT,{children:[c.jsx(tm,{}),c.jsxs(bs,{ref:o,className:Z(sT({side:e}),t),...r,children:[n,c.jsxs(Fd,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-secondary",children:[c.jsx(oe.X,{className:"h-4 w-4"}),c.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));nm.displayName=bs.displayName;const rm=({className:e,...t})=>c.jsx("div",{className:Z("flex flex-col space-y-2 text-center sm:text-left",e),...t});rm.displayName="SheetHeader";const om=m.forwardRef(({className:e,...t},n)=>c.jsx(ar,{ref:n,className:Z("text-lg font-semibold text-foreground",e),...t}));om.displayName=ar.displayName;const sm=m.forwardRef(({className:e,...t},n)=>c.jsx(ys,{ref:n,className:Z("text-sm text-muted-foreground",e),...t}));sm.displayName=ys.displayName;const iT={api:{baseUrl:"http://localhost:8000/api",authToken:"",enableAuth:!1},ui:{layout:"sidebar",theme:"light",showTimestamps:!0,showAgentNames:!0,compactMessages:!1},behavior:{autoSave:!0,enableStreaming:!0,showTypingIndicator:!0}};function aT({settings:e,onSettingsChange:t,className:n=""}){const[r,o]=y.useState(!1),[s,i]=y.useState(!1),[a,l]=y.useState(e),[u,d]=y.useState(!1),{toast:f}=la();y.useEffect(()=>{const g=JSON.stringify(a)!==JSON.stringify(e);d(g)},[a,e]),y.useEffect(()=>{l(e)},[e]);const h=()=>{t(a),d(!1),f({title:"Settings saved",description:"Your chat configuration has been updated successfully."})},p=()=>{l(iT),d(!0),f({title:"Settings reset",description:"Configuration has been reset to defaults."})},w=()=>{l(e),d(!1),o(!1)},x=async()=>{try{const v=await(await fetch(`${a.api.baseUrl}/health`)).json();f({title:"Connection successful",description:`API is ${v.status||"healthy"}`})}catch{f({title:"Connection failed",description:"Unable to connect to the API endpoint.",variant:"destructive"})}};return c.jsxs(nT,{open:r,onOpenChange:o,children:[c.jsx(rT,{asChild:!0,children:c.jsxs(Ge,{variant:"outline",size:"sm",className:n,children:[c.jsx(oe.Settings,{className:"h-4 w-4 mr-2"}),"Settings",u&&c.jsx(Zi,{variant:"destructive",className:"ml-2 h-4 w-4 p-0"})]})}),c.jsxs(nm,{className:"w-[500px] sm:w-[600px] overflow-y-auto",children:[c.jsxs(rm,{children:[c.jsx(om,{children:"Chat Settings"}),c.jsx(sm,{children:"Configure your chat interface, API connection, and behavior preferences."})]}),c.jsxs("div",{className:"space-y-6 py-6",children:[c.jsxs(ro,{children:[c.jsx(oo,{className:"pb-3",children:c.jsxs(so,{className:"text-lg flex items-center gap-2",children:[c.jsx(oe.Server,{className:"h-5 w-5"}),"API Configuration"]})}),c.jsxs(Qo,{className:"space-y-4",children:[c.jsxs("div",{className:"space-y-2",children:[c.jsx(Jt,{htmlFor:"api-url",children:"API Base URL"}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx(Hs,{id:"api-url",value:a.api.baseUrl,onChange:g=>l(v=>({...v,api:{...v.api,baseUrl:g.target.value}})),placeholder:"http://localhost:8000/api"}),c.jsx(Ge,{variant:"outline",onClick:x,children:"Test"})]})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx(Jt,{htmlFor:"enable-auth",children:"Enable Authentication"}),c.jsx(Un,{id:"enable-auth",checked:a.api.enableAuth,onCheckedChange:g=>l(v=>({...v,api:{...v.api,enableAuth:g}}))})]}),a.api.enableAuth&&c.jsxs("div",{className:"space-y-2",children:[c.jsx(Jt,{htmlFor:"auth-token",children:"Authentication Token"}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx(Hs,{id:"auth-token",type:s?"text":"password",value:a.api.authToken,onChange:g=>l(v=>({...v,api:{...v.api,authToken:g.target.value}})),placeholder:"Enter your Bearer token"}),c.jsx(Ge,{variant:"outline",size:"icon",onClick:()=>i(!s),children:s?c.jsx(oe.EyeOff,{className:"h-4 w-4"}):c.jsx(oe.Eye,{className:"h-4 w-4"})})]})]})]})]}),c.jsxs(ro,{children:[c.jsx(oo,{className:"pb-3",children:c.jsxs(so,{className:"text-lg flex items-center gap-2",children:[c.jsx(oe.Layout,{className:"h-5 w-5"}),"Interface Settings"]})}),c.jsxs(Qo,{className:"space-y-4",children:[c.jsxs("div",{className:"space-y-2",children:[c.jsx(Jt,{htmlFor:"layout",children:"Layout Style"}),c.jsxs(Kp,{value:a.ui.layout,onValueChange:g=>l(v=>({...v,ui:{...v.ui,layout:g}})),children:[c.jsx(ll,{children:c.jsx(Gp,{})}),c.jsxs(cl,{children:[c.jsx(pr,{value:"sidebar",children:"Sidebar Layout"}),c.jsx(pr,{value:"fullscreen",children:"Fullscreen"}),c.jsx(pr,{value:"tabs",children:"Tabbed Interface"})]})]})]}),c.jsxs("div",{className:"space-y-2",children:[c.jsx(Jt,{htmlFor:"theme",children:"Theme"}),c.jsxs(Kp,{value:a.ui.theme,onValueChange:g=>l(v=>({...v,ui:{...v.ui,theme:g}})),children:[c.jsx(ll,{children:c.jsx(Gp,{})}),c.jsxs(cl,{children:[c.jsx(pr,{value:"light",children:"Light"}),c.jsx(pr,{value:"dark",children:"Dark"}),c.jsx(pr,{value:"system",children:"System"})]})]})]}),c.jsx(em,{}),c.jsxs("div",{className:"space-y-3",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx(Jt,{htmlFor:"show-timestamps",children:"Show Timestamps"}),c.jsx(Un,{id:"show-timestamps",checked:a.ui.showTimestamps,onCheckedChange:g=>l(v=>({...v,ui:{...v.ui,showTimestamps:g}}))})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx(Jt,{htmlFor:"show-agent-names",children:"Show Agent Names"}),c.jsx(Un,{id:"show-agent-names",checked:a.ui.showAgentNames,onCheckedChange:g=>l(v=>({...v,ui:{...v.ui,showAgentNames:g}}))})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx(Jt,{htmlFor:"compact-messages",children:"Compact Messages"}),c.jsx(Un,{id:"compact-messages",checked:a.ui.compactMessages,onCheckedChange:g=>l(v=>({...v,ui:{...v.ui,compactMessages:g}}))})]})]})]})]}),c.jsxs(ro,{children:[c.jsx(oo,{className:"pb-3",children:c.jsxs(so,{className:"text-lg flex items-center gap-2",children:[c.jsx(oe.MessageCircle,{className:"h-5 w-5"}),"Behavior Settings"]})}),c.jsxs(Qo,{className:"space-y-4",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx(Jt,{htmlFor:"auto-save",children:"Auto-save Conversations"}),c.jsx("p",{className:"text-sm text-muted-foreground",children:"Automatically save messages to threads"})]}),c.jsx(Un,{id:"auto-save",checked:a.behavior.autoSave,onCheckedChange:g=>l(v=>({...v,behavior:{...v.behavior,autoSave:g}}))})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx(Jt,{htmlFor:"enable-streaming",children:"Enable Streaming"}),c.jsx("p",{className:"text-sm text-muted-foreground",children:"Stream responses in real-time"})]}),c.jsx(Un,{id:"enable-streaming",checked:a.behavior.enableStreaming,onCheckedChange:g=>l(v=>({...v,behavior:{...v.behavior,enableStreaming:g}}))})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx(Jt,{htmlFor:"typing-indicator",children:"Typing Indicator"}),c.jsx("p",{className:"text-sm text-muted-foreground",children:"Show typing indicator during responses"})]}),c.jsx(Un,{id:"typing-indicator",checked:a.behavior.showTypingIndicator,onCheckedChange:g=>l(v=>({...v,behavior:{...v.behavior,showTypingIndicator:g}}))})]})]})]})]}),c.jsxs("div",{className:"flex items-center justify-between pt-6 border-t",children:[c.jsxs(Ge,{variant:"outline",onClick:p,children:[c.jsx(oe.RotateCcw,{className:"h-4 w-4 mr-2"}),"Reset"]}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx(Ge,{variant:"outline",onClick:w,children:"Cancel"}),c.jsxs(Ge,{onClick:h,disabled:!u,children:[c.jsx(oe.Save,{className:"h-4 w-4 mr-2"}),"Save Changes"]})]})]})]})]})}function lT({layout:e="sidebar",layoutSize:t="desktop",showThreads:n=!0,className:r="",customStyles:o={},...s}){const i=u=>{const d="h-full";switch(u){case"phone":return`${d} max-w-none`;case"tablet":return`${d} max-w-4xl mx-auto`;case"half-screen":return`${d} max-w-2xl`;case"desktop":default:return`${d} max-w-7xl mx-auto`}},a=u=>({"--chat-sidebar-width":u==="phone"?"100%":u==="tablet"?"280px":u==="half-screen"?"240px":"320px","--chat-message-max-width":u==="phone"?"95%":u==="tablet"?"90%":u==="half-screen"?"85%":"80%","--chat-input-height":u==="phone"?"120px":"100px"}),l=y.useCallback(u=>{var d;(d=s.onThreadChange)==null||d.call(s,u)},[s]);return e==="fullscreen"?c.jsx(Lo,{...s,onThreadChange:l,children:c.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:c.jsx(zs,{className:"flex-1",onError:s.onError,enableFileUpload:!0})})}):e==="tabs"?c.jsx(Lo,{...s,onThreadChange:l,children:c.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:c.jsxs("div",{className:"flex-1 flex min-h-0 overflow-hidden",children:[n&&c.jsx("div",{className:`w-80 border-r flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:c.jsx(tl,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),c.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:c.jsx(zs,{onError:s.onError,enableFileUpload:!0})})]})})}):c.jsx(Lo,{...s,onThreadChange:l,children:c.jsxs("div",{className:`${i(t)} flex overflow-hidden ${r} ${o.container||""}`,style:a(t),children:[n&&c.jsx("div",{className:`w-80 border-r bg-gray-50 flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:c.jsx(tl,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),c.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:c.jsx(zs,{onError:s.onError,enableFileUpload:!0})})]})})}je.ChatApi=sc,je.ChatInterface=zs,je.ChatProviders=Lo,je.ChatSettings=aT,je.MarkdownContent=sa,je.MessageComponent=Kd,je.MessageList=Ta,je.ThreadManager=tl,je.applySettings=hC,je.chatApiClient=Pn,je.default=lT,je.del=oc,je.get=nn,je.getChatToken=tc,je.getCurrentSettings=fC,je.getDefaultApiConfig=Qh,je.getDefaultChatSettings=ep,je.onChatTokenChanged=nc,je.post=gi,je.put=rc,je.setChatToken=mi,je.useApi=xi,je.useChatStream=bc,je.useMessagesReducer=dc,je.useStream=Ec,je.useThreadState=Do,je.useThreads=Mo,Object.defineProperties(je,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
140
|
+
`).trim():n.replace(/</g,"<").replace(/>/g,">").trim()}function ly(e,t=Ns){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 cy(e){let t;return typeof e=="string"?t=e:typeof e=="object"&&e!==null?t=JSON.stringify(e):t=String(e),ly(t),ay(t)}function _a(e){const t=e+"CollectionProvider",[n,r]=wn(t),[o,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),i=x=>{const{scope:g,children:v}=x,w=y.useRef(null),S=y.useRef(new Map).current;return c.jsx(o,{scope:g,itemMap:S,collectionRef:w,children:v})};i.displayName=t;const a=e+"CollectionSlot",l=Jn.createSlot(a),u=y.forwardRef((x,g)=>{const{scope:v,children:w}=x,S=s(a,v),N=Ke(g,S.collectionRef);return c.jsx(l,{ref:N,children:w})});u.displayName=a;const d=e+"CollectionItemSlot",f="data-radix-collection-item",h=Jn.createSlot(d),p=y.forwardRef((x,g)=>{const{scope:v,children:w,...S}=x,N=y.useRef(null),T=Ke(g,N),k=s(d,v);return y.useEffect(()=>(k.itemMap.set(N,{ref:N,...S}),()=>void k.itemMap.delete(N))),c.jsx(h,{[f]:"",ref:T,children:w})});p.displayName=d;function b(x){const g=s(e+"CollectionConsumer",x);return y.useCallback(()=>{const w=g.collectionRef.current;if(!w)return[];const S=Array.from(w.querySelectorAll(`[${f}]`));return Array.from(g.itemMap.values()).sort((k,E)=>S.indexOf(k.ref.current)-S.indexOf(E.ref.current))},[g.collectionRef,g.itemMap])}return[{Provider:i,Slot:u,ItemSlot:p},b,r]}var uy=m.createContext(void 0);function As(e){const t=m.useContext(uy);return e||t||"ltr"}const dy=["top","right","bottom","left"],Un=Math.min,Vt=Math.max,_s=Math.round,js=Math.floor,Cn=e=>({x:e,y:e}),fy={left:"right",right:"left",bottom:"top",top:"bottom"},hy={start:"end",end:"start"};function ja(e,t,n){return Vt(e,Un(t,n))}function jn(e,t){return typeof e=="function"?e(t):e}function Rn(e){return e.split("-")[0]}function Pr(e){return e.split("-")[1]}function Ra(e){return e==="x"?"y":"x"}function Pa(e){return e==="y"?"height":"width"}const py=new Set(["top","bottom"]);function Tn(e){return py.has(Rn(e))?"y":"x"}function Oa(e){return Ra(Tn(e))}function my(e,t,n){n===void 0&&(n=!1);const r=Pr(e),o=Oa(e),s=Pa(o);let i=o==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(i=Rs(i)),[i,Rs(i)]}function gy(e){const t=Rs(e);return[Ma(e),t,Ma(t)]}function Ma(e){return e.replace(/start|end/g,t=>hy[t])}const ef=["left","right"],tf=["right","left"],xy=["top","bottom"],vy=["bottom","top"];function by(e,t,n){switch(e){case"top":case"bottom":return n?t?tf:ef:t?ef:tf;case"left":case"right":return t?xy:vy;default:return[]}}function wy(e,t,n,r){const o=Pr(e);let s=by(Rn(e),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(Ma)))),s}function Rs(e){return e.replace(/left|right|bottom|top/g,t=>fy[t])}function yy(e){return{top:0,right:0,bottom:0,left:0,...e}}function nf(e){return typeof e!="number"?yy(e):{top:e,right:e,bottom:e,left:e}}function Ps(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 rf(e,t,n){let{reference:r,floating:o}=e;const s=Tn(t),i=Oa(t),a=Pa(i),l=Rn(t),u=s==="y",d=r.x+r.width/2-o.width/2,f=r.y+r.height/2-o.height/2,h=r[a]/2-o[a]/2;let p;switch(l){case"top":p={x:d,y:r.y-o.height};break;case"bottom":p={x:d,y:r.y+r.height};break;case"right":p={x:r.x+r.width,y:f};break;case"left":p={x:r.x-o.width,y:f};break;default:p={x:r.x,y:r.y}}switch(Pr(t)){case"start":p[i]-=h*(n&&u?-1:1);break;case"end":p[i]+=h*(n&&u?-1:1);break}return p}const Sy=async(e,t,n)=>{const{placement:r="bottom",strategy:o="absolute",middleware:s=[],platform:i}=n,a=s.filter(Boolean),l=await(i.isRTL==null?void 0:i.isRTL(t));let u=await i.getElementRects({reference:e,floating:t,strategy:o}),{x:d,y:f}=rf(u,r,l),h=r,p={},b=0;for(let x=0;x<a.length;x++){const{name:g,fn:v}=a[x],{x:w,y:S,data:N,reset:T}=await v({x:d,y:f,initialPlacement:r,placement:h,strategy:o,middlewareData:p,rects:u,platform:i,elements:{reference:e,floating:t}});d=w??d,f=S??f,p={...p,[g]:{...p[g],...N}},T&&b<=50&&(b++,typeof T=="object"&&(T.placement&&(h=T.placement),T.rects&&(u=T.rects===!0?await i.getElementRects({reference:e,floating:t,strategy:o}):T.rects),{x:d,y:f}=rf(u,h,l)),x=-1)}return{x:d,y:f,placement:h,strategy:o,middlewareData:p}};async function fo(e,t){var n;t===void 0&&(t={});const{x:r,y:o,platform:s,rects:i,elements:a,strategy:l}=e,{boundary:u="clippingAncestors",rootBoundary:d="viewport",elementContext:f="floating",altBoundary:h=!1,padding:p=0}=jn(t,e),b=nf(p),g=a[h?f==="floating"?"reference":"floating":f],v=Ps(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(g)))==null||n?g:g.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(a.floating)),boundary:u,rootBoundary:d,strategy:l})),w=f==="floating"?{x:r,y:o,width:i.floating.width,height:i.floating.height}:i.reference,S=await(s.getOffsetParent==null?void 0:s.getOffsetParent(a.floating)),N=await(s.isElement==null?void 0:s.isElement(S))?await(s.getScale==null?void 0:s.getScale(S))||{x:1,y:1}:{x:1,y:1},T=Ps(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:w,offsetParent:S,strategy:l}):w);return{top:(v.top-T.top+b.top)/N.y,bottom:(T.bottom-v.bottom+b.bottom)/N.y,left:(v.left-T.left+b.left)/N.x,right:(T.right-v.right+b.right)/N.x}}const Cy=e=>({name:"arrow",options:e,async fn(t){const{x:n,y:r,placement:o,rects:s,platform:i,elements:a,middlewareData:l}=t,{element:u,padding:d=0}=jn(e,t)||{};if(u==null)return{};const f=nf(d),h={x:n,y:r},p=Oa(o),b=Pa(p),x=await i.getDimensions(u),g=p==="y",v=g?"top":"left",w=g?"bottom":"right",S=g?"clientHeight":"clientWidth",N=s.reference[b]+s.reference[p]-h[p]-s.floating[b],T=h[p]-s.reference[p],k=await(i.getOffsetParent==null?void 0:i.getOffsetParent(u));let E=k?k[S]:0;(!E||!await(i.isElement==null?void 0:i.isElement(k)))&&(E=a.floating[S]||s.floating[b]);const A=N/2-T/2,j=E/2-x[b]/2-1,P=Un(f[v],j),L=Un(f[w],j),$=P,V=E-x[b]-L,M=E/2-x[b]/2+A,G=ja($,M,V),K=!l.arrow&&Pr(o)!=null&&M!==G&&s.reference[b]/2-(M<$?P:L)-x[b]/2<0,W=K?M<$?M-$:M-V:0;return{[p]:h[p]+W,data:{[p]:G,centerOffset:M-G-W,...K&&{alignmentOffset:W}},reset:K}}}),Ty=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(t){var n,r;const{placement:o,middlewareData:s,rects:i,initialPlacement:a,platform:l,elements:u}=t,{mainAxis:d=!0,crossAxis:f=!0,fallbackPlacements:h,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:b="none",flipAlignment:x=!0,...g}=jn(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const v=Rn(o),w=Tn(a),S=Rn(a)===a,N=await(l.isRTL==null?void 0:l.isRTL(u.floating)),T=h||(S||!x?[Rs(a)]:gy(a)),k=b!=="none";!h&&k&&T.push(...wy(a,x,b,N));const E=[a,...T],A=await fo(t,g),j=[];let P=((r=s.flip)==null?void 0:r.overflows)||[];if(d&&j.push(A[v]),f){const M=my(o,i,N);j.push(A[M[0]],A[M[1]])}if(P=[...P,{placement:o,overflows:j}],!j.every(M=>M<=0)){var L,$;const M=(((L=s.flip)==null?void 0:L.index)||0)+1,G=E[M];if(G&&(!(f==="alignment"?w!==Tn(G):!1)||P.every(B=>Tn(B.placement)===w?B.overflows[0]>0:!0)))return{data:{index:M,overflows:P},reset:{placement:G}};let K=($=P.filter(W=>W.overflows[0]<=0).sort((W,B)=>W.overflows[1]-B.overflows[1])[0])==null?void 0:$.placement;if(!K)switch(p){case"bestFit":{var V;const W=(V=P.filter(B=>{if(k){const F=Tn(B.placement);return F===w||F==="y"}return!0}).map(B=>[B.placement,B.overflows.filter(F=>F>0).reduce((F,ue)=>F+ue,0)]).sort((B,F)=>B[1]-F[1])[0])==null?void 0:V[0];W&&(K=W);break}case"initialPlacement":K=a;break}if(o!==K)return{reset:{placement:K}}}return{}}}};function of(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function sf(e){return dy.some(t=>e[t]>=0)}const ky=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n}=t,{strategy:r="referenceHidden",...o}=jn(e,t);switch(r){case"referenceHidden":{const s=await fo(t,{...o,elementContext:"reference"}),i=of(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:sf(i)}}}case"escaped":{const s=await fo(t,{...o,altBoundary:!0}),i=of(s,n.floating);return{data:{escapedOffsets:i,escaped:sf(i)}}}default:return{}}}}},af=new Set(["left","top"]);async function Iy(e,t){const{placement:n,platform:r,elements:o}=e,s=await(r.isRTL==null?void 0:r.isRTL(o.floating)),i=Rn(n),a=Pr(n),l=Tn(n)==="y",u=af.has(i)?-1:1,d=s&&l?-1:1,f=jn(t,e);let{mainAxis:h,crossAxis:p,alignmentAxis:b}=typeof f=="number"?{mainAxis:f,crossAxis:0,alignmentAxis:null}:{mainAxis:f.mainAxis||0,crossAxis:f.crossAxis||0,alignmentAxis:f.alignmentAxis};return a&&typeof b=="number"&&(p=a==="end"?b*-1:b),l?{x:p*d,y:h*u}:{x:h*u,y:p*d}}const Ey=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 Iy(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}}}}},Ny=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(t){const{x:n,y:r,placement:o}=t,{mainAxis:s=!0,crossAxis:i=!1,limiter:a={fn:g=>{let{x:v,y:w}=g;return{x:v,y:w}}},...l}=jn(e,t),u={x:n,y:r},d=await fo(t,l),f=Tn(Rn(o)),h=Ra(f);let p=u[h],b=u[f];if(s){const g=h==="y"?"top":"left",v=h==="y"?"bottom":"right",w=p+d[g],S=p-d[v];p=ja(w,p,S)}if(i){const g=f==="y"?"top":"left",v=f==="y"?"bottom":"right",w=b+d[g],S=b-d[v];b=ja(w,b,S)}const x=a.fn({...t,[h]:p,[f]:b});return{...x,data:{x:x.x-n,y:x.y-r,enabled:{[h]:s,[f]:i}}}}}},Ay=function(e){return e===void 0&&(e={}),{options:e,fn(t){const{x:n,y:r,placement:o,rects:s,middlewareData:i}=t,{offset:a=0,mainAxis:l=!0,crossAxis:u=!0}=jn(e,t),d={x:n,y:r},f=Tn(o),h=Ra(f);let p=d[h],b=d[f];const x=jn(a,t),g=typeof x=="number"?{mainAxis:x,crossAxis:0}:{mainAxis:0,crossAxis:0,...x};if(l){const S=h==="y"?"height":"width",N=s.reference[h]-s.floating[S]+g.mainAxis,T=s.reference[h]+s.reference[S]-g.mainAxis;p<N?p=N:p>T&&(p=T)}if(u){var v,w;const S=h==="y"?"width":"height",N=af.has(Rn(o)),T=s.reference[f]-s.floating[S]+(N&&((v=i.offset)==null?void 0:v[f])||0)+(N?0:g.crossAxis),k=s.reference[f]+s.reference[S]+(N?0:((w=i.offset)==null?void 0:w[f])||0)-(N?g.crossAxis:0);b<T?b=T:b>k&&(b=k)}return{[h]:p,[f]:b}}}},_y=function(e){return e===void 0&&(e={}),{name:"size",options:e,async fn(t){var n,r;const{placement:o,rects:s,platform:i,elements:a}=t,{apply:l=()=>{},...u}=jn(e,t),d=await fo(t,u),f=Rn(o),h=Pr(o),p=Tn(o)==="y",{width:b,height:x}=s.floating;let g,v;f==="top"||f==="bottom"?(g=f,v=h===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(v=f,g=h==="end"?"top":"bottom");const w=x-d.top-d.bottom,S=b-d.left-d.right,N=Un(x-d[g],w),T=Un(b-d[v],S),k=!t.middlewareData.shift;let E=N,A=T;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(A=S),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(E=w),k&&!h){const P=Vt(d.left,0),L=Vt(d.right,0),$=Vt(d.top,0),V=Vt(d.bottom,0);p?A=b-2*(P!==0||L!==0?P+L:Vt(d.left,d.right)):E=x-2*($!==0||V!==0?$+V:Vt(d.top,d.bottom))}await l({...t,availableWidth:A,availableHeight:E});const j=await i.getDimensions(a.floating);return b!==j.width||x!==j.height?{reset:{rects:!0}}:{}}}};function Os(){return typeof window<"u"}function Or(e){return lf(e)?(e.nodeName||"").toLowerCase():"#document"}function Kt(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function kn(e){var t;return(t=(lf(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function lf(e){return Os()?e instanceof Node||e instanceof Kt(e).Node:!1}function un(e){return Os()?e instanceof Element||e instanceof Kt(e).Element:!1}function In(e){return Os()?e instanceof HTMLElement||e instanceof Kt(e).HTMLElement:!1}function cf(e){return!Os()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Kt(e).ShadowRoot}const jy=new Set(["inline","contents"]);function ho(e){const{overflow:t,overflowX:n,overflowY:r,display:o}=dn(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!jy.has(o)}const Ry=new Set(["table","td","th"]);function Py(e){return Ry.has(Or(e))}const Oy=[":popover-open",":modal"];function Ms(e){return Oy.some(t=>{try{return e.matches(t)}catch{return!1}})}const My=["transform","translate","scale","rotate","perspective"],Dy=["transform","translate","scale","rotate","perspective","filter"],Ly=["paint","layout","strict","content"];function Da(e){const t=La(),n=un(e)?dn(e):e;return My.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)||Dy.some(r=>(n.willChange||"").includes(r))||Ly.some(r=>(n.contain||"").includes(r))}function $y(e){let t=Wn(e);for(;In(t)&&!Mr(t);){if(Da(t))return t;if(Ms(t))return null;t=Wn(t)}return null}function La(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const Fy=new Set(["html","body","#document"]);function Mr(e){return Fy.has(Or(e))}function dn(e){return Kt(e).getComputedStyle(e)}function Ds(e){return un(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Wn(e){if(Or(e)==="html")return e;const t=e.assignedSlot||e.parentNode||cf(e)&&e.host||kn(e);return cf(t)?t.host:t}function uf(e){const t=Wn(e);return Mr(t)?e.ownerDocument?e.ownerDocument.body:e.body:In(t)&&ho(t)?t:uf(t)}function po(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const o=uf(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=Kt(o);if(s){const a=$a(i);return t.concat(i,i.visualViewport||[],ho(o)?o:[],a&&n?po(a):[])}return t.concat(o,po(o,[],n))}function $a(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function df(e){const t=dn(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const o=In(e),s=o?e.offsetWidth:n,i=o?e.offsetHeight:r,a=_s(n)!==s||_s(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function Fa(e){return un(e)?e:e.contextElement}function Dr(e){const t=Fa(e);if(!In(t))return Cn(1);const n=t.getBoundingClientRect(),{width:r,height:o,$:s}=df(t);let i=(s?_s(n.width):n.width)/r,a=(s?_s(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const By=Cn(0);function ff(e){const t=Kt(e);return!La()||!t.visualViewport?By:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function zy(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==Kt(e)?!1:t}function ur(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const o=e.getBoundingClientRect(),s=Fa(e);let i=Cn(1);t&&(r?un(r)&&(i=Dr(r)):i=Dr(e));const a=zy(s,n,r)?ff(s):Cn(0);let l=(o.left+a.x)/i.x,u=(o.top+a.y)/i.y,d=o.width/i.x,f=o.height/i.y;if(s){const h=Kt(s),p=r&&un(r)?Kt(r):r;let b=h,x=$a(b);for(;x&&r&&p!==b;){const g=Dr(x),v=x.getBoundingClientRect(),w=dn(x),S=v.left+(x.clientLeft+parseFloat(w.paddingLeft))*g.x,N=v.top+(x.clientTop+parseFloat(w.paddingTop))*g.y;l*=g.x,u*=g.y,d*=g.x,f*=g.y,l+=S,u+=N,b=Kt(x),x=$a(b)}}return Ps({width:d,height:f,x:l,y:u})}function Ls(e,t){const n=Ds(e).scrollLeft;return t?t.left+n:ur(kn(e)).left+n}function hf(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-Ls(e,n),o=n.top+t.scrollTop;return{x:r,y:o}}function Hy(e){let{elements:t,rect:n,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=kn(r),a=t?Ms(t.floating):!1;if(r===i||a&&s)return n;let l={scrollLeft:0,scrollTop:0},u=Cn(1);const d=Cn(0),f=In(r);if((f||!f&&!s)&&((Or(r)!=="body"||ho(i))&&(l=Ds(r)),In(r))){const p=ur(r);u=Dr(r),d.x=p.x+r.clientLeft,d.y=p.y+r.clientTop}const h=i&&!f&&!s?hf(i,l):Cn(0);return{width:n.width*u.x,height:n.height*u.y,x:n.x*u.x-l.scrollLeft*u.x+d.x+h.x,y:n.y*u.y-l.scrollTop*u.y+d.y+h.y}}function Uy(e){return Array.from(e.getClientRects())}function Wy(e){const t=kn(e),n=Ds(e),r=e.ownerDocument.body,o=Vt(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=Vt(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let i=-n.scrollLeft+Ls(e);const a=-n.scrollTop;return dn(r).direction==="rtl"&&(i+=Vt(t.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}const pf=25;function Vy(e,t){const n=Kt(e),r=kn(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=La();(!d||d&&t==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}const u=Ls(r);if(u<=0){const d=r.ownerDocument,f=d.body,h=getComputedStyle(f),p=d.compatMode==="CSS1Compat"&&parseFloat(h.marginLeft)+parseFloat(h.marginRight)||0,b=Math.abs(r.clientWidth-f.clientWidth-p);b<=pf&&(s-=b)}else u<=pf&&(s+=u);return{width:s,height:i,x:a,y:l}}const Ky=new Set(["absolute","fixed"]);function qy(e,t){const n=ur(e,!0,t==="fixed"),r=n.top+e.clientTop,o=n.left+e.clientLeft,s=In(e)?Dr(e):Cn(1),i=e.clientWidth*s.x,a=e.clientHeight*s.y,l=o*s.x,u=r*s.y;return{width:i,height:a,x:l,y:u}}function mf(e,t,n){let r;if(t==="viewport")r=Vy(e,n);else if(t==="document")r=Wy(kn(e));else if(un(t))r=qy(t,n);else{const o=ff(e);r={x:t.x-o.x,y:t.y-o.y,width:t.width,height:t.height}}return Ps(r)}function gf(e,t){const n=Wn(e);return n===t||!un(n)||Mr(n)?!1:dn(n).position==="fixed"||gf(n,t)}function Gy(e,t){const n=t.get(e);if(n)return n;let r=po(e,[],!1).filter(a=>un(a)&&Or(a)!=="body"),o=null;const s=dn(e).position==="fixed";let i=s?Wn(e):e;for(;un(i)&&!Mr(i);){const a=dn(i),l=Da(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&Ky.has(o.position)||ho(i)&&!l&&gf(e,i))?r=r.filter(d=>d!==i):o=a,i=Wn(i)}return t.set(e,r),r}function Yy(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i=[...n==="clippingAncestors"?Ms(t)?[]:Gy(t,this._c):[].concat(n),r],a=i[0],l=i.reduce((u,d)=>{const f=mf(t,d,o);return u.top=Vt(f.top,u.top),u.right=Un(f.right,u.right),u.bottom=Un(f.bottom,u.bottom),u.left=Vt(f.left,u.left),u},mf(t,a,o));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function Xy(e){const{width:t,height:n}=df(e);return{width:t,height:n}}function Jy(e,t,n){const r=In(t),o=kn(t),s=n==="fixed",i=ur(e,!0,s,t);let a={scrollLeft:0,scrollTop:0};const l=Cn(0);function u(){l.x=Ls(o)}if(r||!r&&!s)if((Or(t)!=="body"||ho(o))&&(a=Ds(t)),r){const p=ur(t,!0,s,t);l.x=p.x+t.clientLeft,l.y=p.y+t.clientTop}else o&&u();s&&!r&&o&&u();const d=o&&!r&&!s?hf(o,a):Cn(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 Ba(e){return dn(e).position==="static"}function xf(e,t){if(!In(e)||dn(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return kn(e)===n&&(n=n.ownerDocument.body),n}function vf(e,t){const n=Kt(e);if(Ms(e))return n;if(!In(e)){let o=Wn(e);for(;o&&!Mr(o);){if(un(o)&&!Ba(o))return o;o=Wn(o)}return n}let r=xf(e,t);for(;r&&Py(r)&&Ba(r);)r=xf(r,t);return r&&Mr(r)&&Ba(r)&&!Da(r)?n:r||$y(e)||n}const Zy=async function(e){const t=this.getOffsetParent||vf,n=this.getDimensions,r=await n(e.floating);return{reference:Jy(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function Qy(e){return dn(e).direction==="rtl"}const e0={convertOffsetParentRelativeRectToViewportRelativeRect:Hy,getDocumentElement:kn,getClippingRect:Yy,getOffsetParent:vf,getElementRects:Zy,getClientRects:Uy,getDimensions:Xy,getScale:Dr,isElement:un,isRTL:Qy};function bf(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function t0(e,t){let n=null,r;const o=kn(e);function s(){var a;clearTimeout(r),(a=n)==null||a.disconnect(),n=null}function i(a,l){a===void 0&&(a=!1),l===void 0&&(l=1),s();const u=e.getBoundingClientRect(),{left:d,top:f,width:h,height:p}=u;if(a||t(),!h||!p)return;const b=js(f),x=js(o.clientWidth-(d+h)),g=js(o.clientHeight-(f+p)),v=js(d),S={rootMargin:-b+"px "+-x+"px "+-g+"px "+-v+"px",threshold:Vt(0,Un(1,l))||1};let N=!0;function T(k){const E=k[0].intersectionRatio;if(E!==l){if(!N)return i();E?i(!1,E):r=setTimeout(()=>{i(!1,1e-7)},1e3)}E===1&&!bf(u,e.getBoundingClientRect())&&i(),N=!1}try{n=new IntersectionObserver(T,{...S,root:o.ownerDocument})}catch{n=new IntersectionObserver(T,S)}n.observe(e)}return i(!0),s}function n0(e,t,n,r){r===void 0&&(r={});const{ancestorScroll:o=!0,ancestorResize:s=!0,elementResize:i=typeof ResizeObserver=="function",layoutShift:a=typeof IntersectionObserver=="function",animationFrame:l=!1}=r,u=Fa(e),d=o||s?[...u?po(u):[],...po(t)]:[];d.forEach(v=>{o&&v.addEventListener("scroll",n,{passive:!0}),s&&v.addEventListener("resize",n)});const f=u&&a?t0(u,n):null;let h=-1,p=null;i&&(p=new ResizeObserver(v=>{let[w]=v;w&&w.target===u&&p&&(p.unobserve(t),cancelAnimationFrame(h),h=requestAnimationFrame(()=>{var S;(S=p)==null||S.observe(t)})),n()}),u&&!l&&p.observe(u),p.observe(t));let b,x=l?ur(e):null;l&&g();function g(){const v=ur(e);x&&!bf(x,v)&&n(),x=v,b=requestAnimationFrame(g)}return n(),()=>{var v;d.forEach(w=>{o&&w.removeEventListener("scroll",n),s&&w.removeEventListener("resize",n)}),f==null||f(),(v=p)==null||v.disconnect(),p=null,l&&cancelAnimationFrame(b)}}const r0=Ey,o0=Ny,s0=Ty,i0=_y,a0=ky,wf=Cy,l0=Ay,c0=(e,t,n)=>{const r=new Map,o={platform:e0,...n},s={...o.platform,_c:r};return Sy(e,t,{...o,platform:s})};var u0=typeof document<"u",d0=function(){},$s=u0?y.useLayoutEffect:d0;function Fs(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(!Fs(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)&&!Fs(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function yf(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function Sf(e,t){const n=yf(e);return Math.round(t*n)/n}function za(e){const t=m.useRef(e);return $s(()=>{t.current=e}),t}function f0(e){e===void 0&&(e={});const{placement:t="bottom",strategy:n="absolute",middleware:r=[],platform:o,elements:{reference:s,floating:i}={},transform:a=!0,whileElementsMounted:l,open:u}=e,[d,f]=m.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[h,p]=m.useState(r);Fs(h,r)||p(r);const[b,x]=m.useState(null),[g,v]=m.useState(null),w=m.useCallback(B=>{B!==k.current&&(k.current=B,x(B))},[]),S=m.useCallback(B=>{B!==E.current&&(E.current=B,v(B))},[]),N=s||b,T=i||g,k=m.useRef(null),E=m.useRef(null),A=m.useRef(d),j=l!=null,P=za(l),L=za(o),$=za(u),V=m.useCallback(()=>{if(!k.current||!E.current)return;const B={placement:t,strategy:n,middleware:h};L.current&&(B.platform=L.current),c0(k.current,E.current,B).then(F=>{const ue={...F,isPositioned:$.current!==!1};M.current&&!Fs(A.current,ue)&&(A.current=ue,ko.flushSync(()=>{f(ue)}))})},[h,t,n,L,$]);$s(()=>{u===!1&&A.current.isPositioned&&(A.current.isPositioned=!1,f(B=>({...B,isPositioned:!1})))},[u]);const M=m.useRef(!1);$s(()=>(M.current=!0,()=>{M.current=!1}),[]),$s(()=>{if(N&&(k.current=N),T&&(E.current=T),N&&T){if(P.current)return P.current(N,T,V);V()}},[N,T,V,P,j]);const G=m.useMemo(()=>({reference:k,floating:E,setReference:w,setFloating:S}),[w,S]),K=m.useMemo(()=>({reference:N,floating:T}),[N,T]),W=m.useMemo(()=>{const B={position:n,left:0,top:0};if(!K.floating)return B;const F=Sf(K.floating,d.x),ue=Sf(K.floating,d.y);return a?{...B,transform:"translate("+F+"px, "+ue+"px)",...yf(K.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:F,top:ue}},[n,a,K.floating,d.x,d.y]);return m.useMemo(()=>({...d,update:V,refs:G,elements:K,floatingStyles:W}),[d,V,G,K,W])}const h0=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?wf({element:r.current,padding:o}).fn(n):{}:r?wf({element:r,padding:o}).fn(n):{}}}},p0=(e,t)=>({...r0(e),options:[e,t]}),m0=(e,t)=>({...o0(e),options:[e,t]}),g0=(e,t)=>({...l0(e),options:[e,t]}),x0=(e,t)=>({...s0(e),options:[e,t]}),v0=(e,t)=>({...i0(e),options:[e,t]}),b0=(e,t)=>({...a0(e),options:[e,t]}),w0=(e,t)=>({...h0(e),options:[e,t]});var y0="Arrow",Cf=m.forwardRef((e,t)=>{const{children:n,width:r=10,height:o=5,...s}=e;return c.jsx(_e.svg,{...s,ref:t,width:r,height:o,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:e.asChild?n:c.jsx("polygon",{points:"0,0 30,0 15,10"})})});Cf.displayName=y0;var S0=Cf;function Tf(e){const[t,n]=m.useState(void 0);return St(()=>{if(e){n({width:e.offsetWidth,height:e.offsetHeight});const r=new ResizeObserver(o=>{if(!Array.isArray(o)||!o.length)return;const s=o[0];let i,a;if("borderBoxSize"in s){const l=s.borderBoxSize,u=Array.isArray(l)?l[0]:l;i=u.inlineSize,a=u.blockSize}else i=e.offsetWidth,a=e.offsetHeight;n({width:i,height:a})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else n(void 0)},[e]),t}var Ha="Popper",[kf,Bs]=wn(Ha),[C0,If]=kf(Ha),Ef=e=>{const{__scopePopper:t,children:n}=e,[r,o]=m.useState(null);return c.jsx(C0,{scope:t,anchor:r,onAnchorChange:o,children:n})};Ef.displayName=Ha;var Nf="PopperAnchor",Af=m.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...o}=e,s=If(Nf,n),i=m.useRef(null),a=Ke(t,i),l=m.useRef(null);return m.useEffect(()=>{const u=l.current;l.current=(r==null?void 0:r.current)||i.current,u!==l.current&&s.onAnchorChange(l.current)}),r?null:c.jsx(_e.div,{...o,ref:a})});Af.displayName=Nf;var Ua="PopperContent",[T0,k0]=kf(Ua),_f=m.forwardRef((e,t)=>{var q,O,X,te,he,re;const{__scopePopper:n,side:r="bottom",sideOffset:o=0,align:s="center",alignOffset:i=0,arrowPadding:a=0,avoidCollisions:l=!0,collisionBoundary:u=[],collisionPadding:d=0,sticky:f="partial",hideWhenDetached:h=!1,updatePositionStrategy:p="optimized",onPlaced:b,...x}=e,g=If(Ua,n),[v,w]=m.useState(null),S=Ke(t,pe=>w(pe)),[N,T]=m.useState(null),k=Tf(N),E=(k==null?void 0:k.width)??0,A=(k==null?void 0:k.height)??0,j=r+(s!=="center"?"-"+s:""),P=typeof d=="number"?d:{top:0,right:0,bottom:0,left:0,...d},L=Array.isArray(u)?u:[u],$=L.length>0,V={padding:P,boundary:L.filter(E0),altBoundary:$},{refs:M,floatingStyles:G,placement:K,isPositioned:W,middlewareData:B}=f0({strategy:"fixed",placement:j,whileElementsMounted:(...pe)=>n0(...pe,{animationFrame:p==="always"}),elements:{reference:g.anchor},middleware:[p0({mainAxis:o+A,alignmentAxis:i}),l&&m0({mainAxis:!0,crossAxis:!1,limiter:f==="partial"?g0():void 0,...V}),l&&x0({...V}),v0({...V,apply:({elements:pe,rects:tt,availableWidth:nt,availableHeight:Pe})=>{const{width:He,height:ut}=tt.reference,rt=pe.floating.style;rt.setProperty("--radix-popper-available-width",`${nt}px`),rt.setProperty("--radix-popper-available-height",`${Pe}px`),rt.setProperty("--radix-popper-anchor-width",`${He}px`),rt.setProperty("--radix-popper-anchor-height",`${ut}px`)}}),N&&w0({element:N,padding:a}),N0({arrowWidth:E,arrowHeight:A}),h&&b0({strategy:"referenceHidden",...V})]}),[F,ue]=Pf(K),D=kt(b);St(()=>{W&&(D==null||D())},[W,D]);const ee=(q=B.arrow)==null?void 0:q.x,fe=(O=B.arrow)==null?void 0:O.y,we=((X=B.arrow)==null?void 0:X.centerOffset)!==0,[ye,Ce]=m.useState();return St(()=>{v&&Ce(window.getComputedStyle(v).zIndex)},[v]),c.jsx("div",{ref:M.setFloating,"data-radix-popper-content-wrapper":"",style:{...G,transform:W?G.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:ye,"--radix-popper-transform-origin":[(te=B.transformOrigin)==null?void 0:te.x,(he=B.transformOrigin)==null?void 0:he.y].join(" "),...((re=B.hide)==null?void 0:re.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:c.jsx(T0,{scope:n,placedSide:F,onArrowChange:T,arrowX:ee,arrowY:fe,shouldHideArrow:we,children:c.jsx(_e.div,{"data-side":F,"data-align":ue,...x,ref:S,style:{...x.style,animation:W?void 0:"none"}})})})});_f.displayName=Ua;var jf="PopperArrow",I0={top:"bottom",right:"left",bottom:"top",left:"right"},Rf=m.forwardRef(function(t,n){const{__scopePopper:r,...o}=t,s=k0(jf,r),i=I0[s.placedSide];return c.jsx("span",{ref:s.onArrowChange,style:{position:"absolute",left:s.arrowX,top:s.arrowY,[i]:0,transformOrigin:{top:"",right:"0 0",bottom:"center 0",left:"100% 0"}[s.placedSide],transform:{top:"translateY(100%)",right:"translateY(50%) rotate(90deg) translateX(-50%)",bottom:"rotate(180deg)",left:"translateY(50%) rotate(-90deg) translateX(50%)"}[s.placedSide],visibility:s.shouldHideArrow?"hidden":void 0},children:c.jsx(S0,{...o,ref:n,style:{...o.style,display:"block"}})})});Rf.displayName=jf;function E0(e){return e!==null}var N0=e=>({name:"transformOrigin",options:e,fn(t){var g,v,w;const{placement:n,rects:r,middlewareData:o}=t,i=((g=o.arrow)==null?void 0:g.centerOffset)!==0,a=i?0:e.arrowWidth,l=i?0:e.arrowHeight,[u,d]=Pf(n),f={start:"0%",center:"50%",end:"100%"}[d],h=(((v=o.arrow)==null?void 0:v.x)??0)+a/2,p=(((w=o.arrow)==null?void 0:w.y)??0)+l/2;let b="",x="";return u==="bottom"?(b=i?f:`${h}px`,x=`${-l}px`):u==="top"?(b=i?f:`${h}px`,x=`${r.floating.height+l}px`):u==="right"?(b=`${-l}px`,x=i?f:`${p}px`):u==="left"&&(b=`${r.floating.width+l}px`,x=i?f:`${p}px`),{data:{x:b,y:x}}}});function Pf(e){const[t,n="center"]=e.split("-");return[t,n]}var Of=Ef,Mf=Af,Df=_f,Lf=Rf,Wa="rovingFocusGroup.onEntryFocus",A0={bubbles:!1,cancelable:!0},mo="RovingFocusGroup",[Va,$f,_0]=_a(mo),[j0,Ff]=wn(mo,[_0]),[R0,P0]=j0(mo),Bf=m.forwardRef((e,t)=>c.jsx(Va.Provider,{scope:e.__scopeRovingFocusGroup,children:c.jsx(Va.Slot,{scope:e.__scopeRovingFocusGroup,children:c.jsx(O0,{...e,ref:t})})}));Bf.displayName=mo;var O0=m.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:o=!1,dir:s,currentTabStopId:i,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:l,onEntryFocus:u,preventScrollOnEntryFocus:d=!1,...f}=e,h=m.useRef(null),p=Ke(t,h),b=As(s),[x,g]=sr({prop:i,defaultProp:a??null,onChange:l,caller:mo}),[v,w]=m.useState(!1),S=kt(u),N=$f(n),T=m.useRef(!1),[k,E]=m.useState(0);return m.useEffect(()=>{const A=h.current;if(A)return A.addEventListener(Wa,S),()=>A.removeEventListener(Wa,S)},[S]),c.jsx(R0,{scope:n,orientation:r,dir:b,loop:o,currentTabStopId:x,onItemFocus:m.useCallback(A=>g(A),[g]),onItemShiftTab:m.useCallback(()=>w(!0),[]),onFocusableItemAdd:m.useCallback(()=>E(A=>A+1),[]),onFocusableItemRemove:m.useCallback(()=>E(A=>A-1),[]),children:c.jsx(_e.div,{tabIndex:v||k===0?-1:0,"data-orientation":r,...f,ref:p,style:{outline:"none",...e.style},onMouseDown:de(e.onMouseDown,()=>{T.current=!0}),onFocus:de(e.onFocus,A=>{const j=!T.current;if(A.target===A.currentTarget&&j&&!v){const P=new CustomEvent(Wa,A0);if(A.currentTarget.dispatchEvent(P),!P.defaultPrevented){const L=N().filter(K=>K.focusable),$=L.find(K=>K.active),V=L.find(K=>K.id===x),G=[$,V,...L].filter(Boolean).map(K=>K.ref.current);Uf(G,d)}}T.current=!1}),onBlur:de(e.onBlur,()=>w(!1))})})}),zf="RovingFocusGroupItem",Hf=m.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:o=!1,tabStopId:s,children:i,...a}=e,l=yn(),u=s||l,d=P0(zf,n),f=d.currentTabStopId===u,h=$f(n),{onFocusableItemAdd:p,onFocusableItemRemove:b,currentTabStopId:x}=d;return m.useEffect(()=>{if(r)return p(),()=>b()},[r,p,b]),c.jsx(Va.ItemSlot,{scope:n,id:u,focusable:r,active:o,children:c.jsx(_e.span,{tabIndex:f?0:-1,"data-orientation":d.orientation,...a,ref:t,onMouseDown:de(e.onMouseDown,g=>{r?d.onItemFocus(u):g.preventDefault()}),onFocus:de(e.onFocus,()=>d.onItemFocus(u)),onKeyDown:de(e.onKeyDown,g=>{if(g.key==="Tab"&&g.shiftKey){d.onItemShiftTab();return}if(g.target!==g.currentTarget)return;const v=L0(g,d.orientation,d.dir);if(v!==void 0){if(g.metaKey||g.ctrlKey||g.altKey||g.shiftKey)return;g.preventDefault();let S=h().filter(N=>N.focusable).map(N=>N.ref.current);if(v==="last")S.reverse();else if(v==="prev"||v==="next"){v==="prev"&&S.reverse();const N=S.indexOf(g.currentTarget);S=d.loop?$0(S,N+1):S.slice(N+1)}setTimeout(()=>Uf(S))}}),children:typeof i=="function"?i({isCurrentTabStop:f,hasTabStop:x!=null}):i})})});Hf.displayName=zf;var M0={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function D0(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function L0(e,t,n){const r=D0(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return M0[r]}function Uf(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function $0(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var F0=Bf,B0=Hf,Ka=["Enter"," "],z0=["ArrowDown","PageUp","Home"],Wf=["ArrowUp","PageDown","End"],H0=[...z0,...Wf],U0={ltr:[...Ka,"ArrowRight"],rtl:[...Ka,"ArrowLeft"]},W0={ltr:["ArrowLeft"],rtl:["ArrowRight"]},go="Menu",[xo,V0,K0]=_a(go),[dr,Vf]=wn(go,[K0,Bs,Ff]),zs=Bs(),Kf=Ff(),[q0,fr]=dr(go),[G0,vo]=dr(go),qf=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=zs(t),[l,u]=m.useState(null),d=m.useRef(!1),f=kt(s),h=As(o);return m.useEffect(()=>{const p=()=>{d.current=!0,document.addEventListener("pointerdown",b,{capture:!0,once:!0}),document.addEventListener("pointermove",b,{capture:!0,once:!0})},b=()=>d.current=!1;return document.addEventListener("keydown",p,{capture:!0}),()=>{document.removeEventListener("keydown",p,{capture:!0}),document.removeEventListener("pointerdown",b,{capture:!0}),document.removeEventListener("pointermove",b,{capture:!0})}},[]),c.jsx(Of,{...a,children:c.jsx(q0,{scope:t,open:n,onOpenChange:f,content:l,onContentChange:u,children:c.jsx(G0,{scope:t,onClose:m.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:d,dir:h,modal:i,children:r})})})};qf.displayName=go;var Y0="MenuAnchor",qa=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=zs(n);return c.jsx(Mf,{...o,...r,ref:t})});qa.displayName=Y0;var Ga="MenuPortal",[X0,Gf]=dr(Ga,{forceMount:void 0}),Yf=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:o}=e,s=fr(Ga,t);return c.jsx(X0,{scope:t,forceMount:n,children:c.jsx(Wt,{present:n||s.open,children:c.jsx(hs,{asChild:!0,container:o,children:r})})})};Yf.displayName=Ga;var Zt="MenuContent",[J0,Ya]=dr(Zt),Xf=m.forwardRef((e,t)=>{const n=Gf(Zt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=fr(Zt,e.__scopeMenu),i=vo(Zt,e.__scopeMenu);return c.jsx(xo.Provider,{scope:e.__scopeMenu,children:c.jsx(Wt,{present:r||s.open,children:c.jsx(xo.Slot,{scope:e.__scopeMenu,children:i.modal?c.jsx(Z0,{...o,ref:t}):c.jsx(Q0,{...o,ref:t})})})})}),Z0=m.forwardRef((e,t)=>{const n=fr(Zt,e.__scopeMenu),r=m.useRef(null),o=Ke(t,r);return m.useEffect(()=>{const s=r.current;if(s)return Ta(s)},[]),c.jsx(Xa,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:de(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),Q0=m.forwardRef((e,t)=>{const n=fr(Zt,e.__scopeMenu);return c.jsx(Xa,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),eS=Jn.createSlot("MenuContent.ScrollLock"),Xa=m.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:o,onOpenAutoFocus:s,onCloseAutoFocus:i,disableOutsidePointerEvents:a,onEntryFocus:l,onEscapeKeyDown:u,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:h,onDismiss:p,disableOutsideScroll:b,...x}=e,g=fr(Zt,n),v=vo(Zt,n),w=zs(n),S=Kf(n),N=V0(n),[T,k]=m.useState(null),E=m.useRef(null),A=Ke(t,E,g.onContentChange),j=m.useRef(0),P=m.useRef(""),L=m.useRef(0),$=m.useRef(null),V=m.useRef("right"),M=m.useRef(0),G=b?bs:m.Fragment,K=b?{as:eS,allowPinchZoom:!0}:void 0,W=F=>{var q,O;const ue=P.current+F,D=N().filter(X=>!X.disabled),ee=document.activeElement,fe=(q=D.find(X=>X.ref.current===ee))==null?void 0:q.textValue,we=D.map(X=>X.textValue),ye=fS(we,ue,fe),Ce=(O=D.find(X=>X.textValue===ye))==null?void 0:O.ref.current;(function X(te){P.current=te,window.clearTimeout(j.current),te!==""&&(j.current=window.setTimeout(()=>X(""),1e3))})(ue),Ce&&setTimeout(()=>Ce.focus())};m.useEffect(()=>()=>window.clearTimeout(j.current),[]),va();const B=m.useCallback(F=>{var D,ee;return V.current===((D=$.current)==null?void 0:D.side)&&pS(F,(ee=$.current)==null?void 0:ee.area)},[]);return c.jsx(J0,{scope:n,searchRef:P,onItemEnter:m.useCallback(F=>{B(F)&&F.preventDefault()},[B]),onItemLeave:m.useCallback(F=>{var ue;B(F)||((ue=E.current)==null||ue.focus(),k(null))},[B]),onTriggerLeave:m.useCallback(F=>{B(F)&&F.preventDefault()},[B]),pointerGraceTimerRef:L,onPointerGraceIntentChange:m.useCallback(F=>{$.current=F},[]),children:c.jsx(G,{...K,children:c.jsx(fs,{asChild:!0,trapped:o,onMountAutoFocus:de(s,F=>{var ue;F.preventDefault(),(ue=E.current)==null||ue.focus({preventScroll:!0})}),onUnmountAutoFocus:i,children:c.jsx(ds,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:u,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:h,onDismiss:p,children:c.jsx(F0,{asChild:!0,...S,dir:v.dir,orientation:"vertical",loop:r,currentTabStopId:T,onCurrentTabStopIdChange:k,onEntryFocus:de(l,F=>{v.isUsingKeyboardRef.current||F.preventDefault()}),preventScrollOnEntryFocus:!0,children:c.jsx(Df,{role:"menu","aria-orientation":"vertical","data-state":hh(g.open),"data-radix-menu-content":"",dir:v.dir,...w,...x,ref:A,style:{outline:"none",...x.style},onKeyDown:de(x.onKeyDown,F=>{const D=F.target.closest("[data-radix-menu-content]")===F.currentTarget,ee=F.ctrlKey||F.altKey||F.metaKey,fe=F.key.length===1;D&&(F.key==="Tab"&&F.preventDefault(),!ee&&fe&&W(F.key));const we=E.current;if(F.target!==we||!H0.includes(F.key))return;F.preventDefault();const Ce=N().filter(q=>!q.disabled).map(q=>q.ref.current);Wf.includes(F.key)&&Ce.reverse(),uS(Ce)}),onBlur:de(e.onBlur,F=>{F.currentTarget.contains(F.target)||(window.clearTimeout(j.current),P.current="")}),onPointerMove:de(e.onPointerMove,wo(F=>{const ue=F.target,D=M.current!==F.clientX;if(F.currentTarget.contains(ue)&&D){const ee=F.clientX>M.current?"right":"left";V.current=ee,M.current=F.clientX}}))})})})})})})});Xf.displayName=Zt;var tS="MenuGroup",Ja=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return c.jsx(_e.div,{role:"group",...r,ref:t})});Ja.displayName=tS;var nS="MenuLabel",Jf=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return c.jsx(_e.div,{...r,ref:t})});Jf.displayName=nS;var Hs="MenuItem",Zf="menu.itemSelect",Us=m.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...o}=e,s=m.useRef(null),i=vo(Hs,e.__scopeMenu),a=Ya(Hs,e.__scopeMenu),l=Ke(t,s),u=m.useRef(!1),d=()=>{const f=s.current;if(!n&&f){const h=new CustomEvent(Zf,{bubbles:!0,cancelable:!0});f.addEventListener(Zf,p=>r==null?void 0:r(p),{once:!0}),Ru(f,h),h.defaultPrevented?u.current=!1:i.onClose()}};return c.jsx(Qf,{...o,ref:l,disabled:n,onClick:de(e.onClick,d),onPointerDown:f=>{var h;(h=e.onPointerDown)==null||h.call(e,f),u.current=!0},onPointerUp:de(e.onPointerUp,f=>{var h;u.current||(h=f.currentTarget)==null||h.click()}),onKeyDown:de(e.onKeyDown,f=>{const h=a.searchRef.current!=="";n||h&&f.key===" "||Ka.includes(f.key)&&(f.currentTarget.click(),f.preventDefault())})})});Us.displayName=Hs;var Qf=m.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:o,...s}=e,i=Ya(Hs,n),a=Kf(n),l=m.useRef(null),u=Ke(t,l),[d,f]=m.useState(!1),[h,p]=m.useState("");return m.useEffect(()=>{const b=l.current;b&&p((b.textContent??"").trim())},[s.children]),c.jsx(xo.ItemSlot,{scope:n,disabled:r,textValue:o??h,children:c.jsx(B0,{asChild:!0,...a,focusable:!r,children:c.jsx(_e.div,{role:"menuitem","data-highlighted":d?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:u,onPointerMove:de(e.onPointerMove,wo(b=>{r?i.onItemLeave(b):(i.onItemEnter(b),b.defaultPrevented||b.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:de(e.onPointerLeave,wo(b=>i.onItemLeave(b))),onFocus:de(e.onFocus,()=>f(!0)),onBlur:de(e.onBlur,()=>f(!1))})})})}),rS="MenuCheckboxItem",eh=m.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...o}=e;return c.jsx(sh,{scope:e.__scopeMenu,checked:n,children:c.jsx(Us,{role:"menuitemcheckbox","aria-checked":Ws(n)?"mixed":n,...o,ref:t,"data-state":Qa(n),onSelect:de(o.onSelect,()=>r==null?void 0:r(Ws(n)?!0:!n),{checkForDefaultPrevented:!1})})})});eh.displayName=rS;var th="MenuRadioGroup",[oS,sS]=dr(th,{value:void 0,onValueChange:()=>{}}),nh=m.forwardRef((e,t)=>{const{value:n,onValueChange:r,...o}=e,s=kt(r);return c.jsx(oS,{scope:e.__scopeMenu,value:n,onValueChange:s,children:c.jsx(Ja,{...o,ref:t})})});nh.displayName=th;var rh="MenuRadioItem",oh=m.forwardRef((e,t)=>{const{value:n,...r}=e,o=sS(rh,e.__scopeMenu),s=n===o.value;return c.jsx(sh,{scope:e.__scopeMenu,checked:s,children:c.jsx(Us,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":Qa(s),onSelect:de(r.onSelect,()=>{var i;return(i=o.onValueChange)==null?void 0:i.call(o,n)},{checkForDefaultPrevented:!1})})})});oh.displayName=rh;var Za="MenuItemIndicator",[sh,iS]=dr(Za,{checked:!1}),ih=m.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...o}=e,s=iS(Za,n);return c.jsx(Wt,{present:r||Ws(s.checked)||s.checked===!0,children:c.jsx(_e.span,{...o,ref:t,"data-state":Qa(s.checked)})})});ih.displayName=Za;var aS="MenuSeparator",ah=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return c.jsx(_e.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});ah.displayName=aS;var lS="MenuArrow",lh=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=zs(n);return c.jsx(Lf,{...o,...r,ref:t})});lh.displayName=lS;var cS="MenuSub",[VT,ch]=dr(cS),bo="MenuSubTrigger",uh=m.forwardRef((e,t)=>{const n=fr(bo,e.__scopeMenu),r=vo(bo,e.__scopeMenu),o=ch(bo,e.__scopeMenu),s=Ya(bo,e.__scopeMenu),i=m.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:l}=s,u={__scopeMenu:e.__scopeMenu},d=m.useCallback(()=>{i.current&&window.clearTimeout(i.current),i.current=null},[]);return m.useEffect(()=>d,[d]),m.useEffect(()=>{const f=a.current;return()=>{window.clearTimeout(f),l(null)}},[a,l]),c.jsx(qa,{asChild:!0,...u,children:c.jsx(Qf,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":o.contentId,"data-state":hh(n.open),...e,ref:oa(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:de(e.onPointerMove,wo(f=>{s.onItemEnter(f),!f.defaultPrevented&&!e.disabled&&!n.open&&!i.current&&(s.onPointerGraceIntentChange(null),i.current=window.setTimeout(()=>{n.onOpenChange(!0),d()},100))})),onPointerLeave:de(e.onPointerLeave,wo(f=>{var p,b;d();const h=(p=n.content)==null?void 0:p.getBoundingClientRect();if(h){const x=(b=n.content)==null?void 0:b.dataset.side,g=x==="right",v=g?-5:5,w=h[g?"left":"right"],S=h[g?"right":"left"];s.onPointerGraceIntentChange({area:[{x:f.clientX+v,y:f.clientY},{x:w,y:h.top},{x:S,y:h.top},{x:S,y:h.bottom},{x:w,y:h.bottom}],side:x}),window.clearTimeout(a.current),a.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(f),f.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:de(e.onKeyDown,f=>{var p;const h=s.searchRef.current!=="";e.disabled||h&&f.key===" "||U0[r.dir].includes(f.key)&&(n.onOpenChange(!0),(p=n.content)==null||p.focus(),f.preventDefault())})})})});uh.displayName=bo;var dh="MenuSubContent",fh=m.forwardRef((e,t)=>{const n=Gf(Zt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=fr(Zt,e.__scopeMenu),i=vo(Zt,e.__scopeMenu),a=ch(dh,e.__scopeMenu),l=m.useRef(null),u=Ke(t,l);return c.jsx(xo.Provider,{scope:e.__scopeMenu,children:c.jsx(Wt,{present:r||s.open,children:c.jsx(xo.Slot,{scope:e.__scopeMenu,children:c.jsx(Xa,{id:a.contentId,"aria-labelledby":a.triggerId,...o,ref:u,align:"start",side:i.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:d=>{var f;i.isUsingKeyboardRef.current&&((f=l.current)==null||f.focus()),d.preventDefault()},onCloseAutoFocus:d=>d.preventDefault(),onFocusOutside:de(e.onFocusOutside,d=>{d.target!==a.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:de(e.onEscapeKeyDown,d=>{i.onClose(),d.preventDefault()}),onKeyDown:de(e.onKeyDown,d=>{var p;const f=d.currentTarget.contains(d.target),h=W0[i.dir].includes(d.key);f&&h&&(s.onOpenChange(!1),(p=a.trigger)==null||p.focus(),d.preventDefault())})})})})})});fh.displayName=dh;function hh(e){return e?"open":"closed"}function Ws(e){return e==="indeterminate"}function Qa(e){return Ws(e)?"indeterminate":e?"checked":"unchecked"}function uS(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function dS(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function fS(e,t,n){const o=t.length>1&&Array.from(t).every(u=>u===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let i=dS(e,Math.max(s,0));o.length===1&&(i=i.filter(u=>u!==n));const l=i.find(u=>u.toLowerCase().startsWith(o.toLowerCase()));return l!==n?l:void 0}function hS(e,t){const{x:n,y:r}=e;let o=!1;for(let s=0,i=t.length-1;s<t.length;i=s++){const a=t[s],l=t[i],u=a.x,d=a.y,f=l.x,h=l.y;d>r!=h>r&&n<(f-u)*(r-d)/(h-d)+u&&(o=!o)}return o}function pS(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return hS(n,t)}function wo(e){return t=>t.pointerType==="mouse"?e(t):void 0}var mS=qf,gS=qa,xS=Yf,vS=Xf,bS=Ja,wS=Jf,yS=Us,SS=eh,CS=nh,TS=oh,kS=ih,IS=ah,ES=lh,NS=uh,AS=fh,Vs="DropdownMenu",[_S,KT]=wn(Vs,[Vf]),Ot=Vf(),[jS,ph]=_S(Vs),mh=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:o,defaultOpen:s,onOpenChange:i,modal:a=!0}=e,l=Ot(t),u=m.useRef(null),[d,f]=sr({prop:o,defaultProp:s??!1,onChange:i,caller:Vs});return c.jsx(jS,{scope:t,triggerId:yn(),triggerRef:u,contentId:yn(),open:d,onOpenChange:f,onOpenToggle:m.useCallback(()=>f(h=>!h),[f]),modal:a,children:c.jsx(mS,{...l,open:d,onOpenChange:f,dir:r,modal:a,children:n})})};mh.displayName=Vs;var gh="DropdownMenuTrigger",xh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...o}=e,s=ph(gh,n),i=Ot(n);return c.jsx(gS,{asChild:!0,...i,children:c.jsx(_e.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:oa(t,s.triggerRef),onPointerDown:de(e.onPointerDown,a=>{!r&&a.button===0&&a.ctrlKey===!1&&(s.onOpenToggle(),s.open||a.preventDefault())}),onKeyDown:de(e.onKeyDown,a=>{r||(["Enter"," "].includes(a.key)&&s.onOpenToggle(),a.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(a.key)&&a.preventDefault())})})})});xh.displayName=gh;var RS="DropdownMenuPortal",vh=e=>{const{__scopeDropdownMenu:t,...n}=e,r=Ot(t);return c.jsx(xS,{...r,...n})};vh.displayName=RS;var bh="DropdownMenuContent",wh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=ph(bh,n),s=Ot(n),i=m.useRef(!1);return c.jsx(vS,{id:o.contentId,"aria-labelledby":o.triggerId,...s,...r,ref:t,onCloseAutoFocus:de(e.onCloseAutoFocus,a=>{var l;i.current||(l=o.triggerRef.current)==null||l.focus(),i.current=!1,a.preventDefault()}),onInteractOutside:de(e.onInteractOutside,a=>{const l=a.detail.originalEvent,u=l.button===0&&l.ctrlKey===!0,d=l.button===2||u;(!o.modal||d)&&(i.current=!0)}),style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});wh.displayName=bh;var PS="DropdownMenuGroup",OS=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return c.jsx(bS,{...o,...r,ref:t})});OS.displayName=PS;var MS="DropdownMenuLabel",yh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return c.jsx(wS,{...o,...r,ref:t})});yh.displayName=MS;var DS="DropdownMenuItem",Sh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return c.jsx(yS,{...o,...r,ref:t})});Sh.displayName=DS;var LS="DropdownMenuCheckboxItem",Ch=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return c.jsx(SS,{...o,...r,ref:t})});Ch.displayName=LS;var $S="DropdownMenuRadioGroup",FS=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return c.jsx(CS,{...o,...r,ref:t})});FS.displayName=$S;var BS="DropdownMenuRadioItem",Th=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return c.jsx(TS,{...o,...r,ref:t})});Th.displayName=BS;var zS="DropdownMenuItemIndicator",kh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return c.jsx(kS,{...o,...r,ref:t})});kh.displayName=zS;var HS="DropdownMenuSeparator",Ih=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return c.jsx(IS,{...o,...r,ref:t})});Ih.displayName=HS;var US="DropdownMenuArrow",WS=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return c.jsx(ES,{...o,...r,ref:t})});WS.displayName=US;var VS="DropdownMenuSubTrigger",Eh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return c.jsx(NS,{...o,...r,ref:t})});Eh.displayName=VS;var KS="DropdownMenuSubContent",Nh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return c.jsx(AS,{...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)"}})});Nh.displayName=KS;var qS=mh,GS=xh,YS=vh,Ah=wh,_h=yh,jh=Sh,Rh=Ch,Ph=Th,Oh=kh,Mh=Ih,Dh=Eh,Lh=Nh;const XS=qS,JS=GS,ZS=m.forwardRef(({className:e,inset:t,children:n,...r},o)=>c.jsxs(Dh,{ref:o,className:Q("flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent",t&&"pl-8",e),...r,children:[n,c.jsx(se.ChevronRight,{className:"ml-auto h-4 w-4"})]}));ZS.displayName=Dh.displayName;const QS=m.forwardRef(({className:e,...t},n)=>c.jsx(Lh,{ref:n,className:Q("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}));QS.displayName=Lh.displayName;const $h=m.forwardRef(({className:e,sideOffset:t=4,...n},r)=>c.jsx(YS,{children:c.jsx(Ah,{ref:r,sideOffset:t,className:Q("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})}));$h.displayName=Ah.displayName;const el=m.forwardRef(({className:e,inset:t,...n},r)=>c.jsx(jh,{ref:r,className:Q("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}));el.displayName=jh.displayName;const eC=m.forwardRef(({className:e,children:t,checked:n,...r},o)=>c.jsxs(Rh,{ref:o,className:Q("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),checked:n,...r,children:[c.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:c.jsx(Oh,{children:c.jsx(se.Check,{className:"h-4 w-4"})})}),t]}));eC.displayName=Rh.displayName;const tC=m.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(Ph,{ref:r,className:Q("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[c.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:c.jsx(Oh,{children:c.jsx(se.Circle,{className:"h-2 w-2 fill-current"})})}),t]}));tC.displayName=Ph.displayName;const nC=m.forwardRef(({className:e,inset:t,...n},r)=>c.jsx(_h,{ref:r,className:Q("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));nC.displayName=_h.displayName;const rC=m.forwardRef(({className:e,...t},n)=>c.jsx(Mh,{ref:n,className:Q("-mx-1 my-1 h-px bg-muted",e),...t}));rC.displayName=Mh.displayName;function Ks({className:e="",placeholder:t="Type your message...",autoFocus:n=!0,maxHeight:r=void 0,streamingDebounceMs:o=500,streamingThrottleMs:s,followNewMessages:i=!0,enableFileUpload:a=!0,enableExcelUpload:l=!1,enableMessageEditing:u=!0,customStyles:d={},onMessageSent:f,onExcelUploadSuccess:h,onError:p}){const{api:b}=Si(),{currentThreadId:x}=Bo(),{threadId:g,messages:v,hasMore:w,isHistoryLoading:S,isLoading:N,loadOlder:T,listCheckpoints:k,navigateToCheckpoint:E,returnToLatest:A,checkpoint:j,respondToInterrupt:P,metadata:L}=zo(),{isStreaming:$,error:V,submit:M,stop:G}=jc(),K=g??x??null,W=(j==null?void 0:j.id)??null,B=(j==null?void 0:j.namespace)??null,F=(L==null?void 0:L.assemblingMessageId)??null,[ue,D]=y.useState(null),[ee,fe]=y.useState(""),[we,ye]=y.useState(null),[Ce,q]=y.useState([]),[O,X]=y.useState(0),[te,he]=y.useState(0),[re,pe]=y.useState(!1),[tt,nt]=y.useState(null),[Pe,He]=y.useState(null),[ut,rt]=y.useState(!1),[Ue,bt]=y.useState(null),[Z,oe]=y.useState([]),[me,Te]=y.useState(null),[ge,Oe]=y.useState(null),[at,Me]=y.useState(!1),it=y.useRef(null),mt=y.useRef(null),Ct=y.useRef(null),Bt=y.useCallback(()=>{it.current&&(it.current.value=""),mt.current&&(mt.current.value=""),X(ie=>ie+1),he(ie=>ie+1)},[]),gr=y.useRef(!1);y.useEffect(()=>{gr.current&&!$&&(q([]),Bt()),gr.current=$},[$,Bt]);const[ri,So]=y.useState("desktop");y.useEffect(()=>{const ie=()=>{const Se=window.innerWidth;So(Se<640?"phone":Se<1024?"tablet":"desktop")};return ie(),window.addEventListener("resize",ie),()=>window.removeEventListener("resize",ie)},[]),y.useEffect(()=>{let ie=!1;if(!K){oe([]),Te(null),Oe(null),Ct.current=null;return}const Se={threadId:K,checkpointId:W??null,checkpointNs:B??null},We=Ct.current;if(!(We&&We.threadId===Se.threadId&&We.checkpointId===Se.checkpointId&&We.checkpointNs===Se.checkpointNs))return k(K).then(et=>{var Ee;if(ie)return;const Mt=((et==null?void 0:et.checkpoints)??[]).slice().sort(($e,Xe)=>new Date(Xe.createdAt).getTime()-new Date($e.createdAt).getTime());oe(Mt);const I=me,H=I&&Mt.some($e=>$e.checkpointId===I)?I:((Ee=Mt[0])==null?void 0:Ee.checkpointId)??null;let J=null;if(H){const $e=Mt.find(Xe=>Xe.checkpointId===H);J=($e==null?void 0:$e.checkpointNs)??null}Te(H),Oe(J),Ct.current=Se}).catch(et=>{console.error("ChatInterface - listCheckpoints error:",et),ie||(oe([]),Ct.current=null)}),()=>{ie=!0}},[K,W,B,me,k]),y.useEffect(()=>{W&&(Te(W),Oe(B??null))},[W,B]);const xr=y.useCallback(async()=>{if(!(!w||S))try{await T()}catch(ie){console.warn("loadOlder failed",ie)}},[w,S,T]);y.useEffect(()=>{(async()=>{if(!b.baseUrl){bt(null);return}try{const Se=await b.getAgent("default");bt(Se.uiDefaultMessage||null)}catch(Se){console.warn("Failed to fetch default message:",Se),bt(null)}})()},[b]),y.useEffect(()=>{V&&!ut&&(p==null||p(V))},[V,ut,p]);const It=ie=>{if(ie.length>Ns)return`Message too long (${ie.length}/${Ns} characters)`;try{return cy(ie),null}catch(Se){return(Se==null?void 0:Se.message)||"Invalid message"}},Br=async ie=>{const Se=ie.trim();if(!(!Se&&Ce.length===0)){if(Se){const We=It(Se);if(We){ye(We);return}}try{await M({text:Se||"",attachments:Ce,payload:ue?{edit:!0,originalMessageId:ue}:void 0},{checkpointId:me??W??void 0,checkpointNs:ge??B??void 0}),f==null||f(Se),ye(null),q([]),Bt(),D(null),fe("")}catch(We){const et=(We==null?void 0:We.message)||"Failed to send message";ye(et),p==null||p(et)}}},qt=y.useCallback((ie,Se)=>{u&&(D(ie),fe(Se),ye(null))},[u]),gt=y.useCallback(()=>{D(null),fe(""),ye(null)},[]),tn=y.useCallback((ie,Se)=>{qt(ie,Se)},[qt]),Nn=y.useCallback(ie=>{const Se=We=>{const et=We.content||[],Mt=et.filter(I=>I.type==="text").map(I=>I.text).join("");if(Mt)return Mt;try{return JSON.stringify(et,null,2)}catch{return String(et)}};for(let We=ie-1;We>=0;We--)if(v[We].role==="user"){const et=Se(v[We]);et&&M({text:et},{checkpointId:me??W??void 0,checkpointNs:ge??B??void 0});break}},[v,M,me,ge,W,B]),zr=ie=>{const Se=Array.from(ie.target.files||[]);q(We=>[...We,...Se]),ie.target.value=""},Gt=ie=>{q(Se=>{const We=Se.filter((et,Mt)=>ie!==Mt);return We.length===0&&Bt(),We})},vr=async ie=>{const Se=(ie.target.files||[])[0];if(Se){nt(null),He(null),pe(!0);try{await M({attachments:[Se]},{checkpointId:me??W??void 0,checkpointNs:ge??B??void 0});const We=`Uploaded ${Se.name} - processing through chat stream`;He(We)}catch(We){const et=We instanceof Error?We.message:"Failed to upload Excel file";console.error("Excel upload failed",We),nt(et),p==null||p(et)}finally{pe(!1),ie.target.value="",Bt()}}},hn=ie=>{if(!ie)return"Unknown";const Se=Date.parse(ie);return Number.isNaN(Se)?ie:new Date(Se).toLocaleString()},pn=async ie=>{if(x){Me(!0);try{if(!ie){await A(),Te(null),Oe(null);return}const Se=Z.find(et=>et.checkpointId===ie),We=(Se==null?void 0:Se.checkpointNs)??null;await E(ie,We),Te(ie),Oe(We)}finally{Me(!1)}}},br=`flex flex-1 w-full flex-col min-h-0 min-w-0 max-h-full overflow-hidden bg-transparent ${e} ${d.container||""}`,Co=`flex-1 min-h-0 min-w-0 max-h-full w-full overflow-hidden overscroll-contain break-words break-anywhere p-4 bg-transparent ${d.messagesArea||""}`,wr=`flex-shrink-0 w-full border-t p-4 bg-transparent ${d.inputArea||""}`;return c.jsxs("div",{className:br,children:[!!V&&!ut&&c.jsxs("div",{className:"flex-shrink-0 bg-red-50 border border-red-200 text-red-800 px-4 py-2 text-sm flex items-center justify-between",children:[c.jsx("span",{children:V}),c.jsx(Je,{variant:"ghost",size:"sm",onClick:()=>rt(!0),className:"text-red-800 hover:bg-red-100","aria-label":"Dismiss error",children:c.jsx(se.X,{size:16})})]}),x&&Z.length>0&&c.jsxs("div",{className:"flex-shrink-0 flex items-center gap-2 px-4 py-2 border-b border-border bg-muted/60 text-xs dark:bg-muted/50",children:[c.jsx("span",{className:"opacity-70",children:"Checkpoint:"}),c.jsxs("select",{className:"border border-border rounded px-2 py-1 text-xs bg-card text-foreground focus:outline-none focus:ring-1 focus:ring-ring dark:bg-secondary",value:me??"",onChange:ie=>{const Se=ie.target.value||null;pn(Se)},children:[c.jsx("option",{value:"",children:"Latest"}),Z.map(ie=>c.jsxs("option",{value:ie.checkpointId,children:[hn(ie.createdAt),ie.preview?` — ${ie.preview.slice(0,40)}`:""]},ie.checkpointId))]})]}),c.jsxs("div",{className:`relative ${Co}`,style:r?{maxHeight:r}:void 0,children:[c.jsx(Aa,{className:"h-full",style:{height:"100%"},messages:v,isStreaming:$,streamingAssistantId:F,streamingDebounceMs:typeof s=="number"?s:o,followNewMessages:i,layoutSize:ri,enableMessageEditing:u,editingMessageId:ue,onStartReached:()=>{xr()},onEdit:tn,onRegenerate:Nn,onCancelEdit:gt,emptyMessage:Ue??void 0,isNavigatingCheckpoint:at}),N&&c.jsxs("div",{className:"absolute inset-0 z-10 flex flex-col items-center justify-center gap-2 bg-background/80 backdrop-blur-sm text-muted-foreground",children:[c.jsx(se.Loader2,{className:"h-6 w-6 animate-spin"}),c.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:"Loading messages…"})]})]}),c.jsxs("div",{className:wr,children:[ue&&c.jsx("div",{className:"mb-3 p-3 bg-blue-50 border border-blue-200 rounded-lg",children:c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(se.Edit3,{size:16,className:"text-blue-600"}),c.jsx("span",{className:"text-sm font-medium text-blue-800",children:"Editing message"})]}),c.jsx(Je,{variant:"ghost",size:"sm",onClick:gt,className:"text-blue-600 hover:bg-blue-100",children:c.jsx(se.X,{size:16})})]})}),(a||l)&&c.jsxs("div",{className:"mb-3 space-y-3",children:[a&&c.jsxs(c.Fragment,{children:[c.jsx("input",{ref:it,type:"file",multiple:!0,onChange:ie=>zr(ie),className:"hidden"},O),Ce.length>0&&c.jsx("div",{className:"flex flex-wrap gap-2",children:Ce.map((ie,Se)=>c.jsxs("div",{className:"flex items-center gap-2 bg-gray-100 dark:bg-gray-800 rounded-lg px-3 py-2 text-sm text-gray-900 dark:text-gray-100",children:[c.jsx(se.Paperclip,{size:14}),c.jsx("span",{className:"truncate max-w-[150px]",children:ie.name}),c.jsx(Je,{variant:"ghost",size:"sm",onClick:()=>Gt(Se),className:"h-4 w-4 p-0 text-gray-500 dark:text-gray-400 hover:text-red-500 dark:hover:text-red-400","aria-label":`Remove ${ie.name}`,children:c.jsx(se.X,{size:12})})]},Se))})]}),l&&c.jsxs(c.Fragment,{children:[c.jsx("input",{ref:mt,type:"file",accept:".xls,.xlsx,.xlsm",onChange:vr,className:"hidden"},te),re&&c.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[c.jsx(se.Loader2,{className:"h-4 w-4 animate-spin"})," Uploading Excel file..."]}),Pe&&!re&&c.jsx("div",{className:"text-sm rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-emerald-700",children:Pe}),tt&&!re&&c.jsx("div",{className:"text-sm rounded border border-red-200 bg-red-50 px-3 py-2 text-red-600",children:tt})]})]}),we&&c.jsx("div",{className:"mb-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2",children:we}),c.jsxs("div",{className:"flex items-end gap-2",children:[(a||l)&&c.jsxs(XS,{children:[c.jsx(JS,{asChild:!0,children:c.jsx(Je,{type:"button",size:"icon",variant:"outline",disabled:$,title:"More input actions",className:d.moreButton||"",children:c.jsx(se.Plus,{size:16})})}),c.jsxs($h,{align:"start",sideOffset:6,className:"w-52",children:[a&&c.jsxs(el,{onClick:()=>{var ie;return(ie=it.current)==null?void 0:ie.click()},className:"cursor-pointer",children:[c.jsx(se.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]}),l&&c.jsxs(el,{onClick:()=>{var ie;re||(ie=mt.current)==null||ie.click()},className:`cursor-pointer ${re?"opacity-60 pointer-events-none":""}`,children:[c.jsx(se.FileSpreadsheet,{className:"h-4 w-4 mr-2"})," Upload Excel file"]})]})]}),c.jsx("div",{className:"flex-1",children:c.jsx(Sx,{initialValue:ee,editingMessageId:ue,placeholder:ue?"Edit your message...":t,isStreaming:$,disabled:!1,maxLength:Ns,onSend:Br,onCancelEdit:gt,onStop:G,allowEmptySend:Ce.length>0,textareaClassName:`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${ue?"border-blue-400 bg-blue-50 text-blue-900 dark:border-blue-500 dark:bg-blue-950/60 dark:text-blue-50":""} ${we?"border-red-400":""} ${d.textarea||""}`})})]})]})]})}const qs=m.forwardRef(({className:e,type:t,...n},r)=>c.jsx("input",{type:t,className:Q("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}));qs.displayName="Input";function tl(e,[t,n]){return Math.min(n,Math.max(t,e))}function oC(e,t){return m.useReducer((n,r)=>t[n][r]??n,e)}var nl="ScrollArea",[Fh,qT]=wn(nl),[sC,Qt]=Fh(nl),Bh=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,type:r="hover",dir:o,scrollHideDelay:s=600,...i}=e,[a,l]=m.useState(null),[u,d]=m.useState(null),[f,h]=m.useState(null),[p,b]=m.useState(null),[x,g]=m.useState(null),[v,w]=m.useState(0),[S,N]=m.useState(0),[T,k]=m.useState(!1),[E,A]=m.useState(!1),j=Ke(t,L=>l(L)),P=As(o);return c.jsx(sC,{scope:n,type:r,dir:P,scrollHideDelay:s,scrollArea:a,viewport:u,onViewportChange:d,content:f,onContentChange:h,scrollbarX:p,onScrollbarXChange:b,scrollbarXEnabled:T,onScrollbarXEnabledChange:k,scrollbarY:x,onScrollbarYChange:g,scrollbarYEnabled:E,onScrollbarYEnabledChange:A,onCornerWidthChange:w,onCornerHeightChange:N,children:c.jsx(_e.div,{dir:P,...i,ref:j,style:{position:"relative","--radix-scroll-area-corner-width":v+"px","--radix-scroll-area-corner-height":S+"px",...e.style}})})});Bh.displayName=nl;var zh="ScrollAreaViewport",Hh=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,i=Qt(zh,n),a=m.useRef(null),l=Ke(t,a,i.onViewportChange);return c.jsxs(c.Fragment,{children:[c.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-scroll-area-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-scroll-area-viewport]::-webkit-scrollbar{display:none}"},nonce:o}),c.jsx(_e.div,{"data-radix-scroll-area-viewport":"",...s,ref:l,style:{overflowX:i.scrollbarXEnabled?"scroll":"hidden",overflowY:i.scrollbarYEnabled?"scroll":"hidden",...e.style},children:c.jsx("div",{ref:i.onContentChange,style:{minWidth:"100%",display:"table"},children:r})})]})});Hh.displayName=zh;var En="ScrollAreaScrollbar",rl=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Qt(En,e.__scopeScrollArea),{onScrollbarXEnabledChange:s,onScrollbarYEnabledChange:i}=o,a=e.orientation==="horizontal";return m.useEffect(()=>(a?s(!0):i(!0),()=>{a?s(!1):i(!1)}),[a,s,i]),o.type==="hover"?c.jsx(iC,{...r,ref:t,forceMount:n}):o.type==="scroll"?c.jsx(aC,{...r,ref:t,forceMount:n}):o.type==="auto"?c.jsx(Uh,{...r,ref:t,forceMount:n}):o.type==="always"?c.jsx(ol,{...r,ref:t}):null});rl.displayName=En;var iC=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Qt(En,e.__scopeScrollArea),[s,i]=m.useState(!1);return m.useEffect(()=>{const a=o.scrollArea;let l=0;if(a){const u=()=>{window.clearTimeout(l),i(!0)},d=()=>{l=window.setTimeout(()=>i(!1),o.scrollHideDelay)};return a.addEventListener("pointerenter",u),a.addEventListener("pointerleave",d),()=>{window.clearTimeout(l),a.removeEventListener("pointerenter",u),a.removeEventListener("pointerleave",d)}}},[o.scrollArea,o.scrollHideDelay]),c.jsx(Wt,{present:n||s,children:c.jsx(Uh,{"data-state":s?"visible":"hidden",...r,ref:t})})}),aC=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Qt(En,e.__scopeScrollArea),s=e.orientation==="horizontal",i=Js(()=>l("SCROLL_END"),100),[a,l]=oC("hidden",{hidden:{SCROLL:"scrolling"},scrolling:{SCROLL_END:"idle",POINTER_ENTER:"interacting"},interacting:{SCROLL:"interacting",POINTER_LEAVE:"idle"},idle:{HIDE:"hidden",SCROLL:"scrolling",POINTER_ENTER:"interacting"}});return m.useEffect(()=>{if(a==="idle"){const u=window.setTimeout(()=>l("HIDE"),o.scrollHideDelay);return()=>window.clearTimeout(u)}},[a,o.scrollHideDelay,l]),m.useEffect(()=>{const u=o.viewport,d=s?"scrollLeft":"scrollTop";if(u){let f=u[d];const h=()=>{const p=u[d];f!==p&&(l("SCROLL"),i()),f=p};return u.addEventListener("scroll",h),()=>u.removeEventListener("scroll",h)}},[o.viewport,s,l,i]),c.jsx(Wt,{present:n||a!=="hidden",children:c.jsx(ol,{"data-state":a==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:de(e.onPointerEnter,()=>l("POINTER_ENTER")),onPointerLeave:de(e.onPointerLeave,()=>l("POINTER_LEAVE"))})})}),Uh=m.forwardRef((e,t)=>{const n=Qt(En,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,i]=m.useState(!1),a=e.orientation==="horizontal",l=Js(()=>{if(n.viewport){const u=n.viewport.offsetWidth<n.viewport.scrollWidth,d=n.viewport.offsetHeight<n.viewport.scrollHeight;i(a?u:d)}},10);return Lr(n.viewport,l),Lr(n.content,l),c.jsx(Wt,{present:r||s,children:c.jsx(ol,{"data-state":s?"visible":"hidden",...o,ref:t})})}),ol=m.forwardRef((e,t)=>{const{orientation:n="vertical",...r}=e,o=Qt(En,e.__scopeScrollArea),s=m.useRef(null),i=m.useRef(0),[a,l]=m.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),u=Gh(a.viewport,a.content),d={...r,sizes:a,onSizesChange:l,hasThumb:u>0&&u<1,onThumbChange:h=>s.current=h,onThumbPointerUp:()=>i.current=0,onThumbPointerDown:h=>i.current=h};function f(h,p){return hC(h,i.current,a,p)}return n==="horizontal"?c.jsx(lC,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollLeft,p=Yh(h,a,o.dir);s.current.style.transform=`translate3d(${p}px, 0, 0)`}},onWheelScroll:h=>{o.viewport&&(o.viewport.scrollLeft=h)},onDragScroll:h=>{o.viewport&&(o.viewport.scrollLeft=f(h,o.dir))}}):n==="vertical"?c.jsx(cC,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollTop,p=Yh(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}),lC=m.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=Qt(En,e.__scopeScrollArea),[i,a]=m.useState(),l=m.useRef(null),u=Ke(t,l,s.onScrollbarXChange);return m.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),c.jsx(Vh,{"data-orientation":"horizontal",...o,ref:u,sizes:n,style:{bottom:0,left:s.dir==="rtl"?"var(--radix-scroll-area-corner-width)":0,right:s.dir==="ltr"?"var(--radix-scroll-area-corner-width)":0,"--radix-scroll-area-thumb-width":Xs(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),Jh(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:Ys(i.paddingLeft),paddingEnd:Ys(i.paddingRight)}})}})}),cC=m.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=Qt(En,e.__scopeScrollArea),[i,a]=m.useState(),l=m.useRef(null),u=Ke(t,l,s.onScrollbarYChange);return m.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),c.jsx(Vh,{"data-orientation":"vertical",...o,ref:u,sizes:n,style:{top:0,right:s.dir==="ltr"?0:void 0,left:s.dir==="rtl"?0:void 0,bottom:"var(--radix-scroll-area-corner-height)","--radix-scroll-area-thumb-height":Xs(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),Jh(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:Ys(i.paddingTop),paddingEnd:Ys(i.paddingBottom)}})}})}),[uC,Wh]=Fh(En),Vh=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,sizes:r,hasThumb:o,onThumbChange:s,onThumbPointerUp:i,onThumbPointerDown:a,onThumbPositionChange:l,onDragScroll:u,onWheelScroll:d,onResize:f,...h}=e,p=Qt(En,n),[b,x]=m.useState(null),g=Ke(t,j=>x(j)),v=m.useRef(null),w=m.useRef(""),S=p.viewport,N=r.content-r.viewport,T=kt(d),k=kt(l),E=Js(f,10);function A(j){if(v.current){const P=j.clientX-v.current.left,L=j.clientY-v.current.top;u({x:P,y:L})}}return m.useEffect(()=>{const j=P=>{const L=P.target;(b==null?void 0:b.contains(L))&&T(P,N)};return document.addEventListener("wheel",j,{passive:!1}),()=>document.removeEventListener("wheel",j,{passive:!1})},[S,b,N,T]),m.useEffect(k,[r,k]),Lr(b,E),Lr(p.content,E),c.jsx(uC,{scope:n,scrollbar:b,hasThumb:o,onThumbChange:kt(s),onThumbPointerUp:kt(i),onThumbPositionChange:k,onThumbPointerDown:kt(a),children:c.jsx(_e.div,{...h,ref:g,style:{position:"absolute",...h.style},onPointerDown:de(e.onPointerDown,j=>{j.button===0&&(j.target.setPointerCapture(j.pointerId),v.current=b.getBoundingClientRect(),w.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",p.viewport&&(p.viewport.style.scrollBehavior="auto"),A(j))}),onPointerMove:de(e.onPointerMove,A),onPointerUp:de(e.onPointerUp,j=>{const P=j.target;P.hasPointerCapture(j.pointerId)&&P.releasePointerCapture(j.pointerId),document.body.style.webkitUserSelect=w.current,p.viewport&&(p.viewport.style.scrollBehavior=""),v.current=null})})})}),Gs="ScrollAreaThumb",Kh=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Wh(Gs,e.__scopeScrollArea);return c.jsx(Wt,{present:n||o.hasThumb,children:c.jsx(dC,{ref:t,...r})})}),dC=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=Qt(Gs,n),i=Wh(Gs,n),{onThumbPositionChange:a}=i,l=Ke(t,f=>i.onThumbChange(f)),u=m.useRef(void 0),d=Js(()=>{u.current&&(u.current(),u.current=void 0)},100);return m.useEffect(()=>{const f=s.viewport;if(f){const h=()=>{if(d(),!u.current){const p=pC(f,a);u.current=p,a()}};return a(),f.addEventListener("scroll",h),()=>f.removeEventListener("scroll",h)}},[s.viewport,d,a]),c.jsx(_e.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:de(e.onPointerDownCapture,f=>{const p=f.target.getBoundingClientRect(),b=f.clientX-p.left,x=f.clientY-p.top;i.onThumbPointerDown({x:b,y:x})}),onPointerUp:de(e.onPointerUp,i.onThumbPointerUp)})});Kh.displayName=Gs;var sl="ScrollAreaCorner",qh=m.forwardRef((e,t)=>{const n=Qt(sl,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?c.jsx(fC,{...e,ref:t}):null});qh.displayName=sl;var fC=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=Qt(sl,n),[s,i]=m.useState(0),[a,l]=m.useState(0),u=!!(s&&a);return Lr(o.scrollbarX,()=>{var f;const d=((f=o.scrollbarX)==null?void 0:f.offsetHeight)||0;o.onCornerHeightChange(d),l(d)}),Lr(o.scrollbarY,()=>{var f;const d=((f=o.scrollbarY)==null?void 0:f.offsetWidth)||0;o.onCornerWidthChange(d),i(d)}),u?c.jsx(_e.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 Ys(e){return e?parseInt(e,10):0}function Gh(e,t){const n=e/t;return isNaN(n)?0:n}function Xs(e){const t=Gh(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function hC(e,t,n,r="ltr"){const o=Xs(n),s=o/2,i=t||s,a=o-i,l=n.scrollbar.paddingStart+i,u=n.scrollbar.size-n.scrollbar.paddingEnd-a,d=n.content-n.viewport,f=r==="ltr"?[0,d]:[d*-1,0];return Xh([l,u],f)(e)}function Yh(e,t,n="ltr"){const r=Xs(t),o=t.scrollbar.paddingStart+t.scrollbar.paddingEnd,s=t.scrollbar.size-o,i=t.content-t.viewport,a=s-r,l=n==="ltr"?[0,i]:[i*-1,0],u=tl(e,l);return Xh([0,i],[0,a])(u)}function Xh(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 Jh(e,t){return e>0&&e<t}var pC=(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 Js(e,t){const n=kt(e),r=m.useRef(0);return m.useEffect(()=>()=>window.clearTimeout(r.current),[]),m.useCallback(()=>{window.clearTimeout(r.current),r.current=window.setTimeout(n,t)},[n,t])}function Lr(e,t){const n=kt(t);St(()=>{let r=0;if(e){const o=new ResizeObserver(()=>{cancelAnimationFrame(r),r=window.requestAnimationFrame(n)});return o.observe(e),()=>{window.cancelAnimationFrame(r),o.unobserve(e)}}},[e,n])}var Zh=Bh,mC=Hh,gC=qh;const Qh=m.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(Zh,{ref:r,className:Q("relative overflow-hidden",e),...n,children:[c.jsx(mC,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),c.jsx(ep,{}),c.jsx(gC,{})]}));Qh.displayName=Zh.displayName;const ep=m.forwardRef(({className:e,orientation:t="vertical",...n},r)=>c.jsx(rl,{ref:r,orientation:t,className:Q("flex touch-none select-none transition-colors",t==="vertical"&&"h-full w-2.5 border-l border-l-transparent p-[1px]",t==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent p-[1px]",e),...n,children:c.jsx(Kh,{className:"relative flex-1 rounded-full bg-border"})}));ep.displayName=rl.displayName;function il({className:e="",showCreateButton:t=!0,showDeleteButton:n=!0,showEditTitle:r=!0,maxHeight:o="400px",customStyles:s={},currentThreadId:i=null,navigateToThread:a,onThreadSelect:l,onThreadCreate:u,onThreadDelete:d}){const{threads:f,currentThreadId:h,isLoading:p,actions:b}=Bo(),{loadThread:x}=zo(),{createThread:g,deleteThread:v,renameThread:w}=b,[S,N]=y.useState(Array.isArray(f)?f:[]),T=y.useRef(S.length>0),[k,E]=y.useState(null),[A,j]=y.useState(""),[P,L]=y.useState(!1);y.useEffect(()=>{const D=Array.isArray(f)?f:[];if(D.length>0){T.current=!0,N(D);return}p||(T.current=!1,N(D))},[f,p]);const $=async D=>{try{await x(D),a==null||a(D),l==null||l(D)}catch(ee){console.error("Failed to select thread:",ee)}},V=async()=>{try{L(!0);const D=await g();u==null||u(D),a==null||a(D)}catch(D){console.error("Failed to create thread:",D)}finally{L(!1)}},M=async(D,ee)=>{if(ee.stopPropagation(),!!confirm("Delete this thread?"))try{await v(D),d==null||d(D)}catch(fe){console.error("Failed to delete thread:",fe)}},G=(D,ee)=>{ee.stopPropagation(),E(D.threadId),j(D.title||`Thread ${D.threadId.slice(0,8)}`)},K=async D=>{if(A.trim())try{await w(D,A.trim()),E(null),j("")}catch(ee){console.error("Failed to update title:",ee)}},W=()=>{E(null),j("")},B=(D,ee)=>{D.key==="Enter"?K(ee):D.key==="Escape"&&W()},F=D=>{if(!D)return"";try{const ee=new Date(D),we=new Date().getTime()-ee.getTime(),ye=Math.floor(we/(1e3*60*60*24));return ye===0?ee.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):ye===1?"Yesterday":ye<7?`${ye} days ago`:ee.toLocaleDateString()}catch{return""}},ue=D=>D.title||`Thread ${D.threadId.slice(0,8)}`;return c.jsxs("div",{className:`flex flex-col h-full ${e} ${s.container||""}`,children:[t&&c.jsx("div",{className:s.header||"flex-shrink-0 p-2 border-b bg-slate-800 border-slate-700 text-slate-100 flex justify-end",children:c.jsx(Je,{onClick:V,disabled:P||p,className:s.createButton||"p-2",size:"sm",variant:"ghost",title:P?"Creating...":"New Chat",children:c.jsx(se.MessageSquarePlus,{size:20})})}),c.jsx(Qh,{className:`flex-1 min-h-0 ${s.threadList||""}`,style:o?{maxHeight:o}:void 0,children:c.jsx("div",{className:"p-2 space-y-1 pb-4",children:p?c.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 py-8 text-slate-400",children:[c.jsx(se.Loader2,{className:"h-5 w-5 animate-spin"}),c.jsx("span",{className:"text-sm",children:"Loading threads…"})]}):S.length===0?c.jsxs("div",{className:"text-center py-8 text-slate-400",children:[c.jsx(se.MessageSquare,{className:"w-8 h-8 mx-auto mb-2 opacity-40 text-slate-500"}),c.jsx("p",{className:"text-sm text-slate-500",children:"No conversations yet"})]}):S.slice().sort((D,ee)=>new Date(ee.updatedAt||ee.createdAt||"").getTime()-new Date(D.updatedAt||D.createdAt||"").getTime()).map(D=>c.jsxs("div",{onClick:()=>$(D.threadId),className:`group relative p-3 rounded-lg cursor-pointer transition-colors border ${(i??h)===D.threadId?`${s.activeThread||"bg-slate-600 border-slate-500"} `:`${s.threadItem||"bg-slate-700 border-slate-600 hover:bg-slate-600 text-gray-900 dark:text-slate-100"}`} ${s.threadItem||""} text-gray-900 dark:text-slate-100`,children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("div",{className:"flex-1 min-w-0",children:k===D.threadId?c.jsxs("div",{className:"flex items-center gap-2",onClick:ee=>ee.stopPropagation(),children:[c.jsx(qs,{value:A,onChange:ee=>j(ee.target.value),onKeyDown:ee=>B(ee,D.threadId),className:"h-6 text-sm",autoFocus:!0}),c.jsx(Je,{variant:"ghost",size:"sm",onClick:()=>K(D.threadId),className:"h-6 w-6 p-0",children:c.jsx(se.Check,{size:12})}),c.jsx(Je,{variant:"ghost",size:"sm",onClick:W,className:"h-6 w-6 p-0",children:c.jsx(se.X,{size:12})})]}):c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"font-medium text-sm truncate text-gray-900 dark:text-slate-100",children:ue(D)}),c.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500 dark:text-slate-400 mt-1",children:[c.jsx(se.Calendar,{size:10}),c.jsx("span",{children:F(D.updatedAt||D.createdAt)})]})]})}),c.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity ml-2",children:[r&&k!==D.threadId&&c.jsx(Je,{variant:"ghost",size:"sm",onClick:ee=>G(D,ee),className:"h-6 w-6 p-0",title:"Edit title",children:c.jsx(se.Edit3,{size:12})}),n&&c.jsx(Je,{variant:"ghost",size:"sm",onClick:ee=>M(D.threadId,ee),className:"h-6 w-6 p-0 text-red-400 hover:text-red-300 hover:bg-red-900/20",title:"Delete thread",children:c.jsx(se.Trash2,{size:12})})]})]}),i===D.threadId&&c.jsx("div",{className:"absolute left-0 top-1/2 -translate-y-1/2 w-1 h-8 bg-blue-400 rounded-r"})]},D.threadId))})})]})}function $r(e){if(!(typeof globalThis>"u"))return globalThis[e]}function xC(e){if(typeof e!="string")return;const t=e.trim();if(t)return An(t)}function tp(){const e=[$r("__API_BASE_URL__"),$r("__CHAT_API_BASE_URL__"),$r("__CHAT_API_URL__")];for(const t of e){const n=xC(t);if(n)return n}}function np(){const e=[$r("__API_AUTH_TOKEN__"),$r("__CHAT_API_KEY__"),$r("__CHAT_AUTH_TOKEN__")];for(const t of e)if(typeof t=="string"&&t.trim())return t.trim()}function rp(...e){for(const t of e)if(typeof t=="string"&&t.trim())return An(t);return An()}function op(){const e={},t=tp(),n=np();return t&&(e.baseUrl=t),n&&(e.apiKey=n),e}function sp(){const e=op(),t=Mn.getAuthToken(),n=tp();return{apiBaseUrl:rp(e.baseUrl,Mn.baseUrl,n),apiKey:t||e.apiKey||np()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,truncateToolMessages:!0,toolMessagePreviewLength:200,darkMode:!1,enableSound:!1,messageHistory:100}}const ip="chat-settings";function vC(){try{const e=localStorage.getItem(ip);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function bC(e){try{const t={...e,apiBaseUrl:An(e.apiBaseUrl)};localStorage.setItem(ip,JSON.stringify(t)),t.apiKey&&Mn.setAuthToken(t.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function wC(){const e=sp(),t=vC(),n=Mn.getAuthToken(),r=typeof t.apiBaseUrl=="string"?t.apiBaseUrl:void 0;return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:rp(Mn.baseUrl,r,e.apiBaseUrl)}}function yC(e){Mn.updateConfig({baseUrl:e.apiBaseUrl,authToken:e.apiKey??void 0}),bC(e)}var SC="Label",ap=m.forwardRef((e,t)=>c.jsx(_e.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())}}));ap.displayName=SC;var lp=ap;const CC=To.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),en=m.forwardRef(({className:e,...t},n)=>c.jsx(lp,{ref:n,className:Q(CC(),e),...t}));en.displayName=lp.displayName;function cp(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 Zs="Switch",[TC,GT]=wn(Zs),[kC,IC]=TC(Zs),up=m.forwardRef((e,t)=>{const{__scopeSwitch:n,name:r,checked:o,defaultChecked:s,required:i,disabled:a,value:l="on",onCheckedChange:u,form:d,...f}=e,[h,p]=m.useState(null),b=Ke(t,S=>p(S)),x=m.useRef(!1),g=h?d||!!h.closest("form"):!0,[v,w]=sr({prop:o,defaultProp:s??!1,onChange:u,caller:Zs});return c.jsxs(kC,{scope:n,checked:v,disabled:a,children:[c.jsx(_e.button,{type:"button",role:"switch","aria-checked":v,"aria-required":i,"data-state":pp(v),"data-disabled":a?"":void 0,disabled:a,value:l,...f,ref:b,onClick:de(e.onClick,S=>{w(N=>!N),g&&(x.current=S.isPropagationStopped(),x.current||S.stopPropagation())})}),g&&c.jsx(hp,{control:h,bubbles:!x.current,name:r,value:l,checked:v,required:i,disabled:a,form:d,style:{transform:"translateX(-100%)"}})]})});up.displayName=Zs;var dp="SwitchThumb",fp=m.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,o=IC(dp,n);return c.jsx(_e.span,{"data-state":pp(o.checked),"data-disabled":o.disabled?"":void 0,...r,ref:t})});fp.displayName=dp;var EC="SwitchBubbleInput",hp=m.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...o},s)=>{const i=m.useRef(null),a=Ke(i,s),l=cp(n),u=Tf(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 b=new Event("click",{bubbles:r});p.call(d,n),d.dispatchEvent(b)}},[l,n,r]),c.jsx("input",{type:"checkbox","aria-hidden":!0,defaultChecked:n,...o,tabIndex:-1,ref:a,style:{...o.style,...u,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});hp.displayName=EC;function pp(e){return e?"checked":"unchecked"}var mp=up,NC=fp;const Vn=m.forwardRef(({className:e,...t},n)=>c.jsx(mp,{className:Q("peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",e),...t,ref:n,children:c.jsx(NC,{className:Q("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")})}));Vn.displayName=mp.displayName;var gp=Object.freeze({position:"absolute",border:0,width:1,height:1,padding:0,margin:-1,overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",wordWrap:"normal"}),AC="VisuallyHidden",_C=m.forwardRef((e,t)=>c.jsx(_e.span,{...e,ref:t,style:{...gp,...e.style}}));_C.displayName=AC;var jC=[" ","Enter","ArrowUp","ArrowDown"],RC=[" ","Enter"],hr="Select",[Qs,ei,PC]=_a(hr),[Fr,YT]=wn(hr,[PC,Bs]),ti=Bs(),[OC,Kn]=Fr(hr),[MC,DC]=Fr(hr),xp=e=>{const{__scopeSelect:t,children:n,open:r,defaultOpen:o,onOpenChange:s,value:i,defaultValue:a,onValueChange:l,dir:u,name:d,autoComplete:f,disabled:h,required:p,form:b}=e,x=ti(t),[g,v]=m.useState(null),[w,S]=m.useState(null),[N,T]=m.useState(!1),k=As(u),[E,A]=sr({prop:r,defaultProp:o??!1,onChange:s,caller:hr}),[j,P]=sr({prop:i,defaultProp:a,onChange:l,caller:hr}),L=m.useRef(null),$=g?b||!!g.closest("form"):!0,[V,M]=m.useState(new Set),G=Array.from(V).map(K=>K.props.value).join(";");return c.jsx(Of,{...x,children:c.jsxs(OC,{required:p,scope:t,trigger:g,onTriggerChange:v,valueNode:w,onValueNodeChange:S,valueNodeHasChildren:N,onValueNodeHasChildrenChange:T,contentId:yn(),value:j,onValueChange:P,open:E,onOpenChange:A,dir:k,triggerPointerDownPosRef:L,disabled:h,children:[c.jsx(Qs.Provider,{scope:t,children:c.jsx(MC,{scope:e.__scopeSelect,onNativeOptionAdd:m.useCallback(K=>{M(W=>new Set(W).add(K))},[]),onNativeOptionRemove:m.useCallback(K=>{M(W=>{const B=new Set(W);return B.delete(K),B})},[]),children:n})}),$?c.jsxs(zp,{"aria-hidden":!0,required:p,tabIndex:-1,name:d,autoComplete:f,value:j,onChange:K=>P(K.target.value),disabled:h,form:b,children:[j===void 0?c.jsx("option",{value:""}):null,Array.from(V)]},G):null]})})};xp.displayName=hr;var vp="SelectTrigger",bp=m.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...o}=e,s=ti(n),i=Kn(vp,n),a=i.disabled||r,l=Ke(t,i.onTriggerChange),u=ei(n),d=m.useRef("touch"),[f,h,p]=Up(x=>{const g=u().filter(S=>!S.disabled),v=g.find(S=>S.value===i.value),w=Wp(g,x,v);w!==void 0&&i.onValueChange(w.value)}),b=x=>{a||(i.onOpenChange(!0),p()),x&&(i.triggerPointerDownPosRef.current={x:Math.round(x.pageX),y:Math.round(x.pageY)})};return c.jsx(Mf,{asChild:!0,...s,children:c.jsx(_e.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":Hp(i.value)?"":void 0,...o,ref:l,onClick:de(o.onClick,x=>{x.currentTarget.focus(),d.current!=="mouse"&&b(x)}),onPointerDown:de(o.onPointerDown,x=>{d.current=x.pointerType;const g=x.target;g.hasPointerCapture(x.pointerId)&&g.releasePointerCapture(x.pointerId),x.button===0&&x.ctrlKey===!1&&x.pointerType==="mouse"&&(b(x),x.preventDefault())}),onKeyDown:de(o.onKeyDown,x=>{const g=f.current!=="";!(x.ctrlKey||x.altKey||x.metaKey)&&x.key.length===1&&h(x.key),!(g&&x.key===" ")&&jC.includes(x.key)&&(b(),x.preventDefault())})})})});bp.displayName=vp;var wp="SelectValue",yp=m.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,children:s,placeholder:i="",...a}=e,l=Kn(wp,n),{onValueNodeHasChildrenChange:u}=l,d=s!==void 0,f=Ke(t,l.onValueNodeChange);return St(()=>{u(d)},[u,d]),c.jsx(_e.span,{...a,ref:f,style:{pointerEvents:"none"},children:Hp(l.value)?c.jsx(c.Fragment,{children:i}):s})});yp.displayName=wp;var LC="SelectIcon",Sp=m.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...o}=e;return c.jsx(_e.span,{"aria-hidden":!0,...o,ref:t,children:r||"▼"})});Sp.displayName=LC;var $C="SelectPortal",Cp=e=>c.jsx(hs,{asChild:!0,...e});Cp.displayName=$C;var pr="SelectContent",Tp=m.forwardRef((e,t)=>{const n=Kn(pr,e.__scopeSelect),[r,o]=m.useState();if(St(()=>{o(new DocumentFragment)},[]),!n.open){const s=r;return s?ko.createPortal(c.jsx(kp,{scope:e.__scopeSelect,children:c.jsx(Qs.Slot,{scope:e.__scopeSelect,children:c.jsx("div",{children:e.children})})}),s):null}return c.jsx(Ip,{...e,ref:t})});Tp.displayName=pr;var fn=10,[kp,qn]=Fr(pr),FC="SelectContentImpl",BC=Jn.createSlot("SelectContent.RemoveScroll"),Ip=m.forwardRef((e,t)=>{const{__scopeSelect:n,position:r="item-aligned",onCloseAutoFocus:o,onEscapeKeyDown:s,onPointerDownOutside:i,side:a,sideOffset:l,align:u,alignOffset:d,arrowPadding:f,collisionBoundary:h,collisionPadding:p,sticky:b,hideWhenDetached:x,avoidCollisions:g,...v}=e,w=Kn(pr,n),[S,N]=m.useState(null),[T,k]=m.useState(null),E=Ke(t,q=>N(q)),[A,j]=m.useState(null),[P,L]=m.useState(null),$=ei(n),[V,M]=m.useState(!1),G=m.useRef(!1);m.useEffect(()=>{if(S)return Ta(S)},[S]),va();const K=m.useCallback(q=>{const[O,...X]=$().map(re=>re.ref.current),[te]=X.slice(-1),he=document.activeElement;for(const re of q)if(re===he||(re==null||re.scrollIntoView({block:"nearest"}),re===O&&T&&(T.scrollTop=0),re===te&&T&&(T.scrollTop=T.scrollHeight),re==null||re.focus(),document.activeElement!==he))return},[$,T]),W=m.useCallback(()=>K([A,S]),[K,A,S]);m.useEffect(()=>{V&&W()},[V,W]);const{onOpenChange:B,triggerPointerDownPosRef:F}=w;m.useEffect(()=>{if(S){let q={x:0,y:0};const O=te=>{var he,re;q={x:Math.abs(Math.round(te.pageX)-(((he=F.current)==null?void 0:he.x)??0)),y:Math.abs(Math.round(te.pageY)-(((re=F.current)==null?void 0:re.y)??0))}},X=te=>{q.x<=10&&q.y<=10?te.preventDefault():S.contains(te.target)||B(!1),document.removeEventListener("pointermove",O),F.current=null};return F.current!==null&&(document.addEventListener("pointermove",O),document.addEventListener("pointerup",X,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",O),document.removeEventListener("pointerup",X,{capture:!0})}}},[S,B,F]),m.useEffect(()=>{const q=()=>B(!1);return window.addEventListener("blur",q),window.addEventListener("resize",q),()=>{window.removeEventListener("blur",q),window.removeEventListener("resize",q)}},[B]);const[ue,D]=Up(q=>{const O=$().filter(he=>!he.disabled),X=O.find(he=>he.ref.current===document.activeElement),te=Wp(O,q,X);te&&setTimeout(()=>te.ref.current.focus())}),ee=m.useCallback((q,O,X)=>{const te=!G.current&&!X;(w.value!==void 0&&w.value===O||te)&&(j(q),te&&(G.current=!0))},[w.value]),fe=m.useCallback(()=>S==null?void 0:S.focus(),[S]),we=m.useCallback((q,O,X)=>{const te=!G.current&&!X;(w.value!==void 0&&w.value===O||te)&&L(q)},[w.value]),ye=r==="popper"?al:Ep,Ce=ye===al?{side:a,sideOffset:l,align:u,alignOffset:d,arrowPadding:f,collisionBoundary:h,collisionPadding:p,sticky:b,hideWhenDetached:x,avoidCollisions:g}:{};return c.jsx(kp,{scope:n,content:S,viewport:T,onViewportChange:k,itemRefCallback:ee,selectedItem:A,onItemLeave:fe,itemTextRefCallback:we,focusSelectedItem:W,selectedItemText:P,position:r,isPositioned:V,searchRef:ue,children:c.jsx(bs,{as:BC,allowPinchZoom:!0,children:c.jsx(fs,{asChild:!0,trapped:w.open,onMountAutoFocus:q=>{q.preventDefault()},onUnmountAutoFocus:de(o,q=>{var O;(O=w.trigger)==null||O.focus({preventScroll:!0}),q.preventDefault()}),children:c.jsx(ds,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:q=>q.preventDefault(),onDismiss:()=>w.onOpenChange(!1),children:c.jsx(ye,{role:"listbox",id:w.contentId,"data-state":w.open?"open":"closed",dir:w.dir,onContextMenu:q=>q.preventDefault(),...v,...Ce,onPlaced:()=>M(!0),ref:E,style:{display:"flex",flexDirection:"column",outline:"none",...v.style},onKeyDown:de(v.onKeyDown,q=>{const O=q.ctrlKey||q.altKey||q.metaKey;if(q.key==="Tab"&&q.preventDefault(),!O&&q.key.length===1&&D(q.key),["ArrowUp","ArrowDown","Home","End"].includes(q.key)){let te=$().filter(he=>!he.disabled).map(he=>he.ref.current);if(["ArrowUp","End"].includes(q.key)&&(te=te.slice().reverse()),["ArrowUp","ArrowDown"].includes(q.key)){const he=q.target,re=te.indexOf(he);te=te.slice(re+1)}setTimeout(()=>K(te)),q.preventDefault()}})})})})})})});Ip.displayName=FC;var zC="SelectItemAlignedPosition",Ep=m.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...o}=e,s=Kn(pr,n),i=qn(pr,n),[a,l]=m.useState(null),[u,d]=m.useState(null),f=Ke(t,E=>d(E)),h=ei(n),p=m.useRef(!1),b=m.useRef(!0),{viewport:x,selectedItem:g,selectedItemText:v,focusSelectedItem:w}=i,S=m.useCallback(()=>{if(s.trigger&&s.valueNode&&a&&u&&x&&g&&v){const E=s.trigger.getBoundingClientRect(),A=u.getBoundingClientRect(),j=s.valueNode.getBoundingClientRect(),P=v.getBoundingClientRect();if(s.dir!=="rtl"){const he=P.left-A.left,re=j.left-he,pe=E.left-re,tt=E.width+pe,nt=Math.max(tt,A.width),Pe=window.innerWidth-fn,He=tl(re,[fn,Math.max(fn,Pe-nt)]);a.style.minWidth=tt+"px",a.style.left=He+"px"}else{const he=A.right-P.right,re=window.innerWidth-j.right-he,pe=window.innerWidth-E.right-re,tt=E.width+pe,nt=Math.max(tt,A.width),Pe=window.innerWidth-fn,He=tl(re,[fn,Math.max(fn,Pe-nt)]);a.style.minWidth=tt+"px",a.style.right=He+"px"}const L=h(),$=window.innerHeight-fn*2,V=x.scrollHeight,M=window.getComputedStyle(u),G=parseInt(M.borderTopWidth,10),K=parseInt(M.paddingTop,10),W=parseInt(M.borderBottomWidth,10),B=parseInt(M.paddingBottom,10),F=G+K+V+B+W,ue=Math.min(g.offsetHeight*5,F),D=window.getComputedStyle(x),ee=parseInt(D.paddingTop,10),fe=parseInt(D.paddingBottom,10),we=E.top+E.height/2-fn,ye=$-we,Ce=g.offsetHeight/2,q=g.offsetTop+Ce,O=G+K+q,X=F-O;if(O<=we){const he=L.length>0&&g===L[L.length-1].ref.current;a.style.bottom="0px";const re=u.clientHeight-x.offsetTop-x.offsetHeight,pe=Math.max(ye,Ce+(he?fe:0)+re+W),tt=O+pe;a.style.height=tt+"px"}else{const he=L.length>0&&g===L[0].ref.current;a.style.top="0px";const pe=Math.max(we,G+x.offsetTop+(he?ee:0)+Ce)+X;a.style.height=pe+"px",x.scrollTop=O-we+x.offsetTop}a.style.margin=`${fn}px 0`,a.style.minHeight=ue+"px",a.style.maxHeight=$+"px",r==null||r(),requestAnimationFrame(()=>p.current=!0)}},[h,s.trigger,s.valueNode,a,u,x,g,v,s.dir,r]);St(()=>S(),[S]);const[N,T]=m.useState();St(()=>{u&&T(window.getComputedStyle(u).zIndex)},[u]);const k=m.useCallback(E=>{E&&b.current===!0&&(S(),w==null||w(),b.current=!1)},[S,w]);return c.jsx(UC,{scope:n,contentWrapper:a,shouldExpandOnScrollRef:p,onScrollButtonChange:k,children:c.jsx("div",{ref:l,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:N},children:c.jsx(_e.div,{...o,ref:f,style:{boxSizing:"border-box",maxHeight:"100%",...o.style}})})})});Ep.displayName=zC;var HC="SelectPopperPosition",al=m.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=fn,...s}=e,i=ti(n);return c.jsx(Df,{...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)"}})});al.displayName=HC;var[UC,ll]=Fr(pr,{}),cl="SelectViewport",Np=m.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...o}=e,s=qn(cl,n),i=ll(cl,n),a=Ke(t,s.onViewportChange),l=m.useRef(0);return c.jsxs(c.Fragment,{children:[c.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}"},nonce:r}),c.jsx(Qs.Slot,{scope:n,children:c.jsx(_e.div,{"data-radix-select-viewport":"",role:"presentation",...o,ref:a,style:{position:"relative",flex:1,overflow:"hidden auto",...o.style},onScroll:de(o.onScroll,u=>{const d=u.currentTarget,{contentWrapper:f,shouldExpandOnScrollRef:h}=i;if(h!=null&&h.current&&f){const p=Math.abs(l.current-d.scrollTop);if(p>0){const b=window.innerHeight-fn*2,x=parseFloat(f.style.minHeight),g=parseFloat(f.style.height),v=Math.max(x,g);if(v<b){const w=v+p,S=Math.min(b,w),N=w-S;f.style.height=S+"px",f.style.bottom==="0px"&&(d.scrollTop=N>0?N:0,f.style.justifyContent="flex-end")}}}l.current=d.scrollTop})})})]})});Np.displayName=cl;var Ap="SelectGroup",[WC,VC]=Fr(Ap),KC=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=yn();return c.jsx(WC,{scope:n,id:o,children:c.jsx(_e.div,{role:"group","aria-labelledby":o,...r,ref:t})})});KC.displayName=Ap;var _p="SelectLabel",jp=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=VC(_p,n);return c.jsx(_e.div,{id:o.id,...r,ref:t})});jp.displayName=_p;var ni="SelectItem",[qC,Rp]=Fr(ni),Pp=m.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:s,...i}=e,a=Kn(ni,n),l=qn(ni,n),u=a.value===r,[d,f]=m.useState(s??""),[h,p]=m.useState(!1),b=Ke(t,w=>{var S;return(S=l.itemRefCallback)==null?void 0:S.call(l,w,r,o)}),x=yn(),g=m.useRef("touch"),v=()=>{o||(a.onValueChange(r),a.onOpenChange(!1))};if(r==="")throw new Error("A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.");return c.jsx(qC,{scope:n,value:r,disabled:o,textId:x,isSelected:u,onItemTextChange:m.useCallback(w=>{f(S=>S||((w==null?void 0:w.textContent)??"").trim())},[]),children:c.jsx(Qs.ItemSlot,{scope:n,value:r,disabled:o,textValue:d,children:c.jsx(_e.div,{role:"option","aria-labelledby":x,"data-highlighted":h?"":void 0,"aria-selected":u&&h,"data-state":u?"checked":"unchecked","aria-disabled":o||void 0,"data-disabled":o?"":void 0,tabIndex:o?void 0:-1,...i,ref:b,onFocus:de(i.onFocus,()=>p(!0)),onBlur:de(i.onBlur,()=>p(!1)),onClick:de(i.onClick,()=>{g.current!=="mouse"&&v()}),onPointerUp:de(i.onPointerUp,()=>{g.current==="mouse"&&v()}),onPointerDown:de(i.onPointerDown,w=>{g.current=w.pointerType}),onPointerMove:de(i.onPointerMove,w=>{var S;g.current=w.pointerType,o?(S=l.onItemLeave)==null||S.call(l):g.current==="mouse"&&w.currentTarget.focus({preventScroll:!0})}),onPointerLeave:de(i.onPointerLeave,w=>{var S;w.currentTarget===document.activeElement&&((S=l.onItemLeave)==null||S.call(l))}),onKeyDown:de(i.onKeyDown,w=>{var N;((N=l.searchRef)==null?void 0:N.current)!==""&&w.key===" "||(RC.includes(w.key)&&v(),w.key===" "&&w.preventDefault())})})})})});Pp.displayName=ni;var yo="SelectItemText",Op=m.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,...s}=e,i=Kn(yo,n),a=qn(yo,n),l=Rp(yo,n),u=DC(yo,n),[d,f]=m.useState(null),h=Ke(t,v=>f(v),l.onItemTextChange,v=>{var w;return(w=a.itemTextRefCallback)==null?void 0:w.call(a,v,l.value,l.disabled)}),p=d==null?void 0:d.textContent,b=m.useMemo(()=>c.jsx("option",{value:l.value,disabled:l.disabled,children:p},l.value),[l.disabled,l.value,p]),{onNativeOptionAdd:x,onNativeOptionRemove:g}=u;return St(()=>(x(b),()=>g(b)),[x,g,b]),c.jsxs(c.Fragment,{children:[c.jsx(_e.span,{id:l.textId,...s,ref:h}),l.isSelected&&i.valueNode&&!i.valueNodeHasChildren?ko.createPortal(s.children,i.valueNode):null]})});Op.displayName=yo;var Mp="SelectItemIndicator",Dp=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return Rp(Mp,n).isSelected?c.jsx(_e.span,{"aria-hidden":!0,...r,ref:t}):null});Dp.displayName=Mp;var ul="SelectScrollUpButton",Lp=m.forwardRef((e,t)=>{const n=qn(ul,e.__scopeSelect),r=ll(ul,e.__scopeSelect),[o,s]=m.useState(!1),i=Ke(t,r.onScrollButtonChange);return St(()=>{if(n.viewport&&n.isPositioned){let a=function(){const u=l.scrollTop>0;s(u)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?c.jsx(Fp,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop-l.offsetHeight)}}):null});Lp.displayName=ul;var dl="SelectScrollDownButton",$p=m.forwardRef((e,t)=>{const n=qn(dl,e.__scopeSelect),r=ll(dl,e.__scopeSelect),[o,s]=m.useState(!1),i=Ke(t,r.onScrollButtonChange);return St(()=>{if(n.viewport&&n.isPositioned){let a=function(){const u=l.scrollHeight-l.clientHeight,d=Math.ceil(l.scrollTop)<u;s(d)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?c.jsx(Fp,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop+l.offsetHeight)}}):null});$p.displayName=dl;var Fp=m.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...o}=e,s=qn("SelectScrollButton",n),i=m.useRef(null),a=ei(n),l=m.useCallback(()=>{i.current!==null&&(window.clearInterval(i.current),i.current=null)},[]);return m.useEffect(()=>()=>l(),[l]),St(()=>{var d;const u=a().find(f=>f.ref.current===document.activeElement);(d=u==null?void 0:u.ref.current)==null||d.scrollIntoView({block:"nearest"})},[a]),c.jsx(_e.div,{"aria-hidden":!0,...o,ref:t,style:{flexShrink:0,...o.style},onPointerDown:de(o.onPointerDown,()=>{i.current===null&&(i.current=window.setInterval(r,50))}),onPointerMove:de(o.onPointerMove,()=>{var u;(u=s.onItemLeave)==null||u.call(s),i.current===null&&(i.current=window.setInterval(r,50))}),onPointerLeave:de(o.onPointerLeave,()=>{l()})})}),GC="SelectSeparator",Bp=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return c.jsx(_e.div,{"aria-hidden":!0,...r,ref:t})});Bp.displayName=GC;var fl="SelectArrow",YC=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=ti(n),s=Kn(fl,n),i=qn(fl,n);return s.open&&i.position==="popper"?c.jsx(Lf,{...o,...r,ref:t}):null});YC.displayName=fl;var XC="SelectBubbleInput",zp=m.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const o=m.useRef(null),s=Ke(r,o),i=cp(t);return m.useEffect(()=>{const a=o.current;if(!a)return;const l=window.HTMLSelectElement.prototype,d=Object.getOwnPropertyDescriptor(l,"value").set;if(i!==t&&d){const f=new Event("change",{bubbles:!0});d.call(a,t),a.dispatchEvent(f)}},[i,t]),c.jsx(_e.select,{...n,style:{...gp,...n.style},ref:s,defaultValue:t})});zp.displayName=XC;function Hp(e){return e===""||e===void 0}function Up(e){const t=kt(e),n=m.useRef(""),r=m.useRef(0),o=m.useCallback(i=>{const a=n.current+i;t(a),function l(u){n.current=u,window.clearTimeout(r.current),u!==""&&(r.current=window.setTimeout(()=>l(""),1e3))}(a)},[t]),s=m.useCallback(()=>{n.current="",window.clearTimeout(r.current)},[]);return m.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,o,s]}function Wp(e,t,n){const o=t.length>1&&Array.from(t).every(u=>u===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let i=JC(e,Math.max(s,0));o.length===1&&(i=i.filter(u=>u!==n));const l=i.find(u=>u.textValue.toLowerCase().startsWith(o.toLowerCase()));return l!==n?l:void 0}function JC(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var ZC=xp,Vp=bp,QC=yp,eT=Sp,tT=Cp,Kp=Tp,nT=Np,qp=jp,Gp=Pp,rT=Op,oT=Dp,Yp=Lp,Xp=$p,Jp=Bp;const Zp=ZC,Qp=QC,hl=m.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(Vp,{ref:r,className:Q("flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",e),...n,children:[t,c.jsx(eT,{asChild:!0,children:c.jsx(se.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));hl.displayName=Vp.displayName;const em=m.forwardRef(({className:e,...t},n)=>c.jsx(Yp,{ref:n,className:Q("flex cursor-default items-center justify-center py-1",e),...t,children:c.jsx(se.ChevronUp,{className:"h-4 w-4"})}));em.displayName=Yp.displayName;const tm=m.forwardRef(({className:e,...t},n)=>c.jsx(Xp,{ref:n,className:Q("flex cursor-default items-center justify-center py-1",e),...t,children:c.jsx(se.ChevronDown,{className:"h-4 w-4"})}));tm.displayName=Xp.displayName;const pl=m.forwardRef(({className:e,children:t,position:n="popper",...r},o)=>c.jsx(tT,{children:c.jsxs(Kp,{ref:o,className:Q("relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",n==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",e),position:n,...r,children:[c.jsx(em,{}),c.jsx(nT,{className:Q("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),c.jsx(tm,{})]})}));pl.displayName=Kp.displayName;const sT=m.forwardRef(({className:e,...t},n)=>c.jsx(qp,{ref:n,className:Q("py-1.5 pl-8 pr-2 text-sm font-semibold",e),...t}));sT.displayName=qp.displayName;const mr=m.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(Gp,{ref:r,className:Q("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[c.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:c.jsx(oT,{children:c.jsx(se.Check,{className:"h-4 w-4"})})}),c.jsx(rT,{children:t})]}));mr.displayName=Gp.displayName;const iT=m.forwardRef(({className:e,...t},n)=>c.jsx(Jp,{ref:n,className:Q("-mx-1 my-1 h-px bg-muted",e),...t}));iT.displayName=Jp.displayName;var aT="Separator",nm="horizontal",lT=["horizontal","vertical"],rm=m.forwardRef((e,t)=>{const{decorative:n,orientation:r=nm,...o}=e,s=cT(r)?r:nm,a=n?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return c.jsx(_e.div,{"data-orientation":s,...a,...o,ref:t})});rm.displayName=aT;function cT(e){return lT.includes(e)}var om=rm;const sm=m.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},o)=>c.jsx(om,{ref:o,decorative:n,orientation:t,className:Q("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));sm.displayName=om.displayName;const uT=zd,dT=Ww,fT=Hd,im=m.forwardRef(({className:e,...t},n)=>c.jsx(Ts,{className:Q("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}));im.displayName=Ts.displayName;const hT=To.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"}}),am=m.forwardRef(({side:e="right",className:t,children:n,...r},o)=>c.jsxs(fT,{children:[c.jsx(im,{}),c.jsxs(ks,{ref:o,className:Q(hT({side:e}),t),...r,children:[n,c.jsxs(Ud,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-secondary",children:[c.jsx(se.X,{className:"h-4 w-4"}),c.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));am.displayName=ks.displayName;const lm=({className:e,...t})=>c.jsx("div",{className:Q("flex flex-col space-y-2 text-center sm:text-left",e),...t});lm.displayName="SheetHeader";const cm=m.forwardRef(({className:e,...t},n)=>c.jsx(lr,{ref:n,className:Q("text-lg font-semibold text-foreground",e),...t}));cm.displayName=lr.displayName;const um=m.forwardRef(({className:e,...t},n)=>c.jsx(Is,{ref:n,className:Q("text-sm text-muted-foreground",e),...t}));um.displayName=Is.displayName;const pT={api:{baseUrl:"http://localhost:8000/api",authToken:"",enableAuth:!1},ui:{layout:"sidebar",theme:"light",showTimestamps:!0,showAgentNames:!0,compactMessages:!1},behavior:{autoSave:!0,enableStreaming:!0,showTypingIndicator:!0}};function mT({settings:e,onSettingsChange:t,className:n=""}){const[r,o]=y.useState(!1),[s,i]=y.useState(!1),[a,l]=y.useState(e),[u,d]=y.useState(!1),{toast:f}=ha();y.useEffect(()=>{const g=JSON.stringify(a)!==JSON.stringify(e);d(g)},[a,e]),y.useEffect(()=>{l(e)},[e]);const h=()=>{t(a),d(!1),f({title:"Settings saved",description:"Your chat configuration has been updated successfully."})},p=()=>{l(pT),d(!0),f({title:"Settings reset",description:"Configuration has been reset to defaults."})},b=()=>{l(e),d(!1),o(!1)},x=async()=>{try{const v=await(await fetch(`${a.api.baseUrl}/health`)).json();f({title:"Connection successful",description:`API is ${v.status||"healthy"}`})}catch{f({title:"Connection failed",description:"Unable to connect to the API endpoint.",variant:"destructive"})}};return c.jsxs(uT,{open:r,onOpenChange:o,children:[c.jsx(dT,{asChild:!0,children:c.jsxs(Je,{variant:"outline",size:"sm",className:n,children:[c.jsx(se.Settings,{className:"h-4 w-4 mr-2"}),"Settings",u&&c.jsx(ra,{variant:"destructive",className:"ml-2 h-4 w-4 p-0"})]})}),c.jsxs(am,{className:"w-[500px] sm:w-[600px] overflow-y-auto",children:[c.jsxs(lm,{children:[c.jsx(cm,{children:"Chat Settings"}),c.jsx(um,{children:"Configure your chat interface, API connection, and behavior preferences."})]}),c.jsxs("div",{className:"space-y-6 py-6",children:[c.jsxs(io,{children:[c.jsx(ao,{className:"pb-3",children:c.jsxs(lo,{className:"text-lg flex items-center gap-2",children:[c.jsx(se.Server,{className:"h-5 w-5"}),"API Configuration"]})}),c.jsxs(os,{className:"space-y-4",children:[c.jsxs("div",{className:"space-y-2",children:[c.jsx(en,{htmlFor:"api-url",children:"API Base URL"}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx(qs,{id:"api-url",value:a.api.baseUrl,onChange:g=>l(v=>({...v,api:{...v.api,baseUrl:g.target.value}})),placeholder:"http://localhost:8000/api"}),c.jsx(Je,{variant:"outline",onClick:x,children:"Test"})]})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx(en,{htmlFor:"enable-auth",children:"Enable Authentication"}),c.jsx(Vn,{id:"enable-auth",checked:a.api.enableAuth,onCheckedChange:g=>l(v=>({...v,api:{...v.api,enableAuth:g}}))})]}),a.api.enableAuth&&c.jsxs("div",{className:"space-y-2",children:[c.jsx(en,{htmlFor:"auth-token",children:"Authentication Token"}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx(qs,{id:"auth-token",type:s?"text":"password",value:a.api.authToken,onChange:g=>l(v=>({...v,api:{...v.api,authToken:g.target.value}})),placeholder:"Enter your Bearer token"}),c.jsx(Je,{variant:"outline",size:"icon",onClick:()=>i(!s),children:s?c.jsx(se.EyeOff,{className:"h-4 w-4"}):c.jsx(se.Eye,{className:"h-4 w-4"})})]})]})]})]}),c.jsxs(io,{children:[c.jsx(ao,{className:"pb-3",children:c.jsxs(lo,{className:"text-lg flex items-center gap-2",children:[c.jsx(se.Layout,{className:"h-5 w-5"}),"Interface Settings"]})}),c.jsxs(os,{className:"space-y-4",children:[c.jsxs("div",{className:"space-y-2",children:[c.jsx(en,{htmlFor:"layout",children:"Layout Style"}),c.jsxs(Zp,{value:a.ui.layout,onValueChange:g=>l(v=>({...v,ui:{...v.ui,layout:g}})),children:[c.jsx(hl,{children:c.jsx(Qp,{})}),c.jsxs(pl,{children:[c.jsx(mr,{value:"sidebar",children:"Sidebar Layout"}),c.jsx(mr,{value:"fullscreen",children:"Fullscreen"}),c.jsx(mr,{value:"tabs",children:"Tabbed Interface"})]})]})]}),c.jsxs("div",{className:"space-y-2",children:[c.jsx(en,{htmlFor:"theme",children:"Theme"}),c.jsxs(Zp,{value:a.ui.theme,onValueChange:g=>l(v=>({...v,ui:{...v.ui,theme:g}})),children:[c.jsx(hl,{children:c.jsx(Qp,{})}),c.jsxs(pl,{children:[c.jsx(mr,{value:"light",children:"Light"}),c.jsx(mr,{value:"dark",children:"Dark"}),c.jsx(mr,{value:"system",children:"System"})]})]})]}),c.jsx(sm,{}),c.jsxs("div",{className:"space-y-3",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx(en,{htmlFor:"show-timestamps",children:"Show Timestamps"}),c.jsx(Vn,{id:"show-timestamps",checked:a.ui.showTimestamps,onCheckedChange:g=>l(v=>({...v,ui:{...v.ui,showTimestamps:g}}))})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx(en,{htmlFor:"show-agent-names",children:"Show Agent Names"}),c.jsx(Vn,{id:"show-agent-names",checked:a.ui.showAgentNames,onCheckedChange:g=>l(v=>({...v,ui:{...v.ui,showAgentNames:g}}))})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx(en,{htmlFor:"compact-messages",children:"Compact Messages"}),c.jsx(Vn,{id:"compact-messages",checked:a.ui.compactMessages,onCheckedChange:g=>l(v=>({...v,ui:{...v.ui,compactMessages:g}}))})]})]})]})]}),c.jsxs(io,{children:[c.jsx(ao,{className:"pb-3",children:c.jsxs(lo,{className:"text-lg flex items-center gap-2",children:[c.jsx(se.MessageCircle,{className:"h-5 w-5"}),"Behavior Settings"]})}),c.jsxs(os,{className:"space-y-4",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx(en,{htmlFor:"auto-save",children:"Auto-save Conversations"}),c.jsx("p",{className:"text-sm text-muted-foreground",children:"Automatically save messages to threads"})]}),c.jsx(Vn,{id:"auto-save",checked:a.behavior.autoSave,onCheckedChange:g=>l(v=>({...v,behavior:{...v.behavior,autoSave:g}}))})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx(en,{htmlFor:"enable-streaming",children:"Enable Streaming"}),c.jsx("p",{className:"text-sm text-muted-foreground",children:"Stream responses in real-time"})]}),c.jsx(Vn,{id:"enable-streaming",checked:a.behavior.enableStreaming,onCheckedChange:g=>l(v=>({...v,behavior:{...v.behavior,enableStreaming:g}}))})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx(en,{htmlFor:"typing-indicator",children:"Typing Indicator"}),c.jsx("p",{className:"text-sm text-muted-foreground",children:"Show typing indicator during responses"})]}),c.jsx(Vn,{id:"typing-indicator",checked:a.behavior.showTypingIndicator,onCheckedChange:g=>l(v=>({...v,behavior:{...v.behavior,showTypingIndicator:g}}))})]})]})]})]}),c.jsxs("div",{className:"flex items-center justify-between pt-6 border-t",children:[c.jsxs(Je,{variant:"outline",onClick:p,children:[c.jsx(se.RotateCcw,{className:"h-4 w-4 mr-2"}),"Reset"]}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx(Je,{variant:"outline",onClick:b,children:"Cancel"}),c.jsxs(Je,{onClick:h,disabled:!u,children:[c.jsx(se.Save,{className:"h-4 w-4 mr-2"}),"Save Changes"]})]})]})]})]})}function gT({layout:e="sidebar",layoutSize:t="desktop",showThreads:n=!0,className:r="",customStyles:o={},...s}){const i=u=>{const d="h-full";switch(u){case"phone":return`${d} max-w-none`;case"tablet":return`${d} max-w-4xl mx-auto`;case"half-screen":return`${d} max-w-2xl`;case"desktop":default:return`${d} max-w-7xl mx-auto`}},a=u=>({"--chat-sidebar-width":u==="phone"?"100%":u==="tablet"?"280px":u==="half-screen"?"240px":"320px","--chat-message-max-width":u==="phone"?"95%":u==="tablet"?"90%":u==="half-screen"?"85%":"80%","--chat-input-height":u==="phone"?"120px":"100px"}),l=y.useCallback(u=>{var d;(d=s.onThreadChange)==null||d.call(s,u)},[s]);return e==="fullscreen"?c.jsx(Ho,{...s,onThreadChange:l,children:c.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:c.jsx(Ks,{className:"flex-1",onError:s.onError,enableFileUpload:!0})})}):e==="tabs"?c.jsx(Ho,{...s,onThreadChange:l,children:c.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:c.jsxs("div",{className:"flex-1 flex min-h-0 overflow-hidden",children:[n&&c.jsx("div",{className:`w-80 border-r flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:c.jsx(il,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),c.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:c.jsx(Ks,{onError:s.onError,enableFileUpload:!0})})]})})}):c.jsx(Ho,{...s,onThreadChange:l,children:c.jsxs("div",{className:`${i(t)} flex overflow-hidden ${r} ${o.container||""}`,style:a(t),children:[n&&c.jsx("div",{className:`w-80 border-r bg-gray-50 flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:c.jsx(il,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),c.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:c.jsx(Ks,{onError:s.onError,enableFileUpload:!0})})]})})}je.ChatApi=cc,je.ChatInterface=Ks,je.ChatProviders=Ho,je.ChatSettings=mT,je.MarkdownContent=ua,je.MessageComponent=Zd,je.MessageList=Aa,je.ThreadManager=il,je.applySettings=yC,je.chatApiClient=Mn,je.default=gT,je.del=lc,je.get=on,je.getChatToken=sc,je.getCurrentSettings=wC,je.getDefaultApiConfig=op,je.getDefaultChatSettings=sp,je.onChatTokenChanged=ic,je.post=yi,je.put=ac,je.setChatToken=wi,je.useApi=Si,je.useChatStream=kc,je.useMessagesReducer=gc,je.useStream=jc,je.useThreadState=zo,je.useThreads=Bo,Object.defineProperties(je,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|