teodor-new-chat-ui 4.3.1 → 4.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.esm.js +4590 -4530
- package/dist/index.umd.js +46 -46
- package/dist/lib/historyUtils.d.ts +17 -8
- 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 \``+I+"`."}return""}}function
|
|
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} />`,z,C,xe,C),Rn[C+z]=!0}}return I===r?Fr(pt):$r(pt),pt}}function we(I,H,te){return se(I,H,te,!0)}function Ue(I,H,te){return se(I,H,te,!1)}var it=Ue,Ot=we;zr.Fragment=r,zr.jsx=it,zr.jsxs=Ot}()),zr}process.env.NODE_ENV==="production"?ri.exports=fm():ri.exports=hm();var c=ri.exports;function ml(e,t){return function(){return e.apply(t,arguments)}}const{toString:pm}=Object.prototype,{getPrototypeOf:oi}=Object,{iterator:Co,toStringTag:gl}=Symbol,To=(e=>t=>{const n=pm.call(t);return e[n]||(e[n]=n.slice(8,-1).toLowerCase())})(Object.create(null)),en=e=>(e=e.toLowerCase(),t=>To(t)===e),ko=e=>t=>typeof t===e,{isArray:vr}=Array,br=ko("undefined");function Hr(e){return e!==null&&!br(e)&&e.constructor!==null&&!br(e.constructor)&&Mt(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const xl=en("ArrayBuffer");function mm(e){let t;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?t=ArrayBuffer.isView(e):t=e&&e.buffer&&xl(e.buffer),t}const gm=ko("string"),Mt=ko("function"),vl=ko("number"),Ur=e=>e!==null&&typeof e=="object",xm=e=>e===!0||e===!1,Io=e=>{if(To(e)!=="object")return!1;const t=oi(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(gl in e)&&!(Co in e)},vm=e=>{if(!Ur(e)||Hr(e))return!1;try{return Object.keys(e).length===0&&Object.getPrototypeOf(e)===Object.prototype}catch{return!1}},bm=en("Date"),wm=en("File"),ym=en("Blob"),Sm=en("FileList"),Cm=e=>Ur(e)&&Mt(e.pipe),Tm=e=>{let t;return e&&(typeof FormData=="function"&&e instanceof FormData||Mt(e.append)&&((t=To(e))==="formdata"||t==="object"&&Mt(e.toString)&&e.toString()==="[object FormData]"))},km=en("URLSearchParams"),[Im,Em,Nm,Am]=["ReadableStream","Request","Response","Headers"].map(en),_m=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]),vr(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 bl(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 Zn=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global,wl=e=>!br(e)&&e!==Zn;function si(){const{caseless:e,skipUndefined:t}=wl(this)&&this||{},n={},r=(o,s)=>{const i=e&&bl(n,s)||s;Io(n[i])&&Io(o)?n[i]=si(n[i],o):Io(o)?n[i]=si({},o):vr(o)?n[i]=o.slice():(!t||!br(o))&&(n[i]=o)};for(let o=0,s=arguments.length;o<s;o++)arguments[o]&&Wr(arguments[o],r);return n}const jm=(e,t,n,{allOwnKeys:r}={})=>(Wr(t,(o,s)=>{n&&Mt(o)?e[s]=ml(o,n):e[s]=o},{allOwnKeys:r}),e),Rm=e=>(e.charCodeAt(0)===65279&&(e=e.slice(1)),e),Pm=(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)},Om=(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&&oi(e)}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},Mm=(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},Dm=e=>{if(!e)return null;if(vr(e))return e;let t=e.length;if(!vl(t))return null;const n=new Array(t);for(;t-- >0;)n[t]=e[t];return n},Lm=(e=>t=>e&&t instanceof e)(typeof Uint8Array<"u"&&oi(Uint8Array)),$m=(e,t)=>{const r=(e&&e[Co]).call(e);let o;for(;(o=r.next())&&!o.done;){const s=o.value;t.call(e,s[0],s[1])}},Fm=(e,t)=>{let n;const r=[];for(;(n=e.exec(t))!==null;)r.push(n);return r},Bm=en("HTMLFormElement"),zm=e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(n,r,o){return r.toUpperCase()+o}),yl=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),Hm=en("RegExp"),Sl=(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)},Um=e=>{Sl(e,(t,n)=>{if(Mt(e)&&["arguments","caller","callee"].indexOf(n)!==-1)return!1;const r=e[n];if(Mt(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+"'")})}})},Wm=(e,t)=>{const n={},r=o=>{o.forEach(s=>{n[s]=!0})};return vr(e)?r(e):r(String(e).split(t)),n},Vm=()=>{},qm=(e,t)=>e!=null&&Number.isFinite(e=+e)?e:t;function Km(e){return!!(e&&Mt(e.append)&&e[gl]==="FormData"&&e[Co])}const Gm=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=vr(r)?[]:{};return Wr(r,(i,a)=>{const l=n(i,o+1);!br(l)&&(s[a]=l)}),t[o]=void 0,s}}return r};return n(e,0)},Ym=en("AsyncFunction"),Xm=e=>e&&(Ur(e)||Mt(e))&&Mt(e.then)&&Mt(e.catch),Cl=((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",Mt(Zn.postMessage)),Jm=typeof queueMicrotask<"u"?queueMicrotask.bind(Zn):typeof process<"u"&&process.nextTick||Cl,R={isArray:vr,isArrayBuffer:xl,isBuffer:Hr,isFormData:Tm,isArrayBufferView:mm,isString:gm,isNumber:vl,isBoolean:xm,isObject:Ur,isPlainObject:Io,isEmptyObject:vm,isReadableStream:Im,isRequest:Em,isResponse:Nm,isHeaders:Am,isUndefined:br,isDate:bm,isFile:wm,isBlob:ym,isRegExp:Hm,isFunction:Mt,isStream:Cm,isURLSearchParams:km,isTypedArray:Lm,isFileList:Sm,forEach:Wr,merge:si,extend:jm,trim:_m,stripBOM:Rm,inherits:Pm,toFlatObject:Om,kindOf:To,kindOfTest:en,endsWith:Mm,toArray:Dm,forEachEntry:$m,matchAll:Fm,isHTMLForm:Bm,hasOwnProperty:yl,hasOwnProp:yl,reduceDescriptors:Sl,freezeMethods:Um,toObjectSet:Wm,toCamelCase:zm,noop:Vm,toFiniteNumber:qm,findKey:bl,global:Zn,isContextDefined:wl,isSpecCompliantForm:Km,toJSONObject:Gm,isAsyncFn:Ym,isThenable:Xm,setImmediate:Cl,asap:Jm,isIterable:e=>e!=null&&Mt(e[Co])};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 Tl=De.prototype,kl={};["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=>{kl[e]={value:e}}),Object.defineProperties(De,kl),Object.defineProperty(Tl,"isAxiosError",{value:!0}),De.from=(e,t,n,r,o,s)=>{const i=Object.create(Tl);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 Zm=null;function ii(e){return R.isPlainObject(e)||R.isArray(e)}function Il(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=Il(o),!n&&s?"["+o+"]":o}).join(n?".":""):t}function Qm(e){return R.isArray(e)&&!e.some(ii)}const eg=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(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)&&Qm(b)||(R.isFileList(b)||R.endsWith(x,"[]"))&&(v=R.toArray(b)))return x=Il(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 ii(b)?!0:(t.append(El(g,x,s),u(b)),!1)}const f=[],h=Object.assign(eg,{defaultVisitor:d,convertValue:u,isVisitable:ii});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 Nl(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,function(r){return t[r]})}function ai(e,t){this._pairs=[],e&&Eo(e,this,t)}const Al=ai.prototype;Al.append=function(t,n){this._pairs.push([t,n])},Al.toString=function(t){const n=t?function(r){return t.call(this,r,Nl)}:Nl;return this._pairs.map(function(o){return n(o[0])+"="+n(o[1])},"").join("&")};function tg(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+")}function _l(e,t,n){if(!t)return e;const r=n&&n.encode||tg;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 ai(t,n).toString(r),s){const i=e.indexOf("#");i!==-1&&(e=e.slice(0,i)),e+=(e.indexOf("?")===-1?"?":"&")+s}return e}class jl{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 Rl={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},ng={isBrowser:!0,classes:{URLSearchParams:typeof URLSearchParams<"u"?URLSearchParams:ai,FormData:typeof FormData<"u"?FormData:null,Blob:typeof Blob<"u"?Blob:null},protocols:["http","https","file","blob","url","data"]},li=typeof window<"u"&&typeof document<"u",ci=typeof navigator=="object"&&navigator||void 0,rg=li&&(!ci||["ReactNative","NativeScript","NS"].indexOf(ci.product)<0),og=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function",sg=li&&window.location.href||"http://localhost",kt={...Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv:li,hasStandardBrowserEnv:rg,hasStandardBrowserWebWorkerEnv:og,navigator:ci,origin:sg},Symbol.toStringTag,{value:"Module"})),...ng};function ig(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 ag(e){return R.matchAll(/\w+|\[(\w*)]/g,e).map(t=>t[0]==="[]"?"":t[1]||t[0])}function lg(e){const t={},n=Object.keys(e);let r;const o=n.length;let s;for(r=0;r<o;r++)s=n[r],t[s]=e[s];return t}function Pl(e){function t(n,r,o,s){let i=n[s++];if(i==="__proto__")return!0;const a=Number.isFinite(+i),l=s>=n.length;return i=!i&&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]=lg(o[i])),!a)}if(R.isFormData(e)&&R.isFunction(e.entries)){const n={};return R.forEachEntry(e,(r,o)=>{t(ag(r),o,n,0)}),n}return null}function cg(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:Rl,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(Pl(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 ig(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),cg(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 ug=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"]),dg=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[Ol]=this[Ol]={accessors:{}}).accessors,o=this.prototype;function s(i){const a=qr(i);r[a]||(mg(o,i),r[a]=!0)}return R.isArray(t)?t.forEach(s):s(t),this}};Dt.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),R.reduceDescriptors(Dt.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(r){this[n]=r}}}),R.freezeMethods(Dt);function di(e,t){const n=this||Vr,r=t||n,o=Dt.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 Ml(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 Dl(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 gg(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function xg(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 vg(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 Ao=(e,t,n=3)=>{let r=0;const o=xg(50,250);return vg(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)},Ll=(e,t)=>{const n=e!=null;return[r=>t[0]({lengthComputable:n,total:e,loaded:r}),t[1]]},$l=e=>(...t)=>R.asap(()=>e(...t)),bg=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,wg=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 yg(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function Sg(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function Fl(e,t,n){let r=!yg(t);return e&&(r||n==!1)?Sg(e,t):t}const Bl=e=>e instanceof Dt?{...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(Bl(u),Bl(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 zl=e=>{const t=Qn({},e);let{data:n,withXSRFToken:r,xsrfHeaderName:o,xsrfCookieName:s,headers:i,auth:a}=t;if(t.headers=i=Dt.from(i),t.url=_l(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&&bg(t.url))){const l=o&&s&&wg.read(s);l&&i.set(o,l)}return t},Cg=typeof XMLHttpRequest<"u"&&function(e){return new Promise(function(n,r){const o=zl(e);let s=o.data;const i=Dt.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=Dt.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};Dl(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||Rl;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]=Ao(u,!0),g.addEventListener("progress",h)),l&&g.upload&&([f,p]=Ao(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 w=gg(o.url);if(w&&kt.protocols.indexOf(w)===-1){r(new De("Unsupported protocol "+w+":",De.ERR_BAD_REQUEST,e));return}g.send(s||null)})},Tg=(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}},kg=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},Ig=async function*(e,t){for await(const n of Eg(e))yield*kg(n,t)},Eg=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()}},Hl=(e,t,n,r)=>{const o=Ig(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})},Ul=64*1024,{isFunction:_o}=R,Ng=(({Request:e,Response:t})=>({Request:e,Response:t}))(R.global),{ReadableStream:Wl,TextEncoder:Vl}=R.global,ql=(e,...t)=>{try{return!!e(...t)}catch{return!1}},Ag=e=>{e=R.merge.call({skipUndefined:!0},Ng,e);const{fetch:t,Request:n,Response:r}=e,o=t?_o(t):typeof fetch=="function",s=_o(n),i=_o(r);if(!o)return!1;const a=o&&_o(Wl),l=o&&(typeof Vl=="function"?(b=>x=>b.encode(x))(new Vl):async b=>new Uint8Array(await new n(b).arrayBuffer())),u=s&&a&&ql(()=>{let b=!1;const x=new n(kt.origin,{body:new Wl,method:"POST",get duplex(){return b=!0,"half"}}).headers.has("Content-Type");return b&&!x}),d=i&&a&&ql(()=>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(kt.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}=zl(b),L=t||fetch;E=E?(E+"").toLowerCase():"text";let $=Tg([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"}),Q;if(R.isFormData(v)&&(Q=D.headers.get("content-type"))&&A.setContentType(Q),D.body){const[de,be]=Ll(G,Ao($l(k)));v=Hl(D.body,Ul,de,be)}}R.isString(j)||(j=j?"include":"omit");const q=s&&"credentials"in n.prototype,W={...P,signal:$,method:g.toUpperCase(),headers:A.normalize().toJSON(),body:v,duplex:"half",credentials:q?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 Q=R.toFiniteNumber(B.headers.get("content-length")),[de,be]=T&&Ll(Q,Ao($l(T),!0))||[];B=new r(Hl(B.body,Ul,de,()=>{be&&be(),M&&M()}),D)}E=E||"text";let le=await f[R.findKey(f,E)||"text"](B,b);return!F&&M&&M(),await new Promise((D,Q)=>{Dl(D,Q,{data:le,headers:Dt.from(B.headers),status:B.status,statusText:B.statusText,config:b,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,b,V),{cause:q.cause||q}):De.from(q,q&&q.code,b,V)}}},_g=new Map,Kl=e=>{let t=e?e.env:{};const{fetch:n,Request:r,Response:o}=t,s=[r,o,n];let i=s.length,a=i,l,u,d=_g;for(;a--;)l=s[a],u=d.get(l),u===void 0&&d.set(l,u=a?new Map:Ag(t)),d=u;return u};Kl();const fi={http:Zm,xhr:Cg,fetch:{get:Kl}};R.forEach(fi,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const Gl=e=>`- ${e}`,jg=e=>R.isFunction(e)||e===null||e===!1,Yl={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,!jg(r)&&(o=fi[(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=Qn(this.defaults,n);const{transitional:r,paramsSerializer:o,headers:s}=n;r!==void 0&&Ro.assertOptions(r,{silentJSONParsing:fn.transitional(fn.boolean),forcedJSONParsing:fn.transitional(fn.boolean),clarifyTimeoutError:fn.transitional(fn.boolean)},!1),o!=null&&(R.isFunction(o)?n.paramsSerializer={serialize:o}:Ro.assertOptions(o,{encode:fn.function,serialize:fn.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),Ro.assertOptions(n,{baseUrl:fn.spelling("baseURL"),withXsrfToken:fn.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=Dt.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=[Xl.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=Xl.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=Fl(t.baseURL,t.url,t.allowAbsoluteUrls);return _l(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 Pg=class cm{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 cm(function(o){t=o}),cancel:t}}};function Og(e){return function(n){return e.apply(null,n)}}function Mg(e){return R.isObject(e)&&e.isAxiosError===!0}const pi={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(pi).forEach(([e,t])=>{pi[t]=e});function Ql(e){const t=new er(e),n=ml(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 Ql(Qn(e,o))},n}const mt=Ql(Vr);mt.Axios=er,mt.CanceledError=wr,mt.CancelToken=Pg,mt.isCancel=Ml,mt.VERSION=Jl,mt.toFormData=Eo,mt.AxiosError=De,mt.Cancel=mt.CanceledError,mt.all=function(t){return Promise.all(t)},mt.spread=Og,mt.isAxiosError=Mg,mt.mergeConfig=Qn,mt.AxiosHeaders=Dt,mt.formToJSON=e=>Pl(R.isHTMLForm(e)?new FormData(e):e),mt.getAdapter=Yl.getAdapter,mt.HttpStatusCode=pi,mt.default=mt;const{Axios:ST,AxiosError:CT,CanceledError:TT,isCancel:kT,CancelToken:IT,VERSION:ET,all:NT,Cancel:AT,isAxiosError:_T,spread:jT,toFormData:RT,AxiosHeaders:PT,HttpStatusCode:OT,formToJSON:MT,getAdapter:DT,mergeConfig:LT}=mt,ec=typeof window<"u"?window.__API_BASE_URL__:void 0,tc=ec?En(ec):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 Po=null;const mi=new Set;function nc(){return Po}function gi(e){Po=e,mi.forEach(t=>t(e))}function rc(e){return mi.add(e),()=>mi.delete(e)}const qt=mt.create({...tc?{baseURL:tc}:{},timeout:3e4,withCredentials:!0});qt.interceptors.request.use(e=>(Po&&(e.headers.Authorization=`Bearer ${Po}`),e)),qt.interceptors.response.use(e=>e,e=>Promise.reject(e));async function tn(e,t){return qt.defaults.baseURL?(await qt.get(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}async function xi(e,t,n){return qt.defaults.baseURL?(await qt.post(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function oc(e,t,n){return qt.defaults.baseURL?(await qt.put(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function sc(e,t){return qt.defaults.baseURL?(await qt.delete(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}function nn(e){return e&&typeof e=="object"&&"data"in e?e.data:e}class ic{get baseUrl(){const t=qt.defaults.baseURL;return t?En(String(t)):""}updateConfig(t){t.baseUrl&&(qt.defaults.baseURL=En(String(t.baseUrl))),t.authToken!==void 0&&gi(t.authToken)}getAuthToken(){return nc()}setAuthToken(t){gi(t)}onTokenChange(t){return rc(t)}async listThreads(){const t=await tn("/threads"),n=nn(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async createThread(t){const r=await xi("/threads",t?{title:t}:void 0);return nn(r)}async updateThread(t,n){const r=await oc(`/threads/${t}`,{title:n});return nn(r)}async deleteThread(t){const n=await sc(`/threads/${t}`);return nn(n)}async threadInfo(t){const n=await tn(`/threads/${t}/info`);return nn(n)}async listAgents(){const t=await tn("/agents"),n=nn(t);return(n==null?void 0:n.items)??[]}async getAgent(t){const n=await tn(`/agents/${t}`);return nn(n)}async getAgentSchema(t){const n=await tn(`/agents/${t}/schema`);return nn(n)}async getMessages(t){const n=await tn(`/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 nn(n)}async getStateHistory(t){const n=await tn(`/threads/${t.threadId}/state/history`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return nn(n)}resumeStream(t){}async resume(t){const n=await xi("/runs/resume",{thread_id:t.threadId,value:t.value});return nn(n)}}const On=new ic,ac=y.createContext(null);function Dg({children:e,apiConfig:t}){const n=On;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(ac.Provider,{value:r,children:e})}function vi(){const e=y.useContext(ac);if(!e)throw new Error("useApi must be used within ApiProvider");return e}async function Lg(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 $g(e,t=[],n,r,o,s){const i=[],a=[];for(const l of t)try{const u=await Lg(l);a.push({filename:l.name,data:u,mime_type:l.type||"application/octet-stream"})}catch{}return{contentParts:i,filesInfo:a}}const Fg={human:"user",user:"user",ai:"assistant",assistant:"assistant",tool:"tool",function:"tool",system:"system"};function bi(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(!bi(r))return{payload:{threadId:n,checkpointId:void 0,checkpointNs:void 0,messages:[],hasMore:!1,nextCursor:null,nextCursorNs:null},checkpoints:[],interrupt:null};const o=zg(t),s=lc(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,pendingInterrupt:(s==null?void 0:s.interrupt)??null},checkpoints:o,interrupt:(s==null?void 0:s.interrupt)??null}}function lc(e,t){var h,p;if(!bi(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)=>qg(b,x)).filter(b=>!!b),i=Ft((h=e.config)==null?void 0:h.configurable),a=ht(i,["checkpoint_id","checkpointId"]),l=ht(i,["checkpoint_ns","checkpointNs"]),u=Ft((p=e.parentConfig)==null?void 0:p.configurable),d=ht(u,["checkpoint_id","checkpointId"])??null,f=ht(u,["checkpoint_ns","checkpointNs"])??null;return{messages:s,checkpointId:a??null,checkpointNs:l??null,nextCursor:d,nextCursorNs:f,interrupt:Bg(o,s,t)}}function Bg(e,t,n){const r=Wg(e,n);return r||Ug(t,n)}function zg(e){const t=new Map;e.forEach((r,o)=>{if(!bi(r))return;const s=lc(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=Hg(s.messages),u=s.messages[s.messages.length-1],d=Ft(r==null?void 0:r.metadata),f=ht(d,["branch_label","branchLabel"]),h=Ft(r==null?void 0:r.parentConfig),p=Ft(h==null?void 0:h.configurable),b=ht(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:b??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)=>uc(o.createdAt)-uc(r.createdAt)),n}function Hg(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 Ug(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 Wg(e,t){if(!Array.isArray(e)||!e.length)return null;for(let n=e.length-1;n>=0;n--){const r=Vg(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=Kr(r.interrupts[s],`${o}-interrupt-${s}`);if(i)return i}if(r.state!==void 0&&r.state!==null){const s=Kr(r.state,`${o}-state`);if(s)return s}}return null}function Vg(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=Ft(e);if(!n)return null;const r=ht(n,["id","task_id","taskId"])??t,o=ht(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 Kr(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=cc(e,t);if(o)return o;if(Array.isArray(e)){for(let s=e.length-1;s>=0;s--){const i=Kr(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=Kr(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=Kr(l,t,n+1,r);if(u)return u}}return null}function cc(e,t){if(!e)return null;if(typeof e=="object"&&!Array.isArray(e)){const n=e,r=ht(n,["type","event","kind"]),o=ht(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=cc(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 uc(e){if(!e)return 0;const t=Date.parse(e);return Number.isFinite(t)?t:0}function qg(e,t){if(!e||typeof e!="object")return null;const n=e,r=Ft(e)??{},o=Ft(n.data)??r,s=String(n.type??o.type??o.role??"").toLowerCase(),i=Fg[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=Ft(o.additional_kwargs)??Ft(o.additionalKwargs),d=Ft(o.response_metadata)??Ft(o.responseMetadata),f=ht(u,["createdAt","created_at"])??ht(o,["created_at","createdAt"]),h=ht(u,["checkpointId","checkpoint_id"]),p=ht(u,["checkpointNs","checkpoint_ns"]),b=Kg(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=Zg(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=Gg((u==null?void 0:u.tool_calls)??o.tool_calls);if(w.length&&(x.content=[...x.content,...w]),i==="tool"){const S=Xg(o,x.content);S&&(x.content=S)}return x}function Kg(e){if(!e)return[];if(Array.isArray(e))return e.map(t=>dc(t)).filter(t=>!!t);if(typeof e=="string")return e.trim()?[{type:"text",text:e.trim()}]:[];if(typeof e=="object"){const t=dc(e);return t?[t]:[]}return[]}function dc(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=ht(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=ht(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 Yg(t)??null;if(n==="tool_end"){const o=ht(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=ht(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 Gg(e){return Array.isArray(e)?e.map((t,n)=>{if(!t||typeof t!="object")return null;const r=t,o=ht(r,["id","call_id"]),s=Ft(r.function),i=ht(s,["name"])??"tool",a=s==null?void 0:s.arguments,l=fc(a);return{type:"tool_call",id:o??`tool_call_${n}`,name:i,args:l}}).filter(t=>!!t):[]}function Yg(e){const t=ht(e,["id","call_id"]),n=ht(e,["name"]);if(!t||!n)return null;const r=fc(e.args??e.arguments);return{type:"tool_call",id:t,name:n,args:r}}function Xg(e,t){const n=ht(e,["tool_call_id","toolCallId","id"]);if(!n)return t;const r=e.content??e.output,o=typeof r=="string"?Jg(r):r,s={type:"tool_end",toolCallId:n,output:o};return typeof e.error=="string"&&(s.error=e.error),[s]}function fc(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 Jg(e){try{return JSON.parse(e)}catch{return e}}function Ft(e){if(!(!e||typeof e!="object"||Array.isArray(e)))return{...e}}function ht(e,t){if(e)for(const n of t){const r=e[n];if(typeof r=="string"&&r.trim())return r}}function Zg(e,t){if(!e)return;const n={};let r=!1;for(const[o,s]of Object.entries(e)){if(t.includes(o)){r=!0;continue}s!==void 0&&(n[o]=s)}return r?Object.keys(n).length?n:void 0:e}function Qg(e){return e.type!=="thread_info"&&e.type!=="token"}const ex={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null,messagesStreamMeta:{},pendingInterrupt:null};function tx(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:yi(((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=yi(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=yi(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 pc(e,t.payload.ev);case"batch":{const{events:r}=t.payload;return r.length?r.reduce((o,s)=>pc(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 hc(e=[]){const[t,n]=y.useReducer(tx,{...ex,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 pc(e,t){var n,r,o,s;if(t.type==="message_start"&&t.role==="assistant"){const i=t.id,a=ox(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??Si(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:bc(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}=nx(u.content,t.delta,f,h);if(!x)return e;const g={...u,content:p},v=mc(a,l,g),w={...d,[i]:b};return{...e,messages:v,messagesStreamMeta:w}}if(t.type==="message_end"){const i=e.assemblingId??Si(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?xc(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=rx(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??Si(e.messages),a={type:"interrupt",value:t.value,id:t.id};if(i)return{...e,assemblingId:null,messages:xc(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:gc(e.messages,l,f=>({...f,content:vc(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 yi(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 mc(e,t,n){return t<0||t>=e.length?e:[...e.slice(0,t),n,...e.slice(t+1)]}function Si(e){for(let t=e.length-1;t>=0;t--)if(e[t].role==="assistant")return e[t].id;return null}function gc(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 xc(e,t,n){return gc(e,t,r=>({...r,content:vc(r.content,n)}))}function vc(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=yc(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 bc(e){return!e||!e.length?"":e.filter(t=>t.type==="text").map(t=>t.text??"").join("")}function nx(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??bc(e);let l="",u=e.slice();if(s){const f=yc(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 wc(e){return e.replace(/\s+/g," ").trim()}function yc(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=wc(e),o=wc(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 rx(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 mc(e,r,s)}return e}function ox(e){if(!e)return null;const t=e.split("/");return t[t.length-1]||null}function Sc(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,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,q,W,B,F,le,D,Q;const M=de=>{var be;try{const ye=JSON.parse(JSON.stringify(de));return(be=ye==null?void 0:ye.payload)!=null&&be.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__,ut=((G=window.localStorage)==null?void 0:G.getItem("authToken"))||null;let nt=null;try{const xt=(q=window.localStorage)==null?void 0:q.getItem("chat-settings");xt&&(nt=((W=JSON.parse(xt))==null?void 0:W.apiKey)||null)}catch{}const Be=He||ut||nt||null;Be&&(de={Authorization:`Bearer ${Be}`})}}catch{}console.debug("[use-chat] POST",t+n,M(P));const be=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(!be.ok||!be.body){const Pe=await be.text().catch(()=>"");throw console.debug("[use-chat] non-OK response",be.status,Pe==null?void 0:Pe.slice(0,500)),new Error(`stream ${be.status}${Pe?": "+Pe:""}`)}w(!0);const ye=be.body.getReader(),Se=new TextDecoder;let K="",O=[];T.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 he=Date.now();const Qe=setInterval(()=>{var Pe;if(Date.now()-he>6e4){const He="Stream idle timeout";d(He),V.abort(),(Pe=$==null?void 0:$.onError)==null||Pe.call($,He)}},5e3),et=1024*1024;try{const Pe=be.headers.get("X-Thread-Id")||be.headers.get("x-thread-id"),He=be.headers.get("X-Thread-Created")||be.headers.get("x-thread-created"),ut=Pe??null,nt=String(He??"").toLowerCase()==="true";for((B=$==null?void 0:$.onOpen)==null||B.call($,{threadId:ut,created:nt});;){const{value:Be,done:xt}=await ye.read();if(xt)break;K+=Se.decode(Be,{stream:!0}),K.length>et&&(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 ax({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(Qg(p)){n(p);return}r==null||r(p)},[n,o,t,r]),{stream:a,stop:l,isStreaming:u,error:d,setToken:f}=Sc({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 Cc=y.createContext(null),Tc=y.createContext(null),kc=y.createContext(null),lx=y.createContext(!1),cx="cachedThreads",ux="v1",Oo=300,Ci=200;function dx(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 fx(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 Ic(e){if(typeof window<"u"&&"requestIdleCallback"in window)try{window.requestIdleCallback(e,{timeout:1e3});return}catch{}window.setTimeout(e,Oo)}function yr(){return typeof window<"u"&&typeof window.localStorage<"u"}function Ti(e){if(!yr())return null;try{return window.localStorage.getItem(e)}catch{return null}}function Ec(e,t){if(yr())try{window.localStorage.setItem(e,t)}catch{}}function ki(e){if(yr())try{window.localStorage.removeItem(e)}catch{}}function hx(){const e=Ti(cx);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 px(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 Ii(e,t){return`cachedThreads:v1:${e}:${px(t||"anon")}`}function mx(e){const t=Ti(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{Ec(e,JSON.stringify(t))}catch{}}function Ni(e){const t=mx(e);if(t.length>0)return t;const n=hx();if(n.length>0)try{Ei(e,n.slice(0,Ci))}catch{}return n}function Mo(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 Ai(e){return e.order.map(t=>e.byId[t]).filter(Boolean)}function gx({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}=vi(),d=y.useMemo(()=>En(u),[u]),f=y.useMemo(()=>{try{return new URL(u).host}catch{return"unknown"}},[u]),h=y.useMemo(()=>`threadPayload:${ux}:${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 _=Ti(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{Ec(p(C.threadId),JSON.stringify(z))}catch{}},[p]),v=y.useCallback(C=>{ki(p(C))},[p]),w=y.useCallback(()=>{if(yr())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 Ii(f,(C=l.getAuthToken)==null?void 0:C.call(l))}),[T,k]=y.useState(()=>{var _;const C=Ni(Ii(f,(_=l.getAuthToken)==null?void 0:_.call(l)));return Mo(C)}),E=y.useMemo(()=>Ai(T),[T]),[A,j]=y.useState(t),[P,L]=y.useState(!1),[$,V]=y.useState(!1),[M,G]=y.useState(null),[q,W]=y.useState(null),[B,F]=y.useState(null),le=y.useCallback(()=>{const C=Ni(S);y.startTransition(()=>{k(Mo(C))})},[S]),[D,Q]=y.useState(!1),[de,be]=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:he,dispatch:Qe,seed:et,prepend:Pe,pushUser:He,onEvent:ut,reset:nt}=hc(),Be=y.useRef(A);y.useEffect(()=>{Be.current=A},[A]);const xt=y.useRef(!1),J=y.useRef([]),re=y.useRef(null),me=y.useRef(null),Ce=y.useRef(new Map),ge=y.useRef(A),Oe=y.useRef(!1),at=y.useRef(null),Me=y.useRef(new Map),tt=y.useCallback((C,_,z)=>{if(!C)return;const xe=z==="replace"?[]:Me.current.get(C)??[],ue=z==="replace"?_:[..._,...xe];if(!ue.length){z==="replace"&&Me.current.set(C,[]);return}const Ee=new Map;for(const pe of ue){if(!(pe!=null&&pe.checkpointId))continue;const qe=`${pe.checkpointId}::${pe.checkpointNs??""}`;Ee.has(qe)||Ee.set(qe,pe)}const Ye=Array.from(Ee.values()).sort((pe,qe)=>{const rt=Number.isFinite(Date.parse(pe.createdAt))?Date.parse(pe.createdAt):0;return(Number.isFinite(Date.parse(qe.createdAt))?Date.parse(qe.createdAt):0)-rt});Me.current.set(C,Ye)},[]),bt=y.useCallback((C,_)=>new Promise((z,xe)=>{const ue=async()=>{xt.current=!0;try{await C(),z()}catch(Ee){xe(Ee)}finally{xt.current=!1;const Ee=J.current.shift();Ee&&Ee().catch(()=>{})}};xt.current?J.current.push(ue):ue().catch(Ee=>{xe(Ee)})}),[]),Zt=y.useRef(E.length),[Kn,Dr]=y.useState(!1),gr=y.useRef(!1);y.useEffect(()=>{Zt.current=E.length},[E.length]),y.useEffect(()=>{const C=he.pendingInterrupt??fx(he.messages);dx(B,C)||F(C??null)},[B,he.messages,he.pendingInterrupt]);const Pt=y.useCallback(async()=>{const C=Zt.current>0;C||L(!0);try{const _=await l.listThreads();y.startTransition(()=>{k(z=>{const xe=Ye=>Ye.map(pe=>`${pe.threadId}:${pe.updatedAt??""}:${pe.messageCount??""}`).join("|"),ue=Ai(z);return xe(ue)===xe(_)||_.length===0&&ue.length>0&&!gr.current?z:Mo(_)})}),G(null),gr.current||(gr.current=!0,Dr(!0))}catch(_){i==null||i(String(_)),console.error("[ChatSessionProvider] Failed to refresh threads:",_),G(String(_))}finally{C||L(!1)}},[l,i]),wo=y.useRef(!1),jn=y.useRef(null),St=y.useRef(null),At=y.useRef(""),Vt=y.useCallback((C,_)=>{if(!yr())return;St.current!==null&&(window.clearTimeout(St.current),St.current=null);const z=C.map(ue=>`${ue.threadId}:${ue.updatedAt??""}:${ue.messageCount??""}`).join("|");if(C.length===0){try{ki(S)}catch{}At.current="";return}if(z===At.current)return;const xe=()=>{try{const ue=C.slice(0,Ci);Ei(S,ue),At.current=z}catch{}finally{St.current=null}};if(_!=null&&_.immediate){xe();return}St.current=window.setTimeout(()=>{Ic(xe)},Oo)},[S]),Gn=y.useCallback(()=>{Vt(E,{immediate:!0})},[Vt,E]),un=y.useCallback((C,_,z)=>{const xe=Array.isArray(C==null?void 0:C.messages)?C.messages:[],ue=z??(C==null?void 0:C.threadId)??Be.current,Ee=ue!=null&&ue===Be.current,Ye=(C==null?void 0:C.pendingInterrupt)??null;if(_==="replace"){if(ue){const pe={threadId:ue,messages:xe.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};Ce.current.set(ue,pe),ge.current=ue}if(!Ee)return;et(xe,{checkpointId:(C==null?void 0:C.checkpointId)??null,checkpointNs:(C==null?void 0:C.checkpointNs)??null,pendingInterrupt:Ye}),F(Ye??null)}else if(_==="prepend"&&xe.length&&ue){const pe=Ce.current.get(ue),qe=(pe==null?void 0:pe.messages)??[],rt=new Set,_t=[...xe,...qe].filter(Qt=>{const In=Qt==null?void 0:Qt.id;return In?rt.has(In)?!1:(rt.add(In),!0):!0}),kn={threadId:ue,messages:_t,hasMore:(C==null?void 0:C.hasMore)??(pe==null?void 0:pe.hasMore)??!1,nextCursor:(C==null?void 0:C.nextCursor)??(pe==null?void 0:pe.nextCursor)??null,checkpointId:(pe==null?void 0:pe.checkpointId)??(C==null?void 0:C.checkpointId)??null,checkpointNs:(pe==null?void 0:pe.checkpointNs)??(C==null?void 0:C.checkpointNs)??null,nextCursorNs:(C==null?void 0:C.nextCursorNs)??(pe==null?void 0:pe.nextCursorNs)??null,pendingInterrupt:(pe==null?void 0:pe.pendingInterrupt)??Ye??null};if(Ce.current.set(ue,kn),!Ee)return;Pe(xe)}else _==="prepend"&&xe.length&&Pe(xe);Ee&&(_==="replace"?(Se((C==null?void 0:C.nextCursor)??null),Q(!!(C!=null&&C.hasMore)),O((C==null?void 0:C.checkpointId)??void 0),ee((C==null?void 0:C.checkpointNs)??void 0),ne((C==null?void 0:C.nextCursorNs)??void 0)):(Se(pe=>(C==null?void 0:C.nextCursor)??pe??null),Q(pe=>(C==null?void 0:C.hasMore)!==void 0?!!(C!=null&&C.hasMore):pe),O(pe=>(C==null?void 0:C.checkpointId)??pe??void 0),ee(pe=>(C==null?void 0:C.checkpointNs)??pe??void 0),ne(pe=>(C==null?void 0:C.nextCursorNs)!==void 0?C.nextCursorNs??void 0:pe)))},[Pe,et,F]),xr=y.useCallback(C=>{C.threadId!=null&&C.threadId!==Be.current||(et(C.messages,{checkpointId:C.checkpointId,checkpointNs:C.checkpointNs,pendingInterrupt:C.pendingInterrupt??null}),F(C.pendingInterrupt??null),Se(C.nextCursor),Q(C.hasMore),O(C.checkpointId??void 0),ee(C.checkpointNs??void 0),ne(C.nextCursorNs??void 0),ge.current=C.threadId)},[et,F]),dn=y.useCallback(C=>{C&&(Ce.current.delete(C),v(C),Me.current.delete(C),ge.current===C&&(ge.current=null))},[v]),Tn=y.useCallback(()=>{const C=Be.current;C&&dn(C),nt([]),Q(!1),be(!1),Se(null),O(void 0),ee(void 0),ne(void 0)},[dn,nt]),Yn=y.useCallback(({from:C,to:_})=>{const z=Be.current;z&&console.warn(`[ChatSessionProvider] Stream sequence gap detected (${C} -> ${_}) for thread ${z}`)},[]),Lr=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};Be.current!==_&&(!Be.current&&he.messages.length<=1&&(me.current=_),j(_)),y.startTransition(()=>{k(xe=>{const ue=xe.byId[_];return ue?ue.title===z.title&&ue.updatedAt===z.updatedAt&&ue.messageCount===z.messageCount?xe:{byId:{...xe.byId,[_]:z},order:xe.order}:{byId:{...xe.byId,[_]:z},order:[_,...xe.order]}})})},[he.messages.length]),{startStream:$r,stop:Fr,isStreaming:Rn,error:se,setAuthToken:we}=ax({baseUrl:d,onThreadInfo:Lr,onMessageEvent:ut,onUnhandledEvent:C=>{console.warn(`[ChatSessionProvider] Unhandled stream event: ${C.type}`,C)},onSequenceGap:Yn});y.useEffect(()=>{wo.current=Rn},[Rn]),y.useEffect(()=>{if(!yr())return;St.current!==null&&(window.clearTimeout(St.current),St.current=null);const C=E.map(z=>`${z.threadId}:${z.updatedAt??""}:${z.messageCount??""}`).join("|");if(E.length===0){try{ki(S)}catch{}At.current="";return}if(C===At.current)return;const _=()=>{try{const z=E.slice(0,Ci);Ei(S,z),At.current=C}catch{}finally{St.current=null}};return St.current=window.setTimeout(()=>{Ic(_),St.current=null},Oo),()=>{St.current!==null&&(window.clearTimeout(St.current),St.current=null)}},[E,Vt]),y.useEffect(()=>{var xe;const C=l.getAuthToken();we(C);const _=ue=>{const Ee=Ii(f,ue);at.current!==Ee&&(at.current=Ee,Oe.current=!1),N(Ee);const Ye=Ni(Ee);y.startTransition(()=>{k(Mo(Ye))}),Oe.current||(Oe.current=!0,Pt().catch(()=>{}))};_(C);const z=(xe=l.onTokenChange)==null?void 0:xe.call(l,ue=>{we(ue),w(),_(ue)});return()=>{z==null||z()}},[l,f,we,w,Pt]);const Ue=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(ue=>({byId:{...ue.byId,[_]:z},order:[_,...ue.order]})),j(_);try{const ue=await l.createThread(C),Ee=typeof ue=="string"?ue:ue.threadId;return k(Ye=>{const pe=Ye.byId[_];if(!pe)return Ye;const qe={...Ye.byId};delete qe[_],qe[Ee]={...pe,threadId:Ee};const rt=Ye.order.map(_t=>_t===_?Ee:_t);return{byId:qe,order:rt}}),j(Ee),setTimeout(()=>Pt(),10),G(null),Ee}catch(ue){throw k(Ee=>{if(!Ee.byId[_])return Ee;const Ye={...Ee.byId};delete Ye[_];const pe=Ee.order.filter(qe=>qe!==_);return{byId:Ye,order:pe}}),j(null),G(String(ue)),ue}},[l,Pt]),it=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 ue=z.order.filter(Ye=>Ye!==C),Ee={byId:xe,order:ue};return _=Ai(Ee),Ee}),_&&Vt(_,{immediate:!0}),dn(C),Be.current===C&&(me.current=C,j(null),Be.current=null,ge.current=null,Tn()),await Pt(),G(null)}catch(_){throw G(String(_)),_}},[l,Tn,dn,Pt,Vt]),Ot=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 Pt(),G(String(z)),z}},[l,Pt]),I=y.useCallback(async(C,_,z,xe=!1)=>{await bt(async()=>{if(me.current===C&&!xe){me.current=null;return}if(re.current===C&&!xe)return;j(qe=>qe===C?qe:C),Be.current=C;const ue=!xe&&!_&&!z;let Ee=!1;if(ue){const qe=Ce.current.get(C);if(qe)xr(qe),Ee=!0;else{const rt=x(C);rt&&(Ce.current.set(C,rt),xr(rt),Ee=!0)}}const Ye=xe||!Ee||!!_||!!z,pe=async qe=>{qe&&V(!0),re.current=C;try{const rt=await l.getStateHistory({threadId:C,checkpointId:_,checkpointNs:z}),{payload:_t,checkpoints:kn}=wi(rt);un(_t,"replace",C),tt(C,kn,"replace"),W(null)}catch(rt){throw(!Ee||xe||qe)&&(i==null||i(String(rt))),W(String(rt)),rt}finally{re.current=null,qe&&V(!1)}};Ye?await pe(!0):ue&&Ee&&pe(!1).catch(qe=>{console.warn("[ChatSessionProvider] Background refresh failed:",qe)})},`loadThread-${C}`)},[l,xr,un,bt,i,tt]),H=y.useCallback(async()=>{await bt(async()=>{const C=Be.current;C&&dn(C),me.current=null,j(null),Be.current=null,ge.current=null,Tn(),O(void 0),ee(void 0),ne(void 0);try{localStorage.removeItem("lastThreadId")}catch(_){console.warn("[ChatSessionProvider] Failed to clear lastThreadId:",_)}},"clearCurrentThread")},[Tn,dn,bt]),te=y.useCallback(async C=>{const _=Me.current.get(C);if(_)return{threadId:C,checkpoints:_.slice()};const z=await l.getStateHistory({threadId:C}),{checkpoints:xe}=wi(z);tt(C,xe,"replace");const ue=Me.current.get(C)??[];return{threadId:C,checkpoints:ue.slice()}},[l,tt]),Ie=y.useCallback(async(C,_)=>{if(!Be.current)throw new Error("No active thread");await I(Be.current,C,_??void 0,!0)},[I]),$e=y.useCallback(async()=>{if(!Be.current)throw new Error("No active thread");await I(Be.current,void 0,void 0,!0)},[I]),Ge=y.useCallback(async()=>{if(!Be.current)throw new Error("No active thread");if(de||!D)return;const C=ye;if(C){be(!0);try{const _=Be.current,z=await l.getStateHistory({threadId:_,checkpointId:C??K,checkpointNs:fe??X}),{payload:xe,checkpoints:ue}=wi(z);un(xe,"prepend",_??void 0),_&&tt(_,ue,"prepend"),W(null)}catch(_){throw W(String(_)),_}finally{be(!1)}}},[l,un,D,K,X,fe,ye,de,tt]),We=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};un(_,"replace",C.threadId)},[un]),ze=y.useCallback(async(C,_)=>{var ti;const z=Be.current,xe=(C==null?void 0:C.text)??"",ue=(C==null?void 0:C.attachments)??[],Ee=ue.length?ue:(_==null?void 0:_.attachments)??[],Ye={...(_==null?void 0:_.payloadExtras)??{},...(C==null?void 0:C.payload)??{}};if(!z&&!Object.keys(Ye).length&&Ee.length===0&&!xe.trim()){console.warn("[ChatSessionProvider] Nothing to submit - skipping");return}!z&&!Ye.messages&&console.warn("[ChatSessionProvider] No thread ID - message will create new thread");const{contentParts:pe,filesInfo:qe}=await $g(l,Ee),rt=[...pe];xe&&xe.trim()&&rt.push({type:"text",text:xe.trim()});const _t=!!z,kn=_t?(_==null?void 0:_.checkpointId)??he.lastCheckpointId??void 0:void 0,Qt=_t?(_==null?void 0:_.checkpointNs)??he.lastCheckpointNs??void 0:void 0,In={id:((ti=crypto.randomUUID)==null?void 0:ti.call(crypto))||`user-${Date.now()}`,role:"user",content:rt,createdAt:new Date().toISOString(),...kn!=null?{checkpointId:kn}:{},...Qt!=null?{checkpointNs:Qt}:{}};rt.length>0&&He(In);const dl={...In,content:rt},Qs=Ee.length>0,ei={...z?{threadId:z}:{},payload:{messages:rt.length>0?[dl]:[],files_info:qe,...o&&Qs&&s?{active_agent:s}:{},...Ye},...kn!=null?{checkpointId:kn}:{},...Qt!=null?{checkpointNs:Qt}:{},nodeFilter:_==null?void 0:_.nodeFilter,config:_==null?void 0:_.config};$r(ei,{onError:Pn=>{console.warn("[ChatSessionProvider] Stream error:",Pn)},onOpen:({threadId:Pn})=>{!Be.current&&Pn&&(he.messages.length<=1&&(me.current=Pn),j(Pn))},onGap:Yn})},[l,o,s,Yn,he.lastCheckpointId,he.lastCheckpointNs,he.messages.length,He,$r]),wt=y.useCallback(async(C,_,z)=>{var ue,Ee;const xe=Be.current;if(!xe)throw new Error("No active thread to handle interrupt");try{const Ye=_?z??!0:!1;try{Qe({type:"interrupt_response",payload:{interruptId:C}})}catch(In){console.warn("[ChatSessionProvider] optimistic interrupt_response dispatch failed:",In)}const pe=`${d}/runs/resume`,qe=(ue=l.getAuthToken)==null?void 0:ue.call(l),rt=await fetch(pe,{method:"POST",headers:{"Content-Type":"application/json",...qe?{Authorization:`Bearer ${qe}`}:{}},body:JSON.stringify({thread_id:xe,value:Ye})});if(!rt.ok)throw new Error(`Resume failed with status ${rt.status}`);const _t=(Ee=rt.body)==null?void 0:Ee.getReader();if(!_t)throw new Error("No response body for resume stream");const kn=new TextDecoder;let Qt="";for(;;){const{done:In,value:dl}=await _t.read();if(In)break;Qt+=kn.decode(dl,{stream:!0});const Qs=Qt.split(`
|
|
39
|
-
`);Qt=Qs.pop()||"";for(const ei of Qs)if(ei.startsWith("data: ")){const ti=ei.slice(6);try{const Pn=JSON.parse(ti);Qe({type:"event",payload:{ev:Pn}})}catch(Pn){console.warn("[ChatSessionProvider] Failed to parse resume SSE event:",Pn)}}}F(null)}catch(Ye){throw console.error(`[ChatSessionProvider] Failed to handle interrupt ${C}:`,Ye),Ye}},[l,Qe,d]),ft=y.useCallback(C=>wt(C.interruptId,C.approved,C.value),[wt]);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(Pt().catch(_=>{console.error("[ChatSessionProvider] Failed to refresh threads (background):",_),i==null||i(String(_))}),!r&&!t)try{const _=localStorage.getItem("lastThreadId");_&&(j(_),n&&await I(_))}catch(_){console.warn("[ChatSessionProvider] Failed to restore last thread:",_)}else t&&n&&await I(t)}catch(_){console.error("[ChatSessionProvider] Initialization failed:",_),i==null||i(String(_))}})(),()=>{}),[]),y.useEffect(()=>{var ue,Ee,Ye,pe;const C=Be.current;if(!C||ge.current!==C)return;const _={threadId:C,messages:he.messages.slice(),hasMore:D,nextCursor:ye,checkpointId:he.lastCheckpointId??null,checkpointNs:he.lastCheckpointNs??null,nextCursorNs:fe??null,pendingInterrupt:he.pendingInterrupt??B??null},z=Ce.current.get(C);(!z||z.messages.length!==_.messages.length||z.messages.some((qe,rt)=>{var _t;return(qe==null?void 0:qe.id)!==((_t=_.messages[rt])==null?void 0:_t.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||(((ue=z==null?void 0:z.pendingInterrupt)==null?void 0:ue.id)??null)!==(((Ee=_.pendingInterrupt)==null?void 0:Ee.id)??null)||JSON.stringify((Ye=z==null?void 0:z.pendingInterrupt)==null?void 0:Ye.value)!==JSON.stringify((pe=_.pendingInterrupt)==null?void 0:pe.value))&&(Ce.current.set(C,_),jn.current&&window.clearTimeout(jn.current),jn.current=window.setTimeout(()=>{try{g(_,100)}catch(qe){console.warn("[ChatSessionProvider] Failed to persist thread payload:",qe)}},Oo))},[D,ye,fe,he.lastCheckpointId,he.lastCheckpointNs,he.messages,he.pendingInterrupt,B]);const pt=y.useMemo(()=>({threads:E,currentThreadId:A,setCurrentThreadId:j,isLoading:P,error:M,actions:{createThread:Ue,deleteThread:it,renameThread:Ot,refreshThreads:()=>Pt()},persistThreadsCache:Gn,hydrateFromCache:le}),[E,A,P,M,Ue,it,Ot,Pt,Gn,le,j]),$t=y.useMemo(()=>{const C=he.lastBranch??null,_=he.assemblingId??null,z=C||_?{branchLabel:(C==null?void 0:C.branchLabel)??null,lastBranch:C,assemblingMessageId:_}:null;return{threadId:A,messages:he.messages,interrupt:B,checkpoint:{id:he.lastCheckpointId??null,namespace:he.lastCheckpointNs??null},metadata:z,isLoading:$,isHistoryLoading:de,error:q,hasMore:D,loadOlder:Ge,seedFromSnapshot:We,clearState:Tn,listCheckpoints:te,navigateToCheckpoint:Ie,returnToLatest:$e,loadThread:I,clearThread:H,respondToInterrupt:wt}},[H,Tn,A,B,D,de,$,te,Ge,I,he.assemblingId,he.lastBranch,he.lastCheckpointId,he.lastCheckpointNs,he.messages,Ie,wt,$e,We,q]),Xn=y.useMemo(()=>({isStreaming:Rn,error:se,submit:ze,stop:Fr,resume:ft,setAuthToken:we}),[Rn,se,ze,Fr,ft,we]);return c.jsx(lx.Provider,{value:!0,children:c.jsx(kc.Provider,{value:Xn,children:c.jsx(Cc.Provider,{value:pt,children:c.jsx(Tc.Provider,{value:$t,children:e})})})})}function Do(){const e=y.useContext(Cc);if(!e)throw new Error("useThreads must be used within ChatSessionProvider");return e}function Lo(){const e=y.useContext(Tc);if(!e)throw new Error("useThreadState must be used within ChatSessionProvider");return e}function Nc(){const e=y.useContext(kc);if(!e)throw new Error("useStream must be used within ChatSessionProvider");return e}function $o({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(Dg,{apiConfig:t,children:c.jsx(gx,{initialThreadId:n,autoLoadInitial:r,disableAutoRestore:o,enableFileAgentRouting:s,fileAgentId:i,onError:a,onThreadChange:l,children:e})})}function Z(...e){return dm.twMerge(um.clsx(e))}const xx=yo.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"}}),Xe=m.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?Jn.Slot:"button";return c.jsx(i,{className:Z(xx({variant:t,size:n,className:e})),ref:s,...o})});Xe.displayName="Button";const Ac=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}));Ac.displayName="Textarea";function vx({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(Ac,{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(Xe,{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(Xe,{type:"submit",size:"icon",className:"shrink-0",title:t?"Save changes":"Send message",disabled:o||!h.trim()&&!f||b,children:c.jsx(oe.Send,{size:16})})})]})})}const bx=y.memo(vx),Fo=0,Mn=1,Sr=2,_c=4;function jc(e){return()=>e}function wx(e){e()}function Rc(e,t){return n=>e(t(n))}function Pc(e,t){return()=>e(t)}function yx(e,t){return n=>e(t,n)}function _i(e){return e!==void 0}function Sx(...e){return()=>{e.map(wx)}}function Cr(){}function Bo(e,t){return t(e),e}function Cx(e,t){return t(e)}function lt(...e){return e}function Ze(e,t){return e(Mn,t)}function Le(e,t){e(Fo,t)}function ji(e){e(Sr)}function gt(e){return e(_c)}function ve(e,t){return Ze(e,yx(t,Fo))}function rn(e,t){const n=e(Mn,r=>{n(),t(r)});return n}function Oc(e){let t,n;return r=>o=>{t=o,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function Mc(e,t){return e===t}function ct(e=Mc){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function Ae(e){return t=>n=>{e(n)&&t(n)}}function ie(e){return t=>Rc(t,e)}function hn(e){return t=>()=>{t(e)}}function U(e,...t){const n=Tx(...t);return(r,o)=>{switch(r){case Sr:ji(e);return;case Mn:return Ze(e,n(o))}}}function pn(e,t){return n=>r=>{n(t=e(t,r))}}function tr(e){return t=>n=>{e>0?e--:t(n)}}function Nn(e){let t=null,n;return r=>o=>{t=o,!n&&(n=setTimeout(()=>{n=void 0,r(t)},e))}}function Fe(...e){const t=new Array(e.length);let n=0,r=null;const o=Math.pow(2,e.length)-1;return e.forEach((s,i)=>{const a=Math.pow(2,i);Ze(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 Tx(...e){return t=>e.reduceRight(Cx,t)}function kx(e){let t,n;const r=()=>t==null?void 0:t();return function(o,s){switch(o){case Mn:return s?n===s?void 0:(r(),n=s,t=Ze(e,s),t):(r(),Cr);case Sr:r(),n=null;return}}}function Y(e){let t=e;const n=Ke();return(r,o)=>{switch(r){case Fo:t=o;break;case Mn:{o(t);break}case _c:return t}return n(r,o)}}function It(e,t){return Bo(Y(t),n=>ve(e,n))}function Ke(){const e=[];return(t,n)=>{switch(t){case Fo:e.slice().forEach(r=>{r(n)});return;case Sr:e.splice(0,e.length);return;case Mn:return e.push(n),()=>{const r=e.indexOf(n);r>-1&&e.splice(r,1)}}}}function Bt(e){return Bo(Ke(),t=>ve(e,t))}function Je(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:Ix(),singleton:n}}const Ix=()=>Symbol();function Ex(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 vt(...e){const t=Ke(),n=new Array(e.length);let r=0;const o=Math.pow(2,e.length)-1;return e.forEach((s,i)=>{const a=Math.pow(2,i);Ze(s,l=>{n[i]=l,r=r|a,r===o&&Le(t,n)})}),function(s,i){switch(s){case Sr:{ji(t);return}case Mn:return r===o&&i(n),Ze(t,i)}}}function Ne(e,t=Mc){return U(e,ct(t))}function Ri(...e){return function(t,n){switch(t){case Sr:return;case Mn:return Sx(...e.map(r=>Ze(r,n)))}}}var Lt=(e=>(e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR",e))(Lt||{});const Nx={0:"debug",3:"error",1:"log",2:"warn"},Ax=()=>typeof globalThis>"u"?window:globalThis,Dn=Je(()=>{const e=Y(3);return{log:Y((t,n,r=1)=>{var o;const s=(o=Ax().VIRTUOSO_LOG_LEVEL)!=null?o:gt(e);r>=s&&console[Nx[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 Pi(e,t,n).callbackRef}function Pi(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 _x(e,t,n,r,o,s,i,a,l){const u=y.useCallback(d=>{const f=jx(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?Dc("column-gap",getComputedStyle(d).columnGap,o):Dc("row-gap",getComputedStyle(d).rowGap,o)),f!==null&&e(f)},[e,t,o,s,i,r,a]);return Pi(u,n,l)}function jx(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},Lt.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 Dc(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Lt.WARN),t==="normal"?0:parseInt(t??"0",10)}function Lc(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}=Pi(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 jt=Je(()=>{const e=Ke(),t=Ke(),n=Y(0),r=Ke(),o=Y(0),s=Ke(),i=Ke(),a=Y(0),l=Y(0),u=Y(0),d=Y(0),f=Ke(),h=Ke(),p=Y(!1),b=Y(!1),x=Y(!1);return ve(U(e,ie(({scrollTop:g})=>g)),t),ve(U(e,ie(({scrollHeight:g})=>g)),i),ve(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}),Gr={lvl:0};function $c(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===Gr}function Yr(e,t){if(!ot(e))return t===e.k?e.v:t<e.k?Yr(e.l,t):Yr(e.r,t)}function on(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=on(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return on(e.l,t,n)}function zt(e,t,n){return ot(e)?zc(t,n,1):t===e.k?yt(e,{k:t,v:n}):t<e.k?Hc(yt(e,{l:zt(e.l,t,n)})):Hc(yt(e,{r:zt(e.r,t,n)}))}function Tr(){return Gr}function zo(e,t,n){if(ot(e))return[];const r=on(e,t)[0];return Rx(Mi(e,r,n))}function Oi(e,t){if(ot(e))return Gr;const{k:n,l:r,r:o}=e;if(t===n){if(ot(r))return o;if(ot(o))return r;{const[s,i]=Bc(r);return Ho(yt(e,{k:s,l:Fc(r),v:i}))}}else return t<n?Ho(yt(e,{l:Oi(r,t)})):Ho(yt(e,{r:Oi(o,t)}))}function rr(e){return ot(e)?[]:[...rr(e.l),{k:e.k,v:e.v},...rr(e.r)]}function Mi(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(Mi(o,t,n))),r>=t&&r<=n&&a.push({k:r,v:i}),r<=n&&(a=a.concat(Mi(s,t,n))),a}function Ho(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(Di(t))return Uc(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(Di(e))return Li(yt(e,{lvl:n-1}));if(!ot(r)&&!ot(r.l)){const o=r.l,s=Di(o)?r.lvl-1:r.lvl;return yt(o,{l:yt(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:Li(yt(r,{l:o.r,lvl:s}))})}else throw new Error("Unexpected empty nodes")}}function yt(e,t){return zc(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 Fc(e){return ot(e.r)?e.l:Ho(yt(e,{r:Fc(e.r)}))}function Di(e){return ot(e)||e.lvl>e.r.lvl}function Bc(e){return ot(e.r)?[e.k,e.v]:Bc(e.r)}function zc(e,t,n,r=Gr,o=Gr){return{k:e,l:r,lvl:n,r:o,v:t}}function Hc(e){return Li(Uc(e))}function Uc(e){const{l:t}=e;return!ot(t)&&t.lvl===e.lvl?yt(t,{r:yt(e,{l:t.r})}):e}function Li(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 Rx(e){return $c(e,({k:t,v:n})=>({index:t,value:n}))}function Wc(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function Xr(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}const $i=Je(()=>({recalcInProgress:Y(!1)}),[],{singleton:!0});function Vc(e,t,n){return e[Uo(e,t,n)]}function Uo(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 Px(e,t,n,r){const o=Uo(e,t,r),s=Uo(e,n,r,o);return e.slice(o,s+1)}function Ln(e,t){return Math.round(e.getBoundingClientRect()[t])}function Wo(e){return!ot(e.groupOffsetTree)}function Fi({index:e},t){return t===e?0:t<e?-1:1}function Ox(){return{groupIndices:[],groupOffsetTree:Tr(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:Tr()}}function Mx(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=zt(e,0,s);continue}const a=zo(e,i-1,o+1);if(a.some(Hx(r)))continue;let l=!1,u=!1;for(const{end:d,start:f,value:h}of a)l?(o>=f||s===h)&&(e=Oi(e,f)):(u=h!==s,l=!0),d>o&&o>=f&&h!==s&&(e=zt(e,o+1,h));u&&(e=zt(e,i,s))}return[e,n]}function Dx(e){return typeof e.groupIndex<"u"}function Lx({offset:e},t){return t===e?0:t<e?-1:1}function Jr(e,t,n){if(t.length===0)return 0;const{index:r,offset:o,size:s}=Vc(t,e,Fi),i=e-r,a=s*i+(i-1)*n+o;return a>0?a+n:a}function qc(e,t){if(!Wo(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function Kc(e,t,n){if(Dx(e))return t.groupIndices[e.groupIndex]+1;{const r=e.index==="LAST"?n:e.index;let o=qc(r,t);return o=Math.max(0,o,Math.min(n,o)),o}}function $x(e,t,n,r=0){return r>0&&(t=Math.max(t,Vc(e,r,Fi).offset)),$c(Px(e,t,n,Lx),zx)}function Fx(e,[t,n,r,o]){t.length>0&&r("received item sizes",t,Lt.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)=>zt(zt(b,x,h),x+1,p),i)}else[i,a]=Mx(i,t);if(i===s)return e;const{lastIndex:l,lastOffset:u,lastSize:d,offsetTree:f}=Bi(e.offsetTree,a,i,o);return{groupIndices:n,groupOffsetTree:n.reduce((h,p)=>zt(h,p,Jr(p,f,o)),Tr()),lastIndex:l,lastOffset:u,lastSize:d,offsetTree:f,sizeTree:i}}function Bx(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 Gc(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 Bi(e,t,n,r){let o=e,s=0,i=0,a=0,l=0;if(t!==0){l=Uo(o,t-1,Fi),a=o[l].offset;const u=on(n,t-1);s=u[0],i=u[1],o.length&&o[l].size===on(n,t)[1]&&(l-=1),o=o.slice(0,l+1)}else o=[];for(const{start:u,value:d}of zo(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 zx(e){return{index:e.index,value:e}}function Hx(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 Ux={offsetHeight:"height",offsetWidth:"width"},mn=Je(([{log:e},{recalcInProgress:t}])=>{const n=Ke(),r=Ke(),o=It(r,0),s=Ke(),i=Ke(),a=Y(0),l=Y([]),u=Y(void 0),d=Y(void 0),f=Y((T,k)=>Ln(T,Ux[k])),h=Y(void 0),p=Y(0),b=Ox(),x=It(U(n,Fe(l,e,p),pn(Fx,b),ct()),b),g=It(U(l,ct(),pn((T,k)=>({current:k,prev:T.current}),{current:[],prev:[]}),ie(({prev:T})=>T)),[]);ve(U(l,Ae(T=>T.length>0),Fe(x,p),ie(([T,k,E])=>{const A=T.reduce((j,P,L)=>zt(j,P,Jr(P,k.offsetTree,E)||L),Tr());return{...k,groupIndices:T,groupOffsetTree:A}})),x),ve(U(r,Fe(x),Ae(([T,{lastIndex:k}])=>T<k),ie(([T,{lastIndex:k,lastSize:E}])=>[{endIndex:k,size:E,startIndex:T}])),n),ve(u,d);const v=It(U(u,ie(T=>T===void 0)),!0);ve(U(d,Ae(T=>T!==void 0&&ot(gt(x).sizeTree)),ie(T=>[{endIndex:0,size:T,startIndex:0}])),n);const w=Bt(U(n,Fe(x),pn(({sizes:T},[k,E])=>({changed:E!==T,sizes:E}),{changed:!1,sizes:b}),ie(T=>T.changed)));Ze(U(a,pn((T,k)=>({diff:T.prev-k,prev:k}),{diff:0,prev:0}),ie(T=>T.diff)),T=>{const{groupIndices:k}=gt(x);if(T>0)Le(t,!0),Le(s,T+Gc(T,k));else if(T<0){const E=gt(g);E.length>0&&(T-=Gc(-T,E)),Le(i,T)}}),Ze(U(a,Fe(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},Lt.ERROR)});const S=Bt(s);ve(U(s,Fe(x),ie(([T,k])=>{const E=k.groupIndices.length>0,A=[],j=k.lastSize;if(E){const P=Yr(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:q})=>{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:q,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=Bt(U(i,Fe(x,p),ie(([T,{offsetTree:k},E])=>{const A=-T;return Jr(A,k,E)})));return ve(U(i,Fe(x,p),ie(([T,k,E])=>{if(k.groupIndices.length>0){if(ot(k.sizeTree))return k;let A=Tr();const j=gt(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})=>zt(V,Math.max(0,M+T),G),A),P!==-T){const V=Yr(k.sizeTree,$);A=zt(A,0,V);const M=on(k.sizeTree,-T+1)[1];A=zt(A,1,M)}return{...k,sizeTree:A,...Bi(k.offsetTree,0,A,E)}}else{const A=rr(k.sizeTree).reduce((j,{k:P,v:L})=>zt(j,Math.max(0,P+T),L),Tr());return{...k,sizeTree:A,...Bi(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(Dn,$i),{singleton:!0});function Wx(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const Yc=Je(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=Ke(),i=Ke(),a=Bt(U(s,ie(Wx)));return ve(U(a,ie(l=>l.totalCount)),n),ve(U(a,ie(l=>l.groupIndices)),e),ve(U(vt(o,t,r),Ae(([l,u])=>Wo(u)),ie(([l,u,d])=>on(u.groupOffsetTree,Math.max(l-d,0),"v")[0]),ct(),ie(l=>[l])),i),{groupCounts:s,topItemsIndexes:i}},lt(mn,jt)),$n=Je(([{log:e}])=>{const t=Y(!1),n=Bt(U(t,Ae(r=>r),ct()));return Ze(t,r=>{r&>(e)("props updated",{},Lt.DEBUG)}),{didMount:n,propsReady:t}},lt(Dn),{singleton:!0}),Vx=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function Xc(e){const t=typeof e=="number"?{index:e}:e;return t.align||(t.align="start"),(!t.behavior||!Vx)&&(t.behavior="auto"),t.offset||(t.offset=0),t}const Zr=Je(([{gap:e,listRefresh:t,sizes:n,totalCount:r},{fixedFooterHeight:o,fixedHeaderHeight:s,footerHeight:i,headerHeight:a,scrollingInProgress:l,scrollTo:u,smoothScrollTargetReached:d,viewportHeight:f},{log:h}])=>{const p=Ke(),b=Ke(),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 ve(U(p,Fe(n,f,r,x,a,i,h),Fe(e,s,o),ie(([[N,T,k,E,A,j,P,L],$,V,M])=>{const G=Xc(N),{align:q,behavior:W,offset:B}=G,F=E-1,le=Kc(G,T,F);let D=Jr(le,T.offsetTree,$)+j;q==="end"?(D+=V+on(T.sizeTree,le)[1]-k+M,le===F&&(D+=P)):q==="center"?D+=(V+on(T.sizeTree,le)[1]-k+M)/2:D-=A,B&&(D+=B);const Q=de=>{S(),de?(L("retrying to scroll to",{location:N},Lt.DEBUG),Le(p,N)):(Le(b,!0),L("list did not change, scroll successful",{},Lt.DEBUG))};if(S(),W==="smooth"){let de=!1;w=Ze(t,be=>{de=de||be}),g=rn(d,()=>{Q(de)})}else g=rn(U(t,qx(150)),Q);return v=setTimeout(()=>{S()},1200),Le(l,!0),L("scrolling from index to",{behavior:W,index:le,top:D},Lt.DEBUG),{behavior:W,top:D}})),u),{scrollTargetReached:b,scrollToIndex:p,topListHeight:x}},lt(mn,jt,Dn),{singleton:!0});function qx(e){return t=>{const n=setTimeout(()=>{t(!1)},e);return r=>{r&&(t(!0),clearTimeout(n))}}}function zi(e,t){e==0?t():requestAnimationFrame(()=>{zi(e-1,t)})}function Hi(e,t){const n=t-1;return typeof e=="number"?e:e.index==="LAST"?n:e.index}const Qr=Je(([{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(U(i,Fe(l),Ae(([d,f])=>!!f),hn(!1)),a),ve(U(i,Fe(l),Ae(([d,f])=>!!f),hn(!1)),u),Ze(U(vt(t,i),Fe(a,n,e,u),Ae(([[,d],f,{sizeTree:h},p,b])=>d&&(!ot(h)||_i(p))&&!f&&!b),Fe(l)),([,d])=>{rn(o,()=>{Le(u,!0)}),zi(4,()=>{rn(r,()=>{Le(a,!0)}),Le(s,d)})}),{initialItemFinalLocationReached:u,initialTopMostItemIndex:l,scrolledToInitialItem:a}},lt(mn,jt,Zr,$n),{singleton:!0});function Jc(e,t){return Math.abs(e-t)<1.01}const eo="up",to="down",Kx="none",Gx={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},Yx=0,no=Je(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:o,viewportHeight:s}])=>{const i=Y(!1),a=Y(!0),l=Ke(),u=Ke(),d=Y(4),f=Y(Yx),h=It(U(Ri(U(Ne(o),tr(1),hn(!0)),U(Ne(o),tr(1),hn(!1),Oc(100))),ct()),!1),p=It(U(Ri(U(n,hn(!0)),U(n,hn(!1),Oc(200))),ct()),!1);ve(U(vt(Ne(o),Ne(f)),ie(([w,S])=>w<=S),ct()),a),ve(U(a,Nn(50)),u);const b=Bt(U(vt(r,Ne(s),Ne(t),Ne(e),Ne(d)),pn((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}},Gx),ct((w,S)=>w&&w.atBottom===S.atBottom))),x=It(U(r,pn((w,{scrollHeight:S,scrollTop:N,viewportHeight:T})=>{if(Jc(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),ie(w=>w.jump)),0);ve(U(b,ie(w=>w.atBottom)),i),ve(U(i,Nn(50)),l);const g=Y(to);ve(U(r,ie(({scrollTop:w})=>w),ct(),pn((w,S)=>gt(p)?{direction:w.direction,prevScrollTop:S}:{direction:S<w.prevScrollTop?eo:to,prevScrollTop:S},{direction:to,prevScrollTop:0}),ie(w=>w.direction)),g),ve(U(r,Nn(50),hn(Kx)),g);const v=Y(0);return ve(U(h,Ae(w=>!w),hn(0)),v),ve(U(o,Nn(100),Fe(h),Ae(([w,S])=>!!S),pn(([w,S],[N])=>[S,N],[0,0]),ie(([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(jt)),Vo="top",qo="bottom",Zc="none";function Qc(e,t,n){return typeof e=="number"?n===eo&&t===Vo||n===to&&t===qo?e:0:n===eo?t===Vo?e.main:e.reverse:t===qo?e.main:e.reverse}function eu(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const Ui=Je(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:o}])=>{const s=Ke(),i=Y(0),a=Y(0),l=Y(0),u=It(U(vt(Ne(r),Ne(o),Ne(n),Ne(s,Xr),Ne(l),Ne(i),Ne(t),Ne(e),Ne(a)),ie(([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=Zc;const A=eu(S,Vo),j=eu(S,qo);return p-=w,p+=h+v,b+=h+v,b-=w,p>d+T-A&&(E=eo),b<d-k+f+j&&(E=to),E!==Zc?[Math.max(N-h-Qc(x,Vo,E)-A,0),N-k-v+f+Qc(x,qo,E)+j]:null}),Ae(d=>d!=null),ct(Xr)),[0,0]);return{increaseViewportBy:a,listBoundary:s,overscan:l,topListHeight:i,visibleRange:u}},lt(jt),{singleton:!0});function Xx(e,t,n){if(Wo(t)){const r=qc(e,t);return[{index:on(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 Wi={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function Ko(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:nu(e,o,s),offsetBottom:b,offsetTop:u,top:p,topItems:nu(t,o,s),topListHeight:t.reduce((x,g)=>g.size+x,0),totalCount:n}}function tu(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=Hi(t,a),u=Array.from({length:a}).map((d,f)=>({data:s[f+l],index:f+l,offset:0,size:0}));return Ko(u,[],a,o,n,r)}function nu(e,t,n){if(e.length===0)return[];if(!Wo(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=zo(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=Je(([{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=Ke();ve(s.topItemsIndexes,x);const w=It(U(vt(p,b,Ne(l,Xr),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}),ie(([,,[k,E],A,j,P,L,$,V,M,G])=>{const q=j,{offsetTree:W,sizeTree:B}=q,F=gt(g);if(A===0)return{...Wi,totalCount:A};if(k===0&&E===0)return F===0?{...Wi,totalCount:A}:tu(F,P,j,V,M,G||[]);if(ot(B))return F>0?null:Ko(Xx(Hi(P,A),q,G),[],A,M,q,V);const le=[];if($.length>0){const ye=$[0],Se=$[$.length-1];let K=0;for(const O of zo(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++)le.push({data:G==null?void 0:G[ne],index:ne,offset:K,size:X}),K+=X}}if(!L)return Ko([],le,A,M,q,V);const D=$.length>0?$[$.length-1]+1:0,Q=$x(W,k,E,D);if(Q.length===0)return null;const de=A-1,be=Bo([],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>=E);ne++)ye.push({data:G==null?void 0:G[ne],index:ne,offset:O,size:ee}),O+=ee+M}});return Ko(be,le,A,M,q,V)}),Ae(k=>k!==null),ct()),Wi);ve(U(e,Ae(_i),ie(k=>k==null?void 0:k.length)),o),ve(U(w,ie(k=>k.topListHeight)),f),ve(f,a),ve(U(w,ie(k=>[k.top,k.bottom])),i),ve(U(w,ie(k=>k.items)),v);const S=Bt(U(w,Ae(({items:k})=>k.length>0),Fe(o,e),Ae(([{items:k},E])=>k[k.length-1].originalIndex===E-1),ie(([,k,E])=>[k-1,E]),ct(Xr),ie(([k])=>k))),N=Bt(U(w,Nn(200),Ae(({items:k,topItems:E})=>k.length>0&&k[0].originalIndex===E.length),ie(({items:k})=>k[0].index),ct())),T=Bt(U(w,Ae(({items:k})=>k.length>0),ie(({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(Wc)));return{endReached:S,initialItemCount:g,itemsRendered:v,listState:w,rangeChanged:T,startReached:N,topItemsIndexes:x,...h}},lt(mn,Yc,Ui,Qr,Zr,no,$n,$i),{singleton:!0}),ru=Je(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:o}])=>{const s=Ke(),i=It(U(vt(n,e,r,t,o),ie(([a,l,u,d,f])=>a+l+u+d+f.offsetBottom+f.bottom)),0);return ve(Ne(i),s),{totalListHeight:i,totalListHeightChanged:s}},lt(jt,or),{singleton:!0}),Jx=Je(([{viewportHeight:e},{totalListHeight:t}])=>{const n=Y(!1),r=It(U(vt(n,e,t),Ae(([o])=>o),ie(([,o,s])=>Math.max(0,o-s)),Nn(0),ct()),0);return{alignToBottom:n,paddingTopAddition:r}},lt(jt,ru),{singleton:!0}),ou=Je(()=>({context:Y(null)})),Zx=({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,su=Je(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:s,scrollingInProgress:i,scrollTop:a,viewportHeight:l},{scrollToIndex:u}])=>{const d=Ke();return ve(U(d,Fe(t,l,n,s,o,r,a),Fe(e),ie(([[f,h,p,b,x,g,v,w],S])=>{const{align:N,behavior:T,calculateViewLocation:k=Zx,done:E,...A}=f,j=Kc(f,h,b-1),P=Jr(j,h.offsetTree,S)+x+g,L=P+on(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&&rn(U(i,Ae(G=>!G),tr(gt(i)?1:2)),E):E&&E(),M}),Ae(f=>f!==null)),u),{scrollIntoView:d}},lt(mn,jt,Zr,or,Dn),{singleton:!0});function iu(e){return e?e==="smooth"?"smooth":"auto":!1}const Qx=(e,t)=>typeof e=="function"?iu(e(t)):t&&iu(e),ev=Je(([{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=Ke();let g=null;function v(T){Le(i,{align:"end",behavior:T,index:"LAST"})}Ze(U(vt(U(Ne(t),tr(1)),l),Fe(Ne(b),s,a,f),ie(([[T,k],E,A,j,P])=>{let L=k&&j,$="auto";return L&&($=Qx(E,A||P),L=L&&!!$),{followOutputBehavior:$,shouldFollow:L,totalCount:T}}),Ae(({shouldFollow:T})=>T)),({followOutputBehavior:T,totalCount:k})=>{g&&(g(),g=null),gt(n)?requestAnimationFrame(()=>{gt(d)("following output to ",{totalCount:k},Lt.DEBUG),v(T)}):g=rn(e,()=>{gt(d)("following output to ",{totalCount:k},Lt.DEBUG),v(T),g=null})});function w(T){const k=rn(o,E=>{T&&!E.atBottom&&E.notAtBottomBecause==="SIZE_INCREASED"&&!g&&(gt(d)("scrolling to bottom due to increased size",{},Lt.DEBUG),v("auto"))});setTimeout(k,100)}Ze(U(vt(Ne(b),t,u),Ae(([T,,k])=>T&&k),pn(({value:T},[,k])=>({refreshed:T===k,value:k}),{refreshed:!1,value:0}),Ae(({refreshed:T})=>T),Fe(b,t)),([,T])=>{gt(a)&&w(T!==!1)}),Ze(x,()=>{w(gt(b)!==!1)}),Ze(vt(Ne(b),o),([T,k])=>{T&&!k.atBottom&&k.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&v("auto")});const S=Y(null),N=Ke();return ve(Ri(U(Ne(r),ie(T=>{var k;return(k=T==null?void 0:T.length)!=null?k:0})),U(Ne(t))),N),Ze(U(vt(U(N,tr(1)),l),Fe(Ne(S),a,f,h),ie(([[T,k],E,A,j,P])=>k&&A&&(E==null?void 0:E({context:P,totalCount:T,scrollingInProgress:j}))),Ae(T=>!!T),Nn(0)),T=>{g&&(g(),g=null),gt(n)?requestAnimationFrame(()=>{gt(d)("scrolling into view",{}),Le(p,T)}):g=rn(e,()=>{gt(d)("scrolling into view",{}),Le(p,T),g=null})}),{autoscrollToBottom:x,followOutput:b,scrollIntoViewOnChange:S}},lt(mn,no,Zr,Qr,$n,Dn,jt,ou,su)),tv=Je(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:s,listState:i},{didMount:a}])=>(ve(U(a,Fe(s),Ae(([,l])=>l!==0),Fe(o,r,t,n,e),ie(([[,l],u,d,f,h,p=[]])=>tu(l,u,d,f,h,p))),i),{}),lt(mn,Qr,or,$n),{singleton:!0}),nv=Je(([{didMount:e},{scrollTo:t},{listState:n}])=>{const r=Y(0);return Ze(U(e,Fe(r),Ae(([,o])=>o!==0),ie(([,o])=>({top:o}))),o=>{rn(U(n,tr(1),Ae(s=>s.items.length>1)),()=>{requestAnimationFrame(()=>{Le(t,o)})})}),{initialScrollTop:r}},lt($n,jt,or),{singleton:!0}),au=Je(([{scrollVelocity:e}])=>{const t=Y(!1),n=Ke(),r=Y(!1);return ve(U(e,Fe(r,t,n),Ae(([o,s])=>!!s),ie(([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),Ze(U(vt(t,e,n),Fe(r)),([[o,s,i],a])=>{o&&a&&a.change&&a.change(s,i)}),{isSeeking:t,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:e}},lt(no),{singleton:!0}),Vi=Je(([{scrollContainerState:e,scrollTo:t}])=>{const n=Ke(),r=Ke(),o=Ke(),s=Y(!1),i=Y(void 0);return ve(U(vt(n,r),ie(([{scrollHeight:a,scrollTop:l,viewportHeight:u},{offsetTop:d}])=>({scrollHeight:a,scrollTop:Math.max(0,l-d),viewportHeight:u}))),e),ve(U(t,Fe(r),ie(([a,{offsetTop:l}])=>({...a,top:a.top+l}))),o),{customScrollParent:i,useWindowScroll:s,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:r}},lt(jt)),rv=Je(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:o},{didMount:s},{useWindowScroll:i,windowScrollContainerState:a,windowViewportRect:l}])=>{const u=Ke(),d=Y(void 0),f=Y(null),h=Y(null);return ve(a,f),ve(l,h),Ze(U(u,Fe(t,r,i,f,h,n)),([p,b,x,g,v,w,S])=>{const N=Bx(b.sizeTree);g&&v!==null&&w!==null&&(x=v.scrollTop-w.offsetTop),x-=S,p({ranges:N,scrollTop:x})}),ve(U(d,Ae(_i),ie(ov)),o),ve(U(s,Fe(d),Ae(([,p])=>p!==void 0),ct(),ie(([,p])=>p.ranges)),e),{getState:u,restoreStateFrom:d}},lt(mn,jt,Qr,$n,Vi));function ov(e){return{align:"start",index:0,offset:e.scrollTop}}const sv=Je(([{topItemsIndexes:e}])=>{const t=Y(0);return ve(U(t,Ae(n=>n>=0),ie(n=>Array.from({length:n}).map((r,o)=>o))),e),{topItemCount:t}},lt(or));function lu(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const iv=lu(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),av=Je(([{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=Bt(U(l,Fe(i),pn(([,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),Fe(r,a,n,o,p,b),Ae(([,v,w,S,,,N])=>!N&&!S&&v!==0&&w===eo),ie(([[v],,,,,w])=>(w("Upward scrolling compensation",{amount:v},Lt.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 Ze(U(x,Fe(e,s)),([v,w,S])=>{S&&iv()?Le(e,w-v):g(-v)}),Ze(U(vt(It(s,!1),e,b),Ae(([v,w,S])=>!v&&!S&&w!==0),ie(([v,w])=>w),Nn(1)),g),ve(U(f,ie(v=>({top:-v}))),t),Ze(U(u,Fe(h,d),ie(([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=Yr(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(jt,no,or,mn,Dn,$i)),lv=Je(([e,t,n,r,o,s,i,a,l,u,d])=>({...e,...t,...n,...r,...o,...s,...i,...a,...l,...u,...d}),lt(Ui,tv,$n,au,ru,nv,Jx,Vi,su,Dn,ou)),cu=Je(([{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])=>(ve(N.rangeChanged,j.scrollSeekRangeChanged),ve(U(j.windowViewportRect,ie(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(mn,Qr,jt,rv,ev,or,Zr,av,sv,Yc,lv));function cv(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 Go=typeof document<"u"?y.useLayoutEffect:y.useEffect;function uu(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]=kx(g[t.events[w]]),v),{})}const f=y.forwardRef((g,v)=>{const{children:w,...S}=g,[N]=y.useState(()=>Bo(Ex(e),E=>{l(E,S)})),[T]=y.useState(Pc(d,N));Go(()=>{for(const E of i)E in S&&Ze(T[E],S[E]);return()=>{Object.values(T).map(ji)}},[S,T,N]),Go(()=>{l(N,S)}),y.useImperativeHandle(v,jc(u(N)));const k=n;return c.jsx(a.Provider,{value:N,children:n?c.jsx(k,{...cv([...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=>Ze(v,S),[v]);return y.useSyncExternalStore(w,()=>gt(v),()=>gt(v))},b=g=>{const v=y.useContext(a)[g],[w,S]=y.useState(Pc(gt,v));return Go(()=>Ze(v,N=>{N!==w&&S(jc(N))}),[v,w]),w},x=y.version.startsWith("18")?p:b;return{Component:f,useEmitter:(g,v)=>{const w=y.useContext(a)[g];Go(()=>Ze(w,v),[v,w])},useEmitterValue:x,usePublisher:h}}const du=y.createContext(void 0),fu=y.createContext(void 0),hu=typeof document<"u"?y.useLayoutEffect:y.useEffect;function qi(e){return"self"in e}function uv(e){return"body"in e}function pu(e,t,n,r=Cr,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(uv(g)||qi(g)){const w=qi(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():ni.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;qi(p)?(g=Math.max(Ln(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=Ln(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)),Jc(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 Ki="-webkit-sticky",mu="sticky",Gi=lu(()=>{if(typeof document>"u")return mu;const e=document.createElement("div");return e.style.position=Ki,e.style.position===Ki?Ki:mu});function Yi(e){return e}const dv=Je(()=>{const e=Y(a=>`Item ${a}`),t=Y(a=>`Group ${a}`),n=Y({}),r=Y(Yi),o=Y("div"),s=Y(Cr),i=(a,l=null)=>It(U(n,ie(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")}}),fv=Je(([e,t])=>({...e,...t}),lt(cu,dv)),hv=({height:e})=>c.jsx("div",{style:{height:e}}),pv={overflowAnchor:"none",position:Gi(),zIndex:1},gu={overflowAnchor:"none"},mv={...gu,display:"inline-block",height:"100%"},xu=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"),b=Kt("gap"),x=Re("horizontalDirection"),{callbackRef:g}=_x(n,h,f,e?Cr:a,p,b,o,x,Re("skipAnimationFrameInResizeObserver")),[v,w]=y.useState(0);Xi("deviation",M=>{v!==M&&w(M)});const S=Re("EmptyPlaceholder"),N=Re("ScrollSeekPlaceholder")||hv,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,{...Et(S,u)}):c.jsx(T,{...Et(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,q=A(G+t.firstItemIndex,M.data,u);return j?y.createElement(N,{...Et(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(E,{...Et(E,u),"data-index":G,"data-item-index":M.index,"data-known-size":M.size,key:q,style:pv},d(M.index,u)):y.createElement(k,{...Et(k,u),...bv(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?mv:gu},P?l(M.index,M.groupIndex,M.data,u):l(M.index,M.data,u))})})}),gv={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},xv={outline:"none",overflowX:"auto",position:"relative"},Yo=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),vv={position:Gi(),top:0,width:"100%",zIndex:1};function Et(e,t){if(typeof e!="string")return{context:t}}function bv(e,t){return{item:typeof e=="string"?void 0:t}}const wv=y.memo(function(){const e=Re("HeaderComponent"),t=Kt("headerHeight"),n=Re("HeaderFooterTag"),r=nr(y.useMemo(()=>s=>{t(Ln(s,"height"))},[t]),!0,Re("skipAnimationFrameInResizeObserver")),o=Re("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...Et(e,o)})}):null}),yv=y.memo(function(){const e=Re("FooterComponent"),t=Kt("footerHeight"),n=Re("HeaderFooterTag"),r=nr(y.useMemo(()=>s=>{t(Ln(s,"height"))},[t]),!0,Re("skipAnimationFrameInResizeObserver")),o=Re("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...Et(e,o)})}):null});function vu({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}=pu(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?xv:gv,...o},tabIndex:0,...i,...Et(l,s),children:r})})}function bu({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}=pu(a,u,l,b,h);return hu(()=>{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,...Et(l,s),children:r})})}const Sv=({children:e})=>{const t=y.useContext(du),n=Kt("viewportHeight"),r=Kt("fixedItemHeight"),o=Re("alignToBottom"),s=Re("horizontalDirection"),i=y.useMemo(()=>Rc(n,l=>Ln(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:Yo(o),children:e})},Cv=({children:e})=>{const t=y.useContext(du),n=Kt("windowViewportRect"),r=Kt("fixedItemHeight"),o=Re("customScrollParent"),s=Lc(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:Yo(i),children:e})},Tv=({children:e})=>{const t=Re("TopItemListComponent")||"div",n=Re("headerHeight"),r={...vv,marginTop:`${n}px`},o=Re("context");return c.jsx(t,{style:r,...Et(t,o),children:e})},kv=y.memo(function(e){const t=Re("useWindowScroll"),n=Re("topItemsIndexes").length>0,r=Re("customScrollParent"),o=Re("context");return c.jsxs(r||t?Nv:Ev,{...e,context:o,children:[n&&c.jsx(Tv,{children:c.jsx(xu,{showTopList:!0})}),c.jsxs(r||t?Cv:Sv,{children:[c.jsx(wv,{}),c.jsx(xu,{}),c.jsx(yv,{})]})]})}),{Component:Iv,useEmitter:Xi,useEmitterValue:Re,usePublisher:Kt}=uu(fv,{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"}},kv),Ev=vu({useEmitter:Xi,useEmitterValue:Re,usePublisher:Kt}),Nv=bu({useEmitter:Xi,useEmitterValue:Re,usePublisher:Kt}),Av=Iv;lt(cu,Je(()=>{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(Yi),a=Y(Cr),l=(u,d=null)=>It(U(s,ie(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")}})),Gi();const wu={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},_v={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:yu,floor:Xo,max:ro,min:Ji,round:Su}=Math;function Cu(e,t,n){return Array.from({length:t-e+1}).map((r,o)=>({data:n===null?null:n[o+e],index:o+e}))}function jv(e){return{..._v,items:e}}function Jo(e,t){return e&&e.width===t.width&&e.height===t.height}function Rv(e,t){return e&&e.column===t.column&&e.row===t.row}const Pv=Je(([{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(wu),j=Y({height:0,width:0}),P=Y({height:0,width:0}),L=Ke(),$=Ke(),V=Y(0),M=Y(null),G=Y({column:0,row:0}),q=Ke(),W=Ke(),B=Y(!1),F=Y(0),le=Y(!0),D=Y(!1),Q=Y(!1);Ze(U(b,Fe(F),Ae(([O,X])=>!!X)),()=>{Le(le,!1)}),Ze(U(vt(b,le,P,j,F,D),Ae(([O,X,ee,fe,,ne])=>O&&!X&&ee.height!==0&&fe.height!==0&&!ne)),([,,,,O])=>{Le(D,!0),zi(1,()=>{Le(L,O)}),rn(U(u),()=>{Le(t,[0,0]),Le(le,!0)})}),ve(U(W,Ae(O=>O!=null&&O.scrollTop>0),hn(0)),E),Ze(U(b,Fe(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),rn(U(u,tr(1)),X=>{Le(B,!1)}),Le(l,{top:O.scrollTop})))}),ve(U(j,ie(({height:O})=>O)),f),ve(U(vt(Ne(j,Jo),Ne(P,Jo),Ne(G,(O,X)=>O&&O.column===X.column&&O.row===X.row),Ne(u)),ie(([O,X,ee,fe])=>({gap:ee,item:X,scrollTop:fe,viewport:O}))),q),ve(U(vt(Ne(k),r,Ne(G,Rv),Ne(P,Jo),Ne(j,Jo),Ne(M),Ne(E),Ne(B),Ne(le),Ne(F)),Ae(([,,,,,,,O])=>!O),ie(([O,[X,ee],fe,ne,he,Qe,et,,Pe,He])=>{const{column:ut,row:nt}=fe,{height:Be,width:xt}=ne,{width:J}=he;if(et===0&&(O===0||J===0))return wu;if(xt===0){const bt=Hi(He,O),Zt=bt+Math.max(et-1,0);return jv(Cu(bt,Zt,Qe))}const re=Tu(J,xt,ut);let me,Ce;Pe?X===0&&ee===0&&et>0?(me=0,Ce=et-1):(me=re*Xo((X+nt)/(Be+nt)),Ce=re*yu((ee+nt)/(Be+nt))-1,Ce=Ji(O-1,ro(Ce,re-1)),me=Ji(Ce,ro(0,me))):(me=0,Ce=-1);const ge=Cu(me,Ce,Qe),{bottom:Oe,top:at}=ku(he,fe,ne,ge),Me=yu(O/re),tt=Me*Be+(Me-1)*nt-Oe;return{bottom:Oe,itemHeight:Be,items:ge,itemWidth:xt,offsetBottom:tt,offsetTop:at,top:at}})),A),ve(U(M,Ae(O=>O!==null),ie(O=>O.length)),k),ve(U(vt(j,P,A,G),Ae(([O,X,{items:ee}])=>ee.length>0&&X.height!==0&&O.height!==0),ie(([O,X,{items:ee},fe])=>{const{bottom:ne,top:he}=ku(O,fe,X,ee);return[he,ne]}),ct(Xr)),t);const de=Y(!1);ve(U(u,Fe(de),ie(([O,X])=>X||O!==0)),de);const be=Bt(U(vt(A,k),Ae(([{items:O}])=>O.length>0),Fe(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}),ie(([[,O]])=>O-1),ct())),ye=Bt(U(Ne(A),Ae(({items:O})=>O.length>0&&O[0].index===0),hn(0),ct())),Se=Bt(U(Ne(A),Fe(B),Ae(([{items:O},X])=>O.length>0&&!X),ie(([{items:O}])=>({endIndex:O[O.length-1].index,startIndex:O[0].index})),ct(Wc),Nn(0)));ve(Se,p.scrollSeekRangeChanged),ve(U(L,Fe(j,P,k,G),ie(([O,X,ee,fe,ne])=>{const he=Xc(O),{align:Qe,behavior:et,offset:Pe}=he;let He=he.index;He==="LAST"&&(He=fe-1),He=ro(0,He,Ji(fe-1,He));let ut=Zi(X,ne,ee,He);return Qe==="end"?ut=Su(ut-X.height+ee.height):Qe==="center"&&(ut=Su(ut-X.height/2+ee.height/2)),Pe&&(ut+=Pe),{behavior:et,top:ut}})),l);const K=It(U(A,ie(O=>O.offsetBottom+O.bottom)),0);return ve(U(N,ie(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:Q,initialTopMostItemIndex:F,totalListHeight:K,...h,endReached:be,propsReady:x,rangeChanged:Se,startReached:ye,stateChanged:q,stateRestoreInProgress:B,...T}},lt(Ui,jt,no,au,$n,Vi,Dn));function Tu(e,t,n){return ro(1,Xo((e+n)/(Xo(t)+n)))}function ku(e,t,n,r){const{height:o}=n;if(o===void 0||r.length===0)return{bottom:0,top:0};const s=Zi(e,t,n,r[0].index);return{bottom:Zi(e,t,n,r[r.length-1].index)+o,top:s}}function Zi(e,t,n,r){const o=Tu(e.width,n.width,t.column),s=Xo(r/o),i=s*n.height+ro(0,s-1)*t.row;return i>0?i+t.row:i}const Ov=Je(()=>{const e=Y(f=>`Item ${f}`),t=Y({}),n=Y(null),r=Y("virtuoso-grid-item"),o=Y("virtuoso-grid-list"),s=Y(Yi),i=Y("div"),a=Y(Cr),l=(f,h=null)=>It(U(t,ie(p=>p[f]),ct()),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")}}),Mv=Je(([e,t])=>({...e,...t}),lt(Pv,Ov)),Dv=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"),b=dt("stateRestoreInProgress"),x=Gt("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:Eu("column-gap",getComputedStyle(v).columnGap,p),row:Eu("row-gap",getComputedStyle(v).rowGap,p)})},[i,f,h,p]),!0,!1);return hu(()=>{e.itemHeight>0&&e.itemWidth>0&&x(!0)},[e]),b?null:c.jsx(l,{className:t,ref:g,...Et(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,{...Et(u,d),height:e.itemHeight,index:v.index,width:e.itemWidth},w):y.createElement(a,{...Et(a,d),className:n,"data-index":v.index,key:w},r(v.index,v.data,d))})})}),Lv=y.memo(function(){const e=dt("HeaderComponent"),t=Gt("headerHeight"),n=dt("headerFooterTag"),r=nr(y.useMemo(()=>s=>{t(Ln(s,"height"))},[t]),!0,!1),o=dt("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...Et(e,o)})}):null}),$v=y.memo(function(){const e=dt("FooterComponent"),t=Gt("footerHeight"),n=dt("headerFooterTag"),r=nr(y.useMemo(()=>s=>{t(Ln(s,"height"))},[t]),!0,!1),o=dt("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...Et(e,o)})}):null}),Fv=({children:e})=>{const t=y.useContext(fu),n=Gt("itemDimensions"),r=Gt("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:Yo(!1),children:e})},Bv=({children:e})=>{const t=y.useContext(fu),n=Gt("windowViewportRect"),r=Gt("itemDimensions"),o=dt("customScrollParent"),s=Lc(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:Yo(!1),children:e})},zv=y.memo(function({...e}){const t=dt("useWindowScroll"),n=dt("customScrollParent"),r=n||t?Uv:Hv,o=n||t?Bv:Fv,s=dt("context");return c.jsx(r,{...e,...Et(r,s),children:c.jsxs(o,{children:[c.jsx(Lv,{}),c.jsx(Dv,{}),c.jsx($v,{})]})})}),{useEmitter:Iu,useEmitterValue:dt,usePublisher:Gt}=uu(Mv,{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"}},zv),Hv=vu({useEmitter:Iu,useEmitterValue:dt,usePublisher:Gt}),Uv=bu({useEmitter:Iu,useEmitterValue:dt,usePublisher:Gt});function Eu(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Lt.WARN),t==="normal"?0:parseInt(t??"0",10)}const Wv=yo.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 Qi({className:e,variant:t,...n}){return c.jsx("div",{className:Z(Wv({variant:t}),e),...n})}function ce(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 Vv(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 gn(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,qv(o,...t)]}function qv(...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:()=>{},Kv=m[" useInsertionEffect ".trim().toString()]||Ct;function sr({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=Gv({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=Yv(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 Gv({defaultProp:e,onChange:t}){const[n,r]=m.useState(e),o=m.useRef(n),s=m.useRef(t);return Kv(()=>{s.current=t},[t]),m.useEffect(()=>{var i;o.current!==n&&((i=s.current)==null||i.call(s,n),o.current=n)},[n,o]),[n,r,s]}function Yv(e){return typeof e=="function"}function Nu(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function ea(...e){return t=>{let n=!1;const r=e.map(o=>{const s=Nu(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():Nu(e[o],null)}}}}function Ve(...e){return m.useCallback(ea(...e),e)}var Xv=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],_e=Xv.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 Au(e,t){e&&So.flushSync(()=>e.dispatchEvent(t))}function Jv(e,t){return m.useReducer((n,r)=>t[n][r]??n,e)}var Ht=e=>{const{present:t,children:n}=e,r=Zv(t),o=typeof n=="function"?n({present:r.isPresent}):m.Children.only(n),s=Ve(r.ref,Qv(o));return typeof n=="function"||r.isPresent?m.cloneElement(o,{ref:s}):null};Ht.displayName="Presence";function Zv(e){const[t,n]=m.useState(),r=m.useRef(null),o=m.useRef(e),s=m.useRef("none"),i=e?"mounted":"unmounted",[a,l]=Jv(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return m.useEffect(()=>{const u=Zo(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=Zo(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=Zo(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=Zo(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 Zo(e){return(e==null?void 0:e.animationName)||"none"}function Qv(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 eb=m[" useId ".trim().toString()]||(()=>{}),tb=0;function xn(e){const[t,n]=m.useState(eb());return Ct(()=>{n(r=>r??String(tb++))},[e]),e||(t?`radix-${t}`:"")}var Qo="Collapsible",[nb,FT]=gn(Qo),[rb,ta]=nb(Qo),_u=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:Qo});return c.jsx(rb,{scope:n,disabled:s,contentId:xn(),open:l,onOpenToggle:m.useCallback(()=>u(d=>!d),[u]),children:c.jsx(_e.div,{"data-state":ra(l),"data-disabled":s?"":void 0,...a,ref:t})})});_u.displayName=Qo;var ju="CollapsibleTrigger",Ru=m.forwardRef((e,t)=>{const{__scopeCollapsible:n,...r}=e,o=ta(ju,n);return c.jsx(_e.button,{type:"button","aria-controls":o.contentId,"aria-expanded":o.open||!1,"data-state":ra(o.open),"data-disabled":o.disabled?"":void 0,disabled:o.disabled,...r,ref:t,onClick:ce(e.onClick,o.onOpenToggle)})});Ru.displayName=ju;var na="CollapsibleContent",ob=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=ta(na,e.__scopeCollapsible);return c.jsx(Ht,{present:n||o.open,children:({present:s})=>c.jsx(sb,{...r,ref:t,present:s})})});ob.displayName=na;var sb=m.forwardRef((e,t)=>{const{__scopeCollapsible:n,present:r,children:o,...s}=e,i=ta(na,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),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)},[]),Ct(()=>{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":ra(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 ra(e){return e?"open":"closed"}var ib=_u;const Pu=ib,Ou=Ru,oo=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}));oo.displayName="Card";const so=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:Z("flex flex-col space-y-1.5 p-6",e),...t}));so.displayName="CardHeader";const io=m.forwardRef(({className:e,...t},n)=>c.jsx("h3",{ref:n,className:Z("text-2xl font-semibold leading-none tracking-tight",e),...t}));io.displayName="CardTitle";const Mu=m.forwardRef(({className:e,...t},n)=>c.jsx("p",{ref:n,className:Z("text-sm text-muted-foreground",e),...t}));Mu.displayName="CardDescription";const es=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:Z("p-6 pt-0",e),...t}));es.displayName="CardContent";const Du=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:Z("flex items-center p-6 pt-0",e),...t}));Du.displayName="CardFooter";function Lu(){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=Lu();function ab(e){ir=e}const $u=/[&<>"']/,lb=new RegExp($u.source,"g"),Fu=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,cb=new RegExp(Fu.source,"g"),ub={"&":"&","<":"<",">":">",'"':""","'":"'"},Bu=e=>ub[e];function Nt(e,t){if(t){if($u.test(e))return e.replace(lb,Bu)}else if(Fu.test(e))return e.replace(cb,Bu);return e}const db=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;function zu(e){return e.replace(db,(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 fb=/(^|[^\[])\^/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(fb,"$1"),e=e.replace(r,o),n),getRegex:()=>new RegExp(e,t)};return n}const hb=/[^\w:]/g,pb=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function Hu(e,t,n){if(e){let r;try{r=decodeURIComponent(zu(n)).replace(hb,"").toLowerCase()}catch{return null}if(r.indexOf("javascript:")===0||r.indexOf("vbscript:")===0||r.indexOf("data:")===0)return null}t&&!pb.test(n)&&(n=vb(t,n));try{n=encodeURI(n).replace(/%25/g,"%")}catch{return null}return n}const ts={},mb=/^[^:]+:\/*[^/]*$/,gb=/^([^:]+:)[\s\S]*$/,xb=/^([^:]+:\/*[^/]*)[\s\S]*$/;function vb(e,t){ts[" "+e]||(mb.test(e)?ts[" "+e]=e+"/":ts[" "+e]=rs(e,"/",!0)),e=ts[" "+e];const n=e.indexOf(":")===-1;return t.substring(0,2)==="//"?n?t:e.replace(gb,"$1")+t:t.charAt(0)==="/"?n?t:e.replace(xb,"$1")+t:e+t}const ns={exec:function(){}};function Uu(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 rs(e,t,n){const r=e.length;if(r===0)return"";let o=0;for(;o<r;){const s=e.charAt(r-o-1);if(s===t&&!n)o++;else if(s!==t&&n)o++;else break}return e.slice(0,r-o)}function bb(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 wb(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 Wu(e,t){if(t<1)return"";let n="";for(;t>1;)t&1&&(n+=e),t>>=1,e+=e;return n+e}function Vu(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 yb(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
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
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
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"),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]):
|
|
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 Yu(e,t){return(n,r,o)=>{typeof r=="function"&&(o=r,r=null);const s={...r};r={...ke.defaults,...s};const i=Cb(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(wb(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 Yu(Fn.lex,Bn.parse)(e,t,n)}ke.options=ke.setOptions=function(e){return ke.defaults={...ke.defaults,...e},ab(ke.defaults),ke},ke.getDefaults=Lu,ke.defaults=ir,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 sa;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 oa;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 os;for(const s in n.hooks){const i=o[s];os.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=Yu(Fn.lexInline,Bn.parseInline),ke.Parser=Bn,ke.parser=Bn.parse,ke.Renderer=sa,ke.TextRenderer=Ku,ke.Lexer=Fn,ke.lexer=Fn.lex,ke.Tokenizer=oa,ke.Slugger=Gu,ke.Hooks=os,ke.parse=ke,ke.options,ke.setOptions,ke.use,ke.walkTokens,ke.parseInline,Bn.parse,Fn.lex;function ia({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 Xu(e,t){return await tn(e,{responseType:"blob",onDownloadProgress:r=>{try{t&&r.lengthComputable}catch{}},maxBodyLength:1/0})}async function Ju(e,t){return await(await Xu(`/files/${e}/view`,t)).text()}async function Tb(e,t){const n=await Xu(`/files/${e}/download`,t),r=URL.createObjectURL(n);let o=`file_${e}`;try{const i=await tn(`/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 kb(e,t=50,n=0){const r={limit:t,offset:n};return e&&(r.thread_id=e),await tn("/files",{params:r})}const Ib=1,Eb=1e6;let aa=0;function Nb(){return aa=(aa+1)%Number.MAX_SAFE_INTEGER,aa.toString()}const la=new Map,Zu=e=>{if(la.has(e))return;const t=setTimeout(()=>{la.delete(e),ao({type:"REMOVE_TOAST",toastId:e})},Eb);la.set(e,t)},Ab=(e,t)=>{switch(t.type){case"ADD_TOAST":return{...e,toasts:[t.toast,...e.toasts].slice(0,Ib)};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?Zu(n):e.toasts.forEach(r=>{Zu(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)}}},ss=[];let is={toasts:[]};function ao(e){is=Ab(is,e),ss.forEach(t=>{t(is)})}function _b({...e}){const t=Nb(),n=o=>ao({type:"UPDATE_TOAST",toast:{...o,id:t}}),r=()=>ao({type:"DISMISS_TOAST",toastId:t});return ao({type:"ADD_TOAST",toast:{...e,id:t,open:!0,onOpenChange:o=>{o||r()}}}),{id:t,dismiss:r,update:n}}function ca(){const[e,t]=m.useState(is);return m.useEffect(()=>(ss.push(t),()=>{const n=ss.indexOf(t);n>-1&&ss.splice(n,1)}),[e]),{...e,toast:_b,dismiss:n=>ao({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 jb(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 Rb="DismissableLayer",ua="dismissableLayer.update",Pb="dismissableLayer.pointerDownOutside",Ob="dismissableLayer.focusOutside",Qu,ed=m.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),as=m.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:a,...l}=e,u=m.useContext(ed),[d,f]=m.useState(null),h=(d==null?void 0:d.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,p]=m.useState({}),b=Ve(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=Lb(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=$b(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 jb(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&&(Qu=h.body.style.pointerEvents,h.body.style.pointerEvents="none"),u.layersWithOutsidePointerEventsDisabled.add(d)),u.layers.add(d),td(),()=>{n&&u.layersWithOutsidePointerEventsDisabled.size===1&&(h.body.style.pointerEvents=Qu)}},[d,h,n,u]),m.useEffect(()=>()=>{d&&(u.layers.delete(d),u.layersWithOutsidePointerEventsDisabled.delete(d),td())},[d,u]),m.useEffect(()=>{const E=()=>p({});return document.addEventListener(ua,E),()=>document.removeEventListener(ua,E)},[]),c.jsx(_e.div,{...l,ref:b,style:{pointerEvents:S?N?"auto":"none":void 0,...e.style},onFocusCapture:ce(e.onFocusCapture,k.onFocusCapture),onBlurCapture:ce(e.onBlurCapture,k.onBlurCapture),onPointerDownCapture:ce(e.onPointerDownCapture,T.onPointerDownCapture)})});as.displayName=Rb;var Mb="DismissableLayerBranch",Db=m.forwardRef((e,t)=>{const n=m.useContext(ed),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})});Db.displayName=Mb;function Lb(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(){nd(Pb,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 $b(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&&nd(Ob,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 td(){const e=new CustomEvent(ua);document.dispatchEvent(e)}function nd(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?Au(o,s):o.dispatchEvent(s)}var da="focusScope.autoFocusOnMount",fa="focusScope.autoFocusOnUnmount",rd={bubbles:!1,cancelable:!0},Fb="FocusScope",ls=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:zn(f.current,{select:!0})},g=function(S){if(p.paused||!a)return;const N=S.relatedTarget;N!==null&&(a.contains(N)||zn(f.current,{select:!0}))},v=function(S){if(document.activeElement===document.body)for(const T of S)T.removedNodes.length>0&&zn(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){id.add(p);const x=document.activeElement;if(!a.contains(x)){const v=new CustomEvent(da,rd);a.addEventListener(da,u),a.dispatchEvent(v),v.defaultPrevented||(Bb(Vb(od(a)),{select:!0}),document.activeElement===x&&zn(a))}return()=>{a.removeEventListener(da,u),setTimeout(()=>{const v=new CustomEvent(fa,rd);a.addEventListener(fa,d),a.dispatchEvent(v),v.defaultPrevented||zn(x??document.body,{select:!0}),a.removeEventListener(fa,d),id.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]=zb(w);S&&N?!x.shiftKey&&v===N?(x.preventDefault(),n&&zn(S,{select:!0})):x.shiftKey&&v===S&&(x.preventDefault(),n&&zn(N,{select:!0})):v===w&&x.preventDefault()}},[n,r,p.paused]);return c.jsx(_e.div,{tabIndex:-1,...i,ref:h,onKeyDown:b})});ls.displayName=Fb;function Bb(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(zn(r,{select:t}),document.activeElement!==n)return}function zb(e){const t=od(e),n=sd(t,e),r=sd(t.reverse(),e);return[n,r]}function od(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 sd(e,t){for(const n of e)if(!Hb(n,{upTo:t}))return n}function Hb(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 Ub(e){return e instanceof HTMLInputElement&&"select"in e}function zn(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&Ub(e)&&t&&e.select()}}var id=Wb();function Wb(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=ad(e,t),e.unshift(t)},remove(t){var n;e=ad(e,t),(n=e[0])==null||n.resume()}}}function ad(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function Vb(e){return e.filter(t=>t.tagName!=="A")}var qb="Portal",cs=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?ni.createPortal(c.jsx(_e.div,{...r,ref:t}),i):null});cs.displayName=qb;var ha=0;function pa(){m.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??ld()),document.body.insertAdjacentElement("beforeend",e[1]??ld()),ha++,()=>{ha===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),ha--}},[])}function ld(){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 vn=function(){return vn=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},vn.apply(this,arguments)};function cd(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var o=0,r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]]);return n}function Kb(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 us="right-scroll-bar-position",ds="width-before-scroll-bar",Gb="with-scroll-bars-hidden",Yb="--removed-body-scroll-bar-size";function ma(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function Xb(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 Jb=typeof window<"u"?m.useLayoutEffect:m.useEffect,ud=new WeakMap;function Zb(e,t){var n=Xb(null,function(r){return e.forEach(function(o){return ma(o,r)})});return Jb(function(){var r=ud.get(n);if(r){var o=new Set(r),s=new Set(e),i=n.current;o.forEach(function(a){s.has(a)||ma(a,null)}),s.forEach(function(a){o.has(a)||ma(a,i)})}ud.set(n,e)},[e]),n}function Qb(e){return e}function ew(e,t){t===void 0&&(t=Qb);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 tw(e){e===void 0&&(e={});var t=ew(null);return t.options=vn({async:!0,ssr:!1},e),t}var dd=function(e){var t=e.sideCar,n=cd(e,["sideCar"]);if(!t)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=t.read();if(!r)throw new Error("Sidecar medium not found");return m.createElement(r,vn({},n))};dd.isSideCarExport=!0;function nw(e,t){return e.useMedium(t),dd}var fd=tw(),ga=function(){},fs=m.forwardRef(function(e,t){var n=m.useRef(null),r=m.useState({onScrollCapture:ga,onWheelCapture:ga,onTouchMoveCapture:ga}),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=cd(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),T=h,k=Zb([n,t]),E=vn(vn({},N),o);return m.createElement(m.Fragment,null,d&&m.createElement(T,{sideCar:fd,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),vn(vn({},E),{ref:k})):m.createElement(w,vn({},E,{className:l,ref:k}),a))});fs.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},fs.classNames={fullWidth:ds,zeroRight:us};var rw=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function ow(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=rw();return t&&e.setAttribute("nonce",t),e}function sw(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function iw(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var aw=function(){var e=0,t=null;return{add:function(n){e==0&&(t=ow())&&(sw(t,n),iw(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},lw=function(){var e=aw();return function(t,n){m.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},hd=function(){var e=lw(),t=function(n){var r=n.styles,o=n.dynamic;return e(r,o),null};return t},cw={left:0,top:0,right:0,gap:0},xa=function(e){return parseInt(e||"",10)||0},uw=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[xa(n),xa(r),xa(o)]},dw=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return cw;var t=uw(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])}},fw=hd(),kr="data-scroll-locked",hw=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 ${ge.length-cr} chars]`:ge,at=N==="expanded";return c.jsxs(Pu,{open:at,onOpenChange:Me=>T(Me?"expanded":"preview"),children:[c.jsx("div",{className:"flex items-center gap-2 text-xs",children:c.jsx(Qi,{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(Ou,{asChild:!0,children:c.jsx(Xe,{variant:"ghost",size:"sm",className:"h-6 text-xs",children:at?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"]})})})]},me.toolCallId??Ce)})})}if(!F){const re=c.jsx("div",{className:"space-y-2",children:t.content.map((me,Ce)=>c.jsx(ut,{part:me,i:Ce},Ce))});return r?c.jsxs("div",{"aria-busy":"true",role:"status",children:[re,c.jsx(Zw,{className:D})]}):re}},[Q,be.length,ye.length,Se.length,r,t.model,F,de.name,K,N,u,nt,D]),xt=y.useMemo(()=>Jw(t),[t]);return c.jsxs(c.Fragment,{children:[c.jsx("div",{className:Z(Qe(),p.container),children:c.jsxs("div",{className:Z(et(),p.content),children:[(i||a||F)&&c.jsxs("div",{className:Z("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:[he(),a&&xt&&c.jsx("span",{className:Z("font-medium",W?"text-xs":"text-sm"),children:xt}),F&&de.name&&c.jsxs(Qi,{variant:"outline",className:Z("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:J=>{(J.key==="Enter"||J.key===" ")&&(J.preventDefault(),T(re=>re==="collapsed"?"preview":"collapsed"))},onClick:()=>T(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"})})]}),F&&!de.name&&c.jsx(Xe,{variant:"ghost",size:"sm",className:Z("h-6 px-1",D,"hover:bg-foreground/10"),onClick:()=>T(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,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: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(Xe,{variant:"ghost",size:"sm",onClick:()=>X(F?"visible":"all"),className:Z("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(oe.Copy,{className:Z(w?"text-success":D,W?"h-3 w-3":"h-4 w-4")})}),F&&c.jsx(Xe,{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"&&b&&c.jsx(Xe,{variant:"ghost",size:"sm",onClick:ee,className:Z("h-6 w-6 p-0 hover:bg-foreground/10",D,W&&"h-5 w-5"),"aria-label":"Edit message",children:c.jsx(oe.Edit,{className:Z(D,W?"h-3 w-3":"h-4 w-4")})}),B==="assistant"&&x&&c.jsx(Xe,{variant:"ghost",size:"sm",onClick:fe,className:Z("h-6 w-6 p-0 hover:bg-foreground/10",D,W&&"h-5 w-5"),"aria-label":"Regenerate response",children:c.jsx(oe.RotateCcw,{className:Z(D,W?"h-3 w-3":"h-4 w-4")})})]})]})]}),c.jsx("div",{className:"relative",children:Be()}),F&&N==="expanded"&&(de.toolCallId||de.name)&&c.jsxs("div",{className:Z("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",W&&"text-xs"),children:[de.name&&c.jsxs("div",{children:["Function: ",de.name]}),de.toolCallId&&c.jsxs("div",{children:["Call ID: ",de.toolCallId]})]}),!(i||a||F)&&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(Xe,{variant:"ghost",size:"sm",onClick:()=>X(),className:Z("h-6 w-6 p-0 hover:bg-background/50 text-current",W&&"h-5 w-5"),children:c.jsx(oe.Copy,{className:Z(w?"text-success":"text-current",W?"h-3 w-3":"h-4 w-4")})}),B==="user"&&b&&c.jsx(Xe,{variant:"ghost",size:"sm",onClick:ee,className:Z("h-6 w-6 p-0 hover:bg-background/50 text-current",W&&"h-5 w-5"),children:c.jsx(oe.Edit,{className:Z("text-current",W?"h-3 w-3":"h-4 w-4")})}),B==="assistant"&&x&&c.jsx(Xe,{variant:"ghost",size:"sm",onClick:fe,className:Z("h-6 w-6 p-0 hover:bg-background/50 text-current",W&&"h-5 w-5"),children:c.jsx(oe.RotateCcw,{className:Z("text-current",W?"h-3 w-3":"h-4 w-4")})})]})]})}),G&&c.jsx(Vw,{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&&Gd(e.message)===Gd(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 Qw({data:e}){if(Array.isArray(e))return e.every(n=>n===null||["string","number","boolean"].includes(typeof n))?c.jsx("div",{className:Cs,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:Ta(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:Cs,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:Cs,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:ey(i)})]},s))})})}return c.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:Ta(e)})}function ey(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(lo(e))})}catch{return String(e)}}function ty({interruptPart:e,onApprove:t,onReject:n}){const r=e.title??"Approve the result?";return c.jsxs(oo,{className:"border-blue-200 dark:border-blue-800 bg-blue-50/50 dark:bg-blue-950/10",children:[c.jsxs(so,{className:"pb-3",children:[c.jsx(io,{className:"text-blue-900 dark:text-blue-100 text-base",children:r}),c.jsx(Mu,{className:"text-blue-700 dark:text-blue-300",children:"Please approve or reject this action to continue."})]}),c.jsx(Du,{className:"pt-0",children:c.jsxs("div",{className:"flex gap-2 ml-auto",children:[c.jsx(Xe,{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(Xe,{size:"sm",onClick:()=>t(e),className:"bg-blue-600 hover:bg-blue-700 text-white",children:"Approve"})]})})]})}function ny({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 ry({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:Cs,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 Xd=(e,t)=>(e==null?void 0:e.id)??`message-${t}`,ka=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(Av,{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,$)=>Xd($,L),itemContent:(L,$)=>{const V=Xd($,L);return c.jsx("div",{className:"mb-4 last:mb-0","data-message-id":V,style:{minHeight:"60px",containIntrinsicSize:"auto 120px"},children:c.jsx(Yd,{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})})}})})});ka.displayName="MessageList";const Ts=1e4;function oy(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 sy(e,t=Ts){if(!e||typeof e!="string")throw new Error("Invalid content: must be a non-empty string");if(e.length>t)throw new Error(`Message exceeds maximum length of ${t} characters`);return e}function iy(e){let t;return typeof e=="string"?t=e:typeof e=="object"&&e!==null?t=JSON.stringify(e):t=String(e),sy(t),oy(t)}function Ia(e){const t=e+"CollectionProvider",[n,r]=gn(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=Ve(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=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: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 ay=m.createContext(void 0);function ks(e){const t=m.useContext(ay);return e||t||"ltr"}const ly=["top","right","bottom","left"],Hn=Math.min,Ut=Math.max,Is=Math.round,Es=Math.floor,bn=e=>({x:e,y:e}),cy={left:"right",right:"left",bottom:"top",top:"bottom"},uy={start:"end",end:"start"};function Ea(e,t,n){return Ut(e,Hn(t,n))}function An(e,t){return typeof e=="function"?e(t):e}function _n(e){return e.split("-")[0]}function Ar(e){return e.split("-")[1]}function Na(e){return e==="x"?"y":"x"}function Aa(e){return e==="y"?"height":"width"}const dy=new Set(["top","bottom"]);function wn(e){return dy.has(_n(e))?"y":"x"}function _a(e){return Na(wn(e))}function fy(e,t,n){n===void 0&&(n=!1);const r=Ar(e),o=_a(e),s=Aa(o);let i=o==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(i=Ns(i)),[i,Ns(i)]}function hy(e){const t=Ns(e);return[ja(e),t,ja(t)]}function ja(e){return e.replace(/start|end/g,t=>uy[t])}const Jd=["left","right"],Zd=["right","left"],py=["top","bottom"],my=["bottom","top"];function gy(e,t,n){switch(e){case"top":case"bottom":return n?t?Zd:Jd:t?Jd:Zd;case"left":case"right":return t?py:my;default:return[]}}function xy(e,t,n,r){const o=Ar(e);let s=gy(_n(e),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(ja)))),s}function Ns(e){return e.replace(/left|right|bottom|top/g,t=>cy[t])}function vy(e){return{top:0,right:0,bottom:0,left:0,...e}}function Qd(e){return typeof e!="number"?vy(e):{top:e,right:e,bottom:e,left:e}}function As(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 ef(e,t,n){let{reference:r,floating:o}=e;const s=wn(t),i=_a(t),a=Aa(i),l=_n(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(Ar(t)){case"start":p[i]-=h*(n&&u?-1:1);break;case"end":p[i]+=h*(n&&u?-1:1);break}return p}const by=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}=ef(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}=ef(u,h,l)),x=-1)}return{x:d,y:f,placement:h,strategy:o,middlewareData:p}};async function co(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}=An(t,e),b=Qd(p),g=a[h?f==="floating"?"reference":"floating":f],v=As(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=As(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 wy=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}=An(e,t)||{};if(u==null)return{};const f=Qd(d),h={x:n,y:r},p=_a(o),b=Aa(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=Hn(f[v],j),L=Hn(f[w],j),$=P,V=E-x[b]-L,M=E/2-x[b]/2+A,G=Ea($,M,V),q=!l.arrow&&Ar(o)!=null&&M!==G&&s.reference[b]/2-(M<$?P:L)-x[b]/2<0,W=q?M<$?M-$:M-V:0;return{[p]:h[p]+W,data:{[p]:G,centerOffset:M-G-W,...q&&{alignmentOffset:W}},reset:q}}}),yy=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(t){var n,r;const{placement:o,middlewareData:s,rects:i,initialPlacement:a,platform:l,elements:u}=t,{mainAxis:d=!0,crossAxis:f=!0,fallbackPlacements:h,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:b="none",flipAlignment:x=!0,...g}=An(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const v=_n(o),w=wn(a),S=_n(a)===a,N=await(l.isRTL==null?void 0:l.isRTL(u.floating)),T=h||(S||!x?[Ns(a)]:hy(a)),k=b!=="none";!h&&k&&T.push(...xy(a,x,b,N));const E=[a,...T],A=await co(t,g),j=[];let P=((r=s.flip)==null?void 0:r.overflows)||[];if(d&&j.push(A[v]),f){const M=fy(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!==wn(G):!1)||P.every(B=>wn(B.placement)===w?B.overflows[0]>0:!0)))return{data:{index:M,overflows:P},reset:{placement:G}};let q=($=P.filter(W=>W.overflows[0]<=0).sort((W,B)=>W.overflows[1]-B.overflows[1])[0])==null?void 0:$.placement;if(!q)switch(p){case"bestFit":{var V;const W=(V=P.filter(B=>{if(k){const F=wn(B.placement);return F===w||F==="y"}return!0}).map(B=>[B.placement,B.overflows.filter(F=>F>0).reduce((F,le)=>F+le,0)]).sort((B,F)=>B[1]-F[1])[0])==null?void 0:V[0];W&&(q=W);break}case"initialPlacement":q=a;break}if(o!==q)return{reset:{placement:q}}}return{}}}};function tf(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function nf(e){return ly.some(t=>e[t]>=0)}const Sy=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n}=t,{strategy:r="referenceHidden",...o}=An(e,t);switch(r){case"referenceHidden":{const s=await co(t,{...o,elementContext:"reference"}),i=tf(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:nf(i)}}}case"escaped":{const s=await co(t,{...o,altBoundary:!0}),i=tf(s,n.floating);return{data:{escapedOffsets:i,escaped:nf(i)}}}default:return{}}}}},rf=new Set(["left","top"]);async function Cy(e,t){const{placement:n,platform:r,elements:o}=e,s=await(r.isRTL==null?void 0:r.isRTL(o.floating)),i=_n(n),a=Ar(n),l=wn(n)==="y",u=rf.has(i)?-1:1,d=s&&l?-1:1,f=An(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 Ty=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 Cy(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}}}}},ky=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}=An(e,t),u={x:n,y:r},d=await co(t,l),f=wn(_n(o)),h=Na(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=Ea(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=Ea(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}}}}}},Iy=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}=An(e,t),d={x:n,y:r},f=wn(o),h=Na(f);let p=d[h],b=d[f];const x=An(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=rf.has(_n(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}}}},Ey=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}=An(e,t),d=await co(t,u),f=_n(o),h=Ar(o),p=wn(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=Hn(x-d[g],w),T=Hn(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=Ut(d.left,0),L=Ut(d.right,0),$=Ut(d.top,0),V=Ut(d.bottom,0);p?A=b-2*(P!==0||L!==0?P+L:Ut(d.left,d.right)):E=x-2*($!==0||V!==0?$+V:Ut(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 _s(){return typeof window<"u"}function _r(e){return of(e)?(e.nodeName||"").toLowerCase():"#document"}function Wt(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function yn(e){var t;return(t=(of(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function of(e){return _s()?e instanceof Node||e instanceof Wt(e).Node:!1}function an(e){return _s()?e instanceof Element||e instanceof Wt(e).Element:!1}function Sn(e){return _s()?e instanceof HTMLElement||e instanceof Wt(e).HTMLElement:!1}function sf(e){return!_s()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Wt(e).ShadowRoot}const Ny=new Set(["inline","contents"]);function uo(e){const{overflow:t,overflowX:n,overflowY:r,display:o}=ln(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!Ny.has(o)}const Ay=new Set(["table","td","th"]);function _y(e){return Ay.has(_r(e))}const jy=[":popover-open",":modal"];function js(e){return jy.some(t=>{try{return e.matches(t)}catch{return!1}})}const Ry=["transform","translate","scale","rotate","perspective"],Py=["transform","translate","scale","rotate","perspective","filter"],Oy=["paint","layout","strict","content"];function Ra(e){const t=Pa(),n=an(e)?ln(e):e;return Ry.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)||Py.some(r=>(n.willChange||"").includes(r))||Oy.some(r=>(n.contain||"").includes(r))}function My(e){let t=Un(e);for(;Sn(t)&&!jr(t);){if(Ra(t))return t;if(js(t))return null;t=Un(t)}return null}function Pa(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const Dy=new Set(["html","body","#document"]);function jr(e){return Dy.has(_r(e))}function ln(e){return Wt(e).getComputedStyle(e)}function Rs(e){return an(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Un(e){if(_r(e)==="html")return e;const t=e.assignedSlot||e.parentNode||sf(e)&&e.host||yn(e);return sf(t)?t.host:t}function af(e){const t=Un(e);return jr(t)?e.ownerDocument?e.ownerDocument.body:e.body:Sn(t)&&uo(t)?t:af(t)}function fo(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const o=af(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=Wt(o);if(s){const a=Oa(i);return t.concat(i,i.visualViewport||[],uo(o)?o:[],a&&n?fo(a):[])}return t.concat(o,fo(o,[],n))}function Oa(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function lf(e){const t=ln(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const o=Sn(e),s=o?e.offsetWidth:n,i=o?e.offsetHeight:r,a=Is(n)!==s||Is(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function Ma(e){return an(e)?e:e.contextElement}function Rr(e){const t=Ma(e);if(!Sn(t))return bn(1);const n=t.getBoundingClientRect(),{width:r,height:o,$:s}=lf(t);let i=(s?Is(n.width):n.width)/r,a=(s?Is(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const Ly=bn(0);function cf(e){const t=Wt(e);return!Pa()||!t.visualViewport?Ly:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function $y(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==Wt(e)?!1:t}function ur(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const o=e.getBoundingClientRect(),s=Ma(e);let i=bn(1);t&&(r?an(r)&&(i=Rr(r)):i=Rr(e));const a=$y(s,n,r)?cf(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=Wt(s),p=r&&an(r)?Wt(r):r;let b=h,x=Oa(b);for(;x&&r&&p!==b;){const g=Rr(x),v=x.getBoundingClientRect(),w=ln(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=Wt(x),x=Oa(b)}}return As({width:d,height:f,x:l,y:u})}function Ps(e,t){const n=Rs(e).scrollLeft;return t?t.left+n:ur(yn(e)).left+n}function uf(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-Ps(e,n),o=n.top+t.scrollTop;return{x:r,y:o}}function Fy(e){let{elements:t,rect:n,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=yn(r),a=t?js(t.floating):!1;if(r===i||a&&s)return n;let l={scrollLeft:0,scrollTop:0},u=bn(1);const d=bn(0),f=Sn(r);if((f||!f&&!s)&&((_r(r)!=="body"||uo(i))&&(l=Rs(r)),Sn(r))){const p=ur(r);u=Rr(r),d.x=p.x+r.clientLeft,d.y=p.y+r.clientTop}const h=i&&!f&&!s?uf(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 By(e){return Array.from(e.getClientRects())}function zy(e){const t=yn(e),n=Rs(e),r=e.ownerDocument.body,o=Ut(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=Ut(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let i=-n.scrollLeft+Ps(e);const a=-n.scrollTop;return ln(r).direction==="rtl"&&(i+=Ut(t.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}const df=25;function Hy(e,t){const n=Wt(e),r=yn(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=Pa();(!d||d&&t==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}const u=Ps(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<=df&&(s-=b)}else u<=df&&(s+=u);return{width:s,height:i,x:a,y:l}}const Uy=new Set(["absolute","fixed"]);function Wy(e,t){const n=ur(e,!0,t==="fixed"),r=n.top+e.clientTop,o=n.left+e.clientLeft,s=Sn(e)?Rr(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 ff(e,t,n){let r;if(t==="viewport")r=Hy(e,n);else if(t==="document")r=zy(yn(e));else if(an(t))r=Wy(t,n);else{const o=cf(e);r={x:t.x-o.x,y:t.y-o.y,width:t.width,height:t.height}}return As(r)}function hf(e,t){const n=Un(e);return n===t||!an(n)||jr(n)?!1:ln(n).position==="fixed"||hf(n,t)}function Vy(e,t){const n=t.get(e);if(n)return n;let r=fo(e,[],!1).filter(a=>an(a)&&_r(a)!=="body"),o=null;const s=ln(e).position==="fixed";let i=s?Un(e):e;for(;an(i)&&!jr(i);){const a=ln(i),l=Ra(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&Uy.has(o.position)||uo(i)&&!l&&hf(e,i))?r=r.filter(d=>d!==i):o=a,i=Un(i)}return t.set(e,r),r}function qy(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i=[...n==="clippingAncestors"?js(t)?[]:Vy(t,this._c):[].concat(n),r],a=i[0],l=i.reduce((u,d)=>{const f=ff(t,d,o);return u.top=Ut(f.top,u.top),u.right=Hn(f.right,u.right),u.bottom=Hn(f.bottom,u.bottom),u.left=Ut(f.left,u.left),u},ff(t,a,o));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function Ky(e){const{width:t,height:n}=lf(e);return{width:t,height:n}}function Gy(e,t,n){const r=Sn(t),o=yn(t),s=n==="fixed",i=ur(e,!0,s,t);let a={scrollLeft:0,scrollTop:0};const l=bn(0);function u(){l.x=Ps(o)}if(r||!r&&!s)if((_r(t)!=="body"||uo(o))&&(a=Rs(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?uf(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 Da(e){return ln(e).position==="static"}function pf(e,t){if(!Sn(e)||ln(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return yn(e)===n&&(n=n.ownerDocument.body),n}function mf(e,t){const n=Wt(e);if(js(e))return n;if(!Sn(e)){let o=Un(e);for(;o&&!jr(o);){if(an(o)&&!Da(o))return o;o=Un(o)}return n}let r=pf(e,t);for(;r&&_y(r)&&Da(r);)r=pf(r,t);return r&&jr(r)&&Da(r)&&!Ra(r)?n:r||My(e)||n}const Yy=async function(e){const t=this.getOffsetParent||mf,n=this.getDimensions,r=await n(e.floating);return{reference:Gy(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function Xy(e){return ln(e).direction==="rtl"}const Jy={convertOffsetParentRelativeRectToViewportRelativeRect:Fy,getDocumentElement:yn,getClippingRect:qy,getOffsetParent:mf,getElementRects:Yy,getClientRects:By,getDimensions:Ky,getScale:Rr,isElement:an,isRTL:Xy};function gf(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function Zy(e,t){let n=null,r;const o=yn(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=Es(f),x=Es(o.clientWidth-(d+h)),g=Es(o.clientHeight-(f+p)),v=Es(d),S={rootMargin:-b+"px "+-x+"px "+-g+"px "+-v+"px",threshold:Ut(0,Hn(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&&!gf(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 Qy(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=Ma(e),d=o||s?[...u?fo(u):[],...fo(t)]:[];d.forEach(v=>{o&&v.addEventListener("scroll",n,{passive:!0}),s&&v.addEventListener("resize",n)});const f=u&&a?Zy(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&&!gf(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 e0=Ty,t0=ky,n0=yy,r0=Ey,o0=Sy,xf=wy,s0=Iy,i0=(e,t,n)=>{const r=new Map,o={platform:Jy,...n},s={...o.platform,_c:r};return by(e,t,{...o,platform:s})};var a0=typeof document<"u",l0=function(){},Os=a0?y.useLayoutEffect:l0;function Ms(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(!Ms(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)&&!Ms(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function vf(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function bf(e,t){const n=vf(e);return Math.round(t*n)/n}function La(e){const t=m.useRef(e);return Os(()=>{t.current=e}),t}function c0(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);Ms(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=La(l),L=La(o),$=La(u),V=m.useCallback(()=>{if(!k.current||!E.current)return;const B={placement:t,strategy:n,middleware:h};L.current&&(B.platform=L.current),i0(k.current,E.current,B).then(F=>{const le={...F,isPositioned:$.current!==!1};M.current&&!Ms(A.current,le)&&(A.current=le,So.flushSync(()=>{f(le)}))})},[h,t,n,L,$]);Os(()=>{u===!1&&A.current.isPositioned&&(A.current.isPositioned=!1,f(B=>({...B,isPositioned:!1})))},[u]);const M=m.useRef(!1);Os(()=>(M.current=!0,()=>{M.current=!1}),[]),Os(()=>{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]),q=m.useMemo(()=>({reference:N,floating:T}),[N,T]),W=m.useMemo(()=>{const B={position:n,left:0,top:0};if(!q.floating)return B;const F=bf(q.floating,d.x),le=bf(q.floating,d.y);return a?{...B,transform:"translate("+F+"px, "+le+"px)",...vf(q.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:F,top:le}},[n,a,q.floating,d.x,d.y]);return m.useMemo(()=>({...d,update:V,refs:G,elements:q,floatingStyles:W}),[d,V,G,q,W])}const u0=e=>{function t(n){return{}.hasOwnProperty.call(n,"current")}return{name:"arrow",options:e,fn(n){const{element:r,padding:o}=typeof e=="function"?e(n):e;return r&&t(r)?r.current!=null?xf({element:r.current,padding:o}).fn(n):{}:r?xf({element:r,padding:o}).fn(n):{}}}},d0=(e,t)=>({...e0(e),options:[e,t]}),f0=(e,t)=>({...t0(e),options:[e,t]}),h0=(e,t)=>({...s0(e),options:[e,t]}),p0=(e,t)=>({...n0(e),options:[e,t]}),m0=(e,t)=>({...r0(e),options:[e,t]}),g0=(e,t)=>({...o0(e),options:[e,t]}),x0=(e,t)=>({...u0(e),options:[e,t]});var v0="Arrow",wf=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"})})});wf.displayName=v0;var b0=wf;function yf(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 $a="Popper",[Sf,Ds]=gn($a),[w0,Cf]=Sf($a),Tf=e=>{const{__scopePopper:t,children:n}=e,[r,o]=m.useState(null);return c.jsx(w0,{scope:t,anchor:r,onAnchorChange:o,children:n})};Tf.displayName=$a;var kf="PopperAnchor",If=m.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...o}=e,s=Cf(kf,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})});If.displayName=kf;var Fa="PopperContent",[y0,S0]=Sf(Fa),Ef=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:b,...x}=e,g=Cf(Fa,n),[v,w]=m.useState(null),S=Ve(t,he=>w(he)),[N,T]=m.useState(null),k=yf(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(T0),altBoundary:$},{refs:M,floatingStyles:G,placement:q,isPositioned:W,middlewareData:B}=c0({strategy:"fixed",placement:j,whileElementsMounted:(...he)=>Qy(...he,{animationFrame:p==="always"}),elements:{reference:g.anchor},middleware:[d0({mainAxis:o+A,alignmentAxis:i}),l&&f0({mainAxis:!0,crossAxis:!1,limiter:f==="partial"?h0():void 0,...V}),l&&p0({...V}),m0({...V,apply:({elements:he,rects:Qe,availableWidth:et,availableHeight:Pe})=>{const{width:He,height:ut}=Qe.reference,nt=he.floating.style;nt.setProperty("--radix-popper-available-width",`${et}px`),nt.setProperty("--radix-popper-available-height",`${Pe}px`),nt.setProperty("--radix-popper-anchor-width",`${He}px`),nt.setProperty("--radix-popper-anchor-height",`${ut}px`)}}),N&&x0({element:N,padding:a}),k0({arrowWidth:E,arrowHeight:A}),h&&g0({strategy:"referenceHidden",...V})]}),[F,le]=_f(q),D=Tt(b);Ct(()=>{W&&(D==null||D())},[W,D]);const Q=(K=B.arrow)==null?void 0:K.x,de=(O=B.arrow)==null?void 0:O.y,be=((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:W?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(y0,{scope:n,placedSide:F,onArrowChange:T,arrowX:Q,arrowY:de,shouldHideArrow:be,children:c.jsx(_e.div,{"data-side":F,"data-align":le,...x,ref:S,style:{...x.style,animation:W?void 0:"none"}})})})});Ef.displayName=Fa;var Nf="PopperArrow",C0={top:"bottom",right:"left",bottom:"top",left:"right"},Af=m.forwardRef(function(t,n){const{__scopePopper:r,...o}=t,s=S0(Nf,r),i=C0[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(b0,{...o,ref:n,style:{...o.style,display:"block"}})})});Af.displayName=Nf;function T0(e){return e!==null}var k0=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]=_f(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 _f(e){const[t,n="center"]=e.split("-");return[t,n]}var jf=Tf,Rf=If,Pf=Ef,Of=Af,Ba="rovingFocusGroup.onEntryFocus",I0={bubbles:!1,cancelable:!0},ho="RovingFocusGroup",[za,Mf,E0]=Ia(ho),[N0,Df]=gn(ho,[E0]),[A0,_0]=N0(ho),Lf=m.forwardRef((e,t)=>c.jsx(za.Provider,{scope:e.__scopeRovingFocusGroup,children:c.jsx(za.Slot,{scope:e.__scopeRovingFocusGroup,children:c.jsx(j0,{...e,ref:t})})}));Lf.displayName=ho;var j0=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),b=ks(s),[x,g]=sr({prop:i,defaultProp:a??null,onChange:l,caller:ho}),[v,w]=m.useState(!1),S=Tt(u),N=Mf(n),T=m.useRef(!1),[k,E]=m.useState(0);return m.useEffect(()=>{const A=h.current;if(A)return A.addEventListener(Ba,S),()=>A.removeEventListener(Ba,S)},[S]),c.jsx(A0,{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:ce(e.onMouseDown,()=>{T.current=!0}),onFocus:ce(e.onFocus,A=>{const j=!T.current;if(A.target===A.currentTarget&&j&&!v){const P=new CustomEvent(Ba,I0);if(A.currentTarget.dispatchEvent(P),!P.defaultPrevented){const L=N().filter(q=>q.focusable),$=L.find(q=>q.active),V=L.find(q=>q.id===x),G=[$,V,...L].filter(Boolean).map(q=>q.ref.current);Bf(G,d)}}T.current=!1}),onBlur:ce(e.onBlur,()=>w(!1))})})}),$f="RovingFocusGroupItem",Ff=m.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:o=!1,tabStopId:s,children:i,...a}=e,l=xn(),u=s||l,d=_0($f,n),f=d.currentTabStopId===u,h=Mf(n),{onFocusableItemAdd:p,onFocusableItemRemove:b,currentTabStopId:x}=d;return m.useEffect(()=>{if(r)return p(),()=>b()},[r,p,b]),c.jsx(za.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:ce(e.onMouseDown,g=>{r?d.onItemFocus(u):g.preventDefault()}),onFocus:ce(e.onFocus,()=>d.onItemFocus(u)),onKeyDown:ce(e.onKeyDown,g=>{if(g.key==="Tab"&&g.shiftKey){d.onItemShiftTab();return}if(g.target!==g.currentTarget)return;const v=O0(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?M0(S,N+1):S.slice(N+1)}setTimeout(()=>Bf(S))}}),children:typeof i=="function"?i({isCurrentTabStop:f,hasTabStop:x!=null}):i})})});Ff.displayName=$f;var R0={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function P0(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function O0(e,t,n){const r=P0(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return R0[r]}function Bf(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function M0(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var D0=Lf,L0=Ff,Ha=["Enter"," "],$0=["ArrowDown","PageUp","Home"],zf=["ArrowUp","PageDown","End"],F0=[...$0,...zf],B0={ltr:[...Ha,"ArrowRight"],rtl:[...Ha,"ArrowLeft"]},z0={ltr:["ArrowLeft"],rtl:["ArrowRight"]},po="Menu",[mo,H0,U0]=Ia(po),[dr,Hf]=gn(po,[U0,Ds,Df]),Ls=Ds(),Uf=Df(),[W0,fr]=dr(po),[V0,go]=dr(po),Wf=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=Ls(t),[l,u]=m.useState(null),d=m.useRef(!1),f=Tt(s),h=ks(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(jf,{...a,children:c.jsx(W0,{scope:t,open:n,onOpenChange:f,content:l,onContentChange:u,children:c.jsx(V0,{scope:t,onClose:m.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:d,dir:h,modal:i,children:r})})})};Wf.displayName=po;var q0="MenuAnchor",Ua=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=Ls(n);return c.jsx(Rf,{...o,...r,ref:t})});Ua.displayName=q0;var Wa="MenuPortal",[K0,Vf]=dr(Wa,{forceMount:void 0}),qf=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:o}=e,s=fr(Wa,t);return c.jsx(K0,{scope:t,forceMount:n,children:c.jsx(Ht,{present:n||s.open,children:c.jsx(cs,{asChild:!0,container:o,children:r})})})};qf.displayName=Wa;var Yt="MenuContent",[G0,Va]=dr(Yt),Kf=m.forwardRef((e,t)=>{const n=Vf(Yt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=fr(Yt,e.__scopeMenu),i=go(Yt,e.__scopeMenu);return c.jsx(mo.Provider,{scope:e.__scopeMenu,children:c.jsx(Ht,{present:r||s.open,children:c.jsx(mo.Slot,{scope:e.__scopeMenu,children:i.modal?c.jsx(Y0,{...o,ref:t}):c.jsx(X0,{...o,ref:t})})})})}),Y0=m.forwardRef((e,t)=>{const n=fr(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(qa,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:ce(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),X0=m.forwardRef((e,t)=>{const n=fr(Yt,e.__scopeMenu);return c.jsx(qa,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),J0=Jn.createSlot("MenuContent.ScrollLock"),qa=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(Yt,n),v=go(Yt,n),w=Ls(n),S=Uf(n),N=H0(n),[T,k]=m.useState(null),E=m.useRef(null),A=Ve(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?ms:m.Fragment,q=b?{as:J0,allowPinchZoom:!0}:void 0,W=F=>{var K,O;const le=P.current+F,D=N().filter(X=>!X.disabled),Q=document.activeElement,de=(K=D.find(X=>X.ref.current===Q))==null?void 0:K.textValue,be=D.map(X=>X.textValue),ye=cS(be,le,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))})(le),Se&&setTimeout(()=>Se.focus())};m.useEffect(()=>()=>window.clearTimeout(j.current),[]),pa();const B=m.useCallback(F=>{var D,Q;return V.current===((D=$.current)==null?void 0:D.side)&&dS(F,(Q=$.current)==null?void 0:Q.area)},[]);return c.jsx(G0,{scope:n,searchRef:P,onItemEnter:m.useCallback(F=>{B(F)&&F.preventDefault()},[B]),onItemLeave:m.useCallback(F=>{var le;B(F)||((le=E.current)==null||le.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,{...q,children:c.jsx(ls,{asChild:!0,trapped:o,onMountAutoFocus:ce(s,F=>{var le;F.preventDefault(),(le=E.current)==null||le.focus({preventScroll:!0})}),onUnmountAutoFocus:i,children:c.jsx(as,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:u,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:h,onDismiss:p,children:c.jsx(D0,{asChild:!0,...S,dir:v.dir,orientation:"vertical",loop:r,currentTabStopId:T,onCurrentTabStopIdChange:k,onEntryFocus:ce(l,F=>{v.isUsingKeyboardRef.current||F.preventDefault()}),preventScrollOnEntryFocus:!0,children:c.jsx(Pf,{role:"menu","aria-orientation":"vertical","data-state":uh(g.open),"data-radix-menu-content":"",dir:v.dir,...w,...x,ref:A,style:{outline:"none",...x.style},onKeyDown:ce(x.onKeyDown,F=>{const D=F.target.closest("[data-radix-menu-content]")===F.currentTarget,Q=F.ctrlKey||F.altKey||F.metaKey,de=F.key.length===1;D&&(F.key==="Tab"&&F.preventDefault(),!Q&&de&&W(F.key));const be=E.current;if(F.target!==be||!F0.includes(F.key))return;F.preventDefault();const Se=N().filter(K=>!K.disabled).map(K=>K.ref.current);zf.includes(F.key)&&Se.reverse(),aS(Se)}),onBlur:ce(e.onBlur,F=>{F.currentTarget.contains(F.target)||(window.clearTimeout(j.current),P.current="")}),onPointerMove:ce(e.onPointerMove,vo(F=>{const le=F.target,D=M.current!==F.clientX;if(F.currentTarget.contains(le)&&D){const Q=F.clientX>M.current?"right":"left";V.current=Q,M.current=F.clientX}}))})})})})})})});Kf.displayName=Yt;var Z0="MenuGroup",Ka=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return c.jsx(_e.div,{role:"group",...r,ref:t})});Ka.displayName=Z0;var Q0="MenuLabel",Gf=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return c.jsx(_e.div,{...r,ref:t})});Gf.displayName=Q0;var $s="MenuItem",Yf="menu.itemSelect",Fs=m.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...o}=e,s=m.useRef(null),i=go($s,e.__scopeMenu),a=Va($s,e.__scopeMenu),l=Ve(t,s),u=m.useRef(!1),d=()=>{const f=s.current;if(!n&&f){const h=new CustomEvent(Yf,{bubbles:!0,cancelable:!0});f.addEventListener(Yf,p=>r==null?void 0:r(p),{once:!0}),Au(f,h),h.defaultPrevented?u.current=!1:i.onClose()}};return c.jsx(Xf,{...o,ref:l,disabled:n,onClick:ce(e.onClick,d),onPointerDown:f=>{var h;(h=e.onPointerDown)==null||h.call(e,f),u.current=!0},onPointerUp:ce(e.onPointerUp,f=>{var h;u.current||(h=f.currentTarget)==null||h.click()}),onKeyDown:ce(e.onKeyDown,f=>{const h=a.searchRef.current!=="";n||h&&f.key===" "||Ha.includes(f.key)&&(f.currentTarget.click(),f.preventDefault())})})});Fs.displayName=$s;var Xf=m.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:o,...s}=e,i=Va($s,n),a=Uf(n),l=m.useRef(null),u=Ve(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(mo.ItemSlot,{scope:n,disabled:r,textValue:o??h,children:c.jsx(L0,{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:ce(e.onPointerMove,vo(b=>{r?i.onItemLeave(b):(i.onItemEnter(b),b.defaultPrevented||b.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:ce(e.onPointerLeave,vo(b=>i.onItemLeave(b))),onFocus:ce(e.onFocus,()=>f(!0)),onBlur:ce(e.onBlur,()=>f(!1))})})})}),eS="MenuCheckboxItem",Jf=m.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...o}=e;return c.jsx(nh,{scope:e.__scopeMenu,checked:n,children:c.jsx(Fs,{role:"menuitemcheckbox","aria-checked":Bs(n)?"mixed":n,...o,ref:t,"data-state":Ya(n),onSelect:ce(o.onSelect,()=>r==null?void 0:r(Bs(n)?!0:!n),{checkForDefaultPrevented:!1})})})});Jf.displayName=eS;var Zf="MenuRadioGroup",[tS,nS]=dr(Zf,{value:void 0,onValueChange:()=>{}}),Qf=m.forwardRef((e,t)=>{const{value:n,onValueChange:r,...o}=e,s=Tt(r);return c.jsx(tS,{scope:e.__scopeMenu,value:n,onValueChange:s,children:c.jsx(Ka,{...o,ref:t})})});Qf.displayName=Zf;var eh="MenuRadioItem",th=m.forwardRef((e,t)=>{const{value:n,...r}=e,o=nS(eh,e.__scopeMenu),s=n===o.value;return c.jsx(nh,{scope:e.__scopeMenu,checked:s,children:c.jsx(Fs,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":Ya(s),onSelect:ce(r.onSelect,()=>{var i;return(i=o.onValueChange)==null?void 0:i.call(o,n)},{checkForDefaultPrevented:!1})})})});th.displayName=eh;var Ga="MenuItemIndicator",[nh,rS]=dr(Ga,{checked:!1}),rh=m.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...o}=e,s=rS(Ga,n);return c.jsx(Ht,{present:r||Bs(s.checked)||s.checked===!0,children:c.jsx(_e.span,{...o,ref:t,"data-state":Ya(s.checked)})})});rh.displayName=Ga;var oS="MenuSeparator",oh=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return c.jsx(_e.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});oh.displayName=oS;var sS="MenuArrow",sh=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=Ls(n);return c.jsx(Of,{...o,...r,ref:t})});sh.displayName=sS;var iS="MenuSub",[HT,ih]=dr(iS),xo="MenuSubTrigger",ah=m.forwardRef((e,t)=>{const n=fr(xo,e.__scopeMenu),r=go(xo,e.__scopeMenu),o=ih(xo,e.__scopeMenu),s=Va(xo,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(Ua,{asChild:!0,...u,children:c.jsx(Xf,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":o.contentId,"data-state":uh(n.open),...e,ref:ea(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:ce(e.onPointerMove,vo(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:ce(e.onPointerLeave,vo(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:ce(e.onKeyDown,f=>{var p;const h=s.searchRef.current!=="";e.disabled||h&&f.key===" "||B0[r.dir].includes(f.key)&&(n.onOpenChange(!0),(p=n.content)==null||p.focus(),f.preventDefault())})})})});ah.displayName=xo;var lh="MenuSubContent",ch=m.forwardRef((e,t)=>{const n=Vf(Yt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=fr(Yt,e.__scopeMenu),i=go(Yt,e.__scopeMenu),a=ih(lh,e.__scopeMenu),l=m.useRef(null),u=Ve(t,l);return c.jsx(mo.Provider,{scope:e.__scopeMenu,children:c.jsx(Ht,{present:r||s.open,children:c.jsx(mo.Slot,{scope:e.__scopeMenu,children:c.jsx(qa,{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:ce(e.onFocusOutside,d=>{d.target!==a.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:ce(e.onEscapeKeyDown,d=>{i.onClose(),d.preventDefault()}),onKeyDown:ce(e.onKeyDown,d=>{var p;const f=d.currentTarget.contains(d.target),h=z0[i.dir].includes(d.key);f&&h&&(s.onOpenChange(!1),(p=a.trigger)==null||p.focus(),d.preventDefault())})})})})})});ch.displayName=lh;function uh(e){return e?"open":"closed"}function Bs(e){return e==="indeterminate"}function Ya(e){return Bs(e)?"indeterminate":e?"checked":"unchecked"}function aS(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function lS(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function cS(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=lS(e,Math.max(s,0));o.length===1&&(i=i.filter(u=>u!==n));const l=i.find(u=>u.toLowerCase().startsWith(o.toLowerCase()));return l!==n?l:void 0}function uS(e,t){const{x:n,y:r}=e;let o=!1;for(let s=0,i=t.length-1;s<t.length;i=s++){const a=t[s],l=t[i],u=a.x,d=a.y,f=l.x,h=l.y;d>r!=h>r&&n<(f-u)*(r-d)/(h-d)+u&&(o=!o)}return o}function dS(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return uS(n,t)}function vo(e){return t=>t.pointerType==="mouse"?e(t):void 0}var fS=Wf,hS=Ua,pS=qf,mS=Kf,gS=Ka,xS=Gf,vS=Fs,bS=Jf,wS=Qf,yS=th,SS=rh,CS=oh,TS=sh,kS=ah,IS=ch,zs="DropdownMenu",[ES,UT]=gn(zs,[Hf]),Rt=Hf(),[NS,dh]=ES(zs),fh=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:o,defaultOpen:s,onOpenChange:i,modal:a=!0}=e,l=Rt(t),u=m.useRef(null),[d,f]=sr({prop:o,defaultProp:s??!1,onChange:i,caller:zs});return c.jsx(NS,{scope:t,triggerId:xn(),triggerRef:u,contentId:xn(),open:d,onOpenChange:f,onOpenToggle:m.useCallback(()=>f(h=>!h),[f]),modal:a,children:c.jsx(fS,{...l,open:d,onOpenChange:f,dir:r,modal:a,children:n})})};fh.displayName=zs;var hh="DropdownMenuTrigger",ph=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...o}=e,s=dh(hh,n),i=Rt(n);return c.jsx(hS,{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:ea(t,s.triggerRef),onPointerDown:ce(e.onPointerDown,a=>{!r&&a.button===0&&a.ctrlKey===!1&&(s.onOpenToggle(),s.open||a.preventDefault())}),onKeyDown:ce(e.onKeyDown,a=>{r||(["Enter"," "].includes(a.key)&&s.onOpenToggle(),a.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(a.key)&&a.preventDefault())})})})});ph.displayName=hh;var AS="DropdownMenuPortal",mh=e=>{const{__scopeDropdownMenu:t,...n}=e,r=Rt(t);return c.jsx(pS,{...r,...n})};mh.displayName=AS;var gh="DropdownMenuContent",xh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=dh(gh,n),s=Rt(n),i=m.useRef(!1);return c.jsx(mS,{id:o.contentId,"aria-labelledby":o.triggerId,...s,...r,ref:t,onCloseAutoFocus:ce(e.onCloseAutoFocus,a=>{var l;i.current||(l=o.triggerRef.current)==null||l.focus(),i.current=!1,a.preventDefault()}),onInteractOutside:ce(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)"}})});xh.displayName=gh;var _S="DropdownMenuGroup",jS=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Rt(n);return c.jsx(gS,{...o,...r,ref:t})});jS.displayName=_S;var RS="DropdownMenuLabel",vh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Rt(n);return c.jsx(xS,{...o,...r,ref:t})});vh.displayName=RS;var PS="DropdownMenuItem",bh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Rt(n);return c.jsx(vS,{...o,...r,ref:t})});bh.displayName=PS;var OS="DropdownMenuCheckboxItem",wh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Rt(n);return c.jsx(bS,{...o,...r,ref:t})});wh.displayName=OS;var MS="DropdownMenuRadioGroup",DS=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Rt(n);return c.jsx(wS,{...o,...r,ref:t})});DS.displayName=MS;var LS="DropdownMenuRadioItem",yh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Rt(n);return c.jsx(yS,{...o,...r,ref:t})});yh.displayName=LS;var $S="DropdownMenuItemIndicator",Sh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Rt(n);return c.jsx(SS,{...o,...r,ref:t})});Sh.displayName=$S;var FS="DropdownMenuSeparator",Ch=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Rt(n);return c.jsx(CS,{...o,...r,ref:t})});Ch.displayName=FS;var BS="DropdownMenuArrow",zS=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Rt(n);return c.jsx(TS,{...o,...r,ref:t})});zS.displayName=BS;var HS="DropdownMenuSubTrigger",Th=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Rt(n);return c.jsx(kS,{...o,...r,ref:t})});Th.displayName=HS;var US="DropdownMenuSubContent",kh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Rt(n);return c.jsx(IS,{...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)"}})});kh.displayName=US;var WS=fh,VS=ph,qS=mh,Ih=xh,Eh=vh,Nh=bh,Ah=wh,_h=yh,jh=Sh,Rh=Ch,Ph=Th,Oh=kh;const KS=WS,GS=VS,YS=m.forwardRef(({className:e,inset:t,children:n,...r},o)=>c.jsxs(Ph,{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"})]}));YS.displayName=Ph.displayName;const XS=m.forwardRef(({className:e,...t},n)=>c.jsx(Oh,{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}));XS.displayName=Oh.displayName;const Mh=m.forwardRef(({className:e,sideOffset:t=4,...n},r)=>c.jsx(qS,{children:c.jsx(Ih,{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})}));Mh.displayName=Ih.displayName;const Xa=m.forwardRef(({className:e,inset:t,...n},r)=>c.jsx(Nh,{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}));Xa.displayName=Nh.displayName;const JS=m.forwardRef(({className:e,children:t,checked:n,...r},o)=>c.jsxs(Ah,{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(jh,{children:c.jsx(oe.Check,{className:"h-4 w-4"})})}),t]}));JS.displayName=Ah.displayName;const ZS=m.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(_h,{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(jh,{children:c.jsx(oe.Circle,{className:"h-2 w-2 fill-current"})})}),t]}));ZS.displayName=_h.displayName;const QS=m.forwardRef(({className:e,inset:t,...n},r)=>c.jsx(Eh,{ref:r,className:Z("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));QS.displayName=Eh.displayName;const eC=m.forwardRef(({className:e,...t},n)=>c.jsx(Rh,{ref:n,className:Z("-mx-1 my-1 h-px bg-muted",e),...t}));eC.displayName=Rh.displayName;function Hs({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}=vi(),{currentThreadId:x}=Do(),{threadId:g,messages:v,hasMore:w,isHistoryLoading:S,isLoading:N,loadOlder:T,listCheckpoints:k,navigateToCheckpoint:E,returnToLatest:A,checkpoint:j,respondToInterrupt:P,metadata:L}=Lo(),{isStreaming:$,error:V,submit:M,stop:G}=Nc(),q=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,[le,D]=y.useState(null),[Q,de]=y.useState(""),[be,ye]=y.useState(null),[Se,K]=y.useState([]),[O,X]=y.useState(0),[ee,fe]=y.useState(0),[ne,he]=y.useState(!1),[Qe,et]=y.useState(null),[Pe,He]=y.useState(null),[ut,nt]=y.useState(!1),[Be,xt]=y.useState(null),[J,re]=y.useState([]),[me,Ce]=y.useState(null),[ge,Oe]=y.useState(null),[at,Me]=y.useState(!1),tt=y.useRef(null),bt=y.useRef(null),Zt=y.useRef(null),Kn=y.useCallback(()=>{tt.current&&(tt.current.value=""),bt.current&&(bt.current.value=""),X(se=>se+1),fe(se=>se+1)},[]),Dr=y.useRef(!1);y.useEffect(()=>{Dr.current&&!$&&(K([]),Kn()),Dr.current=$},[$,Kn]);const[gr,Pt]=y.useState("desktop");y.useEffect(()=>{const se=()=>{const we=window.innerWidth;Pt(we<640?"phone":we<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 we={threadId:q,checkpointId:W??null,checkpointNs:B??null},Ue=Zt.current;if(!(Ue&&Ue.threadId===we.threadId&&Ue.checkpointId===we.checkpointId&&Ue.checkpointNs===we.checkpointNs))return k(q).then(it=>{var Ie;if(se)return;const Ot=((it==null?void 0:it.checkpoints)??[]).slice().sort(($e,Ge)=>new Date(Ge.createdAt).getTime()-new Date($e.createdAt).getTime());re(Ot);const I=me,H=I&&Ot.some($e=>$e.checkpointId===I)?I:((Ie=Ot[0])==null?void 0:Ie.checkpointId)??null;let te=null;if(H){const $e=Ot.find(Ge=>Ge.checkpointId===H);te=($e==null?void 0:$e.checkpointNs)??null}Ce(H),Oe(te),Zt.current=we}).catch(it=>{console.error("ChatInterface - listCheckpoints error:",it),se||(re([]),Zt.current=null)}),()=>{se=!0}},[q,W,B,me,k]),y.useEffect(()=>{W&&(Ce(W),Oe(B??null))},[W,B]);const wo=y.useCallback(async()=>{if(!(!w||S))try{await T()}catch(se){console.warn("loadOlder failed",se)}},[w,S,T]);y.useEffect(()=>{(async()=>{if(!b.baseUrl){xt(null);return}try{const we=await b.getAgent("default");xt(we.uiDefaultMessage||null)}catch(we){console.warn("Failed to fetch default message:",we),xt(null)}})()},[b]),y.useEffect(()=>{V&&!ut&&(p==null||p(V))},[V,ut,p]);const jn=se=>{if(se.length>Ts)return`Message too long (${se.length}/${Ts} characters)`;try{return iy(se),null}catch(we){return(we==null?void 0:we.message)||"Invalid message"}},St=async se=>{const we=se.trim();if(!(!we&&Se.length===0)){if(we){const Ue=jn(we);if(Ue){ye(Ue);return}}try{await M({text:we||"",attachments:Se,payload:le?{edit:!0,originalMessageId:le}:void 0},{checkpointId:me??W??void 0,checkpointNs:ge??B??void 0}),f==null||f(we),ye(null),K([]),Kn(),D(null),de("")}catch(Ue){const it=(Ue==null?void 0:Ue.message)||"Failed to send message";ye(it),p==null||p(it)}}},At=y.useCallback((se,we)=>{u&&(D(se),de(we),ye(null))},[u]),Vt=y.useCallback(()=>{D(null),de(""),ye(null)},[]),Gn=y.useCallback((se,we)=>{At(se,we)},[At]),un=y.useCallback(se=>{const we=Ue=>{const it=Ue.content||[],Ot=it.filter(I=>I.type==="text").map(I=>I.text).join("");if(Ot)return Ot;try{return JSON.stringify(it,null,2)}catch{return String(it)}};for(let Ue=se-1;Ue>=0;Ue--)if(v[Ue].role==="user"){const it=we(v[Ue]);it&&M({text:it},{checkpointId:me??W??void 0,checkpointNs:ge??B??void 0});break}},[v,M,me,ge,W,B]),xr=se=>{const we=Array.from(se.target.files||[]);K(Ue=>[...Ue,...we]),se.target.value=""},dn=se=>{K(we=>{const Ue=we.filter((it,Ot)=>se!==Ot);return Ue.length===0&&Kn(),Ue})},Tn=async se=>{const we=(se.target.files||[])[0];if(we){et(null),He(null),he(!0);try{await M({attachments:[we]},{checkpointId:me??W??void 0,checkpointNs:ge??B??void 0});const Ue=`Uploaded ${we.name} - processing through chat stream`;He(Ue)}catch(Ue){const it=Ue instanceof Error?Ue.message:"Failed to upload Excel file";console.error("Excel upload failed",Ue),et(it),p==null||p(it)}finally{he(!1),se.target.value="",Kn()}}},Yn=se=>{if(!se)return"Unknown";const we=Date.parse(se);return Number.isNaN(we)?se:new Date(we).toLocaleString()},Lr=async se=>{if(x){Me(!0);try{if(!se){await A(),Ce(null),Oe(null);return}const we=J.find(it=>it.checkpointId===se),Ue=(we==null?void 0:we.checkpointNs)??null;await E(se,Ue),Ce(se),Oe(Ue)}finally{Me(!1)}}},$r=`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||""}`,Rn=`flex-shrink-0 w-full border-t p-4 bg-transparent ${d.inputArea||""}`;return c.jsxs("div",{className:$r,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(Xe,{variant:"ghost",size:"sm",onClick:()=>nt(!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:me??"",onChange:se=>{const we=se.target.value||null;Lr(we)},children:[c.jsx("option",{value:"",children:"Latest"}),J.map(se=>c.jsxs("option",{value:se.checkpointId,children:[Yn(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(ka,{className:"h-full",style:{height:"100%"},messages:v,isStreaming:$,streamingAssistantId:F,streamingDebounceMs:typeof s=="number"?s:o,followNewMessages:i,layoutSize:gr,enableMessageEditing:u,editingMessageId:le,onStartReached:()=>{wo()},onEdit:Gn,onRegenerate:un,onCancelEdit:Vt,emptyMessage:Be??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(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:Rn,children:[le&&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(Xe,{variant:"ghost",size:"sm",onClick:Vt,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:tt,type:"file",multiple:!0,onChange:se=>xr(se),className:"hidden"},O),Se.length>0&&c.jsx("div",{className:"flex flex-wrap gap-2",children:Se.map((se,we)=>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(Xe,{variant:"ghost",size:"sm",onClick:()=>dn(we),className:"h-4 w-4 p-0 text-gray-500 dark:text-gray-400 hover:text-red-500 dark:hover:text-red-400","aria-label":`Remove ${se.name}`,children:c.jsx(oe.X,{size:12})})]},we))})]}),l&&c.jsxs(c.Fragment,{children:[c.jsx("input",{ref:bt,type:"file",accept:".xls,.xlsx,.xlsm",onChange:Tn,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}),Qe&&!ne&&c.jsx("div",{className:"text-sm rounded border border-red-200 bg-red-50 px-3 py-2 text-red-600",children:Qe})]})]}),be&&c.jsx("div",{className:"mb-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2",children:be}),c.jsxs("div",{className:"flex items-end gap-2",children:[(a||l)&&c.jsxs(KS,{children:[c.jsx(GS,{asChild:!0,children:c.jsx(Xe,{type:"button",size:"icon",variant:"outline",disabled:$,title:"More input actions",className:d.moreButton||"",children:c.jsx(oe.Plus,{size:16})})}),c.jsxs(Mh,{align:"start",sideOffset:6,className:"w-52",children:[a&&c.jsxs(Xa,{onClick:()=>{var se;return(se=tt.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(Xa,{onClick:()=>{var se;ne||(se=bt.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(bx,{initialValue:Q,editingMessageId:le,placeholder:le?"Edit your message...":t,isStreaming:$,disabled:!1,maxLength:Ts,onSend:St,onCancelEdit:Vt,onStop:G,allowEmptySend:Se.length>0,textareaClassName:`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${le?"border-blue-400 bg-blue-50 text-blue-900 dark:border-blue-500 dark:bg-blue-950/60 dark:text-blue-50":""} ${be?"border-red-400":""} ${d.textarea||""}`})})]})]})]})}const Us=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}));Us.displayName="Input";function Ja(e,[t,n]){return Math.min(n,Math.max(t,e))}function tC(e,t){return m.useReducer((n,r)=>t[n][r]??n,e)}var Za="ScrollArea",[Dh,WT]=gn(Za),[nC,Xt]=Dh(Za),Lh=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=Ve(t,L=>l(L)),P=ks(o);return c.jsx(nC,{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}})})});Lh.displayName=Za;var $h="ScrollAreaViewport",Fh=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,i=Xt($h,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})})]})});Fh.displayName=$h;var Cn="ScrollAreaScrollbar",Qa=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Xt(Cn,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(rC,{...r,ref:t,forceMount:n}):o.type==="scroll"?c.jsx(oC,{...r,ref:t,forceMount:n}):o.type==="auto"?c.jsx(Bh,{...r,ref:t,forceMount:n}):o.type==="always"?c.jsx(el,{...r,ref:t}):null});Qa.displayName=Cn;var rC=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Xt(Cn,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(Ht,{present:n||s,children:c.jsx(Bh,{"data-state":s?"visible":"hidden",...r,ref:t})})}),oC=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Xt(Cn,e.__scopeScrollArea),s=e.orientation==="horizontal",i=Ks(()=>l("SCROLL_END"),100),[a,l]=tC("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(Ht,{present:n||a!=="hidden",children:c.jsx(el,{"data-state":a==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:ce(e.onPointerEnter,()=>l("POINTER_ENTER")),onPointerLeave:ce(e.onPointerLeave,()=>l("POINTER_LEAVE"))})})}),Bh=m.forwardRef((e,t)=>{const n=Xt(Cn,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,i]=m.useState(!1),a=e.orientation==="horizontal",l=Ks(()=>{if(n.viewport){const u=n.viewport.offsetWidth<n.viewport.scrollWidth,d=n.viewport.offsetHeight<n.viewport.scrollHeight;i(a?u:d)}},10);return Pr(n.viewport,l),Pr(n.content,l),c.jsx(Ht,{present:r||s,children:c.jsx(el,{"data-state":s?"visible":"hidden",...o,ref:t})})}),el=m.forwardRef((e,t)=>{const{orientation:n="vertical",...r}=e,o=Xt(Cn,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=Vh(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 uC(h,i.current,a,p)}return n==="horizontal"?c.jsx(sC,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollLeft,p=qh(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(iC,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollTop,p=qh(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}),sC=m.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=Xt(Cn,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(Hh,{"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":qs(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),Gh(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:Vs(i.paddingLeft),paddingEnd:Vs(i.paddingRight)}})}})}),iC=m.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=Xt(Cn,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(Hh,{"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":qs(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),Gh(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:Vs(i.paddingTop),paddingEnd:Vs(i.paddingBottom)}})}})}),[aC,zh]=Dh(Cn),Hh=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(Cn,n),[b,x]=m.useState(null),g=Ve(t,j=>x(j)),v=m.useRef(null),w=m.useRef(""),S=p.viewport,N=r.content-r.viewport,T=Tt(d),k=Tt(l),E=Ks(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]),Pr(b,E),Pr(p.content,E),c.jsx(aC,{scope:n,scrollbar:b,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:ce(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:ce(e.onPointerMove,A),onPointerUp:ce(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})})})}),Ws="ScrollAreaThumb",Uh=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=zh(Ws,e.__scopeScrollArea);return c.jsx(Ht,{present:n||o.hasThumb,children:c.jsx(lC,{ref:t,...r})})}),lC=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=Xt(Ws,n),i=zh(Ws,n),{onThumbPositionChange:a}=i,l=Ve(t,f=>i.onThumbChange(f)),u=m.useRef(void 0),d=Ks(()=>{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=dC(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:ce(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:ce(e.onPointerUp,i.onThumbPointerUp)})});Uh.displayName=Ws;var tl="ScrollAreaCorner",Wh=m.forwardRef((e,t)=>{const n=Xt(tl,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?c.jsx(cC,{...e,ref:t}):null});Wh.displayName=tl;var cC=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=Xt(tl,n),[s,i]=m.useState(0),[a,l]=m.useState(0),u=!!(s&&a);return Pr(o.scrollbarX,()=>{var f;const d=((f=o.scrollbarX)==null?void 0:f.offsetHeight)||0;o.onCornerHeightChange(d),l(d)}),Pr(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 Vs(e){return e?parseInt(e,10):0}function Vh(e,t){const n=e/t;return isNaN(n)?0:n}function qs(e){const t=Vh(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function uC(e,t,n,r="ltr"){const o=qs(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 Kh([l,u],f)(e)}function qh(e,t,n="ltr"){const r=qs(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=Ja(e,l);return Kh([0,i],[0,a])(u)}function Kh(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 Gh(e,t){return e>0&&e<t}var dC=(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 Ks(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 Pr(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 Yh=Lh,fC=Fh,hC=Wh;const Xh=m.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(Yh,{ref:r,className:Z("relative overflow-hidden",e),...n,children:[c.jsx(fC,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),c.jsx(Jh,{}),c.jsx(hC,{})]}));Xh.displayName=Yh.displayName;const Jh=m.forwardRef(({className:e,orientation:t="vertical",...n},r)=>c.jsx(Qa,{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(Uh,{className:"relative flex-1 rounded-full bg-border"})}));Jh.displayName=Qa.displayName;function nl({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}=Do(),{loadThread:x}=Lo(),{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(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(),E(D.threadId),j(D.title||`Thread ${D.threadId.slice(0,8)}`)},q=async D=>{if(A.trim())try{await w(D,A.trim()),E(null),j("")}catch(Q){console.error("Failed to update title:",Q)}},W=()=>{E(null),j("")},B=(D,Q)=>{D.key==="Enter"?q(Q):D.key==="Escape"&&W()},F=D=>{if(!D)return"";try{const Q=new Date(D),be=new Date().getTime()-Q.getTime(),ye=Math.floor(be/(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""}},le=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(Xe,{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(Xh,{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:()=>$(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(Us,{value:A,onChange:Q=>j(Q.target.value),onKeyDown:Q=>B(Q,D.threadId),className:"h-6 text-sm",autoFocus:!0}),c.jsx(Xe,{variant:"ghost",size:"sm",onClick:()=>q(D.threadId),className:"h-6 w-6 p-0",children:c.jsx(oe.Check,{size:12})}),c.jsx(Xe,{variant:"ghost",size:"sm",onClick:W,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:le(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: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(Xe,{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(Xe,{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 Or(e){if(!(typeof globalThis>"u"))return globalThis[e]}function pC(e){if(typeof e!="string")return;const t=e.trim();if(t)return En(t)}function Zh(){const e=[Or("__API_BASE_URL__"),Or("__CHAT_API_BASE_URL__"),Or("__CHAT_API_URL__")];for(const t of e){const n=pC(t);if(n)return n}}function Qh(){const e=[Or("__API_AUTH_TOKEN__"),Or("__CHAT_API_KEY__"),Or("__CHAT_AUTH_TOKEN__")];for(const t of e)if(typeof t=="string"&&t.trim())return t.trim()}function ep(...e){for(const t of e)if(typeof t=="string"&&t.trim())return En(t);return En()}function tp(){const e={},t=Zh(),n=Qh();return t&&(e.baseUrl=t),n&&(e.apiKey=n),e}function np(){const e=tp(),t=On.getAuthToken(),n=Zh();return{apiBaseUrl:ep(e.baseUrl,On.baseUrl,n),apiKey:t||e.apiKey||Qh()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,truncateToolMessages:!0,toolMessagePreviewLength:200,darkMode:!1,enableSound:!1,messageHistory:100}}const rp="chat-settings";function mC(){try{const e=localStorage.getItem(rp);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function gC(e){try{const t={...e,apiBaseUrl:En(e.apiBaseUrl)};localStorage.setItem(rp,JSON.stringify(t)),t.apiKey&&On.setAuthToken(t.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function xC(){const e=np(),t=mC(),n=On.getAuthToken(),r=typeof t.apiBaseUrl=="string"?t.apiBaseUrl:void 0;return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:ep(On.baseUrl,r,e.apiBaseUrl)}}function vC(e){On.updateConfig({baseUrl:e.apiBaseUrl,authToken:e.apiKey??void 0}),gC(e)}var bC="Label",op=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())}}));op.displayName=bC;var sp=op;const wC=yo.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(sp,{ref:n,className:Z(wC(),e),...t}));Jt.displayName=sp.displayName;function ip(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 Gs="Switch",[yC,VT]=gn(Gs),[SC,CC]=yC(Gs),ap=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=Ve(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:Gs});return c.jsxs(SC,{scope:n,checked:v,disabled:a,children:[c.jsx(_e.button,{type:"button",role:"switch","aria-checked":v,"aria-required":i,"data-state":dp(v),"data-disabled":a?"":void 0,disabled:a,value:l,...f,ref:b,onClick:ce(e.onClick,S=>{w(N=>!N),g&&(x.current=S.isPropagationStopped(),x.current||S.stopPropagation())})}),g&&c.jsx(up,{control:h,bubbles:!x.current,name:r,value:l,checked:v,required:i,disabled:a,form:d,style:{transform:"translateX(-100%)"}})]})});ap.displayName=Gs;var lp="SwitchThumb",cp=m.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,o=CC(lp,n);return c.jsx(_e.span,{"data-state":dp(o.checked),"data-disabled":o.disabled?"":void 0,...r,ref:t})});cp.displayName=lp;var TC="SwitchBubbleInput",up=m.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...o},s)=>{const i=m.useRef(null),a=Ve(i,s),l=ip(n),u=yf(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}})});up.displayName=TC;function dp(e){return e?"checked":"unchecked"}var fp=ap,kC=cp;const Wn=m.forwardRef(({className:e,...t},n)=>c.jsx(fp,{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(kC,{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")})}));Wn.displayName=fp.displayName;var hp=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"}),IC="VisuallyHidden",EC=m.forwardRef((e,t)=>c.jsx(_e.span,{...e,ref:t,style:{...hp,...e.style}}));EC.displayName=IC;var NC=[" ","Enter","ArrowUp","ArrowDown"],AC=[" ","Enter"],hr="Select",[Ys,Xs,_C]=Ia(hr),[Mr,qT]=gn(hr,[_C,Ds]),Js=Ds(),[jC,Vn]=Mr(hr),[RC,PC]=Mr(hr),pp=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=Js(t),[g,v]=m.useState(null),[w,S]=m.useState(null),[N,T]=m.useState(!1),k=ks(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(q=>q.props.value).join(";");return c.jsx(jf,{...x,children:c.jsxs(jC,{required:p,scope:t,trigger:g,onTriggerChange:v,valueNode:w,onValueNodeChange:S,valueNodeHasChildren:N,onValueNodeHasChildrenChange:T,contentId:xn(),value:j,onValueChange:P,open:E,onOpenChange:A,dir:k,triggerPointerDownPosRef:L,disabled:h,children:[c.jsx(Ys.Provider,{scope:t,children:c.jsx(RC,{scope:e.__scopeSelect,onNativeOptionAdd:m.useCallback(q=>{M(W=>new Set(W).add(q))},[]),onNativeOptionRemove:m.useCallback(q=>{M(W=>{const B=new Set(W);return B.delete(q),B})},[]),children:n})}),$?c.jsxs($p,{"aria-hidden":!0,required:p,tabIndex:-1,name:d,autoComplete:f,value:j,onChange:q=>P(q.target.value),disabled:h,form:b,children:[j===void 0?c.jsx("option",{value:""}):null,Array.from(V)]},G):null]})})};pp.displayName=hr;var mp="SelectTrigger",gp=m.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...o}=e,s=Js(n),i=Vn(mp,n),a=i.disabled||r,l=Ve(t,i.onTriggerChange),u=Xs(n),d=m.useRef("touch"),[f,h,p]=Bp(x=>{const g=u().filter(S=>!S.disabled),v=g.find(S=>S.value===i.value),w=zp(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(Rf,{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":Fp(i.value)?"":void 0,...o,ref:l,onClick:ce(o.onClick,x=>{x.currentTarget.focus(),d.current!=="mouse"&&b(x)}),onPointerDown:ce(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:ce(o.onKeyDown,x=>{const g=f.current!=="";!(x.ctrlKey||x.altKey||x.metaKey)&&x.key.length===1&&h(x.key),!(g&&x.key===" ")&&NC.includes(x.key)&&(b(),x.preventDefault())})})})});gp.displayName=mp;var xp="SelectValue",vp=m.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,children:s,placeholder:i="",...a}=e,l=Vn(xp,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:Fp(l.value)?c.jsx(c.Fragment,{children:i}):s})});vp.displayName=xp;var OC="SelectIcon",bp=m.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...o}=e;return c.jsx(_e.span,{"aria-hidden":!0,...o,ref:t,children:r||"▼"})});bp.displayName=OC;var MC="SelectPortal",wp=e=>c.jsx(cs,{asChild:!0,...e});wp.displayName=MC;var pr="SelectContent",yp=m.forwardRef((e,t)=>{const n=Vn(pr,e.__scopeSelect),[r,o]=m.useState();if(Ct(()=>{o(new DocumentFragment)},[]),!n.open){const s=r;return s?So.createPortal(c.jsx(Sp,{scope:e.__scopeSelect,children:c.jsx(Ys.Slot,{scope:e.__scopeSelect,children:c.jsx("div",{children:e.children})})}),s):null}return c.jsx(Cp,{...e,ref:t})});yp.displayName=pr;var cn=10,[Sp,qn]=Mr(pr),DC="SelectContentImpl",LC=Jn.createSlot("SelectContent.RemoveScroll"),Cp=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=Vn(pr,n),[S,N]=m.useState(null),[T,k]=m.useState(null),E=Ve(t,K=>N(K)),[A,j]=m.useState(null),[P,L]=m.useState(null),$=Xs(n),[V,M]=m.useState(!1),G=m.useRef(!1);m.useEffect(()=>{if(S)return wa(S)},[S]),pa();const q=m.useCallback(K=>{const[O,...X]=$().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&&T&&(T.scrollTop=0),ne===ee&&T&&(T.scrollTop=T.scrollHeight),ne==null||ne.focus(),document.activeElement!==fe))return},[$,T]),W=m.useCallback(()=>q([A,S]),[q,A,S]);m.useEffect(()=>{V&&W()},[V,W]);const{onOpenChange:B,triggerPointerDownPosRef:F}=w;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=F.current)==null?void 0:fe.x)??0)),y:Math.abs(Math.round(ee.pageY)-(((ne=F.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),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 K=()=>B(!1);return window.addEventListener("blur",K),window.addEventListener("resize",K),()=>{window.removeEventListener("blur",K),window.removeEventListener("resize",K)}},[B]);const[le,D]=Bp(K=>{const O=$().filter(fe=>!fe.disabled),X=O.find(fe=>fe.ref.current===document.activeElement),ee=zp(O,K,X);ee&&setTimeout(()=>ee.ref.current.focus())}),Q=m.useCallback((K,O,X)=>{const ee=!G.current&&!X;(w.value!==void 0&&w.value===O||ee)&&(j(K),ee&&(G.current=!0))},[w.value]),de=m.useCallback(()=>S==null?void 0:S.focus(),[S]),be=m.useCallback((K,O,X)=>{const ee=!G.current&&!X;(w.value!==void 0&&w.value===O||ee)&&L(K)},[w.value]),ye=r==="popper"?rl:Tp,Se=ye===rl?{side:a,sideOffset:l,align:u,alignOffset:d,arrowPadding:f,collisionBoundary:h,collisionPadding:p,sticky:b,hideWhenDetached:x,avoidCollisions:g}:{};return c.jsx(Sp,{scope:n,content:S,viewport:T,onViewportChange:k,itemRefCallback:Q,selectedItem:A,onItemLeave:de,itemTextRefCallback:be,focusSelectedItem:W,selectedItemText:P,position:r,isPositioned:V,searchRef:le,children:c.jsx(ms,{as:LC,allowPinchZoom:!0,children:c.jsx(ls,{asChild:!0,trapped:w.open,onMountAutoFocus:K=>{K.preventDefault()},onUnmountAutoFocus:ce(o,K=>{var O;(O=w.trigger)==null||O.focus({preventScroll:!0}),K.preventDefault()}),children:c.jsx(as,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:K=>K.preventDefault(),onDismiss:()=>w.onOpenChange(!1),children:c.jsx(ye,{role:"listbox",id:w.contentId,"data-state":w.open?"open":"closed",dir:w.dir,onContextMenu:K=>K.preventDefault(),...v,...Se,onPlaced:()=>M(!0),ref:E,style:{display:"flex",flexDirection:"column",outline:"none",...v.style},onKeyDown:ce(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=$().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()}})})})})})})});Cp.displayName=DC;var $C="SelectItemAlignedPosition",Tp=m.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...o}=e,s=Vn(pr,n),i=qn(pr,n),[a,l]=m.useState(null),[u,d]=m.useState(null),f=Ve(t,E=>d(E)),h=Xs(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 fe=P.left-A.left,ne=j.left-fe,he=E.left-ne,Qe=E.width+he,et=Math.max(Qe,A.width),Pe=window.innerWidth-cn,He=Ja(ne,[cn,Math.max(cn,Pe-et)]);a.style.minWidth=Qe+"px",a.style.left=He+"px"}else{const fe=A.right-P.right,ne=window.innerWidth-j.right-fe,he=window.innerWidth-E.right-ne,Qe=E.width+he,et=Math.max(Qe,A.width),Pe=window.innerWidth-cn,He=Ja(ne,[cn,Math.max(cn,Pe-et)]);a.style.minWidth=Qe+"px",a.style.right=He+"px"}const L=h(),$=window.innerHeight-cn*2,V=x.scrollHeight,M=window.getComputedStyle(u),G=parseInt(M.borderTopWidth,10),q=parseInt(M.paddingTop,10),W=parseInt(M.borderBottomWidth,10),B=parseInt(M.paddingBottom,10),F=G+q+V+B+W,le=Math.min(g.offsetHeight*5,F),D=window.getComputedStyle(x),Q=parseInt(D.paddingTop,10),de=parseInt(D.paddingBottom,10),be=E.top+E.height/2-cn,ye=$-be,Se=g.offsetHeight/2,K=g.offsetTop+Se,O=G+q+K,X=F-O;if(O<=be){const fe=L.length>0&&g===L[L.length-1].ref.current;a.style.bottom="0px";const ne=u.clientHeight-x.offsetTop-x.offsetHeight,he=Math.max(ye,Se+(fe?de:0)+ne+W),Qe=O+he;a.style.height=Qe+"px"}else{const fe=L.length>0&&g===L[0].ref.current;a.style.top="0px";const he=Math.max(be,G+x.offsetTop+(fe?Q:0)+Se)+X;a.style.height=he+"px",x.scrollTop=O-be+x.offsetTop}a.style.margin=`${cn}px 0`,a.style.minHeight=le+"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]);Ct(()=>S(),[S]);const[N,T]=m.useState();Ct(()=>{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(BC,{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}})})})});Tp.displayName=$C;var FC="SelectPopperPosition",rl=m.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=cn,...s}=e,i=Js(n);return c.jsx(Pf,{...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)"}})});rl.displayName=FC;var[BC,ol]=Mr(pr,{}),sl="SelectViewport",kp=m.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...o}=e,s=qn(sl,n),i=ol(sl,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(Ys.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:ce(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-cn*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})})})]})});kp.displayName=sl;var Ip="SelectGroup",[zC,HC]=Mr(Ip),UC=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=xn();return c.jsx(zC,{scope:n,id:o,children:c.jsx(_e.div,{role:"group","aria-labelledby":o,...r,ref:t})})});UC.displayName=Ip;var Ep="SelectLabel",Np=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=HC(Ep,n);return c.jsx(_e.div,{id:o.id,...r,ref:t})});Np.displayName=Ep;var Zs="SelectItem",[WC,Ap]=Mr(Zs),_p=m.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:s,...i}=e,a=Vn(Zs,n),l=qn(Zs,n),u=a.value===r,[d,f]=m.useState(s??""),[h,p]=m.useState(!1),b=Ve(t,w=>{var S;return(S=l.itemRefCallback)==null?void 0:S.call(l,w,r,o)}),x=xn(),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(WC,{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(Ys.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:ce(i.onFocus,()=>p(!0)),onBlur:ce(i.onBlur,()=>p(!1)),onClick:ce(i.onClick,()=>{g.current!=="mouse"&&v()}),onPointerUp:ce(i.onPointerUp,()=>{g.current==="mouse"&&v()}),onPointerDown:ce(i.onPointerDown,w=>{g.current=w.pointerType}),onPointerMove:ce(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:ce(i.onPointerLeave,w=>{var S;w.currentTarget===document.activeElement&&((S=l.onItemLeave)==null||S.call(l))}),onKeyDown:ce(i.onKeyDown,w=>{var N;((N=l.searchRef)==null?void 0:N.current)!==""&&w.key===" "||(AC.includes(w.key)&&v(),w.key===" "&&w.preventDefault())})})})})});_p.displayName=Zs;var bo="SelectItemText",jp=m.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,...s}=e,i=Vn(bo,n),a=qn(bo,n),l=Ap(bo,n),u=PC(bo,n),[d,f]=m.useState(null),h=Ve(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 Ct(()=>(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?So.createPortal(s.children,i.valueNode):null]})});jp.displayName=bo;var Rp="SelectItemIndicator",Pp=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return Ap(Rp,n).isSelected?c.jsx(_e.span,{"aria-hidden":!0,...r,ref:t}):null});Pp.displayName=Rp;var il="SelectScrollUpButton",Op=m.forwardRef((e,t)=>{const n=qn(il,e.__scopeSelect),r=ol(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.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(Dp,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop-l.offsetHeight)}}):null});Op.displayName=il;var al="SelectScrollDownButton",Mp=m.forwardRef((e,t)=>{const n=qn(al,e.__scopeSelect),r=ol(al,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(Dp,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop+l.offsetHeight)}}):null});Mp.displayName=al;var Dp=m.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...o}=e,s=qn("SelectScrollButton",n),i=m.useRef(null),a=Xs(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:ce(o.onPointerDown,()=>{i.current===null&&(i.current=window.setInterval(r,50))}),onPointerMove:ce(o.onPointerMove,()=>{var u;(u=s.onItemLeave)==null||u.call(s),i.current===null&&(i.current=window.setInterval(r,50))}),onPointerLeave:ce(o.onPointerLeave,()=>{l()})})}),VC="SelectSeparator",Lp=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return c.jsx(_e.div,{"aria-hidden":!0,...r,ref:t})});Lp.displayName=VC;var ll="SelectArrow",qC=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Js(n),s=Vn(ll,n),i=qn(ll,n);return s.open&&i.position==="popper"?c.jsx(Of,{...o,...r,ref:t}):null});qC.displayName=ll;var KC="SelectBubbleInput",$p=m.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const o=m.useRef(null),s=Ve(r,o),i=ip(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:{...hp,...n.style},ref:s,defaultValue:t})});$p.displayName=KC;function Fp(e){return e===""||e===void 0}function Bp(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 zp(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=GC(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 GC(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var YC=pp,Hp=gp,XC=vp,JC=bp,ZC=wp,Up=yp,QC=kp,Wp=Np,Vp=_p,eT=jp,tT=Pp,qp=Op,Kp=Mp,Gp=Lp;const Yp=YC,Xp=XC,cl=m.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(Hp,{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(JC,{asChild:!0,children:c.jsx(oe.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));cl.displayName=Hp.displayName;const Jp=m.forwardRef(({className:e,...t},n)=>c.jsx(qp,{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"})}));Jp.displayName=qp.displayName;const Zp=m.forwardRef(({className:e,...t},n)=>c.jsx(Kp,{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"})}));Zp.displayName=Kp.displayName;const ul=m.forwardRef(({className:e,children:t,position:n="popper",...r},o)=>c.jsx(ZC,{children:c.jsxs(Up,{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(Jp,{}),c.jsx(QC,{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(Zp,{})]})}));ul.displayName=Up.displayName;const nT=m.forwardRef(({className:e,...t},n)=>c.jsx(Wp,{ref:n,className:Z("py-1.5 pl-8 pr-2 text-sm font-semibold",e),...t}));nT.displayName=Wp.displayName;const mr=m.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(Vp,{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(tT,{children:c.jsx(oe.Check,{className:"h-4 w-4"})})}),c.jsx(eT,{children:t})]}));mr.displayName=Vp.displayName;const rT=m.forwardRef(({className:e,...t},n)=>c.jsx(Gp,{ref:n,className:Z("-mx-1 my-1 h-px bg-muted",e),...t}));rT.displayName=Gp.displayName;var oT="Separator",Qp="horizontal",sT=["horizontal","vertical"],em=m.forwardRef((e,t)=>{const{decorative:n,orientation:r=Qp,...o}=e,s=iT(r)?r:Qp,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})});em.displayName=oT;function iT(e){return sT.includes(e)}var tm=em;const nm=m.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},o)=>c.jsx(tm,{ref:o,decorative:n,orientation:t,className:Z("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));nm.displayName=tm.displayName;const aT=$d,lT=zw,cT=Fd,rm=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}));rm.displayName=ws.displayName;const uT=yo.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"}}),om=m.forwardRef(({side:e="right",className:t,children:n,...r},o)=>c.jsxs(cT,{children:[c.jsx(rm,{}),c.jsxs(ys,{ref:o,className:Z(uT({side:e}),t),...r,children:[n,c.jsxs(Bd,{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"})]})]})]}));om.displayName=ys.displayName;const sm=({className:e,...t})=>c.jsx("div",{className:Z("flex flex-col space-y-2 text-center sm:text-left",e),...t});sm.displayName="SheetHeader";const im=m.forwardRef(({className:e,...t},n)=>c.jsx(lr,{ref:n,className:Z("text-lg font-semibold text-foreground",e),...t}));im.displayName=lr.displayName;const am=m.forwardRef(({className:e,...t},n)=>c.jsx(Ss,{ref:n,className:Z("text-sm text-muted-foreground",e),...t}));am.displayName=Ss.displayName;const dT={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 fT({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}=ca();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(dT),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(aT,{open:r,onOpenChange:o,children:[c.jsx(lT,{asChild:!0,children:c.jsxs(Xe,{variant:"outline",size:"sm",className:n,children:[c.jsx(oe.Settings,{className:"h-4 w-4 mr-2"}),"Settings",u&&c.jsx(Qi,{variant:"destructive",className:"ml-2 h-4 w-4 p-0"})]})}),c.jsxs(om,{className:"w-[500px] sm:w-[600px] overflow-y-auto",children:[c.jsxs(sm,{children:[c.jsx(im,{children:"Chat Settings"}),c.jsx(am,{children:"Configure your chat interface, API connection, and behavior preferences."})]}),c.jsxs("div",{className:"space-y-6 py-6",children:[c.jsxs(oo,{children:[c.jsx(so,{className:"pb-3",children:c.jsxs(io,{className:"text-lg flex items-center gap-2",children:[c.jsx(oe.Server,{className:"h-5 w-5"}),"API Configuration"]})}),c.jsxs(es,{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(Us,{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(Xe,{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(Wn,{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(Us,{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(Xe,{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(oo,{children:[c.jsx(so,{className:"pb-3",children:c.jsxs(io,{className:"text-lg flex items-center gap-2",children:[c.jsx(oe.Layout,{className:"h-5 w-5"}),"Interface Settings"]})}),c.jsxs(es,{className:"space-y-4",children:[c.jsxs("div",{className:"space-y-2",children:[c.jsx(Jt,{htmlFor:"layout",children:"Layout Style"}),c.jsxs(Yp,{value:a.ui.layout,onValueChange:g=>l(v=>({...v,ui:{...v.ui,layout:g}})),children:[c.jsx(cl,{children:c.jsx(Xp,{})}),c.jsxs(ul,{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(Jt,{htmlFor:"theme",children:"Theme"}),c.jsxs(Yp,{value:a.ui.theme,onValueChange:g=>l(v=>({...v,ui:{...v.ui,theme:g}})),children:[c.jsx(cl,{children:c.jsx(Xp,{})}),c.jsxs(ul,{children:[c.jsx(mr,{value:"light",children:"Light"}),c.jsx(mr,{value:"dark",children:"Dark"}),c.jsx(mr,{value:"system",children:"System"})]})]})]}),c.jsx(nm,{}),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(Wn,{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(Wn,{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(Wn,{id:"compact-messages",checked:a.ui.compactMessages,onCheckedChange:g=>l(v=>({...v,ui:{...v.ui,compactMessages:g}}))})]})]})]})]}),c.jsxs(oo,{children:[c.jsx(so,{className:"pb-3",children:c.jsxs(io,{className:"text-lg flex items-center gap-2",children:[c.jsx(oe.MessageCircle,{className:"h-5 w-5"}),"Behavior Settings"]})}),c.jsxs(es,{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(Wn,{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(Wn,{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(Wn,{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(Xe,{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(Xe,{variant:"outline",onClick:b,children:"Cancel"}),c.jsxs(Xe,{onClick:h,disabled:!u,children:[c.jsx(oe.Save,{className:"h-4 w-4 mr-2"}),"Save Changes"]})]})]})]})]})}function hT({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($o,{...s,onThreadChange:l,children:c.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:c.jsx(Hs,{className:"flex-1",onError:s.onError,enableFileUpload:!0})})}):e==="tabs"?c.jsx($o,{...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(nl,{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(Hs,{onError:s.onError,enableFileUpload:!0})})]})})}):c.jsx($o,{...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(nl,{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(Hs,{onError:s.onError,enableFileUpload:!0})})]})})}je.ChatApi=ic,je.ChatInterface=Hs,je.ChatProviders=$o,je.ChatSettings=fT,je.MarkdownContent=ia,je.MessageComponent=Yd,je.MessageList=ka,je.ThreadManager=nl,je.applySettings=vC,je.chatApiClient=On,je.default=hT,je.del=sc,je.get=tn,je.getChatToken=nc,je.getCurrentSettings=xC,je.getDefaultApiConfig=tp,je.getDefaultChatSettings=np,je.onChatTokenChanged=rc,je.post=xi,je.put=oc,je.setChatToken=gi,je.useApi=vi,je.useChatStream=Sc,je.useMessagesReducer=hc,je.useStream=Nc,je.useThreadState=Lo,je.useThreads=Do,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.jsx("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: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"}})});
|