teodor-new-chat-ui 4.3.339 → 4.3.340
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/chat/TimelineColumn.d.ts +3 -1
- package/dist/index.esm.js +711 -701
- package/dist/index.umd.js +25 -25
- package/package.json +1 -1
package/dist/index.umd.js
CHANGED
|
@@ -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 qa;function Wh(){if(qa)return Nr;qa=1;var e=w,t=Symbol.for("react.element"),n=Symbol.for("react.fragment"),r=Object.prototype.hasOwnProperty,o=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,s={key:!0,ref:!0,__self:!0,__source:!0};function i(a,l,c){var d,f={},
|
|
9
|
+
*/var qa;function Wh(){if(qa)return Nr;qa=1;var e=w,t=Symbol.for("react.element"),n=Symbol.for("react.fragment"),r=Object.prototype.hasOwnProperty,o=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,s={key:!0,ref:!0,__self:!0,__source:!0};function i(a,l,c){var d,f={},h=null,p=null;c!==void 0&&(h=""+c),l.key!==void 0&&(h=""+l.key),l.ref!==void 0&&(p=l.ref);for(d in l)r.call(l,d)&&!s.hasOwnProperty(d)&&(f[d]=l[d]);if(a&&a.defaultProps)for(d in l=a.defaultProps,l)f[d]===void 0&&(f[d]=l[d]);return{$$typeof:t,type:a,key:h,ref:p,props:f,_owner:o.current}}return Nr.Fragment=n,Nr.jsx=i,Nr.jsxs=i,Nr}var _r={};/**
|
|
10
10
|
* @license React
|
|
11
11
|
* react-jsx-runtime.development.js
|
|
12
12
|
*
|
|
@@ -14,11 +14,11 @@
|
|
|
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 Ga;function Vh(){return Ga||(Ga=1,process.env.NODE_ENV!=="production"&&function(){var e=w,t=Symbol.for("react.element"),n=Symbol.for("react.portal"),r=Symbol.for("react.fragment"),o=Symbol.for("react.strict_mode"),s=Symbol.for("react.profiler"),i=Symbol.for("react.provider"),a=Symbol.for("react.context"),l=Symbol.for("react.forward_ref"),c=Symbol.for("react.suspense"),d=Symbol.for("react.suspense_list"),f=Symbol.for("react.memo"),
|
|
17
|
+
*/var Ga;function Vh(){return Ga||(Ga=1,process.env.NODE_ENV!=="production"&&function(){var e=w,t=Symbol.for("react.element"),n=Symbol.for("react.portal"),r=Symbol.for("react.fragment"),o=Symbol.for("react.strict_mode"),s=Symbol.for("react.profiler"),i=Symbol.for("react.provider"),a=Symbol.for("react.context"),l=Symbol.for("react.forward_ref"),c=Symbol.for("react.suspense"),d=Symbol.for("react.suspense_list"),f=Symbol.for("react.memo"),h=Symbol.for("react.lazy"),p=Symbol.for("react.offscreen"),x=Symbol.iterator,m="@@iterator";function y(E){if(E===null||typeof E!="object")return null;var W=x&&E[x]||E[m];return typeof W=="function"?W:null}var g=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function b(E){{for(var W=arguments.length,ie=new Array(W>1?W-1:0),be=1;be<W;be++)ie[be-1]=arguments[be];S("error",E,ie)}}function S(E,W,ie){{var be=g.ReactDebugCurrentFrame,Ke=be.getStackAddendum();Ke!==""&&(W+="%s",ie=ie.concat([Ke]));var rt=ie.map(function($e){return String($e)});rt.unshift("Warning: "+W),Function.prototype.apply.call(console[E],console,rt)}}var k=!1,C=!1,T=!1,I=!1,A=!1,R;R=Symbol.for("react.module.reference");function L(E){return!!(typeof E=="string"||typeof E=="function"||E===r||E===s||A||E===o||E===c||E===d||I||E===p||k||C||T||typeof E=="object"&&E!==null&&(E.$$typeof===h||E.$$typeof===f||E.$$typeof===i||E.$$typeof===a||E.$$typeof===l||E.$$typeof===R||E.getModuleId!==void 0))}function P(E,W,ie){var be=E.displayName;if(be)return be;var Ke=W.displayName||W.name||"";return Ke!==""?ie+"("+Ke+")":ie}function D(E){return E.displayName||"Context"}function F(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 c:return"Suspense";case d:return"SuspenseList"}if(typeof E=="object")switch(E.$$typeof){case a:var W=E;return D(W)+".Consumer";case i:var ie=E;return D(ie._context)+".Provider";case l:return P(E,E.render,"ForwardRef");case f:var be=E.displayName||null;return be!==null?be:F(E.type)||"Memo";case h:{var Ke=E,rt=Ke._payload,$e=Ke._init;try{return F($e(rt))}catch{return null}}}return null}var N=Object.assign,B=0,j,V,z,M,q,J,se;function ge(){}ge.__reactDisabledLog=!0;function Ee(){{if(B===0){j=console.log,V=console.info,z=console.warn,M=console.error,q=console.group,J=console.groupCollapsed,se=console.groupEnd;var E={configurable:!0,enumerable:!0,value:ge,writable:!0};Object.defineProperties(console,{info:E,log:E,warn:E,error:E,group:E,groupCollapsed:E,groupEnd:E})}B++}}function Y(){{if(B--,B===0){var E={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:N({},E,{value:j}),info:N({},E,{value:V}),warn:N({},E,{value:z}),error:N({},E,{value:M}),group:N({},E,{value:q}),groupCollapsed:N({},E,{value:J}),groupEnd:N({},E,{value:se})})}B<0&&b("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var U=g.ReactCurrentDispatcher,Z;function $(E,W,ie){{if(Z===void 0)try{throw Error()}catch(Ke){var be=Ke.stack.trim().match(/\n( *(at )?)/);Z=be&&be[1]||""}return`
|
|
18
18
|
`+Z+E}}var K=!1,Q;{var ce=typeof WeakMap=="function"?WeakMap:Map;Q=new ce}function oe(E,W){if(!E||K)return"";{var ie=Q.get(E);if(ie!==void 0)return ie}var be;K=!0;var Ke=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var rt;rt=U.current,U.current=null,Ee();try{if(W){var $e=function(){throw Error()};if(Object.defineProperty($e.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct($e,[])}catch(He){be=He}Reflect.construct(E,[],$e)}else{try{$e.call()}catch(He){be=He}E.call($e.prototype)}}else{try{throw Error()}catch(He){be=He}E()}}catch(He){if(He&&be&&typeof He.stack=="string"){for(var Le=He.stack.split(`
|
|
19
19
|
`),Et=be.stack.split(`
|
|
20
20
|
`),mt=Le.length-1,xt=Et.length-1;mt>=1&&xt>=0&&Le[mt]!==Et[xt];)xt--;for(;mt>=1&&xt>=0;mt--,xt--)if(Le[mt]!==Et[xt]){if(mt!==1||xt!==1)do if(mt--,xt--,xt<0||Le[mt]!==Et[xt]){var fe=`
|
|
21
|
-
`+Le[mt].replace(" at new "," at ");return E.displayName&&fe.includes("<anonymous>")&&(fe=fe.replace("<anonymous>",E.displayName)),typeof E=="function"&&Q.set(E,fe),fe}while(mt>=1&&xt>=0);break}}}finally{K=!1,U.current=rt,Y(),Error.prepareStackTrace=Ke}var Se=E?E.displayName||E.name:"",Ie=Se?$(Se):"";return typeof E=="function"&&Q.set(E,Ie),Ie}function Ne(E,W,ie){return oe(E,!1)}function Ue(E){var W=E.prototype;return!!(W&&W.isReactComponent)}function re(E,W,ie){if(E==null)return"";if(typeof E=="function")return oe(E,Ue(E));if(typeof E=="string")return $(E);switch(E){case c:return $("Suspense");case d:return $("SuspenseList")}if(typeof E=="object")switch(E.$$typeof){case l:return Ne(E.render);case f:return re(E.type,W,ie);case
|
|
21
|
+
`+Le[mt].replace(" at new "," at ");return E.displayName&&fe.includes("<anonymous>")&&(fe=fe.replace("<anonymous>",E.displayName)),typeof E=="function"&&Q.set(E,fe),fe}while(mt>=1&&xt>=0);break}}}finally{K=!1,U.current=rt,Y(),Error.prepareStackTrace=Ke}var Se=E?E.displayName||E.name:"",Ie=Se?$(Se):"";return typeof E=="function"&&Q.set(E,Ie),Ie}function Ne(E,W,ie){return oe(E,!1)}function Ue(E){var W=E.prototype;return!!(W&&W.isReactComponent)}function re(E,W,ie){if(E==null)return"";if(typeof E=="function")return oe(E,Ue(E));if(typeof E=="string")return $(E);switch(E){case c:return $("Suspense");case d:return $("SuspenseList")}if(typeof E=="object")switch(E.$$typeof){case l:return Ne(E.render);case f:return re(E.type,W,ie);case h:{var be=E,Ke=be._payload,rt=be._init;try{return re(rt(Ke),W,ie)}catch{}}}return""}var xe=Object.prototype.hasOwnProperty,Pe={},Ze=g.ReactDebugCurrentFrame;function Qe(E){if(E){var W=E._owner,ie=re(E.type,E._source,W?W.type:null);Ze.setExtraStackFrame(ie)}else Ze.setExtraStackFrame(null)}function Ve(E,W,ie,be,Ke){{var rt=Function.call.bind(xe);for(var $e in E)if(rt(E,$e)){var Le=void 0;try{if(typeof E[$e]!="function"){var Et=Error((be||"React class")+": "+ie+" type `"+$e+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof E[$e]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw Et.name="Invariant Violation",Et}Le=E[$e](W,$e,be,ie,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(mt){Le=mt}Le&&!(Le instanceof Error)&&(Qe(Ke),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).",be||"React class",ie,$e,typeof Le),Qe(null)),Le instanceof Error&&!(Le.message in Pe)&&(Pe[Le.message]=!0,Qe(Ke),b("Failed %s type: %s",ie,Le.message),Qe(null))}}}var tt=Array.isArray;function it(E){return tt(E)}function qe(E){{var W=typeof Symbol=="function"&&Symbol.toStringTag,ie=W&&E[Symbol.toStringTag]||E.constructor.name||"Object";return ie}}function nt(E){try{return at(E),!1}catch{return!0}}function at(E){return""+E}function Rt(E){if(nt(E))return b("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",qe(E)),at(E)}var gt=g.ReactCurrentOwner,ht={key:!0,ref:!0,__self:!0,__source:!0},bt,St;function Lt(E){if(xe.call(E,"ref")){var W=Object.getOwnPropertyDescriptor(E,"ref").get;if(W&&W.isReactWarning)return!1}return E.ref!==void 0}function Mt(E){if(xe.call(E,"key")){var W=Object.getOwnPropertyDescriptor(E,"key").get;if(W&&W.isReactWarning)return!1}return E.key!==void 0}function et(E,W){typeof E.ref=="string"&>.current}function It(E,W){{var ie=function(){bt||(bt=!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)",W))};ie.isReactWarning=!0,Object.defineProperty(E,"key",{get:ie,configurable:!0})}}function bn(E,W){{var ie=function(){St||(St=!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)",W))};ie.isReactWarning=!0,Object.defineProperty(E,"ref",{get:ie,configurable:!0})}}var Ge=function(E,W,ie,be,Ke,rt,$e){var Le={$$typeof:t,type:E,key:W,ref:ie,props:$e,_owner:rt};return Le._store={},Object.defineProperty(Le._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(Le,"_self",{configurable:!1,enumerable:!1,writable:!1,value:be}),Object.defineProperty(Le,"_source",{configurable:!1,enumerable:!1,writable:!1,value:Ke}),Object.freeze&&(Object.freeze(Le.props),Object.freeze(Le)),Le};function Ye(E,W,ie,be,Ke){{var rt,$e={},Le=null,Et=null;ie!==void 0&&(Rt(ie),Le=""+ie),Mt(W)&&(Rt(W.key),Le=""+W.key),Lt(W)&&(Et=W.ref,et(W,Ke));for(rt in W)xe.call(W,rt)&&!ht.hasOwnProperty(rt)&&($e[rt]=W[rt]);if(E&&E.defaultProps){var mt=E.defaultProps;for(rt in mt)$e[rt]===void 0&&($e[rt]=mt[rt])}if(Le||Et){var xt=typeof E=="function"?E.displayName||E.name||"Unknown":E;Le&&It($e,xt),Et&&bn($e,xt)}return Ge(E,Le,Et,Ke,be,gt.current,$e)}}var pt=g.ReactCurrentOwner,lt=g.ReactDebugCurrentFrame;function G(E){if(E){var W=E._owner,ie=re(E.type,E._source,W?W.type:null);lt.setExtraStackFrame(ie)}else lt.setExtraStackFrame(null)}var _;_=!1;function X(E){return typeof E=="object"&&E!==null&&E.$$typeof===t}function te(){{if(pt.current){var E=F(pt.current.type);if(E)return`
|
|
22
22
|
|
|
23
23
|
Check the render method of \``+E+"`."}return""}}function pe(E){return""}var ve={};function we(E){{var W=te();if(!W){var ie=typeof E=="string"?E:E.displayName||E.name;ie&&(W=`
|
|
24
24
|
|
|
@@ -27,15 +27,15 @@ Check the top-level render call using <`+ie+">.")}return W}}function Fe(E,W){{if
|
|
|
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} />`,Un,Ie,tn,Ie),En[Ie+Un]=!0}}return E===r?Vt(xt):je(xt),xt}}function Ar(E,W,ie){return ir(E,W,ie,!0)}function fo(E,W,ie){return ir(E,W,ie,!1)}var zn=fo,ar=Ar;_r.Fragment=r,_r.jsx=zn,_r.jsxs=ar}()),_r}process.env.NODE_ENV==="production"?Xs.exports=Wh():Xs.exports=Vh();var u=Xs.exports;function Ya(e,t){return function(){return e.apply(t,arguments)}}const{toString:Kh}=Object.prototype,{getPrototypeOf:Js}=Object,{iterator:mo,toStringTag:Xa}=Symbol,go=(e=>t=>{const n=Kh.call(t);return e[n]||(e[n]=n.slice(8,-1).toLowerCase())})(Object.create(null)),nn=e=>(e=e.toLowerCase(),t=>go(t)===e),xo=e=>t=>typeof t===e,{isArray:lr}=Array,cr=xo("undefined");function jr(e){return e!==null&&!cr(e)&&e.constructor!==null&&!cr(e.constructor)&&$t(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const Ja=nn("ArrayBuffer");function qh(e){let t;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?t=ArrayBuffer.isView(e):t=e&&e.buffer&&Ja(e.buffer),t}const Gh=xo("string"),$t=xo("function"),Za=xo("number"),Rr=e=>e!==null&&typeof e=="object",Yh=e=>e===!0||e===!1,yo=e=>{if(go(e)!=="object")return!1;const t=Js(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Xa in e)&&!(mo in e)},Xh=e=>{if(!Rr(e)||jr(e))return!1;try{return Object.keys(e).length===0&&Object.getPrototypeOf(e)===Object.prototype}catch{return!1}},Jh=nn("Date"),Zh=nn("File"),Qh=nn("Blob"),em=nn("FileList"),tm=e=>Rr(e)&&$t(e.pipe),nm=e=>{let t;return e&&(typeof FormData=="function"&&e instanceof FormData||$t(e.append)&&((t=go(e))==="formdata"||t==="object"&&$t(e.toString)&&e.toString()==="[object FormData]"))},rm=nn("URLSearchParams"),[om,sm,im,am]=["ReadableStream","Request","Response","Headers"].map(nn),lm=e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function Mr(e,t,{allOwnKeys:n=!1}={}){if(e===null||typeof e>"u")return;let r,o;if(typeof e!="object"&&(e=[e]),lr(e))for(r=0,o=e.length;r<o;r++)t.call(null,e[r],r,e);else{if(jr(e))return;const s=n?Object.getOwnPropertyNames(e):Object.keys(e),i=s.length;let a;for(r=0;r<i;r++)a=s[r],t.call(null,e[a],a,e)}}function Qa(e,t){if(jr(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 Wn=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global,el=e=>!cr(e)&&e!==Wn;function Zs(){const{caseless:e,skipUndefined:t}=el(this)&&this||{},n={},r=(o,s)=>{const i=e&&Qa(n,s)||s;yo(n[i])&&yo(o)?n[i]=Zs(n[i],o):yo(o)?n[i]=Zs({},o):lr(o)?n[i]=o.slice():(!t||!cr(o))&&(n[i]=o)};for(let o=0,s=arguments.length;o<s;o++)arguments[o]&&Mr(arguments[o],r);return n}const cm=(e,t,n,{allOwnKeys:r}={})=>(Mr(t,(o,s)=>{n&&$t(o)?e[s]=Ya(o,n):e[s]=o},{allOwnKeys:r}),e),um=e=>(e.charCodeAt(0)===65279&&(e=e.slice(1)),e),dm=(e,t,n,r)=>{e.prototype=Object.create(t.prototype,r),e.prototype.constructor=e,Object.defineProperty(e,"super",{value:t.prototype}),n&&Object.assign(e.prototype,n)},fm=(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&&Js(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},hm=e=>{if(!e)return null;if(lr(e))return e;let t=e.length;if(!Za(t))return null;const n=new Array(t);for(;t-- >0;)n[t]=e[t];return n},mm=(e=>t=>e&&t instanceof e)(typeof Uint8Array<"u"&&Js(Uint8Array)),gm=(e,t)=>{const r=(e&&e[mo]).call(e);let o;for(;(o=r.next())&&!o.done;){const s=o.value;t.call(e,s[0],s[1])}},xm=(e,t)=>{let n;const r=[];for(;(n=e.exec(t))!==null;)r.push(n);return r},ym=nn("HTMLFormElement"),vm=e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(n,r,o){return r.toUpperCase()+o}),tl=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),bm=nn("RegExp"),nl=(e,t)=>{const n=Object.getOwnPropertyDescriptors(e),r={};Mr(n,(o,s)=>{let i;(i=t(o,s,e))!==!1&&(r[s]=i||o)}),Object.defineProperties(e,r)},wm=e=>{nl(e,(t,n)=>{if($t(e)&&["arguments","caller","callee"].indexOf(n)!==-1)return!1;const r=e[n];if($t(r)){if(t.enumerable=!1,"writable"in t){t.writable=!1;return}t.set||(t.set=()=>{throw Error("Can not rewrite read-only method '"+n+"'")})}})},Sm=(e,t)=>{const n={},r=o=>{o.forEach(s=>{n[s]=!0})};return lr(e)?r(e):r(String(e).split(t)),n},Cm=()=>{},Tm=(e,t)=>e!=null&&Number.isFinite(e=+e)?e:t;function km(e){return!!(e&&$t(e.append)&&e[Xa]==="FormData"&&e[mo])}const Im=e=>{const t=new Array(10),n=(r,o)=>{if(Rr(r)){if(t.indexOf(r)>=0)return;if(jr(r))return r;if(!("toJSON"in r)){t[o]=r;const s=lr(r)?[]:{};return Mr(r,(i,a)=>{const l=n(i,o+1);!cr(l)&&(s[a]=l)}),t[o]=void 0,s}}return r};return n(e,0)},Em=nn("AsyncFunction"),Am=e=>e&&(Rr(e)||$t(e))&&$t(e.then)&&$t(e.catch),rl=((e,t)=>e?setImmediate:t?((n,r)=>(Wn.addEventListener("message",({source:o,data:s})=>{o===Wn&&s===n&&r.length&&r.shift()()},!1),o=>{r.push(o),Wn.postMessage(n,"*")}))(`axios@${Math.random()}`,[]):n=>setTimeout(n))(typeof setImmediate=="function",$t(Wn.postMessage)),Nm=typeof queueMicrotask<"u"?queueMicrotask.bind(Wn):typeof process<"u"&&process.nextTick||rl,O={isArray:lr,isArrayBuffer:Ja,isBuffer:jr,isFormData:nm,isArrayBufferView:qh,isString:Gh,isNumber:Za,isBoolean:Yh,isObject:Rr,isPlainObject:yo,isEmptyObject:Xh,isReadableStream:om,isRequest:sm,isResponse:im,isHeaders:am,isUndefined:cr,isDate:Jh,isFile:Zh,isBlob:Qh,isRegExp:bm,isFunction:$t,isStream:tm,isURLSearchParams:rm,isTypedArray:mm,isFileList:em,forEach:Mr,merge:Zs,extend:cm,trim:lm,stripBOM:um,inherits:dm,toFlatObject:fm,kindOf:go,kindOfTest:nn,endsWith:pm,toArray:hm,forEachEntry:gm,matchAll:xm,isHTMLForm:ym,hasOwnProperty:tl,hasOwnProp:tl,reduceDescriptors:nl,freezeMethods:wm,toObjectSet:Sm,toCamelCase:vm,noop:Cm,toFiniteNumber:Tm,findKey:Qa,global:Wn,isContextDefined:el,isSpecCompliantForm:km,toJSONObject:Im,isAsyncFn:Em,isThenable:Am,setImmediate:rl,asap:Nm,isIterable:e=>e!=null&&$t(e[mo])};function Re(e,t,n,r,o){Error.call(this),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=new Error().stack,this.message=e,this.name="AxiosError",t&&(this.code=t),n&&(this.config=n),r&&(this.request=r),o&&(this.response=o,this.status=o.status?o.status:null)}O.inherits(Re,Error,{toJSON:function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:O.toJSONObject(this.config),code:this.code,status:this.status}}});const ol=Re.prototype,sl={};["ERR_BAD_OPTION_VALUE","ERR_BAD_OPTION","ECONNABORTED","ETIMEDOUT","ERR_NETWORK","ERR_FR_TOO_MANY_REDIRECTS","ERR_DEPRECATED","ERR_BAD_RESPONSE","ERR_BAD_REQUEST","ERR_CANCELED","ERR_NOT_SUPPORT","ERR_INVALID_URL"].forEach(e=>{sl[e]={value:e}}),Object.defineProperties(Re,sl),Object.defineProperty(ol,"isAxiosError",{value:!0}),Re.from=(e,t,n,r,o,s)=>{const i=Object.create(ol);O.toFlatObject(e,i,function(d){return d!==Error.prototype},c=>c!=="isAxiosError");const a=e&&e.message?e.message:"Error",l=t==null&&e?e.code:t;return Re.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 _m=null;function Qs(e){return O.isPlainObject(e)||O.isArray(e)}function il(e){return O.endsWith(e,"[]")?e.slice(0,-2):e}function al(e,t,n){return e?e.concat(t).map(function(o,s){return o=il(o),!n&&s?"["+o+"]":o}).join(n?".":""):t}function jm(e){return O.isArray(e)&&!e.some(Qs)}const Rm=O.toFlatObject(O,{},null,function(t){return/^is[A-Z]/.test(t)});function vo(e,t,n){if(!O.isObject(e))throw new TypeError("target must be an object");t=t||new FormData,n=O.toFlatObject(n,{metaTokens:!0,dots:!1,indexes:!1},!1,function(m,y){return!O.isUndefined(y[m])});const r=n.metaTokens,o=n.visitor||d,s=n.dots,i=n.indexes,l=(n.Blob||typeof Blob<"u"&&Blob)&&O.isSpecCompliantForm(t);if(!O.isFunction(o))throw new TypeError("visitor must be a function");function c(x){if(x===null)return"";if(O.isDate(x))return x.toISOString();if(O.isBoolean(x))return x.toString();if(!l&&O.isBlob(x))throw new Re("Blob is not supported. Use a Buffer instead.");return O.isArrayBuffer(x)||O.isTypedArray(x)?l&&typeof Blob=="function"?new Blob([x]):Buffer.from(x):x}function d(x,m,y){let g=x;if(x&&!y&&typeof x=="object"){if(O.endsWith(m,"{}"))m=r?m:m.slice(0,-2),x=JSON.stringify(x);else if(O.isArray(x)&&jm(x)||(O.isFileList(x)||O.endsWith(m,"[]"))&&(g=O.toArray(x)))return m=il(m),g.forEach(function(S,k){!(O.isUndefined(S)||S===null)&&t.append(i===!0?al([m],k,s):i===null?m:m+"[]",c(S))}),!1}return Qs(x)?!0:(t.append(al(y,m,s),c(x)),!1)}const f=[],p=Object.assign(Rm,{defaultVisitor:d,convertValue:c,isVisitable:Qs});function h(x,m){if(!O.isUndefined(x)){if(f.indexOf(x)!==-1)throw Error("Circular reference detected in "+m.join("."));f.push(x),O.forEach(x,function(g,b){(!(O.isUndefined(g)||g===null)&&o.call(t,g,O.isString(b)?b.trim():b,m,p))===!0&&h(g,m?m.concat(b):[b])}),f.pop()}}if(!O.isObject(e))throw new TypeError("data must be an object");return h(e),t}function ll(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,function(r){return t[r]})}function ei(e,t){this._pairs=[],e&&vo(e,this,t)}const cl=ei.prototype;cl.append=function(t,n){this._pairs.push([t,n])},cl.toString=function(t){const n=t?function(r){return t.call(this,r,ll)}:ll;return this._pairs.map(function(o){return n(o[0])+"="+n(o[1])},"").join("&")};function Mm(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+")}function ul(e,t,n){if(!t)return e;const r=n&&n.encode||Mm;O.isFunction(n)&&(n={serialize:n});const o=n&&n.serialize;let s;if(o?s=o(t,n):s=O.isURLSearchParams(t)?t.toString():new ei(t,n).toString(r),s){const i=e.indexOf("#");i!==-1&&(e=e.slice(0,i)),e+=(e.indexOf("?")===-1?"?":"&")+s}return e}class dl{constructor(){this.handlers=[]}use(t,n,r){return this.handlers.push({fulfilled:t,rejected:n,synchronous:r?r.synchronous:!1,runWhen:r?r.runWhen:null}),this.handlers.length-1}eject(t){this.handlers[t]&&(this.handlers[t]=null)}clear(){this.handlers&&(this.handlers=[])}forEach(t){O.forEach(this.handlers,function(r){r!==null&&t(r)})}}const fl={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},Pm={isBrowser:!0,classes:{URLSearchParams:typeof URLSearchParams<"u"?URLSearchParams:ei,FormData:typeof FormData<"u"?FormData:null,Blob:typeof Blob<"u"?Blob:null},protocols:["http","https","file","blob","url","data"]},ti=typeof window<"u"&&typeof document<"u",ni=typeof navigator=="object"&&navigator||void 0,Om=ti&&(!ni||["ReactNative","NativeScript","NS"].indexOf(ni.product)<0),Dm=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function",Lm=ti&&window.location.href||"http://localhost",At={...Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv:ti,hasStandardBrowserEnv:Om,hasStandardBrowserWebWorkerEnv:Dm,navigator:ni,origin:Lm},Symbol.toStringTag,{value:"Module"})),...Pm};function $m(e,t){return vo(e,new At.classes.URLSearchParams,{visitor:function(n,r,o,s){return At.isNode&&O.isBuffer(n)?(this.append(r,n.toString("base64")),!1):s.defaultVisitor.apply(this,arguments)},...t})}function Fm(e){return O.matchAll(/\w+|\[(\w*)]/g,e).map(t=>t[0]==="[]"?"":t[1]||t[0])}function Bm(e){const t={},n=Object.keys(e);let r;const o=n.length;let s;for(r=0;r<o;r++)s=n[r],t[s]=e[s];return t}function pl(e){function t(n,r,o,s){let i=n[s++];if(i==="__proto__")return!0;const a=Number.isFinite(+i),l=s>=n.length;return i=!i&&O.isArray(o)?o.length:i,l?(O.hasOwnProp(o,i)?o[i]=[o[i],r]:o[i]=r,!a):((!o[i]||!O.isObject(o[i]))&&(o[i]=[]),t(n,r,o[i],s)&&O.isArray(o[i])&&(o[i]=Bm(o[i])),!a)}if(O.isFormData(e)&&O.isFunction(e.entries)){const n={};return O.forEachEntry(e,(r,o)=>{t(Fm(r),o,n,0)}),n}return null}function zm(e,t,n){if(O.isString(e))try{return(t||JSON.parse)(e),O.trim(e)}catch(r){if(r.name!=="SyntaxError")throw r}return(n||JSON.stringify)(e)}const Pr={transitional:fl,adapter:["xhr","http","fetch"],transformRequest:[function(t,n){const r=n.getContentType()||"",o=r.indexOf("application/json")>-1,s=O.isObject(t);if(s&&O.isHTMLForm(t)&&(t=new FormData(t)),O.isFormData(t))return o?JSON.stringify(pl(t)):t;if(O.isArrayBuffer(t)||O.isBuffer(t)||O.isStream(t)||O.isFile(t)||O.isBlob(t)||O.isReadableStream(t))return t;if(O.isArrayBufferView(t))return t.buffer;if(O.isURLSearchParams(t))return n.setContentType("application/x-www-form-urlencoded;charset=utf-8",!1),t.toString();let a;if(s){if(r.indexOf("application/x-www-form-urlencoded")>-1)return $m(t,this.formSerializer).toString();if((a=O.isFileList(t))||r.indexOf("multipart/form-data")>-1){const l=this.env&&this.env.FormData;return vo(a?{"files[]":t}:t,l&&new l,this.formSerializer)}}return s||o?(n.setContentType("application/json",!1),zm(t)):t}],transformResponse:[function(t){const n=this.transitional||Pr.transitional,r=n&&n.forcedJSONParsing,o=this.responseType==="json";if(O.isResponse(t)||O.isReadableStream(t))return t;if(t&&O.isString(t)&&(r&&!this.responseType||o)){const i=!(n&&n.silentJSONParsing)&&o;try{return JSON.parse(t,this.parseReviver)}catch(a){if(i)throw a.name==="SyntaxError"?Re.from(a,Re.ERR_BAD_RESPONSE,this,null,this.response):a}}return t}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:At.classes.FormData,Blob:At.classes.Blob},validateStatus:function(t){return t>=200&&t<300},headers:{common:{Accept:"application/json, text/plain, */*","Content-Type":void 0}}};O.forEach(["delete","get","head","post","put","patch"],e=>{Pr.headers[e]={}});const Um=O.toObjectSet(["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"]),Hm=e=>{const t={};let n,r,o;return e&&e.split(`
|
|
30
|
+
<%s key={someKey} {...props} />`,Un,Ie,tn,Ie),En[Ie+Un]=!0}}return E===r?Vt(xt):je(xt),xt}}function Ar(E,W,ie){return ir(E,W,ie,!0)}function fo(E,W,ie){return ir(E,W,ie,!1)}var zn=fo,ar=Ar;_r.Fragment=r,_r.jsx=zn,_r.jsxs=ar}()),_r}process.env.NODE_ENV==="production"?Xs.exports=Wh():Xs.exports=Vh();var u=Xs.exports;function Ya(e,t){return function(){return e.apply(t,arguments)}}const{toString:Kh}=Object.prototype,{getPrototypeOf:Js}=Object,{iterator:mo,toStringTag:Xa}=Symbol,go=(e=>t=>{const n=Kh.call(t);return e[n]||(e[n]=n.slice(8,-1).toLowerCase())})(Object.create(null)),nn=e=>(e=e.toLowerCase(),t=>go(t)===e),xo=e=>t=>typeof t===e,{isArray:lr}=Array,cr=xo("undefined");function jr(e){return e!==null&&!cr(e)&&e.constructor!==null&&!cr(e.constructor)&&$t(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const Ja=nn("ArrayBuffer");function qh(e){let t;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?t=ArrayBuffer.isView(e):t=e&&e.buffer&&Ja(e.buffer),t}const Gh=xo("string"),$t=xo("function"),Za=xo("number"),Rr=e=>e!==null&&typeof e=="object",Yh=e=>e===!0||e===!1,yo=e=>{if(go(e)!=="object")return!1;const t=Js(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Xa in e)&&!(mo in e)},Xh=e=>{if(!Rr(e)||jr(e))return!1;try{return Object.keys(e).length===0&&Object.getPrototypeOf(e)===Object.prototype}catch{return!1}},Jh=nn("Date"),Zh=nn("File"),Qh=nn("Blob"),em=nn("FileList"),tm=e=>Rr(e)&&$t(e.pipe),nm=e=>{let t;return e&&(typeof FormData=="function"&&e instanceof FormData||$t(e.append)&&((t=go(e))==="formdata"||t==="object"&&$t(e.toString)&&e.toString()==="[object FormData]"))},rm=nn("URLSearchParams"),[om,sm,im,am]=["ReadableStream","Request","Response","Headers"].map(nn),lm=e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function Mr(e,t,{allOwnKeys:n=!1}={}){if(e===null||typeof e>"u")return;let r,o;if(typeof e!="object"&&(e=[e]),lr(e))for(r=0,o=e.length;r<o;r++)t.call(null,e[r],r,e);else{if(jr(e))return;const s=n?Object.getOwnPropertyNames(e):Object.keys(e),i=s.length;let a;for(r=0;r<i;r++)a=s[r],t.call(null,e[a],a,e)}}function Qa(e,t){if(jr(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 Wn=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global,el=e=>!cr(e)&&e!==Wn;function Zs(){const{caseless:e,skipUndefined:t}=el(this)&&this||{},n={},r=(o,s)=>{const i=e&&Qa(n,s)||s;yo(n[i])&&yo(o)?n[i]=Zs(n[i],o):yo(o)?n[i]=Zs({},o):lr(o)?n[i]=o.slice():(!t||!cr(o))&&(n[i]=o)};for(let o=0,s=arguments.length;o<s;o++)arguments[o]&&Mr(arguments[o],r);return n}const cm=(e,t,n,{allOwnKeys:r}={})=>(Mr(t,(o,s)=>{n&&$t(o)?e[s]=Ya(o,n):e[s]=o},{allOwnKeys:r}),e),um=e=>(e.charCodeAt(0)===65279&&(e=e.slice(1)),e),dm=(e,t,n,r)=>{e.prototype=Object.create(t.prototype,r),e.prototype.constructor=e,Object.defineProperty(e,"super",{value:t.prototype}),n&&Object.assign(e.prototype,n)},fm=(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&&Js(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},hm=e=>{if(!e)return null;if(lr(e))return e;let t=e.length;if(!Za(t))return null;const n=new Array(t);for(;t-- >0;)n[t]=e[t];return n},mm=(e=>t=>e&&t instanceof e)(typeof Uint8Array<"u"&&Js(Uint8Array)),gm=(e,t)=>{const r=(e&&e[mo]).call(e);let o;for(;(o=r.next())&&!o.done;){const s=o.value;t.call(e,s[0],s[1])}},xm=(e,t)=>{let n;const r=[];for(;(n=e.exec(t))!==null;)r.push(n);return r},ym=nn("HTMLFormElement"),vm=e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(n,r,o){return r.toUpperCase()+o}),tl=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),bm=nn("RegExp"),nl=(e,t)=>{const n=Object.getOwnPropertyDescriptors(e),r={};Mr(n,(o,s)=>{let i;(i=t(o,s,e))!==!1&&(r[s]=i||o)}),Object.defineProperties(e,r)},wm=e=>{nl(e,(t,n)=>{if($t(e)&&["arguments","caller","callee"].indexOf(n)!==-1)return!1;const r=e[n];if($t(r)){if(t.enumerable=!1,"writable"in t){t.writable=!1;return}t.set||(t.set=()=>{throw Error("Can not rewrite read-only method '"+n+"'")})}})},Sm=(e,t)=>{const n={},r=o=>{o.forEach(s=>{n[s]=!0})};return lr(e)?r(e):r(String(e).split(t)),n},Cm=()=>{},Tm=(e,t)=>e!=null&&Number.isFinite(e=+e)?e:t;function km(e){return!!(e&&$t(e.append)&&e[Xa]==="FormData"&&e[mo])}const Im=e=>{const t=new Array(10),n=(r,o)=>{if(Rr(r)){if(t.indexOf(r)>=0)return;if(jr(r))return r;if(!("toJSON"in r)){t[o]=r;const s=lr(r)?[]:{};return Mr(r,(i,a)=>{const l=n(i,o+1);!cr(l)&&(s[a]=l)}),t[o]=void 0,s}}return r};return n(e,0)},Em=nn("AsyncFunction"),Am=e=>e&&(Rr(e)||$t(e))&&$t(e.then)&&$t(e.catch),rl=((e,t)=>e?setImmediate:t?((n,r)=>(Wn.addEventListener("message",({source:o,data:s})=>{o===Wn&&s===n&&r.length&&r.shift()()},!1),o=>{r.push(o),Wn.postMessage(n,"*")}))(`axios@${Math.random()}`,[]):n=>setTimeout(n))(typeof setImmediate=="function",$t(Wn.postMessage)),Nm=typeof queueMicrotask<"u"?queueMicrotask.bind(Wn):typeof process<"u"&&process.nextTick||rl,O={isArray:lr,isArrayBuffer:Ja,isBuffer:jr,isFormData:nm,isArrayBufferView:qh,isString:Gh,isNumber:Za,isBoolean:Yh,isObject:Rr,isPlainObject:yo,isEmptyObject:Xh,isReadableStream:om,isRequest:sm,isResponse:im,isHeaders:am,isUndefined:cr,isDate:Jh,isFile:Zh,isBlob:Qh,isRegExp:bm,isFunction:$t,isStream:tm,isURLSearchParams:rm,isTypedArray:mm,isFileList:em,forEach:Mr,merge:Zs,extend:cm,trim:lm,stripBOM:um,inherits:dm,toFlatObject:fm,kindOf:go,kindOfTest:nn,endsWith:pm,toArray:hm,forEachEntry:gm,matchAll:xm,isHTMLForm:ym,hasOwnProperty:tl,hasOwnProp:tl,reduceDescriptors:nl,freezeMethods:wm,toObjectSet:Sm,toCamelCase:vm,noop:Cm,toFiniteNumber:Tm,findKey:Qa,global:Wn,isContextDefined:el,isSpecCompliantForm:km,toJSONObject:Im,isAsyncFn:Em,isThenable:Am,setImmediate:rl,asap:Nm,isIterable:e=>e!=null&&$t(e[mo])};function Re(e,t,n,r,o){Error.call(this),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=new Error().stack,this.message=e,this.name="AxiosError",t&&(this.code=t),n&&(this.config=n),r&&(this.request=r),o&&(this.response=o,this.status=o.status?o.status:null)}O.inherits(Re,Error,{toJSON:function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:O.toJSONObject(this.config),code:this.code,status:this.status}}});const ol=Re.prototype,sl={};["ERR_BAD_OPTION_VALUE","ERR_BAD_OPTION","ECONNABORTED","ETIMEDOUT","ERR_NETWORK","ERR_FR_TOO_MANY_REDIRECTS","ERR_DEPRECATED","ERR_BAD_RESPONSE","ERR_BAD_REQUEST","ERR_CANCELED","ERR_NOT_SUPPORT","ERR_INVALID_URL"].forEach(e=>{sl[e]={value:e}}),Object.defineProperties(Re,sl),Object.defineProperty(ol,"isAxiosError",{value:!0}),Re.from=(e,t,n,r,o,s)=>{const i=Object.create(ol);O.toFlatObject(e,i,function(d){return d!==Error.prototype},c=>c!=="isAxiosError");const a=e&&e.message?e.message:"Error",l=t==null&&e?e.code:t;return Re.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 _m=null;function Qs(e){return O.isPlainObject(e)||O.isArray(e)}function il(e){return O.endsWith(e,"[]")?e.slice(0,-2):e}function al(e,t,n){return e?e.concat(t).map(function(o,s){return o=il(o),!n&&s?"["+o+"]":o}).join(n?".":""):t}function jm(e){return O.isArray(e)&&!e.some(Qs)}const Rm=O.toFlatObject(O,{},null,function(t){return/^is[A-Z]/.test(t)});function vo(e,t,n){if(!O.isObject(e))throw new TypeError("target must be an object");t=t||new FormData,n=O.toFlatObject(n,{metaTokens:!0,dots:!1,indexes:!1},!1,function(m,y){return!O.isUndefined(y[m])});const r=n.metaTokens,o=n.visitor||d,s=n.dots,i=n.indexes,l=(n.Blob||typeof Blob<"u"&&Blob)&&O.isSpecCompliantForm(t);if(!O.isFunction(o))throw new TypeError("visitor must be a function");function c(x){if(x===null)return"";if(O.isDate(x))return x.toISOString();if(O.isBoolean(x))return x.toString();if(!l&&O.isBlob(x))throw new Re("Blob is not supported. Use a Buffer instead.");return O.isArrayBuffer(x)||O.isTypedArray(x)?l&&typeof Blob=="function"?new Blob([x]):Buffer.from(x):x}function d(x,m,y){let g=x;if(x&&!y&&typeof x=="object"){if(O.endsWith(m,"{}"))m=r?m:m.slice(0,-2),x=JSON.stringify(x);else if(O.isArray(x)&&jm(x)||(O.isFileList(x)||O.endsWith(m,"[]"))&&(g=O.toArray(x)))return m=il(m),g.forEach(function(S,k){!(O.isUndefined(S)||S===null)&&t.append(i===!0?al([m],k,s):i===null?m:m+"[]",c(S))}),!1}return Qs(x)?!0:(t.append(al(y,m,s),c(x)),!1)}const f=[],h=Object.assign(Rm,{defaultVisitor:d,convertValue:c,isVisitable:Qs});function p(x,m){if(!O.isUndefined(x)){if(f.indexOf(x)!==-1)throw Error("Circular reference detected in "+m.join("."));f.push(x),O.forEach(x,function(g,b){(!(O.isUndefined(g)||g===null)&&o.call(t,g,O.isString(b)?b.trim():b,m,h))===!0&&p(g,m?m.concat(b):[b])}),f.pop()}}if(!O.isObject(e))throw new TypeError("data must be an object");return p(e),t}function ll(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,function(r){return t[r]})}function ei(e,t){this._pairs=[],e&&vo(e,this,t)}const cl=ei.prototype;cl.append=function(t,n){this._pairs.push([t,n])},cl.toString=function(t){const n=t?function(r){return t.call(this,r,ll)}:ll;return this._pairs.map(function(o){return n(o[0])+"="+n(o[1])},"").join("&")};function Mm(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+")}function ul(e,t,n){if(!t)return e;const r=n&&n.encode||Mm;O.isFunction(n)&&(n={serialize:n});const o=n&&n.serialize;let s;if(o?s=o(t,n):s=O.isURLSearchParams(t)?t.toString():new ei(t,n).toString(r),s){const i=e.indexOf("#");i!==-1&&(e=e.slice(0,i)),e+=(e.indexOf("?")===-1?"?":"&")+s}return e}class dl{constructor(){this.handlers=[]}use(t,n,r){return this.handlers.push({fulfilled:t,rejected:n,synchronous:r?r.synchronous:!1,runWhen:r?r.runWhen:null}),this.handlers.length-1}eject(t){this.handlers[t]&&(this.handlers[t]=null)}clear(){this.handlers&&(this.handlers=[])}forEach(t){O.forEach(this.handlers,function(r){r!==null&&t(r)})}}const fl={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},Pm={isBrowser:!0,classes:{URLSearchParams:typeof URLSearchParams<"u"?URLSearchParams:ei,FormData:typeof FormData<"u"?FormData:null,Blob:typeof Blob<"u"?Blob:null},protocols:["http","https","file","blob","url","data"]},ti=typeof window<"u"&&typeof document<"u",ni=typeof navigator=="object"&&navigator||void 0,Om=ti&&(!ni||["ReactNative","NativeScript","NS"].indexOf(ni.product)<0),Dm=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function",Lm=ti&&window.location.href||"http://localhost",At={...Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv:ti,hasStandardBrowserEnv:Om,hasStandardBrowserWebWorkerEnv:Dm,navigator:ni,origin:Lm},Symbol.toStringTag,{value:"Module"})),...Pm};function $m(e,t){return vo(e,new At.classes.URLSearchParams,{visitor:function(n,r,o,s){return At.isNode&&O.isBuffer(n)?(this.append(r,n.toString("base64")),!1):s.defaultVisitor.apply(this,arguments)},...t})}function Fm(e){return O.matchAll(/\w+|\[(\w*)]/g,e).map(t=>t[0]==="[]"?"":t[1]||t[0])}function Bm(e){const t={},n=Object.keys(e);let r;const o=n.length;let s;for(r=0;r<o;r++)s=n[r],t[s]=e[s];return t}function pl(e){function t(n,r,o,s){let i=n[s++];if(i==="__proto__")return!0;const a=Number.isFinite(+i),l=s>=n.length;return i=!i&&O.isArray(o)?o.length:i,l?(O.hasOwnProp(o,i)?o[i]=[o[i],r]:o[i]=r,!a):((!o[i]||!O.isObject(o[i]))&&(o[i]=[]),t(n,r,o[i],s)&&O.isArray(o[i])&&(o[i]=Bm(o[i])),!a)}if(O.isFormData(e)&&O.isFunction(e.entries)){const n={};return O.forEachEntry(e,(r,o)=>{t(Fm(r),o,n,0)}),n}return null}function zm(e,t,n){if(O.isString(e))try{return(t||JSON.parse)(e),O.trim(e)}catch(r){if(r.name!=="SyntaxError")throw r}return(n||JSON.stringify)(e)}const Pr={transitional:fl,adapter:["xhr","http","fetch"],transformRequest:[function(t,n){const r=n.getContentType()||"",o=r.indexOf("application/json")>-1,s=O.isObject(t);if(s&&O.isHTMLForm(t)&&(t=new FormData(t)),O.isFormData(t))return o?JSON.stringify(pl(t)):t;if(O.isArrayBuffer(t)||O.isBuffer(t)||O.isStream(t)||O.isFile(t)||O.isBlob(t)||O.isReadableStream(t))return t;if(O.isArrayBufferView(t))return t.buffer;if(O.isURLSearchParams(t))return n.setContentType("application/x-www-form-urlencoded;charset=utf-8",!1),t.toString();let a;if(s){if(r.indexOf("application/x-www-form-urlencoded")>-1)return $m(t,this.formSerializer).toString();if((a=O.isFileList(t))||r.indexOf("multipart/form-data")>-1){const l=this.env&&this.env.FormData;return vo(a?{"files[]":t}:t,l&&new l,this.formSerializer)}}return s||o?(n.setContentType("application/json",!1),zm(t)):t}],transformResponse:[function(t){const n=this.transitional||Pr.transitional,r=n&&n.forcedJSONParsing,o=this.responseType==="json";if(O.isResponse(t)||O.isReadableStream(t))return t;if(t&&O.isString(t)&&(r&&!this.responseType||o)){const i=!(n&&n.silentJSONParsing)&&o;try{return JSON.parse(t,this.parseReviver)}catch(a){if(i)throw a.name==="SyntaxError"?Re.from(a,Re.ERR_BAD_RESPONSE,this,null,this.response):a}}return t}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:At.classes.FormData,Blob:At.classes.Blob},validateStatus:function(t){return t>=200&&t<300},headers:{common:{Accept:"application/json, text/plain, */*","Content-Type":void 0}}};O.forEach(["delete","get","head","post","put","patch"],e=>{Pr.headers[e]={}});const Um=O.toObjectSet(["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"]),Hm=e=>{const t={};let n,r,o;return e&&e.split(`
|
|
31
31
|
`).forEach(function(i){o=i.indexOf(":"),n=i.substring(0,o).trim().toLowerCase(),r=i.substring(o+1).trim(),!(!n||t[n]&&Um[n])&&(n==="set-cookie"?t[n]?t[n].push(r):t[n]=[r]:t[n]=t[n]?t[n]+", "+r:r)}),t},hl=Symbol("internals");function Or(e){return e&&String(e).trim().toLowerCase()}function bo(e){return e===!1||e==null?e:O.isArray(e)?e.map(bo):String(e)}function Wm(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 Vm=e=>/^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(e.trim());function ri(e,t,n,r,o){if(O.isFunction(r))return r.call(this,t,n);if(o&&(t=n),!!O.isString(t)){if(O.isString(r))return t.indexOf(r)!==-1;if(O.isRegExp(r))return r.test(t)}}function Km(e){return e.trim().toLowerCase().replace(/([a-z\d])(\w*)/g,(t,n,r)=>n.toUpperCase()+r)}function qm(e,t){const n=O.toCamelCase(" "+t);["get","set","has"].forEach(r=>{Object.defineProperty(e,r+n,{value:function(o,s,i){return this[r].call(this,t,o,s,i)},configurable:!0})})}let Ft=class{constructor(t){t&&this.set(t)}set(t,n,r){const o=this;function s(a,l,c){const d=Or(l);if(!d)throw new Error("header name must be a non-empty string");const f=O.findKey(o,d);(!f||o[f]===void 0||c===!0||c===void 0&&o[f]!==!1)&&(o[f||l]=bo(a))}const i=(a,l)=>O.forEach(a,(c,d)=>s(c,d,l));if(O.isPlainObject(t)||t instanceof this.constructor)i(t,n);else if(O.isString(t)&&(t=t.trim())&&!Vm(t))i(Hm(t),n);else if(O.isObject(t)&&O.isIterable(t)){let a={},l,c;for(const d of t){if(!O.isArray(d))throw TypeError("Object iterator must return a key-value pair");a[c=d[0]]=(l=a[c])?O.isArray(l)?[...l,d[1]]:[l,d[1]]:d[1]}i(a,n)}else t!=null&&s(n,t,r);return this}get(t,n){if(t=Or(t),t){const r=O.findKey(this,t);if(r){const o=this[r];if(!n)return o;if(n===!0)return Wm(o);if(O.isFunction(n))return n.call(this,o,r);if(O.isRegExp(n))return n.exec(o);throw new TypeError("parser must be boolean|regexp|function")}}}has(t,n){if(t=Or(t),t){const r=O.findKey(this,t);return!!(r&&this[r]!==void 0&&(!n||ri(this,this[r],r,n)))}return!1}delete(t,n){const r=this;let o=!1;function s(i){if(i=Or(i),i){const a=O.findKey(r,i);a&&(!n||ri(r,r[a],a,n))&&(delete r[a],o=!0)}}return O.isArray(t)?t.forEach(s):s(t),o}clear(t){const n=Object.keys(this);let r=n.length,o=!1;for(;r--;){const s=n[r];(!t||ri(this,this[s],s,t,!0))&&(delete this[s],o=!0)}return o}normalize(t){const n=this,r={};return O.forEach(this,(o,s)=>{const i=O.findKey(r,s);if(i){n[i]=bo(o),delete n[s];return}const a=t?Km(s):String(s).trim();a!==s&&delete n[s],n[a]=bo(o),r[a]=!0}),this}concat(...t){return this.constructor.concat(this,...t)}toJSON(t){const n=Object.create(null);return O.forEach(this,(r,o)=>{r!=null&&r!==!1&&(n[o]=t&&O.isArray(r)?r.join(", "):r)}),n}[Symbol.iterator](){return Object.entries(this.toJSON())[Symbol.iterator]()}toString(){return Object.entries(this.toJSON()).map(([t,n])=>t+": "+n).join(`
|
|
32
|
-
`)}getSetCookie(){return this.get("set-cookie")||[]}get[Symbol.toStringTag](){return"AxiosHeaders"}static from(t){return t instanceof this?t:new this(t)}static concat(t,...n){const r=new this(t);return n.forEach(o=>r.set(o)),r}static accessor(t){const r=(this[hl]=this[hl]={accessors:{}}).accessors,o=this.prototype;function s(i){const a=Or(i);r[a]||(qm(o,i),r[a]=!0)}return O.isArray(t)?t.forEach(s):s(t),this}};Ft.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),O.reduceDescriptors(Ft.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(r){this[n]=r}}}),O.freezeMethods(Ft);function oi(e,t){const n=this||Pr,r=t||n,o=Ft.from(r.headers);let s=r.data;return O.forEach(e,function(a){s=a.call(n,s,o.normalize(),t?t.status:void 0)}),o.normalize(),s}function ml(e){return!!(e&&e.__CANCEL__)}function ur(e,t,n){Re.call(this,e??"canceled",Re.ERR_CANCELED,t,n),this.name="CanceledError"}O.inherits(ur,Re,{__CANCEL__:!0});function gl(e,t,n){const r=n.config.validateStatus;!n.status||!r||r(n.status)?e(n):t(new Re("Request failed with status code "+n.status,[Re.ERR_BAD_REQUEST,Re.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n))}function Gm(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function Ym(e,t){e=e||10;const n=new Array(e),r=new Array(e);let o=0,s=0,i;return t=t!==void 0?t:1e3,function(l){const c=Date.now(),d=r[s];i||(i=c),n[o]=l,r[o]=c;let f=s,p=0;for(;f!==o;)p+=n[f++],f=f%e;if(o=(o+1)%e,o===s&&(s=(s+1)%e),c-i<t)return;const h=d&&c-d;return h?Math.round(p*1e3/h):void 0}}function Xm(e,t){let n=0,r=1e3/t,o,s;const i=(c,d=Date.now())=>{n=d,o=null,s&&(clearTimeout(s),s=null),e(...c)};return[(...c)=>{const d=Date.now(),f=d-n;f>=r?i(c,d):(o=c,s||(s=setTimeout(()=>{s=null,i(o)},r-f)))},()=>o&&i(o)]}const wo=(e,t,n=3)=>{let r=0;const o=Ym(50,250);return Xm(s=>{const i=s.loaded,a=s.lengthComputable?s.total:void 0,l=i-r,c=o(l),d=i<=a;r=i;const f={loaded:i,total:a,progress:a?i/a:void 0,bytes:l,rate:c||void 0,estimated:c&&a&&d?(a-i)/c:void 0,event:s,lengthComputable:a!=null,[t?"download":"upload"]:!0};e(f)},n)},xl=(e,t)=>{const n=e!=null;return[r=>t[0]({lengthComputable:n,total:e,loaded:r}),t[1]]},yl=e=>(...t)=>O.asap(()=>e(...t)),Jm=At.hasStandardBrowserEnv?((e,t)=>n=>(n=new URL(n,At.origin),e.protocol===n.protocol&&e.host===n.host&&(t||e.port===n.port)))(new URL(At.origin),At.navigator&&/(msie|trident)/i.test(At.navigator.userAgent)):()=>!0,Zm=At.hasStandardBrowserEnv?{write(e,t,n,r,o,s){const i=[e+"="+encodeURIComponent(t)];O.isNumber(n)&&i.push("expires="+new Date(n).toGMTString()),O.isString(r)&&i.push("path="+r),O.isString(o)&&i.push("domain="+o),s===!0&&i.push("secure"),document.cookie=i.join("; ")},read(e){const t=document.cookie.match(new RegExp("(^|;\\s*)("+e+")=([^;]*)"));return t?decodeURIComponent(t[3]):null},remove(e){this.write(e,"",Date.now()-864e5)}}:{write(){},read(){return null},remove(){}};function Qm(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function eg(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function vl(e,t,n){let r=!Qm(t);return e&&(r||n==!1)?eg(e,t):t}const bl=e=>e instanceof Ft?{...e}:e;function Vn(e,t){t=t||{};const n={};function r(c,d,f,p){return O.isPlainObject(c)&&O.isPlainObject(d)?O.merge.call({caseless:p},c,d):O.isPlainObject(d)?O.merge({},d):O.isArray(d)?d.slice():d}function o(c,d,f,p){if(O.isUndefined(d)){if(!O.isUndefined(c))return r(void 0,c,f,p)}else return r(c,d,f,p)}function s(c,d){if(!O.isUndefined(d))return r(void 0,d)}function i(c,d){if(O.isUndefined(d)){if(!O.isUndefined(c))return r(void 0,c)}else return r(void 0,d)}function a(c,d,f){if(f in t)return r(c,d);if(f in e)return r(void 0,c)}const l={url:s,method:s,data:s,baseURL:i,transformRequest:i,transformResponse:i,paramsSerializer:i,timeout:i,timeoutMessage:i,withCredentials:i,withXSRFToken:i,adapter:i,responseType:i,xsrfCookieName:i,xsrfHeaderName:i,onUploadProgress:i,onDownloadProgress:i,decompress:i,maxContentLength:i,maxBodyLength:i,beforeRedirect:i,transport:i,httpAgent:i,httpsAgent:i,cancelToken:i,socketPath:i,responseEncoding:i,validateStatus:a,headers:(c,d,f)=>o(bl(c),bl(d),f,!0)};return O.forEach(Object.keys({...e,...t}),function(d){const f=l[d]||o,p=f(e[d],t[d],d);O.isUndefined(p)&&f!==a||(n[d]=p)}),n}const wl=e=>{const t=Vn({},e);let{data:n,withXSRFToken:r,xsrfHeaderName:o,xsrfCookieName:s,headers:i,auth:a}=t;if(t.headers=i=Ft.from(i),t.url=ul(vl(t.baseURL,t.url,t.allowAbsoluteUrls),e.params,e.paramsSerializer),a&&i.set("Authorization","Basic "+btoa((a.username||"")+":"+(a.password?unescape(encodeURIComponent(a.password)):""))),O.isFormData(n)){if(At.hasStandardBrowserEnv||At.hasStandardBrowserWebWorkerEnv)i.setContentType(void 0);else if(O.isFunction(n.getHeaders)){const l=n.getHeaders(),c=["content-type","content-length"];Object.entries(l).forEach(([d,f])=>{c.includes(d.toLowerCase())&&i.set(d,f)})}}if(At.hasStandardBrowserEnv&&(r&&O.isFunction(r)&&(r=r(t)),r||r!==!1&&Jm(t.url))){const l=o&&s&&Zm.read(s);l&&i.set(o,l)}return t},tg=typeof XMLHttpRequest<"u"&&function(e){return new Promise(function(n,r){const o=wl(e);let s=o.data;const i=Ft.from(o.headers).normalize();let{responseType:a,onUploadProgress:l,onDownloadProgress:c}=o,d,f,p,h,x;function m(){h&&h(),x&&x(),o.cancelToken&&o.cancelToken.unsubscribe(d),o.signal&&o.signal.removeEventListener("abort",d)}let y=new XMLHttpRequest;y.open(o.method.toUpperCase(),o.url,!0),y.timeout=o.timeout;function g(){if(!y)return;const S=Ft.from("getAllResponseHeaders"in y&&y.getAllResponseHeaders()),C={data:!a||a==="text"||a==="json"?y.responseText:y.response,status:y.status,statusText:y.statusText,headers:S,config:e,request:y};gl(function(I){n(I),m()},function(I){r(I),m()},C),y=null}"onloadend"in y?y.onloadend=g:y.onreadystatechange=function(){!y||y.readyState!==4||y.status===0&&!(y.responseURL&&y.responseURL.indexOf("file:")===0)||setTimeout(g)},y.onabort=function(){y&&(r(new Re("Request aborted",Re.ECONNABORTED,e,y)),y=null)},y.onerror=function(k){const C=k&&k.message?k.message:"Network Error",T=new Re(C,Re.ERR_NETWORK,e,y);T.event=k||null,r(T),y=null},y.ontimeout=function(){let k=o.timeout?"timeout of "+o.timeout+"ms exceeded":"timeout exceeded";const C=o.transitional||fl;o.timeoutErrorMessage&&(k=o.timeoutErrorMessage),r(new Re(k,C.clarifyTimeoutError?Re.ETIMEDOUT:Re.ECONNABORTED,e,y)),y=null},s===void 0&&i.setContentType(null),"setRequestHeader"in y&&O.forEach(i.toJSON(),function(k,C){y.setRequestHeader(C,k)}),O.isUndefined(o.withCredentials)||(y.withCredentials=!!o.withCredentials),a&&a!=="json"&&(y.responseType=o.responseType),c&&([p,x]=wo(c,!0),y.addEventListener("progress",p)),l&&y.upload&&([f,h]=wo(l),y.upload.addEventListener("progress",f),y.upload.addEventListener("loadend",h)),(o.cancelToken||o.signal)&&(d=S=>{y&&(r(!S||S.type?new ur(null,e,y):S),y.abort(),y=null)},o.cancelToken&&o.cancelToken.subscribe(d),o.signal&&(o.signal.aborted?d():o.signal.addEventListener("abort",d)));const b=Gm(o.url);if(b&&At.protocols.indexOf(b)===-1){r(new Re("Unsupported protocol "+b+":",Re.ERR_BAD_REQUEST,e));return}y.send(s||null)})},ng=(e,t)=>{const{length:n}=e=e?e.filter(Boolean):[];if(t||n){let r=new AbortController,o;const s=function(c){if(!o){o=!0,a();const d=c instanceof Error?c:this.reason;r.abort(d instanceof Re?d:new ur(d instanceof Error?d.message:d))}};let i=t&&setTimeout(()=>{i=null,s(new Re(`timeout ${t} of ms exceeded`,Re.ETIMEDOUT))},t);const a=()=>{e&&(i&&clearTimeout(i),i=null,e.forEach(c=>{c.unsubscribe?c.unsubscribe(s):c.removeEventListener("abort",s)}),e=null)};e.forEach(c=>c.addEventListener("abort",s));const{signal:l}=r;return l.unsubscribe=()=>O.asap(a),l}},rg=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},og=async function*(e,t){for await(const n of sg(e))yield*rg(n,t)},sg=async function*(e){if(e[Symbol.asyncIterator]){yield*e;return}const t=e.getReader();try{for(;;){const{done:n,value:r}=await t.read();if(n)break;yield r}}finally{await t.cancel()}},Sl=(e,t,n,r)=>{const o=og(e,t);let s=0,i,a=l=>{i||(i=!0,r&&r(l))};return new ReadableStream({async pull(l){try{const{done:c,value:d}=await o.next();if(c){a(),l.close();return}let f=d.byteLength;if(n){let p=s+=f;n(p)}l.enqueue(new Uint8Array(d))}catch(c){throw a(c),c}},cancel(l){return a(l),o.return()}},{highWaterMark:2})},Cl=64*1024,{isFunction:So}=O,ig=(({Request:e,Response:t})=>({Request:e,Response:t}))(O.global),{ReadableStream:Tl,TextEncoder:kl}=O.global,Il=(e,...t)=>{try{return!!e(...t)}catch{return!1}},ag=e=>{e=O.merge.call({skipUndefined:!0},ig,e);const{fetch:t,Request:n,Response:r}=e,o=t?So(t):typeof fetch=="function",s=So(n),i=So(r);if(!o)return!1;const a=o&&So(Tl),l=o&&(typeof kl=="function"?(x=>m=>x.encode(m))(new kl):async x=>new Uint8Array(await new n(x).arrayBuffer())),c=s&&a&&Il(()=>{let x=!1;const m=new n(At.origin,{body:new Tl,method:"POST",get duplex(){return x=!0,"half"}}).headers.has("Content-Type");return x&&!m}),d=i&&a&&Il(()=>O.isReadableStream(new r("").body)),f={stream:d&&(x=>x.body)};o&&["text","arrayBuffer","blob","formData","stream"].forEach(x=>{!f[x]&&(f[x]=(m,y)=>{let g=m&&m[x];if(g)return g.call(m);throw new Re(`Response type '${x}' is not supported`,Re.ERR_NOT_SUPPORT,y)})});const p=async x=>{if(x==null)return 0;if(O.isBlob(x))return x.size;if(O.isSpecCompliantForm(x))return(await new n(At.origin,{method:"POST",body:x}).arrayBuffer()).byteLength;if(O.isArrayBufferView(x)||O.isArrayBuffer(x))return x.byteLength;if(O.isURLSearchParams(x)&&(x=x+""),O.isString(x))return(await l(x)).byteLength},h=async(x,m)=>{const y=O.toFiniteNumber(x.getContentLength());return y??p(m)};return async x=>{let{url:m,method:y,data:g,signal:b,cancelToken:S,timeout:k,onDownloadProgress:C,onUploadProgress:T,responseType:I,headers:A,withCredentials:R="same-origin",fetchOptions:L}=wl(x),P=t||fetch;I=I?(I+"").toLowerCase():"text";let D=ng([b,S&&S.toAbortSignal()],k),F=null;const N=D&&D.unsubscribe&&(()=>{D.unsubscribe()});let B;try{if(T&&c&&y!=="get"&&y!=="head"&&(B=await h(A,g))!==0){let J=new n(m,{method:"POST",body:g,duplex:"half"}),se;if(O.isFormData(g)&&(se=J.headers.get("content-type"))&&A.setContentType(se),J.body){const[ge,Ee]=xl(B,wo(yl(T)));g=Sl(J.body,Cl,ge,Ee)}}O.isString(R)||(R=R?"include":"omit");const j=s&&"credentials"in n.prototype,V={...L,signal:D,method:y.toUpperCase(),headers:A.normalize().toJSON(),body:g,duplex:"half",credentials:j?R:void 0};F=s&&new n(m,V);let z=await(s?P(F,L):P(m,V));const M=d&&(I==="stream"||I==="response");if(d&&(C||M&&N)){const J={};["status","statusText","headers"].forEach(Y=>{J[Y]=z[Y]});const se=O.toFiniteNumber(z.headers.get("content-length")),[ge,Ee]=C&&xl(se,wo(yl(C),!0))||[];z=new r(Sl(z.body,Cl,ge,()=>{Ee&&Ee(),N&&N()}),J)}I=I||"text";let q=await f[O.findKey(f,I)||"text"](z,x);return!M&&N&&N(),await new Promise((J,se)=>{gl(J,se,{data:q,headers:Ft.from(z.headers),status:z.status,statusText:z.statusText,config:x,request:F})})}catch(j){throw N&&N(),j&&j.name==="TypeError"&&/Load failed|fetch/i.test(j.message)?Object.assign(new Re("Network Error",Re.ERR_NETWORK,x,F),{cause:j.cause||j}):Re.from(j,j&&j.code,x,F)}}},lg=new Map,El=e=>{let t=e?e.env:{};const{fetch:n,Request:r,Response:o}=t,s=[r,o,n];let i=s.length,a=i,l,c,d=lg;for(;a--;)l=s[a],c=d.get(l),c===void 0&&d.set(l,c=a?new Map:ag(t)),d=c;return c};El();const si={http:_m,xhr:tg,fetch:{get:El}};O.forEach(si,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const Al=e=>`- ${e}`,cg=e=>O.isFunction(e)||e===null||e===!1,Nl={getAdapter:(e,t)=>{e=O.isArray(e)?e:[e];const{length:n}=e;let r,o;const s={};for(let i=0;i<n;i++){r=e[i];let a;if(o=r,!cg(r)&&(o=si[(a=String(r)).toLowerCase()],o===void 0))throw new Re(`Unknown adapter '${a}'`);if(o&&(O.isFunction(o)||(o=o.get(t))))break;s[a||"#"+i]=o}if(!o){const i=Object.entries(s).map(([l,c])=>`adapter ${l} `+(c===!1?"is not supported by the environment":"is not available in the build"));let a=n?i.length>1?`since :
|
|
32
|
+
`)}getSetCookie(){return this.get("set-cookie")||[]}get[Symbol.toStringTag](){return"AxiosHeaders"}static from(t){return t instanceof this?t:new this(t)}static concat(t,...n){const r=new this(t);return n.forEach(o=>r.set(o)),r}static accessor(t){const r=(this[hl]=this[hl]={accessors:{}}).accessors,o=this.prototype;function s(i){const a=Or(i);r[a]||(qm(o,i),r[a]=!0)}return O.isArray(t)?t.forEach(s):s(t),this}};Ft.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),O.reduceDescriptors(Ft.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(r){this[n]=r}}}),O.freezeMethods(Ft);function oi(e,t){const n=this||Pr,r=t||n,o=Ft.from(r.headers);let s=r.data;return O.forEach(e,function(a){s=a.call(n,s,o.normalize(),t?t.status:void 0)}),o.normalize(),s}function ml(e){return!!(e&&e.__CANCEL__)}function ur(e,t,n){Re.call(this,e??"canceled",Re.ERR_CANCELED,t,n),this.name="CanceledError"}O.inherits(ur,Re,{__CANCEL__:!0});function gl(e,t,n){const r=n.config.validateStatus;!n.status||!r||r(n.status)?e(n):t(new Re("Request failed with status code "+n.status,[Re.ERR_BAD_REQUEST,Re.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n))}function Gm(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function Ym(e,t){e=e||10;const n=new Array(e),r=new Array(e);let o=0,s=0,i;return t=t!==void 0?t:1e3,function(l){const c=Date.now(),d=r[s];i||(i=c),n[o]=l,r[o]=c;let f=s,h=0;for(;f!==o;)h+=n[f++],f=f%e;if(o=(o+1)%e,o===s&&(s=(s+1)%e),c-i<t)return;const p=d&&c-d;return p?Math.round(h*1e3/p):void 0}}function Xm(e,t){let n=0,r=1e3/t,o,s;const i=(c,d=Date.now())=>{n=d,o=null,s&&(clearTimeout(s),s=null),e(...c)};return[(...c)=>{const d=Date.now(),f=d-n;f>=r?i(c,d):(o=c,s||(s=setTimeout(()=>{s=null,i(o)},r-f)))},()=>o&&i(o)]}const wo=(e,t,n=3)=>{let r=0;const o=Ym(50,250);return Xm(s=>{const i=s.loaded,a=s.lengthComputable?s.total:void 0,l=i-r,c=o(l),d=i<=a;r=i;const f={loaded:i,total:a,progress:a?i/a:void 0,bytes:l,rate:c||void 0,estimated:c&&a&&d?(a-i)/c:void 0,event:s,lengthComputable:a!=null,[t?"download":"upload"]:!0};e(f)},n)},xl=(e,t)=>{const n=e!=null;return[r=>t[0]({lengthComputable:n,total:e,loaded:r}),t[1]]},yl=e=>(...t)=>O.asap(()=>e(...t)),Jm=At.hasStandardBrowserEnv?((e,t)=>n=>(n=new URL(n,At.origin),e.protocol===n.protocol&&e.host===n.host&&(t||e.port===n.port)))(new URL(At.origin),At.navigator&&/(msie|trident)/i.test(At.navigator.userAgent)):()=>!0,Zm=At.hasStandardBrowserEnv?{write(e,t,n,r,o,s){const i=[e+"="+encodeURIComponent(t)];O.isNumber(n)&&i.push("expires="+new Date(n).toGMTString()),O.isString(r)&&i.push("path="+r),O.isString(o)&&i.push("domain="+o),s===!0&&i.push("secure"),document.cookie=i.join("; ")},read(e){const t=document.cookie.match(new RegExp("(^|;\\s*)("+e+")=([^;]*)"));return t?decodeURIComponent(t[3]):null},remove(e){this.write(e,"",Date.now()-864e5)}}:{write(){},read(){return null},remove(){}};function Qm(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function eg(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function vl(e,t,n){let r=!Qm(t);return e&&(r||n==!1)?eg(e,t):t}const bl=e=>e instanceof Ft?{...e}:e;function Vn(e,t){t=t||{};const n={};function r(c,d,f,h){return O.isPlainObject(c)&&O.isPlainObject(d)?O.merge.call({caseless:h},c,d):O.isPlainObject(d)?O.merge({},d):O.isArray(d)?d.slice():d}function o(c,d,f,h){if(O.isUndefined(d)){if(!O.isUndefined(c))return r(void 0,c,f,h)}else return r(c,d,f,h)}function s(c,d){if(!O.isUndefined(d))return r(void 0,d)}function i(c,d){if(O.isUndefined(d)){if(!O.isUndefined(c))return r(void 0,c)}else return r(void 0,d)}function a(c,d,f){if(f in t)return r(c,d);if(f in e)return r(void 0,c)}const l={url:s,method:s,data:s,baseURL:i,transformRequest:i,transformResponse:i,paramsSerializer:i,timeout:i,timeoutMessage:i,withCredentials:i,withXSRFToken:i,adapter:i,responseType:i,xsrfCookieName:i,xsrfHeaderName:i,onUploadProgress:i,onDownloadProgress:i,decompress:i,maxContentLength:i,maxBodyLength:i,beforeRedirect:i,transport:i,httpAgent:i,httpsAgent:i,cancelToken:i,socketPath:i,responseEncoding:i,validateStatus:a,headers:(c,d,f)=>o(bl(c),bl(d),f,!0)};return O.forEach(Object.keys({...e,...t}),function(d){const f=l[d]||o,h=f(e[d],t[d],d);O.isUndefined(h)&&f!==a||(n[d]=h)}),n}const wl=e=>{const t=Vn({},e);let{data:n,withXSRFToken:r,xsrfHeaderName:o,xsrfCookieName:s,headers:i,auth:a}=t;if(t.headers=i=Ft.from(i),t.url=ul(vl(t.baseURL,t.url,t.allowAbsoluteUrls),e.params,e.paramsSerializer),a&&i.set("Authorization","Basic "+btoa((a.username||"")+":"+(a.password?unescape(encodeURIComponent(a.password)):""))),O.isFormData(n)){if(At.hasStandardBrowserEnv||At.hasStandardBrowserWebWorkerEnv)i.setContentType(void 0);else if(O.isFunction(n.getHeaders)){const l=n.getHeaders(),c=["content-type","content-length"];Object.entries(l).forEach(([d,f])=>{c.includes(d.toLowerCase())&&i.set(d,f)})}}if(At.hasStandardBrowserEnv&&(r&&O.isFunction(r)&&(r=r(t)),r||r!==!1&&Jm(t.url))){const l=o&&s&&Zm.read(s);l&&i.set(o,l)}return t},tg=typeof XMLHttpRequest<"u"&&function(e){return new Promise(function(n,r){const o=wl(e);let s=o.data;const i=Ft.from(o.headers).normalize();let{responseType:a,onUploadProgress:l,onDownloadProgress:c}=o,d,f,h,p,x;function m(){p&&p(),x&&x(),o.cancelToken&&o.cancelToken.unsubscribe(d),o.signal&&o.signal.removeEventListener("abort",d)}let y=new XMLHttpRequest;y.open(o.method.toUpperCase(),o.url,!0),y.timeout=o.timeout;function g(){if(!y)return;const S=Ft.from("getAllResponseHeaders"in y&&y.getAllResponseHeaders()),C={data:!a||a==="text"||a==="json"?y.responseText:y.response,status:y.status,statusText:y.statusText,headers:S,config:e,request:y};gl(function(I){n(I),m()},function(I){r(I),m()},C),y=null}"onloadend"in y?y.onloadend=g:y.onreadystatechange=function(){!y||y.readyState!==4||y.status===0&&!(y.responseURL&&y.responseURL.indexOf("file:")===0)||setTimeout(g)},y.onabort=function(){y&&(r(new Re("Request aborted",Re.ECONNABORTED,e,y)),y=null)},y.onerror=function(k){const C=k&&k.message?k.message:"Network Error",T=new Re(C,Re.ERR_NETWORK,e,y);T.event=k||null,r(T),y=null},y.ontimeout=function(){let k=o.timeout?"timeout of "+o.timeout+"ms exceeded":"timeout exceeded";const C=o.transitional||fl;o.timeoutErrorMessage&&(k=o.timeoutErrorMessage),r(new Re(k,C.clarifyTimeoutError?Re.ETIMEDOUT:Re.ECONNABORTED,e,y)),y=null},s===void 0&&i.setContentType(null),"setRequestHeader"in y&&O.forEach(i.toJSON(),function(k,C){y.setRequestHeader(C,k)}),O.isUndefined(o.withCredentials)||(y.withCredentials=!!o.withCredentials),a&&a!=="json"&&(y.responseType=o.responseType),c&&([h,x]=wo(c,!0),y.addEventListener("progress",h)),l&&y.upload&&([f,p]=wo(l),y.upload.addEventListener("progress",f),y.upload.addEventListener("loadend",p)),(o.cancelToken||o.signal)&&(d=S=>{y&&(r(!S||S.type?new ur(null,e,y):S),y.abort(),y=null)},o.cancelToken&&o.cancelToken.subscribe(d),o.signal&&(o.signal.aborted?d():o.signal.addEventListener("abort",d)));const b=Gm(o.url);if(b&&At.protocols.indexOf(b)===-1){r(new Re("Unsupported protocol "+b+":",Re.ERR_BAD_REQUEST,e));return}y.send(s||null)})},ng=(e,t)=>{const{length:n}=e=e?e.filter(Boolean):[];if(t||n){let r=new AbortController,o;const s=function(c){if(!o){o=!0,a();const d=c instanceof Error?c:this.reason;r.abort(d instanceof Re?d:new ur(d instanceof Error?d.message:d))}};let i=t&&setTimeout(()=>{i=null,s(new Re(`timeout ${t} of ms exceeded`,Re.ETIMEDOUT))},t);const a=()=>{e&&(i&&clearTimeout(i),i=null,e.forEach(c=>{c.unsubscribe?c.unsubscribe(s):c.removeEventListener("abort",s)}),e=null)};e.forEach(c=>c.addEventListener("abort",s));const{signal:l}=r;return l.unsubscribe=()=>O.asap(a),l}},rg=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},og=async function*(e,t){for await(const n of sg(e))yield*rg(n,t)},sg=async function*(e){if(e[Symbol.asyncIterator]){yield*e;return}const t=e.getReader();try{for(;;){const{done:n,value:r}=await t.read();if(n)break;yield r}}finally{await t.cancel()}},Sl=(e,t,n,r)=>{const o=og(e,t);let s=0,i,a=l=>{i||(i=!0,r&&r(l))};return new ReadableStream({async pull(l){try{const{done:c,value:d}=await o.next();if(c){a(),l.close();return}let f=d.byteLength;if(n){let h=s+=f;n(h)}l.enqueue(new Uint8Array(d))}catch(c){throw a(c),c}},cancel(l){return a(l),o.return()}},{highWaterMark:2})},Cl=64*1024,{isFunction:So}=O,ig=(({Request:e,Response:t})=>({Request:e,Response:t}))(O.global),{ReadableStream:Tl,TextEncoder:kl}=O.global,Il=(e,...t)=>{try{return!!e(...t)}catch{return!1}},ag=e=>{e=O.merge.call({skipUndefined:!0},ig,e);const{fetch:t,Request:n,Response:r}=e,o=t?So(t):typeof fetch=="function",s=So(n),i=So(r);if(!o)return!1;const a=o&&So(Tl),l=o&&(typeof kl=="function"?(x=>m=>x.encode(m))(new kl):async x=>new Uint8Array(await new n(x).arrayBuffer())),c=s&&a&&Il(()=>{let x=!1;const m=new n(At.origin,{body:new Tl,method:"POST",get duplex(){return x=!0,"half"}}).headers.has("Content-Type");return x&&!m}),d=i&&a&&Il(()=>O.isReadableStream(new r("").body)),f={stream:d&&(x=>x.body)};o&&["text","arrayBuffer","blob","formData","stream"].forEach(x=>{!f[x]&&(f[x]=(m,y)=>{let g=m&&m[x];if(g)return g.call(m);throw new Re(`Response type '${x}' is not supported`,Re.ERR_NOT_SUPPORT,y)})});const h=async x=>{if(x==null)return 0;if(O.isBlob(x))return x.size;if(O.isSpecCompliantForm(x))return(await new n(At.origin,{method:"POST",body:x}).arrayBuffer()).byteLength;if(O.isArrayBufferView(x)||O.isArrayBuffer(x))return x.byteLength;if(O.isURLSearchParams(x)&&(x=x+""),O.isString(x))return(await l(x)).byteLength},p=async(x,m)=>{const y=O.toFiniteNumber(x.getContentLength());return y??h(m)};return async x=>{let{url:m,method:y,data:g,signal:b,cancelToken:S,timeout:k,onDownloadProgress:C,onUploadProgress:T,responseType:I,headers:A,withCredentials:R="same-origin",fetchOptions:L}=wl(x),P=t||fetch;I=I?(I+"").toLowerCase():"text";let D=ng([b,S&&S.toAbortSignal()],k),F=null;const N=D&&D.unsubscribe&&(()=>{D.unsubscribe()});let B;try{if(T&&c&&y!=="get"&&y!=="head"&&(B=await p(A,g))!==0){let J=new n(m,{method:"POST",body:g,duplex:"half"}),se;if(O.isFormData(g)&&(se=J.headers.get("content-type"))&&A.setContentType(se),J.body){const[ge,Ee]=xl(B,wo(yl(T)));g=Sl(J.body,Cl,ge,Ee)}}O.isString(R)||(R=R?"include":"omit");const j=s&&"credentials"in n.prototype,V={...L,signal:D,method:y.toUpperCase(),headers:A.normalize().toJSON(),body:g,duplex:"half",credentials:j?R:void 0};F=s&&new n(m,V);let z=await(s?P(F,L):P(m,V));const M=d&&(I==="stream"||I==="response");if(d&&(C||M&&N)){const J={};["status","statusText","headers"].forEach(Y=>{J[Y]=z[Y]});const se=O.toFiniteNumber(z.headers.get("content-length")),[ge,Ee]=C&&xl(se,wo(yl(C),!0))||[];z=new r(Sl(z.body,Cl,ge,()=>{Ee&&Ee(),N&&N()}),J)}I=I||"text";let q=await f[O.findKey(f,I)||"text"](z,x);return!M&&N&&N(),await new Promise((J,se)=>{gl(J,se,{data:q,headers:Ft.from(z.headers),status:z.status,statusText:z.statusText,config:x,request:F})})}catch(j){throw N&&N(),j&&j.name==="TypeError"&&/Load failed|fetch/i.test(j.message)?Object.assign(new Re("Network Error",Re.ERR_NETWORK,x,F),{cause:j.cause||j}):Re.from(j,j&&j.code,x,F)}}},lg=new Map,El=e=>{let t=e?e.env:{};const{fetch:n,Request:r,Response:o}=t,s=[r,o,n];let i=s.length,a=i,l,c,d=lg;for(;a--;)l=s[a],c=d.get(l),c===void 0&&d.set(l,c=a?new Map:ag(t)),d=c;return c};El();const si={http:_m,xhr:tg,fetch:{get:El}};O.forEach(si,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const Al=e=>`- ${e}`,cg=e=>O.isFunction(e)||e===null||e===!1,Nl={getAdapter:(e,t)=>{e=O.isArray(e)?e:[e];const{length:n}=e;let r,o;const s={};for(let i=0;i<n;i++){r=e[i];let a;if(o=r,!cg(r)&&(o=si[(a=String(r)).toLowerCase()],o===void 0))throw new Re(`Unknown adapter '${a}'`);if(o&&(O.isFunction(o)||(o=o.get(t))))break;s[a||"#"+i]=o}if(!o){const i=Object.entries(s).map(([l,c])=>`adapter ${l} `+(c===!1?"is not supported by the environment":"is not available in the build"));let a=n?i.length>1?`since :
|
|
33
33
|
`+i.map(Al).join(`
|
|
34
34
|
`):" "+Al(i[0]):"as no adapter specified";throw new Re("There is no suitable adapter to dispatch the request "+a,"ERR_NOT_SUPPORT")}return o},adapters:si};function ii(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new ur(null,e)}function _l(e){return ii(e),e.headers=Ft.from(e.headers),e.data=oi.call(e,e.transformRequest),["post","put","patch"].indexOf(e.method)!==-1&&e.headers.setContentType("application/x-www-form-urlencoded",!1),Nl.getAdapter(e.adapter||Pr.adapter,e)(e).then(function(r){return ii(e),r.data=oi.call(e,e.transformResponse,r),r.headers=Ft.from(r.headers),r},function(r){return ml(r)||(ii(e),r&&r.response&&(r.response.data=oi.call(e,e.transformResponse,r.response),r.response.headers=Ft.from(r.response.headers))),Promise.reject(r)})}const jl="1.12.2",Co={};["object","boolean","number","function","string","symbol"].forEach((e,t)=>{Co[e]=function(r){return typeof r===e||"a"+(t<1?"n ":" ")+e}});const Rl={};Co.transitional=function(t,n,r){function o(s,i){return"[Axios v"+jl+"] Transitional option '"+s+"'"+i+(r?". "+r:"")}return(s,i,a)=>{if(t===!1)throw new Re(o(i," has been removed"+(n?" in "+n:"")),Re.ERR_DEPRECATED);return n&&!Rl[i]&&(Rl[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}},Co.spelling=function(t){return(n,r)=>(console.warn(`${r} is likely a misspelling of ${t}`),!0)};function ug(e,t,n){if(typeof e!="object")throw new Re("options must be an object",Re.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 Re("option "+s+" must be "+l,Re.ERR_BAD_OPTION_VALUE);continue}if(n!==!0)throw new Re("Unknown option "+s,Re.ERR_BAD_OPTION)}}const To={assertOptions:ug,validators:Co},un=To.validators;let Kn=class{constructor(t){this.defaults=t||{},this.interceptors={request:new dl,response:new dl}}async request(t,n){try{return await this._request(t,n)}catch(r){if(r instanceof Error){let o={};Error.captureStackTrace?Error.captureStackTrace(o):o=new Error;const s=o.stack?o.stack.replace(/^.+\n/,""):"";try{r.stack?s&&!String(r.stack).endsWith(s.replace(/^.+\n.+\n/,""))&&(r.stack+=`
|
|
35
|
-
`+s):r.stack=s}catch{}}throw r}}_request(t,n){typeof t=="string"?(n=n||{},n.url=t):n=t||{},n=Vn(this.defaults,n);const{transitional:r,paramsSerializer:o,headers:s}=n;r!==void 0&&To.assertOptions(r,{silentJSONParsing:un.transitional(un.boolean),forcedJSONParsing:un.transitional(un.boolean),clarifyTimeoutError:un.transitional(un.boolean)},!1),o!=null&&(O.isFunction(o)?n.paramsSerializer={serialize:o}:To.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),To.assertOptions(n,{baseUrl:un.spelling("baseURL"),withXsrfToken:un.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let i=s&&O.merge(s.common,s[n.method]);s&&O.forEach(["delete","get","head","post","put","patch","common"],x=>{delete s[x]}),n.headers=Ft.concat(i,s);const a=[];let l=!0;this.interceptors.request.forEach(function(m){typeof m.runWhen=="function"&&m.runWhen(n)===!1||(l=l&&m.synchronous,a.unshift(m.fulfilled,m.rejected))});const c=[];this.interceptors.response.forEach(function(m){c.push(m.fulfilled,m.rejected)});let d,f=0,p;if(!l){const x=[_l.bind(this),void 0];for(x.unshift(...a),x.push(...c),p=x.length,d=Promise.resolve(n);f<p;)d=d.then(x[f++],x[f++]);return d}p=a.length;let h=n;for(;f<p;){const x=a[f++],m=a[f++];try{h=x(h)}catch(y){m.call(this,y);break}}try{d=_l.call(this,h)}catch(x){return Promise.reject(x)}for(f=0,p=c.length;f<p;)d=d.then(c[f++],c[f++]);return d}getUri(t){t=Vn(this.defaults,t);const n=vl(t.baseURL,t.url,t.allowAbsoluteUrls);return ul(n,t.params,t.paramsSerializer)}};O.forEach(["delete","get","head","options"],function(t){Kn.prototype[t]=function(n,r){return this.request(Vn(r||{},{method:t,url:n,data:(r||{}).data}))}}),O.forEach(["post","put","patch"],function(t){function n(r){return function(s,i,a){return this.request(Vn(a||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:s,data:i}))}}Kn.prototype[t]=n(),Kn.prototype[t+"Form"]=n(!0)});let dg=class zh{constructor(t){if(typeof t!="function")throw new TypeError("executor must be a function.");let n;this.promise=new Promise(function(s){n=s});const r=this;this.promise.then(o=>{if(!r._listeners)return;let s=r._listeners.length;for(;s-- >0;)r._listeners[s](o);r._listeners=null}),this.promise.then=o=>{let s;const i=new Promise(a=>{r.subscribe(a),s=a}).then(o);return i.cancel=function(){r.unsubscribe(s)},i},t(function(s,i,a){r.reason||(r.reason=new ur(s,i,a),n(r.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(t){if(this.reason){t(this.reason);return}this._listeners?this._listeners.push(t):this._listeners=[t]}unsubscribe(t){if(!this._listeners)return;const n=this._listeners.indexOf(t);n!==-1&&this._listeners.splice(n,1)}toAbortSignal(){const t=new AbortController,n=r=>{t.abort(r)};return this.subscribe(n),t.signal.unsubscribe=()=>this.unsubscribe(n),t.signal}static source(){let t;return{token:new zh(function(o){t=o}),cancel:t}}};function fg(e){return function(n){return e.apply(null,n)}}function pg(e){return O.isObject(e)&&e.isAxiosError===!0}const ai={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(ai).forEach(([e,t])=>{ai[t]=e});function Ml(e){const t=new Kn(e),n=Ya(Kn.prototype.request,t);return O.extend(n,Kn.prototype,t,{allOwnKeys:!0}),O.extend(n,t,null,{allOwnKeys:!0}),n.create=function(o){return Ml(Vn(e,o))},n}const yt=Ml(Pr);yt.Axios=Kn,yt.CanceledError=ur,yt.CancelToken=dg,yt.isCancel=ml,yt.VERSION=jl,yt.toFormData=vo,yt.AxiosError=Re,yt.Cancel=yt.CanceledError,yt.all=function(t){return Promise.all(t)},yt.spread=fg,yt.isAxiosError=pg,yt.mergeConfig=Vn,yt.AxiosHeaders=Ft,yt.formToJSON=e=>pl(O.isHTMLForm(e)?new FormData(e):e),yt.getAdapter=Nl.getAdapter,yt.HttpStatusCode=ai,yt.default=yt;const{Axios:yT,AxiosError:vT,CanceledError:bT,isCancel:wT,CancelToken:ST,VERSION:CT,all:TT,Cancel:kT,isAxiosError:IT,spread:ET,toFormData:AT,AxiosHeaders:NT,HttpStatusCode:_T,formToJSON:jT,getAdapter:RT,mergeConfig:MT}=yt,Pl=typeof window<"u"?window.__API_BASE_URL__:void 0,Ol=Pl?wn(Pl):void 0;function wn(e){const n=(e!=null&&e.trim()?e.trim():"/api/chat").replace(/\/+$/,"");return n?n.endsWith("/chat")?n:`${n}/chat`:"/api/chat"}let ko=null;const li=new Set;function Dl(){return ko}function Io(e){ko=e,li.forEach(t=>t(e))}function Ll(e){return li.add(e),()=>li.delete(e)}const hg=3e4,mg=9e4,Kt=yt.create({...Ol?{baseURL:Ol}:{},timeout:hg,withCredentials:!0});Kt.interceptors.request.use(e=>(ko&&(e.headers.Authorization=`Bearer ${ko}`),e)),Kt.interceptors.response.use(e=>{if(typeof window<"u"&&(e!=null&&e.data))try{const t=e.data,n=t.data||{},r=typeof t.token=="string"&&t.token||typeof n.token=="string"&&n.token||null,o=typeof t.expires_at=="number"&&t.expires_at||typeof n.expires_at=="number"&&n.expires_at||typeof t.expiresAt=="number"&&t.expiresAt||typeof n.expiresAt=="number"&&n.expiresAt||null;r&&(localStorage.setItem("authToken",r),Io(r)),o&&localStorage.setItem("authTokenExpiresAt",o.toString()),(r||o)&&window.dispatchEvent(new CustomEvent("smartorg:chat-token-updated",{detail:{token:r,expiresAt:o}}))}catch(t){console.warn("[chat-api] Error storing token:",t)}return e},e=>Promise.reject(e));async function qt(e,t){return Kt.defaults.baseURL?(await Kt.get(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}async function ci(e,t,n){return Kt.defaults.baseURL?(await Kt.post(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function $l(e,t,n){return Kt.defaults.baseURL?(await Kt.put(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function Fl(e,t){return Kt.defaults.baseURL?(await Kt.delete(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}function Gt(e){return e&&typeof e=="object"&&"data"in e?e.data:e}class Bl{get baseUrl(){const t=Kt.defaults.baseURL;return t?wn(String(t)):""}updateConfig(t){t.baseUrl&&(Kt.defaults.baseURL=wn(String(t.baseUrl))),t.authToken!==void 0&&Io(t.authToken)}getAuthToken(){return Dl()}setAuthToken(t){Io(t)}onTokenChange(t){return Ll(t)}async listThreads(){const t=await qt("/threads"),n=Gt(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async createThread(t){const r=await ci("/threads",t?{title:t}:void 0);return Gt(r)}async updateThread(t,n){const r=await $l(`/threads/${t}`,{title:n});return Gt(r)}async deleteThread(t){const n=await Fl(`/threads/${t}`);return Gt(n)}async threadInfo(t){const n=await qt(`/threads/${t}/info`);return Gt(n)}async listAgents(){const t=await qt("/agents"),n=Gt(t);return(n==null?void 0:n.items)??[]}async getAgent(t){const n=await qt(`/agents/${t}`);return Gt(n)}async getAgentSchema(t){const n=await qt(`/agents/${t}/schema`);return Gt(n)}async getState(t){const n=await qt(`/threads/${t.threadId}/state`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return Gt(n)}async getStateHistory(t){const n=await qt(`/threads/${t.threadId}/state/history`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs},timeout:mg});return Gt(n)}async cancelRun(t){const n=await ci("/runs/cancel",{threadId:t});return Gt(n)}async listCheckpointSummaries(t){const n=await qt(`/threads/${t}/state/checkpoints`,{params:{thread_id:t}}),r=Gt(n);return(r==null?void 0:r.items)??[]}}const An=new Bl,zl=w.createContext(null);function gg({children:e,apiConfig:t}){const n=An;if(t){const o=n.baseUrl,s=n.getAuthToken();t.baseUrl&&t.baseUrl!==o&&n.updateConfig({baseUrl:t.baseUrl}),t.apiKey!==void 0&&t.apiKey!==s&&n.updateConfig({authToken:t.apiKey})}const r={token:n.getAuthToken(),setToken:o=>n.setAuthToken(o),api:n,baseUrl:n.baseUrl};return u.jsx(zl.Provider,{value:r,children:e})}function ui(){const e=w.useContext(zl);if(!e)throw new Error("useApi must be used within ApiProvider");return e}async function xg(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 yg(e,t=[],n,r,o,s){const i=[],a=[];for(const l of t)try{const c=await xg(l);a.push({filename:l.name,data:c,mime_type:l.type||"application/octet-stream"})}catch{}return{contentParts:i,filesInfo:a}}const vg={human:"user",user:"user",ai:"assistant",assistant:"assistant",tool:"tool",function:"tool",system:"system"};function di(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 bg(e,t){return`${e??""}::${t??""}`}function dr(e){const t=Array.isArray(e==null?void 0:e.checkpoints)?(e==null?void 0:e.checkpoints)??[]:e!=null&&e.checkpoints?Object.values(e.checkpoints):[],n=(e==null?void 0:e.threadId)??"",r=t[0];if(!di(r))return{threadId:n,latest:null,checkpoints:[],timeline:[],interrupt:null,snapshots:{}};const{orderedSnapshots:o,snapshotMap:s}=Sg(t),i=Ul(r,0),a=Cg(o);return{threadId:n,latest:i,checkpoints:o,timeline:a,interrupt:(i==null?void 0:i.interrupt)??null,snapshots:s}}function Ul(e,t){if(!di(e))return null;const n=e.values??{messages:[]},r=Array.isArray(n==null?void 0:n.messages)?n.messages:[],{messages:o,...s}=n,i=Object.keys(s).length?s:null,a=e.tasks,l=Array.isArray(a)?a.filter(R=>!!R&&typeof R=="object").map(R=>({...R})):a===null?null:void 0,c=r.map((R,L)=>Rg(R,L)).filter(R=>!!R),d=Pt(e.config),f=Pt(d==null?void 0:d.configurable),p=dt(f,["checkpoint_id","checkpointId"]),h=dt(f,["checkpoint_ns","checkpointNs"]),x=Pt(e==null?void 0:e.parentConfig),m=Pt(x==null?void 0:x.configurable),y=dt(m,["checkpoint_id","checkpointId"])??null,g=dt(m,["checkpoint_ns","checkpointNs"])??null,b=e==null?void 0:e.createdAt,S=typeof b=="string"&&b.trim()?b:new Date(Date.now()-t).toISOString(),k=c.slice().reverse().find(R=>R.role==="user")??null,C=Pt(e==null?void 0:e.metadata),T=dt(C,["branch_label","branchLabel"]),I=dt(m,["checkpoint_id","checkpointId"]),A=Array.isArray(e.next)?[...e.next]:(e==null?void 0:e.next)===null?null:void 0;return{messages:c,checkpointId:p??null,checkpointNs:h??null,nextCursor:y,nextCursorNs:g,interrupt:wg(a,c,t),createdAt:S,parentId:I??null,branchLabel:T??null,lastUserMessageId:(k==null?void 0:k.id)??null,hasMessages:c.length>0,messagesLen:c.length,metadata:C??null,config:d??null,parentConfig:x??null,next:A??null,tasks:l??null,values:i??null}}function wg(e,t,n){const r=_g(e,n);return r||Ng(t,n)}function Sg(e){const t=new Map;e.forEach((o,s)=>{if(!di(o))return;const i=Ul(o,s);if(!(i!=null&&i.checkpointId))return;const a=bg(i.checkpointId,i.checkpointNs??null),l=t.get(a);if(!l){t.set(a,i);return}t.set(a,Ig(l,i))});const n=Array.from(t.values());n.sort((o,s)=>Wl(s.createdAt??"")-Wl(o.createdAt??""));const r={};for(const[o,s]of t.entries())r[o]=s;return{orderedSnapshots:n,snapshotMap:r}}function Cg(e){var n,r;const t=[];for(const o of e){const s=o.checkpointId??null;if(!s)continue;const i=o.metadata??{},a=dt(i,["label"])??dt(i,["branch_label","branchLabel"])??dt(i,["description"])??"User input",l=kg(i,["step"]),c=dt(i,["source"]),d=o.createdAt??null,f=((r=(n=o.messages)==null?void 0:n[o.messages.length-1])==null?void 0:r.id)??null,p=o.lastUserMessageId??f,h=Tg(o.next);t.push({id:s,label:a,messageId:p,step:l,source:c??null,createdAt:d,next:h??void 0,parentConfig:o.parentConfig??null})}return t}function Tg(e){if(!Array.isArray(e)||e.length===0)return null;const t=e.map(n=>{if(typeof n=="string")return n.trim();if(n&&typeof n=="object"&&"type"in n){const r=n;if(typeof r.type=="string")return r.type}return null}).filter(n=>!!(n&&n.length));return t.length?t.join(", "):null}function kg(e,t){if(!e)return null;for(const n of t){const r=e[n];if(typeof r=="number"&&Number.isFinite(r))return r}return null}function Ig(e,t){return{...e,metadata:Eo(e.metadata,t.metadata)??null,config:Eo(e.config,t.config)??null,parentConfig:Eo(e.parentConfig,t.parentConfig)??null,next:Eg(e.next,t.next)??null,tasks:Ag(e.tasks,t.tasks)??null,values:Eo(e.values,t.values)??null}}function Eo(e,t){return t&&typeof t=="object"?{...e&&typeof e=="object"?e:{},...t}:t===null?e&&typeof e=="object"?{...e}:e??null:e&&typeof e=="object"?{...e}:e??void 0}function Eg(e,t){return Array.isArray(t)?t.slice():t===null?Array.isArray(e)?e.slice():e??null:Array.isArray(e)?e.slice():e??void 0}function Ag(e,t){return Array.isArray(t)?t.map(n=>({...n})):t===null?Array.isArray(e)?e.map(n=>({...n})):e??null:Array.isArray(e)?e.map(n=>({...n})):e??void 0}function Ng(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 _g(e,t){if(!Array.isArray(e)||!e.length)return null;for(let n=e.length-1;n>=0;n--){const r=jg(e[n],`task-${t}-${n}`);if(!r)continue;const o=r.id||`task-${t}-${n}`;if(Array.isArray(r.interrupts)&&r.interrupts.length)for(let s=r.interrupts.length-1;s>=0;s--){const i=Dr(r.interrupts[s],`${o}-interrupt-${s}`);if(i)return i}if(r.state!==void 0&&r.state!==null){const s=Dr(r.state,`${o}-state`);if(s)return s}}return null}function jg(e,t){if(!e)return null;if(Array.isArray(e)){const[a,l,c,,d,,f,...p]=e,h=typeof a=="string"&&a.trim()?a:t,x=typeof l=="string"&&l.trim()?l:Array.isArray(c)&&typeof c[0]=="string"?String(c[0]):"task",m=Array.isArray(d)?d:void 0,y=p.length?p[p.length-1]:void 0;return{id:h,name:x,interrupts:m,state:y!==void 0?y:f}}const n=Pt(e);if(!n)return null;const r=dt(n,["id","thread_id","taskId"])??t,o=dt(n,["name"])??"task",s=Array.isArray(n.interrupts)?n.interrupts:void 0,i=Object.prototype.hasOwnProperty.call(n,"state")?n.state:void 0;return{id:r,name:o,interrupts:s,state:i}}function Dr(e,t,n=0,r=new Set){if(n>6||e==null)return null;if(typeof e=="object"){if(r.has(e))return null;r.add(e)}const o=Hl(e,t);if(o)return o;if(Array.isArray(e)){for(let s=e.length-1;s>=0;s--){const i=Dr(e[s],t,n+1,r);if(i)return i}return null}if(typeof e=="object"){const s=e,i=["interrupt","pending_interrupt","pendingInterrupt","value","data","payload","result","response"];for(const a of i)if(a in s){const l=Dr(s[a],t,n+1,r);if(l)return l}for(const[a,l]of Object.entries(s)){if(i.includes(a)||a==="messages"||a==="results")continue;const c=Dr(l,t,n+1,r);if(c)return c}}return null}function Hl(e,t){if(!e)return null;if(typeof e=="object"&&!Array.isArray(e)){const n=e,r=dt(n,["type","event","kind"]),o=dt(n,["id","interrupt_id","interruptId","value_id"])??(r&&r.toLowerCase().includes("interrupt")?t:void 0);if(!(Object.prototype.hasOwnProperty.call(n,"value")||Object.prototype.hasOwnProperty.call(n,"data")||Object.prototype.hasOwnProperty.call(n,"payload"))&&!(r&&r.toLowerCase().includes("interrupt")))return null;const i=Object.prototype.hasOwnProperty.call(n,"value")?n.value:Object.prototype.hasOwnProperty.call(n,"data")?n.data:Object.prototype.hasOwnProperty.call(n,"payload")?n.payload:n,a=o&&o.trim()?o:t;return a?{id:a,value:i}:null}if(Array.isArray(e)){for(let n=e.length-1;n>=0;n--){const r=Hl(e[n],t);if(r)return r}return e.length>=2&&typeof e[0]=="string"&&e[0].trim()?{id:e[0],value:e[1]}:null}if(typeof e=="string"){const n=e.trim();return n?{id:t||n,value:n}:null}return null}function Wl(e){if(!e)return 0;const t=Date.parse(e);return Number.isFinite(t)?t:0}function Rg(e,t){if(!e||typeof e!="object")return null;const n=e,r=Pt(e)??{},o=Pt(n.data)??r,s=String(n.type??o.type??o.role??"").toLowerCase(),i=vg[s];if(!i)return null;const a=o.id??o.message_id??o.run_id??null,l=typeof a=="string"&&a.trim()?a:`history-${i}-${t}`,c=Pt(o.additional_kwargs)??Pt(o.additionalKwargs),d=Pt(o.response_metadata)??Pt(o.responseMetadata),f=dt(c,["createdAt","created_at"])??dt(o,["created_at","createdAt"]),p=dt(c,["checkpointId","checkpoint_id"]),h=dt(c,["checkpointNs","checkpoint_ns"]),x=Mg(o.content),m={id:l,role:i,content:x};f&&(m.createdAt=f),typeof o.name=="string"&&o.name.trim()&&(m.name=o.name),typeof(d==null?void 0:d.model_name)=="string"&&(m.model=String(d.model_name)),!m.model&&typeof o.model=="string"&&(m.model=o.model),p&&(m.checkpointId=p),h&&(m.checkpointNs=h);const y=Dg(Pt(o.artifact??r.artifact??o.artifacts??r.artifacts));y&&(m.artifact=y);const g=Bg(c,["createdAt","created_at","checkpointId","checkpoint_id","checkpointNs","checkpoint_ns","tool_calls"]),b=d?{...d}:void 0;g&&Object.keys(g).length&&(m.additionalKwargs=g),b&&Object.keys(b).length&&(m.responseMetadata=b);const S=Pg((c==null?void 0:c.tool_calls)??o.tool_calls);if(S.length&&(m.content=[...m.content,...S]),i==="tool"){const k=Og(o,m.content);k&&(m.content=k)}return m}function Mg(e){if(!e)return[];if(Array.isArray(e))return e.map(t=>Vl(t)).filter(t=>!!t);if(typeof e=="string")return e.trim()?[{type:"text",text:e.trim()}]:[];if(typeof e=="object"){const t=Vl(e);return t?[t]:[]}return[]}function Vl(e){if(!e||typeof e!="object")return typeof e=="string"&&e.trim()?{type:"text",text:e}:null;const t=e,n=String(t.type??"").toLowerCase();if(!n||n==="text"){const o=typeof t.text=="string"?t.text:typeof t.value=="string"?t.value:"";return o.trim()?{type:"text",text:o}:null}if(n==="image"||n==="image_url"){const o=dt(t,["url","src"]);if(!o)return null;const s={type:"image_url",url:o};return typeof t.mimeType=="string"&&(s.mimeType=t.mimeType),typeof t.alt=="string"&&(s.alt=t.alt),s}if(n==="file"){const o=dt(t,["url"]);if(!o)return null;const s={type:"file",url:o};return typeof t.mimeType=="string"&&(s.mimeType=t.mimeType),typeof t.name=="string"&&(s.name=t.name),typeof t.size=="number"&&(s.size=t.size),typeof t.sourceType=="string"&&(s.sourceType=t.sourceType),s}if(n==="tool_call")return Kl(t)??null;if(n==="tool_end"){const o="output"in t?t.output:t.content;return o?{type:"text",text:typeof o=="string"?o:JSON.stringify(o)}:null}if(n==="interrupt")return{type:"interrupt",value:t.value,...t};if(n==="tool"){const o=dt(t,["text","content"]);if(o)return{type:"text",text:o}}const r=typeof t.content=="string"?t.content:typeof t.value=="string"?t.value:JSON.stringify(t);return r?{type:"text",text:r}:null}function Kl(e,t){var s;const n=dt(e,["id","call_id"])??t,r=dt(e,["name"])??dt(Pt(e.function),["name"]);if(!n||!r)return null;const o=Fg(e.args??e.arguments??((s=Pt(e.function))==null?void 0:s.arguments));return{type:"tool_call",id:n,name:r,args:o}}function Pg(e){return Array.isArray(e)?e.map((t,n)=>Kl(t,`tool_call_${n}`)).filter(t=>!!t):[]}function Og(e,t){const n=e.content??e.output;if(!n)return t;const o={type:"text",text:typeof n=="string"?n:JSON.stringify(n)};return[...t,o]}function Dg(e){return e?{plots:Lg(e.plots)}:void 0}function Lg(e){return Array.isArray(e)?e.map(t=>$g(t)).filter(t=>!!t):[]}function $g(e){if(!e||typeof e!="object")return null;const t=e,n=typeof t.content_base64=="string"&&t.content_base64.trim()||void 0,r=typeof t.url=="string"&&t.url.trim()||void 0,o=(typeof t.format=="string"?t.format.trim():void 0)||(typeof t.mimeType=="string"?t.mimeType.trim():void 0)||(typeof t.mime_type=="string"?t.mime_type.trim():void 0),s=typeof t.plotId=="string"&&t.plotId.trim()||void 0,i=typeof t.artifactId=="string"&&t.artifactId.trim()||void 0,a={};return n&&(a.content_base64=n),r&&(a.url=r),o&&(a.format=o),s&&(a.plotId=s),i&&(a.artifactId=i),a}function Fg(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 Pt(e){if(!(!e||typeof e!="object"||Array.isArray(e)))return{...e}}function dt(e,t){if(e)for(const n of t){const r=e[n];if(typeof r=="string"&&r.trim())return r}}function 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}const fr=120;function zg(e){if(!Array.isArray(e))return"";const t=e.filter(r=>!!(r&&r.type==="text")).map(r=>(r.text??"").trim()).filter(Boolean);if(!t.length)return"";const n=t.join(" ").replace(/\s+/g," ").trim();return n?n.length>fr?`${n.slice(0,fr-3)}…`:n:""}function Ug(e){var r,o;const t=[(r=e.additionalKwargs)==null?void 0:r.summary,(o=e.responseMetadata)==null?void 0:o.summary];for(const s of t)if(typeof s=="string"&&s.trim()){const i=s.trim();return i.length>fr?`${i.slice(0,fr-3)}…`:i}const n=(e.name||e.id||"").toString().trim();return n?n.length>fr?`${n.slice(0,fr-3)}…`:n:""}function ql(e){const t=new Map;for(const n of e){if(!n.id||n.role!=="user")continue;const o=zg(n.content)||Ug(n);o&&t.set(n.id,o)}return t}function Gl(e={}){const t=w.useMemo(()=>wn(e.baseUrl),[e.baseUrl]),n=e.streamPath??"/runs/stream",[r,o]=w.useState(e.token??null),s=w.useRef(e.headers??{}),i=e.credentials??"include",[a,l]=w.useState(!1),[c,d]=w.useState(null),[f,p]=w.useState(""),[h,x]=w.useState(null),[m,y]=w.useState(0),[g,b]=w.useState(!1),S=w.useRef(null),k=w.useRef(!0),C=w.useRef(0),T=w.useRef(null),I=w.useRef(null),A=w.useRef(null),R=w.useRef(null),L=w.useCallback(N=>{o(N)},[]),P=w.useCallback(()=>{p(""),x(null),d(null),I.current=null,A.current=null,R.current=null},[]),D=w.useCallback(()=>{var N;console.debug("[use-chat] stop() invoked - aborting stream"),(N=S.current)==null||N.abort(),S.current=null,T.current=null,l(!1),b(!1),C.current=0,y(0)},[]),F=w.useCallback((N,B,j)=>{S.current&&(S.current.abort(),S.current=null),l(!0),d(null),e.autoAppendAssistant!==!1&&p(""),x(null),I.current=null,A.current=null,R.current=null;const V=new AbortController;S.current=V;let z=null,M=null,q=!1;return T.current={threadId:N.threadId??null,headers:{}},(async()=>{var se,ge,Ee,Y,U,Z,$,K,Q,ce,oe,Ne,Ue,re,xe,Pe,Ze,Qe;const J=Ve=>{var tt;try{const it=JSON.parse(JSON.stringify(Ve));return(tt=it==null?void 0:it.payload)!=null&&tt.files_info&&Array.isArray(it.payload.files_info)&&(it.payload.files_info=it.payload.files_info.map(qe=>({...qe,data:qe!=null&&qe.data?`<base64 ${String(qe.data).length} chars>`:qe==null?void 0:qe.data}))),it}catch{return Ve}};try{let Ve={};try{if(r)Ve={Authorization:`Bearer ${r}`};else if(typeof window<"u"){const Ye=window.__AUTH_TOKEN__,pt=((se=window.localStorage)==null?void 0:se.getItem("authToken"))||null;let lt=null;try{const _=(ge=window.localStorage)==null?void 0:ge.getItem("chat-settings");_&&(lt=((Ee=JSON.parse(_))==null?void 0:Ee.apiKey)||null)}catch{}const G=Ye||pt||lt||null;G&&(Ve={Authorization:`Bearer ${G}`})}}catch{}console.debug("[use-chat] POST",t+n,J(N));let tt={};if(typeof window<"u")try{const Ge=(Y=window.localStorage)==null?void 0:Y.getItem("authSessionId");Ge&&(tt={"X-Session-Id":Ge})}catch{}const it={...Ve,...tt,...s.current},qe={"Content-Type":"application/json",Accept:"text/event-stream",...it},nt=await fetch(t+n,{method:"POST",headers:qe,body:JSON.stringify(N),signal:V.signal,credentials:i});if(T.current&&(T.current.headers=it),!nt.ok||!nt.body){const Ge=await nt.text().catch(()=>"");console.debug("[use-chat] non-OK response",nt.status,Ge==null?void 0:Ge.slice(0,500));const Ye=`stream ${nt.status}${Ge?": "+Ge:""}`;throw(U=j==null?void 0:j.onConnectionError)==null||U.call(j,Ye),q=!0,z="error",M=Ye,new Error(Ye)}b(!0);const at=nt.body.getReader(),Rt=new TextDecoder;let gt="",ht=[];C.current=0,y(0);let bt=0,St=null;const Lt=()=>{if(ht.length){const Ge=ht.join("");ht=[],k.current&&p(Ye=>Ye+Ge)}St=null},Mt=()=>{typeof window<"u"&&St==null&&(St=requestAnimationFrame(Lt))};let et=Date.now();const It=setInterval(()=>{var Ge;if(Date.now()-et>18e5){const Ye="Stream idle timeout";d(Ye),z="error",M=Ye,V.abort(),(Ge=j==null?void 0:j.onError)==null||Ge.call(j,Ye)}},5e3),bn=1024*1024;try{const Ge=nt.headers.get("X-Thread-Id")||nt.headers.get("x-thread-id"),Ye=nt.headers.get("X-Thread-Created")||nt.headers.get("x-thread-created"),pt=Ge??null,lt=String(Ye??"").toLowerCase()==="true";for(T.current&&!T.current.threadId&&(T.current={...T.current,threadId:pt}),(Z=j==null?void 0:j.onOpen)==null||Z.call(j,{threadId:pt,created:lt});;){const{value:G,done:_}=await at.read();if(_)break;gt+=Rt.decode(G,{stream:!0}),gt.length>bn&&(gt="",console.warn("Stream buffer reset: exceeded 1MB"));let X;for(;(X=gt.indexOf(`
|
|
35
|
+
`+s):r.stack=s}catch{}}throw r}}_request(t,n){typeof t=="string"?(n=n||{},n.url=t):n=t||{},n=Vn(this.defaults,n);const{transitional:r,paramsSerializer:o,headers:s}=n;r!==void 0&&To.assertOptions(r,{silentJSONParsing:un.transitional(un.boolean),forcedJSONParsing:un.transitional(un.boolean),clarifyTimeoutError:un.transitional(un.boolean)},!1),o!=null&&(O.isFunction(o)?n.paramsSerializer={serialize:o}:To.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),To.assertOptions(n,{baseUrl:un.spelling("baseURL"),withXsrfToken:un.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let i=s&&O.merge(s.common,s[n.method]);s&&O.forEach(["delete","get","head","post","put","patch","common"],x=>{delete s[x]}),n.headers=Ft.concat(i,s);const a=[];let l=!0;this.interceptors.request.forEach(function(m){typeof m.runWhen=="function"&&m.runWhen(n)===!1||(l=l&&m.synchronous,a.unshift(m.fulfilled,m.rejected))});const c=[];this.interceptors.response.forEach(function(m){c.push(m.fulfilled,m.rejected)});let d,f=0,h;if(!l){const x=[_l.bind(this),void 0];for(x.unshift(...a),x.push(...c),h=x.length,d=Promise.resolve(n);f<h;)d=d.then(x[f++],x[f++]);return d}h=a.length;let p=n;for(;f<h;){const x=a[f++],m=a[f++];try{p=x(p)}catch(y){m.call(this,y);break}}try{d=_l.call(this,p)}catch(x){return Promise.reject(x)}for(f=0,h=c.length;f<h;)d=d.then(c[f++],c[f++]);return d}getUri(t){t=Vn(this.defaults,t);const n=vl(t.baseURL,t.url,t.allowAbsoluteUrls);return ul(n,t.params,t.paramsSerializer)}};O.forEach(["delete","get","head","options"],function(t){Kn.prototype[t]=function(n,r){return this.request(Vn(r||{},{method:t,url:n,data:(r||{}).data}))}}),O.forEach(["post","put","patch"],function(t){function n(r){return function(s,i,a){return this.request(Vn(a||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:s,data:i}))}}Kn.prototype[t]=n(),Kn.prototype[t+"Form"]=n(!0)});let dg=class zh{constructor(t){if(typeof t!="function")throw new TypeError("executor must be a function.");let n;this.promise=new Promise(function(s){n=s});const r=this;this.promise.then(o=>{if(!r._listeners)return;let s=r._listeners.length;for(;s-- >0;)r._listeners[s](o);r._listeners=null}),this.promise.then=o=>{let s;const i=new Promise(a=>{r.subscribe(a),s=a}).then(o);return i.cancel=function(){r.unsubscribe(s)},i},t(function(s,i,a){r.reason||(r.reason=new ur(s,i,a),n(r.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(t){if(this.reason){t(this.reason);return}this._listeners?this._listeners.push(t):this._listeners=[t]}unsubscribe(t){if(!this._listeners)return;const n=this._listeners.indexOf(t);n!==-1&&this._listeners.splice(n,1)}toAbortSignal(){const t=new AbortController,n=r=>{t.abort(r)};return this.subscribe(n),t.signal.unsubscribe=()=>this.unsubscribe(n),t.signal}static source(){let t;return{token:new zh(function(o){t=o}),cancel:t}}};function fg(e){return function(n){return e.apply(null,n)}}function pg(e){return O.isObject(e)&&e.isAxiosError===!0}const ai={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(ai).forEach(([e,t])=>{ai[t]=e});function Ml(e){const t=new Kn(e),n=Ya(Kn.prototype.request,t);return O.extend(n,Kn.prototype,t,{allOwnKeys:!0}),O.extend(n,t,null,{allOwnKeys:!0}),n.create=function(o){return Ml(Vn(e,o))},n}const yt=Ml(Pr);yt.Axios=Kn,yt.CanceledError=ur,yt.CancelToken=dg,yt.isCancel=ml,yt.VERSION=jl,yt.toFormData=vo,yt.AxiosError=Re,yt.Cancel=yt.CanceledError,yt.all=function(t){return Promise.all(t)},yt.spread=fg,yt.isAxiosError=pg,yt.mergeConfig=Vn,yt.AxiosHeaders=Ft,yt.formToJSON=e=>pl(O.isHTMLForm(e)?new FormData(e):e),yt.getAdapter=Nl.getAdapter,yt.HttpStatusCode=ai,yt.default=yt;const{Axios:yT,AxiosError:vT,CanceledError:bT,isCancel:wT,CancelToken:ST,VERSION:CT,all:TT,Cancel:kT,isAxiosError:IT,spread:ET,toFormData:AT,AxiosHeaders:NT,HttpStatusCode:_T,formToJSON:jT,getAdapter:RT,mergeConfig:MT}=yt,Pl=typeof window<"u"?window.__API_BASE_URL__:void 0,Ol=Pl?wn(Pl):void 0;function wn(e){const n=(e!=null&&e.trim()?e.trim():"/api/chat").replace(/\/+$/,"");return n?n.endsWith("/chat")?n:`${n}/chat`:"/api/chat"}let ko=null;const li=new Set;function Dl(){return ko}function Io(e){ko=e,li.forEach(t=>t(e))}function Ll(e){return li.add(e),()=>li.delete(e)}const hg=3e4,mg=9e4,Kt=yt.create({...Ol?{baseURL:Ol}:{},timeout:hg,withCredentials:!0});Kt.interceptors.request.use(e=>(ko&&(e.headers.Authorization=`Bearer ${ko}`),e)),Kt.interceptors.response.use(e=>{if(typeof window<"u"&&(e!=null&&e.data))try{const t=e.data,n=t.data||{},r=typeof t.token=="string"&&t.token||typeof n.token=="string"&&n.token||null,o=typeof t.expires_at=="number"&&t.expires_at||typeof n.expires_at=="number"&&n.expires_at||typeof t.expiresAt=="number"&&t.expiresAt||typeof n.expiresAt=="number"&&n.expiresAt||null;r&&(localStorage.setItem("authToken",r),Io(r)),o&&localStorage.setItem("authTokenExpiresAt",o.toString()),(r||o)&&window.dispatchEvent(new CustomEvent("smartorg:chat-token-updated",{detail:{token:r,expiresAt:o}}))}catch(t){console.warn("[chat-api] Error storing token:",t)}return e},e=>Promise.reject(e));async function qt(e,t){return Kt.defaults.baseURL?(await Kt.get(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}async function ci(e,t,n){return Kt.defaults.baseURL?(await Kt.post(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function $l(e,t,n){return Kt.defaults.baseURL?(await Kt.put(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function Fl(e,t){return Kt.defaults.baseURL?(await Kt.delete(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}function Gt(e){return e&&typeof e=="object"&&"data"in e?e.data:e}class Bl{get baseUrl(){const t=Kt.defaults.baseURL;return t?wn(String(t)):""}updateConfig(t){t.baseUrl&&(Kt.defaults.baseURL=wn(String(t.baseUrl))),t.authToken!==void 0&&Io(t.authToken)}getAuthToken(){return Dl()}setAuthToken(t){Io(t)}onTokenChange(t){return Ll(t)}async listThreads(){const t=await qt("/threads"),n=Gt(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async createThread(t){const r=await ci("/threads",t?{title:t}:void 0);return Gt(r)}async updateThread(t,n){const r=await $l(`/threads/${t}`,{title:n});return Gt(r)}async deleteThread(t){const n=await Fl(`/threads/${t}`);return Gt(n)}async threadInfo(t){const n=await qt(`/threads/${t}/info`);return Gt(n)}async listAgents(){const t=await qt("/agents"),n=Gt(t);return(n==null?void 0:n.items)??[]}async getAgent(t){const n=await qt(`/agents/${t}`);return Gt(n)}async getAgentSchema(t){const n=await qt(`/agents/${t}/schema`);return Gt(n)}async getState(t){const n=await qt(`/threads/${t.threadId}/state`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return Gt(n)}async getStateHistory(t){const n=await qt(`/threads/${t.threadId}/state/history`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs},timeout:mg});return Gt(n)}async cancelRun(t){const n=await ci("/runs/cancel",{threadId:t});return Gt(n)}async listCheckpointSummaries(t){const n=await qt(`/threads/${t}/state/checkpoints`,{params:{thread_id:t}}),r=Gt(n);return(r==null?void 0:r.items)??[]}}const An=new Bl,zl=w.createContext(null);function gg({children:e,apiConfig:t}){const n=An;if(t){const o=n.baseUrl,s=n.getAuthToken();t.baseUrl&&t.baseUrl!==o&&n.updateConfig({baseUrl:t.baseUrl}),t.apiKey!==void 0&&t.apiKey!==s&&n.updateConfig({authToken:t.apiKey})}const r={token:n.getAuthToken(),setToken:o=>n.setAuthToken(o),api:n,baseUrl:n.baseUrl};return u.jsx(zl.Provider,{value:r,children:e})}function ui(){const e=w.useContext(zl);if(!e)throw new Error("useApi must be used within ApiProvider");return e}async function xg(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 yg(e,t=[],n,r,o,s){const i=[],a=[];for(const l of t)try{const c=await xg(l);a.push({filename:l.name,data:c,mime_type:l.type||"application/octet-stream"})}catch{}return{contentParts:i,filesInfo:a}}const vg={human:"user",user:"user",ai:"assistant",assistant:"assistant",tool:"tool",function:"tool",system:"system"};function di(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 bg(e,t){return`${e??""}::${t??""}`}function dr(e){const t=Array.isArray(e==null?void 0:e.checkpoints)?(e==null?void 0:e.checkpoints)??[]:e!=null&&e.checkpoints?Object.values(e.checkpoints):[],n=(e==null?void 0:e.threadId)??"",r=t[0];if(!di(r))return{threadId:n,latest:null,checkpoints:[],timeline:[],interrupt:null,snapshots:{}};const{orderedSnapshots:o,snapshotMap:s}=Sg(t),i=Ul(r,0),a=Cg(o);return{threadId:n,latest:i,checkpoints:o,timeline:a,interrupt:(i==null?void 0:i.interrupt)??null,snapshots:s}}function Ul(e,t){if(!di(e))return null;const n=e.values??{messages:[]},r=Array.isArray(n==null?void 0:n.messages)?n.messages:[],{messages:o,...s}=n,i=Object.keys(s).length?s:null,a=e.tasks,l=Array.isArray(a)?a.filter(R=>!!R&&typeof R=="object").map(R=>({...R})):a===null?null:void 0,c=r.map((R,L)=>Rg(R,L)).filter(R=>!!R),d=Pt(e.config),f=Pt(d==null?void 0:d.configurable),h=dt(f,["checkpoint_id","checkpointId"]),p=dt(f,["checkpoint_ns","checkpointNs"]),x=Pt(e==null?void 0:e.parentConfig),m=Pt(x==null?void 0:x.configurable),y=dt(m,["checkpoint_id","checkpointId"])??null,g=dt(m,["checkpoint_ns","checkpointNs"])??null,b=e==null?void 0:e.createdAt,S=typeof b=="string"&&b.trim()?b:new Date(Date.now()-t).toISOString(),k=c.slice().reverse().find(R=>R.role==="user")??null,C=Pt(e==null?void 0:e.metadata),T=dt(C,["branch_label","branchLabel"]),I=dt(m,["checkpoint_id","checkpointId"]),A=Array.isArray(e.next)?[...e.next]:(e==null?void 0:e.next)===null?null:void 0;return{messages:c,checkpointId:h??null,checkpointNs:p??null,nextCursor:y,nextCursorNs:g,interrupt:wg(a,c,t),createdAt:S,parentId:I??null,branchLabel:T??null,lastUserMessageId:(k==null?void 0:k.id)??null,hasMessages:c.length>0,messagesLen:c.length,metadata:C??null,config:d??null,parentConfig:x??null,next:A??null,tasks:l??null,values:i??null}}function wg(e,t,n){const r=_g(e,n);return r||Ng(t,n)}function Sg(e){const t=new Map;e.forEach((o,s)=>{if(!di(o))return;const i=Ul(o,s);if(!(i!=null&&i.checkpointId))return;const a=bg(i.checkpointId,i.checkpointNs??null),l=t.get(a);if(!l){t.set(a,i);return}t.set(a,Ig(l,i))});const n=Array.from(t.values());n.sort((o,s)=>Wl(s.createdAt??"")-Wl(o.createdAt??""));const r={};for(const[o,s]of t.entries())r[o]=s;return{orderedSnapshots:n,snapshotMap:r}}function Cg(e){var n,r;const t=[];for(const o of e){const s=o.checkpointId??null;if(!s)continue;const i=o.metadata??{},a=dt(i,["label"])??dt(i,["branch_label","branchLabel"])??dt(i,["description"])??"User input",l=kg(i,["step"]),c=dt(i,["source"]),d=o.createdAt??null,f=((r=(n=o.messages)==null?void 0:n[o.messages.length-1])==null?void 0:r.id)??null,h=o.lastUserMessageId??f,p=Tg(o.next);t.push({id:s,label:a,messageId:h,step:l,source:c??null,createdAt:d,next:p??void 0,parentConfig:o.parentConfig??null})}return t}function Tg(e){if(!Array.isArray(e)||e.length===0)return null;const t=e.map(n=>{if(typeof n=="string")return n.trim();if(n&&typeof n=="object"&&"type"in n){const r=n;if(typeof r.type=="string")return r.type}return null}).filter(n=>!!(n&&n.length));return t.length?t.join(", "):null}function kg(e,t){if(!e)return null;for(const n of t){const r=e[n];if(typeof r=="number"&&Number.isFinite(r))return r}return null}function Ig(e,t){return{...e,metadata:Eo(e.metadata,t.metadata)??null,config:Eo(e.config,t.config)??null,parentConfig:Eo(e.parentConfig,t.parentConfig)??null,next:Eg(e.next,t.next)??null,tasks:Ag(e.tasks,t.tasks)??null,values:Eo(e.values,t.values)??null}}function Eo(e,t){return t&&typeof t=="object"?{...e&&typeof e=="object"?e:{},...t}:t===null?e&&typeof e=="object"?{...e}:e??null:e&&typeof e=="object"?{...e}:e??void 0}function Eg(e,t){return Array.isArray(t)?t.slice():t===null?Array.isArray(e)?e.slice():e??null:Array.isArray(e)?e.slice():e??void 0}function Ag(e,t){return Array.isArray(t)?t.map(n=>({...n})):t===null?Array.isArray(e)?e.map(n=>({...n})):e??null:Array.isArray(e)?e.map(n=>({...n})):e??void 0}function Ng(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 _g(e,t){if(!Array.isArray(e)||!e.length)return null;for(let n=e.length-1;n>=0;n--){const r=jg(e[n],`task-${t}-${n}`);if(!r)continue;const o=r.id||`task-${t}-${n}`;if(Array.isArray(r.interrupts)&&r.interrupts.length)for(let s=r.interrupts.length-1;s>=0;s--){const i=Dr(r.interrupts[s],`${o}-interrupt-${s}`);if(i)return i}if(r.state!==void 0&&r.state!==null){const s=Dr(r.state,`${o}-state`);if(s)return s}}return null}function jg(e,t){if(!e)return null;if(Array.isArray(e)){const[a,l,c,,d,,f,...h]=e,p=typeof a=="string"&&a.trim()?a:t,x=typeof l=="string"&&l.trim()?l:Array.isArray(c)&&typeof c[0]=="string"?String(c[0]):"task",m=Array.isArray(d)?d:void 0,y=h.length?h[h.length-1]:void 0;return{id:p,name:x,interrupts:m,state:y!==void 0?y:f}}const n=Pt(e);if(!n)return null;const r=dt(n,["id","thread_id","taskId"])??t,o=dt(n,["name"])??"task",s=Array.isArray(n.interrupts)?n.interrupts:void 0,i=Object.prototype.hasOwnProperty.call(n,"state")?n.state:void 0;return{id:r,name:o,interrupts:s,state:i}}function Dr(e,t,n=0,r=new Set){if(n>6||e==null)return null;if(typeof e=="object"){if(r.has(e))return null;r.add(e)}const o=Hl(e,t);if(o)return o;if(Array.isArray(e)){for(let s=e.length-1;s>=0;s--){const i=Dr(e[s],t,n+1,r);if(i)return i}return null}if(typeof e=="object"){const s=e,i=["interrupt","pending_interrupt","pendingInterrupt","value","data","payload","result","response"];for(const a of i)if(a in s){const l=Dr(s[a],t,n+1,r);if(l)return l}for(const[a,l]of Object.entries(s)){if(i.includes(a)||a==="messages"||a==="results")continue;const c=Dr(l,t,n+1,r);if(c)return c}}return null}function Hl(e,t){if(!e)return null;if(typeof e=="object"&&!Array.isArray(e)){const n=e,r=dt(n,["type","event","kind"]),o=dt(n,["id","interrupt_id","interruptId","value_id"])??(r&&r.toLowerCase().includes("interrupt")?t:void 0);if(!(Object.prototype.hasOwnProperty.call(n,"value")||Object.prototype.hasOwnProperty.call(n,"data")||Object.prototype.hasOwnProperty.call(n,"payload"))&&!(r&&r.toLowerCase().includes("interrupt")))return null;const i=Object.prototype.hasOwnProperty.call(n,"value")?n.value:Object.prototype.hasOwnProperty.call(n,"data")?n.data:Object.prototype.hasOwnProperty.call(n,"payload")?n.payload:n,a=o&&o.trim()?o:t;return a?{id:a,value:i}:null}if(Array.isArray(e)){for(let n=e.length-1;n>=0;n--){const r=Hl(e[n],t);if(r)return r}return e.length>=2&&typeof e[0]=="string"&&e[0].trim()?{id:e[0],value:e[1]}:null}if(typeof e=="string"){const n=e.trim();return n?{id:t||n,value:n}:null}return null}function Wl(e){if(!e)return 0;const t=Date.parse(e);return Number.isFinite(t)?t:0}function Rg(e,t){if(!e||typeof e!="object")return null;const n=e,r=Pt(e)??{},o=Pt(n.data)??r,s=String(n.type??o.type??o.role??"").toLowerCase(),i=vg[s];if(!i)return null;const a=o.id??o.message_id??o.run_id??null,l=typeof a=="string"&&a.trim()?a:`history-${i}-${t}`,c=Pt(o.additional_kwargs)??Pt(o.additionalKwargs),d=Pt(o.response_metadata)??Pt(o.responseMetadata),f=dt(c,["createdAt","created_at"])??dt(o,["created_at","createdAt"]),h=dt(c,["checkpointId","checkpoint_id"]),p=dt(c,["checkpointNs","checkpoint_ns"]),x=Mg(o.content),m={id:l,role:i,content:x};f&&(m.createdAt=f),typeof o.name=="string"&&o.name.trim()&&(m.name=o.name),typeof(d==null?void 0:d.model_name)=="string"&&(m.model=String(d.model_name)),!m.model&&typeof o.model=="string"&&(m.model=o.model),h&&(m.checkpointId=h),p&&(m.checkpointNs=p);const y=Dg(Pt(o.artifact??r.artifact??o.artifacts??r.artifacts));y&&(m.artifact=y);const g=Bg(c,["createdAt","created_at","checkpointId","checkpoint_id","checkpointNs","checkpoint_ns","tool_calls"]),b=d?{...d}:void 0;g&&Object.keys(g).length&&(m.additionalKwargs=g),b&&Object.keys(b).length&&(m.responseMetadata=b);const S=Pg((c==null?void 0:c.tool_calls)??o.tool_calls);if(S.length&&(m.content=[...m.content,...S]),i==="tool"){const k=Og(o,m.content);k&&(m.content=k)}return m}function Mg(e){if(!e)return[];if(Array.isArray(e))return e.map(t=>Vl(t)).filter(t=>!!t);if(typeof e=="string")return e.trim()?[{type:"text",text:e.trim()}]:[];if(typeof e=="object"){const t=Vl(e);return t?[t]:[]}return[]}function Vl(e){if(!e||typeof e!="object")return typeof e=="string"&&e.trim()?{type:"text",text:e}:null;const t=e,n=String(t.type??"").toLowerCase();if(!n||n==="text"){const o=typeof t.text=="string"?t.text:typeof t.value=="string"?t.value:"";return o.trim()?{type:"text",text:o}:null}if(n==="image"||n==="image_url"){const o=dt(t,["url","src"]);if(!o)return null;const s={type:"image_url",url:o};return typeof t.mimeType=="string"&&(s.mimeType=t.mimeType),typeof t.alt=="string"&&(s.alt=t.alt),s}if(n==="file"){const o=dt(t,["url"]);if(!o)return null;const s={type:"file",url:o};return typeof t.mimeType=="string"&&(s.mimeType=t.mimeType),typeof t.name=="string"&&(s.name=t.name),typeof t.size=="number"&&(s.size=t.size),typeof t.sourceType=="string"&&(s.sourceType=t.sourceType),s}if(n==="tool_call")return Kl(t)??null;if(n==="tool_end"){const o="output"in t?t.output:t.content;return o?{type:"text",text:typeof o=="string"?o:JSON.stringify(o)}:null}if(n==="interrupt")return{type:"interrupt",value:t.value,...t};if(n==="tool"){const o=dt(t,["text","content"]);if(o)return{type:"text",text:o}}const r=typeof t.content=="string"?t.content:typeof t.value=="string"?t.value:JSON.stringify(t);return r?{type:"text",text:r}:null}function Kl(e,t){var s;const n=dt(e,["id","call_id"])??t,r=dt(e,["name"])??dt(Pt(e.function),["name"]);if(!n||!r)return null;const o=Fg(e.args??e.arguments??((s=Pt(e.function))==null?void 0:s.arguments));return{type:"tool_call",id:n,name:r,args:o}}function Pg(e){return Array.isArray(e)?e.map((t,n)=>Kl(t,`tool_call_${n}`)).filter(t=>!!t):[]}function Og(e,t){const n=e.content??e.output;if(!n)return t;const o={type:"text",text:typeof n=="string"?n:JSON.stringify(n)};return[...t,o]}function Dg(e){return e?{plots:Lg(e.plots)}:void 0}function Lg(e){return Array.isArray(e)?e.map(t=>$g(t)).filter(t=>!!t):[]}function $g(e){if(!e||typeof e!="object")return null;const t=e,n=typeof t.content_base64=="string"&&t.content_base64.trim()||void 0,r=typeof t.url=="string"&&t.url.trim()||void 0,o=(typeof t.format=="string"?t.format.trim():void 0)||(typeof t.mimeType=="string"?t.mimeType.trim():void 0)||(typeof t.mime_type=="string"?t.mime_type.trim():void 0),s=typeof t.plotId=="string"&&t.plotId.trim()||void 0,i=typeof t.artifactId=="string"&&t.artifactId.trim()||void 0,a={};return n&&(a.content_base64=n),r&&(a.url=r),o&&(a.format=o),s&&(a.plotId=s),i&&(a.artifactId=i),a}function Fg(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 Pt(e){if(!(!e||typeof e!="object"||Array.isArray(e)))return{...e}}function dt(e,t){if(e)for(const n of t){const r=e[n];if(typeof r=="string"&&r.trim())return r}}function 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}const fr=120;function zg(e){if(!Array.isArray(e))return"";const t=e.filter(r=>!!(r&&r.type==="text")).map(r=>(r.text??"").trim()).filter(Boolean);if(!t.length)return"";const n=t.join(" ").replace(/\s+/g," ").trim();return n?n.length>fr?`${n.slice(0,fr-3)}…`:n:""}function Ug(e){var r,o;const t=[(r=e.additionalKwargs)==null?void 0:r.summary,(o=e.responseMetadata)==null?void 0:o.summary];for(const s of t)if(typeof s=="string"&&s.trim()){const i=s.trim();return i.length>fr?`${i.slice(0,fr-3)}…`:i}const n=(e.name||e.id||"").toString().trim();return n?n.length>fr?`${n.slice(0,fr-3)}…`:n:""}function ql(e){const t=new Map;for(const n of e){if(!n.id||n.role!=="user")continue;const o=zg(n.content)||Ug(n);o&&t.set(n.id,o)}return t}function Gl(e={}){const t=w.useMemo(()=>wn(e.baseUrl),[e.baseUrl]),n=e.streamPath??"/runs/stream",[r,o]=w.useState(e.token??null),s=w.useRef(e.headers??{}),i=e.credentials??"include",[a,l]=w.useState(!1),[c,d]=w.useState(null),[f,h]=w.useState(""),[p,x]=w.useState(null),[m,y]=w.useState(0),[g,b]=w.useState(!1),S=w.useRef(null),k=w.useRef(!0),C=w.useRef(0),T=w.useRef(null),I=w.useRef(null),A=w.useRef(null),R=w.useRef(null),L=w.useCallback(N=>{o(N)},[]),P=w.useCallback(()=>{h(""),x(null),d(null),I.current=null,A.current=null,R.current=null},[]),D=w.useCallback(()=>{var N;console.debug("[use-chat] stop() invoked - aborting stream"),(N=S.current)==null||N.abort(),S.current=null,T.current=null,l(!1),b(!1),C.current=0,y(0)},[]),F=w.useCallback((N,B,j)=>{S.current&&(S.current.abort(),S.current=null),l(!0),d(null),e.autoAppendAssistant!==!1&&h(""),x(null),I.current=null,A.current=null,R.current=null;const V=new AbortController;S.current=V;let z=null,M=null,q=!1;return T.current={threadId:N.threadId??null,headers:{}},(async()=>{var se,ge,Ee,Y,U,Z,$,K,Q,ce,oe,Ne,Ue,re,xe,Pe,Ze,Qe;const J=Ve=>{var tt;try{const it=JSON.parse(JSON.stringify(Ve));return(tt=it==null?void 0:it.payload)!=null&&tt.files_info&&Array.isArray(it.payload.files_info)&&(it.payload.files_info=it.payload.files_info.map(qe=>({...qe,data:qe!=null&&qe.data?`<base64 ${String(qe.data).length} chars>`:qe==null?void 0:qe.data}))),it}catch{return Ve}};try{let Ve={};try{if(r)Ve={Authorization:`Bearer ${r}`};else if(typeof window<"u"){const Ye=window.__AUTH_TOKEN__,pt=((se=window.localStorage)==null?void 0:se.getItem("authToken"))||null;let lt=null;try{const _=(ge=window.localStorage)==null?void 0:ge.getItem("chat-settings");_&&(lt=((Ee=JSON.parse(_))==null?void 0:Ee.apiKey)||null)}catch{}const G=Ye||pt||lt||null;G&&(Ve={Authorization:`Bearer ${G}`})}}catch{}console.debug("[use-chat] POST",t+n,J(N));let tt={};if(typeof window<"u")try{const Ge=(Y=window.localStorage)==null?void 0:Y.getItem("authSessionId");Ge&&(tt={"X-Session-Id":Ge})}catch{}const it={...Ve,...tt,...s.current},qe={"Content-Type":"application/json",Accept:"text/event-stream",...it},nt=await fetch(t+n,{method:"POST",headers:qe,body:JSON.stringify(N),signal:V.signal,credentials:i});if(T.current&&(T.current.headers=it),!nt.ok||!nt.body){const Ge=await nt.text().catch(()=>"");console.debug("[use-chat] non-OK response",nt.status,Ge==null?void 0:Ge.slice(0,500));const Ye=`stream ${nt.status}${Ge?": "+Ge:""}`;throw(U=j==null?void 0:j.onConnectionError)==null||U.call(j,Ye),q=!0,z="error",M=Ye,new Error(Ye)}b(!0);const at=nt.body.getReader(),Rt=new TextDecoder;let gt="",ht=[];C.current=0,y(0);let bt=0,St=null;const Lt=()=>{if(ht.length){const Ge=ht.join("");ht=[],k.current&&h(Ye=>Ye+Ge)}St=null},Mt=()=>{typeof window<"u"&&St==null&&(St=requestAnimationFrame(Lt))};let et=Date.now();const It=setInterval(()=>{var Ge;if(Date.now()-et>18e5){const Ye="Stream idle timeout";d(Ye),z="error",M=Ye,V.abort(),(Ge=j==null?void 0:j.onError)==null||Ge.call(j,Ye)}},5e3),bn=1024*1024;try{const Ge=nt.headers.get("X-Thread-Id")||nt.headers.get("x-thread-id"),Ye=nt.headers.get("X-Thread-Created")||nt.headers.get("x-thread-created"),pt=Ge??null,lt=String(Ye??"").toLowerCase()==="true";for(T.current&&!T.current.threadId&&(T.current={...T.current,threadId:pt}),(Z=j==null?void 0:j.onOpen)==null||Z.call(j,{threadId:pt,created:lt});;){const{value:G,done:_}=await at.read();if(_)break;gt+=Rt.decode(G,{stream:!0}),gt.length>bn&&(gt="",console.warn("Stream buffer reset: exceeded 1MB"));let X;for(;(X=gt.indexOf(`
|
|
36
36
|
|
|
37
|
-
`))>=0;){const te=gt.slice(0,X);gt=gt.slice(X+2);const pe=Wg(te);if(!pe)continue;let ve;try{ve=JSON.parse(pe)}catch{console.debug("[use-chat] malformed SSE:",pe.slice(0,200));continue}const we=Hg(ve)?ve.data:ve;et=Date.now();const Fe=we.seq;if(Fe!==void 0){if(Fe<=bt){console.debug("[use-chat] drop duplicate/out-of-order event",{seq:Fe,lastProcessedSeq:bt,type:we.type});continue}bt>0&&Fe>bt+1&&(($=j==null?void 0:j.onGap)==null||$.call(j,{from:bt,to:Fe})),bt=Fe,C.current=Fe,y(Fe)}if(console.debug("[use-chat] received event",{seq:we.seq,type:we.type,preview:(()=>{var Oe;try{return we.type==="message_delta"?{deltaTypes:(Oe=we.delta)==null?void 0:Oe.map(je=>je.type),textLen:(we.delta||[]).filter(je=>je.type==="text").map(je=>String(je.text||"").length)}:we.content||we.delta?{hasContent:!0}:{}}catch(je){return{err:String(je)}}})()}),we.type==="checkpoint")I.current=we.checkpointId??null,A.current=we.checkpointNs??null,x(we.checkpointId??null);else if(we.type==="state_history"){R.current=we;try{const je=dr(we).latest;je&&(I.current=je.checkpointId??null,A.current=je.checkpointNs??null,x(je.checkpointId??null))}catch(Oe){console.warn("[use-chat] Failed to hydrate state_history payload",Oe)}}try{B==null||B(we)}catch(Oe){console.error("[use-chat] Error in onEvent callback:",Oe,"for event:",we.type)}if(we.type==="token"&&e.autoAppendAssistant!==!1)ht.push(we.content),Mt();else if(we.type==="message_delta"){const Oe=we.delta.filter(je=>je.type==="text").map(je=>je.text).join("");Oe&&e.autoAppendAssistant!==!1&&(ht.push(Oe),Mt())}else if(we.type==="heartbeat"){console.debug("[use-chat] heartbeat received");try{(K=j==null?void 0:j.onHeartbeat)==null||K.call(j,we)}catch(Oe){console.warn("[use-chat] heartbeat callback failed",Oe)}}else if(St!==null&&cancelAnimationFrame(St),Lt(),we.type==="checkpoint")x(we.checkpointId);else if(we.type==="error"){const Oe=we;if(d(Oe.message),z="error",M=Oe.message,Oe.error_type==="auth_error"||Oe.code==="TOKEN_EXPIRED"||((Q=Oe.message)==null?void 0:Q.includes("token"))||((ce=Oe.message)==null?void 0:ce.includes("401"))||((oe=Oe.message)==null?void 0:oe.includes("unauthorized"))||((Ne=Oe.message)==null?void 0:Ne.includes("Unauthorized"))){console.error("[use-chat] Auth error detected:",Oe.message);try{(Ue=j==null?void 0:j.onAuthError)==null||Ue.call(j,Oe.message)}catch(Vt){console.warn("[use-chat] onAuthError handler failed",Vt)}V.abort()}}}}Lt(),z===null&&!V.signal.aborted&&(z="complete")}catch(Ge){if(Ge.name==="AbortError")z=z??"aborted";else{const Ye=Ge.message||String(Ge);z="error",M=Ye,d(Ye),(re=j==null?void 0:j.onError)==null||re.call(j,Ye)}}finally{try{await at.cancel()}catch{}finally{(xe=at.releaseLock)==null||xe.call(at)}St!==null&&typeof window<"u"&&window.cancelAnimationFrame(St),clearInterval(It)}}catch(Ve){if(Ve.name==="AbortError")z=z??"aborted";else{const tt=Ve.message||String(Ve);z="error",M=tt,d(tt),(Pe=j==null?void 0:j.onError)==null||Pe.call(j,tt),q||((Ze=j==null?void 0:j.onConnectionError)==null||Ze.call(j,tt),q=!0)}}finally{const Ve=C.current,tt=I.current,it=A.current,qe=R.current,nt=z??(V.signal.aborted?"aborted":M?"error":"complete");try{(Qe=j==null?void 0:j.onClosed)==null||Qe.call(j,{reason:nt,lastSeq:Ve,lastCheckpointId:tt,lastCheckpointNs:it,lastStateHistory:qe,error:M})}catch(at){console.warn("[use-chat] onClosed callback failed",at)}l(!1),b(!1),S.current=null,C.current=0,y(0),T.current=null}})(),{close:()=>V.abort()}},[t,n,r,e.autoAppendAssistant]);return w.useEffect(()=>()=>{var N;k.current=!1,(N=S.current)==null||N.abort()},[]),{isStreaming:a,error:c,assistantText:f,lastCheckpointId:
|
|
38
|
-
`)}function Vg(e){return e.type!=="token"}const Kg={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null,messagesStreamMeta:{},pendingInterrupt:null};function qg(e,t){var n;switch(t.type){case"reset":return{messages:fi(((n=t.payload)==null?void 0:n.messages)??[]),assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null,pendingInterrupt:null};case"seed":{const r=fi(t.payload.messages),o={...e,messages:r,assemblingId:null,pendingInterrupt:t.payload.pendingInterrupt??null};return Object.prototype.hasOwnProperty.call(t.payload,"checkpointId")&&(o.lastCheckpointId=t.payload.checkpointId??null),Object.prototype.hasOwnProperty.call(t.payload,"checkpointNs")&&(o.lastCheckpointNs=t.payload.checkpointNs??null),o}case"prepend":{const r=fi(t.payload.messages);if(!r.length)return e;const o=new Set(e.messages.map(i=>i.id)),s=r.filter(i=>!o.has(i.id));return s.length?{...e,messages:[...s,...e.messages]}: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 Xl(e,t.payload.ev);case"batch":{const{events:r}=t.payload;return r.length?r.reduce((o,s)=>Xl(o,s),e):e}case"interrupt_response":return{...e,messages:Jl(e.messages),pendingInterrupt:null};default:return e}}function Yl(e=[]){const[t,n]=w.useReducer(qg,{...Kg,messages:e}),r=w.useRef([]),o=w.useRef(null),s=w.useRef(null),i=w.useCallback(()=>{o.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.current),s.current!==null&&clearTimeout(s.current),o.current=null,s.current=null;const d=r.current;d.length&&(r.current=[],n({type:"batch",payload:{events:d}}))},[]),a=w.useCallback(()=>{typeof window<"u"&&typeof window.requestAnimationFrame=="function"?o.current===null&&(o.current=window.requestAnimationFrame(()=>i())):s.current===null&&(s.current=setTimeout(i,8))},[i]),l=w.useCallback(d=>{r.current.push(d),a()},[a]);w.useEffect(()=>()=>{o.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.current),s.current!==null&&clearTimeout(s.current),r.current=[]},[]);const c=w.useMemo(()=>({reset:d=>n({type:"reset",payload:{messages:d}}),seed:(d,f)=>n({type:"seed",payload:{messages:d,...f??{}}}),prepend:d=>n({type:"prepend",payload:{messages:d}}),pushUser:d=>n({type:"user_message",payload:{message:d}}),onEvent:l}),[l]);return{state:t,dispatch:n,...c}}function Xl(e,t){var n,r,o,s,i;if(t.type==="message_start"&&t.role==="assistant"){const a=t.id,l=Jg(t.model);if(e.messages.some(f=>f.id===a)){const f=e.messagesStreamMeta??{},p={...f,[a]:f[a]??{lastSeq:t.seq??null,lastText:""}};return{...e,assemblingId:a,messagesStreamMeta:p}}const d={id:a,role:"assistant",name:l||void 0,model:t.model,createdAt:new Date().toISOString(),content:[]};return{...e,assemblingId:a,messages:[...e.messages,d]}}if(t.type==="message_delta"){const a=e.assemblingId??Zl(e.messages);if(!a)return e;const l=e.messages,c=l.findIndex(k=>k.id===a&&k.role==="assistant");if(c===-1)return e;const d=l[c],f=e.messagesStreamMeta??{},p=f[a]??{lastSeq:null,lastText:tc(d.content)},h=t.seq??null;if(h!==null&&typeof h=="number"&&typeof p.lastSeq=="number"&&h<=p.lastSeq)return console.debug("[MessageReducer] skipping delta - seq <= lastSeq",{seq:h,lastSeq:p.lastSeq}),e;const{newParts:x,newMeta:m,changed:y}=Gg(d.content,t.delta,p,h);if(!y)return e;const g={...d,content:x},b=Ao(l,c,g),S={...f,[a]:m};return{...e,messages:b,messagesStreamMeta:S}}if(t.type==="message_end"){const a=e.assemblingId??Zl(e.messages);if(!a)return{...e,assemblingId:null};const l=e.messages,c=l.findIndex(d=>d.id===a&&d.role==="assistant");if(c>=0){const d=l[c];if(!((n=d.content)==null?void 0:n.some(p=>{var h;return(p==null?void 0:p.type)==="text"&&((h=p.text)==null?void 0:h.trim())}))){console.debug("[MessageReducer] pruning assistant message with no visible text",{id:d.id,contentTypes:(r=d.content)==null?void 0:r.map(h=>h==null?void 0:h.type),contentPreview:(o=d.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 p=[...l.slice(0,c),...l.slice(c+1)];return{...e,assemblingId:null,messages:p}}}return e}if(t.type==="tool_start"){const a=Ql(t),l=a[0]??(typeof t.id=="string"?t.id:null)??(typeof t.call_id=="string"?t.call_id:null),c=t.name??t.tool??"tool";!l&&a.length===0&&a.push(`${c}-${Date.now()}`);const d=a.length?a:l?[l]:[],f=ec(e,d,c),p=f>=0?e.messages[f]:null,h=l??d[0]??`${c}-${Date.now()}`,x=(p==null?void 0:p.id)??`tool-${h}`,m=d[0]??h,y={type:"tool_call",id:m,name:c,args:t.args};if(p){const S=hi(p,d,c,t.args),k={...p,name:p.name??c,additionalKwargs:S},C=f,T=C>=0?Ao(e.messages,C,k):e.messages,I=No(k,d),A=mi(e.toolIndex,x,I);return{...e,messages:T,toolIndex:A}}const g={id:x,role:"tool",name:c,createdAt:new Date().toISOString(),content:[y],additionalKwargs:hi(void 0,d.length?d:[m],c,t.args)},b=No(g,d.length?d:[m]);return{...e,messages:[...e.messages,g],toolIndex:mi(e.toolIndex,x,b)}}if(t.type==="tool_end"){const a=Ql(t);if(!a.length&&!(typeof t.id=="string"&&t.id))return e;const l=t.name??null,c=ec(e,a,l),d=c>=0?e.messages[c]:null,f=l??(d==null?void 0:d.name)??((s=d==null?void 0:d.additionalKwargs)==null?void 0:s.toolName)??"tool",p=a[0]??((i=d==null?void 0:d.id)==null?void 0:i.replace(/^tool-/,""))??`${f}-${Date.now()}`,h=(d==null?void 0:d.id)??`tool-${p}`,x=No(d,a);let m=t.output;if(typeof t.output=="string")try{const I=t.output.trim();(I.startsWith("{")||I.startsWith("["))&&(m=JSON.parse(I))}catch{m=t.output}const y=t.artifact??(d==null?void 0:d.artifact),g={type:"text",text:typeof m=="string"?m:JSON.stringify(m)},b=(d==null?void 0:d.createdAt)??new Date().toISOString(),S=hi(d??void 0,x.length?x:a,f),k={id:h,role:"tool",name:f??(d==null?void 0:d.name)??"tool",content:[g],createdAt:b,artifact:y??void 0,additionalKwargs:S},C=c>=0?Ao(e.messages,c,k):[...e.messages,k],T=No(k,a.length?a:x);return{...e,messages:C,toolIndex:mi(e.toolIndex,h,T)}}if(t.type==="checkpoint"){const a=t.checkpointNs??e.lastCheckpointNs??null,l=Xg(e.messages,t.checkpointId,a);return{...e,lastCheckpointId:t.checkpointId,lastCheckpointNs:a,messages:l}}if(t.type==="branch"){const a=t.checkpointId??e.lastCheckpointId,l=t.checkpointNs??e.lastCheckpointNs;return{...e,lastBranch:t,lastCheckpointId:a??null,lastCheckpointNs:l??null}}if(t.type==="error"){const a={id:`err-${Date.now()}`,role:"system",content:[{type:"text",text:`Error: ${t.message}`}],createdAt:new Date().toISOString()};return{...e,messages:[...e.messages,a]}}if(t.type==="state_history"){const a=dr(t),l=a.interrupt,c=a.latest,d=l===null?Jl(e.messages):e.messages;return{...e,messages:d,pendingInterrupt:l,lastCheckpointId:(c==null?void 0:c.checkpointId)??e.lastCheckpointId,lastCheckpointNs:(c==null?void 0:c.checkpointNs)??e.lastCheckpointNs}}return t.type==="thread_info",e}function fi(e){return e.filter(t=>{var s;if(t.role!=="assistant")return!0;const n=(t.content||[]).some(i=>{var a;return i&&i.type==="text"&&((a=i.text)==null?void 0:a.trim())}),r=(t.content||[]).some(i=>i&&i.type==="image_url"),o=!!((s=t.artifact)!=null&&s.plots&&t.artifact.plots.length>0);return!!(n||r||o)})}function Ao(e,t,n){return t<0||t>=e.length?e:[...e.slice(0,t),n,...e.slice(t+1)]}function Jl(e){let t=!1;const n=e.map(r=>{const o=(r.content??[]).filter(s=>s.type!=="interrupt");return o.length!==r.content.length?(t=!0,{...r,content:o}):r});return t?n:e}function Zl(e){for(let t=e.length-1;t>=0;t--)if(e[t].role==="assistant")return e[t].id;return null}function Ql(e){const t=new Set,n=r=>{typeof r=="string"&&r.trim()&&t.add(r.trim())};return n(e.id),n(e==null?void 0:e.call_id),n(e==null?void 0:e.callId),Array.from(t)}function pi(e){if(!e)return[];const t=new Set,n=o=>{typeof o=="string"&&o.trim()&&t.add(o.trim())},r=e.additionalKwargs;if(r){n(r.toolCallId);const o=r.toolCallIds;if(Array.isArray(o))for(const s of o)n(s)}for(const o of e.content??[])(o==null?void 0:o.type)==="tool_call"&&n(o.id);return Array.from(t)}function hi(e,t,n,r){const o=new Set,s=l=>{typeof l=="string"&&l.trim()&&o.add(l.trim())};if(e){const l=pi(e);for(const c of l)s(c)}for(const l of t)s(l);const i=Array.from(o),a={...(e==null?void 0:e.additionalKwargs)??{}};if(i.length){a.toolCallIds=i;const l=typeof a.toolCallId=="string"?a.toolCallId.trim():null;a.toolCallId=l&&o.has(l)?l:i[0]}return n&&(a.toolName=n),r!==void 0&&(a.toolArgs=r),a}function No(e,t){const n=new Set;for(const o of t)typeof o=="string"&&o.trim()&&n.add(o.trim());const r=pi(e);for(const o of r)n.add(o);return Array.from(n)}function mi(e,t,n){if(!n.length)return e;let r=!1;const o={...e};for(const s of n)s&&o[s]!==t&&(o[s]=t,r=!0);return r?o:e}function ec(e,t,n){var o,s;const r=new Set(t.filter(i=>typeof i=="string"&&i.trim()));for(const i of r){const a=e.toolIndex[i];if(a){const l=e.messages.findIndex(c=>c.id===a);if(l!==-1)return l}}for(let i=e.messages.length-1;i>=0;i--){const a=e.messages[i];if(a.role!=="tool")continue;if(pi(a).some(c=>r.has(c)))return i}if(typeof n=="string"&&n.trim())for(let i=e.messages.length-1;i>=0;i--){const a=e.messages[i];if(a.role!=="tool"||a.name&&a.name!==n)continue;if(!((o=a.content)==null?void 0:o.some(c=>c.type!=="tool_call")))return i}for(let i=e.messages.length-1;i>=0;i--){const a=e.messages[i];if(a.role!=="tool")continue;if(!((s=a.content)==null?void 0:s.some(c=>c.type!=="tool_call")))return i}return-1}function tc(e){return!e||!e.length?"":e.filter(t=>t.type==="text").map(t=>t.text??"").join("")}function Gg(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??tc(e);let l="",c=e.slice();if(s){const f=Yg(a,s);if(f===""?l="":f===s?l=s:l=f,l){const p=c[c.length-1];if((p==null?void 0:p.type)==="text"){const h=p.text??"",x={...p,text:h+l};c=[...c.slice(0,c.length-1),x]}else c=[...c,{type:"text",text:l}];o.lastText=a+l}else o.lastText=a}i.length&&(c=[...c,...i]);const d=!!(l||i.length);return{newParts:c,newMeta:o,changed:d}}function nc(e){return e.replace(/\s+/g," ").trim()}function Yg(e,t){if(!t)return"";if(!e)return t;if(e===t)return"";const n=Math.min(e.length,t.length);for(let i=n;i>0;i--)if(e.slice(-i)===t.slice(0,i))return t.slice(i);const r=nc(e),o=nc(t);if(r===o)return"";const s=Math.min(r.length,o.length);for(let i=s;i>0;i--)if(r.slice(-i)===o.slice(0,i))return t;return t}function Xg(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 Ao(e,r,s)}return e}function Jg(e){if(!e)return null;const t=e.split("/");return t[t.length-1]||null}const rc=200;function Zg({baseUrl:e,onThreadInfo:t,onMessageEvent:n,onStateHistory:r,onUnhandledEvent:o,onSequenceGap:s,onStreamClosed:i,onConnectionError:a,onAuthError:l,onHeartbeat:c}){const d=w.useRef(null),f=w.useRef(null),p=w.useRef(new Map),h=w.useRef(null),x=w.useRef(null),m=w.useCallback(P=>{try{const D=globalThis.structuredClone;if(typeof D=="function")return D(P)}catch{}try{return JSON.parse(JSON.stringify(P))}catch{return P}},[]),y=w.useCallback((P,D)=>{if(!P)return;const F=p.current.get(P)??[],N=m(D),B=F.length>=rc?[...F.slice(F.length-rc+1),N]:[...F,N];p.current.set(P,B)},[m]),g=w.useCallback(P=>{P&&p.current.set(P,[])},[]),b=w.useCallback(P=>{const D=P??f.current;if(!D)return;const F=p.current.get(D);F!=null&&F.length&&F.forEach(N=>{try{n(N)}catch(B){console.error("[useChatStreamingService] Failed to replay buffered event",B)}})},[n]),S=w.useCallback(P=>{var N,B,j,V,z;const D=P.seq??null;if(D!==null){const M=d.current;if(M!==null){if(D<=M)return;D>M+1&&(s==null||s({from:M,to:D}))}d.current=D}if(P.type==="thread_info"){f.current=P.threadId,h.current&&(h.current.threadIdGuess=P.threadId),x.current=P,g(P.threadId),console.log("[useChatStreamingService] 🎯 Received thread_info event:",P);try{t(P)}catch(M){console.error("[useChatStreamingService] Error in onThreadInfo handler:",M)}return}if(P.type==="heartbeat"){try{c==null||c(P)}catch(M){console.error("[useChatStreamingService] Error in onHeartbeat handler:",M)}return}if(P.type==="error"){const M=P;if(M.error_type==="auth_error"||M.code==="TOKEN_EXPIRED"||((N=M.message)==null?void 0:N.includes("token"))||((B=M.message)==null?void 0:B.includes("401"))||((j=M.message)==null?void 0:j.includes("unauthorized"))||((V=M.message)==null?void 0:V.includes("Unauthorized"))){console.error("[useChatStreamingService] Auth error event detected:",M.message);try{l==null||l(M.message)}catch(J){console.warn("[useChatStreamingService] onAuthError handler failed",J)}}}const F=P.threadId??(P.type==="state_history"?P.threadId:void 0)??f.current??((z=h.current)==null?void 0:z.threadIdGuess)??null;if(P.type==="state_history"){f.current=F??f.current;try{r==null||r(P)}catch(M){console.error("[useChatStreamingService] onStateHistory handler failed",M)}}if(Vg(P)){P.type==="checkpoint"||P.type==="state_history"?g(F??null):y(F??null,P);try{n(P)}catch(M){console.error("[useChatStreamingService] Error in onMessageEvent handler:",M)}return}try{o==null||o(P)}catch(M){console.error("[useChatStreamingService] Error in onUnhandledEvent handler:",M)}},[y,g,n,s,t,r,o]),{stream:k,stop:C,isStreaming:T,error:I,setToken:A}=Gl({baseUrl:e,token:void 0}),R=w.useCallback((P,D)=>{d.current=null,x.current=null,f.current=P.threadId??null,h.current={request:P,callbacks:D,manualStop:!1,threadIdGuess:P.threadId??null},k(P,S,{onOpen:D==null?void 0:D.onOpen,onError:F=>{var N;(N=D==null?void 0:D.onError)==null||N.call(D,F)},onGap:(D==null?void 0:D.onGap)??s,onConnectionError:F=>{var N;a==null||a(F),(N=D==null?void 0:D.onConnectionError)==null||N.call(D,F)},onAuthError:F=>{var N;l==null||l(F),(N=D==null?void 0:D.onAuthError)==null||N.call(D,F)},onHeartbeat:F=>{var N;try{c==null||c(F)}catch(B){console.warn("[useChatStreamingService] onHeartbeat handler failed",B)}try{(N=D==null?void 0:D.onHeartbeat)==null||N.call(D,F)}catch(B){console.warn("[useChatStreamingService] downstream onHeartbeat handler failed",B)}},onClosed:F=>{var V,z,M,q;const N=((V=h.current)==null?void 0:V.manualStop)??!1,B=f.current??((z=h.current)==null?void 0:z.threadIdGuess)??((M=F.lastStateHistory)==null?void 0:M.threadId)??null;(F.reason==="complete"||F.reason==="aborted"&&N)&&g(B);const j={...F,threadId:B,threadInfo:x.current,manualStop:N};try{i==null||i(j)}catch(J){console.warn("[useChatStreamingService] onStreamClosed handler failed",J)}try{(q=D==null?void 0:D.onClosed)==null||q.call(D,j)}catch(J){console.warn("[useChatStreamingService] downstream onClosed handler failed",J)}h.current&&(h.current=null)}})},[g,S,l,a,c,s,i,k]),L=w.useCallback(()=>{h.current&&(h.current.manualStop=!0),C()},[C]);return w.useMemo(()=>({startStream:R,stop:L,isStreaming:T,error:I,setAuthToken:A,replayBufferedEvents:b}),[R,L,T,I,A,b])}const oc=w.createContext(null),sc=w.createContext(null),ic=w.createContext(null);w.createContext(!1);function Qg({children:e,initialThreadId:t=null,initialCheckpointId:n=null,initialCheckpointNs:r=null,autoLoadInitial:o=!0,onError:s,onAuthError:i,onThreadChange:a}){const{api:l,baseUrl:c}=ui(),d=w.useMemo(()=>wn(c),[c]),[f,p]=w.useState([]),[h,x]=w.useState(t),[m,y]=w.useState(!1),[g,b]=w.useState(null),[S,k]=w.useState(!1),[C,T]=w.useState(null),{state:I,seed:A,prepend:R,pushUser:L,onEvent:P}=Yl(),[D,F]=w.useState(!1),[N,B]=w.useState(!1),[j,V]=w.useState(null),[z,M]=w.useState([]),[q,J]=w.useState([]),[se,ge]=w.useState(!1),Ee=w.useMemo(()=>z.flatMap(G=>G.messages??[]),[z]),Y=w.useMemo(()=>ql(Ee),[Ee]),U=w.useRef(h),Z=w.useRef(null),$=w.useRef(null),K=w.useRef(null),Q=w.useRef(null),ce=w.useRef(!1),oe=w.useRef(null),Ne=w.useRef(new Map),Ue=w.useRef(new Map);w.useEffect(()=>{U.current=h},[h]);const re=w.useCallback(async()=>{y(!0),b(null);try{const G=await l.listThreads();p(G??[])}catch(G){const _=String(G);b(_),s==null||s(_)}finally{y(!1)}},[l,s]),xe=w.useCallback(G=>{if(!(G!=null&&G.threadId))return;const _={threadId:G.threadId,title:G.title||`Thread ${G.threadId.slice(0,8)}`,createdAt:G.createdAt||new Date().toISOString(),updatedAt:G.updatedAt||new Date().toISOString(),messageCount:G.messageCount??1};p(X=>{let te=!1;const pe=X.map(ve=>ve.threadId===_.threadId?(te=!0,console.debug("[ChatSessionProvider] thread_info: updating existing thread",_.threadId),{...ve,title:_.title??ve.title,updatedAt:_.updatedAt??ve.updatedAt,messageCount:_.messageCount??ve.messageCount}):ve);return te?pe:(console.debug("[ChatSessionProvider] thread_info: adding thread to list",_.threadId),[_,...X])})},[]),Pe=w.useCallback(G=>{const _=G.threadId??U.current;if(!_||U.current&&U.current!==_)return;const{checkpoints:X,timeline:te}=dr(G);if(!X.length)return;const pe=X.find(ve=>ve.messages&&ve.messages.length>0)??X.find(ve=>!!ve.checkpointId)??X[0];A((pe==null?void 0:pe.messages)??[],{checkpointId:(pe==null?void 0:pe.checkpointId)??null,checkpointNs:(pe==null?void 0:pe.checkpointNs)??null}),J(te),M(X),F(!!(pe!=null&&pe.nextCursor)),V((pe==null?void 0:pe.nextCursor)??null),oe.current=`${_}:latest`,$.current=null,K.current=null},[A]),Ze=w.useCallback(G=>{console.log("[ChatSessionProvider] 🎯 Received thread_info:",G.threadId),xe(G),U.current!==G.threadId&&((G.created??!U.current)&&($.current=G.threadId),K.current=G.threadId,console.log("[ChatSessionProvider] thread_info: marking to skip auto-load for new thread"),x(G.threadId))},[xe]),{startStream:Qe,stop:Ve,isStreaming:tt,error:it,setAuthToken:qe}=Zg({baseUrl:d,onThreadInfo:Ze,onMessageEvent:P,onStateHistory:Pe,onUnhandledEvent:G=>{console.warn("[ChatSessionProvider] Unhandled event:",G.type)},onAuthError:i}),nt=w.useCallback(async G=>{try{const _=await l.createThread(G);return x(_.threadId),await re(),_.threadId}catch(_){return s==null||s(String(_)),null}},[l,re,s]),at=w.useCallback(async G=>{const _=f;p(te=>te.filter(pe=>pe.threadId!==G));const X=new AbortController;Ue.current.set(G,X);try{await l.deleteThread(G),U.current===G&&(x(null),A([],{})),console.log("[ChatSessionProvider] Thread deleted successfully:",G)}catch(te){console.error("[ChatSessionProvider] Delete failed, restoring thread:",G,te),p(_),s==null||s(`Failed to delete thread: ${String(te)}`)}finally{Ue.current.delete(G)}},[f,l,A,s]),Rt=w.useCallback(async(G,_)=>{try{await l.updateThread(G,_),await re()}catch(X){s==null||s(String(X))}},[l,re,s]),gt=w.useCallback(async(G,_)=>{if(!G)return;const X=`${G}:${_??"latest"}`,te=Ne.current.get(X);if(te)return te;const pe=(async()=>{const ve=G;k(!0),T(null);try{const we=await l.getStateHistory({threadId:ve,checkpointId:_||void 0});if(U.current!==ve){console.log(`[ChatSessionProvider] Thread changed during load (was ${ve}, now ${U.current}), discarding stale data`);return}const{checkpoints:Fe,timeline:Oe}=dr(we),je=Fe.find(Vt=>Vt.messages&&Vt.messages.length>0)??(_?Fe.find(Vt=>Vt.checkpointId===_):null)??Fe[0];A((je==null?void 0:je.messages)??[],{checkpointId:(je==null?void 0:je.checkpointId)??null,checkpointNs:(je==null?void 0:je.checkpointNs)??null}),J(Oe),M(Fe),F(!!(je!=null&&je.nextCursor)),V((je==null?void 0:je.nextCursor)??null)}catch(we){if(U.current===ve){const Fe=String(we);T(Fe),s==null||s(Fe)}}finally{k(!1)}})();Ne.current.set(X,pe);try{await pe}finally{Ne.current.delete(X)}return U.current===G&&(oe.current=X),pe},[l,A,s]),ht=w.useCallback(async(G,_)=>{Q.current=G;try{await gt(G,_)}finally{Q.current===G&&(Q.current=null)}},[gt]);w.useEffect(()=>{if(!o||!h||S||tt)return;if($.current===h){$.current=null,Z.current=h;return}if(K.current===h){Z.current=h;return}if(Q.current===h){Q.current=null,Z.current=h;return}if(Z.current===h)return;Z.current=h;const G=!ce.current&&!!n&&h===t;let _;G&&n?(_=n,ce.current=!0,console.log("[ChatSessionProvider] Loading thread with checkpoint:",_,r?`(ns: ${r})`:"")):console.log("[ChatSessionProvider] Loading thread with latest checkpoint");const X=`${h}:${_??"latest"}`;oe.current!==X&&ht(h,_)},[o,h,n,r,t,S,tt,ht]);const bt=w.useCallback(async(G,_)=>{const X=U.current;if(!X)return;const te=X;ge(!0);try{const pe=await l.getStateHistory({threadId:te,checkpointId:G,checkpointNs:_??void 0});if(U.current!==te){console.log(`[ChatSessionProvider] Thread changed during checkpoint navigation (was ${te}, now ${U.current}), discarding stale data`);return}const{checkpoints:ve,timeline:we}=dr(pe),Fe=ve.find(Oe=>Oe.checkpointId===G&&(_?Oe.checkpointNs===_:!0));if(!Fe){console.warn("[ChatSessionProvider] Requested checkpoint not found:",{checkpointId:G,checkpointNs:_});return}J(we),M(ve),A(Fe.messages??[],{checkpointId:Fe.checkpointId??null,checkpointNs:Fe.checkpointNs??null})}catch(pe){U.current===te&&(s==null||s(String(pe)))}finally{ge(!1)}},[l,A,s]),St=w.useCallback((G,_)=>{A(I.messages,{checkpointId:G??null,checkpointNs:_??null})},[A,I.messages]),Lt=w.useCallback(async()=>{U.current&&await ht(U.current)},[ht]),Mt=w.useCallback(async()=>{if(!U.current||!j)return;const G=U.current;B(!0);try{const _=await l.getStateHistory({threadId:G,checkpointId:j});if(U.current!==G)return;const{checkpoints:X}=dr(_);if(X.length>0){const te=X[X.length-1];R((te==null?void 0:te.messages)??[]),F(!!(te!=null&&te.nextCursor)),V((te==null?void 0:te.nextCursor)??null)}}catch(_){U.current===G&&(s==null||s(String(_)))}finally{B(!1)}},[l,j,R,s]),et=w.useCallback(async()=>{A([],{}),x(null),Ve(),M([]),J([]),F(!1),V(null),k(!1),ge(!1),B(!1),T(null);try{await l.getAgent("default")}catch(G){console.warn("[ChatSessionProvider] Failed to refetch agent after clearing thread:",G)}},[A,Ve,l]),It=w.useCallback(async(G,_,X)=>{const te=U.current;if(!te)throw new Error("No active thread to handle interrupt");const pe=_?X??!0:!1;try{const ve={threadId:te,checkpointId:I.lastCheckpointId??void 0,checkpointNs:I.lastCheckpointNs??void 0,command:{kind:"resume",value:pe}};Qe(ve)}catch(ve){throw console.error(`[ChatSessionProvider] Failed to handle interrupt ${G}:`,ve),ve}},[I.lastCheckpointId,I.lastCheckpointNs,Qe]);w.useEffect(()=>{re()},[re]),w.useEffect(()=>{a==null||a(h)},[h,a]);const bn=w.useCallback(async(G,_)=>{let X=U.current;const te=(G==null?void 0:G.text)??"",pe=(G==null?void 0:G.attachments)??[],ve=(te==null?void 0:te.trim())??"",we={...(G==null?void 0:G.payload)??{}},Fe=Array.isArray(we.messages)?we.messages:void 0;Fe&&delete we.messages;const Oe=!!(Fe&&Fe.length);if(!X&&!ve&&pe.length===0&&!Oe)return;if(!X){const ie=Math.floor(Date.now()/1e3).toString(16).padStart(8,"0"),be=Array.from({length:4},()=>Math.floor(Math.random()*4294967295).toString(16).padStart(8,"0")).join("").slice(0,16);X=`${ie}${be}`,$.current=X,x(X)}const{contentParts:je,filesInfo:Vt}=await yg(l,pe),En=[...je];ve&&En.push({type:"text",text:te});const ir=_==null?void 0:_.originalMessageId,Ar=!!(_!=null&&_.edit&&ir),fo=!Oe&&En.length>0;let zn=null;fo&&(zn={id:Ar?ir:`msg-${Date.now()}`,role:"user",content:En,createdAt:new Date().toISOString()},Ar||L(zn));const ar=Oe?Fe:zn?[zn]:[],E={...we,...Vt.length?{files_info:Vt}:{}};ar.length?E.messages=ar:"messages"in E||(E.messages=[]);const W={threadId:X,payload:E,checkpointId:(_==null?void 0:_.checkpointId)??I.lastCheckpointId??void 0,checkpointNs:(_==null?void 0:_.checkpointNs)??I.lastCheckpointNs??void 0,edit:!!(_!=null&&_.edit),timelineCheckpoints:q};Qe(W)},[l,L,I,Qe,q]),Ge=w.useMemo(()=>({threads:f,currentThreadId:h,setCurrentThreadId:x,isLoading:m,error:g,actions:{createThread:nt,deleteThread:at,renameThread:Rt,refreshThreads:re}}),[f,h,m,g,nt,at,Rt,re]),Ye=w.useMemo(()=>{const G=I.assemblingId??null;return G?{assemblingMessageId:G}:null},[I.assemblingId]),pt=w.useMemo(()=>({threadId:h,messages:I.messages,interrupt:null,checkpoint:{id:I.lastCheckpointId??null,namespace:I.lastCheckpointNs??null},checkpoints:z,timelineCheckpoints:q,metadata:Ye,isLoading:S,isHistoryLoading:N,isLoadingCheckpoint:se,error:C,hasMore:D,loadOlder:Mt,clearState:et,navigateToCheckpoint:bt,setCurrentCheckpointId:St,returnToLatest:Lt,loadThread:ht,clearThread:et,respondToInterrupt:It,messagePreviews:Y}),[h,I,z,q,S,N,se,C,D,Mt,et,bt,St,Lt,ht,It,Y,Ye]),lt=w.useMemo(()=>({isStreaming:tt,error:it,connectionState:tt?"connected":"idle",submit:bn,send:bn,stop:Ve,setAuthToken:qe}),[tt,it,bn,Ve,qe]);return u.jsx(oc.Provider,{value:Ge,children:u.jsx(sc.Provider,{value:pt,children:u.jsx(ic.Provider,{value:lt,children:e})})})}function _o(){const e=w.useContext(oc);if(!e)throw new Error("useThreads must be used within ChatSessionProvider");return e}function jo(){const e=w.useContext(sc);if(!e)throw new Error("useThreadState must be used within ChatSessionProvider");return e}function ac(){const e=w.useContext(ic);if(!e)throw new Error("useStream must be used within ChatSessionProvider");return e}function Ro({children:e,apiConfig:t,initialThreadId:n=null,initialCheckpointId:r=null,initialCheckpointNs:o=null,autoLoadInitial:s=!0,onError:i,onAuthError:a,onThreadChange:l}){return u.jsx(gg,{apiConfig:t,children:u.jsx(Qg,{initialThreadId:n,initialCheckpointId:r,initialCheckpointNs:o,autoLoadInitial:s,onError:i,onAuthError:a,onThreadChange:l,children:e})})}function ne(...e){return Hh.twMerge(Uh.clsx(e))}const ex=po.cva("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-10 w-10"}},defaultVariants:{variant:"default",size:"default"}}),Xe=v.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?Hn.Slot:"button";return u.jsx(i,{className:ne(ex({variant:t,size:n,className:e})),ref:s,...o})});Xe.displayName="Button";const lc=v.forwardRef(({className:e,...t},n)=>u.jsx("textarea",{className:ne("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",e),ref:n,...t}));lc.displayName="Textarea";function cc({initialValue:e="",editingMessageId:t=null,placeholder:n="Type your message...",isStreaming:r=!1,disabled:o=!1,maxLength:s=2e4,value:i,onValueChange:a,onSend:l,onCancelEdit:c,onStop:d,className:f="",textareaClassName:p="",allowEmptySend:h=!1}){const x=i!==void 0,[m,y]=w.useState(e),g=(x?i:m)??"",[b,S]=w.useTransition(),k=w.useRef(null),C=w.useRef(0),T=w.useRef(null);w.useEffect(()=>{x||(y(e??""),T.current=null,k.current&&(k.current.style.height="auto",k.current.style.height=`${k.current.scrollHeight}px`))},[e,t,x]);const I=w.useCallback(()=>{const B=k.current;B&&(B.style.height="auto",B.style.height=`${B.scrollHeight}px`)},[]);w.useEffect(()=>{I()},[I,g]);const A=w.useCallback((B,{fromUser:j})=>{x||y(B),j&&(a==null||a(B))},[x,a]),R=w.useCallback(async B=>{B&&B.preventDefault();const j=(g??"").trim();if(!j&&!h)return;const V=++C.current;T.current={id:V,shouldClear:!0},S(()=>{var z,M,q;try{const J=l(j);J&&typeof J.then=="function"?J.then(()=>{var se,ge;((se=T.current)==null?void 0:se.id)===V&&T.current.shouldClear&&(x||(y(""),k.current&&(k.current.style.height="auto"),a==null||a(""))),((ge=T.current)==null?void 0:ge.id)===V&&(T.current=null)}).catch(()=>{var se;((se=T.current)==null?void 0:se.id)===V&&(T.current=null)}):(((z=T.current)==null?void 0:z.id)===V&&T.current.shouldClear&&(x||(y(""),k.current&&(k.current.style.height="auto"),a==null||a(""))),((M=T.current)==null?void 0:M.id)===V&&(T.current=null))}catch{((q=T.current)==null?void 0:q.id)===V&&(T.current=null)}})},[g,l,h,x,a]),L=w.useCallback(B=>{const j=B.target.value;A(j,{fromUser:!0}),T.current&&(T.current.shouldClear=!1),k.current&&(k.current.style.height="auto",k.current.style.height=`${k.current.scrollHeight}px`)},[A]),P=w.useCallback(B=>{B.key==="Enter"&&!B.shiftKey?(B.preventDefault(),R()):B.key==="Escape"&&t&&(B.preventDefault(),c==null||c())},[R,t,c]),N=`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${t?"border-[hsl(var(--ring))] bg-[hsl(var(--card))] text-[hsl(var(--card-foreground))] dark:bg-[hsl(var(--card))] dark:text-[hsl(var(--card-foreground))]":""} ${p}`;return u.jsx("form",{onSubmit:B=>void R(B),className:`w-full ${f}`,children:u.jsxs("div",{className:"flex items-end gap-2",children:[u.jsx("div",{className:"flex-1",children:u.jsx(lc,{ref:k,value:g,onChange:L,onKeyDown:P,placeholder:t?"Edit your message...":n,className:N,disabled:o,maxLength:s,rows:1,spellCheck:!1,autoCorrect:"off"})}),u.jsx("div",{children:r?u.jsx(Xe,{type:"button",onClick:()=>{d==null||d()},size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",disabled:o||!d,children:u.jsx(ae.Square,{size:16})}):u.jsx(Xe,{type:"submit",size:"icon",className:"shrink-0",title:t?"Save changes":"Send message",disabled:o||!g.trim()&&!h||b,children:u.jsx(ae.Send,{size:16})})})]})})}const tx=w.memo(cc);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 uc(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=uc(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():uc(e[o],null)}}}}function Be(...e){return v.useCallback(gi(...e),e)}function nx(e,t){const n=v.createContext(t),r=s=>{const{children:i,...a}=s,l=v.useMemo(()=>a,Object.values(a));return u.jsx(n.Provider,{value:l,children:i})};r.displayName=e+"Provider";function o(s){const i=v.useContext(n);if(i)return i;if(t!==void 0)return t;throw new Error(`\`${s}\` must be used within \`${e}\``)}return[r,o]}function Sn(e,t=[]){let n=[];function r(s,i){const a=v.createContext(i),l=n.length;n=[...n,i];const c=f=>{var g;const{scope:p,children:h,...x}=f,m=((g=p==null?void 0:p[e])==null?void 0:g[l])||a,y=v.useMemo(()=>x,Object.values(x));return u.jsx(m.Provider,{value:y,children:h})};c.displayName=s+"Provider";function d(f,p){var m;const h=((m=p==null?void 0:p[e])==null?void 0:m[l])||a,x=v.useContext(h);if(x)return x;if(i!==void 0)return i;throw new Error(`\`${f}\` must be used within \`${s}\``)}return[c,d]}const o=()=>{const s=n.map(i=>v.createContext(i));return function(a){const l=(a==null?void 0:a[e])||s;return v.useMemo(()=>({[`__scope${e}`]:{...a,[e]:l}}),[a,l])}};return o.scopeName=e,[r,rx(o,...t)]}function rx(...e){const t=e[0];if(e.length===1)return t;const n=()=>{const r=e.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(s){const i=r.reduce((a,{useScope:l,scopeName:c})=>{const f=l(s)[`__scope${c}`];return{...a,...f}},{});return v.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}var Tt=globalThis!=null&&globalThis.document?v.useLayoutEffect:()=>{},ox=v[" useInsertionEffect ".trim().toString()]||Tt;function pr({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=sx({defaultProp:t,onChange:n}),a=e!==void 0,l=a?e:o;{const d=v.useRef(e!==void 0);v.useEffect(()=>{const f=d.current;f!==a&&console.warn(`${r} is changing from ${f?"controlled":"uncontrolled"} to ${a?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),d.current=a},[a,r])}const c=v.useCallback(d=>{var f;if(a){const p=ix(d)?d(e):d;p!==e&&((f=i.current)==null||f.call(i,p))}else s(d)},[a,e,s,i]);return[l,c]}function sx({defaultProp:e,onChange:t}){const[n,r]=v.useState(e),o=v.useRef(n),s=v.useRef(t);return ox(()=>{s.current=t},[t]),v.useEffect(()=>{var i;o.current!==n&&((i=s.current)==null||i.call(s,n),o.current=n)},[n,o]),[n,r,s]}function ix(e){return typeof e=="function"}var ax=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],_e=ax.reduce((e,t)=>{const n=Hn.createSlot(`Primitive.${t}`),r=v.forwardRef((o,s)=>{const{asChild:i,...a}=o,l=i?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),u.jsx(l,{...a,ref:s})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function dc(e,t){e&&ho.flushSync(()=>e.dispatchEvent(t))}function xi(e){const t=e+"CollectionProvider",[n,r]=Sn(t),[o,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),i=m=>{const{scope:y,children:g}=m,b=w.useRef(null),S=w.useRef(new Map).current;return u.jsx(o,{scope:y,itemMap:S,collectionRef:b,children:g})};i.displayName=t;const a=e+"CollectionSlot",l=Hn.createSlot(a),c=w.forwardRef((m,y)=>{const{scope:g,children:b}=m,S=s(a,g),k=Be(y,S.collectionRef);return u.jsx(l,{ref:k,children:b})});c.displayName=a;const d=e+"CollectionItemSlot",f="data-radix-collection-item",p=Hn.createSlot(d),h=w.forwardRef((m,y)=>{const{scope:g,children:b,...S}=m,k=w.useRef(null),C=Be(y,k),T=s(d,g);return w.useEffect(()=>(T.itemMap.set(k,{ref:k,...S}),()=>void T.itemMap.delete(k))),u.jsx(p,{[f]:"",ref:C,children:b})});h.displayName=d;function x(m){const y=s(e+"CollectionConsumer",m);return w.useCallback(()=>{const b=y.collectionRef.current;if(!b)return[];const S=Array.from(b.querySelectorAll(`[${f}]`));return Array.from(y.itemMap.values()).sort((T,I)=>S.indexOf(T.ref.current)-S.indexOf(I.ref.current))},[y.collectionRef,y.itemMap])}return[{Provider:i,Slot:c,ItemSlot:h},x,r]}var lx=v.createContext(void 0);function Mo(e){const t=v.useContext(lx);return e||t||"ltr"}function kt(e){const t=v.useRef(e);return v.useEffect(()=>{t.current=e}),v.useMemo(()=>(...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)},[])}function cx(e,t=globalThis==null?void 0:globalThis.document){const n=kt(e);v.useEffect(()=>{const r=o=>{o.key==="Escape"&&n(o)};return t.addEventListener("keydown",r,{capture:!0}),()=>t.removeEventListener("keydown",r,{capture:!0})},[n,t])}var ux="DismissableLayer",yi="dismissableLayer.update",dx="dismissableLayer.pointerDownOutside",fx="dismissableLayer.focusOutside",fc,pc=v.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),Po=v.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:a,...l}=e,c=v.useContext(pc),[d,f]=v.useState(null),p=(d==null?void 0:d.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,h]=v.useState({}),x=Be(t,I=>f(I)),m=Array.from(c.layers),[y]=[...c.layersWithOutsidePointerEventsDisabled].slice(-1),g=m.indexOf(y),b=d?m.indexOf(d):-1,S=c.layersWithOutsidePointerEventsDisabled.size>0,k=b>=g,C=mx(I=>{const A=I.target,R=[...c.branches].some(L=>L.contains(A));!k||R||(o==null||o(I),i==null||i(I),I.defaultPrevented||a==null||a())},p),T=gx(I=>{const A=I.target;[...c.branches].some(L=>L.contains(A))||(s==null||s(I),i==null||i(I),I.defaultPrevented||a==null||a())},p);return cx(I=>{b===c.layers.size-1&&(r==null||r(I),!I.defaultPrevented&&a&&(I.preventDefault(),a()))},p),v.useEffect(()=>{if(d)return n&&(c.layersWithOutsidePointerEventsDisabled.size===0&&(fc=p.body.style.pointerEvents,p.body.style.pointerEvents="none"),c.layersWithOutsidePointerEventsDisabled.add(d)),c.layers.add(d),hc(),()=>{n&&c.layersWithOutsidePointerEventsDisabled.size===1&&(p.body.style.pointerEvents=fc)}},[d,p,n,c]),v.useEffect(()=>()=>{d&&(c.layers.delete(d),c.layersWithOutsidePointerEventsDisabled.delete(d),hc())},[d,c]),v.useEffect(()=>{const I=()=>h({});return document.addEventListener(yi,I),()=>document.removeEventListener(yi,I)},[]),u.jsx(_e.div,{...l,ref:x,style:{pointerEvents:S?k?"auto":"none":void 0,...e.style},onFocusCapture:de(e.onFocusCapture,T.onFocusCapture),onBlurCapture:de(e.onBlurCapture,T.onBlurCapture),onPointerDownCapture:de(e.onPointerDownCapture,C.onPointerDownCapture)})});Po.displayName=ux;var px="DismissableLayerBranch",hx=v.forwardRef((e,t)=>{const n=v.useContext(pc),r=v.useRef(null),o=Be(t,r);return v.useEffect(()=>{const s=r.current;if(s)return n.branches.add(s),()=>{n.branches.delete(s)}},[n.branches]),u.jsx(_e.div,{...e,ref:o})});hx.displayName=px;function mx(e,t=globalThis==null?void 0:globalThis.document){const n=kt(e),r=v.useRef(!1),o=v.useRef(()=>{});return v.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let l=function(){mc(dx,n,c,{discrete:!0})};const c={originalEvent:a};a.pointerType==="touch"?(t.removeEventListener("click",o.current),o.current=l,t.addEventListener("click",o.current,{once:!0})):l()}else t.removeEventListener("click",o.current);r.current=!1},i=window.setTimeout(()=>{t.addEventListener("pointerdown",s)},0);return()=>{window.clearTimeout(i),t.removeEventListener("pointerdown",s),t.removeEventListener("click",o.current)}},[t,n]),{onPointerDownCapture:()=>r.current=!0}}function gx(e,t=globalThis==null?void 0:globalThis.document){const n=kt(e),r=v.useRef(!1);return v.useEffect(()=>{const o=s=>{s.target&&!r.current&&mc(fx,n,{originalEvent:s},{discrete:!1})};return t.addEventListener("focusin",o),()=>t.removeEventListener("focusin",o)},[t,n]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}function hc(){const e=new CustomEvent(yi);document.dispatchEvent(e)}function mc(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?dc(o,s):o.dispatchEvent(s)}var vi=0;function bi(){v.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??gc()),document.body.insertAdjacentElement("beforeend",e[1]??gc()),vi++,()=>{vi===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),vi--}},[])}function gc(){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 wi="focusScope.autoFocusOnMount",Si="focusScope.autoFocusOnUnmount",xc={bubbles:!1,cancelable:!0},xx="FocusScope",Oo=v.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:s,...i}=e,[a,l]=v.useState(null),c=kt(o),d=kt(s),f=v.useRef(null),p=Be(t,m=>l(m)),h=v.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;v.useEffect(()=>{if(r){let m=function(S){if(h.paused||!a)return;const k=S.target;a.contains(k)?f.current=k:Nn(f.current,{select:!0})},y=function(S){if(h.paused||!a)return;const k=S.relatedTarget;k!==null&&(a.contains(k)||Nn(f.current,{select:!0}))},g=function(S){if(document.activeElement===document.body)for(const C of S)C.removedNodes.length>0&&Nn(a)};document.addEventListener("focusin",m),document.addEventListener("focusout",y);const b=new MutationObserver(g);return a&&b.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",m),document.removeEventListener("focusout",y),b.disconnect()}}},[r,a,h.paused]),v.useEffect(()=>{if(a){bc.add(h);const m=document.activeElement;if(!a.contains(m)){const g=new CustomEvent(wi,xc);a.addEventListener(wi,c),a.dispatchEvent(g),g.defaultPrevented||(yx(Cx(yc(a)),{select:!0}),document.activeElement===m&&Nn(a))}return()=>{a.removeEventListener(wi,c),setTimeout(()=>{const g=new CustomEvent(Si,xc);a.addEventListener(Si,d),a.dispatchEvent(g),g.defaultPrevented||Nn(m??document.body,{select:!0}),a.removeEventListener(Si,d),bc.remove(h)},0)}}},[a,c,d,h]);const x=v.useCallback(m=>{if(!n&&!r||h.paused)return;const y=m.key==="Tab"&&!m.altKey&&!m.ctrlKey&&!m.metaKey,g=document.activeElement;if(y&&g){const b=m.currentTarget,[S,k]=vx(b);S&&k?!m.shiftKey&&g===k?(m.preventDefault(),n&&Nn(S,{select:!0})):m.shiftKey&&g===S&&(m.preventDefault(),n&&Nn(k,{select:!0})):g===b&&m.preventDefault()}},[n,r,h.paused]);return u.jsx(_e.div,{tabIndex:-1,...i,ref:p,onKeyDown:x})});Oo.displayName=xx;function yx(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(Nn(r,{select:t}),document.activeElement!==n)return}function vx(e){const t=yc(e),n=vc(t,e),r=vc(t.reverse(),e);return[n,r]}function yc(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 vc(e,t){for(const n of e)if(!bx(n,{upTo:t}))return n}function bx(e,{upTo:t}){if(getComputedStyle(e).visibility==="hidden")return!0;for(;e;){if(t!==void 0&&e===t)return!1;if(getComputedStyle(e).display==="none")return!0;e=e.parentElement}return!1}function wx(e){return e instanceof HTMLInputElement&&"select"in e}function Nn(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&wx(e)&&t&&e.select()}}var bc=Sx();function Sx(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=wc(e,t),e.unshift(t)},remove(t){var n;e=wc(e,t),(n=e[0])==null||n.resume()}}}function wc(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function Cx(e){return e.filter(t=>t.tagName!=="A")}var Tx=v[" useId ".trim().toString()]||(()=>{}),kx=0;function Cn(e){const[t,n]=v.useState(Tx());return Tt(()=>{n(r=>r??String(kx++))},[e]),t?`radix-${t}`:""}const Ix=["top","right","bottom","left"],_n=Math.min,zt=Math.max,Do=Math.round,Lo=Math.floor,dn=e=>({x:e,y:e}),Ex={left:"right",right:"left",bottom:"top",top:"bottom"},Ax={start:"end",end:"start"};function Ci(e,t,n){return zt(e,_n(t,n))}function Tn(e,t){return typeof e=="function"?e(t):e}function kn(e){return e.split("-")[0]}function hr(e){return e.split("-")[1]}function Ti(e){return e==="x"?"y":"x"}function ki(e){return e==="y"?"height":"width"}const Nx=new Set(["top","bottom"]);function fn(e){return Nx.has(kn(e))?"y":"x"}function Ii(e){return Ti(fn(e))}function _x(e,t,n){n===void 0&&(n=!1);const r=hr(e),o=Ii(e),s=ki(o);let i=o==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(i=$o(i)),[i,$o(i)]}function jx(e){const t=$o(e);return[Ei(e),t,Ei(t)]}function Ei(e){return e.replace(/start|end/g,t=>Ax[t])}const Sc=["left","right"],Cc=["right","left"],Rx=["top","bottom"],Mx=["bottom","top"];function Px(e,t,n){switch(e){case"top":case"bottom":return n?t?Cc:Sc:t?Sc:Cc;case"left":case"right":return t?Rx:Mx;default:return[]}}function Ox(e,t,n,r){const o=hr(e);let s=Px(kn(e),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(Ei)))),s}function $o(e){return e.replace(/left|right|bottom|top/g,t=>Ex[t])}function Dx(e){return{top:0,right:0,bottom:0,left:0,...e}}function Tc(e){return typeof e!="number"?Dx(e):{top:e,right:e,bottom:e,left:e}}function Fo(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 kc(e,t,n){let{reference:r,floating:o}=e;const s=fn(t),i=Ii(t),a=ki(i),l=kn(t),c=s==="y",d=r.x+r.width/2-o.width/2,f=r.y+r.height/2-o.height/2,p=r[a]/2-o[a]/2;let h;switch(l){case"top":h={x:d,y:r.y-o.height};break;case"bottom":h={x:d,y:r.y+r.height};break;case"right":h={x:r.x+r.width,y:f};break;case"left":h={x:r.x-o.width,y:f};break;default:h={x:r.x,y:r.y}}switch(hr(t)){case"start":h[i]-=p*(n&&c?-1:1);break;case"end":h[i]+=p*(n&&c?-1:1);break}return h}const Lx=async(e,t,n)=>{const{placement:r="bottom",strategy:o="absolute",middleware:s=[],platform:i}=n,a=s.filter(Boolean),l=await(i.isRTL==null?void 0:i.isRTL(t));let c=await i.getElementRects({reference:e,floating:t,strategy:o}),{x:d,y:f}=kc(c,r,l),p=r,h={},x=0;for(let m=0;m<a.length;m++){const{name:y,fn:g}=a[m],{x:b,y:S,data:k,reset:C}=await g({x:d,y:f,initialPlacement:r,placement:p,strategy:o,middlewareData:h,rects:c,platform:i,elements:{reference:e,floating:t}});d=b??d,f=S??f,h={...h,[y]:{...h[y],...k}},C&&x<=50&&(x++,typeof C=="object"&&(C.placement&&(p=C.placement),C.rects&&(c=C.rects===!0?await i.getElementRects({reference:e,floating:t,strategy:o}):C.rects),{x:d,y:f}=kc(c,p,l)),m=-1)}return{x:d,y:f,placement:p,strategy:o,middlewareData:h}};async function Lr(e,t){var n;t===void 0&&(t={});const{x:r,y:o,platform:s,rects:i,elements:a,strategy:l}=e,{boundary:c="clippingAncestors",rootBoundary:d="viewport",elementContext:f="floating",altBoundary:p=!1,padding:h=0}=Tn(t,e),x=Tc(h),y=a[p?f==="floating"?"reference":"floating":f],g=Fo(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(y)))==null||n?y:y.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(a.floating)),boundary:c,rootBoundary:d,strategy:l})),b=f==="floating"?{x:r,y:o,width:i.floating.width,height:i.floating.height}:i.reference,S=await(s.getOffsetParent==null?void 0:s.getOffsetParent(a.floating)),k=await(s.isElement==null?void 0:s.isElement(S))?await(s.getScale==null?void 0:s.getScale(S))||{x:1,y:1}:{x:1,y:1},C=Fo(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:b,offsetParent:S,strategy:l}):b);return{top:(g.top-C.top+x.top)/k.y,bottom:(C.bottom-g.bottom+x.bottom)/k.y,left:(g.left-C.left+x.left)/k.x,right:(C.right-g.right+x.right)/k.x}}const $x=e=>({name:"arrow",options:e,async fn(t){const{x:n,y:r,placement:o,rects:s,platform:i,elements:a,middlewareData:l}=t,{element:c,padding:d=0}=Tn(e,t)||{};if(c==null)return{};const f=Tc(d),p={x:n,y:r},h=Ii(o),x=ki(h),m=await i.getDimensions(c),y=h==="y",g=y?"top":"left",b=y?"bottom":"right",S=y?"clientHeight":"clientWidth",k=s.reference[x]+s.reference[h]-p[h]-s.floating[x],C=p[h]-s.reference[h],T=await(i.getOffsetParent==null?void 0:i.getOffsetParent(c));let I=T?T[S]:0;(!I||!await(i.isElement==null?void 0:i.isElement(T)))&&(I=a.floating[S]||s.floating[x]);const A=k/2-C/2,R=I/2-m[x]/2-1,L=_n(f[g],R),P=_n(f[b],R),D=L,F=I-m[x]-P,N=I/2-m[x]/2+A,B=Ci(D,N,F),j=!l.arrow&&hr(o)!=null&&N!==B&&s.reference[x]/2-(N<D?L:P)-m[x]/2<0,V=j?N<D?N-D:N-F:0;return{[h]:p[h]+V,data:{[h]:B,centerOffset:N-B-V,...j&&{alignmentOffset:V}},reset:j}}}),Fx=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(t){var n,r;const{placement:o,middlewareData:s,rects:i,initialPlacement:a,platform:l,elements:c}=t,{mainAxis:d=!0,crossAxis:f=!0,fallbackPlacements:p,fallbackStrategy:h="bestFit",fallbackAxisSideDirection:x="none",flipAlignment:m=!0,...y}=Tn(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const g=kn(o),b=fn(a),S=kn(a)===a,k=await(l.isRTL==null?void 0:l.isRTL(c.floating)),C=p||(S||!m?[$o(a)]:jx(a)),T=x!=="none";!p&&T&&C.push(...Ox(a,m,x,k));const I=[a,...C],A=await Lr(t,y),R=[];let L=((r=s.flip)==null?void 0:r.overflows)||[];if(d&&R.push(A[g]),f){const N=_x(o,i,k);R.push(A[N[0]],A[N[1]])}if(L=[...L,{placement:o,overflows:R}],!R.every(N=>N<=0)){var P,D;const N=(((P=s.flip)==null?void 0:P.index)||0)+1,B=I[N];if(B&&(!(f==="alignment"?b!==fn(B):!1)||L.every(z=>fn(z.placement)===b?z.overflows[0]>0:!0)))return{data:{index:N,overflows:L},reset:{placement:B}};let j=(D=L.filter(V=>V.overflows[0]<=0).sort((V,z)=>V.overflows[1]-z.overflows[1])[0])==null?void 0:D.placement;if(!j)switch(h){case"bestFit":{var F;const V=(F=L.filter(z=>{if(T){const M=fn(z.placement);return M===b||M==="y"}return!0}).map(z=>[z.placement,z.overflows.filter(M=>M>0).reduce((M,q)=>M+q,0)]).sort((z,M)=>z[1]-M[1])[0])==null?void 0:F[0];V&&(j=V);break}case"initialPlacement":j=a;break}if(o!==j)return{reset:{placement:j}}}return{}}}};function Ic(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function Ec(e){return Ix.some(t=>e[t]>=0)}const Bx=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n}=t,{strategy:r="referenceHidden",...o}=Tn(e,t);switch(r){case"referenceHidden":{const s=await Lr(t,{...o,elementContext:"reference"}),i=Ic(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:Ec(i)}}}case"escaped":{const s=await Lr(t,{...o,altBoundary:!0}),i=Ic(s,n.floating);return{data:{escapedOffsets:i,escaped:Ec(i)}}}default:return{}}}}},Ac=new Set(["left","top"]);async function zx(e,t){const{placement:n,platform:r,elements:o}=e,s=await(r.isRTL==null?void 0:r.isRTL(o.floating)),i=kn(n),a=hr(n),l=fn(n)==="y",c=Ac.has(i)?-1:1,d=s&&l?-1:1,f=Tn(t,e);let{mainAxis:p,crossAxis:h,alignmentAxis:x}=typeof f=="number"?{mainAxis:f,crossAxis:0,alignmentAxis:null}:{mainAxis:f.mainAxis||0,crossAxis:f.crossAxis||0,alignmentAxis:f.alignmentAxis};return a&&typeof x=="number"&&(h=a==="end"?x*-1:x),l?{x:h*d,y:p*c}:{x:p*c,y:h*d}}const Ux=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 zx(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}}}}},Hx=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(t){const{x:n,y:r,placement:o}=t,{mainAxis:s=!0,crossAxis:i=!1,limiter:a={fn:y=>{let{x:g,y:b}=y;return{x:g,y:b}}},...l}=Tn(e,t),c={x:n,y:r},d=await Lr(t,l),f=fn(kn(o)),p=Ti(f);let h=c[p],x=c[f];if(s){const y=p==="y"?"top":"left",g=p==="y"?"bottom":"right",b=h+d[y],S=h-d[g];h=Ci(b,h,S)}if(i){const y=f==="y"?"top":"left",g=f==="y"?"bottom":"right",b=x+d[y],S=x-d[g];x=Ci(b,x,S)}const m=a.fn({...t,[p]:h,[f]:x});return{...m,data:{x:m.x-n,y:m.y-r,enabled:{[p]:s,[f]:i}}}}}},Wx=function(e){return e===void 0&&(e={}),{options:e,fn(t){const{x:n,y:r,placement:o,rects:s,middlewareData:i}=t,{offset:a=0,mainAxis:l=!0,crossAxis:c=!0}=Tn(e,t),d={x:n,y:r},f=fn(o),p=Ti(f);let h=d[p],x=d[f];const m=Tn(a,t),y=typeof m=="number"?{mainAxis:m,crossAxis:0}:{mainAxis:0,crossAxis:0,...m};if(l){const S=p==="y"?"height":"width",k=s.reference[p]-s.floating[S]+y.mainAxis,C=s.reference[p]+s.reference[S]-y.mainAxis;h<k?h=k:h>C&&(h=C)}if(c){var g,b;const S=p==="y"?"width":"height",k=Ac.has(kn(o)),C=s.reference[f]-s.floating[S]+(k&&((g=i.offset)==null?void 0:g[f])||0)+(k?0:y.crossAxis),T=s.reference[f]+s.reference[S]+(k?0:((b=i.offset)==null?void 0:b[f])||0)-(k?y.crossAxis:0);x<C?x=C:x>T&&(x=T)}return{[p]:h,[f]:x}}}},Vx=function(e){return e===void 0&&(e={}),{name:"size",options:e,async fn(t){var n,r;const{placement:o,rects:s,platform:i,elements:a}=t,{apply:l=()=>{},...c}=Tn(e,t),d=await Lr(t,c),f=kn(o),p=hr(o),h=fn(o)==="y",{width:x,height:m}=s.floating;let y,g;f==="top"||f==="bottom"?(y=f,g=p===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(g=f,y=p==="end"?"top":"bottom");const b=m-d.top-d.bottom,S=x-d.left-d.right,k=_n(m-d[y],b),C=_n(x-d[g],S),T=!t.middlewareData.shift;let I=k,A=C;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(A=S),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(I=b),T&&!p){const L=zt(d.left,0),P=zt(d.right,0),D=zt(d.top,0),F=zt(d.bottom,0);h?A=x-2*(L!==0||P!==0?L+P:zt(d.left,d.right)):I=m-2*(D!==0||F!==0?D+F:zt(d.top,d.bottom))}await l({...t,availableWidth:A,availableHeight:I});const R=await i.getDimensions(a.floating);return x!==R.width||m!==R.height?{reset:{rects:!0}}:{}}}};function Bo(){return typeof window<"u"}function mr(e){return Nc(e)?(e.nodeName||"").toLowerCase():"#document"}function Ut(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function pn(e){var t;return(t=(Nc(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function Nc(e){return Bo()?e instanceof Node||e instanceof Ut(e).Node:!1}function rn(e){return Bo()?e instanceof Element||e instanceof Ut(e).Element:!1}function hn(e){return Bo()?e instanceof HTMLElement||e instanceof Ut(e).HTMLElement:!1}function _c(e){return!Bo()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Ut(e).ShadowRoot}const Kx=new Set(["inline","contents"]);function $r(e){const{overflow:t,overflowX:n,overflowY:r,display:o}=on(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!Kx.has(o)}const qx=new Set(["table","td","th"]);function Gx(e){return qx.has(mr(e))}const Yx=[":popover-open",":modal"];function zo(e){return Yx.some(t=>{try{return e.matches(t)}catch{return!1}})}const Xx=["transform","translate","scale","rotate","perspective"],Jx=["transform","translate","scale","rotate","perspective","filter"],Zx=["paint","layout","strict","content"];function Ai(e){const t=Ni(),n=rn(e)?on(e):e;return Xx.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)||Jx.some(r=>(n.willChange||"").includes(r))||Zx.some(r=>(n.contain||"").includes(r))}function Qx(e){let t=jn(e);for(;hn(t)&&!gr(t);){if(Ai(t))return t;if(zo(t))return null;t=jn(t)}return null}function Ni(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const ey=new Set(["html","body","#document"]);function gr(e){return ey.has(mr(e))}function on(e){return Ut(e).getComputedStyle(e)}function Uo(e){return rn(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function jn(e){if(mr(e)==="html")return e;const t=e.assignedSlot||e.parentNode||_c(e)&&e.host||pn(e);return _c(t)?t.host:t}function jc(e){const t=jn(e);return gr(t)?e.ownerDocument?e.ownerDocument.body:e.body:hn(t)&&$r(t)?t:jc(t)}function Fr(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const o=jc(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=Ut(o);if(s){const a=_i(i);return t.concat(i,i.visualViewport||[],$r(o)?o:[],a&&n?Fr(a):[])}return t.concat(o,Fr(o,[],n))}function _i(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function Rc(e){const t=on(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const o=hn(e),s=o?e.offsetWidth:n,i=o?e.offsetHeight:r,a=Do(n)!==s||Do(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function ji(e){return rn(e)?e:e.contextElement}function xr(e){const t=ji(e);if(!hn(t))return dn(1);const n=t.getBoundingClientRect(),{width:r,height:o,$:s}=Rc(t);let i=(s?Do(n.width):n.width)/r,a=(s?Do(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const ty=dn(0);function Mc(e){const t=Ut(e);return!Ni()||!t.visualViewport?ty:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function ny(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==Ut(e)?!1:t}function qn(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const o=e.getBoundingClientRect(),s=ji(e);let i=dn(1);t&&(r?rn(r)&&(i=xr(r)):i=xr(e));const a=ny(s,n,r)?Mc(s):dn(0);let l=(o.left+a.x)/i.x,c=(o.top+a.y)/i.y,d=o.width/i.x,f=o.height/i.y;if(s){const p=Ut(s),h=r&&rn(r)?Ut(r):r;let x=p,m=_i(x);for(;m&&r&&h!==x;){const y=xr(m),g=m.getBoundingClientRect(),b=on(m),S=g.left+(m.clientLeft+parseFloat(b.paddingLeft))*y.x,k=g.top+(m.clientTop+parseFloat(b.paddingTop))*y.y;l*=y.x,c*=y.y,d*=y.x,f*=y.y,l+=S,c+=k,x=Ut(m),m=_i(x)}}return Fo({width:d,height:f,x:l,y:c})}function Ho(e,t){const n=Uo(e).scrollLeft;return t?t.left+n:qn(pn(e)).left+n}function Pc(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-Ho(e,n),o=n.top+t.scrollTop;return{x:r,y:o}}function ry(e){let{elements:t,rect:n,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=pn(r),a=t?zo(t.floating):!1;if(r===i||a&&s)return n;let l={scrollLeft:0,scrollTop:0},c=dn(1);const d=dn(0),f=hn(r);if((f||!f&&!s)&&((mr(r)!=="body"||$r(i))&&(l=Uo(r)),hn(r))){const h=qn(r);c=xr(r),d.x=h.x+r.clientLeft,d.y=h.y+r.clientTop}const p=i&&!f&&!s?Pc(i,l):dn(0);return{width:n.width*c.x,height:n.height*c.y,x:n.x*c.x-l.scrollLeft*c.x+d.x+p.x,y:n.y*c.y-l.scrollTop*c.y+d.y+p.y}}function oy(e){return Array.from(e.getClientRects())}function sy(e){const t=pn(e),n=Uo(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+Ho(e);const a=-n.scrollTop;return on(r).direction==="rtl"&&(i+=zt(t.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}const Oc=25;function iy(e,t){const n=Ut(e),r=pn(e),o=n.visualViewport;let s=r.clientWidth,i=r.clientHeight,a=0,l=0;if(o){s=o.width,i=o.height;const d=Ni();(!d||d&&t==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}const c=Ho(r);if(c<=0){const d=r.ownerDocument,f=d.body,p=getComputedStyle(f),h=d.compatMode==="CSS1Compat"&&parseFloat(p.marginLeft)+parseFloat(p.marginRight)||0,x=Math.abs(r.clientWidth-f.clientWidth-h);x<=Oc&&(s-=x)}else c<=Oc&&(s+=c);return{width:s,height:i,x:a,y:l}}const ay=new Set(["absolute","fixed"]);function ly(e,t){const n=qn(e,!0,t==="fixed"),r=n.top+e.clientTop,o=n.left+e.clientLeft,s=hn(e)?xr(e):dn(1),i=e.clientWidth*s.x,a=e.clientHeight*s.y,l=o*s.x,c=r*s.y;return{width:i,height:a,x:l,y:c}}function Dc(e,t,n){let r;if(t==="viewport")r=iy(e,n);else if(t==="document")r=sy(pn(e));else if(rn(t))r=ly(t,n);else{const o=Mc(e);r={x:t.x-o.x,y:t.y-o.y,width:t.width,height:t.height}}return Fo(r)}function Lc(e,t){const n=jn(e);return n===t||!rn(n)||gr(n)?!1:on(n).position==="fixed"||Lc(n,t)}function cy(e,t){const n=t.get(e);if(n)return n;let r=Fr(e,[],!1).filter(a=>rn(a)&&mr(a)!=="body"),o=null;const s=on(e).position==="fixed";let i=s?jn(e):e;for(;rn(i)&&!gr(i);){const a=on(i),l=Ai(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&ay.has(o.position)||$r(i)&&!l&&Lc(e,i))?r=r.filter(d=>d!==i):o=a,i=jn(i)}return t.set(e,r),r}function uy(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i=[...n==="clippingAncestors"?zo(t)?[]:cy(t,this._c):[].concat(n),r],a=i[0],l=i.reduce((c,d)=>{const f=Dc(t,d,o);return c.top=zt(f.top,c.top),c.right=_n(f.right,c.right),c.bottom=_n(f.bottom,c.bottom),c.left=zt(f.left,c.left),c},Dc(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}=Rc(e);return{width:t,height:n}}function fy(e,t,n){const r=hn(t),o=pn(t),s=n==="fixed",i=qn(e,!0,s,t);let a={scrollLeft:0,scrollTop:0};const l=dn(0);function c(){l.x=Ho(o)}if(r||!r&&!s)if((mr(t)!=="body"||$r(o))&&(a=Uo(t)),r){const h=qn(t,!0,s,t);l.x=h.x+t.clientLeft,l.y=h.y+t.clientTop}else o&&c();s&&!r&&o&&c();const d=o&&!r&&!s?Pc(o,a):dn(0),f=i.left+a.scrollLeft-l.x-d.x,p=i.top+a.scrollTop-l.y-d.y;return{x:f,y:p,width:i.width,height:i.height}}function Ri(e){return on(e).position==="static"}function $c(e,t){if(!hn(e)||on(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return pn(e)===n&&(n=n.ownerDocument.body),n}function Fc(e,t){const n=Ut(e);if(zo(e))return n;if(!hn(e)){let o=jn(e);for(;o&&!gr(o);){if(rn(o)&&!Ri(o))return o;o=jn(o)}return n}let r=$c(e,t);for(;r&&Gx(r)&&Ri(r);)r=$c(r,t);return r&&gr(r)&&Ri(r)&&!Ai(r)?n:r||Qx(e)||n}const py=async function(e){const t=this.getOffsetParent||Fc,n=this.getDimensions,r=await n(e.floating);return{reference:fy(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function hy(e){return on(e).direction==="rtl"}const my={convertOffsetParentRelativeRectToViewportRelativeRect:ry,getDocumentElement:pn,getClippingRect:uy,getOffsetParent:Fc,getElementRects:py,getClientRects:oy,getDimensions:dy,getScale:xr,isElement:rn,isRTL:hy};function Bc(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function gy(e,t){let n=null,r;const o=pn(e);function s(){var a;clearTimeout(r),(a=n)==null||a.disconnect(),n=null}function i(a,l){a===void 0&&(a=!1),l===void 0&&(l=1),s();const c=e.getBoundingClientRect(),{left:d,top:f,width:p,height:h}=c;if(a||t(),!p||!h)return;const x=Lo(f),m=Lo(o.clientWidth-(d+p)),y=Lo(o.clientHeight-(f+h)),g=Lo(d),S={rootMargin:-x+"px "+-m+"px "+-y+"px "+-g+"px",threshold:zt(0,_n(1,l))||1};let k=!0;function C(T){const I=T[0].intersectionRatio;if(I!==l){if(!k)return i();I?i(!1,I):r=setTimeout(()=>{i(!1,1e-7)},1e3)}I===1&&!Bc(c,e.getBoundingClientRect())&&i(),k=!1}try{n=new IntersectionObserver(C,{...S,root:o.ownerDocument})}catch{n=new IntersectionObserver(C,S)}n.observe(e)}return i(!0),s}function xy(e,t,n,r){r===void 0&&(r={});const{ancestorScroll:o=!0,ancestorResize:s=!0,elementResize:i=typeof ResizeObserver=="function",layoutShift:a=typeof IntersectionObserver=="function",animationFrame:l=!1}=r,c=ji(e),d=o||s?[...c?Fr(c):[],...Fr(t)]:[];d.forEach(g=>{o&&g.addEventListener("scroll",n,{passive:!0}),s&&g.addEventListener("resize",n)});const f=c&&a?gy(c,n):null;let p=-1,h=null;i&&(h=new ResizeObserver(g=>{let[b]=g;b&&b.target===c&&h&&(h.unobserve(t),cancelAnimationFrame(p),p=requestAnimationFrame(()=>{var S;(S=h)==null||S.observe(t)})),n()}),c&&!l&&h.observe(c),h.observe(t));let x,m=l?qn(e):null;l&&y();function y(){const g=qn(e);m&&!Bc(m,g)&&n(),m=g,x=requestAnimationFrame(y)}return n(),()=>{var g;d.forEach(b=>{o&&b.removeEventListener("scroll",n),s&&b.removeEventListener("resize",n)}),f==null||f(),(g=h)==null||g.disconnect(),h=null,l&&cancelAnimationFrame(x)}}const yy=Ux,vy=Hx,by=Fx,wy=Vx,Sy=Bx,zc=$x,Cy=Wx,Ty=(e,t,n)=>{const r=new Map,o={platform:my,...n},s={...o.platform,_c:r};return Lx(e,t,{...o,platform:s})};var ky=typeof document<"u",Iy=function(){},Wo=ky?w.useLayoutEffect:Iy;function Vo(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(!Vo(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)&&!Vo(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function Uc(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function Hc(e,t){const n=Uc(e);return Math.round(t*n)/n}function Mi(e){const t=v.useRef(e);return Wo(()=>{t.current=e}),t}function Ey(e){e===void 0&&(e={});const{placement:t="bottom",strategy:n="absolute",middleware:r=[],platform:o,elements:{reference:s,floating:i}={},transform:a=!0,whileElementsMounted:l,open:c}=e,[d,f]=v.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[p,h]=v.useState(r);Vo(p,r)||h(r);const[x,m]=v.useState(null),[y,g]=v.useState(null),b=v.useCallback(z=>{z!==T.current&&(T.current=z,m(z))},[]),S=v.useCallback(z=>{z!==I.current&&(I.current=z,g(z))},[]),k=s||x,C=i||y,T=v.useRef(null),I=v.useRef(null),A=v.useRef(d),R=l!=null,L=Mi(l),P=Mi(o),D=Mi(c),F=v.useCallback(()=>{if(!T.current||!I.current)return;const z={placement:t,strategy:n,middleware:p};P.current&&(z.platform=P.current),Ty(T.current,I.current,z).then(M=>{const q={...M,isPositioned:D.current!==!1};N.current&&!Vo(A.current,q)&&(A.current=q,ho.flushSync(()=>{f(q)}))})},[p,t,n,P,D]);Wo(()=>{c===!1&&A.current.isPositioned&&(A.current.isPositioned=!1,f(z=>({...z,isPositioned:!1})))},[c]);const N=v.useRef(!1);Wo(()=>(N.current=!0,()=>{N.current=!1}),[]),Wo(()=>{if(k&&(T.current=k),C&&(I.current=C),k&&C){if(L.current)return L.current(k,C,F);F()}},[k,C,F,L,R]);const B=v.useMemo(()=>({reference:T,floating:I,setReference:b,setFloating:S}),[b,S]),j=v.useMemo(()=>({reference:k,floating:C}),[k,C]),V=v.useMemo(()=>{const z={position:n,left:0,top:0};if(!j.floating)return z;const M=Hc(j.floating,d.x),q=Hc(j.floating,d.y);return a?{...z,transform:"translate("+M+"px, "+q+"px)",...Uc(j.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:M,top:q}},[n,a,j.floating,d.x,d.y]);return v.useMemo(()=>({...d,update:F,refs:B,elements:j,floatingStyles:V}),[d,F,B,j,V])}const Ay=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?zc({element:r.current,padding:o}).fn(n):{}:r?zc({element:r,padding:o}).fn(n):{}}}},Ny=(e,t)=>({...yy(e),options:[e,t]}),_y=(e,t)=>({...vy(e),options:[e,t]}),jy=(e,t)=>({...Cy(e),options:[e,t]}),Ry=(e,t)=>({...by(e),options:[e,t]}),My=(e,t)=>({...wy(e),options:[e,t]}),Py=(e,t)=>({...Sy(e),options:[e,t]}),Oy=(e,t)=>({...Ay(e),options:[e,t]});var Dy="Arrow",Wc=v.forwardRef((e,t)=>{const{children:n,width:r=10,height:o=5,...s}=e;return u.jsx(_e.svg,{...s,ref:t,width:r,height:o,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:e.asChild?n:u.jsx("polygon",{points:"0,0 30,0 15,10"})})});Wc.displayName=Dy;var Ly=Wc;function Vc(e){const[t,n]=v.useState(void 0);return Tt(()=>{if(e){n({width:e.offsetWidth,height:e.offsetHeight});const r=new ResizeObserver(o=>{if(!Array.isArray(o)||!o.length)return;const s=o[0];let i,a;if("borderBoxSize"in s){const l=s.borderBoxSize,c=Array.isArray(l)?l[0]:l;i=c.inlineSize,a=c.blockSize}else i=e.offsetWidth,a=e.offsetHeight;n({width:i,height:a})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else n(void 0)},[e]),t}var Pi="Popper",[Kc,Ko]=Sn(Pi),[$y,qc]=Kc(Pi),Gc=e=>{const{__scopePopper:t,children:n}=e,[r,o]=v.useState(null);return u.jsx($y,{scope:t,anchor:r,onAnchorChange:o,children:n})};Gc.displayName=Pi;var Yc="PopperAnchor",Xc=v.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...o}=e,s=qc(Yc,n),i=v.useRef(null),a=Be(t,i),l=v.useRef(null);return v.useEffect(()=>{const c=l.current;l.current=(r==null?void 0:r.current)||i.current,c!==l.current&&s.onAnchorChange(l.current)}),r?null:u.jsx(_e.div,{...o,ref:a})});Xc.displayName=Yc;var Oi="PopperContent",[Fy,By]=Kc(Oi),Jc=v.forwardRef((e,t)=>{var Z,$,K,Q,ce,oe;const{__scopePopper:n,side:r="bottom",sideOffset:o=0,align:s="center",alignOffset:i=0,arrowPadding:a=0,avoidCollisions:l=!0,collisionBoundary:c=[],collisionPadding:d=0,sticky:f="partial",hideWhenDetached:p=!1,updatePositionStrategy:h="optimized",onPlaced:x,...m}=e,y=qc(Oi,n),[g,b]=v.useState(null),S=Be(t,Ne=>b(Ne)),[k,C]=v.useState(null),T=Vc(k),I=(T==null?void 0:T.width)??0,A=(T==null?void 0:T.height)??0,R=r+(s!=="center"?"-"+s:""),L=typeof d=="number"?d:{top:0,right:0,bottom:0,left:0,...d},P=Array.isArray(c)?c:[c],D=P.length>0,F={padding:L,boundary:P.filter(Uy),altBoundary:D},{refs:N,floatingStyles:B,placement:j,isPositioned:V,middlewareData:z}=Ey({strategy:"fixed",placement:R,whileElementsMounted:(...Ne)=>xy(...Ne,{animationFrame:h==="always"}),elements:{reference:y.anchor},middleware:[Ny({mainAxis:o+A,alignmentAxis:i}),l&&_y({mainAxis:!0,crossAxis:!1,limiter:f==="partial"?jy():void 0,...F}),l&&Ry({...F}),My({...F,apply:({elements:Ne,rects:Ue,availableWidth:re,availableHeight:xe})=>{const{width:Pe,height:Ze}=Ue.reference,Qe=Ne.floating.style;Qe.setProperty("--radix-popper-available-width",`${re}px`),Qe.setProperty("--radix-popper-available-height",`${xe}px`),Qe.setProperty("--radix-popper-anchor-width",`${Pe}px`),Qe.setProperty("--radix-popper-anchor-height",`${Ze}px`)}}),k&&Oy({element:k,padding:a}),Hy({arrowWidth:I,arrowHeight:A}),p&&Py({strategy:"referenceHidden",...F})]}),[M,q]=eu(j),J=kt(x);Tt(()=>{V&&(J==null||J())},[V,J]);const se=(Z=z.arrow)==null?void 0:Z.x,ge=($=z.arrow)==null?void 0:$.y,Ee=((K=z.arrow)==null?void 0:K.centerOffset)!==0,[Y,U]=v.useState();return Tt(()=>{g&&U(window.getComputedStyle(g).zIndex)},[g]),u.jsx("div",{ref:N.setFloating,"data-radix-popper-content-wrapper":"",style:{...B,transform:V?B.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:Y,"--radix-popper-transform-origin":[(Q=z.transformOrigin)==null?void 0:Q.x,(ce=z.transformOrigin)==null?void 0:ce.y].join(" "),...((oe=z.hide)==null?void 0:oe.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:u.jsx(Fy,{scope:n,placedSide:M,onArrowChange:C,arrowX:se,arrowY:ge,shouldHideArrow:Ee,children:u.jsx(_e.div,{"data-side":M,"data-align":q,...m,ref:S,style:{...m.style,animation:V?void 0:"none"}})})})});Jc.displayName=Oi;var Zc="PopperArrow",zy={top:"bottom",right:"left",bottom:"top",left:"right"},Qc=v.forwardRef(function(t,n){const{__scopePopper:r,...o}=t,s=By(Zc,r),i=zy[s.placedSide];return u.jsx("span",{ref:s.onArrowChange,style:{position:"absolute",left:s.arrowX,top:s.arrowY,[i]:0,transformOrigin:{top:"",right:"0 0",bottom:"center 0",left:"100% 0"}[s.placedSide],transform:{top:"translateY(100%)",right:"translateY(50%) rotate(90deg) translateX(-50%)",bottom:"rotate(180deg)",left:"translateY(50%) rotate(-90deg) translateX(50%)"}[s.placedSide],visibility:s.shouldHideArrow?"hidden":void 0},children:u.jsx(Ly,{...o,ref:n,style:{...o.style,display:"block"}})})});Qc.displayName=Zc;function Uy(e){return e!==null}var Hy=e=>({name:"transformOrigin",options:e,fn(t){var y,g,b;const{placement:n,rects:r,middlewareData:o}=t,i=((y=o.arrow)==null?void 0:y.centerOffset)!==0,a=i?0:e.arrowWidth,l=i?0:e.arrowHeight,[c,d]=eu(n),f={start:"0%",center:"50%",end:"100%"}[d],p=(((g=o.arrow)==null?void 0:g.x)??0)+a/2,h=(((b=o.arrow)==null?void 0:b.y)??0)+l/2;let x="",m="";return c==="bottom"?(x=i?f:`${p}px`,m=`${-l}px`):c==="top"?(x=i?f:`${p}px`,m=`${r.floating.height+l}px`):c==="right"?(x=`${-l}px`,m=i?f:`${h}px`):c==="left"&&(x=`${r.floating.width+l}px`,m=i?f:`${h}px`),{data:{x,y:m}}}});function eu(e){const[t,n="center"]=e.split("-");return[t,n]}var tu=Gc,nu=Xc,ru=Jc,ou=Qc,Wy="Portal",qo=v.forwardRef((e,t)=>{var a;const{container:n,...r}=e,[o,s]=v.useState(!1);Tt(()=>s(!0),[]);const i=n||o&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?Gs.createPortal(u.jsx(_e.div,{...r,ref:t}),i):null});qo.displayName=Wy;function Vy(e,t){return v.useReducer((n,r)=>t[n][r]??n,e)}var Yt=e=>{const{present:t,children:n}=e,r=Ky(t),o=typeof n=="function"?n({present:r.isPresent}):v.Children.only(n),s=Be(r.ref,qy(o));return typeof n=="function"||r.isPresent?v.cloneElement(o,{ref:s}):null};Yt.displayName="Presence";function Ky(e){const[t,n]=v.useState(),r=v.useRef(null),o=v.useRef(e),s=v.useRef("none"),i=e?"mounted":"unmounted",[a,l]=Vy(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return v.useEffect(()=>{const c=Go(r.current);s.current=a==="mounted"?c:"none"},[a]),Tt(()=>{const c=r.current,d=o.current;if(d!==e){const p=s.current,h=Go(c);e?l("MOUNT"):h==="none"||(c==null?void 0:c.display)==="none"?l("UNMOUNT"):l(d&&p!==h?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,l]),Tt(()=>{if(t){let c;const d=t.ownerDocument.defaultView??window,f=h=>{const m=Go(r.current).includes(CSS.escape(h.animationName));if(h.target===t&&m&&(l("ANIMATION_END"),!o.current)){const y=t.style.animationFillMode;t.style.animationFillMode="forwards",c=d.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=y)})}},p=h=>{h.target===t&&(s.current=Go(r.current))};return t.addEventListener("animationstart",p),t.addEventListener("animationcancel",f),t.addEventListener("animationend",f),()=>{d.clearTimeout(c),t.removeEventListener("animationstart",p),t.removeEventListener("animationcancel",f),t.removeEventListener("animationend",f)}}else l("ANIMATION_END")},[t,l]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:v.useCallback(c=>{r.current=c?getComputedStyle(c):null,n(c)},[])}}function Go(e){return(e==null?void 0:e.animationName)||"none"}function qy(e){var r,o;let t=(r=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:r.get,n=t&&"isReactWarning"in t&&t.isReactWarning;return n?e.ref:(t=(o=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:o.get,n=t&&"isReactWarning"in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}var Di="rovingFocusGroup.onEntryFocus",Gy={bubbles:!1,cancelable:!0},Br="RovingFocusGroup",[Li,su,Yy]=xi(Br),[Xy,iu]=Sn(Br,[Yy]),[Jy,Zy]=Xy(Br),au=v.forwardRef((e,t)=>u.jsx(Li.Provider,{scope:e.__scopeRovingFocusGroup,children:u.jsx(Li.Slot,{scope:e.__scopeRovingFocusGroup,children:u.jsx(Qy,{...e,ref:t})})}));au.displayName=Br;var Qy=v.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:o=!1,dir:s,currentTabStopId:i,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:l,onEntryFocus:c,preventScrollOnEntryFocus:d=!1,...f}=e,p=v.useRef(null),h=Be(t,p),x=Mo(s),[m,y]=pr({prop:i,defaultProp:a??null,onChange:l,caller:Br}),[g,b]=v.useState(!1),S=kt(c),k=su(n),C=v.useRef(!1),[T,I]=v.useState(0);return v.useEffect(()=>{const A=p.current;if(A)return A.addEventListener(Di,S),()=>A.removeEventListener(Di,S)},[S]),u.jsx(Jy,{scope:n,orientation:r,dir:x,loop:o,currentTabStopId:m,onItemFocus:v.useCallback(A=>y(A),[y]),onItemShiftTab:v.useCallback(()=>b(!0),[]),onFocusableItemAdd:v.useCallback(()=>I(A=>A+1),[]),onFocusableItemRemove:v.useCallback(()=>I(A=>A-1),[]),children:u.jsx(_e.div,{tabIndex:g||T===0?-1:0,"data-orientation":r,...f,ref:h,style:{outline:"none",...e.style},onMouseDown:de(e.onMouseDown,()=>{C.current=!0}),onFocus:de(e.onFocus,A=>{const R=!C.current;if(A.target===A.currentTarget&&R&&!g){const L=new CustomEvent(Di,Gy);if(A.currentTarget.dispatchEvent(L),!L.defaultPrevented){const P=k().filter(j=>j.focusable),D=P.find(j=>j.active),F=P.find(j=>j.id===m),B=[D,F,...P].filter(Boolean).map(j=>j.ref.current);uu(B,d)}}C.current=!1}),onBlur:de(e.onBlur,()=>b(!1))})})}),lu="RovingFocusGroupItem",cu=v.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:o=!1,tabStopId:s,children:i,...a}=e,l=Cn(),c=s||l,d=Zy(lu,n),f=d.currentTabStopId===c,p=su(n),{onFocusableItemAdd:h,onFocusableItemRemove:x,currentTabStopId:m}=d;return v.useEffect(()=>{if(r)return h(),()=>x()},[r,h,x]),u.jsx(Li.ItemSlot,{scope:n,id:c,focusable:r,active:o,children:u.jsx(_e.span,{tabIndex:f?0:-1,"data-orientation":d.orientation,...a,ref:t,onMouseDown:de(e.onMouseDown,y=>{r?d.onItemFocus(c):y.preventDefault()}),onFocus:de(e.onFocus,()=>d.onItemFocus(c)),onKeyDown:de(e.onKeyDown,y=>{if(y.key==="Tab"&&y.shiftKey){d.onItemShiftTab();return}if(y.target!==y.currentTarget)return;const g=nv(y,d.orientation,d.dir);if(g!==void 0){if(y.metaKey||y.ctrlKey||y.altKey||y.shiftKey)return;y.preventDefault();let S=p().filter(k=>k.focusable).map(k=>k.ref.current);if(g==="last")S.reverse();else if(g==="prev"||g==="next"){g==="prev"&&S.reverse();const k=S.indexOf(y.currentTarget);S=d.loop?rv(S,k+1):S.slice(k+1)}setTimeout(()=>uu(S))}}),children:typeof i=="function"?i({isCurrentTabStop:f,hasTabStop:m!=null}):i})})});cu.displayName=lu;var ev={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function tv(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function nv(e,t,n){const r=tv(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return ev[r]}function uu(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function rv(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var ov=au,sv=cu,iv=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},yr=new WeakMap,Yo=new WeakMap,Xo={},$i=0,du=function(e){return e&&(e.host||du(e.parentNode))},av=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=du(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})},lv=function(e,t,n,r){var o=av(t,Array.isArray(e)?e:[e]);Xo[n]||(Xo[n]=new WeakMap);var s=Xo[n],i=[],a=new Set,l=new Set(o),c=function(f){!f||a.has(f)||(a.add(f),c(f.parentNode))};o.forEach(c);var d=function(f){!f||l.has(f)||Array.prototype.forEach.call(f.children,function(p){if(a.has(p))d(p);else try{var h=p.getAttribute(r),x=h!==null&&h!=="false",m=(yr.get(p)||0)+1,y=(s.get(p)||0)+1;yr.set(p,m),s.set(p,y),i.push(p),m===1&&x&&Yo.set(p,!0),y===1&&p.setAttribute(n,"true"),x||p.setAttribute(r,"true")}catch(g){console.error("aria-hidden: cannot operate on ",p,g)}})};return d(t),a.clear(),$i++,function(){i.forEach(function(f){var p=yr.get(f)-1,h=s.get(f)-1;yr.set(f,p),s.set(f,h),p||(Yo.has(f)||f.removeAttribute(r),Yo.delete(f)),h||f.removeAttribute(n)}),$i--,$i||(yr=new WeakMap,yr=new WeakMap,Yo=new WeakMap,Xo={})}},Fi=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),o=iv(e);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live], script"))),lv(r,o,n,"aria-hidden")):function(){return null}},mn=function(){return mn=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},mn.apply(this,arguments)};function fu(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 cv(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 Jo="right-scroll-bar-position",Zo="width-before-scroll-bar",uv="with-scroll-bars-hidden",dv="--removed-body-scroll-bar-size";function Bi(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function fv(e,t){var n=w.useState(function(){return{value:e,callback:t,facade:{get current(){return n.value},set current(r){var o=n.value;o!==r&&(n.value=r,n.callback(r,o))}}}})[0];return n.callback=t,n.facade}var pv=typeof window<"u"?v.useLayoutEffect:v.useEffect,pu=new WeakMap;function hv(e,t){var n=fv(null,function(r){return e.forEach(function(o){return Bi(o,r)})});return pv(function(){var r=pu.get(n);if(r){var o=new Set(r),s=new Set(e),i=n.current;o.forEach(function(a){s.has(a)||Bi(a,null)}),s.forEach(function(a){o.has(a)||Bi(a,i)})}pu.set(n,e)},[e]),n}function mv(e){return e}function gv(e,t){t===void 0&&(t=mv);var n=[],r=!1,o={read:function(){if(r)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return n.length?n[n.length-1]:e},useMedium:function(s){var i=t(s,r);return n.push(i),function(){n=n.filter(function(a){return a!==i})}},assignSyncMedium:function(s){for(r=!0;n.length;){var i=n;n=[],i.forEach(s)}n={push:function(a){return s(a)},filter:function(){return n}}},assignMedium:function(s){r=!0;var i=[];if(n.length){var a=n;n=[],a.forEach(s),i=n}var l=function(){var d=i;i=[],d.forEach(s)},c=function(){return Promise.resolve().then(l)};c(),n={push:function(d){i.push(d),c()},filter:function(d){return i=i.filter(d),n}}}};return o}function xv(e){e===void 0&&(e={});var t=gv(null);return t.options=mn({async:!0,ssr:!1},e),t}var hu=function(e){var t=e.sideCar,n=fu(e,["sideCar"]);if(!t)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=t.read();if(!r)throw new Error("Sidecar medium not found");return v.createElement(r,mn({},n))};hu.isSideCarExport=!0;function yv(e,t){return e.useMedium(t),hu}var mu=xv(),zi=function(){},Qo=v.forwardRef(function(e,t){var n=v.useRef(null),r=v.useState({onScrollCapture:zi,onWheelCapture:zi,onTouchMoveCapture:zi}),o=r[0],s=r[1],i=e.forwardProps,a=e.children,l=e.className,c=e.removeScrollBar,d=e.enabled,f=e.shards,p=e.sideCar,h=e.noRelative,x=e.noIsolation,m=e.inert,y=e.allowPinchZoom,g=e.as,b=g===void 0?"div":g,S=e.gapMode,k=fu(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),C=p,T=hv([n,t]),I=mn(mn({},k),o);return v.createElement(v.Fragment,null,d&&v.createElement(C,{sideCar:mu,removeScrollBar:c,shards:f,noRelative:h,noIsolation:x,inert:m,setCallbacks:s,allowPinchZoom:!!y,lockRef:n,gapMode:S}),i?v.cloneElement(v.Children.only(a),mn(mn({},I),{ref:T})):v.createElement(b,mn({},I,{className:l,ref:T}),a))});Qo.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},Qo.classNames={fullWidth:Zo,zeroRight:Jo};var vv=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function bv(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=vv();return t&&e.setAttribute("nonce",t),e}function wv(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function Sv(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var Cv=function(){var e=0,t=null;return{add:function(n){e==0&&(t=bv())&&(wv(t,n),Sv(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},Tv=function(){var e=Cv();return function(t,n){v.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},gu=function(){var e=Tv(),t=function(n){var r=n.styles,o=n.dynamic;return e(r,o),null};return t},kv={left:0,top:0,right:0,gap:0},Ui=function(e){return parseInt(e||"",10)||0},Iv=function(e){var t=window.getComputedStyle(document.body),n=t[e==="padding"?"paddingLeft":"marginLeft"],r=t[e==="padding"?"paddingTop":"marginTop"],o=t[e==="padding"?"paddingRight":"marginRight"];return[Ui(n),Ui(r),Ui(o)]},Ev=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return kv;var t=Iv(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])}},Av=gu(),vr="data-scroll-locked",Nv=function(e,t,n,r){var o=e.left,s=e.top,i=e.right,a=e.gap;return n===void 0&&(n="margin"),`
|
|
37
|
+
`))>=0;){const te=gt.slice(0,X);gt=gt.slice(X+2);const pe=Wg(te);if(!pe)continue;let ve;try{ve=JSON.parse(pe)}catch{console.debug("[use-chat] malformed SSE:",pe.slice(0,200));continue}const we=Hg(ve)?ve.data:ve;et=Date.now();const Fe=we.seq;if(Fe!==void 0){if(Fe<=bt){console.debug("[use-chat] drop duplicate/out-of-order event",{seq:Fe,lastProcessedSeq:bt,type:we.type});continue}bt>0&&Fe>bt+1&&(($=j==null?void 0:j.onGap)==null||$.call(j,{from:bt,to:Fe})),bt=Fe,C.current=Fe,y(Fe)}if(console.debug("[use-chat] received event",{seq:we.seq,type:we.type,preview:(()=>{var Oe;try{return we.type==="message_delta"?{deltaTypes:(Oe=we.delta)==null?void 0:Oe.map(je=>je.type),textLen:(we.delta||[]).filter(je=>je.type==="text").map(je=>String(je.text||"").length)}:we.content||we.delta?{hasContent:!0}:{}}catch(je){return{err:String(je)}}})()}),we.type==="checkpoint")I.current=we.checkpointId??null,A.current=we.checkpointNs??null,x(we.checkpointId??null);else if(we.type==="state_history"){R.current=we;try{const je=dr(we).latest;je&&(I.current=je.checkpointId??null,A.current=je.checkpointNs??null,x(je.checkpointId??null))}catch(Oe){console.warn("[use-chat] Failed to hydrate state_history payload",Oe)}}try{B==null||B(we)}catch(Oe){console.error("[use-chat] Error in onEvent callback:",Oe,"for event:",we.type)}if(we.type==="token"&&e.autoAppendAssistant!==!1)ht.push(we.content),Mt();else if(we.type==="message_delta"){const Oe=we.delta.filter(je=>je.type==="text").map(je=>je.text).join("");Oe&&e.autoAppendAssistant!==!1&&(ht.push(Oe),Mt())}else if(we.type==="heartbeat"){console.debug("[use-chat] heartbeat received");try{(K=j==null?void 0:j.onHeartbeat)==null||K.call(j,we)}catch(Oe){console.warn("[use-chat] heartbeat callback failed",Oe)}}else if(St!==null&&cancelAnimationFrame(St),Lt(),we.type==="checkpoint")x(we.checkpointId);else if(we.type==="error"){const Oe=we;if(d(Oe.message),z="error",M=Oe.message,Oe.error_type==="auth_error"||Oe.code==="TOKEN_EXPIRED"||((Q=Oe.message)==null?void 0:Q.includes("token"))||((ce=Oe.message)==null?void 0:ce.includes("401"))||((oe=Oe.message)==null?void 0:oe.includes("unauthorized"))||((Ne=Oe.message)==null?void 0:Ne.includes("Unauthorized"))){console.error("[use-chat] Auth error detected:",Oe.message);try{(Ue=j==null?void 0:j.onAuthError)==null||Ue.call(j,Oe.message)}catch(Vt){console.warn("[use-chat] onAuthError handler failed",Vt)}V.abort()}}}}Lt(),z===null&&!V.signal.aborted&&(z="complete")}catch(Ge){if(Ge.name==="AbortError")z=z??"aborted";else{const Ye=Ge.message||String(Ge);z="error",M=Ye,d(Ye),(re=j==null?void 0:j.onError)==null||re.call(j,Ye)}}finally{try{await at.cancel()}catch{}finally{(xe=at.releaseLock)==null||xe.call(at)}St!==null&&typeof window<"u"&&window.cancelAnimationFrame(St),clearInterval(It)}}catch(Ve){if(Ve.name==="AbortError")z=z??"aborted";else{const tt=Ve.message||String(Ve);z="error",M=tt,d(tt),(Pe=j==null?void 0:j.onError)==null||Pe.call(j,tt),q||((Ze=j==null?void 0:j.onConnectionError)==null||Ze.call(j,tt),q=!0)}}finally{const Ve=C.current,tt=I.current,it=A.current,qe=R.current,nt=z??(V.signal.aborted?"aborted":M?"error":"complete");try{(Qe=j==null?void 0:j.onClosed)==null||Qe.call(j,{reason:nt,lastSeq:Ve,lastCheckpointId:tt,lastCheckpointNs:it,lastStateHistory:qe,error:M})}catch(at){console.warn("[use-chat] onClosed callback failed",at)}l(!1),b(!1),S.current=null,C.current=0,y(0),T.current=null}})(),{close:()=>V.abort()}},[t,n,r,e.autoAppendAssistant]);return w.useEffect(()=>()=>{var N;k.current=!1,(N=S.current)==null||N.abort()},[]),{isStreaming:a,error:c,assistantText:f,lastCheckpointId:p,lastSeq:m,connected:g,stream:F,stop:D,clear:P,setToken:L}}function Hg(e){return!!e&&typeof e=="object"&&e.protocolVersion==="v1"&&"data"in e}function Wg(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 Vg(e){return e.type!=="token"}const Kg={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null,messagesStreamMeta:{},pendingInterrupt:null};function qg(e,t){var n;switch(t.type){case"reset":return{messages:fi(((n=t.payload)==null?void 0:n.messages)??[]),assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null,pendingInterrupt:null};case"seed":{const r=fi(t.payload.messages),o={...e,messages:r,assemblingId:null,pendingInterrupt:t.payload.pendingInterrupt??null};return Object.prototype.hasOwnProperty.call(t.payload,"checkpointId")&&(o.lastCheckpointId=t.payload.checkpointId??null),Object.prototype.hasOwnProperty.call(t.payload,"checkpointNs")&&(o.lastCheckpointNs=t.payload.checkpointNs??null),o}case"prepend":{const r=fi(t.payload.messages);if(!r.length)return e;const o=new Set(e.messages.map(i=>i.id)),s=r.filter(i=>!o.has(i.id));return s.length?{...e,messages:[...s,...e.messages]}: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 Xl(e,t.payload.ev);case"batch":{const{events:r}=t.payload;return r.length?r.reduce((o,s)=>Xl(o,s),e):e}case"interrupt_response":return{...e,messages:Jl(e.messages),pendingInterrupt:null};default:return e}}function Yl(e=[]){const[t,n]=w.useReducer(qg,{...Kg,messages:e}),r=w.useRef([]),o=w.useRef(null),s=w.useRef(null),i=w.useCallback(()=>{o.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.current),s.current!==null&&clearTimeout(s.current),o.current=null,s.current=null;const d=r.current;d.length&&(r.current=[],n({type:"batch",payload:{events:d}}))},[]),a=w.useCallback(()=>{typeof window<"u"&&typeof window.requestAnimationFrame=="function"?o.current===null&&(o.current=window.requestAnimationFrame(()=>i())):s.current===null&&(s.current=setTimeout(i,8))},[i]),l=w.useCallback(d=>{r.current.push(d),a()},[a]);w.useEffect(()=>()=>{o.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.current),s.current!==null&&clearTimeout(s.current),r.current=[]},[]);const c=w.useMemo(()=>({reset:d=>n({type:"reset",payload:{messages:d}}),seed:(d,f)=>n({type:"seed",payload:{messages:d,...f??{}}}),prepend:d=>n({type:"prepend",payload:{messages:d}}),pushUser:d=>n({type:"user_message",payload:{message:d}}),onEvent:l}),[l]);return{state:t,dispatch:n,...c}}function Xl(e,t){var n,r,o,s,i;if(t.type==="message_start"&&t.role==="assistant"){const a=t.id,l=Jg(t.model);if(e.messages.some(f=>f.id===a)){const f=e.messagesStreamMeta??{},h={...f,[a]:f[a]??{lastSeq:t.seq??null,lastText:""}};return{...e,assemblingId:a,messagesStreamMeta:h}}const d={id:a,role:"assistant",name:l||void 0,model:t.model,createdAt:new Date().toISOString(),content:[]};return{...e,assemblingId:a,messages:[...e.messages,d]}}if(t.type==="message_delta"){const a=e.assemblingId??Zl(e.messages);if(!a)return e;const l=e.messages,c=l.findIndex(k=>k.id===a&&k.role==="assistant");if(c===-1)return e;const d=l[c],f=e.messagesStreamMeta??{},h=f[a]??{lastSeq:null,lastText:tc(d.content)},p=t.seq??null;if(p!==null&&typeof p=="number"&&typeof h.lastSeq=="number"&&p<=h.lastSeq)return console.debug("[MessageReducer] skipping delta - seq <= lastSeq",{seq:p,lastSeq:h.lastSeq}),e;const{newParts:x,newMeta:m,changed:y}=Gg(d.content,t.delta,h,p);if(!y)return e;const g={...d,content:x},b=Ao(l,c,g),S={...f,[a]:m};return{...e,messages:b,messagesStreamMeta:S}}if(t.type==="message_end"){const a=e.assemblingId??Zl(e.messages);if(!a)return{...e,assemblingId:null};const l=e.messages,c=l.findIndex(d=>d.id===a&&d.role==="assistant");if(c>=0){const d=l[c];if(!((n=d.content)==null?void 0:n.some(h=>{var p;return(h==null?void 0:h.type)==="text"&&((p=h.text)==null?void 0:p.trim())}))){console.debug("[MessageReducer] pruning assistant message with no visible text",{id:d.id,contentTypes:(r=d.content)==null?void 0:r.map(p=>p==null?void 0:p.type),contentPreview:(o=d.content)==null?void 0:o.map(p=>(p==null?void 0:p.type)==="text"?String(p.text).slice(0,100):p==null?void 0:p.type)});const h=[...l.slice(0,c),...l.slice(c+1)];return{...e,assemblingId:null,messages:h}}}return e}if(t.type==="tool_start"){const a=Ql(t),l=a[0]??(typeof t.id=="string"?t.id:null)??(typeof t.call_id=="string"?t.call_id:null),c=t.name??t.tool??"tool";!l&&a.length===0&&a.push(`${c}-${Date.now()}`);const d=a.length?a:l?[l]:[],f=ec(e,d,c),h=f>=0?e.messages[f]:null,p=l??d[0]??`${c}-${Date.now()}`,x=(h==null?void 0:h.id)??`tool-${p}`,m=d[0]??p,y={type:"tool_call",id:m,name:c,args:t.args};if(h){const S=hi(h,d,c,t.args),k={...h,name:h.name??c,additionalKwargs:S},C=f,T=C>=0?Ao(e.messages,C,k):e.messages,I=No(k,d),A=mi(e.toolIndex,x,I);return{...e,messages:T,toolIndex:A}}const g={id:x,role:"tool",name:c,createdAt:new Date().toISOString(),content:[y],additionalKwargs:hi(void 0,d.length?d:[m],c,t.args)},b=No(g,d.length?d:[m]);return{...e,messages:[...e.messages,g],toolIndex:mi(e.toolIndex,x,b)}}if(t.type==="tool_end"){const a=Ql(t);if(!a.length&&!(typeof t.id=="string"&&t.id))return e;const l=t.name??null,c=ec(e,a,l),d=c>=0?e.messages[c]:null,f=l??(d==null?void 0:d.name)??((s=d==null?void 0:d.additionalKwargs)==null?void 0:s.toolName)??"tool",h=a[0]??((i=d==null?void 0:d.id)==null?void 0:i.replace(/^tool-/,""))??`${f}-${Date.now()}`,p=(d==null?void 0:d.id)??`tool-${h}`,x=No(d,a);let m=t.output;if(typeof t.output=="string")try{const I=t.output.trim();(I.startsWith("{")||I.startsWith("["))&&(m=JSON.parse(I))}catch{m=t.output}const y=t.artifact??(d==null?void 0:d.artifact),g={type:"text",text:typeof m=="string"?m:JSON.stringify(m)},b=(d==null?void 0:d.createdAt)??new Date().toISOString(),S=hi(d??void 0,x.length?x:a,f),k={id:p,role:"tool",name:f??(d==null?void 0:d.name)??"tool",content:[g],createdAt:b,artifact:y??void 0,additionalKwargs:S},C=c>=0?Ao(e.messages,c,k):[...e.messages,k],T=No(k,a.length?a:x);return{...e,messages:C,toolIndex:mi(e.toolIndex,p,T)}}if(t.type==="checkpoint"){const a=t.checkpointNs??e.lastCheckpointNs??null,l=Xg(e.messages,t.checkpointId,a);return{...e,lastCheckpointId:t.checkpointId,lastCheckpointNs:a,messages:l}}if(t.type==="branch"){const a=t.checkpointId??e.lastCheckpointId,l=t.checkpointNs??e.lastCheckpointNs;return{...e,lastBranch:t,lastCheckpointId:a??null,lastCheckpointNs:l??null}}if(t.type==="error"){const a={id:`err-${Date.now()}`,role:"system",content:[{type:"text",text:`Error: ${t.message}`}],createdAt:new Date().toISOString()};return{...e,messages:[...e.messages,a]}}if(t.type==="state_history"){const a=dr(t),l=a.interrupt,c=a.latest,d=l===null?Jl(e.messages):e.messages;return{...e,messages:d,pendingInterrupt:l,lastCheckpointId:(c==null?void 0:c.checkpointId)??e.lastCheckpointId,lastCheckpointNs:(c==null?void 0:c.checkpointNs)??e.lastCheckpointNs}}return t.type==="thread_info",e}function fi(e){return e.filter(t=>{var s;if(t.role!=="assistant")return!0;const n=(t.content||[]).some(i=>{var a;return i&&i.type==="text"&&((a=i.text)==null?void 0:a.trim())}),r=(t.content||[]).some(i=>i&&i.type==="image_url"),o=!!((s=t.artifact)!=null&&s.plots&&t.artifact.plots.length>0);return!!(n||r||o)})}function Ao(e,t,n){return t<0||t>=e.length?e:[...e.slice(0,t),n,...e.slice(t+1)]}function Jl(e){let t=!1;const n=e.map(r=>{const o=(r.content??[]).filter(s=>s.type!=="interrupt");return o.length!==r.content.length?(t=!0,{...r,content:o}):r});return t?n:e}function Zl(e){for(let t=e.length-1;t>=0;t--)if(e[t].role==="assistant")return e[t].id;return null}function Ql(e){const t=new Set,n=r=>{typeof r=="string"&&r.trim()&&t.add(r.trim())};return n(e.id),n(e==null?void 0:e.call_id),n(e==null?void 0:e.callId),Array.from(t)}function pi(e){if(!e)return[];const t=new Set,n=o=>{typeof o=="string"&&o.trim()&&t.add(o.trim())},r=e.additionalKwargs;if(r){n(r.toolCallId);const o=r.toolCallIds;if(Array.isArray(o))for(const s of o)n(s)}for(const o of e.content??[])(o==null?void 0:o.type)==="tool_call"&&n(o.id);return Array.from(t)}function hi(e,t,n,r){const o=new Set,s=l=>{typeof l=="string"&&l.trim()&&o.add(l.trim())};if(e){const l=pi(e);for(const c of l)s(c)}for(const l of t)s(l);const i=Array.from(o),a={...(e==null?void 0:e.additionalKwargs)??{}};if(i.length){a.toolCallIds=i;const l=typeof a.toolCallId=="string"?a.toolCallId.trim():null;a.toolCallId=l&&o.has(l)?l:i[0]}return n&&(a.toolName=n),r!==void 0&&(a.toolArgs=r),a}function No(e,t){const n=new Set;for(const o of t)typeof o=="string"&&o.trim()&&n.add(o.trim());const r=pi(e);for(const o of r)n.add(o);return Array.from(n)}function mi(e,t,n){if(!n.length)return e;let r=!1;const o={...e};for(const s of n)s&&o[s]!==t&&(o[s]=t,r=!0);return r?o:e}function ec(e,t,n){var o,s;const r=new Set(t.filter(i=>typeof i=="string"&&i.trim()));for(const i of r){const a=e.toolIndex[i];if(a){const l=e.messages.findIndex(c=>c.id===a);if(l!==-1)return l}}for(let i=e.messages.length-1;i>=0;i--){const a=e.messages[i];if(a.role!=="tool")continue;if(pi(a).some(c=>r.has(c)))return i}if(typeof n=="string"&&n.trim())for(let i=e.messages.length-1;i>=0;i--){const a=e.messages[i];if(a.role!=="tool"||a.name&&a.name!==n)continue;if(!((o=a.content)==null?void 0:o.some(c=>c.type!=="tool_call")))return i}for(let i=e.messages.length-1;i>=0;i--){const a=e.messages[i];if(a.role!=="tool")continue;if(!((s=a.content)==null?void 0:s.some(c=>c.type!=="tool_call")))return i}return-1}function tc(e){return!e||!e.length?"":e.filter(t=>t.type==="text").map(t=>t.text??"").join("")}function Gg(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??tc(e);let l="",c=e.slice();if(s){const f=Yg(a,s);if(f===""?l="":f===s?l=s:l=f,l){const h=c[c.length-1];if((h==null?void 0:h.type)==="text"){const p=h.text??"",x={...h,text:p+l};c=[...c.slice(0,c.length-1),x]}else c=[...c,{type:"text",text:l}];o.lastText=a+l}else o.lastText=a}i.length&&(c=[...c,...i]);const d=!!(l||i.length);return{newParts:c,newMeta:o,changed:d}}function nc(e){return e.replace(/\s+/g," ").trim()}function Yg(e,t){if(!t)return"";if(!e)return t;if(e===t)return"";const n=Math.min(e.length,t.length);for(let i=n;i>0;i--)if(e.slice(-i)===t.slice(0,i))return t.slice(i);const r=nc(e),o=nc(t);if(r===o)return"";const s=Math.min(r.length,o.length);for(let i=s;i>0;i--)if(r.slice(-i)===o.slice(0,i))return t;return t}function Xg(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 Ao(e,r,s)}return e}function Jg(e){if(!e)return null;const t=e.split("/");return t[t.length-1]||null}const rc=200;function Zg({baseUrl:e,onThreadInfo:t,onMessageEvent:n,onStateHistory:r,onUnhandledEvent:o,onSequenceGap:s,onStreamClosed:i,onConnectionError:a,onAuthError:l,onHeartbeat:c}){const d=w.useRef(null),f=w.useRef(null),h=w.useRef(new Map),p=w.useRef(null),x=w.useRef(null),m=w.useCallback(P=>{try{const D=globalThis.structuredClone;if(typeof D=="function")return D(P)}catch{}try{return JSON.parse(JSON.stringify(P))}catch{return P}},[]),y=w.useCallback((P,D)=>{if(!P)return;const F=h.current.get(P)??[],N=m(D),B=F.length>=rc?[...F.slice(F.length-rc+1),N]:[...F,N];h.current.set(P,B)},[m]),g=w.useCallback(P=>{P&&h.current.set(P,[])},[]),b=w.useCallback(P=>{const D=P??f.current;if(!D)return;const F=h.current.get(D);F!=null&&F.length&&F.forEach(N=>{try{n(N)}catch(B){console.error("[useChatStreamingService] Failed to replay buffered event",B)}})},[n]),S=w.useCallback(P=>{var N,B,j,V,z;const D=P.seq??null;if(D!==null){const M=d.current;if(M!==null){if(D<=M)return;D>M+1&&(s==null||s({from:M,to:D}))}d.current=D}if(P.type==="thread_info"){f.current=P.threadId,p.current&&(p.current.threadIdGuess=P.threadId),x.current=P,g(P.threadId),console.log("[useChatStreamingService] 🎯 Received thread_info event:",P);try{t(P)}catch(M){console.error("[useChatStreamingService] Error in onThreadInfo handler:",M)}return}if(P.type==="heartbeat"){try{c==null||c(P)}catch(M){console.error("[useChatStreamingService] Error in onHeartbeat handler:",M)}return}if(P.type==="error"){const M=P;if(M.error_type==="auth_error"||M.code==="TOKEN_EXPIRED"||((N=M.message)==null?void 0:N.includes("token"))||((B=M.message)==null?void 0:B.includes("401"))||((j=M.message)==null?void 0:j.includes("unauthorized"))||((V=M.message)==null?void 0:V.includes("Unauthorized"))){console.error("[useChatStreamingService] Auth error event detected:",M.message);try{l==null||l(M.message)}catch(J){console.warn("[useChatStreamingService] onAuthError handler failed",J)}}}const F=P.threadId??(P.type==="state_history"?P.threadId:void 0)??f.current??((z=p.current)==null?void 0:z.threadIdGuess)??null;if(P.type==="state_history"){f.current=F??f.current;try{r==null||r(P)}catch(M){console.error("[useChatStreamingService] onStateHistory handler failed",M)}}if(Vg(P)){P.type==="checkpoint"||P.type==="state_history"?g(F??null):y(F??null,P);try{n(P)}catch(M){console.error("[useChatStreamingService] Error in onMessageEvent handler:",M)}return}try{o==null||o(P)}catch(M){console.error("[useChatStreamingService] Error in onUnhandledEvent handler:",M)}},[y,g,n,s,t,r,o]),{stream:k,stop:C,isStreaming:T,error:I,setToken:A}=Gl({baseUrl:e,token:void 0}),R=w.useCallback((P,D)=>{d.current=null,x.current=null,f.current=P.threadId??null,p.current={request:P,callbacks:D,manualStop:!1,threadIdGuess:P.threadId??null},k(P,S,{onOpen:D==null?void 0:D.onOpen,onError:F=>{var N;(N=D==null?void 0:D.onError)==null||N.call(D,F)},onGap:(D==null?void 0:D.onGap)??s,onConnectionError:F=>{var N;a==null||a(F),(N=D==null?void 0:D.onConnectionError)==null||N.call(D,F)},onAuthError:F=>{var N;l==null||l(F),(N=D==null?void 0:D.onAuthError)==null||N.call(D,F)},onHeartbeat:F=>{var N;try{c==null||c(F)}catch(B){console.warn("[useChatStreamingService] onHeartbeat handler failed",B)}try{(N=D==null?void 0:D.onHeartbeat)==null||N.call(D,F)}catch(B){console.warn("[useChatStreamingService] downstream onHeartbeat handler failed",B)}},onClosed:F=>{var V,z,M,q;const N=((V=p.current)==null?void 0:V.manualStop)??!1,B=f.current??((z=p.current)==null?void 0:z.threadIdGuess)??((M=F.lastStateHistory)==null?void 0:M.threadId)??null;(F.reason==="complete"||F.reason==="aborted"&&N)&&g(B);const j={...F,threadId:B,threadInfo:x.current,manualStop:N};try{i==null||i(j)}catch(J){console.warn("[useChatStreamingService] onStreamClosed handler failed",J)}try{(q=D==null?void 0:D.onClosed)==null||q.call(D,j)}catch(J){console.warn("[useChatStreamingService] downstream onClosed handler failed",J)}p.current&&(p.current=null)}})},[g,S,l,a,c,s,i,k]),L=w.useCallback(()=>{p.current&&(p.current.manualStop=!0),C()},[C]);return w.useMemo(()=>({startStream:R,stop:L,isStreaming:T,error:I,setAuthToken:A,replayBufferedEvents:b}),[R,L,T,I,A,b])}const oc=w.createContext(null),sc=w.createContext(null),ic=w.createContext(null);w.createContext(!1);function Qg({children:e,initialThreadId:t=null,initialCheckpointId:n=null,initialCheckpointNs:r=null,autoLoadInitial:o=!0,onError:s,onAuthError:i,onThreadChange:a}){const{api:l,baseUrl:c}=ui(),d=w.useMemo(()=>wn(c),[c]),[f,h]=w.useState([]),[p,x]=w.useState(t),[m,y]=w.useState(!1),[g,b]=w.useState(null),[S,k]=w.useState(!1),[C,T]=w.useState(null),{state:I,seed:A,prepend:R,pushUser:L,onEvent:P}=Yl(),[D,F]=w.useState(!1),[N,B]=w.useState(!1),[j,V]=w.useState(null),[z,M]=w.useState([]),[q,J]=w.useState([]),[se,ge]=w.useState(!1),Ee=w.useMemo(()=>z.flatMap(G=>G.messages??[]),[z]),Y=w.useMemo(()=>ql(Ee),[Ee]),U=w.useRef(p),Z=w.useRef(null),$=w.useRef(null),K=w.useRef(null),Q=w.useRef(null),ce=w.useRef(!1),oe=w.useRef(null),Ne=w.useRef(new Map),Ue=w.useRef(new Map);w.useEffect(()=>{U.current=p},[p]);const re=w.useCallback(async()=>{y(!0),b(null);try{const G=await l.listThreads();h(G??[])}catch(G){const _=String(G);b(_),s==null||s(_)}finally{y(!1)}},[l,s]),xe=w.useCallback(G=>{if(!(G!=null&&G.threadId))return;const _={threadId:G.threadId,title:G.title||`Thread ${G.threadId.slice(0,8)}`,createdAt:G.createdAt||new Date().toISOString(),updatedAt:G.updatedAt||new Date().toISOString(),messageCount:G.messageCount??1};h(X=>{let te=!1;const pe=X.map(ve=>ve.threadId===_.threadId?(te=!0,console.debug("[ChatSessionProvider] thread_info: updating existing thread",_.threadId),{...ve,title:_.title??ve.title,updatedAt:_.updatedAt??ve.updatedAt,messageCount:_.messageCount??ve.messageCount}):ve);return te?pe:(console.debug("[ChatSessionProvider] thread_info: adding thread to list",_.threadId),[_,...X])})},[]),Pe=w.useCallback(G=>{const _=G.threadId??U.current;if(!_||U.current&&U.current!==_)return;const{checkpoints:X,timeline:te}=dr(G);if(!X.length)return;const pe=X.find(ve=>ve.messages&&ve.messages.length>0)??X.find(ve=>!!ve.checkpointId)??X[0];A((pe==null?void 0:pe.messages)??[],{checkpointId:(pe==null?void 0:pe.checkpointId)??null,checkpointNs:(pe==null?void 0:pe.checkpointNs)??null}),J(te),M(X),F(!!(pe!=null&&pe.nextCursor)),V((pe==null?void 0:pe.nextCursor)??null),oe.current=`${_}:latest`,$.current=null,K.current=null},[A]),Ze=w.useCallback(G=>{console.log("[ChatSessionProvider] 🎯 Received thread_info:",G.threadId),xe(G),U.current!==G.threadId&&((G.created??!U.current)&&($.current=G.threadId),K.current=G.threadId,console.log("[ChatSessionProvider] thread_info: marking to skip auto-load for new thread"),x(G.threadId))},[xe]),{startStream:Qe,stop:Ve,isStreaming:tt,error:it,setAuthToken:qe}=Zg({baseUrl:d,onThreadInfo:Ze,onMessageEvent:P,onStateHistory:Pe,onUnhandledEvent:G=>{console.warn("[ChatSessionProvider] Unhandled event:",G.type)},onAuthError:i}),nt=w.useCallback(async G=>{try{const _=await l.createThread(G);return x(_.threadId),await re(),_.threadId}catch(_){return s==null||s(String(_)),null}},[l,re,s]),at=w.useCallback(async G=>{const _=f;h(te=>te.filter(pe=>pe.threadId!==G));const X=new AbortController;Ue.current.set(G,X);try{await l.deleteThread(G),U.current===G&&(x(null),A([],{})),console.log("[ChatSessionProvider] Thread deleted successfully:",G)}catch(te){console.error("[ChatSessionProvider] Delete failed, restoring thread:",G,te),h(_),s==null||s(`Failed to delete thread: ${String(te)}`)}finally{Ue.current.delete(G)}},[f,l,A,s]),Rt=w.useCallback(async(G,_)=>{try{await l.updateThread(G,_),await re()}catch(X){s==null||s(String(X))}},[l,re,s]),gt=w.useCallback(async(G,_)=>{if(!G)return;const X=`${G}:${_??"latest"}`,te=Ne.current.get(X);if(te)return te;const pe=(async()=>{const ve=G;k(!0),T(null);try{const we=await l.getStateHistory({threadId:ve,checkpointId:_||void 0});if(U.current!==ve){console.log(`[ChatSessionProvider] Thread changed during load (was ${ve}, now ${U.current}), discarding stale data`);return}const{checkpoints:Fe,timeline:Oe}=dr(we),je=Fe.find(Vt=>Vt.messages&&Vt.messages.length>0)??(_?Fe.find(Vt=>Vt.checkpointId===_):null)??Fe[0];A((je==null?void 0:je.messages)??[],{checkpointId:(je==null?void 0:je.checkpointId)??null,checkpointNs:(je==null?void 0:je.checkpointNs)??null}),J(Oe),M(Fe),F(!!(je!=null&&je.nextCursor)),V((je==null?void 0:je.nextCursor)??null)}catch(we){if(U.current===ve){const Fe=String(we);T(Fe),s==null||s(Fe)}}finally{k(!1)}})();Ne.current.set(X,pe);try{await pe}finally{Ne.current.delete(X)}return U.current===G&&(oe.current=X),pe},[l,A,s]),ht=w.useCallback(async(G,_)=>{Q.current=G;try{await gt(G,_)}finally{Q.current===G&&(Q.current=null)}},[gt]);w.useEffect(()=>{if(!o||!p||S||tt)return;if($.current===p){$.current=null,Z.current=p;return}if(K.current===p){Z.current=p;return}if(Q.current===p){Q.current=null,Z.current=p;return}if(Z.current===p)return;Z.current=p;const G=!ce.current&&!!n&&p===t;let _;G&&n?(_=n,ce.current=!0,console.log("[ChatSessionProvider] Loading thread with checkpoint:",_,r?`(ns: ${r})`:"")):console.log("[ChatSessionProvider] Loading thread with latest checkpoint");const X=`${p}:${_??"latest"}`;oe.current!==X&&ht(p,_)},[o,p,n,r,t,S,tt,ht]);const bt=w.useCallback(async(G,_)=>{const X=U.current;if(!X)return;const te=X;ge(!0);try{const pe=await l.getStateHistory({threadId:te,checkpointId:G,checkpointNs:_??void 0});if(U.current!==te){console.log(`[ChatSessionProvider] Thread changed during checkpoint navigation (was ${te}, now ${U.current}), discarding stale data`);return}const{checkpoints:ve,timeline:we}=dr(pe),Fe=ve.find(Oe=>Oe.checkpointId===G&&(_?Oe.checkpointNs===_:!0));if(!Fe){console.warn("[ChatSessionProvider] Requested checkpoint not found:",{checkpointId:G,checkpointNs:_});return}J(we),M(ve),A(Fe.messages??[],{checkpointId:Fe.checkpointId??null,checkpointNs:Fe.checkpointNs??null})}catch(pe){U.current===te&&(s==null||s(String(pe)))}finally{ge(!1)}},[l,A,s]),St=w.useCallback((G,_)=>{A(I.messages,{checkpointId:G??null,checkpointNs:_??null})},[A,I.messages]),Lt=w.useCallback(async()=>{U.current&&await ht(U.current)},[ht]),Mt=w.useCallback(async()=>{if(!U.current||!j)return;const G=U.current;B(!0);try{const _=await l.getStateHistory({threadId:G,checkpointId:j});if(U.current!==G)return;const{checkpoints:X}=dr(_);if(X.length>0){const te=X[X.length-1];R((te==null?void 0:te.messages)??[]),F(!!(te!=null&&te.nextCursor)),V((te==null?void 0:te.nextCursor)??null)}}catch(_){U.current===G&&(s==null||s(String(_)))}finally{B(!1)}},[l,j,R,s]),et=w.useCallback(async()=>{A([],{}),x(null),Ve(),M([]),J([]),F(!1),V(null),k(!1),ge(!1),B(!1),T(null);try{await l.getAgent("default")}catch(G){console.warn("[ChatSessionProvider] Failed to refetch agent after clearing thread:",G)}},[A,Ve,l]),It=w.useCallback(async(G,_,X)=>{const te=U.current;if(!te)throw new Error("No active thread to handle interrupt");const pe=_?X??!0:!1;try{const ve={threadId:te,checkpointId:I.lastCheckpointId??void 0,checkpointNs:I.lastCheckpointNs??void 0,command:{kind:"resume",value:pe}};Qe(ve)}catch(ve){throw console.error(`[ChatSessionProvider] Failed to handle interrupt ${G}:`,ve),ve}},[I.lastCheckpointId,I.lastCheckpointNs,Qe]);w.useEffect(()=>{re()},[re]),w.useEffect(()=>{a==null||a(p)},[p,a]);const bn=w.useCallback(async(G,_)=>{let X=U.current;const te=(G==null?void 0:G.text)??"",pe=(G==null?void 0:G.attachments)??[],ve=(te==null?void 0:te.trim())??"",we={...(G==null?void 0:G.payload)??{}},Fe=Array.isArray(we.messages)?we.messages:void 0;Fe&&delete we.messages;const Oe=!!(Fe&&Fe.length);if(!X&&!ve&&pe.length===0&&!Oe)return;if(!X){const ie=Math.floor(Date.now()/1e3).toString(16).padStart(8,"0"),be=Array.from({length:4},()=>Math.floor(Math.random()*4294967295).toString(16).padStart(8,"0")).join("").slice(0,16);X=`${ie}${be}`,$.current=X,x(X)}const{contentParts:je,filesInfo:Vt}=await yg(l,pe),En=[...je];ve&&En.push({type:"text",text:te});const ir=_==null?void 0:_.originalMessageId,Ar=!!(_!=null&&_.edit&&ir),fo=!Oe&&En.length>0;let zn=null;fo&&(zn={id:Ar?ir:`msg-${Date.now()}`,role:"user",content:En,createdAt:new Date().toISOString()},Ar||L(zn));const ar=Oe?Fe:zn?[zn]:[],E={...we,...Vt.length?{files_info:Vt}:{}};ar.length?E.messages=ar:"messages"in E||(E.messages=[]);const W={threadId:X,payload:E,checkpointId:(_==null?void 0:_.checkpointId)??I.lastCheckpointId??void 0,checkpointNs:(_==null?void 0:_.checkpointNs)??I.lastCheckpointNs??void 0,edit:!!(_!=null&&_.edit),timelineCheckpoints:q};Qe(W)},[l,L,I,Qe,q]),Ge=w.useMemo(()=>({threads:f,currentThreadId:p,setCurrentThreadId:x,isLoading:m,error:g,actions:{createThread:nt,deleteThread:at,renameThread:Rt,refreshThreads:re}}),[f,p,m,g,nt,at,Rt,re]),Ye=w.useMemo(()=>{const G=I.assemblingId??null;return G?{assemblingMessageId:G}:null},[I.assemblingId]),pt=w.useMemo(()=>({threadId:p,messages:I.messages,interrupt:null,checkpoint:{id:I.lastCheckpointId??null,namespace:I.lastCheckpointNs??null},checkpoints:z,timelineCheckpoints:q,metadata:Ye,isLoading:S,isHistoryLoading:N,isLoadingCheckpoint:se,error:C,hasMore:D,loadOlder:Mt,clearState:et,navigateToCheckpoint:bt,setCurrentCheckpointId:St,returnToLatest:Lt,loadThread:ht,clearThread:et,respondToInterrupt:It,messagePreviews:Y}),[p,I,z,q,S,N,se,C,D,Mt,et,bt,St,Lt,ht,It,Y,Ye]),lt=w.useMemo(()=>({isStreaming:tt,error:it,connectionState:tt?"connected":"idle",submit:bn,send:bn,stop:Ve,setAuthToken:qe}),[tt,it,bn,Ve,qe]);return u.jsx(oc.Provider,{value:Ge,children:u.jsx(sc.Provider,{value:pt,children:u.jsx(ic.Provider,{value:lt,children:e})})})}function _o(){const e=w.useContext(oc);if(!e)throw new Error("useThreads must be used within ChatSessionProvider");return e}function jo(){const e=w.useContext(sc);if(!e)throw new Error("useThreadState must be used within ChatSessionProvider");return e}function ac(){const e=w.useContext(ic);if(!e)throw new Error("useStream must be used within ChatSessionProvider");return e}function Ro({children:e,apiConfig:t,initialThreadId:n=null,initialCheckpointId:r=null,initialCheckpointNs:o=null,autoLoadInitial:s=!0,onError:i,onAuthError:a,onThreadChange:l}){return u.jsx(gg,{apiConfig:t,children:u.jsx(Qg,{initialThreadId:n,initialCheckpointId:r,initialCheckpointNs:o,autoLoadInitial:s,onError:i,onAuthError:a,onThreadChange:l,children:e})})}function ne(...e){return Hh.twMerge(Uh.clsx(e))}const ex=po.cva("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-10 w-10"}},defaultVariants:{variant:"default",size:"default"}}),Xe=v.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?Hn.Slot:"button";return u.jsx(i,{className:ne(ex({variant:t,size:n,className:e})),ref:s,...o})});Xe.displayName="Button";const lc=v.forwardRef(({className:e,...t},n)=>u.jsx("textarea",{className:ne("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",e),ref:n,...t}));lc.displayName="Textarea";function cc({initialValue:e="",editingMessageId:t=null,placeholder:n="Type your message...",isStreaming:r=!1,disabled:o=!1,maxLength:s=2e4,value:i,onValueChange:a,onSend:l,onCancelEdit:c,onStop:d,className:f="",textareaClassName:h="",allowEmptySend:p=!1}){const x=i!==void 0,[m,y]=w.useState(e),g=(x?i:m)??"",[b,S]=w.useTransition(),k=w.useRef(null),C=w.useRef(0),T=w.useRef(null);w.useEffect(()=>{x||(y(e??""),T.current=null,k.current&&(k.current.style.height="auto",k.current.style.height=`${k.current.scrollHeight}px`))},[e,t,x]);const I=w.useCallback(()=>{const B=k.current;B&&(B.style.height="auto",B.style.height=`${B.scrollHeight}px`)},[]);w.useEffect(()=>{I()},[I,g]);const A=w.useCallback((B,{fromUser:j})=>{x||y(B),j&&(a==null||a(B))},[x,a]),R=w.useCallback(async B=>{B&&B.preventDefault();const j=(g??"").trim();if(!j&&!p)return;const V=++C.current;T.current={id:V,shouldClear:!0},S(()=>{var z,M,q;try{const J=l(j);J&&typeof J.then=="function"?J.then(()=>{var se,ge;((se=T.current)==null?void 0:se.id)===V&&T.current.shouldClear&&(x||(y(""),k.current&&(k.current.style.height="auto"),a==null||a(""))),((ge=T.current)==null?void 0:ge.id)===V&&(T.current=null)}).catch(()=>{var se;((se=T.current)==null?void 0:se.id)===V&&(T.current=null)}):(((z=T.current)==null?void 0:z.id)===V&&T.current.shouldClear&&(x||(y(""),k.current&&(k.current.style.height="auto"),a==null||a(""))),((M=T.current)==null?void 0:M.id)===V&&(T.current=null))}catch{((q=T.current)==null?void 0:q.id)===V&&(T.current=null)}})},[g,l,p,x,a]),L=w.useCallback(B=>{const j=B.target.value;A(j,{fromUser:!0}),T.current&&(T.current.shouldClear=!1),k.current&&(k.current.style.height="auto",k.current.style.height=`${k.current.scrollHeight}px`)},[A]),P=w.useCallback(B=>{B.key==="Enter"&&!B.shiftKey?(B.preventDefault(),R()):B.key==="Escape"&&t&&(B.preventDefault(),c==null||c())},[R,t,c]),N=`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${t?"border-[hsl(var(--ring))] bg-[hsl(var(--card))] text-[hsl(var(--card-foreground))] dark:bg-[hsl(var(--card))] dark:text-[hsl(var(--card-foreground))]":""} ${h}`;return u.jsx("form",{onSubmit:B=>void R(B),className:`w-full ${f}`,children:u.jsxs("div",{className:"flex items-end gap-2",children:[u.jsx("div",{className:"flex-1",children:u.jsx(lc,{ref:k,value:g,onChange:L,onKeyDown:P,placeholder:t?"Edit your message...":n,className:N,disabled:o,maxLength:s,rows:1,spellCheck:!1,autoCorrect:"off"})}),u.jsx("div",{children:r?u.jsx(Xe,{type:"button",onClick:()=>{d==null||d()},size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",disabled:o||!d,children:u.jsx(ae.Square,{size:16})}):u.jsx(Xe,{type:"submit",size:"icon",className:"shrink-0",title:t?"Save changes":"Send message",disabled:o||!g.trim()&&!p||b,children:u.jsx(ae.Send,{size:16})})})]})})}const tx=w.memo(cc);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 uc(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=uc(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():uc(e[o],null)}}}}function Be(...e){return v.useCallback(gi(...e),e)}function nx(e,t){const n=v.createContext(t),r=s=>{const{children:i,...a}=s,l=v.useMemo(()=>a,Object.values(a));return u.jsx(n.Provider,{value:l,children:i})};r.displayName=e+"Provider";function o(s){const i=v.useContext(n);if(i)return i;if(t!==void 0)return t;throw new Error(`\`${s}\` must be used within \`${e}\``)}return[r,o]}function Sn(e,t=[]){let n=[];function r(s,i){const a=v.createContext(i),l=n.length;n=[...n,i];const c=f=>{var g;const{scope:h,children:p,...x}=f,m=((g=h==null?void 0:h[e])==null?void 0:g[l])||a,y=v.useMemo(()=>x,Object.values(x));return u.jsx(m.Provider,{value:y,children:p})};c.displayName=s+"Provider";function d(f,h){var m;const p=((m=h==null?void 0:h[e])==null?void 0:m[l])||a,x=v.useContext(p);if(x)return x;if(i!==void 0)return i;throw new Error(`\`${f}\` must be used within \`${s}\``)}return[c,d]}const o=()=>{const s=n.map(i=>v.createContext(i));return function(a){const l=(a==null?void 0:a[e])||s;return v.useMemo(()=>({[`__scope${e}`]:{...a,[e]:l}}),[a,l])}};return o.scopeName=e,[r,rx(o,...t)]}function rx(...e){const t=e[0];if(e.length===1)return t;const n=()=>{const r=e.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(s){const i=r.reduce((a,{useScope:l,scopeName:c})=>{const f=l(s)[`__scope${c}`];return{...a,...f}},{});return v.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}var Tt=globalThis!=null&&globalThis.document?v.useLayoutEffect:()=>{},ox=v[" useInsertionEffect ".trim().toString()]||Tt;function pr({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=sx({defaultProp:t,onChange:n}),a=e!==void 0,l=a?e:o;{const d=v.useRef(e!==void 0);v.useEffect(()=>{const f=d.current;f!==a&&console.warn(`${r} is changing from ${f?"controlled":"uncontrolled"} to ${a?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),d.current=a},[a,r])}const c=v.useCallback(d=>{var f;if(a){const h=ix(d)?d(e):d;h!==e&&((f=i.current)==null||f.call(i,h))}else s(d)},[a,e,s,i]);return[l,c]}function sx({defaultProp:e,onChange:t}){const[n,r]=v.useState(e),o=v.useRef(n),s=v.useRef(t);return ox(()=>{s.current=t},[t]),v.useEffect(()=>{var i;o.current!==n&&((i=s.current)==null||i.call(s,n),o.current=n)},[n,o]),[n,r,s]}function ix(e){return typeof e=="function"}var ax=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],_e=ax.reduce((e,t)=>{const n=Hn.createSlot(`Primitive.${t}`),r=v.forwardRef((o,s)=>{const{asChild:i,...a}=o,l=i?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),u.jsx(l,{...a,ref:s})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function dc(e,t){e&&ho.flushSync(()=>e.dispatchEvent(t))}function xi(e){const t=e+"CollectionProvider",[n,r]=Sn(t),[o,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),i=m=>{const{scope:y,children:g}=m,b=w.useRef(null),S=w.useRef(new Map).current;return u.jsx(o,{scope:y,itemMap:S,collectionRef:b,children:g})};i.displayName=t;const a=e+"CollectionSlot",l=Hn.createSlot(a),c=w.forwardRef((m,y)=>{const{scope:g,children:b}=m,S=s(a,g),k=Be(y,S.collectionRef);return u.jsx(l,{ref:k,children:b})});c.displayName=a;const d=e+"CollectionItemSlot",f="data-radix-collection-item",h=Hn.createSlot(d),p=w.forwardRef((m,y)=>{const{scope:g,children:b,...S}=m,k=w.useRef(null),C=Be(y,k),T=s(d,g);return w.useEffect(()=>(T.itemMap.set(k,{ref:k,...S}),()=>void T.itemMap.delete(k))),u.jsx(h,{[f]:"",ref:C,children:b})});p.displayName=d;function x(m){const y=s(e+"CollectionConsumer",m);return w.useCallback(()=>{const b=y.collectionRef.current;if(!b)return[];const S=Array.from(b.querySelectorAll(`[${f}]`));return Array.from(y.itemMap.values()).sort((T,I)=>S.indexOf(T.ref.current)-S.indexOf(I.ref.current))},[y.collectionRef,y.itemMap])}return[{Provider:i,Slot:c,ItemSlot:p},x,r]}var lx=v.createContext(void 0);function Mo(e){const t=v.useContext(lx);return e||t||"ltr"}function kt(e){const t=v.useRef(e);return v.useEffect(()=>{t.current=e}),v.useMemo(()=>(...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)},[])}function cx(e,t=globalThis==null?void 0:globalThis.document){const n=kt(e);v.useEffect(()=>{const r=o=>{o.key==="Escape"&&n(o)};return t.addEventListener("keydown",r,{capture:!0}),()=>t.removeEventListener("keydown",r,{capture:!0})},[n,t])}var ux="DismissableLayer",yi="dismissableLayer.update",dx="dismissableLayer.pointerDownOutside",fx="dismissableLayer.focusOutside",fc,pc=v.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),Po=v.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:a,...l}=e,c=v.useContext(pc),[d,f]=v.useState(null),h=(d==null?void 0:d.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,p]=v.useState({}),x=Be(t,I=>f(I)),m=Array.from(c.layers),[y]=[...c.layersWithOutsidePointerEventsDisabled].slice(-1),g=m.indexOf(y),b=d?m.indexOf(d):-1,S=c.layersWithOutsidePointerEventsDisabled.size>0,k=b>=g,C=mx(I=>{const A=I.target,R=[...c.branches].some(L=>L.contains(A));!k||R||(o==null||o(I),i==null||i(I),I.defaultPrevented||a==null||a())},h),T=gx(I=>{const A=I.target;[...c.branches].some(L=>L.contains(A))||(s==null||s(I),i==null||i(I),I.defaultPrevented||a==null||a())},h);return cx(I=>{b===c.layers.size-1&&(r==null||r(I),!I.defaultPrevented&&a&&(I.preventDefault(),a()))},h),v.useEffect(()=>{if(d)return n&&(c.layersWithOutsidePointerEventsDisabled.size===0&&(fc=h.body.style.pointerEvents,h.body.style.pointerEvents="none"),c.layersWithOutsidePointerEventsDisabled.add(d)),c.layers.add(d),hc(),()=>{n&&c.layersWithOutsidePointerEventsDisabled.size===1&&(h.body.style.pointerEvents=fc)}},[d,h,n,c]),v.useEffect(()=>()=>{d&&(c.layers.delete(d),c.layersWithOutsidePointerEventsDisabled.delete(d),hc())},[d,c]),v.useEffect(()=>{const I=()=>p({});return document.addEventListener(yi,I),()=>document.removeEventListener(yi,I)},[]),u.jsx(_e.div,{...l,ref:x,style:{pointerEvents:S?k?"auto":"none":void 0,...e.style},onFocusCapture:de(e.onFocusCapture,T.onFocusCapture),onBlurCapture:de(e.onBlurCapture,T.onBlurCapture),onPointerDownCapture:de(e.onPointerDownCapture,C.onPointerDownCapture)})});Po.displayName=ux;var px="DismissableLayerBranch",hx=v.forwardRef((e,t)=>{const n=v.useContext(pc),r=v.useRef(null),o=Be(t,r);return v.useEffect(()=>{const s=r.current;if(s)return n.branches.add(s),()=>{n.branches.delete(s)}},[n.branches]),u.jsx(_e.div,{...e,ref:o})});hx.displayName=px;function mx(e,t=globalThis==null?void 0:globalThis.document){const n=kt(e),r=v.useRef(!1),o=v.useRef(()=>{});return v.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let l=function(){mc(dx,n,c,{discrete:!0})};const c={originalEvent:a};a.pointerType==="touch"?(t.removeEventListener("click",o.current),o.current=l,t.addEventListener("click",o.current,{once:!0})):l()}else t.removeEventListener("click",o.current);r.current=!1},i=window.setTimeout(()=>{t.addEventListener("pointerdown",s)},0);return()=>{window.clearTimeout(i),t.removeEventListener("pointerdown",s),t.removeEventListener("click",o.current)}},[t,n]),{onPointerDownCapture:()=>r.current=!0}}function gx(e,t=globalThis==null?void 0:globalThis.document){const n=kt(e),r=v.useRef(!1);return v.useEffect(()=>{const o=s=>{s.target&&!r.current&&mc(fx,n,{originalEvent:s},{discrete:!1})};return t.addEventListener("focusin",o),()=>t.removeEventListener("focusin",o)},[t,n]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}function hc(){const e=new CustomEvent(yi);document.dispatchEvent(e)}function mc(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?dc(o,s):o.dispatchEvent(s)}var vi=0;function bi(){v.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??gc()),document.body.insertAdjacentElement("beforeend",e[1]??gc()),vi++,()=>{vi===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),vi--}},[])}function gc(){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 wi="focusScope.autoFocusOnMount",Si="focusScope.autoFocusOnUnmount",xc={bubbles:!1,cancelable:!0},xx="FocusScope",Oo=v.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:s,...i}=e,[a,l]=v.useState(null),c=kt(o),d=kt(s),f=v.useRef(null),h=Be(t,m=>l(m)),p=v.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;v.useEffect(()=>{if(r){let m=function(S){if(p.paused||!a)return;const k=S.target;a.contains(k)?f.current=k:Nn(f.current,{select:!0})},y=function(S){if(p.paused||!a)return;const k=S.relatedTarget;k!==null&&(a.contains(k)||Nn(f.current,{select:!0}))},g=function(S){if(document.activeElement===document.body)for(const C of S)C.removedNodes.length>0&&Nn(a)};document.addEventListener("focusin",m),document.addEventListener("focusout",y);const b=new MutationObserver(g);return a&&b.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",m),document.removeEventListener("focusout",y),b.disconnect()}}},[r,a,p.paused]),v.useEffect(()=>{if(a){bc.add(p);const m=document.activeElement;if(!a.contains(m)){const g=new CustomEvent(wi,xc);a.addEventListener(wi,c),a.dispatchEvent(g),g.defaultPrevented||(yx(Cx(yc(a)),{select:!0}),document.activeElement===m&&Nn(a))}return()=>{a.removeEventListener(wi,c),setTimeout(()=>{const g=new CustomEvent(Si,xc);a.addEventListener(Si,d),a.dispatchEvent(g),g.defaultPrevented||Nn(m??document.body,{select:!0}),a.removeEventListener(Si,d),bc.remove(p)},0)}}},[a,c,d,p]);const x=v.useCallback(m=>{if(!n&&!r||p.paused)return;const y=m.key==="Tab"&&!m.altKey&&!m.ctrlKey&&!m.metaKey,g=document.activeElement;if(y&&g){const b=m.currentTarget,[S,k]=vx(b);S&&k?!m.shiftKey&&g===k?(m.preventDefault(),n&&Nn(S,{select:!0})):m.shiftKey&&g===S&&(m.preventDefault(),n&&Nn(k,{select:!0})):g===b&&m.preventDefault()}},[n,r,p.paused]);return u.jsx(_e.div,{tabIndex:-1,...i,ref:h,onKeyDown:x})});Oo.displayName=xx;function yx(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(Nn(r,{select:t}),document.activeElement!==n)return}function vx(e){const t=yc(e),n=vc(t,e),r=vc(t.reverse(),e);return[n,r]}function yc(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 vc(e,t){for(const n of e)if(!bx(n,{upTo:t}))return n}function bx(e,{upTo:t}){if(getComputedStyle(e).visibility==="hidden")return!0;for(;e;){if(t!==void 0&&e===t)return!1;if(getComputedStyle(e).display==="none")return!0;e=e.parentElement}return!1}function wx(e){return e instanceof HTMLInputElement&&"select"in e}function Nn(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&wx(e)&&t&&e.select()}}var bc=Sx();function Sx(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=wc(e,t),e.unshift(t)},remove(t){var n;e=wc(e,t),(n=e[0])==null||n.resume()}}}function wc(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function Cx(e){return e.filter(t=>t.tagName!=="A")}var Tx=v[" useId ".trim().toString()]||(()=>{}),kx=0;function Cn(e){const[t,n]=v.useState(Tx());return Tt(()=>{n(r=>r??String(kx++))},[e]),t?`radix-${t}`:""}const Ix=["top","right","bottom","left"],_n=Math.min,zt=Math.max,Do=Math.round,Lo=Math.floor,dn=e=>({x:e,y:e}),Ex={left:"right",right:"left",bottom:"top",top:"bottom"},Ax={start:"end",end:"start"};function Ci(e,t,n){return zt(e,_n(t,n))}function Tn(e,t){return typeof e=="function"?e(t):e}function kn(e){return e.split("-")[0]}function hr(e){return e.split("-")[1]}function Ti(e){return e==="x"?"y":"x"}function ki(e){return e==="y"?"height":"width"}const Nx=new Set(["top","bottom"]);function fn(e){return Nx.has(kn(e))?"y":"x"}function Ii(e){return Ti(fn(e))}function _x(e,t,n){n===void 0&&(n=!1);const r=hr(e),o=Ii(e),s=ki(o);let i=o==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(i=$o(i)),[i,$o(i)]}function jx(e){const t=$o(e);return[Ei(e),t,Ei(t)]}function Ei(e){return e.replace(/start|end/g,t=>Ax[t])}const Sc=["left","right"],Cc=["right","left"],Rx=["top","bottom"],Mx=["bottom","top"];function Px(e,t,n){switch(e){case"top":case"bottom":return n?t?Cc:Sc:t?Sc:Cc;case"left":case"right":return t?Rx:Mx;default:return[]}}function Ox(e,t,n,r){const o=hr(e);let s=Px(kn(e),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(Ei)))),s}function $o(e){return e.replace(/left|right|bottom|top/g,t=>Ex[t])}function Dx(e){return{top:0,right:0,bottom:0,left:0,...e}}function Tc(e){return typeof e!="number"?Dx(e):{top:e,right:e,bottom:e,left:e}}function Fo(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 kc(e,t,n){let{reference:r,floating:o}=e;const s=fn(t),i=Ii(t),a=ki(i),l=kn(t),c=s==="y",d=r.x+r.width/2-o.width/2,f=r.y+r.height/2-o.height/2,h=r[a]/2-o[a]/2;let p;switch(l){case"top":p={x:d,y:r.y-o.height};break;case"bottom":p={x:d,y:r.y+r.height};break;case"right":p={x:r.x+r.width,y:f};break;case"left":p={x:r.x-o.width,y:f};break;default:p={x:r.x,y:r.y}}switch(hr(t)){case"start":p[i]-=h*(n&&c?-1:1);break;case"end":p[i]+=h*(n&&c?-1:1);break}return p}const Lx=async(e,t,n)=>{const{placement:r="bottom",strategy:o="absolute",middleware:s=[],platform:i}=n,a=s.filter(Boolean),l=await(i.isRTL==null?void 0:i.isRTL(t));let c=await i.getElementRects({reference:e,floating:t,strategy:o}),{x:d,y:f}=kc(c,r,l),h=r,p={},x=0;for(let m=0;m<a.length;m++){const{name:y,fn:g}=a[m],{x:b,y:S,data:k,reset:C}=await g({x:d,y:f,initialPlacement:r,placement:h,strategy:o,middlewareData:p,rects:c,platform:i,elements:{reference:e,floating:t}});d=b??d,f=S??f,p={...p,[y]:{...p[y],...k}},C&&x<=50&&(x++,typeof C=="object"&&(C.placement&&(h=C.placement),C.rects&&(c=C.rects===!0?await i.getElementRects({reference:e,floating:t,strategy:o}):C.rects),{x:d,y:f}=kc(c,h,l)),m=-1)}return{x:d,y:f,placement:h,strategy:o,middlewareData:p}};async function Lr(e,t){var n;t===void 0&&(t={});const{x:r,y:o,platform:s,rects:i,elements:a,strategy:l}=e,{boundary:c="clippingAncestors",rootBoundary:d="viewport",elementContext:f="floating",altBoundary:h=!1,padding:p=0}=Tn(t,e),x=Tc(p),y=a[h?f==="floating"?"reference":"floating":f],g=Fo(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(y)))==null||n?y:y.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(a.floating)),boundary:c,rootBoundary:d,strategy:l})),b=f==="floating"?{x:r,y:o,width:i.floating.width,height:i.floating.height}:i.reference,S=await(s.getOffsetParent==null?void 0:s.getOffsetParent(a.floating)),k=await(s.isElement==null?void 0:s.isElement(S))?await(s.getScale==null?void 0:s.getScale(S))||{x:1,y:1}:{x:1,y:1},C=Fo(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:b,offsetParent:S,strategy:l}):b);return{top:(g.top-C.top+x.top)/k.y,bottom:(C.bottom-g.bottom+x.bottom)/k.y,left:(g.left-C.left+x.left)/k.x,right:(C.right-g.right+x.right)/k.x}}const $x=e=>({name:"arrow",options:e,async fn(t){const{x:n,y:r,placement:o,rects:s,platform:i,elements:a,middlewareData:l}=t,{element:c,padding:d=0}=Tn(e,t)||{};if(c==null)return{};const f=Tc(d),h={x:n,y:r},p=Ii(o),x=ki(p),m=await i.getDimensions(c),y=p==="y",g=y?"top":"left",b=y?"bottom":"right",S=y?"clientHeight":"clientWidth",k=s.reference[x]+s.reference[p]-h[p]-s.floating[x],C=h[p]-s.reference[p],T=await(i.getOffsetParent==null?void 0:i.getOffsetParent(c));let I=T?T[S]:0;(!I||!await(i.isElement==null?void 0:i.isElement(T)))&&(I=a.floating[S]||s.floating[x]);const A=k/2-C/2,R=I/2-m[x]/2-1,L=_n(f[g],R),P=_n(f[b],R),D=L,F=I-m[x]-P,N=I/2-m[x]/2+A,B=Ci(D,N,F),j=!l.arrow&&hr(o)!=null&&N!==B&&s.reference[x]/2-(N<D?L:P)-m[x]/2<0,V=j?N<D?N-D:N-F:0;return{[p]:h[p]+V,data:{[p]:B,centerOffset:N-B-V,...j&&{alignmentOffset:V}},reset:j}}}),Fx=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(t){var n,r;const{placement:o,middlewareData:s,rects:i,initialPlacement:a,platform:l,elements:c}=t,{mainAxis:d=!0,crossAxis:f=!0,fallbackPlacements:h,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:x="none",flipAlignment:m=!0,...y}=Tn(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const g=kn(o),b=fn(a),S=kn(a)===a,k=await(l.isRTL==null?void 0:l.isRTL(c.floating)),C=h||(S||!m?[$o(a)]:jx(a)),T=x!=="none";!h&&T&&C.push(...Ox(a,m,x,k));const I=[a,...C],A=await Lr(t,y),R=[];let L=((r=s.flip)==null?void 0:r.overflows)||[];if(d&&R.push(A[g]),f){const N=_x(o,i,k);R.push(A[N[0]],A[N[1]])}if(L=[...L,{placement:o,overflows:R}],!R.every(N=>N<=0)){var P,D;const N=(((P=s.flip)==null?void 0:P.index)||0)+1,B=I[N];if(B&&(!(f==="alignment"?b!==fn(B):!1)||L.every(z=>fn(z.placement)===b?z.overflows[0]>0:!0)))return{data:{index:N,overflows:L},reset:{placement:B}};let j=(D=L.filter(V=>V.overflows[0]<=0).sort((V,z)=>V.overflows[1]-z.overflows[1])[0])==null?void 0:D.placement;if(!j)switch(p){case"bestFit":{var F;const V=(F=L.filter(z=>{if(T){const M=fn(z.placement);return M===b||M==="y"}return!0}).map(z=>[z.placement,z.overflows.filter(M=>M>0).reduce((M,q)=>M+q,0)]).sort((z,M)=>z[1]-M[1])[0])==null?void 0:F[0];V&&(j=V);break}case"initialPlacement":j=a;break}if(o!==j)return{reset:{placement:j}}}return{}}}};function Ic(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function Ec(e){return Ix.some(t=>e[t]>=0)}const Bx=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n}=t,{strategy:r="referenceHidden",...o}=Tn(e,t);switch(r){case"referenceHidden":{const s=await Lr(t,{...o,elementContext:"reference"}),i=Ic(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:Ec(i)}}}case"escaped":{const s=await Lr(t,{...o,altBoundary:!0}),i=Ic(s,n.floating);return{data:{escapedOffsets:i,escaped:Ec(i)}}}default:return{}}}}},Ac=new Set(["left","top"]);async function zx(e,t){const{placement:n,platform:r,elements:o}=e,s=await(r.isRTL==null?void 0:r.isRTL(o.floating)),i=kn(n),a=hr(n),l=fn(n)==="y",c=Ac.has(i)?-1:1,d=s&&l?-1:1,f=Tn(t,e);let{mainAxis:h,crossAxis:p,alignmentAxis:x}=typeof f=="number"?{mainAxis:f,crossAxis:0,alignmentAxis:null}:{mainAxis:f.mainAxis||0,crossAxis:f.crossAxis||0,alignmentAxis:f.alignmentAxis};return a&&typeof x=="number"&&(p=a==="end"?x*-1:x),l?{x:p*d,y:h*c}:{x:h*c,y:p*d}}const Ux=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 zx(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}}}}},Hx=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(t){const{x:n,y:r,placement:o}=t,{mainAxis:s=!0,crossAxis:i=!1,limiter:a={fn:y=>{let{x:g,y:b}=y;return{x:g,y:b}}},...l}=Tn(e,t),c={x:n,y:r},d=await Lr(t,l),f=fn(kn(o)),h=Ti(f);let p=c[h],x=c[f];if(s){const y=h==="y"?"top":"left",g=h==="y"?"bottom":"right",b=p+d[y],S=p-d[g];p=Ci(b,p,S)}if(i){const y=f==="y"?"top":"left",g=f==="y"?"bottom":"right",b=x+d[y],S=x-d[g];x=Ci(b,x,S)}const m=a.fn({...t,[h]:p,[f]:x});return{...m,data:{x:m.x-n,y:m.y-r,enabled:{[h]:s,[f]:i}}}}}},Wx=function(e){return e===void 0&&(e={}),{options:e,fn(t){const{x:n,y:r,placement:o,rects:s,middlewareData:i}=t,{offset:a=0,mainAxis:l=!0,crossAxis:c=!0}=Tn(e,t),d={x:n,y:r},f=fn(o),h=Ti(f);let p=d[h],x=d[f];const m=Tn(a,t),y=typeof m=="number"?{mainAxis:m,crossAxis:0}:{mainAxis:0,crossAxis:0,...m};if(l){const S=h==="y"?"height":"width",k=s.reference[h]-s.floating[S]+y.mainAxis,C=s.reference[h]+s.reference[S]-y.mainAxis;p<k?p=k:p>C&&(p=C)}if(c){var g,b;const S=h==="y"?"width":"height",k=Ac.has(kn(o)),C=s.reference[f]-s.floating[S]+(k&&((g=i.offset)==null?void 0:g[f])||0)+(k?0:y.crossAxis),T=s.reference[f]+s.reference[S]+(k?0:((b=i.offset)==null?void 0:b[f])||0)-(k?y.crossAxis:0);x<C?x=C:x>T&&(x=T)}return{[h]:p,[f]:x}}}},Vx=function(e){return e===void 0&&(e={}),{name:"size",options:e,async fn(t){var n,r;const{placement:o,rects:s,platform:i,elements:a}=t,{apply:l=()=>{},...c}=Tn(e,t),d=await Lr(t,c),f=kn(o),h=hr(o),p=fn(o)==="y",{width:x,height:m}=s.floating;let y,g;f==="top"||f==="bottom"?(y=f,g=h===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(g=f,y=h==="end"?"top":"bottom");const b=m-d.top-d.bottom,S=x-d.left-d.right,k=_n(m-d[y],b),C=_n(x-d[g],S),T=!t.middlewareData.shift;let I=k,A=C;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(A=S),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(I=b),T&&!h){const L=zt(d.left,0),P=zt(d.right,0),D=zt(d.top,0),F=zt(d.bottom,0);p?A=x-2*(L!==0||P!==0?L+P:zt(d.left,d.right)):I=m-2*(D!==0||F!==0?D+F:zt(d.top,d.bottom))}await l({...t,availableWidth:A,availableHeight:I});const R=await i.getDimensions(a.floating);return x!==R.width||m!==R.height?{reset:{rects:!0}}:{}}}};function Bo(){return typeof window<"u"}function mr(e){return Nc(e)?(e.nodeName||"").toLowerCase():"#document"}function Ut(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function pn(e){var t;return(t=(Nc(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function Nc(e){return Bo()?e instanceof Node||e instanceof Ut(e).Node:!1}function rn(e){return Bo()?e instanceof Element||e instanceof Ut(e).Element:!1}function hn(e){return Bo()?e instanceof HTMLElement||e instanceof Ut(e).HTMLElement:!1}function _c(e){return!Bo()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Ut(e).ShadowRoot}const Kx=new Set(["inline","contents"]);function $r(e){const{overflow:t,overflowX:n,overflowY:r,display:o}=on(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!Kx.has(o)}const qx=new Set(["table","td","th"]);function Gx(e){return qx.has(mr(e))}const Yx=[":popover-open",":modal"];function zo(e){return Yx.some(t=>{try{return e.matches(t)}catch{return!1}})}const Xx=["transform","translate","scale","rotate","perspective"],Jx=["transform","translate","scale","rotate","perspective","filter"],Zx=["paint","layout","strict","content"];function Ai(e){const t=Ni(),n=rn(e)?on(e):e;return Xx.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)||Jx.some(r=>(n.willChange||"").includes(r))||Zx.some(r=>(n.contain||"").includes(r))}function Qx(e){let t=jn(e);for(;hn(t)&&!gr(t);){if(Ai(t))return t;if(zo(t))return null;t=jn(t)}return null}function Ni(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const ey=new Set(["html","body","#document"]);function gr(e){return ey.has(mr(e))}function on(e){return Ut(e).getComputedStyle(e)}function Uo(e){return rn(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function jn(e){if(mr(e)==="html")return e;const t=e.assignedSlot||e.parentNode||_c(e)&&e.host||pn(e);return _c(t)?t.host:t}function jc(e){const t=jn(e);return gr(t)?e.ownerDocument?e.ownerDocument.body:e.body:hn(t)&&$r(t)?t:jc(t)}function Fr(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const o=jc(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=Ut(o);if(s){const a=_i(i);return t.concat(i,i.visualViewport||[],$r(o)?o:[],a&&n?Fr(a):[])}return t.concat(o,Fr(o,[],n))}function _i(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function Rc(e){const t=on(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const o=hn(e),s=o?e.offsetWidth:n,i=o?e.offsetHeight:r,a=Do(n)!==s||Do(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function ji(e){return rn(e)?e:e.contextElement}function xr(e){const t=ji(e);if(!hn(t))return dn(1);const n=t.getBoundingClientRect(),{width:r,height:o,$:s}=Rc(t);let i=(s?Do(n.width):n.width)/r,a=(s?Do(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const ty=dn(0);function Mc(e){const t=Ut(e);return!Ni()||!t.visualViewport?ty:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function ny(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==Ut(e)?!1:t}function qn(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const o=e.getBoundingClientRect(),s=ji(e);let i=dn(1);t&&(r?rn(r)&&(i=xr(r)):i=xr(e));const a=ny(s,n,r)?Mc(s):dn(0);let l=(o.left+a.x)/i.x,c=(o.top+a.y)/i.y,d=o.width/i.x,f=o.height/i.y;if(s){const h=Ut(s),p=r&&rn(r)?Ut(r):r;let x=h,m=_i(x);for(;m&&r&&p!==x;){const y=xr(m),g=m.getBoundingClientRect(),b=on(m),S=g.left+(m.clientLeft+parseFloat(b.paddingLeft))*y.x,k=g.top+(m.clientTop+parseFloat(b.paddingTop))*y.y;l*=y.x,c*=y.y,d*=y.x,f*=y.y,l+=S,c+=k,x=Ut(m),m=_i(x)}}return Fo({width:d,height:f,x:l,y:c})}function Ho(e,t){const n=Uo(e).scrollLeft;return t?t.left+n:qn(pn(e)).left+n}function Pc(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-Ho(e,n),o=n.top+t.scrollTop;return{x:r,y:o}}function ry(e){let{elements:t,rect:n,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=pn(r),a=t?zo(t.floating):!1;if(r===i||a&&s)return n;let l={scrollLeft:0,scrollTop:0},c=dn(1);const d=dn(0),f=hn(r);if((f||!f&&!s)&&((mr(r)!=="body"||$r(i))&&(l=Uo(r)),hn(r))){const p=qn(r);c=xr(r),d.x=p.x+r.clientLeft,d.y=p.y+r.clientTop}const h=i&&!f&&!s?Pc(i,l):dn(0);return{width:n.width*c.x,height:n.height*c.y,x:n.x*c.x-l.scrollLeft*c.x+d.x+h.x,y:n.y*c.y-l.scrollTop*c.y+d.y+h.y}}function oy(e){return Array.from(e.getClientRects())}function sy(e){const t=pn(e),n=Uo(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+Ho(e);const a=-n.scrollTop;return on(r).direction==="rtl"&&(i+=zt(t.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}const Oc=25;function iy(e,t){const n=Ut(e),r=pn(e),o=n.visualViewport;let s=r.clientWidth,i=r.clientHeight,a=0,l=0;if(o){s=o.width,i=o.height;const d=Ni();(!d||d&&t==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}const c=Ho(r);if(c<=0){const d=r.ownerDocument,f=d.body,h=getComputedStyle(f),p=d.compatMode==="CSS1Compat"&&parseFloat(h.marginLeft)+parseFloat(h.marginRight)||0,x=Math.abs(r.clientWidth-f.clientWidth-p);x<=Oc&&(s-=x)}else c<=Oc&&(s+=c);return{width:s,height:i,x:a,y:l}}const ay=new Set(["absolute","fixed"]);function ly(e,t){const n=qn(e,!0,t==="fixed"),r=n.top+e.clientTop,o=n.left+e.clientLeft,s=hn(e)?xr(e):dn(1),i=e.clientWidth*s.x,a=e.clientHeight*s.y,l=o*s.x,c=r*s.y;return{width:i,height:a,x:l,y:c}}function Dc(e,t,n){let r;if(t==="viewport")r=iy(e,n);else if(t==="document")r=sy(pn(e));else if(rn(t))r=ly(t,n);else{const o=Mc(e);r={x:t.x-o.x,y:t.y-o.y,width:t.width,height:t.height}}return Fo(r)}function Lc(e,t){const n=jn(e);return n===t||!rn(n)||gr(n)?!1:on(n).position==="fixed"||Lc(n,t)}function cy(e,t){const n=t.get(e);if(n)return n;let r=Fr(e,[],!1).filter(a=>rn(a)&&mr(a)!=="body"),o=null;const s=on(e).position==="fixed";let i=s?jn(e):e;for(;rn(i)&&!gr(i);){const a=on(i),l=Ai(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&ay.has(o.position)||$r(i)&&!l&&Lc(e,i))?r=r.filter(d=>d!==i):o=a,i=jn(i)}return t.set(e,r),r}function uy(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i=[...n==="clippingAncestors"?zo(t)?[]:cy(t,this._c):[].concat(n),r],a=i[0],l=i.reduce((c,d)=>{const f=Dc(t,d,o);return c.top=zt(f.top,c.top),c.right=_n(f.right,c.right),c.bottom=_n(f.bottom,c.bottom),c.left=zt(f.left,c.left),c},Dc(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}=Rc(e);return{width:t,height:n}}function fy(e,t,n){const r=hn(t),o=pn(t),s=n==="fixed",i=qn(e,!0,s,t);let a={scrollLeft:0,scrollTop:0};const l=dn(0);function c(){l.x=Ho(o)}if(r||!r&&!s)if((mr(t)!=="body"||$r(o))&&(a=Uo(t)),r){const p=qn(t,!0,s,t);l.x=p.x+t.clientLeft,l.y=p.y+t.clientTop}else o&&c();s&&!r&&o&&c();const d=o&&!r&&!s?Pc(o,a):dn(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 Ri(e){return on(e).position==="static"}function $c(e,t){if(!hn(e)||on(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return pn(e)===n&&(n=n.ownerDocument.body),n}function Fc(e,t){const n=Ut(e);if(zo(e))return n;if(!hn(e)){let o=jn(e);for(;o&&!gr(o);){if(rn(o)&&!Ri(o))return o;o=jn(o)}return n}let r=$c(e,t);for(;r&&Gx(r)&&Ri(r);)r=$c(r,t);return r&&gr(r)&&Ri(r)&&!Ai(r)?n:r||Qx(e)||n}const py=async function(e){const t=this.getOffsetParent||Fc,n=this.getDimensions,r=await n(e.floating);return{reference:fy(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function hy(e){return on(e).direction==="rtl"}const my={convertOffsetParentRelativeRectToViewportRelativeRect:ry,getDocumentElement:pn,getClippingRect:uy,getOffsetParent:Fc,getElementRects:py,getClientRects:oy,getDimensions:dy,getScale:xr,isElement:rn,isRTL:hy};function Bc(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function gy(e,t){let n=null,r;const o=pn(e);function s(){var a;clearTimeout(r),(a=n)==null||a.disconnect(),n=null}function i(a,l){a===void 0&&(a=!1),l===void 0&&(l=1),s();const c=e.getBoundingClientRect(),{left:d,top:f,width:h,height:p}=c;if(a||t(),!h||!p)return;const x=Lo(f),m=Lo(o.clientWidth-(d+h)),y=Lo(o.clientHeight-(f+p)),g=Lo(d),S={rootMargin:-x+"px "+-m+"px "+-y+"px "+-g+"px",threshold:zt(0,_n(1,l))||1};let k=!0;function C(T){const I=T[0].intersectionRatio;if(I!==l){if(!k)return i();I?i(!1,I):r=setTimeout(()=>{i(!1,1e-7)},1e3)}I===1&&!Bc(c,e.getBoundingClientRect())&&i(),k=!1}try{n=new IntersectionObserver(C,{...S,root:o.ownerDocument})}catch{n=new IntersectionObserver(C,S)}n.observe(e)}return i(!0),s}function xy(e,t,n,r){r===void 0&&(r={});const{ancestorScroll:o=!0,ancestorResize:s=!0,elementResize:i=typeof ResizeObserver=="function",layoutShift:a=typeof IntersectionObserver=="function",animationFrame:l=!1}=r,c=ji(e),d=o||s?[...c?Fr(c):[],...Fr(t)]:[];d.forEach(g=>{o&&g.addEventListener("scroll",n,{passive:!0}),s&&g.addEventListener("resize",n)});const f=c&&a?gy(c,n):null;let h=-1,p=null;i&&(p=new ResizeObserver(g=>{let[b]=g;b&&b.target===c&&p&&(p.unobserve(t),cancelAnimationFrame(h),h=requestAnimationFrame(()=>{var S;(S=p)==null||S.observe(t)})),n()}),c&&!l&&p.observe(c),p.observe(t));let x,m=l?qn(e):null;l&&y();function y(){const g=qn(e);m&&!Bc(m,g)&&n(),m=g,x=requestAnimationFrame(y)}return n(),()=>{var g;d.forEach(b=>{o&&b.removeEventListener("scroll",n),s&&b.removeEventListener("resize",n)}),f==null||f(),(g=p)==null||g.disconnect(),p=null,l&&cancelAnimationFrame(x)}}const yy=Ux,vy=Hx,by=Fx,wy=Vx,Sy=Bx,zc=$x,Cy=Wx,Ty=(e,t,n)=>{const r=new Map,o={platform:my,...n},s={...o.platform,_c:r};return Lx(e,t,{...o,platform:s})};var ky=typeof document<"u",Iy=function(){},Wo=ky?w.useLayoutEffect:Iy;function Vo(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(!Vo(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)&&!Vo(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function Uc(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function Hc(e,t){const n=Uc(e);return Math.round(t*n)/n}function Mi(e){const t=v.useRef(e);return Wo(()=>{t.current=e}),t}function Ey(e){e===void 0&&(e={});const{placement:t="bottom",strategy:n="absolute",middleware:r=[],platform:o,elements:{reference:s,floating:i}={},transform:a=!0,whileElementsMounted:l,open:c}=e,[d,f]=v.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[h,p]=v.useState(r);Vo(h,r)||p(r);const[x,m]=v.useState(null),[y,g]=v.useState(null),b=v.useCallback(z=>{z!==T.current&&(T.current=z,m(z))},[]),S=v.useCallback(z=>{z!==I.current&&(I.current=z,g(z))},[]),k=s||x,C=i||y,T=v.useRef(null),I=v.useRef(null),A=v.useRef(d),R=l!=null,L=Mi(l),P=Mi(o),D=Mi(c),F=v.useCallback(()=>{if(!T.current||!I.current)return;const z={placement:t,strategy:n,middleware:h};P.current&&(z.platform=P.current),Ty(T.current,I.current,z).then(M=>{const q={...M,isPositioned:D.current!==!1};N.current&&!Vo(A.current,q)&&(A.current=q,ho.flushSync(()=>{f(q)}))})},[h,t,n,P,D]);Wo(()=>{c===!1&&A.current.isPositioned&&(A.current.isPositioned=!1,f(z=>({...z,isPositioned:!1})))},[c]);const N=v.useRef(!1);Wo(()=>(N.current=!0,()=>{N.current=!1}),[]),Wo(()=>{if(k&&(T.current=k),C&&(I.current=C),k&&C){if(L.current)return L.current(k,C,F);F()}},[k,C,F,L,R]);const B=v.useMemo(()=>({reference:T,floating:I,setReference:b,setFloating:S}),[b,S]),j=v.useMemo(()=>({reference:k,floating:C}),[k,C]),V=v.useMemo(()=>{const z={position:n,left:0,top:0};if(!j.floating)return z;const M=Hc(j.floating,d.x),q=Hc(j.floating,d.y);return a?{...z,transform:"translate("+M+"px, "+q+"px)",...Uc(j.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:M,top:q}},[n,a,j.floating,d.x,d.y]);return v.useMemo(()=>({...d,update:F,refs:B,elements:j,floatingStyles:V}),[d,F,B,j,V])}const Ay=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?zc({element:r.current,padding:o}).fn(n):{}:r?zc({element:r,padding:o}).fn(n):{}}}},Ny=(e,t)=>({...yy(e),options:[e,t]}),_y=(e,t)=>({...vy(e),options:[e,t]}),jy=(e,t)=>({...Cy(e),options:[e,t]}),Ry=(e,t)=>({...by(e),options:[e,t]}),My=(e,t)=>({...wy(e),options:[e,t]}),Py=(e,t)=>({...Sy(e),options:[e,t]}),Oy=(e,t)=>({...Ay(e),options:[e,t]});var Dy="Arrow",Wc=v.forwardRef((e,t)=>{const{children:n,width:r=10,height:o=5,...s}=e;return u.jsx(_e.svg,{...s,ref:t,width:r,height:o,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:e.asChild?n:u.jsx("polygon",{points:"0,0 30,0 15,10"})})});Wc.displayName=Dy;var Ly=Wc;function Vc(e){const[t,n]=v.useState(void 0);return Tt(()=>{if(e){n({width:e.offsetWidth,height:e.offsetHeight});const r=new ResizeObserver(o=>{if(!Array.isArray(o)||!o.length)return;const s=o[0];let i,a;if("borderBoxSize"in s){const l=s.borderBoxSize,c=Array.isArray(l)?l[0]:l;i=c.inlineSize,a=c.blockSize}else i=e.offsetWidth,a=e.offsetHeight;n({width:i,height:a})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else n(void 0)},[e]),t}var Pi="Popper",[Kc,Ko]=Sn(Pi),[$y,qc]=Kc(Pi),Gc=e=>{const{__scopePopper:t,children:n}=e,[r,o]=v.useState(null);return u.jsx($y,{scope:t,anchor:r,onAnchorChange:o,children:n})};Gc.displayName=Pi;var Yc="PopperAnchor",Xc=v.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...o}=e,s=qc(Yc,n),i=v.useRef(null),a=Be(t,i),l=v.useRef(null);return v.useEffect(()=>{const c=l.current;l.current=(r==null?void 0:r.current)||i.current,c!==l.current&&s.onAnchorChange(l.current)}),r?null:u.jsx(_e.div,{...o,ref:a})});Xc.displayName=Yc;var Oi="PopperContent",[Fy,By]=Kc(Oi),Jc=v.forwardRef((e,t)=>{var Z,$,K,Q,ce,oe;const{__scopePopper:n,side:r="bottom",sideOffset:o=0,align:s="center",alignOffset:i=0,arrowPadding:a=0,avoidCollisions:l=!0,collisionBoundary:c=[],collisionPadding:d=0,sticky:f="partial",hideWhenDetached:h=!1,updatePositionStrategy:p="optimized",onPlaced:x,...m}=e,y=qc(Oi,n),[g,b]=v.useState(null),S=Be(t,Ne=>b(Ne)),[k,C]=v.useState(null),T=Vc(k),I=(T==null?void 0:T.width)??0,A=(T==null?void 0:T.height)??0,R=r+(s!=="center"?"-"+s:""),L=typeof d=="number"?d:{top:0,right:0,bottom:0,left:0,...d},P=Array.isArray(c)?c:[c],D=P.length>0,F={padding:L,boundary:P.filter(Uy),altBoundary:D},{refs:N,floatingStyles:B,placement:j,isPositioned:V,middlewareData:z}=Ey({strategy:"fixed",placement:R,whileElementsMounted:(...Ne)=>xy(...Ne,{animationFrame:p==="always"}),elements:{reference:y.anchor},middleware:[Ny({mainAxis:o+A,alignmentAxis:i}),l&&_y({mainAxis:!0,crossAxis:!1,limiter:f==="partial"?jy():void 0,...F}),l&&Ry({...F}),My({...F,apply:({elements:Ne,rects:Ue,availableWidth:re,availableHeight:xe})=>{const{width:Pe,height:Ze}=Ue.reference,Qe=Ne.floating.style;Qe.setProperty("--radix-popper-available-width",`${re}px`),Qe.setProperty("--radix-popper-available-height",`${xe}px`),Qe.setProperty("--radix-popper-anchor-width",`${Pe}px`),Qe.setProperty("--radix-popper-anchor-height",`${Ze}px`)}}),k&&Oy({element:k,padding:a}),Hy({arrowWidth:I,arrowHeight:A}),h&&Py({strategy:"referenceHidden",...F})]}),[M,q]=eu(j),J=kt(x);Tt(()=>{V&&(J==null||J())},[V,J]);const se=(Z=z.arrow)==null?void 0:Z.x,ge=($=z.arrow)==null?void 0:$.y,Ee=((K=z.arrow)==null?void 0:K.centerOffset)!==0,[Y,U]=v.useState();return Tt(()=>{g&&U(window.getComputedStyle(g).zIndex)},[g]),u.jsx("div",{ref:N.setFloating,"data-radix-popper-content-wrapper":"",style:{...B,transform:V?B.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:Y,"--radix-popper-transform-origin":[(Q=z.transformOrigin)==null?void 0:Q.x,(ce=z.transformOrigin)==null?void 0:ce.y].join(" "),...((oe=z.hide)==null?void 0:oe.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:u.jsx(Fy,{scope:n,placedSide:M,onArrowChange:C,arrowX:se,arrowY:ge,shouldHideArrow:Ee,children:u.jsx(_e.div,{"data-side":M,"data-align":q,...m,ref:S,style:{...m.style,animation:V?void 0:"none"}})})})});Jc.displayName=Oi;var Zc="PopperArrow",zy={top:"bottom",right:"left",bottom:"top",left:"right"},Qc=v.forwardRef(function(t,n){const{__scopePopper:r,...o}=t,s=By(Zc,r),i=zy[s.placedSide];return u.jsx("span",{ref:s.onArrowChange,style:{position:"absolute",left:s.arrowX,top:s.arrowY,[i]:0,transformOrigin:{top:"",right:"0 0",bottom:"center 0",left:"100% 0"}[s.placedSide],transform:{top:"translateY(100%)",right:"translateY(50%) rotate(90deg) translateX(-50%)",bottom:"rotate(180deg)",left:"translateY(50%) rotate(-90deg) translateX(50%)"}[s.placedSide],visibility:s.shouldHideArrow?"hidden":void 0},children:u.jsx(Ly,{...o,ref:n,style:{...o.style,display:"block"}})})});Qc.displayName=Zc;function Uy(e){return e!==null}var Hy=e=>({name:"transformOrigin",options:e,fn(t){var y,g,b;const{placement:n,rects:r,middlewareData:o}=t,i=((y=o.arrow)==null?void 0:y.centerOffset)!==0,a=i?0:e.arrowWidth,l=i?0:e.arrowHeight,[c,d]=eu(n),f={start:"0%",center:"50%",end:"100%"}[d],h=(((g=o.arrow)==null?void 0:g.x)??0)+a/2,p=(((b=o.arrow)==null?void 0:b.y)??0)+l/2;let x="",m="";return c==="bottom"?(x=i?f:`${h}px`,m=`${-l}px`):c==="top"?(x=i?f:`${h}px`,m=`${r.floating.height+l}px`):c==="right"?(x=`${-l}px`,m=i?f:`${p}px`):c==="left"&&(x=`${r.floating.width+l}px`,m=i?f:`${p}px`),{data:{x,y:m}}}});function eu(e){const[t,n="center"]=e.split("-");return[t,n]}var tu=Gc,nu=Xc,ru=Jc,ou=Qc,Wy="Portal",qo=v.forwardRef((e,t)=>{var a;const{container:n,...r}=e,[o,s]=v.useState(!1);Tt(()=>s(!0),[]);const i=n||o&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?Gs.createPortal(u.jsx(_e.div,{...r,ref:t}),i):null});qo.displayName=Wy;function Vy(e,t){return v.useReducer((n,r)=>t[n][r]??n,e)}var Yt=e=>{const{present:t,children:n}=e,r=Ky(t),o=typeof n=="function"?n({present:r.isPresent}):v.Children.only(n),s=Be(r.ref,qy(o));return typeof n=="function"||r.isPresent?v.cloneElement(o,{ref:s}):null};Yt.displayName="Presence";function Ky(e){const[t,n]=v.useState(),r=v.useRef(null),o=v.useRef(e),s=v.useRef("none"),i=e?"mounted":"unmounted",[a,l]=Vy(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return v.useEffect(()=>{const c=Go(r.current);s.current=a==="mounted"?c:"none"},[a]),Tt(()=>{const c=r.current,d=o.current;if(d!==e){const h=s.current,p=Go(c);e?l("MOUNT"):p==="none"||(c==null?void 0:c.display)==="none"?l("UNMOUNT"):l(d&&h!==p?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,l]),Tt(()=>{if(t){let c;const d=t.ownerDocument.defaultView??window,f=p=>{const m=Go(r.current).includes(CSS.escape(p.animationName));if(p.target===t&&m&&(l("ANIMATION_END"),!o.current)){const y=t.style.animationFillMode;t.style.animationFillMode="forwards",c=d.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=y)})}},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(c),t.removeEventListener("animationstart",h),t.removeEventListener("animationcancel",f),t.removeEventListener("animationend",f)}}else l("ANIMATION_END")},[t,l]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:v.useCallback(c=>{r.current=c?getComputedStyle(c):null,n(c)},[])}}function Go(e){return(e==null?void 0:e.animationName)||"none"}function qy(e){var r,o;let t=(r=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:r.get,n=t&&"isReactWarning"in t&&t.isReactWarning;return n?e.ref:(t=(o=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:o.get,n=t&&"isReactWarning"in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}var Di="rovingFocusGroup.onEntryFocus",Gy={bubbles:!1,cancelable:!0},Br="RovingFocusGroup",[Li,su,Yy]=xi(Br),[Xy,iu]=Sn(Br,[Yy]),[Jy,Zy]=Xy(Br),au=v.forwardRef((e,t)=>u.jsx(Li.Provider,{scope:e.__scopeRovingFocusGroup,children:u.jsx(Li.Slot,{scope:e.__scopeRovingFocusGroup,children:u.jsx(Qy,{...e,ref:t})})}));au.displayName=Br;var Qy=v.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:o=!1,dir:s,currentTabStopId:i,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:l,onEntryFocus:c,preventScrollOnEntryFocus:d=!1,...f}=e,h=v.useRef(null),p=Be(t,h),x=Mo(s),[m,y]=pr({prop:i,defaultProp:a??null,onChange:l,caller:Br}),[g,b]=v.useState(!1),S=kt(c),k=su(n),C=v.useRef(!1),[T,I]=v.useState(0);return v.useEffect(()=>{const A=h.current;if(A)return A.addEventListener(Di,S),()=>A.removeEventListener(Di,S)},[S]),u.jsx(Jy,{scope:n,orientation:r,dir:x,loop:o,currentTabStopId:m,onItemFocus:v.useCallback(A=>y(A),[y]),onItemShiftTab:v.useCallback(()=>b(!0),[]),onFocusableItemAdd:v.useCallback(()=>I(A=>A+1),[]),onFocusableItemRemove:v.useCallback(()=>I(A=>A-1),[]),children:u.jsx(_e.div,{tabIndex:g||T===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 R=!C.current;if(A.target===A.currentTarget&&R&&!g){const L=new CustomEvent(Di,Gy);if(A.currentTarget.dispatchEvent(L),!L.defaultPrevented){const P=k().filter(j=>j.focusable),D=P.find(j=>j.active),F=P.find(j=>j.id===m),B=[D,F,...P].filter(Boolean).map(j=>j.ref.current);uu(B,d)}}C.current=!1}),onBlur:de(e.onBlur,()=>b(!1))})})}),lu="RovingFocusGroupItem",cu=v.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:o=!1,tabStopId:s,children:i,...a}=e,l=Cn(),c=s||l,d=Zy(lu,n),f=d.currentTabStopId===c,h=su(n),{onFocusableItemAdd:p,onFocusableItemRemove:x,currentTabStopId:m}=d;return v.useEffect(()=>{if(r)return p(),()=>x()},[r,p,x]),u.jsx(Li.ItemSlot,{scope:n,id:c,focusable:r,active:o,children:u.jsx(_e.span,{tabIndex:f?0:-1,"data-orientation":d.orientation,...a,ref:t,onMouseDown:de(e.onMouseDown,y=>{r?d.onItemFocus(c):y.preventDefault()}),onFocus:de(e.onFocus,()=>d.onItemFocus(c)),onKeyDown:de(e.onKeyDown,y=>{if(y.key==="Tab"&&y.shiftKey){d.onItemShiftTab();return}if(y.target!==y.currentTarget)return;const g=nv(y,d.orientation,d.dir);if(g!==void 0){if(y.metaKey||y.ctrlKey||y.altKey||y.shiftKey)return;y.preventDefault();let S=h().filter(k=>k.focusable).map(k=>k.ref.current);if(g==="last")S.reverse();else if(g==="prev"||g==="next"){g==="prev"&&S.reverse();const k=S.indexOf(y.currentTarget);S=d.loop?rv(S,k+1):S.slice(k+1)}setTimeout(()=>uu(S))}}),children:typeof i=="function"?i({isCurrentTabStop:f,hasTabStop:m!=null}):i})})});cu.displayName=lu;var ev={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function tv(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function nv(e,t,n){const r=tv(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return ev[r]}function uu(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function rv(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var ov=au,sv=cu,iv=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},yr=new WeakMap,Yo=new WeakMap,Xo={},$i=0,du=function(e){return e&&(e.host||du(e.parentNode))},av=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=du(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})},lv=function(e,t,n,r){var o=av(t,Array.isArray(e)?e:[e]);Xo[n]||(Xo[n]=new WeakMap);var s=Xo[n],i=[],a=new Set,l=new Set(o),c=function(f){!f||a.has(f)||(a.add(f),c(f.parentNode))};o.forEach(c);var d=function(f){!f||l.has(f)||Array.prototype.forEach.call(f.children,function(h){if(a.has(h))d(h);else try{var p=h.getAttribute(r),x=p!==null&&p!=="false",m=(yr.get(h)||0)+1,y=(s.get(h)||0)+1;yr.set(h,m),s.set(h,y),i.push(h),m===1&&x&&Yo.set(h,!0),y===1&&h.setAttribute(n,"true"),x||h.setAttribute(r,"true")}catch(g){console.error("aria-hidden: cannot operate on ",h,g)}})};return d(t),a.clear(),$i++,function(){i.forEach(function(f){var h=yr.get(f)-1,p=s.get(f)-1;yr.set(f,h),s.set(f,p),h||(Yo.has(f)||f.removeAttribute(r),Yo.delete(f)),p||f.removeAttribute(n)}),$i--,$i||(yr=new WeakMap,yr=new WeakMap,Yo=new WeakMap,Xo={})}},Fi=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),o=iv(e);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live], script"))),lv(r,o,n,"aria-hidden")):function(){return null}},mn=function(){return mn=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},mn.apply(this,arguments)};function fu(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 cv(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 Jo="right-scroll-bar-position",Zo="width-before-scroll-bar",uv="with-scroll-bars-hidden",dv="--removed-body-scroll-bar-size";function Bi(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function fv(e,t){var n=w.useState(function(){return{value:e,callback:t,facade:{get current(){return n.value},set current(r){var o=n.value;o!==r&&(n.value=r,n.callback(r,o))}}}})[0];return n.callback=t,n.facade}var pv=typeof window<"u"?v.useLayoutEffect:v.useEffect,pu=new WeakMap;function hv(e,t){var n=fv(null,function(r){return e.forEach(function(o){return Bi(o,r)})});return pv(function(){var r=pu.get(n);if(r){var o=new Set(r),s=new Set(e),i=n.current;o.forEach(function(a){s.has(a)||Bi(a,null)}),s.forEach(function(a){o.has(a)||Bi(a,i)})}pu.set(n,e)},[e]),n}function mv(e){return e}function gv(e,t){t===void 0&&(t=mv);var n=[],r=!1,o={read:function(){if(r)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return n.length?n[n.length-1]:e},useMedium:function(s){var i=t(s,r);return n.push(i),function(){n=n.filter(function(a){return a!==i})}},assignSyncMedium:function(s){for(r=!0;n.length;){var i=n;n=[],i.forEach(s)}n={push:function(a){return s(a)},filter:function(){return n}}},assignMedium:function(s){r=!0;var i=[];if(n.length){var a=n;n=[],a.forEach(s),i=n}var l=function(){var d=i;i=[],d.forEach(s)},c=function(){return Promise.resolve().then(l)};c(),n={push:function(d){i.push(d),c()},filter:function(d){return i=i.filter(d),n}}}};return o}function xv(e){e===void 0&&(e={});var t=gv(null);return t.options=mn({async:!0,ssr:!1},e),t}var hu=function(e){var t=e.sideCar,n=fu(e,["sideCar"]);if(!t)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=t.read();if(!r)throw new Error("Sidecar medium not found");return v.createElement(r,mn({},n))};hu.isSideCarExport=!0;function yv(e,t){return e.useMedium(t),hu}var mu=xv(),zi=function(){},Qo=v.forwardRef(function(e,t){var n=v.useRef(null),r=v.useState({onScrollCapture:zi,onWheelCapture:zi,onTouchMoveCapture:zi}),o=r[0],s=r[1],i=e.forwardProps,a=e.children,l=e.className,c=e.removeScrollBar,d=e.enabled,f=e.shards,h=e.sideCar,p=e.noRelative,x=e.noIsolation,m=e.inert,y=e.allowPinchZoom,g=e.as,b=g===void 0?"div":g,S=e.gapMode,k=fu(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),C=h,T=hv([n,t]),I=mn(mn({},k),o);return v.createElement(v.Fragment,null,d&&v.createElement(C,{sideCar:mu,removeScrollBar:c,shards:f,noRelative:p,noIsolation:x,inert:m,setCallbacks:s,allowPinchZoom:!!y,lockRef:n,gapMode:S}),i?v.cloneElement(v.Children.only(a),mn(mn({},I),{ref:T})):v.createElement(b,mn({},I,{className:l,ref:T}),a))});Qo.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},Qo.classNames={fullWidth:Zo,zeroRight:Jo};var vv=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function bv(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=vv();return t&&e.setAttribute("nonce",t),e}function wv(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function Sv(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var Cv=function(){var e=0,t=null;return{add:function(n){e==0&&(t=bv())&&(wv(t,n),Sv(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},Tv=function(){var e=Cv();return function(t,n){v.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},gu=function(){var e=Tv(),t=function(n){var r=n.styles,o=n.dynamic;return e(r,o),null};return t},kv={left:0,top:0,right:0,gap:0},Ui=function(e){return parseInt(e||"",10)||0},Iv=function(e){var t=window.getComputedStyle(document.body),n=t[e==="padding"?"paddingLeft":"marginLeft"],r=t[e==="padding"?"paddingTop":"marginTop"],o=t[e==="padding"?"paddingRight":"marginRight"];return[Ui(n),Ui(r),Ui(o)]},Ev=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return kv;var t=Iv(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])}},Av=gu(),vr="data-scroll-locked",Nv=function(e,t,n,r){var o=e.left,s=e.top,i=e.right,a=e.gap;return n===void 0&&(n="margin"),`
|
|
39
39
|
.`.concat(uv,` {
|
|
40
40
|
overflow: hidden `).concat(r,`;
|
|
41
41
|
padding-right: `).concat(a,"px ").concat(r,`;
|
|
@@ -72,10 +72,10 @@ React keys must be passed directly to JSX without using spread:
|
|
|
72
72
|
body[`).concat(vr,`] {
|
|
73
73
|
`).concat(dv,": ").concat(a,`px;
|
|
74
74
|
}
|
|
75
|
-
`)},xu=function(){var e=parseInt(document.body.getAttribute(vr)||"0",10);return isFinite(e)?e:0},_v=function(){v.useEffect(function(){return document.body.setAttribute(vr,(xu()+1).toString()),function(){var e=xu()-1;e<=0?document.body.removeAttribute(vr):document.body.setAttribute(vr,e.toString())}},[])},jv=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,o=r===void 0?"margin":r;_v();var s=v.useMemo(function(){return Ev(o)},[o]);return v.createElement(Av,{styles:Nv(s,!t,o,n?"":"!important")})},Hi=!1;if(typeof window<"u")try{var es=Object.defineProperty({},"passive",{get:function(){return Hi=!0,!0}});window.addEventListener("test",es,es),window.removeEventListener("test",es,es)}catch{Hi=!1}var br=Hi?{passive:!1}:!1,Rv=function(e){return e.tagName==="TEXTAREA"},yu=function(e,t){if(!(e instanceof Element))return!1;var n=window.getComputedStyle(e);return n[t]!=="hidden"&&!(n.overflowY===n.overflowX&&!Rv(e)&&n[t]==="visible")},Mv=function(e){return yu(e,"overflowY")},Pv=function(e){return yu(e,"overflowX")},vu=function(e,t){var n=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var o=bu(e,r);if(o){var s=wu(e,r),i=s[1],a=s[2];if(i>a)return!0}r=r.parentNode}while(r&&r!==n.body);return!1},Ov=function(e){var t=e.scrollTop,n=e.scrollHeight,r=e.clientHeight;return[t,n,r]},Dv=function(e){var t=e.scrollLeft,n=e.scrollWidth,r=e.clientWidth;return[t,n,r]},bu=function(e,t){return e==="v"?Mv(t):Pv(t)},wu=function(e,t){return e==="v"?Ov(t):Dv(t)},Lv=function(e,t){return e==="h"&&t==="rtl"?-1:1},$v=function(e,t,n,r,o){var s=Lv(e,window.getComputedStyle(t).direction),i=s*r,a=n.target,l=t.contains(a),c=!1,d=i>0,f=0,
|
|
75
|
+
`)},xu=function(){var e=parseInt(document.body.getAttribute(vr)||"0",10);return isFinite(e)?e:0},_v=function(){v.useEffect(function(){return document.body.setAttribute(vr,(xu()+1).toString()),function(){var e=xu()-1;e<=0?document.body.removeAttribute(vr):document.body.setAttribute(vr,e.toString())}},[])},jv=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,o=r===void 0?"margin":r;_v();var s=v.useMemo(function(){return Ev(o)},[o]);return v.createElement(Av,{styles:Nv(s,!t,o,n?"":"!important")})},Hi=!1;if(typeof window<"u")try{var es=Object.defineProperty({},"passive",{get:function(){return Hi=!0,!0}});window.addEventListener("test",es,es),window.removeEventListener("test",es,es)}catch{Hi=!1}var br=Hi?{passive:!1}:!1,Rv=function(e){return e.tagName==="TEXTAREA"},yu=function(e,t){if(!(e instanceof Element))return!1;var n=window.getComputedStyle(e);return n[t]!=="hidden"&&!(n.overflowY===n.overflowX&&!Rv(e)&&n[t]==="visible")},Mv=function(e){return yu(e,"overflowY")},Pv=function(e){return yu(e,"overflowX")},vu=function(e,t){var n=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var o=bu(e,r);if(o){var s=wu(e,r),i=s[1],a=s[2];if(i>a)return!0}r=r.parentNode}while(r&&r!==n.body);return!1},Ov=function(e){var t=e.scrollTop,n=e.scrollHeight,r=e.clientHeight;return[t,n,r]},Dv=function(e){var t=e.scrollLeft,n=e.scrollWidth,r=e.clientWidth;return[t,n,r]},bu=function(e,t){return e==="v"?Mv(t):Pv(t)},wu=function(e,t){return e==="v"?Ov(t):Dv(t)},Lv=function(e,t){return e==="h"&&t==="rtl"?-1:1},$v=function(e,t,n,r,o){var s=Lv(e,window.getComputedStyle(t).direction),i=s*r,a=n.target,l=t.contains(a),c=!1,d=i>0,f=0,h=0;do{if(!a)break;var p=wu(e,a),x=p[0],m=p[1],y=p[2],g=m-y-s*x;(x||g)&&bu(e,a)&&(f+=g,h+=x);var b=a.parentNode;a=b&&b.nodeType===Node.DOCUMENT_FRAGMENT_NODE?b.host:b}while(!l&&a!==document.body||l&&(t.contains(a)||t===a));return(d&&Math.abs(f)<1||!d&&Math.abs(h)<1)&&(c=!0),c},ts=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},Su=function(e){return[e.deltaX,e.deltaY]},Cu=function(e){return e&&"current"in e?e.current:e},Fv=function(e,t){return e[0]===t[0]&&e[1]===t[1]},Bv=function(e){return`
|
|
76
76
|
.block-interactivity-`.concat(e,` {pointer-events: none;}
|
|
77
77
|
.allow-interactivity-`).concat(e,` {pointer-events: all;}
|
|
78
|
-
`)},zv=0,wr=[];function Uv(e){var t=v.useRef([]),n=v.useRef([0,0]),r=v.useRef(),o=v.useState(zv++)[0],s=v.useState(gu)[0],i=v.useRef(e);v.useEffect(function(){i.current=e},[e]),v.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(o));var m=cv([e.lockRef.current],(e.shards||[]).map(Cu),!0).filter(Boolean);return m.forEach(function(y){return y.classList.add("allow-interactivity-".concat(o))}),function(){document.body.classList.remove("block-interactivity-".concat(o)),m.forEach(function(y){return y.classList.remove("allow-interactivity-".concat(o))})}}},[e.inert,e.lockRef.current,e.shards]);var a=v.useCallback(function(m,y){if("touches"in m&&m.touches.length===2||m.type==="wheel"&&m.ctrlKey)return!i.current.allowPinchZoom;var g=ts(m),b=n.current,S="deltaX"in m?m.deltaX:b[0]-g[0],k="deltaY"in m?m.deltaY:b[1]-g[1],C,T=m.target,I=Math.abs(S)>Math.abs(k)?"h":"v";if("touches"in m&&I==="h"&&T.type==="range")return!1;var A=vu(I,T);if(!A)return!0;if(A?C=I:(C=I==="v"?"h":"v",A=vu(I,T)),!A)return!1;if(!r.current&&"changedTouches"in m&&(S||k)&&(r.current=C),!C)return!0;var R=r.current||C;return $v(R,y,m,R==="h"?S:k)},[]),l=v.useCallback(function(m){var y=m;if(!(!wr.length||wr[wr.length-1]!==s)){var g="deltaY"in y?Su(y):ts(y),b=t.current.filter(function(C){return C.name===y.type&&(C.target===y.target||y.target===C.shadowParent)&&Fv(C.delta,g)})[0];if(b&&b.should){y.cancelable&&y.preventDefault();return}if(!b){var S=(i.current.shards||[]).map(Cu).filter(Boolean).filter(function(C){return C.contains(y.target)}),k=S.length>0?a(y,S[0]):!i.current.noIsolation;k&&y.cancelable&&y.preventDefault()}}},[]),c=v.useCallback(function(m,y,g,b){var S={name:m,delta:y,target:g,should:b,shadowParent:Hv(g)};t.current.push(S),setTimeout(function(){t.current=t.current.filter(function(k){return k!==S})},1)},[]),d=v.useCallback(function(m){n.current=ts(m),r.current=void 0},[]),f=v.useCallback(function(m){c(m.type,Su(m),m.target,a(m,e.lockRef.current))},[]),p=v.useCallback(function(m){c(m.type,ts(m),m.target,a(m,e.lockRef.current))},[]);v.useEffect(function(){return wr.push(s),e.setCallbacks({onScrollCapture:f,onWheelCapture:f,onTouchMoveCapture:p}),document.addEventListener("wheel",l,br),document.addEventListener("touchmove",l,br),document.addEventListener("touchstart",d,br),function(){wr=wr.filter(function(m){return m!==s}),document.removeEventListener("wheel",l,br),document.removeEventListener("touchmove",l,br),document.removeEventListener("touchstart",d,br)}},[]);var h=e.removeScrollBar,x=e.inert;return v.createElement(v.Fragment,null,x?v.createElement(s,{styles:Bv(o)}):null,h?v.createElement(jv,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function Hv(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const Wv=yv(mu,Uv);var ns=v.forwardRef(function(e,t){return v.createElement(Qo,mn({},e,{ref:t,sideCar:Wv}))});ns.classNames=Qo.classNames;var Wi=["Enter"," "],Vv=["ArrowDown","PageUp","Home"],Tu=["ArrowUp","PageDown","End"],Kv=[...Vv,...Tu],qv={ltr:[...Wi,"ArrowRight"],rtl:[...Wi,"ArrowLeft"]},Gv={ltr:["ArrowLeft"],rtl:["ArrowRight"]},zr="Menu",[Ur,Yv,Xv]=xi(zr),[Gn,ku]=Sn(zr,[Xv,Ko,iu]),rs=Ko(),Iu=iu(),[Jv,Yn]=Gn(zr),[Zv,Hr]=Gn(zr),Eu=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=rs(t),[l,c]=v.useState(null),d=v.useRef(!1),f=kt(s),p=Mo(o);return v.useEffect(()=>{const h=()=>{d.current=!0,document.addEventListener("pointerdown",x,{capture:!0,once:!0}),document.addEventListener("pointermove",x,{capture:!0,once:!0})},x=()=>d.current=!1;return document.addEventListener("keydown",h,{capture:!0}),()=>{document.removeEventListener("keydown",h,{capture:!0}),document.removeEventListener("pointerdown",x,{capture:!0}),document.removeEventListener("pointermove",x,{capture:!0})}},[]),u.jsx(tu,{...a,children:u.jsx(Jv,{scope:t,open:n,onOpenChange:f,content:l,onContentChange:c,children:u.jsx(Zv,{scope:t,onClose:v.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:d,dir:p,modal:i,children:r})})})};Eu.displayName=zr;var Qv="MenuAnchor",Vi=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=rs(n);return u.jsx(nu,{...o,...r,ref:t})});Vi.displayName=Qv;var Ki="MenuPortal",[eb,Au]=Gn(Ki,{forceMount:void 0}),Nu=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:o}=e,s=Yn(Ki,t);return u.jsx(eb,{scope:t,forceMount:n,children:u.jsx(Yt,{present:n||s.open,children:u.jsx(qo,{asChild:!0,container:o,children:r})})})};Nu.displayName=Ki;var Xt="MenuContent",[tb,qi]=Gn(Xt),_u=v.forwardRef((e,t)=>{const n=Au(Xt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Yn(Xt,e.__scopeMenu),i=Hr(Xt,e.__scopeMenu);return u.jsx(Ur.Provider,{scope:e.__scopeMenu,children:u.jsx(Yt,{present:r||s.open,children:u.jsx(Ur.Slot,{scope:e.__scopeMenu,children:i.modal?u.jsx(nb,{...o,ref:t}):u.jsx(rb,{...o,ref:t})})})})}),nb=v.forwardRef((e,t)=>{const n=Yn(Xt,e.__scopeMenu),r=v.useRef(null),o=Be(t,r);return v.useEffect(()=>{const s=r.current;if(s)return Fi(s)},[]),u.jsx(Gi,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:de(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),rb=v.forwardRef((e,t)=>{const n=Yn(Xt,e.__scopeMenu);return u.jsx(Gi,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),ob=Hn.createSlot("MenuContent.ScrollLock"),Gi=v.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:o,onOpenAutoFocus:s,onCloseAutoFocus:i,disableOutsidePointerEvents:a,onEntryFocus:l,onEscapeKeyDown:c,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:p,onDismiss:h,disableOutsideScroll:x,...m}=e,y=Yn(Xt,n),g=Hr(Xt,n),b=rs(n),S=Iu(n),k=Yv(n),[C,T]=v.useState(null),I=v.useRef(null),A=Be(t,I,y.onContentChange),R=v.useRef(0),L=v.useRef(""),P=v.useRef(0),D=v.useRef(null),F=v.useRef("right"),N=v.useRef(0),B=x?ns:v.Fragment,j=x?{as:ob,allowPinchZoom:!0}:void 0,V=M=>{var Z,$;const q=L.current+M,J=k().filter(K=>!K.disabled),se=document.activeElement,ge=(Z=J.find(K=>K.ref.current===se))==null?void 0:Z.textValue,Ee=J.map(K=>K.textValue),Y=gb(Ee,q,ge),U=($=J.find(K=>K.textValue===Y))==null?void 0:$.ref.current;(function K(Q){L.current=Q,window.clearTimeout(R.current),Q!==""&&(R.current=window.setTimeout(()=>K(""),1e3))})(q),U&&setTimeout(()=>U.focus())};v.useEffect(()=>()=>window.clearTimeout(R.current),[]),bi();const z=v.useCallback(M=>{var J,se;return F.current===((J=D.current)==null?void 0:J.side)&&yb(M,(se=D.current)==null?void 0:se.area)},[]);return u.jsx(tb,{scope:n,searchRef:L,onItemEnter:v.useCallback(M=>{z(M)&&M.preventDefault()},[z]),onItemLeave:v.useCallback(M=>{var q;z(M)||((q=I.current)==null||q.focus(),T(null))},[z]),onTriggerLeave:v.useCallback(M=>{z(M)&&M.preventDefault()},[z]),pointerGraceTimerRef:P,onPointerGraceIntentChange:v.useCallback(M=>{D.current=M},[]),children:u.jsx(B,{...j,children:u.jsx(Oo,{asChild:!0,trapped:o,onMountAutoFocus:de(s,M=>{var q;M.preventDefault(),(q=I.current)==null||q.focus({preventScroll:!0})}),onUnmountAutoFocus:i,children:u.jsx(Po,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:c,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:p,onDismiss:h,children:u.jsx(ov,{asChild:!0,...S,dir:g.dir,orientation:"vertical",loop:r,currentTabStopId:C,onCurrentTabStopIdChange:T,onEntryFocus:de(l,M=>{g.isUsingKeyboardRef.current||M.preventDefault()}),preventScrollOnEntryFocus:!0,children:u.jsx(ru,{role:"menu","aria-orientation":"vertical","data-state":qu(y.open),"data-radix-menu-content":"",dir:g.dir,...b,...m,ref:A,style:{outline:"none",...m.style},onKeyDown:de(m.onKeyDown,M=>{const J=M.target.closest("[data-radix-menu-content]")===M.currentTarget,se=M.ctrlKey||M.altKey||M.metaKey,ge=M.key.length===1;J&&(M.key==="Tab"&&M.preventDefault(),!se&&ge&&V(M.key));const Ee=I.current;if(M.target!==Ee||!Kv.includes(M.key))return;M.preventDefault();const U=k().filter(Z=>!Z.disabled).map(Z=>Z.ref.current);Tu.includes(M.key)&&U.reverse(),hb(U)}),onBlur:de(e.onBlur,M=>{M.currentTarget.contains(M.target)||(window.clearTimeout(R.current),L.current="")}),onPointerMove:de(e.onPointerMove,Vr(M=>{const q=M.target,J=N.current!==M.clientX;if(M.currentTarget.contains(q)&&J){const se=M.clientX>N.current?"right":"left";F.current=se,N.current=M.clientX}}))})})})})})})});_u.displayName=Xt;var sb="MenuGroup",Yi=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(_e.div,{role:"group",...r,ref:t})});Yi.displayName=sb;var ib="MenuLabel",ju=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(_e.div,{...r,ref:t})});ju.displayName=ib;var os="MenuItem",Ru="menu.itemSelect",ss=v.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...o}=e,s=v.useRef(null),i=Hr(os,e.__scopeMenu),a=qi(os,e.__scopeMenu),l=Be(t,s),c=v.useRef(!1),d=()=>{const f=s.current;if(!n&&f){const p=new CustomEvent(Ru,{bubbles:!0,cancelable:!0});f.addEventListener(Ru,h=>r==null?void 0:r(h),{once:!0}),dc(f,p),p.defaultPrevented?c.current=!1:i.onClose()}};return u.jsx(Mu,{...o,ref:l,disabled:n,onClick:de(e.onClick,d),onPointerDown:f=>{var p;(p=e.onPointerDown)==null||p.call(e,f),c.current=!0},onPointerUp:de(e.onPointerUp,f=>{var p;c.current||(p=f.currentTarget)==null||p.click()}),onKeyDown:de(e.onKeyDown,f=>{const p=a.searchRef.current!=="";n||p&&f.key===" "||Wi.includes(f.key)&&(f.currentTarget.click(),f.preventDefault())})})});ss.displayName=os;var Mu=v.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:o,...s}=e,i=qi(os,n),a=Iu(n),l=v.useRef(null),c=Be(t,l),[d,f]=v.useState(!1),[p,h]=v.useState("");return v.useEffect(()=>{const x=l.current;x&&h((x.textContent??"").trim())},[s.children]),u.jsx(Ur.ItemSlot,{scope:n,disabled:r,textValue:o??p,children:u.jsx(sv,{asChild:!0,...a,focusable:!r,children:u.jsx(_e.div,{role:"menuitem","data-highlighted":d?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:c,onPointerMove:de(e.onPointerMove,Vr(x=>{r?i.onItemLeave(x):(i.onItemEnter(x),x.defaultPrevented||x.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:de(e.onPointerLeave,Vr(x=>i.onItemLeave(x))),onFocus:de(e.onFocus,()=>f(!0)),onBlur:de(e.onBlur,()=>f(!1))})})})}),ab="MenuCheckboxItem",Pu=v.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...o}=e;return u.jsx(Fu,{scope:e.__scopeMenu,checked:n,children:u.jsx(ss,{role:"menuitemcheckbox","aria-checked":is(n)?"mixed":n,...o,ref:t,"data-state":Ji(n),onSelect:de(o.onSelect,()=>r==null?void 0:r(is(n)?!0:!n),{checkForDefaultPrevented:!1})})})});Pu.displayName=ab;var Ou="MenuRadioGroup",[lb,cb]=Gn(Ou,{value:void 0,onValueChange:()=>{}}),Du=v.forwardRef((e,t)=>{const{value:n,onValueChange:r,...o}=e,s=kt(r);return u.jsx(lb,{scope:e.__scopeMenu,value:n,onValueChange:s,children:u.jsx(Yi,{...o,ref:t})})});Du.displayName=Ou;var Lu="MenuRadioItem",$u=v.forwardRef((e,t)=>{const{value:n,...r}=e,o=cb(Lu,e.__scopeMenu),s=n===o.value;return u.jsx(Fu,{scope:e.__scopeMenu,checked:s,children:u.jsx(ss,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":Ji(s),onSelect:de(r.onSelect,()=>{var i;return(i=o.onValueChange)==null?void 0:i.call(o,n)},{checkForDefaultPrevented:!1})})})});$u.displayName=Lu;var Xi="MenuItemIndicator",[Fu,ub]=Gn(Xi,{checked:!1}),Bu=v.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...o}=e,s=ub(Xi,n);return u.jsx(Yt,{present:r||is(s.checked)||s.checked===!0,children:u.jsx(_e.span,{...o,ref:t,"data-state":Ji(s.checked)})})});Bu.displayName=Xi;var db="MenuSeparator",zu=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(_e.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});zu.displayName=db;var fb="MenuArrow",Uu=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=rs(n);return u.jsx(ou,{...o,...r,ref:t})});Uu.displayName=fb;var pb="MenuSub",[PT,Hu]=Gn(pb),Wr="MenuSubTrigger",Wu=v.forwardRef((e,t)=>{const n=Yn(Wr,e.__scopeMenu),r=Hr(Wr,e.__scopeMenu),o=Hu(Wr,e.__scopeMenu),s=qi(Wr,e.__scopeMenu),i=v.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:l}=s,c={__scopeMenu:e.__scopeMenu},d=v.useCallback(()=>{i.current&&window.clearTimeout(i.current),i.current=null},[]);return v.useEffect(()=>d,[d]),v.useEffect(()=>{const f=a.current;return()=>{window.clearTimeout(f),l(null)}},[a,l]),u.jsx(Vi,{asChild:!0,...c,children:u.jsx(Mu,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":o.contentId,"data-state":qu(n.open),...e,ref:gi(t,o.onTriggerChange),onClick:f=>{var p;(p=e.onClick)==null||p.call(e,f),!(e.disabled||f.defaultPrevented)&&(f.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:de(e.onPointerMove,Vr(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,Vr(f=>{var h,x;d();const p=(h=n.content)==null?void 0:h.getBoundingClientRect();if(p){const m=(x=n.content)==null?void 0:x.dataset.side,y=m==="right",g=y?-5:5,b=p[y?"left":"right"],S=p[y?"right":"left"];s.onPointerGraceIntentChange({area:[{x:f.clientX+g,y:f.clientY},{x:b,y:p.top},{x:S,y:p.top},{x:S,y:p.bottom},{x:b,y:p.bottom}],side:m}),window.clearTimeout(a.current),a.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(f),f.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:de(e.onKeyDown,f=>{var h;const p=s.searchRef.current!=="";e.disabled||p&&f.key===" "||qv[r.dir].includes(f.key)&&(n.onOpenChange(!0),(h=n.content)==null||h.focus(),f.preventDefault())})})})});Wu.displayName=Wr;var Vu="MenuSubContent",Ku=v.forwardRef((e,t)=>{const n=Au(Xt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Yn(Xt,e.__scopeMenu),i=Hr(Xt,e.__scopeMenu),a=Hu(Vu,e.__scopeMenu),l=v.useRef(null),c=Be(t,l);return u.jsx(Ur.Provider,{scope:e.__scopeMenu,children:u.jsx(Yt,{present:r||s.open,children:u.jsx(Ur.Slot,{scope:e.__scopeMenu,children:u.jsx(Gi,{id:a.contentId,"aria-labelledby":a.triggerId,...o,ref:c,align:"start",side:i.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:d=>{var f;i.isUsingKeyboardRef.current&&((f=l.current)==null||f.focus()),d.preventDefault()},onCloseAutoFocus:d=>d.preventDefault(),onFocusOutside: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 h;const f=d.currentTarget.contains(d.target),p=Gv[i.dir].includes(d.key);f&&p&&(s.onOpenChange(!1),(h=a.trigger)==null||h.focus(),d.preventDefault())})})})})})});Ku.displayName=Vu;function qu(e){return e?"open":"closed"}function is(e){return e==="indeterminate"}function Ji(e){return is(e)?"indeterminate":e?"checked":"unchecked"}function hb(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function mb(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function gb(e,t,n){const o=t.length>1&&Array.from(t).every(c=>c===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let i=mb(e,Math.max(s,0));o.length===1&&(i=i.filter(c=>c!==n));const l=i.find(c=>c.toLowerCase().startsWith(o.toLowerCase()));return l!==n?l:void 0}function xb(e,t){const{x:n,y:r}=e;let o=!1;for(let s=0,i=t.length-1;s<t.length;i=s++){const a=t[s],l=t[i],c=a.x,d=a.y,f=l.x,p=l.y;d>r!=p>r&&n<(f-c)*(r-d)/(p-d)+c&&(o=!o)}return o}function yb(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return xb(n,t)}function Vr(e){return t=>t.pointerType==="mouse"?e(t):void 0}var vb=Eu,bb=Vi,wb=Nu,Sb=_u,Cb=Yi,Tb=ju,kb=ss,Ib=Pu,Eb=Du,Ab=$u,Nb=Bu,_b=zu,jb=Uu,Rb=Wu,Mb=Ku,as="DropdownMenu",[Pb,OT]=Sn(as,[ku]),Ot=ku(),[Ob,Gu]=Pb(as),Yu=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:o,defaultOpen:s,onOpenChange:i,modal:a=!0}=e,l=Ot(t),c=v.useRef(null),[d,f]=pr({prop:o,defaultProp:s??!1,onChange:i,caller:as});return u.jsx(Ob,{scope:t,triggerId:Cn(),triggerRef:c,contentId:Cn(),open:d,onOpenChange:f,onOpenToggle:v.useCallback(()=>f(p=>!p),[f]),modal:a,children:u.jsx(vb,{...l,open:d,onOpenChange:f,dir:r,modal:a,children:n})})};Yu.displayName=as;var Xu="DropdownMenuTrigger",Ju=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...o}=e,s=Gu(Xu,n),i=Ot(n);return u.jsx(bb,{asChild:!0,...i,children:u.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: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())})})})});Ju.displayName=Xu;var Db="DropdownMenuPortal",Zu=e=>{const{__scopeDropdownMenu:t,...n}=e,r=Ot(t);return u.jsx(wb,{...r,...n})};Zu.displayName=Db;var Qu="DropdownMenuContent",ed=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Gu(Qu,n),s=Ot(n),i=v.useRef(!1);return u.jsx(Sb,{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,c=l.button===0&&l.ctrlKey===!0,d=l.button===2||c;(!o.modal||d)&&(i.current=!0)}),style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});ed.displayName=Qu;var Lb="DropdownMenuGroup",$b=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return u.jsx(Cb,{...o,...r,ref:t})});$b.displayName=Lb;var Fb="DropdownMenuLabel",td=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return u.jsx(Tb,{...o,...r,ref:t})});td.displayName=Fb;var Bb="DropdownMenuItem",nd=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return u.jsx(kb,{...o,...r,ref:t})});nd.displayName=Bb;var zb="DropdownMenuCheckboxItem",rd=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return u.jsx(Ib,{...o,...r,ref:t})});rd.displayName=zb;var Ub="DropdownMenuRadioGroup",Hb=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return u.jsx(Eb,{...o,...r,ref:t})});Hb.displayName=Ub;var Wb="DropdownMenuRadioItem",od=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return u.jsx(Ab,{...o,...r,ref:t})});od.displayName=Wb;var Vb="DropdownMenuItemIndicator",sd=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return u.jsx(Nb,{...o,...r,ref:t})});sd.displayName=Vb;var Kb="DropdownMenuSeparator",id=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return u.jsx(_b,{...o,...r,ref:t})});id.displayName=Kb;var qb="DropdownMenuArrow",Gb=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return u.jsx(jb,{...o,...r,ref:t})});Gb.displayName=qb;var Yb="DropdownMenuSubTrigger",ad=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return u.jsx(Rb,{...o,...r,ref:t})});ad.displayName=Yb;var Xb="DropdownMenuSubContent",ld=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return u.jsx(Mb,{...o,...r,ref:t,style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});ld.displayName=Xb;var Jb=Yu,Zb=Ju,Qb=Zu,cd=ed,ud=td,dd=nd,fd=rd,pd=od,hd=sd,md=id,gd=ad,xd=ld;const ew=Jb,tw=Zb,nw=v.forwardRef(({className:e,inset:t,children:n,...r},o)=>u.jsxs(gd,{ref:o,className:ne("flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent",t&&"pl-8",e),...r,children:[n,u.jsx(ae.ChevronRight,{className:"ml-auto h-4 w-4"})]}));nw.displayName=gd.displayName;const rw=v.forwardRef(({className:e,...t},n)=>u.jsx(xd,{ref:n,className:ne("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}));rw.displayName=xd.displayName;const yd=v.forwardRef(({className:e,sideOffset:t=4,...n},r)=>u.jsx(Qb,{children:u.jsx(cd,{ref:r,sideOffset:t,className:ne("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})}));yd.displayName=cd.displayName;const Zi=v.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(dd,{ref:r,className:ne("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t&&"pl-8",e),...n}));Zi.displayName=dd.displayName;const ow=v.forwardRef(({className:e,children:t,checked:n,...r},o)=>u.jsxs(fd,{ref:o,className:ne("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),checked:n,...r,children:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(hd,{children:u.jsx(ae.Check,{className:"h-4 w-4"})})}),t]}));ow.displayName=fd.displayName;const sw=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(pd,{ref:r,className:ne("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(hd,{children:u.jsx(ae.Circle,{className:"h-2 w-2 fill-current"})})}),t]}));sw.displayName=pd.displayName;const iw=v.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(ud,{ref:r,className:ne("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));iw.displayName=ud.displayName;const aw=v.forwardRef(({className:e,...t},n)=>u.jsx(md,{ref:n,className:ne("-mx-1 my-1 h-px bg-muted",e),...t}));aw.displayName=md.displayName;function lw(e){const t=new Map;console.log("[attemptDetection] groupCheckpointsByLastUserMessageId processing",e.length,"checkpoints");for(const n of e){const o=[...n.messages??[]].reverse().find(s=>s.role==="user");if(o!=null&&o.id){const s=t.get(o.id)??[];s.push(n),t.set(o.id,s),s.length===1?console.log(`[attemptDetection] New user message group: "${o.id}" checkpoint ${n.checkpointId}`):console.log(`[attemptDetection] Adding to existing group: "${o.id}" now has ${s.length} checkpoints`)}else console.log(`[attemptDetection] Checkpoint ${n.checkpointId} has no user messages`)}return console.log("[attemptDetection] Final grouping:",{totalGroups:t.size,groupSizes:Array.from(t.entries()).map(([n,r])=>({userMessageId:n,count:r.length}))}),t}function cw(e){console.log("[attemptDetection] buildAttemptMetadataMap called with",e.length,"checkpoints");const t=new Map,n=lw(e);console.log("[attemptDetection] Grouped into",n.size,"unique user message IDs");for(const[r,o]of n.entries())o.length>1&&console.log(`[attemptDetection] User message "${r}" found in ${o.length} checkpoints (EDITS DETECTED)`,{checkpointIds:o.map(s=>s.checkpointId),createdAts:o.map(s=>s.createdAt)});for(const[r,o]of n.entries())if(o.length===1){const s=o[0];s.checkpointId&&t.set(s.checkpointId,{attemptIndex:0,attemptCount:1,isLatestAttempt:!0,baseUserMessageId:r})}else{const s=[...o].sort((i,a)=>Date.parse(a.createdAt??"0")-Date.parse(i.createdAt??"0"));console.log(`[attemptDetection] Sorted ${s.length} versions for user message "${r}":`,{versionOrder:s.map((i,a)=>`v${a}: ${i.checkpointId} (${i.createdAt})`)}),s.forEach((i,a)=>{i.checkpointId&&t.set(i.checkpointId,{attemptIndex:a,attemptCount:s.length,isLatestAttempt:a===s.length-1,baseUserMessageId:r})})}return console.log("[attemptDetection] Final versionMetadata:",{totalCheckpoints:t.size,editedMessages:Array.from(t.entries()).filter(([r,o])=>o.attemptCount>1).map(([r,o])=>({checkpointId:r,attemptIndex:o.attemptIndex,attemptCount:o.attemptCount,isLatestAttempt:o.isLatestAttempt}))}),t}function uw(e){const t=new Map;for(const[n,r]of e.entries())if(r.baseUserMessageId&&r.attemptCount>1){const o=t.get(r.baseUserMessageId)??[];o.push({checkpointId:n,attemptIndex:r.attemptIndex,attemptCount:r.attemptCount,isLatestAttempt:r.isLatestAttempt}),t.set(r.baseUserMessageId,o)}return t}function ls(e,t){if(!e||typeof e!="object")return null;const n=e[t];return typeof n=="number"?n:null}function dw(e,t){if(!e||typeof e!="object")return null;const n=e[t];return typeof n=="string"&&n.trim()?n:null}function fw(e){if(!Array.isArray(e)||e.length===0)return null;const t=e.map(n=>{if(typeof n=="string")return n.trim();if(n&&typeof n=="object"&&"type"in n){const r=n;if(typeof r.type=="string")return r.type}return null}).filter(n=>!!(n&&n.length));return t.length?t.join(", "):null}function pw(e){const t=Array.isArray(e)?e.map(r=>{const o=fw(r.next);return o?{...r,metadata:{...r.metadata??{},next:o}}:r}):[];return t.some(r=>ls(r.metadata,"step")!==null)&&t.sort((r,o)=>{const s=ls(r.metadata,"step"),i=ls(o.metadata,"step");if(s!==null||i!==null)return(i??Number.NEGATIVE_INFINITY)-(s??Number.NEGATIVE_INFINITY);const a=Date.parse(r.createdAt??""),l=Date.parse(o.createdAt??"");return Number.isNaN(a)||Number.isNaN(l)?0:l-a}),t}function hw(e){const t=w.useMemo(()=>pw(e),[e]),{checkpointMetaById:n,checkpointIndexByKey:r,attemptMetaById:o,userMessageIdToAttempts:s}=w.useMemo(()=>{const i=new Map,a=new Map,l=new Map;for(const f of t){const p=f.checkpointId??null;if(!p)continue;const h=ls(f.metadata,"step"),x=dw(f.metadata,"source"),m={id:p,step:h,source:x,createdAt:f.createdAt??null,namespace:f.checkpointNs??null,parentId:f.parentId??null};if(i.set(p,m),h!==null&&x){const y=`${h}:${x}`,g=a.get(y)??[];g.push(m),a.set(y,g)}}console.log("[useCheckpointMetadata] Building attempt metadata for",t.length,"checkpoints");const c=cw(t);for(const[f,p]of i.entries()){const h=c.get(f);h?l.set(f,{...p,attemptIndex:h.attemptIndex,attemptCount:h.attemptCount,isLatestAttempt:h.isLatestAttempt,baseUserMessageId:h.baseUserMessageId??null}):l.set(f,{...p,attemptIndex:0,attemptCount:1,isLatestAttempt:!0,baseUserMessageId:null})}console.log("[useCheckpointMetadata] Final attemptMetaById:",{totalCheckpoints:l.size,withMultipleAttempts:Array.from(l.values()).filter(f=>f.attemptCount>1).length,samples:Array.from(l.entries()).slice(0,3).map(([f,p])=>({checkpointId:f,attemptIndex:p.attemptIndex,attemptCount:p.attemptCount}))});const d=uw(l);return console.log("[useCheckpointMetadata] userMessageIdToAttempts map built with",d.size,"user message IDs with multiple attempts"),{checkpointMetaById:i,checkpointIndexByKey:a,attemptMetaById:l,userMessageIdToAttempts:d}},[t]);return{checkpointMetaById:n,checkpointIndexByKey:r,attemptMetaById:o,userMessageIdToAttempts:s}}const cs=1e4;function mw(e){if(typeof e!="string")return String(e);const t=[/<script[^>]*>.*?<\/script>/gi,/<iframe[^>]*>.*?<\/iframe>/gi,/javascript:/gi,/vbscript:/gi,/on\w+\s*=/gi,/<object[^>]*>.*?<\/object>/gi,/<embed[^>]*>.*?<\/embed>/gi,/<form[^>]*>.*?<\/form>/gi];let n=e;for(const o of t)n=n.replace(o,"");return/<[^>]+>/.test(n)&&!/<(?!\/?(?:code|strong|em|b|i|br|p|ul|ol|li|h[1-6])\b)[^>]+>/i.test(n)?n.replace(/<code>(.*?)<\/code>/gi,"`$1`").replace(/<strong>(.*?)<\/strong>/gi,"**$1**").replace(/<b>(.*?)<\/b>/gi,"**$1**").replace(/<em>(.*?)<\/em>/gi,"*$1*").replace(/<i>(.*?)<\/i>/gi,"*$1*").replace(/<br\s*\/?>/gi,`
|
|
78
|
+
`)},zv=0,wr=[];function Uv(e){var t=v.useRef([]),n=v.useRef([0,0]),r=v.useRef(),o=v.useState(zv++)[0],s=v.useState(gu)[0],i=v.useRef(e);v.useEffect(function(){i.current=e},[e]),v.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(o));var m=cv([e.lockRef.current],(e.shards||[]).map(Cu),!0).filter(Boolean);return m.forEach(function(y){return y.classList.add("allow-interactivity-".concat(o))}),function(){document.body.classList.remove("block-interactivity-".concat(o)),m.forEach(function(y){return y.classList.remove("allow-interactivity-".concat(o))})}}},[e.inert,e.lockRef.current,e.shards]);var a=v.useCallback(function(m,y){if("touches"in m&&m.touches.length===2||m.type==="wheel"&&m.ctrlKey)return!i.current.allowPinchZoom;var g=ts(m),b=n.current,S="deltaX"in m?m.deltaX:b[0]-g[0],k="deltaY"in m?m.deltaY:b[1]-g[1],C,T=m.target,I=Math.abs(S)>Math.abs(k)?"h":"v";if("touches"in m&&I==="h"&&T.type==="range")return!1;var A=vu(I,T);if(!A)return!0;if(A?C=I:(C=I==="v"?"h":"v",A=vu(I,T)),!A)return!1;if(!r.current&&"changedTouches"in m&&(S||k)&&(r.current=C),!C)return!0;var R=r.current||C;return $v(R,y,m,R==="h"?S:k)},[]),l=v.useCallback(function(m){var y=m;if(!(!wr.length||wr[wr.length-1]!==s)){var g="deltaY"in y?Su(y):ts(y),b=t.current.filter(function(C){return C.name===y.type&&(C.target===y.target||y.target===C.shadowParent)&&Fv(C.delta,g)})[0];if(b&&b.should){y.cancelable&&y.preventDefault();return}if(!b){var S=(i.current.shards||[]).map(Cu).filter(Boolean).filter(function(C){return C.contains(y.target)}),k=S.length>0?a(y,S[0]):!i.current.noIsolation;k&&y.cancelable&&y.preventDefault()}}},[]),c=v.useCallback(function(m,y,g,b){var S={name:m,delta:y,target:g,should:b,shadowParent:Hv(g)};t.current.push(S),setTimeout(function(){t.current=t.current.filter(function(k){return k!==S})},1)},[]),d=v.useCallback(function(m){n.current=ts(m),r.current=void 0},[]),f=v.useCallback(function(m){c(m.type,Su(m),m.target,a(m,e.lockRef.current))},[]),h=v.useCallback(function(m){c(m.type,ts(m),m.target,a(m,e.lockRef.current))},[]);v.useEffect(function(){return wr.push(s),e.setCallbacks({onScrollCapture:f,onWheelCapture:f,onTouchMoveCapture:h}),document.addEventListener("wheel",l,br),document.addEventListener("touchmove",l,br),document.addEventListener("touchstart",d,br),function(){wr=wr.filter(function(m){return m!==s}),document.removeEventListener("wheel",l,br),document.removeEventListener("touchmove",l,br),document.removeEventListener("touchstart",d,br)}},[]);var p=e.removeScrollBar,x=e.inert;return v.createElement(v.Fragment,null,x?v.createElement(s,{styles:Bv(o)}):null,p?v.createElement(jv,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function Hv(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const Wv=yv(mu,Uv);var ns=v.forwardRef(function(e,t){return v.createElement(Qo,mn({},e,{ref:t,sideCar:Wv}))});ns.classNames=Qo.classNames;var Wi=["Enter"," "],Vv=["ArrowDown","PageUp","Home"],Tu=["ArrowUp","PageDown","End"],Kv=[...Vv,...Tu],qv={ltr:[...Wi,"ArrowRight"],rtl:[...Wi,"ArrowLeft"]},Gv={ltr:["ArrowLeft"],rtl:["ArrowRight"]},zr="Menu",[Ur,Yv,Xv]=xi(zr),[Gn,ku]=Sn(zr,[Xv,Ko,iu]),rs=Ko(),Iu=iu(),[Jv,Yn]=Gn(zr),[Zv,Hr]=Gn(zr),Eu=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=rs(t),[l,c]=v.useState(null),d=v.useRef(!1),f=kt(s),h=Mo(o);return v.useEffect(()=>{const p=()=>{d.current=!0,document.addEventListener("pointerdown",x,{capture:!0,once:!0}),document.addEventListener("pointermove",x,{capture:!0,once:!0})},x=()=>d.current=!1;return document.addEventListener("keydown",p,{capture:!0}),()=>{document.removeEventListener("keydown",p,{capture:!0}),document.removeEventListener("pointerdown",x,{capture:!0}),document.removeEventListener("pointermove",x,{capture:!0})}},[]),u.jsx(tu,{...a,children:u.jsx(Jv,{scope:t,open:n,onOpenChange:f,content:l,onContentChange:c,children:u.jsx(Zv,{scope:t,onClose:v.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:d,dir:h,modal:i,children:r})})})};Eu.displayName=zr;var Qv="MenuAnchor",Vi=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=rs(n);return u.jsx(nu,{...o,...r,ref:t})});Vi.displayName=Qv;var Ki="MenuPortal",[eb,Au]=Gn(Ki,{forceMount:void 0}),Nu=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:o}=e,s=Yn(Ki,t);return u.jsx(eb,{scope:t,forceMount:n,children:u.jsx(Yt,{present:n||s.open,children:u.jsx(qo,{asChild:!0,container:o,children:r})})})};Nu.displayName=Ki;var Xt="MenuContent",[tb,qi]=Gn(Xt),_u=v.forwardRef((e,t)=>{const n=Au(Xt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Yn(Xt,e.__scopeMenu),i=Hr(Xt,e.__scopeMenu);return u.jsx(Ur.Provider,{scope:e.__scopeMenu,children:u.jsx(Yt,{present:r||s.open,children:u.jsx(Ur.Slot,{scope:e.__scopeMenu,children:i.modal?u.jsx(nb,{...o,ref:t}):u.jsx(rb,{...o,ref:t})})})})}),nb=v.forwardRef((e,t)=>{const n=Yn(Xt,e.__scopeMenu),r=v.useRef(null),o=Be(t,r);return v.useEffect(()=>{const s=r.current;if(s)return Fi(s)},[]),u.jsx(Gi,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:de(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),rb=v.forwardRef((e,t)=>{const n=Yn(Xt,e.__scopeMenu);return u.jsx(Gi,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),ob=Hn.createSlot("MenuContent.ScrollLock"),Gi=v.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:o,onOpenAutoFocus:s,onCloseAutoFocus:i,disableOutsidePointerEvents:a,onEntryFocus:l,onEscapeKeyDown:c,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:h,onDismiss:p,disableOutsideScroll:x,...m}=e,y=Yn(Xt,n),g=Hr(Xt,n),b=rs(n),S=Iu(n),k=Yv(n),[C,T]=v.useState(null),I=v.useRef(null),A=Be(t,I,y.onContentChange),R=v.useRef(0),L=v.useRef(""),P=v.useRef(0),D=v.useRef(null),F=v.useRef("right"),N=v.useRef(0),B=x?ns:v.Fragment,j=x?{as:ob,allowPinchZoom:!0}:void 0,V=M=>{var Z,$;const q=L.current+M,J=k().filter(K=>!K.disabled),se=document.activeElement,ge=(Z=J.find(K=>K.ref.current===se))==null?void 0:Z.textValue,Ee=J.map(K=>K.textValue),Y=gb(Ee,q,ge),U=($=J.find(K=>K.textValue===Y))==null?void 0:$.ref.current;(function K(Q){L.current=Q,window.clearTimeout(R.current),Q!==""&&(R.current=window.setTimeout(()=>K(""),1e3))})(q),U&&setTimeout(()=>U.focus())};v.useEffect(()=>()=>window.clearTimeout(R.current),[]),bi();const z=v.useCallback(M=>{var J,se;return F.current===((J=D.current)==null?void 0:J.side)&&yb(M,(se=D.current)==null?void 0:se.area)},[]);return u.jsx(tb,{scope:n,searchRef:L,onItemEnter:v.useCallback(M=>{z(M)&&M.preventDefault()},[z]),onItemLeave:v.useCallback(M=>{var q;z(M)||((q=I.current)==null||q.focus(),T(null))},[z]),onTriggerLeave:v.useCallback(M=>{z(M)&&M.preventDefault()},[z]),pointerGraceTimerRef:P,onPointerGraceIntentChange:v.useCallback(M=>{D.current=M},[]),children:u.jsx(B,{...j,children:u.jsx(Oo,{asChild:!0,trapped:o,onMountAutoFocus:de(s,M=>{var q;M.preventDefault(),(q=I.current)==null||q.focus({preventScroll:!0})}),onUnmountAutoFocus:i,children:u.jsx(Po,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:c,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:h,onDismiss:p,children:u.jsx(ov,{asChild:!0,...S,dir:g.dir,orientation:"vertical",loop:r,currentTabStopId:C,onCurrentTabStopIdChange:T,onEntryFocus:de(l,M=>{g.isUsingKeyboardRef.current||M.preventDefault()}),preventScrollOnEntryFocus:!0,children:u.jsx(ru,{role:"menu","aria-orientation":"vertical","data-state":qu(y.open),"data-radix-menu-content":"",dir:g.dir,...b,...m,ref:A,style:{outline:"none",...m.style},onKeyDown:de(m.onKeyDown,M=>{const J=M.target.closest("[data-radix-menu-content]")===M.currentTarget,se=M.ctrlKey||M.altKey||M.metaKey,ge=M.key.length===1;J&&(M.key==="Tab"&&M.preventDefault(),!se&&ge&&V(M.key));const Ee=I.current;if(M.target!==Ee||!Kv.includes(M.key))return;M.preventDefault();const U=k().filter(Z=>!Z.disabled).map(Z=>Z.ref.current);Tu.includes(M.key)&&U.reverse(),hb(U)}),onBlur:de(e.onBlur,M=>{M.currentTarget.contains(M.target)||(window.clearTimeout(R.current),L.current="")}),onPointerMove:de(e.onPointerMove,Vr(M=>{const q=M.target,J=N.current!==M.clientX;if(M.currentTarget.contains(q)&&J){const se=M.clientX>N.current?"right":"left";F.current=se,N.current=M.clientX}}))})})})})})})});_u.displayName=Xt;var sb="MenuGroup",Yi=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(_e.div,{role:"group",...r,ref:t})});Yi.displayName=sb;var ib="MenuLabel",ju=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(_e.div,{...r,ref:t})});ju.displayName=ib;var os="MenuItem",Ru="menu.itemSelect",ss=v.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...o}=e,s=v.useRef(null),i=Hr(os,e.__scopeMenu),a=qi(os,e.__scopeMenu),l=Be(t,s),c=v.useRef(!1),d=()=>{const f=s.current;if(!n&&f){const h=new CustomEvent(Ru,{bubbles:!0,cancelable:!0});f.addEventListener(Ru,p=>r==null?void 0:r(p),{once:!0}),dc(f,h),h.defaultPrevented?c.current=!1:i.onClose()}};return u.jsx(Mu,{...o,ref:l,disabled:n,onClick:de(e.onClick,d),onPointerDown:f=>{var h;(h=e.onPointerDown)==null||h.call(e,f),c.current=!0},onPointerUp:de(e.onPointerUp,f=>{var h;c.current||(h=f.currentTarget)==null||h.click()}),onKeyDown:de(e.onKeyDown,f=>{const h=a.searchRef.current!=="";n||h&&f.key===" "||Wi.includes(f.key)&&(f.currentTarget.click(),f.preventDefault())})})});ss.displayName=os;var Mu=v.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:o,...s}=e,i=qi(os,n),a=Iu(n),l=v.useRef(null),c=Be(t,l),[d,f]=v.useState(!1),[h,p]=v.useState("");return v.useEffect(()=>{const x=l.current;x&&p((x.textContent??"").trim())},[s.children]),u.jsx(Ur.ItemSlot,{scope:n,disabled:r,textValue:o??h,children:u.jsx(sv,{asChild:!0,...a,focusable:!r,children:u.jsx(_e.div,{role:"menuitem","data-highlighted":d?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:c,onPointerMove:de(e.onPointerMove,Vr(x=>{r?i.onItemLeave(x):(i.onItemEnter(x),x.defaultPrevented||x.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:de(e.onPointerLeave,Vr(x=>i.onItemLeave(x))),onFocus:de(e.onFocus,()=>f(!0)),onBlur:de(e.onBlur,()=>f(!1))})})})}),ab="MenuCheckboxItem",Pu=v.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...o}=e;return u.jsx(Fu,{scope:e.__scopeMenu,checked:n,children:u.jsx(ss,{role:"menuitemcheckbox","aria-checked":is(n)?"mixed":n,...o,ref:t,"data-state":Ji(n),onSelect:de(o.onSelect,()=>r==null?void 0:r(is(n)?!0:!n),{checkForDefaultPrevented:!1})})})});Pu.displayName=ab;var Ou="MenuRadioGroup",[lb,cb]=Gn(Ou,{value:void 0,onValueChange:()=>{}}),Du=v.forwardRef((e,t)=>{const{value:n,onValueChange:r,...o}=e,s=kt(r);return u.jsx(lb,{scope:e.__scopeMenu,value:n,onValueChange:s,children:u.jsx(Yi,{...o,ref:t})})});Du.displayName=Ou;var Lu="MenuRadioItem",$u=v.forwardRef((e,t)=>{const{value:n,...r}=e,o=cb(Lu,e.__scopeMenu),s=n===o.value;return u.jsx(Fu,{scope:e.__scopeMenu,checked:s,children:u.jsx(ss,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":Ji(s),onSelect:de(r.onSelect,()=>{var i;return(i=o.onValueChange)==null?void 0:i.call(o,n)},{checkForDefaultPrevented:!1})})})});$u.displayName=Lu;var Xi="MenuItemIndicator",[Fu,ub]=Gn(Xi,{checked:!1}),Bu=v.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...o}=e,s=ub(Xi,n);return u.jsx(Yt,{present:r||is(s.checked)||s.checked===!0,children:u.jsx(_e.span,{...o,ref:t,"data-state":Ji(s.checked)})})});Bu.displayName=Xi;var db="MenuSeparator",zu=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(_e.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});zu.displayName=db;var fb="MenuArrow",Uu=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=rs(n);return u.jsx(ou,{...o,...r,ref:t})});Uu.displayName=fb;var pb="MenuSub",[PT,Hu]=Gn(pb),Wr="MenuSubTrigger",Wu=v.forwardRef((e,t)=>{const n=Yn(Wr,e.__scopeMenu),r=Hr(Wr,e.__scopeMenu),o=Hu(Wr,e.__scopeMenu),s=qi(Wr,e.__scopeMenu),i=v.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:l}=s,c={__scopeMenu:e.__scopeMenu},d=v.useCallback(()=>{i.current&&window.clearTimeout(i.current),i.current=null},[]);return v.useEffect(()=>d,[d]),v.useEffect(()=>{const f=a.current;return()=>{window.clearTimeout(f),l(null)}},[a,l]),u.jsx(Vi,{asChild:!0,...c,children:u.jsx(Mu,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":o.contentId,"data-state":qu(n.open),...e,ref:gi(t,o.onTriggerChange),onClick:f=>{var 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,Vr(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,Vr(f=>{var p,x;d();const h=(p=n.content)==null?void 0:p.getBoundingClientRect();if(h){const m=(x=n.content)==null?void 0:x.dataset.side,y=m==="right",g=y?-5:5,b=h[y?"left":"right"],S=h[y?"right":"left"];s.onPointerGraceIntentChange({area:[{x:f.clientX+g,y:f.clientY},{x:b,y:h.top},{x:S,y:h.top},{x:S,y:h.bottom},{x:b,y:h.bottom}],side:m}),window.clearTimeout(a.current),a.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(f),f.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:de(e.onKeyDown,f=>{var p;const h=s.searchRef.current!=="";e.disabled||h&&f.key===" "||qv[r.dir].includes(f.key)&&(n.onOpenChange(!0),(p=n.content)==null||p.focus(),f.preventDefault())})})})});Wu.displayName=Wr;var Vu="MenuSubContent",Ku=v.forwardRef((e,t)=>{const n=Au(Xt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Yn(Xt,e.__scopeMenu),i=Hr(Xt,e.__scopeMenu),a=Hu(Vu,e.__scopeMenu),l=v.useRef(null),c=Be(t,l);return u.jsx(Ur.Provider,{scope:e.__scopeMenu,children:u.jsx(Yt,{present:r||s.open,children:u.jsx(Ur.Slot,{scope:e.__scopeMenu,children:u.jsx(Gi,{id:a.contentId,"aria-labelledby":a.triggerId,...o,ref:c,align:"start",side:i.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:d=>{var f;i.isUsingKeyboardRef.current&&((f=l.current)==null||f.focus()),d.preventDefault()},onCloseAutoFocus:d=>d.preventDefault(),onFocusOutside: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=Gv[i.dir].includes(d.key);f&&h&&(s.onOpenChange(!1),(p=a.trigger)==null||p.focus(),d.preventDefault())})})})})})});Ku.displayName=Vu;function qu(e){return e?"open":"closed"}function is(e){return e==="indeterminate"}function Ji(e){return is(e)?"indeterminate":e?"checked":"unchecked"}function hb(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function mb(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function gb(e,t,n){const o=t.length>1&&Array.from(t).every(c=>c===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let i=mb(e,Math.max(s,0));o.length===1&&(i=i.filter(c=>c!==n));const l=i.find(c=>c.toLowerCase().startsWith(o.toLowerCase()));return l!==n?l:void 0}function xb(e,t){const{x:n,y:r}=e;let o=!1;for(let s=0,i=t.length-1;s<t.length;i=s++){const a=t[s],l=t[i],c=a.x,d=a.y,f=l.x,h=l.y;d>r!=h>r&&n<(f-c)*(r-d)/(h-d)+c&&(o=!o)}return o}function yb(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return xb(n,t)}function Vr(e){return t=>t.pointerType==="mouse"?e(t):void 0}var vb=Eu,bb=Vi,wb=Nu,Sb=_u,Cb=Yi,Tb=ju,kb=ss,Ib=Pu,Eb=Du,Ab=$u,Nb=Bu,_b=zu,jb=Uu,Rb=Wu,Mb=Ku,as="DropdownMenu",[Pb,OT]=Sn(as,[ku]),Ot=ku(),[Ob,Gu]=Pb(as),Yu=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:o,defaultOpen:s,onOpenChange:i,modal:a=!0}=e,l=Ot(t),c=v.useRef(null),[d,f]=pr({prop:o,defaultProp:s??!1,onChange:i,caller:as});return u.jsx(Ob,{scope:t,triggerId:Cn(),triggerRef:c,contentId:Cn(),open:d,onOpenChange:f,onOpenToggle:v.useCallback(()=>f(h=>!h),[f]),modal:a,children:u.jsx(vb,{...l,open:d,onOpenChange:f,dir:r,modal:a,children:n})})};Yu.displayName=as;var Xu="DropdownMenuTrigger",Ju=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...o}=e,s=Gu(Xu,n),i=Ot(n);return u.jsx(bb,{asChild:!0,...i,children:u.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: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())})})})});Ju.displayName=Xu;var Db="DropdownMenuPortal",Zu=e=>{const{__scopeDropdownMenu:t,...n}=e,r=Ot(t);return u.jsx(wb,{...r,...n})};Zu.displayName=Db;var Qu="DropdownMenuContent",ed=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Gu(Qu,n),s=Ot(n),i=v.useRef(!1);return u.jsx(Sb,{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,c=l.button===0&&l.ctrlKey===!0,d=l.button===2||c;(!o.modal||d)&&(i.current=!0)}),style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});ed.displayName=Qu;var Lb="DropdownMenuGroup",$b=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return u.jsx(Cb,{...o,...r,ref:t})});$b.displayName=Lb;var Fb="DropdownMenuLabel",td=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return u.jsx(Tb,{...o,...r,ref:t})});td.displayName=Fb;var Bb="DropdownMenuItem",nd=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return u.jsx(kb,{...o,...r,ref:t})});nd.displayName=Bb;var zb="DropdownMenuCheckboxItem",rd=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return u.jsx(Ib,{...o,...r,ref:t})});rd.displayName=zb;var Ub="DropdownMenuRadioGroup",Hb=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return u.jsx(Eb,{...o,...r,ref:t})});Hb.displayName=Ub;var Wb="DropdownMenuRadioItem",od=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return u.jsx(Ab,{...o,...r,ref:t})});od.displayName=Wb;var Vb="DropdownMenuItemIndicator",sd=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return u.jsx(Nb,{...o,...r,ref:t})});sd.displayName=Vb;var Kb="DropdownMenuSeparator",id=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return u.jsx(_b,{...o,...r,ref:t})});id.displayName=Kb;var qb="DropdownMenuArrow",Gb=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return u.jsx(jb,{...o,...r,ref:t})});Gb.displayName=qb;var Yb="DropdownMenuSubTrigger",ad=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return u.jsx(Rb,{...o,...r,ref:t})});ad.displayName=Yb;var Xb="DropdownMenuSubContent",ld=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return u.jsx(Mb,{...o,...r,ref:t,style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});ld.displayName=Xb;var Jb=Yu,Zb=Ju,Qb=Zu,cd=ed,ud=td,dd=nd,fd=rd,pd=od,hd=sd,md=id,gd=ad,xd=ld;const ew=Jb,tw=Zb,nw=v.forwardRef(({className:e,inset:t,children:n,...r},o)=>u.jsxs(gd,{ref:o,className:ne("flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent",t&&"pl-8",e),...r,children:[n,u.jsx(ae.ChevronRight,{className:"ml-auto h-4 w-4"})]}));nw.displayName=gd.displayName;const rw=v.forwardRef(({className:e,...t},n)=>u.jsx(xd,{ref:n,className:ne("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}));rw.displayName=xd.displayName;const yd=v.forwardRef(({className:e,sideOffset:t=4,...n},r)=>u.jsx(Qb,{children:u.jsx(cd,{ref:r,sideOffset:t,className:ne("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})}));yd.displayName=cd.displayName;const Zi=v.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(dd,{ref:r,className:ne("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t&&"pl-8",e),...n}));Zi.displayName=dd.displayName;const ow=v.forwardRef(({className:e,children:t,checked:n,...r},o)=>u.jsxs(fd,{ref:o,className:ne("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),checked:n,...r,children:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(hd,{children:u.jsx(ae.Check,{className:"h-4 w-4"})})}),t]}));ow.displayName=fd.displayName;const sw=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(pd,{ref:r,className:ne("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(hd,{children:u.jsx(ae.Circle,{className:"h-2 w-2 fill-current"})})}),t]}));sw.displayName=pd.displayName;const iw=v.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(ud,{ref:r,className:ne("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));iw.displayName=ud.displayName;const aw=v.forwardRef(({className:e,...t},n)=>u.jsx(md,{ref:n,className:ne("-mx-1 my-1 h-px bg-muted",e),...t}));aw.displayName=md.displayName;function lw(e){const t=new Map;console.log("[attemptDetection] groupCheckpointsByLastUserMessageId processing",e.length,"checkpoints");for(const n of e){const o=[...n.messages??[]].reverse().find(s=>s.role==="user");if(o!=null&&o.id){const s=t.get(o.id)??[];s.push(n),t.set(o.id,s),s.length===1?console.log(`[attemptDetection] New user message group: "${o.id}" checkpoint ${n.checkpointId}`):console.log(`[attemptDetection] Adding to existing group: "${o.id}" now has ${s.length} checkpoints`)}else console.log(`[attemptDetection] Checkpoint ${n.checkpointId} has no user messages`)}return console.log("[attemptDetection] Final grouping:",{totalGroups:t.size,groupSizes:Array.from(t.entries()).map(([n,r])=>({userMessageId:n,count:r.length}))}),t}function cw(e){console.log("[attemptDetection] buildAttemptMetadataMap called with",e.length,"checkpoints");const t=new Map,n=lw(e);console.log("[attemptDetection] Grouped into",n.size,"unique user message IDs");for(const[r,o]of n.entries())o.length>1&&console.log(`[attemptDetection] User message "${r}" found in ${o.length} checkpoints (EDITS DETECTED)`,{checkpointIds:o.map(s=>s.checkpointId),createdAts:o.map(s=>s.createdAt)});for(const[r,o]of n.entries())if(o.length===1){const s=o[0];s.checkpointId&&t.set(s.checkpointId,{attemptIndex:0,attemptCount:1,isLatestAttempt:!0,baseUserMessageId:r})}else{const s=[...o].sort((i,a)=>Date.parse(a.createdAt??"0")-Date.parse(i.createdAt??"0"));console.log(`[attemptDetection] Sorted ${s.length} versions for user message "${r}":`,{versionOrder:s.map((i,a)=>`v${a}: ${i.checkpointId} (${i.createdAt})`)}),s.forEach((i,a)=>{i.checkpointId&&t.set(i.checkpointId,{attemptIndex:a,attemptCount:s.length,isLatestAttempt:a===s.length-1,baseUserMessageId:r})})}return console.log("[attemptDetection] Final versionMetadata:",{totalCheckpoints:t.size,editedMessages:Array.from(t.entries()).filter(([r,o])=>o.attemptCount>1).map(([r,o])=>({checkpointId:r,attemptIndex:o.attemptIndex,attemptCount:o.attemptCount,isLatestAttempt:o.isLatestAttempt}))}),t}function uw(e){const t=new Map;for(const[n,r]of e.entries())if(r.baseUserMessageId&&r.attemptCount>1){const o=t.get(r.baseUserMessageId)??[];o.push({checkpointId:n,attemptIndex:r.attemptIndex,attemptCount:r.attemptCount,isLatestAttempt:r.isLatestAttempt}),t.set(r.baseUserMessageId,o)}return t}function ls(e,t){if(!e||typeof e!="object")return null;const n=e[t];return typeof n=="number"?n:null}function dw(e,t){if(!e||typeof e!="object")return null;const n=e[t];return typeof n=="string"&&n.trim()?n:null}function fw(e){if(!Array.isArray(e)||e.length===0)return null;const t=e.map(n=>{if(typeof n=="string")return n.trim();if(n&&typeof n=="object"&&"type"in n){const r=n;if(typeof r.type=="string")return r.type}return null}).filter(n=>!!(n&&n.length));return t.length?t.join(", "):null}function pw(e){const t=Array.isArray(e)?e.map(r=>{const o=fw(r.next);return o?{...r,metadata:{...r.metadata??{},next:o}}:r}):[];return t.some(r=>ls(r.metadata,"step")!==null)&&t.sort((r,o)=>{const s=ls(r.metadata,"step"),i=ls(o.metadata,"step");if(s!==null||i!==null)return(i??Number.NEGATIVE_INFINITY)-(s??Number.NEGATIVE_INFINITY);const a=Date.parse(r.createdAt??""),l=Date.parse(o.createdAt??"");return Number.isNaN(a)||Number.isNaN(l)?0:l-a}),t}function hw(e){const t=w.useMemo(()=>pw(e),[e]),{checkpointMetaById:n,checkpointIndexByKey:r,attemptMetaById:o,userMessageIdToAttempts:s}=w.useMemo(()=>{const i=new Map,a=new Map,l=new Map;for(const f of t){const h=f.checkpointId??null;if(!h)continue;const p=ls(f.metadata,"step"),x=dw(f.metadata,"source"),m={id:h,step:p,source:x,createdAt:f.createdAt??null,namespace:f.checkpointNs??null,parentId:f.parentId??null};if(i.set(h,m),p!==null&&x){const y=`${p}:${x}`,g=a.get(y)??[];g.push(m),a.set(y,g)}}console.log("[useCheckpointMetadata] Building attempt metadata for",t.length,"checkpoints");const c=cw(t);for(const[f,h]of i.entries()){const p=c.get(f);p?l.set(f,{...h,attemptIndex:p.attemptIndex,attemptCount:p.attemptCount,isLatestAttempt:p.isLatestAttempt,baseUserMessageId:p.baseUserMessageId??null}):l.set(f,{...h,attemptIndex:0,attemptCount:1,isLatestAttempt:!0,baseUserMessageId:null})}console.log("[useCheckpointMetadata] Final attemptMetaById:",{totalCheckpoints:l.size,withMultipleAttempts:Array.from(l.values()).filter(f=>f.attemptCount>1).length,samples:Array.from(l.entries()).slice(0,3).map(([f,h])=>({checkpointId:f,attemptIndex:h.attemptIndex,attemptCount:h.attemptCount}))});const d=uw(l);return console.log("[useCheckpointMetadata] userMessageIdToAttempts map built with",d.size,"user message IDs with multiple attempts"),{checkpointMetaById:i,checkpointIndexByKey:a,attemptMetaById:l,userMessageIdToAttempts:d}},[t]);return{checkpointMetaById:n,checkpointIndexByKey:r,attemptMetaById:o,userMessageIdToAttempts:s}}const cs=1e4;function mw(e){if(typeof e!="string")return String(e);const t=[/<script[^>]*>.*?<\/script>/gi,/<iframe[^>]*>.*?<\/iframe>/gi,/javascript:/gi,/vbscript:/gi,/on\w+\s*=/gi,/<object[^>]*>.*?<\/object>/gi,/<embed[^>]*>.*?<\/embed>/gi,/<form[^>]*>.*?<\/form>/gi];let n=e;for(const o of t)n=n.replace(o,"");return/<[^>]+>/.test(n)&&!/<(?!\/?(?:code|strong|em|b|i|br|p|ul|ol|li|h[1-6])\b)[^>]+>/i.test(n)?n.replace(/<code>(.*?)<\/code>/gi,"`$1`").replace(/<strong>(.*?)<\/strong>/gi,"**$1**").replace(/<b>(.*?)<\/b>/gi,"**$1**").replace(/<em>(.*?)<\/em>/gi,"*$1*").replace(/<i>(.*?)<\/i>/gi,"*$1*").replace(/<br\s*\/?>/gi,`
|
|
79
79
|
`).replace(/<p>(.*?)<\/p>/gi,`$1
|
|
80
80
|
|
|
81
81
|
`).replace(/<h([1-6])>(.*?)<\/h[1-6]>/gi,(o,s,i)=>`${"#".repeat(parseInt(s))} ${i}
|
|
@@ -83,24 +83,24 @@ React keys must be passed directly to JSX without using spread:
|
|
|
83
83
|
`).replace(/<ul>/gi,"").replace(/<\/ul>/gi,`
|
|
84
84
|
`).replace(/<ol>/gi,"").replace(/<\/ol>/gi,`
|
|
85
85
|
`).replace(/<li>(.*?)<\/li>/gi,`- $1
|
|
86
|
-
`).trim():n.replace(/</g,"<").replace(/>/g,">").trim()}function gw(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 xw(e){let t;return typeof e=="string"?t=e:typeof e=="object"&&e!==null?t=JSON.stringify(e):t=String(e),gw(t),mw(t)}const us=0,Rn=1,Sr=2,vd=4;function bd(e){return()=>e}function yw(e){e()}function wd(e,t){return n=>e(t(n))}function Sd(e,t){return()=>e(t)}function vw(e,t){return n=>e(t,n)}function Qi(e){return e!==void 0}function bw(...e){return()=>{e.map(yw)}}function Cr(){}function ds(e,t){return t(e),e}function ww(e,t){return t(e)}function ct(...e){return e}function Je(e,t){return e(Rn,t)}function Me(e,t){e(us,t)}function ea(e){e(Sr)}function vt(e){return e(vd)}function he(e,t){return Je(e,vw(t,us))}function sn(e,t){const n=e(Rn,r=>{n(),t(r)});return n}function Cd(e){let t,n;return r=>o=>{t=o,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function Td(e,t){return e===t}function ut(e=Td){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function ke(e){return t=>n=>{e(n)&&t(n)}}function le(e){return t=>wd(t,e)}function gn(e){return t=>()=>{t(e)}}function H(e,...t){const n=Sw(...t);return(r,o)=>{switch(r){case Sr:ea(e);return;case Rn:return Je(e,n(o))}}}function xn(e,t){return n=>r=>{n(t=e(t,r))}}function Xn(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 De(...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 c=n;n=n|a,t[i]=l,c!==o&&n===o&&r&&(r(),r=null)})}),s=>i=>{const a=()=>{s([i].concat(t))};n===o?a():r=a}}function Sw(...e){return t=>e.reduceRight(ww,t)}function Cw(e){let t,n;const r=()=>t==null?void 0:t();return function(o,s){switch(o){case Rn:return s?n===s?void 0:(r(),n=s,t=Je(e,s),t):(r(),Cr);case Sr:r(),n=null;return}}}function ee(e){let t=e;const n=ze();return(r,o)=>{switch(r){case us:t=o;break;case Rn:{o(t);break}case vd:return t}return n(r,o)}}function Nt(e,t){return ds(ee(t),n=>he(e,n))}function ze(){const e=[];return(t,n)=>{switch(t){case us:e.slice().forEach(r=>{r(n)});return;case Sr:e.splice(0,e.length);return;case Rn:return e.push(n),()=>{const r=e.indexOf(n);r>-1&&e.splice(r,1)}}}}function Ht(e){return ds(ze(),t=>he(e,t))}function We(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:Tw(),singleton:n}}const Tw=()=>Symbol();function kw(e){const t=new Map,n=({constructor:r,dependencies:o,id:s,singleton:i})=>{if(i&&t.has(s))return t.get(s);const a=r(o.map(l=>n(l)));return i&&t.set(s,a),a};return n(e)}function wt(...e){const t=ze(),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&&Me(t,n)})}),function(s,i){switch(s){case Sr:{ea(t);return}case Rn:return r===o&&i(n),Je(t,i)}}}function Te(e,t=Td){return H(e,ut(t))}function ta(...e){return function(t,n){switch(t){case Sr:return;case Rn:return bw(...e.map(r=>Je(r,n)))}}}var Bt=(e=>(e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR",e))(Bt||{});const Iw={0:"debug",3:"error",1:"log",2:"warn"},Ew=()=>typeof globalThis>"u"?window:globalThis,Mn=We(()=>{const e=ee(3);return{log:ee((t,n,r=1)=>{var o;const s=(o=Ew().VIRTUOSO_LOG_LEVEL)!=null?o:vt(e);r>=s&&console[Iw[r]]("%creact-virtuoso: %c%s %o","color: #0253b3; font-weight: bold","color: initial",t,n)}),logLevel:e}},[],{singleton:!0});function Jn(e,t,n){return na(e,t,n).callbackRef}function na(e,t,n){const r=w.useRef(null);let o=i=>{};const s=w.useMemo(()=>typeof ResizeObserver<"u"?new ResizeObserver(i=>{const a=()=>{const l=i[0].target;l.offsetParent!==null&&e(l)};n?a():requestAnimationFrame(a)}):null,[e,n]);return o=i=>{i&&t?(s==null||s.observe(i),r.current=i):(r.current&&(s==null||s.unobserve(r.current)),r.current=null)},{callbackRef:o,ref:r}}function Aw(e,t,n,r,o,s,i,a,l){const c=w.useCallback(d=>{const f=Nw(d.children,t,a?"offsetWidth":"offsetHeight",o);let p=d.parentElement;for(;!p.dataset.virtuosoScroller;)p=p.parentElement;const h=p.lastElementChild.dataset.viewportType==="window";let x;h&&(x=p.ownerDocument.defaultView);const m=i?a?i.scrollLeft:i.scrollTop:h?a?x.scrollX||x.document.documentElement.scrollLeft:x.scrollY||x.document.documentElement.scrollTop:a?p.scrollLeft:p.scrollTop,y=i?a?i.scrollWidth:i.scrollHeight:h?a?x.document.documentElement.scrollWidth:x.document.documentElement.scrollHeight:a?p.scrollWidth:p.scrollHeight,g=i?a?i.offsetWidth:i.offsetHeight:h?a?x.innerWidth:x.innerHeight:a?p.offsetWidth:p.offsetHeight;r({scrollHeight:y,scrollTop:Math.max(m,0),viewportHeight:g}),s==null||s(a?kd("column-gap",getComputedStyle(d).columnGap,o):kd("row-gap",getComputedStyle(d).rowGap,o)),f!==null&&e(f)},[e,t,o,s,i,r,a]);return na(c,n,l)}function Nw(e,t,n,r){const o=e.length;if(o===0)return null;const s=[];for(let i=0;i<o;i++){const a=e.item(i);if(a.dataset.index===void 0)continue;const l=parseInt(a.dataset.index),c=parseFloat(a.dataset.knownSize),d=t(a,n);if(d===0&&r("Zero-sized element, this should not happen",{child:a},Bt.ERROR),d===c)continue;const f=s[s.length-1];s.length===0||f.size!==d||f.endIndex!==l-1?s.push({endIndex:l,size:d,startIndex:l}):s[s.length-1].endIndex++}return s}function kd(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Bt.WARN),t==="normal"?0:parseInt(t??"0",10)}function Id(e,t,n){const r=w.useRef(null),o=w.useCallback(l=>{if(!(l!=null&&l.offsetParent))return;const c=l.getBoundingClientRect(),d=c.width;let f,p;if(t){const h=t.getBoundingClientRect(),x=c.top-h.top;p=h.height-Math.max(0,x),f=x+t.scrollTop}else{const h=i.current.ownerDocument.defaultView;p=h.innerHeight-Math.max(0,c.top),f=c.top+h.scrollY}r.current={offsetTop:f,visibleHeight:p,visibleWidth:d},e(r.current)},[e,t]),{callbackRef:s,ref:i}=na(o,!0,n),a=w.useCallback(()=>{o(i.current)},[o,i]);return w.useEffect(()=>{var l;if(t){t.addEventListener("scroll",a);const c=new ResizeObserver(()=>{requestAnimationFrame(a)});return c.observe(t),()=>{t.removeEventListener("scroll",a),c.unobserve(t)}}else{const c=(l=i.current)==null?void 0:l.ownerDocument.defaultView;return c==null||c.addEventListener("scroll",a),c==null||c.addEventListener("resize",a),()=>{c==null||c.removeEventListener("scroll",a),c==null||c.removeEventListener("resize",a)}}},[a,t,i]),s}const Dt=We(()=>{const e=ze(),t=ze(),n=ee(0),r=ze(),o=ee(0),s=ze(),i=ze(),a=ee(0),l=ee(0),c=ee(0),d=ee(0),f=ze(),p=ze(),h=ee(!1),x=ee(!1),m=ee(!1);return he(H(e,le(({scrollTop:y})=>y)),t),he(H(e,le(({scrollHeight:y})=>y)),i),he(t,o),{deviation:n,fixedFooterHeight:c,fixedHeaderHeight:l,footerHeight:d,headerHeight:a,horizontalDirection:x,scrollBy:p,scrollContainerState:e,scrollHeight:i,scrollingInProgress:h,scrollTo:f,scrollTop:t,skipAnimationFrameInResizeObserver:m,smoothScrollTargetReached:r,statefulScrollTop:o,viewportHeight:s}},[],{singleton:!0}),Kr={lvl:0};function Ed(e,t){const n=e.length;if(n===0)return[];let{index:r,value:o}=t(e[0]);const s=[];for(let i=1;i<n;i++){const{index:a,value:l}=t(e[i]);s.push({end:a-1,start:r,value:o}),r=a,o=l}return s.push({end:1/0,start:r,value:o}),s}function ot(e){return e===Kr}function qr(e,t){if(!ot(e))return t===e.k?e.v:t<e.k?qr(e.l,t):qr(e.r,t)}function an(e,t,n="k"){if(ot(e))return[-1/0,void 0];if(Number(e[n])===t)return[e.k,e.v];if(Number(e[n])<t){const r=an(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return an(e.l,t,n)}function Wt(e,t,n){return ot(e)?_d(t,n,1):t===e.k?Ct(e,{k:t,v:n}):t<e.k?jd(Ct(e,{l:Wt(e.l,t,n)})):jd(Ct(e,{r:Wt(e.r,t,n)}))}function Tr(){return Kr}function fs(e,t,n){if(ot(e))return[];const r=an(e,t)[0];return _w(oa(e,r,n))}function ra(e,t){if(ot(e))return Kr;const{k:n,l:r,r:o}=e;if(t===n){if(ot(r))return o;if(ot(o))return r;{const[s,i]=Nd(r);return ps(Ct(e,{k:s,l:Ad(r),v:i}))}}else return t<n?ps(Ct(e,{l:ra(r,t)})):ps(Ct(e,{r:ra(o,t)}))}function Zn(e){return ot(e)?[]:[...Zn(e.l),{k:e.k,v:e.v},...Zn(e.r)]}function oa(e,t,n){if(ot(e))return[];const{k:r,l:o,r:s,v:i}=e;let a=[];return r>t&&(a=a.concat(oa(o,t,n))),r>=t&&r<=n&&a.push({k:r,v:i}),r<=n&&(a=a.concat(oa(s,t,n))),a}function ps(e){const{l:t,lvl:n,r}=e;if(r.lvl>=n-1&&t.lvl>=n-1)return e;if(n>r.lvl+1){if(sa(t))return Rd(Ct(e,{lvl:n-1}));if(!ot(t)&&!ot(t.r))return Ct(t.r,{l:Ct(t,{r:t.r.l}),lvl:n,r:Ct(e,{l:t.r.r,lvl:n-1})});throw new Error("Unexpected empty nodes")}else{if(sa(e))return ia(Ct(e,{lvl:n-1}));if(!ot(r)&&!ot(r.l)){const o=r.l,s=sa(o)?r.lvl-1:r.lvl;return Ct(o,{l:Ct(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:ia(Ct(r,{l:o.r,lvl:s}))})}else throw new Error("Unexpected empty nodes")}}function Ct(e,t){return _d(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 Ad(e){return ot(e.r)?e.l:ps(Ct(e,{r:Ad(e.r)}))}function sa(e){return ot(e)||e.lvl>e.r.lvl}function Nd(e){return ot(e.r)?[e.k,e.v]:Nd(e.r)}function _d(e,t,n,r=Kr,o=Kr){return{k:e,l:r,lvl:n,r:o,v:t}}function jd(e){return ia(Rd(e))}function Rd(e){const{l:t}=e;return!ot(t)&&t.lvl===e.lvl?Ct(t,{r:Ct(e,{l:t.r})}):e}function ia(e){const{lvl:t,r:n}=e;return!ot(n)&&!ot(n.r)&&n.lvl===t&&n.r.lvl===t?Ct(n,{l:Ct(e,{r:n.l}),lvl:t+1}):e}function _w(e){return Ed(e,({k:t,v:n})=>({index:t,value:n}))}function Md(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function Gr(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}const aa=We(()=>({recalcInProgress:ee(!1)}),[],{singleton:!0});function Pd(e,t,n){return e[hs(e,t,n)]}function hs(e,t,n,r=0){let o=e.length-1;for(;r<=o;){const s=Math.floor((r+o)/2),i=e[s],a=n(i,t);if(a===0)return s;if(a===-1){if(o-r<2)return s-1;o=s-1}else{if(o===r)return s;r=s+1}}throw new Error(`Failed binary finding record in array - ${e.join(",")}, searched for ${t}`)}function jw(e,t,n,r){const o=hs(e,t,r),s=hs(e,n,r,o);return e.slice(o,s+1)}function Pn(e,t){return Math.round(e.getBoundingClientRect()[t])}function ms(e){return!ot(e.groupOffsetTree)}function la({index:e},t){return t===e?0:t<e?-1:1}function Rw(){return{groupIndices:[],groupOffsetTree:Tr(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:Tr()}}function Mw(e,t){let n=ot(e)?0:1/0;for(const r of t){const{endIndex:o,size:s,startIndex:i}=r;if(n=Math.min(n,i),ot(e)){e=Wt(e,0,s);continue}const a=fs(e,i-1,o+1);if(a.some(Bw(r)))continue;let l=!1,c=!1;for(const{end:d,start:f,value:p}of a)l?(o>=f||s===p)&&(e=ra(e,f)):(c=p!==s,l=!0),d>o&&o>=f&&p!==s&&(e=Wt(e,o+1,p));c&&(e=Wt(e,i,s))}return[e,n]}function Pw(e){return typeof e.groupIndex<"u"}function Ow({offset:e},t){return t===e?0:t<e?-1:1}function Yr(e,t,n){if(t.length===0)return 0;const{index:r,offset:o,size:s}=Pd(t,e,la),i=e-r,a=s*i+(i-1)*n+o;return a>0?a+n:a}function Od(e,t){if(!ms(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function Dd(e,t,n){if(Pw(e))return t.groupIndices[e.groupIndex]+1;{const r=e.index==="LAST"?n:e.index;let o=Od(r,t);return o=Math.max(0,o,Math.min(n,o)),o}}function Dw(e,t,n,r=0){return r>0&&(t=Math.max(t,Pd(e,r,la).offset)),Ed(jw(e,t,n,Ow),Fw)}function Lw(e,[t,n,r,o]){t.length>0&&r("received item sizes",t,Bt.DEBUG);const s=e.sizeTree;let i=s,a=0;if(n.length>0&&ot(s)&&t.length===2){const p=t[0].size,h=t[1].size;i=n.reduce((x,m)=>Wt(Wt(x,m,p),m+1,h),i)}else[i,a]=Mw(i,t);if(i===s)return e;const{lastIndex:l,lastOffset:c,lastSize:d,offsetTree:f}=ca(e.offsetTree,a,i,o);return{groupIndices:n,groupOffsetTree:n.reduce((p,h)=>Wt(p,h,Yr(h,f,o)),Tr()),lastIndex:l,lastOffset:c,lastSize:d,offsetTree:f,sizeTree:i}}function $w(e){return Zn(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 Ld(e,t){let n=0,r=0;for(;n<e;)n+=t[r+1]-t[r]-1,r++;return r-(n===e?0:1)}function ca(e,t,n,r){let o=e,s=0,i=0,a=0,l=0;if(t!==0){l=hs(o,t-1,la),a=o[l].offset;const c=an(n,t-1);s=c[0],i=c[1],o.length&&o[l].size===an(n,t)[1]&&(l-=1),o=o.slice(0,l+1)}else o=[];for(const{start:c,value:d}of fs(n,t,1/0)){const f=c-s,p=f*i+a+f*r;o.push({index:c,offset:p,size:d}),s=c,a=p,i=d}return{lastIndex:s,lastOffset:a,lastSize:i,offsetTree:o}}function Fw(e){return{index:e.index,value:e}}function Bw(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 zw={offsetHeight:"height",offsetWidth:"width"},yn=We(([{log:e},{recalcInProgress:t}])=>{const n=ze(),r=ze(),o=Nt(r,0),s=ze(),i=ze(),a=ee(0),l=ee([]),c=ee(void 0),d=ee(void 0),f=ee((C,T)=>Pn(C,zw[T])),p=ee(void 0),h=ee(0),x=Rw(),m=Nt(H(n,De(l,e,h),xn(Lw,x),ut()),x),y=Nt(H(l,ut(),xn((C,T)=>({current:T,prev:C.current}),{current:[],prev:[]}),le(({prev:C})=>C)),[]);he(H(l,ke(C=>C.length>0),De(m,h),le(([C,T,I])=>{const A=C.reduce((R,L,P)=>Wt(R,L,Yr(L,T.offsetTree,I)||P),Tr());return{...T,groupIndices:C,groupOffsetTree:A}})),m),he(H(r,De(m),ke(([C,{lastIndex:T}])=>C<T),le(([C,{lastIndex:T,lastSize:I}])=>[{endIndex:T,size:I,startIndex:C}])),n),he(c,d);const g=Nt(H(c,le(C=>C===void 0)),!0);he(H(d,ke(C=>C!==void 0&&ot(vt(m).sizeTree)),le(C=>[{endIndex:0,size:C,startIndex:0}])),n);const b=Ht(H(n,De(m),xn(({sizes:C},[T,I])=>({changed:I!==C,sizes:I}),{changed:!1,sizes:x}),le(C=>C.changed)));Je(H(a,xn((C,T)=>({diff:C.prev-T,prev:T}),{diff:0,prev:0}),le(C=>C.diff)),C=>{const{groupIndices:T}=vt(m);if(C>0)Me(t,!0),Me(s,C+Ld(C,T));else if(C<0){const I=vt(y);I.length>0&&(C-=Ld(-C,I)),Me(i,C)}}),Je(H(a,De(e)),([C,T])=>{C<0&&T("`firstItemIndex` prop should not be set to less than zero. If you don't know the total count, just use a very high value",{firstItemIndex:a},Bt.ERROR)});const S=Ht(s);he(H(s,De(m),le(([C,T])=>{const I=T.groupIndices.length>0,A=[],R=T.lastSize;if(I){const L=qr(T.sizeTree,0);let P=0,D=0;for(;P<C;){const N=T.groupIndices[D],B=T.groupIndices.length===D+1?1/0:T.groupIndices[D+1]-N-1;A.push({endIndex:N,size:L,startIndex:N}),A.push({endIndex:N+1+B-1,size:R,startIndex:N+1}),D++,P+=B+1}const F=Zn(T.sizeTree);return P!==C&&F.shift(),F.reduce((N,{k:B,v:j})=>{let V=N.ranges;return N.prevSize!==0&&(V=[...N.ranges,{endIndex:B+C-1,size:N.prevSize,startIndex:N.prevIndex}]),{prevIndex:B+C,prevSize:j,ranges:V}},{prevIndex:C,prevSize:0,ranges:A}).ranges}return Zn(T.sizeTree).reduce((L,{k:P,v:D})=>({prevIndex:P+C,prevSize:D,ranges:[...L.ranges,{endIndex:P+C-1,size:L.prevSize,startIndex:L.prevIndex}]}),{prevIndex:0,prevSize:R,ranges:[]}).ranges})),n);const k=Ht(H(i,De(m,h),le(([C,{offsetTree:T},I])=>{const A=-C;return Yr(A,T,I)})));return he(H(i,De(m,h),le(([C,T,I])=>{if(T.groupIndices.length>0){if(ot(T.sizeTree))return T;let A=Tr();const R=vt(y);let L=0,P=0,D=0;for(;L<-C;){D=R[P];const F=R[P+1]-D-1;P++,L+=F+1}if(A=Zn(T.sizeTree).reduce((F,{k:N,v:B})=>Wt(F,Math.max(0,N+C),B),A),L!==-C){const F=qr(T.sizeTree,D);A=Wt(A,0,F);const N=an(T.sizeTree,-C+1)[1];A=Wt(A,1,N)}return{...T,sizeTree:A,...ca(T.offsetTree,0,A,I)}}else{const A=Zn(T.sizeTree).reduce((R,{k:L,v:P})=>Wt(R,Math.max(0,L+C),P),Tr());return{...T,sizeTree:A,...ca(T.offsetTree,0,A,I)}}})),m),{beforeUnshiftWith:S,data:p,defaultItemSize:d,firstItemIndex:a,fixedItemSize:c,gap:h,groupIndices:l,itemSize:f,listRefresh:b,shiftWith:i,shiftWithOffset:k,sizeRanges:n,sizes:m,statefulTotalCount:o,totalCount:r,trackItemSizes:g,unshiftWith:s}},ct(Mn,aa),{singleton:!0});function Uw(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const $d=We(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=ze(),i=ze(),a=Ht(H(s,le(Uw)));return he(H(a,le(l=>l.totalCount)),n),he(H(a,le(l=>l.groupIndices)),e),he(H(wt(o,t,r),ke(([l,c])=>ms(c)),le(([l,c,d])=>an(c.groupOffsetTree,Math.max(l-d,0),"v")[0]),ut(),le(l=>[l])),i),{groupCounts:s,topItemsIndexes:i}},ct(yn,Dt)),On=We(([{log:e}])=>{const t=ee(!1),n=Ht(H(t,ke(r=>r),ut()));return Je(t,r=>{r&&vt(e)("props updated",{},Bt.DEBUG)}),{didMount:n,propsReady:t}},ct(Mn),{singleton:!0}),Hw=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function Fd(e){const t=typeof e=="number"?{index:e}:e;return t.align||(t.align="start"),(!t.behavior||!Hw)&&(t.behavior="auto"),t.offset||(t.offset=0),t}const Xr=We(([{gap:e,listRefresh:t,sizes:n,totalCount:r},{fixedFooterHeight:o,fixedHeaderHeight:s,footerHeight:i,headerHeight:a,scrollingInProgress:l,scrollTo:c,smoothScrollTargetReached:d,viewportHeight:f},{log:p}])=>{const h=ze(),x=ze(),m=ee(0);let y=null,g=null,b=null;function S(){y&&(y(),y=null),b&&(b(),b=null),g&&(clearTimeout(g),g=null),Me(l,!1)}return he(H(h,De(n,f,r,m,a,i,p),De(e,s,o),le(([[k,C,T,I,A,R,L,P],D,F,N])=>{const B=Fd(k),{align:j,behavior:V,offset:z}=B,M=I-1,q=Dd(B,C,M);let J=Yr(q,C.offsetTree,D)+R;j==="end"?(J+=F+an(C.sizeTree,q)[1]-T+N,q===M&&(J+=L)):j==="center"?J+=(F+an(C.sizeTree,q)[1]-T+N)/2:J-=A,z&&(J+=z);const se=ge=>{S(),ge?(P("retrying to scroll to",{location:k},Bt.DEBUG),Me(h,k)):(Me(x,!0),P("list did not change, scroll successful",{},Bt.DEBUG))};if(S(),V==="smooth"){let ge=!1;b=Je(t,Ee=>{ge=ge||Ee}),y=sn(d,()=>{se(ge)})}else y=sn(H(t,Ww(150)),se);return g=setTimeout(()=>{S()},1200),Me(l,!0),P("scrolling from index to",{behavior:V,index:q,top:J},Bt.DEBUG),{behavior:V,top:J}})),c),{scrollTargetReached:x,scrollToIndex:h,topListHeight:m}},ct(yn,Dt,Mn),{singleton:!0});function Ww(e){return t=>{const n=setTimeout(()=>{t(!1)},e);return r=>{r&&(t(!0),clearTimeout(n))}}}function ua(e,t){e==0?t():requestAnimationFrame(()=>{ua(e-1,t)})}function da(e,t){const n=t-1;return typeof e=="number"?e:e.index==="LAST"?n:e.index}const Jr=We(([{defaultItemSize:e,listRefresh:t,sizes:n},{scrollTop:r},{scrollTargetReached:o,scrollToIndex:s},{didMount:i}])=>{const a=ee(!0),l=ee(0),c=ee(!0);return he(H(i,De(l),ke(([d,f])=>!!f),gn(!1)),a),he(H(i,De(l),ke(([d,f])=>!!f),gn(!1)),c),Je(H(wt(t,i),De(a,n,e,c),ke(([[,d],f,{sizeTree:p},h,x])=>d&&(!ot(p)||Qi(h))&&!f&&!x),De(l)),([,d])=>{sn(o,()=>{Me(c,!0)}),ua(4,()=>{sn(r,()=>{Me(a,!0)}),Me(s,d)})}),{initialItemFinalLocationReached:c,initialTopMostItemIndex:l,scrolledToInitialItem:a}},ct(yn,Dt,Xr,On),{singleton:!0});function Bd(e,t){return Math.abs(e-t)<1.01}const Zr="up",Qr="down",Vw="none",Kw={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},qw=0,eo=We(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:o,viewportHeight:s}])=>{const i=ee(!1),a=ee(!0),l=ze(),c=ze(),d=ee(4),f=ee(qw),p=Nt(H(ta(H(Te(o),Xn(1),gn(!0)),H(Te(o),Xn(1),gn(!1),Cd(100))),ut()),!1),h=Nt(H(ta(H(n,gn(!0)),H(n,gn(!1),Cd(200))),ut()),!1);he(H(wt(Te(o),Te(f)),le(([b,S])=>b<=S),ut()),a),he(H(a,In(50)),c);const x=Ht(H(wt(r,Te(s),Te(t),Te(e),Te(d)),xn((b,[{scrollHeight:S,scrollTop:k},C,T,I,A])=>{const R=k+C-S>-A,L={scrollHeight:S,scrollTop:k,viewportHeight:C};if(R){let D,F;return k>b.state.scrollTop?(D="SCROLLED_DOWN",F=b.state.scrollTop-k):(D="SIZE_DECREASED",F=b.state.scrollTop-k||b.scrollTopDelta),{atBottom:!0,atBottomBecause:D,scrollTopDelta:F,state:L}}let P;return L.scrollHeight>b.state.scrollHeight?P="SIZE_INCREASED":C<b.state.viewportHeight?P="VIEWPORT_HEIGHT_DECREASING":k<b.state.scrollTop?P="SCROLLING_UPWARDS":P="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:P,state:L}},Kw),ut((b,S)=>b&&b.atBottom===S.atBottom))),m=Nt(H(r,xn((b,{scrollHeight:S,scrollTop:k,viewportHeight:C})=>{if(Bd(b.scrollHeight,S))return{changed:!1,jump:0,scrollHeight:S,scrollTop:k};{const T=S-(k+C)<1;return b.scrollTop!==k&&T?{changed:!0,jump:b.scrollTop-k,scrollHeight:S,scrollTop:k}:{changed:!0,jump:0,scrollHeight:S,scrollTop:k}}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),ke(b=>b.changed),le(b=>b.jump)),0);he(H(x,le(b=>b.atBottom)),i),he(H(i,In(50)),l);const y=ee(Qr);he(H(r,le(({scrollTop:b})=>b),ut(),xn((b,S)=>vt(h)?{direction:b.direction,prevScrollTop:S}:{direction:S<b.prevScrollTop?Zr:Qr,prevScrollTop:S},{direction:Qr,prevScrollTop:0}),le(b=>b.direction)),y),he(H(r,In(50),gn(Vw)),y);const g=ee(0);return he(H(p,ke(b=>!b),gn(0)),g),he(H(o,In(100),De(p),ke(([b,S])=>!!S),xn(([b,S],[k])=>[S,k],[0,0]),le(([b,S])=>S-b)),g),{atBottomState:x,atBottomStateChange:l,atBottomThreshold:d,atTopStateChange:c,atTopThreshold:f,isAtBottom:i,isAtTop:a,isScrolling:p,lastJumpDueToItemResize:m,scrollDirection:y,scrollVelocity:g}},ct(Dt)),gs="top",xs="bottom",zd="none";function Ud(e,t,n){return typeof e=="number"?n===Zr&&t===gs||n===Qr&&t===xs?e:0:n===Zr?t===gs?e.main:e.reverse:t===xs?e.main:e.reverse}function Hd(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const fa=We(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:o}])=>{const s=ze(),i=ee(0),a=ee(0),l=ee(0),c=Nt(H(wt(Te(r),Te(o),Te(n),Te(s,Gr),Te(l),Te(i),Te(t),Te(e),Te(a)),le(([d,f,p,[h,x],m,y,g,b,S])=>{const k=d-b,C=y+g,T=Math.max(p-k,0);let I=zd;const A=Hd(S,gs),R=Hd(S,xs);return h-=b,h+=p+g,x+=p+g,x-=b,h>d+C-A&&(I=Zr),x<d-T+f+R&&(I=Qr),I!==zd?[Math.max(k-p-Ud(m,gs,I)-A,0),k-T-g+f+Ud(m,xs,I)+R]:null}),ke(d=>d!=null),ut(Gr)),[0,0]);return{increaseViewportBy:a,listBoundary:s,overscan:l,topListHeight:i,visibleRange:c}},ct(Dt),{singleton:!0});function Gw(e,t,n){if(ms(t)){const r=Od(e,t);return[{index:an(t.groupOffsetTree,r)[0],offset:0,size:0},{data:n==null?void 0:n[0],index:r,offset:0,size:0}]}return[{data:n==null?void 0:n[0],index:e,offset:0,size:0}]}const pa={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function ys(e,t,n,r,o,s){const{lastIndex:i,lastOffset:a,lastSize:l}=o;let c=0,d=0;if(e.length>0){c=e[0].offset;const m=e[e.length-1];d=m.offset+m.size}const f=n-i,p=a+f*l+(f-1)*r,h=c,x=p-d;return{bottom:d,firstItemIndex:s,items:Vd(e,o,s),offsetBottom:x,offsetTop:c,top:h,topItems:Vd(t,o,s),topListHeight:t.reduce((m,y)=>y.size+m,0),totalCount:n}}function Wd(e,t,n,r,o,s){let i=0;if(n.groupIndices.length>0)for(const d of n.groupIndices){if(d-i>=e)break;i++}const a=e+i,l=da(t,a),c=Array.from({length:a}).map((d,f)=>({data:s[f+l],index:f+l,offset:0,size:0}));return ys(c,[],a,o,n,r)}function Vd(e,t,n){if(e.length===0)return[];if(!ms(t))return e.map(c=>({...c,index:c.index+n,originalIndex:c.index}));const r=e[0].index,o=e[e.length-1].index,s=[],i=fs(t.groupOffsetTree,r,o);let a,l=0;for(const c of e){(!a||a.end<c.index)&&(a=i.shift(),l=t.groupIndices.indexOf(a.start));let d;c.index===a.start?d={index:l,type:"group"}:d={groupIndex:l,index:c.index-(l+1)+n},s.push({...d,data:c.data,offset:c.offset,originalIndex:c.index,size:c.size})}return s}const Qn=We(([{data:e,firstItemIndex:t,gap:n,sizes:r,totalCount:o},s,{listBoundary:i,topListHeight:a,visibleRange:l},{initialTopMostItemIndex:c,scrolledToInitialItem:d},{topListHeight:f},p,{didMount:h},{recalcInProgress:x}])=>{const m=ee([]),y=ee(0),g=ze();he(s.topItemsIndexes,m);const b=Nt(H(wt(h,x,Te(l,Gr),Te(o),Te(r),Te(c),d,Te(m),Te(t),Te(n),e),ke(([T,I,,A,,,,,,,R])=>{const L=R&&R.length!==A;return T&&!I&&!L}),le(([,,[T,I],A,R,L,P,D,F,N,B])=>{const j=R,{offsetTree:V,sizeTree:z}=j,M=vt(y);if(A===0)return{...pa,totalCount:A};if(T===0&&I===0)return M===0?{...pa,totalCount:A}:Wd(M,L,R,F,N,B||[]);if(ot(z))return M>0?null:ys(Gw(da(L,A),j,B),[],A,N,j,F);const q=[];if(D.length>0){const Y=D[0],U=D[D.length-1];let Z=0;for(const $ of fs(z,Y,U)){const K=$.value,Q=Math.max($.start,Y),ce=Math.min($.end,U);for(let oe=Q;oe<=ce;oe++)q.push({data:B==null?void 0:B[oe],index:oe,offset:Z,size:K}),Z+=K}}if(!P)return ys([],q,A,N,j,F);const J=D.length>0?D[D.length-1]+1:0,se=Dw(V,T,I,J);if(se.length===0)return null;const ge=A-1,Ee=ds([],Y=>{for(const U of se){const Z=U.value;let $=Z.offset,K=U.start;const Q=Z.size;if(Z.offset<T){K+=Math.floor((T-Z.offset+N)/(Q+N));const oe=K-U.start;$+=oe*Q+oe*N}K<J&&($+=(J-K)*Q,K=J);const ce=Math.min(U.end,ge);for(let oe=K;oe<=ce&&!($>=I);oe++)Y.push({data:B==null?void 0:B[oe],index:oe,offset:$,size:Q}),$+=Q+N}});return ys(Ee,q,A,N,j,F)}),ke(T=>T!==null),ut()),pa);he(H(e,ke(Qi),le(T=>T==null?void 0:T.length)),o),he(H(b,le(T=>T.topListHeight)),f),he(f,a),he(H(b,le(T=>[T.top,T.bottom])),i),he(H(b,le(T=>T.items)),g);const S=Ht(H(b,ke(({items:T})=>T.length>0),De(o,e),ke(([{items:T},I])=>T[T.length-1].originalIndex===I-1),le(([,T,I])=>[T-1,I]),ut(Gr),le(([T])=>T))),k=Ht(H(b,In(200),ke(({items:T,topItems:I})=>T.length>0&&T[0].originalIndex===I.length),le(({items:T})=>T[0].index),ut())),C=Ht(H(b,ke(({items:T})=>T.length>0),le(({items:T})=>{let I=0,A=T.length-1;for(;T[I].type==="group"&&I<A;)I++;for(;T[A].type==="group"&&A>I;)A--;return{endIndex:T[A].index,startIndex:T[I].index}}),ut(Md)));return{endReached:S,initialItemCount:y,itemsRendered:g,listState:b,rangeChanged:C,startReached:k,topItemsIndexes:m,...p}},ct(yn,$d,fa,Jr,Xr,eo,On,aa),{singleton:!0}),Kd=We(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:o}])=>{const s=ze(),i=Nt(H(wt(n,e,r,t,o),le(([a,l,c,d,f])=>a+l+c+d+f.offsetBottom+f.bottom)),0);return he(Te(i),s),{totalListHeight:i,totalListHeightChanged:s}},ct(Dt,Qn),{singleton:!0}),Yw=We(([{viewportHeight:e},{totalListHeight:t}])=>{const n=ee(!1),r=Nt(H(wt(n,e,t),ke(([o])=>o),le(([,o,s])=>Math.max(0,o-s)),In(0),ut()),0);return{alignToBottom:n,paddingTopAddition:r}},ct(Dt,Kd),{singleton:!0}),qd=We(()=>({context:ee(null)})),Xw=({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,Gd=We(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:s,scrollingInProgress:i,scrollTop:a,viewportHeight:l},{scrollToIndex:c}])=>{const d=ze();return he(H(d,De(t,l,n,s,o,r,a),De(e),le(([[f,p,h,x,m,y,g,b],S])=>{const{align:k,behavior:C,calculateViewLocation:T=Xw,done:I,...A}=f,R=Dd(f,p,x-1),L=Yr(R,p.offsetTree,S)+m+y,P=L+an(p.sizeTree,R)[1],D=b+y,F=b+h-g,N=T({itemBottom:P,itemTop:L,locationParams:{align:k,behavior:C,...A},viewportBottom:F,viewportTop:D});return N?I&&sn(H(i,ke(B=>!B),Xn(vt(i)?1:2)),I):I&&I(),N}),ke(f=>f!==null)),c),{scrollIntoView:d}},ct(yn,Dt,Xr,Qn,Mn),{singleton:!0});function Yd(e){return e?e==="smooth"?"smooth":"auto":!1}const Jw=(e,t)=>typeof e=="function"?Yd(e(t)):t&&Yd(e),Zw=We(([{listRefresh:e,totalCount:t,fixedItemSize:n,data:r},{atBottomState:o,isAtBottom:s},{scrollToIndex:i},{scrolledToInitialItem:a},{didMount:l,propsReady:c},{log:d},{scrollingInProgress:f},{context:p},{scrollIntoView:h}])=>{const x=ee(!1),m=ze();let y=null;function g(C){Me(i,{align:"end",behavior:C,index:"LAST"})}Je(H(wt(H(Te(t),Xn(1)),l),De(Te(x),s,a,f),le(([[C,T],I,A,R,L])=>{let P=T&&R,D="auto";return P&&(D=Jw(I,A||L),P=P&&!!D),{followOutputBehavior:D,shouldFollow:P,totalCount:C}}),ke(({shouldFollow:C})=>C)),({followOutputBehavior:C,totalCount:T})=>{y&&(y(),y=null),vt(n)?requestAnimationFrame(()=>{vt(d)("following output to ",{totalCount:T},Bt.DEBUG),g(C)}):y=sn(e,()=>{vt(d)("following output to ",{totalCount:T},Bt.DEBUG),g(C),y=null})});function b(C){const T=sn(o,I=>{C&&!I.atBottom&&I.notAtBottomBecause==="SIZE_INCREASED"&&!y&&(vt(d)("scrolling to bottom due to increased size",{},Bt.DEBUG),g("auto"))});setTimeout(T,100)}Je(H(wt(Te(x),t,c),ke(([C,,T])=>C&&T),xn(({value:C},[,T])=>({refreshed:C===T,value:T}),{refreshed:!1,value:0}),ke(({refreshed:C})=>C),De(x,t)),([,C])=>{vt(a)&&b(C!==!1)}),Je(m,()=>{b(vt(x)!==!1)}),Je(wt(Te(x),o),([C,T])=>{C&&!T.atBottom&&T.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&g("auto")});const S=ee(null),k=ze();return he(ta(H(Te(r),le(C=>{var T;return(T=C==null?void 0:C.length)!=null?T:0})),H(Te(t))),k),Je(H(wt(H(k,Xn(1)),l),De(Te(S),a,f,p),le(([[C,T],I,A,R,L])=>T&&A&&(I==null?void 0:I({context:L,totalCount:C,scrollingInProgress:R}))),ke(C=>!!C),In(0)),C=>{y&&(y(),y=null),vt(n)?requestAnimationFrame(()=>{vt(d)("scrolling into view",{}),Me(h,C)}):y=sn(e,()=>{vt(d)("scrolling into view",{}),Me(h,C),y=null})}),{autoscrollToBottom:m,followOutput:x,scrollIntoViewOnChange:S}},ct(yn,eo,Xr,Jr,On,Mn,Dt,qd,Gd)),Qw=We(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:s,listState:i},{didMount:a}])=>(he(H(a,De(s),ke(([,l])=>l!==0),De(o,r,t,n,e),le(([[,l],c,d,f,p,h=[]])=>Wd(l,c,d,f,p,h))),i),{}),ct(yn,Jr,Qn,On),{singleton:!0}),e0=We(([{didMount:e},{scrollTo:t},{listState:n}])=>{const r=ee(0);return Je(H(e,De(r),ke(([,o])=>o!==0),le(([,o])=>({top:o}))),o=>{sn(H(n,Xn(1),ke(s=>s.items.length>1)),()=>{requestAnimationFrame(()=>{Me(t,o)})})}),{initialScrollTop:r}},ct(On,Dt,Qn),{singleton:!0}),Xd=We(([{scrollVelocity:e}])=>{const t=ee(!1),n=ze(),r=ee(!1);return he(H(e,De(r,t,n),ke(([o,s])=>!!s),le(([o,s,i,a])=>{const{enter:l,exit:c}=s;if(i){if(c(o,a))return!1}else if(l(o,a))return!0;return i}),ut()),t),Je(H(wt(t,e,n),De(r)),([[o,s,i],a])=>{o&&a&&a.change&&a.change(s,i)}),{isSeeking:t,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:e}},ct(eo),{singleton:!0}),ha=We(([{scrollContainerState:e,scrollTo:t}])=>{const n=ze(),r=ze(),o=ze(),s=ee(!1),i=ee(void 0);return he(H(wt(n,r),le(([{scrollHeight:a,scrollTop:l,viewportHeight:c},{offsetTop:d}])=>({scrollHeight:a,scrollTop:Math.max(0,l-d),viewportHeight:c}))),e),he(H(t,De(r),le(([a,{offsetTop:l}])=>({...a,top:a.top+l}))),o),{customScrollParent:i,useWindowScroll:s,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:r}},ct(Dt)),t0=We(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:o},{didMount:s},{useWindowScroll:i,windowScrollContainerState:a,windowViewportRect:l}])=>{const c=ze(),d=ee(void 0),f=ee(null),p=ee(null);return he(a,f),he(l,p),Je(H(c,De(t,r,i,f,p,n)),([h,x,m,y,g,b,S])=>{const k=$w(x.sizeTree);y&&g!==null&&b!==null&&(m=g.scrollTop-b.offsetTop),m-=S,h({ranges:k,scrollTop:m})}),he(H(d,ke(Qi),le(n0)),o),he(H(s,De(d),ke(([,h])=>h!==void 0),ut(),le(([,h])=>h.ranges)),e),{getState:c,restoreStateFrom:d}},ct(yn,Dt,Jr,On,ha));function n0(e){return{align:"start",index:0,offset:e.scrollTop}}const r0=We(([{topItemsIndexes:e}])=>{const t=ee(0);return he(H(t,ke(n=>n>=0),le(n=>Array.from({length:n}).map((r,o)=>o))),e),{topItemCount:t}},ct(Qn));function Jd(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const o0=Jd(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),s0=We(([{deviation:e,scrollBy:t,scrollingInProgress:n,scrollTop:r},{isAtBottom:o,isScrolling:s,lastJumpDueToItemResize:i,scrollDirection:a},{listState:l},{beforeUnshiftWith:c,gap:d,shiftWithOffset:f,sizes:p},{log:h},{recalcInProgress:x}])=>{const m=Ht(H(l,De(i),xn(([,g,b,S],[{bottom:k,items:C,offsetBottom:T,totalCount:I},A])=>{const R=k+T;let L=0;return b===I&&g.length>0&&C.length>0&&(C[0].originalIndex===0&&g[0].originalIndex===0||(L=R-S,L!==0&&(L+=A))),[L,C,I,R]},[0,[],0,0]),ke(([g])=>g!==0),De(r,a,n,o,h,x),ke(([,g,b,S,,,k])=>!k&&!S&&g!==0&&b===Zr),le(([[g],,,,,b])=>(b("Upward scrolling compensation",{amount:g},Bt.DEBUG),g))));function y(g){g>0?(Me(t,{behavior:"auto",top:-g}),Me(e,0)):(Me(e,0),Me(t,{behavior:"auto",top:-g}))}return Je(H(m,De(e,s)),([g,b,S])=>{S&&o0()?Me(e,b-g):y(-g)}),Je(H(wt(Nt(s,!1),e,x),ke(([g,b,S])=>!g&&!S&&b!==0),le(([g,b])=>b),In(1)),y),he(H(f,le(g=>({top:-g}))),t),Je(H(c,De(p,d),le(([g,{groupIndices:b,lastSize:S,sizeTree:k},C])=>{function T(I){return I*(S+C)}if(b.length===0)return T(g);{let I=0;const A=qr(k,0);let R=0,L=0;for(;R<g;){R++,I+=A;let P=b.length===L+1?1/0:b[L+1]-b[L]-1;R+P>g&&(I-=A,P=g-R+1),R+=P,I+=T(P),L++}return I}})),g=>{Me(e,g),requestAnimationFrame(()=>{Me(t,{top:g}),requestAnimationFrame(()=>{Me(e,0),Me(x,!1)})})}),{deviation:e}},ct(Dt,eo,Qn,yn,Mn,aa)),i0=We(([e,t,n,r,o,s,i,a,l,c,d])=>({...e,...t,...n,...r,...o,...s,...i,...a,...l,...c,...d}),ct(fa,Qw,On,Xd,Kd,e0,Yw,ha,Gd,Mn,qd)),Zd=We(([{data:e,defaultItemSize:t,firstItemIndex:n,fixedItemSize:r,gap:o,groupIndices:s,itemSize:i,sizeRanges:a,sizes:l,statefulTotalCount:c,totalCount:d,trackItemSizes:f},{initialItemFinalLocationReached:p,initialTopMostItemIndex:h,scrolledToInitialItem:x},m,y,g,{listState:b,topItemsIndexes:S,...k},{scrollToIndex:C},T,{topItemCount:I},{groupCounts:A},R])=>(he(k.rangeChanged,R.scrollSeekRangeChanged),he(H(R.windowViewportRect,le(L=>L.visibleHeight)),m.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:n,fixedItemHeight:r,gap:o,groupCounts:A,initialItemFinalLocationReached:p,initialTopMostItemIndex:h,scrolledToInitialItem:x,sizeRanges:a,topItemCount:I,topItemsIndexes:S,totalCount:d,...g,groupIndices:s,itemSize:i,listState:b,scrollToIndex:C,statefulTotalCount:c,trackItemSizes:f,...k,...R,...m,sizes:l,...y}),ct(yn,Jr,Dt,t0,Zw,Qn,Xr,s0,r0,$d,i0));function a0(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 vs=typeof document<"u"?w.useLayoutEffect:w.useEffect;function Qd(e,t,n){const r=Object.keys(t.required||{}),o=Object.keys(t.optional||{}),s=Object.keys(t.methods||{}),i=Object.keys(t.events||{}),a=w.createContext({});function l(y,g){y.propsReady&&Me(y.propsReady,!1);for(const b of r){const S=y[t.required[b]];Me(S,g[b])}for(const b of o)if(b in g){const S=y[t.optional[b]];Me(S,g[b])}y.propsReady&&Me(y.propsReady,!0)}function c(y){return s.reduce((g,b)=>(g[b]=S=>{const k=y[t.methods[b]];Me(k,S)},g),{})}function d(y){return i.reduce((g,b)=>(g[b]=Cw(y[t.events[b]]),g),{})}const f=w.forwardRef((y,g)=>{const{children:b,...S}=y,[k]=w.useState(()=>ds(kw(e),I=>{l(I,S)})),[C]=w.useState(Sd(d,k));vs(()=>{for(const I of i)I in S&&Je(C[I],S[I]);return()=>{Object.values(C).map(ea)}},[S,C,k]),vs(()=>{l(k,S)}),w.useImperativeHandle(g,bd(c(k)));const T=n;return u.jsx(a.Provider,{value:k,children:n?u.jsx(T,{...a0([...r,...o,...i],S),children:b}):b})}),p=y=>{const g=w.useContext(a);return w.useCallback(b=>{Me(g[y],b)},[g,y])},h=y=>{const g=w.useContext(a)[y],b=w.useCallback(S=>Je(g,S),[g]);return w.useSyncExternalStore(b,()=>vt(g),()=>vt(g))},x=y=>{const g=w.useContext(a)[y],[b,S]=w.useState(Sd(vt,g));return vs(()=>Je(g,k=>{k!==b&&S(bd(k))}),[g,b]),b},m=w.version.startsWith("18")?h:x;return{Component:f,useEmitter:(y,g)=>{const b=w.useContext(a)[y];vs(()=>Je(b,g),[g,b])},useEmitterValue:m,usePublisher:p}}const ef=w.createContext(void 0),tf=w.createContext(void 0),nf=typeof document<"u"?w.useLayoutEffect:w.useEffect;function ma(e){return"self"in e}function l0(e){return"body"in e}function rf(e,t,n,r=Cr,o,s){const i=w.useRef(null),a=w.useRef(null),l=w.useRef(null),c=w.useCallback(p=>{let h,x,m;const y=p.target;if(l0(y)||ma(y)){const b=ma(y)?y:y.defaultView;m=s?b.scrollX:b.scrollY,h=s?b.document.documentElement.scrollWidth:b.document.documentElement.scrollHeight,x=s?b.innerWidth:b.innerHeight}else m=s?y.scrollLeft:y.scrollTop,h=s?y.scrollWidth:y.scrollHeight,x=s?y.offsetWidth:y.offsetHeight;const g=()=>{e({scrollHeight:h,scrollTop:Math.max(m,0),viewportHeight:x})};p.suppressFlushSync?g():Gs.flushSync(g),a.current!==null&&(m===a.current||m<=0||m===h-x)&&(a.current=null,t(!0),l.current&&(clearTimeout(l.current),l.current=null))},[e,t,s]);w.useEffect(()=>{const p=o||i.current;return r(o||i.current),c({suppressFlushSync:!0,target:p}),p.addEventListener("scroll",c,{passive:!0}),()=>{r(null),p.removeEventListener("scroll",c)}},[i,c,n,r,o]);function d(p){const h=i.current;if(!h||(s?"offsetWidth"in h&&h.offsetWidth===0:"offsetHeight"in h&&h.offsetHeight===0))return;const x=p.behavior==="smooth";let m,y,g;ma(h)?(y=Math.max(Pn(h.document.documentElement,s?"width":"height"),s?h.document.documentElement.scrollWidth:h.document.documentElement.scrollHeight),m=s?h.innerWidth:h.innerHeight,g=s?window.scrollX:window.scrollY):(y=h[s?"scrollWidth":"scrollHeight"],m=Pn(h,s?"width":"height"),g=h[s?"scrollLeft":"scrollTop"]);const b=y-m;if(p.top=Math.ceil(Math.max(Math.min(b,p.top),0)),Bd(m,y)||p.top===g){e({scrollHeight:y,scrollTop:g,viewportHeight:m}),x&&t(!0);return}x?(a.current=p.top,l.current&&clearTimeout(l.current),l.current=setTimeout(()=>{l.current=null,a.current=null,t(!0)},1e3)):a.current=null,s&&(p={behavior:p.behavior,left:p.top}),h.scrollTo(p)}function f(p){s&&(p={behavior:p.behavior,left:p.top}),i.current.scrollBy(p)}return{scrollByCallback:f,scrollerRef:i,scrollToCallback:d}}const ga="-webkit-sticky",of="sticky",xa=Jd(()=>{if(typeof document>"u")return of;const e=document.createElement("div");return e.style.position=ga,e.style.position===ga?ga:of});function ya(e){return e}const c0=We(()=>{const e=ee(a=>`Item ${a}`),t=ee(a=>`Group ${a}`),n=ee({}),r=ee(ya),o=ee("div"),s=ee(Cr),i=(a,l=null)=>Nt(H(n,le(c=>c[a]),ut()),l);return{components:n,computeItemKey:r,EmptyPlaceholder:i("EmptyPlaceholder"),FooterComponent:i("Footer"),GroupComponent:i("Group","div"),groupContent:t,HeaderComponent:i("Header"),HeaderFooterTag:o,ItemComponent:i("Item","div"),itemContent:e,ListComponent:i("List","div"),ScrollerComponent:i("Scroller","div"),scrollerRef:s,ScrollSeekPlaceholder:i("ScrollSeekPlaceholder"),TopItemListComponent:i("TopItemList")}}),u0=We(([e,t])=>({...e,...t}),ct(Zd,c0)),d0=({height:e})=>u.jsx("div",{style:{height:e}}),f0={overflowAnchor:"none",position:xa(),zIndex:1},sf={overflowAnchor:"none"},p0={...sf,display:"inline-block",height:"100%"},af=w.memo(function({showTopList:e=!1}){const t=Ae("listState"),n=Jt("sizeRanges"),r=Ae("useWindowScroll"),o=Ae("customScrollParent"),s=Jt("windowScrollContainerState"),i=Jt("scrollContainerState"),a=o||r?s:i,l=Ae("itemContent"),c=Ae("context"),d=Ae("groupContent"),f=Ae("trackItemSizes"),p=Ae("itemSize"),h=Ae("log"),x=Jt("gap"),m=Ae("horizontalDirection"),{callbackRef:y}=Aw(n,p,f,e?Cr:a,h,x,o,m,Ae("skipAnimationFrameInResizeObserver")),[g,b]=w.useState(0);va("deviation",N=>{g!==N&&b(N)});const S=Ae("EmptyPlaceholder"),k=Ae("ScrollSeekPlaceholder")||d0,C=Ae("ListComponent"),T=Ae("ItemComponent"),I=Ae("GroupComponent"),A=Ae("computeItemKey"),R=Ae("isSeeking"),L=Ae("groupIndices").length>0,P=Ae("alignToBottom"),D=Ae("initialItemFinalLocationReached"),F=e?{}:{boxSizing:"border-box",...m?{display:"inline-block",height:"100%",marginLeft:g!==0?g:P?"auto":0,paddingLeft:t.offsetTop,paddingRight:t.offsetBottom,whiteSpace:"nowrap"}:{marginTop:g!==0?g:P?"auto":0,paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},...D?{}:{visibility:"hidden"}};return!e&&t.totalCount===0&&S?u.jsx(S,{..._t(S,c)}):u.jsx(C,{..._t(C,c),"data-testid":e?"virtuoso-top-item-list":"virtuoso-item-list",ref:y,style:F,children:(e?t.topItems:t.items).map(N=>{const B=N.originalIndex,j=A(B+t.firstItemIndex,N.data,c);return R?w.createElement(k,{..._t(k,c),height:N.size,index:N.index,key:j,type:N.type||"item",...N.type==="group"?{}:{groupIndex:N.groupIndex}}):N.type==="group"?w.createElement(I,{..._t(I,c),"data-index":B,"data-item-index":N.index,"data-known-size":N.size,key:j,style:f0},d(N.index,c)):w.createElement(T,{..._t(T,c),...x0(T,N.data),"data-index":B,"data-item-group-index":N.groupIndex,"data-item-index":N.index,"data-known-size":N.size,key:j,style:m?p0:sf},L?l(N.index,N.groupIndex,N.data,c):l(N.index,N.data,c))})})}),h0={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},m0={outline:"none",overflowX:"auto",position:"relative"},bs=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),g0={position:xa(),top:0,width:"100%",zIndex:1};function _t(e,t){if(typeof e!="string")return{context:t}}function x0(e,t){return{item:typeof e=="string"?void 0:t}}const y0=w.memo(function(){const e=Ae("HeaderComponent"),t=Jt("headerHeight"),n=Ae("HeaderFooterTag"),r=Jn(w.useMemo(()=>s=>{t(Pn(s,"height"))},[t]),!0,Ae("skipAnimationFrameInResizeObserver")),o=Ae("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{..._t(e,o)})}):null}),v0=w.memo(function(){const e=Ae("FooterComponent"),t=Jt("footerHeight"),n=Ae("HeaderFooterTag"),r=Jn(w.useMemo(()=>s=>{t(Pn(s,"height"))},[t]),!0,Ae("skipAnimationFrameInResizeObserver")),o=Ae("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{..._t(e,o)})}):null});function lf({useEmitter:e,useEmitterValue:t,usePublisher:n}){return w.memo(function({children:r,style:o,context:s,...i}){const a=n("scrollContainerState"),l=t("ScrollerComponent"),c=n("smoothScrollTargetReached"),d=t("scrollerRef"),f=t("horizontalDirection")||!1,{scrollByCallback:p,scrollerRef:h,scrollToCallback:x}=rf(a,c,l,d,void 0,f);return e("scrollTo",x),e("scrollBy",p),u.jsx(l,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:h,style:{...f?m0:h0,...o},tabIndex:0,...i,..._t(l,s),children:r})})}function cf({useEmitter:e,useEmitterValue:t,usePublisher:n}){return w.memo(function({children:r,style:o,context:s,...i}){const a=n("windowScrollContainerState"),l=t("ScrollerComponent"),c=n("smoothScrollTargetReached"),d=t("totalListHeight"),f=t("deviation"),p=t("customScrollParent"),h=w.useRef(null),x=t("scrollerRef"),{scrollByCallback:m,scrollerRef:y,scrollToCallback:g}=rf(a,c,l,x,p);return nf(()=>{var b;return y.current=p||((b=h.current)==null?void 0:b.ownerDocument.defaultView),()=>{y.current=null}},[y,p]),e("windowScrollTo",g),e("scrollBy",m),u.jsx(l,{ref:h,"data-virtuoso-scroller":!0,style:{position:"relative",...o,...d!==0?{height:d+f}:{}},...i,..._t(l,s),children:r})})}const b0=({children:e})=>{const t=w.useContext(ef),n=Jt("viewportHeight"),r=Jt("fixedItemHeight"),o=Ae("alignToBottom"),s=Ae("horizontalDirection"),i=w.useMemo(()=>wd(n,l=>Pn(l,s?"width":"height")),[n,s]),a=Jn(i,!0,Ae("skipAnimationFrameInResizeObserver"));return w.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),u.jsx("div",{"data-viewport-type":"element",ref:a,style:bs(o),children:e})},w0=({children:e})=>{const t=w.useContext(ef),n=Jt("windowViewportRect"),r=Jt("fixedItemHeight"),o=Ae("customScrollParent"),s=Id(n,o,Ae("skipAnimationFrameInResizeObserver")),i=Ae("alignToBottom");return w.useEffect(()=>{t&&(r(t.itemHeight),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:100}))},[t,n,r]),u.jsx("div",{"data-viewport-type":"window",ref:s,style:bs(i),children:e})},S0=({children:e})=>{const t=Ae("TopItemListComponent")||"div",n=Ae("headerHeight"),r={...g0,marginTop:`${n}px`},o=Ae("context");return u.jsx(t,{style:r,..._t(t,o),children:e})},C0=w.memo(function(e){const t=Ae("useWindowScroll"),n=Ae("topItemsIndexes").length>0,r=Ae("customScrollParent"),o=Ae("context");return u.jsxs(r||t?I0:k0,{...e,context:o,children:[n&&u.jsx(S0,{children:u.jsx(af,{showTopList:!0})}),u.jsxs(r||t?w0:b0,{children:[u.jsx(y0,{}),u.jsx(af,{}),u.jsx(v0,{})]})]})}),{Component:T0,useEmitter:va,useEmitterValue:Ae,usePublisher:Jt}=Qd(u0,{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"}},C0),k0=lf({useEmitter:va,useEmitterValue:Ae,usePublisher:Jt}),I0=cf({useEmitter:va,useEmitterValue:Ae,usePublisher:Jt}),E0=T0;ct(Zd,We(()=>{const e=ee(c=>u.jsxs("td",{children:["Item $",c]})),t=ee(null),n=ee(c=>u.jsxs("td",{colSpan:1e3,children:["Group ",c]})),r=ee(null),o=ee(null),s=ee({}),i=ee(ya),a=ee(Cr),l=(c,d=null)=>Nt(H(s,le(f=>f[c]),ut()),d);return{components:s,computeItemKey:i,context:t,EmptyPlaceholder:l("EmptyPlaceholder"),FillerRow:l("FillerRow"),fixedFooterContent:o,fixedHeaderContent:r,itemContent:e,groupContent:n,ScrollerComponent:l("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder"),TableBodyComponent:l("TableBody","tbody"),TableComponent:l("Table","table"),TableFooterComponent:l("TableFoot","tfoot"),TableHeadComponent:l("TableHead","thead"),TableRowComponent:l("TableRow","tr"),GroupComponent:l("Group","tr")}})),xa();const uf={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},A0={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:df,floor:ws,max:to,min:ba,round:ff}=Math;function pf(e,t,n){return Array.from({length:t-e+1}).map((r,o)=>({data:n===null?null:n[o+e],index:o+e}))}function N0(e){return{...A0,items:e}}function Ss(e,t){return e&&e.width===t.width&&e.height===t.height}function _0(e,t){return e&&e.column===t.column&&e.row===t.row}const j0=We(([{increaseViewportBy:e,listBoundary:t,overscan:n,visibleRange:r},{footerHeight:o,headerHeight:s,scrollBy:i,scrollContainerState:a,scrollTo:l,scrollTop:c,smoothScrollTargetReached:d,viewportHeight:f},p,h,{didMount:x,propsReady:m},{customScrollParent:y,useWindowScroll:g,windowScrollContainerState:b,windowScrollTo:S,windowViewportRect:k},C])=>{const T=ee(0),I=ee(0),A=ee(uf),R=ee({height:0,width:0}),L=ee({height:0,width:0}),P=ze(),D=ze(),F=ee(0),N=ee(null),B=ee({column:0,row:0}),j=ze(),V=ze(),z=ee(!1),M=ee(0),q=ee(!0),J=ee(!1),se=ee(!1);Je(H(x,De(M),ke(([$,K])=>!!K)),()=>{Me(q,!1)}),Je(H(wt(x,q,L,R,M,J),ke(([$,K,Q,ce,,oe])=>$&&!K&&Q.height!==0&&ce.height!==0&&!oe)),([,,,,$])=>{Me(J,!0),ua(1,()=>{Me(P,$)}),sn(H(c),()=>{Me(t,[0,0]),Me(q,!0)})}),he(H(V,ke($=>$!=null&&$.scrollTop>0),gn(0)),I),Je(H(x,De(V),ke(([,$])=>$!=null)),([,$])=>{$&&(Me(R,$.viewport),Me(L,$.item),Me(B,$.gap),$.scrollTop>0&&(Me(z,!0),sn(H(c,Xn(1)),K=>{Me(z,!1)}),Me(l,{top:$.scrollTop})))}),he(H(R,le(({height:$})=>$)),f),he(H(wt(Te(R,Ss),Te(L,Ss),Te(B,($,K)=>$&&$.column===K.column&&$.row===K.row),Te(c)),le(([$,K,Q,ce])=>({gap:Q,item:K,scrollTop:ce,viewport:$}))),j),he(H(wt(Te(T),r,Te(B,_0),Te(L,Ss),Te(R,Ss),Te(N),Te(I),Te(z),Te(q),Te(M)),ke(([,,,,,,,$])=>!$),le(([$,[K,Q],ce,oe,Ne,Ue,re,,xe,Pe])=>{const{column:Ze,row:Qe}=ce,{height:Ve,width:tt}=oe,{width:it}=Ne;if(re===0&&($===0||it===0))return uf;if(tt===0){const Lt=da(Pe,$),Mt=Lt+Math.max(re-1,0);return N0(pf(Lt,Mt,Ue))}const qe=hf(it,tt,Ze);let nt,at;xe?K===0&&Q===0&&re>0?(nt=0,at=re-1):(nt=qe*ws((K+Qe)/(Ve+Qe)),at=qe*df((Q+Qe)/(Ve+Qe))-1,at=ba($-1,to(at,qe-1)),nt=ba(at,to(0,nt))):(nt=0,at=-1);const Rt=pf(nt,at,Ue),{bottom:gt,top:ht}=mf(Ne,ce,oe,Rt),bt=df($/qe),St=bt*Ve+(bt-1)*Qe-gt;return{bottom:gt,itemHeight:Ve,items:Rt,itemWidth:tt,offsetBottom:St,offsetTop:ht,top:ht}})),A),he(H(N,ke($=>$!==null),le($=>$.length)),T),he(H(wt(R,L,A,B),ke(([$,K,{items:Q}])=>Q.length>0&&K.height!==0&&$.height!==0),le(([$,K,{items:Q},ce])=>{const{bottom:oe,top:Ne}=mf($,ce,K,Q);return[Ne,oe]}),ut(Gr)),t);const ge=ee(!1);he(H(c,De(ge),le(([$,K])=>K||$!==0)),ge);const Ee=Ht(H(wt(A,T),ke(([{items:$}])=>$.length>0),De(ge),ke(([[$,K],Q])=>{const ce=$.items[$.items.length-1].index===K-1;return(Q||$.bottom>0&&$.itemHeight>0&&$.offsetBottom===0&&$.items.length===K)&&ce}),le(([[,$]])=>$-1),ut())),Y=Ht(H(Te(A),ke(({items:$})=>$.length>0&&$[0].index===0),gn(0),ut())),U=Ht(H(Te(A),De(z),ke(([{items:$},K])=>$.length>0&&!K),le(([{items:$}])=>({endIndex:$[$.length-1].index,startIndex:$[0].index})),ut(Md),In(0)));he(U,h.scrollSeekRangeChanged),he(H(P,De(R,L,T,B),le(([$,K,Q,ce,oe])=>{const Ne=Fd($),{align:Ue,behavior:re,offset:xe}=Ne;let Pe=Ne.index;Pe==="LAST"&&(Pe=ce-1),Pe=to(0,Pe,ba(ce-1,Pe));let Ze=wa(K,oe,Q,Pe);return Ue==="end"?Ze=ff(Ze-K.height+Q.height):Ue==="center"&&(Ze=ff(Ze-K.height/2+Q.height/2)),xe&&(Ze+=xe),{behavior:re,top:Ze}})),l);const Z=Nt(H(A,le($=>$.offsetBottom+$.bottom)),0);return he(H(k,le($=>({height:$.visibleHeight,width:$.visibleWidth}))),R),{customScrollParent:y,data:N,deviation:F,footerHeight:o,gap:B,headerHeight:s,increaseViewportBy:e,initialItemCount:I,itemDimensions:L,overscan:n,restoreStateFrom:V,scrollBy:i,scrollContainerState:a,scrollHeight:D,scrollTo:l,scrollToIndex:P,scrollTop:c,smoothScrollTargetReached:d,totalCount:T,useWindowScroll:g,viewportDimensions:R,windowScrollContainerState:b,windowScrollTo:S,windowViewportRect:k,...h,gridState:A,horizontalDirection:se,initialTopMostItemIndex:M,totalListHeight:Z,...p,endReached:Ee,propsReady:m,rangeChanged:U,startReached:Y,stateChanged:j,stateRestoreInProgress:z,...C}},ct(fa,Dt,eo,Xd,On,ha,Mn));function hf(e,t,n){return to(1,ws((e+n)/(ws(t)+n)))}function mf(e,t,n,r){const{height:o}=n;if(o===void 0||r.length===0)return{bottom:0,top:0};const s=wa(e,t,n,r[0].index);return{bottom:wa(e,t,n,r[r.length-1].index)+o,top:s}}function wa(e,t,n,r){const o=hf(e.width,n.width,t.column),s=ws(r/o),i=s*n.height+to(0,s-1)*t.row;return i>0?i+t.row:i}const R0=We(()=>{const e=ee(f=>`Item ${f}`),t=ee({}),n=ee(null),r=ee("virtuoso-grid-item"),o=ee("virtuoso-grid-list"),s=ee(ya),i=ee("div"),a=ee(Cr),l=(f,p=null)=>Nt(H(t,le(h=>h[f]),ut()),p),c=ee(!1),d=ee(!1);return he(Te(d),c),{components:t,computeItemKey:s,context:n,FooterComponent:l("Footer"),HeaderComponent:l("Header"),headerFooterTag:i,itemClassName:r,ItemComponent:l("Item","div"),itemContent:e,listClassName:o,ListComponent:l("List","div"),readyStateChanged:c,reportReadyState:d,ScrollerComponent:l("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder","div")}}),M0=We(([e,t])=>({...e,...t}),ct(j0,R0)),P0=w.memo(function(){const e=ft("gridState"),t=ft("listClassName"),n=ft("itemClassName"),r=ft("itemContent"),o=ft("computeItemKey"),s=ft("isSeeking"),i=Zt("scrollHeight"),a=ft("ItemComponent"),l=ft("ListComponent"),c=ft("ScrollSeekPlaceholder"),d=ft("context"),f=Zt("itemDimensions"),p=Zt("gap"),h=ft("log"),x=ft("stateRestoreInProgress"),m=Zt("reportReadyState"),y=Jn(w.useMemo(()=>g=>{const b=g.parentElement.parentElement.scrollHeight;i(b);const S=g.firstChild;if(S){const{height:k,width:C}=S.getBoundingClientRect();f({height:k,width:C})}p({column:xf("column-gap",getComputedStyle(g).columnGap,h),row:xf("row-gap",getComputedStyle(g).rowGap,h)})},[i,f,p,h]),!0,!1);return nf(()=>{e.itemHeight>0&&e.itemWidth>0&&m(!0)},[e]),x?null:u.jsx(l,{className:t,ref:y,..._t(l,d),"data-testid":"virtuoso-item-list",style:{paddingBottom:e.offsetBottom,paddingTop:e.offsetTop},children:e.items.map(g=>{const b=o(g.index,g.data,d);return s?u.jsx(c,{..._t(c,d),height:e.itemHeight,index:g.index,width:e.itemWidth},b):w.createElement(a,{..._t(a,d),className:n,"data-index":g.index,key:b},r(g.index,g.data,d))})})}),O0=w.memo(function(){const e=ft("HeaderComponent"),t=Zt("headerHeight"),n=ft("headerFooterTag"),r=Jn(w.useMemo(()=>s=>{t(Pn(s,"height"))},[t]),!0,!1),o=ft("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{..._t(e,o)})}):null}),D0=w.memo(function(){const e=ft("FooterComponent"),t=Zt("footerHeight"),n=ft("headerFooterTag"),r=Jn(w.useMemo(()=>s=>{t(Pn(s,"height"))},[t]),!0,!1),o=ft("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{..._t(e,o)})}):null}),L0=({children:e})=>{const t=w.useContext(tf),n=Zt("itemDimensions"),r=Zt("viewportDimensions"),o=Jn(w.useMemo(()=>s=>{r(s.getBoundingClientRect())},[r]),!0,!1);return w.useEffect(()=>{t&&(r({height:t.viewportHeight,width:t.viewportWidth}),n({height:t.itemHeight,width:t.itemWidth}))},[t,r,n]),u.jsx("div",{ref:o,style:bs(!1),children:e})},$0=({children:e})=>{const t=w.useContext(tf),n=Zt("windowViewportRect"),r=Zt("itemDimensions"),o=ft("customScrollParent"),s=Id(n,o,!1);return w.useEffect(()=>{t&&(r({height:t.itemHeight,width:t.itemWidth}),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:t.viewportWidth}))},[t,n,r]),u.jsx("div",{ref:s,style:bs(!1),children:e})},F0=w.memo(function({...e}){const t=ft("useWindowScroll"),n=ft("customScrollParent"),r=n||t?z0:B0,o=n||t?$0:L0,s=ft("context");return u.jsx(r,{...e,..._t(r,s),children:u.jsxs(o,{children:[u.jsx(O0,{}),u.jsx(P0,{}),u.jsx(D0,{})]})})}),{useEmitter:gf,useEmitterValue:ft,usePublisher:Zt}=Qd(M0,{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"}},F0),B0=lf({useEmitter:gf,useEmitterValue:ft,usePublisher:Zt}),z0=cf({useEmitter:gf,useEmitterValue:ft,usePublisher:Zt});function xf(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Bt.WARN),t==="normal"?0:parseInt(t??"0",10)}const U0=po.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 yf({className:e,variant:t,...n}){return u.jsx("div",{className:ne(U0({variant:t}),e),...n})}function Sa(e){const t=e==null?void 0:e.trim();if(!t||!(t.startsWith("{")||t.startsWith("[")))return null;try{return JSON.parse(t)}catch{return null}}function vf(e){return!!(e&&typeof e=="object"&&(e.type==="file"||e.mimeType||e.filename||e.sourceType==="base64"))}function no(e){if(typeof e=="string")return e;if(e&&typeof e=="object"){if(Array.isArray(e)){const n=e.map(no).filter(r=>r!==void 0);if(!n.length){console.debug("[message-utils] sanitizeForDisplay - array emptied -> returning undefined",{originalLength:e.length});return}return n}if(vf(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=no(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 ro(e){if(typeof e=="string")return e;if(vf(e))return"";try{const t=no(e);return t===void 0?"":typeof t=="string"?t:JSON.stringify(t,null,2)}catch{return""}}function H0(e){return typeof e!="string"?!1:/^[\s\n]*[-*]\s|^[\s\n]*#+\s|```|^\s*\[.*\]\(|^>\s/.test(e)}function W0(e){const t=ro(e);return typeof e=="string"&&H0(e)?{content:e,isMarkdown:!0}:{content:t,isMarkdown:!1}}function Cs(e){if(e==null)return e;if(typeof e=="string"){const t=e.trim();if(t.startsWith("{")||t.startsWith("[")){const n=Sa(t);if(n!==null)return Cs(n)}return e}return typeof e=="object"&&!Array.isArray(e)&&e.content!==void 0?Cs(e.content):e}function V0(e){return e.filter(t=>t.type==="text").map(t=>t.text).join("")}function bf(e){const t=e.content.find(s=>s.type==="tool_call"),n=e.additionalKwargs??{},r=typeof(t==null?void 0:t.id)=="string"&&t.id||typeof n.toolCallId=="string"&&n.toolCallId||(e.id.startsWith("tool-")?e.id.slice(5):void 0);return{name:(typeof(t==null?void 0:t.name)=="string"&&t.name||typeof n.toolName=="string"&&n.toolName||e.name&&String(e.name))??void 0,toolCallId:r??void 0}}function Ts(e){if(e==null)return null;const t=String(e).trim();return t.length>0?t:null}function K0(e){const t=r=>{try{const o=no(r);return typeof o=="string"?o:JSON.stringify(o??"")}catch{return""}},n=e.filter(r=>r.type==="text");return n.length?t(n.map(r=>r.text).join(`
|
|
86
|
+
`).trim():n.replace(/</g,"<").replace(/>/g,">").trim()}function gw(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 xw(e){let t;return typeof e=="string"?t=e:typeof e=="object"&&e!==null?t=JSON.stringify(e):t=String(e),gw(t),mw(t)}const us=0,Rn=1,Sr=2,vd=4;function bd(e){return()=>e}function yw(e){e()}function wd(e,t){return n=>e(t(n))}function Sd(e,t){return()=>e(t)}function vw(e,t){return n=>e(t,n)}function Qi(e){return e!==void 0}function bw(...e){return()=>{e.map(yw)}}function Cr(){}function ds(e,t){return t(e),e}function ww(e,t){return t(e)}function ct(...e){return e}function Je(e,t){return e(Rn,t)}function Me(e,t){e(us,t)}function ea(e){e(Sr)}function vt(e){return e(vd)}function he(e,t){return Je(e,vw(t,us))}function sn(e,t){const n=e(Rn,r=>{n(),t(r)});return n}function Cd(e){let t,n;return r=>o=>{t=o,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function Td(e,t){return e===t}function ut(e=Td){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function ke(e){return t=>n=>{e(n)&&t(n)}}function le(e){return t=>wd(t,e)}function gn(e){return t=>()=>{t(e)}}function H(e,...t){const n=Sw(...t);return(r,o)=>{switch(r){case Sr:ea(e);return;case Rn:return Je(e,n(o))}}}function xn(e,t){return n=>r=>{n(t=e(t,r))}}function Xn(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 De(...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 c=n;n=n|a,t[i]=l,c!==o&&n===o&&r&&(r(),r=null)})}),s=>i=>{const a=()=>{s([i].concat(t))};n===o?a():r=a}}function Sw(...e){return t=>e.reduceRight(ww,t)}function Cw(e){let t,n;const r=()=>t==null?void 0:t();return function(o,s){switch(o){case Rn:return s?n===s?void 0:(r(),n=s,t=Je(e,s),t):(r(),Cr);case Sr:r(),n=null;return}}}function ee(e){let t=e;const n=ze();return(r,o)=>{switch(r){case us:t=o;break;case Rn:{o(t);break}case vd:return t}return n(r,o)}}function Nt(e,t){return ds(ee(t),n=>he(e,n))}function ze(){const e=[];return(t,n)=>{switch(t){case us:e.slice().forEach(r=>{r(n)});return;case Sr:e.splice(0,e.length);return;case Rn:return e.push(n),()=>{const r=e.indexOf(n);r>-1&&e.splice(r,1)}}}}function Ht(e){return ds(ze(),t=>he(e,t))}function We(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:Tw(),singleton:n}}const Tw=()=>Symbol();function kw(e){const t=new Map,n=({constructor:r,dependencies:o,id:s,singleton:i})=>{if(i&&t.has(s))return t.get(s);const a=r(o.map(l=>n(l)));return i&&t.set(s,a),a};return n(e)}function wt(...e){const t=ze(),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&&Me(t,n)})}),function(s,i){switch(s){case Sr:{ea(t);return}case Rn:return r===o&&i(n),Je(t,i)}}}function Te(e,t=Td){return H(e,ut(t))}function ta(...e){return function(t,n){switch(t){case Sr:return;case Rn:return bw(...e.map(r=>Je(r,n)))}}}var Bt=(e=>(e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR",e))(Bt||{});const Iw={0:"debug",3:"error",1:"log",2:"warn"},Ew=()=>typeof globalThis>"u"?window:globalThis,Mn=We(()=>{const e=ee(3);return{log:ee((t,n,r=1)=>{var o;const s=(o=Ew().VIRTUOSO_LOG_LEVEL)!=null?o:vt(e);r>=s&&console[Iw[r]]("%creact-virtuoso: %c%s %o","color: #0253b3; font-weight: bold","color: initial",t,n)}),logLevel:e}},[],{singleton:!0});function Jn(e,t,n){return na(e,t,n).callbackRef}function na(e,t,n){const r=w.useRef(null);let o=i=>{};const s=w.useMemo(()=>typeof ResizeObserver<"u"?new ResizeObserver(i=>{const a=()=>{const l=i[0].target;l.offsetParent!==null&&e(l)};n?a():requestAnimationFrame(a)}):null,[e,n]);return o=i=>{i&&t?(s==null||s.observe(i),r.current=i):(r.current&&(s==null||s.unobserve(r.current)),r.current=null)},{callbackRef:o,ref:r}}function Aw(e,t,n,r,o,s,i,a,l){const c=w.useCallback(d=>{const f=Nw(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 x;p&&(x=h.ownerDocument.defaultView);const m=i?a?i.scrollLeft:i.scrollTop:p?a?x.scrollX||x.document.documentElement.scrollLeft:x.scrollY||x.document.documentElement.scrollTop:a?h.scrollLeft:h.scrollTop,y=i?a?i.scrollWidth:i.scrollHeight:p?a?x.document.documentElement.scrollWidth:x.document.documentElement.scrollHeight:a?h.scrollWidth:h.scrollHeight,g=i?a?i.offsetWidth:i.offsetHeight:p?a?x.innerWidth:x.innerHeight:a?h.offsetWidth:h.offsetHeight;r({scrollHeight:y,scrollTop:Math.max(m,0),viewportHeight:g}),s==null||s(a?kd("column-gap",getComputedStyle(d).columnGap,o):kd("row-gap",getComputedStyle(d).rowGap,o)),f!==null&&e(f)},[e,t,o,s,i,r,a]);return na(c,n,l)}function Nw(e,t,n,r){const o=e.length;if(o===0)return null;const s=[];for(let i=0;i<o;i++){const a=e.item(i);if(a.dataset.index===void 0)continue;const l=parseInt(a.dataset.index),c=parseFloat(a.dataset.knownSize),d=t(a,n);if(d===0&&r("Zero-sized element, this should not happen",{child:a},Bt.ERROR),d===c)continue;const f=s[s.length-1];s.length===0||f.size!==d||f.endIndex!==l-1?s.push({endIndex:l,size:d,startIndex:l}):s[s.length-1].endIndex++}return s}function kd(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Bt.WARN),t==="normal"?0:parseInt(t??"0",10)}function Id(e,t,n){const r=w.useRef(null),o=w.useCallback(l=>{if(!(l!=null&&l.offsetParent))return;const c=l.getBoundingClientRect(),d=c.width;let f,h;if(t){const p=t.getBoundingClientRect(),x=c.top-p.top;h=p.height-Math.max(0,x),f=x+t.scrollTop}else{const p=i.current.ownerDocument.defaultView;h=p.innerHeight-Math.max(0,c.top),f=c.top+p.scrollY}r.current={offsetTop:f,visibleHeight:h,visibleWidth:d},e(r.current)},[e,t]),{callbackRef:s,ref:i}=na(o,!0,n),a=w.useCallback(()=>{o(i.current)},[o,i]);return w.useEffect(()=>{var l;if(t){t.addEventListener("scroll",a);const c=new ResizeObserver(()=>{requestAnimationFrame(a)});return c.observe(t),()=>{t.removeEventListener("scroll",a),c.unobserve(t)}}else{const c=(l=i.current)==null?void 0:l.ownerDocument.defaultView;return c==null||c.addEventListener("scroll",a),c==null||c.addEventListener("resize",a),()=>{c==null||c.removeEventListener("scroll",a),c==null||c.removeEventListener("resize",a)}}},[a,t,i]),s}const Dt=We(()=>{const e=ze(),t=ze(),n=ee(0),r=ze(),o=ee(0),s=ze(),i=ze(),a=ee(0),l=ee(0),c=ee(0),d=ee(0),f=ze(),h=ze(),p=ee(!1),x=ee(!1),m=ee(!1);return he(H(e,le(({scrollTop:y})=>y)),t),he(H(e,le(({scrollHeight:y})=>y)),i),he(t,o),{deviation:n,fixedFooterHeight:c,fixedHeaderHeight:l,footerHeight:d,headerHeight:a,horizontalDirection:x,scrollBy:h,scrollContainerState:e,scrollHeight:i,scrollingInProgress:p,scrollTo:f,scrollTop:t,skipAnimationFrameInResizeObserver:m,smoothScrollTargetReached:r,statefulScrollTop:o,viewportHeight:s}},[],{singleton:!0}),Kr={lvl:0};function Ed(e,t){const n=e.length;if(n===0)return[];let{index:r,value:o}=t(e[0]);const s=[];for(let i=1;i<n;i++){const{index:a,value:l}=t(e[i]);s.push({end:a-1,start:r,value:o}),r=a,o=l}return s.push({end:1/0,start:r,value:o}),s}function ot(e){return e===Kr}function qr(e,t){if(!ot(e))return t===e.k?e.v:t<e.k?qr(e.l,t):qr(e.r,t)}function an(e,t,n="k"){if(ot(e))return[-1/0,void 0];if(Number(e[n])===t)return[e.k,e.v];if(Number(e[n])<t){const r=an(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return an(e.l,t,n)}function Wt(e,t,n){return ot(e)?_d(t,n,1):t===e.k?Ct(e,{k:t,v:n}):t<e.k?jd(Ct(e,{l:Wt(e.l,t,n)})):jd(Ct(e,{r:Wt(e.r,t,n)}))}function Tr(){return Kr}function fs(e,t,n){if(ot(e))return[];const r=an(e,t)[0];return _w(oa(e,r,n))}function ra(e,t){if(ot(e))return Kr;const{k:n,l:r,r:o}=e;if(t===n){if(ot(r))return o;if(ot(o))return r;{const[s,i]=Nd(r);return ps(Ct(e,{k:s,l:Ad(r),v:i}))}}else return t<n?ps(Ct(e,{l:ra(r,t)})):ps(Ct(e,{r:ra(o,t)}))}function Zn(e){return ot(e)?[]:[...Zn(e.l),{k:e.k,v:e.v},...Zn(e.r)]}function oa(e,t,n){if(ot(e))return[];const{k:r,l:o,r:s,v:i}=e;let a=[];return r>t&&(a=a.concat(oa(o,t,n))),r>=t&&r<=n&&a.push({k:r,v:i}),r<=n&&(a=a.concat(oa(s,t,n))),a}function ps(e){const{l:t,lvl:n,r}=e;if(r.lvl>=n-1&&t.lvl>=n-1)return e;if(n>r.lvl+1){if(sa(t))return Rd(Ct(e,{lvl:n-1}));if(!ot(t)&&!ot(t.r))return Ct(t.r,{l:Ct(t,{r:t.r.l}),lvl:n,r:Ct(e,{l:t.r.r,lvl:n-1})});throw new Error("Unexpected empty nodes")}else{if(sa(e))return ia(Ct(e,{lvl:n-1}));if(!ot(r)&&!ot(r.l)){const o=r.l,s=sa(o)?r.lvl-1:r.lvl;return Ct(o,{l:Ct(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:ia(Ct(r,{l:o.r,lvl:s}))})}else throw new Error("Unexpected empty nodes")}}function Ct(e,t){return _d(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 Ad(e){return ot(e.r)?e.l:ps(Ct(e,{r:Ad(e.r)}))}function sa(e){return ot(e)||e.lvl>e.r.lvl}function Nd(e){return ot(e.r)?[e.k,e.v]:Nd(e.r)}function _d(e,t,n,r=Kr,o=Kr){return{k:e,l:r,lvl:n,r:o,v:t}}function jd(e){return ia(Rd(e))}function Rd(e){const{l:t}=e;return!ot(t)&&t.lvl===e.lvl?Ct(t,{r:Ct(e,{l:t.r})}):e}function ia(e){const{lvl:t,r:n}=e;return!ot(n)&&!ot(n.r)&&n.lvl===t&&n.r.lvl===t?Ct(n,{l:Ct(e,{r:n.l}),lvl:t+1}):e}function _w(e){return Ed(e,({k:t,v:n})=>({index:t,value:n}))}function Md(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function Gr(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}const aa=We(()=>({recalcInProgress:ee(!1)}),[],{singleton:!0});function Pd(e,t,n){return e[hs(e,t,n)]}function hs(e,t,n,r=0){let o=e.length-1;for(;r<=o;){const s=Math.floor((r+o)/2),i=e[s],a=n(i,t);if(a===0)return s;if(a===-1){if(o-r<2)return s-1;o=s-1}else{if(o===r)return s;r=s+1}}throw new Error(`Failed binary finding record in array - ${e.join(",")}, searched for ${t}`)}function jw(e,t,n,r){const o=hs(e,t,r),s=hs(e,n,r,o);return e.slice(o,s+1)}function Pn(e,t){return Math.round(e.getBoundingClientRect()[t])}function ms(e){return!ot(e.groupOffsetTree)}function la({index:e},t){return t===e?0:t<e?-1:1}function Rw(){return{groupIndices:[],groupOffsetTree:Tr(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:Tr()}}function Mw(e,t){let n=ot(e)?0:1/0;for(const r of t){const{endIndex:o,size:s,startIndex:i}=r;if(n=Math.min(n,i),ot(e)){e=Wt(e,0,s);continue}const a=fs(e,i-1,o+1);if(a.some(Bw(r)))continue;let l=!1,c=!1;for(const{end:d,start:f,value:h}of a)l?(o>=f||s===h)&&(e=ra(e,f)):(c=h!==s,l=!0),d>o&&o>=f&&h!==s&&(e=Wt(e,o+1,h));c&&(e=Wt(e,i,s))}return[e,n]}function Pw(e){return typeof e.groupIndex<"u"}function Ow({offset:e},t){return t===e?0:t<e?-1:1}function Yr(e,t,n){if(t.length===0)return 0;const{index:r,offset:o,size:s}=Pd(t,e,la),i=e-r,a=s*i+(i-1)*n+o;return a>0?a+n:a}function Od(e,t){if(!ms(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function Dd(e,t,n){if(Pw(e))return t.groupIndices[e.groupIndex]+1;{const r=e.index==="LAST"?n:e.index;let o=Od(r,t);return o=Math.max(0,o,Math.min(n,o)),o}}function Dw(e,t,n,r=0){return r>0&&(t=Math.max(t,Pd(e,r,la).offset)),Ed(jw(e,t,n,Ow),Fw)}function Lw(e,[t,n,r,o]){t.length>0&&r("received item sizes",t,Bt.DEBUG);const s=e.sizeTree;let i=s,a=0;if(n.length>0&&ot(s)&&t.length===2){const h=t[0].size,p=t[1].size;i=n.reduce((x,m)=>Wt(Wt(x,m,h),m+1,p),i)}else[i,a]=Mw(i,t);if(i===s)return e;const{lastIndex:l,lastOffset:c,lastSize:d,offsetTree:f}=ca(e.offsetTree,a,i,o);return{groupIndices:n,groupOffsetTree:n.reduce((h,p)=>Wt(h,p,Yr(p,f,o)),Tr()),lastIndex:l,lastOffset:c,lastSize:d,offsetTree:f,sizeTree:i}}function $w(e){return Zn(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 Ld(e,t){let n=0,r=0;for(;n<e;)n+=t[r+1]-t[r]-1,r++;return r-(n===e?0:1)}function ca(e,t,n,r){let o=e,s=0,i=0,a=0,l=0;if(t!==0){l=hs(o,t-1,la),a=o[l].offset;const c=an(n,t-1);s=c[0],i=c[1],o.length&&o[l].size===an(n,t)[1]&&(l-=1),o=o.slice(0,l+1)}else o=[];for(const{start:c,value:d}of fs(n,t,1/0)){const f=c-s,h=f*i+a+f*r;o.push({index:c,offset:h,size:d}),s=c,a=h,i=d}return{lastIndex:s,lastOffset:a,lastSize:i,offsetTree:o}}function Fw(e){return{index:e.index,value:e}}function Bw(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 zw={offsetHeight:"height",offsetWidth:"width"},yn=We(([{log:e},{recalcInProgress:t}])=>{const n=ze(),r=ze(),o=Nt(r,0),s=ze(),i=ze(),a=ee(0),l=ee([]),c=ee(void 0),d=ee(void 0),f=ee((C,T)=>Pn(C,zw[T])),h=ee(void 0),p=ee(0),x=Rw(),m=Nt(H(n,De(l,e,p),xn(Lw,x),ut()),x),y=Nt(H(l,ut(),xn((C,T)=>({current:T,prev:C.current}),{current:[],prev:[]}),le(({prev:C})=>C)),[]);he(H(l,ke(C=>C.length>0),De(m,p),le(([C,T,I])=>{const A=C.reduce((R,L,P)=>Wt(R,L,Yr(L,T.offsetTree,I)||P),Tr());return{...T,groupIndices:C,groupOffsetTree:A}})),m),he(H(r,De(m),ke(([C,{lastIndex:T}])=>C<T),le(([C,{lastIndex:T,lastSize:I}])=>[{endIndex:T,size:I,startIndex:C}])),n),he(c,d);const g=Nt(H(c,le(C=>C===void 0)),!0);he(H(d,ke(C=>C!==void 0&&ot(vt(m).sizeTree)),le(C=>[{endIndex:0,size:C,startIndex:0}])),n);const b=Ht(H(n,De(m),xn(({sizes:C},[T,I])=>({changed:I!==C,sizes:I}),{changed:!1,sizes:x}),le(C=>C.changed)));Je(H(a,xn((C,T)=>({diff:C.prev-T,prev:T}),{diff:0,prev:0}),le(C=>C.diff)),C=>{const{groupIndices:T}=vt(m);if(C>0)Me(t,!0),Me(s,C+Ld(C,T));else if(C<0){const I=vt(y);I.length>0&&(C-=Ld(-C,I)),Me(i,C)}}),Je(H(a,De(e)),([C,T])=>{C<0&&T("`firstItemIndex` prop should not be set to less than zero. If you don't know the total count, just use a very high value",{firstItemIndex:a},Bt.ERROR)});const S=Ht(s);he(H(s,De(m),le(([C,T])=>{const I=T.groupIndices.length>0,A=[],R=T.lastSize;if(I){const L=qr(T.sizeTree,0);let P=0,D=0;for(;P<C;){const N=T.groupIndices[D],B=T.groupIndices.length===D+1?1/0:T.groupIndices[D+1]-N-1;A.push({endIndex:N,size:L,startIndex:N}),A.push({endIndex:N+1+B-1,size:R,startIndex:N+1}),D++,P+=B+1}const F=Zn(T.sizeTree);return P!==C&&F.shift(),F.reduce((N,{k:B,v:j})=>{let V=N.ranges;return N.prevSize!==0&&(V=[...N.ranges,{endIndex:B+C-1,size:N.prevSize,startIndex:N.prevIndex}]),{prevIndex:B+C,prevSize:j,ranges:V}},{prevIndex:C,prevSize:0,ranges:A}).ranges}return Zn(T.sizeTree).reduce((L,{k:P,v:D})=>({prevIndex:P+C,prevSize:D,ranges:[...L.ranges,{endIndex:P+C-1,size:L.prevSize,startIndex:L.prevIndex}]}),{prevIndex:0,prevSize:R,ranges:[]}).ranges})),n);const k=Ht(H(i,De(m,p),le(([C,{offsetTree:T},I])=>{const A=-C;return Yr(A,T,I)})));return he(H(i,De(m,p),le(([C,T,I])=>{if(T.groupIndices.length>0){if(ot(T.sizeTree))return T;let A=Tr();const R=vt(y);let L=0,P=0,D=0;for(;L<-C;){D=R[P];const F=R[P+1]-D-1;P++,L+=F+1}if(A=Zn(T.sizeTree).reduce((F,{k:N,v:B})=>Wt(F,Math.max(0,N+C),B),A),L!==-C){const F=qr(T.sizeTree,D);A=Wt(A,0,F);const N=an(T.sizeTree,-C+1)[1];A=Wt(A,1,N)}return{...T,sizeTree:A,...ca(T.offsetTree,0,A,I)}}else{const A=Zn(T.sizeTree).reduce((R,{k:L,v:P})=>Wt(R,Math.max(0,L+C),P),Tr());return{...T,sizeTree:A,...ca(T.offsetTree,0,A,I)}}})),m),{beforeUnshiftWith:S,data:h,defaultItemSize:d,firstItemIndex:a,fixedItemSize:c,gap:p,groupIndices:l,itemSize:f,listRefresh:b,shiftWith:i,shiftWithOffset:k,sizeRanges:n,sizes:m,statefulTotalCount:o,totalCount:r,trackItemSizes:g,unshiftWith:s}},ct(Mn,aa),{singleton:!0});function Uw(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const $d=We(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=ze(),i=ze(),a=Ht(H(s,le(Uw)));return he(H(a,le(l=>l.totalCount)),n),he(H(a,le(l=>l.groupIndices)),e),he(H(wt(o,t,r),ke(([l,c])=>ms(c)),le(([l,c,d])=>an(c.groupOffsetTree,Math.max(l-d,0),"v")[0]),ut(),le(l=>[l])),i),{groupCounts:s,topItemsIndexes:i}},ct(yn,Dt)),On=We(([{log:e}])=>{const t=ee(!1),n=Ht(H(t,ke(r=>r),ut()));return Je(t,r=>{r&&vt(e)("props updated",{},Bt.DEBUG)}),{didMount:n,propsReady:t}},ct(Mn),{singleton:!0}),Hw=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function Fd(e){const t=typeof e=="number"?{index:e}:e;return t.align||(t.align="start"),(!t.behavior||!Hw)&&(t.behavior="auto"),t.offset||(t.offset=0),t}const Xr=We(([{gap:e,listRefresh:t,sizes:n,totalCount:r},{fixedFooterHeight:o,fixedHeaderHeight:s,footerHeight:i,headerHeight:a,scrollingInProgress:l,scrollTo:c,smoothScrollTargetReached:d,viewportHeight:f},{log:h}])=>{const p=ze(),x=ze(),m=ee(0);let y=null,g=null,b=null;function S(){y&&(y(),y=null),b&&(b(),b=null),g&&(clearTimeout(g),g=null),Me(l,!1)}return he(H(p,De(n,f,r,m,a,i,h),De(e,s,o),le(([[k,C,T,I,A,R,L,P],D,F,N])=>{const B=Fd(k),{align:j,behavior:V,offset:z}=B,M=I-1,q=Dd(B,C,M);let J=Yr(q,C.offsetTree,D)+R;j==="end"?(J+=F+an(C.sizeTree,q)[1]-T+N,q===M&&(J+=L)):j==="center"?J+=(F+an(C.sizeTree,q)[1]-T+N)/2:J-=A,z&&(J+=z);const se=ge=>{S(),ge?(P("retrying to scroll to",{location:k},Bt.DEBUG),Me(p,k)):(Me(x,!0),P("list did not change, scroll successful",{},Bt.DEBUG))};if(S(),V==="smooth"){let ge=!1;b=Je(t,Ee=>{ge=ge||Ee}),y=sn(d,()=>{se(ge)})}else y=sn(H(t,Ww(150)),se);return g=setTimeout(()=>{S()},1200),Me(l,!0),P("scrolling from index to",{behavior:V,index:q,top:J},Bt.DEBUG),{behavior:V,top:J}})),c),{scrollTargetReached:x,scrollToIndex:p,topListHeight:m}},ct(yn,Dt,Mn),{singleton:!0});function Ww(e){return t=>{const n=setTimeout(()=>{t(!1)},e);return r=>{r&&(t(!0),clearTimeout(n))}}}function ua(e,t){e==0?t():requestAnimationFrame(()=>{ua(e-1,t)})}function da(e,t){const n=t-1;return typeof e=="number"?e:e.index==="LAST"?n:e.index}const Jr=We(([{defaultItemSize:e,listRefresh:t,sizes:n},{scrollTop:r},{scrollTargetReached:o,scrollToIndex:s},{didMount:i}])=>{const a=ee(!0),l=ee(0),c=ee(!0);return he(H(i,De(l),ke(([d,f])=>!!f),gn(!1)),a),he(H(i,De(l),ke(([d,f])=>!!f),gn(!1)),c),Je(H(wt(t,i),De(a,n,e,c),ke(([[,d],f,{sizeTree:h},p,x])=>d&&(!ot(h)||Qi(p))&&!f&&!x),De(l)),([,d])=>{sn(o,()=>{Me(c,!0)}),ua(4,()=>{sn(r,()=>{Me(a,!0)}),Me(s,d)})}),{initialItemFinalLocationReached:c,initialTopMostItemIndex:l,scrolledToInitialItem:a}},ct(yn,Dt,Xr,On),{singleton:!0});function Bd(e,t){return Math.abs(e-t)<1.01}const Zr="up",Qr="down",Vw="none",Kw={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},qw=0,eo=We(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:o,viewportHeight:s}])=>{const i=ee(!1),a=ee(!0),l=ze(),c=ze(),d=ee(4),f=ee(qw),h=Nt(H(ta(H(Te(o),Xn(1),gn(!0)),H(Te(o),Xn(1),gn(!1),Cd(100))),ut()),!1),p=Nt(H(ta(H(n,gn(!0)),H(n,gn(!1),Cd(200))),ut()),!1);he(H(wt(Te(o),Te(f)),le(([b,S])=>b<=S),ut()),a),he(H(a,In(50)),c);const x=Ht(H(wt(r,Te(s),Te(t),Te(e),Te(d)),xn((b,[{scrollHeight:S,scrollTop:k},C,T,I,A])=>{const R=k+C-S>-A,L={scrollHeight:S,scrollTop:k,viewportHeight:C};if(R){let D,F;return k>b.state.scrollTop?(D="SCROLLED_DOWN",F=b.state.scrollTop-k):(D="SIZE_DECREASED",F=b.state.scrollTop-k||b.scrollTopDelta),{atBottom:!0,atBottomBecause:D,scrollTopDelta:F,state:L}}let P;return L.scrollHeight>b.state.scrollHeight?P="SIZE_INCREASED":C<b.state.viewportHeight?P="VIEWPORT_HEIGHT_DECREASING":k<b.state.scrollTop?P="SCROLLING_UPWARDS":P="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:P,state:L}},Kw),ut((b,S)=>b&&b.atBottom===S.atBottom))),m=Nt(H(r,xn((b,{scrollHeight:S,scrollTop:k,viewportHeight:C})=>{if(Bd(b.scrollHeight,S))return{changed:!1,jump:0,scrollHeight:S,scrollTop:k};{const T=S-(k+C)<1;return b.scrollTop!==k&&T?{changed:!0,jump:b.scrollTop-k,scrollHeight:S,scrollTop:k}:{changed:!0,jump:0,scrollHeight:S,scrollTop:k}}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),ke(b=>b.changed),le(b=>b.jump)),0);he(H(x,le(b=>b.atBottom)),i),he(H(i,In(50)),l);const y=ee(Qr);he(H(r,le(({scrollTop:b})=>b),ut(),xn((b,S)=>vt(p)?{direction:b.direction,prevScrollTop:S}:{direction:S<b.prevScrollTop?Zr:Qr,prevScrollTop:S},{direction:Qr,prevScrollTop:0}),le(b=>b.direction)),y),he(H(r,In(50),gn(Vw)),y);const g=ee(0);return he(H(h,ke(b=>!b),gn(0)),g),he(H(o,In(100),De(h),ke(([b,S])=>!!S),xn(([b,S],[k])=>[S,k],[0,0]),le(([b,S])=>S-b)),g),{atBottomState:x,atBottomStateChange:l,atBottomThreshold:d,atTopStateChange:c,atTopThreshold:f,isAtBottom:i,isAtTop:a,isScrolling:h,lastJumpDueToItemResize:m,scrollDirection:y,scrollVelocity:g}},ct(Dt)),gs="top",xs="bottom",zd="none";function Ud(e,t,n){return typeof e=="number"?n===Zr&&t===gs||n===Qr&&t===xs?e:0:n===Zr?t===gs?e.main:e.reverse:t===xs?e.main:e.reverse}function Hd(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const fa=We(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:o}])=>{const s=ze(),i=ee(0),a=ee(0),l=ee(0),c=Nt(H(wt(Te(r),Te(o),Te(n),Te(s,Gr),Te(l),Te(i),Te(t),Te(e),Te(a)),le(([d,f,h,[p,x],m,y,g,b,S])=>{const k=d-b,C=y+g,T=Math.max(h-k,0);let I=zd;const A=Hd(S,gs),R=Hd(S,xs);return p-=b,p+=h+g,x+=h+g,x-=b,p>d+C-A&&(I=Zr),x<d-T+f+R&&(I=Qr),I!==zd?[Math.max(k-h-Ud(m,gs,I)-A,0),k-T-g+f+Ud(m,xs,I)+R]:null}),ke(d=>d!=null),ut(Gr)),[0,0]);return{increaseViewportBy:a,listBoundary:s,overscan:l,topListHeight:i,visibleRange:c}},ct(Dt),{singleton:!0});function Gw(e,t,n){if(ms(t)){const r=Od(e,t);return[{index:an(t.groupOffsetTree,r)[0],offset:0,size:0},{data:n==null?void 0:n[0],index:r,offset:0,size:0}]}return[{data:n==null?void 0:n[0],index:e,offset:0,size:0}]}const pa={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function ys(e,t,n,r,o,s){const{lastIndex:i,lastOffset:a,lastSize:l}=o;let c=0,d=0;if(e.length>0){c=e[0].offset;const m=e[e.length-1];d=m.offset+m.size}const f=n-i,h=a+f*l+(f-1)*r,p=c,x=h-d;return{bottom:d,firstItemIndex:s,items:Vd(e,o,s),offsetBottom:x,offsetTop:c,top:p,topItems:Vd(t,o,s),topListHeight:t.reduce((m,y)=>y.size+m,0),totalCount:n}}function Wd(e,t,n,r,o,s){let i=0;if(n.groupIndices.length>0)for(const d of n.groupIndices){if(d-i>=e)break;i++}const a=e+i,l=da(t,a),c=Array.from({length:a}).map((d,f)=>({data:s[f+l],index:f+l,offset:0,size:0}));return ys(c,[],a,o,n,r)}function Vd(e,t,n){if(e.length===0)return[];if(!ms(t))return e.map(c=>({...c,index:c.index+n,originalIndex:c.index}));const r=e[0].index,o=e[e.length-1].index,s=[],i=fs(t.groupOffsetTree,r,o);let a,l=0;for(const c of e){(!a||a.end<c.index)&&(a=i.shift(),l=t.groupIndices.indexOf(a.start));let d;c.index===a.start?d={index:l,type:"group"}:d={groupIndex:l,index:c.index-(l+1)+n},s.push({...d,data:c.data,offset:c.offset,originalIndex:c.index,size:c.size})}return s}const Qn=We(([{data:e,firstItemIndex:t,gap:n,sizes:r,totalCount:o},s,{listBoundary:i,topListHeight:a,visibleRange:l},{initialTopMostItemIndex:c,scrolledToInitialItem:d},{topListHeight:f},h,{didMount:p},{recalcInProgress:x}])=>{const m=ee([]),y=ee(0),g=ze();he(s.topItemsIndexes,m);const b=Nt(H(wt(p,x,Te(l,Gr),Te(o),Te(r),Te(c),d,Te(m),Te(t),Te(n),e),ke(([T,I,,A,,,,,,,R])=>{const L=R&&R.length!==A;return T&&!I&&!L}),le(([,,[T,I],A,R,L,P,D,F,N,B])=>{const j=R,{offsetTree:V,sizeTree:z}=j,M=vt(y);if(A===0)return{...pa,totalCount:A};if(T===0&&I===0)return M===0?{...pa,totalCount:A}:Wd(M,L,R,F,N,B||[]);if(ot(z))return M>0?null:ys(Gw(da(L,A),j,B),[],A,N,j,F);const q=[];if(D.length>0){const Y=D[0],U=D[D.length-1];let Z=0;for(const $ of fs(z,Y,U)){const K=$.value,Q=Math.max($.start,Y),ce=Math.min($.end,U);for(let oe=Q;oe<=ce;oe++)q.push({data:B==null?void 0:B[oe],index:oe,offset:Z,size:K}),Z+=K}}if(!P)return ys([],q,A,N,j,F);const J=D.length>0?D[D.length-1]+1:0,se=Dw(V,T,I,J);if(se.length===0)return null;const ge=A-1,Ee=ds([],Y=>{for(const U of se){const Z=U.value;let $=Z.offset,K=U.start;const Q=Z.size;if(Z.offset<T){K+=Math.floor((T-Z.offset+N)/(Q+N));const oe=K-U.start;$+=oe*Q+oe*N}K<J&&($+=(J-K)*Q,K=J);const ce=Math.min(U.end,ge);for(let oe=K;oe<=ce&&!($>=I);oe++)Y.push({data:B==null?void 0:B[oe],index:oe,offset:$,size:Q}),$+=Q+N}});return ys(Ee,q,A,N,j,F)}),ke(T=>T!==null),ut()),pa);he(H(e,ke(Qi),le(T=>T==null?void 0:T.length)),o),he(H(b,le(T=>T.topListHeight)),f),he(f,a),he(H(b,le(T=>[T.top,T.bottom])),i),he(H(b,le(T=>T.items)),g);const S=Ht(H(b,ke(({items:T})=>T.length>0),De(o,e),ke(([{items:T},I])=>T[T.length-1].originalIndex===I-1),le(([,T,I])=>[T-1,I]),ut(Gr),le(([T])=>T))),k=Ht(H(b,In(200),ke(({items:T,topItems:I})=>T.length>0&&T[0].originalIndex===I.length),le(({items:T})=>T[0].index),ut())),C=Ht(H(b,ke(({items:T})=>T.length>0),le(({items:T})=>{let I=0,A=T.length-1;for(;T[I].type==="group"&&I<A;)I++;for(;T[A].type==="group"&&A>I;)A--;return{endIndex:T[A].index,startIndex:T[I].index}}),ut(Md)));return{endReached:S,initialItemCount:y,itemsRendered:g,listState:b,rangeChanged:C,startReached:k,topItemsIndexes:m,...h}},ct(yn,$d,fa,Jr,Xr,eo,On,aa),{singleton:!0}),Kd=We(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:o}])=>{const s=ze(),i=Nt(H(wt(n,e,r,t,o),le(([a,l,c,d,f])=>a+l+c+d+f.offsetBottom+f.bottom)),0);return he(Te(i),s),{totalListHeight:i,totalListHeightChanged:s}},ct(Dt,Qn),{singleton:!0}),Yw=We(([{viewportHeight:e},{totalListHeight:t}])=>{const n=ee(!1),r=Nt(H(wt(n,e,t),ke(([o])=>o),le(([,o,s])=>Math.max(0,o-s)),In(0),ut()),0);return{alignToBottom:n,paddingTopAddition:r}},ct(Dt,Kd),{singleton:!0}),qd=We(()=>({context:ee(null)})),Xw=({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,Gd=We(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:s,scrollingInProgress:i,scrollTop:a,viewportHeight:l},{scrollToIndex:c}])=>{const d=ze();return he(H(d,De(t,l,n,s,o,r,a),De(e),le(([[f,h,p,x,m,y,g,b],S])=>{const{align:k,behavior:C,calculateViewLocation:T=Xw,done:I,...A}=f,R=Dd(f,h,x-1),L=Yr(R,h.offsetTree,S)+m+y,P=L+an(h.sizeTree,R)[1],D=b+y,F=b+p-g,N=T({itemBottom:P,itemTop:L,locationParams:{align:k,behavior:C,...A},viewportBottom:F,viewportTop:D});return N?I&&sn(H(i,ke(B=>!B),Xn(vt(i)?1:2)),I):I&&I(),N}),ke(f=>f!==null)),c),{scrollIntoView:d}},ct(yn,Dt,Xr,Qn,Mn),{singleton:!0});function Yd(e){return e?e==="smooth"?"smooth":"auto":!1}const Jw=(e,t)=>typeof e=="function"?Yd(e(t)):t&&Yd(e),Zw=We(([{listRefresh:e,totalCount:t,fixedItemSize:n,data:r},{atBottomState:o,isAtBottom:s},{scrollToIndex:i},{scrolledToInitialItem:a},{didMount:l,propsReady:c},{log:d},{scrollingInProgress:f},{context:h},{scrollIntoView:p}])=>{const x=ee(!1),m=ze();let y=null;function g(C){Me(i,{align:"end",behavior:C,index:"LAST"})}Je(H(wt(H(Te(t),Xn(1)),l),De(Te(x),s,a,f),le(([[C,T],I,A,R,L])=>{let P=T&&R,D="auto";return P&&(D=Jw(I,A||L),P=P&&!!D),{followOutputBehavior:D,shouldFollow:P,totalCount:C}}),ke(({shouldFollow:C})=>C)),({followOutputBehavior:C,totalCount:T})=>{y&&(y(),y=null),vt(n)?requestAnimationFrame(()=>{vt(d)("following output to ",{totalCount:T},Bt.DEBUG),g(C)}):y=sn(e,()=>{vt(d)("following output to ",{totalCount:T},Bt.DEBUG),g(C),y=null})});function b(C){const T=sn(o,I=>{C&&!I.atBottom&&I.notAtBottomBecause==="SIZE_INCREASED"&&!y&&(vt(d)("scrolling to bottom due to increased size",{},Bt.DEBUG),g("auto"))});setTimeout(T,100)}Je(H(wt(Te(x),t,c),ke(([C,,T])=>C&&T),xn(({value:C},[,T])=>({refreshed:C===T,value:T}),{refreshed:!1,value:0}),ke(({refreshed:C})=>C),De(x,t)),([,C])=>{vt(a)&&b(C!==!1)}),Je(m,()=>{b(vt(x)!==!1)}),Je(wt(Te(x),o),([C,T])=>{C&&!T.atBottom&&T.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&g("auto")});const S=ee(null),k=ze();return he(ta(H(Te(r),le(C=>{var T;return(T=C==null?void 0:C.length)!=null?T:0})),H(Te(t))),k),Je(H(wt(H(k,Xn(1)),l),De(Te(S),a,f,h),le(([[C,T],I,A,R,L])=>T&&A&&(I==null?void 0:I({context:L,totalCount:C,scrollingInProgress:R}))),ke(C=>!!C),In(0)),C=>{y&&(y(),y=null),vt(n)?requestAnimationFrame(()=>{vt(d)("scrolling into view",{}),Me(p,C)}):y=sn(e,()=>{vt(d)("scrolling into view",{}),Me(p,C),y=null})}),{autoscrollToBottom:m,followOutput:x,scrollIntoViewOnChange:S}},ct(yn,eo,Xr,Jr,On,Mn,Dt,qd,Gd)),Qw=We(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:s,listState:i},{didMount:a}])=>(he(H(a,De(s),ke(([,l])=>l!==0),De(o,r,t,n,e),le(([[,l],c,d,f,h,p=[]])=>Wd(l,c,d,f,h,p))),i),{}),ct(yn,Jr,Qn,On),{singleton:!0}),e0=We(([{didMount:e},{scrollTo:t},{listState:n}])=>{const r=ee(0);return Je(H(e,De(r),ke(([,o])=>o!==0),le(([,o])=>({top:o}))),o=>{sn(H(n,Xn(1),ke(s=>s.items.length>1)),()=>{requestAnimationFrame(()=>{Me(t,o)})})}),{initialScrollTop:r}},ct(On,Dt,Qn),{singleton:!0}),Xd=We(([{scrollVelocity:e}])=>{const t=ee(!1),n=ze(),r=ee(!1);return he(H(e,De(r,t,n),ke(([o,s])=>!!s),le(([o,s,i,a])=>{const{enter:l,exit:c}=s;if(i){if(c(o,a))return!1}else if(l(o,a))return!0;return i}),ut()),t),Je(H(wt(t,e,n),De(r)),([[o,s,i],a])=>{o&&a&&a.change&&a.change(s,i)}),{isSeeking:t,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:e}},ct(eo),{singleton:!0}),ha=We(([{scrollContainerState:e,scrollTo:t}])=>{const n=ze(),r=ze(),o=ze(),s=ee(!1),i=ee(void 0);return he(H(wt(n,r),le(([{scrollHeight:a,scrollTop:l,viewportHeight:c},{offsetTop:d}])=>({scrollHeight:a,scrollTop:Math.max(0,l-d),viewportHeight:c}))),e),he(H(t,De(r),le(([a,{offsetTop:l}])=>({...a,top:a.top+l}))),o),{customScrollParent:i,useWindowScroll:s,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:r}},ct(Dt)),t0=We(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:o},{didMount:s},{useWindowScroll:i,windowScrollContainerState:a,windowViewportRect:l}])=>{const c=ze(),d=ee(void 0),f=ee(null),h=ee(null);return he(a,f),he(l,h),Je(H(c,De(t,r,i,f,h,n)),([p,x,m,y,g,b,S])=>{const k=$w(x.sizeTree);y&&g!==null&&b!==null&&(m=g.scrollTop-b.offsetTop),m-=S,p({ranges:k,scrollTop:m})}),he(H(d,ke(Qi),le(n0)),o),he(H(s,De(d),ke(([,p])=>p!==void 0),ut(),le(([,p])=>p.ranges)),e),{getState:c,restoreStateFrom:d}},ct(yn,Dt,Jr,On,ha));function n0(e){return{align:"start",index:0,offset:e.scrollTop}}const r0=We(([{topItemsIndexes:e}])=>{const t=ee(0);return he(H(t,ke(n=>n>=0),le(n=>Array.from({length:n}).map((r,o)=>o))),e),{topItemCount:t}},ct(Qn));function Jd(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const o0=Jd(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),s0=We(([{deviation:e,scrollBy:t,scrollingInProgress:n,scrollTop:r},{isAtBottom:o,isScrolling:s,lastJumpDueToItemResize:i,scrollDirection:a},{listState:l},{beforeUnshiftWith:c,gap:d,shiftWithOffset:f,sizes:h},{log:p},{recalcInProgress:x}])=>{const m=Ht(H(l,De(i),xn(([,g,b,S],[{bottom:k,items:C,offsetBottom:T,totalCount:I},A])=>{const R=k+T;let L=0;return b===I&&g.length>0&&C.length>0&&(C[0].originalIndex===0&&g[0].originalIndex===0||(L=R-S,L!==0&&(L+=A))),[L,C,I,R]},[0,[],0,0]),ke(([g])=>g!==0),De(r,a,n,o,p,x),ke(([,g,b,S,,,k])=>!k&&!S&&g!==0&&b===Zr),le(([[g],,,,,b])=>(b("Upward scrolling compensation",{amount:g},Bt.DEBUG),g))));function y(g){g>0?(Me(t,{behavior:"auto",top:-g}),Me(e,0)):(Me(e,0),Me(t,{behavior:"auto",top:-g}))}return Je(H(m,De(e,s)),([g,b,S])=>{S&&o0()?Me(e,b-g):y(-g)}),Je(H(wt(Nt(s,!1),e,x),ke(([g,b,S])=>!g&&!S&&b!==0),le(([g,b])=>b),In(1)),y),he(H(f,le(g=>({top:-g}))),t),Je(H(c,De(h,d),le(([g,{groupIndices:b,lastSize:S,sizeTree:k},C])=>{function T(I){return I*(S+C)}if(b.length===0)return T(g);{let I=0;const A=qr(k,0);let R=0,L=0;for(;R<g;){R++,I+=A;let P=b.length===L+1?1/0:b[L+1]-b[L]-1;R+P>g&&(I-=A,P=g-R+1),R+=P,I+=T(P),L++}return I}})),g=>{Me(e,g),requestAnimationFrame(()=>{Me(t,{top:g}),requestAnimationFrame(()=>{Me(e,0),Me(x,!1)})})}),{deviation:e}},ct(Dt,eo,Qn,yn,Mn,aa)),i0=We(([e,t,n,r,o,s,i,a,l,c,d])=>({...e,...t,...n,...r,...o,...s,...i,...a,...l,...c,...d}),ct(fa,Qw,On,Xd,Kd,e0,Yw,ha,Gd,Mn,qd)),Zd=We(([{data:e,defaultItemSize:t,firstItemIndex:n,fixedItemSize:r,gap:o,groupIndices:s,itemSize:i,sizeRanges:a,sizes:l,statefulTotalCount:c,totalCount:d,trackItemSizes:f},{initialItemFinalLocationReached:h,initialTopMostItemIndex:p,scrolledToInitialItem:x},m,y,g,{listState:b,topItemsIndexes:S,...k},{scrollToIndex:C},T,{topItemCount:I},{groupCounts:A},R])=>(he(k.rangeChanged,R.scrollSeekRangeChanged),he(H(R.windowViewportRect,le(L=>L.visibleHeight)),m.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:n,fixedItemHeight:r,gap:o,groupCounts:A,initialItemFinalLocationReached:h,initialTopMostItemIndex:p,scrolledToInitialItem:x,sizeRanges:a,topItemCount:I,topItemsIndexes:S,totalCount:d,...g,groupIndices:s,itemSize:i,listState:b,scrollToIndex:C,statefulTotalCount:c,trackItemSizes:f,...k,...R,...m,sizes:l,...y}),ct(yn,Jr,Dt,t0,Zw,Qn,Xr,s0,r0,$d,i0));function a0(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 vs=typeof document<"u"?w.useLayoutEffect:w.useEffect;function Qd(e,t,n){const r=Object.keys(t.required||{}),o=Object.keys(t.optional||{}),s=Object.keys(t.methods||{}),i=Object.keys(t.events||{}),a=w.createContext({});function l(y,g){y.propsReady&&Me(y.propsReady,!1);for(const b of r){const S=y[t.required[b]];Me(S,g[b])}for(const b of o)if(b in g){const S=y[t.optional[b]];Me(S,g[b])}y.propsReady&&Me(y.propsReady,!0)}function c(y){return s.reduce((g,b)=>(g[b]=S=>{const k=y[t.methods[b]];Me(k,S)},g),{})}function d(y){return i.reduce((g,b)=>(g[b]=Cw(y[t.events[b]]),g),{})}const f=w.forwardRef((y,g)=>{const{children:b,...S}=y,[k]=w.useState(()=>ds(kw(e),I=>{l(I,S)})),[C]=w.useState(Sd(d,k));vs(()=>{for(const I of i)I in S&&Je(C[I],S[I]);return()=>{Object.values(C).map(ea)}},[S,C,k]),vs(()=>{l(k,S)}),w.useImperativeHandle(g,bd(c(k)));const T=n;return u.jsx(a.Provider,{value:k,children:n?u.jsx(T,{...a0([...r,...o,...i],S),children:b}):b})}),h=y=>{const g=w.useContext(a);return w.useCallback(b=>{Me(g[y],b)},[g,y])},p=y=>{const g=w.useContext(a)[y],b=w.useCallback(S=>Je(g,S),[g]);return w.useSyncExternalStore(b,()=>vt(g),()=>vt(g))},x=y=>{const g=w.useContext(a)[y],[b,S]=w.useState(Sd(vt,g));return vs(()=>Je(g,k=>{k!==b&&S(bd(k))}),[g,b]),b},m=w.version.startsWith("18")?p:x;return{Component:f,useEmitter:(y,g)=>{const b=w.useContext(a)[y];vs(()=>Je(b,g),[g,b])},useEmitterValue:m,usePublisher:h}}const ef=w.createContext(void 0),tf=w.createContext(void 0),nf=typeof document<"u"?w.useLayoutEffect:w.useEffect;function ma(e){return"self"in e}function l0(e){return"body"in e}function rf(e,t,n,r=Cr,o,s){const i=w.useRef(null),a=w.useRef(null),l=w.useRef(null),c=w.useCallback(h=>{let p,x,m;const y=h.target;if(l0(y)||ma(y)){const b=ma(y)?y:y.defaultView;m=s?b.scrollX:b.scrollY,p=s?b.document.documentElement.scrollWidth:b.document.documentElement.scrollHeight,x=s?b.innerWidth:b.innerHeight}else m=s?y.scrollLeft:y.scrollTop,p=s?y.scrollWidth:y.scrollHeight,x=s?y.offsetWidth:y.offsetHeight;const g=()=>{e({scrollHeight:p,scrollTop:Math.max(m,0),viewportHeight:x})};h.suppressFlushSync?g():Gs.flushSync(g),a.current!==null&&(m===a.current||m<=0||m===p-x)&&(a.current=null,t(!0),l.current&&(clearTimeout(l.current),l.current=null))},[e,t,s]);w.useEffect(()=>{const h=o||i.current;return r(o||i.current),c({suppressFlushSync:!0,target:h}),h.addEventListener("scroll",c,{passive:!0}),()=>{r(null),h.removeEventListener("scroll",c)}},[i,c,n,r,o]);function d(h){const p=i.current;if(!p||(s?"offsetWidth"in p&&p.offsetWidth===0:"offsetHeight"in p&&p.offsetHeight===0))return;const x=h.behavior==="smooth";let m,y,g;ma(p)?(y=Math.max(Pn(p.document.documentElement,s?"width":"height"),s?p.document.documentElement.scrollWidth:p.document.documentElement.scrollHeight),m=s?p.innerWidth:p.innerHeight,g=s?window.scrollX:window.scrollY):(y=p[s?"scrollWidth":"scrollHeight"],m=Pn(p,s?"width":"height"),g=p[s?"scrollLeft":"scrollTop"]);const b=y-m;if(h.top=Math.ceil(Math.max(Math.min(b,h.top),0)),Bd(m,y)||h.top===g){e({scrollHeight:y,scrollTop:g,viewportHeight:m}),x&&t(!0);return}x?(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 ga="-webkit-sticky",of="sticky",xa=Jd(()=>{if(typeof document>"u")return of;const e=document.createElement("div");return e.style.position=ga,e.style.position===ga?ga:of});function ya(e){return e}const c0=We(()=>{const e=ee(a=>`Item ${a}`),t=ee(a=>`Group ${a}`),n=ee({}),r=ee(ya),o=ee("div"),s=ee(Cr),i=(a,l=null)=>Nt(H(n,le(c=>c[a]),ut()),l);return{components:n,computeItemKey:r,EmptyPlaceholder:i("EmptyPlaceholder"),FooterComponent:i("Footer"),GroupComponent:i("Group","div"),groupContent:t,HeaderComponent:i("Header"),HeaderFooterTag:o,ItemComponent:i("Item","div"),itemContent:e,ListComponent:i("List","div"),ScrollerComponent:i("Scroller","div"),scrollerRef:s,ScrollSeekPlaceholder:i("ScrollSeekPlaceholder"),TopItemListComponent:i("TopItemList")}}),u0=We(([e,t])=>({...e,...t}),ct(Zd,c0)),d0=({height:e})=>u.jsx("div",{style:{height:e}}),f0={overflowAnchor:"none",position:xa(),zIndex:1},sf={overflowAnchor:"none"},p0={...sf,display:"inline-block",height:"100%"},af=w.memo(function({showTopList:e=!1}){const t=Ae("listState"),n=Jt("sizeRanges"),r=Ae("useWindowScroll"),o=Ae("customScrollParent"),s=Jt("windowScrollContainerState"),i=Jt("scrollContainerState"),a=o||r?s:i,l=Ae("itemContent"),c=Ae("context"),d=Ae("groupContent"),f=Ae("trackItemSizes"),h=Ae("itemSize"),p=Ae("log"),x=Jt("gap"),m=Ae("horizontalDirection"),{callbackRef:y}=Aw(n,h,f,e?Cr:a,p,x,o,m,Ae("skipAnimationFrameInResizeObserver")),[g,b]=w.useState(0);va("deviation",N=>{g!==N&&b(N)});const S=Ae("EmptyPlaceholder"),k=Ae("ScrollSeekPlaceholder")||d0,C=Ae("ListComponent"),T=Ae("ItemComponent"),I=Ae("GroupComponent"),A=Ae("computeItemKey"),R=Ae("isSeeking"),L=Ae("groupIndices").length>0,P=Ae("alignToBottom"),D=Ae("initialItemFinalLocationReached"),F=e?{}:{boxSizing:"border-box",...m?{display:"inline-block",height:"100%",marginLeft:g!==0?g:P?"auto":0,paddingLeft:t.offsetTop,paddingRight:t.offsetBottom,whiteSpace:"nowrap"}:{marginTop:g!==0?g:P?"auto":0,paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},...D?{}:{visibility:"hidden"}};return!e&&t.totalCount===0&&S?u.jsx(S,{..._t(S,c)}):u.jsx(C,{..._t(C,c),"data-testid":e?"virtuoso-top-item-list":"virtuoso-item-list",ref:y,style:F,children:(e?t.topItems:t.items).map(N=>{const B=N.originalIndex,j=A(B+t.firstItemIndex,N.data,c);return R?w.createElement(k,{..._t(k,c),height:N.size,index:N.index,key:j,type:N.type||"item",...N.type==="group"?{}:{groupIndex:N.groupIndex}}):N.type==="group"?w.createElement(I,{..._t(I,c),"data-index":B,"data-item-index":N.index,"data-known-size":N.size,key:j,style:f0},d(N.index,c)):w.createElement(T,{..._t(T,c),...x0(T,N.data),"data-index":B,"data-item-group-index":N.groupIndex,"data-item-index":N.index,"data-known-size":N.size,key:j,style:m?p0:sf},L?l(N.index,N.groupIndex,N.data,c):l(N.index,N.data,c))})})}),h0={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},m0={outline:"none",overflowX:"auto",position:"relative"},bs=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),g0={position:xa(),top:0,width:"100%",zIndex:1};function _t(e,t){if(typeof e!="string")return{context:t}}function x0(e,t){return{item:typeof e=="string"?void 0:t}}const y0=w.memo(function(){const e=Ae("HeaderComponent"),t=Jt("headerHeight"),n=Ae("HeaderFooterTag"),r=Jn(w.useMemo(()=>s=>{t(Pn(s,"height"))},[t]),!0,Ae("skipAnimationFrameInResizeObserver")),o=Ae("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{..._t(e,o)})}):null}),v0=w.memo(function(){const e=Ae("FooterComponent"),t=Jt("footerHeight"),n=Ae("HeaderFooterTag"),r=Jn(w.useMemo(()=>s=>{t(Pn(s,"height"))},[t]),!0,Ae("skipAnimationFrameInResizeObserver")),o=Ae("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{..._t(e,o)})}):null});function lf({useEmitter:e,useEmitterValue:t,usePublisher:n}){return w.memo(function({children:r,style:o,context:s,...i}){const a=n("scrollContainerState"),l=t("ScrollerComponent"),c=n("smoothScrollTargetReached"),d=t("scrollerRef"),f=t("horizontalDirection")||!1,{scrollByCallback:h,scrollerRef:p,scrollToCallback:x}=rf(a,c,l,d,void 0,f);return e("scrollTo",x),e("scrollBy",h),u.jsx(l,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:p,style:{...f?m0:h0,...o},tabIndex:0,...i,..._t(l,s),children:r})})}function cf({useEmitter:e,useEmitterValue:t,usePublisher:n}){return w.memo(function({children:r,style:o,context:s,...i}){const a=n("windowScrollContainerState"),l=t("ScrollerComponent"),c=n("smoothScrollTargetReached"),d=t("totalListHeight"),f=t("deviation"),h=t("customScrollParent"),p=w.useRef(null),x=t("scrollerRef"),{scrollByCallback:m,scrollerRef:y,scrollToCallback:g}=rf(a,c,l,x,h);return nf(()=>{var b;return y.current=h||((b=p.current)==null?void 0:b.ownerDocument.defaultView),()=>{y.current=null}},[y,h]),e("windowScrollTo",g),e("scrollBy",m),u.jsx(l,{ref:p,"data-virtuoso-scroller":!0,style:{position:"relative",...o,...d!==0?{height:d+f}:{}},...i,..._t(l,s),children:r})})}const b0=({children:e})=>{const t=w.useContext(ef),n=Jt("viewportHeight"),r=Jt("fixedItemHeight"),o=Ae("alignToBottom"),s=Ae("horizontalDirection"),i=w.useMemo(()=>wd(n,l=>Pn(l,s?"width":"height")),[n,s]),a=Jn(i,!0,Ae("skipAnimationFrameInResizeObserver"));return w.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),u.jsx("div",{"data-viewport-type":"element",ref:a,style:bs(o),children:e})},w0=({children:e})=>{const t=w.useContext(ef),n=Jt("windowViewportRect"),r=Jt("fixedItemHeight"),o=Ae("customScrollParent"),s=Id(n,o,Ae("skipAnimationFrameInResizeObserver")),i=Ae("alignToBottom");return w.useEffect(()=>{t&&(r(t.itemHeight),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:100}))},[t,n,r]),u.jsx("div",{"data-viewport-type":"window",ref:s,style:bs(i),children:e})},S0=({children:e})=>{const t=Ae("TopItemListComponent")||"div",n=Ae("headerHeight"),r={...g0,marginTop:`${n}px`},o=Ae("context");return u.jsx(t,{style:r,..._t(t,o),children:e})},C0=w.memo(function(e){const t=Ae("useWindowScroll"),n=Ae("topItemsIndexes").length>0,r=Ae("customScrollParent"),o=Ae("context");return u.jsxs(r||t?I0:k0,{...e,context:o,children:[n&&u.jsx(S0,{children:u.jsx(af,{showTopList:!0})}),u.jsxs(r||t?w0:b0,{children:[u.jsx(y0,{}),u.jsx(af,{}),u.jsx(v0,{})]})]})}),{Component:T0,useEmitter:va,useEmitterValue:Ae,usePublisher:Jt}=Qd(u0,{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"}},C0),k0=lf({useEmitter:va,useEmitterValue:Ae,usePublisher:Jt}),I0=cf({useEmitter:va,useEmitterValue:Ae,usePublisher:Jt}),E0=T0;ct(Zd,We(()=>{const e=ee(c=>u.jsxs("td",{children:["Item $",c]})),t=ee(null),n=ee(c=>u.jsxs("td",{colSpan:1e3,children:["Group ",c]})),r=ee(null),o=ee(null),s=ee({}),i=ee(ya),a=ee(Cr),l=(c,d=null)=>Nt(H(s,le(f=>f[c]),ut()),d);return{components:s,computeItemKey:i,context:t,EmptyPlaceholder:l("EmptyPlaceholder"),FillerRow:l("FillerRow"),fixedFooterContent:o,fixedHeaderContent:r,itemContent:e,groupContent:n,ScrollerComponent:l("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder"),TableBodyComponent:l("TableBody","tbody"),TableComponent:l("Table","table"),TableFooterComponent:l("TableFoot","tfoot"),TableHeadComponent:l("TableHead","thead"),TableRowComponent:l("TableRow","tr"),GroupComponent:l("Group","tr")}})),xa();const uf={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},A0={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:df,floor:ws,max:to,min:ba,round:ff}=Math;function pf(e,t,n){return Array.from({length:t-e+1}).map((r,o)=>({data:n===null?null:n[o+e],index:o+e}))}function N0(e){return{...A0,items:e}}function Ss(e,t){return e&&e.width===t.width&&e.height===t.height}function _0(e,t){return e&&e.column===t.column&&e.row===t.row}const j0=We(([{increaseViewportBy:e,listBoundary:t,overscan:n,visibleRange:r},{footerHeight:o,headerHeight:s,scrollBy:i,scrollContainerState:a,scrollTo:l,scrollTop:c,smoothScrollTargetReached:d,viewportHeight:f},h,p,{didMount:x,propsReady:m},{customScrollParent:y,useWindowScroll:g,windowScrollContainerState:b,windowScrollTo:S,windowViewportRect:k},C])=>{const T=ee(0),I=ee(0),A=ee(uf),R=ee({height:0,width:0}),L=ee({height:0,width:0}),P=ze(),D=ze(),F=ee(0),N=ee(null),B=ee({column:0,row:0}),j=ze(),V=ze(),z=ee(!1),M=ee(0),q=ee(!0),J=ee(!1),se=ee(!1);Je(H(x,De(M),ke(([$,K])=>!!K)),()=>{Me(q,!1)}),Je(H(wt(x,q,L,R,M,J),ke(([$,K,Q,ce,,oe])=>$&&!K&&Q.height!==0&&ce.height!==0&&!oe)),([,,,,$])=>{Me(J,!0),ua(1,()=>{Me(P,$)}),sn(H(c),()=>{Me(t,[0,0]),Me(q,!0)})}),he(H(V,ke($=>$!=null&&$.scrollTop>0),gn(0)),I),Je(H(x,De(V),ke(([,$])=>$!=null)),([,$])=>{$&&(Me(R,$.viewport),Me(L,$.item),Me(B,$.gap),$.scrollTop>0&&(Me(z,!0),sn(H(c,Xn(1)),K=>{Me(z,!1)}),Me(l,{top:$.scrollTop})))}),he(H(R,le(({height:$})=>$)),f),he(H(wt(Te(R,Ss),Te(L,Ss),Te(B,($,K)=>$&&$.column===K.column&&$.row===K.row),Te(c)),le(([$,K,Q,ce])=>({gap:Q,item:K,scrollTop:ce,viewport:$}))),j),he(H(wt(Te(T),r,Te(B,_0),Te(L,Ss),Te(R,Ss),Te(N),Te(I),Te(z),Te(q),Te(M)),ke(([,,,,,,,$])=>!$),le(([$,[K,Q],ce,oe,Ne,Ue,re,,xe,Pe])=>{const{column:Ze,row:Qe}=ce,{height:Ve,width:tt}=oe,{width:it}=Ne;if(re===0&&($===0||it===0))return uf;if(tt===0){const Lt=da(Pe,$),Mt=Lt+Math.max(re-1,0);return N0(pf(Lt,Mt,Ue))}const qe=hf(it,tt,Ze);let nt,at;xe?K===0&&Q===0&&re>0?(nt=0,at=re-1):(nt=qe*ws((K+Qe)/(Ve+Qe)),at=qe*df((Q+Qe)/(Ve+Qe))-1,at=ba($-1,to(at,qe-1)),nt=ba(at,to(0,nt))):(nt=0,at=-1);const Rt=pf(nt,at,Ue),{bottom:gt,top:ht}=mf(Ne,ce,oe,Rt),bt=df($/qe),St=bt*Ve+(bt-1)*Qe-gt;return{bottom:gt,itemHeight:Ve,items:Rt,itemWidth:tt,offsetBottom:St,offsetTop:ht,top:ht}})),A),he(H(N,ke($=>$!==null),le($=>$.length)),T),he(H(wt(R,L,A,B),ke(([$,K,{items:Q}])=>Q.length>0&&K.height!==0&&$.height!==0),le(([$,K,{items:Q},ce])=>{const{bottom:oe,top:Ne}=mf($,ce,K,Q);return[Ne,oe]}),ut(Gr)),t);const ge=ee(!1);he(H(c,De(ge),le(([$,K])=>K||$!==0)),ge);const Ee=Ht(H(wt(A,T),ke(([{items:$}])=>$.length>0),De(ge),ke(([[$,K],Q])=>{const ce=$.items[$.items.length-1].index===K-1;return(Q||$.bottom>0&&$.itemHeight>0&&$.offsetBottom===0&&$.items.length===K)&&ce}),le(([[,$]])=>$-1),ut())),Y=Ht(H(Te(A),ke(({items:$})=>$.length>0&&$[0].index===0),gn(0),ut())),U=Ht(H(Te(A),De(z),ke(([{items:$},K])=>$.length>0&&!K),le(([{items:$}])=>({endIndex:$[$.length-1].index,startIndex:$[0].index})),ut(Md),In(0)));he(U,p.scrollSeekRangeChanged),he(H(P,De(R,L,T,B),le(([$,K,Q,ce,oe])=>{const Ne=Fd($),{align:Ue,behavior:re,offset:xe}=Ne;let Pe=Ne.index;Pe==="LAST"&&(Pe=ce-1),Pe=to(0,Pe,ba(ce-1,Pe));let Ze=wa(K,oe,Q,Pe);return Ue==="end"?Ze=ff(Ze-K.height+Q.height):Ue==="center"&&(Ze=ff(Ze-K.height/2+Q.height/2)),xe&&(Ze+=xe),{behavior:re,top:Ze}})),l);const Z=Nt(H(A,le($=>$.offsetBottom+$.bottom)),0);return he(H(k,le($=>({height:$.visibleHeight,width:$.visibleWidth}))),R),{customScrollParent:y,data:N,deviation:F,footerHeight:o,gap:B,headerHeight:s,increaseViewportBy:e,initialItemCount:I,itemDimensions:L,overscan:n,restoreStateFrom:V,scrollBy:i,scrollContainerState:a,scrollHeight:D,scrollTo:l,scrollToIndex:P,scrollTop:c,smoothScrollTargetReached:d,totalCount:T,useWindowScroll:g,viewportDimensions:R,windowScrollContainerState:b,windowScrollTo:S,windowViewportRect:k,...p,gridState:A,horizontalDirection:se,initialTopMostItemIndex:M,totalListHeight:Z,...h,endReached:Ee,propsReady:m,rangeChanged:U,startReached:Y,stateChanged:j,stateRestoreInProgress:z,...C}},ct(fa,Dt,eo,Xd,On,ha,Mn));function hf(e,t,n){return to(1,ws((e+n)/(ws(t)+n)))}function mf(e,t,n,r){const{height:o}=n;if(o===void 0||r.length===0)return{bottom:0,top:0};const s=wa(e,t,n,r[0].index);return{bottom:wa(e,t,n,r[r.length-1].index)+o,top:s}}function wa(e,t,n,r){const o=hf(e.width,n.width,t.column),s=ws(r/o),i=s*n.height+to(0,s-1)*t.row;return i>0?i+t.row:i}const R0=We(()=>{const e=ee(f=>`Item ${f}`),t=ee({}),n=ee(null),r=ee("virtuoso-grid-item"),o=ee("virtuoso-grid-list"),s=ee(ya),i=ee("div"),a=ee(Cr),l=(f,h=null)=>Nt(H(t,le(p=>p[f]),ut()),h),c=ee(!1),d=ee(!1);return he(Te(d),c),{components:t,computeItemKey:s,context:n,FooterComponent:l("Footer"),HeaderComponent:l("Header"),headerFooterTag:i,itemClassName:r,ItemComponent:l("Item","div"),itemContent:e,listClassName:o,ListComponent:l("List","div"),readyStateChanged:c,reportReadyState:d,ScrollerComponent:l("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder","div")}}),M0=We(([e,t])=>({...e,...t}),ct(j0,R0)),P0=w.memo(function(){const e=ft("gridState"),t=ft("listClassName"),n=ft("itemClassName"),r=ft("itemContent"),o=ft("computeItemKey"),s=ft("isSeeking"),i=Zt("scrollHeight"),a=ft("ItemComponent"),l=ft("ListComponent"),c=ft("ScrollSeekPlaceholder"),d=ft("context"),f=Zt("itemDimensions"),h=Zt("gap"),p=ft("log"),x=ft("stateRestoreInProgress"),m=Zt("reportReadyState"),y=Jn(w.useMemo(()=>g=>{const b=g.parentElement.parentElement.scrollHeight;i(b);const S=g.firstChild;if(S){const{height:k,width:C}=S.getBoundingClientRect();f({height:k,width:C})}h({column:xf("column-gap",getComputedStyle(g).columnGap,p),row:xf("row-gap",getComputedStyle(g).rowGap,p)})},[i,f,h,p]),!0,!1);return nf(()=>{e.itemHeight>0&&e.itemWidth>0&&m(!0)},[e]),x?null:u.jsx(l,{className:t,ref:y,..._t(l,d),"data-testid":"virtuoso-item-list",style:{paddingBottom:e.offsetBottom,paddingTop:e.offsetTop},children:e.items.map(g=>{const b=o(g.index,g.data,d);return s?u.jsx(c,{..._t(c,d),height:e.itemHeight,index:g.index,width:e.itemWidth},b):w.createElement(a,{..._t(a,d),className:n,"data-index":g.index,key:b},r(g.index,g.data,d))})})}),O0=w.memo(function(){const e=ft("HeaderComponent"),t=Zt("headerHeight"),n=ft("headerFooterTag"),r=Jn(w.useMemo(()=>s=>{t(Pn(s,"height"))},[t]),!0,!1),o=ft("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{..._t(e,o)})}):null}),D0=w.memo(function(){const e=ft("FooterComponent"),t=Zt("footerHeight"),n=ft("headerFooterTag"),r=Jn(w.useMemo(()=>s=>{t(Pn(s,"height"))},[t]),!0,!1),o=ft("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{..._t(e,o)})}):null}),L0=({children:e})=>{const t=w.useContext(tf),n=Zt("itemDimensions"),r=Zt("viewportDimensions"),o=Jn(w.useMemo(()=>s=>{r(s.getBoundingClientRect())},[r]),!0,!1);return w.useEffect(()=>{t&&(r({height:t.viewportHeight,width:t.viewportWidth}),n({height:t.itemHeight,width:t.itemWidth}))},[t,r,n]),u.jsx("div",{ref:o,style:bs(!1),children:e})},$0=({children:e})=>{const t=w.useContext(tf),n=Zt("windowViewportRect"),r=Zt("itemDimensions"),o=ft("customScrollParent"),s=Id(n,o,!1);return w.useEffect(()=>{t&&(r({height:t.itemHeight,width:t.itemWidth}),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:t.viewportWidth}))},[t,n,r]),u.jsx("div",{ref:s,style:bs(!1),children:e})},F0=w.memo(function({...e}){const t=ft("useWindowScroll"),n=ft("customScrollParent"),r=n||t?z0:B0,o=n||t?$0:L0,s=ft("context");return u.jsx(r,{...e,..._t(r,s),children:u.jsxs(o,{children:[u.jsx(O0,{}),u.jsx(P0,{}),u.jsx(D0,{})]})})}),{useEmitter:gf,useEmitterValue:ft,usePublisher:Zt}=Qd(M0,{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"}},F0),B0=lf({useEmitter:gf,useEmitterValue:ft,usePublisher:Zt}),z0=cf({useEmitter:gf,useEmitterValue:ft,usePublisher:Zt});function xf(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Bt.WARN),t==="normal"?0:parseInt(t??"0",10)}const U0=po.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 yf({className:e,variant:t,...n}){return u.jsx("div",{className:ne(U0({variant:t}),e),...n})}function Sa(e){const t=e==null?void 0:e.trim();if(!t||!(t.startsWith("{")||t.startsWith("[")))return null;try{return JSON.parse(t)}catch{return null}}function vf(e){return!!(e&&typeof e=="object"&&(e.type==="file"||e.mimeType||e.filename||e.sourceType==="base64"))}function no(e){if(typeof e=="string")return e;if(e&&typeof e=="object"){if(Array.isArray(e)){const n=e.map(no).filter(r=>r!==void 0);if(!n.length){console.debug("[message-utils] sanitizeForDisplay - array emptied -> returning undefined",{originalLength:e.length});return}return n}if(vf(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=no(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 ro(e){if(typeof e=="string")return e;if(vf(e))return"";try{const t=no(e);return t===void 0?"":typeof t=="string"?t:JSON.stringify(t,null,2)}catch{return""}}function H0(e){return typeof e!="string"?!1:/^[\s\n]*[-*]\s|^[\s\n]*#+\s|```|^\s*\[.*\]\(|^>\s/.test(e)}function W0(e){const t=ro(e);return typeof e=="string"&&H0(e)?{content:e,isMarkdown:!0}:{content:t,isMarkdown:!1}}function Cs(e){if(e==null)return e;if(typeof e=="string"){const t=e.trim();if(t.startsWith("{")||t.startsWith("[")){const n=Sa(t);if(n!==null)return Cs(n)}return e}return typeof e=="object"&&!Array.isArray(e)&&e.content!==void 0?Cs(e.content):e}function V0(e){return e.filter(t=>t.type==="text").map(t=>t.text).join("")}function bf(e){const t=e.content.find(s=>s.type==="tool_call"),n=e.additionalKwargs??{},r=typeof(t==null?void 0:t.id)=="string"&&t.id||typeof n.toolCallId=="string"&&n.toolCallId||(e.id.startsWith("tool-")?e.id.slice(5):void 0);return{name:(typeof(t==null?void 0:t.name)=="string"&&t.name||typeof n.toolName=="string"&&n.toolName||e.name&&String(e.name))??void 0,toolCallId:r??void 0}}function Ts(e){if(e==null)return null;const t=String(e).trim();return t.length>0?t:null}function K0(e){const t=r=>{try{const o=no(r);return typeof o=="string"?o:JSON.stringify(o??"")}catch{return""}},n=e.filter(r=>r.type==="text");return n.length?t(n.map(r=>r.text).join(`
|
|
87
87
|
`)):t(e)}function q0(e){return e.name&&e.name.trim()?e.name:e.model&&e.model.includes("/")?e.model.split("/").pop()||null:e.model||null}function wf(e){if("type"in e&&e.type==="default_message")return`default:${e.content.length}`;const t=e.updatedAt??e.createdAt??"",n=Array.isArray(e.content)?e.content.map(r=>{switch(r.type){case"text":return`t:${r.text.length}`;case"image_url":return"img";case"file":return"file";case"tool_call":return"call";case"interrupt":return"interrupt";default:return"unknown"}}).join("|"):"";return`${e.id}:${t}:${n}`}function G0(e){if(!e)return"image/png";const t=e.trim();return t?t.includes("/")?t:`image/${t}`:"image/png"}function Y0(e){const t=[],n=r=>{r&&r.trim()&&t.push(r.trim())};return e&&(n(e.plotId),n(e.artifactId)),t}function X0({base64:e,url:t,formatHint:n,extras:r}){const o=typeof e=="string"&&e.length>0,s=G0(n),i=o?`data:${s};base64,${e}`:t,a=Y0(r),l=a.length?a.join(" / "):void 0,c=l?`${l} artifact`:"artifact image";return{src:i,alt:c,label:l}}function J0(e){var o,s;const t=((o=e.content_base64)==null?void 0:o.trim())||void 0,n=((s=e.url)==null?void 0:s.trim())||void 0,r=e.format||e.mimeType||e.mime_type;return X0({base64:t,url:n,formatHint:r,extras:{plotId:e.plotId,artifactId:e.artifactId}})}async function Sf(e,t){return await qt(e,{responseType:"blob",onDownloadProgress:r=>{try{t&&r.lengthComputable}catch{}},maxBodyLength:1/0})}async function Cf(e,t){return await(await Sf(`/files/${e}/view`,t)).text()}async function Z0(e,t){const n=await Sf(`/files/${e}/download`,t),r=URL.createObjectURL(n);let o=`file_${e}`;try{const i=await qt(`/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 Q0(e,t=50,n=0){const r={limit:t,offset:n};return e&&(r.thread_id=e),await qt("/files",{params:r})}var ks="Dialog",[Tf,LT]=Sn(ks),[eS,ln]=Tf(ks),kf=e=>{const{__scopeDialog:t,children:n,open:r,defaultOpen:o,onOpenChange:s,modal:i=!0}=e,a=v.useRef(null),l=v.useRef(null),[c,d]=pr({prop:r,defaultProp:o??!1,onChange:s,caller:ks});return u.jsx(eS,{scope:t,triggerRef:a,contentRef:l,contentId:Cn(),titleId:Cn(),descriptionId:Cn(),open:c,onOpenChange:d,onOpenToggle:v.useCallback(()=>d(f=>!f),[d]),modal:i,children:n})};kf.displayName=ks;var If="DialogTrigger",Ef=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=ln(If,n),s=Be(t,o.triggerRef);return u.jsx(_e.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":ka(o.open),...r,ref:s,onClick:de(e.onClick,o.onOpenToggle)})});Ef.displayName=If;var Ca="DialogPortal",[tS,Af]=Tf(Ca,{forceMount:void 0}),Nf=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:o}=e,s=ln(Ca,t);return u.jsx(tS,{scope:t,forceMount:n,children:v.Children.map(r,i=>u.jsx(Yt,{present:n||s.open,children:u.jsx(qo,{asChild:!0,container:o,children:i})}))})};Nf.displayName=Ca;var Is="DialogOverlay",_f=v.forwardRef((e,t)=>{const n=Af(Is,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=ln(Is,e.__scopeDialog);return s.modal?u.jsx(Yt,{present:r||s.open,children:u.jsx(rS,{...o,ref:t})}):null});_f.displayName=Is;var nS=Hn.createSlot("DialogOverlay.RemoveScroll"),rS=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=ln(Is,n);return u.jsx(ns,{as:nS,allowPinchZoom:!0,shards:[o.contentRef],children:u.jsx(_e.div,{"data-state":ka(o.open),...r,ref:t,style:{pointerEvents:"auto",...r.style}})})}),er="DialogContent",jf=v.forwardRef((e,t)=>{const n=Af(er,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=ln(er,e.__scopeDialog);return u.jsx(Yt,{present:r||s.open,children:s.modal?u.jsx(oS,{...o,ref:t}):u.jsx(sS,{...o,ref:t})})});jf.displayName=er;var oS=v.forwardRef((e,t)=>{const n=ln(er,e.__scopeDialog),r=v.useRef(null),o=Be(t,n.contentRef,r);return v.useEffect(()=>{const s=r.current;if(s)return Fi(s)},[]),u.jsx(Rf,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:de(e.onCloseAutoFocus,s=>{var i;s.preventDefault(),(i=n.triggerRef.current)==null||i.focus()}),onPointerDownOutside:de(e.onPointerDownOutside,s=>{const i=s.detail.originalEvent,a=i.button===0&&i.ctrlKey===!0;(i.button===2||a)&&s.preventDefault()}),onFocusOutside:de(e.onFocusOutside,s=>s.preventDefault())})}),sS=v.forwardRef((e,t)=>{const n=ln(er,e.__scopeDialog),r=v.useRef(!1),o=v.useRef(!1);return u.jsx(Rf,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var i,a;(i=e.onCloseAutoFocus)==null||i.call(e,s),s.defaultPrevented||(r.current||(a=n.triggerRef.current)==null||a.focus(),s.preventDefault()),r.current=!1,o.current=!1},onInteractOutside:s=>{var l,c;(l=e.onInteractOutside)==null||l.call(e,s),s.defaultPrevented||(r.current=!0,s.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const i=s.target;((c=n.triggerRef.current)==null?void 0:c.contains(i))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&o.current&&s.preventDefault()}})}),Rf=v.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:s,...i}=e,a=ln(er,n),l=v.useRef(null),c=Be(t,l);return bi(),u.jsxs(u.Fragment,{children:[u.jsx(Oo,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s,children:u.jsx(Po,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":ka(a.open),...i,ref:c,onDismiss:()=>a.onOpenChange(!1)})}),u.jsxs(u.Fragment,{children:[u.jsx(iS,{titleId:a.titleId}),u.jsx(lS,{contentRef:l,descriptionId:a.descriptionId})]})]})}),Ta="DialogTitle",Mf=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=ln(Ta,n);return u.jsx(_e.h2,{id:o.titleId,...r,ref:t})});Mf.displayName=Ta;var Pf="DialogDescription",Of=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=ln(Pf,n);return u.jsx(_e.p,{id:o.descriptionId,...r,ref:t})});Of.displayName=Pf;var Df="DialogClose",Lf=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=ln(Df,n);return u.jsx(_e.button,{type:"button",...r,ref:t,onClick:de(e.onClick,()=>o.onOpenChange(!1))})});Lf.displayName=Df;function ka(e){return e?"open":"closed"}var $f="DialogTitleWarning",[$T,Ff]=nx($f,{contentName:er,titleName:Ta,docsSlug:"dialog"}),iS=({titleId:e})=>{const t=Ff($f),n=`\`${t.contentName}\` requires a \`${t.titleName}\` for the component to be accessible for screen reader users.
|
|
88
88
|
|
|
89
89
|
If you want to hide the \`${t.titleName}\`, you can wrap it with our VisuallyHidden component.
|
|
90
90
|
|
|
91
|
-
For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return v.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},aS="DialogDescriptionWarning",lS=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${Ff(aS).contentName}}.`;return v.useEffect(()=>{var s;const o=(s=e.current)==null?void 0:s.getAttribute("aria-describedby");t&&o&&(document.getElementById(t)||console.warn(r))},[r,e,t]),null},Bf=kf,cS=Ef,zf=Nf,Es=_f,As=jf,tr=Mf,Ns=Of,Uf=Lf;const uS=Bf,dS=zf,Hf=v.forwardRef(({className:e,...t},n)=>u.jsx(Es,{ref:n,className:ne("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}));Hf.displayName=Es.displayName;const Wf=v.forwardRef(({className:e,children:t,...n},r)=>{const o=v.useMemo(()=>{let s=!1;function i(a){v.Children.forEach(a,l=>{if(s||!v.isValidElement(l))return;const c=l.type;if(c===tr||(c==null?void 0:c.displayName)===tr.displayName||(c==null?void 0:c.name)==="DialogTitle"){s=!0;return}l.props&&l.props.children&&i(l.props.children)})}return i(t),s},[t]);return u.jsxs(dS,{children:[u.jsx(Hf,{}),u.jsxs(As,{ref:r,className:ne("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",e),...n,children:[!o&&u.jsx(tr,{className:"sr-only",children:"Dialog"}),t,u.jsxs(Uf,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground",children:[u.jsx(ae.X,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]})});Wf.displayName=As.displayName;const Vf=({className:e,...t})=>u.jsx("div",{className:ne("flex flex-col space-y-1.5 text-center sm:text-left",e),...t});Vf.displayName="DialogHeader";const Kf=v.forwardRef(({className:e,...t},n)=>u.jsx(tr,{ref:n,className:ne("text-lg font-semibold leading-none tracking-tight",e),...t}));Kf.displayName=tr.displayName;const fS=v.forwardRef(({className:e,...t},n)=>u.jsx(Ns,{ref:n,className:ne("text-sm text-muted-foreground",e),...t}));fS.displayName=Ns.displayName;const pS=1,hS=1e6;let Ia=0;function mS(){return Ia=(Ia+1)%Number.MAX_SAFE_INTEGER,Ia.toString()}const Ea=new Map,qf=e=>{if(Ea.has(e))return;const t=setTimeout(()=>{Ea.delete(e),oo({type:"REMOVE_TOAST",toastId:e})},hS);Ea.set(e,t)},gS=(e,t)=>{switch(t.type){case"ADD_TOAST":return{...e,toasts:[t.toast,...e.toasts].slice(0,pS)};case"UPDATE_TOAST":return{...e,toasts:e.toasts.map(n=>n.id===t.toast.id?{...n,...t.toast}:n)};case"DISMISS_TOAST":{const{toastId:n}=t;return n?qf(n):e.toasts.forEach(r=>{qf(r.id)}),{...e,toasts:e.toasts.map(r=>r.id===n||n===void 0?{...r,open:!1}:r)}}case"REMOVE_TOAST":return t.toastId===void 0?{...e,toasts:[]}:{...e,toasts:e.toasts.filter(n=>n.id!==t.toastId)}}},_s=[];let js={toasts:[]};function oo(e){js=gS(js,e),_s.forEach(t=>{t(js)})}function xS({...e}){const t=mS(),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 Aa(){const[e,t]=v.useState(js);return v.useEffect(()=>(_s.push(t),()=>{const n=_s.indexOf(t);n>-1&&_s.splice(n,1)}),[e]),{...e,toast:xS,dismiss:n=>oo({type:"DISMISS_TOAST",toastId:n})}}function yS({isOpen:e,onClose:t,fileId:n,fileName:r,mimeType:o}){const[s,i]=w.useState(!1),[a,l]=w.useState(null),[c,d]=w.useState(null),{toast:f}=Aa(),p=w.useCallback(async()=>{if(n){i(!0),d(null),l(null);try{const g=await Cf(n);l(g)}catch(g){console.error("Failed to load file:",g),d(g instanceof Error?g.message:"Failed to load file")}finally{i(!1)}}},[n]);w.useEffect(()=>{e&&n&&p()},[e,n,p]);const h=async()=>{if(n)try{await Z0(n),f({title:"Download started",description:`Downloading ${r}`})}catch(g){console.error("Failed to download file:",g),f({title:"Download failed",description:String(g),variant:"destructive"})}},x=async()=>{if(n)try{const g=await Cf(n),b=new Blob([g],{type:o}),S=URL.createObjectURL(b);window.open(S,"_blank"),URL.revokeObjectURL(S)}catch(g){console.error("Failed to open file externally:",g),f({title:"Failed to open file",description:String(g),variant:"destructive"})}},m=()=>s?u.jsxs("div",{className:"flex items-center justify-center py-12",children:[u.jsx(ae.Loader,{className:"h-8 w-8 animate-spin mr-3"}),u.jsx("span",{children:"Loading file..."})]}):c?u.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[u.jsx("div",{className:"text-red-500 mb-4",children:"⚠️"}),u.jsx("p",{className:"text-red-600 mb-4",children:c}),u.jsx(Xe,{onClick:p,variant:"outline",children:"Try Again"})]}):a?o.startsWith("image/")?u.jsx("div",{className:"flex justify-center",children:u.jsx("img",{src:`data:${o};base64,${a}`,alt:r,className:"max-w-full max-h-[70vh] object-contain rounded-lg"})}):o==="application/pdf"?u.jsx("div",{className:"w-full h-[70vh] border rounded-lg overflow-hidden",children:u.jsx("iframe",{src:`data:application/pdf;base64,${a}`,className:"w-full h-full",title:r})}):o.startsWith("text/")||o.includes("json")||o.includes("xml")?u.jsx("div",{className:"bg-gray-50 dark:bg-gray-900 rounded-lg p-4 max-h-[70vh] overflow-auto",children:u.jsx("pre",{className:"whitespace-pre-wrap font-mono text-sm",children:a})}):u.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[u.jsx(ae.FileText,{className:"h-16 w-16 text-gray-400 mb-4"}),u.jsx("p",{className:"text-lg font-medium mb-2",children:r}),u.jsxs("p",{className:"text-sm text-muted-foreground mb-4",children:[o," • ",a.length," bytes"]}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"This file type cannot be previewed. Use download or external view."})]}):u.jsx("div",{className:"flex items-center justify-center py-12",children:u.jsx("p",{className:"text-muted-foreground",children:"No content to display"})}),y=()=>o.startsWith("image/")?u.jsx(ae.Image,{className:"h-5 w-5"}):u.jsx(ae.FileText,{className:"h-5 w-5"});return u.jsx(uS,{open:e,onOpenChange:t,children:u.jsxs(Wf,{className:"max-w-4xl max-h-[90vh] overflow-hidden",children:[u.jsx(Vf,{children:u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{className:"flex items-center gap-3",children:[y(),u.jsxs("div",{children:[u.jsx(Kf,{className:"text-left",children:r}),u.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:[o," • Click download or external view for full access"]})]})]}),u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsxs(Xe,{variant:"outline",size:"sm",onClick:x,className:"flex items-center gap-2",children:[u.jsx(ae.ExternalLink,{className:"h-4 w-4"}),"External"]}),u.jsxs(Xe,{variant:"outline",size:"sm",onClick:h,className:"flex items-center gap-2",children:[u.jsx(ae.Download,{className:"h-4 w-4"}),"Download"]})]})]})}),u.jsx("div",{className:"flex-1 overflow-hidden",children:m()})]})})}function Gf(){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 nr=Gf();function vS(e){nr=e}const Yf=/[&<>"']/,bS=new RegExp(Yf.source,"g"),Xf=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,wS=new RegExp(Xf.source,"g"),SS={"&":"&","<":"<",">":">",'"':""","'":"'"},Jf=e=>SS[e];function jt(e,t){if(t){if(Yf.test(e))return e.replace(bS,Jf)}else if(Xf.test(e))return e.replace(wS,Jf);return e}const CS=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;function Zf(e){return e.replace(CS,(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 TS=/(^|[^\[])\^/g;function st(e,t){e=typeof e=="string"?e:e.source,t=t||"";const n={replace:(r,o)=>(o=o.source||o,o=o.replace(TS,"$1"),e=e.replace(r,o),n),getRegex:()=>new RegExp(e,t)};return n}const kS=/[^\w:]/g,IS=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function Qf(e,t,n){if(e){let r;try{r=decodeURIComponent(Zf(n)).replace(kS,"").toLowerCase()}catch{return null}if(r.indexOf("javascript:")===0||r.indexOf("vbscript:")===0||r.indexOf("data:")===0)return null}t&&!IS.test(n)&&(n=_S(t,n));try{n=encodeURI(n).replace(/%25/g,"%")}catch{return null}return n}const Rs={},ES=/^[^:]+:\/*[^/]*$/,AS=/^([^:]+:)[\s\S]*$/,NS=/^([^:]+:\/*[^/]*)[\s\S]*$/;function _S(e,t){Rs[" "+e]||(ES.test(e)?Rs[" "+e]=e+"/":Rs[" "+e]=Ps(e,"/",!0)),e=Rs[" "+e];const n=e.indexOf(":")===-1;return t.substring(0,2)==="//"?n?t:e.replace(AS,"$1")+t:t.charAt(0)==="/"?n?t:e.replace(NS,"$1")+t:e+t}const Ms={exec:function(){}};function ep(e,t){const n=e.replace(/\|/g,(s,i,a)=>{let l=!1,c=i;for(;--c>=0&&a[c]==="\\";)l=!l;return l?"|":" |"}),r=n.split(/ \|/);let o=0;if(r[0].trim()||r.shift(),r.length>0&&!r[r.length-1].trim()&&r.pop(),r.length>t)r.splice(t);else for(;r.length<t;)r.push("");for(;o<r.length;o++)r[o]=r[o].trim().replace(/\\\|/g,"|");return r}function Ps(e,t,n){const r=e.length;if(r===0)return"";let o=0;for(;o<r;){const s=e.charAt(r-o-1);if(s===t&&!n)o++;else if(s!==t&&n)o++;else break}return e.slice(0,r-o)}function jS(e,t){if(e.indexOf(t[1])===-1)return-1;const n=e.length;let r=0,o=0;for(;o<n;o++)if(e[o]==="\\")o++;else if(e[o]===t[0])r++;else if(e[o]===t[1]&&(r--,r<0))return o;return-1}function RS(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 tp(e,t){if(t<1)return"";let n="";for(;t>1;)t&1&&(n+=e),t>>=1,e+=e;return n+e}function np(e,t,n,r){const o=t.href,s=t.title?jt(t.title):null,i=e[1].replace(/\\([\[\]])/g,"$1");if(e[0].charAt(0)!=="!"){r.state.inLink=!0;const a={type:"link",raw:n,href:o,title:s,text:i,tokens:r.inlineTokens(i)};return r.state.inLink=!1,a}return{type:"image",raw:n,href:o,title:s,text:jt(i)}}function MS(e,t){const n=e.match(/^(\s+)(?:```)/);if(n===null)return t;const r=n[1];return t.split(`
|
|
91
|
+
For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return v.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},aS="DialogDescriptionWarning",lS=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${Ff(aS).contentName}}.`;return v.useEffect(()=>{var s;const o=(s=e.current)==null?void 0:s.getAttribute("aria-describedby");t&&o&&(document.getElementById(t)||console.warn(r))},[r,e,t]),null},Bf=kf,cS=Ef,zf=Nf,Es=_f,As=jf,tr=Mf,Ns=Of,Uf=Lf;const uS=Bf,dS=zf,Hf=v.forwardRef(({className:e,...t},n)=>u.jsx(Es,{ref:n,className:ne("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}));Hf.displayName=Es.displayName;const Wf=v.forwardRef(({className:e,children:t,...n},r)=>{const o=v.useMemo(()=>{let s=!1;function i(a){v.Children.forEach(a,l=>{if(s||!v.isValidElement(l))return;const c=l.type;if(c===tr||(c==null?void 0:c.displayName)===tr.displayName||(c==null?void 0:c.name)==="DialogTitle"){s=!0;return}l.props&&l.props.children&&i(l.props.children)})}return i(t),s},[t]);return u.jsxs(dS,{children:[u.jsx(Hf,{}),u.jsxs(As,{ref:r,className:ne("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",e),...n,children:[!o&&u.jsx(tr,{className:"sr-only",children:"Dialog"}),t,u.jsxs(Uf,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground",children:[u.jsx(ae.X,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]})});Wf.displayName=As.displayName;const Vf=({className:e,...t})=>u.jsx("div",{className:ne("flex flex-col space-y-1.5 text-center sm:text-left",e),...t});Vf.displayName="DialogHeader";const Kf=v.forwardRef(({className:e,...t},n)=>u.jsx(tr,{ref:n,className:ne("text-lg font-semibold leading-none tracking-tight",e),...t}));Kf.displayName=tr.displayName;const fS=v.forwardRef(({className:e,...t},n)=>u.jsx(Ns,{ref:n,className:ne("text-sm text-muted-foreground",e),...t}));fS.displayName=Ns.displayName;const pS=1,hS=1e6;let Ia=0;function mS(){return Ia=(Ia+1)%Number.MAX_SAFE_INTEGER,Ia.toString()}const Ea=new Map,qf=e=>{if(Ea.has(e))return;const t=setTimeout(()=>{Ea.delete(e),oo({type:"REMOVE_TOAST",toastId:e})},hS);Ea.set(e,t)},gS=(e,t)=>{switch(t.type){case"ADD_TOAST":return{...e,toasts:[t.toast,...e.toasts].slice(0,pS)};case"UPDATE_TOAST":return{...e,toasts:e.toasts.map(n=>n.id===t.toast.id?{...n,...t.toast}:n)};case"DISMISS_TOAST":{const{toastId:n}=t;return n?qf(n):e.toasts.forEach(r=>{qf(r.id)}),{...e,toasts:e.toasts.map(r=>r.id===n||n===void 0?{...r,open:!1}:r)}}case"REMOVE_TOAST":return t.toastId===void 0?{...e,toasts:[]}:{...e,toasts:e.toasts.filter(n=>n.id!==t.toastId)}}},_s=[];let js={toasts:[]};function oo(e){js=gS(js,e),_s.forEach(t=>{t(js)})}function xS({...e}){const t=mS(),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 Aa(){const[e,t]=v.useState(js);return v.useEffect(()=>(_s.push(t),()=>{const n=_s.indexOf(t);n>-1&&_s.splice(n,1)}),[e]),{...e,toast:xS,dismiss:n=>oo({type:"DISMISS_TOAST",toastId:n})}}function yS({isOpen:e,onClose:t,fileId:n,fileName:r,mimeType:o}){const[s,i]=w.useState(!1),[a,l]=w.useState(null),[c,d]=w.useState(null),{toast:f}=Aa(),h=w.useCallback(async()=>{if(n){i(!0),d(null),l(null);try{const g=await Cf(n);l(g)}catch(g){console.error("Failed to load file:",g),d(g instanceof Error?g.message:"Failed to load file")}finally{i(!1)}}},[n]);w.useEffect(()=>{e&&n&&h()},[e,n,h]);const p=async()=>{if(n)try{await Z0(n),f({title:"Download started",description:`Downloading ${r}`})}catch(g){console.error("Failed to download file:",g),f({title:"Download failed",description:String(g),variant:"destructive"})}},x=async()=>{if(n)try{const g=await Cf(n),b=new Blob([g],{type:o}),S=URL.createObjectURL(b);window.open(S,"_blank"),URL.revokeObjectURL(S)}catch(g){console.error("Failed to open file externally:",g),f({title:"Failed to open file",description:String(g),variant:"destructive"})}},m=()=>s?u.jsxs("div",{className:"flex items-center justify-center py-12",children:[u.jsx(ae.Loader,{className:"h-8 w-8 animate-spin mr-3"}),u.jsx("span",{children:"Loading file..."})]}):c?u.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[u.jsx("div",{className:"text-red-500 mb-4",children:"⚠️"}),u.jsx("p",{className:"text-red-600 mb-4",children:c}),u.jsx(Xe,{onClick:h,variant:"outline",children:"Try Again"})]}):a?o.startsWith("image/")?u.jsx("div",{className:"flex justify-center",children:u.jsx("img",{src:`data:${o};base64,${a}`,alt:r,className:"max-w-full max-h-[70vh] object-contain rounded-lg"})}):o==="application/pdf"?u.jsx("div",{className:"w-full h-[70vh] border rounded-lg overflow-hidden",children:u.jsx("iframe",{src:`data:application/pdf;base64,${a}`,className:"w-full h-full",title:r})}):o.startsWith("text/")||o.includes("json")||o.includes("xml")?u.jsx("div",{className:"bg-gray-50 dark:bg-gray-900 rounded-lg p-4 max-h-[70vh] overflow-auto",children:u.jsx("pre",{className:"whitespace-pre-wrap font-mono text-sm",children:a})}):u.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[u.jsx(ae.FileText,{className:"h-16 w-16 text-gray-400 mb-4"}),u.jsx("p",{className:"text-lg font-medium mb-2",children:r}),u.jsxs("p",{className:"text-sm text-muted-foreground mb-4",children:[o," • ",a.length," bytes"]}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"This file type cannot be previewed. Use download or external view."})]}):u.jsx("div",{className:"flex items-center justify-center py-12",children:u.jsx("p",{className:"text-muted-foreground",children:"No content to display"})}),y=()=>o.startsWith("image/")?u.jsx(ae.Image,{className:"h-5 w-5"}):u.jsx(ae.FileText,{className:"h-5 w-5"});return u.jsx(uS,{open:e,onOpenChange:t,children:u.jsxs(Wf,{className:"max-w-4xl max-h-[90vh] overflow-hidden",children:[u.jsx(Vf,{children:u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{className:"flex items-center gap-3",children:[y(),u.jsxs("div",{children:[u.jsx(Kf,{className:"text-left",children:r}),u.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:[o," • Click download or external view for full access"]})]})]}),u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsxs(Xe,{variant:"outline",size:"sm",onClick:x,className:"flex items-center gap-2",children:[u.jsx(ae.ExternalLink,{className:"h-4 w-4"}),"External"]}),u.jsxs(Xe,{variant:"outline",size:"sm",onClick:p,className:"flex items-center gap-2",children:[u.jsx(ae.Download,{className:"h-4 w-4"}),"Download"]})]})]})}),u.jsx("div",{className:"flex-1 overflow-hidden",children:m()})]})})}function Gf(){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 nr=Gf();function vS(e){nr=e}const Yf=/[&<>"']/,bS=new RegExp(Yf.source,"g"),Xf=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,wS=new RegExp(Xf.source,"g"),SS={"&":"&","<":"<",">":">",'"':""","'":"'"},Jf=e=>SS[e];function jt(e,t){if(t){if(Yf.test(e))return e.replace(bS,Jf)}else if(Xf.test(e))return e.replace(wS,Jf);return e}const CS=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;function Zf(e){return e.replace(CS,(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 TS=/(^|[^\[])\^/g;function st(e,t){e=typeof e=="string"?e:e.source,t=t||"";const n={replace:(r,o)=>(o=o.source||o,o=o.replace(TS,"$1"),e=e.replace(r,o),n),getRegex:()=>new RegExp(e,t)};return n}const kS=/[^\w:]/g,IS=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function Qf(e,t,n){if(e){let r;try{r=decodeURIComponent(Zf(n)).replace(kS,"").toLowerCase()}catch{return null}if(r.indexOf("javascript:")===0||r.indexOf("vbscript:")===0||r.indexOf("data:")===0)return null}t&&!IS.test(n)&&(n=_S(t,n));try{n=encodeURI(n).replace(/%25/g,"%")}catch{return null}return n}const Rs={},ES=/^[^:]+:\/*[^/]*$/,AS=/^([^:]+:)[\s\S]*$/,NS=/^([^:]+:\/*[^/]*)[\s\S]*$/;function _S(e,t){Rs[" "+e]||(ES.test(e)?Rs[" "+e]=e+"/":Rs[" "+e]=Ps(e,"/",!0)),e=Rs[" "+e];const n=e.indexOf(":")===-1;return t.substring(0,2)==="//"?n?t:e.replace(AS,"$1")+t:t.charAt(0)==="/"?n?t:e.replace(NS,"$1")+t:e+t}const Ms={exec:function(){}};function ep(e,t){const n=e.replace(/\|/g,(s,i,a)=>{let l=!1,c=i;for(;--c>=0&&a[c]==="\\";)l=!l;return l?"|":" |"}),r=n.split(/ \|/);let o=0;if(r[0].trim()||r.shift(),r.length>0&&!r[r.length-1].trim()&&r.pop(),r.length>t)r.splice(t);else for(;r.length<t;)r.push("");for(;o<r.length;o++)r[o]=r[o].trim().replace(/\\\|/g,"|");return r}function Ps(e,t,n){const r=e.length;if(r===0)return"";let o=0;for(;o<r;){const s=e.charAt(r-o-1);if(s===t&&!n)o++;else if(s!==t&&n)o++;else break}return e.slice(0,r-o)}function jS(e,t){if(e.indexOf(t[1])===-1)return-1;const n=e.length;let r=0,o=0;for(;o<n;o++)if(e[o]==="\\")o++;else if(e[o]===t[0])r++;else if(e[o]===t[1]&&(r--,r<0))return o;return-1}function RS(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 tp(e,t){if(t<1)return"";let n="";for(;t>1;)t&1&&(n+=e),t>>=1,e+=e;return n+e}function np(e,t,n,r){const o=t.href,s=t.title?jt(t.title):null,i=e[1].replace(/\\([\[\]])/g,"$1");if(e[0].charAt(0)!=="!"){r.state.inLink=!0;const a={type:"link",raw:n,href:o,title:s,text:i,tokens:r.inlineTokens(i)};return r.state.inLink=!1,a}return{type:"image",raw:n,href:o,title:s,text:jt(i)}}function MS(e,t){const n=e.match(/^(\s+)(?:```)/);if(n===null)return t;const r=n[1];return t.split(`
|
|
92
92
|
`).map(o=>{const s=o.match(/^\s+/);if(s===null)return o;const[i]=s;return i.length>=r.length?o.slice(r.length):o}).join(`
|
|
93
93
|
`)}class Na{constructor(t){this.options=t||nr}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:Ps(r,`
|
|
94
|
-
`)}}}fences(t){const n=this.rules.block.fences.exec(t);if(n){const r=n[0],o=MS(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=Ps(r,"#");(this.options.pedantic||!o||/ $/.test(o))&&(r=o.trim())}return{type:"heading",raw:n[0],depth:n[1].length,text:r,tokens:this.lexer.inline(r)}}}hr(t){const n=this.rules.block.hr.exec(t);if(n)return{type:"hr",raw:n[0]}}blockquote(t){const n=this.rules.block.blockquote.exec(t);if(n){const r=n[0].replace(/^ *>[ \t]?/gm,""),o=this.lexer.state.top;this.lexer.state.top=!0;const s=this.lexer.blockTokens(r);return this.lexer.state.top=o,{type:"blockquote",raw:n[0],tokens:s,text:r}}}list(t){let n=this.rules.block.list.exec(t);if(n){let r,o,s,i,a,l,c,d,f,p,
|
|
94
|
+
`)}}}fences(t){const n=this.rules.block.fences.exec(t);if(n){const r=n[0],o=MS(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=Ps(r,"#");(this.options.pedantic||!o||/ $/.test(o))&&(r=o.trim())}return{type:"heading",raw:n[0],depth:n[1].length,text:r,tokens:this.lexer.inline(r)}}}hr(t){const n=this.rules.block.hr.exec(t);if(n)return{type:"hr",raw:n[0]}}blockquote(t){const n=this.rules.block.blockquote.exec(t);if(n){const r=n[0].replace(/^ *>[ \t]?/gm,""),o=this.lexer.state.top;this.lexer.state.top=!0;const s=this.lexer.blockTokens(r);return this.lexer.state.top=o,{type:"blockquote",raw:n[0],tokens:s,text:r}}}list(t){let n=this.rules.block.list.exec(t);if(n){let r,o,s,i,a,l,c,d,f,h,p,x,m=n[1].trim();const y=m.length>1,g={type:"list",raw:"",ordered:y,start:y?+m.slice(0,-1):"",loose:!1,items:[]};m=y?`\\d{1,9}\\${m.slice(-1)}`:`\\${m}`,this.options.pedantic&&(m=y?m:"[*+-]");const b=new RegExp(`^( {0,3}${m})((?:[ ][^\\n]*)?(?:\\n|$))`);for(;t&&(x=!1,!(!(n=b.exec(t))||this.rules.block.hr.test(t)));){if(r=n[0],t=t.substring(r.length),d=n[2].split(`
|
|
95
95
|
`,1)[0].replace(/^\t+/,k=>" ".repeat(3*k.length)),f=t.split(`
|
|
96
|
-
`,1)[0],this.options.pedantic?(i=2,
|
|
97
|
-
`,t=t.substring(f.length+1),x=!0),!x){const k=new RegExp(`^ {0,${Math.min(3,i-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),C=new RegExp(`^ {0,${Math.min(3,i-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),T=new RegExp(`^ {0,${Math.min(3,i-1)}}(?:\`\`\`|~~~)`),I=new RegExp(`^ {0,${Math.min(3,i-1)}}#`);for(;t&&(
|
|
98
|
-
`,1)[0],f=
|
|
99
|
-
`+f.slice(i);else{if(l||d.search(/[^ ]/)>=4||T.test(d)||I.test(d)||C.test(d))break;
|
|
100
|
-
`+f}!l&&!f.trim()&&(l=!0),r+=
|
|
101
|
-
`,t=t.substring(
|
|
96
|
+
`,1)[0],this.options.pedantic?(i=2,p=d.trimLeft()):(i=n[2].search(/[^ ]/),i=i>4?1:i,p=d.slice(i),i+=n[1].length),l=!1,!d&&/^ *$/.test(f)&&(r+=f+`
|
|
97
|
+
`,t=t.substring(f.length+1),x=!0),!x){const k=new RegExp(`^ {0,${Math.min(3,i-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),C=new RegExp(`^ {0,${Math.min(3,i-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),T=new RegExp(`^ {0,${Math.min(3,i-1)}}(?:\`\`\`|~~~)`),I=new RegExp(`^ {0,${Math.min(3,i-1)}}#`);for(;t&&(h=t.split(`
|
|
98
|
+
`,1)[0],f=h,this.options.pedantic&&(f=f.replace(/^ {1,4}(?=( {4})*[^ ])/g," ")),!(T.test(f)||I.test(f)||k.test(f)||C.test(t)));){if(f.search(/[^ ]/)>=i||!f.trim())p+=`
|
|
99
|
+
`+f.slice(i);else{if(l||d.search(/[^ ]/)>=4||T.test(d)||I.test(d)||C.test(d))break;p+=`
|
|
100
|
+
`+f}!l&&!f.trim()&&(l=!0),r+=h+`
|
|
101
|
+
`,t=t.substring(h.length+1),d=f.slice(i)}}g.loose||(c?g.loose=!0:/\n *\n *$/.test(r)&&(c=!0)),this.options.gfm&&(o=/^\[[ xX]\] /.exec(p),o&&(s=o[0]!=="[ ] ",p=p.replace(/^\[[ xX]\] +/,""))),g.items.push({type:"list_item",raw:r,task:!!o,checked:s,loose:!1,text:p}),g.raw+=r}g.items[g.items.length-1].raw=r.trimRight(),g.items[g.items.length-1].text=p.trimRight(),g.raw=g.raw.trimRight();const S=g.items.length;for(a=0;a<S;a++)if(this.lexer.state.top=!1,g.items[a].tokens=this.lexer.blockTokens(g.items[a].text,[]),!g.loose){const k=g.items[a].tokens.filter(T=>T.type==="space"),C=k.length>0&&k.some(T=>/\n.*\n/.test(T.raw));g.loose=C}if(g.loose)for(a=0;a<S;a++)g.items[a].loose=!0;return g}}html(t){const n=this.rules.block.html.exec(t);if(n){const r={type:"html",raw:n[0],pre:!this.options.sanitizer&&(n[1]==="pre"||n[1]==="script"||n[1]==="style"),text:n[0]};if(this.options.sanitize){const o=this.options.sanitizer?this.options.sanitizer(n[0]):jt(n[0]);r.type="paragraph",r.text=o,r.tokens=this.lexer.inline(o)}return r}}def(t){const n=this.rules.block.def.exec(t);if(n){const r=n[1].toLowerCase().replace(/\s+/g," "),o=n[2]?n[2].replace(/^<(.*)>$/,"$1").replace(this.rules.inline._escapes,"$1"):"",s=n[3]?n[3].substring(1,n[3].length-1).replace(this.rules.inline._escapes,"$1"):n[3];return{type:"def",tag:r,raw:n[0],href:o,title:s}}}table(t){const n=this.rules.block.table.exec(t);if(n){const r={type:"table",header:ep(n[1]).map(o=>({text:o})),align:n[2].replace(/^ *|\| *$/g,"").split(/ *\| */),rows:n[3]&&n[3].trim()?n[3].replace(/\n[ \t]*$/,"").split(`
|
|
102
102
|
`):[]};if(r.header.length===r.align.length){r.raw=n[0];let o=r.align.length,s,i,a,l;for(s=0;s<o;s++)/^ *-+: *$/.test(r.align[s])?r.align[s]="right":/^ *:-+: *$/.test(r.align[s])?r.align[s]="center":/^ *:-+ *$/.test(r.align[s])?r.align[s]="left":r.align[s]=null;for(o=r.rows.length,s=0;s<o;s++)r.rows[s]=ep(r.rows[s],r.header.length).map(c=>({text:c}));for(o=r.header.length,i=0;i<o;i++)r.header[i].tokens=this.lexer.inline(r.header[i].text);for(o=r.rows.length,i=0;i<o;i++)for(l=r.rows[i],a=0;a<l.length;a++)l[a].tokens=this.lexer.inline(l[a].text);return r}}}lheading(t){const n=this.rules.block.lheading.exec(t);if(n)return{type:"heading",raw:n[0],depth:n[2].charAt(0)==="="?1:2,text:n[1],tokens:this.lexer.inline(n[1])}}paragraph(t){const n=this.rules.block.paragraph.exec(t);if(n){const r=n[1].charAt(n[1].length-1)===`
|
|
103
|
-
`?n[1].slice(0,-1):n[1];return{type:"paragraph",raw:n[0],text:r,tokens:this.lexer.inline(r)}}}text(t){const n=this.rules.block.text.exec(t);if(n)return{type:"text",raw:n[0],text:n[0],tokens:this.lexer.inline(n[0])}}escape(t){const n=this.rules.inline.escape.exec(t);if(n)return{type:"escape",raw:n[0],text:jt(n[1])}}tag(t){const n=this.rules.inline.tag.exec(t);if(n)return!this.lexer.state.inLink&&/^<a /i.test(n[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&/^<\/a>/i.test(n[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&/^<(pre|code|kbd|script)(\s|>)/i.test(n[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&/^<\/(pre|code|kbd|script)(\s|>)/i.test(n[0])&&(this.lexer.state.inRawBlock=!1),{type:this.options.sanitize?"text":"html",raw:n[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,text:this.options.sanitize?this.options.sanitizer?this.options.sanitizer(n[0]):jt(n[0]):n[0]}}link(t){const n=this.rules.inline.link.exec(t);if(n){const r=n[2].trim();if(!this.options.pedantic&&/^</.test(r)){if(!/>$/.test(r))return;const i=Ps(r.slice(0,-1),"\\");if((r.length-i.length)%2===0)return}else{const i=jS(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)),np(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 np(r,o,r[0],this.lexer)}}emStrong(t,n,r=""){let o=this.rules.inline.emStrong.lDelim.exec(t);if(!o||o[3]&&r.match(/[\p{L}\p{N}]/u))return;const s=o[1]||o[2]||"";if(!s||s&&(r===""||this.rules.inline.punctuation.exec(r))){const i=o[0].length-1;let a,l,c=i,d=0;const f=o[0][0]==="*"?this.rules.inline.emStrong.rDelimAst:this.rules.inline.emStrong.rDelimUnd;for(f.lastIndex=0,n=n.slice(-1*t.length+i);(o=f.exec(n))!=null;){if(a=o[1]||o[2]||o[3]||o[4]||o[5]||o[6],!a)continue;if(l=a.length,o[3]||o[4]){c+=l;continue}else if((o[5]||o[6])&&i%3&&!((i+l)%3)){d+=l;continue}if(c-=l,c>0)continue;l=Math.min(l,l+c+d);const
|
|
103
|
+
`?n[1].slice(0,-1):n[1];return{type:"paragraph",raw:n[0],text:r,tokens:this.lexer.inline(r)}}}text(t){const n=this.rules.block.text.exec(t);if(n)return{type:"text",raw:n[0],text:n[0],tokens:this.lexer.inline(n[0])}}escape(t){const n=this.rules.inline.escape.exec(t);if(n)return{type:"escape",raw:n[0],text:jt(n[1])}}tag(t){const n=this.rules.inline.tag.exec(t);if(n)return!this.lexer.state.inLink&&/^<a /i.test(n[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&/^<\/a>/i.test(n[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&/^<(pre|code|kbd|script)(\s|>)/i.test(n[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&/^<\/(pre|code|kbd|script)(\s|>)/i.test(n[0])&&(this.lexer.state.inRawBlock=!1),{type:this.options.sanitize?"text":"html",raw:n[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,text:this.options.sanitize?this.options.sanitizer?this.options.sanitizer(n[0]):jt(n[0]):n[0]}}link(t){const n=this.rules.inline.link.exec(t);if(n){const r=n[2].trim();if(!this.options.pedantic&&/^</.test(r)){if(!/>$/.test(r))return;const i=Ps(r.slice(0,-1),"\\");if((r.length-i.length)%2===0)return}else{const i=jS(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)),np(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 np(r,o,r[0],this.lexer)}}emStrong(t,n,r=""){let o=this.rules.inline.emStrong.lDelim.exec(t);if(!o||o[3]&&r.match(/[\p{L}\p{N}]/u))return;const s=o[1]||o[2]||"";if(!s||s&&(r===""||this.rules.inline.punctuation.exec(r))){const i=o[0].length-1;let a,l,c=i,d=0;const f=o[0][0]==="*"?this.rules.inline.emStrong.rDelimAst:this.rules.inline.emStrong.rDelimUnd;for(f.lastIndex=0,n=n.slice(-1*t.length+i);(o=f.exec(n))!=null;){if(a=o[1]||o[2]||o[3]||o[4]||o[5]||o[6],!a)continue;if(l=a.length,o[3]||o[4]){c+=l;continue}else if((o[5]||o[6])&&i%3&&!((i+l)%3)){d+=l;continue}if(c-=l,c>0)continue;l=Math.min(l,l+c+d);const h=t.slice(0,i+o.index+(o[0].length-a.length)+l);if(Math.min(i,l)%2){const x=h.slice(1,-1);return{type:"em",raw:h,text:x,tokens:this.lexer.inlineTokens(x)}}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=jt(r,!0),{type:"codespan",raw:n[0],text:r}}}br(t){const n=this.rules.inline.br.exec(t);if(n)return{type:"br",raw:n[0]}}del(t){const n=this.rules.inline.del.exec(t);if(n)return{type:"del",raw:n[0],text:n[2],tokens:this.lexer.inlineTokens(n[2])}}autolink(t,n){const r=this.rules.inline.autolink.exec(t);if(r){let o,s;return r[2]==="@"?(o=jt(this.options.mangle?n(r[1]):r[1]),s="mailto:"+o):(o=jt(r[1]),s=o),{type:"link",raw:r[0],text:o,href:s,tokens:[{type:"text",raw:o,text:o}]}}}url(t,n){let r;if(r=this.rules.inline.url.exec(t)){let o,s;if(r[2]==="@")o=jt(this.options.mangle?n(r[0]):r[0]),s="mailto:"+o;else{let i;do i=r[0],r[0]=this.rules.inline._backpedal.exec(r[0])[0];while(i!==r[0]);o=jt(r[0]),r[1]==="www."?s="http://"+r[0]:s=r[0]}return{type:"link",raw:r[0],text:o,href:s,tokens:[{type:"text",raw:o,text:o}]}}}inlineText(t,n){const r=this.rules.inline.text.exec(t);if(r){let o;return this.lexer.state.inRawBlock?o=this.options.sanitize?this.options.sanitizer?this.options.sanitizer(r[0]):jt(r[0]):r[0]:o=jt(this.options.smartypants?n(r[0]):r[0]),{type:"text",raw:r[0],text:o}}}}const ye={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:Ms,lheading:/^((?:.|\n(?!\n))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,_paragraph:/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,text:/^[^\n]+/};ye._label=/(?!\s*\])(?:\\.|[^\[\]\\])+/,ye._title=/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/,ye.def=st(ye.def).replace("label",ye._label).replace("title",ye._title).getRegex(),ye.bullet=/(?:[*+-]|\d{1,9}[.)])/,ye.listItemStart=st(/^( *)(bull) */).replace("bull",ye.bullet).getRegex(),ye.list=st(ye.list).replace(/bull/g,ye.bullet).replace("hr","\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))").replace("def","\\n+(?="+ye.def.source+")").getRegex(),ye._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",ye._comment=/<!--(?!-?>)[\s\S]*?(?:-->|$)/,ye.html=st(ye.html,"i").replace("comment",ye._comment).replace("tag",ye._tag).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),ye.paragraph=st(ye._paragraph).replace("hr",ye.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",ye._tag).getRegex(),ye.blockquote=st(ye.blockquote).replace("paragraph",ye.paragraph).getRegex(),ye.normal={...ye},ye.gfm={...ye.normal,table:"^ *([^\\n ].*\\|.*)\\n {0,3}(?:\\| *)?(:?-+:? *(?:\\| *:?-+:? *)*)(?:\\| *)?(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)"},ye.gfm.table=st(ye.gfm.table).replace("hr",ye.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",ye._tag).getRegex(),ye.gfm.paragraph=st(ye._paragraph).replace("hr",ye.hr).replace("heading"," {0,3}#{1,6} ").replace("|lheading","").replace("table",ye.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",ye._tag).getRegex(),ye.pedantic={...ye.normal,html:st(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",ye._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:Ms,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:st(ye.normal._paragraph).replace("hr",ye.hr).replace("heading",` *#{1,6} *[^
|
|
104
104
|
]`).replace("lheading",ye.lheading).replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").getRegex()};const ue={escape:/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,autolink:/^<(scheme:[^\s\x00-\x1f<>]*|email)>/,url:Ms,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:Ms,text:/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,punctuation:/^([\spunctuation])/};ue._punctuation="!\"#$%&'()+\\-.,/:;<=>?@\\[\\]`^{|}~",ue.punctuation=st(ue.punctuation).replace(/punctuation/g,ue._punctuation).getRegex(),ue.blockSkip=/\[[^\]]*?\]\([^\)]*?\)|`[^`]*?`|<[^>]*?>/g,ue.escapedEmSt=/(?:^|[^\\])(?:\\\\)*\\[*_]/g,ue._comment=st(ye._comment).replace("(?:-->|$)","-->").getRegex(),ue.emStrong.lDelim=st(ue.emStrong.lDelim).replace(/punct/g,ue._punctuation).getRegex(),ue.emStrong.rDelimAst=st(ue.emStrong.rDelimAst,"g").replace(/punct/g,ue._punctuation).getRegex(),ue.emStrong.rDelimUnd=st(ue.emStrong.rDelimUnd,"g").replace(/punct/g,ue._punctuation).getRegex(),ue._escapes=/\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/g,ue._scheme=/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/,ue._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])?)+(?![-_])/,ue.autolink=st(ue.autolink).replace("scheme",ue._scheme).replace("email",ue._email).getRegex(),ue._attribute=/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/,ue.tag=st(ue.tag).replace("comment",ue._comment).replace("attribute",ue._attribute).getRegex(),ue._label=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,ue._href=/<(?:\\.|[^\n<>\\])+>|[^\s\x00-\x1f]*/,ue._title=/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/,ue.link=st(ue.link).replace("label",ue._label).replace("href",ue._href).replace("title",ue._title).getRegex(),ue.reflink=st(ue.reflink).replace("label",ue._label).replace("ref",ye._label).getRegex(),ue.nolink=st(ue.nolink).replace("ref",ye._label).getRegex(),ue.reflinkSearch=st(ue.reflinkSearch,"g").replace("reflink",ue.reflink).replace("nolink",ue.nolink).getRegex(),ue.normal={...ue},ue.pedantic={...ue.normal,strong:{start:/^__|\*\*/,middle:/^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,endAst:/\*\*(?!\*)/g,endUnd:/__(?!_)/g},em:{start:/^_|\*/,middle:/^()\*(?=\S)([\s\S]*?\S)\*(?!\*)|^_(?=\S)([\s\S]*?\S)_(?!_)/,endAst:/\*(?!\*)/g,endUnd:/_(?!_)/g},link:st(/^!?\[(label)\]\((.*?)\)/).replace("label",ue._label).getRegex(),reflink:st(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",ue._label).getRegex()},ue.gfm={...ue.normal,escape:st(ue.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.!#$%&'*+\/=?_`{\|}~-]+@)))/},ue.gfm.url=st(ue.gfm.url,"i").replace("email",ue.gfm._extended_email).getRegex(),ue.breaks={...ue.gfm,br:st(ue.br).replace("{2,}","*").getRegex(),text:st(ue.gfm.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()};function PS(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 rp(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 Dn{constructor(t){this.tokens=[],this.tokens.links=Object.create(null),this.options=t||nr,this.options.tokenizer=this.options.tokenizer||new Na,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};const n={block:ye.normal,inline:ue.normal};this.options.pedantic?(n.block=ye.pedantic,n.inline=ue.pedantic):this.options.gfm&&(n.block=ye.gfm,this.options.breaks?n.inline=ue.breaks:n.inline=ue.gfm),this.tokenizer.rules=n}static get rules(){return{block:ye,inline:ue}}static lex(t,n){return new Dn(n).lex(t)}static lexInline(t,n){return new Dn(n).inlineTokens(t)}lex(t){t=t.replace(/\r\n|\r/g,`
|
|
105
105
|
`),this.blockTokens(t,this.tokens);let n;for(;n=this.inlineQueue.shift();)this.inlineTokens(n.src,n.tokens);return this.tokens}blockTokens(t,n=[]){this.options.pedantic?t=t.replace(/\t/g," ").replace(/^ +$/gm,""):t=t.replace(/^( *)(\t+)/gm,(a,l,c)=>l+" ".repeat(c.length));let r,o,s,i;for(;t;)if(!(this.options.extensions&&this.options.extensions.block&&this.options.extensions.block.some(a=>(r=a.call({lexer:this},t,n))?(t=t.substring(r.raw.length),n.push(r),!0):!1))){if(r=this.tokenizer.space(t)){t=t.substring(r.raw.length),r.raw.length===1&&n.length>0?n[n.length-1].raw+=`
|
|
106
106
|
`:n.push(r);continue}if(r=this.tokenizer.code(t)){t=t.substring(r.raw.length),o=n[n.length-1],o&&(o.type==="paragraph"||o.type==="text")?(o.raw+=`
|
|
@@ -111,7 +111,7 @@ For more information, see https://radix-ui.com/primitives/docs/components/${t.do
|
|
|
111
111
|
`+r.raw,o.text+=`
|
|
112
112
|
`+r.text,this.inlineQueue.pop(),this.inlineQueue[this.inlineQueue.length-1].src=o.text):n.push(r),i=s.length!==t.length,t=t.substring(r.raw.length);continue}if(r=this.tokenizer.text(t)){t=t.substring(r.raw.length),o=n[n.length-1],o&&o.type==="text"?(o.raw+=`
|
|
113
113
|
`+r.raw,o.text+=`
|
|
114
|
-
`+r.text,this.inlineQueue.pop(),this.inlineQueue[this.inlineQueue.length-1].src=o.text):n.push(r);continue}if(t){const a="Infinite loop on byte: "+t.charCodeAt(0);if(this.options.silent){console.error(a);break}else throw new Error(a)}}return this.state.top=!0,n}inline(t,n=[]){return this.inlineQueue.push({src:t,tokens:n}),n}inlineTokens(t,n=[]){let r,o,s,i=t,a,l,c;if(this.tokens.links){const d=Object.keys(this.tokens.links);if(d.length>0)for(;(a=this.tokenizer.rules.inline.reflinkSearch.exec(i))!=null;)d.includes(a[0].slice(a[0].lastIndexOf("[")+1,-1))&&(i=i.slice(0,a.index)+"["+tp("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)+"["+tp("a",a[0].length-2)+"]"+i.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);for(;(a=this.tokenizer.rules.inline.escapedEmSt.exec(i))!=null;)i=i.slice(0,a.index+a[0].length-2)+"++"+i.slice(this.tokenizer.rules.inline.escapedEmSt.lastIndex),this.tokenizer.rules.inline.escapedEmSt.lastIndex--;for(;t;)if(l||(c=""),l=!1,!(this.options.extensions&&this.options.extensions.inline&&this.options.extensions.inline.some(d=>(r=d.call({lexer:this},t,n))?(t=t.substring(r.raw.length),n.push(r),!0):!1))){if(r=this.tokenizer.escape(t)){t=t.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.tag(t)){t=t.substring(r.raw.length),o=n[n.length-1],o&&r.type==="text"&&o.type==="text"?(o.raw+=r.raw,o.text+=r.text):n.push(r);continue}if(r=this.tokenizer.link(t)){t=t.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.reflink(t,this.tokens.links)){t=t.substring(r.raw.length),o=n[n.length-1],o&&r.type==="text"&&o.type==="text"?(o.raw+=r.raw,o.text+=r.text):n.push(r);continue}if(r=this.tokenizer.emStrong(t,i,c)){t=t.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.codespan(t)){t=t.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.br(t)){t=t.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.del(t)){t=t.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.autolink(t,rp)){t=t.substring(r.raw.length),n.push(r);continue}if(!this.state.inLink&&(r=this.tokenizer.url(t,rp))){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
|
|
114
|
+
`+r.text,this.inlineQueue.pop(),this.inlineQueue[this.inlineQueue.length-1].src=o.text):n.push(r);continue}if(t){const a="Infinite loop on byte: "+t.charCodeAt(0);if(this.options.silent){console.error(a);break}else throw new Error(a)}}return this.state.top=!0,n}inline(t,n=[]){return this.inlineQueue.push({src:t,tokens:n}),n}inlineTokens(t,n=[]){let r,o,s,i=t,a,l,c;if(this.tokens.links){const d=Object.keys(this.tokens.links);if(d.length>0)for(;(a=this.tokenizer.rules.inline.reflinkSearch.exec(i))!=null;)d.includes(a[0].slice(a[0].lastIndexOf("[")+1,-1))&&(i=i.slice(0,a.index)+"["+tp("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)+"["+tp("a",a[0].length-2)+"]"+i.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);for(;(a=this.tokenizer.rules.inline.escapedEmSt.exec(i))!=null;)i=i.slice(0,a.index+a[0].length-2)+"++"+i.slice(this.tokenizer.rules.inline.escapedEmSt.lastIndex),this.tokenizer.rules.inline.escapedEmSt.lastIndex--;for(;t;)if(l||(c=""),l=!1,!(this.options.extensions&&this.options.extensions.inline&&this.options.extensions.inline.some(d=>(r=d.call({lexer:this},t,n))?(t=t.substring(r.raw.length),n.push(r),!0):!1))){if(r=this.tokenizer.escape(t)){t=t.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.tag(t)){t=t.substring(r.raw.length),o=n[n.length-1],o&&r.type==="text"&&o.type==="text"?(o.raw+=r.raw,o.text+=r.text):n.push(r);continue}if(r=this.tokenizer.link(t)){t=t.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.reflink(t,this.tokens.links)){t=t.substring(r.raw.length),o=n[n.length-1],o&&r.type==="text"&&o.type==="text"?(o.raw+=r.raw,o.text+=r.text):n.push(r);continue}if(r=this.tokenizer.emStrong(t,i,c)){t=t.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.codespan(t)){t=t.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.br(t)){t=t.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.del(t)){t=t.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.autolink(t,rp)){t=t.substring(r.raw.length),n.push(r);continue}if(!this.state.inLink&&(r=this.tokenizer.url(t,rp))){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,PS)){t=t.substring(r.raw.length),r.raw.slice(-1)!=="_"&&(c=r.raw.slice(-1)),l=!0,o=n[n.length-1],o&&o.type==="text"?(o.raw+=r.raw,o.text+=r.text):n.push(r);continue}if(t){const d="Infinite loop on byte: "+t.charCodeAt(0);if(this.options.silent){console.error(d);break}else throw new Error(d)}}return n}}class _a{constructor(t){this.options=t||nr}code(t,n,r){const o=(n||"").match(/\S*/)[0];if(this.options.highlight){const s=this.options.highlight(t,o);s!=null&&s!==t&&(r=!0,t=s)}return t=t.replace(/\n$/,"")+`
|
|
115
115
|
`,o?'<pre><code class="'+this.options.langPrefix+jt(o)+'">'+(r?t:jt(t,!0))+`</code></pre>
|
|
116
116
|
`:"<pre><code>"+(r?t:jt(t,!0))+`</code></pre>
|
|
117
117
|
`}blockquote(t){return`<blockquote>
|
|
@@ -131,7 +131,7 @@ ${t}</blockquote>
|
|
|
131
131
|
`}tablerow(t){return`<tr>
|
|
132
132
|
${t}</tr>
|
|
133
133
|
`}tablecell(t,n){const r=n.header?"th":"td";return(n.align?`<${r} align="${n.align}">`:`<${r}>`)+t+`</${r}>
|
|
134
|
-
`}strong(t){return`<strong>${t}</strong>`}em(t){return`<em>${t}</em>`}codespan(t){return`<code>${t}</code>`}br(){return this.options.xhtml?"<br/>":"<br>"}del(t){return`<del>${t}</del>`}link(t,n,r){if(t=Qf(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=Qf(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 op{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 sp{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 Ln{constructor(t){this.options=t||nr,this.options.renderer=this.options.renderer||new _a,this.renderer=this.options.renderer,this.renderer.options=this.options,this.textRenderer=new op,this.slugger=new sp}static parse(t,n){return new Ln(n).parse(t)}static parseInline(t,n){return new Ln(n).parseInline(t)}parse(t,n=!0){let r="",o,s,i,a,l,c,d,f,p,
|
|
135
|
-
`+(
|
|
136
|
-
Please report this to https://github.com/markedjs/marked.`,e){const o="<p>An error occurred:</p><pre>"+jt(r.message+"",!0)+"</pre>";if(t)return Promise.resolve(o);if(n){n(null,o);return}return o}if(t)return Promise.reject(r);if(n){n(r);return}throw r}}function ip(e,t){return(n,r,o)=>{typeof r=="function"&&(o=r,r=null);const s={...r};r={...me.defaults,...s};const i=OS(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(RS(r),r.hooks&&(r.hooks.options=r),o){const a=r.highlight;let l;try{r.hooks&&(n=r.hooks.preprocess(n)),l=e(n,r)}catch(f){return i(f)}const c=function(f){let p;if(!f)try{r.walkTokens&&me.walkTokens(l,r.walkTokens),p=t(l,r),r.hooks&&(p=r.hooks.postprocess(p))}catch(h){f=h}return r.highlight=a,f?i(f):o(null,p)};if(!a||a.length<3||(delete r.highlight,!l.length))return c();let d=0;me.walkTokens(l,function(f){f.type==="code"&&(d++,setTimeout(()=>{a(f.text,f.lang,function(p,h){if(p)return c(p);h!=null&&h!==f.text&&(f.text=h,f.escaped=!0),d--,d===0&&c()})},0))}),d===0&&c();return}if(r.async)return Promise.resolve(r.hooks?r.hooks.preprocess(n):n).then(a=>e(a,r)).then(a=>r.walkTokens?Promise.all(me.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&&me.walkTokens(a,r.walkTokens);let l=t(a,r);return r.hooks&&(l=r.hooks.postprocess(l)),l}catch(a){return i(a)}}}function me(e,t,n){return ip(Dn.lex,Ln.parse)(e,t,n)}me.options=me.setOptions=function(e){return me.defaults={...me.defaults,...e},vS(me.defaults),me},me.getDefaults=Gf,me.defaults=nr,me.use=function(...e){const t=me.defaults.extensions||{renderers:{},childTokens:{}};e.forEach(n=>{const r={...n};if(r.async=me.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=me.defaults.renderer||new _a;for(const s in n.renderer){const i=o[s];o[s]=(...a)=>{let l=n.renderer[s].apply(o,a);return l===!1&&(l=i.apply(o,a)),l}}r.renderer=o}if(n.tokenizer){const o=me.defaults.tokenizer||new Na;for(const s in n.tokenizer){const i=o[s];o[s]=(...a)=>{let l=n.tokenizer[s].apply(o,a);return l===!1&&(l=i.apply(o,a)),l}}r.tokenizer=o}if(n.hooks){const o=me.defaults.hooks||new Os;for(const s in n.hooks){const i=o[s];Os.passThroughHooks.has(s)?o[s]=a=>{if(me.defaults.async)return Promise.resolve(n.hooks[s].call(o,a)).then(c=>i.call(o,c));const l=n.hooks[s].call(o,a);return i.call(o,l)}:o[s]=(...a)=>{let l=n.hooks[s].apply(o,a);return l===!1&&(l=i.apply(o,a)),l}}r.hooks=o}if(n.walkTokens){const o=me.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}}me.setOptions(r)})},me.walkTokens=function(e,t){let n=[];for(const r of e)switch(n=n.concat(t.call(me,r)),r.type){case"table":{for(const o of r.header)n=n.concat(me.walkTokens(o.tokens,t));for(const o of r.rows)for(const s of o)n=n.concat(me.walkTokens(s.tokens,t));break}case"list":{n=n.concat(me.walkTokens(r.items,t));break}default:me.defaults.extensions&&me.defaults.extensions.childTokens&&me.defaults.extensions.childTokens[r.type]?me.defaults.extensions.childTokens[r.type].forEach(function(o){n=n.concat(me.walkTokens(r[o],t))}):r.tokens&&(n=n.concat(me.walkTokens(r.tokens,t)))}return n},me.parseInline=ip(Dn.lexInline,Ln.parseInline),me.Parser=Ln,me.parser=Ln.parse,me.Renderer=_a,me.TextRenderer=op,me.Lexer=Dn,me.lexer=Dn.lex,me.Tokenizer=Na,me.Slugger=sp,me.Hooks=Os,me.parse=me,me.options,me.setOptions,me.use,me.walkTokens,me.parseInline,Ln.parse,Dn.lex;function so({content:e,className:t="",allowHtml:n=!1,style:r}){const o=w.useMemo(()=>{try{if(!n){const i=e.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,"").replace(/<iframe\b[^<]*(?:(?!<\/iframe>)<[^<]*)*<\/iframe>/gi,"").replace(/javascript:/gi,"").replace(/on\w+\s*=/gi,"");return typeof me.parse=="function"?me.parse(i):me(i)}return typeof me.parse=="function"?me.parse(e):me(e)}catch(i){return console.error("[MarkdownContent] parse error",i),`<pre class="font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words">Error rendering markdown: ${String(i)}</pre>`}},[e,n]),s=w.useMemo(()=>{const i={color:"currentColor",...r};if(r&&r.color){const a=r.color;return{...i,"--tw-prose-body":a,"--tw-prose-headings":a,"--tw-prose-links":a,"--tw-prose-bold":a,"--tw-prose-counters":a,"--tw-prose-bullets":a,"--tw-prose-hr":a,"--tw-prose-quotes":a,"--tw-prose-quote-borders":a,"--tw-prose-captions":a,"--tw-prose-code":a,"--tw-prose-pre-code":a,"--tw-prose-pre-bg":"inherit","--tw-prose-th-borders":a,"--tw-prose-td-borders":a}}return i},[r]);return u.jsx("div",{className:ne("markdown prose prose-sm max-w-none break-words","dark:prose-invert","text-current","prose-headings:text-current prose-p:text-current prose-li:text-current prose-a:text-current prose-strong:text-current","prose-em:text-current prose-blockquote:text-current prose-table:text-current prose-td:text-current prose-th:text-current","prose-pre:font-mono prose-pre:text-xs prose-pre:bg-background/50 prose-pre:border prose-pre:rounded prose-pre:p-3 prose-pre:whitespace-pre prose-pre:overflow-x-auto","prose-code:font-mono prose-code:text-sm prose-code:bg-background/50 prose-code:px-1.5 prose-code:py-0.5 prose-code:rounded prose-code:text-current",t),style:s,dangerouslySetInnerHTML:{__html:o}})}const DS={MODE:"library"};function LS(){var i;const e=typeof globalThis<"u"?globalThis.process:void 0,t=typeof((i=e==null?void 0:e.env)==null?void 0:i.NODE_ENV)=="string"?e.env.NODE_ENV:void 0;if(t)return t==="production";const n=typeof{url:typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Ys&&Ys.tagName.toUpperCase()==="SCRIPT"&&Ys.src||new URL("index.umd.js",document.baseURI).href}<"u"?DS:void 0,r=typeof(n==null?void 0:n.MODE)=="string"?n.MODE:void 0,o=typeof(n==null?void 0:n.NODE_ENV)=="string"?n.NODE_ENV:void 0;return(r??o)==="production"}function $S(){return!LS()}function FS(){return typeof window>"u"?!1:window.__ARTIFACT_DEBUG__===!0}function BS(){return $S()||FS()}function zS({preview:e,idx:t}){return w.useEffect(()=>{BS()&&console.debug(`[MessageComponent] Preview ${t} mounted:`,{src:e.src.substring(0,100),alt:e.alt,label:e.label})},[t,e]),u.jsxs("div",{className:"space-y-2",children:[e.label&&u.jsxs("p",{className:"text-[0.65rem] uppercase tracking-wide text-muted-foreground",children:["Artifact: ",e.label]}),u.jsx("div",{className:"overflow-hidden rounded border border-border/60 bg-background/60 p-1 shadow-sm",children:u.jsx("img",{src:e.src,alt:e.alt,title:e.label,loading:"lazy",className:"h-auto max-h-[420px] w-full rounded object-contain",onLoad:()=>{},onError:n=>{console.error(`[MessageComponent] ❌ Image failed to load for artifact ${t}:`,{alt:e.alt,label:e.label,message:n.target.alt})}})})]})}const US="prose prose-sm max-w-none break-words dark:prose-invert prose-headings:break-words prose-p:break-words prose-li:break-words prose-td:break-words prose-th:break-words prose-a:break-all prose-code:break-words prose-blockquote:break-words";function ap({data:e}){return Array.isArray(e)?e.every(n=>n===null||["string","number","boolean"].includes(typeof n))?u.jsx("div",{className:US,children:u.jsx("ul",{className:"list-disc pl-5",children:e.map((n,r)=>u.jsx("li",{children:String(n)},r))})}):u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:ro(e)}):u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:ro(e)})}const io=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:ne("rounded-lg border bg-card text-card-foreground shadow-sm",e),...t}));io.displayName="Card";const ao=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:ne("flex flex-col space-y-1.5 p-6",e),...t}));ao.displayName="CardHeader";const lo=v.forwardRef(({className:e,...t},n)=>u.jsx("h3",{ref:n,className:ne("text-2xl font-semibold leading-none tracking-tight",e),...t}));lo.displayName="CardTitle";const lp=v.forwardRef(({className:e,...t},n)=>u.jsx("p",{ref:n,className:ne("text-sm text-muted-foreground",e),...t}));lp.displayName="CardDescription";const co=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:ne("p-6 pt-0",e),...t}));co.displayName="CardContent";const cp=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:ne("flex items-center p-6 pt-0",e),...t}));cp.displayName="CardFooter";function HS({interruptPart:e,onApprove:t,onReject:n,disabled:r,isActive:o,payload:s}){const i=e.title??"Approve the result?";let a=null;if(s!=null)if(typeof s=="string")a=u.jsx("p",{className:"text-sm leading-relaxed text-blue-800/90 dark:text-blue-200/90 whitespace-pre-wrap",children:s});else{const c=ro(s);a=u.jsx("pre",{className:"max-h-48 overflow-auto rounded bg-blue-100/60 p-2 text-xs text-blue-900/90 dark:bg-blue-900/40 dark:text-blue-100/80",children:c})}const l=o?"Please approve or reject this action to resume the workflow.":"Waiting for approval from another participant.";return u.jsxs(io,{className:ne("border-blue-200 dark:border-blue-800 bg-blue-50/50 dark:bg-blue-950/10 transition-shadow",o?"shadow-md ring-1 ring-blue-300 dark:ring-blue-500/70":"opacity-80"),children:[u.jsxs(ao,{className:"pb-3",children:[u.jsx(lo,{className:"text-blue-900 dark:text-blue-100 text-base",children:i}),u.jsx(lp,{className:"text-blue-700 dark:text-blue-300 text-sm",children:l})]}),a&&u.jsx(co,{className:"pt-0 pb-3",children:a}),u.jsx(cp,{className:"pt-0",children:u.jsxs("div",{className:"flex gap-2 ml-auto",children:[u.jsx(Xe,{size:"sm",variant:"outline",onClick:()=>n(e),className:"border-red-300 text-red-700 hover:bg-red-50 dark:border-red-700 dark:text-red-300 dark:hover:bg-red-950/50",disabled:r||!o,children:"Reject"}),u.jsx(Xe,{size:"sm",onClick:()=>t(e),className:"bg-blue-600 hover:bg-blue-700 text-white",disabled:r||!o,children:"Approve"})]})})]})}function WS(e){const{allowFileOpen:t,currentThreadId:n}=e,{toast:r}=Aa(),[o,s]=w.useState({}),[i,a]=w.useState(null),[l,c]=w.useState(!1),d=w.useCallback(()=>{c(!1),a(null)},[]),f=w.useCallback(h=>{a(h),c(!0)},[]),p=w.useCallback(async(h,x,m)=>{var y,g;if(!t){h.preventDefault();return}if(o[m]){h.preventDefault();return}try{const b=String(x.url??""),S=b.match(/\/chat\/files\/([^/]+)(?:\/(view|download))?/);if(S){h.preventDefault();const k=S[1],C=x.name||`file_${k}`,T=x.mimeType||"application/octet-stream";f({id:k,name:C,mimeType:T});return}if(b.startsWith("data:")){h.preventDefault(),s(C=>({...C,[m]:!0}));const k=r({title:"Fetching file...",description:"",open:!0});try{const C=await Q0(n??void 0);if(!C||!Array.isArray(C))throw new Error("Invalid file list response");const T=C.find(I=>!I||typeof I!="object"||!((I.filename??"")===(x.name??""))?!1:typeof x.size=="number"&&typeof I.size=="number"?I.size===x.size:!0);if(!(T!=null&&T.id))throw new Error(`File "${x.name}" is not yet available on the server`);if(!T.id||!T.filename)throw new Error("Invalid file data received from server");f({id:T.id,name:x.name||T.filename||`file_${T.id}`,mimeType:x.mimeType||T.mime_type||"application/octet-stream"}),(y=k.update)==null||y.call(k,{id:k.id,title:"Success",description:`Opened ${x.name}`,open:!0})}catch(C){console.error("Failed to fetch server file:",C);const T=C instanceof Error?C.message:"Unknown error occurred";(g=k.update)==null||g.call(k,{id:k.id,title:"Failed",description:T}),r({title:"Failed to fetch file",description:T,open:!0})}finally{s(C=>({...C,[m]:!1}))}}}catch(b){console.error("File click error:",b),s(S=>({...S,[m]:!1}))}},[t,o,r,n,f]);return{uploadingFiles:o,handleFileClick:p,fileViewerOpen:l,currentFileInfo:i,closeFileViewer:d}}function VS({text:e,expanded:t,onExpandedChange:n,previewLength:r,isCompact:o}){const s=Math.max(e.length-r,0),i=e.substring(0,r);return u.jsxs("div",{className:"flex flex-col gap-1",children:[u.jsx("div",{className:ne("text-sm text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:t?u.jsx(so,{content:e,allowHtml:!1}):u.jsxs("pre",{className:ne("font-sans whitespace-pre-wrap break-words bg-transparent p-0 m-0 text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:[i,"..."]})}),u.jsx(Xe,{type:"button",variant:"ghost",size:"sm",className:"h-6 text-xs !text-[hsl(var(--chat-bubble-user-text))]",onClick:()=>n(!t),children:t?u.jsxs(u.Fragment,{children:[u.jsx(ae.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):u.jsxs(u.Fragment,{children:[u.jsx(ae.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more (",s," chars)"]})})]})}function KS({message:e,viewMode:t}){const r=bf(e).name||"tool",o=c=>{if(c==null)return null;const d=typeof c=="string"?Sa(c)??c:c;if(d&&typeof d=="object")return u.jsx(ap,{data:d});const f=typeof d=="string"?d:(()=>{try{return ro(d)}catch{return String(d??"")}})();return u.jsx("pre",{className:"whitespace-pre-wrap break-words font-sans text-sm text-foreground/90",children:f})},s=c=>{if(c==null)return null;const{content:d,isMarkdown:f}=W0(c);return f?u.jsx(so,{content:d,className:"text-current"}):o(c)};if(t==="preview")return null;const i=e.content.find(c=>c.type!=="tool_call");if(!i)return u.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[u.jsx(ae.Loader,{className:"h-4 w-4 animate-spin"}),u.jsxs("span",{children:["Waiting for ",r," output…"]})]});if(i.type==="text"){const d=(i.text??"").trim();if(!d)return null;const f=Cs(d);return s(f)}const a=no(i),l=Cs(a);return s(l)}function qS({className:e}){const[t,n]=w.useState(0);return w.useEffect(()=>{const r=setInterval(()=>n(o=>(o+1)%4),500);return()=>clearInterval(r)},[]),u.jsxs("span",{"aria-live":"polite",className:ne("inline-block text-xs opacity-70 ml-1",e),children:["Is thinking",".".repeat(t)]})}const Ds=w.memo(function({message:t,messageIndex:n,isStreamingMessage:r=!1,isEditing:o=!1,showActions:s=!0,showTimestamp:i=!0,showAgentName:a=!0,layoutSize:l="desktop",truncateUserMessages:c=!0,userMessagePreviewLength:d=500,showToolMessages:f=!0,showArtifactPreviews:p=!0,customStyles:h={},onEdit:x,onRegenerate:m,onCancelEdit:y,onCopy:g,activeInterrupt:b,disableInterruptActions:S=!1,onInterruptActionStart:k,onInterruptActionEnd:C,checkpointCandidates:T=[],activeCheckpointId:I=null,onSelectCheckpoint:A,defaultCheckpointId:R=null,messageParentCheckpointId:L=null}){const[P,D]=w.useState(!1),[F,N]=w.useState("preview"),[B,j]=w.useState(!1),{currentThreadId:V}=_o(),{respondToInterrupt:z}=jo(),M=l==="phone"||l==="half-screen",q=t.role,J=q==="tool",se=w.useMemo(()=>"type"in t&&t.type==="default_message"?t:null,[t]),ge=!!se,Ee=!(r&&q!=="user"),{uploadingFiles:Y,handleFileClick:U,fileViewerOpen:Z,currentFileInfo:$,closeFileViewer:K}=WS({allowFileOpen:Ee,currentThreadId:V}),Q=w.useMemo(()=>{switch(q){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))]"}},[q]),ce=w.useMemo(()=>{if(se)return"";const _=t.content;return Array.isArray(_)?V0(_):""},[se,t]),oe=w.useMemo(()=>{if(se)return{};const _=t.content;return Array.isArray(_)?bf(t):{}},[se,t]),Ne=w.useMemo(()=>{if(se)return[];const _=t.content;return Array.isArray(_)?_.filter(X=>X.type==="image_url"):[]},[se,t]),Ue=w.useMemo(()=>{if(se)return[];const _=t.content;return Array.isArray(_)?_.filter(X=>X.type==="file"):[]},[se,t]),re=w.useMemo(()=>{if(se)return[];const _=t.content;return Array.isArray(_)?_.filter(X=>X.type==="interrupt"):[]},[se,t]),xe=(b==null?void 0:b.id)??(b==null?void 0:b.interrupt_id),Pe=Ts(xe),Ze=b==null?void 0:b.value,Qe=w.useMemo(()=>{if(se)return"";const _=t.content;return Array.isArray(_)?K0(_):""},[se,t]),Ve=w.useMemo(()=>{if(se||!p)return[];const X=t.artifact;if(!X)return[];const te=[],pe=[...Array.isArray(X.plots)?X.plots:[]];for(const ve of pe){const we=J0(ve);we&&te.push(we)}return te},[se,t,p]),tt=w.useCallback(async()=>{const _=J?Qe:ce;async function X(te){if(navigator.clipboard&&typeof navigator.clipboard.writeText=="function"){await navigator.clipboard.writeText(te);return}if(navigator.clipboard&&typeof navigator.clipboard.write=="function"&&typeof ClipboardItem<"u"){const pe=new Blob([te],{type:"text/plain"});await navigator.clipboard.write([new ClipboardItem({"text/plain":pe})]);return}throw new Error("Clipboard API not supported in this context.")}try{await X(_),D(!0),setTimeout(()=>D(!1),2e3),g==null||g(_)}catch(te){console.error("Failed to copy:",te)}},[J,Qe,ce,g]),it=w.useCallback(()=>{if(!x)return;const _=J?Qe:ce,X="type"in t&&t.type==="default_message"?void 0:{checkpointId:t.checkpointId??null,checkpointNs:t.checkpointNs??null};x(t.id,_,X)},[x,t.id,J,Qe,ce,t]),qe=w.useCallback(()=>{m==null||m(n)},[m,n]),nt=w.useCallback(()=>{const X=ne(M?"h-3 w-3":"h-4 w-4","opacity-60 flex-shrink-0",Q);switch(q){case"user":return u.jsx(ae.User,{className:X});case"assistant":return u.jsx(ae.Bot,{className:X});case"tool":return u.jsx(ae.Wrench,{className:X});default:return u.jsx(ae.Bot,{className:X})}},[M,Q,q]),at=w.useCallback(()=>{const _="group relative mb-4 flex w-full";switch(q){case"user":return ne(_,"justify-end");case"assistant":case"tool":case"system":return ne(_,"justify-start");default:return _}},[q]),Rt=w.useCallback(()=>{const _=ne("rounded-lg px-4 py-3 relative min-w-0 max-w-full break-words",M&&"px-3 py-2 text-sm");if(ge)return ne(_,"w-full","bg-[hsl(var(--chat-bubble-ai))] text-[hsl(var(--chat-bubble-ai-text))]","border border-border/60 dark:border-border/40 shadow-sm");switch(q){case"user":return ne(_,"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 ne(_,"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 ne(_,"w-full md:max-w-[95%] bg-secondary/50 text-secondary-foreground border border-dashed");case"system":return ne(_,"w-full md:max-w-[85%] bg-accent/40 text-muted-foreground border");default:return ne(_,"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")}},[M,ge,q]),gt=w.useCallback(async _=>{if(S)return;const X=Ts((_==null?void 0:_.id)??(_==null?void 0:_.interrupt_id));if(!X){console.warn("Interrupt part missing id",_);return}try{k==null||k(),await z(X,!0)}catch(te){console.error("Failed to approve interrupt:",te)}finally{C==null||C()}},[S,C,k,z]),ht=w.useCallback(async _=>{if(S)return;const X=Ts((_==null?void 0:_.id)??(_==null?void 0:_.interrupt_id));if(!X){console.warn("Interrupt part missing id",_);return}try{k==null||k(),await z(X,!1)}catch(te){console.error("Failed to reject interrupt:",te)}finally{C==null||C()}},[S,C,k,z]),bt=w.useCallback(({part:_,i:X})=>{if(_.type==="text"){const te=_.text??"",pe=te.trim(),ve=Sa(pe);return ve&&q!=="tool"?u.jsx(ap,{data:ve},X):q==="user"&&c&&pe.length>d?u.jsx(VS,{text:pe,expanded:B,onExpandedChange:j,previewLength:d,isCompact:M},X):u.jsx(so,{content:te,allowHtml:!1},X)}if(_.type==="image_url"){const te=_;return u.jsx("div",{className:"my-2",children:u.jsx("img",{src:te.url,alt:te.alt??"",loading:"lazy",className:"border rounded max-h-[420px] w-auto object-contain"})},X)}if(_.type==="file"){const te=_,pe=te.name||"file";return u.jsxs("a",{href:te.url,onClick:ve=>U(ve.nativeEvent,te,X),className:`inline-flex items-center gap-2 rounded px-2 py-1 text-xs bg-gray-100 border hover:bg-gray-200
|
|
137
|
-
dark:bg-background/10 dark:border-border/30 dark:hover:bg-background/20`,children:[Y[X]?u.jsx(ae.Loader,{className:"h-4 w-4 animate-spin"}):null,u.jsxs("span",{className:"truncate max-w-[180px]",children:[pe,Y[X]?" (processing)":""]})]},X)}if(_.type==="interrupt"){const te=_,pe=Ts((te==null?void 0:te.id)??(te==null?void 0:te.interrupt_id)),ve=!!(Pe&&pe&&pe===Pe),we=ve?Ze??(te==null?void 0:te.value):te==null?void 0:te.value,Fe=pe?{...te,id:pe,interrupt_id:pe}:te;return u.jsx(HS,{interruptPart:Fe,onApprove:gt,onReject:ht,disabled:S,isActive:ve,payload:we},X)}return null},[U,Y,gt,ht,q,c,d,B,M,Pe,Ze,b,S,re]),St=w.useCallback(()=>u.jsxs("div",{className:"flex items-center gap-2 p-2 bg-muted/30 rounded",children:[u.jsx(ae.Paperclip,{className:"h-4 w-4 text-muted-foreground"}),u.jsx("span",{className:"text-sm text-muted-foreground",children:"File upload"})]}),[]),Lt=w.useCallback(()=>{const _=ce.trim().length>0||Ne.length>0||Ue.length>0||re.length>0;if(!J&&Ue.length>0&&!r)return St();if(!J&&!_&&!r)return null;if(J)return!f&&Ve.length>0?null:f?u.jsx(KS,{message:t,viewMode:F},t.id):null;if(!J&&!se){const X=t,te=u.jsx("div",{className:"space-y-2",children:X.content.map((pe,ve)=>u.jsx(bt,{part:pe,i:ve},ve))});return r?u.jsxs("div",{"aria-busy":"true",role:"status",children:[te,u.jsx(qS,{className:Q})]}):te}},[ce,Ne.length,Ue.length,re.length,r,J,F,f,Ve.length,St,Q]),Mt=w.useMemo(()=>se?"Assistant":q0(t),[se,t]),et=w.useMemo(()=>se?[]:Array.isArray(T)?T:[],[T,se]),It=w.useMemo(()=>{var _;return et.length?R&&et.some(X=>X.id===R)?R:((_=et[0])==null?void 0:_.id)??null:null},[R,et]),Ge=w.useMemo(()=>!et.length||!I?null:et.some(_=>_.id===I)?I:null,[I,et])??It,Ye=q==="user"&&et.length>0&&typeof A=="function",pt=w.useCallback((_,X=!1)=>{if(!A)return;const te=(_==null?void 0:_.id)??null,pe=(_==null?void 0:_.parentId)??L??null;A(te,pe,X)},[L,A]),lt=w.useMemo(()=>Ge?et.findIndex(_=>_.id===Ge):-1,[Ge,et]),G=w.useMemo(()=>lt<0?null:et[lt]??null,[lt,et]);return J&&!f&&Ve.length===0?null:ge&&se?u.jsx("div",{className:ne(at(),h.container),children:u.jsxs("div",{className:ne(Rt(),h.content),children:[u.jsxs("div",{className:"flex items-center gap-2 mb-2 pb-2 border-b border-current/10",children:[u.jsx(ae.Bot,{className:ne("h-4 w-4",Q)}),a&&u.jsx("span",{className:"font-medium text-sm",children:"Assistant"})]}),u.jsx(so,{content:se.content,className:"text-current"})]})}):u.jsxs(u.Fragment,{children:[u.jsx("div",{className:ne(at(),h.container),children:u.jsxs("div",{className:ne(Rt(),h.content),children:[(i||a||J)&&u.jsxs("div",{className:ne("flex items-center justify-between mb-2 pb-2 border-b border-current/10",M&&"mb-1 pb-1",Q,h.header),children:[u.jsxs("div",{className:"flex items-center gap-2",children:[nt(),a&&Mt&&u.jsx("span",{className:ne("font-medium",M?"text-xs":"text-sm"),children:Mt}),J&&u.jsxs(yf,{variant:"outline",className:ne("text-xs flex items-center gap-1 cursor-pointer select-none",Q,"border border-current/40",M&&"text-xs h-4"),role:"button",tabIndex:0,"aria-expanded":F==="expanded",onClick:()=>N(_=>_==="expanded"?"preview":"expanded"),onKeyDown:_=>{(_.key==="Enter"||_.key===" ")&&(_.preventDefault(),N(X=>X==="expanded"?"preview":"expanded"))},children:[u.jsx("span",{children:oe.name??"Tool Output"}),oe.toolCallId&&u.jsx("span",{className:"opacity-70",children:oe.toolCallId.slice(0,8)}),F==="expanded"?u.jsx(ae.ChevronUp,{className:"h-3 w-3"}):u.jsx(ae.ChevronDown,{className:"h-3 w-3"})]})]}),u.jsxs("div",{className:"flex items-center gap-2",children:[Ye&&G&<>=0&&u.jsx("div",{className:"flex flex-wrap items-center gap-2 text-xs",children:u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx("button",{type:"button",className:ne("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",lt<et.length-1?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(lt>=et.length-1)return;const _=et[lt+1];_&&pt(_)},"aria-label":"Older checkpoint (back in time)",disabled:lt>=et.length-1,children:u.jsx(ae.ChevronLeft,{className:"h-3 w-3"})}),u.jsx("div",{className:"flex items-center gap-2",children:u.jsxs("span",{className:"whitespace-nowrap",children:[et.length-lt," / ",et.length]})}),u.jsx("button",{type:"button",className:ne("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",lt>0?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(!(lt<=0))if(lt===1)pt(null,!0);else{const _=et[lt-1];_&&pt(_,!1)}},"aria-label":"Newer checkpoint (forward in time)",disabled:lt<=0,children:u.jsx(ae.ChevronRight,{className:"h-3 w-3"})})]})}),i&&t.createdAt&&u.jsx("time",{className:ne("text-xs opacity-60",Q,M&&"text-xs"),dateTime:new Date(t.createdAt).toISOString(),title:new Date(t.createdAt).toLocaleString(),children:new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit"}).format(new Date(t.createdAt))}),s&&!o&&u.jsxs("div",{className:ne("opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",h.actions),children:[u.jsx("div",{className:"relative",children:u.jsx(Xe,{variant:"ghost",size:"sm",onClick:()=>tt(),className:ne("h-6 w-6 p-0 hover:bg-foreground/10",Q,M&&"h-5 w-5"),"aria-label":"Copy message",title:"Copy message",children:u.jsx(ae.Copy,{className:ne(P?"text-success":Q,M?"h-3 w-3":"h-4 w-4")})})}),q==="user"&&x&&u.jsx(Xe,{variant:"ghost",size:"sm",onClick:it,className:ne("h-6 w-6 p-0 hover:bg-foreground/10",Q,M&&"h-5 w-5"),"aria-label":"Edit message",children:u.jsx(ae.Edit,{className:ne(Q,M?"h-3 w-3":"h-4 w-4")})}),q==="assistant"&&m&&u.jsx(Xe,{variant:"ghost",size:"sm",onClick:qe,className:ne("h-6 w-6 p-0 hover:bg-foreground/10",Q,M&&"h-5 w-5"),"aria-label":"Regenerate response",children:u.jsx(ae.RotateCcw,{className:ne(Q,M?"h-3 w-3":"h-4 w-4")})})]})]})]}),u.jsxs("div",{className:"relative",children:[Lt(),p&&Ve.length>0&&u.jsx("div",{className:"mt-3 space-y-4",children:Ve.map((_,X)=>u.jsx(zS,{preview:_,idx:X},`artifact-${X}`))})]}),J&&F==="expanded"&&(oe.toolCallId||oe.name)&&u.jsxs("div",{className:ne("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",M&&"text-xs"),children:[oe.name&&u.jsxs("div",{children:["Function: ",oe.name]}),oe.toolCallId&&u.jsxs("div",{children:["Call ID: ",oe.toolCallId]})]}),!(i||a||J)&&s&&!o&&u.jsxs("div",{className:ne("absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",h.actions),children:[u.jsx(Xe,{variant:"ghost",size:"sm",onClick:()=>tt(),className:ne("h-6 w-6 p-0 hover:bg-background/50 text-current",M&&"h-5 w-5"),children:u.jsx(ae.Copy,{className:ne(P?"text-success":"text-current",M?"h-3 w-3":"h-4 w-4")})}),q==="user"&&x&&u.jsx(Xe,{variant:"ghost",size:"sm",onClick:it,className:ne("h-6 w-6 p-0 hover:bg-background/50 text-current",M&&"h-5 w-5"),children:u.jsx(ae.Edit,{className:ne("text-current",M?"h-3 w-3":"h-4 w-4")})}),q==="assistant"&&m&&u.jsx(Xe,{variant:"ghost",size:"sm",onClick:qe,className:ne("h-6 w-6 p-0 hover:bg-background/50 text-current",M&&"h-5 w-5"),children:u.jsx(ae.RotateCcw,{className:ne("text-current",M?"h-3 w-3":"h-4 w-4")})})]})]})}),$&&u.jsx(yS,{isOpen:Z,onClose:K,fileId:$.id,fileName:$.name,mimeType:$.mimeType})]})},(e,t)=>{var i,a,l,c,d,f,p,h;if(t.isStreamingMessage||e.isStreamingMessage||!(e.message.id===t.message.id&&wf(e.message)===wf(t.message)))return!1;const o=["isEditing","showActions","layoutSize","showTimestamp","showAgentName","truncateUserMessages","userMessagePreviewLength","showToolMessages","attemptMeta"].every(x=>e[x]===t[x]),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)===((c=t.customStyles)==null?void 0:c.content)&&((d=e.customStyles)==null?void 0:d.actions)===((f=t.customStyles)==null?void 0:f.actions)&&((p=e.customStyles)==null?void 0:p.header)===((h=t.customStyles)==null?void 0:h.header);return o&&s});Ds.displayName="MessageComponent";function GS(e,t){return w.useMemo(()=>{var d,f,p,h,x;const n=e&&"type"in e&&e.type==="default_message";let r=[],o=null,s={},i={},a=null,l=null,c=null;if(!n&&e){const m=e,y=m.checkpointId??null;s=m.additionalKwargs??{},i=m.responseMetadata??{};const g=y&&t.checkpointMetaById?t.checkpointMetaById.get(y)??null:null;a=typeof s.step=="number"?s.step:typeof i.step=="number"?i.step:(g==null?void 0:g.step)??null;const b=typeof s.source=="string"?s.source:typeof i.source=="string"?i.source:(g==null?void 0:g.source)??null;l=b?String(b):null;const S=a!==null&&l?`${a}:${l}`:null;if(S&&((d=t.checkpointIndexByKey)!=null&&d.has(S))?r=t.checkpointIndexByKey.get(S)??[]:y&&g&&(r=[g]),o=y??((f=r[0])==null?void 0:f.id)??null,c=y?((p=t.attemptMetaById)==null?void 0:p.get(y))??null:null,!c&&(e==null?void 0:e.role)==="user"&&(e!=null&&e.id)&&t.userMessageIdToAttempts){const k=t.userMessageIdToAttempts.get(e.id);if(k&&k.length>0){const C=k[0].checkpointId;c=((h=t.attemptMetaById)==null?void 0:h.get(C))??null,c&&console.log(`[useMessageMetadata] Found attempt by user message ID "${e.id}":`,k.length,"versions")}}if(!c&&r.length>0&&t.attemptMetaById){const k=t.attemptMetaById.get(r[0].id);k&&(c=k)}if(c&&c.attemptCount>1&&t.attemptMetaById){const k=c.baseUserMessageId;if(k){const C=[];for(const[T,I]of t.attemptMetaById.entries())if(I.baseUserMessageId===k){const A=(x=t.checkpointMetaById)==null?void 0:x.get(T);A&&C.push(A)}C.length>0&&(r=C)}}if(c&&c.attemptCount>1&&t.checkpointMetaById&&t.attemptMetaById){const k=[];for(const[C,T]of t.checkpointMetaById.entries()){const I=t.attemptMetaById.get(C);I&&I.attemptCount===c.attemptCount&&I.baseUserMessageId===c.baseUserMessageId&&k.push(T)}k.sort((C,T)=>{const I=C.createdAt?Date.parse(C.createdAt):0;return(T.createdAt?Date.parse(T.createdAt):0)-I}),k.length>0&&(r=k,console.log("[useMessageMetadata] Populated checkpointCandidates with all attempts:",{messageId:e.id,attemptCount:c.attemptCount,candidateIds:r.map(C=>C.id)}))}}return{checkpointCandidates:r,defaultCheckpointId:o,attemptMeta:c,resolvedStep:a,resolvedSource:l}},[e,t.checkpointMetaById,t.checkpointIndexByKey,t.attemptMetaById,t.userMessageIdToAttempts])}const up=(e,t)=>(e==null?void 0:e.id)??`message-${t}`,dp=w.memo(function({message:t,index:n,isStreaming:r,streamingAssistantId:o,streamingDebounceMs:s,layoutSize:i,enableMessageEditing:a,editingMessageId:l,onEdit:c,onRegenerate:d,onCancelEdit:f,activeInterrupt:p,disableInterruptActions:h,onInterruptActionStart:x,onInterruptActionEnd:m,showToolMessages:y,showArtifactPreviews:g,checkpointMetaById:b,checkpointIndexByKey:S,attemptMetaById:k,userMessageIdToAttempts:C,activeCheckpointId:T,onSelectCheckpoint:I}){const A=up(t,n),R="type"in t&&t.type==="default_message",{checkpointCandidates:L,defaultCheckpointId:P,attemptMeta:D}=GS(t,{checkpointMetaById:b,checkpointIndexByKey:S,attemptMetaById:k,userMessageIdToAttempts:C}),F=t&&!R?t.additionalKwargs??{}:{},N=t&&!R?t.responseMetadata??{}:{},B=(()=>{if(typeof F.parentCheckpointId=="string")return F.parentCheckpointId;if(typeof N.parentCheckpointId=="string")return N.parentCheckpointId})();return u.jsx("div",{className:"relative mb-4 last:mb-0","data-message-id":A,style:{minHeight:"60px",containIntrinsicSize:"auto 120px"},children:u.jsx(Ds,{message:t,messageIndex:n,isStreamingMessage:r&&o===t.id,streamingDebounceMs:s,isEditing:l===t.id,showActions:a,showTimestamp:!1,showAgentName:!0,layoutSize:i,onEdit:c,onRegenerate:()=>d(n),onCancelEdit:f,activeInterrupt:p,disableInterruptActions:h,onInterruptActionStart:x,onInterruptActionEnd:m,showToolMessages:y,showArtifactPreviews:g,checkpointCandidates:L,activeCheckpointId:T??null,onSelectCheckpoint:I,defaultCheckpointId:P,messageParentCheckpointId:B,attemptMeta:D})})});dp.displayName="MessageRow";const ja=w.forwardRef(({messages:e,isStreaming:t,streamingAssistantId:n,streamingDebounceMs:r,layoutSize:o,enableMessageEditing:s,editingMessageId:i,onStartReached:a,onEdit:l,onRegenerate:c,onCancelEdit:d,className:f,style:p,emptyMessage:h,followNewMessages:x=!0,isNavigatingCheckpoint:m=!1,onScrollAway:y,onAtBottom:g,activeInterrupt:b,disableInterruptActions:S=!1,onInterruptActionStart:k,onInterruptActionEnd:C,showToolMessages:T=!0,showArtifactPreviews:I=!0,checkpointMetaById:A,checkpointIndexByKey:R,attemptMetaById:L,userMessageIdToAttempts:P,activeCheckpointId:D,onSelectCheckpoint:F,createSyntheticThinkingMessage:N=!1},B)=>{const j=w.useRef(null),V=w.useRef(null),z=w.useRef(!1),M=w.useRef(!1),[q,J]=w.useState(!0),se=w.useMemo(()=>b?e.some(re=>"type"in re&&re.type==="default_message"?!1:Array.isArray(re==null?void 0:re.content)&&re.content.some(xe=>xe&&xe.type==="interrupt"&&(xe.id??xe.interrupt_id)===b.id)):!1,[b,e]),ge=w.useMemo(()=>{if(!b||se)return null;const re=b.id&&String(b.id).trim()?String(b.id).trim():"pending-interrupt";let xe;const Pe=b.value;if(Pe&&typeof Pe=="object"&&!Array.isArray(Pe)){const Ze=Pe.title;typeof Ze=="string"&&Ze.trim()&&(xe=Ze.trim())}return{id:`interrupt-${re}`,role:"system",createdAt:new Date().toISOString(),content:[{type:"interrupt",id:re,value:Pe,title:xe}]}},[b,se]),Ee=w.useMemo(()=>ge?[...e,ge]:e,[e,ge]),Y=w.useMemo(()=>!N||!t?Ee:!Ee.some(xe=>xe.role==="assistant")&&Ee.length>0?[...Ee,{id:"thinking-assistant",role:"assistant",content:[],createdAt:new Date().toISOString()}]:Ee,[Ee,t,N]),U=w.useMemo(()=>T?Y:Y.filter(re=>(re==null?void 0:re.role)!=="tool"),[Y,T]),Z=w.useCallback(re=>{J(re),y&&y(!re),g&&g(re)},[y,g]),$=w.useMemo(()=>{if(a)return async()=>{if(!z.current){z.current=!0;try{await a()}finally{z.current=!1}}}},[a]),K=w.useMemo(()=>!x||m?!1:q?"auto":!1,[q,x,m]),Q=w.useMemo(()=>{if(typeof h!="string")return null;const re=h.trim();return re?{id:"default-message",role:"assistant",type:"default_message",content:re,createdAt:new Date().toISOString()}:null},[h]),ce=["flex h-full flex-col md:flex-row",f].filter(Boolean).join(" "),oe=()=>Q?u.jsx("div",{className:"p-6 h-full overflow-y-auto",children:u.jsx("div",{className:"w-full max-w-full",children:u.jsx(Ds,{message:Q,messageIndex:0,isStreamingMessage:!1,showActions:!1,showTimestamp:!1,showAgentName:!0,layoutSize:o,onEdit:()=>{},onRegenerate:()=>{},onCancelEdit:()=>{},showArtifactPreviews:I})})}):u.jsx("div",{className:"flex h-full items-center justify-center py-8 text-center text-muted-foreground",children:h??"No messages yet. Start a conversation!"}),Ne=U.length,Ue=Ne>0;return w.useEffect(()=>{var re,xe;if(Ne===0){M.current=!1;return}M.current||(M.current=!0,j.current?(xe=(re=j.current).scrollToIndex)==null||xe.call(re,{index:0,align:"start",behavior:"auto"}):V.current&&(V.current.scrollTop=0))},[Ne]),w.useImperativeHandle(B,()=>({scrollToLatest:()=>{var re,xe;if(j.current&&U.length>0){const Pe=U.length-1;(xe=(re=j.current).scrollToIndex)==null||xe.call(re,{index:Pe,align:"end",behavior:"auto"})}else V.current&&(V.current.scrollTop=V.current.scrollHeight)},scrollToTop:()=>{var re,xe;j.current&&U.length>0?(xe=(re=j.current).scrollToIndex)==null||xe.call(re,{index:0,align:"start",behavior:"auto"}):V.current&&(V.current.scrollTop=0)}}),[U]),u.jsx("div",{className:ce,style:p,children:u.jsx("div",{className:"relative flex-1 min-h-0",children:Ue?u.jsx(E0,{ref:re=>{j.current=re},scrollerRef:re=>{V.current=re instanceof HTMLDivElement?re:null},data:U,followOutput:K,overscan:200,increaseViewportBy:{top:100,bottom:200},defaultItemHeight:80,atBottomThreshold:50,startReached:()=>{$&&$()},atBottomStateChange:Z,style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:(re,xe)=>up(xe,re),itemContent:(re,xe)=>u.jsx(dp,{message:xe,index:re,isStreaming:t,streamingAssistantId:n,streamingDebounceMs:r,layoutSize:o,enableMessageEditing:s,editingMessageId:i,onEdit:l,onRegenerate:c,onCancelEdit:d,activeInterrupt:b,disableInterruptActions:S,onInterruptActionStart:k,onInterruptActionEnd:C,showToolMessages:T,showArtifactPreviews:I,checkpointMetaById:A,checkpointIndexByKey:R,attemptMetaById:L,userMessageIdToAttempts:P,activeCheckpointId:D,onSelectCheckpoint:F})}):oe()})})});ja.displayName="MessageList";const fp={value:""};function Ls({className:e="",placeholder:t="Type your message...",autoFocus:n=!0,maxHeight:r=void 0,streamingDebounceMs:o=500,streamingThrottleMs:s,followNewMessages:i=!0,enableFileUpload:a=!0,enableExcelUpload:l=!1,enableMessageEditing:c=!0,showToolMessages:d=!0,showArtifactPreviews:f=!0,customStyles:p={},onMessageSent:h,onExcelUploadSuccess:x,onError:m}){const{api:y}=ui(),{currentThreadId:g}=_o(),{threadId:b,messages:S,isHistoryLoading:k,isLoading:C,navigateToCheckpoint:T,returnToLatest:I,checkpoint:A,checkpoints:R,interrupt:L,metadata:P,timelineCheckpoints:D,messagePreviews:F}=jo(),{isStreaming:N,error:B,connectionState:j,submit:V,stop:z}=ac(),M=b??g??null,q=(A==null?void 0:A.id)??null,J=(A==null?void 0:A.namespace)??null,se=(P==null?void 0:P.assemblingMessageId)??null,ge=L,[Ee,Y]=w.useState(!1);w.useEffect(()=>{ge||Y(!1)},[ge]);const U=w.useCallback(()=>{Y(!0)},[]),Z=w.useCallback(()=>{Y(!1)},[]),$=!!ge||Ee,[K,Q]=w.useState(null),[ce,oe]=w.useState(""),[Ne,Ue]=w.useState(null),[re,xe]=w.useState(null),[Pe,Ze]=w.useState([]),[Qe,Ve]=w.useState(0),[tt,it]=w.useState(0),[qe,nt]=w.useState(!1),[at,Rt]=w.useState(null),[gt,ht]=w.useState(null),[bt,St]=w.useState(!1),[Lt,Mt]=w.useState(null),et=w.useRef(!1),[It,bn]=w.useState(()=>fp.value),Ge=w.useRef(It),Ye=w.useRef(null),pt=w.useCallback(fe=>{fp.value=fe,bn(fe)},[]),[lt,G]=w.useState(!1),_=w.useRef(null),{checkpointMetaById:X,checkpointIndexByKey:te,attemptMetaById:pe,userMessageIdToAttempts:ve}=hw(R),we=D??[],Fe=w.useRef(null),Oe=w.useRef(null),je=w.useCallback(()=>{Fe.current&&(Fe.current.value=""),Oe.current&&(Oe.current.value=""),Ve(fe=>fe+1),it(fe=>fe+1)},[]),Vt=w.useCallback(fe=>{pt(fe)},[pt]),En=w.useRef(!1);w.useEffect(()=>{En.current&&!N&&(Ze([]),je()),En.current=N},[N,je]);const[ir,Ar]=w.useState("desktop");w.useEffect(()=>{const fe=()=>{const Se=window.innerWidth;Ar(Se<640?"phone":Se<1024?"tablet":"desktop")};return fe(),window.addEventListener("resize",fe),()=>window.removeEventListener("resize",fe)},[]),w.useEffect(()=>{et.current=!1},[M]),w.useEffect(()=>{Ge.current=It},[It]),w.useEffect(()=>{if(!K){Ye.current=null;return}Ye.current===null&&(Ye.current=Ge.current),pt(ce??"")},[ce,K,pt]),w.useEffect(()=>{(async()=>{if(!y.baseUrl){Mt(null);return}try{const Ie=(await y.getAgent("default")).uiDefaultMessage||"";Mt(Ie||null)}catch(Se){console.warn("Failed to fetch default message:",Se),Mt(null)}})()},[y.baseUrl]),w.useEffect(()=>{B&&!bt&&(m==null||m(B))},[B,bt,m]);const fo=fe=>{if(fe.length>cs)return`Message too long (${fe.length}/${cs} characters)`;try{return xw(fe),null}catch(Se){return(Se==null?void 0:Se.message)||"Invalid message"}},zn=async fe=>{const Se=fe.trim();if(!(!Se&&Pe.length===0)){if(Se){const Ie=fo(Se);if(Ie){xe(Ie);return}}try{const Ie=K?(Ne==null?void 0:Ne.checkpointId)??q??void 0:q??void 0,He=K?(Ne==null?void 0:Ne.checkpointNs)??J??void 0:J??void 0;await V({text:Se||"",attachments:Pe},{checkpointId:Ie,checkpointNs:He,edit:!!K,originalMessageId:K??void 0}),h==null||h(Se),pt(""),xe(null),Ze([]),je(),Q(null),oe(""),Ue(null)}catch(Ie){const He=(Ie==null?void 0:Ie.message)||"Failed to send message";xe(He),m==null||m(He)}}},ar=w.useCallback((fe,Se,Ie)=>{c&&(Ye.current=It,Q(fe),oe(Se),pt(Se),xe(null),Ue({checkpointId:(Ie==null?void 0:Ie.checkpointId)??null,checkpointNs:(Ie==null?void 0:Ie.checkpointNs)??null}))},[It,c,pt]),E=w.useCallback(()=>{Q(null),oe(""),Ue(null),xe(null),pt(Ye.current??It),Ye.current=null},[It,pt]),W=w.useCallback((fe,Se,Ie)=>{ar(fe,Se,Ie)},[ar]),ie=w.useCallback(fe=>{let Se=null;for(let tn=fe-1;tn>=0;tn--)if(S[tn].role==="user"){Se=S[tn];break}if(!Se)return;const Ie=Array.isArray(Se.content)?Se.content:[],Un=Ie.filter(tn=>(tn==null?void 0:tn.type)==="text").map(tn=>tn.text).join("")||(()=>{try{return JSON.stringify(Ie,null,2)}catch{return String(Ie)}})();Un&&V({text:Un},{checkpointId:q??void 0,checkpointNs:J??void 0,edit:!0,originalMessageId:Se.id})},[S,V,q,J]),be=fe=>{const Se=Array.from(fe.target.files||[]);Ze(Ie=>[...Ie,...Se]),fe.target.value=""},Ke=fe=>{Ze(Se=>{const Ie=Se.filter((He,Un)=>fe!==Un);return Ie.length===0&&je(),Ie})},rt=async fe=>{const Se=(fe.target.files||[])[0];if(Se){Rt(null),ht(null),nt(!0);try{await V({attachments:[Se]},{checkpointId:q??void 0,checkpointNs:J??void 0});const Ie=`Uploaded ${Se.name} - processing through chat stream`;ht(Ie)}catch(Ie){const He=Ie instanceof Error?Ie.message:"Failed to upload Excel file";console.error("Excel upload failed",Ie),Rt(He),m==null||m(He)}finally{nt(!1),fe.target.value="",je()}}},$e=async fe=>{if(g){G(!0);try{if(!fe){await I(),requestAnimationFrame(()=>{var He;(He=_.current)==null||He.scrollToLatest()});return}const Se=R.find(He=>He.checkpointId===fe),Ie=(Se==null?void 0:Se.checkpointNs)??null;await T(fe,Ie),requestAnimationFrame(()=>{var He;(He=_.current)==null||He.scrollToTop()})}finally{G(!1)}}},Le=w.useCallback(async(fe,Se,Ie)=>{await $e(Ie?null:fe)},[$e]),Et=`flex flex-1 w-full flex-col min-h-0 min-w-0 max-h-full overflow-hidden bg-transparent ${e} ${p.container||""}`,mt=`flex-1 min-h-0 min-w-0 max-h-full w-full overflow-hidden overscroll-contain break-words break-anywhere p-4 bg-transparent ${p.messagesArea||""}`,xt=`relative flex-shrink-0 w-full border-t p-4 bg-transparent ${p.inputArea||""}`;return u.jsxs("div",{className:Et,children:[!!B&&!bt&&u.jsxs("div",{className:"flex-shrink-0 bg-red-50 border border-red-200 text-red-800 px-4 py-2 text-sm flex items-center justify-between",children:[u.jsx("span",{children:B}),u.jsx(Xe,{variant:"ghost",size:"sm",onClick:()=>St(!0),className:"text-red-800 hover:bg-red-100","aria-label":"Dismiss error",children:u.jsx(ae.X,{size:16})})]}),u.jsxs("div",{className:`relative ${mt}`,style:r?{maxHeight:r}:void 0,children:[u.jsx(ja,{ref:_,className:"h-full",style:{height:"100%"},messages:S,isStreaming:N,streamingAssistantId:se,streamingDebounceMs:typeof s=="number"?s:o,followNewMessages:i,layoutSize:ir,enableMessageEditing:c,editingMessageId:K,onEdit:W,onRegenerate:ie,onCancelEdit:E,emptyMessage:Lt??void 0,isNavigatingCheckpoint:lt,activeInterrupt:ge,disableInterruptActions:Ee,onInterruptActionStart:U,onInterruptActionEnd:Z,showToolMessages:d,showArtifactPreviews:f,checkpointMetaById:X,checkpointIndexByKey:te,attemptMetaById:pe,userMessageIdToAttempts:ve,activeCheckpointId:q,onSelectCheckpoint:Le,timelineCheckpoints:we,messagePreviews:F}),(j==="reconnecting"||j==="connecting")&&u.jsx("div",{className:"pointer-events-none absolute top-3 right-3 z-20 rounded-full bg-muted/80 px-3 py-1 text-xs font-medium text-foreground shadow-sm backdrop-blur-sm dark:bg-muted/60",children:u.jsxs("span",{className:"flex items-center gap-2",children:[u.jsx(ae.Loader2,{className:"h-3 w-3 animate-spin"}),j==="reconnecting"?"Reconnecting…":"Connecting…"]})}),j==="error"&&u.jsx("div",{className:"pointer-events-none absolute top-3 right-3 z-20 rounded-full bg-destructive/10 px-3 py-1 text-xs font-semibold text-destructive shadow-sm",children:"Connection lost"}),C&&u.jsxs("div",{className:"absolute inset-0 z-10 flex flex-col items-center justify-center gap-2 bg-background/80 backdrop-blur-sm text-muted-foreground",children:[u.jsx(ae.Loader2,{className:"h-6 w-6 animate-spin"}),u.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:"Loading messages…"})]}),(k||lt)&&u.jsxs("div",{className:"absolute inset-0 z-10 flex flex-col items-center justify-center gap-2 bg-background/80 backdrop-blur-sm text-muted-foreground",children:[u.jsx(ae.Loader2,{className:"h-6 w-6 animate-spin"}),u.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:"Loading checkpoint…"})]})]}),u.jsxs("div",{className:xt,children:[K&&u.jsx("div",{className:"mb-3 p-3 bg-blue-50 border border-blue-200 rounded-lg",children:u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx(ae.Edit3,{size:16,className:"text-blue-600"}),u.jsx("span",{className:"text-sm font-medium text-blue-800",children:"Editing message"})]}),u.jsx(Xe,{variant:"ghost",size:"sm",onClick:E,className:"text-blue-600 hover:bg-blue-100",children:u.jsx(ae.X,{size:16})})]})}),(a||l)&&u.jsxs("div",{className:"mb-3 space-y-3",children:[a&&u.jsxs(u.Fragment,{children:[u.jsx("input",{ref:Fe,type:"file",multiple:!0,onChange:fe=>be(fe),className:"hidden"},Qe),Pe.length>0&&u.jsx("div",{className:"flex flex-wrap gap-2",children:Pe.map((fe,Se)=>u.jsxs("div",{className:"flex items-center gap-2 bg-gray-100 dark:bg-gray-800 rounded-lg px-3 py-2 text-sm text-gray-900 dark:text-gray-100",children:[u.jsx(ae.Paperclip,{size:14}),u.jsx("span",{className:"truncate max-w-[150px]",children:fe.name}),u.jsx(Xe,{variant:"ghost",size:"sm",onClick:()=>Ke(Se),className:"h-4 w-4 p-0 text-gray-500 dark:text-gray-400 hover:text-red-500 dark:hover:text-red-400","aria-label":`Remove ${fe.name}`,children:u.jsx(ae.X,{size:12})})]},Se))})]}),l&&u.jsxs(u.Fragment,{children:[u.jsx("input",{ref:Oe,type:"file",accept:".xls,.xlsx,.xlsm",onChange:rt,className:"hidden"},tt),qe&&u.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[u.jsx(ae.Loader2,{className:"h-4 w-4 animate-spin"})," Uploading Excel file..."]}),gt&&!qe&&u.jsx("div",{className:"text-sm rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-emerald-700",children:gt}),at&&!qe&&u.jsx("div",{className:"text-sm rounded border border-red-200 bg-red-50 px-3 py-2 text-red-600",children:at})]})]}),re&&u.jsx("div",{className:"mb-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2",children:re}),u.jsxs("div",{className:"flex items-end gap-2",children:[(a||l)&&u.jsxs(ew,{children:[u.jsx(tw,{asChild:!0,children:u.jsx(Xe,{type:"button",size:"icon",variant:"outline",disabled:N||$,title:"More input actions",className:p.moreButton||"",children:u.jsx(ae.Plus,{size:16})})}),u.jsxs(yd,{align:"start",sideOffset:6,className:"w-52",children:[a&&u.jsxs(Zi,{onClick:()=>{var fe;return(fe=Fe.current)==null?void 0:fe.click()},className:"cursor-pointer",children:[u.jsx(ae.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]}),l&&u.jsxs(Zi,{onClick:()=>{var fe;qe||(fe=Oe.current)==null||fe.click()},className:`cursor-pointer ${qe?"opacity-60 pointer-events-none":""}`,children:[u.jsx(ae.FileSpreadsheet,{className:"h-4 w-4 mr-2"})," Upload Excel file"]})]})]}),u.jsx("div",{className:"flex-1",children:u.jsx(tx,{initialValue:ce,editingMessageId:K,value:It,onValueChange:Vt,placeholder:K?"Edit your message...":t,isStreaming:N,disabled:$,maxLength:cs,onSend:zn,onCancelEdit:E,onStop:z,allowEmptySend:Pe.length>0,textareaClassName:`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${K?"border-blue-400 bg-blue-50 text-blue-900 dark:border-blue-500 dark:bg-blue-950/60 dark:text-blue-50":""} ${re?"border-red-400":""} ${p.textarea||""}`})})]})]})]})}const $s=v.forwardRef(({className:e,type:t,...n},r)=>u.jsx("input",{type:t,className:ne("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 Ra(e,[t,n]){return Math.min(n,Math.max(t,e))}function YS(e,t){return v.useReducer((n,r)=>t[n][r]??n,e)}var Ma="ScrollArea",[pp,FT]=Sn(Ma),[XS,Qt]=pp(Ma),hp=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,type:r="hover",dir:o,scrollHideDelay:s=600,...i}=e,[a,l]=v.useState(null),[c,d]=v.useState(null),[f,p]=v.useState(null),[h,x]=v.useState(null),[m,y]=v.useState(null),[g,b]=v.useState(0),[S,k]=v.useState(0),[C,T]=v.useState(!1),[I,A]=v.useState(!1),R=Be(t,P=>l(P)),L=Mo(o);return u.jsx(XS,{scope:n,type:r,dir:L,scrollHideDelay:s,scrollArea:a,viewport:c,onViewportChange:d,content:f,onContentChange:p,scrollbarX:h,onScrollbarXChange:x,scrollbarXEnabled:C,onScrollbarXEnabledChange:T,scrollbarY:m,onScrollbarYChange:y,scrollbarYEnabled:I,onScrollbarYEnabledChange:A,onCornerWidthChange:b,onCornerHeightChange:k,children:u.jsx(_e.div,{dir:L,...i,ref:R,style:{position:"relative","--radix-scroll-area-corner-width":g+"px","--radix-scroll-area-corner-height":S+"px",...e.style}})})});hp.displayName=Ma;var mp="ScrollAreaViewport",gp=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,i=Qt(mp,n),a=v.useRef(null),l=Be(t,a,i.onViewportChange);return u.jsxs(u.Fragment,{children:[u.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-scroll-area-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-scroll-area-viewport]::-webkit-scrollbar{display:none}"},nonce:o}),u.jsx(_e.div,{"data-radix-scroll-area-viewport":"",...s,ref:l,style:{overflowX:i.scrollbarXEnabled?"scroll":"hidden",overflowY:i.scrollbarYEnabled?"scroll":"hidden",...e.style},children:u.jsx("div",{ref:i.onContentChange,style:{minWidth:"100%",display:"table"},children:r})})]})});gp.displayName=mp;var vn="ScrollAreaScrollbar",Pa=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Qt(vn,e.__scopeScrollArea),{onScrollbarXEnabledChange:s,onScrollbarYEnabledChange:i}=o,a=e.orientation==="horizontal";return v.useEffect(()=>(a?s(!0):i(!0),()=>{a?s(!1):i(!1)}),[a,s,i]),o.type==="hover"?u.jsx(JS,{...r,ref:t,forceMount:n}):o.type==="scroll"?u.jsx(ZS,{...r,ref:t,forceMount:n}):o.type==="auto"?u.jsx(xp,{...r,ref:t,forceMount:n}):o.type==="always"?u.jsx(Oa,{...r,ref:t}):null});Pa.displayName=vn;var JS=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Qt(vn,e.__scopeScrollArea),[s,i]=v.useState(!1);return v.useEffect(()=>{const a=o.scrollArea;let l=0;if(a){const c=()=>{window.clearTimeout(l),i(!0)},d=()=>{l=window.setTimeout(()=>i(!1),o.scrollHideDelay)};return a.addEventListener("pointerenter",c),a.addEventListener("pointerleave",d),()=>{window.clearTimeout(l),a.removeEventListener("pointerenter",c),a.removeEventListener("pointerleave",d)}}},[o.scrollArea,o.scrollHideDelay]),u.jsx(Yt,{present:n||s,children:u.jsx(xp,{"data-state":s?"visible":"hidden",...r,ref:t})})}),ZS=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Qt(vn,e.__scopeScrollArea),s=e.orientation==="horizontal",i=Us(()=>l("SCROLL_END"),100),[a,l]=YS("hidden",{hidden:{SCROLL:"scrolling"},scrolling:{SCROLL_END:"idle",POINTER_ENTER:"interacting"},interacting:{SCROLL:"interacting",POINTER_LEAVE:"idle"},idle:{HIDE:"hidden",SCROLL:"scrolling",POINTER_ENTER:"interacting"}});return v.useEffect(()=>{if(a==="idle"){const c=window.setTimeout(()=>l("HIDE"),o.scrollHideDelay);return()=>window.clearTimeout(c)}},[a,o.scrollHideDelay,l]),v.useEffect(()=>{const c=o.viewport,d=s?"scrollLeft":"scrollTop";if(c){let f=c[d];const p=()=>{const h=c[d];f!==h&&(l("SCROLL"),i()),f=h};return c.addEventListener("scroll",p),()=>c.removeEventListener("scroll",p)}},[o.viewport,s,l,i]),u.jsx(Yt,{present:n||a!=="hidden",children:u.jsx(Oa,{"data-state":a==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:de(e.onPointerEnter,()=>l("POINTER_ENTER")),onPointerLeave:de(e.onPointerLeave,()=>l("POINTER_LEAVE"))})})}),xp=v.forwardRef((e,t)=>{const n=Qt(vn,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,i]=v.useState(!1),a=e.orientation==="horizontal",l=Us(()=>{if(n.viewport){const c=n.viewport.offsetWidth<n.viewport.scrollWidth,d=n.viewport.offsetHeight<n.viewport.scrollHeight;i(a?c:d)}},10);return kr(n.viewport,l),kr(n.content,l),u.jsx(Yt,{present:r||s,children:u.jsx(Oa,{"data-state":s?"visible":"hidden",...o,ref:t})})}),Oa=v.forwardRef((e,t)=>{const{orientation:n="vertical",...r}=e,o=Qt(vn,e.__scopeScrollArea),s=v.useRef(null),i=v.useRef(0),[a,l]=v.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),c=Sp(a.viewport,a.content),d={...r,sizes:a,onSizesChange:l,hasThumb:c>0&&c<1,onThumbChange:p=>s.current=p,onThumbPointerUp:()=>i.current=0,onThumbPointerDown:p=>i.current=p};function f(p,h){return oC(p,i.current,a,h)}return n==="horizontal"?u.jsx(QS,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const p=o.viewport.scrollLeft,h=Cp(p,a,o.dir);s.current.style.transform=`translate3d(${h}px, 0, 0)`}},onWheelScroll:p=>{o.viewport&&(o.viewport.scrollLeft=p)},onDragScroll:p=>{o.viewport&&(o.viewport.scrollLeft=f(p,o.dir))}}):n==="vertical"?u.jsx(eC,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const p=o.viewport.scrollTop,h=Cp(p,a);s.current.style.transform=`translate3d(0, ${h}px, 0)`}},onWheelScroll:p=>{o.viewport&&(o.viewport.scrollTop=p)},onDragScroll:p=>{o.viewport&&(o.viewport.scrollTop=f(p))}}):null}),QS=v.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=Qt(vn,e.__scopeScrollArea),[i,a]=v.useState(),l=v.useRef(null),c=Be(t,l,s.onScrollbarXChange);return v.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(vp,{"data-orientation":"horizontal",...o,ref:c,sizes:n,style:{bottom:0,left:s.dir==="rtl"?"var(--radix-scroll-area-corner-width)":0,right:s.dir==="ltr"?"var(--radix-scroll-area-corner-width)":0,"--radix-scroll-area-thumb-width":zs(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.x),onDragScroll:d=>e.onDragScroll(d.x),onWheelScroll:(d,f)=>{if(s.viewport){const p=s.viewport.scrollLeft+d.deltaX;e.onWheelScroll(p),kp(p,f)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollWidth,viewport:s.viewport.offsetWidth,scrollbar:{size:l.current.clientWidth,paddingStart:Bs(i.paddingLeft),paddingEnd:Bs(i.paddingRight)}})}})}),eC=v.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=Qt(vn,e.__scopeScrollArea),[i,a]=v.useState(),l=v.useRef(null),c=Be(t,l,s.onScrollbarYChange);return v.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(vp,{"data-orientation":"vertical",...o,ref:c,sizes:n,style:{top:0,right:s.dir==="ltr"?0:void 0,left:s.dir==="rtl"?0:void 0,bottom:"var(--radix-scroll-area-corner-height)","--radix-scroll-area-thumb-height":zs(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.y),onDragScroll:d=>e.onDragScroll(d.y),onWheelScroll:(d,f)=>{if(s.viewport){const p=s.viewport.scrollTop+d.deltaY;e.onWheelScroll(p),kp(p,f)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollHeight,viewport:s.viewport.offsetHeight,scrollbar:{size:l.current.clientHeight,paddingStart:Bs(i.paddingTop),paddingEnd:Bs(i.paddingBottom)}})}})}),[tC,yp]=pp(vn),vp=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,sizes:r,hasThumb:o,onThumbChange:s,onThumbPointerUp:i,onThumbPointerDown:a,onThumbPositionChange:l,onDragScroll:c,onWheelScroll:d,onResize:f,...p}=e,h=Qt(vn,n),[x,m]=v.useState(null),y=Be(t,R=>m(R)),g=v.useRef(null),b=v.useRef(""),S=h.viewport,k=r.content-r.viewport,C=kt(d),T=kt(l),I=Us(f,10);function A(R){if(g.current){const L=R.clientX-g.current.left,P=R.clientY-g.current.top;c({x:L,y:P})}}return v.useEffect(()=>{const R=L=>{const P=L.target;(x==null?void 0:x.contains(P))&&C(L,k)};return document.addEventListener("wheel",R,{passive:!1}),()=>document.removeEventListener("wheel",R,{passive:!1})},[S,x,k,C]),v.useEffect(T,[r,T]),kr(x,I),kr(h.content,I),u.jsx(tC,{scope:n,scrollbar:x,hasThumb:o,onThumbChange:kt(s),onThumbPointerUp:kt(i),onThumbPositionChange:T,onThumbPointerDown:kt(a),children:u.jsx(_e.div,{...p,ref:y,style:{position:"absolute",...p.style},onPointerDown:de(e.onPointerDown,R=>{R.button===0&&(R.target.setPointerCapture(R.pointerId),g.current=x.getBoundingClientRect(),b.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",h.viewport&&(h.viewport.style.scrollBehavior="auto"),A(R))}),onPointerMove:de(e.onPointerMove,A),onPointerUp:de(e.onPointerUp,R=>{const L=R.target;L.hasPointerCapture(R.pointerId)&&L.releasePointerCapture(R.pointerId),document.body.style.webkitUserSelect=b.current,h.viewport&&(h.viewport.style.scrollBehavior=""),g.current=null})})})}),Fs="ScrollAreaThumb",bp=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=yp(Fs,e.__scopeScrollArea);return u.jsx(Yt,{present:n||o.hasThumb,children:u.jsx(nC,{ref:t,...r})})}),nC=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=Qt(Fs,n),i=yp(Fs,n),{onThumbPositionChange:a}=i,l=Be(t,f=>i.onThumbChange(f)),c=v.useRef(void 0),d=Us(()=>{c.current&&(c.current(),c.current=void 0)},100);return v.useEffect(()=>{const f=s.viewport;if(f){const p=()=>{if(d(),!c.current){const h=sC(f,a);c.current=h,a()}};return a(),f.addEventListener("scroll",p),()=>f.removeEventListener("scroll",p)}},[s.viewport,d,a]),u.jsx(_e.div,{"data-state":i.hasThumb?"visible":"hidden",...o,ref:l,style:{width:"var(--radix-scroll-area-thumb-width)",height:"var(--radix-scroll-area-thumb-height)",...r},onPointerDownCapture:de(e.onPointerDownCapture,f=>{const h=f.target.getBoundingClientRect(),x=f.clientX-h.left,m=f.clientY-h.top;i.onThumbPointerDown({x,y:m})}),onPointerUp:de(e.onPointerUp,i.onThumbPointerUp)})});bp.displayName=Fs;var Da="ScrollAreaCorner",wp=v.forwardRef((e,t)=>{const n=Qt(Da,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?u.jsx(rC,{...e,ref:t}):null});wp.displayName=Da;var rC=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=Qt(Da,n),[s,i]=v.useState(0),[a,l]=v.useState(0),c=!!(s&&a);return kr(o.scrollbarX,()=>{var f;const d=((f=o.scrollbarX)==null?void 0:f.offsetHeight)||0;o.onCornerHeightChange(d),l(d)}),kr(o.scrollbarY,()=>{var f;const d=((f=o.scrollbarY)==null?void 0:f.offsetWidth)||0;o.onCornerWidthChange(d),i(d)}),c?u.jsx(_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 Bs(e){return e?parseInt(e,10):0}function Sp(e,t){const n=e/t;return isNaN(n)?0:n}function zs(e){const t=Sp(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function oC(e,t,n,r="ltr"){const o=zs(n),s=o/2,i=t||s,a=o-i,l=n.scrollbar.paddingStart+i,c=n.scrollbar.size-n.scrollbar.paddingEnd-a,d=n.content-n.viewport,f=r==="ltr"?[0,d]:[d*-1,0];return Tp([l,c],f)(e)}function Cp(e,t,n="ltr"){const r=zs(t),o=t.scrollbar.paddingStart+t.scrollbar.paddingEnd,s=t.scrollbar.size-o,i=t.content-t.viewport,a=s-r,l=n==="ltr"?[0,i]:[i*-1,0],c=Ra(e,l);return Tp([0,i],[0,a])(c)}function Tp(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 kp(e,t){return e>0&&e<t}var sC=(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=kt(e),r=v.useRef(0);return v.useEffect(()=>()=>window.clearTimeout(r.current),[]),v.useCallback(()=>{window.clearTimeout(r.current),r.current=window.setTimeout(n,t)},[n,t])}function kr(e,t){const n=kt(t);Tt(()=>{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 Ip=hp,iC=gp,aC=wp;const Ep=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Ip,{ref:r,className:ne("relative overflow-hidden",e),...n,children:[u.jsx(iC,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),u.jsx(Ap,{}),u.jsx(aC,{})]}));Ep.displayName=Ip.displayName;const Ap=v.forwardRef(({className:e,orientation:t="vertical",...n},r)=>u.jsx(Pa,{ref:r,orientation:t,className:ne("flex touch-none select-none transition-colors",t==="vertical"&&"h-full w-2.5 border-l border-l-transparent p-[1px]",t==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent p-[1px]",e),...n,children:u.jsx(bp,{className:"relative flex-1 rounded-full bg-border"})}));Ap.displayName=Pa.displayName;const Np=25;function La({className:e="",showCreateButton:t=!0,showDeleteButton:n=!0,showEditTitle:r=!0,maxHeight:o="400px",customStyles:s={},currentThreadId:i=null,navigateToThread:a,onThreadSelect:l,onThreadCreate:c,onThreadDelete:d}){const{threads:f,currentThreadId:p,setCurrentThreadId:h,isLoading:x,actions:m}=_o(),{loadThread:y}=jo(),{createThread:g,deleteThread:b,renameThread:S}=m,[k,C]=w.useState(Array.isArray(f)?f:[]),T=w.useRef(k.length>0),I=w.useRef(null),A=w.useRef(0),[R,L]=w.useState(null),[P,D]=w.useState(""),[F,N]=w.useState(!1);w.useEffect(()=>{const Y=Array.isArray(f)?f:[];if(Y.length>0){T.current=!0,C(Y);return}x||(T.current=!1,C(Y))},[f,x]),w.useEffect(()=>{if(!I.current)return;const Y=I.current.querySelector("[data-radix-scroll-area-viewport]");if(!Y)return;let U=null,Z=null;return U=requestAnimationFrame(()=>{Z=requestAnimationFrame(()=>{Y.scrollTop=A.current})}),()=>{U!==null&&cancelAnimationFrame(U),Z!==null&&cancelAnimationFrame(Z)}},[k]);const B=async Y=>{try{h(Y),await y(Y),a==null||a(Y),l==null||l(Y)}catch(U){console.error("Failed to select thread:",U)}},j=async()=>{try{N(!0);const Y=await g();Y&&(c==null||c(Y),a==null||a(Y))}catch(Y){console.error("Failed to create thread:",Y)}finally{N(!1)}},V=async(Y,U)=>{if(U.stopPropagation(),!!confirm("Delete this thread?")){if(I.current){const Z=I.current.querySelector("[data-radix-scroll-area-viewport]");Z&&(A.current=Z.scrollTop)}try{await b(Y),d==null||d(Y)}catch(Z){console.error("Failed to delete thread:",Z)}}},z=(Y,U)=>{U.stopPropagation(),L(Y.threadId),D(Y.title||`Thread ${Y.threadId.slice(0,8)}`)},M=async Y=>{if(P.trim())try{await S(Y,P.trim()),L(null),D("")}catch(U){console.error("Failed to update title:",U)}},q=()=>{L(null),D("")},J=(Y,U)=>{Y.key==="Enter"?M(U):Y.key==="Escape"&&q()},se=Y=>{if(!Y)return"";try{const U=new Date(Y),$=new Date().getTime()-U.getTime(),K=Math.floor($/(1e3*60*60*24));return K===0?U.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):K===1?"Yesterday":K<7?`${K} days ago`:U.toLocaleDateString()}catch{return""}},ge=Y=>Y.title||`Thread ${Y.threadId.slice(0,8)}`,Ee=Y=>{const U=ge(Y);return U.length<=Np?U:`${U.slice(0,Np)}...`};return u.jsxs("div",{className:`flex flex-col h-full ${e} ${s.container||""}`,children:[t&&u.jsx("div",{className:s.header||"flex-shrink-0 p-2 border-b bg-slate-800 border-slate-700 text-slate-100 flex justify-end",children:u.jsx(Xe,{onClick:j,disabled:F||x,className:s.createButton||"p-2",size:"sm",variant:"ghost",title:F?"Creating...":"New Chat",children:u.jsx(ae.MessageSquarePlus,{size:20})})}),u.jsx(Ep,{ref:I,className:`flex-1 min-h-0 ${s.threadList||""}`,style:o?{maxHeight:o}:void 0,children:u.jsx("div",{className:"p-2 space-y-1 pb-4",children:x?u.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 py-8 text-slate-400",children:[u.jsx(ae.Loader2,{className:"h-5 w-5 animate-spin"}),u.jsx("span",{className:"text-sm",children:"Loading threads…"})]}):k.length===0?u.jsxs("div",{className:"text-center py-8 text-slate-400",children:[u.jsx(ae.MessageSquare,{className:"w-8 h-8 mx-auto mb-2 opacity-40 text-slate-500"}),u.jsx("p",{className:"text-sm text-slate-500",children:"No conversations yet"})]}):k.slice().sort((Y,U)=>new Date(U.updatedAt||U.createdAt||"").getTime()-new Date(Y.updatedAt||Y.createdAt||"").getTime()).map(Y=>u.jsxs("div",{onClick:()=>B(Y.threadId),className:`group relative p-3 rounded-lg cursor-pointer transition-colors border ${(i??p)===Y.threadId?`${s.activeThread||"bg-slate-600 border-slate-500"} `:`${s.threadItem||"bg-slate-700 border-slate-600 hover:bg-slate-600 text-gray-900 dark:text-slate-100"}`} ${s.threadItem||""} text-gray-900 dark:text-slate-100`,children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx("div",{className:"flex-1 min-w-0",children:R===Y.threadId?u.jsxs("div",{className:"flex items-center gap-2",onClick:U=>U.stopPropagation(),children:[u.jsx($s,{value:P,onChange:U=>D(U.target.value),onKeyDown:U=>J(U,Y.threadId),className:"h-6 text-sm",autoFocus:!0}),u.jsx(Xe,{variant:"ghost",size:"sm",onClick:()=>M(Y.threadId),className:"h-6 w-6 p-0",children:u.jsx(ae.Check,{size:12})}),u.jsx(Xe,{variant:"ghost",size:"sm",onClick:q,className:"h-6 w-6 p-0",children:u.jsx(ae.X,{size:12})})]}):u.jsxs(u.Fragment,{children:[u.jsx("div",{className:"font-medium text-sm truncate text-gray-900 dark:text-slate-100",children:Ee(Y)}),u.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500 dark:text-slate-400 mt-1",children:[u.jsx(ae.Calendar,{size:10}),u.jsx("span",{children:se(Y.updatedAt||Y.createdAt)})]})]})}),u.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity ml-2",children:[r&&R!==Y.threadId&&u.jsx(Xe,{variant:"ghost",size:"sm",onClick:U=>z(Y,U),className:"h-6 w-6 p-0",title:"Edit title",children:u.jsx(ae.Edit3,{size:12})}),n&&u.jsx(Xe,{variant:"ghost",size:"sm",onClick:U=>V(Y.threadId,U),className:"h-6 w-6 p-0 text-red-400 hover:text-red-300 hover:bg-red-900/20",title:"Delete thread",children:u.jsx(ae.Trash2,{size:12})})]})]}),i===Y.threadId&&u.jsx("div",{className:"absolute left-0 top-1/2 -translate-y-1/2 w-1 h-8 bg-blue-400 rounded-r"})]},Y.threadId))})})]})}const lC=({timelineEntries:e,activeCheckpointId:t,onSelectCheckpoint:n,messagePreviews:r,className:o})=>{const s=e??[],i=s.length>0,a=w.useMemo(()=>i?[...s].reverse():[],[s,i]),l=t??(s.length?s[s.length-1].id:null);if(!i)return null;const d=["w-32 flex-shrink-0 flex-col border-r border-border/40 pr-2 flex bg-white text-gray-900 dark:bg-slate-900 dark:text-slate-100",o].filter(Boolean).join(" ");return u.jsxs("div",{className:d,children:[u.jsxs("div",{className:"relative flex-1 overflow-y-auto pt-4 pb-2 pr-1",children:[u.jsx("div",{className:"absolute left-0 right-0 top-1 px-2 pb-3 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground",children:u.jsx("span",{children:"Timeline"})}),u.jsx("div",{className:"pointer-events-none absolute left-3 top-0 bottom-0 w-px bg-border/40"}),u.jsx("div",{className:"flex flex-col gap-3 pt-6 pr-2",children:a.map(f=>{const p=l===f.id,h=f.messageId?(r==null?void 0:r.get(f.messageId))??null:null;return u.jsxs("button",{type:"button",disabled:!n,onClick:()=>n==null?void 0:n(f.id),className:`relative flex items-start gap-2 text-left text-[11px] transition ${p?"text-primary":"text-muted-foreground"} ${n?"hover:text-foreground":"cursor-default opacity-70"}`,children:[u.jsx("span",{className:`mt-1 inline-flex h-3 w-3 items-center justify-center rounded-full border ${p?"border-primary bg-primary/10 text-primary":"border-border bg-background"}`,children:u.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${p?"bg-primary":"bg-border"}`})}),u.jsxs("span",{className:"flex-1",children:[u.jsx("span",{className:"block font-medium leading-tight",children:f.label||"User input"}),u.jsxs("span",{className:"text-[9px] uppercase tracking-wide text-muted-foreground/70",children:[f.step!==null?`STEP ${f.step}`:"STEP —",f.next?` - ${f.next}`:""]}),h&&u.jsx("p",{className:"text-[10px] text-muted-foreground/80 mt-1 line-clamp-2",title:h,children:h})]})]},f.id)})})]}),n&&u.jsx("button",{type:"button",onClick:()=>n==null?void 0:n(null),className:"mt-auto mb-3 rounded-md border border-border/70 px-2 py-1 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground transition hover:border-foreground/60 hover:text-foreground",children:"Latest"})]})};function Ir(e){if(!(typeof globalThis>"u"))return globalThis[e]}function cC(e){if(typeof e!="string")return;const t=e.trim();if(t)return wn(t)}function _p(){const e=[Ir("__API_BASE_URL__"),Ir("__CHAT_API_BASE_URL__"),Ir("__CHAT_API_URL__")];for(const t of e){const n=cC(t);if(n)return n}}function jp(){const e=[Ir("__API_AUTH_TOKEN__"),Ir("__CHAT_API_KEY__"),Ir("__CHAT_AUTH_TOKEN__")];for(const t of e)if(typeof t=="string"&&t.trim())return t.trim()}function Rp(...e){for(const t of e)if(typeof t=="string"&&t.trim())return wn(t);return wn()}function Mp(){const e={},t=_p(),n=jp();return t&&(e.baseUrl=t),n&&(e.apiKey=n),e}function Pp(){const e=Mp(),t=An.getAuthToken(),n=_p();return{apiBaseUrl:Rp(e.baseUrl,An.baseUrl,n),apiKey:t||e.apiKey||jp()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,darkMode:!1,enableSound:!1,messageHistory:100}}const Op="chat-settings";function uC(){try{const e=localStorage.getItem(Op);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function dC(e){try{const t={...e,apiBaseUrl:wn(e.apiBaseUrl)};localStorage.setItem(Op,JSON.stringify(t)),t.apiKey&&An.setAuthToken(t.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function fC(){const e=Pp(),t=uC(),n=An.getAuthToken(),r=typeof t.apiBaseUrl=="string"?t.apiBaseUrl:void 0;return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:Rp(An.baseUrl,r,e.apiBaseUrl)}}function pC(e){An.updateConfig({baseUrl:e.apiBaseUrl,authToken:e.apiKey??void 0}),dC(e)}var hC="Label",Dp=v.forwardRef((e,t)=>u.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())}}));Dp.displayName=hC;var Lp=Dp;const mC=po.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),en=v.forwardRef(({className:e,...t},n)=>u.jsx(Lp,{ref:n,className:ne(mC(),e),...t}));en.displayName=Lp.displayName;function $p(e){const t=v.useRef({value:e,previous:e});return v.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}var Fp=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"}),gC="VisuallyHidden",xC=v.forwardRef((e,t)=>u.jsx(_e.span,{...e,ref:t,style:{...Fp,...e.style}}));xC.displayName=gC;var yC=[" ","Enter","ArrowUp","ArrowDown"],vC=[" ","Enter"],rr="Select",[Hs,Ws,bC]=xi(rr),[Er,BT]=Sn(rr,[bC,Ko]),Vs=Ko(),[wC,$n]=Er(rr),[SC,CC]=Er(rr),Bp=e=>{const{__scopeSelect:t,children:n,open:r,defaultOpen:o,onOpenChange:s,value:i,defaultValue:a,onValueChange:l,dir:c,name:d,autoComplete:f,disabled:p,required:h,form:x}=e,m=Vs(t),[y,g]=v.useState(null),[b,S]=v.useState(null),[k,C]=v.useState(!1),T=Mo(c),[I,A]=pr({prop:r,defaultProp:o??!1,onChange:s,caller:rr}),[R,L]=pr({prop:i,defaultProp:a,onChange:l,caller:rr}),P=v.useRef(null),D=y?x||!!y.closest("form"):!0,[F,N]=v.useState(new Set),B=Array.from(F).map(j=>j.props.value).join(";");return u.jsx(tu,{...m,children:u.jsxs(wC,{required:h,scope:t,trigger:y,onTriggerChange:g,valueNode:b,onValueNodeChange:S,valueNodeHasChildren:k,onValueNodeHasChildrenChange:C,contentId:Cn(),value:R,onValueChange:L,open:I,onOpenChange:A,dir:T,triggerPointerDownPosRef:P,disabled:p,children:[u.jsx(Hs.Provider,{scope:t,children:u.jsx(SC,{scope:e.__scopeSelect,onNativeOptionAdd:v.useCallback(j=>{N(V=>new Set(V).add(j))},[]),onNativeOptionRemove:v.useCallback(j=>{N(V=>{const z=new Set(V);return z.delete(j),z})},[]),children:n})}),D?u.jsxs(uh,{"aria-hidden":!0,required:h,tabIndex:-1,name:d,autoComplete:f,value:R,onChange:j=>L(j.target.value),disabled:p,form:x,children:[R===void 0?u.jsx("option",{value:""}):null,Array.from(F)]},B):null]})})};Bp.displayName=rr;var zp="SelectTrigger",Up=v.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...o}=e,s=Vs(n),i=$n(zp,n),a=i.disabled||r,l=Be(t,i.onTriggerChange),c=Ws(n),d=v.useRef("touch"),[f,p,h]=fh(m=>{const y=c().filter(S=>!S.disabled),g=y.find(S=>S.value===i.value),b=ph(y,m,g);b!==void 0&&i.onValueChange(b.value)}),x=m=>{a||(i.onOpenChange(!0),h()),m&&(i.triggerPointerDownPosRef.current={x:Math.round(m.pageX),y:Math.round(m.pageY)})};return u.jsx(nu,{asChild:!0,...s,children:u.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":dh(i.value)?"":void 0,...o,ref:l,onClick:de(o.onClick,m=>{m.currentTarget.focus(),d.current!=="mouse"&&x(m)}),onPointerDown:de(o.onPointerDown,m=>{d.current=m.pointerType;const y=m.target;y.hasPointerCapture(m.pointerId)&&y.releasePointerCapture(m.pointerId),m.button===0&&m.ctrlKey===!1&&m.pointerType==="mouse"&&(x(m),m.preventDefault())}),onKeyDown:de(o.onKeyDown,m=>{const y=f.current!=="";!(m.ctrlKey||m.altKey||m.metaKey)&&m.key.length===1&&p(m.key),!(y&&m.key===" ")&&yC.includes(m.key)&&(x(),m.preventDefault())})})})});Up.displayName=zp;var Hp="SelectValue",Wp=v.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,children:s,placeholder:i="",...a}=e,l=$n(Hp,n),{onValueNodeHasChildrenChange:c}=l,d=s!==void 0,f=Be(t,l.onValueNodeChange);return Tt(()=>{c(d)},[c,d]),u.jsx(_e.span,{...a,ref:f,style:{pointerEvents:"none"},children:dh(l.value)?u.jsx(u.Fragment,{children:i}):s})});Wp.displayName=Hp;var TC="SelectIcon",Vp=v.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...o}=e;return u.jsx(_e.span,{"aria-hidden":!0,...o,ref:t,children:r||"▼"})});Vp.displayName=TC;var kC="SelectPortal",Kp=e=>u.jsx(qo,{asChild:!0,...e});Kp.displayName=kC;var or="SelectContent",qp=v.forwardRef((e,t)=>{const n=$n(or,e.__scopeSelect),[r,o]=v.useState();if(Tt(()=>{o(new DocumentFragment)},[]),!n.open){const s=r;return s?ho.createPortal(u.jsx(Gp,{scope:e.__scopeSelect,children:u.jsx(Hs.Slot,{scope:e.__scopeSelect,children:u.jsx("div",{children:e.children})})}),s):null}return u.jsx(Yp,{...e,ref:t})});qp.displayName=or;var cn=10,[Gp,Fn]=Er(or),IC="SelectContentImpl",EC=Hn.createSlot("SelectContent.RemoveScroll"),Yp=v.forwardRef((e,t)=>{const{__scopeSelect:n,position:r="item-aligned",onCloseAutoFocus:o,onEscapeKeyDown:s,onPointerDownOutside:i,side:a,sideOffset:l,align:c,alignOffset:d,arrowPadding:f,collisionBoundary:p,collisionPadding:h,sticky:x,hideWhenDetached:m,avoidCollisions:y,...g}=e,b=$n(or,n),[S,k]=v.useState(null),[C,T]=v.useState(null),I=Be(t,Z=>k(Z)),[A,R]=v.useState(null),[L,P]=v.useState(null),D=Ws(n),[F,N]=v.useState(!1),B=v.useRef(!1);v.useEffect(()=>{if(S)return Fi(S)},[S]),bi();const j=v.useCallback(Z=>{const[$,...K]=D().map(oe=>oe.ref.current),[Q]=K.slice(-1),ce=document.activeElement;for(const oe of Z)if(oe===ce||(oe==null||oe.scrollIntoView({block:"nearest"}),oe===$&&C&&(C.scrollTop=0),oe===Q&&C&&(C.scrollTop=C.scrollHeight),oe==null||oe.focus(),document.activeElement!==ce))return},[D,C]),V=v.useCallback(()=>j([A,S]),[j,A,S]);v.useEffect(()=>{F&&V()},[F,V]);const{onOpenChange:z,triggerPointerDownPosRef:M}=b;v.useEffect(()=>{if(S){let Z={x:0,y:0};const $=Q=>{var ce,oe;Z={x:Math.abs(Math.round(Q.pageX)-(((ce=M.current)==null?void 0:ce.x)??0)),y:Math.abs(Math.round(Q.pageY)-(((oe=M.current)==null?void 0:oe.y)??0))}},K=Q=>{Z.x<=10&&Z.y<=10?Q.preventDefault():S.contains(Q.target)||z(!1),document.removeEventListener("pointermove",$),M.current=null};return M.current!==null&&(document.addEventListener("pointermove",$),document.addEventListener("pointerup",K,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",$),document.removeEventListener("pointerup",K,{capture:!0})}}},[S,z,M]),v.useEffect(()=>{const Z=()=>z(!1);return window.addEventListener("blur",Z),window.addEventListener("resize",Z),()=>{window.removeEventListener("blur",Z),window.removeEventListener("resize",Z)}},[z]);const[q,J]=fh(Z=>{const $=D().filter(ce=>!ce.disabled),K=$.find(ce=>ce.ref.current===document.activeElement),Q=ph($,Z,K);Q&&setTimeout(()=>Q.ref.current.focus())}),se=v.useCallback((Z,$,K)=>{const Q=!B.current&&!K;(b.value!==void 0&&b.value===$||Q)&&(R(Z),Q&&(B.current=!0))},[b.value]),ge=v.useCallback(()=>S==null?void 0:S.focus(),[S]),Ee=v.useCallback((Z,$,K)=>{const Q=!B.current&&!K;(b.value!==void 0&&b.value===$||Q)&&P(Z)},[b.value]),Y=r==="popper"?$a:Xp,U=Y===$a?{side:a,sideOffset:l,align:c,alignOffset:d,arrowPadding:f,collisionBoundary:p,collisionPadding:h,sticky:x,hideWhenDetached:m,avoidCollisions:y}:{};return u.jsx(Gp,{scope:n,content:S,viewport:C,onViewportChange:T,itemRefCallback:se,selectedItem:A,onItemLeave:ge,itemTextRefCallback:Ee,focusSelectedItem:V,selectedItemText:L,position:r,isPositioned:F,searchRef:q,children:u.jsx(ns,{as:EC,allowPinchZoom:!0,children:u.jsx(Oo,{asChild:!0,trapped:b.open,onMountAutoFocus:Z=>{Z.preventDefault()},onUnmountAutoFocus:de(o,Z=>{var $;($=b.trigger)==null||$.focus({preventScroll:!0}),Z.preventDefault()}),children:u.jsx(Po,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:Z=>Z.preventDefault(),onDismiss:()=>b.onOpenChange(!1),children:u.jsx(Y,{role:"listbox",id:b.contentId,"data-state":b.open?"open":"closed",dir:b.dir,onContextMenu:Z=>Z.preventDefault(),...g,...U,onPlaced:()=>N(!0),ref:I,style:{display:"flex",flexDirection:"column",outline:"none",...g.style},onKeyDown:de(g.onKeyDown,Z=>{const $=Z.ctrlKey||Z.altKey||Z.metaKey;if(Z.key==="Tab"&&Z.preventDefault(),!$&&Z.key.length===1&&J(Z.key),["ArrowUp","ArrowDown","Home","End"].includes(Z.key)){let Q=D().filter(ce=>!ce.disabled).map(ce=>ce.ref.current);if(["ArrowUp","End"].includes(Z.key)&&(Q=Q.slice().reverse()),["ArrowUp","ArrowDown"].includes(Z.key)){const ce=Z.target,oe=Q.indexOf(ce);Q=Q.slice(oe+1)}setTimeout(()=>j(Q)),Z.preventDefault()}})})})})})})});Yp.displayName=IC;var AC="SelectItemAlignedPosition",Xp=v.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...o}=e,s=$n(or,n),i=Fn(or,n),[a,l]=v.useState(null),[c,d]=v.useState(null),f=Be(t,I=>d(I)),p=Ws(n),h=v.useRef(!1),x=v.useRef(!0),{viewport:m,selectedItem:y,selectedItemText:g,focusSelectedItem:b}=i,S=v.useCallback(()=>{if(s.trigger&&s.valueNode&&a&&c&&m&&y&&g){const I=s.trigger.getBoundingClientRect(),A=c.getBoundingClientRect(),R=s.valueNode.getBoundingClientRect(),L=g.getBoundingClientRect();if(s.dir!=="rtl"){const ce=L.left-A.left,oe=R.left-ce,Ne=I.left-oe,Ue=I.width+Ne,re=Math.max(Ue,A.width),xe=window.innerWidth-cn,Pe=Ra(oe,[cn,Math.max(cn,xe-re)]);a.style.minWidth=Ue+"px",a.style.left=Pe+"px"}else{const ce=A.right-L.right,oe=window.innerWidth-R.right-ce,Ne=window.innerWidth-I.right-oe,Ue=I.width+Ne,re=Math.max(Ue,A.width),xe=window.innerWidth-cn,Pe=Ra(oe,[cn,Math.max(cn,xe-re)]);a.style.minWidth=Ue+"px",a.style.right=Pe+"px"}const P=p(),D=window.innerHeight-cn*2,F=m.scrollHeight,N=window.getComputedStyle(c),B=parseInt(N.borderTopWidth,10),j=parseInt(N.paddingTop,10),V=parseInt(N.borderBottomWidth,10),z=parseInt(N.paddingBottom,10),M=B+j+F+z+V,q=Math.min(y.offsetHeight*5,M),J=window.getComputedStyle(m),se=parseInt(J.paddingTop,10),ge=parseInt(J.paddingBottom,10),Ee=I.top+I.height/2-cn,Y=D-Ee,U=y.offsetHeight/2,Z=y.offsetTop+U,$=B+j+Z,K=M-$;if($<=Ee){const ce=P.length>0&&y===P[P.length-1].ref.current;a.style.bottom="0px";const oe=c.clientHeight-m.offsetTop-m.offsetHeight,Ne=Math.max(Y,U+(ce?ge:0)+oe+V),Ue=$+Ne;a.style.height=Ue+"px"}else{const ce=P.length>0&&y===P[0].ref.current;a.style.top="0px";const Ne=Math.max(Ee,B+m.offsetTop+(ce?se:0)+U)+K;a.style.height=Ne+"px",m.scrollTop=$-Ee+m.offsetTop}a.style.margin=`${cn}px 0`,a.style.minHeight=q+"px",a.style.maxHeight=D+"px",r==null||r(),requestAnimationFrame(()=>h.current=!0)}},[p,s.trigger,s.valueNode,a,c,m,y,g,s.dir,r]);Tt(()=>S(),[S]);const[k,C]=v.useState();Tt(()=>{c&&C(window.getComputedStyle(c).zIndex)},[c]);const T=v.useCallback(I=>{I&&x.current===!0&&(S(),b==null||b(),x.current=!1)},[S,b]);return u.jsx(_C,{scope:n,contentWrapper:a,shouldExpandOnScrollRef:h,onScrollButtonChange:T,children:u.jsx("div",{ref:l,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:k},children:u.jsx(_e.div,{...o,ref:f,style:{boxSizing:"border-box",maxHeight:"100%",...o.style}})})})});Xp.displayName=AC;var NC="SelectPopperPosition",$a=v.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=cn,...s}=e,i=Vs(n);return u.jsx(ru,{...i,...s,ref:t,align:r,collisionPadding:o,style:{boxSizing:"border-box",...s.style,"--radix-select-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-select-content-available-width":"var(--radix-popper-available-width)","--radix-select-content-available-height":"var(--radix-popper-available-height)","--radix-select-trigger-width":"var(--radix-popper-anchor-width)","--radix-select-trigger-height":"var(--radix-popper-anchor-height)"}})});$a.displayName=NC;var[_C,Fa]=Er(or,{}),Ba="SelectViewport",Jp=v.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...o}=e,s=Fn(Ba,n),i=Fa(Ba,n),a=Be(t,s.onViewportChange),l=v.useRef(0);return u.jsxs(u.Fragment,{children:[u.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}"},nonce:r}),u.jsx(Hs.Slot,{scope:n,children:u.jsx(_e.div,{"data-radix-select-viewport":"",role:"presentation",...o,ref:a,style:{position:"relative",flex:1,overflow:"hidden auto",...o.style},onScroll:de(o.onScroll,c=>{const d=c.currentTarget,{contentWrapper:f,shouldExpandOnScrollRef:p}=i;if(p!=null&&p.current&&f){const h=Math.abs(l.current-d.scrollTop);if(h>0){const x=window.innerHeight-cn*2,m=parseFloat(f.style.minHeight),y=parseFloat(f.style.height),g=Math.max(m,y);if(g<x){const b=g+h,S=Math.min(x,b),k=b-S;f.style.height=S+"px",f.style.bottom==="0px"&&(d.scrollTop=k>0?k:0,f.style.justifyContent="flex-end")}}}l.current=d.scrollTop})})})]})});Jp.displayName=Ba;var Zp="SelectGroup",[jC,RC]=Er(Zp),MC=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Cn();return u.jsx(jC,{scope:n,id:o,children:u.jsx(_e.div,{role:"group","aria-labelledby":o,...r,ref:t})})});MC.displayName=Zp;var Qp="SelectLabel",eh=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=RC(Qp,n);return u.jsx(_e.div,{id:o.id,...r,ref:t})});eh.displayName=Qp;var Ks="SelectItem",[PC,th]=Er(Ks),nh=v.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:s,...i}=e,a=$n(Ks,n),l=Fn(Ks,n),c=a.value===r,[d,f]=v.useState(s??""),[p,h]=v.useState(!1),x=Be(t,b=>{var S;return(S=l.itemRefCallback)==null?void 0:S.call(l,b,r,o)}),m=Cn(),y=v.useRef("touch"),g=()=>{o||(a.onValueChange(r),a.onOpenChange(!1))};if(r==="")throw new Error("A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.");return u.jsx(PC,{scope:n,value:r,disabled:o,textId:m,isSelected:c,onItemTextChange:v.useCallback(b=>{f(S=>S||((b==null?void 0:b.textContent)??"").trim())},[]),children:u.jsx(Hs.ItemSlot,{scope:n,value:r,disabled:o,textValue:d,children:u.jsx(_e.div,{role:"option","aria-labelledby":m,"data-highlighted":p?"":void 0,"aria-selected":c&&p,"data-state":c?"checked":"unchecked","aria-disabled":o||void 0,"data-disabled":o?"":void 0,tabIndex:o?void 0:-1,...i,ref:x,onFocus:de(i.onFocus,()=>h(!0)),onBlur:de(i.onBlur,()=>h(!1)),onClick:de(i.onClick,()=>{y.current!=="mouse"&&g()}),onPointerUp:de(i.onPointerUp,()=>{y.current==="mouse"&&g()}),onPointerDown:de(i.onPointerDown,b=>{y.current=b.pointerType}),onPointerMove:de(i.onPointerMove,b=>{var S;y.current=b.pointerType,o?(S=l.onItemLeave)==null||S.call(l):y.current==="mouse"&&b.currentTarget.focus({preventScroll:!0})}),onPointerLeave:de(i.onPointerLeave,b=>{var S;b.currentTarget===document.activeElement&&((S=l.onItemLeave)==null||S.call(l))}),onKeyDown:de(i.onKeyDown,b=>{var k;((k=l.searchRef)==null?void 0:k.current)!==""&&b.key===" "||(vC.includes(b.key)&&g(),b.key===" "&&b.preventDefault())})})})})});nh.displayName=Ks;var uo="SelectItemText",rh=v.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,...s}=e,i=$n(uo,n),a=Fn(uo,n),l=th(uo,n),c=CC(uo,n),[d,f]=v.useState(null),p=Be(t,g=>f(g),l.onItemTextChange,g=>{var b;return(b=a.itemTextRefCallback)==null?void 0:b.call(a,g,l.value,l.disabled)}),h=d==null?void 0:d.textContent,x=v.useMemo(()=>u.jsx("option",{value:l.value,disabled:l.disabled,children:h},l.value),[l.disabled,l.value,h]),{onNativeOptionAdd:m,onNativeOptionRemove:y}=c;return Tt(()=>(m(x),()=>y(x)),[m,y,x]),u.jsxs(u.Fragment,{children:[u.jsx(_e.span,{id:l.textId,...s,ref:p}),l.isSelected&&i.valueNode&&!i.valueNodeHasChildren?ho.createPortal(s.children,i.valueNode):null]})});rh.displayName=uo;var oh="SelectItemIndicator",sh=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return th(oh,n).isSelected?u.jsx(_e.span,{"aria-hidden":!0,...r,ref:t}):null});sh.displayName=oh;var za="SelectScrollUpButton",ih=v.forwardRef((e,t)=>{const n=Fn(za,e.__scopeSelect),r=Fa(za,e.__scopeSelect),[o,s]=v.useState(!1),i=Be(t,r.onScrollButtonChange);return Tt(()=>{if(n.viewport&&n.isPositioned){let a=function(){const c=l.scrollTop>0;s(c)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?u.jsx(lh,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop-l.offsetHeight)}}):null});ih.displayName=za;var Ua="SelectScrollDownButton",ah=v.forwardRef((e,t)=>{const n=Fn(Ua,e.__scopeSelect),r=Fa(Ua,e.__scopeSelect),[o,s]=v.useState(!1),i=Be(t,r.onScrollButtonChange);return Tt(()=>{if(n.viewport&&n.isPositioned){let a=function(){const c=l.scrollHeight-l.clientHeight,d=Math.ceil(l.scrollTop)<c;s(d)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?u.jsx(lh,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop+l.offsetHeight)}}):null});ah.displayName=Ua;var lh=v.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...o}=e,s=Fn("SelectScrollButton",n),i=v.useRef(null),a=Ws(n),l=v.useCallback(()=>{i.current!==null&&(window.clearInterval(i.current),i.current=null)},[]);return v.useEffect(()=>()=>l(),[l]),Tt(()=>{var d;const c=a().find(f=>f.ref.current===document.activeElement);(d=c==null?void 0:c.ref.current)==null||d.scrollIntoView({block:"nearest"})},[a]),u.jsx(_e.div,{"aria-hidden":!0,...o,ref:t,style:{flexShrink:0,...o.style},onPointerDown:de(o.onPointerDown,()=>{i.current===null&&(i.current=window.setInterval(r,50))}),onPointerMove:de(o.onPointerMove,()=>{var c;(c=s.onItemLeave)==null||c.call(s),i.current===null&&(i.current=window.setInterval(r,50))}),onPointerLeave:de(o.onPointerLeave,()=>{l()})})}),OC="SelectSeparator",ch=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return u.jsx(_e.div,{"aria-hidden":!0,...r,ref:t})});ch.displayName=OC;var Ha="SelectArrow",DC=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Vs(n),s=$n(Ha,n),i=Fn(Ha,n);return s.open&&i.position==="popper"?u.jsx(ou,{...o,...r,ref:t}):null});DC.displayName=Ha;var LC="SelectBubbleInput",uh=v.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const o=v.useRef(null),s=Be(r,o),i=$p(t);return v.useEffect(()=>{const a=o.current;if(!a)return;const l=window.HTMLSelectElement.prototype,d=Object.getOwnPropertyDescriptor(l,"value").set;if(i!==t&&d){const f=new Event("change",{bubbles:!0});d.call(a,t),a.dispatchEvent(f)}},[i,t]),u.jsx(_e.select,{...n,style:{...Fp,...n.style},ref:s,defaultValue:t})});uh.displayName=LC;function dh(e){return e===""||e===void 0}function fh(e){const t=kt(e),n=v.useRef(""),r=v.useRef(0),o=v.useCallback(i=>{const a=n.current+i;t(a),function l(c){n.current=c,window.clearTimeout(r.current),c!==""&&(r.current=window.setTimeout(()=>l(""),1e3))}(a)},[t]),s=v.useCallback(()=>{n.current="",window.clearTimeout(r.current)},[]);return v.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,o,s]}function ph(e,t,n){const o=t.length>1&&Array.from(t).every(c=>c===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let i=$C(e,Math.max(s,0));o.length===1&&(i=i.filter(c=>c!==n));const l=i.find(c=>c.textValue.toLowerCase().startsWith(o.toLowerCase()));return l!==n?l:void 0}function $C(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var FC=Bp,hh=Up,BC=Wp,zC=Vp,UC=Kp,mh=qp,HC=Jp,gh=eh,xh=nh,WC=rh,VC=sh,yh=ih,vh=ah,bh=ch;const wh=FC,Sh=BC,Wa=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(hh,{ref:r,className:ne("flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",e),...n,children:[t,u.jsx(zC,{asChild:!0,children:u.jsx(ae.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));Wa.displayName=hh.displayName;const Ch=v.forwardRef(({className:e,...t},n)=>u.jsx(yh,{ref:n,className:ne("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(ae.ChevronUp,{className:"h-4 w-4"})}));Ch.displayName=yh.displayName;const Th=v.forwardRef(({className:e,...t},n)=>u.jsx(vh,{ref:n,className:ne("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(ae.ChevronDown,{className:"h-4 w-4"})}));Th.displayName=vh.displayName;const Va=v.forwardRef(({className:e,children:t,position:n="popper",...r},o)=>u.jsx(UC,{children:u.jsxs(mh,{ref:o,className:ne("relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",n==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",e),position:n,...r,children:[u.jsx(Ch,{}),u.jsx(HC,{className:ne("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),u.jsx(Th,{})]})}));Va.displayName=mh.displayName;const KC=v.forwardRef(({className:e,...t},n)=>u.jsx(gh,{ref:n,className:ne("py-1.5 pl-8 pr-2 text-sm font-semibold",e),...t}));KC.displayName=gh.displayName;const sr=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(xh,{ref:r,className:ne("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(VC,{children:u.jsx(ae.Check,{className:"h-4 w-4"})})}),u.jsx(WC,{children:t})]}));sr.displayName=xh.displayName;const qC=v.forwardRef(({className:e,...t},n)=>u.jsx(bh,{ref:n,className:ne("-mx-1 my-1 h-px bg-muted",e),...t}));qC.displayName=bh.displayName;var GC="Separator",kh="horizontal",YC=["horizontal","vertical"],Ih=v.forwardRef((e,t)=>{const{decorative:n,orientation:r=kh,...o}=e,s=XC(r)?r:kh,a=n?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return u.jsx(_e.div,{"data-orientation":s,...a,...o,ref:t})});Ih.displayName=GC;function XC(e){return YC.includes(e)}var Eh=Ih;const Ah=v.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},o)=>u.jsx(Eh,{ref:o,decorative:n,orientation:t,className:ne("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));Ah.displayName=Eh.displayName;const JC=Bf,ZC=cS,QC=zf,Nh=v.forwardRef(({className:e,...t},n)=>u.jsx(Es,{className:ne("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}));Nh.displayName=Es.displayName;const eT=po.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"}}),_h=v.forwardRef(({side:e="right",className:t,children:n,...r},o)=>u.jsxs(QC,{children:[u.jsx(Nh,{}),u.jsxs(As,{ref:o,className:ne(eT({side:e}),t),...r,children:[n,u.jsxs(Uf,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-secondary",children:[u.jsx(ae.X,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));_h.displayName=As.displayName;const jh=({className:e,...t})=>u.jsx("div",{className:ne("flex flex-col space-y-2 text-center sm:text-left",e),...t});jh.displayName="SheetHeader";const Rh=v.forwardRef(({className:e,...t},n)=>u.jsx(tr,{ref:n,className:ne("text-lg font-semibold text-foreground",e),...t}));Rh.displayName=tr.displayName;const Mh=v.forwardRef(({className:e,...t},n)=>u.jsx(Ns,{ref:n,className:ne("text-sm text-muted-foreground",e),...t}));Mh.displayName=Ns.displayName;var qs="Switch",[tT,zT]=Sn(qs),[nT,rT]=tT(qs),Ph=v.forwardRef((e,t)=>{const{__scopeSwitch:n,name:r,checked:o,defaultChecked:s,required:i,disabled:a,value:l="on",onCheckedChange:c,form:d,...f}=e,[p,h]=v.useState(null),x=Be(t,S=>h(S)),m=v.useRef(!1),y=p?d||!!p.closest("form"):!0,[g,b]=pr({prop:o,defaultProp:s??!1,onChange:c,caller:qs});return u.jsxs(nT,{scope:n,checked:g,disabled:a,children:[u.jsx(_e.button,{type:"button",role:"switch","aria-checked":g,"aria-required":i,"data-state":$h(g),"data-disabled":a?"":void 0,disabled:a,value:l,...f,ref:x,onClick:de(e.onClick,S=>{b(k=>!k),y&&(m.current=S.isPropagationStopped(),m.current||S.stopPropagation())})}),y&&u.jsx(Lh,{control:p,bubbles:!m.current,name:r,value:l,checked:g,required:i,disabled:a,form:d,style:{transform:"translateX(-100%)"}})]})});Ph.displayName=qs;var Oh="SwitchThumb",Dh=v.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,o=rT(Oh,n);return u.jsx(_e.span,{"data-state":$h(o.checked),"data-disabled":o.disabled?"":void 0,...r,ref:t})});Dh.displayName=Oh;var oT="SwitchBubbleInput",Lh=v.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...o},s)=>{const i=v.useRef(null),a=Be(i,s),l=$p(n),c=Vc(t);return v.useEffect(()=>{const d=i.current;if(!d)return;const f=window.HTMLInputElement.prototype,h=Object.getOwnPropertyDescriptor(f,"checked").set;if(l!==n&&h){const x=new Event("click",{bubbles:r});h.call(d,n),d.dispatchEvent(x)}},[l,n,r]),u.jsx("input",{type:"checkbox","aria-hidden":!0,defaultChecked:n,...o,tabIndex:-1,ref:a,style:{...o.style,...c,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});Lh.displayName=oT;function $h(e){return e?"checked":"unchecked"}var Fh=Ph,sT=Dh;const Bn=v.forwardRef(({className:e,...t},n)=>u.jsx(Fh,{className:ne("peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",e),...t,ref:n,children:u.jsx(sT,{className:ne("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")})}));Bn.displayName=Fh.displayName;const iT={api:{baseUrl:"http://localhost:8000/api",authToken:"",enableAuth:!1},ui:{layout:"sidebar",theme:"light",showTimestamps:!0,showAgentNames:!0,compactMessages:!1},behavior:{autoSave:!0,enableStreaming:!0,showTypingIndicator:!0}};function aT({settings:e,onSettingsChange:t,className:n=""}){const[r,o]=w.useState(!1),[s,i]=w.useState(!1),[a,l]=w.useState(e),[c,d]=w.useState(!1),{toast:f}=Aa();w.useEffect(()=>{const y=JSON.stringify(a)!==JSON.stringify(e);d(y)},[a,e]),w.useEffect(()=>{l(e)},[e]);const p=()=>{t(a),d(!1),f({title:"Settings saved",description:"Your chat configuration has been updated successfully."})},h=()=>{l(iT),d(!0),f({title:"Settings reset",description:"Configuration has been reset to defaults."})},x=()=>{l(e),d(!1),o(!1)},m=async()=>{try{const g=await(await fetch(`${a.api.baseUrl}/health`)).json();f({title:"Connection successful",description:`API is ${g.status||"healthy"}`})}catch{f({title:"Connection failed",description:"Unable to connect to the API endpoint.",variant:"destructive"})}};return u.jsxs(JC,{open:r,onOpenChange:o,children:[u.jsx(ZC,{asChild:!0,children:u.jsxs(Xe,{variant:"outline",size:"sm",className:n,children:[u.jsx(ae.Settings,{className:"h-4 w-4 mr-2"}),"Settings",c&&u.jsx(yf,{variant:"destructive",className:"ml-2 h-4 w-4 p-0"})]})}),u.jsxs(_h,{className:"w-[500px] sm:w-[600px] overflow-y-auto",children:[u.jsxs(jh,{children:[u.jsx(Rh,{children:"Chat Settings"}),u.jsx(Mh,{children:"Configure your chat interface, API connection, and behavior preferences."})]}),u.jsxs("div",{className:"space-y-6 py-6",children:[u.jsxs(io,{children:[u.jsx(ao,{className:"pb-3",children:u.jsxs(lo,{className:"text-lg flex items-center gap-2",children:[u.jsx(ae.Server,{className:"h-5 w-5"}),"API Configuration"]})}),u.jsxs(co,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(en,{htmlFor:"api-url",children:"API Base URL"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx($s,{id:"api-url",value:a.api.baseUrl,onChange:y=>l(g=>({...g,api:{...g.api,baseUrl:y.target.value}})),placeholder:"http://localhost:8000/api"}),u.jsx(Xe,{variant:"outline",onClick:m,children:"Test"})]})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(en,{htmlFor:"enable-auth",children:"Enable Authentication"}),u.jsx(Bn,{id:"enable-auth",checked:a.api.enableAuth,onCheckedChange:y=>l(g=>({...g,api:{...g.api,enableAuth:y}}))})]}),a.api.enableAuth&&u.jsxs("div",{className:"space-y-2",children:[u.jsx(en,{htmlFor:"auth-token",children:"Authentication Token"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx($s,{id:"auth-token",type:s?"text":"password",value:a.api.authToken,onChange:y=>l(g=>({...g,api:{...g.api,authToken:y.target.value}})),placeholder:"Enter your Bearer token"}),u.jsx(Xe,{variant:"outline",size:"icon",onClick:()=>i(!s),children:s?u.jsx(ae.EyeOff,{className:"h-4 w-4"}):u.jsx(ae.Eye,{className:"h-4 w-4"})})]})]})]})]}),u.jsxs(io,{children:[u.jsx(ao,{className:"pb-3",children:u.jsxs(lo,{className:"text-lg flex items-center gap-2",children:[u.jsx(ae.Layout,{className:"h-5 w-5"}),"Interface Settings"]})}),u.jsxs(co,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(en,{htmlFor:"layout",children:"Layout Style"}),u.jsxs(wh,{value:a.ui.layout,onValueChange:y=>l(g=>({...g,ui:{...g.ui,layout:y}})),children:[u.jsx(Wa,{children:u.jsx(Sh,{})}),u.jsxs(Va,{children:[u.jsx(sr,{value:"sidebar",children:"Sidebar Layout"}),u.jsx(sr,{value:"fullscreen",children:"Fullscreen"}),u.jsx(sr,{value:"tabs",children:"Tabbed Interface"})]})]})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx(en,{htmlFor:"theme",children:"Theme"}),u.jsxs(wh,{value:a.ui.theme,onValueChange:y=>l(g=>({...g,ui:{...g.ui,theme:y}})),children:[u.jsx(Wa,{children:u.jsx(Sh,{})}),u.jsxs(Va,{children:[u.jsx(sr,{value:"light",children:"Light"}),u.jsx(sr,{value:"dark",children:"Dark"}),u.jsx(sr,{value:"system",children:"System"})]})]})]}),u.jsx(Ah,{}),u.jsxs("div",{className:"space-y-3",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(en,{htmlFor:"show-timestamps",children:"Show Timestamps"}),u.jsx(Bn,{id:"show-timestamps",checked:a.ui.showTimestamps,onCheckedChange:y=>l(g=>({...g,ui:{...g.ui,showTimestamps:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(en,{htmlFor:"show-agent-names",children:"Show Agent Names"}),u.jsx(Bn,{id:"show-agent-names",checked:a.ui.showAgentNames,onCheckedChange:y=>l(g=>({...g,ui:{...g.ui,showAgentNames:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(en,{htmlFor:"compact-messages",children:"Compact Messages"}),u.jsx(Bn,{id:"compact-messages",checked:a.ui.compactMessages,onCheckedChange:y=>l(g=>({...g,ui:{...g.ui,compactMessages:y}}))})]})]})]})]}),u.jsxs(io,{children:[u.jsx(ao,{className:"pb-3",children:u.jsxs(lo,{className:"text-lg flex items-center gap-2",children:[u.jsx(ae.MessageCircle,{className:"h-5 w-5"}),"Behavior Settings"]})}),u.jsxs(co,{className:"space-y-4",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(en,{htmlFor:"auto-save",children:"Auto-save Conversations"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Automatically save messages to threads"})]}),u.jsx(Bn,{id:"auto-save",checked:a.behavior.autoSave,onCheckedChange:y=>l(g=>({...g,behavior:{...g.behavior,autoSave:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(en,{htmlFor:"enable-streaming",children:"Enable Streaming"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Stream responses in real-time"})]}),u.jsx(Bn,{id:"enable-streaming",checked:a.behavior.enableStreaming,onCheckedChange:y=>l(g=>({...g,behavior:{...g.behavior,enableStreaming:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(en,{htmlFor:"typing-indicator",children:"Typing Indicator"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Show typing indicator during responses"})]}),u.jsx(Bn,{id:"typing-indicator",checked:a.behavior.showTypingIndicator,onCheckedChange:y=>l(g=>({...g,behavior:{...g.behavior,showTypingIndicator:y}}))})]})]})]})]}),u.jsxs("div",{className:"flex items-center justify-between pt-6 border-t",children:[u.jsxs(Xe,{variant:"outline",onClick:h,children:[u.jsx(ae.RotateCcw,{className:"h-4 w-4 mr-2"}),"Reset"]}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(Xe,{variant:"outline",onClick:x,children:"Cancel"}),u.jsxs(Xe,{onClick:p,disabled:!c,children:[u.jsx(ae.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=c=>{const d="h-full";switch(c){case"phone":return`${d} max-w-none`;case"tablet":return`${d} max-w-4xl mx-auto`;case"half-screen":return`${d} max-w-2xl`;case"desktop":default:return`${d} max-w-7xl mx-auto`}},a=c=>({"--chat-sidebar-width":c==="phone"?"100%":c==="tablet"?"280px":c==="half-screen"?"240px":"320px","--chat-message-max-width":c==="phone"?"95%":c==="tablet"?"90%":c==="half-screen"?"85%":"80%","--chat-input-height":c==="phone"?"120px":"100px"}),l=w.useCallback(c=>{var d;(d=s.onThreadChange)==null||d.call(s,c)},[s]);return e==="fullscreen"?u.jsx(Ro,{...s,onThreadChange:l,children:u.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:u.jsx(Ls,{className:"flex-1",onError:s.onError,enableFileUpload:!0})})}):e==="tabs"?u.jsx(Ro,{...s,onThreadChange:l,children:u.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:u.jsxs("div",{className:"flex-1 flex min-h-0 overflow-hidden",children:[n&&u.jsx("div",{className:`w-80 border-r flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:u.jsx(La,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),u.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:u.jsx(Ls,{onError:s.onError,enableFileUpload:!0})})]})})}):u.jsx(Ro,{...s,onThreadChange:l,children:u.jsxs("div",{className:`${i(t)} flex overflow-hidden ${r} ${o.container||""}`,style:a(t),children:[n&&u.jsx("div",{className:`w-80 border-r bg-gray-50 flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:u.jsx(La,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),u.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:u.jsx(Ls,{onError:s.onError,enableFileUpload:!0})})]})})}Ce.ChatApi=Bl,Ce.ChatInput=cc,Ce.ChatInterface=Ls,Ce.ChatProviders=Ro,Ce.ChatSettings=aT,Ce.MarkdownContent=so,Ce.MessageComponent=Ds,Ce.MessageList=ja,Ce.ThreadManager=La,Ce.TimelineColumn=lC,Ce.applySettings=pC,Ce.buildMessagePreviewMap=ql,Ce.chatApiClient=An,Ce.default=lT,Ce.del=Fl,Ce.get=qt,Ce.getChatToken=Dl,Ce.getCurrentSettings=fC,Ce.getDefaultApiConfig=Mp,Ce.getDefaultChatSettings=Pp,Ce.onChatTokenChanged=Ll,Ce.post=ci,Ce.put=$l,Ce.setChatToken=Io,Ce.useApi=ui,Ce.useChatStream=Gl,Ce.useMessagesReducer=Yl,Ce.useStream=ac,Ce.useThreadState=jo,Ce.useThreads=_o,Object.defineProperties(Ce,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
134
|
+
`}strong(t){return`<strong>${t}</strong>`}em(t){return`<em>${t}</em>`}codespan(t){return`<code>${t}</code>`}br(){return this.options.xhtml?"<br/>":"<br>"}del(t){return`<del>${t}</del>`}link(t,n,r){if(t=Qf(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=Qf(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 op{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 sp{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 Ln{constructor(t){this.options=t||nr,this.options.renderer=this.options.renderer||new _a,this.renderer=this.options.renderer,this.renderer.options=this.options,this.textRenderer=new op,this.slugger=new sp}static parse(t,n){return new Ln(n).parse(t)}static parseInline(t,n){return new Ln(n).parseInline(t)}parse(t,n=!0){let r="",o,s,i,a,l,c,d,f,h,p,x,m,y,g,b,S,k,C,T;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]&&(T=this.options.extensions.renderers[p.type].call({parser:this},p),T!==!1||!["space","hr","heading","code","table","blockquote","list","html","paragraph","text"].includes(p.type))){r+=T||"";continue}switch(p.type){case"space":continue;case"hr":{r+=this.renderer.hr();continue}case"heading":{r+=this.renderer.heading(this.parseInline(p.tokens),p.depth,Zf(this.parseInline(p.tokens,this.textRenderer)),this.slugger);continue}case"code":{r+=this.renderer.code(p.text,p.lang,p.escaped);continue}case"table":{for(f="",d="",a=p.header.length,s=0;s<a;s++)d+=this.renderer.tablecell(this.parseInline(p.header[s].tokens),{header:!0,align:p.align[s]});for(f+=this.renderer.tablerow(d),h="",a=p.rows.length,s=0;s<a;s++){for(c=p.rows[s],d="",l=c.length,i=0;i<l;i++)d+=this.renderer.tablecell(this.parseInline(c[i].tokens),{header:!1,align:p.align[i]});h+=this.renderer.tablerow(d)}r+=this.renderer.table(f,h);continue}case"blockquote":{h=this.parse(p.tokens),r+=this.renderer.blockquote(h);continue}case"list":{for(x=p.ordered,m=p.start,y=p.loose,a=p.items.length,h="",s=0;s<a;s++)b=p.items[s],S=b.checked,k=b.task,g="",b.task&&(C=this.renderer.checkbox(S),y?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}):g+=C),g+=this.parse(b.tokens,y),h+=this.renderer.listitem(g,k,S);r+=this.renderer.list(h,x,m);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+=`
|
|
135
|
+
`+(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 Os{constructor(t){this.options=t||nr}preprocess(t){return t}postprocess(t){return t}}Bh(Os,"passThroughHooks",new Set(["preprocess","postprocess"]));function OS(e,t,n){return r=>{if(r.message+=`
|
|
136
|
+
Please report this to https://github.com/markedjs/marked.`,e){const o="<p>An error occurred:</p><pre>"+jt(r.message+"",!0)+"</pre>";if(t)return Promise.resolve(o);if(n){n(null,o);return}return o}if(t)return Promise.reject(r);if(n){n(r);return}throw r}}function ip(e,t){return(n,r,o)=>{typeof r=="function"&&(o=r,r=null);const s={...r};r={...me.defaults,...s};const i=OS(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(RS(r),r.hooks&&(r.hooks.options=r),o){const a=r.highlight;let l;try{r.hooks&&(n=r.hooks.preprocess(n)),l=e(n,r)}catch(f){return i(f)}const c=function(f){let h;if(!f)try{r.walkTokens&&me.walkTokens(l,r.walkTokens),h=t(l,r),r.hooks&&(h=r.hooks.postprocess(h))}catch(p){f=p}return r.highlight=a,f?i(f):o(null,h)};if(!a||a.length<3||(delete r.highlight,!l.length))return c();let d=0;me.walkTokens(l,function(f){f.type==="code"&&(d++,setTimeout(()=>{a(f.text,f.lang,function(h,p){if(h)return c(h);p!=null&&p!==f.text&&(f.text=p,f.escaped=!0),d--,d===0&&c()})},0))}),d===0&&c();return}if(r.async)return Promise.resolve(r.hooks?r.hooks.preprocess(n):n).then(a=>e(a,r)).then(a=>r.walkTokens?Promise.all(me.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&&me.walkTokens(a,r.walkTokens);let l=t(a,r);return r.hooks&&(l=r.hooks.postprocess(l)),l}catch(a){return i(a)}}}function me(e,t,n){return ip(Dn.lex,Ln.parse)(e,t,n)}me.options=me.setOptions=function(e){return me.defaults={...me.defaults,...e},vS(me.defaults),me},me.getDefaults=Gf,me.defaults=nr,me.use=function(...e){const t=me.defaults.extensions||{renderers:{},childTokens:{}};e.forEach(n=>{const r={...n};if(r.async=me.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=me.defaults.renderer||new _a;for(const s in n.renderer){const i=o[s];o[s]=(...a)=>{let l=n.renderer[s].apply(o,a);return l===!1&&(l=i.apply(o,a)),l}}r.renderer=o}if(n.tokenizer){const o=me.defaults.tokenizer||new Na;for(const s in n.tokenizer){const i=o[s];o[s]=(...a)=>{let l=n.tokenizer[s].apply(o,a);return l===!1&&(l=i.apply(o,a)),l}}r.tokenizer=o}if(n.hooks){const o=me.defaults.hooks||new Os;for(const s in n.hooks){const i=o[s];Os.passThroughHooks.has(s)?o[s]=a=>{if(me.defaults.async)return Promise.resolve(n.hooks[s].call(o,a)).then(c=>i.call(o,c));const l=n.hooks[s].call(o,a);return i.call(o,l)}:o[s]=(...a)=>{let l=n.hooks[s].apply(o,a);return l===!1&&(l=i.apply(o,a)),l}}r.hooks=o}if(n.walkTokens){const o=me.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}}me.setOptions(r)})},me.walkTokens=function(e,t){let n=[];for(const r of e)switch(n=n.concat(t.call(me,r)),r.type){case"table":{for(const o of r.header)n=n.concat(me.walkTokens(o.tokens,t));for(const o of r.rows)for(const s of o)n=n.concat(me.walkTokens(s.tokens,t));break}case"list":{n=n.concat(me.walkTokens(r.items,t));break}default:me.defaults.extensions&&me.defaults.extensions.childTokens&&me.defaults.extensions.childTokens[r.type]?me.defaults.extensions.childTokens[r.type].forEach(function(o){n=n.concat(me.walkTokens(r[o],t))}):r.tokens&&(n=n.concat(me.walkTokens(r.tokens,t)))}return n},me.parseInline=ip(Dn.lexInline,Ln.parseInline),me.Parser=Ln,me.parser=Ln.parse,me.Renderer=_a,me.TextRenderer=op,me.Lexer=Dn,me.lexer=Dn.lex,me.Tokenizer=Na,me.Slugger=sp,me.Hooks=Os,me.parse=me,me.options,me.setOptions,me.use,me.walkTokens,me.parseInline,Ln.parse,Dn.lex;function so({content:e,className:t="",allowHtml:n=!1,style:r}){const o=w.useMemo(()=>{try{if(!n){const i=e.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,"").replace(/<iframe\b[^<]*(?:(?!<\/iframe>)<[^<]*)*<\/iframe>/gi,"").replace(/javascript:/gi,"").replace(/on\w+\s*=/gi,"");return typeof me.parse=="function"?me.parse(i):me(i)}return typeof me.parse=="function"?me.parse(e):me(e)}catch(i){return console.error("[MarkdownContent] parse error",i),`<pre class="font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words">Error rendering markdown: ${String(i)}</pre>`}},[e,n]),s=w.useMemo(()=>{const i={color:"currentColor",...r};if(r&&r.color){const a=r.color;return{...i,"--tw-prose-body":a,"--tw-prose-headings":a,"--tw-prose-links":a,"--tw-prose-bold":a,"--tw-prose-counters":a,"--tw-prose-bullets":a,"--tw-prose-hr":a,"--tw-prose-quotes":a,"--tw-prose-quote-borders":a,"--tw-prose-captions":a,"--tw-prose-code":a,"--tw-prose-pre-code":a,"--tw-prose-pre-bg":"inherit","--tw-prose-th-borders":a,"--tw-prose-td-borders":a}}return i},[r]);return u.jsx("div",{className:ne("markdown prose prose-sm max-w-none break-words","dark:prose-invert","text-current","prose-headings:text-current prose-p:text-current prose-li:text-current prose-a:text-current prose-strong:text-current","prose-em:text-current prose-blockquote:text-current prose-table:text-current prose-td:text-current prose-th:text-current","prose-pre:font-mono prose-pre:text-xs prose-pre:bg-background/50 prose-pre:border prose-pre:rounded prose-pre:p-3 prose-pre:whitespace-pre prose-pre:overflow-x-auto","prose-code:font-mono prose-code:text-sm prose-code:bg-background/50 prose-code:px-1.5 prose-code:py-0.5 prose-code:rounded prose-code:text-current",t),style:s,dangerouslySetInnerHTML:{__html:o}})}const DS={MODE:"library"};function LS(){var i;const e=typeof globalThis<"u"?globalThis.process:void 0,t=typeof((i=e==null?void 0:e.env)==null?void 0:i.NODE_ENV)=="string"?e.env.NODE_ENV:void 0;if(t)return t==="production";const n=typeof{url:typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Ys&&Ys.tagName.toUpperCase()==="SCRIPT"&&Ys.src||new URL("index.umd.js",document.baseURI).href}<"u"?DS:void 0,r=typeof(n==null?void 0:n.MODE)=="string"?n.MODE:void 0,o=typeof(n==null?void 0:n.NODE_ENV)=="string"?n.NODE_ENV:void 0;return(r??o)==="production"}function $S(){return!LS()}function FS(){return typeof window>"u"?!1:window.__ARTIFACT_DEBUG__===!0}function BS(){return $S()||FS()}function zS({preview:e,idx:t}){return w.useEffect(()=>{BS()&&console.debug(`[MessageComponent] Preview ${t} mounted:`,{src:e.src.substring(0,100),alt:e.alt,label:e.label})},[t,e]),u.jsxs("div",{className:"space-y-2",children:[e.label&&u.jsxs("p",{className:"text-[0.65rem] uppercase tracking-wide text-muted-foreground",children:["Artifact: ",e.label]}),u.jsx("div",{className:"overflow-hidden rounded border border-border/60 bg-background/60 p-1 shadow-sm",children:u.jsx("img",{src:e.src,alt:e.alt,title:e.label,loading:"lazy",className:"h-auto max-h-[420px] w-full rounded object-contain",onLoad:()=>{},onError:n=>{console.error(`[MessageComponent] ❌ Image failed to load for artifact ${t}:`,{alt:e.alt,label:e.label,message:n.target.alt})}})})]})}const US="prose prose-sm max-w-none break-words dark:prose-invert prose-headings:break-words prose-p:break-words prose-li:break-words prose-td:break-words prose-th:break-words prose-a:break-all prose-code:break-words prose-blockquote:break-words";function ap({data:e}){return Array.isArray(e)?e.every(n=>n===null||["string","number","boolean"].includes(typeof n))?u.jsx("div",{className:US,children:u.jsx("ul",{className:"list-disc pl-5",children:e.map((n,r)=>u.jsx("li",{children:String(n)},r))})}):u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:ro(e)}):u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:ro(e)})}const io=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:ne("rounded-lg border bg-card text-card-foreground shadow-sm",e),...t}));io.displayName="Card";const ao=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:ne("flex flex-col space-y-1.5 p-6",e),...t}));ao.displayName="CardHeader";const lo=v.forwardRef(({className:e,...t},n)=>u.jsx("h3",{ref:n,className:ne("text-2xl font-semibold leading-none tracking-tight",e),...t}));lo.displayName="CardTitle";const lp=v.forwardRef(({className:e,...t},n)=>u.jsx("p",{ref:n,className:ne("text-sm text-muted-foreground",e),...t}));lp.displayName="CardDescription";const co=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:ne("p-6 pt-0",e),...t}));co.displayName="CardContent";const cp=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:ne("flex items-center p-6 pt-0",e),...t}));cp.displayName="CardFooter";function HS({interruptPart:e,onApprove:t,onReject:n,disabled:r,isActive:o,payload:s}){const i=e.title??"Approve the result?";let a=null;if(s!=null)if(typeof s=="string")a=u.jsx("p",{className:"text-sm leading-relaxed text-blue-800/90 dark:text-blue-200/90 whitespace-pre-wrap",children:s});else{const c=ro(s);a=u.jsx("pre",{className:"max-h-48 overflow-auto rounded bg-blue-100/60 p-2 text-xs text-blue-900/90 dark:bg-blue-900/40 dark:text-blue-100/80",children:c})}const l=o?"Please approve or reject this action to resume the workflow.":"Waiting for approval from another participant.";return u.jsxs(io,{className:ne("border-blue-200 dark:border-blue-800 bg-blue-50/50 dark:bg-blue-950/10 transition-shadow",o?"shadow-md ring-1 ring-blue-300 dark:ring-blue-500/70":"opacity-80"),children:[u.jsxs(ao,{className:"pb-3",children:[u.jsx(lo,{className:"text-blue-900 dark:text-blue-100 text-base",children:i}),u.jsx(lp,{className:"text-blue-700 dark:text-blue-300 text-sm",children:l})]}),a&&u.jsx(co,{className:"pt-0 pb-3",children:a}),u.jsx(cp,{className:"pt-0",children:u.jsxs("div",{className:"flex gap-2 ml-auto",children:[u.jsx(Xe,{size:"sm",variant:"outline",onClick:()=>n(e),className:"border-red-300 text-red-700 hover:bg-red-50 dark:border-red-700 dark:text-red-300 dark:hover:bg-red-950/50",disabled:r||!o,children:"Reject"}),u.jsx(Xe,{size:"sm",onClick:()=>t(e),className:"bg-blue-600 hover:bg-blue-700 text-white",disabled:r||!o,children:"Approve"})]})})]})}function WS(e){const{allowFileOpen:t,currentThreadId:n}=e,{toast:r}=Aa(),[o,s]=w.useState({}),[i,a]=w.useState(null),[l,c]=w.useState(!1),d=w.useCallback(()=>{c(!1),a(null)},[]),f=w.useCallback(p=>{a(p),c(!0)},[]),h=w.useCallback(async(p,x,m)=>{var y,g;if(!t){p.preventDefault();return}if(o[m]){p.preventDefault();return}try{const b=String(x.url??""),S=b.match(/\/chat\/files\/([^/]+)(?:\/(view|download))?/);if(S){p.preventDefault();const k=S[1],C=x.name||`file_${k}`,T=x.mimeType||"application/octet-stream";f({id:k,name:C,mimeType:T});return}if(b.startsWith("data:")){p.preventDefault(),s(C=>({...C,[m]:!0}));const k=r({title:"Fetching file...",description:"",open:!0});try{const C=await Q0(n??void 0);if(!C||!Array.isArray(C))throw new Error("Invalid file list response");const T=C.find(I=>!I||typeof I!="object"||!((I.filename??"")===(x.name??""))?!1:typeof x.size=="number"&&typeof I.size=="number"?I.size===x.size:!0);if(!(T!=null&&T.id))throw new Error(`File "${x.name}" is not yet available on the server`);if(!T.id||!T.filename)throw new Error("Invalid file data received from server");f({id:T.id,name:x.name||T.filename||`file_${T.id}`,mimeType:x.mimeType||T.mime_type||"application/octet-stream"}),(y=k.update)==null||y.call(k,{id:k.id,title:"Success",description:`Opened ${x.name}`,open:!0})}catch(C){console.error("Failed to fetch server file:",C);const T=C instanceof Error?C.message:"Unknown error occurred";(g=k.update)==null||g.call(k,{id:k.id,title:"Failed",description:T}),r({title:"Failed to fetch file",description:T,open:!0})}finally{s(C=>({...C,[m]:!1}))}}}catch(b){console.error("File click error:",b),s(S=>({...S,[m]:!1}))}},[t,o,r,n,f]);return{uploadingFiles:o,handleFileClick:h,fileViewerOpen:l,currentFileInfo:i,closeFileViewer:d}}function VS({text:e,expanded:t,onExpandedChange:n,previewLength:r,isCompact:o}){const s=Math.max(e.length-r,0),i=e.substring(0,r);return u.jsxs("div",{className:"flex flex-col gap-1",children:[u.jsx("div",{className:ne("text-sm text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:t?u.jsx(so,{content:e,allowHtml:!1}):u.jsxs("pre",{className:ne("font-sans whitespace-pre-wrap break-words bg-transparent p-0 m-0 text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:[i,"..."]})}),u.jsx(Xe,{type:"button",variant:"ghost",size:"sm",className:"h-6 text-xs !text-[hsl(var(--chat-bubble-user-text))]",onClick:()=>n(!t),children:t?u.jsxs(u.Fragment,{children:[u.jsx(ae.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):u.jsxs(u.Fragment,{children:[u.jsx(ae.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more (",s," chars)"]})})]})}function KS({message:e,viewMode:t}){const r=bf(e).name||"tool",o=c=>{if(c==null)return null;const d=typeof c=="string"?Sa(c)??c:c;if(d&&typeof d=="object")return u.jsx(ap,{data:d});const f=typeof d=="string"?d:(()=>{try{return ro(d)}catch{return String(d??"")}})();return u.jsx("pre",{className:"whitespace-pre-wrap break-words font-sans text-sm text-foreground/90",children:f})},s=c=>{if(c==null)return null;const{content:d,isMarkdown:f}=W0(c);return f?u.jsx(so,{content:d,className:"text-current"}):o(c)};if(t==="preview")return null;const i=e.content.find(c=>c.type!=="tool_call");if(!i)return u.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[u.jsx(ae.Loader,{className:"h-4 w-4 animate-spin"}),u.jsxs("span",{children:["Waiting for ",r," output…"]})]});if(i.type==="text"){const d=(i.text??"").trim();if(!d)return null;const f=Cs(d);return s(f)}const a=no(i),l=Cs(a);return s(l)}function qS({className:e}){const[t,n]=w.useState(0);return w.useEffect(()=>{const r=setInterval(()=>n(o=>(o+1)%4),500);return()=>clearInterval(r)},[]),u.jsxs("span",{"aria-live":"polite",className:ne("inline-block text-xs opacity-70 ml-1",e),children:["Is thinking",".".repeat(t)]})}const Ds=w.memo(function({message:t,messageIndex:n,isStreamingMessage:r=!1,isEditing:o=!1,showActions:s=!0,showTimestamp:i=!0,showAgentName:a=!0,layoutSize:l="desktop",truncateUserMessages:c=!0,userMessagePreviewLength:d=500,showToolMessages:f=!0,showArtifactPreviews:h=!0,customStyles:p={},onEdit:x,onRegenerate:m,onCancelEdit:y,onCopy:g,activeInterrupt:b,disableInterruptActions:S=!1,onInterruptActionStart:k,onInterruptActionEnd:C,checkpointCandidates:T=[],activeCheckpointId:I=null,onSelectCheckpoint:A,defaultCheckpointId:R=null,messageParentCheckpointId:L=null}){const[P,D]=w.useState(!1),[F,N]=w.useState("preview"),[B,j]=w.useState(!1),{currentThreadId:V}=_o(),{respondToInterrupt:z}=jo(),M=l==="phone"||l==="half-screen",q=t.role,J=q==="tool",se=w.useMemo(()=>"type"in t&&t.type==="default_message"?t:null,[t]),ge=!!se,Ee=!(r&&q!=="user"),{uploadingFiles:Y,handleFileClick:U,fileViewerOpen:Z,currentFileInfo:$,closeFileViewer:K}=WS({allowFileOpen:Ee,currentThreadId:V}),Q=w.useMemo(()=>{switch(q){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))]"}},[q]),ce=w.useMemo(()=>{if(se)return"";const _=t.content;return Array.isArray(_)?V0(_):""},[se,t]),oe=w.useMemo(()=>{if(se)return{};const _=t.content;return Array.isArray(_)?bf(t):{}},[se,t]),Ne=w.useMemo(()=>{if(se)return[];const _=t.content;return Array.isArray(_)?_.filter(X=>X.type==="image_url"):[]},[se,t]),Ue=w.useMemo(()=>{if(se)return[];const _=t.content;return Array.isArray(_)?_.filter(X=>X.type==="file"):[]},[se,t]),re=w.useMemo(()=>{if(se)return[];const _=t.content;return Array.isArray(_)?_.filter(X=>X.type==="interrupt"):[]},[se,t]),xe=(b==null?void 0:b.id)??(b==null?void 0:b.interrupt_id),Pe=Ts(xe),Ze=b==null?void 0:b.value,Qe=w.useMemo(()=>{if(se)return"";const _=t.content;return Array.isArray(_)?K0(_):""},[se,t]),Ve=w.useMemo(()=>{if(se||!h)return[];const X=t.artifact;if(!X)return[];const te=[],pe=[...Array.isArray(X.plots)?X.plots:[]];for(const ve of pe){const we=J0(ve);we&&te.push(we)}return te},[se,t,h]),tt=w.useCallback(async()=>{const _=J?Qe:ce;async function X(te){if(navigator.clipboard&&typeof navigator.clipboard.writeText=="function"){await navigator.clipboard.writeText(te);return}if(navigator.clipboard&&typeof navigator.clipboard.write=="function"&&typeof ClipboardItem<"u"){const pe=new Blob([te],{type:"text/plain"});await navigator.clipboard.write([new ClipboardItem({"text/plain":pe})]);return}throw new Error("Clipboard API not supported in this context.")}try{await X(_),D(!0),setTimeout(()=>D(!1),2e3),g==null||g(_)}catch(te){console.error("Failed to copy:",te)}},[J,Qe,ce,g]),it=w.useCallback(()=>{if(!x)return;const _=J?Qe:ce,X="type"in t&&t.type==="default_message"?void 0:{checkpointId:t.checkpointId??null,checkpointNs:t.checkpointNs??null};x(t.id,_,X)},[x,t.id,J,Qe,ce,t]),qe=w.useCallback(()=>{m==null||m(n)},[m,n]),nt=w.useCallback(()=>{const X=ne(M?"h-3 w-3":"h-4 w-4","opacity-60 flex-shrink-0",Q);switch(q){case"user":return u.jsx(ae.User,{className:X});case"assistant":return u.jsx(ae.Bot,{className:X});case"tool":return u.jsx(ae.Wrench,{className:X});default:return u.jsx(ae.Bot,{className:X})}},[M,Q,q]),at=w.useCallback(()=>{const _="group relative mb-4 flex w-full";switch(q){case"user":return ne(_,"justify-end");case"assistant":case"tool":case"system":return ne(_,"justify-start");default:return _}},[q]),Rt=w.useCallback(()=>{const _=ne("rounded-lg px-4 py-3 relative min-w-0 max-w-full break-words",M&&"px-3 py-2 text-sm");if(ge)return ne(_,"w-full","bg-[hsl(var(--chat-bubble-ai))] text-[hsl(var(--chat-bubble-ai-text))]","border border-border/60 dark:border-border/40 shadow-sm");switch(q){case"user":return ne(_,"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 ne(_,"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 ne(_,"w-full md:max-w-[95%] bg-secondary/50 text-secondary-foreground border border-dashed");case"system":return ne(_,"w-full md:max-w-[85%] bg-accent/40 text-muted-foreground border");default:return ne(_,"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")}},[M,ge,q]),gt=w.useCallback(async _=>{if(S)return;const X=Ts((_==null?void 0:_.id)??(_==null?void 0:_.interrupt_id));if(!X){console.warn("Interrupt part missing id",_);return}try{k==null||k(),await z(X,!0)}catch(te){console.error("Failed to approve interrupt:",te)}finally{C==null||C()}},[S,C,k,z]),ht=w.useCallback(async _=>{if(S)return;const X=Ts((_==null?void 0:_.id)??(_==null?void 0:_.interrupt_id));if(!X){console.warn("Interrupt part missing id",_);return}try{k==null||k(),await z(X,!1)}catch(te){console.error("Failed to reject interrupt:",te)}finally{C==null||C()}},[S,C,k,z]),bt=w.useCallback(({part:_,i:X})=>{if(_.type==="text"){const te=_.text??"",pe=te.trim(),ve=Sa(pe);return ve&&q!=="tool"?u.jsx(ap,{data:ve},X):q==="user"&&c&&pe.length>d?u.jsx(VS,{text:pe,expanded:B,onExpandedChange:j,previewLength:d,isCompact:M},X):u.jsx(so,{content:te,allowHtml:!1},X)}if(_.type==="image_url"){const te=_;return u.jsx("div",{className:"my-2",children:u.jsx("img",{src:te.url,alt:te.alt??"",loading:"lazy",className:"border rounded max-h-[420px] w-auto object-contain"})},X)}if(_.type==="file"){const te=_,pe=te.name||"file";return u.jsxs("a",{href:te.url,onClick:ve=>U(ve.nativeEvent,te,X),className:`inline-flex items-center gap-2 rounded px-2 py-1 text-xs bg-gray-100 border hover:bg-gray-200
|
|
137
|
+
dark:bg-background/10 dark:border-border/30 dark:hover:bg-background/20`,children:[Y[X]?u.jsx(ae.Loader,{className:"h-4 w-4 animate-spin"}):null,u.jsxs("span",{className:"truncate max-w-[180px]",children:[pe,Y[X]?" (processing)":""]})]},X)}if(_.type==="interrupt"){const te=_,pe=Ts((te==null?void 0:te.id)??(te==null?void 0:te.interrupt_id)),ve=!!(Pe&&pe&&pe===Pe),we=ve?Ze??(te==null?void 0:te.value):te==null?void 0:te.value,Fe=pe?{...te,id:pe,interrupt_id:pe}:te;return u.jsx(HS,{interruptPart:Fe,onApprove:gt,onReject:ht,disabled:S,isActive:ve,payload:we},X)}return null},[U,Y,gt,ht,q,c,d,B,M,Pe,Ze,b,S,re]),St=w.useCallback(()=>u.jsxs("div",{className:"flex items-center gap-2 p-2 bg-muted/30 rounded",children:[u.jsx(ae.Paperclip,{className:"h-4 w-4 text-muted-foreground"}),u.jsx("span",{className:"text-sm text-muted-foreground",children:"File upload"})]}),[]),Lt=w.useCallback(()=>{const _=ce.trim().length>0||Ne.length>0||Ue.length>0||re.length>0;if(!J&&Ue.length>0&&!r)return St();if(!J&&!_&&!r)return null;if(J)return!f&&Ve.length>0?null:f?u.jsx(KS,{message:t,viewMode:F},t.id):null;if(!J&&!se){const X=t,te=u.jsx("div",{className:"space-y-2",children:X.content.map((pe,ve)=>u.jsx(bt,{part:pe,i:ve},ve))});return r?u.jsxs("div",{"aria-busy":"true",role:"status",children:[te,u.jsx(qS,{className:Q})]}):te}},[ce,Ne.length,Ue.length,re.length,r,J,F,f,Ve.length,St,Q]),Mt=w.useMemo(()=>se?"Assistant":q0(t),[se,t]),et=w.useMemo(()=>se?[]:Array.isArray(T)?T:[],[T,se]),It=w.useMemo(()=>{var _;return et.length?R&&et.some(X=>X.id===R)?R:((_=et[0])==null?void 0:_.id)??null:null},[R,et]),Ge=w.useMemo(()=>!et.length||!I?null:et.some(_=>_.id===I)?I:null,[I,et])??It,Ye=q==="user"&&et.length>0&&typeof A=="function",pt=w.useCallback((_,X=!1)=>{if(!A)return;const te=(_==null?void 0:_.id)??null,pe=(_==null?void 0:_.parentId)??L??null;A(te,pe,X)},[L,A]),lt=w.useMemo(()=>Ge?et.findIndex(_=>_.id===Ge):-1,[Ge,et]),G=w.useMemo(()=>lt<0?null:et[lt]??null,[lt,et]);return J&&!f&&Ve.length===0?null:ge&&se?u.jsx("div",{className:ne(at(),p.container),children:u.jsxs("div",{className:ne(Rt(),p.content),children:[u.jsxs("div",{className:"flex items-center gap-2 mb-2 pb-2 border-b border-current/10",children:[u.jsx(ae.Bot,{className:ne("h-4 w-4",Q)}),a&&u.jsx("span",{className:"font-medium text-sm",children:"Assistant"})]}),u.jsx(so,{content:se.content,className:"text-current"})]})}):u.jsxs(u.Fragment,{children:[u.jsx("div",{className:ne(at(),p.container),children:u.jsxs("div",{className:ne(Rt(),p.content),children:[(i||a||J)&&u.jsxs("div",{className:ne("flex items-center justify-between mb-2 pb-2 border-b border-current/10",M&&"mb-1 pb-1",Q,p.header),children:[u.jsxs("div",{className:"flex items-center gap-2",children:[nt(),a&&Mt&&u.jsx("span",{className:ne("font-medium",M?"text-xs":"text-sm"),children:Mt}),J&&u.jsxs(yf,{variant:"outline",className:ne("text-xs flex items-center gap-1 cursor-pointer select-none",Q,"border border-current/40",M&&"text-xs h-4"),role:"button",tabIndex:0,"aria-expanded":F==="expanded",onClick:()=>N(_=>_==="expanded"?"preview":"expanded"),onKeyDown:_=>{(_.key==="Enter"||_.key===" ")&&(_.preventDefault(),N(X=>X==="expanded"?"preview":"expanded"))},children:[u.jsx("span",{children:oe.name??"Tool Output"}),oe.toolCallId&&u.jsx("span",{className:"opacity-70",children:oe.toolCallId.slice(0,8)}),F==="expanded"?u.jsx(ae.ChevronUp,{className:"h-3 w-3"}):u.jsx(ae.ChevronDown,{className:"h-3 w-3"})]})]}),u.jsxs("div",{className:"flex items-center gap-2",children:[Ye&&G&<>=0&&u.jsx("div",{className:"flex flex-wrap items-center gap-2 text-xs",children:u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx("button",{type:"button",className:ne("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",lt<et.length-1?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(lt>=et.length-1)return;const _=et[lt+1];_&&pt(_)},"aria-label":"Older checkpoint (back in time)",disabled:lt>=et.length-1,children:u.jsx(ae.ChevronLeft,{className:"h-3 w-3"})}),u.jsx("div",{className:"flex items-center gap-2",children:u.jsxs("span",{className:"whitespace-nowrap",children:[et.length-lt," / ",et.length]})}),u.jsx("button",{type:"button",className:ne("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",lt>0?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(!(lt<=0))if(lt===1)pt(null,!0);else{const _=et[lt-1];_&&pt(_,!1)}},"aria-label":"Newer checkpoint (forward in time)",disabled:lt<=0,children:u.jsx(ae.ChevronRight,{className:"h-3 w-3"})})]})}),i&&t.createdAt&&u.jsx("time",{className:ne("text-xs opacity-60",Q,M&&"text-xs"),dateTime:new Date(t.createdAt).toISOString(),title:new Date(t.createdAt).toLocaleString(),children:new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit"}).format(new Date(t.createdAt))}),s&&!o&&u.jsxs("div",{className:ne("opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",p.actions),children:[u.jsx("div",{className:"relative",children:u.jsx(Xe,{variant:"ghost",size:"sm",onClick:()=>tt(),className:ne("h-6 w-6 p-0 hover:bg-foreground/10",Q,M&&"h-5 w-5"),"aria-label":"Copy message",title:"Copy message",children:u.jsx(ae.Copy,{className:ne(P?"text-success":Q,M?"h-3 w-3":"h-4 w-4")})})}),q==="user"&&x&&u.jsx(Xe,{variant:"ghost",size:"sm",onClick:it,className:ne("h-6 w-6 p-0 hover:bg-foreground/10",Q,M&&"h-5 w-5"),"aria-label":"Edit message",children:u.jsx(ae.Edit,{className:ne(Q,M?"h-3 w-3":"h-4 w-4")})}),q==="assistant"&&m&&u.jsx(Xe,{variant:"ghost",size:"sm",onClick:qe,className:ne("h-6 w-6 p-0 hover:bg-foreground/10",Q,M&&"h-5 w-5"),"aria-label":"Regenerate response",children:u.jsx(ae.RotateCcw,{className:ne(Q,M?"h-3 w-3":"h-4 w-4")})})]})]})]}),u.jsxs("div",{className:"relative",children:[Lt(),h&&Ve.length>0&&u.jsx("div",{className:"mt-3 space-y-4",children:Ve.map((_,X)=>u.jsx(zS,{preview:_,idx:X},`artifact-${X}`))})]}),J&&F==="expanded"&&(oe.toolCallId||oe.name)&&u.jsxs("div",{className:ne("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",M&&"text-xs"),children:[oe.name&&u.jsxs("div",{children:["Function: ",oe.name]}),oe.toolCallId&&u.jsxs("div",{children:["Call ID: ",oe.toolCallId]})]}),!(i||a||J)&&s&&!o&&u.jsxs("div",{className:ne("absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",p.actions),children:[u.jsx(Xe,{variant:"ghost",size:"sm",onClick:()=>tt(),className:ne("h-6 w-6 p-0 hover:bg-background/50 text-current",M&&"h-5 w-5"),children:u.jsx(ae.Copy,{className:ne(P?"text-success":"text-current",M?"h-3 w-3":"h-4 w-4")})}),q==="user"&&x&&u.jsx(Xe,{variant:"ghost",size:"sm",onClick:it,className:ne("h-6 w-6 p-0 hover:bg-background/50 text-current",M&&"h-5 w-5"),children:u.jsx(ae.Edit,{className:ne("text-current",M?"h-3 w-3":"h-4 w-4")})}),q==="assistant"&&m&&u.jsx(Xe,{variant:"ghost",size:"sm",onClick:qe,className:ne("h-6 w-6 p-0 hover:bg-background/50 text-current",M&&"h-5 w-5"),children:u.jsx(ae.RotateCcw,{className:ne("text-current",M?"h-3 w-3":"h-4 w-4")})})]})]})}),$&&u.jsx(yS,{isOpen:Z,onClose:K,fileId:$.id,fileName:$.name,mimeType:$.mimeType})]})},(e,t)=>{var i,a,l,c,d,f,h,p;if(t.isStreamingMessage||e.isStreamingMessage||!(e.message.id===t.message.id&&wf(e.message)===wf(t.message)))return!1;const o=["isEditing","showActions","layoutSize","showTimestamp","showAgentName","truncateUserMessages","userMessagePreviewLength","showToolMessages","attemptMeta"].every(x=>e[x]===t[x]),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)===((c=t.customStyles)==null?void 0:c.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});Ds.displayName="MessageComponent";function GS(e,t){return w.useMemo(()=>{var d,f,h,p,x;const n=e&&"type"in e&&e.type==="default_message";let r=[],o=null,s={},i={},a=null,l=null,c=null;if(!n&&e){const m=e,y=m.checkpointId??null;s=m.additionalKwargs??{},i=m.responseMetadata??{};const g=y&&t.checkpointMetaById?t.checkpointMetaById.get(y)??null:null;a=typeof s.step=="number"?s.step:typeof i.step=="number"?i.step:(g==null?void 0:g.step)??null;const b=typeof s.source=="string"?s.source:typeof i.source=="string"?i.source:(g==null?void 0:g.source)??null;l=b?String(b):null;const S=a!==null&&l?`${a}:${l}`:null;if(S&&((d=t.checkpointIndexByKey)!=null&&d.has(S))?r=t.checkpointIndexByKey.get(S)??[]:y&&g&&(r=[g]),o=y??((f=r[0])==null?void 0:f.id)??null,c=y?((h=t.attemptMetaById)==null?void 0:h.get(y))??null:null,!c&&(e==null?void 0:e.role)==="user"&&(e!=null&&e.id)&&t.userMessageIdToAttempts){const k=t.userMessageIdToAttempts.get(e.id);if(k&&k.length>0){const C=k[0].checkpointId;c=((p=t.attemptMetaById)==null?void 0:p.get(C))??null,c&&console.log(`[useMessageMetadata] Found attempt by user message ID "${e.id}":`,k.length,"versions")}}if(!c&&r.length>0&&t.attemptMetaById){const k=t.attemptMetaById.get(r[0].id);k&&(c=k)}if(c&&c.attemptCount>1&&t.attemptMetaById){const k=c.baseUserMessageId;if(k){const C=[];for(const[T,I]of t.attemptMetaById.entries())if(I.baseUserMessageId===k){const A=(x=t.checkpointMetaById)==null?void 0:x.get(T);A&&C.push(A)}C.length>0&&(r=C)}}if(c&&c.attemptCount>1&&t.checkpointMetaById&&t.attemptMetaById){const k=[];for(const[C,T]of t.checkpointMetaById.entries()){const I=t.attemptMetaById.get(C);I&&I.attemptCount===c.attemptCount&&I.baseUserMessageId===c.baseUserMessageId&&k.push(T)}k.sort((C,T)=>{const I=C.createdAt?Date.parse(C.createdAt):0;return(T.createdAt?Date.parse(T.createdAt):0)-I}),k.length>0&&(r=k,console.log("[useMessageMetadata] Populated checkpointCandidates with all attempts:",{messageId:e.id,attemptCount:c.attemptCount,candidateIds:r.map(C=>C.id)}))}}return{checkpointCandidates:r,defaultCheckpointId:o,attemptMeta:c,resolvedStep:a,resolvedSource:l}},[e,t.checkpointMetaById,t.checkpointIndexByKey,t.attemptMetaById,t.userMessageIdToAttempts])}const up=(e,t)=>(e==null?void 0:e.id)??`message-${t}`,dp=w.memo(function({message:t,index:n,isStreaming:r,streamingAssistantId:o,streamingDebounceMs:s,layoutSize:i,enableMessageEditing:a,editingMessageId:l,onEdit:c,onRegenerate:d,onCancelEdit:f,activeInterrupt:h,disableInterruptActions:p,onInterruptActionStart:x,onInterruptActionEnd:m,showToolMessages:y,showArtifactPreviews:g,checkpointMetaById:b,checkpointIndexByKey:S,attemptMetaById:k,userMessageIdToAttempts:C,activeCheckpointId:T,onSelectCheckpoint:I}){const A=up(t,n),R="type"in t&&t.type==="default_message",{checkpointCandidates:L,defaultCheckpointId:P,attemptMeta:D}=GS(t,{checkpointMetaById:b,checkpointIndexByKey:S,attemptMetaById:k,userMessageIdToAttempts:C}),F=t&&!R?t.additionalKwargs??{}:{},N=t&&!R?t.responseMetadata??{}:{},B=(()=>{if(typeof F.parentCheckpointId=="string")return F.parentCheckpointId;if(typeof N.parentCheckpointId=="string")return N.parentCheckpointId})();return u.jsx("div",{className:"relative mb-4 last:mb-0","data-message-id":A,style:{minHeight:"60px",containIntrinsicSize:"auto 120px"},children:u.jsx(Ds,{message:t,messageIndex:n,isStreamingMessage:r&&o===t.id,streamingDebounceMs:s,isEditing:l===t.id,showActions:a,showTimestamp:!1,showAgentName:!0,layoutSize:i,onEdit:c,onRegenerate:()=>d(n),onCancelEdit:f,activeInterrupt:h,disableInterruptActions:p,onInterruptActionStart:x,onInterruptActionEnd:m,showToolMessages:y,showArtifactPreviews:g,checkpointCandidates:L,activeCheckpointId:T??null,onSelectCheckpoint:I,defaultCheckpointId:P,messageParentCheckpointId:B,attemptMeta:D})})});dp.displayName="MessageRow";const ja=w.forwardRef(({messages:e,isStreaming:t,streamingAssistantId:n,streamingDebounceMs:r,layoutSize:o,enableMessageEditing:s,editingMessageId:i,onStartReached:a,onEdit:l,onRegenerate:c,onCancelEdit:d,className:f,style:h,emptyMessage:p,followNewMessages:x=!0,isNavigatingCheckpoint:m=!1,onScrollAway:y,onAtBottom:g,activeInterrupt:b,disableInterruptActions:S=!1,onInterruptActionStart:k,onInterruptActionEnd:C,showToolMessages:T=!0,showArtifactPreviews:I=!0,checkpointMetaById:A,checkpointIndexByKey:R,attemptMetaById:L,userMessageIdToAttempts:P,activeCheckpointId:D,onSelectCheckpoint:F,createSyntheticThinkingMessage:N=!1},B)=>{const j=w.useRef(null),V=w.useRef(null),z=w.useRef(!1),M=w.useRef(!1),[q,J]=w.useState(!0),se=w.useMemo(()=>b?e.some(re=>"type"in re&&re.type==="default_message"?!1:Array.isArray(re==null?void 0:re.content)&&re.content.some(xe=>xe&&xe.type==="interrupt"&&(xe.id??xe.interrupt_id)===b.id)):!1,[b,e]),ge=w.useMemo(()=>{if(!b||se)return null;const re=b.id&&String(b.id).trim()?String(b.id).trim():"pending-interrupt";let xe;const Pe=b.value;if(Pe&&typeof Pe=="object"&&!Array.isArray(Pe)){const Ze=Pe.title;typeof Ze=="string"&&Ze.trim()&&(xe=Ze.trim())}return{id:`interrupt-${re}`,role:"system",createdAt:new Date().toISOString(),content:[{type:"interrupt",id:re,value:Pe,title:xe}]}},[b,se]),Ee=w.useMemo(()=>ge?[...e,ge]:e,[e,ge]),Y=w.useMemo(()=>!N||!t?Ee:!Ee.some(xe=>xe.role==="assistant")&&Ee.length>0?[...Ee,{id:"thinking-assistant",role:"assistant",content:[],createdAt:new Date().toISOString()}]:Ee,[Ee,t,N]),U=w.useMemo(()=>T?Y:Y.filter(re=>(re==null?void 0:re.role)!=="tool"),[Y,T]),Z=w.useCallback(re=>{J(re),y&&y(!re),g&&g(re)},[y,g]),$=w.useMemo(()=>{if(a)return async()=>{if(!z.current){z.current=!0;try{await a()}finally{z.current=!1}}}},[a]),K=w.useMemo(()=>!x||m?!1:q?"auto":!1,[q,x,m]),Q=w.useMemo(()=>{if(typeof p!="string")return null;const re=p.trim();return re?{id:"default-message",role:"assistant",type:"default_message",content:re,createdAt:new Date().toISOString()}:null},[p]),ce=["flex h-full flex-col md:flex-row",f].filter(Boolean).join(" "),oe=()=>Q?u.jsx("div",{className:"p-6 h-full overflow-y-auto",children:u.jsx("div",{className:"w-full max-w-full",children:u.jsx(Ds,{message:Q,messageIndex:0,isStreamingMessage:!1,showActions:!1,showTimestamp:!1,showAgentName:!0,layoutSize:o,onEdit:()=>{},onRegenerate:()=>{},onCancelEdit:()=>{},showArtifactPreviews:I})})}):u.jsx("div",{className:"flex h-full items-center justify-center py-8 text-center text-muted-foreground",children:p??"No messages yet. Start a conversation!"}),Ne=U.length,Ue=Ne>0;return w.useEffect(()=>{var re,xe;if(Ne===0){M.current=!1;return}M.current||(M.current=!0,j.current?(xe=(re=j.current).scrollToIndex)==null||xe.call(re,{index:0,align:"start",behavior:"auto"}):V.current&&(V.current.scrollTop=0))},[Ne]),w.useImperativeHandle(B,()=>({scrollToLatest:()=>{var re,xe;if(j.current&&U.length>0){const Pe=U.length-1;(xe=(re=j.current).scrollToIndex)==null||xe.call(re,{index:Pe,align:"end",behavior:"auto"})}else V.current&&(V.current.scrollTop=V.current.scrollHeight)},scrollToTop:()=>{var re,xe;j.current&&U.length>0?(xe=(re=j.current).scrollToIndex)==null||xe.call(re,{index:0,align:"start",behavior:"auto"}):V.current&&(V.current.scrollTop=0)}}),[U]),u.jsx("div",{className:ce,style:h,children:u.jsx("div",{className:"relative flex-1 min-h-0",children:Ue?u.jsx(E0,{ref:re=>{j.current=re},scrollerRef:re=>{V.current=re instanceof HTMLDivElement?re:null},data:U,followOutput:K,overscan:200,increaseViewportBy:{top:100,bottom:200},defaultItemHeight:80,atBottomThreshold:50,startReached:()=>{$&&$()},atBottomStateChange:Z,style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:(re,xe)=>up(xe,re),itemContent:(re,xe)=>u.jsx(dp,{message:xe,index:re,isStreaming:t,streamingAssistantId:n,streamingDebounceMs:r,layoutSize:o,enableMessageEditing:s,editingMessageId:i,onEdit:l,onRegenerate:c,onCancelEdit:d,activeInterrupt:b,disableInterruptActions:S,onInterruptActionStart:k,onInterruptActionEnd:C,showToolMessages:T,showArtifactPreviews:I,checkpointMetaById:A,checkpointIndexByKey:R,attemptMetaById:L,userMessageIdToAttempts:P,activeCheckpointId:D,onSelectCheckpoint:F})}):oe()})})});ja.displayName="MessageList";const fp={value:""};function Ls({className:e="",placeholder:t="Type your message...",autoFocus:n=!0,maxHeight:r=void 0,streamingDebounceMs:o=500,streamingThrottleMs:s,followNewMessages:i=!0,enableFileUpload:a=!0,enableExcelUpload:l=!1,enableMessageEditing:c=!0,showToolMessages:d=!0,showArtifactPreviews:f=!0,customStyles:h={},onMessageSent:p,onExcelUploadSuccess:x,onError:m}){const{api:y}=ui(),{currentThreadId:g}=_o(),{threadId:b,messages:S,isHistoryLoading:k,isLoading:C,navigateToCheckpoint:T,returnToLatest:I,checkpoint:A,checkpoints:R,interrupt:L,metadata:P,timelineCheckpoints:D,messagePreviews:F}=jo(),{isStreaming:N,error:B,connectionState:j,submit:V,stop:z}=ac(),M=b??g??null,q=(A==null?void 0:A.id)??null,J=(A==null?void 0:A.namespace)??null,se=(P==null?void 0:P.assemblingMessageId)??null,ge=L,[Ee,Y]=w.useState(!1);w.useEffect(()=>{ge||Y(!1)},[ge]);const U=w.useCallback(()=>{Y(!0)},[]),Z=w.useCallback(()=>{Y(!1)},[]),$=!!ge||Ee,[K,Q]=w.useState(null),[ce,oe]=w.useState(""),[Ne,Ue]=w.useState(null),[re,xe]=w.useState(null),[Pe,Ze]=w.useState([]),[Qe,Ve]=w.useState(0),[tt,it]=w.useState(0),[qe,nt]=w.useState(!1),[at,Rt]=w.useState(null),[gt,ht]=w.useState(null),[bt,St]=w.useState(!1),[Lt,Mt]=w.useState(null),et=w.useRef(!1),[It,bn]=w.useState(()=>fp.value),Ge=w.useRef(It),Ye=w.useRef(null),pt=w.useCallback(fe=>{fp.value=fe,bn(fe)},[]),[lt,G]=w.useState(!1),_=w.useRef(null),{checkpointMetaById:X,checkpointIndexByKey:te,attemptMetaById:pe,userMessageIdToAttempts:ve}=hw(R),we=D??[],Fe=w.useRef(null),Oe=w.useRef(null),je=w.useCallback(()=>{Fe.current&&(Fe.current.value=""),Oe.current&&(Oe.current.value=""),Ve(fe=>fe+1),it(fe=>fe+1)},[]),Vt=w.useCallback(fe=>{pt(fe)},[pt]),En=w.useRef(!1);w.useEffect(()=>{En.current&&!N&&(Ze([]),je()),En.current=N},[N,je]);const[ir,Ar]=w.useState("desktop");w.useEffect(()=>{const fe=()=>{const Se=window.innerWidth;Ar(Se<640?"phone":Se<1024?"tablet":"desktop")};return fe(),window.addEventListener("resize",fe),()=>window.removeEventListener("resize",fe)},[]),w.useEffect(()=>{et.current=!1},[M]),w.useEffect(()=>{Ge.current=It},[It]),w.useEffect(()=>{if(!K){Ye.current=null;return}Ye.current===null&&(Ye.current=Ge.current),pt(ce??"")},[ce,K,pt]),w.useEffect(()=>{(async()=>{if(!y.baseUrl){Mt(null);return}try{const Ie=(await y.getAgent("default")).uiDefaultMessage||"";Mt(Ie||null)}catch(Se){console.warn("Failed to fetch default message:",Se),Mt(null)}})()},[y.baseUrl]),w.useEffect(()=>{B&&!bt&&(m==null||m(B))},[B,bt,m]);const fo=fe=>{if(fe.length>cs)return`Message too long (${fe.length}/${cs} characters)`;try{return xw(fe),null}catch(Se){return(Se==null?void 0:Se.message)||"Invalid message"}},zn=async fe=>{const Se=fe.trim();if(!(!Se&&Pe.length===0)){if(Se){const Ie=fo(Se);if(Ie){xe(Ie);return}}try{const Ie=K?(Ne==null?void 0:Ne.checkpointId)??q??void 0:q??void 0,He=K?(Ne==null?void 0:Ne.checkpointNs)??J??void 0:J??void 0;await V({text:Se||"",attachments:Pe},{checkpointId:Ie,checkpointNs:He,edit:!!K,originalMessageId:K??void 0}),p==null||p(Se),pt(""),xe(null),Ze([]),je(),Q(null),oe(""),Ue(null)}catch(Ie){const He=(Ie==null?void 0:Ie.message)||"Failed to send message";xe(He),m==null||m(He)}}},ar=w.useCallback((fe,Se,Ie)=>{c&&(Ye.current=It,Q(fe),oe(Se),pt(Se),xe(null),Ue({checkpointId:(Ie==null?void 0:Ie.checkpointId)??null,checkpointNs:(Ie==null?void 0:Ie.checkpointNs)??null}))},[It,c,pt]),E=w.useCallback(()=>{Q(null),oe(""),Ue(null),xe(null),pt(Ye.current??It),Ye.current=null},[It,pt]),W=w.useCallback((fe,Se,Ie)=>{ar(fe,Se,Ie)},[ar]),ie=w.useCallback(fe=>{let Se=null;for(let tn=fe-1;tn>=0;tn--)if(S[tn].role==="user"){Se=S[tn];break}if(!Se)return;const Ie=Array.isArray(Se.content)?Se.content:[],Un=Ie.filter(tn=>(tn==null?void 0:tn.type)==="text").map(tn=>tn.text).join("")||(()=>{try{return JSON.stringify(Ie,null,2)}catch{return String(Ie)}})();Un&&V({text:Un},{checkpointId:q??void 0,checkpointNs:J??void 0,edit:!0,originalMessageId:Se.id})},[S,V,q,J]),be=fe=>{const Se=Array.from(fe.target.files||[]);Ze(Ie=>[...Ie,...Se]),fe.target.value=""},Ke=fe=>{Ze(Se=>{const Ie=Se.filter((He,Un)=>fe!==Un);return Ie.length===0&&je(),Ie})},rt=async fe=>{const Se=(fe.target.files||[])[0];if(Se){Rt(null),ht(null),nt(!0);try{await V({attachments:[Se]},{checkpointId:q??void 0,checkpointNs:J??void 0});const Ie=`Uploaded ${Se.name} - processing through chat stream`;ht(Ie)}catch(Ie){const He=Ie instanceof Error?Ie.message:"Failed to upload Excel file";console.error("Excel upload failed",Ie),Rt(He),m==null||m(He)}finally{nt(!1),fe.target.value="",je()}}},$e=async fe=>{if(g){G(!0);try{if(!fe){await I(),requestAnimationFrame(()=>{var He;(He=_.current)==null||He.scrollToLatest()});return}const Se=R.find(He=>He.checkpointId===fe),Ie=(Se==null?void 0:Se.checkpointNs)??null;await T(fe,Ie),requestAnimationFrame(()=>{var He;(He=_.current)==null||He.scrollToTop()})}finally{G(!1)}}},Le=w.useCallback(async(fe,Se,Ie)=>{await $e(Ie?null:fe)},[$e]),Et=`flex flex-1 w-full flex-col min-h-0 min-w-0 max-h-full overflow-hidden bg-transparent ${e} ${h.container||""}`,mt=`flex-1 min-h-0 min-w-0 max-h-full w-full overflow-hidden overscroll-contain break-words break-anywhere p-4 bg-transparent ${h.messagesArea||""}`,xt=`relative flex-shrink-0 w-full border-t p-4 bg-transparent ${h.inputArea||""}`;return u.jsxs("div",{className:Et,children:[!!B&&!bt&&u.jsxs("div",{className:"flex-shrink-0 bg-red-50 border border-red-200 text-red-800 px-4 py-2 text-sm flex items-center justify-between",children:[u.jsx("span",{children:B}),u.jsx(Xe,{variant:"ghost",size:"sm",onClick:()=>St(!0),className:"text-red-800 hover:bg-red-100","aria-label":"Dismiss error",children:u.jsx(ae.X,{size:16})})]}),u.jsxs("div",{className:`relative ${mt}`,style:r?{maxHeight:r}:void 0,children:[u.jsx(ja,{ref:_,className:"h-full",style:{height:"100%"},messages:S,isStreaming:N,streamingAssistantId:se,streamingDebounceMs:typeof s=="number"?s:o,followNewMessages:i,layoutSize:ir,enableMessageEditing:c,editingMessageId:K,onEdit:W,onRegenerate:ie,onCancelEdit:E,emptyMessage:Lt??void 0,isNavigatingCheckpoint:lt,activeInterrupt:ge,disableInterruptActions:Ee,onInterruptActionStart:U,onInterruptActionEnd:Z,showToolMessages:d,showArtifactPreviews:f,checkpointMetaById:X,checkpointIndexByKey:te,attemptMetaById:pe,userMessageIdToAttempts:ve,activeCheckpointId:q,onSelectCheckpoint:Le,timelineCheckpoints:we,messagePreviews:F}),(j==="reconnecting"||j==="connecting")&&u.jsx("div",{className:"pointer-events-none absolute top-3 right-3 z-20 rounded-full bg-muted/80 px-3 py-1 text-xs font-medium text-foreground shadow-sm backdrop-blur-sm dark:bg-muted/60",children:u.jsxs("span",{className:"flex items-center gap-2",children:[u.jsx(ae.Loader2,{className:"h-3 w-3 animate-spin"}),j==="reconnecting"?"Reconnecting…":"Connecting…"]})}),j==="error"&&u.jsx("div",{className:"pointer-events-none absolute top-3 right-3 z-20 rounded-full bg-destructive/10 px-3 py-1 text-xs font-semibold text-destructive shadow-sm",children:"Connection lost"}),C&&u.jsxs("div",{className:"absolute inset-0 z-10 flex flex-col items-center justify-center gap-2 bg-background/80 backdrop-blur-sm text-muted-foreground",children:[u.jsx(ae.Loader2,{className:"h-6 w-6 animate-spin"}),u.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:"Loading messages…"})]}),(k||lt)&&u.jsxs("div",{className:"absolute inset-0 z-10 flex flex-col items-center justify-center gap-2 bg-background/80 backdrop-blur-sm text-muted-foreground",children:[u.jsx(ae.Loader2,{className:"h-6 w-6 animate-spin"}),u.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:"Loading checkpoint…"})]})]}),u.jsxs("div",{className:xt,children:[K&&u.jsx("div",{className:"mb-3 p-3 bg-blue-50 border border-blue-200 rounded-lg",children:u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx(ae.Edit3,{size:16,className:"text-blue-600"}),u.jsx("span",{className:"text-sm font-medium text-blue-800",children:"Editing message"})]}),u.jsx(Xe,{variant:"ghost",size:"sm",onClick:E,className:"text-blue-600 hover:bg-blue-100",children:u.jsx(ae.X,{size:16})})]})}),(a||l)&&u.jsxs("div",{className:"mb-3 space-y-3",children:[a&&u.jsxs(u.Fragment,{children:[u.jsx("input",{ref:Fe,type:"file",multiple:!0,onChange:fe=>be(fe),className:"hidden"},Qe),Pe.length>0&&u.jsx("div",{className:"flex flex-wrap gap-2",children:Pe.map((fe,Se)=>u.jsxs("div",{className:"flex items-center gap-2 bg-gray-100 dark:bg-gray-800 rounded-lg px-3 py-2 text-sm text-gray-900 dark:text-gray-100",children:[u.jsx(ae.Paperclip,{size:14}),u.jsx("span",{className:"truncate max-w-[150px]",children:fe.name}),u.jsx(Xe,{variant:"ghost",size:"sm",onClick:()=>Ke(Se),className:"h-4 w-4 p-0 text-gray-500 dark:text-gray-400 hover:text-red-500 dark:hover:text-red-400","aria-label":`Remove ${fe.name}`,children:u.jsx(ae.X,{size:12})})]},Se))})]}),l&&u.jsxs(u.Fragment,{children:[u.jsx("input",{ref:Oe,type:"file",accept:".xls,.xlsx,.xlsm",onChange:rt,className:"hidden"},tt),qe&&u.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[u.jsx(ae.Loader2,{className:"h-4 w-4 animate-spin"})," Uploading Excel file..."]}),gt&&!qe&&u.jsx("div",{className:"text-sm rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-emerald-700",children:gt}),at&&!qe&&u.jsx("div",{className:"text-sm rounded border border-red-200 bg-red-50 px-3 py-2 text-red-600",children:at})]})]}),re&&u.jsx("div",{className:"mb-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2",children:re}),u.jsxs("div",{className:"flex items-end gap-2",children:[(a||l)&&u.jsxs(ew,{children:[u.jsx(tw,{asChild:!0,children:u.jsx(Xe,{type:"button",size:"icon",variant:"outline",disabled:N||$,title:"More input actions",className:h.moreButton||"",children:u.jsx(ae.Plus,{size:16})})}),u.jsxs(yd,{align:"start",sideOffset:6,className:"w-52",children:[a&&u.jsxs(Zi,{onClick:()=>{var fe;return(fe=Fe.current)==null?void 0:fe.click()},className:"cursor-pointer",children:[u.jsx(ae.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]}),l&&u.jsxs(Zi,{onClick:()=>{var fe;qe||(fe=Oe.current)==null||fe.click()},className:`cursor-pointer ${qe?"opacity-60 pointer-events-none":""}`,children:[u.jsx(ae.FileSpreadsheet,{className:"h-4 w-4 mr-2"})," Upload Excel file"]})]})]}),u.jsx("div",{className:"flex-1",children:u.jsx(tx,{initialValue:ce,editingMessageId:K,value:It,onValueChange:Vt,placeholder:K?"Edit your message...":t,isStreaming:N,disabled:$,maxLength:cs,onSend:zn,onCancelEdit:E,onStop:z,allowEmptySend:Pe.length>0,textareaClassName:`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${K?"border-blue-400 bg-blue-50 text-blue-900 dark:border-blue-500 dark:bg-blue-950/60 dark:text-blue-50":""} ${re?"border-red-400":""} ${h.textarea||""}`})})]})]})]})}const $s=v.forwardRef(({className:e,type:t,...n},r)=>u.jsx("input",{type:t,className:ne("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 Ra(e,[t,n]){return Math.min(n,Math.max(t,e))}function YS(e,t){return v.useReducer((n,r)=>t[n][r]??n,e)}var Ma="ScrollArea",[pp,FT]=Sn(Ma),[XS,Qt]=pp(Ma),hp=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,type:r="hover",dir:o,scrollHideDelay:s=600,...i}=e,[a,l]=v.useState(null),[c,d]=v.useState(null),[f,h]=v.useState(null),[p,x]=v.useState(null),[m,y]=v.useState(null),[g,b]=v.useState(0),[S,k]=v.useState(0),[C,T]=v.useState(!1),[I,A]=v.useState(!1),R=Be(t,P=>l(P)),L=Mo(o);return u.jsx(XS,{scope:n,type:r,dir:L,scrollHideDelay:s,scrollArea:a,viewport:c,onViewportChange:d,content:f,onContentChange:h,scrollbarX:p,onScrollbarXChange:x,scrollbarXEnabled:C,onScrollbarXEnabledChange:T,scrollbarY:m,onScrollbarYChange:y,scrollbarYEnabled:I,onScrollbarYEnabledChange:A,onCornerWidthChange:b,onCornerHeightChange:k,children:u.jsx(_e.div,{dir:L,...i,ref:R,style:{position:"relative","--radix-scroll-area-corner-width":g+"px","--radix-scroll-area-corner-height":S+"px",...e.style}})})});hp.displayName=Ma;var mp="ScrollAreaViewport",gp=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,i=Qt(mp,n),a=v.useRef(null),l=Be(t,a,i.onViewportChange);return u.jsxs(u.Fragment,{children:[u.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-scroll-area-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-scroll-area-viewport]::-webkit-scrollbar{display:none}"},nonce:o}),u.jsx(_e.div,{"data-radix-scroll-area-viewport":"",...s,ref:l,style:{overflowX:i.scrollbarXEnabled?"scroll":"hidden",overflowY:i.scrollbarYEnabled?"scroll":"hidden",...e.style},children:u.jsx("div",{ref:i.onContentChange,style:{minWidth:"100%",display:"table"},children:r})})]})});gp.displayName=mp;var vn="ScrollAreaScrollbar",Pa=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Qt(vn,e.__scopeScrollArea),{onScrollbarXEnabledChange:s,onScrollbarYEnabledChange:i}=o,a=e.orientation==="horizontal";return v.useEffect(()=>(a?s(!0):i(!0),()=>{a?s(!1):i(!1)}),[a,s,i]),o.type==="hover"?u.jsx(JS,{...r,ref:t,forceMount:n}):o.type==="scroll"?u.jsx(ZS,{...r,ref:t,forceMount:n}):o.type==="auto"?u.jsx(xp,{...r,ref:t,forceMount:n}):o.type==="always"?u.jsx(Oa,{...r,ref:t}):null});Pa.displayName=vn;var JS=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Qt(vn,e.__scopeScrollArea),[s,i]=v.useState(!1);return v.useEffect(()=>{const a=o.scrollArea;let l=0;if(a){const c=()=>{window.clearTimeout(l),i(!0)},d=()=>{l=window.setTimeout(()=>i(!1),o.scrollHideDelay)};return a.addEventListener("pointerenter",c),a.addEventListener("pointerleave",d),()=>{window.clearTimeout(l),a.removeEventListener("pointerenter",c),a.removeEventListener("pointerleave",d)}}},[o.scrollArea,o.scrollHideDelay]),u.jsx(Yt,{present:n||s,children:u.jsx(xp,{"data-state":s?"visible":"hidden",...r,ref:t})})}),ZS=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Qt(vn,e.__scopeScrollArea),s=e.orientation==="horizontal",i=Us(()=>l("SCROLL_END"),100),[a,l]=YS("hidden",{hidden:{SCROLL:"scrolling"},scrolling:{SCROLL_END:"idle",POINTER_ENTER:"interacting"},interacting:{SCROLL:"interacting",POINTER_LEAVE:"idle"},idle:{HIDE:"hidden",SCROLL:"scrolling",POINTER_ENTER:"interacting"}});return v.useEffect(()=>{if(a==="idle"){const c=window.setTimeout(()=>l("HIDE"),o.scrollHideDelay);return()=>window.clearTimeout(c)}},[a,o.scrollHideDelay,l]),v.useEffect(()=>{const c=o.viewport,d=s?"scrollLeft":"scrollTop";if(c){let f=c[d];const h=()=>{const p=c[d];f!==p&&(l("SCROLL"),i()),f=p};return c.addEventListener("scroll",h),()=>c.removeEventListener("scroll",h)}},[o.viewport,s,l,i]),u.jsx(Yt,{present:n||a!=="hidden",children:u.jsx(Oa,{"data-state":a==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:de(e.onPointerEnter,()=>l("POINTER_ENTER")),onPointerLeave:de(e.onPointerLeave,()=>l("POINTER_LEAVE"))})})}),xp=v.forwardRef((e,t)=>{const n=Qt(vn,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,i]=v.useState(!1),a=e.orientation==="horizontal",l=Us(()=>{if(n.viewport){const c=n.viewport.offsetWidth<n.viewport.scrollWidth,d=n.viewport.offsetHeight<n.viewport.scrollHeight;i(a?c:d)}},10);return kr(n.viewport,l),kr(n.content,l),u.jsx(Yt,{present:r||s,children:u.jsx(Oa,{"data-state":s?"visible":"hidden",...o,ref:t})})}),Oa=v.forwardRef((e,t)=>{const{orientation:n="vertical",...r}=e,o=Qt(vn,e.__scopeScrollArea),s=v.useRef(null),i=v.useRef(0),[a,l]=v.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),c=Sp(a.viewport,a.content),d={...r,sizes:a,onSizesChange:l,hasThumb:c>0&&c<1,onThumbChange:h=>s.current=h,onThumbPointerUp:()=>i.current=0,onThumbPointerDown:h=>i.current=h};function f(h,p){return oC(h,i.current,a,p)}return n==="horizontal"?u.jsx(QS,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollLeft,p=Cp(h,a,o.dir);s.current.style.transform=`translate3d(${p}px, 0, 0)`}},onWheelScroll:h=>{o.viewport&&(o.viewport.scrollLeft=h)},onDragScroll:h=>{o.viewport&&(o.viewport.scrollLeft=f(h,o.dir))}}):n==="vertical"?u.jsx(eC,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollTop,p=Cp(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}),QS=v.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=Qt(vn,e.__scopeScrollArea),[i,a]=v.useState(),l=v.useRef(null),c=Be(t,l,s.onScrollbarXChange);return v.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(vp,{"data-orientation":"horizontal",...o,ref:c,sizes:n,style:{bottom:0,left:s.dir==="rtl"?"var(--radix-scroll-area-corner-width)":0,right:s.dir==="ltr"?"var(--radix-scroll-area-corner-width)":0,"--radix-scroll-area-thumb-width":zs(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),kp(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)}})}})}),eC=v.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=Qt(vn,e.__scopeScrollArea),[i,a]=v.useState(),l=v.useRef(null),c=Be(t,l,s.onScrollbarYChange);return v.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(vp,{"data-orientation":"vertical",...o,ref:c,sizes:n,style:{top:0,right:s.dir==="ltr"?0:void 0,left:s.dir==="rtl"?0:void 0,bottom:"var(--radix-scroll-area-corner-height)","--radix-scroll-area-thumb-height":zs(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),kp(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)}})}})}),[tC,yp]=pp(vn),vp=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,sizes:r,hasThumb:o,onThumbChange:s,onThumbPointerUp:i,onThumbPointerDown:a,onThumbPositionChange:l,onDragScroll:c,onWheelScroll:d,onResize:f,...h}=e,p=Qt(vn,n),[x,m]=v.useState(null),y=Be(t,R=>m(R)),g=v.useRef(null),b=v.useRef(""),S=p.viewport,k=r.content-r.viewport,C=kt(d),T=kt(l),I=Us(f,10);function A(R){if(g.current){const L=R.clientX-g.current.left,P=R.clientY-g.current.top;c({x:L,y:P})}}return v.useEffect(()=>{const R=L=>{const P=L.target;(x==null?void 0:x.contains(P))&&C(L,k)};return document.addEventListener("wheel",R,{passive:!1}),()=>document.removeEventListener("wheel",R,{passive:!1})},[S,x,k,C]),v.useEffect(T,[r,T]),kr(x,I),kr(p.content,I),u.jsx(tC,{scope:n,scrollbar:x,hasThumb:o,onThumbChange:kt(s),onThumbPointerUp:kt(i),onThumbPositionChange:T,onThumbPointerDown:kt(a),children:u.jsx(_e.div,{...h,ref:y,style:{position:"absolute",...h.style},onPointerDown:de(e.onPointerDown,R=>{R.button===0&&(R.target.setPointerCapture(R.pointerId),g.current=x.getBoundingClientRect(),b.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",p.viewport&&(p.viewport.style.scrollBehavior="auto"),A(R))}),onPointerMove:de(e.onPointerMove,A),onPointerUp:de(e.onPointerUp,R=>{const L=R.target;L.hasPointerCapture(R.pointerId)&&L.releasePointerCapture(R.pointerId),document.body.style.webkitUserSelect=b.current,p.viewport&&(p.viewport.style.scrollBehavior=""),g.current=null})})})}),Fs="ScrollAreaThumb",bp=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=yp(Fs,e.__scopeScrollArea);return u.jsx(Yt,{present:n||o.hasThumb,children:u.jsx(nC,{ref:t,...r})})}),nC=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=Qt(Fs,n),i=yp(Fs,n),{onThumbPositionChange:a}=i,l=Be(t,f=>i.onThumbChange(f)),c=v.useRef(void 0),d=Us(()=>{c.current&&(c.current(),c.current=void 0)},100);return v.useEffect(()=>{const f=s.viewport;if(f){const h=()=>{if(d(),!c.current){const p=sC(f,a);c.current=p,a()}};return a(),f.addEventListener("scroll",h),()=>f.removeEventListener("scroll",h)}},[s.viewport,d,a]),u.jsx(_e.div,{"data-state":i.hasThumb?"visible":"hidden",...o,ref:l,style:{width:"var(--radix-scroll-area-thumb-width)",height:"var(--radix-scroll-area-thumb-height)",...r},onPointerDownCapture:de(e.onPointerDownCapture,f=>{const p=f.target.getBoundingClientRect(),x=f.clientX-p.left,m=f.clientY-p.top;i.onThumbPointerDown({x,y:m})}),onPointerUp:de(e.onPointerUp,i.onThumbPointerUp)})});bp.displayName=Fs;var Da="ScrollAreaCorner",wp=v.forwardRef((e,t)=>{const n=Qt(Da,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?u.jsx(rC,{...e,ref:t}):null});wp.displayName=Da;var rC=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=Qt(Da,n),[s,i]=v.useState(0),[a,l]=v.useState(0),c=!!(s&&a);return kr(o.scrollbarX,()=>{var f;const d=((f=o.scrollbarX)==null?void 0:f.offsetHeight)||0;o.onCornerHeightChange(d),l(d)}),kr(o.scrollbarY,()=>{var f;const d=((f=o.scrollbarY)==null?void 0:f.offsetWidth)||0;o.onCornerWidthChange(d),i(d)}),c?u.jsx(_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 Bs(e){return e?parseInt(e,10):0}function Sp(e,t){const n=e/t;return isNaN(n)?0:n}function zs(e){const t=Sp(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function oC(e,t,n,r="ltr"){const o=zs(n),s=o/2,i=t||s,a=o-i,l=n.scrollbar.paddingStart+i,c=n.scrollbar.size-n.scrollbar.paddingEnd-a,d=n.content-n.viewport,f=r==="ltr"?[0,d]:[d*-1,0];return Tp([l,c],f)(e)}function Cp(e,t,n="ltr"){const r=zs(t),o=t.scrollbar.paddingStart+t.scrollbar.paddingEnd,s=t.scrollbar.size-o,i=t.content-t.viewport,a=s-r,l=n==="ltr"?[0,i]:[i*-1,0],c=Ra(e,l);return Tp([0,i],[0,a])(c)}function Tp(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 kp(e,t){return e>0&&e<t}var sC=(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=kt(e),r=v.useRef(0);return v.useEffect(()=>()=>window.clearTimeout(r.current),[]),v.useCallback(()=>{window.clearTimeout(r.current),r.current=window.setTimeout(n,t)},[n,t])}function kr(e,t){const n=kt(t);Tt(()=>{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 Ip=hp,iC=gp,aC=wp;const Ep=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Ip,{ref:r,className:ne("relative overflow-hidden",e),...n,children:[u.jsx(iC,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),u.jsx(Ap,{}),u.jsx(aC,{})]}));Ep.displayName=Ip.displayName;const Ap=v.forwardRef(({className:e,orientation:t="vertical",...n},r)=>u.jsx(Pa,{ref:r,orientation:t,className:ne("flex touch-none select-none transition-colors",t==="vertical"&&"h-full w-2.5 border-l border-l-transparent p-[1px]",t==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent p-[1px]",e),...n,children:u.jsx(bp,{className:"relative flex-1 rounded-full bg-border"})}));Ap.displayName=Pa.displayName;const Np=25;function La({className:e="",showCreateButton:t=!0,showDeleteButton:n=!0,showEditTitle:r=!0,maxHeight:o="400px",customStyles:s={},currentThreadId:i=null,navigateToThread:a,onThreadSelect:l,onThreadCreate:c,onThreadDelete:d}){const{threads:f,currentThreadId:h,setCurrentThreadId:p,isLoading:x,actions:m}=_o(),{loadThread:y}=jo(),{createThread:g,deleteThread:b,renameThread:S}=m,[k,C]=w.useState(Array.isArray(f)?f:[]),T=w.useRef(k.length>0),I=w.useRef(null),A=w.useRef(0),[R,L]=w.useState(null),[P,D]=w.useState(""),[F,N]=w.useState(!1);w.useEffect(()=>{const Y=Array.isArray(f)?f:[];if(Y.length>0){T.current=!0,C(Y);return}x||(T.current=!1,C(Y))},[f,x]),w.useEffect(()=>{if(!I.current)return;const Y=I.current.querySelector("[data-radix-scroll-area-viewport]");if(!Y)return;let U=null,Z=null;return U=requestAnimationFrame(()=>{Z=requestAnimationFrame(()=>{Y.scrollTop=A.current})}),()=>{U!==null&&cancelAnimationFrame(U),Z!==null&&cancelAnimationFrame(Z)}},[k]);const B=async Y=>{try{p(Y),await y(Y),a==null||a(Y),l==null||l(Y)}catch(U){console.error("Failed to select thread:",U)}},j=async()=>{try{N(!0);const Y=await g();Y&&(c==null||c(Y),a==null||a(Y))}catch(Y){console.error("Failed to create thread:",Y)}finally{N(!1)}},V=async(Y,U)=>{if(U.stopPropagation(),!!confirm("Delete this thread?")){if(I.current){const Z=I.current.querySelector("[data-radix-scroll-area-viewport]");Z&&(A.current=Z.scrollTop)}try{await b(Y),d==null||d(Y)}catch(Z){console.error("Failed to delete thread:",Z)}}},z=(Y,U)=>{U.stopPropagation(),L(Y.threadId),D(Y.title||`Thread ${Y.threadId.slice(0,8)}`)},M=async Y=>{if(P.trim())try{await S(Y,P.trim()),L(null),D("")}catch(U){console.error("Failed to update title:",U)}},q=()=>{L(null),D("")},J=(Y,U)=>{Y.key==="Enter"?M(U):Y.key==="Escape"&&q()},se=Y=>{if(!Y)return"";try{const U=new Date(Y),$=new Date().getTime()-U.getTime(),K=Math.floor($/(1e3*60*60*24));return K===0?U.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):K===1?"Yesterday":K<7?`${K} days ago`:U.toLocaleDateString()}catch{return""}},ge=Y=>Y.title||`Thread ${Y.threadId.slice(0,8)}`,Ee=Y=>{const U=ge(Y);return U.length<=Np?U:`${U.slice(0,Np)}...`};return u.jsxs("div",{className:`flex flex-col h-full ${e} ${s.container||""}`,children:[t&&u.jsx("div",{className:s.header||"flex-shrink-0 p-2 border-b bg-slate-800 border-slate-700 text-slate-100 flex justify-end",children:u.jsx(Xe,{onClick:j,disabled:F||x,className:s.createButton||"p-2",size:"sm",variant:"ghost",title:F?"Creating...":"New Chat",children:u.jsx(ae.MessageSquarePlus,{size:20})})}),u.jsx(Ep,{ref:I,className:`flex-1 min-h-0 ${s.threadList||""}`,style:o?{maxHeight:o}:void 0,children:u.jsx("div",{className:"p-2 space-y-1 pb-4",children:x?u.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 py-8 text-slate-400",children:[u.jsx(ae.Loader2,{className:"h-5 w-5 animate-spin"}),u.jsx("span",{className:"text-sm",children:"Loading threads…"})]}):k.length===0?u.jsxs("div",{className:"text-center py-8 text-slate-400",children:[u.jsx(ae.MessageSquare,{className:"w-8 h-8 mx-auto mb-2 opacity-40 text-slate-500"}),u.jsx("p",{className:"text-sm text-slate-500",children:"No conversations yet"})]}):k.slice().sort((Y,U)=>new Date(U.updatedAt||U.createdAt||"").getTime()-new Date(Y.updatedAt||Y.createdAt||"").getTime()).map(Y=>u.jsxs("div",{onClick:()=>B(Y.threadId),className:`group relative p-3 rounded-lg cursor-pointer transition-colors border ${(i??h)===Y.threadId?`${s.activeThread||"bg-slate-600 border-slate-500"} `:`${s.threadItem||"bg-slate-700 border-slate-600 hover:bg-slate-600 text-gray-900 dark:text-slate-100"}`} ${s.threadItem||""} text-gray-900 dark:text-slate-100`,children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx("div",{className:"flex-1 min-w-0",children:R===Y.threadId?u.jsxs("div",{className:"flex items-center gap-2",onClick:U=>U.stopPropagation(),children:[u.jsx($s,{value:P,onChange:U=>D(U.target.value),onKeyDown:U=>J(U,Y.threadId),className:"h-6 text-sm",autoFocus:!0}),u.jsx(Xe,{variant:"ghost",size:"sm",onClick:()=>M(Y.threadId),className:"h-6 w-6 p-0",children:u.jsx(ae.Check,{size:12})}),u.jsx(Xe,{variant:"ghost",size:"sm",onClick:q,className:"h-6 w-6 p-0",children:u.jsx(ae.X,{size:12})})]}):u.jsxs(u.Fragment,{children:[u.jsx("div",{className:"font-medium text-sm truncate text-gray-900 dark:text-slate-100",children:Ee(Y)}),u.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500 dark:text-slate-400 mt-1",children:[u.jsx(ae.Calendar,{size:10}),u.jsx("span",{children:se(Y.updatedAt||Y.createdAt)})]})]})}),u.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity ml-2",children:[r&&R!==Y.threadId&&u.jsx(Xe,{variant:"ghost",size:"sm",onClick:U=>z(Y,U),className:"h-6 w-6 p-0",title:"Edit title",children:u.jsx(ae.Edit3,{size:12})}),n&&u.jsx(Xe,{variant:"ghost",size:"sm",onClick:U=>V(Y.threadId,U),className:"h-6 w-6 p-0 text-red-400 hover:text-red-300 hover:bg-red-900/20",title:"Delete thread",children:u.jsx(ae.Trash2,{size:12})})]})]}),i===Y.threadId&&u.jsx("div",{className:"absolute left-0 top-1/2 -translate-y-1/2 w-1 h-8 bg-blue-400 rounded-r"})]},Y.threadId))})})]})}const lC=({timelineEntries:e,activeCheckpointId:t,onSelectCheckpoint:n,messagePreviews:r,className:o,onHoverStart:s,onHoverEnd:i})=>{const a=e??[],l=a.length>0,c=w.useMemo(()=>l?[...a].reverse():[],[a,l]),d=t??(a.length?a[a.length-1].id:null);if(!l)return null;const h=["w-32 flex-shrink-0 flex-col border-r border-border/40 pr-2 flex bg-white text-gray-900 dark:bg-slate-900 dark:text-slate-100",o].filter(Boolean).join(" ");return u.jsxs("div",{className:h,onMouseEnter:s,onMouseLeave:i,children:[u.jsxs("div",{className:"relative flex-1 overflow-y-auto pt-4 pb-2 pr-1",children:[u.jsx("div",{className:"absolute left-0 right-0 top-1 px-2 pb-3 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground",children:u.jsx("span",{children:"Timeline"})}),u.jsx("div",{className:"pointer-events-none absolute left-3 top-0 bottom-0 w-px bg-border/40"}),u.jsx("div",{className:"flex flex-col gap-3 pt-6 pr-2",children:c.map(p=>{const x=d===p.id,m=p.messageId?(r==null?void 0:r.get(p.messageId))??null:null;return u.jsxs("button",{type:"button",disabled:!n,onClick:()=>n==null?void 0:n(p.id),className:`relative flex items-start gap-2 text-left text-[11px] transition ${x?"text-primary":"text-muted-foreground"} ${n?"hover:text-foreground":"cursor-default opacity-70"}`,children:[u.jsx("span",{className:`mt-1 inline-flex h-3 w-3 items-center justify-center rounded-full border ${x?"border-primary bg-primary/10 text-primary":"border-border bg-background"}`,children:u.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${x?"bg-primary":"bg-border"}`})}),u.jsxs("span",{className:"flex-1",children:[u.jsx("span",{className:"block font-medium leading-tight",children:p.label||"User input"}),u.jsxs("span",{className:"text-[9px] uppercase tracking-wide text-muted-foreground/70",children:[p.step!==null?`STEP ${p.step}`:"STEP —",p.next?` - ${p.next}`:""]}),m&&u.jsx("p",{className:"text-[10px] text-muted-foreground/80 mt-1 line-clamp-2",title:m,children:m})]})]},p.id)})})]}),n&&u.jsx("button",{type:"button",onClick:()=>n==null?void 0:n(null),className:"mt-auto mb-3 rounded-md border border-border/70 px-2 py-1 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground transition hover:border-foreground/60 hover:text-foreground",children:"Latest"})]})};function Ir(e){if(!(typeof globalThis>"u"))return globalThis[e]}function cC(e){if(typeof e!="string")return;const t=e.trim();if(t)return wn(t)}function _p(){const e=[Ir("__API_BASE_URL__"),Ir("__CHAT_API_BASE_URL__"),Ir("__CHAT_API_URL__")];for(const t of e){const n=cC(t);if(n)return n}}function jp(){const e=[Ir("__API_AUTH_TOKEN__"),Ir("__CHAT_API_KEY__"),Ir("__CHAT_AUTH_TOKEN__")];for(const t of e)if(typeof t=="string"&&t.trim())return t.trim()}function Rp(...e){for(const t of e)if(typeof t=="string"&&t.trim())return wn(t);return wn()}function Mp(){const e={},t=_p(),n=jp();return t&&(e.baseUrl=t),n&&(e.apiKey=n),e}function Pp(){const e=Mp(),t=An.getAuthToken(),n=_p();return{apiBaseUrl:Rp(e.baseUrl,An.baseUrl,n),apiKey:t||e.apiKey||jp()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,darkMode:!1,enableSound:!1,messageHistory:100}}const Op="chat-settings";function uC(){try{const e=localStorage.getItem(Op);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function dC(e){try{const t={...e,apiBaseUrl:wn(e.apiBaseUrl)};localStorage.setItem(Op,JSON.stringify(t)),t.apiKey&&An.setAuthToken(t.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function fC(){const e=Pp(),t=uC(),n=An.getAuthToken(),r=typeof t.apiBaseUrl=="string"?t.apiBaseUrl:void 0;return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:Rp(An.baseUrl,r,e.apiBaseUrl)}}function pC(e){An.updateConfig({baseUrl:e.apiBaseUrl,authToken:e.apiKey??void 0}),dC(e)}var hC="Label",Dp=v.forwardRef((e,t)=>u.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())}}));Dp.displayName=hC;var Lp=Dp;const mC=po.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),en=v.forwardRef(({className:e,...t},n)=>u.jsx(Lp,{ref:n,className:ne(mC(),e),...t}));en.displayName=Lp.displayName;function $p(e){const t=v.useRef({value:e,previous:e});return v.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}var Fp=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"}),gC="VisuallyHidden",xC=v.forwardRef((e,t)=>u.jsx(_e.span,{...e,ref:t,style:{...Fp,...e.style}}));xC.displayName=gC;var yC=[" ","Enter","ArrowUp","ArrowDown"],vC=[" ","Enter"],rr="Select",[Hs,Ws,bC]=xi(rr),[Er,BT]=Sn(rr,[bC,Ko]),Vs=Ko(),[wC,$n]=Er(rr),[SC,CC]=Er(rr),Bp=e=>{const{__scopeSelect:t,children:n,open:r,defaultOpen:o,onOpenChange:s,value:i,defaultValue:a,onValueChange:l,dir:c,name:d,autoComplete:f,disabled:h,required:p,form:x}=e,m=Vs(t),[y,g]=v.useState(null),[b,S]=v.useState(null),[k,C]=v.useState(!1),T=Mo(c),[I,A]=pr({prop:r,defaultProp:o??!1,onChange:s,caller:rr}),[R,L]=pr({prop:i,defaultProp:a,onChange:l,caller:rr}),P=v.useRef(null),D=y?x||!!y.closest("form"):!0,[F,N]=v.useState(new Set),B=Array.from(F).map(j=>j.props.value).join(";");return u.jsx(tu,{...m,children:u.jsxs(wC,{required:p,scope:t,trigger:y,onTriggerChange:g,valueNode:b,onValueNodeChange:S,valueNodeHasChildren:k,onValueNodeHasChildrenChange:C,contentId:Cn(),value:R,onValueChange:L,open:I,onOpenChange:A,dir:T,triggerPointerDownPosRef:P,disabled:h,children:[u.jsx(Hs.Provider,{scope:t,children:u.jsx(SC,{scope:e.__scopeSelect,onNativeOptionAdd:v.useCallback(j=>{N(V=>new Set(V).add(j))},[]),onNativeOptionRemove:v.useCallback(j=>{N(V=>{const z=new Set(V);return z.delete(j),z})},[]),children:n})}),D?u.jsxs(uh,{"aria-hidden":!0,required:p,tabIndex:-1,name:d,autoComplete:f,value:R,onChange:j=>L(j.target.value),disabled:h,form:x,children:[R===void 0?u.jsx("option",{value:""}):null,Array.from(F)]},B):null]})})};Bp.displayName=rr;var zp="SelectTrigger",Up=v.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...o}=e,s=Vs(n),i=$n(zp,n),a=i.disabled||r,l=Be(t,i.onTriggerChange),c=Ws(n),d=v.useRef("touch"),[f,h,p]=fh(m=>{const y=c().filter(S=>!S.disabled),g=y.find(S=>S.value===i.value),b=ph(y,m,g);b!==void 0&&i.onValueChange(b.value)}),x=m=>{a||(i.onOpenChange(!0),p()),m&&(i.triggerPointerDownPosRef.current={x:Math.round(m.pageX),y:Math.round(m.pageY)})};return u.jsx(nu,{asChild:!0,...s,children:u.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":dh(i.value)?"":void 0,...o,ref:l,onClick:de(o.onClick,m=>{m.currentTarget.focus(),d.current!=="mouse"&&x(m)}),onPointerDown:de(o.onPointerDown,m=>{d.current=m.pointerType;const y=m.target;y.hasPointerCapture(m.pointerId)&&y.releasePointerCapture(m.pointerId),m.button===0&&m.ctrlKey===!1&&m.pointerType==="mouse"&&(x(m),m.preventDefault())}),onKeyDown:de(o.onKeyDown,m=>{const y=f.current!=="";!(m.ctrlKey||m.altKey||m.metaKey)&&m.key.length===1&&h(m.key),!(y&&m.key===" ")&&yC.includes(m.key)&&(x(),m.preventDefault())})})})});Up.displayName=zp;var Hp="SelectValue",Wp=v.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,children:s,placeholder:i="",...a}=e,l=$n(Hp,n),{onValueNodeHasChildrenChange:c}=l,d=s!==void 0,f=Be(t,l.onValueNodeChange);return Tt(()=>{c(d)},[c,d]),u.jsx(_e.span,{...a,ref:f,style:{pointerEvents:"none"},children:dh(l.value)?u.jsx(u.Fragment,{children:i}):s})});Wp.displayName=Hp;var TC="SelectIcon",Vp=v.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...o}=e;return u.jsx(_e.span,{"aria-hidden":!0,...o,ref:t,children:r||"▼"})});Vp.displayName=TC;var kC="SelectPortal",Kp=e=>u.jsx(qo,{asChild:!0,...e});Kp.displayName=kC;var or="SelectContent",qp=v.forwardRef((e,t)=>{const n=$n(or,e.__scopeSelect),[r,o]=v.useState();if(Tt(()=>{o(new DocumentFragment)},[]),!n.open){const s=r;return s?ho.createPortal(u.jsx(Gp,{scope:e.__scopeSelect,children:u.jsx(Hs.Slot,{scope:e.__scopeSelect,children:u.jsx("div",{children:e.children})})}),s):null}return u.jsx(Yp,{...e,ref:t})});qp.displayName=or;var cn=10,[Gp,Fn]=Er(or),IC="SelectContentImpl",EC=Hn.createSlot("SelectContent.RemoveScroll"),Yp=v.forwardRef((e,t)=>{const{__scopeSelect:n,position:r="item-aligned",onCloseAutoFocus:o,onEscapeKeyDown:s,onPointerDownOutside:i,side:a,sideOffset:l,align:c,alignOffset:d,arrowPadding:f,collisionBoundary:h,collisionPadding:p,sticky:x,hideWhenDetached:m,avoidCollisions:y,...g}=e,b=$n(or,n),[S,k]=v.useState(null),[C,T]=v.useState(null),I=Be(t,Z=>k(Z)),[A,R]=v.useState(null),[L,P]=v.useState(null),D=Ws(n),[F,N]=v.useState(!1),B=v.useRef(!1);v.useEffect(()=>{if(S)return Fi(S)},[S]),bi();const j=v.useCallback(Z=>{const[$,...K]=D().map(oe=>oe.ref.current),[Q]=K.slice(-1),ce=document.activeElement;for(const oe of Z)if(oe===ce||(oe==null||oe.scrollIntoView({block:"nearest"}),oe===$&&C&&(C.scrollTop=0),oe===Q&&C&&(C.scrollTop=C.scrollHeight),oe==null||oe.focus(),document.activeElement!==ce))return},[D,C]),V=v.useCallback(()=>j([A,S]),[j,A,S]);v.useEffect(()=>{F&&V()},[F,V]);const{onOpenChange:z,triggerPointerDownPosRef:M}=b;v.useEffect(()=>{if(S){let Z={x:0,y:0};const $=Q=>{var ce,oe;Z={x:Math.abs(Math.round(Q.pageX)-(((ce=M.current)==null?void 0:ce.x)??0)),y:Math.abs(Math.round(Q.pageY)-(((oe=M.current)==null?void 0:oe.y)??0))}},K=Q=>{Z.x<=10&&Z.y<=10?Q.preventDefault():S.contains(Q.target)||z(!1),document.removeEventListener("pointermove",$),M.current=null};return M.current!==null&&(document.addEventListener("pointermove",$),document.addEventListener("pointerup",K,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",$),document.removeEventListener("pointerup",K,{capture:!0})}}},[S,z,M]),v.useEffect(()=>{const Z=()=>z(!1);return window.addEventListener("blur",Z),window.addEventListener("resize",Z),()=>{window.removeEventListener("blur",Z),window.removeEventListener("resize",Z)}},[z]);const[q,J]=fh(Z=>{const $=D().filter(ce=>!ce.disabled),K=$.find(ce=>ce.ref.current===document.activeElement),Q=ph($,Z,K);Q&&setTimeout(()=>Q.ref.current.focus())}),se=v.useCallback((Z,$,K)=>{const Q=!B.current&&!K;(b.value!==void 0&&b.value===$||Q)&&(R(Z),Q&&(B.current=!0))},[b.value]),ge=v.useCallback(()=>S==null?void 0:S.focus(),[S]),Ee=v.useCallback((Z,$,K)=>{const Q=!B.current&&!K;(b.value!==void 0&&b.value===$||Q)&&P(Z)},[b.value]),Y=r==="popper"?$a:Xp,U=Y===$a?{side:a,sideOffset:l,align:c,alignOffset:d,arrowPadding:f,collisionBoundary:h,collisionPadding:p,sticky:x,hideWhenDetached:m,avoidCollisions:y}:{};return u.jsx(Gp,{scope:n,content:S,viewport:C,onViewportChange:T,itemRefCallback:se,selectedItem:A,onItemLeave:ge,itemTextRefCallback:Ee,focusSelectedItem:V,selectedItemText:L,position:r,isPositioned:F,searchRef:q,children:u.jsx(ns,{as:EC,allowPinchZoom:!0,children:u.jsx(Oo,{asChild:!0,trapped:b.open,onMountAutoFocus:Z=>{Z.preventDefault()},onUnmountAutoFocus:de(o,Z=>{var $;($=b.trigger)==null||$.focus({preventScroll:!0}),Z.preventDefault()}),children:u.jsx(Po,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:Z=>Z.preventDefault(),onDismiss:()=>b.onOpenChange(!1),children:u.jsx(Y,{role:"listbox",id:b.contentId,"data-state":b.open?"open":"closed",dir:b.dir,onContextMenu:Z=>Z.preventDefault(),...g,...U,onPlaced:()=>N(!0),ref:I,style:{display:"flex",flexDirection:"column",outline:"none",...g.style},onKeyDown:de(g.onKeyDown,Z=>{const $=Z.ctrlKey||Z.altKey||Z.metaKey;if(Z.key==="Tab"&&Z.preventDefault(),!$&&Z.key.length===1&&J(Z.key),["ArrowUp","ArrowDown","Home","End"].includes(Z.key)){let Q=D().filter(ce=>!ce.disabled).map(ce=>ce.ref.current);if(["ArrowUp","End"].includes(Z.key)&&(Q=Q.slice().reverse()),["ArrowUp","ArrowDown"].includes(Z.key)){const ce=Z.target,oe=Q.indexOf(ce);Q=Q.slice(oe+1)}setTimeout(()=>j(Q)),Z.preventDefault()}})})})})})})});Yp.displayName=IC;var AC="SelectItemAlignedPosition",Xp=v.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...o}=e,s=$n(or,n),i=Fn(or,n),[a,l]=v.useState(null),[c,d]=v.useState(null),f=Be(t,I=>d(I)),h=Ws(n),p=v.useRef(!1),x=v.useRef(!0),{viewport:m,selectedItem:y,selectedItemText:g,focusSelectedItem:b}=i,S=v.useCallback(()=>{if(s.trigger&&s.valueNode&&a&&c&&m&&y&&g){const I=s.trigger.getBoundingClientRect(),A=c.getBoundingClientRect(),R=s.valueNode.getBoundingClientRect(),L=g.getBoundingClientRect();if(s.dir!=="rtl"){const ce=L.left-A.left,oe=R.left-ce,Ne=I.left-oe,Ue=I.width+Ne,re=Math.max(Ue,A.width),xe=window.innerWidth-cn,Pe=Ra(oe,[cn,Math.max(cn,xe-re)]);a.style.minWidth=Ue+"px",a.style.left=Pe+"px"}else{const ce=A.right-L.right,oe=window.innerWidth-R.right-ce,Ne=window.innerWidth-I.right-oe,Ue=I.width+Ne,re=Math.max(Ue,A.width),xe=window.innerWidth-cn,Pe=Ra(oe,[cn,Math.max(cn,xe-re)]);a.style.minWidth=Ue+"px",a.style.right=Pe+"px"}const P=h(),D=window.innerHeight-cn*2,F=m.scrollHeight,N=window.getComputedStyle(c),B=parseInt(N.borderTopWidth,10),j=parseInt(N.paddingTop,10),V=parseInt(N.borderBottomWidth,10),z=parseInt(N.paddingBottom,10),M=B+j+F+z+V,q=Math.min(y.offsetHeight*5,M),J=window.getComputedStyle(m),se=parseInt(J.paddingTop,10),ge=parseInt(J.paddingBottom,10),Ee=I.top+I.height/2-cn,Y=D-Ee,U=y.offsetHeight/2,Z=y.offsetTop+U,$=B+j+Z,K=M-$;if($<=Ee){const ce=P.length>0&&y===P[P.length-1].ref.current;a.style.bottom="0px";const oe=c.clientHeight-m.offsetTop-m.offsetHeight,Ne=Math.max(Y,U+(ce?ge:0)+oe+V),Ue=$+Ne;a.style.height=Ue+"px"}else{const ce=P.length>0&&y===P[0].ref.current;a.style.top="0px";const Ne=Math.max(Ee,B+m.offsetTop+(ce?se:0)+U)+K;a.style.height=Ne+"px",m.scrollTop=$-Ee+m.offsetTop}a.style.margin=`${cn}px 0`,a.style.minHeight=q+"px",a.style.maxHeight=D+"px",r==null||r(),requestAnimationFrame(()=>p.current=!0)}},[h,s.trigger,s.valueNode,a,c,m,y,g,s.dir,r]);Tt(()=>S(),[S]);const[k,C]=v.useState();Tt(()=>{c&&C(window.getComputedStyle(c).zIndex)},[c]);const T=v.useCallback(I=>{I&&x.current===!0&&(S(),b==null||b(),x.current=!1)},[S,b]);return u.jsx(_C,{scope:n,contentWrapper:a,shouldExpandOnScrollRef:p,onScrollButtonChange:T,children:u.jsx("div",{ref:l,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:k},children:u.jsx(_e.div,{...o,ref:f,style:{boxSizing:"border-box",maxHeight:"100%",...o.style}})})})});Xp.displayName=AC;var NC="SelectPopperPosition",$a=v.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=cn,...s}=e,i=Vs(n);return u.jsx(ru,{...i,...s,ref:t,align:r,collisionPadding:o,style:{boxSizing:"border-box",...s.style,"--radix-select-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-select-content-available-width":"var(--radix-popper-available-width)","--radix-select-content-available-height":"var(--radix-popper-available-height)","--radix-select-trigger-width":"var(--radix-popper-anchor-width)","--radix-select-trigger-height":"var(--radix-popper-anchor-height)"}})});$a.displayName=NC;var[_C,Fa]=Er(or,{}),Ba="SelectViewport",Jp=v.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...o}=e,s=Fn(Ba,n),i=Fa(Ba,n),a=Be(t,s.onViewportChange),l=v.useRef(0);return u.jsxs(u.Fragment,{children:[u.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}"},nonce:r}),u.jsx(Hs.Slot,{scope:n,children:u.jsx(_e.div,{"data-radix-select-viewport":"",role:"presentation",...o,ref:a,style:{position:"relative",flex:1,overflow:"hidden auto",...o.style},onScroll:de(o.onScroll,c=>{const d=c.currentTarget,{contentWrapper:f,shouldExpandOnScrollRef:h}=i;if(h!=null&&h.current&&f){const p=Math.abs(l.current-d.scrollTop);if(p>0){const x=window.innerHeight-cn*2,m=parseFloat(f.style.minHeight),y=parseFloat(f.style.height),g=Math.max(m,y);if(g<x){const b=g+p,S=Math.min(x,b),k=b-S;f.style.height=S+"px",f.style.bottom==="0px"&&(d.scrollTop=k>0?k:0,f.style.justifyContent="flex-end")}}}l.current=d.scrollTop})})})]})});Jp.displayName=Ba;var Zp="SelectGroup",[jC,RC]=Er(Zp),MC=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Cn();return u.jsx(jC,{scope:n,id:o,children:u.jsx(_e.div,{role:"group","aria-labelledby":o,...r,ref:t})})});MC.displayName=Zp;var Qp="SelectLabel",eh=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=RC(Qp,n);return u.jsx(_e.div,{id:o.id,...r,ref:t})});eh.displayName=Qp;var Ks="SelectItem",[PC,th]=Er(Ks),nh=v.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:s,...i}=e,a=$n(Ks,n),l=Fn(Ks,n),c=a.value===r,[d,f]=v.useState(s??""),[h,p]=v.useState(!1),x=Be(t,b=>{var S;return(S=l.itemRefCallback)==null?void 0:S.call(l,b,r,o)}),m=Cn(),y=v.useRef("touch"),g=()=>{o||(a.onValueChange(r),a.onOpenChange(!1))};if(r==="")throw new Error("A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.");return u.jsx(PC,{scope:n,value:r,disabled:o,textId:m,isSelected:c,onItemTextChange:v.useCallback(b=>{f(S=>S||((b==null?void 0:b.textContent)??"").trim())},[]),children:u.jsx(Hs.ItemSlot,{scope:n,value:r,disabled:o,textValue:d,children:u.jsx(_e.div,{role:"option","aria-labelledby":m,"data-highlighted":h?"":void 0,"aria-selected":c&&h,"data-state":c?"checked":"unchecked","aria-disabled":o||void 0,"data-disabled":o?"":void 0,tabIndex:o?void 0:-1,...i,ref:x,onFocus:de(i.onFocus,()=>p(!0)),onBlur:de(i.onBlur,()=>p(!1)),onClick:de(i.onClick,()=>{y.current!=="mouse"&&g()}),onPointerUp:de(i.onPointerUp,()=>{y.current==="mouse"&&g()}),onPointerDown:de(i.onPointerDown,b=>{y.current=b.pointerType}),onPointerMove:de(i.onPointerMove,b=>{var S;y.current=b.pointerType,o?(S=l.onItemLeave)==null||S.call(l):y.current==="mouse"&&b.currentTarget.focus({preventScroll:!0})}),onPointerLeave:de(i.onPointerLeave,b=>{var S;b.currentTarget===document.activeElement&&((S=l.onItemLeave)==null||S.call(l))}),onKeyDown:de(i.onKeyDown,b=>{var k;((k=l.searchRef)==null?void 0:k.current)!==""&&b.key===" "||(vC.includes(b.key)&&g(),b.key===" "&&b.preventDefault())})})})})});nh.displayName=Ks;var uo="SelectItemText",rh=v.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,...s}=e,i=$n(uo,n),a=Fn(uo,n),l=th(uo,n),c=CC(uo,n),[d,f]=v.useState(null),h=Be(t,g=>f(g),l.onItemTextChange,g=>{var b;return(b=a.itemTextRefCallback)==null?void 0:b.call(a,g,l.value,l.disabled)}),p=d==null?void 0:d.textContent,x=v.useMemo(()=>u.jsx("option",{value:l.value,disabled:l.disabled,children:p},l.value),[l.disabled,l.value,p]),{onNativeOptionAdd:m,onNativeOptionRemove:y}=c;return Tt(()=>(m(x),()=>y(x)),[m,y,x]),u.jsxs(u.Fragment,{children:[u.jsx(_e.span,{id:l.textId,...s,ref:h}),l.isSelected&&i.valueNode&&!i.valueNodeHasChildren?ho.createPortal(s.children,i.valueNode):null]})});rh.displayName=uo;var oh="SelectItemIndicator",sh=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return th(oh,n).isSelected?u.jsx(_e.span,{"aria-hidden":!0,...r,ref:t}):null});sh.displayName=oh;var za="SelectScrollUpButton",ih=v.forwardRef((e,t)=>{const n=Fn(za,e.__scopeSelect),r=Fa(za,e.__scopeSelect),[o,s]=v.useState(!1),i=Be(t,r.onScrollButtonChange);return Tt(()=>{if(n.viewport&&n.isPositioned){let a=function(){const c=l.scrollTop>0;s(c)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?u.jsx(lh,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop-l.offsetHeight)}}):null});ih.displayName=za;var Ua="SelectScrollDownButton",ah=v.forwardRef((e,t)=>{const n=Fn(Ua,e.__scopeSelect),r=Fa(Ua,e.__scopeSelect),[o,s]=v.useState(!1),i=Be(t,r.onScrollButtonChange);return Tt(()=>{if(n.viewport&&n.isPositioned){let a=function(){const c=l.scrollHeight-l.clientHeight,d=Math.ceil(l.scrollTop)<c;s(d)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?u.jsx(lh,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop+l.offsetHeight)}}):null});ah.displayName=Ua;var lh=v.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...o}=e,s=Fn("SelectScrollButton",n),i=v.useRef(null),a=Ws(n),l=v.useCallback(()=>{i.current!==null&&(window.clearInterval(i.current),i.current=null)},[]);return v.useEffect(()=>()=>l(),[l]),Tt(()=>{var d;const c=a().find(f=>f.ref.current===document.activeElement);(d=c==null?void 0:c.ref.current)==null||d.scrollIntoView({block:"nearest"})},[a]),u.jsx(_e.div,{"aria-hidden":!0,...o,ref:t,style:{flexShrink:0,...o.style},onPointerDown:de(o.onPointerDown,()=>{i.current===null&&(i.current=window.setInterval(r,50))}),onPointerMove:de(o.onPointerMove,()=>{var c;(c=s.onItemLeave)==null||c.call(s),i.current===null&&(i.current=window.setInterval(r,50))}),onPointerLeave:de(o.onPointerLeave,()=>{l()})})}),OC="SelectSeparator",ch=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return u.jsx(_e.div,{"aria-hidden":!0,...r,ref:t})});ch.displayName=OC;var Ha="SelectArrow",DC=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Vs(n),s=$n(Ha,n),i=Fn(Ha,n);return s.open&&i.position==="popper"?u.jsx(ou,{...o,...r,ref:t}):null});DC.displayName=Ha;var LC="SelectBubbleInput",uh=v.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const o=v.useRef(null),s=Be(r,o),i=$p(t);return v.useEffect(()=>{const a=o.current;if(!a)return;const l=window.HTMLSelectElement.prototype,d=Object.getOwnPropertyDescriptor(l,"value").set;if(i!==t&&d){const f=new Event("change",{bubbles:!0});d.call(a,t),a.dispatchEvent(f)}},[i,t]),u.jsx(_e.select,{...n,style:{...Fp,...n.style},ref:s,defaultValue:t})});uh.displayName=LC;function dh(e){return e===""||e===void 0}function fh(e){const t=kt(e),n=v.useRef(""),r=v.useRef(0),o=v.useCallback(i=>{const a=n.current+i;t(a),function l(c){n.current=c,window.clearTimeout(r.current),c!==""&&(r.current=window.setTimeout(()=>l(""),1e3))}(a)},[t]),s=v.useCallback(()=>{n.current="",window.clearTimeout(r.current)},[]);return v.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,o,s]}function ph(e,t,n){const o=t.length>1&&Array.from(t).every(c=>c===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let i=$C(e,Math.max(s,0));o.length===1&&(i=i.filter(c=>c!==n));const l=i.find(c=>c.textValue.toLowerCase().startsWith(o.toLowerCase()));return l!==n?l:void 0}function $C(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var FC=Bp,hh=Up,BC=Wp,zC=Vp,UC=Kp,mh=qp,HC=Jp,gh=eh,xh=nh,WC=rh,VC=sh,yh=ih,vh=ah,bh=ch;const wh=FC,Sh=BC,Wa=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(hh,{ref:r,className:ne("flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",e),...n,children:[t,u.jsx(zC,{asChild:!0,children:u.jsx(ae.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));Wa.displayName=hh.displayName;const Ch=v.forwardRef(({className:e,...t},n)=>u.jsx(yh,{ref:n,className:ne("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(ae.ChevronUp,{className:"h-4 w-4"})}));Ch.displayName=yh.displayName;const Th=v.forwardRef(({className:e,...t},n)=>u.jsx(vh,{ref:n,className:ne("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(ae.ChevronDown,{className:"h-4 w-4"})}));Th.displayName=vh.displayName;const Va=v.forwardRef(({className:e,children:t,position:n="popper",...r},o)=>u.jsx(UC,{children:u.jsxs(mh,{ref:o,className:ne("relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",n==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",e),position:n,...r,children:[u.jsx(Ch,{}),u.jsx(HC,{className:ne("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),u.jsx(Th,{})]})}));Va.displayName=mh.displayName;const KC=v.forwardRef(({className:e,...t},n)=>u.jsx(gh,{ref:n,className:ne("py-1.5 pl-8 pr-2 text-sm font-semibold",e),...t}));KC.displayName=gh.displayName;const sr=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(xh,{ref:r,className:ne("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(VC,{children:u.jsx(ae.Check,{className:"h-4 w-4"})})}),u.jsx(WC,{children:t})]}));sr.displayName=xh.displayName;const qC=v.forwardRef(({className:e,...t},n)=>u.jsx(bh,{ref:n,className:ne("-mx-1 my-1 h-px bg-muted",e),...t}));qC.displayName=bh.displayName;var GC="Separator",kh="horizontal",YC=["horizontal","vertical"],Ih=v.forwardRef((e,t)=>{const{decorative:n,orientation:r=kh,...o}=e,s=XC(r)?r:kh,a=n?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return u.jsx(_e.div,{"data-orientation":s,...a,...o,ref:t})});Ih.displayName=GC;function XC(e){return YC.includes(e)}var Eh=Ih;const Ah=v.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},o)=>u.jsx(Eh,{ref:o,decorative:n,orientation:t,className:ne("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));Ah.displayName=Eh.displayName;const JC=Bf,ZC=cS,QC=zf,Nh=v.forwardRef(({className:e,...t},n)=>u.jsx(Es,{className:ne("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}));Nh.displayName=Es.displayName;const eT=po.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"}}),_h=v.forwardRef(({side:e="right",className:t,children:n,...r},o)=>u.jsxs(QC,{children:[u.jsx(Nh,{}),u.jsxs(As,{ref:o,className:ne(eT({side:e}),t),...r,children:[n,u.jsxs(Uf,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-secondary",children:[u.jsx(ae.X,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));_h.displayName=As.displayName;const jh=({className:e,...t})=>u.jsx("div",{className:ne("flex flex-col space-y-2 text-center sm:text-left",e),...t});jh.displayName="SheetHeader";const Rh=v.forwardRef(({className:e,...t},n)=>u.jsx(tr,{ref:n,className:ne("text-lg font-semibold text-foreground",e),...t}));Rh.displayName=tr.displayName;const Mh=v.forwardRef(({className:e,...t},n)=>u.jsx(Ns,{ref:n,className:ne("text-sm text-muted-foreground",e),...t}));Mh.displayName=Ns.displayName;var qs="Switch",[tT,zT]=Sn(qs),[nT,rT]=tT(qs),Ph=v.forwardRef((e,t)=>{const{__scopeSwitch:n,name:r,checked:o,defaultChecked:s,required:i,disabled:a,value:l="on",onCheckedChange:c,form:d,...f}=e,[h,p]=v.useState(null),x=Be(t,S=>p(S)),m=v.useRef(!1),y=h?d||!!h.closest("form"):!0,[g,b]=pr({prop:o,defaultProp:s??!1,onChange:c,caller:qs});return u.jsxs(nT,{scope:n,checked:g,disabled:a,children:[u.jsx(_e.button,{type:"button",role:"switch","aria-checked":g,"aria-required":i,"data-state":$h(g),"data-disabled":a?"":void 0,disabled:a,value:l,...f,ref:x,onClick:de(e.onClick,S=>{b(k=>!k),y&&(m.current=S.isPropagationStopped(),m.current||S.stopPropagation())})}),y&&u.jsx(Lh,{control:h,bubbles:!m.current,name:r,value:l,checked:g,required:i,disabled:a,form:d,style:{transform:"translateX(-100%)"}})]})});Ph.displayName=qs;var Oh="SwitchThumb",Dh=v.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,o=rT(Oh,n);return u.jsx(_e.span,{"data-state":$h(o.checked),"data-disabled":o.disabled?"":void 0,...r,ref:t})});Dh.displayName=Oh;var oT="SwitchBubbleInput",Lh=v.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...o},s)=>{const i=v.useRef(null),a=Be(i,s),l=$p(n),c=Vc(t);return v.useEffect(()=>{const d=i.current;if(!d)return;const f=window.HTMLInputElement.prototype,p=Object.getOwnPropertyDescriptor(f,"checked").set;if(l!==n&&p){const x=new Event("click",{bubbles:r});p.call(d,n),d.dispatchEvent(x)}},[l,n,r]),u.jsx("input",{type:"checkbox","aria-hidden":!0,defaultChecked:n,...o,tabIndex:-1,ref:a,style:{...o.style,...c,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});Lh.displayName=oT;function $h(e){return e?"checked":"unchecked"}var Fh=Ph,sT=Dh;const Bn=v.forwardRef(({className:e,...t},n)=>u.jsx(Fh,{className:ne("peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",e),...t,ref:n,children:u.jsx(sT,{className:ne("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")})}));Bn.displayName=Fh.displayName;const iT={api:{baseUrl:"http://localhost:8000/api",authToken:"",enableAuth:!1},ui:{layout:"sidebar",theme:"light",showTimestamps:!0,showAgentNames:!0,compactMessages:!1},behavior:{autoSave:!0,enableStreaming:!0,showTypingIndicator:!0}};function aT({settings:e,onSettingsChange:t,className:n=""}){const[r,o]=w.useState(!1),[s,i]=w.useState(!1),[a,l]=w.useState(e),[c,d]=w.useState(!1),{toast:f}=Aa();w.useEffect(()=>{const y=JSON.stringify(a)!==JSON.stringify(e);d(y)},[a,e]),w.useEffect(()=>{l(e)},[e]);const h=()=>{t(a),d(!1),f({title:"Settings saved",description:"Your chat configuration has been updated successfully."})},p=()=>{l(iT),d(!0),f({title:"Settings reset",description:"Configuration has been reset to defaults."})},x=()=>{l(e),d(!1),o(!1)},m=async()=>{try{const g=await(await fetch(`${a.api.baseUrl}/health`)).json();f({title:"Connection successful",description:`API is ${g.status||"healthy"}`})}catch{f({title:"Connection failed",description:"Unable to connect to the API endpoint.",variant:"destructive"})}};return u.jsxs(JC,{open:r,onOpenChange:o,children:[u.jsx(ZC,{asChild:!0,children:u.jsxs(Xe,{variant:"outline",size:"sm",className:n,children:[u.jsx(ae.Settings,{className:"h-4 w-4 mr-2"}),"Settings",c&&u.jsx(yf,{variant:"destructive",className:"ml-2 h-4 w-4 p-0"})]})}),u.jsxs(_h,{className:"w-[500px] sm:w-[600px] overflow-y-auto",children:[u.jsxs(jh,{children:[u.jsx(Rh,{children:"Chat Settings"}),u.jsx(Mh,{children:"Configure your chat interface, API connection, and behavior preferences."})]}),u.jsxs("div",{className:"space-y-6 py-6",children:[u.jsxs(io,{children:[u.jsx(ao,{className:"pb-3",children:u.jsxs(lo,{className:"text-lg flex items-center gap-2",children:[u.jsx(ae.Server,{className:"h-5 w-5"}),"API Configuration"]})}),u.jsxs(co,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(en,{htmlFor:"api-url",children:"API Base URL"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx($s,{id:"api-url",value:a.api.baseUrl,onChange:y=>l(g=>({...g,api:{...g.api,baseUrl:y.target.value}})),placeholder:"http://localhost:8000/api"}),u.jsx(Xe,{variant:"outline",onClick:m,children:"Test"})]})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(en,{htmlFor:"enable-auth",children:"Enable Authentication"}),u.jsx(Bn,{id:"enable-auth",checked:a.api.enableAuth,onCheckedChange:y=>l(g=>({...g,api:{...g.api,enableAuth:y}}))})]}),a.api.enableAuth&&u.jsxs("div",{className:"space-y-2",children:[u.jsx(en,{htmlFor:"auth-token",children:"Authentication Token"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx($s,{id:"auth-token",type:s?"text":"password",value:a.api.authToken,onChange:y=>l(g=>({...g,api:{...g.api,authToken:y.target.value}})),placeholder:"Enter your Bearer token"}),u.jsx(Xe,{variant:"outline",size:"icon",onClick:()=>i(!s),children:s?u.jsx(ae.EyeOff,{className:"h-4 w-4"}):u.jsx(ae.Eye,{className:"h-4 w-4"})})]})]})]})]}),u.jsxs(io,{children:[u.jsx(ao,{className:"pb-3",children:u.jsxs(lo,{className:"text-lg flex items-center gap-2",children:[u.jsx(ae.Layout,{className:"h-5 w-5"}),"Interface Settings"]})}),u.jsxs(co,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(en,{htmlFor:"layout",children:"Layout Style"}),u.jsxs(wh,{value:a.ui.layout,onValueChange:y=>l(g=>({...g,ui:{...g.ui,layout:y}})),children:[u.jsx(Wa,{children:u.jsx(Sh,{})}),u.jsxs(Va,{children:[u.jsx(sr,{value:"sidebar",children:"Sidebar Layout"}),u.jsx(sr,{value:"fullscreen",children:"Fullscreen"}),u.jsx(sr,{value:"tabs",children:"Tabbed Interface"})]})]})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx(en,{htmlFor:"theme",children:"Theme"}),u.jsxs(wh,{value:a.ui.theme,onValueChange:y=>l(g=>({...g,ui:{...g.ui,theme:y}})),children:[u.jsx(Wa,{children:u.jsx(Sh,{})}),u.jsxs(Va,{children:[u.jsx(sr,{value:"light",children:"Light"}),u.jsx(sr,{value:"dark",children:"Dark"}),u.jsx(sr,{value:"system",children:"System"})]})]})]}),u.jsx(Ah,{}),u.jsxs("div",{className:"space-y-3",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(en,{htmlFor:"show-timestamps",children:"Show Timestamps"}),u.jsx(Bn,{id:"show-timestamps",checked:a.ui.showTimestamps,onCheckedChange:y=>l(g=>({...g,ui:{...g.ui,showTimestamps:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(en,{htmlFor:"show-agent-names",children:"Show Agent Names"}),u.jsx(Bn,{id:"show-agent-names",checked:a.ui.showAgentNames,onCheckedChange:y=>l(g=>({...g,ui:{...g.ui,showAgentNames:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(en,{htmlFor:"compact-messages",children:"Compact Messages"}),u.jsx(Bn,{id:"compact-messages",checked:a.ui.compactMessages,onCheckedChange:y=>l(g=>({...g,ui:{...g.ui,compactMessages:y}}))})]})]})]})]}),u.jsxs(io,{children:[u.jsx(ao,{className:"pb-3",children:u.jsxs(lo,{className:"text-lg flex items-center gap-2",children:[u.jsx(ae.MessageCircle,{className:"h-5 w-5"}),"Behavior Settings"]})}),u.jsxs(co,{className:"space-y-4",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(en,{htmlFor:"auto-save",children:"Auto-save Conversations"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Automatically save messages to threads"})]}),u.jsx(Bn,{id:"auto-save",checked:a.behavior.autoSave,onCheckedChange:y=>l(g=>({...g,behavior:{...g.behavior,autoSave:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(en,{htmlFor:"enable-streaming",children:"Enable Streaming"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Stream responses in real-time"})]}),u.jsx(Bn,{id:"enable-streaming",checked:a.behavior.enableStreaming,onCheckedChange:y=>l(g=>({...g,behavior:{...g.behavior,enableStreaming:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(en,{htmlFor:"typing-indicator",children:"Typing Indicator"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Show typing indicator during responses"})]}),u.jsx(Bn,{id:"typing-indicator",checked:a.behavior.showTypingIndicator,onCheckedChange:y=>l(g=>({...g,behavior:{...g.behavior,showTypingIndicator:y}}))})]})]})]})]}),u.jsxs("div",{className:"flex items-center justify-between pt-6 border-t",children:[u.jsxs(Xe,{variant:"outline",onClick:p,children:[u.jsx(ae.RotateCcw,{className:"h-4 w-4 mr-2"}),"Reset"]}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(Xe,{variant:"outline",onClick:x,children:"Cancel"}),u.jsxs(Xe,{onClick:h,disabled:!c,children:[u.jsx(ae.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=c=>{const d="h-full";switch(c){case"phone":return`${d} max-w-none`;case"tablet":return`${d} max-w-4xl mx-auto`;case"half-screen":return`${d} max-w-2xl`;case"desktop":default:return`${d} max-w-7xl mx-auto`}},a=c=>({"--chat-sidebar-width":c==="phone"?"100%":c==="tablet"?"280px":c==="half-screen"?"240px":"320px","--chat-message-max-width":c==="phone"?"95%":c==="tablet"?"90%":c==="half-screen"?"85%":"80%","--chat-input-height":c==="phone"?"120px":"100px"}),l=w.useCallback(c=>{var d;(d=s.onThreadChange)==null||d.call(s,c)},[s]);return e==="fullscreen"?u.jsx(Ro,{...s,onThreadChange:l,children:u.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:u.jsx(Ls,{className:"flex-1",onError:s.onError,enableFileUpload:!0})})}):e==="tabs"?u.jsx(Ro,{...s,onThreadChange:l,children:u.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:u.jsxs("div",{className:"flex-1 flex min-h-0 overflow-hidden",children:[n&&u.jsx("div",{className:`w-80 border-r flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:u.jsx(La,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),u.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:u.jsx(Ls,{onError:s.onError,enableFileUpload:!0})})]})})}):u.jsx(Ro,{...s,onThreadChange:l,children:u.jsxs("div",{className:`${i(t)} flex overflow-hidden ${r} ${o.container||""}`,style:a(t),children:[n&&u.jsx("div",{className:`w-80 border-r bg-gray-50 flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:u.jsx(La,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),u.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:u.jsx(Ls,{onError:s.onError,enableFileUpload:!0})})]})})}Ce.ChatApi=Bl,Ce.ChatInput=cc,Ce.ChatInterface=Ls,Ce.ChatProviders=Ro,Ce.ChatSettings=aT,Ce.MarkdownContent=so,Ce.MessageComponent=Ds,Ce.MessageList=ja,Ce.ThreadManager=La,Ce.TimelineColumn=lC,Ce.applySettings=pC,Ce.buildMessagePreviewMap=ql,Ce.chatApiClient=An,Ce.default=lT,Ce.del=Fl,Ce.get=qt,Ce.getChatToken=Dl,Ce.getCurrentSettings=fC,Ce.getDefaultApiConfig=Mp,Ce.getDefaultChatSettings=Pp,Ce.onChatTokenChanged=Ll,Ce.post=ci,Ce.put=$l,Ce.setChatToken=Io,Ce.useApi=ui,Ce.useChatStream=Gl,Ce.useMessagesReducer=Yl,Ce.useStream=ac,Ce.useThreadState=jo,Ce.useThreads=_o,Object.defineProperties(Ce,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|