teodor-new-chat-ui 4.2.6 → 4.2.7
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 +5255 -5234
- package/dist/index.umd.js +49 -49
- package/dist/lib/chat-api.d.ts +1 -7
- package/dist/lib/historyUtils.d.ts +14 -2
- package/dist/types/api.d.ts +2 -0
- package/package.json +1 -1
package/dist/index.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(
|
|
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,oe,Xn,bo,lm,cm,ti){"use strict";var cT=Object.defineProperty;var uT=(je,y,oe)=>y in je?cT(je,y,{enumerable:!0,configurable:!0,writable:!0,value:oe}):je[y]=oe;var im=(je,y,oe)=>uT(je,typeof y!="symbol"?y+"":y,oe);function dl(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=dl(y),yo=dl(ti);var ni={exports:{}},Br={};/**
|
|
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 fl;function um(){if(fl)return Br;fl=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 Br.Fragment=n,Br.jsx=i,Br.jsxs=i,Br}var zr={};/**
|
|
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
|
-
`+
|
|
17
|
+
*/var hl;function dm(){return hl||(hl=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"),w=Symbol.iterator,x="@@iterator";function g(E){if(E===null||typeof E!="object")return null;var z=w&&E[w]||E[x];return typeof z=="function"?z:null}var v=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function b(E){{for(var z=arguments.length,te=new Array(z>1?z-1:0),Ee=1;Ee<z;Ee++)te[Ee-1]=arguments[Ee];S("error",E,te)}}function S(E,z,te){{var Ee=v.ReactDebugCurrentFrame,Fe=Ee.getStackAddendum();Fe!==""&&(z+="%s",te=te.concat([Fe]));var Ke=te.map(function(We){return String(We)});Ke.unshift("Warning: "+z),Function.prototype.apply.call(console[E],console,Ke)}}var N=!1,C=!1,k=!1,I=!1,A=!1,j;j=Symbol.for("react.module.reference");function P(E){return!!(typeof E=="string"||typeof E=="function"||E===r||E===s||A||E===o||E===u||E===d||I||E===p||N||C||k||typeof E=="object"&&E!==null&&(E.$$typeof===h||E.$$typeof===f||E.$$typeof===i||E.$$typeof===a||E.$$typeof===l||E.$$typeof===j||E.getModuleId!==void 0))}function L(E,z,te){var Ee=E.displayName;if(Ee)return Ee;var Fe=z.displayName||z.name||"";return Fe!==""?te+"("+Fe+")":te}function F(E){return E.displayName||"Context"}function V(E){if(E==null)return null;if(typeof E.tag=="number"&&b("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof E=="function")return E.displayName||E.name||null;if(typeof E=="string")return E;switch(E){case r:return"Fragment";case n:return"Portal";case s:return"Profiler";case o:return"StrictMode";case u:return"Suspense";case d:return"SuspenseList"}if(typeof E=="object")switch(E.$$typeof){case a:var z=E;return F(z)+".Consumer";case i:var te=E;return F(te._context)+".Provider";case l:return L(E,E.render,"ForwardRef");case f:var Ee=E.displayName||null;return Ee!==null?Ee:V(E.type)||"Memo";case h:{var Fe=E,Ke=Fe._payload,We=Fe._init;try{return V(We(Ke))}catch{return null}}}return null}var M=Object.assign,G=0,q,U,B,$,ce,D,Q;function de(){}de.__reactDisabledLog=!0;function we(){{if(G===0){q=console.log,U=console.info,B=console.warn,$=console.error,ce=console.group,D=console.groupCollapsed,Q=console.groupEnd;var E={configurable:!0,enumerable:!0,value:de,writable:!0};Object.defineProperties(console,{info:E,log:E,warn:E,error:E,group:E,groupCollapsed:E,groupEnd:E})}G++}}function ye(){{if(G--,G===0){var E={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:M({},E,{value:q}),info:M({},E,{value:U}),warn:M({},E,{value:B}),error:M({},E,{value:$}),group:M({},E,{value:ce}),groupCollapsed:M({},E,{value:D}),groupEnd:M({},E,{value:Q})})}G<0&&b("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var Se=v.ReactCurrentDispatcher,K;function O(E,z,te){{if(K===void 0)try{throw Error()}catch(Fe){var Ee=Fe.stack.trim().match(/\n( *(at )?)/);K=Ee&&Ee[1]||""}return`
|
|
18
|
+
`+K+E}}var X=!1,ee;{var fe=typeof WeakMap=="function"?WeakMap:Map;ee=new fe}function ne(E,z){if(!E||X)return"";{var te=ee.get(E);if(te!==void 0)return te}var Ee;X=!0;var Fe=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var Ke;Ke=Se.current,Se.current=null,we();try{if(z){var We=function(){throw Error()};if(Object.defineProperty(We.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(We,[])}catch(_){Ee=_}Reflect.construct(E,[],We)}else{try{We.call()}catch(_){Ee=_}E.call(We.prototype)}}else{try{throw Error()}catch(_){Ee=_}E()}}catch(_){if(_&&Ee&&typeof _.stack=="string"){for(var ze=_.stack.split(`
|
|
19
|
+
`),wt=Ee.stack.split(`
|
|
20
|
+
`),ft=ze.length-1,ht=wt.length-1;ft>=1&&ht>=0&&ze[ft]!==wt[ht];)ht--;for(;ft>=1&&ht>=0;ft--,ht--)if(ze[ft]!==wt[ht]){if(ft!==1||ht!==1)do if(ft--,ht--,ht<0||ze[ft]!==wt[ht]){var Lt=`
|
|
21
|
+
`+ze[ft].replace(" at new "," at ");return E.displayName&&Lt.includes("<anonymous>")&&(Lt=Lt.replace("<anonymous>",E.displayName)),typeof E=="function"&&ee.set(E,Lt),Lt}while(ft>=1&&ht>=0);break}}}finally{X=!1,Se.current=Ke,ye(),Error.prepareStackTrace=Fe}var Yn=E?E.displayName||E.name:"",T=Yn?O(Yn):"";return typeof E=="function"&&ee.set(E,T),T}function pe(E,z,te){return ne(E,!1)}function Ze(E){var z=E.prototype;return!!(z&&z.isReactComponent)}function Qe(E,z,te){if(E==null)return"";if(typeof E=="function")return ne(E,Ze(E));if(typeof E=="string")return O(E);switch(E){case u:return O("Suspense");case d:return O("SuspenseList")}if(typeof E=="object")switch(E.$$typeof){case l:return pe(E.render);case f:return Qe(E.type,z,te);case h:{var Ee=E,Fe=Ee._payload,Ke=Ee._init;try{return Qe(Ke(Fe),z,te)}catch{}}}return""}var Pe=Object.prototype.hasOwnProperty,He={},ct=v.ReactDebugCurrentFrame;function tt(E){if(E){var z=E._owner,te=Qe(E.type,E._source,z?z.type:null);ct.setExtraStackFrame(te)}else ct.setExtraStackFrame(null)}function Be(E,z,te,Ee,Fe){{var Ke=Function.call.bind(Pe);for(var We in E)if(Ke(E,We)){var ze=void 0;try{if(typeof E[We]!="function"){var wt=Error((Ee||"React class")+": "+te+" type `"+We+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof E[We]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw wt.name="Invariant Violation",wt}ze=E[We](z,We,Ee,te,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(ft){ze=ft}ze&&!(ze instanceof Error)&&(tt(Fe),b("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",Ee||"React class",te,We,typeof ze),tt(null)),ze instanceof Error&&!(ze.message in He)&&(He[ze.message]=!0,tt(Fe),b("Failed %s type: %s",te,ze.message),tt(null))}}}var gt=Array.isArray;function J(E){return gt(E)}function re(E){{var z=typeof Symbol=="function"&&Symbol.toStringTag,te=z&&E[Symbol.toStringTag]||E.constructor.name||"Object";return te}}function he(E){try{return Ce(E),!1}catch{return!0}}function Ce(E){return""+E}function me(E){if(he(E))return b("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",re(E)),Ce(E)}var Oe=v.ReactCurrentOwner,it={key:!0,ref:!0,__self:!0,__source:!0},Me,et;function vt(E){if(Pe.call(E,"ref")){var z=Object.getOwnPropertyDescriptor(E,"ref").get;if(z&&z.isReactWarning)return!1}return E.ref!==void 0}function Zt(E){if(Pe.call(E,"key")){var z=Object.getOwnPropertyDescriptor(E,"key").get;if(z&&z.isReactWarning)return!1}return E.key!==void 0}function qn(E,z){typeof E.ref=="string"&&Oe.current}function Mr(E,z){{var te=function(){Me||(Me=!0,b("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",z))};te.isReactWarning=!0,Object.defineProperty(E,"key",{get:te,configurable:!0})}}function mr(E,z){{var te=function(){et||(et=!0,b("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",z))};te.isReactWarning=!0,Object.defineProperty(E,"ref",{get:te,configurable:!0})}}var Rt=function(E,z,te,Ee,Fe,Ke,We){var ze={$$typeof:t,type:E,key:z,ref:te,props:We,_owner:Ke};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:Fe}),Object.freeze&&(Object.freeze(ze.props),Object.freeze(ze)),ze};function wo(E,z,te,Ee,Fe){{var Ke,We={},ze=null,wt=null;te!==void 0&&(me(te),ze=""+te),Zt(z)&&(me(z.key),ze=""+z.key),vt(z)&&(wt=z.ref,qn(z,Fe));for(Ke in z)Pe.call(z,Ke)&&!it.hasOwnProperty(Ke)&&(We[Ke]=z[Ke]);if(E&&E.defaultProps){var ft=E.defaultProps;for(Ke in ft)We[Ke]===void 0&&(We[Ke]=ft[Ke])}if(ze||wt){var ht=typeof E=="function"?E.displayName||E.name||"Unknown":E;ze&&Mr(We,ht),wt&&mr(We,ht)}return Rt(E,ze,wt,Fe,Ee,Oe.current,We)}}var _n=v.ReactCurrentOwner,St=v.ReactDebugCurrentFrame;function At(E){if(E){var z=E._owner,te=Qe(E.type,E._source,z?z.type:null);St.setExtraStackFrame(te)}else St.setExtraStackFrame(null)}var Ut;Ut=!1;function Kn(E){return typeof E=="object"&&E!==null&&E.$$typeof===t}function dn(){{if(_n.current){var E=V(_n.current.type);if(E)return`
|
|
22
22
|
|
|
23
|
-
Check the render method of \``+
|
|
23
|
+
Check the render method of \``+E+"`."}return""}}function gr(E){return""}var fn={};function kn(E){{var z=dn();if(!z){var te=typeof E=="string"?E:E.displayName||E.name;te&&(z=`
|
|
24
24
|
|
|
25
|
-
Check the top-level render call using <`+
|
|
25
|
+
Check the top-level render call using <`+te+">.")}return z}}function Gn(E,z){{if(!E._store||E._store.validated||E.key!=null)return;E._store.validated=!0;var te=kn(z);if(fn[te])return;fn[te]=!0;var Ee="";E&&E._owner&&E._owner!==_n.current&&(Ee=" It was passed a child from "+V(E._owner.type)+"."),At(E),b('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',te,Ee),At(null)}}function Dr(E,z){{if(typeof E!="object")return;if(J(E))for(var te=0;te<E.length;te++){var Ee=E[te];Kn(Ee)&&Gn(Ee,z)}else if(Kn(E))E._store&&(E._store.validated=!0);else if(E){var Fe=g(E);if(typeof Fe=="function"&&Fe!==E.entries)for(var Ke=Fe.call(E),We;!(We=Ke.next()).done;)Kn(We.value)&&Gn(We.value,z)}}}function Lr(E){{var z=E.type;if(z==null||typeof z=="string")return;var te;if(typeof z=="function")te=z.propTypes;else if(typeof z=="object"&&(z.$$typeof===l||z.$$typeof===f))te=z.propTypes;else return;if(te){var Ee=V(z);Be(te,E.props,"prop",Ee,E)}else if(z.PropTypes!==void 0&&!Ut){Ut=!0;var Fe=V(z);b("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",Fe||"Unknown")}typeof z.getDefaultProps=="function"&&!z.getDefaultProps.isReactClassApproved&&b("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function Fr(E){{for(var z=Object.keys(E.props),te=0;te<z.length;te++){var Ee=z[te];if(Ee!=="children"&&Ee!=="key"){At(E),b("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",Ee),At(null);break}}E.ref!==null&&(At(E),b("Invalid attribute `ref` supplied to `React.Fragment`."),At(null))}}var jn={};function se(E,z,te,Ee,Fe,Ke){{var We=P(E);if(!We){var ze="";(E===void 0||typeof E=="object"&&E!==null&&Object.keys(E).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 wt=gr();wt?ze+=wt:ze+=dn();var ft;E===null?ft="null":J(E)?ft="array":E!==void 0&&E.$$typeof===t?(ft="<"+(V(E.type)||"Unknown")+" />",ze=" Did you accidentally export a JSX literal instead of a component?"):ft=typeof E,b("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",ft,ze)}var ht=wo(E,z,te,Fe,Ke);if(ht==null)return ht;if(We){var Lt=z.children;if(Lt!==void 0)if(Ee)if(J(Lt)){for(var Yn=0;Yn<Lt.length;Yn++)Dr(Lt[Yn],E);Object.freeze&&Object.freeze(Lt)}else b("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else Dr(Lt,E)}if(Pe.call(z,"key")){var T=V(E),_=Object.keys(z).filter(function(ie){return ie!=="key"}),W=_.length>0?"{key: someKey, "+_.join(": ..., ")+": ...}":"{key: someKey}";if(!jn[T+W]){var xe=_.length>0?"{"+_.join(": ..., ")+": ...}":"{}";b(`A props object containing a "key" prop is being spread into JSX:
|
|
26
26
|
let props = %s;
|
|
27
27
|
<%s {...props} />
|
|
28
28
|
React keys must be passed directly to JSX without using spread:
|
|
29
29
|
let props = %s;
|
|
30
|
-
<%s key={someKey} {...props} />`,xe,he,me,he),pr[he+xe]=!0}}return I===r?An(T):Dr(T),T}}function Te(I,B,oe){return ae(I,B,oe,!0)}function Oe(I,B,oe){return ae(I,B,oe,!1)}var rt=Oe,Rt=Te;$r.Fragment=r,$r.jsx=rt,$r.jsxs=Rt}()),$r}process.env.NODE_ENV==="production"?Qs.exports=sm():Qs.exports=im();var c=Qs.exports;function cl(e,t){return function(){return e.apply(t,arguments)}}const{toString:am}=Object.prototype,{getPrototypeOf:ei}=Object,{iterator:wo,toStringTag:ul}=Symbol,bo=(e=>t=>{const n=am.call(t);return e[n]||(e[n]=n.slice(8,-1).toLowerCase())})(Object.create(null)),Qt=e=>(e=e.toLowerCase(),t=>bo(t)===e),yo=e=>t=>typeof t===e,{isArray:mr}=Array,gr=yo("undefined");function zr(e){return e!==null&&!gr(e)&&e.constructor!==null&&!gr(e.constructor)&&Pt(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const dl=Qt("ArrayBuffer");function lm(e){let t;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?t=ArrayBuffer.isView(e):t=e&&e.buffer&&dl(e.buffer),t}const cm=yo("string"),Pt=yo("function"),fl=yo("number"),Br=e=>e!==null&&typeof e=="object",um=e=>e===!0||e===!1,So=e=>{if(bo(e)!=="object")return!1;const t=ei(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(ul in e)&&!(wo in e)},dm=e=>{if(!Br(e)||zr(e))return!1;try{return Object.keys(e).length===0&&Object.getPrototypeOf(e)===Object.prototype}catch{return!1}},fm=Qt("Date"),hm=Qt("File"),pm=Qt("Blob"),mm=Qt("FileList"),gm=e=>Br(e)&&Pt(e.pipe),xm=e=>{let t;return e&&(typeof FormData=="function"&&e instanceof FormData||Pt(e.append)&&((t=bo(e))==="formdata"||t==="object"&&Pt(e.toString)&&e.toString()==="[object FormData]"))},vm=Qt("URLSearchParams"),[wm,bm,ym,Sm]=["ReadableStream","Request","Response","Headers"].map(Qt),Cm=e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function Hr(e,t,{allOwnKeys:n=!1}={}){if(e===null||typeof e>"u")return;let r,o;if(typeof e!="object"&&(e=[e]),mr(e))for(r=0,o=e.length;r<o;r++)t.call(null,e[r],r,e);else{if(zr(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 hl(e,t){if(zr(e))return null;t=t.toLowerCase();const n=Object.keys(e);let r=n.length,o;for(;r-- >0;)if(o=n[r],t===o.toLowerCase())return o;return null}const Kn=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global,pl=e=>!gr(e)&&e!==Kn;function ti(){const{caseless:e,skipUndefined:t}=pl(this)&&this||{},n={},r=(o,s)=>{const i=e&&hl(n,s)||s;So(n[i])&&So(o)?n[i]=ti(n[i],o):So(o)?n[i]=ti({},o):mr(o)?n[i]=o.slice():(!t||!gr(o))&&(n[i]=o)};for(let o=0,s=arguments.length;o<s;o++)arguments[o]&&Hr(arguments[o],r);return n}const Tm=(e,t,n,{allOwnKeys:r}={})=>(Hr(t,(o,s)=>{n&&Pt(o)?e[s]=cl(o,n):e[s]=o},{allOwnKeys:r}),e),km=e=>(e.charCodeAt(0)===65279&&(e=e.slice(1)),e),Im=(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)},Em=(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&&ei(e)}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},Nm=(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},Am=e=>{if(!e)return null;if(mr(e))return e;let t=e.length;if(!fl(t))return null;const n=new Array(t);for(;t-- >0;)n[t]=e[t];return n},_m=(e=>t=>e&&t instanceof e)(typeof Uint8Array<"u"&&ei(Uint8Array)),jm=(e,t)=>{const r=(e&&e[wo]).call(e);let o;for(;(o=r.next())&&!o.done;){const s=o.value;t.call(e,s[0],s[1])}},Rm=(e,t)=>{let n;const r=[];for(;(n=e.exec(t))!==null;)r.push(n);return r},Pm=Qt("HTMLFormElement"),Om=e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(n,r,o){return r.toUpperCase()+o}),ml=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),Mm=Qt("RegExp"),gl=(e,t)=>{const n=Object.getOwnPropertyDescriptors(e),r={};Hr(n,(o,s)=>{let i;(i=t(o,s,e))!==!1&&(r[s]=i||o)}),Object.defineProperties(e,r)},Dm=e=>{gl(e,(t,n)=>{if(Pt(e)&&["arguments","caller","callee"].indexOf(n)!==-1)return!1;const r=e[n];if(Pt(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+"'")})}})},Lm=(e,t)=>{const n={},r=o=>{o.forEach(s=>{n[s]=!0})};return mr(e)?r(e):r(String(e).split(t)),n},Fm=()=>{},$m=(e,t)=>e!=null&&Number.isFinite(e=+e)?e:t;function zm(e){return!!(e&&Pt(e.append)&&e[ul]==="FormData"&&e[wo])}const Bm=e=>{const t=new Array(10),n=(r,o)=>{if(Br(r)){if(t.indexOf(r)>=0)return;if(zr(r))return r;if(!("toJSON"in r)){t[o]=r;const s=mr(r)?[]:{};return Hr(r,(i,a)=>{const l=n(i,o+1);!gr(l)&&(s[a]=l)}),t[o]=void 0,s}}return r};return n(e,0)},Hm=Qt("AsyncFunction"),Um=e=>e&&(Br(e)||Pt(e))&&Pt(e.then)&&Pt(e.catch),xl=((e,t)=>e?setImmediate:t?((n,r)=>(Kn.addEventListener("message",({source:o,data:s})=>{o===Kn&&s===n&&r.length&&r.shift()()},!1),o=>{r.push(o),Kn.postMessage(n,"*")}))(`axios@${Math.random()}`,[]):n=>setTimeout(n))(typeof setImmediate=="function",Pt(Kn.postMessage)),Wm=typeof queueMicrotask<"u"?queueMicrotask.bind(Kn):typeof process<"u"&&process.nextTick||xl,R={isArray:mr,isArrayBuffer:dl,isBuffer:zr,isFormData:xm,isArrayBufferView:lm,isString:cm,isNumber:fl,isBoolean:um,isObject:Br,isPlainObject:So,isEmptyObject:dm,isReadableStream:wm,isRequest:bm,isResponse:ym,isHeaders:Sm,isUndefined:gr,isDate:fm,isFile:hm,isBlob:pm,isRegExp:Mm,isFunction:Pt,isStream:gm,isURLSearchParams:vm,isTypedArray:_m,isFileList:mm,forEach:Hr,merge:ti,extend:Tm,trim:Cm,stripBOM:km,inherits:Im,toFlatObject:Em,kindOf:bo,kindOfTest:Qt,endsWith:Nm,toArray:Am,forEachEntry:jm,matchAll:Rm,isHTMLForm:Pm,hasOwnProperty:ml,hasOwnProp:ml,reduceDescriptors:gl,freezeMethods:Dm,toObjectSet:Lm,toCamelCase:Om,noop:Fm,toFiniteNumber:$m,findKey:hl,global:Kn,isContextDefined:pl,isSpecCompliantForm:zm,toJSONObject:Bm,isAsyncFn:Hm,isThenable:Um,setImmediate:xl,asap:Wm,isIterable:e=>e!=null&&Pt(e[wo])};function Me(e,t,n,r,o){Error.call(this),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=new Error().stack,this.message=e,this.name="AxiosError",t&&(this.code=t),n&&(this.config=n),r&&(this.request=r),o&&(this.response=o,this.status=o.status?o.status:null)}R.inherits(Me,Error,{toJSON:function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:R.toJSONObject(this.config),code:this.code,status:this.status}}});const vl=Me.prototype,wl={};["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=>{wl[e]={value:e}}),Object.defineProperties(Me,wl),Object.defineProperty(vl,"isAxiosError",{value:!0}),Me.from=(e,t,n,r,o,s)=>{const i=Object.create(vl);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 Me.call(i,a,l,n,r,o),e&&i.cause==null&&Object.defineProperty(i,"cause",{value:e,configurable:!0}),i.name=e&&e.name||"Error",s&&Object.assign(i,s),i};const Vm=null;function ni(e){return R.isPlainObject(e)||R.isArray(e)}function bl(e){return R.endsWith(e,"[]")?e.slice(0,-2):e}function yl(e,t,n){return e?e.concat(t).map(function(o,s){return o=bl(o),!n&&s?"["+o+"]":o}).join(n?".":""):t}function Km(e){return R.isArray(e)&&!e.some(ni)}const qm=R.toFlatObject(R,{},null,function(t){return/^is[A-Z]/.test(t)});function Co(e,t,n){if(!R.isObject(e))throw new TypeError("target must be an object");t=t||new FormData,n=R.toFlatObject(n,{metaTokens:!0,dots:!1,indexes:!1},!1,function(x,g){return!R.isUndefined(g[x])});const r=n.metaTokens,o=n.visitor||d,s=n.dots,i=n.indexes,l=(n.Blob||typeof Blob<"u"&&Blob)&&R.isSpecCompliantForm(t);if(!R.isFunction(o))throw new TypeError("visitor must be a function");function u(w){if(w===null)return"";if(R.isDate(w))return w.toISOString();if(R.isBoolean(w))return w.toString();if(!l&&R.isBlob(w))throw new Me("Blob is not supported. Use a Buffer instead.");return R.isArrayBuffer(w)||R.isTypedArray(w)?l&&typeof Blob=="function"?new Blob([w]):Buffer.from(w):w}function d(w,x,g){let v=w;if(w&&!g&&typeof w=="object"){if(R.endsWith(x,"{}"))x=r?x:x.slice(0,-2),w=JSON.stringify(w);else if(R.isArray(w)&&Km(w)||(R.isFileList(w)||R.endsWith(x,"[]"))&&(v=R.toArray(w)))return x=bl(x),v.forEach(function(S,N){!(R.isUndefined(S)||S===null)&&t.append(i===!0?yl([x],N,s):i===null?x:x+"[]",u(S))}),!1}return ni(w)?!0:(t.append(yl(g,x,s),u(w)),!1)}const f=[],h=Object.assign(qm,{defaultVisitor:d,convertValue:u,isVisitable:ni});function p(w,x){if(!R.isUndefined(w)){if(f.indexOf(w)!==-1)throw Error("Circular reference detected in "+x.join("."));f.push(w),R.forEach(w,function(v,b){(!(R.isUndefined(v)||v===null)&&o.call(t,v,R.isString(b)?b.trim():b,x,h))===!0&&p(v,x?x.concat(b):[b])}),f.pop()}}if(!R.isObject(e))throw new TypeError("data must be an object");return p(e),t}function Sl(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,function(r){return t[r]})}function ri(e,t){this._pairs=[],e&&Co(e,this,t)}const Cl=ri.prototype;Cl.append=function(t,n){this._pairs.push([t,n])},Cl.toString=function(t){const n=t?function(r){return t.call(this,r,Sl)}:Sl;return this._pairs.map(function(o){return n(o[0])+"="+n(o[1])},"").join("&")};function Gm(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+")}function Tl(e,t,n){if(!t)return e;const r=n&&n.encode||Gm;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 ri(t,n).toString(r),s){const i=e.indexOf("#");i!==-1&&(e=e.slice(0,i)),e+=(e.indexOf("?")===-1?"?":"&")+s}return e}class kl{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 Il={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},Ym={isBrowser:!0,classes:{URLSearchParams:typeof URLSearchParams<"u"?URLSearchParams:ri,FormData:typeof FormData<"u"?FormData:null,Blob:typeof Blob<"u"?Blob:null},protocols:["http","https","file","blob","url","data"]},oi=typeof window<"u"&&typeof document<"u",si=typeof navigator=="object"&&navigator||void 0,Xm=oi&&(!si||["ReactNative","NativeScript","NS"].indexOf(si.product)<0),Jm=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function",Zm=oi&&window.location.href||"http://localhost",Tt={...Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv:oi,hasStandardBrowserEnv:Xm,hasStandardBrowserWebWorkerEnv:Jm,navigator:si,origin:Zm},Symbol.toStringTag,{value:"Module"})),...Ym};function Qm(e,t){return Co(e,new Tt.classes.URLSearchParams,{visitor:function(n,r,o,s){return Tt.isNode&&R.isBuffer(n)?(this.append(r,n.toString("base64")),!1):s.defaultVisitor.apply(this,arguments)},...t})}function eg(e){return R.matchAll(/\w+|\[(\w*)]/g,e).map(t=>t[0]==="[]"?"":t[1]||t[0])}function tg(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 El(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]=tg(o[i])),!a)}if(R.isFormData(e)&&R.isFunction(e.entries)){const n={};return R.forEachEntry(e,(r,o)=>{t(eg(r),o,n,0)}),n}return null}function ng(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 Ur={transitional:Il,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(El(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 Qm(t,this.formSerializer).toString();if((a=R.isFileList(t))||r.indexOf("multipart/form-data")>-1){const l=this.env&&this.env.FormData;return Co(a?{"files[]":t}:t,l&&new l,this.formSerializer)}}return s||o?(n.setContentType("application/json",!1),ng(t)):t}],transformResponse:[function(t){const n=this.transitional||Ur.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"?Me.from(a,Me.ERR_BAD_RESPONSE,this,null,this.response):a}}return t}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:Tt.classes.FormData,Blob:Tt.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=>{Ur.headers[e]={}});const rg=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"]),og=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[Nl]=this[Nl]={accessors:{}}).accessors,o=this.prototype;function s(i){const a=Wr(i);r[a]||(lg(o,i),r[a]=!0)}return R.isArray(t)?t.forEach(s):s(t),this}};Ot.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),R.reduceDescriptors(Ot.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(r){this[n]=r}}}),R.freezeMethods(Ot);function ai(e,t){const n=this||Ur,r=t||n,o=Ot.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 Al(e){return!!(e&&e.__CANCEL__)}function xr(e,t,n){Me.call(this,e??"canceled",Me.ERR_CANCELED,t,n),this.name="CanceledError"}R.inherits(xr,Me,{__CANCEL__:!0});function _l(e,t,n){const r=n.config.validateStatus;!n.status||!r||r(n.status)?e(n):t(new Me("Request failed with status code "+n.status,[Me.ERR_BAD_REQUEST,Me.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n))}function cg(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function ug(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 dg(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 ko=(e,t,n=3)=>{let r=0;const o=ug(50,250);return dg(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)},jl=(e,t)=>{const n=e!=null;return[r=>t[0]({lengthComputable:n,total:e,loaded:r}),t[1]]},Rl=e=>(...t)=>R.asap(()=>e(...t)),fg=Tt.hasStandardBrowserEnv?((e,t)=>n=>(n=new URL(n,Tt.origin),e.protocol===n.protocol&&e.host===n.host&&(t||e.port===n.port)))(new URL(Tt.origin),Tt.navigator&&/(msie|trident)/i.test(Tt.navigator.userAgent)):()=>!0,hg=Tt.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 pg(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function mg(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function Pl(e,t,n){let r=!pg(t);return e&&(r||n==!1)?mg(e,t):t}const Ol=e=>e instanceof Ot?{...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(Ol(u),Ol(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 Ml=e=>{const t=qn({},e);let{data:n,withXSRFToken:r,xsrfHeaderName:o,xsrfCookieName:s,headers:i,auth:a}=t;if(t.headers=i=Ot.from(i),t.url=Tl(Pl(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(Tt.hasStandardBrowserEnv||Tt.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(Tt.hasStandardBrowserEnv&&(r&&R.isFunction(r)&&(r=r(t)),r||r!==!1&&fg(t.url))){const l=o&&s&&hg.read(s);l&&i.set(o,l)}return t},gg=typeof XMLHttpRequest<"u"&&function(e){return new Promise(function(n,r){const o=Ml(e);let s=o.data;const i=Ot.from(o.headers).normalize();let{responseType:a,onUploadProgress:l,onDownloadProgress:u}=o,d,f,h,p,w;function x(){p&&p(),w&&w(),o.cancelToken&&o.cancelToken.unsubscribe(d),o.signal&&o.signal.removeEventListener("abort",d)}let g=new XMLHttpRequest;g.open(o.method.toUpperCase(),o.url,!0),g.timeout=o.timeout;function v(){if(!g)return;const S=Ot.from("getAllResponseHeaders"in g&&g.getAllResponseHeaders()),C={data:!a||a==="text"||a==="json"?g.responseText:g.response,status:g.status,statusText:g.statusText,headers:S,config:e,request:g};_l(function(E){n(E),x()},function(E){r(E),x()},C),g=null}"onloadend"in g?g.onloadend=v:g.onreadystatechange=function(){!g||g.readyState!==4||g.status===0&&!(g.responseURL&&g.responseURL.indexOf("file:")===0)||setTimeout(v)},g.onabort=function(){g&&(r(new Me("Request aborted",Me.ECONNABORTED,e,g)),g=null)},g.onerror=function(N){const C=N&&N.message?N.message:"Network Error",k=new Me(C,Me.ERR_NETWORK,e,g);k.event=N||null,r(k),g=null},g.ontimeout=function(){let N=o.timeout?"timeout of "+o.timeout+"ms exceeded":"timeout exceeded";const C=o.transitional||Il;o.timeoutErrorMessage&&(N=o.timeoutErrorMessage),r(new Me(N,C.clarifyTimeoutError?Me.ETIMEDOUT:Me.ECONNABORTED,e,g)),g=null},s===void 0&&i.setContentType(null),"setRequestHeader"in g&&R.forEach(i.toJSON(),function(N,C){g.setRequestHeader(C,N)}),R.isUndefined(o.withCredentials)||(g.withCredentials=!!o.withCredentials),a&&a!=="json"&&(g.responseType=o.responseType),u&&([h,w]=ko(u,!0),g.addEventListener("progress",h)),l&&g.upload&&([f,p]=ko(l),g.upload.addEventListener("progress",f),g.upload.addEventListener("loadend",p)),(o.cancelToken||o.signal)&&(d=S=>{g&&(r(!S||S.type?new xr(null,e,g):S),g.abort(),g=null)},o.cancelToken&&o.cancelToken.subscribe(d),o.signal&&(o.signal.aborted?d():o.signal.addEventListener("abort",d)));const b=cg(o.url);if(b&&Tt.protocols.indexOf(b)===-1){r(new Me("Unsupported protocol "+b+":",Me.ERR_BAD_REQUEST,e));return}g.send(s||null)})},xg=(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 Me?d:new xr(d instanceof Error?d.message:d))}};let i=t&&setTimeout(()=>{i=null,s(new Me(`timeout ${t} of ms exceeded`,Me.ETIMEDOUT))},t);const a=()=>{e&&(i&&clearTimeout(i),i=null,e.forEach(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}},vg=function*(e,t){let n=e.byteLength;if(n<t){yield e;return}let r=0,o;for(;r<n;)o=r+t,yield e.slice(r,o),r=o},wg=async function*(e,t){for await(const n of bg(e))yield*vg(n,t)},bg=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()}},Dl=(e,t,n,r)=>{const o=wg(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})},Ll=64*1024,{isFunction:Io}=R,yg=(({Request:e,Response:t})=>({Request:e,Response:t}))(R.global),{ReadableStream:Fl,TextEncoder:$l}=R.global,zl=(e,...t)=>{try{return!!e(...t)}catch{return!1}},Sg=e=>{e=R.merge.call({skipUndefined:!0},yg,e);const{fetch:t,Request:n,Response:r}=e,o=t?Io(t):typeof fetch=="function",s=Io(n),i=Io(r);if(!o)return!1;const a=o&&Io(Fl),l=o&&(typeof $l=="function"?(w=>x=>w.encode(x))(new $l):async w=>new Uint8Array(await new n(w).arrayBuffer())),u=s&&a&&zl(()=>{let w=!1;const x=new n(Tt.origin,{body:new Fl,method:"POST",get duplex(){return w=!0,"half"}}).headers.has("Content-Type");return w&&!x}),d=i&&a&&zl(()=>R.isReadableStream(new r("").body)),f={stream:d&&(w=>w.body)};o&&["text","arrayBuffer","blob","formData","stream"].forEach(w=>{!f[w]&&(f[w]=(x,g)=>{let v=x&&x[w];if(v)return v.call(x);throw new Me(`Response type '${w}' is not supported`,Me.ERR_NOT_SUPPORT,g)})});const h=async w=>{if(w==null)return 0;if(R.isBlob(w))return w.size;if(R.isSpecCompliantForm(w))return(await new n(Tt.origin,{method:"POST",body:w}).arrayBuffer()).byteLength;if(R.isArrayBufferView(w)||R.isArrayBuffer(w))return w.byteLength;if(R.isURLSearchParams(w)&&(w=w+""),R.isString(w))return(await l(w)).byteLength},p=async(w,x)=>{const g=R.toFiniteNumber(w.getContentLength());return g??h(x)};return async w=>{let{url:x,method:g,data:v,signal:b,cancelToken:S,timeout:N,onDownloadProgress:C,onUploadProgress:k,responseType:E,headers:A,withCredentials:j="same-origin",fetchOptions:P}=Ml(w),L=t||fetch;E=E?(E+"").toLowerCase():"text";let F=xg([b,S&&S.toAbortSignal()],N),V=null;const M=F&&F.unsubscribe&&(()=>{F.unsubscribe()});let Y;try{if(k&&u&&g!=="get"&&g!=="head"&&(Y=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,ve]=jl(Y,ko(Rl(k)));v=Dl(D.body,Ll,fe,ve)}}R.isString(j)||(j=j?"include":"omit");const K=s&&"credentials"in n.prototype,W={...P,signal:F,method:g.toUpperCase(),headers:A.normalize().toJSON(),body:v,duplex:"half",credentials:K?j:void 0};V=s&&new n(x,W);let z=await(s?L(V,P):L(x,W));const $=d&&(E==="stream"||E==="response");if(d&&(C||$&&M)){const D={};["status","statusText","headers"].forEach(be=>{D[be]=z[be]});const ee=R.toFiniteNumber(z.headers.get("content-length")),[fe,ve]=C&&jl(ee,ko(Rl(C),!0))||[];z=new r(Dl(z.body,Ll,fe,()=>{ve&&ve(),M&&M()}),D)}E=E||"text";let ue=await f[R.findKey(f,E)||"text"](z,w);return!$&&M&&M(),await new Promise((D,ee)=>{_l(D,ee,{data:ue,headers:Ot.from(z.headers),status:z.status,statusText:z.statusText,config:w,request:V})})}catch(K){throw M&&M(),K&&K.name==="TypeError"&&/Load failed|fetch/i.test(K.message)?Object.assign(new Me("Network Error",Me.ERR_NETWORK,w,V),{cause:K.cause||K}):Me.from(K,K&&K.code,w,V)}}},Cg=new Map,Bl=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=Cg;for(;a--;)l=s[a],u=d.get(l),u===void 0&&d.set(l,u=a?new Map:Sg(t)),d=u;return u};Bl();const li={http:Vm,xhr:gg,fetch:{get:Bl}};R.forEach(li,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const Hl=e=>`- ${e}`,Tg=e=>R.isFunction(e)||e===null||e===!1,Ul={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,!Tg(r)&&(o=li[(a=String(r)).toLowerCase()],o===void 0))throw new Me(`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&&No.assertOptions(r,{silentJSONParsing:un.transitional(un.boolean),forcedJSONParsing:un.transitional(un.boolean),clarifyTimeoutError:un.transitional(un.boolean)},!1),o!=null&&(R.isFunction(o)?n.paramsSerializer={serialize:o}:No.assertOptions(o,{encode:un.function,serialize:un.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),No.assertOptions(n,{baseUrl:un.spelling("baseURL"),withXsrfToken:un.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let i=s&&R.merge(s.common,s[n.method]);s&&R.forEach(["delete","get","head","post","put","patch","common"],w=>{delete s[w]}),n.headers=Ot.concat(i,s);const a=[];let l=!0;this.interceptors.request.forEach(function(x){typeof x.runWhen=="function"&&x.runWhen(n)===!1||(l=l&&x.synchronous,a.unshift(x.fulfilled,x.rejected))});const u=[];this.interceptors.response.forEach(function(x){u.push(x.fulfilled,x.rejected)});let d,f=0,h;if(!l){const w=[Wl.bind(this),void 0];for(w.unshift(...a),w.push(...u),h=w.length,d=Promise.resolve(n);f<h;)d=d.then(w[f++],w[f++]);return d}h=a.length;let p=n;for(;f<h;){const w=a[f++],x=a[f++];try{p=w(p)}catch(g){x.call(this,g);break}}try{d=Wl.call(this,p)}catch(w){return Promise.reject(w)}for(f=0,h=u.length;f<h;)d=d.then(u[f++],u[f++]);return d}getUri(t){t=qn(this.defaults,t);const n=Pl(t.baseURL,t.url,t.allowAbsoluteUrls);return Tl(n,t.params,t.paramsSerializer)}};R.forEach(["delete","get","head","options"],function(t){Gn.prototype[t]=function(n,r){return this.request(qn(r||{},{method:t,url:n,data:(r||{}).data}))}}),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}))}}Gn.prototype[t]=n(),Gn.prototype[t+"Form"]=n(!0)});let Ig=class nm{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 xr(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 nm(function(o){t=o}),cancel:t}}};function Eg(e){return function(n){return e.apply(null,n)}}function Ng(e){return R.isObject(e)&&e.isAxiosError===!0}const ui={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(ui).forEach(([e,t])=>{ui[t]=e});function ql(e){const t=new Gn(e),n=cl(Gn.prototype.request,t);return R.extend(n,Gn.prototype,t,{allOwnKeys:!0}),R.extend(n,t,null,{allOwnKeys:!0}),n.create=function(o){return ql(qn(e,o))},n}const dt=ql(Ur);dt.Axios=Gn,dt.CanceledError=xr,dt.CancelToken=Ig,dt.isCancel=Al,dt.VERSION=Vl,dt.toFormData=Co,dt.AxiosError=Me,dt.Cancel=dt.CanceledError,dt.all=function(t){return Promise.all(t)},dt.spread=Eg,dt.isAxiosError=Ng,dt.mergeConfig=qn,dt.AxiosHeaders=Ot,dt.formToJSON=e=>El(R.isHTMLForm(e)?new FormData(e):e),dt.getAdapter=Ul.getAdapter,dt.HttpStatusCode=ui,dt.default=dt;const{Axios:dT,AxiosError:fT,CanceledError:hT,isCancel:pT,CancelToken:mT,VERSION:gT,all:xT,Cancel:vT,isAxiosError:wT,spread:bT,toFormData:yT,AxiosHeaders:ST,HttpStatusCode:CT,formToJSON:TT,getAdapter:kT,mergeConfig:IT}=dt,Gl=typeof window<"u"?window.__API_BASE_URL__:void 0,Yl=Gl?Tn(Gl):void 0;function Tn(e){const n=(e!=null&&e.trim()?e.trim():"/api/chat").replace(/\/+$/,"");return n?n.endsWith("/chat")?n:`${n}/chat`:"/api/chat"}let Ao=null;const di=new Set;function Xl(){return Ao}function fi(e){Ao=e,di.forEach(t=>t(e))}function Jl(e){return di.add(e),()=>di.delete(e)}const Wt=dt.create({...Yl?{baseURL:Yl}:{},timeout:3e4,withCredentials:!0});Wt.interceptors.request.use(e=>(Ao&&(e.headers.Authorization=`Bearer ${Ao}`),e)),Wt.interceptors.response.use(e=>e,e=>Promise.reject(e));async function Dt(e,t){return Wt.defaults.baseURL?(await Wt.get(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}async function hi(e,t,n){return Wt.defaults.baseURL?(await Wt.post(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function Zl(e,t,n){return Wt.defaults.baseURL?(await Wt.put(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function Ql(e,t){return Wt.defaults.baseURL?(await Wt.delete(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}function Lt(e){return e&&typeof e=="object"&&"data"in e?e.data:e}class ec{get baseUrl(){const t=Wt.defaults.baseURL;return t?Tn(String(t)):""}updateConfig(t){t.baseUrl&&(Wt.defaults.baseURL=Tn(String(t.baseUrl))),t.authToken!==void 0&&fi(t.authToken)}getAuthToken(){return Xl()}setAuthToken(t){fi(t)}onTokenChange(t){return Jl(t)}async listThreads(){const t=await Dt("/threads"),n=Lt(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async createThread(t){const r=await hi("/threads",t?{title:t}:void 0);return Lt(r)}async updateThread(t,n){const r=await Zl(`/threads/${t}`,{title:n});return Lt(r)}async deleteThread(t){const n=await Ql(`/threads/${t}`);return Lt(n)}async threadInfo(t){const n=await Dt(`/threads/${t}/info`);return Lt(n)}async listAgents(){const t=await Dt("/agents"),n=Lt(t);return(n==null?void 0:n.items)??[]}async getAgent(t){const n=await Dt(`/agents/${t}`);return Lt(n)}async getAgentSchema(t){const n=await Dt(`/agents/${t}/schema`);return Lt(n)}async getMessages(t){const n=await Dt(`/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 Lt(n)}async getState(t){const n=await Dt(`/threads/${t.threadId}/state`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return Lt(n)}async getStateHistory(t){const n=await Dt(`/threads/${t.threadId}/state/history`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return Lt(n)}async listCheckpoints(t){const n=await Dt(`/threads/${t}/checkpoints`,{params:{thread_id:t}});return Lt(n)}resumeStream(t){}async resume(t){const n=await hi("/runs/resume",{thread_id:t.threadId,value:t.value});return Lt(n)}}const jn=new ec,tc=y.createContext(null);function Ag({children:e,apiConfig:t}){const n=jn;if(t){const o=n.baseUrl,s=n.getAuthToken();t.baseUrl&&t.baseUrl!==o&&n.updateConfig({baseUrl:t.baseUrl}),t.apiKey!==void 0&&t.apiKey!==s&&n.updateConfig({authToken:t.apiKey})}const r={token:n.getAuthToken(),setToken:o=>n.setAuthToken(o),api:n,baseUrl:n.baseUrl};return c.jsx(tc.Provider,{value:r,children:e})}function pi(){const e=y.useContext(tc);if(!e)throw new Error("useApi must be used within ApiProvider");return e}function _g(e,t){const n=e==null?void 0:e.checkpoints,r=Array.isArray(n)?n.slice():n?Object.values(n):[],o=i=>i&&typeof i=="object"&&i!==null&&"checkpointId"in i&&"createdAt"in i&&typeof i.checkpointId=="string"&&typeof i.createdAt=="string",s=r.filter(o).map(i=>{const a=i;return{checkpointId:a.checkpointId,checkpointNs:a.checkpointNs??"",createdAt:a.createdAt,messagesLen:a.messagesLen??0,preview:a.preview??"",role:a.role??null,parentId:a.parentId??null,editedMessageId:a.editedMessageId??null,branchLabel:a.branchLabel??null,lastMessageId:a.lastMessageId??null,hasMessages:typeof a.hasMessages=="boolean"?a.hasMessages:void 0}});return{threadId:(e==null?void 0:e.threadId)??t??null,checkpoints:s}}async function jg(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 Rg(e,t=[],n,r,o,s){const i=[],a=[];for(const l of t)try{const u=await jg(l);a.push({filename:l.name,data:u,mime_type:l.type||"application/octet-stream"})}catch{}return{contentParts:i,filesInfo:a}}const Pg={human:"user",user:"user",ai:"assistant",assistant:"assistant",tool:"tool",function:"tool",system:"system"};function Og(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 nc(e){var d;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(!Og(r))return{threadId:n,checkpointId:void 0,checkpointNs:void 0,messages:[],hasMore:!1,nextCursor:null};const o=r.values??{},i=(Array.isArray(o==null?void 0:o.messages)?o.messages:[]).map((f,h)=>Mg(f,h)).filter(f=>!!f),a=Rn((d=r.config)==null?void 0:d.configurable),l=At(a,["checkpoint_id","checkpointId"]),u=At(a,["checkpoint_ns","checkpointNs"]);return{threadId:n,checkpointId:l??void 0,checkpointNs:u??void 0,messages:i,hasMore:!1,nextCursor:null}}function Mg(e,t){if(!e||typeof e!="object")return null;const n=e,r=Rn(e)??{},o=Rn(n.data)??r,s=String(n.type??o.type??o.role??"").toLowerCase(),i=Pg[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=Rn(o.additional_kwargs)??Rn(o.additionalKwargs),d=Rn(o.response_metadata)??Rn(o.responseMetadata),f=At(u,["createdAt","created_at"])??At(o,["created_at","createdAt"]),h=At(u,["checkpointId","checkpoint_id"]),p=At(u,["checkpointNs","checkpoint_ns"]),w=Dg(o.content),x={id:l,role:i,content:w};f&&(x.createdAt=f),typeof o.name=="string"&&o.name.trim()&&(x.name=o.name),typeof(d==null?void 0:d.model_name)=="string"&&(x.model=String(d.model_name)),!x.model&&typeof o.model=="string"&&(x.model=o.model),h&&(x.checkpointId=h),p&&(x.checkpointNs=p);const g=Bg(u,["createdAt","created_at","checkpointId","checkpoint_id","checkpointNs","checkpoint_ns","tool_calls"]),v=d?{...d}:void 0;g&&Object.keys(g).length&&(x.additionalKwargs=g),v&&Object.keys(v).length&&(x.responseMetadata=v);const b=Lg((u==null?void 0:u.tool_calls)??o.tool_calls);if(b.length&&(x.content=[...x.content,...b]),i==="tool"){const S=$g(o,x.content);S&&(x.content=S)}return x}function Dg(e){if(!e)return[];if(Array.isArray(e))return e.map(t=>rc(t)).filter(t=>!!t);if(typeof e=="string")return e.trim()?[{type:"text",text:e.trim()}]:[];if(typeof e=="object"){const t=rc(e);return t?[t]:[]}return[]}function rc(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=At(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=At(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 Fg(t)??null;if(n==="tool_end"){const o=At(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=At(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 Lg(e){return Array.isArray(e)?e.map((t,n)=>{if(!t||typeof t!="object")return null;const r=t,o=At(r,["id","call_id"]),s=Rn(r.function),i=At(s,["name"])??"tool",a=s==null?void 0:s.arguments,l=oc(a);return{type:"tool_call",id:o??`tool_call_${n}`,name:i,args:l}}).filter(t=>!!t):[]}function Fg(e){const t=At(e,["id","call_id"]),n=At(e,["name"]);if(!t||!n)return null;const r=oc(e.args??e.arguments);return{type:"tool_call",id:t,name:n,args:r}}function $g(e,t){const n=At(e,["tool_call_id","toolCallId","id"]);if(!n)return t;const r=e.content??e.output,o=typeof r=="string"?zg(r):r,s={type:"tool_end",toolCallId:n,output:o};return typeof e.error=="string"&&(s.error=e.error),[s]}function oc(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 zg(e){try{return JSON.parse(e)}catch{return e}}function Rn(e){if(!(!e||typeof e!="object"||Array.isArray(e)))return{...e}}function At(e,t){if(e)for(const n of t){const r=e[n];if(typeof r=="string"&&r.trim())return r}}function Bg(e,t){if(!e)return;const n={};let r=!1;for(const[o,s]of Object.entries(e)){if(t.includes(o)){r=!0;continue}s!==void 0&&(n[o]=s)}return r?Object.keys(n).length?n:void 0:e}function Hg(e){return e.type!=="thread_info"&&e.type!=="token"}const Ug={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null,messagesStreamMeta:{}};function Wg(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:mi(((n=t.payload)==null?void 0:n.messages)??[]),assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null};return console.log("[MessageReducer] 📊 After reset - messages count:",r.messages.length),r}case"seed":{const r=mi(t.payload.messages),o={...e,messages:r,assemblingId:null};return Object.prototype.hasOwnProperty.call(t.payload,"checkpointId")&&(o.lastCheckpointId=t.payload.checkpointId??null),Object.prototype.hasOwnProperty.call(t.payload,"checkpointNs")&&(o.lastCheckpointNs=t.payload.checkpointNs??null),console.log("[MessageReducer] seed action (REPLACE mode):",{incomingCount:t.payload.messages.length,sanitizedCount:r.length,previousCount:e.messages.length,checkpointId:o.lastCheckpointId}),o}case"prepend":{const r=mi(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 ic(e,t.payload.ev);case"batch":{const{events:r}=t.payload;return r.length?r.reduce((o,s)=>ic(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 sc(e=[]){const[t,n]=y.useReducer(Wg,{...Ug,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 ic(e,t){var n,r,o,s;if(t.type==="message_start"&&t.role==="assistant"){const i=t.id,a=qg(t.model);if(e.messages.some(d=>d.id===i)){const d=e.messagesStreamMeta??{},f={...d,[i]:d[i]??{lastSeq:t.seq??null,lastText:""}};return{...e,assemblingId:i,messagesStreamMeta:f}}const u={id:i,role:"assistant",name:a||void 0,model:t.model,createdAt:new Date().toISOString(),content:[]};return{...e,assemblingId:i,messages:[...e.messages,u]}}if(t.type==="message_delta"){const i=e.assemblingId??gi(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:dc(u.content)},h=t.seq??null;if(h!==null&&typeof h=="number"&&typeof f.lastSeq=="number"&&h<=f.lastSeq)return console.debug("[MessageReducer] skipping delta - seq <= lastSeq",{seq:h,lastSeq:f.lastSeq}),e;const{newParts:p,newMeta:w,changed:x}=Vg(u.content,t.delta,f,h);if(!x)return e;const g={...u,content:p},v=ac(a,l,g),b={...d,[i]:w};return{...e,messages:v,messagesStreamMeta:b}}if(t.type==="message_end"){const i=e.assemblingId??gi(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?cc(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=Kg(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??gi(e.messages),a={type:"interrupt",value:t.value,id:t.id};if(i)return{...e,assemblingId:null,messages:cc(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:lc(e.messages,l,f=>({...f,content:uc(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 mi(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 ac(e,t,n){return t<0||t>=e.length?e:[...e.slice(0,t),n,...e.slice(t+1)]}function gi(e){for(let t=e.length-1;t>=0;t--)if(e[t].role==="assistant")return e[t].id;return null}function lc(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 cc(e,t,n){return lc(e,t,r=>({...r,content:uc(r.content,n)}))}function uc(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=hc(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 dc(e){return!e||!e.length?"":e.filter(t=>t.type==="text").map(t=>t.text??"").join("")}function Vg(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??dc(e);let l="",u=e.slice();if(s){const f=hc(a,s);if(f===""?l="":f===s?l=s:l=f,l){const h=u[u.length-1];if((h==null?void 0:h.type)==="text"){const p=h.text??"",w={...h,text:p+l};u=[...u.slice(0,u.length-1),w]}else u=[...u,{type:"text",text:l}];o.lastText=a+l}else o.lastText=a}i.length&&(u=[...u,...i]);const d=!!(l||i.length);return{newParts:u,newMeta:o,changed:d}}function fc(e){return e.replace(/\s+/g," ").trim()}function hc(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=fc(e),o=fc(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 Kg(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 ac(e,r,s)}return e}function qg(e){if(!e)return null;const t=e.split("/");return t[t.length-1]||null}function pc(e={}){const t=y.useMemo(()=>Tn(e.baseUrl),[e.baseUrl]),n=e.streamPath??"/runs/stream",[r,o]=y.useState(e.token??null),s=y.useRef(e.headers??{}),i=e.credentials??"include",[a,l]=y.useState(!1),[u,d]=y.useState(null),[f,h]=y.useState(""),[p,w]=y.useState(null),[x,g]=y.useState(0),[v,b]=y.useState(!1),S=y.useRef(null),N=y.useRef(!0),C=y.useRef(0),k=y.useCallback(P=>{o(P)},[]),E=y.useCallback(()=>{var P;(P=S.current)==null||P.abort(),S.current=null,l(!1),b(!1),C.current=0,g(0)},[]),A=y.useCallback(()=>{h(""),w(null),d(null)},[]),j=y.useCallback((P,L,F)=>{S.current&&(S.current.abort(),S.current=null),l(!0),d(null),e.autoAppendAssistant!==!1&&h("");const V=new AbortController;return S.current=V,(async()=>{var Y,K,W,z,$,ue,D,ee;const M=fe=>{var ve;try{const be=JSON.parse(JSON.stringify(fe));return(ve=be==null?void 0:be.payload)!=null&&ve.files_info&&Array.isArray(be.payload.files_info)&&(be.payload.files_info=be.payload.files_info.map(ye=>({...ye,data:ye!=null&&ye.data?`<base64 ${String(ye.data).length} chars>`:ye==null?void 0:ye.data}))),be}catch{return fe}};try{let fe={};try{if(r)fe={Authorization:`Bearer ${r}`};else if(typeof window<"u"){const Be=window.__AUTH_TOKEN__,Ee=((Y=window.localStorage)==null?void 0:Y.getItem("authToken"))||null;let Ze=null;try{const ht=(K=window.localStorage)==null?void 0:K.getItem("chat-settings");ht&&(Ze=((W=JSON.parse(ht))==null?void 0:W.apiKey)||null)}catch{}const wt=Be||Ee||Ze||null;wt&&(fe={Authorization:`Bearer ${wt}`})}}catch{}console.debug("[use-chat] POST",t+n,M(P));const ve=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(!ve.ok||!ve.body){const De=await ve.text().catch(()=>"");throw console.debug("[use-chat] non-OK response",ve.status,De==null?void 0:De.slice(0,500)),new Error(`stream ${ve.status}${De?": "+De:""}`)}b(!0);const be=ve.body.getReader(),ye=new TextDecoder;let q="",O=[];C.current=0,g(0);let J=0,te=null;const G=()=>{if(O.length){const De=O.join("");O=[],N.current&&h(Be=>Be+De)}te=null},se=()=>{typeof window<"u"&&te==null&&(te=requestAnimationFrame(G))};let Ve=Date.now();const Je=setInterval(()=>{var De;if(Date.now()-Ve>6e4){const Be="Stream idle timeout";d(Be),V.abort(),(De=F==null?void 0:F.onError)==null||De.call(F,Be)}},5e3),nt=1024*1024;try{const De=ve.headers.get("X-Thread-Id")||ve.headers.get("x-thread-id"),Be=ve.headers.get("X-Thread-Created")||ve.headers.get("x-thread-created"),Ee=De??null,Ze=String(Be??"").toLowerCase()==="true";for((z=F==null?void 0:F.onOpen)==null||z.call(F,{threadId:Ee,created:Ze});;){const{value:wt,done:ht}=await be.read();if(ht)break;q+=ye.decode(wt,{stream:!0}),q.length>nt&&(q="",console.warn("Stream buffer reset: exceeded 1MB"));let Z;for(;(Z=q.indexOf(`
|
|
30
|
+
<%s key={someKey} {...props} />`,W,T,xe,T),jn[T+W]=!0}}return E===r?Fr(ht):Lr(ht),ht}}function be(E,z,te){return se(E,z,te,!0)}function Ue(E,z,te){return se(E,z,te,!1)}var ot=Ue,Pt=be;zr.Fragment=r,zr.jsx=ot,zr.jsxs=Pt}()),zr}process.env.NODE_ENV==="production"?ni.exports=um():ni.exports=dm();var c=ni.exports;function pl(e,t){return function(){return e.apply(t,arguments)}}const{toString:fm}=Object.prototype,{getPrototypeOf:ri}=Object,{iterator:So,toStringTag:ml}=Symbol,Co=(e=>t=>{const n=fm.call(t);return e[n]||(e[n]=n.slice(8,-1).toLowerCase())})(Object.create(null)),tn=e=>(e=e.toLowerCase(),t=>Co(t)===e),To=e=>t=>typeof t===e,{isArray:xr}=Array,vr=To("undefined");function Hr(e){return e!==null&&!vr(e)&&e.constructor!==null&&!vr(e.constructor)&&Ot(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const gl=tn("ArrayBuffer");function hm(e){let t;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?t=ArrayBuffer.isView(e):t=e&&e.buffer&&gl(e.buffer),t}const pm=To("string"),Ot=To("function"),xl=To("number"),Ur=e=>e!==null&&typeof e=="object",mm=e=>e===!0||e===!1,ko=e=>{if(Co(e)!=="object")return!1;const t=ri(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(ml in e)&&!(So in e)},gm=e=>{if(!Ur(e)||Hr(e))return!1;try{return Object.keys(e).length===0&&Object.getPrototypeOf(e)===Object.prototype}catch{return!1}},xm=tn("Date"),vm=tn("File"),wm=tn("Blob"),bm=tn("FileList"),ym=e=>Ur(e)&&Ot(e.pipe),Sm=e=>{let t;return e&&(typeof FormData=="function"&&e instanceof FormData||Ot(e.append)&&((t=Co(e))==="formdata"||t==="object"&&Ot(e.toString)&&e.toString()==="[object FormData]"))},Cm=tn("URLSearchParams"),[Tm,km,Em,Im]=["ReadableStream","Request","Response","Headers"].map(tn),Nm=e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function Wr(e,t,{allOwnKeys:n=!1}={}){if(e===null||typeof e>"u")return;let r,o;if(typeof e!="object"&&(e=[e]),xr(e))for(r=0,o=e.length;r<o;r++)t.call(null,e[r],r,e);else{if(Hr(e))return;const s=n?Object.getOwnPropertyNames(e):Object.keys(e),i=s.length;let a;for(r=0;r<i;r++)a=s[r],t.call(null,e[a],a,e)}}function vl(e,t){if(Hr(e))return null;t=t.toLowerCase();const n=Object.keys(e);let r=n.length,o;for(;r-- >0;)if(o=n[r],t===o.toLowerCase())return o;return null}const Jn=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global,wl=e=>!vr(e)&&e!==Jn;function oi(){const{caseless:e,skipUndefined:t}=wl(this)&&this||{},n={},r=(o,s)=>{const i=e&&vl(n,s)||s;ko(n[i])&&ko(o)?n[i]=oi(n[i],o):ko(o)?n[i]=oi({},o):xr(o)?n[i]=o.slice():(!t||!vr(o))&&(n[i]=o)};for(let o=0,s=arguments.length;o<s;o++)arguments[o]&&Wr(arguments[o],r);return n}const Am=(e,t,n,{allOwnKeys:r}={})=>(Wr(t,(o,s)=>{n&&Ot(o)?e[s]=pl(o,n):e[s]=o},{allOwnKeys:r}),e),_m=e=>(e.charCodeAt(0)===65279&&(e=e.slice(1)),e),jm=(e,t,n,r)=>{e.prototype=Object.create(t.prototype,r),e.prototype.constructor=e,Object.defineProperty(e,"super",{value:t.prototype}),n&&Object.assign(e.prototype,n)},Rm=(e,t,n,r)=>{let o,s,i;const a={};if(t=t||{},e==null)return t;do{for(o=Object.getOwnPropertyNames(e),s=o.length;s-- >0;)i=o[s],(!r||r(i,e,t))&&!a[i]&&(t[i]=e[i],a[i]=!0);e=n!==!1&&ri(e)}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},Pm=(e,t,n)=>{e=String(e),(n===void 0||n>e.length)&&(n=e.length),n-=t.length;const r=e.indexOf(t,n);return r!==-1&&r===n},Om=e=>{if(!e)return null;if(xr(e))return e;let t=e.length;if(!xl(t))return null;const n=new Array(t);for(;t-- >0;)n[t]=e[t];return n},Mm=(e=>t=>e&&t instanceof e)(typeof Uint8Array<"u"&&ri(Uint8Array)),Dm=(e,t)=>{const r=(e&&e[So]).call(e);let o;for(;(o=r.next())&&!o.done;){const s=o.value;t.call(e,s[0],s[1])}},Lm=(e,t)=>{let n;const r=[];for(;(n=e.exec(t))!==null;)r.push(n);return r},Fm=tn("HTMLFormElement"),$m=e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(n,r,o){return r.toUpperCase()+o}),bl=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),Bm=tn("RegExp"),yl=(e,t)=>{const n=Object.getOwnPropertyDescriptors(e),r={};Wr(n,(o,s)=>{let i;(i=t(o,s,e))!==!1&&(r[s]=i||o)}),Object.defineProperties(e,r)},zm=e=>{yl(e,(t,n)=>{if(Ot(e)&&["arguments","caller","callee"].indexOf(n)!==-1)return!1;const r=e[n];if(Ot(r)){if(t.enumerable=!1,"writable"in t){t.writable=!1;return}t.set||(t.set=()=>{throw Error("Can not rewrite read-only method '"+n+"'")})}})},Hm=(e,t)=>{const n={},r=o=>{o.forEach(s=>{n[s]=!0})};return xr(e)?r(e):r(String(e).split(t)),n},Um=()=>{},Wm=(e,t)=>e!=null&&Number.isFinite(e=+e)?e:t;function Vm(e){return!!(e&&Ot(e.append)&&e[ml]==="FormData"&&e[So])}const qm=e=>{const t=new Array(10),n=(r,o)=>{if(Ur(r)){if(t.indexOf(r)>=0)return;if(Hr(r))return r;if(!("toJSON"in r)){t[o]=r;const s=xr(r)?[]:{};return Wr(r,(i,a)=>{const l=n(i,o+1);!vr(l)&&(s[a]=l)}),t[o]=void 0,s}}return r};return n(e,0)},Km=tn("AsyncFunction"),Gm=e=>e&&(Ur(e)||Ot(e))&&Ot(e.then)&&Ot(e.catch),Sl=((e,t)=>e?setImmediate:t?((n,r)=>(Jn.addEventListener("message",({source:o,data:s})=>{o===Jn&&s===n&&r.length&&r.shift()()},!1),o=>{r.push(o),Jn.postMessage(n,"*")}))(`axios@${Math.random()}`,[]):n=>setTimeout(n))(typeof setImmediate=="function",Ot(Jn.postMessage)),Ym=typeof queueMicrotask<"u"?queueMicrotask.bind(Jn):typeof process<"u"&&process.nextTick||Sl,R={isArray:xr,isArrayBuffer:gl,isBuffer:Hr,isFormData:Sm,isArrayBufferView:hm,isString:pm,isNumber:xl,isBoolean:mm,isObject:Ur,isPlainObject:ko,isEmptyObject:gm,isReadableStream:Tm,isRequest:km,isResponse:Em,isHeaders:Im,isUndefined:vr,isDate:xm,isFile:vm,isBlob:wm,isRegExp:Bm,isFunction:Ot,isStream:ym,isURLSearchParams:Cm,isTypedArray:Mm,isFileList:bm,forEach:Wr,merge:oi,extend:Am,trim:Nm,stripBOM:_m,inherits:jm,toFlatObject:Rm,kindOf:Co,kindOfTest:tn,endsWith:Pm,toArray:Om,forEachEntry:Dm,matchAll:Lm,isHTMLForm:Fm,hasOwnProperty:bl,hasOwnProp:bl,reduceDescriptors:yl,freezeMethods:zm,toObjectSet:Hm,toCamelCase:$m,noop:Um,toFiniteNumber:Wm,findKey:vl,global:Jn,isContextDefined:wl,isSpecCompliantForm:Vm,toJSONObject:qm,isAsyncFn:Km,isThenable:Gm,setImmediate:Sl,asap:Ym,isIterable:e=>e!=null&&Ot(e[So])};function De(e,t,n,r,o){Error.call(this),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=new Error().stack,this.message=e,this.name="AxiosError",t&&(this.code=t),n&&(this.config=n),r&&(this.request=r),o&&(this.response=o,this.status=o.status?o.status:null)}R.inherits(De,Error,{toJSON:function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:R.toJSONObject(this.config),code:this.code,status:this.status}}});const Cl=De.prototype,Tl={};["ERR_BAD_OPTION_VALUE","ERR_BAD_OPTION","ECONNABORTED","ETIMEDOUT","ERR_NETWORK","ERR_FR_TOO_MANY_REDIRECTS","ERR_DEPRECATED","ERR_BAD_RESPONSE","ERR_BAD_REQUEST","ERR_CANCELED","ERR_NOT_SUPPORT","ERR_INVALID_URL"].forEach(e=>{Tl[e]={value:e}}),Object.defineProperties(De,Tl),Object.defineProperty(Cl,"isAxiosError",{value:!0}),De.from=(e,t,n,r,o,s)=>{const i=Object.create(Cl);R.toFlatObject(e,i,function(d){return d!==Error.prototype},u=>u!=="isAxiosError");const a=e&&e.message?e.message:"Error",l=t==null&&e?e.code:t;return De.call(i,a,l,n,r,o),e&&i.cause==null&&Object.defineProperty(i,"cause",{value:e,configurable:!0}),i.name=e&&e.name||"Error",s&&Object.assign(i,s),i};const Xm=null;function si(e){return R.isPlainObject(e)||R.isArray(e)}function kl(e){return R.endsWith(e,"[]")?e.slice(0,-2):e}function El(e,t,n){return e?e.concat(t).map(function(o,s){return o=kl(o),!n&&s?"["+o+"]":o}).join(n?".":""):t}function Jm(e){return R.isArray(e)&&!e.some(si)}const Zm=R.toFlatObject(R,{},null,function(t){return/^is[A-Z]/.test(t)});function Eo(e,t,n){if(!R.isObject(e))throw new TypeError("target must be an object");t=t||new FormData,n=R.toFlatObject(n,{metaTokens:!0,dots:!1,indexes:!1},!1,function(x,g){return!R.isUndefined(g[x])});const r=n.metaTokens,o=n.visitor||d,s=n.dots,i=n.indexes,l=(n.Blob||typeof Blob<"u"&&Blob)&&R.isSpecCompliantForm(t);if(!R.isFunction(o))throw new TypeError("visitor must be a function");function u(w){if(w===null)return"";if(R.isDate(w))return w.toISOString();if(R.isBoolean(w))return w.toString();if(!l&&R.isBlob(w))throw new De("Blob is not supported. Use a Buffer instead.");return R.isArrayBuffer(w)||R.isTypedArray(w)?l&&typeof Blob=="function"?new Blob([w]):Buffer.from(w):w}function d(w,x,g){let v=w;if(w&&!g&&typeof w=="object"){if(R.endsWith(x,"{}"))x=r?x:x.slice(0,-2),w=JSON.stringify(w);else if(R.isArray(w)&&Jm(w)||(R.isFileList(w)||R.endsWith(x,"[]"))&&(v=R.toArray(w)))return x=kl(x),v.forEach(function(S,N){!(R.isUndefined(S)||S===null)&&t.append(i===!0?El([x],N,s):i===null?x:x+"[]",u(S))}),!1}return si(w)?!0:(t.append(El(g,x,s),u(w)),!1)}const f=[],h=Object.assign(Zm,{defaultVisitor:d,convertValue:u,isVisitable:si});function p(w,x){if(!R.isUndefined(w)){if(f.indexOf(w)!==-1)throw Error("Circular reference detected in "+x.join("."));f.push(w),R.forEach(w,function(v,b){(!(R.isUndefined(v)||v===null)&&o.call(t,v,R.isString(b)?b.trim():b,x,h))===!0&&p(v,x?x.concat(b):[b])}),f.pop()}}if(!R.isObject(e))throw new TypeError("data must be an object");return p(e),t}function Il(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,function(r){return t[r]})}function ii(e,t){this._pairs=[],e&&Eo(e,this,t)}const Nl=ii.prototype;Nl.append=function(t,n){this._pairs.push([t,n])},Nl.toString=function(t){const n=t?function(r){return t.call(this,r,Il)}:Il;return this._pairs.map(function(o){return n(o[0])+"="+n(o[1])},"").join("&")};function Qm(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+")}function Al(e,t,n){if(!t)return e;const r=n&&n.encode||Qm;R.isFunction(n)&&(n={serialize:n});const o=n&&n.serialize;let s;if(o?s=o(t,n):s=R.isURLSearchParams(t)?t.toString():new ii(t,n).toString(r),s){const i=e.indexOf("#");i!==-1&&(e=e.slice(0,i)),e+=(e.indexOf("?")===-1?"?":"&")+s}return e}class _l{constructor(){this.handlers=[]}use(t,n,r){return this.handlers.push({fulfilled:t,rejected:n,synchronous:r?r.synchronous:!1,runWhen:r?r.runWhen:null}),this.handlers.length-1}eject(t){this.handlers[t]&&(this.handlers[t]=null)}clear(){this.handlers&&(this.handlers=[])}forEach(t){R.forEach(this.handlers,function(r){r!==null&&t(r)})}}const jl={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},eg={isBrowser:!0,classes:{URLSearchParams:typeof URLSearchParams<"u"?URLSearchParams:ii,FormData:typeof FormData<"u"?FormData:null,Blob:typeof Blob<"u"?Blob:null},protocols:["http","https","file","blob","url","data"]},ai=typeof window<"u"&&typeof document<"u",li=typeof navigator=="object"&&navigator||void 0,tg=ai&&(!li||["ReactNative","NativeScript","NS"].indexOf(li.product)<0),ng=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function",rg=ai&&window.location.href||"http://localhost",kt={...Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv:ai,hasStandardBrowserEnv:tg,hasStandardBrowserWebWorkerEnv:ng,navigator:li,origin:rg},Symbol.toStringTag,{value:"Module"})),...eg};function og(e,t){return Eo(e,new kt.classes.URLSearchParams,{visitor:function(n,r,o,s){return kt.isNode&&R.isBuffer(n)?(this.append(r,n.toString("base64")),!1):s.defaultVisitor.apply(this,arguments)},...t})}function sg(e){return R.matchAll(/\w+|\[(\w*)]/g,e).map(t=>t[0]==="[]"?"":t[1]||t[0])}function ig(e){const t={},n=Object.keys(e);let r;const o=n.length;let s;for(r=0;r<o;r++)s=n[r],t[s]=e[s];return t}function Rl(e){function t(n,r,o,s){let i=n[s++];if(i==="__proto__")return!0;const a=Number.isFinite(+i),l=s>=n.length;return i=!i&&R.isArray(o)?o.length:i,l?(R.hasOwnProp(o,i)?o[i]=[o[i],r]:o[i]=r,!a):((!o[i]||!R.isObject(o[i]))&&(o[i]=[]),t(n,r,o[i],s)&&R.isArray(o[i])&&(o[i]=ig(o[i])),!a)}if(R.isFormData(e)&&R.isFunction(e.entries)){const n={};return R.forEachEntry(e,(r,o)=>{t(sg(r),o,n,0)}),n}return null}function ag(e,t,n){if(R.isString(e))try{return(t||JSON.parse)(e),R.trim(e)}catch(r){if(r.name!=="SyntaxError")throw r}return(n||JSON.stringify)(e)}const Vr={transitional:jl,adapter:["xhr","http","fetch"],transformRequest:[function(t,n){const r=n.getContentType()||"",o=r.indexOf("application/json")>-1,s=R.isObject(t);if(s&&R.isHTMLForm(t)&&(t=new FormData(t)),R.isFormData(t))return o?JSON.stringify(Rl(t)):t;if(R.isArrayBuffer(t)||R.isBuffer(t)||R.isStream(t)||R.isFile(t)||R.isBlob(t)||R.isReadableStream(t))return t;if(R.isArrayBufferView(t))return t.buffer;if(R.isURLSearchParams(t))return n.setContentType("application/x-www-form-urlencoded;charset=utf-8",!1),t.toString();let a;if(s){if(r.indexOf("application/x-www-form-urlencoded")>-1)return og(t,this.formSerializer).toString();if((a=R.isFileList(t))||r.indexOf("multipart/form-data")>-1){const l=this.env&&this.env.FormData;return Eo(a?{"files[]":t}:t,l&&new l,this.formSerializer)}}return s||o?(n.setContentType("application/json",!1),ag(t)):t}],transformResponse:[function(t){const n=this.transitional||Vr.transitional,r=n&&n.forcedJSONParsing,o=this.responseType==="json";if(R.isResponse(t)||R.isReadableStream(t))return t;if(t&&R.isString(t)&&(r&&!this.responseType||o)){const i=!(n&&n.silentJSONParsing)&&o;try{return JSON.parse(t,this.parseReviver)}catch(a){if(i)throw a.name==="SyntaxError"?De.from(a,De.ERR_BAD_RESPONSE,this,null,this.response):a}}return t}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:kt.classes.FormData,Blob:kt.classes.Blob},validateStatus:function(t){return t>=200&&t<300},headers:{common:{Accept:"application/json, text/plain, */*","Content-Type":void 0}}};R.forEach(["delete","get","head","post","put","patch"],e=>{Vr.headers[e]={}});const lg=R.toObjectSet(["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"]),cg=e=>{const t={};let n,r,o;return e&&e.split(`
|
|
31
|
+
`).forEach(function(i){o=i.indexOf(":"),n=i.substring(0,o).trim().toLowerCase(),r=i.substring(o+1).trim(),!(!n||t[n]&&lg[n])&&(n==="set-cookie"?t[n]?t[n].push(r):t[n]=[r]:t[n]=t[n]?t[n]+", "+r:r)}),t},Pl=Symbol("internals");function qr(e){return e&&String(e).trim().toLowerCase()}function Io(e){return e===!1||e==null?e:R.isArray(e)?e.map(Io):String(e)}function ug(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 dg=e=>/^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(e.trim());function ci(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 fg(e){return e.trim().toLowerCase().replace(/([a-z\d])(\w*)/g,(t,n,r)=>n.toUpperCase()+r)}function hg(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 Mt=class{constructor(t){t&&this.set(t)}set(t,n,r){const o=this;function s(a,l,u){const d=qr(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]=Io(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())&&!dg(t))i(cg(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=qr(t),t){const r=R.findKey(this,t);if(r){const o=this[r];if(!n)return o;if(n===!0)return ug(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=qr(t),t){const r=R.findKey(this,t);return!!(r&&this[r]!==void 0&&(!n||ci(this,this[r],r,n)))}return!1}delete(t,n){const r=this;let o=!1;function s(i){if(i=qr(i),i){const a=R.findKey(r,i);a&&(!n||ci(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||ci(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]=Io(o),delete n[s];return}const a=t?fg(s):String(s).trim();a!==s&&delete n[s],n[a]=Io(o),r[a]=!0}),this}concat(...t){return this.constructor.concat(this,...t)}toJSON(t){const n=Object.create(null);return 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[Pl]=this[Pl]={accessors:{}}).accessors,o=this.prototype;function s(i){const a=qr(i);r[a]||(hg(o,i),r[a]=!0)}return R.isArray(t)?t.forEach(s):s(t),this}};Mt.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),R.reduceDescriptors(Mt.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(r){this[n]=r}}}),R.freezeMethods(Mt);function ui(e,t){const n=this||Vr,r=t||n,o=Mt.from(r.headers);let s=r.data;return R.forEach(e,function(a){s=a.call(n,s,o.normalize(),t?t.status:void 0)}),o.normalize(),s}function Ol(e){return!!(e&&e.__CANCEL__)}function wr(e,t,n){De.call(this,e??"canceled",De.ERR_CANCELED,t,n),this.name="CanceledError"}R.inherits(wr,De,{__CANCEL__:!0});function Ml(e,t,n){const r=n.config.validateStatus;!n.status||!r||r(n.status)?e(n):t(new De("Request failed with status code "+n.status,[De.ERR_BAD_REQUEST,De.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n))}function pg(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function mg(e,t){e=e||10;const n=new Array(e),r=new Array(e);let o=0,s=0,i;return t=t!==void 0?t:1e3,function(l){const u=Date.now(),d=r[s];i||(i=u),n[o]=l,r[o]=u;let f=s,h=0;for(;f!==o;)h+=n[f++],f=f%e;if(o=(o+1)%e,o===s&&(s=(s+1)%e),u-i<t)return;const p=d&&u-d;return p?Math.round(h*1e3/p):void 0}}function gg(e,t){let n=0,r=1e3/t,o,s;const i=(u,d=Date.now())=>{n=d,o=null,s&&(clearTimeout(s),s=null),e(...u)};return[(...u)=>{const d=Date.now(),f=d-n;f>=r?i(u,d):(o=u,s||(s=setTimeout(()=>{s=null,i(o)},r-f)))},()=>o&&i(o)]}const No=(e,t,n=3)=>{let r=0;const o=mg(50,250);return gg(s=>{const i=s.loaded,a=s.lengthComputable?s.total:void 0,l=i-r,u=o(l),d=i<=a;r=i;const f={loaded:i,total:a,progress:a?i/a:void 0,bytes:l,rate:u||void 0,estimated:u&&a&&d?(a-i)/u:void 0,event:s,lengthComputable:a!=null,[t?"download":"upload"]:!0};e(f)},n)},Dl=(e,t)=>{const n=e!=null;return[r=>t[0]({lengthComputable:n,total:e,loaded:r}),t[1]]},Ll=e=>(...t)=>R.asap(()=>e(...t)),xg=kt.hasStandardBrowserEnv?((e,t)=>n=>(n=new URL(n,kt.origin),e.protocol===n.protocol&&e.host===n.host&&(t||e.port===n.port)))(new URL(kt.origin),kt.navigator&&/(msie|trident)/i.test(kt.navigator.userAgent)):()=>!0,vg=kt.hasStandardBrowserEnv?{write(e,t,n,r,o,s){const i=[e+"="+encodeURIComponent(t)];R.isNumber(n)&&i.push("expires="+new Date(n).toGMTString()),R.isString(r)&&i.push("path="+r),R.isString(o)&&i.push("domain="+o),s===!0&&i.push("secure"),document.cookie=i.join("; ")},read(e){const t=document.cookie.match(new RegExp("(^|;\\s*)("+e+")=([^;]*)"));return t?decodeURIComponent(t[3]):null},remove(e){this.write(e,"",Date.now()-864e5)}}:{write(){},read(){return null},remove(){}};function wg(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function bg(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function Fl(e,t,n){let r=!wg(t);return e&&(r||n==!1)?bg(e,t):t}const $l=e=>e instanceof Mt?{...e}:e;function Zn(e,t){t=t||{};const n={};function r(u,d,f,h){return R.isPlainObject(u)&&R.isPlainObject(d)?R.merge.call({caseless:h},u,d):R.isPlainObject(d)?R.merge({},d):R.isArray(d)?d.slice():d}function o(u,d,f,h){if(R.isUndefined(d)){if(!R.isUndefined(u))return r(void 0,u,f,h)}else return r(u,d,f,h)}function s(u,d){if(!R.isUndefined(d))return r(void 0,d)}function i(u,d){if(R.isUndefined(d)){if(!R.isUndefined(u))return r(void 0,u)}else return r(void 0,d)}function a(u,d,f){if(f in t)return r(u,d);if(f in e)return r(void 0,u)}const l={url:s,method:s,data:s,baseURL:i,transformRequest:i,transformResponse:i,paramsSerializer:i,timeout:i,timeoutMessage:i,withCredentials:i,withXSRFToken:i,adapter:i,responseType:i,xsrfCookieName:i,xsrfHeaderName:i,onUploadProgress:i,onDownloadProgress:i,decompress:i,maxContentLength:i,maxBodyLength:i,beforeRedirect:i,transport:i,httpAgent:i,httpsAgent:i,cancelToken:i,socketPath:i,responseEncoding:i,validateStatus:a,headers:(u,d,f)=>o($l(u),$l(d),f,!0)};return R.forEach(Object.keys({...e,...t}),function(d){const f=l[d]||o,h=f(e[d],t[d],d);R.isUndefined(h)&&f!==a||(n[d]=h)}),n}const Bl=e=>{const t=Zn({},e);let{data:n,withXSRFToken:r,xsrfHeaderName:o,xsrfCookieName:s,headers:i,auth:a}=t;if(t.headers=i=Mt.from(i),t.url=Al(Fl(t.baseURL,t.url,t.allowAbsoluteUrls),e.params,e.paramsSerializer),a&&i.set("Authorization","Basic "+btoa((a.username||"")+":"+(a.password?unescape(encodeURIComponent(a.password)):""))),R.isFormData(n)){if(kt.hasStandardBrowserEnv||kt.hasStandardBrowserWebWorkerEnv)i.setContentType(void 0);else if(R.isFunction(n.getHeaders)){const l=n.getHeaders(),u=["content-type","content-length"];Object.entries(l).forEach(([d,f])=>{u.includes(d.toLowerCase())&&i.set(d,f)})}}if(kt.hasStandardBrowserEnv&&(r&&R.isFunction(r)&&(r=r(t)),r||r!==!1&&xg(t.url))){const l=o&&s&&vg.read(s);l&&i.set(o,l)}return t},yg=typeof XMLHttpRequest<"u"&&function(e){return new Promise(function(n,r){const o=Bl(e);let s=o.data;const i=Mt.from(o.headers).normalize();let{responseType:a,onUploadProgress:l,onDownloadProgress:u}=o,d,f,h,p,w;function x(){p&&p(),w&&w(),o.cancelToken&&o.cancelToken.unsubscribe(d),o.signal&&o.signal.removeEventListener("abort",d)}let g=new XMLHttpRequest;g.open(o.method.toUpperCase(),o.url,!0),g.timeout=o.timeout;function v(){if(!g)return;const S=Mt.from("getAllResponseHeaders"in g&&g.getAllResponseHeaders()),C={data:!a||a==="text"||a==="json"?g.responseText:g.response,status:g.status,statusText:g.statusText,headers:S,config:e,request:g};Ml(function(I){n(I),x()},function(I){r(I),x()},C),g=null}"onloadend"in g?g.onloadend=v:g.onreadystatechange=function(){!g||g.readyState!==4||g.status===0&&!(g.responseURL&&g.responseURL.indexOf("file:")===0)||setTimeout(v)},g.onabort=function(){g&&(r(new De("Request aborted",De.ECONNABORTED,e,g)),g=null)},g.onerror=function(N){const C=N&&N.message?N.message:"Network Error",k=new De(C,De.ERR_NETWORK,e,g);k.event=N||null,r(k),g=null},g.ontimeout=function(){let N=o.timeout?"timeout of "+o.timeout+"ms exceeded":"timeout exceeded";const C=o.transitional||jl;o.timeoutErrorMessage&&(N=o.timeoutErrorMessage),r(new De(N,C.clarifyTimeoutError?De.ETIMEDOUT:De.ECONNABORTED,e,g)),g=null},s===void 0&&i.setContentType(null),"setRequestHeader"in g&&R.forEach(i.toJSON(),function(N,C){g.setRequestHeader(C,N)}),R.isUndefined(o.withCredentials)||(g.withCredentials=!!o.withCredentials),a&&a!=="json"&&(g.responseType=o.responseType),u&&([h,w]=No(u,!0),g.addEventListener("progress",h)),l&&g.upload&&([f,p]=No(l),g.upload.addEventListener("progress",f),g.upload.addEventListener("loadend",p)),(o.cancelToken||o.signal)&&(d=S=>{g&&(r(!S||S.type?new wr(null,e,g):S),g.abort(),g=null)},o.cancelToken&&o.cancelToken.subscribe(d),o.signal&&(o.signal.aborted?d():o.signal.addEventListener("abort",d)));const b=pg(o.url);if(b&&kt.protocols.indexOf(b)===-1){r(new De("Unsupported protocol "+b+":",De.ERR_BAD_REQUEST,e));return}g.send(s||null)})},Sg=(e,t)=>{const{length:n}=e=e?e.filter(Boolean):[];if(t||n){let r=new AbortController,o;const s=function(u){if(!o){o=!0,a();const d=u instanceof Error?u:this.reason;r.abort(d instanceof De?d:new wr(d instanceof Error?d.message:d))}};let i=t&&setTimeout(()=>{i=null,s(new De(`timeout ${t} of ms exceeded`,De.ETIMEDOUT))},t);const a=()=>{e&&(i&&clearTimeout(i),i=null,e.forEach(u=>{u.unsubscribe?u.unsubscribe(s):u.removeEventListener("abort",s)}),e=null)};e.forEach(u=>u.addEventListener("abort",s));const{signal:l}=r;return l.unsubscribe=()=>R.asap(a),l}},Cg=function*(e,t){let n=e.byteLength;if(n<t){yield e;return}let r=0,o;for(;r<n;)o=r+t,yield e.slice(r,o),r=o},Tg=async function*(e,t){for await(const n of kg(e))yield*Cg(n,t)},kg=async function*(e){if(e[Symbol.asyncIterator]){yield*e;return}const t=e.getReader();try{for(;;){const{done:n,value:r}=await t.read();if(n)break;yield r}}finally{await t.cancel()}},zl=(e,t,n,r)=>{const o=Tg(e,t);let s=0,i,a=l=>{i||(i=!0,r&&r(l))};return new ReadableStream({async pull(l){try{const{done:u,value:d}=await o.next();if(u){a(),l.close();return}let f=d.byteLength;if(n){let h=s+=f;n(h)}l.enqueue(new Uint8Array(d))}catch(u){throw a(u),u}},cancel(l){return a(l),o.return()}},{highWaterMark:2})},Hl=64*1024,{isFunction:Ao}=R,Eg=(({Request:e,Response:t})=>({Request:e,Response:t}))(R.global),{ReadableStream:Ul,TextEncoder:Wl}=R.global,Vl=(e,...t)=>{try{return!!e(...t)}catch{return!1}},Ig=e=>{e=R.merge.call({skipUndefined:!0},Eg,e);const{fetch:t,Request:n,Response:r}=e,o=t?Ao(t):typeof fetch=="function",s=Ao(n),i=Ao(r);if(!o)return!1;const a=o&&Ao(Ul),l=o&&(typeof Wl=="function"?(w=>x=>w.encode(x))(new Wl):async w=>new Uint8Array(await new n(w).arrayBuffer())),u=s&&a&&Vl(()=>{let w=!1;const x=new n(kt.origin,{body:new Ul,method:"POST",get duplex(){return w=!0,"half"}}).headers.has("Content-Type");return w&&!x}),d=i&&a&&Vl(()=>R.isReadableStream(new r("").body)),f={stream:d&&(w=>w.body)};o&&["text","arrayBuffer","blob","formData","stream"].forEach(w=>{!f[w]&&(f[w]=(x,g)=>{let v=x&&x[w];if(v)return v.call(x);throw new De(`Response type '${w}' is not supported`,De.ERR_NOT_SUPPORT,g)})});const h=async w=>{if(w==null)return 0;if(R.isBlob(w))return w.size;if(R.isSpecCompliantForm(w))return(await new n(kt.origin,{method:"POST",body:w}).arrayBuffer()).byteLength;if(R.isArrayBufferView(w)||R.isArrayBuffer(w))return w.byteLength;if(R.isURLSearchParams(w)&&(w=w+""),R.isString(w))return(await l(w)).byteLength},p=async(w,x)=>{const g=R.toFiniteNumber(w.getContentLength());return g??h(x)};return async w=>{let{url:x,method:g,data:v,signal:b,cancelToken:S,timeout:N,onDownloadProgress:C,onUploadProgress:k,responseType:I,headers:A,withCredentials:j="same-origin",fetchOptions:P}=Bl(w),L=t||fetch;I=I?(I+"").toLowerCase():"text";let F=Sg([b,S&&S.toAbortSignal()],N),V=null;const M=F&&F.unsubscribe&&(()=>{F.unsubscribe()});let G;try{if(k&&u&&g!=="get"&&g!=="head"&&(G=await p(A,v))!==0){let D=new n(x,{method:"POST",body:v,duplex:"half"}),Q;if(R.isFormData(v)&&(Q=D.headers.get("content-type"))&&A.setContentType(Q),D.body){const[de,we]=Dl(G,No(Ll(k)));v=zl(D.body,Hl,de,we)}}R.isString(j)||(j=j?"include":"omit");const q=s&&"credentials"in n.prototype,U={...P,signal:F,method:g.toUpperCase(),headers:A.normalize().toJSON(),body:v,duplex:"half",credentials:q?j:void 0};V=s&&new n(x,U);let B=await(s?L(V,P):L(x,U));const $=d&&(I==="stream"||I==="response");if(d&&(C||$&&M)){const D={};["status","statusText","headers"].forEach(ye=>{D[ye]=B[ye]});const Q=R.toFiniteNumber(B.headers.get("content-length")),[de,we]=C&&Dl(Q,No(Ll(C),!0))||[];B=new r(zl(B.body,Hl,de,()=>{we&&we(),M&&M()}),D)}I=I||"text";let ce=await f[R.findKey(f,I)||"text"](B,w);return!$&&M&&M(),await new Promise((D,Q)=>{Ml(D,Q,{data:ce,headers:Mt.from(B.headers),status:B.status,statusText:B.statusText,config:w,request:V})})}catch(q){throw M&&M(),q&&q.name==="TypeError"&&/Load failed|fetch/i.test(q.message)?Object.assign(new De("Network Error",De.ERR_NETWORK,w,V),{cause:q.cause||q}):De.from(q,q&&q.code,w,V)}}},Ng=new Map,ql=e=>{let t=e?e.env:{};const{fetch:n,Request:r,Response:o}=t,s=[r,o,n];let i=s.length,a=i,l,u,d=Ng;for(;a--;)l=s[a],u=d.get(l),u===void 0&&d.set(l,u=a?new Map:Ig(t)),d=u;return u};ql();const di={http:Xm,xhr:yg,fetch:{get:ql}};R.forEach(di,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const Kl=e=>`- ${e}`,Ag=e=>R.isFunction(e)||e===null||e===!1,Gl={getAdapter:(e,t)=>{e=R.isArray(e)?e:[e];const{length:n}=e;let r,o;const s={};for(let i=0;i<n;i++){r=e[i];let a;if(o=r,!Ag(r)&&(o=di[(a=String(r)).toLowerCase()],o===void 0))throw new De(`Unknown adapter '${a}'`);if(o&&(R.isFunction(o)||(o=o.get(t))))break;s[a||"#"+i]=o}if(!o){const i=Object.entries(s).map(([l,u])=>`adapter ${l} `+(u===!1?"is not supported by the environment":"is not available in the build"));let a=n?i.length>1?`since :
|
|
33
|
+
`+i.map(Kl).join(`
|
|
34
|
+
`):" "+Kl(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:di};function fi(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new wr(null,e)}function Yl(e){return fi(e),e.headers=Mt.from(e.headers),e.data=ui.call(e,e.transformRequest),["post","put","patch"].indexOf(e.method)!==-1&&e.headers.setContentType("application/x-www-form-urlencoded",!1),Gl.getAdapter(e.adapter||Vr.adapter,e)(e).then(function(r){return fi(e),r.data=ui.call(e,e.transformResponse,r),r.headers=Mt.from(r.headers),r},function(r){return Ol(r)||(fi(e),r&&r.response&&(r.response.data=ui.call(e,e.transformResponse,r.response),r.response.headers=Mt.from(r.response.headers))),Promise.reject(r)})}const Xl="1.12.2",_o={};["object","boolean","number","function","string","symbol"].forEach((e,t)=>{_o[e]=function(r){return typeof r===e||"a"+(t<1?"n ":" ")+e}});const Jl={};_o.transitional=function(t,n,r){function o(s,i){return"[Axios v"+Xl+"] 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&&!Jl[i]&&(Jl[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}},_o.spelling=function(t){return(n,r)=>(console.warn(`${r} is likely a misspelling of ${t}`),!0)};function _g(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 jo={assertOptions:_g,validators:_o},hn=jo.validators;let Qn=class{constructor(t){this.defaults=t||{},this.interceptors={request:new _l,response:new _l}}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=Zn(this.defaults,n);const{transitional:r,paramsSerializer:o,headers:s}=n;r!==void 0&&jo.assertOptions(r,{silentJSONParsing:hn.transitional(hn.boolean),forcedJSONParsing:hn.transitional(hn.boolean),clarifyTimeoutError:hn.transitional(hn.boolean)},!1),o!=null&&(R.isFunction(o)?n.paramsSerializer={serialize:o}:jo.assertOptions(o,{encode:hn.function,serialize:hn.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),jo.assertOptions(n,{baseUrl:hn.spelling("baseURL"),withXsrfToken:hn.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let i=s&&R.merge(s.common,s[n.method]);s&&R.forEach(["delete","get","head","post","put","patch","common"],w=>{delete s[w]}),n.headers=Mt.concat(i,s);const a=[];let l=!0;this.interceptors.request.forEach(function(x){typeof x.runWhen=="function"&&x.runWhen(n)===!1||(l=l&&x.synchronous,a.unshift(x.fulfilled,x.rejected))});const u=[];this.interceptors.response.forEach(function(x){u.push(x.fulfilled,x.rejected)});let d,f=0,h;if(!l){const w=[Yl.bind(this),void 0];for(w.unshift(...a),w.push(...u),h=w.length,d=Promise.resolve(n);f<h;)d=d.then(w[f++],w[f++]);return d}h=a.length;let p=n;for(;f<h;){const w=a[f++],x=a[f++];try{p=w(p)}catch(g){x.call(this,g);break}}try{d=Yl.call(this,p)}catch(w){return Promise.reject(w)}for(f=0,h=u.length;f<h;)d=d.then(u[f++],u[f++]);return d}getUri(t){t=Zn(this.defaults,t);const n=Fl(t.baseURL,t.url,t.allowAbsoluteUrls);return Al(n,t.params,t.paramsSerializer)}};R.forEach(["delete","get","head","options"],function(t){Qn.prototype[t]=function(n,r){return this.request(Zn(r||{},{method:t,url:n,data:(r||{}).data}))}}),R.forEach(["post","put","patch"],function(t){function n(r){return function(s,i,a){return this.request(Zn(a||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:s,data:i}))}}Qn.prototype[t]=n(),Qn.prototype[t+"Form"]=n(!0)});let jg=class am{constructor(t){if(typeof t!="function")throw new TypeError("executor must be a function.");let n;this.promise=new Promise(function(s){n=s});const r=this;this.promise.then(o=>{if(!r._listeners)return;let s=r._listeners.length;for(;s-- >0;)r._listeners[s](o);r._listeners=null}),this.promise.then=o=>{let s;const i=new Promise(a=>{r.subscribe(a),s=a}).then(o);return i.cancel=function(){r.unsubscribe(s)},i},t(function(s,i,a){r.reason||(r.reason=new wr(s,i,a),n(r.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(t){if(this.reason){t(this.reason);return}this._listeners?this._listeners.push(t):this._listeners=[t]}unsubscribe(t){if(!this._listeners)return;const n=this._listeners.indexOf(t);n!==-1&&this._listeners.splice(n,1)}toAbortSignal(){const t=new AbortController,n=r=>{t.abort(r)};return this.subscribe(n),t.signal.unsubscribe=()=>this.unsubscribe(n),t.signal}static source(){let t;return{token:new am(function(o){t=o}),cancel:t}}};function Rg(e){return function(n){return e.apply(null,n)}}function Pg(e){return R.isObject(e)&&e.isAxiosError===!0}const hi={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511};Object.entries(hi).forEach(([e,t])=>{hi[t]=e});function Zl(e){const t=new Qn(e),n=pl(Qn.prototype.request,t);return R.extend(n,Qn.prototype,t,{allOwnKeys:!0}),R.extend(n,t,null,{allOwnKeys:!0}),n.create=function(o){return Zl(Zn(e,o))},n}const pt=Zl(Vr);pt.Axios=Qn,pt.CanceledError=wr,pt.CancelToken=jg,pt.isCancel=Ol,pt.VERSION=Xl,pt.toFormData=Eo,pt.AxiosError=De,pt.Cancel=pt.CanceledError,pt.all=function(t){return Promise.all(t)},pt.spread=Rg,pt.isAxiosError=Pg,pt.mergeConfig=Zn,pt.AxiosHeaders=Mt,pt.formToJSON=e=>Rl(R.isHTMLForm(e)?new FormData(e):e),pt.getAdapter=Gl.getAdapter,pt.HttpStatusCode=hi,pt.default=pt;const{Axios:xT,AxiosError:vT,CanceledError:wT,isCancel:bT,CancelToken:yT,VERSION:ST,all:CT,Cancel:TT,isAxiosError:kT,spread:ET,toFormData:IT,AxiosHeaders:NT,HttpStatusCode:AT,formToJSON:_T,getAdapter:jT,mergeConfig:RT}=pt,Ql=typeof window<"u"?window.__API_BASE_URL__:void 0,ec=Ql?En(Ql):void 0;function En(e){const n=(e!=null&&e.trim()?e.trim():"/api/chat").replace(/\/+$/,"");return n?n.endsWith("/chat")?n:`${n}/chat`:"/api/chat"}let Ro=null;const pi=new Set;function tc(){return Ro}function mi(e){Ro=e,pi.forEach(t=>t(e))}function nc(e){return pi.add(e),()=>pi.delete(e)}const Vt=pt.create({...ec?{baseURL:ec}:{},timeout:3e4,withCredentials:!0});Vt.interceptors.request.use(e=>(Ro&&(e.headers.Authorization=`Bearer ${Ro}`),e)),Vt.interceptors.response.use(e=>e,e=>Promise.reject(e));async function nn(e,t){return Vt.defaults.baseURL?(await Vt.get(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}async function gi(e,t,n){return Vt.defaults.baseURL?(await Vt.post(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function rc(e,t,n){return Vt.defaults.baseURL?(await Vt.put(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function oc(e,t){return Vt.defaults.baseURL?(await Vt.delete(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}function rn(e){return e&&typeof e=="object"&&"data"in e?e.data:e}class sc{get baseUrl(){const t=Vt.defaults.baseURL;return t?En(String(t)):""}updateConfig(t){t.baseUrl&&(Vt.defaults.baseURL=En(String(t.baseUrl))),t.authToken!==void 0&&mi(t.authToken)}getAuthToken(){return tc()}setAuthToken(t){mi(t)}onTokenChange(t){return nc(t)}async listThreads(){const t=await nn("/threads"),n=rn(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async createThread(t){const r=await gi("/threads",t?{title:t}:void 0);return rn(r)}async updateThread(t,n){const r=await rc(`/threads/${t}`,{title:n});return rn(r)}async deleteThread(t){const n=await oc(`/threads/${t}`);return rn(n)}async threadInfo(t){const n=await nn(`/threads/${t}/info`);return rn(n)}async listAgents(){const t=await nn("/agents"),n=rn(t);return(n==null?void 0:n.items)??[]}async getAgent(t){const n=await nn(`/agents/${t}`);return rn(n)}async getAgentSchema(t){const n=await nn(`/agents/${t}/schema`);return rn(n)}async getMessages(t){const n=await nn(`/threads/${t.threadId}/messages`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs,limit:t.limit,before_id:t.beforeId??void 0}});return rn(n)}async getStateHistory(t){const n=await nn(`/threads/${t.threadId}/state/history`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return rn(n)}resumeStream(t){}async resume(t){const n=await gi("/runs/resume",{thread_id:t.threadId,value:t.value});return rn(n)}}const Pn=new sc,ic=y.createContext(null);function Og({children:e,apiConfig:t}){const n=Pn;if(t){const o=n.baseUrl,s=n.getAuthToken();t.baseUrl&&t.baseUrl!==o&&n.updateConfig({baseUrl:t.baseUrl}),t.apiKey!==void 0&&t.apiKey!==s&&n.updateConfig({authToken:t.apiKey})}const r={token:n.getAuthToken(),setToken:o=>n.setAuthToken(o),api:n,baseUrl:n.baseUrl};return c.jsx(ic.Provider,{value:r,children:e})}function xi(){const e=y.useContext(ic);if(!e)throw new Error("useApi must be used within ApiProvider");return e}async function Mg(e){return await new Promise((t,n)=>{const r=new FileReader;r.onload=()=>{try{const o=r.result,s=new Uint8Array(o);let i="";const a=s.byteLength;for(let l=0;l<a;l++)i+=String.fromCharCode(s[l]);t(btoa(i))}catch(o){n(o)}},r.onerror=o=>n(o),r.readAsArrayBuffer(e)})}async function Dg(e,t=[],n,r,o,s){const i=[],a=[];for(const l of t)try{const u=await Mg(l);a.push({filename:l.name,data:u,mime_type:l.type||"application/octet-stream"})}catch{}return{contentParts:i,filesInfo:a}}const Lg={human:"user",user:"user",ai:"assistant",assistant:"assistant",tool:"tool",function:"tool",system:"system"};function vi(e){if(!e||typeof e!="object")return!1;const t=e;return"values"in t&&"config"in t&&typeof t.values=="object"&&t.values!==null&&typeof t.config=="object"&&t.config!==null}function wi(e){const t=Array.isArray(e==null?void 0:e.checkpoints)?(e==null?void 0:e.checkpoints)??[]:e!=null&&e.checkpoints?Object.values(e.checkpoints):[],n=(e==null?void 0:e.threadId)??"",r=t[0];if(!vi(r))return{payload:{threadId:n,checkpointId:void 0,checkpointNs:void 0,messages:[],hasMore:!1,nextCursor:null,nextCursorNs:null},checkpoints:[],interrupt:null};const o=Fg(t),s=ac(r,0);return{payload:{threadId:n,checkpointId:(s==null?void 0:s.checkpointId)??void 0,checkpointNs:(s==null?void 0:s.checkpointNs)??void 0,messages:(s==null?void 0:s.messages)??[],hasMore:!!(s!=null&&s.nextCursor),nextCursor:(s==null?void 0:s.nextCursor)??null,nextCursorNs:(s==null?void 0:s.nextCursorNs)??null},checkpoints:o,interrupt:(s==null?void 0:s.interrupt)??null}}function ac(e,t){var f,h;if(!vi(e))return null;const n=e.values??{},o=(Array.isArray(n==null?void 0:n.messages)?n.messages:[]).map((p,w)=>zg(p,w)).filter(p=>!!p),s=qt((f=e.config)==null?void 0:f.configurable),i=bt(s,["checkpoint_id","checkpointId"]),a=bt(s,["checkpoint_ns","checkpointNs"]),l=qt((h=e.parentConfig)==null?void 0:h.configurable),u=bt(l,["checkpoint_id","checkpointId"])??null,d=bt(l,["checkpoint_ns","checkpointNs"])??null;return{messages:o,checkpointId:i??null,checkpointNs:a??null,nextCursor:u,nextCursorNs:d,interrupt:Bg(o,t)}}function Fg(e){const t=new Map;e.forEach((r,o)=>{if(!vi(r))return;const s=ac(r,o);if(!(s!=null&&s.checkpointId))return;const i=r==null?void 0:r.createdAt,a=typeof i=="string"&&i.trim()?i:new Date(Date.now()-o).toISOString(),l=$g(s.messages),u=s.messages[s.messages.length-1],d=qt(r==null?void 0:r.metadata),f=bt(d,["branch_label","branchLabel"]),h=qt(r==null?void 0:r.parentConfig),p=qt(h==null?void 0:h.configurable),w=bt(p,["checkpoint_id","checkpointId"]),x={checkpointId:s.checkpointId,checkpointNs:s.checkpointNs??"",createdAt:a,messagesLen:s.messages.length,preview:l??null,role:(u==null?void 0:u.role)??null,parentId:w??null,branchLabel:f??null,lastMessageId:(u==null?void 0:u.id)??null,hasMessages:s.messages.length>0},g=`${x.checkpointId}::${x.checkpointNs}`;t.has(g)||t.set(g,x)});const n=Array.from(t.values());return n.sort((r,o)=>lc(o.createdAt)-lc(r.createdAt)),n}function $g(e){var t;for(let n=e.length-1;n>=0;n--){const r=((t=e[n])==null?void 0:t.content)??[];for(let o=0;o<r.length;o++){const s=r[o];if(s&&s.type==="text"&&typeof s.text=="string"){const i=s.text.trim();if(i)return i}}}return null}function Bg(e,t){var n;for(let r=e.length-1;r>=0;r--){const o=((n=e[r])==null?void 0:n.content)??[];for(let s=o.length-1;s>=0;s--){const i=o[s];if((i==null?void 0:i.type)==="interrupt"){const a=i;return{id:typeof a.id=="string"&&a.id.trim()?a.id:`interrupt-${t}-${r}-${s}`,value:a.value}}}}return null}function lc(e){if(!e)return 0;const t=Date.parse(e);return Number.isFinite(t)?t:0}function zg(e,t){if(!e||typeof e!="object")return null;const n=e,r=qt(e)??{},o=qt(n.data)??r,s=String(n.type??o.type??o.role??"").toLowerCase(),i=Lg[s];if(!i)return null;const a=o.id??o.message_id??o.run_id??null,l=typeof a=="string"&&a.trim()?a:`history-${i}-${t}`,u=qt(o.additional_kwargs)??qt(o.additionalKwargs),d=qt(o.response_metadata)??qt(o.responseMetadata),f=bt(u,["createdAt","created_at"])??bt(o,["created_at","createdAt"]),h=bt(u,["checkpointId","checkpoint_id"]),p=bt(u,["checkpointNs","checkpoint_ns"]),w=Hg(o.content),x={id:l,role:i,content:w};f&&(x.createdAt=f),typeof o.name=="string"&&o.name.trim()&&(x.name=o.name),typeof(d==null?void 0:d.model_name)=="string"&&(x.model=String(d.model_name)),!x.model&&typeof o.model=="string"&&(x.model=o.model),h&&(x.checkpointId=h),p&&(x.checkpointNs=p);const g=Kg(u,["createdAt","created_at","checkpointId","checkpoint_id","checkpointNs","checkpoint_ns","tool_calls"]),v=d?{...d}:void 0;g&&Object.keys(g).length&&(x.additionalKwargs=g),v&&Object.keys(v).length&&(x.responseMetadata=v);const b=Ug((u==null?void 0:u.tool_calls)??o.tool_calls);if(b.length&&(x.content=[...x.content,...b]),i==="tool"){const S=Vg(o,x.content);S&&(x.content=S)}return x}function Hg(e){if(!e)return[];if(Array.isArray(e))return e.map(t=>cc(t)).filter(t=>!!t);if(typeof e=="string")return e.trim()?[{type:"text",text:e.trim()}]:[];if(typeof e=="object"){const t=cc(e);return t?[t]:[]}return[]}function cc(e){if(!e||typeof e!="object")return typeof e=="string"&&e.trim()?{type:"text",text:e}:null;const t=e,n=String(t.type??"").toLowerCase();if(!n||n==="text"){const o=typeof t.text=="string"?t.text:typeof t.value=="string"?t.value:"";return o.trim()?{type:"text",text:o}:null}if(n==="image"||n==="image_url"){const o=bt(t,["url","src"]);if(!o)return null;const s={type:"image_url",url:o};return typeof t.mimeType=="string"&&(s.mimeType=t.mimeType),typeof t.alt=="string"&&(s.alt=t.alt),s}if(n==="file"){const o=bt(t,["url"]);if(!o)return null;const s={type:"file",url:o};return typeof t.mimeType=="string"&&(s.mimeType=t.mimeType),typeof t.name=="string"&&(s.name=t.name),typeof t.size=="number"&&(s.size=t.size),typeof t.sourceType=="string"&&(s.sourceType=t.sourceType),s}if(n==="tool_call")return Wg(t)??null;if(n==="tool_end"){const o=bt(t,["tool_call_id","toolCallId","id"]);if(!o)return null;const s={type:"tool_end",toolCallId:o,output:"output"in t?t.output:t.content};return typeof t.error=="string"&&(s.error=t.error),s}if(n==="interrupt")return{type:"interrupt",value:t.value,...t};if(n==="tool"){const o=bt(t,["text","content"]);if(o)return{type:"text",text:o}}const r=typeof t.content=="string"?t.content:typeof t.value=="string"?t.value:JSON.stringify(t);return r?{type:"text",text:r}:null}function Ug(e){return Array.isArray(e)?e.map((t,n)=>{if(!t||typeof t!="object")return null;const r=t,o=bt(r,["id","call_id"]),s=qt(r.function),i=bt(s,["name"])??"tool",a=s==null?void 0:s.arguments,l=uc(a);return{type:"tool_call",id:o??`tool_call_${n}`,name:i,args:l}}).filter(t=>!!t):[]}function Wg(e){const t=bt(e,["id","call_id"]),n=bt(e,["name"]);if(!t||!n)return null;const r=uc(e.args??e.arguments);return{type:"tool_call",id:t,name:n,args:r}}function Vg(e,t){const n=bt(e,["tool_call_id","toolCallId","id"]);if(!n)return t;const r=e.content??e.output,o=typeof r=="string"?qg(r):r,s={type:"tool_end",toolCallId:n,output:o};return typeof e.error=="string"&&(s.error=e.error),[s]}function uc(e){if(!e)return{};if(typeof e=="string")try{const t=JSON.parse(e);return typeof t=="object"&&t!==null?t:{raw:e}}catch{return{raw:e}}return typeof e=="object"&&!Array.isArray(e)?{...e}:{}}function qg(e){try{return JSON.parse(e)}catch{return e}}function qt(e){if(!(!e||typeof e!="object"||Array.isArray(e)))return{...e}}function bt(e,t){if(e)for(const n of t){const r=e[n];if(typeof r=="string"&&r.trim())return r}}function Kg(e,t){if(!e)return;const n={};let r=!1;for(const[o,s]of Object.entries(e)){if(t.includes(o)){r=!0;continue}s!==void 0&&(n[o]=s)}return r?Object.keys(n).length?n:void 0:e}function Gg(e){return e.type!=="thread_info"&&e.type!=="token"}const Yg={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null,messagesStreamMeta:{}};function Xg(e,t){var n;switch(t.type){case"reset":{console.log("[MessageReducer] 🔄 RESET action received"),console.log("[MessageReducer] 📊 Before reset - messages count:",e.messages.length);const r={messages:bi(((n=t.payload)==null?void 0:n.messages)??[]),assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null};return console.log("[MessageReducer] 📊 After reset - messages count:",r.messages.length),r}case"seed":{const r=bi(t.payload.messages),o={...e,messages:r,assemblingId:null};return Object.prototype.hasOwnProperty.call(t.payload,"checkpointId")&&(o.lastCheckpointId=t.payload.checkpointId??null),Object.prototype.hasOwnProperty.call(t.payload,"checkpointNs")&&(o.lastCheckpointNs=t.payload.checkpointNs??null),console.log("[MessageReducer] seed action (REPLACE mode):",{incomingCount:t.payload.messages.length,sanitizedCount:r.length,previousCount:e.messages.length,checkpointId:o.lastCheckpointId}),o}case"prepend":{const r=bi(t.payload.messages);if(!r.length)return console.log("[MessageReducer] No incoming messages after sanitize - skipping"),e;const o=new Set(e.messages.map(i=>i.id)),s=r.filter(i=>!o.has(i.id));return console.log("[MessageReducer] After dedup:",{uniqueCount:s.length,duplicates:r.length-s.length,finalTotal:s.length+e.messages.length}),s.length?{...e,messages:[...s,...e.messages]}:(console.log("[MessageReducer] All messages were duplicates - skipping"),e)}case"user_message":{const r=t.payload.message;return e.messages.some(o=>o.id===r.id)?e:{...e,messages:[...e.messages,r]}}case"event":return fc(e,t.payload.ev);case"batch":{const{events:r}=t.payload;return r.length?r.reduce((o,s)=>fc(o,s),e):e}case"interrupt_response":{const{interruptId:r}=t.payload,o=e.messages.map(s=>({...s,content:s.content.filter(i=>i.type!=="interrupt")}));return{...e,messages:o,pendingInterrupt:null}}default:return e}}function dc(e=[]){const[t,n]=y.useReducer(Xg,{...Yg,messages:e}),r=y.useRef([]),o=y.useRef(null),s=y.useRef(null),i=y.useCallback(()=>{o.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.current),s.current!==null&&clearTimeout(s.current),o.current=null,s.current=null;const d=r.current;d.length&&(r.current=[],n({type:"batch",payload:{events:d}}))},[]),a=y.useCallback(()=>{typeof window<"u"&&typeof window.requestAnimationFrame=="function"?o.current===null&&(o.current=window.requestAnimationFrame(()=>i())):s.current===null&&(s.current=setTimeout(i,8))},[i]),l=y.useCallback(d=>{r.current.push(d),a()},[a]);y.useEffect(()=>()=>{o.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.current),s.current!==null&&clearTimeout(s.current),r.current=[]},[]);const u=y.useMemo(()=>({reset:d=>n({type:"reset",payload:{messages:d}}),seed:(d,f)=>n({type:"seed",payload:{messages:d,...f??{}}}),prepend:d=>n({type:"prepend",payload:{messages:d}}),pushUser:d=>n({type:"user_message",payload:{message:d}}),onEvent:l}),[l]);return{state:t,dispatch:n,...u}}function fc(e,t){var n,r,o,s;if(t.type==="message_start"&&t.role==="assistant"){const i=t.id,a=Qg(t.model);if(e.messages.some(d=>d.id===i)){const d=e.messagesStreamMeta??{},f={...d,[i]:d[i]??{lastSeq:t.seq??null,lastText:""}};return{...e,assemblingId:i,messagesStreamMeta:f}}const u={id:i,role:"assistant",name:a||void 0,model:t.model,createdAt:new Date().toISOString(),content:[]};return{...e,assemblingId:i,messages:[...e.messages,u]}}if(t.type==="message_delta"){const i=e.assemblingId??yi(e.messages);if(!i)return e;const a=e.messages,l=a.findIndex(S=>S.id===i&&S.role==="assistant");if(l===-1)return e;const u=a[l],d=e.messagesStreamMeta??{},f=d[i]??{lastSeq:null,lastText:xc(u.content)},h=t.seq??null;if(h!==null&&typeof h=="number"&&typeof f.lastSeq=="number"&&h<=f.lastSeq)return console.debug("[MessageReducer] skipping delta - seq <= lastSeq",{seq:h,lastSeq:f.lastSeq}),e;const{newParts:p,newMeta:w,changed:x}=Jg(u.content,t.delta,f,h);if(!x)return e;const g={...u,content:p},v=hc(a,l,g),b={...d,[i]:w};return{...e,messages:v,messagesStreamMeta:b}}if(t.type==="message_end"){const i=e.assemblingId??yi(e.messages);if(!i)return{...e,assemblingId:null};const a=e.messages,l=a.findIndex(u=>u.id===i&&u.role==="assistant");if(l>=0){const u=a[l];if(!((n=u.content)==null?void 0:n.some(f=>{var h;return(f==null?void 0:f.type)==="text"&&((h=f.text)==null?void 0:h.trim())}))){console.debug("[MessageReducer] pruning assistant message with no visible text",{id:u.id,contentTypes:(r=u.content)==null?void 0:r.map(h=>h==null?void 0:h.type),contentPreview:(o=u.content)==null?void 0:o.map(h=>(h==null?void 0:h.type)==="text"?String(h.text).slice(0,100):h==null?void 0:h.type)});const f=[...a.slice(0,l),...a.slice(l+1)];return{...e,assemblingId:null,messages:f}}}return e}if(t.type==="tool_start"){const i=t.id??t.call_id,a=t.name??t.tool??"tool";if(!i)return e;const l=`tool-${i}`,u={type:"tool_call",id:i,name:a,args:t.args};if(e.messages.find(h=>h.id===l))return{...e,toolIndex:{...e.toolIndex,[i]:l}};const f={id:l,role:"tool",name:a,createdAt:new Date().toISOString(),content:[u]};return{...e,messages:[...e.messages,f],toolIndex:{...e.toolIndex,[i]:l}}}if(t.type==="tool_end"){const i=t.id??t.call_id;if(!i)return e;const a=e.toolIndex[i]??`tool-${i}`,l={type:"tool_end",toolCallId:i,output:t.output,error:t.error},u=e.messages.find(h=>h.id===a),d={id:a,role:"tool",name:t.name??((s=e.messages.find(h=>h.id===a))==null?void 0:s.name),content:[l],createdAt:new Date().toISOString()},f=u?mc(e.messages,a,[l]):[...e.messages,d];return{...e,messages:f,toolIndex:{...e.toolIndex,[i]:a}}}if(t.type==="checkpoint"){const i=t.checkpointNs??e.lastCheckpointNs??null,a=Zg(e.messages,t.checkpointId,i);return{...e,lastCheckpointId:t.checkpointId,lastCheckpointNs:i,messages:a}}if(t.type==="branch"){const i=t.checkpointId??e.lastCheckpointId,a=t.checkpointNs??e.lastCheckpointNs;return{...e,lastBranch:t,lastCheckpointId:i??null,lastCheckpointNs:a??null}}if(t.type==="error"){const i={id:`err-${Date.now()}`,role:"system",content:[{type:"text",text:`Error: ${t.message}`}],createdAt:new Date().toISOString()};return{...e,messages:[...e.messages,i]}}if(t.type==="interrupt"){const i=e.assemblingId??yi(e.messages),a={type:"interrupt",value:t.value,id:t.id};if(i)return{...e,assemblingId:null,messages:mc(e.messages,i,[a]),pendingInterrupt:{id:t.id,value:t.value}};const l=`interrupt-${t.id}`;if(e.messages.findIndex(f=>f.id===l)!==-1)return{...e,assemblingId:null,messages:pc(e.messages,l,f=>({...f,content:gc(f.content??[],[a])})),pendingInterrupt:{id:t.id,value:t.value}};const d={id:l,role:"system",createdAt:new Date().toISOString(),content:[a]};return{...e,messages:[...e.messages,d],pendingInterrupt:{id:t.id,value:t.value}}}return e}function bi(e){return e.filter(t=>{if(t.role!=="assistant")return!0;const n=(t.content||[]).some(o=>{var s;return o&&o.type==="text"&&((s=o.text)==null?void 0:s.trim())}),r=(t.content||[]).some(o=>o&&o.type==="image_url");return!!(n||r)})}function hc(e,t,n){return t<0||t>=e.length?e:[...e.slice(0,t),n,...e.slice(t+1)]}function yi(e){for(let t=e.length-1;t>=0;t--)if(e[t].role==="assistant")return e[t].id;return null}function pc(e,t,n){const r=e.findIndex(i=>i.id===t);if(r===-1)return e;const o=e[r],s=n(o);return s===o?e:[...e.slice(0,r),s,...e.slice(r+1)]}function mc(e,t,n){return pc(e,t,r=>({...r,content:gc(r.content,n)}))}function gc(e,t){const n=e.slice();for(const r of t)if(r.type==="text"){const o=n[n.length-1],s=r.text??"";if(!s)continue;if((o==null?void 0:o.type)==="text"){let i=function(p){return p.replace(/\s+/g," ").trim()};const a=o,l=a.text??"";if(console.debug("[MessageReducer] mergeParts",{incomingLength:s.length,previousLength:l.length,incomingSnippet:s.slice(0,100),previousSnippet:l.slice(-100)}),!l){a.text=s;continue}const u=i(s),d=i(l);if(u.startsWith(d)||s.startsWith(l)){console.debug("[MessageReducer] incoming startsWith previous (norm/raw) - replacing",{incomingLength:s.length,previousLength:l.length}),a.text=s;continue}if(u.includes(d)){console.debug("[MessageReducer] incoming includes previous (normalized) - replacing",{incomingLength:s.length,previousLength:l.length}),a.text=s;continue}if(d.includes(u)&&u.length<=3){console.debug("[MessageReducer] previous includes incoming (normalized) - skipping trivial incoming",{incomingLength:s.length,previousLength:l.length});continue}const h=wc(l,s);h?(console.debug("[MessageReducer] suffix computed",{suffixLength:h.length}),a.text=l+h):(console.debug("[MessageReducer] no overlap detected - appending incoming",{incomingLength:s.length}),a.text=l+s)}else n.push({type:"text",text:s})}else n.push(r);return n}function xc(e){return!e||!e.length?"":e.filter(t=>t.type==="text").map(t=>t.text??"").join("")}function Jg(e,t,n,r){const o={...n};if(r!==null&&typeof r=="number"){if(typeof o.lastSeq=="number"&&r<=o.lastSeq)return{newParts:e,newMeta:o,changed:!1};o.lastSeq=r}const s=t.filter(f=>f.type==="text").map(f=>f.text??"").join(""),i=t.filter(f=>f.type!=="text"),a=o.lastText??xc(e);let l="",u=e.slice();if(s){const f=wc(a,s);if(f===""?l="":f===s?l=s:l=f,l){const h=u[u.length-1];if((h==null?void 0:h.type)==="text"){const p=h.text??"",w={...h,text:p+l};u=[...u.slice(0,u.length-1),w]}else u=[...u,{type:"text",text:l}];o.lastText=a+l}else o.lastText=a}i.length&&(u=[...u,...i]);const d=!!(l||i.length);return{newParts:u,newMeta:o,changed:d}}function vc(e){return e.replace(/\s+/g," ").trim()}function wc(e,t){if(!t)return"";if(!e)return t;if(e===t)return"";const n=Math.min(e.length,t.length);for(let i=n;i>0;i--)if(e.slice(-i)===t.slice(0,i))return t.slice(i);const r=vc(e),o=vc(t);if(r===o)return"";const s=Math.min(r.length,o.length);for(let i=s;i>0;i--)if(r.slice(-i)===o.slice(0,i))return t;return t}function Zg(e,t,n){for(let r=e.length-1;r>=0;r--)if(e[r].role==="assistant"){const s={...e[r],checkpointId:t,checkpointNs:n??void 0};return hc(e,r,s)}return e}function Qg(e){if(!e)return null;const t=e.split("/");return t[t.length-1]||null}function bc(e={}){const t=y.useMemo(()=>En(e.baseUrl),[e.baseUrl]),n=e.streamPath??"/runs/stream",[r,o]=y.useState(e.token??null),s=y.useRef(e.headers??{}),i=e.credentials??"include",[a,l]=y.useState(!1),[u,d]=y.useState(null),[f,h]=y.useState(""),[p,w]=y.useState(null),[x,g]=y.useState(0),[v,b]=y.useState(!1),S=y.useRef(null),N=y.useRef(!0),C=y.useRef(0),k=y.useCallback(P=>{o(P)},[]),I=y.useCallback(()=>{var P;(P=S.current)==null||P.abort(),S.current=null,l(!1),b(!1),C.current=0,g(0)},[]),A=y.useCallback(()=>{h(""),w(null),d(null)},[]),j=y.useCallback((P,L,F)=>{S.current&&(S.current.abort(),S.current=null),l(!0),d(null),e.autoAppendAssistant!==!1&&h("");const V=new AbortController;return S.current=V,(async()=>{var G,q,U,B,$,ce,D,Q;const M=de=>{var we;try{const ye=JSON.parse(JSON.stringify(de));return(we=ye==null?void 0:ye.payload)!=null&&we.files_info&&Array.isArray(ye.payload.files_info)&&(ye.payload.files_info=ye.payload.files_info.map(Se=>({...Se,data:Se!=null&&Se.data?`<base64 ${String(Se.data).length} chars>`:Se==null?void 0:Se.data}))),ye}catch{return de}};try{let de={};try{if(r)de={Authorization:`Bearer ${r}`};else if(typeof window<"u"){const He=window.__AUTH_TOKEN__,ct=((G=window.localStorage)==null?void 0:G.getItem("authToken"))||null;let tt=null;try{const gt=(q=window.localStorage)==null?void 0:q.getItem("chat-settings");gt&&(tt=((U=JSON.parse(gt))==null?void 0:U.apiKey)||null)}catch{}const Be=He||ct||tt||null;Be&&(de={Authorization:`Bearer ${Be}`})}}catch{}console.debug("[use-chat] POST",t+n,M(P));const we=await fetch(t+n,{method:"POST",headers:{"Content-Type":"application/json",Accept:"text/event-stream",...de,...s.current},body:JSON.stringify(P),signal:V.signal,credentials:i});if(!we.ok||!we.body){const Pe=await we.text().catch(()=>"");throw console.debug("[use-chat] non-OK response",we.status,Pe==null?void 0:Pe.slice(0,500)),new Error(`stream ${we.status}${Pe?": "+Pe:""}`)}b(!0);const ye=we.body.getReader(),Se=new TextDecoder;let K="",O=[];C.current=0,g(0);let X=0,ee=null;const fe=()=>{if(O.length){const Pe=O.join("");O=[],N.current&&h(He=>He+Pe)}ee=null},ne=()=>{typeof window<"u"&&ee==null&&(ee=requestAnimationFrame(fe))};let pe=Date.now();const Ze=setInterval(()=>{var Pe;if(Date.now()-pe>6e4){const He="Stream idle timeout";d(He),V.abort(),(Pe=F==null?void 0:F.onError)==null||Pe.call(F,He)}},5e3),Qe=1024*1024;try{const Pe=we.headers.get("X-Thread-Id")||we.headers.get("x-thread-id"),He=we.headers.get("X-Thread-Created")||we.headers.get("x-thread-created"),ct=Pe??null,tt=String(He??"").toLowerCase()==="true";for((B=F==null?void 0:F.onOpen)==null||B.call(F,{threadId:ct,created:tt});;){const{value:Be,done:gt}=await ye.read();if(gt)break;K+=Se.decode(Be,{stream:!0}),K.length>Qe&&(K="",console.warn("Stream buffer reset: exceeded 1MB"));let J;for(;(J=K.indexOf(`
|
|
36
36
|
|
|
37
|
-
`))>=0;){const re=
|
|
38
|
-
`)}function Xg({baseUrl:e,onThreadInfo:t,onMessageEvent:n,onUnhandledEvent:r,onSequenceGap:o}){const s=y.useRef(null),i=y.useCallback(p=>{const w=p.seq??null;if(w!==null){const x=s.current;if(x!==null){if(w<=x)return;w>x+1&&(o==null||o({from:x,to:w}))}s.current=w}if(p.type==="thread_info"){console.log("[useChatStreamingService] 🎯 Received thread_info event:",p),t(p);return}if(Hg(p)){n(p);return}r==null||r(p)},[n,o,t,r]),{stream:a,stop:l,isStreaming:u,error:d,setToken:f}=pc({baseUrl:e,token:null}),h=y.useCallback((p,w)=>{s.current=null,a(p,i,{onOpen:w==null?void 0:w.onOpen,onError:x=>{var g;(g=w==null?void 0:w.onError)==null||g.call(w,x)},onGap:(w==null?void 0:w.onGap)??o})},[i,o,a]);return y.useMemo(()=>({startStream:h,stop:l,isStreaming:u,error:d,setAuthToken:f}),[h,l,u,d,f])}const mc=y.createContext(null),gc=y.createContext(null),xc=y.createContext(null),Jg=y.createContext(!1),Zg="cachedThreads",Qg="v1",_o=300,xi=200;function vc(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 ex(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 tx(e){if(!e||typeof e!="object")return null;const t=e.tasks;if(!Array.isArray(t))return null;for(const n of t){if(!n||typeof n!="object")continue;const r=n.interrupts;if(!Array.isArray(r)||r.length===0)continue;const o=r[0];if(!o)continue;return{id:(typeof(o==null?void 0:o.id)=="string"?o.id:typeof n.id=="string"?n.id:null)??"interrupt-task",value:o==null?void 0:o.value}}return null}function wc(e){if(typeof window<"u"&&"requestIdleCallback"in window)try{window.requestIdleCallback(e,{timeout:1e3});return}catch{}window.setTimeout(e,_o)}function vr(){return typeof window<"u"&&typeof window.localStorage<"u"}function vi(e){if(!vr())return null;try{return window.localStorage.getItem(e)}catch{return null}}function bc(e,t){if(vr())try{window.localStorage.setItem(e,t)}catch{}}function wi(e){if(vr())try{window.localStorage.removeItem(e)}catch{}}function nx(){const e=vi(Zg);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 rx(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 bi(e,t){return`cachedThreads:v1:${e}:${rx(t||"anon")}`}function ox(e){const t=vi(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 yi(e,t){try{bc(e,JSON.stringify(t))}catch{}}function Si(e){const t=ox(e);if(t.length>0)return t;const n=nx();if(n.length>0)try{yi(e,n.slice(0,xi))}catch{}return n}function jo(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 Ci(e){return e.order.map(t=>e.byId[t]).filter(Boolean)}function sx({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}=pi(),d=y.useMemo(()=>Tn(u),[u]),f=y.useMemo(()=>{try{return new URL(u).host}catch{return"unknown"}},[u]),h=y.useMemo(()=>`threadPayload:${Qg}:${f}:`,[f]),p=y.useCallback(T=>`${h}${T}`,[h]),w=y.useCallback(T=>{if(!T||typeof T!="object")return null;const _=T;return typeof _.threadId!="string"||!Array.isArray(_.messages)?null:{threadId:_.threadId,messages:_.messages,hasMore:!!_.hasMore,nextCursor:_.nextCursor??null,checkpointId:_.checkpointId??null,checkpointNs:_.checkpointNs??null}},[]),x=y.useCallback(T=>{const _=vi(p(T));if(!_)return null;try{const U=JSON.parse(_);return w(U)}catch{return null}},[p,w]),g=y.useCallback((T,_=100)=>{const U={...T,messages:Array.isArray(T.messages)?T.messages.slice(-_):[]};try{bc(p(T.threadId),JSON.stringify(U))}catch{}},[p]),v=y.useCallback(T=>{wi(p(T))},[p]),b=y.useCallback(()=>{if(vr())try{const T=h;for(let _=0;_<window.localStorage.length;_++){const U=window.localStorage.key(_);U&&U.startsWith(T)&&window.localStorage.removeItem(U)}}catch{}},[h]),[S,N]=y.useState(()=>{var T;return bi(f,(T=l.getAuthToken)==null?void 0:T.call(l))}),[C,k]=y.useState(()=>{var _;const T=Si(bi(f,(_=l.getAuthToken)==null?void 0:_.call(l)));return jo(T)}),E=y.useMemo(()=>Ci(C),[C]),[A,j]=y.useState(t),[P,L]=y.useState(!1),[F,V]=y.useState(!1),[M,Y]=y.useState(null),[K,W]=y.useState(null),[z,$]=y.useState(null),ue=y.useCallback(()=>{const T=Si(S);y.startTransition(()=>{k(jo(T))})},[S]),[D,ee]=y.useState(!1),[fe,ve]=y.useState(!1),[be,ye]=y.useState(null),[q,O]=y.useState(void 0),[J,te]=y.useState(void 0),{state:G,dispatch:se,seed:Ve,prepend:Je,pushUser:nt,onEvent:De,reset:Be}=sc(),Ee=y.useRef(A);y.useEffect(()=>{Ee.current=A},[A]);const Ze=y.useRef(!1),wt=y.useRef([]),ht=y.useRef(null),Z=y.useRef(null),re=y.useRef(new Map),pe=y.useRef(A),Ne=y.useRef(!1),we=y.useRef(null),Ae=y.useRef({threadId:null,checkpointId:null,checkpointNs:null}),Qe=y.useCallback((T,_)=>new Promise((U,he)=>{const ne=async()=>{Ze.current=!0;try{await T(),U()}catch(xe){he(xe)}finally{Ze.current=!1;const xe=wt.current.shift();xe&&xe().catch(()=>{})}};Ze.current?wt.current.push(ne):ne().catch(xe=>{he(xe)})}),[]),ze=y.useRef(E.length),[lt,St]=y.useState(!1),Ut=y.useRef(!1);y.useEffect(()=>{ze.current=E.length},[E.length]),y.useEffect(()=>{const T=Ee.current;if(!T){z!==null&&$(null),Ae.current={threadId:null,checkpointId:null,checkpointNs:null};return}const _=G.pendingInterrupt??ex(G.messages);if(_){vc(z,_)||$(_),Ae.current={threadId:T,checkpointId:G.lastCheckpointId??null,checkpointNs:G.lastCheckpointNs??null};return}const U={threadId:T,checkpointId:G.lastCheckpointId??null,checkpointNs:G.lastCheckpointNs??null},he=Ae.current.threadId===U.threadId&&Ae.current.checkpointId===U.checkpointId&&Ae.current.checkpointNs===U.checkpointNs;if(!(l!=null&&l.getState)){z!==null&&$(null),Ae.current=U;return}if(he&&z===null)return;let ne=!1;return Ae.current=U,l.getState({threadId:T,checkpointId:U.checkpointId??void 0,checkpointNs:U.checkpointNs??void 0}).then(xe=>{if(ne)return;const me=tx(xe==null?void 0:xe.state);vc(z,me??null)||$(me??null)}).catch(xe=>{ne||(console.warn("[ChatSessionProvider] Failed to inspect thread state for interrupts:",xe),z!==null&&$(null))}),()=>{ne=!0}},[l,z,G.lastCheckpointId,G.lastCheckpointNs,G.messages,G.pendingInterrupt]);const gt=y.useCallback(async()=>{const T=ze.current>0;T||L(!0);try{const _=await l.listThreads();y.startTransition(()=>{k(U=>{const he=me=>me.map(xt=>`${xt.threadId}:${xt.updatedAt??""}:${xt.messageCount??""}`).join("|"),ne=Ci(U);return he(ne)===he(_)||_.length===0&&ne.length>0&&!Ut.current?U:jo(_)})}),Y(null),Ut.current||(Ut.current=!0,St(!0))}catch(_){i==null||i(String(_)),console.error("[ChatSessionProvider] Failed to refresh threads:",_),Y(String(_))}finally{T||L(!1)}},[l,i]),Pr=y.useRef(!1),ur=y.useRef(null),bt=y.useRef(null),Sn=y.useRef(""),an=y.useCallback((T,_)=>{if(!vr())return;bt.current!==null&&(window.clearTimeout(bt.current),bt.current=null);const U=T.map(ne=>`${ne.threadId}:${ne.updatedAt??""}:${ne.messageCount??""}`).join("|");if(T.length===0){try{wi(S)}catch{}Sn.current="";return}if(U===Sn.current)return;const he=()=>{try{const ne=T.slice(0,xi);yi(S,ne),Sn.current=U}catch{}finally{bt.current=null}};if(_!=null&&_.immediate){he();return}bt.current=window.setTimeout(()=>{wc(he)},_o)},[S]),dr=y.useCallback(()=>{an(E,{immediate:!0})},[an,E]),Nt=y.useCallback((T,_,U)=>{const he=Array.isArray(T==null?void 0:T.messages)?T.messages:[],ne=U??(T==null?void 0:T.threadId)??Ee.current,xe=ne!=null&&ne===Ee.current;if(_==="replace"){if(ne){const me={threadId:ne,messages:he.slice(),hasMore:!!(T!=null&&T.hasMore),nextCursor:(T==null?void 0:T.nextCursor)??null,checkpointId:(T==null?void 0:T.checkpointId)??null,checkpointNs:(T==null?void 0:T.checkpointNs)??null};re.current.set(ne,me),pe.current=ne}if(!xe)return;Ve(he,{checkpointId:(T==null?void 0:T.checkpointId)??null,checkpointNs:(T==null?void 0:T.checkpointNs)??null})}else if(_==="prepend"&&he.length&&ne){const me=re.current.get(ne),xt=(me==null?void 0:me.messages)??[],it=new Set,ut=[...he,...xt].filter(Cn=>{const Zt=Cn==null?void 0:Cn.id;return Zt?it.has(Zt)?!1:(it.add(Zt),!0):!0}),Jt={threadId:ne,messages:ut,hasMore:(T==null?void 0:T.hasMore)??(me==null?void 0:me.hasMore)??!1,nextCursor:(T==null?void 0:T.nextCursor)??(me==null?void 0:me.nextCursor)??null,checkpointId:(me==null?void 0:me.checkpointId)??(T==null?void 0:T.checkpointId)??null,checkpointNs:(me==null?void 0:me.checkpointNs)??(T==null?void 0:T.checkpointNs)??null};if(re.current.set(ne,Jt),!xe)return;Je(he)}else _==="prepend"&&he.length&&Je(he);xe&&(_==="replace"?(ye((T==null?void 0:T.nextCursor)??null),ee(!!(T!=null&&T.hasMore)),O((T==null?void 0:T.checkpointId)??void 0),te((T==null?void 0:T.checkpointNs)??void 0)):(ye(me=>(T==null?void 0:T.nextCursor)??me??null),ee(me=>(T==null?void 0:T.hasMore)!==void 0?!!(T!=null&&T.hasMore):me),O(me=>(T==null?void 0:T.checkpointId)??me??void 0),te(me=>(T==null?void 0:T.checkpointNs)??me??void 0)))},[Je,Ve]),ln=y.useCallback(T=>{T.threadId!=null&&T.threadId!==Ee.current||(Ve(T.messages,{checkpointId:T.checkpointId,checkpointNs:T.checkpointNs}),ye(T.nextCursor),ee(T.hasMore),O(T.checkpointId??void 0),te(T.checkpointNs??void 0),pe.current=T.threadId)},[Ve]),Xt=y.useCallback(T=>{T&&(re.current.delete(T),v(T),pe.current===T&&(pe.current=null))},[v]),cn=y.useCallback(()=>{const T=Ee.current;T&&Xt(T),Be([]),ee(!1),ve(!1),ye(null),O(void 0),te(void 0)},[Xt,Be]),fr=y.useCallback(({from:T,to:_})=>{const U=Ee.current;U&&console.warn(`[ChatSessionProvider] Stream sequence gap detected (${T} -> ${_}) for thread ${U}`)},[]),Or=y.useCallback(T=>{const _=T.threadId;console.log("[ChatSessionProvider] 📥 Handling thread_info event:",{threadId:_,title:T.title,created:T.created,currentThreads:E.length});const U={threadId:_,title:T.title||`Thread ${_.slice(0,8)}`,createdAt:T.createdAt||new Date().toISOString(),updatedAt:T.updatedAt||new Date().toISOString(),messageCount:T.messageCount||0};Ee.current!==_&&(!Ee.current&&G.messages.length<=1&&(Z.current=_),j(_)),y.startTransition(()=>{k(he=>{const ne=he.byId[_];return ne?ne.title===U.title&&ne.updatedAt===U.updatedAt&&ne.messageCount===U.messageCount?he:{byId:{...he.byId,[_]:U},order:he.order}:{byId:{...he.byId,[_]:U},order:[_,...he.order]}})})},[G.messages.length]),{startStream:Mr,stop:hr,isStreaming:Nn,error:Dr,setAuthToken:An}=Xg({baseUrl:d,onThreadInfo:Or,onMessageEvent:De,onUnhandledEvent:T=>{console.warn(`[ChatSessionProvider] Unhandled stream event: ${T.type}`,T)},onSequenceGap:fr});y.useEffect(()=>{Pr.current=Nn},[Nn]),y.useEffect(()=>{if(!vr())return;bt.current!==null&&(window.clearTimeout(bt.current),bt.current=null);const T=E.map(U=>`${U.threadId}:${U.updatedAt??""}:${U.messageCount??""}`).join("|");if(E.length===0){try{wi(S)}catch{}Sn.current="";return}if(T===Sn.current)return;const _=()=>{try{const U=E.slice(0,xi);yi(S,U),Sn.current=T}catch{}finally{bt.current=null}};return bt.current=window.setTimeout(()=>{wc(_),bt.current=null},_o),()=>{bt.current!==null&&(window.clearTimeout(bt.current),bt.current=null)}},[E,an]),y.useEffect(()=>{var he;const T=l.getAuthToken();An(T);const _=ne=>{const xe=bi(f,ne);we.current!==xe&&(we.current=xe,Ne.current=!1),N(xe);const me=Si(xe);y.startTransition(()=>{k(jo(me))}),Ne.current||(Ne.current=!0,gt().catch(()=>{}))};_(T);const U=(he=l.onTokenChange)==null?void 0:he.call(l,ne=>{An(ne),b(),_(ne)});return()=>{U==null||U()}},[l,f,An,b,gt]);const pr=y.useCallback(async T=>{var he;const _=`Thread ${(he=crypto.randomUUID)==null?void 0:he.call(crypto)}`,U={threadId:_,title:T||"New Chat",createdAt:new Date().toISOString(),updatedAt:new Date().toISOString(),messageCount:0};k(ne=>({byId:{...ne.byId,[_]:U},order:[_,...ne.order]})),j(_);try{const ne=await l.createThread(T),xe=typeof ne=="string"?ne:ne.threadId;return k(me=>{const xt=me.byId[_];if(!xt)return me;const it={...me.byId};delete it[_],it[xe]={...xt,threadId:xe};const ut=me.order.map(Jt=>Jt===_?xe:Jt);return{byId:it,order:ut}}),j(xe),setTimeout(()=>gt(),10),Y(null),xe}catch(ne){throw k(xe=>{if(!xe.byId[_])return xe;const me={...xe.byId};delete me[_];const xt=xe.order.filter(it=>it!==_);return{byId:me,order:xt}}),j(null),Y(String(ne)),ne}},[l,gt]),ae=y.useCallback(async T=>{try{await l.deleteThread(T);let _=null;k(U=>{if(!U.byId[T])return U;const he={...U.byId};delete he[T];const ne=U.order.filter(me=>me!==T),xe={byId:he,order:ne};return _=Ci(xe),xe}),_&&an(_,{immediate:!0}),Xt(T),Ee.current===T&&(Z.current=T,j(null),Ee.current=null,pe.current=null,cn()),await gt(),Y(null)}catch(_){throw Y(String(_)),_}},[l,cn,Xt,gt,an]),Te=y.useCallback(async(T,_)=>{try{await l.updateThread(T,_),k(U=>{const he=U.byId[T];return he?{byId:{...U.byId,[T]:{...he,title:_}},order:U.order}:U}),Y(null)}catch(U){throw await gt(),Y(String(U)),U}},[l,gt]),Oe=y.useCallback(async(T,_,U,he=!1)=>{await Qe(async()=>{if(Z.current===T&&!he){Z.current=null;return}if(ht.current===T&&!he)return;j(it=>it===T?it:T),Ee.current=T;const ne=!he&&!_&&!U;let xe=!1;if(ne){const it=re.current.get(T);if(it)ln(it),xe=!0;else{const ut=x(T);ut&&(re.current.set(T,ut),ln(ut),xe=!0)}}const me=he||!xe||!!_||!!U,xt=async it=>{it&&V(!0),ht.current=T;try{const ut=await l.getStateHistory({threadId:T,checkpointId:_,checkpointNs:U}),Jt=nc(ut);Nt(Jt,"replace",T),W(null)}catch(ut){throw(!xe||he||it)&&(i==null||i(String(ut))),W(String(ut)),ut}finally{ht.current=null,it&&V(!1)}};me?await xt(!0):ne&&xe&&xt(!1).catch(it=>{console.warn("[ChatSessionProvider] Background refresh failed:",it)})},`loadThread-${T}`)},[l,ln,Nt,Qe,i]),rt=y.useCallback(async()=>{await Qe(async()=>{const T=Ee.current;T&&Xt(T),Z.current=null,j(null),Ee.current=null,pe.current=null,cn(),O(void 0),te(void 0);try{localStorage.removeItem("lastThreadId")}catch(_){console.warn("[ChatSessionProvider] Failed to clear lastThreadId:",_)}},"clearCurrentThread")},[cn,Xt,Qe]),Rt=y.useCallback(async T=>{const _=await l.listCheckpoints(T);return _g(_,T)},[l]),I=y.useCallback(async(T,_)=>{if(!Ee.current)throw new Error("No active thread");await Oe(Ee.current,T,_??void 0,!0)},[Oe]),B=y.useCallback(async()=>{if(!Ee.current)throw new Error("No active thread");await Oe(Ee.current,void 0,void 0,!0)},[Oe]),oe=y.useCallback(async()=>{if(!Ee.current)throw new Error("No active thread");if(fe||!D)return;const T=be;if(T){ve(!0);try{const _=Ee.current,U=await l.getStateHistory({threadId:_,checkpointId:T??q,checkpointNs:J}),he=nc(U);Nt(he,"prepend",_??void 0),W(null)}catch(_){throw W(String(_)),_}finally{ve(!1)}}},[l,Nt,D,q,J,be,fe]),ke=y.useCallback(T=>{if(!(T!=null&&T.threadId))return;const _={threadId:T.threadId,checkpointId:T.checkpointId??void 0,checkpointNs:T.checkpointNs??void 0,messages:T.messages??[],hasMore:T.hasMore,nextCursor:T.nextCursor??null};Nt(_,"replace",T.threadId)},[Nt]),Fe=y.useCallback(async(T,_)=>{var Js;const U=Ee.current,he=(T==null?void 0:T.text)??"",ne=(T==null?void 0:T.attachments)??[],xe=ne.length?ne:(_==null?void 0:_.attachments)??[],me={...(_==null?void 0:_.payloadExtras)??{},...(T==null?void 0:T.payload)??{}};if(!U&&!Object.keys(me).length&&xe.length===0&&!he.trim()){console.warn("[ChatSessionProvider] Nothing to submit - skipping");return}!U&&!me.messages&&console.warn("[ChatSessionProvider] No thread ID - message will create new thread");const{contentParts:xt,filesInfo:it}=await Rg(l,xe),ut=[...xt];he&&he.trim()&&ut.push({type:"text",text:he.trim()});const Jt=!!U,Cn=Jt?(_==null?void 0:_.checkpointId)??G.lastCheckpointId??void 0:void 0,Zt=Jt?(_==null?void 0:_.checkpointNs)??G.lastCheckpointNs??void 0:void 0,Lr={id:((Js=crypto.randomUUID)==null?void 0:Js.call(crypto))||`user-${Date.now()}`,role:"user",content:ut,createdAt:new Date().toISOString(),...Cn!=null?{checkpointId:Cn}:{},...Zt!=null?{checkpointNs:Zt}:{}};ut.length>0&&nt(Lr);const sl={...Lr,content:ut},Ys=xe.length>0,Xs={...U?{threadId:U}:{},payload:{messages:ut.length>0?[sl]:[],files_info:it,...o&&Ys&&s?{active_agent:s}:{},...me},...Cn!=null?{checkpointId:Cn}:{},...Zt!=null?{checkpointNs:Zt}:{},nodeFilter:_==null?void 0:_.nodeFilter,config:_==null?void 0:_.config};Mr(Xs,{onError:_n=>{console.warn("[ChatSessionProvider] Stream error:",_n)},onOpen:({threadId:_n})=>{!Ee.current&&_n&&(G.messages.length<=1&&(Z.current=_n),j(_n))},onGap:fr})},[l,o,s,fr,G.lastCheckpointId,G.lastCheckpointNs,G.messages.length,nt,Mr]),Ke=y.useCallback(async(T,_,U)=>{var ne,xe;const he=Ee.current;if(!he)throw new Error("No active thread to handle interrupt");try{const me=_?U??!0:!1;try{se({type:"interrupt_response",payload:{interruptId:T}})}catch(Lr){console.warn("[ChatSessionProvider] optimistic interrupt_response dispatch failed:",Lr)}const xt=`${d}/runs/resume`,it=(ne=l.getAuthToken)==null?void 0:ne.call(l),ut=await fetch(xt,{method:"POST",headers:{"Content-Type":"application/json",...it?{Authorization:`Bearer ${it}`}:{}},body:JSON.stringify({thread_id:he,value:me})});if(!ut.ok)throw new Error(`Resume failed with status ${ut.status}`);const Jt=(xe=ut.body)==null?void 0:xe.getReader();if(!Jt)throw new Error("No response body for resume stream");const Cn=new TextDecoder;let Zt="";for(;;){const{done:Lr,value:sl}=await Jt.read();if(Lr)break;Zt+=Cn.decode(sl,{stream:!0});const Ys=Zt.split(`
|
|
39
|
-
`);Zt=Ys.pop()||"";for(const Xs of Ys)if(Xs.startsWith("data: ")){const Js=Xs.slice(6);try{const _n=JSON.parse(Js);se({type:"event",payload:{ev:_n}})}catch(_n){console.warn("[ChatSessionProvider] Failed to parse resume SSE event:",_n)}}}$(null)}catch(me){throw console.error(`[ChatSessionProvider] Failed to handle interrupt ${T}:`,me),me}},[l,se,d]),Ue=y.useCallback(T=>Ke(T.interruptId,T.approved,T.value),[Ke]);y.useEffect(()=>{if(a==null||a(A),A)try{localStorage.setItem("lastThreadId",A)}catch(T){console.warn("[ChatSessionProvider] Failed to persist lastThreadId:",T)}},[A,a]),y.useEffect(()=>((async()=>{try{if(gt().catch(_=>{console.error("[ChatSessionProvider] Failed to refresh threads (background):",_),i==null||i(String(_))}),!r&&!t)try{const _=localStorage.getItem("lastThreadId");_&&(j(_),n&&await Oe(_))}catch(_){console.warn("[ChatSessionProvider] Failed to restore last thread:",_)}else t&&n&&await Oe(t)}catch(_){console.error("[ChatSessionProvider] Initialization failed:",_),i==null||i(String(_))}})(),()=>{}),[]),y.useEffect(()=>{const T=Ee.current;if(!T||pe.current!==T)return;const _={threadId:T,messages:G.messages.slice(),hasMore:D,nextCursor:be,checkpointId:G.lastCheckpointId??null,checkpointNs:G.lastCheckpointNs??null},U=re.current.get(T);(!U||U.messages.length!==_.messages.length||U.messages.some((ne,xe)=>{var me;return(ne==null?void 0:ne.id)!==((me=_.messages[xe])==null?void 0:me.id)})||(U==null?void 0:U.hasMore)!==_.hasMore||(U==null?void 0:U.nextCursor)!==_.nextCursor||(U==null?void 0:U.checkpointId)!==_.checkpointId||(U==null?void 0:U.checkpointNs)!==_.checkpointNs)&&(re.current.set(T,_),ur.current&&window.clearTimeout(ur.current),ur.current=window.setTimeout(()=>{try{g(_,100)}catch(ne){console.warn("[ChatSessionProvider] Failed to persist thread payload:",ne)}},_o))},[D,be,G.lastCheckpointId,G.lastCheckpointNs,G.messages]);const He=y.useMemo(()=>({threads:E,currentThreadId:A,setCurrentThreadId:j,isLoading:P,error:M,actions:{createThread:pr,deleteThread:ae,renameThread:Te,refreshThreads:()=>gt()},persistThreadsCache:dr,hydrateFromCache:ue}),[E,A,P,M,pr,ae,Te,gt,dr,ue,j]),Ct=y.useMemo(()=>{const T=G.lastBranch??null,_=G.assemblingId??null,U=T||_?{branchLabel:(T==null?void 0:T.branchLabel)??null,lastBranch:T,assemblingMessageId:_}:null;return{threadId:A,messages:G.messages,interrupt:z,checkpoint:{id:G.lastCheckpointId??null,namespace:G.lastCheckpointNs??null},metadata:U,isLoading:F,isHistoryLoading:fe,error:K,hasMore:D,loadOlder:oe,seedFromSnapshot:ke,clearState:cn,listCheckpoints:Rt,navigateToCheckpoint:I,returnToLatest:B,loadThread:Oe,clearThread:rt,respondToInterrupt:Ke}},[rt,cn,A,z,D,fe,F,Rt,oe,Oe,G.assemblingId,G.lastBranch,G.lastCheckpointId,G.lastCheckpointNs,G.messages,I,Ke,B,ke,K]),ct=y.useMemo(()=>({isStreaming:Nn,error:Dr,submit:Fe,stop:hr,resume:Ue,setAuthToken:An}),[Nn,Dr,Fe,hr,Ue,An]);return c.jsx(Jg.Provider,{value:!0,children:c.jsx(xc.Provider,{value:ct,children:c.jsx(mc.Provider,{value:He,children:c.jsx(gc.Provider,{value:Ct,children:e})})})})}function Ro(){const e=y.useContext(mc);if(!e)throw new Error("useThreads must be used within ChatSessionProvider");return e}function Po(){const e=y.useContext(gc);if(!e)throw new Error("useThreadState must be used within ChatSessionProvider");return e}function yc(){const e=y.useContext(xc);if(!e)throw new Error("useStream must be used within ChatSessionProvider");return e}function Oo({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(Ag,{apiConfig:t,children:c.jsx(sx,{initialThreadId:n,autoLoadInitial:r,disableAutoRestore:o,enableFileAgentRouting:s,fileAgentId:i,onError:a,onThreadChange:l,children:e})})}function Q(...e){return om.twMerge(rm.clsx(e))}const ix=xo.cva("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-10 w-10"}},defaultVariants:{variant:"default",size:"default"}}),Ge=m.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?Vn.Slot:"button";return c.jsx(i,{className:Q(ix({variant:t,size:n,className:e})),ref:s,...o})});Ge.displayName="Button";const Sc=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}));Sc.displayName="Textarea";function ax({initialValue:e="",editingMessageId:t=null,placeholder:n="Type your message...",isStreaming:r=!1,disabled:o=!1,maxLength:s=2e4,onSend:i,onCancelEdit:a,onStop:l,className:u="",textareaClassName:d="",allowEmptySend:f=!1}){const[h,p]=y.useState(e),[w,x]=y.useTransition(),g=y.useRef(null);y.useEffect(()=>{p(e??""),g.current&&(g.current.style.height="auto",g.current.style.height=`${g.current.scrollHeight}px`)},[e,t]);const v=y.useCallback(()=>{const A=g.current;A&&(A.style.height="auto",A.style.height=`${A.scrollHeight}px`)},[]);y.useEffect(()=>{v()},[v]);const b=y.useCallback(async A=>{A&&A.preventDefault();const j=(h??"").trim();!j&&!f||x(()=>{try{const P=i(j);P&&typeof P.then=="function"?P.then(()=>{p(""),g.current&&(g.current.style.height="auto")}).catch(()=>{}):(p(""),g.current&&(g.current.style.height="auto"))}catch{}})},[h,i,f]),S=y.useCallback(A=>{p(A.target.value),g.current&&(g.current.style.height="auto",g.current.style.height=`${g.current.scrollHeight}px`)},[]),N=y.useCallback(A=>{A.key==="Enter"&&!A.shiftKey?(A.preventDefault(),b()):A.key==="Escape"&&t&&(A.preventDefault(),a==null||a())},[b,t,a]),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 b(A),className:`w-full ${u}`,children:c.jsxs("div",{className:"flex items-end gap-2",children:[c.jsx("div",{className:"flex-1",children:c.jsx(Sc,{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(Ge,{type:"button",onClick:()=>{l==null||l()},size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",disabled:o||!l,children:c.jsx(ie.Square,{size:16})}):c.jsx(Ge,{type:"submit",size:"icon",className:"shrink-0",title:t?"Save changes":"Send message",disabled:o||!h.trim()&&!f||w,children:c.jsx(ie.Send,{size:16})})})]})})}const lx=y.memo(ax),Mo=0,Pn=1,wr=2,Cc=4;function Tc(e){return()=>e}function cx(e){e()}function kc(e,t){return n=>e(t(n))}function Ic(e,t){return()=>e(t)}function ux(e,t){return n=>e(t,n)}function Ti(e){return e!==void 0}function dx(...e){return()=>{e.map(cx)}}function br(){}function Do(e,t){return t(e),e}function fx(e,t){return t(e)}function ot(...e){return e}function Xe(e,t){return e(Pn,t)}function Le(e,t){e(Mo,t)}function ki(e){e(wr)}function ft(e){return e(Cc)}function ge(e,t){return Xe(e,ux(t,Mo))}function en(e,t){const n=e(Pn,r=>{n(),t(r)});return n}function Ec(e){let t,n;return r=>o=>{t=o,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function Nc(e,t){return e===t}function st(e=Nc){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function _e(e){return t=>n=>{e(n)&&t(n)}}function le(e){return t=>kc(t,e)}function dn(e){return t=>()=>{t(e)}}function H(e,...t){const n=hx(...t);return(r,o)=>{switch(r){case wr:ki(e);return;case Pn:return Xe(e,n(o))}}}function fn(e,t){return n=>r=>{n(t=e(t,r))}}function Yn(e){return t=>n=>{e>0?e--:t(n)}}function kn(e){let t=null,n;return r=>o=>{t=o,!n&&(n=setTimeout(()=>{n=void 0,r(t)},e))}}function $e(...e){const t=new Array(e.length);let n=0,r=null;const o=Math.pow(2,e.length)-1;return e.forEach((s,i)=>{const a=Math.pow(2,i);Xe(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 hx(...e){return t=>e.reduceRight(fx,t)}function px(e){let t,n;const r=()=>t==null?void 0:t();return function(o,s){switch(o){case Pn:return s?n===s?void 0:(r(),n=s,t=Xe(e,s),t):(r(),br);case wr:r(),n=null;return}}}function X(e){let t=e;const n=qe();return(r,o)=>{switch(r){case Mo:t=o;break;case Pn:{o(t);break}case Cc:return t}return n(r,o)}}function kt(e,t){return Do(X(t),n=>ge(e,n))}function qe(){const e=[];return(t,n)=>{switch(t){case Mo:e.slice().forEach(r=>{r(n)});return;case wr:e.splice(0,e.length);return;case Pn:return e.push(n),()=>{const r=e.indexOf(n);r>-1&&e.splice(r,1)}}}}function Ft(e){return Do(qe(),t=>ge(e,t))}function Ye(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:mx(),singleton:n}}const mx=()=>Symbol();function gx(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 pt(...e){const t=qe(),n=new Array(e.length);let r=0;const o=Math.pow(2,e.length)-1;return e.forEach((s,i)=>{const a=Math.pow(2,i);Xe(s,l=>{n[i]=l,r=r|a,r===o&&Le(t,n)})}),function(s,i){switch(s){case wr:{ki(t);return}case Pn:return r===o&&i(n),Xe(t,i)}}}function Ie(e,t=Nc){return H(e,st(t))}function Ii(...e){return function(t,n){switch(t){case wr:return;case Pn:return dx(...e.map(r=>Xe(r,n)))}}}var Mt=(e=>(e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR",e))(Mt||{});const xx={0:"debug",3:"error",1:"log",2:"warn"},vx=()=>typeof globalThis>"u"?window:globalThis,On=Ye(()=>{const e=X(3);return{log:X((t,n,r=1)=>{var o;const s=(o=vx().VIRTUOSO_LOG_LEVEL)!=null?o:ft(e);r>=s&&console[xx[r]]("%creact-virtuoso: %c%s %o","color: #0253b3; font-weight: bold","color: initial",t,n)}),logLevel:e}},[],{singleton:!0});function Xn(e,t,n){return Ei(e,t,n).callbackRef}function Ei(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 wx(e,t,n,r,o,s,i,a,l){const u=y.useCallback(d=>{const f=bx(d.children,t,a?"offsetWidth":"offsetHeight",o);let h=d.parentElement;for(;!h.dataset.virtuosoScroller;)h=h.parentElement;const p=h.lastElementChild.dataset.viewportType==="window";let w;p&&(w=h.ownerDocument.defaultView);const x=i?a?i.scrollLeft:i.scrollTop:p?a?w.scrollX||w.document.documentElement.scrollLeft:w.scrollY||w.document.documentElement.scrollTop:a?h.scrollLeft:h.scrollTop,g=i?a?i.scrollWidth:i.scrollHeight:p?a?w.document.documentElement.scrollWidth:w.document.documentElement.scrollHeight:a?h.scrollWidth:h.scrollHeight,v=i?a?i.offsetWidth:i.offsetHeight:p?a?w.innerWidth:w.innerHeight:a?h.offsetWidth:h.offsetHeight;r({scrollHeight:g,scrollTop:Math.max(x,0),viewportHeight:v}),s==null||s(a?Ac("column-gap",getComputedStyle(d).columnGap,o):Ac("row-gap",getComputedStyle(d).rowGap,o)),f!==null&&e(f)},[e,t,o,s,i,r,a]);return Ei(u,n,l)}function bx(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},Mt.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 Ac(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Mt.WARN),t==="normal"?0:parseInt(t??"0",10)}function _c(e,t,n){const r=y.useRef(null),o=y.useCallback(l=>{if(!(l!=null&&l.offsetParent))return;const u=l.getBoundingClientRect(),d=u.width;let f,h;if(t){const p=t.getBoundingClientRect(),w=u.top-p.top;h=p.height-Math.max(0,w),f=w+t.scrollTop}else{const p=i.current.ownerDocument.defaultView;h=p.innerHeight-Math.max(0,u.top),f=u.top+p.scrollY}r.current={offsetTop:f,visibleHeight:h,visibleWidth:d},e(r.current)},[e,t]),{callbackRef:s,ref:i}=Ei(o,!0,n),a=y.useCallback(()=>{o(i.current)},[o,i]);return y.useEffect(()=>{var l;if(t){t.addEventListener("scroll",a);const u=new ResizeObserver(()=>{requestAnimationFrame(a)});return u.observe(t),()=>{t.removeEventListener("scroll",a),u.unobserve(t)}}else{const u=(l=i.current)==null?void 0:l.ownerDocument.defaultView;return u==null||u.addEventListener("scroll",a),u==null||u.addEventListener("resize",a),()=>{u==null||u.removeEventListener("scroll",a),u==null||u.removeEventListener("resize",a)}}},[a,t,i]),s}const _t=Ye(()=>{const e=qe(),t=qe(),n=X(0),r=qe(),o=X(0),s=qe(),i=qe(),a=X(0),l=X(0),u=X(0),d=X(0),f=qe(),h=qe(),p=X(!1),w=X(!1),x=X(!1);return ge(H(e,le(({scrollTop:g})=>g)),t),ge(H(e,le(({scrollHeight:g})=>g)),i),ge(t,o),{deviation:n,fixedFooterHeight:u,fixedHeaderHeight:l,footerHeight:d,headerHeight:a,horizontalDirection:w,scrollBy:h,scrollContainerState:e,scrollHeight:i,scrollingInProgress:p,scrollTo:f,scrollTop:t,skipAnimationFrameInResizeObserver:x,smoothScrollTargetReached:r,statefulScrollTop:o,viewportHeight:s}},[],{singleton:!0}),Vr={lvl:0};function jc(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 et(e){return e===Vr}function Kr(e,t){if(!et(e))return t===e.k?e.v:t<e.k?Kr(e.l,t):Kr(e.r,t)}function tn(e,t,n="k"){if(et(e))return[-1/0,void 0];if(Number(e[n])===t)return[e.k,e.v];if(Number(e[n])<t){const r=tn(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return tn(e.l,t,n)}function $t(e,t,n){return et(e)?Oc(t,n,1):t===e.k?mt(e,{k:t,v:n}):t<e.k?Mc(mt(e,{l:$t(e.l,t,n)})):Mc(mt(e,{r:$t(e.r,t,n)}))}function yr(){return Vr}function Lo(e,t,n){if(et(e))return[];const r=tn(e,t)[0];return yx(Ai(e,r,n))}function Ni(e,t){if(et(e))return Vr;const{k:n,l:r,r:o}=e;if(t===n){if(et(r))return o;if(et(o))return r;{const[s,i]=Pc(r);return Fo(mt(e,{k:s,l:Rc(r),v:i}))}}else return t<n?Fo(mt(e,{l:Ni(r,t)})):Fo(mt(e,{r:Ni(o,t)}))}function Jn(e){return et(e)?[]:[...Jn(e.l),{k:e.k,v:e.v},...Jn(e.r)]}function Ai(e,t,n){if(et(e))return[];const{k:r,l:o,r:s,v:i}=e;let a=[];return r>t&&(a=a.concat(Ai(o,t,n))),r>=t&&r<=n&&a.push({k:r,v:i}),r<=n&&(a=a.concat(Ai(s,t,n))),a}function Fo(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(_i(t))return Dc(mt(e,{lvl:n-1}));if(!et(t)&&!et(t.r))return mt(t.r,{l:mt(t,{r:t.r.l}),lvl:n,r:mt(e,{l:t.r.r,lvl:n-1})});throw new Error("Unexpected empty nodes")}else{if(_i(e))return ji(mt(e,{lvl:n-1}));if(!et(r)&&!et(r.l)){const o=r.l,s=_i(o)?r.lvl-1:r.lvl;return mt(o,{l:mt(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:ji(mt(r,{l:o.r,lvl:s}))})}else throw new Error("Unexpected empty nodes")}}function mt(e,t){return Oc(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 Rc(e){return et(e.r)?e.l:Fo(mt(e,{r:Rc(e.r)}))}function _i(e){return et(e)||e.lvl>e.r.lvl}function Pc(e){return et(e.r)?[e.k,e.v]:Pc(e.r)}function Oc(e,t,n,r=Vr,o=Vr){return{k:e,l:r,lvl:n,r:o,v:t}}function Mc(e){return ji(Dc(e))}function Dc(e){const{l:t}=e;return!et(t)&&t.lvl===e.lvl?mt(t,{r:mt(e,{l:t.r})}):e}function ji(e){const{lvl:t,r:n}=e;return!et(n)&&!et(n.r)&&n.lvl===t&&n.r.lvl===t?mt(n,{l:mt(e,{r:n.l}),lvl:t+1}):e}function yx(e){return jc(e,({k:t,v:n})=>({index:t,value:n}))}function Lc(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function qr(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}const Ri=Ye(()=>({recalcInProgress:X(!1)}),[],{singleton:!0});function Fc(e,t,n){return e[$o(e,t,n)]}function $o(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 Sx(e,t,n,r){const o=$o(e,t,r),s=$o(e,n,r,o);return e.slice(o,s+1)}function Mn(e,t){return Math.round(e.getBoundingClientRect()[t])}function zo(e){return!et(e.groupOffsetTree)}function Pi({index:e},t){return t===e?0:t<e?-1:1}function Cx(){return{groupIndices:[],groupOffsetTree:yr(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:yr()}}function Tx(e,t){let n=et(e)?0:1/0;for(const r of t){const{endIndex:o,size:s,startIndex:i}=r;if(n=Math.min(n,i),et(e)){e=$t(e,0,s);continue}const a=Lo(e,i-1,o+1);if(a.some(jx(r)))continue;let l=!1,u=!1;for(const{end:d,start:f,value:h}of a)l?(o>=f||s===h)&&(e=Ni(e,f)):(u=h!==s,l=!0),d>o&&o>=f&&h!==s&&(e=$t(e,o+1,h));u&&(e=$t(e,i,s))}return[e,n]}function kx(e){return typeof e.groupIndex<"u"}function Ix({offset:e},t){return t===e?0:t<e?-1:1}function Gr(e,t,n){if(t.length===0)return 0;const{index:r,offset:o,size:s}=Fc(t,e,Pi),i=e-r,a=s*i+(i-1)*n+o;return a>0?a+n:a}function $c(e,t){if(!zo(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function zc(e,t,n){if(kx(e))return t.groupIndices[e.groupIndex]+1;{const r=e.index==="LAST"?n:e.index;let o=$c(r,t);return o=Math.max(0,o,Math.min(n,o)),o}}function Ex(e,t,n,r=0){return r>0&&(t=Math.max(t,Fc(e,r,Pi).offset)),jc(Sx(e,t,n,Ix),_x)}function Nx(e,[t,n,r,o]){t.length>0&&r("received item sizes",t,Mt.DEBUG);const s=e.sizeTree;let i=s,a=0;if(n.length>0&&et(s)&&t.length===2){const h=t[0].size,p=t[1].size;i=n.reduce((w,x)=>$t($t(w,x,h),x+1,p),i)}else[i,a]=Tx(i,t);if(i===s)return e;const{lastIndex:l,lastOffset:u,lastSize:d,offsetTree:f}=Oi(e.offsetTree,a,i,o);return{groupIndices:n,groupOffsetTree:n.reduce((h,p)=>$t(h,p,Gr(p,f,o)),yr()),lastIndex:l,lastOffset:u,lastSize:d,offsetTree:f,sizeTree:i}}function Ax(e){return Jn(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 Bc(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 Oi(e,t,n,r){let o=e,s=0,i=0,a=0,l=0;if(t!==0){l=$o(o,t-1,Pi),a=o[l].offset;const u=tn(n,t-1);s=u[0],i=u[1],o.length&&o[l].size===tn(n,t)[1]&&(l-=1),o=o.slice(0,l+1)}else o=[];for(const{start:u,value:d}of Lo(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 _x(e){return{index:e.index,value:e}}function jx(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 Rx={offsetHeight:"height",offsetWidth:"width"},hn=Ye(([{log:e},{recalcInProgress:t}])=>{const n=qe(),r=qe(),o=kt(r,0),s=qe(),i=qe(),a=X(0),l=X([]),u=X(void 0),d=X(void 0),f=X((C,k)=>Mn(C,Rx[k])),h=X(void 0),p=X(0),w=Cx(),x=kt(H(n,$e(l,e,p),fn(Nx,w),st()),w),g=kt(H(l,st(),fn((C,k)=>({current:k,prev:C.current}),{current:[],prev:[]}),le(({prev:C})=>C)),[]);ge(H(l,_e(C=>C.length>0),$e(x,p),le(([C,k,E])=>{const A=C.reduce((j,P,L)=>$t(j,P,Gr(P,k.offsetTree,E)||L),yr());return{...k,groupIndices:C,groupOffsetTree:A}})),x),ge(H(r,$e(x),_e(([C,{lastIndex:k}])=>C<k),le(([C,{lastIndex:k,lastSize:E}])=>[{endIndex:k,size:E,startIndex:C}])),n),ge(u,d);const v=kt(H(u,le(C=>C===void 0)),!0);ge(H(d,_e(C=>C!==void 0&&et(ft(x).sizeTree)),le(C=>[{endIndex:0,size:C,startIndex:0}])),n);const b=Ft(H(n,$e(x),fn(({sizes:C},[k,E])=>({changed:E!==C,sizes:E}),{changed:!1,sizes:w}),le(C=>C.changed)));Xe(H(a,fn((C,k)=>({diff:C.prev-k,prev:k}),{diff:0,prev:0}),le(C=>C.diff)),C=>{const{groupIndices:k}=ft(x);if(C>0)Le(t,!0),Le(s,C+Bc(C,k));else if(C<0){const E=ft(g);E.length>0&&(C-=Bc(-C,E)),Le(i,C)}}),Xe(H(a,$e(e)),([C,k])=>{C<0&&k("`firstItemIndex` prop should not be set to less than zero. If you don't know the total count, just use a very high value",{firstItemIndex:a},Mt.ERROR)});const S=Ft(s);ge(H(s,$e(x),le(([C,k])=>{const E=k.groupIndices.length>0,A=[],j=k.lastSize;if(E){const P=Kr(k.sizeTree,0);let L=0,F=0;for(;L<C;){const M=k.groupIndices[F],Y=k.groupIndices.length===F+1?1/0:k.groupIndices[F+1]-M-1;A.push({endIndex:M,size:P,startIndex:M}),A.push({endIndex:M+1+Y-1,size:j,startIndex:M+1}),F++,L+=Y+1}const V=Jn(k.sizeTree);return L!==C&&V.shift(),V.reduce((M,{k:Y,v:K})=>{let W=M.ranges;return M.prevSize!==0&&(W=[...M.ranges,{endIndex:Y+C-1,size:M.prevSize,startIndex:M.prevIndex}]),{prevIndex:Y+C,prevSize:K,ranges:W}},{prevIndex:C,prevSize:0,ranges:A}).ranges}return Jn(k.sizeTree).reduce((P,{k:L,v:F})=>({prevIndex:L+C,prevSize:F,ranges:[...P.ranges,{endIndex:L+C-1,size:P.prevSize,startIndex:P.prevIndex}]}),{prevIndex:0,prevSize:j,ranges:[]}).ranges})),n);const N=Ft(H(i,$e(x,p),le(([C,{offsetTree:k},E])=>{const A=-C;return Gr(A,k,E)})));return ge(H(i,$e(x,p),le(([C,k,E])=>{if(k.groupIndices.length>0){if(et(k.sizeTree))return k;let A=yr();const j=ft(g);let P=0,L=0,F=0;for(;P<-C;){F=j[L];const V=j[L+1]-F-1;L++,P+=V+1}if(A=Jn(k.sizeTree).reduce((V,{k:M,v:Y})=>$t(V,Math.max(0,M+C),Y),A),P!==-C){const V=Kr(k.sizeTree,F);A=$t(A,0,V);const M=tn(k.sizeTree,-C+1)[1];A=$t(A,1,M)}return{...k,sizeTree:A,...Oi(k.offsetTree,0,A,E)}}else{const A=Jn(k.sizeTree).reduce((j,{k:P,v:L})=>$t(j,Math.max(0,P+C),L),yr());return{...k,sizeTree:A,...Oi(k.offsetTree,0,A,E)}}})),x),{beforeUnshiftWith:S,data:h,defaultItemSize:d,firstItemIndex:a,fixedItemSize:u,gap:p,groupIndices:l,itemSize:f,listRefresh:b,shiftWith:i,shiftWithOffset:N,sizeRanges:n,sizes:x,statefulTotalCount:o,totalCount:r,trackItemSizes:v,unshiftWith:s}},ot(On,Ri),{singleton:!0});function Px(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const Hc=Ye(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=qe(),i=qe(),a=Ft(H(s,le(Px)));return ge(H(a,le(l=>l.totalCount)),n),ge(H(a,le(l=>l.groupIndices)),e),ge(H(pt(o,t,r),_e(([l,u])=>zo(u)),le(([l,u,d])=>tn(u.groupOffsetTree,Math.max(l-d,0),"v")[0]),st(),le(l=>[l])),i),{groupCounts:s,topItemsIndexes:i}},ot(hn,_t)),Dn=Ye(([{log:e}])=>{const t=X(!1),n=Ft(H(t,_e(r=>r),st()));return Xe(t,r=>{r&&ft(e)("props updated",{},Mt.DEBUG)}),{didMount:n,propsReady:t}},ot(On),{singleton:!0}),Ox=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function Uc(e){const t=typeof e=="number"?{index:e}:e;return t.align||(t.align="start"),(!t.behavior||!Ox)&&(t.behavior="auto"),t.offset||(t.offset=0),t}const Yr=Ye(([{gap:e,listRefresh:t,sizes:n,totalCount:r},{fixedFooterHeight:o,fixedHeaderHeight:s,footerHeight:i,headerHeight:a,scrollingInProgress:l,scrollTo:u,smoothScrollTargetReached:d,viewportHeight:f},{log:h}])=>{const p=qe(),w=qe(),x=X(0);let g=null,v=null,b=null;function S(){g&&(g(),g=null),b&&(b(),b=null),v&&(clearTimeout(v),v=null),Le(l,!1)}return ge(H(p,$e(n,f,r,x,a,i,h),$e(e,s,o),le(([[N,C,k,E,A,j,P,L],F,V,M])=>{const Y=Uc(N),{align:K,behavior:W,offset:z}=Y,$=E-1,ue=zc(Y,C,$);let D=Gr(ue,C.offsetTree,F)+j;K==="end"?(D+=V+tn(C.sizeTree,ue)[1]-k+M,ue===$&&(D+=P)):K==="center"?D+=(V+tn(C.sizeTree,ue)[1]-k+M)/2:D-=A,z&&(D+=z);const ee=fe=>{S(),fe?(L("retrying to scroll to",{location:N},Mt.DEBUG),Le(p,N)):(Le(w,!0),L("list did not change, scroll successful",{},Mt.DEBUG))};if(S(),W==="smooth"){let fe=!1;b=Xe(t,ve=>{fe=fe||ve}),g=en(d,()=>{ee(fe)})}else g=en(H(t,Mx(150)),ee);return v=setTimeout(()=>{S()},1200),Le(l,!0),L("scrolling from index to",{behavior:W,index:ue,top:D},Mt.DEBUG),{behavior:W,top:D}})),u),{scrollTargetReached:w,scrollToIndex:p,topListHeight:x}},ot(hn,_t,On),{singleton:!0});function Mx(e){return t=>{const n=setTimeout(()=>{t(!1)},e);return r=>{r&&(t(!0),clearTimeout(n))}}}function Mi(e,t){e==0?t():requestAnimationFrame(()=>{Mi(e-1,t)})}function Di(e,t){const n=t-1;return typeof e=="number"?e:e.index==="LAST"?n:e.index}const Xr=Ye(([{defaultItemSize:e,listRefresh:t,sizes:n},{scrollTop:r},{scrollTargetReached:o,scrollToIndex:s},{didMount:i}])=>{const a=X(!0),l=X(0),u=X(!0);return ge(H(i,$e(l),_e(([d,f])=>!!f),dn(!1)),a),ge(H(i,$e(l),_e(([d,f])=>!!f),dn(!1)),u),Xe(H(pt(t,i),$e(a,n,e,u),_e(([[,d],f,{sizeTree:h},p,w])=>d&&(!et(h)||Ti(p))&&!f&&!w),$e(l)),([,d])=>{en(o,()=>{Le(u,!0)}),Mi(4,()=>{en(r,()=>{Le(a,!0)}),Le(s,d)})}),{initialItemFinalLocationReached:u,initialTopMostItemIndex:l,scrolledToInitialItem:a}},ot(hn,_t,Yr,Dn),{singleton:!0});function Wc(e,t){return Math.abs(e-t)<1.01}const Jr="up",Zr="down",Dx="none",Lx={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},Fx=0,Qr=Ye(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:o,viewportHeight:s}])=>{const i=X(!1),a=X(!0),l=qe(),u=qe(),d=X(4),f=X(Fx),h=kt(H(Ii(H(Ie(o),Yn(1),dn(!0)),H(Ie(o),Yn(1),dn(!1),Ec(100))),st()),!1),p=kt(H(Ii(H(n,dn(!0)),H(n,dn(!1),Ec(200))),st()),!1);ge(H(pt(Ie(o),Ie(f)),le(([b,S])=>b<=S),st()),a),ge(H(a,kn(50)),u);const w=Ft(H(pt(r,Ie(s),Ie(t),Ie(e),Ie(d)),fn((b,[{scrollHeight:S,scrollTop:N},C,k,E,A])=>{const j=N+C-S>-A,P={scrollHeight:S,scrollTop:N,viewportHeight:C};if(j){let F,V;return N>b.state.scrollTop?(F="SCROLLED_DOWN",V=b.state.scrollTop-N):(F="SIZE_DECREASED",V=b.state.scrollTop-N||b.scrollTopDelta),{atBottom:!0,atBottomBecause:F,scrollTopDelta:V,state:P}}let L;return P.scrollHeight>b.state.scrollHeight?L="SIZE_INCREASED":C<b.state.viewportHeight?L="VIEWPORT_HEIGHT_DECREASING":N<b.state.scrollTop?L="SCROLLING_UPWARDS":L="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:L,state:P}},Lx),st((b,S)=>b&&b.atBottom===S.atBottom))),x=kt(H(r,fn((b,{scrollHeight:S,scrollTop:N,viewportHeight:C})=>{if(Wc(b.scrollHeight,S))return{changed:!1,jump:0,scrollHeight:S,scrollTop:N};{const k=S-(N+C)<1;return b.scrollTop!==N&&k?{changed:!0,jump:b.scrollTop-N,scrollHeight:S,scrollTop:N}:{changed:!0,jump:0,scrollHeight:S,scrollTop:N}}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),_e(b=>b.changed),le(b=>b.jump)),0);ge(H(w,le(b=>b.atBottom)),i),ge(H(i,kn(50)),l);const g=X(Zr);ge(H(r,le(({scrollTop:b})=>b),st(),fn((b,S)=>ft(p)?{direction:b.direction,prevScrollTop:S}:{direction:S<b.prevScrollTop?Jr:Zr,prevScrollTop:S},{direction:Zr,prevScrollTop:0}),le(b=>b.direction)),g),ge(H(r,kn(50),dn(Dx)),g);const v=X(0);return ge(H(h,_e(b=>!b),dn(0)),v),ge(H(o,kn(100),$e(h),_e(([b,S])=>!!S),fn(([b,S],[N])=>[S,N],[0,0]),le(([b,S])=>S-b)),v),{atBottomState:w,atBottomStateChange:l,atBottomThreshold:d,atTopStateChange:u,atTopThreshold:f,isAtBottom:i,isAtTop:a,isScrolling:h,lastJumpDueToItemResize:x,scrollDirection:g,scrollVelocity:v}},ot(_t)),Bo="top",Ho="bottom",Vc="none";function Kc(e,t,n){return typeof e=="number"?n===Jr&&t===Bo||n===Zr&&t===Ho?e:0:n===Jr?t===Bo?e.main:e.reverse:t===Ho?e.main:e.reverse}function qc(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const Li=Ye(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:o}])=>{const s=qe(),i=X(0),a=X(0),l=X(0),u=kt(H(pt(Ie(r),Ie(o),Ie(n),Ie(s,qr),Ie(l),Ie(i),Ie(t),Ie(e),Ie(a)),le(([d,f,h,[p,w],x,g,v,b,S])=>{const N=d-b,C=g+v,k=Math.max(h-N,0);let E=Vc;const A=qc(S,Bo),j=qc(S,Ho);return p-=b,p+=h+v,w+=h+v,w-=b,p>d+C-A&&(E=Jr),w<d-k+f+j&&(E=Zr),E!==Vc?[Math.max(N-h-Kc(x,Bo,E)-A,0),N-k-v+f+Kc(x,Ho,E)+j]:null}),_e(d=>d!=null),st(qr)),[0,0]);return{increaseViewportBy:a,listBoundary:s,overscan:l,topListHeight:i,visibleRange:u}},ot(_t),{singleton:!0});function $x(e,t,n){if(zo(t)){const r=$c(e,t);return[{index:tn(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 Fi={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function Uo(e,t,n,r,o,s){const{lastIndex:i,lastOffset:a,lastSize:l}=o;let u=0,d=0;if(e.length>0){u=e[0].offset;const x=e[e.length-1];d=x.offset+x.size}const f=n-i,h=a+f*l+(f-1)*r,p=u,w=h-d;return{bottom:d,firstItemIndex:s,items:Yc(e,o,s),offsetBottom:w,offsetTop:u,top:p,topItems:Yc(t,o,s),topListHeight:t.reduce((x,g)=>g.size+x,0),totalCount:n}}function Gc(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=Di(t,a),u=Array.from({length:a}).map((d,f)=>({data:s[f+l],index:f+l,offset:0,size:0}));return Uo(u,[],a,o,n,r)}function Yc(e,t,n){if(e.length===0)return[];if(!zo(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=Lo(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 Zn=Ye(([{data:e,firstItemIndex:t,gap:n,sizes:r,totalCount:o},s,{listBoundary:i,topListHeight:a,visibleRange:l},{initialTopMostItemIndex:u,scrolledToInitialItem:d},{topListHeight:f},h,{didMount:p},{recalcInProgress:w}])=>{const x=X([]),g=X(0),v=qe();ge(s.topItemsIndexes,x);const b=kt(H(pt(p,w,Ie(l,qr),Ie(o),Ie(r),Ie(u),d,Ie(x),Ie(t),Ie(n),e),_e(([k,E,,A,,,,,,,j])=>{const P=j&&j.length!==A;return k&&!E&&!P}),le(([,,[k,E],A,j,P,L,F,V,M,Y])=>{const K=j,{offsetTree:W,sizeTree:z}=K,$=ft(g);if(A===0)return{...Fi,totalCount:A};if(k===0&&E===0)return $===0?{...Fi,totalCount:A}:Gc($,P,j,V,M,Y||[]);if(et(z))return $>0?null:Uo($x(Di(P,A),K,Y),[],A,M,K,V);const ue=[];if(F.length>0){const be=F[0],ye=F[F.length-1];let q=0;for(const O of Lo(z,be,ye)){const J=O.value,te=Math.max(O.start,be),G=Math.min(O.end,ye);for(let se=te;se<=G;se++)ue.push({data:Y==null?void 0:Y[se],index:se,offset:q,size:J}),q+=J}}if(!L)return Uo([],ue,A,M,K,V);const D=F.length>0?F[F.length-1]+1:0,ee=Ex(W,k,E,D);if(ee.length===0)return null;const fe=A-1,ve=Do([],be=>{for(const ye of ee){const q=ye.value;let O=q.offset,J=ye.start;const te=q.size;if(q.offset<k){J+=Math.floor((k-q.offset+M)/(te+M));const se=J-ye.start;O+=se*te+se*M}J<D&&(O+=(D-J)*te,J=D);const G=Math.min(ye.end,fe);for(let se=J;se<=G&&!(O>=E);se++)be.push({data:Y==null?void 0:Y[se],index:se,offset:O,size:te}),O+=te+M}});return Uo(ve,ue,A,M,K,V)}),_e(k=>k!==null),st()),Fi);ge(H(e,_e(Ti),le(k=>k==null?void 0:k.length)),o),ge(H(b,le(k=>k.topListHeight)),f),ge(f,a),ge(H(b,le(k=>[k.top,k.bottom])),i),ge(H(b,le(k=>k.items)),v);const S=Ft(H(b,_e(({items:k})=>k.length>0),$e(o,e),_e(([{items:k},E])=>k[k.length-1].originalIndex===E-1),le(([,k,E])=>[k-1,E]),st(qr),le(([k])=>k))),N=Ft(H(b,kn(200),_e(({items:k,topItems:E})=>k.length>0&&k[0].originalIndex===E.length),le(({items:k})=>k[0].index),st())),C=Ft(H(b,_e(({items:k})=>k.length>0),le(({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}}),st(Lc)));return{endReached:S,initialItemCount:g,itemsRendered:v,listState:b,rangeChanged:C,startReached:N,topItemsIndexes:x,...h}},ot(hn,Hc,Li,Xr,Yr,Qr,Dn,Ri),{singleton:!0}),Xc=Ye(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:o}])=>{const s=qe(),i=kt(H(pt(n,e,r,t,o),le(([a,l,u,d,f])=>a+l+u+d+f.offsetBottom+f.bottom)),0);return ge(Ie(i),s),{totalListHeight:i,totalListHeightChanged:s}},ot(_t,Zn),{singleton:!0}),zx=Ye(([{viewportHeight:e},{totalListHeight:t}])=>{const n=X(!1),r=kt(H(pt(n,e,t),_e(([o])=>o),le(([,o,s])=>Math.max(0,o-s)),kn(0),st()),0);return{alignToBottom:n,paddingTopAddition:r}},ot(_t,Xc),{singleton:!0}),Jc=Ye(()=>({context:X(null)})),Bx=({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,Zc=Ye(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:s,scrollingInProgress:i,scrollTop:a,viewportHeight:l},{scrollToIndex:u}])=>{const d=qe();return ge(H(d,$e(t,l,n,s,o,r,a),$e(e),le(([[f,h,p,w,x,g,v,b],S])=>{const{align:N,behavior:C,calculateViewLocation:k=Bx,done:E,...A}=f,j=zc(f,h,w-1),P=Gr(j,h.offsetTree,S)+x+g,L=P+tn(h.sizeTree,j)[1],F=b+g,V=b+p-v,M=k({itemBottom:L,itemTop:P,locationParams:{align:N,behavior:C,...A},viewportBottom:V,viewportTop:F});return M?E&&en(H(i,_e(Y=>!Y),Yn(ft(i)?1:2)),E):E&&E(),M}),_e(f=>f!==null)),u),{scrollIntoView:d}},ot(hn,_t,Yr,Zn,On),{singleton:!0});function Qc(e){return e?e==="smooth"?"smooth":"auto":!1}const Hx=(e,t)=>typeof e=="function"?Qc(e(t)):t&&Qc(e),Ux=Ye(([{listRefresh:e,totalCount:t,fixedItemSize:n,data:r},{atBottomState:o,isAtBottom:s},{scrollToIndex:i},{scrolledToInitialItem:a},{didMount:l,propsReady:u},{log:d},{scrollingInProgress:f},{context:h},{scrollIntoView:p}])=>{const w=X(!1),x=qe();let g=null;function v(C){Le(i,{align:"end",behavior:C,index:"LAST"})}Xe(H(pt(H(Ie(t),Yn(1)),l),$e(Ie(w),s,a,f),le(([[C,k],E,A,j,P])=>{let L=k&&j,F="auto";return L&&(F=Hx(E,A||P),L=L&&!!F),{followOutputBehavior:F,shouldFollow:L,totalCount:C}}),_e(({shouldFollow:C})=>C)),({followOutputBehavior:C,totalCount:k})=>{g&&(g(),g=null),ft(n)?requestAnimationFrame(()=>{ft(d)("following output to ",{totalCount:k},Mt.DEBUG),v(C)}):g=en(e,()=>{ft(d)("following output to ",{totalCount:k},Mt.DEBUG),v(C),g=null})});function b(C){const k=en(o,E=>{C&&!E.atBottom&&E.notAtBottomBecause==="SIZE_INCREASED"&&!g&&(ft(d)("scrolling to bottom due to increased size",{},Mt.DEBUG),v("auto"))});setTimeout(k,100)}Xe(H(pt(Ie(w),t,u),_e(([C,,k])=>C&&k),fn(({value:C},[,k])=>({refreshed:C===k,value:k}),{refreshed:!1,value:0}),_e(({refreshed:C})=>C),$e(w,t)),([,C])=>{ft(a)&&b(C!==!1)}),Xe(x,()=>{b(ft(w)!==!1)}),Xe(pt(Ie(w),o),([C,k])=>{C&&!k.atBottom&&k.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&v("auto")});const S=X(null),N=qe();return ge(Ii(H(Ie(r),le(C=>{var k;return(k=C==null?void 0:C.length)!=null?k:0})),H(Ie(t))),N),Xe(H(pt(H(N,Yn(1)),l),$e(Ie(S),a,f,h),le(([[C,k],E,A,j,P])=>k&&A&&(E==null?void 0:E({context:P,totalCount:C,scrollingInProgress:j}))),_e(C=>!!C),kn(0)),C=>{g&&(g(),g=null),ft(n)?requestAnimationFrame(()=>{ft(d)("scrolling into view",{}),Le(p,C)}):g=en(e,()=>{ft(d)("scrolling into view",{}),Le(p,C),g=null})}),{autoscrollToBottom:x,followOutput:w,scrollIntoViewOnChange:S}},ot(hn,Qr,Yr,Xr,Dn,On,_t,Jc,Zc)),Wx=Ye(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:s,listState:i},{didMount:a}])=>(ge(H(a,$e(s),_e(([,l])=>l!==0),$e(o,r,t,n,e),le(([[,l],u,d,f,h,p=[]])=>Gc(l,u,d,f,h,p))),i),{}),ot(hn,Xr,Zn,Dn),{singleton:!0}),Vx=Ye(([{didMount:e},{scrollTo:t},{listState:n}])=>{const r=X(0);return Xe(H(e,$e(r),_e(([,o])=>o!==0),le(([,o])=>({top:o}))),o=>{en(H(n,Yn(1),_e(s=>s.items.length>1)),()=>{requestAnimationFrame(()=>{Le(t,o)})})}),{initialScrollTop:r}},ot(Dn,_t,Zn),{singleton:!0}),eu=Ye(([{scrollVelocity:e}])=>{const t=X(!1),n=qe(),r=X(!1);return ge(H(e,$e(r,t,n),_e(([o,s])=>!!s),le(([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}),st()),t),Xe(H(pt(t,e,n),$e(r)),([[o,s,i],a])=>{o&&a&&a.change&&a.change(s,i)}),{isSeeking:t,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:e}},ot(Qr),{singleton:!0}),$i=Ye(([{scrollContainerState:e,scrollTo:t}])=>{const n=qe(),r=qe(),o=qe(),s=X(!1),i=X(void 0);return ge(H(pt(n,r),le(([{scrollHeight:a,scrollTop:l,viewportHeight:u},{offsetTop:d}])=>({scrollHeight:a,scrollTop:Math.max(0,l-d),viewportHeight:u}))),e),ge(H(t,$e(r),le(([a,{offsetTop:l}])=>({...a,top:a.top+l}))),o),{customScrollParent:i,useWindowScroll:s,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:r}},ot(_t)),Kx=Ye(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:o},{didMount:s},{useWindowScroll:i,windowScrollContainerState:a,windowViewportRect:l}])=>{const u=qe(),d=X(void 0),f=X(null),h=X(null);return ge(a,f),ge(l,h),Xe(H(u,$e(t,r,i,f,h,n)),([p,w,x,g,v,b,S])=>{const N=Ax(w.sizeTree);g&&v!==null&&b!==null&&(x=v.scrollTop-b.offsetTop),x-=S,p({ranges:N,scrollTop:x})}),ge(H(d,_e(Ti),le(qx)),o),ge(H(s,$e(d),_e(([,p])=>p!==void 0),st(),le(([,p])=>p.ranges)),e),{getState:u,restoreStateFrom:d}},ot(hn,_t,Xr,Dn,$i));function qx(e){return{align:"start",index:0,offset:e.scrollTop}}const Gx=Ye(([{topItemsIndexes:e}])=>{const t=X(0);return ge(H(t,_e(n=>n>=0),le(n=>Array.from({length:n}).map((r,o)=>o))),e),{topItemCount:t}},ot(Zn));function tu(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const Yx=tu(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),Xx=Ye(([{deviation:e,scrollBy:t,scrollingInProgress:n,scrollTop:r},{isAtBottom:o,isScrolling:s,lastJumpDueToItemResize:i,scrollDirection:a},{listState:l},{beforeUnshiftWith:u,gap:d,shiftWithOffset:f,sizes:h},{log:p},{recalcInProgress:w}])=>{const x=Ft(H(l,$e(i),fn(([,v,b,S],[{bottom:N,items:C,offsetBottom:k,totalCount:E},A])=>{const j=N+k;let P=0;return b===E&&v.length>0&&C.length>0&&(C[0].originalIndex===0&&v[0].originalIndex===0||(P=j-S,P!==0&&(P+=A))),[P,C,E,j]},[0,[],0,0]),_e(([v])=>v!==0),$e(r,a,n,o,p,w),_e(([,v,b,S,,,N])=>!N&&!S&&v!==0&&b===Jr),le(([[v],,,,,b])=>(b("Upward scrolling compensation",{amount:v},Mt.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 Xe(H(x,$e(e,s)),([v,b,S])=>{S&&Yx()?Le(e,b-v):g(-v)}),Xe(H(pt(kt(s,!1),e,w),_e(([v,b,S])=>!v&&!S&&b!==0),le(([v,b])=>b),kn(1)),g),ge(H(f,le(v=>({top:-v}))),t),Xe(H(u,$e(h,d),le(([v,{groupIndices:b,lastSize:S,sizeTree:N},C])=>{function k(E){return E*(S+C)}if(b.length===0)return k(v);{let E=0;const A=Kr(N,0);let j=0,P=0;for(;j<v;){j++,E+=A;let L=b.length===P+1?1/0:b[P+1]-b[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(w,!1)})})}),{deviation:e}},ot(_t,Qr,Zn,hn,On,Ri)),Jx=Ye(([e,t,n,r,o,s,i,a,l,u,d])=>({...e,...t,...n,...r,...o,...s,...i,...a,...l,...u,...d}),ot(Li,Wx,Dn,eu,Xc,Vx,zx,$i,Zc,On,Jc)),nu=Ye(([{data:e,defaultItemSize:t,firstItemIndex:n,fixedItemSize:r,gap:o,groupIndices:s,itemSize:i,sizeRanges:a,sizes:l,statefulTotalCount:u,totalCount:d,trackItemSizes:f},{initialItemFinalLocationReached:h,initialTopMostItemIndex:p,scrolledToInitialItem:w},x,g,v,{listState:b,topItemsIndexes:S,...N},{scrollToIndex:C},k,{topItemCount:E},{groupCounts:A},j])=>(ge(N.rangeChanged,j.scrollSeekRangeChanged),ge(H(j.windowViewportRect,le(P=>P.visibleHeight)),x.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:n,fixedItemHeight:r,gap:o,groupCounts:A,initialItemFinalLocationReached:h,initialTopMostItemIndex:p,scrolledToInitialItem:w,sizeRanges:a,topItemCount:E,topItemsIndexes:S,totalCount:d,...v,groupIndices:s,itemSize:i,listState:b,scrollToIndex:C,statefulTotalCount:u,trackItemSizes:f,...N,...j,...x,sizes:l,...g}),ot(hn,Xr,_t,Kx,Ux,Zn,Yr,Xx,Gx,Hc,Jx));function Zx(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 Wo=typeof document<"u"?y.useLayoutEffect:y.useEffect;function ru(e,t,n){const r=Object.keys(t.required||{}),o=Object.keys(t.optional||{}),s=Object.keys(t.methods||{}),i=Object.keys(t.events||{}),a=y.createContext({});function l(g,v){g.propsReady&&Le(g.propsReady,!1);for(const b of r){const S=g[t.required[b]];Le(S,v[b])}for(const b of o)if(b in v){const S=g[t.optional[b]];Le(S,v[b])}g.propsReady&&Le(g.propsReady,!0)}function u(g){return s.reduce((v,b)=>(v[b]=S=>{const N=g[t.methods[b]];Le(N,S)},v),{})}function d(g){return i.reduce((v,b)=>(v[b]=px(g[t.events[b]]),v),{})}const f=y.forwardRef((g,v)=>{const{children:b,...S}=g,[N]=y.useState(()=>Do(gx(e),E=>{l(E,S)})),[C]=y.useState(Ic(d,N));Wo(()=>{for(const E of i)E in S&&Xe(C[E],S[E]);return()=>{Object.values(C).map(ki)}},[S,C,N]),Wo(()=>{l(N,S)}),y.useImperativeHandle(v,Tc(u(N)));const k=n;return c.jsx(a.Provider,{value:N,children:n?c.jsx(k,{...Zx([...r,...o,...i],S),children:b}):b})}),h=g=>{const v=y.useContext(a);return y.useCallback(b=>{Le(v[g],b)},[v,g])},p=g=>{const v=y.useContext(a)[g],b=y.useCallback(S=>Xe(v,S),[v]);return y.useSyncExternalStore(b,()=>ft(v),()=>ft(v))},w=g=>{const v=y.useContext(a)[g],[b,S]=y.useState(Ic(ft,v));return Wo(()=>Xe(v,N=>{N!==b&&S(Tc(N))}),[v,b]),b},x=y.version.startsWith("18")?p:w;return{Component:f,useEmitter:(g,v)=>{const b=y.useContext(a)[g];Wo(()=>Xe(b,v),[v,b])},useEmitterValue:x,usePublisher:h}}const ou=y.createContext(void 0),su=y.createContext(void 0),iu=typeof document<"u"?y.useLayoutEffect:y.useEffect;function zi(e){return"self"in e}function Qx(e){return"body"in e}function au(e,t,n,r=br,o,s){const i=y.useRef(null),a=y.useRef(null),l=y.useRef(null),u=y.useCallback(h=>{let p,w,x;const g=h.target;if(Qx(g)||zi(g)){const b=zi(g)?g:g.defaultView;x=s?b.scrollX:b.scrollY,p=s?b.document.documentElement.scrollWidth:b.document.documentElement.scrollHeight,w=s?b.innerWidth:b.innerHeight}else x=s?g.scrollLeft:g.scrollTop,p=s?g.scrollWidth:g.scrollHeight,w=s?g.offsetWidth:g.offsetHeight;const v=()=>{e({scrollHeight:p,scrollTop:Math.max(x,0),viewportHeight:w})};h.suppressFlushSync?v():Zs.flushSync(v),a.current!==null&&(x===a.current||x<=0||x===p-w)&&(a.current=null,t(!0),l.current&&(clearTimeout(l.current),l.current=null))},[e,t,s]);y.useEffect(()=>{const h=o||i.current;return r(o||i.current),u({suppressFlushSync:!0,target:h}),h.addEventListener("scroll",u,{passive:!0}),()=>{r(null),h.removeEventListener("scroll",u)}},[i,u,n,r,o]);function d(h){const p=i.current;if(!p||(s?"offsetWidth"in p&&p.offsetWidth===0:"offsetHeight"in p&&p.offsetHeight===0))return;const w=h.behavior==="smooth";let x,g,v;zi(p)?(g=Math.max(Mn(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=Mn(p,s?"width":"height"),v=p[s?"scrollLeft":"scrollTop"]);const b=g-x;if(h.top=Math.ceil(Math.max(Math.min(b,h.top),0)),Wc(x,g)||h.top===v){e({scrollHeight:g,scrollTop:v,viewportHeight:x}),w&&t(!0);return}w?(a.current=h.top,l.current&&clearTimeout(l.current),l.current=setTimeout(()=>{l.current=null,a.current=null,t(!0)},1e3)):a.current=null,s&&(h={behavior:h.behavior,left:h.top}),p.scrollTo(h)}function f(h){s&&(h={behavior:h.behavior,left:h.top}),i.current.scrollBy(h)}return{scrollByCallback:f,scrollerRef:i,scrollToCallback:d}}const Bi="-webkit-sticky",lu="sticky",Hi=tu(()=>{if(typeof document>"u")return lu;const e=document.createElement("div");return e.style.position=Bi,e.style.position===Bi?Bi:lu});function Ui(e){return e}const ev=Ye(()=>{const e=X(a=>`Item ${a}`),t=X(a=>`Group ${a}`),n=X({}),r=X(Ui),o=X("div"),s=X(br),i=(a,l=null)=>kt(H(n,le(u=>u[a]),st()),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")}}),tv=Ye(([e,t])=>({...e,...t}),ot(nu,ev)),nv=({height:e})=>c.jsx("div",{style:{height:e}}),rv={overflowAnchor:"none",position:Hi(),zIndex:1},cu={overflowAnchor:"none"},ov={...cu,display:"inline-block",height:"100%"},uu=y.memo(function({showTopList:e=!1}){const t=Pe("listState"),n=Vt("sizeRanges"),r=Pe("useWindowScroll"),o=Pe("customScrollParent"),s=Vt("windowScrollContainerState"),i=Vt("scrollContainerState"),a=o||r?s:i,l=Pe("itemContent"),u=Pe("context"),d=Pe("groupContent"),f=Pe("trackItemSizes"),h=Pe("itemSize"),p=Pe("log"),w=Vt("gap"),x=Pe("horizontalDirection"),{callbackRef:g}=wx(n,h,f,e?br:a,p,w,o,x,Pe("skipAnimationFrameInResizeObserver")),[v,b]=y.useState(0);Wi("deviation",M=>{v!==M&&b(M)});const S=Pe("EmptyPlaceholder"),N=Pe("ScrollSeekPlaceholder")||nv,C=Pe("ListComponent"),k=Pe("ItemComponent"),E=Pe("GroupComponent"),A=Pe("computeItemKey"),j=Pe("isSeeking"),P=Pe("groupIndices").length>0,L=Pe("alignToBottom"),F=Pe("initialItemFinalLocationReached"),V=e?{}:{boxSizing:"border-box",...x?{display:"inline-block",height:"100%",marginLeft:v!==0?v:L?"auto":0,paddingLeft:t.offsetTop,paddingRight:t.offsetBottom,whiteSpace:"nowrap"}:{marginTop:v!==0?v:L?"auto":0,paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},...F?{}:{visibility:"hidden"}};return!e&&t.totalCount===0&&S?c.jsx(S,{...It(S,u)}):c.jsx(C,{...It(C,u),"data-testid":e?"virtuoso-top-item-list":"virtuoso-item-list",ref:g,style:V,children:(e?t.topItems:t.items).map(M=>{const Y=M.originalIndex,K=A(Y+t.firstItemIndex,M.data,u);return j?y.createElement(N,{...It(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,{...It(E,u),"data-index":Y,"data-item-index":M.index,"data-known-size":M.size,key:K,style:rv},d(M.index,u)):y.createElement(k,{...It(k,u),...lv(k,M.data),"data-index":Y,"data-item-group-index":M.groupIndex,"data-item-index":M.index,"data-known-size":M.size,key:K,style:x?ov:cu},P?l(M.index,M.groupIndex,M.data,u):l(M.index,M.data,u))})})}),sv={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},iv={outline:"none",overflowX:"auto",position:"relative"},Vo=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),av={position:Hi(),top:0,width:"100%",zIndex:1};function It(e,t){if(typeof e!="string")return{context:t}}function lv(e,t){return{item:typeof e=="string"?void 0:t}}const cv=y.memo(function(){const e=Pe("HeaderComponent"),t=Vt("headerHeight"),n=Pe("HeaderFooterTag"),r=Xn(y.useMemo(()=>s=>{t(Mn(s,"height"))},[t]),!0,Pe("skipAnimationFrameInResizeObserver")),o=Pe("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...It(e,o)})}):null}),uv=y.memo(function(){const e=Pe("FooterComponent"),t=Vt("footerHeight"),n=Pe("HeaderFooterTag"),r=Xn(y.useMemo(()=>s=>{t(Mn(s,"height"))},[t]),!0,Pe("skipAnimationFrameInResizeObserver")),o=Pe("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...It(e,o)})}):null});function du({useEmitter:e,useEmitterValue:t,usePublisher:n}){return y.memo(function({children:r,style:o,context:s,...i}){const a=n("scrollContainerState"),l=t("ScrollerComponent"),u=n("smoothScrollTargetReached"),d=t("scrollerRef"),f=t("horizontalDirection")||!1,{scrollByCallback:h,scrollerRef:p,scrollToCallback:w}=au(a,u,l,d,void 0,f);return e("scrollTo",w),e("scrollBy",h),c.jsx(l,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:p,style:{...f?iv:sv,...o},tabIndex:0,...i,...It(l,s),children:r})})}function fu({useEmitter:e,useEmitterValue:t,usePublisher:n}){return y.memo(function({children:r,style:o,context:s,...i}){const a=n("windowScrollContainerState"),l=t("ScrollerComponent"),u=n("smoothScrollTargetReached"),d=t("totalListHeight"),f=t("deviation"),h=t("customScrollParent"),p=y.useRef(null),w=t("scrollerRef"),{scrollByCallback:x,scrollerRef:g,scrollToCallback:v}=au(a,u,l,w,h);return iu(()=>{var b;return g.current=h||((b=p.current)==null?void 0:b.ownerDocument.defaultView),()=>{g.current=null}},[g,h]),e("windowScrollTo",v),e("scrollBy",x),c.jsx(l,{ref:p,"data-virtuoso-scroller":!0,style:{position:"relative",...o,...d!==0?{height:d+f}:{}},...i,...It(l,s),children:r})})}const dv=({children:e})=>{const t=y.useContext(ou),n=Vt("viewportHeight"),r=Vt("fixedItemHeight"),o=Pe("alignToBottom"),s=Pe("horizontalDirection"),i=y.useMemo(()=>kc(n,l=>Mn(l,s?"width":"height")),[n,s]),a=Xn(i,!0,Pe("skipAnimationFrameInResizeObserver"));return y.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),c.jsx("div",{"data-viewport-type":"element",ref:a,style:Vo(o),children:e})},fv=({children:e})=>{const t=y.useContext(ou),n=Vt("windowViewportRect"),r=Vt("fixedItemHeight"),o=Pe("customScrollParent"),s=_c(n,o,Pe("skipAnimationFrameInResizeObserver")),i=Pe("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:Vo(i),children:e})},hv=({children:e})=>{const t=Pe("TopItemListComponent")||"div",n=Pe("headerHeight"),r={...av,marginTop:`${n}px`},o=Pe("context");return c.jsx(t,{style:r,...It(t,o),children:e})},pv=y.memo(function(e){const t=Pe("useWindowScroll"),n=Pe("topItemsIndexes").length>0,r=Pe("customScrollParent"),o=Pe("context");return c.jsxs(r||t?xv:gv,{...e,context:o,children:[n&&c.jsx(hv,{children:c.jsx(uu,{showTopList:!0})}),c.jsxs(r||t?fv:dv,{children:[c.jsx(cv,{}),c.jsx(uu,{}),c.jsx(uv,{})]})]})}),{Component:mv,useEmitter:Wi,useEmitterValue:Pe,usePublisher:Vt}=ru(tv,{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"}},pv),gv=du({useEmitter:Wi,useEmitterValue:Pe,usePublisher:Vt}),xv=fu({useEmitter:Wi,useEmitterValue:Pe,usePublisher:Vt}),vv=mv;ot(nu,Ye(()=>{const e=X(u=>c.jsxs("td",{children:["Item $",u]})),t=X(null),n=X(u=>c.jsxs("td",{colSpan:1e3,children:["Group ",u]})),r=X(null),o=X(null),s=X({}),i=X(Ui),a=X(br),l=(u,d=null)=>kt(H(s,le(f=>f[u]),st()),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")}})),Hi();const hu={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},wv={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:pu,floor:Ko,max:eo,min:Vi,round:mu}=Math;function gu(e,t,n){return Array.from({length:t-e+1}).map((r,o)=>({data:n===null?null:n[o+e],index:o+e}))}function bv(e){return{...wv,items:e}}function qo(e,t){return e&&e.width===t.width&&e.height===t.height}function yv(e,t){return e&&e.column===t.column&&e.row===t.row}const Sv=Ye(([{increaseViewportBy:e,listBoundary:t,overscan:n,visibleRange:r},{footerHeight:o,headerHeight:s,scrollBy:i,scrollContainerState:a,scrollTo:l,scrollTop:u,smoothScrollTargetReached:d,viewportHeight:f},h,p,{didMount:w,propsReady:x},{customScrollParent:g,useWindowScroll:v,windowScrollContainerState:b,windowScrollTo:S,windowViewportRect:N},C])=>{const k=X(0),E=X(0),A=X(hu),j=X({height:0,width:0}),P=X({height:0,width:0}),L=qe(),F=qe(),V=X(0),M=X(null),Y=X({column:0,row:0}),K=qe(),W=qe(),z=X(!1),$=X(0),ue=X(!0),D=X(!1),ee=X(!1);Xe(H(w,$e($),_e(([O,J])=>!!J)),()=>{Le(ue,!1)}),Xe(H(pt(w,ue,P,j,$,D),_e(([O,J,te,G,,se])=>O&&!J&&te.height!==0&&G.height!==0&&!se)),([,,,,O])=>{Le(D,!0),Mi(1,()=>{Le(L,O)}),en(H(u),()=>{Le(t,[0,0]),Le(ue,!0)})}),ge(H(W,_e(O=>O!=null&&O.scrollTop>0),dn(0)),E),Xe(H(w,$e(W),_e(([,O])=>O!=null)),([,O])=>{O&&(Le(j,O.viewport),Le(P,O.item),Le(Y,O.gap),O.scrollTop>0&&(Le(z,!0),en(H(u,Yn(1)),J=>{Le(z,!1)}),Le(l,{top:O.scrollTop})))}),ge(H(j,le(({height:O})=>O)),f),ge(H(pt(Ie(j,qo),Ie(P,qo),Ie(Y,(O,J)=>O&&O.column===J.column&&O.row===J.row),Ie(u)),le(([O,J,te,G])=>({gap:te,item:J,scrollTop:G,viewport:O}))),K),ge(H(pt(Ie(k),r,Ie(Y,yv),Ie(P,qo),Ie(j,qo),Ie(M),Ie(E),Ie(z),Ie(ue),Ie($)),_e(([,,,,,,,O])=>!O),le(([O,[J,te],G,se,Ve,Je,nt,,De,Be])=>{const{column:Ee,row:Ze}=G,{height:wt,width:ht}=se,{width:Z}=Ve;if(nt===0&&(O===0||Z===0))return hu;if(ht===0){const St=Di(Be,O),Ut=St+Math.max(nt-1,0);return bv(gu(St,Ut,Je))}const re=xu(Z,ht,Ee);let pe,Ne;De?J===0&&te===0&&nt>0?(pe=0,Ne=nt-1):(pe=re*Ko((J+Ze)/(wt+Ze)),Ne=re*pu((te+Ze)/(wt+Ze))-1,Ne=Vi(O-1,eo(Ne,re-1)),pe=Vi(Ne,eo(0,pe))):(pe=0,Ne=-1);const we=gu(pe,Ne,Je),{bottom:Ae,top:Qe}=vu(Ve,G,se,we),ze=pu(O/re),lt=ze*wt+(ze-1)*Ze-Ae;return{bottom:Ae,itemHeight:wt,items:we,itemWidth:ht,offsetBottom:lt,offsetTop:Qe,top:Qe}})),A),ge(H(M,_e(O=>O!==null),le(O=>O.length)),k),ge(H(pt(j,P,A,Y),_e(([O,J,{items:te}])=>te.length>0&&J.height!==0&&O.height!==0),le(([O,J,{items:te},G])=>{const{bottom:se,top:Ve}=vu(O,G,J,te);return[Ve,se]}),st(qr)),t);const fe=X(!1);ge(H(u,$e(fe),le(([O,J])=>J||O!==0)),fe);const ve=Ft(H(pt(A,k),_e(([{items:O}])=>O.length>0),$e(fe),_e(([[O,J],te])=>{const G=O.items[O.items.length-1].index===J-1;return(te||O.bottom>0&&O.itemHeight>0&&O.offsetBottom===0&&O.items.length===J)&&G}),le(([[,O]])=>O-1),st())),be=Ft(H(Ie(A),_e(({items:O})=>O.length>0&&O[0].index===0),dn(0),st())),ye=Ft(H(Ie(A),$e(z),_e(([{items:O},J])=>O.length>0&&!J),le(([{items:O}])=>({endIndex:O[O.length-1].index,startIndex:O[0].index})),st(Lc),kn(0)));ge(ye,p.scrollSeekRangeChanged),ge(H(L,$e(j,P,k,Y),le(([O,J,te,G,se])=>{const Ve=Uc(O),{align:Je,behavior:nt,offset:De}=Ve;let Be=Ve.index;Be==="LAST"&&(Be=G-1),Be=eo(0,Be,Vi(G-1,Be));let Ee=Ki(J,se,te,Be);return Je==="end"?Ee=mu(Ee-J.height+te.height):Je==="center"&&(Ee=mu(Ee-J.height/2+te.height/2)),De&&(Ee+=De),{behavior:nt,top:Ee}})),l);const q=kt(H(A,le(O=>O.offsetBottom+O.bottom)),0);return ge(H(N,le(O=>({height:O.visibleHeight,width:O.visibleWidth}))),j),{customScrollParent:g,data:M,deviation:V,footerHeight:o,gap:Y,headerHeight:s,increaseViewportBy:e,initialItemCount:E,itemDimensions:P,overscan:n,restoreStateFrom:W,scrollBy:i,scrollContainerState:a,scrollHeight:F,scrollTo:l,scrollToIndex:L,scrollTop:u,smoothScrollTargetReached:d,totalCount:k,useWindowScroll:v,viewportDimensions:j,windowScrollContainerState:b,windowScrollTo:S,windowViewportRect:N,...p,gridState:A,horizontalDirection:ee,initialTopMostItemIndex:$,totalListHeight:q,...h,endReached:ve,propsReady:x,rangeChanged:ye,startReached:be,stateChanged:K,stateRestoreInProgress:z,...C}},ot(Li,_t,Qr,eu,Dn,$i,On));function xu(e,t,n){return eo(1,Ko((e+n)/(Ko(t)+n)))}function vu(e,t,n,r){const{height:o}=n;if(o===void 0||r.length===0)return{bottom:0,top:0};const s=Ki(e,t,n,r[0].index);return{bottom:Ki(e,t,n,r[r.length-1].index)+o,top:s}}function Ki(e,t,n,r){const o=xu(e.width,n.width,t.column),s=Ko(r/o),i=s*n.height+eo(0,s-1)*t.row;return i>0?i+t.row:i}const Cv=Ye(()=>{const e=X(f=>`Item ${f}`),t=X({}),n=X(null),r=X("virtuoso-grid-item"),o=X("virtuoso-grid-list"),s=X(Ui),i=X("div"),a=X(br),l=(f,h=null)=>kt(H(t,le(p=>p[f]),st()),h),u=X(!1),d=X(!1);return ge(Ie(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")}}),Tv=Ye(([e,t])=>({...e,...t}),ot(Sv,Cv)),kv=y.memo(function(){const e=at("gridState"),t=at("listClassName"),n=at("itemClassName"),r=at("itemContent"),o=at("computeItemKey"),s=at("isSeeking"),i=Kt("scrollHeight"),a=at("ItemComponent"),l=at("ListComponent"),u=at("ScrollSeekPlaceholder"),d=at("context"),f=Kt("itemDimensions"),h=Kt("gap"),p=at("log"),w=at("stateRestoreInProgress"),x=Kt("reportReadyState"),g=Xn(y.useMemo(()=>v=>{const b=v.parentElement.parentElement.scrollHeight;i(b);const S=v.firstChild;if(S){const{height:N,width:C}=S.getBoundingClientRect();f({height:N,width:C})}h({column:bu("column-gap",getComputedStyle(v).columnGap,p),row:bu("row-gap",getComputedStyle(v).rowGap,p)})},[i,f,h,p]),!0,!1);return iu(()=>{e.itemHeight>0&&e.itemWidth>0&&x(!0)},[e]),w?null:c.jsx(l,{className:t,ref:g,...It(l,d),"data-testid":"virtuoso-item-list",style:{paddingBottom:e.offsetBottom,paddingTop:e.offsetTop},children:e.items.map(v=>{const b=o(v.index,v.data,d);return s?c.jsx(u,{...It(u,d),height:e.itemHeight,index:v.index,width:e.itemWidth},b):y.createElement(a,{...It(a,d),className:n,"data-index":v.index,key:b},r(v.index,v.data,d))})})}),Iv=y.memo(function(){const e=at("HeaderComponent"),t=Kt("headerHeight"),n=at("headerFooterTag"),r=Xn(y.useMemo(()=>s=>{t(Mn(s,"height"))},[t]),!0,!1),o=at("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...It(e,o)})}):null}),Ev=y.memo(function(){const e=at("FooterComponent"),t=Kt("footerHeight"),n=at("headerFooterTag"),r=Xn(y.useMemo(()=>s=>{t(Mn(s,"height"))},[t]),!0,!1),o=at("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...It(e,o)})}):null}),Nv=({children:e})=>{const t=y.useContext(su),n=Kt("itemDimensions"),r=Kt("viewportDimensions"),o=Xn(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:Vo(!1),children:e})},Av=({children:e})=>{const t=y.useContext(su),n=Kt("windowViewportRect"),r=Kt("itemDimensions"),o=at("customScrollParent"),s=_c(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:Vo(!1),children:e})},_v=y.memo(function({...e}){const t=at("useWindowScroll"),n=at("customScrollParent"),r=n||t?Rv:jv,o=n||t?Av:Nv,s=at("context");return c.jsx(r,{...e,...It(r,s),children:c.jsxs(o,{children:[c.jsx(Iv,{}),c.jsx(kv,{}),c.jsx(Ev,{})]})})}),{useEmitter:wu,useEmitterValue:at,usePublisher:Kt}=ru(Tv,{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"}},_v),jv=du({useEmitter:wu,useEmitterValue:at,usePublisher:Kt}),Rv=fu({useEmitter:wu,useEmitterValue:at,usePublisher:Kt});function bu(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Mt.WARN),t==="normal"?0:parseInt(t??"0",10)}const Pv=xo.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:Q(Pv({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 Ov(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 pn(e,t=[]){let n=[];function r(s,i){const a=m.createContext(i),l=n.length;n=[...n,i];const u=f=>{var v;const{scope:h,children:p,...w}=f,x=((v=h==null?void 0:h[e])==null?void 0:v[l])||a,g=m.useMemo(()=>w,Object.values(w));return c.jsx(x.Provider,{value:g,children:p})};u.displayName=s+"Provider";function d(f,h){var x;const p=((x=h==null?void 0:h[e])==null?void 0:x[l])||a,w=m.useContext(p);if(w)return w;if(i!==void 0)return i;throw new Error(`\`${f}\` must be used within \`${s}\``)}return[u,d]}const o=()=>{const s=n.map(i=>m.createContext(i));return function(a){const l=(a==null?void 0:a[e])||s;return m.useMemo(()=>({[`__scope${e}`]:{...a,[e]:l}}),[a,l])}};return o.scopeName=e,[r,Mv(o,...t)]}function Mv(...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 vt=globalThis!=null&&globalThis.document?m.useLayoutEffect:()=>{},Dv=m[" useInsertionEffect ".trim().toString()]||vt;function Qn({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=Lv({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=Fv(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 Lv({defaultProp:e,onChange:t}){const[n,r]=m.useState(e),o=m.useRef(n),s=m.useRef(t);return Dv(()=>{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 Fv(e){return typeof e=="function"}function yu(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function Gi(...e){return t=>{let n=!1;const r=e.map(o=>{const s=yu(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():yu(e[o],null)}}}}function We(...e){return m.useCallback(Gi(...e),e)}var $v=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],je=$v.reduce((e,t)=>{const n=Vn.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 Su(e,t){e&&vo.flushSync(()=>e.dispatchEvent(t))}function zv(e,t){return m.useReducer((n,r)=>t[n][r]??n,e)}var zt=e=>{const{present:t,children:n}=e,r=Bv(t),o=typeof n=="function"?n({present:r.isPresent}):m.Children.only(n),s=We(r.ref,Hv(o));return typeof n=="function"||r.isPresent?m.cloneElement(o,{ref:s}):null};zt.displayName="Presence";function Bv(e){const[t,n]=m.useState(),r=m.useRef(null),o=m.useRef(e),s=m.useRef("none"),i=e?"mounted":"unmounted",[a,l]=zv(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return m.useEffect(()=>{const u=Go(r.current);s.current=a==="mounted"?u:"none"},[a]),vt(()=>{const u=r.current,d=o.current;if(d!==e){const h=s.current,p=Go(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]),vt(()=>{if(t){let u;const d=t.ownerDocument.defaultView??window,f=p=>{const x=Go(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=Go(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 Go(e){return(e==null?void 0:e.animationName)||"none"}function Hv(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 Uv=m[" useId ".trim().toString()]||(()=>{}),Wv=0;function mn(e){const[t,n]=m.useState(Uv());return vt(()=>{n(r=>r??String(Wv++))},[e]),e||(t?`radix-${t}`:"")}var Yo="Collapsible",[Vv,NT]=pn(Yo),[Kv,Yi]=Vv(Yo),Cu=m.forwardRef((e,t)=>{const{__scopeCollapsible:n,open:r,defaultOpen:o,disabled:s,onOpenChange:i,...a}=e,[l,u]=Qn({prop:r,defaultProp:o??!1,onChange:i,caller:Yo});return c.jsx(Kv,{scope:n,disabled:s,contentId:mn(),open:l,onOpenToggle:m.useCallback(()=>u(d=>!d),[u]),children:c.jsx(je.div,{"data-state":Ji(l),"data-disabled":s?"":void 0,...a,ref:t})})});Cu.displayName=Yo;var Tu="CollapsibleTrigger",ku=m.forwardRef((e,t)=>{const{__scopeCollapsible:n,...r}=e,o=Yi(Tu,n);return c.jsx(je.button,{type:"button","aria-controls":o.contentId,"aria-expanded":o.open||!1,"data-state":Ji(o.open),"data-disabled":o.disabled?"":void 0,disabled:o.disabled,...r,ref:t,onClick:de(e.onClick,o.onOpenToggle)})});ku.displayName=Tu;var Xi="CollapsibleContent",qv=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Yi(Xi,e.__scopeCollapsible);return c.jsx(zt,{present:n||o.open,children:({present:s})=>c.jsx(Gv,{...r,ref:t,present:s})})});qv.displayName=Xi;var Gv=m.forwardRef((e,t)=>{const{__scopeCollapsible:n,present:r,children:o,...s}=e,i=Yi(Xi,n),[a,l]=m.useState(r),u=m.useRef(null),d=We(t,u),f=m.useRef(0),h=f.current,p=m.useRef(0),w=p.current,x=i.open||a,g=m.useRef(x),v=m.useRef(void 0);return m.useEffect(()=>{const b=requestAnimationFrame(()=>g.current=!1);return()=>cancelAnimationFrame(b)},[]),vt(()=>{const b=u.current;if(b){v.current=v.current||{transitionDuration:b.style.transitionDuration,animationName:b.style.animationName},b.style.transitionDuration="0s",b.style.animationName="none";const S=b.getBoundingClientRect();f.current=S.height,p.current=S.width,g.current||(b.style.transitionDuration=v.current.transitionDuration,b.style.animationName=v.current.animationName),l(r)}},[i.open,r]),c.jsx(je.div,{"data-state":Ji(i.open),"data-disabled":i.disabled?"":void 0,id:i.contentId,hidden:!x,...s,ref:d,style:{"--radix-collapsible-content-height":h?`${h}px`:void 0,"--radix-collapsible-content-width":w?`${w}px`:void 0,...e.style},children:x&&o})});function Ji(e){return e?"open":"closed"}var Yv=Cu;const Iu=Yv,Eu=ku,to=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}));to.displayName="Card";const no=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:Q("flex flex-col space-y-1.5 p-6",e),...t}));no.displayName="CardHeader";const ro=m.forwardRef(({className:e,...t},n)=>c.jsx("h3",{ref:n,className:Q("text-2xl font-semibold leading-none tracking-tight",e),...t}));ro.displayName="CardTitle";const Nu=m.forwardRef(({className:e,...t},n)=>c.jsx("p",{ref:n,className:Q("text-sm text-muted-foreground",e),...t}));Nu.displayName="CardDescription";const Xo=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:Q("p-6 pt-0",e),...t}));Xo.displayName="CardContent";const Au=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:Q("flex items-center p-6 pt-0",e),...t}));Au.displayName="CardFooter";function _u(){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 er=_u();function Xv(e){er=e}const ju=/[&<>"']/,Jv=new RegExp(ju.source,"g"),Ru=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,Zv=new RegExp(Ru.source,"g"),Qv={"&":"&","<":"<",">":">",'"':""","'":"'"},Pu=e=>Qv[e];function Et(e,t){if(t){if(ju.test(e))return e.replace(Jv,Pu)}else if(Ru.test(e))return e.replace(Zv,Pu);return e}const ew=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;function Ou(e){return e.replace(ew,(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 tw=/(^|[^\[])\^/g;function tt(e,t){e=typeof e=="string"?e:e.source,t=t||"";const n={replace:(r,o)=>(o=o.source||o,o=o.replace(tw,"$1"),e=e.replace(r,o),n),getRegex:()=>new RegExp(e,t)};return n}const nw=/[^\w:]/g,rw=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function Mu(e,t,n){if(e){let r;try{r=decodeURIComponent(Ou(n)).replace(nw,"").toLowerCase()}catch{return null}if(r.indexOf("javascript:")===0||r.indexOf("vbscript:")===0||r.indexOf("data:")===0)return null}t&&!rw.test(n)&&(n=aw(t,n));try{n=encodeURI(n).replace(/%25/g,"%")}catch{return null}return n}const Jo={},ow=/^[^:]+:\/*[^/]*$/,sw=/^([^:]+:)[\s\S]*$/,iw=/^([^:]+:\/*[^/]*)[\s\S]*$/;function aw(e,t){Jo[" "+e]||(ow.test(e)?Jo[" "+e]=e+"/":Jo[" "+e]=Qo(e,"/",!0)),e=Jo[" "+e];const n=e.indexOf(":")===-1;return t.substring(0,2)==="//"?n?t:e.replace(sw,"$1")+t:t.charAt(0)==="/"?n?t:e.replace(iw,"$1")+t:e+t}const Zo={exec:function(){}};function Du(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 Qo(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 lw(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 cw(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 Lu(e,t){if(t<1)return"";let n="";for(;t>1;)t&1&&(n+=e),t>>=1,e+=e;return n+e}function Fu(e,t,n,r){const o=t.href,s=t.title?Et(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:Et(i)}}function uw(e,t){const n=e.match(/^(\s+)(?:```)/);if(n===null)return t;const r=n[1];return t.split(`
|
|
37
|
+
`))>=0;){const re=K.slice(0,J);K=K.slice(J+2);const he=tx(re);if(!he)continue;let Ce;try{Ce=JSON.parse(he)}catch{console.debug("[use-chat] malformed SSE:",he.slice(0,200));continue}const me=ex(Ce)?Ce.data:Ce;pe=Date.now();const Oe=me.seq;if(Oe!==void 0){if(Oe<=X){console.debug("[use-chat] drop duplicate/out-of-order event",{seq:Oe,lastProcessedSeq:X,type:me.type});continue}X>0&&Oe>X+1&&(($=F==null?void 0:F.onGap)==null||$.call(F,{from:X,to:Oe})),X=Oe,C.current=Oe,g(Oe)}if(console.debug("[use-chat] received event",{seq:me.seq,type:me.type,preview:(()=>{var it;try{return me.type==="message_delta"?{deltaTypes:(it=me.delta)==null?void 0:it.map(Me=>Me.type),textLen:(me.delta||[]).filter(Me=>Me.type==="text").map(Me=>String(Me.text||"").length)}:me.content||me.delta?{hasContent:!0}:{}}catch(Me){return{err:String(Me)}}})()}),L==null||L(me),me.type==="token"&&e.autoAppendAssistant!==!1)O.push(me.content),ne();else if(me.type==="message_delta"){const it=me.delta.filter(Me=>Me.type==="text").map(Me=>Me.text).join("");it&&e.autoAppendAssistant!==!1&&(O.push(it),ne())}else me.type==="heartbeat"?console.debug("[use-chat] heartbeat received"):(ee!==null&&cancelAnimationFrame(ee),fe(),me.type==="checkpoint"?w(me.checkpointId):me.type==="error"&&d(me.message))}}fe()}catch(Pe){if(Pe.name!=="AbortError"){const He=Pe.message||String(Pe);d(He),(ce=F==null?void 0:F.onError)==null||ce.call(F,He)}}finally{try{await ye.cancel()}catch{}finally{(D=ye.releaseLock)==null||D.call(ye)}ee!==null&&typeof window<"u"&&window.cancelAnimationFrame(ee),clearInterval(Ze),l(!1),b(!1),S.current=null,C.current=0,g(0)}}catch(de){if(de.name!=="AbortError"){const we=de.message||String(de);d(we),(Q=F==null?void 0:F.onError)==null||Q.call(F,we)}}finally{l(!1),b(!1),S.current=null,C.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:I,clear:A,setToken:k}}function ex(e){return!!e&&typeof e=="object"&&e.protocolVersion==="v1"&&"data"in e}function tx(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 nx({baseUrl:e,onThreadInfo:t,onMessageEvent:n,onUnhandledEvent:r,onSequenceGap:o}){const s=y.useRef(null),i=y.useCallback(p=>{const w=p.seq??null;if(w!==null){const x=s.current;if(x!==null){if(w<=x)return;w>x+1&&(o==null||o({from:x,to:w}))}s.current=w}if(p.type==="thread_info"){console.log("[useChatStreamingService] 🎯 Received thread_info event:",p),t(p);return}if(Gg(p)){n(p);return}r==null||r(p)},[n,o,t,r]),{stream:a,stop:l,isStreaming:u,error:d,setToken:f}=bc({baseUrl:e,token:null}),h=y.useCallback((p,w)=>{s.current=null,a(p,i,{onOpen:w==null?void 0:w.onOpen,onError:x=>{var g;(g=w==null?void 0:w.onError)==null||g.call(w,x)},onGap:(w==null?void 0:w.onGap)??o})},[i,o,a]);return y.useMemo(()=>({startStream:h,stop:l,isStreaming:u,error:d,setAuthToken:f}),[h,l,u,d,f])}const yc=y.createContext(null),Sc=y.createContext(null),Cc=y.createContext(null),rx=y.createContext(!1),ox="cachedThreads",sx="v1",Po=300,Si=200;function ix(e,t){if(!e&&!t)return!0;if(!e||!t||e.id!==t.id)return!1;try{return JSON.stringify(e.value)===JSON.stringify(t.value)}catch{return e.value===t.value}}function ax(e){var t;for(let n=e.length-1;n>=0;n--){const r=((t=e[n])==null?void 0:t.content)??[];for(let o=r.length-1;o>=0;o--){const s=r[o];if((s==null?void 0:s.type)==="interrupt"){const i=s.id;return{id:(typeof i=="string"?i:null)??`interrupt-${e[n].id??o}`,value:s.value}}}}return null}function Tc(e){if(typeof window<"u"&&"requestIdleCallback"in window)try{window.requestIdleCallback(e,{timeout:1e3});return}catch{}window.setTimeout(e,Po)}function br(){return typeof window<"u"&&typeof window.localStorage<"u"}function Ci(e){if(!br())return null;try{return window.localStorage.getItem(e)}catch{return null}}function kc(e,t){if(br())try{window.localStorage.setItem(e,t)}catch{}}function Ti(e){if(br())try{window.localStorage.removeItem(e)}catch{}}function lx(){const e=Ci(ox);if(!e)return[];try{const t=JSON.parse(e);return Array.isArray(t)?t.filter(n=>{if(!n||typeof n!="object")return!1;const r=n;return typeof r.threadId=="string"&&typeof r.title=="string"}):[]}catch{return[]}}function cx(e){let t=5381;for(let n=0;n<e.length;n++)t=(t<<5)+t^e.charCodeAt(n);return(t>>>0).toString(36)}function ki(e,t){return`cachedThreads:v1:${e}:${cx(t||"anon")}`}function ux(e){const t=Ci(e);if(!t)return[];try{const n=JSON.parse(t);return Array.isArray(n)?n.filter(r=>{if(!r||typeof r!="object")return!1;const o=r;return typeof o.threadId=="string"&&typeof o.title=="string"}):[]}catch{return[]}}function Ei(e,t){try{kc(e,JSON.stringify(t))}catch{}}function Ii(e){const t=ux(e);if(t.length>0)return t;const n=lx();if(n.length>0)try{Ei(e,n.slice(0,Si))}catch{}return n}function Oo(e){const t={},n=[];for(const r of e)!r||typeof r.threadId!="string"||t[r.threadId]||(t[r.threadId]=r,n.push(r.threadId));return{byId:t,order:n}}function Ni(e){return e.order.map(t=>e.byId[t]).filter(Boolean)}function dx({children:e,initialThreadId:t=null,autoLoadInitial:n=!0,disableAutoRestore:r=!1,enableFileAgentRouting:o=!1,fileAgentId:s="invoice_reader",onError:i,onThreadChange:a}){const{api:l,baseUrl:u}=xi(),d=y.useMemo(()=>En(u),[u]),f=y.useMemo(()=>{try{return new URL(u).host}catch{return"unknown"}},[u]),h=y.useMemo(()=>`threadPayload:${sx}:${f}:`,[f]),p=y.useCallback(T=>`${h}${T}`,[h]),w=y.useCallback(T=>{if(!T||typeof T!="object")return null;const _=T;return typeof _.threadId!="string"||!Array.isArray(_.messages)?null:{threadId:_.threadId,messages:_.messages,hasMore:!!_.hasMore,nextCursor:_.nextCursor??null,checkpointId:_.checkpointId??null,checkpointNs:_.checkpointNs??null,nextCursorNs:_.nextCursorNs??null}},[]),x=y.useCallback(T=>{const _=Ci(p(T));if(!_)return null;try{const W=JSON.parse(_);return w(W)}catch{return null}},[p,w]),g=y.useCallback((T,_=100)=>{const W={...T,messages:Array.isArray(T.messages)?T.messages.slice(-_):[]};try{kc(p(T.threadId),JSON.stringify(W))}catch{}},[p]),v=y.useCallback(T=>{Ti(p(T))},[p]),b=y.useCallback(()=>{if(br())try{const T=h;for(let _=0;_<window.localStorage.length;_++){const W=window.localStorage.key(_);W&&W.startsWith(T)&&window.localStorage.removeItem(W)}}catch{}},[h]),[S,N]=y.useState(()=>{var T;return ki(f,(T=l.getAuthToken)==null?void 0:T.call(l))}),[C,k]=y.useState(()=>{var _;const T=Ii(ki(f,(_=l.getAuthToken)==null?void 0:_.call(l)));return Oo(T)}),I=y.useMemo(()=>Ni(C),[C]),[A,j]=y.useState(t),[P,L]=y.useState(!1),[F,V]=y.useState(!1),[M,G]=y.useState(null),[q,U]=y.useState(null),[B,$]=y.useState(null),ce=y.useCallback(()=>{const T=Ii(S);y.startTransition(()=>{k(Oo(T))})},[S]),[D,Q]=y.useState(!1),[de,we]=y.useState(!1),[ye,Se]=y.useState(null),[K,O]=y.useState(void 0),[X,ee]=y.useState(void 0),[fe,ne]=y.useState(void 0),{state:pe,dispatch:Ze,seed:Qe,prepend:Pe,pushUser:He,onEvent:ct,reset:tt}=dc(),Be=y.useRef(A);y.useEffect(()=>{Be.current=A},[A]);const gt=y.useRef(!1),J=y.useRef([]),re=y.useRef(null),he=y.useRef(null),Ce=y.useRef(new Map),me=y.useRef(A),Oe=y.useRef(!1),it=y.useRef(null),Me=y.useRef(new Map),et=y.useCallback((T,_,W)=>{if(!T)return;const xe=W==="replace"?[]:Me.current.get(T)??[],ie=W==="replace"?_:[..._,...xe];if(!ie.length){W==="replace"&&Me.current.set(T,[]);return}const Ie=new Map;for(const st of ie){if(!(st!=null&&st.checkpointId))continue;const Xe=`${st.checkpointId}::${st.checkpointNs??""}`;Ie.has(Xe)||Ie.set(Xe,st)}const ge=Array.from(Ie.values()).sort((st,Xe)=>{const ut=Number.isFinite(Date.parse(st.createdAt))?Date.parse(st.createdAt):0;return(Number.isFinite(Date.parse(Xe.createdAt))?Date.parse(Xe.createdAt):0)-ut});Me.current.set(T,ge)},[]),vt=y.useCallback((T,_)=>new Promise((W,xe)=>{const ie=async()=>{gt.current=!0;try{await T(),W()}catch(Ie){xe(Ie)}finally{gt.current=!1;const Ie=J.current.shift();Ie&&Ie().catch(()=>{})}};gt.current?J.current.push(ie):ie().catch(Ie=>{xe(Ie)})}),[]),Zt=y.useRef(I.length),[qn,Mr]=y.useState(!1),mr=y.useRef(!1);y.useEffect(()=>{Zt.current=I.length},[I.length]),y.useEffect(()=>{const T=pe.pendingInterrupt??ax(pe.messages);ix(B,T)||$(T??null)},[B,pe.messages,pe.pendingInterrupt]);const Rt=y.useCallback(async()=>{const T=Zt.current>0;T||L(!0);try{const _=await l.listThreads();y.startTransition(()=>{k(W=>{const xe=ge=>ge.map(st=>`${st.threadId}:${st.updatedAt??""}:${st.messageCount??""}`).join("|"),ie=Ni(W);return xe(ie)===xe(_)||_.length===0&&ie.length>0&&!mr.current?W:Oo(_)})}),G(null),mr.current||(mr.current=!0,Mr(!0))}catch(_){i==null||i(String(_)),console.error("[ChatSessionProvider] Failed to refresh threads:",_),G(String(_))}finally{T||L(!1)}},[l,i]),wo=y.useRef(!1),_n=y.useRef(null),St=y.useRef(null),At=y.useRef(""),Ut=y.useCallback((T,_)=>{if(!br())return;St.current!==null&&(window.clearTimeout(St.current),St.current=null);const W=T.map(ie=>`${ie.threadId}:${ie.updatedAt??""}:${ie.messageCount??""}`).join("|");if(T.length===0){try{Ti(S)}catch{}At.current="";return}if(W===At.current)return;const xe=()=>{try{const ie=T.slice(0,Si);Ei(S,ie),At.current=W}catch{}finally{St.current=null}};if(_!=null&&_.immediate){xe();return}St.current=window.setTimeout(()=>{Tc(xe)},Po)},[S]),Kn=y.useCallback(()=>{Ut(I,{immediate:!0})},[Ut,I]),dn=y.useCallback((T,_,W)=>{const xe=Array.isArray(T==null?void 0:T.messages)?T.messages:[],ie=W??(T==null?void 0:T.threadId)??Be.current,Ie=ie!=null&&ie===Be.current;if(_==="replace"){if(ie){const ge={threadId:ie,messages:xe.slice(),hasMore:!!(T!=null&&T.hasMore),nextCursor:(T==null?void 0:T.nextCursor)??null,checkpointId:(T==null?void 0:T.checkpointId)??null,checkpointNs:(T==null?void 0:T.checkpointNs)??null,nextCursorNs:(T==null?void 0:T.nextCursorNs)??null};Ce.current.set(ie,ge),me.current=ie}if(!Ie)return;Qe(xe,{checkpointId:(T==null?void 0:T.checkpointId)??null,checkpointNs:(T==null?void 0:T.checkpointNs)??null})}else if(_==="prepend"&&xe.length&&ie){const ge=Ce.current.get(ie),st=(ge==null?void 0:ge.messages)??[],Xe=new Set,ut=[...xe,...st].filter(Qt=>{const en=Qt==null?void 0:Qt.id;return en?Xe.has(en)?!1:(Xe.add(en),!0):!0}),Wt={threadId:ie,messages:ut,hasMore:(T==null?void 0:T.hasMore)??(ge==null?void 0:ge.hasMore)??!1,nextCursor:(T==null?void 0:T.nextCursor)??(ge==null?void 0:ge.nextCursor)??null,checkpointId:(ge==null?void 0:ge.checkpointId)??(T==null?void 0:T.checkpointId)??null,checkpointNs:(ge==null?void 0:ge.checkpointNs)??(T==null?void 0:T.checkpointNs)??null,nextCursorNs:(T==null?void 0:T.nextCursorNs)??(ge==null?void 0:ge.nextCursorNs)??null};if(Ce.current.set(ie,Wt),!Ie)return;Pe(xe)}else _==="prepend"&&xe.length&&Pe(xe);Ie&&(_==="replace"?(Se((T==null?void 0:T.nextCursor)??null),Q(!!(T!=null&&T.hasMore)),O((T==null?void 0:T.checkpointId)??void 0),ee((T==null?void 0:T.checkpointNs)??void 0),ne((T==null?void 0:T.nextCursorNs)??void 0)):(Se(ge=>(T==null?void 0:T.nextCursor)??ge??null),Q(ge=>(T==null?void 0:T.hasMore)!==void 0?!!(T!=null&&T.hasMore):ge),O(ge=>(T==null?void 0:T.checkpointId)??ge??void 0),ee(ge=>(T==null?void 0:T.checkpointNs)??ge??void 0),ne(ge=>(T==null?void 0:T.nextCursorNs)!==void 0?T.nextCursorNs??void 0:ge)))},[Pe,Qe]),gr=y.useCallback(T=>{T.threadId!=null&&T.threadId!==Be.current||(Qe(T.messages,{checkpointId:T.checkpointId,checkpointNs:T.checkpointNs}),Se(T.nextCursor),Q(T.hasMore),O(T.checkpointId??void 0),ee(T.checkpointNs??void 0),ne(T.nextCursorNs??void 0),me.current=T.threadId)},[Qe]),fn=y.useCallback(T=>{T&&(Ce.current.delete(T),v(T),Me.current.delete(T),me.current===T&&(me.current=null))},[v]),kn=y.useCallback(()=>{const T=Be.current;T&&fn(T),tt([]),Q(!1),we(!1),Se(null),O(void 0),ee(void 0),ne(void 0)},[fn,tt]),Gn=y.useCallback(({from:T,to:_})=>{const W=Be.current;W&&console.warn(`[ChatSessionProvider] Stream sequence gap detected (${T} -> ${_}) for thread ${W}`)},[]),Dr=y.useCallback(T=>{const _=T.threadId;console.log("[ChatSessionProvider] 📥 Handling thread_info event:",{threadId:_,title:T.title,created:T.created,currentThreads:I.length});const W={threadId:_,title:T.title||`Thread ${_.slice(0,8)}`,createdAt:T.createdAt||new Date().toISOString(),updatedAt:T.updatedAt||new Date().toISOString(),messageCount:T.messageCount||0};Be.current!==_&&(!Be.current&&pe.messages.length<=1&&(he.current=_),j(_)),y.startTransition(()=>{k(xe=>{const ie=xe.byId[_];return ie?ie.title===W.title&&ie.updatedAt===W.updatedAt&&ie.messageCount===W.messageCount?xe:{byId:{...xe.byId,[_]:W},order:xe.order}:{byId:{...xe.byId,[_]:W},order:[_,...xe.order]}})})},[pe.messages.length]),{startStream:Lr,stop:Fr,isStreaming:jn,error:se,setAuthToken:be}=nx({baseUrl:d,onThreadInfo:Dr,onMessageEvent:ct,onUnhandledEvent:T=>{console.warn(`[ChatSessionProvider] Unhandled stream event: ${T.type}`,T)},onSequenceGap:Gn});y.useEffect(()=>{wo.current=jn},[jn]),y.useEffect(()=>{if(!br())return;St.current!==null&&(window.clearTimeout(St.current),St.current=null);const T=I.map(W=>`${W.threadId}:${W.updatedAt??""}:${W.messageCount??""}`).join("|");if(I.length===0){try{Ti(S)}catch{}At.current="";return}if(T===At.current)return;const _=()=>{try{const W=I.slice(0,Si);Ei(S,W),At.current=T}catch{}finally{St.current=null}};return St.current=window.setTimeout(()=>{Tc(_),St.current=null},Po),()=>{St.current!==null&&(window.clearTimeout(St.current),St.current=null)}},[I,Ut]),y.useEffect(()=>{var xe;const T=l.getAuthToken();be(T);const _=ie=>{const Ie=ki(f,ie);it.current!==Ie&&(it.current=Ie,Oe.current=!1),N(Ie);const ge=Ii(Ie);y.startTransition(()=>{k(Oo(ge))}),Oe.current||(Oe.current=!0,Rt().catch(()=>{}))};_(T);const W=(xe=l.onTokenChange)==null?void 0:xe.call(l,ie=>{be(ie),b(),_(ie)});return()=>{W==null||W()}},[l,f,be,b,Rt]);const Ue=y.useCallback(async T=>{var xe;const _=`Thread ${(xe=crypto.randomUUID)==null?void 0:xe.call(crypto)}`,W={threadId:_,title:T||"New Chat",createdAt:new Date().toISOString(),updatedAt:new Date().toISOString(),messageCount:0};k(ie=>({byId:{...ie.byId,[_]:W},order:[_,...ie.order]})),j(_);try{const ie=await l.createThread(T),Ie=typeof ie=="string"?ie:ie.threadId;return k(ge=>{const st=ge.byId[_];if(!st)return ge;const Xe={...ge.byId};delete Xe[_],Xe[Ie]={...st,threadId:Ie};const ut=ge.order.map(Wt=>Wt===_?Ie:Wt);return{byId:Xe,order:ut}}),j(Ie),setTimeout(()=>Rt(),10),G(null),Ie}catch(ie){throw k(Ie=>{if(!Ie.byId[_])return Ie;const ge={...Ie.byId};delete ge[_];const st=Ie.order.filter(Xe=>Xe!==_);return{byId:ge,order:st}}),j(null),G(String(ie)),ie}},[l,Rt]),ot=y.useCallback(async T=>{try{await l.deleteThread(T);let _=null;k(W=>{if(!W.byId[T])return W;const xe={...W.byId};delete xe[T];const ie=W.order.filter(ge=>ge!==T),Ie={byId:xe,order:ie};return _=Ni(Ie),Ie}),_&&Ut(_,{immediate:!0}),fn(T),Be.current===T&&(he.current=T,j(null),Be.current=null,me.current=null,kn()),await Rt(),G(null)}catch(_){throw G(String(_)),_}},[l,kn,fn,Rt,Ut]),Pt=y.useCallback(async(T,_)=>{try{await l.updateThread(T,_),k(W=>{const xe=W.byId[T];return xe?{byId:{...W.byId,[T]:{...xe,title:_}},order:W.order}:W}),G(null)}catch(W){throw await Rt(),G(String(W)),W}},[l,Rt]),E=y.useCallback(async(T,_,W,xe=!1)=>{await vt(async()=>{if(he.current===T&&!xe){he.current=null;return}if(re.current===T&&!xe)return;j(Xe=>Xe===T?Xe:T),Be.current=T;const ie=!xe&&!_&&!W;let Ie=!1;if(ie){const Xe=Ce.current.get(T);if(Xe)gr(Xe),Ie=!0;else{const ut=x(T);ut&&(Ce.current.set(T,ut),gr(ut),Ie=!0)}}const ge=xe||!Ie||!!_||!!W,st=async Xe=>{Xe&&V(!0),re.current=T;try{const ut=await l.getStateHistory({threadId:T,checkpointId:_,checkpointNs:W}),{payload:Wt,checkpoints:Qt}=wi(ut);dn(Wt,"replace",T),et(T,Qt,"replace"),U(null)}catch(ut){throw(!Ie||xe||Xe)&&(i==null||i(String(ut))),U(String(ut)),ut}finally{re.current=null,Xe&&V(!1)}};ge?await st(!0):ie&&Ie&&st(!1).catch(Xe=>{console.warn("[ChatSessionProvider] Background refresh failed:",Xe)})},`loadThread-${T}`)},[l,gr,dn,vt,i,et]),z=y.useCallback(async()=>{await vt(async()=>{const T=Be.current;T&&fn(T),he.current=null,j(null),Be.current=null,me.current=null,kn(),O(void 0),ee(void 0),ne(void 0);try{localStorage.removeItem("lastThreadId")}catch(_){console.warn("[ChatSessionProvider] Failed to clear lastThreadId:",_)}},"clearCurrentThread")},[kn,fn,vt]),te=y.useCallback(async T=>{const _=Me.current.get(T);if(_)return{threadId:T,checkpoints:_.slice()};const W=await l.getStateHistory({threadId:T}),{checkpoints:xe}=wi(W);et(T,xe,"replace");const ie=Me.current.get(T)??[];return{threadId:T,checkpoints:ie.slice()}},[l,et]),Ee=y.useCallback(async(T,_)=>{if(!Be.current)throw new Error("No active thread");await E(Be.current,T,_??void 0,!0)},[E]),Fe=y.useCallback(async()=>{if(!Be.current)throw new Error("No active thread");await E(Be.current,void 0,void 0,!0)},[E]),Ke=y.useCallback(async()=>{if(!Be.current)throw new Error("No active thread");if(de||!D)return;const T=ye;if(T){we(!0);try{const _=Be.current,W=await l.getStateHistory({threadId:_,checkpointId:T??K,checkpointNs:fe??X}),{payload:xe,checkpoints:ie}=wi(W);dn(xe,"prepend",_??void 0),_&&et(_,ie,"prepend"),U(null)}catch(_){throw U(String(_)),_}finally{we(!1)}}},[l,dn,D,K,X,fe,ye,de,et]),We=y.useCallback(T=>{if(!(T!=null&&T.threadId))return;const _={threadId:T.threadId,checkpointId:T.checkpointId??void 0,checkpointNs:T.checkpointNs??void 0,messages:T.messages??[],hasMore:T.hasMore,nextCursor:T.nextCursor??null,nextCursorNs:T.nextCursorNs??null};dn(_,"replace",T.threadId)},[dn]),ze=y.useCallback(async(T,_)=>{var ei;const W=Be.current,xe=(T==null?void 0:T.text)??"",ie=(T==null?void 0:T.attachments)??[],Ie=ie.length?ie:(_==null?void 0:_.attachments)??[],ge={...(_==null?void 0:_.payloadExtras)??{},...(T==null?void 0:T.payload)??{}};if(!W&&!Object.keys(ge).length&&Ie.length===0&&!xe.trim()){console.warn("[ChatSessionProvider] Nothing to submit - skipping");return}!W&&!ge.messages&&console.warn("[ChatSessionProvider] No thread ID - message will create new thread");const{contentParts:st,filesInfo:Xe}=await Dg(l,Ie),ut=[...st];xe&&xe.trim()&&ut.push({type:"text",text:xe.trim()});const Wt=!!W,Qt=Wt?(_==null?void 0:_.checkpointId)??pe.lastCheckpointId??void 0:void 0,en=Wt?(_==null?void 0:_.checkpointNs)??pe.lastCheckpointNs??void 0:void 0,$r={id:((ei=crypto.randomUUID)==null?void 0:ei.call(crypto))||`user-${Date.now()}`,role:"user",content:ut,createdAt:new Date().toISOString(),...Qt!=null?{checkpointId:Qt}:{},...en!=null?{checkpointNs:en}:{}};ut.length>0&&He($r);const ul={...$r,content:ut},Zs=Ie.length>0,Qs={...W?{threadId:W}:{},payload:{messages:ut.length>0?[ul]:[],files_info:Xe,...o&&Zs&&s?{active_agent:s}:{},...ge},...Qt!=null?{checkpointId:Qt}:{},...en!=null?{checkpointNs:en}:{},nodeFilter:_==null?void 0:_.nodeFilter,config:_==null?void 0:_.config};Lr(Qs,{onError:Rn=>{console.warn("[ChatSessionProvider] Stream error:",Rn)},onOpen:({threadId:Rn})=>{!Be.current&&Rn&&(pe.messages.length<=1&&(he.current=Rn),j(Rn))},onGap:Gn})},[l,o,s,Gn,pe.lastCheckpointId,pe.lastCheckpointNs,pe.messages.length,He,Lr]),wt=y.useCallback(async(T,_,W)=>{var ie,Ie;const xe=Be.current;if(!xe)throw new Error("No active thread to handle interrupt");try{const ge=_?W??!0:!1;try{Ze({type:"interrupt_response",payload:{interruptId:T}})}catch($r){console.warn("[ChatSessionProvider] optimistic interrupt_response dispatch failed:",$r)}const st=`${d}/runs/resume`,Xe=(ie=l.getAuthToken)==null?void 0:ie.call(l),ut=await fetch(st,{method:"POST",headers:{"Content-Type":"application/json",...Xe?{Authorization:`Bearer ${Xe}`}:{}},body:JSON.stringify({thread_id:xe,value:ge})});if(!ut.ok)throw new Error(`Resume failed with status ${ut.status}`);const Wt=(Ie=ut.body)==null?void 0:Ie.getReader();if(!Wt)throw new Error("No response body for resume stream");const Qt=new TextDecoder;let en="";for(;;){const{done:$r,value:ul}=await Wt.read();if($r)break;en+=Qt.decode(ul,{stream:!0});const Zs=en.split(`
|
|
39
|
+
`);en=Zs.pop()||"";for(const Qs of Zs)if(Qs.startsWith("data: ")){const ei=Qs.slice(6);try{const Rn=JSON.parse(ei);Ze({type:"event",payload:{ev:Rn}})}catch(Rn){console.warn("[ChatSessionProvider] Failed to parse resume SSE event:",Rn)}}}$(null)}catch(ge){throw console.error(`[ChatSessionProvider] Failed to handle interrupt ${T}:`,ge),ge}},[l,Ze,d]),ft=y.useCallback(T=>wt(T.interruptId,T.approved,T.value),[wt]);y.useEffect(()=>{if(a==null||a(A),A)try{localStorage.setItem("lastThreadId",A)}catch(T){console.warn("[ChatSessionProvider] Failed to persist lastThreadId:",T)}},[A,a]),y.useEffect(()=>((async()=>{try{if(Rt().catch(_=>{console.error("[ChatSessionProvider] Failed to refresh threads (background):",_),i==null||i(String(_))}),!r&&!t)try{const _=localStorage.getItem("lastThreadId");_&&(j(_),n&&await E(_))}catch(_){console.warn("[ChatSessionProvider] Failed to restore last thread:",_)}else t&&n&&await E(t)}catch(_){console.error("[ChatSessionProvider] Initialization failed:",_),i==null||i(String(_))}})(),()=>{}),[]),y.useEffect(()=>{const T=Be.current;if(!T||me.current!==T)return;const _={threadId:T,messages:pe.messages.slice(),hasMore:D,nextCursor:ye,checkpointId:pe.lastCheckpointId??null,checkpointNs:pe.lastCheckpointNs??null,nextCursorNs:fe??null},W=Ce.current.get(T);(!W||W.messages.length!==_.messages.length||W.messages.some((ie,Ie)=>{var ge;return(ie==null?void 0:ie.id)!==((ge=_.messages[Ie])==null?void 0:ge.id)})||(W==null?void 0:W.hasMore)!==_.hasMore||(W==null?void 0:W.nextCursor)!==_.nextCursor||(W==null?void 0:W.nextCursorNs)!==_.nextCursorNs||(W==null?void 0:W.checkpointId)!==_.checkpointId||(W==null?void 0:W.checkpointNs)!==_.checkpointNs)&&(Ce.current.set(T,_),_n.current&&window.clearTimeout(_n.current),_n.current=window.setTimeout(()=>{try{g(_,100)}catch(ie){console.warn("[ChatSessionProvider] Failed to persist thread payload:",ie)}},Po))},[D,ye,fe,pe.lastCheckpointId,pe.lastCheckpointNs,pe.messages]);const ht=y.useMemo(()=>({threads:I,currentThreadId:A,setCurrentThreadId:j,isLoading:P,error:M,actions:{createThread:Ue,deleteThread:ot,renameThread:Pt,refreshThreads:()=>Rt()},persistThreadsCache:Kn,hydrateFromCache:ce}),[I,A,P,M,Ue,ot,Pt,Rt,Kn,ce,j]),Lt=y.useMemo(()=>{const T=pe.lastBranch??null,_=pe.assemblingId??null,W=T||_?{branchLabel:(T==null?void 0:T.branchLabel)??null,lastBranch:T,assemblingMessageId:_}:null;return{threadId:A,messages:pe.messages,interrupt:B,checkpoint:{id:pe.lastCheckpointId??null,namespace:pe.lastCheckpointNs??null},metadata:W,isLoading:F,isHistoryLoading:de,error:q,hasMore:D,loadOlder:Ke,seedFromSnapshot:We,clearState:kn,listCheckpoints:te,navigateToCheckpoint:Ee,returnToLatest:Fe,loadThread:E,clearThread:z,respondToInterrupt:wt}},[z,kn,A,B,D,de,F,te,Ke,E,pe.assemblingId,pe.lastBranch,pe.lastCheckpointId,pe.lastCheckpointNs,pe.messages,Ee,wt,Fe,We,q]),Yn=y.useMemo(()=>({isStreaming:jn,error:se,submit:ze,stop:Fr,resume:ft,setAuthToken:be}),[jn,se,ze,Fr,ft,be]);return c.jsx(rx.Provider,{value:!0,children:c.jsx(Cc.Provider,{value:Yn,children:c.jsx(yc.Provider,{value:ht,children:c.jsx(Sc.Provider,{value:Lt,children:e})})})})}function Mo(){const e=y.useContext(yc);if(!e)throw new Error("useThreads must be used within ChatSessionProvider");return e}function Do(){const e=y.useContext(Sc);if(!e)throw new Error("useThreadState must be used within ChatSessionProvider");return e}function Ec(){const e=y.useContext(Cc);if(!e)throw new Error("useStream must be used within ChatSessionProvider");return e}function Lo({children:e,apiConfig:t,initialThreadId:n=null,autoLoadInitial:r=!0,disableAutoRestore:o=!1,enableFileAgentRouting:s=!1,fileAgentId:i="invoice_reader",onError:a,onThreadChange:l}){return c.jsx(Og,{apiConfig:t,children:c.jsx(dx,{initialThreadId:n,autoLoadInitial:r,disableAutoRestore:o,enableFileAgentRouting:s,fileAgentId:i,onError:a,onThreadChange:l,children:e})})}function Z(...e){return cm.twMerge(lm.clsx(e))}const fx=bo.cva("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-10 w-10"}},defaultVariants:{variant:"default",size:"default"}}),Ge=m.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?Xn.Slot:"button";return c.jsx(i,{className:Z(fx({variant:t,size:n,className:e})),ref:s,...o})});Ge.displayName="Button";const Ic=m.forwardRef(({className:e,...t},n)=>c.jsx("textarea",{className:Z("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",e),ref:n,...t}));Ic.displayName="Textarea";function hx({initialValue:e="",editingMessageId:t=null,placeholder:n="Type your message...",isStreaming:r=!1,disabled:o=!1,maxLength:s=2e4,onSend:i,onCancelEdit:a,onStop:l,className:u="",textareaClassName:d="",allowEmptySend:f=!1}){const[h,p]=y.useState(e),[w,x]=y.useTransition(),g=y.useRef(null);y.useEffect(()=>{p(e??""),g.current&&(g.current.style.height="auto",g.current.style.height=`${g.current.scrollHeight}px`)},[e,t]);const v=y.useCallback(()=>{const A=g.current;A&&(A.style.height="auto",A.style.height=`${A.scrollHeight}px`)},[]);y.useEffect(()=>{v()},[v]);const b=y.useCallback(async A=>{A&&A.preventDefault();const j=(h??"").trim();!j&&!f||x(()=>{try{const P=i(j);P&&typeof P.then=="function"?P.then(()=>{p(""),g.current&&(g.current.style.height="auto")}).catch(()=>{}):(p(""),g.current&&(g.current.style.height="auto"))}catch{}})},[h,i,f]),S=y.useCallback(A=>{p(A.target.value),g.current&&(g.current.style.height="auto",g.current.style.height=`${g.current.scrollHeight}px`)},[]),N=y.useCallback(A=>{A.key==="Enter"&&!A.shiftKey?(A.preventDefault(),b()):A.key==="Escape"&&t&&(A.preventDefault(),a==null||a())},[b,t,a]),I=`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${t?"border-[hsl(var(--ring))] bg-[hsl(var(--card))] text-[hsl(var(--card-foreground))] dark:bg-[hsl(var(--card))] dark:text-[hsl(var(--card-foreground))]":""} ${d}`;return c.jsx("form",{onSubmit:A=>void b(A),className:`w-full ${u}`,children:c.jsxs("div",{className:"flex items-end gap-2",children:[c.jsx("div",{className:"flex-1",children:c.jsx(Ic,{ref:g,value:h,onChange:S,onKeyDown:N,placeholder:t?"Edit your message...":n,className:I,disabled:o,maxLength:s,rows:1,spellCheck:!1,autoCorrect:"off"})}),c.jsx("div",{children:r?c.jsx(Ge,{type:"button",onClick:()=>{l==null||l()},size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",disabled:o||!l,children:c.jsx(oe.Square,{size:16})}):c.jsx(Ge,{type:"submit",size:"icon",className:"shrink-0",title:t?"Save changes":"Send message",disabled:o||!h.trim()&&!f||w,children:c.jsx(oe.Send,{size:16})})})]})})}const px=y.memo(hx),Fo=0,On=1,yr=2,Nc=4;function Ac(e){return()=>e}function mx(e){e()}function _c(e,t){return n=>e(t(n))}function jc(e,t){return()=>e(t)}function gx(e,t){return n=>e(t,n)}function Ai(e){return e!==void 0}function xx(...e){return()=>{e.map(mx)}}function Sr(){}function $o(e,t){return t(e),e}function vx(e,t){return t(e)}function at(...e){return e}function Je(e,t){return e(On,t)}function Le(e,t){e(Fo,t)}function _i(e){e(yr)}function mt(e){return e(Nc)}function ve(e,t){return Je(e,gx(t,Fo))}function on(e,t){const n=e(On,r=>{n(),t(r)});return n}function Rc(e){let t,n;return r=>o=>{t=o,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function Pc(e,t){return e===t}function lt(e=Pc){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function Ae(e){return t=>n=>{e(n)&&t(n)}}function ae(e){return t=>_c(t,e)}function pn(e){return t=>()=>{t(e)}}function H(e,...t){const n=wx(...t);return(r,o)=>{switch(r){case yr:_i(e);return;case On:return Je(e,n(o))}}}function mn(e,t){return n=>r=>{n(t=e(t,r))}}function er(e){return t=>n=>{e>0?e--:t(n)}}function In(e){let t=null,n;return r=>o=>{t=o,!n&&(n=setTimeout(()=>{n=void 0,r(t)},e))}}function $e(...e){const t=new Array(e.length);let n=0,r=null;const o=Math.pow(2,e.length)-1;return e.forEach((s,i)=>{const a=Math.pow(2,i);Je(s,l=>{const u=n;n=n|a,t[i]=l,u!==o&&n===o&&r&&(r(),r=null)})}),s=>i=>{const a=()=>{s([i].concat(t))};n===o?a():r=a}}function wx(...e){return t=>e.reduceRight(vx,t)}function bx(e){let t,n;const r=()=>t==null?void 0:t();return function(o,s){switch(o){case On:return s?n===s?void 0:(r(),n=s,t=Je(e,s),t):(r(),Sr);case yr:r(),n=null;return}}}function Y(e){let t=e;const n=qe();return(r,o)=>{switch(r){case Fo:t=o;break;case On:{o(t);break}case Nc:return t}return n(r,o)}}function Et(e,t){return $o(Y(t),n=>ve(e,n))}function qe(){const e=[];return(t,n)=>{switch(t){case Fo:e.slice().forEach(r=>{r(n)});return;case yr:e.splice(0,e.length);return;case On:return e.push(n),()=>{const r=e.indexOf(n);r>-1&&e.splice(r,1)}}}}function Ft(e){return $o(qe(),t=>ve(e,t))}function Ye(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:yx(),singleton:n}}const yx=()=>Symbol();function Sx(e){const t=new Map,n=({constructor:r,dependencies:o,id:s,singleton:i})=>{if(i&&t.has(s))return t.get(s);const a=r(o.map(l=>n(l)));return i&&t.set(s,a),a};return n(e)}function xt(...e){const t=qe(),n=new Array(e.length);let r=0;const o=Math.pow(2,e.length)-1;return e.forEach((s,i)=>{const a=Math.pow(2,i);Je(s,l=>{n[i]=l,r=r|a,r===o&&Le(t,n)})}),function(s,i){switch(s){case yr:{_i(t);return}case On:return r===o&&i(n),Je(t,i)}}}function Ne(e,t=Pc){return H(e,lt(t))}function ji(...e){return function(t,n){switch(t){case yr:return;case On:return xx(...e.map(r=>Je(r,n)))}}}var Dt=(e=>(e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR",e))(Dt||{});const Cx={0:"debug",3:"error",1:"log",2:"warn"},Tx=()=>typeof globalThis>"u"?window:globalThis,Mn=Ye(()=>{const e=Y(3);return{log:Y((t,n,r=1)=>{var o;const s=(o=Tx().VIRTUOSO_LOG_LEVEL)!=null?o:mt(e);r>=s&&console[Cx[r]]("%creact-virtuoso: %c%s %o","color: #0253b3; font-weight: bold","color: initial",t,n)}),logLevel:e}},[],{singleton:!0});function tr(e,t,n){return Ri(e,t,n).callbackRef}function Ri(e,t,n){const r=y.useRef(null);let o=i=>{};const s=y.useMemo(()=>typeof ResizeObserver<"u"?new ResizeObserver(i=>{const a=()=>{const l=i[0].target;l.offsetParent!==null&&e(l)};n?a():requestAnimationFrame(a)}):null,[e,n]);return o=i=>{i&&t?(s==null||s.observe(i),r.current=i):(r.current&&(s==null||s.unobserve(r.current)),r.current=null)},{callbackRef:o,ref:r}}function kx(e,t,n,r,o,s,i,a,l){const u=y.useCallback(d=>{const f=Ex(d.children,t,a?"offsetWidth":"offsetHeight",o);let h=d.parentElement;for(;!h.dataset.virtuosoScroller;)h=h.parentElement;const p=h.lastElementChild.dataset.viewportType==="window";let w;p&&(w=h.ownerDocument.defaultView);const x=i?a?i.scrollLeft:i.scrollTop:p?a?w.scrollX||w.document.documentElement.scrollLeft:w.scrollY||w.document.documentElement.scrollTop:a?h.scrollLeft:h.scrollTop,g=i?a?i.scrollWidth:i.scrollHeight:p?a?w.document.documentElement.scrollWidth:w.document.documentElement.scrollHeight:a?h.scrollWidth:h.scrollHeight,v=i?a?i.offsetWidth:i.offsetHeight:p?a?w.innerWidth:w.innerHeight:a?h.offsetWidth:h.offsetHeight;r({scrollHeight:g,scrollTop:Math.max(x,0),viewportHeight:v}),s==null||s(a?Oc("column-gap",getComputedStyle(d).columnGap,o):Oc("row-gap",getComputedStyle(d).rowGap,o)),f!==null&&e(f)},[e,t,o,s,i,r,a]);return Ri(u,n,l)}function Ex(e,t,n,r){const o=e.length;if(o===0)return null;const s=[];for(let i=0;i<o;i++){const a=e.item(i);if(a.dataset.index===void 0)continue;const l=parseInt(a.dataset.index),u=parseFloat(a.dataset.knownSize),d=t(a,n);if(d===0&&r("Zero-sized element, this should not happen",{child:a},Dt.ERROR),d===u)continue;const f=s[s.length-1];s.length===0||f.size!==d||f.endIndex!==l-1?s.push({endIndex:l,size:d,startIndex:l}):s[s.length-1].endIndex++}return s}function Oc(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Dt.WARN),t==="normal"?0:parseInt(t??"0",10)}function Mc(e,t,n){const r=y.useRef(null),o=y.useCallback(l=>{if(!(l!=null&&l.offsetParent))return;const u=l.getBoundingClientRect(),d=u.width;let f,h;if(t){const p=t.getBoundingClientRect(),w=u.top-p.top;h=p.height-Math.max(0,w),f=w+t.scrollTop}else{const p=i.current.ownerDocument.defaultView;h=p.innerHeight-Math.max(0,u.top),f=u.top+p.scrollY}r.current={offsetTop:f,visibleHeight:h,visibleWidth:d},e(r.current)},[e,t]),{callbackRef:s,ref:i}=Ri(o,!0,n),a=y.useCallback(()=>{o(i.current)},[o,i]);return y.useEffect(()=>{var l;if(t){t.addEventListener("scroll",a);const u=new ResizeObserver(()=>{requestAnimationFrame(a)});return u.observe(t),()=>{t.removeEventListener("scroll",a),u.unobserve(t)}}else{const u=(l=i.current)==null?void 0:l.ownerDocument.defaultView;return u==null||u.addEventListener("scroll",a),u==null||u.addEventListener("resize",a),()=>{u==null||u.removeEventListener("scroll",a),u==null||u.removeEventListener("resize",a)}}},[a,t,i]),s}const _t=Ye(()=>{const e=qe(),t=qe(),n=Y(0),r=qe(),o=Y(0),s=qe(),i=qe(),a=Y(0),l=Y(0),u=Y(0),d=Y(0),f=qe(),h=qe(),p=Y(!1),w=Y(!1),x=Y(!1);return ve(H(e,ae(({scrollTop:g})=>g)),t),ve(H(e,ae(({scrollHeight:g})=>g)),i),ve(t,o),{deviation:n,fixedFooterHeight:u,fixedHeaderHeight:l,footerHeight:d,headerHeight:a,horizontalDirection:w,scrollBy:h,scrollContainerState:e,scrollHeight:i,scrollingInProgress:p,scrollTo:f,scrollTop:t,skipAnimationFrameInResizeObserver:x,smoothScrollTargetReached:r,statefulScrollTop:o,viewportHeight:s}},[],{singleton:!0}),Kr={lvl:0};function Dc(e,t){const n=e.length;if(n===0)return[];let{index:r,value:o}=t(e[0]);const s=[];for(let i=1;i<n;i++){const{index:a,value:l}=t(e[i]);s.push({end:a-1,start:r,value:o}),r=a,o=l}return s.push({end:1/0,start:r,value:o}),s}function nt(e){return e===Kr}function Gr(e,t){if(!nt(e))return t===e.k?e.v:t<e.k?Gr(e.l,t):Gr(e.r,t)}function sn(e,t,n="k"){if(nt(e))return[-1/0,void 0];if(Number(e[n])===t)return[e.k,e.v];if(Number(e[n])<t){const r=sn(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return sn(e.l,t,n)}function $t(e,t,n){return nt(e)?$c(t,n,1):t===e.k?yt(e,{k:t,v:n}):t<e.k?Bc(yt(e,{l:$t(e.l,t,n)})):Bc(yt(e,{r:$t(e.r,t,n)}))}function Cr(){return Kr}function Bo(e,t,n){if(nt(e))return[];const r=sn(e,t)[0];return Ix(Oi(e,r,n))}function Pi(e,t){if(nt(e))return Kr;const{k:n,l:r,r:o}=e;if(t===n){if(nt(r))return o;if(nt(o))return r;{const[s,i]=Fc(r);return zo(yt(e,{k:s,l:Lc(r),v:i}))}}else return t<n?zo(yt(e,{l:Pi(r,t)})):zo(yt(e,{r:Pi(o,t)}))}function nr(e){return nt(e)?[]:[...nr(e.l),{k:e.k,v:e.v},...nr(e.r)]}function Oi(e,t,n){if(nt(e))return[];const{k:r,l:o,r:s,v:i}=e;let a=[];return r>t&&(a=a.concat(Oi(o,t,n))),r>=t&&r<=n&&a.push({k:r,v:i}),r<=n&&(a=a.concat(Oi(s,t,n))),a}function zo(e){const{l:t,lvl:n,r}=e;if(r.lvl>=n-1&&t.lvl>=n-1)return e;if(n>r.lvl+1){if(Mi(t))return zc(yt(e,{lvl:n-1}));if(!nt(t)&&!nt(t.r))return yt(t.r,{l:yt(t,{r:t.r.l}),lvl:n,r:yt(e,{l:t.r.r,lvl:n-1})});throw new Error("Unexpected empty nodes")}else{if(Mi(e))return Di(yt(e,{lvl:n-1}));if(!nt(r)&&!nt(r.l)){const o=r.l,s=Mi(o)?r.lvl-1:r.lvl;return yt(o,{l:yt(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:Di(yt(r,{l:o.r,lvl:s}))})}else throw new Error("Unexpected empty nodes")}}function yt(e,t){return $c(t.k!==void 0?t.k:e.k,t.v!==void 0?t.v:e.v,t.lvl!==void 0?t.lvl:e.lvl,t.l!==void 0?t.l:e.l,t.r!==void 0?t.r:e.r)}function Lc(e){return nt(e.r)?e.l:zo(yt(e,{r:Lc(e.r)}))}function Mi(e){return nt(e)||e.lvl>e.r.lvl}function Fc(e){return nt(e.r)?[e.k,e.v]:Fc(e.r)}function $c(e,t,n,r=Kr,o=Kr){return{k:e,l:r,lvl:n,r:o,v:t}}function Bc(e){return Di(zc(e))}function zc(e){const{l:t}=e;return!nt(t)&&t.lvl===e.lvl?yt(t,{r:yt(e,{l:t.r})}):e}function Di(e){const{lvl:t,r:n}=e;return!nt(n)&&!nt(n.r)&&n.lvl===t&&n.r.lvl===t?yt(n,{l:yt(e,{r:n.l}),lvl:t+1}):e}function Ix(e){return Dc(e,({k:t,v:n})=>({index:t,value:n}))}function Hc(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function Yr(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}const Li=Ye(()=>({recalcInProgress:Y(!1)}),[],{singleton:!0});function Uc(e,t,n){return e[Ho(e,t,n)]}function Ho(e,t,n,r=0){let o=e.length-1;for(;r<=o;){const s=Math.floor((r+o)/2),i=e[s],a=n(i,t);if(a===0)return s;if(a===-1){if(o-r<2)return s-1;o=s-1}else{if(o===r)return s;r=s+1}}throw new Error(`Failed binary finding record in array - ${e.join(",")}, searched for ${t}`)}function Nx(e,t,n,r){const o=Ho(e,t,r),s=Ho(e,n,r,o);return e.slice(o,s+1)}function Dn(e,t){return Math.round(e.getBoundingClientRect()[t])}function Uo(e){return!nt(e.groupOffsetTree)}function Fi({index:e},t){return t===e?0:t<e?-1:1}function Ax(){return{groupIndices:[],groupOffsetTree:Cr(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:Cr()}}function _x(e,t){let n=nt(e)?0:1/0;for(const r of t){const{endIndex:o,size:s,startIndex:i}=r;if(n=Math.min(n,i),nt(e)){e=$t(e,0,s);continue}const a=Bo(e,i-1,o+1);if(a.some(Lx(r)))continue;let l=!1,u=!1;for(const{end:d,start:f,value:h}of a)l?(o>=f||s===h)&&(e=Pi(e,f)):(u=h!==s,l=!0),d>o&&o>=f&&h!==s&&(e=$t(e,o+1,h));u&&(e=$t(e,i,s))}return[e,n]}function jx(e){return typeof e.groupIndex<"u"}function Rx({offset:e},t){return t===e?0:t<e?-1:1}function Xr(e,t,n){if(t.length===0)return 0;const{index:r,offset:o,size:s}=Uc(t,e,Fi),i=e-r,a=s*i+(i-1)*n+o;return a>0?a+n:a}function Wc(e,t){if(!Uo(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function Vc(e,t,n){if(jx(e))return t.groupIndices[e.groupIndex]+1;{const r=e.index==="LAST"?n:e.index;let o=Wc(r,t);return o=Math.max(0,o,Math.min(n,o)),o}}function Px(e,t,n,r=0){return r>0&&(t=Math.max(t,Uc(e,r,Fi).offset)),Dc(Nx(e,t,n,Rx),Dx)}function Ox(e,[t,n,r,o]){t.length>0&&r("received item sizes",t,Dt.DEBUG);const s=e.sizeTree;let i=s,a=0;if(n.length>0&&nt(s)&&t.length===2){const h=t[0].size,p=t[1].size;i=n.reduce((w,x)=>$t($t(w,x,h),x+1,p),i)}else[i,a]=_x(i,t);if(i===s)return e;const{lastIndex:l,lastOffset:u,lastSize:d,offsetTree:f}=$i(e.offsetTree,a,i,o);return{groupIndices:n,groupOffsetTree:n.reduce((h,p)=>$t(h,p,Xr(p,f,o)),Cr()),lastIndex:l,lastOffset:u,lastSize:d,offsetTree:f,sizeTree:i}}function Mx(e){return nr(e).map(({k:t,v:n},r,o)=>{const s=o[r+1];return{endIndex:s?s.k-1:1/0,size:n,startIndex:t}})}function qc(e,t){let n=0,r=0;for(;n<e;)n+=t[r+1]-t[r]-1,r++;return r-(n===e?0:1)}function $i(e,t,n,r){let o=e,s=0,i=0,a=0,l=0;if(t!==0){l=Ho(o,t-1,Fi),a=o[l].offset;const u=sn(n,t-1);s=u[0],i=u[1],o.length&&o[l].size===sn(n,t)[1]&&(l-=1),o=o.slice(0,l+1)}else o=[];for(const{start:u,value:d}of Bo(n,t,1/0)){const f=u-s,h=f*i+a+f*r;o.push({index:u,offset:h,size:d}),s=u,a=h,i=d}return{lastIndex:s,lastOffset:a,lastSize:i,offsetTree:o}}function Dx(e){return{index:e.index,value:e}}function Lx(e){const{endIndex:t,size:n,startIndex:r}=e;return o=>o.start===r&&(o.end===t||o.end===1/0)&&o.value===n}const Fx={offsetHeight:"height",offsetWidth:"width"},gn=Ye(([{log:e},{recalcInProgress:t}])=>{const n=qe(),r=qe(),o=Et(r,0),s=qe(),i=qe(),a=Y(0),l=Y([]),u=Y(void 0),d=Y(void 0),f=Y((C,k)=>Dn(C,Fx[k])),h=Y(void 0),p=Y(0),w=Ax(),x=Et(H(n,$e(l,e,p),mn(Ox,w),lt()),w),g=Et(H(l,lt(),mn((C,k)=>({current:k,prev:C.current}),{current:[],prev:[]}),ae(({prev:C})=>C)),[]);ve(H(l,Ae(C=>C.length>0),$e(x,p),ae(([C,k,I])=>{const A=C.reduce((j,P,L)=>$t(j,P,Xr(P,k.offsetTree,I)||L),Cr());return{...k,groupIndices:C,groupOffsetTree:A}})),x),ve(H(r,$e(x),Ae(([C,{lastIndex:k}])=>C<k),ae(([C,{lastIndex:k,lastSize:I}])=>[{endIndex:k,size:I,startIndex:C}])),n),ve(u,d);const v=Et(H(u,ae(C=>C===void 0)),!0);ve(H(d,Ae(C=>C!==void 0&&nt(mt(x).sizeTree)),ae(C=>[{endIndex:0,size:C,startIndex:0}])),n);const b=Ft(H(n,$e(x),mn(({sizes:C},[k,I])=>({changed:I!==C,sizes:I}),{changed:!1,sizes:w}),ae(C=>C.changed)));Je(H(a,mn((C,k)=>({diff:C.prev-k,prev:k}),{diff:0,prev:0}),ae(C=>C.diff)),C=>{const{groupIndices:k}=mt(x);if(C>0)Le(t,!0),Le(s,C+qc(C,k));else if(C<0){const I=mt(g);I.length>0&&(C-=qc(-C,I)),Le(i,C)}}),Je(H(a,$e(e)),([C,k])=>{C<0&&k("`firstItemIndex` prop should not be set to less than zero. If you don't know the total count, just use a very high value",{firstItemIndex:a},Dt.ERROR)});const S=Ft(s);ve(H(s,$e(x),ae(([C,k])=>{const I=k.groupIndices.length>0,A=[],j=k.lastSize;if(I){const P=Gr(k.sizeTree,0);let L=0,F=0;for(;L<C;){const M=k.groupIndices[F],G=k.groupIndices.length===F+1?1/0:k.groupIndices[F+1]-M-1;A.push({endIndex:M,size:P,startIndex:M}),A.push({endIndex:M+1+G-1,size:j,startIndex:M+1}),F++,L+=G+1}const V=nr(k.sizeTree);return L!==C&&V.shift(),V.reduce((M,{k:G,v:q})=>{let U=M.ranges;return M.prevSize!==0&&(U=[...M.ranges,{endIndex:G+C-1,size:M.prevSize,startIndex:M.prevIndex}]),{prevIndex:G+C,prevSize:q,ranges:U}},{prevIndex:C,prevSize:0,ranges:A}).ranges}return nr(k.sizeTree).reduce((P,{k:L,v:F})=>({prevIndex:L+C,prevSize:F,ranges:[...P.ranges,{endIndex:L+C-1,size:P.prevSize,startIndex:P.prevIndex}]}),{prevIndex:0,prevSize:j,ranges:[]}).ranges})),n);const N=Ft(H(i,$e(x,p),ae(([C,{offsetTree:k},I])=>{const A=-C;return Xr(A,k,I)})));return ve(H(i,$e(x,p),ae(([C,k,I])=>{if(k.groupIndices.length>0){if(nt(k.sizeTree))return k;let A=Cr();const j=mt(g);let P=0,L=0,F=0;for(;P<-C;){F=j[L];const V=j[L+1]-F-1;L++,P+=V+1}if(A=nr(k.sizeTree).reduce((V,{k:M,v:G})=>$t(V,Math.max(0,M+C),G),A),P!==-C){const V=Gr(k.sizeTree,F);A=$t(A,0,V);const M=sn(k.sizeTree,-C+1)[1];A=$t(A,1,M)}return{...k,sizeTree:A,...$i(k.offsetTree,0,A,I)}}else{const A=nr(k.sizeTree).reduce((j,{k:P,v:L})=>$t(j,Math.max(0,P+C),L),Cr());return{...k,sizeTree:A,...$i(k.offsetTree,0,A,I)}}})),x),{beforeUnshiftWith:S,data:h,defaultItemSize:d,firstItemIndex:a,fixedItemSize:u,gap:p,groupIndices:l,itemSize:f,listRefresh:b,shiftWith:i,shiftWithOffset:N,sizeRanges:n,sizes:x,statefulTotalCount:o,totalCount:r,trackItemSizes:v,unshiftWith:s}},at(Mn,Li),{singleton:!0});function $x(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const Kc=Ye(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=qe(),i=qe(),a=Ft(H(s,ae($x)));return ve(H(a,ae(l=>l.totalCount)),n),ve(H(a,ae(l=>l.groupIndices)),e),ve(H(xt(o,t,r),Ae(([l,u])=>Uo(u)),ae(([l,u,d])=>sn(u.groupOffsetTree,Math.max(l-d,0),"v")[0]),lt(),ae(l=>[l])),i),{groupCounts:s,topItemsIndexes:i}},at(gn,_t)),Ln=Ye(([{log:e}])=>{const t=Y(!1),n=Ft(H(t,Ae(r=>r),lt()));return Je(t,r=>{r&&mt(e)("props updated",{},Dt.DEBUG)}),{didMount:n,propsReady:t}},at(Mn),{singleton:!0}),Bx=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function Gc(e){const t=typeof e=="number"?{index:e}:e;return t.align||(t.align="start"),(!t.behavior||!Bx)&&(t.behavior="auto"),t.offset||(t.offset=0),t}const Jr=Ye(([{gap:e,listRefresh:t,sizes:n,totalCount:r},{fixedFooterHeight:o,fixedHeaderHeight:s,footerHeight:i,headerHeight:a,scrollingInProgress:l,scrollTo:u,smoothScrollTargetReached:d,viewportHeight:f},{log:h}])=>{const p=qe(),w=qe(),x=Y(0);let g=null,v=null,b=null;function S(){g&&(g(),g=null),b&&(b(),b=null),v&&(clearTimeout(v),v=null),Le(l,!1)}return ve(H(p,$e(n,f,r,x,a,i,h),$e(e,s,o),ae(([[N,C,k,I,A,j,P,L],F,V,M])=>{const G=Gc(N),{align:q,behavior:U,offset:B}=G,$=I-1,ce=Vc(G,C,$);let D=Xr(ce,C.offsetTree,F)+j;q==="end"?(D+=V+sn(C.sizeTree,ce)[1]-k+M,ce===$&&(D+=P)):q==="center"?D+=(V+sn(C.sizeTree,ce)[1]-k+M)/2:D-=A,B&&(D+=B);const Q=de=>{S(),de?(L("retrying to scroll to",{location:N},Dt.DEBUG),Le(p,N)):(Le(w,!0),L("list did not change, scroll successful",{},Dt.DEBUG))};if(S(),U==="smooth"){let de=!1;b=Je(t,we=>{de=de||we}),g=on(d,()=>{Q(de)})}else g=on(H(t,zx(150)),Q);return v=setTimeout(()=>{S()},1200),Le(l,!0),L("scrolling from index to",{behavior:U,index:ce,top:D},Dt.DEBUG),{behavior:U,top:D}})),u),{scrollTargetReached:w,scrollToIndex:p,topListHeight:x}},at(gn,_t,Mn),{singleton:!0});function zx(e){return t=>{const n=setTimeout(()=>{t(!1)},e);return r=>{r&&(t(!0),clearTimeout(n))}}}function Bi(e,t){e==0?t():requestAnimationFrame(()=>{Bi(e-1,t)})}function zi(e,t){const n=t-1;return typeof e=="number"?e:e.index==="LAST"?n:e.index}const Zr=Ye(([{defaultItemSize:e,listRefresh:t,sizes:n},{scrollTop:r},{scrollTargetReached:o,scrollToIndex:s},{didMount:i}])=>{const a=Y(!0),l=Y(0),u=Y(!0);return ve(H(i,$e(l),Ae(([d,f])=>!!f),pn(!1)),a),ve(H(i,$e(l),Ae(([d,f])=>!!f),pn(!1)),u),Je(H(xt(t,i),$e(a,n,e,u),Ae(([[,d],f,{sizeTree:h},p,w])=>d&&(!nt(h)||Ai(p))&&!f&&!w),$e(l)),([,d])=>{on(o,()=>{Le(u,!0)}),Bi(4,()=>{on(r,()=>{Le(a,!0)}),Le(s,d)})}),{initialItemFinalLocationReached:u,initialTopMostItemIndex:l,scrolledToInitialItem:a}},at(gn,_t,Jr,Ln),{singleton:!0});function Yc(e,t){return Math.abs(e-t)<1.01}const Qr="up",eo="down",Hx="none",Ux={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},Wx=0,to=Ye(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:o,viewportHeight:s}])=>{const i=Y(!1),a=Y(!0),l=qe(),u=qe(),d=Y(4),f=Y(Wx),h=Et(H(ji(H(Ne(o),er(1),pn(!0)),H(Ne(o),er(1),pn(!1),Rc(100))),lt()),!1),p=Et(H(ji(H(n,pn(!0)),H(n,pn(!1),Rc(200))),lt()),!1);ve(H(xt(Ne(o),Ne(f)),ae(([b,S])=>b<=S),lt()),a),ve(H(a,In(50)),u);const w=Ft(H(xt(r,Ne(s),Ne(t),Ne(e),Ne(d)),mn((b,[{scrollHeight:S,scrollTop:N},C,k,I,A])=>{const j=N+C-S>-A,P={scrollHeight:S,scrollTop:N,viewportHeight:C};if(j){let F,V;return N>b.state.scrollTop?(F="SCROLLED_DOWN",V=b.state.scrollTop-N):(F="SIZE_DECREASED",V=b.state.scrollTop-N||b.scrollTopDelta),{atBottom:!0,atBottomBecause:F,scrollTopDelta:V,state:P}}let L;return P.scrollHeight>b.state.scrollHeight?L="SIZE_INCREASED":C<b.state.viewportHeight?L="VIEWPORT_HEIGHT_DECREASING":N<b.state.scrollTop?L="SCROLLING_UPWARDS":L="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:L,state:P}},Ux),lt((b,S)=>b&&b.atBottom===S.atBottom))),x=Et(H(r,mn((b,{scrollHeight:S,scrollTop:N,viewportHeight:C})=>{if(Yc(b.scrollHeight,S))return{changed:!1,jump:0,scrollHeight:S,scrollTop:N};{const k=S-(N+C)<1;return b.scrollTop!==N&&k?{changed:!0,jump:b.scrollTop-N,scrollHeight:S,scrollTop:N}:{changed:!0,jump:0,scrollHeight:S,scrollTop:N}}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),Ae(b=>b.changed),ae(b=>b.jump)),0);ve(H(w,ae(b=>b.atBottom)),i),ve(H(i,In(50)),l);const g=Y(eo);ve(H(r,ae(({scrollTop:b})=>b),lt(),mn((b,S)=>mt(p)?{direction:b.direction,prevScrollTop:S}:{direction:S<b.prevScrollTop?Qr:eo,prevScrollTop:S},{direction:eo,prevScrollTop:0}),ae(b=>b.direction)),g),ve(H(r,In(50),pn(Hx)),g);const v=Y(0);return ve(H(h,Ae(b=>!b),pn(0)),v),ve(H(o,In(100),$e(h),Ae(([b,S])=>!!S),mn(([b,S],[N])=>[S,N],[0,0]),ae(([b,S])=>S-b)),v),{atBottomState:w,atBottomStateChange:l,atBottomThreshold:d,atTopStateChange:u,atTopThreshold:f,isAtBottom:i,isAtTop:a,isScrolling:h,lastJumpDueToItemResize:x,scrollDirection:g,scrollVelocity:v}},at(_t)),Wo="top",Vo="bottom",Xc="none";function Jc(e,t,n){return typeof e=="number"?n===Qr&&t===Wo||n===eo&&t===Vo?e:0:n===Qr?t===Wo?e.main:e.reverse:t===Vo?e.main:e.reverse}function Zc(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const Hi=Ye(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:o}])=>{const s=qe(),i=Y(0),a=Y(0),l=Y(0),u=Et(H(xt(Ne(r),Ne(o),Ne(n),Ne(s,Yr),Ne(l),Ne(i),Ne(t),Ne(e),Ne(a)),ae(([d,f,h,[p,w],x,g,v,b,S])=>{const N=d-b,C=g+v,k=Math.max(h-N,0);let I=Xc;const A=Zc(S,Wo),j=Zc(S,Vo);return p-=b,p+=h+v,w+=h+v,w-=b,p>d+C-A&&(I=Qr),w<d-k+f+j&&(I=eo),I!==Xc?[Math.max(N-h-Jc(x,Wo,I)-A,0),N-k-v+f+Jc(x,Vo,I)+j]:null}),Ae(d=>d!=null),lt(Yr)),[0,0]);return{increaseViewportBy:a,listBoundary:s,overscan:l,topListHeight:i,visibleRange:u}},at(_t),{singleton:!0});function Vx(e,t,n){if(Uo(t)){const r=Wc(e,t);return[{index:sn(t.groupOffsetTree,r)[0],offset:0,size:0},{data:n==null?void 0:n[0],index:r,offset:0,size:0}]}return[{data:n==null?void 0:n[0],index:e,offset:0,size:0}]}const Ui={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function qo(e,t,n,r,o,s){const{lastIndex:i,lastOffset:a,lastSize:l}=o;let u=0,d=0;if(e.length>0){u=e[0].offset;const x=e[e.length-1];d=x.offset+x.size}const f=n-i,h=a+f*l+(f-1)*r,p=u,w=h-d;return{bottom:d,firstItemIndex:s,items:eu(e,o,s),offsetBottom:w,offsetTop:u,top:p,topItems:eu(t,o,s),topListHeight:t.reduce((x,g)=>g.size+x,0),totalCount:n}}function Qc(e,t,n,r,o,s){let i=0;if(n.groupIndices.length>0)for(const d of n.groupIndices){if(d-i>=e)break;i++}const a=e+i,l=zi(t,a),u=Array.from({length:a}).map((d,f)=>({data:s[f+l],index:f+l,offset:0,size:0}));return qo(u,[],a,o,n,r)}function eu(e,t,n){if(e.length===0)return[];if(!Uo(t))return e.map(u=>({...u,index:u.index+n,originalIndex:u.index}));const r=e[0].index,o=e[e.length-1].index,s=[],i=Bo(t.groupOffsetTree,r,o);let a,l=0;for(const u of e){(!a||a.end<u.index)&&(a=i.shift(),l=t.groupIndices.indexOf(a.start));let d;u.index===a.start?d={index:l,type:"group"}:d={groupIndex:l,index:u.index-(l+1)+n},s.push({...d,data:u.data,offset:u.offset,originalIndex:u.index,size:u.size})}return s}const rr=Ye(([{data:e,firstItemIndex:t,gap:n,sizes:r,totalCount:o},s,{listBoundary:i,topListHeight:a,visibleRange:l},{initialTopMostItemIndex:u,scrolledToInitialItem:d},{topListHeight:f},h,{didMount:p},{recalcInProgress:w}])=>{const x=Y([]),g=Y(0),v=qe();ve(s.topItemsIndexes,x);const b=Et(H(xt(p,w,Ne(l,Yr),Ne(o),Ne(r),Ne(u),d,Ne(x),Ne(t),Ne(n),e),Ae(([k,I,,A,,,,,,,j])=>{const P=j&&j.length!==A;return k&&!I&&!P}),ae(([,,[k,I],A,j,P,L,F,V,M,G])=>{const q=j,{offsetTree:U,sizeTree:B}=q,$=mt(g);if(A===0)return{...Ui,totalCount:A};if(k===0&&I===0)return $===0?{...Ui,totalCount:A}:Qc($,P,j,V,M,G||[]);if(nt(B))return $>0?null:qo(Vx(zi(P,A),q,G),[],A,M,q,V);const ce=[];if(F.length>0){const ye=F[0],Se=F[F.length-1];let K=0;for(const O of Bo(B,ye,Se)){const X=O.value,ee=Math.max(O.start,ye),fe=Math.min(O.end,Se);for(let ne=ee;ne<=fe;ne++)ce.push({data:G==null?void 0:G[ne],index:ne,offset:K,size:X}),K+=X}}if(!L)return qo([],ce,A,M,q,V);const D=F.length>0?F[F.length-1]+1:0,Q=Px(U,k,I,D);if(Q.length===0)return null;const de=A-1,we=$o([],ye=>{for(const Se of Q){const K=Se.value;let O=K.offset,X=Se.start;const ee=K.size;if(K.offset<k){X+=Math.floor((k-K.offset+M)/(ee+M));const ne=X-Se.start;O+=ne*ee+ne*M}X<D&&(O+=(D-X)*ee,X=D);const fe=Math.min(Se.end,de);for(let ne=X;ne<=fe&&!(O>=I);ne++)ye.push({data:G==null?void 0:G[ne],index:ne,offset:O,size:ee}),O+=ee+M}});return qo(we,ce,A,M,q,V)}),Ae(k=>k!==null),lt()),Ui);ve(H(e,Ae(Ai),ae(k=>k==null?void 0:k.length)),o),ve(H(b,ae(k=>k.topListHeight)),f),ve(f,a),ve(H(b,ae(k=>[k.top,k.bottom])),i),ve(H(b,ae(k=>k.items)),v);const S=Ft(H(b,Ae(({items:k})=>k.length>0),$e(o,e),Ae(([{items:k},I])=>k[k.length-1].originalIndex===I-1),ae(([,k,I])=>[k-1,I]),lt(Yr),ae(([k])=>k))),N=Ft(H(b,In(200),Ae(({items:k,topItems:I})=>k.length>0&&k[0].originalIndex===I.length),ae(({items:k})=>k[0].index),lt())),C=Ft(H(b,Ae(({items:k})=>k.length>0),ae(({items:k})=>{let I=0,A=k.length-1;for(;k[I].type==="group"&&I<A;)I++;for(;k[A].type==="group"&&A>I;)A--;return{endIndex:k[A].index,startIndex:k[I].index}}),lt(Hc)));return{endReached:S,initialItemCount:g,itemsRendered:v,listState:b,rangeChanged:C,startReached:N,topItemsIndexes:x,...h}},at(gn,Kc,Hi,Zr,Jr,to,Ln,Li),{singleton:!0}),tu=Ye(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:o}])=>{const s=qe(),i=Et(H(xt(n,e,r,t,o),ae(([a,l,u,d,f])=>a+l+u+d+f.offsetBottom+f.bottom)),0);return ve(Ne(i),s),{totalListHeight:i,totalListHeightChanged:s}},at(_t,rr),{singleton:!0}),qx=Ye(([{viewportHeight:e},{totalListHeight:t}])=>{const n=Y(!1),r=Et(H(xt(n,e,t),Ae(([o])=>o),ae(([,o,s])=>Math.max(0,o-s)),In(0),lt()),0);return{alignToBottom:n,paddingTopAddition:r}},at(_t,tu),{singleton:!0}),nu=Ye(()=>({context:Y(null)})),Kx=({itemBottom:e,itemTop:t,locationParams:{align:n,behavior:r,...o},viewportBottom:s,viewportTop:i})=>t<i?{...o,align:n??"start",behavior:r}:e>s?{...o,align:n??"end",behavior:r}:null,ru=Ye(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:s,scrollingInProgress:i,scrollTop:a,viewportHeight:l},{scrollToIndex:u}])=>{const d=qe();return ve(H(d,$e(t,l,n,s,o,r,a),$e(e),ae(([[f,h,p,w,x,g,v,b],S])=>{const{align:N,behavior:C,calculateViewLocation:k=Kx,done:I,...A}=f,j=Vc(f,h,w-1),P=Xr(j,h.offsetTree,S)+x+g,L=P+sn(h.sizeTree,j)[1],F=b+g,V=b+p-v,M=k({itemBottom:L,itemTop:P,locationParams:{align:N,behavior:C,...A},viewportBottom:V,viewportTop:F});return M?I&&on(H(i,Ae(G=>!G),er(mt(i)?1:2)),I):I&&I(),M}),Ae(f=>f!==null)),u),{scrollIntoView:d}},at(gn,_t,Jr,rr,Mn),{singleton:!0});function ou(e){return e?e==="smooth"?"smooth":"auto":!1}const Gx=(e,t)=>typeof e=="function"?ou(e(t)):t&&ou(e),Yx=Ye(([{listRefresh:e,totalCount:t,fixedItemSize:n,data:r},{atBottomState:o,isAtBottom:s},{scrollToIndex:i},{scrolledToInitialItem:a},{didMount:l,propsReady:u},{log:d},{scrollingInProgress:f},{context:h},{scrollIntoView:p}])=>{const w=Y(!1),x=qe();let g=null;function v(C){Le(i,{align:"end",behavior:C,index:"LAST"})}Je(H(xt(H(Ne(t),er(1)),l),$e(Ne(w),s,a,f),ae(([[C,k],I,A,j,P])=>{let L=k&&j,F="auto";return L&&(F=Gx(I,A||P),L=L&&!!F),{followOutputBehavior:F,shouldFollow:L,totalCount:C}}),Ae(({shouldFollow:C})=>C)),({followOutputBehavior:C,totalCount:k})=>{g&&(g(),g=null),mt(n)?requestAnimationFrame(()=>{mt(d)("following output to ",{totalCount:k},Dt.DEBUG),v(C)}):g=on(e,()=>{mt(d)("following output to ",{totalCount:k},Dt.DEBUG),v(C),g=null})});function b(C){const k=on(o,I=>{C&&!I.atBottom&&I.notAtBottomBecause==="SIZE_INCREASED"&&!g&&(mt(d)("scrolling to bottom due to increased size",{},Dt.DEBUG),v("auto"))});setTimeout(k,100)}Je(H(xt(Ne(w),t,u),Ae(([C,,k])=>C&&k),mn(({value:C},[,k])=>({refreshed:C===k,value:k}),{refreshed:!1,value:0}),Ae(({refreshed:C})=>C),$e(w,t)),([,C])=>{mt(a)&&b(C!==!1)}),Je(x,()=>{b(mt(w)!==!1)}),Je(xt(Ne(w),o),([C,k])=>{C&&!k.atBottom&&k.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&v("auto")});const S=Y(null),N=qe();return ve(ji(H(Ne(r),ae(C=>{var k;return(k=C==null?void 0:C.length)!=null?k:0})),H(Ne(t))),N),Je(H(xt(H(N,er(1)),l),$e(Ne(S),a,f,h),ae(([[C,k],I,A,j,P])=>k&&A&&(I==null?void 0:I({context:P,totalCount:C,scrollingInProgress:j}))),Ae(C=>!!C),In(0)),C=>{g&&(g(),g=null),mt(n)?requestAnimationFrame(()=>{mt(d)("scrolling into view",{}),Le(p,C)}):g=on(e,()=>{mt(d)("scrolling into view",{}),Le(p,C),g=null})}),{autoscrollToBottom:x,followOutput:w,scrollIntoViewOnChange:S}},at(gn,to,Jr,Zr,Ln,Mn,_t,nu,ru)),Xx=Ye(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:s,listState:i},{didMount:a}])=>(ve(H(a,$e(s),Ae(([,l])=>l!==0),$e(o,r,t,n,e),ae(([[,l],u,d,f,h,p=[]])=>Qc(l,u,d,f,h,p))),i),{}),at(gn,Zr,rr,Ln),{singleton:!0}),Jx=Ye(([{didMount:e},{scrollTo:t},{listState:n}])=>{const r=Y(0);return Je(H(e,$e(r),Ae(([,o])=>o!==0),ae(([,o])=>({top:o}))),o=>{on(H(n,er(1),Ae(s=>s.items.length>1)),()=>{requestAnimationFrame(()=>{Le(t,o)})})}),{initialScrollTop:r}},at(Ln,_t,rr),{singleton:!0}),su=Ye(([{scrollVelocity:e}])=>{const t=Y(!1),n=qe(),r=Y(!1);return ve(H(e,$e(r,t,n),Ae(([o,s])=>!!s),ae(([o,s,i,a])=>{const{enter:l,exit:u}=s;if(i){if(u(o,a))return!1}else if(l(o,a))return!0;return i}),lt()),t),Je(H(xt(t,e,n),$e(r)),([[o,s,i],a])=>{o&&a&&a.change&&a.change(s,i)}),{isSeeking:t,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:e}},at(to),{singleton:!0}),Wi=Ye(([{scrollContainerState:e,scrollTo:t}])=>{const n=qe(),r=qe(),o=qe(),s=Y(!1),i=Y(void 0);return ve(H(xt(n,r),ae(([{scrollHeight:a,scrollTop:l,viewportHeight:u},{offsetTop:d}])=>({scrollHeight:a,scrollTop:Math.max(0,l-d),viewportHeight:u}))),e),ve(H(t,$e(r),ae(([a,{offsetTop:l}])=>({...a,top:a.top+l}))),o),{customScrollParent:i,useWindowScroll:s,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:r}},at(_t)),Zx=Ye(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:o},{didMount:s},{useWindowScroll:i,windowScrollContainerState:a,windowViewportRect:l}])=>{const u=qe(),d=Y(void 0),f=Y(null),h=Y(null);return ve(a,f),ve(l,h),Je(H(u,$e(t,r,i,f,h,n)),([p,w,x,g,v,b,S])=>{const N=Mx(w.sizeTree);g&&v!==null&&b!==null&&(x=v.scrollTop-b.offsetTop),x-=S,p({ranges:N,scrollTop:x})}),ve(H(d,Ae(Ai),ae(Qx)),o),ve(H(s,$e(d),Ae(([,p])=>p!==void 0),lt(),ae(([,p])=>p.ranges)),e),{getState:u,restoreStateFrom:d}},at(gn,_t,Zr,Ln,Wi));function Qx(e){return{align:"start",index:0,offset:e.scrollTop}}const ev=Ye(([{topItemsIndexes:e}])=>{const t=Y(0);return ve(H(t,Ae(n=>n>=0),ae(n=>Array.from({length:n}).map((r,o)=>o))),e),{topItemCount:t}},at(rr));function iu(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const tv=iu(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),nv=Ye(([{deviation:e,scrollBy:t,scrollingInProgress:n,scrollTop:r},{isAtBottom:o,isScrolling:s,lastJumpDueToItemResize:i,scrollDirection:a},{listState:l},{beforeUnshiftWith:u,gap:d,shiftWithOffset:f,sizes:h},{log:p},{recalcInProgress:w}])=>{const x=Ft(H(l,$e(i),mn(([,v,b,S],[{bottom:N,items:C,offsetBottom:k,totalCount:I},A])=>{const j=N+k;let P=0;return b===I&&v.length>0&&C.length>0&&(C[0].originalIndex===0&&v[0].originalIndex===0||(P=j-S,P!==0&&(P+=A))),[P,C,I,j]},[0,[],0,0]),Ae(([v])=>v!==0),$e(r,a,n,o,p,w),Ae(([,v,b,S,,,N])=>!N&&!S&&v!==0&&b===Qr),ae(([[v],,,,,b])=>(b("Upward scrolling compensation",{amount:v},Dt.DEBUG),v))));function g(v){v>0?(Le(t,{behavior:"auto",top:-v}),Le(e,0)):(Le(e,0),Le(t,{behavior:"auto",top:-v}))}return Je(H(x,$e(e,s)),([v,b,S])=>{S&&tv()?Le(e,b-v):g(-v)}),Je(H(xt(Et(s,!1),e,w),Ae(([v,b,S])=>!v&&!S&&b!==0),ae(([v,b])=>b),In(1)),g),ve(H(f,ae(v=>({top:-v}))),t),Je(H(u,$e(h,d),ae(([v,{groupIndices:b,lastSize:S,sizeTree:N},C])=>{function k(I){return I*(S+C)}if(b.length===0)return k(v);{let I=0;const A=Gr(N,0);let j=0,P=0;for(;j<v;){j++,I+=A;let L=b.length===P+1?1/0:b[P+1]-b[P]-1;j+L>v&&(I-=A,L=v-j+1),j+=L,I+=k(L),P++}return I}})),v=>{Le(e,v),requestAnimationFrame(()=>{Le(t,{top:v}),requestAnimationFrame(()=>{Le(e,0),Le(w,!1)})})}),{deviation:e}},at(_t,to,rr,gn,Mn,Li)),rv=Ye(([e,t,n,r,o,s,i,a,l,u,d])=>({...e,...t,...n,...r,...o,...s,...i,...a,...l,...u,...d}),at(Hi,Xx,Ln,su,tu,Jx,qx,Wi,ru,Mn,nu)),au=Ye(([{data:e,defaultItemSize:t,firstItemIndex:n,fixedItemSize:r,gap:o,groupIndices:s,itemSize:i,sizeRanges:a,sizes:l,statefulTotalCount:u,totalCount:d,trackItemSizes:f},{initialItemFinalLocationReached:h,initialTopMostItemIndex:p,scrolledToInitialItem:w},x,g,v,{listState:b,topItemsIndexes:S,...N},{scrollToIndex:C},k,{topItemCount:I},{groupCounts:A},j])=>(ve(N.rangeChanged,j.scrollSeekRangeChanged),ve(H(j.windowViewportRect,ae(P=>P.visibleHeight)),x.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:n,fixedItemHeight:r,gap:o,groupCounts:A,initialItemFinalLocationReached:h,initialTopMostItemIndex:p,scrolledToInitialItem:w,sizeRanges:a,topItemCount:I,topItemsIndexes:S,totalCount:d,...v,groupIndices:s,itemSize:i,listState:b,scrollToIndex:C,statefulTotalCount:u,trackItemSizes:f,...N,...j,...x,sizes:l,...g}),at(gn,Zr,_t,Zx,Yx,rr,Jr,nv,ev,Kc,rv));function ov(e,t){const n={},r={};let o=0;const s=e.length;for(;o<s;)r[e[o]]=1,o+=1;for(const i in t)Object.hasOwn(r,i)||(n[i]=t[i]);return n}const Ko=typeof document<"u"?y.useLayoutEffect:y.useEffect;function lu(e,t,n){const r=Object.keys(t.required||{}),o=Object.keys(t.optional||{}),s=Object.keys(t.methods||{}),i=Object.keys(t.events||{}),a=y.createContext({});function l(g,v){g.propsReady&&Le(g.propsReady,!1);for(const b of r){const S=g[t.required[b]];Le(S,v[b])}for(const b of o)if(b in v){const S=g[t.optional[b]];Le(S,v[b])}g.propsReady&&Le(g.propsReady,!0)}function u(g){return s.reduce((v,b)=>(v[b]=S=>{const N=g[t.methods[b]];Le(N,S)},v),{})}function d(g){return i.reduce((v,b)=>(v[b]=bx(g[t.events[b]]),v),{})}const f=y.forwardRef((g,v)=>{const{children:b,...S}=g,[N]=y.useState(()=>$o(Sx(e),I=>{l(I,S)})),[C]=y.useState(jc(d,N));Ko(()=>{for(const I of i)I in S&&Je(C[I],S[I]);return()=>{Object.values(C).map(_i)}},[S,C,N]),Ko(()=>{l(N,S)}),y.useImperativeHandle(v,Ac(u(N)));const k=n;return c.jsx(a.Provider,{value:N,children:n?c.jsx(k,{...ov([...r,...o,...i],S),children:b}):b})}),h=g=>{const v=y.useContext(a);return y.useCallback(b=>{Le(v[g],b)},[v,g])},p=g=>{const v=y.useContext(a)[g],b=y.useCallback(S=>Je(v,S),[v]);return y.useSyncExternalStore(b,()=>mt(v),()=>mt(v))},w=g=>{const v=y.useContext(a)[g],[b,S]=y.useState(jc(mt,v));return Ko(()=>Je(v,N=>{N!==b&&S(Ac(N))}),[v,b]),b},x=y.version.startsWith("18")?p:w;return{Component:f,useEmitter:(g,v)=>{const b=y.useContext(a)[g];Ko(()=>Je(b,v),[v,b])},useEmitterValue:x,usePublisher:h}}const cu=y.createContext(void 0),uu=y.createContext(void 0),du=typeof document<"u"?y.useLayoutEffect:y.useEffect;function Vi(e){return"self"in e}function sv(e){return"body"in e}function fu(e,t,n,r=Sr,o,s){const i=y.useRef(null),a=y.useRef(null),l=y.useRef(null),u=y.useCallback(h=>{let p,w,x;const g=h.target;if(sv(g)||Vi(g)){const b=Vi(g)?g:g.defaultView;x=s?b.scrollX:b.scrollY,p=s?b.document.documentElement.scrollWidth:b.document.documentElement.scrollHeight,w=s?b.innerWidth:b.innerHeight}else x=s?g.scrollLeft:g.scrollTop,p=s?g.scrollWidth:g.scrollHeight,w=s?g.offsetWidth:g.offsetHeight;const v=()=>{e({scrollHeight:p,scrollTop:Math.max(x,0),viewportHeight:w})};h.suppressFlushSync?v():ti.flushSync(v),a.current!==null&&(x===a.current||x<=0||x===p-w)&&(a.current=null,t(!0),l.current&&(clearTimeout(l.current),l.current=null))},[e,t,s]);y.useEffect(()=>{const h=o||i.current;return r(o||i.current),u({suppressFlushSync:!0,target:h}),h.addEventListener("scroll",u,{passive:!0}),()=>{r(null),h.removeEventListener("scroll",u)}},[i,u,n,r,o]);function d(h){const p=i.current;if(!p||(s?"offsetWidth"in p&&p.offsetWidth===0:"offsetHeight"in p&&p.offsetHeight===0))return;const w=h.behavior==="smooth";let x,g,v;Vi(p)?(g=Math.max(Dn(p.document.documentElement,s?"width":"height"),s?p.document.documentElement.scrollWidth:p.document.documentElement.scrollHeight),x=s?p.innerWidth:p.innerHeight,v=s?window.scrollX:window.scrollY):(g=p[s?"scrollWidth":"scrollHeight"],x=Dn(p,s?"width":"height"),v=p[s?"scrollLeft":"scrollTop"]);const b=g-x;if(h.top=Math.ceil(Math.max(Math.min(b,h.top),0)),Yc(x,g)||h.top===v){e({scrollHeight:g,scrollTop:v,viewportHeight:x}),w&&t(!0);return}w?(a.current=h.top,l.current&&clearTimeout(l.current),l.current=setTimeout(()=>{l.current=null,a.current=null,t(!0)},1e3)):a.current=null,s&&(h={behavior:h.behavior,left:h.top}),p.scrollTo(h)}function f(h){s&&(h={behavior:h.behavior,left:h.top}),i.current.scrollBy(h)}return{scrollByCallback:f,scrollerRef:i,scrollToCallback:d}}const qi="-webkit-sticky",hu="sticky",Ki=iu(()=>{if(typeof document>"u")return hu;const e=document.createElement("div");return e.style.position=qi,e.style.position===qi?qi:hu});function Gi(e){return e}const iv=Ye(()=>{const e=Y(a=>`Item ${a}`),t=Y(a=>`Group ${a}`),n=Y({}),r=Y(Gi),o=Y("div"),s=Y(Sr),i=(a,l=null)=>Et(H(n,ae(u=>u[a]),lt()),l);return{components:n,computeItemKey:r,EmptyPlaceholder:i("EmptyPlaceholder"),FooterComponent:i("Footer"),GroupComponent:i("Group","div"),groupContent:t,HeaderComponent:i("Header"),HeaderFooterTag:o,ItemComponent:i("Item","div"),itemContent:e,ListComponent:i("List","div"),ScrollerComponent:i("Scroller","div"),scrollerRef:s,ScrollSeekPlaceholder:i("ScrollSeekPlaceholder"),TopItemListComponent:i("TopItemList")}}),av=Ye(([e,t])=>({...e,...t}),at(au,iv)),lv=({height:e})=>c.jsx("div",{style:{height:e}}),cv={overflowAnchor:"none",position:Ki(),zIndex:1},pu={overflowAnchor:"none"},uv={...pu,display:"inline-block",height:"100%"},mu=y.memo(function({showTopList:e=!1}){const t=Re("listState"),n=Kt("sizeRanges"),r=Re("useWindowScroll"),o=Re("customScrollParent"),s=Kt("windowScrollContainerState"),i=Kt("scrollContainerState"),a=o||r?s:i,l=Re("itemContent"),u=Re("context"),d=Re("groupContent"),f=Re("trackItemSizes"),h=Re("itemSize"),p=Re("log"),w=Kt("gap"),x=Re("horizontalDirection"),{callbackRef:g}=kx(n,h,f,e?Sr:a,p,w,o,x,Re("skipAnimationFrameInResizeObserver")),[v,b]=y.useState(0);Yi("deviation",M=>{v!==M&&b(M)});const S=Re("EmptyPlaceholder"),N=Re("ScrollSeekPlaceholder")||lv,C=Re("ListComponent"),k=Re("ItemComponent"),I=Re("GroupComponent"),A=Re("computeItemKey"),j=Re("isSeeking"),P=Re("groupIndices").length>0,L=Re("alignToBottom"),F=Re("initialItemFinalLocationReached"),V=e?{}:{boxSizing:"border-box",...x?{display:"inline-block",height:"100%",marginLeft:v!==0?v:L?"auto":0,paddingLeft:t.offsetTop,paddingRight:t.offsetBottom,whiteSpace:"nowrap"}:{marginTop:v!==0?v:L?"auto":0,paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},...F?{}:{visibility:"hidden"}};return!e&&t.totalCount===0&&S?c.jsx(S,{...It(S,u)}):c.jsx(C,{...It(C,u),"data-testid":e?"virtuoso-top-item-list":"virtuoso-item-list",ref:g,style:V,children:(e?t.topItems:t.items).map(M=>{const G=M.originalIndex,q=A(G+t.firstItemIndex,M.data,u);return j?y.createElement(N,{...It(N,u),height:M.size,index:M.index,key:q,type:M.type||"item",...M.type==="group"?{}:{groupIndex:M.groupIndex}}):M.type==="group"?y.createElement(I,{...It(I,u),"data-index":G,"data-item-index":M.index,"data-known-size":M.size,key:q,style:cv},d(M.index,u)):y.createElement(k,{...It(k,u),...pv(k,M.data),"data-index":G,"data-item-group-index":M.groupIndex,"data-item-index":M.index,"data-known-size":M.size,key:q,style:x?uv:pu},P?l(M.index,M.groupIndex,M.data,u):l(M.index,M.data,u))})})}),dv={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},fv={outline:"none",overflowX:"auto",position:"relative"},Go=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),hv={position:Ki(),top:0,width:"100%",zIndex:1};function It(e,t){if(typeof e!="string")return{context:t}}function pv(e,t){return{item:typeof e=="string"?void 0:t}}const mv=y.memo(function(){const e=Re("HeaderComponent"),t=Kt("headerHeight"),n=Re("HeaderFooterTag"),r=tr(y.useMemo(()=>s=>{t(Dn(s,"height"))},[t]),!0,Re("skipAnimationFrameInResizeObserver")),o=Re("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...It(e,o)})}):null}),gv=y.memo(function(){const e=Re("FooterComponent"),t=Kt("footerHeight"),n=Re("HeaderFooterTag"),r=tr(y.useMemo(()=>s=>{t(Dn(s,"height"))},[t]),!0,Re("skipAnimationFrameInResizeObserver")),o=Re("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...It(e,o)})}):null});function gu({useEmitter:e,useEmitterValue:t,usePublisher:n}){return y.memo(function({children:r,style:o,context:s,...i}){const a=n("scrollContainerState"),l=t("ScrollerComponent"),u=n("smoothScrollTargetReached"),d=t("scrollerRef"),f=t("horizontalDirection")||!1,{scrollByCallback:h,scrollerRef:p,scrollToCallback:w}=fu(a,u,l,d,void 0,f);return e("scrollTo",w),e("scrollBy",h),c.jsx(l,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:p,style:{...f?fv:dv,...o},tabIndex:0,...i,...It(l,s),children:r})})}function xu({useEmitter:e,useEmitterValue:t,usePublisher:n}){return y.memo(function({children:r,style:o,context:s,...i}){const a=n("windowScrollContainerState"),l=t("ScrollerComponent"),u=n("smoothScrollTargetReached"),d=t("totalListHeight"),f=t("deviation"),h=t("customScrollParent"),p=y.useRef(null),w=t("scrollerRef"),{scrollByCallback:x,scrollerRef:g,scrollToCallback:v}=fu(a,u,l,w,h);return du(()=>{var b;return g.current=h||((b=p.current)==null?void 0:b.ownerDocument.defaultView),()=>{g.current=null}},[g,h]),e("windowScrollTo",v),e("scrollBy",x),c.jsx(l,{ref:p,"data-virtuoso-scroller":!0,style:{position:"relative",...o,...d!==0?{height:d+f}:{}},...i,...It(l,s),children:r})})}const xv=({children:e})=>{const t=y.useContext(cu),n=Kt("viewportHeight"),r=Kt("fixedItemHeight"),o=Re("alignToBottom"),s=Re("horizontalDirection"),i=y.useMemo(()=>_c(n,l=>Dn(l,s?"width":"height")),[n,s]),a=tr(i,!0,Re("skipAnimationFrameInResizeObserver"));return y.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),c.jsx("div",{"data-viewport-type":"element",ref:a,style:Go(o),children:e})},vv=({children:e})=>{const t=y.useContext(cu),n=Kt("windowViewportRect"),r=Kt("fixedItemHeight"),o=Re("customScrollParent"),s=Mc(n,o,Re("skipAnimationFrameInResizeObserver")),i=Re("alignToBottom");return y.useEffect(()=>{t&&(r(t.itemHeight),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:100}))},[t,n,r]),c.jsx("div",{"data-viewport-type":"window",ref:s,style:Go(i),children:e})},wv=({children:e})=>{const t=Re("TopItemListComponent")||"div",n=Re("headerHeight"),r={...hv,marginTop:`${n}px`},o=Re("context");return c.jsx(t,{style:r,...It(t,o),children:e})},bv=y.memo(function(e){const t=Re("useWindowScroll"),n=Re("topItemsIndexes").length>0,r=Re("customScrollParent"),o=Re("context");return c.jsxs(r||t?Cv:Sv,{...e,context:o,children:[n&&c.jsx(wv,{children:c.jsx(mu,{showTopList:!0})}),c.jsxs(r||t?vv:xv,{children:[c.jsx(mv,{}),c.jsx(mu,{}),c.jsx(gv,{})]})]})}),{Component:yv,useEmitter:Yi,useEmitterValue:Re,usePublisher:Kt}=lu(av,{required:{},optional:{restoreStateFrom:"restoreStateFrom",context:"context",followOutput:"followOutput",scrollIntoViewOnChange:"scrollIntoViewOnChange",itemContent:"itemContent",groupContent:"groupContent",overscan:"overscan",increaseViewportBy:"increaseViewportBy",totalCount:"totalCount",groupCounts:"groupCounts",topItemCount:"topItemCount",firstItemIndex:"firstItemIndex",initialTopMostItemIndex:"initialTopMostItemIndex",components:"components",atBottomThreshold:"atBottomThreshold",atTopThreshold:"atTopThreshold",computeItemKey:"computeItemKey",defaultItemHeight:"defaultItemHeight",fixedItemHeight:"fixedItemHeight",itemSize:"itemSize",scrollSeekConfiguration:"scrollSeekConfiguration",headerFooterTag:"HeaderFooterTag",data:"data",initialItemCount:"initialItemCount",initialScrollTop:"initialScrollTop",alignToBottom:"alignToBottom",useWindowScroll:"useWindowScroll",customScrollParent:"customScrollParent",scrollerRef:"scrollerRef",logLevel:"logLevel",horizontalDirection:"horizontalDirection",skipAnimationFrameInResizeObserver:"skipAnimationFrameInResizeObserver"},methods:{scrollToIndex:"scrollToIndex",scrollIntoView:"scrollIntoView",scrollTo:"scrollTo",scrollBy:"scrollBy",autoscrollToBottom:"autoscrollToBottom",getState:"getState"},events:{isScrolling:"isScrolling",endReached:"endReached",startReached:"startReached",rangeChanged:"rangeChanged",atBottomStateChange:"atBottomStateChange",atTopStateChange:"atTopStateChange",totalListHeightChanged:"totalListHeightChanged",itemsRendered:"itemsRendered",groupIndices:"groupIndices"}},bv),Sv=gu({useEmitter:Yi,useEmitterValue:Re,usePublisher:Kt}),Cv=xu({useEmitter:Yi,useEmitterValue:Re,usePublisher:Kt}),Tv=yv;at(au,Ye(()=>{const e=Y(u=>c.jsxs("td",{children:["Item $",u]})),t=Y(null),n=Y(u=>c.jsxs("td",{colSpan:1e3,children:["Group ",u]})),r=Y(null),o=Y(null),s=Y({}),i=Y(Gi),a=Y(Sr),l=(u,d=null)=>Et(H(s,ae(f=>f[u]),lt()),d);return{components:s,computeItemKey:i,context:t,EmptyPlaceholder:l("EmptyPlaceholder"),FillerRow:l("FillerRow"),fixedFooterContent:o,fixedHeaderContent:r,itemContent:e,groupContent:n,ScrollerComponent:l("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder"),TableBodyComponent:l("TableBody","tbody"),TableComponent:l("Table","table"),TableFooterComponent:l("TableFoot","tfoot"),TableHeadComponent:l("TableHead","thead"),TableRowComponent:l("TableRow","tr"),GroupComponent:l("Group","tr")}})),Ki();const vu={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},kv={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:wu,floor:Yo,max:no,min:Xi,round:bu}=Math;function yu(e,t,n){return Array.from({length:t-e+1}).map((r,o)=>({data:n===null?null:n[o+e],index:o+e}))}function Ev(e){return{...kv,items:e}}function Xo(e,t){return e&&e.width===t.width&&e.height===t.height}function Iv(e,t){return e&&e.column===t.column&&e.row===t.row}const Nv=Ye(([{increaseViewportBy:e,listBoundary:t,overscan:n,visibleRange:r},{footerHeight:o,headerHeight:s,scrollBy:i,scrollContainerState:a,scrollTo:l,scrollTop:u,smoothScrollTargetReached:d,viewportHeight:f},h,p,{didMount:w,propsReady:x},{customScrollParent:g,useWindowScroll:v,windowScrollContainerState:b,windowScrollTo:S,windowViewportRect:N},C])=>{const k=Y(0),I=Y(0),A=Y(vu),j=Y({height:0,width:0}),P=Y({height:0,width:0}),L=qe(),F=qe(),V=Y(0),M=Y(null),G=Y({column:0,row:0}),q=qe(),U=qe(),B=Y(!1),$=Y(0),ce=Y(!0),D=Y(!1),Q=Y(!1);Je(H(w,$e($),Ae(([O,X])=>!!X)),()=>{Le(ce,!1)}),Je(H(xt(w,ce,P,j,$,D),Ae(([O,X,ee,fe,,ne])=>O&&!X&&ee.height!==0&&fe.height!==0&&!ne)),([,,,,O])=>{Le(D,!0),Bi(1,()=>{Le(L,O)}),on(H(u),()=>{Le(t,[0,0]),Le(ce,!0)})}),ve(H(U,Ae(O=>O!=null&&O.scrollTop>0),pn(0)),I),Je(H(w,$e(U),Ae(([,O])=>O!=null)),([,O])=>{O&&(Le(j,O.viewport),Le(P,O.item),Le(G,O.gap),O.scrollTop>0&&(Le(B,!0),on(H(u,er(1)),X=>{Le(B,!1)}),Le(l,{top:O.scrollTop})))}),ve(H(j,ae(({height:O})=>O)),f),ve(H(xt(Ne(j,Xo),Ne(P,Xo),Ne(G,(O,X)=>O&&O.column===X.column&&O.row===X.row),Ne(u)),ae(([O,X,ee,fe])=>({gap:ee,item:X,scrollTop:fe,viewport:O}))),q),ve(H(xt(Ne(k),r,Ne(G,Iv),Ne(P,Xo),Ne(j,Xo),Ne(M),Ne(I),Ne(B),Ne(ce),Ne($)),Ae(([,,,,,,,O])=>!O),ae(([O,[X,ee],fe,ne,pe,Ze,Qe,,Pe,He])=>{const{column:ct,row:tt}=fe,{height:Be,width:gt}=ne,{width:J}=pe;if(Qe===0&&(O===0||J===0))return vu;if(gt===0){const vt=zi(He,O),Zt=vt+Math.max(Qe-1,0);return Ev(yu(vt,Zt,Ze))}const re=Su(J,gt,ct);let he,Ce;Pe?X===0&&ee===0&&Qe>0?(he=0,Ce=Qe-1):(he=re*Yo((X+tt)/(Be+tt)),Ce=re*wu((ee+tt)/(Be+tt))-1,Ce=Xi(O-1,no(Ce,re-1)),he=Xi(Ce,no(0,he))):(he=0,Ce=-1);const me=yu(he,Ce,Ze),{bottom:Oe,top:it}=Cu(pe,fe,ne,me),Me=wu(O/re),et=Me*Be+(Me-1)*tt-Oe;return{bottom:Oe,itemHeight:Be,items:me,itemWidth:gt,offsetBottom:et,offsetTop:it,top:it}})),A),ve(H(M,Ae(O=>O!==null),ae(O=>O.length)),k),ve(H(xt(j,P,A,G),Ae(([O,X,{items:ee}])=>ee.length>0&&X.height!==0&&O.height!==0),ae(([O,X,{items:ee},fe])=>{const{bottom:ne,top:pe}=Cu(O,fe,X,ee);return[pe,ne]}),lt(Yr)),t);const de=Y(!1);ve(H(u,$e(de),ae(([O,X])=>X||O!==0)),de);const we=Ft(H(xt(A,k),Ae(([{items:O}])=>O.length>0),$e(de),Ae(([[O,X],ee])=>{const fe=O.items[O.items.length-1].index===X-1;return(ee||O.bottom>0&&O.itemHeight>0&&O.offsetBottom===0&&O.items.length===X)&&fe}),ae(([[,O]])=>O-1),lt())),ye=Ft(H(Ne(A),Ae(({items:O})=>O.length>0&&O[0].index===0),pn(0),lt())),Se=Ft(H(Ne(A),$e(B),Ae(([{items:O},X])=>O.length>0&&!X),ae(([{items:O}])=>({endIndex:O[O.length-1].index,startIndex:O[0].index})),lt(Hc),In(0)));ve(Se,p.scrollSeekRangeChanged),ve(H(L,$e(j,P,k,G),ae(([O,X,ee,fe,ne])=>{const pe=Gc(O),{align:Ze,behavior:Qe,offset:Pe}=pe;let He=pe.index;He==="LAST"&&(He=fe-1),He=no(0,He,Xi(fe-1,He));let ct=Ji(X,ne,ee,He);return Ze==="end"?ct=bu(ct-X.height+ee.height):Ze==="center"&&(ct=bu(ct-X.height/2+ee.height/2)),Pe&&(ct+=Pe),{behavior:Qe,top:ct}})),l);const K=Et(H(A,ae(O=>O.offsetBottom+O.bottom)),0);return ve(H(N,ae(O=>({height:O.visibleHeight,width:O.visibleWidth}))),j),{customScrollParent:g,data:M,deviation:V,footerHeight:o,gap:G,headerHeight:s,increaseViewportBy:e,initialItemCount:I,itemDimensions:P,overscan:n,restoreStateFrom:U,scrollBy:i,scrollContainerState:a,scrollHeight:F,scrollTo:l,scrollToIndex:L,scrollTop:u,smoothScrollTargetReached:d,totalCount:k,useWindowScroll:v,viewportDimensions:j,windowScrollContainerState:b,windowScrollTo:S,windowViewportRect:N,...p,gridState:A,horizontalDirection:Q,initialTopMostItemIndex:$,totalListHeight:K,...h,endReached:we,propsReady:x,rangeChanged:Se,startReached:ye,stateChanged:q,stateRestoreInProgress:B,...C}},at(Hi,_t,to,su,Ln,Wi,Mn));function Su(e,t,n){return no(1,Yo((e+n)/(Yo(t)+n)))}function Cu(e,t,n,r){const{height:o}=n;if(o===void 0||r.length===0)return{bottom:0,top:0};const s=Ji(e,t,n,r[0].index);return{bottom:Ji(e,t,n,r[r.length-1].index)+o,top:s}}function Ji(e,t,n,r){const o=Su(e.width,n.width,t.column),s=Yo(r/o),i=s*n.height+no(0,s-1)*t.row;return i>0?i+t.row:i}const Av=Ye(()=>{const e=Y(f=>`Item ${f}`),t=Y({}),n=Y(null),r=Y("virtuoso-grid-item"),o=Y("virtuoso-grid-list"),s=Y(Gi),i=Y("div"),a=Y(Sr),l=(f,h=null)=>Et(H(t,ae(p=>p[f]),lt()),h),u=Y(!1),d=Y(!1);return ve(Ne(d),u),{components:t,computeItemKey:s,context:n,FooterComponent:l("Footer"),HeaderComponent:l("Header"),headerFooterTag:i,itemClassName:r,ItemComponent:l("Item","div"),itemContent:e,listClassName:o,ListComponent:l("List","div"),readyStateChanged:u,reportReadyState:d,ScrollerComponent:l("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder","div")}}),_v=Ye(([e,t])=>({...e,...t}),at(Nv,Av)),jv=y.memo(function(){const e=dt("gridState"),t=dt("listClassName"),n=dt("itemClassName"),r=dt("itemContent"),o=dt("computeItemKey"),s=dt("isSeeking"),i=Gt("scrollHeight"),a=dt("ItemComponent"),l=dt("ListComponent"),u=dt("ScrollSeekPlaceholder"),d=dt("context"),f=Gt("itemDimensions"),h=Gt("gap"),p=dt("log"),w=dt("stateRestoreInProgress"),x=Gt("reportReadyState"),g=tr(y.useMemo(()=>v=>{const b=v.parentElement.parentElement.scrollHeight;i(b);const S=v.firstChild;if(S){const{height:N,width:C}=S.getBoundingClientRect();f({height:N,width:C})}h({column:ku("column-gap",getComputedStyle(v).columnGap,p),row:ku("row-gap",getComputedStyle(v).rowGap,p)})},[i,f,h,p]),!0,!1);return du(()=>{e.itemHeight>0&&e.itemWidth>0&&x(!0)},[e]),w?null:c.jsx(l,{className:t,ref:g,...It(l,d),"data-testid":"virtuoso-item-list",style:{paddingBottom:e.offsetBottom,paddingTop:e.offsetTop},children:e.items.map(v=>{const b=o(v.index,v.data,d);return s?c.jsx(u,{...It(u,d),height:e.itemHeight,index:v.index,width:e.itemWidth},b):y.createElement(a,{...It(a,d),className:n,"data-index":v.index,key:b},r(v.index,v.data,d))})})}),Rv=y.memo(function(){const e=dt("HeaderComponent"),t=Gt("headerHeight"),n=dt("headerFooterTag"),r=tr(y.useMemo(()=>s=>{t(Dn(s,"height"))},[t]),!0,!1),o=dt("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...It(e,o)})}):null}),Pv=y.memo(function(){const e=dt("FooterComponent"),t=Gt("footerHeight"),n=dt("headerFooterTag"),r=tr(y.useMemo(()=>s=>{t(Dn(s,"height"))},[t]),!0,!1),o=dt("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...It(e,o)})}):null}),Ov=({children:e})=>{const t=y.useContext(uu),n=Gt("itemDimensions"),r=Gt("viewportDimensions"),o=tr(y.useMemo(()=>s=>{r(s.getBoundingClientRect())},[r]),!0,!1);return y.useEffect(()=>{t&&(r({height:t.viewportHeight,width:t.viewportWidth}),n({height:t.itemHeight,width:t.itemWidth}))},[t,r,n]),c.jsx("div",{ref:o,style:Go(!1),children:e})},Mv=({children:e})=>{const t=y.useContext(uu),n=Gt("windowViewportRect"),r=Gt("itemDimensions"),o=dt("customScrollParent"),s=Mc(n,o,!1);return y.useEffect(()=>{t&&(r({height:t.itemHeight,width:t.itemWidth}),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:t.viewportWidth}))},[t,n,r]),c.jsx("div",{ref:s,style:Go(!1),children:e})},Dv=y.memo(function({...e}){const t=dt("useWindowScroll"),n=dt("customScrollParent"),r=n||t?Fv:Lv,o=n||t?Mv:Ov,s=dt("context");return c.jsx(r,{...e,...It(r,s),children:c.jsxs(o,{children:[c.jsx(Rv,{}),c.jsx(jv,{}),c.jsx(Pv,{})]})})}),{useEmitter:Tu,useEmitterValue:dt,usePublisher:Gt}=lu(_v,{optional:{context:"context",totalCount:"totalCount",overscan:"overscan",itemContent:"itemContent",components:"components",computeItemKey:"computeItemKey",data:"data",initialItemCount:"initialItemCount",scrollSeekConfiguration:"scrollSeekConfiguration",headerFooterTag:"headerFooterTag",listClassName:"listClassName",itemClassName:"itemClassName",useWindowScroll:"useWindowScroll",customScrollParent:"customScrollParent",scrollerRef:"scrollerRef",logLevel:"logLevel",restoreStateFrom:"restoreStateFrom",initialTopMostItemIndex:"initialTopMostItemIndex",increaseViewportBy:"increaseViewportBy"},methods:{scrollTo:"scrollTo",scrollBy:"scrollBy",scrollToIndex:"scrollToIndex"},events:{isScrolling:"isScrolling",endReached:"endReached",startReached:"startReached",rangeChanged:"rangeChanged",atBottomStateChange:"atBottomStateChange",atTopStateChange:"atTopStateChange",stateChanged:"stateChanged",readyStateChanged:"readyStateChanged"}},Dv),Lv=gu({useEmitter:Tu,useEmitterValue:dt,usePublisher:Gt}),Fv=xu({useEmitter:Tu,useEmitterValue:dt,usePublisher:Gt});function ku(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Dt.WARN),t==="normal"?0:parseInt(t??"0",10)}const $v=bo.cva("inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground hover:bg-primary/80",secondary:"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",destructive:"border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80",outline:"text-foreground"}},defaultVariants:{variant:"default"}});function Zi({className:e,variant:t,...n}){return c.jsx("div",{className:Z($v({variant:t}),e),...n})}function ue(e,t,{checkForDefaultPrevented:n=!0}={}){return function(o){if(e==null||e(o),n===!1||!o.defaultPrevented)return t==null?void 0:t(o)}}function Bv(e,t){const n=m.createContext(t),r=s=>{const{children:i,...a}=s,l=m.useMemo(()=>a,Object.values(a));return c.jsx(n.Provider,{value:l,children:i})};r.displayName=e+"Provider";function o(s){const i=m.useContext(n);if(i)return i;if(t!==void 0)return t;throw new Error(`\`${s}\` must be used within \`${e}\``)}return[r,o]}function xn(e,t=[]){let n=[];function r(s,i){const a=m.createContext(i),l=n.length;n=[...n,i];const u=f=>{var v;const{scope:h,children:p,...w}=f,x=((v=h==null?void 0:h[e])==null?void 0:v[l])||a,g=m.useMemo(()=>w,Object.values(w));return c.jsx(x.Provider,{value:g,children:p})};u.displayName=s+"Provider";function d(f,h){var x;const p=((x=h==null?void 0:h[e])==null?void 0:x[l])||a,w=m.useContext(p);if(w)return w;if(i!==void 0)return i;throw new Error(`\`${f}\` must be used within \`${s}\``)}return[u,d]}const o=()=>{const s=n.map(i=>m.createContext(i));return function(a){const l=(a==null?void 0:a[e])||s;return m.useMemo(()=>({[`__scope${e}`]:{...a,[e]:l}}),[a,l])}};return o.scopeName=e,[r,zv(o,...t)]}function zv(...e){const t=e[0];if(e.length===1)return t;const n=()=>{const r=e.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(s){const i=r.reduce((a,{useScope:l,scopeName:u})=>{const f=l(s)[`__scope${u}`];return{...a,...f}},{});return m.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}var Ct=globalThis!=null&&globalThis.document?m.useLayoutEffect:()=>{},Hv=m[" useInsertionEffect ".trim().toString()]||Ct;function or({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=Uv({defaultProp:t,onChange:n}),a=e!==void 0,l=a?e:o;{const d=m.useRef(e!==void 0);m.useEffect(()=>{const f=d.current;f!==a&&console.warn(`${r} is changing from ${f?"controlled":"uncontrolled"} to ${a?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),d.current=a},[a,r])}const u=m.useCallback(d=>{var f;if(a){const h=Wv(d)?d(e):d;h!==e&&((f=i.current)==null||f.call(i,h))}else s(d)},[a,e,s,i]);return[l,u]}function Uv({defaultProp:e,onChange:t}){const[n,r]=m.useState(e),o=m.useRef(n),s=m.useRef(t);return Hv(()=>{s.current=t},[t]),m.useEffect(()=>{var i;o.current!==n&&((i=s.current)==null||i.call(s,n),o.current=n)},[n,o]),[n,r,s]}function Wv(e){return typeof e=="function"}function Eu(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function Qi(...e){return t=>{let n=!1;const r=e.map(o=>{const s=Eu(o,t);return!n&&typeof s=="function"&&(n=!0),s});if(n)return()=>{for(let o=0;o<r.length;o++){const s=r[o];typeof s=="function"?s():Eu(e[o],null)}}}}function Ve(...e){return m.useCallback(Qi(...e),e)}var Vv=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],_e=Vv.reduce((e,t)=>{const n=Xn.createSlot(`Primitive.${t}`),r=m.forwardRef((o,s)=>{const{asChild:i,...a}=o,l=i?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),c.jsx(l,{...a,ref:s})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function Iu(e,t){e&&yo.flushSync(()=>e.dispatchEvent(t))}function qv(e,t){return m.useReducer((n,r)=>t[n][r]??n,e)}var Bt=e=>{const{present:t,children:n}=e,r=Kv(t),o=typeof n=="function"?n({present:r.isPresent}):m.Children.only(n),s=Ve(r.ref,Gv(o));return typeof n=="function"||r.isPresent?m.cloneElement(o,{ref:s}):null};Bt.displayName="Presence";function Kv(e){const[t,n]=m.useState(),r=m.useRef(null),o=m.useRef(e),s=m.useRef("none"),i=e?"mounted":"unmounted",[a,l]=qv(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return m.useEffect(()=>{const u=Jo(r.current);s.current=a==="mounted"?u:"none"},[a]),Ct(()=>{const u=r.current,d=o.current;if(d!==e){const h=s.current,p=Jo(u);e?l("MOUNT"):p==="none"||(u==null?void 0:u.display)==="none"?l("UNMOUNT"):l(d&&h!==p?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,l]),Ct(()=>{if(t){let u;const d=t.ownerDocument.defaultView??window,f=p=>{const x=Jo(r.current).includes(CSS.escape(p.animationName));if(p.target===t&&x&&(l("ANIMATION_END"),!o.current)){const g=t.style.animationFillMode;t.style.animationFillMode="forwards",u=d.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=g)})}},h=p=>{p.target===t&&(s.current=Jo(r.current))};return t.addEventListener("animationstart",h),t.addEventListener("animationcancel",f),t.addEventListener("animationend",f),()=>{d.clearTimeout(u),t.removeEventListener("animationstart",h),t.removeEventListener("animationcancel",f),t.removeEventListener("animationend",f)}}else l("ANIMATION_END")},[t,l]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:m.useCallback(u=>{r.current=u?getComputedStyle(u):null,n(u)},[])}}function Jo(e){return(e==null?void 0:e.animationName)||"none"}function Gv(e){var r,o;let t=(r=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:r.get,n=t&&"isReactWarning"in t&&t.isReactWarning;return n?e.ref:(t=(o=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:o.get,n=t&&"isReactWarning"in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}var Yv=m[" useId ".trim().toString()]||(()=>{}),Xv=0;function vn(e){const[t,n]=m.useState(Yv());return Ct(()=>{n(r=>r??String(Xv++))},[e]),e||(t?`radix-${t}`:"")}var Zo="Collapsible",[Jv,OT]=xn(Zo),[Zv,ea]=Jv(Zo),Nu=m.forwardRef((e,t)=>{const{__scopeCollapsible:n,open:r,defaultOpen:o,disabled:s,onOpenChange:i,...a}=e,[l,u]=or({prop:r,defaultProp:o??!1,onChange:i,caller:Zo});return c.jsx(Zv,{scope:n,disabled:s,contentId:vn(),open:l,onOpenToggle:m.useCallback(()=>u(d=>!d),[u]),children:c.jsx(_e.div,{"data-state":na(l),"data-disabled":s?"":void 0,...a,ref:t})})});Nu.displayName=Zo;var Au="CollapsibleTrigger",_u=m.forwardRef((e,t)=>{const{__scopeCollapsible:n,...r}=e,o=ea(Au,n);return c.jsx(_e.button,{type:"button","aria-controls":o.contentId,"aria-expanded":o.open||!1,"data-state":na(o.open),"data-disabled":o.disabled?"":void 0,disabled:o.disabled,...r,ref:t,onClick:ue(e.onClick,o.onOpenToggle)})});_u.displayName=Au;var ta="CollapsibleContent",Qv=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=ea(ta,e.__scopeCollapsible);return c.jsx(Bt,{present:n||o.open,children:({present:s})=>c.jsx(ew,{...r,ref:t,present:s})})});Qv.displayName=ta;var ew=m.forwardRef((e,t)=>{const{__scopeCollapsible:n,present:r,children:o,...s}=e,i=ea(ta,n),[a,l]=m.useState(r),u=m.useRef(null),d=Ve(t,u),f=m.useRef(0),h=f.current,p=m.useRef(0),w=p.current,x=i.open||a,g=m.useRef(x),v=m.useRef(void 0);return m.useEffect(()=>{const b=requestAnimationFrame(()=>g.current=!1);return()=>cancelAnimationFrame(b)},[]),Ct(()=>{const b=u.current;if(b){v.current=v.current||{transitionDuration:b.style.transitionDuration,animationName:b.style.animationName},b.style.transitionDuration="0s",b.style.animationName="none";const S=b.getBoundingClientRect();f.current=S.height,p.current=S.width,g.current||(b.style.transitionDuration=v.current.transitionDuration,b.style.animationName=v.current.animationName),l(r)}},[i.open,r]),c.jsx(_e.div,{"data-state":na(i.open),"data-disabled":i.disabled?"":void 0,id:i.contentId,hidden:!x,...s,ref:d,style:{"--radix-collapsible-content-height":h?`${h}px`:void 0,"--radix-collapsible-content-width":w?`${w}px`:void 0,...e.style},children:x&&o})});function na(e){return e?"open":"closed"}var tw=Nu;const ju=tw,Ru=_u,ro=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:Z("rounded-lg border bg-card text-card-foreground shadow-sm",e),...t}));ro.displayName="Card";const oo=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:Z("flex flex-col space-y-1.5 p-6",e),...t}));oo.displayName="CardHeader";const so=m.forwardRef(({className:e,...t},n)=>c.jsx("h3",{ref:n,className:Z("text-2xl font-semibold leading-none tracking-tight",e),...t}));so.displayName="CardTitle";const Pu=m.forwardRef(({className:e,...t},n)=>c.jsx("p",{ref:n,className:Z("text-sm text-muted-foreground",e),...t}));Pu.displayName="CardDescription";const Qo=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:Z("p-6 pt-0",e),...t}));Qo.displayName="CardContent";const Ou=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:Z("flex items-center p-6 pt-0",e),...t}));Ou.displayName="CardFooter";function Mu(){return{async:!1,baseUrl:null,breaks:!1,extensions:null,gfm:!0,headerIds:!0,headerPrefix:"",highlight:null,hooks:null,langPrefix:"language-",mangle:!0,pedantic:!1,renderer:null,sanitize:!1,sanitizer:null,silent:!1,smartypants:!1,tokenizer:null,walkTokens:null,xhtml:!1}}let sr=Mu();function nw(e){sr=e}const Du=/[&<>"']/,rw=new RegExp(Du.source,"g"),Lu=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,ow=new RegExp(Lu.source,"g"),sw={"&":"&","<":"<",">":">",'"':""","'":"'"},Fu=e=>sw[e];function Nt(e,t){if(t){if(Du.test(e))return e.replace(rw,Fu)}else if(Lu.test(e))return e.replace(ow,Fu);return e}const iw=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;function $u(e){return e.replace(iw,(t,n)=>(n=n.toLowerCase(),n==="colon"?":":n.charAt(0)==="#"?n.charAt(1)==="x"?String.fromCharCode(parseInt(n.substring(2),16)):String.fromCharCode(+n.substring(1)):""))}const aw=/(^|[^\[])\^/g;function rt(e,t){e=typeof e=="string"?e:e.source,t=t||"";const n={replace:(r,o)=>(o=o.source||o,o=o.replace(aw,"$1"),e=e.replace(r,o),n),getRegex:()=>new RegExp(e,t)};return n}const lw=/[^\w:]/g,cw=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function Bu(e,t,n){if(e){let r;try{r=decodeURIComponent($u(n)).replace(lw,"").toLowerCase()}catch{return null}if(r.indexOf("javascript:")===0||r.indexOf("vbscript:")===0||r.indexOf("data:")===0)return null}t&&!cw.test(n)&&(n=hw(t,n));try{n=encodeURI(n).replace(/%25/g,"%")}catch{return null}return n}const es={},uw=/^[^:]+:\/*[^/]*$/,dw=/^([^:]+:)[\s\S]*$/,fw=/^([^:]+:\/*[^/]*)[\s\S]*$/;function hw(e,t){es[" "+e]||(uw.test(e)?es[" "+e]=e+"/":es[" "+e]=ns(e,"/",!0)),e=es[" "+e];const n=e.indexOf(":")===-1;return t.substring(0,2)==="//"?n?t:e.replace(dw,"$1")+t:t.charAt(0)==="/"?n?t:e.replace(fw,"$1")+t:e+t}const ts={exec:function(){}};function zu(e,t){const n=e.replace(/\|/g,(s,i,a)=>{let l=!1,u=i;for(;--u>=0&&a[u]==="\\";)l=!l;return l?"|":" |"}),r=n.split(/ \|/);let o=0;if(r[0].trim()||r.shift(),r.length>0&&!r[r.length-1].trim()&&r.pop(),r.length>t)r.splice(t);else for(;r.length<t;)r.push("");for(;o<r.length;o++)r[o]=r[o].trim().replace(/\\\|/g,"|");return r}function ns(e,t,n){const r=e.length;if(r===0)return"";let o=0;for(;o<r;){const s=e.charAt(r-o-1);if(s===t&&!n)o++;else if(s!==t&&n)o++;else break}return e.slice(0,r-o)}function pw(e,t){if(e.indexOf(t[1])===-1)return-1;const n=e.length;let r=0,o=0;for(;o<n;o++)if(e[o]==="\\")o++;else if(e[o]===t[0])r++;else if(e[o]===t[1]&&(r--,r<0))return o;return-1}function mw(e){e&&e.sanitize&&!e.silent&&console.warn("marked(): sanitize and sanitizer parameters are deprecated since version 0.7.0, should not be used and will be removed in the future. Read more here: https://marked.js.org/#/USING_ADVANCED.md#options")}function Hu(e,t){if(t<1)return"";let n="";for(;t>1;)t&1&&(n+=e),t>>=1,e+=e;return n+e}function Uu(e,t,n,r){const o=t.href,s=t.title?Nt(t.title):null,i=e[1].replace(/\\([\[\]])/g,"$1");if(e[0].charAt(0)!=="!"){r.state.inLink=!0;const a={type:"link",raw:n,href:o,title:s,text:i,tokens:r.inlineTokens(i)};return r.state.inLink=!1,a}return{type:"image",raw:n,href:o,title:s,text:Nt(i)}}function gw(e,t){const n=e.match(/^(\s+)(?:```)/);if(n===null)return t;const r=n[1];return t.split(`
|
|
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 ra{constructor(t){this.options=t||sr}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:ns(r,`
|
|
42
|
+
`)}}}fences(t){const n=this.rules.block.fences.exec(t);if(n){const r=n[0],o=gw(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=ns(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,w,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 b=new RegExp(`^( {0,3}${x})((?:[ ][^\\n]*)?(?:\\n|$))`);for(;t&&(w=!1,!(!(n=b.exec(t))||this.rules.block.hr.test(t)));){if(r=n[0],t=t.substring(r.length),d=n[2].split(`
|
|
43
43
|
`,1)[0].replace(/^\t+/,N=>" ".repeat(3*N.length)),f=t.split(`
|
|
44
44
|
`,1)[0],this.options.pedantic?(i=2,p=d.trimLeft()):(i=n[2].search(/[^ ]/),i=i>4?1:i,p=d.slice(i),i+=n[1].length),l=!1,!d&&/^ *$/.test(f)&&(r+=f+`
|
|
45
|
-
`,t=t.substring(f.length+1),w=!0),!w){const N=new RegExp(`^ {0,${Math.min(3,i-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),C=new RegExp(`^ {0,${Math.min(3,i-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),k=new RegExp(`^ {0,${Math.min(3,i-1)}}(?:\`\`\`|~~~)`),
|
|
46
|
-
`,1)[0],f=h,this.options.pedantic&&(f=f.replace(/^ {1,4}(?=( {4})*[^ ])/g," ")),!(k.test(f)||
|
|
47
|
-
`+f.slice(i);else{if(l||d.search(/[^ ]/)>=4||k.test(d)||
|
|
45
|
+
`,t=t.substring(f.length+1),w=!0),!w){const N=new RegExp(`^ {0,${Math.min(3,i-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),C=new RegExp(`^ {0,${Math.min(3,i-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),k=new RegExp(`^ {0,${Math.min(3,i-1)}}(?:\`\`\`|~~~)`),I=new RegExp(`^ {0,${Math.min(3,i-1)}}#`);for(;t&&(h=t.split(`
|
|
46
|
+
`,1)[0],f=h,this.options.pedantic&&(f=f.replace(/^ {1,4}(?=( {4})*[^ ])/g," ")),!(k.test(f)||I.test(f)||N.test(f)||C.test(t)));){if(f.search(/[^ ]/)>=i||!f.trim())p+=`
|
|
47
|
+
`+f.slice(i);else{if(l||d.search(/[^ ]/)>=4||k.test(d)||I.test(d)||C.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"),C=N.length>0&&N.some(k=>/\n.*\n/.test(k.raw));v.loose=C}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"),C=N.length>0&&N.some(k=>/\n.*\n/.test(k.raw));v.loose=C}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]):Nt(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:zu(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]=zu(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:Nt(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]):Nt(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=ns(r.slice(0,-1),"\\");if((r.length-i.length)%2===0)return}else{const i=pw(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)),Uu(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 Uu(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 w=h.slice(1,-1);return{type:"em",raw:h,text:w,tokens:this.lexer.inlineTokens(w)}}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=Nt(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=Nt(this.options.mangle?n(r[1]):r[1]),s="mailto:"+o):(o=Nt(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=Nt(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=Nt(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]):Nt(r[0]):r[0]:o=Nt(this.options.smartypants?n(r[0]):r[0]),{type:"text",raw:r[0],text:o}}}}const Te={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:ts,lheading:/^((?:.|\n(?!\n))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,_paragraph:/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,text:/^[^\n]+/};Te._label=/(?!\s*\])(?:\\.|[^\[\]\\])+/,Te._title=/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/,Te.def=rt(Te.def).replace("label",Te._label).replace("title",Te._title).getRegex(),Te.bullet=/(?:[*+-]|\d{1,9}[.)])/,Te.listItemStart=rt(/^( *)(bull) */).replace("bull",Te.bullet).getRegex(),Te.list=rt(Te.list).replace(/bull/g,Te.bullet).replace("hr","\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))").replace("def","\\n+(?="+Te.def.source+")").getRegex(),Te._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",Te._comment=/<!--(?!-?>)[\s\S]*?(?:-->|$)/,Te.html=rt(Te.html,"i").replace("comment",Te._comment).replace("tag",Te._tag).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),Te.paragraph=rt(Te._paragraph).replace("hr",Te.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",Te._tag).getRegex(),Te.blockquote=rt(Te.blockquote).replace("paragraph",Te.paragraph).getRegex(),Te.normal={...Te},Te.gfm={...Te.normal,table:"^ *([^\\n ].*\\|.*)\\n {0,3}(?:\\| *)?(:?-+:? *(?:\\| *:?-+:? *)*)(?:\\| *)?(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)"},Te.gfm.table=rt(Te.gfm.table).replace("hr",Te.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",Te._tag).getRegex(),Te.gfm.paragraph=rt(Te._paragraph).replace("hr",Te.hr).replace("heading"," {0,3}#{1,6} ").replace("|lheading","").replace("table",Te.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",Te._tag).getRegex(),Te.pedantic={...Te.normal,html:rt(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",Te._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:ts,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:rt(Te.normal._paragraph).replace("hr",Te.hr).replace("heading",` *#{1,6} *[^
|
|
52
|
+
]`).replace("lheading",Te.lheading).replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").getRegex()};const le={escape:/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,autolink:/^<(scheme:[^\s\x00-\x1f<>]*|email)>/,url:ts,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:ts,text:/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,punctuation:/^([\spunctuation])/};le._punctuation="!\"#$%&'()+\\-.,/:;<=>?@\\[\\]`^{|}~",le.punctuation=rt(le.punctuation).replace(/punctuation/g,le._punctuation).getRegex(),le.blockSkip=/\[[^\]]*?\]\([^\)]*?\)|`[^`]*?`|<[^>]*?>/g,le.escapedEmSt=/(?:^|[^\\])(?:\\\\)*\\[*_]/g,le._comment=rt(Te._comment).replace("(?:-->|$)","-->").getRegex(),le.emStrong.lDelim=rt(le.emStrong.lDelim).replace(/punct/g,le._punctuation).getRegex(),le.emStrong.rDelimAst=rt(le.emStrong.rDelimAst,"g").replace(/punct/g,le._punctuation).getRegex(),le.emStrong.rDelimUnd=rt(le.emStrong.rDelimUnd,"g").replace(/punct/g,le._punctuation).getRegex(),le._escapes=/\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/g,le._scheme=/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/,le._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])?)+(?![-_])/,le.autolink=rt(le.autolink).replace("scheme",le._scheme).replace("email",le._email).getRegex(),le._attribute=/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/,le.tag=rt(le.tag).replace("comment",le._comment).replace("attribute",le._attribute).getRegex(),le._label=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,le._href=/<(?:\\.|[^\n<>\\])+>|[^\s\x00-\x1f]*/,le._title=/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/,le.link=rt(le.link).replace("label",le._label).replace("href",le._href).replace("title",le._title).getRegex(),le.reflink=rt(le.reflink).replace("label",le._label).replace("ref",Te._label).getRegex(),le.nolink=rt(le.nolink).replace("ref",Te._label).getRegex(),le.reflinkSearch=rt(le.reflinkSearch,"g").replace("reflink",le.reflink).replace("nolink",le.nolink).getRegex(),le.normal={...le},le.pedantic={...le.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:rt(/^!?\[(label)\]\((.*?)\)/).replace("label",le._label).getRegex(),reflink:rt(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",le._label).getRegex()},le.gfm={...le.normal,escape:rt(le.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.!#$%&'*+\/=?_`{\|}~-]+@)))/},le.gfm.url=rt(le.gfm.url,"i").replace("email",le.gfm._extended_email).getRegex(),le.breaks={...le.gfm,br:rt(le.br).replace("{2,}","*").getRegex(),text:rt(le.gfm.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()};function xw(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 Wu(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 Fn{constructor(t){this.tokens=[],this.tokens.links=Object.create(null),this.options=t||sr,this.options.tokenizer=this.options.tokenizer||new ra,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:Te.normal,inline:le.normal};this.options.pedantic?(n.block=Te.pedantic,n.inline=le.pedantic):this.options.gfm&&(n.block=Te.gfm,this.options.breaks?n.inline=le.breaks:n.inline=le.gfm),this.tokenizer.rules=n}static get rules(){return{block:Te,inline:le}}static lex(t,n){return new Fn(n).lex(t)}static lexInline(t,n){return new Fn(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)+"["+Hu("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)+"["+Hu("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,Wu)){t=t.substring(r.raw.length),n.push(r);continue}if(!this.state.inLink&&(r=this.tokenizer.url(t,Wu))){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,xw)){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 oa{constructor(t){this.options=t||sr}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+Nt(o)+'">'+(r?t:Nt(t,!0))+`</code></pre>
|
|
64
|
+
`:"<pre><code>"+(r?t:Nt(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>"+Et(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 Hu(e,t){return(n,r,o)=>{typeof r=="function"&&(o=r,r=null);const s={...r};r={...Ce.defaults,...s};const i=fw(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(cw(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&&Ce.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;Ce.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(Ce.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&&Ce.walkTokens(a,r.walkTokens);let l=t(a,r);return r.hooks&&(l=r.hooks.postprocess(l)),l}catch(a){return i(a)}}}function Ce(e,t,n){return Hu(Ln.lex,Fn.parse)(e,t,n)}Ce.options=Ce.setOptions=function(e){return Ce.defaults={...Ce.defaults,...e},Xv(Ce.defaults),Ce},Ce.getDefaults=_u,Ce.defaults=er,Ce.use=function(...e){const t=Ce.defaults.extensions||{renderers:{},childTokens:{}};e.forEach(n=>{const r={...n};if(r.async=Ce.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=Ce.defaults.renderer||new Qi;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=Ce.defaults.tokenizer||new Zi;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=Ce.defaults.hooks||new es;for(const s in n.hooks){const i=o[s];es.passThroughHooks.has(s)?o[s]=a=>{if(Ce.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=Ce.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}}Ce.setOptions(r)})},Ce.walkTokens=function(e,t){let n=[];for(const r of e)switch(n=n.concat(t.call(Ce,r)),r.type){case"table":{for(const o of r.header)n=n.concat(Ce.walkTokens(o.tokens,t));for(const o of r.rows)for(const s of o)n=n.concat(Ce.walkTokens(s.tokens,t));break}case"list":{n=n.concat(Ce.walkTokens(r.items,t));break}default:Ce.defaults.extensions&&Ce.defaults.extensions.childTokens&&Ce.defaults.extensions.childTokens[r.type]?Ce.defaults.extensions.childTokens[r.type].forEach(function(o){n=n.concat(Ce.walkTokens(r[o],t))}):r.tokens&&(n=n.concat(Ce.walkTokens(r.tokens,t)))}return n},Ce.parseInline=Hu(Ln.lexInline,Fn.parseInline),Ce.Parser=Fn,Ce.parser=Fn.parse,Ce.Renderer=Qi,Ce.TextRenderer=zu,Ce.Lexer=Ln,Ce.lexer=Ln.lex,Ce.Tokenizer=Zi,Ce.Slugger=Bu,Ce.Hooks=es,Ce.parse=Ce,Ce.options,Ce.setOptions,Ce.use,Ce.walkTokens,Ce.parseInline,Fn.parse,Ln.lex;function ea({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 Ce.parse(i)}return Ce.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 Uu(e,t){return await Dt(e,{responseType:"blob",onDownloadProgress:r=>{try{t&&r.lengthComputable}catch{}},maxBodyLength:1/0})}async function Wu(e,t){return await(await Uu(`/files/${e}/view`,t)).text()}async function hw(e,t){const n=await Uu(`/files/${e}/download`,t),r=URL.createObjectURL(n);let o=`file_${e}`;try{const i=await Dt(`/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 pw(e,t=50,n=0){const r={limit:t,offset:n};return e&&(r.thread_id=e),await Dt("/files",{params:r})}const mw=1,gw=1e6;let ta=0;function xw(){return ta=(ta+1)%Number.MAX_SAFE_INTEGER,ta.toString()}const na=new Map,Vu=e=>{if(na.has(e))return;const t=setTimeout(()=>{na.delete(e),oo({type:"REMOVE_TOAST",toastId:e})},gw);na.set(e,t)},vw=(e,t)=>{switch(t.type){case"ADD_TOAST":return{...e,toasts:[t.toast,...e.toasts].slice(0,mw)};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?Vu(n):e.toasts.forEach(r=>{Vu(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)}}},ts=[];let ns={toasts:[]};function oo(e){ns=vw(ns,e),ts.forEach(t=>{t(ns)})}function ww({...e}){const t=xw(),n=o=>oo({type:"UPDATE_TOAST",toast:{...o,id:t}}),r=()=>oo({type:"DISMISS_TOAST",toastId:t});return oo({type:"ADD_TOAST",toast:{...e,id:t,open:!0,onOpenChange:o=>{o||r()}}}),{id:t,dismiss:r,update:n}}function ra(){const[e,t]=m.useState(ns);return m.useEffect(()=>(ts.push(t),()=>{const n=ts.indexOf(t);n>-1&&ts.splice(n,1)}),[e]),{...e,toast:ww,dismiss:n=>oo({type:"DISMISS_TOAST",toastId:n})}}function yt(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 bw(e,t=globalThis==null?void 0:globalThis.document){const n=yt(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 yw="DismissableLayer",oa="dismissableLayer.update",Sw="dismissableLayer.pointerDownOutside",Cw="dismissableLayer.focusOutside",Ku,qu=m.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),rs=m.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:a,...l}=e,u=m.useContext(qu),[d,f]=m.useState(null),h=(d==null?void 0:d.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,p]=m.useState({}),w=We(t,E=>f(E)),x=Array.from(u.layers),[g]=[...u.layersWithOutsidePointerEventsDisabled].slice(-1),v=x.indexOf(g),b=d?x.indexOf(d):-1,S=u.layersWithOutsidePointerEventsDisabled.size>0,N=b>=v,C=Iw(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=Ew(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 bw(E=>{b===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&&(Ku=h.body.style.pointerEvents,h.body.style.pointerEvents="none"),u.layersWithOutsidePointerEventsDisabled.add(d)),u.layers.add(d),Gu(),()=>{n&&u.layersWithOutsidePointerEventsDisabled.size===1&&(h.body.style.pointerEvents=Ku)}},[d,h,n,u]),m.useEffect(()=>()=>{d&&(u.layers.delete(d),u.layersWithOutsidePointerEventsDisabled.delete(d),Gu())},[d,u]),m.useEffect(()=>{const E=()=>p({});return document.addEventListener(oa,E),()=>document.removeEventListener(oa,E)},[]),c.jsx(je.div,{...l,ref:w,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,C.onPointerDownCapture)})});rs.displayName=yw;var Tw="DismissableLayerBranch",kw=m.forwardRef((e,t)=>{const n=m.useContext(qu),r=m.useRef(null),o=We(t,r);return m.useEffect(()=>{const s=r.current;if(s)return n.branches.add(s),()=>{n.branches.delete(s)}},[n.branches]),c.jsx(je.div,{...e,ref:o})});kw.displayName=Tw;function Iw(e,t=globalThis==null?void 0:globalThis.document){const n=yt(e),r=m.useRef(!1),o=m.useRef(()=>{});return m.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let l=function(){Yu(Sw,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 Ew(e,t=globalThis==null?void 0:globalThis.document){const n=yt(e),r=m.useRef(!1);return m.useEffect(()=>{const o=s=>{s.target&&!r.current&&Yu(Cw,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 Gu(){const e=new CustomEvent(oa);document.dispatchEvent(e)}function Yu(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?Su(o,s):o.dispatchEvent(s)}var sa="focusScope.autoFocusOnMount",ia="focusScope.autoFocusOnUnmount",Xu={bubbles:!1,cancelable:!0},Nw="FocusScope",os=m.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:s,...i}=e,[a,l]=m.useState(null),u=yt(o),d=yt(s),f=m.useRef(null),h=We(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:$n(f.current,{select:!0})},g=function(S){if(p.paused||!a)return;const N=S.relatedTarget;N!==null&&(a.contains(N)||$n(f.current,{select:!0}))},v=function(S){if(document.activeElement===document.body)for(const C of S)C.removedNodes.length>0&&$n(a)};document.addEventListener("focusin",x),document.addEventListener("focusout",g);const b=new MutationObserver(v);return a&&b.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",x),document.removeEventListener("focusout",g),b.disconnect()}}},[r,a,p.paused]),m.useEffect(()=>{if(a){Qu.add(p);const x=document.activeElement;if(!a.contains(x)){const v=new CustomEvent(sa,Xu);a.addEventListener(sa,u),a.dispatchEvent(v),v.defaultPrevented||(Aw(Ow(Ju(a)),{select:!0}),document.activeElement===x&&$n(a))}return()=>{a.removeEventListener(sa,u),setTimeout(()=>{const v=new CustomEvent(ia,Xu);a.addEventListener(ia,d),a.dispatchEvent(v),v.defaultPrevented||$n(x??document.body,{select:!0}),a.removeEventListener(ia,d),Qu.remove(p)},0)}}},[a,u,d,p]);const w=m.useCallback(x=>{if(!n&&!r||p.paused)return;const g=x.key==="Tab"&&!x.altKey&&!x.ctrlKey&&!x.metaKey,v=document.activeElement;if(g&&v){const b=x.currentTarget,[S,N]=_w(b);S&&N?!x.shiftKey&&v===N?(x.preventDefault(),n&&$n(S,{select:!0})):x.shiftKey&&v===S&&(x.preventDefault(),n&&$n(N,{select:!0})):v===b&&x.preventDefault()}},[n,r,p.paused]);return c.jsx(je.div,{tabIndex:-1,...i,ref:h,onKeyDown:w})});os.displayName=Nw;function Aw(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if($n(r,{select:t}),document.activeElement!==n)return}function _w(e){const t=Ju(e),n=Zu(t,e),r=Zu(t.reverse(),e);return[n,r]}function Ju(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 Zu(e,t){for(const n of e)if(!jw(n,{upTo:t}))return n}function jw(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 Rw(e){return e instanceof HTMLInputElement&&"select"in e}function $n(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&Rw(e)&&t&&e.select()}}var Qu=Pw();function Pw(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=ed(e,t),e.unshift(t)},remove(t){var n;e=ed(e,t),(n=e[0])==null||n.resume()}}}function ed(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function Ow(e){return e.filter(t=>t.tagName!=="A")}var Mw="Portal",ss=m.forwardRef((e,t)=>{var a;const{container:n,...r}=e,[o,s]=m.useState(!1);vt(()=>s(!0),[]);const i=n||o&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?Zs.createPortal(c.jsx(je.div,{...r,ref:t}),i):null});ss.displayName=Mw;var aa=0;function la(){m.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??td()),document.body.insertAdjacentElement("beforeend",e[1]??td()),aa++,()=>{aa===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),aa--}},[])}function td(){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 gn=function(){return gn=Object.assign||function(t){for(var n,r=1,o=arguments.length;r<o;r++){n=arguments[r];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(t[s]=n[s])}return t},gn.apply(this,arguments)};function nd(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 Dw(e,t,n){if(n||arguments.length===2)for(var r=0,o=t.length,s;r<o;r++)(s||!(r in t))&&(s||(s=Array.prototype.slice.call(t,0,r)),s[r]=t[r]);return e.concat(s||Array.prototype.slice.call(t))}typeof SuppressedError=="function"&&SuppressedError;var is="right-scroll-bar-position",as="width-before-scroll-bar",Lw="with-scroll-bars-hidden",Fw="--removed-body-scroll-bar-size";function ca(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function $w(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 zw=typeof window<"u"?m.useLayoutEffect:m.useEffect,rd=new WeakMap;function Bw(e,t){var n=$w(null,function(r){return e.forEach(function(o){return ca(o,r)})});return zw(function(){var r=rd.get(n);if(r){var o=new Set(r),s=new Set(e),i=n.current;o.forEach(function(a){s.has(a)||ca(a,null)}),s.forEach(function(a){o.has(a)||ca(a,i)})}rd.set(n,e)},[e]),n}function Hw(e){return e}function Uw(e,t){t===void 0&&(t=Hw);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 Ww(e){e===void 0&&(e={});var t=Uw(null);return t.options=gn({async:!0,ssr:!1},e),t}var od=function(e){var t=e.sideCar,n=nd(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,gn({},n))};od.isSideCarExport=!0;function Vw(e,t){return e.useMedium(t),od}var sd=Ww(),ua=function(){},ls=m.forwardRef(function(e,t){var n=m.useRef(null),r=m.useState({onScrollCapture:ua,onWheelCapture:ua,onTouchMoveCapture:ua}),o=r[0],s=r[1],i=e.forwardProps,a=e.children,l=e.className,u=e.removeScrollBar,d=e.enabled,f=e.shards,h=e.sideCar,p=e.noRelative,w=e.noIsolation,x=e.inert,g=e.allowPinchZoom,v=e.as,b=v===void 0?"div":v,S=e.gapMode,N=nd(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),C=h,k=Bw([n,t]),E=gn(gn({},N),o);return m.createElement(m.Fragment,null,d&&m.createElement(C,{sideCar:sd,removeScrollBar:u,shards:f,noRelative:p,noIsolation:w,inert:x,setCallbacks:s,allowPinchZoom:!!g,lockRef:n,gapMode:S}),i?m.cloneElement(m.Children.only(a),gn(gn({},E),{ref:k})):m.createElement(b,gn({},E,{className:l,ref:k}),a))});ls.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},ls.classNames={fullWidth:as,zeroRight:is};var Kw=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function qw(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=Kw();return t&&e.setAttribute("nonce",t),e}function Gw(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function Yw(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var Xw=function(){var e=0,t=null;return{add:function(n){e==0&&(t=qw())&&(Gw(t,n),Yw(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},Jw=function(){var e=Xw();return function(t,n){m.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},id=function(){var e=Jw(),t=function(n){var r=n.styles,o=n.dynamic;return e(r,o),null};return t},Zw={left:0,top:0,right:0,gap:0},da=function(e){return parseInt(e||"",10)||0},Qw=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[da(n),da(r),da(o)]},eb=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return Zw;var t=Qw(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])}},tb=id(),Sr="data-scroll-locked",nb=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=Bu(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=Bu(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 Vu{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 qu{constructor(){this.seen={}}serialize(t){return t.toLowerCase().trim().replace(/<[!\/a-z].*?>/ig,"").replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g,"").replace(/\s/g,"-")}getNextSafeSlug(t,n){let r=t,o=0;if(this.seen.hasOwnProperty(r)){o=this.seen[t];do o++,r=t+"-"+o;while(this.seen.hasOwnProperty(r))}return n||(this.seen[t]=o,this.seen[r]=0),r}slug(t,n={}){const r=this.serialize(t);return this.getNextSafeSlug(r,n.dryrun)}}class $n{constructor(t){this.options=t||sr,this.options.renderer=this.options.renderer||new oa,this.renderer=this.options.renderer,this.renderer.options=this.options,this.textRenderer=new Vu,this.slugger=new qu}static parse(t,n){return new $n(n).parse(t)}static parseInline(t,n){return new $n(n).parseInline(t)}parse(t,n=!0){let r="",o,s,i,a,l,u,d,f,h,p,w,x,g,v,b,S,N,C,k;const I=t.length;for(o=0;o<I;o++){if(p=t[o],this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[p.type]&&(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,$u(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(w=p.ordered,x=p.start,g=p.loose,a=p.items.length,h="",s=0;s<a;s++)b=p.items[s],S=b.checked,N=b.task,v="",b.task&&(C=this.renderer.checkbox(S),g?b.tokens.length>0&&b.tokens[0].type==="paragraph"?(b.tokens[0].text=C+" "+b.tokens[0].text,b.tokens[0].tokens&&b.tokens[0].tokens.length>0&&b.tokens[0].tokens[0].type==="text"&&(b.tokens[0].tokens[0].text=C+" "+b.tokens[0].tokens[0].text)):b.tokens.unshift({type:"text",text:C}):v+=C),v+=this.parse(b.tokens,g),h+=this.renderer.listitem(v,N,S);r+=this.renderer.list(h,w,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<I&&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 rs{constructor(t){this.options=t||sr}preprocess(t){return t}postprocess(t){return t}}im(rs,"passThroughHooks",new Set(["preprocess","postprocess"]));function vw(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>"+Nt(r.message+"",!0)+"</pre>";if(t)return Promise.resolve(o);if(n){n(null,o);return}return o}if(t)return Promise.reject(r);if(n){n(r);return}throw r}}function Ku(e,t){return(n,r,o)=>{typeof r=="function"&&(o=r,r=null);const s={...r};r={...ke.defaults,...s};const i=vw(r.silent,r.async,o);if(typeof n>"u"||n===null)return i(new Error("marked(): input parameter is undefined or null"));if(typeof n!="string")return i(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(n)+", string expected"));if(mw(r),r.hooks&&(r.hooks.options=r),o){const a=r.highlight;let l;try{r.hooks&&(n=r.hooks.preprocess(n)),l=e(n,r)}catch(f){return i(f)}const u=function(f){let h;if(!f)try{r.walkTokens&&ke.walkTokens(l,r.walkTokens),h=t(l,r),r.hooks&&(h=r.hooks.postprocess(h))}catch(p){f=p}return r.highlight=a,f?i(f):o(null,h)};if(!a||a.length<3||(delete r.highlight,!l.length))return u();let d=0;ke.walkTokens(l,function(f){f.type==="code"&&(d++,setTimeout(()=>{a(f.text,f.lang,function(h,p){if(h)return u(h);p!=null&&p!==f.text&&(f.text=p,f.escaped=!0),d--,d===0&&u()})},0))}),d===0&&u();return}if(r.async)return Promise.resolve(r.hooks?r.hooks.preprocess(n):n).then(a=>e(a,r)).then(a=>r.walkTokens?Promise.all(ke.walkTokens(a,r.walkTokens)).then(()=>a):a).then(a=>t(a,r)).then(a=>r.hooks?r.hooks.postprocess(a):a).catch(i);try{r.hooks&&(n=r.hooks.preprocess(n));const a=e(n,r);r.walkTokens&&ke.walkTokens(a,r.walkTokens);let l=t(a,r);return r.hooks&&(l=r.hooks.postprocess(l)),l}catch(a){return i(a)}}}function ke(e,t,n){return Ku(Fn.lex,$n.parse)(e,t,n)}ke.options=ke.setOptions=function(e){return ke.defaults={...ke.defaults,...e},nw(ke.defaults),ke},ke.getDefaults=Mu,ke.defaults=sr,ke.use=function(...e){const t=ke.defaults.extensions||{renderers:{},childTokens:{}};e.forEach(n=>{const r={...n};if(r.async=ke.defaults.async||r.async||!1,n.extensions&&(n.extensions.forEach(o=>{if(!o.name)throw new Error("extension name required");if(o.renderer){const s=t.renderers[o.name];s?t.renderers[o.name]=function(...i){let a=o.renderer.apply(this,i);return a===!1&&(a=s.apply(this,i)),a}:t.renderers[o.name]=o.renderer}if(o.tokenizer){if(!o.level||o.level!=="block"&&o.level!=="inline")throw new Error("extension level must be 'block' or 'inline'");t[o.level]?t[o.level].unshift(o.tokenizer):t[o.level]=[o.tokenizer],o.start&&(o.level==="block"?t.startBlock?t.startBlock.push(o.start):t.startBlock=[o.start]:o.level==="inline"&&(t.startInline?t.startInline.push(o.start):t.startInline=[o.start]))}o.childTokens&&(t.childTokens[o.name]=o.childTokens)}),r.extensions=t),n.renderer){const o=ke.defaults.renderer||new oa;for(const s in n.renderer){const i=o[s];o[s]=(...a)=>{let l=n.renderer[s].apply(o,a);return l===!1&&(l=i.apply(o,a)),l}}r.renderer=o}if(n.tokenizer){const o=ke.defaults.tokenizer||new ra;for(const s in n.tokenizer){const i=o[s];o[s]=(...a)=>{let l=n.tokenizer[s].apply(o,a);return l===!1&&(l=i.apply(o,a)),l}}r.tokenizer=o}if(n.hooks){const o=ke.defaults.hooks||new rs;for(const s in n.hooks){const i=o[s];rs.passThroughHooks.has(s)?o[s]=a=>{if(ke.defaults.async)return Promise.resolve(n.hooks[s].call(o,a)).then(u=>i.call(o,u));const l=n.hooks[s].call(o,a);return i.call(o,l)}:o[s]=(...a)=>{let l=n.hooks[s].apply(o,a);return l===!1&&(l=i.apply(o,a)),l}}r.hooks=o}if(n.walkTokens){const o=ke.defaults.walkTokens;r.walkTokens=function(s){let i=[];return i.push(n.walkTokens.call(this,s)),o&&(i=i.concat(o.call(this,s))),i}}ke.setOptions(r)})},ke.walkTokens=function(e,t){let n=[];for(const r of e)switch(n=n.concat(t.call(ke,r)),r.type){case"table":{for(const o of r.header)n=n.concat(ke.walkTokens(o.tokens,t));for(const o of r.rows)for(const s of o)n=n.concat(ke.walkTokens(s.tokens,t));break}case"list":{n=n.concat(ke.walkTokens(r.items,t));break}default:ke.defaults.extensions&&ke.defaults.extensions.childTokens&&ke.defaults.extensions.childTokens[r.type]?ke.defaults.extensions.childTokens[r.type].forEach(function(o){n=n.concat(ke.walkTokens(r[o],t))}):r.tokens&&(n=n.concat(ke.walkTokens(r.tokens,t)))}return n},ke.parseInline=Ku(Fn.lexInline,$n.parseInline),ke.Parser=$n,ke.parser=$n.parse,ke.Renderer=oa,ke.TextRenderer=Vu,ke.Lexer=Fn,ke.lexer=Fn.lex,ke.Tokenizer=ra,ke.Slugger=qu,ke.Hooks=rs,ke.parse=ke,ke.options,ke.setOptions,ke.use,ke.walkTokens,ke.parseInline,$n.parse,Fn.lex;function sa({content:e,className:t="",allowHtml:n=!1,style:r}){const o=y.useMemo(()=>{try{if(!n){const i=e.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,"").replace(/<iframe\b[^<]*(?:(?!<\/iframe>)<[^<]*)*<\/iframe>/gi,"").replace(/javascript:/gi,"").replace(/on\w+\s*=/gi,"");return ke.parse(i)}return ke.parse(e)}catch(i){return console.error("[MarkdownContent] parse error",i),`<pre>Error rendering markdown: ${String(i)}</pre>`}},[e,n]),s=y.useMemo(()=>{if(r&&r.color){const i=r.color;return{...r,"--tw-prose-body":i,"--tw-prose-headings":i,"--tw-prose-links":i,"--tw-prose-bold":i,"--tw-prose-counters":i,"--tw-prose-bullets":i,"--tw-prose-hr":i,"--tw-prose-quotes":i,"--tw-prose-quote-borders":i,"--tw-prose-captions":i,"--tw-prose-code":i,"--tw-prose-pre-code":i,"--tw-prose-pre-bg":"inherit","--tw-prose-th-borders":i,"--tw-prose-td-borders":i}}return r},[r]);return c.jsx("div",{className:Z("markdown prose max-w-none break-words dark:prose-invert",t),style:s,dangerouslySetInnerHTML:{__html:o}})}async function Gu(e,t){return await nn(e,{responseType:"blob",onDownloadProgress:r=>{try{t&&r.lengthComputable}catch{}},maxBodyLength:1/0})}async function Yu(e,t){return await(await Gu(`/files/${e}/view`,t)).text()}async function ww(e,t){const n=await Gu(`/files/${e}/download`,t),r=URL.createObjectURL(n);let o=`file_${e}`;try{const i=await nn(`/files/${e}`);o=(i==null?void 0:i.filename)??o}catch{}const s=document.createElement("a");s.href=r,s.download=o,document.body.appendChild(s),s.click(),s.remove(),setTimeout(()=>URL.revokeObjectURL(r),6e4)}async function bw(e,t=50,n=0){const r={limit:t,offset:n};return e&&(r.thread_id=e),await nn("/files",{params:r})}const yw=1,Sw=1e6;let ia=0;function Cw(){return ia=(ia+1)%Number.MAX_SAFE_INTEGER,ia.toString()}const aa=new Map,Xu=e=>{if(aa.has(e))return;const t=setTimeout(()=>{aa.delete(e),io({type:"REMOVE_TOAST",toastId:e})},Sw);aa.set(e,t)},Tw=(e,t)=>{switch(t.type){case"ADD_TOAST":return{...e,toasts:[t.toast,...e.toasts].slice(0,yw)};case"UPDATE_TOAST":return{...e,toasts:e.toasts.map(n=>n.id===t.toast.id?{...n,...t.toast}:n)};case"DISMISS_TOAST":{const{toastId:n}=t;return n?Xu(n):e.toasts.forEach(r=>{Xu(r.id)}),{...e,toasts:e.toasts.map(r=>r.id===n||n===void 0?{...r,open:!1}:r)}}case"REMOVE_TOAST":return t.toastId===void 0?{...e,toasts:[]}:{...e,toasts:e.toasts.filter(n=>n.id!==t.toastId)}}},os=[];let ss={toasts:[]};function io(e){ss=Tw(ss,e),os.forEach(t=>{t(ss)})}function kw({...e}){const t=Cw(),n=o=>io({type:"UPDATE_TOAST",toast:{...o,id:t}}),r=()=>io({type:"DISMISS_TOAST",toastId:t});return io({type:"ADD_TOAST",toast:{...e,id:t,open:!0,onOpenChange:o=>{o||r()}}}),{id:t,dismiss:r,update:n}}function la(){const[e,t]=m.useState(ss);return m.useEffect(()=>(os.push(t),()=>{const n=os.indexOf(t);n>-1&&os.splice(n,1)}),[e]),{...e,toast:kw,dismiss:n=>io({type:"DISMISS_TOAST",toastId:n})}}function Tt(e){const t=m.useRef(e);return m.useEffect(()=>{t.current=e}),m.useMemo(()=>(...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)},[])}function Ew(e,t=globalThis==null?void 0:globalThis.document){const n=Tt(e);m.useEffect(()=>{const r=o=>{o.key==="Escape"&&n(o)};return t.addEventListener("keydown",r,{capture:!0}),()=>t.removeEventListener("keydown",r,{capture:!0})},[n,t])}var Iw="DismissableLayer",ca="dismissableLayer.update",Nw="dismissableLayer.pointerDownOutside",Aw="dismissableLayer.focusOutside",Ju,Zu=m.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),is=m.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:a,...l}=e,u=m.useContext(Zu),[d,f]=m.useState(null),h=(d==null?void 0:d.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,p]=m.useState({}),w=Ve(t,I=>f(I)),x=Array.from(u.layers),[g]=[...u.layersWithOutsidePointerEventsDisabled].slice(-1),v=x.indexOf(g),b=d?x.indexOf(d):-1,S=u.layersWithOutsidePointerEventsDisabled.size>0,N=b>=v,C=Rw(I=>{const A=I.target,j=[...u.branches].some(P=>P.contains(A));!N||j||(o==null||o(I),i==null||i(I),I.defaultPrevented||a==null||a())},h),k=Pw(I=>{const A=I.target;[...u.branches].some(P=>P.contains(A))||(s==null||s(I),i==null||i(I),I.defaultPrevented||a==null||a())},h);return Ew(I=>{b===u.layers.size-1&&(r==null||r(I),!I.defaultPrevented&&a&&(I.preventDefault(),a()))},h),m.useEffect(()=>{if(d)return n&&(u.layersWithOutsidePointerEventsDisabled.size===0&&(Ju=h.body.style.pointerEvents,h.body.style.pointerEvents="none"),u.layersWithOutsidePointerEventsDisabled.add(d)),u.layers.add(d),Qu(),()=>{n&&u.layersWithOutsidePointerEventsDisabled.size===1&&(h.body.style.pointerEvents=Ju)}},[d,h,n,u]),m.useEffect(()=>()=>{d&&(u.layers.delete(d),u.layersWithOutsidePointerEventsDisabled.delete(d),Qu())},[d,u]),m.useEffect(()=>{const I=()=>p({});return document.addEventListener(ca,I),()=>document.removeEventListener(ca,I)},[]),c.jsx(_e.div,{...l,ref:w,style:{pointerEvents:S?N?"auto":"none":void 0,...e.style},onFocusCapture:ue(e.onFocusCapture,k.onFocusCapture),onBlurCapture:ue(e.onBlurCapture,k.onBlurCapture),onPointerDownCapture:ue(e.onPointerDownCapture,C.onPointerDownCapture)})});is.displayName=Iw;var _w="DismissableLayerBranch",jw=m.forwardRef((e,t)=>{const n=m.useContext(Zu),r=m.useRef(null),o=Ve(t,r);return m.useEffect(()=>{const s=r.current;if(s)return n.branches.add(s),()=>{n.branches.delete(s)}},[n.branches]),c.jsx(_e.div,{...e,ref:o})});jw.displayName=_w;function Rw(e,t=globalThis==null?void 0:globalThis.document){const n=Tt(e),r=m.useRef(!1),o=m.useRef(()=>{});return m.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let l=function(){ed(Nw,n,u,{discrete:!0})};const u={originalEvent:a};a.pointerType==="touch"?(t.removeEventListener("click",o.current),o.current=l,t.addEventListener("click",o.current,{once:!0})):l()}else t.removeEventListener("click",o.current);r.current=!1},i=window.setTimeout(()=>{t.addEventListener("pointerdown",s)},0);return()=>{window.clearTimeout(i),t.removeEventListener("pointerdown",s),t.removeEventListener("click",o.current)}},[t,n]),{onPointerDownCapture:()=>r.current=!0}}function Pw(e,t=globalThis==null?void 0:globalThis.document){const n=Tt(e),r=m.useRef(!1);return m.useEffect(()=>{const o=s=>{s.target&&!r.current&&ed(Aw,n,{originalEvent:s},{discrete:!1})};return t.addEventListener("focusin",o),()=>t.removeEventListener("focusin",o)},[t,n]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}function Qu(){const e=new CustomEvent(ca);document.dispatchEvent(e)}function ed(e,t,n,{discrete:r}){const o=n.originalEvent.target,s=new CustomEvent(e,{bubbles:!1,cancelable:!0,detail:n});t&&o.addEventListener(e,t,{once:!0}),r?Iu(o,s):o.dispatchEvent(s)}var ua="focusScope.autoFocusOnMount",da="focusScope.autoFocusOnUnmount",td={bubbles:!1,cancelable:!0},Ow="FocusScope",as=m.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:s,...i}=e,[a,l]=m.useState(null),u=Tt(o),d=Tt(s),f=m.useRef(null),h=Ve(t,x=>l(x)),p=m.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;m.useEffect(()=>{if(r){let x=function(S){if(p.paused||!a)return;const N=S.target;a.contains(N)?f.current=N:Bn(f.current,{select:!0})},g=function(S){if(p.paused||!a)return;const N=S.relatedTarget;N!==null&&(a.contains(N)||Bn(f.current,{select:!0}))},v=function(S){if(document.activeElement===document.body)for(const C of S)C.removedNodes.length>0&&Bn(a)};document.addEventListener("focusin",x),document.addEventListener("focusout",g);const b=new MutationObserver(v);return a&&b.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",x),document.removeEventListener("focusout",g),b.disconnect()}}},[r,a,p.paused]),m.useEffect(()=>{if(a){od.add(p);const x=document.activeElement;if(!a.contains(x)){const v=new CustomEvent(ua,td);a.addEventListener(ua,u),a.dispatchEvent(v),v.defaultPrevented||(Mw(Bw(nd(a)),{select:!0}),document.activeElement===x&&Bn(a))}return()=>{a.removeEventListener(ua,u),setTimeout(()=>{const v=new CustomEvent(da,td);a.addEventListener(da,d),a.dispatchEvent(v),v.defaultPrevented||Bn(x??document.body,{select:!0}),a.removeEventListener(da,d),od.remove(p)},0)}}},[a,u,d,p]);const w=m.useCallback(x=>{if(!n&&!r||p.paused)return;const g=x.key==="Tab"&&!x.altKey&&!x.ctrlKey&&!x.metaKey,v=document.activeElement;if(g&&v){const b=x.currentTarget,[S,N]=Dw(b);S&&N?!x.shiftKey&&v===N?(x.preventDefault(),n&&Bn(S,{select:!0})):x.shiftKey&&v===S&&(x.preventDefault(),n&&Bn(N,{select:!0})):v===b&&x.preventDefault()}},[n,r,p.paused]);return c.jsx(_e.div,{tabIndex:-1,...i,ref:h,onKeyDown:w})});as.displayName=Ow;function Mw(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(Bn(r,{select:t}),document.activeElement!==n)return}function Dw(e){const t=nd(e),n=rd(t,e),r=rd(t.reverse(),e);return[n,r]}function nd(e){const t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:r=>{const o=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||o?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;n.nextNode();)t.push(n.currentNode);return t}function rd(e,t){for(const n of e)if(!Lw(n,{upTo:t}))return n}function Lw(e,{upTo:t}){if(getComputedStyle(e).visibility==="hidden")return!0;for(;e;){if(t!==void 0&&e===t)return!1;if(getComputedStyle(e).display==="none")return!0;e=e.parentElement}return!1}function Fw(e){return e instanceof HTMLInputElement&&"select"in e}function Bn(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&Fw(e)&&t&&e.select()}}var od=$w();function $w(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=sd(e,t),e.unshift(t)},remove(t){var n;e=sd(e,t),(n=e[0])==null||n.resume()}}}function sd(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function Bw(e){return e.filter(t=>t.tagName!=="A")}var zw="Portal",ls=m.forwardRef((e,t)=>{var a;const{container:n,...r}=e,[o,s]=m.useState(!1);Ct(()=>s(!0),[]);const i=n||o&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?ti.createPortal(c.jsx(_e.div,{...r,ref:t}),i):null});ls.displayName=zw;var fa=0;function ha(){m.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??id()),document.body.insertAdjacentElement("beforeend",e[1]??id()),fa++,()=>{fa===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),fa--}},[])}function id(){const e=document.createElement("span");return e.setAttribute("data-radix-focus-guard",""),e.tabIndex=0,e.style.outline="none",e.style.opacity="0",e.style.position="fixed",e.style.pointerEvents="none",e}var wn=function(){return wn=Object.assign||function(t){for(var n,r=1,o=arguments.length;r<o;r++){n=arguments[r];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(t[s]=n[s])}return t},wn.apply(this,arguments)};function ad(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var o=0,r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]]);return n}function Hw(e,t,n){if(n||arguments.length===2)for(var r=0,o=t.length,s;r<o;r++)(s||!(r in t))&&(s||(s=Array.prototype.slice.call(t,0,r)),s[r]=t[r]);return e.concat(s||Array.prototype.slice.call(t))}typeof SuppressedError=="function"&&SuppressedError;var cs="right-scroll-bar-position",us="width-before-scroll-bar",Uw="with-scroll-bars-hidden",Ww="--removed-body-scroll-bar-size";function pa(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function Vw(e,t){var n=y.useState(function(){return{value:e,callback:t,facade:{get current(){return n.value},set current(r){var o=n.value;o!==r&&(n.value=r,n.callback(r,o))}}}})[0];return n.callback=t,n.facade}var qw=typeof window<"u"?m.useLayoutEffect:m.useEffect,ld=new WeakMap;function Kw(e,t){var n=Vw(null,function(r){return e.forEach(function(o){return pa(o,r)})});return qw(function(){var r=ld.get(n);if(r){var o=new Set(r),s=new Set(e),i=n.current;o.forEach(function(a){s.has(a)||pa(a,null)}),s.forEach(function(a){o.has(a)||pa(a,i)})}ld.set(n,e)},[e]),n}function Gw(e){return e}function Yw(e,t){t===void 0&&(t=Gw);var n=[],r=!1,o={read:function(){if(r)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return n.length?n[n.length-1]:e},useMedium:function(s){var i=t(s,r);return n.push(i),function(){n=n.filter(function(a){return a!==i})}},assignSyncMedium:function(s){for(r=!0;n.length;){var i=n;n=[],i.forEach(s)}n={push:function(a){return s(a)},filter:function(){return n}}},assignMedium:function(s){r=!0;var i=[];if(n.length){var a=n;n=[],a.forEach(s),i=n}var l=function(){var d=i;i=[],d.forEach(s)},u=function(){return Promise.resolve().then(l)};u(),n={push:function(d){i.push(d),u()},filter:function(d){return i=i.filter(d),n}}}};return o}function Xw(e){e===void 0&&(e={});var t=Yw(null);return t.options=wn({async:!0,ssr:!1},e),t}var cd=function(e){var t=e.sideCar,n=ad(e,["sideCar"]);if(!t)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=t.read();if(!r)throw new Error("Sidecar medium not found");return m.createElement(r,wn({},n))};cd.isSideCarExport=!0;function Jw(e,t){return e.useMedium(t),cd}var ud=Xw(),ma=function(){},ds=m.forwardRef(function(e,t){var n=m.useRef(null),r=m.useState({onScrollCapture:ma,onWheelCapture:ma,onTouchMoveCapture:ma}),o=r[0],s=r[1],i=e.forwardProps,a=e.children,l=e.className,u=e.removeScrollBar,d=e.enabled,f=e.shards,h=e.sideCar,p=e.noRelative,w=e.noIsolation,x=e.inert,g=e.allowPinchZoom,v=e.as,b=v===void 0?"div":v,S=e.gapMode,N=ad(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),C=h,k=Kw([n,t]),I=wn(wn({},N),o);return m.createElement(m.Fragment,null,d&&m.createElement(C,{sideCar:ud,removeScrollBar:u,shards:f,noRelative:p,noIsolation:w,inert:x,setCallbacks:s,allowPinchZoom:!!g,lockRef:n,gapMode:S}),i?m.cloneElement(m.Children.only(a),wn(wn({},I),{ref:k})):m.createElement(b,wn({},I,{className:l,ref:k}),a))});ds.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},ds.classNames={fullWidth:us,zeroRight:cs};var Zw=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function Qw(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=Zw();return t&&e.setAttribute("nonce",t),e}function eb(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function tb(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var nb=function(){var e=0,t=null;return{add:function(n){e==0&&(t=Qw())&&(eb(t,n),tb(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},rb=function(){var e=nb();return function(t,n){m.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},dd=function(){var e=rb(),t=function(n){var r=n.styles,o=n.dynamic;return e(r,o),null};return t},ob={left:0,top:0,right:0,gap:0},ga=function(e){return parseInt(e||"",10)||0},sb=function(e){var t=window.getComputedStyle(document.body),n=t[e==="padding"?"paddingLeft":"marginLeft"],r=t[e==="padding"?"paddingTop":"marginTop"],o=t[e==="padding"?"paddingRight":"marginRight"];return[ga(n),ga(r),ga(o)]},ib=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return ob;var t=sb(e),n=document.documentElement.clientWidth,r=window.innerWidth;return{left:t[0],top:t[1],right:t[2],gap:Math.max(0,r-n+t[2]-t[0])}},ab=dd(),Tr="data-scroll-locked",lb=function(e,t,n,r){var o=e.left,s=e.top,i=e.right,a=e.gap;return n===void 0&&(n="margin"),`
|
|
85
|
+
.`.concat(Uw,` {
|
|
86
86
|
overflow: hidden `).concat(r,`;
|
|
87
87
|
padding-right: `).concat(a,"px ").concat(r,`;
|
|
88
88
|
}
|
|
89
|
-
body[`).concat(
|
|
89
|
+
body[`).concat(Tr,`] {
|
|
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(cs,` {
|
|
103
103
|
right: `).concat(a,"px ").concat(r,`;
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
.`).concat(
|
|
106
|
+
.`).concat(us,` {
|
|
107
107
|
margin-right: `).concat(a,"px ").concat(r,`;
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
.`).concat(
|
|
110
|
+
.`).concat(cs," .").concat(cs,` {
|
|
111
111
|
right: 0 `).concat(r,`;
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
-
.`).concat(
|
|
114
|
+
.`).concat(us," .").concat(us,` {
|
|
115
115
|
margin-right: 0 `).concat(r,`;
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
-
body[`).concat(
|
|
119
|
-
`).concat(
|
|
118
|
+
body[`).concat(Tr,`] {
|
|
119
|
+
`).concat(Ww,": ").concat(a,`px;
|
|
120
120
|
}
|
|
121
|
-
`)},
|
|
121
|
+
`)},fd=function(){var e=parseInt(document.body.getAttribute(Tr)||"0",10);return isFinite(e)?e:0},cb=function(){m.useEffect(function(){return document.body.setAttribute(Tr,(fd()+1).toString()),function(){var e=fd()-1;e<=0?document.body.removeAttribute(Tr):document.body.setAttribute(Tr,e.toString())}},[])},ub=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,o=r===void 0?"margin":r;cb();var s=m.useMemo(function(){return ib(o)},[o]);return m.createElement(ab,{styles:lb(s,!t,o,n?"":"!important")})},xa=!1;if(typeof window<"u")try{var fs=Object.defineProperty({},"passive",{get:function(){return xa=!0,!0}});window.addEventListener("test",fs,fs),window.removeEventListener("test",fs,fs)}catch{xa=!1}var kr=xa?{passive:!1}:!1,db=function(e){return e.tagName==="TEXTAREA"},hd=function(e,t){if(!(e instanceof Element))return!1;var n=window.getComputedStyle(e);return n[t]!=="hidden"&&!(n.overflowY===n.overflowX&&!db(e)&&n[t]==="visible")},fb=function(e){return hd(e,"overflowY")},hb=function(e){return hd(e,"overflowX")},pd=function(e,t){var n=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var o=md(e,r);if(o){var s=gd(e,r),i=s[1],a=s[2];if(i>a)return!0}r=r.parentNode}while(r&&r!==n.body);return!1},pb=function(e){var t=e.scrollTop,n=e.scrollHeight,r=e.clientHeight;return[t,n,r]},mb=function(e){var t=e.scrollLeft,n=e.scrollWidth,r=e.clientWidth;return[t,n,r]},md=function(e,t){return e==="v"?fb(t):hb(t)},gd=function(e,t){return e==="v"?pb(t):mb(t)},gb=function(e,t){return e==="h"&&t==="rtl"?-1:1},xb=function(e,t,n,r,o){var s=gb(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=gd(e,a),w=p[0],x=p[1],g=p[2],v=x-g-s*w;(w||v)&&md(e,a)&&(f+=v,h+=w);var b=a.parentNode;a=b&&b.nodeType===Node.DOCUMENT_FRAGMENT_NODE?b.host:b}while(!l&&a!==document.body||l&&(t.contains(a)||t===a));return(d&&Math.abs(f)<1||!d&&Math.abs(h)<1)&&(u=!0),u},hs=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},xd=function(e){return[e.deltaX,e.deltaY]},vd=function(e){return e&&"current"in e?e.current:e},vb=function(e,t){return e[0]===t[0]&&e[1]===t[1]},wb=function(e){return`
|
|
122
122
|
.block-interactivity-`.concat(e,` {pointer-events: none;}
|
|
123
123
|
.allow-interactivity-`).concat(e,` {pointer-events: all;}
|
|
124
|
-
`)},
|
|
124
|
+
`)},bb=0,Er=[];function yb(e){var t=m.useRef([]),n=m.useRef([0,0]),r=m.useRef(),o=m.useState(bb++)[0],s=m.useState(dd)[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=Hw([e.lockRef.current],(e.shards||[]).map(vd),!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=hs(x),b=n.current,S="deltaX"in x?x.deltaX:b[0]-v[0],N="deltaY"in x?x.deltaY:b[1]-v[1],C,k=x.target,I=Math.abs(S)>Math.abs(N)?"h":"v";if("touches"in x&&I==="h"&&k.type==="range")return!1;var A=pd(I,k);if(!A)return!0;if(A?C=I:(C=I==="v"?"h":"v",A=pd(I,k)),!A)return!1;if(!r.current&&"changedTouches"in x&&(S||N)&&(r.current=C),!C)return!0;var j=r.current||C;return xb(j,g,x,j==="h"?S:N)},[]),l=m.useCallback(function(x){var g=x;if(!(!Er.length||Er[Er.length-1]!==s)){var v="deltaY"in g?xd(g):hs(g),b=t.current.filter(function(C){return C.name===g.type&&(C.target===g.target||g.target===C.shadowParent)&&vb(C.delta,v)})[0];if(b&&b.should){g.cancelable&&g.preventDefault();return}if(!b){var S=(i.current.shards||[]).map(vd).filter(Boolean).filter(function(C){return C.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,b){var S={name:x,delta:g,target:v,should:b,shadowParent:Sb(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=hs(x),r.current=void 0},[]),f=m.useCallback(function(x){u(x.type,xd(x),x.target,a(x,e.lockRef.current))},[]),h=m.useCallback(function(x){u(x.type,hs(x),x.target,a(x,e.lockRef.current))},[]);m.useEffect(function(){return Er.push(s),e.setCallbacks({onScrollCapture:f,onWheelCapture:f,onTouchMoveCapture:h}),document.addEventListener("wheel",l,kr),document.addEventListener("touchmove",l,kr),document.addEventListener("touchstart",d,kr),function(){Er=Er.filter(function(x){return x!==s}),document.removeEventListener("wheel",l,kr),document.removeEventListener("touchmove",l,kr),document.removeEventListener("touchstart",d,kr)}},[]);var p=e.removeScrollBar,w=e.inert;return m.createElement(m.Fragment,null,w?m.createElement(s,{styles:wb(o)}):null,p?m.createElement(ub,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function Sb(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const Cb=Jw(ud,yb);var ps=m.forwardRef(function(e,t){return m.createElement(ds,wn({},e,{ref:t,sideCar:Cb}))});ps.classNames=ds.classNames;var Tb=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},Ir=new WeakMap,ms=new WeakMap,gs={},va=0,wd=function(e){return e&&(e.host||wd(e.parentNode))},kb=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=wd(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})},Eb=function(e,t,n,r){var o=kb(t,Array.isArray(e)?e:[e]);gs[n]||(gs[n]=new WeakMap);var s=gs[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),w=p!==null&&p!=="false",x=(Ir.get(h)||0)+1,g=(s.get(h)||0)+1;Ir.set(h,x),s.set(h,g),i.push(h),x===1&&w&&ms.set(h,!0),g===1&&h.setAttribute(n,"true"),w||h.setAttribute(r,"true")}catch(v){console.error("aria-hidden: cannot operate on ",h,v)}})};return d(t),a.clear(),va++,function(){i.forEach(function(f){var h=Ir.get(f)-1,p=s.get(f)-1;Ir.set(f,h),s.set(f,p),h||(ms.has(f)||f.removeAttribute(r),ms.delete(f)),p||f.removeAttribute(n)}),va--,va||(Ir=new WeakMap,Ir=new WeakMap,ms=new WeakMap,gs={})}},wa=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),o=Tb(e);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live], script"))),Eb(r,o,n,"aria-hidden")):function(){return null}},xs="Dialog",[bd,MT]=xn(xs),[Ib,an]=bd(xs),yd=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]=or({prop:r,defaultProp:o??!1,onChange:s,caller:xs});return c.jsx(Ib,{scope:t,triggerRef:a,contentRef:l,contentId:vn(),titleId:vn(),descriptionId:vn(),open:u,onOpenChange:d,onOpenToggle:m.useCallback(()=>d(f=>!f),[d]),modal:i,children:n})};yd.displayName=xs;var Sd="DialogTrigger",Cd=m.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=an(Sd,n),s=Ve(t,o.triggerRef);return c.jsx(_e.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":Sa(o.open),...r,ref:s,onClick:ue(e.onClick,o.onOpenToggle)})});Cd.displayName=Sd;var ba="DialogPortal",[Nb,Td]=bd(ba,{forceMount:void 0}),kd=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:o}=e,s=an(ba,t);return c.jsx(Nb,{scope:t,forceMount:n,children:m.Children.map(r,i=>c.jsx(Bt,{present:n||s.open,children:c.jsx(ls,{asChild:!0,container:o,children:i})}))})};kd.displayName=ba;var vs="DialogOverlay",Ed=m.forwardRef((e,t)=>{const n=Td(vs,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=an(vs,e.__scopeDialog);return s.modal?c.jsx(Bt,{present:r||s.open,children:c.jsx(_b,{...o,ref:t})}):null});Ed.displayName=vs;var Ab=Xn.createSlot("DialogOverlay.RemoveScroll"),_b=m.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=an(vs,n);return c.jsx(ps,{as:Ab,allowPinchZoom:!0,shards:[o.contentRef],children:c.jsx(_e.div,{"data-state":Sa(o.open),...r,ref:t,style:{pointerEvents:"auto",...r.style}})})}),ir="DialogContent",Id=m.forwardRef((e,t)=>{const n=Td(ir,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=an(ir,e.__scopeDialog);return c.jsx(Bt,{present:r||s.open,children:s.modal?c.jsx(jb,{...o,ref:t}):c.jsx(Rb,{...o,ref:t})})});Id.displayName=ir;var jb=m.forwardRef((e,t)=>{const n=an(ir,e.__scopeDialog),r=m.useRef(null),o=Ve(t,n.contentRef,r);return m.useEffect(()=>{const s=r.current;if(s)return wa(s)},[]),c.jsx(Nd,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:ue(e.onCloseAutoFocus,s=>{var i;s.preventDefault(),(i=n.triggerRef.current)==null||i.focus()}),onPointerDownOutside:ue(e.onPointerDownOutside,s=>{const i=s.detail.originalEvent,a=i.button===0&&i.ctrlKey===!0;(i.button===2||a)&&s.preventDefault()}),onFocusOutside:ue(e.onFocusOutside,s=>s.preventDefault())})}),Rb=m.forwardRef((e,t)=>{const n=an(ir,e.__scopeDialog),r=m.useRef(!1),o=m.useRef(!1);return c.jsx(Nd,{...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()}})}),Nd=m.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:s,...i}=e,a=an(ir,n),l=m.useRef(null),u=Ve(t,l);return ha(),c.jsxs(c.Fragment,{children:[c.jsx(as,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s,children:c.jsx(is,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":Sa(a.open),...i,ref:u,onDismiss:()=>a.onOpenChange(!1)})}),c.jsxs(c.Fragment,{children:[c.jsx(Pb,{titleId:a.titleId}),c.jsx(Mb,{contentRef:l,descriptionId:a.descriptionId})]})]})}),ya="DialogTitle",Ad=m.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=an(ya,n);return c.jsx(_e.h2,{id:o.titleId,...r,ref:t})});Ad.displayName=ya;var _d="DialogDescription",jd=m.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=an(_d,n);return c.jsx(_e.p,{id:o.descriptionId,...r,ref:t})});jd.displayName=_d;var Rd="DialogClose",Pd=m.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=an(Rd,n);return c.jsx(_e.button,{type:"button",...r,ref:t,onClick:ue(e.onClick,()=>o.onOpenChange(!1))})});Pd.displayName=Rd;function Sa(e){return e?"open":"closed"}var Od="DialogTitleWarning",[DT,Md]=Bv(Od,{contentName:ir,titleName:ya,docsSlug:"dialog"}),Pb=({titleId:e})=>{const t=Md(Od),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[re]?c.jsx(
|
|
132
|
-
… [truncated ${we.length-rr} chars]`:we,Qe=N==="expanded";return c.jsxs(Iu,{open:Qe,onOpenChange:ze=>C(ze?"expanded":"preview"),children:[c.jsx("div",{className:"flex items-center gap-2 text-xs",children:c.jsx(qi,{variant:"outline",children:(pe.name??"tool")+(pe.toolCallId?` • ${pe.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:Qe?Ae:Ae.slice(0,d)+(Ae.length>d?"...":"")})}),c.jsx(Eu,{asChild:!0,children:c.jsx(Ge,{variant:"ghost",size:"sm",className:"h-6 text-xs",children:Qe?c.jsxs(c.Fragment,{children:[" ",c.jsx(ie.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):c.jsxs(c.Fragment,{children:[c.jsx(ie.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more"]})})})]},pe.toolCallId??Ne)})})}if(!$){const re=c.jsx("div",{className:"space-y-2",children:t.content.map((pe,Ne)=>c.jsx(Ee,{part:pe,i:Ne},Ne))});return r?c.jsxs("div",{"aria-busy":"true",role:"status",children:[re,c.jsx(Bb,{className:D})]}):re}},[ee,ve.length,be.length,ye.length,r,t.model,$,fe.name,q,N,u,Ze,D]),ht=y.useMemo(()=>zb(t),[t]);return c.jsxs(c.Fragment,{children:[c.jsx("div",{className:Q(Je(),p.container),children:c.jsxs("div",{className:Q(nt(),p.content),children:[(i||a||$)&&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:[Ve(),a&&ht&&c.jsx("span",{className:Q("font-medium",W?"text-xs":"text-sm"),children:ht}),$&&fe.name&&c.jsxs(qi,{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(),C(re=>re==="collapsed"?"preview":"collapsed"))},onClick:()=>C(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(ie.ChevronUp,{className:"h-3 w-3"}):c.jsx(ie.ChevronDown,{className:"h-3 w-3"})})]}),$&&!fe.name&&c.jsx(Ge,{variant:"ghost",size:"sm",className:Q("h-6 px-1",D,"hover:bg-foreground/10"),onClick:()=>C(Z=>Z==="collapsed"?"preview":"collapsed"),children:c.jsxs("span",{className:"text-xs flex items-center gap-1",children:["Tool Output ",N!=="collapsed"?c.jsx(ie.ChevronUp,{className:"h-3 w-3"}):c.jsx(ie.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(Ge,{variant:"ghost",size:"sm",onClick:()=>J($?"visible":"all"),className:Q("h-6 w-6 p-0 hover:bg-foreground/10",D,W&&"h-5 w-5"),"aria-label":$?"Copy visible":"Copy message",title:$?"Copy visible portion":"Copy message",children:c.jsx(ie.Copy,{className:Q(b?"text-success":D,W?"h-3 w-3":"h-4 w-4")})}),$&&c.jsx(Ge,{variant:"ghost",size:"sm",onClick:()=>J("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"})]}),z==="user"&&w&&c.jsx(Ge,{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(ie.Edit,{className:Q(D,W?"h-3 w-3":"h-4 w-4")})}),z==="assistant"&&x&&c.jsx(Ge,{variant:"ghost",size:"sm",onClick:G,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(ie.RotateCcw,{className:Q(D,W?"h-3 w-3":"h-4 w-4")})})]})]})]}),c.jsx("div",{className:"relative",children:wt()}),$&&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||$)&&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(Ge,{variant:"ghost",size:"sm",onClick:()=>J(),className:Q("h-6 w-6 p-0 hover:bg-background/50 text-current",W&&"h-5 w-5"),children:c.jsx(ie.Copy,{className:Q(b?"text-success":"text-current",W?"h-3 w-3":"h-4 w-4")})}),z==="user"&&w&&c.jsx(Ge,{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(ie.Edit,{className:Q("text-current",W?"h-3 w-3":"h-4 w-4")})}),z==="assistant"&&x&&c.jsx(Ge,{variant:"ghost",size:"sm",onClick:G,className:Q("h-6 w-6 p-0 hover:bg-background/50 text-current",W&&"h-5 w-5"),children:c.jsx(ie.RotateCcw,{className:Q("text-current",W?"h-3 w-3":"h-4 w-4")})})]})]})}),Y&&c.jsx(Ob,{isOpen:V,onClose:()=>{M(!1),K(null)},fileId:Y.id,fileName:Y.name,mimeType:Y.mimeType})]})},(e,t)=>{var i,a,l,u,d,f,h,p;if(t.isStreamingMessage||e.isStreamingMessage||!(e.message.id===t.message.id&&Bd(e.message)===Bd(t.message)))return!1;const o=["isEditing","showActions","layoutSize","showTimestamp","showAgentName","truncateToolMessages","toolMessagePreviewLength","truncateUserMessages","userMessagePreviewLength"].every(w=>e[w]===t[w]),s=((i=e.customStyles)==null?void 0:i.container)===((a=t.customStyles)==null?void 0:a.container)&&((l=e.customStyles)==null?void 0:l.content)===((u=t.customStyles)==null?void 0:u.content)&&((d=e.customStyles)==null?void 0:d.actions)===((f=t.customStyles)==null?void 0:f.actions)&&((h=e.customStyles)==null?void 0:h.header)===((p=t.customStyles)==null?void 0:p.header);return o&&s});function Hb({data:e}){if(Array.isArray(e))return e.every(n=>n===null||["string","number","boolean"].includes(typeof n))?c.jsx("div",{className:ws,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:va(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:ws,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:ws,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:Ub(i)})]},s))})})}return c.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:va(e)})}function Ub(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(so(e))})}catch{return String(e)}}function Wb({interruptPart:e,onApprove:t,onReject:n}){const r=e.title??"Approve the result?";return c.jsxs(to,{className:"border-blue-200 dark:border-blue-800 bg-blue-50/50 dark:bg-blue-950/10",children:[c.jsxs(no,{className:"pb-3",children:[c.jsx(ro,{className:"text-blue-900 dark:text-blue-100 text-base",children:r}),c.jsx(Nu,{className:"text-blue-700 dark:text-blue-300",children:"Please approve or reject this action to continue."})]}),c.jsx(Au,{className:"pt-0",children:c.jsxs("div",{className:"flex gap-2 ml-auto",children:[c.jsx(Ge,{size:"sm",variant:"outline",onClick:()=>n(e),className:"border-red-300 text-red-700 hover:bg-red-50 dark:border-red-700 dark:text-red-300 dark:hover:bg-red-950/50",children:"Reject"}),c.jsx(Ge,{size:"sm",onClick:()=>t(e),className:"bg-blue-600 hover:bg-blue-700 text-white",children:"Approve"})]})})]})}function Vb({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 Kb({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:ws,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 Ud=(e,t)=>(e==null?void 0:e.id)??`message-${t}`,wa=y.forwardRef(({messages:e,isStreaming:t,streamingAssistantId:n,streamingDebounceMs:r,layoutSize:o,enableMessageEditing:s,editingMessageId:i,onStartReached:a,onEdit:l,onRegenerate:u,onCancelEdit:d,className:f,style:h,emptyMessage:p,followNewMessages:w=!0,isNavigatingCheckpoint:x=!1,onScrollAway:g,onAtBottom:v},b)=>{const S=y.useRef(null),N=y.useRef(null),C=y.useRef(!1),[k,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(!C.current){C.current=!0;try{await a()}finally{C.current=!1}}}},[a]),P=y.useMemo(()=>!w||x?!1:k?"auto":!1,[k,w,x]);return e.length===0?c.jsx("div",{className:f,style:h,children:c.jsx("div",{className:"flex items-center justify-center py-8 text-muted-foreground text-center max-w-md mx-auto",children:p||"No messages yet. Start a conversation!"})}):c.jsx("div",{className:f,style:h,children:c.jsx(vv,{ref:L=>{S.current=L},scrollerRef:L=>{N.current=L instanceof HTMLDivElement?L:null},data:e,followOutput:P,overscan:200,increaseViewportBy:{top:100,bottom:200},defaultItemHeight:80,atBottomThreshold:50,alignToBottom:!1,startReached:()=>{j&&j()},atBottomStateChange:A,style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:(L,F)=>Ud(F,L),itemContent:(L,F)=>{const V=Ud(F,L);return c.jsx("div",{className:"mb-4 last:mb-0","data-message-id":V,style:{minHeight:"60px",containIntrinsicSize:"auto 120px"},children:c.jsx(Hd,{message:F,messageIndex:L,isStreamingMessage:t&&n===F.id,streamingDebounceMs:r,isEditing:i===F.id,showActions:s,showTimestamp:!1,showAgentName:!0,layoutSize:o,truncateToolMessages:!1,toolMessagePreviewLength:200,onEdit:l,onRegenerate:()=>u(L),onCancelEdit:d})})}})})});wa.displayName="MessageList";const bs=1e4;function qb(e){if(typeof e!="string")return String(e);const t=[/<script[^>]*>.*?<\/script>/gi,/<iframe[^>]*>.*?<\/iframe>/gi,/javascript:/gi,/vbscript:/gi,/on\w+\s*=/gi,/<object[^>]*>.*?<\/object>/gi,/<embed[^>]*>.*?<\/embed>/gi,/<form[^>]*>.*?<\/form>/gi];let n=e;for(const o of t)n=n.replace(o,"");return/<[^>]+>/.test(n)&&!/<(?!\/?(?:code|strong|em|b|i|br|p|ul|ol|li|h[1-6])\b)[^>]+>/i.test(n)?n.replace(/<code>(.*?)<\/code>/gi,"`$1`").replace(/<strong>(.*?)<\/strong>/gi,"**$1**").replace(/<b>(.*?)<\/b>/gi,"**$1**").replace(/<em>(.*?)<\/em>/gi,"*$1*").replace(/<i>(.*?)<\/i>/gi,"*$1*").replace(/<br\s*\/?>/gi,`
|
|
128
|
+
For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return m.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},Ob="DialogDescriptionWarning",Mb=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${Md(Ob).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},Dd=yd,Db=Cd,Ld=kd,ws=Ed,bs=Id,ar=Ad,ys=jd,Fd=Pd;const Lb=Dd,Fb=Ld,$d=m.forwardRef(({className:e,...t},n)=>c.jsx(ws,{ref:n,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}));$d.displayName=ws.displayName;const Bd=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===ar||(u==null?void 0:u.displayName)===ar.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(Fb,{children:[c.jsx($d,{}),c.jsxs(bs,{ref:r,className:Z("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(ar,{className:"sr-only",children:"Dialog"}),t,c.jsxs(Fd,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground",children:[c.jsx(oe.X,{className:"h-4 w-4"}),c.jsx("span",{className:"sr-only",children:"Close"})]})]})]})});Bd.displayName=bs.displayName;const zd=({className:e,...t})=>c.jsx("div",{className:Z("flex flex-col space-y-1.5 text-center sm:text-left",e),...t});zd.displayName="DialogHeader";const Hd=m.forwardRef(({className:e,...t},n)=>c.jsx(ar,{ref:n,className:Z("text-lg font-semibold leading-none tracking-tight",e),...t}));Hd.displayName=ar.displayName;const $b=m.forwardRef(({className:e,...t},n)=>c.jsx(ys,{ref:n,className:Z("text-sm text-muted-foreground",e),...t}));$b.displayName=ys.displayName;function Bb({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}=la(),h=y.useCallback(async()=>{if(n){i(!0),d(null),l(null);try{const v=await Yu(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 ww(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"})}},w=async()=>{if(n)try{const v=await Yu(n),b=new Blob([v],{type:o}),S=URL.createObjectURL(b);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(oe.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(Ge,{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(oe.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(oe.Image,{className:"h-5 w-5"}):c.jsx(oe.FileText,{className:"h-5 w-5"});return c.jsx(Lb,{open:e,onOpenChange:t,children:c.jsxs(Bd,{className:"max-w-4xl max-h-[90vh] overflow-hidden",children:[c.jsx(zd,{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(Hd,{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(Ge,{variant:"outline",size:"sm",onClick:w,className:"flex items-center gap-2",children:[c.jsx(oe.ExternalLink,{className:"h-4 w-4"}),"External"]}),c.jsxs(Ge,{variant:"outline",size:"sm",onClick:p,className:"flex items-center gap-2",children:[c.jsx(oe.Download,{className:"h-4 w-4"}),"Download"]})]})]})}),c.jsx("div",{className:"flex-1 overflow-hidden",children:x()})]})})}function Ud(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 Wd(e){return!!(e&&typeof e=="object"&&(e.type==="file"||e.mimeType||e.filename||e.sourceType==="base64"))}function ao(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(ao).filter(r=>r!==void 0);if(!n.length){console.debug("[message-utils] sanitizeForDisplay - array emptied -> returning undefined",{originalLength:e.length});return}return n}if(Wd(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=ao(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 Ca(e){if(typeof e=="string")return e;if(Wd(e))return"";try{const t=ao(e);return t===void 0?"":typeof t=="string"?t:JSON.stringify(t,null,2)}catch{return""}}function Vd(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 Vd(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),w=/description\s*=\s*(['"])([\s\S]*?)\1/.exec(h),x=p?p[2].trim():"",g=w?w[2].trim():"";n[i].push({title:x,description:g})}}return Object.values(n).some(i=>i.length>0)?n:null}const Ss="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",lr=1e5;function zb(e){return e.filter(t=>t.type==="text").map(t=>t.text).join("")}function Hb(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 Ub(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 Wb(e){const t=(r,o=lr)=>{try{const s=ao(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 Vb(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 qb(e){return e.name&&e.name.trim()?e.name:e.model&&e.model.includes("/")?e.model.split("/").pop()||null:e.model||null}function qd(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 Kb({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:Z("inline-block text-xs opacity-70 ml-1",e),children:["Is thinking",".".repeat(t)]})}const Kd=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:w,onRegenerate:x,onCancelEdit:g,onCopy:v}){const[b,S]=y.useState(!1),[N,C]=y.useState("collapsed"),[k,I]=y.useState(!1),{currentThreadId:A}=Mo(),{respondToInterrupt:j}=Do(),{toast:P}=la(),[L,F]=y.useState({}),[V,M]=y.useState(!1),[G,q]=y.useState(null),U=l==="phone"||l==="half-screen",B=t.role,$=B==="tool",ce=!(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]),Q=y.useMemo(()=>zb(t.content),[t.content]),de=y.useMemo(()=>Hb(t.content),[t.content]),we=y.useMemo(()=>t.content.filter(J=>J.type==="image_url"),[t.content]),ye=y.useMemo(()=>t.content.filter(J=>J.type==="file"),[t.content]),Se=y.useMemo(()=>t.content.filter(J=>J.type==="interrupt"),[t.content]),K=y.useMemo(()=>Wb(t.content),[t.content]);y.useMemo(()=>Vb(t.content),[t.content]);const O=y.useMemo(()=>K.length<=lr?K:`${K.slice(0,lr)}
|
|
130
|
+
… [truncated ${K.length-lr} chars]`,[K]),X=y.useCallback(async(J="all")=>{const he=J==="visible"&&$?O:$?K:Q;async function Ce(me){try{await navigator.clipboard.writeText(me)}catch{try{const Oe=document.createElement("textarea");Oe.value=me,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 Ce(he),S(!0),setTimeout(()=>S(!1),2e3),v==null||v(he)}catch(me){console.error("Failed to copy:",me)}},[$,K,Q,O,v]),ee=y.useCallback(()=>{if(!w)return;const J=$?K:Q;w(t.id,J)},[w,t.id,$,K,Q]),fe=y.useCallback(()=>{x==null||x(n)},[x,n]),ne=y.useCallback(async(J,re,he)=>{if(!ce){J.preventDefault();return}if(L[he]){J.preventDefault();return}try{const Ce=String(re.url??""),me=Ce.match(/\/chat\/files\/([^/]+)(?:\/(view|download))?/);if(me){J.preventDefault();const Oe=me[1],it=re.name||`file_${Oe}`,Me=re.mimeType||"application/octet-stream";q({id:Oe,name:it,mimeType:Me}),M(!0);return}if(Ce.startsWith("data:")){J.preventDefault(),F(Me=>({...Me,[he]:!0}));const Oe=`${re.name}_${re.size}_${Date.now()}`,it=P({title:"Fetching file...",description:"",open:!0});try{const Me=await bw(A??void 0);if(!Me||!Array.isArray(Me))throw new Error("Invalid file list response");const et=Me.find(vt=>!vt||typeof vt!="object"||!((vt.filename??"")===(re.name??""))?!1:typeof re.size=="number"&&typeof vt.size=="number"?vt.size===re.size:!0);if(!(et!=null&&et.id))throw new Error(`File "${re.name}" is not yet available on the server`);if(!et.id||!et.filename)throw new Error("Invalid file data received from server");q({id:et.id,name:re.name||et.filename||`file_${et.id}`,mimeType:re.mimeType||et.mime_type||"application/octet-stream"}),M(!0),it.update({id:it.id,title:"Success",description:`Opened ${re.name}`,open:!0})}catch(Me){console.error("Failed to fetch server file:",Me);const et=Me instanceof Error?Me.message:"Unknown error occurred";it.update({id:it.id,title:"Failed",description:et}),P({title:"Failed to fetch file",description:et,open:!0})}finally{F(Me=>({...Me,[he]:!1}))}}}catch(Ce){console.error("File click error:",Ce),F(me=>({...me,[he]:!1}))}},[ce,L,P,A]),pe=y.useCallback(()=>{const re=Z(U?"h-3 w-3":"h-4 w-4","opacity-60 flex-shrink-0",D);switch(B){case"user":return c.jsx(oe.User,{className:re});case"assistant":return c.jsx(oe.Bot,{className:re});case"tool":return c.jsx(oe.Wrench,{className:re});default:return c.jsx(oe.Bot,{className:re})}},[U,D,B]),Ze=y.useCallback(()=>{const J="group relative mb-4 flex w-full";switch(B){case"user":return Z(J,"justify-end");case"assistant":case"tool":case"system":return Z(J,"justify-start");default:return J}},[B]),Qe=y.useCallback(()=>{const J=Z("rounded-lg px-4 py-3 relative min-w-0 max-w-full break-words",U&&"px-3 py-2 text-sm");switch(B){case"user":return Z(J,"w-full md:max-w-[95%]","bg-[hsl(var(--chat-bubble-user))] text-[hsl(var(--chat-bubble-user-text))]","border border-transparent");case"assistant":return Z(J,"w-full md:max-w-[95%]","bg-[hsl(var(--chat-bubble-ai))] text-[hsl(var(--chat-bubble-ai-text))]","border border-border/60 dark:border-border/40");case"tool":return Z(J,"w-full md:max-w-[95%] bg-secondary/50 text-secondary-foreground border border-dashed");case"system":return Z(J,"w-full md:max-w-[85%] bg-accent/40 text-muted-foreground border");default:return Z(J,"w-full md:max-w-[95%]","bg-[hsl(var(--chat-bubble-ai))] text-[hsl(var(--chat-bubble-ai-text))]","border border-border/60 dark:border-border/40")}},[U,B]),Pe=y.useCallback(async J=>{try{const re=(J==null?void 0:J.id)||(J==null?void 0:J.interrupt_id);if(!re){console.warn("Interrupt part missing id",J);return}await j(re,!0)}catch(re){console.error("Failed to approve interrupt:",re)}},[j]),He=y.useCallback(async J=>{try{const re=(J==null?void 0:J.id)||(J==null?void 0:J.interrupt_id);if(!re){console.warn("Interrupt part missing id",J);return}await j(re,!1)}catch(re){console.error("Failed to reject interrupt:",re)}},[j]),ct=y.useCallback(({part:J,i:re})=>{if(J.type==="text"){const he=J.text??"",Ce=he.trim(),me=Ud(Ce);return me&&B!=="tool"?c.jsx(Gb,{data:me},re):B==="user"&&f&&Ce.length>h?c.jsxs(ju,{open:k,onOpenChange:I,children:[c.jsx("div",{className:Z("text-sm text-[hsl(var(--chat-bubble-user-text))]",U&&"text-xs"),children:k?c.jsx(sa,{content:Ce,allowHtml:!1}):c.jsxs("pre",{className:Z("font-sans whitespace-pre-wrap break-words bg-transparent p-0 m-0 text-[hsl(var(--chat-bubble-user-text))]",U&&"text-xs"),children:[Ce.substring(0,h),"..."]})}),c.jsx(Ru,{asChild:!0,children:c.jsx(Ge,{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(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 (",Ce.length-h," chars)"]})})})]},re):c.jsx(sa,{content:he,allowHtml:!1},re)}if(J.type==="image_url"){const he=J;return c.jsx("div",{className:"my-2",children:c.jsx("img",{src:he.url,alt:he.alt??"",loading:"lazy",className:"border rounded max-h-[420px] w-auto object-contain"})},re)}if(J.type==="file"){const he=J,Ce=he.name||"file";return c.jsxs("a",{href:he.url,onClick:me=>ne(me,he,re),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[re]?c.jsx(oe.Loader,{className:"h-4 w-4 animate-spin"}):null,c.jsxs("span",{className:"truncate max-w-[180px]",children:[Ce,L[re]?" (processing)":""]})]},re)}return J.type==="interrupt"?c.jsx(Xb,{interruptPart:J,onApprove:Pe,onReject:He},re):null},[ne,L,Pe,He,B,f,h,k,U]),tt=y.useCallback(()=>c.jsxs("div",{className:"flex items-center gap-2 p-2 bg-muted/30 rounded",children:[c.jsx(oe.Paperclip,{className:"h-4 w-4 text-muted-foreground"}),c.jsx("span",{className:"text-sm text-muted-foreground",children:"File upload"})]}),[]),Be=y.useCallback(()=>{const J=Q.trim().length>0||we.length>0||ye.length>0||Se.length>0;if(!$&&!J&&!r)return tt();if(t.model==="reflection"){const re=Q.trim(),he=Ud(re);if(he&&typeof he=="object")return c.jsx(Jb,{data:he})}if($&&de.name==="get_issues"){const re=t.content.find(me=>me.type==="tool_end"),he=(re==null?void 0:re.output)??K,Ce=Vd(he);if(Ce)return c.jsx(Zb,{issues:Ce})}if($){const re=Ub(t.content);if(re.length>0)return c.jsx("div",{className:"space-y-2",children:re.map((he,Ce)=>{const me=typeof he.output=="string"?he.output:Ca(he.output),Oe=me.length>lr?`${me.slice(0,lr)}
|
|
132
|
+
… [truncated ${me.length-lr} chars]`:me,it=N==="expanded";return c.jsxs(ju,{open:it,onOpenChange:Me=>C(Me?"expanded":"preview"),children:[c.jsx("div",{className:"flex items-center gap-2 text-xs",children:c.jsx(Zi,{variant:"outline",children:(he.name??"tool")+(he.toolCallId?` • ${he.toolCallId.slice(0,8)}`:"")})}),c.jsx("div",{className:"font-mono text-sm mt-1",children:c.jsx("pre",{className:"whitespace-pre-wrap break-words",children:it?Oe:Oe.slice(0,d)+(Oe.length>d?"...":"")})}),c.jsx(Ru,{asChild:!0,children:c.jsx(Ge,{variant:"ghost",size:"sm",className:"h-6 text-xs",children:it?c.jsxs(c.Fragment,{children:[" ",c.jsx(oe.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):c.jsxs(c.Fragment,{children:[c.jsx(oe.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more"]})})})]},he.toolCallId??Ce)})})}if(!$){const re=c.jsx("div",{className:"space-y-2",children:t.content.map((he,Ce)=>c.jsx(ct,{part:he,i:Ce},Ce))});return r?c.jsxs("div",{"aria-busy":"true",role:"status",children:[re,c.jsx(Kb,{className:D})]}):re}},[Q,we.length,ye.length,Se.length,r,t.model,$,de.name,K,N,u,tt,D]),gt=y.useMemo(()=>qb(t),[t]);return c.jsxs(c.Fragment,{children:[c.jsx("div",{className:Z(Ze(),p.container),children:c.jsxs("div",{className:Z(Qe(),p.content),children:[(i||a||$)&&c.jsxs("div",{className:Z("flex items-center justify-between mb-2 pb-2 border-b border-current/10",U&&"mb-1 pb-1",D,p.header),children:[c.jsxs("div",{className:"flex items-center gap-2",children:[pe(),a&>&&c.jsx("span",{className:Z("font-medium",U?"text-xs":"text-sm"),children:gt}),$&&de.name&&c.jsxs(Zi,{variant:"outline",className:Z("text-xs flex items-center gap-1 cursor-pointer",D,"border border-current/40",U&&"text-xs h-4"),role:"button",tabIndex:0,"aria-expanded":N!=="collapsed",onKeyDown:J=>{(J.key==="Enter"||J.key===" ")&&(J.preventDefault(),C(re=>re==="collapsed"?"preview":"collapsed"))},onClick:()=>C(J=>J==="collapsed"?"preview":"collapsed"),children:[c.jsx("span",{children:de.name}),c.jsx("span",{className:"inline-flex items-center",children:N!=="collapsed"?c.jsx(oe.ChevronUp,{className:"h-3 w-3"}):c.jsx(oe.ChevronDown,{className:"h-3 w-3"})})]}),$&&!de.name&&c.jsx(Ge,{variant:"ghost",size:"sm",className:Z("h-6 px-1",D,"hover:bg-foreground/10"),onClick:()=>C(J=>J==="collapsed"?"preview":"collapsed"),children:c.jsxs("span",{className:"text-xs flex items-center gap-1",children:["Tool Output ",N!=="collapsed"?c.jsx(oe.ChevronUp,{className:"h-3 w-3"}):c.jsx(oe.ChevronDown,{className:"h-3 w-3"})]})})]}),c.jsxs("div",{className:"flex items-center gap-2",children:[i&&t.createdAt&&c.jsx("time",{className:Z("text-xs opacity-60",D,U&&"text-xs"),dateTime:new Date(t.createdAt).toISOString(),title:new Date(t.createdAt).toLocaleString(),children:new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit"}).format(new Date(t.createdAt))}),s&&!o&&c.jsxs("div",{className:Z("opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",p.actions),children:[c.jsxs("div",{className:"relative",children:[c.jsx(Ge,{variant:"ghost",size:"sm",onClick:()=>X($?"visible":"all"),className:Z("h-6 w-6 p-0 hover:bg-foreground/10",D,U&&"h-5 w-5"),"aria-label":$?"Copy visible":"Copy message",title:$?"Copy visible portion":"Copy message",children:c.jsx(oe.Copy,{className:Z(b?"text-success":D,U?"h-3 w-3":"h-4 w-4")})}),$&&c.jsx(Ge,{variant:"ghost",size:"sm",onClick:()=>X("all"),className:Z("h-6 px-1 text-xs hover:bg-foreground/10",D),"aria-label":"Copy all (may be large)",title:"Copy all (may be large)",children:"all"})]}),B==="user"&&w&&c.jsx(Ge,{variant:"ghost",size:"sm",onClick:ee,className:Z("h-6 w-6 p-0 hover:bg-foreground/10",D,U&&"h-5 w-5"),"aria-label":"Edit message",children:c.jsx(oe.Edit,{className:Z(D,U?"h-3 w-3":"h-4 w-4")})}),B==="assistant"&&x&&c.jsx(Ge,{variant:"ghost",size:"sm",onClick:fe,className:Z("h-6 w-6 p-0 hover:bg-foreground/10",D,U&&"h-5 w-5"),"aria-label":"Regenerate response",children:c.jsx(oe.RotateCcw,{className:Z(D,U?"h-3 w-3":"h-4 w-4")})})]})]})]}),c.jsx("div",{className:"relative",children:Be()}),$&&N==="expanded"&&(de.toolCallId||de.name)&&c.jsxs("div",{className:Z("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",U&&"text-xs"),children:[de.name&&c.jsxs("div",{children:["Function: ",de.name]}),de.toolCallId&&c.jsxs("div",{children:["Call ID: ",de.toolCallId]})]}),!(i||a||$)&&s&&!o&&c.jsxs("div",{className:Z("absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",p.actions),children:[c.jsx(Ge,{variant:"ghost",size:"sm",onClick:()=>X(),className:Z("h-6 w-6 p-0 hover:bg-background/50 text-current",U&&"h-5 w-5"),children:c.jsx(oe.Copy,{className:Z(b?"text-success":"text-current",U?"h-3 w-3":"h-4 w-4")})}),B==="user"&&w&&c.jsx(Ge,{variant:"ghost",size:"sm",onClick:ee,className:Z("h-6 w-6 p-0 hover:bg-background/50 text-current",U&&"h-5 w-5"),children:c.jsx(oe.Edit,{className:Z("text-current",U?"h-3 w-3":"h-4 w-4")})}),B==="assistant"&&x&&c.jsx(Ge,{variant:"ghost",size:"sm",onClick:fe,className:Z("h-6 w-6 p-0 hover:bg-background/50 text-current",U&&"h-5 w-5"),children:c.jsx(oe.RotateCcw,{className:Z("text-current",U?"h-3 w-3":"h-4 w-4")})})]})]})}),G&&c.jsx(Bb,{isOpen:V,onClose:()=>{M(!1),q(null)},fileId:G.id,fileName:G.name,mimeType:G.mimeType})]})},(e,t)=>{var i,a,l,u,d,f,h,p;if(t.isStreamingMessage||e.isStreamingMessage||!(e.message.id===t.message.id&&qd(e.message)===qd(t.message)))return!1;const o=["isEditing","showActions","layoutSize","showTimestamp","showAgentName","truncateToolMessages","toolMessagePreviewLength","truncateUserMessages","userMessagePreviewLength"].every(w=>e[w]===t[w]),s=((i=e.customStyles)==null?void 0:i.container)===((a=t.customStyles)==null?void 0:a.container)&&((l=e.customStyles)==null?void 0:l.content)===((u=t.customStyles)==null?void 0:u.content)&&((d=e.customStyles)==null?void 0:d.actions)===((f=t.customStyles)==null?void 0:f.actions)&&((h=e.customStyles)==null?void 0:h.header)===((p=t.customStyles)==null?void 0:p.header);return o&&s});function Gb({data:e}){if(Array.isArray(e))return e.every(n=>n===null||["string","number","boolean"].includes(typeof n))?c.jsx("div",{className:Ss,children:c.jsx("ul",{className:"list-disc pl-5",children:e.map((n,r)=>c.jsx("li",{children:String(n)},r))})}):c.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:Ca(e)});if(e&&typeof e=="object"){const t=Array.isArray(e.distilled_facts)?e.distilled_facts:null,n=Array.isArray(e.follow_up_queries)?e.follow_up_queries:null,r=typeof e.is_sufficient=="boolean"?e.is_sufficient:void 0;if(t||n||typeof r=="boolean")return c.jsxs("div",{className:Ss,children:[typeof r=="boolean"&&c.jsxs("p",{children:[c.jsx("strong",{children:"Is sufficient:"})," ",r?"Yes":"No"]}),n&&n.length>0&&c.jsxs("div",{children:[c.jsx("p",{children:c.jsx("strong",{children:"Follow-up queries:"})}),c.jsx("ul",{className:"list-disc pl-5",children:n.map((s,i)=>c.jsx("li",{children:String(s)},i))})]}),t&&t.length>0&&c.jsxs("div",{children:[c.jsx("p",{children:c.jsx("strong",{children:"Facts:"})}),c.jsx("ul",{className:"list-disc pl-5",children:t.map((s,i)=>c.jsx("li",{children:String(s)},i))})]})]});const o=Object.entries(e);return c.jsx("div",{className:Ss,children:c.jsx("dl",{className:"mt-0",children:o.map(([s,i])=>c.jsxs("div",{className:"mb-1",children:[c.jsxs("dt",{className:"inline font-medium mr-1",children:[s,":"]}),c.jsx("dd",{className:"inline",children:Yb(i)})]},s))})})}return c.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:Ca(e)})}function Yb(e){if(e==null)return String(e);const t=typeof e;if(t==="string"||t==="number"||t==="boolean")return String(e);if(Array.isArray(e)&&e.every(r=>r===null||["string","number","boolean"].includes(typeof r)))return e.join(", ");try{return c.jsx("code",{className:"text-xs",children:JSON.stringify(ao(e))})}catch{return String(e)}}function Xb({interruptPart:e,onApprove:t,onReject:n}){const r=e.title??"Approve the result?";return c.jsxs(ro,{className:"border-blue-200 dark:border-blue-800 bg-blue-50/50 dark:bg-blue-950/10",children:[c.jsxs(oo,{className:"pb-3",children:[c.jsx(so,{className:"text-blue-900 dark:text-blue-100 text-base",children:r}),c.jsx(Pu,{className:"text-blue-700 dark:text-blue-300",children:"Please approve or reject this action to continue."})]}),c.jsx(Ou,{className:"pt-0",children:c.jsxs("div",{className:"flex gap-2 ml-auto",children:[c.jsx(Ge,{size:"sm",variant:"outline",onClick:()=>n(e),className:"border-red-300 text-red-700 hover:bg-red-50 dark:border-red-700 dark:text-red-300 dark:hover:bg-red-950/50",children:"Reject"}),c.jsx(Ge,{size:"sm",onClick:()=>t(e),className:"bg-blue-600 hover:bg-blue-700 text-white",children:"Approve"})]})})]})}function Jb({data:e}){return c.jsx("dl",{className:"grid grid-cols-1 gap-y-2",children:Object.entries(e).map(([t,n])=>c.jsxs("div",{className:"flex",children:[c.jsxs("dt",{className:"font-semibold mr-2",children:[t,":"]}),c.jsx("dd",{className:"flex-1 break-words",children:Array.isArray(n)?n.map((r,o)=>c.jsxs("div",{className:"ml-4 break-words",children:["- ",String(r)]},o)):String(n)})]},t))})}function Zb({issues:e}){const t=[{key:"desirability",title:"Desirability"},{key:"feasibility",title:"Feasibility"},{key:"viability",title:"Viability"},{key:"other",title:"Other"}];return c.jsx("div",{className:Ss,children:t.map(n=>{const r=e[n.key];return!r||!r.length?null:c.jsxs("div",{className:"mb-4",children:[c.jsxs("h4",{className:"font-semibold mb-2",children:[n.title," (",r.length,")"]}),c.jsx("ol",{className:"list-decimal pl-5 space-y-2",children:r.map((o,s)=>c.jsxs("li",{children:[c.jsx("div",{className:"font-medium",children:o.title}),c.jsx("div",{className:"text-sm text-muted-foreground",children:o.description})]},s))})]},n.key)})})}const Gd=(e,t)=>(e==null?void 0:e.id)??`message-${t}`,Ta=y.forwardRef(({messages:e,isStreaming:t,streamingAssistantId:n,streamingDebounceMs:r,layoutSize:o,enableMessageEditing:s,editingMessageId:i,onStartReached:a,onEdit:l,onRegenerate:u,onCancelEdit:d,className:f,style:h,emptyMessage:p,followNewMessages:w=!0,isNavigatingCheckpoint:x=!1,onScrollAway:g,onAtBottom:v},b)=>{const S=y.useRef(null),N=y.useRef(null),C=y.useRef(!1),[k,I]=y.useState(!0),A=y.useCallback(L=>{I(L),g&&g(!L),v&&v(L)},[g,v]),j=y.useMemo(()=>{if(a)return async()=>{if(!C.current){C.current=!0;try{await a()}finally{C.current=!1}}}},[a]),P=y.useMemo(()=>!w||x?!1:k?"auto":!1,[k,w,x]);return e.length===0?c.jsx("div",{className:f,style:h,children:c.jsx("div",{className:"flex items-center justify-center py-8 text-muted-foreground text-center max-w-md mx-auto",children:p||"No messages yet. Start a conversation!"})}):c.jsx("div",{className:f,style:h,children:c.jsx(Tv,{ref:L=>{S.current=L},scrollerRef:L=>{N.current=L instanceof HTMLDivElement?L:null},data:e,followOutput:P,overscan:200,increaseViewportBy:{top:100,bottom:200},defaultItemHeight:80,atBottomThreshold:50,alignToBottom:!1,startReached:()=>{j&&j()},atBottomStateChange:A,style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:(L,F)=>Gd(F,L),itemContent:(L,F)=>{const V=Gd(F,L);return c.jsx("div",{className:"mb-4 last:mb-0","data-message-id":V,style:{minHeight:"60px",containIntrinsicSize:"auto 120px"},children:c.jsx(Kd,{message:F,messageIndex:L,isStreamingMessage:t&&n===F.id,streamingDebounceMs:r,isEditing:i===F.id,showActions:s,showTimestamp:!1,showAgentName:!0,layoutSize:o,truncateToolMessages:!1,toolMessagePreviewLength:200,onEdit:l,onRegenerate:()=>u(L),onCancelEdit:d})})}})})});Ta.displayName="MessageList";const Cs=1e4;function Qb(e){if(typeof e!="string")return String(e);const t=[/<script[^>]*>.*?<\/script>/gi,/<iframe[^>]*>.*?<\/iframe>/gi,/javascript:/gi,/vbscript:/gi,/on\w+\s*=/gi,/<object[^>]*>.*?<\/object>/gi,/<embed[^>]*>.*?<\/embed>/gi,/<form[^>]*>.*?<\/form>/gi];let n=e;for(const o of t)n=n.replace(o,"");return/<[^>]+>/.test(n)&&!/<(?!\/?(?:code|strong|em|b|i|br|p|ul|ol|li|h[1-6])\b)[^>]+>/i.test(n)?n.replace(/<code>(.*?)<\/code>/gi,"`$1`").replace(/<strong>(.*?)<\/strong>/gi,"**$1**").replace(/<b>(.*?)<\/b>/gi,"**$1**").replace(/<em>(.*?)<\/em>/gi,"*$1*").replace(/<i>(.*?)<\/i>/gi,"*$1*").replace(/<br\s*\/?>/gi,`
|
|
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 Gb(e,t=bs){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 Yb(e){let t;return typeof e=="string"?t=e:typeof e=="object"&&e!==null?t=JSON.stringify(e):t=String(e),Gb(t),qb(t)}function ba(e){const t=e+"CollectionProvider",[n,r]=pn(t),[o,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),i=x=>{const{scope:g,children:v}=x,b=y.useRef(null),S=y.useRef(new Map).current;return c.jsx(o,{scope:g,itemMap:S,collectionRef:b,children:v})};i.displayName=t;const a=e+"CollectionSlot",l=Vn.createSlot(a),u=y.forwardRef((x,g)=>{const{scope:v,children:b}=x,S=s(a,v),N=We(g,S.collectionRef);return c.jsx(l,{ref:N,children:b})});u.displayName=a;const d=e+"CollectionItemSlot",f="data-radix-collection-item",h=Vn.createSlot(d),p=y.forwardRef((x,g)=>{const{scope:v,children:b,...S}=x,N=y.useRef(null),C=We(g,N),k=s(d,v);return y.useEffect(()=>(k.itemMap.set(N,{ref:N,...S}),()=>void k.itemMap.delete(N))),c.jsx(h,{[f]:"",ref:C,children:b})});p.displayName=d;function w(x){const g=s(e+"CollectionConsumer",x);return y.useCallback(()=>{const b=g.collectionRef.current;if(!b)return[];const S=Array.from(b.querySelectorAll(`[${f}]`));return Array.from(g.itemMap.values()).sort((k,E)=>S.indexOf(k.ref.current)-S.indexOf(E.ref.current))},[g.collectionRef,g.itemMap])}return[{Provider:i,Slot:u,ItemSlot:p},w,r]}var Xb=m.createContext(void 0);function ys(e){const t=m.useContext(Xb);return e||t||"ltr"}const Jb=["top","right","bottom","left"],zn=Math.min,Bt=Math.max,Ss=Math.round,Cs=Math.floor,xn=e=>({x:e,y:e}),Zb={left:"right",right:"left",bottom:"top",top:"bottom"},Qb={start:"end",end:"start"};function ya(e,t,n){return Bt(e,zn(t,n))}function In(e,t){return typeof e=="function"?e(t):e}function En(e){return e.split("-")[0]}function Ir(e){return e.split("-")[1]}function Sa(e){return e==="x"?"y":"x"}function Ca(e){return e==="y"?"height":"width"}const ey=new Set(["top","bottom"]);function vn(e){return ey.has(En(e))?"y":"x"}function Ta(e){return Sa(vn(e))}function ty(e,t,n){n===void 0&&(n=!1);const r=Ir(e),o=Ta(e),s=Ca(o);let i=o==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(i=Ts(i)),[i,Ts(i)]}function ny(e){const t=Ts(e);return[ka(e),t,ka(t)]}function ka(e){return e.replace(/start|end/g,t=>Qb[t])}const Wd=["left","right"],Vd=["right","left"],ry=["top","bottom"],oy=["bottom","top"];function sy(e,t,n){switch(e){case"top":case"bottom":return n?t?Vd:Wd:t?Wd:Vd;case"left":case"right":return t?ry:oy;default:return[]}}function iy(e,t,n,r){const o=Ir(e);let s=sy(En(e),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(ka)))),s}function Ts(e){return e.replace(/left|right|bottom|top/g,t=>Zb[t])}function ay(e){return{top:0,right:0,bottom:0,left:0,...e}}function Kd(e){return typeof e!="number"?ay(e):{top:e,right:e,bottom:e,left:e}}function ks(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 qd(e,t,n){let{reference:r,floating:o}=e;const s=vn(t),i=Ta(t),a=Ca(i),l=En(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(Ir(t)){case"start":p[i]-=h*(n&&u?-1:1);break;case"end":p[i]+=h*(n&&u?-1:1);break}return p}const ly=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}=qd(u,r,l),h=r,p={},w=0;for(let x=0;x<a.length;x++){const{name:g,fn:v}=a[x],{x:b,y:S,data:N,reset:C}=await v({x:d,y:f,initialPlacement:r,placement:h,strategy:o,middlewareData:p,rects:u,platform:i,elements:{reference:e,floating:t}});d=b??d,f=S??f,p={...p,[g]:{...p[g],...N}},C&&w<=50&&(w++,typeof C=="object"&&(C.placement&&(h=C.placement),C.rects&&(u=C.rects===!0?await i.getElementRects({reference:e,floating:t,strategy:o}):C.rects),{x:d,y:f}=qd(u,h,l)),x=-1)}return{x:d,y:f,placement:h,strategy:o,middlewareData:p}};async function io(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}=In(t,e),w=Kd(p),g=a[h?f==="floating"?"reference":"floating":f],v=ks(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(g)))==null||n?g:g.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(a.floating)),boundary:u,rootBoundary:d,strategy:l})),b=f==="floating"?{x:r,y:o,width:i.floating.width,height:i.floating.height}:i.reference,S=await(s.getOffsetParent==null?void 0:s.getOffsetParent(a.floating)),N=await(s.isElement==null?void 0:s.isElement(S))?await(s.getScale==null?void 0:s.getScale(S))||{x:1,y:1}:{x:1,y:1},C=ks(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:b,offsetParent:S,strategy:l}):b);return{top:(v.top-C.top+w.top)/N.y,bottom:(C.bottom-v.bottom+w.bottom)/N.y,left:(v.left-C.left+w.left)/N.x,right:(C.right-v.right+w.right)/N.x}}const 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}=In(e,t)||{};if(u==null)return{};const f=Kd(d),h={x:n,y:r},p=Ta(o),w=Ca(p),x=await i.getDimensions(u),g=p==="y",v=g?"top":"left",b=g?"bottom":"right",S=g?"clientHeight":"clientWidth",N=s.reference[w]+s.reference[p]-h[p]-s.floating[w],C=h[p]-s.reference[p],k=await(i.getOffsetParent==null?void 0:i.getOffsetParent(u));let E=k?k[S]:0;(!E||!await(i.isElement==null?void 0:i.isElement(k)))&&(E=a.floating[S]||s.floating[w]);const A=N/2-C/2,j=E/2-x[w]/2-1,P=zn(f[v],j),L=zn(f[b],j),F=P,V=E-x[w]-L,M=E/2-x[w]/2+A,Y=ya(F,M,V),K=!l.arrow&&Ir(o)!=null&&M!==Y&&s.reference[w]/2-(M<F?P:L)-x[w]/2<0,W=K?M<F?M-F:M-V:0;return{[p]:h[p]+W,data:{[p]:Y,centerOffset:M-Y-W,...K&&{alignmentOffset:W}},reset:K}}}),uy=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(t){var n,r;const{placement:o,middlewareData:s,rects:i,initialPlacement:a,platform:l,elements:u}=t,{mainAxis:d=!0,crossAxis:f=!0,fallbackPlacements:h,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:w="none",flipAlignment:x=!0,...g}=In(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const v=En(o),b=vn(a),S=En(a)===a,N=await(l.isRTL==null?void 0:l.isRTL(u.floating)),C=h||(S||!x?[Ts(a)]:ny(a)),k=w!=="none";!h&&k&&C.push(...iy(a,x,w,N));const E=[a,...C],A=await io(t,g),j=[];let P=((r=s.flip)==null?void 0:r.overflows)||[];if(d&&j.push(A[v]),f){const M=ty(o,i,N);j.push(A[M[0]],A[M[1]])}if(P=[...P,{placement:o,overflows:j}],!j.every(M=>M<=0)){var L,F;const M=(((L=s.flip)==null?void 0:L.index)||0)+1,Y=E[M];if(Y&&(!(f==="alignment"?b!==vn(Y):!1)||P.every(z=>vn(z.placement)===b?z.overflows[0]>0:!0)))return{data:{index:M,overflows:P},reset:{placement:Y}};let K=(F=P.filter(W=>W.overflows[0]<=0).sort((W,z)=>W.overflows[1]-z.overflows[1])[0])==null?void 0:F.placement;if(!K)switch(p){case"bestFit":{var V;const W=(V=P.filter(z=>{if(k){const $=vn(z.placement);return $===b||$==="y"}return!0}).map(z=>[z.placement,z.overflows.filter($=>$>0).reduce(($,ue)=>$+ue,0)]).sort((z,$)=>z[1]-$[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 Gd(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function Yd(e){return Jb.some(t=>e[t]>=0)}const dy=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n}=t,{strategy:r="referenceHidden",...o}=In(e,t);switch(r){case"referenceHidden":{const s=await io(t,{...o,elementContext:"reference"}),i=Gd(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:Yd(i)}}}case"escaped":{const s=await io(t,{...o,altBoundary:!0}),i=Gd(s,n.floating);return{data:{escapedOffsets:i,escaped:Yd(i)}}}default:return{}}}}},Xd=new Set(["left","top"]);async function fy(e,t){const{placement:n,platform:r,elements:o}=e,s=await(r.isRTL==null?void 0:r.isRTL(o.floating)),i=En(n),a=Ir(n),l=vn(n)==="y",u=Xd.has(i)?-1:1,d=s&&l?-1:1,f=In(t,e);let{mainAxis:h,crossAxis:p,alignmentAxis:w}=typeof f=="number"?{mainAxis:f,crossAxis:0,alignmentAxis:null}:{mainAxis:f.mainAxis||0,crossAxis:f.crossAxis||0,alignmentAxis:f.alignmentAxis};return a&&typeof w=="number"&&(p=a==="end"?w*-1:w),l?{x:p*d,y:h*u}:{x:h*u,y:p*d}}const hy=function(e){return e===void 0&&(e=0),{name:"offset",options:e,async fn(t){var n,r;const{x:o,y:s,placement:i,middlewareData:a}=t,l=await fy(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}}}}},py=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(t){const{x:n,y:r,placement:o}=t,{mainAxis:s=!0,crossAxis:i=!1,limiter:a={fn:g=>{let{x:v,y:b}=g;return{x:v,y:b}}},...l}=In(e,t),u={x:n,y:r},d=await io(t,l),f=vn(En(o)),h=Sa(f);let p=u[h],w=u[f];if(s){const g=h==="y"?"top":"left",v=h==="y"?"bottom":"right",b=p+d[g],S=p-d[v];p=ya(b,p,S)}if(i){const g=f==="y"?"top":"left",v=f==="y"?"bottom":"right",b=w+d[g],S=w-d[v];w=ya(b,w,S)}const x=a.fn({...t,[h]:p,[f]:w});return{...x,data:{x:x.x-n,y:x.y-r,enabled:{[h]:s,[f]:i}}}}}},my=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}=In(e,t),d={x:n,y:r},f=vn(o),h=Sa(f);let p=d[h],w=d[f];const x=In(a,t),g=typeof x=="number"?{mainAxis:x,crossAxis:0}:{mainAxis:0,crossAxis:0,...x};if(l){const S=h==="y"?"height":"width",N=s.reference[h]-s.floating[S]+g.mainAxis,C=s.reference[h]+s.reference[S]-g.mainAxis;p<N?p=N:p>C&&(p=C)}if(u){var v,b;const S=h==="y"?"width":"height",N=Xd.has(En(o)),C=s.reference[f]-s.floating[S]+(N&&((v=i.offset)==null?void 0:v[f])||0)+(N?0:g.crossAxis),k=s.reference[f]+s.reference[S]+(N?0:((b=i.offset)==null?void 0:b[f])||0)-(N?g.crossAxis:0);w<C?w=C:w>k&&(w=k)}return{[h]:p,[f]:w}}}},gy=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}=In(e,t),d=await io(t,u),f=En(o),h=Ir(o),p=vn(o)==="y",{width:w,height:x}=s.floating;let g,v;f==="top"||f==="bottom"?(g=f,v=h===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(v=f,g=h==="end"?"top":"bottom");const b=x-d.top-d.bottom,S=w-d.left-d.right,N=zn(x-d[g],b),C=zn(w-d[v],S),k=!t.middlewareData.shift;let E=N,A=C;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(A=S),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(E=b),k&&!h){const P=Bt(d.left,0),L=Bt(d.right,0),F=Bt(d.top,0),V=Bt(d.bottom,0);p?A=w-2*(P!==0||L!==0?P+L:Bt(d.left,d.right)):E=x-2*(F!==0||V!==0?F+V:Bt(d.top,d.bottom))}await l({...t,availableWidth:A,availableHeight:E});const j=await i.getDimensions(a.floating);return w!==j.width||x!==j.height?{reset:{rects:!0}}:{}}}};function Is(){return typeof window<"u"}function Er(e){return Jd(e)?(e.nodeName||"").toLowerCase():"#document"}function Ht(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function wn(e){var t;return(t=(Jd(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function Jd(e){return Is()?e instanceof Node||e instanceof Ht(e).Node:!1}function rn(e){return Is()?e instanceof Element||e instanceof Ht(e).Element:!1}function bn(e){return Is()?e instanceof HTMLElement||e instanceof Ht(e).HTMLElement:!1}function Zd(e){return!Is()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Ht(e).ShadowRoot}const xy=new Set(["inline","contents"]);function ao(e){const{overflow:t,overflowX:n,overflowY:r,display:o}=on(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!xy.has(o)}const vy=new Set(["table","td","th"]);function wy(e){return vy.has(Er(e))}const by=[":popover-open",":modal"];function Es(e){return by.some(t=>{try{return e.matches(t)}catch{return!1}})}const yy=["transform","translate","scale","rotate","perspective"],Sy=["transform","translate","scale","rotate","perspective","filter"],Cy=["paint","layout","strict","content"];function Ia(e){const t=Ea(),n=rn(e)?on(e):e;return yy.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)||Sy.some(r=>(n.willChange||"").includes(r))||Cy.some(r=>(n.contain||"").includes(r))}function Ty(e){let t=Bn(e);for(;bn(t)&&!Nr(t);){if(Ia(t))return t;if(Es(t))return null;t=Bn(t)}return null}function Ea(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const ky=new Set(["html","body","#document"]);function Nr(e){return ky.has(Er(e))}function on(e){return Ht(e).getComputedStyle(e)}function Ns(e){return rn(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Bn(e){if(Er(e)==="html")return e;const t=e.assignedSlot||e.parentNode||Zd(e)&&e.host||wn(e);return Zd(t)?t.host:t}function Qd(e){const t=Bn(e);return Nr(t)?e.ownerDocument?e.ownerDocument.body:e.body:bn(t)&&ao(t)?t:Qd(t)}function lo(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const o=Qd(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=Ht(o);if(s){const a=Na(i);return t.concat(i,i.visualViewport||[],ao(o)?o:[],a&&n?lo(a):[])}return t.concat(o,lo(o,[],n))}function Na(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function ef(e){const t=on(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const o=bn(e),s=o?e.offsetWidth:n,i=o?e.offsetHeight:r,a=Ss(n)!==s||Ss(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function Aa(e){return rn(e)?e:e.contextElement}function Ar(e){const t=Aa(e);if(!bn(t))return xn(1);const n=t.getBoundingClientRect(),{width:r,height:o,$:s}=ef(t);let i=(s?Ss(n.width):n.width)/r,a=(s?Ss(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const Iy=xn(0);function tf(e){const t=Ht(e);return!Ea()||!t.visualViewport?Iy:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function Ey(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==Ht(e)?!1:t}function or(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const o=e.getBoundingClientRect(),s=Aa(e);let i=xn(1);t&&(r?rn(r)&&(i=Ar(r)):i=Ar(e));const a=Ey(s,n,r)?tf(s):xn(0);let l=(o.left+a.x)/i.x,u=(o.top+a.y)/i.y,d=o.width/i.x,f=o.height/i.y;if(s){const h=Ht(s),p=r&&rn(r)?Ht(r):r;let w=h,x=Na(w);for(;x&&r&&p!==w;){const g=Ar(x),v=x.getBoundingClientRect(),b=on(x),S=v.left+(x.clientLeft+parseFloat(b.paddingLeft))*g.x,N=v.top+(x.clientTop+parseFloat(b.paddingTop))*g.y;l*=g.x,u*=g.y,d*=g.x,f*=g.y,l+=S,u+=N,w=Ht(x),x=Na(w)}}return ks({width:d,height:f,x:l,y:u})}function As(e,t){const n=Ns(e).scrollLeft;return t?t.left+n:or(wn(e)).left+n}function nf(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-As(e,n),o=n.top+t.scrollTop;return{x:r,y:o}}function Ny(e){let{elements:t,rect:n,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=wn(r),a=t?Es(t.floating):!1;if(r===i||a&&s)return n;let l={scrollLeft:0,scrollTop:0},u=xn(1);const d=xn(0),f=bn(r);if((f||!f&&!s)&&((Er(r)!=="body"||ao(i))&&(l=Ns(r)),bn(r))){const p=or(r);u=Ar(r),d.x=p.x+r.clientLeft,d.y=p.y+r.clientTop}const h=i&&!f&&!s?nf(i,l):xn(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 Ay(e){return Array.from(e.getClientRects())}function _y(e){const t=wn(e),n=Ns(e),r=e.ownerDocument.body,o=Bt(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=Bt(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let i=-n.scrollLeft+As(e);const a=-n.scrollTop;return on(r).direction==="rtl"&&(i+=Bt(t.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}const rf=25;function jy(e,t){const n=Ht(e),r=wn(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=Ea();(!d||d&&t==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}const u=As(r);if(u<=0){const d=r.ownerDocument,f=d.body,h=getComputedStyle(f),p=d.compatMode==="CSS1Compat"&&parseFloat(h.marginLeft)+parseFloat(h.marginRight)||0,w=Math.abs(r.clientWidth-f.clientWidth-p);w<=rf&&(s-=w)}else u<=rf&&(s+=u);return{width:s,height:i,x:a,y:l}}const Ry=new Set(["absolute","fixed"]);function Py(e,t){const n=or(e,!0,t==="fixed"),r=n.top+e.clientTop,o=n.left+e.clientLeft,s=bn(e)?Ar(e):xn(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 of(e,t,n){let r;if(t==="viewport")r=jy(e,n);else if(t==="document")r=_y(wn(e));else if(rn(t))r=Py(t,n);else{const o=tf(e);r={x:t.x-o.x,y:t.y-o.y,width:t.width,height:t.height}}return ks(r)}function sf(e,t){const n=Bn(e);return n===t||!rn(n)||Nr(n)?!1:on(n).position==="fixed"||sf(n,t)}function Oy(e,t){const n=t.get(e);if(n)return n;let r=lo(e,[],!1).filter(a=>rn(a)&&Er(a)!=="body"),o=null;const s=on(e).position==="fixed";let i=s?Bn(e):e;for(;rn(i)&&!Nr(i);){const a=on(i),l=Ia(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&Ry.has(o.position)||ao(i)&&!l&&sf(e,i))?r=r.filter(d=>d!==i):o=a,i=Bn(i)}return t.set(e,r),r}function My(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i=[...n==="clippingAncestors"?Es(t)?[]:Oy(t,this._c):[].concat(n),r],a=i[0],l=i.reduce((u,d)=>{const f=of(t,d,o);return u.top=Bt(f.top,u.top),u.right=zn(f.right,u.right),u.bottom=zn(f.bottom,u.bottom),u.left=Bt(f.left,u.left),u},of(t,a,o));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function Dy(e){const{width:t,height:n}=ef(e);return{width:t,height:n}}function Ly(e,t,n){const r=bn(t),o=wn(t),s=n==="fixed",i=or(e,!0,s,t);let a={scrollLeft:0,scrollTop:0};const l=xn(0);function u(){l.x=As(o)}if(r||!r&&!s)if((Er(t)!=="body"||ao(o))&&(a=Ns(t)),r){const p=or(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?nf(o,a):xn(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 _a(e){return on(e).position==="static"}function af(e,t){if(!bn(e)||on(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return wn(e)===n&&(n=n.ownerDocument.body),n}function lf(e,t){const n=Ht(e);if(Es(e))return n;if(!bn(e)){let o=Bn(e);for(;o&&!Nr(o);){if(rn(o)&&!_a(o))return o;o=Bn(o)}return n}let r=af(e,t);for(;r&&wy(r)&&_a(r);)r=af(r,t);return r&&Nr(r)&&_a(r)&&!Ia(r)?n:r||Ty(e)||n}const Fy=async function(e){const t=this.getOffsetParent||lf,n=this.getDimensions,r=await n(e.floating);return{reference:Ly(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function $y(e){return on(e).direction==="rtl"}const zy={convertOffsetParentRelativeRectToViewportRelativeRect:Ny,getDocumentElement:wn,getClippingRect:My,getOffsetParent:lf,getElementRects:Fy,getClientRects:Ay,getDimensions:Dy,getScale:Ar,isElement:rn,isRTL:$y};function cf(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function By(e,t){let n=null,r;const o=wn(e);function s(){var a;clearTimeout(r),(a=n)==null||a.disconnect(),n=null}function i(a,l){a===void 0&&(a=!1),l===void 0&&(l=1),s();const u=e.getBoundingClientRect(),{left:d,top:f,width:h,height:p}=u;if(a||t(),!h||!p)return;const w=Cs(f),x=Cs(o.clientWidth-(d+h)),g=Cs(o.clientHeight-(f+p)),v=Cs(d),S={rootMargin:-w+"px "+-x+"px "+-g+"px "+-v+"px",threshold:Bt(0,zn(1,l))||1};let N=!0;function C(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&&!cf(u,e.getBoundingClientRect())&&i(),N=!1}try{n=new IntersectionObserver(C,{...S,root:o.ownerDocument})}catch{n=new IntersectionObserver(C,S)}n.observe(e)}return i(!0),s}function Hy(e,t,n,r){r===void 0&&(r={});const{ancestorScroll:o=!0,ancestorResize:s=!0,elementResize:i=typeof ResizeObserver=="function",layoutShift:a=typeof IntersectionObserver=="function",animationFrame:l=!1}=r,u=Aa(e),d=o||s?[...u?lo(u):[],...lo(t)]:[];d.forEach(v=>{o&&v.addEventListener("scroll",n,{passive:!0}),s&&v.addEventListener("resize",n)});const f=u&&a?By(u,n):null;let h=-1,p=null;i&&(p=new ResizeObserver(v=>{let[b]=v;b&&b.target===u&&p&&(p.unobserve(t),cancelAnimationFrame(h),h=requestAnimationFrame(()=>{var S;(S=p)==null||S.observe(t)})),n()}),u&&!l&&p.observe(u),p.observe(t));let w,x=l?or(e):null;l&&g();function g(){const v=or(e);x&&!cf(x,v)&&n(),x=v,w=requestAnimationFrame(g)}return n(),()=>{var v;d.forEach(b=>{o&&b.removeEventListener("scroll",n),s&&b.removeEventListener("resize",n)}),f==null||f(),(v=p)==null||v.disconnect(),p=null,l&&cancelAnimationFrame(w)}}const Uy=hy,Wy=py,Vy=uy,Ky=gy,qy=dy,uf=cy,Gy=my,Yy=(e,t,n)=>{const r=new Map,o={platform:zy,...n},s={...o.platform,_c:r};return ly(e,t,{...o,platform:s})};var Xy=typeof document<"u",Jy=function(){},_s=Xy?y.useLayoutEffect:Jy;function js(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(!js(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)&&!js(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function df(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function ff(e,t){const n=df(e);return Math.round(t*n)/n}function ja(e){const t=m.useRef(e);return _s(()=>{t.current=e}),t}function Zy(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);js(h,r)||p(r);const[w,x]=m.useState(null),[g,v]=m.useState(null),b=m.useCallback(z=>{z!==k.current&&(k.current=z,x(z))},[]),S=m.useCallback(z=>{z!==E.current&&(E.current=z,v(z))},[]),N=s||w,C=i||g,k=m.useRef(null),E=m.useRef(null),A=m.useRef(d),j=l!=null,P=ja(l),L=ja(o),F=ja(u),V=m.useCallback(()=>{if(!k.current||!E.current)return;const z={placement:t,strategy:n,middleware:h};L.current&&(z.platform=L.current),Yy(k.current,E.current,z).then($=>{const ue={...$,isPositioned:F.current!==!1};M.current&&!js(A.current,ue)&&(A.current=ue,vo.flushSync(()=>{f(ue)}))})},[h,t,n,L,F]);_s(()=>{u===!1&&A.current.isPositioned&&(A.current.isPositioned=!1,f(z=>({...z,isPositioned:!1})))},[u]);const M=m.useRef(!1);_s(()=>(M.current=!0,()=>{M.current=!1}),[]),_s(()=>{if(N&&(k.current=N),C&&(E.current=C),N&&C){if(P.current)return P.current(N,C,V);V()}},[N,C,V,P,j]);const Y=m.useMemo(()=>({reference:k,floating:E,setReference:b,setFloating:S}),[b,S]),K=m.useMemo(()=>({reference:N,floating:C}),[N,C]),W=m.useMemo(()=>{const z={position:n,left:0,top:0};if(!K.floating)return z;const $=ff(K.floating,d.x),ue=ff(K.floating,d.y);return a?{...z,transform:"translate("+$+"px, "+ue+"px)",...df(K.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:$,top:ue}},[n,a,K.floating,d.x,d.y]);return m.useMemo(()=>({...d,update:V,refs:Y,elements:K,floatingStyles:W}),[d,V,Y,K,W])}const Qy=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?uf({element:r.current,padding:o}).fn(n):{}:r?uf({element:r,padding:o}).fn(n):{}}}},e0=(e,t)=>({...Uy(e),options:[e,t]}),t0=(e,t)=>({...Wy(e),options:[e,t]}),n0=(e,t)=>({...Gy(e),options:[e,t]}),r0=(e,t)=>({...Vy(e),options:[e,t]}),o0=(e,t)=>({...Ky(e),options:[e,t]}),s0=(e,t)=>({...qy(e),options:[e,t]}),i0=(e,t)=>({...Qy(e),options:[e,t]});var a0="Arrow",hf=m.forwardRef((e,t)=>{const{children:n,width:r=10,height:o=5,...s}=e;return c.jsx(je.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"})})});hf.displayName=a0;var l0=hf;function pf(e){const[t,n]=m.useState(void 0);return vt(()=>{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 Ra="Popper",[mf,Rs]=pn(Ra),[c0,gf]=mf(Ra),xf=e=>{const{__scopePopper:t,children:n}=e,[r,o]=m.useState(null);return c.jsx(c0,{scope:t,anchor:r,onAnchorChange:o,children:n})};xf.displayName=Ra;var vf="PopperAnchor",wf=m.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...o}=e,s=gf(vf,n),i=m.useRef(null),a=We(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(je.div,{...o,ref:a})});wf.displayName=vf;var Pa="PopperContent",[u0,d0]=mf(Pa),bf=m.forwardRef((e,t)=>{var q,O,J,te,G,se;const{__scopePopper:n,side:r="bottom",sideOffset:o=0,align:s="center",alignOffset:i=0,arrowPadding:a=0,avoidCollisions:l=!0,collisionBoundary:u=[],collisionPadding:d=0,sticky:f="partial",hideWhenDetached:h=!1,updatePositionStrategy:p="optimized",onPlaced:w,...x}=e,g=gf(Pa,n),[v,b]=m.useState(null),S=We(t,Ve=>b(Ve)),[N,C]=m.useState(null),k=pf(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],F=L.length>0,V={padding:P,boundary:L.filter(h0),altBoundary:F},{refs:M,floatingStyles:Y,placement:K,isPositioned:W,middlewareData:z}=Zy({strategy:"fixed",placement:j,whileElementsMounted:(...Ve)=>Hy(...Ve,{animationFrame:p==="always"}),elements:{reference:g.anchor},middleware:[e0({mainAxis:o+A,alignmentAxis:i}),l&&t0({mainAxis:!0,crossAxis:!1,limiter:f==="partial"?n0():void 0,...V}),l&&r0({...V}),o0({...V,apply:({elements:Ve,rects:Je,availableWidth:nt,availableHeight:De})=>{const{width:Be,height:Ee}=Je.reference,Ze=Ve.floating.style;Ze.setProperty("--radix-popper-available-width",`${nt}px`),Ze.setProperty("--radix-popper-available-height",`${De}px`),Ze.setProperty("--radix-popper-anchor-width",`${Be}px`),Ze.setProperty("--radix-popper-anchor-height",`${Ee}px`)}}),N&&i0({element:N,padding:a}),p0({arrowWidth:E,arrowHeight:A}),h&&s0({strategy:"referenceHidden",...V})]}),[$,ue]=Cf(K),D=yt(w);vt(()=>{W&&(D==null||D())},[W,D]);const ee=(q=z.arrow)==null?void 0:q.x,fe=(O=z.arrow)==null?void 0:O.y,ve=((J=z.arrow)==null?void 0:J.centerOffset)!==0,[be,ye]=m.useState();return vt(()=>{v&&ye(window.getComputedStyle(v).zIndex)},[v]),c.jsx("div",{ref:M.setFloating,"data-radix-popper-content-wrapper":"",style:{...Y,transform:W?Y.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:be,"--radix-popper-transform-origin":[(te=z.transformOrigin)==null?void 0:te.x,(G=z.transformOrigin)==null?void 0:G.y].join(" "),...((se=z.hide)==null?void 0:se.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:c.jsx(u0,{scope:n,placedSide:$,onArrowChange:C,arrowX:ee,arrowY:fe,shouldHideArrow:ve,children:c.jsx(je.div,{"data-side":$,"data-align":ue,...x,ref:S,style:{...x.style,animation:W?void 0:"none"}})})})});bf.displayName=Pa;var yf="PopperArrow",f0={top:"bottom",right:"left",bottom:"top",left:"right"},Sf=m.forwardRef(function(t,n){const{__scopePopper:r,...o}=t,s=d0(yf,r),i=f0[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(l0,{...o,ref:n,style:{...o.style,display:"block"}})})});Sf.displayName=yf;function h0(e){return e!==null}var p0=e=>({name:"transformOrigin",options:e,fn(t){var g,v,b;const{placement:n,rects:r,middlewareData:o}=t,i=((g=o.arrow)==null?void 0:g.centerOffset)!==0,a=i?0:e.arrowWidth,l=i?0:e.arrowHeight,[u,d]=Cf(n),f={start:"0%",center:"50%",end:"100%"}[d],h=(((v=o.arrow)==null?void 0:v.x)??0)+a/2,p=(((b=o.arrow)==null?void 0:b.y)??0)+l/2;let w="",x="";return u==="bottom"?(w=i?f:`${h}px`,x=`${-l}px`):u==="top"?(w=i?f:`${h}px`,x=`${r.floating.height+l}px`):u==="right"?(w=`${-l}px`,x=i?f:`${p}px`):u==="left"&&(w=`${r.floating.width+l}px`,x=i?f:`${p}px`),{data:{x:w,y:x}}}});function Cf(e){const[t,n="center"]=e.split("-");return[t,n]}var Tf=xf,kf=wf,If=bf,Ef=Sf,Oa="rovingFocusGroup.onEntryFocus",m0={bubbles:!1,cancelable:!0},co="RovingFocusGroup",[Ma,Nf,g0]=ba(co),[x0,Af]=pn(co,[g0]),[v0,w0]=x0(co),_f=m.forwardRef((e,t)=>c.jsx(Ma.Provider,{scope:e.__scopeRovingFocusGroup,children:c.jsx(Ma.Slot,{scope:e.__scopeRovingFocusGroup,children:c.jsx(b0,{...e,ref:t})})}));_f.displayName=co;var b0=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=We(t,h),w=ys(s),[x,g]=Qn({prop:i,defaultProp:a??null,onChange:l,caller:co}),[v,b]=m.useState(!1),S=yt(u),N=Nf(n),C=m.useRef(!1),[k,E]=m.useState(0);return m.useEffect(()=>{const A=h.current;if(A)return A.addEventListener(Oa,S),()=>A.removeEventListener(Oa,S)},[S]),c.jsx(v0,{scope:n,orientation:r,dir:w,loop:o,currentTabStopId:x,onItemFocus:m.useCallback(A=>g(A),[g]),onItemShiftTab:m.useCallback(()=>b(!0),[]),onFocusableItemAdd:m.useCallback(()=>E(A=>A+1),[]),onFocusableItemRemove:m.useCallback(()=>E(A=>A-1),[]),children:c.jsx(je.div,{tabIndex:v||k===0?-1:0,"data-orientation":r,...f,ref:p,style:{outline:"none",...e.style},onMouseDown:de(e.onMouseDown,()=>{C.current=!0}),onFocus:de(e.onFocus,A=>{const j=!C.current;if(A.target===A.currentTarget&&j&&!v){const P=new CustomEvent(Oa,m0);if(A.currentTarget.dispatchEvent(P),!P.defaultPrevented){const L=N().filter(K=>K.focusable),F=L.find(K=>K.active),V=L.find(K=>K.id===x),Y=[F,V,...L].filter(Boolean).map(K=>K.ref.current);Pf(Y,d)}}C.current=!1}),onBlur:de(e.onBlur,()=>b(!1))})})}),jf="RovingFocusGroupItem",Rf=m.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:o=!1,tabStopId:s,children:i,...a}=e,l=mn(),u=s||l,d=w0(jf,n),f=d.currentTabStopId===u,h=Nf(n),{onFocusableItemAdd:p,onFocusableItemRemove:w,currentTabStopId:x}=d;return m.useEffect(()=>{if(r)return p(),()=>w()},[r,p,w]),c.jsx(Ma.ItemSlot,{scope:n,id:u,focusable:r,active:o,children:c.jsx(je.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=C0(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?T0(S,N+1):S.slice(N+1)}setTimeout(()=>Pf(S))}}),children:typeof i=="function"?i({isCurrentTabStop:f,hasTabStop:x!=null}):i})})});Rf.displayName=jf;var y0={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function S0(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function C0(e,t,n){const r=S0(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return y0[r]}function Pf(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function T0(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var k0=_f,I0=Rf,Da=["Enter"," "],E0=["ArrowDown","PageUp","Home"],Of=["ArrowUp","PageDown","End"],N0=[...E0,...Of],A0={ltr:[...Da,"ArrowRight"],rtl:[...Da,"ArrowLeft"]},_0={ltr:["ArrowLeft"],rtl:["ArrowRight"]},uo="Menu",[fo,j0,R0]=ba(uo),[sr,Mf]=pn(uo,[R0,Rs,Af]),Ps=Rs(),Df=Af(),[P0,ir]=sr(uo),[O0,ho]=sr(uo),Lf=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=Ps(t),[l,u]=m.useState(null),d=m.useRef(!1),f=yt(s),h=ys(o);return m.useEffect(()=>{const p=()=>{d.current=!0,document.addEventListener("pointerdown",w,{capture:!0,once:!0}),document.addEventListener("pointermove",w,{capture:!0,once:!0})},w=()=>d.current=!1;return document.addEventListener("keydown",p,{capture:!0}),()=>{document.removeEventListener("keydown",p,{capture:!0}),document.removeEventListener("pointerdown",w,{capture:!0}),document.removeEventListener("pointermove",w,{capture:!0})}},[]),c.jsx(Tf,{...a,children:c.jsx(P0,{scope:t,open:n,onOpenChange:f,content:l,onContentChange:u,children:c.jsx(O0,{scope:t,onClose:m.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:d,dir:h,modal:i,children:r})})})};Lf.displayName=uo;var M0="MenuAnchor",La=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=Ps(n);return c.jsx(kf,{...o,...r,ref:t})});La.displayName=M0;var Fa="MenuPortal",[D0,Ff]=sr(Fa,{forceMount:void 0}),$f=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:o}=e,s=ir(Fa,t);return c.jsx(D0,{scope:t,forceMount:n,children:c.jsx(zt,{present:n||s.open,children:c.jsx(ss,{asChild:!0,container:o,children:r})})})};$f.displayName=Fa;var qt="MenuContent",[L0,$a]=sr(qt),zf=m.forwardRef((e,t)=>{const n=Ff(qt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=ir(qt,e.__scopeMenu),i=ho(qt,e.__scopeMenu);return c.jsx(fo.Provider,{scope:e.__scopeMenu,children:c.jsx(zt,{present:r||s.open,children:c.jsx(fo.Slot,{scope:e.__scopeMenu,children:i.modal?c.jsx(F0,{...o,ref:t}):c.jsx($0,{...o,ref:t})})})})}),F0=m.forwardRef((e,t)=>{const n=ir(qt,e.__scopeMenu),r=m.useRef(null),o=We(t,r);return m.useEffect(()=>{const s=r.current;if(s)return pa(s)},[]),c.jsx(za,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:de(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),$0=m.forwardRef((e,t)=>{const n=ir(qt,e.__scopeMenu);return c.jsx(za,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),z0=Vn.createSlot("MenuContent.ScrollLock"),za=m.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:o,onOpenAutoFocus:s,onCloseAutoFocus:i,disableOutsidePointerEvents:a,onEntryFocus:l,onEscapeKeyDown:u,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:h,onDismiss:p,disableOutsideScroll:w,...x}=e,g=ir(qt,n),v=ho(qt,n),b=Ps(n),S=Df(n),N=j0(n),[C,k]=m.useState(null),E=m.useRef(null),A=We(t,E,g.onContentChange),j=m.useRef(0),P=m.useRef(""),L=m.useRef(0),F=m.useRef(null),V=m.useRef("right"),M=m.useRef(0),Y=w?ds:m.Fragment,K=w?{as:z0,allowPinchZoom:!0}:void 0,W=$=>{var q,O;const ue=P.current+$,D=N().filter(J=>!J.disabled),ee=document.activeElement,fe=(q=D.find(J=>J.ref.current===ee))==null?void 0:q.textValue,ve=D.map(J=>J.textValue),be=Z0(ve,ue,fe),ye=(O=D.find(J=>J.textValue===be))==null?void 0:O.ref.current;(function J(te){P.current=te,window.clearTimeout(j.current),te!==""&&(j.current=window.setTimeout(()=>J(""),1e3))})(ue),ye&&setTimeout(()=>ye.focus())};m.useEffect(()=>()=>window.clearTimeout(j.current),[]),la();const z=m.useCallback($=>{var D,ee;return V.current===((D=F.current)==null?void 0:D.side)&&eS($,(ee=F.current)==null?void 0:ee.area)},[]);return c.jsx(L0,{scope:n,searchRef:P,onItemEnter:m.useCallback($=>{z($)&&$.preventDefault()},[z]),onItemLeave:m.useCallback($=>{var ue;z($)||((ue=E.current)==null||ue.focus(),k(null))},[z]),onTriggerLeave:m.useCallback($=>{z($)&&$.preventDefault()},[z]),pointerGraceTimerRef:L,onPointerGraceIntentChange:m.useCallback($=>{F.current=$},[]),children:c.jsx(Y,{...K,children:c.jsx(os,{asChild:!0,trapped:o,onMountAutoFocus:de(s,$=>{var ue;$.preventDefault(),(ue=E.current)==null||ue.focus({preventScroll:!0})}),onUnmountAutoFocus:i,children:c.jsx(rs,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:u,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:h,onDismiss:p,children:c.jsx(k0,{asChild:!0,...S,dir:v.dir,orientation:"vertical",loop:r,currentTabStopId:C,onCurrentTabStopIdChange:k,onEntryFocus:de(l,$=>{v.isUsingKeyboardRef.current||$.preventDefault()}),preventScrollOnEntryFocus:!0,children:c.jsx(If,{role:"menu","aria-orientation":"vertical","data-state":rh(g.open),"data-radix-menu-content":"",dir:v.dir,...b,...x,ref:A,style:{outline:"none",...x.style},onKeyDown:de(x.onKeyDown,$=>{const D=$.target.closest("[data-radix-menu-content]")===$.currentTarget,ee=$.ctrlKey||$.altKey||$.metaKey,fe=$.key.length===1;D&&($.key==="Tab"&&$.preventDefault(),!ee&&fe&&W($.key));const ve=E.current;if($.target!==ve||!N0.includes($.key))return;$.preventDefault();const ye=N().filter(q=>!q.disabled).map(q=>q.ref.current);Of.includes($.key)&&ye.reverse(),X0(ye)}),onBlur:de(e.onBlur,$=>{$.currentTarget.contains($.target)||(window.clearTimeout(j.current),P.current="")}),onPointerMove:de(e.onPointerMove,mo($=>{const ue=$.target,D=M.current!==$.clientX;if($.currentTarget.contains(ue)&&D){const ee=$.clientX>M.current?"right":"left";V.current=ee,M.current=$.clientX}}))})})})})})})});zf.displayName=qt;var B0="MenuGroup",Ba=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return c.jsx(je.div,{role:"group",...r,ref:t})});Ba.displayName=B0;var H0="MenuLabel",Bf=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return c.jsx(je.div,{...r,ref:t})});Bf.displayName=H0;var Os="MenuItem",Hf="menu.itemSelect",Ms=m.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...o}=e,s=m.useRef(null),i=ho(Os,e.__scopeMenu),a=$a(Os,e.__scopeMenu),l=We(t,s),u=m.useRef(!1),d=()=>{const f=s.current;if(!n&&f){const h=new CustomEvent(Hf,{bubbles:!0,cancelable:!0});f.addEventListener(Hf,p=>r==null?void 0:r(p),{once:!0}),Su(f,h),h.defaultPrevented?u.current=!1:i.onClose()}};return c.jsx(Uf,{...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===" "||Da.includes(f.key)&&(f.currentTarget.click(),f.preventDefault())})})});Ms.displayName=Os;var Uf=m.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:o,...s}=e,i=$a(Os,n),a=Df(n),l=m.useRef(null),u=We(t,l),[d,f]=m.useState(!1),[h,p]=m.useState("");return m.useEffect(()=>{const w=l.current;w&&p((w.textContent??"").trim())},[s.children]),c.jsx(fo.ItemSlot,{scope:n,disabled:r,textValue:o??h,children:c.jsx(I0,{asChild:!0,...a,focusable:!r,children:c.jsx(je.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,mo(w=>{r?i.onItemLeave(w):(i.onItemEnter(w),w.defaultPrevented||w.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:de(e.onPointerLeave,mo(w=>i.onItemLeave(w))),onFocus:de(e.onFocus,()=>f(!0)),onBlur:de(e.onBlur,()=>f(!1))})})})}),U0="MenuCheckboxItem",Wf=m.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...o}=e;return c.jsx(Yf,{scope:e.__scopeMenu,checked:n,children:c.jsx(Ms,{role:"menuitemcheckbox","aria-checked":Ds(n)?"mixed":n,...o,ref:t,"data-state":Ua(n),onSelect:de(o.onSelect,()=>r==null?void 0:r(Ds(n)?!0:!n),{checkForDefaultPrevented:!1})})})});Wf.displayName=U0;var Vf="MenuRadioGroup",[W0,V0]=sr(Vf,{value:void 0,onValueChange:()=>{}}),Kf=m.forwardRef((e,t)=>{const{value:n,onValueChange:r,...o}=e,s=yt(r);return c.jsx(W0,{scope:e.__scopeMenu,value:n,onValueChange:s,children:c.jsx(Ba,{...o,ref:t})})});Kf.displayName=Vf;var qf="MenuRadioItem",Gf=m.forwardRef((e,t)=>{const{value:n,...r}=e,o=V0(qf,e.__scopeMenu),s=n===o.value;return c.jsx(Yf,{scope:e.__scopeMenu,checked:s,children:c.jsx(Ms,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":Ua(s),onSelect:de(r.onSelect,()=>{var i;return(i=o.onValueChange)==null?void 0:i.call(o,n)},{checkForDefaultPrevented:!1})})})});Gf.displayName=qf;var Ha="MenuItemIndicator",[Yf,K0]=sr(Ha,{checked:!1}),Xf=m.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...o}=e,s=K0(Ha,n);return c.jsx(zt,{present:r||Ds(s.checked)||s.checked===!0,children:c.jsx(je.span,{...o,ref:t,"data-state":Ua(s.checked)})})});Xf.displayName=Ha;var q0="MenuSeparator",Jf=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return c.jsx(je.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});Jf.displayName=q0;var G0="MenuArrow",Zf=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=Ps(n);return c.jsx(Ef,{...o,...r,ref:t})});Zf.displayName=G0;var Y0="MenuSub",[jT,Qf]=sr(Y0),po="MenuSubTrigger",eh=m.forwardRef((e,t)=>{const n=ir(po,e.__scopeMenu),r=ho(po,e.__scopeMenu),o=Qf(po,e.__scopeMenu),s=$a(po,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(La,{asChild:!0,...u,children:c.jsx(Uf,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":o.contentId,"data-state":rh(n.open),...e,ref:Gi(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,mo(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,mo(f=>{var p,w;d();const h=(p=n.content)==null?void 0:p.getBoundingClientRect();if(h){const x=(w=n.content)==null?void 0:w.dataset.side,g=x==="right",v=g?-5:5,b=h[g?"left":"right"],S=h[g?"right":"left"];s.onPointerGraceIntentChange({area:[{x:f.clientX+v,y:f.clientY},{x:b,y:h.top},{x:S,y:h.top},{x:S,y:h.bottom},{x:b,y:h.bottom}],side:x}),window.clearTimeout(a.current),a.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(f),f.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:de(e.onKeyDown,f=>{var p;const h=s.searchRef.current!=="";e.disabled||h&&f.key===" "||A0[r.dir].includes(f.key)&&(n.onOpenChange(!0),(p=n.content)==null||p.focus(),f.preventDefault())})})})});eh.displayName=po;var th="MenuSubContent",nh=m.forwardRef((e,t)=>{const n=Ff(qt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=ir(qt,e.__scopeMenu),i=ho(qt,e.__scopeMenu),a=Qf(th,e.__scopeMenu),l=m.useRef(null),u=We(t,l);return c.jsx(fo.Provider,{scope:e.__scopeMenu,children:c.jsx(zt,{present:r||s.open,children:c.jsx(fo.Slot,{scope:e.__scopeMenu,children:c.jsx(za,{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=_0[i.dir].includes(d.key);f&&h&&(s.onOpenChange(!1),(p=a.trigger)==null||p.focus(),d.preventDefault())})})})})})});nh.displayName=th;function rh(e){return e?"open":"closed"}function Ds(e){return e==="indeterminate"}function Ua(e){return Ds(e)?"indeterminate":e?"checked":"unchecked"}function X0(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function J0(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function Z0(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=J0(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 Q0(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 eS(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return Q0(n,t)}function mo(e){return t=>t.pointerType==="mouse"?e(t):void 0}var tS=Lf,nS=La,rS=$f,oS=zf,sS=Ba,iS=Bf,aS=Ms,lS=Wf,cS=Kf,uS=Gf,dS=Xf,fS=Jf,hS=Zf,pS=eh,mS=nh,Ls="DropdownMenu",[gS,RT]=pn(Ls,[Mf]),jt=Mf(),[xS,oh]=gS(Ls),sh=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:o,defaultOpen:s,onOpenChange:i,modal:a=!0}=e,l=jt(t),u=m.useRef(null),[d,f]=Qn({prop:o,defaultProp:s??!1,onChange:i,caller:Ls});return c.jsx(xS,{scope:t,triggerId:mn(),triggerRef:u,contentId:mn(),open:d,onOpenChange:f,onOpenToggle:m.useCallback(()=>f(h=>!h),[f]),modal:a,children:c.jsx(tS,{...l,open:d,onOpenChange:f,dir:r,modal:a,children:n})})};sh.displayName=Ls;var ih="DropdownMenuTrigger",ah=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...o}=e,s=oh(ih,n),i=jt(n);return c.jsx(nS,{asChild:!0,...i,children:c.jsx(je.button,{type:"button",id:s.triggerId,"aria-haspopup":"menu","aria-expanded":s.open,"aria-controls":s.open?s.contentId:void 0,"data-state":s.open?"open":"closed","data-disabled":r?"":void 0,disabled:r,...o,ref:Gi(t,s.triggerRef),onPointerDown: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())})})})});ah.displayName=ih;var vS="DropdownMenuPortal",lh=e=>{const{__scopeDropdownMenu:t,...n}=e,r=jt(t);return c.jsx(rS,{...r,...n})};lh.displayName=vS;var ch="DropdownMenuContent",uh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=oh(ch,n),s=jt(n),i=m.useRef(!1);return c.jsx(oS,{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)"}})});uh.displayName=ch;var wS="DropdownMenuGroup",bS=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=jt(n);return c.jsx(sS,{...o,...r,ref:t})});bS.displayName=wS;var yS="DropdownMenuLabel",dh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=jt(n);return c.jsx(iS,{...o,...r,ref:t})});dh.displayName=yS;var SS="DropdownMenuItem",fh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=jt(n);return c.jsx(aS,{...o,...r,ref:t})});fh.displayName=SS;var CS="DropdownMenuCheckboxItem",hh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=jt(n);return c.jsx(lS,{...o,...r,ref:t})});hh.displayName=CS;var TS="DropdownMenuRadioGroup",kS=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=jt(n);return c.jsx(cS,{...o,...r,ref:t})});kS.displayName=TS;var IS="DropdownMenuRadioItem",ph=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=jt(n);return c.jsx(uS,{...o,...r,ref:t})});ph.displayName=IS;var ES="DropdownMenuItemIndicator",mh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=jt(n);return c.jsx(dS,{...o,...r,ref:t})});mh.displayName=ES;var NS="DropdownMenuSeparator",gh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=jt(n);return c.jsx(fS,{...o,...r,ref:t})});gh.displayName=NS;var AS="DropdownMenuArrow",_S=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=jt(n);return c.jsx(hS,{...o,...r,ref:t})});_S.displayName=AS;var jS="DropdownMenuSubTrigger",xh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=jt(n);return c.jsx(pS,{...o,...r,ref:t})});xh.displayName=jS;var RS="DropdownMenuSubContent",vh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=jt(n);return c.jsx(mS,{...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)"}})});vh.displayName=RS;var PS=sh,OS=ah,MS=lh,wh=uh,bh=dh,yh=fh,Sh=hh,Ch=ph,Th=mh,kh=gh,Ih=xh,Eh=vh;const DS=PS,LS=OS,FS=m.forwardRef(({className:e,inset:t,children:n,...r},o)=>c.jsxs(Ih,{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(ie.ChevronRight,{className:"ml-auto h-4 w-4"})]}));FS.displayName=Ih.displayName;const $S=m.forwardRef(({className:e,...t},n)=>c.jsx(Eh,{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}));$S.displayName=Eh.displayName;const Nh=m.forwardRef(({className:e,sideOffset:t=4,...n},r)=>c.jsx(MS,{children:c.jsx(wh,{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})}));Nh.displayName=wh.displayName;const Wa=m.forwardRef(({className:e,inset:t,...n},r)=>c.jsx(yh,{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}));Wa.displayName=yh.displayName;const zS=m.forwardRef(({className:e,children:t,checked:n,...r},o)=>c.jsxs(Sh,{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(Th,{children:c.jsx(ie.Check,{className:"h-4 w-4"})})}),t]}));zS.displayName=Sh.displayName;const BS=m.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(Ch,{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(Th,{children:c.jsx(ie.Circle,{className:"h-2 w-2 fill-current"})})}),t]}));BS.displayName=Ch.displayName;const HS=m.forwardRef(({className:e,inset:t,...n},r)=>c.jsx(bh,{ref:r,className:Q("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));HS.displayName=bh.displayName;const US=m.forwardRef(({className:e,...t},n)=>c.jsx(kh,{ref:n,className:Q("-mx-1 my-1 h-px bg-muted",e),...t}));US.displayName=kh.displayName;function Fs({className:e="",placeholder:t="Type your message...",autoFocus:n=!0,maxHeight:r=void 0,streamingDebounceMs:o=500,streamingThrottleMs:s,followNewMessages:i=!0,enableFileUpload:a=!0,enableExcelUpload:l=!1,enableMessageEditing:u=!0,customStyles:d={},onMessageSent:f,onExcelUploadSuccess:h,onError:p}){const{api:w}=pi(),{currentThreadId:x}=Ro(),{threadId:g,messages:v,hasMore:b,isHistoryLoading:S,isLoading:N,loadOlder:C,listCheckpoints:k,navigateToCheckpoint:E,returnToLatest:A,checkpoint:j,respondToInterrupt:P,metadata:L}=Po(),{isStreaming:F,error:V,submit:M,stop:Y}=yc(),K=g??x??null,W=(j==null?void 0:j.id)??null,z=(j==null?void 0:j.namespace)??null,$=(L==null?void 0:L.assemblingMessageId)??null,[ue,D]=y.useState(null),[ee,fe]=y.useState(""),[ve,be]=y.useState(null),[ye,q]=y.useState([]),[O,J]=y.useState(0),[te,G]=y.useState(0),[se,Ve]=y.useState(!1),[Je,nt]=y.useState(null),[De,Be]=y.useState(null),[Ee,Ze]=y.useState(!1),[wt,ht]=y.useState(null),[Z,re]=y.useState([]),[pe,Ne]=y.useState(null),[we,Ae]=y.useState(null),[Qe,ze]=y.useState(!1),lt=y.useRef(null),St=y.useRef(null),Ut=y.useRef(null),gt=y.useCallback(()=>{lt.current&&(lt.current.value=""),St.current&&(St.current.value=""),J(ae=>ae+1),G(ae=>ae+1)},[]),Pr=y.useRef(!1);y.useEffect(()=>{Pr.current&&!F&&(q([]),gt()),Pr.current=F},[F,gt]);const[ur,bt]=y.useState("desktop");y.useEffect(()=>{const ae=()=>{const Te=window.innerWidth;bt(Te<640?"phone":Te<1024?"tablet":"desktop")};return ae(),window.addEventListener("resize",ae),()=>window.removeEventListener("resize",ae)},[]),y.useEffect(()=>{let ae=!1;if(!K){re([]),Ne(null),Ae(null),Ut.current=null;return}const Te={threadId:K,checkpointId:W??null,checkpointNs:z??null},Oe=Ut.current;if(!(Oe&&Oe.threadId===Te.threadId&&Oe.checkpointId===Te.checkpointId&&Oe.checkpointNs===Te.checkpointNs))return k(K).then(rt=>{var ke;if(ae)return;const Rt=((rt==null?void 0:rt.checkpoints)??[]).slice().sort((Fe,Ke)=>new Date(Ke.createdAt).getTime()-new Date(Fe.createdAt).getTime());re(Rt);const I=pe,B=I&&Rt.some(Fe=>Fe.checkpointId===I)?I:((ke=Rt[0])==null?void 0:ke.checkpointId)??null;let oe=null;if(B){const Fe=Rt.find(Ke=>Ke.checkpointId===B);oe=(Fe==null?void 0:Fe.checkpointNs)??null}Ne(B),Ae(oe),Ut.current=Te}).catch(rt=>{console.error("ChatInterface - listCheckpoints error:",rt),ae||(re([]),Ut.current=null)}),()=>{ae=!0}},[K,W,z,pe,k]),y.useEffect(()=>{W&&(Ne(W),Ae(z??null))},[W,z]);const Sn=y.useCallback(async()=>{if(!(!b||S))try{await C()}catch(ae){console.warn("loadOlder failed",ae)}},[b,S,C]);y.useEffect(()=>{(async()=>{if(!w.baseUrl){ht(null);return}try{const Te=await w.getAgent("default");ht(Te.uiDefaultMessage||null)}catch(Te){console.warn("Failed to fetch default message:",Te),ht(null)}})()},[w]),y.useEffect(()=>{V&&!Ee&&(p==null||p(V))},[V,Ee,p]);const an=ae=>{if(ae.length>bs)return`Message too long (${ae.length}/${bs} characters)`;try{return Yb(ae),null}catch(Te){return(Te==null?void 0:Te.message)||"Invalid message"}},dr=async ae=>{const Te=ae.trim();if(!(!Te&&ye.length===0)){if(Te){const Oe=an(Te);if(Oe){be(Oe);return}}try{await M({text:Te||"",attachments:ye,payload:ue?{edit:!0,originalMessageId:ue}:void 0},{checkpointId:pe??W??void 0,checkpointNs:we??z??void 0}),f==null||f(Te),be(null),q([]),gt(),D(null),fe("")}catch(Oe){const rt=(Oe==null?void 0:Oe.message)||"Failed to send message";be(rt),p==null||p(rt)}}},Nt=y.useCallback((ae,Te)=>{u&&(D(ae),fe(Te),be(null))},[u]),ln=y.useCallback(()=>{D(null),fe(""),be(null)},[]),Xt=y.useCallback((ae,Te)=>{Nt(ae,Te)},[Nt]),cn=y.useCallback(ae=>{const Te=Oe=>{const rt=Oe.content||[],Rt=rt.filter(I=>I.type==="text").map(I=>I.text).join("");if(Rt)return Rt;try{return JSON.stringify(rt,null,2)}catch{return String(rt)}};for(let Oe=ae-1;Oe>=0;Oe--)if(v[Oe].role==="user"){const rt=Te(v[Oe]);rt&&M({text:rt},{checkpointId:pe??W??void 0,checkpointNs:we??z??void 0});break}},[v,M,pe,we,W,z]),fr=ae=>{const Te=Array.from(ae.target.files||[]);q(Oe=>[...Oe,...Te]),ae.target.value=""},Or=ae=>{q(Te=>{const Oe=Te.filter((rt,Rt)=>ae!==Rt);return Oe.length===0&>(),Oe})},Mr=async ae=>{const Te=(ae.target.files||[])[0];if(Te){nt(null),Be(null),Ve(!0);try{await M({attachments:[Te]},{checkpointId:pe??W??void 0,checkpointNs:we??z??void 0});const Oe=`Uploaded ${Te.name} - processing through chat stream`;Be(Oe)}catch(Oe){const rt=Oe instanceof Error?Oe.message:"Failed to upload Excel file";console.error("Excel upload failed",Oe),nt(rt),p==null||p(rt)}finally{Ve(!1),ae.target.value="",gt()}}},hr=ae=>{if(!ae)return"Unknown";const Te=Date.parse(ae);return Number.isNaN(Te)?ae:new Date(Te).toLocaleString()},Nn=async ae=>{if(x){ze(!0);try{if(!ae){await A(),Ne(null),Ae(null);return}const Te=Z.find(rt=>rt.checkpointId===ae),Oe=(Te==null?void 0:Te.checkpointNs)??null;await E(ae,Oe),Ne(ae),Ae(Oe)}finally{ze(!1)}}},Dr=`flex flex-1 w-full flex-col min-h-0 min-w-0 max-h-full overflow-hidden bg-transparent ${e} ${d.container||""}`,An=`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||""}`,pr=`flex-shrink-0 w-full border-t p-4 bg-transparent ${d.inputArea||""}`;return c.jsxs("div",{className:Dr,children:[!!V&&!Ee&&c.jsxs("div",{className:"flex-shrink-0 bg-red-50 border border-red-200 text-red-800 px-4 py-2 text-sm flex items-center justify-between",children:[c.jsx("span",{children:V}),c.jsx(Ge,{variant:"ghost",size:"sm",onClick:()=>Ze(!0),className:"text-red-800 hover:bg-red-100","aria-label":"Dismiss error",children:c.jsx(ie.X,{size:16})})]}),x&&Z.length>0&&c.jsxs("div",{className:"flex-shrink-0 flex items-center gap-2 px-4 py-2 border-b border-border bg-muted/60 text-xs dark:bg-muted/50",children:[c.jsx("span",{className:"opacity-70",children:"Checkpoint:"}),c.jsxs("select",{className:"border border-border rounded px-2 py-1 text-xs bg-card text-foreground focus:outline-none focus:ring-1 focus:ring-ring dark:bg-secondary",value:pe??"",onChange:ae=>{const Te=ae.target.value||null;Nn(Te)},children:[c.jsx("option",{value:"",children:"Latest"}),Z.map(ae=>c.jsxs("option",{value:ae.checkpointId,children:[hr(ae.createdAt),ae.preview?` — ${ae.preview.slice(0,40)}`:""]},ae.checkpointId))]})]}),c.jsxs("div",{className:`relative ${An}`,style:r?{maxHeight:r}:void 0,children:[c.jsx(wa,{className:"h-full",style:{height:"100%"},messages:v,isStreaming:F,streamingAssistantId:$,streamingDebounceMs:typeof s=="number"?s:o,followNewMessages:i,layoutSize:ur,enableMessageEditing:u,editingMessageId:ue,onStartReached:()=>{Sn()},onEdit:Xt,onRegenerate:cn,onCancelEdit:ln,emptyMessage:wt??void 0,isNavigatingCheckpoint:Qe}),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(ie.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:pr,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(ie.Edit3,{size:16,className:"text-blue-600"}),c.jsx("span",{className:"text-sm font-medium text-blue-800",children:"Editing message"})]}),c.jsx(Ge,{variant:"ghost",size:"sm",onClick:ln,className:"text-blue-600 hover:bg-blue-100",children:c.jsx(ie.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:lt,type:"file",multiple:!0,onChange:ae=>fr(ae),className:"hidden"},O),ye.length>0&&c.jsx("div",{className:"flex flex-wrap gap-2",children:ye.map((ae,Te)=>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(ie.Paperclip,{size:14}),c.jsx("span",{className:"truncate max-w-[150px]",children:ae.name}),c.jsx(Ge,{variant:"ghost",size:"sm",onClick:()=>Or(Te),className:"h-4 w-4 p-0 text-gray-500 dark:text-gray-400 hover:text-red-500 dark:hover:text-red-400","aria-label":`Remove ${ae.name}`,children:c.jsx(ie.X,{size:12})})]},Te))})]}),l&&c.jsxs(c.Fragment,{children:[c.jsx("input",{ref:St,type:"file",accept:".xls,.xlsx,.xlsm",onChange:Mr,className:"hidden"},te),se&&c.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[c.jsx(ie.Loader2,{className:"h-4 w-4 animate-spin"})," Uploading Excel file..."]}),De&&!se&&c.jsx("div",{className:"text-sm rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-emerald-700",children:De}),Je&&!se&&c.jsx("div",{className:"text-sm rounded border border-red-200 bg-red-50 px-3 py-2 text-red-600",children:Je})]})]}),ve&&c.jsx("div",{className:"mb-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2",children:ve}),c.jsxs("div",{className:"flex items-end gap-2",children:[(a||l)&&c.jsxs(DS,{children:[c.jsx(LS,{asChild:!0,children:c.jsx(Ge,{type:"button",size:"icon",variant:"outline",disabled:F,title:"More input actions",className:d.moreButton||"",children:c.jsx(ie.Plus,{size:16})})}),c.jsxs(Nh,{align:"start",sideOffset:6,className:"w-52",children:[a&&c.jsxs(Wa,{onClick:()=>{var ae;return(ae=lt.current)==null?void 0:ae.click()},className:"cursor-pointer",children:[c.jsx(ie.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]}),l&&c.jsxs(Wa,{onClick:()=>{var ae;se||(ae=St.current)==null||ae.click()},className:`cursor-pointer ${se?"opacity-60 pointer-events-none":""}`,children:[c.jsx(ie.FileSpreadsheet,{className:"h-4 w-4 mr-2"})," Upload Excel file"]})]})]}),c.jsx("div",{className:"flex-1",children:c.jsx(lx,{initialValue:ee,editingMessageId:ue,placeholder:ue?"Edit your message...":t,isStreaming:F,disabled:!1,maxLength:bs,onSend:dr,onCancelEdit:ln,onStop:Y,allowEmptySend:ye.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":""} ${ve?"border-red-400":""} ${d.textarea||""}`})})]})]})]})}const $s=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}));$s.displayName="Input";function Va(e,[t,n]){return Math.min(n,Math.max(t,e))}function WS(e,t){return m.useReducer((n,r)=>t[n][r]??n,e)}var Ka="ScrollArea",[Ah,PT]=pn(Ka),[VS,Gt]=Ah(Ka),_h=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,type:r="hover",dir:o,scrollHideDelay:s=600,...i}=e,[a,l]=m.useState(null),[u,d]=m.useState(null),[f,h]=m.useState(null),[p,w]=m.useState(null),[x,g]=m.useState(null),[v,b]=m.useState(0),[S,N]=m.useState(0),[C,k]=m.useState(!1),[E,A]=m.useState(!1),j=We(t,L=>l(L)),P=ys(o);return c.jsx(VS,{scope:n,type:r,dir:P,scrollHideDelay:s,scrollArea:a,viewport:u,onViewportChange:d,content:f,onContentChange:h,scrollbarX:p,onScrollbarXChange:w,scrollbarXEnabled:C,onScrollbarXEnabledChange:k,scrollbarY:x,onScrollbarYChange:g,scrollbarYEnabled:E,onScrollbarYEnabledChange:A,onCornerWidthChange:b,onCornerHeightChange:N,children:c.jsx(je.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}})})});_h.displayName=Ka;var jh="ScrollAreaViewport",Rh=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,i=Gt(jh,n),a=m.useRef(null),l=We(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(je.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})})]})});Rh.displayName=jh;var yn="ScrollAreaScrollbar",qa=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Gt(yn,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(KS,{...r,ref:t,forceMount:n}):o.type==="scroll"?c.jsx(qS,{...r,ref:t,forceMount:n}):o.type==="auto"?c.jsx(Ph,{...r,ref:t,forceMount:n}):o.type==="always"?c.jsx(Ga,{...r,ref:t}):null});qa.displayName=yn;var KS=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Gt(yn,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(zt,{present:n||s,children:c.jsx(Ph,{"data-state":s?"visible":"hidden",...r,ref:t})})}),qS=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Gt(yn,e.__scopeScrollArea),s=e.orientation==="horizontal",i=Us(()=>l("SCROLL_END"),100),[a,l]=WS("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(zt,{present:n||a!=="hidden",children:c.jsx(Ga,{"data-state":a==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:de(e.onPointerEnter,()=>l("POINTER_ENTER")),onPointerLeave:de(e.onPointerLeave,()=>l("POINTER_LEAVE"))})})}),Ph=m.forwardRef((e,t)=>{const n=Gt(yn,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,i]=m.useState(!1),a=e.orientation==="horizontal",l=Us(()=>{if(n.viewport){const u=n.viewport.offsetWidth<n.viewport.scrollWidth,d=n.viewport.offsetHeight<n.viewport.scrollHeight;i(a?u:d)}},10);return _r(n.viewport,l),_r(n.content,l),c.jsx(zt,{present:r||s,children:c.jsx(Ga,{"data-state":s?"visible":"hidden",...o,ref:t})})}),Ga=m.forwardRef((e,t)=>{const{orientation:n="vertical",...r}=e,o=Gt(yn,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=Fh(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 QS(h,i.current,a,p)}return n==="horizontal"?c.jsx(GS,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollLeft,p=$h(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(YS,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollTop,p=$h(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}),GS=m.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=Gt(yn,e.__scopeScrollArea),[i,a]=m.useState(),l=m.useRef(null),u=We(t,l,s.onScrollbarXChange);return m.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),c.jsx(Mh,{"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":Hs(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),Bh(h,f)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollWidth,viewport:s.viewport.offsetWidth,scrollbar:{size:l.current.clientWidth,paddingStart:Bs(i.paddingLeft),paddingEnd:Bs(i.paddingRight)}})}})}),YS=m.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=Gt(yn,e.__scopeScrollArea),[i,a]=m.useState(),l=m.useRef(null),u=We(t,l,s.onScrollbarYChange);return m.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),c.jsx(Mh,{"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":Hs(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),Bh(h,f)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollHeight,viewport:s.viewport.offsetHeight,scrollbar:{size:l.current.clientHeight,paddingStart:Bs(i.paddingTop),paddingEnd:Bs(i.paddingBottom)}})}})}),[XS,Oh]=Ah(yn),Mh=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=Gt(yn,n),[w,x]=m.useState(null),g=We(t,j=>x(j)),v=m.useRef(null),b=m.useRef(""),S=p.viewport,N=r.content-r.viewport,C=yt(d),k=yt(l),E=Us(f,10);function A(j){if(v.current){const P=j.clientX-v.current.left,L=j.clientY-v.current.top;u({x:P,y:L})}}return m.useEffect(()=>{const j=P=>{const L=P.target;(w==null?void 0:w.contains(L))&&C(P,N)};return document.addEventListener("wheel",j,{passive:!1}),()=>document.removeEventListener("wheel",j,{passive:!1})},[S,w,N,C]),m.useEffect(k,[r,k]),_r(w,E),_r(p.content,E),c.jsx(XS,{scope:n,scrollbar:w,hasThumb:o,onThumbChange:yt(s),onThumbPointerUp:yt(i),onThumbPositionChange:k,onThumbPointerDown:yt(a),children:c.jsx(je.div,{...h,ref:g,style:{position:"absolute",...h.style},onPointerDown:de(e.onPointerDown,j=>{j.button===0&&(j.target.setPointerCapture(j.pointerId),v.current=w.getBoundingClientRect(),b.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",p.viewport&&(p.viewport.style.scrollBehavior="auto"),A(j))}),onPointerMove: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=b.current,p.viewport&&(p.viewport.style.scrollBehavior=""),v.current=null})})})}),zs="ScrollAreaThumb",Dh=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Oh(zs,e.__scopeScrollArea);return c.jsx(zt,{present:n||o.hasThumb,children:c.jsx(JS,{ref:t,...r})})}),JS=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=Gt(zs,n),i=Oh(zs,n),{onThumbPositionChange:a}=i,l=We(t,f=>i.onThumbChange(f)),u=m.useRef(void 0),d=Us(()=>{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=eC(f,a);u.current=p,a()}};return a(),f.addEventListener("scroll",h),()=>f.removeEventListener("scroll",h)}},[s.viewport,d,a]),c.jsx(je.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(),w=f.clientX-p.left,x=f.clientY-p.top;i.onThumbPointerDown({x:w,y:x})}),onPointerUp:de(e.onPointerUp,i.onThumbPointerUp)})});Dh.displayName=zs;var Ya="ScrollAreaCorner",Lh=m.forwardRef((e,t)=>{const n=Gt(Ya,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?c.jsx(ZS,{...e,ref:t}):null});Lh.displayName=Ya;var ZS=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=Gt(Ya,n),[s,i]=m.useState(0),[a,l]=m.useState(0),u=!!(s&&a);return _r(o.scrollbarX,()=>{var f;const d=((f=o.scrollbarX)==null?void 0:f.offsetHeight)||0;o.onCornerHeightChange(d),l(d)}),_r(o.scrollbarY,()=>{var f;const d=((f=o.scrollbarY)==null?void 0:f.offsetWidth)||0;o.onCornerWidthChange(d),i(d)}),u?c.jsx(je.div,{...r,ref:t,style:{width:s,height:a,position:"absolute",right:o.dir==="ltr"?0:void 0,left:o.dir==="rtl"?0:void 0,bottom:0,...e.style}}):null});function Bs(e){return e?parseInt(e,10):0}function Fh(e,t){const n=e/t;return isNaN(n)?0:n}function Hs(e){const t=Fh(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function QS(e,t,n,r="ltr"){const o=Hs(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 zh([l,u],f)(e)}function $h(e,t,n="ltr"){const r=Hs(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=Va(e,l);return zh([0,i],[0,a])(u)}function zh(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 Bh(e,t){return e>0&&e<t}var eC=(e,t=()=>{})=>{let n={left:e.scrollLeft,top:e.scrollTop},r=0;return function o(){const s={left:e.scrollLeft,top:e.scrollTop},i=n.left!==s.left,a=n.top!==s.top;(i||a)&&t(),n=s,r=window.requestAnimationFrame(o)}(),()=>window.cancelAnimationFrame(r)};function Us(e,t){const n=yt(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 _r(e,t){const n=yt(t);vt(()=>{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 Hh=_h,tC=Rh,nC=Lh;const Uh=m.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(Hh,{ref:r,className:Q("relative overflow-hidden",e),...n,children:[c.jsx(tC,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),c.jsx(Wh,{}),c.jsx(nC,{})]}));Uh.displayName=Hh.displayName;const Wh=m.forwardRef(({className:e,orientation:t="vertical",...n},r)=>c.jsx(qa,{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(Dh,{className:"relative flex-1 rounded-full bg-border"})}));Wh.displayName=qa.displayName;function Xa({className:e="",showCreateButton:t=!0,showDeleteButton:n=!0,showEditTitle:r=!0,maxHeight:o="400px",customStyles:s={},currentThreadId:i=null,navigateToThread:a,onThreadSelect:l,onThreadCreate:u,onThreadDelete:d}){const{threads:f,currentThreadId:h,isLoading:p,actions:w}=Ro(),{loadThread:x}=Po(),{createThread:g,deleteThread:v,renameThread:b}=w,[S,N]=y.useState(Array.isArray(f)?f:[]),C=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){C.current=!0,N(D);return}p||(C.current=!1,N(D))},[f,p]);const F=async D=>{try{await x(D),a==null||a(D),l==null||l(D)}catch(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)}},Y=(D,ee)=>{ee.stopPropagation(),E(D.threadId),j(D.title||`Thread ${D.threadId.slice(0,8)}`)},K=async D=>{if(A.trim())try{await b(D,A.trim()),E(null),j("")}catch(ee){console.error("Failed to update title:",ee)}},W=()=>{E(null),j("")},z=(D,ee)=>{D.key==="Enter"?K(ee):D.key==="Escape"&&W()},$=D=>{if(!D)return"";try{const ee=new Date(D),ve=new Date().getTime()-ee.getTime(),be=Math.floor(ve/(1e3*60*60*24));return be===0?ee.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):be===1?"Yesterday":be<7?`${be} 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(Ge,{onClick:V,disabled:P||p,className:s.createButton||"p-2",size:"sm",variant:"ghost",title:P?"Creating...":"New Chat",children:c.jsx(ie.MessageSquarePlus,{size:20})})}),c.jsx(Uh,{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(ie.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(ie.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:()=>F(D.threadId),className:`group relative p-3 rounded-lg cursor-pointer transition-colors border ${(i??h)===D.threadId?`${s.activeThread||"bg-slate-600 border-slate-500"} `:`${s.threadItem||"bg-slate-700 border-slate-600 hover:bg-slate-600 text-gray-900 dark:text-slate-100"}`} ${s.threadItem||""} text-gray-900 dark:text-slate-100`,children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("div",{className:"flex-1 min-w-0",children:k===D.threadId?c.jsxs("div",{className:"flex items-center gap-2",onClick:ee=>ee.stopPropagation(),children:[c.jsx($s,{value:A,onChange:ee=>j(ee.target.value),onKeyDown:ee=>z(ee,D.threadId),className:"h-6 text-sm",autoFocus:!0}),c.jsx(Ge,{variant:"ghost",size:"sm",onClick:()=>K(D.threadId),className:"h-6 w-6 p-0",children:c.jsx(ie.Check,{size:12})}),c.jsx(Ge,{variant:"ghost",size:"sm",onClick:W,className:"h-6 w-6 p-0",children:c.jsx(ie.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(ie.Calendar,{size:10}),c.jsx("span",{children:$(D.updatedAt||D.createdAt)})]})]})}),c.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity ml-2",children:[r&&k!==D.threadId&&c.jsx(Ge,{variant:"ghost",size:"sm",onClick:ee=>Y(D,ee),className:"h-6 w-6 p-0",title:"Edit title",children:c.jsx(ie.Edit3,{size:12})}),n&&c.jsx(Ge,{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(ie.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 jr(e){if(!(typeof globalThis>"u"))return globalThis[e]}function rC(e){if(typeof e!="string")return;const t=e.trim();if(t)return Tn(t)}function Vh(){const e=[jr("__API_BASE_URL__"),jr("__CHAT_API_BASE_URL__"),jr("__CHAT_API_URL__")];for(const t of e){const n=rC(t);if(n)return n}}function Kh(){const e=[jr("__API_AUTH_TOKEN__"),jr("__CHAT_API_KEY__"),jr("__CHAT_AUTH_TOKEN__")];for(const t of e)if(typeof t=="string"&&t.trim())return t.trim()}function qh(...e){for(const t of e)if(typeof t=="string"&&t.trim())return Tn(t);return Tn()}function Gh(){const e={},t=Vh(),n=Kh();return t&&(e.baseUrl=t),n&&(e.apiKey=n),e}function Yh(){const e=Gh(),t=jn.getAuthToken(),n=Vh();return{apiBaseUrl:qh(e.baseUrl,jn.baseUrl,n),apiKey:t||e.apiKey||Kh()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,truncateToolMessages:!0,toolMessagePreviewLength:200,darkMode:!1,enableSound:!1,messageHistory:100}}const Xh="chat-settings";function oC(){try{const e=localStorage.getItem(Xh);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function sC(e){try{const t={...e,apiBaseUrl:Tn(e.apiBaseUrl)};localStorage.setItem(Xh,JSON.stringify(t)),t.apiKey&&jn.setAuthToken(t.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function iC(){const e=Yh(),t=oC(),n=jn.getAuthToken(),r=typeof t.apiBaseUrl=="string"?t.apiBaseUrl:void 0;return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:qh(jn.baseUrl,r,e.apiBaseUrl)}}function aC(e){jn.updateConfig({baseUrl:e.apiBaseUrl,authToken:e.apiKey??void 0}),sC(e)}var lC="Label",Jh=m.forwardRef((e,t)=>c.jsx(je.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())}}));Jh.displayName=lC;var Zh=Jh;const cC=xo.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),Yt=m.forwardRef(({className:e,...t},n)=>c.jsx(Zh,{ref:n,className:Q(cC(),e),...t}));Yt.displayName=Zh.displayName;function Qh(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 Ws="Switch",[uC,OT]=pn(Ws),[dC,fC]=uC(Ws),ep=m.forwardRef((e,t)=>{const{__scopeSwitch:n,name:r,checked:o,defaultChecked:s,required:i,disabled:a,value:l="on",onCheckedChange:u,form:d,...f}=e,[h,p]=m.useState(null),w=We(t,S=>p(S)),x=m.useRef(!1),g=h?d||!!h.closest("form"):!0,[v,b]=Qn({prop:o,defaultProp:s??!1,onChange:u,caller:Ws});return c.jsxs(dC,{scope:n,checked:v,disabled:a,children:[c.jsx(je.button,{type:"button",role:"switch","aria-checked":v,"aria-required":i,"data-state":op(v),"data-disabled":a?"":void 0,disabled:a,value:l,...f,ref:w,onClick:de(e.onClick,S=>{b(N=>!N),g&&(x.current=S.isPropagationStopped(),x.current||S.stopPropagation())})}),g&&c.jsx(rp,{control:h,bubbles:!x.current,name:r,value:l,checked:v,required:i,disabled:a,form:d,style:{transform:"translateX(-100%)"}})]})});ep.displayName=Ws;var tp="SwitchThumb",np=m.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,o=fC(tp,n);return c.jsx(je.span,{"data-state":op(o.checked),"data-disabled":o.disabled?"":void 0,...r,ref:t})});np.displayName=tp;var hC="SwitchBubbleInput",rp=m.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...o},s)=>{const i=m.useRef(null),a=We(i,s),l=Qh(n),u=pf(t);return m.useEffect(()=>{const d=i.current;if(!d)return;const f=window.HTMLInputElement.prototype,p=Object.getOwnPropertyDescriptor(f,"checked").set;if(l!==n&&p){const w=new Event("click",{bubbles:r});p.call(d,n),d.dispatchEvent(w)}},[l,n,r]),c.jsx("input",{type:"checkbox","aria-hidden":!0,defaultChecked:n,...o,tabIndex:-1,ref:a,style:{...o.style,...u,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});rp.displayName=hC;function op(e){return e?"checked":"unchecked"}var sp=ep,pC=np;const Hn=m.forwardRef(({className:e,...t},n)=>c.jsx(sp,{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(pC,{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")})}));Hn.displayName=sp.displayName;var ip=Object.freeze({position:"absolute",border:0,width:1,height:1,padding:0,margin:-1,overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",wordWrap:"normal"}),mC="VisuallyHidden",gC=m.forwardRef((e,t)=>c.jsx(je.span,{...e,ref:t,style:{...ip,...e.style}}));gC.displayName=mC;var xC=[" ","Enter","ArrowUp","ArrowDown"],vC=[" ","Enter"],ar="Select",[Vs,Ks,wC]=ba(ar),[Rr,MT]=pn(ar,[wC,Rs]),qs=Rs(),[bC,Un]=Rr(ar),[yC,SC]=Rr(ar),ap=e=>{const{__scopeSelect:t,children:n,open:r,defaultOpen:o,onOpenChange:s,value:i,defaultValue:a,onValueChange:l,dir:u,name:d,autoComplete:f,disabled:h,required:p,form:w}=e,x=qs(t),[g,v]=m.useState(null),[b,S]=m.useState(null),[N,C]=m.useState(!1),k=ys(u),[E,A]=Qn({prop:r,defaultProp:o??!1,onChange:s,caller:ar}),[j,P]=Qn({prop:i,defaultProp:a,onChange:l,caller:ar}),L=m.useRef(null),F=g?w||!!g.closest("form"):!0,[V,M]=m.useState(new Set),Y=Array.from(V).map(K=>K.props.value).join(";");return c.jsx(Tf,{...x,children:c.jsxs(bC,{required:p,scope:t,trigger:g,onTriggerChange:v,valueNode:b,onValueNodeChange:S,valueNodeHasChildren:N,onValueNodeHasChildrenChange:C,contentId:mn(),value:j,onValueChange:P,open:E,onOpenChange:A,dir:k,triggerPointerDownPosRef:L,disabled:h,children:[c.jsx(Vs.Provider,{scope:t,children:c.jsx(yC,{scope:e.__scopeSelect,onNativeOptionAdd:m.useCallback(K=>{M(W=>new Set(W).add(K))},[]),onNativeOptionRemove:m.useCallback(K=>{M(W=>{const z=new Set(W);return z.delete(K),z})},[]),children:n})}),F?c.jsxs(jp,{"aria-hidden":!0,required:p,tabIndex:-1,name:d,autoComplete:f,value:j,onChange:K=>P(K.target.value),disabled:h,form:w,children:[j===void 0?c.jsx("option",{value:""}):null,Array.from(V)]},Y):null]})})};ap.displayName=ar;var lp="SelectTrigger",cp=m.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...o}=e,s=qs(n),i=Un(lp,n),a=i.disabled||r,l=We(t,i.onTriggerChange),u=Ks(n),d=m.useRef("touch"),[f,h,p]=Pp(x=>{const g=u().filter(S=>!S.disabled),v=g.find(S=>S.value===i.value),b=Op(g,x,v);b!==void 0&&i.onValueChange(b.value)}),w=x=>{a||(i.onOpenChange(!0),p()),x&&(i.triggerPointerDownPosRef.current={x:Math.round(x.pageX),y:Math.round(x.pageY)})};return c.jsx(kf,{asChild:!0,...s,children:c.jsx(je.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":Rp(i.value)?"":void 0,...o,ref:l,onClick:de(o.onClick,x=>{x.currentTarget.focus(),d.current!=="mouse"&&w(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"&&(w(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===" ")&&xC.includes(x.key)&&(w(),x.preventDefault())})})})});cp.displayName=lp;var up="SelectValue",dp=m.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,children:s,placeholder:i="",...a}=e,l=Un(up,n),{onValueNodeHasChildrenChange:u}=l,d=s!==void 0,f=We(t,l.onValueNodeChange);return vt(()=>{u(d)},[u,d]),c.jsx(je.span,{...a,ref:f,style:{pointerEvents:"none"},children:Rp(l.value)?c.jsx(c.Fragment,{children:i}):s})});dp.displayName=up;var CC="SelectIcon",fp=m.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...o}=e;return c.jsx(je.span,{"aria-hidden":!0,...o,ref:t,children:r||"▼"})});fp.displayName=CC;var TC="SelectPortal",hp=e=>c.jsx(ss,{asChild:!0,...e});hp.displayName=TC;var lr="SelectContent",pp=m.forwardRef((e,t)=>{const n=Un(lr,e.__scopeSelect),[r,o]=m.useState();if(vt(()=>{o(new DocumentFragment)},[]),!n.open){const s=r;return s?vo.createPortal(c.jsx(mp,{scope:e.__scopeSelect,children:c.jsx(Vs.Slot,{scope:e.__scopeSelect,children:c.jsx("div",{children:e.children})})}),s):null}return c.jsx(gp,{...e,ref:t})});pp.displayName=lr;var sn=10,[mp,Wn]=Rr(lr),kC="SelectContentImpl",IC=Vn.createSlot("SelectContent.RemoveScroll"),gp=m.forwardRef((e,t)=>{const{__scopeSelect:n,position:r="item-aligned",onCloseAutoFocus:o,onEscapeKeyDown:s,onPointerDownOutside:i,side:a,sideOffset:l,align:u,alignOffset:d,arrowPadding:f,collisionBoundary:h,collisionPadding:p,sticky:w,hideWhenDetached:x,avoidCollisions:g,...v}=e,b=Un(lr,n),[S,N]=m.useState(null),[C,k]=m.useState(null),E=We(t,q=>N(q)),[A,j]=m.useState(null),[P,L]=m.useState(null),F=Ks(n),[V,M]=m.useState(!1),Y=m.useRef(!1);m.useEffect(()=>{if(S)return pa(S)},[S]),la();const K=m.useCallback(q=>{const[O,...J]=F().map(se=>se.ref.current),[te]=J.slice(-1),G=document.activeElement;for(const se of q)if(se===G||(se==null||se.scrollIntoView({block:"nearest"}),se===O&&C&&(C.scrollTop=0),se===te&&C&&(C.scrollTop=C.scrollHeight),se==null||se.focus(),document.activeElement!==G))return},[F,C]),W=m.useCallback(()=>K([A,S]),[K,A,S]);m.useEffect(()=>{V&&W()},[V,W]);const{onOpenChange:z,triggerPointerDownPosRef:$}=b;m.useEffect(()=>{if(S){let q={x:0,y:0};const O=te=>{var G,se;q={x:Math.abs(Math.round(te.pageX)-(((G=$.current)==null?void 0:G.x)??0)),y:Math.abs(Math.round(te.pageY)-(((se=$.current)==null?void 0:se.y)??0))}},J=te=>{q.x<=10&&q.y<=10?te.preventDefault():S.contains(te.target)||z(!1),document.removeEventListener("pointermove",O),$.current=null};return $.current!==null&&(document.addEventListener("pointermove",O),document.addEventListener("pointerup",J,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",O),document.removeEventListener("pointerup",J,{capture:!0})}}},[S,z,$]),m.useEffect(()=>{const q=()=>z(!1);return window.addEventListener("blur",q),window.addEventListener("resize",q),()=>{window.removeEventListener("blur",q),window.removeEventListener("resize",q)}},[z]);const[ue,D]=Pp(q=>{const O=F().filter(G=>!G.disabled),J=O.find(G=>G.ref.current===document.activeElement),te=Op(O,q,J);te&&setTimeout(()=>te.ref.current.focus())}),ee=m.useCallback((q,O,J)=>{const te=!Y.current&&!J;(b.value!==void 0&&b.value===O||te)&&(j(q),te&&(Y.current=!0))},[b.value]),fe=m.useCallback(()=>S==null?void 0:S.focus(),[S]),ve=m.useCallback((q,O,J)=>{const te=!Y.current&&!J;(b.value!==void 0&&b.value===O||te)&&L(q)},[b.value]),be=r==="popper"?Ja:xp,ye=be===Ja?{side:a,sideOffset:l,align:u,alignOffset:d,arrowPadding:f,collisionBoundary:h,collisionPadding:p,sticky:w,hideWhenDetached:x,avoidCollisions:g}:{};return c.jsx(mp,{scope:n,content:S,viewport:C,onViewportChange:k,itemRefCallback:ee,selectedItem:A,onItemLeave:fe,itemTextRefCallback:ve,focusSelectedItem:W,selectedItemText:P,position:r,isPositioned:V,searchRef:ue,children:c.jsx(ds,{as:IC,allowPinchZoom:!0,children:c.jsx(os,{asChild:!0,trapped:b.open,onMountAutoFocus:q=>{q.preventDefault()},onUnmountAutoFocus:de(o,q=>{var O;(O=b.trigger)==null||O.focus({preventScroll:!0}),q.preventDefault()}),children:c.jsx(rs,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:q=>q.preventDefault(),onDismiss:()=>b.onOpenChange(!1),children:c.jsx(be,{role:"listbox",id:b.contentId,"data-state":b.open?"open":"closed",dir:b.dir,onContextMenu:q=>q.preventDefault(),...v,...ye,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=F().filter(G=>!G.disabled).map(G=>G.ref.current);if(["ArrowUp","End"].includes(q.key)&&(te=te.slice().reverse()),["ArrowUp","ArrowDown"].includes(q.key)){const G=q.target,se=te.indexOf(G);te=te.slice(se+1)}setTimeout(()=>K(te)),q.preventDefault()}})})})})})})});gp.displayName=kC;var EC="SelectItemAlignedPosition",xp=m.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...o}=e,s=Un(lr,n),i=Wn(lr,n),[a,l]=m.useState(null),[u,d]=m.useState(null),f=We(t,E=>d(E)),h=Ks(n),p=m.useRef(!1),w=m.useRef(!0),{viewport:x,selectedItem:g,selectedItemText:v,focusSelectedItem:b}=i,S=m.useCallback(()=>{if(s.trigger&&s.valueNode&&a&&u&&x&&g&&v){const E=s.trigger.getBoundingClientRect(),A=u.getBoundingClientRect(),j=s.valueNode.getBoundingClientRect(),P=v.getBoundingClientRect();if(s.dir!=="rtl"){const G=P.left-A.left,se=j.left-G,Ve=E.left-se,Je=E.width+Ve,nt=Math.max(Je,A.width),De=window.innerWidth-sn,Be=Va(se,[sn,Math.max(sn,De-nt)]);a.style.minWidth=Je+"px",a.style.left=Be+"px"}else{const G=A.right-P.right,se=window.innerWidth-j.right-G,Ve=window.innerWidth-E.right-se,Je=E.width+Ve,nt=Math.max(Je,A.width),De=window.innerWidth-sn,Be=Va(se,[sn,Math.max(sn,De-nt)]);a.style.minWidth=Je+"px",a.style.right=Be+"px"}const L=h(),F=window.innerHeight-sn*2,V=x.scrollHeight,M=window.getComputedStyle(u),Y=parseInt(M.borderTopWidth,10),K=parseInt(M.paddingTop,10),W=parseInt(M.borderBottomWidth,10),z=parseInt(M.paddingBottom,10),$=Y+K+V+z+W,ue=Math.min(g.offsetHeight*5,$),D=window.getComputedStyle(x),ee=parseInt(D.paddingTop,10),fe=parseInt(D.paddingBottom,10),ve=E.top+E.height/2-sn,be=F-ve,ye=g.offsetHeight/2,q=g.offsetTop+ye,O=Y+K+q,J=$-O;if(O<=ve){const G=L.length>0&&g===L[L.length-1].ref.current;a.style.bottom="0px";const se=u.clientHeight-x.offsetTop-x.offsetHeight,Ve=Math.max(be,ye+(G?fe:0)+se+W),Je=O+Ve;a.style.height=Je+"px"}else{const G=L.length>0&&g===L[0].ref.current;a.style.top="0px";const Ve=Math.max(ve,Y+x.offsetTop+(G?ee:0)+ye)+J;a.style.height=Ve+"px",x.scrollTop=O-ve+x.offsetTop}a.style.margin=`${sn}px 0`,a.style.minHeight=ue+"px",a.style.maxHeight=F+"px",r==null||r(),requestAnimationFrame(()=>p.current=!0)}},[h,s.trigger,s.valueNode,a,u,x,g,v,s.dir,r]);vt(()=>S(),[S]);const[N,C]=m.useState();vt(()=>{u&&C(window.getComputedStyle(u).zIndex)},[u]);const k=m.useCallback(E=>{E&&w.current===!0&&(S(),b==null||b(),w.current=!1)},[S,b]);return c.jsx(AC,{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(je.div,{...o,ref:f,style:{boxSizing:"border-box",maxHeight:"100%",...o.style}})})})});xp.displayName=EC;var NC="SelectPopperPosition",Ja=m.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=sn,...s}=e,i=qs(n);return c.jsx(If,{...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)"}})});Ja.displayName=NC;var[AC,Za]=Rr(lr,{}),Qa="SelectViewport",vp=m.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...o}=e,s=Wn(Qa,n),i=Za(Qa,n),a=We(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(Vs.Slot,{scope:n,children:c.jsx(je.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 w=window.innerHeight-sn*2,x=parseFloat(f.style.minHeight),g=parseFloat(f.style.height),v=Math.max(x,g);if(v<w){const b=v+p,S=Math.min(w,b),N=b-S;f.style.height=S+"px",f.style.bottom==="0px"&&(d.scrollTop=N>0?N:0,f.style.justifyContent="flex-end")}}}l.current=d.scrollTop})})})]})});vp.displayName=Qa;var wp="SelectGroup",[_C,jC]=Rr(wp),RC=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=mn();return c.jsx(_C,{scope:n,id:o,children:c.jsx(je.div,{role:"group","aria-labelledby":o,...r,ref:t})})});RC.displayName=wp;var bp="SelectLabel",yp=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=jC(bp,n);return c.jsx(je.div,{id:o.id,...r,ref:t})});yp.displayName=bp;var Gs="SelectItem",[PC,Sp]=Rr(Gs),Cp=m.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:s,...i}=e,a=Un(Gs,n),l=Wn(Gs,n),u=a.value===r,[d,f]=m.useState(s??""),[h,p]=m.useState(!1),w=We(t,b=>{var S;return(S=l.itemRefCallback)==null?void 0:S.call(l,b,r,o)}),x=mn(),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(PC,{scope:n,value:r,disabled:o,textId:x,isSelected:u,onItemTextChange:m.useCallback(b=>{f(S=>S||((b==null?void 0:b.textContent)??"").trim())},[]),children:c.jsx(Vs.ItemSlot,{scope:n,value:r,disabled:o,textValue:d,children:c.jsx(je.div,{role:"option","aria-labelledby":x,"data-highlighted":h?"":void 0,"aria-selected":u&&h,"data-state":u?"checked":"unchecked","aria-disabled":o||void 0,"data-disabled":o?"":void 0,tabIndex:o?void 0:-1,...i,ref:w,onFocus: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,b=>{g.current=b.pointerType}),onPointerMove:de(i.onPointerMove,b=>{var S;g.current=b.pointerType,o?(S=l.onItemLeave)==null||S.call(l):g.current==="mouse"&&b.currentTarget.focus({preventScroll:!0})}),onPointerLeave:de(i.onPointerLeave,b=>{var S;b.currentTarget===document.activeElement&&((S=l.onItemLeave)==null||S.call(l))}),onKeyDown:de(i.onKeyDown,b=>{var N;((N=l.searchRef)==null?void 0:N.current)!==""&&b.key===" "||(vC.includes(b.key)&&v(),b.key===" "&&b.preventDefault())})})})})});Cp.displayName=Gs;var go="SelectItemText",Tp=m.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,...s}=e,i=Un(go,n),a=Wn(go,n),l=Sp(go,n),u=SC(go,n),[d,f]=m.useState(null),h=We(t,v=>f(v),l.onItemTextChange,v=>{var b;return(b=a.itemTextRefCallback)==null?void 0:b.call(a,v,l.value,l.disabled)}),p=d==null?void 0:d.textContent,w=m.useMemo(()=>c.jsx("option",{value:l.value,disabled:l.disabled,children:p},l.value),[l.disabled,l.value,p]),{onNativeOptionAdd:x,onNativeOptionRemove:g}=u;return vt(()=>(x(w),()=>g(w)),[x,g,w]),c.jsxs(c.Fragment,{children:[c.jsx(je.span,{id:l.textId,...s,ref:h}),l.isSelected&&i.valueNode&&!i.valueNodeHasChildren?vo.createPortal(s.children,i.valueNode):null]})});Tp.displayName=go;var kp="SelectItemIndicator",Ip=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return Sp(kp,n).isSelected?c.jsx(je.span,{"aria-hidden":!0,...r,ref:t}):null});Ip.displayName=kp;var el="SelectScrollUpButton",Ep=m.forwardRef((e,t)=>{const n=Wn(el,e.__scopeSelect),r=Za(el,e.__scopeSelect),[o,s]=m.useState(!1),i=We(t,r.onScrollButtonChange);return vt(()=>{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(Ap,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop-l.offsetHeight)}}):null});Ep.displayName=el;var tl="SelectScrollDownButton",Np=m.forwardRef((e,t)=>{const n=Wn(tl,e.__scopeSelect),r=Za(tl,e.__scopeSelect),[o,s]=m.useState(!1),i=We(t,r.onScrollButtonChange);return vt(()=>{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(Ap,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop+l.offsetHeight)}}):null});Np.displayName=tl;var Ap=m.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...o}=e,s=Wn("SelectScrollButton",n),i=m.useRef(null),a=Ks(n),l=m.useCallback(()=>{i.current!==null&&(window.clearInterval(i.current),i.current=null)},[]);return m.useEffect(()=>()=>l(),[l]),vt(()=>{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(je.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()})})}),OC="SelectSeparator",_p=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return c.jsx(je.div,{"aria-hidden":!0,...r,ref:t})});_p.displayName=OC;var nl="SelectArrow",MC=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=qs(n),s=Un(nl,n),i=Wn(nl,n);return s.open&&i.position==="popper"?c.jsx(Ef,{...o,...r,ref:t}):null});MC.displayName=nl;var DC="SelectBubbleInput",jp=m.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const o=m.useRef(null),s=We(r,o),i=Qh(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(je.select,{...n,style:{...ip,...n.style},ref:s,defaultValue:t})});jp.displayName=DC;function Rp(e){return e===""||e===void 0}function Pp(e){const t=yt(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 Op(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=LC(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 LC(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var FC=ap,Mp=cp,$C=dp,zC=fp,BC=hp,Dp=pp,HC=vp,Lp=yp,Fp=Cp,UC=Tp,WC=Ip,$p=Ep,zp=Np,Bp=_p;const Hp=FC,Up=$C,rl=m.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(Mp,{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(zC,{asChild:!0,children:c.jsx(ie.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));rl.displayName=Mp.displayName;const Wp=m.forwardRef(({className:e,...t},n)=>c.jsx($p,{ref:n,className:Q("flex cursor-default items-center justify-center py-1",e),...t,children:c.jsx(ie.ChevronUp,{className:"h-4 w-4"})}));Wp.displayName=$p.displayName;const Vp=m.forwardRef(({className:e,...t},n)=>c.jsx(zp,{ref:n,className:Q("flex cursor-default items-center justify-center py-1",e),...t,children:c.jsx(ie.ChevronDown,{className:"h-4 w-4"})}));Vp.displayName=zp.displayName;const ol=m.forwardRef(({className:e,children:t,position:n="popper",...r},o)=>c.jsx(BC,{children:c.jsxs(Dp,{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(Wp,{}),c.jsx(HC,{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(Vp,{})]})}));ol.displayName=Dp.displayName;const VC=m.forwardRef(({className:e,...t},n)=>c.jsx(Lp,{ref:n,className:Q("py-1.5 pl-8 pr-2 text-sm font-semibold",e),...t}));VC.displayName=Lp.displayName;const cr=m.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(Fp,{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(WC,{children:c.jsx(ie.Check,{className:"h-4 w-4"})})}),c.jsx(UC,{children:t})]}));cr.displayName=Fp.displayName;const KC=m.forwardRef(({className:e,...t},n)=>c.jsx(Bp,{ref:n,className:Q("-mx-1 my-1 h-px bg-muted",e),...t}));KC.displayName=Bp.displayName;var qC="Separator",Kp="horizontal",GC=["horizontal","vertical"],qp=m.forwardRef((e,t)=>{const{decorative:n,orientation:r=Kp,...o}=e,s=YC(r)?r:Kp,a=n?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return c.jsx(je.div,{"data-orientation":s,...a,...o,ref:t})});qp.displayName=qC;function YC(e){return GC.includes(e)}var Gp=qp;const Yp=m.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},o)=>c.jsx(Gp,{ref:o,decorative:n,orientation:t,className:Q("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));Yp.displayName=Gp.displayName;const XC=jd,JC=_b,ZC=Rd,Xp=m.forwardRef(({className:e,...t},n)=>c.jsx(gs,{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}));Xp.displayName=gs.displayName;const QC=xo.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"}}),Jp=m.forwardRef(({side:e="right",className:t,children:n,...r},o)=>c.jsxs(ZC,{children:[c.jsx(Xp,{}),c.jsxs(xs,{ref:o,className:Q(QC({side:e}),t),...r,children:[n,c.jsxs(Pd,{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(ie.X,{className:"h-4 w-4"}),c.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));Jp.displayName=xs.displayName;const Zp=({className:e,...t})=>c.jsx("div",{className:Q("flex flex-col space-y-2 text-center sm:text-left",e),...t});Zp.displayName="SheetHeader";const Qp=m.forwardRef(({className:e,...t},n)=>c.jsx(nr,{ref:n,className:Q("text-lg font-semibold text-foreground",e),...t}));Qp.displayName=nr.displayName;const em=m.forwardRef(({className:e,...t},n)=>c.jsx(vs,{ref:n,className:Q("text-sm text-muted-foreground",e),...t}));em.displayName=vs.displayName;const eT={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 tT({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}=ra();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(eT),d(!0),f({title:"Settings reset",description:"Configuration has been reset to defaults."})},w=()=>{l(e),d(!1),o(!1)},x=async()=>{try{const v=await(await fetch(`${a.api.baseUrl}/health`)).json();f({title:"Connection successful",description:`API is ${v.status||"healthy"}`})}catch{f({title:"Connection failed",description:"Unable to connect to the API endpoint.",variant:"destructive"})}};return c.jsxs(XC,{open:r,onOpenChange:o,children:[c.jsx(JC,{asChild:!0,children:c.jsxs(Ge,{variant:"outline",size:"sm",className:n,children:[c.jsx(ie.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(Jp,{className:"w-[500px] sm:w-[600px] overflow-y-auto",children:[c.jsxs(Zp,{children:[c.jsx(Qp,{children:"Chat Settings"}),c.jsx(em,{children:"Configure your chat interface, API connection, and behavior preferences."})]}),c.jsxs("div",{className:"space-y-6 py-6",children:[c.jsxs(to,{children:[c.jsx(no,{className:"pb-3",children:c.jsxs(ro,{className:"text-lg flex items-center gap-2",children:[c.jsx(ie.Server,{className:"h-5 w-5"}),"API Configuration"]})}),c.jsxs(Xo,{className:"space-y-4",children:[c.jsxs("div",{className:"space-y-2",children:[c.jsx(Yt,{htmlFor:"api-url",children:"API Base URL"}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx($s,{id:"api-url",value:a.api.baseUrl,onChange:g=>l(v=>({...v,api:{...v.api,baseUrl:g.target.value}})),placeholder:"http://localhost:8000/api"}),c.jsx(Ge,{variant:"outline",onClick:x,children:"Test"})]})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx(Yt,{htmlFor:"enable-auth",children:"Enable Authentication"}),c.jsx(Hn,{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(Yt,{htmlFor:"auth-token",children:"Authentication Token"}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx($s,{id:"auth-token",type:s?"text":"password",value:a.api.authToken,onChange:g=>l(v=>({...v,api:{...v.api,authToken:g.target.value}})),placeholder:"Enter your Bearer token"}),c.jsx(Ge,{variant:"outline",size:"icon",onClick:()=>i(!s),children:s?c.jsx(ie.EyeOff,{className:"h-4 w-4"}):c.jsx(ie.Eye,{className:"h-4 w-4"})})]})]})]})]}),c.jsxs(to,{children:[c.jsx(no,{className:"pb-3",children:c.jsxs(ro,{className:"text-lg flex items-center gap-2",children:[c.jsx(ie.Layout,{className:"h-5 w-5"}),"Interface Settings"]})}),c.jsxs(Xo,{className:"space-y-4",children:[c.jsxs("div",{className:"space-y-2",children:[c.jsx(Yt,{htmlFor:"layout",children:"Layout Style"}),c.jsxs(Hp,{value:a.ui.layout,onValueChange:g=>l(v=>({...v,ui:{...v.ui,layout:g}})),children:[c.jsx(rl,{children:c.jsx(Up,{})}),c.jsxs(ol,{children:[c.jsx(cr,{value:"sidebar",children:"Sidebar Layout"}),c.jsx(cr,{value:"fullscreen",children:"Fullscreen"}),c.jsx(cr,{value:"tabs",children:"Tabbed Interface"})]})]})]}),c.jsxs("div",{className:"space-y-2",children:[c.jsx(Yt,{htmlFor:"theme",children:"Theme"}),c.jsxs(Hp,{value:a.ui.theme,onValueChange:g=>l(v=>({...v,ui:{...v.ui,theme:g}})),children:[c.jsx(rl,{children:c.jsx(Up,{})}),c.jsxs(ol,{children:[c.jsx(cr,{value:"light",children:"Light"}),c.jsx(cr,{value:"dark",children:"Dark"}),c.jsx(cr,{value:"system",children:"System"})]})]})]}),c.jsx(Yp,{}),c.jsxs("div",{className:"space-y-3",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx(Yt,{htmlFor:"show-timestamps",children:"Show Timestamps"}),c.jsx(Hn,{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(Yt,{htmlFor:"show-agent-names",children:"Show Agent Names"}),c.jsx(Hn,{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(Yt,{htmlFor:"compact-messages",children:"Compact Messages"}),c.jsx(Hn,{id:"compact-messages",checked:a.ui.compactMessages,onCheckedChange:g=>l(v=>({...v,ui:{...v.ui,compactMessages:g}}))})]})]})]})]}),c.jsxs(to,{children:[c.jsx(no,{className:"pb-3",children:c.jsxs(ro,{className:"text-lg flex items-center gap-2",children:[c.jsx(ie.MessageCircle,{className:"h-5 w-5"}),"Behavior Settings"]})}),c.jsxs(Xo,{className:"space-y-4",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx(Yt,{htmlFor:"auto-save",children:"Auto-save Conversations"}),c.jsx("p",{className:"text-sm text-muted-foreground",children:"Automatically save messages to threads"})]}),c.jsx(Hn,{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(Yt,{htmlFor:"enable-streaming",children:"Enable Streaming"}),c.jsx("p",{className:"text-sm text-muted-foreground",children:"Stream responses in real-time"})]}),c.jsx(Hn,{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(Yt,{htmlFor:"typing-indicator",children:"Typing Indicator"}),c.jsx("p",{className:"text-sm text-muted-foreground",children:"Show typing indicator during responses"})]}),c.jsx(Hn,{id:"typing-indicator",checked:a.behavior.showTypingIndicator,onCheckedChange:g=>l(v=>({...v,behavior:{...v.behavior,showTypingIndicator:g}}))})]})]})]})]}),c.jsxs("div",{className:"flex items-center justify-between pt-6 border-t",children:[c.jsxs(Ge,{variant:"outline",onClick:p,children:[c.jsx(ie.RotateCcw,{className:"h-4 w-4 mr-2"}),"Reset"]}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx(Ge,{variant:"outline",onClick:w,children:"Cancel"}),c.jsxs(Ge,{onClick:h,disabled:!u,children:[c.jsx(ie.Save,{className:"h-4 w-4 mr-2"}),"Save Changes"]})]})]})]})]})}function nT({layout:e="sidebar",layoutSize:t="desktop",showThreads:n=!0,className:r="",customStyles:o={},...s}){const i=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(Oo,{...s,onThreadChange:l,children:c.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:c.jsx(Fs,{className:"flex-1",onError:s.onError,enableFileUpload:!0})})}):e==="tabs"?c.jsx(Oo,{...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(Xa,{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(Fs,{onError:s.onError,enableFileUpload:!0})})]})})}):c.jsx(Oo,{...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(Xa,{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(Fs,{onError:s.onError,enableFileUpload:!0})})]})})}Re.ChatApi=ec,Re.ChatInterface=Fs,Re.ChatProviders=Oo,Re.ChatSettings=tT,Re.MarkdownContent=ea,Re.MessageComponent=Hd,Re.MessageList=wa,Re.ThreadManager=Xa,Re.applySettings=aC,Re.chatApiClient=jn,Re.default=nT,Re.del=Ql,Re.get=Dt,Re.getChatToken=Xl,Re.getCurrentSettings=iC,Re.getDefaultApiConfig=Gh,Re.getDefaultChatSettings=Yh,Re.onChatTokenChanged=Jl,Re.post=hi,Re.put=Zl,Re.setChatToken=fi,Re.useApi=pi,Re.useChatStream=pc,Re.useMessagesReducer=sc,Re.useStream=yc,Re.useThreadState=Po,Re.useThreads=Ro,Object.defineProperties(Re,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
140
|
+
`).trim():n.replace(/</g,"<").replace(/>/g,">").trim()}function ey(e,t=Cs){if(!e||typeof e!="string")throw new Error("Invalid content: must be a non-empty string");if(e.length>t)throw new Error(`Message exceeds maximum length of ${t} characters`);return e}function ty(e){let t;return typeof e=="string"?t=e:typeof e=="object"&&e!==null?t=JSON.stringify(e):t=String(e),ey(t),Qb(t)}function ka(e){const t=e+"CollectionProvider",[n,r]=xn(t),[o,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),i=x=>{const{scope:g,children:v}=x,b=y.useRef(null),S=y.useRef(new Map).current;return c.jsx(o,{scope:g,itemMap:S,collectionRef:b,children:v})};i.displayName=t;const a=e+"CollectionSlot",l=Xn.createSlot(a),u=y.forwardRef((x,g)=>{const{scope:v,children:b}=x,S=s(a,v),N=Ve(g,S.collectionRef);return c.jsx(l,{ref:N,children:b})});u.displayName=a;const d=e+"CollectionItemSlot",f="data-radix-collection-item",h=Xn.createSlot(d),p=y.forwardRef((x,g)=>{const{scope:v,children:b,...S}=x,N=y.useRef(null),C=Ve(g,N),k=s(d,v);return y.useEffect(()=>(k.itemMap.set(N,{ref:N,...S}),()=>void k.itemMap.delete(N))),c.jsx(h,{[f]:"",ref:C,children:b})});p.displayName=d;function w(x){const g=s(e+"CollectionConsumer",x);return y.useCallback(()=>{const b=g.collectionRef.current;if(!b)return[];const S=Array.from(b.querySelectorAll(`[${f}]`));return Array.from(g.itemMap.values()).sort((k,I)=>S.indexOf(k.ref.current)-S.indexOf(I.ref.current))},[g.collectionRef,g.itemMap])}return[{Provider:i,Slot:u,ItemSlot:p},w,r]}var ny=m.createContext(void 0);function Ts(e){const t=m.useContext(ny);return e||t||"ltr"}const ry=["top","right","bottom","left"],zn=Math.min,zt=Math.max,ks=Math.round,Es=Math.floor,bn=e=>({x:e,y:e}),oy={left:"right",right:"left",bottom:"top",top:"bottom"},sy={start:"end",end:"start"};function Ea(e,t,n){return zt(e,zn(t,n))}function Nn(e,t){return typeof e=="function"?e(t):e}function An(e){return e.split("-")[0]}function Nr(e){return e.split("-")[1]}function Ia(e){return e==="x"?"y":"x"}function Na(e){return e==="y"?"height":"width"}const iy=new Set(["top","bottom"]);function yn(e){return iy.has(An(e))?"y":"x"}function Aa(e){return Ia(yn(e))}function ay(e,t,n){n===void 0&&(n=!1);const r=Nr(e),o=Aa(e),s=Na(o);let i=o==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(i=Is(i)),[i,Is(i)]}function ly(e){const t=Is(e);return[_a(e),t,_a(t)]}function _a(e){return e.replace(/start|end/g,t=>sy[t])}const Yd=["left","right"],Xd=["right","left"],cy=["top","bottom"],uy=["bottom","top"];function dy(e,t,n){switch(e){case"top":case"bottom":return n?t?Xd:Yd:t?Yd:Xd;case"left":case"right":return t?cy:uy;default:return[]}}function fy(e,t,n,r){const o=Nr(e);let s=dy(An(e),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(_a)))),s}function Is(e){return e.replace(/left|right|bottom|top/g,t=>oy[t])}function hy(e){return{top:0,right:0,bottom:0,left:0,...e}}function Jd(e){return typeof e!="number"?hy(e):{top:e,right:e,bottom:e,left:e}}function Ns(e){const{x:t,y:n,width:r,height:o}=e;return{width:r,height:o,top:n,left:t,right:t+r,bottom:n+o,x:t,y:n}}function Zd(e,t,n){let{reference:r,floating:o}=e;const s=yn(t),i=Aa(t),a=Na(i),l=An(t),u=s==="y",d=r.x+r.width/2-o.width/2,f=r.y+r.height/2-o.height/2,h=r[a]/2-o[a]/2;let p;switch(l){case"top":p={x:d,y:r.y-o.height};break;case"bottom":p={x:d,y:r.y+r.height};break;case"right":p={x:r.x+r.width,y:f};break;case"left":p={x:r.x-o.width,y:f};break;default:p={x:r.x,y:r.y}}switch(Nr(t)){case"start":p[i]-=h*(n&&u?-1:1);break;case"end":p[i]+=h*(n&&u?-1:1);break}return p}const py=async(e,t,n)=>{const{placement:r="bottom",strategy:o="absolute",middleware:s=[],platform:i}=n,a=s.filter(Boolean),l=await(i.isRTL==null?void 0:i.isRTL(t));let u=await i.getElementRects({reference:e,floating:t,strategy:o}),{x:d,y:f}=Zd(u,r,l),h=r,p={},w=0;for(let x=0;x<a.length;x++){const{name:g,fn:v}=a[x],{x:b,y:S,data:N,reset:C}=await v({x:d,y:f,initialPlacement:r,placement:h,strategy:o,middlewareData:p,rects:u,platform:i,elements:{reference:e,floating:t}});d=b??d,f=S??f,p={...p,[g]:{...p[g],...N}},C&&w<=50&&(w++,typeof C=="object"&&(C.placement&&(h=C.placement),C.rects&&(u=C.rects===!0?await i.getElementRects({reference:e,floating:t,strategy:o}):C.rects),{x:d,y:f}=Zd(u,h,l)),x=-1)}return{x:d,y:f,placement:h,strategy:o,middlewareData:p}};async function lo(e,t){var n;t===void 0&&(t={});const{x:r,y:o,platform:s,rects:i,elements:a,strategy:l}=e,{boundary:u="clippingAncestors",rootBoundary:d="viewport",elementContext:f="floating",altBoundary:h=!1,padding:p=0}=Nn(t,e),w=Jd(p),g=a[h?f==="floating"?"reference":"floating":f],v=Ns(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(g)))==null||n?g:g.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(a.floating)),boundary:u,rootBoundary:d,strategy:l})),b=f==="floating"?{x:r,y:o,width:i.floating.width,height:i.floating.height}:i.reference,S=await(s.getOffsetParent==null?void 0:s.getOffsetParent(a.floating)),N=await(s.isElement==null?void 0:s.isElement(S))?await(s.getScale==null?void 0:s.getScale(S))||{x:1,y:1}:{x:1,y:1},C=Ns(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:b,offsetParent:S,strategy:l}):b);return{top:(v.top-C.top+w.top)/N.y,bottom:(C.bottom-v.bottom+w.bottom)/N.y,left:(v.left-C.left+w.left)/N.x,right:(C.right-v.right+w.right)/N.x}}const my=e=>({name:"arrow",options:e,async fn(t){const{x:n,y:r,placement:o,rects:s,platform:i,elements:a,middlewareData:l}=t,{element:u,padding:d=0}=Nn(e,t)||{};if(u==null)return{};const f=Jd(d),h={x:n,y:r},p=Aa(o),w=Na(p),x=await i.getDimensions(u),g=p==="y",v=g?"top":"left",b=g?"bottom":"right",S=g?"clientHeight":"clientWidth",N=s.reference[w]+s.reference[p]-h[p]-s.floating[w],C=h[p]-s.reference[p],k=await(i.getOffsetParent==null?void 0:i.getOffsetParent(u));let I=k?k[S]:0;(!I||!await(i.isElement==null?void 0:i.isElement(k)))&&(I=a.floating[S]||s.floating[w]);const A=N/2-C/2,j=I/2-x[w]/2-1,P=zn(f[v],j),L=zn(f[b],j),F=P,V=I-x[w]-L,M=I/2-x[w]/2+A,G=Ea(F,M,V),q=!l.arrow&&Nr(o)!=null&&M!==G&&s.reference[w]/2-(M<F?P:L)-x[w]/2<0,U=q?M<F?M-F:M-V:0;return{[p]:h[p]+U,data:{[p]:G,centerOffset:M-G-U,...q&&{alignmentOffset:U}},reset:q}}}),gy=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(t){var n,r;const{placement:o,middlewareData:s,rects:i,initialPlacement:a,platform:l,elements:u}=t,{mainAxis:d=!0,crossAxis:f=!0,fallbackPlacements:h,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:w="none",flipAlignment:x=!0,...g}=Nn(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const v=An(o),b=yn(a),S=An(a)===a,N=await(l.isRTL==null?void 0:l.isRTL(u.floating)),C=h||(S||!x?[Is(a)]:ly(a)),k=w!=="none";!h&&k&&C.push(...fy(a,x,w,N));const I=[a,...C],A=await lo(t,g),j=[];let P=((r=s.flip)==null?void 0:r.overflows)||[];if(d&&j.push(A[v]),f){const M=ay(o,i,N);j.push(A[M[0]],A[M[1]])}if(P=[...P,{placement:o,overflows:j}],!j.every(M=>M<=0)){var L,F;const M=(((L=s.flip)==null?void 0:L.index)||0)+1,G=I[M];if(G&&(!(f==="alignment"?b!==yn(G):!1)||P.every(B=>yn(B.placement)===b?B.overflows[0]>0:!0)))return{data:{index:M,overflows:P},reset:{placement:G}};let q=(F=P.filter(U=>U.overflows[0]<=0).sort((U,B)=>U.overflows[1]-B.overflows[1])[0])==null?void 0:F.placement;if(!q)switch(p){case"bestFit":{var V;const U=(V=P.filter(B=>{if(k){const $=yn(B.placement);return $===b||$==="y"}return!0}).map(B=>[B.placement,B.overflows.filter($=>$>0).reduce(($,ce)=>$+ce,0)]).sort((B,$)=>B[1]-$[1])[0])==null?void 0:V[0];U&&(q=U);break}case"initialPlacement":q=a;break}if(o!==q)return{reset:{placement:q}}}return{}}}};function Qd(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function ef(e){return ry.some(t=>e[t]>=0)}const xy=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n}=t,{strategy:r="referenceHidden",...o}=Nn(e,t);switch(r){case"referenceHidden":{const s=await lo(t,{...o,elementContext:"reference"}),i=Qd(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:ef(i)}}}case"escaped":{const s=await lo(t,{...o,altBoundary:!0}),i=Qd(s,n.floating);return{data:{escapedOffsets:i,escaped:ef(i)}}}default:return{}}}}},tf=new Set(["left","top"]);async function vy(e,t){const{placement:n,platform:r,elements:o}=e,s=await(r.isRTL==null?void 0:r.isRTL(o.floating)),i=An(n),a=Nr(n),l=yn(n)==="y",u=tf.has(i)?-1:1,d=s&&l?-1:1,f=Nn(t,e);let{mainAxis:h,crossAxis:p,alignmentAxis:w}=typeof f=="number"?{mainAxis:f,crossAxis:0,alignmentAxis:null}:{mainAxis:f.mainAxis||0,crossAxis:f.crossAxis||0,alignmentAxis:f.alignmentAxis};return a&&typeof w=="number"&&(p=a==="end"?w*-1:w),l?{x:p*d,y:h*u}:{x:h*u,y:p*d}}const wy=function(e){return e===void 0&&(e=0),{name:"offset",options:e,async fn(t){var n,r;const{x:o,y:s,placement:i,middlewareData:a}=t,l=await vy(t,e);return i===((n=a.offset)==null?void 0:n.placement)&&(r=a.arrow)!=null&&r.alignmentOffset?{}:{x:o+l.x,y:s+l.y,data:{...l,placement:i}}}}},by=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(t){const{x:n,y:r,placement:o}=t,{mainAxis:s=!0,crossAxis:i=!1,limiter:a={fn:g=>{let{x:v,y:b}=g;return{x:v,y:b}}},...l}=Nn(e,t),u={x:n,y:r},d=await lo(t,l),f=yn(An(o)),h=Ia(f);let p=u[h],w=u[f];if(s){const g=h==="y"?"top":"left",v=h==="y"?"bottom":"right",b=p+d[g],S=p-d[v];p=Ea(b,p,S)}if(i){const g=f==="y"?"top":"left",v=f==="y"?"bottom":"right",b=w+d[g],S=w-d[v];w=Ea(b,w,S)}const x=a.fn({...t,[h]:p,[f]:w});return{...x,data:{x:x.x-n,y:x.y-r,enabled:{[h]:s,[f]:i}}}}}},yy=function(e){return e===void 0&&(e={}),{options:e,fn(t){const{x:n,y:r,placement:o,rects:s,middlewareData:i}=t,{offset:a=0,mainAxis:l=!0,crossAxis:u=!0}=Nn(e,t),d={x:n,y:r},f=yn(o),h=Ia(f);let p=d[h],w=d[f];const x=Nn(a,t),g=typeof x=="number"?{mainAxis:x,crossAxis:0}:{mainAxis:0,crossAxis:0,...x};if(l){const S=h==="y"?"height":"width",N=s.reference[h]-s.floating[S]+g.mainAxis,C=s.reference[h]+s.reference[S]-g.mainAxis;p<N?p=N:p>C&&(p=C)}if(u){var v,b;const S=h==="y"?"width":"height",N=tf.has(An(o)),C=s.reference[f]-s.floating[S]+(N&&((v=i.offset)==null?void 0:v[f])||0)+(N?0:g.crossAxis),k=s.reference[f]+s.reference[S]+(N?0:((b=i.offset)==null?void 0:b[f])||0)-(N?g.crossAxis:0);w<C?w=C:w>k&&(w=k)}return{[h]:p,[f]:w}}}},Sy=function(e){return e===void 0&&(e={}),{name:"size",options:e,async fn(t){var n,r;const{placement:o,rects:s,platform:i,elements:a}=t,{apply:l=()=>{},...u}=Nn(e,t),d=await lo(t,u),f=An(o),h=Nr(o),p=yn(o)==="y",{width:w,height:x}=s.floating;let g,v;f==="top"||f==="bottom"?(g=f,v=h===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(v=f,g=h==="end"?"top":"bottom");const b=x-d.top-d.bottom,S=w-d.left-d.right,N=zn(x-d[g],b),C=zn(w-d[v],S),k=!t.middlewareData.shift;let I=N,A=C;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(A=S),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(I=b),k&&!h){const P=zt(d.left,0),L=zt(d.right,0),F=zt(d.top,0),V=zt(d.bottom,0);p?A=w-2*(P!==0||L!==0?P+L:zt(d.left,d.right)):I=x-2*(F!==0||V!==0?F+V:zt(d.top,d.bottom))}await l({...t,availableWidth:A,availableHeight:I});const j=await i.getDimensions(a.floating);return w!==j.width||x!==j.height?{reset:{rects:!0}}:{}}}};function As(){return typeof window<"u"}function Ar(e){return nf(e)?(e.nodeName||"").toLowerCase():"#document"}function Ht(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function Sn(e){var t;return(t=(nf(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function nf(e){return As()?e instanceof Node||e instanceof Ht(e).Node:!1}function ln(e){return As()?e instanceof Element||e instanceof Ht(e).Element:!1}function Cn(e){return As()?e instanceof HTMLElement||e instanceof Ht(e).HTMLElement:!1}function rf(e){return!As()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Ht(e).ShadowRoot}const Cy=new Set(["inline","contents"]);function co(e){const{overflow:t,overflowX:n,overflowY:r,display:o}=cn(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!Cy.has(o)}const Ty=new Set(["table","td","th"]);function ky(e){return Ty.has(Ar(e))}const Ey=[":popover-open",":modal"];function _s(e){return Ey.some(t=>{try{return e.matches(t)}catch{return!1}})}const Iy=["transform","translate","scale","rotate","perspective"],Ny=["transform","translate","scale","rotate","perspective","filter"],Ay=["paint","layout","strict","content"];function ja(e){const t=Ra(),n=ln(e)?cn(e):e;return Iy.some(r=>n[r]?n[r]!=="none":!1)||(n.containerType?n.containerType!=="normal":!1)||!t&&(n.backdropFilter?n.backdropFilter!=="none":!1)||!t&&(n.filter?n.filter!=="none":!1)||Ny.some(r=>(n.willChange||"").includes(r))||Ay.some(r=>(n.contain||"").includes(r))}function _y(e){let t=Hn(e);for(;Cn(t)&&!_r(t);){if(ja(t))return t;if(_s(t))return null;t=Hn(t)}return null}function Ra(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const jy=new Set(["html","body","#document"]);function _r(e){return jy.has(Ar(e))}function cn(e){return Ht(e).getComputedStyle(e)}function js(e){return ln(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Hn(e){if(Ar(e)==="html")return e;const t=e.assignedSlot||e.parentNode||rf(e)&&e.host||Sn(e);return rf(t)?t.host:t}function of(e){const t=Hn(e);return _r(t)?e.ownerDocument?e.ownerDocument.body:e.body:Cn(t)&&co(t)?t:of(t)}function uo(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const o=of(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=Ht(o);if(s){const a=Pa(i);return t.concat(i,i.visualViewport||[],co(o)?o:[],a&&n?uo(a):[])}return t.concat(o,uo(o,[],n))}function Pa(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function sf(e){const t=cn(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const o=Cn(e),s=o?e.offsetWidth:n,i=o?e.offsetHeight:r,a=ks(n)!==s||ks(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function Oa(e){return ln(e)?e:e.contextElement}function jr(e){const t=Oa(e);if(!Cn(t))return bn(1);const n=t.getBoundingClientRect(),{width:r,height:o,$:s}=sf(t);let i=(s?ks(n.width):n.width)/r,a=(s?ks(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const Ry=bn(0);function af(e){const t=Ht(e);return!Ra()||!t.visualViewport?Ry:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function Py(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==Ht(e)?!1:t}function cr(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const o=e.getBoundingClientRect(),s=Oa(e);let i=bn(1);t&&(r?ln(r)&&(i=jr(r)):i=jr(e));const a=Py(s,n,r)?af(s):bn(0);let l=(o.left+a.x)/i.x,u=(o.top+a.y)/i.y,d=o.width/i.x,f=o.height/i.y;if(s){const h=Ht(s),p=r&&ln(r)?Ht(r):r;let w=h,x=Pa(w);for(;x&&r&&p!==w;){const g=jr(x),v=x.getBoundingClientRect(),b=cn(x),S=v.left+(x.clientLeft+parseFloat(b.paddingLeft))*g.x,N=v.top+(x.clientTop+parseFloat(b.paddingTop))*g.y;l*=g.x,u*=g.y,d*=g.x,f*=g.y,l+=S,u+=N,w=Ht(x),x=Pa(w)}}return Ns({width:d,height:f,x:l,y:u})}function Rs(e,t){const n=js(e).scrollLeft;return t?t.left+n:cr(Sn(e)).left+n}function lf(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-Rs(e,n),o=n.top+t.scrollTop;return{x:r,y:o}}function Oy(e){let{elements:t,rect:n,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=Sn(r),a=t?_s(t.floating):!1;if(r===i||a&&s)return n;let l={scrollLeft:0,scrollTop:0},u=bn(1);const d=bn(0),f=Cn(r);if((f||!f&&!s)&&((Ar(r)!=="body"||co(i))&&(l=js(r)),Cn(r))){const p=cr(r);u=jr(r),d.x=p.x+r.clientLeft,d.y=p.y+r.clientTop}const h=i&&!f&&!s?lf(i,l):bn(0);return{width:n.width*u.x,height:n.height*u.y,x:n.x*u.x-l.scrollLeft*u.x+d.x+h.x,y:n.y*u.y-l.scrollTop*u.y+d.y+h.y}}function My(e){return Array.from(e.getClientRects())}function Dy(e){const t=Sn(e),n=js(e),r=e.ownerDocument.body,o=zt(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=zt(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let i=-n.scrollLeft+Rs(e);const a=-n.scrollTop;return cn(r).direction==="rtl"&&(i+=zt(t.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}const cf=25;function Ly(e,t){const n=Ht(e),r=Sn(e),o=n.visualViewport;let s=r.clientWidth,i=r.clientHeight,a=0,l=0;if(o){s=o.width,i=o.height;const d=Ra();(!d||d&&t==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}const u=Rs(r);if(u<=0){const d=r.ownerDocument,f=d.body,h=getComputedStyle(f),p=d.compatMode==="CSS1Compat"&&parseFloat(h.marginLeft)+parseFloat(h.marginRight)||0,w=Math.abs(r.clientWidth-f.clientWidth-p);w<=cf&&(s-=w)}else u<=cf&&(s+=u);return{width:s,height:i,x:a,y:l}}const Fy=new Set(["absolute","fixed"]);function $y(e,t){const n=cr(e,!0,t==="fixed"),r=n.top+e.clientTop,o=n.left+e.clientLeft,s=Cn(e)?jr(e):bn(1),i=e.clientWidth*s.x,a=e.clientHeight*s.y,l=o*s.x,u=r*s.y;return{width:i,height:a,x:l,y:u}}function uf(e,t,n){let r;if(t==="viewport")r=Ly(e,n);else if(t==="document")r=Dy(Sn(e));else if(ln(t))r=$y(t,n);else{const o=af(e);r={x:t.x-o.x,y:t.y-o.y,width:t.width,height:t.height}}return Ns(r)}function df(e,t){const n=Hn(e);return n===t||!ln(n)||_r(n)?!1:cn(n).position==="fixed"||df(n,t)}function By(e,t){const n=t.get(e);if(n)return n;let r=uo(e,[],!1).filter(a=>ln(a)&&Ar(a)!=="body"),o=null;const s=cn(e).position==="fixed";let i=s?Hn(e):e;for(;ln(i)&&!_r(i);){const a=cn(i),l=ja(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&Fy.has(o.position)||co(i)&&!l&&df(e,i))?r=r.filter(d=>d!==i):o=a,i=Hn(i)}return t.set(e,r),r}function zy(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i=[...n==="clippingAncestors"?_s(t)?[]:By(t,this._c):[].concat(n),r],a=i[0],l=i.reduce((u,d)=>{const f=uf(t,d,o);return u.top=zt(f.top,u.top),u.right=zn(f.right,u.right),u.bottom=zn(f.bottom,u.bottom),u.left=zt(f.left,u.left),u},uf(t,a,o));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function Hy(e){const{width:t,height:n}=sf(e);return{width:t,height:n}}function Uy(e,t,n){const r=Cn(t),o=Sn(t),s=n==="fixed",i=cr(e,!0,s,t);let a={scrollLeft:0,scrollTop:0};const l=bn(0);function u(){l.x=Rs(o)}if(r||!r&&!s)if((Ar(t)!=="body"||co(o))&&(a=js(t)),r){const p=cr(t,!0,s,t);l.x=p.x+t.clientLeft,l.y=p.y+t.clientTop}else o&&u();s&&!r&&o&&u();const d=o&&!r&&!s?lf(o,a):bn(0),f=i.left+a.scrollLeft-l.x-d.x,h=i.top+a.scrollTop-l.y-d.y;return{x:f,y:h,width:i.width,height:i.height}}function Ma(e){return cn(e).position==="static"}function ff(e,t){if(!Cn(e)||cn(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return Sn(e)===n&&(n=n.ownerDocument.body),n}function hf(e,t){const n=Ht(e);if(_s(e))return n;if(!Cn(e)){let o=Hn(e);for(;o&&!_r(o);){if(ln(o)&&!Ma(o))return o;o=Hn(o)}return n}let r=ff(e,t);for(;r&&ky(r)&&Ma(r);)r=ff(r,t);return r&&_r(r)&&Ma(r)&&!ja(r)?n:r||_y(e)||n}const Wy=async function(e){const t=this.getOffsetParent||hf,n=this.getDimensions,r=await n(e.floating);return{reference:Uy(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function Vy(e){return cn(e).direction==="rtl"}const qy={convertOffsetParentRelativeRectToViewportRelativeRect:Oy,getDocumentElement:Sn,getClippingRect:zy,getOffsetParent:hf,getElementRects:Wy,getClientRects:My,getDimensions:Hy,getScale:jr,isElement:ln,isRTL:Vy};function pf(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function Ky(e,t){let n=null,r;const o=Sn(e);function s(){var a;clearTimeout(r),(a=n)==null||a.disconnect(),n=null}function i(a,l){a===void 0&&(a=!1),l===void 0&&(l=1),s();const u=e.getBoundingClientRect(),{left:d,top:f,width:h,height:p}=u;if(a||t(),!h||!p)return;const w=Es(f),x=Es(o.clientWidth-(d+h)),g=Es(o.clientHeight-(f+p)),v=Es(d),S={rootMargin:-w+"px "+-x+"px "+-g+"px "+-v+"px",threshold:zt(0,zn(1,l))||1};let N=!0;function C(k){const I=k[0].intersectionRatio;if(I!==l){if(!N)return i();I?i(!1,I):r=setTimeout(()=>{i(!1,1e-7)},1e3)}I===1&&!pf(u,e.getBoundingClientRect())&&i(),N=!1}try{n=new IntersectionObserver(C,{...S,root:o.ownerDocument})}catch{n=new IntersectionObserver(C,S)}n.observe(e)}return i(!0),s}function Gy(e,t,n,r){r===void 0&&(r={});const{ancestorScroll:o=!0,ancestorResize:s=!0,elementResize:i=typeof ResizeObserver=="function",layoutShift:a=typeof IntersectionObserver=="function",animationFrame:l=!1}=r,u=Oa(e),d=o||s?[...u?uo(u):[],...uo(t)]:[];d.forEach(v=>{o&&v.addEventListener("scroll",n,{passive:!0}),s&&v.addEventListener("resize",n)});const f=u&&a?Ky(u,n):null;let h=-1,p=null;i&&(p=new ResizeObserver(v=>{let[b]=v;b&&b.target===u&&p&&(p.unobserve(t),cancelAnimationFrame(h),h=requestAnimationFrame(()=>{var S;(S=p)==null||S.observe(t)})),n()}),u&&!l&&p.observe(u),p.observe(t));let w,x=l?cr(e):null;l&&g();function g(){const v=cr(e);x&&!pf(x,v)&&n(),x=v,w=requestAnimationFrame(g)}return n(),()=>{var v;d.forEach(b=>{o&&b.removeEventListener("scroll",n),s&&b.removeEventListener("resize",n)}),f==null||f(),(v=p)==null||v.disconnect(),p=null,l&&cancelAnimationFrame(w)}}const Yy=wy,Xy=by,Jy=gy,Zy=Sy,Qy=xy,mf=my,e0=yy,t0=(e,t,n)=>{const r=new Map,o={platform:qy,...n},s={...o.platform,_c:r};return py(e,t,{...o,platform:s})};var n0=typeof document<"u",r0=function(){},Ps=n0?y.useLayoutEffect:r0;function Os(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(typeof e=="function"&&e.toString()===t.toString())return!0;let n,r,o;if(e&&t&&typeof e=="object"){if(Array.isArray(e)){if(n=e.length,n!==t.length)return!1;for(r=n;r--!==0;)if(!Os(e[r],t[r]))return!1;return!0}if(o=Object.keys(e),n=o.length,n!==Object.keys(t).length)return!1;for(r=n;r--!==0;)if(!{}.hasOwnProperty.call(t,o[r]))return!1;for(r=n;r--!==0;){const s=o[r];if(!(s==="_owner"&&e.$$typeof)&&!Os(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function gf(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function xf(e,t){const n=gf(e);return Math.round(t*n)/n}function Da(e){const t=m.useRef(e);return Ps(()=>{t.current=e}),t}function o0(e){e===void 0&&(e={});const{placement:t="bottom",strategy:n="absolute",middleware:r=[],platform:o,elements:{reference:s,floating:i}={},transform:a=!0,whileElementsMounted:l,open:u}=e,[d,f]=m.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[h,p]=m.useState(r);Os(h,r)||p(r);const[w,x]=m.useState(null),[g,v]=m.useState(null),b=m.useCallback(B=>{B!==k.current&&(k.current=B,x(B))},[]),S=m.useCallback(B=>{B!==I.current&&(I.current=B,v(B))},[]),N=s||w,C=i||g,k=m.useRef(null),I=m.useRef(null),A=m.useRef(d),j=l!=null,P=Da(l),L=Da(o),F=Da(u),V=m.useCallback(()=>{if(!k.current||!I.current)return;const B={placement:t,strategy:n,middleware:h};L.current&&(B.platform=L.current),t0(k.current,I.current,B).then($=>{const ce={...$,isPositioned:F.current!==!1};M.current&&!Os(A.current,ce)&&(A.current=ce,yo.flushSync(()=>{f(ce)}))})},[h,t,n,L,F]);Ps(()=>{u===!1&&A.current.isPositioned&&(A.current.isPositioned=!1,f(B=>({...B,isPositioned:!1})))},[u]);const M=m.useRef(!1);Ps(()=>(M.current=!0,()=>{M.current=!1}),[]),Ps(()=>{if(N&&(k.current=N),C&&(I.current=C),N&&C){if(P.current)return P.current(N,C,V);V()}},[N,C,V,P,j]);const G=m.useMemo(()=>({reference:k,floating:I,setReference:b,setFloating:S}),[b,S]),q=m.useMemo(()=>({reference:N,floating:C}),[N,C]),U=m.useMemo(()=>{const B={position:n,left:0,top:0};if(!q.floating)return B;const $=xf(q.floating,d.x),ce=xf(q.floating,d.y);return a?{...B,transform:"translate("+$+"px, "+ce+"px)",...gf(q.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:$,top:ce}},[n,a,q.floating,d.x,d.y]);return m.useMemo(()=>({...d,update:V,refs:G,elements:q,floatingStyles:U}),[d,V,G,q,U])}const s0=e=>{function t(n){return{}.hasOwnProperty.call(n,"current")}return{name:"arrow",options:e,fn(n){const{element:r,padding:o}=typeof e=="function"?e(n):e;return r&&t(r)?r.current!=null?mf({element:r.current,padding:o}).fn(n):{}:r?mf({element:r,padding:o}).fn(n):{}}}},i0=(e,t)=>({...Yy(e),options:[e,t]}),a0=(e,t)=>({...Xy(e),options:[e,t]}),l0=(e,t)=>({...e0(e),options:[e,t]}),c0=(e,t)=>({...Jy(e),options:[e,t]}),u0=(e,t)=>({...Zy(e),options:[e,t]}),d0=(e,t)=>({...Qy(e),options:[e,t]}),f0=(e,t)=>({...s0(e),options:[e,t]});var h0="Arrow",vf=m.forwardRef((e,t)=>{const{children:n,width:r=10,height:o=5,...s}=e;return c.jsx(_e.svg,{...s,ref:t,width:r,height:o,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:e.asChild?n:c.jsx("polygon",{points:"0,0 30,0 15,10"})})});vf.displayName=h0;var p0=vf;function wf(e){const[t,n]=m.useState(void 0);return Ct(()=>{if(e){n({width:e.offsetWidth,height:e.offsetHeight});const r=new ResizeObserver(o=>{if(!Array.isArray(o)||!o.length)return;const s=o[0];let i,a;if("borderBoxSize"in s){const l=s.borderBoxSize,u=Array.isArray(l)?l[0]:l;i=u.inlineSize,a=u.blockSize}else i=e.offsetWidth,a=e.offsetHeight;n({width:i,height:a})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else n(void 0)},[e]),t}var La="Popper",[bf,Ms]=xn(La),[m0,yf]=bf(La),Sf=e=>{const{__scopePopper:t,children:n}=e,[r,o]=m.useState(null);return c.jsx(m0,{scope:t,anchor:r,onAnchorChange:o,children:n})};Sf.displayName=La;var Cf="PopperAnchor",Tf=m.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...o}=e,s=yf(Cf,n),i=m.useRef(null),a=Ve(t,i),l=m.useRef(null);return m.useEffect(()=>{const u=l.current;l.current=(r==null?void 0:r.current)||i.current,u!==l.current&&s.onAnchorChange(l.current)}),r?null:c.jsx(_e.div,{...o,ref:a})});Tf.displayName=Cf;var Fa="PopperContent",[g0,x0]=bf(Fa),kf=m.forwardRef((e,t)=>{var K,O,X,ee,fe,ne;const{__scopePopper:n,side:r="bottom",sideOffset:o=0,align:s="center",alignOffset:i=0,arrowPadding:a=0,avoidCollisions:l=!0,collisionBoundary:u=[],collisionPadding:d=0,sticky:f="partial",hideWhenDetached:h=!1,updatePositionStrategy:p="optimized",onPlaced:w,...x}=e,g=yf(Fa,n),[v,b]=m.useState(null),S=Ve(t,pe=>b(pe)),[N,C]=m.useState(null),k=wf(N),I=(k==null?void 0:k.width)??0,A=(k==null?void 0:k.height)??0,j=r+(s!=="center"?"-"+s:""),P=typeof d=="number"?d:{top:0,right:0,bottom:0,left:0,...d},L=Array.isArray(u)?u:[u],F=L.length>0,V={padding:P,boundary:L.filter(w0),altBoundary:F},{refs:M,floatingStyles:G,placement:q,isPositioned:U,middlewareData:B}=o0({strategy:"fixed",placement:j,whileElementsMounted:(...pe)=>Gy(...pe,{animationFrame:p==="always"}),elements:{reference:g.anchor},middleware:[i0({mainAxis:o+A,alignmentAxis:i}),l&&a0({mainAxis:!0,crossAxis:!1,limiter:f==="partial"?l0():void 0,...V}),l&&c0({...V}),u0({...V,apply:({elements:pe,rects:Ze,availableWidth:Qe,availableHeight:Pe})=>{const{width:He,height:ct}=Ze.reference,tt=pe.floating.style;tt.setProperty("--radix-popper-available-width",`${Qe}px`),tt.setProperty("--radix-popper-available-height",`${Pe}px`),tt.setProperty("--radix-popper-anchor-width",`${He}px`),tt.setProperty("--radix-popper-anchor-height",`${ct}px`)}}),N&&f0({element:N,padding:a}),b0({arrowWidth:I,arrowHeight:A}),h&&d0({strategy:"referenceHidden",...V})]}),[$,ce]=Nf(q),D=Tt(w);Ct(()=>{U&&(D==null||D())},[U,D]);const Q=(K=B.arrow)==null?void 0:K.x,de=(O=B.arrow)==null?void 0:O.y,we=((X=B.arrow)==null?void 0:X.centerOffset)!==0,[ye,Se]=m.useState();return Ct(()=>{v&&Se(window.getComputedStyle(v).zIndex)},[v]),c.jsx("div",{ref:M.setFloating,"data-radix-popper-content-wrapper":"",style:{...G,transform:U?G.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:ye,"--radix-popper-transform-origin":[(ee=B.transformOrigin)==null?void 0:ee.x,(fe=B.transformOrigin)==null?void 0:fe.y].join(" "),...((ne=B.hide)==null?void 0:ne.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:c.jsx(g0,{scope:n,placedSide:$,onArrowChange:C,arrowX:Q,arrowY:de,shouldHideArrow:we,children:c.jsx(_e.div,{"data-side":$,"data-align":ce,...x,ref:S,style:{...x.style,animation:U?void 0:"none"}})})})});kf.displayName=Fa;var Ef="PopperArrow",v0={top:"bottom",right:"left",bottom:"top",left:"right"},If=m.forwardRef(function(t,n){const{__scopePopper:r,...o}=t,s=x0(Ef,r),i=v0[s.placedSide];return c.jsx("span",{ref:s.onArrowChange,style:{position:"absolute",left:s.arrowX,top:s.arrowY,[i]:0,transformOrigin:{top:"",right:"0 0",bottom:"center 0",left:"100% 0"}[s.placedSide],transform:{top:"translateY(100%)",right:"translateY(50%) rotate(90deg) translateX(-50%)",bottom:"rotate(180deg)",left:"translateY(50%) rotate(-90deg) translateX(50%)"}[s.placedSide],visibility:s.shouldHideArrow?"hidden":void 0},children:c.jsx(p0,{...o,ref:n,style:{...o.style,display:"block"}})})});If.displayName=Ef;function w0(e){return e!==null}var b0=e=>({name:"transformOrigin",options:e,fn(t){var g,v,b;const{placement:n,rects:r,middlewareData:o}=t,i=((g=o.arrow)==null?void 0:g.centerOffset)!==0,a=i?0:e.arrowWidth,l=i?0:e.arrowHeight,[u,d]=Nf(n),f={start:"0%",center:"50%",end:"100%"}[d],h=(((v=o.arrow)==null?void 0:v.x)??0)+a/2,p=(((b=o.arrow)==null?void 0:b.y)??0)+l/2;let w="",x="";return u==="bottom"?(w=i?f:`${h}px`,x=`${-l}px`):u==="top"?(w=i?f:`${h}px`,x=`${r.floating.height+l}px`):u==="right"?(w=`${-l}px`,x=i?f:`${p}px`):u==="left"&&(w=`${r.floating.width+l}px`,x=i?f:`${p}px`),{data:{x:w,y:x}}}});function Nf(e){const[t,n="center"]=e.split("-");return[t,n]}var Af=Sf,_f=Tf,jf=kf,Rf=If,$a="rovingFocusGroup.onEntryFocus",y0={bubbles:!1,cancelable:!0},fo="RovingFocusGroup",[Ba,Pf,S0]=ka(fo),[C0,Of]=xn(fo,[S0]),[T0,k0]=C0(fo),Mf=m.forwardRef((e,t)=>c.jsx(Ba.Provider,{scope:e.__scopeRovingFocusGroup,children:c.jsx(Ba.Slot,{scope:e.__scopeRovingFocusGroup,children:c.jsx(E0,{...e,ref:t})})}));Mf.displayName=fo;var E0=m.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:o=!1,dir:s,currentTabStopId:i,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:l,onEntryFocus:u,preventScrollOnEntryFocus:d=!1,...f}=e,h=m.useRef(null),p=Ve(t,h),w=Ts(s),[x,g]=or({prop:i,defaultProp:a??null,onChange:l,caller:fo}),[v,b]=m.useState(!1),S=Tt(u),N=Pf(n),C=m.useRef(!1),[k,I]=m.useState(0);return m.useEffect(()=>{const A=h.current;if(A)return A.addEventListener($a,S),()=>A.removeEventListener($a,S)},[S]),c.jsx(T0,{scope:n,orientation:r,dir:w,loop:o,currentTabStopId:x,onItemFocus:m.useCallback(A=>g(A),[g]),onItemShiftTab:m.useCallback(()=>b(!0),[]),onFocusableItemAdd:m.useCallback(()=>I(A=>A+1),[]),onFocusableItemRemove:m.useCallback(()=>I(A=>A-1),[]),children:c.jsx(_e.div,{tabIndex:v||k===0?-1:0,"data-orientation":r,...f,ref:p,style:{outline:"none",...e.style},onMouseDown:ue(e.onMouseDown,()=>{C.current=!0}),onFocus:ue(e.onFocus,A=>{const j=!C.current;if(A.target===A.currentTarget&&j&&!v){const P=new CustomEvent($a,y0);if(A.currentTarget.dispatchEvent(P),!P.defaultPrevented){const L=N().filter(q=>q.focusable),F=L.find(q=>q.active),V=L.find(q=>q.id===x),G=[F,V,...L].filter(Boolean).map(q=>q.ref.current);Ff(G,d)}}C.current=!1}),onBlur:ue(e.onBlur,()=>b(!1))})})}),Df="RovingFocusGroupItem",Lf=m.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:o=!1,tabStopId:s,children:i,...a}=e,l=vn(),u=s||l,d=k0(Df,n),f=d.currentTabStopId===u,h=Pf(n),{onFocusableItemAdd:p,onFocusableItemRemove:w,currentTabStopId:x}=d;return m.useEffect(()=>{if(r)return p(),()=>w()},[r,p,w]),c.jsx(Ba.ItemSlot,{scope:n,id:u,focusable:r,active:o,children:c.jsx(_e.span,{tabIndex:f?0:-1,"data-orientation":d.orientation,...a,ref:t,onMouseDown:ue(e.onMouseDown,g=>{r?d.onItemFocus(u):g.preventDefault()}),onFocus:ue(e.onFocus,()=>d.onItemFocus(u)),onKeyDown:ue(e.onKeyDown,g=>{if(g.key==="Tab"&&g.shiftKey){d.onItemShiftTab();return}if(g.target!==g.currentTarget)return;const v=A0(g,d.orientation,d.dir);if(v!==void 0){if(g.metaKey||g.ctrlKey||g.altKey||g.shiftKey)return;g.preventDefault();let S=h().filter(N=>N.focusable).map(N=>N.ref.current);if(v==="last")S.reverse();else if(v==="prev"||v==="next"){v==="prev"&&S.reverse();const N=S.indexOf(g.currentTarget);S=d.loop?_0(S,N+1):S.slice(N+1)}setTimeout(()=>Ff(S))}}),children:typeof i=="function"?i({isCurrentTabStop:f,hasTabStop:x!=null}):i})})});Lf.displayName=Df;var I0={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function N0(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function A0(e,t,n){const r=N0(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return I0[r]}function Ff(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function _0(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var j0=Mf,R0=Lf,za=["Enter"," "],P0=["ArrowDown","PageUp","Home"],$f=["ArrowUp","PageDown","End"],O0=[...P0,...$f],M0={ltr:[...za,"ArrowRight"],rtl:[...za,"ArrowLeft"]},D0={ltr:["ArrowLeft"],rtl:["ArrowRight"]},ho="Menu",[po,L0,F0]=ka(ho),[ur,Bf]=xn(ho,[F0,Ms,Of]),Ds=Ms(),zf=Of(),[$0,dr]=ur(ho),[B0,mo]=ur(ho),Hf=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=Ds(t),[l,u]=m.useState(null),d=m.useRef(!1),f=Tt(s),h=Ts(o);return m.useEffect(()=>{const p=()=>{d.current=!0,document.addEventListener("pointerdown",w,{capture:!0,once:!0}),document.addEventListener("pointermove",w,{capture:!0,once:!0})},w=()=>d.current=!1;return document.addEventListener("keydown",p,{capture:!0}),()=>{document.removeEventListener("keydown",p,{capture:!0}),document.removeEventListener("pointerdown",w,{capture:!0}),document.removeEventListener("pointermove",w,{capture:!0})}},[]),c.jsx(Af,{...a,children:c.jsx($0,{scope:t,open:n,onOpenChange:f,content:l,onContentChange:u,children:c.jsx(B0,{scope:t,onClose:m.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:d,dir:h,modal:i,children:r})})})};Hf.displayName=ho;var z0="MenuAnchor",Ha=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=Ds(n);return c.jsx(_f,{...o,...r,ref:t})});Ha.displayName=z0;var Ua="MenuPortal",[H0,Uf]=ur(Ua,{forceMount:void 0}),Wf=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:o}=e,s=dr(Ua,t);return c.jsx(H0,{scope:t,forceMount:n,children:c.jsx(Bt,{present:n||s.open,children:c.jsx(ls,{asChild:!0,container:o,children:r})})})};Wf.displayName=Ua;var Yt="MenuContent",[U0,Wa]=ur(Yt),Vf=m.forwardRef((e,t)=>{const n=Uf(Yt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=dr(Yt,e.__scopeMenu),i=mo(Yt,e.__scopeMenu);return c.jsx(po.Provider,{scope:e.__scopeMenu,children:c.jsx(Bt,{present:r||s.open,children:c.jsx(po.Slot,{scope:e.__scopeMenu,children:i.modal?c.jsx(W0,{...o,ref:t}):c.jsx(V0,{...o,ref:t})})})})}),W0=m.forwardRef((e,t)=>{const n=dr(Yt,e.__scopeMenu),r=m.useRef(null),o=Ve(t,r);return m.useEffect(()=>{const s=r.current;if(s)return wa(s)},[]),c.jsx(Va,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:ue(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),V0=m.forwardRef((e,t)=>{const n=dr(Yt,e.__scopeMenu);return c.jsx(Va,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),q0=Xn.createSlot("MenuContent.ScrollLock"),Va=m.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:o,onOpenAutoFocus:s,onCloseAutoFocus:i,disableOutsidePointerEvents:a,onEntryFocus:l,onEscapeKeyDown:u,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:h,onDismiss:p,disableOutsideScroll:w,...x}=e,g=dr(Yt,n),v=mo(Yt,n),b=Ds(n),S=zf(n),N=L0(n),[C,k]=m.useState(null),I=m.useRef(null),A=Ve(t,I,g.onContentChange),j=m.useRef(0),P=m.useRef(""),L=m.useRef(0),F=m.useRef(null),V=m.useRef("right"),M=m.useRef(0),G=w?ps:m.Fragment,q=w?{as:q0,allowPinchZoom:!0}:void 0,U=$=>{var K,O;const ce=P.current+$,D=N().filter(X=>!X.disabled),Q=document.activeElement,de=(K=D.find(X=>X.ref.current===Q))==null?void 0:K.textValue,we=D.map(X=>X.textValue),ye=oS(we,ce,de),Se=(O=D.find(X=>X.textValue===ye))==null?void 0:O.ref.current;(function X(ee){P.current=ee,window.clearTimeout(j.current),ee!==""&&(j.current=window.setTimeout(()=>X(""),1e3))})(ce),Se&&setTimeout(()=>Se.focus())};m.useEffect(()=>()=>window.clearTimeout(j.current),[]),ha();const B=m.useCallback($=>{var D,Q;return V.current===((D=F.current)==null?void 0:D.side)&&iS($,(Q=F.current)==null?void 0:Q.area)},[]);return c.jsx(U0,{scope:n,searchRef:P,onItemEnter:m.useCallback($=>{B($)&&$.preventDefault()},[B]),onItemLeave:m.useCallback($=>{var ce;B($)||((ce=I.current)==null||ce.focus(),k(null))},[B]),onTriggerLeave:m.useCallback($=>{B($)&&$.preventDefault()},[B]),pointerGraceTimerRef:L,onPointerGraceIntentChange:m.useCallback($=>{F.current=$},[]),children:c.jsx(G,{...q,children:c.jsx(as,{asChild:!0,trapped:o,onMountAutoFocus:ue(s,$=>{var ce;$.preventDefault(),(ce=I.current)==null||ce.focus({preventScroll:!0})}),onUnmountAutoFocus:i,children:c.jsx(is,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:u,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:h,onDismiss:p,children:c.jsx(j0,{asChild:!0,...S,dir:v.dir,orientation:"vertical",loop:r,currentTabStopId:C,onCurrentTabStopIdChange:k,onEntryFocus:ue(l,$=>{v.isUsingKeyboardRef.current||$.preventDefault()}),preventScrollOnEntryFocus:!0,children:c.jsx(jf,{role:"menu","aria-orientation":"vertical","data-state":lh(g.open),"data-radix-menu-content":"",dir:v.dir,...b,...x,ref:A,style:{outline:"none",...x.style},onKeyDown:ue(x.onKeyDown,$=>{const D=$.target.closest("[data-radix-menu-content]")===$.currentTarget,Q=$.ctrlKey||$.altKey||$.metaKey,de=$.key.length===1;D&&($.key==="Tab"&&$.preventDefault(),!Q&&de&&U($.key));const we=I.current;if($.target!==we||!O0.includes($.key))return;$.preventDefault();const Se=N().filter(K=>!K.disabled).map(K=>K.ref.current);$f.includes($.key)&&Se.reverse(),nS(Se)}),onBlur:ue(e.onBlur,$=>{$.currentTarget.contains($.target)||(window.clearTimeout(j.current),P.current="")}),onPointerMove:ue(e.onPointerMove,xo($=>{const ce=$.target,D=M.current!==$.clientX;if($.currentTarget.contains(ce)&&D){const Q=$.clientX>M.current?"right":"left";V.current=Q,M.current=$.clientX}}))})})})})})})});Vf.displayName=Yt;var K0="MenuGroup",qa=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return c.jsx(_e.div,{role:"group",...r,ref:t})});qa.displayName=K0;var G0="MenuLabel",qf=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return c.jsx(_e.div,{...r,ref:t})});qf.displayName=G0;var Ls="MenuItem",Kf="menu.itemSelect",Fs=m.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...o}=e,s=m.useRef(null),i=mo(Ls,e.__scopeMenu),a=Wa(Ls,e.__scopeMenu),l=Ve(t,s),u=m.useRef(!1),d=()=>{const f=s.current;if(!n&&f){const h=new CustomEvent(Kf,{bubbles:!0,cancelable:!0});f.addEventListener(Kf,p=>r==null?void 0:r(p),{once:!0}),Iu(f,h),h.defaultPrevented?u.current=!1:i.onClose()}};return c.jsx(Gf,{...o,ref:l,disabled:n,onClick:ue(e.onClick,d),onPointerDown:f=>{var h;(h=e.onPointerDown)==null||h.call(e,f),u.current=!0},onPointerUp:ue(e.onPointerUp,f=>{var h;u.current||(h=f.currentTarget)==null||h.click()}),onKeyDown:ue(e.onKeyDown,f=>{const h=a.searchRef.current!=="";n||h&&f.key===" "||za.includes(f.key)&&(f.currentTarget.click(),f.preventDefault())})})});Fs.displayName=Ls;var Gf=m.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:o,...s}=e,i=Wa(Ls,n),a=zf(n),l=m.useRef(null),u=Ve(t,l),[d,f]=m.useState(!1),[h,p]=m.useState("");return m.useEffect(()=>{const w=l.current;w&&p((w.textContent??"").trim())},[s.children]),c.jsx(po.ItemSlot,{scope:n,disabled:r,textValue:o??h,children:c.jsx(R0,{asChild:!0,...a,focusable:!r,children:c.jsx(_e.div,{role:"menuitem","data-highlighted":d?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:u,onPointerMove:ue(e.onPointerMove,xo(w=>{r?i.onItemLeave(w):(i.onItemEnter(w),w.defaultPrevented||w.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:ue(e.onPointerLeave,xo(w=>i.onItemLeave(w))),onFocus:ue(e.onFocus,()=>f(!0)),onBlur:ue(e.onBlur,()=>f(!1))})})})}),Y0="MenuCheckboxItem",Yf=m.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...o}=e;return c.jsx(eh,{scope:e.__scopeMenu,checked:n,children:c.jsx(Fs,{role:"menuitemcheckbox","aria-checked":$s(n)?"mixed":n,...o,ref:t,"data-state":Ga(n),onSelect:ue(o.onSelect,()=>r==null?void 0:r($s(n)?!0:!n),{checkForDefaultPrevented:!1})})})});Yf.displayName=Y0;var Xf="MenuRadioGroup",[X0,J0]=ur(Xf,{value:void 0,onValueChange:()=>{}}),Jf=m.forwardRef((e,t)=>{const{value:n,onValueChange:r,...o}=e,s=Tt(r);return c.jsx(X0,{scope:e.__scopeMenu,value:n,onValueChange:s,children:c.jsx(qa,{...o,ref:t})})});Jf.displayName=Xf;var Zf="MenuRadioItem",Qf=m.forwardRef((e,t)=>{const{value:n,...r}=e,o=J0(Zf,e.__scopeMenu),s=n===o.value;return c.jsx(eh,{scope:e.__scopeMenu,checked:s,children:c.jsx(Fs,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":Ga(s),onSelect:ue(r.onSelect,()=>{var i;return(i=o.onValueChange)==null?void 0:i.call(o,n)},{checkForDefaultPrevented:!1})})})});Qf.displayName=Zf;var Ka="MenuItemIndicator",[eh,Z0]=ur(Ka,{checked:!1}),th=m.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...o}=e,s=Z0(Ka,n);return c.jsx(Bt,{present:r||$s(s.checked)||s.checked===!0,children:c.jsx(_e.span,{...o,ref:t,"data-state":Ga(s.checked)})})});th.displayName=Ka;var Q0="MenuSeparator",nh=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return c.jsx(_e.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});nh.displayName=Q0;var eS="MenuArrow",rh=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=Ds(n);return c.jsx(Rf,{...o,...r,ref:t})});rh.displayName=eS;var tS="MenuSub",[LT,oh]=ur(tS),go="MenuSubTrigger",sh=m.forwardRef((e,t)=>{const n=dr(go,e.__scopeMenu),r=mo(go,e.__scopeMenu),o=oh(go,e.__scopeMenu),s=Wa(go,e.__scopeMenu),i=m.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:l}=s,u={__scopeMenu:e.__scopeMenu},d=m.useCallback(()=>{i.current&&window.clearTimeout(i.current),i.current=null},[]);return m.useEffect(()=>d,[d]),m.useEffect(()=>{const f=a.current;return()=>{window.clearTimeout(f),l(null)}},[a,l]),c.jsx(Ha,{asChild:!0,...u,children:c.jsx(Gf,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":o.contentId,"data-state":lh(n.open),...e,ref:Qi(t,o.onTriggerChange),onClick:f=>{var h;(h=e.onClick)==null||h.call(e,f),!(e.disabled||f.defaultPrevented)&&(f.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:ue(e.onPointerMove,xo(f=>{s.onItemEnter(f),!f.defaultPrevented&&!e.disabled&&!n.open&&!i.current&&(s.onPointerGraceIntentChange(null),i.current=window.setTimeout(()=>{n.onOpenChange(!0),d()},100))})),onPointerLeave:ue(e.onPointerLeave,xo(f=>{var p,w;d();const h=(p=n.content)==null?void 0:p.getBoundingClientRect();if(h){const x=(w=n.content)==null?void 0:w.dataset.side,g=x==="right",v=g?-5:5,b=h[g?"left":"right"],S=h[g?"right":"left"];s.onPointerGraceIntentChange({area:[{x:f.clientX+v,y:f.clientY},{x:b,y:h.top},{x:S,y:h.top},{x:S,y:h.bottom},{x:b,y:h.bottom}],side:x}),window.clearTimeout(a.current),a.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(f),f.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:ue(e.onKeyDown,f=>{var p;const h=s.searchRef.current!=="";e.disabled||h&&f.key===" "||M0[r.dir].includes(f.key)&&(n.onOpenChange(!0),(p=n.content)==null||p.focus(),f.preventDefault())})})})});sh.displayName=go;var ih="MenuSubContent",ah=m.forwardRef((e,t)=>{const n=Uf(Yt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=dr(Yt,e.__scopeMenu),i=mo(Yt,e.__scopeMenu),a=oh(ih,e.__scopeMenu),l=m.useRef(null),u=Ve(t,l);return c.jsx(po.Provider,{scope:e.__scopeMenu,children:c.jsx(Bt,{present:r||s.open,children:c.jsx(po.Slot,{scope:e.__scopeMenu,children:c.jsx(Va,{id:a.contentId,"aria-labelledby":a.triggerId,...o,ref:u,align:"start",side:i.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:d=>{var f;i.isUsingKeyboardRef.current&&((f=l.current)==null||f.focus()),d.preventDefault()},onCloseAutoFocus:d=>d.preventDefault(),onFocusOutside:ue(e.onFocusOutside,d=>{d.target!==a.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:ue(e.onEscapeKeyDown,d=>{i.onClose(),d.preventDefault()}),onKeyDown:ue(e.onKeyDown,d=>{var p;const f=d.currentTarget.contains(d.target),h=D0[i.dir].includes(d.key);f&&h&&(s.onOpenChange(!1),(p=a.trigger)==null||p.focus(),d.preventDefault())})})})})})});ah.displayName=ih;function lh(e){return e?"open":"closed"}function $s(e){return e==="indeterminate"}function Ga(e){return $s(e)?"indeterminate":e?"checked":"unchecked"}function nS(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function rS(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function oS(e,t,n){const o=t.length>1&&Array.from(t).every(u=>u===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let i=rS(e,Math.max(s,0));o.length===1&&(i=i.filter(u=>u!==n));const l=i.find(u=>u.toLowerCase().startsWith(o.toLowerCase()));return l!==n?l:void 0}function sS(e,t){const{x:n,y:r}=e;let o=!1;for(let s=0,i=t.length-1;s<t.length;i=s++){const a=t[s],l=t[i],u=a.x,d=a.y,f=l.x,h=l.y;d>r!=h>r&&n<(f-u)*(r-d)/(h-d)+u&&(o=!o)}return o}function iS(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return sS(n,t)}function xo(e){return t=>t.pointerType==="mouse"?e(t):void 0}var aS=Hf,lS=Ha,cS=Wf,uS=Vf,dS=qa,fS=qf,hS=Fs,pS=Yf,mS=Jf,gS=Qf,xS=th,vS=nh,wS=rh,bS=sh,yS=ah,Bs="DropdownMenu",[SS,FT]=xn(Bs,[Bf]),jt=Bf(),[CS,ch]=SS(Bs),uh=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:o,defaultOpen:s,onOpenChange:i,modal:a=!0}=e,l=jt(t),u=m.useRef(null),[d,f]=or({prop:o,defaultProp:s??!1,onChange:i,caller:Bs});return c.jsx(CS,{scope:t,triggerId:vn(),triggerRef:u,contentId:vn(),open:d,onOpenChange:f,onOpenToggle:m.useCallback(()=>f(h=>!h),[f]),modal:a,children:c.jsx(aS,{...l,open:d,onOpenChange:f,dir:r,modal:a,children:n})})};uh.displayName=Bs;var dh="DropdownMenuTrigger",fh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...o}=e,s=ch(dh,n),i=jt(n);return c.jsx(lS,{asChild:!0,...i,children:c.jsx(_e.button,{type:"button",id:s.triggerId,"aria-haspopup":"menu","aria-expanded":s.open,"aria-controls":s.open?s.contentId:void 0,"data-state":s.open?"open":"closed","data-disabled":r?"":void 0,disabled:r,...o,ref:Qi(t,s.triggerRef),onPointerDown:ue(e.onPointerDown,a=>{!r&&a.button===0&&a.ctrlKey===!1&&(s.onOpenToggle(),s.open||a.preventDefault())}),onKeyDown:ue(e.onKeyDown,a=>{r||(["Enter"," "].includes(a.key)&&s.onOpenToggle(),a.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(a.key)&&a.preventDefault())})})})});fh.displayName=dh;var TS="DropdownMenuPortal",hh=e=>{const{__scopeDropdownMenu:t,...n}=e,r=jt(t);return c.jsx(cS,{...r,...n})};hh.displayName=TS;var ph="DropdownMenuContent",mh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=ch(ph,n),s=jt(n),i=m.useRef(!1);return c.jsx(uS,{id:o.contentId,"aria-labelledby":o.triggerId,...s,...r,ref:t,onCloseAutoFocus:ue(e.onCloseAutoFocus,a=>{var l;i.current||(l=o.triggerRef.current)==null||l.focus(),i.current=!1,a.preventDefault()}),onInteractOutside:ue(e.onInteractOutside,a=>{const l=a.detail.originalEvent,u=l.button===0&&l.ctrlKey===!0,d=l.button===2||u;(!o.modal||d)&&(i.current=!0)}),style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});mh.displayName=ph;var kS="DropdownMenuGroup",ES=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=jt(n);return c.jsx(dS,{...o,...r,ref:t})});ES.displayName=kS;var IS="DropdownMenuLabel",gh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=jt(n);return c.jsx(fS,{...o,...r,ref:t})});gh.displayName=IS;var NS="DropdownMenuItem",xh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=jt(n);return c.jsx(hS,{...o,...r,ref:t})});xh.displayName=NS;var AS="DropdownMenuCheckboxItem",vh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=jt(n);return c.jsx(pS,{...o,...r,ref:t})});vh.displayName=AS;var _S="DropdownMenuRadioGroup",jS=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=jt(n);return c.jsx(mS,{...o,...r,ref:t})});jS.displayName=_S;var RS="DropdownMenuRadioItem",wh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=jt(n);return c.jsx(gS,{...o,...r,ref:t})});wh.displayName=RS;var PS="DropdownMenuItemIndicator",bh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=jt(n);return c.jsx(xS,{...o,...r,ref:t})});bh.displayName=PS;var OS="DropdownMenuSeparator",yh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=jt(n);return c.jsx(vS,{...o,...r,ref:t})});yh.displayName=OS;var MS="DropdownMenuArrow",DS=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=jt(n);return c.jsx(wS,{...o,...r,ref:t})});DS.displayName=MS;var LS="DropdownMenuSubTrigger",Sh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=jt(n);return c.jsx(bS,{...o,...r,ref:t})});Sh.displayName=LS;var FS="DropdownMenuSubContent",Ch=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=jt(n);return c.jsx(yS,{...o,...r,ref:t,style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});Ch.displayName=FS;var $S=uh,BS=fh,zS=hh,Th=mh,kh=gh,Eh=xh,Ih=vh,Nh=wh,Ah=bh,_h=yh,jh=Sh,Rh=Ch;const HS=$S,US=BS,WS=m.forwardRef(({className:e,inset:t,children:n,...r},o)=>c.jsxs(jh,{ref:o,className:Z("flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent",t&&"pl-8",e),...r,children:[n,c.jsx(oe.ChevronRight,{className:"ml-auto h-4 w-4"})]}));WS.displayName=jh.displayName;const VS=m.forwardRef(({className:e,...t},n)=>c.jsx(Rh,{ref:n,className:Z("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e),...t}));VS.displayName=Rh.displayName;const Ph=m.forwardRef(({className:e,sideOffset:t=4,...n},r)=>c.jsx(zS,{children:c.jsx(Th,{ref:r,sideOffset:t,className:Z("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e),...n})}));Ph.displayName=Th.displayName;const Ya=m.forwardRef(({className:e,inset:t,...n},r)=>c.jsx(Eh,{ref:r,className:Z("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t&&"pl-8",e),...n}));Ya.displayName=Eh.displayName;const qS=m.forwardRef(({className:e,children:t,checked:n,...r},o)=>c.jsxs(Ih,{ref:o,className:Z("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),checked:n,...r,children:[c.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:c.jsx(Ah,{children:c.jsx(oe.Check,{className:"h-4 w-4"})})}),t]}));qS.displayName=Ih.displayName;const KS=m.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(Nh,{ref:r,className:Z("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[c.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:c.jsx(Ah,{children:c.jsx(oe.Circle,{className:"h-2 w-2 fill-current"})})}),t]}));KS.displayName=Nh.displayName;const GS=m.forwardRef(({className:e,inset:t,...n},r)=>c.jsx(kh,{ref:r,className:Z("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));GS.displayName=kh.displayName;const YS=m.forwardRef(({className:e,...t},n)=>c.jsx(_h,{ref:n,className:Z("-mx-1 my-1 h-px bg-muted",e),...t}));YS.displayName=_h.displayName;function zs({className:e="",placeholder:t="Type your message...",autoFocus:n=!0,maxHeight:r=void 0,streamingDebounceMs:o=500,streamingThrottleMs:s,followNewMessages:i=!0,enableFileUpload:a=!0,enableExcelUpload:l=!1,enableMessageEditing:u=!0,customStyles:d={},onMessageSent:f,onExcelUploadSuccess:h,onError:p}){const{api:w}=xi(),{currentThreadId:x}=Mo(),{threadId:g,messages:v,hasMore:b,isHistoryLoading:S,isLoading:N,loadOlder:C,listCheckpoints:k,navigateToCheckpoint:I,returnToLatest:A,checkpoint:j,respondToInterrupt:P,metadata:L}=Do(),{isStreaming:F,error:V,submit:M,stop:G}=Ec(),q=g??x??null,U=(j==null?void 0:j.id)??null,B=(j==null?void 0:j.namespace)??null,$=(L==null?void 0:L.assemblingMessageId)??null,[ce,D]=y.useState(null),[Q,de]=y.useState(""),[we,ye]=y.useState(null),[Se,K]=y.useState([]),[O,X]=y.useState(0),[ee,fe]=y.useState(0),[ne,pe]=y.useState(!1),[Ze,Qe]=y.useState(null),[Pe,He]=y.useState(null),[ct,tt]=y.useState(!1),[Be,gt]=y.useState(null),[J,re]=y.useState([]),[he,Ce]=y.useState(null),[me,Oe]=y.useState(null),[it,Me]=y.useState(!1),et=y.useRef(null),vt=y.useRef(null),Zt=y.useRef(null),qn=y.useCallback(()=>{et.current&&(et.current.value=""),vt.current&&(vt.current.value=""),X(se=>se+1),fe(se=>se+1)},[]),Mr=y.useRef(!1);y.useEffect(()=>{Mr.current&&!F&&(K([]),qn()),Mr.current=F},[F,qn]);const[mr,Rt]=y.useState("desktop");y.useEffect(()=>{const se=()=>{const be=window.innerWidth;Rt(be<640?"phone":be<1024?"tablet":"desktop")};return se(),window.addEventListener("resize",se),()=>window.removeEventListener("resize",se)},[]),y.useEffect(()=>{let se=!1;if(!q){re([]),Ce(null),Oe(null),Zt.current=null;return}const be={threadId:q,checkpointId:U??null,checkpointNs:B??null},Ue=Zt.current;if(!(Ue&&Ue.threadId===be.threadId&&Ue.checkpointId===be.checkpointId&&Ue.checkpointNs===be.checkpointNs))return k(q).then(ot=>{var Ee;if(se)return;const Pt=((ot==null?void 0:ot.checkpoints)??[]).slice().sort((Fe,Ke)=>new Date(Ke.createdAt).getTime()-new Date(Fe.createdAt).getTime());re(Pt);const E=he,z=E&&Pt.some(Fe=>Fe.checkpointId===E)?E:((Ee=Pt[0])==null?void 0:Ee.checkpointId)??null;let te=null;if(z){const Fe=Pt.find(Ke=>Ke.checkpointId===z);te=(Fe==null?void 0:Fe.checkpointNs)??null}Ce(z),Oe(te),Zt.current=be}).catch(ot=>{console.error("ChatInterface - listCheckpoints error:",ot),se||(re([]),Zt.current=null)}),()=>{se=!0}},[q,U,B,he,k]),y.useEffect(()=>{U&&(Ce(U),Oe(B??null))},[U,B]);const wo=y.useCallback(async()=>{if(!(!b||S))try{await C()}catch(se){console.warn("loadOlder failed",se)}},[b,S,C]);y.useEffect(()=>{(async()=>{if(!w.baseUrl){gt(null);return}try{const be=await w.getAgent("default");gt(be.uiDefaultMessage||null)}catch(be){console.warn("Failed to fetch default message:",be),gt(null)}})()},[w]),y.useEffect(()=>{V&&!ct&&(p==null||p(V))},[V,ct,p]);const _n=se=>{if(se.length>Cs)return`Message too long (${se.length}/${Cs} characters)`;try{return ty(se),null}catch(be){return(be==null?void 0:be.message)||"Invalid message"}},St=async se=>{const be=se.trim();if(!(!be&&Se.length===0)){if(be){const Ue=_n(be);if(Ue){ye(Ue);return}}try{await M({text:be||"",attachments:Se,payload:ce?{edit:!0,originalMessageId:ce}:void 0},{checkpointId:he??U??void 0,checkpointNs:me??B??void 0}),f==null||f(be),ye(null),K([]),qn(),D(null),de("")}catch(Ue){const ot=(Ue==null?void 0:Ue.message)||"Failed to send message";ye(ot),p==null||p(ot)}}},At=y.useCallback((se,be)=>{u&&(D(se),de(be),ye(null))},[u]),Ut=y.useCallback(()=>{D(null),de(""),ye(null)},[]),Kn=y.useCallback((se,be)=>{At(se,be)},[At]),dn=y.useCallback(se=>{const be=Ue=>{const ot=Ue.content||[],Pt=ot.filter(E=>E.type==="text").map(E=>E.text).join("");if(Pt)return Pt;try{return JSON.stringify(ot,null,2)}catch{return String(ot)}};for(let Ue=se-1;Ue>=0;Ue--)if(v[Ue].role==="user"){const ot=be(v[Ue]);ot&&M({text:ot},{checkpointId:he??U??void 0,checkpointNs:me??B??void 0});break}},[v,M,he,me,U,B]),gr=se=>{const be=Array.from(se.target.files||[]);K(Ue=>[...Ue,...be]),se.target.value=""},fn=se=>{K(be=>{const Ue=be.filter((ot,Pt)=>se!==Pt);return Ue.length===0&&qn(),Ue})},kn=async se=>{const be=(se.target.files||[])[0];if(be){Qe(null),He(null),pe(!0);try{await M({attachments:[be]},{checkpointId:he??U??void 0,checkpointNs:me??B??void 0});const Ue=`Uploaded ${be.name} - processing through chat stream`;He(Ue)}catch(Ue){const ot=Ue instanceof Error?Ue.message:"Failed to upload Excel file";console.error("Excel upload failed",Ue),Qe(ot),p==null||p(ot)}finally{pe(!1),se.target.value="",qn()}}},Gn=se=>{if(!se)return"Unknown";const be=Date.parse(se);return Number.isNaN(be)?se:new Date(be).toLocaleString()},Dr=async se=>{if(x){Me(!0);try{if(!se){await A(),Ce(null),Oe(null);return}const be=J.find(ot=>ot.checkpointId===se),Ue=(be==null?void 0:be.checkpointNs)??null;await I(se,Ue),Ce(se),Oe(Ue)}finally{Me(!1)}}},Lr=`flex flex-1 w-full flex-col min-h-0 min-w-0 max-h-full overflow-hidden bg-transparent ${e} ${d.container||""}`,Fr=`flex-1 min-h-0 min-w-0 max-h-full w-full overflow-hidden overscroll-contain break-words break-anywhere p-4 bg-transparent ${d.messagesArea||""}`,jn=`flex-shrink-0 w-full border-t p-4 bg-transparent ${d.inputArea||""}`;return c.jsxs("div",{className:Lr,children:[!!V&&!ct&&c.jsxs("div",{className:"flex-shrink-0 bg-red-50 border border-red-200 text-red-800 px-4 py-2 text-sm flex items-center justify-between",children:[c.jsx("span",{children:V}),c.jsx(Ge,{variant:"ghost",size:"sm",onClick:()=>tt(!0),className:"text-red-800 hover:bg-red-100","aria-label":"Dismiss error",children:c.jsx(oe.X,{size:16})})]}),x&&J.length>0&&c.jsxs("div",{className:"flex-shrink-0 flex items-center gap-2 px-4 py-2 border-b border-border bg-muted/60 text-xs dark:bg-muted/50",children:[c.jsx("span",{className:"opacity-70",children:"Checkpoint:"}),c.jsxs("select",{className:"border border-border rounded px-2 py-1 text-xs bg-card text-foreground focus:outline-none focus:ring-1 focus:ring-ring dark:bg-secondary",value:he??"",onChange:se=>{const be=se.target.value||null;Dr(be)},children:[c.jsx("option",{value:"",children:"Latest"}),J.map(se=>c.jsxs("option",{value:se.checkpointId,children:[Gn(se.createdAt),se.preview?` — ${se.preview.slice(0,40)}`:""]},se.checkpointId))]})]}),c.jsxs("div",{className:`relative ${Fr}`,style:r?{maxHeight:r}:void 0,children:[c.jsx(Ta,{className:"h-full",style:{height:"100%"},messages:v,isStreaming:F,streamingAssistantId:$,streamingDebounceMs:typeof s=="number"?s:o,followNewMessages:i,layoutSize:mr,enableMessageEditing:u,editingMessageId:ce,onStartReached:()=>{wo()},onEdit:Kn,onRegenerate:dn,onCancelEdit:Ut,emptyMessage:Be??void 0,isNavigatingCheckpoint:it}),N&&c.jsxs("div",{className:"absolute inset-0 z-10 flex flex-col items-center justify-center gap-2 bg-background/80 backdrop-blur-sm text-muted-foreground",children:[c.jsx(oe.Loader2,{className:"h-6 w-6 animate-spin"}),c.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:"Loading messages…"})]})]}),c.jsxs("div",{className:jn,children:[ce&&c.jsx("div",{className:"mb-3 p-3 bg-blue-50 border border-blue-200 rounded-lg",children:c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(oe.Edit3,{size:16,className:"text-blue-600"}),c.jsx("span",{className:"text-sm font-medium text-blue-800",children:"Editing message"})]}),c.jsx(Ge,{variant:"ghost",size:"sm",onClick:Ut,className:"text-blue-600 hover:bg-blue-100",children:c.jsx(oe.X,{size:16})})]})}),(a||l)&&c.jsxs("div",{className:"mb-3 space-y-3",children:[a&&c.jsxs(c.Fragment,{children:[c.jsx("input",{ref:et,type:"file",multiple:!0,onChange:se=>gr(se),className:"hidden"},O),Se.length>0&&c.jsx("div",{className:"flex flex-wrap gap-2",children:Se.map((se,be)=>c.jsxs("div",{className:"flex items-center gap-2 bg-gray-100 dark:bg-gray-800 rounded-lg px-3 py-2 text-sm text-gray-900 dark:text-gray-100",children:[c.jsx(oe.Paperclip,{size:14}),c.jsx("span",{className:"truncate max-w-[150px]",children:se.name}),c.jsx(Ge,{variant:"ghost",size:"sm",onClick:()=>fn(be),className:"h-4 w-4 p-0 text-gray-500 dark:text-gray-400 hover:text-red-500 dark:hover:text-red-400","aria-label":`Remove ${se.name}`,children:c.jsx(oe.X,{size:12})})]},be))})]}),l&&c.jsxs(c.Fragment,{children:[c.jsx("input",{ref:vt,type:"file",accept:".xls,.xlsx,.xlsm",onChange:kn,className:"hidden"},ee),ne&&c.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[c.jsx(oe.Loader2,{className:"h-4 w-4 animate-spin"})," Uploading Excel file..."]}),Pe&&!ne&&c.jsx("div",{className:"text-sm rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-emerald-700",children:Pe}),Ze&&!ne&&c.jsx("div",{className:"text-sm rounded border border-red-200 bg-red-50 px-3 py-2 text-red-600",children:Ze})]})]}),we&&c.jsx("div",{className:"mb-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2",children:we}),c.jsxs("div",{className:"flex items-end gap-2",children:[(a||l)&&c.jsxs(HS,{children:[c.jsx(US,{asChild:!0,children:c.jsx(Ge,{type:"button",size:"icon",variant:"outline",disabled:F,title:"More input actions",className:d.moreButton||"",children:c.jsx(oe.Plus,{size:16})})}),c.jsxs(Ph,{align:"start",sideOffset:6,className:"w-52",children:[a&&c.jsxs(Ya,{onClick:()=>{var se;return(se=et.current)==null?void 0:se.click()},className:"cursor-pointer",children:[c.jsx(oe.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]}),l&&c.jsxs(Ya,{onClick:()=>{var se;ne||(se=vt.current)==null||se.click()},className:`cursor-pointer ${ne?"opacity-60 pointer-events-none":""}`,children:[c.jsx(oe.FileSpreadsheet,{className:"h-4 w-4 mr-2"})," Upload Excel file"]})]})]}),c.jsx("div",{className:"flex-1",children:c.jsx(px,{initialValue:Q,editingMessageId:ce,placeholder:ce?"Edit your message...":t,isStreaming:F,disabled:!1,maxLength:Cs,onSend:St,onCancelEdit:Ut,onStop:G,allowEmptySend:Se.length>0,textareaClassName:`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${ce?"border-blue-400 bg-blue-50 text-blue-900 dark:border-blue-500 dark:bg-blue-950/60 dark:text-blue-50":""} ${we?"border-red-400":""} ${d.textarea||""}`})})]})]})]})}const Hs=m.forwardRef(({className:e,type:t,...n},r)=>c.jsx("input",{type:t,className:Z("flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",e),ref:r,...n}));Hs.displayName="Input";function Xa(e,[t,n]){return Math.min(n,Math.max(t,e))}function XS(e,t){return m.useReducer((n,r)=>t[n][r]??n,e)}var Ja="ScrollArea",[Oh,$T]=xn(Ja),[JS,Xt]=Oh(Ja),Mh=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,type:r="hover",dir:o,scrollHideDelay:s=600,...i}=e,[a,l]=m.useState(null),[u,d]=m.useState(null),[f,h]=m.useState(null),[p,w]=m.useState(null),[x,g]=m.useState(null),[v,b]=m.useState(0),[S,N]=m.useState(0),[C,k]=m.useState(!1),[I,A]=m.useState(!1),j=Ve(t,L=>l(L)),P=Ts(o);return c.jsx(JS,{scope:n,type:r,dir:P,scrollHideDelay:s,scrollArea:a,viewport:u,onViewportChange:d,content:f,onContentChange:h,scrollbarX:p,onScrollbarXChange:w,scrollbarXEnabled:C,onScrollbarXEnabledChange:k,scrollbarY:x,onScrollbarYChange:g,scrollbarYEnabled:I,onScrollbarYEnabledChange:A,onCornerWidthChange:b,onCornerHeightChange:N,children:c.jsx(_e.div,{dir:P,...i,ref:j,style:{position:"relative","--radix-scroll-area-corner-width":v+"px","--radix-scroll-area-corner-height":S+"px",...e.style}})})});Mh.displayName=Ja;var Dh="ScrollAreaViewport",Lh=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,i=Xt(Dh,n),a=m.useRef(null),l=Ve(t,a,i.onViewportChange);return c.jsxs(c.Fragment,{children:[c.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-scroll-area-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-scroll-area-viewport]::-webkit-scrollbar{display:none}"},nonce:o}),c.jsx(_e.div,{"data-radix-scroll-area-viewport":"",...s,ref:l,style:{overflowX:i.scrollbarXEnabled?"scroll":"hidden",overflowY:i.scrollbarYEnabled?"scroll":"hidden",...e.style},children:c.jsx("div",{ref:i.onContentChange,style:{minWidth:"100%",display:"table"},children:r})})]})});Lh.displayName=Dh;var Tn="ScrollAreaScrollbar",Za=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Xt(Tn,e.__scopeScrollArea),{onScrollbarXEnabledChange:s,onScrollbarYEnabledChange:i}=o,a=e.orientation==="horizontal";return m.useEffect(()=>(a?s(!0):i(!0),()=>{a?s(!1):i(!1)}),[a,s,i]),o.type==="hover"?c.jsx(ZS,{...r,ref:t,forceMount:n}):o.type==="scroll"?c.jsx(QS,{...r,ref:t,forceMount:n}):o.type==="auto"?c.jsx(Fh,{...r,ref:t,forceMount:n}):o.type==="always"?c.jsx(Qa,{...r,ref:t}):null});Za.displayName=Tn;var ZS=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Xt(Tn,e.__scopeScrollArea),[s,i]=m.useState(!1);return m.useEffect(()=>{const a=o.scrollArea;let l=0;if(a){const u=()=>{window.clearTimeout(l),i(!0)},d=()=>{l=window.setTimeout(()=>i(!1),o.scrollHideDelay)};return a.addEventListener("pointerenter",u),a.addEventListener("pointerleave",d),()=>{window.clearTimeout(l),a.removeEventListener("pointerenter",u),a.removeEventListener("pointerleave",d)}}},[o.scrollArea,o.scrollHideDelay]),c.jsx(Bt,{present:n||s,children:c.jsx(Fh,{"data-state":s?"visible":"hidden",...r,ref:t})})}),QS=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Xt(Tn,e.__scopeScrollArea),s=e.orientation==="horizontal",i=qs(()=>l("SCROLL_END"),100),[a,l]=XS("hidden",{hidden:{SCROLL:"scrolling"},scrolling:{SCROLL_END:"idle",POINTER_ENTER:"interacting"},interacting:{SCROLL:"interacting",POINTER_LEAVE:"idle"},idle:{HIDE:"hidden",SCROLL:"scrolling",POINTER_ENTER:"interacting"}});return m.useEffect(()=>{if(a==="idle"){const u=window.setTimeout(()=>l("HIDE"),o.scrollHideDelay);return()=>window.clearTimeout(u)}},[a,o.scrollHideDelay,l]),m.useEffect(()=>{const u=o.viewport,d=s?"scrollLeft":"scrollTop";if(u){let f=u[d];const h=()=>{const p=u[d];f!==p&&(l("SCROLL"),i()),f=p};return u.addEventListener("scroll",h),()=>u.removeEventListener("scroll",h)}},[o.viewport,s,l,i]),c.jsx(Bt,{present:n||a!=="hidden",children:c.jsx(Qa,{"data-state":a==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:ue(e.onPointerEnter,()=>l("POINTER_ENTER")),onPointerLeave:ue(e.onPointerLeave,()=>l("POINTER_LEAVE"))})})}),Fh=m.forwardRef((e,t)=>{const n=Xt(Tn,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,i]=m.useState(!1),a=e.orientation==="horizontal",l=qs(()=>{if(n.viewport){const u=n.viewport.offsetWidth<n.viewport.scrollWidth,d=n.viewport.offsetHeight<n.viewport.scrollHeight;i(a?u:d)}},10);return Rr(n.viewport,l),Rr(n.content,l),c.jsx(Bt,{present:r||s,children:c.jsx(Qa,{"data-state":s?"visible":"hidden",...o,ref:t})})}),Qa=m.forwardRef((e,t)=>{const{orientation:n="vertical",...r}=e,o=Xt(Tn,e.__scopeScrollArea),s=m.useRef(null),i=m.useRef(0),[a,l]=m.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),u=Uh(a.viewport,a.content),d={...r,sizes:a,onSizesChange:l,hasThumb:u>0&&u<1,onThumbChange:h=>s.current=h,onThumbPointerUp:()=>i.current=0,onThumbPointerDown:h=>i.current=h};function f(h,p){return sC(h,i.current,a,p)}return n==="horizontal"?c.jsx(eC,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollLeft,p=Wh(h,a,o.dir);s.current.style.transform=`translate3d(${p}px, 0, 0)`}},onWheelScroll:h=>{o.viewport&&(o.viewport.scrollLeft=h)},onDragScroll:h=>{o.viewport&&(o.viewport.scrollLeft=f(h,o.dir))}}):n==="vertical"?c.jsx(tC,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollTop,p=Wh(h,a);s.current.style.transform=`translate3d(0, ${p}px, 0)`}},onWheelScroll:h=>{o.viewport&&(o.viewport.scrollTop=h)},onDragScroll:h=>{o.viewport&&(o.viewport.scrollTop=f(h))}}):null}),eC=m.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=Xt(Tn,e.__scopeScrollArea),[i,a]=m.useState(),l=m.useRef(null),u=Ve(t,l,s.onScrollbarXChange);return m.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),c.jsx(Bh,{"data-orientation":"horizontal",...o,ref:u,sizes:n,style:{bottom:0,left:s.dir==="rtl"?"var(--radix-scroll-area-corner-width)":0,right:s.dir==="ltr"?"var(--radix-scroll-area-corner-width)":0,"--radix-scroll-area-thumb-width":Vs(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.x),onDragScroll:d=>e.onDragScroll(d.x),onWheelScroll:(d,f)=>{if(s.viewport){const h=s.viewport.scrollLeft+d.deltaX;e.onWheelScroll(h),qh(h,f)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollWidth,viewport:s.viewport.offsetWidth,scrollbar:{size:l.current.clientWidth,paddingStart:Ws(i.paddingLeft),paddingEnd:Ws(i.paddingRight)}})}})}),tC=m.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=Xt(Tn,e.__scopeScrollArea),[i,a]=m.useState(),l=m.useRef(null),u=Ve(t,l,s.onScrollbarYChange);return m.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),c.jsx(Bh,{"data-orientation":"vertical",...o,ref:u,sizes:n,style:{top:0,right:s.dir==="ltr"?0:void 0,left:s.dir==="rtl"?0:void 0,bottom:"var(--radix-scroll-area-corner-height)","--radix-scroll-area-thumb-height":Vs(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.y),onDragScroll:d=>e.onDragScroll(d.y),onWheelScroll:(d,f)=>{if(s.viewport){const h=s.viewport.scrollTop+d.deltaY;e.onWheelScroll(h),qh(h,f)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollHeight,viewport:s.viewport.offsetHeight,scrollbar:{size:l.current.clientHeight,paddingStart:Ws(i.paddingTop),paddingEnd:Ws(i.paddingBottom)}})}})}),[nC,$h]=Oh(Tn),Bh=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,sizes:r,hasThumb:o,onThumbChange:s,onThumbPointerUp:i,onThumbPointerDown:a,onThumbPositionChange:l,onDragScroll:u,onWheelScroll:d,onResize:f,...h}=e,p=Xt(Tn,n),[w,x]=m.useState(null),g=Ve(t,j=>x(j)),v=m.useRef(null),b=m.useRef(""),S=p.viewport,N=r.content-r.viewport,C=Tt(d),k=Tt(l),I=qs(f,10);function A(j){if(v.current){const P=j.clientX-v.current.left,L=j.clientY-v.current.top;u({x:P,y:L})}}return m.useEffect(()=>{const j=P=>{const L=P.target;(w==null?void 0:w.contains(L))&&C(P,N)};return document.addEventListener("wheel",j,{passive:!1}),()=>document.removeEventListener("wheel",j,{passive:!1})},[S,w,N,C]),m.useEffect(k,[r,k]),Rr(w,I),Rr(p.content,I),c.jsx(nC,{scope:n,scrollbar:w,hasThumb:o,onThumbChange:Tt(s),onThumbPointerUp:Tt(i),onThumbPositionChange:k,onThumbPointerDown:Tt(a),children:c.jsx(_e.div,{...h,ref:g,style:{position:"absolute",...h.style},onPointerDown:ue(e.onPointerDown,j=>{j.button===0&&(j.target.setPointerCapture(j.pointerId),v.current=w.getBoundingClientRect(),b.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",p.viewport&&(p.viewport.style.scrollBehavior="auto"),A(j))}),onPointerMove:ue(e.onPointerMove,A),onPointerUp:ue(e.onPointerUp,j=>{const P=j.target;P.hasPointerCapture(j.pointerId)&&P.releasePointerCapture(j.pointerId),document.body.style.webkitUserSelect=b.current,p.viewport&&(p.viewport.style.scrollBehavior=""),v.current=null})})})}),Us="ScrollAreaThumb",zh=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=$h(Us,e.__scopeScrollArea);return c.jsx(Bt,{present:n||o.hasThumb,children:c.jsx(rC,{ref:t,...r})})}),rC=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=Xt(Us,n),i=$h(Us,n),{onThumbPositionChange:a}=i,l=Ve(t,f=>i.onThumbChange(f)),u=m.useRef(void 0),d=qs(()=>{u.current&&(u.current(),u.current=void 0)},100);return m.useEffect(()=>{const f=s.viewport;if(f){const h=()=>{if(d(),!u.current){const p=iC(f,a);u.current=p,a()}};return a(),f.addEventListener("scroll",h),()=>f.removeEventListener("scroll",h)}},[s.viewport,d,a]),c.jsx(_e.div,{"data-state":i.hasThumb?"visible":"hidden",...o,ref:l,style:{width:"var(--radix-scroll-area-thumb-width)",height:"var(--radix-scroll-area-thumb-height)",...r},onPointerDownCapture:ue(e.onPointerDownCapture,f=>{const p=f.target.getBoundingClientRect(),w=f.clientX-p.left,x=f.clientY-p.top;i.onThumbPointerDown({x:w,y:x})}),onPointerUp:ue(e.onPointerUp,i.onThumbPointerUp)})});zh.displayName=Us;var el="ScrollAreaCorner",Hh=m.forwardRef((e,t)=>{const n=Xt(el,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?c.jsx(oC,{...e,ref:t}):null});Hh.displayName=el;var oC=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=Xt(el,n),[s,i]=m.useState(0),[a,l]=m.useState(0),u=!!(s&&a);return Rr(o.scrollbarX,()=>{var f;const d=((f=o.scrollbarX)==null?void 0:f.offsetHeight)||0;o.onCornerHeightChange(d),l(d)}),Rr(o.scrollbarY,()=>{var f;const d=((f=o.scrollbarY)==null?void 0:f.offsetWidth)||0;o.onCornerWidthChange(d),i(d)}),u?c.jsx(_e.div,{...r,ref:t,style:{width:s,height:a,position:"absolute",right:o.dir==="ltr"?0:void 0,left:o.dir==="rtl"?0:void 0,bottom:0,...e.style}}):null});function Ws(e){return e?parseInt(e,10):0}function Uh(e,t){const n=e/t;return isNaN(n)?0:n}function Vs(e){const t=Uh(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function sC(e,t,n,r="ltr"){const o=Vs(n),s=o/2,i=t||s,a=o-i,l=n.scrollbar.paddingStart+i,u=n.scrollbar.size-n.scrollbar.paddingEnd-a,d=n.content-n.viewport,f=r==="ltr"?[0,d]:[d*-1,0];return Vh([l,u],f)(e)}function Wh(e,t,n="ltr"){const r=Vs(t),o=t.scrollbar.paddingStart+t.scrollbar.paddingEnd,s=t.scrollbar.size-o,i=t.content-t.viewport,a=s-r,l=n==="ltr"?[0,i]:[i*-1,0],u=Xa(e,l);return Vh([0,i],[0,a])(u)}function Vh(e,t){return n=>{if(e[0]===e[1]||t[0]===t[1])return t[0];const r=(t[1]-t[0])/(e[1]-e[0]);return t[0]+r*(n-e[0])}}function qh(e,t){return e>0&&e<t}var iC=(e,t=()=>{})=>{let n={left:e.scrollLeft,top:e.scrollTop},r=0;return function o(){const s={left:e.scrollLeft,top:e.scrollTop},i=n.left!==s.left,a=n.top!==s.top;(i||a)&&t(),n=s,r=window.requestAnimationFrame(o)}(),()=>window.cancelAnimationFrame(r)};function qs(e,t){const n=Tt(e),r=m.useRef(0);return m.useEffect(()=>()=>window.clearTimeout(r.current),[]),m.useCallback(()=>{window.clearTimeout(r.current),r.current=window.setTimeout(n,t)},[n,t])}function Rr(e,t){const n=Tt(t);Ct(()=>{let r=0;if(e){const o=new ResizeObserver(()=>{cancelAnimationFrame(r),r=window.requestAnimationFrame(n)});return o.observe(e),()=>{window.cancelAnimationFrame(r),o.unobserve(e)}}},[e,n])}var Kh=Mh,aC=Lh,lC=Hh;const Gh=m.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(Kh,{ref:r,className:Z("relative overflow-hidden",e),...n,children:[c.jsx(aC,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),c.jsx(Yh,{}),c.jsx(lC,{})]}));Gh.displayName=Kh.displayName;const Yh=m.forwardRef(({className:e,orientation:t="vertical",...n},r)=>c.jsx(Za,{ref:r,orientation:t,className:Z("flex touch-none select-none transition-colors",t==="vertical"&&"h-full w-2.5 border-l border-l-transparent p-[1px]",t==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent p-[1px]",e),...n,children:c.jsx(zh,{className:"relative flex-1 rounded-full bg-border"})}));Yh.displayName=Za.displayName;function tl({className:e="",showCreateButton:t=!0,showDeleteButton:n=!0,showEditTitle:r=!0,maxHeight:o="400px",customStyles:s={},currentThreadId:i=null,navigateToThread:a,onThreadSelect:l,onThreadCreate:u,onThreadDelete:d}){const{threads:f,currentThreadId:h,isLoading:p,actions:w}=Mo(),{loadThread:x}=Do(),{createThread:g,deleteThread:v,renameThread:b}=w,[S,N]=y.useState(Array.isArray(f)?f:[]),C=y.useRef(S.length>0),[k,I]=y.useState(null),[A,j]=y.useState(""),[P,L]=y.useState(!1);y.useEffect(()=>{const D=Array.isArray(f)?f:[];if(D.length>0){C.current=!0,N(D);return}p||(C.current=!1,N(D))},[f,p]);const F=async D=>{try{await x(D),a==null||a(D),l==null||l(D)}catch(Q){console.error("Failed to select thread:",Q)}},V=async()=>{try{L(!0);const D=await g();u==null||u(D),a==null||a(D)}catch(D){console.error("Failed to create thread:",D)}finally{L(!1)}},M=async(D,Q)=>{if(Q.stopPropagation(),!!confirm("Delete this thread?"))try{await v(D),d==null||d(D)}catch(de){console.error("Failed to delete thread:",de)}},G=(D,Q)=>{Q.stopPropagation(),I(D.threadId),j(D.title||`Thread ${D.threadId.slice(0,8)}`)},q=async D=>{if(A.trim())try{await b(D,A.trim()),I(null),j("")}catch(Q){console.error("Failed to update title:",Q)}},U=()=>{I(null),j("")},B=(D,Q)=>{D.key==="Enter"?q(Q):D.key==="Escape"&&U()},$=D=>{if(!D)return"";try{const Q=new Date(D),we=new Date().getTime()-Q.getTime(),ye=Math.floor(we/(1e3*60*60*24));return ye===0?Q.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):ye===1?"Yesterday":ye<7?`${ye} days ago`:Q.toLocaleDateString()}catch{return""}},ce=D=>D.title||`Thread ${D.threadId.slice(0,8)}`;return c.jsxs("div",{className:`flex flex-col h-full ${e} ${s.container||""}`,children:[t&&c.jsx("div",{className:s.header||"flex-shrink-0 p-2 border-b bg-slate-800 border-slate-700 text-slate-100 flex justify-end",children:c.jsx(Ge,{onClick:V,disabled:P||p,className:s.createButton||"p-2",size:"sm",variant:"ghost",title:P?"Creating...":"New Chat",children:c.jsx(oe.MessageSquarePlus,{size:20})})}),c.jsx(Gh,{className:`flex-1 min-h-0 ${s.threadList||""}`,style:o?{maxHeight:o}:void 0,children:c.jsx("div",{className:"p-2 space-y-1 pb-4",children:p?c.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 py-8 text-slate-400",children:[c.jsx(oe.Loader2,{className:"h-5 w-5 animate-spin"}),c.jsx("span",{className:"text-sm",children:"Loading threads…"})]}):S.length===0?c.jsxs("div",{className:"text-center py-8 text-slate-400",children:[c.jsx(oe.MessageSquare,{className:"w-8 h-8 mx-auto mb-2 opacity-40 text-slate-500"}),c.jsx("p",{className:"text-sm text-slate-500",children:"No conversations yet"})]}):S.slice().sort((D,Q)=>new Date(Q.updatedAt||Q.createdAt||"").getTime()-new Date(D.updatedAt||D.createdAt||"").getTime()).map(D=>c.jsxs("div",{onClick:()=>F(D.threadId),className:`group relative p-3 rounded-lg cursor-pointer transition-colors border ${(i??h)===D.threadId?`${s.activeThread||"bg-slate-600 border-slate-500"} `:`${s.threadItem||"bg-slate-700 border-slate-600 hover:bg-slate-600 text-gray-900 dark:text-slate-100"}`} ${s.threadItem||""} text-gray-900 dark:text-slate-100`,children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("div",{className:"flex-1 min-w-0",children:k===D.threadId?c.jsxs("div",{className:"flex items-center gap-2",onClick:Q=>Q.stopPropagation(),children:[c.jsx(Hs,{value:A,onChange:Q=>j(Q.target.value),onKeyDown:Q=>B(Q,D.threadId),className:"h-6 text-sm",autoFocus:!0}),c.jsx(Ge,{variant:"ghost",size:"sm",onClick:()=>q(D.threadId),className:"h-6 w-6 p-0",children:c.jsx(oe.Check,{size:12})}),c.jsx(Ge,{variant:"ghost",size:"sm",onClick:U,className:"h-6 w-6 p-0",children:c.jsx(oe.X,{size:12})})]}):c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"font-medium text-sm truncate text-gray-900 dark:text-slate-100",children:ce(D)}),c.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500 dark:text-slate-400 mt-1",children:[c.jsx(oe.Calendar,{size:10}),c.jsx("span",{children:$(D.updatedAt||D.createdAt)})]})]})}),c.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity ml-2",children:[r&&k!==D.threadId&&c.jsx(Ge,{variant:"ghost",size:"sm",onClick:Q=>G(D,Q),className:"h-6 w-6 p-0",title:"Edit title",children:c.jsx(oe.Edit3,{size:12})}),n&&c.jsx(Ge,{variant:"ghost",size:"sm",onClick:Q=>M(D.threadId,Q),className:"h-6 w-6 p-0 text-red-400 hover:text-red-300 hover:bg-red-900/20",title:"Delete thread",children:c.jsx(oe.Trash2,{size:12})})]})]}),i===D.threadId&&c.jsx("div",{className:"absolute left-0 top-1/2 -translate-y-1/2 w-1 h-8 bg-blue-400 rounded-r"})]},D.threadId))})})]})}function Pr(e){if(!(typeof globalThis>"u"))return globalThis[e]}function cC(e){if(typeof e!="string")return;const t=e.trim();if(t)return En(t)}function Xh(){const e=[Pr("__API_BASE_URL__"),Pr("__CHAT_API_BASE_URL__"),Pr("__CHAT_API_URL__")];for(const t of e){const n=cC(t);if(n)return n}}function Jh(){const e=[Pr("__API_AUTH_TOKEN__"),Pr("__CHAT_API_KEY__"),Pr("__CHAT_AUTH_TOKEN__")];for(const t of e)if(typeof t=="string"&&t.trim())return t.trim()}function Zh(...e){for(const t of e)if(typeof t=="string"&&t.trim())return En(t);return En()}function Qh(){const e={},t=Xh(),n=Jh();return t&&(e.baseUrl=t),n&&(e.apiKey=n),e}function ep(){const e=Qh(),t=Pn.getAuthToken(),n=Xh();return{apiBaseUrl:Zh(e.baseUrl,Pn.baseUrl,n),apiKey:t||e.apiKey||Jh()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,truncateToolMessages:!0,toolMessagePreviewLength:200,darkMode:!1,enableSound:!1,messageHistory:100}}const tp="chat-settings";function uC(){try{const e=localStorage.getItem(tp);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function dC(e){try{const t={...e,apiBaseUrl:En(e.apiBaseUrl)};localStorage.setItem(tp,JSON.stringify(t)),t.apiKey&&Pn.setAuthToken(t.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function fC(){const e=ep(),t=uC(),n=Pn.getAuthToken(),r=typeof t.apiBaseUrl=="string"?t.apiBaseUrl:void 0;return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:Zh(Pn.baseUrl,r,e.apiBaseUrl)}}function hC(e){Pn.updateConfig({baseUrl:e.apiBaseUrl,authToken:e.apiKey??void 0}),dC(e)}var pC="Label",np=m.forwardRef((e,t)=>c.jsx(_e.label,{...e,ref:t,onMouseDown:n=>{var o;n.target.closest("button, input, select, textarea")||((o=e.onMouseDown)==null||o.call(e,n),!n.defaultPrevented&&n.detail>1&&n.preventDefault())}}));np.displayName=pC;var rp=np;const mC=bo.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),Jt=m.forwardRef(({className:e,...t},n)=>c.jsx(rp,{ref:n,className:Z(mC(),e),...t}));Jt.displayName=rp.displayName;function op(e){const t=m.useRef({value:e,previous:e});return m.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}var Ks="Switch",[gC,BT]=xn(Ks),[xC,vC]=gC(Ks),sp=m.forwardRef((e,t)=>{const{__scopeSwitch:n,name:r,checked:o,defaultChecked:s,required:i,disabled:a,value:l="on",onCheckedChange:u,form:d,...f}=e,[h,p]=m.useState(null),w=Ve(t,S=>p(S)),x=m.useRef(!1),g=h?d||!!h.closest("form"):!0,[v,b]=or({prop:o,defaultProp:s??!1,onChange:u,caller:Ks});return c.jsxs(xC,{scope:n,checked:v,disabled:a,children:[c.jsx(_e.button,{type:"button",role:"switch","aria-checked":v,"aria-required":i,"data-state":cp(v),"data-disabled":a?"":void 0,disabled:a,value:l,...f,ref:w,onClick:ue(e.onClick,S=>{b(N=>!N),g&&(x.current=S.isPropagationStopped(),x.current||S.stopPropagation())})}),g&&c.jsx(lp,{control:h,bubbles:!x.current,name:r,value:l,checked:v,required:i,disabled:a,form:d,style:{transform:"translateX(-100%)"}})]})});sp.displayName=Ks;var ip="SwitchThumb",ap=m.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,o=vC(ip,n);return c.jsx(_e.span,{"data-state":cp(o.checked),"data-disabled":o.disabled?"":void 0,...r,ref:t})});ap.displayName=ip;var wC="SwitchBubbleInput",lp=m.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...o},s)=>{const i=m.useRef(null),a=Ve(i,s),l=op(n),u=wf(t);return m.useEffect(()=>{const d=i.current;if(!d)return;const f=window.HTMLInputElement.prototype,p=Object.getOwnPropertyDescriptor(f,"checked").set;if(l!==n&&p){const w=new Event("click",{bubbles:r});p.call(d,n),d.dispatchEvent(w)}},[l,n,r]),c.jsx("input",{type:"checkbox","aria-hidden":!0,defaultChecked:n,...o,tabIndex:-1,ref:a,style:{...o.style,...u,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});lp.displayName=wC;function cp(e){return e?"checked":"unchecked"}var up=sp,bC=ap;const Un=m.forwardRef(({className:e,...t},n)=>c.jsx(up,{className:Z("peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",e),...t,ref:n,children:c.jsx(bC,{className:Z("pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0")})}));Un.displayName=up.displayName;var dp=Object.freeze({position:"absolute",border:0,width:1,height:1,padding:0,margin:-1,overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",wordWrap:"normal"}),yC="VisuallyHidden",SC=m.forwardRef((e,t)=>c.jsx(_e.span,{...e,ref:t,style:{...dp,...e.style}}));SC.displayName=yC;var CC=[" ","Enter","ArrowUp","ArrowDown"],TC=[" ","Enter"],fr="Select",[Gs,Ys,kC]=ka(fr),[Or,zT]=xn(fr,[kC,Ms]),Xs=Ms(),[EC,Wn]=Or(fr),[IC,NC]=Or(fr),fp=e=>{const{__scopeSelect:t,children:n,open:r,defaultOpen:o,onOpenChange:s,value:i,defaultValue:a,onValueChange:l,dir:u,name:d,autoComplete:f,disabled:h,required:p,form:w}=e,x=Xs(t),[g,v]=m.useState(null),[b,S]=m.useState(null),[N,C]=m.useState(!1),k=Ts(u),[I,A]=or({prop:r,defaultProp:o??!1,onChange:s,caller:fr}),[j,P]=or({prop:i,defaultProp:a,onChange:l,caller:fr}),L=m.useRef(null),F=g?w||!!g.closest("form"):!0,[V,M]=m.useState(new Set),G=Array.from(V).map(q=>q.props.value).join(";");return c.jsx(Af,{...x,children:c.jsxs(EC,{required:p,scope:t,trigger:g,onTriggerChange:v,valueNode:b,onValueNodeChange:S,valueNodeHasChildren:N,onValueNodeHasChildrenChange:C,contentId:vn(),value:j,onValueChange:P,open:I,onOpenChange:A,dir:k,triggerPointerDownPosRef:L,disabled:h,children:[c.jsx(Gs.Provider,{scope:t,children:c.jsx(IC,{scope:e.__scopeSelect,onNativeOptionAdd:m.useCallback(q=>{M(U=>new Set(U).add(q))},[]),onNativeOptionRemove:m.useCallback(q=>{M(U=>{const B=new Set(U);return B.delete(q),B})},[]),children:n})}),F?c.jsxs(Dp,{"aria-hidden":!0,required:p,tabIndex:-1,name:d,autoComplete:f,value:j,onChange:q=>P(q.target.value),disabled:h,form:w,children:[j===void 0?c.jsx("option",{value:""}):null,Array.from(V)]},G):null]})})};fp.displayName=fr;var hp="SelectTrigger",pp=m.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...o}=e,s=Xs(n),i=Wn(hp,n),a=i.disabled||r,l=Ve(t,i.onTriggerChange),u=Ys(n),d=m.useRef("touch"),[f,h,p]=Fp(x=>{const g=u().filter(S=>!S.disabled),v=g.find(S=>S.value===i.value),b=$p(g,x,v);b!==void 0&&i.onValueChange(b.value)}),w=x=>{a||(i.onOpenChange(!0),p()),x&&(i.triggerPointerDownPosRef.current={x:Math.round(x.pageX),y:Math.round(x.pageY)})};return c.jsx(_f,{asChild:!0,...s,children:c.jsx(_e.button,{type:"button",role:"combobox","aria-controls":i.contentId,"aria-expanded":i.open,"aria-required":i.required,"aria-autocomplete":"none",dir:i.dir,"data-state":i.open?"open":"closed",disabled:a,"data-disabled":a?"":void 0,"data-placeholder":Lp(i.value)?"":void 0,...o,ref:l,onClick:ue(o.onClick,x=>{x.currentTarget.focus(),d.current!=="mouse"&&w(x)}),onPointerDown:ue(o.onPointerDown,x=>{d.current=x.pointerType;const g=x.target;g.hasPointerCapture(x.pointerId)&&g.releasePointerCapture(x.pointerId),x.button===0&&x.ctrlKey===!1&&x.pointerType==="mouse"&&(w(x),x.preventDefault())}),onKeyDown:ue(o.onKeyDown,x=>{const g=f.current!=="";!(x.ctrlKey||x.altKey||x.metaKey)&&x.key.length===1&&h(x.key),!(g&&x.key===" ")&&CC.includes(x.key)&&(w(),x.preventDefault())})})})});pp.displayName=hp;var mp="SelectValue",gp=m.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,children:s,placeholder:i="",...a}=e,l=Wn(mp,n),{onValueNodeHasChildrenChange:u}=l,d=s!==void 0,f=Ve(t,l.onValueNodeChange);return Ct(()=>{u(d)},[u,d]),c.jsx(_e.span,{...a,ref:f,style:{pointerEvents:"none"},children:Lp(l.value)?c.jsx(c.Fragment,{children:i}):s})});gp.displayName=mp;var AC="SelectIcon",xp=m.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...o}=e;return c.jsx(_e.span,{"aria-hidden":!0,...o,ref:t,children:r||"▼"})});xp.displayName=AC;var _C="SelectPortal",vp=e=>c.jsx(ls,{asChild:!0,...e});vp.displayName=_C;var hr="SelectContent",wp=m.forwardRef((e,t)=>{const n=Wn(hr,e.__scopeSelect),[r,o]=m.useState();if(Ct(()=>{o(new DocumentFragment)},[]),!n.open){const s=r;return s?yo.createPortal(c.jsx(bp,{scope:e.__scopeSelect,children:c.jsx(Gs.Slot,{scope:e.__scopeSelect,children:c.jsx("div",{children:e.children})})}),s):null}return c.jsx(yp,{...e,ref:t})});wp.displayName=hr;var un=10,[bp,Vn]=Or(hr),jC="SelectContentImpl",RC=Xn.createSlot("SelectContent.RemoveScroll"),yp=m.forwardRef((e,t)=>{const{__scopeSelect:n,position:r="item-aligned",onCloseAutoFocus:o,onEscapeKeyDown:s,onPointerDownOutside:i,side:a,sideOffset:l,align:u,alignOffset:d,arrowPadding:f,collisionBoundary:h,collisionPadding:p,sticky:w,hideWhenDetached:x,avoidCollisions:g,...v}=e,b=Wn(hr,n),[S,N]=m.useState(null),[C,k]=m.useState(null),I=Ve(t,K=>N(K)),[A,j]=m.useState(null),[P,L]=m.useState(null),F=Ys(n),[V,M]=m.useState(!1),G=m.useRef(!1);m.useEffect(()=>{if(S)return wa(S)},[S]),ha();const q=m.useCallback(K=>{const[O,...X]=F().map(ne=>ne.ref.current),[ee]=X.slice(-1),fe=document.activeElement;for(const ne of K)if(ne===fe||(ne==null||ne.scrollIntoView({block:"nearest"}),ne===O&&C&&(C.scrollTop=0),ne===ee&&C&&(C.scrollTop=C.scrollHeight),ne==null||ne.focus(),document.activeElement!==fe))return},[F,C]),U=m.useCallback(()=>q([A,S]),[q,A,S]);m.useEffect(()=>{V&&U()},[V,U]);const{onOpenChange:B,triggerPointerDownPosRef:$}=b;m.useEffect(()=>{if(S){let K={x:0,y:0};const O=ee=>{var fe,ne;K={x:Math.abs(Math.round(ee.pageX)-(((fe=$.current)==null?void 0:fe.x)??0)),y:Math.abs(Math.round(ee.pageY)-(((ne=$.current)==null?void 0:ne.y)??0))}},X=ee=>{K.x<=10&&K.y<=10?ee.preventDefault():S.contains(ee.target)||B(!1),document.removeEventListener("pointermove",O),$.current=null};return $.current!==null&&(document.addEventListener("pointermove",O),document.addEventListener("pointerup",X,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",O),document.removeEventListener("pointerup",X,{capture:!0})}}},[S,B,$]),m.useEffect(()=>{const K=()=>B(!1);return window.addEventListener("blur",K),window.addEventListener("resize",K),()=>{window.removeEventListener("blur",K),window.removeEventListener("resize",K)}},[B]);const[ce,D]=Fp(K=>{const O=F().filter(fe=>!fe.disabled),X=O.find(fe=>fe.ref.current===document.activeElement),ee=$p(O,K,X);ee&&setTimeout(()=>ee.ref.current.focus())}),Q=m.useCallback((K,O,X)=>{const ee=!G.current&&!X;(b.value!==void 0&&b.value===O||ee)&&(j(K),ee&&(G.current=!0))},[b.value]),de=m.useCallback(()=>S==null?void 0:S.focus(),[S]),we=m.useCallback((K,O,X)=>{const ee=!G.current&&!X;(b.value!==void 0&&b.value===O||ee)&&L(K)},[b.value]),ye=r==="popper"?nl:Sp,Se=ye===nl?{side:a,sideOffset:l,align:u,alignOffset:d,arrowPadding:f,collisionBoundary:h,collisionPadding:p,sticky:w,hideWhenDetached:x,avoidCollisions:g}:{};return c.jsx(bp,{scope:n,content:S,viewport:C,onViewportChange:k,itemRefCallback:Q,selectedItem:A,onItemLeave:de,itemTextRefCallback:we,focusSelectedItem:U,selectedItemText:P,position:r,isPositioned:V,searchRef:ce,children:c.jsx(ps,{as:RC,allowPinchZoom:!0,children:c.jsx(as,{asChild:!0,trapped:b.open,onMountAutoFocus:K=>{K.preventDefault()},onUnmountAutoFocus:ue(o,K=>{var O;(O=b.trigger)==null||O.focus({preventScroll:!0}),K.preventDefault()}),children:c.jsx(is,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:K=>K.preventDefault(),onDismiss:()=>b.onOpenChange(!1),children:c.jsx(ye,{role:"listbox",id:b.contentId,"data-state":b.open?"open":"closed",dir:b.dir,onContextMenu:K=>K.preventDefault(),...v,...Se,onPlaced:()=>M(!0),ref:I,style:{display:"flex",flexDirection:"column",outline:"none",...v.style},onKeyDown:ue(v.onKeyDown,K=>{const O=K.ctrlKey||K.altKey||K.metaKey;if(K.key==="Tab"&&K.preventDefault(),!O&&K.key.length===1&&D(K.key),["ArrowUp","ArrowDown","Home","End"].includes(K.key)){let ee=F().filter(fe=>!fe.disabled).map(fe=>fe.ref.current);if(["ArrowUp","End"].includes(K.key)&&(ee=ee.slice().reverse()),["ArrowUp","ArrowDown"].includes(K.key)){const fe=K.target,ne=ee.indexOf(fe);ee=ee.slice(ne+1)}setTimeout(()=>q(ee)),K.preventDefault()}})})})})})})});yp.displayName=jC;var PC="SelectItemAlignedPosition",Sp=m.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...o}=e,s=Wn(hr,n),i=Vn(hr,n),[a,l]=m.useState(null),[u,d]=m.useState(null),f=Ve(t,I=>d(I)),h=Ys(n),p=m.useRef(!1),w=m.useRef(!0),{viewport:x,selectedItem:g,selectedItemText:v,focusSelectedItem:b}=i,S=m.useCallback(()=>{if(s.trigger&&s.valueNode&&a&&u&&x&&g&&v){const I=s.trigger.getBoundingClientRect(),A=u.getBoundingClientRect(),j=s.valueNode.getBoundingClientRect(),P=v.getBoundingClientRect();if(s.dir!=="rtl"){const fe=P.left-A.left,ne=j.left-fe,pe=I.left-ne,Ze=I.width+pe,Qe=Math.max(Ze,A.width),Pe=window.innerWidth-un,He=Xa(ne,[un,Math.max(un,Pe-Qe)]);a.style.minWidth=Ze+"px",a.style.left=He+"px"}else{const fe=A.right-P.right,ne=window.innerWidth-j.right-fe,pe=window.innerWidth-I.right-ne,Ze=I.width+pe,Qe=Math.max(Ze,A.width),Pe=window.innerWidth-un,He=Xa(ne,[un,Math.max(un,Pe-Qe)]);a.style.minWidth=Ze+"px",a.style.right=He+"px"}const L=h(),F=window.innerHeight-un*2,V=x.scrollHeight,M=window.getComputedStyle(u),G=parseInt(M.borderTopWidth,10),q=parseInt(M.paddingTop,10),U=parseInt(M.borderBottomWidth,10),B=parseInt(M.paddingBottom,10),$=G+q+V+B+U,ce=Math.min(g.offsetHeight*5,$),D=window.getComputedStyle(x),Q=parseInt(D.paddingTop,10),de=parseInt(D.paddingBottom,10),we=I.top+I.height/2-un,ye=F-we,Se=g.offsetHeight/2,K=g.offsetTop+Se,O=G+q+K,X=$-O;if(O<=we){const fe=L.length>0&&g===L[L.length-1].ref.current;a.style.bottom="0px";const ne=u.clientHeight-x.offsetTop-x.offsetHeight,pe=Math.max(ye,Se+(fe?de:0)+ne+U),Ze=O+pe;a.style.height=Ze+"px"}else{const fe=L.length>0&&g===L[0].ref.current;a.style.top="0px";const pe=Math.max(we,G+x.offsetTop+(fe?Q:0)+Se)+X;a.style.height=pe+"px",x.scrollTop=O-we+x.offsetTop}a.style.margin=`${un}px 0`,a.style.minHeight=ce+"px",a.style.maxHeight=F+"px",r==null||r(),requestAnimationFrame(()=>p.current=!0)}},[h,s.trigger,s.valueNode,a,u,x,g,v,s.dir,r]);Ct(()=>S(),[S]);const[N,C]=m.useState();Ct(()=>{u&&C(window.getComputedStyle(u).zIndex)},[u]);const k=m.useCallback(I=>{I&&w.current===!0&&(S(),b==null||b(),w.current=!1)},[S,b]);return c.jsx(MC,{scope:n,contentWrapper:a,shouldExpandOnScrollRef:p,onScrollButtonChange:k,children:c.jsx("div",{ref:l,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:N},children:c.jsx(_e.div,{...o,ref:f,style:{boxSizing:"border-box",maxHeight:"100%",...o.style}})})})});Sp.displayName=PC;var OC="SelectPopperPosition",nl=m.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=un,...s}=e,i=Xs(n);return c.jsx(jf,{...i,...s,ref:t,align:r,collisionPadding:o,style:{boxSizing:"border-box",...s.style,"--radix-select-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-select-content-available-width":"var(--radix-popper-available-width)","--radix-select-content-available-height":"var(--radix-popper-available-height)","--radix-select-trigger-width":"var(--radix-popper-anchor-width)","--radix-select-trigger-height":"var(--radix-popper-anchor-height)"}})});nl.displayName=OC;var[MC,rl]=Or(hr,{}),ol="SelectViewport",Cp=m.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...o}=e,s=Vn(ol,n),i=rl(ol,n),a=Ve(t,s.onViewportChange),l=m.useRef(0);return c.jsxs(c.Fragment,{children:[c.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}"},nonce:r}),c.jsx(Gs.Slot,{scope:n,children:c.jsx(_e.div,{"data-radix-select-viewport":"",role:"presentation",...o,ref:a,style:{position:"relative",flex:1,overflow:"hidden auto",...o.style},onScroll:ue(o.onScroll,u=>{const d=u.currentTarget,{contentWrapper:f,shouldExpandOnScrollRef:h}=i;if(h!=null&&h.current&&f){const p=Math.abs(l.current-d.scrollTop);if(p>0){const w=window.innerHeight-un*2,x=parseFloat(f.style.minHeight),g=parseFloat(f.style.height),v=Math.max(x,g);if(v<w){const b=v+p,S=Math.min(w,b),N=b-S;f.style.height=S+"px",f.style.bottom==="0px"&&(d.scrollTop=N>0?N:0,f.style.justifyContent="flex-end")}}}l.current=d.scrollTop})})})]})});Cp.displayName=ol;var Tp="SelectGroup",[DC,LC]=Or(Tp),FC=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=vn();return c.jsx(DC,{scope:n,id:o,children:c.jsx(_e.div,{role:"group","aria-labelledby":o,...r,ref:t})})});FC.displayName=Tp;var kp="SelectLabel",Ep=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=LC(kp,n);return c.jsx(_e.div,{id:o.id,...r,ref:t})});Ep.displayName=kp;var Js="SelectItem",[$C,Ip]=Or(Js),Np=m.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:s,...i}=e,a=Wn(Js,n),l=Vn(Js,n),u=a.value===r,[d,f]=m.useState(s??""),[h,p]=m.useState(!1),w=Ve(t,b=>{var S;return(S=l.itemRefCallback)==null?void 0:S.call(l,b,r,o)}),x=vn(),g=m.useRef("touch"),v=()=>{o||(a.onValueChange(r),a.onOpenChange(!1))};if(r==="")throw new Error("A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.");return c.jsx($C,{scope:n,value:r,disabled:o,textId:x,isSelected:u,onItemTextChange:m.useCallback(b=>{f(S=>S||((b==null?void 0:b.textContent)??"").trim())},[]),children:c.jsx(Gs.ItemSlot,{scope:n,value:r,disabled:o,textValue:d,children:c.jsx(_e.div,{role:"option","aria-labelledby":x,"data-highlighted":h?"":void 0,"aria-selected":u&&h,"data-state":u?"checked":"unchecked","aria-disabled":o||void 0,"data-disabled":o?"":void 0,tabIndex:o?void 0:-1,...i,ref:w,onFocus:ue(i.onFocus,()=>p(!0)),onBlur:ue(i.onBlur,()=>p(!1)),onClick:ue(i.onClick,()=>{g.current!=="mouse"&&v()}),onPointerUp:ue(i.onPointerUp,()=>{g.current==="mouse"&&v()}),onPointerDown:ue(i.onPointerDown,b=>{g.current=b.pointerType}),onPointerMove:ue(i.onPointerMove,b=>{var S;g.current=b.pointerType,o?(S=l.onItemLeave)==null||S.call(l):g.current==="mouse"&&b.currentTarget.focus({preventScroll:!0})}),onPointerLeave:ue(i.onPointerLeave,b=>{var S;b.currentTarget===document.activeElement&&((S=l.onItemLeave)==null||S.call(l))}),onKeyDown:ue(i.onKeyDown,b=>{var N;((N=l.searchRef)==null?void 0:N.current)!==""&&b.key===" "||(TC.includes(b.key)&&v(),b.key===" "&&b.preventDefault())})})})})});Np.displayName=Js;var vo="SelectItemText",Ap=m.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,...s}=e,i=Wn(vo,n),a=Vn(vo,n),l=Ip(vo,n),u=NC(vo,n),[d,f]=m.useState(null),h=Ve(t,v=>f(v),l.onItemTextChange,v=>{var b;return(b=a.itemTextRefCallback)==null?void 0:b.call(a,v,l.value,l.disabled)}),p=d==null?void 0:d.textContent,w=m.useMemo(()=>c.jsx("option",{value:l.value,disabled:l.disabled,children:p},l.value),[l.disabled,l.value,p]),{onNativeOptionAdd:x,onNativeOptionRemove:g}=u;return Ct(()=>(x(w),()=>g(w)),[x,g,w]),c.jsxs(c.Fragment,{children:[c.jsx(_e.span,{id:l.textId,...s,ref:h}),l.isSelected&&i.valueNode&&!i.valueNodeHasChildren?yo.createPortal(s.children,i.valueNode):null]})});Ap.displayName=vo;var _p="SelectItemIndicator",jp=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return Ip(_p,n).isSelected?c.jsx(_e.span,{"aria-hidden":!0,...r,ref:t}):null});jp.displayName=_p;var sl="SelectScrollUpButton",Rp=m.forwardRef((e,t)=>{const n=Vn(sl,e.__scopeSelect),r=rl(sl,e.__scopeSelect),[o,s]=m.useState(!1),i=Ve(t,r.onScrollButtonChange);return Ct(()=>{if(n.viewport&&n.isPositioned){let a=function(){const u=l.scrollTop>0;s(u)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?c.jsx(Op,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop-l.offsetHeight)}}):null});Rp.displayName=sl;var il="SelectScrollDownButton",Pp=m.forwardRef((e,t)=>{const n=Vn(il,e.__scopeSelect),r=rl(il,e.__scopeSelect),[o,s]=m.useState(!1),i=Ve(t,r.onScrollButtonChange);return Ct(()=>{if(n.viewport&&n.isPositioned){let a=function(){const u=l.scrollHeight-l.clientHeight,d=Math.ceil(l.scrollTop)<u;s(d)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?c.jsx(Op,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop+l.offsetHeight)}}):null});Pp.displayName=il;var Op=m.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...o}=e,s=Vn("SelectScrollButton",n),i=m.useRef(null),a=Ys(n),l=m.useCallback(()=>{i.current!==null&&(window.clearInterval(i.current),i.current=null)},[]);return m.useEffect(()=>()=>l(),[l]),Ct(()=>{var d;const u=a().find(f=>f.ref.current===document.activeElement);(d=u==null?void 0:u.ref.current)==null||d.scrollIntoView({block:"nearest"})},[a]),c.jsx(_e.div,{"aria-hidden":!0,...o,ref:t,style:{flexShrink:0,...o.style},onPointerDown:ue(o.onPointerDown,()=>{i.current===null&&(i.current=window.setInterval(r,50))}),onPointerMove:ue(o.onPointerMove,()=>{var u;(u=s.onItemLeave)==null||u.call(s),i.current===null&&(i.current=window.setInterval(r,50))}),onPointerLeave:ue(o.onPointerLeave,()=>{l()})})}),BC="SelectSeparator",Mp=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return c.jsx(_e.div,{"aria-hidden":!0,...r,ref:t})});Mp.displayName=BC;var al="SelectArrow",zC=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Xs(n),s=Wn(al,n),i=Vn(al,n);return s.open&&i.position==="popper"?c.jsx(Rf,{...o,...r,ref:t}):null});zC.displayName=al;var HC="SelectBubbleInput",Dp=m.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const o=m.useRef(null),s=Ve(r,o),i=op(t);return m.useEffect(()=>{const a=o.current;if(!a)return;const l=window.HTMLSelectElement.prototype,d=Object.getOwnPropertyDescriptor(l,"value").set;if(i!==t&&d){const f=new Event("change",{bubbles:!0});d.call(a,t),a.dispatchEvent(f)}},[i,t]),c.jsx(_e.select,{...n,style:{...dp,...n.style},ref:s,defaultValue:t})});Dp.displayName=HC;function Lp(e){return e===""||e===void 0}function Fp(e){const t=Tt(e),n=m.useRef(""),r=m.useRef(0),o=m.useCallback(i=>{const a=n.current+i;t(a),function l(u){n.current=u,window.clearTimeout(r.current),u!==""&&(r.current=window.setTimeout(()=>l(""),1e3))}(a)},[t]),s=m.useCallback(()=>{n.current="",window.clearTimeout(r.current)},[]);return m.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,o,s]}function $p(e,t,n){const o=t.length>1&&Array.from(t).every(u=>u===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let i=UC(e,Math.max(s,0));o.length===1&&(i=i.filter(u=>u!==n));const l=i.find(u=>u.textValue.toLowerCase().startsWith(o.toLowerCase()));return l!==n?l:void 0}function UC(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var WC=fp,Bp=pp,VC=gp,qC=xp,KC=vp,zp=wp,GC=Cp,Hp=Ep,Up=Np,YC=Ap,XC=jp,Wp=Rp,Vp=Pp,qp=Mp;const Kp=WC,Gp=VC,ll=m.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(Bp,{ref:r,className:Z("flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",e),...n,children:[t,c.jsx(qC,{asChild:!0,children:c.jsx(oe.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));ll.displayName=Bp.displayName;const Yp=m.forwardRef(({className:e,...t},n)=>c.jsx(Wp,{ref:n,className:Z("flex cursor-default items-center justify-center py-1",e),...t,children:c.jsx(oe.ChevronUp,{className:"h-4 w-4"})}));Yp.displayName=Wp.displayName;const Xp=m.forwardRef(({className:e,...t},n)=>c.jsx(Vp,{ref:n,className:Z("flex cursor-default items-center justify-center py-1",e),...t,children:c.jsx(oe.ChevronDown,{className:"h-4 w-4"})}));Xp.displayName=Vp.displayName;const cl=m.forwardRef(({className:e,children:t,position:n="popper",...r},o)=>c.jsx(KC,{children:c.jsxs(zp,{ref:o,className:Z("relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",n==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",e),position:n,...r,children:[c.jsx(Yp,{}),c.jsx(GC,{className:Z("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),c.jsx(Xp,{})]})}));cl.displayName=zp.displayName;const JC=m.forwardRef(({className:e,...t},n)=>c.jsx(Hp,{ref:n,className:Z("py-1.5 pl-8 pr-2 text-sm font-semibold",e),...t}));JC.displayName=Hp.displayName;const pr=m.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(Up,{ref:r,className:Z("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[c.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:c.jsx(XC,{children:c.jsx(oe.Check,{className:"h-4 w-4"})})}),c.jsx(YC,{children:t})]}));pr.displayName=Up.displayName;const ZC=m.forwardRef(({className:e,...t},n)=>c.jsx(qp,{ref:n,className:Z("-mx-1 my-1 h-px bg-muted",e),...t}));ZC.displayName=qp.displayName;var QC="Separator",Jp="horizontal",eT=["horizontal","vertical"],Zp=m.forwardRef((e,t)=>{const{decorative:n,orientation:r=Jp,...o}=e,s=tT(r)?r:Jp,a=n?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return c.jsx(_e.div,{"data-orientation":s,...a,...o,ref:t})});Zp.displayName=QC;function tT(e){return eT.includes(e)}var Qp=Zp;const em=m.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},o)=>c.jsx(Qp,{ref:o,decorative:n,orientation:t,className:Z("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));em.displayName=Qp.displayName;const nT=Dd,rT=Db,oT=Ld,tm=m.forwardRef(({className:e,...t},n)=>c.jsx(ws,{className:Z("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",e),...t,ref:n}));tm.displayName=ws.displayName;const sT=bo.cva("fixed z-50 gap-4 bg-background p-6 shadow-lg transition ease-in-out data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:duration-300 data-[state=open]:duration-500",{variants:{side:{top:"inset-x-0 top-0 border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",bottom:"inset-x-0 bottom-0 border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",left:"inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm",right:"inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm"}},defaultVariants:{side:"right"}}),nm=m.forwardRef(({side:e="right",className:t,children:n,...r},o)=>c.jsxs(oT,{children:[c.jsx(tm,{}),c.jsxs(bs,{ref:o,className:Z(sT({side:e}),t),...r,children:[n,c.jsxs(Fd,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-secondary",children:[c.jsx(oe.X,{className:"h-4 w-4"}),c.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));nm.displayName=bs.displayName;const rm=({className:e,...t})=>c.jsx("div",{className:Z("flex flex-col space-y-2 text-center sm:text-left",e),...t});rm.displayName="SheetHeader";const om=m.forwardRef(({className:e,...t},n)=>c.jsx(ar,{ref:n,className:Z("text-lg font-semibold text-foreground",e),...t}));om.displayName=ar.displayName;const sm=m.forwardRef(({className:e,...t},n)=>c.jsx(ys,{ref:n,className:Z("text-sm text-muted-foreground",e),...t}));sm.displayName=ys.displayName;const iT={api:{baseUrl:"http://localhost:8000/api",authToken:"",enableAuth:!1},ui:{layout:"sidebar",theme:"light",showTimestamps:!0,showAgentNames:!0,compactMessages:!1},behavior:{autoSave:!0,enableStreaming:!0,showTypingIndicator:!0}};function aT({settings:e,onSettingsChange:t,className:n=""}){const[r,o]=y.useState(!1),[s,i]=y.useState(!1),[a,l]=y.useState(e),[u,d]=y.useState(!1),{toast:f}=la();y.useEffect(()=>{const g=JSON.stringify(a)!==JSON.stringify(e);d(g)},[a,e]),y.useEffect(()=>{l(e)},[e]);const h=()=>{t(a),d(!1),f({title:"Settings saved",description:"Your chat configuration has been updated successfully."})},p=()=>{l(iT),d(!0),f({title:"Settings reset",description:"Configuration has been reset to defaults."})},w=()=>{l(e),d(!1),o(!1)},x=async()=>{try{const v=await(await fetch(`${a.api.baseUrl}/health`)).json();f({title:"Connection successful",description:`API is ${v.status||"healthy"}`})}catch{f({title:"Connection failed",description:"Unable to connect to the API endpoint.",variant:"destructive"})}};return c.jsxs(nT,{open:r,onOpenChange:o,children:[c.jsx(rT,{asChild:!0,children:c.jsxs(Ge,{variant:"outline",size:"sm",className:n,children:[c.jsx(oe.Settings,{className:"h-4 w-4 mr-2"}),"Settings",u&&c.jsx(Zi,{variant:"destructive",className:"ml-2 h-4 w-4 p-0"})]})}),c.jsxs(nm,{className:"w-[500px] sm:w-[600px] overflow-y-auto",children:[c.jsxs(rm,{children:[c.jsx(om,{children:"Chat Settings"}),c.jsx(sm,{children:"Configure your chat interface, API connection, and behavior preferences."})]}),c.jsxs("div",{className:"space-y-6 py-6",children:[c.jsxs(ro,{children:[c.jsx(oo,{className:"pb-3",children:c.jsxs(so,{className:"text-lg flex items-center gap-2",children:[c.jsx(oe.Server,{className:"h-5 w-5"}),"API Configuration"]})}),c.jsxs(Qo,{className:"space-y-4",children:[c.jsxs("div",{className:"space-y-2",children:[c.jsx(Jt,{htmlFor:"api-url",children:"API Base URL"}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx(Hs,{id:"api-url",value:a.api.baseUrl,onChange:g=>l(v=>({...v,api:{...v.api,baseUrl:g.target.value}})),placeholder:"http://localhost:8000/api"}),c.jsx(Ge,{variant:"outline",onClick:x,children:"Test"})]})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx(Jt,{htmlFor:"enable-auth",children:"Enable Authentication"}),c.jsx(Un,{id:"enable-auth",checked:a.api.enableAuth,onCheckedChange:g=>l(v=>({...v,api:{...v.api,enableAuth:g}}))})]}),a.api.enableAuth&&c.jsxs("div",{className:"space-y-2",children:[c.jsx(Jt,{htmlFor:"auth-token",children:"Authentication Token"}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx(Hs,{id:"auth-token",type:s?"text":"password",value:a.api.authToken,onChange:g=>l(v=>({...v,api:{...v.api,authToken:g.target.value}})),placeholder:"Enter your Bearer token"}),c.jsx(Ge,{variant:"outline",size:"icon",onClick:()=>i(!s),children:s?c.jsx(oe.EyeOff,{className:"h-4 w-4"}):c.jsx(oe.Eye,{className:"h-4 w-4"})})]})]})]})]}),c.jsxs(ro,{children:[c.jsx(oo,{className:"pb-3",children:c.jsxs(so,{className:"text-lg flex items-center gap-2",children:[c.jsx(oe.Layout,{className:"h-5 w-5"}),"Interface Settings"]})}),c.jsxs(Qo,{className:"space-y-4",children:[c.jsxs("div",{className:"space-y-2",children:[c.jsx(Jt,{htmlFor:"layout",children:"Layout Style"}),c.jsxs(Kp,{value:a.ui.layout,onValueChange:g=>l(v=>({...v,ui:{...v.ui,layout:g}})),children:[c.jsx(ll,{children:c.jsx(Gp,{})}),c.jsxs(cl,{children:[c.jsx(pr,{value:"sidebar",children:"Sidebar Layout"}),c.jsx(pr,{value:"fullscreen",children:"Fullscreen"}),c.jsx(pr,{value:"tabs",children:"Tabbed Interface"})]})]})]}),c.jsxs("div",{className:"space-y-2",children:[c.jsx(Jt,{htmlFor:"theme",children:"Theme"}),c.jsxs(Kp,{value:a.ui.theme,onValueChange:g=>l(v=>({...v,ui:{...v.ui,theme:g}})),children:[c.jsx(ll,{children:c.jsx(Gp,{})}),c.jsxs(cl,{children:[c.jsx(pr,{value:"light",children:"Light"}),c.jsx(pr,{value:"dark",children:"Dark"}),c.jsx(pr,{value:"system",children:"System"})]})]})]}),c.jsx(em,{}),c.jsxs("div",{className:"space-y-3",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx(Jt,{htmlFor:"show-timestamps",children:"Show Timestamps"}),c.jsx(Un,{id:"show-timestamps",checked:a.ui.showTimestamps,onCheckedChange:g=>l(v=>({...v,ui:{...v.ui,showTimestamps:g}}))})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx(Jt,{htmlFor:"show-agent-names",children:"Show Agent Names"}),c.jsx(Un,{id:"show-agent-names",checked:a.ui.showAgentNames,onCheckedChange:g=>l(v=>({...v,ui:{...v.ui,showAgentNames:g}}))})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx(Jt,{htmlFor:"compact-messages",children:"Compact Messages"}),c.jsx(Un,{id:"compact-messages",checked:a.ui.compactMessages,onCheckedChange:g=>l(v=>({...v,ui:{...v.ui,compactMessages:g}}))})]})]})]})]}),c.jsxs(ro,{children:[c.jsx(oo,{className:"pb-3",children:c.jsxs(so,{className:"text-lg flex items-center gap-2",children:[c.jsx(oe.MessageCircle,{className:"h-5 w-5"}),"Behavior Settings"]})}),c.jsxs(Qo,{className:"space-y-4",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx(Jt,{htmlFor:"auto-save",children:"Auto-save Conversations"}),c.jsx("p",{className:"text-sm text-muted-foreground",children:"Automatically save messages to threads"})]}),c.jsx(Un,{id:"auto-save",checked:a.behavior.autoSave,onCheckedChange:g=>l(v=>({...v,behavior:{...v.behavior,autoSave:g}}))})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx(Jt,{htmlFor:"enable-streaming",children:"Enable Streaming"}),c.jsx("p",{className:"text-sm text-muted-foreground",children:"Stream responses in real-time"})]}),c.jsx(Un,{id:"enable-streaming",checked:a.behavior.enableStreaming,onCheckedChange:g=>l(v=>({...v,behavior:{...v.behavior,enableStreaming:g}}))})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx(Jt,{htmlFor:"typing-indicator",children:"Typing Indicator"}),c.jsx("p",{className:"text-sm text-muted-foreground",children:"Show typing indicator during responses"})]}),c.jsx(Un,{id:"typing-indicator",checked:a.behavior.showTypingIndicator,onCheckedChange:g=>l(v=>({...v,behavior:{...v.behavior,showTypingIndicator:g}}))})]})]})]})]}),c.jsxs("div",{className:"flex items-center justify-between pt-6 border-t",children:[c.jsxs(Ge,{variant:"outline",onClick:p,children:[c.jsx(oe.RotateCcw,{className:"h-4 w-4 mr-2"}),"Reset"]}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx(Ge,{variant:"outline",onClick:w,children:"Cancel"}),c.jsxs(Ge,{onClick:h,disabled:!u,children:[c.jsx(oe.Save,{className:"h-4 w-4 mr-2"}),"Save Changes"]})]})]})]})]})}function lT({layout:e="sidebar",layoutSize:t="desktop",showThreads:n=!0,className:r="",customStyles:o={},...s}){const i=u=>{const d="h-full";switch(u){case"phone":return`${d} max-w-none`;case"tablet":return`${d} max-w-4xl mx-auto`;case"half-screen":return`${d} max-w-2xl`;case"desktop":default:return`${d} max-w-7xl mx-auto`}},a=u=>({"--chat-sidebar-width":u==="phone"?"100%":u==="tablet"?"280px":u==="half-screen"?"240px":"320px","--chat-message-max-width":u==="phone"?"95%":u==="tablet"?"90%":u==="half-screen"?"85%":"80%","--chat-input-height":u==="phone"?"120px":"100px"}),l=y.useCallback(u=>{var d;(d=s.onThreadChange)==null||d.call(s,u)},[s]);return e==="fullscreen"?c.jsx(Lo,{...s,onThreadChange:l,children:c.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:c.jsx(zs,{className:"flex-1",onError:s.onError,enableFileUpload:!0})})}):e==="tabs"?c.jsx(Lo,{...s,onThreadChange:l,children:c.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:c.jsxs("div",{className:"flex-1 flex min-h-0 overflow-hidden",children:[n&&c.jsx("div",{className:`w-80 border-r flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:c.jsx(tl,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),c.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:c.jsx(zs,{onError:s.onError,enableFileUpload:!0})})]})})}):c.jsx(Lo,{...s,onThreadChange:l,children:c.jsxs("div",{className:`${i(t)} flex overflow-hidden ${r} ${o.container||""}`,style:a(t),children:[n&&c.jsx("div",{className:`w-80 border-r bg-gray-50 flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:c.jsx(tl,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),c.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:c.jsx(zs,{onError:s.onError,enableFileUpload:!0})})]})})}je.ChatApi=sc,je.ChatInterface=zs,je.ChatProviders=Lo,je.ChatSettings=aT,je.MarkdownContent=sa,je.MessageComponent=Kd,je.MessageList=Ta,je.ThreadManager=tl,je.applySettings=hC,je.chatApiClient=Pn,je.default=lT,je.del=oc,je.get=nn,je.getChatToken=tc,je.getCurrentSettings=fC,je.getDefaultApiConfig=Qh,je.getDefaultChatSettings=ep,je.onChatTokenChanged=nc,je.post=gi,je.put=rc,je.setChatToken=mi,je.useApi=xi,je.useChatStream=bc,je.useMessagesReducer=dc,je.useStream=Ec,je.useThreadState=Do,je.useThreads=Mo,Object.defineProperties(je,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|