@mastra/deployer-vercel 1.2.5-alpha.0 → 1.2.5-alpha.1
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/CHANGELOG.md +10 -0
- package/dist/index.cjs +3 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/studio/assets/{core-DmuC-0UU.js → core-B6cOHeaZ.js} +1 -1
- package/dist/studio/assets/{index-D2p72qtW.js → index-Cri75gQs.js} +2 -2
- package/dist/studio/assets/{main-CdpwwFH-.js → main-CKnCGTTa.js} +6 -6
- package/dist/studio/index.html +1 -1
- package/package.json +5 -5
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./core-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./core-B6cOHeaZ.js","./engine-compile-BkERmzkH.js","./preload-helper-PPVm8Dsz.js","./engine-javascript-CSIo_1eZ.js"])))=>i.map(i=>d[i]);
|
|
2
2
|
import{_ as jo}from"./preload-helper-PPVm8Dsz.js";function O7t(e,t){for(var n=0;n<t.length;n++){const r=t[n];if(typeof r!="string"&&!Array.isArray(r)){for(const s in r)if(s!=="default"&&!(s in e)){const a=Object.getOwnPropertyDescriptor(r,s);a&&Object.defineProperty(e,s,a.get?a:{enumerable:!0,get:()=>r[s]})}}}return Object.freeze(Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}))}var Bj=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Tc(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var fY={exports:{}},bA={};var ERe;function _7t(){if(ERe)return bA;ERe=1;var e=Symbol.for("react.transitional.element"),t=Symbol.for("react.fragment");function n(r,s,a){var i=null;if(a!==void 0&&(i=""+a),s.key!==void 0&&(i=""+s.key),"key"in s){a={};for(var l in s)l!=="key"&&(a[l]=s[l])}else a=s;return s=a.ref,{$$typeof:e,type:r,key:i,ref:s!==void 0?s:null,props:a}}return bA.Fragment=t,bA.jsx=n,bA.jsxs=n,bA}var jRe;function C7t(){return jRe||(jRe=1,fY.exports=_7t()),fY.exports}var o=C7t(),pY={exports:{}},Br={},TRe;function E7t(){if(TRe)return Br;TRe=1;var e={env:{}};var t=Symbol.for("react.transitional.element"),n=Symbol.for("react.portal"),r=Symbol.for("react.fragment"),s=Symbol.for("react.strict_mode"),a=Symbol.for("react.profiler"),i=Symbol.for("react.consumer"),l=Symbol.for("react.context"),c=Symbol.for("react.forward_ref"),u=Symbol.for("react.suspense"),d=Symbol.for("react.memo"),f=Symbol.for("react.lazy"),p=Symbol.for("react.activity"),h=Symbol.iterator;function m(V){return V===null||typeof V!="object"?null:(V=h&&V[h]||V["@@iterator"],typeof V=="function"?V:null)}var v={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},y=Object.assign,b={};function S(V,$,U){this.props=V,this.context=$,this.refs=b,this.updater=U||v}S.prototype.isReactComponent={},S.prototype.setState=function(V,$){if(typeof V!="object"&&typeof V!="function"&&V!=null)throw Error("takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,V,$,"setState")},S.prototype.forceUpdate=function(V){this.updater.enqueueForceUpdate(this,V,"forceUpdate")};function w(){}w.prototype=S.prototype;function k(V,$,U){this.props=V,this.context=$,this.refs=b,this.updater=U||v}var _=k.prototype=new w;_.constructor=k,y(_,S.prototype),_.isPureReactComponent=!0;var C=Array.isArray;function E(){}var j={H:null,A:null,T:null,S:null},N=Object.prototype.hasOwnProperty;function I(V,$,U){var Z=U.ref;return{$$typeof:t,type:V,key:$,ref:Z!==void 0?Z:null,props:U}}function R(V,$){return I(V.type,$,V.props)}function P(V){return typeof V=="object"&&V!==null&&V.$$typeof===t}function L(V){var $={"=":"=0",":":"=2"};return"$"+V.replace(/[=:]/g,function(U){return $[U]})}var M=/\/+/g;function q(V,$){return typeof V=="object"&&V!==null&&V.key!=null?L(""+V.key):$.toString(36)}function H(V){switch(V.status){case"fulfilled":return V.value;case"rejected":throw V.reason;default:switch(typeof V.status=="string"?V.then(E,E):(V.status="pending",V.then(function($){V.status==="pending"&&(V.status="fulfilled",V.value=$)},function($){V.status==="pending"&&(V.status="rejected",V.reason=$)})),V.status){case"fulfilled":return V.value;case"rejected":throw V.reason}}throw V}function F(V,$,U,Z,X){var te=typeof V;(te==="undefined"||te==="boolean")&&(V=null);var J=!1;if(V===null)J=!0;else switch(te){case"bigint":case"string":case"number":J=!0;break;case"object":switch(V.$$typeof){case t:case n:J=!0;break;case f:return J=V._init,F(J(V._payload),$,U,Z,X)}}if(J)return X=X(V),J=Z===""?"."+q(V,0):Z,C(X)?(U="",J!=null&&(U=J.replace(M,"$&/")+"/"),F(X,$,U,"",function(ce){return ce})):X!=null&&(P(X)&&(X=R(X,U+(X.key==null||V&&V.key===X.key?"":(""+X.key).replace(M,"$&/")+"/")+J)),$.push(X)),1;J=0;var ee=Z===""?".":Z+":";if(C(V))for(var ae=0;ae<V.length;ae++)Z=V[ae],te=ee+q(Z,ae),J+=F(Z,$,U,te,X);else if(ae=m(V),typeof ae=="function")for(V=ae.call(V),ae=0;!(Z=V.next()).done;)Z=Z.value,te=ee+q(Z,ae++),J+=F(Z,$,U,te,X);else if(te==="object"){if(typeof V.then=="function")return F(H(V),$,U,Z,X);throw $=String(V),Error("Objects are not valid as a React child (found: "+($==="[object Object]"?"object with keys {"+Object.keys(V).join(", ")+"}":$)+"). If you meant to render a collection of children, use an array instead.")}return J}function z(V,$,U){if(V==null)return V;var Z=[],X=0;return F(V,Z,"","",function(te){return $.call(U,te,X++)}),Z}function B(V){if(V._status===-1){var $=V._result;$=$(),$.then(function(U){(V._status===0||V._status===-1)&&(V._status=1,V._result=U)},function(U){(V._status===0||V._status===-1)&&(V._status=2,V._result=U)}),V._status===-1&&(V._status=0,V._result=$)}if(V._status===1)return V._result.default;throw V._result}var D=typeof reportError=="function"?reportError:function(V){if(typeof window=="object"&&typeof window.ErrorEvent=="function"){var $=new window.ErrorEvent("error",{bubbles:!0,cancelable:!0,message:typeof V=="object"&&V!==null&&typeof V.message=="string"?String(V.message):String(V),error:V});if(!window.dispatchEvent($))return}else if(typeof e=="object"&&typeof e.emit=="function"){e.emit("uncaughtException",V);return}console.error(V)},Q={map:z,forEach:function(V,$,U){z(V,function(){$.apply(this,arguments)},U)},count:function(V){var $=0;return z(V,function(){$++}),$},toArray:function(V){return z(V,function($){return $})||[]},only:function(V){if(!P(V))throw Error("React.Children.only expected to receive a single React element child.");return V}};return Br.Activity=p,Br.Children=Q,Br.Component=S,Br.Fragment=r,Br.Profiler=a,Br.PureComponent=k,Br.StrictMode=s,Br.Suspense=u,Br.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=j,Br.__COMPILER_RUNTIME={__proto__:null,c:function(V){return j.H.useMemoCache(V)}},Br.cache=function(V){return function(){return V.apply(null,arguments)}},Br.cacheSignal=function(){return null},Br.cloneElement=function(V,$,U){if(V==null)throw Error("The argument must be a React element, but you passed "+V+".");var Z=y({},V.props),X=V.key;if($!=null)for(te in $.key!==void 0&&(X=""+$.key),$)!N.call($,te)||te==="key"||te==="__self"||te==="__source"||te==="ref"&&$.ref===void 0||(Z[te]=$[te]);var te=arguments.length-2;if(te===1)Z.children=U;else if(1<te){for(var J=Array(te),ee=0;ee<te;ee++)J[ee]=arguments[ee+2];Z.children=J}return I(V.type,X,Z)},Br.createContext=function(V){return V={$$typeof:l,_currentValue:V,_currentValue2:V,_threadCount:0,Provider:null,Consumer:null},V.Provider=V,V.Consumer={$$typeof:i,_context:V},V},Br.createElement=function(V,$,U){var Z,X={},te=null;if($!=null)for(Z in $.key!==void 0&&(te=""+$.key),$)N.call($,Z)&&Z!=="key"&&Z!=="__self"&&Z!=="__source"&&(X[Z]=$[Z]);var J=arguments.length-2;if(J===1)X.children=U;else if(1<J){for(var ee=Array(J),ae=0;ae<J;ae++)ee[ae]=arguments[ae+2];X.children=ee}if(V&&V.defaultProps)for(Z in J=V.defaultProps,J)X[Z]===void 0&&(X[Z]=J[Z]);return I(V,te,X)},Br.createRef=function(){return{current:null}},Br.forwardRef=function(V){return{$$typeof:c,render:V}},Br.isValidElement=P,Br.lazy=function(V){return{$$typeof:f,_payload:{_status:-1,_result:V},_init:B}},Br.memo=function(V,$){return{$$typeof:d,type:V,compare:$===void 0?null:$}},Br.startTransition=function(V){var $=j.T,U={};j.T=U;try{var Z=V(),X=j.S;X!==null&&X(U,Z),typeof Z=="object"&&Z!==null&&typeof Z.then=="function"&&Z.then(E,D)}catch(te){D(te)}finally{$!==null&&U.types!==null&&($.types=U.types),j.T=$}},Br.unstable_useCacheRefresh=function(){return j.H.useCacheRefresh()},Br.use=function(V){return j.H.use(V)},Br.useActionState=function(V,$,U){return j.H.useActionState(V,$,U)},Br.useCallback=function(V,$){return j.H.useCallback(V,$)},Br.useContext=function(V){return j.H.useContext(V)},Br.useDebugValue=function(){},Br.useDeferredValue=function(V,$){return j.H.useDeferredValue(V,$)},Br.useEffect=function(V,$){return j.H.useEffect(V,$)},Br.useEffectEvent=function(V){return j.H.useEffectEvent(V)},Br.useId=function(){return j.H.useId()},Br.useImperativeHandle=function(V,$,U){return j.H.useImperativeHandle(V,$,U)},Br.useInsertionEffect=function(V,$){return j.H.useInsertionEffect(V,$)},Br.useLayoutEffect=function(V,$){return j.H.useLayoutEffect(V,$)},Br.useMemo=function(V,$){return j.H.useMemo(V,$)},Br.useOptimistic=function(V,$){return j.H.useOptimistic(V,$)},Br.useReducer=function(V,$,U){return j.H.useReducer(V,$,U)},Br.useRef=function(V){return j.H.useRef(V)},Br.useState=function(V){return j.H.useState(V)},Br.useSyncExternalStore=function(V,$,U){return j.H.useSyncExternalStore(V,$,U)},Br.useTransition=function(){return j.H.useTransition()},Br.version="19.2.6",Br}var NRe;function pN(){return NRe||(NRe=1,pY.exports=E7t()),pY.exports}var g=pN();const Le=Tc(g),hN=O7t({__proto__:null,default:Le},[g]);var hY={exports:{}},xA={},mY={exports:{}},gY={};var IRe;function j7t(){return IRe||(IRe=1,(function(e){function t(H,F){var z=H.length;H.push(F);e:for(;0<z;){var B=z-1>>>1,D=H[B];if(0<s(D,F))H[B]=F,H[z]=D,z=B;else break e}}function n(H){return H.length===0?null:H[0]}function r(H){if(H.length===0)return null;var F=H[0],z=H.pop();if(z!==F){H[0]=z;e:for(var B=0,D=H.length,Q=D>>>1;B<Q;){var V=2*(B+1)-1,$=H[V],U=V+1,Z=H[U];if(0>s($,z))U<D&&0>s(Z,$)?(H[B]=Z,H[U]=z,B=U):(H[B]=$,H[V]=z,B=V);else if(U<D&&0>s(Z,z))H[B]=Z,H[U]=z,B=U;else break e}}return F}function s(H,F){var z=H.sortIndex-F.sortIndex;return z!==0?z:H.id-F.id}if(e.unstable_now=void 0,typeof performance=="object"&&typeof performance.now=="function"){var a=performance;e.unstable_now=function(){return a.now()}}else{var i=Date,l=i.now();e.unstable_now=function(){return i.now()-l}}var c=[],u=[],d=1,f=null,p=3,h=!1,m=!1,v=!1,y=!1,b=typeof setTimeout=="function"?setTimeout:null,S=typeof clearTimeout=="function"?clearTimeout:null,w=typeof setImmediate<"u"?setImmediate:null;function k(H){for(var F=n(u);F!==null;){if(F.callback===null)r(u);else if(F.startTime<=H)r(u),F.sortIndex=F.expirationTime,t(c,F);else break;F=n(u)}}function _(H){if(v=!1,k(H),!m)if(n(c)!==null)m=!0,C||(C=!0,P());else{var F=n(u);F!==null&&q(_,F.startTime-H)}}var C=!1,E=-1,j=5,N=-1;function I(){return y?!0:!(e.unstable_now()-N<j)}function R(){if(y=!1,C){var H=e.unstable_now();N=H;var F=!0;try{e:{m=!1,v&&(v=!1,S(E),E=-1),h=!0;var z=p;try{t:{for(k(H),f=n(c);f!==null&&!(f.expirationTime>H&&I());){var B=f.callback;if(typeof B=="function"){f.callback=null,p=f.priorityLevel;var D=B(f.expirationTime<=H);if(H=e.unstable_now(),typeof D=="function"){f.callback=D,k(H),F=!0;break t}f===n(c)&&r(c),k(H)}else r(c);f=n(c)}if(f!==null)F=!0;else{var Q=n(u);Q!==null&&q(_,Q.startTime-H),F=!1}}break e}finally{f=null,p=z,h=!1}F=void 0}}finally{F?P():C=!1}}}var P;if(typeof w=="function")P=function(){w(R)};else if(typeof MessageChannel<"u"){var L=new MessageChannel,M=L.port2;L.port1.onmessage=R,P=function(){M.postMessage(null)}}else P=function(){b(R,0)};function q(H,F){E=b(function(){H(e.unstable_now())},F)}e.unstable_IdlePriority=5,e.unstable_ImmediatePriority=1,e.unstable_LowPriority=4,e.unstable_NormalPriority=3,e.unstable_Profiling=null,e.unstable_UserBlockingPriority=2,e.unstable_cancelCallback=function(H){H.callback=null},e.unstable_forceFrameRate=function(H){0>H||125<H?console.error("forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported"):j=0<H?Math.floor(1e3/H):5},e.unstable_getCurrentPriorityLevel=function(){return p},e.unstable_next=function(H){switch(p){case 1:case 2:case 3:var F=3;break;default:F=p}var z=p;p=F;try{return H()}finally{p=z}},e.unstable_requestPaint=function(){y=!0},e.unstable_runWithPriority=function(H,F){switch(H){case 1:case 2:case 3:case 4:case 5:break;default:H=3}var z=p;p=H;try{return F()}finally{p=z}},e.unstable_scheduleCallback=function(H,F,z){var B=e.unstable_now();switch(typeof z=="object"&&z!==null?(z=z.delay,z=typeof z=="number"&&0<z?B+z:B):z=B,H){case 1:var D=-1;break;case 2:D=250;break;case 5:D=1073741823;break;case 4:D=1e4;break;default:D=5e3}return D=z+D,H={id:d++,callback:F,priorityLevel:H,startTime:z,expirationTime:D,sortIndex:-1},z>B?(H.sortIndex=z,t(u,H),n(c)===null&&H===n(u)&&(v?(S(E),E=-1):v=!0,q(_,z-B))):(H.sortIndex=D,t(c,H),m||h||(m=!0,C||(C=!0,P()))),H},e.unstable_shouldYield=I,e.unstable_wrapCallback=function(H){var F=p;return function(){var z=p;p=F;try{return H.apply(this,arguments)}finally{p=z}}}})(gY)),gY}var ARe;function T7t(){return ARe||(ARe=1,mY.exports=j7t()),mY.exports}var vY={exports:{}},mu={};var RRe;function N7t(){if(RRe)return mu;RRe=1;var e=pN();function t(c){var u="https://react.dev/errors/"+c;if(1<arguments.length){u+="?args[]="+encodeURIComponent(arguments[1]);for(var d=2;d<arguments.length;d++)u+="&args[]="+encodeURIComponent(arguments[d])}return"Minified React error #"+c+"; visit "+u+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings."}function n(){}var r={d:{f:n,r:function(){throw Error(t(522))},D:n,C:n,L:n,m:n,X:n,S:n,M:n},p:0,findDOMNode:null},s=Symbol.for("react.portal");function a(c,u,d){var f=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:s,key:f==null?null:""+f,children:c,containerInfo:u,implementation:d}}var i=e.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;function l(c,u){if(c==="font")return"";if(typeof u=="string")return u==="use-credentials"?u:""}return mu.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=r,mu.createPortal=function(c,u){var d=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!u||u.nodeType!==1&&u.nodeType!==9&&u.nodeType!==11)throw Error(t(299));return a(c,u,null,d)},mu.flushSync=function(c){var u=i.T,d=r.p;try{if(i.T=null,r.p=2,c)return c()}finally{i.T=u,r.p=d,r.d.f()}},mu.preconnect=function(c,u){typeof c=="string"&&(u?(u=u.crossOrigin,u=typeof u=="string"?u==="use-credentials"?u:"":void 0):u=null,r.d.C(c,u))},mu.prefetchDNS=function(c){typeof c=="string"&&r.d.D(c)},mu.preinit=function(c,u){if(typeof c=="string"&&u&&typeof u.as=="string"){var d=u.as,f=l(d,u.crossOrigin),p=typeof u.integrity=="string"?u.integrity:void 0,h=typeof u.fetchPriority=="string"?u.fetchPriority:void 0;d==="style"?r.d.S(c,typeof u.precedence=="string"?u.precedence:void 0,{crossOrigin:f,integrity:p,fetchPriority:h}):d==="script"&&r.d.X(c,{crossOrigin:f,integrity:p,fetchPriority:h,nonce:typeof u.nonce=="string"?u.nonce:void 0})}},mu.preinitModule=function(c,u){if(typeof c=="string")if(typeof u=="object"&&u!==null){if(u.as==null||u.as==="script"){var d=l(u.as,u.crossOrigin);r.d.M(c,{crossOrigin:d,integrity:typeof u.integrity=="string"?u.integrity:void 0,nonce:typeof u.nonce=="string"?u.nonce:void 0})}}else u==null&&r.d.M(c)},mu.preload=function(c,u){if(typeof c=="string"&&typeof u=="object"&&u!==null&&typeof u.as=="string"){var d=u.as,f=l(d,u.crossOrigin);r.d.L(c,d,{crossOrigin:f,integrity:typeof u.integrity=="string"?u.integrity:void 0,nonce:typeof u.nonce=="string"?u.nonce:void 0,type:typeof u.type=="string"?u.type:void 0,fetchPriority:typeof u.fetchPriority=="string"?u.fetchPriority:void 0,referrerPolicy:typeof u.referrerPolicy=="string"?u.referrerPolicy:void 0,imageSrcSet:typeof u.imageSrcSet=="string"?u.imageSrcSet:void 0,imageSizes:typeof u.imageSizes=="string"?u.imageSizes:void 0,media:typeof u.media=="string"?u.media:void 0})}},mu.preloadModule=function(c,u){if(typeof c=="string")if(u){var d=l(u.as,u.crossOrigin);r.d.m(c,{as:typeof u.as=="string"&&u.as!=="script"?u.as:void 0,crossOrigin:d,integrity:typeof u.integrity=="string"?u.integrity:void 0})}else r.d.m(c)},mu.requestFormReset=function(c){r.d.r(c)},mu.unstable_batchedUpdates=function(c,u){return c(u)},mu.useFormState=function(c,u,d){return i.H.useFormState(c,u,d)},mu.useFormStatus=function(){return i.H.useHostTransitionStatus()},mu.version="19.2.6",mu}var PRe;function frt(){if(PRe)return vY.exports;PRe=1;function e(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(e)}catch(t){console.error(t)}}return e(),vY.exports=N7t(),vY.exports}var $Re;function I7t(){if($Re)return xA;$Re=1;var e={env:{}};var t=T7t(),n=pN(),r=frt();function s(x){var O="https://react.dev/errors/"+x;if(1<arguments.length){O+="?args[]="+encodeURIComponent(arguments[1]);for(var T=2;T<arguments.length;T++)O+="&args[]="+encodeURIComponent(arguments[T])}return"Minified React error #"+x+"; visit "+O+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings."}function a(x){return!(!x||x.nodeType!==1&&x.nodeType!==9&&x.nodeType!==11)}function i(x){var O=x,T=x;if(x.alternate)for(;O.return;)O=O.return;else{x=O;do O=x,(O.flags&4098)!==0&&(T=O.return),x=O.return;while(x)}return O.tag===3?T:null}function l(x){if(x.tag===13){var O=x.memoizedState;if(O===null&&(x=x.alternate,x!==null&&(O=x.memoizedState)),O!==null)return O.dehydrated}return null}function c(x){if(x.tag===31){var O=x.memoizedState;if(O===null&&(x=x.alternate,x!==null&&(O=x.memoizedState)),O!==null)return O.dehydrated}return null}function u(x){if(i(x)!==x)throw Error(s(188))}function d(x){var O=x.alternate;if(!O){if(O=i(x),O===null)throw Error(s(188));return O!==x?null:x}for(var T=x,A=O;;){var W=T.return;if(W===null)break;var G=W.alternate;if(G===null){if(A=W.return,A!==null){T=A;continue}break}if(W.child===G.child){for(G=W.child;G;){if(G===T)return u(W),x;if(G===A)return u(W),O;G=G.sibling}throw Error(s(188))}if(T.return!==A.return)T=W,A=G;else{for(var ie=!1,we=W.child;we;){if(we===T){ie=!0,T=W,A=G;break}if(we===A){ie=!0,A=W,T=G;break}we=we.sibling}if(!ie){for(we=G.child;we;){if(we===T){ie=!0,T=G,A=W;break}if(we===A){ie=!0,A=G,T=W;break}we=we.sibling}if(!ie)throw Error(s(189))}}if(T.alternate!==A)throw Error(s(190))}if(T.tag!==3)throw Error(s(188));return T.stateNode.current===T?x:O}function f(x){var O=x.tag;if(O===5||O===26||O===27||O===6)return x;for(x=x.child;x!==null;){if(O=f(x),O!==null)return O;x=x.sibling}return null}var p=Object.assign,h=Symbol.for("react.element"),m=Symbol.for("react.transitional.element"),v=Symbol.for("react.portal"),y=Symbol.for("react.fragment"),b=Symbol.for("react.strict_mode"),S=Symbol.for("react.profiler"),w=Symbol.for("react.consumer"),k=Symbol.for("react.context"),_=Symbol.for("react.forward_ref"),C=Symbol.for("react.suspense"),E=Symbol.for("react.suspense_list"),j=Symbol.for("react.memo"),N=Symbol.for("react.lazy"),I=Symbol.for("react.activity"),R=Symbol.for("react.memo_cache_sentinel"),P=Symbol.iterator;function L(x){return x===null||typeof x!="object"?null:(x=P&&x[P]||x["@@iterator"],typeof x=="function"?x:null)}var M=Symbol.for("react.client.reference");function q(x){if(x==null)return null;if(typeof x=="function")return x.$$typeof===M?null:x.displayName||x.name||null;if(typeof x=="string")return x;switch(x){case y:return"Fragment";case S:return"Profiler";case b:return"StrictMode";case C:return"Suspense";case E:return"SuspenseList";case I:return"Activity"}if(typeof x=="object")switch(x.$$typeof){case v:return"Portal";case k:return x.displayName||"Context";case w:return(x._context.displayName||"Context")+".Consumer";case _:var O=x.render;return x=x.displayName,x||(x=O.displayName||O.name||"",x=x!==""?"ForwardRef("+x+")":"ForwardRef"),x;case j:return O=x.displayName||null,O!==null?O:q(x.type)||"Memo";case N:O=x._payload,x=x._init;try{return q(x(O))}catch{}}return null}var H=Array.isArray,F=n.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,z=r.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,B={pending:!1,data:null,method:null,action:null},D=[],Q=-1;function V(x){return{current:x}}function $(x){0>Q||(x.current=D[Q],D[Q]=null,Q--)}function U(x,O){Q++,D[Q]=x.current,x.current=O}var Z=V(null),X=V(null),te=V(null),J=V(null);function ee(x,O){switch(U(te,O),U(X,x),U(Z,null),O.nodeType){case 9:case 11:x=(x=O.documentElement)&&(x=x.namespaceURI)?YAe(x):0;break;default:if(x=O.tagName,O=O.namespaceURI)O=YAe(O),x=XAe(O,x);else switch(x){case"svg":x=1;break;case"math":x=2;break;default:x=0}}$(Z),U(Z,x)}function ae(){$(Z),$(X),$(te)}function ce(x){x.memoizedState!==null&&U(J,x);var O=Z.current,T=XAe(O,x.type);O!==T&&(U(X,x),U(Z,T))}function Y(x){X.current===x&&($(Z),$(X)),J.current===x&&($(J),mA._currentValue=B)}var ne,ue;function pe(x){if(ne===void 0)try{throw Error()}catch(T){var O=T.stack.trim().match(/\n( *(at )?)/);ne=O&&O[1]||"",ue=-1<T.stack.indexOf(`
|
|
3
3
|
at`)?" (<anonymous>)":-1<T.stack.indexOf("@")?"@unknown:0:0":""}return`
|
|
4
4
|
`+ne+x+ue}var le=!1;function ve(x,O){if(!x||le)return"";le=!0;var T=Error.prepareStackTrace;Error.prepareStackTrace=void 0;try{var A={DetermineComponentFrameRoot:function(){try{if(O){var Ct=function(){throw Error()};if(Object.defineProperty(Ct.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(Ct,[])}catch(ft){var ct=ft}Reflect.construct(x,[],Ct)}else{try{Ct.call()}catch(ft){ct=ft}x.call(Ct.prototype)}}else{try{throw Error()}catch(ft){ct=ft}(Ct=x())&&typeof Ct.catch=="function"&&Ct.catch(function(){})}}catch(ft){if(ft&&ct&&typeof ft.stack=="string")return[ft.stack,ct.stack]}return[null,null]}};A.DetermineComponentFrameRoot.displayName="DetermineComponentFrameRoot";var W=Object.getOwnPropertyDescriptor(A.DetermineComponentFrameRoot,"name");W&&W.configurable&&Object.defineProperty(A.DetermineComponentFrameRoot,"name",{value:"DetermineComponentFrameRoot"});var G=A.DetermineComponentFrameRoot(),ie=G[0],we=G[1];if(ie&&we){var Be=ie.split(`
|
|
@@ -333,7 +333,7 @@ attempted value: ${i}
|
|
|
333
333
|
\${}
|
|
334
334
|
}
|
|
335
335
|
}`,{label:"class",detail:"definition",type:"keyword"}),zd('import {${names}} from "${module}"\n${}',{label:"import",detail:"named",type:"keyword"}),zd('import ${name} from "${module}"\n${}',{label:"import",detail:"default",type:"keyword"})],sbt=Wwe.concat([zd("interface ${name} {\n ${}\n}",{label:"interface",detail:"definition",type:"keyword"}),zd("type ${name} = ${type}",{label:"type",detail:"definition",type:"keyword"}),zd("enum ${name} {\n ${}\n}",{label:"enum",detail:"definition",type:"keyword"})]),GLe=new lgt,abt=new Set(["Script","Block","FunctionExpression","FunctionDeclaration","ArrowFunction","MethodDeclaration","ForStatement"]);function ZA(e){return(t,n)=>{let r=t.node.getChild("VariableDefinition");return r&&n(r,e),!0}}const j9n=["FunctionDeclaration"],T9n={FunctionDeclaration:ZA("function"),ClassDeclaration:ZA("class"),ClassExpression:()=>!0,EnumDeclaration:ZA("constant"),TypeAliasDeclaration:ZA("type"),NamespaceDeclaration:ZA("namespace"),VariableDefinition(e,t){e.matchContext(j9n)||t(e,"variable")},TypeDefinition(e,t){t(e,"type")},__proto__:null};function ibt(e,t){let n=GLe.get(t);if(n)return n;let r=[],s=!0;function a(i,l){let c=e.sliceString(i.from,i.to);r.push({label:c,type:l})}return t.cursor(Fa.IncludeAnonymous).iterate(i=>{if(s)s=!1;else if(i.name){let l=T9n[i.name];if(l&&l(i,a)||abt.has(i.name))return!1}else if(i.to-i.from>8192){for(let l of ibt(e,i.node))r.push(l);return!1}}),GLe.set(t,r),r}const w7=/^[\w$\xa1-\uffff][\w$\d\xa1-\uffff]*$/,Zwe=["TemplateString","String","RegExp","LineComment","BlockComment","VariableDefinition","TypeDefinition","Label","PropertyDefinition","PropertyName","PrivatePropertyDefinition","PrivatePropertyName","JSXText","JSXAttributeValue","JSXOpenTag","JSXCloseTag","JSXSelfClosingTag",".","?."];function obt(e){let t=hi(e.state).resolveInner(e.pos,-1);if(Zwe.indexOf(t.name)>-1)return null;let n=t.name=="VariableName"||t.to-t.from<20&&w7.test(e.state.sliceDoc(t.from,t.to));if(!n&&!e.explicit)return null;let r=[];for(let s=t;s;s=s.parent)abt.has(s.name)&&(r=r.concat(ibt(e.state.doc,s)));return{options:r,from:n?t.from:e.pos,validFor:w7}}function LK(e,t,n){var r;let s=[];for(;;){let a=t.firstChild,i;if(a?.name=="VariableName")return s.push(e(a)),{path:s.reverse(),name:n};if(a?.name=="MemberExpression"&&((r=i=a.lastChild)===null||r===void 0?void 0:r.name)=="PropertyName")s.push(e(i)),t=a;else return null}}function lbt(e){let t=r=>e.state.doc.sliceString(r.from,r.to),n=hi(e.state).resolveInner(e.pos,-1);return n.name=="PropertyName"?LK(t,n.parent,t(n)):(n.name=="."||n.name=="?.")&&n.parent.name=="MemberExpression"?LK(t,n.parent,""):Zwe.indexOf(n.name)>-1?null:n.name=="VariableName"||n.to-n.from<20&&w7.test(t(n))?{path:[],name:t(n)}:n.name=="MemberExpression"?LK(t,n,""):e.explicit?{path:[],name:""}:null}function N9n(e,t){let n=e,r=[],s=new Set;for(let a=0;;a++){for(let l of(Object.getOwnPropertyNames||Object.keys)(e)){if(!/^[a-zA-Z_$\xaa-\uffdc][\w$\xaa-\uffdc]*$/.test(l)||s.has(l))continue;s.add(l);let c;try{c=n[l]}catch{continue}r.push({label:l,type:typeof c=="function"?/^[A-Z]/.test(l)?"class":t?"function":"method":t?"variable":"property",boost:-a})}let i=Object.getPrototypeOf(e);if(!i)return r;e=i}}function I9n(e){let t=new Map;return n=>{let r=lbt(n);if(!r)return null;let s=e;for(let i of r.path)if(s=s[i],!s)return null;let a=t.get(s);return a||t.set(s,a=N9n(s,!r.path.length)),{from:n.pos-r.name.length,options:a,validFor:w7}}}const Zh=jO.define({name:"javascript",parser:E9n.configure({props:[N_.add({IfStatement:Sj({except:/^\s*({|else\b)/}),TryStatement:Sj({except:/^\s*({|catch\b|finally\b)/}),LabeledStatement:_4n,SwitchBody:e=>{let t=e.textAfter,n=/^\s*\}/.test(t),r=/^\s*(case|default)\b/.test(t);return e.baseIndent+(n?0:r?1:2)*e.unit},Block:O4n({closing:"}"}),ArrowFunction:e=>e.baseIndent+e.unit,"TemplateString BlockComment":()=>null,"Statement Property":Sj({except:/^\s*{/}),JSXElement(e){let t=/^\s*<\//.test(e.textAfter);return e.lineIndent(e.node.from)+(t?0:e.unit)},JSXEscape(e){let t=/\s*\}/.test(e.textAfter);return e.lineIndent(e.node.from)+(t?0:e.unit)},"JSXOpenTag JSXSelfClosingTag"(e){return e.column(e.node.from)+e.unit}}),I_.add({"Block ClassBody SwitchBody EnumBody ObjectExpression ArrayExpression ObjectType":Cwe,BlockComment(e){return{from:e.from+2,to:e.to-2}},JSXElement(e){let t=e.firstChild;if(!t||t.name=="JSXSelfClosingTag")return null;let n=e.lastChild;return{from:t.to,to:n.type.isError?e.to:n.from}},"JSXSelfClosingTag JSXOpenTag"(e){var t;let n=(t=e.firstChild)===null||t===void 0?void 0:t.nextSibling,r=e.lastChild;return!n||n.type.isError?null:{from:n.to,to:r.type.isError?e.to:r.from}}})]}),languageData:{closeBrackets:{brackets:["(","[","{","'",'"',"`"]},commentTokens:{line:"//",block:{open:"/*",close:"*/"}},indentOnInput:/^\s*(?:case |default:|\{|\}|<\/)$/,wordChars:"$"}}),cbt={test:e=>/^JSX/.test(e.name),facet:xV({commentTokens:{block:{open:"{/*",close:"*/}"}}})},Gwe=Zh.configure({dialect:"ts"},"typescript"),Qwe=Zh.configure({dialect:"jsx",props:[kwe.add(e=>e.isTop?[cbt]:void 0)]}),Ywe=Zh.configure({dialect:"jsx ts",props:[kwe.add(e=>e.isTop?[cbt]:void 0)]},"typescript");let ubt=e=>({label:e,type:"keyword"});const dbt="break case const continue default delete export extends false finally in instanceof let new return static super switch this throw true typeof var yield".split(" ").map(ubt),A9n=dbt.concat(["declare","implements","private","protected","public"].map(ubt));function S7(e={}){let t=e.jsx?e.typescript?Ywe:Qwe:e.typescript?Gwe:Zh,n=e.typescript?sbt.concat(A9n):Wwe.concat(dbt);return new NO(t,[Zh.data.of({autocomplete:u5n(Zwe,cyt(n))}),Zh.data.of({autocomplete:obt}),e.jsx?fbt:[]])}function R9n(e){for(;;){if(e.name=="JSXOpenTag"||e.name=="JSXSelfClosingTag"||e.name=="JSXFragmentTag")return e;if(e.name=="JSXEscape"||!e.parent)return null;e=e.parent}}function QLe(e,t,n=e.length){for(let r=t?.firstChild;r;r=r.nextSibling)if(r.name=="JSXIdentifier"||r.name=="JSXBuiltin"||r.name=="JSXNamespacedName"||r.name=="JSXMemberExpression")return e.sliceString(r.from,Math.min(r.to,n));return""}const P9n=typeof navigator=="object"&&/Android\b/.test(navigator.userAgent),fbt=It.inputHandler.of((e,t,n,r,s)=>{if((P9n?e.composing:e.compositionStarted)||e.state.readOnly||t!=n||r!=">"&&r!="/"||!Zh.isActiveAt(e.state,t,-1))return!1;let a=s(),{state:i}=a,l=i.changeByRange(c=>{var u;let{head:d}=c,f=hi(i).resolveInner(d-1,-1),p;if(f.name=="JSXStartTag"&&(f=f.parent),!(i.doc.sliceString(d-1,d)!=r||f.name=="JSXAttributeValue"&&f.to>d)){if(r==">"&&f.name=="JSXFragmentTag")return{range:c,changes:{from:d,insert:"</>"}};if(r=="/"&&f.name=="JSXStartCloseTag"){let h=f.parent,m=h.parent;if(m&&h.from==d-2&&((p=QLe(i.doc,m.firstChild,d))||((u=m.firstChild)===null||u===void 0?void 0:u.name)=="JSXFragmentTag")){let v=`${p}>`;return{range:xt.cursor(d+v.length,-1),changes:{from:d,insert:v}}}}else if(r==">"){let h=R9n(f);if(h&&h.name=="JSXOpenTag"&&!/^\/?>|^<\//.test(i.doc.sliceString(d,d+2))&&(p=QLe(i.doc,h,d)))return{range:c,changes:{from:d,insert:`</${p}>`}}}}return{range:c}});return l.changes.empty?!1:(e.dispatch([a,i.update(l,{userEvent:"input.complete",scrollIntoView:!0})]),!0)});function $9n(e,t){return t||(t={parserOptions:{ecmaVersion:2019,sourceType:"module"},env:{browser:!0,node:!0,es6:!0,es2015:!0,es2017:!0,es2020:!0},rules:{}},e.getRules().forEach((n,r)=>{var s;!((s=n.meta.docs)===null||s===void 0)&&s.recommended&&(t.rules[r]=2)})),n=>{let{state:r}=n,s=[];for(let{from:a,to:i}of Zh.findRegions(r)){let l=r.doc.lineAt(a),c={line:l.number-1,col:a-l.from,pos:a};for(let u of e.verify(r.sliceDoc(a,i),t))s.push(M9n(u,r.doc,c))}return s}}function YLe(e,t,n,r){return n.line(e+r.line).from+t+(e==1?r.col-1:-1)}function M9n(e,t,n){let r=YLe(e.line,e.column,t,n),s={from:r,to:e.endLine!=null&&e.endColumn!=1?YLe(e.endLine,e.endColumn,t,n):r,message:e.message,source:e.ruleId?"eslint:"+e.ruleId:"eslint",severity:e.severity==1?"warning":"error"};if(e.fix){let{range:a,text:i}=e.fix,l=a[0]+n.pos-r,c=a[1]+n.pos-r;s.actions=[{name:"fix",apply(u,d){u.dispatch({changes:{from:d+l,to:d+c,insert:i},scrollIntoView:!0})}}]}return s}const b6=Object.freeze(Object.defineProperty({__proto__:null,autoCloseTags:fbt,completionPath:lbt,esLint:$9n,javascript:S7,javascriptLanguage:Zh,jsxLanguage:Qwe,localCompletionSource:obt,scopeCompletionSource:I9n,snippets:Wwe,tsxLanguage:Ywe,typescriptLanguage:Gwe,typescriptSnippets:sbt},Symbol.toStringTag,{value:"Module"})),GA=["_blank","_self","_top","_parent"],FK=["ascii","utf-8","utf-16","latin1","latin1"],zK=["get","post","put","delete"],BK=["application/x-www-form-urlencoded","multipart/form-data","text/plain"],Gf=["true","false"],Jn={},D9n={a:{attrs:{href:null,ping:null,type:null,media:null,target:GA,hreflang:null}},abbr:Jn,address:Jn,area:{attrs:{alt:null,coords:null,href:null,target:null,ping:null,media:null,hreflang:null,type:null,shape:["default","rect","circle","poly"]}},article:Jn,aside:Jn,audio:{attrs:{src:null,mediagroup:null,crossorigin:["anonymous","use-credentials"],preload:["none","metadata","auto"],autoplay:["autoplay"],loop:["loop"],controls:["controls"]}},b:Jn,base:{attrs:{href:null,target:GA}},bdi:Jn,bdo:Jn,blockquote:{attrs:{cite:null}},body:Jn,br:Jn,button:{attrs:{form:null,formaction:null,name:null,value:null,autofocus:["autofocus"],disabled:["autofocus"],formenctype:BK,formmethod:zK,formnovalidate:["novalidate"],formtarget:GA,type:["submit","reset","button"]}},canvas:{attrs:{width:null,height:null}},caption:Jn,center:Jn,cite:Jn,code:Jn,col:{attrs:{span:null}},colgroup:{attrs:{span:null}},command:{attrs:{type:["command","checkbox","radio"],label:null,icon:null,radiogroup:null,command:null,title:null,disabled:["disabled"],checked:["checked"]}},data:{attrs:{value:null}},datagrid:{attrs:{disabled:["disabled"],multiple:["multiple"]}},datalist:{attrs:{data:null}},dd:Jn,del:{attrs:{cite:null,datetime:null}},details:{attrs:{open:["open"]}},dfn:Jn,div:Jn,dl:Jn,dt:Jn,em:Jn,embed:{attrs:{src:null,type:null,width:null,height:null}},eventsource:{attrs:{src:null}},fieldset:{attrs:{disabled:["disabled"],form:null,name:null}},figcaption:Jn,figure:Jn,footer:Jn,form:{attrs:{action:null,name:null,"accept-charset":FK,autocomplete:["on","off"],enctype:BK,method:zK,novalidate:["novalidate"],target:GA}},h1:Jn,h2:Jn,h3:Jn,h4:Jn,h5:Jn,h6:Jn,head:{children:["title","base","link","style","meta","script","noscript","command"]},header:Jn,hgroup:Jn,hr:Jn,html:{attrs:{manifest:null}},i:Jn,iframe:{attrs:{src:null,srcdoc:null,name:null,width:null,height:null,sandbox:["allow-top-navigation","allow-same-origin","allow-forms","allow-scripts"],seamless:["seamless"]}},img:{attrs:{alt:null,src:null,ismap:null,usemap:null,width:null,height:null,crossorigin:["anonymous","use-credentials"]}},input:{attrs:{alt:null,dirname:null,form:null,formaction:null,height:null,list:null,max:null,maxlength:null,min:null,name:null,pattern:null,placeholder:null,size:null,src:null,step:null,value:null,width:null,accept:["audio/*","video/*","image/*"],autocomplete:["on","off"],autofocus:["autofocus"],checked:["checked"],disabled:["disabled"],formenctype:BK,formmethod:zK,formnovalidate:["novalidate"],formtarget:GA,multiple:["multiple"],readonly:["readonly"],required:["required"],type:["hidden","text","search","tel","url","email","password","datetime","date","month","week","time","datetime-local","number","range","color","checkbox","radio","file","submit","image","reset","button"]}},ins:{attrs:{cite:null,datetime:null}},kbd:Jn,keygen:{attrs:{challenge:null,form:null,name:null,autofocus:["autofocus"],disabled:["disabled"],keytype:["RSA"]}},label:{attrs:{for:null,form:null}},legend:Jn,li:{attrs:{value:null}},link:{attrs:{href:null,type:null,hreflang:null,media:null,sizes:["all","16x16","16x16 32x32","16x16 32x32 64x64"]}},map:{attrs:{name:null}},mark:Jn,menu:{attrs:{label:null,type:["list","context","toolbar"]}},meta:{attrs:{content:null,charset:FK,name:["viewport","application-name","author","description","generator","keywords"],"http-equiv":["content-language","content-type","default-style","refresh"]}},meter:{attrs:{value:null,min:null,low:null,high:null,max:null,optimum:null}},nav:Jn,noscript:Jn,object:{attrs:{data:null,type:null,name:null,usemap:null,form:null,width:null,height:null,typemustmatch:["typemustmatch"]}},ol:{attrs:{reversed:["reversed"],start:null,type:["1","a","A","i","I"]},children:["li","script","template","ul","ol"]},optgroup:{attrs:{disabled:["disabled"],label:null}},option:{attrs:{disabled:["disabled"],label:null,selected:["selected"],value:null}},output:{attrs:{for:null,form:null,name:null}},p:Jn,param:{attrs:{name:null,value:null}},pre:Jn,progress:{attrs:{value:null,max:null}},q:{attrs:{cite:null}},rp:Jn,rt:Jn,ruby:Jn,samp:Jn,script:{attrs:{type:["text/javascript"],src:null,async:["async"],defer:["defer"],charset:FK}},section:Jn,select:{attrs:{form:null,name:null,size:null,autofocus:["autofocus"],disabled:["disabled"],multiple:["multiple"]}},slot:{attrs:{name:null}},small:Jn,source:{attrs:{src:null,type:null,media:null}},span:Jn,strong:Jn,style:{attrs:{type:["text/css"],media:null,scoped:null}},sub:Jn,summary:Jn,sup:Jn,table:Jn,tbody:Jn,td:{attrs:{colspan:null,rowspan:null,headers:null}},template:Jn,textarea:{attrs:{dirname:null,form:null,maxlength:null,name:null,placeholder:null,rows:null,cols:null,autofocus:["autofocus"],disabled:["disabled"],readonly:["readonly"],required:["required"],wrap:["soft","hard"]}},tfoot:Jn,th:{attrs:{colspan:null,rowspan:null,headers:null,scope:["row","col","rowgroup","colgroup"]}},thead:Jn,time:{attrs:{datetime:null}},title:Jn,tr:Jn,track:{attrs:{src:null,label:null,default:null,kind:["subtitles","captions","descriptions","chapters","metadata"],srclang:null}},ul:{children:["li","script","template","ul","ol"]},var:Jn,video:{attrs:{src:null,poster:null,width:null,height:null,crossorigin:["anonymous","use-credentials"],preload:["auto","metadata","none"],autoplay:["autoplay"],mediagroup:["movie"],muted:["muted"],controls:["controls"]}},wbr:Jn},pbt={accesskey:null,class:null,contenteditable:Gf,contextmenu:null,dir:["ltr","rtl","auto"],draggable:["true","false","auto"],dropzone:["copy","move","link","string:","file:"],hidden:["hidden"],id:null,inert:["inert"],itemid:null,itemprop:null,itemref:null,itemscope:["itemscope"],itemtype:null,lang:["ar","bn","de","en-GB","en-US","es","fr","hi","id","ja","pa","pt","ru","tr","zh"],spellcheck:Gf,autocorrect:Gf,autocapitalize:Gf,style:null,tabindex:null,title:null,translate:["yes","no"],rel:["stylesheet","alternate","author","bookmark","help","license","next","nofollow","noreferrer","prefetch","prev","search","tag"],role:"alert application article banner button cell checkbox complementary contentinfo dialog document feed figure form grid gridcell heading img list listbox listitem main navigation region row rowgroup search switch tab table tabpanel textbox timer".split(" "),"aria-activedescendant":null,"aria-atomic":Gf,"aria-autocomplete":["inline","list","both","none"],"aria-busy":Gf,"aria-checked":["true","false","mixed","undefined"],"aria-controls":null,"aria-describedby":null,"aria-disabled":Gf,"aria-dropeffect":null,"aria-expanded":["true","false","undefined"],"aria-flowto":null,"aria-grabbed":["true","false","undefined"],"aria-haspopup":Gf,"aria-hidden":Gf,"aria-invalid":["true","false","grammar","spelling"],"aria-label":null,"aria-labelledby":null,"aria-level":null,"aria-live":["off","polite","assertive"],"aria-multiline":Gf,"aria-multiselectable":Gf,"aria-owns":null,"aria-posinset":null,"aria-pressed":["true","false","mixed","undefined"],"aria-readonly":Gf,"aria-relevant":null,"aria-required":Gf,"aria-selected":["true","false","undefined"],"aria-setsize":null,"aria-sort":["ascending","descending","none","other"],"aria-valuemax":null,"aria-valuemin":null,"aria-valuenow":null,"aria-valuetext":null},hbt="beforeunload copy cut dragstart dragover dragleave dragenter dragend drag paste focus blur change click load mousedown mouseenter mouseleave mouseup keydown keyup resize scroll unload".split(" ").map(e=>"on"+e);for(let e of hbt)pbt[e]=null;class Y${constructor(t,n){this.tags={...D9n,...t},this.globalAttrs={...pbt,...n},this.allTags=Object.keys(this.tags),this.globalAttrNames=Object.keys(this.globalAttrs)}}Y$.default=new Y$;function yT(e,t,n=e.length){if(!t)return"";let r=t.firstChild,s=r&&r.getChild("TagName");return s?e.sliceString(s.from,Math.min(s.to,n)):""}function bT(e,t=!1){for(;e;e=e.parent)if(e.name=="Element")if(t)t=!1;else return e;return null}function mbt(e,t,n){let r=n.tags[yT(e,bT(t))];return r?.children||n.allTags}function Xwe(e,t){let n=[];for(let r=bT(t);r&&!r.type.isTop;r=bT(r.parent)){let s=yT(e,r);if(s&&r.lastChild.name=="CloseTag")break;s&&n.indexOf(s)<0&&(t.name=="EndTag"||t.from>=r.firstChild.to)&&n.push(s)}return n}const gbt=/^[:\-\.\w\u00b7-\uffff]*$/;function XLe(e,t,n,r,s){let a=/\s*>/.test(e.sliceDoc(s,s+5))?"":">",i=bT(n,n.name=="StartTag"||n.name=="TagName");return{from:r,to:s,options:mbt(e.doc,i,t).map(l=>({label:l,type:"type"})).concat(Xwe(e.doc,n).map((l,c)=>({label:"/"+l,apply:"/"+l+a,type:"type",boost:99-c}))),validFor:/^\/?[:\-\.\w\u00b7-\uffff]*$/}}function KLe(e,t,n,r){let s=/\s*>/.test(e.sliceDoc(r,r+5))?"":">";return{from:n,to:r,options:Xwe(e.doc,t).map((a,i)=>({label:a,apply:a+s,type:"type",boost:99-i})),validFor:gbt}}function L9n(e,t,n,r){let s=[],a=0;for(let i of mbt(e.doc,n,t))s.push({label:"<"+i,type:"type"});for(let i of Xwe(e.doc,n))s.push({label:"</"+i+">",type:"type",boost:99-a++});return{from:r,to:r,options:s,validFor:/^<\/?[:\-\.\w\u00b7-\uffff]*$/}}function F9n(e,t,n,r,s){let a=bT(n),i=a?t.tags[yT(e.doc,a)]:null,l=i&&i.attrs?Object.keys(i.attrs):[],c=i&&i.globalAttrs===!1?l:l.length?l.concat(t.globalAttrNames):t.globalAttrNames;return{from:r,to:s,options:c.map(u=>({label:u,type:"property"})),validFor:gbt}}function z9n(e,t,n,r,s){var a;let i=(a=n.parent)===null||a===void 0?void 0:a.getChild("AttributeName"),l=[],c;if(i){let u=e.sliceDoc(i.from,i.to),d=t.globalAttrs[u];if(!d){let f=bT(n),p=f?t.tags[yT(e.doc,f)]:null;d=p?.attrs&&p.attrs[u]}if(d){let f=e.sliceDoc(r,s).toLowerCase(),p='"',h='"';/^['"]/.test(f)?(c=f[0]=='"'?/^[^"]*$/:/^[^']*$/,p="",h=e.sliceDoc(s,s+1)==f[0]?"":f[0],f=f.slice(1),r++):c=/^[^\s<>='"]*$/;for(let m of d)l.push({label:m,apply:p+m+h,type:"constant"})}}return{from:r,to:s,options:l,validFor:c}}function vbt(e,t){let{state:n,pos:r}=t,s=hi(n).resolveInner(r,-1),a=s.resolve(r);for(let i=r,l;a==s&&(l=s.childBefore(i));){let c=l.lastChild;if(!c||!c.type.isError||c.from<c.to)break;a=s=l,i=c.from}return s.name=="TagName"?s.parent&&/CloseTag$/.test(s.parent.name)?KLe(n,s,s.from,r):XLe(n,e,s,s.from,r):s.name=="StartTag"||s.name=="IncompleteTag"?XLe(n,e,s,r,r):s.name=="StartCloseTag"||s.name=="IncompleteCloseTag"?KLe(n,s,r,r):s.name=="OpenTag"||s.name=="SelfClosingTag"||s.name=="AttributeName"?F9n(n,e,s,s.name=="AttributeName"?s.from:r,r):s.name=="Is"||s.name=="AttributeValue"||s.name=="UnquotedAttributeValue"?z9n(n,e,s,s.name=="Is"?r:s.from,r):t.explicit&&(a.name=="Element"||a.name=="Text"||a.name=="Document")?L9n(n,e,s,r):null}function B9n(e){return vbt(Y$.default,e)}function U9n(e){let{extraTags:t,extraGlobalAttributes:n}=e,r=n||t?new Y$(t,n):Y$.default;return s=>vbt(r,s)}const q9n=Zh.parser.configure({top:"SingleExpression"}),ybt=[{tag:"script",attrs:e=>e.type=="text/typescript"||e.lang=="ts",parser:Gwe.parser},{tag:"script",attrs:e=>e.type=="text/babel"||e.type=="text/jsx",parser:Qwe.parser},{tag:"script",attrs:e=>e.type=="text/typescript-jsx",parser:Ywe.parser},{tag:"script",attrs(e){return/^(importmap|speculationrules|application\/(.+\+)?json)$/i.test(e.type)},parser:q9n},{tag:"script",attrs(e){return!e.type||/^(?:text|application)\/(?:x-)?(?:java|ecma)script$|^module$|^$/i.test(e.type)},parser:Zh.parser},{tag:"style",attrs(e){return(!e.lang||e.lang=="css")&&(!e.type||/^(text\/)?(x-)?(stylesheet|css)$/i.test(e.type))},parser:x7.parser}],bbt=[{name:"style",parser:x7.parser.configure({top:"Styles"})}].concat(hbt.map(e=>({name:e,parser:Zh.parser}))),xbt=jO.define({name:"html",parser:h6n.configure({props:[N_.add({Element(e){let t=/^(\s*)(<\/)?/.exec(e.textAfter);return e.node.to<=e.pos+t[0].length?e.continue():e.lineIndent(e.node.from)+(t[2]?0:e.unit)},"OpenTag CloseTag SelfClosingTag"(e){return e.column(e.node.from)+e.unit},Document(e){if(e.pos+/\s*/.exec(e.textAfter)[0].length<e.node.to)return e.continue();let t=null,n;for(let r=e.node;;){let s=r.lastChild;if(!s||s.name!="Element"||s.to!=r.to)break;t=r=s}return t&&!((n=t.lastChild)&&(n.name=="CloseTag"||n.name=="SelfClosingTag"))?e.lineIndent(t.from)+e.unit:null}}),I_.add({Element(e){let t=e.firstChild,n=e.lastChild;return!t||t.name!="OpenTag"?null:{from:t.to,to:n.name=="CloseTag"?n.from:e.to}}}),nyt.add({"OpenTag CloseTag":e=>e.getChild("TagName")})]}),languageData:{commentTokens:{block:{open:"<!--",close:"-->"}},indentOnInput:/^\s*<\/\w+\W$/,wordChars:"-_"}}),YF=xbt.configure({wrap:Xyt(ybt,bbt)});function V9n(e={}){let t="",n;e.matchClosingTags===!1&&(t="noMatch"),e.selfClosingTags===!0&&(t=(t?t+" ":"")+"selfClosing"),(e.nestedLanguages&&e.nestedLanguages.length||e.nestedAttributes&&e.nestedAttributes.length)&&(n=Xyt((e.nestedLanguages||[]).concat(ybt),(e.nestedAttributes||[]).concat(bbt)));let r=n?xbt.configure({wrap:n,dialect:t}):t?YF.configure({dialect:t}):YF;return new NO(r,[YF.data.of({autocomplete:U9n(e)}),e.autoCloseTags!==!1?H9n:[],S7().support,Y6n().support])}const JLe=new Set("area base br col command embed frame hr img input keygen link meta param source track wbr menuitem".split(" ")),H9n=It.inputHandler.of((e,t,n,r,s)=>{if(e.composing||e.state.readOnly||t!=n||r!=">"&&r!="/"||!YF.isActiveAt(e.state,t,-1))return!1;let a=s(),{state:i}=a,l=i.changeByRange(c=>{var u,d,f;let p=i.doc.sliceString(c.from-1,c.to)==r,{head:h}=c,m=hi(i).resolveInner(h,-1),v;if(p&&r==">"&&m.name=="EndTag"){let y=m.parent;if(((d=(u=y.parent)===null||u===void 0?void 0:u.lastChild)===null||d===void 0?void 0:d.name)!="CloseTag"&&(v=yT(i.doc,y.parent,h))&&!JLe.has(v)){let b=h+(i.doc.sliceString(h,h+1)===">"?1:0),S=`</${v}>`;return{range:c,changes:{from:h,to:b,insert:S}}}}else if(p&&r=="/"&&m.name=="IncompleteCloseTag"){let y=m.parent;if(m.from==h-2&&((f=y.lastChild)===null||f===void 0?void 0:f.name)!="CloseTag"&&(v=yT(i.doc,y,h))&&!JLe.has(v)){let b=h+(i.doc.sliceString(h,h+1)===">"?1:0),S=`${v}>`;return{range:xt.cursor(h+S.length,-1),changes:{from:h,to:b,insert:S}}}}return{range:c}});return l.changes.empty?!1:(e.dispatch([a,i.update(l,{userEvent:"input.complete",scrollIntoView:!0})]),!0)}),wbt=xV({commentTokens:{block:{open:"<!--",close:"-->"}}}),Sbt=new Pr,kbt=gLn.configure({props:[I_.add(e=>!e.is("Block")||e.is("Document")||ghe(e)!=null||W9n(e)?void 0:(t,n)=>({from:n.doc.lineAt(t.from).to,to:t.to})),Sbt.add(ghe),N_.add({Document:()=>null}),vw.add({Document:wbt})]});function ghe(e){let t=/^(?:ATX|Setext)Heading(\d)$/.exec(e.name);return t?+t[1]:void 0}function W9n(e){return e.name=="OrderedList"||e.name=="BulletList"}function Z9n(e,t){let n=e;for(;;){let r=n.nextSibling,s;if(!r||(s=ghe(r.type))!=null&&s<=t)break;n=r}return n.to}const G9n=Vvt.of((e,t,n)=>{for(let r=hi(e).resolveInner(n,-1);r&&!(r.from<t);r=r.parent){let s=r.type.prop(Sbt);if(s==null)continue;let a=Z9n(r,s);if(a>n)return{from:n,to:a}}return null});function Kwe(e){return new bp(wbt,e,[],"markdown")}const Obt=Kwe(kbt),Q9n=kbt.configure([ELn,TLn,jLn,NLn,{props:[I_.add({Table:(e,t)=>({from:t.doc.lineAt(e.from).to,to:e.to})})]}]),RO=Kwe(Q9n);function Y9n(e,t){return n=>{if(n&&e){let r=null;if(n=/\S*/.exec(n)[0],typeof e=="function"?r=e(n):r=Km.matchLanguageName(e,n,!0),r instanceof Km)return r.support?r.support.language.parser:TO.getSkippingParser(r.load());if(r)return r.parser}return t?t.parser:null}}class UK{constructor(t,n,r,s,a,i,l){this.node=t,this.from=n,this.to=r,this.spaceBefore=s,this.spaceAfter=a,this.type=i,this.item=l}blank(t,n=!0){let r=this.spaceBefore+(this.node.name=="Blockquote"?">":"");if(t!=null){for(;r.length<t;)r+=" ";return r}else{for(let s=this.to-this.from-r.length-this.spaceAfter.length;s>0;s--)r+=" ";return r+(n?this.spaceAfter:"")}}marker(t,n){let r=this.node.name=="OrderedList"?String(+Cbt(this.item,t)[2]+n):"";return this.spaceBefore+r+this.type+this.spaceAfter}}function _bt(e,t){let n=[],r=[];for(let s=e;s;s=s.parent){if(s.name=="FencedCode")return r;(s.name=="ListItem"||s.name=="Blockquote")&&n.push(s)}for(let s=n.length-1;s>=0;s--){let a=n[s],i,l=t.lineAt(a.from),c=a.from-l.from;if(a.name=="Blockquote"&&(i=/^ *>( ?)/.exec(l.text.slice(c))))r.push(new UK(a,c,c+i[0].length,"",i[1],">",null));else if(a.name=="ListItem"&&a.parent.name=="OrderedList"&&(i=/^( *)\d+([.)])( *)/.exec(l.text.slice(c)))){let u=i[3],d=i[0].length;u.length>=4&&(u=u.slice(0,u.length-4),d-=4),r.push(new UK(a.parent,c,c+d,i[1],u,i[2],a))}else if(a.name=="ListItem"&&a.parent.name=="BulletList"&&(i=/^( *)([-+*])( {1,4}\[[ xX]\])?( +)/.exec(l.text.slice(c)))){let u=i[4],d=i[0].length;u.length>4&&(u=u.slice(0,u.length-4),d-=4);let f=i[2];i[3]&&(f+=i[3].replace(/[xX]/," ")),r.push(new UK(a.parent,c,c+d,i[1],u,f,a))}}return r}function Cbt(e,t){return/^(\s*)(\d+)(?=[.)])/.exec(t.sliceString(e.from,e.from+10))}function qK(e,t,n,r=0){for(let s=-1,a=e;;){if(a.name=="ListItem"){let l=Cbt(a,t),c=+l[2];if(s>=0){if(c!=s+1)return;n.push({from:a.from+l[1].length,to:a.from+l[0].length,insert:String(s+2+r)})}s=c}let i=a.nextSibling;if(!i)break;a=i}}function Jwe(e,t){let n=/^[ \t]*/.exec(e)[0].length;if(!n||t.facet(zN)!=" ")return e;let r=Eg(e,4,n),s="";for(let a=r;a>0;)a>=4?(s+=" ",a-=4):(s+=" ",a--);return s+e.slice(n)}const Ebt=(e={})=>({state:t,dispatch:n})=>{let r=hi(t),{doc:s}=t,a=null,i=t.changeByRange(l=>{if(!l.empty||!RO.isActiveAt(t,l.from,-1)&&!RO.isActiveAt(t,l.from,1))return a={range:l};let c=l.from,u=s.lineAt(c),d=_bt(r.resolveInner(c,-1),s);for(;d.length&&d[d.length-1].from>c-u.from;)d.pop();if(!d.length)return a={range:l};let f=d[d.length-1];if(f.to-f.spaceAfter.length>c-u.from)return a={range:l};let p=c>=f.to-f.spaceAfter.length&&!/\S/.test(u.text.slice(f.to));if(f.item&&p){let b=f.node.firstChild,S=f.node.getChild("ListItem","ListItem");if(b.to>=c||S&&S.to<c||u.from>0&&!/[^\s>]/.test(s.lineAt(u.from-1).text)||e.nonTightLists===!1){let w=d.length>1?d[d.length-2]:null,k,_="";w&&w.item?(k=u.from+w.from,_=w.marker(s,1)):k=u.from+(w?w.to:0);let C=[{from:k,to:c,insert:_}];return f.node.name=="OrderedList"&&qK(f.item,s,C,-2),w&&w.node.name=="OrderedList"&&qK(w.item,s,C),{range:xt.cursor(k+_.length),changes:C}}else{let w=t6e(d,t,u);return{range:xt.cursor(c+w.length+1),changes:{from:u.from,insert:w+t.lineBreak}}}}if(f.node.name=="Blockquote"&&p&&u.from){let b=s.lineAt(u.from-1),S=/>\s*$/.exec(b.text);if(S&&S.index==f.from){let w=t.changes([{from:b.from+S.index,to:b.to},{from:u.from+f.from,to:u.to}]);return{range:l.map(w),changes:w}}}let h=[];f.node.name=="OrderedList"&&qK(f.item,s,h);let m=f.item&&f.item.from<u.from,v="";if(!m||/^[\s\d.)\-+*>]*/.exec(u.text)[0].length>=f.to)for(let b=0,S=d.length-1;b<=S;b++)v+=b==S&&!m?d[b].marker(s,1):d[b].blank(b<S?Eg(u.text,4,d[b+1].from)-v.length:null);let y=c;for(;y>u.from&&/\s/.test(u.text.charAt(y-u.from-1));)y--;return v=Jwe(v,t),X9n(f.node,t.doc)&&(v=t6e(d,t,u)+t.lineBreak+v),h.push({from:y,to:c,insert:t.lineBreak+v}),{range:xt.cursor(y+v.length+1),changes:h}});return a?!1:(n(t.update(i,{scrollIntoView:!0,userEvent:"input"})),!0)},jbt=Ebt();function e6e(e){return e.name=="QuoteMark"||e.name=="ListMark"}function X9n(e,t){if(e.name!="OrderedList"&&e.name!="BulletList")return!1;let n=e.firstChild,r=e.getChild("ListItem","ListItem");if(!r)return!1;let s=t.lineAt(n.to),a=t.lineAt(r.from),i=/^[\s>]*$/.test(s.text);return s.number+(i?0:1)<a.number}function t6e(e,t,n){let r="";for(let s=0,a=e.length-2;s<=a;s++)r+=e[s].blank(s<a?Eg(n.text,4,e[s+1].from)-r.length:null,s<a);return Jwe(r,t)}function K9n(e,t){let n=e.resolveInner(t,-1),r=t;e6e(n)&&(r=n.from,n=n.parent);for(let s;s=n.childBefore(r);)if(e6e(s))r=s.from;else if(s.name=="OrderedList"||s.name=="BulletList")n=s.lastChild,r=n.to;else break;return n}const Tbt=({state:e,dispatch:t})=>{let n=hi(e),r=null,s=e.changeByRange(a=>{let i=a.from,{doc:l}=e;if(a.empty&&RO.isActiveAt(e,a.from)){let c=l.lineAt(i),u=_bt(K9n(n,i),l);if(u.length){let d=u[u.length-1],f=d.to-d.spaceAfter.length+(d.spaceAfter?1:0);if(i-c.from>f&&!/\S/.test(c.text.slice(f,i-c.from)))return{range:xt.cursor(c.from+f),changes:{from:c.from+f,to:i}};if(i-c.from==f&&(!d.item||c.from<=d.item.from||!/\S/.test(c.text.slice(0,d.to)))){let p=c.from+d.from;if(d.item&&d.node.from<d.item.from&&/\S/.test(c.text.slice(d.from,d.to))){let h=d.blank(Eg(c.text,4,d.to)-Eg(c.text,4,d.from));return p==c.from&&(h=Jwe(h,e)),{range:xt.cursor(p+h.length),changes:{from:p,to:c.from+d.to,insert:h}}}if(p<i)return{range:xt.cursor(p),changes:{from:p,to:i}}}}}return r={range:a}});return r?!1:(t(e.update(s,{scrollIntoView:!0,userEvent:"delete"})),!0)},Nbt=[{key:"Enter",run:jbt},{key:"Backspace",run:Tbt}],Ibt=V9n({matchClosingTags:!1});function e1e(e={}){let{codeLanguages:t,defaultCodeLanguage:n,addKeymap:r=!0,base:{parser:s}=Obt,completeHTMLTags:a=!0,pasteURLAsLink:i=!0,htmlTagLanguage:l=Ibt}=e;if(!(s instanceof OV))throw new RangeError("Base parser provided to `markdown` should be a Markdown parser");let c=e.extensions?[e.extensions]:[],u=[l.support,G9n],d;i&&u.push(Abt),n instanceof NO?(u.push(n.support),d=n.language):n&&(d=n);let f=t||d?Y9n(t,d):void 0;c.push(yLn({codeParser:f,htmlParser:l.language.parser})),r&&u.push(Mg.high(FN.of(Nbt)));let p=Kwe(s.configure(c));return a&&u.push(p.data.of({autocomplete:J9n})),new NO(p,u)}function J9n(e){let{state:t,pos:n}=e,r=/<[:\-\.\w\u00b7-\uffff]*$/.exec(t.sliceDoc(n-25,n));if(!r)return null;let s=hi(t).resolveInner(n,-1);for(;s&&!s.type.isTop;){if(s.name=="CodeBlock"||s.name=="FencedCode"||s.name=="ProcessingInstructionBlock"||s.name=="CommentBlock"||s.name=="Link"||s.name=="Image")return null;s=s.parent}return{from:n-r[0].length,to:n,options:eFn(),validFor:/^<[:\-\.\w\u00b7-\uffff]*$/}}let VK=null;function eFn(){if(VK)return VK;let e=B9n(new Nwe(is.create({extensions:Ibt}),0,!0));return VK=e?e.options:[]}const tFn=/code|horizontalrule|html|link|comment|processing|escape|entity|image|mark|url/i,Abt=It.domEventHandlers({paste:(e,t)=>{var n;let{main:r}=t.state.selection;if(r.empty)return!1;let s=(n=e.clipboardData)===null||n===void 0?void 0:n.getData("text/plain");if(!s||!/^(https?:\/\/|mailto:|xmpp:|www\.)/.test(s)||(/^www\./.test(s)&&(s="https://"+s),!RO.isActiveAt(t.state,r.from,1)))return!1;let a=hi(t.state),i=!1;return a.iterate({from:r.from,to:r.to,enter:l=>{(l.from>r.from||tFn.test(l.name))&&(i=!0)},leave:l=>{l.to<r.to&&(i=!0)}}),i?!1:(t.dispatch({changes:[{from:r.from,insert:"["},{from:r.to,insert:`](${s})`}],userEvent:"input.paste",scrollIntoView:!0}),!0)}}),nFn=Object.freeze(Object.defineProperty({__proto__:null,commonmarkLanguage:Obt,deleteMarkupBackward:Tbt,insertNewlineContinueMarkup:jbt,insertNewlineContinueMarkupCommand:Ebt,markdown:e1e,markdownKeymap:Nbt,markdownLanguage:RO,pasteURLAsLink:Abt},Symbol.toStringTag,{value:"Module"}));function PO(){return PO=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},PO.apply(null,arguments)}var rFn=e=>{var t=e.theme,n=e.settings,r=n===void 0?{}:n,s=e.styles,a=s===void 0?[]:s,i={".cm-gutters":{}},l={};r.background&&(l.backgroundColor=r.background),r.backgroundImage&&(l.backgroundImage=r.backgroundImage),r.foreground&&(l.color=r.foreground),r.fontSize&&(l.fontSize=r.fontSize),(r.background||r.foreground)&&(i["&"]=l),r.fontFamily&&(i["&.cm-editor .cm-scroller"]={fontFamily:r.fontFamily}),r.gutterBackground&&(i[".cm-gutters"].backgroundColor=r.gutterBackground),r.gutterForeground&&(i[".cm-gutters"].color=r.gutterForeground),r.gutterBorder&&(i[".cm-gutters"].borderRightColor=r.gutterBorder),r.caret&&(i[".cm-content"]={caretColor:r.caret},i[".cm-cursor, .cm-dropCursor"]={borderLeftColor:r.caret});var c={};r.gutterActiveForeground&&(c.color=r.gutterActiveForeground),r.lineHighlight&&(i[".cm-activeLine"]={backgroundColor:r.lineHighlight},c.backgroundColor=r.lineHighlight),i[".cm-activeLineGutter"]=c,r.selection&&(i["&.cm-focused .cm-selectionBackground, & .cm-line::selection, & .cm-selectionLayer .cm-selectionBackground, .cm-content ::selection"]={background:r.selection+" !important"}),r.selectionMatch&&(i["& .cm-selectionMatch"]={backgroundColor:r.selectionMatch});var u=It.theme(i,{dark:t==="dark"}),d=Dg.define(a),f=[u,B1(d)];return f},sFn={background:"#282a36",foreground:"#f8f8f2",caret:"#f8f8f0",selection:"rgba(255, 255, 255, 0.1)",selectionMatch:"rgba(255, 255, 255, 0.2)",gutterBackground:"#282a36",gutterForeground:"#6D8A88",gutterBorder:"transparent",lineHighlight:"rgba(255, 255, 255, 0.1)"},aFn=[{tag:fe.comment,color:"#6272a4"},{tag:fe.string,color:"#f1fa8c"},{tag:fe.atom,color:"#bd93f9"},{tag:fe.meta,color:"#f8f8f2"},{tag:[fe.keyword,fe.operator,fe.tagName],color:"#ff79c6"},{tag:[fe.function(fe.propertyName),fe.propertyName],color:"#66d9ef"},{tag:[fe.definition(fe.variableName),fe.function(fe.variableName),fe.className,fe.attributeName],color:"#50fa7b"},{tag:fe.atom,color:"#bd93f9"}],UN=e=>{var t=e||{},n=t.theme,r=n===void 0?"dark":n,s=t.settings,a=s===void 0?{}:s,i=t.styles,l=i===void 0?[]:i;return rFn({theme:r,settings:PO({},sFn,a),styles:[...aFn,...l]})};UN();function Rbt(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}const iFn=e=>{let{state:t}=e,n=t.doc.lineAt(t.selection.main.from),r=n1e(e.state,n.from);return r.line?oFn(e):r.block?cFn(e):!1};function t1e(e,t){return({state:n,dispatch:r})=>{if(n.readOnly)return!1;let s=e(t,n);return s?(r(n.update(s)),!0):!1}}const oFn=t1e(fFn,0),lFn=t1e(Pbt,0),cFn=t1e((e,t)=>Pbt(e,t,dFn(t)),0);function n1e(e,t){let n=e.languageDataAt("commentTokens",t,1);return n.length?n[0]:{}}const QA=50;function uFn(e,{open:t,close:n},r,s){let a=e.sliceDoc(r-QA,r),i=e.sliceDoc(s,s+QA),l=/\s*$/.exec(a)[0].length,c=/^\s*/.exec(i)[0].length,u=a.length-l;if(a.slice(u-t.length,u)==t&&i.slice(c,c+n.length)==n)return{open:{pos:r-l,margin:l&&1},close:{pos:s+c,margin:c&&1}};let d,f;s-r<=2*QA?d=f=e.sliceDoc(r,s):(d=e.sliceDoc(r,r+QA),f=e.sliceDoc(s-QA,s));let p=/^\s*/.exec(d)[0].length,h=/\s*$/.exec(f)[0].length,m=f.length-h-n.length;return d.slice(p,p+t.length)==t&&f.slice(m,m+n.length)==n?{open:{pos:r+p+t.length,margin:/\s/.test(d.charAt(p+t.length))?1:0},close:{pos:s-h-n.length,margin:/\s/.test(f.charAt(m-1))?1:0}}:null}function dFn(e){let t=[];for(let n of e.selection.ranges){let r=e.doc.lineAt(n.from),s=n.to<=r.to?r:e.doc.lineAt(n.to);s.from>r.from&&s.from==n.to&&(s=n.to==r.to+1?r:e.doc.lineAt(n.to-1));let a=t.length-1;a>=0&&t[a].to>r.from?t[a].to=s.to:t.push({from:r.from+/^\s*/.exec(r.text)[0].length,to:s.to})}return t}function Pbt(e,t,n=t.selection.ranges){let r=n.map(a=>n1e(t,a.from).block);if(!r.every(a=>a))return null;let s=n.map((a,i)=>uFn(t,r[i],a.from,a.to));if(e!=2&&!s.every(a=>a))return{changes:t.changes(n.map((a,i)=>s[i]?[]:[{from:a.from,insert:r[i].open+" "},{from:a.to,insert:" "+r[i].close}]))};if(e!=1&&s.some(a=>a)){let a=[];for(let i=0,l;i<s.length;i++)if(l=s[i]){let c=r[i],{open:u,close:d}=l;a.push({from:u.pos-c.open.length,to:u.pos+u.margin},{from:d.pos-d.margin,to:d.pos+c.close.length})}return{changes:a}}return null}function fFn(e,t,n=t.selection.ranges){let r=[],s=-1;e:for(let{from:a,to:i}of n){let l=r.length,c=1e9,u;for(let d=a;d<=i;){let f=t.doc.lineAt(d);if(u==null&&(u=n1e(t,f.from).line,!u))continue e;if(f.from>s&&(a==i||i>f.from)){s=f.from;let p=/^\s*/.exec(f.text)[0].length,h=p==f.length,m=f.text.slice(p,p+u.length)==u?p:-1;p<f.text.length&&p<c&&(c=p),r.push({line:f,comment:m,token:u,indent:p,empty:h,single:!1})}d=f.to+1}if(c<1e9)for(let d=l;d<r.length;d++)r[d].indent<r[d].line.text.length&&(r[d].indent=c);r.length==l+1&&(r[l].single=!0)}if(e!=2&&r.some(a=>a.comment<0&&(!a.empty||a.single))){let a=[];for(let{line:l,token:c,indent:u,empty:d,single:f}of r)(f||!d)&&a.push({from:l.from+u,insert:c+" "});let i=t.changes(a);return{changes:i,selection:t.selection.map(i,1)}}else if(e!=1&&r.some(a=>a.comment>=0)){let a=[];for(let{line:i,comment:l,token:c}of r)if(l>=0){let u=i.from+l,d=u+c.length;i.text[d-i.from]==" "&&d++,a.push({from:u,to:d})}return{changes:a}}return null}const vhe=Py.define(),pFn=Py.define(),hFn=On.define(),$bt=On.define({combine(e){return $y(e,{minDepth:100,newGroupDelay:500,joinToEvent:(t,n)=>n},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(t,n)=>(r,s)=>t(r,s)||n(r,s)})}}),Mbt=gl.define({create(){return zv.empty},update(e,t){let n=t.state.facet($bt),r=t.annotation(vhe);if(r){let c=tf.fromTransaction(t,r.selection),u=r.side,d=u==0?e.undone:e.done;return c?d=k7(d,d.length,n.minDepth,c):d=Fbt(d,t.startState.selection),new zv(u==0?r.rest:d,u==0?d:r.rest)}let s=t.annotation(pFn);if((s=="full"||s=="before")&&(e=e.isolate()),t.annotation(Tl.addToHistory)===!1)return t.changes.empty?e:e.addMapping(t.changes.desc);let a=tf.fromTransaction(t),i=t.annotation(Tl.time),l=t.annotation(Tl.userEvent);return a?e=e.addChanges(a,i,l,n,t):t.selection&&(e=e.addSelection(t.startState.selection,i,l,n.newGroupDelay)),(s=="full"||s=="after")&&(e=e.isolate()),e},toJSON(e){return{done:e.done.map(t=>t.toJSON()),undone:e.undone.map(t=>t.toJSON())}},fromJSON(e){return new zv(e.done.map(tf.fromJSON),e.undone.map(tf.fromJSON))}});function mFn(e={}){return[Mbt,$bt.of(e),It.domEventHandlers({beforeinput(t,n){let r=t.inputType=="historyUndo"?Dbt:t.inputType=="historyRedo"?yhe:null;return r?(t.preventDefault(),r(n)):!1}})]}function _V(e,t){return function({state:n,dispatch:r}){if(!t&&n.readOnly)return!1;let s=n.field(Mbt,!1);if(!s)return!1;let a=s.pop(e,n,t);return a?(r(a),!0):!1}}const Dbt=_V(0,!1),yhe=_V(1,!1),gFn=_V(0,!0),vFn=_V(1,!0);class tf{constructor(t,n,r,s,a){this.changes=t,this.effects=n,this.mapped=r,this.startSelection=s,this.selectionsAfter=a}setSelAfter(t){return new tf(this.changes,this.effects,this.mapped,this.startSelection,t)}toJSON(){var t,n,r;return{changes:(t=this.changes)===null||t===void 0?void 0:t.toJSON(),mapped:(n=this.mapped)===null||n===void 0?void 0:n.toJSON(),startSelection:(r=this.startSelection)===null||r===void 0?void 0:r.toJSON(),selectionsAfter:this.selectionsAfter.map(s=>s.toJSON())}}static fromJSON(t){return new tf(t.changes&&El.fromJSON(t.changes),[],t.mapped&&Kv.fromJSON(t.mapped),t.startSelection&&xt.fromJSON(t.startSelection),t.selectionsAfter.map(xt.fromJSON))}static fromTransaction(t,n){let r=Lh;for(let s of t.startState.facet(hFn)){let a=s(t);a.length&&(r=r.concat(a))}return!r.length&&t.changes.empty?null:new tf(t.changes.invert(t.startState.doc),r,void 0,n||t.startState.selection,Lh)}static selection(t){return new tf(void 0,Lh,void 0,void 0,t)}}function k7(e,t,n,r){let s=t+1>n+20?t-n-1:0,a=e.slice(s,t);return a.push(r),a}function yFn(e,t){let n=[],r=!1;return e.iterChangedRanges((s,a)=>n.push(s,a)),t.iterChangedRanges((s,a,i,l)=>{for(let c=0;c<n.length;){let u=n[c++],d=n[c++];l>=u&&i<=d&&(r=!0)}}),r}function bFn(e,t){return e.ranges.length==t.ranges.length&&e.ranges.filter((n,r)=>n.empty!=t.ranges[r].empty).length===0}function Lbt(e,t){return e.length?t.length?e.concat(t):e:t}const Lh=[],xFn=200;function Fbt(e,t){if(e.length){let n=e[e.length-1],r=n.selectionsAfter.slice(Math.max(0,n.selectionsAfter.length-xFn));return r.length&&r[r.length-1].eq(t)?e:(r.push(t),k7(e,e.length-1,1e9,n.setSelAfter(r)))}else return[tf.selection([t])]}function wFn(e){let t=e[e.length-1],n=e.slice();return n[e.length-1]=t.setSelAfter(t.selectionsAfter.slice(0,t.selectionsAfter.length-1)),n}function HK(e,t){if(!e.length)return e;let n=e.length,r=Lh;for(;n;){let s=SFn(e[n-1],t,r);if(s.changes&&!s.changes.empty||s.effects.length){let a=e.slice(0,n);return a[n-1]=s,a}else t=s.mapped,n--,r=s.selectionsAfter}return r.length?[tf.selection(r)]:Lh}function SFn(e,t,n){let r=Lbt(e.selectionsAfter.length?e.selectionsAfter.map(l=>l.map(t)):Lh,n);if(!e.changes)return tf.selection(r);let s=e.changes.map(t),a=t.mapDesc(e.changes,!0),i=e.mapped?e.mapped.composeDesc(a):a;return new tf(s,vr.mapEffects(e.effects,t),i,e.startSelection.map(a),r)}const kFn=/^(input\.type|delete)($|\.)/;class zv{constructor(t,n,r=0,s=void 0){this.done=t,this.undone=n,this.prevTime=r,this.prevUserEvent=s}isolate(){return this.prevTime?new zv(this.done,this.undone):this}addChanges(t,n,r,s,a){let i=this.done,l=i[i.length-1];return l&&l.changes&&!l.changes.empty&&t.changes&&(!r||kFn.test(r))&&(!l.selectionsAfter.length&&n-this.prevTime<s.newGroupDelay&&s.joinToEvent(a,yFn(l.changes,t.changes))||r=="input.type.compose")?i=k7(i,i.length-1,s.minDepth,new tf(t.changes.compose(l.changes),Lbt(vr.mapEffects(t.effects,l.changes),l.effects),l.mapped,l.startSelection,Lh)):i=k7(i,i.length,s.minDepth,t),new zv(i,Lh,n,r)}addSelection(t,n,r,s){let a=this.done.length?this.done[this.done.length-1].selectionsAfter:Lh;return a.length>0&&n-this.prevTime<s&&r==this.prevUserEvent&&r&&/^select($|\.)/.test(r)&&bFn(a[a.length-1],t)?this:new zv(Fbt(this.done,t),this.undone,n,r)}addMapping(t){return new zv(HK(this.done,t),HK(this.undone,t),this.prevTime,this.prevUserEvent)}pop(t,n,r){let s=t==0?this.done:this.undone;if(s.length==0)return null;let a=s[s.length-1],i=a.selectionsAfter[0]||(a.startSelection?a.startSelection.map(a.changes.invertedDesc,1):n.selection);if(r&&a.selectionsAfter.length)return n.update({selection:a.selectionsAfter[a.selectionsAfter.length-1],annotations:vhe.of({side:t,rest:wFn(s),selection:i}),userEvent:t==0?"select.undo":"select.redo",scrollIntoView:!0});if(a.changes){let l=s.length==1?Lh:s.slice(0,s.length-1);return a.mapped&&(l=HK(l,a.mapped)),n.update({changes:a.changes,selection:a.startSelection,effects:a.effects,annotations:vhe.of({side:t,rest:l,selection:i}),filter:!1,userEvent:t==0?"undo":"redo",scrollIntoView:!0})}else return null}}zv.empty=new zv(Lh,Lh);const OFn=[{key:"Mod-z",run:Dbt,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:yhe,preventDefault:!0},{linux:"Ctrl-Shift-z",run:yhe,preventDefault:!0},{key:"Mod-u",run:gFn,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:vFn,preventDefault:!0}];function qN(e,t){return xt.create(e.ranges.map(t),e.mainIndex)}function Lg(e,t){return e.update({selection:t,scrollIntoView:!0,userEvent:"select"})}function Fg({state:e,dispatch:t},n){let r=qN(e.selection,n);return r.eq(e.selection,!0)?!1:(t(Lg(e,r)),!0)}function CV(e,t){return xt.cursor(t?e.to:e.from)}function zbt(e,t){return Fg(e,n=>n.empty?e.moveByChar(n,t):CV(n,t))}function Vu(e){return e.textDirectionAt(e.state.selection.main.head)==Si.LTR}const Bbt=e=>zbt(e,!Vu(e)),Ubt=e=>zbt(e,Vu(e));function qbt(e,t){return Fg(e,n=>n.empty?e.moveByGroup(n,t):CV(n,t))}const _Fn=e=>qbt(e,!Vu(e)),CFn=e=>qbt(e,Vu(e));function EFn(e,t,n){if(t.type.prop(n))return!0;let r=t.to-t.from;return r&&(r>2||/[^\s,.;:]/.test(e.sliceDoc(t.from,t.to)))||t.firstChild}function EV(e,t,n){let r=hi(e).resolveInner(t.head),s=n?Pr.closedBy:Pr.openedBy;for(let c=t.head;;){let u=n?r.childAfter(c):r.childBefore(c);if(!u)break;EFn(e,u,s)?r=u:c=n?u.to:u.from}let a=r.type.prop(s),i,l;return a&&(i=n?Fv(e,r.from,1):Fv(e,r.to,-1))&&i.matched?l=n?i.end.to:i.end.from:l=n?r.to:r.from,xt.cursor(l,n?-1:1)}const jFn=e=>Fg(e,t=>EV(e.state,t,!Vu(e))),TFn=e=>Fg(e,t=>EV(e.state,t,Vu(e)));function Vbt(e,t){return Fg(e,n=>{if(!n.empty)return CV(n,t);let r=e.moveVertically(n,t);return r.head!=n.head?r:e.moveToLineBoundary(n,t)})}const Hbt=e=>Vbt(e,!1),Wbt=e=>Vbt(e,!0);function Zbt(e){let t=e.scrollDOM.clientHeight<e.scrollDOM.scrollHeight-2,n=0,r=0,s;if(t){for(let a of e.state.facet(It.scrollMargins)){let i=a(e);i?.top&&(n=Math.max(i?.top,n)),i?.bottom&&(r=Math.max(i?.bottom,r))}s=e.scrollDOM.clientHeight-n-r}else s=(e.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:n,marginBottom:r,selfScroll:t,height:Math.max(e.defaultLineHeight,s-5)}}function Gbt(e,t){let n=Zbt(e),{state:r}=e,s=qN(r.selection,i=>i.empty?e.moveVertically(i,t,n.height):CV(i,t));if(s.eq(r.selection))return!1;let a;if(n.selfScroll){let i=e.coordsAtPos(r.selection.main.head),l=e.scrollDOM.getBoundingClientRect(),c=l.top+n.marginTop,u=l.bottom-n.marginBottom;i&&i.top>c&&i.bottom<u&&(a=It.scrollIntoView(s.main.head,{y:"start",yMargin:i.top-c}))}return e.dispatch(Lg(r,s),{effects:a}),!0}const n6e=e=>Gbt(e,!1),bhe=e=>Gbt(e,!0);function U1(e,t,n){let r=e.lineBlockAt(t.head),s=e.moveToLineBoundary(t,n);if(s.head==t.head&&s.head!=(n?r.to:r.from)&&(s=e.moveToLineBoundary(t,n,!1)),!n&&s.head==r.from&&r.length){let a=/^\s*/.exec(e.state.sliceDoc(r.from,Math.min(r.from+100,r.to)))[0].length;a&&t.head!=r.from+a&&(s=xt.cursor(r.from+a))}return s}const NFn=e=>Fg(e,t=>U1(e,t,!0)),IFn=e=>Fg(e,t=>U1(e,t,!1)),AFn=e=>Fg(e,t=>U1(e,t,!Vu(e))),RFn=e=>Fg(e,t=>U1(e,t,Vu(e))),PFn=e=>Fg(e,t=>xt.cursor(e.lineBlockAt(t.head).from,1)),$Fn=e=>Fg(e,t=>xt.cursor(e.lineBlockAt(t.head).to,-1));function MFn(e,t,n){let r=!1,s=qN(e.selection,a=>{let i=Fv(e,a.head,-1)||Fv(e,a.head,1)||a.head>0&&Fv(e,a.head-1,1)||a.head<e.doc.length&&Fv(e,a.head+1,-1);if(!i||!i.end)return a;r=!0;let l=i.start.from==a.head?i.end.to:i.end.from;return xt.cursor(l)});return r?(t(Lg(e,s)),!0):!1}const DFn=({state:e,dispatch:t})=>MFn(e,t);function xm(e,t){let n=qN(e.state.selection,r=>{let s=t(r);return xt.range(r.anchor,s.head,s.goalColumn,s.bidiLevel||void 0,s.assoc)});return n.eq(e.state.selection)?!1:(e.dispatch(Lg(e.state,n)),!0)}function Qbt(e,t){return xm(e,n=>e.moveByChar(n,t))}const Ybt=e=>Qbt(e,!Vu(e)),Xbt=e=>Qbt(e,Vu(e));function Kbt(e,t){return xm(e,n=>e.moveByGroup(n,t))}const LFn=e=>Kbt(e,!Vu(e)),FFn=e=>Kbt(e,Vu(e)),zFn=e=>xm(e,t=>EV(e.state,t,!Vu(e))),BFn=e=>xm(e,t=>EV(e.state,t,Vu(e)));function Jbt(e,t){return xm(e,n=>e.moveVertically(n,t))}const ext=e=>Jbt(e,!1),txt=e=>Jbt(e,!0);function nxt(e,t){return xm(e,n=>e.moveVertically(n,t,Zbt(e).height))}const r6e=e=>nxt(e,!1),s6e=e=>nxt(e,!0),UFn=e=>xm(e,t=>U1(e,t,!0)),qFn=e=>xm(e,t=>U1(e,t,!1)),VFn=e=>xm(e,t=>U1(e,t,!Vu(e))),HFn=e=>xm(e,t=>U1(e,t,Vu(e))),WFn=e=>xm(e,t=>xt.cursor(e.lineBlockAt(t.head).from)),ZFn=e=>xm(e,t=>xt.cursor(e.lineBlockAt(t.head).to)),a6e=({state:e,dispatch:t})=>(t(Lg(e,{anchor:0})),!0),i6e=({state:e,dispatch:t})=>(t(Lg(e,{anchor:e.doc.length})),!0),o6e=({state:e,dispatch:t})=>(t(Lg(e,{anchor:e.selection.main.anchor,head:0})),!0),l6e=({state:e,dispatch:t})=>(t(Lg(e,{anchor:e.selection.main.anchor,head:e.doc.length})),!0),GFn=({state:e,dispatch:t})=>(t(e.update({selection:{anchor:0,head:e.doc.length},userEvent:"select"})),!0),QFn=({state:e,dispatch:t})=>{let n=jV(e).map(({from:r,to:s})=>xt.range(r,Math.min(s+1,e.doc.length)));return t(e.update({selection:xt.create(n),userEvent:"select"})),!0},YFn=({state:e,dispatch:t})=>{let n=qN(e.selection,r=>{let s=hi(e),a=s.resolveStack(r.from,1);if(r.empty){let i=s.resolveStack(r.from,-1);i.node.from>=a.node.from&&i.node.to<=a.node.to&&(a=i)}for(let i=a;i;i=i.next){let{node:l}=i;if((l.from<r.from&&l.to>=r.to||l.to>r.to&&l.from<=r.from)&&i.next)return xt.range(l.to,l.from)}return r});return n.eq(e.selection)?!1:(t(Lg(e,n)),!0)};function rxt(e,t){let{state:n}=e,r=n.selection,s=n.selection.ranges.slice();for(let a of n.selection.ranges){let i=n.doc.lineAt(a.head);if(t?i.to<e.state.doc.length:i.from>0)for(let l=a;;){let c=e.moveVertically(l,t);if(c.head<i.from||c.head>i.to){s.some(u=>u.head==c.head)||s.push(c);break}else{if(c.head==l.head)break;l=c}}}return s.length==r.ranges.length?!1:(e.dispatch(Lg(n,xt.create(s,s.length-1))),!0)}const XFn=e=>rxt(e,!1),KFn=e=>rxt(e,!0),JFn=({state:e,dispatch:t})=>{let n=e.selection,r=null;return n.ranges.length>1?r=xt.create([n.main]):n.main.empty||(r=xt.create([xt.cursor(n.main.head)])),r?(t(Lg(e,r)),!0):!1};function d3(e,t){if(e.state.readOnly)return!1;let n="delete.selection",{state:r}=e,s=r.changeByRange(a=>{let{from:i,to:l}=a;if(i==l){let c=t(a);c<i?(n="delete.backward",c=x6(e,c,!1)):c>i&&(n="delete.forward",c=x6(e,c,!0)),i=Math.min(i,c),l=Math.max(l,c)}else i=x6(e,i,!1),l=x6(e,l,!0);return i==l?{range:a}:{changes:{from:i,to:l},range:xt.cursor(i,i<a.head?-1:1)}});return s.changes.empty?!1:(e.dispatch(r.update(s,{scrollIntoView:!0,userEvent:n,effects:n=="delete.selection"?It.announce.of(r.phrase("Selection deleted")):void 0})),!0)}function x6(e,t,n){if(e instanceof It)for(let r of e.state.facet(It.atomicRanges).map(s=>s(e)))r.between(t,t,(s,a)=>{s<t&&a>t&&(t=n?a:s)});return t}const sxt=(e,t,n)=>d3(e,r=>{let s=r.from,{state:a}=e,i=a.doc.lineAt(s),l,c;if(n&&!t&&s>i.from&&s<i.from+200&&!/[^ \t]/.test(l=i.text.slice(0,s-i.from))){if(l[l.length-1]==" ")return s-1;let u=Eg(l,a.tabSize),d=u%IO(a)||IO(a);for(let f=0;f<d&&l[l.length-1-f]==" ";f++)s--;c=s}else c=xc(i.text,s-i.from,t,t)+i.from,c==s&&i.number!=(t?a.doc.lines:1)?c+=t?1:-1:!t&&/[\ufe00-\ufe0f]/.test(i.text.slice(c-i.from,s-i.from))&&(c=xc(i.text,c-i.from,!1,!1)+i.from);return c}),xhe=e=>sxt(e,!1,!0),axt=e=>sxt(e,!0,!1),ixt=(e,t)=>d3(e,n=>{let r=n.head,{state:s}=e,a=s.doc.lineAt(r),i=s.charCategorizer(r);for(let l=null;;){if(r==(t?a.to:a.from)){r==n.head&&a.number!=(t?s.doc.lines:1)&&(r+=t?1:-1);break}let c=xc(a.text,r-a.from,t)+a.from,u=a.text.slice(Math.min(r,c)-a.from,Math.max(r,c)-a.from),d=i(u);if(l!=null&&d!=l)break;(u!=" "||r!=n.head)&&(l=d),r=c}return r}),oxt=e=>ixt(e,!1),e8n=e=>ixt(e,!0),t8n=e=>d3(e,t=>{let n=e.lineBlockAt(t.head).to;return t.head<n?n:Math.min(e.state.doc.length,t.head+1)}),n8n=e=>d3(e,t=>{let n=e.moveToLineBoundary(t,!1).head;return t.head>n?n:Math.max(0,t.head-1)}),r8n=e=>d3(e,t=>{let n=e.moveToLineBoundary(t,!0).head;return t.head<n?n:Math.min(e.state.doc.length,t.head+1)}),s8n=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=e.changeByRange(r=>({changes:{from:r.from,to:r.to,insert:ka.of(["",""])},range:xt.cursor(r.from)}));return t(e.update(n,{scrollIntoView:!0,userEvent:"input"})),!0},a8n=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=e.changeByRange(r=>{if(!r.empty||r.from==0||r.from==e.doc.length)return{range:r};let s=r.from,a=e.doc.lineAt(s),i=s==a.from?s-1:xc(a.text,s-a.from,!1)+a.from,l=s==a.to?s+1:xc(a.text,s-a.from,!0)+a.from;return{changes:{from:i,to:l,insert:e.doc.slice(s,l).append(e.doc.slice(i,s))},range:xt.cursor(l)}});return n.changes.empty?!1:(t(e.update(n,{scrollIntoView:!0,userEvent:"move.character"})),!0)};function jV(e){let t=[],n=-1;for(let r of e.selection.ranges){let s=e.doc.lineAt(r.from),a=e.doc.lineAt(r.to);if(!r.empty&&r.to==a.from&&(a=e.doc.lineAt(r.to-1)),n>=s.number){let i=t[t.length-1];i.to=a.to,i.ranges.push(r)}else t.push({from:s.from,to:a.to,ranges:[r]});n=a.number+1}return t}function lxt(e,t,n){if(e.readOnly)return!1;let r=[],s=[];for(let a of jV(e)){if(n?a.to==e.doc.length:a.from==0)continue;let i=e.doc.lineAt(n?a.to+1:a.from-1),l=i.length+1;if(n){r.push({from:a.to,to:i.to},{from:a.from,insert:i.text+e.lineBreak});for(let c of a.ranges)s.push(xt.range(Math.min(e.doc.length,c.anchor+l),Math.min(e.doc.length,c.head+l)))}else{r.push({from:i.from,to:a.from},{from:a.to,insert:e.lineBreak+i.text});for(let c of a.ranges)s.push(xt.range(c.anchor-l,c.head-l))}}return r.length?(t(e.update({changes:r,scrollIntoView:!0,selection:xt.create(s,e.selection.mainIndex),userEvent:"move.line"})),!0):!1}const i8n=({state:e,dispatch:t})=>lxt(e,t,!1),o8n=({state:e,dispatch:t})=>lxt(e,t,!0);function cxt(e,t,n){if(e.readOnly)return!1;let r=[];for(let a of jV(e))n?r.push({from:a.from,insert:e.doc.slice(a.from,a.to)+e.lineBreak}):r.push({from:a.to,insert:e.lineBreak+e.doc.slice(a.from,a.to)});let s=e.changes(r);return t(e.update({changes:s,selection:e.selection.map(s,n?1:-1),scrollIntoView:!0,userEvent:"input.copyline"})),!0}const l8n=({state:e,dispatch:t})=>cxt(e,t,!1),c8n=({state:e,dispatch:t})=>cxt(e,t,!0),u8n=e=>{if(e.state.readOnly)return!1;let{state:t}=e,n=t.changes(jV(t).map(({from:s,to:a})=>(s>0?s--:a<t.doc.length&&a++,{from:s,to:a}))),r=qN(t.selection,s=>{let a;if(e.lineWrapping){let i=e.lineBlockAt(s.head),l=e.coordsAtPos(s.head,s.assoc||1);l&&(a=i.bottom+e.documentTop-l.bottom+e.defaultLineHeight/2)}return e.moveVertically(s,!0,a)}).map(n);return e.dispatch({changes:n,selection:r,scrollIntoView:!0,userEvent:"delete.line"}),!0};function d8n(e,t){if(/\(\)|\[\]|\{\}/.test(e.sliceDoc(t-1,t+1)))return{from:t,to:t};let n=hi(e).resolveInner(t),r=n.childBefore(t),s=n.childAfter(t),a;return r&&s&&r.to<=t&&s.from>=t&&(a=r.type.prop(Pr.closedBy))&&a.indexOf(s.name)>-1&&e.doc.lineAt(r.to).from==e.doc.lineAt(s.from).from&&!/\S/.test(e.sliceDoc(r.to,s.from))?{from:r.to,to:s.from}:null}const c6e=uxt(!1),f8n=uxt(!0);function uxt(e){return({state:t,dispatch:n})=>{if(t.readOnly)return!1;let r=t.changeByRange(s=>{let{from:a,to:i}=s,l=t.doc.lineAt(a),c=!e&&a==i&&d8n(t,a);e&&(a=i=(i<=l.to?l:t.doc.lineAt(i)).to);let u=new wV(t,{simulateBreak:a,simulateDoubleBreak:!!c}),d=Owe(u,a);for(d==null&&(d=Eg(/^\s*/.exec(t.doc.lineAt(a).text)[0],t.tabSize));i<l.to&&/\s/.test(l.text[i-l.from]);)i++;c?{from:a,to:i}=c:a>l.from&&a<l.from+100&&!/\S/.test(l.text.slice(0,a))&&(a=l.from);let f=["",U$(t,d)];return c&&f.push(U$(t,u.lineIndent(l.from,-1))),{changes:{from:a,to:i,insert:ka.of(f)},range:xt.cursor(a+1+f[1].length)}});return n(t.update(r,{scrollIntoView:!0,userEvent:"input"})),!0}}function r1e(e,t){let n=-1;return e.changeByRange(r=>{let s=[];for(let i=r.from;i<=r.to;){let l=e.doc.lineAt(i);l.number>n&&(r.empty||r.to>l.from)&&(t(l,s,r),n=l.number),i=l.to+1}let a=e.changes(s);return{changes:s,range:xt.range(a.mapPos(r.anchor,1),a.mapPos(r.head,1))}})}const p8n=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=Object.create(null),r=new wV(e,{overrideIndentation:a=>{let i=n[a];return i??-1}}),s=r1e(e,(a,i,l)=>{let c=Owe(r,a.from);if(c==null)return;/\S/.test(a.text)||(c=0);let u=/^\s*/.exec(a.text)[0],d=U$(e,c);(u!=d||l.from<a.from+u.length)&&(n[a.from]=c,i.push({from:a.from,to:a.from+u.length,insert:d}))});return s.changes.empty||t(e.update(s,{userEvent:"indent"})),!0},dxt=({state:e,dispatch:t})=>e.readOnly?!1:(t(e.update(r1e(e,(n,r)=>{r.push({from:n.from,insert:e.facet(zN)})}),{userEvent:"input.indent"})),!0),fxt=({state:e,dispatch:t})=>e.readOnly?!1:(t(e.update(r1e(e,(n,r)=>{let s=/^\s*/.exec(n.text)[0];if(!s)return;let a=Eg(s,e.tabSize),i=0,l=U$(e,Math.max(0,a-IO(e)));for(;i<s.length&&i<l.length&&s.charCodeAt(i)==l.charCodeAt(i);)i++;r.push({from:n.from+i,to:n.from+s.length,insert:l.slice(i)})}),{userEvent:"delete.dedent"})),!0),h8n=e=>(e.setTabFocusMode(),!0),m8n=[{key:"Ctrl-b",run:Bbt,shift:Ybt,preventDefault:!0},{key:"Ctrl-f",run:Ubt,shift:Xbt},{key:"Ctrl-p",run:Hbt,shift:ext},{key:"Ctrl-n",run:Wbt,shift:txt},{key:"Ctrl-a",run:PFn,shift:WFn},{key:"Ctrl-e",run:$Fn,shift:ZFn},{key:"Ctrl-d",run:axt},{key:"Ctrl-h",run:xhe},{key:"Ctrl-k",run:t8n},{key:"Ctrl-Alt-h",run:oxt},{key:"Ctrl-o",run:s8n},{key:"Ctrl-t",run:a8n},{key:"Ctrl-v",run:bhe}],g8n=[{key:"ArrowLeft",run:Bbt,shift:Ybt,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:_Fn,shift:LFn,preventDefault:!0},{mac:"Cmd-ArrowLeft",run:AFn,shift:VFn,preventDefault:!0},{key:"ArrowRight",run:Ubt,shift:Xbt,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:CFn,shift:FFn,preventDefault:!0},{mac:"Cmd-ArrowRight",run:RFn,shift:HFn,preventDefault:!0},{key:"ArrowUp",run:Hbt,shift:ext,preventDefault:!0},{mac:"Cmd-ArrowUp",run:a6e,shift:o6e},{mac:"Ctrl-ArrowUp",run:n6e,shift:r6e},{key:"ArrowDown",run:Wbt,shift:txt,preventDefault:!0},{mac:"Cmd-ArrowDown",run:i6e,shift:l6e},{mac:"Ctrl-ArrowDown",run:bhe,shift:s6e},{key:"PageUp",run:n6e,shift:r6e},{key:"PageDown",run:bhe,shift:s6e},{key:"Home",run:IFn,shift:qFn,preventDefault:!0},{key:"Mod-Home",run:a6e,shift:o6e},{key:"End",run:NFn,shift:UFn,preventDefault:!0},{key:"Mod-End",run:i6e,shift:l6e},{key:"Enter",run:c6e,shift:c6e},{key:"Mod-a",run:GFn},{key:"Backspace",run:xhe,shift:xhe,preventDefault:!0},{key:"Delete",run:axt,preventDefault:!0},{key:"Mod-Backspace",mac:"Alt-Backspace",run:oxt,preventDefault:!0},{key:"Mod-Delete",mac:"Alt-Delete",run:e8n,preventDefault:!0},{mac:"Mod-Backspace",run:n8n,preventDefault:!0},{mac:"Mod-Delete",run:r8n,preventDefault:!0}].concat(m8n.map(e=>({mac:e.key,run:e.run,shift:e.shift}))),v8n=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:jFn,shift:zFn},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:TFn,shift:BFn},{key:"Alt-ArrowUp",run:i8n},{key:"Shift-Alt-ArrowUp",run:l8n},{key:"Alt-ArrowDown",run:o8n},{key:"Shift-Alt-ArrowDown",run:c8n},{key:"Mod-Alt-ArrowUp",run:XFn},{key:"Mod-Alt-ArrowDown",run:KFn},{key:"Escape",run:JFn},{key:"Mod-Enter",run:f8n},{key:"Alt-l",mac:"Ctrl-l",run:QFn},{key:"Mod-i",run:YFn,preventDefault:!0},{key:"Mod-[",run:fxt},{key:"Mod-]",run:dxt},{key:"Mod-Alt-\\",run:p8n},{key:"Shift-Mod-k",run:u8n},{key:"Shift-Mod-\\",run:DFn},{key:"Mod-/",run:iFn},{key:"Alt-A",run:lFn},{key:"Ctrl-m",mac:"Shift-Alt-m",run:h8n}].concat(g8n),y8n={key:"Tab",run:dxt,shift:fxt},u6e=typeof String.prototype.normalize=="function"?e=>e.normalize("NFKD"):e=>e;class _x{constructor(t,n,r=0,s=t.length,a,i){this.test=i,this.value={from:0,to:0,precise:!1},this.done=!1,this.matches=[],this.buffer="",this.bufferPos=0,this.iter=t.iterRange(r,s),this.bufferStart=r,this.normalize=a?l=>a(u6e(l)):u6e,this.query=this.normalize(n)}peek(){if(this.bufferPos==this.buffer.length){if(this.bufferStart+=this.buffer.length,this.iter.next(),this.iter.done)return-1;this.bufferPos=0,this.buffer=this.iter.value}return Wd(this.buffer,this.bufferPos)}next(){for(;this.matches.length;)this.matches.pop();return this.nextOverlapping()}nextOverlapping(){for(;;){let t=this.peek();if(t<0)return this.done=!0,this;let n=awe(t),r=this.bufferStart+this.bufferPos;this.bufferPos+=Ev(t);let s=this.normalize(n);if(s.length)for(let a=0,i=r,l=!0;;a++){let c=s.charCodeAt(a),u=this.match(c,i,l,this.bufferPos+this.bufferStart,a==s.length-1);if(u)return this.value=u,this;if(a==s.length-1)break;l&&a<n.length&&n.charCodeAt(a)==c?i++:l=!1}}}match(t,n,r,s,a){let i=null;for(let l=0;l<this.matches.length;){let c=this.matches[l],u=!1;this.query.charCodeAt(c.index)==t&&(c.index==this.query.length-1?i={from:c.from,to:s,precise:a&&c.precise}:(c.index++,u=!0)),u?l++:this.matches.splice(l,1)}return this.query.charCodeAt(0)==t&&(this.query.length==1?i={from:n,to:s,precise:r&&a}:this.matches.push({from:n,index:1,precise:r})),i&&this.test&&!this.test(i.from,i.to,this.buffer,this.bufferStart)&&(i=null),i}}typeof Symbol<"u"&&(_x.prototype[Symbol.iterator]=function(){return this});const pxt={from:-1,to:-1,match:/.*/.exec(""),precise:!0},s1e="gm"+(/x/.unicode==null?"":"u");class hxt{constructor(t,n,r,s=0,a=t.length){if(this.text=t,this.to=a,this.curLine="",this.done=!1,this.value=pxt,/\\[sWDnr]|\n|\r|\[\^/.test(n))return new mxt(t,n,r,s,a);this.re=new RegExp(n,s1e+(r?.ignoreCase?"i":"")),this.test=r?.test,this.iter=t.iter();let i=t.lineAt(s);this.curLineStart=i.from,this.matchPos=O7(t,s),this.getLine(this.curLineStart)}getLine(t){this.iter.next(t),this.iter.lineBreak?this.curLine="":(this.curLine=this.iter.value,this.curLineStart+this.curLine.length>this.to&&(this.curLine=this.curLine.slice(0,this.to-this.curLineStart)),this.iter.next())}nextLine(){this.curLineStart=this.curLineStart+this.curLine.length+1,this.curLineStart>this.to?this.curLine="":this.getLine(0)}next(){for(let t=this.matchPos-this.curLineStart;;){this.re.lastIndex=t;let n=this.matchPos<=this.to&&this.re.exec(this.curLine);if(n){let r=this.curLineStart+n.index,s=r+n[0].length;if(this.matchPos=O7(this.text,s+(r==s?1:0)),r==this.curLineStart+this.curLine.length&&this.nextLine(),(r<s||r>this.value.to)&&(!this.test||this.test(r,s,n)))return this.value={from:r,to:s,precise:!0,match:n},this;t=this.matchPos-this.curLineStart}else if(this.curLineStart+this.curLine.length<this.to)this.nextLine(),t=0;else return this.done=!0,this}}}const WK=new WeakMap;class Oj{constructor(t,n){this.from=t,this.text=n}get to(){return this.from+this.text.length}static get(t,n,r){let s=WK.get(t);if(!s||s.from>=r||s.to<=n){let l=new Oj(n,t.sliceString(n,r));return WK.set(t,l),l}if(s.from==n&&s.to==r)return s;let{text:a,from:i}=s;return i>n&&(a=t.sliceString(n,i)+a,i=n),s.to<r&&(a+=t.sliceString(s.to,r)),WK.set(t,new Oj(i,a)),new Oj(n,a.slice(n-i,r-i))}}class mxt{constructor(t,n,r,s,a){this.text=t,this.to=a,this.done=!1,this.value=pxt,this.matchPos=O7(t,s),this.re=new RegExp(n,s1e+(r?.ignoreCase?"i":"")),this.test=r?.test,this.flat=Oj.get(t,s,this.chunkEnd(s+5e3))}chunkEnd(t){return t>=this.to?this.to:this.text.lineAt(t).to}next(){for(;;){let t=this.re.lastIndex=this.matchPos-this.flat.from,n=this.re.exec(this.flat.text);if(n&&!n[0]&&n.index==t&&(this.re.lastIndex=t+1,n=this.re.exec(this.flat.text)),n){let r=this.flat.from+n.index,s=r+n[0].length;if((this.flat.to>=this.to||n.index+n[0].length<=this.flat.text.length-10)&&(!this.test||this.test(r,s,n)))return this.value={from:r,to:s,precise:!0,match:n},this.matchPos=O7(this.text,s+(r==s?1:0)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=Oj.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+this.flat.text.length*2))}}}typeof Symbol<"u"&&(hxt.prototype[Symbol.iterator]=mxt.prototype[Symbol.iterator]=function(){return this});function b8n(e){try{return new RegExp(e,s1e),!0}catch{return!1}}function O7(e,t){if(t>=e.length)return t;let n=e.lineAt(t),r;for(;t<n.to&&(r=n.text.charCodeAt(t-n.from))>=56320&&r<57344;)t++;return t}const x8n=e=>{let{state:t}=e,n=String(t.doc.lineAt(e.state.selection.main.head).number),{close:r,result:s}=t4n(e,{label:t.phrase("Go to line"),input:{type:"text",name:"line",value:n},focus:!0,submitLabel:t.phrase("go")});return s.then(a=>{let i=a&&/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(a.elements.line.value);if(!i){e.dispatch({effects:r});return}let l=t.doc.lineAt(t.selection.main.head),[,c,u,d,f]=i,p=d?+d.slice(1):0,h=u?+u:l.number;if(u&&f){let y=h/100;c&&(y=y*(c=="-"?-1:1)+l.number/t.doc.lines),h=Math.round(t.doc.lines*y)}else u&&c&&(h=h*(c=="-"?-1:1)+l.number);let m=t.doc.line(Math.max(1,Math.min(t.doc.lines,h))),v=xt.cursor(m.from+Math.max(0,Math.min(p,m.length)));e.dispatch({effects:[r,It.scrollIntoView(v.from,{y:"center"})],selection:v})}),!0},w8n={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},S8n=On.define({combine(e){return $y(e,w8n,{highlightWordAroundCursor:(t,n)=>t||n,minSelectionLength:Math.min,maxMatches:Math.min})}});function k8n(e){return[j8n,E8n]}const O8n=Cn.mark({class:"cm-selectionMatch"}),_8n=Cn.mark({class:"cm-selectionMatch cm-selectionMatch-main"});function d6e(e,t,n,r){return(n==0||e(t.sliceDoc(n-1,n))!=po.Word)&&(r==t.doc.length||e(t.sliceDoc(r,r+1))!=po.Word)}function C8n(e,t,n,r){return e(t.sliceDoc(n,n+1))==po.Word&&e(t.sliceDoc(r-1,r))==po.Word}const E8n=bo.fromClass(class{constructor(e){this.decorations=this.getDeco(e)}update(e){(e.selectionSet||e.docChanged||e.viewportChanged)&&(this.decorations=this.getDeco(e.view))}getDeco(e){let t=e.state.facet(S8n),{state:n}=e,r=n.selection;if(r.ranges.length>1)return Cn.none;let s=r.main,a,i=null;if(s.empty){if(!t.highlightWordAroundCursor)return Cn.none;let c=n.wordAt(s.head);if(!c)return Cn.none;i=n.charCategorizer(s.head),a=n.sliceDoc(c.from,c.to)}else{let c=s.to-s.from;if(c<t.minSelectionLength||c>200)return Cn.none;if(t.wholeWords){if(a=n.sliceDoc(s.from,s.to),i=n.charCategorizer(s.head),!(d6e(i,n,s.from,s.to)&&C8n(i,n,s.from,s.to)))return Cn.none}else if(a=n.sliceDoc(s.from,s.to),!a)return Cn.none}let l=[];for(let c of e.visibleRanges){let u=new _x(n.doc,a,c.from,c.to);for(;!u.next().done;){let{from:d,to:f}=u.value;if((!i||d6e(i,n,d,f))&&(s.empty&&d<=s.from&&f>=s.to?l.push(_8n.range(d,f)):(d>=s.to||f<=s.from)&&l.push(O8n.range(d,f)),l.length>t.maxMatches))return Cn.none}}return Cn.set(l)}},{decorations:e=>e.decorations}),j8n=It.baseTheme({".cm-selectionMatch":{backgroundColor:"#99ff7780"},".cm-searchMatch .cm-selectionMatch":{backgroundColor:"transparent"}}),T8n=({state:e,dispatch:t})=>{let{selection:n}=e,r=xt.create(n.ranges.map(s=>e.wordAt(s.head)||xt.cursor(s.head)),n.mainIndex);return r.eq(n)?!1:(t(e.update({selection:r})),!0)};function N8n(e,t){let{main:n,ranges:r}=e.selection,s=e.wordAt(n.head),a=s&&s.from==n.from&&s.to==n.to;for(let i=!1,l=new _x(e.doc,t,r[r.length-1].to);;)if(l.next(),l.done){if(i)return null;l=new _x(e.doc,t,0,Math.max(0,r[r.length-1].from-1)),i=!0}else{if(i&&r.some(c=>c.from==l.value.from))continue;if(a){let c=e.wordAt(l.value.from);if(!c||c.from!=l.value.from||c.to!=l.value.to)continue}return l.value}}const I8n=({state:e,dispatch:t})=>{let{ranges:n}=e.selection;if(n.some(a=>a.from===a.to))return T8n({state:e,dispatch:t});let r=e.sliceDoc(n[0].from,n[0].to);if(e.selection.ranges.some(a=>e.sliceDoc(a.from,a.to)!=r))return!1;let s=N8n(e,r);return s?(t(e.update({selection:e.selection.addRange(xt.range(s.from,s.to),!1),effects:It.scrollIntoView(s.to)})),!0):!1},VN=On.define({combine(e){return $y(e,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:t=>new H8n(t),scrollToMatch:t=>It.scrollIntoView(t)})}});class gxt{constructor(t){this.search=t.search,this.caseSensitive=!!t.caseSensitive,this.literal=!!t.literal,this.regexp=!!t.regexp,this.replace=t.replace||"",this.valid=!!this.search&&(!this.regexp||b8n(this.search)),this.unquoted=this.unquote(this.search),this.wholeWord=!!t.wholeWord,this.test=t.test}unquote(t){return this.literal?t:t.replace(/\\([nrt\\])/g,(n,r)=>r=="n"?`
|
|
336
|
-
`:r=="r"?"\r":r=="t"?" ":"\\")}eq(t){return this.search==t.search&&this.replace==t.replace&&this.caseSensitive==t.caseSensitive&&this.regexp==t.regexp&&this.wholeWord==t.wholeWord&&this.test==t.test}create(){return this.regexp?new D8n(this):new P8n(this)}getCursor(t,n=0,r){let s=t.doc?t:is.create({doc:t});return r==null&&(r=s.doc.length),this.regexp?kE(this,s,n,r):SE(this,s,n,r)}}class vxt{constructor(t){this.spec=t}}function A8n(e,t,n){return(r,s,a,i)=>{if(n&&!n(r,s,a,i))return!1;let l=r>=i&&s<=i+a.length?a.slice(r-i,s-i):t.doc.sliceString(r,s);return e(l,t,r,s)}}function SE(e,t,n,r){let s;return e.wholeWord&&(s=R8n(t.doc,t.charCategorizer(t.selection.main.head))),e.test&&(s=A8n(e.test,t,s)),new _x(t.doc,e.unquoted,n,r,e.caseSensitive?void 0:a=>a.toLowerCase(),s)}function R8n(e,t){return(n,r,s,a)=>((a>n||a+s.length<r)&&(a=Math.max(0,n-2),s=e.sliceString(a,Math.min(e.length,r+2))),(t(_7(s,n-a))!=po.Word||t(C7(s,n-a))!=po.Word)&&(t(C7(s,r-a))!=po.Word||t(_7(s,r-a))!=po.Word))}class P8n extends vxt{constructor(t){super(t)}nextMatch(t,n,r){let s=SE(this.spec,t,r,t.doc.length).nextOverlapping();if(s.done){let a=Math.min(t.doc.length,n+this.spec.unquoted.length);s=SE(this.spec,t,0,a).nextOverlapping()}return s.done||s.value.from==n&&s.value.to==r?null:s.value}prevMatchInRange(t,n,r){for(let s=r;;){let a=Math.max(n,s-1e4-this.spec.unquoted.length),i=SE(this.spec,t,a,s),l=null;for(;!i.nextOverlapping().done;)l=i.value;if(l)return l;if(a==n)return null;s-=1e4}}prevMatch(t,n,r){let s=this.prevMatchInRange(t,0,n);return s||(s=this.prevMatchInRange(t,Math.max(0,r-this.spec.unquoted.length),t.doc.length)),s&&(s.from!=n||s.to!=r)?s:null}getReplacement(t){return this.spec.unquote(this.spec.replace)}matchAll(t,n){let r=SE(this.spec,t,0,t.doc.length),s=[];for(;!r.next().done;){if(s.length>=n)return null;s.push(r.value)}return s}highlight(t,n,r,s){let a=SE(this.spec,t,Math.max(0,n-this.spec.unquoted.length),Math.min(r+this.spec.unquoted.length,t.doc.length));for(;!a.next().done;)s(a.value.from,a.value.to)}}function $8n(e,t,n){return(r,s,a)=>(!n||n(r,s,a))&&e(a[0],t,r,s)}function kE(e,t,n,r){let s;return e.wholeWord&&(s=M8n(t.charCategorizer(t.selection.main.head))),e.test&&(s=$8n(e.test,t,s)),new hxt(t.doc,e.search,{ignoreCase:!e.caseSensitive,test:s},n,r)}function _7(e,t){return e.slice(xc(e,t,!1),t)}function C7(e,t){return e.slice(t,xc(e,t))}function M8n(e){return(t,n,r)=>!r[0].length||(e(_7(r.input,r.index))!=po.Word||e(C7(r.input,r.index))!=po.Word)&&(e(C7(r.input,r.index+r[0].length))!=po.Word||e(_7(r.input,r.index+r[0].length))!=po.Word)}class D8n extends vxt{nextMatch(t,n,r){let s=kE(this.spec,t,r,t.doc.length).next();return s.done&&(s=kE(this.spec,t,0,n).next()),s.done?null:s.value}prevMatchInRange(t,n,r){for(let s=1;;s++){let a=Math.max(n,r-s*1e4),i=kE(this.spec,t,a,r),l=null;for(;!i.next().done;)l=i.value;if(l&&(a==n||l.from>a+10))return l;if(a==n)return null}}prevMatch(t,n,r){return this.prevMatchInRange(t,0,n)||this.prevMatchInRange(t,r,t.doc.length)}getReplacement(t){return this.spec.unquote(this.spec.replace).replace(/\$([$&]|\d+)/g,(n,r)=>{if(r=="&")return t.match[0];if(r=="$")return"$";for(let s=r.length;s>0;s--){let a=+r.slice(0,s);if(a>0&&a<t.match.length)return t.match[a]+r.slice(s)}return n})}matchAll(t,n){let r=kE(this.spec,t,0,t.doc.length),s=[];for(;!r.next().done;){if(s.length>=n)return null;s.push(r.value)}return s}highlight(t,n,r,s){let a=kE(this.spec,t,Math.max(0,n-250),Math.min(r+250,t.doc.length));for(;!a.next().done;)s(a.value.from,a.value.to)}}const X$=vr.define(),a1e=vr.define(),$w=gl.define({create(e){return new ZK(whe(e).create(),null)},update(e,t){for(let n of t.effects)n.is(X$)?e=new ZK(n.value.create(),e.panel):n.is(a1e)&&(e=new ZK(e.query,n.value?i1e:null));return e},provide:e=>B$.from(e,t=>t.panel)});class ZK{constructor(t,n){this.query=t,this.panel=n}}const L8n=Cn.mark({class:"cm-searchMatch"}),F8n=Cn.mark({class:"cm-searchMatch cm-searchMatch-selected"}),z8n=bo.fromClass(class{constructor(e){this.view=e,this.decorations=this.highlight(e.state.field($w))}update(e){let t=e.state.field($w);(t!=e.startState.field($w)||e.docChanged||e.selectionSet||e.viewportChanged)&&(this.decorations=this.highlight(t))}highlight({query:e,panel:t}){if(!t||!e.spec.valid)return Cn.none;let{view:n}=this,r=new kd;for(let s=0,a=n.visibleRanges,i=a.length;s<i;s++){let{from:l,to:c}=a[s];for(;s<i-1&&c>a[s+1].from-500;)c=a[++s].to;e.highlight(n.state,l,c,(u,d)=>{let f=n.state.selection.ranges.some(p=>p.from==u&&p.to==d);r.add(u,d,f?F8n:L8n)})}return r.finish()}},{decorations:e=>e.decorations});function f3(e){return t=>{let n=t.state.field($w,!1);return n&&n.query.spec.valid?e(t,n):xxt(t)}}const E7=f3((e,{query:t})=>{let{to:n}=e.state.selection.main,r=t.nextMatch(e.state,n,n);if(!r)return!1;let s=xt.single(r.from,r.to),a=e.state.facet(VN);return e.dispatch({selection:s,effects:[o1e(e,r),a.scrollToMatch(s.main,e)],userEvent:"select.search"}),bxt(e),!0}),j7=f3((e,{query:t})=>{let{state:n}=e,{from:r}=n.selection.main,s=t.prevMatch(n,r,r);if(!s)return!1;let a=xt.single(s.from,s.to),i=e.state.facet(VN);return e.dispatch({selection:a,effects:[o1e(e,s),i.scrollToMatch(a.main,e)],userEvent:"select.search"}),bxt(e),!0}),B8n=f3((e,{query:t})=>{let n=t.matchAll(e.state,1e3);return!n||!n.length?!1:(e.dispatch({selection:xt.create(n.map(r=>xt.range(r.from,r.to))),userEvent:"select.search.matches"}),!0)}),U8n=({state:e,dispatch:t})=>{let n=e.selection;if(n.ranges.length>1||n.main.empty)return!1;let{from:r,to:s}=n.main,a=[],i=0;for(let l=new _x(e.doc,e.sliceDoc(r,s));!l.next().done;){if(a.length>1e3)return!1;l.value.from==r&&(i=a.length),a.push(xt.range(l.value.from,l.value.to))}return t(e.update({selection:xt.create(a,i),userEvent:"select.search.matches"})),!0},f6e=f3((e,{query:t})=>{let{state:n}=e,{from:r,to:s}=n.selection.main;if(n.readOnly)return!1;let a=t.nextMatch(n,r,r);if(!a)return!1;let i=a,l=[],c,u,d=[];i.precise?i.from==r&&i.to==s&&(u=n.toText(t.getReplacement(i)),l.push({from:i.from,to:i.to,insert:u}),d.push(It.announce.of(n.phrase("replaced match on line $",n.doc.lineAt(r).number)+"."))):i=t.nextMatch(n,i.from,i.to);let f=e.state.changes(l);return i&&(c=xt.single(i.from,i.to).map(f),d.push(o1e(e,i)),d.push(n.facet(VN).scrollToMatch(c.main,e))),e.dispatch({changes:f,selection:c,effects:d,userEvent:"input.replace"}),!0}),q8n=f3((e,{query:t})=>{if(e.state.readOnly)return!1;let n=[];for(let s of t.matchAll(e.state,1e9)){let{from:a,to:i,precise:l}=s;l&&n.push({from:a,to:i,insert:t.getReplacement(s)})}if(!n.length)return!1;let r=e.state.phrase("replaced $ matches",n.length)+".";return e.dispatch({changes:n,effects:It.announce.of(r),userEvent:"input.replace.all"}),!0});function i1e(e){return e.state.facet(VN).createPanel(e)}function whe(e,t){var n,r,s,a,i;let l=e.selection.main,c=l.empty||l.to>l.from+100?"":e.sliceDoc(l.from,l.to);if(t&&!c)return t;let u=e.facet(VN);return new gxt({search:((n=t?.literal)!==null&&n!==void 0?n:u.literal)?c:c.replace(/\n/g,"\\n"),caseSensitive:(r=t?.caseSensitive)!==null&&r!==void 0?r:u.caseSensitive,literal:(s=t?.literal)!==null&&s!==void 0?s:u.literal,regexp:(a=t?.regexp)!==null&&a!==void 0?a:u.regexp,wholeWord:(i=t?.wholeWord)!==null&&i!==void 0?i:u.wholeWord})}function yxt(e){let t=Swe(e,i1e);return t&&t.dom.querySelector("[main-field]")}function bxt(e){let t=yxt(e);t&&t==e.root.activeElement&&t.select()}const xxt=e=>{let t=e.state.field($w,!1);if(t&&t.panel){let n=yxt(e);if(n&&n!=e.root.activeElement){let r=whe(e.state,t.query.spec);r.valid&&e.dispatch({effects:X$.of(r)}),n.focus(),n.select()}}else e.dispatch({effects:[a1e.of(!0),t?X$.of(whe(e.state,t.query.spec)):vr.appendConfig.of(Z8n)]});return!0},wxt=e=>{let t=e.state.field($w,!1);if(!t||!t.panel)return!1;let n=Swe(e,i1e);return n&&n.dom.contains(e.root.activeElement)&&e.focus(),e.dispatch({effects:a1e.of(!1)}),!0},V8n=[{key:"Mod-f",run:xxt,scope:"editor search-panel"},{key:"F3",run:E7,shift:j7,scope:"editor search-panel",preventDefault:!0},{key:"Mod-g",run:E7,shift:j7,scope:"editor search-panel",preventDefault:!0},{key:"Escape",run:wxt,scope:"editor search-panel"},{key:"Mod-Shift-l",run:U8n},{key:"Mod-Alt-g",run:x8n},{key:"Mod-d",run:I8n,preventDefault:!0}];class H8n{constructor(t){this.view=t;let n=this.query=t.state.field($w).query.spec;this.commit=this.commit.bind(this),this.searchField=ci("input",{value:n.search,placeholder:Qf(t,"Find"),"aria-label":Qf(t,"Find"),class:"cm-textfield",name:"search",form:"","main-field":"true",onchange:this.commit,onkeyup:this.commit}),this.replaceField=ci("input",{value:n.replace,placeholder:Qf(t,"Replace"),"aria-label":Qf(t,"Replace"),class:"cm-textfield",name:"replace",form:"",onchange:this.commit,onkeyup:this.commit}),this.caseField=ci("input",{type:"checkbox",name:"case",form:"",checked:n.caseSensitive,onchange:this.commit}),this.reField=ci("input",{type:"checkbox",name:"re",form:"",checked:n.regexp,onchange:this.commit}),this.wordField=ci("input",{type:"checkbox",name:"word",form:"",checked:n.wholeWord,onchange:this.commit});function r(s,a,i){return ci("button",{class:"cm-button",name:s,onclick:a,type:"button"},i)}this.dom=ci("div",{onkeydown:s=>this.keydown(s),class:"cm-search"},[this.searchField,r("next",()=>E7(t),[Qf(t,"next")]),r("prev",()=>j7(t),[Qf(t,"previous")]),r("select",()=>B8n(t),[Qf(t,"all")]),ci("label",null,[this.caseField,Qf(t,"match case")]),ci("label",null,[this.reField,Qf(t,"regexp")]),ci("label",null,[this.wordField,Qf(t,"by word")]),...t.state.readOnly?[]:[ci("br"),this.replaceField,r("replace",()=>f6e(t),[Qf(t,"replace")]),r("replaceAll",()=>q8n(t),[Qf(t,"replace all")])],ci("button",{name:"close",onclick:()=>wxt(t),"aria-label":Qf(t,"close"),type:"button"},["×"])])}commit(){let t=new gxt({search:this.searchField.value,caseSensitive:this.caseField.checked,regexp:this.reField.checked,wholeWord:this.wordField.checked,replace:this.replaceField.value});t.eq(this.query)||(this.query=t,this.view.dispatch({effects:X$.of(t)}))}keydown(t){d3n(this.view,t,"search-panel")?t.preventDefault():t.keyCode==13&&t.target==this.searchField?(t.preventDefault(),(t.shiftKey?j7:E7)(this.view)):t.keyCode==13&&t.target==this.replaceField&&(t.preventDefault(),f6e(this.view))}update(t){for(let n of t.transactions)for(let r of n.effects)r.is(X$)&&!r.value.eq(this.query)&&this.setQuery(r.value)}setQuery(t){this.query=t,this.searchField.value=t.search,this.replaceField.value=t.replace,this.caseField.checked=t.caseSensitive,this.reField.checked=t.regexp,this.wordField.checked=t.wholeWord}mount(){this.searchField.select()}get pos(){return 80}get top(){return this.view.state.facet(VN).top}}function Qf(e,t){return e.state.phrase(t)}const w6=30,S6=/[\s\.,:;?!]/;function o1e(e,{from:t,to:n}){let r=e.state.doc.lineAt(t),s=e.state.doc.lineAt(n).to,a=Math.max(r.from,t-w6),i=Math.min(s,n+w6),l=e.state.sliceDoc(a,i);if(a!=r.from){for(let c=0;c<w6;c++)if(!S6.test(l[c+1])&&S6.test(l[c])){l=l.slice(c);break}}if(i!=s){for(let c=l.length-1;c>l.length-w6;c--)if(!S6.test(l[c-1])&&S6.test(l[c])){l=l.slice(0,c);break}}return It.announce.of(`${e.state.phrase("current match")}. ${l} ${e.state.phrase("on line")} ${r.number}.`)}const W8n=It.baseTheme({".cm-panel.cm-search":{padding:"2px 6px 4px",position:"relative","& [name=close]":{position:"absolute",top:"0",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",padding:0,margin:0},"& input, & button, & label":{margin:".2em .6em .2em 0"},"& input[type=checkbox]":{marginRight:".2em"},"& label":{fontSize:"80%",whiteSpace:"pre"}},"&light .cm-searchMatch":{backgroundColor:"#ffff0054"},"&dark .cm-searchMatch":{backgroundColor:"#00ffff8a"},"&light .cm-searchMatch-selected":{backgroundColor:"#ff6a0054"},"&dark .cm-searchMatch-selected":{backgroundColor:"#ff00ff8a"}}),Z8n=[$w,Mg.low(z8n),W8n];class p6e{constructor(t,n,r){this.from=t,this.to=n,this.diagnostic=r}}class hk{constructor(t,n,r){this.diagnostics=t,this.panel=n,this.selected=r}static init(t,n,r){let s=r.facet(K$).markerFilter;s&&(t=s(t,r));let a=t.slice().sort((d,f)=>d.from-f.from||d.to-f.to),i=new kd,l=[],c=0;for(let d=0;;){let f=d==a.length?null:a[d];if(!f&&!l.length)break;let p,h;for(l.length?(p=c,h=l.reduce((v,y)=>Math.min(v,y.to),f&&f.from>p?f.from:1e8)):(p=f.from,h=f.to,l.push(f),d++);d<a.length;){let v=a[d];if(v.from==p&&(v.to>v.from||v.to==p))l.push(v),d++,h=Math.min(v.to,h);else{h=Math.min(v.from,h);break}}let m=izn(l);if(l.some(v=>v.from==v.to||v.from==v.to-1&&r.doc.lineAt(v.from).to==v.from))i.add(p,p,Cn.widget({widget:new nzn(m),diagnostics:l.slice()}));else{let v=l.reduce((y,b)=>b.markClass?y+" "+b.markClass:y,"");i.add(p,h,Cn.mark({class:"cm-lintRange cm-lintRange-"+m+v,diagnostics:l.slice(),inclusiveEnd:l.some(y=>y.to>h)}))}c=h;for(let v=0;v<l.length;v++)l[v].to<=c&&l.splice(v--,1)}let u=i.finish();return new hk(u,n,xT(u))}}function xT(e,t=null,n=0){let r=null;return e.between(n,1e9,(s,a,{spec:i})=>{if(!(t&&i.diagnostics.indexOf(t)<0))if(!r)r=new p6e(s,a,t||i.diagnostics[0]);else{if(i.diagnostics.indexOf(r.diagnostic)<0)return!1;r=new p6e(r.from,a,r.diagnostic)}}),r}function G8n(e,t){let n=t.pos,r=t.end||n,s=e.state.facet(K$).hideOn(e,n,r);if(s!=null)return s;let a=e.startState.doc.lineAt(t.pos);return!!(e.effects.some(i=>i.is(Sxt))||e.changes.touchesRange(a.from,Math.max(a.to,r)))}function Q8n(e,t){return e.field(xp,!1)?t:t.concat(vr.appendConfig.of(ozn))}const Sxt=vr.define(),l1e=vr.define(),kxt=vr.define(),xp=gl.define({create(){return new hk(Cn.none,null,null)},update(e,t){if(t.docChanged&&e.diagnostics.size){let n=e.diagnostics.map(t.changes),r=null,s=e.panel;if(e.selected){let a=t.changes.mapPos(e.selected.from,1);r=xT(n,e.selected.diagnostic,a)||xT(n,null,a)}!n.size&&s&&t.state.facet(K$).autoPanel&&(s=null),e=new hk(n,s,r)}for(let n of t.effects)if(n.is(Sxt)){let r=t.state.facet(K$).autoPanel?n.value.length?J$.open:null:e.panel;e=hk.init(n.value,r,t.state)}else n.is(l1e)?e=new hk(e.diagnostics,n.value?J$.open:null,e.selected):n.is(kxt)&&(e=new hk(e.diagnostics,e.panel,n.value));return e},provide:e=>[B$.from(e,t=>t.panel),It.decorations.from(e,t=>t.diagnostics)]}),Y8n=Cn.mark({class:"cm-lintRange cm-lintRange-active"});function X8n(e,t,n){let{diagnostics:r}=e.state.field(xp),s,a=-1,i=-1;r.between(t-(n<0?1:0),t+(n>0?1:0),(c,u,{spec:d})=>{if(t>=c&&t<=u&&(c==u||(t>c||n>0)&&(t<u||n<0)))return s=d.diagnostics,a=c,i=u,!1});let l=e.state.facet(K$).tooltipFilter;return s&&l&&(s=l(s,e.state)),s?{pos:a,end:i,above:e.state.doc.lineAt(a).to<i,create(){return{dom:K8n(e,s)}}}:null}function K8n(e,t){return ci("ul",{class:"cm-tooltip-lint"},t.map(n=>_xt(e,n,!1)))}const J8n=e=>{let t=e.state.field(xp,!1);(!t||!t.panel)&&e.dispatch({effects:Q8n(e.state,[l1e.of(!0)])});let n=Swe(e,J$.open);return n&&n.dom.querySelector(".cm-panel-lint ul").focus(),!0},h6e=e=>{let t=e.state.field(xp,!1);return!t||!t.panel?!1:(e.dispatch({effects:l1e.of(!1)}),!0)},ezn=e=>{let t=e.state.field(xp,!1);if(!t)return!1;let n=e.state.selection.main,r=t.diagnostics.iter(n.to+1);return!r.value&&(r=t.diagnostics.iter(0),!r.value||r.from==n.from&&r.to==n.to)?!1:(e.dispatch({selection:{anchor:r.from,head:r.to},scrollIntoView:!0}),!0)},tzn=[{key:"Mod-Shift-m",run:J8n,preventDefault:!0},{key:"F8",run:ezn}],K$=On.define({combine(e){return{sources:e.map(t=>t.source).filter(t=>t!=null),...$y(e.map(t=>t.config),{delay:750,markerFilter:null,tooltipFilter:null,needsRefresh:null,hideOn:()=>null},{delay:Math.max,markerFilter:m6e,tooltipFilter:m6e,needsRefresh:(t,n)=>t?n?r=>t(r)||n(r):t:n,hideOn:(t,n)=>t?n?(r,s,a)=>t(r,s,a)||n(r,s,a):t:n,autoPanel:(t,n)=>t||n})}}});function m6e(e,t){return e?t?(n,r)=>t(e(n,r),r):e:t}function Oxt(e){let t=[];if(e)e:for(let{name:n}of e){for(let r=0;r<n.length;r++){let s=n[r];if(/[a-zA-Z]/.test(s)&&!t.some(a=>a.toLowerCase()==s.toLowerCase())){t.push(s);continue e}}t.push("")}return t}function _xt(e,t,n){var r;let s=n?Oxt(t.actions):[];return ci("li",{class:"cm-diagnostic cm-diagnostic-"+t.severity},ci("span",{class:"cm-diagnosticText"},t.renderMessage?t.renderMessage(e):t.message),(r=t.actions)===null||r===void 0?void 0:r.map((a,i)=>{let l=!1,c=h=>{if(h.preventDefault(),l)return;l=!0;let m=xT(e.state.field(xp).diagnostics,t);m&&a.apply(e,m.from,m.to)},{name:u}=a,d=s[i]?u.indexOf(s[i]):-1,f=d<0?u:[u.slice(0,d),ci("u",u.slice(d,d+1)),u.slice(d+1)],p=a.markClass?" "+a.markClass:"";return ci("button",{type:"button",class:"cm-diagnosticAction"+p,onclick:c,onmousedown:c,"aria-label":` Action: ${u}${d<0?"":` (access key "${s[i]})"`}.`},f)}),t.source&&ci("div",{class:"cm-diagnosticSource"},t.source))}class nzn extends Kp{constructor(t){super(),this.sev=t}eq(t){return t.sev==this.sev}toDOM(){return ci("span",{class:"cm-lintPoint cm-lintPoint-"+this.sev})}}class g6e{constructor(t,n){this.diagnostic=n,this.id="item_"+Math.floor(Math.random()*4294967295).toString(16),this.dom=_xt(t,n,!0),this.dom.id=this.id,this.dom.setAttribute("role","option")}}class J${constructor(t){this.view=t,this.items=[];let n=s=>{if(s.keyCode==27)h6e(this.view),this.view.focus();else if(s.keyCode==38||s.keyCode==33)this.moveSelection((this.selectedIndex-1+this.items.length)%this.items.length);else if(s.keyCode==40||s.keyCode==34)this.moveSelection((this.selectedIndex+1)%this.items.length);else if(s.keyCode==36)this.moveSelection(0);else if(s.keyCode==35)this.moveSelection(this.items.length-1);else if(s.keyCode==13)this.view.focus();else if(s.keyCode>=65&&s.keyCode<=90&&this.selectedIndex>=0){let{diagnostic:a}=this.items[this.selectedIndex],i=Oxt(a.actions);for(let l=0;l<i.length;l++)if(i[l].toUpperCase().charCodeAt(0)==s.keyCode){let c=xT(this.view.state.field(xp).diagnostics,a);c&&a.actions[l].apply(t,c.from,c.to)}}else return;s.preventDefault()},r=s=>{for(let a=0;a<this.items.length;a++)this.items[a].dom.contains(s.target)&&this.moveSelection(a)};this.list=ci("ul",{tabIndex:0,role:"listbox","aria-label":this.view.state.phrase("Diagnostics"),onkeydown:n,onclick:r}),this.dom=ci("div",{class:"cm-panel-lint"},this.list,ci("button",{type:"button",name:"close","aria-label":this.view.state.phrase("close"),onclick:()=>h6e(this.view)},"×")),this.update()}get selectedIndex(){let t=this.view.state.field(xp).selected;if(!t)return-1;for(let n=0;n<this.items.length;n++)if(this.items[n].diagnostic==t.diagnostic)return n;return-1}update(){let{diagnostics:t,selected:n}=this.view.state.field(xp),r=0,s=!1,a=null,i=new Set;for(t.between(0,this.view.state.doc.length,(l,c,{spec:u})=>{for(let d of u.diagnostics){if(i.has(d))continue;i.add(d);let f=-1,p;for(let h=r;h<this.items.length;h++)if(this.items[h].diagnostic==d){f=h;break}f<0?(p=new g6e(this.view,d),this.items.splice(r,0,p),s=!0):(p=this.items[f],f>r&&(this.items.splice(r,f-r),s=!0)),n&&p.diagnostic==n.diagnostic?p.dom.hasAttribute("aria-selected")||(p.dom.setAttribute("aria-selected","true"),a=p):p.dom.hasAttribute("aria-selected")&&p.dom.removeAttribute("aria-selected"),r++}});r<this.items.length&&!(this.items.length==1&&this.items[0].diagnostic.from<0);)s=!0,this.items.pop();this.items.length==0&&(this.items.push(new g6e(this.view,{from:-1,to:-1,severity:"info",message:this.view.state.phrase("No diagnostics")})),s=!0),a?(this.list.setAttribute("aria-activedescendant",a.id),this.view.requestMeasure({key:this,read:()=>({sel:a.dom.getBoundingClientRect(),panel:this.list.getBoundingClientRect()}),write:({sel:l,panel:c})=>{let u=c.height/this.list.offsetHeight;l.top<c.top?this.list.scrollTop-=(c.top-l.top)/u:l.bottom>c.bottom&&(this.list.scrollTop+=(l.bottom-c.bottom)/u)}})):this.selectedIndex<0&&this.list.removeAttribute("aria-activedescendant"),s&&this.sync()}sync(){let t=this.list.firstChild;function n(){let r=t;t=r.nextSibling,r.remove()}for(let r of this.items)if(r.dom.parentNode==this.list){for(;t!=r.dom;)n();t=r.dom.nextSibling}else this.list.insertBefore(r.dom,t);for(;t;)n()}moveSelection(t){if(this.selectedIndex<0)return;let n=this.view.state.field(xp),r=xT(n.diagnostics,this.items[t].diagnostic);r&&this.view.dispatch({selection:{anchor:r.from,head:r.to},scrollIntoView:!0,effects:kxt.of(r)})}static open(t){return new J$(t)}}function rzn(e,t='viewBox="0 0 40 40"'){return`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" ${t}>${encodeURIComponent(e)}</svg>')`}function k6(e){return rzn(`<path d="m0 2.5 l2 -1.5 l1 0 l2 1.5 l1 0" stroke="${e}" fill="none" stroke-width=".7"/>`,'width="6" height="3"')}const szn=It.baseTheme({".cm-diagnostic":{padding:"3px 6px 3px 8px",marginLeft:"-1px",display:"block",whiteSpace:"pre-wrap"},".cm-diagnostic-error":{borderLeft:"5px solid #d11"},".cm-diagnostic-warning":{borderLeft:"5px solid orange"},".cm-diagnostic-info":{borderLeft:"5px solid #999"},".cm-diagnostic-hint":{borderLeft:"5px solid #66d"},".cm-diagnosticAction":{font:"inherit",border:"none",padding:"2px 4px",backgroundColor:"#444",color:"white",borderRadius:"3px",marginLeft:"8px",cursor:"pointer"},".cm-diagnosticSource":{fontSize:"70%",opacity:.7},".cm-lintRange":{backgroundPosition:"left bottom",backgroundRepeat:"repeat-x",paddingBottom:"0.7px"},".cm-lintRange-error":{backgroundImage:k6("#d11")},".cm-lintRange-warning":{backgroundImage:k6("orange")},".cm-lintRange-info":{backgroundImage:k6("#999")},".cm-lintRange-hint":{backgroundImage:k6("#66d")},".cm-lintRange-active":{backgroundColor:"#ffdd9980"},".cm-tooltip-lint":{padding:0,margin:0},".cm-lintPoint":{position:"relative","&:after":{content:'""',position:"absolute",bottom:0,left:"-2px",borderLeft:"3px solid transparent",borderRight:"3px solid transparent",borderBottom:"4px solid #d11"}},".cm-lintPoint-warning":{"&:after":{borderBottomColor:"orange"}},".cm-lintPoint-info":{"&:after":{borderBottomColor:"#999"}},".cm-lintPoint-hint":{"&:after":{borderBottomColor:"#66d"}},".cm-panel.cm-panel-lint":{position:"relative","& ul":{maxHeight:"100px",overflowY:"auto","& [aria-selected]":{backgroundColor:"#ddd","& u":{textDecoration:"underline"}},"&:focus [aria-selected]":{background_fallback:"#bdf",backgroundColor:"Highlight",color_fallback:"white",color:"HighlightText"},"& u":{textDecoration:"none"},padding:0,margin:0},"& [name=close]":{position:"absolute",top:"0",right:"2px",background:"inherit",border:"none",font:"inherit",padding:0,margin:0}}});function azn(e){return e=="error"?4:e=="warning"?3:e=="info"?2:1}function izn(e){let t="hint",n=1;for(let r of e){let s=azn(r.severity);s>n&&(n=s,t=r.severity)}return t}const ozn=[xp,It.decorations.compute([xp],e=>{let{selected:t,panel:n}=e.field(xp);return!t||!n||t.from==t.to?Cn.none:Cn.set([Y8n.range(t.from,t.to)])}),J3n(X8n,{hideOn:G8n}),szn];var v6e=function(t){t===void 0&&(t={});var n=t,r=n.crosshairCursor,s=r===void 0?!1:r,a=[];t.closeBracketsKeymap!==!1&&(a=a.concat(Y5n)),t.defaultKeymap!==!1&&(a=a.concat(v8n)),t.searchKeymap!==!1&&(a=a.concat(V8n)),t.historyKeymap!==!1&&(a=a.concat(OFn)),t.foldKeymap!==!1&&(a=a.concat($4n)),t.completionKeymap!==!1&&(a=a.concat(byt)),t.lintKeymap!==!1&&(a=a.concat(tzn));var i=[];return t.lineNumbers!==!1&&i.push(d4n()),t.highlightActiveLineGutter!==!1&&i.push(h4n()),t.highlightSpecialChars!==!1&&i.push(E3n()),t.history!==!1&&i.push(mFn()),t.foldGutter!==!1&&i.push(F4n()),t.drawSelection!==!1&&i.push(v3n()),t.dropCursor!==!1&&i.push(S3n()),t.allowMultipleSelections!==!1&&i.push(is.allowMultipleSelections.of(!0)),t.indentOnInput!==!1&&i.push(E4n()),t.syntaxHighlighting!==!1&&i.push(B1(q4n,{fallback:!0})),t.bracketMatching!==!1&&i.push(Y4n()),t.closeBrackets!==!1&&i.push(W5n()),t.autocompletion!==!1&&i.push(yyt()),t.rectangularSelection!==!1&&i.push(B3n()),s!==!1&&i.push(V3n()),t.highlightActiveLine!==!1&&i.push(R3n()),t.highlightSelectionMatches!==!1&&i.push(k8n()),t.tabSize&&typeof t.tabSize=="number"&&i.push(zN.of(" ".repeat(t.tabSize))),i.concat([FN.of(a.flat())]).filter(Boolean)};const lzn="#e5c07b",y6e="#e06c75",czn="#56b6c2",uzn="#ffffff",XF="#abb2bf",She="#7d8799",dzn="#61afef",fzn="#98c379",b6e="#d19a66",pzn="#c678dd",hzn="#21252b",x6e="#2c313a",w6e="#282c34",GK="#353a42",mzn="#3E4451",S6e="#528bff",gzn=It.theme({"&":{color:XF,backgroundColor:w6e},".cm-content":{caretColor:S6e},".cm-cursor, .cm-dropCursor":{borderLeftColor:S6e},"&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection":{backgroundColor:mzn},".cm-panels":{backgroundColor:hzn,color:XF},".cm-panels.cm-panels-top":{borderBottom:"2px solid black"},".cm-panels.cm-panels-bottom":{borderTop:"2px solid black"},".cm-searchMatch":{backgroundColor:"#72a1ff59",outline:"1px solid #457dff"},".cm-searchMatch.cm-searchMatch-selected":{backgroundColor:"#6199ff2f"},".cm-activeLine":{backgroundColor:"#6699ff0b"},".cm-selectionMatch":{backgroundColor:"#aafe661a"},"&.cm-focused .cm-matchingBracket, &.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bad0f847"},".cm-gutters":{backgroundColor:w6e,color:She,border:"none"},".cm-activeLineGutter":{backgroundColor:x6e},".cm-foldPlaceholder":{backgroundColor:"transparent",border:"none",color:"#ddd"},".cm-tooltip":{border:"none",backgroundColor:GK},".cm-tooltip .cm-tooltip-arrow:before":{borderTopColor:"transparent",borderBottomColor:"transparent"},".cm-tooltip .cm-tooltip-arrow:after":{borderTopColor:GK,borderBottomColor:GK},".cm-tooltip-autocomplete":{"& > ul > li[aria-selected]":{backgroundColor:x6e,color:XF}}},{dark:!0}),vzn=Dg.define([{tag:fe.keyword,color:pzn},{tag:[fe.name,fe.deleted,fe.character,fe.propertyName,fe.macroName],color:y6e},{tag:[fe.function(fe.variableName),fe.labelName],color:dzn},{tag:[fe.color,fe.constant(fe.name),fe.standard(fe.name)],color:b6e},{tag:[fe.definition(fe.name),fe.separator],color:XF},{tag:[fe.typeName,fe.className,fe.number,fe.changed,fe.annotation,fe.modifier,fe.self,fe.namespace],color:lzn},{tag:[fe.operator,fe.operatorKeyword,fe.url,fe.escape,fe.regexp,fe.link,fe.special(fe.string)],color:czn},{tag:[fe.meta,fe.comment],color:She},{tag:fe.strong,fontWeight:"bold"},{tag:fe.emphasis,fontStyle:"italic"},{tag:fe.strikethrough,textDecoration:"line-through"},{tag:fe.link,color:She,textDecoration:"underline"},{tag:fe.heading,fontWeight:"bold",color:y6e},{tag:[fe.atom,fe.bool,fe.special(fe.variableName)],color:b6e},{tag:[fe.processingInstruction,fe.string,fe.inserted],color:fzn},{tag:fe.invalid,color:uzn}]),yzn=[gzn,B1(vzn)];var bzn=It.theme({"&":{backgroundColor:"#fff"}},{dark:!1}),xzn=function(t){t===void 0&&(t={});var n=t,r=n.indentWithTab,s=r===void 0?!0:r,a=n.editable,i=a===void 0?!0:a,l=n.readOnly,c=l===void 0?!1:l,u=n.theme,d=u===void 0?"light":u,f=n.placeholder,p=f===void 0?"":f,h=n.basicSetup,m=h===void 0?!0:h,v=[];switch(s&&v.unshift(FN.of([y8n])),m&&(typeof m=="boolean"?v.unshift(v6e()):v.unshift(v6e(m))),p&&v.unshift(D3n(p)),d){case"light":v.push(bzn);break;case"dark":v.push(yzn);break;case"none":break;default:v.push(d);break}return i===!1&&v.push(It.editable.of(!1)),c&&v.push(is.readOnly.of(!0)),[...v]},wzn=e=>({line:e.state.doc.lineAt(e.state.selection.main.from),lineCount:e.state.doc.lines,lineBreak:e.state.lineBreak,length:e.state.doc.length,readOnly:e.state.readOnly,tabSize:e.state.tabSize,selection:e.state.selection,selectionAsSingle:e.state.selection.asSingle().main,ranges:e.state.selection.ranges,selectionCode:e.state.sliceDoc(e.state.selection.main.from,e.state.selection.main.to),selections:e.state.selection.ranges.map(t=>e.state.sliceDoc(t.from,t.to)),selectedText:e.state.selection.ranges.some(t=>!t.empty)});class Szn{constructor(t,n){this.timeLeftMS=void 0,this.timeoutMS=void 0,this.isCancelled=!1,this.isTimeExhausted=!1,this.callbacks=[],this.timeLeftMS=n,this.timeoutMS=n,this.callbacks.push(t)}tick(){if(!this.isCancelled&&!this.isTimeExhausted&&(this.timeLeftMS--,this.timeLeftMS<=0)){this.isTimeExhausted=!0;var t=this.callbacks.slice();this.callbacks.length=0,t.forEach(n=>{try{n()}catch(r){console.error("TimeoutLatch callback error:",r)}})}}cancel(){this.isCancelled=!0,this.callbacks.length=0}reset(){this.timeLeftMS=this.timeoutMS,this.isCancelled=!1,this.isTimeExhausted=!1}get isDone(){return this.isCancelled||this.isTimeExhausted}}class k6e{constructor(){this.interval=null,this.latches=new Set}add(t){this.latches.add(t),this.start()}remove(t){this.latches.delete(t),this.latches.size===0&&this.stop()}start(){this.interval===null&&(this.interval=setInterval(()=>{this.latches.forEach(t=>{t.tick(),t.isDone&&this.remove(t)})},1))}stop(){this.interval!==null&&(clearInterval(this.interval),this.interval=null)}}var QK=null,kzn=()=>typeof window>"u"?new k6e:(QK||(QK=new k6e),QK),O6e=Py.define(),Ozn=200,_zn=[];function Czn(e){var t=e.value,n=e.selection,r=e.onChange,s=e.onStatistics,a=e.onCreateEditor,i=e.onUpdate,l=e.extensions,c=l===void 0?_zn:l,u=e.autoFocus,d=e.theme,f=d===void 0?"light":d,p=e.height,h=p===void 0?null:p,m=e.minHeight,v=m===void 0?null:m,y=e.maxHeight,b=y===void 0?null:y,S=e.width,w=S===void 0?null:S,k=e.minWidth,_=k===void 0?null:k,C=e.maxWidth,E=C===void 0?null:C,j=e.placeholder,N=j===void 0?"":j,I=e.editable,R=I===void 0?!0:I,P=e.readOnly,L=P===void 0?!1:P,M=e.indentWithTab,q=M===void 0?!0:M,H=e.basicSetup,F=H===void 0?!0:H,z=e.root,B=e.initialState,D=g.useState(),Q=D[0],V=D[1],$=g.useState(),U=$[0],Z=$[1],X=g.useState(),te=X[0],J=X[1],ee=g.useState(()=>({current:null}))[0],ae=g.useState(()=>({current:null}))[0],ce=It.theme({"&":{height:h,minHeight:v,maxHeight:b,width:w,minWidth:_,maxWidth:E},"& .cm-scroller":{height:"100% !important"}}),Y=It.updateListener.of(pe=>{if(pe.docChanged&&typeof r=="function"&&!pe.transactions.some(ye=>ye.annotation(O6e))){ee.current?ee.current.reset():(ee.current=new Szn(()=>{if(ae.current){var ye=ae.current;ae.current=null,ye()}ee.current=null},Ozn),kzn().add(ee.current));var le=pe.state.doc,ve=le.toString();r(ve,pe)}s&&s(wzn(pe))}),ne=xzn({theme:f,editable:R,readOnly:L,placeholder:N,indentWithTab:q,basicSetup:F}),ue=[Y,ce,...ne];return i&&typeof i=="function"&&ue.push(It.updateListener.of(i)),ue=ue.concat(c),g.useLayoutEffect(()=>{if(Q&&!te){var pe={doc:t,selection:n,extensions:ue},le=B?is.fromJSON(B.json,pe,B.fields):is.create(pe);if(J(le),!U){var ve=new It({state:le,parent:Q,root:z});Z(ve),a&&a(ve,le)}}return()=>{U&&(J(void 0),Z(void 0))}},[Q,te]),g.useEffect(()=>{e.container&&V(e.container)},[e.container]),g.useEffect(()=>()=>{U&&(U.destroy(),Z(void 0)),ee.current&&(ee.current.cancel(),ee.current=null)},[U]),g.useEffect(()=>{u&&U&&U.focus()},[u,U]),g.useEffect(()=>{U&&U.dispatch({effects:vr.reconfigure.of(ue)})},[f,c,h,v,b,w,_,E,N,R,L,q,F,r,i]),g.useEffect(()=>{if(t!==void 0){var pe=U?U.state.doc.toString():"";if(U&&t!==pe){var le=ee.current&&!ee.current.isDone,ve=()=>{U&&t!==U.state.doc.toString()&&U.dispatch({changes:{from:0,to:U.state.doc.toString().length,insert:t||""},annotations:[O6e.of(!0)]})};le?ae.current=ve:ve()}}},[t,U]),{state:te,setState:J,view:U,setView:Z,container:Q,setContainer:V}}var Ezn=["className","value","selection","extensions","onChange","onStatistics","onCreateEditor","onUpdate","autoFocus","theme","height","minHeight","maxHeight","width","minWidth","maxWidth","basicSetup","placeholder","indentWithTab","editable","readOnly","root","initialState"],ru=g.forwardRef((e,t)=>{var n=e.className,r=e.value,s=r===void 0?"":r,a=e.selection,i=e.extensions,l=i===void 0?[]:i,c=e.onChange,u=e.onStatistics,d=e.onCreateEditor,f=e.onUpdate,p=e.autoFocus,h=e.theme,m=h===void 0?"light":h,v=e.height,y=e.minHeight,b=e.maxHeight,S=e.width,w=e.minWidth,k=e.maxWidth,_=e.basicSetup,C=e.placeholder,E=e.indentWithTab,j=e.editable,N=e.readOnly,I=e.root,R=e.initialState,P=Rbt(e,Ezn),L=g.useRef(null),M=Czn({root:I,value:s,autoFocus:p,theme:m,height:v,minHeight:y,maxHeight:b,width:S,minWidth:w,maxWidth:k,basicSetup:_,placeholder:C,indentWithTab:E,editable:j,readOnly:N,selection:a,onChange:c,onStatistics:u,onCreateEditor:d,onUpdate:f,extensions:l,initialState:R}),q=M.state,H=M.view,F=M.container,z=M.setContainer;g.useImperativeHandle(t,()=>({editor:L.current,state:q,view:H}),[L,F,q,H]);var B=g.useCallback(Q=>{L.current=Q,z(Q)},[z]);if(typeof s!="string")throw new Error("value must be typeof string but got "+typeof s);var D=typeof m=="string"?"cm-theme-"+m:"cm-theme";return o.jsx("div",PO({ref:B,className:""+D+(n?" "+n:"")},P))});ru.displayName="CodeMirror";const jzn={js:"javascript",javascript:"javascript",mjs:"javascript",cjs:"javascript",node:"javascript",ts:"typescript",typescript:"typescript",mts:"typescript",cts:"typescript",tsx:"tsx",jsx:"jsx",json:"json",json5:"json",md:"markdown",markdown:"markdown",py:"python",python:"python",sh:"bash",bash:"bash",shell:"bash",zsh:"bash"};let YK=null;function Tzn(){return YK||(YK=(async()=>{const[{createHighlighterCore:e},{createJavaScriptRegexEngine:t}]=await Promise.all([jo(()=>import("./core-DmuC-0UU.js"),__vite__mapDeps([0,1,2]),import.meta.url),jo(()=>import("./engine-javascript-CSIo_1eZ.js"),__vite__mapDeps([3,1]),import.meta.url)]);return e({themes:[jo(()=>import("./github-light-DAi9KRSo.js"),[],import.meta.url),jo(()=>import("./github-dark-DHJKELXO.js"),[],import.meta.url)],langs:[jo(()=>import("./javascript-ySlJ1b_l.js"),[],import.meta.url),jo(()=>import("./typescript-Dj6nwHGl.js"),[],import.meta.url),jo(()=>import("./tsx-B6W0miNI.js"),[],import.meta.url),jo(()=>import("./jsx-BAng5TT0.js"),[],import.meta.url),jo(()=>import("./json-BQoSv7ci.js"),[],import.meta.url),jo(()=>import("./bash-atvbtKCR.js"),[],import.meta.url),jo(()=>import("./markdown-UIAJJxZW.js"),[],import.meta.url),jo(()=>import("./python-DhUJRlN_.js"),[],import.meta.url)],engine:t()})})()),YK}async function Nzn(e,t){const n=jzn[t?.toLowerCase()];if(!n)return null;const r=await Tzn(),{tokens:s}=r.codeToTokens(e,{lang:n,defaultColor:!1,themes:{light:"github-light",dark:"github-dark"}});return s}function Izn(e){return new NO(Ewe.define(e))}const Cxt=[Km.of({name:"JavaScript",alias:["ecmascript","js","node"],extensions:["js","mjs","cjs"],load(){return jo(()=>Promise.resolve().then(()=>b6),void 0,import.meta.url).then(e=>e.javascript())}}),Km.of({name:"JSON",alias:["json5"],extensions:["json","map"],load(){return jo(()=>Promise.resolve().then(()=>l5n),void 0,import.meta.url).then(e=>e.json())}}),Km.of({name:"JSX",extensions:["jsx"],load(){return jo(()=>Promise.resolve().then(()=>b6),void 0,import.meta.url).then(e=>e.javascript({jsx:!0}))}}),Km.of({name:"Markdown",extensions:["md","markdown","mkd"],load(){return jo(()=>Promise.resolve().then(()=>nFn),void 0,import.meta.url).then(e=>e.markdown())}}),Km.of({name:"TSX",extensions:["tsx"],load(){return jo(()=>Promise.resolve().then(()=>b6),void 0,import.meta.url).then(e=>e.javascript({jsx:!0,typescript:!0}))}}),Km.of({name:"TypeScript",alias:["ts"],extensions:["ts","mts","cts"],load(){return jo(()=>Promise.resolve().then(()=>b6),void 0,import.meta.url).then(e=>e.javascript({typescript:!0}))}}),Km.of({name:"Shell",alias:["bash","sh","zsh"],extensions:["sh","ksh","bash"],filename:/^PKGBUILD$/,load(){return jo(()=>import("./shell-CjFT_Tl9.js"),[],import.meta.url).then(e=>Izn(e.shell))}})];function Azn(e,t=5){if(!e?.properties)return[];const n=[];function r(s,a,i){if(i>t)return;const l=Array.isArray(s.type)?s.type.join(" | "):s.type;if(n.push({path:a,label:a,description:s.description??s.title,type:l}),s.properties)for(const[c,u]of Object.entries(s.properties))r(u,`${a}.${c}`,i+1);if(s.items?.properties)for(const[c,u]of Object.entries(s.items.properties))r(u,`${a}[].${c}`,i+1)}for(const[s,a]of Object.entries(e.properties))r(a,s,1);return n}function Rzn(e){const t=Azn(e);return yyt({override:[Pzn(t)],defaultKeymap:!0,closeOnBlur:!0,icons:!1})}function Pzn(e){return t=>{const r=t.state.sliceDoc(Math.max(0,t.pos-50),t.pos).match(/\{\{([a-zA-Z0-9_.\[\]]*)?$/);if(!r)return null;const s=r[1]??"",a=t.pos-s.length,i=s?e.filter(c=>c.path.toLowerCase().startsWith(s.toLowerCase())):e;if(i.length===0)return null;const l=i.map(c=>({label:c.path,displayLabel:c.path,detail:c.type,info:c.description,apply:(u,d,f,p)=>{const v=u.state.sliceDoc(p,p+2)==="}}"?d.label:`${d.label}}}`;u.dispatch({changes:{from:f,to:p,insert:v},selection:{anchor:f+v.length}})}}));return{from:a,options:l,validFor:/^[a-zA-Z0-9_.\[\]]*$/}}}const $zn=/\{\{([a-zA-Z_][a-zA-Z0-9_]*(?:\.[a-zA-Z_][a-zA-Z0-9_]*)*)\}\}/g,Mzn=Cn.mark({class:"cm-variable-highlight"}),_6e=new Avt({regexp:$zn,decoration:()=>Mzn}),Dzn=bo.fromClass(class{decorations;constructor(e){this.decorations=_6e.createDeco(e)}update(e){this.decorations=_6e.updateDeco(e,this.decorations)}},{decorations:e=>e.decorations}),Lzn=Dzn;function Fzn(){const e=UN({settings:{fontFamily:"var(--font-mono)",fontSize:"0.8rem",lineHighlight:"transparent",gutterBackground:"transparent",gutterForeground:"var(--neutral2)",background:"transparent",foreground:"var(--neutral6)",caret:"var(--neutral6)"},styles:[{tag:[fe.className,fe.propertyName],color:"var(--neutral6)"},{tag:fe.heading,color:"var(--accent3)",fontWeight:"bold"},{tag:[fe.heading1,fe.heading2,fe.heading3,fe.heading4,fe.heading5,fe.heading6],color:"var(--accent3)",fontWeight:"bold"},{tag:fe.emphasis,fontStyle:"italic",color:"var(--neutral6)"},{tag:fe.strong,fontWeight:"bold",color:"var(--neutral6)"},{tag:fe.link,color:"var(--accent3)",textDecoration:"underline"},{tag:fe.url,color:"var(--accent3)"},{tag:fe.monospace,color:"var(--neutral6)"},{tag:fe.strikethrough,textDecoration:"line-through"},{tag:fe.quote,fontStyle:"italic",color:"var(--neutral2)"}]}),t=It.theme({".cm-editor":{backgroundColor:"transparent"},".cm-content":{color:"var(--neutral6)",caretColor:"var(--neutral6)"},".cm-lineNumbers .cm-gutterElement":{color:"var(--neutral2)"},".cm-activeLineGutter":{color:"var(--neutral3)"},".cm-cursor":{borderLeftColor:"var(--neutral6)"},".cm-selectionBackground, .cm-content ::selection":{backgroundColor:"color-mix(in srgb, var(--accent3) 22%, transparent)"},".cm-tooltip-autocomplete":{backgroundColor:"var(--surface2)",border:"1px solid var(--border1)",borderRadius:"6px",boxShadow:"0 8px 16px rgba(0, 0, 0, 0.2)"},".cm-tooltip-autocomplete > ul":{fontFamily:"var(--font-mono)"},".cm-completionLabel":{color:"var(--neutral6)"},".cm-completionDetail":{color:"var(--neutral3)",fontSize:"0.7rem",marginLeft:"auto",paddingLeft:"12px"},".cm-completionInfo":{backgroundColor:"var(--surface2)",border:"1px solid var(--border1)",color:"var(--neutral3)",padding:"8px 12px"},".cm-completionIcon":{display:"none"},"ul.cm-completionList li[aria-selected]":{backgroundColor:"var(--surface4)",color:"var(--neutral6)"},".cm-line .cm-variable-highlight":{color:"var(--accent6) !important",fontWeight:"500"}});return[e,t]}function zzn(){const e=It.theme({"&":{backgroundColor:"transparent",color:"var(--neutral6)",fontSize:"0.8rem"},"&.cm-editor .cm-scroller":{fontFamily:"var(--font-mono)"},".cm-gutters":{backgroundColor:"transparent",color:"var(--neutral2)",borderRight:"none"},".cm-content":{color:"var(--neutral6)",caretColor:"var(--neutral6)"},".cm-activeLine":{backgroundColor:"transparent"},".cm-lineNumbers .cm-gutterElement":{color:"var(--neutral2)"},".cm-activeLineGutter":{backgroundColor:"transparent",color:"var(--neutral3)"},".cm-cursor, .cm-dropCursor":{borderLeftColor:"var(--neutral6)"},"&.cm-focused .cm-selectionBackground, & .cm-line::selection, & .cm-selectionLayer .cm-selectionBackground, .cm-content ::selection":{background:"color-mix(in srgb, var(--accent3) 22%, transparent) !important"},".cm-tooltip-autocomplete":{backgroundColor:"var(--surface2)",border:"1px solid var(--border1)",borderRadius:"6px",boxShadow:"0 8px 16px rgba(0, 0, 0, 0.2)"},".cm-tooltip-autocomplete > ul":{fontFamily:"var(--font-mono)"},".cm-completionLabel":{color:"var(--neutral6)"},".cm-completionDetail":{color:"var(--neutral3)",fontSize:"0.7rem",marginLeft:"auto",paddingLeft:"12px"},".cm-completionInfo":{backgroundColor:"var(--surface2)",border:"1px solid var(--border1)",color:"var(--neutral3)",padding:"8px 12px"},".cm-completionIcon":{display:"none"},"ul.cm-completionList li[aria-selected]":{backgroundColor:"var(--surface4)",color:"var(--neutral6)"},".cm-line .cm-variable-highlight":{color:"var(--accent6) !important",fontWeight:"500"}}),t=Dg.define([{tag:[fe.comment,fe.bracket],color:"var(--neutral2)"},{tag:[fe.string,fe.meta,fe.regexp],color:"var(--accent1)"},{tag:[fe.atom,fe.bool,fe.special(fe.variableName)],color:"var(--accent6)"},{tag:[fe.keyword,fe.operator,fe.tagName],color:"var(--accent2)"},{tag:[fe.function(fe.propertyName),fe.propertyName],color:"var(--accent5)"},{tag:[fe.definition(fe.variableName),fe.function(fe.variableName),fe.className,fe.attributeName],color:"var(--accent3)"},{tag:[fe.variableName,fe.number],color:"var(--accent5)"},{tag:[fe.name,fe.quote],color:"var(--accent1)"},{tag:fe.heading,color:"var(--accent3)",fontWeight:"bold"},{tag:[fe.heading1,fe.heading2,fe.heading3,fe.heading4,fe.heading5,fe.heading6],color:"var(--accent3)",fontWeight:"bold"},{tag:[fe.emphasis],fontStyle:"italic",color:"var(--neutral6)"},{tag:[fe.strong],fontWeight:"bold",color:"var(--neutral6)"},{tag:fe.link,color:"var(--accent3)",textDecoration:"underline"},{tag:fe.url,color:"var(--accent3)"},{tag:fe.monospace,color:"var(--neutral6)"},{tag:fe.strikethrough,textDecoration:"line-through"},{tag:[fe.deleted],color:"var(--accent2)"},{tag:fe.invalid,color:"var(--error)"},{tag:[fe.standard(fe.tagName)],color:"var(--accent1)"}]);return[e,B1(t)]}const My=()=>{const e=PN().resolvedTheme==="dark";return g.useMemo(()=>e?Fzn():zzn(),[e])},Qr=g.forwardRef(({data:e,value:t,onChange:n,showCopyButton:r=!0,className:s,language:a="json",highlightVariables:i=!1,placeholder:l,schema:c,autoFocus:u,lineNumbers:d=!0,lineWrapping:f=!0,editable:p,...h},m)=>{const v=My(),y=e?JSON.stringify(e,null,2):t??"",b=g.useMemo(()=>{const S=[];return f&&S.push(It.lineWrapping),a==="json"?S.push(ff):a==="markdown"&&S.push(e1e({base:RO,codeLanguages:Cxt})),i&&a==="markdown"&&S.push(Lzn),c&&a==="markdown"&&S.push(Rzn(c)),p===!1&&S.push(is.readOnly.of(!0)),S},[a,i,c,p,f]);return o.jsxs("div",{className:K("rounded-md bg-surface3 p-1 font-mono relative border border-border1 overflow-hidden",s),...h,children:[r&&o.jsx(Oa,{content:y,className:"absolute top-2 right-2 z-20"}),o.jsx(ru,{ref:m,value:y,theme:v,extensions:b,onChange:n,editable:p,"aria-label":"Code editor",placeholder:l,height:"100%",style:{height:"100%"},autoFocus:u,basicSetup:{lineNumbers:d}})]})}),Bzn=e=>{try{return JSON.stringify(e??{},null,2)}catch{return"{}"}},Uzn=({editorClassName:e="h-[240px] max-h-[40vh]",onSaved:t})=>{const n=My(),{settings:r,setSettings:s}=tV(),a=r?.tracingOptions,i=g.useMemo(()=>Bzn(a),[a]),[l,c]=g.useState(()=>i),u=g.useRef(!1);g.useEffect(()=>{u.current||c(i)},[i]);const d=p=>{u.current=!0,c(p)},f=()=>{if(!l){s({...r,tracingOptions:void 0}),t?.();return}try{const p=JSON.parse(l);typeof p=="object"&&p!==null&&s({...r,tracingOptions:p})}catch{return}t?.()};return o.jsxs("div",{className:"space-y-2 px-5 py-2",children:[o.jsx(ge,{as:"h3",variant:"ui-md",className:"text-neutral3",children:"Tracing Options"}),o.jsx(ru,{value:l,onChange:d,theme:n,extensions:[ff],className:K("overflow-y-scroll bg-surface3 rounded-lg overflow-hidden p-3",e)}),o.jsx("div",{className:"flex items-center justify-end",children:o.jsx(de,{type:"button",onClick:f,children:"Save"})})]})},qzn=()=>{const[e,t]=g.useState(!1);return o.jsxs(o.Fragment,{children:[o.jsxs(Wn,{children:[o.jsx(zn,{asChild:!0,children:o.jsx(de,{type:"button",variant:"ghost",size:"icon-md","aria-label":"Run Options",onClick:()=>t(!0),children:o.jsx(Ue,{children:o.jsx(hq,{})})})}),o.jsx(Bn,{children:"Run Options"})]}),o.jsx(br,{open:e,onOpenChange:t,children:o.jsxs(xr,{children:[o.jsxs(wr,{children:[o.jsx(gr,{children:"Run Options"}),o.jsx(Qs,{children:"Configure tracing and debug options for this workflow run"})]}),o.jsx(Rr,{children:o.jsx(Uzn,{onSaved:()=>t(!1)})})]})})]})};function Vzn({status:e}){switch(e){case"running":return o.jsx(Gt,{});case"failed":return o.jsx(vs,{className:"text-accent2"});case"canceled":return o.jsx(Of,{className:"text-neutral3"});case"pending":case"waiting":return o.jsx(dO,{className:"text-neutral3"});case"suspended":return o.jsx(lq,{className:"text-accent3"});case"success":return o.jsx(Js,{className:"text-accent1"});default:return o.jsx(dO,{className:"text-neutral3"})}}function Ext({status:e}){return o.jsxs(Wn,{children:[o.jsx(zn,{asChild:!0,children:o.jsx(Ue,{"aria-label":e,className:"shrink-0",children:o.jsx(Vzn,{status:e})})}),o.jsx(Bn,{children:e})]})}var XK,C6e;function c1e(){if(C6e)return XK;C6e=1;var e="\0",t="\0",n="";class r{_isDirected=!0;_isMultigraph=!1;_isCompound=!1;_label;_defaultNodeLabelFn=()=>{};_defaultEdgeLabelFn=()=>{};_nodes={};_in={};_preds={};_out={};_sucs={};_edgeObjs={};_edgeLabels={};_nodeCount=0;_edgeCount=0;_parent;_children;constructor(d){d&&(this._isDirected=Object.hasOwn(d,"directed")?d.directed:!0,this._isMultigraph=Object.hasOwn(d,"multigraph")?d.multigraph:!1,this._isCompound=Object.hasOwn(d,"compound")?d.compound:!1),this._isCompound&&(this._parent={},this._children={},this._children[t]={})}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph(d){return this._label=d,this}graph(){return this._label}setDefaultNodeLabel(d){return this._defaultNodeLabelFn=d,typeof d!="function"&&(this._defaultNodeLabelFn=()=>d),this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){var d=this;return this.nodes().filter(f=>Object.keys(d._in[f]).length===0)}sinks(){var d=this;return this.nodes().filter(f=>Object.keys(d._out[f]).length===0)}setNodes(d,f){var p=arguments,h=this;return d.forEach(function(m){p.length>1?h.setNode(m,f):h.setNode(m)}),this}setNode(d,f){return Object.hasOwn(this._nodes,d)?(arguments.length>1&&(this._nodes[d]=f),this):(this._nodes[d]=arguments.length>1?f:this._defaultNodeLabelFn(d),this._isCompound&&(this._parent[d]=t,this._children[d]={},this._children[t][d]=!0),this._in[d]={},this._preds[d]={},this._out[d]={},this._sucs[d]={},++this._nodeCount,this)}node(d){return this._nodes[d]}hasNode(d){return Object.hasOwn(this._nodes,d)}removeNode(d){var f=this;if(Object.hasOwn(this._nodes,d)){var p=h=>f.removeEdge(f._edgeObjs[h]);delete this._nodes[d],this._isCompound&&(this._removeFromParentsChildList(d),delete this._parent[d],this.children(d).forEach(function(h){f.setParent(h)}),delete this._children[d]),Object.keys(this._in[d]).forEach(p),delete this._in[d],delete this._preds[d],Object.keys(this._out[d]).forEach(p),delete this._out[d],delete this._sucs[d],--this._nodeCount}return this}setParent(d,f){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(f===void 0)f=t;else{f+="";for(var p=f;p!==void 0;p=this.parent(p))if(p===d)throw new Error("Setting "+f+" as parent of "+d+" would create a cycle");this.setNode(f)}return this.setNode(d),this._removeFromParentsChildList(d),this._parent[d]=f,this._children[f][d]=!0,this}_removeFromParentsChildList(d){delete this._children[this._parent[d]][d]}parent(d){if(this._isCompound){var f=this._parent[d];if(f!==t)return f}}children(d=t){if(this._isCompound){var f=this._children[d];if(f)return Object.keys(f)}else{if(d===t)return this.nodes();if(this.hasNode(d))return[]}}predecessors(d){var f=this._preds[d];if(f)return Object.keys(f)}successors(d){var f=this._sucs[d];if(f)return Object.keys(f)}neighbors(d){var f=this.predecessors(d);if(f){const h=new Set(f);for(var p of this.successors(d))h.add(p);return Array.from(h.values())}}isLeaf(d){var f;return this.isDirected()?f=this.successors(d):f=this.neighbors(d),f.length===0}filterNodes(d){var f=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});f.setGraph(this.graph());var p=this;Object.entries(this._nodes).forEach(function([v,y]){d(v)&&f.setNode(v,y)}),Object.values(this._edgeObjs).forEach(function(v){f.hasNode(v.v)&&f.hasNode(v.w)&&f.setEdge(v,p.edge(v))});var h={};function m(v){var y=p.parent(v);return y===void 0||f.hasNode(y)?(h[v]=y,y):y in h?h[y]:m(y)}return this._isCompound&&f.nodes().forEach(v=>f.setParent(v,m(v))),f}setDefaultEdgeLabel(d){return this._defaultEdgeLabelFn=d,typeof d!="function"&&(this._defaultEdgeLabelFn=()=>d),this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(d,f){var p=this,h=arguments;return d.reduce(function(m,v){return h.length>1?p.setEdge(m,v,f):p.setEdge(m,v),v}),this}setEdge(){var d,f,p,h,m=!1,v=arguments[0];typeof v=="object"&&v!==null&&"v"in v?(d=v.v,f=v.w,p=v.name,arguments.length===2&&(h=arguments[1],m=!0)):(d=v,f=arguments[1],p=arguments[3],arguments.length>2&&(h=arguments[2],m=!0)),d=""+d,f=""+f,p!==void 0&&(p=""+p);var y=i(this._isDirected,d,f,p);if(Object.hasOwn(this._edgeLabels,y))return m&&(this._edgeLabels[y]=h),this;if(p!==void 0&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(d),this.setNode(f),this._edgeLabels[y]=m?h:this._defaultEdgeLabelFn(d,f,p);var b=l(this._isDirected,d,f,p);return d=b.v,f=b.w,Object.freeze(b),this._edgeObjs[y]=b,s(this._preds[f],d),s(this._sucs[d],f),this._in[f][y]=b,this._out[d][y]=b,this._edgeCount++,this}edge(d,f,p){var h=arguments.length===1?c(this._isDirected,arguments[0]):i(this._isDirected,d,f,p);return this._edgeLabels[h]}edgeAsObj(){const d=this.edge(...arguments);return typeof d!="object"?{label:d}:d}hasEdge(d,f,p){var h=arguments.length===1?c(this._isDirected,arguments[0]):i(this._isDirected,d,f,p);return Object.hasOwn(this._edgeLabels,h)}removeEdge(d,f,p){var h=arguments.length===1?c(this._isDirected,arguments[0]):i(this._isDirected,d,f,p),m=this._edgeObjs[h];return m&&(d=m.v,f=m.w,delete this._edgeLabels[h],delete this._edgeObjs[h],a(this._preds[f],d),a(this._sucs[d],f),delete this._in[f][h],delete this._out[d][h],this._edgeCount--),this}inEdges(d,f){var p=this._in[d];if(p){var h=Object.values(p);return f?h.filter(m=>m.v===f):h}}outEdges(d,f){var p=this._out[d];if(p){var h=Object.values(p);return f?h.filter(m=>m.w===f):h}}nodeEdges(d,f){var p=this.inEdges(d,f);if(p)return p.concat(this.outEdges(d,f))}}function s(u,d){u[d]?u[d]++:u[d]=1}function a(u,d){--u[d]||delete u[d]}function i(u,d,f,p){var h=""+d,m=""+f;if(!u&&h>m){var v=h;h=m,m=v}return h+n+m+n+(p===void 0?e:p)}function l(u,d,f,p){var h=""+d,m=""+f;if(!u&&h>m){var v=h;h=m,m=v}var y={v:h,w:m};return p&&(y.name=p),y}function c(u,d){return i(u,d.v,d.w,d.name)}return XK=r,XK}var KK,E6e;function Hzn(){return E6e||(E6e=1,KK="2.2.4"),KK}var JK,j6e;function Wzn(){return j6e||(j6e=1,JK={Graph:c1e(),version:Hzn()}),JK}var eJ,T6e;function Zzn(){if(T6e)return eJ;T6e=1;var e=c1e();eJ={write:t,read:s};function t(a){var i={options:{directed:a.isDirected(),multigraph:a.isMultigraph(),compound:a.isCompound()},nodes:n(a),edges:r(a)};return a.graph()!==void 0&&(i.value=structuredClone(a.graph())),i}function n(a){return a.nodes().map(function(i){var l=a.node(i),c=a.parent(i),u={v:i};return l!==void 0&&(u.value=l),c!==void 0&&(u.parent=c),u})}function r(a){return a.edges().map(function(i){var l=a.edge(i),c={v:i.v,w:i.w};return i.name!==void 0&&(c.name=i.name),l!==void 0&&(c.value=l),c})}function s(a){var i=new e(a.options).setGraph(a.value);return a.nodes.forEach(function(l){i.setNode(l.v,l.value),l.parent&&i.setParent(l.v,l.parent)}),a.edges.forEach(function(l){i.setEdge({v:l.v,w:l.w,name:l.name},l.value)}),i}return eJ}var tJ,N6e;function Gzn(){if(N6e)return tJ;N6e=1,tJ=e;function e(t){var n={},r=[],s;function a(i){Object.hasOwn(n,i)||(n[i]=!0,s.push(i),t.successors(i).forEach(a),t.predecessors(i).forEach(a))}return t.nodes().forEach(function(i){s=[],a(i),s.length&&r.push(s)}),r}return tJ}var nJ,I6e;function jxt(){if(I6e)return nJ;I6e=1;class e{_arr=[];_keyIndices={};size(){return this._arr.length}keys(){return this._arr.map(function(n){return n.key})}has(n){return Object.hasOwn(this._keyIndices,n)}priority(n){var r=this._keyIndices[n];if(r!==void 0)return this._arr[r].priority}min(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key}add(n,r){var s=this._keyIndices;if(n=String(n),!Object.hasOwn(s,n)){var a=this._arr,i=a.length;return s[n]=i,a.push({key:n,priority:r}),this._decrease(i),!0}return!1}removeMin(){this._swap(0,this._arr.length-1);var n=this._arr.pop();return delete this._keyIndices[n.key],this._heapify(0),n.key}decrease(n,r){var s=this._keyIndices[n];if(r>this._arr[s].priority)throw new Error("New priority is greater than current priority. Key: "+n+" Old: "+this._arr[s].priority+" New: "+r);this._arr[s].priority=r,this._decrease(s)}_heapify(n){var r=this._arr,s=2*n,a=s+1,i=n;s<r.length&&(i=r[s].priority<r[i].priority?s:i,a<r.length&&(i=r[a].priority<r[i].priority?a:i),i!==n&&(this._swap(n,i),this._heapify(i)))}_decrease(n){for(var r=this._arr,s=r[n].priority,a;n!==0&&(a=n>>1,!(r[a].priority<s));)this._swap(n,a),n=a}_swap(n,r){var s=this._arr,a=this._keyIndices,i=s[n],l=s[r];s[n]=l,s[r]=i,a[l.key]=n,a[i.key]=r}}return nJ=e,nJ}var rJ,A6e;function Txt(){if(A6e)return rJ;A6e=1;var e=jxt();rJ=n;var t=()=>1;function n(s,a,i,l){return r(s,String(a),i||t,l||function(c){return s.outEdges(c)})}function r(s,a,i,l){var c={},u=new e,d,f,p=function(h){var m=h.v!==d?h.v:h.w,v=c[m],y=i(h),b=f.distance+y;if(y<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+h+" Weight: "+y);b<v.distance&&(v.distance=b,v.predecessor=d,u.decrease(m,b))};for(s.nodes().forEach(function(h){var m=h===a?0:Number.POSITIVE_INFINITY;c[h]={distance:m},u.add(h,m)});u.size()>0&&(d=u.removeMin(),f=c[d],f.distance!==Number.POSITIVE_INFINITY);)l(d).forEach(p);return c}return rJ}var sJ,R6e;function Qzn(){if(R6e)return sJ;R6e=1;var e=Txt();sJ=t;function t(n,r,s){return n.nodes().reduce(function(a,i){return a[i]=e(n,i,r,s),a},{})}return sJ}var aJ,P6e;function Nxt(){if(P6e)return aJ;P6e=1,aJ=e;function e(t){var n=0,r=[],s={},a=[];function i(l){var c=s[l]={onStack:!0,lowlink:n,index:n++};if(r.push(l),t.successors(l).forEach(function(f){Object.hasOwn(s,f)?s[f].onStack&&(c.lowlink=Math.min(c.lowlink,s[f].index)):(i(f),c.lowlink=Math.min(c.lowlink,s[f].lowlink))}),c.lowlink===c.index){var u=[],d;do d=r.pop(),s[d].onStack=!1,u.push(d);while(l!==d);a.push(u)}}return t.nodes().forEach(function(l){Object.hasOwn(s,l)||i(l)}),a}return aJ}var iJ,$6e;function Yzn(){if($6e)return iJ;$6e=1;var e=Nxt();iJ=t;function t(n){return e(n).filter(function(r){return r.length>1||r.length===1&&n.hasEdge(r[0],r[0])})}return iJ}var oJ,M6e;function Xzn(){if(M6e)return oJ;M6e=1,oJ=t;var e=()=>1;function t(r,s,a){return n(r,s||e,a||function(i){return r.outEdges(i)})}function n(r,s,a){var i={},l=r.nodes();return l.forEach(function(c){i[c]={},i[c][c]={distance:0},l.forEach(function(u){c!==u&&(i[c][u]={distance:Number.POSITIVE_INFINITY})}),a(c).forEach(function(u){var d=u.v===c?u.w:u.v,f=s(u);i[c][d]={distance:f,predecessor:c}})}),l.forEach(function(c){var u=i[c];l.forEach(function(d){var f=i[d];l.forEach(function(p){var h=f[c],m=u[p],v=f[p],y=h.distance+m.distance;y<v.distance&&(v.distance=y,v.predecessor=m.predecessor)})})}),i}return oJ}var lJ,D6e;function Ixt(){if(D6e)return lJ;D6e=1;function e(n){var r={},s={},a=[];function i(l){if(Object.hasOwn(s,l))throw new t;Object.hasOwn(r,l)||(s[l]=!0,r[l]=!0,n.predecessors(l).forEach(i),delete s[l],a.push(l))}if(n.sinks().forEach(i),Object.keys(r).length!==n.nodeCount())throw new t;return a}class t extends Error{constructor(){super(...arguments)}}return lJ=e,e.CycleException=t,lJ}var cJ,L6e;function Kzn(){if(L6e)return cJ;L6e=1;var e=Ixt();cJ=t;function t(n){try{e(n)}catch(r){if(r instanceof e.CycleException)return!1;throw r}return!0}return cJ}var uJ,F6e;function Axt(){if(F6e)return uJ;F6e=1,uJ=e;function e(s,a,i){Array.isArray(a)||(a=[a]);var l=s.isDirected()?f=>s.successors(f):f=>s.neighbors(f),c=i==="post"?t:n,u=[],d={};return a.forEach(f=>{if(!s.hasNode(f))throw new Error("Graph does not have node: "+f);c(f,l,d,u)}),u}function t(s,a,i,l){for(var c=[[s,!1]];c.length>0;){var u=c.pop();u[1]?l.push(u[0]):Object.hasOwn(i,u[0])||(i[u[0]]=!0,c.push([u[0],!0]),r(a(u[0]),d=>c.push([d,!1])))}}function n(s,a,i,l){for(var c=[s];c.length>0;){var u=c.pop();Object.hasOwn(i,u)||(i[u]=!0,l.push(u),r(a(u),d=>c.push(d)))}}function r(s,a){for(var i=s.length;i--;)a(s[i],i,s);return s}return uJ}var dJ,z6e;function Jzn(){if(z6e)return dJ;z6e=1;var e=Axt();dJ=t;function t(n,r){return e(n,r,"post")}return dJ}var fJ,B6e;function e7n(){if(B6e)return fJ;B6e=1;var e=Axt();fJ=t;function t(n,r){return e(n,r,"pre")}return fJ}var pJ,U6e;function t7n(){if(U6e)return pJ;U6e=1;var e=c1e(),t=jxt();pJ=n;function n(r,s){var a=new e,i={},l=new t,c;function u(f){var p=f.v===c?f.w:f.v,h=l.priority(p);if(h!==void 0){var m=s(f);m<h&&(i[p]=c,l.decrease(p,m))}}if(r.nodeCount()===0)return a;r.nodes().forEach(function(f){l.add(f,Number.POSITIVE_INFINITY),a.setNode(f)}),l.decrease(r.nodes()[0],0);for(var d=!1;l.size()>0;){if(c=l.removeMin(),Object.hasOwn(i,c))a.setEdge(c,i[c]);else{if(d)throw new Error("Input graph is not connected: "+r);d=!0}r.nodeEdges(c).forEach(u)}return a}return pJ}var hJ,q6e;function n7n(){return q6e||(q6e=1,hJ={components:Gzn(),dijkstra:Txt(),dijkstraAll:Qzn(),findCycles:Yzn(),floydWarshall:Xzn(),isAcyclic:Kzn(),postorder:Jzn(),preorder:e7n(),prim:t7n(),tarjan:Nxt(),topsort:Ixt()}),hJ}var mJ,V6e;function Tg(){if(V6e)return mJ;V6e=1;var e=Wzn();return mJ={Graph:e.Graph,json:Zzn(),alg:n7n(),version:e.version},mJ}var gJ,H6e;function r7n(){if(H6e)return gJ;H6e=1;class e{constructor(){let s={};s._next=s._prev=s,this._sentinel=s}dequeue(){let s=this._sentinel,a=s._prev;if(a!==s)return t(a),a}enqueue(s){let a=this._sentinel;s._prev&&s._next&&t(s),s._next=a._next,a._next._prev=s,a._next=s,s._prev=a}toString(){let s=[],a=this._sentinel,i=a._prev;for(;i!==a;)s.push(JSON.stringify(i,n)),i=i._prev;return"["+s.join(", ")+"]"}}function t(r){r._prev._next=r._next,r._next._prev=r._prev,delete r._next,delete r._prev}function n(r,s){if(r!=="_next"&&r!=="_prev")return s}return gJ=e,gJ}var vJ,W6e;function s7n(){if(W6e)return vJ;W6e=1;let e=Tg().Graph,t=r7n();vJ=r;let n=()=>1;function r(u,d){if(u.nodeCount()<=1)return[];let f=i(u,d||n);return s(f.graph,f.buckets,f.zeroIdx).flatMap(h=>u.outEdges(h.v,h.w))}function s(u,d,f){let p=[],h=d[d.length-1],m=d[0],v;for(;u.nodeCount();){for(;v=m.dequeue();)a(u,d,f,v);for(;v=h.dequeue();)a(u,d,f,v);if(u.nodeCount()){for(let y=d.length-2;y>0;--y)if(v=d[y].dequeue(),v){p=p.concat(a(u,d,f,v,!0));break}}}return p}function a(u,d,f,p,h){let m=h?[]:void 0;return u.inEdges(p.v).forEach(v=>{let y=u.edge(v),b=u.node(v.v);h&&m.push({v:v.v,w:v.w}),b.out-=y,l(d,f,b)}),u.outEdges(p.v).forEach(v=>{let y=u.edge(v),b=v.w,S=u.node(b);S.in-=y,l(d,f,S)}),u.removeNode(p.v),m}function i(u,d){let f=new e,p=0,h=0;u.nodes().forEach(y=>{f.setNode(y,{v:y,in:0,out:0})}),u.edges().forEach(y=>{let b=f.edge(y.v,y.w)||0,S=d(y),w=b+S;f.setEdge(y.v,y.w,w),h=Math.max(h,f.node(y.v).out+=S),p=Math.max(p,f.node(y.w).in+=S)});let m=c(h+p+3).map(()=>new t),v=p+1;return f.nodes().forEach(y=>{l(m,v,f.node(y))}),{graph:f,buckets:m,zeroIdx:v}}function l(u,d,f){f.out?f.in?u[f.out-f.in+d].enqueue(f):u[u.length-1].enqueue(f):u[0].enqueue(f)}function c(u){const d=[];for(let f=0;f<u;f++)d.push(f);return d}return vJ}var yJ,Z6e;function Nl(){if(Z6e)return yJ;Z6e=1;let e=Tg().Graph;yJ={addBorderNode:d,addDummyNode:t,applyWithChunking:h,asNonCompoundGraph:r,buildLayerMatrix:l,intersectRect:i,mapValues:C,maxRank:m,normalizeRanks:c,notime:b,partition:v,pick:_,predecessorWeights:a,range:k,removeEmptyRanks:u,simplify:n,successorWeights:s,time:y,uniqueId:w,zipObject:E};function t(j,N,I,R){for(var P=R;j.hasNode(P);)P=w(R);return I.dummy=N,j.setNode(P,I),P}function n(j){let N=new e().setGraph(j.graph());return j.nodes().forEach(I=>N.setNode(I,j.node(I))),j.edges().forEach(I=>{let R=N.edge(I.v,I.w)||{weight:0,minlen:1},P=j.edge(I);N.setEdge(I.v,I.w,{weight:R.weight+P.weight,minlen:Math.max(R.minlen,P.minlen)})}),N}function r(j){let N=new e({multigraph:j.isMultigraph()}).setGraph(j.graph());return j.nodes().forEach(I=>{j.children(I).length||N.setNode(I,j.node(I))}),j.edges().forEach(I=>{N.setEdge(I,j.edge(I))}),N}function s(j){let N=j.nodes().map(I=>{let R={};return j.outEdges(I).forEach(P=>{R[P.w]=(R[P.w]||0)+j.edge(P).weight}),R});return E(j.nodes(),N)}function a(j){let N=j.nodes().map(I=>{let R={};return j.inEdges(I).forEach(P=>{R[P.v]=(R[P.v]||0)+j.edge(P).weight}),R});return E(j.nodes(),N)}function i(j,N){let I=j.x,R=j.y,P=N.x-I,L=N.y-R,M=j.width/2,q=j.height/2;if(!P&&!L)throw new Error("Not possible to find intersection inside of the rectangle");let H,F;return Math.abs(L)*M>Math.abs(P)*q?(L<0&&(q=-q),H=q*P/L,F=q):(P<0&&(M=-M),H=M,F=M*L/P),{x:I+H,y:R+F}}function l(j){let N=k(m(j)+1).map(()=>[]);return j.nodes().forEach(I=>{let R=j.node(I),P=R.rank;P!==void 0&&(N[P][R.order]=I)}),N}function c(j){let N=j.nodes().map(R=>{let P=j.node(R).rank;return P===void 0?Number.MAX_VALUE:P}),I=h(Math.min,N);j.nodes().forEach(R=>{let P=j.node(R);Object.hasOwn(P,"rank")&&(P.rank-=I)})}function u(j){let N=j.nodes().map(M=>j.node(M).rank),I=h(Math.min,N),R=[];j.nodes().forEach(M=>{let q=j.node(M).rank-I;R[q]||(R[q]=[]),R[q].push(M)});let P=0,L=j.graph().nodeRankFactor;Array.from(R).forEach((M,q)=>{M===void 0&&q%L!==0?--P:M!==void 0&&P&&M.forEach(H=>j.node(H).rank+=P)})}function d(j,N,I,R){let P={width:0,height:0};return arguments.length>=4&&(P.rank=I,P.order=R),t(j,"border",P,N)}function f(j,N=p){const I=[];for(let R=0;R<j.length;R+=N){const P=j.slice(R,R+N);I.push(P)}return I}const p=65535;function h(j,N){if(N.length>p){const I=f(N);return j.apply(null,I.map(R=>j.apply(null,R)))}else return j.apply(null,N)}function m(j){const I=j.nodes().map(R=>{let P=j.node(R).rank;return P===void 0?Number.MIN_VALUE:P});return h(Math.max,I)}function v(j,N){let I={lhs:[],rhs:[]};return j.forEach(R=>{N(R)?I.lhs.push(R):I.rhs.push(R)}),I}function y(j,N){let I=Date.now();try{return N()}finally{console.log(j+" time: "+(Date.now()-I)+"ms")}}function b(j,N){return N()}let S=0;function w(j){var N=++S;return j+(""+N)}function k(j,N,I=1){N==null&&(N=j,j=0);let R=L=>L<N;I<0&&(R=L=>N<L);const P=[];for(let L=j;R(L);L+=I)P.push(L);return P}function _(j,N){const I={};for(const R of N)j[R]!==void 0&&(I[R]=j[R]);return I}function C(j,N){let I=N;return typeof N=="string"&&(I=R=>R[N]),Object.entries(j).reduce((R,[P,L])=>(R[P]=I(L,P),R),{})}function E(j,N){return j.reduce((I,R,P)=>(I[R]=N[P],I),{})}return yJ}var bJ,G6e;function a7n(){if(G6e)return bJ;G6e=1;let e=s7n(),t=Nl().uniqueId;bJ={run:n,undo:s};function n(a){(a.graph().acyclicer==="greedy"?e(a,l(a)):r(a)).forEach(c=>{let u=a.edge(c);a.removeEdge(c),u.forwardName=c.name,u.reversed=!0,a.setEdge(c.w,c.v,u,t("rev"))});function l(c){return u=>c.edge(u).weight}}function r(a){let i=[],l={},c={};function u(d){Object.hasOwn(c,d)||(c[d]=!0,l[d]=!0,a.outEdges(d).forEach(f=>{Object.hasOwn(l,f.w)?i.push(f):u(f.w)}),delete l[d])}return a.nodes().forEach(u),i}function s(a){a.edges().forEach(i=>{let l=a.edge(i);if(l.reversed){a.removeEdge(i);let c=l.forwardName;delete l.reversed,delete l.forwardName,a.setEdge(i.w,i.v,l,c)}})}return bJ}var xJ,Q6e;function i7n(){if(Q6e)return xJ;Q6e=1;let e=Nl();xJ={run:t,undo:r};function t(s){s.graph().dummyChains=[],s.edges().forEach(a=>n(s,a))}function n(s,a){let i=a.v,l=s.node(i).rank,c=a.w,u=s.node(c).rank,d=a.name,f=s.edge(a),p=f.labelRank;if(u===l+1)return;s.removeEdge(a);let h,m,v;for(v=0,++l;l<u;++v,++l)f.points=[],m={width:0,height:0,edgeLabel:f,edgeObj:a,rank:l},h=e.addDummyNode(s,"edge",m,"_d"),l===p&&(m.width=f.width,m.height=f.height,m.dummy="edge-label",m.labelpos=f.labelpos),s.setEdge(i,h,{weight:f.weight},d),v===0&&s.graph().dummyChains.push(h),i=h;s.setEdge(i,c,{weight:f.weight},d)}function r(s){s.graph().dummyChains.forEach(a=>{let i=s.node(a),l=i.edgeLabel,c;for(s.setEdge(i.edgeObj,l);i.dummy;)c=s.successors(a)[0],s.removeNode(a),l.points.push({x:i.x,y:i.y}),i.dummy==="edge-label"&&(l.x=i.x,l.y=i.y,l.width=i.width,l.height=i.height),a=c,i=s.node(a)})}return xJ}var wJ,Y6e;function T7(){if(Y6e)return wJ;Y6e=1;const{applyWithChunking:e}=Nl();wJ={longestPath:t,slack:n};function t(r){var s={};function a(i){var l=r.node(i);if(Object.hasOwn(s,i))return l.rank;s[i]=!0;let c=r.outEdges(i).map(d=>d==null?Number.POSITIVE_INFINITY:a(d.w)-r.edge(d).minlen);var u=e(Math.min,c);return u===Number.POSITIVE_INFINITY&&(u=0),l.rank=u}r.sources().forEach(a)}function n(r,s){return r.node(s.w).rank-r.node(s.v).rank-r.edge(s).minlen}return wJ}var SJ,X6e;function Rxt(){if(X6e)return SJ;X6e=1;var e=Tg().Graph,t=T7().slack;SJ=n;function n(i){var l=new e({directed:!1}),c=i.nodes()[0],u=i.nodeCount();l.setNode(c,{});for(var d,f;r(l,i)<u;)d=s(l,i),f=l.hasNode(d.v)?t(i,d):-t(i,d),a(l,i,f);return l}function r(i,l){function c(u){l.nodeEdges(u).forEach(d=>{var f=d.v,p=u===f?d.w:f;!i.hasNode(p)&&!t(l,d)&&(i.setNode(p,{}),i.setEdge(u,p,{}),c(p))})}return i.nodes().forEach(c),i.nodeCount()}function s(i,l){return l.edges().reduce((u,d)=>{let f=Number.POSITIVE_INFINITY;return i.hasNode(d.v)!==i.hasNode(d.w)&&(f=t(l,d)),f<u[0]?[f,d]:u},[Number.POSITIVE_INFINITY,null])[1]}function a(i,l,c){i.nodes().forEach(u=>l.node(u).rank+=c)}return SJ}var kJ,K6e;function o7n(){if(K6e)return kJ;K6e=1;var e=Rxt(),t=T7().slack,n=T7().longestPath,r=Tg().alg.preorder,s=Tg().alg.postorder,a=Nl().simplify;kJ=i,i.initLowLimValues=d,i.initCutValues=l,i.calcCutValue=u,i.leaveEdge=p,i.enterEdge=h,i.exchangeEdges=m;function i(S){S=a(S),n(S);var w=e(S);d(w),l(w,S);for(var k,_;k=p(w);)_=h(w,S,k),m(w,S,k,_)}function l(S,w){var k=s(S,S.nodes());k=k.slice(0,k.length-1),k.forEach(_=>c(S,w,_))}function c(S,w,k){var _=S.node(k),C=_.parent;S.edge(k,C).cutvalue=u(S,w,k)}function u(S,w,k){var _=S.node(k),C=_.parent,E=!0,j=w.edge(k,C),N=0;return j||(E=!1,j=w.edge(C,k)),N=j.weight,w.nodeEdges(k).forEach(I=>{var R=I.v===k,P=R?I.w:I.v;if(P!==C){var L=R===E,M=w.edge(I).weight;if(N+=L?M:-M,y(S,k,P)){var q=S.edge(k,P).cutvalue;N+=L?-q:q}}}),N}function d(S,w){arguments.length<2&&(w=S.nodes()[0]),f(S,{},1,w)}function f(S,w,k,_,C){var E=k,j=S.node(_);return w[_]=!0,S.neighbors(_).forEach(N=>{Object.hasOwn(w,N)||(k=f(S,w,k,N,_))}),j.low=E,j.lim=k++,C?j.parent=C:delete j.parent,k}function p(S){return S.edges().find(w=>S.edge(w).cutvalue<0)}function h(S,w,k){var _=k.v,C=k.w;w.hasEdge(_,C)||(_=k.w,C=k.v);var E=S.node(_),j=S.node(C),N=E,I=!1;E.lim>j.lim&&(N=j,I=!0);var R=w.edges().filter(P=>I===b(S,S.node(P.v),N)&&I!==b(S,S.node(P.w),N));return R.reduce((P,L)=>t(w,L)<t(w,P)?L:P)}function m(S,w,k,_){var C=k.v,E=k.w;S.removeEdge(C,E),S.setEdge(_.v,_.w,{}),d(S),l(S,w),v(S,w)}function v(S,w){var k=S.nodes().find(C=>!w.node(C).parent),_=r(S,k);_=_.slice(1),_.forEach(C=>{var E=S.node(C).parent,j=w.edge(C,E),N=!1;j||(j=w.edge(E,C),N=!0),w.node(C).rank=w.node(E).rank+(N?j.minlen:-j.minlen)})}function y(S,w,k){return S.hasEdge(w,k)}function b(S,w,k){return k.low<=w.lim&&w.lim<=k.lim}return kJ}var OJ,J6e;function l7n(){if(J6e)return OJ;J6e=1;var e=T7(),t=e.longestPath,n=Rxt(),r=o7n();OJ=s;function s(c){var u=c.graph().ranker;if(u instanceof Function)return u(c);switch(c.graph().ranker){case"network-simplex":l(c);break;case"tight-tree":i(c);break;case"longest-path":a(c);break;case"none":break;default:l(c)}}var a=t;function i(c){t(c),n(c)}function l(c){r(c)}return OJ}var _J,e9e;function c7n(){if(e9e)return _J;e9e=1,_J=e;function e(r){let s=n(r);r.graph().dummyChains.forEach(a=>{let i=r.node(a),l=i.edgeObj,c=t(r,s,l.v,l.w),u=c.path,d=c.lca,f=0,p=u[f],h=!0;for(;a!==l.w;){if(i=r.node(a),h){for(;(p=u[f])!==d&&r.node(p).maxRank<i.rank;)f++;p===d&&(h=!1)}if(!h){for(;f<u.length-1&&r.node(p=u[f+1]).minRank<=i.rank;)f++;p=u[f]}r.setParent(a,p),a=r.successors(a)[0]}})}function t(r,s,a,i){let l=[],c=[],u=Math.min(s[a].low,s[i].low),d=Math.max(s[a].lim,s[i].lim),f,p;f=a;do f=r.parent(f),l.push(f);while(f&&(s[f].low>u||d>s[f].lim));for(p=f,f=i;(f=r.parent(f))!==p;)c.push(f);return{path:l.concat(c.reverse()),lca:p}}function n(r){let s={},a=0;function i(l){let c=a;r.children(l).forEach(i),s[l]={low:c,lim:a++}}return r.children().forEach(i),s}return _J}var CJ,t9e;function u7n(){if(t9e)return CJ;t9e=1;let e=Nl();CJ={run:t,cleanup:a};function t(i){let l=e.addDummyNode(i,"root",{},"_root"),c=r(i),u=Object.values(c),d=e.applyWithChunking(Math.max,u)-1,f=2*d+1;i.graph().nestingRoot=l,i.edges().forEach(h=>i.edge(h).minlen*=f);let p=s(i)+1;i.children().forEach(h=>n(i,l,f,p,d,c,h)),i.graph().nodeRankFactor=f}function n(i,l,c,u,d,f,p){let h=i.children(p);if(!h.length){p!==l&&i.setEdge(l,p,{weight:0,minlen:c});return}let m=e.addBorderNode(i,"_bt"),v=e.addBorderNode(i,"_bb"),y=i.node(p);i.setParent(m,p),y.borderTop=m,i.setParent(v,p),y.borderBottom=v,h.forEach(b=>{n(i,l,c,u,d,f,b);let S=i.node(b),w=S.borderTop?S.borderTop:b,k=S.borderBottom?S.borderBottom:b,_=S.borderTop?u:2*u,C=w!==k?1:d-f[p]+1;i.setEdge(m,w,{weight:_,minlen:C,nestingEdge:!0}),i.setEdge(k,v,{weight:_,minlen:C,nestingEdge:!0})}),i.parent(p)||i.setEdge(l,m,{weight:0,minlen:d+f[p]})}function r(i){var l={};function c(u,d){var f=i.children(u);f&&f.length&&f.forEach(p=>c(p,d+1)),l[u]=d}return i.children().forEach(u=>c(u,1)),l}function s(i){return i.edges().reduce((l,c)=>l+i.edge(c).weight,0)}function a(i){var l=i.graph();i.removeNode(l.nestingRoot),delete l.nestingRoot,i.edges().forEach(c=>{var u=i.edge(c);u.nestingEdge&&i.removeEdge(c)})}return CJ}var EJ,n9e;function d7n(){if(n9e)return EJ;n9e=1;let e=Nl();EJ=t;function t(r){function s(a){let i=r.children(a),l=r.node(a);if(i.length&&i.forEach(s),Object.hasOwn(l,"minRank")){l.borderLeft=[],l.borderRight=[];for(let c=l.minRank,u=l.maxRank+1;c<u;++c)n(r,"borderLeft","_bl",a,l,c),n(r,"borderRight","_br",a,l,c)}}r.children().forEach(s)}function n(r,s,a,i,l,c){let u={width:0,height:0,rank:c,borderType:s},d=l[s][c-1],f=e.addDummyNode(r,"border",u,a);l[s][c]=f,r.setParent(f,i),d&&r.setEdge(d,f,{weight:1})}return EJ}var jJ,r9e;function f7n(){if(r9e)return jJ;r9e=1,jJ={adjust:e,undo:t};function e(c){let u=c.graph().rankdir.toLowerCase();(u==="lr"||u==="rl")&&n(c)}function t(c){let u=c.graph().rankdir.toLowerCase();(u==="bt"||u==="rl")&&s(c),(u==="lr"||u==="rl")&&(i(c),n(c))}function n(c){c.nodes().forEach(u=>r(c.node(u))),c.edges().forEach(u=>r(c.edge(u)))}function r(c){let u=c.width;c.width=c.height,c.height=u}function s(c){c.nodes().forEach(u=>a(c.node(u))),c.edges().forEach(u=>{let d=c.edge(u);d.points.forEach(a),Object.hasOwn(d,"y")&&a(d)})}function a(c){c.y=-c.y}function i(c){c.nodes().forEach(u=>l(c.node(u))),c.edges().forEach(u=>{let d=c.edge(u);d.points.forEach(l),Object.hasOwn(d,"x")&&l(d)})}function l(c){let u=c.x;c.x=c.y,c.y=u}return jJ}var TJ,s9e;function p7n(){if(s9e)return TJ;s9e=1;let e=Nl();TJ=t;function t(n){let r={},s=n.nodes().filter(d=>!n.children(d).length),a=s.map(d=>n.node(d).rank),i=e.applyWithChunking(Math.max,a),l=e.range(i+1).map(()=>[]);function c(d){if(r[d])return;r[d]=!0;let f=n.node(d);l[f.rank].push(d),n.successors(d).forEach(c)}return s.sort((d,f)=>n.node(d).rank-n.node(f).rank).forEach(c),l}return TJ}var NJ,a9e;function h7n(){if(a9e)return NJ;a9e=1;let e=Nl().zipObject;NJ=t;function t(r,s){let a=0;for(let i=1;i<s.length;++i)a+=n(r,s[i-1],s[i]);return a}function n(r,s,a){let i=e(a,a.map((p,h)=>h)),l=s.flatMap(p=>r.outEdges(p).map(h=>({pos:i[h.w],weight:r.edge(h).weight})).sort((h,m)=>h.pos-m.pos)),c=1;for(;c<a.length;)c<<=1;let u=2*c-1;c-=1;let d=new Array(u).fill(0),f=0;return l.forEach(p=>{let h=p.pos+c;d[h]+=p.weight;let m=0;for(;h>0;)h%2&&(m+=d[h+1]),h=h-1>>1,d[h]+=p.weight;f+=p.weight*m}),f}return NJ}var IJ,i9e;function m7n(){if(i9e)return IJ;i9e=1,IJ=e;function e(t,n=[]){return n.map(r=>{let s=t.inEdges(r);if(s.length){let a=s.reduce((i,l)=>{let c=t.edge(l),u=t.node(l.v);return{sum:i.sum+c.weight*u.order,weight:i.weight+c.weight}},{sum:0,weight:0});return{v:r,barycenter:a.sum/a.weight,weight:a.weight}}else return{v:r}})}return IJ}var AJ,o9e;function g7n(){if(o9e)return AJ;o9e=1;let e=Nl();AJ=t;function t(s,a){let i={};s.forEach((c,u)=>{let d=i[c.v]={indegree:0,in:[],out:[],vs:[c.v],i:u};c.barycenter!==void 0&&(d.barycenter=c.barycenter,d.weight=c.weight)}),a.edges().forEach(c=>{let u=i[c.v],d=i[c.w];u!==void 0&&d!==void 0&&(d.indegree++,u.out.push(i[c.w]))});let l=Object.values(i).filter(c=>!c.indegree);return n(l)}function n(s){let a=[];function i(c){return u=>{u.merged||(u.barycenter===void 0||c.barycenter===void 0||u.barycenter>=c.barycenter)&&r(c,u)}}function l(c){return u=>{u.in.push(c),--u.indegree===0&&s.push(u)}}for(;s.length;){let c=s.pop();a.push(c),c.in.reverse().forEach(i(c)),c.out.forEach(l(c))}return a.filter(c=>!c.merged).map(c=>e.pick(c,["vs","i","barycenter","weight"]))}function r(s,a){let i=0,l=0;s.weight&&(i+=s.barycenter*s.weight,l+=s.weight),a.weight&&(i+=a.barycenter*a.weight,l+=a.weight),s.vs=a.vs.concat(s.vs),s.barycenter=i/l,s.weight=l,s.i=Math.min(a.i,s.i),a.merged=!0}return AJ}var RJ,l9e;function v7n(){if(l9e)return RJ;l9e=1;let e=Nl();RJ=t;function t(s,a){let i=e.partition(s,m=>Object.hasOwn(m,"barycenter")),l=i.lhs,c=i.rhs.sort((m,v)=>v.i-m.i),u=[],d=0,f=0,p=0;l.sort(r(!!a)),p=n(u,c,p),l.forEach(m=>{p+=m.vs.length,u.push(m.vs),d+=m.barycenter*m.weight,f+=m.weight,p=n(u,c,p)});let h={vs:u.flat(!0)};return f&&(h.barycenter=d/f,h.weight=f),h}function n(s,a,i){let l;for(;a.length&&(l=a[a.length-1]).i<=i;)a.pop(),s.push(l.vs),i++;return i}function r(s){return(a,i)=>a.barycenter<i.barycenter?-1:a.barycenter>i.barycenter?1:s?i.i-a.i:a.i-i.i}return RJ}var PJ,c9e;function y7n(){if(c9e)return PJ;c9e=1;let e=m7n(),t=g7n(),n=v7n();PJ=r;function r(i,l,c,u){let d=i.children(l),f=i.node(l),p=f?f.borderLeft:void 0,h=f?f.borderRight:void 0,m={};p&&(d=d.filter(S=>S!==p&&S!==h));let v=e(i,d);v.forEach(S=>{if(i.children(S.v).length){let w=r(i,S.v,c,u);m[S.v]=w,Object.hasOwn(w,"barycenter")&&a(S,w)}});let y=t(v,c);s(y,m);let b=n(y,u);if(p&&(b.vs=[p,b.vs,h].flat(!0),i.predecessors(p).length)){let S=i.node(i.predecessors(p)[0]),w=i.node(i.predecessors(h)[0]);Object.hasOwn(b,"barycenter")||(b.barycenter=0,b.weight=0),b.barycenter=(b.barycenter*b.weight+S.order+w.order)/(b.weight+2),b.weight+=2}return b}function s(i,l){i.forEach(c=>{c.vs=c.vs.flatMap(u=>l[u]?l[u].vs:u)})}function a(i,l){i.barycenter!==void 0?(i.barycenter=(i.barycenter*i.weight+l.barycenter*l.weight)/(i.weight+l.weight),i.weight+=l.weight):(i.barycenter=l.barycenter,i.weight=l.weight)}return PJ}var $J,u9e;function b7n(){if(u9e)return $J;u9e=1;let e=Tg().Graph,t=Nl();$J=n;function n(s,a,i,l){l||(l=s.nodes());let c=r(s),u=new e({compound:!0}).setGraph({root:c}).setDefaultNodeLabel(d=>s.node(d));return l.forEach(d=>{let f=s.node(d),p=s.parent(d);(f.rank===a||f.minRank<=a&&a<=f.maxRank)&&(u.setNode(d),u.setParent(d,p||c),s[i](d).forEach(h=>{let m=h.v===d?h.w:h.v,v=u.edge(m,d),y=v!==void 0?v.weight:0;u.setEdge(m,d,{weight:s.edge(h).weight+y})}),Object.hasOwn(f,"minRank")&&u.setNode(d,{borderLeft:f.borderLeft[a],borderRight:f.borderRight[a]}))}),u}function r(s){for(var a;s.hasNode(a=t.uniqueId("_root")););return a}return $J}var MJ,d9e;function x7n(){if(d9e)return MJ;d9e=1,MJ=e;function e(t,n,r){let s={},a;r.forEach(i=>{let l=t.parent(i),c,u;for(;l;){if(c=t.parent(l),c?(u=s[c],s[c]=l):(u=a,a=l),u&&u!==l){n.setEdge(u,l);return}l=c}})}return MJ}var DJ,f9e;function w7n(){if(f9e)return DJ;f9e=1;let e=p7n(),t=h7n(),n=y7n(),r=b7n(),s=x7n(),a=Tg().Graph,i=Nl();DJ=l;function l(f,p){if(p&&typeof p.customOrder=="function"){p.customOrder(f,l);return}let h=i.maxRank(f),m=c(f,i.range(1,h+1),"inEdges"),v=c(f,i.range(h-1,-1,-1),"outEdges"),y=e(f);if(d(f,y),p&&p.disableOptimalOrderHeuristic)return;let b=Number.POSITIVE_INFINITY,S;for(let w=0,k=0;k<4;++w,++k){u(w%2?m:v,w%4>=2),y=i.buildLayerMatrix(f);let _=t(f,y);_<b&&(k=0,S=Object.assign({},y),b=_)}d(f,S)}function c(f,p,h){const m=new Map,v=(y,b)=>{m.has(y)||m.set(y,[]),m.get(y).push(b)};for(const y of f.nodes()){const b=f.node(y);if(typeof b.rank=="number"&&v(b.rank,y),typeof b.minRank=="number"&&typeof b.maxRank=="number")for(let S=b.minRank;S<=b.maxRank;S++)S!==b.rank&&v(S,y)}return p.map(function(y){return r(f,y,h,m.get(y)||[])})}function u(f,p){let h=new a;f.forEach(function(m){let v=m.graph().root,y=n(m,v,h,p);y.vs.forEach((b,S)=>m.node(b).order=S),s(m,h,y.vs)})}function d(f,p){Object.values(p).forEach(h=>h.forEach((m,v)=>f.node(m).order=v))}return DJ}var LJ,p9e;function S7n(){if(p9e)return LJ;p9e=1;let e=Tg().Graph,t=Nl();LJ={positionX:h,findType1Conflicts:n,findType2Conflicts:r,addConflict:a,hasConflict:i,verticalAlignment:l,horizontalCompaction:c,alignCoordinates:f,findSmallestWidthAlignment:d,balance:p};function n(y,b){let S={};function w(k,_){let C=0,E=0,j=k.length,N=_[_.length-1];return _.forEach((I,R)=>{let P=s(y,I),L=P?y.node(P).order:j;(P||I===N)&&(_.slice(E,R+1).forEach(M=>{y.predecessors(M).forEach(q=>{let H=y.node(q),F=H.order;(F<C||L<F)&&!(H.dummy&&y.node(M).dummy)&&a(S,q,M)})}),E=R+1,C=L)}),_}return b.length&&b.reduce(w),S}function r(y,b){let S={};function w(_,C,E,j,N){let I;t.range(C,E).forEach(R=>{I=_[R],y.node(I).dummy&&y.predecessors(I).forEach(P=>{let L=y.node(P);L.dummy&&(L.order<j||L.order>N)&&a(S,P,I)})})}function k(_,C){let E=-1,j,N=0;return C.forEach((I,R)=>{if(y.node(I).dummy==="border"){let P=y.predecessors(I);P.length&&(j=y.node(P[0]).order,w(C,N,R,E,j),N=R,E=j)}w(C,N,C.length,j,_.length)}),C}return b.length&&b.reduce(k),S}function s(y,b){if(y.node(b).dummy)return y.predecessors(b).find(S=>y.node(S).dummy)}function a(y,b,S){if(b>S){let k=b;b=S,S=k}let w=y[b];w||(y[b]=w={}),w[S]=!0}function i(y,b,S){if(b>S){let w=b;b=S,S=w}return!!y[b]&&Object.hasOwn(y[b],S)}function l(y,b,S,w){let k={},_={},C={};return b.forEach(E=>{E.forEach((j,N)=>{k[j]=j,_[j]=j,C[j]=N})}),b.forEach(E=>{let j=-1;E.forEach(N=>{let I=w(N);if(I.length){I=I.sort((P,L)=>C[P]-C[L]);let R=(I.length-1)/2;for(let P=Math.floor(R),L=Math.ceil(R);P<=L;++P){let M=I[P];_[N]===N&&j<C[M]&&!i(S,N,M)&&(_[M]=N,_[N]=k[N]=k[M],j=C[M])}}})}),{root:k,align:_}}function c(y,b,S,w,k){let _={},C=u(y,b,S,k),E=k?"borderLeft":"borderRight";function j(R,P){let L=C.nodes(),M=L.pop(),q={};for(;M;)q[M]?R(M):(q[M]=!0,L.push(M),L=L.concat(P(M))),M=L.pop()}function N(R){_[R]=C.inEdges(R).reduce((P,L)=>Math.max(P,_[L.v]+C.edge(L)),0)}function I(R){let P=C.outEdges(R).reduce((M,q)=>Math.min(M,_[q.w]-C.edge(q)),Number.POSITIVE_INFINITY),L=y.node(R);P!==Number.POSITIVE_INFINITY&&L.borderType!==E&&(_[R]=Math.max(_[R],P))}return j(N,C.predecessors.bind(C)),j(I,C.successors.bind(C)),Object.keys(w).forEach(R=>_[R]=_[S[R]]),_}function u(y,b,S,w){let k=new e,_=y.graph(),C=m(_.nodesep,_.edgesep,w);return b.forEach(E=>{let j;E.forEach(N=>{let I=S[N];if(k.setNode(I),j){var R=S[j],P=k.edge(R,I);k.setEdge(R,I,Math.max(C(y,N,j),P||0))}j=N})}),k}function d(y,b){return Object.values(b).reduce((S,w)=>{let k=Number.NEGATIVE_INFINITY,_=Number.POSITIVE_INFINITY;Object.entries(w).forEach(([E,j])=>{let N=v(y,E)/2;k=Math.max(j+N,k),_=Math.min(j-N,_)});const C=k-_;return C<S[0]&&(S=[C,w]),S},[Number.POSITIVE_INFINITY,null])[1]}function f(y,b){let S=Object.values(b),w=t.applyWithChunking(Math.min,S),k=t.applyWithChunking(Math.max,S);["u","d"].forEach(_=>{["l","r"].forEach(C=>{let E=_+C,j=y[E];if(j===b)return;let N=Object.values(j),I=w-t.applyWithChunking(Math.min,N);C!=="l"&&(I=k-t.applyWithChunking(Math.max,N)),I&&(y[E]=t.mapValues(j,R=>R+I))})})}function p(y,b){return t.mapValues(y.ul,(S,w)=>{if(b)return y[b.toLowerCase()][w];{let k=Object.values(y).map(_=>_[w]).sort((_,C)=>_-C);return(k[1]+k[2])/2}})}function h(y){let b=t.buildLayerMatrix(y),S=Object.assign(n(y,b),r(y,b)),w={},k;["u","d"].forEach(C=>{k=C==="u"?b:Object.values(b).reverse(),["l","r"].forEach(E=>{E==="r"&&(k=k.map(R=>Object.values(R).reverse()));let j=(C==="u"?y.predecessors:y.successors).bind(y),N=l(y,k,S,j),I=c(y,k,N.root,N.align,E==="r");E==="r"&&(I=t.mapValues(I,R=>-R)),w[C+E]=I})});let _=d(y,w);return f(w,_),p(w,y.graph().align)}function m(y,b,S){return(w,k,_)=>{let C=w.node(k),E=w.node(_),j=0,N;if(j+=C.width/2,Object.hasOwn(C,"labelpos"))switch(C.labelpos.toLowerCase()){case"l":N=-C.width/2;break;case"r":N=C.width/2;break}if(N&&(j+=S?N:-N),N=0,j+=(C.dummy?b:y)/2,j+=(E.dummy?b:y)/2,j+=E.width/2,Object.hasOwn(E,"labelpos"))switch(E.labelpos.toLowerCase()){case"l":N=E.width/2;break;case"r":N=-E.width/2;break}return N&&(j+=S?N:-N),N=0,j}}function v(y,b){return y.node(b).width}return LJ}var FJ,h9e;function k7n(){if(h9e)return FJ;h9e=1;let e=Nl(),t=S7n().positionX;FJ=n;function n(s){s=e.asNonCompoundGraph(s),r(s),Object.entries(t(s)).forEach(([a,i])=>s.node(a).x=i)}function r(s){let a=e.buildLayerMatrix(s),i=s.graph().ranksep,l=0;a.forEach(c=>{const u=c.reduce((d,f)=>{const p=s.node(f).height;return d>p?d:p},0);c.forEach(d=>s.node(d).y=l+u/2),l+=u+i})}return FJ}var zJ,m9e;function O7n(){if(m9e)return zJ;m9e=1;let e=a7n(),t=i7n(),n=l7n(),r=Nl().normalizeRanks,s=c7n(),a=Nl().removeEmptyRanks,i=u7n(),l=d7n(),c=f7n(),u=w7n(),d=k7n(),f=Nl(),p=Tg().Graph;zJ=h;function h($,U){let Z=U&&U.debugTiming?f.time:f.notime;Z("layout",()=>{let X=Z(" buildLayoutGraph",()=>j($));Z(" runLayout",()=>m(X,Z,U)),Z(" updateInputGraph",()=>v($,X))})}function m($,U,Z){U(" makeSpaceForEdgeLabels",()=>N($)),U(" removeSelfEdges",()=>z($)),U(" acyclic",()=>e.run($)),U(" nestingGraph.run",()=>i.run($)),U(" rank",()=>n(f.asNonCompoundGraph($))),U(" injectEdgeLabelProxies",()=>I($)),U(" removeEmptyRanks",()=>a($)),U(" nestingGraph.cleanup",()=>i.cleanup($)),U(" normalizeRanks",()=>r($)),U(" assignRankMinMax",()=>R($)),U(" removeEdgeLabelProxies",()=>P($)),U(" normalize.run",()=>t.run($)),U(" parentDummyChains",()=>s($)),U(" addBorderSegments",()=>l($)),U(" order",()=>u($,Z)),U(" insertSelfEdges",()=>B($)),U(" adjustCoordinateSystem",()=>c.adjust($)),U(" position",()=>d($)),U(" positionSelfEdges",()=>D($)),U(" removeBorderNodes",()=>F($)),U(" normalize.undo",()=>t.undo($)),U(" fixupEdgeLabelCoords",()=>q($)),U(" undoCoordinateSystem",()=>c.undo($)),U(" translateGraph",()=>L($)),U(" assignNodeIntersects",()=>M($)),U(" reversePoints",()=>H($)),U(" acyclic.undo",()=>e.undo($))}function v($,U){$.nodes().forEach(Z=>{let X=$.node(Z),te=U.node(Z);X&&(X.x=te.x,X.y=te.y,X.rank=te.rank,U.children(Z).length&&(X.width=te.width,X.height=te.height))}),$.edges().forEach(Z=>{let X=$.edge(Z),te=U.edge(Z);X.points=te.points,Object.hasOwn(te,"x")&&(X.x=te.x,X.y=te.y)}),$.graph().width=U.graph().width,$.graph().height=U.graph().height}let y=["nodesep","edgesep","ranksep","marginx","marginy"],b={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb"},S=["acyclicer","ranker","rankdir","align"],w=["width","height","rank"],k={width:0,height:0},_=["minlen","weight","width","height","labeloffset"],C={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},E=["labelpos"];function j($){let U=new p({multigraph:!0,compound:!0}),Z=V($.graph());return U.setGraph(Object.assign({},b,Q(Z,y),f.pick(Z,S))),$.nodes().forEach(X=>{let te=V($.node(X));const J=Q(te,w);Object.keys(k).forEach(ee=>{J[ee]===void 0&&(J[ee]=k[ee])}),U.setNode(X,J),U.setParent(X,$.parent(X))}),$.edges().forEach(X=>{let te=V($.edge(X));U.setEdge(X,Object.assign({},C,Q(te,_),f.pick(te,E)))}),U}function N($){let U=$.graph();U.ranksep/=2,$.edges().forEach(Z=>{let X=$.edge(Z);X.minlen*=2,X.labelpos.toLowerCase()!=="c"&&(U.rankdir==="TB"||U.rankdir==="BT"?X.width+=X.labeloffset:X.height+=X.labeloffset)})}function I($){$.edges().forEach(U=>{let Z=$.edge(U);if(Z.width&&Z.height){let X=$.node(U.v),J={rank:($.node(U.w).rank-X.rank)/2+X.rank,e:U};f.addDummyNode($,"edge-proxy",J,"_ep")}})}function R($){let U=0;$.nodes().forEach(Z=>{let X=$.node(Z);X.borderTop&&(X.minRank=$.node(X.borderTop).rank,X.maxRank=$.node(X.borderBottom).rank,U=Math.max(U,X.maxRank))}),$.graph().maxRank=U}function P($){$.nodes().forEach(U=>{let Z=$.node(U);Z.dummy==="edge-proxy"&&($.edge(Z.e).labelRank=Z.rank,$.removeNode(U))})}function L($){let U=Number.POSITIVE_INFINITY,Z=0,X=Number.POSITIVE_INFINITY,te=0,J=$.graph(),ee=J.marginx||0,ae=J.marginy||0;function ce(Y){let ne=Y.x,ue=Y.y,pe=Y.width,le=Y.height;U=Math.min(U,ne-pe/2),Z=Math.max(Z,ne+pe/2),X=Math.min(X,ue-le/2),te=Math.max(te,ue+le/2)}$.nodes().forEach(Y=>ce($.node(Y))),$.edges().forEach(Y=>{let ne=$.edge(Y);Object.hasOwn(ne,"x")&&ce(ne)}),U-=ee,X-=ae,$.nodes().forEach(Y=>{let ne=$.node(Y);ne.x-=U,ne.y-=X}),$.edges().forEach(Y=>{let ne=$.edge(Y);ne.points.forEach(ue=>{ue.x-=U,ue.y-=X}),Object.hasOwn(ne,"x")&&(ne.x-=U),Object.hasOwn(ne,"y")&&(ne.y-=X)}),J.width=Z-U+ee,J.height=te-X+ae}function M($){$.edges().forEach(U=>{let Z=$.edge(U),X=$.node(U.v),te=$.node(U.w),J,ee;Z.points?(J=Z.points[0],ee=Z.points[Z.points.length-1]):(Z.points=[],J=te,ee=X),Z.points.unshift(f.intersectRect(X,J)),Z.points.push(f.intersectRect(te,ee))})}function q($){$.edges().forEach(U=>{let Z=$.edge(U);if(Object.hasOwn(Z,"x"))switch((Z.labelpos==="l"||Z.labelpos==="r")&&(Z.width-=Z.labeloffset),Z.labelpos){case"l":Z.x-=Z.width/2+Z.labeloffset;break;case"r":Z.x+=Z.width/2+Z.labeloffset;break}})}function H($){$.edges().forEach(U=>{let Z=$.edge(U);Z.reversed&&Z.points.reverse()})}function F($){$.nodes().forEach(U=>{if($.children(U).length){let Z=$.node(U),X=$.node(Z.borderTop),te=$.node(Z.borderBottom),J=$.node(Z.borderLeft[Z.borderLeft.length-1]),ee=$.node(Z.borderRight[Z.borderRight.length-1]);Z.width=Math.abs(ee.x-J.x),Z.height=Math.abs(te.y-X.y),Z.x=J.x+Z.width/2,Z.y=X.y+Z.height/2}}),$.nodes().forEach(U=>{$.node(U).dummy==="border"&&$.removeNode(U)})}function z($){$.edges().forEach(U=>{if(U.v===U.w){var Z=$.node(U.v);Z.selfEdges||(Z.selfEdges=[]),Z.selfEdges.push({e:U,label:$.edge(U)}),$.removeEdge(U)}})}function B($){var U=f.buildLayerMatrix($);U.forEach(Z=>{var X=0;Z.forEach((te,J)=>{var ee=$.node(te);ee.order=J+X,(ee.selfEdges||[]).forEach(ae=>{f.addDummyNode($,"selfedge",{width:ae.label.width,height:ae.label.height,rank:ee.rank,order:J+ ++X,e:ae.e,label:ae.label},"_se")}),delete ee.selfEdges})})}function D($){$.nodes().forEach(U=>{var Z=$.node(U);if(Z.dummy==="selfedge"){var X=$.node(Z.e.v),te=X.x+X.width/2,J=X.y,ee=Z.x-te,ae=X.height/2;$.setEdge(Z.e,Z.label),$.removeNode(U),Z.label.points=[{x:te+2*ee/3,y:J-ae},{x:te+5*ee/6,y:J-ae},{x:te+ee,y:J},{x:te+5*ee/6,y:J+ae},{x:te+2*ee/3,y:J+ae}],Z.label.x=Z.x,Z.label.y=Z.y}})}function Q($,U){return f.mapValues(f.pick($,U),Number)}function V($){var U={};return $&&Object.entries($).forEach(([Z,X])=>{typeof Z=="string"&&(Z=Z.toLowerCase()),U[Z]=X}),U}return zJ}var BJ,g9e;function _7n(){if(g9e)return BJ;g9e=1;let e=Nl(),t=Tg().Graph;BJ={debugOrdering:n};function n(r){let s=e.buildLayerMatrix(r),a=new t({compound:!0,multigraph:!0}).setGraph({});return r.nodes().forEach(i=>{a.setNode(i,{label:i}),a.setParent(i,"layer"+r.node(i).rank)}),r.edges().forEach(i=>a.setEdge(i.v,i.w,{},i.name)),s.forEach((i,l)=>{let c="layer"+l;a.setNode(c,{rank:"same"}),i.reduce((u,d)=>(a.setEdge(u,d,{style:"invis"}),d))}),a}return BJ}var UJ,v9e;function C7n(){return v9e||(v9e=1,UJ="1.1.8"),UJ}var qJ,y9e;function E7n(){return y9e||(y9e=1,qJ={graphlib:Tg(),layout:O7n(),debug:_7n(),util:{time:Nl().time,notime:Nl().notime},version:C7n()}),qJ}var j7n=E7n();const b9e=Tc(j7n);function Ml(e){if(typeof e=="string"||typeof e=="number")return""+e;let t="";if(Array.isArray(e))for(let n=0,r;n<e.length;n++)(r=Ml(e[n]))!==""&&(t+=(t&&" ")+r);else for(let n in e)e[n]&&(t+=(t&&" ")+n);return t}var T7n={value:()=>{}};function TV(){for(var e=0,t=arguments.length,n={},r;e<t;++e){if(!(r=arguments[e]+"")||r in n||/[\s.]/.test(r))throw new Error("illegal type: "+r);n[r]=[]}return new KF(n)}function KF(e){this._=e}function N7n(e,t){return e.trim().split(/^|\s+/).map(function(n){var r="",s=n.indexOf(".");if(s>=0&&(r=n.slice(s+1),n=n.slice(0,s)),n&&!t.hasOwnProperty(n))throw new Error("unknown type: "+n);return{type:n,name:r}})}KF.prototype=TV.prototype={constructor:KF,on:function(e,t){var n=this._,r=N7n(e+"",n),s,a=-1,i=r.length;if(arguments.length<2){for(;++a<i;)if((s=(e=r[a]).type)&&(s=I7n(n[s],e.name)))return s;return}if(t!=null&&typeof t!="function")throw new Error("invalid callback: "+t);for(;++a<i;)if(s=(e=r[a]).type)n[s]=x9e(n[s],e.name,t);else if(t==null)for(s in n)n[s]=x9e(n[s],e.name,null);return this},copy:function(){var e={},t=this._;for(var n in t)e[n]=t[n].slice();return new KF(e)},call:function(e,t){if((s=arguments.length-2)>0)for(var n=new Array(s),r=0,s,a;r<s;++r)n[r]=arguments[r+2];if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(a=this._[e],r=0,s=a.length;r<s;++r)a[r].value.apply(t,n)},apply:function(e,t,n){if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(var r=this._[e],s=0,a=r.length;s<a;++s)r[s].value.apply(t,n)}};function I7n(e,t){for(var n=0,r=e.length,s;n<r;++n)if((s=e[n]).name===t)return s.value}function x9e(e,t,n){for(var r=0,s=e.length;r<s;++r)if(e[r].name===t){e[r]=T7n,e=e.slice(0,r).concat(e.slice(r+1));break}return n!=null&&e.push({name:t,value:n}),e}var khe="http://www.w3.org/1999/xhtml";const w9e={svg:"http://www.w3.org/2000/svg",xhtml:khe,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function NV(e){var t=e+="",n=t.indexOf(":");return n>=0&&(t=e.slice(0,n))!=="xmlns"&&(e=e.slice(n+1)),w9e.hasOwnProperty(t)?{space:w9e[t],local:e}:e}function A7n(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===khe&&t.documentElement.namespaceURI===khe?t.createElement(e):t.createElementNS(n,e)}}function R7n(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function Pxt(e){var t=NV(e);return(t.local?R7n:A7n)(t)}function P7n(){}function u1e(e){return e==null?P7n:function(){return this.querySelector(e)}}function $7n(e){typeof e!="function"&&(e=u1e(e));for(var t=this._groups,n=t.length,r=new Array(n),s=0;s<n;++s)for(var a=t[s],i=a.length,l=r[s]=new Array(i),c,u,d=0;d<i;++d)(c=a[d])&&(u=e.call(c,c.__data__,d,a))&&("__data__"in c&&(u.__data__=c.__data__),l[d]=u);return new qp(r,this._parents)}function M7n(e){return e==null?[]:Array.isArray(e)?e:Array.from(e)}function D7n(){return[]}function $xt(e){return e==null?D7n:function(){return this.querySelectorAll(e)}}function L7n(e){return function(){return M7n(e.apply(this,arguments))}}function F7n(e){typeof e=="function"?e=L7n(e):e=$xt(e);for(var t=this._groups,n=t.length,r=[],s=[],a=0;a<n;++a)for(var i=t[a],l=i.length,c,u=0;u<l;++u)(c=i[u])&&(r.push(e.call(c,c.__data__,u,i)),s.push(c));return new qp(r,s)}function Mxt(e){return function(){return this.matches(e)}}function Dxt(e){return function(t){return t.matches(e)}}var z7n=Array.prototype.find;function B7n(e){return function(){return z7n.call(this.children,e)}}function U7n(){return this.firstElementChild}function q7n(e){return this.select(e==null?U7n:B7n(typeof e=="function"?e:Dxt(e)))}var V7n=Array.prototype.filter;function H7n(){return Array.from(this.children)}function W7n(e){return function(){return V7n.call(this.children,e)}}function Z7n(e){return this.selectAll(e==null?H7n:W7n(typeof e=="function"?e:Dxt(e)))}function G7n(e){typeof e!="function"&&(e=Mxt(e));for(var t=this._groups,n=t.length,r=new Array(n),s=0;s<n;++s)for(var a=t[s],i=a.length,l=r[s]=[],c,u=0;u<i;++u)(c=a[u])&&e.call(c,c.__data__,u,a)&&l.push(c);return new qp(r,this._parents)}function Lxt(e){return new Array(e.length)}function Q7n(){return new qp(this._enter||this._groups.map(Lxt),this._parents)}function N7(e,t){this.ownerDocument=e.ownerDocument,this.namespaceURI=e.namespaceURI,this._next=null,this._parent=e,this.__data__=t}N7.prototype={constructor:N7,appendChild:function(e){return this._parent.insertBefore(e,this._next)},insertBefore:function(e,t){return this._parent.insertBefore(e,t)},querySelector:function(e){return this._parent.querySelector(e)},querySelectorAll:function(e){return this._parent.querySelectorAll(e)}};function Y7n(e){return function(){return e}}function X7n(e,t,n,r,s,a){for(var i=0,l,c=t.length,u=a.length;i<u;++i)(l=t[i])?(l.__data__=a[i],r[i]=l):n[i]=new N7(e,a[i]);for(;i<c;++i)(l=t[i])&&(s[i]=l)}function K7n(e,t,n,r,s,a,i){var l,c,u=new Map,d=t.length,f=a.length,p=new Array(d),h;for(l=0;l<d;++l)(c=t[l])&&(p[l]=h=i.call(c,c.__data__,l,t)+"",u.has(h)?s[l]=c:u.set(h,c));for(l=0;l<f;++l)h=i.call(e,a[l],l,a)+"",(c=u.get(h))?(r[l]=c,c.__data__=a[l],u.delete(h)):n[l]=new N7(e,a[l]);for(l=0;l<d;++l)(c=t[l])&&u.get(p[l])===c&&(s[l]=c)}function J7n(e){return e.__data__}function eBn(e,t){if(!arguments.length)return Array.from(this,J7n);var n=t?K7n:X7n,r=this._parents,s=this._groups;typeof e!="function"&&(e=Y7n(e));for(var a=s.length,i=new Array(a),l=new Array(a),c=new Array(a),u=0;u<a;++u){var d=r[u],f=s[u],p=f.length,h=tBn(e.call(d,d&&d.__data__,u,r)),m=h.length,v=l[u]=new Array(m),y=i[u]=new Array(m),b=c[u]=new Array(p);n(d,f,v,y,b,h,t);for(var S=0,w=0,k,_;S<m;++S)if(k=v[S]){for(S>=w&&(w=S+1);!(_=y[w])&&++w<m;);k._next=_||null}}return i=new qp(i,r),i._enter=l,i._exit=c,i}function tBn(e){return typeof e=="object"&&"length"in e?e:Array.from(e)}function nBn(){return new qp(this._exit||this._groups.map(Lxt),this._parents)}function rBn(e,t,n){var r=this.enter(),s=this,a=this.exit();return typeof e=="function"?(r=e(r),r&&(r=r.selection())):r=r.append(e+""),t!=null&&(s=t(s),s&&(s=s.selection())),n==null?a.remove():n(a),r&&s?r.merge(s).order():s}function sBn(e){for(var t=e.selection?e.selection():e,n=this._groups,r=t._groups,s=n.length,a=r.length,i=Math.min(s,a),l=new Array(s),c=0;c<i;++c)for(var u=n[c],d=r[c],f=u.length,p=l[c]=new Array(f),h,m=0;m<f;++m)(h=u[m]||d[m])&&(p[m]=h);for(;c<s;++c)l[c]=n[c];return new qp(l,this._parents)}function aBn(){for(var e=this._groups,t=-1,n=e.length;++t<n;)for(var r=e[t],s=r.length-1,a=r[s],i;--s>=0;)(i=r[s])&&(a&&i.compareDocumentPosition(a)^4&&a.parentNode.insertBefore(i,a),a=i);return this}function iBn(e){e||(e=oBn);function t(f,p){return f&&p?e(f.__data__,p.__data__):!f-!p}for(var n=this._groups,r=n.length,s=new Array(r),a=0;a<r;++a){for(var i=n[a],l=i.length,c=s[a]=new Array(l),u,d=0;d<l;++d)(u=i[d])&&(c[d]=u);c.sort(t)}return new qp(s,this._parents).order()}function oBn(e,t){return e<t?-1:e>t?1:e>=t?0:NaN}function lBn(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function cBn(){return Array.from(this)}function uBn(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var r=e[t],s=0,a=r.length;s<a;++s){var i=r[s];if(i)return i}return null}function dBn(){let e=0;for(const t of this)++e;return e}function fBn(){return!this.node()}function pBn(e){for(var t=this._groups,n=0,r=t.length;n<r;++n)for(var s=t[n],a=0,i=s.length,l;a<i;++a)(l=s[a])&&e.call(l,l.__data__,a,s);return this}function hBn(e){return function(){this.removeAttribute(e)}}function mBn(e){return function(){this.removeAttributeNS(e.space,e.local)}}function gBn(e,t){return function(){this.setAttribute(e,t)}}function vBn(e,t){return function(){this.setAttributeNS(e.space,e.local,t)}}function yBn(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttribute(e):this.setAttribute(e,n)}}function bBn(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttributeNS(e.space,e.local):this.setAttributeNS(e.space,e.local,n)}}function xBn(e,t){var n=NV(e);if(arguments.length<2){var r=this.node();return n.local?r.getAttributeNS(n.space,n.local):r.getAttribute(n)}return this.each((t==null?n.local?mBn:hBn:typeof t=="function"?n.local?bBn:yBn:n.local?vBn:gBn)(n,t))}function Fxt(e){return e.ownerDocument&&e.ownerDocument.defaultView||e.document&&e||e.defaultView}function wBn(e){return function(){this.style.removeProperty(e)}}function SBn(e,t,n){return function(){this.style.setProperty(e,t,n)}}function kBn(e,t,n){return function(){var r=t.apply(this,arguments);r==null?this.style.removeProperty(e):this.style.setProperty(e,r,n)}}function OBn(e,t,n){return arguments.length>1?this.each((t==null?wBn:typeof t=="function"?kBn:SBn)(e,t,n??"")):wT(this.node(),e)}function wT(e,t){return e.style.getPropertyValue(t)||Fxt(e).getComputedStyle(e,null).getPropertyValue(t)}function _Bn(e){return function(){delete this[e]}}function CBn(e,t){return function(){this[e]=t}}function EBn(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function jBn(e,t){return arguments.length>1?this.each((t==null?_Bn:typeof t=="function"?EBn:CBn)(e,t)):this.node()[e]}function zxt(e){return e.trim().split(/^|\s+/)}function d1e(e){return e.classList||new Bxt(e)}function Bxt(e){this._node=e,this._names=zxt(e.getAttribute("class")||"")}Bxt.prototype={add:function(e){var t=this._names.indexOf(e);t<0&&(this._names.push(e),this._node.setAttribute("class",this._names.join(" ")))},remove:function(e){var t=this._names.indexOf(e);t>=0&&(this._names.splice(t,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(e){return this._names.indexOf(e)>=0}};function Uxt(e,t){for(var n=d1e(e),r=-1,s=t.length;++r<s;)n.add(t[r])}function qxt(e,t){for(var n=d1e(e),r=-1,s=t.length;++r<s;)n.remove(t[r])}function TBn(e){return function(){Uxt(this,e)}}function NBn(e){return function(){qxt(this,e)}}function IBn(e,t){return function(){(t.apply(this,arguments)?Uxt:qxt)(this,e)}}function ABn(e,t){var n=zxt(e+"");if(arguments.length<2){for(var r=d1e(this.node()),s=-1,a=n.length;++s<a;)if(!r.contains(n[s]))return!1;return!0}return this.each((typeof t=="function"?IBn:t?TBn:NBn)(n,t))}function RBn(){this.textContent=""}function PBn(e){return function(){this.textContent=e}}function $Bn(e){return function(){var t=e.apply(this,arguments);this.textContent=t??""}}function MBn(e){return arguments.length?this.each(e==null?RBn:(typeof e=="function"?$Bn:PBn)(e)):this.node().textContent}function DBn(){this.innerHTML=""}function LBn(e){return function(){this.innerHTML=e}}function FBn(e){return function(){var t=e.apply(this,arguments);this.innerHTML=t??""}}function zBn(e){return arguments.length?this.each(e==null?DBn:(typeof e=="function"?FBn:LBn)(e)):this.node().innerHTML}function BBn(){this.nextSibling&&this.parentNode.appendChild(this)}function UBn(){return this.each(BBn)}function qBn(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function VBn(){return this.each(qBn)}function HBn(e){var t=typeof e=="function"?e:Pxt(e);return this.select(function(){return this.appendChild(t.apply(this,arguments))})}function WBn(){return null}function ZBn(e,t){var n=typeof e=="function"?e:Pxt(e),r=t==null?WBn:typeof t=="function"?t:u1e(t);return this.select(function(){return this.insertBefore(n.apply(this,arguments),r.apply(this,arguments)||null)})}function GBn(){var e=this.parentNode;e&&e.removeChild(this)}function QBn(){return this.each(GBn)}function YBn(){var e=this.cloneNode(!1),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function XBn(){var e=this.cloneNode(!0),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function KBn(e){return this.select(e?XBn:YBn)}function JBn(e){return arguments.length?this.property("__data__",e):this.node().__data__}function eUn(e){return function(t){e.call(this,t,this.__data__)}}function tUn(e){return e.trim().split(/^|\s+/).map(function(t){var n="",r=t.indexOf(".");return r>=0&&(n=t.slice(r+1),t=t.slice(0,r)),{type:t,name:n}})}function nUn(e){return function(){var t=this.__on;if(t){for(var n=0,r=-1,s=t.length,a;n<s;++n)a=t[n],(!e.type||a.type===e.type)&&a.name===e.name?this.removeEventListener(a.type,a.listener,a.options):t[++r]=a;++r?t.length=r:delete this.__on}}}function rUn(e,t,n){return function(){var r=this.__on,s,a=eUn(t);if(r){for(var i=0,l=r.length;i<l;++i)if((s=r[i]).type===e.type&&s.name===e.name){this.removeEventListener(s.type,s.listener,s.options),this.addEventListener(s.type,s.listener=a,s.options=n),s.value=t;return}}this.addEventListener(e.type,a,n),s={type:e.type,name:e.name,value:t,listener:a,options:n},r?r.push(s):this.__on=[s]}}function sUn(e,t,n){var r=tUn(e+""),s,a=r.length,i;if(arguments.length<2){var l=this.node().__on;if(l){for(var c=0,u=l.length,d;c<u;++c)for(s=0,d=l[c];s<a;++s)if((i=r[s]).type===d.type&&i.name===d.name)return d.value}return}for(l=t?rUn:nUn,s=0;s<a;++s)this.each(l(r[s],t,n));return this}function Vxt(e,t,n){var r=Fxt(e),s=r.CustomEvent;typeof s=="function"?s=new s(t,n):(s=r.document.createEvent("Event"),n?(s.initEvent(t,n.bubbles,n.cancelable),s.detail=n.detail):s.initEvent(t,!1,!1)),e.dispatchEvent(s)}function aUn(e,t){return function(){return Vxt(this,e,t)}}function iUn(e,t){return function(){return Vxt(this,e,t.apply(this,arguments))}}function oUn(e,t){return this.each((typeof t=="function"?iUn:aUn)(e,t))}function*lUn(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var r=e[t],s=0,a=r.length,i;s<a;++s)(i=r[s])&&(yield i)}var Hxt=[null];function qp(e,t){this._groups=e,this._parents=t}function p3(){return new qp([[document.documentElement]],Hxt)}function cUn(){return this}qp.prototype=p3.prototype={constructor:qp,select:$7n,selectAll:F7n,selectChild:q7n,selectChildren:Z7n,filter:G7n,data:eBn,enter:Q7n,exit:nBn,join:rBn,merge:sBn,selection:cUn,order:aBn,sort:iBn,call:lBn,nodes:cBn,node:uBn,size:dBn,empty:fBn,each:pBn,attr:xBn,style:OBn,property:jBn,classed:ABn,text:MBn,html:zBn,raise:UBn,lower:VBn,append:HBn,insert:ZBn,remove:QBn,clone:KBn,datum:JBn,on:sUn,dispatch:oUn,[Symbol.iterator]:lUn};function gp(e){return typeof e=="string"?new qp([[document.querySelector(e)]],[document.documentElement]):new qp([[e]],Hxt)}function uUn(e){let t;for(;t=e.sourceEvent;)e=t;return e}function Jm(e,t){if(e=uUn(e),t===void 0&&(t=e.currentTarget),t){var n=t.ownerSVGElement||t;if(n.createSVGPoint){var r=n.createSVGPoint();return r.x=e.clientX,r.y=e.clientY,r=r.matrixTransform(t.getScreenCTM().inverse()),[r.x,r.y]}if(t.getBoundingClientRect){var s=t.getBoundingClientRect();return[e.clientX-s.left-t.clientLeft,e.clientY-s.top-t.clientTop]}}return[e.pageX,e.pageY]}const dUn={passive:!1},eM={capture:!0,passive:!1};function VJ(e){e.stopImmediatePropagation()}function _j(e){e.preventDefault(),e.stopImmediatePropagation()}function Wxt(e){var t=e.document.documentElement,n=gp(e).on("dragstart.drag",_j,eM);"onselectstart"in t?n.on("selectstart.drag",_j,eM):(t.__noselect=t.style.MozUserSelect,t.style.MozUserSelect="none")}function Zxt(e,t){var n=e.document.documentElement,r=gp(e).on("dragstart.drag",null);t&&(r.on("click.drag",_j,eM),setTimeout(function(){r.on("click.drag",null)},0)),"onselectstart"in n?r.on("selectstart.drag",null):(n.style.MozUserSelect=n.__noselect,delete n.__noselect)}const O6=e=>()=>e;function Ohe(e,{sourceEvent:t,subject:n,target:r,identifier:s,active:a,x:i,y:l,dx:c,dy:u,dispatch:d}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},subject:{value:n,enumerable:!0,configurable:!0},target:{value:r,enumerable:!0,configurable:!0},identifier:{value:s,enumerable:!0,configurable:!0},active:{value:a,enumerable:!0,configurable:!0},x:{value:i,enumerable:!0,configurable:!0},y:{value:l,enumerable:!0,configurable:!0},dx:{value:c,enumerable:!0,configurable:!0},dy:{value:u,enumerable:!0,configurable:!0},_:{value:d}})}Ohe.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function fUn(e){return!e.ctrlKey&&!e.button}function pUn(){return this.parentNode}function hUn(e,t){return t??{x:e.x,y:e.y}}function mUn(){return navigator.maxTouchPoints||"ontouchstart"in this}function Gxt(){var e=fUn,t=pUn,n=hUn,r=mUn,s={},a=TV("start","drag","end"),i=0,l,c,u,d,f=0;function p(k){k.on("mousedown.drag",h).filter(r).on("touchstart.drag",y).on("touchmove.drag",b,dUn).on("touchend.drag touchcancel.drag",S).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function h(k,_){if(!(d||!e.call(this,k,_))){var C=w(this,t.call(this,k,_),k,_,"mouse");C&&(gp(k.view).on("mousemove.drag",m,eM).on("mouseup.drag",v,eM),Wxt(k.view),VJ(k),u=!1,l=k.clientX,c=k.clientY,C("start",k))}}function m(k){if(_j(k),!u){var _=k.clientX-l,C=k.clientY-c;u=_*_+C*C>f}s.mouse("drag",k)}function v(k){gp(k.view).on("mousemove.drag mouseup.drag",null),Zxt(k.view,u),_j(k),s.mouse("end",k)}function y(k,_){if(e.call(this,k,_)){var C=k.changedTouches,E=t.call(this,k,_),j=C.length,N,I;for(N=0;N<j;++N)(I=w(this,E,k,_,C[N].identifier,C[N]))&&(VJ(k),I("start",k,C[N]))}}function b(k){var _=k.changedTouches,C=_.length,E,j;for(E=0;E<C;++E)(j=s[_[E].identifier])&&(_j(k),j("drag",k,_[E]))}function S(k){var _=k.changedTouches,C=_.length,E,j;for(d&&clearTimeout(d),d=setTimeout(function(){d=null},500),E=0;E<C;++E)(j=s[_[E].identifier])&&(VJ(k),j("end",k,_[E]))}function w(k,_,C,E,j,N){var I=a.copy(),R=Jm(N||C,_),P,L,M;if((M=n.call(k,new Ohe("beforestart",{sourceEvent:C,target:p,identifier:j,active:i,x:R[0],y:R[1],dx:0,dy:0,dispatch:I}),E))!=null)return P=M.x-R[0]||0,L=M.y-R[1]||0,function q(H,F,z){var B=R,D;switch(H){case"start":s[j]=q,D=i++;break;case"end":delete s[j],--i;case"drag":R=Jm(z||F,_),D=i;break}I.call(H,k,new Ohe(H,{sourceEvent:F,subject:M,target:p,identifier:j,active:D,x:R[0]+P,y:R[1]+L,dx:R[0]-B[0],dy:R[1]-B[1],dispatch:I}),E)}}return p.filter=function(k){return arguments.length?(e=typeof k=="function"?k:O6(!!k),p):e},p.container=function(k){return arguments.length?(t=typeof k=="function"?k:O6(k),p):t},p.subject=function(k){return arguments.length?(n=typeof k=="function"?k:O6(k),p):n},p.touchable=function(k){return arguments.length?(r=typeof k=="function"?k:O6(!!k),p):r},p.on=function(){var k=a.on.apply(a,arguments);return k===a?p:k},p.clickDistance=function(k){return arguments.length?(f=(k=+k)*k,p):Math.sqrt(f)},p}function f1e(e,t,n){e.prototype=t.prototype=n,n.constructor=e}function Qxt(e,t){var n=Object.create(e.prototype);for(var r in t)n[r]=t[r];return n}function h3(){}var tM=.7,I7=1/tM,Cj="\\s*([+-]?\\d+)\\s*",nM="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",Jv="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",gUn=/^#([0-9a-f]{3,8})$/,vUn=new RegExp(`^rgb\\(${Cj},${Cj},${Cj}\\)$`),yUn=new RegExp(`^rgb\\(${Jv},${Jv},${Jv}\\)$`),bUn=new RegExp(`^rgba\\(${Cj},${Cj},${Cj},${nM}\\)$`),xUn=new RegExp(`^rgba\\(${Jv},${Jv},${Jv},${nM}\\)$`),wUn=new RegExp(`^hsl\\(${nM},${Jv},${Jv}\\)$`),SUn=new RegExp(`^hsla\\(${nM},${Jv},${Jv},${nM}\\)$`),S9e={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074};f1e(h3,$O,{copy(e){return Object.assign(new this.constructor,this,e)},displayable(){return this.rgb().displayable()},hex:k9e,formatHex:k9e,formatHex8:kUn,formatHsl:OUn,formatRgb:O9e,toString:O9e});function k9e(){return this.rgb().formatHex()}function kUn(){return this.rgb().formatHex8()}function OUn(){return Yxt(this).formatHsl()}function O9e(){return this.rgb().formatRgb()}function $O(e){var t,n;return e=(e+"").trim().toLowerCase(),(t=gUn.exec(e))?(n=t[1].length,t=parseInt(t[1],16),n===6?_9e(t):n===3?new nf(t>>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?_6(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?_6(t>>12&15|t>>8&240,t>>8&15|t>>4&240,t>>4&15|t&240,((t&15)<<4|t&15)/255):null):(t=vUn.exec(e))?new nf(t[1],t[2],t[3],1):(t=yUn.exec(e))?new nf(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=bUn.exec(e))?_6(t[1],t[2],t[3],t[4]):(t=xUn.exec(e))?_6(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=wUn.exec(e))?j9e(t[1],t[2]/100,t[3]/100,1):(t=SUn.exec(e))?j9e(t[1],t[2]/100,t[3]/100,t[4]):S9e.hasOwnProperty(e)?_9e(S9e[e]):e==="transparent"?new nf(NaN,NaN,NaN,0):null}function _9e(e){return new nf(e>>16&255,e>>8&255,e&255,1)}function _6(e,t,n,r){return r<=0&&(e=t=n=NaN),new nf(e,t,n,r)}function _Un(e){return e instanceof h3||(e=$O(e)),e?(e=e.rgb(),new nf(e.r,e.g,e.b,e.opacity)):new nf}function _he(e,t,n,r){return arguments.length===1?_Un(e):new nf(e,t,n,r??1)}function nf(e,t,n,r){this.r=+e,this.g=+t,this.b=+n,this.opacity=+r}f1e(nf,_he,Qxt(h3,{brighter(e){return e=e==null?I7:Math.pow(I7,e),new nf(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?tM:Math.pow(tM,e),new nf(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new nf(Wk(this.r),Wk(this.g),Wk(this.b),A7(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:C9e,formatHex:C9e,formatHex8:CUn,formatRgb:E9e,toString:E9e}));function C9e(){return`#${Nk(this.r)}${Nk(this.g)}${Nk(this.b)}`}function CUn(){return`#${Nk(this.r)}${Nk(this.g)}${Nk(this.b)}${Nk((isNaN(this.opacity)?1:this.opacity)*255)}`}function E9e(){const e=A7(this.opacity);return`${e===1?"rgb(":"rgba("}${Wk(this.r)}, ${Wk(this.g)}, ${Wk(this.b)}${e===1?")":`, ${e})`}`}function A7(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function Wk(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function Nk(e){return e=Wk(e),(e<16?"0":"")+e.toString(16)}function j9e(e,t,n,r){return r<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new ag(e,t,n,r)}function Yxt(e){if(e instanceof ag)return new ag(e.h,e.s,e.l,e.opacity);if(e instanceof h3||(e=$O(e)),!e)return new ag;if(e instanceof ag)return e;e=e.rgb();var t=e.r/255,n=e.g/255,r=e.b/255,s=Math.min(t,n,r),a=Math.max(t,n,r),i=NaN,l=a-s,c=(a+s)/2;return l?(t===a?i=(n-r)/l+(n<r)*6:n===a?i=(r-t)/l+2:i=(t-n)/l+4,l/=c<.5?a+s:2-a-s,i*=60):l=c>0&&c<1?0:i,new ag(i,l,c,e.opacity)}function EUn(e,t,n,r){return arguments.length===1?Yxt(e):new ag(e,t,n,r??1)}function ag(e,t,n,r){this.h=+e,this.s=+t,this.l=+n,this.opacity=+r}f1e(ag,EUn,Qxt(h3,{brighter(e){return e=e==null?I7:Math.pow(I7,e),new ag(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?tM:Math.pow(tM,e),new ag(this.h,this.s,this.l*e,this.opacity)},rgb(){var e=this.h%360+(this.h<0)*360,t=isNaN(e)||isNaN(this.s)?0:this.s,n=this.l,r=n+(n<.5?n:1-n)*t,s=2*n-r;return new nf(HJ(e>=240?e-240:e+120,s,r),HJ(e,s,r),HJ(e<120?e+240:e-120,s,r),this.opacity)},clamp(){return new ag(T9e(this.h),C6(this.s),C6(this.l),A7(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const e=A7(this.opacity);return`${e===1?"hsl(":"hsla("}${T9e(this.h)}, ${C6(this.s)*100}%, ${C6(this.l)*100}%${e===1?")":`, ${e})`}`}}));function T9e(e){return e=(e||0)%360,e<0?e+360:e}function C6(e){return Math.max(0,Math.min(1,e||0))}function HJ(e,t,n){return(e<60?t+(n-t)*e/60:e<180?n:e<240?t+(n-t)*(240-e)/60:t)*255}const p1e=e=>()=>e;function jUn(e,t){return function(n){return e+n*t}}function TUn(e,t,n){return e=Math.pow(e,n),t=Math.pow(t,n)-e,n=1/n,function(r){return Math.pow(e+r*t,n)}}function NUn(e){return(e=+e)==1?Xxt:function(t,n){return n-t?TUn(t,n,e):p1e(isNaN(t)?n:t)}}function Xxt(e,t){var n=t-e;return n?jUn(e,n):p1e(isNaN(e)?t:e)}const R7=(function e(t){var n=NUn(t);function r(s,a){var i=n((s=_he(s)).r,(a=_he(a)).r),l=n(s.g,a.g),c=n(s.b,a.b),u=Xxt(s.opacity,a.opacity);return function(d){return s.r=i(d),s.g=l(d),s.b=c(d),s.opacity=u(d),s+""}}return r.gamma=e,r})(1);function IUn(e,t){t||(t=[]);var n=e?Math.min(t.length,e.length):0,r=t.slice(),s;return function(a){for(s=0;s<n;++s)r[s]=e[s]*(1-a)+t[s]*a;return r}}function AUn(e){return ArrayBuffer.isView(e)&&!(e instanceof DataView)}function RUn(e,t){var n=t?t.length:0,r=e?Math.min(n,e.length):0,s=new Array(r),a=new Array(n),i;for(i=0;i<r;++i)s[i]=ix(e[i],t[i]);for(;i<n;++i)a[i]=t[i];return function(l){for(i=0;i<r;++i)a[i]=s[i](l);return a}}function PUn(e,t){var n=new Date;return e=+e,t=+t,function(r){return n.setTime(e*(1-r)+t*r),n}}function tg(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}function $Un(e,t){var n={},r={},s;(e===null||typeof e!="object")&&(e={}),(t===null||typeof t!="object")&&(t={});for(s in t)s in e?n[s]=ix(e[s],t[s]):r[s]=t[s];return function(a){for(s in n)r[s]=n[s](a);return r}}var Che=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,WJ=new RegExp(Che.source,"g");function MUn(e){return function(){return e}}function DUn(e){return function(t){return e(t)+""}}function Kxt(e,t){var n=Che.lastIndex=WJ.lastIndex=0,r,s,a,i=-1,l=[],c=[];for(e=e+"",t=t+"";(r=Che.exec(e))&&(s=WJ.exec(t));)(a=s.index)>n&&(a=t.slice(n,a),l[i]?l[i]+=a:l[++i]=a),(r=r[0])===(s=s[0])?l[i]?l[i]+=s:l[++i]=s:(l[++i]=null,c.push({i,x:tg(r,s)})),n=WJ.lastIndex;return n<t.length&&(a=t.slice(n),l[i]?l[i]+=a:l[++i]=a),l.length<2?c[0]?DUn(c[0].x):MUn(t):(t=c.length,function(u){for(var d=0,f;d<t;++d)l[(f=c[d]).i]=f.x(u);return l.join("")})}function ix(e,t){var n=typeof t,r;return t==null||n==="boolean"?p1e(t):(n==="number"?tg:n==="string"?(r=$O(t))?(t=r,R7):Kxt:t instanceof $O?R7:t instanceof Date?PUn:AUn(t)?IUn:Array.isArray(t)?RUn:typeof t.valueOf!="function"&&typeof t.toString!="function"||isNaN(t)?$Un:tg)(e,t)}function h1e(e,t){return e=+e,t=+t,function(n){return Math.round(e*(1-n)+t*n)}}var N9e=180/Math.PI,Ehe={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function Jxt(e,t,n,r,s,a){var i,l,c;return(i=Math.sqrt(e*e+t*t))&&(e/=i,t/=i),(c=e*n+t*r)&&(n-=e*c,r-=t*c),(l=Math.sqrt(n*n+r*r))&&(n/=l,r/=l,c/=l),e*r<t*n&&(e=-e,t=-t,c=-c,i=-i),{translateX:s,translateY:a,rotate:Math.atan2(t,e)*N9e,skewX:Math.atan(c)*N9e,scaleX:i,scaleY:l}}var E6;function LUn(e){const t=new(typeof DOMMatrix=="function"?DOMMatrix:WebKitCSSMatrix)(e+"");return t.isIdentity?Ehe:Jxt(t.a,t.b,t.c,t.d,t.e,t.f)}function FUn(e){return e==null||(E6||(E6=document.createElementNS("http://www.w3.org/2000/svg","g")),E6.setAttribute("transform",e),!(e=E6.transform.baseVal.consolidate()))?Ehe:(e=e.matrix,Jxt(e.a,e.b,e.c,e.d,e.e,e.f))}function e0t(e,t,n,r){function s(u){return u.length?u.pop()+" ":""}function a(u,d,f,p,h,m){if(u!==f||d!==p){var v=h.push("translate(",null,t,null,n);m.push({i:v-4,x:tg(u,f)},{i:v-2,x:tg(d,p)})}else(f||p)&&h.push("translate("+f+t+p+n)}function i(u,d,f,p){u!==d?(u-d>180?d+=360:d-u>180&&(u+=360),p.push({i:f.push(s(f)+"rotate(",null,r)-2,x:tg(u,d)})):d&&f.push(s(f)+"rotate("+d+r)}function l(u,d,f,p){u!==d?p.push({i:f.push(s(f)+"skewX(",null,r)-2,x:tg(u,d)}):d&&f.push(s(f)+"skewX("+d+r)}function c(u,d,f,p,h,m){if(u!==f||d!==p){var v=h.push(s(h)+"scale(",null,",",null,")");m.push({i:v-4,x:tg(u,f)},{i:v-2,x:tg(d,p)})}else(f!==1||p!==1)&&h.push(s(h)+"scale("+f+","+p+")")}return function(u,d){var f=[],p=[];return u=e(u),d=e(d),a(u.translateX,u.translateY,d.translateX,d.translateY,f,p),i(u.rotate,d.rotate,f,p),l(u.skewX,d.skewX,f,p),c(u.scaleX,u.scaleY,d.scaleX,d.scaleY,f,p),u=d=null,function(h){for(var m=-1,v=p.length,y;++m<v;)f[(y=p[m]).i]=y.x(h);return f.join("")}}}var zUn=e0t(LUn,"px, ","px)","deg)"),BUn=e0t(FUn,", ",")",")"),UUn=1e-12;function I9e(e){return((e=Math.exp(e))+1/e)/2}function qUn(e){return((e=Math.exp(e))-1/e)/2}function VUn(e){return((e=Math.exp(2*e))-1)/(e+1)}const JF=(function e(t,n,r){function s(a,i){var l=a[0],c=a[1],u=a[2],d=i[0],f=i[1],p=i[2],h=d-l,m=f-c,v=h*h+m*m,y,b;if(v<UUn)b=Math.log(p/u)/t,y=function(E){return[l+E*h,c+E*m,u*Math.exp(t*E*b)]};else{var S=Math.sqrt(v),w=(p*p-u*u+r*v)/(2*u*n*S),k=(p*p-u*u-r*v)/(2*p*n*S),_=Math.log(Math.sqrt(w*w+1)-w),C=Math.log(Math.sqrt(k*k+1)-k);b=(C-_)/t,y=function(E){var j=E*b,N=I9e(_),I=u/(n*S)*(N*VUn(t*j+_)-qUn(_));return[l+I*h,c+I*m,u*N/I9e(t*j+_)]}}return y.duration=b*1e3*t/Math.SQRT2,y}return s.rho=function(a){var i=Math.max(.001,+a),l=i*i,c=l*l;return e(i,l,c)},s})(Math.SQRT2,2,4);function HUn(e,t){t===void 0&&(t=e,e=ix);for(var n=0,r=t.length-1,s=t[0],a=new Array(r<0?0:r);n<r;)a[n]=e(s,s=t[++n]);return function(i){var l=Math.max(0,Math.min(r-1,Math.floor(i*=r)));return a[l](i-l)}}var ST=0,u2=0,YA=0,t0t=1e3,P7,d2,$7=0,MO=0,IV=0,rM=typeof performance=="object"&&performance.now?performance:Date,n0t=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(e){setTimeout(e,17)};function m1e(){return MO||(n0t(WUn),MO=rM.now()+IV)}function WUn(){MO=0}function M7(){this._call=this._time=this._next=null}M7.prototype=r0t.prototype={constructor:M7,restart:function(e,t,n){if(typeof e!="function")throw new TypeError("callback is not a function");n=(n==null?m1e():+n)+(t==null?0:+t),!this._next&&d2!==this&&(d2?d2._next=this:P7=this,d2=this),this._call=e,this._time=n,jhe()},stop:function(){this._call&&(this._call=null,this._time=1/0,jhe())}};function r0t(e,t,n){var r=new M7;return r.restart(e,t,n),r}function ZUn(){m1e(),++ST;for(var e=P7,t;e;)(t=MO-e._time)>=0&&e._call.call(void 0,t),e=e._next;--ST}function A9e(){MO=($7=rM.now())+IV,ST=u2=0;try{ZUn()}finally{ST=0,QUn(),MO=0}}function GUn(){var e=rM.now(),t=e-$7;t>t0t&&(IV-=t,$7=e)}function QUn(){for(var e,t=P7,n,r=1/0;t;)t._call?(r>t._time&&(r=t._time),e=t,t=t._next):(n=t._next,t._next=null,t=e?e._next=n:P7=n);d2=e,jhe(r)}function jhe(e){if(!ST){u2&&(u2=clearTimeout(u2));var t=e-MO;t>24?(e<1/0&&(u2=setTimeout(A9e,e-rM.now()-IV)),YA&&(YA=clearInterval(YA))):(YA||($7=rM.now(),YA=setInterval(GUn,t0t)),ST=1,n0t(A9e))}}function R9e(e,t,n){var r=new M7;return t=t==null?0:+t,r.restart(s=>{r.stop(),e(s+t)},t,n),r}var YUn=TV("start","end","cancel","interrupt"),XUn=[],s0t=0,P9e=1,The=2,e8=3,$9e=4,Nhe=5,t8=6;function AV(e,t,n,r,s,a){var i=e.__transition;if(!i)e.__transition={};else if(n in i)return;KUn(e,n,{name:t,index:r,group:s,on:YUn,tween:XUn,time:a.time,delay:a.delay,duration:a.duration,ease:a.ease,timer:null,state:s0t})}function g1e(e,t){var n=zg(e,t);if(n.state>s0t)throw new Error("too late; already scheduled");return n}function Dy(e,t){var n=zg(e,t);if(n.state>e8)throw new Error("too late; already running");return n}function zg(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw new Error("transition not found");return n}function KUn(e,t,n){var r=e.__transition,s;r[t]=n,n.timer=r0t(a,0,n.time);function a(u){n.state=P9e,n.timer.restart(i,n.delay,n.time),n.delay<=u&&i(u-n.delay)}function i(u){var d,f,p,h;if(n.state!==P9e)return c();for(d in r)if(h=r[d],h.name===n.name){if(h.state===e8)return R9e(i);h.state===$9e?(h.state=t8,h.timer.stop(),h.on.call("interrupt",e,e.__data__,h.index,h.group),delete r[d]):+d<t&&(h.state=t8,h.timer.stop(),h.on.call("cancel",e,e.__data__,h.index,h.group),delete r[d])}if(R9e(function(){n.state===e8&&(n.state=$9e,n.timer.restart(l,n.delay,n.time),l(u))}),n.state=The,n.on.call("start",e,e.__data__,n.index,n.group),n.state===The){for(n.state=e8,s=new Array(p=n.tween.length),d=0,f=-1;d<p;++d)(h=n.tween[d].value.call(e,e.__data__,n.index,n.group))&&(s[++f]=h);s.length=f+1}}function l(u){for(var d=u<n.duration?n.ease.call(null,u/n.duration):(n.timer.restart(c),n.state=Nhe,1),f=-1,p=s.length;++f<p;)s[f].call(e,d);n.state===Nhe&&(n.on.call("end",e,e.__data__,n.index,n.group),c())}function c(){n.state=t8,n.timer.stop(),delete r[t];for(var u in r)return;delete e.__transition}}function n8(e,t){var n=e.__transition,r,s,a=!0,i;if(n){t=t==null?null:t+"";for(i in n){if((r=n[i]).name!==t){a=!1;continue}s=r.state>The&&r.state<Nhe,r.state=t8,r.timer.stop(),r.on.call(s?"interrupt":"cancel",e,e.__data__,r.index,r.group),delete n[i]}a&&delete e.__transition}}function JUn(e){return this.each(function(){n8(this,e)})}function eqn(e,t){var n,r;return function(){var s=Dy(this,e),a=s.tween;if(a!==n){r=n=a;for(var i=0,l=r.length;i<l;++i)if(r[i].name===t){r=r.slice(),r.splice(i,1);break}}s.tween=r}}function tqn(e,t,n){var r,s;if(typeof n!="function")throw new Error;return function(){var a=Dy(this,e),i=a.tween;if(i!==r){s=(r=i).slice();for(var l={name:t,value:n},c=0,u=s.length;c<u;++c)if(s[c].name===t){s[c]=l;break}c===u&&s.push(l)}a.tween=s}}function nqn(e,t){var n=this._id;if(e+="",arguments.length<2){for(var r=zg(this.node(),n).tween,s=0,a=r.length,i;s<a;++s)if((i=r[s]).name===e)return i.value;return null}return this.each((t==null?eqn:tqn)(n,e,t))}function v1e(e,t,n){var r=e._id;return e.each(function(){var s=Dy(this,r);(s.value||(s.value={}))[t]=n.apply(this,arguments)}),function(s){return zg(s,r).value[t]}}function a0t(e,t){var n;return(typeof t=="number"?tg:t instanceof $O?R7:(n=$O(t))?(t=n,R7):Kxt)(e,t)}function rqn(e){return function(){this.removeAttribute(e)}}function sqn(e){return function(){this.removeAttributeNS(e.space,e.local)}}function aqn(e,t,n){var r,s=n+"",a;return function(){var i=this.getAttribute(e);return i===s?null:i===r?a:a=t(r=i,n)}}function iqn(e,t,n){var r,s=n+"",a;return function(){var i=this.getAttributeNS(e.space,e.local);return i===s?null:i===r?a:a=t(r=i,n)}}function oqn(e,t,n){var r,s,a;return function(){var i,l=n(this),c;return l==null?void this.removeAttribute(e):(i=this.getAttribute(e),c=l+"",i===c?null:i===r&&c===s?a:(s=c,a=t(r=i,l)))}}function lqn(e,t,n){var r,s,a;return function(){var i,l=n(this),c;return l==null?void this.removeAttributeNS(e.space,e.local):(i=this.getAttributeNS(e.space,e.local),c=l+"",i===c?null:i===r&&c===s?a:(s=c,a=t(r=i,l)))}}function cqn(e,t){var n=NV(e),r=n==="transform"?BUn:a0t;return this.attrTween(e,typeof t=="function"?(n.local?lqn:oqn)(n,r,v1e(this,"attr."+e,t)):t==null?(n.local?sqn:rqn)(n):(n.local?iqn:aqn)(n,r,t))}function uqn(e,t){return function(n){this.setAttribute(e,t.call(this,n))}}function dqn(e,t){return function(n){this.setAttributeNS(e.space,e.local,t.call(this,n))}}function fqn(e,t){var n,r;function s(){var a=t.apply(this,arguments);return a!==r&&(n=(r=a)&&dqn(e,a)),n}return s._value=t,s}function pqn(e,t){var n,r;function s(){var a=t.apply(this,arguments);return a!==r&&(n=(r=a)&&uqn(e,a)),n}return s._value=t,s}function hqn(e,t){var n="attr."+e;if(arguments.length<2)return(n=this.tween(n))&&n._value;if(t==null)return this.tween(n,null);if(typeof t!="function")throw new Error;var r=NV(e);return this.tween(n,(r.local?fqn:pqn)(r,t))}function mqn(e,t){return function(){g1e(this,e).delay=+t.apply(this,arguments)}}function gqn(e,t){return t=+t,function(){g1e(this,e).delay=t}}function vqn(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?mqn:gqn)(t,e)):zg(this.node(),t).delay}function yqn(e,t){return function(){Dy(this,e).duration=+t.apply(this,arguments)}}function bqn(e,t){return t=+t,function(){Dy(this,e).duration=t}}function xqn(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?yqn:bqn)(t,e)):zg(this.node(),t).duration}function wqn(e,t){if(typeof t!="function")throw new Error;return function(){Dy(this,e).ease=t}}function Sqn(e){var t=this._id;return arguments.length?this.each(wqn(t,e)):zg(this.node(),t).ease}function kqn(e,t){return function(){var n=t.apply(this,arguments);if(typeof n!="function")throw new Error;Dy(this,e).ease=n}}function Oqn(e){if(typeof e!="function")throw new Error;return this.each(kqn(this._id,e))}function _qn(e){typeof e!="function"&&(e=Mxt(e));for(var t=this._groups,n=t.length,r=new Array(n),s=0;s<n;++s)for(var a=t[s],i=a.length,l=r[s]=[],c,u=0;u<i;++u)(c=a[u])&&e.call(c,c.__data__,u,a)&&l.push(c);return new Cx(r,this._parents,this._name,this._id)}function Cqn(e){if(e._id!==this._id)throw new Error;for(var t=this._groups,n=e._groups,r=t.length,s=n.length,a=Math.min(r,s),i=new Array(r),l=0;l<a;++l)for(var c=t[l],u=n[l],d=c.length,f=i[l]=new Array(d),p,h=0;h<d;++h)(p=c[h]||u[h])&&(f[h]=p);for(;l<r;++l)i[l]=t[l];return new Cx(i,this._parents,this._name,this._id)}function Eqn(e){return(e+"").trim().split(/^|\s+/).every(function(t){var n=t.indexOf(".");return n>=0&&(t=t.slice(0,n)),!t||t==="start"})}function jqn(e,t,n){var r,s,a=Eqn(t)?g1e:Dy;return function(){var i=a(this,e),l=i.on;l!==r&&(s=(r=l).copy()).on(t,n),i.on=s}}function Tqn(e,t){var n=this._id;return arguments.length<2?zg(this.node(),n).on.on(e):this.each(jqn(n,e,t))}function Nqn(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function Iqn(){return this.on("end.remove",Nqn(this._id))}function Aqn(e){var t=this._name,n=this._id;typeof e!="function"&&(e=u1e(e));for(var r=this._groups,s=r.length,a=new Array(s),i=0;i<s;++i)for(var l=r[i],c=l.length,u=a[i]=new Array(c),d,f,p=0;p<c;++p)(d=l[p])&&(f=e.call(d,d.__data__,p,l))&&("__data__"in d&&(f.__data__=d.__data__),u[p]=f,AV(u[p],t,n,p,u,zg(d,n)));return new Cx(a,this._parents,t,n)}function Rqn(e){var t=this._name,n=this._id;typeof e!="function"&&(e=$xt(e));for(var r=this._groups,s=r.length,a=[],i=[],l=0;l<s;++l)for(var c=r[l],u=c.length,d,f=0;f<u;++f)if(d=c[f]){for(var p=e.call(d,d.__data__,f,c),h,m=zg(d,n),v=0,y=p.length;v<y;++v)(h=p[v])&&AV(h,t,n,v,p,m);a.push(p),i.push(d)}return new Cx(a,i,t,n)}var Pqn=p3.prototype.constructor;function $qn(){return new Pqn(this._groups,this._parents)}function Mqn(e,t){var n,r,s;return function(){var a=wT(this,e),i=(this.style.removeProperty(e),wT(this,e));return a===i?null:a===n&&i===r?s:s=t(n=a,r=i)}}function i0t(e){return function(){this.style.removeProperty(e)}}function Dqn(e,t,n){var r,s=n+"",a;return function(){var i=wT(this,e);return i===s?null:i===r?a:a=t(r=i,n)}}function Lqn(e,t,n){var r,s,a;return function(){var i=wT(this,e),l=n(this),c=l+"";return l==null&&(c=l=(this.style.removeProperty(e),wT(this,e))),i===c?null:i===r&&c===s?a:(s=c,a=t(r=i,l))}}function Fqn(e,t){var n,r,s,a="style."+t,i="end."+a,l;return function(){var c=Dy(this,e),u=c.on,d=c.value[a]==null?l||(l=i0t(t)):void 0;(u!==n||s!==d)&&(r=(n=u).copy()).on(i,s=d),c.on=r}}function zqn(e,t,n){var r=(e+="")=="transform"?zUn:a0t;return t==null?this.styleTween(e,Mqn(e,r)).on("end.style."+e,i0t(e)):typeof t=="function"?this.styleTween(e,Lqn(e,r,v1e(this,"style."+e,t))).each(Fqn(this._id,e)):this.styleTween(e,Dqn(e,r,t),n).on("end.style."+e,null)}function Bqn(e,t,n){return function(r){this.style.setProperty(e,t.call(this,r),n)}}function Uqn(e,t,n){var r,s;function a(){var i=t.apply(this,arguments);return i!==s&&(r=(s=i)&&Bqn(e,i,n)),r}return a._value=t,a}function qqn(e,t,n){var r="style."+(e+="");if(arguments.length<2)return(r=this.tween(r))&&r._value;if(t==null)return this.tween(r,null);if(typeof t!="function")throw new Error;return this.tween(r,Uqn(e,t,n??""))}function Vqn(e){return function(){this.textContent=e}}function Hqn(e){return function(){var t=e(this);this.textContent=t??""}}function Wqn(e){return this.tween("text",typeof e=="function"?Hqn(v1e(this,"text",e)):Vqn(e==null?"":e+""))}function Zqn(e){return function(t){this.textContent=e.call(this,t)}}function Gqn(e){var t,n;function r(){var s=e.apply(this,arguments);return s!==n&&(t=(n=s)&&Zqn(s)),t}return r._value=e,r}function Qqn(e){var t="text";if(arguments.length<1)return(t=this.tween(t))&&t._value;if(e==null)return this.tween(t,null);if(typeof e!="function")throw new Error;return this.tween(t,Gqn(e))}function Yqn(){for(var e=this._name,t=this._id,n=o0t(),r=this._groups,s=r.length,a=0;a<s;++a)for(var i=r[a],l=i.length,c,u=0;u<l;++u)if(c=i[u]){var d=zg(c,t);AV(c,e,n,u,i,{time:d.time+d.delay+d.duration,delay:0,duration:d.duration,ease:d.ease})}return new Cx(r,this._parents,e,n)}function Xqn(){var e,t,n=this,r=n._id,s=n.size();return new Promise(function(a,i){var l={value:i},c={value:function(){--s===0&&a()}};n.each(function(){var u=Dy(this,r),d=u.on;d!==e&&(t=(e=d).copy(),t._.cancel.push(l),t._.interrupt.push(l),t._.end.push(c)),u.on=t}),s===0&&a()})}var Kqn=0;function Cx(e,t,n,r){this._groups=e,this._parents=t,this._name=n,this._id=r}function o0t(){return++Kqn}var gb=p3.prototype;Cx.prototype={constructor:Cx,select:Aqn,selectAll:Rqn,selectChild:gb.selectChild,selectChildren:gb.selectChildren,filter:_qn,merge:Cqn,selection:$qn,transition:Yqn,call:gb.call,nodes:gb.nodes,node:gb.node,size:gb.size,empty:gb.empty,each:gb.each,on:Tqn,attr:cqn,attrTween:hqn,style:zqn,styleTween:qqn,text:Wqn,textTween:Qqn,remove:Iqn,tween:nqn,delay:vqn,duration:xqn,ease:Sqn,easeVarying:Oqn,end:Xqn,[Symbol.iterator]:gb[Symbol.iterator]};function Jqn(e){return((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2}var eVn={time:null,delay:0,duration:250,ease:Jqn};function tVn(e,t){for(var n;!(n=e.__transition)||!(n=n[t]);)if(!(e=e.parentNode))throw new Error(`transition ${t} not found`);return n}function nVn(e){var t,n;e instanceof Cx?(t=e._id,e=e._name):(t=o0t(),(n=eVn).time=m1e(),e=e==null?null:e+"");for(var r=this._groups,s=r.length,a=0;a<s;++a)for(var i=r[a],l=i.length,c,u=0;u<l;++u)(c=i[u])&&AV(c,e,t,u,i,n||tVn(c,t));return new Cx(r,this._parents,e,t)}p3.prototype.interrupt=JUn;p3.prototype.transition=nVn;const j6=e=>()=>e;function rVn(e,{sourceEvent:t,target:n,transform:r,dispatch:s}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},target:{value:n,enumerable:!0,configurable:!0},transform:{value:r,enumerable:!0,configurable:!0},_:{value:s}})}function Zb(e,t,n){this.k=e,this.x=t,this.y=n}Zb.prototype={constructor:Zb,scale:function(e){return e===1?this:new Zb(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new Zb(this.k,this.x+this.k*e,this.y+this.k*t)},apply:function(e){return[e[0]*this.k+this.x,e[1]*this.k+this.y]},applyX:function(e){return e*this.k+this.x},applyY:function(e){return e*this.k+this.y},invert:function(e){return[(e[0]-this.x)/this.k,(e[1]-this.y)/this.k]},invertX:function(e){return(e-this.x)/this.k},invertY:function(e){return(e-this.y)/this.k},rescaleX:function(e){return e.copy().domain(e.range().map(this.invertX,this).map(e.invert,e))},rescaleY:function(e){return e.copy().domain(e.range().map(this.invertY,this).map(e.invert,e))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};var RV=new Zb(1,0,0);l0t.prototype=Zb.prototype;function l0t(e){for(;!e.__zoom;)if(!(e=e.parentNode))return RV;return e.__zoom}function ZJ(e){e.stopImmediatePropagation()}function XA(e){e.preventDefault(),e.stopImmediatePropagation()}function sVn(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function aVn(){var e=this;return e instanceof SVGElement?(e=e.ownerSVGElement||e,e.hasAttribute("viewBox")?(e=e.viewBox.baseVal,[[e.x,e.y],[e.x+e.width,e.y+e.height]]):[[0,0],[e.width.baseVal.value,e.height.baseVal.value]]):[[0,0],[e.clientWidth,e.clientHeight]]}function M9e(){return this.__zoom||RV}function iVn(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function oVn(){return navigator.maxTouchPoints||"ontouchstart"in this}function lVn(e,t,n){var r=e.invertX(t[0][0])-n[0][0],s=e.invertX(t[1][0])-n[1][0],a=e.invertY(t[0][1])-n[0][1],i=e.invertY(t[1][1])-n[1][1];return e.translate(s>r?(r+s)/2:Math.min(0,r)||Math.max(0,s),i>a?(a+i)/2:Math.min(0,a)||Math.max(0,i))}function c0t(){var e=sVn,t=aVn,n=lVn,r=iVn,s=oVn,a=[0,1/0],i=[[-1/0,-1/0],[1/0,1/0]],l=250,c=JF,u=TV("start","zoom","end"),d,f,p,h=500,m=150,v=0,y=10;function b(M){M.property("__zoom",M9e).on("wheel.zoom",j,{passive:!1}).on("mousedown.zoom",N).on("dblclick.zoom",I).filter(s).on("touchstart.zoom",R).on("touchmove.zoom",P).on("touchend.zoom touchcancel.zoom",L).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}b.transform=function(M,q,H,F){var z=M.selection?M.selection():M;z.property("__zoom",M9e),M!==z?_(M,q,H,F):z.interrupt().each(function(){C(this,arguments).event(F).start().zoom(null,typeof q=="function"?q.apply(this,arguments):q).end()})},b.scaleBy=function(M,q,H,F){b.scaleTo(M,function(){var z=this.__zoom.k,B=typeof q=="function"?q.apply(this,arguments):q;return z*B},H,F)},b.scaleTo=function(M,q,H,F){b.transform(M,function(){var z=t.apply(this,arguments),B=this.__zoom,D=H==null?k(z):typeof H=="function"?H.apply(this,arguments):H,Q=B.invert(D),V=typeof q=="function"?q.apply(this,arguments):q;return n(w(S(B,V),D,Q),z,i)},H,F)},b.translateBy=function(M,q,H,F){b.transform(M,function(){return n(this.__zoom.translate(typeof q=="function"?q.apply(this,arguments):q,typeof H=="function"?H.apply(this,arguments):H),t.apply(this,arguments),i)},null,F)},b.translateTo=function(M,q,H,F,z){b.transform(M,function(){var B=t.apply(this,arguments),D=this.__zoom,Q=F==null?k(B):typeof F=="function"?F.apply(this,arguments):F;return n(RV.translate(Q[0],Q[1]).scale(D.k).translate(typeof q=="function"?-q.apply(this,arguments):-q,typeof H=="function"?-H.apply(this,arguments):-H),B,i)},F,z)};function S(M,q){return q=Math.max(a[0],Math.min(a[1],q)),q===M.k?M:new Zb(q,M.x,M.y)}function w(M,q,H){var F=q[0]-H[0]*M.k,z=q[1]-H[1]*M.k;return F===M.x&&z===M.y?M:new Zb(M.k,F,z)}function k(M){return[(+M[0][0]+ +M[1][0])/2,(+M[0][1]+ +M[1][1])/2]}function _(M,q,H,F){M.on("start.zoom",function(){C(this,arguments).event(F).start()}).on("interrupt.zoom end.zoom",function(){C(this,arguments).event(F).end()}).tween("zoom",function(){var z=this,B=arguments,D=C(z,B).event(F),Q=t.apply(z,B),V=H==null?k(Q):typeof H=="function"?H.apply(z,B):H,$=Math.max(Q[1][0]-Q[0][0],Q[1][1]-Q[0][1]),U=z.__zoom,Z=typeof q=="function"?q.apply(z,B):q,X=c(U.invert(V).concat($/U.k),Z.invert(V).concat($/Z.k));return function(te){if(te===1)te=Z;else{var J=X(te),ee=$/J[2];te=new Zb(ee,V[0]-J[0]*ee,V[1]-J[1]*ee)}D.zoom(null,te)}})}function C(M,q,H){return!H&&M.__zooming||new E(M,q)}function E(M,q){this.that=M,this.args=q,this.active=0,this.sourceEvent=null,this.extent=t.apply(M,q),this.taps=0}E.prototype={event:function(M){return M&&(this.sourceEvent=M),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(M,q){return this.mouse&&M!=="mouse"&&(this.mouse[1]=q.invert(this.mouse[0])),this.touch0&&M!=="touch"&&(this.touch0[1]=q.invert(this.touch0[0])),this.touch1&&M!=="touch"&&(this.touch1[1]=q.invert(this.touch1[0])),this.that.__zoom=q,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(M){var q=gp(this.that).datum();u.call(M,this.that,new rVn(M,{sourceEvent:this.sourceEvent,target:b,transform:this.that.__zoom,dispatch:u}),q)}};function j(M,...q){if(!e.apply(this,arguments))return;var H=C(this,q).event(M),F=this.__zoom,z=Math.max(a[0],Math.min(a[1],F.k*Math.pow(2,r.apply(this,arguments)))),B=Jm(M);if(H.wheel)(H.mouse[0][0]!==B[0]||H.mouse[0][1]!==B[1])&&(H.mouse[1]=F.invert(H.mouse[0]=B)),clearTimeout(H.wheel);else{if(F.k===z)return;H.mouse=[B,F.invert(B)],n8(this),H.start()}XA(M),H.wheel=setTimeout(D,m),H.zoom("mouse",n(w(S(F,z),H.mouse[0],H.mouse[1]),H.extent,i));function D(){H.wheel=null,H.end()}}function N(M,...q){if(p||!e.apply(this,arguments))return;var H=M.currentTarget,F=C(this,q,!0).event(M),z=gp(M.view).on("mousemove.zoom",V,!0).on("mouseup.zoom",$,!0),B=Jm(M,H),D=M.clientX,Q=M.clientY;Wxt(M.view),ZJ(M),F.mouse=[B,this.__zoom.invert(B)],n8(this),F.start();function V(U){if(XA(U),!F.moved){var Z=U.clientX-D,X=U.clientY-Q;F.moved=Z*Z+X*X>v}F.event(U).zoom("mouse",n(w(F.that.__zoom,F.mouse[0]=Jm(U,H),F.mouse[1]),F.extent,i))}function $(U){z.on("mousemove.zoom mouseup.zoom",null),Zxt(U.view,F.moved),XA(U),F.event(U).end()}}function I(M,...q){if(e.apply(this,arguments)){var H=this.__zoom,F=Jm(M.changedTouches?M.changedTouches[0]:M,this),z=H.invert(F),B=H.k*(M.shiftKey?.5:2),D=n(w(S(H,B),F,z),t.apply(this,q),i);XA(M),l>0?gp(this).transition().duration(l).call(_,D,F,M):gp(this).call(b.transform,D,F,M)}}function R(M,...q){if(e.apply(this,arguments)){var H=M.touches,F=H.length,z=C(this,q,M.changedTouches.length===F).event(M),B,D,Q,V;for(ZJ(M),D=0;D<F;++D)Q=H[D],V=Jm(Q,this),V=[V,this.__zoom.invert(V),Q.identifier],z.touch0?!z.touch1&&z.touch0[2]!==V[2]&&(z.touch1=V,z.taps=0):(z.touch0=V,B=!0,z.taps=1+!!d);d&&(d=clearTimeout(d)),B&&(z.taps<2&&(f=V[0],d=setTimeout(function(){d=null},h)),n8(this),z.start())}}function P(M,...q){if(this.__zooming){var H=C(this,q).event(M),F=M.changedTouches,z=F.length,B,D,Q,V;for(XA(M),B=0;B<z;++B)D=F[B],Q=Jm(D,this),H.touch0&&H.touch0[2]===D.identifier?H.touch0[0]=Q:H.touch1&&H.touch1[2]===D.identifier&&(H.touch1[0]=Q);if(D=H.that.__zoom,H.touch1){var $=H.touch0[0],U=H.touch0[1],Z=H.touch1[0],X=H.touch1[1],te=(te=Z[0]-$[0])*te+(te=Z[1]-$[1])*te,J=(J=X[0]-U[0])*J+(J=X[1]-U[1])*J;D=S(D,Math.sqrt(te/J)),Q=[($[0]+Z[0])/2,($[1]+Z[1])/2],V=[(U[0]+X[0])/2,(U[1]+X[1])/2]}else if(H.touch0)Q=H.touch0[0],V=H.touch0[1];else return;H.zoom("touch",n(w(D,Q,V),H.extent,i))}}function L(M,...q){if(this.__zooming){var H=C(this,q).event(M),F=M.changedTouches,z=F.length,B,D;for(ZJ(M),p&&clearTimeout(p),p=setTimeout(function(){p=null},h),B=0;B<z;++B)D=F[B],H.touch0&&H.touch0[2]===D.identifier?delete H.touch0:H.touch1&&H.touch1[2]===D.identifier&&delete H.touch1;if(H.touch1&&!H.touch0&&(H.touch0=H.touch1,delete H.touch1),H.touch0)H.touch0[1]=this.__zoom.invert(H.touch0[0]);else if(H.end(),H.taps===2&&(D=Jm(D,this),Math.hypot(f[0]-D[0],f[1]-D[1])<y)){var Q=gp(this).on("dblclick.zoom");Q&&Q.apply(this,arguments)}}}return b.wheelDelta=function(M){return arguments.length?(r=typeof M=="function"?M:j6(+M),b):r},b.filter=function(M){return arguments.length?(e=typeof M=="function"?M:j6(!!M),b):e},b.touchable=function(M){return arguments.length?(s=typeof M=="function"?M:j6(!!M),b):s},b.extent=function(M){return arguments.length?(t=typeof M=="function"?M:j6([[+M[0][0],+M[0][1]],[+M[1][0],+M[1][1]]]),b):t},b.scaleExtent=function(M){return arguments.length?(a[0]=+M[0],a[1]=+M[1],b):[a[0],a[1]]},b.translateExtent=function(M){return arguments.length?(i[0][0]=+M[0][0],i[1][0]=+M[1][0],i[0][1]=+M[0][1],i[1][1]=+M[1][1],b):[[i[0][0],i[0][1]],[i[1][0],i[1][1]]]},b.constrain=function(M){return arguments.length?(n=M,b):n},b.duration=function(M){return arguments.length?(l=+M,b):l},b.interpolate=function(M){return arguments.length?(c=M,b):c},b.on=function(){var M=u.on.apply(u,arguments);return M===u?b:M},b.clickDistance=function(M){return arguments.length?(v=(M=+M)*M,b):Math.sqrt(v)},b.tapDistance=function(M){return arguments.length?(y=+M,b):y},b}const hy={error001:()=>"[React Flow]: Seems like you have not used zustand provider as an ancestor. Help: https://reactflow.dev/error#001",error002:()=>"It looks like you've created a new nodeTypes or edgeTypes object. If this wasn't on purpose please define the nodeTypes/edgeTypes outside of the component or memoize them.",error003:e=>`Node type "${e}" not found. Using fallback type "default".`,error004:()=>"The React Flow parent container needs a width and a height to render the graph.",error005:()=>"Only child nodes can use a parent extent.",error006:()=>"Can't create edge. An edge needs a source and a target.",error007:e=>`The old edge with id=${e} does not exist.`,error009:e=>`Marker type "${e}" doesn't exist.`,error008:(e,{id:t,sourceHandle:n,targetHandle:r})=>`Couldn't create edge for ${e} handle id: "${e==="source"?n:r}", edge id: ${t}.`,error010:()=>"Handle: No node id found. Make sure to only use a Handle inside a custom Node.",error011:e=>`Edge type "${e}" not found. Using fallback type "default".`,error012:e=>`Node with id "${e}" does not exist, it may have been removed. This can happen when a node is deleted before the "onNodeClick" handler is called.`,error013:(e="react")=>`It seems that you haven't loaded the styles. Please import '@xyflow/${e}/dist/style.css' or base.css to make sure everything is working properly.`,error014:()=>"useNodeConnections: No node ID found. Call useNodeConnections inside a custom Node or provide a node ID.",error015:()=>"It seems that you are trying to drag a node that is not initialized. Please use onNodesChange as explained in the docs."},sM=[[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY],[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]],u0t=["Enter"," ","Escape"],d0t={"node.a11yDescription.default":"Press enter or space to select a node. Press delete to remove it and escape to cancel.","node.a11yDescription.keyboardDisabled":"Press enter or space to select a node. You can then use the arrow keys to move the node around. Press delete to remove it and escape to cancel.","node.a11yDescription.ariaLiveMessage":({direction:e,x:t,y:n})=>`Moved selected node ${e}. New position, x: ${t}, y: ${n}`,"edge.a11yDescription.default":"Press enter or space to select an edge. You can then press delete to remove it or escape to cancel.","controls.ariaLabel":"Control Panel","controls.zoomIn.ariaLabel":"Zoom In","controls.zoomOut.ariaLabel":"Zoom Out","controls.fitView.ariaLabel":"Fit View","controls.interactive.ariaLabel":"Toggle Interactivity","minimap.ariaLabel":"Mini Map","handle.ariaLabel":"Handle"};var kT;(function(e){e.Strict="strict",e.Loose="loose"})(kT||(kT={}));var Zk;(function(e){e.Free="free",e.Vertical="vertical",e.Horizontal="horizontal"})(Zk||(Zk={}));var aM;(function(e){e.Partial="partial",e.Full="full"})(aM||(aM={}));const f0t={inProgress:!1,isValid:null,from:null,fromHandle:null,fromPosition:null,fromNode:null,to:null,toHandle:null,toPosition:null,toNode:null,pointer:null};var iw;(function(e){e.Bezier="default",e.Straight="straight",e.Step="step",e.SmoothStep="smoothstep",e.SimpleBezier="simplebezier"})(iw||(iw={}));var iM;(function(e){e.Arrow="arrow",e.ArrowClosed="arrowclosed"})(iM||(iM={}));var nr;(function(e){e.Left="left",e.Top="top",e.Right="right",e.Bottom="bottom"})(nr||(nr={}));const D9e={[nr.Left]:nr.Right,[nr.Right]:nr.Left,[nr.Top]:nr.Bottom,[nr.Bottom]:nr.Top};function p0t(e){return e===null?null:e?"valid":"invalid"}const h0t=e=>"id"in e&&"source"in e&&"target"in e,cVn=e=>"id"in e&&"position"in e&&!("source"in e)&&!("target"in e),y1e=e=>"id"in e&&"internals"in e&&!("source"in e)&&!("target"in e),m3=(e,t=[0,0])=>{const{width:n,height:r}=Gx(e),s=e.origin??t,a=n*s[0],i=r*s[1];return{x:e.position.x-a,y:e.position.y-i}},uVn=(e,t={nodeOrigin:[0,0]})=>{if(e.length===0)return{x:0,y:0,width:0,height:0};const n=e.reduce((r,s)=>{const a=typeof s=="string";let i=!t.nodeLookup&&!a?s:void 0;t.nodeLookup&&(i=a?t.nodeLookup.get(s):y1e(s)?s:t.nodeLookup.get(s.id));const l=i?D7(i,t.nodeOrigin):{x:0,y:0,x2:0,y2:0};return PV(r,l)},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return $V(n)},g3=(e,t={})=>{let n={x:1/0,y:1/0,x2:-1/0,y2:-1/0},r=!1;return e.forEach(s=>{(t.filter===void 0||t.filter(s))&&(n=PV(n,D7(s)),r=!0)}),r?$V(n):{x:0,y:0,width:0,height:0}},b1e=(e,t,[n,r,s]=[0,0,1],a=!1,i=!1)=>{const l={...y3(t,[n,r,s]),width:t.width/s,height:t.height/s},c=[];for(const u of e.values()){const{measured:d,selectable:f=!0,hidden:p=!1}=u;if(i&&!f||p)continue;const h=d.width??u.width??u.initialWidth??null,m=d.height??u.height??u.initialHeight??null,v=oM(l,_T(u)),y=(h??0)*(m??0),b=a&&v>0;(!u.internals.handleBounds||b||v>=y||u.dragging)&&c.push(u)}return c},dVn=(e,t)=>{const n=new Set;return e.forEach(r=>{n.add(r.id)}),t.filter(r=>n.has(r.source)||n.has(r.target))};function fVn(e,t){const n=new Map,r=t?.nodes?new Set(t.nodes.map(s=>s.id)):null;return e.forEach(s=>{s.measured.width&&s.measured.height&&(t?.includeHiddenNodes||!s.hidden)&&(!r||r.has(s.id))&&n.set(s.id,s)}),n}async function pVn({nodes:e,width:t,height:n,panZoom:r,minZoom:s,maxZoom:a},i){if(e.size===0)return Promise.resolve(!0);const l=fVn(e,i),c=g3(l),u=x1e(c,t,n,i?.minZoom??s,i?.maxZoom??a,i?.padding??.1);return await r.setViewport(u,{duration:i?.duration,ease:i?.ease,interpolate:i?.interpolate}),Promise.resolve(!0)}function m0t({nodeId:e,nextPosition:t,nodeLookup:n,nodeOrigin:r=[0,0],nodeExtent:s,onError:a}){const i=n.get(e),l=i.parentId?n.get(i.parentId):void 0,{x:c,y:u}=l?l.internals.positionAbsolute:{x:0,y:0},d=i.origin??r;let f=i.extent||s;if(i.extent==="parent"&&!i.expandParent)if(!l)a?.("005",hy.error005());else{const h=l.measured.width,m=l.measured.height;h&&m&&(f=[[c,u],[c+h,u+m]])}else l&&CT(i.extent)&&(f=[[i.extent[0][0]+c,i.extent[0][1]+u],[i.extent[1][0]+c,i.extent[1][1]+u]]);const p=CT(f)?DO(t,f,i.measured):t;return(i.measured.width===void 0||i.measured.height===void 0)&&a?.("015",hy.error015()),{position:{x:p.x-c+(i.measured.width??0)*d[0],y:p.y-u+(i.measured.height??0)*d[1]},positionAbsolute:p}}async function hVn({nodesToRemove:e=[],edgesToRemove:t=[],nodes:n,edges:r,onBeforeDelete:s}){const a=new Set(e.map(p=>p.id)),i=[];for(const p of n){if(p.deletable===!1)continue;const h=a.has(p.id),m=!h&&p.parentId&&i.find(v=>v.id===p.parentId);(h||m)&&i.push(p)}const l=new Set(t.map(p=>p.id)),c=r.filter(p=>p.deletable!==!1),d=dVn(i,c);for(const p of c)l.has(p.id)&&!d.find(m=>m.id===p.id)&&d.push(p);if(!s)return{edges:d,nodes:i};const f=await s({nodes:i,edges:d});return typeof f=="boolean"?f?{edges:d,nodes:i}:{edges:[],nodes:[]}:f}const OT=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),DO=(e={x:0,y:0},t,n)=>({x:OT(e.x,t[0][0],t[1][0]-(n?.width??0)),y:OT(e.y,t[0][1],t[1][1]-(n?.height??0))});function g0t(e,t,n){const{width:r,height:s}=Gx(n),{x:a,y:i}=n.internals.positionAbsolute;return DO(e,[[a,i],[a+r,i+s]],t)}const L9e=(e,t,n)=>e<t?OT(Math.abs(e-t),1,t)/t:e>n?-OT(Math.abs(e-n),1,t)/t:0,v0t=(e,t,n=15,r=40)=>{const s=L9e(e.x,r,t.width-r)*n,a=L9e(e.y,r,t.height-r)*n;return[s,a]},PV=(e,t)=>({x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x2,t.x2),y2:Math.max(e.y2,t.y2)}),Ihe=({x:e,y:t,width:n,height:r})=>({x:e,y:t,x2:e+n,y2:t+r}),$V=({x:e,y:t,x2:n,y2:r})=>({x:e,y:t,width:n-e,height:r-t}),_T=(e,t=[0,0])=>{const{x:n,y:r}=y1e(e)?e.internals.positionAbsolute:m3(e,t);return{x:n,y:r,width:e.measured?.width??e.width??e.initialWidth??0,height:e.measured?.height??e.height??e.initialHeight??0}},D7=(e,t=[0,0])=>{const{x:n,y:r}=y1e(e)?e.internals.positionAbsolute:m3(e,t);return{x:n,y:r,x2:n+(e.measured?.width??e.width??e.initialWidth??0),y2:r+(e.measured?.height??e.height??e.initialHeight??0)}},y0t=(e,t)=>$V(PV(Ihe(e),Ihe(t))),oM=(e,t)=>{const n=Math.max(0,Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x)),r=Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y));return Math.ceil(n*r)},F9e=e=>dg(e.width)&&dg(e.height)&&dg(e.x)&&dg(e.y),dg=e=>!isNaN(e)&&isFinite(e),mVn=(e,t)=>{},v3=(e,t=[1,1])=>({x:t[0]*Math.round(e.x/t[0]),y:t[1]*Math.round(e.y/t[1])}),y3=({x:e,y:t},[n,r,s],a=!1,i=[1,1])=>{const l={x:(e-n)/s,y:(t-r)/s};return a?v3(l,i):l},L7=({x:e,y:t},[n,r,s])=>({x:e*s+n,y:t*s+r});function UC(e,t){if(typeof e=="number")return Math.floor((t-t/(1+e))*.5);if(typeof e=="string"&&e.endsWith("px")){const n=parseFloat(e);if(!Number.isNaN(n))return Math.floor(n)}if(typeof e=="string"&&e.endsWith("%")){const n=parseFloat(e);if(!Number.isNaN(n))return Math.floor(t*n*.01)}return console.error(`[React Flow] The padding value "${e}" is invalid. Please provide a number or a string with a valid unit (px or %).`),0}function gVn(e,t,n){if(typeof e=="string"||typeof e=="number"){const r=UC(e,n),s=UC(e,t);return{top:r,right:s,bottom:r,left:s,x:s*2,y:r*2}}if(typeof e=="object"){const r=UC(e.top??e.y??0,n),s=UC(e.bottom??e.y??0,n),a=UC(e.left??e.x??0,t),i=UC(e.right??e.x??0,t);return{top:r,right:i,bottom:s,left:a,x:a+i,y:r+s}}return{top:0,right:0,bottom:0,left:0,x:0,y:0}}function vVn(e,t,n,r,s,a){const{x:i,y:l}=L7(e,[t,n,r]),{x:c,y:u}=L7({x:e.x+e.width,y:e.y+e.height},[t,n,r]),d=s-c,f=a-u;return{left:Math.floor(i),top:Math.floor(l),right:Math.floor(d),bottom:Math.floor(f)}}const x1e=(e,t,n,r,s,a)=>{const i=gVn(a,t,n),l=(t-i.x)/e.width,c=(n-i.y)/e.height,u=Math.min(l,c),d=OT(u,r,s),f=e.x+e.width/2,p=e.y+e.height/2,h=t/2-f*d,m=n/2-p*d,v=vVn(e,h,m,d,t,n),y={left:Math.min(v.left-i.left,0),top:Math.min(v.top-i.top,0),right:Math.min(v.right-i.right,0),bottom:Math.min(v.bottom-i.bottom,0)};return{x:h-y.left+y.right,y:m-y.top+y.bottom,zoom:d}},lM=()=>typeof navigator<"u"&&navigator?.userAgent?.indexOf("Mac")>=0;function CT(e){return e!=null&&e!=="parent"}function Gx(e){return{width:e.measured?.width??e.width??e.initialWidth??0,height:e.measured?.height??e.height??e.initialHeight??0}}function b0t(e){return(e.measured?.width??e.width??e.initialWidth)!==void 0&&(e.measured?.height??e.height??e.initialHeight)!==void 0}function x0t(e,t={width:0,height:0},n,r,s){const a={...e},i=r.get(n);if(i){const l=i.origin||s;a.x+=i.internals.positionAbsolute.x-(t.width??0)*l[0],a.y+=i.internals.positionAbsolute.y-(t.height??0)*l[1]}return a}function z9e(e,t){if(e.size!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;return!0}function yVn(){let e,t;return{promise:new Promise((r,s)=>{e=r,t=s}),resolve:e,reject:t}}function bVn(e){return{...d0t,...e||{}}}function V2(e,{snapGrid:t=[0,0],snapToGrid:n=!1,transform:r,containerBounds:s}){const{x:a,y:i}=fg(e),l=y3({x:a-(s?.left??0),y:i-(s?.top??0)},r),{x:c,y:u}=n?v3(l,t):l;return{xSnapped:c,ySnapped:u,...l}}const w1e=e=>({width:e.offsetWidth,height:e.offsetHeight}),w0t=e=>e?.getRootNode?.()||window?.document,xVn=["INPUT","SELECT","TEXTAREA"];function S0t(e){const t=e.composedPath?.()?.[0]||e.target;return t?.nodeType!==1?!1:xVn.includes(t.nodeName)||t.hasAttribute("contenteditable")||!!t.closest(".nokey")}const k0t=e=>"clientX"in e,fg=(e,t)=>{const n=k0t(e),r=n?e.clientX:e.touches?.[0].clientX,s=n?e.clientY:e.touches?.[0].clientY;return{x:r-(t?.left??0),y:s-(t?.top??0)}},B9e=(e,t,n,r,s)=>{const a=t.querySelectorAll(`.${e}`);return!a||!a.length?null:Array.from(a).map(i=>{const l=i.getBoundingClientRect();return{id:i.getAttribute("data-handleid"),type:e,nodeId:s,position:i.getAttribute("data-handlepos"),x:(l.left-n.left)/r,y:(l.top-n.top)/r,...w1e(i)}})};function O0t({sourceX:e,sourceY:t,targetX:n,targetY:r,sourceControlX:s,sourceControlY:a,targetControlX:i,targetControlY:l}){const c=e*.125+s*.375+i*.375+n*.125,u=t*.125+a*.375+l*.375+r*.125,d=Math.abs(c-e),f=Math.abs(u-t);return[c,u,d,f]}function T6(e,t){return e>=0?.5*e:t*25*Math.sqrt(-e)}function U9e({pos:e,x1:t,y1:n,x2:r,y2:s,c:a}){switch(e){case nr.Left:return[t-T6(t-r,a),n];case nr.Right:return[t+T6(r-t,a),n];case nr.Top:return[t,n-T6(n-s,a)];case nr.Bottom:return[t,n+T6(s-n,a)]}}function S1e({sourceX:e,sourceY:t,sourcePosition:n=nr.Bottom,targetX:r,targetY:s,targetPosition:a=nr.Top,curvature:i=.25}){const[l,c]=U9e({pos:n,x1:e,y1:t,x2:r,y2:s,c:i}),[u,d]=U9e({pos:a,x1:r,y1:s,x2:e,y2:t,c:i}),[f,p,h,m]=O0t({sourceX:e,sourceY:t,targetX:r,targetY:s,sourceControlX:l,sourceControlY:c,targetControlX:u,targetControlY:d});return[`M${e},${t} C${l},${c} ${u},${d} ${r},${s}`,f,p,h,m]}function _0t({sourceX:e,sourceY:t,targetX:n,targetY:r}){const s=Math.abs(n-e)/2,a=n<e?n+s:n-s,i=Math.abs(r-t)/2,l=r<t?r+i:r-i;return[a,l,s,i]}function wVn({sourceNode:e,targetNode:t,selected:n=!1,zIndex:r=0,elevateOnSelect:s=!1,zIndexMode:a="basic"}){if(a==="manual")return r;const i=s&&n?r+1e3:r,l=Math.max(e.parentId||s&&e.selected?e.internals.z:0,t.parentId||s&&t.selected?t.internals.z:0);return i+l}function SVn({sourceNode:e,targetNode:t,width:n,height:r,transform:s}){const a=PV(D7(e),D7(t));a.x===a.x2&&(a.x2+=1),a.y===a.y2&&(a.y2+=1);const i={x:-s[0]/s[2],y:-s[1]/s[2],width:n/s[2],height:r/s[2]};return oM(i,$V(a))>0}const kVn=({source:e,sourceHandle:t,target:n,targetHandle:r})=>`xy-edge__${e}${t||""}-${n}${r||""}`,OVn=(e,t)=>t.some(n=>n.source===e.source&&n.target===e.target&&(n.sourceHandle===e.sourceHandle||!n.sourceHandle&&!e.sourceHandle)&&(n.targetHandle===e.targetHandle||!n.targetHandle&&!e.targetHandle)),_Vn=(e,t,n={})=>{if(!e.source||!e.target)return t;const r=n.getEdgeId||kVn;let s;return h0t(e)?s={...e}:s={...e,id:r(e)},OVn(s,t)?t:(s.sourceHandle===null&&delete s.sourceHandle,s.targetHandle===null&&delete s.targetHandle,t.concat(s))};function C0t({sourceX:e,sourceY:t,targetX:n,targetY:r}){const[s,a,i,l]=_0t({sourceX:e,sourceY:t,targetX:n,targetY:r});return[`M ${e},${t}L ${n},${r}`,s,a,i,l]}const q9e={[nr.Left]:{x:-1,y:0},[nr.Right]:{x:1,y:0},[nr.Top]:{x:0,y:-1},[nr.Bottom]:{x:0,y:1}},CVn=({source:e,sourcePosition:t=nr.Bottom,target:n})=>t===nr.Left||t===nr.Right?e.x<n.x?{x:1,y:0}:{x:-1,y:0}:e.y<n.y?{x:0,y:1}:{x:0,y:-1},V9e=(e,t)=>Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2));function EVn({source:e,sourcePosition:t=nr.Bottom,target:n,targetPosition:r=nr.Top,center:s,offset:a,stepPosition:i}){const l=q9e[t],c=q9e[r],u={x:e.x+l.x*a,y:e.y+l.y*a},d={x:n.x+c.x*a,y:n.y+c.y*a},f=CVn({source:u,sourcePosition:t,target:d}),p=f.x!==0?"x":"y",h=f[p];let m=[],v,y;const b={x:0,y:0},S={x:0,y:0},[,,w,k]=_0t({sourceX:e.x,sourceY:e.y,targetX:n.x,targetY:n.y});if(l[p]*c[p]===-1){p==="x"?(v=s.x??u.x+(d.x-u.x)*i,y=s.y??(u.y+d.y)/2):(v=s.x??(u.x+d.x)/2,y=s.y??u.y+(d.y-u.y)*i);const j=[{x:v,y:u.y},{x:v,y:d.y}],N=[{x:u.x,y},{x:d.x,y}];l[p]===h?m=p==="x"?j:N:m=p==="x"?N:j}else{const j=[{x:u.x,y:d.y}],N=[{x:d.x,y:u.y}];if(p==="x"?m=l.x===h?N:j:m=l.y===h?j:N,t===r){const M=Math.abs(e[p]-n[p]);if(M<=a){const q=Math.min(a-1,a-M);l[p]===h?b[p]=(u[p]>e[p]?-1:1)*q:S[p]=(d[p]>n[p]?-1:1)*q}}if(t!==r){const M=p==="x"?"y":"x",q=l[p]===c[M],H=u[M]>d[M],F=u[M]<d[M];(l[p]===1&&(!q&&H||q&&F)||l[p]!==1&&(!q&&F||q&&H))&&(m=p==="x"?j:N)}const I={x:u.x+b.x,y:u.y+b.y},R={x:d.x+S.x,y:d.y+S.y},P=Math.max(Math.abs(I.x-m[0].x),Math.abs(R.x-m[0].x)),L=Math.max(Math.abs(I.y-m[0].y),Math.abs(R.y-m[0].y));P>=L?(v=(I.x+R.x)/2,y=m[0].y):(v=m[0].x,y=(I.y+R.y)/2)}const _={x:u.x+b.x,y:u.y+b.y},C={x:d.x+S.x,y:d.y+S.y};return[[e,..._.x!==m[0].x||_.y!==m[0].y?[_]:[],...m,...C.x!==m[m.length-1].x||C.y!==m[m.length-1].y?[C]:[],n],v,y,w,k]}function jVn(e,t,n,r){const s=Math.min(V9e(e,t)/2,V9e(t,n)/2,r),{x:a,y:i}=t;if(e.x===a&&a===n.x||e.y===i&&i===n.y)return`L${a} ${i}`;if(e.y===i){const u=e.x<n.x?-1:1,d=e.y<n.y?1:-1;return`L ${a+s*u},${i}Q ${a},${i} ${a},${i+s*d}`}const l=e.x<n.x?1:-1,c=e.y<n.y?-1:1;return`L ${a},${i+s*c}Q ${a},${i} ${a+s*l},${i}`}function Ahe({sourceX:e,sourceY:t,sourcePosition:n=nr.Bottom,targetX:r,targetY:s,targetPosition:a=nr.Top,borderRadius:i=5,centerX:l,centerY:c,offset:u=20,stepPosition:d=.5}){const[f,p,h,m,v]=EVn({source:{x:e,y:t},sourcePosition:n,target:{x:r,y:s},targetPosition:a,center:{x:l,y:c},offset:u,stepPosition:d});let y=`M${f[0].x} ${f[0].y}`;for(let b=1;b<f.length-1;b++)y+=jVn(f[b-1],f[b],f[b+1],i);return y+=`L${f[f.length-1].x} ${f[f.length-1].y}`,[y,p,h,m,v]}function H9e(e){return e&&!!(e.internals.handleBounds||e.handles?.length)&&!!(e.measured.width||e.width||e.initialWidth)}function TVn(e){const{sourceNode:t,targetNode:n}=e;if(!H9e(t)||!H9e(n))return null;const r=t.internals.handleBounds||W9e(t.handles),s=n.internals.handleBounds||W9e(n.handles),a=Z9e(r?.source??[],e.sourceHandle),i=Z9e(e.connectionMode===kT.Strict?s?.target??[]:(s?.target??[]).concat(s?.source??[]),e.targetHandle);if(!a||!i)return e.onError?.("008",hy.error008(a?"target":"source",{id:e.id,sourceHandle:e.sourceHandle,targetHandle:e.targetHandle})),null;const l=a?.position||nr.Bottom,c=i?.position||nr.Top,u=LO(t,a,l),d=LO(n,i,c);return{sourceX:u.x,sourceY:u.y,targetX:d.x,targetY:d.y,sourcePosition:l,targetPosition:c}}function W9e(e){if(!e)return null;const t=[],n=[];for(const r of e)r.width=r.width??1,r.height=r.height??1,r.type==="source"?t.push(r):r.type==="target"&&n.push(r);return{source:t,target:n}}function LO(e,t,n=nr.Left,r=!1){const s=(t?.x??0)+e.internals.positionAbsolute.x,a=(t?.y??0)+e.internals.positionAbsolute.y,{width:i,height:l}=t??Gx(e);if(r)return{x:s+i/2,y:a+l/2};switch(t?.position??n){case nr.Top:return{x:s+i/2,y:a};case nr.Right:return{x:s+i,y:a+l/2};case nr.Bottom:return{x:s+i/2,y:a+l};case nr.Left:return{x:s,y:a+l/2}}}function Z9e(e,t){return e&&(t?e.find(n=>n.id===t):e[0])||null}function Rhe(e,t){return e?typeof e=="string"?e:`${t?`${t}__`:""}${Object.keys(e).sort().map(r=>`${r}=${e[r]}`).join("&")}`:""}function NVn(e,{id:t,defaultColor:n,defaultMarkerStart:r,defaultMarkerEnd:s}){const a=new Set;return e.reduce((i,l)=>([l.markerStart||r,l.markerEnd||s].forEach(c=>{if(c&&typeof c=="object"){const u=Rhe(c,t);a.has(u)||(i.push({id:u,color:c.color||n,...c}),a.add(u))}}),i),[]).sort((i,l)=>i.id.localeCompare(l.id))}const E0t=1e3,IVn=10,k1e={nodeOrigin:[0,0],nodeExtent:sM,elevateNodesOnSelect:!0,zIndexMode:"basic",defaults:{}},AVn={...k1e,checkEquality:!0};function O1e(e,t){const n={...e};for(const r in t)t[r]!==void 0&&(n[r]=t[r]);return n}function RVn(e,t,n){const r=O1e(k1e,n);for(const s of e.values())if(s.parentId)C1e(s,e,t,r);else{const a=m3(s,r.nodeOrigin),i=CT(s.extent)?s.extent:r.nodeExtent,l=DO(a,i,Gx(s));s.internals.positionAbsolute=l}}function PVn(e,t){if(!e.handles)return e.measured?t?.internals.handleBounds:void 0;const n=[],r=[];for(const s of e.handles){const a={id:s.id,width:s.width??1,height:s.height??1,nodeId:e.id,x:s.x,y:s.y,position:s.position,type:s.type};s.type==="source"?n.push(a):s.type==="target"&&r.push(a)}return{source:n,target:r}}function _1e(e){return e==="manual"}function Phe(e,t,n,r={}){const s=O1e(AVn,r),a={i:0},i=new Map(t),l=s?.elevateNodesOnSelect&&!_1e(s.zIndexMode)?E0t:0;let c=e.length>0,u=!1;t.clear(),n.clear();for(const d of e){let f=i.get(d.id);if(s.checkEquality&&d===f?.internals.userNode)t.set(d.id,f);else{const p=m3(d,s.nodeOrigin),h=CT(d.extent)?d.extent:s.nodeExtent,m=DO(p,h,Gx(d));f={...s.defaults,...d,measured:{width:d.measured?.width,height:d.measured?.height},internals:{positionAbsolute:m,handleBounds:PVn(d,f),z:j0t(d,l,s.zIndexMode),userNode:d}},t.set(d.id,f)}(f.measured===void 0||f.measured.width===void 0||f.measured.height===void 0)&&!f.hidden&&(c=!1),d.parentId&&C1e(f,t,n,r,a),u||=d.selected??!1}return{nodesInitialized:c,hasSelectedNodes:u}}function $Vn(e,t){if(!e.parentId)return;const n=t.get(e.parentId);n?n.set(e.id,e):t.set(e.parentId,new Map([[e.id,e]]))}function C1e(e,t,n,r,s){const{elevateNodesOnSelect:a,nodeOrigin:i,nodeExtent:l,zIndexMode:c}=O1e(k1e,r),u=e.parentId,d=t.get(u);if(!d){console.warn(`Parent node ${u} not found. Please make sure that parent nodes are in front of their child nodes in the nodes array.`);return}$Vn(e,n),s&&!d.parentId&&d.internals.rootParentIndex===void 0&&c==="auto"&&(d.internals.rootParentIndex=++s.i,d.internals.z=d.internals.z+s.i*IVn),s&&d.internals.rootParentIndex!==void 0&&(s.i=d.internals.rootParentIndex);const f=a&&!_1e(c)?E0t:0,{x:p,y:h,z:m}=MVn(e,d,i,l,f,c),{positionAbsolute:v}=e.internals,y=p!==v.x||h!==v.y;(y||m!==e.internals.z)&&t.set(e.id,{...e,internals:{...e.internals,positionAbsolute:y?{x:p,y:h}:v,z:m}})}function j0t(e,t,n){const r=dg(e.zIndex)?e.zIndex:0;return _1e(n)?r:r+(e.selected?t:0)}function MVn(e,t,n,r,s,a){const{x:i,y:l}=t.internals.positionAbsolute,c=Gx(e),u=m3(e,n),d=CT(e.extent)?DO(u,e.extent,c):u;let f=DO({x:i+d.x,y:l+d.y},r,c);e.extent==="parent"&&(f=g0t(f,c,t));const p=j0t(e,s,a),h=t.internals.z??0;return{x:f.x,y:f.y,z:h>=p?h+1:p}}function E1e(e,t,n,r=[0,0]){const s=[],a=new Map;for(const i of e){const l=t.get(i.parentId);if(!l)continue;const c=a.get(i.parentId)?.expandedRect??_T(l),u=y0t(c,i.rect);a.set(i.parentId,{expandedRect:u,parent:l})}return a.size>0&&a.forEach(({expandedRect:i,parent:l},c)=>{const u=l.internals.positionAbsolute,d=Gx(l),f=l.origin??r,p=i.x<u.x?Math.round(Math.abs(u.x-i.x)):0,h=i.y<u.y?Math.round(Math.abs(u.y-i.y)):0,m=Math.max(d.width,Math.round(i.width)),v=Math.max(d.height,Math.round(i.height)),y=(m-d.width)*f[0],b=(v-d.height)*f[1];(p>0||h>0||y||b)&&(s.push({id:c,type:"position",position:{x:l.position.x-p+y,y:l.position.y-h+b}}),n.get(c)?.forEach(S=>{e.some(w=>w.id===S.id)||s.push({id:S.id,type:"position",position:{x:S.position.x+p,y:S.position.y+h}})})),(d.width<i.width||d.height<i.height||p||h)&&s.push({id:c,type:"dimensions",setAttributes:!0,dimensions:{width:m+(p?f[0]*p-y:0),height:v+(h?f[1]*h-b:0)}})}),s}function DVn(e,t,n,r,s,a,i){const l=r?.querySelector(".xyflow__viewport");let c=!1;if(!l)return{changes:[],updatedInternals:c};const u=[],d=window.getComputedStyle(l),{m22:f}=new window.DOMMatrixReadOnly(d.transform),p=[];for(const h of e.values()){const m=t.get(h.id);if(!m)continue;if(m.hidden){t.set(m.id,{...m,internals:{...m.internals,handleBounds:void 0}}),c=!0;continue}const v=w1e(h.nodeElement),y=m.measured.width!==v.width||m.measured.height!==v.height;if(!!(v.width&&v.height&&(y||!m.internals.handleBounds||h.force))){const S=h.nodeElement.getBoundingClientRect(),w=CT(m.extent)?m.extent:a;let{positionAbsolute:k}=m.internals;m.parentId&&m.extent==="parent"?k=g0t(k,v,t.get(m.parentId)):w&&(k=DO(k,w,v));const _={...m,measured:v,internals:{...m.internals,positionAbsolute:k,handleBounds:{source:B9e("source",h.nodeElement,S,f,m.id),target:B9e("target",h.nodeElement,S,f,m.id)}}};t.set(m.id,_),m.parentId&&C1e(_,t,n,{nodeOrigin:s,zIndexMode:i}),c=!0,y&&(u.push({id:m.id,type:"dimensions",dimensions:v}),m.expandParent&&m.parentId&&p.push({id:m.id,parentId:m.parentId,rect:_T(_,s)}))}}if(p.length>0){const h=E1e(p,t,n,s);u.push(...h)}return{changes:u,updatedInternals:c}}async function LVn({delta:e,panZoom:t,transform:n,translateExtent:r,width:s,height:a}){if(!t||!e.x&&!e.y)return Promise.resolve(!1);const i=await t.setViewportConstrained({x:n[0]+e.x,y:n[1]+e.y,zoom:n[2]},[[0,0],[s,a]],r),l=!!i&&(i.x!==n[0]||i.y!==n[1]||i.k!==n[2]);return Promise.resolve(l)}function G9e(e,t,n,r,s,a){let i=s;const l=r.get(i)||new Map;r.set(i,l.set(n,t)),i=`${s}-${e}`;const c=r.get(i)||new Map;if(r.set(i,c.set(n,t)),a){i=`${s}-${e}-${a}`;const u=r.get(i)||new Map;r.set(i,u.set(n,t))}}function T0t(e,t,n){e.clear(),t.clear();for(const r of n){const{source:s,target:a,sourceHandle:i=null,targetHandle:l=null}=r,c={edgeId:r.id,source:s,target:a,sourceHandle:i,targetHandle:l},u=`${s}-${i}--${a}-${l}`,d=`${a}-${l}--${s}-${i}`;G9e("source",c,d,e,s,i),G9e("target",c,u,e,a,l),t.set(r.id,r)}}function N0t(e,t){if(!e.parentId)return!1;const n=t.get(e.parentId);return n?n.selected?!0:N0t(n,t):!1}function Q9e(e,t,n){let r=e;do{if(r?.matches?.(t))return!0;if(r===n)return!1;r=r?.parentElement}while(r);return!1}function FVn(e,t,n,r){const s=new Map;for(const[a,i]of e)if((i.selected||i.id===r)&&(!i.parentId||!N0t(i,e))&&(i.draggable||t&&typeof i.draggable>"u")){const l=e.get(a);l&&s.set(a,{id:a,position:l.position||{x:0,y:0},distance:{x:n.x-l.internals.positionAbsolute.x,y:n.y-l.internals.positionAbsolute.y},extent:l.extent,parentId:l.parentId,origin:l.origin,expandParent:l.expandParent,internals:{positionAbsolute:l.internals.positionAbsolute||{x:0,y:0}},measured:{width:l.measured.width??0,height:l.measured.height??0}})}return s}function GJ({nodeId:e,dragItems:t,nodeLookup:n,dragging:r=!0}){const s=[];for(const[i,l]of t){const c=n.get(i)?.internals.userNode;c&&s.push({...c,position:l.position,dragging:r})}if(!e)return[s[0],s];const a=n.get(e)?.internals.userNode;return[a?{...a,position:t.get(e)?.position||a.position,dragging:r}:s[0],s]}function zVn({dragItems:e,snapGrid:t,x:n,y:r}){const s=e.values().next().value;if(!s)return null;const a={x:n-s.distance.x,y:r-s.distance.y},i=v3(a,t);return{x:i.x-a.x,y:i.y-a.y}}function BVn({onNodeMouseDown:e,getStoreItems:t,onDragStart:n,onDrag:r,onDragStop:s}){let a={x:null,y:null},i=0,l=new Map,c=!1,u={x:0,y:0},d=null,f=!1,p=null,h=!1,m=!1,v=null;function y({noDragClassName:S,handleSelector:w,domNode:k,isSelectable:_,nodeId:C,nodeClickDistance:E=0}){p=gp(k);function j({x:P,y:L}){const{nodeLookup:M,nodeExtent:q,snapGrid:H,snapToGrid:F,nodeOrigin:z,onNodeDrag:B,onSelectionDrag:D,onError:Q,updateNodePositions:V}=t();a={x:P,y:L};let $=!1;const U=l.size>1,Z=U&&q?Ihe(g3(l)):null,X=U&&F?zVn({dragItems:l,snapGrid:H,x:P,y:L}):null;for(const[te,J]of l){if(!M.has(te))continue;let ee={x:P-J.distance.x,y:L-J.distance.y};F&&(ee=X?{x:Math.round(ee.x+X.x),y:Math.round(ee.y+X.y)}:v3(ee,H));let ae=null;if(U&&q&&!J.extent&&Z){const{positionAbsolute:ne}=J.internals,ue=ne.x-Z.x+q[0][0],pe=ne.x+J.measured.width-Z.x2+q[1][0],le=ne.y-Z.y+q[0][1],ve=ne.y+J.measured.height-Z.y2+q[1][1];ae=[[ue,le],[pe,ve]]}const{position:ce,positionAbsolute:Y}=m0t({nodeId:te,nextPosition:ee,nodeLookup:M,nodeExtent:ae||q,nodeOrigin:z,onError:Q});$=$||J.position.x!==ce.x||J.position.y!==ce.y,J.position=ce,J.internals.positionAbsolute=Y}if(m=m||$,!!$&&(V(l,!0),v&&(r||B||!C&&D))){const[te,J]=GJ({nodeId:C,dragItems:l,nodeLookup:M});r?.(v,l,te,J),B?.(v,te,J),C||D?.(v,J)}}async function N(){if(!d)return;const{transform:P,panBy:L,autoPanSpeed:M,autoPanOnNodeDrag:q}=t();if(!q){c=!1,cancelAnimationFrame(i);return}const[H,F]=v0t(u,d,M);(H!==0||F!==0)&&(a.x=(a.x??0)-H/P[2],a.y=(a.y??0)-F/P[2],await L({x:H,y:F})&&j(a)),i=requestAnimationFrame(N)}function I(P){const{nodeLookup:L,multiSelectionActive:M,nodesDraggable:q,transform:H,snapGrid:F,snapToGrid:z,selectNodesOnDrag:B,onNodeDragStart:D,onSelectionDragStart:Q,unselectNodesAndEdges:V}=t();f=!0,(!B||!_)&&!M&&C&&(L.get(C)?.selected||V()),_&&B&&C&&e?.(C);const $=V2(P.sourceEvent,{transform:H,snapGrid:F,snapToGrid:z,containerBounds:d});if(a=$,l=FVn(L,q,$,C),l.size>0&&(n||D||!C&&Q)){const[U,Z]=GJ({nodeId:C,dragItems:l,nodeLookup:L});n?.(P.sourceEvent,l,U,Z),D?.(P.sourceEvent,U,Z),C||Q?.(P.sourceEvent,Z)}}const R=Gxt().clickDistance(E).on("start",P=>{const{domNode:L,nodeDragThreshold:M,transform:q,snapGrid:H,snapToGrid:F}=t();d=L?.getBoundingClientRect()||null,h=!1,m=!1,v=P.sourceEvent,M===0&&I(P),a=V2(P.sourceEvent,{transform:q,snapGrid:H,snapToGrid:F,containerBounds:d}),u=fg(P.sourceEvent,d)}).on("drag",P=>{const{autoPanOnNodeDrag:L,transform:M,snapGrid:q,snapToGrid:H,nodeDragThreshold:F,nodeLookup:z}=t(),B=V2(P.sourceEvent,{transform:M,snapGrid:q,snapToGrid:H,containerBounds:d});if(v=P.sourceEvent,(P.sourceEvent.type==="touchmove"&&P.sourceEvent.touches.length>1||C&&!z.has(C))&&(h=!0),!h){if(!c&&L&&f&&(c=!0,N()),!f){const D=fg(P.sourceEvent,d),Q=D.x-u.x,V=D.y-u.y;Math.sqrt(Q*Q+V*V)>F&&I(P)}(a.x!==B.xSnapped||a.y!==B.ySnapped)&&l&&f&&(u=fg(P.sourceEvent,d),j(B))}}).on("end",P=>{if(!(!f||h)&&(c=!1,f=!1,cancelAnimationFrame(i),l.size>0)){const{nodeLookup:L,updateNodePositions:M,onNodeDragStop:q,onSelectionDragStop:H}=t();if(m&&(M(l,!1),m=!1),s||q||!C&&H){const[F,z]=GJ({nodeId:C,dragItems:l,nodeLookup:L,dragging:!1});s?.(P.sourceEvent,l,F,z),q?.(P.sourceEvent,F,z),C||H?.(P.sourceEvent,z)}}}).filter(P=>{const L=P.target;return!P.button&&(!S||!Q9e(L,`.${S}`,k))&&(!w||Q9e(L,w,k))});p.call(R)}function b(){p?.on(".drag",null)}return{update:y,destroy:b}}function UVn(e,t,n){const r=[],s={x:e.x-n,y:e.y-n,width:n*2,height:n*2};for(const a of t.values())oM(s,_T(a))>0&&r.push(a);return r}const qVn=250;function VVn(e,t,n,r){let s=[],a=1/0;const i=UVn(e,n,t+qVn);for(const l of i){const c=[...l.internals.handleBounds?.source??[],...l.internals.handleBounds?.target??[]];for(const u of c){if(r.nodeId===u.nodeId&&r.type===u.type&&r.id===u.id)continue;const{x:d,y:f}=LO(l,u,u.position,!0),p=Math.sqrt(Math.pow(d-e.x,2)+Math.pow(f-e.y,2));p>t||(p<a?(s=[{...u,x:d,y:f}],a=p):p===a&&s.push({...u,x:d,y:f}))}}if(!s.length)return null;if(s.length>1){const l=r.type==="source"?"target":"source";return s.find(c=>c.type===l)??s[0]}return s[0]}function I0t(e,t,n,r,s,a=!1){const i=r.get(e);if(!i)return null;const l=s==="strict"?i.internals.handleBounds?.[t]:[...i.internals.handleBounds?.source??[],...i.internals.handleBounds?.target??[]],c=(n?l?.find(u=>u.id===n):l?.[0])??null;return c&&a?{...c,...LO(i,c,c.position,!0)}:c}function A0t(e,t){return e||(t?.classList.contains("target")?"target":t?.classList.contains("source")?"source":null)}function HVn(e,t){let n=null;return t?n=!0:e&&!t&&(n=!1),n}const R0t=()=>!0;function WVn(e,{connectionMode:t,connectionRadius:n,handleId:r,nodeId:s,edgeUpdaterType:a,isTarget:i,domNode:l,nodeLookup:c,lib:u,autoPanOnConnect:d,flowId:f,panBy:p,cancelConnection:h,onConnectStart:m,onConnect:v,onConnectEnd:y,isValidConnection:b=R0t,onReconnectEnd:S,updateConnection:w,getTransform:k,getFromHandle:_,autoPanSpeed:C,dragThreshold:E=1,handleDomNode:j}){const N=w0t(e.target);let I=0,R;const{x:P,y:L}=fg(e),M=A0t(a,j),q=l?.getBoundingClientRect();let H=!1;if(!q||!M)return;const F=I0t(s,M,r,c,t);if(!F)return;let z=fg(e,q),B=!1,D=null,Q=!1,V=null;function $(){if(!d||!q)return;const[ce,Y]=v0t(z,q,C);p({x:ce,y:Y}),I=requestAnimationFrame($)}const U={...F,nodeId:s,type:M,position:F.position},Z=c.get(s);let te={inProgress:!0,isValid:null,from:LO(Z,U,nr.Left,!0),fromHandle:U,fromPosition:U.position,fromNode:Z,to:z,toHandle:null,toPosition:D9e[U.position],toNode:null,pointer:z};function J(){H=!0,w(te),m?.(e,{nodeId:s,handleId:r,handleType:M})}E===0&&J();function ee(ce){if(!H){const{x:ve,y:ye}=fg(ce),Se=ve-P,Ne=ye-L;if(!(Se*Se+Ne*Ne>E*E))return;J()}if(!_()||!U){ae(ce);return}const Y=k();z=fg(ce,q),R=VVn(y3(z,Y,!1,[1,1]),n,c,U),B||($(),B=!0);const ne=P0t(ce,{handle:R,connectionMode:t,fromNodeId:s,fromHandleId:r,fromType:i?"target":"source",isValidConnection:b,doc:N,lib:u,flowId:f,nodeLookup:c});V=ne.handleDomNode,D=ne.connection,Q=HVn(!!R,ne.isValid);const ue=c.get(s),pe=ue?LO(ue,U,nr.Left,!0):te.from,le={...te,from:pe,isValid:Q,to:ne.toHandle&&Q?L7({x:ne.toHandle.x,y:ne.toHandle.y},Y):z,toHandle:ne.toHandle,toPosition:Q&&ne.toHandle?ne.toHandle.position:D9e[U.position],toNode:ne.toHandle?c.get(ne.toHandle.nodeId):null,pointer:z};w(le),te=le}function ae(ce){if(!("touches"in ce&&ce.touches.length>0)){if(H){(R||V)&&D&&Q&&v?.(D);const{inProgress:Y,...ne}=te,ue={...ne,toPosition:te.toHandle?te.toPosition:null};y?.(ce,ue),a&&S?.(ce,ue)}h(),cancelAnimationFrame(I),B=!1,Q=!1,D=null,V=null,N.removeEventListener("mousemove",ee),N.removeEventListener("mouseup",ae),N.removeEventListener("touchmove",ee),N.removeEventListener("touchend",ae)}}N.addEventListener("mousemove",ee),N.addEventListener("mouseup",ae),N.addEventListener("touchmove",ee),N.addEventListener("touchend",ae)}function P0t(e,{handle:t,connectionMode:n,fromNodeId:r,fromHandleId:s,fromType:a,doc:i,lib:l,flowId:c,isValidConnection:u=R0t,nodeLookup:d}){const f=a==="target",p=t?i.querySelector(`.${l}-flow__handle[data-id="${c}-${t?.nodeId}-${t?.id}-${t?.type}"]`):null,{x:h,y:m}=fg(e),v=i.elementFromPoint(h,m),y=v?.classList.contains(`${l}-flow__handle`)?v:p,b={handleDomNode:y,isValid:!1,connection:null,toHandle:null};if(y){const S=A0t(void 0,y),w=y.getAttribute("data-nodeid"),k=y.getAttribute("data-handleid"),_=y.classList.contains("connectable"),C=y.classList.contains("connectableend");if(!w||!S)return b;const E={source:f?w:r,sourceHandle:f?k:s,target:f?r:w,targetHandle:f?s:k};b.connection=E;const N=_&&C&&(n===kT.Strict?f&&S==="source"||!f&&S==="target":w!==r||k!==s);b.isValid=N&&u(E),b.toHandle=I0t(w,S,k,d,n,!0)}return b}const $he={onPointerDown:WVn,isValid:P0t};function ZVn({domNode:e,panZoom:t,getTransform:n,getViewScale:r}){const s=gp(e);function a({translateExtent:l,width:c,height:u,zoomStep:d=1,pannable:f=!0,zoomable:p=!0,inversePan:h=!1}){const m=w=>{if(w.sourceEvent.type!=="wheel"||!t)return;const k=n(),_=w.sourceEvent.ctrlKey&&lM()?10:1,C=-w.sourceEvent.deltaY*(w.sourceEvent.deltaMode===1?.05:w.sourceEvent.deltaMode?1:.002)*d,E=k[2]*Math.pow(2,C*_);t.scaleTo(E)};let v=[0,0];const y=w=>{(w.sourceEvent.type==="mousedown"||w.sourceEvent.type==="touchstart")&&(v=[w.sourceEvent.clientX??w.sourceEvent.touches[0].clientX,w.sourceEvent.clientY??w.sourceEvent.touches[0].clientY])},b=w=>{const k=n();if(w.sourceEvent.type!=="mousemove"&&w.sourceEvent.type!=="touchmove"||!t)return;const _=[w.sourceEvent.clientX??w.sourceEvent.touches[0].clientX,w.sourceEvent.clientY??w.sourceEvent.touches[0].clientY],C=[_[0]-v[0],_[1]-v[1]];v=_;const E=r()*Math.max(k[2],Math.log(k[2]))*(h?-1:1),j={x:k[0]-C[0]*E,y:k[1]-C[1]*E},N=[[0,0],[c,u]];t.setViewportConstrained({x:j.x,y:j.y,zoom:k[2]},N,l)},S=c0t().on("start",y).on("zoom",f?b:null).on("zoom.wheel",p?m:null);s.call(S,{})}function i(){s.on("zoom",null)}return{update:a,destroy:i,pointer:Jm}}const MV=e=>({x:e.x,y:e.y,zoom:e.k}),QJ=({x:e,y:t,zoom:n})=>RV.translate(e,t).scale(n),HE=(e,t)=>e.target.closest(`.${t}`),$0t=(e,t)=>t===2&&Array.isArray(e)&&e.includes(2),GVn=e=>((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2,YJ=(e,t=0,n=GVn,r=()=>{})=>{const s=typeof t=="number"&&t>0;return s||r(),s?e.transition().duration(t).ease(n).on("end",r):e},M0t=e=>{const t=e.ctrlKey&&lM()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*t};function QVn({zoomPanValues:e,noWheelClassName:t,d3Selection:n,d3Zoom:r,panOnScrollMode:s,panOnScrollSpeed:a,zoomOnPinch:i,onPanZoomStart:l,onPanZoom:c,onPanZoomEnd:u}){return d=>{if(HE(d,t))return d.ctrlKey&&d.preventDefault(),!1;d.preventDefault(),d.stopImmediatePropagation();const f=n.property("__zoom").k||1;if(d.ctrlKey&&i){const y=Jm(d),b=M0t(d),S=f*Math.pow(2,b);r.scaleTo(n,S,y,d);return}const p=d.deltaMode===1?20:1;let h=s===Zk.Vertical?0:d.deltaX*p,m=s===Zk.Horizontal?0:d.deltaY*p;!lM()&&d.shiftKey&&s!==Zk.Vertical&&(h=d.deltaY*p,m=0),r.translateBy(n,-(h/f)*a,-(m/f)*a,{internal:!0});const v=MV(n.property("__zoom"));clearTimeout(e.panScrollTimeout),e.isPanScrolling?(c?.(d,v),e.panScrollTimeout=setTimeout(()=>{u?.(d,v),e.isPanScrolling=!1},150)):(e.isPanScrolling=!0,l?.(d,v))}}function YVn({noWheelClassName:e,preventScrolling:t,d3ZoomHandler:n}){return function(r,s){const a=r.type==="wheel",i=!t&&a&&!r.ctrlKey,l=HE(r,e);if(r.ctrlKey&&a&&l&&r.preventDefault(),i||l)return null;r.preventDefault(),n.call(this,r,s)}}function XVn({zoomPanValues:e,onDraggingChange:t,onPanZoomStart:n}){return r=>{if(r.sourceEvent?.internal)return;const s=MV(r.transform);e.mouseButton=r.sourceEvent?.button||0,e.isZoomingOrPanning=!0,e.prevViewport=s,r.sourceEvent?.type==="mousedown"&&t(!0),n&&n?.(r.sourceEvent,s)}}function KVn({zoomPanValues:e,panOnDrag:t,onPaneContextMenu:n,onTransformChange:r,onPanZoom:s}){return a=>{e.usedRightMouseButton=!!(n&&$0t(t,e.mouseButton??0)),a.sourceEvent?.sync||r([a.transform.x,a.transform.y,a.transform.k]),s&&!a.sourceEvent?.internal&&s?.(a.sourceEvent,MV(a.transform))}}function JVn({zoomPanValues:e,panOnDrag:t,panOnScroll:n,onDraggingChange:r,onPanZoomEnd:s,onPaneContextMenu:a}){return i=>{if(!i.sourceEvent?.internal&&(e.isZoomingOrPanning=!1,a&&$0t(t,e.mouseButton??0)&&!e.usedRightMouseButton&&i.sourceEvent&&a(i.sourceEvent),e.usedRightMouseButton=!1,r(!1),s)){const l=MV(i.transform);e.prevViewport=l,clearTimeout(e.timerId),e.timerId=setTimeout(()=>{s?.(i.sourceEvent,l)},n?150:0)}}}function eHn({zoomActivationKeyPressed:e,zoomOnScroll:t,zoomOnPinch:n,panOnDrag:r,panOnScroll:s,zoomOnDoubleClick:a,userSelectionActive:i,noWheelClassName:l,noPanClassName:c,lib:u,connectionInProgress:d}){return f=>{const p=e||t,h=n&&f.ctrlKey,m=f.type==="wheel";if(f.button===1&&f.type==="mousedown"&&(HE(f,`${u}-flow__node`)||HE(f,`${u}-flow__edge`)))return!0;if(!r&&!p&&!s&&!a&&!n||i||d&&!m||HE(f,l)&&m||HE(f,c)&&(!m||s&&m&&!e)||!n&&f.ctrlKey&&m)return!1;if(!n&&f.type==="touchstart"&&f.touches?.length>1)return f.preventDefault(),!1;if(!p&&!s&&!h&&m||!r&&(f.type==="mousedown"||f.type==="touchstart")||Array.isArray(r)&&!r.includes(f.button)&&f.type==="mousedown")return!1;const v=Array.isArray(r)&&r.includes(f.button)||!f.button||f.button<=1;return(!f.ctrlKey||m)&&v}}function tHn({domNode:e,minZoom:t,maxZoom:n,translateExtent:r,viewport:s,onPanZoom:a,onPanZoomStart:i,onPanZoomEnd:l,onDraggingChange:c}){const u={isZoomingOrPanning:!1,usedRightMouseButton:!1,prevViewport:{},mouseButton:0,timerId:void 0,panScrollTimeout:void 0,isPanScrolling:!1},d=e.getBoundingClientRect(),f=c0t().scaleExtent([t,n]).translateExtent(r),p=gp(e).call(f);S({x:s.x,y:s.y,zoom:OT(s.zoom,t,n)},[[0,0],[d.width,d.height]],r);const h=p.on("wheel.zoom"),m=p.on("dblclick.zoom");f.wheelDelta(M0t);function v(R,P){return p?new Promise(L=>{f?.interpolate(P?.interpolate==="linear"?ix:JF).transform(YJ(p,P?.duration,P?.ease,()=>L(!0)),R)}):Promise.resolve(!1)}function y({noWheelClassName:R,noPanClassName:P,onPaneContextMenu:L,userSelectionActive:M,panOnScroll:q,panOnDrag:H,panOnScrollMode:F,panOnScrollSpeed:z,preventScrolling:B,zoomOnPinch:D,zoomOnScroll:Q,zoomOnDoubleClick:V,zoomActivationKeyPressed:$,lib:U,onTransformChange:Z,connectionInProgress:X,paneClickDistance:te,selectionOnDrag:J}){M&&!u.isZoomingOrPanning&&b();const ee=q&&!$&&!M;f.clickDistance(J?1/0:!dg(te)||te<0?0:te);const ae=ee?QVn({zoomPanValues:u,noWheelClassName:R,d3Selection:p,d3Zoom:f,panOnScrollMode:F,panOnScrollSpeed:z,zoomOnPinch:D,onPanZoomStart:i,onPanZoom:a,onPanZoomEnd:l}):YVn({noWheelClassName:R,preventScrolling:B,d3ZoomHandler:h});if(p.on("wheel.zoom",ae,{passive:!1}),!M){const Y=XVn({zoomPanValues:u,onDraggingChange:c,onPanZoomStart:i});f.on("start",Y);const ne=KVn({zoomPanValues:u,panOnDrag:H,onPaneContextMenu:!!L,onPanZoom:a,onTransformChange:Z});f.on("zoom",ne);const ue=JVn({zoomPanValues:u,panOnDrag:H,panOnScroll:q,onPaneContextMenu:L,onPanZoomEnd:l,onDraggingChange:c});f.on("end",ue)}const ce=eHn({zoomActivationKeyPressed:$,panOnDrag:H,zoomOnScroll:Q,panOnScroll:q,zoomOnDoubleClick:V,zoomOnPinch:D,userSelectionActive:M,noPanClassName:P,noWheelClassName:R,lib:U,connectionInProgress:X});f.filter(ce),V?p.on("dblclick.zoom",m):p.on("dblclick.zoom",null)}function b(){f.on("zoom",null)}async function S(R,P,L){const M=QJ(R),q=f?.constrain()(M,P,L);return q&&await v(q),new Promise(H=>H(q))}async function w(R,P){const L=QJ(R);return await v(L,P),new Promise(M=>M(L))}function k(R){if(p){const P=QJ(R),L=p.property("__zoom");(L.k!==R.zoom||L.x!==R.x||L.y!==R.y)&&f?.transform(p,P,null,{sync:!0})}}function _(){const R=p?l0t(p.node()):{x:0,y:0,k:1};return{x:R.x,y:R.y,zoom:R.k}}function C(R,P){return p?new Promise(L=>{f?.interpolate(P?.interpolate==="linear"?ix:JF).scaleTo(YJ(p,P?.duration,P?.ease,()=>L(!0)),R)}):Promise.resolve(!1)}function E(R,P){return p?new Promise(L=>{f?.interpolate(P?.interpolate==="linear"?ix:JF).scaleBy(YJ(p,P?.duration,P?.ease,()=>L(!0)),R)}):Promise.resolve(!1)}function j(R){f?.scaleExtent(R)}function N(R){f?.translateExtent(R)}function I(R){const P=!dg(R)||R<0?0:R;f?.clickDistance(P)}return{update:y,destroy:b,setViewport:w,setViewportConstrained:S,getViewport:_,scaleTo:C,scaleBy:E,setScaleExtent:j,setTranslateExtent:N,syncViewport:k,setClickDistance:I}}var ET;(function(e){e.Line="line",e.Handle="handle"})(ET||(ET={}));function nHn({width:e,prevWidth:t,height:n,prevHeight:r,affectsX:s,affectsY:a}){const i=e-t,l=n-r,c=[i>0?1:i<0?-1:0,l>0?1:l<0?-1:0];return i&&s&&(c[0]=c[0]*-1),l&&a&&(c[1]=c[1]*-1),c}function Y9e(e){const t=e.includes("right")||e.includes("left"),n=e.includes("bottom")||e.includes("top"),r=e.includes("left"),s=e.includes("top");return{isHorizontal:t,isVertical:n,affectsX:r,affectsY:s}}function F0(e,t){return Math.max(0,t-e)}function z0(e,t){return Math.max(0,e-t)}function N6(e,t,n){return Math.max(0,t-e,e-n)}function X9e(e,t){return e?!t:t}function rHn(e,t,n,r,s,a,i,l){let{affectsX:c,affectsY:u}=t;const{isHorizontal:d,isVertical:f}=t,p=d&&f,{xSnapped:h,ySnapped:m}=n,{minWidth:v,maxWidth:y,minHeight:b,maxHeight:S}=r,{x:w,y:k,width:_,height:C,aspectRatio:E}=e;let j=Math.floor(d?h-e.pointerX:0),N=Math.floor(f?m-e.pointerY:0);const I=_+(c?-j:j),R=C+(u?-N:N),P=-a[0]*_,L=-a[1]*C;let M=N6(I,v,y),q=N6(R,b,S);if(i){let z=0,B=0;c&&j<0?z=F0(w+j+P,i[0][0]):!c&&j>0&&(z=z0(w+I+P,i[1][0])),u&&N<0?B=F0(k+N+L,i[0][1]):!u&&N>0&&(B=z0(k+R+L,i[1][1])),M=Math.max(M,z),q=Math.max(q,B)}if(l){let z=0,B=0;c&&j>0?z=z0(w+j,l[0][0]):!c&&j<0&&(z=F0(w+I,l[1][0])),u&&N>0?B=z0(k+N,l[0][1]):!u&&N<0&&(B=F0(k+R,l[1][1])),M=Math.max(M,z),q=Math.max(q,B)}if(s){if(d){const z=N6(I/E,b,S)*E;if(M=Math.max(M,z),i){let B=0;!c&&!u||c&&!u&&p?B=z0(k+L+I/E,i[1][1])*E:B=F0(k+L+(c?j:-j)/E,i[0][1])*E,M=Math.max(M,B)}if(l){let B=0;!c&&!u||c&&!u&&p?B=F0(k+I/E,l[1][1])*E:B=z0(k+(c?j:-j)/E,l[0][1])*E,M=Math.max(M,B)}}if(f){const z=N6(R*E,v,y)/E;if(q=Math.max(q,z),i){let B=0;!c&&!u||u&&!c&&p?B=z0(w+R*E+P,i[1][0])/E:B=F0(w+(u?N:-N)*E+P,i[0][0])/E,q=Math.max(q,B)}if(l){let B=0;!c&&!u||u&&!c&&p?B=F0(w+R*E,l[1][0])/E:B=z0(w+(u?N:-N)*E,l[0][0])/E,q=Math.max(q,B)}}}N=N+(N<0?q:-q),j=j+(j<0?M:-M),s&&(p?I>R*E?N=(X9e(c,u)?-j:j)/E:j=(X9e(c,u)?-N:N)*E:d?(N=j/E,u=c):(j=N*E,c=u));const H=c?w+j:w,F=u?k+N:k;return{width:_+(c?-j:j),height:C+(u?-N:N),x:a[0]*j*(c?-1:1)+H,y:a[1]*N*(u?-1:1)+F}}const D0t={width:0,height:0,x:0,y:0},sHn={...D0t,pointerX:0,pointerY:0,aspectRatio:1};function aHn(e){return[[0,0],[e.measured.width,e.measured.height]]}function iHn(e,t,n){const r=t.position.x+e.position.x,s=t.position.y+e.position.y,a=e.measured.width??0,i=e.measured.height??0,l=n[0]*a,c=n[1]*i;return[[r-l,s-c],[r+a-l,s+i-c]]}function oHn({domNode:e,nodeId:t,getStoreItems:n,onChange:r,onEnd:s}){const a=gp(e);let i={controlDirection:Y9e("bottom-right"),boundaries:{minWidth:0,minHeight:0,maxWidth:Number.MAX_VALUE,maxHeight:Number.MAX_VALUE},resizeDirection:void 0,keepAspectRatio:!1};function l({controlPosition:u,boundaries:d,keepAspectRatio:f,resizeDirection:p,onResizeStart:h,onResize:m,onResizeEnd:v,shouldResize:y}){let b={...D0t},S={...sHn};i={boundaries:d,resizeDirection:p,keepAspectRatio:f,controlDirection:Y9e(u)};let w,k=null,_=[],C,E,j,N=!1;const I=Gxt().on("start",R=>{const{nodeLookup:P,transform:L,snapGrid:M,snapToGrid:q,nodeOrigin:H,paneDomNode:F}=n();if(w=P.get(t),!w)return;k=F?.getBoundingClientRect()??null;const{xSnapped:z,ySnapped:B}=V2(R.sourceEvent,{transform:L,snapGrid:M,snapToGrid:q,containerBounds:k});b={width:w.measured.width??0,height:w.measured.height??0,x:w.position.x??0,y:w.position.y??0},S={...b,pointerX:z,pointerY:B,aspectRatio:b.width/b.height},C=void 0,w.parentId&&(w.extent==="parent"||w.expandParent)&&(C=P.get(w.parentId),E=C&&w.extent==="parent"?aHn(C):void 0),_=[],j=void 0;for(const[D,Q]of P)if(Q.parentId===t&&(_.push({id:D,position:{...Q.position},extent:Q.extent}),Q.extent==="parent"||Q.expandParent)){const V=iHn(Q,w,Q.origin??H);j?j=[[Math.min(V[0][0],j[0][0]),Math.min(V[0][1],j[0][1])],[Math.max(V[1][0],j[1][0]),Math.max(V[1][1],j[1][1])]]:j=V}h?.(R,{...b})}).on("drag",R=>{const{transform:P,snapGrid:L,snapToGrid:M,nodeOrigin:q}=n(),H=V2(R.sourceEvent,{transform:P,snapGrid:L,snapToGrid:M,containerBounds:k}),F=[];if(!w)return;const{x:z,y:B,width:D,height:Q}=b,V={},$=w.origin??q,{width:U,height:Z,x:X,y:te}=rHn(S,i.controlDirection,H,i.boundaries,i.keepAspectRatio,$,E,j),J=U!==D,ee=Z!==Q,ae=X!==z&&J,ce=te!==B&ⅇif(!ae&&!ce&&!J&&!ee)return;if((ae||ce||$[0]===1||$[1]===1)&&(V.x=ae?X:b.x,V.y=ce?te:b.y,b.x=V.x,b.y=V.y,_.length>0)){const pe=X-z,le=te-B;for(const ve of _)ve.position={x:ve.position.x-pe+$[0]*(U-D),y:ve.position.y-le+$[1]*(Z-Q)},F.push(ve)}if((J||ee)&&(V.width=J&&(!i.resizeDirection||i.resizeDirection==="horizontal")?U:b.width,V.height=ee&&(!i.resizeDirection||i.resizeDirection==="vertical")?Z:b.height,b.width=V.width,b.height=V.height),C&&w.expandParent){const pe=$[0]*(V.width??0);V.x&&V.x<pe&&(b.x=pe,S.x=S.x-(V.x-pe));const le=$[1]*(V.height??0);V.y&&V.y<le&&(b.y=le,S.y=S.y-(V.y-le))}const Y=nHn({width:b.width,prevWidth:D,height:b.height,prevHeight:Q,affectsX:i.controlDirection.affectsX,affectsY:i.controlDirection.affectsY}),ne={...b,direction:Y};y?.(R,ne)!==!1&&(N=!0,m?.(R,ne),r(V,F))}).on("end",R=>{N&&(v?.(R,{...b}),s?.({...b}),N=!1)});a.call(I)}function c(){a.on(".drag",null)}return{update:l,destroy:c}}const lHn={},K9e=e=>{let t;const n=new Set,r=(d,f)=>{const p=typeof d=="function"?d(t):d;if(!Object.is(p,t)){const h=t;t=f??(typeof p!="object"||p===null)?p:Object.assign({},t,p),n.forEach(m=>m(t,h))}},s=()=>t,c={setState:r,getState:s,getInitialState:()=>u,subscribe:d=>(n.add(d),()=>n.delete(d)),destroy:()=>{(lHn?"production":void 0)!=="production"&&console.warn("[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected."),n.clear()}},u=t=e(r,s,c);return c},cHn=e=>e?K9e(e):K9e,{useDebugValue:uHn}=Le,{useSyncExternalStoreWithSelector:dHn}=$wn,fHn=e=>e;function L0t(e,t=fHn,n){const r=dHn(e.subscribe,e.getState,e.getServerState||e.getInitialState,t,n);return uHn(r),r}const J9e=(e,t)=>{const n=cHn(e),r=(s,a=t)=>L0t(n,s,a);return Object.assign(r,n),r},pHn=(e,t)=>e?J9e(e,t):J9e;function no(e,t){if(Object.is(e,t))return!0;if(typeof e!="object"||e===null||typeof t!="object"||t===null)return!1;if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(const[r,s]of e)if(!Object.is(s,t.get(r)))return!1;return!0}if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(const r of e)if(!t.has(r))return!1;return!0}const n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(const r of n)if(!Object.prototype.hasOwnProperty.call(t,r)||!Object.is(e[r],t[r]))return!1;return!0}const DV=g.createContext(null),hHn=DV.Provider,F0t=hy.error001();function Us(e,t){const n=g.useContext(DV);if(n===null)throw new Error(F0t);return L0t(n,e,t)}function So(){const e=g.useContext(DV);if(e===null)throw new Error(F0t);return g.useMemo(()=>({getState:e.getState,setState:e.setState,subscribe:e.subscribe}),[e])}const eFe={display:"none"},mHn={position:"absolute",width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0px, 0px, 0px, 0px)",clipPath:"inset(100%)"},z0t="react-flow__node-desc",B0t="react-flow__edge-desc",gHn="react-flow__aria-live",vHn=e=>e.ariaLiveMessage,yHn=e=>e.ariaLabelConfig;function bHn({rfId:e}){const t=Us(vHn);return o.jsx("div",{id:`${gHn}-${e}`,"aria-live":"assertive","aria-atomic":"true",style:mHn,children:t})}function xHn({rfId:e,disableKeyboardA11y:t}){const n=Us(yHn);return o.jsxs(o.Fragment,{children:[o.jsx("div",{id:`${z0t}-${e}`,style:eFe,children:t?n["node.a11yDescription.default"]:n["node.a11yDescription.keyboardDisabled"]}),o.jsx("div",{id:`${B0t}-${e}`,style:eFe,children:n["edge.a11yDescription.default"]}),!t&&o.jsx(bHn,{rfId:e})]})}const b3=g.forwardRef(({position:e="top-left",children:t,className:n,style:r,...s},a)=>{const i=`${e}`.split("-");return o.jsx("div",{className:Ml(["react-flow__panel",n,...i]),style:r,ref:a,...s,children:t})});b3.displayName="Panel";function wHn({proOptions:e,position:t="bottom-right"}){return e?.hideAttribution?null:o.jsx(b3,{position:t,className:"react-flow__attribution","data-message":"Please only hide this attribution when you are subscribed to React Flow Pro: https://pro.reactflow.dev",children:o.jsx("a",{href:"https://reactflow.dev",target:"_blank",rel:"noopener noreferrer","aria-label":"React Flow attribution",children:"React Flow"})})}const SHn=e=>{const t=[],n=[];for(const[,r]of e.nodeLookup)r.selected&&t.push(r.internals.userNode);for(const[,r]of e.edgeLookup)r.selected&&n.push(r);return{selectedNodes:t,selectedEdges:n}},I6=e=>e.id;function kHn(e,t){return no(e.selectedNodes.map(I6),t.selectedNodes.map(I6))&&no(e.selectedEdges.map(I6),t.selectedEdges.map(I6))}function OHn({onSelectionChange:e}){const t=So(),{selectedNodes:n,selectedEdges:r}=Us(SHn,kHn);return g.useEffect(()=>{const s={nodes:n,edges:r};e?.(s),t.getState().onSelectionChangeHandlers.forEach(a=>a(s))},[n,r,e]),null}const _Hn=e=>!!e.onSelectionChangeHandlers;function CHn({onSelectionChange:e}){const t=Us(_Hn);return e||t?o.jsx(OHn,{onSelectionChange:e}):null}const Mhe=typeof window<"u"?g.useLayoutEffect:g.useEffect,U0t=[0,0],EHn={x:0,y:0,zoom:1},jHn=["nodes","edges","defaultNodes","defaultEdges","onConnect","onConnectStart","onConnectEnd","onClickConnectStart","onClickConnectEnd","nodesDraggable","autoPanOnNodeFocus","nodesConnectable","nodesFocusable","edgesFocusable","edgesReconnectable","elevateNodesOnSelect","elevateEdgesOnSelect","minZoom","maxZoom","nodeExtent","onNodesChange","onEdgesChange","elementsSelectable","connectionMode","snapGrid","snapToGrid","translateExtent","connectOnClick","defaultEdgeOptions","fitView","fitViewOptions","onNodesDelete","onEdgesDelete","onDelete","onNodeDrag","onNodeDragStart","onNodeDragStop","onSelectionDrag","onSelectionDragStart","onSelectionDragStop","onMoveStart","onMove","onMoveEnd","noPanClassName","nodeOrigin","autoPanOnConnect","autoPanOnNodeDrag","onError","connectionRadius","isValidConnection","selectNodesOnDrag","nodeDragThreshold","connectionDragThreshold","onBeforeDelete","debug","autoPanSpeed","ariaLabelConfig","zIndexMode"],tFe=[...jHn,"rfId"],THn=e=>({setNodes:e.setNodes,setEdges:e.setEdges,setMinZoom:e.setMinZoom,setMaxZoom:e.setMaxZoom,setTranslateExtent:e.setTranslateExtent,setNodeExtent:e.setNodeExtent,reset:e.reset,setDefaultNodesAndEdges:e.setDefaultNodesAndEdges}),nFe={translateExtent:sM,nodeOrigin:U0t,minZoom:.5,maxZoom:2,elementsSelectable:!0,noPanClassName:"nopan",rfId:"1"};function NHn(e){const{setNodes:t,setEdges:n,setMinZoom:r,setMaxZoom:s,setTranslateExtent:a,setNodeExtent:i,reset:l,setDefaultNodesAndEdges:c}=Us(THn,no),u=So();Mhe(()=>(c(e.defaultNodes,e.defaultEdges),()=>{d.current=nFe,l()}),[]);const d=g.useRef(nFe);return Mhe(()=>{for(const f of tFe){const p=e[f],h=d.current[f];p!==h&&(typeof e[f]>"u"||(f==="nodes"?t(p):f==="edges"?n(p):f==="minZoom"?r(p):f==="maxZoom"?s(p):f==="translateExtent"?a(p):f==="nodeExtent"?i(p):f==="ariaLabelConfig"?u.setState({ariaLabelConfig:bVn(p)}):f==="fitView"?u.setState({fitViewQueued:p}):f==="fitViewOptions"?u.setState({fitViewOptions:p}):u.setState({[f]:p})))}d.current=e},tFe.map(f=>e[f])),null}function rFe(){return typeof window>"u"||!window.matchMedia?null:window.matchMedia("(prefers-color-scheme: dark)")}function IHn(e){const[t,n]=g.useState(e==="system"?null:e);return g.useEffect(()=>{if(e!=="system"){n(e);return}const r=rFe(),s=()=>n(r?.matches?"dark":"light");return s(),r?.addEventListener("change",s),()=>{r?.removeEventListener("change",s)}},[e]),t!==null?t:rFe()?.matches?"dark":"light"}const sFe=typeof document<"u"?document:null;function cM(e=null,t={target:sFe,actInsideInputWithModifier:!0}){const[n,r]=g.useState(!1),s=g.useRef(!1),a=g.useRef(new Set([])),[i,l]=g.useMemo(()=>{if(e!==null){const u=(Array.isArray(e)?e:[e]).filter(f=>typeof f=="string").map(f=>f.replace("+",`
|
|
336
|
+
`:r=="r"?"\r":r=="t"?" ":"\\")}eq(t){return this.search==t.search&&this.replace==t.replace&&this.caseSensitive==t.caseSensitive&&this.regexp==t.regexp&&this.wholeWord==t.wholeWord&&this.test==t.test}create(){return this.regexp?new D8n(this):new P8n(this)}getCursor(t,n=0,r){let s=t.doc?t:is.create({doc:t});return r==null&&(r=s.doc.length),this.regexp?kE(this,s,n,r):SE(this,s,n,r)}}class vxt{constructor(t){this.spec=t}}function A8n(e,t,n){return(r,s,a,i)=>{if(n&&!n(r,s,a,i))return!1;let l=r>=i&&s<=i+a.length?a.slice(r-i,s-i):t.doc.sliceString(r,s);return e(l,t,r,s)}}function SE(e,t,n,r){let s;return e.wholeWord&&(s=R8n(t.doc,t.charCategorizer(t.selection.main.head))),e.test&&(s=A8n(e.test,t,s)),new _x(t.doc,e.unquoted,n,r,e.caseSensitive?void 0:a=>a.toLowerCase(),s)}function R8n(e,t){return(n,r,s,a)=>((a>n||a+s.length<r)&&(a=Math.max(0,n-2),s=e.sliceString(a,Math.min(e.length,r+2))),(t(_7(s,n-a))!=po.Word||t(C7(s,n-a))!=po.Word)&&(t(C7(s,r-a))!=po.Word||t(_7(s,r-a))!=po.Word))}class P8n extends vxt{constructor(t){super(t)}nextMatch(t,n,r){let s=SE(this.spec,t,r,t.doc.length).nextOverlapping();if(s.done){let a=Math.min(t.doc.length,n+this.spec.unquoted.length);s=SE(this.spec,t,0,a).nextOverlapping()}return s.done||s.value.from==n&&s.value.to==r?null:s.value}prevMatchInRange(t,n,r){for(let s=r;;){let a=Math.max(n,s-1e4-this.spec.unquoted.length),i=SE(this.spec,t,a,s),l=null;for(;!i.nextOverlapping().done;)l=i.value;if(l)return l;if(a==n)return null;s-=1e4}}prevMatch(t,n,r){let s=this.prevMatchInRange(t,0,n);return s||(s=this.prevMatchInRange(t,Math.max(0,r-this.spec.unquoted.length),t.doc.length)),s&&(s.from!=n||s.to!=r)?s:null}getReplacement(t){return this.spec.unquote(this.spec.replace)}matchAll(t,n){let r=SE(this.spec,t,0,t.doc.length),s=[];for(;!r.next().done;){if(s.length>=n)return null;s.push(r.value)}return s}highlight(t,n,r,s){let a=SE(this.spec,t,Math.max(0,n-this.spec.unquoted.length),Math.min(r+this.spec.unquoted.length,t.doc.length));for(;!a.next().done;)s(a.value.from,a.value.to)}}function $8n(e,t,n){return(r,s,a)=>(!n||n(r,s,a))&&e(a[0],t,r,s)}function kE(e,t,n,r){let s;return e.wholeWord&&(s=M8n(t.charCategorizer(t.selection.main.head))),e.test&&(s=$8n(e.test,t,s)),new hxt(t.doc,e.search,{ignoreCase:!e.caseSensitive,test:s},n,r)}function _7(e,t){return e.slice(xc(e,t,!1),t)}function C7(e,t){return e.slice(t,xc(e,t))}function M8n(e){return(t,n,r)=>!r[0].length||(e(_7(r.input,r.index))!=po.Word||e(C7(r.input,r.index))!=po.Word)&&(e(C7(r.input,r.index+r[0].length))!=po.Word||e(_7(r.input,r.index+r[0].length))!=po.Word)}class D8n extends vxt{nextMatch(t,n,r){let s=kE(this.spec,t,r,t.doc.length).next();return s.done&&(s=kE(this.spec,t,0,n).next()),s.done?null:s.value}prevMatchInRange(t,n,r){for(let s=1;;s++){let a=Math.max(n,r-s*1e4),i=kE(this.spec,t,a,r),l=null;for(;!i.next().done;)l=i.value;if(l&&(a==n||l.from>a+10))return l;if(a==n)return null}}prevMatch(t,n,r){return this.prevMatchInRange(t,0,n)||this.prevMatchInRange(t,r,t.doc.length)}getReplacement(t){return this.spec.unquote(this.spec.replace).replace(/\$([$&]|\d+)/g,(n,r)=>{if(r=="&")return t.match[0];if(r=="$")return"$";for(let s=r.length;s>0;s--){let a=+r.slice(0,s);if(a>0&&a<t.match.length)return t.match[a]+r.slice(s)}return n})}matchAll(t,n){let r=kE(this.spec,t,0,t.doc.length),s=[];for(;!r.next().done;){if(s.length>=n)return null;s.push(r.value)}return s}highlight(t,n,r,s){let a=kE(this.spec,t,Math.max(0,n-250),Math.min(r+250,t.doc.length));for(;!a.next().done;)s(a.value.from,a.value.to)}}const X$=vr.define(),a1e=vr.define(),$w=gl.define({create(e){return new ZK(whe(e).create(),null)},update(e,t){for(let n of t.effects)n.is(X$)?e=new ZK(n.value.create(),e.panel):n.is(a1e)&&(e=new ZK(e.query,n.value?i1e:null));return e},provide:e=>B$.from(e,t=>t.panel)});class ZK{constructor(t,n){this.query=t,this.panel=n}}const L8n=Cn.mark({class:"cm-searchMatch"}),F8n=Cn.mark({class:"cm-searchMatch cm-searchMatch-selected"}),z8n=bo.fromClass(class{constructor(e){this.view=e,this.decorations=this.highlight(e.state.field($w))}update(e){let t=e.state.field($w);(t!=e.startState.field($w)||e.docChanged||e.selectionSet||e.viewportChanged)&&(this.decorations=this.highlight(t))}highlight({query:e,panel:t}){if(!t||!e.spec.valid)return Cn.none;let{view:n}=this,r=new kd;for(let s=0,a=n.visibleRanges,i=a.length;s<i;s++){let{from:l,to:c}=a[s];for(;s<i-1&&c>a[s+1].from-500;)c=a[++s].to;e.highlight(n.state,l,c,(u,d)=>{let f=n.state.selection.ranges.some(p=>p.from==u&&p.to==d);r.add(u,d,f?F8n:L8n)})}return r.finish()}},{decorations:e=>e.decorations});function f3(e){return t=>{let n=t.state.field($w,!1);return n&&n.query.spec.valid?e(t,n):xxt(t)}}const E7=f3((e,{query:t})=>{let{to:n}=e.state.selection.main,r=t.nextMatch(e.state,n,n);if(!r)return!1;let s=xt.single(r.from,r.to),a=e.state.facet(VN);return e.dispatch({selection:s,effects:[o1e(e,r),a.scrollToMatch(s.main,e)],userEvent:"select.search"}),bxt(e),!0}),j7=f3((e,{query:t})=>{let{state:n}=e,{from:r}=n.selection.main,s=t.prevMatch(n,r,r);if(!s)return!1;let a=xt.single(s.from,s.to),i=e.state.facet(VN);return e.dispatch({selection:a,effects:[o1e(e,s),i.scrollToMatch(a.main,e)],userEvent:"select.search"}),bxt(e),!0}),B8n=f3((e,{query:t})=>{let n=t.matchAll(e.state,1e3);return!n||!n.length?!1:(e.dispatch({selection:xt.create(n.map(r=>xt.range(r.from,r.to))),userEvent:"select.search.matches"}),!0)}),U8n=({state:e,dispatch:t})=>{let n=e.selection;if(n.ranges.length>1||n.main.empty)return!1;let{from:r,to:s}=n.main,a=[],i=0;for(let l=new _x(e.doc,e.sliceDoc(r,s));!l.next().done;){if(a.length>1e3)return!1;l.value.from==r&&(i=a.length),a.push(xt.range(l.value.from,l.value.to))}return t(e.update({selection:xt.create(a,i),userEvent:"select.search.matches"})),!0},f6e=f3((e,{query:t})=>{let{state:n}=e,{from:r,to:s}=n.selection.main;if(n.readOnly)return!1;let a=t.nextMatch(n,r,r);if(!a)return!1;let i=a,l=[],c,u,d=[];i.precise?i.from==r&&i.to==s&&(u=n.toText(t.getReplacement(i)),l.push({from:i.from,to:i.to,insert:u}),d.push(It.announce.of(n.phrase("replaced match on line $",n.doc.lineAt(r).number)+"."))):i=t.nextMatch(n,i.from,i.to);let f=e.state.changes(l);return i&&(c=xt.single(i.from,i.to).map(f),d.push(o1e(e,i)),d.push(n.facet(VN).scrollToMatch(c.main,e))),e.dispatch({changes:f,selection:c,effects:d,userEvent:"input.replace"}),!0}),q8n=f3((e,{query:t})=>{if(e.state.readOnly)return!1;let n=[];for(let s of t.matchAll(e.state,1e9)){let{from:a,to:i,precise:l}=s;l&&n.push({from:a,to:i,insert:t.getReplacement(s)})}if(!n.length)return!1;let r=e.state.phrase("replaced $ matches",n.length)+".";return e.dispatch({changes:n,effects:It.announce.of(r),userEvent:"input.replace.all"}),!0});function i1e(e){return e.state.facet(VN).createPanel(e)}function whe(e,t){var n,r,s,a,i;let l=e.selection.main,c=l.empty||l.to>l.from+100?"":e.sliceDoc(l.from,l.to);if(t&&!c)return t;let u=e.facet(VN);return new gxt({search:((n=t?.literal)!==null&&n!==void 0?n:u.literal)?c:c.replace(/\n/g,"\\n"),caseSensitive:(r=t?.caseSensitive)!==null&&r!==void 0?r:u.caseSensitive,literal:(s=t?.literal)!==null&&s!==void 0?s:u.literal,regexp:(a=t?.regexp)!==null&&a!==void 0?a:u.regexp,wholeWord:(i=t?.wholeWord)!==null&&i!==void 0?i:u.wholeWord})}function yxt(e){let t=Swe(e,i1e);return t&&t.dom.querySelector("[main-field]")}function bxt(e){let t=yxt(e);t&&t==e.root.activeElement&&t.select()}const xxt=e=>{let t=e.state.field($w,!1);if(t&&t.panel){let n=yxt(e);if(n&&n!=e.root.activeElement){let r=whe(e.state,t.query.spec);r.valid&&e.dispatch({effects:X$.of(r)}),n.focus(),n.select()}}else e.dispatch({effects:[a1e.of(!0),t?X$.of(whe(e.state,t.query.spec)):vr.appendConfig.of(Z8n)]});return!0},wxt=e=>{let t=e.state.field($w,!1);if(!t||!t.panel)return!1;let n=Swe(e,i1e);return n&&n.dom.contains(e.root.activeElement)&&e.focus(),e.dispatch({effects:a1e.of(!1)}),!0},V8n=[{key:"Mod-f",run:xxt,scope:"editor search-panel"},{key:"F3",run:E7,shift:j7,scope:"editor search-panel",preventDefault:!0},{key:"Mod-g",run:E7,shift:j7,scope:"editor search-panel",preventDefault:!0},{key:"Escape",run:wxt,scope:"editor search-panel"},{key:"Mod-Shift-l",run:U8n},{key:"Mod-Alt-g",run:x8n},{key:"Mod-d",run:I8n,preventDefault:!0}];class H8n{constructor(t){this.view=t;let n=this.query=t.state.field($w).query.spec;this.commit=this.commit.bind(this),this.searchField=ci("input",{value:n.search,placeholder:Qf(t,"Find"),"aria-label":Qf(t,"Find"),class:"cm-textfield",name:"search",form:"","main-field":"true",onchange:this.commit,onkeyup:this.commit}),this.replaceField=ci("input",{value:n.replace,placeholder:Qf(t,"Replace"),"aria-label":Qf(t,"Replace"),class:"cm-textfield",name:"replace",form:"",onchange:this.commit,onkeyup:this.commit}),this.caseField=ci("input",{type:"checkbox",name:"case",form:"",checked:n.caseSensitive,onchange:this.commit}),this.reField=ci("input",{type:"checkbox",name:"re",form:"",checked:n.regexp,onchange:this.commit}),this.wordField=ci("input",{type:"checkbox",name:"word",form:"",checked:n.wholeWord,onchange:this.commit});function r(s,a,i){return ci("button",{class:"cm-button",name:s,onclick:a,type:"button"},i)}this.dom=ci("div",{onkeydown:s=>this.keydown(s),class:"cm-search"},[this.searchField,r("next",()=>E7(t),[Qf(t,"next")]),r("prev",()=>j7(t),[Qf(t,"previous")]),r("select",()=>B8n(t),[Qf(t,"all")]),ci("label",null,[this.caseField,Qf(t,"match case")]),ci("label",null,[this.reField,Qf(t,"regexp")]),ci("label",null,[this.wordField,Qf(t,"by word")]),...t.state.readOnly?[]:[ci("br"),this.replaceField,r("replace",()=>f6e(t),[Qf(t,"replace")]),r("replaceAll",()=>q8n(t),[Qf(t,"replace all")])],ci("button",{name:"close",onclick:()=>wxt(t),"aria-label":Qf(t,"close"),type:"button"},["×"])])}commit(){let t=new gxt({search:this.searchField.value,caseSensitive:this.caseField.checked,regexp:this.reField.checked,wholeWord:this.wordField.checked,replace:this.replaceField.value});t.eq(this.query)||(this.query=t,this.view.dispatch({effects:X$.of(t)}))}keydown(t){d3n(this.view,t,"search-panel")?t.preventDefault():t.keyCode==13&&t.target==this.searchField?(t.preventDefault(),(t.shiftKey?j7:E7)(this.view)):t.keyCode==13&&t.target==this.replaceField&&(t.preventDefault(),f6e(this.view))}update(t){for(let n of t.transactions)for(let r of n.effects)r.is(X$)&&!r.value.eq(this.query)&&this.setQuery(r.value)}setQuery(t){this.query=t,this.searchField.value=t.search,this.replaceField.value=t.replace,this.caseField.checked=t.caseSensitive,this.reField.checked=t.regexp,this.wordField.checked=t.wholeWord}mount(){this.searchField.select()}get pos(){return 80}get top(){return this.view.state.facet(VN).top}}function Qf(e,t){return e.state.phrase(t)}const w6=30,S6=/[\s\.,:;?!]/;function o1e(e,{from:t,to:n}){let r=e.state.doc.lineAt(t),s=e.state.doc.lineAt(n).to,a=Math.max(r.from,t-w6),i=Math.min(s,n+w6),l=e.state.sliceDoc(a,i);if(a!=r.from){for(let c=0;c<w6;c++)if(!S6.test(l[c+1])&&S6.test(l[c])){l=l.slice(c);break}}if(i!=s){for(let c=l.length-1;c>l.length-w6;c--)if(!S6.test(l[c-1])&&S6.test(l[c])){l=l.slice(0,c);break}}return It.announce.of(`${e.state.phrase("current match")}. ${l} ${e.state.phrase("on line")} ${r.number}.`)}const W8n=It.baseTheme({".cm-panel.cm-search":{padding:"2px 6px 4px",position:"relative","& [name=close]":{position:"absolute",top:"0",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",padding:0,margin:0},"& input, & button, & label":{margin:".2em .6em .2em 0"},"& input[type=checkbox]":{marginRight:".2em"},"& label":{fontSize:"80%",whiteSpace:"pre"}},"&light .cm-searchMatch":{backgroundColor:"#ffff0054"},"&dark .cm-searchMatch":{backgroundColor:"#00ffff8a"},"&light .cm-searchMatch-selected":{backgroundColor:"#ff6a0054"},"&dark .cm-searchMatch-selected":{backgroundColor:"#ff00ff8a"}}),Z8n=[$w,Mg.low(z8n),W8n];class p6e{constructor(t,n,r){this.from=t,this.to=n,this.diagnostic=r}}class hk{constructor(t,n,r){this.diagnostics=t,this.panel=n,this.selected=r}static init(t,n,r){let s=r.facet(K$).markerFilter;s&&(t=s(t,r));let a=t.slice().sort((d,f)=>d.from-f.from||d.to-f.to),i=new kd,l=[],c=0;for(let d=0;;){let f=d==a.length?null:a[d];if(!f&&!l.length)break;let p,h;for(l.length?(p=c,h=l.reduce((v,y)=>Math.min(v,y.to),f&&f.from>p?f.from:1e8)):(p=f.from,h=f.to,l.push(f),d++);d<a.length;){let v=a[d];if(v.from==p&&(v.to>v.from||v.to==p))l.push(v),d++,h=Math.min(v.to,h);else{h=Math.min(v.from,h);break}}let m=izn(l);if(l.some(v=>v.from==v.to||v.from==v.to-1&&r.doc.lineAt(v.from).to==v.from))i.add(p,p,Cn.widget({widget:new nzn(m),diagnostics:l.slice()}));else{let v=l.reduce((y,b)=>b.markClass?y+" "+b.markClass:y,"");i.add(p,h,Cn.mark({class:"cm-lintRange cm-lintRange-"+m+v,diagnostics:l.slice(),inclusiveEnd:l.some(y=>y.to>h)}))}c=h;for(let v=0;v<l.length;v++)l[v].to<=c&&l.splice(v--,1)}let u=i.finish();return new hk(u,n,xT(u))}}function xT(e,t=null,n=0){let r=null;return e.between(n,1e9,(s,a,{spec:i})=>{if(!(t&&i.diagnostics.indexOf(t)<0))if(!r)r=new p6e(s,a,t||i.diagnostics[0]);else{if(i.diagnostics.indexOf(r.diagnostic)<0)return!1;r=new p6e(r.from,a,r.diagnostic)}}),r}function G8n(e,t){let n=t.pos,r=t.end||n,s=e.state.facet(K$).hideOn(e,n,r);if(s!=null)return s;let a=e.startState.doc.lineAt(t.pos);return!!(e.effects.some(i=>i.is(Sxt))||e.changes.touchesRange(a.from,Math.max(a.to,r)))}function Q8n(e,t){return e.field(xp,!1)?t:t.concat(vr.appendConfig.of(ozn))}const Sxt=vr.define(),l1e=vr.define(),kxt=vr.define(),xp=gl.define({create(){return new hk(Cn.none,null,null)},update(e,t){if(t.docChanged&&e.diagnostics.size){let n=e.diagnostics.map(t.changes),r=null,s=e.panel;if(e.selected){let a=t.changes.mapPos(e.selected.from,1);r=xT(n,e.selected.diagnostic,a)||xT(n,null,a)}!n.size&&s&&t.state.facet(K$).autoPanel&&(s=null),e=new hk(n,s,r)}for(let n of t.effects)if(n.is(Sxt)){let r=t.state.facet(K$).autoPanel?n.value.length?J$.open:null:e.panel;e=hk.init(n.value,r,t.state)}else n.is(l1e)?e=new hk(e.diagnostics,n.value?J$.open:null,e.selected):n.is(kxt)&&(e=new hk(e.diagnostics,e.panel,n.value));return e},provide:e=>[B$.from(e,t=>t.panel),It.decorations.from(e,t=>t.diagnostics)]}),Y8n=Cn.mark({class:"cm-lintRange cm-lintRange-active"});function X8n(e,t,n){let{diagnostics:r}=e.state.field(xp),s,a=-1,i=-1;r.between(t-(n<0?1:0),t+(n>0?1:0),(c,u,{spec:d})=>{if(t>=c&&t<=u&&(c==u||(t>c||n>0)&&(t<u||n<0)))return s=d.diagnostics,a=c,i=u,!1});let l=e.state.facet(K$).tooltipFilter;return s&&l&&(s=l(s,e.state)),s?{pos:a,end:i,above:e.state.doc.lineAt(a).to<i,create(){return{dom:K8n(e,s)}}}:null}function K8n(e,t){return ci("ul",{class:"cm-tooltip-lint"},t.map(n=>_xt(e,n,!1)))}const J8n=e=>{let t=e.state.field(xp,!1);(!t||!t.panel)&&e.dispatch({effects:Q8n(e.state,[l1e.of(!0)])});let n=Swe(e,J$.open);return n&&n.dom.querySelector(".cm-panel-lint ul").focus(),!0},h6e=e=>{let t=e.state.field(xp,!1);return!t||!t.panel?!1:(e.dispatch({effects:l1e.of(!1)}),!0)},ezn=e=>{let t=e.state.field(xp,!1);if(!t)return!1;let n=e.state.selection.main,r=t.diagnostics.iter(n.to+1);return!r.value&&(r=t.diagnostics.iter(0),!r.value||r.from==n.from&&r.to==n.to)?!1:(e.dispatch({selection:{anchor:r.from,head:r.to},scrollIntoView:!0}),!0)},tzn=[{key:"Mod-Shift-m",run:J8n,preventDefault:!0},{key:"F8",run:ezn}],K$=On.define({combine(e){return{sources:e.map(t=>t.source).filter(t=>t!=null),...$y(e.map(t=>t.config),{delay:750,markerFilter:null,tooltipFilter:null,needsRefresh:null,hideOn:()=>null},{delay:Math.max,markerFilter:m6e,tooltipFilter:m6e,needsRefresh:(t,n)=>t?n?r=>t(r)||n(r):t:n,hideOn:(t,n)=>t?n?(r,s,a)=>t(r,s,a)||n(r,s,a):t:n,autoPanel:(t,n)=>t||n})}}});function m6e(e,t){return e?t?(n,r)=>t(e(n,r),r):e:t}function Oxt(e){let t=[];if(e)e:for(let{name:n}of e){for(let r=0;r<n.length;r++){let s=n[r];if(/[a-zA-Z]/.test(s)&&!t.some(a=>a.toLowerCase()==s.toLowerCase())){t.push(s);continue e}}t.push("")}return t}function _xt(e,t,n){var r;let s=n?Oxt(t.actions):[];return ci("li",{class:"cm-diagnostic cm-diagnostic-"+t.severity},ci("span",{class:"cm-diagnosticText"},t.renderMessage?t.renderMessage(e):t.message),(r=t.actions)===null||r===void 0?void 0:r.map((a,i)=>{let l=!1,c=h=>{if(h.preventDefault(),l)return;l=!0;let m=xT(e.state.field(xp).diagnostics,t);m&&a.apply(e,m.from,m.to)},{name:u}=a,d=s[i]?u.indexOf(s[i]):-1,f=d<0?u:[u.slice(0,d),ci("u",u.slice(d,d+1)),u.slice(d+1)],p=a.markClass?" "+a.markClass:"";return ci("button",{type:"button",class:"cm-diagnosticAction"+p,onclick:c,onmousedown:c,"aria-label":` Action: ${u}${d<0?"":` (access key "${s[i]})"`}.`},f)}),t.source&&ci("div",{class:"cm-diagnosticSource"},t.source))}class nzn extends Kp{constructor(t){super(),this.sev=t}eq(t){return t.sev==this.sev}toDOM(){return ci("span",{class:"cm-lintPoint cm-lintPoint-"+this.sev})}}class g6e{constructor(t,n){this.diagnostic=n,this.id="item_"+Math.floor(Math.random()*4294967295).toString(16),this.dom=_xt(t,n,!0),this.dom.id=this.id,this.dom.setAttribute("role","option")}}class J${constructor(t){this.view=t,this.items=[];let n=s=>{if(s.keyCode==27)h6e(this.view),this.view.focus();else if(s.keyCode==38||s.keyCode==33)this.moveSelection((this.selectedIndex-1+this.items.length)%this.items.length);else if(s.keyCode==40||s.keyCode==34)this.moveSelection((this.selectedIndex+1)%this.items.length);else if(s.keyCode==36)this.moveSelection(0);else if(s.keyCode==35)this.moveSelection(this.items.length-1);else if(s.keyCode==13)this.view.focus();else if(s.keyCode>=65&&s.keyCode<=90&&this.selectedIndex>=0){let{diagnostic:a}=this.items[this.selectedIndex],i=Oxt(a.actions);for(let l=0;l<i.length;l++)if(i[l].toUpperCase().charCodeAt(0)==s.keyCode){let c=xT(this.view.state.field(xp).diagnostics,a);c&&a.actions[l].apply(t,c.from,c.to)}}else return;s.preventDefault()},r=s=>{for(let a=0;a<this.items.length;a++)this.items[a].dom.contains(s.target)&&this.moveSelection(a)};this.list=ci("ul",{tabIndex:0,role:"listbox","aria-label":this.view.state.phrase("Diagnostics"),onkeydown:n,onclick:r}),this.dom=ci("div",{class:"cm-panel-lint"},this.list,ci("button",{type:"button",name:"close","aria-label":this.view.state.phrase("close"),onclick:()=>h6e(this.view)},"×")),this.update()}get selectedIndex(){let t=this.view.state.field(xp).selected;if(!t)return-1;for(let n=0;n<this.items.length;n++)if(this.items[n].diagnostic==t.diagnostic)return n;return-1}update(){let{diagnostics:t,selected:n}=this.view.state.field(xp),r=0,s=!1,a=null,i=new Set;for(t.between(0,this.view.state.doc.length,(l,c,{spec:u})=>{for(let d of u.diagnostics){if(i.has(d))continue;i.add(d);let f=-1,p;for(let h=r;h<this.items.length;h++)if(this.items[h].diagnostic==d){f=h;break}f<0?(p=new g6e(this.view,d),this.items.splice(r,0,p),s=!0):(p=this.items[f],f>r&&(this.items.splice(r,f-r),s=!0)),n&&p.diagnostic==n.diagnostic?p.dom.hasAttribute("aria-selected")||(p.dom.setAttribute("aria-selected","true"),a=p):p.dom.hasAttribute("aria-selected")&&p.dom.removeAttribute("aria-selected"),r++}});r<this.items.length&&!(this.items.length==1&&this.items[0].diagnostic.from<0);)s=!0,this.items.pop();this.items.length==0&&(this.items.push(new g6e(this.view,{from:-1,to:-1,severity:"info",message:this.view.state.phrase("No diagnostics")})),s=!0),a?(this.list.setAttribute("aria-activedescendant",a.id),this.view.requestMeasure({key:this,read:()=>({sel:a.dom.getBoundingClientRect(),panel:this.list.getBoundingClientRect()}),write:({sel:l,panel:c})=>{let u=c.height/this.list.offsetHeight;l.top<c.top?this.list.scrollTop-=(c.top-l.top)/u:l.bottom>c.bottom&&(this.list.scrollTop+=(l.bottom-c.bottom)/u)}})):this.selectedIndex<0&&this.list.removeAttribute("aria-activedescendant"),s&&this.sync()}sync(){let t=this.list.firstChild;function n(){let r=t;t=r.nextSibling,r.remove()}for(let r of this.items)if(r.dom.parentNode==this.list){for(;t!=r.dom;)n();t=r.dom.nextSibling}else this.list.insertBefore(r.dom,t);for(;t;)n()}moveSelection(t){if(this.selectedIndex<0)return;let n=this.view.state.field(xp),r=xT(n.diagnostics,this.items[t].diagnostic);r&&this.view.dispatch({selection:{anchor:r.from,head:r.to},scrollIntoView:!0,effects:kxt.of(r)})}static open(t){return new J$(t)}}function rzn(e,t='viewBox="0 0 40 40"'){return`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" ${t}>${encodeURIComponent(e)}</svg>')`}function k6(e){return rzn(`<path d="m0 2.5 l2 -1.5 l1 0 l2 1.5 l1 0" stroke="${e}" fill="none" stroke-width=".7"/>`,'width="6" height="3"')}const szn=It.baseTheme({".cm-diagnostic":{padding:"3px 6px 3px 8px",marginLeft:"-1px",display:"block",whiteSpace:"pre-wrap"},".cm-diagnostic-error":{borderLeft:"5px solid #d11"},".cm-diagnostic-warning":{borderLeft:"5px solid orange"},".cm-diagnostic-info":{borderLeft:"5px solid #999"},".cm-diagnostic-hint":{borderLeft:"5px solid #66d"},".cm-diagnosticAction":{font:"inherit",border:"none",padding:"2px 4px",backgroundColor:"#444",color:"white",borderRadius:"3px",marginLeft:"8px",cursor:"pointer"},".cm-diagnosticSource":{fontSize:"70%",opacity:.7},".cm-lintRange":{backgroundPosition:"left bottom",backgroundRepeat:"repeat-x",paddingBottom:"0.7px"},".cm-lintRange-error":{backgroundImage:k6("#d11")},".cm-lintRange-warning":{backgroundImage:k6("orange")},".cm-lintRange-info":{backgroundImage:k6("#999")},".cm-lintRange-hint":{backgroundImage:k6("#66d")},".cm-lintRange-active":{backgroundColor:"#ffdd9980"},".cm-tooltip-lint":{padding:0,margin:0},".cm-lintPoint":{position:"relative","&:after":{content:'""',position:"absolute",bottom:0,left:"-2px",borderLeft:"3px solid transparent",borderRight:"3px solid transparent",borderBottom:"4px solid #d11"}},".cm-lintPoint-warning":{"&:after":{borderBottomColor:"orange"}},".cm-lintPoint-info":{"&:after":{borderBottomColor:"#999"}},".cm-lintPoint-hint":{"&:after":{borderBottomColor:"#66d"}},".cm-panel.cm-panel-lint":{position:"relative","& ul":{maxHeight:"100px",overflowY:"auto","& [aria-selected]":{backgroundColor:"#ddd","& u":{textDecoration:"underline"}},"&:focus [aria-selected]":{background_fallback:"#bdf",backgroundColor:"Highlight",color_fallback:"white",color:"HighlightText"},"& u":{textDecoration:"none"},padding:0,margin:0},"& [name=close]":{position:"absolute",top:"0",right:"2px",background:"inherit",border:"none",font:"inherit",padding:0,margin:0}}});function azn(e){return e=="error"?4:e=="warning"?3:e=="info"?2:1}function izn(e){let t="hint",n=1;for(let r of e){let s=azn(r.severity);s>n&&(n=s,t=r.severity)}return t}const ozn=[xp,It.decorations.compute([xp],e=>{let{selected:t,panel:n}=e.field(xp);return!t||!n||t.from==t.to?Cn.none:Cn.set([Y8n.range(t.from,t.to)])}),J3n(X8n,{hideOn:G8n}),szn];var v6e=function(t){t===void 0&&(t={});var n=t,r=n.crosshairCursor,s=r===void 0?!1:r,a=[];t.closeBracketsKeymap!==!1&&(a=a.concat(Y5n)),t.defaultKeymap!==!1&&(a=a.concat(v8n)),t.searchKeymap!==!1&&(a=a.concat(V8n)),t.historyKeymap!==!1&&(a=a.concat(OFn)),t.foldKeymap!==!1&&(a=a.concat($4n)),t.completionKeymap!==!1&&(a=a.concat(byt)),t.lintKeymap!==!1&&(a=a.concat(tzn));var i=[];return t.lineNumbers!==!1&&i.push(d4n()),t.highlightActiveLineGutter!==!1&&i.push(h4n()),t.highlightSpecialChars!==!1&&i.push(E3n()),t.history!==!1&&i.push(mFn()),t.foldGutter!==!1&&i.push(F4n()),t.drawSelection!==!1&&i.push(v3n()),t.dropCursor!==!1&&i.push(S3n()),t.allowMultipleSelections!==!1&&i.push(is.allowMultipleSelections.of(!0)),t.indentOnInput!==!1&&i.push(E4n()),t.syntaxHighlighting!==!1&&i.push(B1(q4n,{fallback:!0})),t.bracketMatching!==!1&&i.push(Y4n()),t.closeBrackets!==!1&&i.push(W5n()),t.autocompletion!==!1&&i.push(yyt()),t.rectangularSelection!==!1&&i.push(B3n()),s!==!1&&i.push(V3n()),t.highlightActiveLine!==!1&&i.push(R3n()),t.highlightSelectionMatches!==!1&&i.push(k8n()),t.tabSize&&typeof t.tabSize=="number"&&i.push(zN.of(" ".repeat(t.tabSize))),i.concat([FN.of(a.flat())]).filter(Boolean)};const lzn="#e5c07b",y6e="#e06c75",czn="#56b6c2",uzn="#ffffff",XF="#abb2bf",She="#7d8799",dzn="#61afef",fzn="#98c379",b6e="#d19a66",pzn="#c678dd",hzn="#21252b",x6e="#2c313a",w6e="#282c34",GK="#353a42",mzn="#3E4451",S6e="#528bff",gzn=It.theme({"&":{color:XF,backgroundColor:w6e},".cm-content":{caretColor:S6e},".cm-cursor, .cm-dropCursor":{borderLeftColor:S6e},"&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection":{backgroundColor:mzn},".cm-panels":{backgroundColor:hzn,color:XF},".cm-panels.cm-panels-top":{borderBottom:"2px solid black"},".cm-panels.cm-panels-bottom":{borderTop:"2px solid black"},".cm-searchMatch":{backgroundColor:"#72a1ff59",outline:"1px solid #457dff"},".cm-searchMatch.cm-searchMatch-selected":{backgroundColor:"#6199ff2f"},".cm-activeLine":{backgroundColor:"#6699ff0b"},".cm-selectionMatch":{backgroundColor:"#aafe661a"},"&.cm-focused .cm-matchingBracket, &.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bad0f847"},".cm-gutters":{backgroundColor:w6e,color:She,border:"none"},".cm-activeLineGutter":{backgroundColor:x6e},".cm-foldPlaceholder":{backgroundColor:"transparent",border:"none",color:"#ddd"},".cm-tooltip":{border:"none",backgroundColor:GK},".cm-tooltip .cm-tooltip-arrow:before":{borderTopColor:"transparent",borderBottomColor:"transparent"},".cm-tooltip .cm-tooltip-arrow:after":{borderTopColor:GK,borderBottomColor:GK},".cm-tooltip-autocomplete":{"& > ul > li[aria-selected]":{backgroundColor:x6e,color:XF}}},{dark:!0}),vzn=Dg.define([{tag:fe.keyword,color:pzn},{tag:[fe.name,fe.deleted,fe.character,fe.propertyName,fe.macroName],color:y6e},{tag:[fe.function(fe.variableName),fe.labelName],color:dzn},{tag:[fe.color,fe.constant(fe.name),fe.standard(fe.name)],color:b6e},{tag:[fe.definition(fe.name),fe.separator],color:XF},{tag:[fe.typeName,fe.className,fe.number,fe.changed,fe.annotation,fe.modifier,fe.self,fe.namespace],color:lzn},{tag:[fe.operator,fe.operatorKeyword,fe.url,fe.escape,fe.regexp,fe.link,fe.special(fe.string)],color:czn},{tag:[fe.meta,fe.comment],color:She},{tag:fe.strong,fontWeight:"bold"},{tag:fe.emphasis,fontStyle:"italic"},{tag:fe.strikethrough,textDecoration:"line-through"},{tag:fe.link,color:She,textDecoration:"underline"},{tag:fe.heading,fontWeight:"bold",color:y6e},{tag:[fe.atom,fe.bool,fe.special(fe.variableName)],color:b6e},{tag:[fe.processingInstruction,fe.string,fe.inserted],color:fzn},{tag:fe.invalid,color:uzn}]),yzn=[gzn,B1(vzn)];var bzn=It.theme({"&":{backgroundColor:"#fff"}},{dark:!1}),xzn=function(t){t===void 0&&(t={});var n=t,r=n.indentWithTab,s=r===void 0?!0:r,a=n.editable,i=a===void 0?!0:a,l=n.readOnly,c=l===void 0?!1:l,u=n.theme,d=u===void 0?"light":u,f=n.placeholder,p=f===void 0?"":f,h=n.basicSetup,m=h===void 0?!0:h,v=[];switch(s&&v.unshift(FN.of([y8n])),m&&(typeof m=="boolean"?v.unshift(v6e()):v.unshift(v6e(m))),p&&v.unshift(D3n(p)),d){case"light":v.push(bzn);break;case"dark":v.push(yzn);break;case"none":break;default:v.push(d);break}return i===!1&&v.push(It.editable.of(!1)),c&&v.push(is.readOnly.of(!0)),[...v]},wzn=e=>({line:e.state.doc.lineAt(e.state.selection.main.from),lineCount:e.state.doc.lines,lineBreak:e.state.lineBreak,length:e.state.doc.length,readOnly:e.state.readOnly,tabSize:e.state.tabSize,selection:e.state.selection,selectionAsSingle:e.state.selection.asSingle().main,ranges:e.state.selection.ranges,selectionCode:e.state.sliceDoc(e.state.selection.main.from,e.state.selection.main.to),selections:e.state.selection.ranges.map(t=>e.state.sliceDoc(t.from,t.to)),selectedText:e.state.selection.ranges.some(t=>!t.empty)});class Szn{constructor(t,n){this.timeLeftMS=void 0,this.timeoutMS=void 0,this.isCancelled=!1,this.isTimeExhausted=!1,this.callbacks=[],this.timeLeftMS=n,this.timeoutMS=n,this.callbacks.push(t)}tick(){if(!this.isCancelled&&!this.isTimeExhausted&&(this.timeLeftMS--,this.timeLeftMS<=0)){this.isTimeExhausted=!0;var t=this.callbacks.slice();this.callbacks.length=0,t.forEach(n=>{try{n()}catch(r){console.error("TimeoutLatch callback error:",r)}})}}cancel(){this.isCancelled=!0,this.callbacks.length=0}reset(){this.timeLeftMS=this.timeoutMS,this.isCancelled=!1,this.isTimeExhausted=!1}get isDone(){return this.isCancelled||this.isTimeExhausted}}class k6e{constructor(){this.interval=null,this.latches=new Set}add(t){this.latches.add(t),this.start()}remove(t){this.latches.delete(t),this.latches.size===0&&this.stop()}start(){this.interval===null&&(this.interval=setInterval(()=>{this.latches.forEach(t=>{t.tick(),t.isDone&&this.remove(t)})},1))}stop(){this.interval!==null&&(clearInterval(this.interval),this.interval=null)}}var QK=null,kzn=()=>typeof window>"u"?new k6e:(QK||(QK=new k6e),QK),O6e=Py.define(),Ozn=200,_zn=[];function Czn(e){var t=e.value,n=e.selection,r=e.onChange,s=e.onStatistics,a=e.onCreateEditor,i=e.onUpdate,l=e.extensions,c=l===void 0?_zn:l,u=e.autoFocus,d=e.theme,f=d===void 0?"light":d,p=e.height,h=p===void 0?null:p,m=e.minHeight,v=m===void 0?null:m,y=e.maxHeight,b=y===void 0?null:y,S=e.width,w=S===void 0?null:S,k=e.minWidth,_=k===void 0?null:k,C=e.maxWidth,E=C===void 0?null:C,j=e.placeholder,N=j===void 0?"":j,I=e.editable,R=I===void 0?!0:I,P=e.readOnly,L=P===void 0?!1:P,M=e.indentWithTab,q=M===void 0?!0:M,H=e.basicSetup,F=H===void 0?!0:H,z=e.root,B=e.initialState,D=g.useState(),Q=D[0],V=D[1],$=g.useState(),U=$[0],Z=$[1],X=g.useState(),te=X[0],J=X[1],ee=g.useState(()=>({current:null}))[0],ae=g.useState(()=>({current:null}))[0],ce=It.theme({"&":{height:h,minHeight:v,maxHeight:b,width:w,minWidth:_,maxWidth:E},"& .cm-scroller":{height:"100% !important"}}),Y=It.updateListener.of(pe=>{if(pe.docChanged&&typeof r=="function"&&!pe.transactions.some(ye=>ye.annotation(O6e))){ee.current?ee.current.reset():(ee.current=new Szn(()=>{if(ae.current){var ye=ae.current;ae.current=null,ye()}ee.current=null},Ozn),kzn().add(ee.current));var le=pe.state.doc,ve=le.toString();r(ve,pe)}s&&s(wzn(pe))}),ne=xzn({theme:f,editable:R,readOnly:L,placeholder:N,indentWithTab:q,basicSetup:F}),ue=[Y,ce,...ne];return i&&typeof i=="function"&&ue.push(It.updateListener.of(i)),ue=ue.concat(c),g.useLayoutEffect(()=>{if(Q&&!te){var pe={doc:t,selection:n,extensions:ue},le=B?is.fromJSON(B.json,pe,B.fields):is.create(pe);if(J(le),!U){var ve=new It({state:le,parent:Q,root:z});Z(ve),a&&a(ve,le)}}return()=>{U&&(J(void 0),Z(void 0))}},[Q,te]),g.useEffect(()=>{e.container&&V(e.container)},[e.container]),g.useEffect(()=>()=>{U&&(U.destroy(),Z(void 0)),ee.current&&(ee.current.cancel(),ee.current=null)},[U]),g.useEffect(()=>{u&&U&&U.focus()},[u,U]),g.useEffect(()=>{U&&U.dispatch({effects:vr.reconfigure.of(ue)})},[f,c,h,v,b,w,_,E,N,R,L,q,F,r,i]),g.useEffect(()=>{if(t!==void 0){var pe=U?U.state.doc.toString():"";if(U&&t!==pe){var le=ee.current&&!ee.current.isDone,ve=()=>{U&&t!==U.state.doc.toString()&&U.dispatch({changes:{from:0,to:U.state.doc.toString().length,insert:t||""},annotations:[O6e.of(!0)]})};le?ae.current=ve:ve()}}},[t,U]),{state:te,setState:J,view:U,setView:Z,container:Q,setContainer:V}}var Ezn=["className","value","selection","extensions","onChange","onStatistics","onCreateEditor","onUpdate","autoFocus","theme","height","minHeight","maxHeight","width","minWidth","maxWidth","basicSetup","placeholder","indentWithTab","editable","readOnly","root","initialState"],ru=g.forwardRef((e,t)=>{var n=e.className,r=e.value,s=r===void 0?"":r,a=e.selection,i=e.extensions,l=i===void 0?[]:i,c=e.onChange,u=e.onStatistics,d=e.onCreateEditor,f=e.onUpdate,p=e.autoFocus,h=e.theme,m=h===void 0?"light":h,v=e.height,y=e.minHeight,b=e.maxHeight,S=e.width,w=e.minWidth,k=e.maxWidth,_=e.basicSetup,C=e.placeholder,E=e.indentWithTab,j=e.editable,N=e.readOnly,I=e.root,R=e.initialState,P=Rbt(e,Ezn),L=g.useRef(null),M=Czn({root:I,value:s,autoFocus:p,theme:m,height:v,minHeight:y,maxHeight:b,width:S,minWidth:w,maxWidth:k,basicSetup:_,placeholder:C,indentWithTab:E,editable:j,readOnly:N,selection:a,onChange:c,onStatistics:u,onCreateEditor:d,onUpdate:f,extensions:l,initialState:R}),q=M.state,H=M.view,F=M.container,z=M.setContainer;g.useImperativeHandle(t,()=>({editor:L.current,state:q,view:H}),[L,F,q,H]);var B=g.useCallback(Q=>{L.current=Q,z(Q)},[z]);if(typeof s!="string")throw new Error("value must be typeof string but got "+typeof s);var D=typeof m=="string"?"cm-theme-"+m:"cm-theme";return o.jsx("div",PO({ref:B,className:""+D+(n?" "+n:"")},P))});ru.displayName="CodeMirror";const jzn={js:"javascript",javascript:"javascript",mjs:"javascript",cjs:"javascript",node:"javascript",ts:"typescript",typescript:"typescript",mts:"typescript",cts:"typescript",tsx:"tsx",jsx:"jsx",json:"json",json5:"json",md:"markdown",markdown:"markdown",py:"python",python:"python",sh:"bash",bash:"bash",shell:"bash",zsh:"bash"};let YK=null;function Tzn(){return YK||(YK=(async()=>{const[{createHighlighterCore:e},{createJavaScriptRegexEngine:t}]=await Promise.all([jo(()=>import("./core-B6cOHeaZ.js"),__vite__mapDeps([0,1,2]),import.meta.url),jo(()=>import("./engine-javascript-CSIo_1eZ.js"),__vite__mapDeps([3,1]),import.meta.url)]);return e({themes:[jo(()=>import("./github-light-DAi9KRSo.js"),[],import.meta.url),jo(()=>import("./github-dark-DHJKELXO.js"),[],import.meta.url)],langs:[jo(()=>import("./javascript-ySlJ1b_l.js"),[],import.meta.url),jo(()=>import("./typescript-Dj6nwHGl.js"),[],import.meta.url),jo(()=>import("./tsx-B6W0miNI.js"),[],import.meta.url),jo(()=>import("./jsx-BAng5TT0.js"),[],import.meta.url),jo(()=>import("./json-BQoSv7ci.js"),[],import.meta.url),jo(()=>import("./bash-atvbtKCR.js"),[],import.meta.url),jo(()=>import("./markdown-UIAJJxZW.js"),[],import.meta.url),jo(()=>import("./python-DhUJRlN_.js"),[],import.meta.url)],engine:t()})})()),YK}async function Nzn(e,t){const n=jzn[t?.toLowerCase()];if(!n)return null;const r=await Tzn(),{tokens:s}=r.codeToTokens(e,{lang:n,defaultColor:!1,themes:{light:"github-light",dark:"github-dark"}});return s}function Izn(e){return new NO(Ewe.define(e))}const Cxt=[Km.of({name:"JavaScript",alias:["ecmascript","js","node"],extensions:["js","mjs","cjs"],load(){return jo(()=>Promise.resolve().then(()=>b6),void 0,import.meta.url).then(e=>e.javascript())}}),Km.of({name:"JSON",alias:["json5"],extensions:["json","map"],load(){return jo(()=>Promise.resolve().then(()=>l5n),void 0,import.meta.url).then(e=>e.json())}}),Km.of({name:"JSX",extensions:["jsx"],load(){return jo(()=>Promise.resolve().then(()=>b6),void 0,import.meta.url).then(e=>e.javascript({jsx:!0}))}}),Km.of({name:"Markdown",extensions:["md","markdown","mkd"],load(){return jo(()=>Promise.resolve().then(()=>nFn),void 0,import.meta.url).then(e=>e.markdown())}}),Km.of({name:"TSX",extensions:["tsx"],load(){return jo(()=>Promise.resolve().then(()=>b6),void 0,import.meta.url).then(e=>e.javascript({jsx:!0,typescript:!0}))}}),Km.of({name:"TypeScript",alias:["ts"],extensions:["ts","mts","cts"],load(){return jo(()=>Promise.resolve().then(()=>b6),void 0,import.meta.url).then(e=>e.javascript({typescript:!0}))}}),Km.of({name:"Shell",alias:["bash","sh","zsh"],extensions:["sh","ksh","bash"],filename:/^PKGBUILD$/,load(){return jo(()=>import("./shell-CjFT_Tl9.js"),[],import.meta.url).then(e=>Izn(e.shell))}})];function Azn(e,t=5){if(!e?.properties)return[];const n=[];function r(s,a,i){if(i>t)return;const l=Array.isArray(s.type)?s.type.join(" | "):s.type;if(n.push({path:a,label:a,description:s.description??s.title,type:l}),s.properties)for(const[c,u]of Object.entries(s.properties))r(u,`${a}.${c}`,i+1);if(s.items?.properties)for(const[c,u]of Object.entries(s.items.properties))r(u,`${a}[].${c}`,i+1)}for(const[s,a]of Object.entries(e.properties))r(a,s,1);return n}function Rzn(e){const t=Azn(e);return yyt({override:[Pzn(t)],defaultKeymap:!0,closeOnBlur:!0,icons:!1})}function Pzn(e){return t=>{const r=t.state.sliceDoc(Math.max(0,t.pos-50),t.pos).match(/\{\{([a-zA-Z0-9_.\[\]]*)?$/);if(!r)return null;const s=r[1]??"",a=t.pos-s.length,i=s?e.filter(c=>c.path.toLowerCase().startsWith(s.toLowerCase())):e;if(i.length===0)return null;const l=i.map(c=>({label:c.path,displayLabel:c.path,detail:c.type,info:c.description,apply:(u,d,f,p)=>{const v=u.state.sliceDoc(p,p+2)==="}}"?d.label:`${d.label}}}`;u.dispatch({changes:{from:f,to:p,insert:v},selection:{anchor:f+v.length}})}}));return{from:a,options:l,validFor:/^[a-zA-Z0-9_.\[\]]*$/}}}const $zn=/\{\{([a-zA-Z_][a-zA-Z0-9_]*(?:\.[a-zA-Z_][a-zA-Z0-9_]*)*)\}\}/g,Mzn=Cn.mark({class:"cm-variable-highlight"}),_6e=new Avt({regexp:$zn,decoration:()=>Mzn}),Dzn=bo.fromClass(class{decorations;constructor(e){this.decorations=_6e.createDeco(e)}update(e){this.decorations=_6e.updateDeco(e,this.decorations)}},{decorations:e=>e.decorations}),Lzn=Dzn;function Fzn(){const e=UN({settings:{fontFamily:"var(--font-mono)",fontSize:"0.8rem",lineHighlight:"transparent",gutterBackground:"transparent",gutterForeground:"var(--neutral2)",background:"transparent",foreground:"var(--neutral6)",caret:"var(--neutral6)"},styles:[{tag:[fe.className,fe.propertyName],color:"var(--neutral6)"},{tag:fe.heading,color:"var(--accent3)",fontWeight:"bold"},{tag:[fe.heading1,fe.heading2,fe.heading3,fe.heading4,fe.heading5,fe.heading6],color:"var(--accent3)",fontWeight:"bold"},{tag:fe.emphasis,fontStyle:"italic",color:"var(--neutral6)"},{tag:fe.strong,fontWeight:"bold",color:"var(--neutral6)"},{tag:fe.link,color:"var(--accent3)",textDecoration:"underline"},{tag:fe.url,color:"var(--accent3)"},{tag:fe.monospace,color:"var(--neutral6)"},{tag:fe.strikethrough,textDecoration:"line-through"},{tag:fe.quote,fontStyle:"italic",color:"var(--neutral2)"}]}),t=It.theme({".cm-editor":{backgroundColor:"transparent"},".cm-content":{color:"var(--neutral6)",caretColor:"var(--neutral6)"},".cm-lineNumbers .cm-gutterElement":{color:"var(--neutral2)"},".cm-activeLineGutter":{color:"var(--neutral3)"},".cm-cursor":{borderLeftColor:"var(--neutral6)"},".cm-selectionBackground, .cm-content ::selection":{backgroundColor:"color-mix(in srgb, var(--accent3) 22%, transparent)"},".cm-tooltip-autocomplete":{backgroundColor:"var(--surface2)",border:"1px solid var(--border1)",borderRadius:"6px",boxShadow:"0 8px 16px rgba(0, 0, 0, 0.2)"},".cm-tooltip-autocomplete > ul":{fontFamily:"var(--font-mono)"},".cm-completionLabel":{color:"var(--neutral6)"},".cm-completionDetail":{color:"var(--neutral3)",fontSize:"0.7rem",marginLeft:"auto",paddingLeft:"12px"},".cm-completionInfo":{backgroundColor:"var(--surface2)",border:"1px solid var(--border1)",color:"var(--neutral3)",padding:"8px 12px"},".cm-completionIcon":{display:"none"},"ul.cm-completionList li[aria-selected]":{backgroundColor:"var(--surface4)",color:"var(--neutral6)"},".cm-line .cm-variable-highlight":{color:"var(--accent6) !important",fontWeight:"500"}});return[e,t]}function zzn(){const e=It.theme({"&":{backgroundColor:"transparent",color:"var(--neutral6)",fontSize:"0.8rem"},"&.cm-editor .cm-scroller":{fontFamily:"var(--font-mono)"},".cm-gutters":{backgroundColor:"transparent",color:"var(--neutral2)",borderRight:"none"},".cm-content":{color:"var(--neutral6)",caretColor:"var(--neutral6)"},".cm-activeLine":{backgroundColor:"transparent"},".cm-lineNumbers .cm-gutterElement":{color:"var(--neutral2)"},".cm-activeLineGutter":{backgroundColor:"transparent",color:"var(--neutral3)"},".cm-cursor, .cm-dropCursor":{borderLeftColor:"var(--neutral6)"},"&.cm-focused .cm-selectionBackground, & .cm-line::selection, & .cm-selectionLayer .cm-selectionBackground, .cm-content ::selection":{background:"color-mix(in srgb, var(--accent3) 22%, transparent) !important"},".cm-tooltip-autocomplete":{backgroundColor:"var(--surface2)",border:"1px solid var(--border1)",borderRadius:"6px",boxShadow:"0 8px 16px rgba(0, 0, 0, 0.2)"},".cm-tooltip-autocomplete > ul":{fontFamily:"var(--font-mono)"},".cm-completionLabel":{color:"var(--neutral6)"},".cm-completionDetail":{color:"var(--neutral3)",fontSize:"0.7rem",marginLeft:"auto",paddingLeft:"12px"},".cm-completionInfo":{backgroundColor:"var(--surface2)",border:"1px solid var(--border1)",color:"var(--neutral3)",padding:"8px 12px"},".cm-completionIcon":{display:"none"},"ul.cm-completionList li[aria-selected]":{backgroundColor:"var(--surface4)",color:"var(--neutral6)"},".cm-line .cm-variable-highlight":{color:"var(--accent6) !important",fontWeight:"500"}}),t=Dg.define([{tag:[fe.comment,fe.bracket],color:"var(--neutral2)"},{tag:[fe.string,fe.meta,fe.regexp],color:"var(--accent1)"},{tag:[fe.atom,fe.bool,fe.special(fe.variableName)],color:"var(--accent6)"},{tag:[fe.keyword,fe.operator,fe.tagName],color:"var(--accent2)"},{tag:[fe.function(fe.propertyName),fe.propertyName],color:"var(--accent5)"},{tag:[fe.definition(fe.variableName),fe.function(fe.variableName),fe.className,fe.attributeName],color:"var(--accent3)"},{tag:[fe.variableName,fe.number],color:"var(--accent5)"},{tag:[fe.name,fe.quote],color:"var(--accent1)"},{tag:fe.heading,color:"var(--accent3)",fontWeight:"bold"},{tag:[fe.heading1,fe.heading2,fe.heading3,fe.heading4,fe.heading5,fe.heading6],color:"var(--accent3)",fontWeight:"bold"},{tag:[fe.emphasis],fontStyle:"italic",color:"var(--neutral6)"},{tag:[fe.strong],fontWeight:"bold",color:"var(--neutral6)"},{tag:fe.link,color:"var(--accent3)",textDecoration:"underline"},{tag:fe.url,color:"var(--accent3)"},{tag:fe.monospace,color:"var(--neutral6)"},{tag:fe.strikethrough,textDecoration:"line-through"},{tag:[fe.deleted],color:"var(--accent2)"},{tag:fe.invalid,color:"var(--error)"},{tag:[fe.standard(fe.tagName)],color:"var(--accent1)"}]);return[e,B1(t)]}const My=()=>{const e=PN().resolvedTheme==="dark";return g.useMemo(()=>e?Fzn():zzn(),[e])},Qr=g.forwardRef(({data:e,value:t,onChange:n,showCopyButton:r=!0,className:s,language:a="json",highlightVariables:i=!1,placeholder:l,schema:c,autoFocus:u,lineNumbers:d=!0,lineWrapping:f=!0,editable:p,...h},m)=>{const v=My(),y=e?JSON.stringify(e,null,2):t??"",b=g.useMemo(()=>{const S=[];return f&&S.push(It.lineWrapping),a==="json"?S.push(ff):a==="markdown"&&S.push(e1e({base:RO,codeLanguages:Cxt})),i&&a==="markdown"&&S.push(Lzn),c&&a==="markdown"&&S.push(Rzn(c)),p===!1&&S.push(is.readOnly.of(!0)),S},[a,i,c,p,f]);return o.jsxs("div",{className:K("rounded-md bg-surface3 p-1 font-mono relative border border-border1 overflow-hidden",s),...h,children:[r&&o.jsx(Oa,{content:y,className:"absolute top-2 right-2 z-20"}),o.jsx(ru,{ref:m,value:y,theme:v,extensions:b,onChange:n,editable:p,"aria-label":"Code editor",placeholder:l,height:"100%",style:{height:"100%"},autoFocus:u,basicSetup:{lineNumbers:d}})]})}),Bzn=e=>{try{return JSON.stringify(e??{},null,2)}catch{return"{}"}},Uzn=({editorClassName:e="h-[240px] max-h-[40vh]",onSaved:t})=>{const n=My(),{settings:r,setSettings:s}=tV(),a=r?.tracingOptions,i=g.useMemo(()=>Bzn(a),[a]),[l,c]=g.useState(()=>i),u=g.useRef(!1);g.useEffect(()=>{u.current||c(i)},[i]);const d=p=>{u.current=!0,c(p)},f=()=>{if(!l){s({...r,tracingOptions:void 0}),t?.();return}try{const p=JSON.parse(l);typeof p=="object"&&p!==null&&s({...r,tracingOptions:p})}catch{return}t?.()};return o.jsxs("div",{className:"space-y-2 px-5 py-2",children:[o.jsx(ge,{as:"h3",variant:"ui-md",className:"text-neutral3",children:"Tracing Options"}),o.jsx(ru,{value:l,onChange:d,theme:n,extensions:[ff],className:K("overflow-y-scroll bg-surface3 rounded-lg overflow-hidden p-3",e)}),o.jsx("div",{className:"flex items-center justify-end",children:o.jsx(de,{type:"button",onClick:f,children:"Save"})})]})},qzn=()=>{const[e,t]=g.useState(!1);return o.jsxs(o.Fragment,{children:[o.jsxs(Wn,{children:[o.jsx(zn,{asChild:!0,children:o.jsx(de,{type:"button",variant:"ghost",size:"icon-md","aria-label":"Run Options",onClick:()=>t(!0),children:o.jsx(Ue,{children:o.jsx(hq,{})})})}),o.jsx(Bn,{children:"Run Options"})]}),o.jsx(br,{open:e,onOpenChange:t,children:o.jsxs(xr,{children:[o.jsxs(wr,{children:[o.jsx(gr,{children:"Run Options"}),o.jsx(Qs,{children:"Configure tracing and debug options for this workflow run"})]}),o.jsx(Rr,{children:o.jsx(Uzn,{onSaved:()=>t(!1)})})]})})]})};function Vzn({status:e}){switch(e){case"running":return o.jsx(Gt,{});case"failed":return o.jsx(vs,{className:"text-accent2"});case"canceled":return o.jsx(Of,{className:"text-neutral3"});case"pending":case"waiting":return o.jsx(dO,{className:"text-neutral3"});case"suspended":return o.jsx(lq,{className:"text-accent3"});case"success":return o.jsx(Js,{className:"text-accent1"});default:return o.jsx(dO,{className:"text-neutral3"})}}function Ext({status:e}){return o.jsxs(Wn,{children:[o.jsx(zn,{asChild:!0,children:o.jsx(Ue,{"aria-label":e,className:"shrink-0",children:o.jsx(Vzn,{status:e})})}),o.jsx(Bn,{children:e})]})}var XK,C6e;function c1e(){if(C6e)return XK;C6e=1;var e="\0",t="\0",n="";class r{_isDirected=!0;_isMultigraph=!1;_isCompound=!1;_label;_defaultNodeLabelFn=()=>{};_defaultEdgeLabelFn=()=>{};_nodes={};_in={};_preds={};_out={};_sucs={};_edgeObjs={};_edgeLabels={};_nodeCount=0;_edgeCount=0;_parent;_children;constructor(d){d&&(this._isDirected=Object.hasOwn(d,"directed")?d.directed:!0,this._isMultigraph=Object.hasOwn(d,"multigraph")?d.multigraph:!1,this._isCompound=Object.hasOwn(d,"compound")?d.compound:!1),this._isCompound&&(this._parent={},this._children={},this._children[t]={})}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph(d){return this._label=d,this}graph(){return this._label}setDefaultNodeLabel(d){return this._defaultNodeLabelFn=d,typeof d!="function"&&(this._defaultNodeLabelFn=()=>d),this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){var d=this;return this.nodes().filter(f=>Object.keys(d._in[f]).length===0)}sinks(){var d=this;return this.nodes().filter(f=>Object.keys(d._out[f]).length===0)}setNodes(d,f){var p=arguments,h=this;return d.forEach(function(m){p.length>1?h.setNode(m,f):h.setNode(m)}),this}setNode(d,f){return Object.hasOwn(this._nodes,d)?(arguments.length>1&&(this._nodes[d]=f),this):(this._nodes[d]=arguments.length>1?f:this._defaultNodeLabelFn(d),this._isCompound&&(this._parent[d]=t,this._children[d]={},this._children[t][d]=!0),this._in[d]={},this._preds[d]={},this._out[d]={},this._sucs[d]={},++this._nodeCount,this)}node(d){return this._nodes[d]}hasNode(d){return Object.hasOwn(this._nodes,d)}removeNode(d){var f=this;if(Object.hasOwn(this._nodes,d)){var p=h=>f.removeEdge(f._edgeObjs[h]);delete this._nodes[d],this._isCompound&&(this._removeFromParentsChildList(d),delete this._parent[d],this.children(d).forEach(function(h){f.setParent(h)}),delete this._children[d]),Object.keys(this._in[d]).forEach(p),delete this._in[d],delete this._preds[d],Object.keys(this._out[d]).forEach(p),delete this._out[d],delete this._sucs[d],--this._nodeCount}return this}setParent(d,f){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(f===void 0)f=t;else{f+="";for(var p=f;p!==void 0;p=this.parent(p))if(p===d)throw new Error("Setting "+f+" as parent of "+d+" would create a cycle");this.setNode(f)}return this.setNode(d),this._removeFromParentsChildList(d),this._parent[d]=f,this._children[f][d]=!0,this}_removeFromParentsChildList(d){delete this._children[this._parent[d]][d]}parent(d){if(this._isCompound){var f=this._parent[d];if(f!==t)return f}}children(d=t){if(this._isCompound){var f=this._children[d];if(f)return Object.keys(f)}else{if(d===t)return this.nodes();if(this.hasNode(d))return[]}}predecessors(d){var f=this._preds[d];if(f)return Object.keys(f)}successors(d){var f=this._sucs[d];if(f)return Object.keys(f)}neighbors(d){var f=this.predecessors(d);if(f){const h=new Set(f);for(var p of this.successors(d))h.add(p);return Array.from(h.values())}}isLeaf(d){var f;return this.isDirected()?f=this.successors(d):f=this.neighbors(d),f.length===0}filterNodes(d){var f=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});f.setGraph(this.graph());var p=this;Object.entries(this._nodes).forEach(function([v,y]){d(v)&&f.setNode(v,y)}),Object.values(this._edgeObjs).forEach(function(v){f.hasNode(v.v)&&f.hasNode(v.w)&&f.setEdge(v,p.edge(v))});var h={};function m(v){var y=p.parent(v);return y===void 0||f.hasNode(y)?(h[v]=y,y):y in h?h[y]:m(y)}return this._isCompound&&f.nodes().forEach(v=>f.setParent(v,m(v))),f}setDefaultEdgeLabel(d){return this._defaultEdgeLabelFn=d,typeof d!="function"&&(this._defaultEdgeLabelFn=()=>d),this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(d,f){var p=this,h=arguments;return d.reduce(function(m,v){return h.length>1?p.setEdge(m,v,f):p.setEdge(m,v),v}),this}setEdge(){var d,f,p,h,m=!1,v=arguments[0];typeof v=="object"&&v!==null&&"v"in v?(d=v.v,f=v.w,p=v.name,arguments.length===2&&(h=arguments[1],m=!0)):(d=v,f=arguments[1],p=arguments[3],arguments.length>2&&(h=arguments[2],m=!0)),d=""+d,f=""+f,p!==void 0&&(p=""+p);var y=i(this._isDirected,d,f,p);if(Object.hasOwn(this._edgeLabels,y))return m&&(this._edgeLabels[y]=h),this;if(p!==void 0&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(d),this.setNode(f),this._edgeLabels[y]=m?h:this._defaultEdgeLabelFn(d,f,p);var b=l(this._isDirected,d,f,p);return d=b.v,f=b.w,Object.freeze(b),this._edgeObjs[y]=b,s(this._preds[f],d),s(this._sucs[d],f),this._in[f][y]=b,this._out[d][y]=b,this._edgeCount++,this}edge(d,f,p){var h=arguments.length===1?c(this._isDirected,arguments[0]):i(this._isDirected,d,f,p);return this._edgeLabels[h]}edgeAsObj(){const d=this.edge(...arguments);return typeof d!="object"?{label:d}:d}hasEdge(d,f,p){var h=arguments.length===1?c(this._isDirected,arguments[0]):i(this._isDirected,d,f,p);return Object.hasOwn(this._edgeLabels,h)}removeEdge(d,f,p){var h=arguments.length===1?c(this._isDirected,arguments[0]):i(this._isDirected,d,f,p),m=this._edgeObjs[h];return m&&(d=m.v,f=m.w,delete this._edgeLabels[h],delete this._edgeObjs[h],a(this._preds[f],d),a(this._sucs[d],f),delete this._in[f][h],delete this._out[d][h],this._edgeCount--),this}inEdges(d,f){var p=this._in[d];if(p){var h=Object.values(p);return f?h.filter(m=>m.v===f):h}}outEdges(d,f){var p=this._out[d];if(p){var h=Object.values(p);return f?h.filter(m=>m.w===f):h}}nodeEdges(d,f){var p=this.inEdges(d,f);if(p)return p.concat(this.outEdges(d,f))}}function s(u,d){u[d]?u[d]++:u[d]=1}function a(u,d){--u[d]||delete u[d]}function i(u,d,f,p){var h=""+d,m=""+f;if(!u&&h>m){var v=h;h=m,m=v}return h+n+m+n+(p===void 0?e:p)}function l(u,d,f,p){var h=""+d,m=""+f;if(!u&&h>m){var v=h;h=m,m=v}var y={v:h,w:m};return p&&(y.name=p),y}function c(u,d){return i(u,d.v,d.w,d.name)}return XK=r,XK}var KK,E6e;function Hzn(){return E6e||(E6e=1,KK="2.2.4"),KK}var JK,j6e;function Wzn(){return j6e||(j6e=1,JK={Graph:c1e(),version:Hzn()}),JK}var eJ,T6e;function Zzn(){if(T6e)return eJ;T6e=1;var e=c1e();eJ={write:t,read:s};function t(a){var i={options:{directed:a.isDirected(),multigraph:a.isMultigraph(),compound:a.isCompound()},nodes:n(a),edges:r(a)};return a.graph()!==void 0&&(i.value=structuredClone(a.graph())),i}function n(a){return a.nodes().map(function(i){var l=a.node(i),c=a.parent(i),u={v:i};return l!==void 0&&(u.value=l),c!==void 0&&(u.parent=c),u})}function r(a){return a.edges().map(function(i){var l=a.edge(i),c={v:i.v,w:i.w};return i.name!==void 0&&(c.name=i.name),l!==void 0&&(c.value=l),c})}function s(a){var i=new e(a.options).setGraph(a.value);return a.nodes.forEach(function(l){i.setNode(l.v,l.value),l.parent&&i.setParent(l.v,l.parent)}),a.edges.forEach(function(l){i.setEdge({v:l.v,w:l.w,name:l.name},l.value)}),i}return eJ}var tJ,N6e;function Gzn(){if(N6e)return tJ;N6e=1,tJ=e;function e(t){var n={},r=[],s;function a(i){Object.hasOwn(n,i)||(n[i]=!0,s.push(i),t.successors(i).forEach(a),t.predecessors(i).forEach(a))}return t.nodes().forEach(function(i){s=[],a(i),s.length&&r.push(s)}),r}return tJ}var nJ,I6e;function jxt(){if(I6e)return nJ;I6e=1;class e{_arr=[];_keyIndices={};size(){return this._arr.length}keys(){return this._arr.map(function(n){return n.key})}has(n){return Object.hasOwn(this._keyIndices,n)}priority(n){var r=this._keyIndices[n];if(r!==void 0)return this._arr[r].priority}min(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key}add(n,r){var s=this._keyIndices;if(n=String(n),!Object.hasOwn(s,n)){var a=this._arr,i=a.length;return s[n]=i,a.push({key:n,priority:r}),this._decrease(i),!0}return!1}removeMin(){this._swap(0,this._arr.length-1);var n=this._arr.pop();return delete this._keyIndices[n.key],this._heapify(0),n.key}decrease(n,r){var s=this._keyIndices[n];if(r>this._arr[s].priority)throw new Error("New priority is greater than current priority. Key: "+n+" Old: "+this._arr[s].priority+" New: "+r);this._arr[s].priority=r,this._decrease(s)}_heapify(n){var r=this._arr,s=2*n,a=s+1,i=n;s<r.length&&(i=r[s].priority<r[i].priority?s:i,a<r.length&&(i=r[a].priority<r[i].priority?a:i),i!==n&&(this._swap(n,i),this._heapify(i)))}_decrease(n){for(var r=this._arr,s=r[n].priority,a;n!==0&&(a=n>>1,!(r[a].priority<s));)this._swap(n,a),n=a}_swap(n,r){var s=this._arr,a=this._keyIndices,i=s[n],l=s[r];s[n]=l,s[r]=i,a[l.key]=n,a[i.key]=r}}return nJ=e,nJ}var rJ,A6e;function Txt(){if(A6e)return rJ;A6e=1;var e=jxt();rJ=n;var t=()=>1;function n(s,a,i,l){return r(s,String(a),i||t,l||function(c){return s.outEdges(c)})}function r(s,a,i,l){var c={},u=new e,d,f,p=function(h){var m=h.v!==d?h.v:h.w,v=c[m],y=i(h),b=f.distance+y;if(y<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+h+" Weight: "+y);b<v.distance&&(v.distance=b,v.predecessor=d,u.decrease(m,b))};for(s.nodes().forEach(function(h){var m=h===a?0:Number.POSITIVE_INFINITY;c[h]={distance:m},u.add(h,m)});u.size()>0&&(d=u.removeMin(),f=c[d],f.distance!==Number.POSITIVE_INFINITY);)l(d).forEach(p);return c}return rJ}var sJ,R6e;function Qzn(){if(R6e)return sJ;R6e=1;var e=Txt();sJ=t;function t(n,r,s){return n.nodes().reduce(function(a,i){return a[i]=e(n,i,r,s),a},{})}return sJ}var aJ,P6e;function Nxt(){if(P6e)return aJ;P6e=1,aJ=e;function e(t){var n=0,r=[],s={},a=[];function i(l){var c=s[l]={onStack:!0,lowlink:n,index:n++};if(r.push(l),t.successors(l).forEach(function(f){Object.hasOwn(s,f)?s[f].onStack&&(c.lowlink=Math.min(c.lowlink,s[f].index)):(i(f),c.lowlink=Math.min(c.lowlink,s[f].lowlink))}),c.lowlink===c.index){var u=[],d;do d=r.pop(),s[d].onStack=!1,u.push(d);while(l!==d);a.push(u)}}return t.nodes().forEach(function(l){Object.hasOwn(s,l)||i(l)}),a}return aJ}var iJ,$6e;function Yzn(){if($6e)return iJ;$6e=1;var e=Nxt();iJ=t;function t(n){return e(n).filter(function(r){return r.length>1||r.length===1&&n.hasEdge(r[0],r[0])})}return iJ}var oJ,M6e;function Xzn(){if(M6e)return oJ;M6e=1,oJ=t;var e=()=>1;function t(r,s,a){return n(r,s||e,a||function(i){return r.outEdges(i)})}function n(r,s,a){var i={},l=r.nodes();return l.forEach(function(c){i[c]={},i[c][c]={distance:0},l.forEach(function(u){c!==u&&(i[c][u]={distance:Number.POSITIVE_INFINITY})}),a(c).forEach(function(u){var d=u.v===c?u.w:u.v,f=s(u);i[c][d]={distance:f,predecessor:c}})}),l.forEach(function(c){var u=i[c];l.forEach(function(d){var f=i[d];l.forEach(function(p){var h=f[c],m=u[p],v=f[p],y=h.distance+m.distance;y<v.distance&&(v.distance=y,v.predecessor=m.predecessor)})})}),i}return oJ}var lJ,D6e;function Ixt(){if(D6e)return lJ;D6e=1;function e(n){var r={},s={},a=[];function i(l){if(Object.hasOwn(s,l))throw new t;Object.hasOwn(r,l)||(s[l]=!0,r[l]=!0,n.predecessors(l).forEach(i),delete s[l],a.push(l))}if(n.sinks().forEach(i),Object.keys(r).length!==n.nodeCount())throw new t;return a}class t extends Error{constructor(){super(...arguments)}}return lJ=e,e.CycleException=t,lJ}var cJ,L6e;function Kzn(){if(L6e)return cJ;L6e=1;var e=Ixt();cJ=t;function t(n){try{e(n)}catch(r){if(r instanceof e.CycleException)return!1;throw r}return!0}return cJ}var uJ,F6e;function Axt(){if(F6e)return uJ;F6e=1,uJ=e;function e(s,a,i){Array.isArray(a)||(a=[a]);var l=s.isDirected()?f=>s.successors(f):f=>s.neighbors(f),c=i==="post"?t:n,u=[],d={};return a.forEach(f=>{if(!s.hasNode(f))throw new Error("Graph does not have node: "+f);c(f,l,d,u)}),u}function t(s,a,i,l){for(var c=[[s,!1]];c.length>0;){var u=c.pop();u[1]?l.push(u[0]):Object.hasOwn(i,u[0])||(i[u[0]]=!0,c.push([u[0],!0]),r(a(u[0]),d=>c.push([d,!1])))}}function n(s,a,i,l){for(var c=[s];c.length>0;){var u=c.pop();Object.hasOwn(i,u)||(i[u]=!0,l.push(u),r(a(u),d=>c.push(d)))}}function r(s,a){for(var i=s.length;i--;)a(s[i],i,s);return s}return uJ}var dJ,z6e;function Jzn(){if(z6e)return dJ;z6e=1;var e=Axt();dJ=t;function t(n,r){return e(n,r,"post")}return dJ}var fJ,B6e;function e7n(){if(B6e)return fJ;B6e=1;var e=Axt();fJ=t;function t(n,r){return e(n,r,"pre")}return fJ}var pJ,U6e;function t7n(){if(U6e)return pJ;U6e=1;var e=c1e(),t=jxt();pJ=n;function n(r,s){var a=new e,i={},l=new t,c;function u(f){var p=f.v===c?f.w:f.v,h=l.priority(p);if(h!==void 0){var m=s(f);m<h&&(i[p]=c,l.decrease(p,m))}}if(r.nodeCount()===0)return a;r.nodes().forEach(function(f){l.add(f,Number.POSITIVE_INFINITY),a.setNode(f)}),l.decrease(r.nodes()[0],0);for(var d=!1;l.size()>0;){if(c=l.removeMin(),Object.hasOwn(i,c))a.setEdge(c,i[c]);else{if(d)throw new Error("Input graph is not connected: "+r);d=!0}r.nodeEdges(c).forEach(u)}return a}return pJ}var hJ,q6e;function n7n(){return q6e||(q6e=1,hJ={components:Gzn(),dijkstra:Txt(),dijkstraAll:Qzn(),findCycles:Yzn(),floydWarshall:Xzn(),isAcyclic:Kzn(),postorder:Jzn(),preorder:e7n(),prim:t7n(),tarjan:Nxt(),topsort:Ixt()}),hJ}var mJ,V6e;function Tg(){if(V6e)return mJ;V6e=1;var e=Wzn();return mJ={Graph:e.Graph,json:Zzn(),alg:n7n(),version:e.version},mJ}var gJ,H6e;function r7n(){if(H6e)return gJ;H6e=1;class e{constructor(){let s={};s._next=s._prev=s,this._sentinel=s}dequeue(){let s=this._sentinel,a=s._prev;if(a!==s)return t(a),a}enqueue(s){let a=this._sentinel;s._prev&&s._next&&t(s),s._next=a._next,a._next._prev=s,a._next=s,s._prev=a}toString(){let s=[],a=this._sentinel,i=a._prev;for(;i!==a;)s.push(JSON.stringify(i,n)),i=i._prev;return"["+s.join(", ")+"]"}}function t(r){r._prev._next=r._next,r._next._prev=r._prev,delete r._next,delete r._prev}function n(r,s){if(r!=="_next"&&r!=="_prev")return s}return gJ=e,gJ}var vJ,W6e;function s7n(){if(W6e)return vJ;W6e=1;let e=Tg().Graph,t=r7n();vJ=r;let n=()=>1;function r(u,d){if(u.nodeCount()<=1)return[];let f=i(u,d||n);return s(f.graph,f.buckets,f.zeroIdx).flatMap(h=>u.outEdges(h.v,h.w))}function s(u,d,f){let p=[],h=d[d.length-1],m=d[0],v;for(;u.nodeCount();){for(;v=m.dequeue();)a(u,d,f,v);for(;v=h.dequeue();)a(u,d,f,v);if(u.nodeCount()){for(let y=d.length-2;y>0;--y)if(v=d[y].dequeue(),v){p=p.concat(a(u,d,f,v,!0));break}}}return p}function a(u,d,f,p,h){let m=h?[]:void 0;return u.inEdges(p.v).forEach(v=>{let y=u.edge(v),b=u.node(v.v);h&&m.push({v:v.v,w:v.w}),b.out-=y,l(d,f,b)}),u.outEdges(p.v).forEach(v=>{let y=u.edge(v),b=v.w,S=u.node(b);S.in-=y,l(d,f,S)}),u.removeNode(p.v),m}function i(u,d){let f=new e,p=0,h=0;u.nodes().forEach(y=>{f.setNode(y,{v:y,in:0,out:0})}),u.edges().forEach(y=>{let b=f.edge(y.v,y.w)||0,S=d(y),w=b+S;f.setEdge(y.v,y.w,w),h=Math.max(h,f.node(y.v).out+=S),p=Math.max(p,f.node(y.w).in+=S)});let m=c(h+p+3).map(()=>new t),v=p+1;return f.nodes().forEach(y=>{l(m,v,f.node(y))}),{graph:f,buckets:m,zeroIdx:v}}function l(u,d,f){f.out?f.in?u[f.out-f.in+d].enqueue(f):u[u.length-1].enqueue(f):u[0].enqueue(f)}function c(u){const d=[];for(let f=0;f<u;f++)d.push(f);return d}return vJ}var yJ,Z6e;function Nl(){if(Z6e)return yJ;Z6e=1;let e=Tg().Graph;yJ={addBorderNode:d,addDummyNode:t,applyWithChunking:h,asNonCompoundGraph:r,buildLayerMatrix:l,intersectRect:i,mapValues:C,maxRank:m,normalizeRanks:c,notime:b,partition:v,pick:_,predecessorWeights:a,range:k,removeEmptyRanks:u,simplify:n,successorWeights:s,time:y,uniqueId:w,zipObject:E};function t(j,N,I,R){for(var P=R;j.hasNode(P);)P=w(R);return I.dummy=N,j.setNode(P,I),P}function n(j){let N=new e().setGraph(j.graph());return j.nodes().forEach(I=>N.setNode(I,j.node(I))),j.edges().forEach(I=>{let R=N.edge(I.v,I.w)||{weight:0,minlen:1},P=j.edge(I);N.setEdge(I.v,I.w,{weight:R.weight+P.weight,minlen:Math.max(R.minlen,P.minlen)})}),N}function r(j){let N=new e({multigraph:j.isMultigraph()}).setGraph(j.graph());return j.nodes().forEach(I=>{j.children(I).length||N.setNode(I,j.node(I))}),j.edges().forEach(I=>{N.setEdge(I,j.edge(I))}),N}function s(j){let N=j.nodes().map(I=>{let R={};return j.outEdges(I).forEach(P=>{R[P.w]=(R[P.w]||0)+j.edge(P).weight}),R});return E(j.nodes(),N)}function a(j){let N=j.nodes().map(I=>{let R={};return j.inEdges(I).forEach(P=>{R[P.v]=(R[P.v]||0)+j.edge(P).weight}),R});return E(j.nodes(),N)}function i(j,N){let I=j.x,R=j.y,P=N.x-I,L=N.y-R,M=j.width/2,q=j.height/2;if(!P&&!L)throw new Error("Not possible to find intersection inside of the rectangle");let H,F;return Math.abs(L)*M>Math.abs(P)*q?(L<0&&(q=-q),H=q*P/L,F=q):(P<0&&(M=-M),H=M,F=M*L/P),{x:I+H,y:R+F}}function l(j){let N=k(m(j)+1).map(()=>[]);return j.nodes().forEach(I=>{let R=j.node(I),P=R.rank;P!==void 0&&(N[P][R.order]=I)}),N}function c(j){let N=j.nodes().map(R=>{let P=j.node(R).rank;return P===void 0?Number.MAX_VALUE:P}),I=h(Math.min,N);j.nodes().forEach(R=>{let P=j.node(R);Object.hasOwn(P,"rank")&&(P.rank-=I)})}function u(j){let N=j.nodes().map(M=>j.node(M).rank),I=h(Math.min,N),R=[];j.nodes().forEach(M=>{let q=j.node(M).rank-I;R[q]||(R[q]=[]),R[q].push(M)});let P=0,L=j.graph().nodeRankFactor;Array.from(R).forEach((M,q)=>{M===void 0&&q%L!==0?--P:M!==void 0&&P&&M.forEach(H=>j.node(H).rank+=P)})}function d(j,N,I,R){let P={width:0,height:0};return arguments.length>=4&&(P.rank=I,P.order=R),t(j,"border",P,N)}function f(j,N=p){const I=[];for(let R=0;R<j.length;R+=N){const P=j.slice(R,R+N);I.push(P)}return I}const p=65535;function h(j,N){if(N.length>p){const I=f(N);return j.apply(null,I.map(R=>j.apply(null,R)))}else return j.apply(null,N)}function m(j){const I=j.nodes().map(R=>{let P=j.node(R).rank;return P===void 0?Number.MIN_VALUE:P});return h(Math.max,I)}function v(j,N){let I={lhs:[],rhs:[]};return j.forEach(R=>{N(R)?I.lhs.push(R):I.rhs.push(R)}),I}function y(j,N){let I=Date.now();try{return N()}finally{console.log(j+" time: "+(Date.now()-I)+"ms")}}function b(j,N){return N()}let S=0;function w(j){var N=++S;return j+(""+N)}function k(j,N,I=1){N==null&&(N=j,j=0);let R=L=>L<N;I<0&&(R=L=>N<L);const P=[];for(let L=j;R(L);L+=I)P.push(L);return P}function _(j,N){const I={};for(const R of N)j[R]!==void 0&&(I[R]=j[R]);return I}function C(j,N){let I=N;return typeof N=="string"&&(I=R=>R[N]),Object.entries(j).reduce((R,[P,L])=>(R[P]=I(L,P),R),{})}function E(j,N){return j.reduce((I,R,P)=>(I[R]=N[P],I),{})}return yJ}var bJ,G6e;function a7n(){if(G6e)return bJ;G6e=1;let e=s7n(),t=Nl().uniqueId;bJ={run:n,undo:s};function n(a){(a.graph().acyclicer==="greedy"?e(a,l(a)):r(a)).forEach(c=>{let u=a.edge(c);a.removeEdge(c),u.forwardName=c.name,u.reversed=!0,a.setEdge(c.w,c.v,u,t("rev"))});function l(c){return u=>c.edge(u).weight}}function r(a){let i=[],l={},c={};function u(d){Object.hasOwn(c,d)||(c[d]=!0,l[d]=!0,a.outEdges(d).forEach(f=>{Object.hasOwn(l,f.w)?i.push(f):u(f.w)}),delete l[d])}return a.nodes().forEach(u),i}function s(a){a.edges().forEach(i=>{let l=a.edge(i);if(l.reversed){a.removeEdge(i);let c=l.forwardName;delete l.reversed,delete l.forwardName,a.setEdge(i.w,i.v,l,c)}})}return bJ}var xJ,Q6e;function i7n(){if(Q6e)return xJ;Q6e=1;let e=Nl();xJ={run:t,undo:r};function t(s){s.graph().dummyChains=[],s.edges().forEach(a=>n(s,a))}function n(s,a){let i=a.v,l=s.node(i).rank,c=a.w,u=s.node(c).rank,d=a.name,f=s.edge(a),p=f.labelRank;if(u===l+1)return;s.removeEdge(a);let h,m,v;for(v=0,++l;l<u;++v,++l)f.points=[],m={width:0,height:0,edgeLabel:f,edgeObj:a,rank:l},h=e.addDummyNode(s,"edge",m,"_d"),l===p&&(m.width=f.width,m.height=f.height,m.dummy="edge-label",m.labelpos=f.labelpos),s.setEdge(i,h,{weight:f.weight},d),v===0&&s.graph().dummyChains.push(h),i=h;s.setEdge(i,c,{weight:f.weight},d)}function r(s){s.graph().dummyChains.forEach(a=>{let i=s.node(a),l=i.edgeLabel,c;for(s.setEdge(i.edgeObj,l);i.dummy;)c=s.successors(a)[0],s.removeNode(a),l.points.push({x:i.x,y:i.y}),i.dummy==="edge-label"&&(l.x=i.x,l.y=i.y,l.width=i.width,l.height=i.height),a=c,i=s.node(a)})}return xJ}var wJ,Y6e;function T7(){if(Y6e)return wJ;Y6e=1;const{applyWithChunking:e}=Nl();wJ={longestPath:t,slack:n};function t(r){var s={};function a(i){var l=r.node(i);if(Object.hasOwn(s,i))return l.rank;s[i]=!0;let c=r.outEdges(i).map(d=>d==null?Number.POSITIVE_INFINITY:a(d.w)-r.edge(d).minlen);var u=e(Math.min,c);return u===Number.POSITIVE_INFINITY&&(u=0),l.rank=u}r.sources().forEach(a)}function n(r,s){return r.node(s.w).rank-r.node(s.v).rank-r.edge(s).minlen}return wJ}var SJ,X6e;function Rxt(){if(X6e)return SJ;X6e=1;var e=Tg().Graph,t=T7().slack;SJ=n;function n(i){var l=new e({directed:!1}),c=i.nodes()[0],u=i.nodeCount();l.setNode(c,{});for(var d,f;r(l,i)<u;)d=s(l,i),f=l.hasNode(d.v)?t(i,d):-t(i,d),a(l,i,f);return l}function r(i,l){function c(u){l.nodeEdges(u).forEach(d=>{var f=d.v,p=u===f?d.w:f;!i.hasNode(p)&&!t(l,d)&&(i.setNode(p,{}),i.setEdge(u,p,{}),c(p))})}return i.nodes().forEach(c),i.nodeCount()}function s(i,l){return l.edges().reduce((u,d)=>{let f=Number.POSITIVE_INFINITY;return i.hasNode(d.v)!==i.hasNode(d.w)&&(f=t(l,d)),f<u[0]?[f,d]:u},[Number.POSITIVE_INFINITY,null])[1]}function a(i,l,c){i.nodes().forEach(u=>l.node(u).rank+=c)}return SJ}var kJ,K6e;function o7n(){if(K6e)return kJ;K6e=1;var e=Rxt(),t=T7().slack,n=T7().longestPath,r=Tg().alg.preorder,s=Tg().alg.postorder,a=Nl().simplify;kJ=i,i.initLowLimValues=d,i.initCutValues=l,i.calcCutValue=u,i.leaveEdge=p,i.enterEdge=h,i.exchangeEdges=m;function i(S){S=a(S),n(S);var w=e(S);d(w),l(w,S);for(var k,_;k=p(w);)_=h(w,S,k),m(w,S,k,_)}function l(S,w){var k=s(S,S.nodes());k=k.slice(0,k.length-1),k.forEach(_=>c(S,w,_))}function c(S,w,k){var _=S.node(k),C=_.parent;S.edge(k,C).cutvalue=u(S,w,k)}function u(S,w,k){var _=S.node(k),C=_.parent,E=!0,j=w.edge(k,C),N=0;return j||(E=!1,j=w.edge(C,k)),N=j.weight,w.nodeEdges(k).forEach(I=>{var R=I.v===k,P=R?I.w:I.v;if(P!==C){var L=R===E,M=w.edge(I).weight;if(N+=L?M:-M,y(S,k,P)){var q=S.edge(k,P).cutvalue;N+=L?-q:q}}}),N}function d(S,w){arguments.length<2&&(w=S.nodes()[0]),f(S,{},1,w)}function f(S,w,k,_,C){var E=k,j=S.node(_);return w[_]=!0,S.neighbors(_).forEach(N=>{Object.hasOwn(w,N)||(k=f(S,w,k,N,_))}),j.low=E,j.lim=k++,C?j.parent=C:delete j.parent,k}function p(S){return S.edges().find(w=>S.edge(w).cutvalue<0)}function h(S,w,k){var _=k.v,C=k.w;w.hasEdge(_,C)||(_=k.w,C=k.v);var E=S.node(_),j=S.node(C),N=E,I=!1;E.lim>j.lim&&(N=j,I=!0);var R=w.edges().filter(P=>I===b(S,S.node(P.v),N)&&I!==b(S,S.node(P.w),N));return R.reduce((P,L)=>t(w,L)<t(w,P)?L:P)}function m(S,w,k,_){var C=k.v,E=k.w;S.removeEdge(C,E),S.setEdge(_.v,_.w,{}),d(S),l(S,w),v(S,w)}function v(S,w){var k=S.nodes().find(C=>!w.node(C).parent),_=r(S,k);_=_.slice(1),_.forEach(C=>{var E=S.node(C).parent,j=w.edge(C,E),N=!1;j||(j=w.edge(E,C),N=!0),w.node(C).rank=w.node(E).rank+(N?j.minlen:-j.minlen)})}function y(S,w,k){return S.hasEdge(w,k)}function b(S,w,k){return k.low<=w.lim&&w.lim<=k.lim}return kJ}var OJ,J6e;function l7n(){if(J6e)return OJ;J6e=1;var e=T7(),t=e.longestPath,n=Rxt(),r=o7n();OJ=s;function s(c){var u=c.graph().ranker;if(u instanceof Function)return u(c);switch(c.graph().ranker){case"network-simplex":l(c);break;case"tight-tree":i(c);break;case"longest-path":a(c);break;case"none":break;default:l(c)}}var a=t;function i(c){t(c),n(c)}function l(c){r(c)}return OJ}var _J,e9e;function c7n(){if(e9e)return _J;e9e=1,_J=e;function e(r){let s=n(r);r.graph().dummyChains.forEach(a=>{let i=r.node(a),l=i.edgeObj,c=t(r,s,l.v,l.w),u=c.path,d=c.lca,f=0,p=u[f],h=!0;for(;a!==l.w;){if(i=r.node(a),h){for(;(p=u[f])!==d&&r.node(p).maxRank<i.rank;)f++;p===d&&(h=!1)}if(!h){for(;f<u.length-1&&r.node(p=u[f+1]).minRank<=i.rank;)f++;p=u[f]}r.setParent(a,p),a=r.successors(a)[0]}})}function t(r,s,a,i){let l=[],c=[],u=Math.min(s[a].low,s[i].low),d=Math.max(s[a].lim,s[i].lim),f,p;f=a;do f=r.parent(f),l.push(f);while(f&&(s[f].low>u||d>s[f].lim));for(p=f,f=i;(f=r.parent(f))!==p;)c.push(f);return{path:l.concat(c.reverse()),lca:p}}function n(r){let s={},a=0;function i(l){let c=a;r.children(l).forEach(i),s[l]={low:c,lim:a++}}return r.children().forEach(i),s}return _J}var CJ,t9e;function u7n(){if(t9e)return CJ;t9e=1;let e=Nl();CJ={run:t,cleanup:a};function t(i){let l=e.addDummyNode(i,"root",{},"_root"),c=r(i),u=Object.values(c),d=e.applyWithChunking(Math.max,u)-1,f=2*d+1;i.graph().nestingRoot=l,i.edges().forEach(h=>i.edge(h).minlen*=f);let p=s(i)+1;i.children().forEach(h=>n(i,l,f,p,d,c,h)),i.graph().nodeRankFactor=f}function n(i,l,c,u,d,f,p){let h=i.children(p);if(!h.length){p!==l&&i.setEdge(l,p,{weight:0,minlen:c});return}let m=e.addBorderNode(i,"_bt"),v=e.addBorderNode(i,"_bb"),y=i.node(p);i.setParent(m,p),y.borderTop=m,i.setParent(v,p),y.borderBottom=v,h.forEach(b=>{n(i,l,c,u,d,f,b);let S=i.node(b),w=S.borderTop?S.borderTop:b,k=S.borderBottom?S.borderBottom:b,_=S.borderTop?u:2*u,C=w!==k?1:d-f[p]+1;i.setEdge(m,w,{weight:_,minlen:C,nestingEdge:!0}),i.setEdge(k,v,{weight:_,minlen:C,nestingEdge:!0})}),i.parent(p)||i.setEdge(l,m,{weight:0,minlen:d+f[p]})}function r(i){var l={};function c(u,d){var f=i.children(u);f&&f.length&&f.forEach(p=>c(p,d+1)),l[u]=d}return i.children().forEach(u=>c(u,1)),l}function s(i){return i.edges().reduce((l,c)=>l+i.edge(c).weight,0)}function a(i){var l=i.graph();i.removeNode(l.nestingRoot),delete l.nestingRoot,i.edges().forEach(c=>{var u=i.edge(c);u.nestingEdge&&i.removeEdge(c)})}return CJ}var EJ,n9e;function d7n(){if(n9e)return EJ;n9e=1;let e=Nl();EJ=t;function t(r){function s(a){let i=r.children(a),l=r.node(a);if(i.length&&i.forEach(s),Object.hasOwn(l,"minRank")){l.borderLeft=[],l.borderRight=[];for(let c=l.minRank,u=l.maxRank+1;c<u;++c)n(r,"borderLeft","_bl",a,l,c),n(r,"borderRight","_br",a,l,c)}}r.children().forEach(s)}function n(r,s,a,i,l,c){let u={width:0,height:0,rank:c,borderType:s},d=l[s][c-1],f=e.addDummyNode(r,"border",u,a);l[s][c]=f,r.setParent(f,i),d&&r.setEdge(d,f,{weight:1})}return EJ}var jJ,r9e;function f7n(){if(r9e)return jJ;r9e=1,jJ={adjust:e,undo:t};function e(c){let u=c.graph().rankdir.toLowerCase();(u==="lr"||u==="rl")&&n(c)}function t(c){let u=c.graph().rankdir.toLowerCase();(u==="bt"||u==="rl")&&s(c),(u==="lr"||u==="rl")&&(i(c),n(c))}function n(c){c.nodes().forEach(u=>r(c.node(u))),c.edges().forEach(u=>r(c.edge(u)))}function r(c){let u=c.width;c.width=c.height,c.height=u}function s(c){c.nodes().forEach(u=>a(c.node(u))),c.edges().forEach(u=>{let d=c.edge(u);d.points.forEach(a),Object.hasOwn(d,"y")&&a(d)})}function a(c){c.y=-c.y}function i(c){c.nodes().forEach(u=>l(c.node(u))),c.edges().forEach(u=>{let d=c.edge(u);d.points.forEach(l),Object.hasOwn(d,"x")&&l(d)})}function l(c){let u=c.x;c.x=c.y,c.y=u}return jJ}var TJ,s9e;function p7n(){if(s9e)return TJ;s9e=1;let e=Nl();TJ=t;function t(n){let r={},s=n.nodes().filter(d=>!n.children(d).length),a=s.map(d=>n.node(d).rank),i=e.applyWithChunking(Math.max,a),l=e.range(i+1).map(()=>[]);function c(d){if(r[d])return;r[d]=!0;let f=n.node(d);l[f.rank].push(d),n.successors(d).forEach(c)}return s.sort((d,f)=>n.node(d).rank-n.node(f).rank).forEach(c),l}return TJ}var NJ,a9e;function h7n(){if(a9e)return NJ;a9e=1;let e=Nl().zipObject;NJ=t;function t(r,s){let a=0;for(let i=1;i<s.length;++i)a+=n(r,s[i-1],s[i]);return a}function n(r,s,a){let i=e(a,a.map((p,h)=>h)),l=s.flatMap(p=>r.outEdges(p).map(h=>({pos:i[h.w],weight:r.edge(h).weight})).sort((h,m)=>h.pos-m.pos)),c=1;for(;c<a.length;)c<<=1;let u=2*c-1;c-=1;let d=new Array(u).fill(0),f=0;return l.forEach(p=>{let h=p.pos+c;d[h]+=p.weight;let m=0;for(;h>0;)h%2&&(m+=d[h+1]),h=h-1>>1,d[h]+=p.weight;f+=p.weight*m}),f}return NJ}var IJ,i9e;function m7n(){if(i9e)return IJ;i9e=1,IJ=e;function e(t,n=[]){return n.map(r=>{let s=t.inEdges(r);if(s.length){let a=s.reduce((i,l)=>{let c=t.edge(l),u=t.node(l.v);return{sum:i.sum+c.weight*u.order,weight:i.weight+c.weight}},{sum:0,weight:0});return{v:r,barycenter:a.sum/a.weight,weight:a.weight}}else return{v:r}})}return IJ}var AJ,o9e;function g7n(){if(o9e)return AJ;o9e=1;let e=Nl();AJ=t;function t(s,a){let i={};s.forEach((c,u)=>{let d=i[c.v]={indegree:0,in:[],out:[],vs:[c.v],i:u};c.barycenter!==void 0&&(d.barycenter=c.barycenter,d.weight=c.weight)}),a.edges().forEach(c=>{let u=i[c.v],d=i[c.w];u!==void 0&&d!==void 0&&(d.indegree++,u.out.push(i[c.w]))});let l=Object.values(i).filter(c=>!c.indegree);return n(l)}function n(s){let a=[];function i(c){return u=>{u.merged||(u.barycenter===void 0||c.barycenter===void 0||u.barycenter>=c.barycenter)&&r(c,u)}}function l(c){return u=>{u.in.push(c),--u.indegree===0&&s.push(u)}}for(;s.length;){let c=s.pop();a.push(c),c.in.reverse().forEach(i(c)),c.out.forEach(l(c))}return a.filter(c=>!c.merged).map(c=>e.pick(c,["vs","i","barycenter","weight"]))}function r(s,a){let i=0,l=0;s.weight&&(i+=s.barycenter*s.weight,l+=s.weight),a.weight&&(i+=a.barycenter*a.weight,l+=a.weight),s.vs=a.vs.concat(s.vs),s.barycenter=i/l,s.weight=l,s.i=Math.min(a.i,s.i),a.merged=!0}return AJ}var RJ,l9e;function v7n(){if(l9e)return RJ;l9e=1;let e=Nl();RJ=t;function t(s,a){let i=e.partition(s,m=>Object.hasOwn(m,"barycenter")),l=i.lhs,c=i.rhs.sort((m,v)=>v.i-m.i),u=[],d=0,f=0,p=0;l.sort(r(!!a)),p=n(u,c,p),l.forEach(m=>{p+=m.vs.length,u.push(m.vs),d+=m.barycenter*m.weight,f+=m.weight,p=n(u,c,p)});let h={vs:u.flat(!0)};return f&&(h.barycenter=d/f,h.weight=f),h}function n(s,a,i){let l;for(;a.length&&(l=a[a.length-1]).i<=i;)a.pop(),s.push(l.vs),i++;return i}function r(s){return(a,i)=>a.barycenter<i.barycenter?-1:a.barycenter>i.barycenter?1:s?i.i-a.i:a.i-i.i}return RJ}var PJ,c9e;function y7n(){if(c9e)return PJ;c9e=1;let e=m7n(),t=g7n(),n=v7n();PJ=r;function r(i,l,c,u){let d=i.children(l),f=i.node(l),p=f?f.borderLeft:void 0,h=f?f.borderRight:void 0,m={};p&&(d=d.filter(S=>S!==p&&S!==h));let v=e(i,d);v.forEach(S=>{if(i.children(S.v).length){let w=r(i,S.v,c,u);m[S.v]=w,Object.hasOwn(w,"barycenter")&&a(S,w)}});let y=t(v,c);s(y,m);let b=n(y,u);if(p&&(b.vs=[p,b.vs,h].flat(!0),i.predecessors(p).length)){let S=i.node(i.predecessors(p)[0]),w=i.node(i.predecessors(h)[0]);Object.hasOwn(b,"barycenter")||(b.barycenter=0,b.weight=0),b.barycenter=(b.barycenter*b.weight+S.order+w.order)/(b.weight+2),b.weight+=2}return b}function s(i,l){i.forEach(c=>{c.vs=c.vs.flatMap(u=>l[u]?l[u].vs:u)})}function a(i,l){i.barycenter!==void 0?(i.barycenter=(i.barycenter*i.weight+l.barycenter*l.weight)/(i.weight+l.weight),i.weight+=l.weight):(i.barycenter=l.barycenter,i.weight=l.weight)}return PJ}var $J,u9e;function b7n(){if(u9e)return $J;u9e=1;let e=Tg().Graph,t=Nl();$J=n;function n(s,a,i,l){l||(l=s.nodes());let c=r(s),u=new e({compound:!0}).setGraph({root:c}).setDefaultNodeLabel(d=>s.node(d));return l.forEach(d=>{let f=s.node(d),p=s.parent(d);(f.rank===a||f.minRank<=a&&a<=f.maxRank)&&(u.setNode(d),u.setParent(d,p||c),s[i](d).forEach(h=>{let m=h.v===d?h.w:h.v,v=u.edge(m,d),y=v!==void 0?v.weight:0;u.setEdge(m,d,{weight:s.edge(h).weight+y})}),Object.hasOwn(f,"minRank")&&u.setNode(d,{borderLeft:f.borderLeft[a],borderRight:f.borderRight[a]}))}),u}function r(s){for(var a;s.hasNode(a=t.uniqueId("_root")););return a}return $J}var MJ,d9e;function x7n(){if(d9e)return MJ;d9e=1,MJ=e;function e(t,n,r){let s={},a;r.forEach(i=>{let l=t.parent(i),c,u;for(;l;){if(c=t.parent(l),c?(u=s[c],s[c]=l):(u=a,a=l),u&&u!==l){n.setEdge(u,l);return}l=c}})}return MJ}var DJ,f9e;function w7n(){if(f9e)return DJ;f9e=1;let e=p7n(),t=h7n(),n=y7n(),r=b7n(),s=x7n(),a=Tg().Graph,i=Nl();DJ=l;function l(f,p){if(p&&typeof p.customOrder=="function"){p.customOrder(f,l);return}let h=i.maxRank(f),m=c(f,i.range(1,h+1),"inEdges"),v=c(f,i.range(h-1,-1,-1),"outEdges"),y=e(f);if(d(f,y),p&&p.disableOptimalOrderHeuristic)return;let b=Number.POSITIVE_INFINITY,S;for(let w=0,k=0;k<4;++w,++k){u(w%2?m:v,w%4>=2),y=i.buildLayerMatrix(f);let _=t(f,y);_<b&&(k=0,S=Object.assign({},y),b=_)}d(f,S)}function c(f,p,h){const m=new Map,v=(y,b)=>{m.has(y)||m.set(y,[]),m.get(y).push(b)};for(const y of f.nodes()){const b=f.node(y);if(typeof b.rank=="number"&&v(b.rank,y),typeof b.minRank=="number"&&typeof b.maxRank=="number")for(let S=b.minRank;S<=b.maxRank;S++)S!==b.rank&&v(S,y)}return p.map(function(y){return r(f,y,h,m.get(y)||[])})}function u(f,p){let h=new a;f.forEach(function(m){let v=m.graph().root,y=n(m,v,h,p);y.vs.forEach((b,S)=>m.node(b).order=S),s(m,h,y.vs)})}function d(f,p){Object.values(p).forEach(h=>h.forEach((m,v)=>f.node(m).order=v))}return DJ}var LJ,p9e;function S7n(){if(p9e)return LJ;p9e=1;let e=Tg().Graph,t=Nl();LJ={positionX:h,findType1Conflicts:n,findType2Conflicts:r,addConflict:a,hasConflict:i,verticalAlignment:l,horizontalCompaction:c,alignCoordinates:f,findSmallestWidthAlignment:d,balance:p};function n(y,b){let S={};function w(k,_){let C=0,E=0,j=k.length,N=_[_.length-1];return _.forEach((I,R)=>{let P=s(y,I),L=P?y.node(P).order:j;(P||I===N)&&(_.slice(E,R+1).forEach(M=>{y.predecessors(M).forEach(q=>{let H=y.node(q),F=H.order;(F<C||L<F)&&!(H.dummy&&y.node(M).dummy)&&a(S,q,M)})}),E=R+1,C=L)}),_}return b.length&&b.reduce(w),S}function r(y,b){let S={};function w(_,C,E,j,N){let I;t.range(C,E).forEach(R=>{I=_[R],y.node(I).dummy&&y.predecessors(I).forEach(P=>{let L=y.node(P);L.dummy&&(L.order<j||L.order>N)&&a(S,P,I)})})}function k(_,C){let E=-1,j,N=0;return C.forEach((I,R)=>{if(y.node(I).dummy==="border"){let P=y.predecessors(I);P.length&&(j=y.node(P[0]).order,w(C,N,R,E,j),N=R,E=j)}w(C,N,C.length,j,_.length)}),C}return b.length&&b.reduce(k),S}function s(y,b){if(y.node(b).dummy)return y.predecessors(b).find(S=>y.node(S).dummy)}function a(y,b,S){if(b>S){let k=b;b=S,S=k}let w=y[b];w||(y[b]=w={}),w[S]=!0}function i(y,b,S){if(b>S){let w=b;b=S,S=w}return!!y[b]&&Object.hasOwn(y[b],S)}function l(y,b,S,w){let k={},_={},C={};return b.forEach(E=>{E.forEach((j,N)=>{k[j]=j,_[j]=j,C[j]=N})}),b.forEach(E=>{let j=-1;E.forEach(N=>{let I=w(N);if(I.length){I=I.sort((P,L)=>C[P]-C[L]);let R=(I.length-1)/2;for(let P=Math.floor(R),L=Math.ceil(R);P<=L;++P){let M=I[P];_[N]===N&&j<C[M]&&!i(S,N,M)&&(_[M]=N,_[N]=k[N]=k[M],j=C[M])}}})}),{root:k,align:_}}function c(y,b,S,w,k){let _={},C=u(y,b,S,k),E=k?"borderLeft":"borderRight";function j(R,P){let L=C.nodes(),M=L.pop(),q={};for(;M;)q[M]?R(M):(q[M]=!0,L.push(M),L=L.concat(P(M))),M=L.pop()}function N(R){_[R]=C.inEdges(R).reduce((P,L)=>Math.max(P,_[L.v]+C.edge(L)),0)}function I(R){let P=C.outEdges(R).reduce((M,q)=>Math.min(M,_[q.w]-C.edge(q)),Number.POSITIVE_INFINITY),L=y.node(R);P!==Number.POSITIVE_INFINITY&&L.borderType!==E&&(_[R]=Math.max(_[R],P))}return j(N,C.predecessors.bind(C)),j(I,C.successors.bind(C)),Object.keys(w).forEach(R=>_[R]=_[S[R]]),_}function u(y,b,S,w){let k=new e,_=y.graph(),C=m(_.nodesep,_.edgesep,w);return b.forEach(E=>{let j;E.forEach(N=>{let I=S[N];if(k.setNode(I),j){var R=S[j],P=k.edge(R,I);k.setEdge(R,I,Math.max(C(y,N,j),P||0))}j=N})}),k}function d(y,b){return Object.values(b).reduce((S,w)=>{let k=Number.NEGATIVE_INFINITY,_=Number.POSITIVE_INFINITY;Object.entries(w).forEach(([E,j])=>{let N=v(y,E)/2;k=Math.max(j+N,k),_=Math.min(j-N,_)});const C=k-_;return C<S[0]&&(S=[C,w]),S},[Number.POSITIVE_INFINITY,null])[1]}function f(y,b){let S=Object.values(b),w=t.applyWithChunking(Math.min,S),k=t.applyWithChunking(Math.max,S);["u","d"].forEach(_=>{["l","r"].forEach(C=>{let E=_+C,j=y[E];if(j===b)return;let N=Object.values(j),I=w-t.applyWithChunking(Math.min,N);C!=="l"&&(I=k-t.applyWithChunking(Math.max,N)),I&&(y[E]=t.mapValues(j,R=>R+I))})})}function p(y,b){return t.mapValues(y.ul,(S,w)=>{if(b)return y[b.toLowerCase()][w];{let k=Object.values(y).map(_=>_[w]).sort((_,C)=>_-C);return(k[1]+k[2])/2}})}function h(y){let b=t.buildLayerMatrix(y),S=Object.assign(n(y,b),r(y,b)),w={},k;["u","d"].forEach(C=>{k=C==="u"?b:Object.values(b).reverse(),["l","r"].forEach(E=>{E==="r"&&(k=k.map(R=>Object.values(R).reverse()));let j=(C==="u"?y.predecessors:y.successors).bind(y),N=l(y,k,S,j),I=c(y,k,N.root,N.align,E==="r");E==="r"&&(I=t.mapValues(I,R=>-R)),w[C+E]=I})});let _=d(y,w);return f(w,_),p(w,y.graph().align)}function m(y,b,S){return(w,k,_)=>{let C=w.node(k),E=w.node(_),j=0,N;if(j+=C.width/2,Object.hasOwn(C,"labelpos"))switch(C.labelpos.toLowerCase()){case"l":N=-C.width/2;break;case"r":N=C.width/2;break}if(N&&(j+=S?N:-N),N=0,j+=(C.dummy?b:y)/2,j+=(E.dummy?b:y)/2,j+=E.width/2,Object.hasOwn(E,"labelpos"))switch(E.labelpos.toLowerCase()){case"l":N=E.width/2;break;case"r":N=-E.width/2;break}return N&&(j+=S?N:-N),N=0,j}}function v(y,b){return y.node(b).width}return LJ}var FJ,h9e;function k7n(){if(h9e)return FJ;h9e=1;let e=Nl(),t=S7n().positionX;FJ=n;function n(s){s=e.asNonCompoundGraph(s),r(s),Object.entries(t(s)).forEach(([a,i])=>s.node(a).x=i)}function r(s){let a=e.buildLayerMatrix(s),i=s.graph().ranksep,l=0;a.forEach(c=>{const u=c.reduce((d,f)=>{const p=s.node(f).height;return d>p?d:p},0);c.forEach(d=>s.node(d).y=l+u/2),l+=u+i})}return FJ}var zJ,m9e;function O7n(){if(m9e)return zJ;m9e=1;let e=a7n(),t=i7n(),n=l7n(),r=Nl().normalizeRanks,s=c7n(),a=Nl().removeEmptyRanks,i=u7n(),l=d7n(),c=f7n(),u=w7n(),d=k7n(),f=Nl(),p=Tg().Graph;zJ=h;function h($,U){let Z=U&&U.debugTiming?f.time:f.notime;Z("layout",()=>{let X=Z(" buildLayoutGraph",()=>j($));Z(" runLayout",()=>m(X,Z,U)),Z(" updateInputGraph",()=>v($,X))})}function m($,U,Z){U(" makeSpaceForEdgeLabels",()=>N($)),U(" removeSelfEdges",()=>z($)),U(" acyclic",()=>e.run($)),U(" nestingGraph.run",()=>i.run($)),U(" rank",()=>n(f.asNonCompoundGraph($))),U(" injectEdgeLabelProxies",()=>I($)),U(" removeEmptyRanks",()=>a($)),U(" nestingGraph.cleanup",()=>i.cleanup($)),U(" normalizeRanks",()=>r($)),U(" assignRankMinMax",()=>R($)),U(" removeEdgeLabelProxies",()=>P($)),U(" normalize.run",()=>t.run($)),U(" parentDummyChains",()=>s($)),U(" addBorderSegments",()=>l($)),U(" order",()=>u($,Z)),U(" insertSelfEdges",()=>B($)),U(" adjustCoordinateSystem",()=>c.adjust($)),U(" position",()=>d($)),U(" positionSelfEdges",()=>D($)),U(" removeBorderNodes",()=>F($)),U(" normalize.undo",()=>t.undo($)),U(" fixupEdgeLabelCoords",()=>q($)),U(" undoCoordinateSystem",()=>c.undo($)),U(" translateGraph",()=>L($)),U(" assignNodeIntersects",()=>M($)),U(" reversePoints",()=>H($)),U(" acyclic.undo",()=>e.undo($))}function v($,U){$.nodes().forEach(Z=>{let X=$.node(Z),te=U.node(Z);X&&(X.x=te.x,X.y=te.y,X.rank=te.rank,U.children(Z).length&&(X.width=te.width,X.height=te.height))}),$.edges().forEach(Z=>{let X=$.edge(Z),te=U.edge(Z);X.points=te.points,Object.hasOwn(te,"x")&&(X.x=te.x,X.y=te.y)}),$.graph().width=U.graph().width,$.graph().height=U.graph().height}let y=["nodesep","edgesep","ranksep","marginx","marginy"],b={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb"},S=["acyclicer","ranker","rankdir","align"],w=["width","height","rank"],k={width:0,height:0},_=["minlen","weight","width","height","labeloffset"],C={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},E=["labelpos"];function j($){let U=new p({multigraph:!0,compound:!0}),Z=V($.graph());return U.setGraph(Object.assign({},b,Q(Z,y),f.pick(Z,S))),$.nodes().forEach(X=>{let te=V($.node(X));const J=Q(te,w);Object.keys(k).forEach(ee=>{J[ee]===void 0&&(J[ee]=k[ee])}),U.setNode(X,J),U.setParent(X,$.parent(X))}),$.edges().forEach(X=>{let te=V($.edge(X));U.setEdge(X,Object.assign({},C,Q(te,_),f.pick(te,E)))}),U}function N($){let U=$.graph();U.ranksep/=2,$.edges().forEach(Z=>{let X=$.edge(Z);X.minlen*=2,X.labelpos.toLowerCase()!=="c"&&(U.rankdir==="TB"||U.rankdir==="BT"?X.width+=X.labeloffset:X.height+=X.labeloffset)})}function I($){$.edges().forEach(U=>{let Z=$.edge(U);if(Z.width&&Z.height){let X=$.node(U.v),J={rank:($.node(U.w).rank-X.rank)/2+X.rank,e:U};f.addDummyNode($,"edge-proxy",J,"_ep")}})}function R($){let U=0;$.nodes().forEach(Z=>{let X=$.node(Z);X.borderTop&&(X.minRank=$.node(X.borderTop).rank,X.maxRank=$.node(X.borderBottom).rank,U=Math.max(U,X.maxRank))}),$.graph().maxRank=U}function P($){$.nodes().forEach(U=>{let Z=$.node(U);Z.dummy==="edge-proxy"&&($.edge(Z.e).labelRank=Z.rank,$.removeNode(U))})}function L($){let U=Number.POSITIVE_INFINITY,Z=0,X=Number.POSITIVE_INFINITY,te=0,J=$.graph(),ee=J.marginx||0,ae=J.marginy||0;function ce(Y){let ne=Y.x,ue=Y.y,pe=Y.width,le=Y.height;U=Math.min(U,ne-pe/2),Z=Math.max(Z,ne+pe/2),X=Math.min(X,ue-le/2),te=Math.max(te,ue+le/2)}$.nodes().forEach(Y=>ce($.node(Y))),$.edges().forEach(Y=>{let ne=$.edge(Y);Object.hasOwn(ne,"x")&&ce(ne)}),U-=ee,X-=ae,$.nodes().forEach(Y=>{let ne=$.node(Y);ne.x-=U,ne.y-=X}),$.edges().forEach(Y=>{let ne=$.edge(Y);ne.points.forEach(ue=>{ue.x-=U,ue.y-=X}),Object.hasOwn(ne,"x")&&(ne.x-=U),Object.hasOwn(ne,"y")&&(ne.y-=X)}),J.width=Z-U+ee,J.height=te-X+ae}function M($){$.edges().forEach(U=>{let Z=$.edge(U),X=$.node(U.v),te=$.node(U.w),J,ee;Z.points?(J=Z.points[0],ee=Z.points[Z.points.length-1]):(Z.points=[],J=te,ee=X),Z.points.unshift(f.intersectRect(X,J)),Z.points.push(f.intersectRect(te,ee))})}function q($){$.edges().forEach(U=>{let Z=$.edge(U);if(Object.hasOwn(Z,"x"))switch((Z.labelpos==="l"||Z.labelpos==="r")&&(Z.width-=Z.labeloffset),Z.labelpos){case"l":Z.x-=Z.width/2+Z.labeloffset;break;case"r":Z.x+=Z.width/2+Z.labeloffset;break}})}function H($){$.edges().forEach(U=>{let Z=$.edge(U);Z.reversed&&Z.points.reverse()})}function F($){$.nodes().forEach(U=>{if($.children(U).length){let Z=$.node(U),X=$.node(Z.borderTop),te=$.node(Z.borderBottom),J=$.node(Z.borderLeft[Z.borderLeft.length-1]),ee=$.node(Z.borderRight[Z.borderRight.length-1]);Z.width=Math.abs(ee.x-J.x),Z.height=Math.abs(te.y-X.y),Z.x=J.x+Z.width/2,Z.y=X.y+Z.height/2}}),$.nodes().forEach(U=>{$.node(U).dummy==="border"&&$.removeNode(U)})}function z($){$.edges().forEach(U=>{if(U.v===U.w){var Z=$.node(U.v);Z.selfEdges||(Z.selfEdges=[]),Z.selfEdges.push({e:U,label:$.edge(U)}),$.removeEdge(U)}})}function B($){var U=f.buildLayerMatrix($);U.forEach(Z=>{var X=0;Z.forEach((te,J)=>{var ee=$.node(te);ee.order=J+X,(ee.selfEdges||[]).forEach(ae=>{f.addDummyNode($,"selfedge",{width:ae.label.width,height:ae.label.height,rank:ee.rank,order:J+ ++X,e:ae.e,label:ae.label},"_se")}),delete ee.selfEdges})})}function D($){$.nodes().forEach(U=>{var Z=$.node(U);if(Z.dummy==="selfedge"){var X=$.node(Z.e.v),te=X.x+X.width/2,J=X.y,ee=Z.x-te,ae=X.height/2;$.setEdge(Z.e,Z.label),$.removeNode(U),Z.label.points=[{x:te+2*ee/3,y:J-ae},{x:te+5*ee/6,y:J-ae},{x:te+ee,y:J},{x:te+5*ee/6,y:J+ae},{x:te+2*ee/3,y:J+ae}],Z.label.x=Z.x,Z.label.y=Z.y}})}function Q($,U){return f.mapValues(f.pick($,U),Number)}function V($){var U={};return $&&Object.entries($).forEach(([Z,X])=>{typeof Z=="string"&&(Z=Z.toLowerCase()),U[Z]=X}),U}return zJ}var BJ,g9e;function _7n(){if(g9e)return BJ;g9e=1;let e=Nl(),t=Tg().Graph;BJ={debugOrdering:n};function n(r){let s=e.buildLayerMatrix(r),a=new t({compound:!0,multigraph:!0}).setGraph({});return r.nodes().forEach(i=>{a.setNode(i,{label:i}),a.setParent(i,"layer"+r.node(i).rank)}),r.edges().forEach(i=>a.setEdge(i.v,i.w,{},i.name)),s.forEach((i,l)=>{let c="layer"+l;a.setNode(c,{rank:"same"}),i.reduce((u,d)=>(a.setEdge(u,d,{style:"invis"}),d))}),a}return BJ}var UJ,v9e;function C7n(){return v9e||(v9e=1,UJ="1.1.8"),UJ}var qJ,y9e;function E7n(){return y9e||(y9e=1,qJ={graphlib:Tg(),layout:O7n(),debug:_7n(),util:{time:Nl().time,notime:Nl().notime},version:C7n()}),qJ}var j7n=E7n();const b9e=Tc(j7n);function Ml(e){if(typeof e=="string"||typeof e=="number")return""+e;let t="";if(Array.isArray(e))for(let n=0,r;n<e.length;n++)(r=Ml(e[n]))!==""&&(t+=(t&&" ")+r);else for(let n in e)e[n]&&(t+=(t&&" ")+n);return t}var T7n={value:()=>{}};function TV(){for(var e=0,t=arguments.length,n={},r;e<t;++e){if(!(r=arguments[e]+"")||r in n||/[\s.]/.test(r))throw new Error("illegal type: "+r);n[r]=[]}return new KF(n)}function KF(e){this._=e}function N7n(e,t){return e.trim().split(/^|\s+/).map(function(n){var r="",s=n.indexOf(".");if(s>=0&&(r=n.slice(s+1),n=n.slice(0,s)),n&&!t.hasOwnProperty(n))throw new Error("unknown type: "+n);return{type:n,name:r}})}KF.prototype=TV.prototype={constructor:KF,on:function(e,t){var n=this._,r=N7n(e+"",n),s,a=-1,i=r.length;if(arguments.length<2){for(;++a<i;)if((s=(e=r[a]).type)&&(s=I7n(n[s],e.name)))return s;return}if(t!=null&&typeof t!="function")throw new Error("invalid callback: "+t);for(;++a<i;)if(s=(e=r[a]).type)n[s]=x9e(n[s],e.name,t);else if(t==null)for(s in n)n[s]=x9e(n[s],e.name,null);return this},copy:function(){var e={},t=this._;for(var n in t)e[n]=t[n].slice();return new KF(e)},call:function(e,t){if((s=arguments.length-2)>0)for(var n=new Array(s),r=0,s,a;r<s;++r)n[r]=arguments[r+2];if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(a=this._[e],r=0,s=a.length;r<s;++r)a[r].value.apply(t,n)},apply:function(e,t,n){if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(var r=this._[e],s=0,a=r.length;s<a;++s)r[s].value.apply(t,n)}};function I7n(e,t){for(var n=0,r=e.length,s;n<r;++n)if((s=e[n]).name===t)return s.value}function x9e(e,t,n){for(var r=0,s=e.length;r<s;++r)if(e[r].name===t){e[r]=T7n,e=e.slice(0,r).concat(e.slice(r+1));break}return n!=null&&e.push({name:t,value:n}),e}var khe="http://www.w3.org/1999/xhtml";const w9e={svg:"http://www.w3.org/2000/svg",xhtml:khe,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function NV(e){var t=e+="",n=t.indexOf(":");return n>=0&&(t=e.slice(0,n))!=="xmlns"&&(e=e.slice(n+1)),w9e.hasOwnProperty(t)?{space:w9e[t],local:e}:e}function A7n(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===khe&&t.documentElement.namespaceURI===khe?t.createElement(e):t.createElementNS(n,e)}}function R7n(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function Pxt(e){var t=NV(e);return(t.local?R7n:A7n)(t)}function P7n(){}function u1e(e){return e==null?P7n:function(){return this.querySelector(e)}}function $7n(e){typeof e!="function"&&(e=u1e(e));for(var t=this._groups,n=t.length,r=new Array(n),s=0;s<n;++s)for(var a=t[s],i=a.length,l=r[s]=new Array(i),c,u,d=0;d<i;++d)(c=a[d])&&(u=e.call(c,c.__data__,d,a))&&("__data__"in c&&(u.__data__=c.__data__),l[d]=u);return new qp(r,this._parents)}function M7n(e){return e==null?[]:Array.isArray(e)?e:Array.from(e)}function D7n(){return[]}function $xt(e){return e==null?D7n:function(){return this.querySelectorAll(e)}}function L7n(e){return function(){return M7n(e.apply(this,arguments))}}function F7n(e){typeof e=="function"?e=L7n(e):e=$xt(e);for(var t=this._groups,n=t.length,r=[],s=[],a=0;a<n;++a)for(var i=t[a],l=i.length,c,u=0;u<l;++u)(c=i[u])&&(r.push(e.call(c,c.__data__,u,i)),s.push(c));return new qp(r,s)}function Mxt(e){return function(){return this.matches(e)}}function Dxt(e){return function(t){return t.matches(e)}}var z7n=Array.prototype.find;function B7n(e){return function(){return z7n.call(this.children,e)}}function U7n(){return this.firstElementChild}function q7n(e){return this.select(e==null?U7n:B7n(typeof e=="function"?e:Dxt(e)))}var V7n=Array.prototype.filter;function H7n(){return Array.from(this.children)}function W7n(e){return function(){return V7n.call(this.children,e)}}function Z7n(e){return this.selectAll(e==null?H7n:W7n(typeof e=="function"?e:Dxt(e)))}function G7n(e){typeof e!="function"&&(e=Mxt(e));for(var t=this._groups,n=t.length,r=new Array(n),s=0;s<n;++s)for(var a=t[s],i=a.length,l=r[s]=[],c,u=0;u<i;++u)(c=a[u])&&e.call(c,c.__data__,u,a)&&l.push(c);return new qp(r,this._parents)}function Lxt(e){return new Array(e.length)}function Q7n(){return new qp(this._enter||this._groups.map(Lxt),this._parents)}function N7(e,t){this.ownerDocument=e.ownerDocument,this.namespaceURI=e.namespaceURI,this._next=null,this._parent=e,this.__data__=t}N7.prototype={constructor:N7,appendChild:function(e){return this._parent.insertBefore(e,this._next)},insertBefore:function(e,t){return this._parent.insertBefore(e,t)},querySelector:function(e){return this._parent.querySelector(e)},querySelectorAll:function(e){return this._parent.querySelectorAll(e)}};function Y7n(e){return function(){return e}}function X7n(e,t,n,r,s,a){for(var i=0,l,c=t.length,u=a.length;i<u;++i)(l=t[i])?(l.__data__=a[i],r[i]=l):n[i]=new N7(e,a[i]);for(;i<c;++i)(l=t[i])&&(s[i]=l)}function K7n(e,t,n,r,s,a,i){var l,c,u=new Map,d=t.length,f=a.length,p=new Array(d),h;for(l=0;l<d;++l)(c=t[l])&&(p[l]=h=i.call(c,c.__data__,l,t)+"",u.has(h)?s[l]=c:u.set(h,c));for(l=0;l<f;++l)h=i.call(e,a[l],l,a)+"",(c=u.get(h))?(r[l]=c,c.__data__=a[l],u.delete(h)):n[l]=new N7(e,a[l]);for(l=0;l<d;++l)(c=t[l])&&u.get(p[l])===c&&(s[l]=c)}function J7n(e){return e.__data__}function eBn(e,t){if(!arguments.length)return Array.from(this,J7n);var n=t?K7n:X7n,r=this._parents,s=this._groups;typeof e!="function"&&(e=Y7n(e));for(var a=s.length,i=new Array(a),l=new Array(a),c=new Array(a),u=0;u<a;++u){var d=r[u],f=s[u],p=f.length,h=tBn(e.call(d,d&&d.__data__,u,r)),m=h.length,v=l[u]=new Array(m),y=i[u]=new Array(m),b=c[u]=new Array(p);n(d,f,v,y,b,h,t);for(var S=0,w=0,k,_;S<m;++S)if(k=v[S]){for(S>=w&&(w=S+1);!(_=y[w])&&++w<m;);k._next=_||null}}return i=new qp(i,r),i._enter=l,i._exit=c,i}function tBn(e){return typeof e=="object"&&"length"in e?e:Array.from(e)}function nBn(){return new qp(this._exit||this._groups.map(Lxt),this._parents)}function rBn(e,t,n){var r=this.enter(),s=this,a=this.exit();return typeof e=="function"?(r=e(r),r&&(r=r.selection())):r=r.append(e+""),t!=null&&(s=t(s),s&&(s=s.selection())),n==null?a.remove():n(a),r&&s?r.merge(s).order():s}function sBn(e){for(var t=e.selection?e.selection():e,n=this._groups,r=t._groups,s=n.length,a=r.length,i=Math.min(s,a),l=new Array(s),c=0;c<i;++c)for(var u=n[c],d=r[c],f=u.length,p=l[c]=new Array(f),h,m=0;m<f;++m)(h=u[m]||d[m])&&(p[m]=h);for(;c<s;++c)l[c]=n[c];return new qp(l,this._parents)}function aBn(){for(var e=this._groups,t=-1,n=e.length;++t<n;)for(var r=e[t],s=r.length-1,a=r[s],i;--s>=0;)(i=r[s])&&(a&&i.compareDocumentPosition(a)^4&&a.parentNode.insertBefore(i,a),a=i);return this}function iBn(e){e||(e=oBn);function t(f,p){return f&&p?e(f.__data__,p.__data__):!f-!p}for(var n=this._groups,r=n.length,s=new Array(r),a=0;a<r;++a){for(var i=n[a],l=i.length,c=s[a]=new Array(l),u,d=0;d<l;++d)(u=i[d])&&(c[d]=u);c.sort(t)}return new qp(s,this._parents).order()}function oBn(e,t){return e<t?-1:e>t?1:e>=t?0:NaN}function lBn(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function cBn(){return Array.from(this)}function uBn(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var r=e[t],s=0,a=r.length;s<a;++s){var i=r[s];if(i)return i}return null}function dBn(){let e=0;for(const t of this)++e;return e}function fBn(){return!this.node()}function pBn(e){for(var t=this._groups,n=0,r=t.length;n<r;++n)for(var s=t[n],a=0,i=s.length,l;a<i;++a)(l=s[a])&&e.call(l,l.__data__,a,s);return this}function hBn(e){return function(){this.removeAttribute(e)}}function mBn(e){return function(){this.removeAttributeNS(e.space,e.local)}}function gBn(e,t){return function(){this.setAttribute(e,t)}}function vBn(e,t){return function(){this.setAttributeNS(e.space,e.local,t)}}function yBn(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttribute(e):this.setAttribute(e,n)}}function bBn(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttributeNS(e.space,e.local):this.setAttributeNS(e.space,e.local,n)}}function xBn(e,t){var n=NV(e);if(arguments.length<2){var r=this.node();return n.local?r.getAttributeNS(n.space,n.local):r.getAttribute(n)}return this.each((t==null?n.local?mBn:hBn:typeof t=="function"?n.local?bBn:yBn:n.local?vBn:gBn)(n,t))}function Fxt(e){return e.ownerDocument&&e.ownerDocument.defaultView||e.document&&e||e.defaultView}function wBn(e){return function(){this.style.removeProperty(e)}}function SBn(e,t,n){return function(){this.style.setProperty(e,t,n)}}function kBn(e,t,n){return function(){var r=t.apply(this,arguments);r==null?this.style.removeProperty(e):this.style.setProperty(e,r,n)}}function OBn(e,t,n){return arguments.length>1?this.each((t==null?wBn:typeof t=="function"?kBn:SBn)(e,t,n??"")):wT(this.node(),e)}function wT(e,t){return e.style.getPropertyValue(t)||Fxt(e).getComputedStyle(e,null).getPropertyValue(t)}function _Bn(e){return function(){delete this[e]}}function CBn(e,t){return function(){this[e]=t}}function EBn(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function jBn(e,t){return arguments.length>1?this.each((t==null?_Bn:typeof t=="function"?EBn:CBn)(e,t)):this.node()[e]}function zxt(e){return e.trim().split(/^|\s+/)}function d1e(e){return e.classList||new Bxt(e)}function Bxt(e){this._node=e,this._names=zxt(e.getAttribute("class")||"")}Bxt.prototype={add:function(e){var t=this._names.indexOf(e);t<0&&(this._names.push(e),this._node.setAttribute("class",this._names.join(" ")))},remove:function(e){var t=this._names.indexOf(e);t>=0&&(this._names.splice(t,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(e){return this._names.indexOf(e)>=0}};function Uxt(e,t){for(var n=d1e(e),r=-1,s=t.length;++r<s;)n.add(t[r])}function qxt(e,t){for(var n=d1e(e),r=-1,s=t.length;++r<s;)n.remove(t[r])}function TBn(e){return function(){Uxt(this,e)}}function NBn(e){return function(){qxt(this,e)}}function IBn(e,t){return function(){(t.apply(this,arguments)?Uxt:qxt)(this,e)}}function ABn(e,t){var n=zxt(e+"");if(arguments.length<2){for(var r=d1e(this.node()),s=-1,a=n.length;++s<a;)if(!r.contains(n[s]))return!1;return!0}return this.each((typeof t=="function"?IBn:t?TBn:NBn)(n,t))}function RBn(){this.textContent=""}function PBn(e){return function(){this.textContent=e}}function $Bn(e){return function(){var t=e.apply(this,arguments);this.textContent=t??""}}function MBn(e){return arguments.length?this.each(e==null?RBn:(typeof e=="function"?$Bn:PBn)(e)):this.node().textContent}function DBn(){this.innerHTML=""}function LBn(e){return function(){this.innerHTML=e}}function FBn(e){return function(){var t=e.apply(this,arguments);this.innerHTML=t??""}}function zBn(e){return arguments.length?this.each(e==null?DBn:(typeof e=="function"?FBn:LBn)(e)):this.node().innerHTML}function BBn(){this.nextSibling&&this.parentNode.appendChild(this)}function UBn(){return this.each(BBn)}function qBn(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function VBn(){return this.each(qBn)}function HBn(e){var t=typeof e=="function"?e:Pxt(e);return this.select(function(){return this.appendChild(t.apply(this,arguments))})}function WBn(){return null}function ZBn(e,t){var n=typeof e=="function"?e:Pxt(e),r=t==null?WBn:typeof t=="function"?t:u1e(t);return this.select(function(){return this.insertBefore(n.apply(this,arguments),r.apply(this,arguments)||null)})}function GBn(){var e=this.parentNode;e&&e.removeChild(this)}function QBn(){return this.each(GBn)}function YBn(){var e=this.cloneNode(!1),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function XBn(){var e=this.cloneNode(!0),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function KBn(e){return this.select(e?XBn:YBn)}function JBn(e){return arguments.length?this.property("__data__",e):this.node().__data__}function eUn(e){return function(t){e.call(this,t,this.__data__)}}function tUn(e){return e.trim().split(/^|\s+/).map(function(t){var n="",r=t.indexOf(".");return r>=0&&(n=t.slice(r+1),t=t.slice(0,r)),{type:t,name:n}})}function nUn(e){return function(){var t=this.__on;if(t){for(var n=0,r=-1,s=t.length,a;n<s;++n)a=t[n],(!e.type||a.type===e.type)&&a.name===e.name?this.removeEventListener(a.type,a.listener,a.options):t[++r]=a;++r?t.length=r:delete this.__on}}}function rUn(e,t,n){return function(){var r=this.__on,s,a=eUn(t);if(r){for(var i=0,l=r.length;i<l;++i)if((s=r[i]).type===e.type&&s.name===e.name){this.removeEventListener(s.type,s.listener,s.options),this.addEventListener(s.type,s.listener=a,s.options=n),s.value=t;return}}this.addEventListener(e.type,a,n),s={type:e.type,name:e.name,value:t,listener:a,options:n},r?r.push(s):this.__on=[s]}}function sUn(e,t,n){var r=tUn(e+""),s,a=r.length,i;if(arguments.length<2){var l=this.node().__on;if(l){for(var c=0,u=l.length,d;c<u;++c)for(s=0,d=l[c];s<a;++s)if((i=r[s]).type===d.type&&i.name===d.name)return d.value}return}for(l=t?rUn:nUn,s=0;s<a;++s)this.each(l(r[s],t,n));return this}function Vxt(e,t,n){var r=Fxt(e),s=r.CustomEvent;typeof s=="function"?s=new s(t,n):(s=r.document.createEvent("Event"),n?(s.initEvent(t,n.bubbles,n.cancelable),s.detail=n.detail):s.initEvent(t,!1,!1)),e.dispatchEvent(s)}function aUn(e,t){return function(){return Vxt(this,e,t)}}function iUn(e,t){return function(){return Vxt(this,e,t.apply(this,arguments))}}function oUn(e,t){return this.each((typeof t=="function"?iUn:aUn)(e,t))}function*lUn(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var r=e[t],s=0,a=r.length,i;s<a;++s)(i=r[s])&&(yield i)}var Hxt=[null];function qp(e,t){this._groups=e,this._parents=t}function p3(){return new qp([[document.documentElement]],Hxt)}function cUn(){return this}qp.prototype=p3.prototype={constructor:qp,select:$7n,selectAll:F7n,selectChild:q7n,selectChildren:Z7n,filter:G7n,data:eBn,enter:Q7n,exit:nBn,join:rBn,merge:sBn,selection:cUn,order:aBn,sort:iBn,call:lBn,nodes:cBn,node:uBn,size:dBn,empty:fBn,each:pBn,attr:xBn,style:OBn,property:jBn,classed:ABn,text:MBn,html:zBn,raise:UBn,lower:VBn,append:HBn,insert:ZBn,remove:QBn,clone:KBn,datum:JBn,on:sUn,dispatch:oUn,[Symbol.iterator]:lUn};function gp(e){return typeof e=="string"?new qp([[document.querySelector(e)]],[document.documentElement]):new qp([[e]],Hxt)}function uUn(e){let t;for(;t=e.sourceEvent;)e=t;return e}function Jm(e,t){if(e=uUn(e),t===void 0&&(t=e.currentTarget),t){var n=t.ownerSVGElement||t;if(n.createSVGPoint){var r=n.createSVGPoint();return r.x=e.clientX,r.y=e.clientY,r=r.matrixTransform(t.getScreenCTM().inverse()),[r.x,r.y]}if(t.getBoundingClientRect){var s=t.getBoundingClientRect();return[e.clientX-s.left-t.clientLeft,e.clientY-s.top-t.clientTop]}}return[e.pageX,e.pageY]}const dUn={passive:!1},eM={capture:!0,passive:!1};function VJ(e){e.stopImmediatePropagation()}function _j(e){e.preventDefault(),e.stopImmediatePropagation()}function Wxt(e){var t=e.document.documentElement,n=gp(e).on("dragstart.drag",_j,eM);"onselectstart"in t?n.on("selectstart.drag",_j,eM):(t.__noselect=t.style.MozUserSelect,t.style.MozUserSelect="none")}function Zxt(e,t){var n=e.document.documentElement,r=gp(e).on("dragstart.drag",null);t&&(r.on("click.drag",_j,eM),setTimeout(function(){r.on("click.drag",null)},0)),"onselectstart"in n?r.on("selectstart.drag",null):(n.style.MozUserSelect=n.__noselect,delete n.__noselect)}const O6=e=>()=>e;function Ohe(e,{sourceEvent:t,subject:n,target:r,identifier:s,active:a,x:i,y:l,dx:c,dy:u,dispatch:d}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},subject:{value:n,enumerable:!0,configurable:!0},target:{value:r,enumerable:!0,configurable:!0},identifier:{value:s,enumerable:!0,configurable:!0},active:{value:a,enumerable:!0,configurable:!0},x:{value:i,enumerable:!0,configurable:!0},y:{value:l,enumerable:!0,configurable:!0},dx:{value:c,enumerable:!0,configurable:!0},dy:{value:u,enumerable:!0,configurable:!0},_:{value:d}})}Ohe.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function fUn(e){return!e.ctrlKey&&!e.button}function pUn(){return this.parentNode}function hUn(e,t){return t??{x:e.x,y:e.y}}function mUn(){return navigator.maxTouchPoints||"ontouchstart"in this}function Gxt(){var e=fUn,t=pUn,n=hUn,r=mUn,s={},a=TV("start","drag","end"),i=0,l,c,u,d,f=0;function p(k){k.on("mousedown.drag",h).filter(r).on("touchstart.drag",y).on("touchmove.drag",b,dUn).on("touchend.drag touchcancel.drag",S).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function h(k,_){if(!(d||!e.call(this,k,_))){var C=w(this,t.call(this,k,_),k,_,"mouse");C&&(gp(k.view).on("mousemove.drag",m,eM).on("mouseup.drag",v,eM),Wxt(k.view),VJ(k),u=!1,l=k.clientX,c=k.clientY,C("start",k))}}function m(k){if(_j(k),!u){var _=k.clientX-l,C=k.clientY-c;u=_*_+C*C>f}s.mouse("drag",k)}function v(k){gp(k.view).on("mousemove.drag mouseup.drag",null),Zxt(k.view,u),_j(k),s.mouse("end",k)}function y(k,_){if(e.call(this,k,_)){var C=k.changedTouches,E=t.call(this,k,_),j=C.length,N,I;for(N=0;N<j;++N)(I=w(this,E,k,_,C[N].identifier,C[N]))&&(VJ(k),I("start",k,C[N]))}}function b(k){var _=k.changedTouches,C=_.length,E,j;for(E=0;E<C;++E)(j=s[_[E].identifier])&&(_j(k),j("drag",k,_[E]))}function S(k){var _=k.changedTouches,C=_.length,E,j;for(d&&clearTimeout(d),d=setTimeout(function(){d=null},500),E=0;E<C;++E)(j=s[_[E].identifier])&&(VJ(k),j("end",k,_[E]))}function w(k,_,C,E,j,N){var I=a.copy(),R=Jm(N||C,_),P,L,M;if((M=n.call(k,new Ohe("beforestart",{sourceEvent:C,target:p,identifier:j,active:i,x:R[0],y:R[1],dx:0,dy:0,dispatch:I}),E))!=null)return P=M.x-R[0]||0,L=M.y-R[1]||0,function q(H,F,z){var B=R,D;switch(H){case"start":s[j]=q,D=i++;break;case"end":delete s[j],--i;case"drag":R=Jm(z||F,_),D=i;break}I.call(H,k,new Ohe(H,{sourceEvent:F,subject:M,target:p,identifier:j,active:D,x:R[0]+P,y:R[1]+L,dx:R[0]-B[0],dy:R[1]-B[1],dispatch:I}),E)}}return p.filter=function(k){return arguments.length?(e=typeof k=="function"?k:O6(!!k),p):e},p.container=function(k){return arguments.length?(t=typeof k=="function"?k:O6(k),p):t},p.subject=function(k){return arguments.length?(n=typeof k=="function"?k:O6(k),p):n},p.touchable=function(k){return arguments.length?(r=typeof k=="function"?k:O6(!!k),p):r},p.on=function(){var k=a.on.apply(a,arguments);return k===a?p:k},p.clickDistance=function(k){return arguments.length?(f=(k=+k)*k,p):Math.sqrt(f)},p}function f1e(e,t,n){e.prototype=t.prototype=n,n.constructor=e}function Qxt(e,t){var n=Object.create(e.prototype);for(var r in t)n[r]=t[r];return n}function h3(){}var tM=.7,I7=1/tM,Cj="\\s*([+-]?\\d+)\\s*",nM="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",Jv="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",gUn=/^#([0-9a-f]{3,8})$/,vUn=new RegExp(`^rgb\\(${Cj},${Cj},${Cj}\\)$`),yUn=new RegExp(`^rgb\\(${Jv},${Jv},${Jv}\\)$`),bUn=new RegExp(`^rgba\\(${Cj},${Cj},${Cj},${nM}\\)$`),xUn=new RegExp(`^rgba\\(${Jv},${Jv},${Jv},${nM}\\)$`),wUn=new RegExp(`^hsl\\(${nM},${Jv},${Jv}\\)$`),SUn=new RegExp(`^hsla\\(${nM},${Jv},${Jv},${nM}\\)$`),S9e={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074};f1e(h3,$O,{copy(e){return Object.assign(new this.constructor,this,e)},displayable(){return this.rgb().displayable()},hex:k9e,formatHex:k9e,formatHex8:kUn,formatHsl:OUn,formatRgb:O9e,toString:O9e});function k9e(){return this.rgb().formatHex()}function kUn(){return this.rgb().formatHex8()}function OUn(){return Yxt(this).formatHsl()}function O9e(){return this.rgb().formatRgb()}function $O(e){var t,n;return e=(e+"").trim().toLowerCase(),(t=gUn.exec(e))?(n=t[1].length,t=parseInt(t[1],16),n===6?_9e(t):n===3?new nf(t>>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?_6(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?_6(t>>12&15|t>>8&240,t>>8&15|t>>4&240,t>>4&15|t&240,((t&15)<<4|t&15)/255):null):(t=vUn.exec(e))?new nf(t[1],t[2],t[3],1):(t=yUn.exec(e))?new nf(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=bUn.exec(e))?_6(t[1],t[2],t[3],t[4]):(t=xUn.exec(e))?_6(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=wUn.exec(e))?j9e(t[1],t[2]/100,t[3]/100,1):(t=SUn.exec(e))?j9e(t[1],t[2]/100,t[3]/100,t[4]):S9e.hasOwnProperty(e)?_9e(S9e[e]):e==="transparent"?new nf(NaN,NaN,NaN,0):null}function _9e(e){return new nf(e>>16&255,e>>8&255,e&255,1)}function _6(e,t,n,r){return r<=0&&(e=t=n=NaN),new nf(e,t,n,r)}function _Un(e){return e instanceof h3||(e=$O(e)),e?(e=e.rgb(),new nf(e.r,e.g,e.b,e.opacity)):new nf}function _he(e,t,n,r){return arguments.length===1?_Un(e):new nf(e,t,n,r??1)}function nf(e,t,n,r){this.r=+e,this.g=+t,this.b=+n,this.opacity=+r}f1e(nf,_he,Qxt(h3,{brighter(e){return e=e==null?I7:Math.pow(I7,e),new nf(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?tM:Math.pow(tM,e),new nf(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new nf(Wk(this.r),Wk(this.g),Wk(this.b),A7(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:C9e,formatHex:C9e,formatHex8:CUn,formatRgb:E9e,toString:E9e}));function C9e(){return`#${Nk(this.r)}${Nk(this.g)}${Nk(this.b)}`}function CUn(){return`#${Nk(this.r)}${Nk(this.g)}${Nk(this.b)}${Nk((isNaN(this.opacity)?1:this.opacity)*255)}`}function E9e(){const e=A7(this.opacity);return`${e===1?"rgb(":"rgba("}${Wk(this.r)}, ${Wk(this.g)}, ${Wk(this.b)}${e===1?")":`, ${e})`}`}function A7(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function Wk(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function Nk(e){return e=Wk(e),(e<16?"0":"")+e.toString(16)}function j9e(e,t,n,r){return r<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new ag(e,t,n,r)}function Yxt(e){if(e instanceof ag)return new ag(e.h,e.s,e.l,e.opacity);if(e instanceof h3||(e=$O(e)),!e)return new ag;if(e instanceof ag)return e;e=e.rgb();var t=e.r/255,n=e.g/255,r=e.b/255,s=Math.min(t,n,r),a=Math.max(t,n,r),i=NaN,l=a-s,c=(a+s)/2;return l?(t===a?i=(n-r)/l+(n<r)*6:n===a?i=(r-t)/l+2:i=(t-n)/l+4,l/=c<.5?a+s:2-a-s,i*=60):l=c>0&&c<1?0:i,new ag(i,l,c,e.opacity)}function EUn(e,t,n,r){return arguments.length===1?Yxt(e):new ag(e,t,n,r??1)}function ag(e,t,n,r){this.h=+e,this.s=+t,this.l=+n,this.opacity=+r}f1e(ag,EUn,Qxt(h3,{brighter(e){return e=e==null?I7:Math.pow(I7,e),new ag(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?tM:Math.pow(tM,e),new ag(this.h,this.s,this.l*e,this.opacity)},rgb(){var e=this.h%360+(this.h<0)*360,t=isNaN(e)||isNaN(this.s)?0:this.s,n=this.l,r=n+(n<.5?n:1-n)*t,s=2*n-r;return new nf(HJ(e>=240?e-240:e+120,s,r),HJ(e,s,r),HJ(e<120?e+240:e-120,s,r),this.opacity)},clamp(){return new ag(T9e(this.h),C6(this.s),C6(this.l),A7(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const e=A7(this.opacity);return`${e===1?"hsl(":"hsla("}${T9e(this.h)}, ${C6(this.s)*100}%, ${C6(this.l)*100}%${e===1?")":`, ${e})`}`}}));function T9e(e){return e=(e||0)%360,e<0?e+360:e}function C6(e){return Math.max(0,Math.min(1,e||0))}function HJ(e,t,n){return(e<60?t+(n-t)*e/60:e<180?n:e<240?t+(n-t)*(240-e)/60:t)*255}const p1e=e=>()=>e;function jUn(e,t){return function(n){return e+n*t}}function TUn(e,t,n){return e=Math.pow(e,n),t=Math.pow(t,n)-e,n=1/n,function(r){return Math.pow(e+r*t,n)}}function NUn(e){return(e=+e)==1?Xxt:function(t,n){return n-t?TUn(t,n,e):p1e(isNaN(t)?n:t)}}function Xxt(e,t){var n=t-e;return n?jUn(e,n):p1e(isNaN(e)?t:e)}const R7=(function e(t){var n=NUn(t);function r(s,a){var i=n((s=_he(s)).r,(a=_he(a)).r),l=n(s.g,a.g),c=n(s.b,a.b),u=Xxt(s.opacity,a.opacity);return function(d){return s.r=i(d),s.g=l(d),s.b=c(d),s.opacity=u(d),s+""}}return r.gamma=e,r})(1);function IUn(e,t){t||(t=[]);var n=e?Math.min(t.length,e.length):0,r=t.slice(),s;return function(a){for(s=0;s<n;++s)r[s]=e[s]*(1-a)+t[s]*a;return r}}function AUn(e){return ArrayBuffer.isView(e)&&!(e instanceof DataView)}function RUn(e,t){var n=t?t.length:0,r=e?Math.min(n,e.length):0,s=new Array(r),a=new Array(n),i;for(i=0;i<r;++i)s[i]=ix(e[i],t[i]);for(;i<n;++i)a[i]=t[i];return function(l){for(i=0;i<r;++i)a[i]=s[i](l);return a}}function PUn(e,t){var n=new Date;return e=+e,t=+t,function(r){return n.setTime(e*(1-r)+t*r),n}}function tg(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}function $Un(e,t){var n={},r={},s;(e===null||typeof e!="object")&&(e={}),(t===null||typeof t!="object")&&(t={});for(s in t)s in e?n[s]=ix(e[s],t[s]):r[s]=t[s];return function(a){for(s in n)r[s]=n[s](a);return r}}var Che=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,WJ=new RegExp(Che.source,"g");function MUn(e){return function(){return e}}function DUn(e){return function(t){return e(t)+""}}function Kxt(e,t){var n=Che.lastIndex=WJ.lastIndex=0,r,s,a,i=-1,l=[],c=[];for(e=e+"",t=t+"";(r=Che.exec(e))&&(s=WJ.exec(t));)(a=s.index)>n&&(a=t.slice(n,a),l[i]?l[i]+=a:l[++i]=a),(r=r[0])===(s=s[0])?l[i]?l[i]+=s:l[++i]=s:(l[++i]=null,c.push({i,x:tg(r,s)})),n=WJ.lastIndex;return n<t.length&&(a=t.slice(n),l[i]?l[i]+=a:l[++i]=a),l.length<2?c[0]?DUn(c[0].x):MUn(t):(t=c.length,function(u){for(var d=0,f;d<t;++d)l[(f=c[d]).i]=f.x(u);return l.join("")})}function ix(e,t){var n=typeof t,r;return t==null||n==="boolean"?p1e(t):(n==="number"?tg:n==="string"?(r=$O(t))?(t=r,R7):Kxt:t instanceof $O?R7:t instanceof Date?PUn:AUn(t)?IUn:Array.isArray(t)?RUn:typeof t.valueOf!="function"&&typeof t.toString!="function"||isNaN(t)?$Un:tg)(e,t)}function h1e(e,t){return e=+e,t=+t,function(n){return Math.round(e*(1-n)+t*n)}}var N9e=180/Math.PI,Ehe={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function Jxt(e,t,n,r,s,a){var i,l,c;return(i=Math.sqrt(e*e+t*t))&&(e/=i,t/=i),(c=e*n+t*r)&&(n-=e*c,r-=t*c),(l=Math.sqrt(n*n+r*r))&&(n/=l,r/=l,c/=l),e*r<t*n&&(e=-e,t=-t,c=-c,i=-i),{translateX:s,translateY:a,rotate:Math.atan2(t,e)*N9e,skewX:Math.atan(c)*N9e,scaleX:i,scaleY:l}}var E6;function LUn(e){const t=new(typeof DOMMatrix=="function"?DOMMatrix:WebKitCSSMatrix)(e+"");return t.isIdentity?Ehe:Jxt(t.a,t.b,t.c,t.d,t.e,t.f)}function FUn(e){return e==null||(E6||(E6=document.createElementNS("http://www.w3.org/2000/svg","g")),E6.setAttribute("transform",e),!(e=E6.transform.baseVal.consolidate()))?Ehe:(e=e.matrix,Jxt(e.a,e.b,e.c,e.d,e.e,e.f))}function e0t(e,t,n,r){function s(u){return u.length?u.pop()+" ":""}function a(u,d,f,p,h,m){if(u!==f||d!==p){var v=h.push("translate(",null,t,null,n);m.push({i:v-4,x:tg(u,f)},{i:v-2,x:tg(d,p)})}else(f||p)&&h.push("translate("+f+t+p+n)}function i(u,d,f,p){u!==d?(u-d>180?d+=360:d-u>180&&(u+=360),p.push({i:f.push(s(f)+"rotate(",null,r)-2,x:tg(u,d)})):d&&f.push(s(f)+"rotate("+d+r)}function l(u,d,f,p){u!==d?p.push({i:f.push(s(f)+"skewX(",null,r)-2,x:tg(u,d)}):d&&f.push(s(f)+"skewX("+d+r)}function c(u,d,f,p,h,m){if(u!==f||d!==p){var v=h.push(s(h)+"scale(",null,",",null,")");m.push({i:v-4,x:tg(u,f)},{i:v-2,x:tg(d,p)})}else(f!==1||p!==1)&&h.push(s(h)+"scale("+f+","+p+")")}return function(u,d){var f=[],p=[];return u=e(u),d=e(d),a(u.translateX,u.translateY,d.translateX,d.translateY,f,p),i(u.rotate,d.rotate,f,p),l(u.skewX,d.skewX,f,p),c(u.scaleX,u.scaleY,d.scaleX,d.scaleY,f,p),u=d=null,function(h){for(var m=-1,v=p.length,y;++m<v;)f[(y=p[m]).i]=y.x(h);return f.join("")}}}var zUn=e0t(LUn,"px, ","px)","deg)"),BUn=e0t(FUn,", ",")",")"),UUn=1e-12;function I9e(e){return((e=Math.exp(e))+1/e)/2}function qUn(e){return((e=Math.exp(e))-1/e)/2}function VUn(e){return((e=Math.exp(2*e))-1)/(e+1)}const JF=(function e(t,n,r){function s(a,i){var l=a[0],c=a[1],u=a[2],d=i[0],f=i[1],p=i[2],h=d-l,m=f-c,v=h*h+m*m,y,b;if(v<UUn)b=Math.log(p/u)/t,y=function(E){return[l+E*h,c+E*m,u*Math.exp(t*E*b)]};else{var S=Math.sqrt(v),w=(p*p-u*u+r*v)/(2*u*n*S),k=(p*p-u*u-r*v)/(2*p*n*S),_=Math.log(Math.sqrt(w*w+1)-w),C=Math.log(Math.sqrt(k*k+1)-k);b=(C-_)/t,y=function(E){var j=E*b,N=I9e(_),I=u/(n*S)*(N*VUn(t*j+_)-qUn(_));return[l+I*h,c+I*m,u*N/I9e(t*j+_)]}}return y.duration=b*1e3*t/Math.SQRT2,y}return s.rho=function(a){var i=Math.max(.001,+a),l=i*i,c=l*l;return e(i,l,c)},s})(Math.SQRT2,2,4);function HUn(e,t){t===void 0&&(t=e,e=ix);for(var n=0,r=t.length-1,s=t[0],a=new Array(r<0?0:r);n<r;)a[n]=e(s,s=t[++n]);return function(i){var l=Math.max(0,Math.min(r-1,Math.floor(i*=r)));return a[l](i-l)}}var ST=0,u2=0,YA=0,t0t=1e3,P7,d2,$7=0,MO=0,IV=0,rM=typeof performance=="object"&&performance.now?performance:Date,n0t=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(e){setTimeout(e,17)};function m1e(){return MO||(n0t(WUn),MO=rM.now()+IV)}function WUn(){MO=0}function M7(){this._call=this._time=this._next=null}M7.prototype=r0t.prototype={constructor:M7,restart:function(e,t,n){if(typeof e!="function")throw new TypeError("callback is not a function");n=(n==null?m1e():+n)+(t==null?0:+t),!this._next&&d2!==this&&(d2?d2._next=this:P7=this,d2=this),this._call=e,this._time=n,jhe()},stop:function(){this._call&&(this._call=null,this._time=1/0,jhe())}};function r0t(e,t,n){var r=new M7;return r.restart(e,t,n),r}function ZUn(){m1e(),++ST;for(var e=P7,t;e;)(t=MO-e._time)>=0&&e._call.call(void 0,t),e=e._next;--ST}function A9e(){MO=($7=rM.now())+IV,ST=u2=0;try{ZUn()}finally{ST=0,QUn(),MO=0}}function GUn(){var e=rM.now(),t=e-$7;t>t0t&&(IV-=t,$7=e)}function QUn(){for(var e,t=P7,n,r=1/0;t;)t._call?(r>t._time&&(r=t._time),e=t,t=t._next):(n=t._next,t._next=null,t=e?e._next=n:P7=n);d2=e,jhe(r)}function jhe(e){if(!ST){u2&&(u2=clearTimeout(u2));var t=e-MO;t>24?(e<1/0&&(u2=setTimeout(A9e,e-rM.now()-IV)),YA&&(YA=clearInterval(YA))):(YA||($7=rM.now(),YA=setInterval(GUn,t0t)),ST=1,n0t(A9e))}}function R9e(e,t,n){var r=new M7;return t=t==null?0:+t,r.restart(s=>{r.stop(),e(s+t)},t,n),r}var YUn=TV("start","end","cancel","interrupt"),XUn=[],s0t=0,P9e=1,The=2,e8=3,$9e=4,Nhe=5,t8=6;function AV(e,t,n,r,s,a){var i=e.__transition;if(!i)e.__transition={};else if(n in i)return;KUn(e,n,{name:t,index:r,group:s,on:YUn,tween:XUn,time:a.time,delay:a.delay,duration:a.duration,ease:a.ease,timer:null,state:s0t})}function g1e(e,t){var n=zg(e,t);if(n.state>s0t)throw new Error("too late; already scheduled");return n}function Dy(e,t){var n=zg(e,t);if(n.state>e8)throw new Error("too late; already running");return n}function zg(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw new Error("transition not found");return n}function KUn(e,t,n){var r=e.__transition,s;r[t]=n,n.timer=r0t(a,0,n.time);function a(u){n.state=P9e,n.timer.restart(i,n.delay,n.time),n.delay<=u&&i(u-n.delay)}function i(u){var d,f,p,h;if(n.state!==P9e)return c();for(d in r)if(h=r[d],h.name===n.name){if(h.state===e8)return R9e(i);h.state===$9e?(h.state=t8,h.timer.stop(),h.on.call("interrupt",e,e.__data__,h.index,h.group),delete r[d]):+d<t&&(h.state=t8,h.timer.stop(),h.on.call("cancel",e,e.__data__,h.index,h.group),delete r[d])}if(R9e(function(){n.state===e8&&(n.state=$9e,n.timer.restart(l,n.delay,n.time),l(u))}),n.state=The,n.on.call("start",e,e.__data__,n.index,n.group),n.state===The){for(n.state=e8,s=new Array(p=n.tween.length),d=0,f=-1;d<p;++d)(h=n.tween[d].value.call(e,e.__data__,n.index,n.group))&&(s[++f]=h);s.length=f+1}}function l(u){for(var d=u<n.duration?n.ease.call(null,u/n.duration):(n.timer.restart(c),n.state=Nhe,1),f=-1,p=s.length;++f<p;)s[f].call(e,d);n.state===Nhe&&(n.on.call("end",e,e.__data__,n.index,n.group),c())}function c(){n.state=t8,n.timer.stop(),delete r[t];for(var u in r)return;delete e.__transition}}function n8(e,t){var n=e.__transition,r,s,a=!0,i;if(n){t=t==null?null:t+"";for(i in n){if((r=n[i]).name!==t){a=!1;continue}s=r.state>The&&r.state<Nhe,r.state=t8,r.timer.stop(),r.on.call(s?"interrupt":"cancel",e,e.__data__,r.index,r.group),delete n[i]}a&&delete e.__transition}}function JUn(e){return this.each(function(){n8(this,e)})}function eqn(e,t){var n,r;return function(){var s=Dy(this,e),a=s.tween;if(a!==n){r=n=a;for(var i=0,l=r.length;i<l;++i)if(r[i].name===t){r=r.slice(),r.splice(i,1);break}}s.tween=r}}function tqn(e,t,n){var r,s;if(typeof n!="function")throw new Error;return function(){var a=Dy(this,e),i=a.tween;if(i!==r){s=(r=i).slice();for(var l={name:t,value:n},c=0,u=s.length;c<u;++c)if(s[c].name===t){s[c]=l;break}c===u&&s.push(l)}a.tween=s}}function nqn(e,t){var n=this._id;if(e+="",arguments.length<2){for(var r=zg(this.node(),n).tween,s=0,a=r.length,i;s<a;++s)if((i=r[s]).name===e)return i.value;return null}return this.each((t==null?eqn:tqn)(n,e,t))}function v1e(e,t,n){var r=e._id;return e.each(function(){var s=Dy(this,r);(s.value||(s.value={}))[t]=n.apply(this,arguments)}),function(s){return zg(s,r).value[t]}}function a0t(e,t){var n;return(typeof t=="number"?tg:t instanceof $O?R7:(n=$O(t))?(t=n,R7):Kxt)(e,t)}function rqn(e){return function(){this.removeAttribute(e)}}function sqn(e){return function(){this.removeAttributeNS(e.space,e.local)}}function aqn(e,t,n){var r,s=n+"",a;return function(){var i=this.getAttribute(e);return i===s?null:i===r?a:a=t(r=i,n)}}function iqn(e,t,n){var r,s=n+"",a;return function(){var i=this.getAttributeNS(e.space,e.local);return i===s?null:i===r?a:a=t(r=i,n)}}function oqn(e,t,n){var r,s,a;return function(){var i,l=n(this),c;return l==null?void this.removeAttribute(e):(i=this.getAttribute(e),c=l+"",i===c?null:i===r&&c===s?a:(s=c,a=t(r=i,l)))}}function lqn(e,t,n){var r,s,a;return function(){var i,l=n(this),c;return l==null?void this.removeAttributeNS(e.space,e.local):(i=this.getAttributeNS(e.space,e.local),c=l+"",i===c?null:i===r&&c===s?a:(s=c,a=t(r=i,l)))}}function cqn(e,t){var n=NV(e),r=n==="transform"?BUn:a0t;return this.attrTween(e,typeof t=="function"?(n.local?lqn:oqn)(n,r,v1e(this,"attr."+e,t)):t==null?(n.local?sqn:rqn)(n):(n.local?iqn:aqn)(n,r,t))}function uqn(e,t){return function(n){this.setAttribute(e,t.call(this,n))}}function dqn(e,t){return function(n){this.setAttributeNS(e.space,e.local,t.call(this,n))}}function fqn(e,t){var n,r;function s(){var a=t.apply(this,arguments);return a!==r&&(n=(r=a)&&dqn(e,a)),n}return s._value=t,s}function pqn(e,t){var n,r;function s(){var a=t.apply(this,arguments);return a!==r&&(n=(r=a)&&uqn(e,a)),n}return s._value=t,s}function hqn(e,t){var n="attr."+e;if(arguments.length<2)return(n=this.tween(n))&&n._value;if(t==null)return this.tween(n,null);if(typeof t!="function")throw new Error;var r=NV(e);return this.tween(n,(r.local?fqn:pqn)(r,t))}function mqn(e,t){return function(){g1e(this,e).delay=+t.apply(this,arguments)}}function gqn(e,t){return t=+t,function(){g1e(this,e).delay=t}}function vqn(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?mqn:gqn)(t,e)):zg(this.node(),t).delay}function yqn(e,t){return function(){Dy(this,e).duration=+t.apply(this,arguments)}}function bqn(e,t){return t=+t,function(){Dy(this,e).duration=t}}function xqn(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?yqn:bqn)(t,e)):zg(this.node(),t).duration}function wqn(e,t){if(typeof t!="function")throw new Error;return function(){Dy(this,e).ease=t}}function Sqn(e){var t=this._id;return arguments.length?this.each(wqn(t,e)):zg(this.node(),t).ease}function kqn(e,t){return function(){var n=t.apply(this,arguments);if(typeof n!="function")throw new Error;Dy(this,e).ease=n}}function Oqn(e){if(typeof e!="function")throw new Error;return this.each(kqn(this._id,e))}function _qn(e){typeof e!="function"&&(e=Mxt(e));for(var t=this._groups,n=t.length,r=new Array(n),s=0;s<n;++s)for(var a=t[s],i=a.length,l=r[s]=[],c,u=0;u<i;++u)(c=a[u])&&e.call(c,c.__data__,u,a)&&l.push(c);return new Cx(r,this._parents,this._name,this._id)}function Cqn(e){if(e._id!==this._id)throw new Error;for(var t=this._groups,n=e._groups,r=t.length,s=n.length,a=Math.min(r,s),i=new Array(r),l=0;l<a;++l)for(var c=t[l],u=n[l],d=c.length,f=i[l]=new Array(d),p,h=0;h<d;++h)(p=c[h]||u[h])&&(f[h]=p);for(;l<r;++l)i[l]=t[l];return new Cx(i,this._parents,this._name,this._id)}function Eqn(e){return(e+"").trim().split(/^|\s+/).every(function(t){var n=t.indexOf(".");return n>=0&&(t=t.slice(0,n)),!t||t==="start"})}function jqn(e,t,n){var r,s,a=Eqn(t)?g1e:Dy;return function(){var i=a(this,e),l=i.on;l!==r&&(s=(r=l).copy()).on(t,n),i.on=s}}function Tqn(e,t){var n=this._id;return arguments.length<2?zg(this.node(),n).on.on(e):this.each(jqn(n,e,t))}function Nqn(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function Iqn(){return this.on("end.remove",Nqn(this._id))}function Aqn(e){var t=this._name,n=this._id;typeof e!="function"&&(e=u1e(e));for(var r=this._groups,s=r.length,a=new Array(s),i=0;i<s;++i)for(var l=r[i],c=l.length,u=a[i]=new Array(c),d,f,p=0;p<c;++p)(d=l[p])&&(f=e.call(d,d.__data__,p,l))&&("__data__"in d&&(f.__data__=d.__data__),u[p]=f,AV(u[p],t,n,p,u,zg(d,n)));return new Cx(a,this._parents,t,n)}function Rqn(e){var t=this._name,n=this._id;typeof e!="function"&&(e=$xt(e));for(var r=this._groups,s=r.length,a=[],i=[],l=0;l<s;++l)for(var c=r[l],u=c.length,d,f=0;f<u;++f)if(d=c[f]){for(var p=e.call(d,d.__data__,f,c),h,m=zg(d,n),v=0,y=p.length;v<y;++v)(h=p[v])&&AV(h,t,n,v,p,m);a.push(p),i.push(d)}return new Cx(a,i,t,n)}var Pqn=p3.prototype.constructor;function $qn(){return new Pqn(this._groups,this._parents)}function Mqn(e,t){var n,r,s;return function(){var a=wT(this,e),i=(this.style.removeProperty(e),wT(this,e));return a===i?null:a===n&&i===r?s:s=t(n=a,r=i)}}function i0t(e){return function(){this.style.removeProperty(e)}}function Dqn(e,t,n){var r,s=n+"",a;return function(){var i=wT(this,e);return i===s?null:i===r?a:a=t(r=i,n)}}function Lqn(e,t,n){var r,s,a;return function(){var i=wT(this,e),l=n(this),c=l+"";return l==null&&(c=l=(this.style.removeProperty(e),wT(this,e))),i===c?null:i===r&&c===s?a:(s=c,a=t(r=i,l))}}function Fqn(e,t){var n,r,s,a="style."+t,i="end."+a,l;return function(){var c=Dy(this,e),u=c.on,d=c.value[a]==null?l||(l=i0t(t)):void 0;(u!==n||s!==d)&&(r=(n=u).copy()).on(i,s=d),c.on=r}}function zqn(e,t,n){var r=(e+="")=="transform"?zUn:a0t;return t==null?this.styleTween(e,Mqn(e,r)).on("end.style."+e,i0t(e)):typeof t=="function"?this.styleTween(e,Lqn(e,r,v1e(this,"style."+e,t))).each(Fqn(this._id,e)):this.styleTween(e,Dqn(e,r,t),n).on("end.style."+e,null)}function Bqn(e,t,n){return function(r){this.style.setProperty(e,t.call(this,r),n)}}function Uqn(e,t,n){var r,s;function a(){var i=t.apply(this,arguments);return i!==s&&(r=(s=i)&&Bqn(e,i,n)),r}return a._value=t,a}function qqn(e,t,n){var r="style."+(e+="");if(arguments.length<2)return(r=this.tween(r))&&r._value;if(t==null)return this.tween(r,null);if(typeof t!="function")throw new Error;return this.tween(r,Uqn(e,t,n??""))}function Vqn(e){return function(){this.textContent=e}}function Hqn(e){return function(){var t=e(this);this.textContent=t??""}}function Wqn(e){return this.tween("text",typeof e=="function"?Hqn(v1e(this,"text",e)):Vqn(e==null?"":e+""))}function Zqn(e){return function(t){this.textContent=e.call(this,t)}}function Gqn(e){var t,n;function r(){var s=e.apply(this,arguments);return s!==n&&(t=(n=s)&&Zqn(s)),t}return r._value=e,r}function Qqn(e){var t="text";if(arguments.length<1)return(t=this.tween(t))&&t._value;if(e==null)return this.tween(t,null);if(typeof e!="function")throw new Error;return this.tween(t,Gqn(e))}function Yqn(){for(var e=this._name,t=this._id,n=o0t(),r=this._groups,s=r.length,a=0;a<s;++a)for(var i=r[a],l=i.length,c,u=0;u<l;++u)if(c=i[u]){var d=zg(c,t);AV(c,e,n,u,i,{time:d.time+d.delay+d.duration,delay:0,duration:d.duration,ease:d.ease})}return new Cx(r,this._parents,e,n)}function Xqn(){var e,t,n=this,r=n._id,s=n.size();return new Promise(function(a,i){var l={value:i},c={value:function(){--s===0&&a()}};n.each(function(){var u=Dy(this,r),d=u.on;d!==e&&(t=(e=d).copy(),t._.cancel.push(l),t._.interrupt.push(l),t._.end.push(c)),u.on=t}),s===0&&a()})}var Kqn=0;function Cx(e,t,n,r){this._groups=e,this._parents=t,this._name=n,this._id=r}function o0t(){return++Kqn}var gb=p3.prototype;Cx.prototype={constructor:Cx,select:Aqn,selectAll:Rqn,selectChild:gb.selectChild,selectChildren:gb.selectChildren,filter:_qn,merge:Cqn,selection:$qn,transition:Yqn,call:gb.call,nodes:gb.nodes,node:gb.node,size:gb.size,empty:gb.empty,each:gb.each,on:Tqn,attr:cqn,attrTween:hqn,style:zqn,styleTween:qqn,text:Wqn,textTween:Qqn,remove:Iqn,tween:nqn,delay:vqn,duration:xqn,ease:Sqn,easeVarying:Oqn,end:Xqn,[Symbol.iterator]:gb[Symbol.iterator]};function Jqn(e){return((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2}var eVn={time:null,delay:0,duration:250,ease:Jqn};function tVn(e,t){for(var n;!(n=e.__transition)||!(n=n[t]);)if(!(e=e.parentNode))throw new Error(`transition ${t} not found`);return n}function nVn(e){var t,n;e instanceof Cx?(t=e._id,e=e._name):(t=o0t(),(n=eVn).time=m1e(),e=e==null?null:e+"");for(var r=this._groups,s=r.length,a=0;a<s;++a)for(var i=r[a],l=i.length,c,u=0;u<l;++u)(c=i[u])&&AV(c,e,t,u,i,n||tVn(c,t));return new Cx(r,this._parents,e,t)}p3.prototype.interrupt=JUn;p3.prototype.transition=nVn;const j6=e=>()=>e;function rVn(e,{sourceEvent:t,target:n,transform:r,dispatch:s}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},target:{value:n,enumerable:!0,configurable:!0},transform:{value:r,enumerable:!0,configurable:!0},_:{value:s}})}function Zb(e,t,n){this.k=e,this.x=t,this.y=n}Zb.prototype={constructor:Zb,scale:function(e){return e===1?this:new Zb(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new Zb(this.k,this.x+this.k*e,this.y+this.k*t)},apply:function(e){return[e[0]*this.k+this.x,e[1]*this.k+this.y]},applyX:function(e){return e*this.k+this.x},applyY:function(e){return e*this.k+this.y},invert:function(e){return[(e[0]-this.x)/this.k,(e[1]-this.y)/this.k]},invertX:function(e){return(e-this.x)/this.k},invertY:function(e){return(e-this.y)/this.k},rescaleX:function(e){return e.copy().domain(e.range().map(this.invertX,this).map(e.invert,e))},rescaleY:function(e){return e.copy().domain(e.range().map(this.invertY,this).map(e.invert,e))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};var RV=new Zb(1,0,0);l0t.prototype=Zb.prototype;function l0t(e){for(;!e.__zoom;)if(!(e=e.parentNode))return RV;return e.__zoom}function ZJ(e){e.stopImmediatePropagation()}function XA(e){e.preventDefault(),e.stopImmediatePropagation()}function sVn(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function aVn(){var e=this;return e instanceof SVGElement?(e=e.ownerSVGElement||e,e.hasAttribute("viewBox")?(e=e.viewBox.baseVal,[[e.x,e.y],[e.x+e.width,e.y+e.height]]):[[0,0],[e.width.baseVal.value,e.height.baseVal.value]]):[[0,0],[e.clientWidth,e.clientHeight]]}function M9e(){return this.__zoom||RV}function iVn(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function oVn(){return navigator.maxTouchPoints||"ontouchstart"in this}function lVn(e,t,n){var r=e.invertX(t[0][0])-n[0][0],s=e.invertX(t[1][0])-n[1][0],a=e.invertY(t[0][1])-n[0][1],i=e.invertY(t[1][1])-n[1][1];return e.translate(s>r?(r+s)/2:Math.min(0,r)||Math.max(0,s),i>a?(a+i)/2:Math.min(0,a)||Math.max(0,i))}function c0t(){var e=sVn,t=aVn,n=lVn,r=iVn,s=oVn,a=[0,1/0],i=[[-1/0,-1/0],[1/0,1/0]],l=250,c=JF,u=TV("start","zoom","end"),d,f,p,h=500,m=150,v=0,y=10;function b(M){M.property("__zoom",M9e).on("wheel.zoom",j,{passive:!1}).on("mousedown.zoom",N).on("dblclick.zoom",I).filter(s).on("touchstart.zoom",R).on("touchmove.zoom",P).on("touchend.zoom touchcancel.zoom",L).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}b.transform=function(M,q,H,F){var z=M.selection?M.selection():M;z.property("__zoom",M9e),M!==z?_(M,q,H,F):z.interrupt().each(function(){C(this,arguments).event(F).start().zoom(null,typeof q=="function"?q.apply(this,arguments):q).end()})},b.scaleBy=function(M,q,H,F){b.scaleTo(M,function(){var z=this.__zoom.k,B=typeof q=="function"?q.apply(this,arguments):q;return z*B},H,F)},b.scaleTo=function(M,q,H,F){b.transform(M,function(){var z=t.apply(this,arguments),B=this.__zoom,D=H==null?k(z):typeof H=="function"?H.apply(this,arguments):H,Q=B.invert(D),V=typeof q=="function"?q.apply(this,arguments):q;return n(w(S(B,V),D,Q),z,i)},H,F)},b.translateBy=function(M,q,H,F){b.transform(M,function(){return n(this.__zoom.translate(typeof q=="function"?q.apply(this,arguments):q,typeof H=="function"?H.apply(this,arguments):H),t.apply(this,arguments),i)},null,F)},b.translateTo=function(M,q,H,F,z){b.transform(M,function(){var B=t.apply(this,arguments),D=this.__zoom,Q=F==null?k(B):typeof F=="function"?F.apply(this,arguments):F;return n(RV.translate(Q[0],Q[1]).scale(D.k).translate(typeof q=="function"?-q.apply(this,arguments):-q,typeof H=="function"?-H.apply(this,arguments):-H),B,i)},F,z)};function S(M,q){return q=Math.max(a[0],Math.min(a[1],q)),q===M.k?M:new Zb(q,M.x,M.y)}function w(M,q,H){var F=q[0]-H[0]*M.k,z=q[1]-H[1]*M.k;return F===M.x&&z===M.y?M:new Zb(M.k,F,z)}function k(M){return[(+M[0][0]+ +M[1][0])/2,(+M[0][1]+ +M[1][1])/2]}function _(M,q,H,F){M.on("start.zoom",function(){C(this,arguments).event(F).start()}).on("interrupt.zoom end.zoom",function(){C(this,arguments).event(F).end()}).tween("zoom",function(){var z=this,B=arguments,D=C(z,B).event(F),Q=t.apply(z,B),V=H==null?k(Q):typeof H=="function"?H.apply(z,B):H,$=Math.max(Q[1][0]-Q[0][0],Q[1][1]-Q[0][1]),U=z.__zoom,Z=typeof q=="function"?q.apply(z,B):q,X=c(U.invert(V).concat($/U.k),Z.invert(V).concat($/Z.k));return function(te){if(te===1)te=Z;else{var J=X(te),ee=$/J[2];te=new Zb(ee,V[0]-J[0]*ee,V[1]-J[1]*ee)}D.zoom(null,te)}})}function C(M,q,H){return!H&&M.__zooming||new E(M,q)}function E(M,q){this.that=M,this.args=q,this.active=0,this.sourceEvent=null,this.extent=t.apply(M,q),this.taps=0}E.prototype={event:function(M){return M&&(this.sourceEvent=M),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(M,q){return this.mouse&&M!=="mouse"&&(this.mouse[1]=q.invert(this.mouse[0])),this.touch0&&M!=="touch"&&(this.touch0[1]=q.invert(this.touch0[0])),this.touch1&&M!=="touch"&&(this.touch1[1]=q.invert(this.touch1[0])),this.that.__zoom=q,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(M){var q=gp(this.that).datum();u.call(M,this.that,new rVn(M,{sourceEvent:this.sourceEvent,target:b,transform:this.that.__zoom,dispatch:u}),q)}};function j(M,...q){if(!e.apply(this,arguments))return;var H=C(this,q).event(M),F=this.__zoom,z=Math.max(a[0],Math.min(a[1],F.k*Math.pow(2,r.apply(this,arguments)))),B=Jm(M);if(H.wheel)(H.mouse[0][0]!==B[0]||H.mouse[0][1]!==B[1])&&(H.mouse[1]=F.invert(H.mouse[0]=B)),clearTimeout(H.wheel);else{if(F.k===z)return;H.mouse=[B,F.invert(B)],n8(this),H.start()}XA(M),H.wheel=setTimeout(D,m),H.zoom("mouse",n(w(S(F,z),H.mouse[0],H.mouse[1]),H.extent,i));function D(){H.wheel=null,H.end()}}function N(M,...q){if(p||!e.apply(this,arguments))return;var H=M.currentTarget,F=C(this,q,!0).event(M),z=gp(M.view).on("mousemove.zoom",V,!0).on("mouseup.zoom",$,!0),B=Jm(M,H),D=M.clientX,Q=M.clientY;Wxt(M.view),ZJ(M),F.mouse=[B,this.__zoom.invert(B)],n8(this),F.start();function V(U){if(XA(U),!F.moved){var Z=U.clientX-D,X=U.clientY-Q;F.moved=Z*Z+X*X>v}F.event(U).zoom("mouse",n(w(F.that.__zoom,F.mouse[0]=Jm(U,H),F.mouse[1]),F.extent,i))}function $(U){z.on("mousemove.zoom mouseup.zoom",null),Zxt(U.view,F.moved),XA(U),F.event(U).end()}}function I(M,...q){if(e.apply(this,arguments)){var H=this.__zoom,F=Jm(M.changedTouches?M.changedTouches[0]:M,this),z=H.invert(F),B=H.k*(M.shiftKey?.5:2),D=n(w(S(H,B),F,z),t.apply(this,q),i);XA(M),l>0?gp(this).transition().duration(l).call(_,D,F,M):gp(this).call(b.transform,D,F,M)}}function R(M,...q){if(e.apply(this,arguments)){var H=M.touches,F=H.length,z=C(this,q,M.changedTouches.length===F).event(M),B,D,Q,V;for(ZJ(M),D=0;D<F;++D)Q=H[D],V=Jm(Q,this),V=[V,this.__zoom.invert(V),Q.identifier],z.touch0?!z.touch1&&z.touch0[2]!==V[2]&&(z.touch1=V,z.taps=0):(z.touch0=V,B=!0,z.taps=1+!!d);d&&(d=clearTimeout(d)),B&&(z.taps<2&&(f=V[0],d=setTimeout(function(){d=null},h)),n8(this),z.start())}}function P(M,...q){if(this.__zooming){var H=C(this,q).event(M),F=M.changedTouches,z=F.length,B,D,Q,V;for(XA(M),B=0;B<z;++B)D=F[B],Q=Jm(D,this),H.touch0&&H.touch0[2]===D.identifier?H.touch0[0]=Q:H.touch1&&H.touch1[2]===D.identifier&&(H.touch1[0]=Q);if(D=H.that.__zoom,H.touch1){var $=H.touch0[0],U=H.touch0[1],Z=H.touch1[0],X=H.touch1[1],te=(te=Z[0]-$[0])*te+(te=Z[1]-$[1])*te,J=(J=X[0]-U[0])*J+(J=X[1]-U[1])*J;D=S(D,Math.sqrt(te/J)),Q=[($[0]+Z[0])/2,($[1]+Z[1])/2],V=[(U[0]+X[0])/2,(U[1]+X[1])/2]}else if(H.touch0)Q=H.touch0[0],V=H.touch0[1];else return;H.zoom("touch",n(w(D,Q,V),H.extent,i))}}function L(M,...q){if(this.__zooming){var H=C(this,q).event(M),F=M.changedTouches,z=F.length,B,D;for(ZJ(M),p&&clearTimeout(p),p=setTimeout(function(){p=null},h),B=0;B<z;++B)D=F[B],H.touch0&&H.touch0[2]===D.identifier?delete H.touch0:H.touch1&&H.touch1[2]===D.identifier&&delete H.touch1;if(H.touch1&&!H.touch0&&(H.touch0=H.touch1,delete H.touch1),H.touch0)H.touch0[1]=this.__zoom.invert(H.touch0[0]);else if(H.end(),H.taps===2&&(D=Jm(D,this),Math.hypot(f[0]-D[0],f[1]-D[1])<y)){var Q=gp(this).on("dblclick.zoom");Q&&Q.apply(this,arguments)}}}return b.wheelDelta=function(M){return arguments.length?(r=typeof M=="function"?M:j6(+M),b):r},b.filter=function(M){return arguments.length?(e=typeof M=="function"?M:j6(!!M),b):e},b.touchable=function(M){return arguments.length?(s=typeof M=="function"?M:j6(!!M),b):s},b.extent=function(M){return arguments.length?(t=typeof M=="function"?M:j6([[+M[0][0],+M[0][1]],[+M[1][0],+M[1][1]]]),b):t},b.scaleExtent=function(M){return arguments.length?(a[0]=+M[0],a[1]=+M[1],b):[a[0],a[1]]},b.translateExtent=function(M){return arguments.length?(i[0][0]=+M[0][0],i[1][0]=+M[1][0],i[0][1]=+M[0][1],i[1][1]=+M[1][1],b):[[i[0][0],i[0][1]],[i[1][0],i[1][1]]]},b.constrain=function(M){return arguments.length?(n=M,b):n},b.duration=function(M){return arguments.length?(l=+M,b):l},b.interpolate=function(M){return arguments.length?(c=M,b):c},b.on=function(){var M=u.on.apply(u,arguments);return M===u?b:M},b.clickDistance=function(M){return arguments.length?(v=(M=+M)*M,b):Math.sqrt(v)},b.tapDistance=function(M){return arguments.length?(y=+M,b):y},b}const hy={error001:()=>"[React Flow]: Seems like you have not used zustand provider as an ancestor. Help: https://reactflow.dev/error#001",error002:()=>"It looks like you've created a new nodeTypes or edgeTypes object. If this wasn't on purpose please define the nodeTypes/edgeTypes outside of the component or memoize them.",error003:e=>`Node type "${e}" not found. Using fallback type "default".`,error004:()=>"The React Flow parent container needs a width and a height to render the graph.",error005:()=>"Only child nodes can use a parent extent.",error006:()=>"Can't create edge. An edge needs a source and a target.",error007:e=>`The old edge with id=${e} does not exist.`,error009:e=>`Marker type "${e}" doesn't exist.`,error008:(e,{id:t,sourceHandle:n,targetHandle:r})=>`Couldn't create edge for ${e} handle id: "${e==="source"?n:r}", edge id: ${t}.`,error010:()=>"Handle: No node id found. Make sure to only use a Handle inside a custom Node.",error011:e=>`Edge type "${e}" not found. Using fallback type "default".`,error012:e=>`Node with id "${e}" does not exist, it may have been removed. This can happen when a node is deleted before the "onNodeClick" handler is called.`,error013:(e="react")=>`It seems that you haven't loaded the styles. Please import '@xyflow/${e}/dist/style.css' or base.css to make sure everything is working properly.`,error014:()=>"useNodeConnections: No node ID found. Call useNodeConnections inside a custom Node or provide a node ID.",error015:()=>"It seems that you are trying to drag a node that is not initialized. Please use onNodesChange as explained in the docs."},sM=[[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY],[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]],u0t=["Enter"," ","Escape"],d0t={"node.a11yDescription.default":"Press enter or space to select a node. Press delete to remove it and escape to cancel.","node.a11yDescription.keyboardDisabled":"Press enter or space to select a node. You can then use the arrow keys to move the node around. Press delete to remove it and escape to cancel.","node.a11yDescription.ariaLiveMessage":({direction:e,x:t,y:n})=>`Moved selected node ${e}. New position, x: ${t}, y: ${n}`,"edge.a11yDescription.default":"Press enter or space to select an edge. You can then press delete to remove it or escape to cancel.","controls.ariaLabel":"Control Panel","controls.zoomIn.ariaLabel":"Zoom In","controls.zoomOut.ariaLabel":"Zoom Out","controls.fitView.ariaLabel":"Fit View","controls.interactive.ariaLabel":"Toggle Interactivity","minimap.ariaLabel":"Mini Map","handle.ariaLabel":"Handle"};var kT;(function(e){e.Strict="strict",e.Loose="loose"})(kT||(kT={}));var Zk;(function(e){e.Free="free",e.Vertical="vertical",e.Horizontal="horizontal"})(Zk||(Zk={}));var aM;(function(e){e.Partial="partial",e.Full="full"})(aM||(aM={}));const f0t={inProgress:!1,isValid:null,from:null,fromHandle:null,fromPosition:null,fromNode:null,to:null,toHandle:null,toPosition:null,toNode:null,pointer:null};var iw;(function(e){e.Bezier="default",e.Straight="straight",e.Step="step",e.SmoothStep="smoothstep",e.SimpleBezier="simplebezier"})(iw||(iw={}));var iM;(function(e){e.Arrow="arrow",e.ArrowClosed="arrowclosed"})(iM||(iM={}));var nr;(function(e){e.Left="left",e.Top="top",e.Right="right",e.Bottom="bottom"})(nr||(nr={}));const D9e={[nr.Left]:nr.Right,[nr.Right]:nr.Left,[nr.Top]:nr.Bottom,[nr.Bottom]:nr.Top};function p0t(e){return e===null?null:e?"valid":"invalid"}const h0t=e=>"id"in e&&"source"in e&&"target"in e,cVn=e=>"id"in e&&"position"in e&&!("source"in e)&&!("target"in e),y1e=e=>"id"in e&&"internals"in e&&!("source"in e)&&!("target"in e),m3=(e,t=[0,0])=>{const{width:n,height:r}=Gx(e),s=e.origin??t,a=n*s[0],i=r*s[1];return{x:e.position.x-a,y:e.position.y-i}},uVn=(e,t={nodeOrigin:[0,0]})=>{if(e.length===0)return{x:0,y:0,width:0,height:0};const n=e.reduce((r,s)=>{const a=typeof s=="string";let i=!t.nodeLookup&&!a?s:void 0;t.nodeLookup&&(i=a?t.nodeLookup.get(s):y1e(s)?s:t.nodeLookup.get(s.id));const l=i?D7(i,t.nodeOrigin):{x:0,y:0,x2:0,y2:0};return PV(r,l)},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return $V(n)},g3=(e,t={})=>{let n={x:1/0,y:1/0,x2:-1/0,y2:-1/0},r=!1;return e.forEach(s=>{(t.filter===void 0||t.filter(s))&&(n=PV(n,D7(s)),r=!0)}),r?$V(n):{x:0,y:0,width:0,height:0}},b1e=(e,t,[n,r,s]=[0,0,1],a=!1,i=!1)=>{const l={...y3(t,[n,r,s]),width:t.width/s,height:t.height/s},c=[];for(const u of e.values()){const{measured:d,selectable:f=!0,hidden:p=!1}=u;if(i&&!f||p)continue;const h=d.width??u.width??u.initialWidth??null,m=d.height??u.height??u.initialHeight??null,v=oM(l,_T(u)),y=(h??0)*(m??0),b=a&&v>0;(!u.internals.handleBounds||b||v>=y||u.dragging)&&c.push(u)}return c},dVn=(e,t)=>{const n=new Set;return e.forEach(r=>{n.add(r.id)}),t.filter(r=>n.has(r.source)||n.has(r.target))};function fVn(e,t){const n=new Map,r=t?.nodes?new Set(t.nodes.map(s=>s.id)):null;return e.forEach(s=>{s.measured.width&&s.measured.height&&(t?.includeHiddenNodes||!s.hidden)&&(!r||r.has(s.id))&&n.set(s.id,s)}),n}async function pVn({nodes:e,width:t,height:n,panZoom:r,minZoom:s,maxZoom:a},i){if(e.size===0)return Promise.resolve(!0);const l=fVn(e,i),c=g3(l),u=x1e(c,t,n,i?.minZoom??s,i?.maxZoom??a,i?.padding??.1);return await r.setViewport(u,{duration:i?.duration,ease:i?.ease,interpolate:i?.interpolate}),Promise.resolve(!0)}function m0t({nodeId:e,nextPosition:t,nodeLookup:n,nodeOrigin:r=[0,0],nodeExtent:s,onError:a}){const i=n.get(e),l=i.parentId?n.get(i.parentId):void 0,{x:c,y:u}=l?l.internals.positionAbsolute:{x:0,y:0},d=i.origin??r;let f=i.extent||s;if(i.extent==="parent"&&!i.expandParent)if(!l)a?.("005",hy.error005());else{const h=l.measured.width,m=l.measured.height;h&&m&&(f=[[c,u],[c+h,u+m]])}else l&&CT(i.extent)&&(f=[[i.extent[0][0]+c,i.extent[0][1]+u],[i.extent[1][0]+c,i.extent[1][1]+u]]);const p=CT(f)?DO(t,f,i.measured):t;return(i.measured.width===void 0||i.measured.height===void 0)&&a?.("015",hy.error015()),{position:{x:p.x-c+(i.measured.width??0)*d[0],y:p.y-u+(i.measured.height??0)*d[1]},positionAbsolute:p}}async function hVn({nodesToRemove:e=[],edgesToRemove:t=[],nodes:n,edges:r,onBeforeDelete:s}){const a=new Set(e.map(p=>p.id)),i=[];for(const p of n){if(p.deletable===!1)continue;const h=a.has(p.id),m=!h&&p.parentId&&i.find(v=>v.id===p.parentId);(h||m)&&i.push(p)}const l=new Set(t.map(p=>p.id)),c=r.filter(p=>p.deletable!==!1),d=dVn(i,c);for(const p of c)l.has(p.id)&&!d.find(m=>m.id===p.id)&&d.push(p);if(!s)return{edges:d,nodes:i};const f=await s({nodes:i,edges:d});return typeof f=="boolean"?f?{edges:d,nodes:i}:{edges:[],nodes:[]}:f}const OT=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),DO=(e={x:0,y:0},t,n)=>({x:OT(e.x,t[0][0],t[1][0]-(n?.width??0)),y:OT(e.y,t[0][1],t[1][1]-(n?.height??0))});function g0t(e,t,n){const{width:r,height:s}=Gx(n),{x:a,y:i}=n.internals.positionAbsolute;return DO(e,[[a,i],[a+r,i+s]],t)}const L9e=(e,t,n)=>e<t?OT(Math.abs(e-t),1,t)/t:e>n?-OT(Math.abs(e-n),1,t)/t:0,v0t=(e,t,n=15,r=40)=>{const s=L9e(e.x,r,t.width-r)*n,a=L9e(e.y,r,t.height-r)*n;return[s,a]},PV=(e,t)=>({x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x2,t.x2),y2:Math.max(e.y2,t.y2)}),Ihe=({x:e,y:t,width:n,height:r})=>({x:e,y:t,x2:e+n,y2:t+r}),$V=({x:e,y:t,x2:n,y2:r})=>({x:e,y:t,width:n-e,height:r-t}),_T=(e,t=[0,0])=>{const{x:n,y:r}=y1e(e)?e.internals.positionAbsolute:m3(e,t);return{x:n,y:r,width:e.measured?.width??e.width??e.initialWidth??0,height:e.measured?.height??e.height??e.initialHeight??0}},D7=(e,t=[0,0])=>{const{x:n,y:r}=y1e(e)?e.internals.positionAbsolute:m3(e,t);return{x:n,y:r,x2:n+(e.measured?.width??e.width??e.initialWidth??0),y2:r+(e.measured?.height??e.height??e.initialHeight??0)}},y0t=(e,t)=>$V(PV(Ihe(e),Ihe(t))),oM=(e,t)=>{const n=Math.max(0,Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x)),r=Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y));return Math.ceil(n*r)},F9e=e=>dg(e.width)&&dg(e.height)&&dg(e.x)&&dg(e.y),dg=e=>!isNaN(e)&&isFinite(e),mVn=(e,t)=>{},v3=(e,t=[1,1])=>({x:t[0]*Math.round(e.x/t[0]),y:t[1]*Math.round(e.y/t[1])}),y3=({x:e,y:t},[n,r,s],a=!1,i=[1,1])=>{const l={x:(e-n)/s,y:(t-r)/s};return a?v3(l,i):l},L7=({x:e,y:t},[n,r,s])=>({x:e*s+n,y:t*s+r});function UC(e,t){if(typeof e=="number")return Math.floor((t-t/(1+e))*.5);if(typeof e=="string"&&e.endsWith("px")){const n=parseFloat(e);if(!Number.isNaN(n))return Math.floor(n)}if(typeof e=="string"&&e.endsWith("%")){const n=parseFloat(e);if(!Number.isNaN(n))return Math.floor(t*n*.01)}return console.error(`[React Flow] The padding value "${e}" is invalid. Please provide a number or a string with a valid unit (px or %).`),0}function gVn(e,t,n){if(typeof e=="string"||typeof e=="number"){const r=UC(e,n),s=UC(e,t);return{top:r,right:s,bottom:r,left:s,x:s*2,y:r*2}}if(typeof e=="object"){const r=UC(e.top??e.y??0,n),s=UC(e.bottom??e.y??0,n),a=UC(e.left??e.x??0,t),i=UC(e.right??e.x??0,t);return{top:r,right:i,bottom:s,left:a,x:a+i,y:r+s}}return{top:0,right:0,bottom:0,left:0,x:0,y:0}}function vVn(e,t,n,r,s,a){const{x:i,y:l}=L7(e,[t,n,r]),{x:c,y:u}=L7({x:e.x+e.width,y:e.y+e.height},[t,n,r]),d=s-c,f=a-u;return{left:Math.floor(i),top:Math.floor(l),right:Math.floor(d),bottom:Math.floor(f)}}const x1e=(e,t,n,r,s,a)=>{const i=gVn(a,t,n),l=(t-i.x)/e.width,c=(n-i.y)/e.height,u=Math.min(l,c),d=OT(u,r,s),f=e.x+e.width/2,p=e.y+e.height/2,h=t/2-f*d,m=n/2-p*d,v=vVn(e,h,m,d,t,n),y={left:Math.min(v.left-i.left,0),top:Math.min(v.top-i.top,0),right:Math.min(v.right-i.right,0),bottom:Math.min(v.bottom-i.bottom,0)};return{x:h-y.left+y.right,y:m-y.top+y.bottom,zoom:d}},lM=()=>typeof navigator<"u"&&navigator?.userAgent?.indexOf("Mac")>=0;function CT(e){return e!=null&&e!=="parent"}function Gx(e){return{width:e.measured?.width??e.width??e.initialWidth??0,height:e.measured?.height??e.height??e.initialHeight??0}}function b0t(e){return(e.measured?.width??e.width??e.initialWidth)!==void 0&&(e.measured?.height??e.height??e.initialHeight)!==void 0}function x0t(e,t={width:0,height:0},n,r,s){const a={...e},i=r.get(n);if(i){const l=i.origin||s;a.x+=i.internals.positionAbsolute.x-(t.width??0)*l[0],a.y+=i.internals.positionAbsolute.y-(t.height??0)*l[1]}return a}function z9e(e,t){if(e.size!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;return!0}function yVn(){let e,t;return{promise:new Promise((r,s)=>{e=r,t=s}),resolve:e,reject:t}}function bVn(e){return{...d0t,...e||{}}}function V2(e,{snapGrid:t=[0,0],snapToGrid:n=!1,transform:r,containerBounds:s}){const{x:a,y:i}=fg(e),l=y3({x:a-(s?.left??0),y:i-(s?.top??0)},r),{x:c,y:u}=n?v3(l,t):l;return{xSnapped:c,ySnapped:u,...l}}const w1e=e=>({width:e.offsetWidth,height:e.offsetHeight}),w0t=e=>e?.getRootNode?.()||window?.document,xVn=["INPUT","SELECT","TEXTAREA"];function S0t(e){const t=e.composedPath?.()?.[0]||e.target;return t?.nodeType!==1?!1:xVn.includes(t.nodeName)||t.hasAttribute("contenteditable")||!!t.closest(".nokey")}const k0t=e=>"clientX"in e,fg=(e,t)=>{const n=k0t(e),r=n?e.clientX:e.touches?.[0].clientX,s=n?e.clientY:e.touches?.[0].clientY;return{x:r-(t?.left??0),y:s-(t?.top??0)}},B9e=(e,t,n,r,s)=>{const a=t.querySelectorAll(`.${e}`);return!a||!a.length?null:Array.from(a).map(i=>{const l=i.getBoundingClientRect();return{id:i.getAttribute("data-handleid"),type:e,nodeId:s,position:i.getAttribute("data-handlepos"),x:(l.left-n.left)/r,y:(l.top-n.top)/r,...w1e(i)}})};function O0t({sourceX:e,sourceY:t,targetX:n,targetY:r,sourceControlX:s,sourceControlY:a,targetControlX:i,targetControlY:l}){const c=e*.125+s*.375+i*.375+n*.125,u=t*.125+a*.375+l*.375+r*.125,d=Math.abs(c-e),f=Math.abs(u-t);return[c,u,d,f]}function T6(e,t){return e>=0?.5*e:t*25*Math.sqrt(-e)}function U9e({pos:e,x1:t,y1:n,x2:r,y2:s,c:a}){switch(e){case nr.Left:return[t-T6(t-r,a),n];case nr.Right:return[t+T6(r-t,a),n];case nr.Top:return[t,n-T6(n-s,a)];case nr.Bottom:return[t,n+T6(s-n,a)]}}function S1e({sourceX:e,sourceY:t,sourcePosition:n=nr.Bottom,targetX:r,targetY:s,targetPosition:a=nr.Top,curvature:i=.25}){const[l,c]=U9e({pos:n,x1:e,y1:t,x2:r,y2:s,c:i}),[u,d]=U9e({pos:a,x1:r,y1:s,x2:e,y2:t,c:i}),[f,p,h,m]=O0t({sourceX:e,sourceY:t,targetX:r,targetY:s,sourceControlX:l,sourceControlY:c,targetControlX:u,targetControlY:d});return[`M${e},${t} C${l},${c} ${u},${d} ${r},${s}`,f,p,h,m]}function _0t({sourceX:e,sourceY:t,targetX:n,targetY:r}){const s=Math.abs(n-e)/2,a=n<e?n+s:n-s,i=Math.abs(r-t)/2,l=r<t?r+i:r-i;return[a,l,s,i]}function wVn({sourceNode:e,targetNode:t,selected:n=!1,zIndex:r=0,elevateOnSelect:s=!1,zIndexMode:a="basic"}){if(a==="manual")return r;const i=s&&n?r+1e3:r,l=Math.max(e.parentId||s&&e.selected?e.internals.z:0,t.parentId||s&&t.selected?t.internals.z:0);return i+l}function SVn({sourceNode:e,targetNode:t,width:n,height:r,transform:s}){const a=PV(D7(e),D7(t));a.x===a.x2&&(a.x2+=1),a.y===a.y2&&(a.y2+=1);const i={x:-s[0]/s[2],y:-s[1]/s[2],width:n/s[2],height:r/s[2]};return oM(i,$V(a))>0}const kVn=({source:e,sourceHandle:t,target:n,targetHandle:r})=>`xy-edge__${e}${t||""}-${n}${r||""}`,OVn=(e,t)=>t.some(n=>n.source===e.source&&n.target===e.target&&(n.sourceHandle===e.sourceHandle||!n.sourceHandle&&!e.sourceHandle)&&(n.targetHandle===e.targetHandle||!n.targetHandle&&!e.targetHandle)),_Vn=(e,t,n={})=>{if(!e.source||!e.target)return t;const r=n.getEdgeId||kVn;let s;return h0t(e)?s={...e}:s={...e,id:r(e)},OVn(s,t)?t:(s.sourceHandle===null&&delete s.sourceHandle,s.targetHandle===null&&delete s.targetHandle,t.concat(s))};function C0t({sourceX:e,sourceY:t,targetX:n,targetY:r}){const[s,a,i,l]=_0t({sourceX:e,sourceY:t,targetX:n,targetY:r});return[`M ${e},${t}L ${n},${r}`,s,a,i,l]}const q9e={[nr.Left]:{x:-1,y:0},[nr.Right]:{x:1,y:0},[nr.Top]:{x:0,y:-1},[nr.Bottom]:{x:0,y:1}},CVn=({source:e,sourcePosition:t=nr.Bottom,target:n})=>t===nr.Left||t===nr.Right?e.x<n.x?{x:1,y:0}:{x:-1,y:0}:e.y<n.y?{x:0,y:1}:{x:0,y:-1},V9e=(e,t)=>Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2));function EVn({source:e,sourcePosition:t=nr.Bottom,target:n,targetPosition:r=nr.Top,center:s,offset:a,stepPosition:i}){const l=q9e[t],c=q9e[r],u={x:e.x+l.x*a,y:e.y+l.y*a},d={x:n.x+c.x*a,y:n.y+c.y*a},f=CVn({source:u,sourcePosition:t,target:d}),p=f.x!==0?"x":"y",h=f[p];let m=[],v,y;const b={x:0,y:0},S={x:0,y:0},[,,w,k]=_0t({sourceX:e.x,sourceY:e.y,targetX:n.x,targetY:n.y});if(l[p]*c[p]===-1){p==="x"?(v=s.x??u.x+(d.x-u.x)*i,y=s.y??(u.y+d.y)/2):(v=s.x??(u.x+d.x)/2,y=s.y??u.y+(d.y-u.y)*i);const j=[{x:v,y:u.y},{x:v,y:d.y}],N=[{x:u.x,y},{x:d.x,y}];l[p]===h?m=p==="x"?j:N:m=p==="x"?N:j}else{const j=[{x:u.x,y:d.y}],N=[{x:d.x,y:u.y}];if(p==="x"?m=l.x===h?N:j:m=l.y===h?j:N,t===r){const M=Math.abs(e[p]-n[p]);if(M<=a){const q=Math.min(a-1,a-M);l[p]===h?b[p]=(u[p]>e[p]?-1:1)*q:S[p]=(d[p]>n[p]?-1:1)*q}}if(t!==r){const M=p==="x"?"y":"x",q=l[p]===c[M],H=u[M]>d[M],F=u[M]<d[M];(l[p]===1&&(!q&&H||q&&F)||l[p]!==1&&(!q&&F||q&&H))&&(m=p==="x"?j:N)}const I={x:u.x+b.x,y:u.y+b.y},R={x:d.x+S.x,y:d.y+S.y},P=Math.max(Math.abs(I.x-m[0].x),Math.abs(R.x-m[0].x)),L=Math.max(Math.abs(I.y-m[0].y),Math.abs(R.y-m[0].y));P>=L?(v=(I.x+R.x)/2,y=m[0].y):(v=m[0].x,y=(I.y+R.y)/2)}const _={x:u.x+b.x,y:u.y+b.y},C={x:d.x+S.x,y:d.y+S.y};return[[e,..._.x!==m[0].x||_.y!==m[0].y?[_]:[],...m,...C.x!==m[m.length-1].x||C.y!==m[m.length-1].y?[C]:[],n],v,y,w,k]}function jVn(e,t,n,r){const s=Math.min(V9e(e,t)/2,V9e(t,n)/2,r),{x:a,y:i}=t;if(e.x===a&&a===n.x||e.y===i&&i===n.y)return`L${a} ${i}`;if(e.y===i){const u=e.x<n.x?-1:1,d=e.y<n.y?1:-1;return`L ${a+s*u},${i}Q ${a},${i} ${a},${i+s*d}`}const l=e.x<n.x?1:-1,c=e.y<n.y?-1:1;return`L ${a},${i+s*c}Q ${a},${i} ${a+s*l},${i}`}function Ahe({sourceX:e,sourceY:t,sourcePosition:n=nr.Bottom,targetX:r,targetY:s,targetPosition:a=nr.Top,borderRadius:i=5,centerX:l,centerY:c,offset:u=20,stepPosition:d=.5}){const[f,p,h,m,v]=EVn({source:{x:e,y:t},sourcePosition:n,target:{x:r,y:s},targetPosition:a,center:{x:l,y:c},offset:u,stepPosition:d});let y=`M${f[0].x} ${f[0].y}`;for(let b=1;b<f.length-1;b++)y+=jVn(f[b-1],f[b],f[b+1],i);return y+=`L${f[f.length-1].x} ${f[f.length-1].y}`,[y,p,h,m,v]}function H9e(e){return e&&!!(e.internals.handleBounds||e.handles?.length)&&!!(e.measured.width||e.width||e.initialWidth)}function TVn(e){const{sourceNode:t,targetNode:n}=e;if(!H9e(t)||!H9e(n))return null;const r=t.internals.handleBounds||W9e(t.handles),s=n.internals.handleBounds||W9e(n.handles),a=Z9e(r?.source??[],e.sourceHandle),i=Z9e(e.connectionMode===kT.Strict?s?.target??[]:(s?.target??[]).concat(s?.source??[]),e.targetHandle);if(!a||!i)return e.onError?.("008",hy.error008(a?"target":"source",{id:e.id,sourceHandle:e.sourceHandle,targetHandle:e.targetHandle})),null;const l=a?.position||nr.Bottom,c=i?.position||nr.Top,u=LO(t,a,l),d=LO(n,i,c);return{sourceX:u.x,sourceY:u.y,targetX:d.x,targetY:d.y,sourcePosition:l,targetPosition:c}}function W9e(e){if(!e)return null;const t=[],n=[];for(const r of e)r.width=r.width??1,r.height=r.height??1,r.type==="source"?t.push(r):r.type==="target"&&n.push(r);return{source:t,target:n}}function LO(e,t,n=nr.Left,r=!1){const s=(t?.x??0)+e.internals.positionAbsolute.x,a=(t?.y??0)+e.internals.positionAbsolute.y,{width:i,height:l}=t??Gx(e);if(r)return{x:s+i/2,y:a+l/2};switch(t?.position??n){case nr.Top:return{x:s+i/2,y:a};case nr.Right:return{x:s+i,y:a+l/2};case nr.Bottom:return{x:s+i/2,y:a+l};case nr.Left:return{x:s,y:a+l/2}}}function Z9e(e,t){return e&&(t?e.find(n=>n.id===t):e[0])||null}function Rhe(e,t){return e?typeof e=="string"?e:`${t?`${t}__`:""}${Object.keys(e).sort().map(r=>`${r}=${e[r]}`).join("&")}`:""}function NVn(e,{id:t,defaultColor:n,defaultMarkerStart:r,defaultMarkerEnd:s}){const a=new Set;return e.reduce((i,l)=>([l.markerStart||r,l.markerEnd||s].forEach(c=>{if(c&&typeof c=="object"){const u=Rhe(c,t);a.has(u)||(i.push({id:u,color:c.color||n,...c}),a.add(u))}}),i),[]).sort((i,l)=>i.id.localeCompare(l.id))}const E0t=1e3,IVn=10,k1e={nodeOrigin:[0,0],nodeExtent:sM,elevateNodesOnSelect:!0,zIndexMode:"basic",defaults:{}},AVn={...k1e,checkEquality:!0};function O1e(e,t){const n={...e};for(const r in t)t[r]!==void 0&&(n[r]=t[r]);return n}function RVn(e,t,n){const r=O1e(k1e,n);for(const s of e.values())if(s.parentId)C1e(s,e,t,r);else{const a=m3(s,r.nodeOrigin),i=CT(s.extent)?s.extent:r.nodeExtent,l=DO(a,i,Gx(s));s.internals.positionAbsolute=l}}function PVn(e,t){if(!e.handles)return e.measured?t?.internals.handleBounds:void 0;const n=[],r=[];for(const s of e.handles){const a={id:s.id,width:s.width??1,height:s.height??1,nodeId:e.id,x:s.x,y:s.y,position:s.position,type:s.type};s.type==="source"?n.push(a):s.type==="target"&&r.push(a)}return{source:n,target:r}}function _1e(e){return e==="manual"}function Phe(e,t,n,r={}){const s=O1e(AVn,r),a={i:0},i=new Map(t),l=s?.elevateNodesOnSelect&&!_1e(s.zIndexMode)?E0t:0;let c=e.length>0,u=!1;t.clear(),n.clear();for(const d of e){let f=i.get(d.id);if(s.checkEquality&&d===f?.internals.userNode)t.set(d.id,f);else{const p=m3(d,s.nodeOrigin),h=CT(d.extent)?d.extent:s.nodeExtent,m=DO(p,h,Gx(d));f={...s.defaults,...d,measured:{width:d.measured?.width,height:d.measured?.height},internals:{positionAbsolute:m,handleBounds:PVn(d,f),z:j0t(d,l,s.zIndexMode),userNode:d}},t.set(d.id,f)}(f.measured===void 0||f.measured.width===void 0||f.measured.height===void 0)&&!f.hidden&&(c=!1),d.parentId&&C1e(f,t,n,r,a),u||=d.selected??!1}return{nodesInitialized:c,hasSelectedNodes:u}}function $Vn(e,t){if(!e.parentId)return;const n=t.get(e.parentId);n?n.set(e.id,e):t.set(e.parentId,new Map([[e.id,e]]))}function C1e(e,t,n,r,s){const{elevateNodesOnSelect:a,nodeOrigin:i,nodeExtent:l,zIndexMode:c}=O1e(k1e,r),u=e.parentId,d=t.get(u);if(!d){console.warn(`Parent node ${u} not found. Please make sure that parent nodes are in front of their child nodes in the nodes array.`);return}$Vn(e,n),s&&!d.parentId&&d.internals.rootParentIndex===void 0&&c==="auto"&&(d.internals.rootParentIndex=++s.i,d.internals.z=d.internals.z+s.i*IVn),s&&d.internals.rootParentIndex!==void 0&&(s.i=d.internals.rootParentIndex);const f=a&&!_1e(c)?E0t:0,{x:p,y:h,z:m}=MVn(e,d,i,l,f,c),{positionAbsolute:v}=e.internals,y=p!==v.x||h!==v.y;(y||m!==e.internals.z)&&t.set(e.id,{...e,internals:{...e.internals,positionAbsolute:y?{x:p,y:h}:v,z:m}})}function j0t(e,t,n){const r=dg(e.zIndex)?e.zIndex:0;return _1e(n)?r:r+(e.selected?t:0)}function MVn(e,t,n,r,s,a){const{x:i,y:l}=t.internals.positionAbsolute,c=Gx(e),u=m3(e,n),d=CT(e.extent)?DO(u,e.extent,c):u;let f=DO({x:i+d.x,y:l+d.y},r,c);e.extent==="parent"&&(f=g0t(f,c,t));const p=j0t(e,s,a),h=t.internals.z??0;return{x:f.x,y:f.y,z:h>=p?h+1:p}}function E1e(e,t,n,r=[0,0]){const s=[],a=new Map;for(const i of e){const l=t.get(i.parentId);if(!l)continue;const c=a.get(i.parentId)?.expandedRect??_T(l),u=y0t(c,i.rect);a.set(i.parentId,{expandedRect:u,parent:l})}return a.size>0&&a.forEach(({expandedRect:i,parent:l},c)=>{const u=l.internals.positionAbsolute,d=Gx(l),f=l.origin??r,p=i.x<u.x?Math.round(Math.abs(u.x-i.x)):0,h=i.y<u.y?Math.round(Math.abs(u.y-i.y)):0,m=Math.max(d.width,Math.round(i.width)),v=Math.max(d.height,Math.round(i.height)),y=(m-d.width)*f[0],b=(v-d.height)*f[1];(p>0||h>0||y||b)&&(s.push({id:c,type:"position",position:{x:l.position.x-p+y,y:l.position.y-h+b}}),n.get(c)?.forEach(S=>{e.some(w=>w.id===S.id)||s.push({id:S.id,type:"position",position:{x:S.position.x+p,y:S.position.y+h}})})),(d.width<i.width||d.height<i.height||p||h)&&s.push({id:c,type:"dimensions",setAttributes:!0,dimensions:{width:m+(p?f[0]*p-y:0),height:v+(h?f[1]*h-b:0)}})}),s}function DVn(e,t,n,r,s,a,i){const l=r?.querySelector(".xyflow__viewport");let c=!1;if(!l)return{changes:[],updatedInternals:c};const u=[],d=window.getComputedStyle(l),{m22:f}=new window.DOMMatrixReadOnly(d.transform),p=[];for(const h of e.values()){const m=t.get(h.id);if(!m)continue;if(m.hidden){t.set(m.id,{...m,internals:{...m.internals,handleBounds:void 0}}),c=!0;continue}const v=w1e(h.nodeElement),y=m.measured.width!==v.width||m.measured.height!==v.height;if(!!(v.width&&v.height&&(y||!m.internals.handleBounds||h.force))){const S=h.nodeElement.getBoundingClientRect(),w=CT(m.extent)?m.extent:a;let{positionAbsolute:k}=m.internals;m.parentId&&m.extent==="parent"?k=g0t(k,v,t.get(m.parentId)):w&&(k=DO(k,w,v));const _={...m,measured:v,internals:{...m.internals,positionAbsolute:k,handleBounds:{source:B9e("source",h.nodeElement,S,f,m.id),target:B9e("target",h.nodeElement,S,f,m.id)}}};t.set(m.id,_),m.parentId&&C1e(_,t,n,{nodeOrigin:s,zIndexMode:i}),c=!0,y&&(u.push({id:m.id,type:"dimensions",dimensions:v}),m.expandParent&&m.parentId&&p.push({id:m.id,parentId:m.parentId,rect:_T(_,s)}))}}if(p.length>0){const h=E1e(p,t,n,s);u.push(...h)}return{changes:u,updatedInternals:c}}async function LVn({delta:e,panZoom:t,transform:n,translateExtent:r,width:s,height:a}){if(!t||!e.x&&!e.y)return Promise.resolve(!1);const i=await t.setViewportConstrained({x:n[0]+e.x,y:n[1]+e.y,zoom:n[2]},[[0,0],[s,a]],r),l=!!i&&(i.x!==n[0]||i.y!==n[1]||i.k!==n[2]);return Promise.resolve(l)}function G9e(e,t,n,r,s,a){let i=s;const l=r.get(i)||new Map;r.set(i,l.set(n,t)),i=`${s}-${e}`;const c=r.get(i)||new Map;if(r.set(i,c.set(n,t)),a){i=`${s}-${e}-${a}`;const u=r.get(i)||new Map;r.set(i,u.set(n,t))}}function T0t(e,t,n){e.clear(),t.clear();for(const r of n){const{source:s,target:a,sourceHandle:i=null,targetHandle:l=null}=r,c={edgeId:r.id,source:s,target:a,sourceHandle:i,targetHandle:l},u=`${s}-${i}--${a}-${l}`,d=`${a}-${l}--${s}-${i}`;G9e("source",c,d,e,s,i),G9e("target",c,u,e,a,l),t.set(r.id,r)}}function N0t(e,t){if(!e.parentId)return!1;const n=t.get(e.parentId);return n?n.selected?!0:N0t(n,t):!1}function Q9e(e,t,n){let r=e;do{if(r?.matches?.(t))return!0;if(r===n)return!1;r=r?.parentElement}while(r);return!1}function FVn(e,t,n,r){const s=new Map;for(const[a,i]of e)if((i.selected||i.id===r)&&(!i.parentId||!N0t(i,e))&&(i.draggable||t&&typeof i.draggable>"u")){const l=e.get(a);l&&s.set(a,{id:a,position:l.position||{x:0,y:0},distance:{x:n.x-l.internals.positionAbsolute.x,y:n.y-l.internals.positionAbsolute.y},extent:l.extent,parentId:l.parentId,origin:l.origin,expandParent:l.expandParent,internals:{positionAbsolute:l.internals.positionAbsolute||{x:0,y:0}},measured:{width:l.measured.width??0,height:l.measured.height??0}})}return s}function GJ({nodeId:e,dragItems:t,nodeLookup:n,dragging:r=!0}){const s=[];for(const[i,l]of t){const c=n.get(i)?.internals.userNode;c&&s.push({...c,position:l.position,dragging:r})}if(!e)return[s[0],s];const a=n.get(e)?.internals.userNode;return[a?{...a,position:t.get(e)?.position||a.position,dragging:r}:s[0],s]}function zVn({dragItems:e,snapGrid:t,x:n,y:r}){const s=e.values().next().value;if(!s)return null;const a={x:n-s.distance.x,y:r-s.distance.y},i=v3(a,t);return{x:i.x-a.x,y:i.y-a.y}}function BVn({onNodeMouseDown:e,getStoreItems:t,onDragStart:n,onDrag:r,onDragStop:s}){let a={x:null,y:null},i=0,l=new Map,c=!1,u={x:0,y:0},d=null,f=!1,p=null,h=!1,m=!1,v=null;function y({noDragClassName:S,handleSelector:w,domNode:k,isSelectable:_,nodeId:C,nodeClickDistance:E=0}){p=gp(k);function j({x:P,y:L}){const{nodeLookup:M,nodeExtent:q,snapGrid:H,snapToGrid:F,nodeOrigin:z,onNodeDrag:B,onSelectionDrag:D,onError:Q,updateNodePositions:V}=t();a={x:P,y:L};let $=!1;const U=l.size>1,Z=U&&q?Ihe(g3(l)):null,X=U&&F?zVn({dragItems:l,snapGrid:H,x:P,y:L}):null;for(const[te,J]of l){if(!M.has(te))continue;let ee={x:P-J.distance.x,y:L-J.distance.y};F&&(ee=X?{x:Math.round(ee.x+X.x),y:Math.round(ee.y+X.y)}:v3(ee,H));let ae=null;if(U&&q&&!J.extent&&Z){const{positionAbsolute:ne}=J.internals,ue=ne.x-Z.x+q[0][0],pe=ne.x+J.measured.width-Z.x2+q[1][0],le=ne.y-Z.y+q[0][1],ve=ne.y+J.measured.height-Z.y2+q[1][1];ae=[[ue,le],[pe,ve]]}const{position:ce,positionAbsolute:Y}=m0t({nodeId:te,nextPosition:ee,nodeLookup:M,nodeExtent:ae||q,nodeOrigin:z,onError:Q});$=$||J.position.x!==ce.x||J.position.y!==ce.y,J.position=ce,J.internals.positionAbsolute=Y}if(m=m||$,!!$&&(V(l,!0),v&&(r||B||!C&&D))){const[te,J]=GJ({nodeId:C,dragItems:l,nodeLookup:M});r?.(v,l,te,J),B?.(v,te,J),C||D?.(v,J)}}async function N(){if(!d)return;const{transform:P,panBy:L,autoPanSpeed:M,autoPanOnNodeDrag:q}=t();if(!q){c=!1,cancelAnimationFrame(i);return}const[H,F]=v0t(u,d,M);(H!==0||F!==0)&&(a.x=(a.x??0)-H/P[2],a.y=(a.y??0)-F/P[2],await L({x:H,y:F})&&j(a)),i=requestAnimationFrame(N)}function I(P){const{nodeLookup:L,multiSelectionActive:M,nodesDraggable:q,transform:H,snapGrid:F,snapToGrid:z,selectNodesOnDrag:B,onNodeDragStart:D,onSelectionDragStart:Q,unselectNodesAndEdges:V}=t();f=!0,(!B||!_)&&!M&&C&&(L.get(C)?.selected||V()),_&&B&&C&&e?.(C);const $=V2(P.sourceEvent,{transform:H,snapGrid:F,snapToGrid:z,containerBounds:d});if(a=$,l=FVn(L,q,$,C),l.size>0&&(n||D||!C&&Q)){const[U,Z]=GJ({nodeId:C,dragItems:l,nodeLookup:L});n?.(P.sourceEvent,l,U,Z),D?.(P.sourceEvent,U,Z),C||Q?.(P.sourceEvent,Z)}}const R=Gxt().clickDistance(E).on("start",P=>{const{domNode:L,nodeDragThreshold:M,transform:q,snapGrid:H,snapToGrid:F}=t();d=L?.getBoundingClientRect()||null,h=!1,m=!1,v=P.sourceEvent,M===0&&I(P),a=V2(P.sourceEvent,{transform:q,snapGrid:H,snapToGrid:F,containerBounds:d}),u=fg(P.sourceEvent,d)}).on("drag",P=>{const{autoPanOnNodeDrag:L,transform:M,snapGrid:q,snapToGrid:H,nodeDragThreshold:F,nodeLookup:z}=t(),B=V2(P.sourceEvent,{transform:M,snapGrid:q,snapToGrid:H,containerBounds:d});if(v=P.sourceEvent,(P.sourceEvent.type==="touchmove"&&P.sourceEvent.touches.length>1||C&&!z.has(C))&&(h=!0),!h){if(!c&&L&&f&&(c=!0,N()),!f){const D=fg(P.sourceEvent,d),Q=D.x-u.x,V=D.y-u.y;Math.sqrt(Q*Q+V*V)>F&&I(P)}(a.x!==B.xSnapped||a.y!==B.ySnapped)&&l&&f&&(u=fg(P.sourceEvent,d),j(B))}}).on("end",P=>{if(!(!f||h)&&(c=!1,f=!1,cancelAnimationFrame(i),l.size>0)){const{nodeLookup:L,updateNodePositions:M,onNodeDragStop:q,onSelectionDragStop:H}=t();if(m&&(M(l,!1),m=!1),s||q||!C&&H){const[F,z]=GJ({nodeId:C,dragItems:l,nodeLookup:L,dragging:!1});s?.(P.sourceEvent,l,F,z),q?.(P.sourceEvent,F,z),C||H?.(P.sourceEvent,z)}}}).filter(P=>{const L=P.target;return!P.button&&(!S||!Q9e(L,`.${S}`,k))&&(!w||Q9e(L,w,k))});p.call(R)}function b(){p?.on(".drag",null)}return{update:y,destroy:b}}function UVn(e,t,n){const r=[],s={x:e.x-n,y:e.y-n,width:n*2,height:n*2};for(const a of t.values())oM(s,_T(a))>0&&r.push(a);return r}const qVn=250;function VVn(e,t,n,r){let s=[],a=1/0;const i=UVn(e,n,t+qVn);for(const l of i){const c=[...l.internals.handleBounds?.source??[],...l.internals.handleBounds?.target??[]];for(const u of c){if(r.nodeId===u.nodeId&&r.type===u.type&&r.id===u.id)continue;const{x:d,y:f}=LO(l,u,u.position,!0),p=Math.sqrt(Math.pow(d-e.x,2)+Math.pow(f-e.y,2));p>t||(p<a?(s=[{...u,x:d,y:f}],a=p):p===a&&s.push({...u,x:d,y:f}))}}if(!s.length)return null;if(s.length>1){const l=r.type==="source"?"target":"source";return s.find(c=>c.type===l)??s[0]}return s[0]}function I0t(e,t,n,r,s,a=!1){const i=r.get(e);if(!i)return null;const l=s==="strict"?i.internals.handleBounds?.[t]:[...i.internals.handleBounds?.source??[],...i.internals.handleBounds?.target??[]],c=(n?l?.find(u=>u.id===n):l?.[0])??null;return c&&a?{...c,...LO(i,c,c.position,!0)}:c}function A0t(e,t){return e||(t?.classList.contains("target")?"target":t?.classList.contains("source")?"source":null)}function HVn(e,t){let n=null;return t?n=!0:e&&!t&&(n=!1),n}const R0t=()=>!0;function WVn(e,{connectionMode:t,connectionRadius:n,handleId:r,nodeId:s,edgeUpdaterType:a,isTarget:i,domNode:l,nodeLookup:c,lib:u,autoPanOnConnect:d,flowId:f,panBy:p,cancelConnection:h,onConnectStart:m,onConnect:v,onConnectEnd:y,isValidConnection:b=R0t,onReconnectEnd:S,updateConnection:w,getTransform:k,getFromHandle:_,autoPanSpeed:C,dragThreshold:E=1,handleDomNode:j}){const N=w0t(e.target);let I=0,R;const{x:P,y:L}=fg(e),M=A0t(a,j),q=l?.getBoundingClientRect();let H=!1;if(!q||!M)return;const F=I0t(s,M,r,c,t);if(!F)return;let z=fg(e,q),B=!1,D=null,Q=!1,V=null;function $(){if(!d||!q)return;const[ce,Y]=v0t(z,q,C);p({x:ce,y:Y}),I=requestAnimationFrame($)}const U={...F,nodeId:s,type:M,position:F.position},Z=c.get(s);let te={inProgress:!0,isValid:null,from:LO(Z,U,nr.Left,!0),fromHandle:U,fromPosition:U.position,fromNode:Z,to:z,toHandle:null,toPosition:D9e[U.position],toNode:null,pointer:z};function J(){H=!0,w(te),m?.(e,{nodeId:s,handleId:r,handleType:M})}E===0&&J();function ee(ce){if(!H){const{x:ve,y:ye}=fg(ce),Se=ve-P,Ne=ye-L;if(!(Se*Se+Ne*Ne>E*E))return;J()}if(!_()||!U){ae(ce);return}const Y=k();z=fg(ce,q),R=VVn(y3(z,Y,!1,[1,1]),n,c,U),B||($(),B=!0);const ne=P0t(ce,{handle:R,connectionMode:t,fromNodeId:s,fromHandleId:r,fromType:i?"target":"source",isValidConnection:b,doc:N,lib:u,flowId:f,nodeLookup:c});V=ne.handleDomNode,D=ne.connection,Q=HVn(!!R,ne.isValid);const ue=c.get(s),pe=ue?LO(ue,U,nr.Left,!0):te.from,le={...te,from:pe,isValid:Q,to:ne.toHandle&&Q?L7({x:ne.toHandle.x,y:ne.toHandle.y},Y):z,toHandle:ne.toHandle,toPosition:Q&&ne.toHandle?ne.toHandle.position:D9e[U.position],toNode:ne.toHandle?c.get(ne.toHandle.nodeId):null,pointer:z};w(le),te=le}function ae(ce){if(!("touches"in ce&&ce.touches.length>0)){if(H){(R||V)&&D&&Q&&v?.(D);const{inProgress:Y,...ne}=te,ue={...ne,toPosition:te.toHandle?te.toPosition:null};y?.(ce,ue),a&&S?.(ce,ue)}h(),cancelAnimationFrame(I),B=!1,Q=!1,D=null,V=null,N.removeEventListener("mousemove",ee),N.removeEventListener("mouseup",ae),N.removeEventListener("touchmove",ee),N.removeEventListener("touchend",ae)}}N.addEventListener("mousemove",ee),N.addEventListener("mouseup",ae),N.addEventListener("touchmove",ee),N.addEventListener("touchend",ae)}function P0t(e,{handle:t,connectionMode:n,fromNodeId:r,fromHandleId:s,fromType:a,doc:i,lib:l,flowId:c,isValidConnection:u=R0t,nodeLookup:d}){const f=a==="target",p=t?i.querySelector(`.${l}-flow__handle[data-id="${c}-${t?.nodeId}-${t?.id}-${t?.type}"]`):null,{x:h,y:m}=fg(e),v=i.elementFromPoint(h,m),y=v?.classList.contains(`${l}-flow__handle`)?v:p,b={handleDomNode:y,isValid:!1,connection:null,toHandle:null};if(y){const S=A0t(void 0,y),w=y.getAttribute("data-nodeid"),k=y.getAttribute("data-handleid"),_=y.classList.contains("connectable"),C=y.classList.contains("connectableend");if(!w||!S)return b;const E={source:f?w:r,sourceHandle:f?k:s,target:f?r:w,targetHandle:f?s:k};b.connection=E;const N=_&&C&&(n===kT.Strict?f&&S==="source"||!f&&S==="target":w!==r||k!==s);b.isValid=N&&u(E),b.toHandle=I0t(w,S,k,d,n,!0)}return b}const $he={onPointerDown:WVn,isValid:P0t};function ZVn({domNode:e,panZoom:t,getTransform:n,getViewScale:r}){const s=gp(e);function a({translateExtent:l,width:c,height:u,zoomStep:d=1,pannable:f=!0,zoomable:p=!0,inversePan:h=!1}){const m=w=>{if(w.sourceEvent.type!=="wheel"||!t)return;const k=n(),_=w.sourceEvent.ctrlKey&&lM()?10:1,C=-w.sourceEvent.deltaY*(w.sourceEvent.deltaMode===1?.05:w.sourceEvent.deltaMode?1:.002)*d,E=k[2]*Math.pow(2,C*_);t.scaleTo(E)};let v=[0,0];const y=w=>{(w.sourceEvent.type==="mousedown"||w.sourceEvent.type==="touchstart")&&(v=[w.sourceEvent.clientX??w.sourceEvent.touches[0].clientX,w.sourceEvent.clientY??w.sourceEvent.touches[0].clientY])},b=w=>{const k=n();if(w.sourceEvent.type!=="mousemove"&&w.sourceEvent.type!=="touchmove"||!t)return;const _=[w.sourceEvent.clientX??w.sourceEvent.touches[0].clientX,w.sourceEvent.clientY??w.sourceEvent.touches[0].clientY],C=[_[0]-v[0],_[1]-v[1]];v=_;const E=r()*Math.max(k[2],Math.log(k[2]))*(h?-1:1),j={x:k[0]-C[0]*E,y:k[1]-C[1]*E},N=[[0,0],[c,u]];t.setViewportConstrained({x:j.x,y:j.y,zoom:k[2]},N,l)},S=c0t().on("start",y).on("zoom",f?b:null).on("zoom.wheel",p?m:null);s.call(S,{})}function i(){s.on("zoom",null)}return{update:a,destroy:i,pointer:Jm}}const MV=e=>({x:e.x,y:e.y,zoom:e.k}),QJ=({x:e,y:t,zoom:n})=>RV.translate(e,t).scale(n),HE=(e,t)=>e.target.closest(`.${t}`),$0t=(e,t)=>t===2&&Array.isArray(e)&&e.includes(2),GVn=e=>((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2,YJ=(e,t=0,n=GVn,r=()=>{})=>{const s=typeof t=="number"&&t>0;return s||r(),s?e.transition().duration(t).ease(n).on("end",r):e},M0t=e=>{const t=e.ctrlKey&&lM()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*t};function QVn({zoomPanValues:e,noWheelClassName:t,d3Selection:n,d3Zoom:r,panOnScrollMode:s,panOnScrollSpeed:a,zoomOnPinch:i,onPanZoomStart:l,onPanZoom:c,onPanZoomEnd:u}){return d=>{if(HE(d,t))return d.ctrlKey&&d.preventDefault(),!1;d.preventDefault(),d.stopImmediatePropagation();const f=n.property("__zoom").k||1;if(d.ctrlKey&&i){const y=Jm(d),b=M0t(d),S=f*Math.pow(2,b);r.scaleTo(n,S,y,d);return}const p=d.deltaMode===1?20:1;let h=s===Zk.Vertical?0:d.deltaX*p,m=s===Zk.Horizontal?0:d.deltaY*p;!lM()&&d.shiftKey&&s!==Zk.Vertical&&(h=d.deltaY*p,m=0),r.translateBy(n,-(h/f)*a,-(m/f)*a,{internal:!0});const v=MV(n.property("__zoom"));clearTimeout(e.panScrollTimeout),e.isPanScrolling?(c?.(d,v),e.panScrollTimeout=setTimeout(()=>{u?.(d,v),e.isPanScrolling=!1},150)):(e.isPanScrolling=!0,l?.(d,v))}}function YVn({noWheelClassName:e,preventScrolling:t,d3ZoomHandler:n}){return function(r,s){const a=r.type==="wheel",i=!t&&a&&!r.ctrlKey,l=HE(r,e);if(r.ctrlKey&&a&&l&&r.preventDefault(),i||l)return null;r.preventDefault(),n.call(this,r,s)}}function XVn({zoomPanValues:e,onDraggingChange:t,onPanZoomStart:n}){return r=>{if(r.sourceEvent?.internal)return;const s=MV(r.transform);e.mouseButton=r.sourceEvent?.button||0,e.isZoomingOrPanning=!0,e.prevViewport=s,r.sourceEvent?.type==="mousedown"&&t(!0),n&&n?.(r.sourceEvent,s)}}function KVn({zoomPanValues:e,panOnDrag:t,onPaneContextMenu:n,onTransformChange:r,onPanZoom:s}){return a=>{e.usedRightMouseButton=!!(n&&$0t(t,e.mouseButton??0)),a.sourceEvent?.sync||r([a.transform.x,a.transform.y,a.transform.k]),s&&!a.sourceEvent?.internal&&s?.(a.sourceEvent,MV(a.transform))}}function JVn({zoomPanValues:e,panOnDrag:t,panOnScroll:n,onDraggingChange:r,onPanZoomEnd:s,onPaneContextMenu:a}){return i=>{if(!i.sourceEvent?.internal&&(e.isZoomingOrPanning=!1,a&&$0t(t,e.mouseButton??0)&&!e.usedRightMouseButton&&i.sourceEvent&&a(i.sourceEvent),e.usedRightMouseButton=!1,r(!1),s)){const l=MV(i.transform);e.prevViewport=l,clearTimeout(e.timerId),e.timerId=setTimeout(()=>{s?.(i.sourceEvent,l)},n?150:0)}}}function eHn({zoomActivationKeyPressed:e,zoomOnScroll:t,zoomOnPinch:n,panOnDrag:r,panOnScroll:s,zoomOnDoubleClick:a,userSelectionActive:i,noWheelClassName:l,noPanClassName:c,lib:u,connectionInProgress:d}){return f=>{const p=e||t,h=n&&f.ctrlKey,m=f.type==="wheel";if(f.button===1&&f.type==="mousedown"&&(HE(f,`${u}-flow__node`)||HE(f,`${u}-flow__edge`)))return!0;if(!r&&!p&&!s&&!a&&!n||i||d&&!m||HE(f,l)&&m||HE(f,c)&&(!m||s&&m&&!e)||!n&&f.ctrlKey&&m)return!1;if(!n&&f.type==="touchstart"&&f.touches?.length>1)return f.preventDefault(),!1;if(!p&&!s&&!h&&m||!r&&(f.type==="mousedown"||f.type==="touchstart")||Array.isArray(r)&&!r.includes(f.button)&&f.type==="mousedown")return!1;const v=Array.isArray(r)&&r.includes(f.button)||!f.button||f.button<=1;return(!f.ctrlKey||m)&&v}}function tHn({domNode:e,minZoom:t,maxZoom:n,translateExtent:r,viewport:s,onPanZoom:a,onPanZoomStart:i,onPanZoomEnd:l,onDraggingChange:c}){const u={isZoomingOrPanning:!1,usedRightMouseButton:!1,prevViewport:{},mouseButton:0,timerId:void 0,panScrollTimeout:void 0,isPanScrolling:!1},d=e.getBoundingClientRect(),f=c0t().scaleExtent([t,n]).translateExtent(r),p=gp(e).call(f);S({x:s.x,y:s.y,zoom:OT(s.zoom,t,n)},[[0,0],[d.width,d.height]],r);const h=p.on("wheel.zoom"),m=p.on("dblclick.zoom");f.wheelDelta(M0t);function v(R,P){return p?new Promise(L=>{f?.interpolate(P?.interpolate==="linear"?ix:JF).transform(YJ(p,P?.duration,P?.ease,()=>L(!0)),R)}):Promise.resolve(!1)}function y({noWheelClassName:R,noPanClassName:P,onPaneContextMenu:L,userSelectionActive:M,panOnScroll:q,panOnDrag:H,panOnScrollMode:F,panOnScrollSpeed:z,preventScrolling:B,zoomOnPinch:D,zoomOnScroll:Q,zoomOnDoubleClick:V,zoomActivationKeyPressed:$,lib:U,onTransformChange:Z,connectionInProgress:X,paneClickDistance:te,selectionOnDrag:J}){M&&!u.isZoomingOrPanning&&b();const ee=q&&!$&&!M;f.clickDistance(J?1/0:!dg(te)||te<0?0:te);const ae=ee?QVn({zoomPanValues:u,noWheelClassName:R,d3Selection:p,d3Zoom:f,panOnScrollMode:F,panOnScrollSpeed:z,zoomOnPinch:D,onPanZoomStart:i,onPanZoom:a,onPanZoomEnd:l}):YVn({noWheelClassName:R,preventScrolling:B,d3ZoomHandler:h});if(p.on("wheel.zoom",ae,{passive:!1}),!M){const Y=XVn({zoomPanValues:u,onDraggingChange:c,onPanZoomStart:i});f.on("start",Y);const ne=KVn({zoomPanValues:u,panOnDrag:H,onPaneContextMenu:!!L,onPanZoom:a,onTransformChange:Z});f.on("zoom",ne);const ue=JVn({zoomPanValues:u,panOnDrag:H,panOnScroll:q,onPaneContextMenu:L,onPanZoomEnd:l,onDraggingChange:c});f.on("end",ue)}const ce=eHn({zoomActivationKeyPressed:$,panOnDrag:H,zoomOnScroll:Q,panOnScroll:q,zoomOnDoubleClick:V,zoomOnPinch:D,userSelectionActive:M,noPanClassName:P,noWheelClassName:R,lib:U,connectionInProgress:X});f.filter(ce),V?p.on("dblclick.zoom",m):p.on("dblclick.zoom",null)}function b(){f.on("zoom",null)}async function S(R,P,L){const M=QJ(R),q=f?.constrain()(M,P,L);return q&&await v(q),new Promise(H=>H(q))}async function w(R,P){const L=QJ(R);return await v(L,P),new Promise(M=>M(L))}function k(R){if(p){const P=QJ(R),L=p.property("__zoom");(L.k!==R.zoom||L.x!==R.x||L.y!==R.y)&&f?.transform(p,P,null,{sync:!0})}}function _(){const R=p?l0t(p.node()):{x:0,y:0,k:1};return{x:R.x,y:R.y,zoom:R.k}}function C(R,P){return p?new Promise(L=>{f?.interpolate(P?.interpolate==="linear"?ix:JF).scaleTo(YJ(p,P?.duration,P?.ease,()=>L(!0)),R)}):Promise.resolve(!1)}function E(R,P){return p?new Promise(L=>{f?.interpolate(P?.interpolate==="linear"?ix:JF).scaleBy(YJ(p,P?.duration,P?.ease,()=>L(!0)),R)}):Promise.resolve(!1)}function j(R){f?.scaleExtent(R)}function N(R){f?.translateExtent(R)}function I(R){const P=!dg(R)||R<0?0:R;f?.clickDistance(P)}return{update:y,destroy:b,setViewport:w,setViewportConstrained:S,getViewport:_,scaleTo:C,scaleBy:E,setScaleExtent:j,setTranslateExtent:N,syncViewport:k,setClickDistance:I}}var ET;(function(e){e.Line="line",e.Handle="handle"})(ET||(ET={}));function nHn({width:e,prevWidth:t,height:n,prevHeight:r,affectsX:s,affectsY:a}){const i=e-t,l=n-r,c=[i>0?1:i<0?-1:0,l>0?1:l<0?-1:0];return i&&s&&(c[0]=c[0]*-1),l&&a&&(c[1]=c[1]*-1),c}function Y9e(e){const t=e.includes("right")||e.includes("left"),n=e.includes("bottom")||e.includes("top"),r=e.includes("left"),s=e.includes("top");return{isHorizontal:t,isVertical:n,affectsX:r,affectsY:s}}function F0(e,t){return Math.max(0,t-e)}function z0(e,t){return Math.max(0,e-t)}function N6(e,t,n){return Math.max(0,t-e,e-n)}function X9e(e,t){return e?!t:t}function rHn(e,t,n,r,s,a,i,l){let{affectsX:c,affectsY:u}=t;const{isHorizontal:d,isVertical:f}=t,p=d&&f,{xSnapped:h,ySnapped:m}=n,{minWidth:v,maxWidth:y,minHeight:b,maxHeight:S}=r,{x:w,y:k,width:_,height:C,aspectRatio:E}=e;let j=Math.floor(d?h-e.pointerX:0),N=Math.floor(f?m-e.pointerY:0);const I=_+(c?-j:j),R=C+(u?-N:N),P=-a[0]*_,L=-a[1]*C;let M=N6(I,v,y),q=N6(R,b,S);if(i){let z=0,B=0;c&&j<0?z=F0(w+j+P,i[0][0]):!c&&j>0&&(z=z0(w+I+P,i[1][0])),u&&N<0?B=F0(k+N+L,i[0][1]):!u&&N>0&&(B=z0(k+R+L,i[1][1])),M=Math.max(M,z),q=Math.max(q,B)}if(l){let z=0,B=0;c&&j>0?z=z0(w+j,l[0][0]):!c&&j<0&&(z=F0(w+I,l[1][0])),u&&N>0?B=z0(k+N,l[0][1]):!u&&N<0&&(B=F0(k+R,l[1][1])),M=Math.max(M,z),q=Math.max(q,B)}if(s){if(d){const z=N6(I/E,b,S)*E;if(M=Math.max(M,z),i){let B=0;!c&&!u||c&&!u&&p?B=z0(k+L+I/E,i[1][1])*E:B=F0(k+L+(c?j:-j)/E,i[0][1])*E,M=Math.max(M,B)}if(l){let B=0;!c&&!u||c&&!u&&p?B=F0(k+I/E,l[1][1])*E:B=z0(k+(c?j:-j)/E,l[0][1])*E,M=Math.max(M,B)}}if(f){const z=N6(R*E,v,y)/E;if(q=Math.max(q,z),i){let B=0;!c&&!u||u&&!c&&p?B=z0(w+R*E+P,i[1][0])/E:B=F0(w+(u?N:-N)*E+P,i[0][0])/E,q=Math.max(q,B)}if(l){let B=0;!c&&!u||u&&!c&&p?B=F0(w+R*E,l[1][0])/E:B=z0(w+(u?N:-N)*E,l[0][0])/E,q=Math.max(q,B)}}}N=N+(N<0?q:-q),j=j+(j<0?M:-M),s&&(p?I>R*E?N=(X9e(c,u)?-j:j)/E:j=(X9e(c,u)?-N:N)*E:d?(N=j/E,u=c):(j=N*E,c=u));const H=c?w+j:w,F=u?k+N:k;return{width:_+(c?-j:j),height:C+(u?-N:N),x:a[0]*j*(c?-1:1)+H,y:a[1]*N*(u?-1:1)+F}}const D0t={width:0,height:0,x:0,y:0},sHn={...D0t,pointerX:0,pointerY:0,aspectRatio:1};function aHn(e){return[[0,0],[e.measured.width,e.measured.height]]}function iHn(e,t,n){const r=t.position.x+e.position.x,s=t.position.y+e.position.y,a=e.measured.width??0,i=e.measured.height??0,l=n[0]*a,c=n[1]*i;return[[r-l,s-c],[r+a-l,s+i-c]]}function oHn({domNode:e,nodeId:t,getStoreItems:n,onChange:r,onEnd:s}){const a=gp(e);let i={controlDirection:Y9e("bottom-right"),boundaries:{minWidth:0,minHeight:0,maxWidth:Number.MAX_VALUE,maxHeight:Number.MAX_VALUE},resizeDirection:void 0,keepAspectRatio:!1};function l({controlPosition:u,boundaries:d,keepAspectRatio:f,resizeDirection:p,onResizeStart:h,onResize:m,onResizeEnd:v,shouldResize:y}){let b={...D0t},S={...sHn};i={boundaries:d,resizeDirection:p,keepAspectRatio:f,controlDirection:Y9e(u)};let w,k=null,_=[],C,E,j,N=!1;const I=Gxt().on("start",R=>{const{nodeLookup:P,transform:L,snapGrid:M,snapToGrid:q,nodeOrigin:H,paneDomNode:F}=n();if(w=P.get(t),!w)return;k=F?.getBoundingClientRect()??null;const{xSnapped:z,ySnapped:B}=V2(R.sourceEvent,{transform:L,snapGrid:M,snapToGrid:q,containerBounds:k});b={width:w.measured.width??0,height:w.measured.height??0,x:w.position.x??0,y:w.position.y??0},S={...b,pointerX:z,pointerY:B,aspectRatio:b.width/b.height},C=void 0,w.parentId&&(w.extent==="parent"||w.expandParent)&&(C=P.get(w.parentId),E=C&&w.extent==="parent"?aHn(C):void 0),_=[],j=void 0;for(const[D,Q]of P)if(Q.parentId===t&&(_.push({id:D,position:{...Q.position},extent:Q.extent}),Q.extent==="parent"||Q.expandParent)){const V=iHn(Q,w,Q.origin??H);j?j=[[Math.min(V[0][0],j[0][0]),Math.min(V[0][1],j[0][1])],[Math.max(V[1][0],j[1][0]),Math.max(V[1][1],j[1][1])]]:j=V}h?.(R,{...b})}).on("drag",R=>{const{transform:P,snapGrid:L,snapToGrid:M,nodeOrigin:q}=n(),H=V2(R.sourceEvent,{transform:P,snapGrid:L,snapToGrid:M,containerBounds:k}),F=[];if(!w)return;const{x:z,y:B,width:D,height:Q}=b,V={},$=w.origin??q,{width:U,height:Z,x:X,y:te}=rHn(S,i.controlDirection,H,i.boundaries,i.keepAspectRatio,$,E,j),J=U!==D,ee=Z!==Q,ae=X!==z&&J,ce=te!==B&ⅇif(!ae&&!ce&&!J&&!ee)return;if((ae||ce||$[0]===1||$[1]===1)&&(V.x=ae?X:b.x,V.y=ce?te:b.y,b.x=V.x,b.y=V.y,_.length>0)){const pe=X-z,le=te-B;for(const ve of _)ve.position={x:ve.position.x-pe+$[0]*(U-D),y:ve.position.y-le+$[1]*(Z-Q)},F.push(ve)}if((J||ee)&&(V.width=J&&(!i.resizeDirection||i.resizeDirection==="horizontal")?U:b.width,V.height=ee&&(!i.resizeDirection||i.resizeDirection==="vertical")?Z:b.height,b.width=V.width,b.height=V.height),C&&w.expandParent){const pe=$[0]*(V.width??0);V.x&&V.x<pe&&(b.x=pe,S.x=S.x-(V.x-pe));const le=$[1]*(V.height??0);V.y&&V.y<le&&(b.y=le,S.y=S.y-(V.y-le))}const Y=nHn({width:b.width,prevWidth:D,height:b.height,prevHeight:Q,affectsX:i.controlDirection.affectsX,affectsY:i.controlDirection.affectsY}),ne={...b,direction:Y};y?.(R,ne)!==!1&&(N=!0,m?.(R,ne),r(V,F))}).on("end",R=>{N&&(v?.(R,{...b}),s?.({...b}),N=!1)});a.call(I)}function c(){a.on(".drag",null)}return{update:l,destroy:c}}const lHn={},K9e=e=>{let t;const n=new Set,r=(d,f)=>{const p=typeof d=="function"?d(t):d;if(!Object.is(p,t)){const h=t;t=f??(typeof p!="object"||p===null)?p:Object.assign({},t,p),n.forEach(m=>m(t,h))}},s=()=>t,c={setState:r,getState:s,getInitialState:()=>u,subscribe:d=>(n.add(d),()=>n.delete(d)),destroy:()=>{(lHn?"production":void 0)!=="production"&&console.warn("[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected."),n.clear()}},u=t=e(r,s,c);return c},cHn=e=>e?K9e(e):K9e,{useDebugValue:uHn}=Le,{useSyncExternalStoreWithSelector:dHn}=$wn,fHn=e=>e;function L0t(e,t=fHn,n){const r=dHn(e.subscribe,e.getState,e.getServerState||e.getInitialState,t,n);return uHn(r),r}const J9e=(e,t)=>{const n=cHn(e),r=(s,a=t)=>L0t(n,s,a);return Object.assign(r,n),r},pHn=(e,t)=>e?J9e(e,t):J9e;function no(e,t){if(Object.is(e,t))return!0;if(typeof e!="object"||e===null||typeof t!="object"||t===null)return!1;if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(const[r,s]of e)if(!Object.is(s,t.get(r)))return!1;return!0}if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(const r of e)if(!t.has(r))return!1;return!0}const n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(const r of n)if(!Object.prototype.hasOwnProperty.call(t,r)||!Object.is(e[r],t[r]))return!1;return!0}const DV=g.createContext(null),hHn=DV.Provider,F0t=hy.error001();function Us(e,t){const n=g.useContext(DV);if(n===null)throw new Error(F0t);return L0t(n,e,t)}function So(){const e=g.useContext(DV);if(e===null)throw new Error(F0t);return g.useMemo(()=>({getState:e.getState,setState:e.setState,subscribe:e.subscribe}),[e])}const eFe={display:"none"},mHn={position:"absolute",width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0px, 0px, 0px, 0px)",clipPath:"inset(100%)"},z0t="react-flow__node-desc",B0t="react-flow__edge-desc",gHn="react-flow__aria-live",vHn=e=>e.ariaLiveMessage,yHn=e=>e.ariaLabelConfig;function bHn({rfId:e}){const t=Us(vHn);return o.jsx("div",{id:`${gHn}-${e}`,"aria-live":"assertive","aria-atomic":"true",style:mHn,children:t})}function xHn({rfId:e,disableKeyboardA11y:t}){const n=Us(yHn);return o.jsxs(o.Fragment,{children:[o.jsx("div",{id:`${z0t}-${e}`,style:eFe,children:t?n["node.a11yDescription.default"]:n["node.a11yDescription.keyboardDisabled"]}),o.jsx("div",{id:`${B0t}-${e}`,style:eFe,children:n["edge.a11yDescription.default"]}),!t&&o.jsx(bHn,{rfId:e})]})}const b3=g.forwardRef(({position:e="top-left",children:t,className:n,style:r,...s},a)=>{const i=`${e}`.split("-");return o.jsx("div",{className:Ml(["react-flow__panel",n,...i]),style:r,ref:a,...s,children:t})});b3.displayName="Panel";function wHn({proOptions:e,position:t="bottom-right"}){return e?.hideAttribution?null:o.jsx(b3,{position:t,className:"react-flow__attribution","data-message":"Please only hide this attribution when you are subscribed to React Flow Pro: https://pro.reactflow.dev",children:o.jsx("a",{href:"https://reactflow.dev",target:"_blank",rel:"noopener noreferrer","aria-label":"React Flow attribution",children:"React Flow"})})}const SHn=e=>{const t=[],n=[];for(const[,r]of e.nodeLookup)r.selected&&t.push(r.internals.userNode);for(const[,r]of e.edgeLookup)r.selected&&n.push(r);return{selectedNodes:t,selectedEdges:n}},I6=e=>e.id;function kHn(e,t){return no(e.selectedNodes.map(I6),t.selectedNodes.map(I6))&&no(e.selectedEdges.map(I6),t.selectedEdges.map(I6))}function OHn({onSelectionChange:e}){const t=So(),{selectedNodes:n,selectedEdges:r}=Us(SHn,kHn);return g.useEffect(()=>{const s={nodes:n,edges:r};e?.(s),t.getState().onSelectionChangeHandlers.forEach(a=>a(s))},[n,r,e]),null}const _Hn=e=>!!e.onSelectionChangeHandlers;function CHn({onSelectionChange:e}){const t=Us(_Hn);return e||t?o.jsx(OHn,{onSelectionChange:e}):null}const Mhe=typeof window<"u"?g.useLayoutEffect:g.useEffect,U0t=[0,0],EHn={x:0,y:0,zoom:1},jHn=["nodes","edges","defaultNodes","defaultEdges","onConnect","onConnectStart","onConnectEnd","onClickConnectStart","onClickConnectEnd","nodesDraggable","autoPanOnNodeFocus","nodesConnectable","nodesFocusable","edgesFocusable","edgesReconnectable","elevateNodesOnSelect","elevateEdgesOnSelect","minZoom","maxZoom","nodeExtent","onNodesChange","onEdgesChange","elementsSelectable","connectionMode","snapGrid","snapToGrid","translateExtent","connectOnClick","defaultEdgeOptions","fitView","fitViewOptions","onNodesDelete","onEdgesDelete","onDelete","onNodeDrag","onNodeDragStart","onNodeDragStop","onSelectionDrag","onSelectionDragStart","onSelectionDragStop","onMoveStart","onMove","onMoveEnd","noPanClassName","nodeOrigin","autoPanOnConnect","autoPanOnNodeDrag","onError","connectionRadius","isValidConnection","selectNodesOnDrag","nodeDragThreshold","connectionDragThreshold","onBeforeDelete","debug","autoPanSpeed","ariaLabelConfig","zIndexMode"],tFe=[...jHn,"rfId"],THn=e=>({setNodes:e.setNodes,setEdges:e.setEdges,setMinZoom:e.setMinZoom,setMaxZoom:e.setMaxZoom,setTranslateExtent:e.setTranslateExtent,setNodeExtent:e.setNodeExtent,reset:e.reset,setDefaultNodesAndEdges:e.setDefaultNodesAndEdges}),nFe={translateExtent:sM,nodeOrigin:U0t,minZoom:.5,maxZoom:2,elementsSelectable:!0,noPanClassName:"nopan",rfId:"1"};function NHn(e){const{setNodes:t,setEdges:n,setMinZoom:r,setMaxZoom:s,setTranslateExtent:a,setNodeExtent:i,reset:l,setDefaultNodesAndEdges:c}=Us(THn,no),u=So();Mhe(()=>(c(e.defaultNodes,e.defaultEdges),()=>{d.current=nFe,l()}),[]);const d=g.useRef(nFe);return Mhe(()=>{for(const f of tFe){const p=e[f],h=d.current[f];p!==h&&(typeof e[f]>"u"||(f==="nodes"?t(p):f==="edges"?n(p):f==="minZoom"?r(p):f==="maxZoom"?s(p):f==="translateExtent"?a(p):f==="nodeExtent"?i(p):f==="ariaLabelConfig"?u.setState({ariaLabelConfig:bVn(p)}):f==="fitView"?u.setState({fitViewQueued:p}):f==="fitViewOptions"?u.setState({fitViewOptions:p}):u.setState({[f]:p})))}d.current=e},tFe.map(f=>e[f])),null}function rFe(){return typeof window>"u"||!window.matchMedia?null:window.matchMedia("(prefers-color-scheme: dark)")}function IHn(e){const[t,n]=g.useState(e==="system"?null:e);return g.useEffect(()=>{if(e!=="system"){n(e);return}const r=rFe(),s=()=>n(r?.matches?"dark":"light");return s(),r?.addEventListener("change",s),()=>{r?.removeEventListener("change",s)}},[e]),t!==null?t:rFe()?.matches?"dark":"light"}const sFe=typeof document<"u"?document:null;function cM(e=null,t={target:sFe,actInsideInputWithModifier:!0}){const[n,r]=g.useState(!1),s=g.useRef(!1),a=g.useRef(new Set([])),[i,l]=g.useMemo(()=>{if(e!==null){const u=(Array.isArray(e)?e:[e]).filter(f=>typeof f=="string").map(f=>f.replace("+",`
|
|
337
337
|
`).replace(`
|
|
338
338
|
|
|
339
339
|
`,`
|
|
@@ -342,7 +342,7 @@ attempted value: ${i}
|
|
|
342
342
|
M${j.x},${j.y}h${j.width}v${j.height}h${-j.width}z`,fillRule:"evenodd",pointerEvents:"none"})]})})}Swt.displayName="MiniMap";g.memo(Swt);const OZn=e=>t=>e?`${Math.max(1/t.transform[2],1)}`:void 0,_Zn={[ET.Line]:"right",[ET.Handle]:"bottom-right"};function CZn({nodeId:e,position:t,variant:n=ET.Handle,className:r,style:s=void 0,children:a,color:i,minWidth:l=10,minHeight:c=10,maxWidth:u=Number.MAX_VALUE,maxHeight:d=Number.MAX_VALUE,keepAspectRatio:f=!1,resizeDirection:p,autoScale:h=!0,shouldResize:m,onResizeStart:v,onResize:y,onResizeEnd:b}){const S=Y0t(),w=typeof e=="string"?e:S,k=So(),_=g.useRef(null),C=n===ET.Handle,E=Us(g.useCallback(OZn(C&&h),[C,h]),no),j=g.useRef(null),N=t??_Zn[n];g.useEffect(()=>{if(!(!_.current||!w))return j.current||(j.current=oHn({domNode:_.current,nodeId:w,getStoreItems:()=>{const{nodeLookup:R,transform:P,snapGrid:L,snapToGrid:M,nodeOrigin:q,domNode:H}=k.getState();return{nodeLookup:R,transform:P,snapGrid:L,snapToGrid:M,nodeOrigin:q,paneDomNode:H}},onChange:(R,P)=>{const{triggerNodeChanges:L,nodeLookup:M,parentLookup:q,nodeOrigin:H}=k.getState(),F=[],z={x:R.x,y:R.y},B=M.get(w);if(B&&B.expandParent&&B.parentId){const D=B.origin??H,Q=R.width??B.measured.width??0,V=R.height??B.measured.height??0,$={id:B.id,parentId:B.parentId,rect:{width:Q,height:V,...x0t({x:R.x??B.position.x,y:R.y??B.position.y},{width:Q,height:V},B.parentId,M,D)}},U=E1e([$],M,q,H);F.push(...U),z.x=R.x?Math.max(D[0]*Q,R.x):void 0,z.y=R.y?Math.max(D[1]*V,R.y):void 0}if(z.x!==void 0&&z.y!==void 0){const D={id:w,type:"position",position:{...z}};F.push(D)}if(R.width!==void 0&&R.height!==void 0){const Q={id:w,type:"dimensions",resizing:!0,setAttributes:p?p==="horizontal"?"width":"height":!0,dimensions:{width:R.width,height:R.height}};F.push(Q)}for(const D of P){const Q={...D,type:"position"};F.push(Q)}L(F)},onEnd:({width:R,height:P})=>{const L={id:w,type:"dimensions",resizing:!1,dimensions:{width:R,height:P}};k.getState().triggerNodeChanges([L])}})),j.current.update({controlPosition:N,boundaries:{minWidth:l,minHeight:c,maxWidth:u,maxHeight:d},keepAspectRatio:f,resizeDirection:p,onResizeStart:v,onResize:y,onResizeEnd:b,shouldResize:m}),()=>{j.current?.destroy()}},[N,l,c,u,d,f,v,y,b,m]);const I=N.split("-");return o.jsx("div",{className:Ml(["react-flow__resize-control","nodrag",...I,n,r]),ref:_,style:{...s,scale:E,...i&&{[C?"backgroundColor":"borderColor"]:i}},children:a})}g.memo(CZn);const Db="workflow-step-node",z7="workflow-boundary-node",r8=e=>{switch(e.type){case"step":return e.step.component==="WORKFLOW"?{kind:"nested-workflow-step",id:e.step.id,step:e.step,flow:e}:e.step.mapConfig?{kind:"map-step",id:e.step.id,step:e.step,flow:e}:{kind:"step",id:e.step.id,step:e.step,flow:e};case"foreach":return{kind:"foreach-step",id:e.step.id,step:e.step,flow:e};case"parallel":return{kind:"parallel-step",id:"parallel",flow:e};case"conditional":return{kind:"conditional",id:e.serializedConditions[0]?.id??"conditional",flow:e};case"loop":return{kind:"loop-step",id:e.step.id,step:e.step,flow:e};case"sleep":return{kind:"sleep-step",id:e.id,flow:e};case"sleepUntil":return{kind:"sleep-until-step",id:e.id,flow:e}}},kwt=e=>`boundary-${e}`,JJ=kwt("start"),eee=kwt("end"),Vm=e=>`node-${e}`,gh=e=>`condition-node-${e}`,np=(e,t,n="step")=>`edge-${n}-${e}-${t}`,EZn=e=>{const t=new Set;return e.map(n=>{if(!t.has(n.id))return t.add(n.id),n;let r=1,s=`${n.id}-${r}`;for(;t.has(s);)r+=1,s=`${n.id}-${r}`;return t.add(s),{...n,id:s}})},SFe=e=>e.type===z7?{width:e.measured?.width??56,height:e.measured?.height??56}:{width:e.measured?.width??274,height:e.measured?.height??(e?.data?.isLarge?260:100)},jZn=(e,t,n)=>{if(!e.startsWith("mapping_"))return e;const r=c=>c.split(" ").map(u=>u.charAt(0).toUpperCase()+u.slice(1)).join(" "),s=c=>{const u=c.replace(/Step$/,"").replace(/[-_]/g," ").trim();return r(u)},a=(c,u)=>c.length===0?u?"End":"Start":c.length===1?s(c[0]):`${c.length} Steps`,i=a(t,!1),l=a(n,!0);return`${i} → ${l} Map`},TZn=(e,t)=>{const n=new b9e.graphlib.Graph().setDefaultEdgeLabel(()=>({}));n.setGraph({rankdir:"TB"}),t.forEach(a=>n.setEdge(a.source,a.target)),e.forEach(a=>n.setNode(a.id,{...a,...SFe(a)})),b9e.layout(n);const r=n.graph()?.width?n.graph().width/2:0,s=n.graph()?.height?n.graph().height/2:0;return{nodes:e.map(a=>{const i=n.node(a.id),{width:l,height:c}=SFe(a),u=i.x-l/2,d=i.y-c/2;return{...a,position:{x:u,y:d}}}),edges:t,fullWidth:r,fullHeight:s}},rp={animated:!0,markerEnd:{type:iM.ArrowClosed,width:20,height:20,color:"#8e8e8e"}},tee=e=>r8({type:"conditional",steps:[],serializedConditions:[e]}),Lhe=({stepFlow:e,xIndex:t,yIndex:n,prevNodeIds:r,prevStepIds:s,nextStepFlow:a,condition:i,allPrevNodeIds:l})=>{let c=[],u=[];if(a?.type==="step"||a?.type==="foreach"||a?.type==="loop"){const d=l.has(Vm(a.step.id))?`${a.step.id}-${n+1}`:a.step.id;c=[Vm(d)],u=[a.step.id]}if(a?.type==="sleep"||a?.type==="sleepUntil"){const d=l.has(Vm(a.id))?`${a.id}-${n+1}`:a.id;c=[Vm(d)],u=[a.id]}if(a?.type==="parallel"&&(c=a?.steps.map(d=>{const f=d.step.id,p=l.has(Vm(f))?`${f}-${n+1}`:f;return Vm(p)})||[],u=a?.steps.map(d=>d.step.id)||[]),a?.type==="conditional"&&(c=a?.serializedConditions.map(d=>gh(d.id))||[],u=a?.steps?.map(d=>d.step.id)||[]),e.type==="step"||e.type==="foreach"){const d=e.step.component==="WORKFLOW",f=l.has(Vm(e.step.id))?`${e.step.id}-${n}`:e.step.id,p=Vm(f),m=[...i?[{id:gh(i.id),position:{x:t*300,y:n*100},type:Db,data:{label:i.id,workflowStep:tee(i),nodeRole:"condition",previousStepId:s[s.length-1],nextStepId:e.step.id,withoutTopHandle:!r.length,withoutBottomHandle:!c.length,isLarge:!0,conditions:[{type:"when",fnString:i.fn}]}}]:[],{id:p,position:{x:t*300,y:(n+(i?1:0))*100},type:Db,data:{label:jZn(e.step.id,s,u),workflowStep:r8(e),stepId:e.step.id,description:e.step.description,withoutTopHandle:i?!1:!r.length,withoutBottomHandle:!c.length,stepGraph:d?e.step.serializedStepFlow:void 0,mapConfig:e.step.mapConfig,canSuspend:e.step.canSuspend,isForEach:e.type==="foreach",metadata:e.step.metadata}}],v=[...i?[...(r||[]).map((y,b)=>({id:np(y,gh(i.id),"condition"),source:y,data:{previousStepId:s[b],nextStepId:e.step.id,conditionNode:!0},target:gh(i.id),...rp})),{id:np(gh(i.id),p,"condition"),source:gh(i.id),data:{previousStepId:s[s.length-1],nextStepId:e.step.id,conditionNode:!0},target:p,...rp}]:(r||[]).map((y,b)=>({id:np(y,p),source:y,data:{previousStepId:s[b],nextStepId:e.step.id},target:p,...rp})),...(c||[]).map((y,b)=>({id:np(p,y),source:p,data:{previousStepId:e.step.id,nextStepId:u[b]},target:y,...rp}))];return{nodes:m,edges:v,nextPrevNodeIds:[p],nextPrevStepIds:[e.step.id]}}if(e.type==="sleep"||e.type==="sleepUntil"){const d=l.has(Vm(e.id))?`${e.id}-${n}`:e.id,f=Vm(d),h=[...i?[{id:gh(i.id),position:{x:t*300,y:n*100},type:Db,data:{label:i.id,workflowStep:tee(i),nodeRole:"condition",previousStepId:s[s.length-1],nextStepId:e.id,withoutTopHandle:!1,withoutBottomHandle:!c.length,isLarge:!0,conditions:[{type:"when",fnString:i.fn}]}}]:[],{id:f,position:{x:t*300,y:(n+(i?1:0))*100},type:Db,data:{label:e.id,workflowStep:r8(e),stepId:e.id,withoutTopHandle:i?!1:!r.length,withoutBottomHandle:!c.length,...e.type==="sleepUntil"?{date:e.date}:{duration:e.duration}}}],m=[...r.length?i?[...r.map((v,y)=>({id:np(v,gh(i.id),"condition"),source:v,data:{previousStepId:s[y],nextStepId:e.id,conditionNode:!0},target:gh(i.id),...rp})),{id:np(gh(i.id),f,"condition"),source:gh(i.id),data:{previousStepId:s[s.length-1],nextStepId:e.id,conditionNode:!0},target:f,...rp}]:r.map((v,y)=>({id:np(v,f),source:v,data:{previousStepId:s[y],nextStepId:e.id},target:f,...rp})):[],...c.length?c.map((v,y)=>({id:np(f,v),source:f,data:{previousStepId:e.id,nextStepId:u[y]},target:v,...rp})):[]];return{nodes:h,edges:m,nextPrevNodeIds:[f],nextPrevStepIds:[e.id]}}if(e.type==="loop"){const{step:d,serializedCondition:f,loopType:p}=e,h=Vm(d.id),m=gh(f.id),v=[{id:h,position:{x:t*300,y:n*100},type:Db,data:{label:d.id,workflowStep:r8(e),stepId:d.id,description:d.description,withoutTopHandle:!r.length,withoutBottomHandle:!1,stepGraph:d.component==="WORKFLOW"?d.serializedStepFlow:void 0,canSuspend:d.canSuspend,metadata:d.metadata}},{id:m,position:{x:t*300,y:(n+1)*100},type:Db,data:{label:f.id,workflowStep:tee(f),nodeRole:"condition",previousStepId:d.id,nextStepId:u[0],withoutTopHandle:!1,withoutBottomHandle:!c.length,isLarge:!0,conditions:[{type:p,fnString:f.fn}]}}],y=[...r.length?r.map((b,S)=>({id:np(b,h),source:b,data:{previousStepId:s[S],nextStepId:d.id},target:h,...rp})):[],{id:np(h,m,"condition"),source:h,data:{previousStepId:d.id,nextStepId:u[0]},target:m,...rp},...c.length?c.map((b,S)=>({id:np(m,b,"condition"),source:m,data:{previousStepId:d.id,nextStepId:u[S]},target:b,...rp})):[]];return{nodes:v,edges:y,nextPrevNodeIds:[m],nextPrevStepIds:[d.id]}}if(e.type==="parallel"){let d=[],f=[],p=[];return e.steps.forEach((h,m)=>{const{nodes:v,edges:y,nextPrevStepIds:b}=Lhe({stepFlow:h,xIndex:m,yIndex:n,prevNodeIds:r,prevStepIds:s,nextStepFlow:a,allPrevNodeIds:l}),S=v.map(w=>({...w,data:{...w.data,isParallel:!0}}));d.push(...S),f.push(...y),p.push(...b)}),{nodes:d,edges:f,nextPrevNodeIds:d.map(h=>h.id),nextPrevStepIds:p}}if(e.type==="conditional"){let d=[],f=[],p=[];return e.steps.forEach((h,m)=>{const{nodes:v,edges:y,nextPrevStepIds:b}=Lhe({stepFlow:h,xIndex:m,yIndex:n,prevNodeIds:r,prevStepIds:s,nextStepFlow:a,condition:e.serializedConditions[m],allPrevNodeIds:l});d.push(...v),f.push(...y),p.push(...b)}),{nodes:d,edges:f,nextPrevNodeIds:d.filter(({data:h})=>h.nodeRole!=="condition").map(h=>h.id),nextPrevStepIds:p}}return{nodes:[],edges:[],nextPrevNodeIds:[],nextPrevStepIds:[]}},N1e=({stepGraph:e})=>{if(!e)return{nodes:[],edges:[]};if(e.length===0)return{nodes:[],edges:[]};let t=[],n=[],r=[],s=[];const a=new Set;for(let b=0;b<e.length;b++){const{nodes:S,edges:w,nextPrevNodeIds:k,nextPrevStepIds:_}=Lhe({stepFlow:e[b],xIndex:b,yIndex:b,prevNodeIds:r,prevStepIds:s,nextStepFlow:b===e.length-1?void 0:e[b+1],allPrevNodeIds:a});t.push(...S),n.push(...w),r=k,s=_;for(const C of r)a.add(C)}const i=new Set(n.map(b=>b.target)),l=new Set(n.map(b=>b.source)),c=t.filter(b=>!i.has(b.id)).map(b=>b.id),u=t.filter(b=>!l.has(b.id)).map(b=>b.id),d=new Set(c),f=new Set(u);t=t.map(b=>({...b,data:{...b.data,...d.has(b.id)?{withoutTopHandle:!1}:{},...f.has(b.id)?{withoutBottomHandle:!1}:{}}}));const p=[{id:JJ,position:{x:0,y:0},type:z7,data:{label:"Start",boundaryRole:"start"}},...t,{id:eee,position:{x:0,y:0},type:z7,data:{label:"End",boundaryRole:"end"}}],h=c.map(b=>({id:np(JJ,b,"boundary"),source:JJ,target:b,data:{boundaryPayload:"workflow-input",nextStepId:(()=>{const S=p.find(w=>w.id===b);return S?.type!==Db?b:S?.data.stepId??S?.data.nextStepId??b})()},...rp})),m=u.map(b=>({id:np(b,eee,"boundary"),source:b,target:eee,data:{boundaryPayload:"workflow-output"},...rp}));n=[...h,...n,...m],n=EZn(n);const{nodes:v,edges:y}=TZn(p,n);return{nodes:v,edges:y}},Owt=e=>e.reduce((t,n)=>{if(!n.data||n.data.boundaryPayload)return t;const r=n.data?.nextStepId,s=n.data?.previousStepId;return!r||!s?t:{...t,[r]:[...new Set([...t[r]||[],s])]}},{}),_wt=e=>Object.entries(e).reduce((t,[n,r])=>{for(const s of r)t[s]=[...new Set([...t[s]||[],n])];return t},{}),Cwt=e=>{const t=new Set,n=new Set,r=s=>{if(s){if((s.type==="step"||s.type==="foreach"||s.type==="loop")&&s.step?.component==="WORKFLOW"&&s.step?.id&&n.add(s.step.id),s.type==="conditional")for(const a of s.steps)t.add(a.step.id),r(a);if(s.type==="parallel")for(const a of s.steps)r(a)}};for(const s of e??[])r(s);return{conditionalStepIds:t,nestedWorkflowStepIds:n}},I1e=({stepId:e,conditionalStepIds:t,stepSuccessors:n,stepsFlow:r,isStepSuccess:s})=>t.has(e)?(n[e]??[]).some(i=>(r[i]??[]).some(l=>l!==e&&s(l))):!1,NZn=({stepNodesInOrder:e,isStepSuccess:t,isStepBypassed:n})=>e.find(r=>!t(r)&&!n(r)),IZn=({nextStepKey:e,stepNodesInOrder:t,isStepSuccess:n,isStepBypassed:r})=>{if(!e)return!1;const s=t.indexOf(e);return t.slice(s+1).every(a=>n(a)||r(a))},AZn=(e,t,n=()=>!1)=>e.every(r=>t?.[r]?.status==="success"||n(r)),RZn=(e,t)=>e.find(n=>(n.data?.stepId??n.data?.label)===t),PZn=({nextStepKey:e,stepsFlow:t,steps:n,isStepBypassed:r=()=>!1})=>{if(!e)return;const s=t?.[e]??[];if(s.length===0)return;if(s.length>1)return AZn(s,n,r)?{hasMultiSteps:!0,input:s.filter(i=>n?.[i]?.status==="success").reduce((i,l)=>(i[l]=n?.[l]?.output,i),{})}:void 0;const a=s[0];if(n?.[a]?.status==="success")return{hasMultiSteps:!1,input:n?.[a]?.output}};function Ewt(e,t){return g.useMemo(()=>Object.entries(e?.steps||{}).filter(([n,{status:r}])=>r==="suspended").map(([n,{suspendPayload:r}])=>({stepId:n,runId:t,suspendPayload:r,isLoading:!1})),[e?.steps,t])}function $Zn(e){return g.useMemo(()=>{const t=e?.inputSchema,n=e?.stateSchema,r=t?lm(im(yx(t))):null,s=n?lm(im(yx(n))):null;return{zodSchemaToUse:s?Ss({inputData:r,initialState:s.optional()}):r,hasStateSchema:!!n}},[e?.inputSchema,e?.stateSchema])}function jwt(e){return g.useMemo(()=>{const{nodes:t,edges:n}=N1e({stepGraph:e}),r=t.flatMap(c=>c.type!==Db||c.data.nodeRole==="condition"||!c.data.stepId?[]:[c.data.stepId]),s=Owt(n),a=_wt(s),{conditionalStepIds:i,nestedWorkflowStepIds:l}=Cwt(e);return{stepNodesInOrder:r,stepsFlow:s,stepSuccessors:a,conditionalStepIds:i,nestedWorkflowStepIds:l}},[e])}function A1e(){const{result:e,workflow:t}=g.useContext($l),{stepNodesInOrder:n,stepsFlow:r,stepSuccessors:s,conditionalStepIds:a}=jwt(t?.stepGraph),i=e?.steps,l=e?.status==="paused",c=g.useCallback(f=>i?.[f]?.status==="success",[i]),u=g.useCallback(f=>i?.[f]?.status==="success"||i?.[f]?.status==="skipped",[i]),d=g.useCallback(f=>I1e({stepId:f,conditionalStepIds:a,stepSuccessors:s,stepsFlow:r,isStepSuccess:c}),[a,s,r,c]);return g.useMemo(()=>l?NZn({stepNodesInOrder:n,isStepSuccess:u,isStepBypassed:d}):void 0,[l,n,u,d])}function MZn(){const{result:e}=g.useContext($l);return g.useMemo(()=>Object.entries(e?.steps||{}).find(([n,{status:r}])=>r==="suspended")?.[0],[e?.steps])}function DZn(){const{result:e,runId:t,workflowId:n,workflow:r,payload:s,setDebugMode:a,timeTravelWorkflowStream:i}=g.useContext($l),l=Pl(),{stepsFlow:c,stepNodesInOrder:u,nestedWorkflowStepIds:d,conditionalStepIds:f,stepSuccessors:p}=jwt(r?.stepGraph),h=e?.steps,m=g.useCallback(C=>h?.[C]?.status==="success",[h]),v=g.useCallback(C=>h?.[C]?.status==="success"||h?.[C]?.status==="skipped",[h]),y=g.useCallback(C=>I1e({stepId:C,conditionalStepIds:f,stepSuccessors:p,stepsFlow:c,isStepSuccess:m}),[f,p,c,m]),b=A1e(),S=g.useMemo(()=>{const C=PZn({nextStepKey:b,stepsFlow:c,steps:h,isStepBypassed:y});if(C)return C;if(b&&(c[b]?.length??0)===0)return{hasMultiSteps:!1,input:e?.input??s}},[b,c,h,e?.input,s,y]),w=g.useMemo(()=>IZn({nextStepKey:b,stepNodesInOrder:u,isStepSuccess:v,isStepBypassed:y}),[b,u,v,y]),k=!!(b&&S),_=g.useCallback(C=>{if(!b||!S)return;const E=d.has(b),j=C||E||w,N={runId:t,workflowId:n,step:b,inputData:S.hasMultiSteps?void 0:S.input,requestContext:l,perStep:!j,...S.hasMultiSteps?{context:Object.keys(S.input).reduce((I,R)=>(I[R]={status:"success",output:S.input[R]},I),{})}:{}};C&&a(!1),i(N)},[b,S,t,n,l,a,i,d,w]);return{canRunNextStep:k,runNextStep:g.useCallback(()=>_(!1),[_]),continueFullRun:g.useCallback(()=>_(!0),[_])}}function LZn(){const{workflowId:e,workflow:t,createWorkflowRun:n,resumeWorkflow:r}=g.useContext($l),s=Pl();return g.useCallback(async a=>{if(!t)return;const{stepId:i,runId:l,resumeData:c}=a,u=await n({workflowId:e,prevRunId:l});await r({step:i,runId:u.runId,resumeData:c,workflowId:e,requestContext:s})},[e,t,n,r,s])}const FZn=["success","failed","canceled","tripwire"],zZn=["running","suspended","paused"];function BZn({status:e,cancelMessage:t,isCancelling:n,onCancel:r,disabled:s}){return!e||!zZn.includes(e)?null:o.jsxs(de,{type:"button",variant:"default",className:"w-full",onClick:r,disabled:s||!!t||n||FZn.includes(e),children:[n?o.jsx(Ue,{children:o.jsx(oa,{className:"animate-spin"})}):o.jsx(Ue,{children:o.jsx($lt,{})}),t||"Cancel Workflow Run"]})}function UZn({isStreaming:e}){const{result:t}=g.useContext($l),{canRunNextStep:n,runNextStep:r,continueFullRun:s}=DZn();return t?.status!=="paused"?null:o.jsxs("div",{className:"flex flex-col gap-2","data-testid":"workflow-debug-step-controls",children:[o.jsxs(de,{type:"button",variant:"primary",className:"w-full",onClick:r,disabled:!n||e,children:[e?o.jsx(Ue,{children:o.jsx(oa,{className:"animate-spin"})}):o.jsx(Ue,{children:o.jsx(Fp,{})}),"Run next step"]}),o.jsxs(de,{type:"button",variant:"ghost",className:"w-full",onClick:s,disabled:e,children:[o.jsx(Ue,{children:o.jsx(tct,{})}),"Continue full run"]})]})}const Twt=({data:e,title:t})=>o.jsxs(xr,{className:"max-w-3xl",children:[o.jsx(wr,{children:o.jsx(gr,{children:t})}),o.jsx(Rr,{className:"max-h-[90vh]",children:o.jsx(Qr,{data:e,className:"p-0"})})]}),kFe=({data:e,triggerLabel:t,title:n,triggerIcon:r=o.jsx(ky,{className:"shrink-0 text-neutral3"}),trigger:s,variant:a="default",size:i="md",className:l,open:c,onOpenChange:u})=>{const[d,f]=g.useState(!1),p=c??d,h=u??f;return o.jsxs(o.Fragment,{children:[s??o.jsxs(de,{type:"button",variant:a,size:i,className:l,onClick:()=>h(!0),children:[r,t&&o.jsx("span",{className:"truncate",children:t})]}),o.jsx(br,{open:p,onOpenChange:h,children:o.jsx(Twt,{data:e,title:n})})]})};function qZn(e){const{open:t,defaultOpen:n,onOpenChange:r,disabled:s}=e,[a,i]=uf({controlled:t,default:n,name:"Collapsible",state:"open"}),{mounted:l,setMounted:c,transitionStatus:u}=Pg(a,!0,!0),d=Fi(),[f,p]=g.useState(),h=f??d,m=vt(v=>{const y=!a,b=Ht(Sg,v.nativeEvent);r(y,b),!b.isCanceled&&i(y)});return g.useMemo(()=>({disabled:s,handleTrigger:m,mounted:l,open:a,panelId:h,setMounted:c,setOpen:i,setPanelIdState:p,transitionStatus:u}),[s,m,l,a,h,c,i,p,u])}const Nwt=g.createContext(void 0);function Iwt(){const e=g.useContext(Nwt);if(e===void 0)throw new Error(Sr(15));return e}let R1e=(function(e){return e.open="data-open",e.closed="data-closed",e[e.startingStyle=kg.startingStyle]="startingStyle",e[e.endingStyle=kg.endingStyle]="endingStyle",e})({}),VZn=(function(e){return e.panelOpen="data-panel-open",e})({});const HZn={[R1e.open]:""},WZn={[R1e.closed]:""},ZZn={open(e){return e?{[VZn.panelOpen]:""}:null}},GZn={open(e){return e?HZn:WZn}},Awt={...GZn,...nc},QZn=g.forwardRef(function(t,n){const{render:r,className:s,defaultOpen:a=!1,disabled:i=!1,onOpenChange:l,open:c,style:u,...d}=t,f=vt(l),p=qZn({open:c,defaultOpen:a,onOpenChange:f,disabled:i}),h=g.useMemo(()=>({open:p.open,disabled:p.disabled,transitionStatus:p.transitionStatus}),[p.open,p.disabled,p.transitionStatus]),m=g.useMemo(()=>({...p,onOpenChange:f,state:h}),[p,f,h]),v=En("div",t,{state:h,ref:n,props:d,stateAttributesMapping:Awt});return o.jsx(Nwt.Provider,{value:m,children:v})}),YZn={...ZZn,...nc},XZn=g.forwardRef(function(t,n){const{panelId:r,open:s,handleTrigger:a,state:i,disabled:l}=Iwt(),{className:c,disabled:u=l,id:d,render:f,nativeButton:p=!0,style:h,...m}=t,{getButtonProps:v,buttonRef:y}=Ed({disabled:u,focusableWhenDisabled:!0,native:p});return En("button",t,{state:i,ref:[n,y],props:[{"aria-controls":s?r:void 0,"aria-expanded":s,onClick:a},m,v],stateAttributesMapping:YZn})}),KA={height:void 0,width:void 0};function KZn(e){const{externalRef:t,hiddenUntilFound:n,id:r,keepMounted:s,mounted:a,onOpenChange:i,open:l,setMounted:c,setOpen:u,transitionStatus:d}=e,f=g.useRef(null),p=g.useRef(null),[h,m]=g.useState(KA),v=g.useRef(KA),y=g.useRef(!1),b=g.useRef(l),S=g.useRef(!1),[w,k]=g.useState(!1),_=g.useRef(null),C=Lu(t,f),E=Xi({mounted:a,open:l}),j=$q(f,!1,!1),N=!l&&!a,I=w?"idle":d,R=l&&(b.current||S.current),P=!l&&a&&p.current==="css-animation"&&h.height===void 0&&h.width===void 0?v.current:h,L=n&&N&&p.current!=="css-animation",M=vt((B,D=!0)=>{D&&(v.current=B),m(B)}),q=vt(()=>{_.current?.(),_.current=null}),H=vt(B=>{q(),_.current=()=>{_.current=null,B()}}),F=vt(()=>{l&&a&&p.current==="css-animation"&&(S.current=!0)});Nt(()=>{!w||d==="starting"||k(!1)},[w,d]),g.useEffect(()=>()=>{F(),q()},[F,q]),Nt(()=>{const B=f.current;if(!B)return;!l&&_.current&&q();const D=JZn(B,R);if(p.current=D,l&&d==="idle"&&b.current&&D==="css-animation"){v.current=qC(B);return}if(l&&d==="starting"){const $=y.current;if(y.current=!1,D==="none"){M(qC(B)),k(!0);return}if(D==="css-transition"){const U=eGn(B);if(M(qC(B)),!$)return U;const Z=JA(B,"transition-duration","0s");return H(Z),k(!0),U}if(D==="css-animation"){if(M(qC(B)),!$){JA(B,"animation-name","none")();return}const U=JA(B,"animation-name","none"),Z=JA(B,"animation-duration","0s");U(),H(Z),k(!0);return}}if(!l&&a&&(d==="idle"||d==="starting")){if(D==="none"){M(KA,!1),c(!1);return}D==="css-animation"&&(b.current=!1,S.current=!1),M(qC(B));return}if(d!=="ending")return;if(D==="none"){c(!1);return}const Q=qC(B);if(!((Q.height??0)>0||(Q.width??0)>0)){c(!1);return}M(Q),D==="css-animation"&&JA(B,"animation-name","none")()},[a,l,q,M,c,H,R,d]),rc({enabled:l&&a&&I==="idle",open:!0,ref:f,onComplete(){l&&M(KA,!1)}}),g.useEffect(()=>{if(l||!a||I!=="ending"||!f.current)return;const D=new AbortController;let Q=-1;function V(){E.current.open||(c(!1),M(KA,!1))}return Q=Hd.request(()=>{D.signal.aborted||j(V,D.signal)}),()=>{Hd.cancel(Q),D.abort()}},[E,a,l,I,j,M,c]),Nt(()=>{const B=f.current;!B||!n||!N||B.setAttribute("hidden","until-found")},[N,n]),g.useEffect(function(){const D=f.current;if(!D)return;function Q(V){y.current=!0,u(!0),i(!0,Ht(Io,V))}return Ur(D,"beforematch",Q)},[i,u]);const z=s||n||a||l;return{height:P.height,props:{...L?{[R1e.startingStyle]:""}:void 0,hidden:N,id:r},ref:C,shouldPreventOpenAnimation:R,shouldRender:z,transitionStatus:I,width:P.width}}function qC(e){return{height:e.scrollHeight,width:e.scrollWidth}}function JZn(e,t=!1){const n=Ks(e).getComputedStyle(e),r=(n.animationName.split(",").map(a=>a.trim()).some(a=>a!==""&&a!=="none")||t)&&OFe(n.animationDuration),s=OFe(n.transitionDuration);return r&&s||s?"css-transition":r?"css-animation":"none"}function OFe(e){return e.split(",").map(t=>t.trim()).some(t=>t!==""&&Number.parseFloat(t)>0)}function JA(e,t,n){const r=e.style.getPropertyValue(t),s=e.style.getPropertyPriority(t);return e.style.setProperty(t,n),()=>{if(r===""){e.style.removeProperty(t);return}e.style.setProperty(t,r,s)}}function eGn(e){const t={"justify-content":e.style.justifyContent,"align-items":e.style.alignItems,"align-content":e.style.alignContent,"justify-items":e.style.justifyItems};Object.keys(t).forEach(s=>{e.style.setProperty(s,"initial","important")});function n(){Object.entries(t).forEach(([s,a])=>{if(a===""){e.style.removeProperty(s);return}e.style.setProperty(s,a)})}const r=Hd.request(n);return()=>{Hd.cancel(r),n()}}let _Fe=(function(e){return e.collapsiblePanelHeight="--collapsible-panel-height",e.collapsiblePanelWidth="--collapsible-panel-width",e})({});const tGn=g.forwardRef(function(t,n){const{className:r,hiddenUntilFound:s,keepMounted:a,render:i,id:l,style:c,...u}=t,{mounted:d,onOpenChange:f,open:p,panelId:h,setMounted:m,setPanelIdState:v,setOpen:y,state:b,transitionStatus:S}=Iwt(),w=s??!1,k=a??!1;Nt(()=>{if(l)return v(l),()=>{v(void 0)}},[l,v]);const{height:_,props:C,ref:E,shouldPreventOpenAnimation:j,shouldRender:N,transitionStatus:I,width:R}=KZn({externalRef:n,hiddenUntilFound:w,id:h,keepMounted:k,mounted:d,onOpenChange:f,open:p,setMounted:m,setOpen:y,transitionStatus:S}),P={...b,transitionStatus:I},L=Jdt(c,P),M=En("div",{...t,style:void 0},{state:P,ref:E,props:[C,{style:{[_Fe.collapsiblePanelHeight]:_===void 0?"auto":`${_}px`,[_Fe.collapsiblePanelWidth]:R===void 0?"auto":`${R}px`}},u,L?{style:L}:void 0,j?{style:{animationName:"none"}}:void 0],stateAttributesMapping:Awt});return N?M:null}),xf=QZn,Od=Le.forwardRef(({className:e,asChild:t,children:n,...r},s)=>{const a=t&&Le.isValidElement(n)?{render:n}:{};return o.jsx(XZn,{ref:s,"data-slot":"collapsible-trigger",className:K("-outline-offset-2",ms.colors,qD.visible,"hover:text-neutral5","[&>svg]:transition-transform [&>svg]:duration-normal [&>svg]:ease-out-custom","[&[data-panel-open]>svg]:rotate-90",e),...a,...r,children:t?void 0:n})});Od.displayName="CollapsibleTrigger";const _d=Le.forwardRef(({className:e,children:t,...n},r)=>o.jsx(tGn,{ref:r,"data-slot":"collapsible-content",className:K("overflow-hidden","h-[var(--collapsible-panel-height)] transition-[height] duration-normal ease-out-custom","data-[starting-style]:h-0 data-[ending-style]:h-0"),...n,children:o.jsx("div",{className:e,children:t})}));_d.displayName="CollapsibleContent";function nGn({value:e,onChange:t,disabled:n,includeSimple:r,compact:s}){const a=s?"h-3 w-3":"h-4 w-4",i=[...r?[{value:"simple",label:"Simple"}]:[],{value:"form",label:"Form",icon:o.jsx(obe,{className:a})},{value:"json",label:"JSON",icon:o.jsx(ky,{className:a})}];return o.jsx("div",{role:"radiogroup","aria-label":"Input type",className:K("grid grid-flow-col auto-cols-fr gap-1 border border-border1 bg-surface3",s?"h-5 w-auto rounded-md p-0.5":"w-full rounded-lg p-1"),children:i.map(l=>{const c=l.value===e;return o.jsxs("button",{type:"button",role:"radio","aria-checked":c,"aria-label":l.label,disabled:n,onClick:()=>t(l.value),className:K("flex items-center justify-center rounded-md transition-colors",s?"gap-0.5 px-1 py-0":"gap-2 px-3 py-1.5","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent1",c?"bg-surface5 text-neutral5":"text-neutral3 hover:text-neutral4",n&&"cursor-not-allowed opacity-50"),children:[l.icon,o.jsx(ge,{as:"span",variant:s?"ui-xs":"ui-sm",children:l.label})]},l.value)})})}const B7=({schema:e,defaultValues:t,withoutSubmit:n,isReadOnly:r,disableSubmit:s,isSubmitLoading:a,submitButtonLabel:i,onSubmit:l,children:c,isProcessorWorkflow:u,submitActions:d,leftActions:f,heading:p,headingSlot:h,collapsible:m=!0,headingClassName:v,submitButtonClassName:y,submitButtonIcon:b,submitButtonVariant:S,submitButtonFullWidth:w,hideInputTypeLabel:k,inputTypeLabel:_="Run input",hideHeading:C})=>{const[E,j]=g.useState(u?"simple":"form"),N=g.useMemo(()=>JSON.stringify({message:Pwt(t),phase:$wt(t)}),[t]),I=o.jsx(ge,{as:"span",variant:"ui-md",className:K("text-neutral5 font-semibold",v),children:p??(n?"Run input":"Trigger a run")}),R=o.jsx(nGn,{value:E,onChange:j,disabled:a,includeSimple:u,compact:!m&&!C}),P=o.jsxs(o.Fragment,{children:[!k&&o.jsxs("div",{className:"flex justify-between gap-3 py-3 px-5",children:[o.jsx(ge,{as:"p",variant:"ui-sm",className:"text-neutral3",children:_}),!m&&!C&&o.jsx("div",{className:"shrink-0",children:R})]}),o.jsxs("div",{className:"px-5",children:[(m||C||k)&&o.jsx("div",{className:"pb-4",children:R}),o.jsx("div",{className:K("pb-4",{"opacity-50 pointer-events-none":a}),children:E==="simple"&&u?o.jsx(oGn,{schema:e,defaultValues:t,isSubmitLoading:a,submitButtonLabel:i,submitButtonClassName:y,onSubmit:l,withoutSubmit:n,isReadOnly:r,disableSubmit:s,submitActions:d,leftActions:f,children:c},N):E==="form"?o.jsx(rGn,{schema:e,defaultValues:t,isSubmitLoading:a,submitButtonLabel:i,submitButtonClassName:y,submitButtonIcon:b,submitButtonVariant:S,submitButtonFullWidth:w,onSubmit:l,withoutSubmit:n,isReadOnly:r,disableSubmit:s,submitActions:d,leftActions:f,children:c}):o.jsx(sGn,{schema:e,defaultValues:t,isSubmitLoading:a,submitButtonLabel:i,submitButtonClassName:y,onSubmit:l,withoutSubmit:n,isReadOnly:r,disableSubmit:s,submitActions:d,leftActions:f,children:c})})]})]});return m?o.jsxs(xf,{defaultOpen:!0,children:[o.jsxs(Od,{className:"flex w-full items-center gap-2 pb-3 text-left",children:[o.jsx(ta,{className:"h-4 w-4 shrink-0 text-neutral3"}),h??I]}),o.jsx(_d,{children:P})]}):o.jsxs(o.Fragment,{children:[!C&&o.jsx("div",{className:"border-b border-border1/50 pb-3",children:h??I}),o.jsx("div",{children:P})]})},Rwt=({isSubmitLoading:e,submitButtonLabel:t,disableSubmit:n,submitActions:r,leftActions:s,submitButtonClassName:a,submitButtonIcon:i,submitButtonVariant:l,onSubmit:c})=>o.jsxs("div",{className:"flex items-center justify-between gap-1",children:[s??o.jsx("div",{}),o.jsxs("div",{className:"flex items-center gap-1",children:[r,o.jsxs(de,{variant:l??"primary",onClick:c,disabled:e||n,className:a,children:[e?o.jsx(Ue,{children:o.jsx(oa,{className:"animate-spin"})}):i??o.jsx(Ue,{children:o.jsx(Fp,{})}),t]})]})]}),rGn=({schema:e,defaultValues:t,isSubmitLoading:n,submitButtonLabel:r,onSubmit:s,withoutSubmit:a,isReadOnly:i,disableSubmit:l,children:c,submitActions:u,leftActions:d,submitButtonClassName:f,submitButtonIcon:p,submitButtonVariant:h,submitButtonFullWidth:m})=>o.jsx(a3,{schema:e,defaultValues:t,isSubmitLoading:n,submitButtonLabel:r,submitButtonClassName:f,submitButtonIcon:p,submitButtonVariant:h,submitButtonFullWidth:m,onSubmit:a?void 0:s,readOnly:i,disableSubmit:l,submitActions:u,leftActions:d,children:c}),sGn=({schema:e,defaultValues:t,isSubmitLoading:n,submitButtonLabel:r,onSubmit:s,withoutSubmit:a,isReadOnly:i,disableSubmit:l,children:c,submitActions:u,leftActions:d,submitButtonClassName:f,submitButtonIcon:p,submitButtonVariant:h})=>{const[m,v]=g.useState([]),[y,b]=g.useState(()=>JSON.stringify(t??{},null,2)),S=()=>{v([]);try{const k=e.safeParse(JSON.parse(y));k.success?s(k.data):v(k.error.issues.map(_=>`[${_.path.join(".")}] ${_.message}`))}catch{v(["Invalid JSON provided"])}};let w={};try{w=JSON.parse(y)}catch{w={}}return o.jsxs("div",{className:"flex flex-col gap-4",children:[m.length>0&&o.jsxs("div",{className:"border border-accent2 rounded-lg p-2",children:[o.jsxs(ge,{as:"p",variant:"ui-md",className:"text-accent2 font-semibold",children:[m.length," errors found"]}),o.jsx("ul",{className:"list-disc list-inside",children:m.map((k,_)=>o.jsx("li",{className:"text-ui-sm text-accent2",children:k},_))})]}),o.jsxs("div",{children:[o.jsx(ge,{as:"label",variant:"ui-sm",className:"text-neutral3 pb-1 block",children:"Input data"}),o.jsx(Qr,{data:w,onChange:b,editable:!i})]}),c,a?null:o.jsx(Rwt,{isSubmitLoading:n,submitButtonLabel:r,disableSubmit:l,submitActions:u,leftActions:d,submitButtonClassName:f,submitButtonIcon:p,submitButtonVariant:h,onSubmit:S})]})},CFe=[{value:"input",label:"Input - Process input messages before LLM"},{value:"inputStep",label:"Input Step - Process at each agentic loop step"},{value:"outputStream",label:"Output Stream - Process streaming chunks"},{value:"outputResult",label:"Output Result - Process complete output"},{value:"outputStep",label:"Output Step - Process after each LLM response"}],aGn="Hello, this is a test message.",iGn="input";function Pwt(e){const t=e?.messages?.[0]?.content?.parts?.find(n=>n?.type==="text");return typeof t?.text=="string"?t.text:aGn}function $wt(e){return typeof e?.phase=="string"?e.phase:iGn}const oGn=({schema:e,defaultValues:t,isSubmitLoading:n,submitButtonLabel:r,onSubmit:s,withoutSubmit:a,isReadOnly:i,disableSubmit:l,children:c,submitActions:u,leftActions:d,submitButtonClassName:f,submitButtonIcon:p,submitButtonVariant:h})=>{const[m,v]=g.useState(()=>Pwt(t)),[y,b]=g.useState(()=>$wt(t)),[S,w]=g.useState([]),k=()=>{w([]);const C=y==="outputStep"||y==="outputResult"?"assistant":"user",E={messages:[{id:crypto.randomUUID(),role:C,createdAt:new Date().toISOString(),content:{format:2,parts:[{type:"text",text:m}]}}],phase:y};try{const j=e.safeParse(E);j.success?s(j.data):w(j.error.issues.map(N=>`[${N.path.join(".")}] ${N.message}`))}catch{w(["Error processing input"])}};return o.jsxs("div",{className:"flex flex-col gap-4",children:[S.length>0&&o.jsxs("div",{className:"border border-accent2 rounded-lg p-2",children:[o.jsxs(ge,{as:"p",variant:"ui-md",className:"text-accent2 font-semibold",children:[S.length," errors found"]}),o.jsx("ul",{className:"list-disc list-inside",children:S.map((_,C)=>o.jsx("li",{className:"text-ui-sm text-accent2",children:_},C))})]}),o.jsxs("div",{className:"space-y-2",children:[o.jsx(ge,{as:"label",variant:"ui-sm",className:"text-neutral3",children:"Phase"}),o.jsxs(da,{value:y,onValueChange:b,disabled:i,children:[o.jsx(pa,{className:"w-full",children:o.jsx(fa,{placeholder:"Select phase"})}),o.jsx(ha,{children:CFe.map(_=>o.jsx(Lr,{value:_.value,children:_.value},_.value))})]}),o.jsx(ge,{variant:"ui-xs",className:"text-neutral4",children:CFe.find(_=>_.value===y)?.label})]}),o.jsxs("div",{className:"space-y-2",children:[o.jsx(ge,{as:"label",variant:"ui-sm",className:"text-neutral3",children:"Test Message"}),o.jsx("textarea",{value:m,onChange:_=>v(_.target.value),placeholder:"Enter a test message...",rows:4,disabled:i,className:"w-full bg-transparent border border-border1 rounded-md p-3 text-ui-sm text-neutral6 placeholder:text-neutral3 focus:outline-hidden focus:ring-2 focus:ring-accent1 disabled:opacity-50"})]}),c,a?null:o.jsx(Rwt,{isSubmitLoading:n,submitButtonLabel:r,disableSubmit:l,submitActions:u,leftActions:d,submitButtonClassName:f,submitButtonIcon:p,submitButtonVariant:h,onSubmit:k})]})};function lGn({zodSchema:e,isStreaming:t,onExecute:n,defaultValues:r,isViewingRun:s,isReadOnly:a,disableSubmit:i,isProcessorWorkflow:l,submitActions:c,leftActions:u,heading:d,headingSlot:f,collapsible:p}){const[h,m]=g.useState(!1);return e&&s?o.jsxs("div",{children:[f&&o.jsx("div",{className:"pb-3",children:f}),o.jsx("div",{className:"flex flex-col gap-1 px-5",children:o.jsxs(de,{type:"button",variant:"ghost",size:"sm",className:"w-full justify-start",onClick:()=>m(!0),children:[o.jsx(obe,{className:"shrink-0 text-neutral3"}),o.jsx("span",{className:"truncate",children:"Run input"})]})}),o.jsx(br,{open:h,onOpenChange:m,children:o.jsxs(xr,{className:"max-w-3xl",children:[o.jsx(wr,{children:o.jsx(gr,{children:"Workflow input"})}),o.jsx(Rr,{className:"max-h-[90vh]",children:o.jsx(B7,{schema:e,defaultValues:r,isSubmitLoading:t,submitButtonLabel:"Run",onSubmit:n,withoutSubmit:!0,isReadOnly:!0,disableSubmit:i,isProcessorWorkflow:l,collapsible:!1,hideHeading:!0,hideInputTypeLabel:!0})})]})})]}):e?o.jsx(B7,{schema:e,defaultValues:r,isSubmitLoading:t,submitButtonLabel:"Run",submitButtonVariant:"primary",submitButtonIcon:o.jsx(Ue,{children:o.jsx(Fp,{})}),onSubmit:n,withoutSubmit:s,isReadOnly:a,disableSubmit:i,isProcessorWorkflow:l,submitActions:c,leftActions:u,heading:d,headingSlot:f,collapsible:p}):s?null:o.jsxs("div",{className:"flex items-center justify-between gap-1",children:[u??o.jsx("div",{}),o.jsxs("div",{className:"flex items-center gap-1",children:[c,o.jsxs(de,{variant:"primary",disabled:t||i,onClick:()=>n(null),children:[t?o.jsx(Ue,{children:o.jsx(oa,{className:"animate-spin"})}):o.jsx(Ue,{children:o.jsx(Fp,{})}),"Run"]})]})]})}function cGn(){const{debugMode:e,setDebugMode:t}=g.useContext($l);return o.jsxs("label",{className:"flex shrink-0 items-center gap-2 cursor-pointer",children:[o.jsx(ec,{checked:e,onCheckedChange:t,"aria-label":"Debug"}),o.jsx(ge,{variant:"ui-xs",className:"text-neutral3 whitespace-nowrap",children:"Debug"})]})}function uGn(e){const{setResult:t}=g.useContext($l);g.useEffect(()=>{e&&t(e)},[t,e])}function dGn(e){return e?e.charAt(0).toUpperCase()+e.slice(1):"Run"}function fGn(e){if(e===void 0)return"—";if(e<1e3)return`${e}ms`;const t=e/1e3;if(t<60)return`${Number(t.toPrecision(3))}s`;const n=Math.floor(t/60),r=Math.floor(t%60);return r?`${n}m ${r}s`:`${n}m`}function pGn(e){if(!e||e<=0)return"—";const t=e-Date.now(),n=Math.abs(t),r=Math.floor(n/1e3);if(r<60)return t>=0?`in ${r}s`:`${r}s ago`;const s=Math.floor(r/60);if(s<60)return t>=0?`in ${s}m`:`${s}m ago`;const a=Math.floor(s/60);if(a<24)return t>=0?`in ${a}h`:`${a}h ago`;const i=Math.floor(a/24);return t>=0?`in ${i}d`:`${i}d ago`}function hGn(e,t){const n=Object.values(e?.steps??{}).flatMap(c=>{const u="startedAt"in c?c.startedAt:void 0;if(typeof u!="number")return[];const d="endedAt"in c?c.endedAt:void 0;return[{startedAt:u,...typeof d=="number"?{endedAt:d}:{}}]});if(n.length===0)return;const r=Math.min(...n.map(c=>c.startedAt)),s=n.flatMap(c=>c.endedAt?[c.endedAt]:[]),l=(s.length>0?Math.max(...s):void 0)??(t==="running"||t==="suspended"||t==="waiting"?Date.now():void 0);return l===void 0?void 0:l-r}function mGn({workflow:e,workflowId:t}){const n=Object.keys(e.steps??{}).length;return o.jsxs("div",{className:"flex w-full items-center gap-2 px-5",children:[o.jsx(Ue,{className:"shrink-0 text-neutral4",children:o.jsx(jd,{})}),o.jsx(ge,{as:"span",variant:"ui-md",className:"text-neutral5 font-semibold truncate",children:e.name??t}),o.jsx(Oa,{content:e.name??t,variant:"ghost",className:"shrink-0"}),o.jsxs(dn,{className:"ml-auto shrink-0",children:[n," step",n>1?"s":""]})]})}function gGn({runId:e,status:t,result:n,timestamp:r}){const s=hGn(n,t);return o.jsxs("div",{className:"flex w-full items-start gap-3 px-5",children:[t&&o.jsx("span",{className:"shrink-0 pt-1",children:o.jsx(Ext,{status:t})}),o.jsxs("div",{className:"min-w-0 flex-1",children:[o.jsx(ge,{as:"span",variant:"ui-md",className:"block truncate font-semibold text-neutral5",children:dGn(t)}),o.jsx(ge,{as:"span",variant:"ui-xs",className:"block truncate text-neutral3",title:e,children:e})]}),o.jsxs("div",{className:"shrink-0 text-right",children:[o.jsx(ge,{as:"span",variant:"ui-xs",className:"block font-medium text-neutral5",children:fGn(s)}),o.jsx(ge,{as:"span",variant:"ui-xs",className:"block text-neutral3",children:pGn(r)})]})]})}function Mwt({workflowId:e,paramsRunId:t,paramsRunStatus:n,setRunId:r,workflow:s,isLoading:a,createWorkflowRun:i,streamWorkflow:l,observeWorkflowStream:c,isStreamingWorkflow:u,streamResult:d,isCancellingWorkflowRun:f,cancelWorkflowRun:p}){const h=Pl(),{result:m,setResult:v,payload:y,setPayload:b,setRunId:S,runId:w,runSnapshot:k}=g.useContext($l);uGn(d);const{canExecute:_}=il(),C=_("workflows"),[E,j]=g.useState(""),[N,I]=g.useState(null),R=g.useRef(null),P=t||w,L=P?m??d:null,M=Ewt(L,E),{zodSchemaToUse:q,hasStateSchema:H}=$Zn(s),F=["success","failed","canceled","bailed"].includes(L?.status??""),z=L?.status==="paused",B=async Z=>{try{if(!s)return;I(null),v(null);const X=await i({workflowId:e});r?.(X.runId),j(X.runId),S(X.runId);const{initialState:te,inputData:J}=Z??{},ee=H?J:Z;l({workflowId:e,runId:X.runId,inputData:ee,initialState:te,requestContext:h})}catch{De.error("Error executing workflow")}},D=async()=>{try{const Z=await p({workflowId:e,runId:E});I(Z)}catch{De.error("Error cancelling workflow run")}};if(g.useEffect(()=>{if(!t||!c)return;const Z=`${e}:${t}`;R.current!==Z&&(c({workflowId:e,runId:t}),R.current=Z),j(t),S(t)},[t,c,S,e]),g.useEffect(()=>{!t&&!w&&j("")},[w,t]),a)return o.jsx(Yr,{className:"h-[calc(100vh-126px)] pt-2 px-4 pb-4 text-xs",children:o.jsxs("div",{className:"space-y-4",children:[o.jsx(bt,{className:"h-10"}),o.jsx(bt,{className:"h-10"})]})});if(!s)return null;const Q=M.length>0,V=!!P,$=L?.status??n,U=V?o.jsx(gGn,{runId:P,status:$,result:L,timestamp:k?.timestamp}):o.jsx(mGn,{workflow:s,workflowId:e});return o.jsx("div",{className:"h-full pt-3 overflow-y-auto",children:o.jsxs("div",{className:"border-b border-border1/50",children:[Q&&u&&o.jsxs("div",{className:"py-2 px-5 flex items-center gap-2 bg-surface5 -mt-5 border-b border-border1",children:[o.jsx(Ue,{children:o.jsx(oa,{className:"animate-spin text-neutral6"})}),o.jsx(ge,{children:"Resuming workflow"})]}),C&&o.jsx(o.Fragment,{children:o.jsx(lGn,{zodSchema:q,defaultValues:y,isStreaming:u||Q,onExecute:Z=>{b(Z),B(Z)},isViewingRun:!!t||F||z,isReadOnly:!!t||F||Q||z,disableSubmit:Q,isProcessorWorkflow:s?.isProcessorWorkflow,collapsible:!1,headingSlot:U,leftActions:t?void 0:o.jsx(cGn,{}),submitActions:o.jsxs(o.Fragment,{children:[s?.requestContextSchema&&o.jsx(C$n,{requestContextSchema:s.requestContextSchema}),o.jsx(qzn,{})]})})}),!C&&o.jsx(ge,{variant:"ui-sm",className:"text-neutral3 py-2 px-5",children:"You don't have permission to execute workflows."}),F&&m&&o.jsx("div",{className:"px-5 pb-4",children:o.jsxs("div",{className:"flex flex-col gap-1",children:[o.jsx(kFe,{className:"w-full justify-start",variant:"ghost",size:"sm",data:m,triggerLabel:"Entire workflow execution (JSON)",title:"Entire workflow execution (JSON)"}),"result"in m&&m.result!==void 0&&o.jsx(kFe,{className:"w-full justify-start",variant:"ghost",size:"sm",data:{result:m.result},triggerLabel:"Run output",title:"Run output (JSON)"})]})}),z&&o.jsx("div",{className:"px-5 pb-4 pt-3",children:o.jsx(UZn,{isStreaming:u})}),(L?.status==="running"||Q||z)&&o.jsx("div",{"data-testid":"workflow-cancel-action",className:"px-5 pb-4 pt-3",children:o.jsx(BZn,{status:Q?"suspended":L?.status,cancelMessage:N?.message??null,isCancelling:f,onCancel:D,disabled:Q})})]})})}const vGn=({workflowId:e,runId:t,observeWorkflowStream:n,...r})=>{const{runSnapshot:s,isLoadingRunExecutionResult:a}=g.useContext($l);if(a)return o.jsxs("div",{className:"p-4 space-y-4",children:[o.jsxs("div",{className:"flex items-start gap-3",children:[o.jsx(bt,{className:"h-5 w-5 shrink-0 rounded-full"}),o.jsxs("div",{className:"min-w-0 flex-1 space-y-2",children:[o.jsx(bt,{className:"h-4 w-24"}),o.jsx(bt,{className:"h-3 w-40"})]}),o.jsxs("div",{className:"shrink-0 space-y-2",children:[o.jsx(bt,{className:"ml-auto h-3 w-12"}),o.jsx(bt,{className:"ml-auto h-3 w-16"})]})]}),o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx(bt,{className:"h-4 w-24"}),o.jsx(bt,{className:"h-7 w-28 rounded-md"})]}),o.jsxs("div",{className:"space-y-3",children:[o.jsx(bt,{className:"h-9 w-full rounded-md"}),o.jsx(bt,{className:"h-9 w-full rounded-md"}),o.jsx(bt,{className:"h-9 w-3/4 rounded-md"})]})]});if(!s||!t)return o.jsx("div",{className:"p-4",children:o.jsx(ge,{variant:"ui-md",className:"text-neutral6 text-center",children:"No previous run"})});const i=Hfe(s),l=i?.status;if(t)return o.jsx("div",{className:"h-full grid grid-rows-[1fr_auto]",children:o.jsx(Mwt,{...r,paramsRunId:t,workflowId:e,observeWorkflowStream:()=>{l!=="success"&&l!=="failed"&&l!=="canceled"&&n?.({workflowId:e,runId:t,storeRunResult:i})}})})};function yGn(e){return cht(e,"alert-dialog")}const bGn=h0e,xGn=yGn;function Tt({open:e,onOpenChange:t,children:n}){return o.jsx(xGn,{open:e,onOpenChange:t,children:n})}const Dwt=g.forwardRef(({asChild:e,children:t,...n},r)=>o.jsx(bGn,{ref:r,...YD(e,t),...n,children:e?void 0:t}));Dwt.displayName="AlertDialogTrigger";const Lwt=d0e,P1e=g.forwardRef(({className:e,...t},n)=>o.jsx(eht,{ref:n,className:K("dialog-overlay-anim fixed inset-0 z-50 bg-overlay backdrop-blur-xs",e),...t}));P1e.displayName="AlertDialogOverlay";const Fwt=g.forwardRef(({className:e,...t},n)=>o.jsxs(Lwt,{children:[o.jsx(P1e,{}),o.jsx(lht,{ref:n,"data-slot":"alert-dialog-content",className:K("dialog-content-anim","fixed left-[50%] top-[50%] z-50 grid translate-x-[-50%] translate-y-[-50%]","w-full max-w-[calc(100%-2rem)] sm:max-w-lg","rounded-xl border border-border1/40 bg-surface2/96 backdrop-blur-md shadow-dialog",e),...t})]}));Fwt.displayName="AlertDialogContent";const zwt=({className:e,...t})=>o.jsx("div",{className:K("flex flex-col gap-0.5 px-4 py-3 text-left",e),...t});zwt.displayName="AlertDialogHeader";const Bwt=({className:e,...t})=>o.jsx("div",{className:K("flex flex-col-reverse gap-1.5 px-4 py-2.5 sm:flex-row sm:justify-end",e),...t});Bwt.displayName="AlertDialogFooter";const Uwt=({className:e,...t})=>o.jsx("div",{className:K("overflow-y-auto px-4 py-3.5 max-h-[50vh]",e),...t});Uwt.displayName="AlertDialogBody";const qwt=g.forwardRef(({className:e,...t},n)=>o.jsx(p0e,{ref:n,className:K("text-ui-md font-medium",e),...t}));qwt.displayName="AlertDialogTitle";const Vwt=g.forwardRef(({className:e,...t},n)=>o.jsx(c0e,{ref:n,className:K("text-ui-sm text-neutral3",e),...t}));Vwt.displayName="AlertDialogDescription";const Hwt=g.forwardRef(({className:e,...t},n)=>o.jsx(ZD,{ref:n,className:K(zD({variant:"primary",size:"lg"}),e),...t}));Hwt.displayName="AlertDialogAction";const Wwt=g.forwardRef(({className:e,...t},n)=>o.jsx(ZD,{ref:n,className:K(zD({variant:"default",size:"lg"}),e),...t}));Wwt.displayName="AlertDialogCancel";Tt.Trigger=Dwt;Tt.Portal=Lwt;Tt.Overlay=P1e;Tt.Content=Fwt;Tt.Header=zwt;Tt.Footer=Bwt;Tt.Body=Uwt;Tt.Title=qwt;Tt.Description=Vwt;Tt.Action=Hwt;Tt.Cancel=Wwt;const Zwt=({children:e,"aria-label":t="Threads",embedded:n=!1})=>o.jsx("div",{className:K("h-full w-full",!n&&"pb-2 pl-2"),children:o.jsx("nav",{"aria-label":t,className:K("h-full overflow-y-auto p-1",!n&&"bg-surface3 rounded-studio-panel border border-border1/50"),children:e})}),wGn=({as:e,href:t,to:n,children:r})=>o.jsx(de,{as:e,href:t,to:n,variant:"ghost",className:"w-full justify-start rounded-xl",children:r}),SGn=()=>o.jsx("div",{role:"separator","aria-orientation":"horizontal",className:"-mx-1 my-1 h-px bg-border1/40"}),Gwt=({children:e})=>o.jsx("ol",{className:"flex flex-col gap-px","data-testid":"thread-list",children:e}),Qwt=({as:e,href:t,to:n,isActive:r,onClick:s,onDelete:a,deleteLabel:i="delete",className:l,children:c})=>o.jsxs("li",{className:"group relative",children:[o.jsx(de,{as:e,href:t,to:n,onClick:s,variant:"ghost",className:K("min-h-form-md h-auto! w-full min-w-0 justify-start rounded-xl px-3 py-2 text-left",a&&"pr-9",r&&"bg-surface4 text-neutral6",l),children:o.jsx("span",{className:"min-w-0 flex-1",children:c})}),a&&o.jsx(de,{variant:"ghost",size:"icon-sm",className:"absolute right-1 top-1/2 -translate-y-1/2 opacity-0 transition-opacity group-focus-within:opacity-100 group-hover:opacity-100",onClick:a,"aria-label":i,children:o.jsx(Fu,{})})]}),Ywt=({children:e})=>o.jsx(ge,{as:"p",variant:"ui-sm",className:"text-neutral3 py-3 px-5",children:e}),A_=()=>{const[e,t]=g.useState(!1),n=g.useCallback(r=>{if(r){const s=new IntersectionObserver(([a])=>{t(a.isIntersecting)});return s.observe(r),()=>s.disconnect()}},[]);return{inView:e,setRef:n}},Fhe=20;function kGn(e,t,n){if(!(e.runs.length<Fhe))return n+1}function OGn(e){const t=new Set;return e.pages.flatMap(n=>n.runs).filter(n=>t.has(n.runId)?!1:(t.add(n.runId),!0))}const Xwt=(e,{enabled:t=!0}={})=>{const n=We(),{inView:r,setRef:s}=A_(),a=$1({queryKey:["workflow-runs",e],queryFn:({pageParam:u})=>n.getWorkflow(e).runs({limit:Fhe,offset:u*Fhe}),initialPageParam:0,getNextPageParam:kGn,select:OGn,retry:!1,enabled:t,refetchInterval:5e3}),{hasNextPage:i,isFetchingNextPage:l,fetchNextPage:c}=a;return g.useEffect(()=>{r&&i&&!l&&c()},[r,i,l,c]),{...a,setEndOfListElement:s}},Kwt=(e,t,n)=>{const r=We();return wt({queryKey:["workflow-run",e,t],queryFn:()=>r.getWorkflow(e).runById(t),enabled:!!(e&&t),gcTime:0,staleTime:0,refetchInterval:n})},_Gn=e=>{const t=We(),n=Hr();return Rn({mutationFn:({runId:r})=>t.getWorkflow(e).deleteRunById(r),onSuccess:()=>{n.invalidateQueries({queryKey:["workflow-runs",e]}),De.success("Workflow run deleted successfully")},onError:()=>{De.error("Failed to delete workflow run")}})};function CGn(e){if(!e||typeof e!="object")return null;const t=e.context?.input;if(t==null)return null;if(typeof t=="string")return t;const n=typeof t=="object"&&t!==null&&"output"in t?t.output:t;try{return JSON.stringify(n)}catch{return null}}const EGn=({workflowId:e,runId:t})=>{const[n,r]=g.useState(null),{canDelete:s}=il(),a=s("workflows"),{Link:i,paths:l,navigate:c}=yn(),{isLoading:u,data:d,setEndOfListElement:f,isFetchingNextPage:p}=Xwt(e),{mutateAsync:h}=_Gn(e),m=async y=>{try{await h({runId:y}),r(null),c(l.workflowLink(e))}catch{r(null)}},v=d||[];return o.jsxs(o.Fragment,{children:[u?o.jsx("div",{className:"p-4",children:o.jsx(bt,{className:"h-32"})}):o.jsxs("div",{children:[o.jsx("div",{className:"px-5 pb-2 pt-3 text-left",children:o.jsx(ge,{as:"h2",variant:"ui-md",className:"text-neutral3",children:"Recent runs"})}),o.jsx(Zwt,{"aria-label":"Workflow runs",embedded:!0,children:v.length===0?o.jsx(Ywt,{children:"Your run history will appear here once you run the workflow"}):o.jsxs(Gwt,{children:[v.map(y=>{const b=y.runId===t,S=b?CGn(y.snapshot):null;return o.jsx(Qwt,{as:i,to:l.workflowRunLink(e,y.runId),isActive:b,onDelete:a?()=>r(y.runId):void 0,deleteLabel:"delete run",className:"h-auto min-h-0 items-stretch py-1",children:o.jsxs("span",{className:"flex w-full min-w-0 items-center gap-2.5 px-1 text-left",children:[y?.snapshot&&typeof y.snapshot=="object"&&o.jsx("span",{className:"shrink-0",children:o.jsx(Ext,{status:y.snapshot.status})}),o.jsxs("span",{className:"flex min-w-0 flex-1 flex-col items-start gap-0.5",children:[o.jsxs("span",{className:"flex w-full min-w-0 items-center gap-2 text-xs",children:[o.jsx("span",{className:"min-w-0 flex-1 truncate font-medium text-neutral5",title:y.runId,children:y.runId}),y?.snapshot&&typeof y.snapshot=="object"&&y.snapshot.timestamp&&o.jsx("span",{className:"shrink-0 text-neutral3",children:er(y.snapshot.timestamp,"MMM d, yyyy h:mm a")})]}),S&&o.jsx("span",{className:"block w-full min-w-0 truncate text-xs text-neutral3",children:S})]})]})},`run-${y.runId}`)}),p&&o.jsx("li",{className:"flex justify-center items-center py-2",children:o.jsx(Ue,{children:o.jsx(Gt,{})})}),o.jsx("li",{children:o.jsx("div",{ref:f})})]})})]}),o.jsx(jGn,{open:!!n,onOpenChange:()=>r(null),onDelete:()=>{n&&m(n)}})]})},jGn=({open:e,onOpenChange:t,onDelete:n})=>o.jsx(Tt,{open:e,onOpenChange:t,children:o.jsxs(Tt.Content,{children:[o.jsxs(Tt.Header,{children:[o.jsx(Tt.Title,{children:"Are you absolutely sure?"}),o.jsx(Tt.Description,{children:"This action cannot be undone. This will permanently delete the workflow run and remove it from our servers."})]}),o.jsxs(Tt.Footer,{children:[o.jsx(Tt.Cancel,{children:"Cancel"}),o.jsx(Tt.Action,{onClick:n,children:"Continue"})]})]})}),S3=e=>{const t=We(),{requestContext:n}=_s();return wt({queryKey:["workflow",e],queryFn:()=>e?t.getWorkflow(e).details(n):null,enabled:!!e,retry:!1,refetchOnWindowFocus:!1,throwOnError:!1})};function TGn({workflowId:e,onClick:t}){const{Link:n,paths:r}=yn();return o.jsx("div",{className:"flex-none border-b border-border1/50 px-4 py-4",children:o.jsxs(de,{as:n,href:`${r.workflowLink(e)}/graph`,variant:"primary",className:"w-full",onClick:t,children:[o.jsx(Ue,{children:o.jsx(Vr,{})}),"New workflow run"]})})}function NGn({children:e,newRunButton:t}){return o.jsxs("section",{"data-testid":"workflow-information-top-section",className:"flex max-h-[50%] min-w-0 flex-none flex-col overflow-hidden rounded-studio-panel border border-border1/50 bg-surface3",children:[t,o.jsx(Yr,{"data-testid":"workflow-information-top-scroll-area",className:"min-h-0 flex-1",viewPortClassName:"h-full",mask:{top:!1},children:e})]})}function IGn(e){return o.jsx(Mwt,{...e})}function AGn({runId:e,observeWorkflowStream:t,...n}){return o.jsx(vGn,{...n,runId:e,observeWorkflowStream:t})}function RGn({workflowId:e,activeRunId:t}){return o.jsx("section",{className:"min-h-0 min-w-0 flex-1 overflow-hidden rounded-studio-panel border border-border1/50 bg-surface3",children:o.jsx(Yr,{className:"h-full w-full",viewPortClassName:"h-full",mask:{top:!1},children:o.jsx(EGn,{workflowId:e,runId:t})})})}function PGn({workflowId:e,initialRunId:t}){const{data:n,isLoading:r,error:s}=S3(e),{createWorkflowRun:a,streamWorkflow:i,streamResult:l,isStreamingWorkflow:c,observeWorkflowStream:u,closeStreamsAndReset:d,resumeWorkflow:f,cancelWorkflowRun:p,isCancellingWorkflowRun:h,clearData:m,setRunId:v,runId:y}=g.useContext($l),{setSelectedStepId:b}=sV(),[S,w]=g.useState(""),k=["success","failed","canceled","bailed"].includes(l?.status??""),_=!!(t||S||y||c)||k,C={workflowId:e,setRunId:w,workflow:n??void 0,isLoading:r,createWorkflowRun:a,streamWorkflow:i,resumeWorkflow:f,streamResult:l,isStreamingWorkflow:c,isCancellingWorkflowRun:h,cancelWorkflowRun:p};if(g.useEffect(()=>{!S&&!t&&d()},[S,t,d]),g.useEffect(()=>{if(s){const j=s instanceof Error?s.message:"Failed to load workflow";De.error(`Error loading workflow: ${j}`)}},[s]),s)return null;if(!e)return o.jsx("div",{"data-testid":"workflow-information-panel",className:"flex h-full min-h-0 w-full flex-col gap-2 p-2"});const E=()=>{d(),m(),w(""),v(""),b(null)};return o.jsxs("div",{"data-testid":"workflow-information-panel",className:"flex h-full min-h-0 w-full flex-col gap-2 p-2",children:[o.jsx(NGn,{newRunButton:_?o.jsx(TGn,{workflowId:e,onClick:E}):void 0,children:t?o.jsx(AGn,{...C,runId:t,observeWorkflowStream:u}):o.jsx(IGn,{...C})}),o.jsx(RGn,{workflowId:e,activeRunId:t||S||y})]})}const Jwt=(e=1024)=>{const t=g.useMemo(()=>`(max-width: ${e-1}px)`,[e]),[n,r]=g.useState(!1);return g.useLayoutEffect(()=>{const s=window.matchMedia(t),a=()=>r(s.matches);return a(),s.addEventListener("change",a),()=>s.removeEventListener("change",a)},[t]),n};function $Gn(e,t){const n=getComputedStyle(e),r=parseFloat(n.fontSize);return t*r}function MGn(e,t){const n=getComputedStyle(e.ownerDocument.body),r=parseFloat(n.fontSize);return t*r}function DGn(e){return e/100*window.innerHeight}function LGn(e){return e/100*window.innerWidth}function FGn(e){switch(typeof e){case"number":return[e,"px"];case"string":{const t=parseFloat(e);return e.endsWith("%")?[t,"%"]:e.endsWith("px")?[t,"px"]:e.endsWith("rem")?[t,"rem"]:e.endsWith("em")?[t,"em"]:e.endsWith("vh")?[t,"vh"]:e.endsWith("vw")?[t,"vw"]:[t,"%"]}}}function f2({groupSize:e,panelElement:t,styleProp:n}){let r;const[s,a]=FGn(n);switch(a){case"%":{r=s/100*e;break}case"px":{r=s;break}case"rem":{r=MGn(t,s);break}case"em":{r=$Gn(t,s);break}case"vh":{r=DGn(s);break}case"vw":{r=LGn(s);break}}return r}function hd(e){return parseFloat(e.toFixed(3))}function jT({group:e}){const{orientation:t,panels:n}=e;return n.reduce((r,s)=>(r+=t==="horizontal"?s.element.offsetWidth:s.element.offsetHeight,r),0)}function zhe(e){const{panels:t}=e,n=jT({group:e});return n===0?t.map(r=>({groupResizeBehavior:r.panelConstraints.groupResizeBehavior,collapsedSize:0,collapsible:r.panelConstraints.collapsible===!0,defaultSize:void 0,disabled:r.panelConstraints.disabled,minSize:0,maxSize:100,panelId:r.id})):t.map(r=>{const{element:s,panelConstraints:a}=r;let i=0;if(a.collapsedSize!==void 0){const d=f2({groupSize:n,panelElement:s,styleProp:a.collapsedSize});i=hd(d/n*100)}let l;if(a.defaultSize!==void 0){const d=f2({groupSize:n,panelElement:s,styleProp:a.defaultSize});l=hd(d/n*100)}let c=0;if(a.minSize!==void 0){const d=f2({groupSize:n,panelElement:s,styleProp:a.minSize});c=hd(d/n*100)}let u=100;if(a.maxSize!==void 0){const d=f2({groupSize:n,panelElement:s,styleProp:a.maxSize});u=hd(d/n*100)}return{groupResizeBehavior:a.groupResizeBehavior,collapsedSize:i,collapsible:a.collapsible===!0,defaultSize:l,disabled:a.disabled,minSize:c,maxSize:u,panelId:r.id}})}function ui(e,t="Assertion error"){if(!e)throw Error(t)}function Bhe(e,t){return Array.from(t).sort(e==="horizontal"?zGn:BGn)}function zGn(e,t){const n=e.element.offsetLeft-t.element.offsetLeft;return n!==0?n:e.element.offsetWidth-t.element.offsetWidth}function BGn(e,t){const n=e.element.offsetTop-t.element.offsetTop;return n!==0?n:e.element.offsetHeight-t.element.offsetHeight}function e1t(e){return e!==null&&typeof e=="object"&&"nodeType"in e&&e.nodeType===Node.ELEMENT_NODE}function t1t(e,t){return{x:e.x>=t.left&&e.x<=t.right?0:Math.min(Math.abs(e.x-t.left),Math.abs(e.x-t.right)),y:e.y>=t.top&&e.y<=t.bottom?0:Math.min(Math.abs(e.y-t.top),Math.abs(e.y-t.bottom))}}function UGn({orientation:e,rects:t,targetRect:n}){const r={x:n.x+n.width/2,y:n.y+n.height/2};let s,a=Number.MAX_VALUE;for(const i of t){const{x:l,y:c}=t1t(r,i),u=e==="horizontal"?l:c;u<a&&(a=u,s=i)}return ui(s,"No rect found"),s}let R6;function qGn(){return R6===void 0&&(typeof matchMedia=="function"?R6=!!matchMedia("(pointer:coarse)").matches:R6=!1),R6}function n1t(e){const{element:t,orientation:n,panels:r,separators:s}=e,a=Bhe(n,Array.from(t.children).filter(e1t).map(m=>({element:m}))).map(({element:m})=>m),i=[];let l=!1,c=!1,u=-1,d=-1,f=0,p,h=[];{let m=-1;for(const v of a)v.hasAttribute("data-panel")&&(m++,v.hasAttribute("data-disabled")||(f++,u===-1&&(u=m),d=m))}if(f>1){let m=-1;for(const v of a)if(v.hasAttribute("data-panel")){m++;const y=r.find(b=>b.element===v);if(y){if(p){const b=p.element.getBoundingClientRect(),S=v.getBoundingClientRect();let w;if(c){const k=n==="horizontal"?new DOMRect(b.right,b.top,0,b.height):new DOMRect(b.left,b.bottom,b.width,0),_=n==="horizontal"?new DOMRect(S.left,S.top,0,S.height):new DOMRect(S.left,S.top,S.width,0);switch(h.length){case 0:{w=[k,_];break}case 1:{const C=h[0],E=UGn({orientation:n,rects:[b,S],targetRect:C.element.getBoundingClientRect()});w=[C,E===b?_:k];break}default:{w=h;break}}}else h.length?w=h:w=[n==="horizontal"?new DOMRect(b.right,S.top,S.left-b.right,S.height):new DOMRect(S.left,b.bottom,S.width,S.top-b.bottom)];for(const k of w){let _="width"in k?k:k.element.getBoundingClientRect();const C=qGn()?e.resizeTargetMinimumSize.coarse:e.resizeTargetMinimumSize.fine;if(_.width<C){const j=C-_.width;_=new DOMRect(_.x-j/2,_.y,_.width+j,_.height)}if(_.height<C){const j=C-_.height;_=new DOMRect(_.x,_.y-j/2,_.width,_.height+j)}const E=m<=u||m>d;!l&&!E&&i.push({group:e,groupSize:jT({group:e}),panels:[p,y],separator:"width"in k?void 0:k,rect:_}),l=!1}}c=!1,p=y,h=[]}}else if(v.hasAttribute("data-separator")){v.ariaDisabled!==null&&(l=!0);const y=s.find(b=>b.element===v);y?h.push(y):(p=void 0,h=[])}else c=!0}return i}let r1t=class{#e={};addListener(t,n){const r=this.#e[t];return r===void 0?this.#e[t]=[n]:r.includes(n)||r.push(n),()=>{this.removeListener(t,n)}}emit(t,n){const r=this.#e[t];if(r!==void 0)if(r.length===1)r[0].call(null,n);else{let s=!1,a=null;const i=Array.from(r);for(let l=0;l<i.length;l++){const c=i[l];try{c.call(null,n)}catch(u){a===null&&(s=!0,a=u)}}if(s)throw a}}removeAllListeners(){this.#e={}}removeListener(t,n){const r=this.#e[t];if(r!==void 0){const s=r.indexOf(n);s>=0&&r.splice(s,1)}}},Bv=new Map;const s1t=new r1t;function VGn(e){Bv=new Map(Bv),Bv.delete(e)}function EFe(e,t){for(const[n]of Bv)if(n.id===e)return n}function Mw(e,t){for(const[n,r]of Bv)if(n.id===e)return r;if(t)throw Error(`Could not find data for Group with id ${e}`)}function R_(){return Bv}function $1e(e,t){return s1t.addListener("groupChange",n=>{n.group.id===e&&t(n)})}function Ex(e,t){const n=Bv.get(e);Bv=new Map(Bv),Bv.set(e,t),s1t.emit("groupChange",{group:e,prev:n,next:t})}function HGn(e,t,n){let r,s={x:1/0,y:1/0};for(const a of t){const i=t1t(n,a.rect);switch(e){case"horizontal":{i.x<=s.x&&(r=a,s=i);break}case"vertical":{i.y<=s.y&&(r=a,s=i);break}}}return r?{distance:s,hitRegion:r}:void 0}function WGn(e){return e!==null&&typeof e=="object"&&"nodeType"in e&&e.nodeType===Node.DOCUMENT_FRAGMENT_NODE}function ZGn(e,t){if(e===t)throw new Error("Cannot compare node with itself");const n={a:NFe(e),b:NFe(t)};let r;for(;n.a.at(-1)===n.b.at(-1);)r=n.a.pop(),n.b.pop();ui(r,"Stacking order can only be calculated for elements with a common ancestor");const s={a:TFe(jFe(n.a)),b:TFe(jFe(n.b))};if(s.a===s.b){const a=r.childNodes,i={a:n.a.at(-1),b:n.b.at(-1)};let l=a.length;for(;l--;){const c=a[l];if(c===i.a)return 1;if(c===i.b)return-1}}return Math.sign(s.a-s.b)}const GGn=/\b(?:position|zIndex|opacity|transform|webkitTransform|mixBlendMode|filter|webkitFilter|isolation)\b/;function QGn(e){const t=getComputedStyle(a1t(e)??e).display;return t==="flex"||t==="inline-flex"}function YGn(e){const t=getComputedStyle(e);return!!(t.position==="fixed"||t.zIndex!=="auto"&&(t.position!=="static"||QGn(e))||+t.opacity<1||"transform"in t&&t.transform!=="none"||"webkitTransform"in t&&t.webkitTransform!=="none"||"mixBlendMode"in t&&t.mixBlendMode!=="normal"||"filter"in t&&t.filter!=="none"||"webkitFilter"in t&&t.webkitFilter!=="none"||"isolation"in t&&t.isolation==="isolate"||GGn.test(t.willChange)||t.webkitOverflowScrolling==="touch")}function jFe(e){let t=e.length;for(;t--;){const n=e[t];if(ui(n,"Missing node"),YGn(n))return n}return null}function TFe(e){return e&&Number(getComputedStyle(e).zIndex)||0}function NFe(e){const t=[];for(;e;)t.push(e),e=a1t(e);return t}function a1t(e){const{parentNode:t}=e;return WGn(t)?t.host:t}function XGn(e,t){return e.x<t.x+t.width&&e.x+e.width>t.x&&e.y<t.y+t.height&&e.y+e.height>t.y}function KGn({groupElement:e,hitRegion:t,pointerEventTarget:n}){if(!e1t(n)||n.contains(e)||e.contains(n))return!0;if(ZGn(n,e)>0){let r=n;for(;r;){if(r.contains(e))return!0;if(XGn(r.getBoundingClientRect(),t))return!1;r=r.parentElement}}return!0}function M1e(e,t){const n=[];return t.forEach((r,s)=>{if(s.disabled)return;const a=n1t(s),i=HGn(s.orientation,a,{x:e.clientX,y:e.clientY});i&&i.distance.x<=0&&i.distance.y<=0&&KGn({groupElement:s.element,hitRegion:i.hitRegion.rect,pointerEventTarget:e.target})&&n.push(i.hitRegion)}),n}function JGn(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!=t[n])return!1;return!0}function _u(e,t,n=0){return Math.abs(hd(e)-hd(t))<=n}function bv(e,t){return _u(e,t)?0:e>t?1:-1}function ZE({overrideDisabledPanels:e,panelConstraints:t,prevSize:n,size:r}){const{collapsedSize:s=0,collapsible:a,disabled:i,maxSize:l=100,minSize:c=0}=t;if(i&&!e)return n;if(bv(r,c)<0)if(a){const u=(s+c)/2;bv(r,u)<0?r=s:r=c}else r=c;return r=Math.min(l,r),r=hd(r),r}function uM({delta:e,initialLayout:t,panelConstraints:n,pivotIndices:r,prevLayout:s,trigger:a}){if(_u(e,0))return t;const i=a==="imperative-api",l=Object.values(t),c=Object.values(s),u=[...l],[d,f]=r;ui(d!=null,"Invalid first pivot index"),ui(f!=null,"Invalid second pivot index");let p=0;switch(a){case"keyboard":{{const v=e<0?f:d,y=n[v];ui(y,`Panel constraints not found for index ${v}`);const{collapsedSize:b=0,collapsible:S,minSize:w=0}=y;if(S){const k=l[v];if(ui(k!=null,`Previous layout not found for panel index ${v}`),_u(k,b)){const _=w-k;bv(_,Math.abs(e))>0&&(e=e<0?0-_:_)}}}{const v=e<0?d:f,y=n[v];ui(y,`No panel constraints found for index ${v}`);const{collapsedSize:b=0,collapsible:S,minSize:w=0}=y;if(S){const k=l[v];if(ui(k!=null,`Previous layout not found for panel index ${v}`),_u(k,w)){const _=k-b;bv(_,Math.abs(e))>0&&(e=e<0?0-_:_)}}}break}default:{const v=e<0?f:d,y=n[v];ui(y,`Panel constraints not found for index ${v}`);const b=l[v],{collapsible:S,collapsedSize:w,minSize:k}=y;if(S&&bv(b,k)<0)if(e>0){const _=k-w,C=_/2,E=b+e;bv(E,k)<0&&(e=bv(e,C)<=0?0:_)}else{const _=k-w,C=100-_/2,E=b-e;bv(E,k)<0&&(e=bv(100+e,C)>0?0:-_)}break}}{const v=e<0?1:-1;let y=e<0?f:d,b=0;for(;;){const w=l[y];ui(w!=null,`Previous layout not found for panel index ${y}`);const k=ZE({overrideDisabledPanels:i,panelConstraints:n[y],prevSize:w,size:100})-w;if(b+=k,y+=v,y<0||y>=n.length)break}const S=Math.min(Math.abs(e),Math.abs(b));e=e<0?0-S:S}{let v=e<0?d:f;for(;v>=0&&v<n.length;){const y=Math.abs(e)-Math.abs(p),b=l[v];ui(b!=null,`Previous layout not found for panel index ${v}`);const S=b-y,w=ZE({overrideDisabledPanels:i,panelConstraints:n[v],prevSize:b,size:S});if(!_u(b,w)&&(p+=b-w,u[v]=w,p.toFixed(3).localeCompare(Math.abs(e).toFixed(3),void 0,{numeric:!0})>=0))break;e<0?v--:v++}}if(JGn(c,u))return s;{const v=e<0?f:d,y=l[v];ui(y!=null,`Previous layout not found for panel index ${v}`);const b=y+p,S=ZE({overrideDisabledPanels:i,panelConstraints:n[v],prevSize:y,size:b});if(u[v]=S,!_u(S,b)){let w=b-S,k=e<0?f:d;for(;k>=0&&k<n.length;){const _=u[k];ui(_!=null,`Previous layout not found for panel index ${k}`);const C=_+w,E=ZE({overrideDisabledPanels:i,panelConstraints:n[k],prevSize:_,size:C});if(_u(_,E)||(w-=E-_,u[k]=E),_u(w,0))break;e>0?k--:k++}}}const h=Object.values(u).reduce((v,y)=>y+v,0);if(!_u(h,100,.1))return s;const m=Object.keys(s);return u.reduce((v,y,b)=>(v[m[b]]=y,v),{})}function FO(e,t){if(Object.keys(e).length!==Object.keys(t).length)return!1;for(const n in e)if(t[n]===void 0||bv(e[n],t[n])!==0)return!1;return!0}function zO({layout:e,panelConstraints:t}){const n=Object.values(e),r=[...n],s=r.reduce((l,c)=>l+c,0);if(r.length!==t.length)throw Error(`Invalid ${t.length} panel layout: ${r.map(l=>`${l}%`).join(", ")}`);if(!_u(s,100)&&r.length>0)for(let l=0;l<t.length;l++){const c=r[l];ui(c!=null,`No layout data found for index ${l}`);const u=100/s*c;r[l]=u}let a=0;for(let l=0;l<t.length;l++){const c=n[l];ui(c!=null,`No layout data found for index ${l}`);const u=r[l];ui(u!=null,`No layout data found for index ${l}`);const d=ZE({overrideDisabledPanels:!0,panelConstraints:t[l],prevSize:c,size:u});u!=d&&(a+=u-d,r[l]=d)}if(!_u(a,0))for(let l=0;l<t.length;l++){const c=r[l];ui(c!=null,`No layout data found for index ${l}`);const u=c+a,d=ZE({overrideDisabledPanels:!0,panelConstraints:t[l],prevSize:c,size:u});if(c!==d&&(a-=d-c,r[l]=d,_u(a,0)))break}const i=Object.keys(e);return r.reduce((l,c,u)=>(l[i[u]]=c,l),{})}function i1t({groupId:e,panelId:t}){const n=()=>{const c=R_();for(const[u,{defaultLayoutDeferred:d,derivedPanelConstraints:f,layout:p,groupSize:h,separatorToPanels:m}]of c)if(u.id===e)return{defaultLayoutDeferred:d,derivedPanelConstraints:f,group:u,groupSize:h,layout:p,separatorToPanels:m};throw Error(`Group ${e} not found`)},r=()=>{const c=n().derivedPanelConstraints.find(u=>u.panelId===t);if(c!==void 0)return c;throw Error(`Panel constraints not found for Panel ${t}`)},s=()=>{const c=n().group.panels.find(u=>u.id===t);if(c!==void 0)return c;throw Error(`Layout not found for Panel ${t}`)},a=()=>{const c=n().layout[t];if(c!==void 0)return c;throw Error(`Layout not found for Panel ${t}`)},i=({nextSize:c,panels:u,prevLayout:d,derivedPanelConstraints:f})=>{const p=a(),h=u.findIndex(y=>y.id===t),m=h===0,v=h===u.length-1;if(v&&c<p&&(m||u.slice(0,h).every((y,b)=>{const S=f[b];return S?.collapsible&&_u(S.collapsedSize,d[S.panelId])}))){const y=u.slice(0,h).reduce((b,S)=>b+d[S.id],0);return{...d,[t]:hd(100-y)}}return uM({delta:v?p-c:c-p,initialLayout:d,panelConstraints:f,pivotIndices:v?[h-1,h]:[h,h+1],prevLayout:d,trigger:"imperative-api"})},l=c=>{const u=a();if(c===u)return;const{defaultLayoutDeferred:d,derivedPanelConstraints:f,group:p,groupSize:h,layout:m,separatorToPanels:v}=n(),y=i({nextSize:c,panels:p.panels,prevLayout:m,derivedPanelConstraints:f}),b=zO({layout:y,panelConstraints:f});FO(m,b)||Ex(p,{defaultLayoutDeferred:d,derivedPanelConstraints:f,groupSize:h,layout:b,separatorToPanels:v})};return{collapse:()=>{const{collapsible:c,collapsedSize:u}=r(),{mutableValues:d}=s(),f=a();c&&f!==u&&(d.expandToSize=f,l(u))},expand:()=>{const{collapsible:c,collapsedSize:u,minSize:d}=r(),{mutableValues:f}=s(),p=a();if(c&&p===u){let h=f.expandToSize??d;h===0&&(h=1),l(h)}},getSize:()=>{const{group:c}=n(),u=a(),{element:d}=s(),f=c.orientation==="horizontal"?d.offsetWidth:d.offsetHeight;return{asPercentage:u,inPixels:f}},isCollapsed:()=>{const{collapsible:c,collapsedSize:u}=r(),d=a();return c&&_u(u,d)},resize:c=>{const{group:u}=n(),{element:d}=s(),f=jT({group:u}),p=f2({groupSize:f,panelElement:d,styleProp:c}),h=hd(p/f*100);l(h)}}}function IFe(e){if(e.defaultPrevented)return;const t=R_();M1e(e,t).forEach(n=>{if(n.separator&&!n.separator.disableDoubleClick){const r=n.panels.find(s=>s.panelConstraints.defaultSize!==void 0);if(r){const s=r.panelConstraints.defaultSize,a=i1t({groupId:n.group.id,panelId:r.id});a&&s!==void 0&&(a.resize(s),e.preventDefault())}}})}function s8(e){const t=R_();for(const[n]of t)if(n.separators.some(r=>r.element===e))return n;throw Error("Could not find parent Group for separator element")}function o1t({groupId:e}){const t=()=>{const n=R_();for(const[r,s]of n)if(r.id===e)return{group:r,...s};throw Error(`Could not find Group with id "${e}"`)};return{getLayout(){const{defaultLayoutDeferred:n,layout:r}=t();return n?{}:r},setLayout(n){const{defaultLayoutDeferred:r,derivedPanelConstraints:s,group:a,groupSize:i,layout:l,separatorToPanels:c}=t(),u=zO({layout:n,panelConstraints:s});return r?l:(FO(l,u)||Ex(a,{defaultLayoutDeferred:r,derivedPanelConstraints:s,groupSize:i,layout:u,separatorToPanels:c}),u)}}}function $S(e,t){const n=s8(e),r=Mw(n.id,!0),s=n.separators.find(d=>d.element===e);ui(s,"Matching separator not found");const a=r.separatorToPanels.get(s);ui(a,"Matching panels not found");const i=a.map(d=>n.panels.indexOf(d)),l=o1t({groupId:n.id}).getLayout(),c=uM({delta:t,initialLayout:l,panelConstraints:r.derivedPanelConstraints,pivotIndices:i,prevLayout:l,trigger:"keyboard"}),u=zO({layout:c,panelConstraints:r.derivedPanelConstraints});FO(l,u)||Ex(n,{defaultLayoutDeferred:r.defaultLayoutDeferred,derivedPanelConstraints:r.derivedPanelConstraints,groupSize:r.groupSize,layout:u,separatorToPanels:r.separatorToPanels})}function AFe(e){if(e.defaultPrevented)return;const t=e.currentTarget,n=s8(t);if(!n.disabled)switch(e.key){case"ArrowDown":{e.preventDefault(),n.orientation==="vertical"&&$S(t,5);break}case"ArrowLeft":{e.preventDefault(),n.orientation==="horizontal"&&$S(t,-5);break}case"ArrowRight":{e.preventDefault(),n.orientation==="horizontal"&&$S(t,5);break}case"ArrowUp":{e.preventDefault(),n.orientation==="vertical"&&$S(t,-5);break}case"End":{e.preventDefault(),$S(t,100);break}case"Enter":{e.preventDefault();const r=s8(t),s=Mw(r.id,!0),{derivedPanelConstraints:a,layout:i,separatorToPanels:l}=s,c=r.separators.find(p=>p.element===t);ui(c,"Matching separator not found");const u=l.get(c);ui(u,"Matching panels not found");const d=u[0],f=a.find(p=>p.panelId===d.id);if(ui(f,"Panel metadata not found"),f.collapsible){const p=i[d.id],h=f.collapsedSize===p?r.mutableState.expandedPanelSizes[d.id]??f.minSize:f.collapsedSize;$S(t,h-p)}break}case"F6":{e.preventDefault();const r=s8(t).separators.map(i=>i.element),s=Array.from(r).findIndex(i=>i===e.currentTarget);ui(s!==null,"Index not found");const a=e.shiftKey?s>0?s-1:r.length-1:s+1<r.length?s+1:0;r[a].focus({preventScroll:!0});break}case"Home":{e.preventDefault(),$S(t,-100);break}}}let Ej={cursorFlags:0,state:"inactive"};const D1e=new r1t;function BO(){return Ej}function eQn(e){return D1e.addListener("change",e)}function tQn(e){const t=Ej,n={...Ej};n.cursorFlags=e,Ej=n,D1e.emit("change",{prev:t,next:n})}function jj(e){const t=Ej;Ej=e,D1e.emit("change",{prev:t,next:e})}function RFe(e){if(e.defaultPrevented||e.pointerType==="mouse"&&e.button>0)return;const t=R_(),n=M1e(e,t),r=new Map;let s=!1;n.forEach(a=>{a.separator&&(s||(s=!0,a.separator.element.focus({focusVisible:!1,preventScroll:!0})));const i=t.get(a.group);i&&r.set(a.group,i.layout)}),jj({cursorFlags:0,hitRegions:n,initialLayoutMap:r,pointerDownAtPoint:{x:e.clientX,y:e.clientY},state:"active"}),n.length&&e.preventDefault()}const nQn=e=>e,nee=()=>{},l1t=1,c1t=2,u1t=4,d1t=8,PFe=3,$Fe=12;let P6;function MFe(){return P6===void 0&&(P6=!1,typeof window<"u"&&(window.navigator.userAgent.includes("Chrome")||window.navigator.userAgent.includes("Firefox"))&&(P6=!0)),P6}function rQn({cursorFlags:e,groups:t,state:n}){let r=0,s=0;switch(n){case"active":case"hover":t.forEach(a=>{if(!a.mutableState.disableCursor)switch(a.orientation){case"horizontal":{r++;break}case"vertical":{s++;break}}})}if(!(r===0&&s===0)){switch(n){case"active":{if(e&&MFe()){const a=(e&l1t)!==0,i=(e&c1t)!==0,l=(e&u1t)!==0,c=(e&d1t)!==0;if(a)return l?"se-resize":c?"ne-resize":"e-resize";if(i)return l?"sw-resize":c?"nw-resize":"w-resize";if(l)return"s-resize";if(c)return"n-resize"}break}}return MFe()?r>0&&s>0?"move":r>0?"ew-resize":"ns-resize":r>0&&s>0?"grab":r>0?"col-resize":"row-resize"}}const DFe=new WeakMap;function L1e(e){if(e.defaultView===null||e.defaultView===void 0)return;let{prevStyle:t,styleSheet:n}=DFe.get(e)??{};n===void 0&&(n=new e.defaultView.CSSStyleSheet,e.adoptedStyleSheets&&(Object.isExtensible(e.adoptedStyleSheets)?e.adoptedStyleSheets.push(n):e.adoptedStyleSheets=[...e.adoptedStyleSheets,n]));const r=BO();switch(r.state){case"active":case"hover":{const s=rQn({cursorFlags:r.cursorFlags,groups:r.hitRegions.map(i=>i.group),state:r.state}),a=`*, *:hover {cursor: ${s} !important; }`;if(t===a)return;t=a,s?n.cssRules.length===0?n.insertRule(a):n.replaceSync(a):n.cssRules.length===1&&n.deleteRule(0);break}case"inactive":{t=void 0,n.cssRules.length===1&&n.deleteRule(0);break}}DFe.set(e,{prevStyle:t,styleSheet:n})}function f1t({document:e,event:t,hitRegions:n,initialLayoutMap:r,mountedGroups:s,pointerDownAtPoint:a,prevCursorFlags:i}){let l=0;n.forEach(u=>{const{group:d,groupSize:f}=u,{orientation:p,panels:h}=d,{disableCursor:m}=d.mutableState;let v=0;a?p==="horizontal"?v=(t.clientX-a.x)/f*100:v=(t.clientY-a.y)/f*100:p==="horizontal"?v=t.clientX<0?-100:100:v=t.clientY<0?-100:100;const y=r.get(d),b=s.get(d);if(!y||!b)return;const{defaultLayoutDeferred:S,derivedPanelConstraints:w,groupSize:k,layout:_,separatorToPanels:C}=b;if(w&&_&&C){const E=uM({delta:v,initialLayout:y,panelConstraints:w,pivotIndices:u.panels.map(j=>h.indexOf(j)),prevLayout:_,trigger:"mouse-or-touch"});if(FO(E,_)){if(v!==0&&!m)switch(p){case"horizontal":{l|=v<0?l1t:c1t;break}case"vertical":{l|=v<0?u1t:d1t;break}}}else Ex(u.group,{defaultLayoutDeferred:S,derivedPanelConstraints:w,groupSize:k,layout:E,separatorToPanels:C})}});let c=0;t.movementX===0?c|=i&PFe:c|=l&PFe,t.movementY===0?c|=i&$Fe:c|=l&$Fe,tQn(c),L1e(e)}function LFe(e){const t=R_(),n=BO();n.state==="active"&&f1t({document:e.currentTarget,event:e,hitRegions:n.hitRegions,initialLayoutMap:n.initialLayoutMap,mountedGroups:t,prevCursorFlags:n.cursorFlags})}function FFe(e){if(e.defaultPrevented)return;const t=BO(),n=R_();switch(t.state){case"active":{if(e.buttons===0){jj({cursorFlags:0,state:"inactive"}),t.hitRegions.forEach(r=>{const s=Mw(r.group.id,!0);Ex(r.group,s)});return}for(const r of t.hitRegions)if(r.separator){const{element:s}=r.separator;s.hasPointerCapture?.(e.pointerId)||s.setPointerCapture?.(e.pointerId)}f1t({document:e.currentTarget,event:e,hitRegions:t.hitRegions,initialLayoutMap:t.initialLayoutMap,mountedGroups:n,pointerDownAtPoint:t.pointerDownAtPoint,prevCursorFlags:t.cursorFlags});break}default:{const r=M1e(e,n);r.length===0?t.state!=="inactive"&&jj({cursorFlags:0,state:"inactive"}):jj({cursorFlags:0,hitRegions:r,state:"hover"}),L1e(e.currentTarget);break}}}function zFe(e){e.relatedTarget instanceof HTMLIFrameElement&&BO().state==="hover"&&jj({cursorFlags:0,state:"inactive"})}function BFe(e){if(e.defaultPrevented||e.pointerType==="mouse"&&e.button>0)return;const t=BO();t.state==="active"&&(jj({cursorFlags:0,state:"inactive"}),t.hitRegions.length>0&&(L1e(e.currentTarget),t.hitRegions.forEach(n=>{const r=Mw(n.group.id,!0);Ex(n.group,r)}),e.preventDefault()))}function UFe(e){let t=0,n=0;const r={};for(const a of e)if(a.defaultSize!==void 0){t++;const i=hd(a.defaultSize);n+=i,r[a.panelId]=i}else r[a.panelId]=void 0;const s=e.length-t;if(s!==0){const a=hd((100-n)/s);for(const i of e)i.defaultSize===void 0&&(r[i.panelId]=a)}return r}function sQn(e,t,n){if(!n[0])return;const r=e.panels.find(c=>c.element===t);if(!r||!r.onResize)return;const s=jT({group:e}),a=e.orientation==="horizontal"?r.element.offsetWidth:r.element.offsetHeight,i=r.mutableValues.prevSize,l={asPercentage:hd(a/s*100),inPixels:a};r.mutableValues.prevSize=l,r.onResize(l,r.id,i)}function aQn(e,t){if(Object.keys(e).length!==Object.keys(t).length)return!1;for(const n in e)if(e[n]!==t[n])return!1;return!0}function iQn({group:e,nextGroupSize:t,prevGroupSize:n,prevLayout:r}){if(n<=0||t<=0||n===t)return r;let s=0,a=0,i=!1;const l=new Map,c=[];for(const f of e.panels){const p=r[f.id]??0;if(f.panelConstraints.groupResizeBehavior==="preserve-pixel-size"){i=!0;const h=p/100*n,m=hd(h/t*100);l.set(f.id,m),s+=m}else c.push(f.id),a+=p}if(!i||c.length===0)return r;const u=100-s,d={...r};if(l.forEach((f,p)=>{d[p]=f}),a>0)for(const f of c){const p=r[f]??0;d[f]=hd(p/a*u)}else{const f=hd(u/c.length);for(const p of c)d[p]=f}return d}function oQn(e,t){const n=e.map(s=>s.id),r=Object.keys(t);if(n.length!==r.length)return!1;for(const s of n)if(!r.includes(s))return!1;return!0}const VC=new Map;function lQn(e){let t=!0;ui(e.element.ownerDocument.defaultView,"Cannot register an unmounted Group");const n=e.element.ownerDocument.defaultView.ResizeObserver,r=new Set,s=new Set,a=new n(m=>{for(const v of m){const{borderBoxSize:y,target:b}=v;if(b===e.element){if(t){const S=jT({group:e});if(S===0)return;const w=Mw(e.id);if(!w)return;const k=zhe(e),_=w.defaultLayoutDeferred?UFe(k):w.layout,C=iQn({group:e,nextGroupSize:S,prevGroupSize:w.groupSize,prevLayout:_}),E=zO({layout:C,panelConstraints:k});if(!w.defaultLayoutDeferred&&FO(w.layout,E)&&aQn(w.derivedPanelConstraints,k)&&w.groupSize===S)return;Ex(e,{defaultLayoutDeferred:!1,derivedPanelConstraints:k,groupSize:S,layout:E,separatorToPanels:w.separatorToPanels})}}else sQn(e,b,y)}});a.observe(e.element),e.panels.forEach(m=>{ui(!r.has(m.id),`Panel ids must be unique; id "${m.id}" was used more than once`),r.add(m.id),m.onResize&&a.observe(m.element)});const i=jT({group:e}),l=zhe(e),c=e.panels.map(({id:m})=>m).join(",");let u=e.mutableState.defaultLayout;u&&(oQn(e.panels,u)||(u=void 0));const d=e.mutableState.layouts[c]??u??UFe(l),f=zO({layout:d,panelConstraints:l}),p=e.element.ownerDocument;VC.set(p,(VC.get(p)??0)+1);const h=new Map;return n1t(e).forEach(m=>{m.separator&&h.set(m.separator,m.panels)}),Ex(e,{defaultLayoutDeferred:i===0,derivedPanelConstraints:l,groupSize:i,layout:f,separatorToPanels:h}),e.separators.forEach(m=>{ui(!s.has(m.id),`Separator ids must be unique; id "${m.id}" was used more than once`),s.add(m.id),m.element.addEventListener("keydown",AFe)}),VC.get(p)===1&&(p.addEventListener("dblclick",IFe,!0),p.addEventListener("pointerdown",RFe,!0),p.addEventListener("pointerleave",LFe),p.addEventListener("pointermove",FFe),p.addEventListener("pointerout",zFe),p.addEventListener("pointerup",BFe,!0)),function(){t=!1,VC.set(p,Math.max(0,(VC.get(p)??0)-1)),VGn(e),e.separators.forEach(m=>{m.element.removeEventListener("keydown",AFe)}),VC.get(p)||(p.removeEventListener("dblclick",IFe,!0),p.removeEventListener("pointerdown",RFe,!0),p.removeEventListener("pointerleave",LFe),p.removeEventListener("pointermove",FFe),p.removeEventListener("pointerout",zFe),p.removeEventListener("pointerup",BFe,!0)),a.disconnect()}}function cQn(){const[e,t]=g.useState({}),n=g.useCallback(()=>t({}),[]);return[e,n]}function F1e(e){const t=g.useId();return`${e??t}`}const P_=typeof window<"u"?g.useLayoutEffect:g.useEffect;function H2(e){const t=g.useRef(e);return P_(()=>{t.current=e},[e]),g.useCallback((...n)=>t.current?.(...n),[t])}function z1e(...e){return H2(t=>{e.forEach(n=>{if(n)switch(typeof n){case"function":{n(t);break}case"object":{n.current=t;break}}})})}function B1e(e){const t=g.useRef({...e});return P_(()=>{for(const n in e)t.current[n]=e[n]},[e]),t.current}const p1t=g.createContext(null);function uQn(e,t){const n=g.useRef({getLayout:()=>({}),setLayout:nQn});g.useImperativeHandle(t,()=>n.current,[]),P_(()=>{Object.assign(n.current,o1t({groupId:e}))})}function dM({children:e,className:t,defaultLayout:n,disableCursor:r,disabled:s,elementRef:a,groupRef:i,id:l,onLayoutChange:c,onLayoutChanged:u,orientation:d="horizontal",resizeTargetMinimumSize:f={coarse:20,fine:10},style:p,...h}){const m=g.useRef({onLayoutChange:{},onLayoutChanged:{}}),v=H2(R=>{FO(m.current.onLayoutChange,R)||(m.current.onLayoutChange=R,c?.(R))}),y=H2(R=>{FO(m.current.onLayoutChanged,R)||(m.current.onLayoutChanged=R,u?.(R))}),b=F1e(l),S=g.useRef(null),[w,k]=cQn(),_=g.useRef({lastExpandedPanelSizes:{},layouts:{},panels:[],resizeTargetMinimumSize:f,separators:[]}),C=z1e(S,a);uQn(b,i);const E=H2((R,P)=>{const L=BO(),M=EFe(R),q=Mw(R);if(q){let H=!1;return L.state==="active"&&(H=L.hitRegions.some(F=>F.group===M)),{flexGrow:q.layout[P]??1,pointerEvents:H?"none":void 0}}if(n?.[P])return{flexGrow:n?.[P]}}),j=B1e({defaultLayout:n,disableCursor:r}),N=g.useMemo(()=>({get disableCursor(){return!!j.disableCursor},getPanelStyles:E,id:b,orientation:d,registerPanel:R=>{const P=_.current;return P.panels=Bhe(d,[...P.panels,R]),k(),()=>{P.panels=P.panels.filter(L=>L!==R),k()}},registerSeparator:R=>{const P=_.current;return P.separators=Bhe(d,[...P.separators,R]),k(),()=>{P.separators=P.separators.filter(L=>L!==R),k()}},updatePanelProps:(R,{disabled:P})=>{const L=_.current.panels.find(H=>H.id===R);L&&(L.panelConstraints.disabled=P);const M=EFe(b),q=Mw(b);M&&q&&Ex(M,{...q,derivedPanelConstraints:zhe(M)})},updateSeparatorProps:(R,{disabled:P,disableDoubleClick:L})=>{const M=_.current.separators.find(q=>q.id===R);M&&(M.disabled=P,M.disableDoubleClick=L)}}),[E,b,k,d,j]),I=g.useRef(null);return P_(()=>{const R=S.current;if(R===null)return;const P=_.current;let L;if(j.defaultLayout!==void 0&&Object.keys(j.defaultLayout).length===P.panels.length){L={};for(const D of P.panels){const Q=j.defaultLayout[D.id];Q!==void 0&&(L[D.id]=Q)}}const M={disabled:!!s,element:R,id:b,mutableState:{defaultLayout:L,disableCursor:!!j.disableCursor,expandedPanelSizes:_.current.lastExpandedPanelSizes,layouts:_.current.layouts},orientation:d,panels:P.panels,resizeTargetMinimumSize:P.resizeTargetMinimumSize,separators:P.separators};I.current=M;const q=lQn(M),{defaultLayoutDeferred:H,derivedPanelConstraints:F,layout:z}=Mw(M.id,!0);!H&&F.length>0&&(v(z),y(z));const B=$1e(b,D=>{const{defaultLayoutDeferred:Q,derivedPanelConstraints:V,layout:$}=D.next;if(Q||V.length===0)return;const U=M.panels.map(({id:X})=>X).join(",");M.mutableState.layouts[U]=$,V.forEach(X=>{if(X.collapsible){const{layout:te}=D.prev??{};if(te){const J=_u(X.collapsedSize,$[X.panelId]),ee=_u(X.collapsedSize,te[X.panelId]);J&&!ee&&(M.mutableState.expandedPanelSizes[X.panelId]=te[X.panelId])}}});const Z=BO().state!=="active";v($),Z&&y($)});return()=>{I.current=null,q(),B()}},[s,b,y,v,d,w,j]),g.useEffect(()=>{const R=I.current;R&&(R.mutableState.defaultLayout=n,R.mutableState.disableCursor=!!r)}),o.jsx(p1t.Provider,{value:N,children:o.jsx("div",{...h,className:t,"data-group":!0,"data-testid":b,id:b,ref:C,style:{height:"100%",width:"100%",overflow:"hidden",...p,display:"flex",flexDirection:d==="horizontal"?"row":"column",flexWrap:"nowrap",touchAction:d==="horizontal"?"pan-y":"pan-x"},children:e})})}dM.displayName="Group";function a8(e,t){return`react-resizable-panels:${[e,...t].join(":")}`}function dQn({id:e,panelIds:t,storage:n}){const r=a8(e,[]),s=n.getItem(r);if(s)try{const a=JSON.parse(s);if(t){const i=t.join(","),l=a[i];if(l&&Array.isArray(l.layout)&&t.length===l.layout.length){const c={};for(let u=0;u<t.length;u++)c[t[u]]=l.layout[u];return c}}else{const i=Object.keys(a);if(i.length===1){const l=a[i[0]];if(l&&Array.isArray(l.layout)){const c=i[0].split(",");if(c.length===l.layout.length){const u={};for(let d=0;d<c.length;d++)u[c[d]]=l.layout[d];return u}}}}}catch{}}function h1t({debounceSaveMs:e=100,panelIds:t,storage:n=localStorage,...r}){const s=t!==void 0,a="id"in r?r.id:r.groupId,i=a8(a,t??[]),l=g.useSyncExternalStore(fQn,()=>n.getItem(i),()=>n.getItem(i)),c=g.useMemo(()=>{if(l){const v=JSON.parse(l),y=Object.values(v);if(Array.from(y).every(b=>typeof b=="number"))return v}},[l]),u=g.useMemo(()=>{if(!c)return dQn({id:a,panelIds:t,storage:n})},[c,a,t,n]),d=c??u,f=g.useRef(null),p=g.useCallback(()=>{const v=f.current;v&&(f.current=null,clearTimeout(v))},[]);g.useLayoutEffect(()=>()=>{p()},[p]);const h=g.useCallback(v=>{p();let y;s?y=a8(a,Object.keys(v)):y=a8(a,[]);try{n.setItem(y,JSON.stringify(v))}catch(b){console.error(b)}},[p,s,a,n]),m=g.useCallback(v=>{p(),e===0?h(v):f.current=setTimeout(()=>{h(v)},e)},[p,e,h]);return{defaultLayout:d,onLayoutChange:m,onLayoutChanged:h}}function fQn(){return function(){}}function U1e(){const e=g.useContext(p1t);return ui(e,"Group Context not found; did you render a Panel or Separator outside of a Group?"),e}function pQn(e,t){const{id:n}=U1e(),r=g.useRef({collapse:nee,expand:nee,getSize:()=>({asPercentage:0,inPixels:0}),isCollapsed:()=>!1,resize:nee});g.useImperativeHandle(t,()=>r.current,[]),P_(()=>{Object.assign(r.current,i1t({groupId:n,panelId:e}))})}function Dw({children:e,className:t,collapsedSize:n="0%",collapsible:r=!1,defaultSize:s,disabled:a,elementRef:i,groupResizeBehavior:l="preserve-relative-size",id:c,maxSize:u="100%",minSize:d="0%",onResize:f,panelRef:p,style:h,...m}){const v=!!c,y=F1e(c),b=B1e({disabled:a}),S=g.useRef(null),w=z1e(S,i),{getPanelStyles:k,id:_,orientation:C,registerPanel:E,updatePanelProps:j}=U1e(),N=f!==null,I=H2((M,q,H)=>{f?.(M,c,H)});P_(()=>{const M=S.current;if(M!==null){const q={element:M,id:y,idIsStable:v,mutableValues:{expandToSize:void 0,prevSize:void 0},onResize:N?I:void 0,panelConstraints:{groupResizeBehavior:l,collapsedSize:n,collapsible:r,defaultSize:s,disabled:b.disabled,maxSize:u,minSize:d}};return E(q)}},[l,n,r,s,N,y,v,u,d,I,E,b]),g.useEffect(()=>{j(y,{disabled:a})},[a,y,j]),pQn(y,p);const R=()=>{const M=k(_,y);if(M)return JSON.stringify(M)},P=g.useSyncExternalStore(M=>$1e(_,M),R,R);let L;return P?L=JSON.parse(P):s?L={flexGrow:void 0,flexShrink:void 0,flexBasis:s}:L={flexGrow:1},o.jsx("div",{...m,"data-disabled":a||void 0,"data-panel":!0,"data-testid":y,id:y,ref:w,style:{...hQn,display:"flex",flexBasis:0,flexShrink:1,overflow:"visible",...L},children:o.jsx("div",{className:t,style:{maxHeight:"100%",maxWidth:"100%",flexGrow:1,overflow:"auto",...h,touchAction:C==="horizontal"?"pan-y":"pan-x"},children:e})})}Dw.displayName="Panel";const hQn={minHeight:0,maxHeight:"100%",height:"auto",minWidth:0,maxWidth:"100%",width:"auto",border:"none",borderWidth:0,padding:0,margin:0};function mQn(){return g.useRef(null)}function gQn({layout:e,panelConstraints:t,panelId:n,panelIndex:r}){let s,a;const i=e[n],l=t.find(c=>c.panelId===n);if(l){const c=l.maxSize,u=l.collapsible?l.collapsedSize:l.minSize,d=[r,r+1];a=zO({layout:uM({delta:u-i,initialLayout:e,panelConstraints:t,pivotIndices:d,prevLayout:e}),panelConstraints:t})[n],s=zO({layout:uM({delta:c-i,initialLayout:e,panelConstraints:t,pivotIndices:d,prevLayout:e}),panelConstraints:t})[n]}return{valueControls:n,valueMax:s,valueMin:a,valueNow:i}}function m1t({children:e,className:t,disabled:n,disableDoubleClick:r,elementRef:s,id:a,style:i,...l}){const c=F1e(a),u=B1e({disabled:n,disableDoubleClick:r}),[d,f]=g.useState({}),[p,h]=g.useState("inactive"),[m,v]=g.useState(!1),y=g.useRef(null),b=z1e(y,s),{disableCursor:S,id:w,orientation:k,registerSeparator:_,updateSeparatorProps:C}=U1e(),E=k==="horizontal"?"vertical":"horizontal";P_(()=>{const I=y.current;if(I!==null){const R={disabled:u.disabled,disableDoubleClick:u.disableDoubleClick,element:I,id:c},P=_(R),L=eQn(q=>{h(q.next.state!=="inactive"&&q.next.hitRegions.some(H=>H.separator===R)?q.next.state:"inactive")}),M=$1e(w,q=>{const{derivedPanelConstraints:H,layout:F,separatorToPanels:z}=q.next,B=z.get(R);if(B){const D=B[0],Q=B.indexOf(D);f(gQn({layout:F,panelConstraints:H,panelId:D.id,panelIndex:Q}))}});return()=>{L(),M(),P()}}},[w,c,_,u]),g.useEffect(()=>{C(c,{disabled:n,disableDoubleClick:r})},[n,r,c,C]);let j;n&&!S&&(j="not-allowed");let N;return n?N="disabled":p==="active"?N="active":m?N="focus":N=p,o.jsx("div",{...l,"aria-controls":d.valueControls,"aria-disabled":n||void 0,"aria-orientation":E,"aria-valuemax":d.valueMax,"aria-valuemin":d.valueMin,"aria-valuenow":d.valueNow,children:e,className:t,"data-separator":N,"data-testid":c,id:c,onBlur:()=>v(!1),onFocus:()=>v(!0),ref:b,role:"separator",style:{flexBasis:"auto",cursor:j,...i,flexGrow:0,flexShrink:0,touchAction:"none"},tabIndex:n?void 0:0})}m1t.displayName="Separator";const g1t=({side:e})=>o.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[o.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"5"}),o.jsx("path",{d:e==="left"?"M9 3v18":"M15 3v18"})]}),v1t=K("flex size-8 cursor-pointer items-center justify-center rounded-full","border border-transparent bg-transparent text-neutral5 hover:bg-neutral6/5 hover:text-neutral6 active:bg-neutral6/10","transition-colors duration-150 ease-out-custom motion-reduce:transition-none","focus-visible:outline-hidden focus-visible:border-accent1"),vQn=(e,t,n)=>Math.min(n,Math.max(t,e)),yQn=(e,t,n)=>({client:e.clientY,start:t.top,size:t.height}),bQn=(e,t,n,r=0)=>{const{client:s,start:a,size:i}=yQn(e,t);return vQn(s-a,r,Math.max(r,i-r))},xQn=({axis:e,margin:t=0,variableName:n})=>{const r=g.useRef(null),s=g.useRef(null),a=g.useCallback((u,d=!1)=>{const f=r.current;if(!f)return;const p=d||!s.current?f.getBoundingClientRect():s.current;s.current=p;const h=bQn(u,p,e,t);f.style.setProperty(n,`${h}px`)},[e,t,n]),i=g.useCallback(u=>{a(u,!0)},[a]),l=g.useCallback(u=>{a(u)},[a]),c=g.useCallback(()=>{s.current=null},[]);return{beginTracking:i,elementRef:r,endTracking:c,updateTracking:l}},wQn=22,SQn=e=>{const[t,n]=g.useState(!1),r=g.useRef(!1),s=g.useRef(!1),a=g.useRef(()=>{}),i=g.useCallback(()=>{a.current()},[]),l=g.useCallback(()=>{s.current||(s.current=!0,requestAnimationFrame(()=>{r.current=!0,n(!0),a.current()}))},[]);return g.useEffect(()=>{if(window.matchMedia("(prefers-reduced-motion: reduce)").matches)return;const c=e.current?.parentElement;if(!c)return;const u=Array.from(c.children).filter(h=>h instanceof HTMLElement&&h.hasAttribute("data-panel")),d=Array.from(c.children).filter(h=>h instanceof HTMLElement&&h.hasAttribute("data-separator")),f=()=>{r.current&&u.forEach(h=>h.style.transition="flex-grow 300ms var(--ease-out-custom, ease), flex-basis 300ms var(--ease-out-custom, ease)")},p=()=>u.forEach(h=>h.style.transition="none");return f(),a.current=f,d.forEach(h=>h.addEventListener("pointerdown",p)),window.addEventListener("pointerup",f),window.addEventListener("pointercancel",f),()=>{a.current=()=>{},d.forEach(h=>h.removeEventListener("pointerdown",p)),window.removeEventListener("pointerup",f),window.removeEventListener("pointercancel",f),u.forEach(h=>h.style.transition="")}},[e]),{booted:t,boot:l,enableSizeTransitions:i}},kQn=({collapsed:e,direction:t,elementRef:n})=>{const r=g.useRef(null),s=g.useRef(null),{beginTracking:a,elementRef:i,endTracking:l,updateTracking:c}=xQn({axis:"y",margin:wQn,variableName:"--pill-y"}),u=g.useCallback(p=>{const h=r.current,m=s.current;h&&(h.dataset.edgeHovered=p?"true":"false"),m&&(m.dataset.edgeHovered=p?"true":"false")},[]),d=g.useCallback(p=>{const h=s.current;h&&(a(p),h.style.transitionProperty="opacity, translate",requestAnimationFrame(()=>{h.style.transitionProperty=""}))},[a]),f=g.useCallback(p=>{c(p)},[c]);return g.useEffect(()=>{if(!e)return;const p=n.current,h=t==="left"?p?.nextElementSibling:p?.previousElementSibling;if(!(h instanceof HTMLElement)||!h.hasAttribute("data-separator"))return;const m=b=>{u(!0),d(b)},v=()=>{u(!1),l()},y=b=>f(b);return h.addEventListener("pointerenter",m),h.addEventListener("pointerleave",v),h.addEventListener("pointermove",y),()=>{h.removeEventListener("pointerenter",m),h.removeEventListener("pointerleave",v),h.removeEventListener("pointermove",y),u(!1),l()}},[e,t,n,l,u,d,f]),{endPillTracking:l,expandButtonRef:r,stripRef:i,pillRef:s,spawnPill:d,trackPillPosition:f}},Uhe=({collapsedSize:e,children:t,direction:n,className:r,onResize:s,style:a,minSize:i,...l})=>{const[c,u]=g.useState(!1),d=mQn(),f=g.useRef(null),{booted:p,boot:h,enableSizeTransitions:m}=SQn(f),{endPillTracking:v,expandButtonRef:y,stripRef:b,pillRef:S,spawnPill:w,trackPillPosition:k}=kQn({collapsed:c,direction:n,elementRef:f}),_=g.useCallback(()=>{m(),d.current&&d.current.expand()},[m,d]),C=typeof i=="number"?i:null;return o.jsxs(Dw,{panelRef:d,elementRef:f,collapsedSize:e,minSize:i,className:K("relative",r),style:{overflow:c?"visible":"hidden","--panel-min-w":C?`${C}px`:void 0,...a},...l,onResize:(E,j,N)=>{s?.(E,j,N),typeof e=="number"&&(u(E.inPixels<=e),h())},children:[o.jsx("div",{inert:c,"data-state":c?"collapsed":"open","data-direction":n,style:{minWidth:"var(--panel-min-w)",opacity:c?0:void 0,translate:c?n==="left"?"-100% 0":"100% 0":void 0},className:K("absolute inset-y-0 w-full overflow-hidden","transition-[opacity,translate] duration-300 ease-out-custom motion-reduce:transition-none","data-[direction=left]:left-0 data-[direction=right]:right-0","data-[state=collapsed]:z-10",!p&&"transition-none"),children:t}),c&&o.jsxs(o.Fragment,{children:[o.jsx("button",{ref:y,type:"button","aria-label":"Expand panel",onClick:_,className:K(v1t,"absolute top-2 z-10","transition-[color,background-color,opacity] duration-300 starting:opacity-0",n==="left"?"left-2":"right-2","data-[edge-hovered=true]:text-neutral6"),children:o.jsx(Ue,{children:o.jsx(g1t,{side:n})})}),o.jsx("button",{ref:b,type:"button",tabIndex:-1,"aria-hidden":"true",onClick:_,onPointerEnter:E=>w(E),onPointerLeave:v,onPointerMove:E=>k(E),style:{"--pill-y":"50%"},className:K("group/expand absolute inset-y-0 z-10 w-4 cursor-pointer focus-visible:outline-hidden",n==="left"?"left-1":"right-1"),children:o.jsx("span",{ref:S,style:{top:"var(--pill-y)"},className:K("absolute flex size-7 -translate-y-1/2 items-center justify-center rounded-full bg-neutral6 text-surface1 shadow-dialog","pointer-events-none opacity-0 transition-[opacity,translate,top] duration-150 ease-out-custom motion-reduce:transition-none",n==="left"?"left-0.5 -translate-x-1":"right-0.5 translate-x-1","group-hover/expand:pointer-events-auto group-hover/expand:translate-x-0 group-hover/expand:opacity-100","group-active/expand:bg-neutral6/80","data-[edge-hovered=true]:pointer-events-auto data-[edge-hovered=true]:translate-x-0 data-[edge-hovered=true]:opacity-100"),children:o.jsx(Ue,{children:n==="left"?o.jsx(o1,{}):o.jsx($xe,{})})})})]})]})};let gc=(function(e){return e.nestedDrawers="--nested-drawers",e.height="--drawer-height",e.frontmostHeight="--drawer-frontmost-height",e.swipeMovementX="--drawer-swipe-movement-x",e.swipeMovementY="--drawer-swipe-movement-y",e.snapPointOffset="--drawer-snap-point-offset",e.swipeStrength="--drawer-swipe-strength",e})({}),Gb=(function(e){return e.swipeProgress="--drawer-swipe-progress",e})({});const OQn={...Ef,...nc},_Qn=g.forwardRef(function(t,n){const{render:r,className:s,style:a,forceRender:i=!1,...l}=t,{store:c}=Td(),u=c.useState("open"),d=c.useState("nested"),f=c.useState("mounted"),p=c.useState("transitionStatus");return En("div",t,{state:{open:u,transitionStatus:p},ref:[c.context.backdropRef,n],stateAttributesMapping:OQn,props:[{role:"presentation",hidden:!f,style:{pointerEvents:u?void 0:"none",userSelect:"none",WebkitUserSelect:"none",[Gb.swipeProgress]:"0",[gc.swipeStrength]:"1"}},l],enabled:i||!d})}),CQn=ZD,y1t="data-drawer-content",EQn=g.forwardRef(function(t,n){const{render:r,className:s,style:a,...i}=t;return Td(),En("div",t,{ref:n,props:[{[y1t]:""},i]})}),jQn=c0e,TQn=g.createContext(void 0);function b1t(e){return g.useContext(TQn)}let ig=(function(e){return e[e.open=fd.open]="open",e[e.closed=fd.closed]="closed",e[e.startingStyle=fd.startingStyle]="startingStyle",e[e.endingStyle=fd.endingStyle]="endingStyle",e.expanded="data-expanded",e.nestedDrawerOpen="data-nested-drawer-open",e.nestedDrawerSwiping="data-nested-drawer-swiping",e.swipeDismiss="data-swipe-dismiss",e.swipeDirection="data-swipe-direction",e.swiping="data-swiping",e})({});const x1t=g.createContext(void 0);function FV(e){const t=g.useContext(x1t);if(e===!1&&t===void 0)throw new Error(Sr(90));return t}function qFe(e,t,n){if(!Number.isFinite(t)||t<=0)return null;if(typeof e=="number")return Number.isFinite(e)?e<=1?Ts(e,0,1)*t:e:null;const r=e.trim();if(r.endsWith("px")){const s=Number.parseFloat(r);return Number.isFinite(s)?s:null}if(r.endsWith("rem")){const s=Number.parseFloat(r);return Number.isFinite(s)?s*n:null}return null}function NQn(e,t){let n=null,r=1/0;for(const s of t){const a=Math.abs(s.height-e);a<r&&(r=a,n=s)}return n}function w1t(){const{store:e}=Td(),{snapPoints:t,activeSnapPoint:n,setActiveSnapPoint:r,popupHeight:s}=FV(),a=e.useState("viewportElement"),[i,l]=g.useState(0),[c,u]=g.useState(16),d=vt(()=>{const m=pr(a).documentElement;a&&l(a.offsetHeight),a||l(m.clientHeight);const v=parseFloat(getComputedStyle(m).fontSize);Number.isFinite(v)&&u(v)});Nt(()=>{if(d(),!a||typeof ResizeObserver!="function")return;const h=new ResizeObserver(d);return h.observe(a),()=>{h.disconnect()}},[d,a]);const f=g.useMemo(()=>{if(!t||t.length===0||i<=0||s<=0)return[];const h=Math.min(s,i);if(!Number.isFinite(h)||h<=0)return[];const m=t.map(b=>{const S=qFe(b,i,c);if(S===null||!Number.isFinite(S))return null;const w=Ts(S,0,h);return{value:b,height:w,offset:Math.max(0,s-w)}}).filter(b=>!!b);if(m.length<=1)return m;const v=[],y=[];for(let b=m.length-1;b>=0;b-=1){const S=m[b];y.some(k=>Math.abs(k-S.height)<=1)||(y.push(S.height),v.push(S))}return v.reverse(),v},[s,c,t,i]),p=g.useMemo(()=>{if(n===void 0)return f[0];if(n===null)return;const h=f.find(b=>Object.is(b.value,n));if(h)return h;const m=Math.min(s,i),v=qFe(n,i,c);if(v===null||!Number.isFinite(v))return;const y=Ts(v,0,m);return NQn(y,f)??void 0},[n,s,f,c,i]);return{snapPoints:t,activeSnapPoint:n,setActiveSnapPoint:r,popupHeight:s,viewportHeight:i,resolvedSnapPoints:f,activeSnapPointOffset:p?.offset??null}}const S1t=g.createContext(null);function IQn(e){return g.useContext(S1t)}let VFe=!1;function AQn(){VFe||(typeof CSS<"u"&&"registerProperty"in CSS&&([gc.swipeMovementX,gc.swipeMovementY,gc.snapPointOffset].forEach(e=>{try{CSS.registerProperty({name:e,syntax:"<length>",inherits:!1,initialValue:"0px"})}catch{}}),[{name:Gb.swipeProgress,initialValue:"0"},{name:gc.swipeStrength,initialValue:"1"}].forEach(({name:e,initialValue:t})=>{try{CSS.registerProperty({name:e,syntax:"<number>",inherits:!1,initialValue:t})}catch{}})),VFe=!0)}const RQn={...Ef,...nc,expanded(e){return e?{[ig.expanded]:""}:null},nestedDrawerOpen(e){return e?{[ig.nestedDrawerOpen]:""}:null},nestedDrawerSwiping(e){return e?{[ig.nestedDrawerSwiping]:""}:null},swipeDirection(e){return e?{[ig.swipeDirection]:e}:null},swiping(e){return e?{[ig.swiping]:""}:null}},PQn=g.forwardRef(function(t,n){const{render:r,className:s,style:a,finalFocus:i,initialFocus:l,...c}=t,{store:u}=Td(),{swipeDirection:d,frontmostHeight:f,hasNestedDrawer:p,nestedSwiping:h,nestedSwipeProgressStore:m,onPopupHeightChange:v,notifyParentFrontmostHeight:y,notifyParentHasNestedDrawer:b}=FV(),S=u.useState("descriptionElementId"),w=u.useState("disablePointerDismissal"),k=u.useState("floatingRootContext"),_=u.useState("popupProps"),C=u.useState("modal"),E=u.useState("mounted"),j=u.useState("nested"),N=u.useState("nestedOpenDrawerCount"),I=u.useState("transitionStatus"),R=u.useState("open"),P=u.useState("openMethod"),L=u.useState("titleElementId"),M=u.useState("role"),q=k.useState("floatingId"),H=c.id??q,F=IQn();u0e();const{snapPoints:z,activeSnapPoint:B,activeSnapPointOffset:D}=w1t(),Q=N>0,V=F?.swiping??!1,$=F?.swipeStrength??null,[U,Z]=g.useState(0),X=g.useRef(0),te=vt(()=>{const ve=u.context.popupRef.current;if(!ve)return;const ye=ve.offsetHeight;if(X.current>0&&f>X.current&&ye>X.current)return;if(X.current>0&&p){const ke=X.current;Z(ke),v(ke);return}const Ne=ye;Ne!==X.current&&(X.current=Ne,Z(Ne),v(Ne))});Nt(()=>{if(!E){X.current=0,Z(0),v(0);return}const ve=u.context.popupRef.current;if(!ve||(AQn(),te(),typeof ResizeObserver!="function"))return;const ye=new ResizeObserver(te);return ye.observe(ve),()=>{ye.disconnect()}},[te,E,Q,v,u.context.popupRef]),Nt(()=>{const ve=u.context.popupRef,ye=()=>{const Ne=ve.current;if(!Ne)return;const ke=m.getSnapshot();ke>0?Ne.style.setProperty(Gb.swipeProgress,`${ke}`):Ne.style.setProperty(Gb.swipeProgress,"0")};ye();const Se=m.subscribe(ye);return()=>{Se();const Ne=ve.current;Ne&&Ne.style.setProperty(Gb.swipeProgress,"0")}},[m,u.context.popupRef]),g.useEffect(()=>{if(R)return y?.(f),()=>{y?.(0)}},[f,R,y]),g.useEffect(()=>b?(b(R||I==="ending"),()=>{b(!1)}):void 0,[b,R,I]),rc({open:R,ref:u.context.popupRef,onComplete(){R&&u.context.onOpenChangeComplete?.(!0)}});const J=l===void 0?u.context.popupRef:l,ee=u.useStateSetter("popupElement"),ae={open:R,nested:j,transitionStatus:I,expanded:B===1,nestedDrawerOpen:Q,nestedDrawerSwiping:h,swipeDirection:d,swiping:V};let ce;U&&!(!p&&I!=="ending")&&(ce=`${U}px`);const ne=z&&z.length>0&&(d==="down"||d==="up");let ue=null;ne&&D!==null&&(ue=d==="up"?-D:D);let pe=F?F.getDragStyles():hs;if(ne&&d==="down"){const ve=D??0,ye=Number.parseFloat(String(pe[gc.swipeMovementY]??0)),Se=Number.isFinite(ye)?ve+ye:ve,Ne=Se<0;if(V&&Ne&&Number.isFinite(ye)){const ke=Math.abs(Se),ze=-Math.sqrt(ke)-ve;pe={...pe,transform:void 0,[gc.swipeMovementY]:`${ze}px`}}else pe={...pe,transform:void 0}}const le=En("div",t,{state:ae,props:[_,{id:H,"aria-labelledby":L,"aria-describedby":S,role:M,...Cy,hidden:!E,onKeyDown(ve){F1.has(ve.key)&&ve.stopPropagation()},style:{...pe,[Gb.swipeProgress]:"0",[gc.nestedDrawers]:N,[gc.height]:ce,[gc.snapPointOffset]:typeof ue=="number"?`${ue}px`:"0px",[gc.frontmostHeight]:f?`${f}px`:void 0,[gc.swipeStrength]:typeof $=="number"&&Number.isFinite($)&&$>0?`${$}`:"1"}},c],ref:[n,u.context.popupRef,ee],stateAttributesMapping:RQn});return o.jsx(_N,{context:k,openInteractionType:P,disabled:!E,closeOnFocusOut:!w,initialFocus:J,returnFocus:i,modal:C!==!1,restoreFocus:"popup",children:le})}),$Qn=d0e;var HFe,WFe;function MQn(e){const{children:t,open:n,defaultOpen:r=!1,onOpenChange:s,onOpenChangeComplete:a,disablePointerDismissal:i=!1,modal:l=!0,actionsRef:c,handle:u,triggerId:d,defaultTriggerId:f=null,swipeDirection:p="down",snapToSequentialPoints:h=!1,snapPoints:m,snapPoint:v,defaultSnapPoint:y,onSnapPointChange:b}=e,S=FV(!0),w=S?.onNestedSwipeProgressChange,k=S?.onNestedFrontmostHeightChange,_=S?.onNestedSwipingChange,C=S?.onNestedDrawerPresenceChange,[E,j]=g.useState(0),[N,I]=g.useState(0),[R,P]=g.useState(!1),[L,M]=g.useState(!1),[q]=g.useState(DQn),H=y!==void 0?y:m?.[0]??null,F=v!==void 0,[z,B]=uf({controlled:v,default:H,name:"Drawer",state:"snapPoint"}),D=g.useRef(!1),Q=vt((ce,Y)=>{const ne=Y??Ht(Io);b?.(ce,ne),!ne.isCanceled&&B(ce)}),V=g.useMemo(()=>F||!m||m.length===0?z:z===null||!m.some(ce=>Object.is(ce,z))?H:z,[z,F,H,m]),$=vt(ce=>{j(ce),!D.current&&ce>0&&I(ce)}),U=vt(ce=>{if(ce>0){D.current=!0,I(ce);return}D.current=!1,E>0&&I(E)}),Z=vt(ce=>{P(ce)}),X=vt(ce=>{q.set(ce),w?.(ce)}),te=vt(ce=>{M(ce),_?.(ce)}),J=vt((ce,Y)=>{s?.(ce,Y),!Y.isCanceled&&!ce&&m&&m.length>0&&Q(H,Ht(Y.reason,Y.event,Y.trigger))}),ee=g.useMemo(()=>({swipeDirection:p,snapToSequentialPoints:h,snapPoints:m,activeSnapPoint:V,setActiveSnapPoint:Q,frontmostHeight:N,popupHeight:E,hasNestedDrawer:R,nestedSwiping:L,nestedSwipeProgressStore:q,onNestedDrawerPresenceChange:Z,onPopupHeightChange:$,onNestedFrontmostHeightChange:U,onNestedSwipingChange:te,onNestedSwipeProgressChange:X,notifyParentFrontmostHeight:k,notifyParentSwipingChange:_,notifyParentSwipeProgressChange:w,notifyParentHasNestedDrawer:C}),[V,N,R,L,q,C,w,_,k,Z,U,X,te,$,E,Q,m,h,p]),ae=typeof t=="function"?ce=>o.jsxs(g.Fragment,{children:[HFe||(HFe=o.jsx(ZFe,{})),t(ce)]}):o.jsxs(g.Fragment,{children:[WFe||(WFe=o.jsx(ZFe,{})),t]});return o.jsx(x1t.Provider,{value:ee,children:o.jsx(l0e.Provider,{value:!0,children:o.jsx(uht,{open:n,defaultOpen:r,onOpenChange:J,onOpenChangeComplete:a,disablePointerDismissal:i,modal:l,actionsRef:c,handle:u,triggerId:d,defaultTriggerId:f,children:ae})})})}function DQn(){let e=0;const t=new Set;return{getSnapshot:()=>e,set(n){const r=Number.isFinite(n)?n:0;r!==e&&(e=r,t.forEach(s=>{s()}))},subscribe(n){return t.add(n),()=>{t.delete(n)}}}}function ZFe(){const e=i1(),t=b1t(),{store:n}=Td(!1),r=n.useState("open"),s=n.useState("nestedOpenDialogCount"),a=n.useState("popupElement"),i=s===0;return g.useEffect(()=>{if(!(!t||e==null))return()=>{t.removeDrawer(e)}},[e,t]),g.useEffect(()=>{e!=null&&t?.setDrawerOpen(e,r)},[e,r,t]),g.useEffect(()=>{if(!r||!i||!XP)return;const c=Ks(a).CloseWatcher;if(!c)return;function u(p){n.select("open")&&n.setOpen(!1,Ht(y0n,p))}const d=new c,f=Ur(d,"close",u);return()=>{f(),d.destroy()}},[n,i,r,a]),null}function qhe(e,t){const n=Mu(e);if(t==="vertical"){const s=n.overflowY;return(s==="auto"||s==="scroll")&&e.scrollHeight>e.clientHeight}const r=n.overflowX;return(r==="auto"||r==="scroll")&&e.scrollWidth>e.clientWidth}function LQn(e,t,n){let r=e;for(;r&&r!==t;){for(const s of n)if(qhe(r,s))return!0;r=r.parentElement}return!1}function GE(e,t,n="vertical"){let r=Ra(e)?e:null;for(;r&&r!==t;){if(qhe(r,n))return r;r=r.parentElement}return qhe(t,n)?t:null}function i8(e,t,n){return typeof e?.elementFromPoint=="function"?e.elementFromPoint(t,n):null}const FQn=40,zQn=10,BQn=1,UQn=50,GFe=16,qQn=80,VQn='button,a,input,select,textarea,label,[role="button"]';function ree(e,t,n){switch(e){case"up":return-n;case"down":return n;case"left":return-t;case"right":return t;default:return 0}}function HQn(e){const n=Ks(e).getComputedStyle(e).transform;let r=0,s=0,a=1;if(n&&n!=="none"){const i=n.match(/matrix(?:3d)?\(([^)]+)\)/);if(i){const l=i[1].split(", ").map(parseFloat);l.length===6?(r=l[4],s=l[5],a=Math.sqrt(l[0]*l[0]+l[1]*l[1])):l.length===16&&(r=l[12],s=l[13],a=l[0])}}return{x:r,y:s,scale:a}}function $6(e){return Number.isFinite(e)&&e>0?e:null}function WQn(e){return e%2===1}function see(e,t,n){const r=e[n];if(typeof r=="function")try{r.call(e,t)}catch(s){if(s&&typeof s=="object"&&"name"in s&&s.name==="NotFoundError")return;throw s}}function ZQn(e){const{enabled:t,directions:n,elementRef:r,movementCssVars:s,canStart:a,ignoreSelectorWhenTouch:i=!0,ignoreScrollableAncestors:l=!1,swipeThreshold:c,onDismiss:u,onProgress:d,onCancel:f,onSwipeStart:p,onRelease:h,onSwipingChange:m,trackDrag:v=!0}=e,y=VQn,b=n.length===1?n[0]:void 0,S=Math.max(0,typeof c=="number"?c:FQn),w=n.includes("left"),k=n.includes("right"),_=n.includes("up"),C=n.includes("down"),E=w||k,j=_||C,N=g.useMemo(()=>{const Qe=[];return j&&Qe.push("vertical"),E&&Qe.push("horizontal"),Qe},[E,j]),[I,R]=g.useState(void 0),[P,L]=g.useState(!1),[M,q]=g.useState(!1),[H,F]=g.useState(!1),[z,B]=g.useState({x:0,y:0}),[D,Q]=g.useState({x:0,y:0,scale:1}),[V,$]=g.useState(null),U=g.useRef({x:0,y:0}),Z=g.useRef({x:0,y:0}),X=g.useRef(null),te=g.useRef({x:0,y:0,scale:1}),J=g.useRef(void 0),ee=g.useRef(0),ae=g.useRef(!1),ce=g.useRef({x:0,y:0}),Y=g.useRef(!1),ne=g.useRef(!1),ue=g.useRef(null),pe=g.useRef(!1),le=g.useRef(!1),ve=g.useRef({width:0,height:0}),ye=g.useRef(0),Se=g.useRef(S),Ne=g.useRef(null),ke=g.useRef(null),Ie=g.useRef({x:0,y:0}),ze=g.useRef(null),oe=g.useRef(!1),se=vt(Qe=>{oe.current!==Qe&&(oe.current=Qe,L(Qe),m?.(Qe))});function re(Qe){if(!Qe)return;if(typeof c!="function"){Se.current=S;return}const lt=r.current;if(!lt)return;const it=c({element:lt,direction:Qe});Se.current=Math.max(0,it)}const he=vt((Qe,lt)=>{const it=Number.isFinite(Qe)?Ts(Qe,0,1):0,Xt=it!==ye.current;let Zt=!1;if(lt){const _n=ze.current;Zt=!_n||_n.deltaX!==lt.deltaX||_n.deltaY!==lt.deltaY||_n.direction!==lt.direction}!Xt&&!Zt||(ye.current=it,lt?ze.current=lt:Xt&&(ze.current=null),d?.(it,lt))});function xe(Qe,lt){if(lt===null)return;const it=ke.current;if(it&<>it.time){const Xt=Math.max(lt-it.time,GFe);Ie.current={x:(Qe.x-it.x)/Xt,y:(Qe.y-it.y)/Xt}}ke.current={x:Qe.x,y:Qe.y,time:lt}}const je=g.useCallback(()=>{R(void 0),se(!1),q(!1),F(!1),B({x:0,y:0}),Q({x:0,y:0,scale:1}),$(null),he(0),Se.current=S,U.current={x:0,y:0},Z.current={x:0,y:0},te.current={x:0,y:0,scale:1},J.current=void 0,ee.current=0,ae.current=!1,ce.current={x:0,y:0},Y.current=!1,X.current=null,ne.current=!1,ue.current=null,pe.current=!1,le.current=!1,ve.current={width:0,height:0},Ne.current=null,ke.current=null,Ie.current={x:0,y:0},ze.current=null},[se,S,he]);g.useEffect(()=>{typeof c!="function"&&(Se.current=S)},[S,c]);function Pe(Qe){if("touches"in Qe){const lt=Qe.touches[0];return lt?{x:lt.clientX,y:lt.clientY}:null}return{x:Qe.clientX,y:Qe.clientY}}function Ge(Qe){return"touches"in Qe?!0:Qe.pointerType==="touch"}function Ze(Qe,lt){const it=pr(r.current);return i8(it,Qe.x,Qe.y)??Oi(lt)}function Ee(Qe,lt){return E&&!j?GE(Qe,lt,"horizontal"):j&&!E?GE(Qe,lt,"vertical"):GE(Qe,lt,"vertical")??GE(Qe,lt,"horizontal")}function _e(Qe,lt,it){pe.current=!1;const Xt=Ge(Qe),Zt=Ze(lt,Qe.nativeEvent),Te=pr(r.current).body,Fe=Xt&&Te?Ee(Zt,Te):null,Me=it?.ignoreScrollableTarget??!1;if(Fe&&!Me||(pe.current=!!(Fe&&Me),(Zt?Zt.closest(y):!1)&&(!Xt||i)))return!1;const nt=r.current;if(l&&nt&&Zt&&N.length>0&&!(it?.ignoreScrollableAncestors??!1)&&LQn(Zt,nt,N))return!1;if(ae.current=!1,J.current=void 0,ee.current=0,U.current=lt,Ne.current=$6(Qe.timeStamp),ce.current=lt,X.current=lt,nt){ve.current={width:nt.offsetWidth,height:nt.offsetHeight},re(b);const Dt=HQn(nt);te.current=Dt,Z.current={x:Dt.x,y:Dt.y},Q(Dt),B({x:Dt.x,y:Dt.y}),xe({x:Dt.x,y:Dt.y},Ne.current),"touches"in Qe||see(nt,Qe.pointerId,"setPointerCapture")}return p?.(Qe.nativeEvent),se(!0),q(!1),$(null),Y.current=!0,he(0),!0}function Ce(){Oe(),pe.current=!1,X.current=null}function Oe(){ne.current=!1,ue.current=null}function Re(Qe){if(Ce(),!oe.current)return;se(!1),q(!1),$(null);const lt=v?D:te.current;Z.current={x:lt.x,y:lt.y},B({x:lt.x,y:lt.y}),R(void 0),le.current=!1;const it=r.current;it&&see(it,Qe.pointerId,"releasePointerCapture"),he(0,{deltaX:0,deltaY:0,direction:void 0}),f?.(Qe.nativeEvent)}function qe(Qe,lt){const it=Te=>Te>=0?Te**.5:-(Math.abs(Te)**.5),Xt=(Te,Fe,Me)=>!Fe&&Te<0||!Me&&Te>0?it(Te):Te,Zt=E?Xt(Qe,w,k):it(Qe),_n=j?Xt(lt,_,C):it(lt);return{x:Zt,y:_n}}function Ye(Qe,lt,it){const Xt=Math.abs(lt),Zt=Math.abs(it);if(j&&it!==0&&(!E||Zt>=Xt)){const Fe=Math.max(0,Qe.scrollHeight-Qe.clientHeight),Me=Qe.scrollTop<=0,Ke=Qe.scrollTop>=Fe,nt=it>0,Dt=it<0;return nt&&Me&&C||Dt&&Ke&&_}if(E&<!==0&&(!j||Xt>Zt)){const Fe=Math.max(0,Qe.scrollWidth-Qe.clientWidth),Me=Qe.scrollLeft<=0,Ke=Qe.scrollLeft>=Fe,nt=lt>0,Dt=lt<0;return nt&&Me&&k||Dt&&Ke&&w}return null}const tt=vt(Qe=>{if(!t||Qe.defaultPrevented||Qe.nativeEvent.defaultPrevented||!("touches"in Qe)&&Qe.button!==0)return;const lt=Pe(Qe);!lt||(ne.current=!0,ue.current=lt,pe.current=!1,le.current=!1,!(a?a(lt,{nativeEvent:Qe.nativeEvent,direction:b}):!0))||_e(Qe,lt)&&Oe()});function At(Qe,lt,it){if(!t||!oe.current)return;const Xt=Oi(Qe.nativeEvent);if(Ge(Qe)&&!pe.current){const fr=Qe.currentTarget;if(Ee(Xt,fr))return}if("touches"in Qe||Qe.preventDefault(),Y.current){U.current=lt;const fr=$6(Qe.timeStamp);fr!==null&&(Ne.current=fr),Y.current=!1}const Zt=lt.x,_n=lt.y,Te=it.x,Fe=it.y;(Fe<0&&_n>ce.current.y||Fe>0&&_n<ce.current.y)&&(ce.current={x:ce.current.x,y:_n}),(Te<0&&Zt>ce.current.x||Te>0&&Zt<ce.current.x)&&(ce.current={x:Zt,y:ce.current.y});const Me=Zt-U.current.x,Ke=_n-U.current.y,nt=_n-ce.current.y,Dt=Zt-ce.current.x;if(!M&&Math.sqrt(Me*Me+Ke*Ke)>=BQn&&(q(!0),V===null&&E&&j)){const Hs=Math.abs(Me),va=Math.abs(Ke);$(Hs>va?"horizontal":"vertical")}let _t;if(!J.current)V==="vertical"?Ke>0?_t="down":Ke<0&&(_t="up"):V==="horizontal"?Me>0?_t="right":Me<0&&(_t="left"):Math.abs(Me)>=Math.abs(Ke)?_t=Me>0?"right":"left":_t=Ke>0?"down":"up",_t&&(_t==="left"&&w||_t==="right"&&k||_t==="up"&&_||_t==="down"&&C)&&(J.current=_t,ee.current=ree(_t,Me,Ke),R(_t),re(_t));else{const fr=J.current,Hs=ree(fr,Dt,nt);Hs>Se.current?(ae.current=!1,R(fr)):!(w&&k)&&!(_&&C)&&ee.current-Hs>=zQn&&(ae.current=!0)}const Ft=qe(Me,Ke);let $t=te.current.x,jt=te.current.y;V==="horizontal"?E&&($t+=Ft.x):(V==="vertical"||E&&($t+=Ft.x),j&&(jt+=Ft.y)),Z.current={x:$t,y:jt},v&&B({x:$t,y:jt}),xe({x:$t,y:jt},$6(Qe.timeStamp));const xn=$t-te.current.x,sr=jt-te.current.y,Zn=J.current,jr=b??J.current;if(!jr){he(0,{deltaX:xn,deltaY:sr,direction:Zn});return}const hr=jr==="left"||jr==="right"?ve.current.width:ve.current.height,xs=te.current.scale||1;if(hr<=0||xs<=0){he(0,{deltaX:xn,deltaY:sr,direction:Zn});return}const Dr=ree(jr,$t-te.current.x,jt-te.current.y);if(Dr<=0){he(0,{deltaX:xn,deltaY:sr,direction:Zn});return}he(Dr/(hr*xs),{deltaX:xn,deltaY:sr,direction:Zn})}const ot=vt(Qe=>{const lt=Pe(Qe);if(!lt)return;if(!("touches"in Qe)){const Zt=WQn(Qe.buttons);Zt&&(le.current=!0);const _n=Qe.buttons===0&&le.current;if(Qe.buttons!==0&&!Zt||_n){Re(Qe);return}}if(!P&&ne.current){if(!Ge(Qe)&&(Qe.defaultPrevented||Qe.nativeEvent.defaultPrevented)){Ce();return}if(a?a(lt,{nativeEvent:Qe.nativeEvent,direction:b}):!0){const _n=ue.current;let Te=!1;if(Ge(Qe)){const Me=r.current;if(_n&&Me){const Ke=Ze(lt,Qe.nativeEvent),Dt=pr(Me).body,_t=Dt?Ee(Ke,Dt):null;if(_t&&(pn(Me,_t)||pn(_t,Me))){const Ft=lt.x-_n.x,$t=lt.y-_n.y,jt=Ye(_t,Ft,$t);if(jt===!1)return;jt===!0&&(Te=!0)}}}_e(Qe,lt,{ignoreScrollableTarget:Te,ignoreScrollableAncestors:Te})&&(_n&&Te?(Oe(),U.current=_n,ce.current=_n,X.current=_n,Y.current=!1):(Oe(),pe.current=!1))}}const it=X.current,Xt=it===null?{x:0,y:0}:{x:lt.x-it.x,y:lt.y-it.y};X.current=lt,At(Qe,lt,Xt)}),zt=vt(Qe=>{if(!t)return;const lt=Z.current,it=te.current,Xt=lt.x-it.x,Zt=lt.y-it.y,_n={deltaX:Xt,deltaY:Zt,direction:I??J.current};if(!oe.current){Ce(),he(0,_n);return}se(!1),q(!1),$(null),Ce(),le.current=!1;const Te=r.current;Te&&("touches"in Qe||see(Te,Qe.pointerId,"releasePointerCapture"));const Fe=Xt,Me=Zt,Ke=Ne.current,nt=$6(Qe.timeStamp),Dt=Ke!==null&&nt!==null&&nt>Ke?nt-Ke:0,_t=Dt>0?Math.max(Dt,UQn):0,Ft=_t>0?Fe/_t:0,$t=_t>0?Me/_t:0;let jt=Ie.current.x,xn=Ie.current.y;const sr=ke.current;if(sr&&nt!==null&&nt>=sr.time){const Dr=nt-sr.time;if(Dr<=qQn){const fr=Math.max(Dr,GFe),Hs=lt.x-sr.x,va=lt.y-sr.y,ja=Hs/fr,Da=va/fr;ja!==0&&(jt=ja),Da!==0&&(xn=Da)}else jt=0,xn=0}const Zn=h?.({event:Qe.nativeEvent,direction:I??J.current,deltaX:Fe,deltaY:Me,velocityX:Ft,velocityY:$t,releaseVelocityX:jt,releaseVelocityY:xn}),jr=typeof Zn=="boolean";if(ae.current&&!jr){Z.current={x:it.x,y:it.y},B({x:it.x,y:it.y}),R(void 0),he(0,_n);return}let hr=!1,xs;if(jr)hr=Zn,xs=I??J.current??b;else for(const Dr of n){switch(Dr){case"right":Fe>Se.current&&(hr=!0,xs="right");break;case"left":Fe<-Se.current&&(hr=!0,xs="left");break;case"down":Me>Se.current&&(hr=!0,xs="down");break;case"up":Me<-Se.current&&(hr=!0,xs="up");break}if(hr)break}hr&&xs?(R(xs),F(!0),u?.(Qe.nativeEvent,{direction:xs})):(Z.current={x:it.x,y:it.y},B({x:it.x,y:it.y}),R(void 0),he(0,_n))}),mt=g.useCallback(()=>{const Qe=v?z:Z.current,lt=v?D:te.current;if(!P&&Qe.x===lt.x&&Qe.y===lt.y&&!H)return{[s.x]:"0px",[s.y]:"0px"};const it=Qe.x-lt.x,Xt=Qe.y-lt.y;return{transition:P?"none":void 0,transform:P?`translateX(${Qe.x}px) translateY(${Qe.y}px) scale(${lt.scale})`:void 0,[s.x]:`${it}px`,[s.y]:`${Xt}px`}},[H,z,D,P,s,v]),Pt=g.useCallback(()=>t?{onPointerDown:tt,onPointerMove:ot,onPointerUp:zt,onPointerCancel:zt}:{},[t,zt,ot,tt]),tn=g.useCallback(()=>t?{onTouchStart:tt,onTouchMove:ot,onTouchEnd:zt,onTouchCancel:zt}:{},[t,zt,ot,tt]);return{swiping:P,swipeDirection:I,dragDismissed:H,getPointerProps:Pt,getTouchProps:tn,getDragStyles:mt,reset:je}}const GQn=p0e,QQn=h0e,Vhe=10,QFe=.5,YFe=.5,YQn=300,XFe=4,KFe=.2,XQn=4,aee=80,JFe=360,iee=.1,e8e=1,KQn=`[${y1t}]`,JQn=g.forwardRef(function(t,n){const{render:r,className:s,style:a,children:i,...l}=t,{store:c}=Td(),{swipeDirection:u,notifyParentSwipingChange:d,notifyParentSwipeProgressChange:f,frontmostHeight:p,snapToSequentialPoints:h}=FV(),m=b1t(),{snapPoints:v,resolvedSnapPoints:y,activeSnapPoint:b,activeSnapPointOffset:S,setActiveSnapPoint:w,popupHeight:k}=w1t(),_=c.useState("open"),C=c.useState("mounted"),E=c.useState("nested"),j=c.useState("nestedOpenDrawerCount"),N=c.useState("viewportElement"),I=c.useState("popupElement"),R=m?.visualStateStore,P=j>0,L=u==="left"||u==="right"?"horizontal":"vertical",M=L==="vertical",q=M?"horizontal":"vertical",[H,F]=g.useState(null),z=g.useRef(void 0),B=g.useRef(null),D=n1(),Q=g.useRef(!1),V=g.useRef(""),$=g.useRef(!1),U=g.useRef(!1),Z=g.useRef(null),X=g.useMemo(()=>{if(!v||v.length<2||u!=="down"&&u!=="up"||y.length<2)return null;const ke=y.map(re=>re.offset).filter(re=>Number.isFinite(re)).sort((re,he)=>re-he);if(ke.length<2)return null;const Ie=ke[0],ze=ke[1],oe=ke[ke.length-1];let se=ze-Ie;if(!Number.isFinite(se)||se<=0){const re=oe-Ie;if(!Number.isFinite(re)||re<=0)return null;se=re}return{minOffset:Ie,range:se}},[y,v,u]),te=g.useMemo(()=>!X||S===null?null:Ts((S-X.minOffset)/X.range,0,1),[S,X]),J=g.useMemo(()=>v&&v.length>0&&(u==="down"||u==="up")?u==="down"?["down","up"]:["up","down"]:[u],[v,u]),ee=vt(ke=>{eYn(c.context.popupRef.current,c.context.backdropRef.current,ke)}),ae=vt(()=>{ee(!1),c.context.popupRef.current?.removeAttribute(kg.endingStyle),F(null)}),ce=vt(()=>{Q.current&&(Q.current=!1,d?.(!1))}),Y=vt(({resolvedProgress:ke,shouldTrackProgress:Ie,notifyParent:ze})=>{const oe=_&&!E&&Ie,se=oe?ke:0,re=_&&Ie?ke:0;ze&&f&&(f(re),re<=0&&ce()),R?.set({swipeProgress:se,frontmostHeight:se>0?p:0});const he=c.context.backdropRef.current;if(he){if(!oe||se<=0){he.style.setProperty(Gb.swipeProgress,"0"),he.style.removeProperty(gc.height);return}he.style.setProperty(Gb.swipeProgress,`${se}`),p>0?he.style.setProperty(gc.height,`${p}px`):he.style.removeProperty(gc.height)}});function ne({direction:ke,deltaX:Ie,deltaY:ze,velocityX:oe,velocityY:se,releaseVelocityX:re,releaseVelocityY:he}){if(!ke)return null;const xe=c.context.popupRef.current;if(!xe)return null;const je=ke==="left"||ke==="right"?xe.offsetWidth:xe.offsetHeight;if(!Number.isFinite(je)||je<=0)return null;const Pe=ke==="left"||ke==="right"?Ie:ze,Ge=v&&v.length>0?S??0:0;let Ze=0;ke==="down"?Ze=Ge:ke==="up"&&(Ze=-Ge);const Ee=Ze+Pe,_e=ke==="left"||ke==="up"?-Ee:Ee,Ce=Math.max(0,je-_e);if(!Number.isFinite(Ce)||Ce<=0)return null;const Oe=ke==="left"||ke==="right"?re:he,Re=ke==="left"||ke==="right"?oe:se,qe=Math.abs(Oe)>0&&Number.isFinite(Oe)?Oe:Re,Ye=ke==="left"||ke==="up"?-qe:qe;if(!Number.isFinite(Ye)||Ye<=KFe)return null;const tt=Ts(Ye,KFe,XQn),At=Ts(Ce/tt,aee,JFe);if(!Number.isFinite(At))return null;const ot=(At-aee)/(JFe-aee),zt=Ts(iee+ot*(e8e-iee),iee,e8e);return!Number.isFinite(zt)||zt<=0?null:zt}function ue(ke){if(Q.current||!ke)return;const Ie=ke.direction??u,ze=Ie==="left"||Ie==="right"?ke.deltaX:ke.deltaY;!Number.isFinite(ze)||Math.abs(ze)<Vhe||(Q.current=!0,d?.(!0))}const pe=ZQn({enabled:C&&!P,directions:J,elementRef:c.context.popupRef,ignoreSelectorWhenTouch:!1,ignoreScrollableAncestors:!0,movementCssVars:{x:gc.swipeMovementX,y:gc.swipeMovementY},onSwipeStart(ke){if("touches"in ke||"pointerType"in ke&&ke.pointerType==="touch")return;const Ie=c.context.popupRef.current;if(!Ie)return;const oe=pr(Ie).getSelection?.();if(!oe||oe.isCollapsed)return;const se=_r(oe.anchorNode)?oe.anchorNode:oe.anchorNode?.parentElement,re=_r(oe.focusNode)?oe.focusNode:oe.focusNode?.parentElement;!pn(Ie,se)&&!pn(Ie,re)||oe.removeAllRanges()},onSwipingChange(ke){t8e(c.context.backdropRef.current,ke),!ke&&!f&&ce()},swipeThreshold({element:ke,direction:Ie}){return n8e(ke,Ie)},canStart(ke,Ie){const ze=c.context.popupRef.current;if(!ze)return!1;const oe=ze.ownerDocument,se=i8(oe,ke.x,ke.y);if(!se||!pn(ze,se))return!1;const re=Ie.nativeEvent;return!(("touches"in re||"pointerType"in re&&re.pointerType==="touch")&&s8e(oe,ze)||re.type==="touchstart"&&oee(se))},onProgress(ke,Ie){ue(Ie);const ze=Ie?.direction??pe.swipeDirection,oe=ze===void 0||ze===u,se=!!(v&&v.length>0),he=se&&(u==="down"||u==="up")||!se||u==="left"||u==="right"||oe;let xe=ke;if(X&&k>0){if(Ie&&Number.isFinite(Ie.deltaY)){const je=S??X.minOffset,Pe=Ts(je+Ie.deltaY,0,k);xe=Ts((Pe-X.minOffset)/X.range,0,1)}else if(te!==null)xe=te;else if(ze==="down"||ze==="up"){const je=ke*k,Pe=S??X.minOffset,Ge=ze==="down"?Pe+je:Pe-je;xe=Ts((Ge-X.minOffset)/X.range,0,1)}}Y({resolvedProgress:xe,shouldTrackProgress:he,notifyParent:!0})},onRelease({event:ke,deltaX:Ie,deltaY:ze,direction:oe,velocityX:se,velocityY:re,releaseVelocityX:he,releaseVelocityY:xe}){const je={deltaX:Ie,deltaY:ze,velocityX:se,velocityY:re,releaseVelocityX:he,releaseVelocityY:xe};function Pe(tn){const Qe=c.context.popupRef.current;Qe&&(ce(),ee(!0),Qe.style.removeProperty("transition"),Qe.setAttribute(kg.endingStyle,""),yo.flushSync(()=>{F(ne({direction:tn,...je}))}))}if(!v||v.length===0){if(!oe){ae();return}const tn=c.context.popupRef.current;if(!tn){ae();return}const Qe=n8e(tn,oe),lt=oe==="left"||oe==="right"?Ie:ze;if(!Number.isFinite(lt)){ae();return}const it=oe==="left"||oe==="up"?-lt:lt;if(it<=0)return ae(),!1;const Xt=oe==="left"||oe==="right"?se:re;if((oe==="left"||oe==="up"?-Xt:Xt)>=QFe&&it>0)return Pe(oe),!0;const _n=it>Qe;return _n?Pe(oe):ae(),_n}if(u!=="down"&&u!=="up"){ae();return}if(!k||y.length===0){ae();return}const Ge=u==="down"?ze:-ze;if(!Number.isFinite(Ge)){ae();return}const Ze=Math.sign(Ge),Ee=u==="down"?xe:-xe,_e=u==="down"?re:-re;let Ce=Number.isFinite(Ee)?Ee:_e;if(Ze!==0&&Math.abs(Ge)>=Vhe&&Number.isFinite(Ce)){const tn=Math.sign(Ce);tn!==0&&tn!==Ze&&(Ce=_e)}const Oe=S??0,Re=Ts(Oe+Ge,0,k),qe=Number.isFinite(Ce)&&Math.abs(Ce)>=YFe?Ts(Ce,-XFe,XFe)*YQn:0,Ye=h?Re:Ts(Re+qe,0,k),tt=Ht(TL,ke),At=()=>(z.current=b,w?.(null,tt),Pe(u),!0);if(h){const tn=[...y].sort((Ke,nt)=>Ke.offset-nt.offset);if(tn.length===0)return ae(),!1;let Qe=0,lt=Math.abs(Oe-tn[0].offset);for(let Ke=1;Ke<tn.length;Ke+=1){const nt=Math.abs(Oe-tn[Ke].offset);nt<lt&&(lt=nt,Qe=Ke)}let it=tn[0];lt=Math.abs(Ye-it.offset);for(const Ke of tn){const nt=Math.abs(Ye-Ke.offset);nt<lt&&(lt=nt,it=Ke)}const Xt=Math.sign(Ce),Zt=Ze!==0&&Xt!==0&&Xt===Ze&&Math.abs(Ce)>=YFe;let _n=Ye;if(Zt){const Ke=Ts(Qe+Ze,0,tn.length-1);if(Ke!==Qe){const nt=tn[Ke];(Ze>0?Ye<nt.offset:Ye>nt.offset)&&(it=nt,_n=nt.offset)}else if(Ze>0)return At()}const Fe=Math.abs(_n-k),Me=Math.abs(_n-it.offset);return Fe<Me?At():(w?.(it.value,tt),ae(),!1)}if(Ce>=QFe&&Ge>0)return At();let ot=y[0],zt=Math.abs(Ye-ot.offset);for(const tn of y){const Qe=Math.abs(Ye-tn.offset);Qe<zt&&(zt=Qe,ot=tn)}return Math.abs(Ye-k)<zt?At():(w?.(ot.value,tt),ae(),!1)},onDismiss(ke){R?.set({swipeProgress:0,frontmostHeight:0});const Ie=c.context.backdropRef.current;Ie&&(Ie.style.setProperty(Gb.swipeProgress,"0"),Ie.style.removeProperty(gc.height));const ze=Ht(TL,ke);if(c.setOpen(!1,ze),ze.isCanceled){const oe=z.current;oe!==void 0&&w?.(oe,Ht(TL,ke)),z.current=void 0,B.current?.(),ae();return}if(c.select("open")){const oe=ke;D.request(()=>{if(c.select("open")){const se=z.current;se!==void 0&&w?.(se,Ht(TL,oe)),z.current=void 0,ae(),B.current?.()}else z.current=void 0});return}z.current=void 0,ee(!0)}}),le=pe.getPointerProps(),ve=pe.getTouchProps(),ye=pe.reset;B.current=ye,g.useEffect(()=>{const ke=N??I;if(!ke)return;const Ie=ke,ze=pr(Ie),oe=Ks(ze);function se(re){if(U.current)return;const he=Z.current,xe=re.touches[0];if(!xe||!he)return;const je=M?xe.clientY-he.lastY:xe.clientX-he.lastX;if(k1t(re,oe)){he.allowSwipe=!1,MS(he,xe);return}if(re.touches.length===2){MS(he,xe);return}if(s8e(ze,Ie)||!_||!C||P){MS(he,xe);return}if(sYn(he,xe,M)){MS(he,xe);return}const Ge=he.scrollTarget;if(!Ge||Ge===ze.documentElement||Ge===ze.body){re.cancelable&&re.preventDefault(),MS(he,xe);return}if(!aYn(Ge,L)){re.cancelable&&re.preventDefault(),MS(he,xe);return}const Ee=je;if(Ee!==0){const _e=oYn(Ge,L,u,Ee);he.allowSwipe?re.cancelable&&re.preventDefault():re.cancelable&&_e?(he.allowSwipe=!0,re.preventDefault()):he.allowSwipe=!1}MS(he,xe)}return Ur(ze,"touchmove",se,{passive:!1,capture:!0})},[C,P,_,I,M,L,u,N]),g.useEffect(()=>{if(!X||pe.swiping)return;Y({resolvedProgress:!_||E?0:te??0,shouldTrackProgress:!0,notifyParent:!1})},[Y,p,E,f,_,te,X,pe.swiping,c,R]),g.useEffect(()=>{if(f)return _||f(0),()=>{f(0)}},[f,_]),g.useEffect(()=>{_&&(ye(),ae())},[ae,_,ye]),g.useEffect(()=>()=>{R?.set({swipeProgress:0,frontmostHeight:0}),t8e(c.context.backdropRef.current,!1),ce()},[ce,c,R]);const Se=g.useMemo(()=>({swiping:pe.swiping,getDragStyles:pe.getDragStyles,swipeStrength:H??null,setSwipeDismissed:ee}),[ee,pe.getDragStyles,pe.swiping,H]);function Ne(){U.current=!1,Z.current=null,V.current="",$.current=!1}return o.jsx(ejn,{ref:n,className:s,style:a,render:r,...Po(l,{onPointerDown(ke){if(V.current=ke.pointerType,$.current=ke.pointerType==="pen",!_||!C||P)return;const Ie=pr(ke.currentTarget),ze=i8(Ie,ke.clientX,ke.clientY);oee(ze)||tYn(ze)||ke.pointerType!=="touch"&&le.onPointerDown?.(ke)},onPointerMove(ke){ke.pointerType!=="touch"&&le.onPointerMove?.(ke)},onPointerUp(ke){V.current===ke.pointerType&&(V.current=""),ke.pointerType!=="touch"&&le.onPointerUp?.(ke)},onPointerCancel(ke){V.current===ke.pointerType&&(V.current=""),ke.pointerType!=="touch"&&le.onPointerCancel?.(ke)},onTouchStart(ke){if(V.current==="pen"&&$.current){$.current=!1,U.current=!1,Z.current=null;return}if(!_||!C||P){U.current=!1,Z.current=null;return}const ze=ke.touches[0];if(!ze)return;if(a8e(ke)){U.current=!1,Z.current=null;return}const oe=pr(ke.currentTarget),se=i8(oe,ze.clientX,ze.clientY);if(U.current=oee(se),U.current){Z.current=null;return}const re=N??I,he=Oi(ke.nativeEvent),xe=_r(he)?he:null;if(re&&xe&&!pn(re,xe)){U.current=!0,Z.current=null;return}let je=null,Pe=!1;re&&xe&&(je=GE(xe,re,L),Pe=GE(xe,re,q)!=null);let Ge=null;je&&(Ge=iYn(je,L,u)?null:!1),Z.current={startX:ze.clientX,startY:ze.clientY,lastX:ze.clientX,lastY:ze.clientY,scrollTarget:je,hasCrossAxisScrollableContent:Pe,allowSwipe:Ge,preserveNativeCrossAxisScroll:!1},ve.onTouchStart?.(ke)},onTouchMove(ke){if(U.current||a8e(ke))return;const Ie=Z.current;Ie?.preserveNativeCrossAxisScroll||Ie?.allowSwipe===!1||Ie?.scrollTarget!=null&&!Ie.allowSwipe||ve.onTouchMove?.(ke)},onTouchEnd(ke){Ne(),ve.onTouchEnd?.(ke)},onTouchCancel(ke){Ne(),ve.onTouchCancel?.(ke)},"data-nested-dialog-open":void 0}),children:o.jsx(S1t.Provider,{value:Se,children:i})})});function eYn(e,t,n){if(n){e?.setAttribute(ig.swipeDismiss,""),t?.setAttribute(ig.swipeDismiss,"");return}e?.removeAttribute(ig.swipeDismiss),t?.removeAttribute(ig.swipeDismiss)}function t8e(e,t){if(e){if(t){e.setAttribute(ig.swiping,"");return}e.removeAttribute(ig.swiping)}}function oee(e){return!!e?.closest(awn)}function tYn(e){return!!e?.closest(KQn)}function n8e(e,t){const n=t==="left"||t==="right"?e.offsetWidth:e.offsetHeight;return Math.max(n*.5,Vhe)}function r8e(e,t){return e instanceof t.HTMLInputElement&&e.type==="range"}function nYn(e){return _r(e)?e.tagName==="INPUT"||e.tagName==="TEXTAREA":!1}function rYn(e,t){const n=_r(e.anchorNode)?e.anchorNode:e.anchorNode?.parentElement,r=_r(e.focusNode)?e.focusNode:e.focusNode?.parentElement;return e.containsNode(t,!0)||pn(t,n)||pn(t,r)}function s8e(e,t){const n=hc(e);if(!!(n&&pn(t,n))&&nYn(n)){const{selectionStart:a,selectionEnd:i}=n;if(a!=null&&i!=null&&a<i)return!0}const s=e.getSelection?.();return!s||s.isCollapsed?!1:rYn(s,t)}function k1t(e,t){const n=e.composedPath();return n?n.some(r=>r8e(r,t)):r8e(Oi(e),t)}function a8e(e){return k1t(e.nativeEvent,Ks(e.currentTarget))}function MS(e,t){e.lastX=t.clientX,e.lastY=t.clientY}function sYn(e,t,n){if(e.preserveNativeCrossAxisScroll)return!0;if(e.allowSwipe===!0||!e.hasCrossAxisScrollableContent)return!1;const r=n?t.clientY-e.startY:t.clientX-e.startX,s=n?t.clientX-e.startX:t.clientY-e.startY,a=Math.abs(r),i=Math.abs(s);return i<6||i<=a+2?!1:(e.preserveNativeCrossAxisScroll=!0,!0)}function aYn(e,t){return t==="vertical"?e.scrollHeight>e.clientHeight:e.scrollWidth>e.clientWidth}function O1t(e,t){if(t==="vertical"){const r=Math.max(0,e.scrollHeight-e.clientHeight);return{offset:e.scrollTop,max:r}}const n=Math.max(0,e.scrollWidth-e.clientWidth);return{offset:e.scrollLeft,max:n}}function iYn(e,t,n){const{offset:r,max:s}=O1t(e,t),a=_1t(n,t);return a===null?!1:a?r<=0:r>=s}function oYn(e,t,n,r){const{offset:s,max:a}=O1t(e,t),i=_1t(n,t);return i===null||!(i?r>0:r<0)?!1:i?s<=0:s>=a}function _1t(e,t){return t==="vertical"?e==="down"?!0:e==="up"?!1:null:e==="right"?!0:e==="left"?!1:null}const lYn=al("drawer-backdrop fixed inset-0 z-50",{variants:{overlay:{visible:"bg-overlay backdrop-blur-xs",transparent:"bg-transparent",none:"hidden"}},defaultVariants:{overlay:"visible"}}),cYn=al("fixed z-50 flex",{variants:{side:{top:"items-start justify-center",bottom:"items-end justify-center",left:"items-stretch justify-start",right:"items-stretch justify-end"},layout:{default:"inset-0",floating:"p-3 sm:p-4",floatingOverlay:"inset-0 p-3 sm:p-4"}},compoundVariants:[{side:"right",layout:"floating",className:"inset-y-0 right-0 w-[calc(32rem+1.5rem)] max-w-full sm:w-[calc(32rem+2rem)]"},{side:"left",layout:"floating",className:"inset-y-0 left-0 w-[calc(32rem+1.5rem)] max-w-full sm:w-[calc(32rem+2rem)]"},{side:"bottom",layout:"floating",className:"inset-x-0 bottom-0 h-[calc(85dvh+1.5rem)] max-h-full sm:h-[calc(85dvh+2rem)]"},{side:"top",layout:"floating",className:"inset-x-0 top-0 h-[calc(85dvh+1.5rem)] max-h-full sm:h-[calc(85dvh+2rem)]"}],defaultVariants:{side:"bottom",layout:"default"}}),uYn=al(K("drawer-popup group/popup relative z-50 box-border flex flex-col overflow-y-auto overscroll-contain outline-none [touch-action:auto] will-change-transform","border-border1 bg-surface3 text-neutral5 shadow-dialog","data-[swiping]:select-none","after:pointer-events-none after:absolute after:inset-0 after:bg-transparent after:transition-[background-color] after:duration-[450ms] after:content-['']","data-[nested-drawer-open]:after:bg-black/25"),{variants:{side:{bottom:"",top:"",left:"",right:""},variant:{default:"",floating:"drawer-popup-floating pointer-events-auto rounded-lg border"}},compoundVariants:[{side:"bottom",variant:"default",className:"h-[var(--drawer-height,auto)] max-h-[calc(85vh_+_3rem)] w-full -mb-12 pb-12 rounded-t-xl border-x border-t"},{side:"top",variant:"default",className:"h-[var(--drawer-height,auto)] max-h-[calc(85vh_+_3rem)] w-full -mt-12 pt-12 rounded-b-xl border-x border-b"},{side:"left",variant:"default",className:"h-full w-[20rem] max-w-[85vw] rounded-r-xl border-y border-r"},{side:"right",variant:"default",className:"h-full w-[20rem] max-w-[85vw] rounded-l-xl border-y border-l"},{side:["left","right"],variant:"floating",className:"h-[calc(100dvh-1.5rem)] w-[32rem] max-w-[calc(100vw-1.5rem)] sm:h-[calc(100dvh-2rem)] sm:max-w-[calc(100vw-2rem)]"},{side:["top","bottom"],variant:"floating",className:"max-h-[calc(85dvh-1.5rem)] w-[calc(100vw-1.5rem)] sm:max-h-[calc(85dvh-2rem)] sm:w-[calc(100vw-2rem)]"}],defaultVariants:{side:"bottom",variant:"default"}}),dYn={top:"up",bottom:"down",left:"left",right:"right"},fYn=(e,t)=>e!=="auto"?e:t==="floating"?"none":"visible",C1t=g.createContext({side:"bottom",variant:"default",resolvedOverlay:"visible"}),zV=()=>g.useContext(C1t),pYn=(e,t)=>e!=="floating"?"default":t==="none"?"floating":"floatingOverlay";function BV({side:e="bottom",variant:t="default",overlay:n="auto",modal:r,disablePointerDismissal:s,children:a,...i}){const l=fYn(n,t),c=r??(l==="none"?!1:void 0),u=s??(l==="none"?!0:void 0),d=g.useMemo(()=>({side:e,variant:t,resolvedOverlay:l}),[e,t,l]);return o.jsx(C1t.Provider,{value:d,children:o.jsx(MQn,{swipeDirection:dYn[e],modal:c,disablePointerDismissal:u,...i,children:a})})}BV.displayName="Drawer";function E1t({asChild:e,children:t,...n}){const r=e&&g.isValidElement(t)?{render:t}:{};return o.jsx(QQn,{...r,...n,children:e?void 0:t})}E1t.displayName="DrawerTrigger";const q1e=g.forwardRef(({asChild:e,children:t,...n},r)=>{const s=e&&g.isValidElement(t)?{render:t}:{};return o.jsx(CQn,{ref:r,...s,...n,children:e?void 0:t})});q1e.displayName="DrawerClose";const V1e=$Qn,j1t=EQn,UV=g.forwardRef(({className:e,overlay:t,...n},r)=>{const{resolvedOverlay:s}=zV(),a=t??s;return o.jsx(_Qn,{ref:r,"data-slot":"drawer-backdrop","data-overlay":a,className:K(lYn({overlay:a}),e),...n})});UV.displayName="DrawerBackdrop";const qV=g.forwardRef(({className:e,side:t,variant:n,...r},s)=>{const a=zV(),i=t??a.side,l=n??a.variant,c=pYn(l,a.resolvedOverlay);return o.jsx(JQn,{ref:s,"data-slot":"drawer-viewport","data-variant":l,className:K(cYn({side:i,layout:c}),e),...r})});qV.displayName="DrawerViewport";const VV=g.forwardRef(({className:e,side:t,variant:n,...r},s)=>{const a=zV(),i=t??a.side,l=n??a.variant;return o.jsx(PQn,{ref:s,"data-slot":"drawer-popup","data-variant":l,className:K(uYn({side:i,variant:l}),e),...r})});VV.displayName="DrawerPopup";const T1t=K("transition-opacity duration-300 ease-[cubic-bezier(0.32,0.72,0,1)] motion-reduce:duration-0","group-data-[nested-drawer-open]/popup:opacity-0"),Hhe=()=>o.jsx("div",{"aria-hidden":!0,"data-slot":"drawer-handle",className:K("mx-auto my-2 h-1 w-12 shrink-0 rounded-full bg-surface5",T1t)});Hhe.displayName="DrawerHandleBar";const N1t=({side:e,variant:t})=>t!=="floating"||e!=="left"&&e!=="right"?null:o.jsx("div",{"aria-hidden":!0,"data-slot":"drawer-side-handle",className:K("absolute top-1/2 z-10 flex h-20 w-5 -translate-y-1/2 touch-none select-none items-center justify-center cursor-ew-resize lg:hidden",e==="right"?"-left-2":"-right-2"),children:o.jsx("div",{className:"h-10 w-1 rounded-full bg-surface5/80 shadow-sm"})});N1t.displayName="DrawerFloatingSideHandle";const I1t=g.forwardRef(({className:e,children:t,variant:n,showCloseButton:r=!0,...s},a)=>{const{side:i,variant:l,resolvedOverlay:c}=zV(),u=n??l,d=i==="top"||i==="bottom";return o.jsxs(V1e,{children:[c!=="none"&&o.jsx(UV,{}),o.jsx(qV,{variant:u,children:o.jsxs(VV,{ref:a,variant:u,className:e,...s,children:[d&&i==="bottom"&&o.jsx(Hhe,{}),o.jsx(N1t,{side:i,variant:u}),o.jsxs("div",{"data-slot":"drawer-content",className:K("relative flex min-h-0 flex-1 flex-col",T1t),children:[r&&o.jsx(A1t,{}),t]}),d&&i==="top"&&o.jsx(Hhe,{})]})})]})});I1t.displayName="DrawerContent";const A1t=()=>o.jsx(q1e,{asChild:!0,children:o.jsx(de,{type:"button",variant:"ghost",size:"icon-sm",className:"absolute top-3 right-3 z-10","aria-label":"Close",children:o.jsx(Fu,{})})});A1t.displayName="DrawerDefaultCloseButton";const HV=g.forwardRef(({className:e,...t},n)=>o.jsx(GQn,{ref:n,className:K("text-ui-md font-medium text-neutral6",e),...t}));HV.displayName="DrawerTitle";const H1e=g.forwardRef(({className:e,...t},n)=>o.jsx(jQn,{ref:n,className:K("text-ui-sm text-neutral3",e),...t}));H1e.displayName="DrawerDescription";const U7=({direction:e,label:t,children:n})=>o.jsxs(BV,{side:e,children:[o.jsx(E1t,{asChild:!0,children:o.jsx("button",{type:"button","aria-label":t,className:K(v1t,"absolute top-2 z-10",e==="left"?"left-2":"right-2"),children:o.jsx(Ue,{children:o.jsx(g1t,{side:e})})})}),o.jsxs(V1e,{keepMounted:!0,children:[o.jsx(UV,{}),o.jsx(qV,{children:o.jsxs(VV,{className:"w-[calc(100vw-2.5rem)] max-w-[28rem]",children:[o.jsx(HV,{className:"sr-only",children:t}),o.jsx("div",{className:"flex min-h-0 flex-1 flex-col",children:n})]})})]})]}),hYn=al("block pointer-events-none transition-all duration-150 ease-out motion-reduce:transition-none",{variants:{variant:{line:"h-3/4 w-px bg-linear-to-b from-transparent via-neutral6/25 to-transparent opacity-0",pill:"h-10 w-0.5 rounded-full bg-surface5"}},defaultVariants:{variant:"line"}}),R1t=({variant:e,className:t})=>o.jsx("span",{"aria-hidden":!0,className:K(hYn({variant:e}),t)}),mYn={line:K("group-hover/separator:opacity-100","group-data-[separator='hover']/separator:opacity-100","group-data-[separator='active']/separator:opacity-100 group-data-[separator='active']/separator:via-neutral6/45","group-focus-visible/separator:opacity-100 group-focus-visible/separator:via-accent1"),pill:K("group-hover/separator:h-12 group-hover/separator:w-1","group-data-[separator='hover']/separator:h-12 group-data-[separator='hover']/separator:w-1","group-data-[separator='active']/separator:h-12 group-data-[separator='active']/separator:w-1 group-data-[separator='active']/separator:bg-accent1","group-focus-visible/separator:bg-accent1")},fM=({variant:e="line"})=>o.jsx(m1t,{className:K("group/separator relative w-0 bg-transparent z-10","focus:outline-hidden focus-visible:outline-hidden"),children:o.jsx("span",{"aria-hidden":!0,className:"absolute inset-y-0 -left-1 -right-1 flex items-center justify-center cursor-col-resize touch-none",children:o.jsx(R1t,{variant:e,className:mYn[e]})})}),P1t=380,i8e=P1t,gYn=8,o8e=e=>Math.max(e-gYn,0),vYn=({workflowId:e,children:t,leftSlot:n,rightSlot:r})=>{const s=Jwt(),[a,i]=g.useState(()=>o8e(i8e)),{defaultLayout:l,onLayoutChange:c}=h1t({id:`workflow-layout-v6-${e}`,storage:localStorage});return s?o.jsxs("div",{className:"relative h-full w-full overflow-hidden",children:[o.jsx("div",{className:"h-full w-full min-w-0 overflow-y-auto",children:t}),n&&o.jsx(U7,{direction:"left",label:"Open left panel",children:n}),r&&o.jsx(U7,{direction:"right",label:"Open right panel",children:r})]}):o.jsxs("div",{className:"relative h-full min-h-0 w-full min-w-0 overflow-hidden",style:{"--workflow-left-panel-width":`${n?a:0}px`},children:[o.jsx("div",{className:"absolute inset-0 min-w-0 overflow-y-auto",children:t}),n&&o.jsxs(dM,{className:"pointer-events-none absolute inset-0 z-10 h-full min-h-0 w-full min-w-0 bg-transparent",defaultLayout:l,onLayoutChange:c,children:[o.jsx(Uhe,{direction:"left",id:"left-slot",minSize:P1t,maxSize:"50%",defaultSize:i8e,collapsedSize:0,collapsible:!0,className:"pointer-events-auto min-w-0 bg-transparent",onResize:u=>i(o8e(u.inPixels)),children:n}),o.jsx(fM,{}),o.jsx(Dw,{id:"left-overlay-filler",className:"pointer-events-none min-w-0 bg-transparent"})]}),r&&o.jsxs(dM,{className:"pointer-events-none absolute inset-0 z-10 h-full min-h-0 w-full min-w-0 bg-transparent",defaultLayout:l,onLayoutChange:c,children:[o.jsx(Dw,{id:"right-overlay-filler",className:"pointer-events-none min-w-0 bg-transparent"}),o.jsx(fM,{}),o.jsx(Uhe,{direction:"right",id:"right-slot",minSize:300,maxSize:"40%",defaultSize:340,collapsedSize:0,collapsible:!0,className:"pointer-events-auto min-w-0 bg-transparent",children:r})]})]})},WV=({threadId:e,agentId:t,memory:n})=>{const r=We(),{requestContext:s}=_s();return wt({queryKey:["memory","messages",e,t,"requestContext"],queryFn:async()=>e?await r.listThreadMessages(e,{agentId:t,requestContext:s,includeSystemReminders:!0}):null,enabled:n&&!!e,staleTime:0,gcTime:0,retry:!1,refetchOnWindowFocus:!1})};async function $1t(){const e=await fetch("https://mastra.ai/api/templates.json");if(!e.ok)throw new Error(`Failed to fetch templates: ${e.statusText}`);const t=await e.json(),n=[{title:"Weather Agent",slug:"weather-agent",githubUrl:"https://github.com/mastra-ai/weather-agent",description:"Get weather information of any city.",longDescription:"One Agent, one Workflow and one Tool to bring you the weather in your city.",imageURL:"",tags:["Agent","Workflow","Tool"],useCase:"",supportedProviders:["openai","anthropic","google","groq"],agents:["weatherAgent"],tools:["weatherTool"],workflows:["weatherWorkflow"]},...t],r=Array.from(new Set(n.flatMap(a=>a.tags))),s=Array.from(new Set(n.flatMap(a=>a.supportedProviders)));return{templates:n,tags:r,providers:s}}async function yYn({repo:e,owner:t}){const n=await fetch(`https://api.github.com/repos/${t}/${e}`);if(!n.ok)throw new Error(`Failed to fetch template: ${n.statusText}`);const r=await n.json();if(!r.is_template)throw new Error("Repo is not a template, please update the repo settings to make it a template");return{title:r.name,slug:r.name,description:r.description??"",imageURL:"",tags:[],useCase:"",longDescription:r.description??"",githubUrl:r.html_url,supportedProviders:[]}}async function bYn({repoOrSlug:e,owner:t}){const{templates:n}=await $1t(),r=n.find(s=>s.slug===e);if(!r){if(e.startsWith("template-")){const a=n.find(i=>`template-${i.slug}`===e);if(a)return a}const s=await yYn({repo:e,owner:t});if(s)return s;throw new Error(`Template ${e} not found`)}return r}async function xYn({repo:e,owner:t,branch:n}){const r=`https://raw.githubusercontent.com/${t}/${e}/${n}/.env.example`,s=await fetch(r);return s.ok?(await s.text()).split(`
|
|
343
343
|
`).reduce((l,c)=>{if(!c||c.startsWith("#"))return l;const[u,d]=c.split("=");return u&&(l[u]=d?.split("")?.every(f=>f==="*")?"":d?.replaceAll('"',"")),l},{}):{}}const wYn=()=>wt({queryKey:["mastra-templates"],queryFn:$1t}),SYn=({repoOrSlug:e,owner:t})=>wt({queryKey:["template-repo",e,t],queryFn:()=>bYn({repoOrSlug:e,owner:t})}),kYn=({repo:e,owner:t,branch:n})=>wt({queryKey:["template-repo-env-vars",e,t,n],queryFn:()=>xYn({repo:e,owner:t,branch:n})}),OYn=()=>{const e=We();return wt({queryKey:["agent-builder-workflow"],queryFn:async()=>await e.getAgentBuilderAction("merge-template").details()})},_Yn=()=>{const e=We();return Rn({mutationFn:async({runId:t})=>await e.getAgentBuilderAction("merge-template").createRun({runId:t})})},CYn=()=>{const e=We();return Rn({mutationFn:async({runId:t})=>await e.getAgentBuilderAction("merge-template").runById(t)})},l8e=e=>{if(typeof e=="string")return e;if(e==null)return"Unknown error";if(e instanceof Error)return typeof e.message=="string"&&e.message.length>0?e.message:"Unknown error";if(typeof e=="object")try{return JSON.stringify(e)}catch{return String(e)}return String(e)},c8e=(e,t,n)=>{let r={...t};if(!(r.payload?.workflowState?.steps&&Object.keys(r.payload.workflowState.steps).length>0)&&n?.allSteps&&(r.payload={...r.payload,workflowState:{...r.payload?.workflowState,steps:Object.keys(n.allSteps).reduce((a,i)=>(a[i]={id:i,description:n.allSteps[i].description,status:"pending"},a),{})}}),e.type==="start"||e.type==="workflow-start"){const a={};n?.allSteps&&Object.entries(n.allSteps).forEach(([l,c])=>{a[l]={id:c.id,description:c.description,status:"pending"}});const i=e.runId||e.payload?.runId;r={...r,runId:i,eventTimestamp:new Date().toISOString(),status:"running",phase:"initializing",payload:{workflowState:{status:"running",steps:a},currentStep:null}}}if(e.type==="step-start"||e.type==="workflow-step-start"){const a=e.payload.id;r={...r,phase:"processing",payload:{...r.payload,currentStep:{id:a,status:"running",startTime:new Date,...e.payload},workflowState:{...r.payload.workflowState,steps:{...r.payload.workflowState.steps,[a]:{...r.payload.workflowState.steps[a],status:"running",startTime:new Date,...e.payload}}}}}}if(e.type==="step-result"||e.type==="workflow-step-result"){const a=e.payload.id,i=e.payload.status,l=e.payload.error;if(r={...r,payload:{...r.payload,currentStep:{...r.payload.currentStep,status:e.payload.status,output:e.payload.output,error:e.payload.error,endTime:new Date},workflowState:{...r.payload.workflowState,steps:{...r.payload.workflowState.steps,[a]:{...r.payload.workflowState.steps[a],status:e.payload.status,output:e.payload.output,error:e.payload.error,endTime:new Date}}}}},i==="failed"&&l){const c=l8e(l);r={...r,status:"failed",error:c,phase:"error",failedStep:{id:a,error:c,description:e.payload.description||a},payload:{...r.payload,workflowState:{...r.payload.workflowState,status:"failed"}},errorTimestamp:new Date}}}if((e.type==="step-finish"||e.type==="workflow-step-finish")&&(r={...r,payload:{...r.payload,currentStep:null}}),(e.type==="finish"||e.type==="workflow-finish")&&(r.phase==="error"||r.status==="failed"?r={...r,completedAt:new Date}:r={...r,status:e.payload.status||"completed",phase:"completed",payload:{...r.payload,currentStep:null,workflowState:{...r.payload.workflowState,status:e.payload.status||"completed"}},completedAt:new Date}),e.type==="error"){const a=l8e(e.payload.error);r={...r,status:"failed",error:a,phase:"error",payload:{...r.payload,workflowState:{...r.payload.workflowState,status:"failed"}},errorTimestamp:new Date}}return{newState:r}},EYn=(e,t)=>{try{localStorage.setItem(`template-install-${e}`,JSON.stringify({state:t,timestamp:Date.now()}))}catch(n){console.warn("Failed to save template state to localStorage:",n)}},M1t=(e,t)=>{const[n,r]=g.useState({}),[s,a]=g.useState(!1);return{streamResult:n,isStreaming:s,processStream:async(l,c)=>{if(a(!0),r({}),!l)throw new Error("No stream returned");const u=l.getReader();let d={runId:c||t,eventTimestamp:new Date().toISOString(),phase:"running",payload:{workflowState:{steps:{}},currentStep:null}};try{for(;;){const{done:f,value:p}=await u.read();if(f)break;const{newState:h}=c8e(p,d,e);if(d=h,r(h),p.runId||c||t){const m=p.runId||c||t;EYn(m,h)}}}catch(f){console.error("💥 [processStream] Error processing template installation stream:",f);const{newState:p}=c8e({type:"error",payload:{error:f instanceof Error?f.message:"Unknown error"}},d,e);r(p)}finally{a(!1),u.releaseLock()}}}},jYn=e=>{const t=We(),{streamResult:n,isStreaming:r,processStream:s}=M1t(e);return{streamInstall:Rn({mutationFn:async({inputData:i,selectedModel:l,runId:c})=>{for(let d=1;d<=3;d++)try{const f=t.getAgentBuilderAction("merge-template"),p=new u_;p.set("selectedModel",l);const h=await f.stream({inputData:i,requestContext:p},c);await s(h,c);return}catch(f){console.error(`💥 [streamInstall] Attempt ${d} failed:`,f);const p=f?.message?.includes("Failed to fetch")||f?.message?.includes("NetworkError")||f?.message?.includes("network error")||f?.message?.includes("fetch")||f?.code==="NETWORK_ERROR"||f?.name==="TypeError";if(console.warn(`Stream attempt ${d}/3 failed:`,f),p){const h=c?`Network error during template installation (likely hot reload). Please refresh the page to resume from where you left off using runId: ${c}`:"Network error during template installation (likely hot reload). Please try again.";throw console.error("🔌 Stream network error:",h),new Error(h)}throw console.error("❌ [streamInstall] Non-network error or max retries reached, throwing:",f),f}}}),streamResult:n,isStreaming:r}},TYn=e=>{const t=We(),{streamResult:n,isStreaming:r,processStream:s}=M1t(e);return{observeInstall:Rn({mutationFn:async({runId:i})=>{for(let u=1;u<=3;u++)try{const f=await t.getAgentBuilderAction("merge-template").observeStream({runId:i});await s(f,i);return}catch(d){console.error(`💥 [observeInstall] Attempt ${u} failed:`,d);const f=d?.message?.includes("Failed to fetch")||d?.message?.includes("NetworkError")||d?.message?.includes("network error")||d?.message?.includes("fetch")||d?.code==="NETWORK_ERROR"||d?.name==="TypeError";if(console.warn(`ObserveStream attempt ${u}/3 failed:`,d),f&&u<3){console.info(`🔄 ObserveStream network error detected (likely hot reload), retrying in 2000ms... (attempt ${u+1}/3)`),await new Promise(p=>setTimeout(p,2e3));continue}throw console.error("❌ [observeInstall] Non-network error or max retries reached, throwing:",d),d}}}),streamResult:n,isStreaming:r}},NYn={"background-task-running":"running","background-task-output":"running","background-task-completed":"completed","background-task-failed":"failed","background-task-cancelled":"cancelled","background-task-suspended":"suspended","background-task-resumed":"running"};function IYn(e={}){const{enabled:t=!0,agentId:n,runId:r,threadId:s,resourceId:a,taskId:i}=e,l=We(),[c,u]=g.useState({}),[d,f]=g.useState(!1),[p,h]=g.useState(null),m=g.useRef(null),v=g.useRef(null),y=g.useRef(0),b=g.useMemo(()=>Object.values(c).filter(N=>N.status==="running"),[c]),S=g.useMemo(()=>Object.values(c).filter(N=>N.status==="completed"),[c]),w=g.useMemo(()=>Object.values(c).filter(N=>N.status==="failed"),[c]),k=g.useCallback(()=>{v.current?.cancel().catch(()=>{}),v.current=null,m.current?.abort(),m.current=null,f(!1)},[]),_=g.useCallback(async()=>{const N=++y.current;k(),h(null);const I=new AbortController;m.current=I;try{const R=await l.streamBackgroundTasks({agentId:n,runId:r,threadId:s,resourceId:a,taskId:i});if(!R){h(new Error("Stream connection failed"));return}N===y.current&&f(!0);const P=R.getReader();for(v.current=P;!I.signal.aborted;){const{done:L,value:M}=await P.read();if(L)break;const q=M;q.type!=="background-task-output"&&u(H=>({...H,[q.payload.taskId]:{...H[q.payload.taskId],...q.payload,status:NYn[q.type]}}))}}catch(R){R?.name!=="AbortError"&&N===y.current&&h(R instanceof Error?R:new Error(String(R)))}finally{N===y.current&&f(!1)}},[l,n,r,s,a,i,k]);g.useEffect(()=>{if(!t){k();return}return _(),k},[t,_,k]);const C=g.useCallback(()=>{k()},[k]),E=g.useCallback(()=>{_()},[_]);return{tasks:c,isConnected:d,error:p,disconnect:C,reconnect:E,runningTasks:b,completedTasks:S,failedTasks:w,clearCompletedAndFailedTasks:()=>{u(N=>{const I={...N};return Object.values(I).forEach(R=>{(R.status==="completed"||R.status==="failed"||R.status==="cancelled"||R.status==="timed_out")&&delete I[R.taskId]}),I})}}}const AYn=(e,t=!0)=>{const n=We();return wt({queryKey:["background-task",e],queryFn:()=>n.getBackgroundTask(e),enabled:t})};function u8e(e){if(!e)return;const t=e instanceof Date?e.getTime():new Date(e).getTime();return Number.isFinite(t)?t:void 0}function RYn({debugMode:e,tracingOptions:t,setIsRunning:n}){const{streamWorkflow:r,streamResult:s,isStreaming:a,observeWorkflowStream:i,closeStreamsAndReset:l,resumeWorkflowStream:c,timeTravelWorkflowStream:u}=Svn({debugMode:e,tracingOptions:t,onError:m=>De.error(m.message)}),d=g.useCallback(m=>(n(!0),r.mutateAsync(m)),[n,r]),f=g.useCallback(m=>(n(!0),c.mutateAsync(m)),[c,n]),p=g.useCallback(m=>(n(!0),i.mutate(m)),[i,n]),h=g.useCallback(m=>(n(!0),u.mutateAsync(m)),[n,u]);return{streamResult:s,isStreaming:a,closeStreamsAndReset:l,startStreamWorkflow:d,startResumeWorkflow:f,startObserveWorkflowStream:p,startTimeTravelWorkflowStream:h}}function W1e({children:e,snapshot:t,workflowId:n,initialRunId:r,withoutTimeTravel:s=!1}){const[a,i]=g.useState(()=>t?Hfe(t):null),[l,c]=g.useState(()=>t?.context?.input??null),[u,d]=g.useState(()=>r??""),f=g.useRef(r??t?.runId??""),[p,h]=g.useState(!1),[m,v]=g.useState(!1),y=p||["success","failed","canceled","bailed"].includes(a?.status??"")?void 0:5e3,{isLoading:b,data:S}=Kwt(n,r??"",y),w=g.useMemo(()=>S&&r?{context:{input:S?.payload,...S?.steps},status:S?.status,result:S?.result,error:S?.error,runId:r,serializedStepGraph:S?.serializedStepGraph,timestamp:u8e(S?.updatedAt)??u8e(S?.createdAt),value:S?.initialState}:void 0,[S,r]),{data:k,isLoading:_,error:C}=S3(n),{settings:E}=tV(),j=kvn(),N=Ovn(),{streamResult:I,isStreaming:R,closeStreamsAndReset:P,startStreamWorkflow:L,startResumeWorkflow:M,startObserveWorkflowStream:q,startTimeTravelWorkflowStream:H}=RYn({debugMode:m,tracingOptions:E?.tracingOptions,setIsRunning:h}),F=g.useCallback(()=>{i(null),c(null)},[]);g.useEffect(()=>{h(!1)},[r]),g.useEffect(()=>{if(w?.runId){f.current=w.runId,i(Hfe(w)),w.value&&Object.keys(w.value).length>0?c({initialState:w.value,inputData:w.context?.input}):c(w.context?.input),d(w.runId);return}!r&&f.current&&(f.current="",i(null),c(null),d(""),h(!1))},[r,w]);const z=g.useMemo(()=>({workflowId:n,result:a,setResult:i,payload:l,setPayload:c,clearData:F,snapshot:t,runId:u,setRunId:d,workflowError:C??null,workflow:k??void 0,isLoading:_,createWorkflowRun:j.mutateAsync,streamWorkflow:L,resumeWorkflow:M,streamResult:I,isStreamingWorkflow:R,isCancellingWorkflowRun:N.isPending,cancelWorkflowRun:N.mutateAsync,observeWorkflowStream:q,closeStreamsAndReset:P,timeTravelWorkflowStream:H,runSnapshot:w,isLoadingRunExecutionResult:b,withoutTimeTravel:s,debugMode:m,setDebugMode:v}),[n,a,l,F,t,u,C,k,_,j.mutateAsync,L,M,I,R,N.isPending,N.mutateAsync,q,P,H,w,b,s,m]);return o.jsx($l.Provider,{value:z,children:e})}function D1t({children:e}){const[t,n]=g.useState(null),[r,s]=g.useState(null),a=g.useMemo(()=>({selectedStepId:t,hoverStepId:r,setSelectedStepId:n,setHoverStepId:s}),[t,r]);return o.jsx(Ypt.Provider,{value:a,children:e})}const L1t=g.createContext(null);function ZV(){const e=g.useContext(L1t);if(!e)throw new Error("useWorkflowStepDetail must be used within WorkflowStepDetailProvider");return e}function Z1e({children:e}){const[t,n]=g.useState(null),r=g.useCallback(({stepName:i,stepId:l,mapConfig:c})=>{n({type:"map-config",stepName:i,stepId:l,mapConfig:c})},[]),s=g.useCallback(({label:i,stepGraph:l,fullStep:c})=>{n({type:"nested-graph",stepName:i,nestedGraph:{label:i,stepGraph:l,fullStep:c}})},[]),a=g.useCallback(()=>{n(null)},[]);return o.jsx(L1t.Provider,{value:{stepDetail:t,showMapConfig:r,showNestedGraph:s,closeStepDetail:a},children:e})}const PYn=({children:e})=>{const{workflowId:t,runId:n}=ur(),{data:r,isLoading:s}=S3(t),{data:a,isLoading:i}=Kwt(t??"",n??"");if(!t)return o.jsx("div",{className:"flex h-full flex-col items-center justify-center",children:o.jsx(ge,{variant:"ui-md",className:"text-neutral6 text-center",children:"No workflow ID provided"})});if(s||n&&i)return o.jsx("div",{className:"h-full p-4",children:o.jsx(bt,{className:"h-full"})});const l=a&&n?{context:{input:a?.payload,...a?.steps},status:a?.status,result:a?.result,error:a?.error,runId:n,serializedStepGraph:a?.serializedStepGraph}:void 0;return o.jsx(r0e,{entityId:t,entityType:"workflow",children:o.jsx(HD,{children:o.jsx(W1e,{snapshot:l,workflowId:t,initialRunId:n,children:o.jsx(D1t,{children:o.jsx(Z1e,{children:o.jsxs("div",{className:"h-full min-h-0",children:[o.jsx(zCn,{workflowName:r?.name||"",workflowId:t}),o.jsx(vYn,{workflowId:t,leftSlot:o.jsx(PGn,{workflowId:t,initialRunId:n}),children:e})]})})})})})})};function F1t({sidebar:e,children:t,tracePanel:n,contentPadding:r=!0}){const s=!!(t||n);return o.jsxs("div",{className:"flex h-full min-h-0 bg-surface2 text-neutral4",children:[e?o.jsx("aside",{className:"min-h-0 w-[22rem] shrink-0 border-r border-border1",children:e}):null,s?o.jsx("main",{className:r?"min-w-0 flex-1 p-4":"min-w-0 flex-1",children:o.jsxs(dM,{className:"h-full min-h-0 w-full min-w-0",direction:"horizontal",children:[t?o.jsx(Dw,{id:"topic-main",className:"min-w-0 pr-2",minSize:35,children:t}):null,n?o.jsxs(o.Fragment,{children:[t?o.jsx(fM,{}):null,o.jsx(Uhe,{direction:"right",id:"topic-trace-details",minSize:300,maxSize:"70%",defaultSize:t?"40%":"100%",collapsedSize:60,collapsible:!0,className:"min-w-0 pl-2",children:n})]}):null]})}):null]})}const z1t=g.createContext("horizontal"),$Yn=al(K("flex","[&>*:hover]:relative [&>*:hover]:z-10","[&>*:focus-visible]:relative [&>*:focus-visible]:z-10","[&>*:has(:focus-visible)]:relative [&>*:has(:focus-visible)]:z-10"),{variants:{orientation:{horizontal:"flex-row items-center",vertical:"flex-col items-stretch"},spacing:{default:"gap-2",close:"gap-0"}},compoundVariants:[{orientation:"horizontal",spacing:"close",className:K("[&>*:has(~_*:not([aria-hidden=true]):not([data-base-ui-focus-guard]):not([aria-owns]))]:rounded-r-none","[&>*:not(:first-child):not([aria-hidden=true]):not([data-base-ui-focus-guard]):not([aria-owns])]:rounded-l-none","[&>*:not([data-slot=buttons-group-separator]):not([aria-hidden=true]):not([data-base-ui-focus-guard]):not([aria-owns]):not(:first-child)]:-ml-px","[&>*:not([data-slot=buttons-group-separator]):not([data-slot=buttons-group-text]):not([data-variant=default]):not([data-variant=primary]):not([aria-hidden=true]):not([data-base-ui-focus-guard]):not([aria-owns]):not(:first-child):not(:hover):not(:focus-visible):not(:has(:focus-visible))]:border-l-transparent","[&>[data-variant=primary]:not([aria-hidden=true]):not(:first-child)]:shadow-[inset_1px_0_0_0_var(--color-border1)]","[&>*:not([data-slot=buttons-group-separator]):not([aria-hidden=true])]:transition-[color,background-color]","[&>[data-slot=select-trigger]]:w-fit [&>[data-slot=select-trigger]]:flex-none","[&>input]:flex-1")},{orientation:"vertical",spacing:"close",className:K("[&>*:not(:last-child)]:rounded-b-none","[&>*:not(:first-child)]:rounded-t-none","[&>:first-child]:rounded-t-xl","[&>:last-child]:rounded-b-xl","[&>*:not([data-slot=buttons-group-separator]):not(:first-child)]:-mt-px","[&>*:not([data-slot=buttons-group-separator]):not([data-slot=buttons-group-text]):not([data-variant=default]):not([data-variant=primary]):not(:first-child):not(:hover):not(:focus-visible):not(:has(:focus-visible))]:border-t-transparent","[&>[data-variant=primary]:not(:first-child)]:shadow-[inset_0_1px_0_0_var(--color-border1)]","[&>*:not([data-slot=buttons-group-separator])]:transition-[color,background-color]")}],defaultVariants:{orientation:"horizontal",spacing:"default"}}),Mr=g.forwardRef(({children:e,className:t,orientation:n="horizontal",spacing:r="default",...s},a)=>o.jsx(z1t.Provider,{value:n,children:o.jsx("div",{ref:a,role:"group","data-slot":"buttons-group","data-orientation":n,className:K($Yn({orientation:n,spacing:r}),t),...s,children:e})}));Mr.displayName="ButtonsGroup";const MYn=g.forwardRef(({className:e,orientation:t,...n},r)=>{const s=g.useContext(z1t),a=t??(s==="vertical"?"horizontal":"vertical");return o.jsx("div",{ref:r,role:"separator","aria-orientation":a,"data-slot":"buttons-group-separator",className:K("self-stretch bg-border1",a==="vertical"?"w-px":"h-px",e),...n})});MYn.displayName="ButtonsGroupSeparator";const DYn=al(K("inline-flex items-center justify-center bg-surface3 border border-border1 text-neutral5 select-none","rounded-full gap-[.75em] px-[1em] whitespace-nowrap shrink-0","[&>svg]:w-[1.1em] [&>svg]:h-[1.1em] [&>svg]:opacity-50"),{variants:{size:{xs:Gd.xs,sm:Gd.sm,md:Gd.md,default:Gd.default,lg:Gd.lg}},defaultVariants:{size:"default"}}),Fh=g.forwardRef(({className:e,size:t="default",...n},r)=>o.jsx("div",{ref:r,"data-slot":"buttons-group-text",className:K(DYn({size:t}),e),...n}));Fh.displayName="ButtonsGroupText";function LYn({collapsed:e,children:t}){return o.jsx("section",{className:K("flex flex-col bg-surface2 border border-border1 rounded-xl overflow-hidden",e?"h-auto":"h-full"),children:t})}function FYn({onClick:e,tooltip:t="Close panel",className:n}){return o.jsx(de,{size:"md",onClick:e,"aria-label":"Close Panel",tooltip:t,className:n,children:o.jsx(Fu,{})})}function zYn(){return UN({settings:{fontFamily:"var(--font-mono)",fontSize:"0.75rem",lineHighlight:"transparent",gutterBackground:"transparent",gutterForeground:"#939393",background:"transparent"},styles:[{tag:[fe.className,fe.propertyName]}]})}function BYn(){const e=It.theme({"&":{backgroundColor:"transparent",color:"var(--neutral6)",fontSize:"0.75rem"},"&.cm-editor .cm-scroller":{fontFamily:"var(--font-mono)"},".cm-gutters":{backgroundColor:"transparent",color:"var(--neutral2)",borderRight:"none"},".cm-content":{color:"var(--neutral6)",caretColor:"var(--neutral6)"},".cm-activeLine":{backgroundColor:"transparent"},".cm-activeLineGutter":{backgroundColor:"transparent"},".cm-cursor, .cm-dropCursor":{borderLeftColor:"var(--neutral6)"}}),t=Dg.define([{tag:[fe.comment,fe.bracket],color:"var(--neutral2)"},{tag:[fe.string,fe.meta,fe.regexp],color:"var(--accent1)"},{tag:[fe.atom,fe.bool,fe.special(fe.variableName)],color:"var(--accent6)"},{tag:[fe.keyword,fe.operator,fe.tagName],color:"var(--accent2)"},{tag:[fe.function(fe.propertyName),fe.propertyName],color:"var(--accent5)"},{tag:[fe.definition(fe.variableName),fe.function(fe.variableName),fe.className,fe.attributeName],color:"var(--accent3)"},{tag:[fe.variableName,fe.number],color:"var(--accent5)"},{tag:[fe.name,fe.quote],color:"var(--accent1)"}]);return[e,B1(t)]}const UYn=()=>{const e=PN().resolvedTheme==="dark";return g.useMemo(()=>e?zYn():BYn(),[e])};function qYn({codeStr:e="",title:t,icon:n,simplified:r=!1,className:s}){const a=UYn(),[i,l]=g.useState(!1),c=g.useMemo(()=>{try{const f=JSON.parse(e);return Whe(f||"")}catch{return!1}},[e]),u=i?e?.replace(/\\n/g,`
|
|
344
344
|
`):e,d=r||i;return!e||e==="null"?null:o.jsxs("div",{className:K("flex flex-col gap-2",s),children:[o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsxs("div",{className:K("flex items-center gap-1.5 text-ui-xs uppercase tracking-widest text-neutral2","[&>svg]:size-3.5"),children:[n,t]}),o.jsxs(Mr,{children:[o.jsx(Oa,{content:e||"No content",size:"sm"}),c&&o.jsx(de,{size:"sm","aria-label":i?"Show escaped newlines":"Show multiline text",onClick:()=>l(f=>!f),children:i?o.jsx(s$,{}):o.jsx(Pz,{})})]})]}),o.jsx("div",{className:"dark:bg-black/20 bg-surface3 p-3 overflow-hidden rounded-lg border dark:border-white/10 border-border1 text-neutral4 text-ui-sm break-all max-h-[30vh] overflow-y-auto",children:d?o.jsx("div",{className:"text-neutral4 font-mono break-all",children:o.jsx("pre",{className:"text-wrap",children:u})}):o.jsx(ru,{extensions:[gT(),It.lineWrapping],theme:a,value:e,editable:!1})})]})}function Whe(e){if(typeof e=="string"){const t=e.indexOf(`
|
|
345
|
-
`);return t!==-1&&t!==e.length-1}else{if(Array.isArray(e))return e.some(t=>Whe(t));if(e&&typeof e=="object")return Object.values(e).some(t=>Whe(t))}return!1}function VYn({children:e}){return o.jsx("div",{className:"flex-1 p-4 overflow-y-auto",children:e})}function HYn({className:e,children:t}){return o.jsx("div",{className:K("flex items-center justify-between gap-2 border-b border-border1 mx-4 py-3",e),children:t})}function WYn({className:e,children:t}){return o.jsx("h3",{className:K("flex gap-2 text-ui-md text-neutral3 [&>b]:text-neutral2 [&>b]:font-normal",e),children:t})}function ZYn({className:e,children:t}){return o.jsx("dl",{className:K("grid grid-cols-[auto_1fr] gap-x-4 gap-y-1.5",e),children:t})}function GYn({className:e,children:t}){return o.jsx("dt",{className:K("text-ui-smd text-neutral2 shrink-0 py-0.5",e),children:t})}function QYn({className:e,children:t}){return o.jsx("dd",{className:K("text-ui-smd text-neutral3 truncate min-w-0 py-0.5",e),children:t})}function YYn({className:e,children:t}){return o.jsx("dt",{className:K("col-span-2 text-ui-sm uppercase tracking-widest text-neutral2 py-3",e),children:t})}const XYn=Object.assign(ZYn,{Key:GYn,Value:QYn,Header:YYn});function KYn({children:e}){return o.jsxs("div",{className:"flex items-center justify-center gap-2 px-4 py-6 text-ui-sm text-neutral3",children:[o.jsx(Gt,{size:"sm",variant:"pulse",className:"text-neutral3"})," ",e??"Loading..."]})}function JYn({children:e}){return o.jsx("p",{className:"px-4 py-6 text-ui-sm text-neutral2",children:e??"No data found."})}const Mi=Object.assign(LYn,{Header:HYn,Heading:WYn,CloseButton:FYn,LoadingData:KYn,NoData:JYn,Content:VYn,KeyValueList:XYn,CodeSection:qYn}),eXn=e=>e.replace(/\/+$/,"");function tXn(e){const t=`${eXn(e.baseUrl)}/api/learning`,n=(a,i)=>{const l=new URL(`${t}${a}`);if(i)for(const[c,u]of Object.entries(i))u!==void 0&&l.searchParams.set(c,String(u));return l.toString()};async function r(a){const i=await fetch(a,{credentials:"include",headers:e.projectId?{"X-Mastra-Project-Id":e.projectId}:void 0});if(!i.ok)throw new Error(`Entity-Learning request failed (${i.status}): ${a}`);return await i.json()}const s=a=>encodeURIComponent(a);return{getEntities(){return r(n("/entities"))},getEntityRuns(a,i){return r(n(`/entities/${s(a)}/runs`,{signalName:i}))},getEntityRun(a,i,l){return r(n(`/entities/${s(a)}/runs/${s(i)}`,{signalName:l}))},getEntityLearning(a,i,l){return r(n(`/entities/${s(a)}/learning`,{signalName:i,runId:l}))},getEntityTopics(a,i,l){return r(n(`/entities/${s(a)}/topics`,{signalName:i,runId:l}))},getEntityTopic(a,i,l,c){return r(n(`/entities/${s(a)}/topics/${s(i)}`,{signalName:l,runId:c}))},getEntityTopicExamples(a,i,l){return r(n(`/entities/${s(a)}/topics/${s(i)}/examples`,{signalName:l.signalName,runId:l.runId,limit:l.limit}))},getEntityPoints(a,i){return r(n(`/entities/${s(a)}/points`,{signalName:i.signalName,runId:i.runId,includeOutliers:i.includeOutliers,limit:i.limit}))},getEntityOutliers(a,i,l){return r(n(`/entities/${s(a)}/outliers`,{signalName:i,runId:l}))},getEntityOutlierExamples(a,i){return r(n(`/entities/${s(a)}/outliers/examples`,{signalName:i.signalName,runId:i.runId,limit:i.limit}))}}}function nXn(e){try{return new URL(e).origin}catch{return e}}function GV(){const e=typeof window>"u"?void 0:window,t=e?.MASTRA_PLATFORM_OBSERVABILITY_ENDPOINT||void 0,n=t?nXn(t):void 0,r=e?.MASTRA_ORGANIZATION_ID||void 0,s=e?.MASTRA_PLATFORM_PROJECT_ID||void 0,a=g.useMemo(()=>n?tXn({baseUrl:n,projectId:s}):null,[n,s]);return{baseUrl:n,organizationId:r,projectId:s,isConfigured:!!n,service:a}}const QV="entity-learning";function B1t(){const{service:e,isConfigured:t}=GV();return wt({queryKey:[QV,"entities"],queryFn:t&&e?()=>e.getEntities():jy,select:n=>n.entities,retry:!1})}function U1t(e,t,n){const{service:r}=GV();return wt({queryKey:[QV,"topics",e,t,"latest"],queryFn:r&&e&&t?()=>r.getEntityTopics(e,t,n):jy,retry:!1})}function rXn(e,t,n){const{service:r}=GV();return wt({queryKey:[QV,"topic-examples",e,t,n?.signalName,n?.runId,n?.limit??null],queryFn:r&&e&&t&&n?.signalName&&n?.runId?()=>r.getEntityTopicExamples(e,t,n):jy,retry:!1})}function sXn(e,t){const{service:n}=GV();return wt({queryKey:[QV,"points",e,t?.signalName,t?.runId,t?.includeOutliers??null,t?.limit??null],queryFn:n&&e&&t?.signalName&&t?.runId?()=>n.getEntityPoints(e,t):jy,retry:!1})}const aXn=[{id:"sentiment",name:"Sentiment",description:"Conversation tone and confidence shifts that affect user outcomes."},{id:"behavior",name:"Behavior",description:"Recurring interaction patterns and behaviors observed across runs."},{id:"goal",name:"Goal",description:"Inferred user goals and intents driving each interaction."},{id:"outcome",name:"Outcome",description:"Resolution outcomes and whether the user objective was met."},{id:"issue",name:"Issue",description:"Recurring issue families found across traces."},{id:"severity",name:"Severity",description:"Risk and urgency bands inferred from trace paths and intervention needs."},{id:"tasks",name:"Tasks",description:"Operational work patterns inferred from agent traces and user requests."}],iXn=e=>e.replace(/[-_]/g," ").replace(/\b\w/g,t=>t.toUpperCase());function YV(e){return aXn.find(t=>t.id===e)??{id:e,name:iXn(e),description:""}}const oXn="agent";function d8e({entities:e,selected:t,onChange:n}){const r=g.useMemo(()=>e.filter(a=>a.entityType===oXn),[e]),s=a=>{const i=r.find(l=>l.entityId===a);i&&n({entityType:i.entityType,entityId:i.entityId})};return o.jsx("div",{className:"flex flex-wrap items-center gap-3",role:"search","aria-label":"Filter signals by agent",children:o.jsxs("label",{className:"flex items-center gap-2",children:[o.jsx("span",{className:"whitespace-nowrap font-mono text-xs uppercase text-neutral3",children:"Agent"}),o.jsxs(da,{value:t?.entityId??"",onValueChange:s,disabled:r.length===0,children:[o.jsx(pa,{size:"sm",variant:"outline",className:"min-w-64","aria-label":"Agent",children:o.jsx(fa,{placeholder:"Select an agent"})}),o.jsx(ha,{children:r.map(a=>o.jsx(Lr,{value:a.entityId,children:a.entityId},a.entityId))})]})]})})}function lXn(e){let t=0;for(let r=0;r<e.length;r++)t=e.charCodeAt(r)+((t<<5)-t),t=t&t;return`hsl(${Math.abs(t*137.508)%360}, 70%, 55%)`}function cXn({topic:e,onSelect:t}){const n=Math.round(e.coverage*100),r=e.itemCount===1?"item":"items",s=lXn(e.topicId),a={"--cluster-color":s};return o.jsx("article",{role:"button",tabIndex:0,onClick:()=>t(e.topicId),onKeyDown:i=>{(i.key==="Enter"||i.key===" ")&&(i.preventDefault(),t(e.topicId))},className:"group cursor-pointer rounded-2xl border border-border1/70 bg-surface2 p-5 shadow-sm transition-colors hover:border-[var(--cluster-color)] focus-visible:border-[var(--cluster-color)] focus-visible:outline-none",style:a,children:o.jsxs("div",{className:"flex h-full min-w-0 flex-col",children:[o.jsxs("div",{className:"flex min-w-0 items-start gap-2",children:[o.jsx("span",{className:"mt-2 h-2.5 w-2.5 shrink-0 rounded-full",style:{backgroundColor:s}}),o.jsxs("div",{children:[o.jsx("h3",{className:"text-md font-semibold text-neutral6",children:e.name}),o.jsx("p",{className:"line-clamp-2 text-sm text-neutral3",children:e.description})]})]}),o.jsxs("div",{className:"space-y-1 pt-4 pl-4",children:[o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx("p",{className:"font-mono text-xs uppercase text-neutral3",children:"Coverage"}),o.jsxs("p",{className:"font-mono text-xs text-neutral3",children:[e.itemCount," ",r]})]}),o.jsxs("div",{className:"grid grid-cols-[minmax(0,1fr)_4rem] items-center gap-4",children:[o.jsx("div",{className:"h-3 overflow-hidden rounded-full bg-surface4",role:"progressbar","aria-label":`${e.name} coverage`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":n,children:o.jsx("div",{className:"h-full rounded-full",style:{width:`${n}%`,backgroundColor:s}})}),o.jsxs("p",{className:"text-right text-ui-md font-semibold text-neutral6",children:[n,"%"]})]})]})]})})}function uXn(){return o.jsx("article",{className:"rounded-2xl border border-border1/70 bg-surface2 p-5 shadow-sm","aria-hidden":"true",children:o.jsxs("div",{className:"flex h-full min-w-0 flex-col",children:[o.jsxs("div",{className:"flex min-w-0 items-start gap-2",children:[o.jsx(bt,{className:"mt-2 h-2.5 w-2.5 shrink-0 rounded-full"}),o.jsxs("div",{className:"min-w-0 flex-1 space-y-2",children:[o.jsx(bt,{className:"h-4 w-1/2"}),o.jsx(bt,{className:"h-3 w-full"})]})]}),o.jsxs("div",{className:"space-y-2 pt-4 pl-4",children:[o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx(bt,{className:"h-3 w-20"}),o.jsx(bt,{className:"h-3 w-12"})]}),o.jsx(bt,{className:"h-3 w-full rounded-full"})]})]})})}function dXn(){return o.jsx("div",{className:"grid gap-6 md:grid-cols-2","aria-label":"Loading clusters","aria-busy":"true",children:Array.from({length:4}).map((e,t)=>o.jsx(uXn,{},t))})}function fXn({entity:e,catalog:t,signalName:n,onSeeDetails:r,onSelectCluster:s}){const{data:a,isLoading:i,isError:l}=U1t(e.entityId,n),c=a?.topics??[];return o.jsxs("section",{className:"space-y-4",children:[o.jsxs("header",{className:"flex items-start justify-between gap-6 px-1",children:[o.jsxs("div",{className:"min-w-0",children:[o.jsxs("div",{className:"flex items-center gap-3",children:[o.jsx("h2",{className:"text-ui-2xl font-semibold text-neutral6",children:t.name}),i?o.jsx(bt,{className:"h-badge-default w-20 rounded-full","aria-hidden":"true"}):l?null:o.jsxs(dn,{variant:"default",children:[c.length," ",c.length===1?"cluster":"clusters"]})]}),t.description?o.jsx("p",{className:"text-ui-lg text-neutral3",children:t.description}):null]}),o.jsxs(de,{type:"button",variant:"outline",size:"lg",className:"shrink-0 gap-2 rounded-xl px-5",onClick:()=>r(n),children:["See details",o.jsx(akn,{className:"h-4 w-4","aria-hidden":"true"})]})]}),i?o.jsx(dXn,{}):l?o.jsx("p",{className:"px-1 text-ui-md text-accent2",children:"Failed to load clusters for this signal."}):c.length===0?o.jsx("p",{className:"px-1 text-ui-md text-neutral3",children:"No clusters found for this signal yet."}):o.jsx("div",{className:"grid gap-6 md:grid-cols-2",children:c.map(u=>o.jsx(cXn,{topic:u,onSelect:d=>s(n,d)},u.topicId))})]})}function pXn({selectedEntity:e,onEntityChange:t,onSignalSelect:n}){const{data:r=[],isLoading:s,isError:a}=B1t(),i=e?r.find(c=>c.entityId===e.entityId):void 0,l=!!i;return o.jsx(F1t,{sidebar:null,contentPadding:!1,children:o.jsxs("div",{className:"flex h-full min-w-0 flex-col","aria-label":"Signals",children:[l&&o.jsx("div",{className:"border-b border-border1/70 px-6 py-4",children:o.jsx(d8e,{entities:r,selected:e,onChange:t})}),o.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto p-6",children:s?o.jsx("div",{className:"flex h-full items-center justify-center",children:o.jsx(Cr,{iconSlot:o.jsx(Gt,{}),titleSlot:"Loading entities…"})}):a?o.jsx("div",{className:"flex h-full items-center justify-center",children:o.jsx(Cr,{iconSlot:o.jsx(Yq,{}),titleSlot:"Failed to load entities",descriptionSlot:"Failed to load entities from the observability endpoint."})}):r.length===0?o.jsx("div",{className:"flex h-full items-center justify-center",children:o.jsx(Cr,{iconSlot:o.jsx(I3e,{}),titleSlot:"No entities available",descriptionSlot:"No entities are available on the server yet."})}):i?i.availableSignals.length===0?o.jsx("div",{className:"flex h-full items-center justify-center",children:o.jsx(Cr,{iconSlot:o.jsx(I3e,{}),titleSlot:"No signals yet",descriptionSlot:"This entity has no signals yet."})}):o.jsx("div",{className:"mx-auto flex max-w-6xl flex-col gap-12",children:i.availableSignals.map(c=>o.jsx(fXn,{entity:i,signalName:c,catalog:YV(c),onSeeDetails:n,onSelectCluster:n},c))}):o.jsx("div",{className:"flex h-full items-center justify-center",children:o.jsx(Cr,{iconSlot:o.jsx(BOn,{}),titleSlot:"No entity selected",descriptionSlot:"Select an entity to inspect its signals and clusters.",actionSlot:o.jsx(d8e,{entities:r,selected:e,onChange:t})})})})]})})}function hXn(){const e=bs(),[t,n]=ga(),r=t.get("entityId"),s=g.useMemo(()=>r?{entityType:"agent",entityId:r}:null,[r]),a=g.useCallback(l=>{n(c=>{const u=new URLSearchParams(c);return l?u.set("entityId",l.entityId):u.delete("entityId"),u},{replace:!0})},[n]),i=g.useCallback((l,c)=>{const u=new URLSearchParams;s&&u.set("entityId",s.entityId),c&&u.set("topicId",c);const d=u.toString();e(`/signals/${l}${d?`?${d}`:""}`,{viewTransition:!0})},[e,s]);return o.jsx(pXn,{selectedEntity:s,onEntityChange:a,onSignalSelect:i})}const G1e=["data-list-row col-span-full relative mt-[3px] mb-1",'after:absolute after:inset-x-[-0.25rem] after:bottom-[-0.25rem] after:h-px after:bg-border1 after:content-[""] after:pointer-events-none',"[&:has(+.data-list-subheader)]:after:hidden [&:not(:has(~.data-list-row))]:after:hidden","transition-colors duration-200 rounded-lg"],Q1e=["grid grid-cols-subgrid gap-8 px-5 outline-none cursor-pointer","hover:bg-surface4 focus-visible:bg-surface4 focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-accent1","transition-colors duration-200 rounded-lg"],q1t=["mx-1",...Q1e,...G1e],mXn=["mx-1 grid grid-cols-subgrid gap-8 px-5",...G1e],V1t=["data-list-sticky-start sticky left-0 z-10 isolate self-stretch overflow-visible",'after:absolute after:-right-4 after:top-1/2 after:-translate-y-1/2 after:h-4 after:w-px after:bg-border2 after:content-[""] after:pointer-events-none'],Y1e=al("",{variants:{variant:{default:"",error:"bg-notice-destructive/10! hover:bg-notice-destructive/15!"}},defaultVariants:{variant:"default"}});function ko({children:e,className:t,height:n="default",as:r,sticky:s,...a}){const i=r||"span";return o.jsx(i,{className:K('relative grid min-w-0 max-w-full items-center overflow-hidden text-ui-md whitespace-nowrap text-neutral3 empty:before:content-["—"] empty:before:text-neutral2',n==="compact"?"py-1.5":"py-2.5",s==="start"&&V1t,t),...a,children:e})}const XV='block min-w-0 max-w-full truncate empty:before:content-["—"] empty:before:text-neutral2 [&>*]:min-w-0 [&>*]:max-w-full [&>*]:overflow-hidden [&>*]:text-ellipsis [&>*]:whitespace-nowrap',gXn="min-w-0 flex-1 truncate";function vXn({children:e}){return o.jsx("span",{className:gXn,children:e})}function yXn({children:e}){return g.Children.map(e,t=>typeof t=="string"||typeof t=="number"?o.jsx(vXn,{children:t}):t)}function KV({children:e}){return g.Children.map(e,t=>!g.isValidElement(t)||typeof t.type!="string"?t:g.cloneElement(t,{className:K("min-w-0 max-w-full overflow-hidden",t.props.className),children:o.jsx(yXn,{children:t.props.children})}))}function bXn({children:e,className:t,...n}){return o.jsx(ko,{className:t,...n,children:o.jsx("span",{className:XV,children:o.jsx(KV,{children:e})})})}function xXn({children:e,className:t}){return o.jsx(ko,{className:K("text-left text-neutral4",t),children:o.jsx("span",{className:XV,children:o.jsx(KV,{children:e})})})}function wXn({children:e,className:t}){return o.jsx(ko,{className:K("text-neutral2",t),children:o.jsx("span",{className:XV,children:o.jsx(KV,{children:e})})})}function SXn({children:e,className:t,...n}){return o.jsx(ko,{sticky:"start",className:K("data-list-row-header -ml-5 -mr-4 w-auto max-w-none rounded-l-md pl-5 pr-4 text-left text-ui-sm font-semibold tracking-tight text-neutral2",t),...n,children:o.jsx("span",{className:K(XV,"relative z-10 w-full"),children:o.jsx(KV,{children:e})})})}function kXn({children:e,className:t,highlight:n,height:r="compact",...s}){return o.jsx(ko,{height:r,className:K("justify-items-end text-right text-ui-sm tabular-nums",n?"text-neutral4 font-semibold":"text-neutral3",t),...s,children:e})}function OXn(e){return e?e.length>8?e.slice(0,8):e:""}function H1t({id:e}){return o.jsx(ko,{height:"compact",className:"text-ui-smd font-mono text-neutral3",children:OXn(e)})}function _Xn({checked:e,onToggle:t,...n}){return o.jsx(ko,{as:"label",height:"compact",className:"h-8 w-8 self-center cursor-pointer justify-items-center overflow-visible px-0 py-0!",onClick:r=>r.stopPropagation(),children:o.jsx(Mo,{checked:e,onCheckedChange:()=>{},onClick:r=>{r.stopPropagation(),t(r.shiftKey)},"aria-label":n["aria-label"]})})}function X1e({children:e,className:t,height:n="compact"}){return o.jsx(ko,{height:n,children:o.jsx("span",{className:K('block min-w-0 max-w-full text-ui-smd font-mono text-neutral3 truncate empty:before:content-["—"]',t),children:e})})}function W1t(e){const t=e instanceof Date?e:new Date(e);return isNaN(t.getTime())?null:t}function K1e({timestamp:e}){const t=W1t(e);return o.jsx(ko,{height:"compact",className:"text-ui-smd text-neutral2",children:t?MN(t)?"Today":er(t,"MMM dd"):null})}function J1e({timestamp:e}){const t=W1t(e);return o.jsx(ko,{height:"compact",className:"text-ui-smd font-mono text-neutral3 flex",children:t?o.jsxs(o.Fragment,{children:[er(t,"HH:mm:ss"),o.jsxs("span",{className:"text-neutral2",children:[".",String(t.getMilliseconds()).padStart(3,"0")]})]}):null})}function JV({isLoading:e,setEndOfListElement:t,hasMore:n,loadingText:r="Loading more data..."}){return t?o.jsx("div",{ref:t,className:K("col-span-full text-ui-md text-neutral3 opacity-50 flex justify-center min-h-1",{"py-4":e,"py-0":!n}),children:e&&r}):null}function eH({message:e="Nothing matches your search",className:t,...n}){return o.jsx("div",{className:K("col-span-full flex flex-col items-center justify-center gap-2 py-12 text-neutral3",t),...n,children:o.jsx("p",{className:"text-ui-md",children:e})})}const CXn={tinted:{background:"color-mix(in oklch, var(--surface1), var(--neutral6) 10%)",hoverBackground:"color-mix(in oklch, var(--surface1), var(--neutral6) 14%)"},surface:{background:"var(--surface2)",hoverBackground:"color-mix(in oklch, var(--surface2), var(--neutral6) 10%)"},transparent:{background:"transparent",hoverBackground:"transparent"}};function EXn(e){return e===void 0?{top:!1}:typeof e=="object"?{top:!1,...e}:e}const f8e=["gap-y-px","[&_.data-list-top]:mx-0 [&_.data-list-top]:bg-[var(--data-list-sticky-header-background)] [&_.data-list-top]:after:hidden","[&_.data-list-top]:rounded-t-xl [&_.data-list-top]:rounded-b-md","[&_.data-list-top>*:not(:first-child)]:relative [&_.data-list-top>*:not(:first-child)]:overflow-visible",'[&_.data-list-top>*:not(:first-child)]:before:absolute [&_.data-list-top>*:not(:first-child)]:before:-left-4 [&_.data-list-top>*:not(:first-child)]:before:top-1/2 [&_.data-list-top>*:not(:first-child)]:before:-translate-y-1/2 [&_.data-list-top>*:not(:first-child)]:before:h-4 [&_.data-list-top>*:not(:first-child)]:before:w-px [&_.data-list-top>*:not(:first-child)]:before:bg-border2 [&_.data-list-top>*:not(:first-child)]:before:content-[""]',"[&_.data-list-row]:mx-0 [&_.data-list-row]:my-0 [&_.data-list-row]:rounded-md","[&_.data-list-row]:hover:bg-surface-overlay-strong!","[&_.data-list-row]:focus-visible:bg-surface-overlay-strong!","[&_.data-list-row>.data-list-sticky-start]:bg-[var(--data-list-sticky-header-background)]","[&_.data-list-row>.data-list-sticky-start]:after:right-0","[&_.data-list-row:hover>.data-list-sticky-start]:bg-[var(--data-list-sticky-header-hover-background)]","[&_.data-list-row:focus-visible>.data-list-sticky-start]:bg-[var(--data-list-sticky-header-hover-background)]","[&_.data-list-row:focus-within>.data-list-sticky-start]:bg-[var(--data-list-sticky-header-hover-background)]","[&_.data-list-top>.data-list-sticky-start]:after:right-0","[&_.data-list-top>.data-list-sticky-start+*]:before:hidden"],jXn=al(K("grid w-max min-w-full max-w-none content-start"),{variants:{variant:{striped:K(...f8e,"[&_.data-list-row]:after:hidden","[&_.data-list-row]:even:bg-surface-overlay-soft"),lined:K(...f8e,'[&_.data-list-row]:after:absolute [&_.data-list-row]:after:h-px [&_.data-list-row]:after:content-[""] [&_.data-list-row]:after:pointer-events-none',"[&_.data-list-row]:after:inset-x-2 [&_.data-list-row]:after:-bottom-px [&_.data-list-row]:after:bg-neutral6/10")}},defaultVariants:{variant:"lined"}});function k3({children:e,columns:t,className:n,variant:r="lined",stickyHeaderBackground:s="tinted",mask:a,scrollRef:i,...l}){const c=CXn[s],u={"--data-list-sticky-header-background":c.background,"--data-list-sticky-header-hover-background":c.hoverBackground,gridTemplateColumns:t},d=o.jsx("div",{className:jXn({variant:r}),style:u,children:e});return o.jsx(Yr,{...l,orientation:"both",mask:EXn(a),viewportRef:i,viewPortClassName:"max-h-[inherit]",className:K("h-full w-full rounded-t-xl",n),children:d})}const Z1t=g.createContext(!1);function eSe(){return g.useContext(Z1t)}const O3=g.forwardRef(({children:e,className:t,type:n="button",flushLeft:r,flushRight:s,colStart:a,colEnd:i,featured:l,variant:c,style:u,...d},f)=>{const p=eSe(),m=a!==void 0||i!==void 0?{...u,gridColumn:`${a??1} / ${i??-1}`}:u;return o.jsx("button",{ref:f,type:n,className:K(...p?Q1e:q1t,"text-left",!p&&r&&"ml-0!",!p&&s&&"mr-0!",l&&"bg-surface4!",Y1e({variant:c}),t),style:m,...d,children:e})});O3.displayName="DataListRowButton";function tSe({height:e}){return e<=0?null:o.jsx("div",{className:"col-span-full",style:{height:e}})}function tH({children:e,className:t,hasLeadingCell:n,...r}){return o.jsx("div",{className:K('data-list-top mx-1 grid grid-cols-subgrid gap-8 col-span-full relative px-5 bg-surface2 sticky top-0 z-20 after:absolute after:inset-x-[-0.25rem] after:bottom-0 after:h-px after:bg-border1 after:content-[""] after:pointer-events-none',n&&"gap-0 pl-0!",t),...r,children:e})}const $_=g.forwardRef(({children:e,className:t,as:n,sticky:r,...s},a)=>{const i=n||"span",l=typeof e=="string"||typeof e=="number";return o.jsx(i,{ref:a,className:K("h-8 min-w-0 max-w-full overflow-hidden py-1 flex items-center whitespace-nowrap text-neutral2 font-semibold tracking-tight text-ui-sm",r==="start"&&V1t,r==="start"&&"-ml-5 -mr-4 w-auto max-w-none rounded-tl-xl rounded-bl-md pl-5 pr-4",r==="start"&&"z-20 bg-[var(--data-list-sticky-header-background)]",t),...s,children:l?o.jsx("span",{className:"min-w-0 truncate",children:e}):e})});function nH({children:e,tooltip:t,className:n}){return o.jsxs(Wn,{children:[o.jsx(zn,{children:o.jsx($_,{className:n,children:e})}),o.jsx(Bn,{children:t})]})}const TXn={sm:{show:"hidden sm:inline-flex",hide:"inline-flex sm:hidden"},md:{show:"hidden md:inline-flex",hide:"inline-flex md:hidden"},lg:{show:"hidden lg:inline-flex",hide:"inline-flex lg:hidden"},xl:{show:"hidden xl:inline-flex",hide:"inline-flex xl:hidden"},"2xl":{show:"hidden 2xl:inline-flex",hide:"inline-flex 2xl:hidden"}};function G1t({long:e,short:t,tooltip:n,breakpoint:r="2xl",className:s}){const a=n??(typeof e=="string"?e:void 0),i=TXn[r],l=o.jsxs(o.Fragment,{children:[o.jsx("span",{className:K("items-center gap-1",i.show),children:e}),o.jsx("span",{className:K("items-center gap-1",i.hide),children:t})]});return a?o.jsx(nH,{tooltip:a,className:K("flex [&_svg]:w-[1.3em] [&_svg]:h-[1.3em]",s),children:l}):o.jsx($_,{className:K("flex [&_svg]:w-[1.3em] [&_svg]:h-[1.3em]",s),children:l})}function NXn({checked:e,onToggle:t,...n}){return o.jsx($_,{as:"label",className:"w-8 cursor-pointer justify-center overflow-visible px-0 py-0!",onClick:r=>r.stopPropagation(),children:o.jsx(Mo,{checked:e,onCheckedChange:()=>t(),"aria-label":n["aria-label"]})})}function Q1t({children:e,to:t,className:n,style:r,LinkComponent:s="a",flushLeft:a,flushRight:i,colStart:l,colEnd:c,featured:u,variant:d}){const f=eSe(),h=l!==void 0||c!==void 0?{...r,gridColumn:`${l??1} / ${c??-1}`}:r;return o.jsx(s,{href:t,className:K(...f?Q1e:q1t,!f&&a&&"ml-0!",!f&&i&&"mr-0!",u&&"bg-surface4!",Y1e({variant:d}),n),style:h,children:e})}const nSe=g.forwardRef(({children:e,className:t,...n},r)=>o.jsx(Z1t.Provider,{value:!0,children:o.jsx("div",{ref:r,className:K("grid grid-cols-subgrid gap-0 mx-1",...G1e,t),...n,children:e})}));nSe.displayName="DataListRowWrapper";const rSe=g.forwardRef(({children:e,className:t,...n},r)=>o.jsx("div",{ref:r,className:K("data-list-subheader relative isolate col-span-full px-4 py-3 border-none text-ui-md text-neutral4 font-medium mx-1","before:absolute before:inset-x-0 before:inset-y-1 before:bg-surface4 before:rounded-md before:-z-1",t),...n,children:e}));rSe.displayName="DataListSubheader";function Y1t({children:e,className:t}){return o.jsx("span",{className:K("text-ui-sm text-neutral2 font-normal",t),children:e})}function IXn({currentPage:e,hasMore:t,onNextPage:n,onPrevPage:r}){const s=typeof e=="number"&&e>0||t;return o.jsxs("div",{className:"col-span-full flex py-4 items-center justify-center text-neutral3 text-ui-md gap-8",children:[o.jsxs("span",{children:["Page ",o.jsx("b",{children:e?e+1:"1"})]}),s&&o.jsxs("div",{className:"flex gap-4",children:[typeof e=="number"&&e>0&&o.jsxs(de,{type:"button",variant:"outline",size:"sm",onClick:r,children:[o.jsx(Zq,{}),"Previous"]}),t&&o.jsxs(de,{type:"button",variant:"outline",size:"sm",onClick:n,children:["Next",o.jsx($z,{})]})]})]})}const X1t=g.forwardRef(({children:e,className:t,flushLeft:n,flushRight:r,colStart:s,colEnd:a,featured:i,variant:l,style:c,...u},d)=>{const f=eSe(),h=s!==void 0||a!==void 0?{...c,gridColumn:`${s??1} / ${a??-1}`}:c;return o.jsx("div",{ref:d,className:K(f?"grid grid-cols-subgrid gap-8 px-5 transition-colors duration-200 rounded-lg":mXn,!f&&n&&"ml-0!",!f&&r&&"mr-0!",i&&"bg-surface4!",Y1e({variant:l}),t),style:h,...u,children:e})});X1t.displayName="DataListRowStatic";const K1t=g.forwardRef(({children:e,className:t,flushLeft:n,colStart:r,style:s,...a},i)=>o.jsx("div",{ref:i,className:K("grid grid-cols-subgrid gap-8 px-5 pointer-events-none [&>*]:pointer-events-auto",!r&&"col-span-full",n&&"pl-0!",t),style:r?{...s,gridColumn:`${r} / -1`}:s,...a,children:e}));K1t.displayName="DataListTopCells";const me=Object.assign(k3,{Top:tH,TopCells:K1t,TopCell:$_,TopCellWithTooltip:nH,TopCellSmart:G1t,RowWrapper:nSe,RowButton:O3,RowLink:Q1t,RowStatic:X1t,Cell:ko,TextCell:bXn,NameCell:xXn,DescriptionCell:wXn,IdCell:H1t,RowHeaderCell:SXn,NumberCell:kXn,MonoCell:X1e,DateCell:K1e,TimeCell:J1e,SelectCell:_Xn,TopSelectCell:NXn,NoMatch:eH,Subheader:rSe,SubHeading:Y1t,Spacer:tSe,NextPageLoading:JV,Pagination:IXn}),AXn=K("group/input-group relative flex w-full flex-1 items-center","border border-border1 text-neutral6",ms.all,"has-[:disabled]:opacity-50 has-[:disabled]:cursor-not-allowed","has-[[aria-invalid=true]]:border-error","has-[>[data-align=block-start]]:flex-col has-[>[data-align=block-start]]:h-auto","has-[>[data-align=block-end]]:flex-col has-[>[data-align=block-end]]:h-auto","has-[textarea]:h-auto","has-[>[data-align=inline-start]]:[&>[data-slot=input-group-control]]:pl-0","has-[>[data-align=inline-end]]:[&>[data-slot=input-group-control]]:pr-0","has-[>[data-align=block-start]]:[&>[data-slot=input-group-control]]:flex-none has-[>[data-align=block-start]]:[&>[data-slot=input-group-control]]:w-full","has-[>[data-align=block-end]]:[&>[data-slot=input-group-control]]:flex-none has-[>[data-align=block-end]]:[&>[data-slot=input-group-control]]:w-full"),J1t=K("has-[>[data-align=block-start]]:rounded-xl","has-[>[data-align=block-end]]:rounded-xl","has-[textarea]:rounded-xl"),p8e=K("bg-surface-overlay-soft rounded-full","hover:bg-surface-overlay-strong",Aft,"outline-hidden focus-within:outline-hidden focus-within:bg-surface-overlay-strong",Nft,J1t),RXn=al(AXn,{variants:{variant:{default:p8e,filled:p8e,outline:K("bg-transparent rounded-full",Aft,"outline-hidden focus-within:outline-hidden",Nft,J1t)}},defaultVariants:{variant:"default"}}),Qc=g.forwardRef(({className:e,size:t="md",variant:n,...r},s)=>o.jsx("div",{ref:s,role:"group","data-slot":"input-group","data-size":t,className:K(RXn({variant:n}),e2[t],e),...r}));Qc.displayName="InputGroup";const PXn=al(K("flex items-center justify-center gap-2 text-neutral3 select-none","group-has-[:disabled]/input-group:opacity-50","[&>svg:not([class*='size-'])]:size-4"),{variants:{align:{"inline-start":"order-first pl-3 pr-1 has-[>button]:pl-1","inline-end":"order-last pr-3 pl-1 has-[>button]:pr-1","block-start":"order-first w-full justify-start px-3 pt-2 pb-1 border-b border-border1","block-end":"order-last w-full justify-start px-3 pb-2 pt-1 border-t border-border1"}},defaultVariants:{align:"inline-start"}}),yc=g.forwardRef(({className:e,align:t="inline-start",onClick:n,...r},s)=>o.jsx("div",{ref:s,role:"group","data-slot":"input-group-addon","data-align":t,className:K(PXn({align:t}),e),onClick:a=>{a.target.closest('button, input, textarea, [role="button"]')||a.currentTarget.parentElement?.querySelector("[data-slot=input-group-control]")?.focus(),n?.(a)},...r}));yc.displayName="InputGroupAddon";const $Xn=K("group-data-[size=xs]/input-group:h-form-xs","group-data-[size=sm]/input-group:h-form-sm","group-data-[size=md]/input-group:h-form-md","group-data-[size=default]/input-group:h-form-default","group-data-[size=lg]/input-group:h-form-lg"),eSt=K("group-data-[size=xs]/input-group:text-ui-xs","group-data-[size=sm]/input-group:text-ui-sm","group-data-[size=md]/input-group:text-ui-md","group-data-[size=default]/input-group:text-ui-md","group-data-[size=lg]/input-group:text-ui-lg"),Yc=g.forwardRef(({className:e,testId:t,error:n,type:r="text",...s},a)=>o.jsx("input",{ref:a,type:r,"data-slot":"input-group-control","data-testid":t,"aria-invalid":n,className:K("flex-1 min-w-0 bg-transparent text-neutral6 px-3 outline-hidden",$Xn,eSt,"placeholder:text-neutral2 placeholder:transition-opacity placeholder:duration-normal","focus:placeholder:opacity-70","disabled:cursor-not-allowed","[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-outer-spin-button]:m-0","[&::-webkit-inner-spin-button]:appearance-none [&::-webkit-inner-spin-button]:m-0","[&[type=number]]:[appearance:textfield]","[&::-webkit-search-cancel-button]:appearance-none",e),...s}));Yc.displayName="InputGroupInput";const MXn=g.forwardRef(({className:e,testId:t,error:n,...r},s)=>o.jsx("textarea",{ref:s,"data-slot":"input-group-control","data-testid":t,"aria-invalid":n,className:K("flex-1 min-w-0 min-h-[60px] resize-y bg-transparent text-neutral6 px-3 py-2 outline-hidden",eSt,"placeholder:text-neutral2 placeholder:transition-opacity placeholder:duration-normal","focus:placeholder:opacity-70","disabled:cursor-not-allowed",e),...r}));MXn.displayName="InputGroupTextarea";const DXn=g.forwardRef(({className:e,...t},n)=>o.jsx("span",{ref:n,className:K("flex items-center gap-2 text-ui-sm text-neutral3 [&_svg]:pointer-events-none","[&_svg:not([class*='size-'])]:size-4",e),...t}));DXn.displayName="InputGroupText";const tSt=g.forwardRef(({size:e="icon-sm",variant:t="ghost",type:n="button",...r},s)=>o.jsx(de,{ref:s,type:n,size:e,variant:t,...r}));tSt.displayName="InputGroupButton";function nSt(e){var t,n,r="";if(typeof e=="string"||typeof e=="number")r+=e;else if(typeof e=="object")if(Array.isArray(e)){var s=e.length;for(t=0;t<s;t++)e[t]&&(n=nSt(e[t]))&&(r&&(r+=" "),r+=n)}else for(n in e)e[n]&&(r&&(r+=" "),r+=n);return r}function Ca(){for(var e,t,n=0,r="",s=arguments.length;n<s;n++)(e=arguments[n])&&(t=nSt(e))&&(r&&(r+=" "),r+=t);return r}var LXn=["dangerouslySetInnerHTML","onCopy","onCopyCapture","onCut","onCutCapture","onPaste","onPasteCapture","onCompositionEnd","onCompositionEndCapture","onCompositionStart","onCompositionStartCapture","onCompositionUpdate","onCompositionUpdateCapture","onFocus","onFocusCapture","onBlur","onBlurCapture","onChange","onChangeCapture","onBeforeInput","onBeforeInputCapture","onInput","onInputCapture","onReset","onResetCapture","onSubmit","onSubmitCapture","onInvalid","onInvalidCapture","onLoad","onLoadCapture","onError","onErrorCapture","onKeyDown","onKeyDownCapture","onKeyPress","onKeyPressCapture","onKeyUp","onKeyUpCapture","onAbort","onAbortCapture","onCanPlay","onCanPlayCapture","onCanPlayThrough","onCanPlayThroughCapture","onDurationChange","onDurationChangeCapture","onEmptied","onEmptiedCapture","onEncrypted","onEncryptedCapture","onEnded","onEndedCapture","onLoadedData","onLoadedDataCapture","onLoadedMetadata","onLoadedMetadataCapture","onLoadStart","onLoadStartCapture","onPause","onPauseCapture","onPlay","onPlayCapture","onPlaying","onPlayingCapture","onProgress","onProgressCapture","onRateChange","onRateChangeCapture","onSeeked","onSeekedCapture","onSeeking","onSeekingCapture","onStalled","onStalledCapture","onSuspend","onSuspendCapture","onTimeUpdate","onTimeUpdateCapture","onVolumeChange","onVolumeChangeCapture","onWaiting","onWaitingCapture","onAuxClick","onAuxClickCapture","onClick","onClickCapture","onContextMenu","onContextMenuCapture","onDoubleClick","onDoubleClickCapture","onDrag","onDragCapture","onDragEnd","onDragEndCapture","onDragEnter","onDragEnterCapture","onDragExit","onDragExitCapture","onDragLeave","onDragLeaveCapture","onDragOver","onDragOverCapture","onDragStart","onDragStartCapture","onDrop","onDropCapture","onMouseDown","onMouseDownCapture","onMouseEnter","onMouseLeave","onMouseMove","onMouseMoveCapture","onMouseOut","onMouseOutCapture","onMouseOver","onMouseOverCapture","onMouseUp","onMouseUpCapture","onSelect","onSelectCapture","onTouchCancel","onTouchCancelCapture","onTouchEnd","onTouchEndCapture","onTouchMove","onTouchMoveCapture","onTouchStart","onTouchStartCapture","onPointerDown","onPointerDownCapture","onPointerMove","onPointerMoveCapture","onPointerUp","onPointerUpCapture","onPointerCancel","onPointerCancelCapture","onPointerEnter","onPointerEnterCapture","onPointerLeave","onPointerLeaveCapture","onPointerOver","onPointerOverCapture","onPointerOut","onPointerOutCapture","onGotPointerCapture","onGotPointerCaptureCapture","onLostPointerCapture","onLostPointerCaptureCapture","onScroll","onScrollCapture","onWheel","onWheelCapture","onAnimationStart","onAnimationStartCapture","onAnimationEnd","onAnimationEndCapture","onAnimationIteration","onAnimationIterationCapture","onTransitionEnd","onTransitionEndCapture"];function sSe(e){if(typeof e!="string")return!1;var t=LXn;return t.includes(e)}var FXn=["aria-activedescendant","aria-atomic","aria-autocomplete","aria-busy","aria-checked","aria-colcount","aria-colindex","aria-colspan","aria-controls","aria-current","aria-describedby","aria-details","aria-disabled","aria-errormessage","aria-expanded","aria-flowto","aria-haspopup","aria-hidden","aria-invalid","aria-keyshortcuts","aria-label","aria-labelledby","aria-level","aria-live","aria-modal","aria-multiline","aria-multiselectable","aria-orientation","aria-owns","aria-placeholder","aria-posinset","aria-pressed","aria-readonly","aria-relevant","aria-required","aria-roledescription","aria-rowcount","aria-rowindex","aria-rowspan","aria-selected","aria-setsize","aria-sort","aria-valuemax","aria-valuemin","aria-valuenow","aria-valuetext","className","color","height","id","lang","max","media","method","min","name","style","target","width","role","tabIndex","accentHeight","accumulate","additive","alignmentBaseline","allowReorder","alphabetic","amplitude","arabicForm","ascent","attributeName","attributeType","autoReverse","azimuth","baseFrequency","baselineShift","baseProfile","bbox","begin","bias","by","calcMode","capHeight","clip","clipPath","clipPathUnits","clipRule","colorInterpolation","colorInterpolationFilters","colorProfile","colorRendering","contentScriptType","contentStyleType","cursor","cx","cy","d","decelerate","descent","diffuseConstant","direction","display","divisor","dominantBaseline","dur","dx","dy","edgeMode","elevation","enableBackground","end","exponent","externalResourcesRequired","fill","fillOpacity","fillRule","filter","filterRes","filterUnits","floodColor","floodOpacity","focusable","fontFamily","fontSize","fontSizeAdjust","fontStretch","fontStyle","fontVariant","fontWeight","format","from","fx","fy","g1","g2","glyphName","glyphOrientationHorizontal","glyphOrientationVertical","glyphRef","gradientTransform","gradientUnits","hanging","horizAdvX","horizOriginX","href","ideographic","imageRendering","in2","in","intercept","k1","k2","k3","k4","k","kernelMatrix","kernelUnitLength","kerning","keyPoints","keySplines","keyTimes","lengthAdjust","letterSpacing","lightingColor","limitingConeAngle","local","markerEnd","markerHeight","markerMid","markerStart","markerUnits","markerWidth","mask","maskContentUnits","maskUnits","mathematical","mode","numOctaves","offset","opacity","operator","order","orient","orientation","origin","overflow","overlinePosition","overlineThickness","paintOrder","panose1","pathLength","patternContentUnits","patternTransform","patternUnits","pointerEvents","pointsAtX","pointsAtY","pointsAtZ","preserveAlpha","preserveAspectRatio","primitiveUnits","r","radius","refX","refY","renderingIntent","repeatCount","repeatDur","requiredExtensions","requiredFeatures","restart","result","rotate","rx","ry","seed","shapeRendering","slope","spacing","specularConstant","specularExponent","speed","spreadMethod","startOffset","stdDeviation","stemh","stemv","stitchTiles","stopColor","stopOpacity","strikethroughPosition","strikethroughThickness","string","stroke","strokeDasharray","strokeDashoffset","strokeLinecap","strokeLinejoin","strokeMiterlimit","strokeOpacity","strokeWidth","surfaceScale","systemLanguage","tableValues","targetX","targetY","textAnchor","textDecoration","textLength","textRendering","to","transform","u1","u2","underlinePosition","underlineThickness","unicode","unicodeBidi","unicodeRange","unitsPerEm","vAlphabetic","values","vectorEffect","version","vertAdvY","vertOriginX","vertOriginY","vHanging","vIdeographic","viewTarget","visibility","vMathematical","widths","wordSpacing","writingMode","x1","x2","x","xChannelSelector","xHeight","xlinkActuate","xlinkArcrole","xlinkHref","xlinkRole","xlinkShow","xlinkTitle","xlinkType","xmlBase","xmlLang","xmlns","xmlnsXlink","xmlSpace","y1","y2","y","yChannelSelector","z","zoomAndPan","ref","key","angle"],zXn=new Set(FXn);function rSt(e){return typeof e!="string"?!1:zXn.has(e)}function sSt(e){return typeof e=="string"&&e.startsWith("data-")}function wf(e){if(typeof e!="object"||e===null)return{};var t={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(rSt(n)||sSt(n))&&(t[n]=e[n]);return t}function _3(e){if(e==null)return null;if(g.isValidElement(e)&&typeof e.props=="object"&&e.props!==null){var t=e.props;return wf(t)}return typeof e=="object"&&!Array.isArray(e)?wf(e):null}function su(e){var t={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(rSt(n)||sSt(n)||sSe(n))&&(t[n]=e[n]);return t}function BXn(e){return e==null?null:g.isValidElement(e)?su(e.props):typeof e=="object"&&!Array.isArray(e)?su(e):null}var UXn=["children","width","height","viewBox","className","style","title","desc"];function Zhe(){return Zhe=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},Zhe.apply(null,arguments)}function qXn(e,t){if(e==null)return{};var n,r,s=VXn(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(s[n]=e[n])}return s}function VXn(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}var aSt=g.forwardRef((e,t)=>{var{children:n,width:r,height:s,viewBox:a,className:i,style:l,title:c,desc:u}=e,d=qXn(e,UXn),f=a||{width:r,height:s,x:0,y:0},p=Ca("recharts-surface",i);return g.createElement("svg",Zhe({},su(d),{className:p,width:r,height:s,style:l,viewBox:"".concat(f.x," ").concat(f.y," ").concat(f.width," ").concat(f.height),ref:t}),g.createElement("title",null,c),g.createElement("desc",null,u),n)}),HXn=["children","className"];function Ghe(){return Ghe=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},Ghe.apply(null,arguments)}function WXn(e,t){if(e==null)return{};var n,r,s=ZXn(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(s[n]=e[n])}return s}function ZXn(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}var tc=g.forwardRef((e,t)=>{var{children:n,className:r}=e,s=WXn(e,HXn),a=Ca("recharts-layer",r);return g.createElement("g",Ghe({className:a},su(s),{ref:t}),n)}),GXn=g.createContext(null);function Pi(e){return function(){return e}}const iSt=Math.cos,q7=Math.sin,Bg=Math.sqrt,V7=Math.PI,rH=2*V7,Qhe=Math.PI,Yhe=2*Qhe,ek=1e-6,QXn=Yhe-ek;function oSt(e){this._+=e[0];for(let t=1,n=e.length;t<n;++t)this._+=arguments[t]+e[t]}function YXn(e){let t=Math.floor(e);if(!(t>=0))throw new Error(`invalid digits: ${e}`);if(t>15)return oSt;const n=10**t;return function(r){this._+=r[0];for(let s=1,a=r.length;s<a;++s)this._+=Math.round(arguments[s]*n)/n+r[s]}}class XXn{constructor(t){this._x0=this._y0=this._x1=this._y1=null,this._="",this._append=t==null?oSt:YXn(t)}moveTo(t,n){this._append`M${this._x0=this._x1=+t},${this._y0=this._y1=+n}`}closePath(){this._x1!==null&&(this._x1=this._x0,this._y1=this._y0,this._append`Z`)}lineTo(t,n){this._append`L${this._x1=+t},${this._y1=+n}`}quadraticCurveTo(t,n,r,s){this._append`Q${+t},${+n},${this._x1=+r},${this._y1=+s}`}bezierCurveTo(t,n,r,s,a,i){this._append`C${+t},${+n},${+r},${+s},${this._x1=+a},${this._y1=+i}`}arcTo(t,n,r,s,a){if(t=+t,n=+n,r=+r,s=+s,a=+a,a<0)throw new Error(`negative radius: ${a}`);let i=this._x1,l=this._y1,c=r-t,u=s-n,d=i-t,f=l-n,p=d*d+f*f;if(this._x1===null)this._append`M${this._x1=t},${this._y1=n}`;else if(p>ek)if(!(Math.abs(f*c-u*d)>ek)||!a)this._append`L${this._x1=t},${this._y1=n}`;else{let h=r-i,m=s-l,v=c*c+u*u,y=h*h+m*m,b=Math.sqrt(v),S=Math.sqrt(p),w=a*Math.tan((Qhe-Math.acos((v+p-y)/(2*b*S)))/2),k=w/S,_=w/b;Math.abs(k-1)>ek&&this._append`L${t+k*d},${n+k*f}`,this._append`A${a},${a},0,0,${+(f*h>d*m)},${this._x1=t+_*c},${this._y1=n+_*u}`}}arc(t,n,r,s,a,i){if(t=+t,n=+n,r=+r,i=!!i,r<0)throw new Error(`negative radius: ${r}`);let l=r*Math.cos(s),c=r*Math.sin(s),u=t+l,d=n+c,f=1^i,p=i?s-a:a-s;this._x1===null?this._append`M${u},${d}`:(Math.abs(this._x1-u)>ek||Math.abs(this._y1-d)>ek)&&this._append`L${u},${d}`,r&&(p<0&&(p=p%Yhe+Yhe),p>QXn?this._append`A${r},${r},0,1,${f},${t-l},${n-c}A${r},${r},0,1,${f},${this._x1=u},${this._y1=d}`:p>ek&&this._append`A${r},${r},0,${+(p>=Qhe)},${f},${this._x1=t+r*Math.cos(a)},${this._y1=n+r*Math.sin(a)}`)}rect(t,n,r,s){this._append`M${this._x0=this._x1=+t},${this._y0=this._y1=+n}h${r=+r}v${+s}h${-r}Z`}toString(){return this._}}function aSe(e){let t=3;return e.digits=function(n){if(!arguments.length)return t;if(n==null)t=null;else{const r=Math.floor(n);if(!(r>=0))throw new RangeError(`invalid digits: ${n}`);t=r}return e},()=>new XXn(t)}function iSe(e){return typeof e=="object"&&"length"in e?e:Array.from(e)}function lSt(e){this._context=e}lSt.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._point=0},lineEnd:function(){(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line=1-this._line},point:function(e,t){switch(e=+e,t=+t,this._point){case 0:this._point=1,this._line?this._context.lineTo(e,t):this._context.moveTo(e,t);break;case 1:this._point=2;default:this._context.lineTo(e,t);break}}};function sH(e){return new lSt(e)}function cSt(e){return e[0]}function uSt(e){return e[1]}function dSt(e,t){var n=Pi(!0),r=null,s=sH,a=null,i=aSe(l);e=typeof e=="function"?e:e===void 0?cSt:Pi(e),t=typeof t=="function"?t:t===void 0?uSt:Pi(t);function l(c){var u,d=(c=iSe(c)).length,f,p=!1,h;for(r==null&&(a=s(h=i())),u=0;u<=d;++u)!(u<d&&n(f=c[u],u,c))===p&&((p=!p)?a.lineStart():a.lineEnd()),p&&a.point(+e(f,u,c),+t(f,u,c));if(h)return a=null,h+""||null}return l.x=function(c){return arguments.length?(e=typeof c=="function"?c:Pi(+c),l):e},l.y=function(c){return arguments.length?(t=typeof c=="function"?c:Pi(+c),l):t},l.defined=function(c){return arguments.length?(n=typeof c=="function"?c:Pi(!!c),l):n},l.curve=function(c){return arguments.length?(s=c,r!=null&&(a=s(r)),l):s},l.context=function(c){return arguments.length?(c==null?r=a=null:a=s(r=c),l):r},l}function M6(e,t,n){var r=null,s=Pi(!0),a=null,i=sH,l=null,c=aSe(u);e=typeof e=="function"?e:e===void 0?cSt:Pi(+e),t=typeof t=="function"?t:Pi(t===void 0?0:+t),n=typeof n=="function"?n:n===void 0?uSt:Pi(+n);function u(f){var p,h,m,v=(f=iSe(f)).length,y,b=!1,S,w=new Array(v),k=new Array(v);for(a==null&&(l=i(S=c())),p=0;p<=v;++p){if(!(p<v&&s(y=f[p],p,f))===b)if(b=!b)h=p,l.areaStart(),l.lineStart();else{for(l.lineEnd(),l.lineStart(),m=p-1;m>=h;--m)l.point(w[m],k[m]);l.lineEnd(),l.areaEnd()}b&&(w[p]=+e(y,p,f),k[p]=+t(y,p,f),l.point(r?+r(y,p,f):w[p],n?+n(y,p,f):k[p]))}if(S)return l=null,S+""||null}function d(){return dSt().defined(s).curve(i).context(a)}return u.x=function(f){return arguments.length?(e=typeof f=="function"?f:Pi(+f),r=null,u):e},u.x0=function(f){return arguments.length?(e=typeof f=="function"?f:Pi(+f),u):e},u.x1=function(f){return arguments.length?(r=f==null?null:typeof f=="function"?f:Pi(+f),u):r},u.y=function(f){return arguments.length?(t=typeof f=="function"?f:Pi(+f),n=null,u):t},u.y0=function(f){return arguments.length?(t=typeof f=="function"?f:Pi(+f),u):t},u.y1=function(f){return arguments.length?(n=f==null?null:typeof f=="function"?f:Pi(+f),u):n},u.lineX0=u.lineY0=function(){return d().x(e).y(t)},u.lineY1=function(){return d().x(e).y(n)},u.lineX1=function(){return d().x(r).y(t)},u.defined=function(f){return arguments.length?(s=typeof f=="function"?f:Pi(!!f),u):s},u.curve=function(f){return arguments.length?(i=f,a!=null&&(l=i(a)),u):i},u.context=function(f){return arguments.length?(f==null?a=l=null:l=i(a=f),u):a},u}class fSt{constructor(t,n){this._context=t,this._x=n}areaStart(){this._line=0}areaEnd(){this._line=NaN}lineStart(){this._point=0}lineEnd(){(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line=1-this._line}point(t,n){switch(t=+t,n=+n,this._point){case 0:{this._point=1,this._line?this._context.lineTo(t,n):this._context.moveTo(t,n);break}case 1:this._point=2;default:{this._x?this._context.bezierCurveTo(this._x0=(this._x0+t)/2,this._y0,this._x0,n,t,n):this._context.bezierCurveTo(this._x0,this._y0=(this._y0+n)/2,t,this._y0,t,n);break}}this._x0=t,this._y0=n}}function KXn(e){return new fSt(e,!0)}function JXn(e){return new fSt(e,!1)}const oSe={draw(e,t){const n=Bg(t/V7);e.moveTo(n,0),e.arc(0,0,n,0,rH)}},eKn={draw(e,t){const n=Bg(t/5)/2;e.moveTo(-3*n,-n),e.lineTo(-n,-n),e.lineTo(-n,-3*n),e.lineTo(n,-3*n),e.lineTo(n,-n),e.lineTo(3*n,-n),e.lineTo(3*n,n),e.lineTo(n,n),e.lineTo(n,3*n),e.lineTo(-n,3*n),e.lineTo(-n,n),e.lineTo(-3*n,n),e.closePath()}},pSt=Bg(1/3),tKn=pSt*2,nKn={draw(e,t){const n=Bg(t/tKn),r=n*pSt;e.moveTo(0,-n),e.lineTo(r,0),e.lineTo(0,n),e.lineTo(-r,0),e.closePath()}},rKn={draw(e,t){const n=Bg(t),r=-n/2;e.rect(r,r,n,n)}},sKn=.8908130915292852,hSt=q7(V7/10)/q7(7*V7/10),aKn=q7(rH/10)*hSt,iKn=-iSt(rH/10)*hSt,oKn={draw(e,t){const n=Bg(t*sKn),r=aKn*n,s=iKn*n;e.moveTo(0,-n),e.lineTo(r,s);for(let a=1;a<5;++a){const i=rH*a/5,l=iSt(i),c=q7(i);e.lineTo(c*n,-l*n),e.lineTo(l*r-c*s,c*r+l*s)}e.closePath()}},lee=Bg(3),lKn={draw(e,t){const n=-Bg(t/(lee*3));e.moveTo(0,n*2),e.lineTo(-lee*n,-n),e.lineTo(lee*n,-n),e.closePath()}},vh=-.5,yh=Bg(3)/2,Xhe=1/Bg(12),cKn=(Xhe/2+1)*3,uKn={draw(e,t){const n=Bg(t/cKn),r=n/2,s=n*Xhe,a=r,i=n*Xhe+n,l=-a,c=i;e.moveTo(r,s),e.lineTo(a,i),e.lineTo(l,c),e.lineTo(vh*r-yh*s,yh*r+vh*s),e.lineTo(vh*a-yh*i,yh*a+vh*i),e.lineTo(vh*l-yh*c,yh*l+vh*c),e.lineTo(vh*r+yh*s,vh*s-yh*r),e.lineTo(vh*a+yh*i,vh*i-yh*a),e.lineTo(vh*l+yh*c,vh*c-yh*l),e.closePath()}};function dKn(e,t){let n=null,r=aSe(s);e=typeof e=="function"?e:Pi(e||oSe),t=typeof t=="function"?t:Pi(t===void 0?64:+t);function s(){let a;if(n||(n=a=r()),e.apply(this,arguments).draw(n,+t.apply(this,arguments)),a)return n=null,a+""||null}return s.type=function(a){return arguments.length?(e=typeof a=="function"?a:Pi(a),s):e},s.size=function(a){return arguments.length?(t=typeof a=="function"?a:Pi(+a),s):t},s.context=function(a){return arguments.length?(n=a??null,s):n},s}function H7(){}function W7(e,t,n){e._context.bezierCurveTo((2*e._x0+e._x1)/3,(2*e._y0+e._y1)/3,(e._x0+2*e._x1)/3,(e._y0+2*e._y1)/3,(e._x0+4*e._x1+t)/6,(e._y0+4*e._y1+n)/6)}function mSt(e){this._context=e}mSt.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._y0=this._y1=NaN,this._point=0},lineEnd:function(){switch(this._point){case 3:W7(this,this._x1,this._y1);case 2:this._context.lineTo(this._x1,this._y1);break}(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line=1-this._line},point:function(e,t){switch(e=+e,t=+t,this._point){case 0:this._point=1,this._line?this._context.lineTo(e,t):this._context.moveTo(e,t);break;case 1:this._point=2;break;case 2:this._point=3,this._context.lineTo((5*this._x0+this._x1)/6,(5*this._y0+this._y1)/6);default:W7(this,e,t);break}this._x0=this._x1,this._x1=e,this._y0=this._y1,this._y1=t}};function fKn(e){return new mSt(e)}function gSt(e){this._context=e}gSt.prototype={areaStart:H7,areaEnd:H7,lineStart:function(){this._x0=this._x1=this._x2=this._x3=this._x4=this._y0=this._y1=this._y2=this._y3=this._y4=NaN,this._point=0},lineEnd:function(){switch(this._point){case 1:{this._context.moveTo(this._x2,this._y2),this._context.closePath();break}case 2:{this._context.moveTo((this._x2+2*this._x3)/3,(this._y2+2*this._y3)/3),this._context.lineTo((this._x3+2*this._x2)/3,(this._y3+2*this._y2)/3),this._context.closePath();break}case 3:{this.point(this._x2,this._y2),this.point(this._x3,this._y3),this.point(this._x4,this._y4);break}}},point:function(e,t){switch(e=+e,t=+t,this._point){case 0:this._point=1,this._x2=e,this._y2=t;break;case 1:this._point=2,this._x3=e,this._y3=t;break;case 2:this._point=3,this._x4=e,this._y4=t,this._context.moveTo((this._x0+4*this._x1+e)/6,(this._y0+4*this._y1+t)/6);break;default:W7(this,e,t);break}this._x0=this._x1,this._x1=e,this._y0=this._y1,this._y1=t}};function pKn(e){return new gSt(e)}function vSt(e){this._context=e}vSt.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._y0=this._y1=NaN,this._point=0},lineEnd:function(){(this._line||this._line!==0&&this._point===3)&&this._context.closePath(),this._line=1-this._line},point:function(e,t){switch(e=+e,t=+t,this._point){case 0:this._point=1;break;case 1:this._point=2;break;case 2:this._point=3;var n=(this._x0+4*this._x1+e)/6,r=(this._y0+4*this._y1+t)/6;this._line?this._context.lineTo(n,r):this._context.moveTo(n,r);break;case 3:this._point=4;default:W7(this,e,t);break}this._x0=this._x1,this._x1=e,this._y0=this._y1,this._y1=t}};function hKn(e){return new vSt(e)}function ySt(e){this._context=e}ySt.prototype={areaStart:H7,areaEnd:H7,lineStart:function(){this._point=0},lineEnd:function(){this._point&&this._context.closePath()},point:function(e,t){e=+e,t=+t,this._point?this._context.lineTo(e,t):(this._point=1,this._context.moveTo(e,t))}};function mKn(e){return new ySt(e)}function h8e(e){return e<0?-1:1}function m8e(e,t,n){var r=e._x1-e._x0,s=t-e._x1,a=(e._y1-e._y0)/(r||s<0&&-0),i=(n-e._y1)/(s||r<0&&-0),l=(a*s+i*r)/(r+s);return(h8e(a)+h8e(i))*Math.min(Math.abs(a),Math.abs(i),.5*Math.abs(l))||0}function g8e(e,t){var n=e._x1-e._x0;return n?(3*(e._y1-e._y0)/n-t)/2:t}function cee(e,t,n){var r=e._x0,s=e._y0,a=e._x1,i=e._y1,l=(a-r)/3;e._context.bezierCurveTo(r+l,s+l*t,a-l,i-l*n,a,i)}function Z7(e){this._context=e}Z7.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._y0=this._y1=this._t0=NaN,this._point=0},lineEnd:function(){switch(this._point){case 2:this._context.lineTo(this._x1,this._y1);break;case 3:cee(this,this._t0,g8e(this,this._t0));break}(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line=1-this._line},point:function(e,t){var n=NaN;if(e=+e,t=+t,!(e===this._x1&&t===this._y1)){switch(this._point){case 0:this._point=1,this._line?this._context.lineTo(e,t):this._context.moveTo(e,t);break;case 1:this._point=2;break;case 2:this._point=3,cee(this,g8e(this,n=m8e(this,e,t)),n);break;default:cee(this,this._t0,n=m8e(this,e,t));break}this._x0=this._x1,this._x1=e,this._y0=this._y1,this._y1=t,this._t0=n}}};function bSt(e){this._context=new xSt(e)}(bSt.prototype=Object.create(Z7.prototype)).point=function(e,t){Z7.prototype.point.call(this,t,e)};function xSt(e){this._context=e}xSt.prototype={moveTo:function(e,t){this._context.moveTo(t,e)},closePath:function(){this._context.closePath()},lineTo:function(e,t){this._context.lineTo(t,e)},bezierCurveTo:function(e,t,n,r,s,a){this._context.bezierCurveTo(t,e,r,n,a,s)}};function gKn(e){return new Z7(e)}function vKn(e){return new bSt(e)}function wSt(e){this._context=e}wSt.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x=[],this._y=[]},lineEnd:function(){var e=this._x,t=this._y,n=e.length;if(n)if(this._line?this._context.lineTo(e[0],t[0]):this._context.moveTo(e[0],t[0]),n===2)this._context.lineTo(e[1],t[1]);else for(var r=v8e(e),s=v8e(t),a=0,i=1;i<n;++a,++i)this._context.bezierCurveTo(r[0][a],s[0][a],r[1][a],s[1][a],e[i],t[i]);(this._line||this._line!==0&&n===1)&&this._context.closePath(),this._line=1-this._line,this._x=this._y=null},point:function(e,t){this._x.push(+e),this._y.push(+t)}};function v8e(e){var t,n=e.length-1,r,s=new Array(n),a=new Array(n),i=new Array(n);for(s[0]=0,a[0]=2,i[0]=e[0]+2*e[1],t=1;t<n-1;++t)s[t]=1,a[t]=4,i[t]=4*e[t]+2*e[t+1];for(s[n-1]=2,a[n-1]=7,i[n-1]=8*e[n-1]+e[n],t=1;t<n;++t)r=s[t]/a[t-1],a[t]-=r,i[t]-=r*i[t-1];for(s[n-1]=i[n-1]/a[n-1],t=n-2;t>=0;--t)s[t]=(i[t]-s[t+1])/a[t];for(a[n-1]=(e[n]+s[n-1])/2,t=0;t<n-1;++t)a[t]=2*e[t+1]-s[t+1];return[s,a]}function yKn(e){return new wSt(e)}function aH(e,t){this._context=e,this._t=t}aH.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x=this._y=NaN,this._point=0},lineEnd:function(){0<this._t&&this._t<1&&this._point===2&&this._context.lineTo(this._x,this._y),(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line>=0&&(this._t=1-this._t,this._line=1-this._line)},point:function(e,t){switch(e=+e,t=+t,this._point){case 0:this._point=1,this._line?this._context.lineTo(e,t):this._context.moveTo(e,t);break;case 1:this._point=2;default:{if(this._t<=0)this._context.lineTo(this._x,t),this._context.lineTo(e,t);else{var n=this._x*(1-this._t)+e*this._t;this._context.lineTo(n,this._y),this._context.lineTo(n,t)}break}}this._x=e,this._y=t}};function bKn(e){return new aH(e,.5)}function xKn(e){return new aH(e,0)}function wKn(e){return new aH(e,1)}function UO(e,t){if((i=e.length)>1)for(var n=1,r,s,a=e[t[0]],i,l=a.length;n<i;++n)for(s=a,a=e[t[n]],r=0;r<l;++r)a[r][1]+=a[r][0]=isNaN(s[r][1])?s[r][0]:s[r][1]}function Khe(e){for(var t=e.length,n=new Array(t);--t>=0;)n[t]=t;return n}function SKn(e,t){return e[t]}function kKn(e){const t=[];return t.key=e,t}function OKn(){var e=Pi([]),t=Khe,n=UO,r=SKn;function s(a){var i=Array.from(e.apply(this,arguments),kKn),l,c=i.length,u=-1,d;for(const f of a)for(l=0,++u;l<c;++l)(i[l][u]=[0,+r(f,i[l].key,u,a)]).data=f;for(l=0,d=iSe(t(i));l<c;++l)i[d[l]].index=l;return n(i,d),i}return s.keys=function(a){return arguments.length?(e=typeof a=="function"?a:Pi(Array.from(a)),s):e},s.value=function(a){return arguments.length?(r=typeof a=="function"?a:Pi(+a),s):r},s.order=function(a){return arguments.length?(t=a==null?Khe:typeof a=="function"?a:Pi(Array.from(a)),s):t},s.offset=function(a){return arguments.length?(n=a??UO,s):n},s}function _Kn(e,t){if((r=e.length)>0){for(var n,r,s=0,a=e[0].length,i;s<a;++s){for(i=n=0;n<r;++n)i+=e[n][s][1]||0;if(i)for(n=0;n<r;++n)e[n][s][1]/=i}UO(e,t)}}function CKn(e,t){if((s=e.length)>0){for(var n=0,r=e[t[0]],s,a=r.length;n<a;++n){for(var i=0,l=0;i<s;++i)l+=e[i][n][1]||0;r[n][1]+=r[n][0]=-l/2}UO(e,t)}}function EKn(e,t){if(!(!((i=e.length)>0)||!((a=(s=e[t[0]]).length)>0))){for(var n=0,r=1,s,a,i;r<a;++r){for(var l=0,c=0,u=0;l<i;++l){for(var d=e[t[l]],f=d[r][1]||0,p=d[r-1][1]||0,h=(f-p)/2,m=0;m<l;++m){var v=e[t[m]],y=v[r][1]||0,b=v[r-1][1]||0;h+=y-b}c+=f,u+=h*f}s[r-1][1]+=s[r-1][0]=n,c&&(n-=u/c)}s[r-1][1]+=s[r-1][0]=n,UO(e,t)}}var uee={},dee={},y8e;function jKn(){return y8e||(y8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});function t(n){return n==="__proto__"}e.isUnsafeProperty=t})(dee)),dee}var fee={},b8e;function SSt(){return b8e||(b8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});function t(n){switch(typeof n){case"number":case"symbol":return!1;case"string":return n.includes(".")||n.includes("[")||n.includes("]")}}e.isDeepKey=t})(fee)),fee}var pee={},x8e;function lSe(){return x8e||(x8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});function t(n){return typeof n=="string"||typeof n=="symbol"?n:Object.is(n?.valueOf?.(),-0)?"-0":String(n)}e.toKey=t})(pee)),pee}var hee={},mee={},w8e;function TKn(){return w8e||(w8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});function t(n){if(n==null)return"";if(typeof n=="string")return n;if(Array.isArray(n))return n.map(t).join(",");const r=String(n);return r==="0"&&Object.is(Number(n),-0)?"-0":r}e.toString=t})(mee)),mee}var S8e;function cSe(){return S8e||(S8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});const t=TKn(),n=lSe();function r(s){if(Array.isArray(s))return s.map(n.toKey);if(typeof s=="symbol")return[s];s=t.toString(s);const a=[],i=s.length;if(i===0)return a;let l=0,c="",u="",d=!1;for(s.charCodeAt(0)===46&&(a.push(""),l++);l<i;){const f=s[l];u?f==="\\"&&l+1<i?(l++,c+=s[l]):f===u?u="":c+=f:d?f==='"'||f==="'"?u=f:f==="]"?(d=!1,a.push(c),c=""):c+=f:f==="["?(d=!0,c&&(a.push(c),c="")):f==="."?c&&(a.push(c),c=""):c+=f,l++}return c&&a.push(c),a}e.toPath=r})(hee)),hee}var k8e;function uSe(){return k8e||(k8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});const t=jKn(),n=SSt(),r=lSe(),s=cSe();function a(l,c,u){if(l==null)return u;switch(typeof c){case"string":{if(t.isUnsafeProperty(c))return u;const d=l[c];return d===void 0?n.isDeepKey(c)?a(l,s.toPath(c),u):u:d}case"number":case"symbol":{typeof c=="number"&&(c=r.toKey(c));const d=l[c];return d===void 0?u:d}default:{if(Array.isArray(c))return i(l,c,u);if(Object.is(c?.valueOf(),-0)?c="-0":c=String(c),t.isUnsafeProperty(c))return u;const d=l[c];return d===void 0?u:d}}}function i(l,c,u){if(c.length===0)return u;let d=l;for(let f=0;f<c.length;f++){if(d==null||t.isUnsafeProperty(c[f]))return u;d=d[c[f]]}return d===void 0?u:d}e.get=a})(uee)),uee}var gee,O8e;function NKn(){return O8e||(O8e=1,gee=uSe().get),gee}var IKn=NKn();const TT=Tc(IKn);var AKn=4;function yw(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:AKn,n=10**t,r=Math.round(e*n)/n;return Object.is(r,-0)?0:r}function Go(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];return e.reduce((s,a,i)=>{var l=n[i-1];return typeof l=="string"?s+l+a:l!==void 0?s+yw(l)+a:s+a},"")}var zh=e=>e===0?0:e>0?1:-1,my=e=>typeof e=="number"&&e!=+e,qO=e=>typeof e=="string"&&e.indexOf("%")===e.length-1,Hn=e=>(typeof e=="number"||e instanceof Number)&&!my(e),cm=e=>Hn(e)||typeof e=="string",RKn=0,pM=e=>{var t=++RKn;return"".concat(e||"").concat(t)},v1=function(t,n){var r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:0,s=arguments.length>3&&arguments[3]!==void 0?arguments[3]:!1;if(!Hn(t)&&typeof t!="string")return r;var a;if(qO(t)){if(n==null)return r;var i=t.indexOf("%");a=n*parseFloat(t.slice(0,i))/100}else a=+t;return my(a)&&(a=r),s&&n!=null&&a>n&&(a=n),a},kSt=e=>{if(!Array.isArray(e))return!1;for(var t=e.length,n={},r=0;r<t;r++)if(!n[String(e[r])])n[String(e[r])]=!0;else return!0;return!1};function uo(e,t,n){return Hn(e)&&Hn(t)?yw(e+n*(t-e)):t}function OSt(e,t,n){if(!(!e||!e.length))return e.find(r=>r&&(typeof t=="function"?t(r):TT(r,t))===n)}var PKn=e=>{for(var t=e.length,n=0,r=0,s=0,a=0,i=1/0,l=-1/0,c=0,u=0,d=0;d<t;d++){var f,p;c=((f=e[d])===null||f===void 0?void 0:f.cx)||0,u=((p=e[d])===null||p===void 0?void 0:p.cy)||0,n+=c,r+=u,s+=c*u,a+=c*c,i=Math.min(i,c),l=Math.max(l,c)}var h=t*a!==n*n?(t*s-n*r)/(t*a-n*n):0;return{xmin:i,xmax:l,a:h,b:(r-h*n)/t}},Ki=e=>e===null||typeof e>"u",C3=e=>Ki(e)?e:"".concat(e.charAt(0).toUpperCase()).concat(e.slice(1));function rf(e){return e!=null}function M_(){}var $Kn=["type","size","sizeType"];function Jhe(){return Jhe=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},Jhe.apply(null,arguments)}function _8e(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(s){return Object.getOwnPropertyDescriptor(e,s).enumerable})),n.push.apply(n,r)}return n}function C8e(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?_8e(Object(n),!0).forEach(function(r){MKn(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):_8e(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}function MKn(e,t,n){return(t=DKn(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function DKn(e){var t=LKn(e,"string");return typeof t=="symbol"?t:t+""}function LKn(e,t){if(typeof e!="object"||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t);if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}function FKn(e,t){if(e==null)return{};var n,r,s=zKn(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(s[n]=e[n])}return s}function zKn(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}var _St={symbolCircle:oSe,symbolCross:eKn,symbolDiamond:nKn,symbolSquare:rKn,symbolStar:oKn,symbolTriangle:lKn,symbolWye:uKn},BKn=Math.PI/180,UKn=e=>{var t="symbol".concat(C3(e));return _St[t]||oSe},qKn=(e,t,n)=>{if(t==="area")return e;switch(n){case"cross":return 5*e*e/9;case"diamond":return .5*e*e/Math.sqrt(3);case"square":return e*e;case"star":{var r=18*BKn;return 1.25*e*e*(Math.tan(r)-Math.tan(r*2)*Math.tan(r)**2)}case"triangle":return Math.sqrt(3)*e*e/4;case"wye":return(21-10*Math.sqrt(3))*e*e/8;default:return Math.PI*e*e/4}},VKn=(e,t)=>{_St["symbol".concat(C3(e))]=t},dSe=e=>{var{type:t="circle",size:n=64,sizeType:r="area"}=e,s=FKn(e,$Kn),a=C8e(C8e({},s),{},{type:t,size:n,sizeType:r}),i="circle";typeof t=="string"&&(i=t);var l=()=>{var p=UKn(i),h=dKn().type(p).size(qKn(n,r,i)),m=h();if(m!==null)return m},{className:c,cx:u,cy:d}=a,f=su(a);return Hn(u)&&Hn(d)&&Hn(n)?g.createElement("path",Jhe({},f,{className:Ca("recharts-symbols",c),transform:"translate(".concat(u,", ").concat(d,")"),d:l()})):null};dSe.registerSymbol=VKn;var CSt=e=>"radius"in e&&"startAngle"in e&&"endAngle"in e,fSe=(e,t)=>{if(!e||typeof e=="function"||typeof e=="boolean")return null;var n=e;if(g.isValidElement(e)&&(n=e.props),typeof n!="object"&&typeof n!="function")return null;var r={};return Object.keys(n).forEach(s=>{sSe(s)&&typeof n[s]=="function"&&(r[s]=(a=>n[s](n,a)))}),r},HKn=(e,t,n)=>r=>(e(t,n,r),null),ESt=(e,t,n)=>{if(e===null||typeof e!="object"&&typeof e!="function")return null;var r=null;return Object.keys(e).forEach(s=>{var a=e[s];sSe(s)&&typeof a=="function"&&(r||(r={}),r[s]=HKn(a,t,n))}),r},WKn=e=>Array.isArray(e)&&e.length>0;function E8e(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(s){return Object.getOwnPropertyDescriptor(e,s).enumerable})),n.push.apply(n,r)}return n}function ZKn(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?E8e(Object(n),!0).forEach(function(r){GKn(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):E8e(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}function GKn(e,t,n){return(t=QKn(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function QKn(e){var t=YKn(e,"string");return typeof t=="symbol"?t:t+""}function YKn(e,t){if(typeof e!="object"||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t);if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}function ic(e,t){var n=ZKn({},e),r=t,s=Object.keys(t),a=s.reduce((i,l)=>(i[l]===void 0&&r[l]!==void 0&&(i[l]=r[l]),i),n);return a}var vee={},yee={},j8e;function XKn(){return j8e||(j8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});function t(n,r){const s=new Map;for(let a=0;a<n.length;a++){const i=n[a],l=r(i,a,n);s.has(l)||s.set(l,i)}return Array.from(s.values())}e.uniqBy=t})(yee)),yee}var bee={},T8e;function KKn(){return T8e||(T8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});function t(n,r){return function(...s){return n.apply(this,s.slice(0,r))}}e.ary=t})(bee)),bee}var xee={},N8e;function jSt(){return N8e||(N8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});function t(n){return n}e.identity=t})(xee)),xee}var wee={},See={},kee={},I8e;function JKn(){return I8e||(I8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});function t(n){return Number.isSafeInteger(n)&&n>=0}e.isLength=t})(kee)),kee}var A8e;function TSt(){return A8e||(A8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});const t=JKn();function n(r){return r!=null&&typeof r!="function"&&t.isLength(r.length)}e.isArrayLike=n})(See)),See}var Oee={},R8e;function eJn(){return R8e||(R8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});function t(n){return typeof n=="object"&&n!==null}e.isObjectLike=t})(Oee)),Oee}var P8e;function tJn(){return P8e||(P8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});const t=TSt(),n=eJn();function r(s){return n.isObjectLike(s)&&t.isArrayLike(s)}e.isArrayLikeObject=r})(wee)),wee}var _ee={},Cee={},$8e;function nJn(){return $8e||($8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});const t=uSe();function n(r){return function(s){return t.get(s,r)}}e.property=n})(Cee)),Cee}var Eee={},jee={},Tee={},Nee={},M8e;function NSt(){return M8e||(M8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});function t(n){return n!==null&&(typeof n=="object"||typeof n=="function")}e.isObject=t})(Nee)),Nee}var Iee={},D8e;function ISt(){return D8e||(D8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});function t(n){return n==null||typeof n!="object"&&typeof n!="function"}e.isPrimitive=t})(Iee)),Iee}var Aee={},L8e;function ASt(){return L8e||(L8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});function t(n,r){return n===r||Number.isNaN(n)&&Number.isNaN(r)}e.isEqualsSameValueZero=t})(Aee)),Aee}var F8e;function rJn(){return F8e||(F8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});const t=NSt(),n=ISt(),r=ASt();function s(d,f,p){return typeof p!="function"?s(d,f,()=>{}):a(d,f,function h(m,v,y,b,S,w){const k=p(m,v,y,b,S,w);return k!==void 0?!!k:a(m,v,h,w)},new Map)}function a(d,f,p,h){if(f===d)return!0;switch(typeof f){case"object":return i(d,f,p,h);case"function":return Object.keys(f).length>0?a(d,{...f},p,h):r.isEqualsSameValueZero(d,f);default:return t.isObject(d)?typeof f=="string"?f==="":!0:r.isEqualsSameValueZero(d,f)}}function i(d,f,p,h){if(f==null)return!0;if(Array.isArray(f))return c(d,f,p,h);if(f instanceof Map)return l(d,f,p,h);if(f instanceof Set)return u(d,f,p,h);const m=Object.keys(f);if(d==null||n.isPrimitive(d))return m.length===0;if(m.length===0)return!0;if(h?.has(f))return h.get(f)===d;h?.set(f,d);try{for(let v=0;v<m.length;v++){const y=m[v];if(!n.isPrimitive(d)&&!(y in d)||f[y]===void 0&&d[y]!==void 0||f[y]===null&&d[y]!==null||!p(d[y],f[y],y,d,f,h))return!1}return!0}finally{h?.delete(f)}}function l(d,f,p,h){if(f.size===0)return!0;if(!(d instanceof Map))return!1;for(const[m,v]of f.entries()){const y=d.get(m);if(p(y,v,m,d,f,h)===!1)return!1}return!0}function c(d,f,p,h){if(f.length===0)return!0;if(!Array.isArray(d))return!1;const m=new Set;for(let v=0;v<f.length;v++){const y=f[v];let b=!1;for(let S=0;S<d.length;S++){if(m.has(S))continue;const w=d[S];let k=!1;if(p(w,y,v,d,f,h)&&(k=!0),k){m.add(S),b=!0;break}}if(!b)return!1}return!0}function u(d,f,p,h){return f.size===0?!0:d instanceof Set?c([...d],[...f],p,h):!1}e.isMatchWith=s,e.isSetMatch=u})(Tee)),Tee}var z8e;function RSt(){return z8e||(z8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});const t=rJn();function n(r,s){return t.isMatchWith(r,s,()=>{})}e.isMatch=n})(jee)),jee}var Ree={},Pee={},$ee={},B8e;function sJn(){return B8e||(B8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});function t(n){return Object.getOwnPropertySymbols(n).filter(r=>Object.prototype.propertyIsEnumerable.call(n,r))}e.getSymbols=t})($ee)),$ee}var Mee={},U8e;function pSe(){return U8e||(U8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});function t(n){return n==null?n===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(n)}e.getTag=t})(Mee)),Mee}var Dee={},q8e;function PSt(){return q8e||(q8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});const t="[object RegExp]",n="[object String]",r="[object Number]",s="[object Boolean]",a="[object Arguments]",i="[object Symbol]",l="[object Date]",c="[object Map]",u="[object Set]",d="[object Array]",f="[object Function]",p="[object ArrayBuffer]",h="[object Object]",m="[object Error]",v="[object DataView]",y="[object Uint8Array]",b="[object Uint8ClampedArray]",S="[object Uint16Array]",w="[object Uint32Array]",k="[object BigUint64Array]",_="[object Int8Array]",C="[object Int16Array]",E="[object Int32Array]",j="[object BigInt64Array]",N="[object Float32Array]",I="[object Float64Array]";e.argumentsTag=a,e.arrayBufferTag=p,e.arrayTag=d,e.bigInt64ArrayTag=j,e.bigUint64ArrayTag=k,e.booleanTag=s,e.dataViewTag=v,e.dateTag=l,e.errorTag=m,e.float32ArrayTag=N,e.float64ArrayTag=I,e.functionTag=f,e.int16ArrayTag=C,e.int32ArrayTag=E,e.int8ArrayTag=_,e.mapTag=c,e.numberTag=r,e.objectTag=h,e.regexpTag=t,e.setTag=u,e.stringTag=n,e.symbolTag=i,e.uint16ArrayTag=S,e.uint32ArrayTag=w,e.uint8ArrayTag=y,e.uint8ClampedArrayTag=b})(Dee)),Dee}var Lee={},Fee={},V8e;function aJn(){return V8e||(V8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});const t=typeof globalThis=="object"&&globalThis||typeof window=="object"&&window||typeof self=="object"&&self||typeof Bj=="object"&&Bj||(function(){return this})()||Function("return this")();e.globalThis=t})(Fee)),Fee}var H8e;function iJn(){return H8e||(H8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});const t=aJn();function n(r){return typeof t.globalThis.Buffer<"u"&&t.globalThis.Buffer.isBuffer(r)}e.isBuffer=n})(Lee)),Lee}var zee={},W8e;function oJn(){return W8e||(W8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});function t(n){return ArrayBuffer.isView(n)&&!(n instanceof DataView)}e.isTypedArray=t})(zee)),zee}var Z8e;function $St(){return Z8e||(Z8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});const t=sJn(),n=pSe(),r=PSt(),s=iJn(),a=ISt(),i=oJn();function l(f,p){return c(f,void 0,f,new Map,p)}function c(f,p,h,m=new Map,v=void 0){const y=v?.(f,p,h,m);if(y!==void 0)return y;if(a.isPrimitive(f))return f;if(m.has(f))return m.get(f);if(Array.isArray(f)){const b=new Array(f.length);m.set(f,b);for(let S=0;S<f.length;S++)b[S]=c(f[S],S,h,m,v);return Object.hasOwn(f,"index")&&(b.index=f.index),Object.hasOwn(f,"input")&&(b.input=f.input),b}if(f instanceof Date)return new Date(f.getTime());if(f instanceof RegExp){const b=new RegExp(f.source,f.flags);return b.lastIndex=f.lastIndex,b}if(f instanceof Map){const b=new Map;m.set(f,b);for(const[S,w]of f)b.set(S,c(w,S,h,m,v));return b}if(f instanceof Set){const b=new Set;m.set(f,b);for(const S of f)b.add(c(S,void 0,h,m,v));return b}if(s.isBuffer(f))return f.subarray();if(i.isTypedArray(f)){const b=new(Object.getPrototypeOf(f)).constructor(f.length);m.set(f,b);for(let S=0;S<f.length;S++)b[S]=c(f[S],S,h,m,v);return b}if(f instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&f instanceof SharedArrayBuffer)return f.slice(0);if(f instanceof DataView){const b=new DataView(f.buffer.slice(0),f.byteOffset,f.byteLength);return m.set(f,b),u(b,f,h,m,v),b}if(typeof File<"u"&&f instanceof File){const b=new File([f],f.name,{type:f.type});return m.set(f,b),u(b,f,h,m,v),b}if(typeof Blob<"u"&&f instanceof Blob){const b=new Blob([f],{type:f.type});return m.set(f,b),u(b,f,h,m,v),b}if(f instanceof Error){const b=structuredClone(f);return m.set(f,b),b.message=f.message,b.name=f.name,b.stack=f.stack,b.cause=f.cause,b.constructor=f.constructor,u(b,f,h,m,v),b}if(f instanceof Boolean){const b=new Boolean(f.valueOf());return m.set(f,b),u(b,f,h,m,v),b}if(f instanceof Number){const b=new Number(f.valueOf());return m.set(f,b),u(b,f,h,m,v),b}if(f instanceof String){const b=new String(f.valueOf());return m.set(f,b),u(b,f,h,m,v),b}if(typeof f=="object"&&d(f)){const b=Object.create(Object.getPrototypeOf(f));return m.set(f,b),u(b,f,h,m,v),b}return f}function u(f,p,h=f,m,v){const y=[...Object.keys(p),...t.getSymbols(p)];for(let b=0;b<y.length;b++){const S=y[b],w=Object.getOwnPropertyDescriptor(f,S);(w==null||w.writable)&&(f[S]=c(p[S],S,h,m,v))}}function d(f){switch(n.getTag(f)){case r.argumentsTag:case r.arrayTag:case r.arrayBufferTag:case r.dataViewTag:case r.booleanTag:case r.dateTag:case r.float32ArrayTag:case r.float64ArrayTag:case r.int8ArrayTag:case r.int16ArrayTag:case r.int32ArrayTag:case r.mapTag:case r.numberTag:case r.objectTag:case r.regexpTag:case r.setTag:case r.stringTag:case r.symbolTag:case r.uint8ArrayTag:case r.uint8ClampedArrayTag:case r.uint16ArrayTag:case r.uint32ArrayTag:return!0;default:return!1}}e.cloneDeepWith=l,e.cloneDeepWithImpl=c,e.copyProperties=u})(Pee)),Pee}var G8e;function lJn(){return G8e||(G8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});const t=$St();function n(r){return t.cloneDeepWithImpl(r,void 0,r,new Map,void 0)}e.cloneDeep=n})(Ree)),Ree}var Q8e;function cJn(){return Q8e||(Q8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});const t=RSt(),n=lJn();function r(s){return s=n.cloneDeep(s),a=>t.isMatch(a,s)}e.matches=r})(Eee)),Eee}var Bee={},Uee={},qee={},Y8e;function uJn(){return Y8e||(Y8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});const t=$St(),n=pSe(),r=PSt();function s(a,i){return t.cloneDeepWith(a,(l,c,u,d)=>{const f=i?.(l,c,u,d);if(f!==void 0)return f;if(typeof a=="object"){if(n.getTag(a)===r.objectTag&&typeof a.constructor!="function"){const p={};return d.set(a,p),t.copyProperties(p,a,u,d),p}switch(Object.prototype.toString.call(a)){case r.numberTag:case r.stringTag:case r.booleanTag:{const p=new a.constructor(a?.valueOf());return t.copyProperties(p,a),p}case r.argumentsTag:{const p={};return t.copyProperties(p,a),p.length=a.length,p[Symbol.iterator]=a[Symbol.iterator],p}default:return}}})}e.cloneDeepWith=s})(qee)),qee}var X8e;function dJn(){return X8e||(X8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});const t=uJn();function n(r){return t.cloneDeepWith(r)}e.cloneDeep=n})(Uee)),Uee}var Vee={},Hee={},K8e;function MSt(){return K8e||(K8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});const t=/^(?:0|[1-9]\d*)$/;function n(r,s=Number.MAX_SAFE_INTEGER){switch(typeof r){case"number":return Number.isInteger(r)&&r>=0&&r<s;case"symbol":return!1;case"string":return t.test(r)}}e.isIndex=n})(Hee)),Hee}var Wee={},J8e;function fJn(){return J8e||(J8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});const t=pSe();function n(r){return r!==null&&typeof r=="object"&&t.getTag(r)==="[object Arguments]"}e.isArguments=n})(Wee)),Wee}var eze;function pJn(){return eze||(eze=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});const t=SSt(),n=MSt(),r=fJn(),s=cSe();function a(i,l){let c;if(Array.isArray(l)?c=l:typeof l=="string"&&t.isDeepKey(l)&&i?.[l]==null?c=s.toPath(l):c=[l],c.length===0)return!1;let u=i;for(let d=0;d<c.length;d++){const f=c[d];if((u==null||!Object.hasOwn(u,f))&&!((Array.isArray(u)||r.isArguments(u))&&n.isIndex(f)&&f<u.length))return!1;u=u[f]}return!0}e.has=a})(Vee)),Vee}var tze;function hJn(){return tze||(tze=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});const t=RSt(),n=lSe(),r=dJn(),s=uSe(),a=pJn();function i(l,c){switch(typeof l){case"object":{Object.is(l?.valueOf(),-0)&&(l="-0");break}case"number":{l=n.toKey(l);break}}return c=r.cloneDeep(c),function(u){const d=s.get(u,l);return d===void 0?a.has(u,l):c===void 0?d===void 0:t.isMatch(d,c)}}e.matchesProperty=i})(Bee)),Bee}var nze;function mJn(){return nze||(nze=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});const t=jSt(),n=nJn(),r=cJn(),s=hJn();function a(i){if(i==null)return t.identity;switch(typeof i){case"function":return i;case"object":return Array.isArray(i)&&i.length===2?s.matchesProperty(i[0],i[1]):r.matches(i);case"string":case"symbol":case"number":return n.property(i)}}e.iteratee=a})(_ee)),_ee}var rze;function gJn(){return rze||(rze=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});const t=XKn(),n=KKn(),r=jSt(),s=tJn(),a=mJn();function i(l,c=r.identity){return s.isArrayLikeObject(l)?t.uniqBy(Array.from(l),n.ary(a.iteratee(c),1)):[]}e.uniqBy=i})(vee)),vee}var Zee,sze;function vJn(){return sze||(sze=1,Zee=gJn().uniqBy),Zee}var yJn=vJn();const aze=Tc(yJn);function bJn(e,t,n){return t===!0?aze(e,n):typeof t=="function"?aze(e,t):e}var hSe=g.createContext(null),xJn=e=>e,so=()=>{var e=g.useContext(hSe);return e?e.store.dispatch:xJn},o8=()=>{},wJn=()=>o8,SJn=(e,t)=>e===t;function Kn(e){var t=g.useContext(hSe),n=g.useMemo(()=>t?r=>{if(r!=null)return e(r)}:o8,[t,e]);return gxe.useSyncExternalStoreWithSelector(t?t.subscription.addNestedSub:wJn,t?t.store.getState:o8,t?t.store.getState:o8,n,SJn)}var Gee={},Qee={},Yee={},ize;function kJn(){return ize||(ize=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});function t(r){return typeof r=="symbol"?1:r===null?2:r===void 0?3:r!==r?4:0}const n=(r,s,a)=>{if(r!==s){const i=t(r),l=t(s);if(i===l&&i===0){if(r<s)return a==="desc"?1:-1;if(r>s)return a==="desc"?-1:1}return a==="desc"?l-i:i-l}return 0};e.compareValues=n})(Yee)),Yee}var Xee={},Kee={},oze;function DSt(){return oze||(oze=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});function t(n){return typeof n=="symbol"||n instanceof Symbol}e.isSymbol=t})(Kee)),Kee}var lze;function OJn(){return lze||(lze=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});const t=DSt(),n=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,r=/^\w*$/;function s(a,i){return Array.isArray(a)?!1:typeof a=="number"||typeof a=="boolean"||a==null||t.isSymbol(a)?!0:typeof a=="string"&&(r.test(a)||!n.test(a))||i!=null&&Object.hasOwn(i,a)}e.isKey=s})(Xee)),Xee}var cze;function _Jn(){return cze||(cze=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});const t=kJn(),n=OJn(),r=cSe();function s(a,i,l,c){if(a==null)return[];l=c?void 0:l,Array.isArray(a)||(a=Object.values(a)),Array.isArray(i)||(i=i==null?[null]:[i]),i.length===0&&(i=[null]),Array.isArray(l)||(l=l==null?[]:[l]),l=l.map(h=>String(h));const u=(h,m)=>{let v=h;for(let y=0;y<m.length&&v!=null;++y)v=v[m[y]];return v},d=(h,m)=>m==null||h==null?m:typeof h=="object"&&"key"in h?Object.hasOwn(m,h.key)?m[h.key]:u(m,h.path):typeof h=="function"?h(m):Array.isArray(h)?u(m,h):typeof m=="object"?m[h]:m,f=i.map(h=>(Array.isArray(h)&&h.length===1&&(h=h[0]),h==null||typeof h=="function"||Array.isArray(h)||n.isKey(h)?h:{key:h,path:r.toPath(h)}));return a.map(h=>({original:h,criteria:f.map(m=>d(m,h))})).slice().sort((h,m)=>{for(let v=0;v<f.length;v++){const y=t.compareValues(h.criteria[v],m.criteria[v],l[v]);if(y!==0)return y}return 0}).map(h=>h.original)}e.orderBy=s})(Qee)),Qee}var Jee={},uze;function CJn(){return uze||(uze=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});function t(n,r=1){const s=[],a=Math.floor(r),i=(l,c)=>{for(let u=0;u<l.length;u++){const d=l[u];Array.isArray(d)&&c<a?i(d,c+1):s.push(d)}};return i(n,0),s}e.flatten=t})(Jee)),Jee}var ete={},dze;function LSt(){return dze||(dze=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});const t=MSt(),n=TSt(),r=NSt(),s=ASt();function a(i,l,c){return r.isObject(c)&&(typeof l=="number"&&n.isArrayLike(c)&&t.isIndex(l)&&l<c.length||typeof l=="string"&&l in c)?s.isEqualsSameValueZero(c[l],i):!1}e.isIterateeCall=a})(ete)),ete}var fze;function EJn(){return fze||(fze=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});const t=_Jn(),n=CJn(),r=LSt();function s(a,...i){const l=i.length;return l>1&&r.isIterateeCall(a,i[0],i[1])?i=[]:l>2&&r.isIterateeCall(i[0],i[1],i[2])&&(i=[i[0]]),t.orderBy(a,n.flatten(i),["asc"])}e.sortBy=s})(Gee)),Gee}var tte,pze;function jJn(){return pze||(pze=1,tte=EJn().sortBy),tte}var TJn=jJn();const iH=Tc(TJn);var FSt=e=>e.legend.settings,NJn=e=>e.legend.size,IJn=e=>e.legend.payload;at([IJn,FSt],(e,t)=>{var{itemSorter:n}=t,r=e.flat(1);return n?iH(r,n):r});var D6=1;function AJn(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],[t,n]=g.useState({height:0,left:0,top:0,width:0}),r=g.useCallback(s=>{if(s!=null){var a=s.getBoundingClientRect(),i={height:a.height,left:a.left,top:a.top,width:a.width};(Math.abs(i.height-t.height)>D6||Math.abs(i.left-t.left)>D6||Math.abs(i.top-t.top)>D6||Math.abs(i.width-t.width)>D6)&&n({height:i.height,left:i.left,top:i.top,width:i.width})}},[t.width,t.height,t.top,t.left,...e]);return[t,r]}function dc(e){return`Minified Redux error #${e}; visit https://redux.js.org/Errors?code=${e} for the full message or use the non-minified dev environment for full errors. `}var RJn=typeof Symbol=="function"&&Symbol.observable||"@@observable",hze=RJn,nte=()=>Math.random().toString(36).substring(7).split("").join("."),PJn={INIT:`@@redux/INIT${nte()}`,REPLACE:`@@redux/REPLACE${nte()}`,PROBE_UNKNOWN_ACTION:()=>`@@redux/PROBE_UNKNOWN_ACTION${nte()}`},G7=PJn;function mSe(e){if(typeof e!="object"||e===null)return!1;let t=e;for(;Object.getPrototypeOf(t)!==null;)t=Object.getPrototypeOf(t);return Object.getPrototypeOf(e)===t||Object.getPrototypeOf(e)===null}function gSe(e,t,n){if(typeof e!="function")throw new Error(dc(2));if(typeof t=="function"&&typeof n=="function"||typeof n=="function"&&typeof arguments[3]=="function")throw new Error(dc(0));if(typeof t=="function"&&typeof n>"u"&&(n=t,t=void 0),typeof n<"u"){if(typeof n!="function")throw new Error(dc(1));return n(gSe)(e,t)}let r=e,s=t,a=new Map,i=a,l=0,c=!1;function u(){i===a&&(i=new Map,a.forEach((y,b)=>{i.set(b,y)}))}function d(){if(c)throw new Error(dc(3));return s}function f(y){if(typeof y!="function")throw new Error(dc(4));if(c)throw new Error(dc(5));let b=!0;u();const S=l++;return i.set(S,y),function(){if(b){if(c)throw new Error(dc(6));b=!1,u(),i.delete(S),a=null}}}function p(y){if(!mSe(y))throw new Error(dc(7));if(typeof y.type>"u")throw new Error(dc(8));if(typeof y.type!="string")throw new Error(dc(17));if(c)throw new Error(dc(9));try{c=!0,s=r(s,y)}finally{c=!1}return(a=i).forEach(S=>{S()}),y}function h(y){if(typeof y!="function")throw new Error(dc(10));r=y,p({type:G7.REPLACE})}function m(){const y=f;return{subscribe(b){if(typeof b!="object"||b===null)throw new Error(dc(11));function S(){const k=b;k.next&&k.next(d())}return S(),{unsubscribe:y(S)}},[hze](){return this}}}return p({type:G7.INIT}),{dispatch:p,subscribe:f,getState:d,replaceReducer:h,[hze]:m}}function $Jn(e){Object.keys(e).forEach(t=>{const n=e[t];if(typeof n(void 0,{type:G7.INIT})>"u")throw new Error(dc(12));if(typeof n(void 0,{type:G7.PROBE_UNKNOWN_ACTION()})>"u")throw new Error(dc(13))})}function zSt(e){const t=Object.keys(e),n={};for(let a=0;a<t.length;a++){const i=t[a];typeof e[i]=="function"&&(n[i]=e[i])}const r=Object.keys(n);let s;try{$Jn(n)}catch(a){s=a}return function(i={},l){if(s)throw s;let c=!1;const u={};for(let d=0;d<r.length;d++){const f=r[d],p=n[f],h=i[f],m=p(h,l);if(typeof m>"u")throw l&&l.type,new Error(dc(14));u[f]=m,c=c||m!==h}return c=c||r.length!==Object.keys(i).length,c?u:i}}function mze(e,t){return function(...n){return t(e.apply(this,n))}}function gze(e,t){if(typeof e=="function")return mze(e,t);if(typeof e!="object"||e===null)throw new Error(dc(16));const n={};for(const r in e){const s=e[r];typeof s=="function"&&(n[r]=mze(s,t))}return n}function hM(...e){return e.length===0?t=>t:e.length===1?e[0]:e.reduce((t,n)=>(...r)=>t(n(...r)))}function BSt(...e){return t=>(n,r)=>{const s=t(n,r);let a=()=>{throw new Error(dc(15))};const i={getState:s.getState,dispatch:(c,...u)=>a(c,...u)},l=e.map(c=>c(i));return a=hM(...l)(s.dispatch),{...s,dispatch:a}}}function USt(e){return mSe(e)&&"type"in e&&typeof e.type=="string"}var qSt=Symbol.for("immer-nothing"),vze=Symbol.for("immer-draftable"),Cd=Symbol.for("immer-state");function og(e,...t){throw new Error(`[Immer] minified error nr: ${e}. Full error at: https://bit.ly/3cXEKWf`)}var wp=Object,NT=wp.getPrototypeOf,Q7="constructor",oH="prototype",eme="configurable",Y7="enumerable",l8="writable",mM="value",jx=e=>!!e&&!!e[Cd];function Ng(e){return e?VSt(e)||cH(e)||!!e[vze]||!!e[Q7]?.[vze]||uH(e)||dH(e):!1}var MJn=wp[oH][Q7].toString(),yze=new WeakMap;function VSt(e){if(!e||!vSe(e))return!1;const t=NT(e);if(t===null||t===wp[oH])return!0;const n=wp.hasOwnProperty.call(t,Q7)&&t[Q7];if(n===Object)return!0;if(!OE(n))return!1;let r=yze.get(n);return r===void 0&&(r=Function.toString.call(n),yze.set(n,r)),r===MJn}function lH(e,t,n=!0){E3(e)===0?(n?Reflect.ownKeys(e):wp.keys(e)).forEach(s=>{t(s,e[s],e)}):e.forEach((r,s)=>t(s,r,e))}function E3(e){const t=e[Cd];return t?t.type_:cH(e)?1:uH(e)?2:dH(e)?3:0}var bze=(e,t,n=E3(e))=>n===2?e.has(t):wp[oH].hasOwnProperty.call(e,t),tme=(e,t,n=E3(e))=>n===2?e.get(t):e[t],X7=(e,t,n,r=E3(e))=>{r===2?e.set(t,n):r===3?e.add(n):e[t]=n};function DJn(e,t){return e===t?e!==0||1/e===1/t:e!==e&&t!==t}var cH=Array.isArray,uH=e=>e instanceof Map,dH=e=>e instanceof Set,vSe=e=>typeof e=="object",OE=e=>typeof e=="function",rte=e=>typeof e=="boolean";function LJn(e){const t=+e;return Number.isInteger(t)&&String(t)===e}var Lb=e=>e.copy_||e.base_,ySe=e=>e.modified_?e.copy_:e.base_;function nme(e,t){if(uH(e))return new Map(e);if(dH(e))return new Set(e);if(cH(e))return Array[oH].slice.call(e);const n=VSt(e);if(t===!0||t==="class_only"&&!n){const r=wp.getOwnPropertyDescriptors(e);delete r[Cd];let s=Reflect.ownKeys(r);for(let a=0;a<s.length;a++){const i=s[a],l=r[i];l[l8]===!1&&(l[l8]=!0,l[eme]=!0),(l.get||l.set)&&(r[i]={[eme]:!0,[l8]:!0,[Y7]:l[Y7],[mM]:e[i]})}return wp.create(NT(e),r)}else{const r=NT(e);if(r!==null&&n)return{...e};const s=wp.create(r);return wp.assign(s,e)}}function bSe(e,t=!1){return fH(e)||jx(e)||!Ng(e)||(E3(e)>1&&wp.defineProperties(e,{set:L6,add:L6,clear:L6,delete:L6}),wp.freeze(e),t&&lH(e,(n,r)=>{bSe(r,!0)},!1)),e}function FJn(){og(2)}var L6={[mM]:FJn};function fH(e){return e===null||!vSe(e)?!0:wp.isFrozen(e)}var K7="MapSet",rme="Patches",xze="ArrayMethods",HSt={};function VO(e){const t=HSt[e];return t||og(0,e),t}var wze=e=>!!HSt[e],gM,WSt=()=>gM,zJn=(e,t)=>({drafts_:[],parent_:e,immer_:t,canAutoFreeze_:!0,unfinalizedDrafts_:0,handledSet_:new Set,processedForPatches_:new Set,mapSetPlugin_:wze(K7)?VO(K7):void 0,arrayMethodsPlugin_:wze(xze)?VO(xze):void 0});function Sze(e,t){t&&(e.patchPlugin_=VO(rme),e.patches_=[],e.inversePatches_=[],e.patchListener_=t)}function sme(e){ame(e),e.drafts_.forEach(BJn),e.drafts_=null}function ame(e){e===gM&&(gM=e.parent_)}var kze=e=>gM=zJn(gM,e);function BJn(e){const t=e[Cd];t.type_===0||t.type_===1?t.revoke_():t.revoked_=!0}function Oze(e,t){t.unfinalizedDrafts_=t.drafts_.length;const n=t.drafts_[0];if(e!==void 0&&e!==n){n[Cd].modified_&&(sme(t),og(4)),Ng(e)&&(e=_ze(t,e));const{patchPlugin_:s}=t;s&&s.generateReplacementPatches_(n[Cd].base_,e,t)}else e=_ze(t,n);return UJn(t,e,!0),sme(t),t.patches_&&t.patchListener_(t.patches_,t.inversePatches_),e!==qSt?e:void 0}function _ze(e,t){if(fH(t))return t;const n=t[Cd];if(!n)return J7(t,e.handledSet_,e);if(!pH(n,e))return t;if(!n.modified_)return n.base_;if(!n.finalized_){const{callbacks_:r}=n;if(r)for(;r.length>0;)r.pop()(e);QSt(n,e)}return n.copy_}function UJn(e,t,n=!1){!e.parent_&&e.immer_.autoFreeze_&&e.canAutoFreeze_&&bSe(t,n)}function ZSt(e){e.finalized_=!0,e.scope_.unfinalizedDrafts_--}var pH=(e,t)=>e.scope_===t,qJn=[];function GSt(e,t,n,r){const s=Lb(e),a=e.type_;if(r!==void 0&&tme(s,r,a)===t){X7(s,r,n,a);return}if(!e.draftLocations_){const l=e.draftLocations_=new Map;lH(s,(c,u)=>{if(jx(u)){const d=l.get(u)||[];d.push(c),l.set(u,d)}})}const i=e.draftLocations_.get(t)??qJn;for(const l of i)X7(s,l,n,a)}function VJn(e,t,n){e.callbacks_.push(function(s){const a=t;if(!a||!pH(a,s))return;s.mapSetPlugin_?.fixSetContents(a);const i=ySe(a);GSt(e,a.draft_??a,i,n),QSt(a,s)})}function QSt(e,t){if(e.modified_&&!e.finalized_&&(e.type_===3||e.type_===1&&e.allIndicesReassigned_||(e.assigned_?.size??0)>0)){const{patchPlugin_:r}=t;if(r){const s=r.getPath(e);s&&r.generatePatches_(e,s,t)}ZSt(e)}}function HJn(e,t,n){const{scope_:r}=e;if(jx(n)){const s=n[Cd];pH(s,r)&&s.callbacks_.push(function(){c8(e);const i=ySe(s);GSt(e,n,i,t)})}else Ng(n)&&e.callbacks_.push(function(){const a=Lb(e);e.type_===3?a.has(n)&&J7(n,r.handledSet_,r):tme(a,t,e.type_)===n&&r.drafts_.length>1&&(e.assigned_.get(t)??!1)===!0&&e.copy_&&J7(tme(e.copy_,t,e.type_),r.handledSet_,r)})}function J7(e,t,n){return!n.immer_.autoFreeze_&&n.unfinalizedDrafts_<1||jx(e)||t.has(e)||!Ng(e)||fH(e)||(t.add(e),lH(e,(r,s)=>{if(jx(s)){const a=s[Cd];if(pH(a,n)){const i=ySe(a);X7(e,r,i,e.type_),ZSt(a)}}else Ng(s)&&J7(s,t,n)})),e}function WJn(e,t){const n=cH(e),r={type_:n?1:0,scope_:t?t.scope_:WSt(),modified_:!1,finalized_:!1,assigned_:void 0,parent_:t,base_:e,draft_:null,copy_:null,revoke_:null,isManual_:!1,callbacks_:void 0};let s=r,a=eB;n&&(s=[r],a=vM);const{revoke:i,proxy:l}=Proxy.revocable(s,a);return r.draft_=l,r.revoke_=i,[l,r]}var eB={get(e,t){if(t===Cd)return e;let n=e.scope_.arrayMethodsPlugin_;const r=e.type_===1&&typeof t=="string";if(r&&n?.isArrayOperationMethod(t))return n.createMethodInterceptor(e,t);const s=Lb(e);if(!bze(s,t,e.type_))return ZJn(e,s,t);const a=s[t];if(e.finalized_||!Ng(a)||r&&e.operationMethod&&n?.isMutatingArrayMethod(e.operationMethod)&&LJn(t))return a;if(a===ste(e.base_,t)){c8(e);const i=e.type_===1?+t:t,l=ome(e.scope_,a,e,i);return e.copy_[i]=l}return a},has(e,t){return t in Lb(e)},ownKeys(e){return Reflect.ownKeys(Lb(e))},set(e,t,n){const r=YSt(Lb(e),t);if(r?.set)return r.set.call(e.draft_,n),!0;if(!e.modified_){const s=ste(Lb(e),t),a=s?.[Cd];if(a&&a.base_===n)return e.copy_[t]=n,e.assigned_.set(t,!1),!0;if(DJn(n,s)&&(n!==void 0||bze(e.base_,t,e.type_)))return!0;c8(e),ime(e)}return e.copy_[t]===n&&(n!==void 0||t in e.copy_)||Number.isNaN(n)&&Number.isNaN(e.copy_[t])||(e.copy_[t]=n,e.assigned_.set(t,!0),HJn(e,t,n)),!0},deleteProperty(e,t){return c8(e),ste(e.base_,t)!==void 0||t in e.base_?(e.assigned_.set(t,!1),ime(e)):e.assigned_.delete(t),e.copy_&&delete e.copy_[t],!0},getOwnPropertyDescriptor(e,t){const n=Lb(e),r=Reflect.getOwnPropertyDescriptor(n,t);return r&&{[l8]:!0,[eme]:e.type_!==1||t!=="length",[Y7]:r[Y7],[mM]:n[t]}},defineProperty(){og(11)},getPrototypeOf(e){return NT(e.base_)},setPrototypeOf(){og(12)}},vM={};for(let e in eB){let t=eB[e];vM[e]=function(){const n=arguments;return n[0]=n[0][0],t.apply(this,n)}}vM.deleteProperty=function(e,t){return vM.set.call(this,e,t,void 0)};vM.set=function(e,t,n){return eB.set.call(this,e[0],t,n,e[0])};function ste(e,t){const n=e[Cd];return(n?Lb(n):e)[t]}function ZJn(e,t,n){const r=YSt(t,n);return r?mM in r?r[mM]:r.get?.call(e.draft_):void 0}function YSt(e,t){if(!(t in e))return;let n=NT(e);for(;n;){const r=Object.getOwnPropertyDescriptor(n,t);if(r)return r;n=NT(n)}}function ime(e){e.modified_||(e.modified_=!0,e.parent_&&ime(e.parent_))}function c8(e){e.copy_||(e.assigned_=new Map,e.copy_=nme(e.base_,e.scope_.immer_.useStrictShallowCopy_))}var GJn=class{constructor(t){this.autoFreeze_=!0,this.useStrictShallowCopy_=!1,this.useStrictIteration_=!1,this.produce=(n,r,s)=>{if(OE(n)&&!OE(r)){const i=r;r=n;const l=this;return function(u=i,...d){return l.produce(u,f=>r.call(this,f,...d))}}OE(r)||og(6),s!==void 0&&!OE(s)&&og(7);let a;if(Ng(n)){const i=kze(this),l=ome(i,n,void 0);let c=!0;try{a=r(l),c=!1}finally{c?sme(i):ame(i)}return Sze(i,s),Oze(a,i)}else if(!n||!vSe(n)){if(a=r(n),a===void 0&&(a=n),a===qSt&&(a=void 0),this.autoFreeze_&&bSe(a,!0),s){const i=[],l=[];VO(rme).generateReplacementPatches_(n,a,{patches_:i,inversePatches_:l}),s(i,l)}return a}else og(1,n)},this.produceWithPatches=(n,r)=>{if(OE(n))return(l,...c)=>this.produceWithPatches(l,u=>n(u,...c));let s,a;return[this.produce(n,r,(l,c)=>{s=l,a=c}),s,a]},rte(t?.autoFreeze)&&this.setAutoFreeze(t.autoFreeze),rte(t?.useStrictShallowCopy)&&this.setUseStrictShallowCopy(t.useStrictShallowCopy),rte(t?.useStrictIteration)&&this.setUseStrictIteration(t.useStrictIteration)}createDraft(t){Ng(t)||og(8),jx(t)&&(t=Bh(t));const n=kze(this),r=ome(n,t,void 0);return r[Cd].isManual_=!0,ame(n),r}finishDraft(t,n){const r=t&&t[Cd];(!r||!r.isManual_)&&og(9);const{scope_:s}=r;return Sze(s,n),Oze(void 0,s)}setAutoFreeze(t){this.autoFreeze_=t}setUseStrictShallowCopy(t){this.useStrictShallowCopy_=t}setUseStrictIteration(t){this.useStrictIteration_=t}shouldUseStrictIteration(){return this.useStrictIteration_}applyPatches(t,n){let r;for(r=n.length-1;r>=0;r--){const a=n[r];if(a.path.length===0&&a.op==="replace"){t=a.value;break}}r>-1&&(n=n.slice(r+1));const s=VO(rme).applyPatches_;return jx(t)?s(t,n):this.produce(t,a=>s(a,n))}};function ome(e,t,n,r){const[s,a]=uH(t)?VO(K7).proxyMap_(t,n):dH(t)?VO(K7).proxySet_(t,n):WJn(t,n);return(n?.scope_??WSt()).drafts_.push(s),a.callbacks_=n?.callbacks_??[],a.key_=r,n&&r!==void 0?VJn(n,a,r):a.callbacks_.push(function(c){c.mapSetPlugin_?.fixSetContents(a);const{patchPlugin_:u}=c;a.modified_&&u&&u.generatePatches_(a,[],c)}),s}function Bh(e){return jx(e)||og(10,e),XSt(e)}function XSt(e){if(!Ng(e)||fH(e))return e;const t=e[Cd];let n,r=!0;if(t){if(!t.modified_)return t.base_;t.finalized_=!0,n=nme(e,t.scope_.immer_.useStrictShallowCopy_),r=t.scope_.immer_.shouldUseStrictIteration()}else n=nme(e,!0);return lH(n,(s,a)=>{X7(n,s,XSt(a))},r),t&&(t.finalized_=!1),n}var QJn=new GJn,KSt=QJn.produce;function JSt(e){return({dispatch:n,getState:r})=>s=>a=>typeof a=="function"?a(n,r,e):s(a)}var YJn=JSt(),XJn=JSt,KJn=typeof window<"u"&&window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__?window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__:function(){if(arguments.length!==0)return typeof arguments[0]=="object"?hM:hM.apply(null,arguments)};function Vp(e,t){function n(...r){if(t){let s=t(...r);if(!s)throw new Error(Tp(0));return{type:e,payload:s.payload,..."meta"in s&&{meta:s.meta},..."error"in s&&{error:s.error}}}return{type:e,payload:r[0]}}return n.toString=()=>`${e}`,n.type=e,n.match=r=>USt(r)&&r.type===e,n}var ekt=class p2 extends Array{constructor(...t){super(...t),Object.setPrototypeOf(this,p2.prototype)}static get[Symbol.species](){return p2}concat(...t){return super.concat.apply(this,t)}prepend(...t){return t.length===1&&Array.isArray(t[0])?new p2(...t[0].concat(this)):new p2(...t.concat(this))}};function Cze(e){return Ng(e)?KSt(e,()=>{}):e}function F6(e,t,n){return e.has(t)?e.get(t):e.set(t,n(t)).get(t)}function JJn(e){return typeof e=="boolean"}var eer=()=>function(t){const{thunk:n=!0,immutableCheck:r=!0,serializableCheck:s=!0,actionCreatorCheck:a=!0}=t??{};let i=new ekt;return n&&(JJn(n)?i.push(YJn):i.push(XJn(n.extraArgument))),i},tkt="RTK_autoBatch",Wi=()=>e=>({payload:e,meta:{[tkt]:!0}}),Eze=e=>t=>{setTimeout(t,e)},nkt=(e={type:"raf"})=>t=>(...n)=>{const r=t(...n);let s=!0,a=!1,i=!1;const l=new Set,c=e.type==="tick"?queueMicrotask:e.type==="raf"?typeof window<"u"&&window.requestAnimationFrame?window.requestAnimationFrame:Eze(10):e.type==="callback"?e.queueNotification:Eze(e.timeout),u=()=>{i=!1,a&&(a=!1,l.forEach(d=>d()))};return Object.assign({},r,{subscribe(d){const f=()=>s&&d(),p=r.subscribe(f);return l.add(d),()=>{p(),l.delete(d)}},dispatch(d){try{return s=!d?.meta?.[tkt],a=!s,a&&(i||(i=!0,c(u))),r.dispatch(d)}finally{s=!0}}})},ter=e=>function(n){const{autoBatch:r=!0}=n??{};let s=new ekt(e);return r&&s.push(nkt(typeof r=="object"?r:void 0)),s};function ner(e){const t=eer(),{reducer:n=void 0,middleware:r,devTools:s=!0,preloadedState:a=void 0,enhancers:i=void 0}=e||{};let l;if(typeof n=="function")l=n;else if(mSe(n))l=zSt(n);else throw new Error(Tp(1));let c;typeof r=="function"?c=r(t):c=t();let u=hM;s&&(u=KJn({trace:!1,...typeof s=="object"&&s}));const d=BSt(...c),f=ter(d);let p=typeof i=="function"?i(f):f();const h=u(...p);return gSe(l,a,h)}function rkt(e){const t={},n=[];let r;const s={addCase(a,i){const l=typeof a=="string"?a:a.type;if(!l)throw new Error(Tp(28));if(l in t)throw new Error(Tp(29));return t[l]=i,s},addAsyncThunk(a,i){return i.pending&&(t[a.pending.type]=i.pending),i.rejected&&(t[a.rejected.type]=i.rejected),i.fulfilled&&(t[a.fulfilled.type]=i.fulfilled),i.settled&&n.push({matcher:a.settled,reducer:i.settled}),s},addMatcher(a,i){return n.push({matcher:a,reducer:i}),s},addDefaultCase(a){return r=a,s}};return e(s),[t,n,r]}function rer(e){return typeof e=="function"}function ser(e,t){let[n,r,s]=rkt(t),a;if(rer(e))a=()=>Cze(e());else{const l=Cze(e);a=()=>l}function i(l=a(),c){let u=[n[c.type],...r.filter(({matcher:d})=>d(c)).map(({reducer:d})=>d)];return u.filter(d=>!!d).length===0&&(u=[s]),u.reduce((d,f)=>{if(f)if(jx(d)){const h=f(d,c);return h===void 0?d:h}else{if(Ng(d))return KSt(d,p=>f(p,c));{const p=f(d,c);if(p===void 0){if(d===null)return d;throw Error("A case reducer on a non-draftable value must not return undefined")}return p}}return d},l)}return i.getInitialState=a,i}var aer="ModuleSymbhasOwnPr-0123456789ABCDEFGHNRVfgctiUvz_KqYTJkLxpZXIjQW",ier=(e=21)=>{let t="",n=e;for(;n--;)t+=aer[Math.random()*64|0];return t},oer=Symbol.for("rtk-slice-createasyncthunk");function ler(e,t){return`${e}/${t}`}function cer({creators:e}={}){const t=e?.asyncThunk?.[oer];return function(r){const{name:s,reducerPath:a=s}=r;if(!s)throw new Error(Tp(11));const i=(typeof r.reducers=="function"?r.reducers(der()):r.reducers)||{},l=Object.keys(i),c={sliceCaseReducersByName:{},sliceCaseReducersByType:{},actionCreators:{},sliceMatchers:[]},u={addCase(w,k){const _=typeof w=="string"?w:w.type;if(!_)throw new Error(Tp(12));if(_ in c.sliceCaseReducersByType)throw new Error(Tp(13));return c.sliceCaseReducersByType[_]=k,u},addMatcher(w,k){return c.sliceMatchers.push({matcher:w,reducer:k}),u},exposeAction(w,k){return c.actionCreators[w]=k,u},exposeCaseReducer(w,k){return c.sliceCaseReducersByName[w]=k,u}};l.forEach(w=>{const k=i[w],_={reducerName:w,type:ler(s,w),createNotation:typeof r.reducers=="function"};per(k)?mer(_,k,u,t):fer(_,k,u)});function d(){const[w={},k=[],_=void 0]=typeof r.extraReducers=="function"?rkt(r.extraReducers):[r.extraReducers],C={...w,...c.sliceCaseReducersByType};return ser(r.initialState,E=>{for(let j in C)E.addCase(j,C[j]);for(let j of c.sliceMatchers)E.addMatcher(j.matcher,j.reducer);for(let j of k)E.addMatcher(j.matcher,j.reducer);_&&E.addDefaultCase(_)})}const f=w=>w,p=new Map,h=new WeakMap;let m;function v(w,k){return m||(m=d()),m(w,k)}function y(){return m||(m=d()),m.getInitialState()}function b(w,k=!1){function _(E){let j=E[w];return typeof j>"u"&&k&&(j=F6(h,_,y)),j}function C(E=f){const j=F6(p,k,()=>new WeakMap);return F6(j,E,()=>{const N={};for(const[I,R]of Object.entries(r.selectors??{}))N[I]=uer(R,E,()=>F6(h,E,y),k);return N})}return{reducerPath:w,getSelectors:C,get selectors(){return C(_)},selectSlice:_}}const S={name:s,reducer:v,actions:c.actionCreators,caseReducers:c.sliceCaseReducersByName,getInitialState:y,...b(a),injectInto(w,{reducerPath:k,..._}={}){const C=k??a;return w.inject({reducerPath:C,reducer:v},_),{...S,...b(C,!0)}}};return S}}function uer(e,t,n,r){function s(a,...i){let l=t(a);return typeof l>"u"&&r&&(l=n()),e(l,...i)}return s.unwrapped=e,s}var Hu=cer();function der(){function e(t,n){return{_reducerDefinitionType:"asyncThunk",payloadCreator:t,...n}}return e.withTypes=()=>e,{reducer(t){return Object.assign({[t.name](...n){return t(...n)}}[t.name],{_reducerDefinitionType:"reducer"})},preparedReducer(t,n){return{_reducerDefinitionType:"reducerWithPrepare",prepare:t,reducer:n}},asyncThunk:e}}function fer({type:e,reducerName:t,createNotation:n},r,s){let a,i;if("reducer"in r){if(n&&!her(r))throw new Error(Tp(17));a=r.reducer,i=r.prepare}else a=r;s.addCase(e,a).exposeCaseReducer(t,a).exposeAction(t,i?Vp(e,i):Vp(e))}function per(e){return e._reducerDefinitionType==="asyncThunk"}function her(e){return e._reducerDefinitionType==="reducerWithPrepare"}function mer({type:e,reducerName:t},n,r,s){if(!s)throw new Error(Tp(18));const{payloadCreator:a,fulfilled:i,pending:l,rejected:c,settled:u,options:d}=n,f=s(e,a,d);r.exposeAction(t,f),i&&r.addCase(f.fulfilled,i),l&&r.addCase(f.pending,l),c&&r.addCase(f.rejected,c),u&&r.addMatcher(f.settled,u),r.exposeCaseReducer(t,{fulfilled:i||z6,pending:l||z6,rejected:c||z6,settled:u||z6})}function z6(){}var ger="task",skt="listener",akt="completed",xSe="cancelled",ver=`task-${xSe}`,yer=`task-${akt}`,lme=`${skt}-${xSe}`,ber=`${skt}-${akt}`,hH=class{constructor(e){this.code=e,this.message=`${ger} ${xSe} (reason: ${e})`}name="TaskAbortError";message},wSe=(e,t)=>{if(typeof e!="function")throw new TypeError(Tp(32))},tB=()=>{},ikt=(e,t=tB)=>(e.catch(t),e),okt=(e,t)=>(e.addEventListener("abort",t,{once:!0}),()=>e.removeEventListener("abort",t)),Gk=e=>{if(e.aborted)throw new hH(e.reason)};function lkt(e,t){let n=tB;return new Promise((r,s)=>{const a=()=>s(new hH(e.reason));if(e.aborted){a();return}n=okt(e,a),t.finally(()=>n()).then(r,s)}).finally(()=>{n=tB})}var xer=async(e,t)=>{try{return await Promise.resolve(),{status:"ok",value:await e()}}catch(n){return{status:n instanceof hH?"cancelled":"rejected",error:n}}finally{t?.()}},nB=e=>t=>ikt(lkt(e,t).then(n=>(Gk(e),n))),ckt=e=>{const t=nB(e);return n=>t(new Promise(r=>setTimeout(r,n)))},{assign:Tj}=Object,jze={},mH="listenerMiddleware",wer=(e,t)=>{const n=r=>okt(e,()=>r.abort(e.reason));return(r,s)=>{wSe(r);const a=new AbortController;n(a);const i=xer(async()=>{Gk(e),Gk(a.signal);const l=await r({pause:nB(a.signal),delay:ckt(a.signal),signal:a.signal});return Gk(a.signal),l},()=>a.abort(yer));return s?.autoJoin&&t.push(i.catch(tB)),{result:nB(e)(i),cancel(){a.abort(ver)}}}},Ser=(e,t)=>{const n=async(r,s)=>{Gk(t);let a=()=>{};const l=[new Promise((c,u)=>{let d=e({predicate:r,effect:(f,p)=>{p.unsubscribe(),c([f,p.getState(),p.getOriginalState()])}});a=()=>{d(),u()}})];s!=null&&l.push(new Promise(c=>setTimeout(c,s,null)));try{const c=await lkt(t,Promise.race(l));return Gk(t),c}finally{a()}};return(r,s)=>ikt(n(r,s))},ukt=e=>{let{type:t,actionCreator:n,matcher:r,predicate:s,effect:a}=e;if(t)s=Vp(t).match;else if(n)t=n.type,s=n.match;else if(r)s=r;else if(!s)throw new Error(Tp(21));return wSe(a),{predicate:s,type:t,effect:a}},dkt=Tj(e=>{const{type:t,predicate:n,effect:r}=ukt(e);return{id:ier(),effect:r,type:t,predicate:n,pending:new Set,unsubscribe:()=>{throw new Error(Tp(22))}}},{withTypes:()=>dkt}),Tze=(e,t)=>{const{type:n,effect:r,predicate:s}=ukt(t);return Array.from(e.values()).find(a=>(typeof n=="string"?a.type===n:a.predicate===s)&&a.effect===r)},cme=e=>{e.pending.forEach(t=>{t.abort(lme)})},ker=(e,t)=>()=>{for(const n of t.keys())cme(n);e.clear()},Nze=(e,t,n)=>{try{e(t,n)}catch(r){setTimeout(()=>{throw r},0)}},fkt=Tj(Vp(`${mH}/add`),{withTypes:()=>fkt}),Oer=Vp(`${mH}/removeAll`),pkt=Tj(Vp(`${mH}/remove`),{withTypes:()=>pkt}),_er=(...e)=>{console.error(`${mH}/error`,...e)},j3=(e={})=>{const t=new Map,n=new Map,r=h=>{const m=n.get(h)??0;n.set(h,m+1)},s=h=>{const m=n.get(h)??1;m===1?n.delete(h):n.set(h,m-1)},{extra:a,onError:i=_er}=e;wSe(i);const l=h=>(h.unsubscribe=()=>t.delete(h.id),t.set(h.id,h),m=>{h.unsubscribe(),m?.cancelActive&&cme(h)}),c=h=>{const m=Tze(t,h)??dkt(h);return l(m)};Tj(c,{withTypes:()=>c});const u=h=>{const m=Tze(t,h);return m&&(m.unsubscribe(),h.cancelActive&&cme(m)),!!m};Tj(u,{withTypes:()=>u});const d=async(h,m,v,y)=>{const b=new AbortController,S=Ser(c,b.signal),w=[];try{h.pending.add(b),r(h),await Promise.resolve(h.effect(m,Tj({},v,{getOriginalState:y,condition:(k,_)=>S(k,_).then(Boolean),take:S,delay:ckt(b.signal),pause:nB(b.signal),extra:a,signal:b.signal,fork:wer(b.signal,w),unsubscribe:h.unsubscribe,subscribe:()=>{t.set(h.id,h)},cancelActiveListeners:()=>{h.pending.forEach((k,_,C)=>{k!==b&&(k.abort(lme),C.delete(k))})},cancel:()=>{b.abort(lme),h.pending.delete(b)},throwIfCancelled:()=>{Gk(b.signal)}})))}catch(k){k instanceof hH||Nze(i,k,{raisedBy:"effect"})}finally{await Promise.all(w),b.abort(ber),s(h),h.pending.delete(b)}},f=ker(t,n);return{middleware:h=>m=>v=>{if(!USt(v))return m(v);if(fkt.match(v))return c(v.payload);if(Oer.match(v)){f();return}if(pkt.match(v))return u(v.payload);let y=h.getState();const b=()=>{if(y===jze)throw new Error(Tp(23));return y};let S;try{if(S=m(v),t.size>0){const w=h.getState(),k=Array.from(t.values());for(const _ of k){let C=!1;try{C=_.predicate(v,w,y)}catch(E){C=!1,Nze(i,E,{raisedBy:"predicate"})}C&&d(_,v,h,b)}}}finally{y=jze}return S},startListening:c,stopListening:u,clearListeners:f}};function Tp(e){return`Minified Redux Toolkit error #${e}; visit https://redux-toolkit.js.org/Errors?code=${e} for the full message or use the non-minified dev environment for full errors. `}var Cer={layoutType:"horizontal",width:0,height:0,margin:{top:5,right:5,bottom:5,left:5},scale:1},hkt=Hu({name:"chartLayout",initialState:Cer,reducers:{setLayout(e,t){e.layoutType=t.payload},setChartSize(e,t){e.width=t.payload.width,e.height=t.payload.height},setMargin(e,t){var n,r,s,a;e.margin.top=(n=t.payload.top)!==null&&n!==void 0?n:0,e.margin.right=(r=t.payload.right)!==null&&r!==void 0?r:0,e.margin.bottom=(s=t.payload.bottom)!==null&&s!==void 0?s:0,e.margin.left=(a=t.payload.left)!==null&&a!==void 0?a:0},setScale(e,t){e.scale=t.payload}}}),{setMargin:Eer,setLayout:jer,setChartSize:Ter,setScale:Ner}=hkt.actions,Ier=hkt.reducer;function mkt(e,t,n){return Array.isArray(e)&&e&&t+n!==0?e.slice(t,n+1):e}function es(e){return Number.isFinite(e)}function gy(e){return typeof e=="number"&&e>0&&Number.isFinite(e)}function Ize(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(s){return Object.getOwnPropertyDescriptor(e,s).enumerable})),n.push.apply(n,r)}return n}function QE(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?Ize(Object(n),!0).forEach(function(r){Aer(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Ize(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}function Aer(e,t,n){return(t=Rer(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Rer(e){var t=Per(e,"string");return typeof t=="symbol"?t:t+""}function Per(e,t){if(typeof e!="object"||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t);if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}function vo(e,t,n){return Ki(e)||Ki(t)?n:cm(t)?TT(e,t,n):typeof t=="function"?t(e):n}var $er=(e,t,n)=>{if(t&&n){var{width:r,height:s}=n,{align:a,verticalAlign:i,layout:l}=t;if((l==="vertical"||l==="horizontal"&&i==="middle")&&a!=="center"&&Hn(e[a]))return QE(QE({},e),{},{[a]:e[a]+(r||0)});if((l==="horizontal"||l==="vertical"&&a==="center")&&i!=="middle"&&Hn(e[i]))return QE(QE({},e),{},{[i]:e[i]+(s||0)})}return e},Ug=(e,t)=>e==="horizontal"&&t==="xAxis"||e==="vertical"&&t==="yAxis"||e==="centric"&&t==="angleAxis"||e==="radial"&&t==="radiusAxis",gkt=(e,t,n,r)=>{if(r)return e.map(l=>l.coordinate);var s,a,i=e.map(l=>(l.coordinate===t&&(s=!0),l.coordinate===n&&(a=!0),l.coordinate));return s||i.push(t),a||i.push(n),i},vkt=(e,t,n)=>{if(!e)return null;var{duplicateDomain:r,type:s,range:a,scale:i,realScaleType:l,isCategorical:c,categoricalDomain:u,tickCount:d,ticks:f,niceTicks:p,axisType:h}=e;if(!i)return null;var m=l==="scaleBand"&&i.bandwidth?i.bandwidth()/2:2,v=s==="category"&&i.bandwidth?i.bandwidth()/m:0;if(v=h==="angleAxis"&&a&&a.length>=2?zh(a[0]-a[1])*2*v:v,f||p){var y=(f||p||[]).map((b,S)=>{var w=r?r.indexOf(b):b,k=i.map(w);return es(k)?{coordinate:k+v,value:b,offset:v,index:S}:null}).filter(rf);return y}return c&&u?u.map((b,S)=>{var w=i.map(b);return es(w)?{coordinate:w+v,value:b,index:S,offset:v}:null}).filter(rf):i.ticks&&d!=null?i.ticks(d).map((b,S)=>{var w=i.map(b);return es(w)?{coordinate:w+v,value:b,index:S,offset:v}:null}).filter(rf):i.domain().map((b,S)=>{var w=i.map(b);return es(w)?{coordinate:w+v,value:r?r[b]:b,index:S,offset:v}:null}).filter(rf)},Mer=e=>{var t,n=e.length;if(!(n<=0)){var r=(t=e[0])===null||t===void 0?void 0:t.length;if(!(r==null||r<=0))for(var s=0;s<r;++s)for(var a=0,i=0,l=0;l<n;++l){var c=e[l],u=c?.[s];if(u!=null){var d=u[1],f=u[0],p=my(d)?f:d;p>=0?(u[0]=a,a+=p,u[1]=a):(u[0]=i,i+=p,u[1]=i)}}}},Der=e=>{var t,n=e.length;if(!(n<=0)){var r=(t=e[0])===null||t===void 0?void 0:t.length;if(!(r==null||r<=0))for(var s=0;s<r;++s)for(var a=0,i=0;i<n;++i){var l=e[i],c=l?.[s];if(c!=null){var u=my(c[1])?c[0]:c[1];u>=0?(c[0]=a,a+=u,c[1]=a):(c[0]=0,c[1]=0)}}}},Ler={sign:Mer,expand:_Kn,none:UO,silhouette:CKn,wiggle:EKn,positive:Der},Fer=(e,t,n)=>{var r,s=(r=Ler[n])!==null&&r!==void 0?r:UO,a=OKn().keys(t).value((l,c)=>Number(vo(l,c,0))).order(Khe).offset(s),i=a(e);return i.forEach((l,c)=>{l.forEach((u,d)=>{var f=vo(e[d],t[c],0);Array.isArray(f)&&f.length===2&&Hn(f[0])&&Hn(f[1])&&(u[0]=f[0],u[1]=f[1])})}),i};function zer(e){return e==null?void 0:String(e)}function IT(e){var{axis:t,ticks:n,bandSize:r,entry:s,index:a,dataKey:i}=e;if(t.type==="category"){if(!t.allowDuplicatedCategory&&t.dataKey&&!Ki(s[t.dataKey])){var l=OSt(n,"value",s[t.dataKey]);if(l)return l.coordinate+r/2}return n!=null&&n[a]?n[a].coordinate+r/2:null}var c=vo(s,Ki(i)?t.dataKey:i),u=t.scale.map(c);return Hn(u)?u:null}var Ber=e=>{var t=e.flat(2).filter(Hn);return[Math.min(...t),Math.max(...t)]},Uer=e=>[e[0]===1/0?0:e[0],e[1]===-1/0?0:e[1]],qer=(e,t,n)=>{if(e!=null)return Uer(Object.keys(e).reduce((r,s)=>{var a=e[s];if(!a)return r;var{stackedData:i}=a,l=i.reduce((c,u)=>{var d=mkt(u,t,n),f=Ber(d);return!es(f[0])||!es(f[1])?c:[Math.min(c[0],f[0]),Math.max(c[1],f[1])]},[1/0,-1/0]);return[Math.min(l[0],r[0]),Math.max(l[1],r[1])]},[1/0,-1/0]))},Aze=/^dataMin[\s]*-[\s]*([0-9]+([.]{1}[0-9]+){0,1})$/,Rze=/^dataMax[\s]*\+[\s]*([0-9]+([.]{1}[0-9]+){0,1})$/,AT=(e,t,n)=>{if(e&&e.scale&&e.scale.bandwidth){var r=e.scale.bandwidth();if(!n||r>0)return r}if(e&&t&&t.length>=2){for(var s=iH(t,d=>d.coordinate),a=1/0,i=1,l=s.length;i<l;i++){var c=s[i],u=s[i-1];a=Math.min((c?.coordinate||0)-(u?.coordinate||0),a)}return a===1/0?0:a}return n?void 0:0};function Pze(e){var{tooltipEntrySettings:t,dataKey:n,payload:r,value:s,name:a}=e;return QE(QE({},t),{},{dataKey:n,payload:r,value:s,name:a})}function HN(e,t){if(e)return String(e);if(typeof t=="string")return t}var Ver=(e,t)=>{if(t==="horizontal")return e.relativeX;if(t==="vertical")return e.relativeY},Her=(e,t)=>t==="centric"?e.angle:e.radius,Qx=e=>e.layout.width,Yx=e=>e.layout.height,Wer=e=>e.layout.scale,ykt=e=>e.layout.margin,gH=at(e=>e.cartesianAxis.xAxis,e=>Object.values(e)),vH=at(e=>e.cartesianAxis.yAxis,e=>Object.values(e)),Zer="data-recharts-item-index",bkt="data-recharts-item-id",T3=60;function $ze(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(s){return Object.getOwnPropertyDescriptor(e,s).enumerable})),n.push.apply(n,r)}return n}function B6(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?$ze(Object(n),!0).forEach(function(r){Ger(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):$ze(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}function Ger(e,t,n){return(t=Qer(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Qer(e){var t=Yer(e,"string");return typeof t=="symbol"?t:t+""}function Yer(e,t){if(typeof e!="object"||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t);if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}var Xer=e=>e.brush.height;function Ker(e){var t=vH(e);return t.reduce((n,r)=>{if(r.orientation==="left"&&!r.mirror&&!r.hide){var s=typeof r.width=="number"?r.width:T3;return n+s}return n},0)}function Jer(e){var t=vH(e);return t.reduce((n,r)=>{if(r.orientation==="right"&&!r.mirror&&!r.hide){var s=typeof r.width=="number"?r.width:T3;return n+s}return n},0)}function etr(e){var t=gH(e);return t.reduce((n,r)=>r.orientation==="top"&&!r.mirror&&!r.hide?n+r.height:n,0)}function ttr(e){var t=gH(e);return t.reduce((n,r)=>r.orientation==="bottom"&&!r.mirror&&!r.hide?n+r.height:n,0)}var lu=at([Qx,Yx,ykt,Xer,Ker,Jer,etr,ttr,FSt,NJn],(e,t,n,r,s,a,i,l,c,u)=>{var d={left:(n.left||0)+s,right:(n.right||0)+a},f={top:(n.top||0)+i,bottom:(n.bottom||0)+l},p=B6(B6({},f),d),h=p.bottom;p.bottom+=r,p=$er(p,c,u);var m=e-p.left-p.right,v=t-p.top-p.bottom;return B6(B6({brushBottom:h},p),{},{width:Math.max(m,0),height:Math.max(v,0)})}),ntr=at(lu,e=>({x:e.left,y:e.top,width:e.width,height:e.height})),xkt=at(Qx,Yx,(e,t)=>({x:0,y:0,width:e,height:t})),rtr=g.createContext(null),oc=()=>g.useContext(rtr)!=null,yH=e=>e.brush,bH=at([yH,lu,ykt],(e,t,n)=>({height:e.height,x:Hn(e.x)?e.x:t.left,y:Hn(e.y)?e.y:t.top+t.height+t.brushBottom-(n?.bottom||0),width:Hn(e.width)?e.width:t.width})),ate={},ite={},ote={},Mze;function str(){return Mze||(Mze=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});function t(n,r,{signal:s,edges:a}={}){let i,l=null;const c=a!=null&&a.includes("leading"),u=a==null||a.includes("trailing"),d=()=>{l!==null&&(n.apply(i,l),i=void 0,l=null)},f=()=>{u&&d(),v()};let p=null;const h=()=>{p!=null&&clearTimeout(p),p=setTimeout(()=>{p=null,f()},r)},m=()=>{p!==null&&(clearTimeout(p),p=null)},v=()=>{m(),i=void 0,l=null},y=()=>{d()},b=function(...S){if(s?.aborted)return;i=this,l=S;const w=p==null;h(),c&&w&&d()};return b.schedule=h,b.cancel=v,b.flush=y,s?.addEventListener("abort",v,{once:!0}),b}e.debounce=t})(ote)),ote}var Dze;function atr(){return Dze||(Dze=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});const t=str();function n(r,s=0,a={}){typeof a!="object"&&(a={});const{leading:i=!1,trailing:l=!0,maxWait:c}=a,u=Array(2);i&&(u[0]="leading"),l&&(u[1]="trailing");let d,f=null;const p=t.debounce(function(...v){d=r.apply(this,v),f=null},s,{edges:u}),h=function(...v){return c!=null&&(f===null&&(f=Date.now()),Date.now()-f>=c)?(d=r.apply(this,v),f=Date.now(),p.cancel(),p.schedule(),d):(p.apply(this,v),d)},m=()=>(p.flush(),d);return h.cancel=p.cancel,h.flush=m,h}e.debounce=n})(ite)),ite}var Lze;function itr(){return Lze||(Lze=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});const t=atr();function n(r,s=0,a={}){const{leading:i=!0,trailing:l=!0}=a;return t.debounce(r,s,{leading:i,maxWait:s,trailing:l})}e.throttle=n})(ate)),ate}var lte,Fze;function otr(){return Fze||(Fze=1,lte=itr().throttle),lte}var ltr=otr();const ctr=Tc(ltr);var rB=function(t,n){for(var r=arguments.length,s=new Array(r>2?r-2:0),a=2;a<r;a++)s[a-2]=arguments[a];if(typeof console<"u"&&console.warn&&(n===void 0&&console.warn("LogUtils requires an error message argument"),!t))if(n===void 0)console.warn("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var i=0;console.warn(n.replace(/%s/g,()=>s[i++]))}},Uv={width:"100%",height:"100%",debounce:0,minWidth:0,initialDimension:{width:-1,height:-1}},wkt=(e,t,n)=>{var{width:r=Uv.width,height:s=Uv.height,aspect:a,maxHeight:i}=n,l=qO(r)?e:Number(r),c=qO(s)?t:Number(s);return a&&a>0&&(l?c=l/a:c&&(l=c*a),i&&c!=null&&c>i&&(c=i)),{calculatedWidth:l,calculatedHeight:c}},utr={width:0,height:0,overflow:"visible"},dtr={width:0,overflowX:"visible"},ftr={height:0,overflowY:"visible"},ptr={},htr=e=>{var{width:t,height:n}=e,r=qO(t),s=qO(n);return r&&s?utr:r?dtr:s?ftr:ptr};function mtr(e){var{width:t,height:n,aspect:r}=e,s=t,a=n;return s===void 0&&a===void 0?(s=Uv.width,a=Uv.height):s===void 0?s=r&&r>0?void 0:Uv.width:a===void 0&&(a=r&&r>0?void 0:Uv.height),{width:s,height:a}}function ume(){return ume=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},ume.apply(null,arguments)}function zze(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(s){return Object.getOwnPropertyDescriptor(e,s).enumerable})),n.push.apply(n,r)}return n}function Bze(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?zze(Object(n),!0).forEach(function(r){gtr(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):zze(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}function gtr(e,t,n){return(t=vtr(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function vtr(e){var t=ytr(e,"string");return typeof t=="symbol"?t:t+""}function ytr(e,t){if(typeof e!="object"||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t);if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}var Skt=g.createContext(Uv.initialDimension);function btr(e){return gy(e.width)&&gy(e.height)}function kkt(e){var{children:t,width:n,height:r}=e,s=g.useMemo(()=>({width:n,height:r}),[n,r]);return btr(s)?g.createElement(Skt.Provider,{value:s},t):null}var SSe=()=>g.useContext(Skt),xtr=g.forwardRef((e,t)=>{var{aspect:n,initialDimension:r=Uv.initialDimension,width:s,height:a,minWidth:i=Uv.minWidth,minHeight:l,maxHeight:c,children:u,debounce:d=Uv.debounce,id:f,className:p,onResize:h,style:m={}}=e,v=g.useRef(null),y=g.useRef();y.current=h,g.useImperativeHandle(t,()=>v.current);var[b,S]=g.useState({containerWidth:r.width,containerHeight:r.height}),w=g.useCallback((j,N)=>{S(I=>{var R=Math.round(j),P=Math.round(N);return I.containerWidth===R&&I.containerHeight===P?I:{containerWidth:R,containerHeight:P}})},[]);g.useEffect(()=>{if(v.current==null||typeof ResizeObserver>"u")return M_;var j=P=>{var L,M=P[0];if(M!=null){var{width:q,height:H}=M.contentRect;w(q,H),(L=y.current)===null||L===void 0||L.call(y,q,H)}};d>0&&(j=ctr(j,d,{trailing:!0,leading:!1}));var N=new ResizeObserver(j),{width:I,height:R}=v.current.getBoundingClientRect();return w(I,R),N.observe(v.current),()=>{N.disconnect()}},[w,d]);var{containerWidth:k,containerHeight:_}=b;rB(!n||n>0,"The aspect(%s) must be greater than zero.",n);var{calculatedWidth:C,calculatedHeight:E}=wkt(k,_,{width:s,height:a,aspect:n,maxHeight:c});return rB(C!=null&&C>0||E!=null&&E>0,`The width(%s) and height(%s) of chart should be greater than 0,
|
|
345
|
+
`);return t!==-1&&t!==e.length-1}else{if(Array.isArray(e))return e.some(t=>Whe(t));if(e&&typeof e=="object")return Object.values(e).some(t=>Whe(t))}return!1}function VYn({children:e}){return o.jsx("div",{className:"flex-1 p-4 overflow-y-auto",children:e})}function HYn({className:e,children:t}){return o.jsx("div",{className:K("flex items-center justify-between gap-2 border-b border-border1 mx-4 py-3",e),children:t})}function WYn({className:e,children:t}){return o.jsx("h3",{className:K("flex gap-2 text-ui-md text-neutral3 [&>b]:text-neutral2 [&>b]:font-normal",e),children:t})}function ZYn({className:e,children:t}){return o.jsx("dl",{className:K("grid grid-cols-[auto_1fr] gap-x-4 gap-y-1.5",e),children:t})}function GYn({className:e,children:t}){return o.jsx("dt",{className:K("text-ui-smd text-neutral2 shrink-0 py-0.5",e),children:t})}function QYn({className:e,children:t}){return o.jsx("dd",{className:K("text-ui-smd text-neutral3 truncate min-w-0 py-0.5",e),children:t})}function YYn({className:e,children:t}){return o.jsx("dt",{className:K("col-span-2 text-ui-sm uppercase tracking-widest text-neutral2 py-3",e),children:t})}const XYn=Object.assign(ZYn,{Key:GYn,Value:QYn,Header:YYn});function KYn({children:e}){return o.jsxs("div",{className:"flex items-center justify-center gap-2 px-4 py-6 text-ui-sm text-neutral3",children:[o.jsx(Gt,{size:"sm",variant:"pulse",className:"text-neutral3"})," ",e??"Loading..."]})}function JYn({children:e}){return o.jsx("p",{className:"px-4 py-6 text-ui-sm text-neutral2",children:e??"No data found."})}const Mi=Object.assign(LYn,{Header:HYn,Heading:WYn,CloseButton:FYn,LoadingData:KYn,NoData:JYn,Content:VYn,KeyValueList:XYn,CodeSection:qYn}),eXn=e=>{let t=e.length;for(;t>0&&e[t-1]==="/";)t--;return e.slice(0,t)};function tXn(e){const t=`${eXn(e.baseUrl)}/api/learning`,n=(a,i)=>{const l=new URL(`${t}${a}`);if(i)for(const[c,u]of Object.entries(i))u!==void 0&&l.searchParams.set(c,String(u));return l.toString()};async function r(a){const i=await fetch(a,{credentials:"include",headers:e.projectId?{"X-Mastra-Project-Id":e.projectId}:void 0});if(!i.ok)throw new Error(`Entity-Learning request failed (${i.status}): ${a}`);return await i.json()}const s=a=>encodeURIComponent(a);return{getEntities(){return r(n("/entities"))},getEntityRuns(a,i){return r(n(`/entities/${s(a)}/runs`,{signalName:i}))},getEntityRun(a,i,l){return r(n(`/entities/${s(a)}/runs/${s(i)}`,{signalName:l}))},getEntityLearning(a,i,l){return r(n(`/entities/${s(a)}/learning`,{signalName:i,runId:l}))},getEntityTopics(a,i,l){return r(n(`/entities/${s(a)}/topics`,{signalName:i,runId:l}))},getEntityTopic(a,i,l,c){return r(n(`/entities/${s(a)}/topics/${s(i)}`,{signalName:l,runId:c}))},getEntityTopicExamples(a,i,l){return r(n(`/entities/${s(a)}/topics/${s(i)}/examples`,{signalName:l.signalName,runId:l.runId,limit:l.limit}))},getEntityPoints(a,i){return r(n(`/entities/${s(a)}/points`,{signalName:i.signalName,runId:i.runId,includeOutliers:i.includeOutliers,limit:i.limit}))},getEntityOutliers(a,i,l){return r(n(`/entities/${s(a)}/outliers`,{signalName:i,runId:l}))},getEntityOutlierExamples(a,i){return r(n(`/entities/${s(a)}/outliers/examples`,{signalName:i.signalName,runId:i.runId,limit:i.limit}))}}}function nXn(e){try{return new URL(e).origin}catch{return e}}function GV(){const e=typeof window>"u"?void 0:window,t=e?.MASTRA_PLATFORM_OBSERVABILITY_ENDPOINT||void 0,n=t?nXn(t):void 0,r=e?.MASTRA_ORGANIZATION_ID||void 0,s=e?.MASTRA_PLATFORM_PROJECT_ID||void 0,a=g.useMemo(()=>n?tXn({baseUrl:n,projectId:s}):null,[n,s]);return{baseUrl:n,organizationId:r,projectId:s,isConfigured:!!n,service:a}}const QV="entity-learning";function B1t(){const{service:e,isConfigured:t}=GV();return wt({queryKey:[QV,"entities"],queryFn:t&&e?()=>e.getEntities():jy,select:n=>n.entities,retry:!1})}function U1t(e,t,n){const{service:r}=GV();return wt({queryKey:[QV,"topics",e,t,"latest"],queryFn:r&&e&&t?()=>r.getEntityTopics(e,t,n):jy,retry:!1})}function rXn(e,t,n){const{service:r}=GV();return wt({queryKey:[QV,"topic-examples",e,t,n?.signalName,n?.runId,n?.limit??null],queryFn:r&&e&&t&&n?.signalName&&n?.runId?()=>r.getEntityTopicExamples(e,t,n):jy,retry:!1})}function sXn(e,t){const{service:n}=GV();return wt({queryKey:[QV,"points",e,t?.signalName,t?.runId,t?.includeOutliers??null,t?.limit??null],queryFn:n&&e&&t?.signalName&&t?.runId?()=>n.getEntityPoints(e,t):jy,retry:!1})}const aXn=[{id:"sentiment",name:"Sentiment",description:"Conversation tone and confidence shifts that affect user outcomes."},{id:"behavior",name:"Behavior",description:"Recurring interaction patterns and behaviors observed across runs."},{id:"goal",name:"Goal",description:"Inferred user goals and intents driving each interaction."},{id:"outcome",name:"Outcome",description:"Resolution outcomes and whether the user objective was met."},{id:"issue",name:"Issue",description:"Recurring issue families found across traces."},{id:"severity",name:"Severity",description:"Risk and urgency bands inferred from trace paths and intervention needs."},{id:"tasks",name:"Tasks",description:"Operational work patterns inferred from agent traces and user requests."}],iXn=e=>e.replace(/[-_]/g," ").replace(/\b\w/g,t=>t.toUpperCase());function YV(e){return aXn.find(t=>t.id===e)??{id:e,name:iXn(e),description:""}}const oXn="agent";function d8e({entities:e,selected:t,onChange:n}){const r=g.useMemo(()=>e.filter(a=>a.entityType===oXn),[e]),s=a=>{const i=r.find(l=>l.entityId===a);i&&n({entityType:i.entityType,entityId:i.entityId})};return o.jsx("div",{className:"flex flex-wrap items-center gap-3",role:"search","aria-label":"Filter signals by agent",children:o.jsxs("label",{className:"flex items-center gap-2",children:[o.jsx("span",{className:"whitespace-nowrap font-mono text-xs uppercase text-neutral3",children:"Agent"}),o.jsxs(da,{value:t?.entityId??"",onValueChange:s,disabled:r.length===0,children:[o.jsx(pa,{size:"sm",variant:"outline",className:"min-w-64","aria-label":"Agent",children:o.jsx(fa,{placeholder:"Select an agent"})}),o.jsx(ha,{children:r.map(a=>o.jsx(Lr,{value:a.entityId,children:a.entityId},a.entityId))})]})]})})}function lXn(e){let t=0;for(let r=0;r<e.length;r++)t=e.charCodeAt(r)+((t<<5)-t),t=t&t;return`hsl(${Math.abs(t*137.508)%360}, 70%, 55%)`}function cXn({topic:e,onSelect:t}){const n=Math.round(e.coverage*100),r=e.itemCount===1?"item":"items",s=lXn(e.topicId),a={"--cluster-color":s};return o.jsx("article",{role:"button",tabIndex:0,onClick:()=>t(e.topicId),onKeyDown:i=>{(i.key==="Enter"||i.key===" ")&&(i.preventDefault(),t(e.topicId))},className:"group cursor-pointer rounded-2xl border border-border1/70 bg-surface2 p-5 shadow-sm transition-colors hover:border-[var(--cluster-color)] focus-visible:border-[var(--cluster-color)] focus-visible:outline-none",style:a,children:o.jsxs("div",{className:"flex h-full min-w-0 flex-col",children:[o.jsxs("div",{className:"flex min-w-0 items-start gap-2",children:[o.jsx("span",{className:"mt-2 h-2.5 w-2.5 shrink-0 rounded-full",style:{backgroundColor:s}}),o.jsxs("div",{children:[o.jsx("h3",{className:"text-md font-semibold text-neutral6",children:e.name}),o.jsx("p",{className:"line-clamp-2 text-sm text-neutral3",children:e.description})]})]}),o.jsxs("div",{className:"space-y-1 pt-4 pl-4",children:[o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx("p",{className:"font-mono text-xs uppercase text-neutral3",children:"Coverage"}),o.jsxs("p",{className:"font-mono text-xs text-neutral3",children:[e.itemCount," ",r]})]}),o.jsxs("div",{className:"grid grid-cols-[minmax(0,1fr)_4rem] items-center gap-4",children:[o.jsx("div",{className:"h-3 overflow-hidden rounded-full bg-surface4",role:"progressbar","aria-label":`${e.name} coverage`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":n,children:o.jsx("div",{className:"h-full rounded-full",style:{width:`${n}%`,backgroundColor:s}})}),o.jsxs("p",{className:"text-right text-ui-md font-semibold text-neutral6",children:[n,"%"]})]})]})]})})}function uXn(){return o.jsx("article",{className:"rounded-2xl border border-border1/70 bg-surface2 p-5 shadow-sm","aria-hidden":"true",children:o.jsxs("div",{className:"flex h-full min-w-0 flex-col",children:[o.jsxs("div",{className:"flex min-w-0 items-start gap-2",children:[o.jsx(bt,{className:"mt-2 h-2.5 w-2.5 shrink-0 rounded-full"}),o.jsxs("div",{className:"min-w-0 flex-1 space-y-2",children:[o.jsx(bt,{className:"h-4 w-1/2"}),o.jsx(bt,{className:"h-3 w-full"})]})]}),o.jsxs("div",{className:"space-y-2 pt-4 pl-4",children:[o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx(bt,{className:"h-3 w-20"}),o.jsx(bt,{className:"h-3 w-12"})]}),o.jsx(bt,{className:"h-3 w-full rounded-full"})]})]})})}function dXn(){return o.jsx("div",{className:"grid gap-6 md:grid-cols-2","aria-label":"Loading clusters","aria-busy":"true",children:Array.from({length:4}).map((e,t)=>o.jsx(uXn,{},t))})}function fXn({entity:e,catalog:t,signalName:n,onSeeDetails:r,onSelectCluster:s}){const{data:a,isLoading:i,isError:l}=U1t(e.entityId,n),c=a?.topics??[];return o.jsxs("section",{className:"space-y-4",children:[o.jsxs("header",{className:"flex items-start justify-between gap-6 px-1",children:[o.jsxs("div",{className:"min-w-0",children:[o.jsxs("div",{className:"flex items-center gap-3",children:[o.jsx("h2",{className:"text-ui-2xl font-semibold text-neutral6",children:t.name}),i?o.jsx(bt,{className:"h-badge-default w-20 rounded-full","aria-hidden":"true"}):l?null:o.jsxs(dn,{variant:"default",children:[c.length," ",c.length===1?"cluster":"clusters"]})]}),t.description?o.jsx("p",{className:"text-ui-lg text-neutral3",children:t.description}):null]}),o.jsxs(de,{type:"button",variant:"outline",size:"lg",className:"shrink-0 gap-2 rounded-xl px-5",onClick:()=>r(n),children:["See details",o.jsx(akn,{className:"h-4 w-4","aria-hidden":"true"})]})]}),i?o.jsx(dXn,{}):l?o.jsx("p",{className:"px-1 text-ui-md text-accent2",children:"Failed to load clusters for this signal."}):c.length===0?o.jsx("p",{className:"px-1 text-ui-md text-neutral3",children:"No clusters found for this signal yet."}):o.jsx("div",{className:"grid gap-6 md:grid-cols-2",children:c.map(u=>o.jsx(cXn,{topic:u,onSelect:d=>s(n,d)},u.topicId))})]})}function pXn({selectedEntity:e,onEntityChange:t,onSignalSelect:n}){const{data:r=[],isLoading:s,isError:a}=B1t(),i=e?r.find(c=>c.entityId===e.entityId):void 0,l=!!i;return o.jsx(F1t,{sidebar:null,contentPadding:!1,children:o.jsxs("div",{className:"flex h-full min-w-0 flex-col","aria-label":"Signals",children:[l&&o.jsx("div",{className:"border-b border-border1/70 px-6 py-4",children:o.jsx(d8e,{entities:r,selected:e,onChange:t})}),o.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto p-6",children:s?o.jsx("div",{className:"flex h-full items-center justify-center",children:o.jsx(Cr,{iconSlot:o.jsx(Gt,{}),titleSlot:"Loading entities…"})}):a?o.jsx("div",{className:"flex h-full items-center justify-center",children:o.jsx(Cr,{iconSlot:o.jsx(Yq,{}),titleSlot:"Failed to load entities",descriptionSlot:"Failed to load entities from the observability endpoint."})}):r.length===0?o.jsx("div",{className:"flex h-full items-center justify-center",children:o.jsx(Cr,{iconSlot:o.jsx(I3e,{}),titleSlot:"No entities available",descriptionSlot:"No entities are available on the server yet."})}):i?i.availableSignals.length===0?o.jsx("div",{className:"flex h-full items-center justify-center",children:o.jsx(Cr,{iconSlot:o.jsx(I3e,{}),titleSlot:"No signals yet",descriptionSlot:"This entity has no signals yet."})}):o.jsx("div",{className:"mx-auto flex max-w-6xl flex-col gap-12",children:i.availableSignals.map(c=>o.jsx(fXn,{entity:i,signalName:c,catalog:YV(c),onSeeDetails:n,onSelectCluster:n},c))}):o.jsx("div",{className:"flex h-full items-center justify-center",children:o.jsx(Cr,{iconSlot:o.jsx(BOn,{}),titleSlot:"No entity selected",descriptionSlot:"Select an entity to inspect its signals and clusters.",actionSlot:o.jsx(d8e,{entities:r,selected:e,onChange:t})})})})]})})}function hXn(){const e=bs(),[t,n]=ga(),r=t.get("entityId"),s=g.useMemo(()=>r?{entityType:"agent",entityId:r}:null,[r]),a=g.useCallback(l=>{n(c=>{const u=new URLSearchParams(c);return l?u.set("entityId",l.entityId):u.delete("entityId"),u},{replace:!0})},[n]),i=g.useCallback((l,c)=>{const u=new URLSearchParams;s&&u.set("entityId",s.entityId),c&&u.set("topicId",c);const d=u.toString();e(`/signals/${l}${d?`?${d}`:""}`,{viewTransition:!0})},[e,s]);return o.jsx(pXn,{selectedEntity:s,onEntityChange:a,onSignalSelect:i})}const G1e=["data-list-row col-span-full relative mt-[3px] mb-1",'after:absolute after:inset-x-[-0.25rem] after:bottom-[-0.25rem] after:h-px after:bg-border1 after:content-[""] after:pointer-events-none',"[&:has(+.data-list-subheader)]:after:hidden [&:not(:has(~.data-list-row))]:after:hidden","transition-colors duration-200 rounded-lg"],Q1e=["grid grid-cols-subgrid gap-8 px-5 outline-none cursor-pointer","hover:bg-surface4 focus-visible:bg-surface4 focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-accent1","transition-colors duration-200 rounded-lg"],q1t=["mx-1",...Q1e,...G1e],mXn=["mx-1 grid grid-cols-subgrid gap-8 px-5",...G1e],V1t=["data-list-sticky-start sticky left-0 z-10 isolate self-stretch overflow-visible",'after:absolute after:-right-4 after:top-1/2 after:-translate-y-1/2 after:h-4 after:w-px after:bg-border2 after:content-[""] after:pointer-events-none'],Y1e=al("",{variants:{variant:{default:"",error:"bg-notice-destructive/10! hover:bg-notice-destructive/15!"}},defaultVariants:{variant:"default"}});function ko({children:e,className:t,height:n="default",as:r,sticky:s,...a}){const i=r||"span";return o.jsx(i,{className:K('relative grid min-w-0 max-w-full items-center overflow-hidden text-ui-md whitespace-nowrap text-neutral3 empty:before:content-["—"] empty:before:text-neutral2',n==="compact"?"py-1.5":"py-2.5",s==="start"&&V1t,t),...a,children:e})}const XV='block min-w-0 max-w-full truncate empty:before:content-["—"] empty:before:text-neutral2 [&>*]:min-w-0 [&>*]:max-w-full [&>*]:overflow-hidden [&>*]:text-ellipsis [&>*]:whitespace-nowrap',gXn="min-w-0 flex-1 truncate";function vXn({children:e}){return o.jsx("span",{className:gXn,children:e})}function yXn({children:e}){return g.Children.map(e,t=>typeof t=="string"||typeof t=="number"?o.jsx(vXn,{children:t}):t)}function KV({children:e}){return g.Children.map(e,t=>!g.isValidElement(t)||typeof t.type!="string"?t:g.cloneElement(t,{className:K("min-w-0 max-w-full overflow-hidden",t.props.className),children:o.jsx(yXn,{children:t.props.children})}))}function bXn({children:e,className:t,...n}){return o.jsx(ko,{className:t,...n,children:o.jsx("span",{className:XV,children:o.jsx(KV,{children:e})})})}function xXn({children:e,className:t}){return o.jsx(ko,{className:K("text-left text-neutral4",t),children:o.jsx("span",{className:XV,children:o.jsx(KV,{children:e})})})}function wXn({children:e,className:t}){return o.jsx(ko,{className:K("text-neutral2",t),children:o.jsx("span",{className:XV,children:o.jsx(KV,{children:e})})})}function SXn({children:e,className:t,...n}){return o.jsx(ko,{sticky:"start",className:K("data-list-row-header -ml-5 -mr-4 w-auto max-w-none rounded-l-md pl-5 pr-4 text-left text-ui-sm font-semibold tracking-tight text-neutral2",t),...n,children:o.jsx("span",{className:K(XV,"relative z-10 w-full"),children:o.jsx(KV,{children:e})})})}function kXn({children:e,className:t,highlight:n,height:r="compact",...s}){return o.jsx(ko,{height:r,className:K("justify-items-end text-right text-ui-sm tabular-nums",n?"text-neutral4 font-semibold":"text-neutral3",t),...s,children:e})}function OXn(e){return e?e.length>8?e.slice(0,8):e:""}function H1t({id:e}){return o.jsx(ko,{height:"compact",className:"text-ui-smd font-mono text-neutral3",children:OXn(e)})}function _Xn({checked:e,onToggle:t,...n}){return o.jsx(ko,{as:"label",height:"compact",className:"h-8 w-8 self-center cursor-pointer justify-items-center overflow-visible px-0 py-0!",onClick:r=>r.stopPropagation(),children:o.jsx(Mo,{checked:e,onCheckedChange:()=>{},onClick:r=>{r.stopPropagation(),t(r.shiftKey)},"aria-label":n["aria-label"]})})}function X1e({children:e,className:t,height:n="compact"}){return o.jsx(ko,{height:n,children:o.jsx("span",{className:K('block min-w-0 max-w-full text-ui-smd font-mono text-neutral3 truncate empty:before:content-["—"]',t),children:e})})}function W1t(e){const t=e instanceof Date?e:new Date(e);return isNaN(t.getTime())?null:t}function K1e({timestamp:e}){const t=W1t(e);return o.jsx(ko,{height:"compact",className:"text-ui-smd text-neutral2",children:t?MN(t)?"Today":er(t,"MMM dd"):null})}function J1e({timestamp:e}){const t=W1t(e);return o.jsx(ko,{height:"compact",className:"text-ui-smd font-mono text-neutral3 flex",children:t?o.jsxs(o.Fragment,{children:[er(t,"HH:mm:ss"),o.jsxs("span",{className:"text-neutral2",children:[".",String(t.getMilliseconds()).padStart(3,"0")]})]}):null})}function JV({isLoading:e,setEndOfListElement:t,hasMore:n,loadingText:r="Loading more data..."}){return t?o.jsx("div",{ref:t,className:K("col-span-full text-ui-md text-neutral3 opacity-50 flex justify-center min-h-1",{"py-4":e,"py-0":!n}),children:e&&r}):null}function eH({message:e="Nothing matches your search",className:t,...n}){return o.jsx("div",{className:K("col-span-full flex flex-col items-center justify-center gap-2 py-12 text-neutral3",t),...n,children:o.jsx("p",{className:"text-ui-md",children:e})})}const CXn={tinted:{background:"color-mix(in oklch, var(--surface1), var(--neutral6) 10%)",hoverBackground:"color-mix(in oklch, var(--surface1), var(--neutral6) 14%)"},surface:{background:"var(--surface2)",hoverBackground:"color-mix(in oklch, var(--surface2), var(--neutral6) 10%)"},transparent:{background:"transparent",hoverBackground:"transparent"}};function EXn(e){return e===void 0?{top:!1}:typeof e=="object"?{top:!1,...e}:e}const f8e=["gap-y-px","[&_.data-list-top]:mx-0 [&_.data-list-top]:bg-[var(--data-list-sticky-header-background)] [&_.data-list-top]:after:hidden","[&_.data-list-top]:rounded-t-xl [&_.data-list-top]:rounded-b-md","[&_.data-list-top>*:not(:first-child)]:relative [&_.data-list-top>*:not(:first-child)]:overflow-visible",'[&_.data-list-top>*:not(:first-child)]:before:absolute [&_.data-list-top>*:not(:first-child)]:before:-left-4 [&_.data-list-top>*:not(:first-child)]:before:top-1/2 [&_.data-list-top>*:not(:first-child)]:before:-translate-y-1/2 [&_.data-list-top>*:not(:first-child)]:before:h-4 [&_.data-list-top>*:not(:first-child)]:before:w-px [&_.data-list-top>*:not(:first-child)]:before:bg-border2 [&_.data-list-top>*:not(:first-child)]:before:content-[""]',"[&_.data-list-row]:mx-0 [&_.data-list-row]:my-0 [&_.data-list-row]:rounded-md","[&_.data-list-row]:hover:bg-surface-overlay-strong!","[&_.data-list-row]:focus-visible:bg-surface-overlay-strong!","[&_.data-list-row>.data-list-sticky-start]:bg-[var(--data-list-sticky-header-background)]","[&_.data-list-row>.data-list-sticky-start]:after:right-0","[&_.data-list-row:hover>.data-list-sticky-start]:bg-[var(--data-list-sticky-header-hover-background)]","[&_.data-list-row:focus-visible>.data-list-sticky-start]:bg-[var(--data-list-sticky-header-hover-background)]","[&_.data-list-row:focus-within>.data-list-sticky-start]:bg-[var(--data-list-sticky-header-hover-background)]","[&_.data-list-top>.data-list-sticky-start]:after:right-0","[&_.data-list-top>.data-list-sticky-start+*]:before:hidden"],jXn=al(K("grid w-max min-w-full max-w-none content-start"),{variants:{variant:{striped:K(...f8e,"[&_.data-list-row]:after:hidden","[&_.data-list-row]:even:bg-surface-overlay-soft"),lined:K(...f8e,'[&_.data-list-row]:after:absolute [&_.data-list-row]:after:h-px [&_.data-list-row]:after:content-[""] [&_.data-list-row]:after:pointer-events-none',"[&_.data-list-row]:after:inset-x-2 [&_.data-list-row]:after:-bottom-px [&_.data-list-row]:after:bg-neutral6/10")}},defaultVariants:{variant:"lined"}});function k3({children:e,columns:t,className:n,variant:r="lined",stickyHeaderBackground:s="tinted",mask:a,scrollRef:i,...l}){const c=CXn[s],u={"--data-list-sticky-header-background":c.background,"--data-list-sticky-header-hover-background":c.hoverBackground,gridTemplateColumns:t},d=o.jsx("div",{className:jXn({variant:r}),style:u,children:e});return o.jsx(Yr,{...l,orientation:"both",mask:EXn(a),viewportRef:i,viewPortClassName:"max-h-[inherit]",className:K("h-full w-full rounded-t-xl",n),children:d})}const Z1t=g.createContext(!1);function eSe(){return g.useContext(Z1t)}const O3=g.forwardRef(({children:e,className:t,type:n="button",flushLeft:r,flushRight:s,colStart:a,colEnd:i,featured:l,variant:c,style:u,...d},f)=>{const p=eSe(),m=a!==void 0||i!==void 0?{...u,gridColumn:`${a??1} / ${i??-1}`}:u;return o.jsx("button",{ref:f,type:n,className:K(...p?Q1e:q1t,"text-left",!p&&r&&"ml-0!",!p&&s&&"mr-0!",l&&"bg-surface4!",Y1e({variant:c}),t),style:m,...d,children:e})});O3.displayName="DataListRowButton";function tSe({height:e}){return e<=0?null:o.jsx("div",{className:"col-span-full",style:{height:e}})}function tH({children:e,className:t,hasLeadingCell:n,...r}){return o.jsx("div",{className:K('data-list-top mx-1 grid grid-cols-subgrid gap-8 col-span-full relative px-5 bg-surface2 sticky top-0 z-20 after:absolute after:inset-x-[-0.25rem] after:bottom-0 after:h-px after:bg-border1 after:content-[""] after:pointer-events-none',n&&"gap-0 pl-0!",t),...r,children:e})}const $_=g.forwardRef(({children:e,className:t,as:n,sticky:r,...s},a)=>{const i=n||"span",l=typeof e=="string"||typeof e=="number";return o.jsx(i,{ref:a,className:K("h-8 min-w-0 max-w-full overflow-hidden py-1 flex items-center whitespace-nowrap text-neutral2 font-semibold tracking-tight text-ui-sm",r==="start"&&V1t,r==="start"&&"-ml-5 -mr-4 w-auto max-w-none rounded-tl-xl rounded-bl-md pl-5 pr-4",r==="start"&&"z-20 bg-[var(--data-list-sticky-header-background)]",t),...s,children:l?o.jsx("span",{className:"min-w-0 truncate",children:e}):e})});function nH({children:e,tooltip:t,className:n}){return o.jsxs(Wn,{children:[o.jsx(zn,{children:o.jsx($_,{className:n,children:e})}),o.jsx(Bn,{children:t})]})}const TXn={sm:{show:"hidden sm:inline-flex",hide:"inline-flex sm:hidden"},md:{show:"hidden md:inline-flex",hide:"inline-flex md:hidden"},lg:{show:"hidden lg:inline-flex",hide:"inline-flex lg:hidden"},xl:{show:"hidden xl:inline-flex",hide:"inline-flex xl:hidden"},"2xl":{show:"hidden 2xl:inline-flex",hide:"inline-flex 2xl:hidden"}};function G1t({long:e,short:t,tooltip:n,breakpoint:r="2xl",className:s}){const a=n??(typeof e=="string"?e:void 0),i=TXn[r],l=o.jsxs(o.Fragment,{children:[o.jsx("span",{className:K("items-center gap-1",i.show),children:e}),o.jsx("span",{className:K("items-center gap-1",i.hide),children:t})]});return a?o.jsx(nH,{tooltip:a,className:K("flex [&_svg]:w-[1.3em] [&_svg]:h-[1.3em]",s),children:l}):o.jsx($_,{className:K("flex [&_svg]:w-[1.3em] [&_svg]:h-[1.3em]",s),children:l})}function NXn({checked:e,onToggle:t,...n}){return o.jsx($_,{as:"label",className:"w-8 cursor-pointer justify-center overflow-visible px-0 py-0!",onClick:r=>r.stopPropagation(),children:o.jsx(Mo,{checked:e,onCheckedChange:()=>t(),"aria-label":n["aria-label"]})})}function Q1t({children:e,to:t,className:n,style:r,LinkComponent:s="a",flushLeft:a,flushRight:i,colStart:l,colEnd:c,featured:u,variant:d}){const f=eSe(),h=l!==void 0||c!==void 0?{...r,gridColumn:`${l??1} / ${c??-1}`}:r;return o.jsx(s,{href:t,className:K(...f?Q1e:q1t,!f&&a&&"ml-0!",!f&&i&&"mr-0!",u&&"bg-surface4!",Y1e({variant:d}),n),style:h,children:e})}const nSe=g.forwardRef(({children:e,className:t,...n},r)=>o.jsx(Z1t.Provider,{value:!0,children:o.jsx("div",{ref:r,className:K("grid grid-cols-subgrid gap-0 mx-1",...G1e,t),...n,children:e})}));nSe.displayName="DataListRowWrapper";const rSe=g.forwardRef(({children:e,className:t,...n},r)=>o.jsx("div",{ref:r,className:K("data-list-subheader relative isolate col-span-full px-4 py-3 border-none text-ui-md text-neutral4 font-medium mx-1","before:absolute before:inset-x-0 before:inset-y-1 before:bg-surface4 before:rounded-md before:-z-1",t),...n,children:e}));rSe.displayName="DataListSubheader";function Y1t({children:e,className:t}){return o.jsx("span",{className:K("text-ui-sm text-neutral2 font-normal",t),children:e})}function IXn({currentPage:e,hasMore:t,onNextPage:n,onPrevPage:r}){const s=typeof e=="number"&&e>0||t;return o.jsxs("div",{className:"col-span-full flex py-4 items-center justify-center text-neutral3 text-ui-md gap-8",children:[o.jsxs("span",{children:["Page ",o.jsx("b",{children:e?e+1:"1"})]}),s&&o.jsxs("div",{className:"flex gap-4",children:[typeof e=="number"&&e>0&&o.jsxs(de,{type:"button",variant:"outline",size:"sm",onClick:r,children:[o.jsx(Zq,{}),"Previous"]}),t&&o.jsxs(de,{type:"button",variant:"outline",size:"sm",onClick:n,children:["Next",o.jsx($z,{})]})]})]})}const X1t=g.forwardRef(({children:e,className:t,flushLeft:n,flushRight:r,colStart:s,colEnd:a,featured:i,variant:l,style:c,...u},d)=>{const f=eSe(),h=s!==void 0||a!==void 0?{...c,gridColumn:`${s??1} / ${a??-1}`}:c;return o.jsx("div",{ref:d,className:K(f?"grid grid-cols-subgrid gap-8 px-5 transition-colors duration-200 rounded-lg":mXn,!f&&n&&"ml-0!",!f&&r&&"mr-0!",i&&"bg-surface4!",Y1e({variant:l}),t),style:h,...u,children:e})});X1t.displayName="DataListRowStatic";const K1t=g.forwardRef(({children:e,className:t,flushLeft:n,colStart:r,style:s,...a},i)=>o.jsx("div",{ref:i,className:K("grid grid-cols-subgrid gap-8 px-5 pointer-events-none [&>*]:pointer-events-auto",!r&&"col-span-full",n&&"pl-0!",t),style:r?{...s,gridColumn:`${r} / -1`}:s,...a,children:e}));K1t.displayName="DataListTopCells";const me=Object.assign(k3,{Top:tH,TopCells:K1t,TopCell:$_,TopCellWithTooltip:nH,TopCellSmart:G1t,RowWrapper:nSe,RowButton:O3,RowLink:Q1t,RowStatic:X1t,Cell:ko,TextCell:bXn,NameCell:xXn,DescriptionCell:wXn,IdCell:H1t,RowHeaderCell:SXn,NumberCell:kXn,MonoCell:X1e,DateCell:K1e,TimeCell:J1e,SelectCell:_Xn,TopSelectCell:NXn,NoMatch:eH,Subheader:rSe,SubHeading:Y1t,Spacer:tSe,NextPageLoading:JV,Pagination:IXn}),AXn=K("group/input-group relative flex w-full flex-1 items-center","border border-border1 text-neutral6",ms.all,"has-[:disabled]:opacity-50 has-[:disabled]:cursor-not-allowed","has-[[aria-invalid=true]]:border-error","has-[>[data-align=block-start]]:flex-col has-[>[data-align=block-start]]:h-auto","has-[>[data-align=block-end]]:flex-col has-[>[data-align=block-end]]:h-auto","has-[textarea]:h-auto","has-[>[data-align=inline-start]]:[&>[data-slot=input-group-control]]:pl-0","has-[>[data-align=inline-end]]:[&>[data-slot=input-group-control]]:pr-0","has-[>[data-align=block-start]]:[&>[data-slot=input-group-control]]:flex-none has-[>[data-align=block-start]]:[&>[data-slot=input-group-control]]:w-full","has-[>[data-align=block-end]]:[&>[data-slot=input-group-control]]:flex-none has-[>[data-align=block-end]]:[&>[data-slot=input-group-control]]:w-full"),J1t=K("has-[>[data-align=block-start]]:rounded-xl","has-[>[data-align=block-end]]:rounded-xl","has-[textarea]:rounded-xl"),p8e=K("bg-surface-overlay-soft rounded-full","hover:bg-surface-overlay-strong",Aft,"outline-hidden focus-within:outline-hidden focus-within:bg-surface-overlay-strong",Nft,J1t),RXn=al(AXn,{variants:{variant:{default:p8e,filled:p8e,outline:K("bg-transparent rounded-full",Aft,"outline-hidden focus-within:outline-hidden",Nft,J1t)}},defaultVariants:{variant:"default"}}),Qc=g.forwardRef(({className:e,size:t="md",variant:n,...r},s)=>o.jsx("div",{ref:s,role:"group","data-slot":"input-group","data-size":t,className:K(RXn({variant:n}),e2[t],e),...r}));Qc.displayName="InputGroup";const PXn=al(K("flex items-center justify-center gap-2 text-neutral3 select-none","group-has-[:disabled]/input-group:opacity-50","[&>svg:not([class*='size-'])]:size-4"),{variants:{align:{"inline-start":"order-first pl-3 pr-1 has-[>button]:pl-1","inline-end":"order-last pr-3 pl-1 has-[>button]:pr-1","block-start":"order-first w-full justify-start px-3 pt-2 pb-1 border-b border-border1","block-end":"order-last w-full justify-start px-3 pb-2 pt-1 border-t border-border1"}},defaultVariants:{align:"inline-start"}}),yc=g.forwardRef(({className:e,align:t="inline-start",onClick:n,...r},s)=>o.jsx("div",{ref:s,role:"group","data-slot":"input-group-addon","data-align":t,className:K(PXn({align:t}),e),onClick:a=>{a.target.closest('button, input, textarea, [role="button"]')||a.currentTarget.parentElement?.querySelector("[data-slot=input-group-control]")?.focus(),n?.(a)},...r}));yc.displayName="InputGroupAddon";const $Xn=K("group-data-[size=xs]/input-group:h-form-xs","group-data-[size=sm]/input-group:h-form-sm","group-data-[size=md]/input-group:h-form-md","group-data-[size=default]/input-group:h-form-default","group-data-[size=lg]/input-group:h-form-lg"),eSt=K("group-data-[size=xs]/input-group:text-ui-xs","group-data-[size=sm]/input-group:text-ui-sm","group-data-[size=md]/input-group:text-ui-md","group-data-[size=default]/input-group:text-ui-md","group-data-[size=lg]/input-group:text-ui-lg"),Yc=g.forwardRef(({className:e,testId:t,error:n,type:r="text",...s},a)=>o.jsx("input",{ref:a,type:r,"data-slot":"input-group-control","data-testid":t,"aria-invalid":n,className:K("flex-1 min-w-0 bg-transparent text-neutral6 px-3 outline-hidden",$Xn,eSt,"placeholder:text-neutral2 placeholder:transition-opacity placeholder:duration-normal","focus:placeholder:opacity-70","disabled:cursor-not-allowed","[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-outer-spin-button]:m-0","[&::-webkit-inner-spin-button]:appearance-none [&::-webkit-inner-spin-button]:m-0","[&[type=number]]:[appearance:textfield]","[&::-webkit-search-cancel-button]:appearance-none",e),...s}));Yc.displayName="InputGroupInput";const MXn=g.forwardRef(({className:e,testId:t,error:n,...r},s)=>o.jsx("textarea",{ref:s,"data-slot":"input-group-control","data-testid":t,"aria-invalid":n,className:K("flex-1 min-w-0 min-h-[60px] resize-y bg-transparent text-neutral6 px-3 py-2 outline-hidden",eSt,"placeholder:text-neutral2 placeholder:transition-opacity placeholder:duration-normal","focus:placeholder:opacity-70","disabled:cursor-not-allowed",e),...r}));MXn.displayName="InputGroupTextarea";const DXn=g.forwardRef(({className:e,...t},n)=>o.jsx("span",{ref:n,className:K("flex items-center gap-2 text-ui-sm text-neutral3 [&_svg]:pointer-events-none","[&_svg:not([class*='size-'])]:size-4",e),...t}));DXn.displayName="InputGroupText";const tSt=g.forwardRef(({size:e="icon-sm",variant:t="ghost",type:n="button",...r},s)=>o.jsx(de,{ref:s,type:n,size:e,variant:t,...r}));tSt.displayName="InputGroupButton";function nSt(e){var t,n,r="";if(typeof e=="string"||typeof e=="number")r+=e;else if(typeof e=="object")if(Array.isArray(e)){var s=e.length;for(t=0;t<s;t++)e[t]&&(n=nSt(e[t]))&&(r&&(r+=" "),r+=n)}else for(n in e)e[n]&&(r&&(r+=" "),r+=n);return r}function Ca(){for(var e,t,n=0,r="",s=arguments.length;n<s;n++)(e=arguments[n])&&(t=nSt(e))&&(r&&(r+=" "),r+=t);return r}var LXn=["dangerouslySetInnerHTML","onCopy","onCopyCapture","onCut","onCutCapture","onPaste","onPasteCapture","onCompositionEnd","onCompositionEndCapture","onCompositionStart","onCompositionStartCapture","onCompositionUpdate","onCompositionUpdateCapture","onFocus","onFocusCapture","onBlur","onBlurCapture","onChange","onChangeCapture","onBeforeInput","onBeforeInputCapture","onInput","onInputCapture","onReset","onResetCapture","onSubmit","onSubmitCapture","onInvalid","onInvalidCapture","onLoad","onLoadCapture","onError","onErrorCapture","onKeyDown","onKeyDownCapture","onKeyPress","onKeyPressCapture","onKeyUp","onKeyUpCapture","onAbort","onAbortCapture","onCanPlay","onCanPlayCapture","onCanPlayThrough","onCanPlayThroughCapture","onDurationChange","onDurationChangeCapture","onEmptied","onEmptiedCapture","onEncrypted","onEncryptedCapture","onEnded","onEndedCapture","onLoadedData","onLoadedDataCapture","onLoadedMetadata","onLoadedMetadataCapture","onLoadStart","onLoadStartCapture","onPause","onPauseCapture","onPlay","onPlayCapture","onPlaying","onPlayingCapture","onProgress","onProgressCapture","onRateChange","onRateChangeCapture","onSeeked","onSeekedCapture","onSeeking","onSeekingCapture","onStalled","onStalledCapture","onSuspend","onSuspendCapture","onTimeUpdate","onTimeUpdateCapture","onVolumeChange","onVolumeChangeCapture","onWaiting","onWaitingCapture","onAuxClick","onAuxClickCapture","onClick","onClickCapture","onContextMenu","onContextMenuCapture","onDoubleClick","onDoubleClickCapture","onDrag","onDragCapture","onDragEnd","onDragEndCapture","onDragEnter","onDragEnterCapture","onDragExit","onDragExitCapture","onDragLeave","onDragLeaveCapture","onDragOver","onDragOverCapture","onDragStart","onDragStartCapture","onDrop","onDropCapture","onMouseDown","onMouseDownCapture","onMouseEnter","onMouseLeave","onMouseMove","onMouseMoveCapture","onMouseOut","onMouseOutCapture","onMouseOver","onMouseOverCapture","onMouseUp","onMouseUpCapture","onSelect","onSelectCapture","onTouchCancel","onTouchCancelCapture","onTouchEnd","onTouchEndCapture","onTouchMove","onTouchMoveCapture","onTouchStart","onTouchStartCapture","onPointerDown","onPointerDownCapture","onPointerMove","onPointerMoveCapture","onPointerUp","onPointerUpCapture","onPointerCancel","onPointerCancelCapture","onPointerEnter","onPointerEnterCapture","onPointerLeave","onPointerLeaveCapture","onPointerOver","onPointerOverCapture","onPointerOut","onPointerOutCapture","onGotPointerCapture","onGotPointerCaptureCapture","onLostPointerCapture","onLostPointerCaptureCapture","onScroll","onScrollCapture","onWheel","onWheelCapture","onAnimationStart","onAnimationStartCapture","onAnimationEnd","onAnimationEndCapture","onAnimationIteration","onAnimationIterationCapture","onTransitionEnd","onTransitionEndCapture"];function sSe(e){if(typeof e!="string")return!1;var t=LXn;return t.includes(e)}var FXn=["aria-activedescendant","aria-atomic","aria-autocomplete","aria-busy","aria-checked","aria-colcount","aria-colindex","aria-colspan","aria-controls","aria-current","aria-describedby","aria-details","aria-disabled","aria-errormessage","aria-expanded","aria-flowto","aria-haspopup","aria-hidden","aria-invalid","aria-keyshortcuts","aria-label","aria-labelledby","aria-level","aria-live","aria-modal","aria-multiline","aria-multiselectable","aria-orientation","aria-owns","aria-placeholder","aria-posinset","aria-pressed","aria-readonly","aria-relevant","aria-required","aria-roledescription","aria-rowcount","aria-rowindex","aria-rowspan","aria-selected","aria-setsize","aria-sort","aria-valuemax","aria-valuemin","aria-valuenow","aria-valuetext","className","color","height","id","lang","max","media","method","min","name","style","target","width","role","tabIndex","accentHeight","accumulate","additive","alignmentBaseline","allowReorder","alphabetic","amplitude","arabicForm","ascent","attributeName","attributeType","autoReverse","azimuth","baseFrequency","baselineShift","baseProfile","bbox","begin","bias","by","calcMode","capHeight","clip","clipPath","clipPathUnits","clipRule","colorInterpolation","colorInterpolationFilters","colorProfile","colorRendering","contentScriptType","contentStyleType","cursor","cx","cy","d","decelerate","descent","diffuseConstant","direction","display","divisor","dominantBaseline","dur","dx","dy","edgeMode","elevation","enableBackground","end","exponent","externalResourcesRequired","fill","fillOpacity","fillRule","filter","filterRes","filterUnits","floodColor","floodOpacity","focusable","fontFamily","fontSize","fontSizeAdjust","fontStretch","fontStyle","fontVariant","fontWeight","format","from","fx","fy","g1","g2","glyphName","glyphOrientationHorizontal","glyphOrientationVertical","glyphRef","gradientTransform","gradientUnits","hanging","horizAdvX","horizOriginX","href","ideographic","imageRendering","in2","in","intercept","k1","k2","k3","k4","k","kernelMatrix","kernelUnitLength","kerning","keyPoints","keySplines","keyTimes","lengthAdjust","letterSpacing","lightingColor","limitingConeAngle","local","markerEnd","markerHeight","markerMid","markerStart","markerUnits","markerWidth","mask","maskContentUnits","maskUnits","mathematical","mode","numOctaves","offset","opacity","operator","order","orient","orientation","origin","overflow","overlinePosition","overlineThickness","paintOrder","panose1","pathLength","patternContentUnits","patternTransform","patternUnits","pointerEvents","pointsAtX","pointsAtY","pointsAtZ","preserveAlpha","preserveAspectRatio","primitiveUnits","r","radius","refX","refY","renderingIntent","repeatCount","repeatDur","requiredExtensions","requiredFeatures","restart","result","rotate","rx","ry","seed","shapeRendering","slope","spacing","specularConstant","specularExponent","speed","spreadMethod","startOffset","stdDeviation","stemh","stemv","stitchTiles","stopColor","stopOpacity","strikethroughPosition","strikethroughThickness","string","stroke","strokeDasharray","strokeDashoffset","strokeLinecap","strokeLinejoin","strokeMiterlimit","strokeOpacity","strokeWidth","surfaceScale","systemLanguage","tableValues","targetX","targetY","textAnchor","textDecoration","textLength","textRendering","to","transform","u1","u2","underlinePosition","underlineThickness","unicode","unicodeBidi","unicodeRange","unitsPerEm","vAlphabetic","values","vectorEffect","version","vertAdvY","vertOriginX","vertOriginY","vHanging","vIdeographic","viewTarget","visibility","vMathematical","widths","wordSpacing","writingMode","x1","x2","x","xChannelSelector","xHeight","xlinkActuate","xlinkArcrole","xlinkHref","xlinkRole","xlinkShow","xlinkTitle","xlinkType","xmlBase","xmlLang","xmlns","xmlnsXlink","xmlSpace","y1","y2","y","yChannelSelector","z","zoomAndPan","ref","key","angle"],zXn=new Set(FXn);function rSt(e){return typeof e!="string"?!1:zXn.has(e)}function sSt(e){return typeof e=="string"&&e.startsWith("data-")}function wf(e){if(typeof e!="object"||e===null)return{};var t={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(rSt(n)||sSt(n))&&(t[n]=e[n]);return t}function _3(e){if(e==null)return null;if(g.isValidElement(e)&&typeof e.props=="object"&&e.props!==null){var t=e.props;return wf(t)}return typeof e=="object"&&!Array.isArray(e)?wf(e):null}function su(e){var t={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(rSt(n)||sSt(n)||sSe(n))&&(t[n]=e[n]);return t}function BXn(e){return e==null?null:g.isValidElement(e)?su(e.props):typeof e=="object"&&!Array.isArray(e)?su(e):null}var UXn=["children","width","height","viewBox","className","style","title","desc"];function Zhe(){return Zhe=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},Zhe.apply(null,arguments)}function qXn(e,t){if(e==null)return{};var n,r,s=VXn(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(s[n]=e[n])}return s}function VXn(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}var aSt=g.forwardRef((e,t)=>{var{children:n,width:r,height:s,viewBox:a,className:i,style:l,title:c,desc:u}=e,d=qXn(e,UXn),f=a||{width:r,height:s,x:0,y:0},p=Ca("recharts-surface",i);return g.createElement("svg",Zhe({},su(d),{className:p,width:r,height:s,style:l,viewBox:"".concat(f.x," ").concat(f.y," ").concat(f.width," ").concat(f.height),ref:t}),g.createElement("title",null,c),g.createElement("desc",null,u),n)}),HXn=["children","className"];function Ghe(){return Ghe=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},Ghe.apply(null,arguments)}function WXn(e,t){if(e==null)return{};var n,r,s=ZXn(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(s[n]=e[n])}return s}function ZXn(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}var tc=g.forwardRef((e,t)=>{var{children:n,className:r}=e,s=WXn(e,HXn),a=Ca("recharts-layer",r);return g.createElement("g",Ghe({className:a},su(s),{ref:t}),n)}),GXn=g.createContext(null);function Pi(e){return function(){return e}}const iSt=Math.cos,q7=Math.sin,Bg=Math.sqrt,V7=Math.PI,rH=2*V7,Qhe=Math.PI,Yhe=2*Qhe,ek=1e-6,QXn=Yhe-ek;function oSt(e){this._+=e[0];for(let t=1,n=e.length;t<n;++t)this._+=arguments[t]+e[t]}function YXn(e){let t=Math.floor(e);if(!(t>=0))throw new Error(`invalid digits: ${e}`);if(t>15)return oSt;const n=10**t;return function(r){this._+=r[0];for(let s=1,a=r.length;s<a;++s)this._+=Math.round(arguments[s]*n)/n+r[s]}}class XXn{constructor(t){this._x0=this._y0=this._x1=this._y1=null,this._="",this._append=t==null?oSt:YXn(t)}moveTo(t,n){this._append`M${this._x0=this._x1=+t},${this._y0=this._y1=+n}`}closePath(){this._x1!==null&&(this._x1=this._x0,this._y1=this._y0,this._append`Z`)}lineTo(t,n){this._append`L${this._x1=+t},${this._y1=+n}`}quadraticCurveTo(t,n,r,s){this._append`Q${+t},${+n},${this._x1=+r},${this._y1=+s}`}bezierCurveTo(t,n,r,s,a,i){this._append`C${+t},${+n},${+r},${+s},${this._x1=+a},${this._y1=+i}`}arcTo(t,n,r,s,a){if(t=+t,n=+n,r=+r,s=+s,a=+a,a<0)throw new Error(`negative radius: ${a}`);let i=this._x1,l=this._y1,c=r-t,u=s-n,d=i-t,f=l-n,p=d*d+f*f;if(this._x1===null)this._append`M${this._x1=t},${this._y1=n}`;else if(p>ek)if(!(Math.abs(f*c-u*d)>ek)||!a)this._append`L${this._x1=t},${this._y1=n}`;else{let h=r-i,m=s-l,v=c*c+u*u,y=h*h+m*m,b=Math.sqrt(v),S=Math.sqrt(p),w=a*Math.tan((Qhe-Math.acos((v+p-y)/(2*b*S)))/2),k=w/S,_=w/b;Math.abs(k-1)>ek&&this._append`L${t+k*d},${n+k*f}`,this._append`A${a},${a},0,0,${+(f*h>d*m)},${this._x1=t+_*c},${this._y1=n+_*u}`}}arc(t,n,r,s,a,i){if(t=+t,n=+n,r=+r,i=!!i,r<0)throw new Error(`negative radius: ${r}`);let l=r*Math.cos(s),c=r*Math.sin(s),u=t+l,d=n+c,f=1^i,p=i?s-a:a-s;this._x1===null?this._append`M${u},${d}`:(Math.abs(this._x1-u)>ek||Math.abs(this._y1-d)>ek)&&this._append`L${u},${d}`,r&&(p<0&&(p=p%Yhe+Yhe),p>QXn?this._append`A${r},${r},0,1,${f},${t-l},${n-c}A${r},${r},0,1,${f},${this._x1=u},${this._y1=d}`:p>ek&&this._append`A${r},${r},0,${+(p>=Qhe)},${f},${this._x1=t+r*Math.cos(a)},${this._y1=n+r*Math.sin(a)}`)}rect(t,n,r,s){this._append`M${this._x0=this._x1=+t},${this._y0=this._y1=+n}h${r=+r}v${+s}h${-r}Z`}toString(){return this._}}function aSe(e){let t=3;return e.digits=function(n){if(!arguments.length)return t;if(n==null)t=null;else{const r=Math.floor(n);if(!(r>=0))throw new RangeError(`invalid digits: ${n}`);t=r}return e},()=>new XXn(t)}function iSe(e){return typeof e=="object"&&"length"in e?e:Array.from(e)}function lSt(e){this._context=e}lSt.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._point=0},lineEnd:function(){(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line=1-this._line},point:function(e,t){switch(e=+e,t=+t,this._point){case 0:this._point=1,this._line?this._context.lineTo(e,t):this._context.moveTo(e,t);break;case 1:this._point=2;default:this._context.lineTo(e,t);break}}};function sH(e){return new lSt(e)}function cSt(e){return e[0]}function uSt(e){return e[1]}function dSt(e,t){var n=Pi(!0),r=null,s=sH,a=null,i=aSe(l);e=typeof e=="function"?e:e===void 0?cSt:Pi(e),t=typeof t=="function"?t:t===void 0?uSt:Pi(t);function l(c){var u,d=(c=iSe(c)).length,f,p=!1,h;for(r==null&&(a=s(h=i())),u=0;u<=d;++u)!(u<d&&n(f=c[u],u,c))===p&&((p=!p)?a.lineStart():a.lineEnd()),p&&a.point(+e(f,u,c),+t(f,u,c));if(h)return a=null,h+""||null}return l.x=function(c){return arguments.length?(e=typeof c=="function"?c:Pi(+c),l):e},l.y=function(c){return arguments.length?(t=typeof c=="function"?c:Pi(+c),l):t},l.defined=function(c){return arguments.length?(n=typeof c=="function"?c:Pi(!!c),l):n},l.curve=function(c){return arguments.length?(s=c,r!=null&&(a=s(r)),l):s},l.context=function(c){return arguments.length?(c==null?r=a=null:a=s(r=c),l):r},l}function M6(e,t,n){var r=null,s=Pi(!0),a=null,i=sH,l=null,c=aSe(u);e=typeof e=="function"?e:e===void 0?cSt:Pi(+e),t=typeof t=="function"?t:Pi(t===void 0?0:+t),n=typeof n=="function"?n:n===void 0?uSt:Pi(+n);function u(f){var p,h,m,v=(f=iSe(f)).length,y,b=!1,S,w=new Array(v),k=new Array(v);for(a==null&&(l=i(S=c())),p=0;p<=v;++p){if(!(p<v&&s(y=f[p],p,f))===b)if(b=!b)h=p,l.areaStart(),l.lineStart();else{for(l.lineEnd(),l.lineStart(),m=p-1;m>=h;--m)l.point(w[m],k[m]);l.lineEnd(),l.areaEnd()}b&&(w[p]=+e(y,p,f),k[p]=+t(y,p,f),l.point(r?+r(y,p,f):w[p],n?+n(y,p,f):k[p]))}if(S)return l=null,S+""||null}function d(){return dSt().defined(s).curve(i).context(a)}return u.x=function(f){return arguments.length?(e=typeof f=="function"?f:Pi(+f),r=null,u):e},u.x0=function(f){return arguments.length?(e=typeof f=="function"?f:Pi(+f),u):e},u.x1=function(f){return arguments.length?(r=f==null?null:typeof f=="function"?f:Pi(+f),u):r},u.y=function(f){return arguments.length?(t=typeof f=="function"?f:Pi(+f),n=null,u):t},u.y0=function(f){return arguments.length?(t=typeof f=="function"?f:Pi(+f),u):t},u.y1=function(f){return arguments.length?(n=f==null?null:typeof f=="function"?f:Pi(+f),u):n},u.lineX0=u.lineY0=function(){return d().x(e).y(t)},u.lineY1=function(){return d().x(e).y(n)},u.lineX1=function(){return d().x(r).y(t)},u.defined=function(f){return arguments.length?(s=typeof f=="function"?f:Pi(!!f),u):s},u.curve=function(f){return arguments.length?(i=f,a!=null&&(l=i(a)),u):i},u.context=function(f){return arguments.length?(f==null?a=l=null:l=i(a=f),u):a},u}class fSt{constructor(t,n){this._context=t,this._x=n}areaStart(){this._line=0}areaEnd(){this._line=NaN}lineStart(){this._point=0}lineEnd(){(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line=1-this._line}point(t,n){switch(t=+t,n=+n,this._point){case 0:{this._point=1,this._line?this._context.lineTo(t,n):this._context.moveTo(t,n);break}case 1:this._point=2;default:{this._x?this._context.bezierCurveTo(this._x0=(this._x0+t)/2,this._y0,this._x0,n,t,n):this._context.bezierCurveTo(this._x0,this._y0=(this._y0+n)/2,t,this._y0,t,n);break}}this._x0=t,this._y0=n}}function KXn(e){return new fSt(e,!0)}function JXn(e){return new fSt(e,!1)}const oSe={draw(e,t){const n=Bg(t/V7);e.moveTo(n,0),e.arc(0,0,n,0,rH)}},eKn={draw(e,t){const n=Bg(t/5)/2;e.moveTo(-3*n,-n),e.lineTo(-n,-n),e.lineTo(-n,-3*n),e.lineTo(n,-3*n),e.lineTo(n,-n),e.lineTo(3*n,-n),e.lineTo(3*n,n),e.lineTo(n,n),e.lineTo(n,3*n),e.lineTo(-n,3*n),e.lineTo(-n,n),e.lineTo(-3*n,n),e.closePath()}},pSt=Bg(1/3),tKn=pSt*2,nKn={draw(e,t){const n=Bg(t/tKn),r=n*pSt;e.moveTo(0,-n),e.lineTo(r,0),e.lineTo(0,n),e.lineTo(-r,0),e.closePath()}},rKn={draw(e,t){const n=Bg(t),r=-n/2;e.rect(r,r,n,n)}},sKn=.8908130915292852,hSt=q7(V7/10)/q7(7*V7/10),aKn=q7(rH/10)*hSt,iKn=-iSt(rH/10)*hSt,oKn={draw(e,t){const n=Bg(t*sKn),r=aKn*n,s=iKn*n;e.moveTo(0,-n),e.lineTo(r,s);for(let a=1;a<5;++a){const i=rH*a/5,l=iSt(i),c=q7(i);e.lineTo(c*n,-l*n),e.lineTo(l*r-c*s,c*r+l*s)}e.closePath()}},lee=Bg(3),lKn={draw(e,t){const n=-Bg(t/(lee*3));e.moveTo(0,n*2),e.lineTo(-lee*n,-n),e.lineTo(lee*n,-n),e.closePath()}},vh=-.5,yh=Bg(3)/2,Xhe=1/Bg(12),cKn=(Xhe/2+1)*3,uKn={draw(e,t){const n=Bg(t/cKn),r=n/2,s=n*Xhe,a=r,i=n*Xhe+n,l=-a,c=i;e.moveTo(r,s),e.lineTo(a,i),e.lineTo(l,c),e.lineTo(vh*r-yh*s,yh*r+vh*s),e.lineTo(vh*a-yh*i,yh*a+vh*i),e.lineTo(vh*l-yh*c,yh*l+vh*c),e.lineTo(vh*r+yh*s,vh*s-yh*r),e.lineTo(vh*a+yh*i,vh*i-yh*a),e.lineTo(vh*l+yh*c,vh*c-yh*l),e.closePath()}};function dKn(e,t){let n=null,r=aSe(s);e=typeof e=="function"?e:Pi(e||oSe),t=typeof t=="function"?t:Pi(t===void 0?64:+t);function s(){let a;if(n||(n=a=r()),e.apply(this,arguments).draw(n,+t.apply(this,arguments)),a)return n=null,a+""||null}return s.type=function(a){return arguments.length?(e=typeof a=="function"?a:Pi(a),s):e},s.size=function(a){return arguments.length?(t=typeof a=="function"?a:Pi(+a),s):t},s.context=function(a){return arguments.length?(n=a??null,s):n},s}function H7(){}function W7(e,t,n){e._context.bezierCurveTo((2*e._x0+e._x1)/3,(2*e._y0+e._y1)/3,(e._x0+2*e._x1)/3,(e._y0+2*e._y1)/3,(e._x0+4*e._x1+t)/6,(e._y0+4*e._y1+n)/6)}function mSt(e){this._context=e}mSt.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._y0=this._y1=NaN,this._point=0},lineEnd:function(){switch(this._point){case 3:W7(this,this._x1,this._y1);case 2:this._context.lineTo(this._x1,this._y1);break}(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line=1-this._line},point:function(e,t){switch(e=+e,t=+t,this._point){case 0:this._point=1,this._line?this._context.lineTo(e,t):this._context.moveTo(e,t);break;case 1:this._point=2;break;case 2:this._point=3,this._context.lineTo((5*this._x0+this._x1)/6,(5*this._y0+this._y1)/6);default:W7(this,e,t);break}this._x0=this._x1,this._x1=e,this._y0=this._y1,this._y1=t}};function fKn(e){return new mSt(e)}function gSt(e){this._context=e}gSt.prototype={areaStart:H7,areaEnd:H7,lineStart:function(){this._x0=this._x1=this._x2=this._x3=this._x4=this._y0=this._y1=this._y2=this._y3=this._y4=NaN,this._point=0},lineEnd:function(){switch(this._point){case 1:{this._context.moveTo(this._x2,this._y2),this._context.closePath();break}case 2:{this._context.moveTo((this._x2+2*this._x3)/3,(this._y2+2*this._y3)/3),this._context.lineTo((this._x3+2*this._x2)/3,(this._y3+2*this._y2)/3),this._context.closePath();break}case 3:{this.point(this._x2,this._y2),this.point(this._x3,this._y3),this.point(this._x4,this._y4);break}}},point:function(e,t){switch(e=+e,t=+t,this._point){case 0:this._point=1,this._x2=e,this._y2=t;break;case 1:this._point=2,this._x3=e,this._y3=t;break;case 2:this._point=3,this._x4=e,this._y4=t,this._context.moveTo((this._x0+4*this._x1+e)/6,(this._y0+4*this._y1+t)/6);break;default:W7(this,e,t);break}this._x0=this._x1,this._x1=e,this._y0=this._y1,this._y1=t}};function pKn(e){return new gSt(e)}function vSt(e){this._context=e}vSt.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._y0=this._y1=NaN,this._point=0},lineEnd:function(){(this._line||this._line!==0&&this._point===3)&&this._context.closePath(),this._line=1-this._line},point:function(e,t){switch(e=+e,t=+t,this._point){case 0:this._point=1;break;case 1:this._point=2;break;case 2:this._point=3;var n=(this._x0+4*this._x1+e)/6,r=(this._y0+4*this._y1+t)/6;this._line?this._context.lineTo(n,r):this._context.moveTo(n,r);break;case 3:this._point=4;default:W7(this,e,t);break}this._x0=this._x1,this._x1=e,this._y0=this._y1,this._y1=t}};function hKn(e){return new vSt(e)}function ySt(e){this._context=e}ySt.prototype={areaStart:H7,areaEnd:H7,lineStart:function(){this._point=0},lineEnd:function(){this._point&&this._context.closePath()},point:function(e,t){e=+e,t=+t,this._point?this._context.lineTo(e,t):(this._point=1,this._context.moveTo(e,t))}};function mKn(e){return new ySt(e)}function h8e(e){return e<0?-1:1}function m8e(e,t,n){var r=e._x1-e._x0,s=t-e._x1,a=(e._y1-e._y0)/(r||s<0&&-0),i=(n-e._y1)/(s||r<0&&-0),l=(a*s+i*r)/(r+s);return(h8e(a)+h8e(i))*Math.min(Math.abs(a),Math.abs(i),.5*Math.abs(l))||0}function g8e(e,t){var n=e._x1-e._x0;return n?(3*(e._y1-e._y0)/n-t)/2:t}function cee(e,t,n){var r=e._x0,s=e._y0,a=e._x1,i=e._y1,l=(a-r)/3;e._context.bezierCurveTo(r+l,s+l*t,a-l,i-l*n,a,i)}function Z7(e){this._context=e}Z7.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._y0=this._y1=this._t0=NaN,this._point=0},lineEnd:function(){switch(this._point){case 2:this._context.lineTo(this._x1,this._y1);break;case 3:cee(this,this._t0,g8e(this,this._t0));break}(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line=1-this._line},point:function(e,t){var n=NaN;if(e=+e,t=+t,!(e===this._x1&&t===this._y1)){switch(this._point){case 0:this._point=1,this._line?this._context.lineTo(e,t):this._context.moveTo(e,t);break;case 1:this._point=2;break;case 2:this._point=3,cee(this,g8e(this,n=m8e(this,e,t)),n);break;default:cee(this,this._t0,n=m8e(this,e,t));break}this._x0=this._x1,this._x1=e,this._y0=this._y1,this._y1=t,this._t0=n}}};function bSt(e){this._context=new xSt(e)}(bSt.prototype=Object.create(Z7.prototype)).point=function(e,t){Z7.prototype.point.call(this,t,e)};function xSt(e){this._context=e}xSt.prototype={moveTo:function(e,t){this._context.moveTo(t,e)},closePath:function(){this._context.closePath()},lineTo:function(e,t){this._context.lineTo(t,e)},bezierCurveTo:function(e,t,n,r,s,a){this._context.bezierCurveTo(t,e,r,n,a,s)}};function gKn(e){return new Z7(e)}function vKn(e){return new bSt(e)}function wSt(e){this._context=e}wSt.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x=[],this._y=[]},lineEnd:function(){var e=this._x,t=this._y,n=e.length;if(n)if(this._line?this._context.lineTo(e[0],t[0]):this._context.moveTo(e[0],t[0]),n===2)this._context.lineTo(e[1],t[1]);else for(var r=v8e(e),s=v8e(t),a=0,i=1;i<n;++a,++i)this._context.bezierCurveTo(r[0][a],s[0][a],r[1][a],s[1][a],e[i],t[i]);(this._line||this._line!==0&&n===1)&&this._context.closePath(),this._line=1-this._line,this._x=this._y=null},point:function(e,t){this._x.push(+e),this._y.push(+t)}};function v8e(e){var t,n=e.length-1,r,s=new Array(n),a=new Array(n),i=new Array(n);for(s[0]=0,a[0]=2,i[0]=e[0]+2*e[1],t=1;t<n-1;++t)s[t]=1,a[t]=4,i[t]=4*e[t]+2*e[t+1];for(s[n-1]=2,a[n-1]=7,i[n-1]=8*e[n-1]+e[n],t=1;t<n;++t)r=s[t]/a[t-1],a[t]-=r,i[t]-=r*i[t-1];for(s[n-1]=i[n-1]/a[n-1],t=n-2;t>=0;--t)s[t]=(i[t]-s[t+1])/a[t];for(a[n-1]=(e[n]+s[n-1])/2,t=0;t<n-1;++t)a[t]=2*e[t+1]-s[t+1];return[s,a]}function yKn(e){return new wSt(e)}function aH(e,t){this._context=e,this._t=t}aH.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x=this._y=NaN,this._point=0},lineEnd:function(){0<this._t&&this._t<1&&this._point===2&&this._context.lineTo(this._x,this._y),(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line>=0&&(this._t=1-this._t,this._line=1-this._line)},point:function(e,t){switch(e=+e,t=+t,this._point){case 0:this._point=1,this._line?this._context.lineTo(e,t):this._context.moveTo(e,t);break;case 1:this._point=2;default:{if(this._t<=0)this._context.lineTo(this._x,t),this._context.lineTo(e,t);else{var n=this._x*(1-this._t)+e*this._t;this._context.lineTo(n,this._y),this._context.lineTo(n,t)}break}}this._x=e,this._y=t}};function bKn(e){return new aH(e,.5)}function xKn(e){return new aH(e,0)}function wKn(e){return new aH(e,1)}function UO(e,t){if((i=e.length)>1)for(var n=1,r,s,a=e[t[0]],i,l=a.length;n<i;++n)for(s=a,a=e[t[n]],r=0;r<l;++r)a[r][1]+=a[r][0]=isNaN(s[r][1])?s[r][0]:s[r][1]}function Khe(e){for(var t=e.length,n=new Array(t);--t>=0;)n[t]=t;return n}function SKn(e,t){return e[t]}function kKn(e){const t=[];return t.key=e,t}function OKn(){var e=Pi([]),t=Khe,n=UO,r=SKn;function s(a){var i=Array.from(e.apply(this,arguments),kKn),l,c=i.length,u=-1,d;for(const f of a)for(l=0,++u;l<c;++l)(i[l][u]=[0,+r(f,i[l].key,u,a)]).data=f;for(l=0,d=iSe(t(i));l<c;++l)i[d[l]].index=l;return n(i,d),i}return s.keys=function(a){return arguments.length?(e=typeof a=="function"?a:Pi(Array.from(a)),s):e},s.value=function(a){return arguments.length?(r=typeof a=="function"?a:Pi(+a),s):r},s.order=function(a){return arguments.length?(t=a==null?Khe:typeof a=="function"?a:Pi(Array.from(a)),s):t},s.offset=function(a){return arguments.length?(n=a??UO,s):n},s}function _Kn(e,t){if((r=e.length)>0){for(var n,r,s=0,a=e[0].length,i;s<a;++s){for(i=n=0;n<r;++n)i+=e[n][s][1]||0;if(i)for(n=0;n<r;++n)e[n][s][1]/=i}UO(e,t)}}function CKn(e,t){if((s=e.length)>0){for(var n=0,r=e[t[0]],s,a=r.length;n<a;++n){for(var i=0,l=0;i<s;++i)l+=e[i][n][1]||0;r[n][1]+=r[n][0]=-l/2}UO(e,t)}}function EKn(e,t){if(!(!((i=e.length)>0)||!((a=(s=e[t[0]]).length)>0))){for(var n=0,r=1,s,a,i;r<a;++r){for(var l=0,c=0,u=0;l<i;++l){for(var d=e[t[l]],f=d[r][1]||0,p=d[r-1][1]||0,h=(f-p)/2,m=0;m<l;++m){var v=e[t[m]],y=v[r][1]||0,b=v[r-1][1]||0;h+=y-b}c+=f,u+=h*f}s[r-1][1]+=s[r-1][0]=n,c&&(n-=u/c)}s[r-1][1]+=s[r-1][0]=n,UO(e,t)}}var uee={},dee={},y8e;function jKn(){return y8e||(y8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});function t(n){return n==="__proto__"}e.isUnsafeProperty=t})(dee)),dee}var fee={},b8e;function SSt(){return b8e||(b8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});function t(n){switch(typeof n){case"number":case"symbol":return!1;case"string":return n.includes(".")||n.includes("[")||n.includes("]")}}e.isDeepKey=t})(fee)),fee}var pee={},x8e;function lSe(){return x8e||(x8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});function t(n){return typeof n=="string"||typeof n=="symbol"?n:Object.is(n?.valueOf?.(),-0)?"-0":String(n)}e.toKey=t})(pee)),pee}var hee={},mee={},w8e;function TKn(){return w8e||(w8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});function t(n){if(n==null)return"";if(typeof n=="string")return n;if(Array.isArray(n))return n.map(t).join(",");const r=String(n);return r==="0"&&Object.is(Number(n),-0)?"-0":r}e.toString=t})(mee)),mee}var S8e;function cSe(){return S8e||(S8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});const t=TKn(),n=lSe();function r(s){if(Array.isArray(s))return s.map(n.toKey);if(typeof s=="symbol")return[s];s=t.toString(s);const a=[],i=s.length;if(i===0)return a;let l=0,c="",u="",d=!1;for(s.charCodeAt(0)===46&&(a.push(""),l++);l<i;){const f=s[l];u?f==="\\"&&l+1<i?(l++,c+=s[l]):f===u?u="":c+=f:d?f==='"'||f==="'"?u=f:f==="]"?(d=!1,a.push(c),c=""):c+=f:f==="["?(d=!0,c&&(a.push(c),c="")):f==="."?c&&(a.push(c),c=""):c+=f,l++}return c&&a.push(c),a}e.toPath=r})(hee)),hee}var k8e;function uSe(){return k8e||(k8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});const t=jKn(),n=SSt(),r=lSe(),s=cSe();function a(l,c,u){if(l==null)return u;switch(typeof c){case"string":{if(t.isUnsafeProperty(c))return u;const d=l[c];return d===void 0?n.isDeepKey(c)?a(l,s.toPath(c),u):u:d}case"number":case"symbol":{typeof c=="number"&&(c=r.toKey(c));const d=l[c];return d===void 0?u:d}default:{if(Array.isArray(c))return i(l,c,u);if(Object.is(c?.valueOf(),-0)?c="-0":c=String(c),t.isUnsafeProperty(c))return u;const d=l[c];return d===void 0?u:d}}}function i(l,c,u){if(c.length===0)return u;let d=l;for(let f=0;f<c.length;f++){if(d==null||t.isUnsafeProperty(c[f]))return u;d=d[c[f]]}return d===void 0?u:d}e.get=a})(uee)),uee}var gee,O8e;function NKn(){return O8e||(O8e=1,gee=uSe().get),gee}var IKn=NKn();const TT=Tc(IKn);var AKn=4;function yw(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:AKn,n=10**t,r=Math.round(e*n)/n;return Object.is(r,-0)?0:r}function Go(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];return e.reduce((s,a,i)=>{var l=n[i-1];return typeof l=="string"?s+l+a:l!==void 0?s+yw(l)+a:s+a},"")}var zh=e=>e===0?0:e>0?1:-1,my=e=>typeof e=="number"&&e!=+e,qO=e=>typeof e=="string"&&e.indexOf("%")===e.length-1,Hn=e=>(typeof e=="number"||e instanceof Number)&&!my(e),cm=e=>Hn(e)||typeof e=="string",RKn=0,pM=e=>{var t=++RKn;return"".concat(e||"").concat(t)},v1=function(t,n){var r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:0,s=arguments.length>3&&arguments[3]!==void 0?arguments[3]:!1;if(!Hn(t)&&typeof t!="string")return r;var a;if(qO(t)){if(n==null)return r;var i=t.indexOf("%");a=n*parseFloat(t.slice(0,i))/100}else a=+t;return my(a)&&(a=r),s&&n!=null&&a>n&&(a=n),a},kSt=e=>{if(!Array.isArray(e))return!1;for(var t=e.length,n={},r=0;r<t;r++)if(!n[String(e[r])])n[String(e[r])]=!0;else return!0;return!1};function uo(e,t,n){return Hn(e)&&Hn(t)?yw(e+n*(t-e)):t}function OSt(e,t,n){if(!(!e||!e.length))return e.find(r=>r&&(typeof t=="function"?t(r):TT(r,t))===n)}var PKn=e=>{for(var t=e.length,n=0,r=0,s=0,a=0,i=1/0,l=-1/0,c=0,u=0,d=0;d<t;d++){var f,p;c=((f=e[d])===null||f===void 0?void 0:f.cx)||0,u=((p=e[d])===null||p===void 0?void 0:p.cy)||0,n+=c,r+=u,s+=c*u,a+=c*c,i=Math.min(i,c),l=Math.max(l,c)}var h=t*a!==n*n?(t*s-n*r)/(t*a-n*n):0;return{xmin:i,xmax:l,a:h,b:(r-h*n)/t}},Ki=e=>e===null||typeof e>"u",C3=e=>Ki(e)?e:"".concat(e.charAt(0).toUpperCase()).concat(e.slice(1));function rf(e){return e!=null}function M_(){}var $Kn=["type","size","sizeType"];function Jhe(){return Jhe=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},Jhe.apply(null,arguments)}function _8e(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(s){return Object.getOwnPropertyDescriptor(e,s).enumerable})),n.push.apply(n,r)}return n}function C8e(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?_8e(Object(n),!0).forEach(function(r){MKn(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):_8e(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}function MKn(e,t,n){return(t=DKn(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function DKn(e){var t=LKn(e,"string");return typeof t=="symbol"?t:t+""}function LKn(e,t){if(typeof e!="object"||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t);if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}function FKn(e,t){if(e==null)return{};var n,r,s=zKn(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(s[n]=e[n])}return s}function zKn(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}var _St={symbolCircle:oSe,symbolCross:eKn,symbolDiamond:nKn,symbolSquare:rKn,symbolStar:oKn,symbolTriangle:lKn,symbolWye:uKn},BKn=Math.PI/180,UKn=e=>{var t="symbol".concat(C3(e));return _St[t]||oSe},qKn=(e,t,n)=>{if(t==="area")return e;switch(n){case"cross":return 5*e*e/9;case"diamond":return .5*e*e/Math.sqrt(3);case"square":return e*e;case"star":{var r=18*BKn;return 1.25*e*e*(Math.tan(r)-Math.tan(r*2)*Math.tan(r)**2)}case"triangle":return Math.sqrt(3)*e*e/4;case"wye":return(21-10*Math.sqrt(3))*e*e/8;default:return Math.PI*e*e/4}},VKn=(e,t)=>{_St["symbol".concat(C3(e))]=t},dSe=e=>{var{type:t="circle",size:n=64,sizeType:r="area"}=e,s=FKn(e,$Kn),a=C8e(C8e({},s),{},{type:t,size:n,sizeType:r}),i="circle";typeof t=="string"&&(i=t);var l=()=>{var p=UKn(i),h=dKn().type(p).size(qKn(n,r,i)),m=h();if(m!==null)return m},{className:c,cx:u,cy:d}=a,f=su(a);return Hn(u)&&Hn(d)&&Hn(n)?g.createElement("path",Jhe({},f,{className:Ca("recharts-symbols",c),transform:"translate(".concat(u,", ").concat(d,")"),d:l()})):null};dSe.registerSymbol=VKn;var CSt=e=>"radius"in e&&"startAngle"in e&&"endAngle"in e,fSe=(e,t)=>{if(!e||typeof e=="function"||typeof e=="boolean")return null;var n=e;if(g.isValidElement(e)&&(n=e.props),typeof n!="object"&&typeof n!="function")return null;var r={};return Object.keys(n).forEach(s=>{sSe(s)&&typeof n[s]=="function"&&(r[s]=(a=>n[s](n,a)))}),r},HKn=(e,t,n)=>r=>(e(t,n,r),null),ESt=(e,t,n)=>{if(e===null||typeof e!="object"&&typeof e!="function")return null;var r=null;return Object.keys(e).forEach(s=>{var a=e[s];sSe(s)&&typeof a=="function"&&(r||(r={}),r[s]=HKn(a,t,n))}),r},WKn=e=>Array.isArray(e)&&e.length>0;function E8e(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(s){return Object.getOwnPropertyDescriptor(e,s).enumerable})),n.push.apply(n,r)}return n}function ZKn(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?E8e(Object(n),!0).forEach(function(r){GKn(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):E8e(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}function GKn(e,t,n){return(t=QKn(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function QKn(e){var t=YKn(e,"string");return typeof t=="symbol"?t:t+""}function YKn(e,t){if(typeof e!="object"||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t);if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}function ic(e,t){var n=ZKn({},e),r=t,s=Object.keys(t),a=s.reduce((i,l)=>(i[l]===void 0&&r[l]!==void 0&&(i[l]=r[l]),i),n);return a}var vee={},yee={},j8e;function XKn(){return j8e||(j8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});function t(n,r){const s=new Map;for(let a=0;a<n.length;a++){const i=n[a],l=r(i,a,n);s.has(l)||s.set(l,i)}return Array.from(s.values())}e.uniqBy=t})(yee)),yee}var bee={},T8e;function KKn(){return T8e||(T8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});function t(n,r){return function(...s){return n.apply(this,s.slice(0,r))}}e.ary=t})(bee)),bee}var xee={},N8e;function jSt(){return N8e||(N8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});function t(n){return n}e.identity=t})(xee)),xee}var wee={},See={},kee={},I8e;function JKn(){return I8e||(I8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});function t(n){return Number.isSafeInteger(n)&&n>=0}e.isLength=t})(kee)),kee}var A8e;function TSt(){return A8e||(A8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});const t=JKn();function n(r){return r!=null&&typeof r!="function"&&t.isLength(r.length)}e.isArrayLike=n})(See)),See}var Oee={},R8e;function eJn(){return R8e||(R8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});function t(n){return typeof n=="object"&&n!==null}e.isObjectLike=t})(Oee)),Oee}var P8e;function tJn(){return P8e||(P8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});const t=TSt(),n=eJn();function r(s){return n.isObjectLike(s)&&t.isArrayLike(s)}e.isArrayLikeObject=r})(wee)),wee}var _ee={},Cee={},$8e;function nJn(){return $8e||($8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});const t=uSe();function n(r){return function(s){return t.get(s,r)}}e.property=n})(Cee)),Cee}var Eee={},jee={},Tee={},Nee={},M8e;function NSt(){return M8e||(M8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});function t(n){return n!==null&&(typeof n=="object"||typeof n=="function")}e.isObject=t})(Nee)),Nee}var Iee={},D8e;function ISt(){return D8e||(D8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});function t(n){return n==null||typeof n!="object"&&typeof n!="function"}e.isPrimitive=t})(Iee)),Iee}var Aee={},L8e;function ASt(){return L8e||(L8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});function t(n,r){return n===r||Number.isNaN(n)&&Number.isNaN(r)}e.isEqualsSameValueZero=t})(Aee)),Aee}var F8e;function rJn(){return F8e||(F8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});const t=NSt(),n=ISt(),r=ASt();function s(d,f,p){return typeof p!="function"?s(d,f,()=>{}):a(d,f,function h(m,v,y,b,S,w){const k=p(m,v,y,b,S,w);return k!==void 0?!!k:a(m,v,h,w)},new Map)}function a(d,f,p,h){if(f===d)return!0;switch(typeof f){case"object":return i(d,f,p,h);case"function":return Object.keys(f).length>0?a(d,{...f},p,h):r.isEqualsSameValueZero(d,f);default:return t.isObject(d)?typeof f=="string"?f==="":!0:r.isEqualsSameValueZero(d,f)}}function i(d,f,p,h){if(f==null)return!0;if(Array.isArray(f))return c(d,f,p,h);if(f instanceof Map)return l(d,f,p,h);if(f instanceof Set)return u(d,f,p,h);const m=Object.keys(f);if(d==null||n.isPrimitive(d))return m.length===0;if(m.length===0)return!0;if(h?.has(f))return h.get(f)===d;h?.set(f,d);try{for(let v=0;v<m.length;v++){const y=m[v];if(!n.isPrimitive(d)&&!(y in d)||f[y]===void 0&&d[y]!==void 0||f[y]===null&&d[y]!==null||!p(d[y],f[y],y,d,f,h))return!1}return!0}finally{h?.delete(f)}}function l(d,f,p,h){if(f.size===0)return!0;if(!(d instanceof Map))return!1;for(const[m,v]of f.entries()){const y=d.get(m);if(p(y,v,m,d,f,h)===!1)return!1}return!0}function c(d,f,p,h){if(f.length===0)return!0;if(!Array.isArray(d))return!1;const m=new Set;for(let v=0;v<f.length;v++){const y=f[v];let b=!1;for(let S=0;S<d.length;S++){if(m.has(S))continue;const w=d[S];let k=!1;if(p(w,y,v,d,f,h)&&(k=!0),k){m.add(S),b=!0;break}}if(!b)return!1}return!0}function u(d,f,p,h){return f.size===0?!0:d instanceof Set?c([...d],[...f],p,h):!1}e.isMatchWith=s,e.isSetMatch=u})(Tee)),Tee}var z8e;function RSt(){return z8e||(z8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});const t=rJn();function n(r,s){return t.isMatchWith(r,s,()=>{})}e.isMatch=n})(jee)),jee}var Ree={},Pee={},$ee={},B8e;function sJn(){return B8e||(B8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});function t(n){return Object.getOwnPropertySymbols(n).filter(r=>Object.prototype.propertyIsEnumerable.call(n,r))}e.getSymbols=t})($ee)),$ee}var Mee={},U8e;function pSe(){return U8e||(U8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});function t(n){return n==null?n===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(n)}e.getTag=t})(Mee)),Mee}var Dee={},q8e;function PSt(){return q8e||(q8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});const t="[object RegExp]",n="[object String]",r="[object Number]",s="[object Boolean]",a="[object Arguments]",i="[object Symbol]",l="[object Date]",c="[object Map]",u="[object Set]",d="[object Array]",f="[object Function]",p="[object ArrayBuffer]",h="[object Object]",m="[object Error]",v="[object DataView]",y="[object Uint8Array]",b="[object Uint8ClampedArray]",S="[object Uint16Array]",w="[object Uint32Array]",k="[object BigUint64Array]",_="[object Int8Array]",C="[object Int16Array]",E="[object Int32Array]",j="[object BigInt64Array]",N="[object Float32Array]",I="[object Float64Array]";e.argumentsTag=a,e.arrayBufferTag=p,e.arrayTag=d,e.bigInt64ArrayTag=j,e.bigUint64ArrayTag=k,e.booleanTag=s,e.dataViewTag=v,e.dateTag=l,e.errorTag=m,e.float32ArrayTag=N,e.float64ArrayTag=I,e.functionTag=f,e.int16ArrayTag=C,e.int32ArrayTag=E,e.int8ArrayTag=_,e.mapTag=c,e.numberTag=r,e.objectTag=h,e.regexpTag=t,e.setTag=u,e.stringTag=n,e.symbolTag=i,e.uint16ArrayTag=S,e.uint32ArrayTag=w,e.uint8ArrayTag=y,e.uint8ClampedArrayTag=b})(Dee)),Dee}var Lee={},Fee={},V8e;function aJn(){return V8e||(V8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});const t=typeof globalThis=="object"&&globalThis||typeof window=="object"&&window||typeof self=="object"&&self||typeof Bj=="object"&&Bj||(function(){return this})()||Function("return this")();e.globalThis=t})(Fee)),Fee}var H8e;function iJn(){return H8e||(H8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});const t=aJn();function n(r){return typeof t.globalThis.Buffer<"u"&&t.globalThis.Buffer.isBuffer(r)}e.isBuffer=n})(Lee)),Lee}var zee={},W8e;function oJn(){return W8e||(W8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});function t(n){return ArrayBuffer.isView(n)&&!(n instanceof DataView)}e.isTypedArray=t})(zee)),zee}var Z8e;function $St(){return Z8e||(Z8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});const t=sJn(),n=pSe(),r=PSt(),s=iJn(),a=ISt(),i=oJn();function l(f,p){return c(f,void 0,f,new Map,p)}function c(f,p,h,m=new Map,v=void 0){const y=v?.(f,p,h,m);if(y!==void 0)return y;if(a.isPrimitive(f))return f;if(m.has(f))return m.get(f);if(Array.isArray(f)){const b=new Array(f.length);m.set(f,b);for(let S=0;S<f.length;S++)b[S]=c(f[S],S,h,m,v);return Object.hasOwn(f,"index")&&(b.index=f.index),Object.hasOwn(f,"input")&&(b.input=f.input),b}if(f instanceof Date)return new Date(f.getTime());if(f instanceof RegExp){const b=new RegExp(f.source,f.flags);return b.lastIndex=f.lastIndex,b}if(f instanceof Map){const b=new Map;m.set(f,b);for(const[S,w]of f)b.set(S,c(w,S,h,m,v));return b}if(f instanceof Set){const b=new Set;m.set(f,b);for(const S of f)b.add(c(S,void 0,h,m,v));return b}if(s.isBuffer(f))return f.subarray();if(i.isTypedArray(f)){const b=new(Object.getPrototypeOf(f)).constructor(f.length);m.set(f,b);for(let S=0;S<f.length;S++)b[S]=c(f[S],S,h,m,v);return b}if(f instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&f instanceof SharedArrayBuffer)return f.slice(0);if(f instanceof DataView){const b=new DataView(f.buffer.slice(0),f.byteOffset,f.byteLength);return m.set(f,b),u(b,f,h,m,v),b}if(typeof File<"u"&&f instanceof File){const b=new File([f],f.name,{type:f.type});return m.set(f,b),u(b,f,h,m,v),b}if(typeof Blob<"u"&&f instanceof Blob){const b=new Blob([f],{type:f.type});return m.set(f,b),u(b,f,h,m,v),b}if(f instanceof Error){const b=structuredClone(f);return m.set(f,b),b.message=f.message,b.name=f.name,b.stack=f.stack,b.cause=f.cause,b.constructor=f.constructor,u(b,f,h,m,v),b}if(f instanceof Boolean){const b=new Boolean(f.valueOf());return m.set(f,b),u(b,f,h,m,v),b}if(f instanceof Number){const b=new Number(f.valueOf());return m.set(f,b),u(b,f,h,m,v),b}if(f instanceof String){const b=new String(f.valueOf());return m.set(f,b),u(b,f,h,m,v),b}if(typeof f=="object"&&d(f)){const b=Object.create(Object.getPrototypeOf(f));return m.set(f,b),u(b,f,h,m,v),b}return f}function u(f,p,h=f,m,v){const y=[...Object.keys(p),...t.getSymbols(p)];for(let b=0;b<y.length;b++){const S=y[b],w=Object.getOwnPropertyDescriptor(f,S);(w==null||w.writable)&&(f[S]=c(p[S],S,h,m,v))}}function d(f){switch(n.getTag(f)){case r.argumentsTag:case r.arrayTag:case r.arrayBufferTag:case r.dataViewTag:case r.booleanTag:case r.dateTag:case r.float32ArrayTag:case r.float64ArrayTag:case r.int8ArrayTag:case r.int16ArrayTag:case r.int32ArrayTag:case r.mapTag:case r.numberTag:case r.objectTag:case r.regexpTag:case r.setTag:case r.stringTag:case r.symbolTag:case r.uint8ArrayTag:case r.uint8ClampedArrayTag:case r.uint16ArrayTag:case r.uint32ArrayTag:return!0;default:return!1}}e.cloneDeepWith=l,e.cloneDeepWithImpl=c,e.copyProperties=u})(Pee)),Pee}var G8e;function lJn(){return G8e||(G8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});const t=$St();function n(r){return t.cloneDeepWithImpl(r,void 0,r,new Map,void 0)}e.cloneDeep=n})(Ree)),Ree}var Q8e;function cJn(){return Q8e||(Q8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});const t=RSt(),n=lJn();function r(s){return s=n.cloneDeep(s),a=>t.isMatch(a,s)}e.matches=r})(Eee)),Eee}var Bee={},Uee={},qee={},Y8e;function uJn(){return Y8e||(Y8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});const t=$St(),n=pSe(),r=PSt();function s(a,i){return t.cloneDeepWith(a,(l,c,u,d)=>{const f=i?.(l,c,u,d);if(f!==void 0)return f;if(typeof a=="object"){if(n.getTag(a)===r.objectTag&&typeof a.constructor!="function"){const p={};return d.set(a,p),t.copyProperties(p,a,u,d),p}switch(Object.prototype.toString.call(a)){case r.numberTag:case r.stringTag:case r.booleanTag:{const p=new a.constructor(a?.valueOf());return t.copyProperties(p,a),p}case r.argumentsTag:{const p={};return t.copyProperties(p,a),p.length=a.length,p[Symbol.iterator]=a[Symbol.iterator],p}default:return}}})}e.cloneDeepWith=s})(qee)),qee}var X8e;function dJn(){return X8e||(X8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});const t=uJn();function n(r){return t.cloneDeepWith(r)}e.cloneDeep=n})(Uee)),Uee}var Vee={},Hee={},K8e;function MSt(){return K8e||(K8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});const t=/^(?:0|[1-9]\d*)$/;function n(r,s=Number.MAX_SAFE_INTEGER){switch(typeof r){case"number":return Number.isInteger(r)&&r>=0&&r<s;case"symbol":return!1;case"string":return t.test(r)}}e.isIndex=n})(Hee)),Hee}var Wee={},J8e;function fJn(){return J8e||(J8e=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});const t=pSe();function n(r){return r!==null&&typeof r=="object"&&t.getTag(r)==="[object Arguments]"}e.isArguments=n})(Wee)),Wee}var eze;function pJn(){return eze||(eze=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});const t=SSt(),n=MSt(),r=fJn(),s=cSe();function a(i,l){let c;if(Array.isArray(l)?c=l:typeof l=="string"&&t.isDeepKey(l)&&i?.[l]==null?c=s.toPath(l):c=[l],c.length===0)return!1;let u=i;for(let d=0;d<c.length;d++){const f=c[d];if((u==null||!Object.hasOwn(u,f))&&!((Array.isArray(u)||r.isArguments(u))&&n.isIndex(f)&&f<u.length))return!1;u=u[f]}return!0}e.has=a})(Vee)),Vee}var tze;function hJn(){return tze||(tze=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});const t=RSt(),n=lSe(),r=dJn(),s=uSe(),a=pJn();function i(l,c){switch(typeof l){case"object":{Object.is(l?.valueOf(),-0)&&(l="-0");break}case"number":{l=n.toKey(l);break}}return c=r.cloneDeep(c),function(u){const d=s.get(u,l);return d===void 0?a.has(u,l):c===void 0?d===void 0:t.isMatch(d,c)}}e.matchesProperty=i})(Bee)),Bee}var nze;function mJn(){return nze||(nze=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});const t=jSt(),n=nJn(),r=cJn(),s=hJn();function a(i){if(i==null)return t.identity;switch(typeof i){case"function":return i;case"object":return Array.isArray(i)&&i.length===2?s.matchesProperty(i[0],i[1]):r.matches(i);case"string":case"symbol":case"number":return n.property(i)}}e.iteratee=a})(_ee)),_ee}var rze;function gJn(){return rze||(rze=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});const t=XKn(),n=KKn(),r=jSt(),s=tJn(),a=mJn();function i(l,c=r.identity){return s.isArrayLikeObject(l)?t.uniqBy(Array.from(l),n.ary(a.iteratee(c),1)):[]}e.uniqBy=i})(vee)),vee}var Zee,sze;function vJn(){return sze||(sze=1,Zee=gJn().uniqBy),Zee}var yJn=vJn();const aze=Tc(yJn);function bJn(e,t,n){return t===!0?aze(e,n):typeof t=="function"?aze(e,t):e}var hSe=g.createContext(null),xJn=e=>e,so=()=>{var e=g.useContext(hSe);return e?e.store.dispatch:xJn},o8=()=>{},wJn=()=>o8,SJn=(e,t)=>e===t;function Kn(e){var t=g.useContext(hSe),n=g.useMemo(()=>t?r=>{if(r!=null)return e(r)}:o8,[t,e]);return gxe.useSyncExternalStoreWithSelector(t?t.subscription.addNestedSub:wJn,t?t.store.getState:o8,t?t.store.getState:o8,n,SJn)}var Gee={},Qee={},Yee={},ize;function kJn(){return ize||(ize=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});function t(r){return typeof r=="symbol"?1:r===null?2:r===void 0?3:r!==r?4:0}const n=(r,s,a)=>{if(r!==s){const i=t(r),l=t(s);if(i===l&&i===0){if(r<s)return a==="desc"?1:-1;if(r>s)return a==="desc"?-1:1}return a==="desc"?l-i:i-l}return 0};e.compareValues=n})(Yee)),Yee}var Xee={},Kee={},oze;function DSt(){return oze||(oze=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});function t(n){return typeof n=="symbol"||n instanceof Symbol}e.isSymbol=t})(Kee)),Kee}var lze;function OJn(){return lze||(lze=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});const t=DSt(),n=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,r=/^\w*$/;function s(a,i){return Array.isArray(a)?!1:typeof a=="number"||typeof a=="boolean"||a==null||t.isSymbol(a)?!0:typeof a=="string"&&(r.test(a)||!n.test(a))||i!=null&&Object.hasOwn(i,a)}e.isKey=s})(Xee)),Xee}var cze;function _Jn(){return cze||(cze=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});const t=kJn(),n=OJn(),r=cSe();function s(a,i,l,c){if(a==null)return[];l=c?void 0:l,Array.isArray(a)||(a=Object.values(a)),Array.isArray(i)||(i=i==null?[null]:[i]),i.length===0&&(i=[null]),Array.isArray(l)||(l=l==null?[]:[l]),l=l.map(h=>String(h));const u=(h,m)=>{let v=h;for(let y=0;y<m.length&&v!=null;++y)v=v[m[y]];return v},d=(h,m)=>m==null||h==null?m:typeof h=="object"&&"key"in h?Object.hasOwn(m,h.key)?m[h.key]:u(m,h.path):typeof h=="function"?h(m):Array.isArray(h)?u(m,h):typeof m=="object"?m[h]:m,f=i.map(h=>(Array.isArray(h)&&h.length===1&&(h=h[0]),h==null||typeof h=="function"||Array.isArray(h)||n.isKey(h)?h:{key:h,path:r.toPath(h)}));return a.map(h=>({original:h,criteria:f.map(m=>d(m,h))})).slice().sort((h,m)=>{for(let v=0;v<f.length;v++){const y=t.compareValues(h.criteria[v],m.criteria[v],l[v]);if(y!==0)return y}return 0}).map(h=>h.original)}e.orderBy=s})(Qee)),Qee}var Jee={},uze;function CJn(){return uze||(uze=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});function t(n,r=1){const s=[],a=Math.floor(r),i=(l,c)=>{for(let u=0;u<l.length;u++){const d=l[u];Array.isArray(d)&&c<a?i(d,c+1):s.push(d)}};return i(n,0),s}e.flatten=t})(Jee)),Jee}var ete={},dze;function LSt(){return dze||(dze=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});const t=MSt(),n=TSt(),r=NSt(),s=ASt();function a(i,l,c){return r.isObject(c)&&(typeof l=="number"&&n.isArrayLike(c)&&t.isIndex(l)&&l<c.length||typeof l=="string"&&l in c)?s.isEqualsSameValueZero(c[l],i):!1}e.isIterateeCall=a})(ete)),ete}var fze;function EJn(){return fze||(fze=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});const t=_Jn(),n=CJn(),r=LSt();function s(a,...i){const l=i.length;return l>1&&r.isIterateeCall(a,i[0],i[1])?i=[]:l>2&&r.isIterateeCall(i[0],i[1],i[2])&&(i=[i[0]]),t.orderBy(a,n.flatten(i),["asc"])}e.sortBy=s})(Gee)),Gee}var tte,pze;function jJn(){return pze||(pze=1,tte=EJn().sortBy),tte}var TJn=jJn();const iH=Tc(TJn);var FSt=e=>e.legend.settings,NJn=e=>e.legend.size,IJn=e=>e.legend.payload;at([IJn,FSt],(e,t)=>{var{itemSorter:n}=t,r=e.flat(1);return n?iH(r,n):r});var D6=1;function AJn(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],[t,n]=g.useState({height:0,left:0,top:0,width:0}),r=g.useCallback(s=>{if(s!=null){var a=s.getBoundingClientRect(),i={height:a.height,left:a.left,top:a.top,width:a.width};(Math.abs(i.height-t.height)>D6||Math.abs(i.left-t.left)>D6||Math.abs(i.top-t.top)>D6||Math.abs(i.width-t.width)>D6)&&n({height:i.height,left:i.left,top:i.top,width:i.width})}},[t.width,t.height,t.top,t.left,...e]);return[t,r]}function dc(e){return`Minified Redux error #${e}; visit https://redux.js.org/Errors?code=${e} for the full message or use the non-minified dev environment for full errors. `}var RJn=typeof Symbol=="function"&&Symbol.observable||"@@observable",hze=RJn,nte=()=>Math.random().toString(36).substring(7).split("").join("."),PJn={INIT:`@@redux/INIT${nte()}`,REPLACE:`@@redux/REPLACE${nte()}`,PROBE_UNKNOWN_ACTION:()=>`@@redux/PROBE_UNKNOWN_ACTION${nte()}`},G7=PJn;function mSe(e){if(typeof e!="object"||e===null)return!1;let t=e;for(;Object.getPrototypeOf(t)!==null;)t=Object.getPrototypeOf(t);return Object.getPrototypeOf(e)===t||Object.getPrototypeOf(e)===null}function gSe(e,t,n){if(typeof e!="function")throw new Error(dc(2));if(typeof t=="function"&&typeof n=="function"||typeof n=="function"&&typeof arguments[3]=="function")throw new Error(dc(0));if(typeof t=="function"&&typeof n>"u"&&(n=t,t=void 0),typeof n<"u"){if(typeof n!="function")throw new Error(dc(1));return n(gSe)(e,t)}let r=e,s=t,a=new Map,i=a,l=0,c=!1;function u(){i===a&&(i=new Map,a.forEach((y,b)=>{i.set(b,y)}))}function d(){if(c)throw new Error(dc(3));return s}function f(y){if(typeof y!="function")throw new Error(dc(4));if(c)throw new Error(dc(5));let b=!0;u();const S=l++;return i.set(S,y),function(){if(b){if(c)throw new Error(dc(6));b=!1,u(),i.delete(S),a=null}}}function p(y){if(!mSe(y))throw new Error(dc(7));if(typeof y.type>"u")throw new Error(dc(8));if(typeof y.type!="string")throw new Error(dc(17));if(c)throw new Error(dc(9));try{c=!0,s=r(s,y)}finally{c=!1}return(a=i).forEach(S=>{S()}),y}function h(y){if(typeof y!="function")throw new Error(dc(10));r=y,p({type:G7.REPLACE})}function m(){const y=f;return{subscribe(b){if(typeof b!="object"||b===null)throw new Error(dc(11));function S(){const k=b;k.next&&k.next(d())}return S(),{unsubscribe:y(S)}},[hze](){return this}}}return p({type:G7.INIT}),{dispatch:p,subscribe:f,getState:d,replaceReducer:h,[hze]:m}}function $Jn(e){Object.keys(e).forEach(t=>{const n=e[t];if(typeof n(void 0,{type:G7.INIT})>"u")throw new Error(dc(12));if(typeof n(void 0,{type:G7.PROBE_UNKNOWN_ACTION()})>"u")throw new Error(dc(13))})}function zSt(e){const t=Object.keys(e),n={};for(let a=0;a<t.length;a++){const i=t[a];typeof e[i]=="function"&&(n[i]=e[i])}const r=Object.keys(n);let s;try{$Jn(n)}catch(a){s=a}return function(i={},l){if(s)throw s;let c=!1;const u={};for(let d=0;d<r.length;d++){const f=r[d],p=n[f],h=i[f],m=p(h,l);if(typeof m>"u")throw l&&l.type,new Error(dc(14));u[f]=m,c=c||m!==h}return c=c||r.length!==Object.keys(i).length,c?u:i}}function mze(e,t){return function(...n){return t(e.apply(this,n))}}function gze(e,t){if(typeof e=="function")return mze(e,t);if(typeof e!="object"||e===null)throw new Error(dc(16));const n={};for(const r in e){const s=e[r];typeof s=="function"&&(n[r]=mze(s,t))}return n}function hM(...e){return e.length===0?t=>t:e.length===1?e[0]:e.reduce((t,n)=>(...r)=>t(n(...r)))}function BSt(...e){return t=>(n,r)=>{const s=t(n,r);let a=()=>{throw new Error(dc(15))};const i={getState:s.getState,dispatch:(c,...u)=>a(c,...u)},l=e.map(c=>c(i));return a=hM(...l)(s.dispatch),{...s,dispatch:a}}}function USt(e){return mSe(e)&&"type"in e&&typeof e.type=="string"}var qSt=Symbol.for("immer-nothing"),vze=Symbol.for("immer-draftable"),Cd=Symbol.for("immer-state");function og(e,...t){throw new Error(`[Immer] minified error nr: ${e}. Full error at: https://bit.ly/3cXEKWf`)}var wp=Object,NT=wp.getPrototypeOf,Q7="constructor",oH="prototype",eme="configurable",Y7="enumerable",l8="writable",mM="value",jx=e=>!!e&&!!e[Cd];function Ng(e){return e?VSt(e)||cH(e)||!!e[vze]||!!e[Q7]?.[vze]||uH(e)||dH(e):!1}var MJn=wp[oH][Q7].toString(),yze=new WeakMap;function VSt(e){if(!e||!vSe(e))return!1;const t=NT(e);if(t===null||t===wp[oH])return!0;const n=wp.hasOwnProperty.call(t,Q7)&&t[Q7];if(n===Object)return!0;if(!OE(n))return!1;let r=yze.get(n);return r===void 0&&(r=Function.toString.call(n),yze.set(n,r)),r===MJn}function lH(e,t,n=!0){E3(e)===0?(n?Reflect.ownKeys(e):wp.keys(e)).forEach(s=>{t(s,e[s],e)}):e.forEach((r,s)=>t(s,r,e))}function E3(e){const t=e[Cd];return t?t.type_:cH(e)?1:uH(e)?2:dH(e)?3:0}var bze=(e,t,n=E3(e))=>n===2?e.has(t):wp[oH].hasOwnProperty.call(e,t),tme=(e,t,n=E3(e))=>n===2?e.get(t):e[t],X7=(e,t,n,r=E3(e))=>{r===2?e.set(t,n):r===3?e.add(n):e[t]=n};function DJn(e,t){return e===t?e!==0||1/e===1/t:e!==e&&t!==t}var cH=Array.isArray,uH=e=>e instanceof Map,dH=e=>e instanceof Set,vSe=e=>typeof e=="object",OE=e=>typeof e=="function",rte=e=>typeof e=="boolean";function LJn(e){const t=+e;return Number.isInteger(t)&&String(t)===e}var Lb=e=>e.copy_||e.base_,ySe=e=>e.modified_?e.copy_:e.base_;function nme(e,t){if(uH(e))return new Map(e);if(dH(e))return new Set(e);if(cH(e))return Array[oH].slice.call(e);const n=VSt(e);if(t===!0||t==="class_only"&&!n){const r=wp.getOwnPropertyDescriptors(e);delete r[Cd];let s=Reflect.ownKeys(r);for(let a=0;a<s.length;a++){const i=s[a],l=r[i];l[l8]===!1&&(l[l8]=!0,l[eme]=!0),(l.get||l.set)&&(r[i]={[eme]:!0,[l8]:!0,[Y7]:l[Y7],[mM]:e[i]})}return wp.create(NT(e),r)}else{const r=NT(e);if(r!==null&&n)return{...e};const s=wp.create(r);return wp.assign(s,e)}}function bSe(e,t=!1){return fH(e)||jx(e)||!Ng(e)||(E3(e)>1&&wp.defineProperties(e,{set:L6,add:L6,clear:L6,delete:L6}),wp.freeze(e),t&&lH(e,(n,r)=>{bSe(r,!0)},!1)),e}function FJn(){og(2)}var L6={[mM]:FJn};function fH(e){return e===null||!vSe(e)?!0:wp.isFrozen(e)}var K7="MapSet",rme="Patches",xze="ArrayMethods",HSt={};function VO(e){const t=HSt[e];return t||og(0,e),t}var wze=e=>!!HSt[e],gM,WSt=()=>gM,zJn=(e,t)=>({drafts_:[],parent_:e,immer_:t,canAutoFreeze_:!0,unfinalizedDrafts_:0,handledSet_:new Set,processedForPatches_:new Set,mapSetPlugin_:wze(K7)?VO(K7):void 0,arrayMethodsPlugin_:wze(xze)?VO(xze):void 0});function Sze(e,t){t&&(e.patchPlugin_=VO(rme),e.patches_=[],e.inversePatches_=[],e.patchListener_=t)}function sme(e){ame(e),e.drafts_.forEach(BJn),e.drafts_=null}function ame(e){e===gM&&(gM=e.parent_)}var kze=e=>gM=zJn(gM,e);function BJn(e){const t=e[Cd];t.type_===0||t.type_===1?t.revoke_():t.revoked_=!0}function Oze(e,t){t.unfinalizedDrafts_=t.drafts_.length;const n=t.drafts_[0];if(e!==void 0&&e!==n){n[Cd].modified_&&(sme(t),og(4)),Ng(e)&&(e=_ze(t,e));const{patchPlugin_:s}=t;s&&s.generateReplacementPatches_(n[Cd].base_,e,t)}else e=_ze(t,n);return UJn(t,e,!0),sme(t),t.patches_&&t.patchListener_(t.patches_,t.inversePatches_),e!==qSt?e:void 0}function _ze(e,t){if(fH(t))return t;const n=t[Cd];if(!n)return J7(t,e.handledSet_,e);if(!pH(n,e))return t;if(!n.modified_)return n.base_;if(!n.finalized_){const{callbacks_:r}=n;if(r)for(;r.length>0;)r.pop()(e);QSt(n,e)}return n.copy_}function UJn(e,t,n=!1){!e.parent_&&e.immer_.autoFreeze_&&e.canAutoFreeze_&&bSe(t,n)}function ZSt(e){e.finalized_=!0,e.scope_.unfinalizedDrafts_--}var pH=(e,t)=>e.scope_===t,qJn=[];function GSt(e,t,n,r){const s=Lb(e),a=e.type_;if(r!==void 0&&tme(s,r,a)===t){X7(s,r,n,a);return}if(!e.draftLocations_){const l=e.draftLocations_=new Map;lH(s,(c,u)=>{if(jx(u)){const d=l.get(u)||[];d.push(c),l.set(u,d)}})}const i=e.draftLocations_.get(t)??qJn;for(const l of i)X7(s,l,n,a)}function VJn(e,t,n){e.callbacks_.push(function(s){const a=t;if(!a||!pH(a,s))return;s.mapSetPlugin_?.fixSetContents(a);const i=ySe(a);GSt(e,a.draft_??a,i,n),QSt(a,s)})}function QSt(e,t){if(e.modified_&&!e.finalized_&&(e.type_===3||e.type_===1&&e.allIndicesReassigned_||(e.assigned_?.size??0)>0)){const{patchPlugin_:r}=t;if(r){const s=r.getPath(e);s&&r.generatePatches_(e,s,t)}ZSt(e)}}function HJn(e,t,n){const{scope_:r}=e;if(jx(n)){const s=n[Cd];pH(s,r)&&s.callbacks_.push(function(){c8(e);const i=ySe(s);GSt(e,n,i,t)})}else Ng(n)&&e.callbacks_.push(function(){const a=Lb(e);e.type_===3?a.has(n)&&J7(n,r.handledSet_,r):tme(a,t,e.type_)===n&&r.drafts_.length>1&&(e.assigned_.get(t)??!1)===!0&&e.copy_&&J7(tme(e.copy_,t,e.type_),r.handledSet_,r)})}function J7(e,t,n){return!n.immer_.autoFreeze_&&n.unfinalizedDrafts_<1||jx(e)||t.has(e)||!Ng(e)||fH(e)||(t.add(e),lH(e,(r,s)=>{if(jx(s)){const a=s[Cd];if(pH(a,n)){const i=ySe(a);X7(e,r,i,e.type_),ZSt(a)}}else Ng(s)&&J7(s,t,n)})),e}function WJn(e,t){const n=cH(e),r={type_:n?1:0,scope_:t?t.scope_:WSt(),modified_:!1,finalized_:!1,assigned_:void 0,parent_:t,base_:e,draft_:null,copy_:null,revoke_:null,isManual_:!1,callbacks_:void 0};let s=r,a=eB;n&&(s=[r],a=vM);const{revoke:i,proxy:l}=Proxy.revocable(s,a);return r.draft_=l,r.revoke_=i,[l,r]}var eB={get(e,t){if(t===Cd)return e;let n=e.scope_.arrayMethodsPlugin_;const r=e.type_===1&&typeof t=="string";if(r&&n?.isArrayOperationMethod(t))return n.createMethodInterceptor(e,t);const s=Lb(e);if(!bze(s,t,e.type_))return ZJn(e,s,t);const a=s[t];if(e.finalized_||!Ng(a)||r&&e.operationMethod&&n?.isMutatingArrayMethod(e.operationMethod)&&LJn(t))return a;if(a===ste(e.base_,t)){c8(e);const i=e.type_===1?+t:t,l=ome(e.scope_,a,e,i);return e.copy_[i]=l}return a},has(e,t){return t in Lb(e)},ownKeys(e){return Reflect.ownKeys(Lb(e))},set(e,t,n){const r=YSt(Lb(e),t);if(r?.set)return r.set.call(e.draft_,n),!0;if(!e.modified_){const s=ste(Lb(e),t),a=s?.[Cd];if(a&&a.base_===n)return e.copy_[t]=n,e.assigned_.set(t,!1),!0;if(DJn(n,s)&&(n!==void 0||bze(e.base_,t,e.type_)))return!0;c8(e),ime(e)}return e.copy_[t]===n&&(n!==void 0||t in e.copy_)||Number.isNaN(n)&&Number.isNaN(e.copy_[t])||(e.copy_[t]=n,e.assigned_.set(t,!0),HJn(e,t,n)),!0},deleteProperty(e,t){return c8(e),ste(e.base_,t)!==void 0||t in e.base_?(e.assigned_.set(t,!1),ime(e)):e.assigned_.delete(t),e.copy_&&delete e.copy_[t],!0},getOwnPropertyDescriptor(e,t){const n=Lb(e),r=Reflect.getOwnPropertyDescriptor(n,t);return r&&{[l8]:!0,[eme]:e.type_!==1||t!=="length",[Y7]:r[Y7],[mM]:n[t]}},defineProperty(){og(11)},getPrototypeOf(e){return NT(e.base_)},setPrototypeOf(){og(12)}},vM={};for(let e in eB){let t=eB[e];vM[e]=function(){const n=arguments;return n[0]=n[0][0],t.apply(this,n)}}vM.deleteProperty=function(e,t){return vM.set.call(this,e,t,void 0)};vM.set=function(e,t,n){return eB.set.call(this,e[0],t,n,e[0])};function ste(e,t){const n=e[Cd];return(n?Lb(n):e)[t]}function ZJn(e,t,n){const r=YSt(t,n);return r?mM in r?r[mM]:r.get?.call(e.draft_):void 0}function YSt(e,t){if(!(t in e))return;let n=NT(e);for(;n;){const r=Object.getOwnPropertyDescriptor(n,t);if(r)return r;n=NT(n)}}function ime(e){e.modified_||(e.modified_=!0,e.parent_&&ime(e.parent_))}function c8(e){e.copy_||(e.assigned_=new Map,e.copy_=nme(e.base_,e.scope_.immer_.useStrictShallowCopy_))}var GJn=class{constructor(t){this.autoFreeze_=!0,this.useStrictShallowCopy_=!1,this.useStrictIteration_=!1,this.produce=(n,r,s)=>{if(OE(n)&&!OE(r)){const i=r;r=n;const l=this;return function(u=i,...d){return l.produce(u,f=>r.call(this,f,...d))}}OE(r)||og(6),s!==void 0&&!OE(s)&&og(7);let a;if(Ng(n)){const i=kze(this),l=ome(i,n,void 0);let c=!0;try{a=r(l),c=!1}finally{c?sme(i):ame(i)}return Sze(i,s),Oze(a,i)}else if(!n||!vSe(n)){if(a=r(n),a===void 0&&(a=n),a===qSt&&(a=void 0),this.autoFreeze_&&bSe(a,!0),s){const i=[],l=[];VO(rme).generateReplacementPatches_(n,a,{patches_:i,inversePatches_:l}),s(i,l)}return a}else og(1,n)},this.produceWithPatches=(n,r)=>{if(OE(n))return(l,...c)=>this.produceWithPatches(l,u=>n(u,...c));let s,a;return[this.produce(n,r,(l,c)=>{s=l,a=c}),s,a]},rte(t?.autoFreeze)&&this.setAutoFreeze(t.autoFreeze),rte(t?.useStrictShallowCopy)&&this.setUseStrictShallowCopy(t.useStrictShallowCopy),rte(t?.useStrictIteration)&&this.setUseStrictIteration(t.useStrictIteration)}createDraft(t){Ng(t)||og(8),jx(t)&&(t=Bh(t));const n=kze(this),r=ome(n,t,void 0);return r[Cd].isManual_=!0,ame(n),r}finishDraft(t,n){const r=t&&t[Cd];(!r||!r.isManual_)&&og(9);const{scope_:s}=r;return Sze(s,n),Oze(void 0,s)}setAutoFreeze(t){this.autoFreeze_=t}setUseStrictShallowCopy(t){this.useStrictShallowCopy_=t}setUseStrictIteration(t){this.useStrictIteration_=t}shouldUseStrictIteration(){return this.useStrictIteration_}applyPatches(t,n){let r;for(r=n.length-1;r>=0;r--){const a=n[r];if(a.path.length===0&&a.op==="replace"){t=a.value;break}}r>-1&&(n=n.slice(r+1));const s=VO(rme).applyPatches_;return jx(t)?s(t,n):this.produce(t,a=>s(a,n))}};function ome(e,t,n,r){const[s,a]=uH(t)?VO(K7).proxyMap_(t,n):dH(t)?VO(K7).proxySet_(t,n):WJn(t,n);return(n?.scope_??WSt()).drafts_.push(s),a.callbacks_=n?.callbacks_??[],a.key_=r,n&&r!==void 0?VJn(n,a,r):a.callbacks_.push(function(c){c.mapSetPlugin_?.fixSetContents(a);const{patchPlugin_:u}=c;a.modified_&&u&&u.generatePatches_(a,[],c)}),s}function Bh(e){return jx(e)||og(10,e),XSt(e)}function XSt(e){if(!Ng(e)||fH(e))return e;const t=e[Cd];let n,r=!0;if(t){if(!t.modified_)return t.base_;t.finalized_=!0,n=nme(e,t.scope_.immer_.useStrictShallowCopy_),r=t.scope_.immer_.shouldUseStrictIteration()}else n=nme(e,!0);return lH(n,(s,a)=>{X7(n,s,XSt(a))},r),t&&(t.finalized_=!1),n}var QJn=new GJn,KSt=QJn.produce;function JSt(e){return({dispatch:n,getState:r})=>s=>a=>typeof a=="function"?a(n,r,e):s(a)}var YJn=JSt(),XJn=JSt,KJn=typeof window<"u"&&window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__?window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__:function(){if(arguments.length!==0)return typeof arguments[0]=="object"?hM:hM.apply(null,arguments)};function Vp(e,t){function n(...r){if(t){let s=t(...r);if(!s)throw new Error(Tp(0));return{type:e,payload:s.payload,..."meta"in s&&{meta:s.meta},..."error"in s&&{error:s.error}}}return{type:e,payload:r[0]}}return n.toString=()=>`${e}`,n.type=e,n.match=r=>USt(r)&&r.type===e,n}var ekt=class p2 extends Array{constructor(...t){super(...t),Object.setPrototypeOf(this,p2.prototype)}static get[Symbol.species](){return p2}concat(...t){return super.concat.apply(this,t)}prepend(...t){return t.length===1&&Array.isArray(t[0])?new p2(...t[0].concat(this)):new p2(...t.concat(this))}};function Cze(e){return Ng(e)?KSt(e,()=>{}):e}function F6(e,t,n){return e.has(t)?e.get(t):e.set(t,n(t)).get(t)}function JJn(e){return typeof e=="boolean"}var eer=()=>function(t){const{thunk:n=!0,immutableCheck:r=!0,serializableCheck:s=!0,actionCreatorCheck:a=!0}=t??{};let i=new ekt;return n&&(JJn(n)?i.push(YJn):i.push(XJn(n.extraArgument))),i},tkt="RTK_autoBatch",Wi=()=>e=>({payload:e,meta:{[tkt]:!0}}),Eze=e=>t=>{setTimeout(t,e)},nkt=(e={type:"raf"})=>t=>(...n)=>{const r=t(...n);let s=!0,a=!1,i=!1;const l=new Set,c=e.type==="tick"?queueMicrotask:e.type==="raf"?typeof window<"u"&&window.requestAnimationFrame?window.requestAnimationFrame:Eze(10):e.type==="callback"?e.queueNotification:Eze(e.timeout),u=()=>{i=!1,a&&(a=!1,l.forEach(d=>d()))};return Object.assign({},r,{subscribe(d){const f=()=>s&&d(),p=r.subscribe(f);return l.add(d),()=>{p(),l.delete(d)}},dispatch(d){try{return s=!d?.meta?.[tkt],a=!s,a&&(i||(i=!0,c(u))),r.dispatch(d)}finally{s=!0}}})},ter=e=>function(n){const{autoBatch:r=!0}=n??{};let s=new ekt(e);return r&&s.push(nkt(typeof r=="object"?r:void 0)),s};function ner(e){const t=eer(),{reducer:n=void 0,middleware:r,devTools:s=!0,preloadedState:a=void 0,enhancers:i=void 0}=e||{};let l;if(typeof n=="function")l=n;else if(mSe(n))l=zSt(n);else throw new Error(Tp(1));let c;typeof r=="function"?c=r(t):c=t();let u=hM;s&&(u=KJn({trace:!1,...typeof s=="object"&&s}));const d=BSt(...c),f=ter(d);let p=typeof i=="function"?i(f):f();const h=u(...p);return gSe(l,a,h)}function rkt(e){const t={},n=[];let r;const s={addCase(a,i){const l=typeof a=="string"?a:a.type;if(!l)throw new Error(Tp(28));if(l in t)throw new Error(Tp(29));return t[l]=i,s},addAsyncThunk(a,i){return i.pending&&(t[a.pending.type]=i.pending),i.rejected&&(t[a.rejected.type]=i.rejected),i.fulfilled&&(t[a.fulfilled.type]=i.fulfilled),i.settled&&n.push({matcher:a.settled,reducer:i.settled}),s},addMatcher(a,i){return n.push({matcher:a,reducer:i}),s},addDefaultCase(a){return r=a,s}};return e(s),[t,n,r]}function rer(e){return typeof e=="function"}function ser(e,t){let[n,r,s]=rkt(t),a;if(rer(e))a=()=>Cze(e());else{const l=Cze(e);a=()=>l}function i(l=a(),c){let u=[n[c.type],...r.filter(({matcher:d})=>d(c)).map(({reducer:d})=>d)];return u.filter(d=>!!d).length===0&&(u=[s]),u.reduce((d,f)=>{if(f)if(jx(d)){const h=f(d,c);return h===void 0?d:h}else{if(Ng(d))return KSt(d,p=>f(p,c));{const p=f(d,c);if(p===void 0){if(d===null)return d;throw Error("A case reducer on a non-draftable value must not return undefined")}return p}}return d},l)}return i.getInitialState=a,i}var aer="ModuleSymbhasOwnPr-0123456789ABCDEFGHNRVfgctiUvz_KqYTJkLxpZXIjQW",ier=(e=21)=>{let t="",n=e;for(;n--;)t+=aer[Math.random()*64|0];return t},oer=Symbol.for("rtk-slice-createasyncthunk");function ler(e,t){return`${e}/${t}`}function cer({creators:e}={}){const t=e?.asyncThunk?.[oer];return function(r){const{name:s,reducerPath:a=s}=r;if(!s)throw new Error(Tp(11));const i=(typeof r.reducers=="function"?r.reducers(der()):r.reducers)||{},l=Object.keys(i),c={sliceCaseReducersByName:{},sliceCaseReducersByType:{},actionCreators:{},sliceMatchers:[]},u={addCase(w,k){const _=typeof w=="string"?w:w.type;if(!_)throw new Error(Tp(12));if(_ in c.sliceCaseReducersByType)throw new Error(Tp(13));return c.sliceCaseReducersByType[_]=k,u},addMatcher(w,k){return c.sliceMatchers.push({matcher:w,reducer:k}),u},exposeAction(w,k){return c.actionCreators[w]=k,u},exposeCaseReducer(w,k){return c.sliceCaseReducersByName[w]=k,u}};l.forEach(w=>{const k=i[w],_={reducerName:w,type:ler(s,w),createNotation:typeof r.reducers=="function"};per(k)?mer(_,k,u,t):fer(_,k,u)});function d(){const[w={},k=[],_=void 0]=typeof r.extraReducers=="function"?rkt(r.extraReducers):[r.extraReducers],C={...w,...c.sliceCaseReducersByType};return ser(r.initialState,E=>{for(let j in C)E.addCase(j,C[j]);for(let j of c.sliceMatchers)E.addMatcher(j.matcher,j.reducer);for(let j of k)E.addMatcher(j.matcher,j.reducer);_&&E.addDefaultCase(_)})}const f=w=>w,p=new Map,h=new WeakMap;let m;function v(w,k){return m||(m=d()),m(w,k)}function y(){return m||(m=d()),m.getInitialState()}function b(w,k=!1){function _(E){let j=E[w];return typeof j>"u"&&k&&(j=F6(h,_,y)),j}function C(E=f){const j=F6(p,k,()=>new WeakMap);return F6(j,E,()=>{const N={};for(const[I,R]of Object.entries(r.selectors??{}))N[I]=uer(R,E,()=>F6(h,E,y),k);return N})}return{reducerPath:w,getSelectors:C,get selectors(){return C(_)},selectSlice:_}}const S={name:s,reducer:v,actions:c.actionCreators,caseReducers:c.sliceCaseReducersByName,getInitialState:y,...b(a),injectInto(w,{reducerPath:k,..._}={}){const C=k??a;return w.inject({reducerPath:C,reducer:v},_),{...S,...b(C,!0)}}};return S}}function uer(e,t,n,r){function s(a,...i){let l=t(a);return typeof l>"u"&&r&&(l=n()),e(l,...i)}return s.unwrapped=e,s}var Hu=cer();function der(){function e(t,n){return{_reducerDefinitionType:"asyncThunk",payloadCreator:t,...n}}return e.withTypes=()=>e,{reducer(t){return Object.assign({[t.name](...n){return t(...n)}}[t.name],{_reducerDefinitionType:"reducer"})},preparedReducer(t,n){return{_reducerDefinitionType:"reducerWithPrepare",prepare:t,reducer:n}},asyncThunk:e}}function fer({type:e,reducerName:t,createNotation:n},r,s){let a,i;if("reducer"in r){if(n&&!her(r))throw new Error(Tp(17));a=r.reducer,i=r.prepare}else a=r;s.addCase(e,a).exposeCaseReducer(t,a).exposeAction(t,i?Vp(e,i):Vp(e))}function per(e){return e._reducerDefinitionType==="asyncThunk"}function her(e){return e._reducerDefinitionType==="reducerWithPrepare"}function mer({type:e,reducerName:t},n,r,s){if(!s)throw new Error(Tp(18));const{payloadCreator:a,fulfilled:i,pending:l,rejected:c,settled:u,options:d}=n,f=s(e,a,d);r.exposeAction(t,f),i&&r.addCase(f.fulfilled,i),l&&r.addCase(f.pending,l),c&&r.addCase(f.rejected,c),u&&r.addMatcher(f.settled,u),r.exposeCaseReducer(t,{fulfilled:i||z6,pending:l||z6,rejected:c||z6,settled:u||z6})}function z6(){}var ger="task",skt="listener",akt="completed",xSe="cancelled",ver=`task-${xSe}`,yer=`task-${akt}`,lme=`${skt}-${xSe}`,ber=`${skt}-${akt}`,hH=class{constructor(e){this.code=e,this.message=`${ger} ${xSe} (reason: ${e})`}name="TaskAbortError";message},wSe=(e,t)=>{if(typeof e!="function")throw new TypeError(Tp(32))},tB=()=>{},ikt=(e,t=tB)=>(e.catch(t),e),okt=(e,t)=>(e.addEventListener("abort",t,{once:!0}),()=>e.removeEventListener("abort",t)),Gk=e=>{if(e.aborted)throw new hH(e.reason)};function lkt(e,t){let n=tB;return new Promise((r,s)=>{const a=()=>s(new hH(e.reason));if(e.aborted){a();return}n=okt(e,a),t.finally(()=>n()).then(r,s)}).finally(()=>{n=tB})}var xer=async(e,t)=>{try{return await Promise.resolve(),{status:"ok",value:await e()}}catch(n){return{status:n instanceof hH?"cancelled":"rejected",error:n}}finally{t?.()}},nB=e=>t=>ikt(lkt(e,t).then(n=>(Gk(e),n))),ckt=e=>{const t=nB(e);return n=>t(new Promise(r=>setTimeout(r,n)))},{assign:Tj}=Object,jze={},mH="listenerMiddleware",wer=(e,t)=>{const n=r=>okt(e,()=>r.abort(e.reason));return(r,s)=>{wSe(r);const a=new AbortController;n(a);const i=xer(async()=>{Gk(e),Gk(a.signal);const l=await r({pause:nB(a.signal),delay:ckt(a.signal),signal:a.signal});return Gk(a.signal),l},()=>a.abort(yer));return s?.autoJoin&&t.push(i.catch(tB)),{result:nB(e)(i),cancel(){a.abort(ver)}}}},Ser=(e,t)=>{const n=async(r,s)=>{Gk(t);let a=()=>{};const l=[new Promise((c,u)=>{let d=e({predicate:r,effect:(f,p)=>{p.unsubscribe(),c([f,p.getState(),p.getOriginalState()])}});a=()=>{d(),u()}})];s!=null&&l.push(new Promise(c=>setTimeout(c,s,null)));try{const c=await lkt(t,Promise.race(l));return Gk(t),c}finally{a()}};return(r,s)=>ikt(n(r,s))},ukt=e=>{let{type:t,actionCreator:n,matcher:r,predicate:s,effect:a}=e;if(t)s=Vp(t).match;else if(n)t=n.type,s=n.match;else if(r)s=r;else if(!s)throw new Error(Tp(21));return wSe(a),{predicate:s,type:t,effect:a}},dkt=Tj(e=>{const{type:t,predicate:n,effect:r}=ukt(e);return{id:ier(),effect:r,type:t,predicate:n,pending:new Set,unsubscribe:()=>{throw new Error(Tp(22))}}},{withTypes:()=>dkt}),Tze=(e,t)=>{const{type:n,effect:r,predicate:s}=ukt(t);return Array.from(e.values()).find(a=>(typeof n=="string"?a.type===n:a.predicate===s)&&a.effect===r)},cme=e=>{e.pending.forEach(t=>{t.abort(lme)})},ker=(e,t)=>()=>{for(const n of t.keys())cme(n);e.clear()},Nze=(e,t,n)=>{try{e(t,n)}catch(r){setTimeout(()=>{throw r},0)}},fkt=Tj(Vp(`${mH}/add`),{withTypes:()=>fkt}),Oer=Vp(`${mH}/removeAll`),pkt=Tj(Vp(`${mH}/remove`),{withTypes:()=>pkt}),_er=(...e)=>{console.error(`${mH}/error`,...e)},j3=(e={})=>{const t=new Map,n=new Map,r=h=>{const m=n.get(h)??0;n.set(h,m+1)},s=h=>{const m=n.get(h)??1;m===1?n.delete(h):n.set(h,m-1)},{extra:a,onError:i=_er}=e;wSe(i);const l=h=>(h.unsubscribe=()=>t.delete(h.id),t.set(h.id,h),m=>{h.unsubscribe(),m?.cancelActive&&cme(h)}),c=h=>{const m=Tze(t,h)??dkt(h);return l(m)};Tj(c,{withTypes:()=>c});const u=h=>{const m=Tze(t,h);return m&&(m.unsubscribe(),h.cancelActive&&cme(m)),!!m};Tj(u,{withTypes:()=>u});const d=async(h,m,v,y)=>{const b=new AbortController,S=Ser(c,b.signal),w=[];try{h.pending.add(b),r(h),await Promise.resolve(h.effect(m,Tj({},v,{getOriginalState:y,condition:(k,_)=>S(k,_).then(Boolean),take:S,delay:ckt(b.signal),pause:nB(b.signal),extra:a,signal:b.signal,fork:wer(b.signal,w),unsubscribe:h.unsubscribe,subscribe:()=>{t.set(h.id,h)},cancelActiveListeners:()=>{h.pending.forEach((k,_,C)=>{k!==b&&(k.abort(lme),C.delete(k))})},cancel:()=>{b.abort(lme),h.pending.delete(b)},throwIfCancelled:()=>{Gk(b.signal)}})))}catch(k){k instanceof hH||Nze(i,k,{raisedBy:"effect"})}finally{await Promise.all(w),b.abort(ber),s(h),h.pending.delete(b)}},f=ker(t,n);return{middleware:h=>m=>v=>{if(!USt(v))return m(v);if(fkt.match(v))return c(v.payload);if(Oer.match(v)){f();return}if(pkt.match(v))return u(v.payload);let y=h.getState();const b=()=>{if(y===jze)throw new Error(Tp(23));return y};let S;try{if(S=m(v),t.size>0){const w=h.getState(),k=Array.from(t.values());for(const _ of k){let C=!1;try{C=_.predicate(v,w,y)}catch(E){C=!1,Nze(i,E,{raisedBy:"predicate"})}C&&d(_,v,h,b)}}}finally{y=jze}return S},startListening:c,stopListening:u,clearListeners:f}};function Tp(e){return`Minified Redux Toolkit error #${e}; visit https://redux-toolkit.js.org/Errors?code=${e} for the full message or use the non-minified dev environment for full errors. `}var Cer={layoutType:"horizontal",width:0,height:0,margin:{top:5,right:5,bottom:5,left:5},scale:1},hkt=Hu({name:"chartLayout",initialState:Cer,reducers:{setLayout(e,t){e.layoutType=t.payload},setChartSize(e,t){e.width=t.payload.width,e.height=t.payload.height},setMargin(e,t){var n,r,s,a;e.margin.top=(n=t.payload.top)!==null&&n!==void 0?n:0,e.margin.right=(r=t.payload.right)!==null&&r!==void 0?r:0,e.margin.bottom=(s=t.payload.bottom)!==null&&s!==void 0?s:0,e.margin.left=(a=t.payload.left)!==null&&a!==void 0?a:0},setScale(e,t){e.scale=t.payload}}}),{setMargin:Eer,setLayout:jer,setChartSize:Ter,setScale:Ner}=hkt.actions,Ier=hkt.reducer;function mkt(e,t,n){return Array.isArray(e)&&e&&t+n!==0?e.slice(t,n+1):e}function es(e){return Number.isFinite(e)}function gy(e){return typeof e=="number"&&e>0&&Number.isFinite(e)}function Ize(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(s){return Object.getOwnPropertyDescriptor(e,s).enumerable})),n.push.apply(n,r)}return n}function QE(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?Ize(Object(n),!0).forEach(function(r){Aer(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Ize(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}function Aer(e,t,n){return(t=Rer(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Rer(e){var t=Per(e,"string");return typeof t=="symbol"?t:t+""}function Per(e,t){if(typeof e!="object"||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t);if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}function vo(e,t,n){return Ki(e)||Ki(t)?n:cm(t)?TT(e,t,n):typeof t=="function"?t(e):n}var $er=(e,t,n)=>{if(t&&n){var{width:r,height:s}=n,{align:a,verticalAlign:i,layout:l}=t;if((l==="vertical"||l==="horizontal"&&i==="middle")&&a!=="center"&&Hn(e[a]))return QE(QE({},e),{},{[a]:e[a]+(r||0)});if((l==="horizontal"||l==="vertical"&&a==="center")&&i!=="middle"&&Hn(e[i]))return QE(QE({},e),{},{[i]:e[i]+(s||0)})}return e},Ug=(e,t)=>e==="horizontal"&&t==="xAxis"||e==="vertical"&&t==="yAxis"||e==="centric"&&t==="angleAxis"||e==="radial"&&t==="radiusAxis",gkt=(e,t,n,r)=>{if(r)return e.map(l=>l.coordinate);var s,a,i=e.map(l=>(l.coordinate===t&&(s=!0),l.coordinate===n&&(a=!0),l.coordinate));return s||i.push(t),a||i.push(n),i},vkt=(e,t,n)=>{if(!e)return null;var{duplicateDomain:r,type:s,range:a,scale:i,realScaleType:l,isCategorical:c,categoricalDomain:u,tickCount:d,ticks:f,niceTicks:p,axisType:h}=e;if(!i)return null;var m=l==="scaleBand"&&i.bandwidth?i.bandwidth()/2:2,v=s==="category"&&i.bandwidth?i.bandwidth()/m:0;if(v=h==="angleAxis"&&a&&a.length>=2?zh(a[0]-a[1])*2*v:v,f||p){var y=(f||p||[]).map((b,S)=>{var w=r?r.indexOf(b):b,k=i.map(w);return es(k)?{coordinate:k+v,value:b,offset:v,index:S}:null}).filter(rf);return y}return c&&u?u.map((b,S)=>{var w=i.map(b);return es(w)?{coordinate:w+v,value:b,index:S,offset:v}:null}).filter(rf):i.ticks&&d!=null?i.ticks(d).map((b,S)=>{var w=i.map(b);return es(w)?{coordinate:w+v,value:b,index:S,offset:v}:null}).filter(rf):i.domain().map((b,S)=>{var w=i.map(b);return es(w)?{coordinate:w+v,value:r?r[b]:b,index:S,offset:v}:null}).filter(rf)},Mer=e=>{var t,n=e.length;if(!(n<=0)){var r=(t=e[0])===null||t===void 0?void 0:t.length;if(!(r==null||r<=0))for(var s=0;s<r;++s)for(var a=0,i=0,l=0;l<n;++l){var c=e[l],u=c?.[s];if(u!=null){var d=u[1],f=u[0],p=my(d)?f:d;p>=0?(u[0]=a,a+=p,u[1]=a):(u[0]=i,i+=p,u[1]=i)}}}},Der=e=>{var t,n=e.length;if(!(n<=0)){var r=(t=e[0])===null||t===void 0?void 0:t.length;if(!(r==null||r<=0))for(var s=0;s<r;++s)for(var a=0,i=0;i<n;++i){var l=e[i],c=l?.[s];if(c!=null){var u=my(c[1])?c[0]:c[1];u>=0?(c[0]=a,a+=u,c[1]=a):(c[0]=0,c[1]=0)}}}},Ler={sign:Mer,expand:_Kn,none:UO,silhouette:CKn,wiggle:EKn,positive:Der},Fer=(e,t,n)=>{var r,s=(r=Ler[n])!==null&&r!==void 0?r:UO,a=OKn().keys(t).value((l,c)=>Number(vo(l,c,0))).order(Khe).offset(s),i=a(e);return i.forEach((l,c)=>{l.forEach((u,d)=>{var f=vo(e[d],t[c],0);Array.isArray(f)&&f.length===2&&Hn(f[0])&&Hn(f[1])&&(u[0]=f[0],u[1]=f[1])})}),i};function zer(e){return e==null?void 0:String(e)}function IT(e){var{axis:t,ticks:n,bandSize:r,entry:s,index:a,dataKey:i}=e;if(t.type==="category"){if(!t.allowDuplicatedCategory&&t.dataKey&&!Ki(s[t.dataKey])){var l=OSt(n,"value",s[t.dataKey]);if(l)return l.coordinate+r/2}return n!=null&&n[a]?n[a].coordinate+r/2:null}var c=vo(s,Ki(i)?t.dataKey:i),u=t.scale.map(c);return Hn(u)?u:null}var Ber=e=>{var t=e.flat(2).filter(Hn);return[Math.min(...t),Math.max(...t)]},Uer=e=>[e[0]===1/0?0:e[0],e[1]===-1/0?0:e[1]],qer=(e,t,n)=>{if(e!=null)return Uer(Object.keys(e).reduce((r,s)=>{var a=e[s];if(!a)return r;var{stackedData:i}=a,l=i.reduce((c,u)=>{var d=mkt(u,t,n),f=Ber(d);return!es(f[0])||!es(f[1])?c:[Math.min(c[0],f[0]),Math.max(c[1],f[1])]},[1/0,-1/0]);return[Math.min(l[0],r[0]),Math.max(l[1],r[1])]},[1/0,-1/0]))},Aze=/^dataMin[\s]*-[\s]*([0-9]+([.]{1}[0-9]+){0,1})$/,Rze=/^dataMax[\s]*\+[\s]*([0-9]+([.]{1}[0-9]+){0,1})$/,AT=(e,t,n)=>{if(e&&e.scale&&e.scale.bandwidth){var r=e.scale.bandwidth();if(!n||r>0)return r}if(e&&t&&t.length>=2){for(var s=iH(t,d=>d.coordinate),a=1/0,i=1,l=s.length;i<l;i++){var c=s[i],u=s[i-1];a=Math.min((c?.coordinate||0)-(u?.coordinate||0),a)}return a===1/0?0:a}return n?void 0:0};function Pze(e){var{tooltipEntrySettings:t,dataKey:n,payload:r,value:s,name:a}=e;return QE(QE({},t),{},{dataKey:n,payload:r,value:s,name:a})}function HN(e,t){if(e)return String(e);if(typeof t=="string")return t}var Ver=(e,t)=>{if(t==="horizontal")return e.relativeX;if(t==="vertical")return e.relativeY},Her=(e,t)=>t==="centric"?e.angle:e.radius,Qx=e=>e.layout.width,Yx=e=>e.layout.height,Wer=e=>e.layout.scale,ykt=e=>e.layout.margin,gH=at(e=>e.cartesianAxis.xAxis,e=>Object.values(e)),vH=at(e=>e.cartesianAxis.yAxis,e=>Object.values(e)),Zer="data-recharts-item-index",bkt="data-recharts-item-id",T3=60;function $ze(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(s){return Object.getOwnPropertyDescriptor(e,s).enumerable})),n.push.apply(n,r)}return n}function B6(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?$ze(Object(n),!0).forEach(function(r){Ger(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):$ze(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}function Ger(e,t,n){return(t=Qer(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Qer(e){var t=Yer(e,"string");return typeof t=="symbol"?t:t+""}function Yer(e,t){if(typeof e!="object"||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t);if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}var Xer=e=>e.brush.height;function Ker(e){var t=vH(e);return t.reduce((n,r)=>{if(r.orientation==="left"&&!r.mirror&&!r.hide){var s=typeof r.width=="number"?r.width:T3;return n+s}return n},0)}function Jer(e){var t=vH(e);return t.reduce((n,r)=>{if(r.orientation==="right"&&!r.mirror&&!r.hide){var s=typeof r.width=="number"?r.width:T3;return n+s}return n},0)}function etr(e){var t=gH(e);return t.reduce((n,r)=>r.orientation==="top"&&!r.mirror&&!r.hide?n+r.height:n,0)}function ttr(e){var t=gH(e);return t.reduce((n,r)=>r.orientation==="bottom"&&!r.mirror&&!r.hide?n+r.height:n,0)}var lu=at([Qx,Yx,ykt,Xer,Ker,Jer,etr,ttr,FSt,NJn],(e,t,n,r,s,a,i,l,c,u)=>{var d={left:(n.left||0)+s,right:(n.right||0)+a},f={top:(n.top||0)+i,bottom:(n.bottom||0)+l},p=B6(B6({},f),d),h=p.bottom;p.bottom+=r,p=$er(p,c,u);var m=e-p.left-p.right,v=t-p.top-p.bottom;return B6(B6({brushBottom:h},p),{},{width:Math.max(m,0),height:Math.max(v,0)})}),ntr=at(lu,e=>({x:e.left,y:e.top,width:e.width,height:e.height})),xkt=at(Qx,Yx,(e,t)=>({x:0,y:0,width:e,height:t})),rtr=g.createContext(null),oc=()=>g.useContext(rtr)!=null,yH=e=>e.brush,bH=at([yH,lu,ykt],(e,t,n)=>({height:e.height,x:Hn(e.x)?e.x:t.left,y:Hn(e.y)?e.y:t.top+t.height+t.brushBottom-(n?.bottom||0),width:Hn(e.width)?e.width:t.width})),ate={},ite={},ote={},Mze;function str(){return Mze||(Mze=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});function t(n,r,{signal:s,edges:a}={}){let i,l=null;const c=a!=null&&a.includes("leading"),u=a==null||a.includes("trailing"),d=()=>{l!==null&&(n.apply(i,l),i=void 0,l=null)},f=()=>{u&&d(),v()};let p=null;const h=()=>{p!=null&&clearTimeout(p),p=setTimeout(()=>{p=null,f()},r)},m=()=>{p!==null&&(clearTimeout(p),p=null)},v=()=>{m(),i=void 0,l=null},y=()=>{d()},b=function(...S){if(s?.aborted)return;i=this,l=S;const w=p==null;h(),c&&w&&d()};return b.schedule=h,b.cancel=v,b.flush=y,s?.addEventListener("abort",v,{once:!0}),b}e.debounce=t})(ote)),ote}var Dze;function atr(){return Dze||(Dze=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});const t=str();function n(r,s=0,a={}){typeof a!="object"&&(a={});const{leading:i=!1,trailing:l=!0,maxWait:c}=a,u=Array(2);i&&(u[0]="leading"),l&&(u[1]="trailing");let d,f=null;const p=t.debounce(function(...v){d=r.apply(this,v),f=null},s,{edges:u}),h=function(...v){return c!=null&&(f===null&&(f=Date.now()),Date.now()-f>=c)?(d=r.apply(this,v),f=Date.now(),p.cancel(),p.schedule(),d):(p.apply(this,v),d)},m=()=>(p.flush(),d);return h.cancel=p.cancel,h.flush=m,h}e.debounce=n})(ite)),ite}var Lze;function itr(){return Lze||(Lze=1,(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});const t=atr();function n(r,s=0,a={}){const{leading:i=!0,trailing:l=!0}=a;return t.debounce(r,s,{leading:i,maxWait:s,trailing:l})}e.throttle=n})(ate)),ate}var lte,Fze;function otr(){return Fze||(Fze=1,lte=itr().throttle),lte}var ltr=otr();const ctr=Tc(ltr);var rB=function(t,n){for(var r=arguments.length,s=new Array(r>2?r-2:0),a=2;a<r;a++)s[a-2]=arguments[a];if(typeof console<"u"&&console.warn&&(n===void 0&&console.warn("LogUtils requires an error message argument"),!t))if(n===void 0)console.warn("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var i=0;console.warn(n.replace(/%s/g,()=>s[i++]))}},Uv={width:"100%",height:"100%",debounce:0,minWidth:0,initialDimension:{width:-1,height:-1}},wkt=(e,t,n)=>{var{width:r=Uv.width,height:s=Uv.height,aspect:a,maxHeight:i}=n,l=qO(r)?e:Number(r),c=qO(s)?t:Number(s);return a&&a>0&&(l?c=l/a:c&&(l=c*a),i&&c!=null&&c>i&&(c=i)),{calculatedWidth:l,calculatedHeight:c}},utr={width:0,height:0,overflow:"visible"},dtr={width:0,overflowX:"visible"},ftr={height:0,overflowY:"visible"},ptr={},htr=e=>{var{width:t,height:n}=e,r=qO(t),s=qO(n);return r&&s?utr:r?dtr:s?ftr:ptr};function mtr(e){var{width:t,height:n,aspect:r}=e,s=t,a=n;return s===void 0&&a===void 0?(s=Uv.width,a=Uv.height):s===void 0?s=r&&r>0?void 0:Uv.width:a===void 0&&(a=r&&r>0?void 0:Uv.height),{width:s,height:a}}function ume(){return ume=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},ume.apply(null,arguments)}function zze(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(s){return Object.getOwnPropertyDescriptor(e,s).enumerable})),n.push.apply(n,r)}return n}function Bze(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?zze(Object(n),!0).forEach(function(r){gtr(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):zze(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}function gtr(e,t,n){return(t=vtr(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function vtr(e){var t=ytr(e,"string");return typeof t=="symbol"?t:t+""}function ytr(e,t){if(typeof e!="object"||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t);if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}var Skt=g.createContext(Uv.initialDimension);function btr(e){return gy(e.width)&&gy(e.height)}function kkt(e){var{children:t,width:n,height:r}=e,s=g.useMemo(()=>({width:n,height:r}),[n,r]);return btr(s)?g.createElement(Skt.Provider,{value:s},t):null}var SSe=()=>g.useContext(Skt),xtr=g.forwardRef((e,t)=>{var{aspect:n,initialDimension:r=Uv.initialDimension,width:s,height:a,minWidth:i=Uv.minWidth,minHeight:l,maxHeight:c,children:u,debounce:d=Uv.debounce,id:f,className:p,onResize:h,style:m={}}=e,v=g.useRef(null),y=g.useRef();y.current=h,g.useImperativeHandle(t,()=>v.current);var[b,S]=g.useState({containerWidth:r.width,containerHeight:r.height}),w=g.useCallback((j,N)=>{S(I=>{var R=Math.round(j),P=Math.round(N);return I.containerWidth===R&&I.containerHeight===P?I:{containerWidth:R,containerHeight:P}})},[]);g.useEffect(()=>{if(v.current==null||typeof ResizeObserver>"u")return M_;var j=P=>{var L,M=P[0];if(M!=null){var{width:q,height:H}=M.contentRect;w(q,H),(L=y.current)===null||L===void 0||L.call(y,q,H)}};d>0&&(j=ctr(j,d,{trailing:!0,leading:!1}));var N=new ResizeObserver(j),{width:I,height:R}=v.current.getBoundingClientRect();return w(I,R),N.observe(v.current),()=>{N.disconnect()}},[w,d]);var{containerWidth:k,containerHeight:_}=b;rB(!n||n>0,"The aspect(%s) must be greater than zero.",n);var{calculatedWidth:C,calculatedHeight:E}=wkt(k,_,{width:s,height:a,aspect:n,maxHeight:c});return rB(C!=null&&C>0||E!=null&&E>0,`The width(%s) and height(%s) of chart should be greater than 0,
|
|
346
346
|
please check the style of container, or the props width(%s) and height(%s),
|
|
347
347
|
or add a minWidth(%s) or minHeight(%s) or use aspect(%s) to control the
|
|
348
348
|
height and width.`,C,E,s,a,i,l,n),g.createElement("div",{id:f?"".concat(f):void 0,className:Ca("recharts-responsive-container",p),style:Bze(Bze({},m),{},{width:s,height:a,minWidth:i,minHeight:l,maxHeight:c}),ref:v},g.createElement("div",{style:htr({width:s,height:a})},g.createElement(kkt,{width:C,height:E},u)))}),N3=g.forwardRef((e,t)=>{var n=SSe();if(gy(n.width)&&gy(n.height))return e.children;var{width:r,height:s}=mtr({width:e.width,height:e.height,aspect:e.aspect}),{calculatedWidth:a,calculatedHeight:i}=wkt(void 0,void 0,{width:r,height:s,aspect:e.aspect,maxHeight:e.maxHeight});return Hn(a)&&Hn(i)?g.createElement(kkt,{width:a,height:i},e.children):g.createElement(xtr,ume({},e,{width:r,height:s,ref:t}))});function kSe(e){if(e)return{x:e.x,y:e.y,upperWidth:"upperWidth"in e?e.upperWidth:e.width,lowerWidth:"lowerWidth"in e?e.lowerWidth:e.width,width:e.width,height:e.height}}var WN=()=>{var e,t=oc(),n=Kn(ntr),r=Kn(bH),s=(e=Kn(yH))===null||e===void 0?void 0:e.padding;return!t||!r||!s?n:{width:r.width-s.left-s.right,height:r.height-s.top-s.bottom,x:s.left,y:s.top}},wtr={top:0,bottom:0,left:0,right:0,width:0,height:0,brushBottom:0},Okt=()=>{var e;return(e=Kn(lu))!==null&&e!==void 0?e:wtr},_kt=()=>Kn(Qx),Ckt=()=>Kn(Yx),Ui=e=>e.layout.layoutType,D_=()=>Kn(Ui),OSe=()=>{var e=D_();if(e==="horizontal"||e==="vertical")return e},Ekt=e=>{var t=e.layout.layoutType;if(t==="centric"||t==="radial")return t},Str=()=>{var e=D_();return e!==void 0},I3=e=>{var t=so(),n=oc(),{width:r,height:s}=e,a=SSe(),i=r,l=s;return a&&(i=a.width>0?a.width:r,l=a.height>0?a.height:s),g.useEffect(()=>{!n&&gy(i)&&gy(l)&&t(Ter({width:i,height:l}))},[t,n,i,l]),null},jkt=Symbol.for("immer-nothing"),Uze=Symbol.for("immer-draftable"),Hp=Symbol.for("immer-state");function lg(e,...t){throw new Error(`[Immer] minified error nr: ${e}. Full error at: https://bit.ly/3cXEKWf`)}var yM=Object.getPrototypeOf;function RT(e){return!!e&&!!e[Hp]}function HO(e){return e?Tkt(e)||Array.isArray(e)||!!e[Uze]||!!e.constructor?.[Uze]||A3(e)||wH(e):!1}var ktr=Object.prototype.constructor.toString(),qze=new WeakMap;function Tkt(e){if(!e||typeof e!="object")return!1;const t=Object.getPrototypeOf(e);if(t===null||t===Object.prototype)return!0;const n=Object.hasOwnProperty.call(t,"constructor")&&t.constructor;if(n===Object)return!0;if(typeof n!="function")return!1;let r=qze.get(n);return r===void 0&&(r=Function.toString.call(n),qze.set(n,r)),r===ktr}function sB(e,t,n=!0){xH(e)===0?(n?Reflect.ownKeys(e):Object.keys(e)).forEach(s=>{t(s,e[s],e)}):e.forEach((r,s)=>t(s,r,e))}function xH(e){const t=e[Hp];return t?t.type_:Array.isArray(e)?1:A3(e)?2:wH(e)?3:0}function dme(e,t){return xH(e)===2?e.has(t):Object.prototype.hasOwnProperty.call(e,t)}function Nkt(e,t,n){const r=xH(e);r===2?e.set(t,n):r===3?e.add(n):e[t]=n}function Otr(e,t){return e===t?e!==0||1/e===1/t:e!==e&&t!==t}function A3(e){return e instanceof Map}function wH(e){return e instanceof Set}function tk(e){return e.copy_||e.base_}function fme(e,t){if(A3(e))return new Map(e);if(wH(e))return new Set(e);if(Array.isArray(e))return Array.prototype.slice.call(e);const n=Tkt(e);if(t===!0||t==="class_only"&&!n){const r=Object.getOwnPropertyDescriptors(e);delete r[Hp];let s=Reflect.ownKeys(r);for(let a=0;a<s.length;a++){const i=s[a],l=r[i];l.writable===!1&&(l.writable=!0,l.configurable=!0),(l.get||l.set)&&(r[i]={configurable:!0,writable:!0,enumerable:l.enumerable,value:e[i]})}return Object.create(yM(e),r)}else{const r=yM(e);if(r!==null&&n)return{...e};const s=Object.create(r);return Object.assign(s,e)}}function _Se(e,t=!1){return SH(e)||RT(e)||!HO(e)||(xH(e)>1&&Object.defineProperties(e,{set:U6,add:U6,clear:U6,delete:U6}),Object.freeze(e),t&&Object.values(e).forEach(n=>_Se(n,!0))),e}function _tr(){lg(2)}var U6={value:_tr};function SH(e){return e===null||typeof e!="object"?!0:Object.isFrozen(e)}var Ctr={};function WO(e){const t=Ctr[e];return t||lg(0,e),t}var bM;function Ikt(){return bM}function Etr(e,t){return{drafts_:[],parent_:e,immer_:t,canAutoFreeze_:!0,unfinalizedDrafts_:0}}function Vze(e,t){t&&(WO("Patches"),e.patches_=[],e.inversePatches_=[],e.patchListener_=t)}function pme(e){hme(e),e.drafts_.forEach(jtr),e.drafts_=null}function hme(e){e===bM&&(bM=e.parent_)}function Hze(e){return bM=Etr(bM,e)}function jtr(e){const t=e[Hp];t.type_===0||t.type_===1?t.revoke_():t.revoked_=!0}function Wze(e,t){t.unfinalizedDrafts_=t.drafts_.length;const n=t.drafts_[0];return e!==void 0&&e!==n?(n[Hp].modified_&&(pme(t),lg(4)),HO(e)&&(e=aB(t,e),t.parent_||iB(t,e)),t.patches_&&WO("Patches").generateReplacementPatches_(n[Hp].base_,e,t.patches_,t.inversePatches_)):e=aB(t,n,[]),pme(t),t.patches_&&t.patchListener_(t.patches_,t.inversePatches_),e!==jkt?e:void 0}function aB(e,t,n){if(SH(t))return t;const r=e.immer_.shouldUseStrictIteration(),s=t[Hp];if(!s)return sB(t,(a,i)=>Zze(e,s,t,a,i,n),r),t;if(s.scope_!==e)return t;if(!s.modified_)return iB(e,s.base_,!0),s.base_;if(!s.finalized_){s.finalized_=!0,s.scope_.unfinalizedDrafts_--;const a=s.copy_;let i=a,l=!1;s.type_===3&&(i=new Set(a),a.clear(),l=!0),sB(i,(c,u)=>Zze(e,s,a,c,u,n,l),r),iB(e,a,!1),n&&e.patches_&&WO("Patches").generatePatches_(s,n,e.patches_,e.inversePatches_)}return s.copy_}function Zze(e,t,n,r,s,a,i){if(s==null||typeof s!="object"&&!i)return;const l=SH(s);if(!(l&&!i)){if(RT(s)){const c=a&&t&&t.type_!==3&&!dme(t.assigned_,r)?a.concat(r):void 0,u=aB(e,s,c);if(Nkt(n,r,u),RT(u))e.canAutoFreeze_=!1;else return}else i&&n.add(s);if(HO(s)&&!l){if(!e.immer_.autoFreeze_&&e.unfinalizedDrafts_<1||t&&t.base_&&t.base_[r]===s&&l)return;aB(e,s),(!t||!t.scope_.parent_)&&typeof r!="symbol"&&(A3(n)?n.has(r):Object.prototype.propertyIsEnumerable.call(n,r))&&iB(e,s)}}}function iB(e,t,n=!1){!e.parent_&&e.immer_.autoFreeze_&&e.canAutoFreeze_&&_Se(t,n)}function Ttr(e,t){const n=Array.isArray(e),r={type_:n?1:0,scope_:t?t.scope_:Ikt(),modified_:!1,finalized_:!1,assigned_:{},parent_:t,base_:e,draft_:null,copy_:null,revoke_:null,isManual_:!1};let s=r,a=CSe;n&&(s=[r],a=xM);const{revoke:i,proxy:l}=Proxy.revocable(s,a);return r.draft_=l,r.revoke_=i,l}var CSe={get(e,t){if(t===Hp)return e;const n=tk(e);if(!dme(n,t))return Ntr(e,n,t);const r=n[t];return e.finalized_||!HO(r)?r:r===cte(e.base_,t)?(ute(e),e.copy_[t]=gme(r,e)):r},has(e,t){return t in tk(e)},ownKeys(e){return Reflect.ownKeys(tk(e))},set(e,t,n){const r=Akt(tk(e),t);if(r?.set)return r.set.call(e.draft_,n),!0;if(!e.modified_){const s=cte(tk(e),t),a=s?.[Hp];if(a&&a.base_===n)return e.copy_[t]=n,e.assigned_[t]=!1,!0;if(Otr(n,s)&&(n!==void 0||dme(e.base_,t)))return!0;ute(e),mme(e)}return e.copy_[t]===n&&(n!==void 0||t in e.copy_)||Number.isNaN(n)&&Number.isNaN(e.copy_[t])||(e.copy_[t]=n,e.assigned_[t]=!0),!0},deleteProperty(e,t){return cte(e.base_,t)!==void 0||t in e.base_?(e.assigned_[t]=!1,ute(e),mme(e)):delete e.assigned_[t],e.copy_&&delete e.copy_[t],!0},getOwnPropertyDescriptor(e,t){const n=tk(e),r=Reflect.getOwnPropertyDescriptor(n,t);return r&&{writable:!0,configurable:e.type_!==1||t!=="length",enumerable:r.enumerable,value:n[t]}},defineProperty(){lg(11)},getPrototypeOf(e){return yM(e.base_)},setPrototypeOf(){lg(12)}},xM={};sB(CSe,(e,t)=>{xM[e]=function(){return arguments[0]=arguments[0][0],t.apply(this,arguments)}});xM.deleteProperty=function(e,t){return xM.set.call(this,e,t,void 0)};xM.set=function(e,t,n){return CSe.set.call(this,e[0],t,n,e[0])};function cte(e,t){const n=e[Hp];return(n?tk(n):e)[t]}function Ntr(e,t,n){const r=Akt(t,n);return r?"value"in r?r.value:r.get?.call(e.draft_):void 0}function Akt(e,t){if(!(t in e))return;let n=yM(e);for(;n;){const r=Object.getOwnPropertyDescriptor(n,t);if(r)return r;n=yM(n)}}function mme(e){e.modified_||(e.modified_=!0,e.parent_&&mme(e.parent_))}function ute(e){e.copy_||(e.copy_=fme(e.base_,e.scope_.immer_.useStrictShallowCopy_))}var Itr=class{constructor(e){this.autoFreeze_=!0,this.useStrictShallowCopy_=!1,this.useStrictIteration_=!0,this.produce=(t,n,r)=>{if(typeof t=="function"&&typeof n!="function"){const a=n;n=t;const i=this;return function(c=a,...u){return i.produce(c,d=>n.call(this,d,...u))}}typeof n!="function"&&lg(6),r!==void 0&&typeof r!="function"&&lg(7);let s;if(HO(t)){const a=Hze(this),i=gme(t,void 0);let l=!0;try{s=n(i),l=!1}finally{l?pme(a):hme(a)}return Vze(a,r),Wze(s,a)}else if(!t||typeof t!="object"){if(s=n(t),s===void 0&&(s=t),s===jkt&&(s=void 0),this.autoFreeze_&&_Se(s,!0),r){const a=[],i=[];WO("Patches").generateReplacementPatches_(t,s,a,i),r(a,i)}return s}else lg(1,t)},this.produceWithPatches=(t,n)=>{if(typeof t=="function")return(i,...l)=>this.produceWithPatches(i,c=>t(c,...l));let r,s;return[this.produce(t,n,(i,l)=>{r=i,s=l}),r,s]},typeof e?.autoFreeze=="boolean"&&this.setAutoFreeze(e.autoFreeze),typeof e?.useStrictShallowCopy=="boolean"&&this.setUseStrictShallowCopy(e.useStrictShallowCopy),typeof e?.useStrictIteration=="boolean"&&this.setUseStrictIteration(e.useStrictIteration)}createDraft(e){HO(e)||lg(8),RT(e)&&(e=Atr(e));const t=Hze(this),n=gme(e,void 0);return n[Hp].isManual_=!0,hme(t),n}finishDraft(e,t){const n=e&&e[Hp];(!n||!n.isManual_)&&lg(9);const{scope_:r}=n;return Vze(r,t),Wze(void 0,r)}setAutoFreeze(e){this.autoFreeze_=e}setUseStrictShallowCopy(e){this.useStrictShallowCopy_=e}setUseStrictIteration(e){this.useStrictIteration_=e}shouldUseStrictIteration(){return this.useStrictIteration_}applyPatches(e,t){let n;for(n=t.length-1;n>=0;n--){const s=t[n];if(s.path.length===0&&s.op==="replace"){e=s.value;break}}n>-1&&(t=t.slice(n+1));const r=WO("Patches").applyPatches_;return RT(e)?r(e,t):this.produce(e,s=>r(s,t))}};function gme(e,t){const n=A3(e)?WO("MapSet").proxyMap_(e,t):wH(e)?WO("MapSet").proxySet_(e,t):Ttr(e,t);return(t?t.scope_:Ikt()).drafts_.push(n),n}function Atr(e){return RT(e)||lg(10,e),Rkt(e)}function Rkt(e){if(!HO(e)||SH(e))return e;const t=e[Hp];let n,r=!0;if(t){if(!t.modified_)return t.base_;t.finalized_=!0,n=fme(e,t.scope_.immer_.useStrictShallowCopy_),r=t.scope_.immer_.shouldUseStrictIteration()}else n=fme(e,!0);return sB(n,(s,a)=>{Nkt(n,s,Rkt(a))},r),t&&(t.finalized_=!1),n}var Rtr=new Itr;Rtr.produce;var Ptr={settings:{layout:"horizontal",align:"center",verticalAlign:"middle",itemSorter:"value"},size:{width:0,height:0},payload:[]},Pkt=Hu({name:"legend",initialState:Ptr,reducers:{setLegendSize(e,t){e.size.width=t.payload.width,e.size.height=t.payload.height},setLegendSettings(e,t){e.settings.align=t.payload.align,e.settings.layout=t.payload.layout,e.settings.verticalAlign=t.payload.verticalAlign,e.settings.itemSorter=t.payload.itemSorter},addLegendPayload:{reducer(e,t){e.payload.push(t.payload)},prepare:Wi()},replaceLegendPayload:{reducer(e,t){var{prev:n,next:r}=t.payload,s=Bh(e).payload.indexOf(n);s>-1&&(e.payload[s]=r)},prepare:Wi()},removeLegendPayload:{reducer(e,t){var n=Bh(e).payload.indexOf(t.payload);n>-1&&e.payload.splice(n,1)},prepare:Wi()}}}),{setLegendSize:Bbs,setLegendSettings:Ubs,addLegendPayload:$tr,replaceLegendPayload:Mtr,removeLegendPayload:Dtr}=Pkt.actions,Ltr=Pkt.reducer,dte={exports:{}},fte={};var Gze;function Ftr(){if(Gze)return fte;Gze=1;var e=pN();function t(c,u){return c===u&&(c!==0||1/c===1/u)||c!==c&&u!==u}var n=typeof Object.is=="function"?Object.is:t,r=e.useSyncExternalStore,s=e.useRef,a=e.useEffect,i=e.useMemo,l=e.useDebugValue;return fte.useSyncExternalStoreWithSelector=function(c,u,d,f,p){var h=s(null);if(h.current===null){var m={hasValue:!1,value:null};h.current=m}else m=h.current;h=i(function(){function y(_){if(!b){if(b=!0,S=_,_=f(_),p!==void 0&&m.hasValue){var C=m.value;if(p(C,_))return w=C}return w=_}if(C=w,n(S,_))return C;var E=f(_);return p!==void 0&&p(C,E)?(S=_,C):(S=_,w=E)}var b=!1,S,w,k=d===void 0?null:d;return[function(){return y(u())},k===null?void 0:function(){return y(k())}]},[u,d,f,p]);var v=r(c,h[0],h[1]);return a(function(){m.hasValue=!0,m.value=v},[v]),l(v),v},fte}var Qze;function ztr(){return Qze||(Qze=1,dte.exports=Ftr()),dte.exports}ztr();var Btr=g.version.startsWith("19"),Utr=Symbol.for(Btr?"react.transitional.element":"react.element"),qtr=Symbol.for("react.portal"),Vtr=Symbol.for("react.fragment"),Htr=Symbol.for("react.strict_mode"),Wtr=Symbol.for("react.profiler"),Ztr=Symbol.for("react.consumer"),Gtr=Symbol.for("react.context"),$kt=Symbol.for("react.forward_ref"),Qtr=Symbol.for("react.suspense"),Ytr=Symbol.for("react.suspense_list"),ESe=Symbol.for("react.memo"),Xtr=Symbol.for("react.lazy"),Ktr=$kt,Jtr=ESe;function enr(e){if(typeof e=="object"&&e!==null){const{$$typeof:t}=e;switch(t){case Utr:switch(e=e.type,e){case Vtr:case Wtr:case Htr:case Qtr:case Ytr:return e;default:switch(e=e&&e.$$typeof,e){case Gtr:case $kt:case Xtr:case ESe:return e;case Ztr:return e;default:return t}}case qtr:return t}}}function tnr(e){return enr(e)===ESe}function nnr(e,t,n,r,{areStatesEqual:s,areOwnPropsEqual:a,areStatePropsEqual:i}){let l=!1,c,u,d,f,p;function h(S,w){return c=S,u=w,d=e(c,u),f=t(r,u),p=n(d,f,u),l=!0,p}function m(){return d=e(c,u),t.dependsOnOwnProps&&(f=t(r,u)),p=n(d,f,u),p}function v(){return e.dependsOnOwnProps&&(d=e(c,u)),t.dependsOnOwnProps&&(f=t(r,u)),p=n(d,f,u),p}function y(){const S=e(c,u),w=!i(S,d);return d=S,w&&(p=n(d,f,u)),p}function b(S,w){const k=!a(w,u),_=!s(S,c,w,u);return c=S,u=w,k&&_?m():k?v():_?y():p}return function(w,k){return l?b(w,k):h(w,k)}}function rnr(e,{initMapStateToProps:t,initMapDispatchToProps:n,initMergeProps:r,...s}){const a=t(e,s),i=n(e,s),l=r(e,s);return nnr(a,i,l,e,s)}function snr(e,t){const n={};for(const r in e){const s=e[r];typeof s=="function"&&(n[r]=(...a)=>t(s(...a)))}return n}function vme(e){return function(n){const r=e(n);function s(){return r}return s.dependsOnOwnProps=!1,s}}function Yze(e){return e.dependsOnOwnProps?!!e.dependsOnOwnProps:e.length!==1}function Mkt(e,t){return function(r,{displayName:s}){const a=function(l,c){return a.dependsOnOwnProps?a.mapToProps(l,c):a.mapToProps(l,void 0)};return a.dependsOnOwnProps=!0,a.mapToProps=function(l,c){a.mapToProps=e,a.dependsOnOwnProps=Yze(e);let u=a(l,c);return typeof u=="function"&&(a.mapToProps=u,a.dependsOnOwnProps=Yze(u),u=a(l,c)),u},a}}function jSe(e,t){return(n,r)=>{throw new Error(`Invalid value of type ${typeof e} for ${t} argument when connecting component ${r.wrappedComponentName}.`)}}function anr(e){return e&&typeof e=="object"?vme(t=>snr(e,t)):e?typeof e=="function"?Mkt(e):jSe(e,"mapDispatchToProps"):vme(t=>({dispatch:t}))}function inr(e){return e?typeof e=="function"?Mkt(e):jSe(e,"mapStateToProps"):vme(()=>({}))}function onr(e,t,n){return{...n,...e,...t}}function lnr(e){return function(n,{displayName:r,areMergedPropsEqual:s}){let a=!1,i;return function(c,u,d){const f=e(c,u,d);return a?s(f,i)||(i=f):(a=!0,i=f),i}}}function cnr(e){return e?typeof e=="function"?lnr(e):jSe(e,"mergeProps"):()=>onr}function unr(e){e()}function dnr(){let e=null,t=null;return{clear(){e=null,t=null},notify(){unr(()=>{let n=e;for(;n;)n.callback(),n=n.next})},get(){const n=[];let r=e;for(;r;)n.push(r),r=r.next;return n},subscribe(n){let r=!0;const s=t={callback:n,next:null,prev:t};return s.prev?s.prev.next=s:e=s,function(){!r||e===null||(r=!1,s.next?s.next.prev=s.prev:t=s.prev,s.prev?s.prev.next=s.next:e=s.next)}}}}var Xze={notify(){},get:()=>[]};function Dkt(e,t){let n,r=Xze,s=0,a=!1;function i(v){d();const y=r.subscribe(v);let b=!1;return()=>{b||(b=!0,y(),f())}}function l(){r.notify()}function c(){m.onStateChange&&m.onStateChange()}function u(){return a}function d(){s++,n||(n=t?t.addNestedSub(c):e.subscribe(c),r=dnr())}function f(){s--,n&&s===0&&(n(),n=void 0,r.clear(),r=Xze)}function p(){a||(a=!0,d())}function h(){a&&(a=!1,f())}const m={addNestedSub:i,notifyNestedSubs:l,handleChangeWrapper:c,isSubscribed:u,trySubscribe:p,tryUnsubscribe:h,getListeners:()=>r};return m}var fnr=()=>typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",pnr=fnr(),hnr=()=>typeof navigator<"u"&&navigator.product==="ReactNative",mnr=hnr(),gnr=()=>pnr||mnr?g.useLayoutEffect:g.useEffect,oB=gnr();function Kze(e,t){return e===t?e!==0||t!==0||1/e===1/t:e!==e&&t!==t}function u8(e,t){if(Kze(e,t))return!0;if(typeof e!="object"||e===null||typeof t!="object"||t===null)return!1;const n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(let s=0;s<n.length;s++)if(!Object.prototype.hasOwnProperty.call(t,n[s])||!Kze(e[n[s]],t[n[s]]))return!1;return!0}var vnr={childContextTypes:!0,contextType:!0,contextTypes:!0,defaultProps:!0,displayName:!0,getDefaultProps:!0,getDerivedStateFromError:!0,getDerivedStateFromProps:!0,mixins:!0,propTypes:!0,type:!0},ynr={name:!0,length:!0,prototype:!0,caller:!0,callee:!0,arguments:!0,arity:!0},bnr={$$typeof:!0,render:!0,defaultProps:!0,displayName:!0,propTypes:!0},Lkt={$$typeof:!0,compare:!0,defaultProps:!0,displayName:!0,propTypes:!0,type:!0},xnr={[Ktr]:bnr,[Jtr]:Lkt};function Jze(e){return tnr(e)?Lkt:xnr[e.$$typeof]||vnr}var wnr=Object.defineProperty,Snr=Object.getOwnPropertyNames,e7e=Object.getOwnPropertySymbols,knr=Object.getOwnPropertyDescriptor,Onr=Object.getPrototypeOf,t7e=Object.prototype;function yme(e,t){if(typeof t!="string"){if(t7e){const a=Onr(t);a&&a!==t7e&&yme(e,a)}let n=Snr(t);e7e&&(n=n.concat(e7e(t)));const r=Jze(e),s=Jze(t);for(let a=0;a<n.length;++a){const i=n[a];if(!ynr[i]&&!(s&&s[i])&&!(r&&r[i])){const l=knr(t,i);try{wnr(e,i,l)}catch{}}}}return e}var _nr=Symbol.for("react-redux-context"),Cnr=typeof globalThis<"u"?globalThis:{};function Enr(){if(!g.createContext)return{};const e=Cnr[_nr]??=new Map;let t=e.get(g.createContext);return t||(t=g.createContext(null),e.set(g.createContext,t)),t}var Fkt=Enr(),jnr=[null,null];function Tnr(e,t,n){oB(()=>e(...t),n)}function Nnr(e,t,n,r,s,a){e.current=r,n.current=!1,s.current&&(s.current=null,a())}function Inr(e,t,n,r,s,a,i,l,c,u,d){if(!e)return()=>{};let f=!1,p=null;const h=()=>{if(f||!l.current)return;const v=t.getState();let y,b;try{y=r(v,s.current)}catch(S){b=S,p=S}b||(p=null),y===a.current?i.current||u():(a.current=y,c.current=y,i.current=!0,d())};return n.onStateChange=h,n.trySubscribe(),h(),()=>{if(f=!0,n.tryUnsubscribe(),n.onStateChange=null,p)throw p}}function Anr(e,t){return e===t}function Rnr(e,t,n,{pure:r,areStatesEqual:s=Anr,areOwnPropsEqual:a=u8,areStatePropsEqual:i=u8,areMergedPropsEqual:l=u8,forwardRef:c=!1,context:u=Fkt}={}){const d=u,f=inr(e),p=anr(t),h=cnr(n),m=!!e;return y=>{const b=y.displayName||y.name||"Component",S=`Connect(${b})`,w={shouldHandleStateChanges:m,displayName:S,wrappedComponentName:b,WrappedComponent:y,initMapStateToProps:f,initMapDispatchToProps:p,initMergeProps:h,areStatesEqual:s,areStatePropsEqual:i,areOwnPropsEqual:a,areMergedPropsEqual:l};function k(E){const[j,N,I]=g.useMemo(()=>{const{reactReduxForwardedRef:Y,...ne}=E;return[E.context,Y,ne]},[E]),R=g.useMemo(()=>{let Y=d;return j?.Consumer,Y},[j,d]),P=g.useContext(R),L=!!E.store&&!!E.store.getState&&!!E.store.dispatch,M=!!P&&!!P.store,q=L?E.store:P.store,H=M?P.getServerState:q.getState,F=g.useMemo(()=>rnr(q.dispatch,w),[q]),[z,B]=g.useMemo(()=>{if(!m)return jnr;const Y=Dkt(q,L?void 0:P.subscription),ne=Y.notifyNestedSubs.bind(Y);return[Y,ne]},[q,L,P]),D=g.useMemo(()=>L?P:{...P,subscription:z},[L,P,z]),Q=g.useRef(void 0),V=g.useRef(I),$=g.useRef(void 0),U=g.useRef(!1),Z=g.useRef(!1),X=g.useRef(void 0);oB(()=>(Z.current=!0,()=>{Z.current=!1}),[]);const te=g.useMemo(()=>()=>$.current&&I===V.current?$.current:F(q.getState(),I),[q,I]),J=g.useMemo(()=>ne=>z?Inr(m,q,z,F,V,Q,U,Z,$,B,ne):()=>{},[z]);Tnr(Nnr,[V,Q,U,I,$,B]);let ee;try{ee=g.useSyncExternalStore(J,te,H?()=>F(H(),I):te)}catch(Y){throw X.current&&(Y.message+=`
|
|
@@ -508,8 +508,8 @@ Ask one simple question at a time.`;function pIr(e,t){const n=g.useRef(e);n.curr
|
|
|
508
508
|
`).trim():e.content.trim():Array.isArray(e)?e.map(uU).join(`
|
|
509
509
|
|
|
510
510
|
`).trim():"",iRt=e=>e.includes(".")?e.split(".")[0]:e,fAr=({providerId:e,className:t="",size:n=20})=>{const[r,s]=g.useState(!1),a=iRt(e),i=a.replace(/\//g,"-").toLowerCase(),c=(d=>({openai:"openai.chat",anthropic:"anthropic.messages",google:"GOOGLE",xai:"X_GROK",groq:"GROQ",deepseek:"deepseek",together:"together",mistral:"mistral",perplexity:"perplexity",fireworks_ai:"fireworks",openrouter:"openrouter",netlify:"netlify",mastra:"mastra"})[d]||"DEFAULT")(a);return["netlify","mastra"].includes(i)||r||!e?tU[c]?o.jsx(Ue,{children:tU[c]}):o.jsx("div",{className:`bg-surface4 rounded ${t}`,style:{width:n,height:n}}):o.jsx("img",{src:`https://models.dev/logos/${i}.svg`,alt:`${e} logo`,width:n,height:n,className:t,onError:()=>s(!0),loading:"lazy",style:{width:`${n}px`,height:`${n}px`,objectFit:"contain"}})};function pAr({agents:e,isLoading:t,search:n=""}){const{paths:r,Link:s}=yn(),a=g.useMemo(()=>Object.values(e??{}),[e]),i=g.useMemo(()=>{const l=n.toLowerCase();return a.filter(c=>{const u=uU(c.instructions);return c.name.toLowerCase().includes(l)||u.toLowerCase().includes(l)})},[a,n]);return t?o.jsx(tl,{columns:"auto 1fr auto auto auto auto"}):o.jsxs(me,{columns:"auto 1fr auto auto auto auto",variant:"striped",children:[o.jsxs(me.Top,{children:[o.jsx(me.TopCell,{className:"",children:"Name"}),o.jsx(me.TopCell,{className:"",children:"Instructions"}),o.jsx(me.TopCell,{className:"",children:"Model"}),o.jsx(me.TopCellSmart,{long:"Workflows",short:o.jsx(jd,{}),tooltip:"Number of attached Workflows",className:"text-center"}),o.jsx(me.TopCellSmart,{long:"Agents",short:o.jsx(sl,{}),tooltip:"Number of attached Agents",className:"text-center"}),o.jsx(me.TopCellSmart,{long:"Tools",short:o.jsx(eh,{}),tooltip:"Number of attached Tools",className:"text-center"})]}),i.length===0&&n?o.jsx(me.NoMatch,{message:"No Agents match your search"}):null,i.map(l=>{const c=fm(l.name,50),u=fm(uU(l.instructions),200),d=Object.keys(l.agents??{}).length,f=Object.keys(l.tools??{}).length,p=Object.keys(l.workflows??{}).length;return o.jsxs(me.RowLink,{to:r.agentLink(l.id),LinkComponent:s,children:[o.jsx(me.NameCell,{children:c||""}),o.jsx(me.DescriptionCell,{children:u||""}),o.jsx(me.Cell,{children:o.jsxs(Al,{children:[l.provider&&o.jsx(fAr,{providerId:l.provider,className:"dark:invert"}),o.jsx("span",{className:"truncate",children:l.modelId||"N/A"})]})}),o.jsx(me.TextCell,{className:"text-center",children:p||""}),o.jsx(me.TextCell,{className:"text-center",children:d||""}),o.jsx(me.TextCell,{className:"text-center",children:f||""})]},l.id)})]})}const hAr=()=>o.jsx("div",{className:"flex h-full items-center justify-center ",children:o.jsx(Cr,{iconSlot:o.jsx(Of,{}),titleSlot:"No Agents yet",descriptionSlot:"Configure agents in code to get started.",actionSlot:o.jsxs(de,{variant:"ghost",as:"a",href:"https://mastra.ai/docs/agents/overview",target:"_blank",rel:"noopener noreferrer",children:["Agents Documentation ",o.jsx(_a,{})]})})});function mAr(){const{data:e={},isLoading:t,error:n}=km(),[r,s]=g.useState("");return n&&gs(n)?o.jsx(lr,{children:o.jsx(Vs,{})}):n&&ys(n)?o.jsx(lr,{children:o.jsx(Ds,{resource:"agents"})}):n?o.jsx(lr,{children:o.jsx(zi,{title:"Failed to load agents",message:n.message})}):Object.keys(e).length===0&&!t?o.jsx(lr,{children:o.jsx(hAr,{})}):o.jsxs(Lt,{children:[o.jsx(CIr,{}),o.jsx(Lt.TopArea,{children:o.jsx("div",{className:"max-w-120",children:o.jsx(jf,{onSearch:s,label:"Filter agents",placeholder:"Filter by name or instructions"})})}),o.jsx(pAr,{agents:e,isLoading:t,search:r})]})}const vl=e=>{const t=We(),n=Pl();return wt({queryKey:["agent",e,n],queryFn:()=>e?t.getAgent(e).details(n):null,retry:!1,enabled:!!e})},Q1=({agentId:e,params:t,enabled:n=!0})=>{const r=We(),{requestContext:s}=_s();return wt({queryKey:["agent-versions",e,t,s],queryFn:e?()=>r.getStoredAgent(e).listVersions(t,s):jy,enabled:n})},oRt=({agentId:e,versionId:t})=>{const n=We(),{requestContext:r}=_s();return wt({queryKey:["agent-version",e,t,r],queryFn:()=>n.getStoredAgent(e).getVersion(t,r),enabled:!!e&&!!t})},gAr=({agentId:e,fromVersionId:t,toVersionId:n})=>{const r=We(),{requestContext:s}=_s();return wt({queryKey:["agent-versions-compare",e,t,n,s],queryFn:()=>r.getStoredAgent(e).compareVersions(t,n,s),enabled:!!e&&!!t&&!!n})};function Sc({name:e,helpText:t,errorMsg:n,required:r=!1,disabled:s=!1,size:a="md",value:i,label:l,labelIsHidden:c=!1,layout:u="vertical",labelColumnWidth:d,options:f,placeholder:p="Select an option",onValueChange:h,className:m}){return o.jsxs(pl.Layout,{layout:u,labelColumnWidth:d,className:m,children:[u==="horizontal"?o.jsx(pl.Column,{children:o.jsx(pl.Label,{name:e,required:r,children:c?o.jsx(xx,{children:l}):l})}):null,o.jsxs(pl.Column,{children:[u==="vertical"&&l&&!c?o.jsx(pl.Label,{name:e,required:r,children:l}):null,o.jsxs(da,{"aria-label":c?l:void 0,name:e,value:i,onValueChange:h,disabled:s,children:[o.jsx(pa,{size:a,children:o.jsx(fa,{placeholder:p})}),o.jsx(ha,{children:f.map(v=>o.jsx(Lr,{value:v.value,children:v.label},v.value))})]}),t&&o.jsx(pl.HelpText,{children:t}),n&&o.jsx(pl.ErrorMsg,{children:n})]})]})}const vAr=({headers:e,onAddHeader:t,onRemoveHeader:n})=>o.jsxs("div",{className:"space-y-4",children:[o.jsx(ge,{as:"h2",variant:"header-xs",className:"text-neutral6",children:"Headers"}),o.jsxs("div",{className:" space-y-6",children:[e.length>0&&o.jsx("ul",{className:"space-y-4",children:e.map((r,s)=>o.jsx("li",{children:o.jsx(yAr,{index:s,header:r,onRemove:()=>n(s)})},s))}),o.jsxs("div",{className:"flex items-center gap-2 justify-between",children:[e.length===0&&o.jsx(ge,{className:"text-neutral3",children:"No header yet"}),o.jsxs(de,{type:"button",onClick:()=>t({name:"",value:""}),size:e.length===0?"md":"sm",className:"",children:[o.jsx(Vr,{}),e.length===0?"Add Header":"Add Another Header"]})]})]})]}),yAr=({index:e,header:t,onRemove:n})=>{const r=g.useId(),s=g.useId();return o.jsxs("div",{className:"grid grid-cols-[1fr_1fr_auto] gap-4 items-end",children:[o.jsx(yO,{id:r,name:`headers.${e}.name`,label:"Name",placeholder:"e.g. Authorization",required:!0,defaultValue:t.name}),o.jsx(yO,{id:s,name:`headers.${e}.value`,label:"Value",placeholder:"e.g. Bearer <token>",required:!0,defaultValue:t.value}),o.jsx(de,{type:"button",onClick:n,"aria-label":"Remove header",tooltip:"Remove header",children:o.jsx(pbe,{})})]})},lRt=({initialConfig:e,onSave:t})=>{const{setConfig:n}=qxe(),[r,s]=g.useState(()=>e?Object.entries(e.headers).map(([c,u])=>({name:c,value:u})):[]),a=c=>{c.preventDefault();const u=new FormData(c.target),d=u.get("url"),f=(u.get("apiPrefix")??"").trim(),p=f.length?f:void 0,h={};for(let m=0;m<r.length;m++){const v=u.get(`headers.${m}.name`),y=u.get(`headers.${m}.value`);h[v]=y}n({headers:h,baseUrl:d,apiPrefix:p}),t?.(),De.success("Configuration saved")},i=c=>{s(u=>[...u,c])},l=c=>{s(u=>u.filter((d,f)=>f!==c))};return o.jsx(sc,{delayDuration:0,children:o.jsxs("form",{onSubmit:a,className:"space-y-6",children:[o.jsx(yO,{name:"url",label:"Mastra instance URL",placeholder:"e.g: http://localhost:4111",required:!0,defaultValue:e?.baseUrl}),o.jsx(yO,{name:"apiPrefix",label:"API prefix",placeholder:"e.g: /api (default)",defaultValue:e?.apiPrefix||""}),o.jsx(vAr,{headers:r,onAddHeader:i,onRemoveHeader:l}),o.jsxs(de,{type:"submit",className:"mt-10! ml-auto",children:[o.jsx(gd,{}),"Save Configuration"]})]})})};function v_e({code:e,options:t,value:n,onValueChange:r,selector:s="select",fileName:a,lang:i,overflow:l="wrap",copyMessage:c,copyTooltip:u,actions:d,className:f}){const p=t&&t.length>0,h=p&&s==="tabs",m=p&&s==="select",v=n??t?.[0]?.value;return o.jsxs("figure",{className:K("group relative flex w-full flex-col overflow-hidden rounded-2xl border border-border2/40 bg-surface2",f),children:[h&&t&&o.jsx(cu,{defaultTab:t[0].value,value:v,onValueChange:r??(()=>{}),children:o.jsxs("div",{className:"flex items-stretch",children:[o.jsx("div",{className:"min-w-0 flex-1",children:o.jsx(uu,{children:t.map(y=>o.jsx(qr,{value:y.value,children:y.label},y.value))})}),d&&o.jsx("div",{className:"flex shrink-0 items-center border-b border-border1 pr-2 pl-3",children:d})]})}),m&&t&&o.jsxs("div",{className:"flex items-center border-b border-border2/40 px-2 py-1.5",children:[o.jsxs(da,{value:v,onValueChange:r,children:[o.jsx(pa,{size:"sm",variant:"ghost",children:o.jsx(fa,{})}),o.jsx(ha,{children:t.map(y=>o.jsx(Lr,{value:y.value,children:y.label},y.value))})]}),d&&o.jsx("div",{className:"ml-auto flex items-center",children:d})]}),!p&&a&&o.jsxs("div",{className:"flex items-center border-b border-border2/40 px-4 py-2",children:[o.jsx("figcaption",{className:"font-mono text-ui-sm text-neutral4",children:a}),d&&o.jsx("div",{className:"ml-auto flex items-center",children:d})]}),!p&&!a&&d&&o.jsx("div",{className:"flex items-center justify-end border-b border-border2/40 px-2 py-1.5",children:d}),o.jsxs("div",{className:"relative",children:[o.jsx(kIt,{code:e,lang:i,className:K("px-4 py-3 font-mono text-ui-sm text-neutral5",l==="scroll"?"overflow-x-auto whitespace-pre":"whitespace-pre-wrap break-all")}),o.jsx(Oa,{content:e,copyMessage:c,tooltip:u,size:"sm",className:K("absolute top-2 right-2 opacity-100 pointer-fine:opacity-0 group-hover:opacity-100 group-focus-within:opacity-100",ms.opacity)})]})]})}const a4=()=>{const e=We();return wt({queryKey:["mastra-packages"],queryFn:()=>e.getSystemPackages()})};var x9={exports:{}},_ne,gHe;function i4(){if(gHe)return _ne;gHe=1;const e="2.0.0",t=256,n=Number.MAX_SAFE_INTEGER||9007199254740991,r=16,s=t-6;return _ne={MAX_LENGTH:t,MAX_SAFE_COMPONENT_LENGTH:r,MAX_SAFE_BUILD_LENGTH:s,MAX_SAFE_INTEGER:n,RELEASE_TYPES:["major","premajor","minor","preminor","patch","prepatch","prerelease"],SEMVER_SPEC_VERSION:e,FLAG_INCLUDE_PRERELEASE:1,FLAG_LOOSE:2},_ne}var Cne,vHe;function CW(){if(vHe)return Cne;vHe=1;var e={},t={};return Cne=typeof e=="object"&&t&&t.NODE_DEBUG&&/\bsemver\b/i.test(t.NODE_DEBUG)?(...r)=>console.error("SEMVER",...r):()=>{},Cne}var yHe;function o4(){return yHe||(yHe=1,(function(e,t){const{MAX_SAFE_COMPONENT_LENGTH:n,MAX_SAFE_BUILD_LENGTH:r,MAX_LENGTH:s}=i4(),a=CW();t=e.exports={};const i=t.re=[],l=t.safeRe=[],c=t.src=[],u=t.safeSrc=[],d=t.t={};let f=0;const p="[a-zA-Z0-9-]",h=[["\\s",1],["\\d",s],[p,r]],m=y=>{for(const[b,S]of h)y=y.split(`${b}*`).join(`${b}{0,${S}}`).split(`${b}+`).join(`${b}{1,${S}}`);return y},v=(y,b,S)=>{const w=m(b),k=f++;a(y,k,b),d[y]=k,c[k]=b,u[k]=w,i[k]=new RegExp(b,S?"g":void 0),l[k]=new RegExp(w,S?"g":void 0)};v("NUMERICIDENTIFIER","0|[1-9]\\d*"),v("NUMERICIDENTIFIERLOOSE","\\d+"),v("NONNUMERICIDENTIFIER",`\\d*[a-zA-Z-]${p}*`),v("MAINVERSION",`(${c[d.NUMERICIDENTIFIER]})\\.(${c[d.NUMERICIDENTIFIER]})\\.(${c[d.NUMERICIDENTIFIER]})`),v("MAINVERSIONLOOSE",`(${c[d.NUMERICIDENTIFIERLOOSE]})\\.(${c[d.NUMERICIDENTIFIERLOOSE]})\\.(${c[d.NUMERICIDENTIFIERLOOSE]})`),v("PRERELEASEIDENTIFIER",`(?:${c[d.NONNUMERICIDENTIFIER]}|${c[d.NUMERICIDENTIFIER]})`),v("PRERELEASEIDENTIFIERLOOSE",`(?:${c[d.NONNUMERICIDENTIFIER]}|${c[d.NUMERICIDENTIFIERLOOSE]})`),v("PRERELEASE",`(?:-(${c[d.PRERELEASEIDENTIFIER]}(?:\\.${c[d.PRERELEASEIDENTIFIER]})*))`),v("PRERELEASELOOSE",`(?:-?(${c[d.PRERELEASEIDENTIFIERLOOSE]}(?:\\.${c[d.PRERELEASEIDENTIFIERLOOSE]})*))`),v("BUILDIDENTIFIER",`${p}+`),v("BUILD",`(?:\\+(${c[d.BUILDIDENTIFIER]}(?:\\.${c[d.BUILDIDENTIFIER]})*))`),v("FULLPLAIN",`v?${c[d.MAINVERSION]}${c[d.PRERELEASE]}?${c[d.BUILD]}?`),v("FULL",`^${c[d.FULLPLAIN]}$`),v("LOOSEPLAIN",`[v=\\s]*${c[d.MAINVERSIONLOOSE]}${c[d.PRERELEASELOOSE]}?${c[d.BUILD]}?`),v("LOOSE",`^${c[d.LOOSEPLAIN]}$`),v("GTLT","((?:<|>)?=?)"),v("XRANGEIDENTIFIERLOOSE",`${c[d.NUMERICIDENTIFIERLOOSE]}|x|X|\\*`),v("XRANGEIDENTIFIER",`${c[d.NUMERICIDENTIFIER]}|x|X|\\*`),v("XRANGEPLAIN",`[v=\\s]*(${c[d.XRANGEIDENTIFIER]})(?:\\.(${c[d.XRANGEIDENTIFIER]})(?:\\.(${c[d.XRANGEIDENTIFIER]})(?:${c[d.PRERELEASE]})?${c[d.BUILD]}?)?)?`),v("XRANGEPLAINLOOSE",`[v=\\s]*(${c[d.XRANGEIDENTIFIERLOOSE]})(?:\\.(${c[d.XRANGEIDENTIFIERLOOSE]})(?:\\.(${c[d.XRANGEIDENTIFIERLOOSE]})(?:${c[d.PRERELEASELOOSE]})?${c[d.BUILD]}?)?)?`),v("XRANGE",`^${c[d.GTLT]}\\s*${c[d.XRANGEPLAIN]}$`),v("XRANGELOOSE",`^${c[d.GTLT]}\\s*${c[d.XRANGEPLAINLOOSE]}$`),v("COERCEPLAIN",`(^|[^\\d])(\\d{1,${n}})(?:\\.(\\d{1,${n}}))?(?:\\.(\\d{1,${n}}))?`),v("COERCE",`${c[d.COERCEPLAIN]}(?:$|[^\\d])`),v("COERCEFULL",c[d.COERCEPLAIN]+`(?:${c[d.PRERELEASE]})?(?:${c[d.BUILD]})?(?:$|[^\\d])`),v("COERCERTL",c[d.COERCE],!0),v("COERCERTLFULL",c[d.COERCEFULL],!0),v("LONETILDE","(?:~>?)"),v("TILDETRIM",`(\\s*)${c[d.LONETILDE]}\\s+`,!0),t.tildeTrimReplace="$1~",v("TILDE",`^${c[d.LONETILDE]}${c[d.XRANGEPLAIN]}$`),v("TILDELOOSE",`^${c[d.LONETILDE]}${c[d.XRANGEPLAINLOOSE]}$`),v("LONECARET","(?:\\^)"),v("CARETTRIM",`(\\s*)${c[d.LONECARET]}\\s+`,!0),t.caretTrimReplace="$1^",v("CARET",`^${c[d.LONECARET]}${c[d.XRANGEPLAIN]}$`),v("CARETLOOSE",`^${c[d.LONECARET]}${c[d.XRANGEPLAINLOOSE]}$`),v("COMPARATORLOOSE",`^${c[d.GTLT]}\\s*(${c[d.LOOSEPLAIN]})$|^$`),v("COMPARATOR",`^${c[d.GTLT]}\\s*(${c[d.FULLPLAIN]})$|^$`),v("COMPARATORTRIM",`(\\s*)${c[d.GTLT]}\\s*(${c[d.LOOSEPLAIN]}|${c[d.XRANGEPLAIN]})`,!0),t.comparatorTrimReplace="$1$2$3",v("HYPHENRANGE",`^\\s*(${c[d.XRANGEPLAIN]})\\s+-\\s+(${c[d.XRANGEPLAIN]})\\s*$`),v("HYPHENRANGELOOSE",`^\\s*(${c[d.XRANGEPLAINLOOSE]})\\s+-\\s+(${c[d.XRANGEPLAINLOOSE]})\\s*$`),v("STAR","(<|>)?=?\\s*\\*"),v("GTE0","^\\s*>=\\s*0\\.0\\.0\\s*$"),v("GTE0PRE","^\\s*>=\\s*0\\.0\\.0-0\\s*$")})(x9,x9.exports)),x9.exports}var Ene,bHe;function y_e(){if(bHe)return Ene;bHe=1;const e=Object.freeze({loose:!0}),t=Object.freeze({});return Ene=r=>r?typeof r!="object"?e:r:t,Ene}var jne,xHe;function cRt(){if(xHe)return jne;xHe=1;const e=/^[0-9]+$/,t=(r,s)=>{if(typeof r=="number"&&typeof s=="number")return r===s?0:r<s?-1:1;const a=e.test(r),i=e.test(s);return a&&i&&(r=+r,s=+s),r===s?0:a&&!i?-1:i&&!a?1:r<s?-1:1};return jne={compareIdentifiers:t,rcompareIdentifiers:(r,s)=>t(s,r)},jne}var Tne,wHe;function Wu(){if(wHe)return Tne;wHe=1;const e=CW(),{MAX_LENGTH:t,MAX_SAFE_INTEGER:n}=i4(),{safeRe:r,t:s}=o4(),a=y_e(),{compareIdentifiers:i}=cRt(),l=(u,d)=>{const f=d.split(".");if(f.length>u.length)return!1;for(let p=0;p<f.length;p++)if(i(u[p],f[p])!==0)return!1;return!0};class c{constructor(d,f){if(f=a(f),d instanceof c){if(d.loose===!!f.loose&&d.includePrerelease===!!f.includePrerelease)return d;d=d.version}else if(typeof d!="string")throw new TypeError(`Invalid version. Must be a string. Got type "${typeof d}".`);if(d.length>t)throw new TypeError(`version is longer than ${t} characters`);e("SemVer",d,f),this.options=f,this.loose=!!f.loose,this.includePrerelease=!!f.includePrerelease;const p=d.trim().match(f.loose?r[s.LOOSE]:r[s.FULL]);if(!p)throw new TypeError(`Invalid Version: ${d}`);if(this.raw=d,this.major=+p[1],this.minor=+p[2],this.patch=+p[3],this.major>n||this.major<0)throw new TypeError("Invalid major version");if(this.minor>n||this.minor<0)throw new TypeError("Invalid minor version");if(this.patch>n||this.patch<0)throw new TypeError("Invalid patch version");p[4]?this.prerelease=p[4].split(".").map(h=>{if(/^[0-9]+$/.test(h)){const m=+h;if(m>=0&&m<n)return m}return h}):this.prerelease=[],this.build=p[5]?p[5].split("."):[],this.format()}format(){return this.version=`${this.major}.${this.minor}.${this.patch}`,this.prerelease.length&&(this.version+=`-${this.prerelease.join(".")}`),this.version}toString(){return this.version}compare(d){if(e("SemVer.compare",this.version,this.options,d),!(d instanceof c)){if(typeof d=="string"&&d===this.version)return 0;d=new c(d,this.options)}return d.version===this.version?0:this.compareMain(d)||this.comparePre(d)}compareMain(d){return d instanceof c||(d=new c(d,this.options)),this.major<d.major?-1:this.major>d.major?1:this.minor<d.minor?-1:this.minor>d.minor?1:this.patch<d.patch?-1:this.patch>d.patch?1:0}comparePre(d){if(d instanceof c||(d=new c(d,this.options)),this.prerelease.length&&!d.prerelease.length)return-1;if(!this.prerelease.length&&d.prerelease.length)return 1;if(!this.prerelease.length&&!d.prerelease.length)return 0;let f=0;do{const p=this.prerelease[f],h=d.prerelease[f];if(e("prerelease compare",f,p,h),p===void 0&&h===void 0)return 0;if(h===void 0)return 1;if(p===void 0)return-1;if(p===h)continue;return i(p,h)}while(++f)}compareBuild(d){d instanceof c||(d=new c(d,this.options));let f=0;do{const p=this.build[f],h=d.build[f];if(e("build compare",f,p,h),p===void 0&&h===void 0)return 0;if(h===void 0)return 1;if(p===void 0)return-1;if(p===h)continue;return i(p,h)}while(++f)}inc(d,f,p){if(d.startsWith("pre")){if(!f&&p===!1)throw new Error("invalid increment argument: identifier is empty");if(f){const h=`-${f}`.match(this.options.loose?r[s.PRERELEASELOOSE]:r[s.PRERELEASE]);if(!h||h[1]!==f)throw new Error(`invalid identifier: ${f}`)}}switch(d){case"premajor":this.prerelease.length=0,this.patch=0,this.minor=0,this.major++,this.inc("pre",f,p);break;case"preminor":this.prerelease.length=0,this.patch=0,this.minor++,this.inc("pre",f,p);break;case"prepatch":this.prerelease.length=0,this.inc("patch",f,p),this.inc("pre",f,p);break;case"prerelease":this.prerelease.length===0&&this.inc("patch",f,p),this.inc("pre",f,p);break;case"release":if(this.prerelease.length===0)throw new Error(`version ${this.raw} is not a prerelease`);this.prerelease.length=0;break;case"major":(this.minor!==0||this.patch!==0||this.prerelease.length===0)&&this.major++,this.minor=0,this.patch=0,this.prerelease=[];break;case"minor":(this.patch!==0||this.prerelease.length===0)&&this.minor++,this.patch=0,this.prerelease=[];break;case"patch":this.prerelease.length===0&&this.patch++,this.prerelease=[];break;case"pre":{const h=Number(p)?1:0;if(this.prerelease.length===0)this.prerelease=[h];else{let m=this.prerelease.length;for(;--m>=0;)typeof this.prerelease[m]=="number"&&(this.prerelease[m]++,m=-2);if(m===-1){if(f===this.prerelease.join(".")&&p===!1)throw new Error("invalid increment argument: identifier already exists");this.prerelease.push(h)}}if(f){let m=[f,h];if(p===!1&&(m=[f]),l(this.prerelease,f)){const v=this.prerelease[f.split(".").length];isNaN(v)&&(this.prerelease=m)}else this.prerelease=m}break}default:throw new Error(`invalid increment argument: ${d}`)}return this.raw=this.format(),this.build.length&&(this.raw+=`+${this.build.join(".")}`),this}}return Tne=c,Tne}var Nne,SHe;function W_(){if(SHe)return Nne;SHe=1;const e=Wu();return Nne=(n,r,s=!1)=>{if(n instanceof e)return n;try{return new e(n,r)}catch(a){if(!s)return null;throw a}},Nne}var Ine,kHe;function bAr(){if(kHe)return Ine;kHe=1;const e=W_();return Ine=(n,r)=>{const s=e(n,r);return s?s.version:null},Ine}var Ane,OHe;function xAr(){if(OHe)return Ane;OHe=1;const e=W_();return Ane=(n,r)=>{const s=e(n.trim().replace(/^[=v]+/,""),r);return s?s.version:null},Ane}var Rne,_He;function wAr(){if(_He)return Rne;_He=1;const e=Wu();return Rne=(n,r,s,a,i)=>{typeof s=="string"&&(i=a,a=s,s=void 0);try{return new e(n instanceof e?n.version:n,s).inc(r,a,i).version}catch{return null}},Rne}var Pne,CHe;function SAr(){if(CHe)return Pne;CHe=1;const e=W_();return Pne=(n,r)=>{const s=e(n,null,!0),a=e(r,null,!0),i=s.compare(a);if(i===0)return null;const l=i>0,c=l?s:a,u=l?a:s,d=!!c.prerelease.length;if(!!u.prerelease.length&&!d){if(!u.patch&&!u.minor)return"major";if(u.compareMain(c)===0)return u.minor&&!u.patch?"minor":"patch"}const p=d?"pre":"";return s.major!==a.major?p+"major":s.minor!==a.minor?p+"minor":s.patch!==a.patch?p+"patch":"prerelease"},Pne}var $ne,EHe;function kAr(){if(EHe)return $ne;EHe=1;const e=Wu();return $ne=(n,r)=>new e(n,r).major,$ne}var Mne,jHe;function OAr(){if(jHe)return Mne;jHe=1;const e=Wu();return Mne=(n,r)=>new e(n,r).minor,Mne}var Dne,THe;function _Ar(){if(THe)return Dne;THe=1;const e=Wu();return Dne=(n,r)=>new e(n,r).patch,Dne}var Lne,NHe;function CAr(){if(NHe)return Lne;NHe=1;const e=W_();return Lne=(n,r)=>{const s=e(n,r);return s&&s.prerelease.length?s.prerelease:null},Lne}var Fne,IHe;function Hg(){if(IHe)return Fne;IHe=1;const e=Wu();return Fne=(n,r,s)=>new e(n,s).compare(new e(r,s)),Fne}var zne,AHe;function EAr(){if(AHe)return zne;AHe=1;const e=Hg();return zne=(n,r,s)=>e(r,n,s),zne}var Bne,RHe;function jAr(){if(RHe)return Bne;RHe=1;const e=Hg();return Bne=(n,r)=>e(n,r,!0),Bne}var Une,PHe;function b_e(){if(PHe)return Une;PHe=1;const e=Wu();return Une=(n,r,s)=>{const a=new e(n,s),i=new e(r,s);return a.compare(i)||a.compareBuild(i)},Une}var qne,$He;function TAr(){if($He)return qne;$He=1;const e=b_e();return qne=(n,r)=>n.sort((s,a)=>e(s,a,r)),qne}var Vne,MHe;function NAr(){if(MHe)return Vne;MHe=1;const e=b_e();return Vne=(n,r)=>n.sort((s,a)=>e(a,s,r)),Vne}var Hne,DHe;function EW(){if(DHe)return Hne;DHe=1;const e=Hg();return Hne=(n,r,s)=>e(n,r,s)>0,Hne}var Wne,LHe;function x_e(){if(LHe)return Wne;LHe=1;const e=Hg();return Wne=(n,r,s)=>e(n,r,s)<0,Wne}var Zne,FHe;function uRt(){if(FHe)return Zne;FHe=1;const e=Hg();return Zne=(n,r,s)=>e(n,r,s)===0,Zne}var Gne,zHe;function dRt(){if(zHe)return Gne;zHe=1;const e=Hg();return Gne=(n,r,s)=>e(n,r,s)!==0,Gne}var Qne,BHe;function w_e(){if(BHe)return Qne;BHe=1;const e=Hg();return Qne=(n,r,s)=>e(n,r,s)>=0,Qne}var Yne,UHe;function S_e(){if(UHe)return Yne;UHe=1;const e=Hg();return Yne=(n,r,s)=>e(n,r,s)<=0,Yne}var Xne,qHe;function fRt(){if(qHe)return Xne;qHe=1;const e=uRt(),t=dRt(),n=EW(),r=w_e(),s=x_e(),a=S_e();return Xne=(l,c,u,d)=>{switch(c){case"===":return typeof l=="object"&&(l=l.version),typeof u=="object"&&(u=u.version),l===u;case"!==":return typeof l=="object"&&(l=l.version),typeof u=="object"&&(u=u.version),l!==u;case"":case"=":case"==":return e(l,u,d);case"!=":return t(l,u,d);case">":return n(l,u,d);case">=":return r(l,u,d);case"<":return s(l,u,d);case"<=":return a(l,u,d);default:throw new TypeError(`Invalid operator: ${c}`)}},Xne}var Kne,VHe;function IAr(){if(VHe)return Kne;VHe=1;const e=Wu(),t=W_(),{safeRe:n,t:r}=o4();return Kne=(a,i)=>{if(a instanceof e)return a;if(typeof a=="number"&&(a=String(a)),typeof a!="string")return null;i=i||{};let l=null;if(!i.rtl)l=a.match(i.includePrerelease?n[r.COERCEFULL]:n[r.COERCE]);else{const h=i.includePrerelease?n[r.COERCERTLFULL]:n[r.COERCERTL];let m;for(;(m=h.exec(a))&&(!l||l.index+l[0].length!==a.length);)(!l||m.index+m[0].length!==l.index+l[0].length)&&(l=m),h.lastIndex=m.index+m[1].length+m[2].length;h.lastIndex=-1}if(l===null)return null;const c=l[2],u=l[3]||"0",d=l[4]||"0",f=i.includePrerelease&&l[5]?`-${l[5]}`:"",p=i.includePrerelease&&l[6]?`+${l[6]}`:"";return t(`${c}.${u}.${d}${f}${p}`,i)},Kne}var Jne,HHe;function AAr(){if(HHe)return Jne;HHe=1;const e=W_(),t=i4(),n=Wu(),r=(l,c,u)=>{if(!t.RELEASE_TYPES.includes(c))return null;const d=s(l,u);return d&&a(d,c)},s=(l,c)=>{const u=l instanceof n?l.version:l;return e(u,c)},a=(l,c)=>{if(i(c))return l.version;switch(l.prerelease=[],c){case"major":l.minor=0,l.patch=0;break;case"minor":l.patch=0;break}return l.format()},i=l=>l.startsWith("pre");return Jne=r,Jne}var ere,WHe;function RAr(){if(WHe)return ere;WHe=1;class e{constructor(){this.max=1e3,this.map=new Map}get(n){const r=this.map.get(n);if(r!==void 0)return this.map.delete(n),this.map.set(n,r),r}delete(n){return this.map.delete(n)}set(n,r){if(!this.delete(n)&&r!==void 0){if(this.map.size>=this.max){const a=this.map.keys().next().value;this.delete(a)}this.map.set(n,r)}return this}}return ere=e,ere}var tre,ZHe;function Wg(){if(ZHe)return tre;ZHe=1;const e=/\s+/g;class t{constructor(z,B){if(B=s(B),z instanceof t)return z.loose===!!B.loose&&z.includePrerelease===!!B.includePrerelease?z:new t(z.raw,B);if(z instanceof a)return this.raw=z.value,this.set=[[z]],this.formatted=void 0,this;if(this.options=B,this.loose=!!B.loose,this.includePrerelease=!!B.includePrerelease,this.raw=z.trim().replace(e," "),this.set=this.raw.split("||").map(D=>this.parseRange(D.trim())).filter(D=>D.length),!this.set.length)throw new TypeError(`Invalid SemVer Range: ${this.raw}`);if(this.set.length>1){const D=this.set[0];if(this.set=this.set.filter(Q=>!b(Q[0])),this.set.length===0)this.set=[D];else if(this.set.length>1){for(const Q of this.set)if(Q.length===1&&S(Q[0])){this.set=[Q];break}}}this.formatted=void 0}get range(){if(this.formatted===void 0){this.formatted="";for(let z=0;z<this.set.length;z++){z>0&&(this.formatted+="||");const B=this.set[z];for(let D=0;D<B.length;D++)D>0&&(this.formatted+=" "),this.formatted+=B[D].toString().trim()}}return this.formatted}format(){return this.range}toString(){return this.range}parseRange(z){z=z.replace(y,"");const D=((this.options.includePrerelease&&m)|(this.options.loose&&v))+":"+z,Q=r.get(D);if(Q)return Q;const V=this.options.loose,$=V?c[d.HYPHENRANGELOOSE]:c[d.HYPHENRANGE];z=z.replace($,q(this.options.includePrerelease)),i("hyphen replace",z),z=z.replace(c[d.COMPARATORTRIM],f),i("comparator trim",z),z=z.replace(c[d.TILDETRIM],p),i("tilde trim",z),z=z.replace(c[d.CARETTRIM],h),i("caret trim",z);let U=z.split(" ").map(J=>k(J,this.options)).join(" ").split(/\s+/).map(J=>M(J,this.options));V&&(U=U.filter(J=>(i("loose invalid filter",J,this.options),!!J.match(c[d.COMPARATORLOOSE])))),i("range list",U);const Z=new Map,X=U.map(J=>new a(J,this.options));for(const J of X){if(b(J))return[J];Z.set(J.value,J)}Z.size>1&&Z.has("")&&Z.delete("");const te=[...Z.values()];return r.set(D,te),te}intersects(z,B){if(!(z instanceof t))throw new TypeError("a Range is required");return this.set.some(D=>w(D,B)&&z.set.some(Q=>w(Q,B)&&D.every(V=>Q.every($=>V.intersects($,B)))))}test(z){if(!z)return!1;if(typeof z=="string")try{z=new l(z,this.options)}catch{return!1}for(let B=0;B<this.set.length;B++)if(H(this.set[B],z,this.options))return!0;return!1}}tre=t;const n=RAr(),r=new n,s=y_e(),a=jW(),i=CW(),l=Wu(),{safeRe:c,src:u,t:d,comparatorTrimReplace:f,tildeTrimReplace:p,caretTrimReplace:h}=o4(),{FLAG_INCLUDE_PRERELEASE:m,FLAG_LOOSE:v}=i4(),y=new RegExp(u[d.BUILD],"g"),b=F=>F.value==="<0.0.0-0",S=F=>F.value==="",w=(F,z)=>{let B=!0;const D=F.slice();let Q=D.pop();for(;B&&D.length;)B=D.every(V=>Q.intersects(V,z)),Q=D.pop();return B},k=(F,z)=>(F=F.replace(c[d.BUILD],""),i("comp",F,z),F=N(F,z),i("caret",F),F=E(F,z),i("tildes",F),F=R(F,z),i("xrange",F),F=L(F,z),i("stars",F),F),_=F=>!F||F.toLowerCase()==="x"||F==="*",C=(F,z,B)=>_(F)&&!_(z)||_(z)&&B&&!_(B),E=(F,z)=>F.trim().split(/\s+/).map(B=>j(B,z)).join(" "),j=(F,z)=>{const B=z.loose?c[d.TILDELOOSE]:c[d.TILDE];return F.replace(B,(D,Q,V,$,U)=>{i("tilde",F,D,Q,V,$,U);let Z;return _(Q)?Z="":_(V)?Z=`>=${Q}.0.0 <${+Q+1}.0.0-0`:_($)?Z=`>=${Q}.${V}.0 <${Q}.${+V+1}.0-0`:U?(i("replaceTilde pr",U),Z=`>=${Q}.${V}.${$}-${U} <${Q}.${+V+1}.0-0`):Z=`>=${Q}.${V}.${$} <${Q}.${+V+1}.0-0`,i("tilde return",Z),Z})},N=(F,z)=>F.trim().split(/\s+/).map(B=>I(B,z)).join(" "),I=(F,z)=>{i("caret",F,z);const B=z.loose?c[d.CARETLOOSE]:c[d.CARET],D=z.includePrerelease?"-0":"";return F.replace(B,(Q,V,$,U,Z)=>{i("caret",F,Q,V,$,U,Z);let X;return _(V)?X="":_($)?X=`>=${V}.0.0${D} <${+V+1}.0.0-0`:_(U)?V==="0"?X=`>=${V}.${$}.0${D} <${V}.${+$+1}.0-0`:X=`>=${V}.${$}.0${D} <${+V+1}.0.0-0`:Z?(i("replaceCaret pr",Z),V==="0"?$==="0"?X=`>=${V}.${$}.${U}-${Z} <${V}.${$}.${+U+1}-0`:X=`>=${V}.${$}.${U}-${Z} <${V}.${+$+1}.0-0`:X=`>=${V}.${$}.${U}-${Z} <${+V+1}.0.0-0`):(i("no pr"),V==="0"?$==="0"?X=`>=${V}.${$}.${U} <${V}.${$}.${+U+1}-0`:X=`>=${V}.${$}.${U} <${V}.${+$+1}.0-0`:X=`>=${V}.${$}.${U} <${+V+1}.0.0-0`),i("caret return",X),X})},R=(F,z)=>(i("replaceXRanges",F,z),F.split(/\s+/).map(B=>P(B,z)).join(" ")),P=(F,z)=>{F=F.trim();const B=z.loose?c[d.XRANGELOOSE]:c[d.XRANGE];return F.replace(B,(D,Q,V,$,U,Z)=>{if(i("xRange",F,D,Q,V,$,U,Z),C(V,$,U))return F;const X=_(V),te=X||_($),J=te||_(U),ee=J;return Q==="="&&ee&&(Q=""),Z=z.includePrerelease?"-0":"",X?Q===">"||Q==="<"?D="<0.0.0-0":D="*":Q&&ee?(te&&($=0),U=0,Q===">"?(Q=">=",te?(V=+V+1,$=0,U=0):($=+$+1,U=0)):Q==="<="&&(Q="<",te?V=+V+1:$=+$+1),Q==="<"&&(Z="-0"),D=`${Q+V}.${$}.${U}${Z}`):te?D=`>=${V}.0.0${Z} <${+V+1}.0.0-0`:J&&(D=`>=${V}.${$}.0${Z} <${V}.${+$+1}.0-0`),i("xRange return",D),D})},L=(F,z)=>(i("replaceStars",F,z),F.trim().replace(c[d.STAR],"")),M=(F,z)=>(i("replaceGTE0",F,z),F.trim().replace(c[z.includePrerelease?d.GTE0PRE:d.GTE0],"")),q=F=>(z,B,D,Q,V,$,U,Z,X,te,J,ee)=>(_(D)?B="":_(Q)?B=`>=${D}.0.0${F?"-0":""}`:_(V)?B=`>=${D}.${Q}.0${F?"-0":""}`:$?B=`>=${B}`:B=`>=${B}${F?"-0":""}`,_(X)?Z="":_(te)?Z=`<${+X+1}.0.0-0`:_(J)?Z=`<${X}.${+te+1}.0-0`:ee?Z=`<=${X}.${te}.${J}-${ee}`:F?Z=`<${X}.${te}.${+J+1}-0`:Z=`<=${Z}`,`${B} ${Z}`.trim()),H=(F,z,B)=>{for(let D=0;D<F.length;D++)if(!F[D].test(z))return!1;if(z.prerelease.length&&!B.includePrerelease){for(let D=0;D<F.length;D++)if(i(F[D].semver),F[D].semver!==a.ANY&&F[D].semver.prerelease.length>0){const Q=F[D].semver;if(Q.major===z.major&&Q.minor===z.minor&&Q.patch===z.patch)return!0}return!1}return!0};return tre}var nre,GHe;function jW(){if(GHe)return nre;GHe=1;const e=Symbol("SemVer ANY");class t{static get ANY(){return e}constructor(d,f){if(f=n(f),d instanceof t){if(d.loose===!!f.loose)return d;d=d.value}d=d.trim().split(/\s+/).join(" "),i("comparator",d,f),this.options=f,this.loose=!!f.loose,this.parse(d),this.semver===e?this.value="":this.value=this.operator+this.semver.version,i("comp",this)}parse(d){const f=this.options.loose?r[s.COMPARATORLOOSE]:r[s.COMPARATOR],p=d.match(f);if(!p)throw new TypeError(`Invalid comparator: ${d}`);this.operator=p[1]!==void 0?p[1]:"",this.operator==="="&&(this.operator=""),p[2]?this.semver=new l(p[2],this.options.loose):this.semver=e}toString(){return this.value}test(d){if(i("Comparator.test",d,this.options.loose),this.semver===e||d===e)return!0;if(typeof d=="string")try{d=new l(d,this.options)}catch{return!1}return a(d,this.operator,this.semver,this.options)}intersects(d,f){if(!(d instanceof t))throw new TypeError("a Comparator is required");return this.operator===""?this.value===""?!0:new c(d.value,f).test(this.value):d.operator===""?d.value===""?!0:new c(this.value,f).test(d.semver):(f=n(f),f.includePrerelease&&(this.value==="<0.0.0-0"||d.value==="<0.0.0-0")||!f.includePrerelease&&(this.value.startsWith("<0.0.0")||d.value.startsWith("<0.0.0"))?!1:!!(this.operator.startsWith(">")&&d.operator.startsWith(">")||this.operator.startsWith("<")&&d.operator.startsWith("<")||this.semver.version===d.semver.version&&this.operator.includes("=")&&d.operator.includes("=")||a(this.semver,"<",d.semver,f)&&this.operator.startsWith(">")&&d.operator.startsWith("<")||a(this.semver,">",d.semver,f)&&this.operator.startsWith("<")&&d.operator.startsWith(">")))}}nre=t;const n=y_e(),{safeRe:r,t:s}=o4(),a=fRt(),i=CW(),l=Wu(),c=Wg();return nre}var rre,QHe;function TW(){if(QHe)return rre;QHe=1;const e=Wg();return rre=(n,r,s)=>{try{r=new e(r,s)}catch{return!1}return r.test(n)},rre}var sre,YHe;function PAr(){if(YHe)return sre;YHe=1;const e=Wg();return sre=(n,r)=>new e(n,r).set.map(s=>s.map(a=>a.value).join(" ").trim().split(" ")),sre}var are,XHe;function $Ar(){if(XHe)return are;XHe=1;const e=Wu(),t=Wg();return are=(r,s,a)=>{let i=null,l=null,c=null;try{c=new t(s,a)}catch{return null}return r.forEach(u=>{c.test(u)&&(!i||l.compare(u)===-1)&&(i=u,l=new e(i,a))}),i},are}var ire,KHe;function MAr(){if(KHe)return ire;KHe=1;const e=Wu(),t=Wg();return ire=(r,s,a)=>{let i=null,l=null,c=null;try{c=new t(s,a)}catch{return null}return r.forEach(u=>{c.test(u)&&(!i||l.compare(u)===1)&&(i=u,l=new e(i,a))}),i},ire}var ore,JHe;function DAr(){if(JHe)return ore;JHe=1;const e=Wu(),t=Wg(),n=EW();return ore=(s,a)=>{s=new t(s,a);let i=new e("0.0.0");if(s.test(i)||(i=new e("0.0.0-0"),s.test(i)))return i;i=null;for(let l=0;l<s.set.length;++l){const c=s.set[l];let u=null;c.forEach(d=>{const f=new e(d.semver.version);switch(d.operator){case">":f.prerelease.length===0?f.patch++:f.prerelease.push(0),f.raw=f.format();case"":case">=":(!u||n(f,u))&&(u=f);break;case"<":case"<=":break;default:throw new Error(`Unexpected operation: ${d.operator}`)}}),u&&(!i||n(i,u))&&(i=u)}return i&&s.test(i)?i:null},ore}var lre,eWe;function LAr(){if(eWe)return lre;eWe=1;const e=Wg();return lre=(n,r)=>{try{return new e(n,r).range||"*"}catch{return null}},lre}var cre,tWe;function k_e(){if(tWe)return cre;tWe=1;const e=Wu(),t=jW(),{ANY:n}=t,r=Wg(),s=TW(),a=EW(),i=x_e(),l=S_e(),c=w_e();return cre=(d,f,p,h)=>{d=new e(d,h),f=new r(f,h);let m,v,y,b,S;switch(p){case">":m=a,v=l,y=i,b=">",S=">=";break;case"<":m=i,v=c,y=a,b="<",S="<=";break;default:throw new TypeError('Must provide a hilo val of "<" or ">"')}if(s(d,f,h))return!1;for(let w=0;w<f.set.length;++w){const k=f.set[w];let _=null,C=null;if(k.forEach(E=>{E.semver===n&&(E=new t(">=0.0.0")),_=_||E,C=C||E,m(E.semver,_.semver,h)?_=E:y(E.semver,C.semver,h)&&(C=E)}),_.operator===b||_.operator===S||(!C.operator||C.operator===b)&&v(d,C.semver))return!1;if(C.operator===S&&y(d,C.semver))return!1}return!0},cre}var ure,nWe;function FAr(){if(nWe)return ure;nWe=1;const e=k_e();return ure=(n,r,s)=>e(n,r,">",s),ure}var dre,rWe;function zAr(){if(rWe)return dre;rWe=1;const e=k_e();return dre=(n,r,s)=>e(n,r,"<",s),dre}var fre,sWe;function BAr(){if(sWe)return fre;sWe=1;const e=Wg();return fre=(n,r,s)=>(n=new e(n,s),r=new e(r,s),n.intersects(r,s)),fre}var pre,aWe;function UAr(){if(aWe)return pre;aWe=1;const e=TW(),t=Hg();return pre=(n,r,s)=>{const a=[];let i=null,l=null;const c=n.sort((p,h)=>t(p,h,s));for(const p of c)e(p,r,s)?(l=p,i||(i=p)):(l&&a.push([i,l]),l=null,i=null);i&&a.push([i,null]);const u=[];for(const[p,h]of a)p===h?u.push(p):!h&&p===c[0]?u.push("*"):h?p===c[0]?u.push(`<=${h}`):u.push(`${p} - ${h}`):u.push(`>=${p}`);const d=u.join(" || "),f=typeof r.raw=="string"?r.raw:String(r);return d.length<f.length?d:r},pre}var hre,iWe;function qAr(){if(iWe)return hre;iWe=1;const e=Wg(),t=jW(),{ANY:n}=t,r=TW(),s=Hg(),a=(f,p,h={})=>{if(f===p)return!0;f=new e(f,h),p=new e(p,h);let m=!1;e:for(const v of f.set){for(const y of p.set){const b=c(v,y,h);if(m=m||b!==null,b)continue e}if(m)return!1}return!0},i=[new t(">=0.0.0-0")],l=[new t(">=0.0.0")],c=(f,p,h)=>{if(f===p)return!0;if(f.length===1&&f[0].semver===n){if(p.length===1&&p[0].semver===n)return!0;h.includePrerelease?f=i:f=l}if(p.length===1&&p[0].semver===n){if(h.includePrerelease)return!0;p=l}const m=new Set;let v,y;for(const j of f)j.operator===">"||j.operator===">="?v=u(v,j,h):j.operator==="<"||j.operator==="<="?y=d(y,j,h):m.add(j.semver);if(m.size>1)return null;let b;if(v&&y){if(b=s(v.semver,y.semver,h),b>0)return null;if(b===0&&(v.operator!==">="||y.operator!=="<="))return null}for(const j of m){if(v&&!r(j,String(v),h)||y&&!r(j,String(y),h))return null;for(const N of p)if(!r(j,String(N),h))return!1;return!0}let S,w,k,_,C=y&&!h.includePrerelease&&y.semver.prerelease.length?y.semver:!1,E=v&&!h.includePrerelease&&v.semver.prerelease.length?v.semver:!1;C&&C.prerelease.length===1&&y.operator==="<"&&C.prerelease[0]===0&&(C=!1);for(const j of p){if(_=_||j.operator===">"||j.operator===">=",k=k||j.operator==="<"||j.operator==="<=",v){if(E&&j.semver.prerelease&&j.semver.prerelease.length&&j.semver.major===E.major&&j.semver.minor===E.minor&&j.semver.patch===E.patch&&(E=!1),j.operator===">"||j.operator===">="){if(S=u(v,j,h),S===j&&S!==v)return!1}else if(v.operator===">="&&!j.test(v.semver))return!1}if(y){if(C&&j.semver.prerelease&&j.semver.prerelease.length&&j.semver.major===C.major&&j.semver.minor===C.minor&&j.semver.patch===C.patch&&(C=!1),j.operator==="<"||j.operator==="<="){if(w=d(y,j,h),w===j&&w!==y)return!1}else if(y.operator==="<="&&!j.test(y.semver))return!1}if(!j.operator&&(y||v)&&b!==0)return!1}return!(v&&k&&!y&&b!==0||y&&_&&!v&&b!==0||E||C)},u=(f,p,h)=>{if(!f)return p;const m=s(f.semver,p.semver,h);return m>0?f:m<0||p.operator===">"&&f.operator===">="?p:f},d=(f,p,h)=>{if(!f)return p;const m=s(f.semver,p.semver,h);return m<0?f:m>0||p.operator==="<"&&f.operator==="<="?p:f};return hre=a,hre}var mre,oWe;function VAr(){if(oWe)return mre;oWe=1;const e=o4(),t=i4(),n=Wu(),r=cRt(),s=W_(),a=bAr(),i=xAr(),l=wAr(),c=SAr(),u=kAr(),d=OAr(),f=_Ar(),p=CAr(),h=Hg(),m=EAr(),v=jAr(),y=b_e(),b=TAr(),S=NAr(),w=EW(),k=x_e(),_=uRt(),C=dRt(),E=w_e(),j=S_e(),N=fRt(),I=IAr(),R=AAr(),P=jW(),L=Wg(),M=TW(),q=PAr(),H=$Ar(),F=MAr(),z=DAr(),B=LAr(),D=k_e(),Q=FAr(),V=zAr(),$=BAr(),U=UAr(),Z=qAr();return mre={parse:s,valid:a,clean:i,inc:l,diff:c,major:u,minor:d,patch:f,prerelease:p,compare:h,rcompare:m,compareLoose:v,compareBuild:y,sort:b,rsort:S,gt:w,lt:k,eq:_,neq:C,gte:E,lte:j,cmp:N,coerce:I,truncate:R,Comparator:P,Range:L,satisfies:M,toComparators:q,maxSatisfying:H,minSatisfying:F,minVersion:z,validRange:B,outside:D,gtr:Q,ltr:V,intersects:$,simplifyRange:U,subset:Z,SemVer:n,re:e.re,src:e.src,tokens:e.t,SEMVER_SPEC_VERSION:t.SEMVER_SPEC_VERSION,RELEASE_TYPES:t.RELEASE_TYPES,compareIdentifiers:r.compareIdentifiers,rcompareIdentifiers:r.rcompareIdentifiers},mre}var HAr=VAr();const OR=Tc(HAr);async function WAr(e,t){const n=OR.prerelease(t),r=n?String(n[0]):null;try{const s=await fetch(`https://registry.npmjs.org/${encodeURIComponent(e)}`);if(!s.ok)return{name:e,version:t,latestVersion:null,isOutdated:!1,isDeprecated:!1,prereleaseTag:r,targetPrereleaseTag:null};const a=await s.json(),i=a["dist-tags"]?.latest??null,c=a.versions?.[t]?.deprecated,u=i?OR.prerelease(i):null,d=u?String(u[0]):null;let f=!1;return i!==null&&OR.valid(t)&&OR.valid(i)&&(f=OR.gt(i,t)),{name:e,version:t,latestVersion:i,isOutdated:f,isDeprecated:!!c,prereleaseTag:r,targetPrereleaseTag:d,deprecationMessage:c}}catch{return{name:e,version:t,latestVersion:null,isOutdated:!1,isDeprecated:!1,prereleaseTag:r,targetPrereleaseTag:null}}}function ZAr(e){const t=r$({queries:e.map(l=>({queryKey:["package-update",l.name,l.version],queryFn:()=>WAr(l.name,l.version),staleTime:36e5,gcTime:864e5}))}),n=t.some(l=>l.isLoading),r=t.map(l=>l.data).filter(l=>l!==void 0),s=!n&&r.length===e.length,a=s?r.filter(l=>l.isOutdated&&!l.isDeprecated).length:0,i=s?r.filter(l=>l.isDeprecated).length:0;return{packages:r,isLoading:n,outdatedCount:a,deprecatedCount:i}}const GAr=["pnpm","npm","yarn","bun"],QAr=e=>GAr.includes(e),YAr={pnpm:"pnpm add",npm:"npm install",yarn:"yarn add",bun:"bun add"},XAr="inline-flex h-[1.375rem] items-center rounded-full bg-sidebar-nav-active px-2.5 font-sans text-ui-xs font-semibold leading-none tracking-normal text-black/80 tabular-nums whitespace-nowrap dark:text-neutral6",KAr=({collapsed:e})=>{const{data:t,isLoading:n}=a4(),r=t?.packages??[],{packages:s,isLoading:a,outdatedCount:i,deprecatedCount:l}=ZAr(r),[c,u]=g.useState("pnpm");if(e||!t?.isDev)return null;if(n)return o.jsx("div",{className:"flex items-center justify-end gap-2 px-3 h-9",children:o.jsx("div",{className:"animate-pulse h-[1.125rem] w-20 bg-surface4 rounded-full"})});const d=r.find(h=>h.name==="@mastra/core");if(!d&&r.length===0)return null;const f=d?.version??r[0]?.version??"",p=JAr(s,c);return o.jsxs(br,{children:[o.jsx("div",{className:"flex px-3 py-1.5",children:o.jsx(m0e,{asChild:!0,children:o.jsx("button",{type:"button",className:"flex rounded-lg p-1 hover:bg-sidebar-nav-hover transition-colors focus-visible:outline-hidden focus-visible:ring-1 focus-visible:ring-accent1 focus-visible:shadow-focus-ring",children:o.jsxs("span",{className:"relative inline-flex",children:[(a||i>0||l>0)&&o.jsxs("span",{className:"absolute -right-1.5 -top-1.5 flex items-center gap-1",children:[a&&o.jsx(Gt,{className:"size-3 text-neutral3"}),i>0&&o.jsx(lWe,{count:i,variant:"warning"}),l>0&&o.jsx(lWe,{count:l,variant:"error"})]}),o.jsxs("span",{className:XAr,children:["v",f]})]})})})}),o.jsx(eRr,{packages:s,isLoadingUpdates:a,outdatedCount:i,deprecatedCount:l,updateCommand:p,packageManager:c,onPackageManagerChange:u})]})};function JAr(e,t){const n=e.filter(a=>a.isOutdated||a.isDeprecated);if(n.length===0)return null;const r=YAr[t],s=n.map(a=>`${a.name}@${a.targetPrereleaseTag??"latest"}`).join(" ");return`${r} ${s}`}function lWe({count:e,variant:t}){return o.jsx("span",{className:K("inline-flex items-center justify-center min-w-[1.125rem] h-[1.125rem] px-1 rounded-full text-ui-xs font-bold text-black",t==="error"?"bg-red-700":"bg-yellow-700"),children:e})}function cWe({value:e,variant:t}){return o.jsx("span",{className:K("inline-flex font-bold rounded-md px-1.5 py-0.5 items-center justify-center text-black text-xs min-w-5",t==="error"?"bg-red-700":"bg-yellow-700"),children:e})}const eRr=({packages:e,isLoadingUpdates:t,outdatedCount:n,deprecatedCount:r,updateCommand:s,packageManager:a,onPackageManagerChange:i})=>{const l=n>0||r>0,c=e.map(u=>`${u.name}@${u.version}`).join(`
|
|
511
|
-
`);return o.jsxs(xr,{className:"max-w-2xl",children:[o.jsxs(wr,{children:[o.jsx(gr,{children:"Installed Mastra Packages"}),o.jsx(Qs,{children:"View and update installed Mastra packages"})]}),o.jsxs(Rr,{children:[o.jsxs("div",{className:"flex items-center justify-between gap-3 text-sm text-neutral3 py-2",children:[t?o.jsx("span",{className:"text-neutral3",children:"Checking for updates..."}):l?o.jsxs("div",{className:"flex items-center gap-3",children:[n>0&&o.jsxs("span",{className:"flex items-center gap-1.5",children:[o.jsx(cWe,{value:n,variant:"warning"}),o.jsxs("span",{children:["package",n!==1?"s":""," outdated"]})]}),r>0&&o.jsxs("span",{className:"flex items-center gap-1.5",children:[o.jsx(cWe,{value:r,variant:"error"}),o.jsxs("span",{children:["package",r!==1?"s":""," deprecated"]})]})]}):o.jsx("span",{className:"text-accent1",children:"✓ All packages are up to date"}),o.jsx(Oa,{content:c,copyMessage:"Copied package versions!",tooltip:"Copy current versions",size:"sm"})]}),o.jsx("div",{className:"max-h-64 overflow-y-auto border border-border1 rounded-md",children:o.jsx("div",{className:"grid grid-cols-[1fr_auto_auto] text-sm",children:e.map((u,d)=>o.jsxs("div",{className:K("contents",d>0&&"[&>div]:border-t [&>div]:border-border1"),children:[o.jsx("div",{className:"py-2 px-3 font-mono text-text1 truncate min-w-0",children:o.jsxs("a",{href:`https://www.npmjs.com/package/${u.name}`,target:"_blank",rel:"noopener noreferrer",className:"hover:text-accent1 hover:underline inline-flex items-center gap-1 group",children:[u.name,o.jsx(_a,{className:"w-3 h-3 opacity-0 group-hover:opacity-100 transition-opacity"})]})}),o.jsx("div",{className:"py-2 px-3 font-mono text-neutral3 flex items-center gap-1.5",children:u.isOutdated||u.isDeprecated?o.jsxs(Wn,{children:[o.jsx(zn,{asChild:!0,children:o.jsx("span",{className:K("cursor-help",u.isDeprecated?"text-red-500":u.isOutdated?"text-yellow-500":""),children:u.version})}),o.jsx(Bn,{children:u.isDeprecated?u.deprecationMessage||"This version is deprecated":"Newer version available"})]}):o.jsx("span",{children:u.version})}),o.jsx("div",{className:"py-2 px-3 font-mono text-neutral3 flex items-center",children:(u.isOutdated||u.isDeprecated)&&u.latestVersion&&o.jsxs(o.Fragment,{children:[o.jsx(ibe,{className:"w-4 h-4 mx-2 text-neutral3"}),o.jsx("span",{className:"text-accent1",children:u.latestVersion})]})})]},u.name))})}),l&&s&&o.jsxs("div",{className:"space-y-2 pt-2 border-t border-border1",children:[o.jsxs("div",{className:"flex items-center gap-2 pt-3",children:[o.jsx(Fx,{className:"w-4 h-4 text-neutral3"}),o.jsx(ge,{as:"span",variant:"ui-sm",className:"text-neutral3",children:"Use the command below to update your packages"})]}),o.jsx(v_e,{code:s,options:[{label:"pnpm",value:"pnpm"},{label:"npm",value:"npm"},{label:"yarn",value:"yarn"},{label:"bun",value:"bun"}],value:a,onValueChange:u=>{QAr(u)&&i(u)},copyMessage:"Copied update command!",copyTooltip:"Copy command"})]})]})]})},Qh=e=>o.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 34 21",fill:"none",...e,children:o.jsx("path",{d:"M4.49805 11.6934C6.98237 11.6934 8.99609 13.7081 8.99609 16.1924C8.9959 18.6765 6.98225 20.6904 4.49805 20.6904C2.01394 20.6903 0.000196352 18.6765 0 16.1924C0 13.7081 2.01382 11.6935 4.49805 11.6934ZM10.3867 0C12.8709 0 14.8846 2.01388 14.8848 4.49805C14.8848 4.8377 14.847 5.16846 14.7755 5.48643C14.4618 6.88139 14.1953 8.4633 14.9928 9.65L16.2575 11.5319C16.3363 11.6491 16.4727 11.7115 16.6137 11.703C16.7369 11.6957 16.8525 11.6343 16.9214 11.5318L18.1876 9.64717C18.9772 8.47198 18.7236 6.90783 18.4205 5.52484C18.3523 5.21392 18.3164 4.89094 18.3164 4.55957C18.3167 2.07546 20.3313 0.0615234 22.8154 0.0615234C25.2994 0.0617476 27.3132 2.0756 27.3135 4.55957C27.3135 4.93883 27.2665 5.30712 27.178 5.65896C26.8547 6.94441 26.5817 8.37932 27.2446 9.52714L28.459 11.6301C28.4819 11.6697 28.5245 11.6934 28.5703 11.6934C31.0545 11.6935 33.0684 13.7081 33.0684 16.1924C33.0682 18.6765 31.0544 20.6903 28.5703 20.6904C26.0861 20.6904 24.0725 18.6765 24.0723 16.1924C24.0723 15.8049 24.1212 15.4288 24.2133 15.0701C24.5458 13.7746 24.8298 12.3251 24.1609 11.1668L23.0044 9.16384C22.9656 9.09659 22.8931 9.05859 22.8154 9.05859C22.7983 9.05859 22.7824 9.06614 22.7728 9.08033L21.4896 10.9895C20.686 12.1851 20.9622 13.781 21.284 15.1851C21.3582 15.5089 21.3975 15.8461 21.3975 16.1924C21.3973 18.6764 19.3834 20.6902 16.8994 20.6904C14.4152 20.6904 12.4006 18.6765 12.4004 16.1924C12.4004 15.932 12.4226 15.6768 12.4651 15.4286C12.6859 14.14 12.8459 12.7122 12.1167 11.6271L11.2419 10.3253C10.6829 9.49347 9.71913 9.05932 8.78286 8.70188C7.0906 8.05584 5.88867 6.41734 5.88867 4.49805C5.88886 2.0139 7.90254 3.29835e-05 10.3867 0Z",fill:"currentColor"})}),tRr=()=>o.jsx("div",{className:"flex flex-col h-screen w-full items-center justify-center bg-surface1",children:o.jsxs("div",{className:"max-w-md w-full mx-auto px-4 pt-4",children:[o.jsx("div",{className:"flex items-center justify-center pb-4",children:o.jsx(Qh,{className:"size-32"})}),o.jsx(lRt,{})]})}),nRr=()=>{const{data:e,isLoading:t}=a4();return{hasObservability:!!(e?.observabilityEnabled??e?.packages?.some(r=>r.name==="@mastra/observability")),isLoading:t}},Y1=()=>{const{data:e,isLoading:t}=a4();return{isCmsAvailable:!!e?.cmsEnabled,isLoading:t}},Z_=e=>{const t=We(),n=Pl();return wt({queryKey:["memory",e,n],queryFn:()=>e?t.getMemoryStatus(e,n):null,enabled:!!e,staleTime:300*1e3,gcTime:600*1e3,retry:!1})},G_=e=>{const t=We(),n=Pl();return wt({queryKey:["memory","config",e,n],queryFn:()=>e?t.getMemoryConfig({agentId:e,requestContext:n}):null,enabled:!!e,staleTime:300*1e3,gcTime:600*1e3,retry:!1,refetchOnWindowFocus:!1})},pRt=({threadId:e,agentId:t})=>{const n=We(),r=Pl();return wt({queryKey:["memory","thread",e,t,r],queryFn:()=>n.getMemoryThread({threadId:e,agentId:t}).get({requestContext:r}),enabled:!!e&&e!=="new"&&!!t,staleTime:300*1e3,gcTime:600*1e3,retry:!1,refetchOnWindowFocus:!1})},hRt=({resourceId:e,agentId:t,isMemoryEnabled:n})=>{const r=We(),s=Pl();return wt({queryKey:["memory","threads",e,t,s],queryFn:async()=>n?(await r.listMemoryThreads({resourceId:e,agentId:t,requestContext:s})).threads:null,enabled:!!n,staleTime:0,gcTime:0,retry:!1,refetchOnWindowFocus:!1})},rRr=()=>{const e=We(),t=Hr(),n=Pl();return Rn({mutationFn:({threadId:r,agentId:s})=>e.getMemoryThread({threadId:r,agentId:s}).delete({requestContext:n}),onSuccess:(r,s)=>{const{agentId:a}=s;a&&t.invalidateQueries({queryKey:["memory","threads",a,a]}),De.success("Chat deleted successfully")},onError:()=>{De.error("Failed to delete chat")}})},sRr=({agentId:e,resourceId:t,threadId:n})=>{const r=Pl(),s=We();return Rn({mutationFn:async({searchQuery:a,memoryConfig:i})=>s.searchMemory({agentId:e,resourceId:t,threadId:n,searchQuery:a,memoryConfig:i,requestContext:r})})},aRr=()=>{const e=We(),t=Hr(),n=Pl();return Rn({mutationFn:async({threadId:r,agentId:s,title:a})=>e.getMemoryThread({threadId:r,agentId:s}).clone({title:a,requestContext:n}),onSuccess:(r,s)=>{const{agentId:a}=s;a&&t.invalidateQueries({queryKey:["memory","threads",a,a]}),De.success("Thread cloned successfully")},onError:()=>{De.error("Failed to clone thread")}})},iRr=({agentId:e,resourceId:t,threadId:n,enabled:r=!0,isActive:s=!1})=>{const a=We(),i=Pl();return wt({queryKey:["observational-memory",e,t,n,i],queryFn:async()=>!t&&!n?null:a.getObservationalMemory({agentId:e,resourceId:t,threadId:n,requestContext:i}),enabled:r&&!!e&&(!!t||!!n),staleTime:s?1e3:30*1e3,gcTime:300*1e3,retry:!1,refetchOnWindowFocus:!1,refetchInterval:s?2e3:!1,placeholderData:l=>l})},mRt=({agentId:e,resourceId:t,threadId:n,pollWhenActive:r=!0})=>{const s=We(),a=Pl(),[i,l]=g.useState(!1),c=wt({queryKey:["memory-status",e,t,n,a],queryFn:()=>e?s.getMemoryStatus(e,a,{resourceId:t,threadId:n}):null,enabled:!!e,staleTime:i&&r?1e3:30*1e3,gcTime:300*1e3,retry:!1,refetchOnWindowFocus:!1,refetchInterval:i&&r?2e3:!1,placeholderData:f=>f}),u=c.data?.observationalMemory?.isObserving,d=c.data?.observationalMemory?.isReflecting;return g.useEffect(()=>{l(u||d||!1)},[u,d]),c},oRr={purple:{icon:"text-purple-700 dark:text-purple-300"},amber:{icon:"text-amber-700 dark:text-amber-300"},emerald:{icon:"text-emerald-700 dark:text-emerald-300"},sky:{icon:"text-sky-700 dark:text-sky-300"},cyan:{icon:"text-cyan-700 dark:text-cyan-300"},orange:{icon:"text-orange-700 dark:text-orange-300"}},$j=e=>e?Object.keys(e).length:0,NW=e=>e>0?String(e):"Off",gRt=e=>(e?.inputProcessors?.length??0)+(e?.outputProcessors?.length??0),vRt=e=>!!e?.result,yRt=(e,t)=>!!(t&&e&&e.editor!==!1);function yI({view:e,label:t,status:n,description:r,docsHref:s,enabled:a,tone:i,icon:l}){const c=oRr[i].icon;return e==="chip"?o.jsx("span",{"aria-label":`${t}: ${n}`,className:K("pointer-events-none inline-flex h-5 min-w-5 items-center justify-center rounded-full px-1 text-neutral3",a?c:void 0),children:o.jsx("span",{className:"size-3 shrink-0 [&>svg]:size-3",children:l})}):o.jsxs("a",{"aria-label":`${t}: ${n}`,href:s,target:"_blank",rel:"noopener noreferrer",className:K("group/capability-row flex min-w-0 items-start gap-2 rounded-md px-2 py-1.5 text-ui-xs text-neutral4 transition-colors duration-normal","hover:bg-surface4/60 hover:text-neutral6 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-border2"),children:[o.jsx("span",{className:K("mt-0.5 size-3.5 shrink-0 text-neutral3 transition-colors duration-normal [&>svg]:size-3.5",a?c:"group-hover/capability-row:text-neutral5"),children:l}),o.jsxs("span",{className:"min-w-0 flex-1",children:[o.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[o.jsx("span",{className:"min-w-0 truncate font-medium text-neutral5",children:t}),o.jsx("span",{className:"shrink-0 tabular-nums text-neutral3",children:n})]}),o.jsx("span",{className:"mt-0.5 block text-neutral3 transition-colors duration-normal group-hover/capability-row:text-neutral4",children:r})]}),o.jsx(_a,{className:"mt-0.5 size-3 shrink-0 text-neutral3 transition-colors duration-normal group-hover/capability-row:text-neutral5"})]})}function uWe({agentId:e,view:t}){const{data:n,isLoading:r}=Z_(e),s=vRt(n),a=s?n?.memoryType==="gateway"?"Gateway":"On":"Off",i=r?"Checking":a;return o.jsx(yI,{view:t,label:"Memory",status:i,description:s?"Conversation history and configured memory features are available for this agent.":"This agent has no memory configured, so conversations are not saved as memory-backed threads.",docsHref:"https://mastra.ai/docs/memory/overview",enabled:s,tone:"purple",icon:o.jsx(H3,{})})}function dWe({agentId:e,view:t}){const{data:n,isLoading:r}=vl(e),{isCmsAvailable:s,isLoading:a}=Y1(),i=yRt(n,s),l=n?.editor===!1,c=Q1({agentId:e,params:{orderBy:{field:"createdAt",direction:"DESC"}},enabled:i}),u=c.data?.total??c.data?.versions.length??0,d=r||a||i&&c.isLoading,f=u>0?String(u):"Ready",h=d?"Checking":i?f:l?"Locked":"Off",v=i?"Editor is available for versioned agent overrides.":l?"This code-defined agent explicitly disables editor overrides.":"Register MastraEditor to enable versioned agent overrides.";return o.jsx(yI,{view:t,label:"Editor",status:h,description:v,docsHref:"https://mastra.ai/docs/editor/overview",enabled:i,tone:"amber",icon:o.jsx(Lp,{})})}function fWe({agentId:e,view:t}){const{data:n,isLoading:r}=vl(e),s=$j(n?.tools);return o.jsx(yI,{view:t,label:"Tools",status:r?"Checking":NW(s),description:s>0?`${s} tool${s===1?"":"s"} available.`:"No tools are configured.",docsHref:"https://mastra.ai/docs/agents/using-tools-and-mcp",enabled:s>0,tone:"emerald",icon:o.jsx(zp,{})})}function pWe({agentId:e,view:t}){const{data:n,isLoading:r}=vl(e),s=$j(n?.workflows);return o.jsx(yI,{view:t,label:"Workflows",status:r?"Checking":NW(s),description:s>0?`${s} workflow${s===1?"":"s"} available.`:"No workflows are attached to this agent.",docsHref:"https://mastra.ai/docs/workflows/overview",enabled:s>0,tone:"sky",icon:o.jsx(vD,{})})}function hWe({agentId:e,view:t}){const{data:n,isLoading:r}=vl(e),s=$j(n?.agents);return o.jsx(yI,{view:t,label:"Sub-agents",status:r?"Checking":NW(s),description:s>0?`${s} sub-agent${s===1?"":"s"} available.`:"No sub-agents are attached to this agent.",docsHref:"https://mastra.ai/docs/agents/supervisor-agents",enabled:s>0,tone:"cyan",icon:o.jsx(EF,{})})}function mWe({agentId:e,view:t}){const{data:n,isLoading:r}=vl(e),s=gRt(n);return o.jsx(yI,{view:t,label:"Processors",status:r?"Checking":NW(s),description:s>0?`${s} input/output processor${s===1?"":"s"} configured.`:"No input or output processors are configured.",docsHref:"https://mastra.ai/docs/agents/processors",enabled:s>0,tone:"orange",icon:o.jsx(hq,{})})}function lRr({agentId:e}){const{data:t}=Z_(e),{data:n}=vl(e),{isCmsAvailable:r}=Y1(),s=[vRt(t),yRt(n,r),$j(n?.tools)>0,$j(n?.workflows)>0,$j(n?.agents)>0,gRt(n)>0],a=s.filter(Boolean).length;return o.jsxs(ge,{as:"span",variant:"ui-xs",className:"shrink-0 text-neutral3",children:[a,"/",s.length]})}function cRr({agentId:e}){const[t,n]=g.useState(!1);return o.jsx(xf,{open:t,onOpenChange:n,children:o.jsxs("div",{className:"shrink-0 border-t border-border1/50",children:[o.jsx(Od,{asChild:!0,"aria-label":t?"Hide capability details":"Show capability details",children:o.jsxs("button",{type:"button","data-testid":"agent-capabilities-footer",className:"flex w-full cursor-pointer items-center gap-1.5 px-2 py-2 text-left text-neutral4 transition-colors duration-normal hover:!text-neutral4 hover:bg-surface4 focus-visible:!text-neutral4 focus-visible:bg-surface4 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-border2 active:bg-surface5/80 aria-expanded:bg-surface4/70 data-[panel-open]:bg-surface4/70",children:[o.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-1.5 overflow-hidden",children:[o.jsx(uWe,{agentId:e,view:"chip"}),o.jsx(dWe,{agentId:e,view:"chip"}),o.jsx(fWe,{agentId:e,view:"chip"}),o.jsx(pWe,{agentId:e,view:"chip"}),o.jsx(hWe,{agentId:e,view:"chip"}),o.jsx(mWe,{agentId:e,view:"chip"})]}),o.jsx(lRr,{agentId:e}),o.jsx(ta,{className:K("size-3.5 shrink-0 text-neutral3 transition-transform duration-normal ease-out-custom",t?"rotate-90":void 0)})]})}),o.jsx(_d,{className:"px-2 pb-2",children:o.jsxs("div",{className:"grid gap-1",children:[o.jsx(uWe,{agentId:e,view:"row"}),o.jsx(dWe,{agentId:e,view:"row"}),o.jsx(fWe,{agentId:e,view:"row"}),o.jsx(pWe,{agentId:e,view:"row"}),o.jsx(hWe,{agentId:e,view:"row"}),o.jsx(mWe,{agentId:e,view:"row"})]})})]})})}const gWe=(e,t)=>e?typeof e=="number"?e:e.max:t;function bRt({record:e,liveProgress:t,agentConfig:n}){const r=e?.config,s=t?.windows?.active?.messages?.threshold??r?.observation?.messageTokens??gWe(n?.messageTokens,3e4),a=t?.windows?.active?.observations?.threshold??r?.reflection?.observationTokens??gWe(n?.observationTokens,4e4),i=t?.windows?.active?.messages?.tokens??e?.pendingMessageTokens??0,l=t?.windows?.active?.observations?.tokens??e?.observationTokenCount??0;return{messageTokens:i,messageThreshold:s,observationTokens:l,observationThreshold:a}}const vWe={modelSettings:{maxRetries:2,maxSteps:15,chatWithGenerateLegacy:!1,chatWithGenerate:!1,chatWithLegacyStream:!1}};function uRr({agentId:e,defaultSettings:t}){const[n,r]=g.useState(t),s=`mastra-agent-store-${e}`;return g.useEffect(()=>{try{const l=localStorage.getItem(s),c=l?JSON.parse(l):{},u={...c,modelSettings:{...vWe.modelSettings,...c?.modelSettings??{},...t?.modelSettings??{}}};r(u)}catch{}},[s,t]),{settings:n,setSettings:l=>{r(c=>({...c,...l})),localStorage.setItem(s,JSON.stringify({...l,agentId:e}))},resetAll:()=>{const l={modelSettings:{...vWe.modelSettings,...t?.modelSettings??{}}};r(l),localStorage.removeItem(s)}}}const xRt=g.createContext({});function O_e({children:e,agentId:t,defaultSettings:n}){const{settings:r,setSettings:s,resetAll:a}=uRr({agentId:t,defaultSettings:n});return o.jsx(xRt.Provider,{value:{settings:r,setSettings:s,resetAll:a},children:e})}const __e=()=>g.useContext(xRt);function yWe(e){try{return JSON.stringify(JSON.parse(e),null,2)}catch{return e}}function dRr(e,t,n){const r=We(),[s,a]=g.useState(!1),[i,l]=g.useState(null),[c,u]=g.useState("thread"),[d,f]=g.useState("markdown"),[p,h]=g.useState(!0),[m,v]=g.useState(!1),{requestContext:y}=_s(),b=g.useCallback(async()=>{h(!0);try{if(!e||!t){l(null),h(!1);return}const w=await r.getWorkingMemory({agentId:e,threadId:t,resourceId:n,requestContext:y}),{workingMemory:k,source:_,workingMemoryTemplate:C,threadExists:E}=w;if(a(E),l(k),u(_),f(C?.format||"markdown"),C?.format==="json"){let j="";k?j=yWe(k):C?.content?j=yWe(C.content):j="",l(j)}else l(k||C?.content||"")}catch(w){l(null),console.error("Error fetching working memory",w)}finally{h(!1)}},[e,t,n]);return g.useEffect(()=>{b()},[b]),{threadExists:s,workingMemoryData:i,workingMemorySource:c,workingMemoryFormat:d,isLoading:p,isUpdating:m,refetch:b,updateWorkingMemory:async w=>{v(!0);try{if(d==="json")try{JSON.parse(w)}catch{throw new Error("Invalid JSON working memory")}await r.updateWorkingMemory({agentId:e,threadId:t,workingMemory:w,resourceId:n,requestContext:y}),b()}catch(k){throw console.error("Error updating working memory",k),k}finally{v(!1)}}}}const wRt=g.createContext({threadExists:!1,workingMemoryData:null,workingMemorySource:"thread",isLoading:!1,isUpdating:!1,updateWorkingMemory:()=>Promise.resolve(),refetch:()=>Promise.resolve()});function SRt({agentId:e,threadId:t,resourceId:n,children:r}){const s=dRr(e,t,n);return o.jsx(wRt.Provider,{value:s,children:r})}function kRt(){const e=g.useContext(wRt);if(!e)throw new Error("useWorkingMemory must be used within a WorkingMemoryProvider");return e}const ORt=g.createContext(null);function _Rt({children:e}){const[t,n]=g.useState(!1),[r,s]=g.useState(!1),[a,i]=g.useState(0),[l,c]=g.useState(null),[u,d]=g.useState(new Set),f=g.useCallback(()=>{i(Date.now())},[]),p=g.useCallback(m=>{d(v=>new Set([...v,m]))},[]),h=g.useCallback(()=>{n(!1),s(!1),d(new Set)},[]);return o.jsx(ORt.Provider,{value:{isObservingFromStream:t,setIsObservingFromStream:n,isReflectingFromStream:r,setIsReflectingFromStream:s,observationsUpdatedAt:a,signalObservationsUpdated:f,streamProgress:l,setStreamProgress:c,activatedCycleIds:u,markCycleIdActivated:p,clearProgress:h},children:e})}function IW(){const e=g.useContext(ORt);return e||{isObservingFromStream:!1,setIsObservingFromStream:()=>{},isReflectingFromStream:!1,setIsReflectingFromStream:()=>{},observationsUpdatedAt:0,signalObservationsUpdated:()=>{},streamProgress:null,setStreamProgress:()=>{},activatedCycleIds:new Set,markCycleIdActivated:()=>{},clearProgress:()=>{}}}const CRt=g.createContext(null),fRr={isPanelOpen:!1,openPanel:()=>{},closePanel:()=>{},selectedTimestamp:null,setSelectedTimestamp:()=>{}};function pRr({children:e}){const[t,n]=g.useState(!1),[r,s]=g.useState(null),a=g.useCallback(()=>n(!0),[]),i=g.useCallback(()=>n(!1),[]),l=g.useMemo(()=>({isPanelOpen:t,openPanel:a,closePanel:i,selectedTimestamp:r,setSelectedTimestamp:s}),[t,a,i,r]);return o.jsx(CRt.Provider,{value:l,children:e})}function AW(){return g.useContext(CRt)??fRr}const ERt=g.createContext(null);function C_e({children:e}){const[t,n]=g.useState(new Set),r=g.useCallback(l=>{n(c=>{if(c.has(l))return c;const u=new Set(c);return u.add(l),u})},[]),s=g.useCallback(l=>{n(c=>{const u=new Set(c);return u.delete(l),u})},[]),a=g.useCallback(l=>t.has(l),[t]),i=g.useCallback(()=>{n(new Set)},[]);return o.jsx(ERt.Provider,{value:{activatedSkills:t,activateSkill:r,deactivateSkill:s,isSkillActivated:a,clearActivatedSkills:i},children:e})}const hRr={activatedSkills:new Set,activateSkill:()=>{},deactivateSkill:()=>{},isSkillActivated:()=>!1,clearActivatedSkills:()=>{}};function jRt(){return g.useContext(ERt)??hRr}const E_e=g.createContext(null);function j_e({children:e,...t}){return o.jsx(E_e.Provider,{value:t,children:e})}function Fo(){const e=g.useContext(E_e);if(!e)throw new Error("useAgentEditFormContext must be used within an AgentEditFormProvider");return e}function TRt(){return g.useContext(E_e)}const NRt=g.createContext(null);function mRr({children:e,defaultProvider:t="",defaultModel:n=""}){const[r,s]=g.useState(t),[a,i]=g.useState(n);return g.useEffect(()=>{t&&!r&&s(t)},[t]),g.useEffect(()=>{n&&!a&&i(n)},[n]),o.jsx(NRt.Provider,{value:{provider:r,model:a,setProvider:s,setModel:i},children:e})}function T_e(){const e=g.useContext(NRt);if(!e)throw new Error("usePlaygroundModel must be used within a PlaygroundModelProvider");return e}const Ei=()=>{const e=We(),t=Hr(),n=Rn({mutationFn:m=>e.createDataset(m),onSuccess:()=>{t.invalidateQueries({queryKey:["datasets"]})}}),r=Rn({mutationFn:m=>e.updateDataset(m),onSuccess:(m,v)=>{t.invalidateQueries({queryKey:["datasets"]}),t.invalidateQueries({queryKey:["dataset",v.datasetId]})}}),s=Rn({mutationFn:m=>e.deleteDataset(m),onSuccess:()=>{t.invalidateQueries({queryKey:["datasets"]})}}),a=Rn({mutationFn:m=>e.addDatasetItem(m),onSuccess:(m,v)=>{t.invalidateQueries({queryKey:["dataset-items",v.datasetId]}),t.invalidateQueries({queryKey:["dataset",v.datasetId]})}}),i=Rn({mutationFn:m=>e.updateDatasetItem(m),onSuccess:(m,v)=>{t.invalidateQueries({queryKey:["dataset-items",v.datasetId]}),t.invalidateQueries({queryKey:["dataset-item",v.datasetId,v.itemId]}),t.invalidateQueries({queryKey:["dataset-item-versions",v.datasetId,v.itemId]}),t.invalidateQueries({queryKey:["dataset-versions",v.datasetId]})}}),l=Rn({mutationFn:({datasetId:m,itemId:v})=>e.deleteDatasetItem(m,v),onSuccess:(m,v)=>{t.invalidateQueries({queryKey:["dataset-items",v.datasetId]}),t.invalidateQueries({queryKey:["dataset",v.datasetId]})}}),c=Rn({mutationFn:m=>e.batchInsertDatasetItems(m),onSuccess:(m,v)=>{t.invalidateQueries({queryKey:["dataset-items",v.datasetId]}),t.invalidateQueries({queryKey:["dataset",v.datasetId]}),t.invalidateQueries({queryKey:["dataset-versions",v.datasetId]})}}),u=Rn({mutationFn:m=>e.batchDeleteDatasetItems(m),onSuccess:(m,v)=>{t.invalidateQueries({queryKey:["dataset-items",v.datasetId]}),t.invalidateQueries({queryKey:["dataset",v.datasetId]}),t.invalidateQueries({queryKey:["dataset-versions",v.datasetId]})}}),d=Rn({mutationFn:async({datasetId:m,itemIds:v})=>e.batchDeleteDatasetItems({datasetId:m,itemIds:v}),onSuccess:(m,v)=>{t.invalidateQueries({queryKey:["dataset-items",v.datasetId]}),t.invalidateQueries({queryKey:["dataset",v.datasetId]}),t.invalidateQueries({queryKey:["dataset-versions",v.datasetId]})}}),f=Rn({mutationFn:m=>e.generateDatasetItems(m)}),p=Rn({mutationFn:m=>e.triggerDatasetExperiment(m),onSuccess:(m,v)=>{t.invalidateQueries({queryKey:["dataset-experiments",v.datasetId]})}}),h=Rn({mutationFn:m=>e.updateDatasetExperimentResult(m),onSuccess:(m,v)=>{t.invalidateQueries({queryKey:["experiment-results",v.experimentId]}),t.invalidateQueries({queryKey:["dataset-experiment-results"]}),t.invalidateQueries({queryKey:["review-items"]}),t.invalidateQueries({queryKey:["dataset-review-items"]}),t.invalidateQueries({queryKey:["dataset-completed-items"]}),t.invalidateQueries({queryKey:["experiment-review-summary"]})}});return{createDataset:n,updateDataset:r,deleteDataset:s,addItem:a,updateItem:i,deleteItem:l,deleteItems:d,batchInsertItems:c,batchDeleteItems:u,generateItems:f,triggerExperiment:p,updateExperimentResult:h}},IRt=g.createContext(null);function gRr({children:e}){const[t,n]=g.useState([]),[r,s]=g.useState([]),[a,i]=g.useState(null),{updateExperimentResult:l}=Ei(),c=We(),u=g.useCallback(S=>{n(w=>{const k=new Set(w.map(C=>C.itemId)),_=S.filter(C=>!k.has(C.itemId));return[...w,..._.map((C,E)=>({...C,id:C.id||`review-${Date.now()}-${E}`,tags:C.tags??[]}))]})},[]),d=g.useCallback(S=>{n(w=>{const k=new Map(S.map(C=>[C.id,C])),_=w.filter(C=>!k.has(C.id));return[...S,..._]})},[]),f=g.useCallback(S=>{const w=t.find(k=>k.id===S);w?.experimentId&&w?.datasetId&&l.mutate({datasetId:w.datasetId,experimentId:w.experimentId,resultId:w.id,status:null}),n(k=>k.filter(_=>_.id!==S))},[t,l]),p=g.useCallback(async S=>{const w=t.find(k=>k.id===S);w?.experimentId&&w?.datasetId&&await l.mutateAsync({datasetId:w.datasetId,experimentId:w.experimentId,resultId:w.id,status:"complete"}),n(k=>k.filter(_=>_.id!==S))},[t,l]),h=g.useCallback((S,w)=>{const k=t.find(_=>_.id===S);k?.experimentId&&k?.datasetId&&l.mutate({datasetId:k.datasetId,experimentId:k.experimentId,resultId:k.id,tags:w}),n(_=>_.map(C=>C.id===S?{...C,tags:w}:C))},[t,l]),m=g.useCallback((S,w)=>{const k=t.find(_=>_.id===S);k?.traceId&&w!==void 0&&c.createFeedback({feedback:{traceId:k.traceId,source:"studio",feedbackSource:"studio",feedbackType:"rating",value:w==="positive"?1:-1,experimentId:k.experimentId??void 0,sourceId:k.id}}).catch(()=>{}),n(_=>_.map(C=>C.id===S?{...C,rating:w}:C))},[t,c]),v=g.useCallback((S,w)=>{const k=t.find(_=>_.id===S);k?.traceId&&c.createFeedback({feedback:{traceId:k.traceId,source:"studio",feedbackSource:"studio",feedbackType:"comment",value:w,comment:w,experimentId:k.experimentId??void 0,sourceId:k.id}}).catch(()=>{}),n(_=>_.map(C=>C.id===S?{...C,comment:w}:C))},[t,c]),y=g.useCallback((S,w)=>{n(k=>k.map(_=>_.id===S?{..._,clusterId:w}:_))},[]),b=g.useCallback(()=>{n([]),s([]),i(null)},[]);return o.jsx(IRt.Provider,{value:{items:t,clusters:r,activeClusterId:a,addItems:u,removeItem:f,completeItem:p,setItemTags:h,rateItem:m,commentItem:v,setClusters:s,setActiveClusterId:i,assignCluster:y,clearAll:b,loadPersistedItems:d},children:e})}function ARt(){const e=g.useContext(IRt);if(!e)throw new Error("useReviewQueue must be used within ReviewQueueProvider");return e}const V0=e=>e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e5?`${(e/1e3).toFixed(0)}k`:e>=1e3?`${(e/1e3).toFixed(1)}k`:Math.round(e).toString(),vRr=e=>e>=60?"bg-blue-500":"bg-green-500",bWe=(e,t)=>{if(typeof e=="string")return e;if(t?.length)return"Auto (tiered)"},yRr=(e,t)=>e?typeof e=="number"?e:e.max:t,xWe=(e,t)=>e?typeof e=="number"?e:e.min:t,bRr=e=>{const[t,n]=g.useState({isActive:e,elapsed:0}),r=g.useRef(null);return t.isActive!==e&&(r.current=e?Date.now():null,n({isActive:e,elapsed:0})),g.useEffect(()=>{if(!e)return;r.current||(r.current=Date.now());const s=setInterval(()=>{const a=r.current;a&&n(i=>({...i,elapsed:(Date.now()-a)/1e3}))},100);return()=>clearInterval(s)},[e]),t.isActive===e?t.elapsed:0},wWe=({value:e,max:t,label:n,isActive:r=!1,model:s,modelRouting:a,baseThreshold:i,totalBudget:l})=>{const c=i!==void 0&&l!==void 0,u=t>0?Math.min(100,Math.max(0,e/t*100)):0,d=vRr(u),f=bRr(r&&u>=100),p=r&&u>=100,h=n==="Messages"?"observing":"reflecting",m=c&&u>=100&&!p&&i&&e<i,v=p?"bg-transparent":"bg-surface4",y=p?"bg-blue-500/10":d,b=p?"text-blue-600":"text-neutral4",S=p?"text-blue-600":"text-white",w=p?"bg-blue-500/10":"bg-surface5",k=p?"text-blue-600":"text-neutral3";return o.jsxs("div",{className:"flex-1 min-w-0",children:[o.jsxs("div",{className:"flex items-center gap-1 mb-1 h-4",children:[o.jsx("span",{className:"text-[9px] text-neutral4 uppercase tracking-wider font-normal",children:n}),o.jsxs(Wn,{children:[o.jsx(zn,{asChild:!0,children:o.jsx("button",{type:"button",className:"inline-flex items-center justify-center",children:o.jsx(Fx,{className:"w-2.5 h-2.5 text-neutral4 hover:text-neutral3 cursor-help"})})}),o.jsx(Bn,{side:"top",className:"max-w-xs bg-surface3 border border-border1 text-foreground",children:o.jsxs("div",{className:"text-xs space-y-1.5",children:[o.jsxs("div",{className:"font-medium text-neutral5",children:[n==="Messages"?"Observer":"Reflector"," Settings"]}),o.jsxs("div",{className:"space-y-0.5",children:[o.jsxs("div",{children:[o.jsx("span",{className:"text-neutral4",children:"Model:"})," ",o.jsx("span",{className:"text-neutral5",children:s||"not configured"})]}),a?.length?o.jsxs("div",{children:[o.jsx("span",{className:"text-neutral4",children:"Routing:"}),o.jsx("div",{className:"mt-0.5 pl-2 space-y-0.5",children:a.map(_=>o.jsxs("div",{className:"text-neutral5",children:["≤",V0(_.upTo)," → ",_.model]},`${_.upTo}-${_.model}`))})]}):o.jsxs("div",{children:[o.jsx("span",{className:"text-neutral4",children:"Threshold:"})," ",o.jsxs("span",{className:"text-neutral5",children:[V0(i??t)," tokens"]})]}),c&&l&&o.jsxs("div",{children:[o.jsx("span",{className:"text-neutral4",children:"Mode:"})," ",o.jsx("span",{className:"text-amber-400",children:"Adaptive"})," ",o.jsxs("span",{className:"text-neutral4",children:["(",V0(l)," shared budget)"]})]})]})]})})]})]}),o.jsxs("div",{className:"flex items-stretch",children:[o.jsxs("div",{className:`relative flex-1 h-5 ${v} rounded-l overflow-hidden`,children:[o.jsx("div",{className:`h-full ${y} transition-all`,style:{width:`${u}%`}}),o.jsx("span",{className:`absolute inset-0 flex items-center ${p?"justify-start pl-2":"justify-center"} text-[10px] font-medium ${b} pointer-events-none`,children:p?`${h} ${f.toFixed(1)}s`:m?"adaptive":`${Math.round(u)}%`}),o.jsx("span",{className:`absolute inset-0 flex items-center ${p?"justify-start pl-2":"justify-center"} text-[10px] font-medium ${S} pointer-events-none`,style:{clipPath:`inset(0 ${100-u}% 0 0)`},children:p?`${h} ${f.toFixed(1)}s`:m?"adaptive":`${Math.round(u)}%`})]}),o.jsxs("span",{className:`text-[10px] ${k} tabular-nums whitespace-nowrap font-mono ${w} px-1.5 flex items-center gap-1 rounded-r -ml-px`,children:[V0(e),o.jsxs("span",{className:p?"text-blue-500":"text-neutral4",children:["/",V0(t)]}),c&&l&&o.jsxs(Wn,{children:[o.jsx(zn,{asChild:!0,children:o.jsxs("span",{className:"text-amber-400 cursor-help",children:["(",V0(i),")"]})}),o.jsx(Bn,{side:"top",className:"max-w-xs bg-surface3 border border-border1 text-foreground",children:o.jsxs("div",{className:"text-xs",children:[o.jsx("span",{className:"text-amber-400",children:V0(i)}),o.jsx("span",{className:"text-neutral4",children:" is the configured threshold. "}),o.jsxs("span",{className:"text-neutral5",children:["Adaptive mode shares a ",V0(l)," token budget between messages and observations."]})]})})]})]})]})]})},xRr=()=>o.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[o.jsx(Rv,{className:"w-4 h-4 text-purple-400"}),o.jsx("h3",{className:"text-sm font-medium text-neutral5",children:"Observational Memory"})]}),wRr=()=>o.jsxs("div",{className:"p-4",children:[o.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[o.jsx(Rv,{className:"w-4 h-4 text-neutral3"}),o.jsx("h3",{className:"text-sm font-medium text-neutral5",children:"Observational Memory"})]}),o.jsxs("div",{className:"bg-surface3 border border-border1 rounded-lg p-4",children:[o.jsx("p",{className:"text-sm text-neutral3 mb-3",children:"Observational Memory is not enabled for this agent. Enable it to automatically extract and maintain observations from conversations."}),o.jsxs("a",{href:"https://mastra.ai/en/docs/memory/observational-memory",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-2 text-sm text-blue-400 hover:text-blue-300 transition-colors",children:["Learn about Observational Memory",o.jsx(_a,{className:"w-3 h-3"})]})]})]});function SRr({pendingMessageTokens:e,messageTokensThreshold:t,isObserving:n,observationModel:r,observationModelRouting:s,baseMessageTokens:a,totalBudget:i,observationTokenCount:l,observationTokensThreshold:c,isReflecting:u,baseObservationTokens:d,reflectionModel:f,reflectionModelRouting:p}){return o.jsx(sc,{delayDuration:0,children:o.jsxs("div",{className:"flex gap-3 mb-3",children:[o.jsx(wWe,{value:e,max:t,label:"Messages",isActive:n,model:r,modelRouting:s,baseThreshold:a,totalBudget:i}),o.jsx(wWe,{value:l,max:c,label:"Observations",isActive:u,baseThreshold:d,model:f,modelRouting:p,totalBudget:i})]})})}const kRr=({agentId:e,resourceId:t,threadId:n})=>{const{isPanelOpen:r,openPanel:s,closePanel:a}=AW(),{isObservingFromStream:i,isReflectingFromStream:l,streamProgress:c,clearProgress:u}=IW();g.useEffect(()=>{u()},[n,u]);const d=c?.threadId===n?c:null,{data:f}=G_(e),{data:p,isLoading:h}=mRt({agentId:e,resourceId:t,threadId:n}),m=120*1e3,v=p?.observationalMemory?.lastObservedAt,y=v?Date.now()-new Date(v).getTime()>m:!0,b=i||l,S=!y&&!b&&(p?.observationalMemory?.isObserving||!1),w=!y&&!b&&(p?.observationalMemory?.isReflecting||!1),k=i||S,_=l||w,C=k||_,{data:E,isLoading:j}=iRr({agentId:e,resourceId:t,threadId:n,enabled:!!p?.observationalMemory?.enabled,isActive:C}),N=h||j,I=p?.observationalMemory?.enabled??!1,R=E?.record,P=f?.config?.observationalMemory,L=R?.config,M=L?.observationModelRouting??L?.observation?.routing??P?.observationModelRouting??P?.observation?.routing,q=L?.reflectionModelRouting??L?.reflection?.routing??P?.reflectionModelRouting??P?.reflection?.routing,H=bWe(L?.observationModel??L?.observation?.model??P?.observationModel??P?.model??P?.observation?.model,M),F=bWe(L?.reflectionModel??L?.reflection?.model??P?.reflectionModel??P?.model??P?.reflection?.model,q),z=P?.messageTokens!==void 0&&typeof P.messageTokens!="number",B=z?yRr(P?.messageTokens,3e4):0,D=z?xWe(P?.messageTokens,3e4):void 0,Q=z?xWe(P?.observationTokens,4e4):void 0,{messageTokens:V,messageThreshold:$,observationTokens:U,observationThreshold:Z}=bRt({record:R,liveProgress:d,agentConfig:P});return N?o.jsx("div",{className:"p-4",children:o.jsx(bt,{className:"h-32 w-full"})}):I?o.jsxs("div",{className:"p-4 overflow-hidden min-w-0 w-full",children:[o.jsx(xRr,{}),o.jsx(SRr,{pendingMessageTokens:V,messageTokensThreshold:$,isObserving:k,observationModel:H,observationModelRouting:M,baseMessageTokens:D,totalBudget:B,observationTokenCount:U,observationTokensThreshold:Z,isReflecting:_,baseObservationTokens:Q,reflectionModel:F,reflectionModelRouting:q}),o.jsxs(de,{size:"sm",className:"w-full justify-center gap-2",onClick:()=>r?a():s(),children:[o.jsx(Rv,{className:"h-3.5 w-3.5"}),"Analyze Observations"]})]}):o.jsx(wRr,{})};function ORr({content:e,height:t="150px",isCopied:n=!1,isDraft:r=!1,onCopy:s,className:a=""}){return o.jsx("div",{className:`rounded-md border ${a}`,style:{height:t},children:o.jsx(Yr,{className:"h-full",children:o.jsxs("div",{className:`p-2 transition-colors group relative ${s?"cursor-pointer hover:bg-surface4/50":""}`,children:[s&&o.jsx("button",{type:"button",onClick:s,"aria-label":"Copy code",className:"absolute inset-0 z-10 rounded-md focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-accent1"}),o.jsx("pre",{className:"text-ui-xs whitespace-pre-wrap font-mono pointer-events-none",children:e}),r&&o.jsx("div",{className:"mt-1.5",children:o.jsx("span",{className:"text-ui-xs px-1.5 py-0.5 rounded-full bg-yellow-500/20 text-yellow-500",children:"Draft - Save changes to apply"})}),n&&o.jsx("span",{className:"absolute top-2 right-2 z-20 text-ui-xs px-1.5 py-0.5 rounded-full bg-green-500/20 text-green-500 pointer-events-none",children:"Copied!"}),s&&o.jsx("span",{className:"absolute top-2 right-2 z-20 text-ui-xs px-1.5 py-0.5 rounded-full bg-surface4 text-neutral4 opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none",children:"Click to copy"})]})})})}const _Rr=({agentId:e})=>{const{threadExists:t,workingMemoryData:n,workingMemorySource:r,isLoading:s,isUpdating:a,updateWorkingMemory:i}=kRt(),{data:l,isLoading:c}=G_(e),d=!!l?.config?.workingMemory?.enabled,{isCopied:f,handleCopy:p}=Bp({text:n??"",copyMessage:"Working memory copied!"}),[h,m]=g.useState({source:n,value:n??""}),[v,y]=g.useState(!1);return!v&&h.source!==n&&m({source:n,value:n??""}),s||c?o.jsx(bt,{className:"h-32 w-full"}):o.jsxs("div",{className:"flex flex-col gap-4 p-4",children:[o.jsxs("div",{children:[o.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[o.jsx("h3",{className:"text-sm font-medium text-neutral5",children:"Working Memory"}),d&&r&&o.jsx("span",{className:K("text-xs font-medium px-2 py-0.5 rounded",r==="resource"?"bg-purple-500/20 text-purple-400":"bg-blue-500/20 text-blue-400"),title:r==="resource"?"Shared across all threads for this agent":"Specific to this conversation thread",children:r})]}),d&&!t&&o.jsx("p",{className:"text-xs text-neutral3",children:"Send a message to the agent to enable working memory."})]}),d?o.jsxs(o.Fragment,{children:[v?o.jsx("textarea",{className:"w-full min-h-[150px] p-3 border border-border1 rounded-lg bg-surface3 font-mono text-sm text-neutral5 resize-none",value:h.value,onChange:b=>m(S=>({...S,value:b.target.value})),disabled:a,"aria-label":"Working memory content",placeholder:"Enter working memory content..."}):o.jsx(o.Fragment,{children:n?o.jsx(o.Fragment,{children:n.trim().startsWith("{")?o.jsx(ORr,{content:n||"",isCopied:f,onCopy:p,className:"bg-surface3 text-sm font-mono min-h-[150px] border border-border1 rounded-lg"}):o.jsx(o.Fragment,{children:o.jsx("div",{className:"bg-surface3 border border-border1 rounded-lg",style:{height:"300px"},children:o.jsx(Yr,{className:"h-full",children:o.jsxs("div",{className:"p-3 cursor-pointer hover:bg-surface4/20 transition-colors relative group text-ui-xs",children:[o.jsx("button",{type:"button",onClick:p,"aria-label":"Copy working memory",className:"absolute inset-0 z-10 rounded-lg focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-accent1"}),o.jsx("div",{className:"pointer-events-none",children:o.jsx(Wp,{children:n})}),f&&o.jsx("span",{className:"absolute top-2 right-2 z-20 text-ui-xs px-1.5 py-0.5 rounded-full bg-green-500/20 text-green-500 pointer-events-none",children:"Copied!"}),o.jsx("span",{className:"absolute top-2 right-2 z-20 text-ui-xs px-1.5 py-0.5 rounded-full bg-surface3 text-neutral4 opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none",children:"Click to copy"})]})})})})}):o.jsx("div",{className:"text-sm text-neutral3 font-mono",children:'No working memory content yet. Click "Edit Working Memory" to add content.'})}),o.jsx("div",{className:"flex gap-2",children:v?o.jsxs(o.Fragment,{children:[o.jsx(de,{onClick:async()=>{try{await i(h.value),y(!1)}catch(b){console.error("Failed to update working memory:",b),De.error("Failed to update working memory")}},disabled:a,className:"text-xs",children:a?o.jsx(Ydn,{className:"w-3 h-3 animate-spin"}):"Save Changes"}),o.jsx(de,{onClick:()=>{m({source:n,value:n??""}),y(!1)},disabled:a,className:"text-xs",children:"Cancel"})]}):o.jsx(o.Fragment,{children:t?o.jsx(de,{onClick:()=>y(!0),disabled:a,className:"text-xs",children:"Edit Working Memory"}):o.jsxs(Wn,{children:[o.jsx(zn,{asChild:!0,children:o.jsx(de,{type:"button","aria-disabled":"true",onClick:b=>b.preventDefault(),className:"text-xs cursor-not-allowed opacity-50",children:"Edit Working Memory"})}),o.jsx(Bn,{children:o.jsx("p",{children:"Working memory will be available after the agent calls updateWorkingMemory"})})]})})})]}):o.jsxs("div",{className:"bg-surface3 border border-border1 rounded-lg p-4",children:[o.jsx("p",{className:"text-sm text-neutral3 mb-3",children:"Working memory is not enabled for this agent. Enable it to maintain context across conversations."}),o.jsxs("a",{href:"https://mastra.ai/en/docs/memory/working-memory",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-2 text-sm text-blue-400 hover:text-blue-300 transition-colors",children:["Learn about working memory",o.jsx(_a,{className:"w-3 h-3"})]})]})]})},CRr="__default__",SWe=e=>e||CRr,RRt=g.createContext({getThreadInput:()=>"",setThreadInputForThread:()=>{}}),PRt=({children:e})=>{const[t,n]=g.useState({}),r=g.useCallback(i=>t[SWe(i)]??"",[t]),s=g.useCallback((i,l)=>{n(c=>{const u=SWe(i),d=c[u]??"",f=typeof l=="function"?l(d):l;if(f===d)return c;if(f.length===0){if(!(u in c))return c;const p={...c};return delete p[u],p}return{...c,[u]:f}})},[]),a=g.useMemo(()=>({getThreadInput:r,setThreadInputForThread:s}),[r,s]);return o.jsx(RRt.Provider,{value:a,children:e})},$Rt=e=>{const{getThreadInput:t,setThreadInputForThread:n}=g.use(RRt),r=g.useCallback(s=>n(e,s),[n,e]);return{threadInput:t(e),setThreadInput:r}},ERr=e=>{const n=Math.floor((new Date().getTime()-e.getTime())/1e3);return n<60?"just now":n<3600?`${Math.floor(n/60)}m ago`:n<86400?`${Math.floor(n/3600)}h ago`:n<604800?`${Math.floor(n/86400)}d ago`:e.toLocaleDateString()},jRr=({searchMemory:e,onResultClick:t,className:n,currentThreadId:r,chatInputValue:s})=>{const[a,i]=g.useState(""),[l,c]=g.useState([]),[u,d]=g.useState(!1),[f,p]=g.useState(!1),[h,m]=g.useState(null),v=g.useRef(void 0),y=g.useRef(null),b=g.useRef(r),S=g.useRef(0),w=g.useRef(null),k=g.useCallback(async I=>{if(!I.trim()){m(null);return}d(!0),m(null);try{const R=await e(I);c(R.results),p(P=>P||R.results.length>0)}catch(R){m("Failed to search memory"),console.error("Memory search error:",R)}finally{d(!1)}},[e]),_=g.useCallback(I=>{const R=I.target.value;if(i(R),v.current&&clearTimeout(v.current),R.trim()){const P=Date.now(),L=P-S.current;if(L>=500)d(!0),k(R),S.current=P;else{d(!0),w.current=R;const M=500-L;v.current=setTimeout(()=>{w.current&&(k(w.current),S.current=Date.now(),w.current=null)},M)}}else c([]),p(!1),d(!1),w.current=null},[k]),C=g.useCallback(I=>{I.key==="Enter"&&(I.preventDefault(),v.current&&clearTimeout(v.current),k(a))},[a,k]);g.useEffect(()=>()=>{v.current&&clearTimeout(v.current)},[]),g.useEffect(()=>{const I=R=>{y.current&&!y.current.contains(R.target)&&p(!1)};return document.addEventListener("mousedown",I),()=>document.removeEventListener("mousedown",I)},[]),g.useEffect(()=>{b.current!==r&&a.trim()&&k(a),b.current=r},[r,a,k]),g.useEffect(()=>{if(s!==void 0&&s!==a)if(i(s),v.current&&clearTimeout(v.current),s.trim()){const I=Date.now(),R=I-S.current;if(R>=500)d(!0),k(s),S.current=I;else{d(!0),w.current=s;const P=500-R;v.current=setTimeout(()=>{w.current&&(k(w.current),S.current=Date.now(),w.current=null)},P)}}else c([]),p(!1),d(!1),w.current=null;return()=>{v.current&&clearTimeout(v.current)}},[s]);const E=(I,R)=>{t?.(I,R)},j=()=>{i(""),c([]),p(!1),m(null),v.current&&clearTimeout(v.current)},N=(I,R=100)=>I.length<=R?I:I.substring(0,R)+"...";return o.jsxs("div",{className:K("flex flex-col h-full",n),ref:y,children:[o.jsxs("div",{className:"relative shrink-0",children:[o.jsx(Xa,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-neutral3"}),o.jsx(kn,{type:"text",value:a,onChange:_,onKeyDown:C,placeholder:"Search memory...",className:"pl-10 pr-10 bg-surface3 border-border1"}),a&&o.jsx(de,{onClick:j,className:"absolute right-1 top-1/2 transform -translate-y-1/2 h-6 w-6 p-0",children:o.jsx(vs,{className:"h-4 w-4"})})]}),(f||a&&(u||l.length===0))&&o.jsx("div",{className:"mt-2 flex-1 bg-surface3 border border-border1 rounded-lg shadow-lg overflow-y-auto",children:h?o.jsx("div",{className:"p-4 text-center",children:o.jsx(ge,{variant:"ui-sm",className:"text-red-500",children:h})}):u&&l.length===0?o.jsx("div",{className:"p-4 text-center",children:o.jsx(ge,{variant:"ui-sm",className:"text-neutral3",children:"Searching..."})}):l.length===0?o.jsx("div",{className:"p-4 text-center",children:o.jsxs(ge,{variant:"ui-sm",className:"text-neutral3",children:['No results found for "',a,'"']})}):o.jsx("div",{className:"py-2",children:l.map(I=>o.jsx("button",{onClick:()=>E(I.id,I.threadId),className:K("w-full px-4 py-3 hover:bg-surface4 transition-colors duration-150 text-left border-b border-border1 last:border-b-0",I.threadId!==r&&"border-l-2 border-l-blue-400"),children:o.jsxs("div",{className:"flex flex-col gap-2",children:[I.context?.before&&I.context.before.length>0&&o.jsx("div",{className:"opacity-50 text-xs space-y-1",children:I.context.before.map((R,P)=>o.jsxs("div",{className:"flex items-start gap-2",children:[o.jsxs("span",{className:"font-medium",children:[R.role,":"]}),o.jsx("span",{className:"text-neutral3",children:N(R.content,50)})]},P))}),o.jsx("div",{className:"flex items-start justify-between gap-2",children:o.jsxs("div",{className:"flex-1 min-w-0",children:[o.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[o.jsx("span",{className:K("text-xs font-medium px-2 py-0.5 rounded",I.role==="user"?"bg-blue-500/20 text-blue-400":"bg-green-500/20 text-green-400"),children:I.role}),o.jsx(ge,{variant:"ui-xs",className:"text-neutral3",children:ERr(new Date(I.createdAt))}),I.threadTitle&&o.jsxs("div",{className:"flex items-center gap-1",children:[o.jsxs(ge,{variant:"ui-xs",className:K("truncate max-w-[150px]",I.threadId!==r?"text-blue-400 font-medium":"text-neutral3"),title:I.threadTitle,children:["• ",I.threadTitle]}),I.threadId!==r&&o.jsx(_a,{className:"w-3 h-3 text-blue-400"})]})]}),o.jsx(ge,{variant:"ui-sm",className:"text-neutral5 wrap-break-word",children:N(I.content)})]})}),I.context?.after&&I.context.after.length>0&&o.jsx("div",{className:"opacity-50 text-xs space-y-1",children:I.context.after.map((R,P)=>o.jsxs("div",{className:"flex items-start gap-2",children:[o.jsxs("span",{className:"font-medium",children:[R.role,":"]}),o.jsx("span",{className:"text-neutral3",children:N(R.content,50)})]},P))})]})},I.id))})})]})};function TRr({agentId:e,threadId:t,memoryType:n}){const r=n==="gateway",{threadInput:s}=$Rt(t),{paths:a,navigate:i}=yn(),{data:l}=pRt({threadId:t,agentId:e}),c=l?.resourceId??e,{data:u,isLoading:d}=G_(e),p=!!u?.config?.semanticRecall,{data:h}=mRt({agentId:e,resourceId:c,threadId:t}),m=h?.observationalMemory?.enabled??!1,{mutateAsync:v,data:y}=sRr({agentId:e||"",resourceId:c||"",threadId:t}),{mutateAsync:b,isPending:S}=aRr(),w=g.useCallback(async()=>{if(!t||!e)return;const C=await b({threadId:t,agentId:e});C?.thread?.id&&i(a.agentThreadLink(e,C.thread.id))},[t,e,b,i,a]),k=g.useCallback((C,E)=>{if(E&&E!==t)i(a.agentThreadLink(e,E,C));else{const j=document.querySelector(`[data-message-id="${C}"]`);j&&(j.scrollIntoView({behavior:"smooth",block:"center"}),j.classList.add("bg-surface4"),setTimeout(()=>{j.classList.remove("bg-surface4")},2e3))}},[e,t,i,a]),_=y?.searchScope;return d?o.jsxs("div",{className:"flex flex-col h-full p-4 gap-4",children:[o.jsx(bt,{className:"h-12 w-full"}),o.jsx(bt,{className:"h-32 w-full"}),o.jsx(bt,{className:"h-48 w-full"})]}):o.jsxs("div",{className:"flex flex-col min-w-0",children:[t&&o.jsx("div",{className:"p-4 border-b border-border1",children:o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsxs("div",{children:[o.jsx("h3",{className:"text-sm font-medium text-neutral5",children:"Clone Thread"}),o.jsx("p",{className:"text-xs text-neutral3 mt-1",children:"Create a copy of this conversation"})]}),o.jsxs(de,{onClick:w,disabled:S,children:[o.jsx(Dp,{className:"w-4 h-4 mr-2"}),S?"Cloning...":"Clone"]})]})}),m&&o.jsx("div",{className:"border-b border-border1 min-w-0 overflow-hidden",children:o.jsx(kRr,{agentId:e,resourceId:c,threadId:t})}),!r&&o.jsxs("div",{className:"p-4 border-b border-border1",children:[o.jsx("div",{className:"mb-2",children:o.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[o.jsx("h3",{className:"text-sm font-medium text-neutral5",children:"Semantic Recall"}),y?.searchScope&&o.jsx("span",{className:K("text-xs font-medium px-2 py-0.5 rounded",_==="resource"?"bg-purple-500/20 text-purple-400":"bg-blue-500/20 text-blue-400"),title:_==="resource"?"Searching across all threads":"Searching within current thread only",children:_})]})}),p?o.jsx(jRr,{searchMemory:C=>v({searchQuery:C,memoryConfig:{lastMessages:0}}),onResultClick:k,currentThreadId:t,className:"w-full",chatInputValue:s}):o.jsxs("div",{className:"bg-surface3 border border-border1 rounded-lg p-4",children:[o.jsx("p",{className:"text-sm text-neutral3 mb-3",children:"Semantic recall is not enabled for this agent. Enable it to search through conversation history."}),o.jsxs("a",{href:"https://mastra.ai/en/docs/memory/semantic-recall",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-2 text-sm text-blue-400 hover:text-blue-300 transition-colors",children:["Learn about semantic recall",o.jsx(_a,{className:"w-3 h-3"})]})]})]}),!r&&o.jsx("div",{children:o.jsx(_Rr,{agentId:e})}),r&&o.jsx("div",{className:"p-4 border-b border-border1",children:o.jsxs("div",{className:"bg-surface3 border border-border1 rounded-lg p-4",children:[o.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[o.jsx("span",{className:"text-xs font-medium px-2 py-0.5 rounded bg-green-500/20 text-green-400",children:"Gateway"}),o.jsx("h3",{className:"text-sm font-medium text-neutral5",children:"Memory Gateway"})]}),o.jsx("p",{className:"text-xs text-neutral3",children:"Memory is managed by the Memory Gateway. Threads and observations are stored remotely."})]})})]})}function NRr(e){let t=e;for(let n=0;n<3&&typeof t=="string";n++)try{const r=JSON.parse(t);if(typeof r=="object"&&r!==null)return r;if(typeof r=="string"&&r!==t){t=r;continue}break}catch{break}return t}function IRr(e){return typeof e=="object"&&e!==null&&"parts"in e&&Array.isArray(e.parts)}function ARr(e){const t=e.type;return t==="data-om-status"||t==="data-om-observation-start"||t==="data-om-observation-end"||t==="data-om-buffering-start"||t==="data-om-buffering-end"||t==="data-om-activation"}function RRr(e,t){switch(e.type){case"data-om-status":return{type:"status",timestamp:t,pendingTokens:e.data.windows?.active?.messages?.tokens,observationTokens:e.data.windows?.active?.observations?.tokens,observationThreshold:e.data.windows?.active?.messages?.threshold,reflectionThreshold:e.data.windows?.active?.observations?.threshold};case"data-om-observation-start":return{type:"observation-start",timestamp:e.data.startedAt,pendingTokens:e.data.tokensToObserve,observationThreshold:e.data.config?.messageTokens,reflectionThreshold:e.data.config?.observationTokens};case"data-om-observation-end":return{type:"observation-end",timestamp:e.data.completedAt,observationTokens:e.data.observationTokens};case"data-om-buffering-start":return{type:"buffering-start",timestamp:e.data.startedAt,pendingTokens:e.data.tokensToBuffer,observationThreshold:e.data.config?.messageTokens,reflectionThreshold:e.data.config?.observationTokens};case"data-om-buffering-end":return{type:"buffering-end",timestamp:e.data.completedAt,observationTokens:e.data.bufferedTokens};case"data-om-activation":return{type:"activation",timestamp:e.data.activatedAt,pendingTokens:e.data.tokensActivated,observationTokens:e.data.observationTokens,observationThreshold:e.data.config?.messageTokens,reflectionThreshold:e.data.config?.observationTokens,generationCount:e.data.generationCount}}}function PRr(e){const t=[];for(const n of e){const r=NRr(n.content);if(IRr(r))for(const s of r.parts)ARr(s)&&t.push(RRr(s,new Date(n.createdAt).toISOString()))}return t.sort((n,r)=>n.timestamp.localeCompare(r.timestamp)),t}function QT(e){return/[Zz+-]\d{0,4}$/.test(e.trim())?new Date(e).getTime():new Date(e.trim().replace(" ","T")+"Z").getTime()}function $Rr(e){if(e.length===0)return{tMin:0,tMax:1};let t=1/0,n=-1/0;for(const r of e){const s=QT(r);s<t&&(t=s),s>n&&(n=s)}return t===n?{tMin:t,tMax:t+1}:{tMin:t,tMax:n}}function l4(e,t){return(QT(e)-t.tMin)/(t.tMax-t.tMin)}function N_e(e,t){return new Date(t.tMin+e*(t.tMax-t.tMin))}function MRt(e){const t=String(e.getUTCDate()).padStart(2,"0"),n=String(e.getUTCMonth()+1).padStart(2,"0"),r=String(e.getUTCHours()).padStart(2,"0"),s=String(e.getUTCMinutes()).padStart(2,"0"),a=String(e.getUTCSeconds()).padStart(2,"0");return`${t}/${n} ${r}:${s}:${a}`}function MRr(e,t){return N_e(e,t).getTime()}function DRt(e){const t=e.lastObservedAt??e.updatedAt;return typeof t=="string"?t:new Date(t).toISOString()}function DRr(e){return QT(DRt(e))}function LRr(e,t){if(t==null||e.length===0)return null;const n=e.map(s=>({id:s.id,t:QT(DRt(s))})).toSorted((s,a)=>s.t-a.t);let r=null;for(const s of n)if(s.t<=t)r=s.id;else break;return r}function kWe(e){const t=e.lastObservedAt??e.updatedAt;return typeof t=="string"?t:new Date(t).toISOString()}function FRr(e){return[...e].sort((t,n)=>QT(kWe(t))-QT(kWe(n)))}function zRr({markers:e,omRecords:t,observationThreshold:n,reflectionThreshold:r}){const s=[...e].filter(i=>i.type==="status"&&(i.pendingTokens!=null||i.observationTokens!=null)).sort((i,l)=>i.timestamp.localeCompare(l.timestamp)).at(-1),a=FRr(t).at(-1);return{messageTokens:s?.pendingTokens??a?.pendingMessageTokens,messageThreshold:s?.observationThreshold??n,memoryTokens:s?.observationTokens??a?.observationTokenCount,memoryThreshold:s?.reflectionThreshold??r}}const BRr="var(--color-green-500, #22c55e)",URr="#f59e0b",OWe="#ec4899";function aP(e){const t=e.lastObservedAt??e.updatedAt;return typeof t=="string"?t:new Date(t).toISOString()}function qRr(e,t,n){const r=e.map(a=>({ts:String(aP(a)),pendingMessageTokens:a.pendingMessageTokens})),s=t.flatMap(a=>a.pendingTokens==null?[]:{ts:a.timestamp,pendingMessageTokens:a.pendingTokens});return[...r,...s].sort((a,i)=>a.ts.localeCompare(i.ts)).map(a=>({t:l4(a.ts,n),pendingMessageTokens:a.pendingMessageTokens}))}function VRr(e,t,n){const r=[...e.map(a=>({ts:String(aP(a)),observationTokenCount:a.observationTokenCount})),...t.flatMap(a=>a.type!=="status"||a.observationTokens==null?[]:{ts:a.timestamp,observationTokenCount:a.observationTokens})].sort((a,i)=>a.ts.localeCompare(i.ts));let s=0;return r.map(a=>(s=Math.max(s,a.observationTokenCount),{t:l4(a.ts,n),observationTokenCount:s}))}function HRr(e,t){const n=e.flatMap(s=>s.observationTokens==null||s.type!=="buffering-end"&&s.type!=="activation"?[]:{ts:s.timestamp,bufferedObservationTokenCount:s.type==="activation"?-s.observationTokens:s.observationTokens}).sort((s,a)=>s.ts.localeCompare(a.ts));let r=0;return n.map(s=>(r=Math.max(0,r+s.bufferedObservationTokenCount),{t:l4(s.ts,t),bufferedObservationTokenCount:r}))}function WRr(e,t){return[...e].sort((n,r)=>String(aP(n)).localeCompare(String(aP(r)))).map(n=>({t:l4(String(aP(n)),t),event:1}))}function ZRr(e,t){return[...e].sort((n,r)=>new Date(n.createdAt).getTime()-new Date(r.createdAt).getTime()).map(n=>({t:l4(new Date(n.createdAt).toISOString(),t),event:1,role:n.role}))}function GRr({domain:e}){const t=[0,.25,.5,.75,1];return o.jsxs("div",{className:"grid grid-cols-[6rem_1fr] items-center",children:[o.jsx("p",{className:"flex items-center self-stretch border-r border-border1/50 pl-3 text-ui-xs font-medium text-icon3",children:"Time"}),o.jsx("div",{className:"flex justify-between px-1 py-1.5 font-mono text-ui-xs text-icon3",children:t.map(n=>o.jsx("span",{children:MRt(N_e(n,e))},n))})]})}function I_e({active:e,payload:t,domain:n,showValue:r}){if(!e||!t?.length)return null;const s=t[0]?.payload?.t,a=n!=null&&s!=null?MRt(N_e(s,n)):null,i=t.filter(l=>l.name!=="t"&&l.name!=="time"&&l.value!=null);return r?o.jsxs("div",{className:"flex flex-col gap-0.5 rounded border border-border1 bg-surface3 px-2 py-1.5 font-mono text-ui-xs shadow",children:[a&&o.jsxs("div",{className:"flex items-center justify-between gap-3",children:[o.jsx("span",{className:"text-icon3",children:"time"}),o.jsx("span",{className:"text-neutral6",children:a})]}),i.map(l=>o.jsxs("div",{className:"flex items-center justify-between gap-3",children:[o.jsx("span",{className:"text-icon3",children:l.name}),o.jsx("span",{className:"text-neutral6",children:typeof l.value=="number"?Math.round(l.value).toLocaleString():String(l.value)})]},l.name))]}):o.jsx("div",{className:"rounded border border-border1 bg-surface3 px-2 py-1 font-mono text-ui-xs shadow",children:a&&o.jsx("span",{className:"text-neutral6",children:a})})}function QRr({label:e,data:t,dataKey:n,color:r,gradientId:s,domain:a,zoomDomain:i,threshold:l}){const c=Math.max(0,...t.map(d=>Number(d[n])||0)),u=l!=null?Math.max(c,l):void 0;return o.jsxs("div",{className:"relative grid grid-cols-[6rem_1fr] items-center border-b border-border1/50 hover:z-10",children:[o.jsx("p",{className:"flex items-center self-stretch border-r border-border1/50 pl-3 text-ui-xs font-medium text-icon3",children:e}),o.jsx("div",{children:o.jsx(N3,{width:"100%",height:32,children:o.jsxs(Wgr,{data:t,margin:{top:0,right:0,bottom:0,left:0},children:[o.jsx("defs",{children:o.jsxs("linearGradient",{id:s,x1:"0",y1:"0",x2:"0",y2:"1",children:[o.jsx("stop",{offset:"0%",stopColor:r,stopOpacity:.35}),o.jsx("stop",{offset:"100%",stopColor:r,stopOpacity:.03})]})}),o.jsx(sI,{dataKey:"t",type:"number",domain:i,allowDataOverflow:!0,hide:!0}),o.jsx(aI,{type:"number",domain:u!=null?[0,u]:void 0,hide:!0}),o.jsx(V3,{content:o.jsx(I_e,{domain:a,showValue:!0}),cursor:{stroke:"rgba(255,255,255,0.08)"}}),o.jsx(qke,{type:"linear",dataKey:n,stroke:r,strokeWidth:1,strokeOpacity:.6,fill:`url(#${s})`,isAnimationActive:!1}),l!=null&&o.jsx($ke,{y:l,stroke:r,strokeDasharray:"4 3",strokeOpacity:.4})]})})})]})}function YRr({label:e,data:t,color:n,height:r=32,domain:s,zoomDomain:a}){return o.jsxs("div",{className:"relative grid grid-cols-[6rem_1fr] items-center border-b border-border1/50 hover:z-10",children:[o.jsx("p",{className:"flex items-center self-stretch border-r border-border1/50 pl-3 text-ui-xs font-medium text-icon3",children:e}),o.jsx("div",{children:o.jsx(N3,{width:"100%",height:r,children:o.jsxs(yEt,{margin:{top:0,right:0,bottom:0,left:0},children:[o.jsx(sI,{dataKey:"t",type:"number",domain:a,allowDataOverflow:!0,hide:!0}),o.jsx(aI,{dataKey:"event",type:"number",domain:[0,2],hide:!0}),o.jsx(V3,{content:o.jsx(I_e,{domain:s}),cursor:!1}),o.jsx(Vke,{data:t,fill:n,isAnimationActive:!1,shape:i=>{const l=i.cx;return o.jsxs("g",{children:[o.jsx("rect",{x:l-6,y:0,width:12,height:r,fill:"transparent"}),o.jsx("rect",{x:l-1.5,y:0,width:3,height:r,fill:n})]})}})]})})})]})}function _We({label:e,areaData:t,areaDataKey:n,eventData:r,color:s,gradientId:a,domain:i,zoomDomain:l,threshold:c,height:u=44,onSelectT:d}){const f=new Map(t.map(y=>[y.t,Number(y[n]??0)])),p=r.reduce((y,b)=>{const S=y.get(b.t);return S?S.push(b):y.set(b.t,[b]),y},new Map),h=Array.from(new Set([...f.keys(),...p.keys()])).sort((y,b)=>y-b);let m=0;const v=[];for(const y of h){const b=f.get(y);b!=null&&(m=b);const S=p.get(y);if(S&&S.length>0)for(const w of S)v.push({...w,t:y,[n]:m});else v.push({t:y,[n]:m})}return o.jsxs("div",{className:"relative grid grid-cols-[6rem_1fr] items-center border-b border-border1/50 hover:z-10",children:[o.jsx("p",{className:"flex items-center self-stretch border-r border-border1/50 pl-3 text-ui-xs font-medium text-icon3",children:e}),o.jsx("div",{children:o.jsx(N3,{width:"100%",height:u,children:o.jsxs(Ggr,{margin:{top:0,right:0,bottom:0,left:0},onClick:y=>{const b=y?.activeLabel;b!=null&&d&&d(Number(b))},className:d?"cursor-pointer":void 0,children:[o.jsx("defs",{children:o.jsxs("linearGradient",{id:a,x1:"0",y1:"0",x2:"0",y2:"1",children:[o.jsx("stop",{offset:"0%",stopColor:s,stopOpacity:.35}),o.jsx("stop",{offset:"100%",stopColor:s,stopOpacity:.06})]})}),o.jsx(sI,{dataKey:"t",type:"number",domain:l,allowDataOverflow:!0,hide:!0}),o.jsx(aI,{yAxisId:"area",dataKey:n,type:"number",hide:!0,domain:[0,"dataMax"]}),o.jsx(V3,{content:o.jsx(I_e,{domain:i,showValue:!0}),cursor:!1}),o.jsx(qke,{yAxisId:"area",data:v,type:"linear",dataKey:n,stroke:s,strokeWidth:1,strokeOpacity:.6,fill:`url(#${a})`,isAnimationActive:!1,activeDot:{r:5,stroke:s,strokeWidth:2,fill:"#0a0a0a"},dot:y=>y.payload?.event?o.jsx("circle",{cx:y.cx,cy:y.cy,r:4,fill:s}):o.jsx(o.Fragment,{})}),c!=null&&o.jsx($ke,{yAxisId:"area",y:c,stroke:s,strokeDasharray:"4 3",strokeOpacity:.4})]})})})]})}function XRr({tDomain:e,zoomLeft:t,zoomRight:n,onZoomLeftChange:r,onZoomRightChange:s,onReset:a}){const i=g.useRef(null),l=g.useRef(null),c=e.tMax-e.tMin,u=c>0?(t-e.tMin)/c*100:0,d=c>0?(n-e.tMin)/c*100:100,f=g.useCallback(p=>{const h=i.current;if(!h)return null;const m=h.getBoundingClientRect(),v=Math.max(0,Math.min(1,(p-m.left)/m.width));return e.tMin+v*(e.tMax-e.tMin)},[e.tMin,e.tMax]);return g.useEffect(()=>{const p=m=>{if(!l.current)return;const v=f(m.clientX);v!=null&&(l.current==="left"?r(Math.min(v,n)):s(Math.max(v,t)))},h=()=>{l.current=null};return window.addEventListener("mousemove",p),window.addEventListener("mouseup",h),()=>{window.removeEventListener("mousemove",p),window.removeEventListener("mouseup",h)}},[f,t,n,r,s]),o.jsxs("div",{className:"grid grid-cols-[6rem_1fr] items-center border-b border-border1/50",children:[o.jsxs("div",{className:"flex items-center gap-1 self-stretch border-r border-border1/50 pl-3",children:[o.jsx("p",{className:"text-ui-xs font-medium text-icon3",children:"Zoom"}),o.jsx(de,{variant:"ghost",size:"icon-sm","aria-label":"Reset zoom",onClick:a,children:o.jsx(GOn,{className:"size-3"})})]}),o.jsxs("div",{ref:i,className:"relative h-6 cursor-pointer select-none",onMouseDown:p=>{const h=f(p.clientX);if(h==null)return;p.preventDefault();const m=Math.abs(h-t),v=Math.abs(h-n);m<=v?(r(Math.min(h,n)),l.current="left"):(s(Math.max(h,t)),l.current="right")},children:[o.jsx("div",{className:"absolute inset-y-0 left-0 bg-surface2/60",style:{width:`${u}%`}}),o.jsx("div",{className:"absolute inset-y-0 border-y border-border1/30 bg-neutral6/5",style:{left:`${u}%`,right:`${100-d}%`}}),o.jsx("div",{className:"absolute inset-y-0 right-0 bg-surface2/60",style:{width:`${100-d}%`}}),o.jsx("div",{className:"absolute inset-y-0 w-1 cursor-col-resize bg-neutral6/50 hover:bg-neutral6",style:{left:`${u}%`,transform:"translateX(-50%)"},onMouseDown:p=>{p.preventDefault(),p.stopPropagation(),l.current="left"}}),o.jsx("div",{className:"absolute inset-y-0 w-1 cursor-col-resize bg-neutral6/50 hover:bg-neutral6",style:{left:`${d}%`,transform:"translateX(-50%)"},onMouseDown:p=>{p.preventDefault(),p.stopPropagation(),l.current="right"}})]})]})}const KRr={tMin:0,tMax:1};function JRr({omRecords:e,markers:t,messages:n,tDomain:r,observationThreshold:s,reflectionThreshold:a,onSelectTimestamp:i,zoomRange:l,onZoomRangeChange:c}){const u=r??KRr,d=g.useCallback(q=>{i?.(MRr(q,u))},[i,u]),f=l!=null&&c!=null,[p,h]=g.useState(u.tMin),[m,v]=g.useState(u.tMax);g.useEffect(()=>{f||(h(u.tMin),v(u.tMax))},[u.tMin,u.tMax,f]);const y=f?l.left:p,b=f?l.right:m,S=g.useCallback(q=>{f?c({left:q,right:b}):h(q)},[f,c,b]),w=g.useCallback(q=>{f?c({left:y,right:q}):v(q)},[f,c,y]),k=g.useCallback(()=>{f?c({left:u.tMin,right:u.tMax}):(h(u.tMin),v(u.tMax))},[f,c,u.tMin,u.tMax]),_=u.tMax-u.tMin,C=_>0?(y-u.tMin)/_:0,E=_>0?(b-u.tMin)/_:1,j=[C,E],N=g.useMemo(()=>ZRr(n,u),[n,u]),I=g.useMemo(()=>qRr(e,t,u),[e,t,u]),R=g.useMemo(()=>VRr(e,t,u),[e,t,u]),P=g.useMemo(()=>HRr(t,u),[t,u]),L=g.useMemo(()=>WRr(e,u),[e,u]);return N.length>0||I.length>0||R.length>0||L.length>0?o.jsxs("div",{className:"flex flex-col pb-2 pr-2 [&_.recharts-surface]:outline-none",children:[o.jsx(_We,{label:"Messages",areaData:I,areaDataKey:"pendingMessageTokens",eventData:N,color:BRr,gradientId:"grad-messages",domain:u,zoomDomain:j,threshold:s,onSelectT:i?d:void 0}),o.jsx(_We,{label:"Observations",areaData:R,areaDataKey:"observationTokenCount",eventData:L,color:URr,gradientId:"grad-observations",domain:u,zoomDomain:j,threshold:a,onSelectT:i?d:void 0}),P.length>0&&o.jsx(QRr,{label:"Buffered obs",data:P,dataKey:"bufferedObservationTokenCount",color:OWe,gradientId:"grad-buffered-obs",domain:u,zoomDomain:j,threshold:a}),L.length>0&&o.jsx(YRr,{label:"Events",data:L,color:OWe,domain:u,zoomDomain:j}),o.jsx(GRr,{domain:u}),o.jsx(XRr,{tDomain:u,zoomLeft:y,zoomRight:b,onZoomLeftChange:S,onZoomRightChange:w,onReset:k})]}):null}class jl{constructor(t,n,r,s){this.fromA=t,this.toA=n,this.fromB=r,this.toB=s}offset(t,n=t){return new jl(this.fromA+t,this.toA+t,this.fromB+n,this.toB+n)}}function t_(e,t,n,r,s,a){if(e==r)return[];let i=R_e(e,t,n,r,s,a),l=P_e(e,t+i,n,r,s+i,a);t+=i,n-=l,s+=i,a-=l;let c=n-t,u=a-s;if(!c||!u)return[new jl(t,n,s,a)];if(c>u){let f=e.slice(t,n).indexOf(r.slice(s,a));if(f>-1)return[new jl(t,t+f,s,s),new jl(t+f+u,n,a,a)]}else if(u>c){let f=r.slice(s,a).indexOf(e.slice(t,n));if(f>-1)return[new jl(t,t,s,s+f),new jl(n,n,s+f+c,a)]}if(c==1||u==1)return[new jl(t,n,s,a)];let d=zRt(e,t,n,r,s,a);if(d){let[f,p,h]=d;return t_(e,t,f,r,s,p).concat(t_(e,f+h,n,r,p+h,a))}return e2r(e,t,n,r,s,a)}let S2=1e9,k2=0,A_e=!1;function e2r(e,t,n,r,s,a){let i=n-t,l=a-s;if(S2<1e9&&Math.min(i,l)>S2*16||k2>0&&Date.now()>k2)return Math.min(i,l)>S2*64?[new jl(t,n,s,a)]:CWe(e,t,n,r,s,a);let c=Math.ceil((i+l)/2);gre.reset(c),vre.reset(c);let u=(h,m)=>e.charCodeAt(t+h)==r.charCodeAt(s+m),d=(h,m)=>e.charCodeAt(n-h-1)==r.charCodeAt(a-m-1),f=(i-l)%2!=0?vre:null,p=f?null:gre;for(let h=0;h<c;h++){if(h>S2||k2>0&&!(h&63)&&Date.now()>k2)return CWe(e,t,n,r,s,a);let m=gre.advance(h,i,l,c,f,!1,u)||vre.advance(h,i,l,c,p,!0,d);if(m)return t2r(e,t,n,t+m[0],r,s,a,s+m[1])}return[new jl(t,n,s,a)]}class LRt{constructor(){this.vec=[]}reset(t){this.len=t<<1;for(let n=0;n<this.len;n++)this.vec[n]=-1;this.vec[t+1]=0,this.start=this.end=0}advance(t,n,r,s,a,i,l){for(let c=-t+this.start;c<=t-this.end;c+=2){let u=s+c,d=c==-t||c!=t&&this.vec[u-1]<this.vec[u+1]?this.vec[u+1]:this.vec[u-1]+1,f=d-c;for(;d<n&&f<r&&l(d,f);)d++,f++;if(this.vec[u]=d,d>n)this.end+=2;else if(f>r)this.start+=2;else if(a){let p=s+(n-r)-c;if(p>=0&&p<this.len&&a.vec[p]!=-1)if(i){let h=a.vec[p];if(h>=n-d)return[h,s+h-p]}else{let h=n-a.vec[p];if(d>=h)return[d,f]}}}return null}}const gre=new LRt,vre=new LRt;function t2r(e,t,n,r,s,a,i,l){let c=!1;return!YT(e,r)&&++r==n&&(c=!0),!YT(s,l)&&++l==i&&(c=!0),c?[new jl(t,n,a,i)]:t_(e,t,r,s,a,l).concat(t_(e,r,n,s,l,i))}function FRt(e,t){let n=1,r=Math.min(e,t);for(;n<r;)n=n<<1;return n}function R_e(e,t,n,r,s,a){if(t==n||t==a||e.charCodeAt(t)!=r.charCodeAt(s))return 0;let i=FRt(n-t,a-s);for(let l=t,c=s;;){let u=l+i,d=c+i;if(u>n||d>a||e.slice(l,u)!=r.slice(c,d)){if(i==1)return l-t-(YT(e,l)?0:1);i=i>>1}else{if(u==n||d==a)return u-t;l=u,c=d}}}function P_e(e,t,n,r,s,a){if(t==n||s==a||e.charCodeAt(n-1)!=r.charCodeAt(a-1))return 0;let i=FRt(n-t,a-s);for(let l=n,c=a;;){let u=l-i,d=c-i;if(u<t||d<s||e.slice(u,l)!=r.slice(d,c)){if(i==1)return n-l-(YT(e,l)?0:1);i=i>>1}else{if(u==t||d==s)return n-u;l=u,c=d}}}function Kge(e,t,n,r,s,a,i,l){let c=r.slice(s,a),u=null;for(;;){if(u||i<l)return u;for(let d=t+i;;){YT(e,d)||d++;let f=d+i;if(YT(e,f)||(f+=f==d+1?1:-1),f>=n)break;let p=e.slice(d,f),h=-1;for(;(h=c.indexOf(p,h+1))!=-1;){let m=R_e(e,f,n,r,s+h+p.length,a),v=P_e(e,t,d,r,s,s+h),y=p.length+m+v;(!u||u[2]<y)&&(u=[d-v,s+h-v,y])}d=f}if(l<0)return u;i=i>>1}}function zRt(e,t,n,r,s,a){let i=n-t,l=a-s;if(i<l){let c=zRt(r,s,a,e,t,n);return c&&[c[1],c[0],c[2]]}return i<4||l*2<i?null:Kge(e,t,n,r,s,a,Math.floor(i/4),-1)}function CWe(e,t,n,r,s,a){A_e=!0;let i=n-t,l=a-s,c;if(i<l){let p=Kge(r,s,a,e,t,n,Math.floor(i/6),50);c=p&&[p[1],p[0],p[2]]}else c=Kge(e,t,n,r,s,a,Math.floor(l/6),50);if(!c)return[new jl(t,n,s,a)];let[u,d,f]=c;return t_(e,t,u,r,s,d).concat(t_(e,u+f,n,r,d+f,a))}function BRt(e,t){for(let n=1;n<e.length;n++){let r=e[n-1],s=e[n];r.toA>s.fromA-t&&r.toB>s.fromB-t&&(e[n-1]=new jl(r.fromA,s.toA,r.fromB,s.toB),e.splice(n--,1))}}function n2r(e,t,n){for(;;){BRt(n,1);let r=!1;for(let s=0;s<n.length;s++){let a=n[s],i,l;(i=R_e(e,a.fromA,a.toA,t,a.fromB,a.toB))&&(a=n[s]=new jl(a.fromA+i,a.toA,a.fromB+i,a.toB)),(l=P_e(e,a.fromA,a.toA,t,a.fromB,a.toB))&&(a=n[s]=new jl(a.fromA,a.toA-l,a.fromB,a.toB-l));let c=a.toA-a.fromA,u=a.toB-a.fromB;if(c&&u)continue;let d=a.fromA-(s?n[s-1].toA:0),f=(s<n.length-1?n[s+1].fromA:e.length)-a.toA;if(!d||!f)continue;let p=c?e.slice(a.fromA,a.toA):t.slice(a.fromB,a.toB);d<=p.length&&e.slice(a.fromA-d,a.fromA)==p.slice(p.length-d)?(n[s]=new jl(a.fromA-d,a.toA-d,a.fromB-d,a.toB-d),r=!0):f<=p.length&&e.slice(a.toA,a.toA+f)==p.slice(0,f)&&(n[s]=new jl(a.fromA+f,a.toA+f,a.fromB+f,a.toB+f),r=!0)}if(!r)break}return n}function r2r(e,t,n){for(let r=0,s=0;s<e.length;s++){let a=e[s],i=a.toA-a.fromA,l=a.toB-a.fromB;if(i&&l||i>3||l>3){let c=s==e.length-1?t.length:e[s+1].fromA,u=a.fromA-r,d=c-a.toA,f=jWe(t,a.fromA,u),p=EWe(t,a.toA,d),h=a.fromA-f,m=p-a.toA;if((!i||!l)&&h&&m){let v=Math.max(i,l),[y,b,S]=i?[t,a.fromA,a.toA]:[n,a.fromB,a.toB];v>h&&t.slice(f,a.fromA)==y.slice(S-h,S)?(a=e[s]=new jl(f,f+i,a.fromB-h,a.toB-h),f=a.fromA,p=EWe(t,a.toA,c-a.toA)):v>m&&t.slice(a.toA,p)==y.slice(b,b+m)&&(a=e[s]=new jl(p-i,p,a.fromB+m,a.toB+m),p=a.toA,f=jWe(t,a.fromA,a.fromA-r)),h=a.fromA-f,m=p-a.toA}if(h||m)a=e[s]=new jl(a.fromA-h,a.toA+m,a.fromB-h,a.toB+m);else if(i){if(!l){let v=NWe(t,a.fromA,a.toA),y,b=v<0?-1:TWe(t,a.toA,a.fromA);v>-1&&(y=v-a.fromA)<=d&&t.slice(a.fromA,v)==t.slice(a.toA,a.toA+y)?a=e[s]=a.offset(y):b>-1&&(y=a.toA-b)<=u&&t.slice(a.fromA-y,a.fromA)==t.slice(b,a.toA)&&(a=e[s]=a.offset(-y))}}else{let v=NWe(n,a.fromB,a.toB),y,b=v<0?-1:TWe(n,a.toB,a.fromB);v>-1&&(y=v-a.fromB)<=d&&n.slice(a.fromB,v)==n.slice(a.toB,a.toB+y)?a=e[s]=a.offset(y):b>-1&&(y=a.toB-b)<=u&&n.slice(a.fromB-y,a.fromB)==n.slice(b,a.toB)&&(a=e[s]=a.offset(-y))}}r=a.toA}return BRt(e,3),e}let Jk;try{Jk=new RegExp("[\\p{Alphabetic}\\p{Number}]","u")}catch{}function URt(e){return e>48&&e<58||e>64&&e<91||e>96&&e<123}function qRt(e,t){if(t==e.length)return 0;let n=e.charCodeAt(t);return n<192?URt(n)?1:0:Jk?!WRt(n)||t==e.length-1?Jk.test(String.fromCharCode(n))?1:0:Jk.test(e.slice(t,t+2))?2:0:0}function VRt(e,t){if(!t)return 0;let n=e.charCodeAt(t-1);return n<192?URt(n)?1:0:Jk?!ZRt(n)||t==1?Jk.test(String.fromCharCode(n))?1:0:Jk.test(e.slice(t-2,t))?2:0:0}const HRt=8;function EWe(e,t,n){if(t==e.length||!VRt(e,t))return t;for(let r=t,s=t+n,a=0;a<HRt;a++){let i=qRt(e,r);if(!i||r+i>s)return r;r+=i}return t}function jWe(e,t,n){if(!t||!qRt(e,t))return t;for(let r=t,s=t-n,a=0;a<HRt;a++){let i=VRt(e,r);if(!i||r-i<s)return r;r-=i}return t}function TWe(e,t,n){for(;t!=n;t--)if(e.charCodeAt(t-1)==10)return t;return-1}function NWe(e,t,n){for(;t!=n;t++)if(e.charCodeAt(t)==10)return t;return-1}const WRt=e=>e>=55296&&e<=56319,ZRt=e=>e>=56320&&e<=57343;function YT(e,t){return!t||t==e.length||!WRt(e.charCodeAt(t-1))||!ZRt(e.charCodeAt(t))}function s2r(e,t,n){var r;let s=n?.override;return s?s(e,t):(S2=((r=n?.scanLimit)!==null&&r!==void 0?r:1e9)>>1,k2=n?.timeout?Date.now()+n.timeout:0,A_e=!1,n2r(e,t,t_(e,0,e.length,t,0,t.length)))}function GRt(){return!A_e}function QRt(e,t,n){return r2r(s2r(e,t,n),e,t)}const cg=On.define({combine:e=>e[0]}),Jge=vr.define(),a2r=On.define(),cx=gl.define({create(e){return null},update(e,t){for(let n of t.effects)n.is(Jge)&&(e=n.value);for(let n of t.state.facet(a2r))e=n(e,t);return e}});class Mj{constructor(t,n,r,s,a,i=!0){this.changes=t,this.fromA=n,this.toA=r,this.fromB=s,this.toB=a,this.precise=i}offset(t,n){return t||n?new Mj(this.changes,this.fromA+t,this.toA+t,this.fromB+n,this.toB+n,this.precise):this}get endA(){return Math.max(this.fromA,this.toA-1)}get endB(){return Math.max(this.fromB,this.toB-1)}static build(t,n,r){let s=QRt(t.toString(),n.toString(),r);return YRt(s,t,n,0,0,GRt())}static updateA(t,n,r,s,a){return $We(PWe(t,s,!0,r.length),t,n,r,a)}static updateB(t,n,r,s,a){return $We(PWe(t,s,!1,n.length),t,n,r,a)}}function IWe(e,t,n,r){let s=n.lineAt(e),a=r.lineAt(t);return s.to==e&&a.to==t&&e<n.length&&t<r.length?[e+1,t+1]:[s.from,a.from]}function AWe(e,t,n,r){let s=n.lineAt(e),a=r.lineAt(t);return s.from==e&&a.from==t?[e,t]:[s.to+1,a.to+1]}function YRt(e,t,n,r,s,a){let i=[];for(let l=0;l<e.length;l++){let c=e[l],[u,d]=IWe(c.fromA+r,c.fromB+s,t,n),[f,p]=AWe(c.toA+r,c.toB+s,t,n),h=[c.offset(-u+r,-d+s)];for(;l<e.length-1;){let m=e[l+1],[v,y]=IWe(m.fromA+r,m.fromB+s,t,n);if(v>f+1&&y>p+1)break;h.push(m.offset(-u+r,-d+s)),[f,p]=AWe(m.toA+r,m.toB+s,t,n),l++}i.push(new Mj(h,u,Math.max(u,f),d,Math.max(d,p),a))}return i}const w9=1e3;function RWe(e,t,n,r){let s=0,a=e.length;for(;;){if(s==a){let d=0,f=0;s&&({toA:d,toB:f}=e[s-1]);let p=t-(n?d:f);return[d+p,f+p]}let i=s+a>>1,l=e[i],[c,u]=n?[l.fromA,l.toA]:[l.fromB,l.toB];if(c>t)a=i;else if(u<=t)s=i+1;else return r?[l.fromA,l.fromB]:[l.toA,l.toB]}}function PWe(e,t,n,r){let s=[];return t.iterChangedRanges((a,i,l,c)=>{let u=0,d=n?t.length:r,f=0,p=n?r:t.length;a>w9&&([u,f]=RWe(e,a-w9,n,!0)),i<t.length-w9&&([d,p]=RWe(e,i+w9,n,!1));let h=c-l-(i-a),m,[v,y]=n?[h,0]:[0,h];s.length&&(m=s[s.length-1]).toA>=u?s[s.length-1]={fromA:m.fromA,fromB:m.fromB,toA:d,toB:p,diffA:m.diffA+v,diffB:m.diffB+y}:s.push({fromA:u,toA:d,fromB:f,toB:p,diffA:v,diffB:y})}),s}function $We(e,t,n,r,s){if(!e.length)return t;let a=[];for(let i=0,l=0,c=0,u=0;;i++){let d=i==e.length?null:e[i],f=d?d.fromA+l:n.length,p=d?d.fromB+c:r.length;for(;u<t.length;){let y=t[u];if(d&&(y.toA+l>f||y.toB+c>p))break;a.push(y.offset(l,c)),u++}if(!d)break;let h=d.toA+l+d.diffA,m=d.toB+c+d.diffB,v=QRt(n.sliceString(f,h),r.sliceString(p,m),s);for(let y of YRt(v,n,r,f,p,GRt()))a.push(y);for(l+=d.diffA,c+=d.diffB;u<t.length;){let y=t[u];if(y.fromA+l>h&&y.fromB+c>m)break;u++}}return a}const i2r={scanLimit:500},XRt=bo.fromClass(class{constructor(e){({deco:this.deco,gutter:this.gutter}=LWe(e))}update(e){(e.docChanged||e.viewportChanged||o2r(e.startState,e.state)||l2r(e.startState,e.state))&&({deco:this.deco,gutter:this.gutter}=LWe(e.view))}},{decorations:e=>e.deco}),S9=Mg.low(Lvt({class:"cm-changeGutter",markers:e=>{var t;return((t=e.plugin(XRt))===null||t===void 0?void 0:t.gutter)||ws.empty}}));function o2r(e,t){return e.field(cx,!1)!=t.field(cx,!1)}function l2r(e,t){return e.facet(cg)!=t.facet(cg)}const MWe=Cn.line({class:"cm-changedLine"}),c2r=Cn.mark({class:"cm-changedText"}),u2r=Cn.mark({tagName:"ins",class:"cm-insertedLine"}),d2r=Cn.mark({tagName:"del",class:"cm-deletedLine"}),DWe=new class extends py{constructor(){super(...arguments),this.elementClass="cm-changedLineGutter"}};function f2r(e,t,n,r,s,a){let i=n?e.fromA:e.fromB,l=n?e.toA:e.toB,c=0;if(i!=l){s.add(i,i,MWe),s.add(i,l,n?d2r:u2r),a&&a.add(i,i,DWe);for(let u=t.iterRange(i,l-1),d=i;!u.next().done;){if(u.lineBreak){d++,s.add(d,d,MWe),a&&a.add(d,d,DWe);continue}let f=d+u.value.length;if(r)for(;c<e.changes.length;){let p=e.changes[c],h=i+(n?p.fromA:p.fromB),m=i+(n?p.toA:p.toB),v=Math.max(d,h),y=Math.min(f,m);if(v<y&&s.add(v,y,c2r),m<f)c++;else break}d=f}}}function LWe(e){let t=e.state.field(cx),{side:n,highlightChanges:r,markGutter:s,overrideChunk:a}=e.state.facet(cg),i=n=="a",l=new kd,c=s?new kd:null,{from:u,to:d}=e.viewport;for(let f of t){if((i?f.fromA:f.fromB)>=d)break;(i?f.toA:f.toB)>u&&(!a||!a(e.state,f,l,c))&&f2r(f,e.state.doc,i,r,l,c)}return{deco:l.finish(),gutter:c&&c.finish()}}class k9 extends Kp{constructor(t){super(),this.height=t}eq(t){return this.height==t.height}toDOM(){let t=document.createElement("div");return t.className="cm-mergeSpacer",t.style.height=this.height+"px",t}updateDOM(t){return t.style.height=this.height+"px",!0}get estimatedHeight(){return this.height}ignoreEvent(){return!1}}const dU=vr.define({map:(e,t)=>e.map(t)}),O2=gl.define({create:()=>Cn.none,update:(e,t)=>{for(let n of t.effects)if(n.is(dU))return n.value;return e.map(t.changes)},provide:e=>It.decorations.from(e)}),O9=.01;function FWe(e,t){if(e.size!=t.size)return!1;let n=e.iter(),r=t.iter();for(;n.value;){if(n.from!=r.from||Math.abs(n.value.spec.widget.height-r.value.spec.widget.height)>1)return!1;n.next(),r.next()}return!0}function p2r(e,t,n){let r=new kd,s=new kd,a=e.state.field(O2).iter(),i=t.state.field(O2).iter(),l=0,c=0,u=0,d=0,f=e.viewport,p=t.viewport;for(let y=0;;y++){let b=y<n.length?n[y]:null,S=b?b.fromA:e.state.doc.length,w=b?b.fromB:t.state.doc.length;if(l<S){let k=e.lineBlockAt(l).top+u,_=t.lineBlockAt(c).top+d,C=k-_;C<-O9?(u-=C,r.add(l,l,Cn.widget({widget:new k9(-C),block:!0,side:-1}))):C>O9&&(d+=C,s.add(c,c,Cn.widget({widget:new k9(C),block:!0,side:-1})))}if(S>l+1e3&&l<f.from&&S>f.from&&c<p.from&&w>p.from){let k=Math.min(f.from-l,p.from-c);l+=k,c+=k,y--}else if(b)l=b.toA,c=b.toB;else break;for(;a.value&&a.from<l;)u-=a.value.spec.widget.height,a.next();for(;i.value&&i.from<c;)d-=i.value.spec.widget.height,i.next()}for(;a.value;)u-=a.value.spec.widget.height,a.next();for(;i.value;)d-=i.value.spec.widget.height,i.next();let h=e.contentHeight+u-(t.contentHeight+d);h<O9?r.add(e.state.doc.length,e.state.doc.length,Cn.widget({widget:new k9(-h),block:!0,side:1})):h>O9&&s.add(t.state.doc.length,t.state.doc.length,Cn.widget({widget:new k9(h),block:!0,side:1}));let m=r.finish(),v=s.finish();FWe(m,e.state.field(O2))||e.dispatch({effects:dU.of(m)}),FWe(v,t.state.field(O2))||t.dispatch({effects:dU.of(v)})}const eve=vr.define({map:(e,t)=>t.mapPos(e)});class h2r extends Kp{constructor(t){super(),this.lines=t}eq(t){return this.lines==t.lines}toDOM(t){let n=document.createElement("div");return n.className="cm-collapsedLines",n.textContent=t.state.phrase("$ unchanged lines",this.lines),n.addEventListener("click",r=>{let s=t.posAtDOM(r.target);t.dispatch({effects:eve.of(s)});let{side:a,sibling:i}=t.state.facet(cg);i&&i().dispatch({effects:eve.of(m2r(s,t.state.field(cx),a=="a"))})}),n}ignoreEvent(t){return t instanceof MouseEvent}get estimatedHeight(){return 27}get type(){return"collapsed-unchanged-code"}}function m2r(e,t,n){let r=0,s=0;for(let a=0;;a++){let i=a<t.length?t[a]:null;if(!i||(n?i.fromA:i.fromB)>=e)return s+(e-r);[r,s]=n?[i.toA,i.toB]:[i.toB,i.toA]}}const g2r=gl.define({create(e){return Cn.none},update(e,t){e=e.map(t.changes);for(let n of t.effects)n.is(eve)&&(e=e.update({filter:r=>r!=n.value}));if(e.size&&t.state.field(cx)!=t.startState.field(cx,!1)){let n=t.state.facet(cg).side=="a",r=[];for(let s of t.state.field(cx))e.between(n?s.fromA:s.fromB,n?s.toA:s.toB,a=>{r.push(a)});r.length&&(e=e.update({filter:s=>r.indexOf(s)<0}))}return e},provide:e=>It.decorations.from(e)});function zWe({margin:e=3,minSize:t=4}){return g2r.init(n=>v2r(n,e,t))}function v2r(e,t,n){let r=new kd,s=e.facet(cg).side=="a",a=e.field(cx),i=1;for(let l=0;;l++){let c=l<a.length?a[l]:null,u=l?i+t:1,d=c?e.doc.lineAt(s?c.fromA:c.fromB).number-1-t:e.doc.lines,f=d-u+1;if(f>=n&&r.add(e.doc.line(u).from,e.doc.line(d).to,Cn.replace({widget:new h2r(f),block:!0})),!c)break;i=e.doc.lineAt(Math.min(e.doc.length,s?c.toA:c.toB)).number}return r.finish()}const y2r=It.styleModule.of(new kx({".cm-mergeView":{overflowY:"auto"},".cm-mergeViewEditors":{display:"flex",alignItems:"stretch"},".cm-mergeViewEditor":{flexGrow:1,flexBasis:0,overflow:"hidden"},".cm-merge-revert":{width:"1.6em",flexGrow:0,flexShrink:0,position:"relative"},".cm-merge-revert button":{position:"absolute",display:"block",width:"100%",boxSizing:"border-box",textAlign:"center",background:"none",border:"none",font:"inherit",cursor:"pointer"}})),b2r=It.baseTheme({".cm-mergeView & .cm-scroller, .cm-mergeView &":{height:"auto !important",overflowY:"visible !important"},"&.cm-merge-a .cm-changedLine, .cm-deletedChunk":{backgroundColor:"rgba(160, 128, 100, .08)"},"&.cm-merge-b .cm-changedLine, .cm-inlineChangedLine":{backgroundColor:"rgba(100, 160, 128, .08)"},"&light.cm-merge-a .cm-changedText, &light .cm-deletedChunk .cm-deletedText":{background:"linear-gradient(#ee443366, #ee443366) bottom/100% 2px no-repeat"},"&dark.cm-merge-a .cm-changedText, &dark .cm-deletedChunk .cm-deletedText":{background:"linear-gradient(#ffaa9966, #ffaa9966) bottom/100% 2px no-repeat"},"&light.cm-merge-b .cm-changedText":{background:"linear-gradient(#22bb22aa, #22bb22aa) bottom/100% 2px no-repeat"},"&dark.cm-merge-b .cm-changedText":{background:"linear-gradient(#88ff88aa, #88ff88aa) bottom/100% 2px no-repeat"},"&.cm-merge-b .cm-deletedText":{background:"#ff000033"},".cm-insertedLine, .cm-deletedLine, .cm-deletedLine del":{textDecoration:"none"},".cm-deletedChunk":{paddingLeft:"6px","& .cm-chunkButtons":{position:"absolute",insetInlineEnd:"5px"},"& button":{border:"none",cursor:"pointer",color:"white",margin:"0 2px",borderRadius:"3px","&[name=accept]":{background:"#2a2"},"&[name=reject]":{background:"#d43"}}},".cm-collapsedLines":{padding:"5px 5px 5px 10px",cursor:"pointer","&:before":{content:'"⦚"',marginInlineEnd:"7px"},"&:after":{content:'"⦚"',marginInlineStart:"7px"}},"&light .cm-collapsedLines":{color:"#444",background:"linear-gradient(to bottom, transparent 0, #f3f3f3 30%, #f3f3f3 70%, transparent 100%)"},"&dark .cm-collapsedLines":{color:"#ddd",background:"linear-gradient(to bottom, transparent 0, #222 30%, #222 70%, transparent 100%)"},".cm-changeGutter":{width:"3px",paddingLeft:"1px"},"&light.cm-merge-a .cm-changedLineGutter, &light .cm-deletedLineGutter":{background:"#e43"},"&dark.cm-merge-a .cm-changedLineGutter, &dark .cm-deletedLineGutter":{background:"#fa9"},"&light.cm-merge-b .cm-changedLineGutter":{background:"#2b2"},"&dark.cm-merge-b .cm-changedLineGutter":{background:"#8f8"},".cm-inlineChangedLineGutter":{background:"#75d"}}),BWe=new LN,_9=new LN;class x2r{constructor(t){this.revertDOM=null,this.revertToA=!1,this.revertToLeft=!1,this.measuring=-1,this.diffConf=t.diffConfig||i2r;let n=[Mg.low(XRt),b2r,y2r,O2,It.updateListener.of(f=>{this.measuring<0&&(f.heightChanged||f.viewportChanged)&&!f.transactions.some(p=>p.effects.some(h=>h.is(dU)))&&this.measure()})],r=[cg.of({side:"a",sibling:()=>this.b,highlightChanges:t.highlightChanges!==!1,markGutter:t.gutter!==!1})];t.gutter!==!1&&r.push(S9);let s=is.create({doc:t.a.doc,selection:t.a.selection,extensions:[t.a.extensions||[],It.editorAttributes.of({class:"cm-merge-a"}),_9.of(r),n]}),a=[cg.of({side:"b",sibling:()=>this.a,highlightChanges:t.highlightChanges!==!1,markGutter:t.gutter!==!1})];t.gutter!==!1&&a.push(S9);let i=is.create({doc:t.b.doc,selection:t.b.selection,extensions:[t.b.extensions||[],It.editorAttributes.of({class:"cm-merge-b"}),_9.of(a),n]});this.chunks=Mj.build(s.doc,i.doc,this.diffConf);let l=[cx.init(()=>this.chunks),BWe.of(t.collapseUnchanged?zWe(t.collapseUnchanged):[])];s=s.update({effects:vr.appendConfig.of(l)}).state,i=i.update({effects:vr.appendConfig.of(l)}).state,this.dom=document.createElement("div"),this.dom.className="cm-mergeView",this.editorDOM=this.dom.appendChild(document.createElement("div")),this.editorDOM.className="cm-mergeViewEditors";let c=t.orientation||"a-b",u=document.createElement("div");u.className="cm-mergeViewEditor";let d=document.createElement("div");d.className="cm-mergeViewEditor",this.editorDOM.appendChild(c=="a-b"?u:d),this.editorDOM.appendChild(c=="a-b"?d:u),this.a=new It({state:s,parent:u,root:t.root,dispatchTransactions:f=>this.dispatch(f,this.a)}),this.b=new It({state:i,parent:d,root:t.root,dispatchTransactions:f=>this.dispatch(f,this.b)}),this.setupRevertControls(!!t.revertControls,t.revertControls=="b-to-a",t.renderRevertControl),t.parent&&t.parent.appendChild(this.dom),this.scheduleMeasure()}dispatch(t,n){if(t.some(r=>r.docChanged)){let r=t[t.length-1],s=t.reduce((i,l)=>i.compose(l.changes),El.empty(t[0].startState.doc.length));this.chunks=n==this.a?Mj.updateA(this.chunks,r.newDoc,this.b.state.doc,s,this.diffConf):Mj.updateB(this.chunks,this.a.state.doc,r.newDoc,s,this.diffConf),n.update([...t,r.state.update({effects:Jge.of(this.chunks)})]);let a=n==this.a?this.b:this.a;a.update([a.state.update({effects:Jge.of(this.chunks)})]),this.scheduleMeasure()}else n.update(t)}reconfigure(t){if("diffConfig"in t&&(this.diffConf=t.diffConfig),"orientation"in t){let a=t.orientation!="b-a";if(a!=(this.editorDOM.firstChild==this.a.dom.parentNode)){let i=this.a.dom.parentNode,l=this.b.dom.parentNode;i.remove(),l.remove(),this.editorDOM.insertBefore(a?i:l,this.editorDOM.firstChild),this.editorDOM.appendChild(a?l:i),this.revertToLeft=!this.revertToLeft,this.revertDOM&&(this.revertDOM.textContent="")}}if("revertControls"in t||"renderRevertControl"in t){let a=!!this.revertDOM,i=this.revertToA,l=this.renderRevert;"revertControls"in t&&(a=!!t.revertControls,i=t.revertControls=="b-to-a"),"renderRevertControl"in t&&(l=t.renderRevertControl),this.setupRevertControls(a,i,l)}let n="highlightChanges"in t,r="gutter"in t,s="collapseUnchanged"in t;if(n||r||s){let a=[],i=[];if(n||r){let l=this.a.state.facet(cg),c=r?t.gutter!==!1:l.markGutter,u=n?t.highlightChanges!==!1:l.highlightChanges;a.push(_9.reconfigure([cg.of({side:"a",sibling:()=>this.b,highlightChanges:u,markGutter:c}),c?S9:[]])),i.push(_9.reconfigure([cg.of({side:"b",sibling:()=>this.a,highlightChanges:u,markGutter:c}),c?S9:[]]))}if(s){let l=BWe.reconfigure(t.collapseUnchanged?zWe(t.collapseUnchanged):[]);a.push(l),i.push(l)}this.a.dispatch({effects:a}),this.b.dispatch({effects:i})}this.scheduleMeasure()}setupRevertControls(t,n,r){this.revertToA=n,this.revertToLeft=this.revertToA==(this.editorDOM.firstChild==this.a.dom.parentNode),this.renderRevert=r,!t&&this.revertDOM?(this.revertDOM.remove(),this.revertDOM=null):t&&!this.revertDOM?(this.revertDOM=this.editorDOM.insertBefore(document.createElement("div"),this.editorDOM.firstChild.nextSibling),this.revertDOM.addEventListener("mousedown",s=>this.revertClicked(s)),this.revertDOM.className="cm-merge-revert"):this.revertDOM&&(this.revertDOM.textContent="")}scheduleMeasure(){if(this.measuring<0){let t=this.dom.ownerDocument.defaultView||window;this.measuring=t.requestAnimationFrame(()=>{this.measuring=-1,this.measure()})}}measure(){p2r(this.a,this.b,this.chunks),this.revertDOM&&this.updateRevertButtons()}updateRevertButtons(){let t=this.revertDOM,n=t.firstChild,r=this.a.viewport,s=this.b.viewport;for(let a=0;a<this.chunks.length;a++){let i=this.chunks[a];if(i.fromA>r.to||i.fromB>s.to)break;if(i.fromA<r.from||i.fromB<s.from)continue;let l=this.a.lineBlockAt(i.fromA).top+"px";for(;n&&+n.dataset.chunk<a;)n=UWe(n);n&&n.dataset.chunk==String(a)?(n.style.top!=l&&(n.style.top=l),n=n.nextSibling):t.insertBefore(this.renderRevertButton(l,a),n)}for(;n;)n=UWe(n)}renderRevertButton(t,n){let r;if(this.renderRevert)r=this.renderRevert();else{r=document.createElement("button");let s=this.a.state.phrase("Revert this chunk");r.setAttribute("aria-label",s),r.setAttribute("title",s),r.textContent=this.revertToLeft?"⇜":"⇝"}return r.style.top=t,r.setAttribute("data-chunk",String(n)),r}revertClicked(t){let n=t.target,r;for(;n&&n.parentNode!=this.revertDOM;)n=n.parentNode;if(n&&(r=this.chunks[n.dataset.chunk])){let[s,a,i,l,c,u]=this.revertToA?[this.b,this.a,r.fromB,r.toB,r.fromA,r.toA]:[this.a,this.b,r.fromA,r.toA,r.fromB,r.toB],d=s.state.sliceDoc(i,Math.max(i,l-1));i!=l&&u<=a.state.doc.length&&(d+=s.state.lineBreak),a.dispatch({changes:{from:c,to:Math.min(a.state.doc.length,u),insert:d},userEvent:"revert"}),t.preventDefault()}}destroy(){this.a.destroy(),this.b.destroy(),this.measuring>-1&&(this.dom.ownerDocument.defaultView||window).cancelAnimationFrame(this.measuring),this.dom.remove()}}function UWe(e){let t=e.nextSibling;return e.remove(),t}const w2r=It.theme({"&.cm-editor .cm-changedLine":{backgroundColor:"transparent",backgroundImage:"none",borderLeft:"none"},"&.cm-editor .cm-changedText":{backgroundImage:"none",backgroundColor:"#880000",padding:"1px 5px",display:"inline-block",borderRadius:"4px"},"&.cm-editor .cm-changedText, &.cm-editor .cm-changedText *":{color:"white"},"&.cm-editor .cm-line":{lineHeight:"1.5",opacity:"0.5"},"&.cm-editor .cm-line.cm-changedLine":{opacity:"1"},"&.cm-editor .cm-gutters":{display:"none"}});function S2r(){return UN({settings:{fontFamily:"var(--font-mono)",fontSize:"0.8125rem",lineHighlight:"transparent",gutterBackground:"transparent",gutterForeground:"#939393",background:"transparent"},styles:[{tag:[fe.className,fe.propertyName]}]})}function k2r(){const e=It.theme({"&":{backgroundColor:"transparent",color:"var(--neutral6)",fontSize:"0.8125rem"},"&.cm-editor .cm-scroller":{fontFamily:"var(--font-mono)"},".cm-gutters":{backgroundColor:"transparent",color:"var(--neutral2)",borderRight:"none"},".cm-content":{color:"var(--neutral6)"},".cm-activeLine":{backgroundColor:"transparent"},".cm-activeLineGutter":{backgroundColor:"transparent"}}),t=Dg.define([{tag:[fe.comment,fe.bracket],color:"var(--neutral2)"},{tag:[fe.string,fe.meta,fe.regexp],color:"var(--accent1)"},{tag:[fe.atom,fe.bool,fe.special(fe.variableName)],color:"var(--accent6)"},{tag:[fe.keyword,fe.operator,fe.tagName],color:"var(--accent2)"},{tag:[fe.function(fe.propertyName),fe.propertyName],color:"var(--accent5)"},{tag:[fe.definition(fe.variableName),fe.function(fe.variableName),fe.className,fe.attributeName],color:"var(--accent3)"},{tag:[fe.variableName,fe.number],color:"var(--accent5)"},{tag:[fe.name,fe.quote],color:"var(--accent1)"}]);return[e,B1(t)]}function $_e({codeA:e,codeB:t}){const n=g.useRef(null),r=g.useRef(null),s=PN().resolvedTheme==="dark",a=g.useMemo(()=>s?S2r():k2r(),[s]);return g.useEffect(()=>{if(!n.current)return;r.current&&r.current.destroy();const i=[gT(),a,w2r,It.lineWrapping,is.readOnly.of(!0)],l=new x2r({parent:n.current,a:{doc:e,extensions:i},b:{doc:t,extensions:i},collapseUnchanged:{margin:3,minSize:4}});return r.current=l,()=>{l.destroy(),r.current=null}},[e,t,a]),o.jsxs("div",{className:"relative overflow-auto rounded-xl border dark:border-white/10 border-border1 dark:bg-black/20 bg-surface3",children:[o.jsx("div",{className:"absolute left-1/2 top-0 h-full w-px dark:bg-white/10 bg-border1 z-10"}),o.jsx("div",{ref:n,className:"[&_.cm-mergeViewEditor]:flex-1 [&_.cm-editor]:bg-transparent [&_.cm-editor]:p-6 [&_.cm-gutters]:bg-transparent"})]})}function O2r(e){if(!e)return null;const t=e.match(/^(\d{1,2}):(\d{2})$/);if(!t)return e;const[,n,r]=t,s=Number(n),a=s>=12?"PM":"AM";return`${s%12||12}:${r} ${a}`}function _2r(e){return e==="🔴"?"high":e==="🟡"?"medium":e==="🟢"?"low":e==="✅"?"complete":null}function C2r(e,t){if(t)return{card:"bg-transparent border-transparent",text:"text-neutral3",time:"text-icon3"};switch(e){case"high":return{card:"border-purple-400/30 bg-purple-500/10",text:"text-neutral6",time:"text-purple-200/80"};case"medium":return{card:"border-blue-400/30 bg-blue-500/10",text:"text-neutral6",time:"text-blue-200/80"};case"low":return{card:"border-emerald-400/30 bg-emerald-500/10",text:"text-neutral6",time:"text-emerald-200/80"};case"complete":return{card:"border-green-400/30 bg-green-500/10",text:"text-neutral6",time:"text-green-200/80"};default:return{card:"border-border1 bg-surface2",text:"text-neutral6",time:"text-icon3"}}}function E2r(e){const t=e.trim();if(!t)return null;if(t.startsWith("* ->")||t.startsWith("->")){const r=t.replace(/^\*?\s*->\s*/,"").trim();return r?{text:r,time:null,priority:null,children:[]}:null}if(t.startsWith("-")){const r=t.replace(/^-\s*/,"").trim();return r?{text:r,time:null,priority:null,children:[]}:null}const n=t.match(/^\*\s*(🔴|🟡|🟢|✅)?\s*(?:\((\d{1,2}:\d{2})\))?\s*(.+)$/);if(n){const[,r,s,a]=n;return{text:a.trim(),time:s??null,priority:_2r(r),children:[]}}return{text:t,time:null,priority:null,children:[]}}function j2r(e){const t=e.match(/<observations>\s*([\s\S]*?)\s*<\/observations>/),n=(t?t[1]:e).trim();if(!n)return[];const r=n.split(`
|
|
512
|
-
`),s=[];let a=null,i=null;for(const l of r){const c=l.trim();if(!c)continue;const u=c.match(/^Date:\s*(.+?)(?:\s*\(([^)]+)\))?$/);if(u){a={title:u[1].trim(),relativeTime:u[2]?.trim()??null,items:[]},s.push(a),i=null;continue}a||(a={title:"Recent",relativeTime:null,items:[]},s.push(a));const f=(l.match(/^(\s*)/)?.[1].length??0)>=2&&(c.startsWith("* ->")||c.startsWith("->")||c.startsWith("-")),p=E2r(l);if(p){if(f&&i){i.children.push(p);continue}a.items.push(p),i=p}}return s}function KRt({items:e,nested:t=!1}){return o.jsx("div",{className:t?"space-y-2 border-l border-border1 pl-4":"space-y-3",children:e.map((n,r)=>{const s=C2r(n.priority,t);return o.jsx("div",{className:"space-y-2",children:o.jsxs("div",{className:"flex items-start gap-3",children:[o.jsx("div",{className:"w-12 shrink-0 pt-2 text-right",children:n.time&&o.jsx("span",{className:`font-mono text-ui-xs ${s.time}`,children:O2r(n.time)})}),o.jsxs("div",{className:K("min-w-0 flex-1 rounded-md border px-3 py-2",s.card),children:[o.jsx("p",{className:K("whitespace-pre-wrap break-words text-sm leading-6",s.text),children:n.text}),n.children.length>0&&o.jsx("div",{className:"mt-3",children:o.jsx(KRt,{items:n.children,nested:!0})})]})]})},`${n.text.slice(0,20)}-${r}`)})})}function T2r({observations:e}){const t=g.useMemo(()=>j2r(e),[e]);return t.length===0?o.jsx("p",{className:"italic text-xs text-icon3",children:"Initialized"}):o.jsx("div",{className:"space-y-5",children:t.map((n,r)=>o.jsxs("section",{className:"space-y-3",children:[o.jsx("div",{className:"flex items-baseline justify-between gap-3 border-b border-border1 pb-2",children:o.jsxs("div",{className:"min-w-0",children:[o.jsx("h3",{className:"text-xs font-medium text-neutral6",children:n.title}),n.relativeTime&&o.jsx("p",{className:"text-ui-xs text-icon3",children:n.relativeTime})]})}),o.jsx(KRt,{items:n.items})]},`${n.title}-${r}`))})}function N2r({records:e,selectedRecordId:t,onSelectRecord:n}){return e.length<=1?null:o.jsxs("div",{className:"border-l border-border1 min-w-[180px] w-[200px] flex flex-col overflow-hidden",children:[o.jsx("div",{className:"border-b border-border1 px-4 py-2",children:o.jsx("p",{className:"text-sm font-normal text-neutral6",children:"History"})}),o.jsx("div",{className:"flex-1 overflow-y-auto",children:e.map(r=>{const s=r.id===t;return o.jsx("button",{type:"button",className:K("w-full cursor-pointer border-l-2 border-l-transparent px-3 py-2 text-left truncate text-xs text-icon3 transition-all hover:bg-surface3/50",s&&"bg-surface3/50 border-l-accent1"),onClick:()=>n(r.id),children:r.activeObservations||o.jsx("span",{className:"italic text-icon3",children:r.isObserving||r.isReflecting?"Processing…":"Initialized"})},r.id)})})]})}function I2r({records:e,selectedRecordId:t,onSelectRecord:n,isLoading:r}){const[s,a]=g.useState(!1),i=g.useMemo(()=>[...e].sort((f,p)=>new Date(f.createdAt).getTime()-new Date(p.createdAt).getTime()),[e]),l=t?i.find(f=>f.id===t):i[i.length-1],c=l?i.findIndex(f=>f.id===l.id):-1,u=c>0?i[c-1]:null;if(g.useEffect(()=>{!t&&i.length>0&&n(i[i.length-1].id)},[t,i,n]),r)return o.jsxs("div",{className:"p-4 space-y-4",children:[o.jsx(bt,{className:"h-6 w-40"}),o.jsx(bt,{className:"h-32 w-full"}),o.jsx(bt,{className:"h-32 w-full"})]});if(!l)return o.jsx("div",{className:"flex h-full items-center justify-center",children:o.jsx(Cr,{iconSlot:o.jsx(spt,{className:"size-4"}),titleSlot:"No observations",descriptionSlot:"No observational memory snapshots available for this thread."})});const d=typeof l.activeObservations=="string"?l.activeObservations:"";return o.jsxs("div",{className:"flex h-full w-full overflow-hidden",children:[o.jsxs("div",{className:"flex min-w-0 flex-1 flex-col overflow-hidden",children:[u&&o.jsx("div",{className:"border-b border-border1 px-4 py-2",children:o.jsx("div",{className:"flex items-start justify-end gap-3",children:o.jsxs("label",{className:"flex cursor-pointer items-center gap-1.5",children:[o.jsx(Mo,{checked:s,onCheckedChange:f=>a(f===!0)}),o.jsx("span",{className:"text-xs text-icon3",children:"Show diff"})]})})}),o.jsx("div",{"data-testid":"observation-detail-body",className:"flex-1 overflow-y-auto p-4",children:s&&u?o.jsx($_e,{codeA:typeof u.activeObservations=="string"?u.activeObservations:"",codeB:d}):d?o.jsx(T2r,{observations:d}):o.jsx("p",{className:"italic text-xs text-icon3",children:l.isObserving||l.isReflecting?"Processing…":"Initialized"})})]}),o.jsx(N2r,{records:i,selectedRecordId:l.id,onSelectRecord:n})]})}function qWe(e){if(e===0)return"0";const t=e/1e3,n=t<.1?2:1;return t.toFixed(n).replace(/\.0+$/,"").replace(/(\.\d*[1-9])0$/,"$1")}function VWe({label:e,value:t,max:n,tone:r}){const s=Math.max(0,Math.min(100,t/n*100)),a=r==="message"?"bg-blue-500/80":"bg-violet-500/80";return o.jsxs("div",{className:"min-w-0 flex-1",children:[o.jsxs("div",{className:"mb-1 flex items-center justify-between gap-2 font-mono text-ui-xs text-icon3",children:[o.jsx("span",{className:"uppercase tracking-wide text-icon6",children:e}),o.jsxs("span",{className:"tabular-nums text-icon3",children:[qWe(t),"/",qWe(n),"k"]})]}),o.jsx("div",{className:"h-1.5 overflow-hidden rounded-full bg-white/[0.08]",children:o.jsx("div",{className:`h-full rounded-full ${a}`,style:{width:`${s}%`}})})]})}function A2r({messageTokens:e,messageThreshold:t,memoryTokens:n,memoryThreshold:r,memoryLabel:s="Memory"}){const a=e!=null&&t!=null,i=n!=null&&r!=null;return!a&&!i?null:o.jsx("div",{className:"border-b border-border1 px-3 py-2",children:o.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row",children:[a?o.jsx(VWe,{label:"Messages",value:e,max:t,tone:"message"}):null,i?o.jsx(VWe,{label:s,value:n,max:r,tone:"memory"}):null]})})}function R2r({messages:e,omRecords:t,isLoading:n=!1,onClose:r,selectedTimestamp:s,onSelectTimestamp:a,contextWindow:i}){const[l,c]=g.useState(null),u=g.useMemo(()=>PRr(e),[e]),d=g.useMemo(()=>e.length===0?{tMin:0,tMax:1}:$Rr(e.map(_=>new Date(_.createdAt).toISOString())),[e]),f=g.useMemo(()=>zRr({markers:u,omRecords:t}),[u,t]),p=i?.memoryTokens??f?.memoryTokens,h=i?.memoryThreshold??f?.memoryThreshold,[m,v]=g.useState({left:d.tMin,right:d.tMax});g.useEffect(()=>{v({left:d.tMin,right:d.tMax})},[d.tMin,d.tMax]);const y=m.left<=d.tMin&&m.right>=d.tMax,b=g.useMemo(()=>y?t:t.filter(_=>{const C=DRr(_);return C>=m.left&&C<=m.right}),[t,y,m.left,m.right]),S=g.useMemo(()=>s!=null?LRr(b,s):null,[b,s]),w=l!=null&&b.some(_=>_.id===l)?l:null,k=S??w;return o.jsxs("div",{className:"flex h-full w-full flex-col overflow-hidden",children:[o.jsxs("div",{className:"flex shrink-0 items-center gap-2 border-b border-border1 px-3 py-2.5",children:[o.jsx(de,{type:"button",variant:"ghost",size:"icon-sm",tooltip:"Back to memory",onClick:()=>r?.(),children:o.jsx(Zq,{})}),o.jsxs("span",{className:"flex min-w-0 items-center gap-1.5 text-neutral6",children:[o.jsx(H3,{className:"h-4 w-4 shrink-0"}),o.jsx(ge,{as:"span",variant:"ui-sm",className:"font-medium",children:"Observational memory"})]})]}),n?o.jsxs("div",{"data-testid":"memory-studio-loading",className:"flex flex-1 flex-col gap-3 p-4",children:[o.jsx(bt,{className:"h-6 w-40"}),o.jsx(bt,{className:"h-32 w-full"}),o.jsx(bt,{className:"h-16 w-full"})]}):o.jsxs("div",{className:"grid min-h-0 flex-1 grid-rows-[1fr_auto] overflow-hidden",children:[o.jsx("div",{className:"min-h-0 flex flex-col overflow-hidden",children:o.jsx(I2r,{records:b,selectedRecordId:k,onSelectRecord:c,isLoading:n})}),o.jsxs("div",{className:"border-t border-border1",children:[o.jsx(A2r,{messageTokens:i?.messageTokens??f?.messageTokens,messageThreshold:i?.messageThreshold??f?.messageThreshold,memoryTokens:p,memoryThreshold:h,memoryLabel:"Observations"}),o.jsx(JRr,{omRecords:t,markers:u,messages:e,tDomain:d,onSelectTimestamp:a,zoomRange:m,onZoomRangeChange:v})]})]})]})}const fU=(e,t)=>["memory","thread",e,"messages",t??0];function P2r(e,t){const n=We(),r=0,s=100;return wt({queryKey:fU(e,r),queryFn:e?()=>n.getMemoryThread({threadId:e}).listMessages({page:r,perPage:s}):jy})}const pU=(e,t)=>["memory","observational-memory",e,t];function $2r(e,t,n){const r=We();return wt({queryKey:pU(e,t),queryFn:e&&t?()=>r.getObservationalMemory({agentId:e,threadId:t,resourceId:n}):jy})}const M2r=2e3;function D2r({agentId:e,threadId:t}){const{isPanelOpen:n,closePanel:r,selectedTimestamp:s,setSelectedTimestamp:a}=AW(),{isObservingFromStream:i,isReflectingFromStream:l,observationsUpdatedAt:c,streamProgress:u}=IW(),d=i||l,{data:f}=pRt({threadId:t,agentId:e}),p=f?.resourceId??e,{data:h}=G_(e),{data:m,isLoading:v,refetch:y}=$2r(n?e:void 0,n?t:void 0,p),{data:b,isLoading:S,refetch:w}=P2r(n?t:void 0);if(g.useEffect(()=>{!n||c===0||(y(),w())},[n,c,y,w]),g.useEffect(()=>{if(!n||!d)return;const E=setInterval(()=>{y(),w()},M2r);return()=>clearInterval(E)},[n,d,y,w]),!n)return null;const k=h?.config?.observationalMemory,_=u?.threadId===t?u:null,C=bRt({record:m?.record,liveProgress:_,agentConfig:k});return o.jsx("div",{"data-testid":"memory-sidebar-om-detail-subpanel",className:"h-full min-h-0 min-w-0 overflow-hidden bg-surface3",children:o.jsx(R2r,{messages:b?.messages??[],omRecords:m?.history??[],isLoading:v||S,onClose:r,selectedTimestamp:s,onSelectTimestamp:a,contextWindow:{messageTokens:C.messageTokens,messageThreshold:C.messageThreshold,memoryTokens:C.observationTokens,memoryThreshold:C.observationThreshold}})})}function L2r(e){if(e!==!1)return e}function F2r(e){const{data:t}=G_(e),n=t?.config;return{lastMessages:L2r(n?.lastMessages),semanticRecallOn:!!n?.semanticRecall,workingMemoryOn:!!n?.workingMemory?.enabled,observationalOn:!!n?.observationalMemory?.enabled}}const HWe="agent-memory-sidebar-tab-v2",z2r=()=>{const[e,t]=g.useState(()=>{const r=sessionStorage.getItem(HWe)||"threads";return r==="threads"||r==="memory"?r:"threads"}),n=g.useCallback(r=>{t(r),sessionStorage.setItem(HWe,r)},[]);return{selectedTab:e,handleTabChange:n}},B2r=({threads:e,threadId:t,onDelete:n,resourceId:r,resourceType:s,embedded:a=!1})=>{const{Link:i,paths:l}=yn(),[c,u]=g.useState(null),{canDelete:d}=il(),f=d("memory"),p=s==="agent"?l.agentNewThreadLink(r):l.networkNewThreadLink(r);return o.jsxs(o.Fragment,{children:[o.jsxs(Zwt,{embedded:a,children:[o.jsxs(wGn,{as:i,to:p,children:[o.jsx(Ue,{children:o.jsx(Vr,{})}),"New Chat"]}),o.jsx(SGn,{}),e.length===0?o.jsx(Ywt,{children:"Your conversations will appear here once you start chatting!"}):o.jsx(Gwt,{children:e.map(h=>{const m=h.id===t,v=s==="agent"?l.agentThreadLink(r,h.id):l.networkThreadLink(r,h.id);return o.jsx(Qwt,{as:i,to:v,isActive:m,onDelete:f?()=>u(h.id):void 0,deleteLabel:"delete thread",children:o.jsx(V2r,{title:h.title,id:h.id,createdAt:h.createdAt})},h.id)})})]}),o.jsx(U2r,{open:!!c,onOpenChange:()=>u(null),onDelete:()=>{c&&n(c)}})]})},U2r=({open:e,onOpenChange:t,onDelete:n})=>o.jsx(Tt,{open:e,onOpenChange:t,children:o.jsxs(Tt.Content,{children:[o.jsxs(Tt.Header,{children:[o.jsx(Tt.Title,{children:"Are you absolutely sure?"}),o.jsx(Tt.Description,{children:"This action cannot be undone. This will permanently delete your chat and remove it from our servers."})]}),o.jsxs(Tt.Footer,{children:[o.jsx(Tt.Cancel,{children:"Cancel"}),o.jsx(Tt.Action,{onClick:n,children:"Continue"})]})]})});function q2r(e){return/^New Thread \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?Z$/.test(e)}function V2r({title:e,id:t,createdAt:n}){const r=e&&!q2r(e)?e:n?H2r(n):`Thread ${t?t.substring(t.length-5):""}`;return o.jsx("span",{className:"block truncate",children:r})}const H2r=e=>{const t={month:"short",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",hour12:!0};return new Date(e).toLocaleString("en-us",t).replace(","," at")};function M_e({children:e,className:t}){return o.jsx("div",{className:K("bg-surface3 rounded-tr-studio-panel border-t border-r border-border1/50 flex h-full w-full min-h-0 min-w-0 flex-col overflow-hidden",t),children:e})}const W2r=e=>e>=85?"bg-orange-400":e>=60?"bg-blue-500":"bg-green-500";function C9({icon:e,label:t,tooltip:n,enabled:r,value:s,expanded:a}){return o.jsxs(Wn,{children:[o.jsx(zn,{asChild:!0,children:o.jsxs("span",{className:K("inline-flex items-center gap-1 rounded-full border px-1.5 py-0.5 transition-colors duration-normal",r?"border-border1 bg-surface4 text-neutral6":"border-border1/40 text-neutral3/50"),children:[o.jsx(e,{className:"h-3 w-3 shrink-0"}),s!==void 0&&o.jsx(ge,{as:"span",variant:"ui-xs",className:"font-medium tabular-nums leading-none",children:s}),a&&o.jsx(ge,{as:"span",variant:"ui-xs",className:"whitespace-nowrap leading-none",children:t})]})}),o.jsx(Bn,{children:n})]})}function Z2r(){return o.jsxs("div",{"data-testid":"memory-sidebar-skeleton",className:"flex h-full min-h-0 w-full flex-col gap-2.5 p-3",children:[o.jsx(bt,{className:"h-3 w-28"}),o.jsx(bt,{className:"h-3 w-20"}),o.jsx(bt,{className:"h-3 w-24"}),o.jsx(bt,{className:"h-3 w-16"})]})}function G2r({agentId:e,threadId:t,threads:n,onDelete:r}){return o.jsx(M_e,{children:o.jsx(Q2r,{agentId:e,threadId:t,threads:n,onDelete:r})})}function Q2r({agentId:e,threadId:t,threads:n,onDelete:r}){const{data:s,isLoading:a}=Z_(e),i=!!s?.result,l=s?.memoryType,{selectedTab:c,handleTabChange:u}=z2r(),{isPanelOpen:d}=AW(),{streamProgress:f}=IW(),{lastMessages:p,semanticRecallOn:h,workingMemoryOn:m,observationalOn:v}=F2r(e),y=c==="memory",b=g.useRef(null),S=g.useRef(null),[w,k]=g.useState({height:0,offset:0}),_=v&&d,C=f?.threadId===t?f.windows?.active?.messages:void 0,E=C&&C.threshold>0?Math.min(100,Math.round(C.tokens/C.threshold*100)):void 0;return g.useLayoutEffect(()=>{if(y||_||!i)return;const j=b.current,N=S.current;if(!j||!N)return;const I=()=>{const P=getComputedStyle(j),L=Number.parseFloat(P.borderTopWidth)||0,M=Number.parseFloat(P.borderBottomWidth)||0,q=Number.parseFloat(P.marginTop)||0,H=Number.parseFloat(P.marginBottom)||0,F=Math.ceil(N.getBoundingClientRect().height+L+M),z=Math.ceil(F+q+H);k(B=>B.height===F&&B.offset===z?B:{height:F,offset:z})};if(I(),typeof ResizeObserver>"u")return;const R=new ResizeObserver(I);return R.observe(N),()=>R.disconnect()},[i,p,E,v,h,y,_,m]),a?o.jsx(Z2r,{}):_?o.jsx("div",{"data-testid":"memory-sidebar-panel",className:"h-full min-h-0 min-w-0",children:o.jsx(D2r,{agentId:e,threadId:t})}):o.jsxs("div",{className:"flex h-full min-h-0 w-full flex-col overflow-hidden",children:[o.jsxs("div",{className:"relative min-h-0 flex-1 overflow-hidden",children:[o.jsx("div",{"aria-hidden":y&&i,inert:y&&i?!0:void 0,"data-testid":"memory-sidebar-thread-layer",className:K("memory-sidebar-thread-layer absolute inset-0 flex min-h-0 flex-col overflow-hidden",y&&i?"pointer-events-none opacity-0":"opacity-100"),children:o.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",style:{paddingBottom:i&&w.offset||void 0},children:i?o.jsx(B2r,{resourceId:e,resourceType:"agent",threads:n,threadId:t,onDelete:r,embedded:!0}):o.jsx(Cr,{iconSlot:null,titleSlot:"Memory not enabled",descriptionSlot:"Conversations are only saved as threads when the agent has memory configured.",actionSlot:o.jsx(de,{as:"a",href:"https://mastra.ai/docs/memory/overview",target:"_blank",rel:"noopener noreferrer",variant:"outline",children:"View documentation"})})})}),i?o.jsxs("div",{ref:b,"data-testid":"memory-sidebar-overlay",className:K("memory-sidebar-overlay absolute inset-x-0 bottom-0 z-10 box-border flex min-h-0 flex-col overflow-hidden border",y?"m-0 rounded-none border-transparent bg-surface3 shadow-none":"m-1 rounded-xl border-border1/40 bg-surface4 hover:bg-surface5 active:bg-surface4"),style:{height:y?"100%":w.height||void 0},children:[o.jsxs("button",{ref:S,type:"button",onClick:()=>u(y?"threads":"memory"),"aria-pressed":y,"data-testid":"memory-sidebar-card",className:"group/memory-card w-full shrink-0 cursor-pointer bg-transparent px-3 py-2.5 text-left",children:[o.jsxs("span",{className:"flex items-center justify-between gap-2",children:[o.jsxs("span",{className:"flex min-w-0 items-center gap-1.5 text-neutral6",children:[o.jsx(H3,{className:"h-4 w-4 shrink-0"}),o.jsx(ge,{as:"span",variant:"ui-sm",className:"font-medium",children:"Memory"})]}),y?o.jsx(Sa,{className:"h-4 w-4 shrink-0 text-neutral3"}):o.jsx(f_,{className:"h-4 w-4 shrink-0 text-neutral3"})]}),o.jsx(sc,{delay:150,timeout:400,children:o.jsxs("span",{className:"mt-1.5 flex flex-wrap items-center gap-1.5",children:[o.jsx(C9,{icon:Yj,label:"recent messages",tooltip:p!==void 0?`Keeps the last ${p} messages in context`:"Recent message history is off",enabled:p!==void 0,value:p,expanded:y}),o.jsx(C9,{icon:Xa,label:"Semantic recall",tooltip:h?"Semantic recall is on - retrieves relevant past messages":"Semantic recall is off",enabled:h,expanded:y}),o.jsx(C9,{icon:Tdn,label:"Working memory",tooltip:m?"Working memory is on - persists notes across the conversation":"Working memory is off",enabled:m,expanded:y}),o.jsx(C9,{icon:Kc,label:"Observational",tooltip:v?"Observational memory is on - learns from the conversation":"Observational memory is off",enabled:v,expanded:y})]})}),E!==void 0?o.jsx("span",{className:"mt-2 block h-1 w-full overflow-hidden rounded-full bg-surface5",children:o.jsx("span",{className:K("block h-full rounded-full transition-all duration-normal",W2r(E)),style:{width:`${E}%`}})}):null]}),y&&o.jsx("div",{className:"memory-card-content min-h-0 flex-1 overflow-y-auto border-t border-border1",children:o.jsx(TRr,{agentId:e,threadId:t,memoryType:l})})]}):null]}),o.jsx(cRr,{agentId:e})]})}function Y2r({agentId:e,threadId:t,threads:n}){const{mutateAsync:r}=rRr(),{paths:s,navigate:a}=yn(),i=async l=>{await r({threadId:l,agentId:e}),l===t&&a(s.agentNewThreadLink(e))};return o.jsx(G2r,{agentId:e,threadId:t,threads:n,onDelete:i})}const tve=(e,t)=>["memory","status",e,t],JRt=g.createContext({messages:[]}),e2t=g.createContext({isRunning:!1,cancelRun:()=>{},canSendWhileStreaming:!1}),t2t=g.createContext({send:()=>{}}),n2t=g.createContext({tasks:[]}),X2r=()=>g.useContext(JRt).messages,r2t=()=>g.useContext(e2t),s2t=()=>g.useContext(t2t).send,K2r=()=>g.useContext(n2t).tasks,a2t="mastra-memory-om-observation",WWe={"data-om-observation-start":"start","data-om-observation-end":"end","data-om-observation-failed":"failed","data-om-buffering-start":"bufferingStart","data-om-buffering-end":"bufferingEnd","data-om-buffering-failed":"bufferingFailed","data-om-activation":"activation"},i2t=(e,t)=>{for(const n of e){if(!(n.type in WWe))continue;const r=n,s=r.data?.cycleId;if(!s)continue;const a=WWe[r.type],i=t.get(s)||{};i[a]=r,t.set(s,i)}return t},D_e=e=>!!e&&typeof e=="object"&&!Array.isArray(e)&&Object.keys(e).length>0,L_e=e=>Array.isArray(e)&&e.length>0,Mk=e=>({...D_e(e?.extractedValues)?{extractedValues:e.extractedValues}:{},...L_e(e?.extractionFailures)?{extractionFailures:e.extractionFailures}:{}}),rj=e=>Object.keys(Mk(e)).length>0,E9=(e,t)=>{if(!e?.data||!t)return e;const n=Mk(e.data),r=Mk(t);if(!Object.keys(r).length)return e;const s={...n.extractedValues??r.extractedValues?{extractedValues:n.extractedValues??r.extractedValues}:{},...n.extractionFailures??r.extractionFailures?{extractionFailures:n.extractionFailures??r.extractionFailures}:{}};return{...e,data:{...e.data,...s}}},J2r=(e,t)=>{for(const[n,r]of e){const s=t.get(n);s&&(r.end=E9(r.end,s.end),r.failed=E9(r.failed,s.failed),r.bufferingEnd=E9(r.bufferingEnd,s.bufferingEnd),r.bufferingFailed=E9(r.bufferingFailed,s.bufferingFailed));const a={...s??{}};rj(r.end?.data)&&(a.end=Mk(r.end?.data)),rj(r.failed?.data)&&(a.failed=Mk(r.failed?.data)),rj(r.bufferingEnd?.data)&&(a.bufferingEnd=Mk(r.bufferingEnd?.data)),rj(r.bufferingFailed?.data)&&(a.bufferingFailed=Mk(r.bufferingFailed?.data)),Object.keys(a).length>0&&t.set(n,a)}return e},ePr=(e,t)=>{const n=new Map;for(const r of e){const s=r?.content?.parts;Array.isArray(s)&&i2t(s,n)}return t?J2r(n,t):n},tPr=(e,t)=>{const n=t.start?.data;if(!n)return;const r=t.end?.data,s=t.failed?.data,a=!!t.failed,i=!!t.end,l=!!n.disconnectedAt||i&&!!r?.disconnectedAt,c=a?"failed":l?"disconnected":i?"observed":"observing",u={...n,...i?r:{},...a?s:{},_state:a?"failed":l?"disconnected":i?"complete":"loading"};return{cycleId:e,recordId:typeof u.recordId=="string"?u.recordId:void 0,status:c,operationType:u.operationType,observations:u.observations,extractedValues:D_e(u.extractedValues)?u.extractedValues:void 0,extractionFailures:L_e(u.extractionFailures)?u.extractionFailures:void 0,omData:u,isLoading:c==="observing"}},nPr=(e,t)=>{const n=t.bufferingStart?.data;if(!n)return;const r=t.bufferingEnd?.data,s=t.bufferingFailed?.data,a=t.activation?.data,i=!!t.bufferingFailed,l=!!t.activation,c=!!t.bufferingEnd,u=!!n.disconnectedAt,d=i?"buffering-failed":u?"disconnected":c?"buffering-complete":l?"activated":"buffering",f={...n,...c?r:{},...i?s:{},...l?a:{},_state:d};return!f.tokensObserved&&f.tokensActivated&&(f.tokensObserved=f.tokensActivated),{cycleId:e,recordId:typeof f.recordId=="string"?f.recordId:void 0,status:d,operationType:f.operationType,observations:f.observations,extractedValues:D_e(f.extractedValues)?f.extractedValues:void 0,extractionFailures:L_e(f.extractionFailures)?f.extractionFailures:void 0,omData:f,isLoading:d==="buffering"}},j9=(e,t,n)=>n==="observation"?tPr(e,t):nPr(e,t),T9=(e,t,n)=>({type:"dynamic-tool",toolCallId:`om-${t}-${e}`,toolName:a2t,input:n.omData,output:n.isLoading?void 0:{status:t==="observation"?n.status==="failed"?"failed":n.status==="disconnected"?"disconnected":"complete":n.status,omData:n.omData},state:n.isLoading?"input-available":"output-available"}),ZWe=(e,t)=>t==="observation"?!!e?.end||!!e?.failed:!!e?.bufferingEnd||!!e?.bufferingFailed,GWe=(e,t)=>t==="observation"?e==="data-om-observation-end"||e==="data-om-observation-failed":e==="data-om-buffering-end"||e==="data-om-buffering-failed"||e==="data-om-activation",rPr=(e,t)=>{if(!e||!Array.isArray(e.content?.parts))return e;const n=i2t(e.content.parts,new Map),r=[];for(const s of e.content.parts){const a=s.data?.cycleId,i=s.type;if(i==="data-om-observation-start"&&a){const l=n.get(a),c=t.get(a);if(!l)continue;const u=ZWe(c,"observation")?c??l:{start:l.start},d=j9(a,u,"observation");if(!d)continue;r.push(T9(a,"observation",d))}else if(i==="data-om-buffering-start"&&a){const l=n.get(a),c=t.get(a);if(!l)continue;const u=ZWe(c,"buffering")?c??l:{bufferingStart:l.bufferingStart},d=j9(a,u,"buffering");if(!d)continue;r.push(T9(a,"buffering",d))}else if(a&&GWe(i,"observation")){const l=n.get(a),c=t.get(a);if(l?.start||c?.start||!c)continue;const u=j9(a,c,"observation");if(!u)continue;r.push(T9(a,"observation",u))}else if(a&&GWe(i,"buffering")){const l=n.get(a),c=t.get(a);if(l?.bufferingStart||c?.bufferingStart||i==="data-om-activation"&&(l?.bufferingEnd||l?.bufferingFailed)||!c)continue;const u=j9(a,c,"buffering");if(!u)continue;r.push(T9(a,"buffering",u))}else{if(i?.startsWith("data-om-"))continue;r.push(s)}}return{...e,content:{...e.content,parts:r}}},o2t=(e,t)=>e.map(n=>{if(n.role!=="assistant")return n;const r=n.content?.parts;if(!Array.isArray(r))return n;const{parts:s,changed:a}=t(r);return a?{...n,content:{...n.content,parts:s}}:n}),F_e=e=>{const t=new Set,n=new Set,r=new Set;for(const s of e){const a=s.content?.parts;if(Array.isArray(a))for(const i of a){const l=i?.data?.cycleId;l&&((i.type==="data-om-observation-end"||i.type==="data-om-observation-failed")&&t.add(l),(i.type==="data-om-buffering-end"||i.type==="data-om-buffering-failed")&&n.add(l),i.type==="data-om-activation"&&r.add(l))}}return{observation:t,buffering:n,activatedBuffering:r}},QWe=e=>{const t=F_e(e),n=new Set([...t.buffering,...t.activatedBuffering]);return o2t(e,r=>{let s=!1;return{parts:r.map(i=>{if(i.type==="data-om-observation-start"){const l=i.data?.cycleId;return!l||i.data?.disconnectedAt||t.observation.has(l)?i:(s=!0,{...i,data:{...i.data,disconnectedAt:new Date().toISOString(),_state:"disconnected"}})}if(i.type==="data-om-buffering-start"){const l=i.data?.cycleId;return!l||i.data?.disconnectedAt||n.has(l)?i:(s=!0,{...i,data:{...i.data,disconnectedAt:new Date().toISOString(),_state:"disconnected"}})}if(i.type==="tool-call"&&i.toolName===a2t){const l=i.metadata?.omData||i.args;if(!l?.completedAt&&!l?.failedAt&&!l?.disconnectedAt)return s=!0,{...i,metadata:{...i.metadata,omData:{...l,disconnectedAt:new Date().toISOString(),_state:"disconnected"}}}}return i}),changed:s}})},sPr=e=>{const{buffering:t,activatedBuffering:n}=F_e(e),r=new Set([...t,...n]);for(const s of e){const a=s.content?.parts;if(Array.isArray(a))for(const i of a){const l=i?.data?.cycleId;if(i.type==="data-om-buffering-start"&&l&&!i.data?.disconnectedAt&&!r.has(l)||i.type==="data-om-buffering-end"&&l&&i.data?.operationType==="observation"&&!rj(i.data))return!0}}return!1},l2t=(e,t)=>{const n=new Map,r=F_e(e).buffering;if(t?.bufferedObservationChunks)for(const s of t.bufferedObservationChunks)s.cycleId&&n.set(s.cycleId,s);return o2t(e,s=>{const a=[];let i=!1;for(const l of s){if(l.type==="data-om-buffering-end"&&l.data?.cycleId&&l.data?.operationType==="observation"){const c=n.get(l.data.cycleId);if(c&&!rj(l.data)){a.push({...l,data:{...l.data,observations:l.data.observations??c.observations,extractedValues:c.extractedValues,extractionFailures:c.extractionFailures}}),i=!0;continue}}if(a.push(l),l.type==="data-om-buffering-start"&&l.data?.cycleId&&!l.data?.disconnectedAt&&!r.has(l.data.cycleId)){const c=l.data.cycleId,u=l.data.operationType,d={cycleId:c,operationType:u,completedAt:new Date().toISOString()};if(u==="observation"){const f=n.get(c);f&&(d.tokensBuffered=f.messageTokens,d.bufferedTokens=f.tokenCount,d.observations=f.observations,d.extractedValues=f.extractedValues,d.extractionFailures=f.extractionFailures)}else u==="reflection"&&t&&(d.tokensBuffered=t.bufferedReflectionInputTokens,d.bufferedTokens=t.bufferedReflectionTokens,d.observations=t.bufferedReflection);a.push({type:"data-om-buffering-end",data:d}),r.add(c),i=!0}}return{parts:a,changed:i}})},aPr=e=>{const t=[];let n=null;for(const r of e){const s=r?.content?.parts;if(Array.isArray(s))for(const a of s)a?.type==="data-om-activation"&&a?.data?.cycleId&&t.push(a.data.cycleId),a?.type==="data-om-status"&&a?.data&&(n=a.data)}return{activatedCycleIds:t,lastProgress:n}},iPr="tool-calls",oPr=e=>`Agent stopped because it reached maxSteps${typeof e=="number"?` (${e})`:""} while tool calls were still pending. Increase maxSteps in advanced settings and try again.`,lPr=e=>{if(e.type!=="finish")return;const t=e.payload?.stepResult?.reason;return typeof t=="string"?t:void 0},cPr=e=>lPr(e)===iPr,nve=e=>{const t=e.payload?.error;let n;if(typeof t=="string")n=t;else if(t instanceof Error)n=t.message;else if(t&&typeof t=="object"&&typeof t.message=="string")n=t.message;else if(t==null)n="Unknown error";else try{n=JSON.stringify(t)??String(t)}catch{try{n=String(t)}catch{n="Unknown error"}}return{id:`error-${e.runId??"unknown"}-${Date.now()}`,role:"assistant",createdAt:new Date,content:{format:2,parts:[{type:"text",text:n}],metadata:{status:"error"}}}},uPr=(e,t)=>nve({runId:e.runId,payload:{error:oPr(t)}}),YWe=e=>{const t=e.type;if(t==="error"||t==="data-om-observation-start"||t==="data-om-observation-end"||t==="data-om-observation-failed"||t==="data-om-status"||t==="data-om-activation")return e},dPr=e=>{const t=new u_;return Object.entries(e.requestContext??{}).forEach(([n,r])=>{t.set(n,r)}),e.agentVersionId&&t.set("agentVersionId",e.agentVersionId),t},XWe=e=>(e.type==="tool-result"||e.type==="tool-execution-end")&&e.payload?.toolName==="updateWorkingMemory"&&typeof e.payload.result=="object"&&"success"in e.payload.result&&e.payload.result?.success,fPr=({agentId:e,requestContext:t,agentVersionId:n,threadId:r,modelSettingsArgs:s,chatWithNetwork:a,chatWithGenerate:i,maxSteps:l,isOMEnabled:c,tracingOptions:u,threadSignalsUnsupportedRef:d,isRunningStream:f,sendMessage:p,cancelRun:h,setMessages:m,setStreamErrors:v,refreshThreadList:y,refreshWorkingMemory:b,handleObservationStart:S,handleProgressUpdate:w,refreshObservationalMemory:k,handleActivation:_,resetObservationalMemoryStreamState:C,signalTimelineRefresh:E})=>{const j=We(),N=Hr(),I=g.useRef(null),R=g.useRef({requestContext:t,agentVersionId:n,threadId:r,modelSettingsArgs:s,chatWithNetwork:a,chatWithGenerate:i,maxSteps:l,isOMEnabled:c,tracingOptions:u});R.current={requestContext:t,agentVersionId:n,threadId:r,modelSettingsArgs:s,chatWithNetwork:a,chatWithGenerate:i,maxSteps:l,isOMEnabled:c,tracingOptions:u};const P=g.useCallback(F=>{F&&(N.refetchQueries({queryKey:pU(e,F)}),N.refetchQueries({queryKey:fU(F)}),N.refetchQueries({queryKey:tve(e,F)}),E())},[e,N,E]),L=g.useCallback(F=>{!F||!R.current.isOMEnabled||j.awaitBufferStatus({agentId:e,resourceId:e,threadId:F}).then(z=>{m(B=>l2t(B,z?.record)),N.invalidateQueries({queryKey:["observational-memory",e]}),N.invalidateQueries({queryKey:["memory-status",e]}),P(F)}).catch(()=>{})},[e,j,N,P,m]),M=g.useCallback(F=>{F?.type==="error"&&v(z=>[...z,nve(F)]),F?.type==="data-om-observation-start"&&S(F.data?.operationType),F?.type==="data-om-status"&&w(F.data),(F?.type==="data-om-observation-end"||F?.type==="data-om-observation-failed"||F?.type==="data-om-activation")&&k(F.data?.operationType),F?.type==="data-om-activation"&&_(F.data)},[_,S,w,k,v]),q=g.useCallback(async({message:F,attachments:z=[]})=>{const B=R.current;if(d.current&&(f||I.current))return;v([]);const D=new AbortController;I.current=D;const Q=dPr(B);try{if(B.chatWithNetwork)await p({message:F,mode:"network",coreUserMessages:z,requestContext:Q,threadId:B.threadId,modelSettings:B.modelSettingsArgs,signal:D.signal,tracingOptions:B.tracingOptions,onNetworkChunk:async V=>{XWe(V)&&b?.(),V.type==="network-execution-event-step-finish"&&y?.(),M(YWe(V))}});else if(B.chatWithGenerate){await p({message:F,mode:"generate",coreUserMessages:z,requestContext:Q,threadId:B.threadId,modelSettings:B.modelSettingsArgs,signal:D.signal,tracingOptions:B.tracingOptions}),await y?.(),P(B.threadId);return}else{await p({message:F,mode:"stream",coreUserMessages:z,requestContext:Q,threadId:B.threadId,modelSettings:B.modelSettingsArgs,tracingOptions:B.tracingOptions,onChunk:async V=>{V.type==="finish"&&(cPr(V)&&v($=>[...$,uPr(V,B.maxSteps)]),await y?.()),XWe(V)&&b?.(),M(YWe(V))},signal:D.signal}),P(B.threadId),L(B.threadId);return}setTimeout(()=>{y?.()},500),P(B.threadId),L(B.threadId)}catch(V){if(console.error("Error occurred in ChatProvider",V),V.name==="AbortError")return;v($=>[...$,nve({runId:"thrown",payload:{error:V}})]),C()}finally{I.current=null}},[L,M,f,y,P,b,C,p,v,d]),H=g.useCallback(async()=>{I.current?.abort(),I.current=null,C(),h?.(),L(R.current.threadId)},[h,L,C]);return{send:q,cancel:H}};function pPr({isSupportedModel:e,threadSignalsEnabled:t,threadId:n,threadSignalsUnsupported:r}){return e&&t&&!!n&&!r}const c2t=g.createContext(void 0);function hPr({children:e,approveToolcall:t,declineToolcall:n,approveToolcallGenerate:r,declineToolcallGenerate:s,approveNetworkToolcall:a,declineNetworkToolcall:i,isRunning:l,toolCallApprovals:c,networkToolCallApprovals:u}){return o.jsx(c2t.Provider,{value:{approveToolcall:t,declineToolcall:n,approveToolcallGenerate:r,declineToolcallGenerate:s,approveNetworkToolcall:a,declineNetworkToolcall:i,isRunning:l,toolCallApprovals:c,networkToolCallApprovals:u},children:e})}function u2t(){const e=g.useContext(c2t);if(!e)throw new Error("useToolCall must be used within a ToolCallProvider");return e}function mPr({children:e,agentId:t,initialMessages:n,threadId:r,refreshThreadList:s,settings:a,requestContext:i,modelVersion:l,agentVersionId:c,supportsMemory:u}){const{settings:d}=tV(),[f,p]=g.useState([]),[h,m]=g.useState(!1),v=g.useRef(!1),y=a?.modelSettings??{},b=window.MASTRA_AGENT_SIGNALS!=="false"&&u!==!1&&!y.chatWithLegacyStream;g.useEffect(()=>{p([]),v.current=!1,m(!1)},[t,r]);const S=g.useMemo(()=>{if(!c&&!i)return;const ot=new u_;return Object.entries(i??{}).forEach(([zt,mt])=>{ot.set(zt,mt)}),c&&ot.set("agentVersionId",c),ot},[c,i]),{messages:w,tasks:k,sendMessage:_,cancelRun:C,isRunning:E,isAwaitingToolApproval:j,setMessages:N,approveToolCall:I,declineToolCall:R,approveToolCallGenerate:P,declineToolCallGenerate:L,toolCallApprovals:M,approveNetworkToolCall:q,declineNetworkToolCall:H,networkToolCallApprovals:F}=Pbe({agentId:t,threadId:r,initialMessages:n,requestContext:S,enableThreadSignals:b,onThreadSignalsUnsupported:()=>{v.current=!0,m(!0)}}),{refetch:z}=kRt(),B=Hr(),D=We(),{data:Q}=G_(t),V=Q?.config?.observationalMemory,$=V===!0||typeof V=="object"&&V!==null&&(!("enabled"in V)||V.enabled!==!1),{setIsObservingFromStream:U,setIsReflectingFromStream:Z,signalObservationsUpdated:X,setStreamProgress:te,markCycleIdActivated:J}=IW(),ee=g.useCallback(ot=>{ot==="reflection"?Z(!0):U(!0)},[U,Z]),ae=g.useCallback(ot=>{ot.threadId&&ot.threadId!==r||te({windows:ot.windows,recordId:ot.recordId,threadId:ot.threadId,stepNumber:ot.stepNumber,generationCount:ot.generationCount})},[te,r]),ce=g.useCallback(ot=>{ot==="reflection"?Z(!1):U(!1),X(),B.invalidateQueries({queryKey:["observational-memory",t]}),B.invalidateQueries({queryKey:["memory-status",t]}),B.refetchQueries({queryKey:pU(t,r)}),B.refetchQueries({queryKey:fU(r)}),B.refetchQueries({queryKey:tve(t,r)})},[t,B,U,Z,X,r]),Y=g.useCallback(ot=>{const zt=ot?.cycleId;zt&&J(zt)},[J]),ne=g.useCallback(()=>{U(!1),Z(!1),N(ot=>QWe(ot)),B.invalidateQueries({queryKey:["observational-memory",t]}),B.invalidateQueries({queryKey:["memory-status",t]}),B.refetchQueries({queryKey:pU(t,r)}),B.refetchQueries({queryKey:fU(r)}),B.refetchQueries({queryKey:tve(t,r)})},[t,B,U,Z,N,r]);g.useEffect(()=>{const{activatedCycleIds:ot,lastProgress:zt}=aPr(n||[]);for(const mt of ot)J(mt);zt&&ae(zt)},[ae,n,J]),g.useEffect(()=>{if(!r||!sPr(n||[]))return;let ot=!1;return D.awaitBufferStatus({agentId:t,resourceId:t,threadId:r}).then(zt=>{ot||N(mt=>l2t(mt,zt?.record))}).catch(()=>{ot||N(zt=>QWe(zt))}),()=>{ot=!0}},[t,D,n,N,r]);const{frequencyPenalty:ue,presencePenalty:pe,maxRetries:le,maxSteps:ve,maxTokens:ye,temperature:Se,topK:Ne,topP:ke,seed:Ie,chatWithGenerate:ze,chatWithNetwork:oe,chatWithLegacyStream:se,providerOptions:re,requireToolApproval:he}=y,xe={frequencyPenalty:ue,presencePenalty:pe,maxRetries:le,temperature:Se,topK:Ne,topP:ke,seed:Ie,maxTokens:ye,providerOptions:re,maxSteps:ve,requireToolApproval:he},{send:je,cancel:Pe}=fPr({agentId:t,requestContext:i,agentVersionId:c,threadId:r,modelSettingsArgs:xe,chatWithNetwork:oe,chatWithGenerate:ze,maxSteps:ve,isOMEnabled:$,tracingOptions:d?.tracingOptions,threadSignalsUnsupportedRef:v,isRunningStream:E,sendMessage:_,cancelRun:C,setMessages:N,setStreamErrors:p,refreshThreadList:s,refreshWorkingMemory:z,handleObservationStart:ee,handleProgressUpdate:ae,refreshObservationalMemory:ce,handleActivation:Y,resetObservationalMemoryStreamState:ne,signalTimelineRefresh:X}),Ge=l==="v2"||l==="v3",Ze=g.useRef(new Map),Ee=g.useMemo(()=>ePr(w,Ze.current),[w]),_e=g.useMemo(()=>[...w.filter(ot=>ot.content?.metadata?.status!=="error"),...f].map(ot=>rPr(ot,Ee)),[w,f,Ee]),Ce=E||j,Re=pPr({isSupportedModel:Ge,threadSignalsEnabled:b&&(!ze&&!oe&&!se),threadId:r,threadSignalsUnsupported:h}),qe=g.useMemo(()=>({messages:_e}),[_e]),Ye=g.useMemo(()=>({isRunning:Ce,cancelRun:Pe,canSendWhileStreaming:Re}),[Ce,Pe,Re]),tt=g.useMemo(()=>({send:je}),[je]),At=g.useMemo(()=>({tasks:k}),[k]);return o.jsx(e2t.Provider,{value:Ye,children:o.jsx(JRt.Provider,{value:qe,children:o.jsx(n2t.Provider,{value:At,children:o.jsx(t2t.Provider,{value:tt,children:o.jsx(hPr,{approveToolcall:I,declineToolcall:R,approveToolcallGenerate:P,declineToolcallGenerate:L,approveNetworkToolcall:q,declineNetworkToolcall:H,isRunning:E,toolCallApprovals:M,networkToolCallApprovals:F,children:e})})})})})}const gPr=(e,t)=>{const n=new Blob([JSON.stringify(t,null,2)],{type:"application/json"}),r=URL.createObjectURL(n),s=document.createElement("a");s.href=r,s.download=e,document.body.appendChild(s),s.click(),s.remove(),URL.revokeObjectURL(r)},KWe={jpg:"image/jpg",jpeg:"image/jpeg",png:"image/png",gif:"image/gif",webp:"image/webp",svg:"image/svg+xml",bmp:"image/bmp",ico:"image/x-icon",pdf:"application/pdf",mp4:"video/mp4",mov:"video/quicktime",webm:"video/webm",mkv:"video/x-matroska",avi:"video/x-msvideo",mpeg:"video/mpeg",mpg:"video/mpeg",mp3:"audio/mpeg",wav:"audio/wav",ogg:"audio/ogg",oga:"audio/ogg",m4a:"audio/mp4",aac:"audio/aac",flac:"audio/flac"},d2t=["https://","http://"],z_e=["gs://","s3://"],vPr=[...d2t,...z_e],yPr=e=>vPr.some(t=>e.startsWith(t)),f2t=e=>d2t.some(t=>e.startsWith(t)),bPr=e=>z_e.some(t=>e.startsWith(t)),JWe=e=>{try{const{pathname:t}=new URL(e),n=t.split(".").pop();return n?KWe[n.toLowerCase()]:void 0}catch{const t=e.split(".").pop()?.split(/[?#]/)[0];return t?KWe[t.toLowerCase()]:void 0}},xPr=async e=>{if(z_e.some(t=>e.startsWith(t)))return JWe(e);try{const t=await fetch(e,{method:"HEAD"});if(!t.ok)throw new Error("Failed to get file content type");const n=t.headers.get("content-type");if(!n)throw new Error("Failed to get file content type");return n}catch{return JWe(e)}},x8=async e=>new Promise((t,n)=>{const r=new FileReader;r.onload=()=>{const s=r.result;typeof s=="string"?t(s):n(new Error("Failed to convert file to base64."))},r.onerror=s=>{n(s)},r.readAsDataURL(e)}),p2t=g.createContext(null),wPr=e=>e.startsWith("image/")?"image":e==="application/pdf"?"pdf":e.startsWith("video/")||e.startsWith("audio/")?"video":"text";let SPr=0;const kPr=()=>`att-${Date.now()}-${++SPr}`,OPr=e=>new Promise((t,n)=>{const r=new FileReader;r.onload=()=>t(typeof r.result=="string"?r.result:""),r.onerror=()=>n(r.error),r.readAsText(e)}),eZe=e=>{const t=yPr(e.name),n=e.type||"text/plain";return{id:kPr(),file:e,name:e.name,contentType:n,kind:wPr(n),isUrl:t}},_Pr=async e=>e.kind==="image"?{role:"user",content:[{type:"image",image:e.isUrl?e.name:await x8(e.file),mimeType:e.contentType}]}:e.kind==="pdf"?{role:"user",content:[{type:"file",data:e.isUrl?e.name:await x8(e.file),mimeType:e.contentType,filename:e.name}]}:e.kind==="video"?{role:"user",content:[{type:"file",data:e.isUrl?e.name:await x8(e.file),mimeType:e.contentType,filename:e.name}]}:{role:"user",content:await OPr(e.file)},CPr=({children:e})=>{const[t,n]=g.useState([]),r=g.useCallback(u=>{const d=Array.from(u);d.length!==0&&n(f=>[...f,...d.map(eZe)])},[]),s=g.useCallback(async u=>{const d=await xPr(u)??"application/octet-stream",f=new File([],u,{type:d});n(p=>[...p,eZe(f)])},[]),a=g.useCallback(u=>{n(d=>d.filter(f=>f.id!==u))},[]),i=g.useCallback(()=>n([]),[]),l=g.useCallback(async()=>Promise.all(t.map(_Pr)),[t]),c=g.useMemo(()=>({attachments:t,addFiles:r,addUrl:s,remove:a,clear:i,toCoreUserMessages:l}),[t,r,s,a,i,l]);return o.jsx(p2t.Provider,{value:c,children:e})},RW=()=>{const e=g.useContext(p2t);if(!e)throw new Error("useComposerAttachments must be used within a ComposerAttachmentsProvider");return e},EPr=()=>{const[e,t]=g.useState(!1),{addFiles:n,addUrl:r}=RW(),s=()=>{const i=document.createElement("input");i.type="file",i.multiple=!0,i.hidden=!0;const l=()=>{window.removeEventListener("focus",c),i.remove()},c=()=>setTimeout(l,0);i.onchange=u=>{const d=u.target.files;d&&d.length>0&&(n(d),t(!1)),l()},document.body.appendChild(i),window.addEventListener("focus",c),i.click()},a=async i=>{i.preventDefault(),i.stopPropagation();const c=new FormData(i.target).get("url-attachment")?.toString().trim();if(c)try{await r(c),t(!1)}catch{}};return o.jsxs(Nd,{open:e,onOpenChange:t,children:[o.jsx(iu,{asChild:!0,children:o.jsx(de,{variant:"default",size:"icon-md",type:"button",tooltip:"Add attachment",children:o.jsx(Vr,{className:"h-5 w-5 text-neutral3 hover:text-neutral6"})})}),o.jsxs(ou,{align:"start",className:"w-80 p-4",children:[o.jsxs("form",{onSubmit:a,className:"flex flex-row items-end gap-2",children:[o.jsxs("div",{className:"w-full space-y-1",children:[o.jsx(Rt,{htmlFor:"url-attachment",className:"text-neutral3 text-ui-md",children:"Public URL"}),o.jsx(kn,{type:"text",name:"url-attachment",id:"url-attachment",className:"w-full",placeholder:"https://placehold.co/600x400/png"})]}),o.jsxs(de,{type:"submit",className:"h-8!",variant:"default",children:[o.jsx(Ue,{children:o.jsx(qlt,{})}),"Add"]})]}),o.jsx("hr",{className:"my-3 border-border1"}),o.jsxs("div",{className:"space-y-2",children:[o.jsx(ge,{variant:"ui-md",className:"text-neutral3",children:"Or from your computer"}),o.jsxs("button",{type:"button",onClick:s,className:"w-full h-28 border border-border1 rounded-lg text-neutral3 border-dashed flex flex-col items-center justify-center gap-2 hover:bg-surface2 active:bg-surface3",children:[o.jsx(Mlt,{className:"size-8"}),o.jsx(ge,{variant:"ui-lg",children:"Add a local file"})]})]})]})]})},jPr=e=>{const[t,n]=g.useState({isLoading:!1,text:""});return g.useEffect(()=>{if(!e)return;(async()=>{n(a=>({...a,isLoading:!0}));const s=await e.text();n(a=>({...a,isLoading:!1,text:s}))})()},[e]),t},XT="h-full w-full flex items-center justify-center",h2t=({data:e,url:t})=>{const[n,r]=g.useState(!1);return t?o.jsx("a",{href:t,className:XT,target:"_blank",rel:"noreferrer noopener",children:o.jsx(Oc,{className:"text-accent2","aria-label":"View PDF"})}):o.jsxs(o.Fragment,{children:[o.jsx("button",{onClick:()=>r(!0),className:XT,type:"button",children:o.jsx(Oc,{className:"text-accent2","aria-label":"View PDF"})}),o.jsx(TPr,{data:e,open:n,onOpenChange:r})]})},TPr=({data:e,open:t,onOpenChange:n})=>o.jsx(br,{open:t,onOpenChange:n,children:o.jsxs(xr,{className:"max-w-4xl",children:[o.jsxs(wr,{children:[o.jsx(gr,{children:"PDF preview"}),o.jsx(Qs,{children:"Preview of the PDF document"})]}),o.jsx(Rr,{children:t&&o.jsx("iframe",{src:e,width:"100%",height:"600px"})})]})}),NPr=e=>e?.startsWith("video/")?{Icon:uun,label:"Video file"}:e?.startsWith("audio/")?{Icon:tun,label:"Audio file"}:e?.startsWith("text/")||e==="application/pdf"?{Icon:Oc,label:"Document file"}:{Icon:rbe,label:"File"},m2t=({name:e,url:t,contentType:n})=>{const{Icon:r,label:s}=NPr(n),a=o.jsx(r,{className:"text-accent2","aria-label":s});return t?o.jsx("a",{href:t,className:XT,target:"_blank",rel:"noreferrer noopener",title:e,children:a}):o.jsx("div",{className:XT,title:e,children:a})},g2t=({src:e})=>{const[t,n]=g.useState(!1);return o.jsxs(o.Fragment,{children:[o.jsx("button",{onClick:()=>n(!0),type:"button",className:XT,children:o.jsx("img",{src:e,className:"object-cover aspect-ratio max-h-[140px] max-w-[320px]",alt:"Preview"})}),o.jsx(IPr,{src:e,open:t,onOpenChange:n})]})},IPr=({src:e,open:t,onOpenChange:n})=>o.jsx(br,{open:t,onOpenChange:n,children:o.jsxs(xr,{className:"max-w-4xl",children:[o.jsxs(wr,{children:[o.jsx(gr,{children:"Image preview"}),o.jsx(Qs,{children:"Preview of the image"})]}),o.jsx(Rr,{children:t&&o.jsx("img",{src:e,alt:"Image"})})]})}),v2t=({data:e})=>{const[t,n]=g.useState(!1),r=e.replace(/<attachment[^>]*>/,"").replace(/<\/attachment>/g,"");return o.jsxs(o.Fragment,{children:[o.jsx("button",{onClick:()=>n(!0),className:XT,type:"button",children:o.jsx(Oc,{className:"text-neutral3"})}),o.jsx(APr,{data:r,open:t,onOpenChange:n})]})},APr=({data:e,open:t,onOpenChange:n})=>o.jsx(br,{open:t,onOpenChange:n,children:o.jsxs(xr,{className:"max-w-4xl h-[80vh]",children:[o.jsxs(wr,{children:[o.jsx(gr,{children:"Text preview"}),o.jsx(Qs,{children:"Preview of the text file"})]}),o.jsx(Rr,{children:t&&o.jsx("div",{className:"whitespace-pre-wrap",children:e})})]})}),RPr=({file:e})=>{const{isLoading:t,text:n}=jPr(e);return o.jsx("div",{className:"flex items-center justify-center h-full w-full",children:t?o.jsx(Gt,{}):o.jsx(v2t,{data:n})})},PPr=({attachment:e})=>{const[t,n]=g.useState({isLoading:!1,text:""});return g.useEffect(()=>{let r=!1;return(async()=>{if(!e.file)return;n(i=>({...i,isLoading:!0}));const a=await x8(e.file);r||n(i=>({...i,isLoading:!1,text:a}))})(),()=>{r=!0}},[e]),o.jsx("div",{className:"flex items-center justify-center h-full w-full",children:t.isLoading?o.jsx(Gt,{}):o.jsx(h2t,{data:t.text,url:e.isUrl?e.name:void 0})})},$Pr=({attachment:e})=>{const[t,n]=g.useState(e.isUrl?e.name:"");return g.useEffect(()=>{if(e.isUrl){n(e.name);return}const r=URL.createObjectURL(e.file);return n(r),()=>URL.revokeObjectURL(r)},[e]),o.jsx(g2t,{src:t})},MPr=({attachment:e})=>{const{remove:t}=RW();return o.jsxs("div",{className:"relative",children:[o.jsx(Jct,{children:o.jsxs(Wn,{children:[o.jsx(zn,{asChild:!0,children:o.jsx("div",{className:"overflow-hidden size-16 rounded-lg bg-surface3 border border-border1 ",children:e.kind==="image"?o.jsx($Pr,{attachment:e}):e.kind==="pdf"?o.jsx(PPr,{attachment:e}):e.kind==="video"?o.jsx(m2t,{name:e.name,url:e.isUrl&&f2t(e.name)?e.name:void 0,contentType:e.contentType}):o.jsx(RPr,{file:e.file})})}),o.jsx(Bn,{side:"top",children:e.name})]})}),o.jsx(de,{variant:"default",size:"icon-sm",type:"button",tooltip:"Remove file",onClick:()=>t(e.id),className:"absolute -right-2 -top-2 text-neutral3 hover:text-neutral6 bg-surface1 hover:bg-surface2",children:o.jsx(Ue,{children:o.jsx(vs,{})})})]})},DPr=()=>{const{attachments:e}=RW();return e.length===0?null:o.jsx("div",{className:"absolute bottom-full inset-x-0 px-2","data-attachments-row":!0,children:o.jsx("div",{className:"max-w-3xl w-full mx-auto overflow-x-auto",children:o.jsx("div",{className:"flex flex-row items-center gap-4 px-3 pt-3 pb-1",children:e.map(t=>o.jsx(MPr,{attachment:t},t.id))})})})},LPr=(e,t)=>{const n=We(),[r,s]=g.useState(!1),[a,i]=g.useState(!1),l=g.useRef(null);g.useEffect(()=>{let d=!1;return e?(n.getAgent(e).voice.getSpeakers(t).then(p=>{d||s(p.length>0)}).catch(()=>{d||s(!1)}),()=>{d=!0}):(s(!1),()=>{d=!0})},[e,n,t]);const c=g.useCallback(()=>{l.current?.(),l.current=null,typeof window<"u"&&window.speechSynthesis&&window.speechSynthesis.cancel(),i(!1)},[]),u=g.useCallback(async d=>{if(d){if(c(),i(!0),e&&r)try{const p=await n.getAgent(e).voice.speak(d);if(!p.body)throw new Error("No audio stream returned from voice.speak()");const h=await Evn(p.body,()=>i(!1));l.current=h??null;return}catch(f){i(!1),Ru.error(f instanceof Error?f.message:"Voice generation failed.");return}if(typeof window<"u"&&window.speechSynthesis){const f=new SpeechSynthesisUtterance(d);f.onend=()=>i(!1),f.onerror=()=>i(!1),window.speechSynthesis.speak(f);return}i(!1)}},[e,n,r,c]);return g.useEffect(()=>()=>c(),[c]),{isSpeaking:a,readAloud:u,stop:c}},tZe=12;function FPr({containerRef:e}){const[t,n]=g.useState([]),[r,s]=g.useState(null),a=g.useRef(""),i=g.useRef(0),l=g.useCallback(()=>{const u=e.current;if(!u){a.current!==""&&(a.current="",n([]));return}const d=u.getBoundingClientRect(),f=Array.from(u.querySelectorAll("[data-om-badge]"));if(f.length===0){a.current!==""&&(a.current="",n([]));return}const p=[];for(let m=0;m<f.length;m++){const v=f[m],y=v.getAttribute("data-om-badge")||"",b=v.getAttribute("data-om-state")||"complete",S=v.getAttribute("data-om-type")||"observation",w=v.getBoundingClientRect();let k;const _=zPr(f,m,S);_?k=_.getBoundingClientRect().bottom+tZe-d.top:k=0;const E=w.bottom+tZe-d.top-k;E<=0||p.push({cycleId:y,omType:S,state:b,top:k,height:E})}const h=JSON.stringify(p);h!==a.current&&(a.current=h,n(p))},[e]);if(g.useEffect(()=>{const u=e.current;if(!u)return;l();const d=new ResizeObserver(()=>{cancelAnimationFrame(i.current),i.current=requestAnimationFrame(l)});d.observe(u);const f=new MutationObserver(()=>{cancelAnimationFrame(i.current),i.current=requestAnimationFrame(l)});return f.observe(u,{childList:!0,subtree:!0}),()=>{cancelAnimationFrame(i.current),d.disconnect(),f.disconnect()}},[l,e]),g.useEffect(()=>{const u=e.current;if(!u)return;const d=p=>{const h=p.target.closest("[data-om-badge]");h&&s(h.getAttribute("data-om-badge"))},f=p=>{p.target.closest("[data-om-badge]")&&s(null)};return u.addEventListener("mouseover",d),u.addEventListener("mouseout",f),()=>{u.removeEventListener("mouseover",d),u.removeEventListener("mouseout",f)}},[e]),t.length===0)return null;const c=t[t.length-1]?.cycleId??null;return o.jsx("div",{className:"pointer-events-none absolute inset-0",style:{zIndex:0},children:t.map(u=>{const d=u.cycleId===c,f=u.cycleId===r,p=r?f:d;return o.jsx(BPr,{highlight:u,visible:p},u.cycleId)})})}function zPr(e,t,n){for(let r=t-1;r>=0;r--){const s=e[r];if(s.getAttribute("data-om-state")!=="failed"&&(n==="observation"||s.getAttribute("data-om-type")==="reflection"))return s}return null}function BPr({highlight:e,visible:t}){const n=UPr(e.state),r=e.state.startsWith("buffering");return o.jsx("div",{className:"absolute left-0 right-0 transition-opacity duration-200",style:{top:e.top,height:e.height,border:`2px ${r?"dashed":"solid"} ${n}`,borderRadius:"0.5rem",opacity:t?1:0}})}function UPr(e){switch(e){case"complete":return"rgba(34, 197, 94, 0.4)";case"loading":return"rgba(59, 130, 246, 0.4)";case"failed":return"rgba(239, 68, 68, 0.4)";case"disconnected":return"rgba(234, 179, 8, 0.4)";case"buffering":return"rgba(156, 163, 175, 0.45)";case"buffering-complete":return"rgba(156, 163, 175, 0.45)";case"buffering-failed":return"rgba(239, 68, 68, 0.4)";case"activated":return"rgba(34, 197, 94, 0.4)";default:return"rgba(34, 197, 94, 0.4)"}}const y2t=g.createContext(null);function qPr({children:e,...t}){return o.jsx(y2t.Provider,{value:t,children:e})}function PW(){return g.useContext(y2t)}function b2t({open:e,onOpenChange:t,input:n,onInputChange:r,requestContext:s,initialGroundTruth:a=""}){const[i,l]=g.useState(a),[c,u]=g.useState("");g.useEffect(()=>{e&&l(a)},[e,a]);const{data:d,isLoading:f}=$g(),{addItem:p}=Ei(),h=g.useMemo(()=>d?.datasets??[],[d?.datasets]),m=g.useCallback(async()=>{if(!c){De.error("Please select a dataset");return}let v;try{v=JSON.parse(n)}catch{De.error("Input must be valid JSON");return}let y;if(i.trim())try{y=JSON.parse(i)}catch{De.error("Ground Truth must be valid JSON");return}try{const b=s&&Object.keys(s).length>0;await p.mutateAsync({datasetId:c,input:v,groundTruth:y,...b?{requestContext:s}:{}});const S=h.find(w=>w.id===c);De.success(`Item saved to "${S?.name}"`),t(!1),u(""),r(""),l("")}catch(b){De.error(`Failed to save item: ${b instanceof Error?b.message:"Unknown error"}`)}},[n,i,c,s,p,h,t,r]);return o.jsx(br,{open:e,onOpenChange:t,children:o.jsxs(xr,{className:"max-w-lg",children:[o.jsxs(wr,{children:[o.jsx(gr,{children:"Save to Dataset"}),o.jsx(Qs,{children:"Save as a dataset item for evaluation."})]}),o.jsxs(Rr,{className:"py-1 space-y-4",children:[o.jsxs("div",{className:"grid gap-2",children:[o.jsx(Rt,{htmlFor:"ds-target",children:"Dataset"}),o.jsxs(da,{value:c,onValueChange:u,disabled:p.isPending||f,children:[o.jsx(pa,{id:"ds-target",children:o.jsx(fa,{placeholder:f?"Loading...":"Select a dataset"})}),o.jsx(ha,{children:h.length===0?o.jsx("div",{className:"px-2 py-4 text-sm text-neutral4 text-center",children:"No datasets available"}):h.map(v=>o.jsx(Lr,{value:v.id,children:v.name},v.id))})]})]}),o.jsxs("div",{className:"grid gap-2",children:[o.jsx(Rt,{children:"Input (JSON)"}),o.jsx(Qr,{value:n,onChange:r,showCopyButton:!1,className:"min-h-[120px] max-h-[240px]"})]}),o.jsxs("div",{className:"grid gap-2",children:[o.jsx(Rt,{children:"Ground Truth (JSON, optional)"}),o.jsx(Qr,{value:i,onChange:l,showCopyButton:!1,className:"min-h-[80px] max-h-[160px]"})]})]}),o.jsxs(Cc,{className:"px-6",children:[o.jsx(de,{variant:"default",size:"sm",onClick:()=>t(!1),children:"Cancel"}),o.jsxs(de,{variant:"primary",size:"sm",onClick:m,disabled:p.isPending||!c||h.length===0,children:[o.jsx(Ue,{size:"sm",children:o.jsx(gd,{})}),p.isPending?"Saving...":"Save Item"]})]})]})})}function VPr({messageText:e}){return PW()?.enabled?o.jsx(HPr,{messageText:e}):null}function HPr({messageText:e}){const t=PW(),[n,r]=g.useState(!1),[s,a]=g.useState(""),i=g.useCallback(()=>{a(JSON.stringify(e,null,2)),r(!0)},[e]);return o.jsxs(o.Fragment,{children:[o.jsx(de,{variant:"default",size:"icon-md",tooltip:"Save to dataset",className:"bg-transparent text-neutral3 hover:text-neutral6",onClick:i,children:o.jsx(iy,{className:"h-4 w-4"})}),o.jsx(b2t,{open:n,onOpenChange:r,input:s,onInputChange:a,requestContext:t?.requestContext})]})}function WPr(){return PW()?.enabled?o.jsx(ZPr,{}):null}function ZPr(){const e=PW(),t=We(),[n,r]=g.useState(!1),[s,a]=g.useState(""),[i,l]=g.useState(""),[c,u]=g.useState(!1),d=g.useCallback(async()=>{u(!0);try{const p=(await t.listThreadMessages(e.threadId,{agentId:e.agentId}))?.messages??[],h=p.length-1,m=p[h];if(m&&m.role==="assistant"){const v=p.slice(0,h);a(JSON.stringify(v,null,2)),l(JSON.stringify(m,null,2))}else a(JSON.stringify(p,null,2)),l("");r(!0)}catch(f){De.error(`Failed to fetch thread messages: ${f instanceof Error?f.message:"Unknown error"}`)}finally{u(!1)}},[t,e.threadId,e.agentId]);return o.jsxs(o.Fragment,{children:[o.jsxs("button",{type:"button",onClick:d,disabled:c,className:"flex items-center gap-1.5 text-neutral3 hover:text-neutral5 transition-colors mx-auto py-3 text-ui-xs leading-ui-xs cursor-pointer disabled:opacity-50",children:[c?o.jsx(Gt,{className:"h-3.5 w-3.5"}):o.jsx(iy,{className:"h-3.5 w-3.5"}),"Save full conversation to dataset"]}),o.jsx(b2t,{open:n,onOpenChange:r,input:s,onInputChange:a,requestContext:e.requestContext,initialGroundTruth:i})]})}const GPr=({part:e,metadata:t})=>o.jsx(XOe,{text:e.text??"",metadata:t}),QPr=({part:e})=>e.type==="data-signal"&&J3(e.data)?o.jsx($It,{signal:e.data}):null,YPr=({toolCallId:e,suspendPayload:t,result:n})=>{const{approveToolcall:r,isRunning:s,toolCallApprovals:a}=u2t(),[i,l]=g.useState([]),[c,u]=g.useState(""),{question:d,options:f,selectionMode:p}=t,h=f?.length?p??"single_select":void 0,m=!!n||a?.[e]?.status==="approved",v=f?.length?h==="multi_select"?"multiple choice":"single choice":"free text",y=g.useCallback(k=>{m||s||(h==="multi_select"?l(_=>_.includes(k)?_.filter(C=>C!==k):[..._,k]):r(e,k))},[m,s,h,r,e]),b=g.useCallback(()=>{i.length===0||m||s||r(e,i)},[i,m,s,r,e]),S=g.useCallback(()=>{const k=c.trim();!k||m||s||r(e,k)},[c,m,s,r,e]),w=g.useCallback(k=>{k.key==="Enter"&&!k.shiftKey&&(k.preventDefault(),S())},[S]);return o.jsxs("div",{"data-testid":"ask-user-badge",className:"mb-4 flex w-full max-w-full overflow-hidden rounded-lg border border-border1 bg-surface3",children:[o.jsx("div",{className:K("w-1 shrink-0",m?"bg-notice-success":"bg-accent1")}),o.jsxs("div",{className:"min-w-0 flex-1",children:[o.jsxs("div",{className:"flex h-header-default items-center gap-2 border-b border-border1 px-4",children:[o.jsx("span",{className:"rounded-md border border-border1 bg-surface4 p-1",children:o.jsx(Ue,{children:o.jsx(Hlt,{className:"text-icon3"})})}),o.jsx(ge,{as:"span",variant:"ui-md",className:"font-medium text-neutral6",children:"Ask User"}),o.jsxs(ge,{as:"span",variant:"ui-sm",className:"text-neutral3",children:["· ",v]}),m&&o.jsx(dn,{variant:"success",size:"sm",icon:o.jsx("span",{className:"size-1.5 rounded-full bg-current"}),children:"Answered"})]}),o.jsxs("div",{className:"flex flex-col gap-4 p-4",children:[o.jsx(ge,{as:"p",variant:"ui-xs",className:"uppercase tracking-wide text-neutral3",children:"Question"}),o.jsx(ge,{as:"p",variant:"ui-lg",className:"text-neutral6",children:d}),m&&n!=null&&o.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-border1 bg-surface4 px-3 py-2",children:[o.jsx(Ue,{children:o.jsx(Js,{className:"text-notice-success-fg"})}),o.jsx(ge,{as:"span",variant:"ui-md",className:"font-medium text-neutral6",children:n.content})]}),!m&&f&&f.length>0&&o.jsxs("div",{className:"flex flex-col gap-2",children:[f.map(k=>{const _=i.includes(k.label);return o.jsxs("button",{type:"button",onClick:()=>y(k.label),disabled:s,className:K("rounded-md border px-3 py-2 text-left transition-colors disabled:cursor-not-allowed disabled:opacity-50",_?"border-accent1 bg-surface4":"border-border1 bg-surface4 hover:bg-surface5"),children:[o.jsx(ge,{as:"span",variant:"ui-md",className:"font-medium text-neutral6",children:k.label}),k.description&&o.jsx(ge,{as:"span",variant:"ui-xs",className:"mt-0.5 block text-neutral3",children:k.description})]},k.label)}),h==="multi_select"&&o.jsxs(de,{onClick:b,disabled:i.length===0||s,children:[o.jsx(Ue,{children:o.jsx(xMe,{})}),"Submit (",i.length," selected)"]})]}),!m&&!f?.length&&o.jsxs("div",{className:"flex gap-2",children:[o.jsx(kn,{placeholder:"Type your answer...",value:c,onChange:k=>u(k.target.value),onKeyDown:w,disabled:s,className:"flex-1"}),o.jsx(de,{onClick:S,disabled:!c.trim()||s,children:o.jsx(Ue,{children:o.jsx(xMe,{})})})]})]})]})]})};function XPr(e){return typeof e=="object"&&e!==null&&"question"in e&&typeof e.question=="string"}function KPr(e){if(typeof e=="object"&&e!==null&&typeof e.content=="string")return e}const JPr=({toolName:e,toolCallId:t,output:n,metadata:r})=>{const s=(r?.suspendedTools?.[e]??r?.suspendedTools?.[t])?.suspendPayload;return XPr(s)?o.jsx(YPr,{toolCallId:t,suspendPayload:s,result:KPr(n)}):null};function e$r(e){return e.metadata?.systemReminder||e.metadata?.dynamicAgentsMdReminder?!0:e.role!=="user"?!1:Array.isArray(e.parts)?e.parts.some(t=>t.type==="text"&&typeof t.text=="string"&&t.text.includes("<system-reminder")):typeof e.content=="string"&&e.content.includes("<system-reminder")}function rve(e){return e.filter(t=>!e$r(t))}function t$r(e,t={}){const n=new gln().add(e,"memory");return t.version==="v6"?rve(n.get.all.aiV6.ui()):rve(n.get.all.aiV5.ui())}function n$r(e){return rve(t$r(e))}const x2t=(e,t)=>Number(e.toPrecision(t)),r$r=({startedAt:e,endedAt:t})=>{const[n,r]=g.useState(e);return g.useEffect(()=>{if(r(e),t!=null)return;const a=setInterval(()=>{r(Date.now())},100);return()=>clearInterval(a)},[e,t]),t!=null?t-e:n-e},s$r=({backgroundTaskTaskId:e,backgroundTaskStartedAt:t,backgroundTaskCompletedAt:n,backgroundTaskSuspendedAt:r,open:s,onOpenChange:a})=>{const{data:i}=AYn(e,!!n||!!r),{tasks:l}=IYn({taskId:e,enabled:!n&&!r}),c=r$r({startedAt:new Date(t).getTime(),endedAt:n?new Date(n).getTime():r?new Date(r).getTime():void 0}),u=i||l[e],d=u?.args,f=u?.result,p=u?.suspendPayload;let h=null;try{const{__mastraMetadata:y,_background:b,...S}=typeof d=="object"?d:JSON.parse(d);h=o.jsx(Qr,{data:S})}catch{h=o.jsx("pre",{className:"whitespace-pre bg-surface4 p-4 rounded-md overflow-x-auto",children:d})}const m=typeof f=="string"?o.jsx("pre",{className:"whitespace-pre bg-surface4 p-4 rounded-md overflow-x-auto",children:f}):o.jsx(Qr,{data:f}),v=typeof p=="string"?o.jsx("pre",{className:"whitespace-pre bg-surface4 p-4 rounded-md overflow-x-auto",children:p}):o.jsx(Qr,{data:p});return o.jsx(br,{open:s,onOpenChange:a,children:o.jsxs(xr,{children:[o.jsxs(wr,{children:[o.jsx(gr,{children:"Background Task Metadata"}),o.jsx(Qs,{children:"View the metadata of the background task."})]}),o.jsxs(Rr,{className:"space-y-4",children:[o.jsxs("div",{className:"space-y-2",children:[o.jsx(ge,{className:"text-neutral3",children:"Background Task Duration"}),o.jsxs(ge,{className:"text-neutral6 text-ui-md",children:[x2t(c,3),"ms"]})]}),o.jsxs("div",{className:"space-y-2",children:[o.jsx(ge,{className:"text-neutral3",children:"Background Task Arguments"}),h]}),v!==void 0&&p&&o.jsxs("div",{className:"space-y-2",children:[o.jsx(ge,{className:"text-neutral3",children:"Background Task Suspend Data"}),v]}),m!==void 0&&f&&o.jsxs("div",{className:"space-y-2",children:[o.jsx(ge,{className:"text-neutral3",children:"Background Task Result"}),m]})]})]})})},B_e=({backgroundTask:e})=>{const[t,n]=g.useState(!1);return o.jsxs(o.Fragment,{children:[o.jsx(de,{variant:"default",size:"icon-md",tooltip:"Show background task information",onClick:()=>n(r=>!r),children:e.completedAt||e.suspendedAt?o.jsx(ect,{className:"text-neutral3 size-5"}):o.jsx(oa,{className:"text-neutral3 size-5 animate-spin"})}),o.jsx(s$r,{backgroundTaskTaskId:e.taskId,backgroundTaskStartedAt:e.startedAt,backgroundTaskCompletedAt:e.completedAt,backgroundTaskSuspendedAt:e.suspendedAt,open:t,onOpenChange:n})]})},c4=({children:e,initialCollapsed:t=!0,icon:n,title:r,collapsible:s=!0,extraInfo:a,"data-testid":i})=>{const[l,c]=g.useState(t);return g.useEffect(()=>{c(t)},[t]),o.jsxs("div",{className:"mb-4","data-testid":i,children:[o.jsxs("div",{className:"flex flex-row gap-2 items-center justify-between",children:[o.jsxs("button",{onClick:s?()=>c(u=>!u):void 0,className:"flex items-center gap-2 disabled:cursor-not-allowed",disabled:!s,type:"button",children:[o.jsx(Ue,{children:o.jsx(f_,{className:K("transition-all",l?"rotate-90":"rotate-180")})}),o.jsx(dn,{icon:n,children:r})]}),a]}),!l&&o.jsx("div",{className:"pt-2",children:o.jsx("div",{className:"p-4 rounded-lg bg-surface2 flex flex-col gap-4",children:e})})]})},a$r=({selectionReason:e,open:t,onOpenChange:n,input:r})=>{let s=null;if(r)try{s=typeof r=="object"?o.jsx(Qr,{data:r}):o.jsx(Qr,{data:JSON.parse(r)})}catch{s=o.jsx("pre",{className:"whitespace-pre-wrap",children:r})}return o.jsx(br,{open:t,onOpenChange:n,children:o.jsxs(xr,{children:[o.jsxs(wr,{children:[o.jsx(gr,{children:"Agent Network Metadata"}),o.jsx(Qs,{children:"View the metadata of the agent's network choice."})]}),o.jsxs(Rr,{className:"space-y-4",children:[o.jsxs("div",{className:"space-y-2",children:[o.jsx(ge,{className:"text-neutral3",children:"Selection Reason"}),o.jsx("div",{className:"text-neutral6 text-ui-md",children:e})]}),s&&o.jsxs("div",{className:"space-y-2",children:[o.jsx(ge,{className:"text-neutral3",children:"Input"}),o.jsx("div",{className:"text-neutral6 text-ui-md",children:s})]})]})]})})},U_e=({selectionReason:e,input:t})=>{const[n,r]=g.useState(!1);return o.jsxs(o.Fragment,{children:[o.jsx(de,{variant:"default",size:"icon-md",tooltip:"Show selection reason",onClick:()=>r(s=>!s),children:o.jsx(ect,{className:"text-neutral3 size-5"})}),o.jsx(a$r,{selectionReason:e||"",open:n,onOpenChange:r,input:t})]})},bI=({toolCalled:e,toolCallId:t,toolApprovalMetadata:n,toolName:r,isNetwork:s,isGenerateMode:a})=>{const{approveToolcall:i,declineToolcall:l,approveToolcallGenerate:c,declineToolcallGenerate:u,isRunning:d,toolCallApprovals:f,approveNetworkToolcall:p,declineNetworkToolcall:h,networkToolCallApprovals:m}=u2t(),v=()=>{s?p(r,n?.runId):a?c(t):i(t)},y=()=>{s?h(r,n?.runId):a?u(t):l(t)},b=s?m?.[n?.runId?`${n.runId}-${r}`:r]?.status:f?.[t]?.status;return n&&!e?o.jsxs("div",{children:[o.jsx("p",{className:"font-medium pb-2",children:"Approval required"}),o.jsxs("div",{className:"flex gap-2 items-center",children:[o.jsxs(de,{onClick:v,disabled:d||!!b,className:b==="approved"?"text-accent1!":"",children:[o.jsx(Ue,{children:o.jsx(Js,{})}),"Approve"]}),o.jsxs(de,{onClick:y,disabled:d||!!b,className:b==="declined"?"text-accent2!":"",children:[o.jsx(Ue,{children:o.jsx(vs,{})}),"Decline"]})]})]}):null},i$r=({agentId:e,messages:t=[],metadata:n,toolCallId:r,toolApprovalMetadata:s,toolName:a,isNetwork:i,suspendPayload:l,toolCalled:c,isComplete:u=!1,keepOpenForStreamingChildMessages:d=!1})=>{const f=n?.mode==="network"?n.routingDecision:void 0,p=n?.mode==="network"?f?.selectionReason??n.selectionReason:void 0,h=n?.mode==="network"?f??n.agentInput:void 0,m=n?.mode==="stream"||n?.mode==="network"||n?.mode==="generate"?n?.requireApprovalMetadata:void 0,v=n?.mode==="stream"||n?.mode==="network"||n?.mode==="generate"?n?.suspendedTools:void 0,y=(n?.mode==="stream"||n?.mode==="generate")&&n?.backgroundTasks?n.backgroundTasks[r]:void 0,b=t.length>0&&t.every(_=>_.type==="text"?!0:_.toolOutput!==void 0);let S=b;i&&(S=c??b);const w=u&&!s&&!d;let k=typeof l=="string"?o.jsx("pre",{className:"whitespace-pre bg-surface4 p-4 rounded-md overflow-x-auto",children:l}):o.jsx(Qr,{data:l,"data-testid":"tool-suspend-payload"});return o.jsxs(c4,{"data-testid":"agent-badge",icon:o.jsx(sl,{className:"text-accent1"}),title:e,initialCollapsed:w,extraInfo:n?.mode==="network"?o.jsx(U_e,{selectionReason:p??"",input:h}):y?.taskId&&y?.startedAt?o.jsx(B_e,{backgroundTask:y}):null,children:[t.map((_,C)=>{if(_.type==="text")return o.jsx(JNt,{children:_.content},C);let E;try{E=typeof _.toolOutput=="string"?JSON.parse(_.toolOutput):_.toolOutput}catch{E=_.toolOutput}return o.jsx(Le.Fragment,{children:o.jsx(gje,{toolName:_.toolName,input:_.args,output:E,state:"output-available",toolCallId:_.toolCallId,metadata:{mode:"stream",requireApprovalMetadata:m,suspendedTools:v}})},C)}),k!==void 0&&l&&o.jsxs("div",{children:[o.jsx("p",{className:"font-medium pb-2",children:"Agent suspend payload"}),k]}),o.jsx(bI,{toolCalled:S,toolCallId:r,toolApprovalMetadata:s,toolName:a,isNetwork:i,isGenerateMode:n?.mode==="generate"})]})},q_e=()=>o.jsx(c4,{icon:o.jsx(Gt,{className:"text-neutral3"}),title:o.jsx(bt,{className:"ml-2 w-12 h-2"}),collapsible:!1}),o$r=e=>{const t=e.find(r=>r.role==="assistant");if(!t)return[];const n=[];for(const r of t.parts??[]){const s=r;if(typeof r.type=="string"&&r.type.startsWith("tool-")){const a=r.type.substring(5),i=a.startsWith("workflow-");n.push({type:"tool",toolCallId:s.toolCallId,toolName:a,args:s.input,toolOutput:i?{...s.output?.result,runId:s.output?.runId}:s.output})}r.type==="text"&&n.push({type:"text",content:s.text})}return n},l$r=({agentId:e,result:t,metadata:n,toolCallId:r,toolApprovalMetadata:s,toolName:a,isNetwork:i,suspendPayload:l,toolCalled:c,isComplete:u})=>{const d=!!(t?.subAgentThreadId&&!t.text&&!t.subAgentToolResults?.length),{data:f,isLoading:p}=WV({threadId:d?t?.subAgentThreadId:void 0,agentId:e,memory:!0});if(p)return o.jsx(q_e,{});const h=f?.messages?n$r(f.messages):[];let m=t?.childMessages?.length?t.childMessages:void 0;if(!m&&t?.subAgentToolResults?.length){const y=t.subAgentToolResults.map(b=>({type:"tool",toolName:b.toolName,toolCallId:b.toolCallId,args:b.args,toolOutput:b.result}));t.text&&y.push({type:"text",content:t.text}),m=y}!m&&t?.text&&(m=[{type:"text",content:t.text}]),m||(m=o$r(h));const v=!!(t&&Object.prototype.hasOwnProperty.call(t,"childMessages"));return o.jsx(i$r,{agentId:e,messages:m??[],keepOpenForStreamingChildMessages:v,metadata:n,toolCallId:r,toolApprovalMetadata:s,toolName:a,isNetwork:i,suspendPayload:l,toolCalled:c,isComplete:u})},c$r=e=>o.jsxs("svg",{width:"126",height:"85",viewBox:"0 0 126 85",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:[o.jsx("path",{d:"M119.322 35.1641C119.322 50.36 94.1055 62.6787 62.9998 62.6787C31.894 62.6787 6.67773 50.36 6.67773 35.1641V49.8368C6.67773 65.0327 31.894 77.3514 62.9998 77.3514C94.1055 77.3514 119.322 65.0327 119.322 49.8368V35.1641Z",fill:"#2E2E2E",fillOpacity:"0.9"}),o.jsx("path",{d:"M119.322 35.1641C119.322 50.36 94.1055 62.6787 62.9998 62.6787C31.894 62.6787 6.67773 50.36 6.67773 35.1641M119.322 35.1641C119.322 19.9681 94.1055 7.64941 62.9998 7.64941C31.894 7.64941 6.67773 19.9681 6.67773 35.1641M119.322 35.1641V49.8368C119.322 65.0327 94.1055 77.3514 62.9998 77.3514C31.894 77.3514 6.67773 65.0327 6.67773 49.8368V35.1641",stroke:"#424242"}),o.jsx("path",{d:"M63.0002 0.96875C28.5152 0.96875 0.55957 15.6489 0.55957 33.7578V51.2433C0.55957 69.3522 28.5152 84.0323 63.0002 84.0323C97.4853 84.0323 125.441 69.3522 125.441 51.2433V33.7578C125.441 15.6489 97.4853 0.96875 63.0002 0.96875Z",stroke:"#707070"}),o.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M95.8997 32.6647C98.4806 33.9355 98.4744 36.0012 95.8997 37.2689L89.6657 40.3384C87.0848 41.6091 82.8892 41.6061 80.3146 40.3384L74.0805 37.2689C71.4996 35.9981 71.5059 33.9324 74.0805 32.6647L80.3146 29.5952C82.8955 28.3244 87.091 28.3275 89.6657 29.5952L95.8997 32.6647ZM74.0805 21.9215C76.6614 23.1923 76.6552 25.258 74.0805 26.5257L67.8465 29.5952C65.2656 30.866 61.0701 30.8629 58.4954 29.5952L52.2613 26.5257C49.6804 25.255 49.6867 23.1892 52.2613 21.9215L58.4954 18.852C61.0763 17.5813 65.2718 17.5843 67.8465 18.852L74.0805 21.9215ZM74.0805 43.4079C76.6614 44.6786 76.6552 46.7444 74.0805 48.0121L67.8465 51.0816C65.2656 52.3523 61.0701 52.3493 58.4954 51.0816L52.2613 48.0121C49.6804 46.7413 49.6867 44.6756 52.2613 43.4079L58.4954 40.3384C61.0763 39.0676 65.2718 39.0707 67.8465 40.3384L74.0805 43.4079ZM52.2613 32.6647C54.8422 33.9355 54.836 36.0012 52.2613 37.2689L46.0273 40.3384C43.4464 41.6091 39.2509 41.6061 36.6762 40.3384L30.4422 37.2689C27.8613 35.9981 27.8675 33.9324 30.4422 32.6647L36.6762 29.5952C39.2571 28.3244 43.4526 28.3275 46.0273 29.5952L52.2613 32.6647Z",fill:"#A9A9A9"})]});let nZe;const w2t=()=>nZe??=Promise.all([jo(()=>import("./standalone-BioU5qLH.js"),[],import.meta.url),jo(()=>import("./babel-CmeIX3PZ.js"),[],import.meta.url),jo(()=>import("./estree-CRgMSIiv.js"),[],import.meta.url)]).catch(e=>{throw nZe=void 0,e}),Dj=async e=>{const[t,n,r]=await w2t();return await t.format(e,{semi:!1,parser:"json",printWidth:80,tabWidth:2,plugins:[n,r]})},u$r=async e=>{const[t,n,r]=await w2t();return await t.format(e,{parser:"babel-ts",printWidth:80,tabWidth:2,plugins:[n,r]})},DM=e=>{try{const t=JSON.parse(e);return!!t&&typeof t=="object"}catch{return!1}},d$r=(e,t)=>{let n;try{n=typeof e=="object"?e:JSON.parse(e)}catch{return null}const r=n?.code;return typeof r!="string"?null:t==null?{code:r}:typeof t=="object"&&typeof t.success=="boolean"&&("result"in t||"logs"in t||"error"in t)?{code:r,result:t}:null},f$r=({toolName:e,code:t,result:n,metadata:r,toolCallId:s,toolApprovalMetadata:a,isNetwork:i,toolCalled:l})=>{const c=n?.logs??[],u=n?.error,d=n!==void 0&&n.result!==void 0,f=l??n!==void 0,[p,h]=g.useState(t);return g.useEffect(()=>{let m=!1;return u$r(t).then(v=>{m||h(v)}).catch(()=>{m||h(t)}),()=>{m=!0}},[t]),o.jsx(c4,{"data-testid":"code-mode-badge",icon:o.jsx(c$r,{className:"text-accent6"}),title:e,initialCollapsed:!a,children:o.jsxs("div",{className:"space-y-4",children:[o.jsxs("div",{children:[o.jsx("p",{className:"font-medium pb-2",children:"Program"}),o.jsx("div",{"data-testid":"code-mode-program",children:o.jsx(v_e,{code:p,lang:"typescript"})})]}),u&&o.jsxs("div",{children:[o.jsx("p",{className:"font-medium pb-2",children:"Error"}),o.jsxs("pre",{"data-testid":"code-mode-error",className:"whitespace-pre-wrap break-words bg-surface4 p-4 rounded-md text-error font-mono text-sm",children:[u.name?`${u.name}: `:"",u.message,typeof u.line=="number"?` (line ${u.line})`:""]})]}),d&&o.jsxs("div",{children:[o.jsx("p",{className:"font-medium pb-2",children:"Result"}),typeof n.result=="string"?o.jsx("pre",{className:"whitespace-pre bg-surface4 p-4 rounded-md overflow-x-auto","data-testid":"code-mode-result",children:n.result}):o.jsx(Qr,{data:n.result,"data-testid":"code-mode-result"})]}),c.length>0&&o.jsxs("div",{children:[o.jsx("p",{className:"font-medium pb-2",children:"Logs"}),o.jsx("pre",{"data-testid":"code-mode-logs",className:"whitespace-pre-wrap break-words bg-black p-3 rounded-md text-neutral-300 font-mono text-sm overflow-x-auto",children:c.join(`
|
|
511
|
+
`);return o.jsxs(xr,{className:"max-w-2xl",children:[o.jsxs(wr,{children:[o.jsx(gr,{children:"Installed Mastra Packages"}),o.jsx(Qs,{children:"View and update installed Mastra packages"})]}),o.jsxs(Rr,{children:[o.jsxs("div",{className:"flex items-center justify-between gap-3 text-sm text-neutral3 py-2",children:[t?o.jsx("span",{className:"text-neutral3",children:"Checking for updates..."}):l?o.jsxs("div",{className:"flex items-center gap-3",children:[n>0&&o.jsxs("span",{className:"flex items-center gap-1.5",children:[o.jsx(cWe,{value:n,variant:"warning"}),o.jsxs("span",{children:["package",n!==1?"s":""," outdated"]})]}),r>0&&o.jsxs("span",{className:"flex items-center gap-1.5",children:[o.jsx(cWe,{value:r,variant:"error"}),o.jsxs("span",{children:["package",r!==1?"s":""," deprecated"]})]})]}):o.jsx("span",{className:"text-accent1",children:"✓ All packages are up to date"}),o.jsx(Oa,{content:c,copyMessage:"Copied package versions!",tooltip:"Copy current versions",size:"sm"})]}),o.jsx("div",{className:"max-h-64 overflow-y-auto border border-border1 rounded-md",children:o.jsx("div",{className:"grid grid-cols-[1fr_auto_auto] text-sm",children:e.map((u,d)=>o.jsxs("div",{className:K("contents",d>0&&"[&>div]:border-t [&>div]:border-border1"),children:[o.jsx("div",{className:"py-2 px-3 font-mono text-text1 truncate min-w-0",children:o.jsxs("a",{href:`https://www.npmjs.com/package/${u.name}`,target:"_blank",rel:"noopener noreferrer",className:"hover:text-accent1 hover:underline inline-flex items-center gap-1 group",children:[u.name,o.jsx(_a,{className:"w-3 h-3 opacity-0 group-hover:opacity-100 transition-opacity"})]})}),o.jsx("div",{className:"py-2 px-3 font-mono text-neutral3 flex items-center gap-1.5",children:u.isOutdated||u.isDeprecated?o.jsxs(Wn,{children:[o.jsx(zn,{asChild:!0,children:o.jsx("span",{className:K("cursor-help",u.isDeprecated?"text-red-500":u.isOutdated?"text-yellow-500":""),children:u.version})}),o.jsx(Bn,{children:u.isDeprecated?u.deprecationMessage||"This version is deprecated":"Newer version available"})]}):o.jsx("span",{children:u.version})}),o.jsx("div",{className:"py-2 px-3 font-mono text-neutral3 flex items-center",children:(u.isOutdated||u.isDeprecated)&&u.latestVersion&&o.jsxs(o.Fragment,{children:[o.jsx(ibe,{className:"w-4 h-4 mx-2 text-neutral3"}),o.jsx("span",{className:"text-accent1",children:u.latestVersion})]})})]},u.name))})}),l&&s&&o.jsxs("div",{className:"space-y-2 pt-2 border-t border-border1",children:[o.jsxs("div",{className:"flex items-center gap-2 pt-3",children:[o.jsx(Fx,{className:"w-4 h-4 text-neutral3"}),o.jsx(ge,{as:"span",variant:"ui-sm",className:"text-neutral3",children:"Use the command below to update your packages"})]}),o.jsx(v_e,{code:s,options:[{label:"pnpm",value:"pnpm"},{label:"npm",value:"npm"},{label:"yarn",value:"yarn"},{label:"bun",value:"bun"}],value:a,onValueChange:u=>{QAr(u)&&i(u)},copyMessage:"Copied update command!",copyTooltip:"Copy command"})]})]})]})},Qh=e=>o.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 34 21",fill:"none",...e,children:o.jsx("path",{d:"M4.49805 11.6934C6.98237 11.6934 8.99609 13.7081 8.99609 16.1924C8.9959 18.6765 6.98225 20.6904 4.49805 20.6904C2.01394 20.6903 0.000196352 18.6765 0 16.1924C0 13.7081 2.01382 11.6935 4.49805 11.6934ZM10.3867 0C12.8709 0 14.8846 2.01388 14.8848 4.49805C14.8848 4.8377 14.847 5.16846 14.7755 5.48643C14.4618 6.88139 14.1953 8.4633 14.9928 9.65L16.2575 11.5319C16.3363 11.6491 16.4727 11.7115 16.6137 11.703C16.7369 11.6957 16.8525 11.6343 16.9214 11.5318L18.1876 9.64717C18.9772 8.47198 18.7236 6.90783 18.4205 5.52484C18.3523 5.21392 18.3164 4.89094 18.3164 4.55957C18.3167 2.07546 20.3313 0.0615234 22.8154 0.0615234C25.2994 0.0617476 27.3132 2.0756 27.3135 4.55957C27.3135 4.93883 27.2665 5.30712 27.178 5.65896C26.8547 6.94441 26.5817 8.37932 27.2446 9.52714L28.459 11.6301C28.4819 11.6697 28.5245 11.6934 28.5703 11.6934C31.0545 11.6935 33.0684 13.7081 33.0684 16.1924C33.0682 18.6765 31.0544 20.6903 28.5703 20.6904C26.0861 20.6904 24.0725 18.6765 24.0723 16.1924C24.0723 15.8049 24.1212 15.4288 24.2133 15.0701C24.5458 13.7746 24.8298 12.3251 24.1609 11.1668L23.0044 9.16384C22.9656 9.09659 22.8931 9.05859 22.8154 9.05859C22.7983 9.05859 22.7824 9.06614 22.7728 9.08033L21.4896 10.9895C20.686 12.1851 20.9622 13.781 21.284 15.1851C21.3582 15.5089 21.3975 15.8461 21.3975 16.1924C21.3973 18.6764 19.3834 20.6902 16.8994 20.6904C14.4152 20.6904 12.4006 18.6765 12.4004 16.1924C12.4004 15.932 12.4226 15.6768 12.4651 15.4286C12.6859 14.14 12.8459 12.7122 12.1167 11.6271L11.2419 10.3253C10.6829 9.49347 9.71913 9.05932 8.78286 8.70188C7.0906 8.05584 5.88867 6.41734 5.88867 4.49805C5.88886 2.0139 7.90254 3.29835e-05 10.3867 0Z",fill:"currentColor"})}),tRr=()=>o.jsx("div",{className:"flex flex-col h-screen w-full items-center justify-center bg-surface1",children:o.jsxs("div",{className:"max-w-md w-full mx-auto px-4 pt-4",children:[o.jsx("div",{className:"flex items-center justify-center pb-4",children:o.jsx(Qh,{className:"size-32"})}),o.jsx(lRt,{})]})}),nRr=()=>{const{data:e,isLoading:t}=a4();return{hasObservability:!!(e?.observabilityEnabled??e?.packages?.some(r=>r.name==="@mastra/observability")),isLoading:t}},Y1=()=>{const{data:e,isLoading:t}=a4();return{isCmsAvailable:!!e?.cmsEnabled,isLoading:t}},Z_=e=>{const t=We(),n=Pl();return wt({queryKey:["memory",e,n],queryFn:()=>e?t.getMemoryStatus(e,n):null,enabled:!!e,staleTime:300*1e3,gcTime:600*1e3,retry:!1})},G_=e=>{const t=We(),n=Pl();return wt({queryKey:["memory","config",e,n],queryFn:()=>e?t.getMemoryConfig({agentId:e,requestContext:n}):null,enabled:!!e,staleTime:300*1e3,gcTime:600*1e3,retry:!1,refetchOnWindowFocus:!1})},pRt=({threadId:e,agentId:t})=>{const n=We(),r=Pl();return wt({queryKey:["memory","thread",e,t,r],queryFn:()=>n.getMemoryThread({threadId:e,agentId:t}).get({requestContext:r}),enabled:!!e&&e!=="new"&&!!t,staleTime:300*1e3,gcTime:600*1e3,retry:!1,refetchOnWindowFocus:!1})},hRt=({resourceId:e,agentId:t,isMemoryEnabled:n})=>{const r=We(),s=Pl();return wt({queryKey:["memory","threads",e,t,s],queryFn:async()=>n?(await r.listMemoryThreads({resourceId:e,agentId:t,requestContext:s})).threads:null,enabled:!!n,staleTime:0,gcTime:0,retry:!1,refetchOnWindowFocus:!1})},rRr=()=>{const e=We(),t=Hr(),n=Pl();return Rn({mutationFn:({threadId:r,agentId:s})=>e.getMemoryThread({threadId:r,agentId:s}).delete({requestContext:n}),onSuccess:(r,s)=>{const{agentId:a}=s;a&&t.invalidateQueries({queryKey:["memory","threads",a,a]}),De.success("Chat deleted successfully")},onError:()=>{De.error("Failed to delete chat")}})},sRr=({agentId:e,resourceId:t,threadId:n})=>{const r=Pl(),s=We();return Rn({mutationFn:async({searchQuery:a,memoryConfig:i})=>s.searchMemory({agentId:e,resourceId:t,threadId:n,searchQuery:a,memoryConfig:i,requestContext:r})})},aRr=()=>{const e=We(),t=Hr(),n=Pl();return Rn({mutationFn:async({threadId:r,agentId:s,title:a})=>e.getMemoryThread({threadId:r,agentId:s}).clone({title:a,requestContext:n}),onSuccess:(r,s)=>{const{agentId:a}=s;a&&t.invalidateQueries({queryKey:["memory","threads",a,a]}),De.success("Thread cloned successfully")},onError:()=>{De.error("Failed to clone thread")}})},iRr=({agentId:e,resourceId:t,threadId:n,enabled:r=!0,isActive:s=!1})=>{const a=We(),i=Pl();return wt({queryKey:["observational-memory",e,t,n,i],queryFn:async()=>!t&&!n?null:a.getObservationalMemory({agentId:e,resourceId:t,threadId:n,requestContext:i}),enabled:r&&!!e&&(!!t||!!n),staleTime:s?1e3:30*1e3,gcTime:300*1e3,retry:!1,refetchOnWindowFocus:!1,refetchInterval:s?2e3:!1,placeholderData:l=>l})},mRt=({agentId:e,resourceId:t,threadId:n,pollWhenActive:r=!0})=>{const s=We(),a=Pl(),[i,l]=g.useState(!1),c=wt({queryKey:["memory-status",e,t,n,a],queryFn:()=>e?s.getMemoryStatus(e,a,{resourceId:t,threadId:n}):null,enabled:!!e,staleTime:i&&r?1e3:30*1e3,gcTime:300*1e3,retry:!1,refetchOnWindowFocus:!1,refetchInterval:i&&r?2e3:!1,placeholderData:f=>f}),u=c.data?.observationalMemory?.isObserving,d=c.data?.observationalMemory?.isReflecting;return g.useEffect(()=>{l(u||d||!1)},[u,d]),c},oRr={purple:{icon:"text-purple-700 dark:text-purple-300"},amber:{icon:"text-amber-700 dark:text-amber-300"},emerald:{icon:"text-emerald-700 dark:text-emerald-300"},sky:{icon:"text-sky-700 dark:text-sky-300"},cyan:{icon:"text-cyan-700 dark:text-cyan-300"},orange:{icon:"text-orange-700 dark:text-orange-300"}},$j=e=>e?Object.keys(e).length:0,NW=e=>e>0?String(e):"Off",gRt=e=>(e?.inputProcessors?.length??0)+(e?.outputProcessors?.length??0),vRt=e=>!!e?.result,yRt=(e,t)=>!!(t&&e&&e.editor!==!1);function yI({view:e,label:t,status:n,description:r,docsHref:s,enabled:a,tone:i,icon:l}){const c=oRr[i].icon;return e==="chip"?o.jsx("span",{"aria-label":`${t}: ${n}`,className:K("pointer-events-none inline-flex h-5 min-w-5 items-center justify-center rounded-full px-1 text-neutral3",a?c:void 0),children:o.jsx("span",{className:"size-3 shrink-0 [&>svg]:size-3",children:l})}):o.jsxs("a",{"aria-label":`${t}: ${n}`,href:s,target:"_blank",rel:"noopener noreferrer",className:K("group/capability-row flex min-w-0 items-start gap-2 rounded-md px-2 py-1.5 text-ui-xs text-neutral4 transition-colors duration-normal","hover:bg-surface4/60 hover:text-neutral6 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-border2"),children:[o.jsx("span",{className:K("mt-0.5 size-3.5 shrink-0 text-neutral3 transition-colors duration-normal [&>svg]:size-3.5",a?c:"group-hover/capability-row:text-neutral5"),children:l}),o.jsxs("span",{className:"min-w-0 flex-1",children:[o.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[o.jsx("span",{className:"min-w-0 truncate font-medium text-neutral5",children:t}),o.jsx("span",{className:"shrink-0 tabular-nums text-neutral3",children:n})]}),o.jsx("span",{className:"mt-0.5 block text-neutral3 transition-colors duration-normal group-hover/capability-row:text-neutral4",children:r})]}),o.jsx(_a,{className:"mt-0.5 size-3 shrink-0 text-neutral3 transition-colors duration-normal group-hover/capability-row:text-neutral5"})]})}function uWe({agentId:e,view:t}){const{data:n,isLoading:r}=Z_(e),s=vRt(n),a=s?n?.memoryType==="gateway"?"Gateway":"On":"Off",i=r?"Checking":a;return o.jsx(yI,{view:t,label:"Memory",status:i,description:s?"Conversation history and configured memory features are available for this agent.":"This agent has no memory configured, so conversations are not saved as memory-backed threads.",docsHref:"https://mastra.ai/docs/memory/overview",enabled:s,tone:"purple",icon:o.jsx(H3,{})})}function dWe({agentId:e,view:t}){const{data:n,isLoading:r}=vl(e),{isCmsAvailable:s,isLoading:a}=Y1(),i=yRt(n,s),l=n?.editor===!1,c=Q1({agentId:e,params:{orderBy:{field:"createdAt",direction:"DESC"}},enabled:i}),u=c.data?.total??c.data?.versions.length??0,d=r||a||i&&c.isLoading,f=u>0?String(u):"Ready",h=d?"Checking":i?f:l?"Locked":"Off",v=i?"Editor is available for versioned agent overrides.":l?"This code-defined agent explicitly disables editor overrides.":"Register MastraEditor to enable versioned agent overrides.";return o.jsx(yI,{view:t,label:"Editor",status:h,description:v,docsHref:"https://mastra.ai/docs/editor/overview",enabled:i,tone:"amber",icon:o.jsx(Lp,{})})}function fWe({agentId:e,view:t}){const{data:n,isLoading:r}=vl(e),s=$j(n?.tools);return o.jsx(yI,{view:t,label:"Tools",status:r?"Checking":NW(s),description:s>0?`${s} tool${s===1?"":"s"} available.`:"No tools are configured.",docsHref:"https://mastra.ai/docs/agents/using-tools-and-mcp",enabled:s>0,tone:"emerald",icon:o.jsx(zp,{})})}function pWe({agentId:e,view:t}){const{data:n,isLoading:r}=vl(e),s=$j(n?.workflows);return o.jsx(yI,{view:t,label:"Workflows",status:r?"Checking":NW(s),description:s>0?`${s} workflow${s===1?"":"s"} available.`:"No workflows are attached to this agent.",docsHref:"https://mastra.ai/docs/workflows/overview",enabled:s>0,tone:"sky",icon:o.jsx(vD,{})})}function hWe({agentId:e,view:t}){const{data:n,isLoading:r}=vl(e),s=$j(n?.agents);return o.jsx(yI,{view:t,label:"Sub-agents",status:r?"Checking":NW(s),description:s>0?`${s} sub-agent${s===1?"":"s"} available.`:"No sub-agents are attached to this agent.",docsHref:"https://mastra.ai/docs/agents/supervisor-agents",enabled:s>0,tone:"cyan",icon:o.jsx(EF,{})})}function mWe({agentId:e,view:t}){const{data:n,isLoading:r}=vl(e),s=gRt(n);return o.jsx(yI,{view:t,label:"Processors",status:r?"Checking":NW(s),description:s>0?`${s} input/output processor${s===1?"":"s"} configured.`:"No input or output processors are configured.",docsHref:"https://mastra.ai/docs/agents/processors",enabled:s>0,tone:"orange",icon:o.jsx(hq,{})})}function lRr({agentId:e}){const{data:t}=Z_(e),{data:n}=vl(e),{isCmsAvailable:r}=Y1(),s=[vRt(t),yRt(n,r),$j(n?.tools)>0,$j(n?.workflows)>0,$j(n?.agents)>0,gRt(n)>0],a=s.filter(Boolean).length;return o.jsxs(ge,{as:"span",variant:"ui-xs",className:"shrink-0 text-neutral3",children:[a,"/",s.length]})}function cRr({agentId:e}){const[t,n]=g.useState(!1);return o.jsx(xf,{open:t,onOpenChange:n,children:o.jsxs("div",{className:"shrink-0 border-t border-border1/50",children:[o.jsx(Od,{asChild:!0,"aria-label":t?"Hide capability details":"Show capability details",children:o.jsxs("button",{type:"button","data-testid":"agent-capabilities-footer",className:"flex w-full cursor-pointer items-center gap-1.5 px-2 py-2 text-left text-neutral4 transition-colors duration-normal hover:!text-neutral4 hover:bg-surface4 focus-visible:!text-neutral4 focus-visible:bg-surface4 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-border2 active:bg-surface5/80 aria-expanded:bg-surface4/70 data-[panel-open]:bg-surface4/70",children:[o.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-1.5 overflow-hidden",children:[o.jsx(uWe,{agentId:e,view:"chip"}),o.jsx(dWe,{agentId:e,view:"chip"}),o.jsx(fWe,{agentId:e,view:"chip"}),o.jsx(pWe,{agentId:e,view:"chip"}),o.jsx(hWe,{agentId:e,view:"chip"}),o.jsx(mWe,{agentId:e,view:"chip"})]}),o.jsx(lRr,{agentId:e}),o.jsx(ta,{className:K("size-3.5 shrink-0 text-neutral3 transition-transform duration-normal ease-out-custom",t?"rotate-90":void 0)})]})}),o.jsx(_d,{className:"px-2 pb-2",children:o.jsxs("div",{className:"grid gap-1",children:[o.jsx(uWe,{agentId:e,view:"row"}),o.jsx(dWe,{agentId:e,view:"row"}),o.jsx(fWe,{agentId:e,view:"row"}),o.jsx(pWe,{agentId:e,view:"row"}),o.jsx(hWe,{agentId:e,view:"row"}),o.jsx(mWe,{agentId:e,view:"row"})]})})]})})}const gWe=(e,t)=>e?typeof e=="number"?e:e.max:t;function bRt({record:e,liveProgress:t,agentConfig:n}){const r=e?.config,s=t?.windows?.active?.messages?.threshold??r?.observation?.messageTokens??gWe(n?.messageTokens,3e4),a=t?.windows?.active?.observations?.threshold??r?.reflection?.observationTokens??gWe(n?.observationTokens,4e4),i=t?.windows?.active?.messages?.tokens??e?.pendingMessageTokens??0,l=t?.windows?.active?.observations?.tokens??e?.observationTokenCount??0;return{messageTokens:i,messageThreshold:s,observationTokens:l,observationThreshold:a}}const vWe={modelSettings:{maxRetries:2,maxSteps:15,chatWithGenerateLegacy:!1,chatWithGenerate:!1,chatWithLegacyStream:!1}};function uRr({agentId:e,defaultSettings:t}){const[n,r]=g.useState(t),s=`mastra-agent-store-${e}`;return g.useEffect(()=>{try{const l=localStorage.getItem(s),c=l?JSON.parse(l):{},u={...c,modelSettings:{...vWe.modelSettings,...c?.modelSettings??{},...t?.modelSettings??{}}};r(u)}catch{}},[s,t]),{settings:n,setSettings:l=>{r(c=>({...c,...l})),localStorage.setItem(s,JSON.stringify({...l,agentId:e}))},resetAll:()=>{const l={modelSettings:{...vWe.modelSettings,...t?.modelSettings??{}}};r(l),localStorage.removeItem(s)}}}const xRt=g.createContext({});function O_e({children:e,agentId:t,defaultSettings:n}){const{settings:r,setSettings:s,resetAll:a}=uRr({agentId:t,defaultSettings:n});return o.jsx(xRt.Provider,{value:{settings:r,setSettings:s,resetAll:a},children:e})}const __e=()=>g.useContext(xRt);function yWe(e){try{return JSON.stringify(JSON.parse(e),null,2)}catch{return e}}function dRr(e,t,n){const r=We(),[s,a]=g.useState(!1),[i,l]=g.useState(null),[c,u]=g.useState("thread"),[d,f]=g.useState("markdown"),[p,h]=g.useState(!0),[m,v]=g.useState(!1),{requestContext:y}=_s(),b=g.useCallback(async()=>{h(!0);try{if(!e||!t){l(null),h(!1);return}const w=await r.getWorkingMemory({agentId:e,threadId:t,resourceId:n,requestContext:y}),{workingMemory:k,source:_,workingMemoryTemplate:C,threadExists:E}=w;if(a(E),l(k),u(_),f(C?.format||"markdown"),C?.format==="json"){let j="";k?j=yWe(k):C?.content?j=yWe(C.content):j="",l(j)}else l(k||C?.content||"")}catch(w){l(null),console.error("Error fetching working memory",w)}finally{h(!1)}},[e,t,n]);return g.useEffect(()=>{b()},[b]),{threadExists:s,workingMemoryData:i,workingMemorySource:c,workingMemoryFormat:d,isLoading:p,isUpdating:m,refetch:b,updateWorkingMemory:async w=>{v(!0);try{if(d==="json")try{JSON.parse(w)}catch{throw new Error("Invalid JSON working memory")}await r.updateWorkingMemory({agentId:e,threadId:t,workingMemory:w,resourceId:n,requestContext:y}),b()}catch(k){throw console.error("Error updating working memory",k),k}finally{v(!1)}}}}const wRt=g.createContext({threadExists:!1,workingMemoryData:null,workingMemorySource:"thread",isLoading:!1,isUpdating:!1,updateWorkingMemory:()=>Promise.resolve(),refetch:()=>Promise.resolve()});function SRt({agentId:e,threadId:t,resourceId:n,children:r}){const s=dRr(e,t,n);return o.jsx(wRt.Provider,{value:s,children:r})}function kRt(){const e=g.useContext(wRt);if(!e)throw new Error("useWorkingMemory must be used within a WorkingMemoryProvider");return e}const ORt=g.createContext(null);function _Rt({children:e}){const[t,n]=g.useState(!1),[r,s]=g.useState(!1),[a,i]=g.useState(0),[l,c]=g.useState(null),[u,d]=g.useState(new Set),f=g.useCallback(()=>{i(Date.now())},[]),p=g.useCallback(m=>{d(v=>new Set([...v,m]))},[]),h=g.useCallback(()=>{n(!1),s(!1),d(new Set)},[]);return o.jsx(ORt.Provider,{value:{isObservingFromStream:t,setIsObservingFromStream:n,isReflectingFromStream:r,setIsReflectingFromStream:s,observationsUpdatedAt:a,signalObservationsUpdated:f,streamProgress:l,setStreamProgress:c,activatedCycleIds:u,markCycleIdActivated:p,clearProgress:h},children:e})}function IW(){const e=g.useContext(ORt);return e||{isObservingFromStream:!1,setIsObservingFromStream:()=>{},isReflectingFromStream:!1,setIsReflectingFromStream:()=>{},observationsUpdatedAt:0,signalObservationsUpdated:()=>{},streamProgress:null,setStreamProgress:()=>{},activatedCycleIds:new Set,markCycleIdActivated:()=>{},clearProgress:()=>{}}}const CRt=g.createContext(null),fRr={isPanelOpen:!1,openPanel:()=>{},closePanel:()=>{},selectedTimestamp:null,setSelectedTimestamp:()=>{}};function pRr({children:e}){const[t,n]=g.useState(!1),[r,s]=g.useState(null),a=g.useCallback(()=>n(!0),[]),i=g.useCallback(()=>n(!1),[]),l=g.useMemo(()=>({isPanelOpen:t,openPanel:a,closePanel:i,selectedTimestamp:r,setSelectedTimestamp:s}),[t,a,i,r]);return o.jsx(CRt.Provider,{value:l,children:e})}function AW(){return g.useContext(CRt)??fRr}const ERt=g.createContext(null);function C_e({children:e}){const[t,n]=g.useState(new Set),r=g.useCallback(l=>{n(c=>{if(c.has(l))return c;const u=new Set(c);return u.add(l),u})},[]),s=g.useCallback(l=>{n(c=>{const u=new Set(c);return u.delete(l),u})},[]),a=g.useCallback(l=>t.has(l),[t]),i=g.useCallback(()=>{n(new Set)},[]);return o.jsx(ERt.Provider,{value:{activatedSkills:t,activateSkill:r,deactivateSkill:s,isSkillActivated:a,clearActivatedSkills:i},children:e})}const hRr={activatedSkills:new Set,activateSkill:()=>{},deactivateSkill:()=>{},isSkillActivated:()=>!1,clearActivatedSkills:()=>{}};function jRt(){return g.useContext(ERt)??hRr}const E_e=g.createContext(null);function j_e({children:e,...t}){return o.jsx(E_e.Provider,{value:t,children:e})}function Fo(){const e=g.useContext(E_e);if(!e)throw new Error("useAgentEditFormContext must be used within an AgentEditFormProvider");return e}function TRt(){return g.useContext(E_e)}const NRt=g.createContext(null);function mRr({children:e,defaultProvider:t="",defaultModel:n=""}){const[r,s]=g.useState(t),[a,i]=g.useState(n);return g.useEffect(()=>{t&&!r&&s(t)},[t]),g.useEffect(()=>{n&&!a&&i(n)},[n]),o.jsx(NRt.Provider,{value:{provider:r,model:a,setProvider:s,setModel:i},children:e})}function T_e(){const e=g.useContext(NRt);if(!e)throw new Error("usePlaygroundModel must be used within a PlaygroundModelProvider");return e}const Ei=()=>{const e=We(),t=Hr(),n=Rn({mutationFn:m=>e.createDataset(m),onSuccess:()=>{t.invalidateQueries({queryKey:["datasets"]})}}),r=Rn({mutationFn:m=>e.updateDataset(m),onSuccess:(m,v)=>{t.invalidateQueries({queryKey:["datasets"]}),t.invalidateQueries({queryKey:["dataset",v.datasetId]})}}),s=Rn({mutationFn:m=>e.deleteDataset(m),onSuccess:()=>{t.invalidateQueries({queryKey:["datasets"]})}}),a=Rn({mutationFn:m=>e.addDatasetItem(m),onSuccess:(m,v)=>{t.invalidateQueries({queryKey:["dataset-items",v.datasetId]}),t.invalidateQueries({queryKey:["dataset",v.datasetId]})}}),i=Rn({mutationFn:m=>e.updateDatasetItem(m),onSuccess:(m,v)=>{t.invalidateQueries({queryKey:["dataset-items",v.datasetId]}),t.invalidateQueries({queryKey:["dataset-item",v.datasetId,v.itemId]}),t.invalidateQueries({queryKey:["dataset-item-versions",v.datasetId,v.itemId]}),t.invalidateQueries({queryKey:["dataset-versions",v.datasetId]})}}),l=Rn({mutationFn:({datasetId:m,itemId:v})=>e.deleteDatasetItem(m,v),onSuccess:(m,v)=>{t.invalidateQueries({queryKey:["dataset-items",v.datasetId]}),t.invalidateQueries({queryKey:["dataset",v.datasetId]})}}),c=Rn({mutationFn:m=>e.batchInsertDatasetItems(m),onSuccess:(m,v)=>{t.invalidateQueries({queryKey:["dataset-items",v.datasetId]}),t.invalidateQueries({queryKey:["dataset",v.datasetId]}),t.invalidateQueries({queryKey:["dataset-versions",v.datasetId]})}}),u=Rn({mutationFn:m=>e.batchDeleteDatasetItems(m),onSuccess:(m,v)=>{t.invalidateQueries({queryKey:["dataset-items",v.datasetId]}),t.invalidateQueries({queryKey:["dataset",v.datasetId]}),t.invalidateQueries({queryKey:["dataset-versions",v.datasetId]})}}),d=Rn({mutationFn:async({datasetId:m,itemIds:v})=>e.batchDeleteDatasetItems({datasetId:m,itemIds:v}),onSuccess:(m,v)=>{t.invalidateQueries({queryKey:["dataset-items",v.datasetId]}),t.invalidateQueries({queryKey:["dataset",v.datasetId]}),t.invalidateQueries({queryKey:["dataset-versions",v.datasetId]})}}),f=Rn({mutationFn:m=>e.generateDatasetItems(m)}),p=Rn({mutationFn:m=>e.triggerDatasetExperiment(m),onSuccess:(m,v)=>{t.invalidateQueries({queryKey:["dataset-experiments",v.datasetId]})}}),h=Rn({mutationFn:m=>e.updateDatasetExperimentResult(m),onSuccess:(m,v)=>{t.invalidateQueries({queryKey:["experiment-results",v.experimentId]}),t.invalidateQueries({queryKey:["dataset-experiment-results"]}),t.invalidateQueries({queryKey:["review-items"]}),t.invalidateQueries({queryKey:["dataset-review-items"]}),t.invalidateQueries({queryKey:["dataset-completed-items"]}),t.invalidateQueries({queryKey:["experiment-review-summary"]})}});return{createDataset:n,updateDataset:r,deleteDataset:s,addItem:a,updateItem:i,deleteItem:l,deleteItems:d,batchInsertItems:c,batchDeleteItems:u,generateItems:f,triggerExperiment:p,updateExperimentResult:h}},IRt=g.createContext(null);function gRr({children:e}){const[t,n]=g.useState([]),[r,s]=g.useState([]),[a,i]=g.useState(null),{updateExperimentResult:l}=Ei(),c=We(),u=g.useCallback(S=>{n(w=>{const k=new Set(w.map(C=>C.itemId)),_=S.filter(C=>!k.has(C.itemId));return[...w,..._.map((C,E)=>({...C,id:C.id||`review-${Date.now()}-${E}`,tags:C.tags??[]}))]})},[]),d=g.useCallback(S=>{n(w=>{const k=new Map(S.map(C=>[C.id,C])),_=w.filter(C=>!k.has(C.id));return[...S,..._]})},[]),f=g.useCallback(S=>{const w=t.find(k=>k.id===S);w?.experimentId&&w?.datasetId&&l.mutate({datasetId:w.datasetId,experimentId:w.experimentId,resultId:w.id,status:null}),n(k=>k.filter(_=>_.id!==S))},[t,l]),p=g.useCallback(async S=>{const w=t.find(k=>k.id===S);w?.experimentId&&w?.datasetId&&await l.mutateAsync({datasetId:w.datasetId,experimentId:w.experimentId,resultId:w.id,status:"complete"}),n(k=>k.filter(_=>_.id!==S))},[t,l]),h=g.useCallback((S,w)=>{const k=t.find(_=>_.id===S);k?.experimentId&&k?.datasetId&&l.mutate({datasetId:k.datasetId,experimentId:k.experimentId,resultId:k.id,tags:w}),n(_=>_.map(C=>C.id===S?{...C,tags:w}:C))},[t,l]),m=g.useCallback((S,w)=>{const k=t.find(_=>_.id===S);k?.traceId&&w!==void 0&&c.createFeedback({feedback:{traceId:k.traceId,source:"studio",feedbackSource:"studio",feedbackType:"rating",value:w==="positive"?1:-1,experimentId:k.experimentId??void 0,sourceId:k.id}}).catch(()=>{}),n(_=>_.map(C=>C.id===S?{...C,rating:w}:C))},[t,c]),v=g.useCallback((S,w)=>{const k=t.find(_=>_.id===S);k?.traceId&&c.createFeedback({feedback:{traceId:k.traceId,source:"studio",feedbackSource:"studio",feedbackType:"comment",value:w,comment:w,experimentId:k.experimentId??void 0,sourceId:k.id}}).catch(()=>{}),n(_=>_.map(C=>C.id===S?{...C,comment:w}:C))},[t,c]),y=g.useCallback((S,w)=>{n(k=>k.map(_=>_.id===S?{..._,clusterId:w}:_))},[]),b=g.useCallback(()=>{n([]),s([]),i(null)},[]);return o.jsx(IRt.Provider,{value:{items:t,clusters:r,activeClusterId:a,addItems:u,removeItem:f,completeItem:p,setItemTags:h,rateItem:m,commentItem:v,setClusters:s,setActiveClusterId:i,assignCluster:y,clearAll:b,loadPersistedItems:d},children:e})}function ARt(){const e=g.useContext(IRt);if(!e)throw new Error("useReviewQueue must be used within ReviewQueueProvider");return e}const V0=e=>e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e5?`${(e/1e3).toFixed(0)}k`:e>=1e3?`${(e/1e3).toFixed(1)}k`:Math.round(e).toString(),vRr=e=>e>=60?"bg-blue-500":"bg-green-500",bWe=(e,t)=>{if(typeof e=="string")return e;if(t?.length)return"Auto (tiered)"},yRr=(e,t)=>e?typeof e=="number"?e:e.max:t,xWe=(e,t)=>e?typeof e=="number"?e:e.min:t,bRr=e=>{const[t,n]=g.useState({isActive:e,elapsed:0}),r=g.useRef(null);return t.isActive!==e&&(r.current=e?Date.now():null,n({isActive:e,elapsed:0})),g.useEffect(()=>{if(!e)return;r.current||(r.current=Date.now());const s=setInterval(()=>{const a=r.current;a&&n(i=>({...i,elapsed:(Date.now()-a)/1e3}))},100);return()=>clearInterval(s)},[e]),t.isActive===e?t.elapsed:0},wWe=({value:e,max:t,label:n,isActive:r=!1,model:s,modelRouting:a,baseThreshold:i,totalBudget:l})=>{const c=i!==void 0&&l!==void 0,u=t>0?Math.min(100,Math.max(0,e/t*100)):0,d=vRr(u),f=bRr(r&&u>=100),p=r&&u>=100,h=n==="Messages"?"observing":"reflecting",m=c&&u>=100&&!p&&i&&e<i,v=p?"bg-transparent":"bg-surface4",y=p?"bg-blue-500/10":d,b=p?"text-blue-600":"text-neutral4",S=p?"text-blue-600":"text-white",w=p?"bg-blue-500/10":"bg-surface5",k=p?"text-blue-600":"text-neutral3";return o.jsxs("div",{className:"flex-1 min-w-0",children:[o.jsxs("div",{className:"flex items-center gap-1 mb-1 h-4",children:[o.jsx("span",{className:"text-[9px] text-neutral4 uppercase tracking-wider font-normal",children:n}),o.jsxs(Wn,{children:[o.jsx(zn,{asChild:!0,children:o.jsx("button",{type:"button",className:"inline-flex items-center justify-center",children:o.jsx(Fx,{className:"w-2.5 h-2.5 text-neutral4 hover:text-neutral3 cursor-help"})})}),o.jsx(Bn,{side:"top",className:"max-w-xs bg-surface3 border border-border1 text-foreground",children:o.jsxs("div",{className:"text-xs space-y-1.5",children:[o.jsxs("div",{className:"font-medium text-neutral5",children:[n==="Messages"?"Observer":"Reflector"," Settings"]}),o.jsxs("div",{className:"space-y-0.5",children:[o.jsxs("div",{children:[o.jsx("span",{className:"text-neutral4",children:"Model:"})," ",o.jsx("span",{className:"text-neutral5",children:s||"not configured"})]}),a?.length?o.jsxs("div",{children:[o.jsx("span",{className:"text-neutral4",children:"Routing:"}),o.jsx("div",{className:"mt-0.5 pl-2 space-y-0.5",children:a.map(_=>o.jsxs("div",{className:"text-neutral5",children:["≤",V0(_.upTo)," → ",_.model]},`${_.upTo}-${_.model}`))})]}):o.jsxs("div",{children:[o.jsx("span",{className:"text-neutral4",children:"Threshold:"})," ",o.jsxs("span",{className:"text-neutral5",children:[V0(i??t)," tokens"]})]}),c&&l&&o.jsxs("div",{children:[o.jsx("span",{className:"text-neutral4",children:"Mode:"})," ",o.jsx("span",{className:"text-amber-400",children:"Adaptive"})," ",o.jsxs("span",{className:"text-neutral4",children:["(",V0(l)," shared budget)"]})]})]})]})})]})]}),o.jsxs("div",{className:"flex items-stretch",children:[o.jsxs("div",{className:`relative flex-1 h-5 ${v} rounded-l overflow-hidden`,children:[o.jsx("div",{className:`h-full ${y} transition-all`,style:{width:`${u}%`}}),o.jsx("span",{className:`absolute inset-0 flex items-center ${p?"justify-start pl-2":"justify-center"} text-[10px] font-medium ${b} pointer-events-none`,children:p?`${h} ${f.toFixed(1)}s`:m?"adaptive":`${Math.round(u)}%`}),o.jsx("span",{className:`absolute inset-0 flex items-center ${p?"justify-start pl-2":"justify-center"} text-[10px] font-medium ${S} pointer-events-none`,style:{clipPath:`inset(0 ${100-u}% 0 0)`},children:p?`${h} ${f.toFixed(1)}s`:m?"adaptive":`${Math.round(u)}%`})]}),o.jsxs("span",{className:`text-[10px] ${k} tabular-nums whitespace-nowrap font-mono ${w} px-1.5 flex items-center gap-1 rounded-r -ml-px`,children:[V0(e),o.jsxs("span",{className:p?"text-blue-500":"text-neutral4",children:["/",V0(t)]}),c&&l&&o.jsxs(Wn,{children:[o.jsx(zn,{asChild:!0,children:o.jsxs("span",{className:"text-amber-400 cursor-help",children:["(",V0(i),")"]})}),o.jsx(Bn,{side:"top",className:"max-w-xs bg-surface3 border border-border1 text-foreground",children:o.jsxs("div",{className:"text-xs",children:[o.jsx("span",{className:"text-amber-400",children:V0(i)}),o.jsx("span",{className:"text-neutral4",children:" is the configured threshold. "}),o.jsxs("span",{className:"text-neutral5",children:["Adaptive mode shares a ",V0(l)," token budget between messages and observations."]})]})})]})]})]})]})},xRr=()=>o.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[o.jsx(Rv,{className:"w-4 h-4 text-purple-400"}),o.jsx("h3",{className:"text-sm font-medium text-neutral5",children:"Observational Memory"})]}),wRr=()=>o.jsxs("div",{className:"p-4",children:[o.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[o.jsx(Rv,{className:"w-4 h-4 text-neutral3"}),o.jsx("h3",{className:"text-sm font-medium text-neutral5",children:"Observational Memory"})]}),o.jsxs("div",{className:"bg-surface3 border border-border1 rounded-lg p-4",children:[o.jsx("p",{className:"text-sm text-neutral3 mb-3",children:"Observational Memory is not enabled for this agent. Enable it to automatically extract and maintain observations from conversations."}),o.jsxs("a",{href:"https://mastra.ai/en/docs/memory/observational-memory",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-2 text-sm text-blue-400 hover:text-blue-300 transition-colors",children:["Learn about Observational Memory",o.jsx(_a,{className:"w-3 h-3"})]})]})]});function SRr({pendingMessageTokens:e,messageTokensThreshold:t,isObserving:n,observationModel:r,observationModelRouting:s,baseMessageTokens:a,totalBudget:i,observationTokenCount:l,observationTokensThreshold:c,isReflecting:u,baseObservationTokens:d,reflectionModel:f,reflectionModelRouting:p}){return o.jsx(sc,{delayDuration:0,children:o.jsxs("div",{className:"flex gap-3 mb-3",children:[o.jsx(wWe,{value:e,max:t,label:"Messages",isActive:n,model:r,modelRouting:s,baseThreshold:a,totalBudget:i}),o.jsx(wWe,{value:l,max:c,label:"Observations",isActive:u,baseThreshold:d,model:f,modelRouting:p,totalBudget:i})]})})}const kRr=({agentId:e,resourceId:t,threadId:n})=>{const{isPanelOpen:r,openPanel:s,closePanel:a}=AW(),{isObservingFromStream:i,isReflectingFromStream:l,streamProgress:c,clearProgress:u}=IW();g.useEffect(()=>{u()},[n,u]);const d=c?.threadId===n?c:null,{data:f}=G_(e),{data:p,isLoading:h}=mRt({agentId:e,resourceId:t,threadId:n}),m=120*1e3,v=p?.observationalMemory?.lastObservedAt,y=v?Date.now()-new Date(v).getTime()>m:!0,b=i||l,S=!y&&!b&&(p?.observationalMemory?.isObserving||!1),w=!y&&!b&&(p?.observationalMemory?.isReflecting||!1),k=i||S,_=l||w,C=k||_,{data:E,isLoading:j}=iRr({agentId:e,resourceId:t,threadId:n,enabled:!!p?.observationalMemory?.enabled,isActive:C}),N=h||j,I=p?.observationalMemory?.enabled??!1,R=E?.record,P=f?.config?.observationalMemory,L=R?.config,M=L?.observationModelRouting??L?.observation?.routing??P?.observationModelRouting??P?.observation?.routing,q=L?.reflectionModelRouting??L?.reflection?.routing??P?.reflectionModelRouting??P?.reflection?.routing,H=bWe(L?.observationModel??L?.observation?.model??P?.observationModel??P?.model??P?.observation?.model,M),F=bWe(L?.reflectionModel??L?.reflection?.model??P?.reflectionModel??P?.model??P?.reflection?.model,q),z=P?.messageTokens!==void 0&&typeof P.messageTokens!="number",B=z?yRr(P?.messageTokens,3e4):0,D=z?xWe(P?.messageTokens,3e4):void 0,Q=z?xWe(P?.observationTokens,4e4):void 0,{messageTokens:V,messageThreshold:$,observationTokens:U,observationThreshold:Z}=bRt({record:R,liveProgress:d,agentConfig:P});return N?o.jsx("div",{className:"p-4",children:o.jsx(bt,{className:"h-32 w-full"})}):I?o.jsxs("div",{className:"p-4 overflow-hidden min-w-0 w-full",children:[o.jsx(xRr,{}),o.jsx(SRr,{pendingMessageTokens:V,messageTokensThreshold:$,isObserving:k,observationModel:H,observationModelRouting:M,baseMessageTokens:D,totalBudget:B,observationTokenCount:U,observationTokensThreshold:Z,isReflecting:_,baseObservationTokens:Q,reflectionModel:F,reflectionModelRouting:q}),o.jsxs(de,{size:"sm",className:"w-full justify-center gap-2",onClick:()=>r?a():s(),children:[o.jsx(Rv,{className:"h-3.5 w-3.5"}),"Analyze Observations"]})]}):o.jsx(wRr,{})};function ORr({content:e,height:t="150px",isCopied:n=!1,isDraft:r=!1,onCopy:s,className:a=""}){return o.jsx("div",{className:`rounded-md border ${a}`,style:{height:t},children:o.jsx(Yr,{className:"h-full",children:o.jsxs("div",{className:`p-2 transition-colors group relative ${s?"cursor-pointer hover:bg-surface4/50":""}`,children:[s&&o.jsx("button",{type:"button",onClick:s,"aria-label":"Copy code",className:"absolute inset-0 z-10 rounded-md focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-accent1"}),o.jsx("pre",{className:"text-ui-xs whitespace-pre-wrap font-mono pointer-events-none",children:e}),r&&o.jsx("div",{className:"mt-1.5",children:o.jsx("span",{className:"text-ui-xs px-1.5 py-0.5 rounded-full bg-yellow-500/20 text-yellow-500",children:"Draft - Save changes to apply"})}),n&&o.jsx("span",{className:"absolute top-2 right-2 z-20 text-ui-xs px-1.5 py-0.5 rounded-full bg-green-500/20 text-green-500 pointer-events-none",children:"Copied!"}),s&&o.jsx("span",{className:"absolute top-2 right-2 z-20 text-ui-xs px-1.5 py-0.5 rounded-full bg-surface4 text-neutral4 opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none",children:"Click to copy"})]})})})}const _Rr=({agentId:e})=>{const{threadExists:t,workingMemoryData:n,workingMemorySource:r,isLoading:s,isUpdating:a,updateWorkingMemory:i}=kRt(),{data:l,isLoading:c}=G_(e),d=!!l?.config?.workingMemory?.enabled,{isCopied:f,handleCopy:p}=Bp({text:n??"",copyMessage:"Working memory copied!"}),[h,m]=g.useState({source:n,value:n??""}),[v,y]=g.useState(!1);return!v&&h.source!==n&&m({source:n,value:n??""}),s||c?o.jsx(bt,{className:"h-32 w-full"}):o.jsxs("div",{className:"flex flex-col gap-4 p-4",children:[o.jsxs("div",{children:[o.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[o.jsx("h3",{className:"text-sm font-medium text-neutral5",children:"Working Memory"}),d&&r&&o.jsx("span",{className:K("text-xs font-medium px-2 py-0.5 rounded",r==="resource"?"bg-purple-500/20 text-purple-400":"bg-blue-500/20 text-blue-400"),title:r==="resource"?"Shared across all threads for this agent":"Specific to this conversation thread",children:r})]}),d&&!t&&o.jsx("p",{className:"text-xs text-neutral3",children:"Send a message to the agent to enable working memory."})]}),d?o.jsxs(o.Fragment,{children:[v?o.jsx("textarea",{className:"w-full min-h-[150px] p-3 border border-border1 rounded-lg bg-surface3 font-mono text-sm text-neutral5 resize-none",value:h.value,onChange:b=>m(S=>({...S,value:b.target.value})),disabled:a,"aria-label":"Working memory content",placeholder:"Enter working memory content..."}):o.jsx(o.Fragment,{children:n?o.jsx(o.Fragment,{children:n.trim().startsWith("{")?o.jsx(ORr,{content:n||"",isCopied:f,onCopy:p,className:"bg-surface3 text-sm font-mono min-h-[150px] border border-border1 rounded-lg"}):o.jsx(o.Fragment,{children:o.jsx("div",{className:"bg-surface3 border border-border1 rounded-lg",style:{height:"300px"},children:o.jsx(Yr,{className:"h-full",children:o.jsxs("div",{className:"p-3 cursor-pointer hover:bg-surface4/20 transition-colors relative group text-ui-xs",children:[o.jsx("button",{type:"button",onClick:p,"aria-label":"Copy working memory",className:"absolute inset-0 z-10 rounded-lg focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-accent1"}),o.jsx("div",{className:"pointer-events-none",children:o.jsx(Wp,{children:n})}),f&&o.jsx("span",{className:"absolute top-2 right-2 z-20 text-ui-xs px-1.5 py-0.5 rounded-full bg-green-500/20 text-green-500 pointer-events-none",children:"Copied!"}),o.jsx("span",{className:"absolute top-2 right-2 z-20 text-ui-xs px-1.5 py-0.5 rounded-full bg-surface3 text-neutral4 opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none",children:"Click to copy"})]})})})})}):o.jsx("div",{className:"text-sm text-neutral3 font-mono",children:'No working memory content yet. Click "Edit Working Memory" to add content.'})}),o.jsx("div",{className:"flex gap-2",children:v?o.jsxs(o.Fragment,{children:[o.jsx(de,{onClick:async()=>{try{await i(h.value),y(!1)}catch(b){console.error("Failed to update working memory:",b),De.error("Failed to update working memory")}},disabled:a,className:"text-xs",children:a?o.jsx(Ydn,{className:"w-3 h-3 animate-spin"}):"Save Changes"}),o.jsx(de,{onClick:()=>{m({source:n,value:n??""}),y(!1)},disabled:a,className:"text-xs",children:"Cancel"})]}):o.jsx(o.Fragment,{children:t?o.jsx(de,{onClick:()=>y(!0),disabled:a,className:"text-xs",children:"Edit Working Memory"}):o.jsxs(Wn,{children:[o.jsx(zn,{asChild:!0,children:o.jsx(de,{type:"button","aria-disabled":"true",onClick:b=>b.preventDefault(),className:"text-xs cursor-not-allowed opacity-50",children:"Edit Working Memory"})}),o.jsx(Bn,{children:o.jsx("p",{children:"Working memory will be available after the agent calls updateWorkingMemory"})})]})})})]}):o.jsxs("div",{className:"bg-surface3 border border-border1 rounded-lg p-4",children:[o.jsx("p",{className:"text-sm text-neutral3 mb-3",children:"Working memory is not enabled for this agent. Enable it to maintain context across conversations."}),o.jsxs("a",{href:"https://mastra.ai/en/docs/memory/working-memory",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-2 text-sm text-blue-400 hover:text-blue-300 transition-colors",children:["Learn about working memory",o.jsx(_a,{className:"w-3 h-3"})]})]})]})},CRr="__default__",SWe=e=>e||CRr,RRt=g.createContext({getThreadInput:()=>"",setThreadInputForThread:()=>{}}),PRt=({children:e})=>{const[t,n]=g.useState({}),r=g.useCallback(i=>t[SWe(i)]??"",[t]),s=g.useCallback((i,l)=>{n(c=>{const u=SWe(i),d=c[u]??"",f=typeof l=="function"?l(d):l;if(f===d)return c;if(f.length===0){if(!(u in c))return c;const p={...c};return delete p[u],p}return{...c,[u]:f}})},[]),a=g.useMemo(()=>({getThreadInput:r,setThreadInputForThread:s}),[r,s]);return o.jsx(RRt.Provider,{value:a,children:e})},$Rt=e=>{const{getThreadInput:t,setThreadInputForThread:n}=g.use(RRt),r=g.useCallback(s=>n(e,s),[n,e]);return{threadInput:t(e),setThreadInput:r}},ERr=e=>{const n=Math.floor((new Date().getTime()-e.getTime())/1e3);return n<60?"just now":n<3600?`${Math.floor(n/60)}m ago`:n<86400?`${Math.floor(n/3600)}h ago`:n<604800?`${Math.floor(n/86400)}d ago`:e.toLocaleDateString()},jRr=({searchMemory:e,onResultClick:t,className:n,currentThreadId:r,chatInputValue:s})=>{const[a,i]=g.useState(""),[l,c]=g.useState([]),[u,d]=g.useState(!1),[f,p]=g.useState(!1),[h,m]=g.useState(null),v=g.useRef(void 0),y=g.useRef(null),b=g.useRef(r),S=g.useRef(0),w=g.useRef(null),k=g.useCallback(async I=>{if(!I.trim()){m(null);return}d(!0),m(null);try{const R=await e(I);c(R.results),p(P=>P||R.results.length>0)}catch(R){m("Failed to search memory"),console.error("Memory search error:",R)}finally{d(!1)}},[e]),_=g.useCallback(I=>{const R=I.target.value;if(i(R),v.current&&clearTimeout(v.current),R.trim()){const P=Date.now(),L=P-S.current;if(L>=500)d(!0),k(R),S.current=P;else{d(!0),w.current=R;const M=500-L;v.current=setTimeout(()=>{w.current&&(k(w.current),S.current=Date.now(),w.current=null)},M)}}else c([]),p(!1),d(!1),w.current=null},[k]),C=g.useCallback(I=>{I.key==="Enter"&&(I.preventDefault(),v.current&&clearTimeout(v.current),k(a))},[a,k]);g.useEffect(()=>()=>{v.current&&clearTimeout(v.current)},[]),g.useEffect(()=>{const I=R=>{y.current&&!y.current.contains(R.target)&&p(!1)};return document.addEventListener("mousedown",I),()=>document.removeEventListener("mousedown",I)},[]),g.useEffect(()=>{b.current!==r&&a.trim()&&k(a),b.current=r},[r,a,k]),g.useEffect(()=>{if(s!==void 0&&s!==a)if(i(s),v.current&&clearTimeout(v.current),s.trim()){const I=Date.now(),R=I-S.current;if(R>=500)d(!0),k(s),S.current=I;else{d(!0),w.current=s;const P=500-R;v.current=setTimeout(()=>{w.current&&(k(w.current),S.current=Date.now(),w.current=null)},P)}}else c([]),p(!1),d(!1),w.current=null;return()=>{v.current&&clearTimeout(v.current)}},[s]);const E=(I,R)=>{t?.(I,R)},j=()=>{i(""),c([]),p(!1),m(null),v.current&&clearTimeout(v.current)},N=(I,R=100)=>I.length<=R?I:I.substring(0,R)+"...";return o.jsxs("div",{className:K("flex flex-col h-full",n),ref:y,children:[o.jsxs("div",{className:"relative shrink-0",children:[o.jsx(Xa,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-neutral3"}),o.jsx(kn,{type:"text",value:a,onChange:_,onKeyDown:C,placeholder:"Search memory...",className:"pl-10 pr-10 bg-surface3 border-border1"}),a&&o.jsx(de,{onClick:j,className:"absolute right-1 top-1/2 transform -translate-y-1/2 h-6 w-6 p-0",children:o.jsx(vs,{className:"h-4 w-4"})})]}),(f||a&&(u||l.length===0))&&o.jsx("div",{className:"mt-2 flex-1 bg-surface3 border border-border1 rounded-lg shadow-lg overflow-y-auto",children:h?o.jsx("div",{className:"p-4 text-center",children:o.jsx(ge,{variant:"ui-sm",className:"text-red-500",children:h})}):u&&l.length===0?o.jsx("div",{className:"p-4 text-center",children:o.jsx(ge,{variant:"ui-sm",className:"text-neutral3",children:"Searching..."})}):l.length===0?o.jsx("div",{className:"p-4 text-center",children:o.jsxs(ge,{variant:"ui-sm",className:"text-neutral3",children:['No results found for "',a,'"']})}):o.jsx("div",{className:"py-2",children:l.map(I=>o.jsx("button",{onClick:()=>E(I.id,I.threadId),className:K("w-full px-4 py-3 hover:bg-surface4 transition-colors duration-150 text-left border-b border-border1 last:border-b-0",I.threadId!==r&&"border-l-2 border-l-blue-400"),children:o.jsxs("div",{className:"flex flex-col gap-2",children:[I.context?.before&&I.context.before.length>0&&o.jsx("div",{className:"opacity-50 text-xs space-y-1",children:I.context.before.map((R,P)=>o.jsxs("div",{className:"flex items-start gap-2",children:[o.jsxs("span",{className:"font-medium",children:[R.role,":"]}),o.jsx("span",{className:"text-neutral3",children:N(R.content,50)})]},P))}),o.jsx("div",{className:"flex items-start justify-between gap-2",children:o.jsxs("div",{className:"flex-1 min-w-0",children:[o.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[o.jsx("span",{className:K("text-xs font-medium px-2 py-0.5 rounded",I.role==="user"?"bg-blue-500/20 text-blue-400":"bg-green-500/20 text-green-400"),children:I.role}),o.jsx(ge,{variant:"ui-xs",className:"text-neutral3",children:ERr(new Date(I.createdAt))}),I.threadTitle&&o.jsxs("div",{className:"flex items-center gap-1",children:[o.jsxs(ge,{variant:"ui-xs",className:K("truncate max-w-[150px]",I.threadId!==r?"text-blue-400 font-medium":"text-neutral3"),title:I.threadTitle,children:["• ",I.threadTitle]}),I.threadId!==r&&o.jsx(_a,{className:"w-3 h-3 text-blue-400"})]})]}),o.jsx(ge,{variant:"ui-sm",className:"text-neutral5 wrap-break-word",children:N(I.content)})]})}),I.context?.after&&I.context.after.length>0&&o.jsx("div",{className:"opacity-50 text-xs space-y-1",children:I.context.after.map((R,P)=>o.jsxs("div",{className:"flex items-start gap-2",children:[o.jsxs("span",{className:"font-medium",children:[R.role,":"]}),o.jsx("span",{className:"text-neutral3",children:N(R.content,50)})]},P))})]})},I.id))})})]})};function TRr({agentId:e,threadId:t,memoryType:n}){const r=n==="gateway",{threadInput:s}=$Rt(t),{paths:a,navigate:i}=yn(),{data:l}=pRt({threadId:t,agentId:e}),c=l?.resourceId??e,{data:u,isLoading:d}=G_(e),p=!!u?.config?.semanticRecall,{data:h}=mRt({agentId:e,resourceId:c,threadId:t}),m=h?.observationalMemory?.enabled??!1,{mutateAsync:v,data:y}=sRr({agentId:e||"",resourceId:c||"",threadId:t}),{mutateAsync:b,isPending:S}=aRr(),w=g.useCallback(async()=>{if(!t||!e)return;const C=await b({threadId:t,agentId:e});C?.thread?.id&&i(a.agentThreadLink(e,C.thread.id))},[t,e,b,i,a]),k=g.useCallback((C,E)=>{if(E&&E!==t)i(a.agentThreadLink(e,E,C));else{const j=document.querySelector(`[data-message-id="${C}"]`);j&&(j.scrollIntoView({behavior:"smooth",block:"center"}),j.classList.add("bg-surface4"),setTimeout(()=>{j.classList.remove("bg-surface4")},2e3))}},[e,t,i,a]),_=y?.searchScope;return d?o.jsxs("div",{className:"flex flex-col h-full p-4 gap-4",children:[o.jsx(bt,{className:"h-12 w-full"}),o.jsx(bt,{className:"h-32 w-full"}),o.jsx(bt,{className:"h-48 w-full"})]}):o.jsxs("div",{className:"flex flex-col min-w-0",children:[t&&o.jsx("div",{className:"p-4 border-b border-border1",children:o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsxs("div",{children:[o.jsx("h3",{className:"text-sm font-medium text-neutral5",children:"Clone Thread"}),o.jsx("p",{className:"text-xs text-neutral3 mt-1",children:"Create a copy of this conversation"})]}),o.jsxs(de,{onClick:w,disabled:S,children:[o.jsx(Dp,{className:"w-4 h-4 mr-2"}),S?"Cloning...":"Clone"]})]})}),m&&o.jsx("div",{className:"border-b border-border1 min-w-0 overflow-hidden",children:o.jsx(kRr,{agentId:e,resourceId:c,threadId:t})}),!r&&o.jsxs("div",{className:"p-4 border-b border-border1",children:[o.jsx("div",{className:"mb-2",children:o.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[o.jsx("h3",{className:"text-sm font-medium text-neutral5",children:"Semantic Recall"}),y?.searchScope&&o.jsx("span",{className:K("text-xs font-medium px-2 py-0.5 rounded",_==="resource"?"bg-purple-500/20 text-purple-400":"bg-blue-500/20 text-blue-400"),title:_==="resource"?"Searching across all threads":"Searching within current thread only",children:_})]})}),p?o.jsx(jRr,{searchMemory:C=>v({searchQuery:C,memoryConfig:{lastMessages:0}}),onResultClick:k,currentThreadId:t,className:"w-full",chatInputValue:s}):o.jsxs("div",{className:"bg-surface3 border border-border1 rounded-lg p-4",children:[o.jsx("p",{className:"text-sm text-neutral3 mb-3",children:"Semantic recall is not enabled for this agent. Enable it to search through conversation history."}),o.jsxs("a",{href:"https://mastra.ai/en/docs/memory/semantic-recall",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-2 text-sm text-blue-400 hover:text-blue-300 transition-colors",children:["Learn about semantic recall",o.jsx(_a,{className:"w-3 h-3"})]})]})]}),!r&&o.jsx("div",{children:o.jsx(_Rr,{agentId:e})}),r&&o.jsx("div",{className:"p-4 border-b border-border1",children:o.jsxs("div",{className:"bg-surface3 border border-border1 rounded-lg p-4",children:[o.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[o.jsx("span",{className:"text-xs font-medium px-2 py-0.5 rounded bg-green-500/20 text-green-400",children:"Gateway"}),o.jsx("h3",{className:"text-sm font-medium text-neutral5",children:"Memory Gateway"})]}),o.jsx("p",{className:"text-xs text-neutral3",children:"Memory is managed by the Memory Gateway. Threads and observations are stored remotely."})]})})]})}function NRr(e){let t=e;for(let n=0;n<3&&typeof t=="string";n++)try{const r=JSON.parse(t);if(typeof r=="object"&&r!==null)return r;if(typeof r=="string"&&r!==t){t=r;continue}break}catch{break}return t}function IRr(e){return typeof e=="object"&&e!==null&&"parts"in e&&Array.isArray(e.parts)}function ARr(e){const t=e.type;return t==="data-om-status"||t==="data-om-observation-start"||t==="data-om-observation-end"||t==="data-om-buffering-start"||t==="data-om-buffering-end"||t==="data-om-activation"}function RRr(e,t){switch(e.type){case"data-om-status":return{type:"status",timestamp:t,pendingTokens:e.data.windows?.active?.messages?.tokens,observationTokens:e.data.windows?.active?.observations?.tokens,observationThreshold:e.data.windows?.active?.messages?.threshold,reflectionThreshold:e.data.windows?.active?.observations?.threshold};case"data-om-observation-start":return{type:"observation-start",timestamp:e.data.startedAt,pendingTokens:e.data.tokensToObserve,observationThreshold:e.data.config?.messageTokens,reflectionThreshold:e.data.config?.observationTokens};case"data-om-observation-end":return{type:"observation-end",timestamp:e.data.completedAt,observationTokens:e.data.observationTokens};case"data-om-buffering-start":return{type:"buffering-start",timestamp:e.data.startedAt,pendingTokens:e.data.tokensToBuffer,observationThreshold:e.data.config?.messageTokens,reflectionThreshold:e.data.config?.observationTokens};case"data-om-buffering-end":return{type:"buffering-end",timestamp:e.data.completedAt,observationTokens:e.data.bufferedTokens};case"data-om-activation":return{type:"activation",timestamp:e.data.activatedAt,pendingTokens:e.data.tokensActivated,observationTokens:e.data.observationTokens,observationThreshold:e.data.config?.messageTokens,reflectionThreshold:e.data.config?.observationTokens,generationCount:e.data.generationCount}}}function PRr(e){const t=[];for(const n of e){const r=NRr(n.content);if(IRr(r))for(const s of r.parts)ARr(s)&&t.push(RRr(s,new Date(n.createdAt).toISOString()))}return t.sort((n,r)=>n.timestamp.localeCompare(r.timestamp)),t}function QT(e){return/[Zz+-]\d{0,4}$/.test(e.trim())?new Date(e).getTime():new Date(e.trim().replace(" ","T")+"Z").getTime()}function $Rr(e){if(e.length===0)return{tMin:0,tMax:1};let t=1/0,n=-1/0;for(const r of e){const s=QT(r);s<t&&(t=s),s>n&&(n=s)}return t===n?{tMin:t,tMax:t+1}:{tMin:t,tMax:n}}function l4(e,t){return(QT(e)-t.tMin)/(t.tMax-t.tMin)}function N_e(e,t){return new Date(t.tMin+e*(t.tMax-t.tMin))}function MRt(e){const t=String(e.getUTCDate()).padStart(2,"0"),n=String(e.getUTCMonth()+1).padStart(2,"0"),r=String(e.getUTCHours()).padStart(2,"0"),s=String(e.getUTCMinutes()).padStart(2,"0"),a=String(e.getUTCSeconds()).padStart(2,"0");return`${t}/${n} ${r}:${s}:${a}`}function MRr(e,t){return N_e(e,t).getTime()}function DRt(e){const t=e.lastObservedAt??e.updatedAt;return typeof t=="string"?t:new Date(t).toISOString()}function DRr(e){return QT(DRt(e))}function LRr(e,t){if(t==null||e.length===0)return null;const n=e.map(s=>({id:s.id,t:QT(DRt(s))})).toSorted((s,a)=>s.t-a.t);let r=null;for(const s of n)if(s.t<=t)r=s.id;else break;return r}function kWe(e){const t=e.lastObservedAt??e.updatedAt;return typeof t=="string"?t:new Date(t).toISOString()}function FRr(e){return[...e].sort((t,n)=>QT(kWe(t))-QT(kWe(n)))}function zRr({markers:e,omRecords:t,observationThreshold:n,reflectionThreshold:r}){const s=[...e].filter(i=>i.type==="status"&&(i.pendingTokens!=null||i.observationTokens!=null)).sort((i,l)=>i.timestamp.localeCompare(l.timestamp)).at(-1),a=FRr(t).at(-1);return{messageTokens:s?.pendingTokens??a?.pendingMessageTokens,messageThreshold:s?.observationThreshold??n,memoryTokens:s?.observationTokens??a?.observationTokenCount,memoryThreshold:s?.reflectionThreshold??r}}const BRr="var(--color-green-500, #22c55e)",URr="#f59e0b",OWe="#ec4899";function aP(e){const t=e.lastObservedAt??e.updatedAt;return typeof t=="string"?t:new Date(t).toISOString()}function qRr(e,t,n){const r=e.map(a=>({ts:String(aP(a)),pendingMessageTokens:a.pendingMessageTokens})),s=t.flatMap(a=>a.pendingTokens==null?[]:{ts:a.timestamp,pendingMessageTokens:a.pendingTokens});return[...r,...s].sort((a,i)=>a.ts.localeCompare(i.ts)).map(a=>({t:l4(a.ts,n),pendingMessageTokens:a.pendingMessageTokens}))}function VRr(e,t,n){const r=[...e.map(a=>({ts:String(aP(a)),observationTokenCount:a.observationTokenCount})),...t.flatMap(a=>a.type!=="status"||a.observationTokens==null?[]:{ts:a.timestamp,observationTokenCount:a.observationTokens})].sort((a,i)=>a.ts.localeCompare(i.ts));let s=0;return r.map(a=>(s=Math.max(s,a.observationTokenCount),{t:l4(a.ts,n),observationTokenCount:s}))}function HRr(e,t){const n=e.flatMap(s=>s.observationTokens==null||s.type!=="buffering-end"&&s.type!=="activation"?[]:{ts:s.timestamp,bufferedObservationTokenCount:s.type==="activation"?-s.observationTokens:s.observationTokens}).sort((s,a)=>s.ts.localeCompare(a.ts));let r=0;return n.map(s=>(r=Math.max(0,r+s.bufferedObservationTokenCount),{t:l4(s.ts,t),bufferedObservationTokenCount:r}))}function WRr(e,t){return[...e].sort((n,r)=>String(aP(n)).localeCompare(String(aP(r)))).map(n=>({t:l4(String(aP(n)),t),event:1}))}function ZRr(e,t){return[...e].sort((n,r)=>new Date(n.createdAt).getTime()-new Date(r.createdAt).getTime()).map(n=>({t:l4(new Date(n.createdAt).toISOString(),t),event:1,role:n.role}))}function GRr({domain:e}){const t=[0,.25,.5,.75,1];return o.jsxs("div",{className:"grid grid-cols-[6rem_1fr] items-center",children:[o.jsx("p",{className:"flex items-center self-stretch border-r border-border1/50 pl-3 text-ui-xs font-medium text-icon3",children:"Time"}),o.jsx("div",{className:"flex justify-between px-1 py-1.5 font-mono text-ui-xs text-icon3",children:t.map(n=>o.jsx("span",{children:MRt(N_e(n,e))},n))})]})}function I_e({active:e,payload:t,domain:n,showValue:r}){if(!e||!t?.length)return null;const s=t[0]?.payload?.t,a=n!=null&&s!=null?MRt(N_e(s,n)):null,i=t.filter(l=>l.name!=="t"&&l.name!=="time"&&l.value!=null);return r?o.jsxs("div",{className:"flex flex-col gap-0.5 rounded border border-border1 bg-surface3 px-2 py-1.5 font-mono text-ui-xs shadow",children:[a&&o.jsxs("div",{className:"flex items-center justify-between gap-3",children:[o.jsx("span",{className:"text-icon3",children:"time"}),o.jsx("span",{className:"text-neutral6",children:a})]}),i.map(l=>o.jsxs("div",{className:"flex items-center justify-between gap-3",children:[o.jsx("span",{className:"text-icon3",children:l.name}),o.jsx("span",{className:"text-neutral6",children:typeof l.value=="number"?Math.round(l.value).toLocaleString():String(l.value)})]},l.name))]}):o.jsx("div",{className:"rounded border border-border1 bg-surface3 px-2 py-1 font-mono text-ui-xs shadow",children:a&&o.jsx("span",{className:"text-neutral6",children:a})})}function QRr({label:e,data:t,dataKey:n,color:r,gradientId:s,domain:a,zoomDomain:i,threshold:l}){const c=Math.max(0,...t.map(d=>Number(d[n])||0)),u=l!=null?Math.max(c,l):void 0;return o.jsxs("div",{className:"relative grid grid-cols-[6rem_1fr] items-center border-b border-border1/50 hover:z-10",children:[o.jsx("p",{className:"flex items-center self-stretch border-r border-border1/50 pl-3 text-ui-xs font-medium text-icon3",children:e}),o.jsx("div",{children:o.jsx(N3,{width:"100%",height:32,children:o.jsxs(Wgr,{data:t,margin:{top:0,right:0,bottom:0,left:0},children:[o.jsx("defs",{children:o.jsxs("linearGradient",{id:s,x1:"0",y1:"0",x2:"0",y2:"1",children:[o.jsx("stop",{offset:"0%",stopColor:r,stopOpacity:.35}),o.jsx("stop",{offset:"100%",stopColor:r,stopOpacity:.03})]})}),o.jsx(sI,{dataKey:"t",type:"number",domain:i,allowDataOverflow:!0,hide:!0}),o.jsx(aI,{type:"number",domain:u!=null?[0,u]:void 0,hide:!0}),o.jsx(V3,{content:o.jsx(I_e,{domain:a,showValue:!0}),cursor:{stroke:"rgba(255,255,255,0.08)"}}),o.jsx(qke,{type:"linear",dataKey:n,stroke:r,strokeWidth:1,strokeOpacity:.6,fill:`url(#${s})`,isAnimationActive:!1}),l!=null&&o.jsx($ke,{y:l,stroke:r,strokeDasharray:"4 3",strokeOpacity:.4})]})})})]})}function YRr({label:e,data:t,color:n,height:r=32,domain:s,zoomDomain:a}){return o.jsxs("div",{className:"relative grid grid-cols-[6rem_1fr] items-center border-b border-border1/50 hover:z-10",children:[o.jsx("p",{className:"flex items-center self-stretch border-r border-border1/50 pl-3 text-ui-xs font-medium text-icon3",children:e}),o.jsx("div",{children:o.jsx(N3,{width:"100%",height:r,children:o.jsxs(yEt,{margin:{top:0,right:0,bottom:0,left:0},children:[o.jsx(sI,{dataKey:"t",type:"number",domain:a,allowDataOverflow:!0,hide:!0}),o.jsx(aI,{dataKey:"event",type:"number",domain:[0,2],hide:!0}),o.jsx(V3,{content:o.jsx(I_e,{domain:s}),cursor:!1}),o.jsx(Vke,{data:t,fill:n,isAnimationActive:!1,shape:i=>{const l=i.cx;return o.jsxs("g",{children:[o.jsx("rect",{x:l-6,y:0,width:12,height:r,fill:"transparent"}),o.jsx("rect",{x:l-1.5,y:0,width:3,height:r,fill:n})]})}})]})})})]})}function _We({label:e,areaData:t,areaDataKey:n,eventData:r,color:s,gradientId:a,domain:i,zoomDomain:l,threshold:c,height:u=44,onSelectT:d}){const f=new Map(t.map(y=>[y.t,Number(y[n]??0)])),p=r.reduce((y,b)=>{const S=y.get(b.t);return S?S.push(b):y.set(b.t,[b]),y},new Map),h=Array.from(new Set([...f.keys(),...p.keys()])).sort((y,b)=>y-b);let m=0;const v=[];for(const y of h){const b=f.get(y);b!=null&&(m=b);const S=p.get(y);if(S&&S.length>0)for(const w of S)v.push({...w,t:y,[n]:m});else v.push({t:y,[n]:m})}return o.jsxs("div",{className:"relative grid grid-cols-[6rem_1fr] items-center border-b border-border1/50 hover:z-10",children:[o.jsx("p",{className:"flex items-center self-stretch border-r border-border1/50 pl-3 text-ui-xs font-medium text-icon3",children:e}),o.jsx("div",{children:o.jsx(N3,{width:"100%",height:u,children:o.jsxs(Ggr,{margin:{top:0,right:0,bottom:0,left:0},onClick:y=>{const b=y?.activeLabel;b!=null&&d&&d(Number(b))},className:d?"cursor-pointer":void 0,children:[o.jsx("defs",{children:o.jsxs("linearGradient",{id:a,x1:"0",y1:"0",x2:"0",y2:"1",children:[o.jsx("stop",{offset:"0%",stopColor:s,stopOpacity:.35}),o.jsx("stop",{offset:"100%",stopColor:s,stopOpacity:.06})]})}),o.jsx(sI,{dataKey:"t",type:"number",domain:l,allowDataOverflow:!0,hide:!0}),o.jsx(aI,{yAxisId:"area",dataKey:n,type:"number",hide:!0,domain:[0,"dataMax"]}),o.jsx(V3,{content:o.jsx(I_e,{domain:i,showValue:!0}),cursor:!1}),o.jsx(qke,{yAxisId:"area",data:v,type:"linear",dataKey:n,stroke:s,strokeWidth:1,strokeOpacity:.6,fill:`url(#${a})`,isAnimationActive:!1,activeDot:{r:5,stroke:s,strokeWidth:2,fill:"#0a0a0a"},dot:y=>y.payload?.event?o.jsx("circle",{cx:y.cx,cy:y.cy,r:4,fill:s}):o.jsx(o.Fragment,{})}),c!=null&&o.jsx($ke,{yAxisId:"area",y:c,stroke:s,strokeDasharray:"4 3",strokeOpacity:.4})]})})})]})}function XRr({tDomain:e,zoomLeft:t,zoomRight:n,onZoomLeftChange:r,onZoomRightChange:s,onReset:a}){const i=g.useRef(null),l=g.useRef(null),c=e.tMax-e.tMin,u=c>0?(t-e.tMin)/c*100:0,d=c>0?(n-e.tMin)/c*100:100,f=g.useCallback(p=>{const h=i.current;if(!h)return null;const m=h.getBoundingClientRect(),v=Math.max(0,Math.min(1,(p-m.left)/m.width));return e.tMin+v*(e.tMax-e.tMin)},[e.tMin,e.tMax]);return g.useEffect(()=>{const p=m=>{if(!l.current)return;const v=f(m.clientX);v!=null&&(l.current==="left"?r(Math.min(v,n)):s(Math.max(v,t)))},h=()=>{l.current=null};return window.addEventListener("mousemove",p),window.addEventListener("mouseup",h),()=>{window.removeEventListener("mousemove",p),window.removeEventListener("mouseup",h)}},[f,t,n,r,s]),o.jsxs("div",{className:"grid grid-cols-[6rem_1fr] items-center border-b border-border1/50",children:[o.jsxs("div",{className:"flex items-center gap-1 self-stretch border-r border-border1/50 pl-3",children:[o.jsx("p",{className:"text-ui-xs font-medium text-icon3",children:"Zoom"}),o.jsx(de,{variant:"ghost",size:"icon-sm","aria-label":"Reset zoom",onClick:a,children:o.jsx(GOn,{className:"size-3"})})]}),o.jsxs("div",{ref:i,className:"relative h-6 cursor-pointer select-none",onMouseDown:p=>{const h=f(p.clientX);if(h==null)return;p.preventDefault();const m=Math.abs(h-t),v=Math.abs(h-n);m<=v?(r(Math.min(h,n)),l.current="left"):(s(Math.max(h,t)),l.current="right")},children:[o.jsx("div",{className:"absolute inset-y-0 left-0 bg-surface2/60",style:{width:`${u}%`}}),o.jsx("div",{className:"absolute inset-y-0 border-y border-border1/30 bg-neutral6/5",style:{left:`${u}%`,right:`${100-d}%`}}),o.jsx("div",{className:"absolute inset-y-0 right-0 bg-surface2/60",style:{width:`${100-d}%`}}),o.jsx("div",{className:"absolute inset-y-0 w-1 cursor-col-resize bg-neutral6/50 hover:bg-neutral6",style:{left:`${u}%`,transform:"translateX(-50%)"},onMouseDown:p=>{p.preventDefault(),p.stopPropagation(),l.current="left"}}),o.jsx("div",{className:"absolute inset-y-0 w-1 cursor-col-resize bg-neutral6/50 hover:bg-neutral6",style:{left:`${d}%`,transform:"translateX(-50%)"},onMouseDown:p=>{p.preventDefault(),p.stopPropagation(),l.current="right"}})]})]})}const KRr={tMin:0,tMax:1};function JRr({omRecords:e,markers:t,messages:n,tDomain:r,observationThreshold:s,reflectionThreshold:a,onSelectTimestamp:i,zoomRange:l,onZoomRangeChange:c}){const u=r??KRr,d=g.useCallback(q=>{i?.(MRr(q,u))},[i,u]),f=l!=null&&c!=null,[p,h]=g.useState(u.tMin),[m,v]=g.useState(u.tMax);g.useEffect(()=>{f||(h(u.tMin),v(u.tMax))},[u.tMin,u.tMax,f]);const y=f?l.left:p,b=f?l.right:m,S=g.useCallback(q=>{f?c({left:q,right:b}):h(q)},[f,c,b]),w=g.useCallback(q=>{f?c({left:y,right:q}):v(q)},[f,c,y]),k=g.useCallback(()=>{f?c({left:u.tMin,right:u.tMax}):(h(u.tMin),v(u.tMax))},[f,c,u.tMin,u.tMax]),_=u.tMax-u.tMin,C=_>0?(y-u.tMin)/_:0,E=_>0?(b-u.tMin)/_:1,j=[C,E],N=g.useMemo(()=>ZRr(n,u),[n,u]),I=g.useMemo(()=>qRr(e,t,u),[e,t,u]),R=g.useMemo(()=>VRr(e,t,u),[e,t,u]),P=g.useMemo(()=>HRr(t,u),[t,u]),L=g.useMemo(()=>WRr(e,u),[e,u]);return N.length>0||I.length>0||R.length>0||L.length>0?o.jsxs("div",{className:"flex flex-col pb-2 pr-2 [&_.recharts-surface]:outline-none",children:[o.jsx(_We,{label:"Messages",areaData:I,areaDataKey:"pendingMessageTokens",eventData:N,color:BRr,gradientId:"grad-messages",domain:u,zoomDomain:j,threshold:s,onSelectT:i?d:void 0}),o.jsx(_We,{label:"Observations",areaData:R,areaDataKey:"observationTokenCount",eventData:L,color:URr,gradientId:"grad-observations",domain:u,zoomDomain:j,threshold:a,onSelectT:i?d:void 0}),P.length>0&&o.jsx(QRr,{label:"Buffered obs",data:P,dataKey:"bufferedObservationTokenCount",color:OWe,gradientId:"grad-buffered-obs",domain:u,zoomDomain:j,threshold:a}),L.length>0&&o.jsx(YRr,{label:"Events",data:L,color:OWe,domain:u,zoomDomain:j}),o.jsx(GRr,{domain:u}),o.jsx(XRr,{tDomain:u,zoomLeft:y,zoomRight:b,onZoomLeftChange:S,onZoomRightChange:w,onReset:k})]}):null}class jl{constructor(t,n,r,s){this.fromA=t,this.toA=n,this.fromB=r,this.toB=s}offset(t,n=t){return new jl(this.fromA+t,this.toA+t,this.fromB+n,this.toB+n)}}function t_(e,t,n,r,s,a){if(e==r)return[];let i=R_e(e,t,n,r,s,a),l=P_e(e,t+i,n,r,s+i,a);t+=i,n-=l,s+=i,a-=l;let c=n-t,u=a-s;if(!c||!u)return[new jl(t,n,s,a)];if(c>u){let f=e.slice(t,n).indexOf(r.slice(s,a));if(f>-1)return[new jl(t,t+f,s,s),new jl(t+f+u,n,a,a)]}else if(u>c){let f=r.slice(s,a).indexOf(e.slice(t,n));if(f>-1)return[new jl(t,t,s,s+f),new jl(n,n,s+f+c,a)]}if(c==1||u==1)return[new jl(t,n,s,a)];let d=zRt(e,t,n,r,s,a);if(d){let[f,p,h]=d;return t_(e,t,f,r,s,p).concat(t_(e,f+h,n,r,p+h,a))}return e2r(e,t,n,r,s,a)}let S2=1e9,k2=0,A_e=!1;function e2r(e,t,n,r,s,a){let i=n-t,l=a-s;if(S2<1e9&&Math.min(i,l)>S2*16||k2>0&&Date.now()>k2)return Math.min(i,l)>S2*64?[new jl(t,n,s,a)]:CWe(e,t,n,r,s,a);let c=Math.ceil((i+l)/2);gre.reset(c),vre.reset(c);let u=(h,m)=>e.charCodeAt(t+h)==r.charCodeAt(s+m),d=(h,m)=>e.charCodeAt(n-h-1)==r.charCodeAt(a-m-1),f=(i-l)%2!=0?vre:null,p=f?null:gre;for(let h=0;h<c;h++){if(h>S2||k2>0&&!(h&63)&&Date.now()>k2)return CWe(e,t,n,r,s,a);let m=gre.advance(h,i,l,c,f,!1,u)||vre.advance(h,i,l,c,p,!0,d);if(m)return t2r(e,t,n,t+m[0],r,s,a,s+m[1])}return[new jl(t,n,s,a)]}class LRt{constructor(){this.vec=[]}reset(t){this.len=t<<1;for(let n=0;n<this.len;n++)this.vec[n]=-1;this.vec[t+1]=0,this.start=this.end=0}advance(t,n,r,s,a,i,l){for(let c=-t+this.start;c<=t-this.end;c+=2){let u=s+c,d=c==-t||c!=t&&this.vec[u-1]<this.vec[u+1]?this.vec[u+1]:this.vec[u-1]+1,f=d-c;for(;d<n&&f<r&&l(d,f);)d++,f++;if(this.vec[u]=d,d>n)this.end+=2;else if(f>r)this.start+=2;else if(a){let p=s+(n-r)-c;if(p>=0&&p<this.len&&a.vec[p]!=-1)if(i){let h=a.vec[p];if(h>=n-d)return[h,s+h-p]}else{let h=n-a.vec[p];if(d>=h)return[d,f]}}}return null}}const gre=new LRt,vre=new LRt;function t2r(e,t,n,r,s,a,i,l){let c=!1;return!YT(e,r)&&++r==n&&(c=!0),!YT(s,l)&&++l==i&&(c=!0),c?[new jl(t,n,a,i)]:t_(e,t,r,s,a,l).concat(t_(e,r,n,s,l,i))}function FRt(e,t){let n=1,r=Math.min(e,t);for(;n<r;)n=n<<1;return n}function R_e(e,t,n,r,s,a){if(t==n||t==a||e.charCodeAt(t)!=r.charCodeAt(s))return 0;let i=FRt(n-t,a-s);for(let l=t,c=s;;){let u=l+i,d=c+i;if(u>n||d>a||e.slice(l,u)!=r.slice(c,d)){if(i==1)return l-t-(YT(e,l)?0:1);i=i>>1}else{if(u==n||d==a)return u-t;l=u,c=d}}}function P_e(e,t,n,r,s,a){if(t==n||s==a||e.charCodeAt(n-1)!=r.charCodeAt(a-1))return 0;let i=FRt(n-t,a-s);for(let l=n,c=a;;){let u=l-i,d=c-i;if(u<t||d<s||e.slice(u,l)!=r.slice(d,c)){if(i==1)return n-l-(YT(e,l)?0:1);i=i>>1}else{if(u==t||d==s)return n-u;l=u,c=d}}}function Kge(e,t,n,r,s,a,i,l){let c=r.slice(s,a),u=null;for(;;){if(u||i<l)return u;for(let d=t+i;;){YT(e,d)||d++;let f=d+i;if(YT(e,f)||(f+=f==d+1?1:-1),f>=n)break;let p=e.slice(d,f),h=-1;for(;(h=c.indexOf(p,h+1))!=-1;){let m=R_e(e,f,n,r,s+h+p.length,a),v=P_e(e,t,d,r,s,s+h),y=p.length+m+v;(!u||u[2]<y)&&(u=[d-v,s+h-v,y])}d=f}if(l<0)return u;i=i>>1}}function zRt(e,t,n,r,s,a){let i=n-t,l=a-s;if(i<l){let c=zRt(r,s,a,e,t,n);return c&&[c[1],c[0],c[2]]}return i<4||l*2<i?null:Kge(e,t,n,r,s,a,Math.floor(i/4),-1)}function CWe(e,t,n,r,s,a){A_e=!0;let i=n-t,l=a-s,c;if(i<l){let p=Kge(r,s,a,e,t,n,Math.floor(i/6),50);c=p&&[p[1],p[0],p[2]]}else c=Kge(e,t,n,r,s,a,Math.floor(l/6),50);if(!c)return[new jl(t,n,s,a)];let[u,d,f]=c;return t_(e,t,u,r,s,d).concat(t_(e,u+f,n,r,d+f,a))}function BRt(e,t){for(let n=1;n<e.length;n++){let r=e[n-1],s=e[n];r.toA>s.fromA-t&&r.toB>s.fromB-t&&(e[n-1]=new jl(r.fromA,s.toA,r.fromB,s.toB),e.splice(n--,1))}}function n2r(e,t,n){for(;;){BRt(n,1);let r=!1;for(let s=0;s<n.length;s++){let a=n[s],i,l;(i=R_e(e,a.fromA,a.toA,t,a.fromB,a.toB))&&(a=n[s]=new jl(a.fromA+i,a.toA,a.fromB+i,a.toB)),(l=P_e(e,a.fromA,a.toA,t,a.fromB,a.toB))&&(a=n[s]=new jl(a.fromA,a.toA-l,a.fromB,a.toB-l));let c=a.toA-a.fromA,u=a.toB-a.fromB;if(c&&u)continue;let d=a.fromA-(s?n[s-1].toA:0),f=(s<n.length-1?n[s+1].fromA:e.length)-a.toA;if(!d||!f)continue;let p=c?e.slice(a.fromA,a.toA):t.slice(a.fromB,a.toB);d<=p.length&&e.slice(a.fromA-d,a.fromA)==p.slice(p.length-d)?(n[s]=new jl(a.fromA-d,a.toA-d,a.fromB-d,a.toB-d),r=!0):f<=p.length&&e.slice(a.toA,a.toA+f)==p.slice(0,f)&&(n[s]=new jl(a.fromA+f,a.toA+f,a.fromB+f,a.toB+f),r=!0)}if(!r)break}return n}function r2r(e,t,n){for(let r=0,s=0;s<e.length;s++){let a=e[s],i=a.toA-a.fromA,l=a.toB-a.fromB;if(i&&l||i>3||l>3){let c=s==e.length-1?t.length:e[s+1].fromA,u=a.fromA-r,d=c-a.toA,f=jWe(t,a.fromA,u),p=EWe(t,a.toA,d),h=a.fromA-f,m=p-a.toA;if((!i||!l)&&h&&m){let v=Math.max(i,l),[y,b,S]=i?[t,a.fromA,a.toA]:[n,a.fromB,a.toB];v>h&&t.slice(f,a.fromA)==y.slice(S-h,S)?(a=e[s]=new jl(f,f+i,a.fromB-h,a.toB-h),f=a.fromA,p=EWe(t,a.toA,c-a.toA)):v>m&&t.slice(a.toA,p)==y.slice(b,b+m)&&(a=e[s]=new jl(p-i,p,a.fromB+m,a.toB+m),p=a.toA,f=jWe(t,a.fromA,a.fromA-r)),h=a.fromA-f,m=p-a.toA}if(h||m)a=e[s]=new jl(a.fromA-h,a.toA+m,a.fromB-h,a.toB+m);else if(i){if(!l){let v=NWe(t,a.fromA,a.toA),y,b=v<0?-1:TWe(t,a.toA,a.fromA);v>-1&&(y=v-a.fromA)<=d&&t.slice(a.fromA,v)==t.slice(a.toA,a.toA+y)?a=e[s]=a.offset(y):b>-1&&(y=a.toA-b)<=u&&t.slice(a.fromA-y,a.fromA)==t.slice(b,a.toA)&&(a=e[s]=a.offset(-y))}}else{let v=NWe(n,a.fromB,a.toB),y,b=v<0?-1:TWe(n,a.toB,a.fromB);v>-1&&(y=v-a.fromB)<=d&&n.slice(a.fromB,v)==n.slice(a.toB,a.toB+y)?a=e[s]=a.offset(y):b>-1&&(y=a.toB-b)<=u&&n.slice(a.fromB-y,a.fromB)==n.slice(b,a.toB)&&(a=e[s]=a.offset(-y))}}r=a.toA}return BRt(e,3),e}let Jk;try{Jk=new RegExp("[\\p{Alphabetic}\\p{Number}]","u")}catch{}function URt(e){return e>48&&e<58||e>64&&e<91||e>96&&e<123}function qRt(e,t){if(t==e.length)return 0;let n=e.charCodeAt(t);return n<192?URt(n)?1:0:Jk?!WRt(n)||t==e.length-1?Jk.test(String.fromCharCode(n))?1:0:Jk.test(e.slice(t,t+2))?2:0:0}function VRt(e,t){if(!t)return 0;let n=e.charCodeAt(t-1);return n<192?URt(n)?1:0:Jk?!ZRt(n)||t==1?Jk.test(String.fromCharCode(n))?1:0:Jk.test(e.slice(t-2,t))?2:0:0}const HRt=8;function EWe(e,t,n){if(t==e.length||!VRt(e,t))return t;for(let r=t,s=t+n,a=0;a<HRt;a++){let i=qRt(e,r);if(!i||r+i>s)return r;r+=i}return t}function jWe(e,t,n){if(!t||!qRt(e,t))return t;for(let r=t,s=t-n,a=0;a<HRt;a++){let i=VRt(e,r);if(!i||r-i<s)return r;r-=i}return t}function TWe(e,t,n){for(;t!=n;t--)if(e.charCodeAt(t-1)==10)return t;return-1}function NWe(e,t,n){for(;t!=n;t++)if(e.charCodeAt(t)==10)return t;return-1}const WRt=e=>e>=55296&&e<=56319,ZRt=e=>e>=56320&&e<=57343;function YT(e,t){return!t||t==e.length||!WRt(e.charCodeAt(t-1))||!ZRt(e.charCodeAt(t))}function s2r(e,t,n){var r;let s=n?.override;return s?s(e,t):(S2=((r=n?.scanLimit)!==null&&r!==void 0?r:1e9)>>1,k2=n?.timeout?Date.now()+n.timeout:0,A_e=!1,n2r(e,t,t_(e,0,e.length,t,0,t.length)))}function GRt(){return!A_e}function QRt(e,t,n){return r2r(s2r(e,t,n),e,t)}const cg=On.define({combine:e=>e[0]}),Jge=vr.define(),a2r=On.define(),cx=gl.define({create(e){return null},update(e,t){for(let n of t.effects)n.is(Jge)&&(e=n.value);for(let n of t.state.facet(a2r))e=n(e,t);return e}});class Mj{constructor(t,n,r,s,a,i=!0){this.changes=t,this.fromA=n,this.toA=r,this.fromB=s,this.toB=a,this.precise=i}offset(t,n){return t||n?new Mj(this.changes,this.fromA+t,this.toA+t,this.fromB+n,this.toB+n,this.precise):this}get endA(){return Math.max(this.fromA,this.toA-1)}get endB(){return Math.max(this.fromB,this.toB-1)}static build(t,n,r){let s=QRt(t.toString(),n.toString(),r);return YRt(s,t,n,0,0,GRt())}static updateA(t,n,r,s,a){return $We(PWe(t,s,!0,r.length),t,n,r,a)}static updateB(t,n,r,s,a){return $We(PWe(t,s,!1,n.length),t,n,r,a)}}function IWe(e,t,n,r){let s=n.lineAt(e),a=r.lineAt(t);return s.to==e&&a.to==t&&e<n.length&&t<r.length?[e+1,t+1]:[s.from,a.from]}function AWe(e,t,n,r){let s=n.lineAt(e),a=r.lineAt(t);return s.from==e&&a.from==t?[e,t]:[s.to+1,a.to+1]}function YRt(e,t,n,r,s,a){let i=[];for(let l=0;l<e.length;l++){let c=e[l],[u,d]=IWe(c.fromA+r,c.fromB+s,t,n),[f,p]=AWe(c.toA+r,c.toB+s,t,n),h=[c.offset(-u+r,-d+s)];for(;l<e.length-1;){let m=e[l+1],[v,y]=IWe(m.fromA+r,m.fromB+s,t,n);if(v>f+1&&y>p+1)break;h.push(m.offset(-u+r,-d+s)),[f,p]=AWe(m.toA+r,m.toB+s,t,n),l++}i.push(new Mj(h,u,Math.max(u,f),d,Math.max(d,p),a))}return i}const w9=1e3;function RWe(e,t,n,r){let s=0,a=e.length;for(;;){if(s==a){let d=0,f=0;s&&({toA:d,toB:f}=e[s-1]);let p=t-(n?d:f);return[d+p,f+p]}let i=s+a>>1,l=e[i],[c,u]=n?[l.fromA,l.toA]:[l.fromB,l.toB];if(c>t)a=i;else if(u<=t)s=i+1;else return r?[l.fromA,l.fromB]:[l.toA,l.toB]}}function PWe(e,t,n,r){let s=[];return t.iterChangedRanges((a,i,l,c)=>{let u=0,d=n?t.length:r,f=0,p=n?r:t.length;a>w9&&([u,f]=RWe(e,a-w9,n,!0)),i<t.length-w9&&([d,p]=RWe(e,i+w9,n,!1));let h=c-l-(i-a),m,[v,y]=n?[h,0]:[0,h];s.length&&(m=s[s.length-1]).toA>=u?s[s.length-1]={fromA:m.fromA,fromB:m.fromB,toA:d,toB:p,diffA:m.diffA+v,diffB:m.diffB+y}:s.push({fromA:u,toA:d,fromB:f,toB:p,diffA:v,diffB:y})}),s}function $We(e,t,n,r,s){if(!e.length)return t;let a=[];for(let i=0,l=0,c=0,u=0;;i++){let d=i==e.length?null:e[i],f=d?d.fromA+l:n.length,p=d?d.fromB+c:r.length;for(;u<t.length;){let y=t[u];if(d&&(y.toA+l>f||y.toB+c>p))break;a.push(y.offset(l,c)),u++}if(!d)break;let h=d.toA+l+d.diffA,m=d.toB+c+d.diffB,v=QRt(n.sliceString(f,h),r.sliceString(p,m),s);for(let y of YRt(v,n,r,f,p,GRt()))a.push(y);for(l+=d.diffA,c+=d.diffB;u<t.length;){let y=t[u];if(y.fromA+l>h&&y.fromB+c>m)break;u++}}return a}const i2r={scanLimit:500},XRt=bo.fromClass(class{constructor(e){({deco:this.deco,gutter:this.gutter}=LWe(e))}update(e){(e.docChanged||e.viewportChanged||o2r(e.startState,e.state)||l2r(e.startState,e.state))&&({deco:this.deco,gutter:this.gutter}=LWe(e.view))}},{decorations:e=>e.deco}),S9=Mg.low(Lvt({class:"cm-changeGutter",markers:e=>{var t;return((t=e.plugin(XRt))===null||t===void 0?void 0:t.gutter)||ws.empty}}));function o2r(e,t){return e.field(cx,!1)!=t.field(cx,!1)}function l2r(e,t){return e.facet(cg)!=t.facet(cg)}const MWe=Cn.line({class:"cm-changedLine"}),c2r=Cn.mark({class:"cm-changedText"}),u2r=Cn.mark({tagName:"ins",class:"cm-insertedLine"}),d2r=Cn.mark({tagName:"del",class:"cm-deletedLine"}),DWe=new class extends py{constructor(){super(...arguments),this.elementClass="cm-changedLineGutter"}};function f2r(e,t,n,r,s,a){let i=n?e.fromA:e.fromB,l=n?e.toA:e.toB,c=0;if(i!=l){s.add(i,i,MWe),s.add(i,l,n?d2r:u2r),a&&a.add(i,i,DWe);for(let u=t.iterRange(i,l-1),d=i;!u.next().done;){if(u.lineBreak){d++,s.add(d,d,MWe),a&&a.add(d,d,DWe);continue}let f=d+u.value.length;if(r)for(;c<e.changes.length;){let p=e.changes[c],h=i+(n?p.fromA:p.fromB),m=i+(n?p.toA:p.toB),v=Math.max(d,h),y=Math.min(f,m);if(v<y&&s.add(v,y,c2r),m<f)c++;else break}d=f}}}function LWe(e){let t=e.state.field(cx),{side:n,highlightChanges:r,markGutter:s,overrideChunk:a}=e.state.facet(cg),i=n=="a",l=new kd,c=s?new kd:null,{from:u,to:d}=e.viewport;for(let f of t){if((i?f.fromA:f.fromB)>=d)break;(i?f.toA:f.toB)>u&&(!a||!a(e.state,f,l,c))&&f2r(f,e.state.doc,i,r,l,c)}return{deco:l.finish(),gutter:c&&c.finish()}}class k9 extends Kp{constructor(t){super(),this.height=t}eq(t){return this.height==t.height}toDOM(){let t=document.createElement("div");return t.className="cm-mergeSpacer",t.style.height=this.height+"px",t}updateDOM(t){return t.style.height=this.height+"px",!0}get estimatedHeight(){return this.height}ignoreEvent(){return!1}}const dU=vr.define({map:(e,t)=>e.map(t)}),O2=gl.define({create:()=>Cn.none,update:(e,t)=>{for(let n of t.effects)if(n.is(dU))return n.value;return e.map(t.changes)},provide:e=>It.decorations.from(e)}),O9=.01;function FWe(e,t){if(e.size!=t.size)return!1;let n=e.iter(),r=t.iter();for(;n.value;){if(n.from!=r.from||Math.abs(n.value.spec.widget.height-r.value.spec.widget.height)>1)return!1;n.next(),r.next()}return!0}function p2r(e,t,n){let r=new kd,s=new kd,a=e.state.field(O2).iter(),i=t.state.field(O2).iter(),l=0,c=0,u=0,d=0,f=e.viewport,p=t.viewport;for(let y=0;;y++){let b=y<n.length?n[y]:null,S=b?b.fromA:e.state.doc.length,w=b?b.fromB:t.state.doc.length;if(l<S){let k=e.lineBlockAt(l).top+u,_=t.lineBlockAt(c).top+d,C=k-_;C<-O9?(u-=C,r.add(l,l,Cn.widget({widget:new k9(-C),block:!0,side:-1}))):C>O9&&(d+=C,s.add(c,c,Cn.widget({widget:new k9(C),block:!0,side:-1})))}if(S>l+1e3&&l<f.from&&S>f.from&&c<p.from&&w>p.from){let k=Math.min(f.from-l,p.from-c);l+=k,c+=k,y--}else if(b)l=b.toA,c=b.toB;else break;for(;a.value&&a.from<l;)u-=a.value.spec.widget.height,a.next();for(;i.value&&i.from<c;)d-=i.value.spec.widget.height,i.next()}for(;a.value;)u-=a.value.spec.widget.height,a.next();for(;i.value;)d-=i.value.spec.widget.height,i.next();let h=e.contentHeight+u-(t.contentHeight+d);h<O9?r.add(e.state.doc.length,e.state.doc.length,Cn.widget({widget:new k9(-h),block:!0,side:1})):h>O9&&s.add(t.state.doc.length,t.state.doc.length,Cn.widget({widget:new k9(h),block:!0,side:1}));let m=r.finish(),v=s.finish();FWe(m,e.state.field(O2))||e.dispatch({effects:dU.of(m)}),FWe(v,t.state.field(O2))||t.dispatch({effects:dU.of(v)})}const eve=vr.define({map:(e,t)=>t.mapPos(e)});class h2r extends Kp{constructor(t){super(),this.lines=t}eq(t){return this.lines==t.lines}toDOM(t){let n=document.createElement("div");return n.className="cm-collapsedLines",n.textContent=t.state.phrase("$ unchanged lines",this.lines),n.addEventListener("click",r=>{let s=t.posAtDOM(r.target);t.dispatch({effects:eve.of(s)});let{side:a,sibling:i}=t.state.facet(cg);i&&i().dispatch({effects:eve.of(m2r(s,t.state.field(cx),a=="a"))})}),n}ignoreEvent(t){return t instanceof MouseEvent}get estimatedHeight(){return 27}get type(){return"collapsed-unchanged-code"}}function m2r(e,t,n){let r=0,s=0;for(let a=0;;a++){let i=a<t.length?t[a]:null;if(!i||(n?i.fromA:i.fromB)>=e)return s+(e-r);[r,s]=n?[i.toA,i.toB]:[i.toB,i.toA]}}const g2r=gl.define({create(e){return Cn.none},update(e,t){e=e.map(t.changes);for(let n of t.effects)n.is(eve)&&(e=e.update({filter:r=>r!=n.value}));if(e.size&&t.state.field(cx)!=t.startState.field(cx,!1)){let n=t.state.facet(cg).side=="a",r=[];for(let s of t.state.field(cx))e.between(n?s.fromA:s.fromB,n?s.toA:s.toB,a=>{r.push(a)});r.length&&(e=e.update({filter:s=>r.indexOf(s)<0}))}return e},provide:e=>It.decorations.from(e)});function zWe({margin:e=3,minSize:t=4}){return g2r.init(n=>v2r(n,e,t))}function v2r(e,t,n){let r=new kd,s=e.facet(cg).side=="a",a=e.field(cx),i=1;for(let l=0;;l++){let c=l<a.length?a[l]:null,u=l?i+t:1,d=c?e.doc.lineAt(s?c.fromA:c.fromB).number-1-t:e.doc.lines,f=d-u+1;if(f>=n&&r.add(e.doc.line(u).from,e.doc.line(d).to,Cn.replace({widget:new h2r(f),block:!0})),!c)break;i=e.doc.lineAt(Math.min(e.doc.length,s?c.toA:c.toB)).number}return r.finish()}const y2r=It.styleModule.of(new kx({".cm-mergeView":{overflowY:"auto"},".cm-mergeViewEditors":{display:"flex",alignItems:"stretch"},".cm-mergeViewEditor":{flexGrow:1,flexBasis:0,overflow:"hidden"},".cm-merge-revert":{width:"1.6em",flexGrow:0,flexShrink:0,position:"relative"},".cm-merge-revert button":{position:"absolute",display:"block",width:"100%",boxSizing:"border-box",textAlign:"center",background:"none",border:"none",font:"inherit",cursor:"pointer"}})),b2r=It.baseTheme({".cm-mergeView & .cm-scroller, .cm-mergeView &":{height:"auto !important",overflowY:"visible !important"},"&.cm-merge-a .cm-changedLine, .cm-deletedChunk":{backgroundColor:"rgba(160, 128, 100, .08)"},"&.cm-merge-b .cm-changedLine, .cm-inlineChangedLine":{backgroundColor:"rgba(100, 160, 128, .08)"},"&light.cm-merge-a .cm-changedText, &light .cm-deletedChunk .cm-deletedText":{background:"linear-gradient(#ee443366, #ee443366) bottom/100% 2px no-repeat"},"&dark.cm-merge-a .cm-changedText, &dark .cm-deletedChunk .cm-deletedText":{background:"linear-gradient(#ffaa9966, #ffaa9966) bottom/100% 2px no-repeat"},"&light.cm-merge-b .cm-changedText":{background:"linear-gradient(#22bb22aa, #22bb22aa) bottom/100% 2px no-repeat"},"&dark.cm-merge-b .cm-changedText":{background:"linear-gradient(#88ff88aa, #88ff88aa) bottom/100% 2px no-repeat"},"&.cm-merge-b .cm-deletedText":{background:"#ff000033"},".cm-insertedLine, .cm-deletedLine, .cm-deletedLine del":{textDecoration:"none"},".cm-deletedChunk":{paddingLeft:"6px","& .cm-chunkButtons":{position:"absolute",insetInlineEnd:"5px"},"& button":{border:"none",cursor:"pointer",color:"white",margin:"0 2px",borderRadius:"3px","&[name=accept]":{background:"#2a2"},"&[name=reject]":{background:"#d43"}}},".cm-collapsedLines":{padding:"5px 5px 5px 10px",cursor:"pointer","&:before":{content:'"⦚"',marginInlineEnd:"7px"},"&:after":{content:'"⦚"',marginInlineStart:"7px"}},"&light .cm-collapsedLines":{color:"#444",background:"linear-gradient(to bottom, transparent 0, #f3f3f3 30%, #f3f3f3 70%, transparent 100%)"},"&dark .cm-collapsedLines":{color:"#ddd",background:"linear-gradient(to bottom, transparent 0, #222 30%, #222 70%, transparent 100%)"},".cm-changeGutter":{width:"3px",paddingLeft:"1px"},"&light.cm-merge-a .cm-changedLineGutter, &light .cm-deletedLineGutter":{background:"#e43"},"&dark.cm-merge-a .cm-changedLineGutter, &dark .cm-deletedLineGutter":{background:"#fa9"},"&light.cm-merge-b .cm-changedLineGutter":{background:"#2b2"},"&dark.cm-merge-b .cm-changedLineGutter":{background:"#8f8"},".cm-inlineChangedLineGutter":{background:"#75d"}}),BWe=new LN,_9=new LN;class x2r{constructor(t){this.revertDOM=null,this.revertToA=!1,this.revertToLeft=!1,this.measuring=-1,this.diffConf=t.diffConfig||i2r;let n=[Mg.low(XRt),b2r,y2r,O2,It.updateListener.of(f=>{this.measuring<0&&(f.heightChanged||f.viewportChanged)&&!f.transactions.some(p=>p.effects.some(h=>h.is(dU)))&&this.measure()})],r=[cg.of({side:"a",sibling:()=>this.b,highlightChanges:t.highlightChanges!==!1,markGutter:t.gutter!==!1})];t.gutter!==!1&&r.push(S9);let s=is.create({doc:t.a.doc,selection:t.a.selection,extensions:[t.a.extensions||[],It.editorAttributes.of({class:"cm-merge-a"}),_9.of(r),n]}),a=[cg.of({side:"b",sibling:()=>this.a,highlightChanges:t.highlightChanges!==!1,markGutter:t.gutter!==!1})];t.gutter!==!1&&a.push(S9);let i=is.create({doc:t.b.doc,selection:t.b.selection,extensions:[t.b.extensions||[],It.editorAttributes.of({class:"cm-merge-b"}),_9.of(a),n]});this.chunks=Mj.build(s.doc,i.doc,this.diffConf);let l=[cx.init(()=>this.chunks),BWe.of(t.collapseUnchanged?zWe(t.collapseUnchanged):[])];s=s.update({effects:vr.appendConfig.of(l)}).state,i=i.update({effects:vr.appendConfig.of(l)}).state,this.dom=document.createElement("div"),this.dom.className="cm-mergeView",this.editorDOM=this.dom.appendChild(document.createElement("div")),this.editorDOM.className="cm-mergeViewEditors";let c=t.orientation||"a-b",u=document.createElement("div");u.className="cm-mergeViewEditor";let d=document.createElement("div");d.className="cm-mergeViewEditor",this.editorDOM.appendChild(c=="a-b"?u:d),this.editorDOM.appendChild(c=="a-b"?d:u),this.a=new It({state:s,parent:u,root:t.root,dispatchTransactions:f=>this.dispatch(f,this.a)}),this.b=new It({state:i,parent:d,root:t.root,dispatchTransactions:f=>this.dispatch(f,this.b)}),this.setupRevertControls(!!t.revertControls,t.revertControls=="b-to-a",t.renderRevertControl),t.parent&&t.parent.appendChild(this.dom),this.scheduleMeasure()}dispatch(t,n){if(t.some(r=>r.docChanged)){let r=t[t.length-1],s=t.reduce((i,l)=>i.compose(l.changes),El.empty(t[0].startState.doc.length));this.chunks=n==this.a?Mj.updateA(this.chunks,r.newDoc,this.b.state.doc,s,this.diffConf):Mj.updateB(this.chunks,this.a.state.doc,r.newDoc,s,this.diffConf),n.update([...t,r.state.update({effects:Jge.of(this.chunks)})]);let a=n==this.a?this.b:this.a;a.update([a.state.update({effects:Jge.of(this.chunks)})]),this.scheduleMeasure()}else n.update(t)}reconfigure(t){if("diffConfig"in t&&(this.diffConf=t.diffConfig),"orientation"in t){let a=t.orientation!="b-a";if(a!=(this.editorDOM.firstChild==this.a.dom.parentNode)){let i=this.a.dom.parentNode,l=this.b.dom.parentNode;i.remove(),l.remove(),this.editorDOM.insertBefore(a?i:l,this.editorDOM.firstChild),this.editorDOM.appendChild(a?l:i),this.revertToLeft=!this.revertToLeft,this.revertDOM&&(this.revertDOM.textContent="")}}if("revertControls"in t||"renderRevertControl"in t){let a=!!this.revertDOM,i=this.revertToA,l=this.renderRevert;"revertControls"in t&&(a=!!t.revertControls,i=t.revertControls=="b-to-a"),"renderRevertControl"in t&&(l=t.renderRevertControl),this.setupRevertControls(a,i,l)}let n="highlightChanges"in t,r="gutter"in t,s="collapseUnchanged"in t;if(n||r||s){let a=[],i=[];if(n||r){let l=this.a.state.facet(cg),c=r?t.gutter!==!1:l.markGutter,u=n?t.highlightChanges!==!1:l.highlightChanges;a.push(_9.reconfigure([cg.of({side:"a",sibling:()=>this.b,highlightChanges:u,markGutter:c}),c?S9:[]])),i.push(_9.reconfigure([cg.of({side:"b",sibling:()=>this.a,highlightChanges:u,markGutter:c}),c?S9:[]]))}if(s){let l=BWe.reconfigure(t.collapseUnchanged?zWe(t.collapseUnchanged):[]);a.push(l),i.push(l)}this.a.dispatch({effects:a}),this.b.dispatch({effects:i})}this.scheduleMeasure()}setupRevertControls(t,n,r){this.revertToA=n,this.revertToLeft=this.revertToA==(this.editorDOM.firstChild==this.a.dom.parentNode),this.renderRevert=r,!t&&this.revertDOM?(this.revertDOM.remove(),this.revertDOM=null):t&&!this.revertDOM?(this.revertDOM=this.editorDOM.insertBefore(document.createElement("div"),this.editorDOM.firstChild.nextSibling),this.revertDOM.addEventListener("mousedown",s=>this.revertClicked(s)),this.revertDOM.className="cm-merge-revert"):this.revertDOM&&(this.revertDOM.textContent="")}scheduleMeasure(){if(this.measuring<0){let t=this.dom.ownerDocument.defaultView||window;this.measuring=t.requestAnimationFrame(()=>{this.measuring=-1,this.measure()})}}measure(){p2r(this.a,this.b,this.chunks),this.revertDOM&&this.updateRevertButtons()}updateRevertButtons(){let t=this.revertDOM,n=t.firstChild,r=this.a.viewport,s=this.b.viewport;for(let a=0;a<this.chunks.length;a++){let i=this.chunks[a];if(i.fromA>r.to||i.fromB>s.to)break;if(i.fromA<r.from||i.fromB<s.from)continue;let l=this.a.lineBlockAt(i.fromA).top+"px";for(;n&&+n.dataset.chunk<a;)n=UWe(n);n&&n.dataset.chunk==String(a)?(n.style.top!=l&&(n.style.top=l),n=n.nextSibling):t.insertBefore(this.renderRevertButton(l,a),n)}for(;n;)n=UWe(n)}renderRevertButton(t,n){let r;if(this.renderRevert)r=this.renderRevert();else{r=document.createElement("button");let s=this.a.state.phrase("Revert this chunk");r.setAttribute("aria-label",s),r.setAttribute("title",s),r.textContent=this.revertToLeft?"⇜":"⇝"}return r.style.top=t,r.setAttribute("data-chunk",String(n)),r}revertClicked(t){let n=t.target,r;for(;n&&n.parentNode!=this.revertDOM;)n=n.parentNode;if(n&&(r=this.chunks[n.dataset.chunk])){let[s,a,i,l,c,u]=this.revertToA?[this.b,this.a,r.fromB,r.toB,r.fromA,r.toA]:[this.a,this.b,r.fromA,r.toA,r.fromB,r.toB],d=s.state.sliceDoc(i,Math.max(i,l-1));i!=l&&u<=a.state.doc.length&&(d+=s.state.lineBreak),a.dispatch({changes:{from:c,to:Math.min(a.state.doc.length,u),insert:d},userEvent:"revert"}),t.preventDefault()}}destroy(){this.a.destroy(),this.b.destroy(),this.measuring>-1&&(this.dom.ownerDocument.defaultView||window).cancelAnimationFrame(this.measuring),this.dom.remove()}}function UWe(e){let t=e.nextSibling;return e.remove(),t}const w2r=It.theme({"&.cm-editor .cm-changedLine":{backgroundColor:"transparent",backgroundImage:"none",borderLeft:"none"},"&.cm-editor .cm-changedText":{backgroundImage:"none",backgroundColor:"#880000",padding:"1px 5px",display:"inline-block",borderRadius:"4px"},"&.cm-editor .cm-changedText, &.cm-editor .cm-changedText *":{color:"white"},"&.cm-editor .cm-line":{lineHeight:"1.5",opacity:"0.5"},"&.cm-editor .cm-line.cm-changedLine":{opacity:"1"},"&.cm-editor .cm-gutters":{display:"none"}});function S2r(){return UN({settings:{fontFamily:"var(--font-mono)",fontSize:"0.8125rem",lineHighlight:"transparent",gutterBackground:"transparent",gutterForeground:"#939393",background:"transparent"},styles:[{tag:[fe.className,fe.propertyName]}]})}function k2r(){const e=It.theme({"&":{backgroundColor:"transparent",color:"var(--neutral6)",fontSize:"0.8125rem"},"&.cm-editor .cm-scroller":{fontFamily:"var(--font-mono)"},".cm-gutters":{backgroundColor:"transparent",color:"var(--neutral2)",borderRight:"none"},".cm-content":{color:"var(--neutral6)"},".cm-activeLine":{backgroundColor:"transparent"},".cm-activeLineGutter":{backgroundColor:"transparent"}}),t=Dg.define([{tag:[fe.comment,fe.bracket],color:"var(--neutral2)"},{tag:[fe.string,fe.meta,fe.regexp],color:"var(--accent1)"},{tag:[fe.atom,fe.bool,fe.special(fe.variableName)],color:"var(--accent6)"},{tag:[fe.keyword,fe.operator,fe.tagName],color:"var(--accent2)"},{tag:[fe.function(fe.propertyName),fe.propertyName],color:"var(--accent5)"},{tag:[fe.definition(fe.variableName),fe.function(fe.variableName),fe.className,fe.attributeName],color:"var(--accent3)"},{tag:[fe.variableName,fe.number],color:"var(--accent5)"},{tag:[fe.name,fe.quote],color:"var(--accent1)"}]);return[e,B1(t)]}function $_e({codeA:e,codeB:t}){const n=g.useRef(null),r=g.useRef(null),s=PN().resolvedTheme==="dark",a=g.useMemo(()=>s?S2r():k2r(),[s]);return g.useEffect(()=>{if(!n.current)return;r.current&&r.current.destroy();const i=[gT(),a,w2r,It.lineWrapping,is.readOnly.of(!0)],l=new x2r({parent:n.current,a:{doc:e,extensions:i},b:{doc:t,extensions:i},collapseUnchanged:{margin:3,minSize:4}});return r.current=l,()=>{l.destroy(),r.current=null}},[e,t,a]),o.jsxs("div",{className:"relative overflow-auto rounded-xl border dark:border-white/10 border-border1 dark:bg-black/20 bg-surface3",children:[o.jsx("div",{className:"absolute left-1/2 top-0 h-full w-px dark:bg-white/10 bg-border1 z-10"}),o.jsx("div",{ref:n,className:"[&_.cm-mergeViewEditor]:flex-1 [&_.cm-editor]:bg-transparent [&_.cm-editor]:p-6 [&_.cm-gutters]:bg-transparent"})]})}function O2r(e){if(!e)return null;const t=e.match(/^(\d{1,2}):(\d{2})$/);if(!t)return e;const[,n,r]=t,s=Number(n),a=s>=12?"PM":"AM";return`${s%12||12}:${r} ${a}`}function _2r(e){return e==="🔴"?"high":e==="🟡"?"medium":e==="🟢"?"low":e==="✅"?"complete":null}function C2r(e,t){if(t)return{card:"bg-transparent border-transparent",text:"text-neutral3",time:"text-icon3"};switch(e){case"high":return{card:"border-purple-400/30 bg-purple-500/10",text:"text-neutral6",time:"text-purple-200/80"};case"medium":return{card:"border-blue-400/30 bg-blue-500/10",text:"text-neutral6",time:"text-blue-200/80"};case"low":return{card:"border-emerald-400/30 bg-emerald-500/10",text:"text-neutral6",time:"text-emerald-200/80"};case"complete":return{card:"border-green-400/30 bg-green-500/10",text:"text-neutral6",time:"text-green-200/80"};default:return{card:"border-border1 bg-surface2",text:"text-neutral6",time:"text-icon3"}}}function E2r(e){const t=e.trim();if(!t)return null;if(t.startsWith("* ->")||t.startsWith("->")){const n=t.replace(/^\*?\s*->\s*/,"").trim();return n?{text:n,time:null,priority:null,children:[]}:null}if(t.startsWith("-")){const n=t.replace(/^-\s*/,"").trim();return n?{text:n,time:null,priority:null,children:[]}:null}if(t.startsWith("*")){let n=t.slice(1).trimStart(),r=null;for(const i of["🔴","🟡","🟢","✅"])if(n.startsWith(i)){r=_2r(i),n=n.slice(i.length).trimStart();break}let s=null;const a=n.match(/^\((\d{1,2}:\d{2})\)/);if(a&&(s=a[1],n=n.slice(a[0].length).trimStart()),n)return{text:n,time:s,priority:r,children:[]}}return{text:t,time:null,priority:null,children:[]}}function j2r(e){const t="<observations>",n=e.indexOf(t),r=n===-1?-1:e.indexOf("</observations>",n+t.length),s=(r===-1?e:e.slice(n+t.length,r)).trim();if(!s)return[];const a=s.split(`
|
|
512
|
+
`),i=[];let l=null,c=null;for(const u of a){const d=u.trim();if(!d)continue;if(d.startsWith("Date:")){let m=d.slice(5).trim(),v=null;if(m.endsWith(")")){const y=m.lastIndexOf("("),b=y===-1?"":m.slice(y+1,-1);y>0&&b&&!b.includes(")")&&(v=b.trim(),m=m.slice(0,y).trim())}if(m){l={title:m,relativeTime:v,items:[]},i.push(l),c=null;continue}}l||(l={title:"Recent",relativeTime:null,items:[]},i.push(l));const p=(u.match(/^(\s*)/)?.[1].length??0)>=2&&(d.startsWith("* ->")||d.startsWith("->")||d.startsWith("-")),h=E2r(u);if(h){if(p&&c){c.children.push(h);continue}l.items.push(h),c=h}}return i}function KRt({items:e,nested:t=!1}){return o.jsx("div",{className:t?"space-y-2 border-l border-border1 pl-4":"space-y-3",children:e.map((n,r)=>{const s=C2r(n.priority,t);return o.jsx("div",{className:"space-y-2",children:o.jsxs("div",{className:"flex items-start gap-3",children:[o.jsx("div",{className:"w-12 shrink-0 pt-2 text-right",children:n.time&&o.jsx("span",{className:`font-mono text-ui-xs ${s.time}`,children:O2r(n.time)})}),o.jsxs("div",{className:K("min-w-0 flex-1 rounded-md border px-3 py-2",s.card),children:[o.jsx("p",{className:K("whitespace-pre-wrap break-words text-sm leading-6",s.text),children:n.text}),n.children.length>0&&o.jsx("div",{className:"mt-3",children:o.jsx(KRt,{items:n.children,nested:!0})})]})]})},`${n.text.slice(0,20)}-${r}`)})})}function T2r({observations:e}){const t=g.useMemo(()=>j2r(e),[e]);return t.length===0?o.jsx("p",{className:"italic text-xs text-icon3",children:"Initialized"}):o.jsx("div",{className:"space-y-5",children:t.map((n,r)=>o.jsxs("section",{className:"space-y-3",children:[o.jsx("div",{className:"flex items-baseline justify-between gap-3 border-b border-border1 pb-2",children:o.jsxs("div",{className:"min-w-0",children:[o.jsx("h3",{className:"text-xs font-medium text-neutral6",children:n.title}),n.relativeTime&&o.jsx("p",{className:"text-ui-xs text-icon3",children:n.relativeTime})]})}),o.jsx(KRt,{items:n.items})]},`${n.title}-${r}`))})}function N2r({records:e,selectedRecordId:t,onSelectRecord:n}){return e.length<=1?null:o.jsxs("div",{className:"border-l border-border1 min-w-[180px] w-[200px] flex flex-col overflow-hidden",children:[o.jsx("div",{className:"border-b border-border1 px-4 py-2",children:o.jsx("p",{className:"text-sm font-normal text-neutral6",children:"History"})}),o.jsx("div",{className:"flex-1 overflow-y-auto",children:e.map(r=>{const s=r.id===t;return o.jsx("button",{type:"button",className:K("w-full cursor-pointer border-l-2 border-l-transparent px-3 py-2 text-left truncate text-xs text-icon3 transition-all hover:bg-surface3/50",s&&"bg-surface3/50 border-l-accent1"),onClick:()=>n(r.id),children:r.activeObservations||o.jsx("span",{className:"italic text-icon3",children:r.isObserving||r.isReflecting?"Processing…":"Initialized"})},r.id)})})]})}function I2r({records:e,selectedRecordId:t,onSelectRecord:n,isLoading:r}){const[s,a]=g.useState(!1),i=g.useMemo(()=>[...e].sort((f,p)=>new Date(f.createdAt).getTime()-new Date(p.createdAt).getTime()),[e]),l=t?i.find(f=>f.id===t):i[i.length-1],c=l?i.findIndex(f=>f.id===l.id):-1,u=c>0?i[c-1]:null;if(g.useEffect(()=>{!t&&i.length>0&&n(i[i.length-1].id)},[t,i,n]),r)return o.jsxs("div",{className:"p-4 space-y-4",children:[o.jsx(bt,{className:"h-6 w-40"}),o.jsx(bt,{className:"h-32 w-full"}),o.jsx(bt,{className:"h-32 w-full"})]});if(!l)return o.jsx("div",{className:"flex h-full items-center justify-center",children:o.jsx(Cr,{iconSlot:o.jsx(spt,{className:"size-4"}),titleSlot:"No observations",descriptionSlot:"No observational memory snapshots available for this thread."})});const d=typeof l.activeObservations=="string"?l.activeObservations:"";return o.jsxs("div",{className:"flex h-full w-full overflow-hidden",children:[o.jsxs("div",{className:"flex min-w-0 flex-1 flex-col overflow-hidden",children:[u&&o.jsx("div",{className:"border-b border-border1 px-4 py-2",children:o.jsx("div",{className:"flex items-start justify-end gap-3",children:o.jsxs("label",{className:"flex cursor-pointer items-center gap-1.5",children:[o.jsx(Mo,{checked:s,onCheckedChange:f=>a(f===!0)}),o.jsx("span",{className:"text-xs text-icon3",children:"Show diff"})]})})}),o.jsx("div",{"data-testid":"observation-detail-body",className:"flex-1 overflow-y-auto p-4",children:s&&u?o.jsx($_e,{codeA:typeof u.activeObservations=="string"?u.activeObservations:"",codeB:d}):d?o.jsx(T2r,{observations:d}):o.jsx("p",{className:"italic text-xs text-icon3",children:l.isObserving||l.isReflecting?"Processing…":"Initialized"})})]}),o.jsx(N2r,{records:i,selectedRecordId:l.id,onSelectRecord:n})]})}function qWe(e){if(e===0)return"0";const t=e/1e3,n=t<.1?2:1;return t.toFixed(n).replace(/\.0+$/,"").replace(/(\.\d*[1-9])0$/,"$1")}function VWe({label:e,value:t,max:n,tone:r}){const s=Math.max(0,Math.min(100,t/n*100)),a=r==="message"?"bg-blue-500/80":"bg-violet-500/80";return o.jsxs("div",{className:"min-w-0 flex-1",children:[o.jsxs("div",{className:"mb-1 flex items-center justify-between gap-2 font-mono text-ui-xs text-icon3",children:[o.jsx("span",{className:"uppercase tracking-wide text-icon6",children:e}),o.jsxs("span",{className:"tabular-nums text-icon3",children:[qWe(t),"/",qWe(n),"k"]})]}),o.jsx("div",{className:"h-1.5 overflow-hidden rounded-full bg-white/[0.08]",children:o.jsx("div",{className:`h-full rounded-full ${a}`,style:{width:`${s}%`}})})]})}function A2r({messageTokens:e,messageThreshold:t,memoryTokens:n,memoryThreshold:r,memoryLabel:s="Memory"}){const a=e!=null&&t!=null,i=n!=null&&r!=null;return!a&&!i?null:o.jsx("div",{className:"border-b border-border1 px-3 py-2",children:o.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row",children:[a?o.jsx(VWe,{label:"Messages",value:e,max:t,tone:"message"}):null,i?o.jsx(VWe,{label:s,value:n,max:r,tone:"memory"}):null]})})}function R2r({messages:e,omRecords:t,isLoading:n=!1,onClose:r,selectedTimestamp:s,onSelectTimestamp:a,contextWindow:i}){const[l,c]=g.useState(null),u=g.useMemo(()=>PRr(e),[e]),d=g.useMemo(()=>e.length===0?{tMin:0,tMax:1}:$Rr(e.map(_=>new Date(_.createdAt).toISOString())),[e]),f=g.useMemo(()=>zRr({markers:u,omRecords:t}),[u,t]),p=i?.memoryTokens??f?.memoryTokens,h=i?.memoryThreshold??f?.memoryThreshold,[m,v]=g.useState({left:d.tMin,right:d.tMax});g.useEffect(()=>{v({left:d.tMin,right:d.tMax})},[d.tMin,d.tMax]);const y=m.left<=d.tMin&&m.right>=d.tMax,b=g.useMemo(()=>y?t:t.filter(_=>{const C=DRr(_);return C>=m.left&&C<=m.right}),[t,y,m.left,m.right]),S=g.useMemo(()=>s!=null?LRr(b,s):null,[b,s]),w=l!=null&&b.some(_=>_.id===l)?l:null,k=S??w;return o.jsxs("div",{className:"flex h-full w-full flex-col overflow-hidden",children:[o.jsxs("div",{className:"flex shrink-0 items-center gap-2 border-b border-border1 px-3 py-2.5",children:[o.jsx(de,{type:"button",variant:"ghost",size:"icon-sm",tooltip:"Back to memory",onClick:()=>r?.(),children:o.jsx(Zq,{})}),o.jsxs("span",{className:"flex min-w-0 items-center gap-1.5 text-neutral6",children:[o.jsx(H3,{className:"h-4 w-4 shrink-0"}),o.jsx(ge,{as:"span",variant:"ui-sm",className:"font-medium",children:"Observational memory"})]})]}),n?o.jsxs("div",{"data-testid":"memory-studio-loading",className:"flex flex-1 flex-col gap-3 p-4",children:[o.jsx(bt,{className:"h-6 w-40"}),o.jsx(bt,{className:"h-32 w-full"}),o.jsx(bt,{className:"h-16 w-full"})]}):o.jsxs("div",{className:"grid min-h-0 flex-1 grid-rows-[1fr_auto] overflow-hidden",children:[o.jsx("div",{className:"min-h-0 flex flex-col overflow-hidden",children:o.jsx(I2r,{records:b,selectedRecordId:k,onSelectRecord:c,isLoading:n})}),o.jsxs("div",{className:"border-t border-border1",children:[o.jsx(A2r,{messageTokens:i?.messageTokens??f?.messageTokens,messageThreshold:i?.messageThreshold??f?.messageThreshold,memoryTokens:p,memoryThreshold:h,memoryLabel:"Observations"}),o.jsx(JRr,{omRecords:t,markers:u,messages:e,tDomain:d,onSelectTimestamp:a,zoomRange:m,onZoomRangeChange:v})]})]})]})}const fU=(e,t)=>["memory","thread",e,"messages",t??0];function P2r(e,t){const n=We(),r=0,s=100;return wt({queryKey:fU(e,r),queryFn:e?()=>n.getMemoryThread({threadId:e}).listMessages({page:r,perPage:s}):jy})}const pU=(e,t)=>["memory","observational-memory",e,t];function $2r(e,t,n){const r=We();return wt({queryKey:pU(e,t),queryFn:e&&t?()=>r.getObservationalMemory({agentId:e,threadId:t,resourceId:n}):jy})}const M2r=2e3;function D2r({agentId:e,threadId:t}){const{isPanelOpen:n,closePanel:r,selectedTimestamp:s,setSelectedTimestamp:a}=AW(),{isObservingFromStream:i,isReflectingFromStream:l,observationsUpdatedAt:c,streamProgress:u}=IW(),d=i||l,{data:f}=pRt({threadId:t,agentId:e}),p=f?.resourceId??e,{data:h}=G_(e),{data:m,isLoading:v,refetch:y}=$2r(n?e:void 0,n?t:void 0,p),{data:b,isLoading:S,refetch:w}=P2r(n?t:void 0);if(g.useEffect(()=>{!n||c===0||(y(),w())},[n,c,y,w]),g.useEffect(()=>{if(!n||!d)return;const E=setInterval(()=>{y(),w()},M2r);return()=>clearInterval(E)},[n,d,y,w]),!n)return null;const k=h?.config?.observationalMemory,_=u?.threadId===t?u:null,C=bRt({record:m?.record,liveProgress:_,agentConfig:k});return o.jsx("div",{"data-testid":"memory-sidebar-om-detail-subpanel",className:"h-full min-h-0 min-w-0 overflow-hidden bg-surface3",children:o.jsx(R2r,{messages:b?.messages??[],omRecords:m?.history??[],isLoading:v||S,onClose:r,selectedTimestamp:s,onSelectTimestamp:a,contextWindow:{messageTokens:C.messageTokens,messageThreshold:C.messageThreshold,memoryTokens:C.observationTokens,memoryThreshold:C.observationThreshold}})})}function L2r(e){if(e!==!1)return e}function F2r(e){const{data:t}=G_(e),n=t?.config;return{lastMessages:L2r(n?.lastMessages),semanticRecallOn:!!n?.semanticRecall,workingMemoryOn:!!n?.workingMemory?.enabled,observationalOn:!!n?.observationalMemory?.enabled}}const HWe="agent-memory-sidebar-tab-v2",z2r=()=>{const[e,t]=g.useState(()=>{const r=sessionStorage.getItem(HWe)||"threads";return r==="threads"||r==="memory"?r:"threads"}),n=g.useCallback(r=>{t(r),sessionStorage.setItem(HWe,r)},[]);return{selectedTab:e,handleTabChange:n}},B2r=({threads:e,threadId:t,onDelete:n,resourceId:r,resourceType:s,embedded:a=!1})=>{const{Link:i,paths:l}=yn(),[c,u]=g.useState(null),{canDelete:d}=il(),f=d("memory"),p=s==="agent"?l.agentNewThreadLink(r):l.networkNewThreadLink(r);return o.jsxs(o.Fragment,{children:[o.jsxs(Zwt,{embedded:a,children:[o.jsxs(wGn,{as:i,to:p,children:[o.jsx(Ue,{children:o.jsx(Vr,{})}),"New Chat"]}),o.jsx(SGn,{}),e.length===0?o.jsx(Ywt,{children:"Your conversations will appear here once you start chatting!"}):o.jsx(Gwt,{children:e.map(h=>{const m=h.id===t,v=s==="agent"?l.agentThreadLink(r,h.id):l.networkThreadLink(r,h.id);return o.jsx(Qwt,{as:i,to:v,isActive:m,onDelete:f?()=>u(h.id):void 0,deleteLabel:"delete thread",children:o.jsx(V2r,{title:h.title,id:h.id,createdAt:h.createdAt})},h.id)})})]}),o.jsx(U2r,{open:!!c,onOpenChange:()=>u(null),onDelete:()=>{c&&n(c)}})]})},U2r=({open:e,onOpenChange:t,onDelete:n})=>o.jsx(Tt,{open:e,onOpenChange:t,children:o.jsxs(Tt.Content,{children:[o.jsxs(Tt.Header,{children:[o.jsx(Tt.Title,{children:"Are you absolutely sure?"}),o.jsx(Tt.Description,{children:"This action cannot be undone. This will permanently delete your chat and remove it from our servers."})]}),o.jsxs(Tt.Footer,{children:[o.jsx(Tt.Cancel,{children:"Cancel"}),o.jsx(Tt.Action,{onClick:n,children:"Continue"})]})]})});function q2r(e){return/^New Thread \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?Z$/.test(e)}function V2r({title:e,id:t,createdAt:n}){const r=e&&!q2r(e)?e:n?H2r(n):`Thread ${t?t.substring(t.length-5):""}`;return o.jsx("span",{className:"block truncate",children:r})}const H2r=e=>{const t={month:"short",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",hour12:!0};return new Date(e).toLocaleString("en-us",t).replace(","," at")};function M_e({children:e,className:t}){return o.jsx("div",{className:K("bg-surface3 rounded-tr-studio-panel border-t border-r border-border1/50 flex h-full w-full min-h-0 min-w-0 flex-col overflow-hidden",t),children:e})}const W2r=e=>e>=85?"bg-orange-400":e>=60?"bg-blue-500":"bg-green-500";function C9({icon:e,label:t,tooltip:n,enabled:r,value:s,expanded:a}){return o.jsxs(Wn,{children:[o.jsx(zn,{asChild:!0,children:o.jsxs("span",{className:K("inline-flex items-center gap-1 rounded-full border px-1.5 py-0.5 transition-colors duration-normal",r?"border-border1 bg-surface4 text-neutral6":"border-border1/40 text-neutral3/50"),children:[o.jsx(e,{className:"h-3 w-3 shrink-0"}),s!==void 0&&o.jsx(ge,{as:"span",variant:"ui-xs",className:"font-medium tabular-nums leading-none",children:s}),a&&o.jsx(ge,{as:"span",variant:"ui-xs",className:"whitespace-nowrap leading-none",children:t})]})}),o.jsx(Bn,{children:n})]})}function Z2r(){return o.jsxs("div",{"data-testid":"memory-sidebar-skeleton",className:"flex h-full min-h-0 w-full flex-col gap-2.5 p-3",children:[o.jsx(bt,{className:"h-3 w-28"}),o.jsx(bt,{className:"h-3 w-20"}),o.jsx(bt,{className:"h-3 w-24"}),o.jsx(bt,{className:"h-3 w-16"})]})}function G2r({agentId:e,threadId:t,threads:n,onDelete:r}){return o.jsx(M_e,{children:o.jsx(Q2r,{agentId:e,threadId:t,threads:n,onDelete:r})})}function Q2r({agentId:e,threadId:t,threads:n,onDelete:r}){const{data:s,isLoading:a}=Z_(e),i=!!s?.result,l=s?.memoryType,{selectedTab:c,handleTabChange:u}=z2r(),{isPanelOpen:d}=AW(),{streamProgress:f}=IW(),{lastMessages:p,semanticRecallOn:h,workingMemoryOn:m,observationalOn:v}=F2r(e),y=c==="memory",b=g.useRef(null),S=g.useRef(null),[w,k]=g.useState({height:0,offset:0}),_=v&&d,C=f?.threadId===t?f.windows?.active?.messages:void 0,E=C&&C.threshold>0?Math.min(100,Math.round(C.tokens/C.threshold*100)):void 0;return g.useLayoutEffect(()=>{if(y||_||!i)return;const j=b.current,N=S.current;if(!j||!N)return;const I=()=>{const P=getComputedStyle(j),L=Number.parseFloat(P.borderTopWidth)||0,M=Number.parseFloat(P.borderBottomWidth)||0,q=Number.parseFloat(P.marginTop)||0,H=Number.parseFloat(P.marginBottom)||0,F=Math.ceil(N.getBoundingClientRect().height+L+M),z=Math.ceil(F+q+H);k(B=>B.height===F&&B.offset===z?B:{height:F,offset:z})};if(I(),typeof ResizeObserver>"u")return;const R=new ResizeObserver(I);return R.observe(N),()=>R.disconnect()},[i,p,E,v,h,y,_,m]),a?o.jsx(Z2r,{}):_?o.jsx("div",{"data-testid":"memory-sidebar-panel",className:"h-full min-h-0 min-w-0",children:o.jsx(D2r,{agentId:e,threadId:t})}):o.jsxs("div",{className:"flex h-full min-h-0 w-full flex-col overflow-hidden",children:[o.jsxs("div",{className:"relative min-h-0 flex-1 overflow-hidden",children:[o.jsx("div",{"aria-hidden":y&&i,inert:y&&i?!0:void 0,"data-testid":"memory-sidebar-thread-layer",className:K("memory-sidebar-thread-layer absolute inset-0 flex min-h-0 flex-col overflow-hidden",y&&i?"pointer-events-none opacity-0":"opacity-100"),children:o.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",style:{paddingBottom:i&&w.offset||void 0},children:i?o.jsx(B2r,{resourceId:e,resourceType:"agent",threads:n,threadId:t,onDelete:r,embedded:!0}):o.jsx(Cr,{iconSlot:null,titleSlot:"Memory not enabled",descriptionSlot:"Conversations are only saved as threads when the agent has memory configured.",actionSlot:o.jsx(de,{as:"a",href:"https://mastra.ai/docs/memory/overview",target:"_blank",rel:"noopener noreferrer",variant:"outline",children:"View documentation"})})})}),i?o.jsxs("div",{ref:b,"data-testid":"memory-sidebar-overlay",className:K("memory-sidebar-overlay absolute inset-x-0 bottom-0 z-10 box-border flex min-h-0 flex-col overflow-hidden border",y?"m-0 rounded-none border-transparent bg-surface3 shadow-none":"m-1 rounded-xl border-border1/40 bg-surface4 hover:bg-surface5 active:bg-surface4"),style:{height:y?"100%":w.height||void 0},children:[o.jsxs("button",{ref:S,type:"button",onClick:()=>u(y?"threads":"memory"),"aria-pressed":y,"data-testid":"memory-sidebar-card",className:"group/memory-card w-full shrink-0 cursor-pointer bg-transparent px-3 py-2.5 text-left",children:[o.jsxs("span",{className:"flex items-center justify-between gap-2",children:[o.jsxs("span",{className:"flex min-w-0 items-center gap-1.5 text-neutral6",children:[o.jsx(H3,{className:"h-4 w-4 shrink-0"}),o.jsx(ge,{as:"span",variant:"ui-sm",className:"font-medium",children:"Memory"})]}),y?o.jsx(Sa,{className:"h-4 w-4 shrink-0 text-neutral3"}):o.jsx(f_,{className:"h-4 w-4 shrink-0 text-neutral3"})]}),o.jsx(sc,{delay:150,timeout:400,children:o.jsxs("span",{className:"mt-1.5 flex flex-wrap items-center gap-1.5",children:[o.jsx(C9,{icon:Yj,label:"recent messages",tooltip:p!==void 0?`Keeps the last ${p} messages in context`:"Recent message history is off",enabled:p!==void 0,value:p,expanded:y}),o.jsx(C9,{icon:Xa,label:"Semantic recall",tooltip:h?"Semantic recall is on - retrieves relevant past messages":"Semantic recall is off",enabled:h,expanded:y}),o.jsx(C9,{icon:Tdn,label:"Working memory",tooltip:m?"Working memory is on - persists notes across the conversation":"Working memory is off",enabled:m,expanded:y}),o.jsx(C9,{icon:Kc,label:"Observational",tooltip:v?"Observational memory is on - learns from the conversation":"Observational memory is off",enabled:v,expanded:y})]})}),E!==void 0?o.jsx("span",{className:"mt-2 block h-1 w-full overflow-hidden rounded-full bg-surface5",children:o.jsx("span",{className:K("block h-full rounded-full transition-all duration-normal",W2r(E)),style:{width:`${E}%`}})}):null]}),y&&o.jsx("div",{className:"memory-card-content min-h-0 flex-1 overflow-y-auto border-t border-border1",children:o.jsx(TRr,{agentId:e,threadId:t,memoryType:l})})]}):null]}),o.jsx(cRr,{agentId:e})]})}function Y2r({agentId:e,threadId:t,threads:n}){const{mutateAsync:r}=rRr(),{paths:s,navigate:a}=yn(),i=async l=>{await r({threadId:l,agentId:e}),l===t&&a(s.agentNewThreadLink(e))};return o.jsx(G2r,{agentId:e,threadId:t,threads:n,onDelete:i})}const tve=(e,t)=>["memory","status",e,t],JRt=g.createContext({messages:[]}),e2t=g.createContext({isRunning:!1,cancelRun:()=>{},canSendWhileStreaming:!1}),t2t=g.createContext({send:()=>{}}),n2t=g.createContext({tasks:[]}),X2r=()=>g.useContext(JRt).messages,r2t=()=>g.useContext(e2t),s2t=()=>g.useContext(t2t).send,K2r=()=>g.useContext(n2t).tasks,a2t="mastra-memory-om-observation",WWe={"data-om-observation-start":"start","data-om-observation-end":"end","data-om-observation-failed":"failed","data-om-buffering-start":"bufferingStart","data-om-buffering-end":"bufferingEnd","data-om-buffering-failed":"bufferingFailed","data-om-activation":"activation"},i2t=(e,t)=>{for(const n of e){if(!(n.type in WWe))continue;const r=n,s=r.data?.cycleId;if(!s)continue;const a=WWe[r.type],i=t.get(s)||{};i[a]=r,t.set(s,i)}return t},D_e=e=>!!e&&typeof e=="object"&&!Array.isArray(e)&&Object.keys(e).length>0,L_e=e=>Array.isArray(e)&&e.length>0,Mk=e=>({...D_e(e?.extractedValues)?{extractedValues:e.extractedValues}:{},...L_e(e?.extractionFailures)?{extractionFailures:e.extractionFailures}:{}}),rj=e=>Object.keys(Mk(e)).length>0,E9=(e,t)=>{if(!e?.data||!t)return e;const n=Mk(e.data),r=Mk(t);if(!Object.keys(r).length)return e;const s={...n.extractedValues??r.extractedValues?{extractedValues:n.extractedValues??r.extractedValues}:{},...n.extractionFailures??r.extractionFailures?{extractionFailures:n.extractionFailures??r.extractionFailures}:{}};return{...e,data:{...e.data,...s}}},J2r=(e,t)=>{for(const[n,r]of e){const s=t.get(n);s&&(r.end=E9(r.end,s.end),r.failed=E9(r.failed,s.failed),r.bufferingEnd=E9(r.bufferingEnd,s.bufferingEnd),r.bufferingFailed=E9(r.bufferingFailed,s.bufferingFailed));const a={...s??{}};rj(r.end?.data)&&(a.end=Mk(r.end?.data)),rj(r.failed?.data)&&(a.failed=Mk(r.failed?.data)),rj(r.bufferingEnd?.data)&&(a.bufferingEnd=Mk(r.bufferingEnd?.data)),rj(r.bufferingFailed?.data)&&(a.bufferingFailed=Mk(r.bufferingFailed?.data)),Object.keys(a).length>0&&t.set(n,a)}return e},ePr=(e,t)=>{const n=new Map;for(const r of e){const s=r?.content?.parts;Array.isArray(s)&&i2t(s,n)}return t?J2r(n,t):n},tPr=(e,t)=>{const n=t.start?.data;if(!n)return;const r=t.end?.data,s=t.failed?.data,a=!!t.failed,i=!!t.end,l=!!n.disconnectedAt||i&&!!r?.disconnectedAt,c=a?"failed":l?"disconnected":i?"observed":"observing",u={...n,...i?r:{},...a?s:{},_state:a?"failed":l?"disconnected":i?"complete":"loading"};return{cycleId:e,recordId:typeof u.recordId=="string"?u.recordId:void 0,status:c,operationType:u.operationType,observations:u.observations,extractedValues:D_e(u.extractedValues)?u.extractedValues:void 0,extractionFailures:L_e(u.extractionFailures)?u.extractionFailures:void 0,omData:u,isLoading:c==="observing"}},nPr=(e,t)=>{const n=t.bufferingStart?.data;if(!n)return;const r=t.bufferingEnd?.data,s=t.bufferingFailed?.data,a=t.activation?.data,i=!!t.bufferingFailed,l=!!t.activation,c=!!t.bufferingEnd,u=!!n.disconnectedAt,d=i?"buffering-failed":u?"disconnected":c?"buffering-complete":l?"activated":"buffering",f={...n,...c?r:{},...i?s:{},...l?a:{},_state:d};return!f.tokensObserved&&f.tokensActivated&&(f.tokensObserved=f.tokensActivated),{cycleId:e,recordId:typeof f.recordId=="string"?f.recordId:void 0,status:d,operationType:f.operationType,observations:f.observations,extractedValues:D_e(f.extractedValues)?f.extractedValues:void 0,extractionFailures:L_e(f.extractionFailures)?f.extractionFailures:void 0,omData:f,isLoading:d==="buffering"}},j9=(e,t,n)=>n==="observation"?tPr(e,t):nPr(e,t),T9=(e,t,n)=>({type:"dynamic-tool",toolCallId:`om-${t}-${e}`,toolName:a2t,input:n.omData,output:n.isLoading?void 0:{status:t==="observation"?n.status==="failed"?"failed":n.status==="disconnected"?"disconnected":"complete":n.status,omData:n.omData},state:n.isLoading?"input-available":"output-available"}),ZWe=(e,t)=>t==="observation"?!!e?.end||!!e?.failed:!!e?.bufferingEnd||!!e?.bufferingFailed,GWe=(e,t)=>t==="observation"?e==="data-om-observation-end"||e==="data-om-observation-failed":e==="data-om-buffering-end"||e==="data-om-buffering-failed"||e==="data-om-activation",rPr=(e,t)=>{if(!e||!Array.isArray(e.content?.parts))return e;const n=i2t(e.content.parts,new Map),r=[];for(const s of e.content.parts){const a=s.data?.cycleId,i=s.type;if(i==="data-om-observation-start"&&a){const l=n.get(a),c=t.get(a);if(!l)continue;const u=ZWe(c,"observation")?c??l:{start:l.start},d=j9(a,u,"observation");if(!d)continue;r.push(T9(a,"observation",d))}else if(i==="data-om-buffering-start"&&a){const l=n.get(a),c=t.get(a);if(!l)continue;const u=ZWe(c,"buffering")?c??l:{bufferingStart:l.bufferingStart},d=j9(a,u,"buffering");if(!d)continue;r.push(T9(a,"buffering",d))}else if(a&&GWe(i,"observation")){const l=n.get(a),c=t.get(a);if(l?.start||c?.start||!c)continue;const u=j9(a,c,"observation");if(!u)continue;r.push(T9(a,"observation",u))}else if(a&&GWe(i,"buffering")){const l=n.get(a),c=t.get(a);if(l?.bufferingStart||c?.bufferingStart||i==="data-om-activation"&&(l?.bufferingEnd||l?.bufferingFailed)||!c)continue;const u=j9(a,c,"buffering");if(!u)continue;r.push(T9(a,"buffering",u))}else{if(i?.startsWith("data-om-"))continue;r.push(s)}}return{...e,content:{...e.content,parts:r}}},o2t=(e,t)=>e.map(n=>{if(n.role!=="assistant")return n;const r=n.content?.parts;if(!Array.isArray(r))return n;const{parts:s,changed:a}=t(r);return a?{...n,content:{...n.content,parts:s}}:n}),F_e=e=>{const t=new Set,n=new Set,r=new Set;for(const s of e){const a=s.content?.parts;if(Array.isArray(a))for(const i of a){const l=i?.data?.cycleId;l&&((i.type==="data-om-observation-end"||i.type==="data-om-observation-failed")&&t.add(l),(i.type==="data-om-buffering-end"||i.type==="data-om-buffering-failed")&&n.add(l),i.type==="data-om-activation"&&r.add(l))}}return{observation:t,buffering:n,activatedBuffering:r}},QWe=e=>{const t=F_e(e),n=new Set([...t.buffering,...t.activatedBuffering]);return o2t(e,r=>{let s=!1;return{parts:r.map(i=>{if(i.type==="data-om-observation-start"){const l=i.data?.cycleId;return!l||i.data?.disconnectedAt||t.observation.has(l)?i:(s=!0,{...i,data:{...i.data,disconnectedAt:new Date().toISOString(),_state:"disconnected"}})}if(i.type==="data-om-buffering-start"){const l=i.data?.cycleId;return!l||i.data?.disconnectedAt||n.has(l)?i:(s=!0,{...i,data:{...i.data,disconnectedAt:new Date().toISOString(),_state:"disconnected"}})}if(i.type==="tool-call"&&i.toolName===a2t){const l=i.metadata?.omData||i.args;if(!l?.completedAt&&!l?.failedAt&&!l?.disconnectedAt)return s=!0,{...i,metadata:{...i.metadata,omData:{...l,disconnectedAt:new Date().toISOString(),_state:"disconnected"}}}}return i}),changed:s}})},sPr=e=>{const{buffering:t,activatedBuffering:n}=F_e(e),r=new Set([...t,...n]);for(const s of e){const a=s.content?.parts;if(Array.isArray(a))for(const i of a){const l=i?.data?.cycleId;if(i.type==="data-om-buffering-start"&&l&&!i.data?.disconnectedAt&&!r.has(l)||i.type==="data-om-buffering-end"&&l&&i.data?.operationType==="observation"&&!rj(i.data))return!0}}return!1},l2t=(e,t)=>{const n=new Map,r=F_e(e).buffering;if(t?.bufferedObservationChunks)for(const s of t.bufferedObservationChunks)s.cycleId&&n.set(s.cycleId,s);return o2t(e,s=>{const a=[];let i=!1;for(const l of s){if(l.type==="data-om-buffering-end"&&l.data?.cycleId&&l.data?.operationType==="observation"){const c=n.get(l.data.cycleId);if(c&&!rj(l.data)){a.push({...l,data:{...l.data,observations:l.data.observations??c.observations,extractedValues:c.extractedValues,extractionFailures:c.extractionFailures}}),i=!0;continue}}if(a.push(l),l.type==="data-om-buffering-start"&&l.data?.cycleId&&!l.data?.disconnectedAt&&!r.has(l.data.cycleId)){const c=l.data.cycleId,u=l.data.operationType,d={cycleId:c,operationType:u,completedAt:new Date().toISOString()};if(u==="observation"){const f=n.get(c);f&&(d.tokensBuffered=f.messageTokens,d.bufferedTokens=f.tokenCount,d.observations=f.observations,d.extractedValues=f.extractedValues,d.extractionFailures=f.extractionFailures)}else u==="reflection"&&t&&(d.tokensBuffered=t.bufferedReflectionInputTokens,d.bufferedTokens=t.bufferedReflectionTokens,d.observations=t.bufferedReflection);a.push({type:"data-om-buffering-end",data:d}),r.add(c),i=!0}}return{parts:a,changed:i}})},aPr=e=>{const t=[];let n=null;for(const r of e){const s=r?.content?.parts;if(Array.isArray(s))for(const a of s)a?.type==="data-om-activation"&&a?.data?.cycleId&&t.push(a.data.cycleId),a?.type==="data-om-status"&&a?.data&&(n=a.data)}return{activatedCycleIds:t,lastProgress:n}},iPr="tool-calls",oPr=e=>`Agent stopped because it reached maxSteps${typeof e=="number"?` (${e})`:""} while tool calls were still pending. Increase maxSteps in advanced settings and try again.`,lPr=e=>{if(e.type!=="finish")return;const t=e.payload?.stepResult?.reason;return typeof t=="string"?t:void 0},cPr=e=>lPr(e)===iPr,nve=e=>{const t=e.payload?.error;let n;if(typeof t=="string")n=t;else if(t instanceof Error)n=t.message;else if(t&&typeof t=="object"&&typeof t.message=="string")n=t.message;else if(t==null)n="Unknown error";else try{n=JSON.stringify(t)??String(t)}catch{try{n=String(t)}catch{n="Unknown error"}}return{id:`error-${e.runId??"unknown"}-${Date.now()}`,role:"assistant",createdAt:new Date,content:{format:2,parts:[{type:"text",text:n}],metadata:{status:"error"}}}},uPr=(e,t)=>nve({runId:e.runId,payload:{error:oPr(t)}}),YWe=e=>{const t=e.type;if(t==="error"||t==="data-om-observation-start"||t==="data-om-observation-end"||t==="data-om-observation-failed"||t==="data-om-status"||t==="data-om-activation")return e},dPr=e=>{const t=new u_;return Object.entries(e.requestContext??{}).forEach(([n,r])=>{t.set(n,r)}),e.agentVersionId&&t.set("agentVersionId",e.agentVersionId),t},XWe=e=>(e.type==="tool-result"||e.type==="tool-execution-end")&&e.payload?.toolName==="updateWorkingMemory"&&typeof e.payload.result=="object"&&"success"in e.payload.result&&e.payload.result?.success,fPr=({agentId:e,requestContext:t,agentVersionId:n,threadId:r,modelSettingsArgs:s,chatWithNetwork:a,chatWithGenerate:i,maxSteps:l,isOMEnabled:c,tracingOptions:u,threadSignalsUnsupportedRef:d,isRunningStream:f,sendMessage:p,cancelRun:h,setMessages:m,setStreamErrors:v,refreshThreadList:y,refreshWorkingMemory:b,handleObservationStart:S,handleProgressUpdate:w,refreshObservationalMemory:k,handleActivation:_,resetObservationalMemoryStreamState:C,signalTimelineRefresh:E})=>{const j=We(),N=Hr(),I=g.useRef(null),R=g.useRef({requestContext:t,agentVersionId:n,threadId:r,modelSettingsArgs:s,chatWithNetwork:a,chatWithGenerate:i,maxSteps:l,isOMEnabled:c,tracingOptions:u});R.current={requestContext:t,agentVersionId:n,threadId:r,modelSettingsArgs:s,chatWithNetwork:a,chatWithGenerate:i,maxSteps:l,isOMEnabled:c,tracingOptions:u};const P=g.useCallback(F=>{F&&(N.refetchQueries({queryKey:pU(e,F)}),N.refetchQueries({queryKey:fU(F)}),N.refetchQueries({queryKey:tve(e,F)}),E())},[e,N,E]),L=g.useCallback(F=>{!F||!R.current.isOMEnabled||j.awaitBufferStatus({agentId:e,resourceId:e,threadId:F}).then(z=>{m(B=>l2t(B,z?.record)),N.invalidateQueries({queryKey:["observational-memory",e]}),N.invalidateQueries({queryKey:["memory-status",e]}),P(F)}).catch(()=>{})},[e,j,N,P,m]),M=g.useCallback(F=>{F?.type==="error"&&v(z=>[...z,nve(F)]),F?.type==="data-om-observation-start"&&S(F.data?.operationType),F?.type==="data-om-status"&&w(F.data),(F?.type==="data-om-observation-end"||F?.type==="data-om-observation-failed"||F?.type==="data-om-activation")&&k(F.data?.operationType),F?.type==="data-om-activation"&&_(F.data)},[_,S,w,k,v]),q=g.useCallback(async({message:F,attachments:z=[]})=>{const B=R.current;if(d.current&&(f||I.current))return;v([]);const D=new AbortController;I.current=D;const Q=dPr(B);try{if(B.chatWithNetwork)await p({message:F,mode:"network",coreUserMessages:z,requestContext:Q,threadId:B.threadId,modelSettings:B.modelSettingsArgs,signal:D.signal,tracingOptions:B.tracingOptions,onNetworkChunk:async V=>{XWe(V)&&b?.(),V.type==="network-execution-event-step-finish"&&y?.(),M(YWe(V))}});else if(B.chatWithGenerate){await p({message:F,mode:"generate",coreUserMessages:z,requestContext:Q,threadId:B.threadId,modelSettings:B.modelSettingsArgs,signal:D.signal,tracingOptions:B.tracingOptions}),await y?.(),P(B.threadId);return}else{await p({message:F,mode:"stream",coreUserMessages:z,requestContext:Q,threadId:B.threadId,modelSettings:B.modelSettingsArgs,tracingOptions:B.tracingOptions,onChunk:async V=>{V.type==="finish"&&(cPr(V)&&v($=>[...$,uPr(V,B.maxSteps)]),await y?.()),XWe(V)&&b?.(),M(YWe(V))},signal:D.signal}),P(B.threadId),L(B.threadId);return}setTimeout(()=>{y?.()},500),P(B.threadId),L(B.threadId)}catch(V){if(console.error("Error occurred in ChatProvider",V),V.name==="AbortError")return;v($=>[...$,nve({runId:"thrown",payload:{error:V}})]),C()}finally{I.current=null}},[L,M,f,y,P,b,C,p,v,d]),H=g.useCallback(async()=>{I.current?.abort(),I.current=null,C(),h?.(),L(R.current.threadId)},[h,L,C]);return{send:q,cancel:H}};function pPr({isSupportedModel:e,threadSignalsEnabled:t,threadId:n,threadSignalsUnsupported:r}){return e&&t&&!!n&&!r}const c2t=g.createContext(void 0);function hPr({children:e,approveToolcall:t,declineToolcall:n,approveToolcallGenerate:r,declineToolcallGenerate:s,approveNetworkToolcall:a,declineNetworkToolcall:i,isRunning:l,toolCallApprovals:c,networkToolCallApprovals:u}){return o.jsx(c2t.Provider,{value:{approveToolcall:t,declineToolcall:n,approveToolcallGenerate:r,declineToolcallGenerate:s,approveNetworkToolcall:a,declineNetworkToolcall:i,isRunning:l,toolCallApprovals:c,networkToolCallApprovals:u},children:e})}function u2t(){const e=g.useContext(c2t);if(!e)throw new Error("useToolCall must be used within a ToolCallProvider");return e}function mPr({children:e,agentId:t,initialMessages:n,threadId:r,refreshThreadList:s,settings:a,requestContext:i,modelVersion:l,agentVersionId:c,supportsMemory:u}){const{settings:d}=tV(),[f,p]=g.useState([]),[h,m]=g.useState(!1),v=g.useRef(!1),y=a?.modelSettings??{},b=window.MASTRA_AGENT_SIGNALS!=="false"&&u!==!1&&!y.chatWithLegacyStream;g.useEffect(()=>{p([]),v.current=!1,m(!1)},[t,r]);const S=g.useMemo(()=>{if(!c&&!i)return;const ot=new u_;return Object.entries(i??{}).forEach(([zt,mt])=>{ot.set(zt,mt)}),c&&ot.set("agentVersionId",c),ot},[c,i]),{messages:w,tasks:k,sendMessage:_,cancelRun:C,isRunning:E,isAwaitingToolApproval:j,setMessages:N,approveToolCall:I,declineToolCall:R,approveToolCallGenerate:P,declineToolCallGenerate:L,toolCallApprovals:M,approveNetworkToolCall:q,declineNetworkToolCall:H,networkToolCallApprovals:F}=Pbe({agentId:t,threadId:r,initialMessages:n,requestContext:S,enableThreadSignals:b,onThreadSignalsUnsupported:()=>{v.current=!0,m(!0)}}),{refetch:z}=kRt(),B=Hr(),D=We(),{data:Q}=G_(t),V=Q?.config?.observationalMemory,$=V===!0||typeof V=="object"&&V!==null&&(!("enabled"in V)||V.enabled!==!1),{setIsObservingFromStream:U,setIsReflectingFromStream:Z,signalObservationsUpdated:X,setStreamProgress:te,markCycleIdActivated:J}=IW(),ee=g.useCallback(ot=>{ot==="reflection"?Z(!0):U(!0)},[U,Z]),ae=g.useCallback(ot=>{ot.threadId&&ot.threadId!==r||te({windows:ot.windows,recordId:ot.recordId,threadId:ot.threadId,stepNumber:ot.stepNumber,generationCount:ot.generationCount})},[te,r]),ce=g.useCallback(ot=>{ot==="reflection"?Z(!1):U(!1),X(),B.invalidateQueries({queryKey:["observational-memory",t]}),B.invalidateQueries({queryKey:["memory-status",t]}),B.refetchQueries({queryKey:pU(t,r)}),B.refetchQueries({queryKey:fU(r)}),B.refetchQueries({queryKey:tve(t,r)})},[t,B,U,Z,X,r]),Y=g.useCallback(ot=>{const zt=ot?.cycleId;zt&&J(zt)},[J]),ne=g.useCallback(()=>{U(!1),Z(!1),N(ot=>QWe(ot)),B.invalidateQueries({queryKey:["observational-memory",t]}),B.invalidateQueries({queryKey:["memory-status",t]}),B.refetchQueries({queryKey:pU(t,r)}),B.refetchQueries({queryKey:fU(r)}),B.refetchQueries({queryKey:tve(t,r)})},[t,B,U,Z,N,r]);g.useEffect(()=>{const{activatedCycleIds:ot,lastProgress:zt}=aPr(n||[]);for(const mt of ot)J(mt);zt&&ae(zt)},[ae,n,J]),g.useEffect(()=>{if(!r||!sPr(n||[]))return;let ot=!1;return D.awaitBufferStatus({agentId:t,resourceId:t,threadId:r}).then(zt=>{ot||N(mt=>l2t(mt,zt?.record))}).catch(()=>{ot||N(zt=>QWe(zt))}),()=>{ot=!0}},[t,D,n,N,r]);const{frequencyPenalty:ue,presencePenalty:pe,maxRetries:le,maxSteps:ve,maxTokens:ye,temperature:Se,topK:Ne,topP:ke,seed:Ie,chatWithGenerate:ze,chatWithNetwork:oe,chatWithLegacyStream:se,providerOptions:re,requireToolApproval:he}=y,xe={frequencyPenalty:ue,presencePenalty:pe,maxRetries:le,temperature:Se,topK:Ne,topP:ke,seed:Ie,maxTokens:ye,providerOptions:re,maxSteps:ve,requireToolApproval:he},{send:je,cancel:Pe}=fPr({agentId:t,requestContext:i,agentVersionId:c,threadId:r,modelSettingsArgs:xe,chatWithNetwork:oe,chatWithGenerate:ze,maxSteps:ve,isOMEnabled:$,tracingOptions:d?.tracingOptions,threadSignalsUnsupportedRef:v,isRunningStream:E,sendMessage:_,cancelRun:C,setMessages:N,setStreamErrors:p,refreshThreadList:s,refreshWorkingMemory:z,handleObservationStart:ee,handleProgressUpdate:ae,refreshObservationalMemory:ce,handleActivation:Y,resetObservationalMemoryStreamState:ne,signalTimelineRefresh:X}),Ge=l==="v2"||l==="v3",Ze=g.useRef(new Map),Ee=g.useMemo(()=>ePr(w,Ze.current),[w]),_e=g.useMemo(()=>[...w.filter(ot=>ot.content?.metadata?.status!=="error"),...f].map(ot=>rPr(ot,Ee)),[w,f,Ee]),Ce=E||j,Re=pPr({isSupportedModel:Ge,threadSignalsEnabled:b&&(!ze&&!oe&&!se),threadId:r,threadSignalsUnsupported:h}),qe=g.useMemo(()=>({messages:_e}),[_e]),Ye=g.useMemo(()=>({isRunning:Ce,cancelRun:Pe,canSendWhileStreaming:Re}),[Ce,Pe,Re]),tt=g.useMemo(()=>({send:je}),[je]),At=g.useMemo(()=>({tasks:k}),[k]);return o.jsx(e2t.Provider,{value:Ye,children:o.jsx(JRt.Provider,{value:qe,children:o.jsx(n2t.Provider,{value:At,children:o.jsx(t2t.Provider,{value:tt,children:o.jsx(hPr,{approveToolcall:I,declineToolcall:R,approveToolcallGenerate:P,declineToolcallGenerate:L,approveNetworkToolcall:q,declineNetworkToolcall:H,isRunning:E,toolCallApprovals:M,networkToolCallApprovals:F,children:e})})})})})}const gPr=(e,t)=>{const n=new Blob([JSON.stringify(t,null,2)],{type:"application/json"}),r=URL.createObjectURL(n),s=document.createElement("a");s.href=r,s.download=e,document.body.appendChild(s),s.click(),s.remove(),URL.revokeObjectURL(r)},KWe={jpg:"image/jpg",jpeg:"image/jpeg",png:"image/png",gif:"image/gif",webp:"image/webp",svg:"image/svg+xml",bmp:"image/bmp",ico:"image/x-icon",pdf:"application/pdf",mp4:"video/mp4",mov:"video/quicktime",webm:"video/webm",mkv:"video/x-matroska",avi:"video/x-msvideo",mpeg:"video/mpeg",mpg:"video/mpeg",mp3:"audio/mpeg",wav:"audio/wav",ogg:"audio/ogg",oga:"audio/ogg",m4a:"audio/mp4",aac:"audio/aac",flac:"audio/flac"},d2t=["https://","http://"],z_e=["gs://","s3://"],vPr=[...d2t,...z_e],yPr=e=>vPr.some(t=>e.startsWith(t)),f2t=e=>d2t.some(t=>e.startsWith(t)),bPr=e=>z_e.some(t=>e.startsWith(t)),JWe=e=>{try{const{pathname:t}=new URL(e),n=t.split(".").pop();return n?KWe[n.toLowerCase()]:void 0}catch{const t=e.split(".").pop()?.split(/[?#]/)[0];return t?KWe[t.toLowerCase()]:void 0}},xPr=async e=>{if(z_e.some(t=>e.startsWith(t)))return JWe(e);try{const t=await fetch(e,{method:"HEAD"});if(!t.ok)throw new Error("Failed to get file content type");const n=t.headers.get("content-type");if(!n)throw new Error("Failed to get file content type");return n}catch{return JWe(e)}},x8=async e=>new Promise((t,n)=>{const r=new FileReader;r.onload=()=>{const s=r.result;typeof s=="string"?t(s):n(new Error("Failed to convert file to base64."))},r.onerror=s=>{n(s)},r.readAsDataURL(e)}),p2t=g.createContext(null),wPr=e=>e.startsWith("image/")?"image":e==="application/pdf"?"pdf":e.startsWith("video/")||e.startsWith("audio/")?"video":"text";let SPr=0;const kPr=()=>`att-${Date.now()}-${++SPr}`,OPr=e=>new Promise((t,n)=>{const r=new FileReader;r.onload=()=>t(typeof r.result=="string"?r.result:""),r.onerror=()=>n(r.error),r.readAsText(e)}),eZe=e=>{const t=yPr(e.name),n=e.type||"text/plain";return{id:kPr(),file:e,name:e.name,contentType:n,kind:wPr(n),isUrl:t}},_Pr=async e=>e.kind==="image"?{role:"user",content:[{type:"image",image:e.isUrl?e.name:await x8(e.file),mimeType:e.contentType}]}:e.kind==="pdf"?{role:"user",content:[{type:"file",data:e.isUrl?e.name:await x8(e.file),mimeType:e.contentType,filename:e.name}]}:e.kind==="video"?{role:"user",content:[{type:"file",data:e.isUrl?e.name:await x8(e.file),mimeType:e.contentType,filename:e.name}]}:{role:"user",content:await OPr(e.file)},CPr=({children:e})=>{const[t,n]=g.useState([]),r=g.useCallback(u=>{const d=Array.from(u);d.length!==0&&n(f=>[...f,...d.map(eZe)])},[]),s=g.useCallback(async u=>{const d=await xPr(u)??"application/octet-stream",f=new File([],u,{type:d});n(p=>[...p,eZe(f)])},[]),a=g.useCallback(u=>{n(d=>d.filter(f=>f.id!==u))},[]),i=g.useCallback(()=>n([]),[]),l=g.useCallback(async()=>Promise.all(t.map(_Pr)),[t]),c=g.useMemo(()=>({attachments:t,addFiles:r,addUrl:s,remove:a,clear:i,toCoreUserMessages:l}),[t,r,s,a,i,l]);return o.jsx(p2t.Provider,{value:c,children:e})},RW=()=>{const e=g.useContext(p2t);if(!e)throw new Error("useComposerAttachments must be used within a ComposerAttachmentsProvider");return e},EPr=()=>{const[e,t]=g.useState(!1),{addFiles:n,addUrl:r}=RW(),s=()=>{const i=document.createElement("input");i.type="file",i.multiple=!0,i.hidden=!0;const l=()=>{window.removeEventListener("focus",c),i.remove()},c=()=>setTimeout(l,0);i.onchange=u=>{const d=u.target.files;d&&d.length>0&&(n(d),t(!1)),l()},document.body.appendChild(i),window.addEventListener("focus",c),i.click()},a=async i=>{i.preventDefault(),i.stopPropagation();const c=new FormData(i.target).get("url-attachment")?.toString().trim();if(c)try{await r(c),t(!1)}catch{}};return o.jsxs(Nd,{open:e,onOpenChange:t,children:[o.jsx(iu,{asChild:!0,children:o.jsx(de,{variant:"default",size:"icon-md",type:"button",tooltip:"Add attachment",children:o.jsx(Vr,{className:"h-5 w-5 text-neutral3 hover:text-neutral6"})})}),o.jsxs(ou,{align:"start",className:"w-80 p-4",children:[o.jsxs("form",{onSubmit:a,className:"flex flex-row items-end gap-2",children:[o.jsxs("div",{className:"w-full space-y-1",children:[o.jsx(Rt,{htmlFor:"url-attachment",className:"text-neutral3 text-ui-md",children:"Public URL"}),o.jsx(kn,{type:"text",name:"url-attachment",id:"url-attachment",className:"w-full",placeholder:"https://placehold.co/600x400/png"})]}),o.jsxs(de,{type:"submit",className:"h-8!",variant:"default",children:[o.jsx(Ue,{children:o.jsx(qlt,{})}),"Add"]})]}),o.jsx("hr",{className:"my-3 border-border1"}),o.jsxs("div",{className:"space-y-2",children:[o.jsx(ge,{variant:"ui-md",className:"text-neutral3",children:"Or from your computer"}),o.jsxs("button",{type:"button",onClick:s,className:"w-full h-28 border border-border1 rounded-lg text-neutral3 border-dashed flex flex-col items-center justify-center gap-2 hover:bg-surface2 active:bg-surface3",children:[o.jsx(Mlt,{className:"size-8"}),o.jsx(ge,{variant:"ui-lg",children:"Add a local file"})]})]})]})]})},jPr=e=>{const[t,n]=g.useState({isLoading:!1,text:""});return g.useEffect(()=>{if(!e)return;(async()=>{n(a=>({...a,isLoading:!0}));const s=await e.text();n(a=>({...a,isLoading:!1,text:s}))})()},[e]),t},XT="h-full w-full flex items-center justify-center",h2t=({data:e,url:t})=>{const[n,r]=g.useState(!1);return t?o.jsx("a",{href:t,className:XT,target:"_blank",rel:"noreferrer noopener",children:o.jsx(Oc,{className:"text-accent2","aria-label":"View PDF"})}):o.jsxs(o.Fragment,{children:[o.jsx("button",{onClick:()=>r(!0),className:XT,type:"button",children:o.jsx(Oc,{className:"text-accent2","aria-label":"View PDF"})}),o.jsx(TPr,{data:e,open:n,onOpenChange:r})]})},TPr=({data:e,open:t,onOpenChange:n})=>o.jsx(br,{open:t,onOpenChange:n,children:o.jsxs(xr,{className:"max-w-4xl",children:[o.jsxs(wr,{children:[o.jsx(gr,{children:"PDF preview"}),o.jsx(Qs,{children:"Preview of the PDF document"})]}),o.jsx(Rr,{children:t&&o.jsx("iframe",{src:e,width:"100%",height:"600px"})})]})}),NPr=e=>e?.startsWith("video/")?{Icon:uun,label:"Video file"}:e?.startsWith("audio/")?{Icon:tun,label:"Audio file"}:e?.startsWith("text/")||e==="application/pdf"?{Icon:Oc,label:"Document file"}:{Icon:rbe,label:"File"},m2t=({name:e,url:t,contentType:n})=>{const{Icon:r,label:s}=NPr(n),a=o.jsx(r,{className:"text-accent2","aria-label":s});return t?o.jsx("a",{href:t,className:XT,target:"_blank",rel:"noreferrer noopener",title:e,children:a}):o.jsx("div",{className:XT,title:e,children:a})},g2t=({src:e})=>{const[t,n]=g.useState(!1);return o.jsxs(o.Fragment,{children:[o.jsx("button",{onClick:()=>n(!0),type:"button",className:XT,children:o.jsx("img",{src:e,className:"object-cover aspect-ratio max-h-[140px] max-w-[320px]",alt:"Preview"})}),o.jsx(IPr,{src:e,open:t,onOpenChange:n})]})},IPr=({src:e,open:t,onOpenChange:n})=>o.jsx(br,{open:t,onOpenChange:n,children:o.jsxs(xr,{className:"max-w-4xl",children:[o.jsxs(wr,{children:[o.jsx(gr,{children:"Image preview"}),o.jsx(Qs,{children:"Preview of the image"})]}),o.jsx(Rr,{children:t&&o.jsx("img",{src:e,alt:"Image"})})]})}),v2t=({data:e})=>{const[t,n]=g.useState(!1),r=e.replace(/<attachment[^>]*>/,"").replace(/<\/attachment>/g,"");return o.jsxs(o.Fragment,{children:[o.jsx("button",{onClick:()=>n(!0),className:XT,type:"button",children:o.jsx(Oc,{className:"text-neutral3"})}),o.jsx(APr,{data:r,open:t,onOpenChange:n})]})},APr=({data:e,open:t,onOpenChange:n})=>o.jsx(br,{open:t,onOpenChange:n,children:o.jsxs(xr,{className:"max-w-4xl h-[80vh]",children:[o.jsxs(wr,{children:[o.jsx(gr,{children:"Text preview"}),o.jsx(Qs,{children:"Preview of the text file"})]}),o.jsx(Rr,{children:t&&o.jsx("div",{className:"whitespace-pre-wrap",children:e})})]})}),RPr=({file:e})=>{const{isLoading:t,text:n}=jPr(e);return o.jsx("div",{className:"flex items-center justify-center h-full w-full",children:t?o.jsx(Gt,{}):o.jsx(v2t,{data:n})})},PPr=({attachment:e})=>{const[t,n]=g.useState({isLoading:!1,text:""});return g.useEffect(()=>{let r=!1;return(async()=>{if(!e.file)return;n(i=>({...i,isLoading:!0}));const a=await x8(e.file);r||n(i=>({...i,isLoading:!1,text:a}))})(),()=>{r=!0}},[e]),o.jsx("div",{className:"flex items-center justify-center h-full w-full",children:t.isLoading?o.jsx(Gt,{}):o.jsx(h2t,{data:t.text,url:e.isUrl?e.name:void 0})})},$Pr=({attachment:e})=>{const[t,n]=g.useState(e.isUrl?e.name:"");return g.useEffect(()=>{if(e.isUrl){n(e.name);return}const r=URL.createObjectURL(e.file);return n(r),()=>URL.revokeObjectURL(r)},[e]),o.jsx(g2t,{src:t})},MPr=({attachment:e})=>{const{remove:t}=RW();return o.jsxs("div",{className:"relative",children:[o.jsx(Jct,{children:o.jsxs(Wn,{children:[o.jsx(zn,{asChild:!0,children:o.jsx("div",{className:"overflow-hidden size-16 rounded-lg bg-surface3 border border-border1 ",children:e.kind==="image"?o.jsx($Pr,{attachment:e}):e.kind==="pdf"?o.jsx(PPr,{attachment:e}):e.kind==="video"?o.jsx(m2t,{name:e.name,url:e.isUrl&&f2t(e.name)?e.name:void 0,contentType:e.contentType}):o.jsx(RPr,{file:e.file})})}),o.jsx(Bn,{side:"top",children:e.name})]})}),o.jsx(de,{variant:"default",size:"icon-sm",type:"button",tooltip:"Remove file",onClick:()=>t(e.id),className:"absolute -right-2 -top-2 text-neutral3 hover:text-neutral6 bg-surface1 hover:bg-surface2",children:o.jsx(Ue,{children:o.jsx(vs,{})})})]})},DPr=()=>{const{attachments:e}=RW();return e.length===0?null:o.jsx("div",{className:"absolute bottom-full inset-x-0 px-2","data-attachments-row":!0,children:o.jsx("div",{className:"max-w-3xl w-full mx-auto overflow-x-auto",children:o.jsx("div",{className:"flex flex-row items-center gap-4 px-3 pt-3 pb-1",children:e.map(t=>o.jsx(MPr,{attachment:t},t.id))})})})},LPr=(e,t)=>{const n=We(),[r,s]=g.useState(!1),[a,i]=g.useState(!1),l=g.useRef(null);g.useEffect(()=>{let d=!1;return e?(n.getAgent(e).voice.getSpeakers(t).then(p=>{d||s(p.length>0)}).catch(()=>{d||s(!1)}),()=>{d=!0}):(s(!1),()=>{d=!0})},[e,n,t]);const c=g.useCallback(()=>{l.current?.(),l.current=null,typeof window<"u"&&window.speechSynthesis&&window.speechSynthesis.cancel(),i(!1)},[]),u=g.useCallback(async d=>{if(d){if(c(),i(!0),e&&r)try{const p=await n.getAgent(e).voice.speak(d);if(!p.body)throw new Error("No audio stream returned from voice.speak()");const h=await Evn(p.body,()=>i(!1));l.current=h??null;return}catch(f){i(!1),Ru.error(f instanceof Error?f.message:"Voice generation failed.");return}if(typeof window<"u"&&window.speechSynthesis){const f=new SpeechSynthesisUtterance(d);f.onend=()=>i(!1),f.onerror=()=>i(!1),window.speechSynthesis.speak(f);return}i(!1)}},[e,n,r,c]);return g.useEffect(()=>()=>c(),[c]),{isSpeaking:a,readAloud:u,stop:c}},tZe=12;function FPr({containerRef:e}){const[t,n]=g.useState([]),[r,s]=g.useState(null),a=g.useRef(""),i=g.useRef(0),l=g.useCallback(()=>{const u=e.current;if(!u){a.current!==""&&(a.current="",n([]));return}const d=u.getBoundingClientRect(),f=Array.from(u.querySelectorAll("[data-om-badge]"));if(f.length===0){a.current!==""&&(a.current="",n([]));return}const p=[];for(let m=0;m<f.length;m++){const v=f[m],y=v.getAttribute("data-om-badge")||"",b=v.getAttribute("data-om-state")||"complete",S=v.getAttribute("data-om-type")||"observation",w=v.getBoundingClientRect();let k;const _=zPr(f,m,S);_?k=_.getBoundingClientRect().bottom+tZe-d.top:k=0;const E=w.bottom+tZe-d.top-k;E<=0||p.push({cycleId:y,omType:S,state:b,top:k,height:E})}const h=JSON.stringify(p);h!==a.current&&(a.current=h,n(p))},[e]);if(g.useEffect(()=>{const u=e.current;if(!u)return;l();const d=new ResizeObserver(()=>{cancelAnimationFrame(i.current),i.current=requestAnimationFrame(l)});d.observe(u);const f=new MutationObserver(()=>{cancelAnimationFrame(i.current),i.current=requestAnimationFrame(l)});return f.observe(u,{childList:!0,subtree:!0}),()=>{cancelAnimationFrame(i.current),d.disconnect(),f.disconnect()}},[l,e]),g.useEffect(()=>{const u=e.current;if(!u)return;const d=p=>{const h=p.target.closest("[data-om-badge]");h&&s(h.getAttribute("data-om-badge"))},f=p=>{p.target.closest("[data-om-badge]")&&s(null)};return u.addEventListener("mouseover",d),u.addEventListener("mouseout",f),()=>{u.removeEventListener("mouseover",d),u.removeEventListener("mouseout",f)}},[e]),t.length===0)return null;const c=t[t.length-1]?.cycleId??null;return o.jsx("div",{className:"pointer-events-none absolute inset-0",style:{zIndex:0},children:t.map(u=>{const d=u.cycleId===c,f=u.cycleId===r,p=r?f:d;return o.jsx(BPr,{highlight:u,visible:p},u.cycleId)})})}function zPr(e,t,n){for(let r=t-1;r>=0;r--){const s=e[r];if(s.getAttribute("data-om-state")!=="failed"&&(n==="observation"||s.getAttribute("data-om-type")==="reflection"))return s}return null}function BPr({highlight:e,visible:t}){const n=UPr(e.state),r=e.state.startsWith("buffering");return o.jsx("div",{className:"absolute left-0 right-0 transition-opacity duration-200",style:{top:e.top,height:e.height,border:`2px ${r?"dashed":"solid"} ${n}`,borderRadius:"0.5rem",opacity:t?1:0}})}function UPr(e){switch(e){case"complete":return"rgba(34, 197, 94, 0.4)";case"loading":return"rgba(59, 130, 246, 0.4)";case"failed":return"rgba(239, 68, 68, 0.4)";case"disconnected":return"rgba(234, 179, 8, 0.4)";case"buffering":return"rgba(156, 163, 175, 0.45)";case"buffering-complete":return"rgba(156, 163, 175, 0.45)";case"buffering-failed":return"rgba(239, 68, 68, 0.4)";case"activated":return"rgba(34, 197, 94, 0.4)";default:return"rgba(34, 197, 94, 0.4)"}}const y2t=g.createContext(null);function qPr({children:e,...t}){return o.jsx(y2t.Provider,{value:t,children:e})}function PW(){return g.useContext(y2t)}function b2t({open:e,onOpenChange:t,input:n,onInputChange:r,requestContext:s,initialGroundTruth:a=""}){const[i,l]=g.useState(a),[c,u]=g.useState("");g.useEffect(()=>{e&&l(a)},[e,a]);const{data:d,isLoading:f}=$g(),{addItem:p}=Ei(),h=g.useMemo(()=>d?.datasets??[],[d?.datasets]),m=g.useCallback(async()=>{if(!c){De.error("Please select a dataset");return}let v;try{v=JSON.parse(n)}catch{De.error("Input must be valid JSON");return}let y;if(i.trim())try{y=JSON.parse(i)}catch{De.error("Ground Truth must be valid JSON");return}try{const b=s&&Object.keys(s).length>0;await p.mutateAsync({datasetId:c,input:v,groundTruth:y,...b?{requestContext:s}:{}});const S=h.find(w=>w.id===c);De.success(`Item saved to "${S?.name}"`),t(!1),u(""),r(""),l("")}catch(b){De.error(`Failed to save item: ${b instanceof Error?b.message:"Unknown error"}`)}},[n,i,c,s,p,h,t,r]);return o.jsx(br,{open:e,onOpenChange:t,children:o.jsxs(xr,{className:"max-w-lg",children:[o.jsxs(wr,{children:[o.jsx(gr,{children:"Save to Dataset"}),o.jsx(Qs,{children:"Save as a dataset item for evaluation."})]}),o.jsxs(Rr,{className:"py-1 space-y-4",children:[o.jsxs("div",{className:"grid gap-2",children:[o.jsx(Rt,{htmlFor:"ds-target",children:"Dataset"}),o.jsxs(da,{value:c,onValueChange:u,disabled:p.isPending||f,children:[o.jsx(pa,{id:"ds-target",children:o.jsx(fa,{placeholder:f?"Loading...":"Select a dataset"})}),o.jsx(ha,{children:h.length===0?o.jsx("div",{className:"px-2 py-4 text-sm text-neutral4 text-center",children:"No datasets available"}):h.map(v=>o.jsx(Lr,{value:v.id,children:v.name},v.id))})]})]}),o.jsxs("div",{className:"grid gap-2",children:[o.jsx(Rt,{children:"Input (JSON)"}),o.jsx(Qr,{value:n,onChange:r,showCopyButton:!1,className:"min-h-[120px] max-h-[240px]"})]}),o.jsxs("div",{className:"grid gap-2",children:[o.jsx(Rt,{children:"Ground Truth (JSON, optional)"}),o.jsx(Qr,{value:i,onChange:l,showCopyButton:!1,className:"min-h-[80px] max-h-[160px]"})]})]}),o.jsxs(Cc,{className:"px-6",children:[o.jsx(de,{variant:"default",size:"sm",onClick:()=>t(!1),children:"Cancel"}),o.jsxs(de,{variant:"primary",size:"sm",onClick:m,disabled:p.isPending||!c||h.length===0,children:[o.jsx(Ue,{size:"sm",children:o.jsx(gd,{})}),p.isPending?"Saving...":"Save Item"]})]})]})})}function VPr({messageText:e}){return PW()?.enabled?o.jsx(HPr,{messageText:e}):null}function HPr({messageText:e}){const t=PW(),[n,r]=g.useState(!1),[s,a]=g.useState(""),i=g.useCallback(()=>{a(JSON.stringify(e,null,2)),r(!0)},[e]);return o.jsxs(o.Fragment,{children:[o.jsx(de,{variant:"default",size:"icon-md",tooltip:"Save to dataset",className:"bg-transparent text-neutral3 hover:text-neutral6",onClick:i,children:o.jsx(iy,{className:"h-4 w-4"})}),o.jsx(b2t,{open:n,onOpenChange:r,input:s,onInputChange:a,requestContext:t?.requestContext})]})}function WPr(){return PW()?.enabled?o.jsx(ZPr,{}):null}function ZPr(){const e=PW(),t=We(),[n,r]=g.useState(!1),[s,a]=g.useState(""),[i,l]=g.useState(""),[c,u]=g.useState(!1),d=g.useCallback(async()=>{u(!0);try{const p=(await t.listThreadMessages(e.threadId,{agentId:e.agentId}))?.messages??[],h=p.length-1,m=p[h];if(m&&m.role==="assistant"){const v=p.slice(0,h);a(JSON.stringify(v,null,2)),l(JSON.stringify(m,null,2))}else a(JSON.stringify(p,null,2)),l("");r(!0)}catch(f){De.error(`Failed to fetch thread messages: ${f instanceof Error?f.message:"Unknown error"}`)}finally{u(!1)}},[t,e.threadId,e.agentId]);return o.jsxs(o.Fragment,{children:[o.jsxs("button",{type:"button",onClick:d,disabled:c,className:"flex items-center gap-1.5 text-neutral3 hover:text-neutral5 transition-colors mx-auto py-3 text-ui-xs leading-ui-xs cursor-pointer disabled:opacity-50",children:[c?o.jsx(Gt,{className:"h-3.5 w-3.5"}):o.jsx(iy,{className:"h-3.5 w-3.5"}),"Save full conversation to dataset"]}),o.jsx(b2t,{open:n,onOpenChange:r,input:s,onInputChange:a,requestContext:e.requestContext,initialGroundTruth:i})]})}const GPr=({part:e,metadata:t})=>o.jsx(XOe,{text:e.text??"",metadata:t}),QPr=({part:e})=>e.type==="data-signal"&&J3(e.data)?o.jsx($It,{signal:e.data}):null,YPr=({toolCallId:e,suspendPayload:t,result:n})=>{const{approveToolcall:r,isRunning:s,toolCallApprovals:a}=u2t(),[i,l]=g.useState([]),[c,u]=g.useState(""),{question:d,options:f,selectionMode:p}=t,h=f?.length?p??"single_select":void 0,m=!!n||a?.[e]?.status==="approved",v=f?.length?h==="multi_select"?"multiple choice":"single choice":"free text",y=g.useCallback(k=>{m||s||(h==="multi_select"?l(_=>_.includes(k)?_.filter(C=>C!==k):[..._,k]):r(e,k))},[m,s,h,r,e]),b=g.useCallback(()=>{i.length===0||m||s||r(e,i)},[i,m,s,r,e]),S=g.useCallback(()=>{const k=c.trim();!k||m||s||r(e,k)},[c,m,s,r,e]),w=g.useCallback(k=>{k.key==="Enter"&&!k.shiftKey&&(k.preventDefault(),S())},[S]);return o.jsxs("div",{"data-testid":"ask-user-badge",className:"mb-4 flex w-full max-w-full overflow-hidden rounded-lg border border-border1 bg-surface3",children:[o.jsx("div",{className:K("w-1 shrink-0",m?"bg-notice-success":"bg-accent1")}),o.jsxs("div",{className:"min-w-0 flex-1",children:[o.jsxs("div",{className:"flex h-header-default items-center gap-2 border-b border-border1 px-4",children:[o.jsx("span",{className:"rounded-md border border-border1 bg-surface4 p-1",children:o.jsx(Ue,{children:o.jsx(Hlt,{className:"text-icon3"})})}),o.jsx(ge,{as:"span",variant:"ui-md",className:"font-medium text-neutral6",children:"Ask User"}),o.jsxs(ge,{as:"span",variant:"ui-sm",className:"text-neutral3",children:["· ",v]}),m&&o.jsx(dn,{variant:"success",size:"sm",icon:o.jsx("span",{className:"size-1.5 rounded-full bg-current"}),children:"Answered"})]}),o.jsxs("div",{className:"flex flex-col gap-4 p-4",children:[o.jsx(ge,{as:"p",variant:"ui-xs",className:"uppercase tracking-wide text-neutral3",children:"Question"}),o.jsx(ge,{as:"p",variant:"ui-lg",className:"text-neutral6",children:d}),m&&n!=null&&o.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-border1 bg-surface4 px-3 py-2",children:[o.jsx(Ue,{children:o.jsx(Js,{className:"text-notice-success-fg"})}),o.jsx(ge,{as:"span",variant:"ui-md",className:"font-medium text-neutral6",children:n.content})]}),!m&&f&&f.length>0&&o.jsxs("div",{className:"flex flex-col gap-2",children:[f.map(k=>{const _=i.includes(k.label);return o.jsxs("button",{type:"button",onClick:()=>y(k.label),disabled:s,className:K("rounded-md border px-3 py-2 text-left transition-colors disabled:cursor-not-allowed disabled:opacity-50",_?"border-accent1 bg-surface4":"border-border1 bg-surface4 hover:bg-surface5"),children:[o.jsx(ge,{as:"span",variant:"ui-md",className:"font-medium text-neutral6",children:k.label}),k.description&&o.jsx(ge,{as:"span",variant:"ui-xs",className:"mt-0.5 block text-neutral3",children:k.description})]},k.label)}),h==="multi_select"&&o.jsxs(de,{onClick:b,disabled:i.length===0||s,children:[o.jsx(Ue,{children:o.jsx(xMe,{})}),"Submit (",i.length," selected)"]})]}),!m&&!f?.length&&o.jsxs("div",{className:"flex gap-2",children:[o.jsx(kn,{placeholder:"Type your answer...",value:c,onChange:k=>u(k.target.value),onKeyDown:w,disabled:s,className:"flex-1"}),o.jsx(de,{onClick:S,disabled:!c.trim()||s,children:o.jsx(Ue,{children:o.jsx(xMe,{})})})]})]})]})]})};function XPr(e){return typeof e=="object"&&e!==null&&"question"in e&&typeof e.question=="string"}function KPr(e){if(typeof e=="object"&&e!==null&&typeof e.content=="string")return e}const JPr=({toolName:e,toolCallId:t,output:n,metadata:r})=>{const s=(r?.suspendedTools?.[e]??r?.suspendedTools?.[t])?.suspendPayload;return XPr(s)?o.jsx(YPr,{toolCallId:t,suspendPayload:s,result:KPr(n)}):null};function e$r(e){return e.metadata?.systemReminder||e.metadata?.dynamicAgentsMdReminder?!0:e.role!=="user"?!1:Array.isArray(e.parts)?e.parts.some(t=>t.type==="text"&&typeof t.text=="string"&&t.text.includes("<system-reminder")):typeof e.content=="string"&&e.content.includes("<system-reminder")}function rve(e){return e.filter(t=>!e$r(t))}function t$r(e,t={}){const n=new gln().add(e,"memory");return t.version==="v6"?rve(n.get.all.aiV6.ui()):rve(n.get.all.aiV5.ui())}function n$r(e){return rve(t$r(e))}const x2t=(e,t)=>Number(e.toPrecision(t)),r$r=({startedAt:e,endedAt:t})=>{const[n,r]=g.useState(e);return g.useEffect(()=>{if(r(e),t!=null)return;const a=setInterval(()=>{r(Date.now())},100);return()=>clearInterval(a)},[e,t]),t!=null?t-e:n-e},s$r=({backgroundTaskTaskId:e,backgroundTaskStartedAt:t,backgroundTaskCompletedAt:n,backgroundTaskSuspendedAt:r,open:s,onOpenChange:a})=>{const{data:i}=AYn(e,!!n||!!r),{tasks:l}=IYn({taskId:e,enabled:!n&&!r}),c=r$r({startedAt:new Date(t).getTime(),endedAt:n?new Date(n).getTime():r?new Date(r).getTime():void 0}),u=i||l[e],d=u?.args,f=u?.result,p=u?.suspendPayload;let h=null;try{const{__mastraMetadata:y,_background:b,...S}=typeof d=="object"?d:JSON.parse(d);h=o.jsx(Qr,{data:S})}catch{h=o.jsx("pre",{className:"whitespace-pre bg-surface4 p-4 rounded-md overflow-x-auto",children:d})}const m=typeof f=="string"?o.jsx("pre",{className:"whitespace-pre bg-surface4 p-4 rounded-md overflow-x-auto",children:f}):o.jsx(Qr,{data:f}),v=typeof p=="string"?o.jsx("pre",{className:"whitespace-pre bg-surface4 p-4 rounded-md overflow-x-auto",children:p}):o.jsx(Qr,{data:p});return o.jsx(br,{open:s,onOpenChange:a,children:o.jsxs(xr,{children:[o.jsxs(wr,{children:[o.jsx(gr,{children:"Background Task Metadata"}),o.jsx(Qs,{children:"View the metadata of the background task."})]}),o.jsxs(Rr,{className:"space-y-4",children:[o.jsxs("div",{className:"space-y-2",children:[o.jsx(ge,{className:"text-neutral3",children:"Background Task Duration"}),o.jsxs(ge,{className:"text-neutral6 text-ui-md",children:[x2t(c,3),"ms"]})]}),o.jsxs("div",{className:"space-y-2",children:[o.jsx(ge,{className:"text-neutral3",children:"Background Task Arguments"}),h]}),v!==void 0&&p&&o.jsxs("div",{className:"space-y-2",children:[o.jsx(ge,{className:"text-neutral3",children:"Background Task Suspend Data"}),v]}),m!==void 0&&f&&o.jsxs("div",{className:"space-y-2",children:[o.jsx(ge,{className:"text-neutral3",children:"Background Task Result"}),m]})]})]})})},B_e=({backgroundTask:e})=>{const[t,n]=g.useState(!1);return o.jsxs(o.Fragment,{children:[o.jsx(de,{variant:"default",size:"icon-md",tooltip:"Show background task information",onClick:()=>n(r=>!r),children:e.completedAt||e.suspendedAt?o.jsx(ect,{className:"text-neutral3 size-5"}):o.jsx(oa,{className:"text-neutral3 size-5 animate-spin"})}),o.jsx(s$r,{backgroundTaskTaskId:e.taskId,backgroundTaskStartedAt:e.startedAt,backgroundTaskCompletedAt:e.completedAt,backgroundTaskSuspendedAt:e.suspendedAt,open:t,onOpenChange:n})]})},c4=({children:e,initialCollapsed:t=!0,icon:n,title:r,collapsible:s=!0,extraInfo:a,"data-testid":i})=>{const[l,c]=g.useState(t);return g.useEffect(()=>{c(t)},[t]),o.jsxs("div",{className:"mb-4","data-testid":i,children:[o.jsxs("div",{className:"flex flex-row gap-2 items-center justify-between",children:[o.jsxs("button",{onClick:s?()=>c(u=>!u):void 0,className:"flex items-center gap-2 disabled:cursor-not-allowed",disabled:!s,type:"button",children:[o.jsx(Ue,{children:o.jsx(f_,{className:K("transition-all",l?"rotate-90":"rotate-180")})}),o.jsx(dn,{icon:n,children:r})]}),a]}),!l&&o.jsx("div",{className:"pt-2",children:o.jsx("div",{className:"p-4 rounded-lg bg-surface2 flex flex-col gap-4",children:e})})]})},a$r=({selectionReason:e,open:t,onOpenChange:n,input:r})=>{let s=null;if(r)try{s=typeof r=="object"?o.jsx(Qr,{data:r}):o.jsx(Qr,{data:JSON.parse(r)})}catch{s=o.jsx("pre",{className:"whitespace-pre-wrap",children:r})}return o.jsx(br,{open:t,onOpenChange:n,children:o.jsxs(xr,{children:[o.jsxs(wr,{children:[o.jsx(gr,{children:"Agent Network Metadata"}),o.jsx(Qs,{children:"View the metadata of the agent's network choice."})]}),o.jsxs(Rr,{className:"space-y-4",children:[o.jsxs("div",{className:"space-y-2",children:[o.jsx(ge,{className:"text-neutral3",children:"Selection Reason"}),o.jsx("div",{className:"text-neutral6 text-ui-md",children:e})]}),s&&o.jsxs("div",{className:"space-y-2",children:[o.jsx(ge,{className:"text-neutral3",children:"Input"}),o.jsx("div",{className:"text-neutral6 text-ui-md",children:s})]})]})]})})},U_e=({selectionReason:e,input:t})=>{const[n,r]=g.useState(!1);return o.jsxs(o.Fragment,{children:[o.jsx(de,{variant:"default",size:"icon-md",tooltip:"Show selection reason",onClick:()=>r(s=>!s),children:o.jsx(ect,{className:"text-neutral3 size-5"})}),o.jsx(a$r,{selectionReason:e||"",open:n,onOpenChange:r,input:t})]})},bI=({toolCalled:e,toolCallId:t,toolApprovalMetadata:n,toolName:r,isNetwork:s,isGenerateMode:a})=>{const{approveToolcall:i,declineToolcall:l,approveToolcallGenerate:c,declineToolcallGenerate:u,isRunning:d,toolCallApprovals:f,approveNetworkToolcall:p,declineNetworkToolcall:h,networkToolCallApprovals:m}=u2t(),v=()=>{s?p(r,n?.runId):a?c(t):i(t)},y=()=>{s?h(r,n?.runId):a?u(t):l(t)},b=s?m?.[n?.runId?`${n.runId}-${r}`:r]?.status:f?.[t]?.status;return n&&!e?o.jsxs("div",{children:[o.jsx("p",{className:"font-medium pb-2",children:"Approval required"}),o.jsxs("div",{className:"flex gap-2 items-center",children:[o.jsxs(de,{onClick:v,disabled:d||!!b,className:b==="approved"?"text-accent1!":"",children:[o.jsx(Ue,{children:o.jsx(Js,{})}),"Approve"]}),o.jsxs(de,{onClick:y,disabled:d||!!b,className:b==="declined"?"text-accent2!":"",children:[o.jsx(Ue,{children:o.jsx(vs,{})}),"Decline"]})]})]}):null},i$r=({agentId:e,messages:t=[],metadata:n,toolCallId:r,toolApprovalMetadata:s,toolName:a,isNetwork:i,suspendPayload:l,toolCalled:c,isComplete:u=!1,keepOpenForStreamingChildMessages:d=!1})=>{const f=n?.mode==="network"?n.routingDecision:void 0,p=n?.mode==="network"?f?.selectionReason??n.selectionReason:void 0,h=n?.mode==="network"?f??n.agentInput:void 0,m=n?.mode==="stream"||n?.mode==="network"||n?.mode==="generate"?n?.requireApprovalMetadata:void 0,v=n?.mode==="stream"||n?.mode==="network"||n?.mode==="generate"?n?.suspendedTools:void 0,y=(n?.mode==="stream"||n?.mode==="generate")&&n?.backgroundTasks?n.backgroundTasks[r]:void 0,b=t.length>0&&t.every(_=>_.type==="text"?!0:_.toolOutput!==void 0);let S=b;i&&(S=c??b);const w=u&&!s&&!d;let k=typeof l=="string"?o.jsx("pre",{className:"whitespace-pre bg-surface4 p-4 rounded-md overflow-x-auto",children:l}):o.jsx(Qr,{data:l,"data-testid":"tool-suspend-payload"});return o.jsxs(c4,{"data-testid":"agent-badge",icon:o.jsx(sl,{className:"text-accent1"}),title:e,initialCollapsed:w,extraInfo:n?.mode==="network"?o.jsx(U_e,{selectionReason:p??"",input:h}):y?.taskId&&y?.startedAt?o.jsx(B_e,{backgroundTask:y}):null,children:[t.map((_,C)=>{if(_.type==="text")return o.jsx(JNt,{children:_.content},C);let E;try{E=typeof _.toolOutput=="string"?JSON.parse(_.toolOutput):_.toolOutput}catch{E=_.toolOutput}return o.jsx(Le.Fragment,{children:o.jsx(gje,{toolName:_.toolName,input:_.args,output:E,state:"output-available",toolCallId:_.toolCallId,metadata:{mode:"stream",requireApprovalMetadata:m,suspendedTools:v}})},C)}),k!==void 0&&l&&o.jsxs("div",{children:[o.jsx("p",{className:"font-medium pb-2",children:"Agent suspend payload"}),k]}),o.jsx(bI,{toolCalled:S,toolCallId:r,toolApprovalMetadata:s,toolName:a,isNetwork:i,isGenerateMode:n?.mode==="generate"})]})},q_e=()=>o.jsx(c4,{icon:o.jsx(Gt,{className:"text-neutral3"}),title:o.jsx(bt,{className:"ml-2 w-12 h-2"}),collapsible:!1}),o$r=e=>{const t=e.find(r=>r.role==="assistant");if(!t)return[];const n=[];for(const r of t.parts??[]){const s=r;if(typeof r.type=="string"&&r.type.startsWith("tool-")){const a=r.type.substring(5),i=a.startsWith("workflow-");n.push({type:"tool",toolCallId:s.toolCallId,toolName:a,args:s.input,toolOutput:i?{...s.output?.result,runId:s.output?.runId}:s.output})}r.type==="text"&&n.push({type:"text",content:s.text})}return n},l$r=({agentId:e,result:t,metadata:n,toolCallId:r,toolApprovalMetadata:s,toolName:a,isNetwork:i,suspendPayload:l,toolCalled:c,isComplete:u})=>{const d=!!(t?.subAgentThreadId&&!t.text&&!t.subAgentToolResults?.length),{data:f,isLoading:p}=WV({threadId:d?t?.subAgentThreadId:void 0,agentId:e,memory:!0});if(p)return o.jsx(q_e,{});const h=f?.messages?n$r(f.messages):[];let m=t?.childMessages?.length?t.childMessages:void 0;if(!m&&t?.subAgentToolResults?.length){const y=t.subAgentToolResults.map(b=>({type:"tool",toolName:b.toolName,toolCallId:b.toolCallId,args:b.args,toolOutput:b.result}));t.text&&y.push({type:"text",content:t.text}),m=y}!m&&t?.text&&(m=[{type:"text",content:t.text}]),m||(m=o$r(h));const v=!!(t&&Object.prototype.hasOwnProperty.call(t,"childMessages"));return o.jsx(i$r,{agentId:e,messages:m??[],keepOpenForStreamingChildMessages:v,metadata:n,toolCallId:r,toolApprovalMetadata:s,toolName:a,isNetwork:i,suspendPayload:l,toolCalled:c,isComplete:u})},c$r=e=>o.jsxs("svg",{width:"126",height:"85",viewBox:"0 0 126 85",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:[o.jsx("path",{d:"M119.322 35.1641C119.322 50.36 94.1055 62.6787 62.9998 62.6787C31.894 62.6787 6.67773 50.36 6.67773 35.1641V49.8368C6.67773 65.0327 31.894 77.3514 62.9998 77.3514C94.1055 77.3514 119.322 65.0327 119.322 49.8368V35.1641Z",fill:"#2E2E2E",fillOpacity:"0.9"}),o.jsx("path",{d:"M119.322 35.1641C119.322 50.36 94.1055 62.6787 62.9998 62.6787C31.894 62.6787 6.67773 50.36 6.67773 35.1641M119.322 35.1641C119.322 19.9681 94.1055 7.64941 62.9998 7.64941C31.894 7.64941 6.67773 19.9681 6.67773 35.1641M119.322 35.1641V49.8368C119.322 65.0327 94.1055 77.3514 62.9998 77.3514C31.894 77.3514 6.67773 65.0327 6.67773 49.8368V35.1641",stroke:"#424242"}),o.jsx("path",{d:"M63.0002 0.96875C28.5152 0.96875 0.55957 15.6489 0.55957 33.7578V51.2433C0.55957 69.3522 28.5152 84.0323 63.0002 84.0323C97.4853 84.0323 125.441 69.3522 125.441 51.2433V33.7578C125.441 15.6489 97.4853 0.96875 63.0002 0.96875Z",stroke:"#707070"}),o.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M95.8997 32.6647C98.4806 33.9355 98.4744 36.0012 95.8997 37.2689L89.6657 40.3384C87.0848 41.6091 82.8892 41.6061 80.3146 40.3384L74.0805 37.2689C71.4996 35.9981 71.5059 33.9324 74.0805 32.6647L80.3146 29.5952C82.8955 28.3244 87.091 28.3275 89.6657 29.5952L95.8997 32.6647ZM74.0805 21.9215C76.6614 23.1923 76.6552 25.258 74.0805 26.5257L67.8465 29.5952C65.2656 30.866 61.0701 30.8629 58.4954 29.5952L52.2613 26.5257C49.6804 25.255 49.6867 23.1892 52.2613 21.9215L58.4954 18.852C61.0763 17.5813 65.2718 17.5843 67.8465 18.852L74.0805 21.9215ZM74.0805 43.4079C76.6614 44.6786 76.6552 46.7444 74.0805 48.0121L67.8465 51.0816C65.2656 52.3523 61.0701 52.3493 58.4954 51.0816L52.2613 48.0121C49.6804 46.7413 49.6867 44.6756 52.2613 43.4079L58.4954 40.3384C61.0763 39.0676 65.2718 39.0707 67.8465 40.3384L74.0805 43.4079ZM52.2613 32.6647C54.8422 33.9355 54.836 36.0012 52.2613 37.2689L46.0273 40.3384C43.4464 41.6091 39.2509 41.6061 36.6762 40.3384L30.4422 37.2689C27.8613 35.9981 27.8675 33.9324 30.4422 32.6647L36.6762 29.5952C39.2571 28.3244 43.4526 28.3275 46.0273 29.5952L52.2613 32.6647Z",fill:"#A9A9A9"})]});let nZe;const w2t=()=>nZe??=Promise.all([jo(()=>import("./standalone-BioU5qLH.js"),[],import.meta.url),jo(()=>import("./babel-CmeIX3PZ.js"),[],import.meta.url),jo(()=>import("./estree-CRgMSIiv.js"),[],import.meta.url)]).catch(e=>{throw nZe=void 0,e}),Dj=async e=>{const[t,n,r]=await w2t();return await t.format(e,{semi:!1,parser:"json",printWidth:80,tabWidth:2,plugins:[n,r]})},u$r=async e=>{const[t,n,r]=await w2t();return await t.format(e,{parser:"babel-ts",printWidth:80,tabWidth:2,plugins:[n,r]})},DM=e=>{try{const t=JSON.parse(e);return!!t&&typeof t=="object"}catch{return!1}},d$r=(e,t)=>{let n;try{n=typeof e=="object"?e:JSON.parse(e)}catch{return null}const r=n?.code;return typeof r!="string"?null:t==null?{code:r}:typeof t=="object"&&typeof t.success=="boolean"&&("result"in t||"logs"in t||"error"in t)?{code:r,result:t}:null},f$r=({toolName:e,code:t,result:n,metadata:r,toolCallId:s,toolApprovalMetadata:a,isNetwork:i,toolCalled:l})=>{const c=n?.logs??[],u=n?.error,d=n!==void 0&&n.result!==void 0,f=l??n!==void 0,[p,h]=g.useState(t);return g.useEffect(()=>{let m=!1;return u$r(t).then(v=>{m||h(v)}).catch(()=>{m||h(t)}),()=>{m=!0}},[t]),o.jsx(c4,{"data-testid":"code-mode-badge",icon:o.jsx(c$r,{className:"text-accent6"}),title:e,initialCollapsed:!a,children:o.jsxs("div",{className:"space-y-4",children:[o.jsxs("div",{children:[o.jsx("p",{className:"font-medium pb-2",children:"Program"}),o.jsx("div",{"data-testid":"code-mode-program",children:o.jsx(v_e,{code:p,lang:"typescript"})})]}),u&&o.jsxs("div",{children:[o.jsx("p",{className:"font-medium pb-2",children:"Error"}),o.jsxs("pre",{"data-testid":"code-mode-error",className:"whitespace-pre-wrap break-words bg-surface4 p-4 rounded-md text-error font-mono text-sm",children:[u.name?`${u.name}: `:"",u.message,typeof u.line=="number"?` (line ${u.line})`:""]})]}),d&&o.jsxs("div",{children:[o.jsx("p",{className:"font-medium pb-2",children:"Result"}),typeof n.result=="string"?o.jsx("pre",{className:"whitespace-pre bg-surface4 p-4 rounded-md overflow-x-auto","data-testid":"code-mode-result",children:n.result}):o.jsx(Qr,{data:n.result,"data-testid":"code-mode-result"})]}),c.length>0&&o.jsxs("div",{children:[o.jsx("p",{className:"font-medium pb-2",children:"Logs"}),o.jsx("pre",{"data-testid":"code-mode-logs",className:"whitespace-pre-wrap break-words bg-black p-3 rounded-md text-neutral-300 font-mono text-sm overflow-x-auto",children:c.join(`
|
|
513
513
|
`)})]}),o.jsx(bI,{toolCalled:f,toolCallId:s,toolApprovalMetadata:a,toolName:e,isNetwork:i,isGenerateMode:r?.mode==="generate"})]})})},p$r=({toolName:e,args:t,result:n,toolCallId:r,toolApprovalMetadata:s,isNetwork:a,toolCalled:i,dataParts:l})=>{const[c,u]=g.useState(!s),{isCopied:d,copyToClipboard:f}=Bp({copiedDuration:1500,showToast:!1});g.useEffect(()=>{u(!s)},[s]);const{Link:p}=yn();let h={path:"."};try{h=typeof t=="object"?t:JSON.parse(t)}catch{}const{path:m=".",maxDepth:v,showHidden:y,dirsOnly:b,exclude:S,extension:w}=h,k=[];v!==void 0&&v!==3&&k.push(`depth: ${v}`),y&&k.push("hidden"),b&&k.push("dirs only"),S&&k.push(`exclude: ${S}`),w&&k.push(`ext: ${w}`);let _="",C="";if(typeof n=="string"&&n){const P=n.lastIndexOf(`
|
|
514
514
|
|
|
515
515
|
`);P!==-1?(_=n.slice(0,P),C=n.slice(P+2)):_=n}const E=!!_,j=i??E,I=g.useMemo(()=>(l??[]).find(P=>P.type==="data"&&P.name==="workspace-metadata"&&P.data?.toolCallId===r),[l,r])?.data,R=()=>{!_||d||f(_)};return o.jsxs("div",{className:"mb-4","data-testid":"file-tree-badge",children:[o.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[o.jsxs("button",{onClick:()=>u(P=>!P),className:"flex items-center gap-2 min-w-0",type:"button",children:[o.jsx(Ue,{children:o.jsx(f_,{className:K("transition-all",c?"rotate-90":"rotate-180")})}),o.jsxs(dn,{icon:o.jsx(yun,{className:"text-accent6",size:16}),children:["List Files ",o.jsx("span",{className:"text-neutral6 font-normal ml-1",children:m}),k.length>0&&o.jsxs("span",{className:"text-neutral4 font-normal ml-1",children:["(",k.join(", "),")"]})]})]}),I?.filesystem&&o.jsxs(p,{href:I.id?`/workspaces/${I.id}?path=${encodeURIComponent(m)}`:"/workspaces",className:"flex items-center gap-1.5 text-xs text-neutral6 px-1.5 py-0.5 rounded bg-surface3 border border-border1 hover:bg-surface4 hover:border-border2 transition-colors",children:[o.jsx(Kde,{className:"size-3"}),o.jsx("span",{children:I.name||I.filesystem.name})]}),c&&E&&C&&o.jsx("span",{className:"text-neutral6 text-xs",children:C})]}),!c&&o.jsxs("div",{className:"pt-2",children:[s&&!j&&o.jsxs("div",{className:"p-4 rounded-lg bg-surface2 flex flex-col gap-4",children:[o.jsxs("div",{children:[o.jsx("p",{className:"font-medium pb-2",children:"Tool arguments"}),o.jsx(Qr,{data:h,"data-testid":"tool-args"})]}),o.jsx(bI,{toolCalled:j,toolCallId:r,toolApprovalMetadata:s,toolName:e,isNetwork:a})]}),j&&_&&o.jsxs("div",{className:"rounded-md border border-border1 bg-surface2 overflow-hidden",children:[o.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 border-b border-border1 bg-surface3",children:[C&&o.jsx("span",{className:"text-neutral6 text-xs",children:C}),o.jsx(de,{variant:"default",size:"icon-sm",tooltip:"Copy tree",onClick:R,disabled:!_,children:o.jsxs("span",{className:"grid",children:[o.jsx("span",{style:{gridArea:"1/1"},className:K("transition-transform",d?"scale-100":"scale-0"),children:o.jsx(Js,{size:14})}),o.jsx("span",{style:{gridArea:"1/1"},className:K("transition-transform",d?"scale-0":"scale-100"),children:o.jsx(Dp,{size:14})})]})})]}),o.jsx("pre",{className:"p-3 text-xs font-mono text-mastra-el-6 overflow-x-auto whitespace-pre max-h-dropdown-max-height overflow-y-auto",children:_})]}),j&&!E&&o.jsx("div",{className:"rounded-md border border-border1 bg-surface2 px-3 py-2",children:o.jsx("span",{className:"text-xs text-neutral6",children:"Loading..."})})]})]})},h$r={"🔴":"text-foreground","🟡":"text-foreground","🟢":"text-foreground"},m$r={"🔴":"bg-purple-500/15","🟡":"bg-blue-500/15","🟢":"bg-green-500/15"},g$r={"🔴":"border-l-purple-500","🟡":"border-l-blue-500","🟢":"border-l-green-500"};function v$r(e,t=!1){const n=e.trim();if(!n)return null;if(n.startsWith("* ->")||n.startsWith("->"))return{priority:null,time:null,content:n.replace(/^\*?\s*->\s*/,""),children:[],isNested:!0};if(t&&n.startsWith("-")){const s=n.replace(/^-\s*/,"");return s?{priority:null,time:null,content:s,children:[],isNested:!0}:null}const r=n.match(/^\*\s*(🔴|🟡|🟢)?\s*(?:\((\d{1,2}:\d{2})\))?\s*(.+)$/);if(r){const[,s,a,i]=r;return{priority:s||null,time:a||null,content:i.trim(),children:[],isNested:t}}return n.startsWith("*")?{priority:null,time:null,content:n.replace(/^\*\s*/,""),children:[],isNested:t}:null}function y$r(e){const t={threads:[]},n=e.match(/<current-task>\s*([\s\S]*?)\s*<\/current-task>/);n&&(t.currentTask=n[1].trim());const r=e.match(/<suggested-response>\s*([\s\S]*?)\s*<\/suggested-response>/);r&&(t.suggestedResponse=r[1].trim());const s=e.match(/<observations>\s*([\s\S]*?)\s*<\/observations>/),i=(s?s[1]:e).split(/(?=Thread [a-f0-9]+:)/i);for(const l of i){const c=l.trim();if(!c)continue;const u=c.match(/^Thread ([a-f0-9]+):/i),d=u?u[1]:"default",f=u?c.replace(/^Thread [a-f0-9]+:\s*/i,""):c,p={threadId:d,dateBlocks:[]},h=f.split(`
|
|
@@ -724,7 +724,7 @@ window.parent.postMessage({jsonrpc:'2.0',method:'ui/notifications/sandbox-proxy-
|
|
|
724
724
|
"groundTruth": "Expected result (optional)",
|
|
725
725
|
"metadata": { "key": "value" } // optional
|
|
726
726
|
}
|
|
727
|
-
]`})]})]})}function Ses({errors:e,maxErrors:t=5}){if(e.length===0)return null;const n=e.slice(0,t),r=e.length-t;return o.jsxs("div",{className:"bg-accent2/10 border border-accent2/30 rounded-md p-3",children:[o.jsxs("div",{className:"flex items-center gap-2 text-accent2 mb-2",children:[o.jsx(Ue,{children:o.jsx(Ep,{className:"w-4 h-4"})}),o.jsxs("span",{className:"font-medium text-sm",children:[e.length," validation error",e.length!==1?"s":""]})]}),o.jsx("ul",{className:"text-sm text-accent2/80 space-y-1",children:n.map((s,a)=>o.jsxs("li",{className:"flex gap-2",children:[o.jsx("span",{className:"shrink-0",children:"•"}),o.jsx("span",{children:s.message})]},a))}),r>0&&o.jsxs("div",{className:"text-xs text-accent2/60 mt-2",children:["+",r," more error",r!==1?"s":""]})]})}function kes({datasetId:e,open:t,onOpenChange:n,onSuccess:r}){const[s,a]=g.useState("upload"),[i,l]=g.useState(null),[c,u]=g.useState({current:0,total:0}),[d,f]=g.useState(null),[p,h]=g.useState(!1),{parseFile:m,isParsing:v,error:y}=QKr(),{batchInsertItems:b}=Ei(),S=g.useCallback(async I=>{try{const R=await m(I);l(R),a("preview")}catch{}},[m]),w=g.useCallback(async()=>{if(!i||i.items.length===0)return;a("importing"),h(!0);const{items:I}=i;u({current:0,total:I.length});try{await b.mutateAsync({datasetId:e,items:I.map(R=>({input:R.input,groundTruth:R.groundTruth,metadata:R.metadata}))}),f({success:I.length,errors:0})}catch{f({success:0,errors:I.length})}u({current:I.length,total:I.length}),h(!1),a("complete")},[i,b,e]),k=g.useCallback(()=>{n(!1),r?.(),d&&d.success>0&&De.success(`Imported ${d.success} item${d.success!==1?"s":""}`),setTimeout(()=>{a("upload"),l(null),u({current:0,total:0}),f(null)},150)},[n,r,d]),_=g.useCallback(()=>{p||(n(!1),setTimeout(()=>{a("upload"),l(null),u({current:0,total:0}),f(null)},150))},[p,n]),C=i&&i.items.length>0&&i.errors.length===0,E=()=>{switch(s){case"upload":return o.jsx(wes,{onFileSelect:S,isParsing:v,error:y?.message});case"preview":return i?o.jsx("div",{className:"flex flex-col gap-4",children:i.errors.length>0?o.jsxs(o.Fragment,{children:[o.jsx(Ses,{errors:i.errors}),o.jsx("div",{className:"text-sm text-neutral4",children:"Please fix the errors in your JSON file and try again."})]}):o.jsxs(o.Fragment,{children:[o.jsxs("div",{className:"text-sm text-neutral4",children:["Found ",i.items.length," valid item",i.items.length!==1?"s":""," to import."]}),o.jsx(xes,{items:i.items,maxRows:5})]})}):null;case"importing":return o.jsxs("div",{className:"flex flex-col items-center gap-4 py-8",children:[o.jsx(Gt,{}),o.jsxs("div",{className:"text-center",children:[o.jsx("div",{className:"text-lg font-medium text-neutral1",children:"Importing items..."}),o.jsxs("div",{className:"text-sm text-neutral4 mt-1",children:[c.current," of ",c.total]})]})]});case"complete":return o.jsxs("div",{className:"flex flex-col items-center gap-4 py-8",children:[o.jsx("div",{className:"text-4xl",children:d&&d.errors===0?"✓":"⚠"}),o.jsxs("div",{className:"text-center",children:[o.jsx("div",{className:"text-lg font-medium text-neutral1",children:"Import Complete"}),o.jsxs("div",{className:"text-sm text-neutral4 mt-1",children:[d?.success??0," item",d?.success!==1?"s":""," imported",d&&d.errors>0&&o.jsxs("span",{className:"text-accent2",children:[" ","(",d.errors," error",d.errors!==1?"s":"",")"]})]})]})]})}},j=()=>{switch(s){case"upload":return o.jsx(de,{onClick:_,children:"Cancel"});case"preview":return o.jsxs(o.Fragment,{children:[o.jsx(de,{onClick:()=>a("upload"),children:"Back"}),o.jsxs(de,{variant:"primary",onClick:w,disabled:!C,children:["Import ",i?.items.length??0," Item",i?.items.length!==1?"s":""]})]});case"importing":return null;case"complete":return o.jsx(de,{variant:"primary",onClick:k,children:"Done"})}},N={upload:"Import JSON",preview:"Preview Data",importing:"Importing",complete:"Import Complete"};return o.jsx(br,{open:t,onOpenChange:_,children:o.jsxs(xr,{className:"max-w-2xl max-h-[90vh]",children:[o.jsxs(wr,{children:[o.jsx(gr,{children:N[s]}),o.jsx(Qs,{children:"Import dataset items from a JSON file."})]}),o.jsx(Rr,{className:"min-h-[200px] max-h-[50vh] overflow-y-auto",children:E()}),o.jsx(Cc,{className:"px-6 pt-4 flex justify-end gap-2",children:j()})]})})}const xTe=e=>{const t=We(),{data:n}=tD(e),r=n?.experiments;return wt({queryKey:["dataset-review-items",e,r?.map(s=>s.id)],queryFn:async()=>!r||r.length===0?[]:(await Promise.all(r.map(async a=>{if(!a.datasetId)return[];try{const{results:i}=await t.listDatasetExperimentResults(a.datasetId,a.id);return i.filter(l=>l.status==="needs-review").map(l=>({id:l.id,input:l.input,output:l.output,error:l.error,itemId:l.itemId,experimentId:l.experimentId,datasetId:a.datasetId??void 0,traceId:l.traceId??void 0,scores:l.scores?Object.fromEntries(l.scores.map(c=>[c.scorerId,c.score??0])):{},tags:l.tags??[],comment:""}))}catch{return[]}}))).flat(),enabled:!!e&&!!r&&r.length>0,refetchOnWindowFocus:!1})},Oes=e=>{const t=We(),{data:n}=tD(e),r=n?.experiments;return wt({queryKey:["dataset-completed-items",e,r?.map(s=>s.id)],queryFn:async()=>!r||r.length===0?[]:(await Promise.all(r.map(async a=>{if(!a.datasetId)return[];try{const{results:i}=await t.listDatasetExperimentResults(a.datasetId,a.id);return i.filter(l=>l.status==="complete").map(l=>({id:l.id,input:l.input,output:l.output,error:l.error,itemId:l.itemId,experimentId:l.experimentId,datasetId:a.datasetId??void 0,traceId:l.traceId??void 0,scores:l.scores?Object.fromEntries(l.scores.map(c=>[c.scorerId,c.score??0])):{},tags:l.tags??[],comment:""}))}catch{return[]}}))).flat(),enabled:!!e&&!!r&&r.length>0,refetchOnWindowFocus:!1})};function _es(e,t){if(typeof e=="string")return e.length>t?e.slice(0,t)+"...":e;try{const n=JSON.stringify(e);return n.length>t?n.slice(0,t)+"...":n}catch{return String(e)}}function A9t({datasetId:e,experimentId:t,featuredItemId:n}){const r=We(),{data:s}=Hx(e),{data:a,isLoading:i}=xTe(e),{data:l,isLoading:c}=Oes(e),u=g.useMemo(()=>t?(a??[]).filter(Ee=>Ee.experimentId===t):a,[a,t]),d=g.useMemo(()=>t?(l??[]).filter(Ee=>Ee.experimentId===t):l,[l,t]),{updateExperimentResult:f}=Ei(),[p,h]=g.useState(n??null);g.useEffect(()=>{n!==void 0&&h(n)},[n]);const[m,v]=g.useState(null),[y,b]=g.useState(new Set),[S,w]=g.useState(!1),[k,_]=g.useState(!1),[C,E]=g.useState(!1),[j,N]=g.useState(""),[I,R]=g.useState(""),[P,L]=g.useState(""),[M,q]=g.useState([]),[H,F]=g.useState(!1),[z,B]=g.useState(null),D=g.useMemo(()=>z??u??[],[z,u]);g.useEffect(()=>{B(null)},[e,t]),g.useEffect(()=>{u&&z===null&&B(u)},[u,z]);const Q=g.useMemo(()=>{const Ee=new Set;if(s?.tags)for(const _e of s.tags)Ee.add(_e);for(const _e of D)for(const Ce of _e.tags)Ee.add(Ce);return[...Ee].sort()},[s,D]),V=g.useCallback(Ee=>{!s||!e||(s.tags??[]).includes(Ee)},[s,e]),$=g.useMemo(()=>m?m==="__untagged__"?D.filter(Ee=>Ee.tags.length===0):D.filter(Ee=>Ee.tags.includes(m)):D,[D,m]),U=g.useMemo(()=>{const Ee=new Map;for(const _e of D)for(const Ce of _e.tags)Ee.set(Ce,(Ee.get(Ce)??0)+1);return[...Ee.entries()].sort((_e,Ce)=>Ce[1]-_e[1])},[D]),Z=g.useMemo(()=>D.filter(Ee=>Ee.tags.length===0).length,[D]),X=g.useMemo(()=>{let Ee=0;return m&&Ee++,S&&Ee++,Ee},[m,S]),te=g.useCallback((Ee,_e)=>{B(Oe=>(Oe??[]).map(Re=>Re.id===Ee?{...Re,tags:_e}:Re));const Ce=D.find(Oe=>Oe.id===Ee);Ce?.experimentId&&Ce?.datasetId&&f.mutate({datasetId:Ce.datasetId,experimentId:Ce.experimentId,resultId:Ce.id,tags:_e})},[D,f]),J=g.useCallback((Ee,_e)=>{const Ce=D.find(Oe=>Oe.id===Ee);Ce?.traceId&&_e!==void 0&&r.createFeedback({feedback:{traceId:Ce.traceId,source:"studio",feedbackSource:"studio",feedbackType:"rating",value:_e==="positive"?1:-1,experimentId:Ce.experimentId??void 0,sourceId:Ce.id}}).catch(()=>{}),B(Oe=>(Oe??[]).map(Re=>Re.id===Ee?{...Re,rating:_e}:Re))},[D,r]),ee=g.useCallback((Ee,_e)=>{const Ce=D.find(Oe=>Oe.id===Ee);Ce?.traceId&&r.createFeedback({feedback:{traceId:Ce.traceId,source:"studio",feedbackSource:"studio",feedbackType:"comment",value:_e,comment:_e,experimentId:Ce.experimentId??void 0,sourceId:Ce.id}}).catch(()=>{}),B(Oe=>(Oe??[]).map(Re=>Re.id===Ee?{...Re,comment:_e}:Re))},[D,r]),ae=g.useCallback(Ee=>{const _e=D.find(Ce=>Ce.id===Ee);B(Ce=>(Ce??[]).filter(Oe=>Oe.id!==Ee)),b(Ce=>{const Oe=new Set(Ce);return Oe.delete(Ee),Oe}),p===Ee&&h(null),_e?.experimentId&&_e?.datasetId&&f.mutate({datasetId:_e.datasetId,experimentId:_e.experimentId,resultId:_e.id,status:null})},[D,f,p]),ce=g.useCallback(Ee=>{const _e=D.find(Ce=>Ce.id===Ee);B(Ce=>(Ce??[]).filter(Oe=>Oe.id!==Ee)),b(Ce=>{const Oe=new Set(Ce);return Oe.delete(Ee),Oe}),p===Ee&&h(null),_e?.experimentId&&_e?.datasetId&&f.mutate({datasetId:_e.datasetId,experimentId:_e.experimentId,resultId:_e.id,status:"complete"})},[D,f,p]),Y=g.useMemo(()=>{const Ee=S?d??[]:$;return!S||!m?Ee:m==="__untagged__"?Ee.filter(_e=>_e.tags.length===0):Ee.filter(_e=>_e.tags.includes(m))},[S,d,$,m]),ne=S?c:!1,ue=g.useMemo(()=>new Set(Y.map(Ee=>Ee.id)),[Y]),pe=g.useMemo(()=>[...y].filter(Ee=>ue.has(Ee)).length,[y,ue]),le=Y.length>0&&pe===Y.length,ve=pe>0&&!le,ye=g.useCallback(Ee=>{b(_e=>{const Ce=new Set(_e);return Ce.has(Ee)?Ce.delete(Ee):Ce.add(Ee),Ce})},[]),Se=g.useCallback(()=>{b(le?new Set:new Set(Y.map(Ee=>Ee.id)))},[le,Y]),Ne=g.useCallback(Ee=>{for(const _e of y){const Ce=D.find(Oe=>Oe.id===_e);Ce&&!Ce.tags.includes(Ee)&&te(_e,[...Ce.tags,Ee])}},[D,y,te]),ke=g.useCallback(Ee=>{for(const _e of y){const Ce=D.find(Oe=>Oe.id===_e);Ce&&Ce.tags.includes(Ee)&&te(_e,Ce.tags.filter(Oe=>Oe!==Ee))}},[D,y,te]),Ie=g.useCallback(()=>{for(const Ee of y)ce(Ee);b(new Set)},[y,ce]),ze=g.useCallback(()=>{for(const Ee of y)ae(Ee);b(new Set)},[y,ae]),oe=g.useCallback(()=>{N(""),E(!0)},[]),se=g.useCallback(async()=>{if(!(!I||!P)){_(!0),E(!1);try{const Ee=D.filter(Ce=>y.has(Ce.id));if(Ee.length===0){_(!1);return}const _e=await r.clusterFailures({modelId:`${I}/${P}`,items:Ee.map(Ce=>({id:Ce.id,input:Ce.input,output:Ce.output??void 0,error:typeof Ce.error=="string"?Ce.error:Ce.error?String(Ce.error):void 0,scores:Ce.scores,existingTags:Ce.tags.length>0?Ce.tags:void 0})),availableTags:Q.length>0?Q:void 0,prompt:j||void 0});_e.proposedTags&&_e.proposedTags.length>0&&(q(_e.proposedTags.map(Ce=>({...Ce,accepted:!0}))),F(!0))}catch(Ee){console.error("Analysis failed:",Ee)}finally{_(!1)}}},[I,P,D,y,r,Q,j]),re=g.useCallback(()=>{for(const Ee of M){if(!Ee.accepted)continue;const _e=D.find(Ce=>Ce.id===Ee.itemId);if(_e){const Ce=[...new Set([..._e.tags,...Ee.tags])];te(_e.id,Ce)}}F(!1)},[M,D,te]),he=g.useCallback(Ee=>{h(_e=>_e===Ee?null:Ee)},[]),xe=g.useMemo(()=>p?Y.find(Ee=>Ee.id===p)??null:null,[p,Y]),je=p?Y.findIndex(Ee=>Ee.id===p):-1,Pe=je>0?()=>h(Y[je-1].id):void 0,Ge=je>=0&&je<Y.length-1?()=>h(Y[je+1].id):void 0,Ze="auto minmax(15rem,1fr) 10rem 8rem 6rem 6rem";return i?o.jsx("div",{className:"flex-1 flex items-center justify-center",children:o.jsx(Gt,{className:"w-6 h-6"})}):o.jsxs("div",{className:"flex flex-1 min-h-0 overflow-hidden",children:[o.jsx(br,{open:C,onOpenChange:E,children:o.jsxs(xr,{children:[o.jsxs(wr,{children:[o.jsx(gr,{children:"Analyze Items"}),o.jsx(Qs,{children:"Use an LLM to automatically suggest tags for the selected items."})]}),o.jsxs("div",{className:"space-y-4 py-2",children:[o.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[o.jsxs("div",{children:[o.jsx(Rt,{className:"text-xs mb-1 block",children:"Provider"}),o.jsx(zy,{value:I,onValueChange:R})]}),o.jsxs("div",{children:[o.jsx(Rt,{className:"text-xs mb-1 block",children:"Model"}),o.jsx(By,{llmId:I,value:P,onValueChange:L})]})]}),o.jsxs(ge,{variant:"ui-xs",className:"text-neutral3",children:[y.size," item",y.size!==1?"s":""," will be analyzed"]}),o.jsxs("div",{children:[o.jsx(Rt,{className:"text-xs",children:"Instructions (optional)"}),o.jsx(Kl,{value:j,onChange:Ee=>N(Ee.target.value),placeholder:"E.g., Focus on safety issues and factual errors...",rows:3,className:"text-xs mt-1"})]})]}),o.jsxs(Cc,{children:[o.jsx(de,{variant:"outline",onClick:()=>E(!1),children:"Cancel"}),o.jsxs(de,{onClick:se,disabled:!I||!P||k,children:[k?o.jsx(Gt,{className:"w-4 h-4 mr-1"}):null,"Analyze"]})]})]})}),o.jsx(br,{open:H,onOpenChange:F,children:o.jsxs(xr,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[o.jsxs(wr,{children:[o.jsx(gr,{children:"Review Proposed Tags"}),o.jsxs(Qs,{children:[M.filter(Ee=>Ee.accepted).length," of ",M.length," proposals selected"]})]}),o.jsx("div",{className:"space-y-3 py-2",children:M.map((Ee,_e)=>{const Ce=D.find(Oe=>Oe.id===Ee.itemId);return o.jsx("div",{className:K("p-3 border rounded-lg",!Ee.accepted&&"opacity-50"),children:o.jsxs("div",{className:"flex items-start gap-2",children:[o.jsx(Mo,{checked:Ee.accepted,onCheckedChange:Oe=>q(Re=>Re.map((qe,Ye)=>Ye===_e?{...qe,accepted:!!Oe}:qe))}),o.jsxs("div",{className:"flex-1 min-w-0",children:[o.jsx(ge,{variant:"ui-xs",className:"text-neutral4 truncate block",children:Ce?typeof Ce.input=="string"?Ce.input.slice(0,100):JSON.stringify(Ce.input).slice(0,100):Ee.itemId}),o.jsx("div",{className:"flex gap-1 flex-wrap mt-1.5",children:Ee.tags.map((Oe,Re)=>o.jsx(c9t,{tag:Oe,onRename:qe=>q(Ye=>Ye.map((tt,At)=>At===_e?{...tt,tags:tt.tags.map((ot,zt)=>zt===Re?qe:ot)}:tt)),onRemove:()=>q(qe=>qe.map((Ye,tt)=>tt===_e?{...Ye,tags:Ye.tags.filter((At,ot)=>ot!==Re)}:Ye))},`${Oe}-${Re}`))}),Ee.reason&&o.jsx(ge,{variant:"ui-xs",className:"text-neutral3 mt-1 block italic",children:Ee.reason})]})]})},Ee.itemId)})}),o.jsxs(Cc,{children:[o.jsx(de,{variant:"outline",onClick:()=>F(!1),children:"Cancel"}),o.jsxs(de,{onClick:re,disabled:M.filter(Ee=>Ee.accepted).length===0,children:["Accept ",M.filter(Ee=>Ee.accepted).length," proposals"]})]})]})}),o.jsxs("div",{className:K("grid w-full h-full grid-cols-1 gap-4 overflow-y-auto",xe&&"grid-cols-[1fr_1fr]"),children:[o.jsxs("div",{className:"grid gap-8 content-start w-full overflow-y-auto",children:[o.jsxs("div",{className:"flex items-center justify-between w-full flex-wrap gap-4 gap-x-6",children:[o.jsxs("div",{className:"flex items-center gap-3",children:[o.jsxs(pt,{children:[o.jsx(pt.Trigger,{asChild:!0,children:o.jsxs(de,{variant:"outline",size:"md",children:[o.jsx(Flt,{}),"Filter",X>0&&o.jsx("span",{className:K("ml-0.5 inline-flex items-center justify-center rounded-full bg-accent1/50 text-neutral5 text-ui-sm w-5 h-5"),children:X})]})}),o.jsxs(pt.Content,{align:"start",className:K("min-w-48"),children:[o.jsxs(pt.Sub,{children:[o.jsxs(pt.SubTrigger,{children:["Status",S&&o.jsx("span",{className:K("ml-auto text-ui-sm text-accent1"),children:"1"})]}),o.jsxs(pt.SubContent,{children:[o.jsx(pt.CheckboxItem,{checked:!S,onCheckedChange:()=>{w(!1),h(null)},onSelect:Ee=>Ee.preventDefault(),children:"Review Queue"}),o.jsx(pt.CheckboxItem,{checked:S,onCheckedChange:()=>{w(!0),h(null)},onSelect:Ee=>Ee.preventDefault(),children:"Completed"})]})]}),o.jsxs(pt.Sub,{children:[o.jsxs(pt.SubTrigger,{children:["Tags",m&&o.jsx("span",{className:K("ml-auto text-ui-sm text-accent1"),children:"1"})]}),o.jsxs(pt.SubContent,{children:[o.jsx(pt.CheckboxItem,{checked:!m,onCheckedChange:()=>v(null),onSelect:Ee=>Ee.preventDefault(),children:"All"}),Z>0&&o.jsx(pt.CheckboxItem,{checked:m==="__untagged__",onCheckedChange:()=>v(m==="__untagged__"?null:"__untagged__"),onSelect:Ee=>Ee.preventDefault(),children:"Untagged"}),U.length>0&&o.jsx(pt.Separator,{}),U.map(([Ee])=>o.jsx(pt.CheckboxItem,{checked:m===Ee,onCheckedChange:()=>v(m===Ee?null:Ee),onSelect:_e=>_e.preventDefault(),children:Ee},Ee))]})]}),X>0&&o.jsxs(o.Fragment,{children:[o.jsx(pt.Separator,{}),o.jsxs(pt.Item,{onSelect:()=>{v(null),w(!1),h(null)},children:[o.jsx(vs,{}),"Clear all filters"]})]})]})]}),X>0&&o.jsxs(de,{variant:"outline",size:"md",onClick:()=>{v(null),w(!1),h(null)},children:[o.jsx(vs,{}),"Reset"]})]}),!S&&y.size>0&&o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx(l9t,{selectedCount:y.size,vocabulary:Q,onApplyTag:Ne,onRemoveTag:ke,onNewTag:Ee=>Ne(Ee)}),o.jsxs(pt,{children:[o.jsx(pt.Trigger,{asChild:!0,children:o.jsxs(de,{disabled:k,children:[k?o.jsx(Gt,{className:"w-4 h-4"}):o.jsx(Ue,{size:"sm",children:o.jsx(Sa,{})}),"Actions"]})}),o.jsxs(pt.Content,{align:"end",children:[o.jsxs(pt.Item,{onSelect:Ie,children:[o.jsx(Ue,{size:"sm",children:o.jsx(uO,{})}),"Complete"]}),o.jsxs(pt.Item,{onSelect:ze,children:[o.jsx(Ue,{size:"sm",children:o.jsx(au,{})}),"Remove"]}),o.jsx(pt.Separator,{}),o.jsxs(pt.Item,{onSelect:oe,children:[o.jsx(Ue,{size:"sm",children:o.jsx(wg,{})}),"Analyze"]})]})]})]})]}),ne?o.jsx("div",{className:"flex-1 flex items-center justify-center",children:o.jsx(Gt,{className:"w-6 h-6"})}):Y.length===0?o.jsx("div",{className:"flex-1 flex items-center justify-center",children:o.jsxs("div",{className:"text-center px-8",children:[o.jsx(ge,{variant:"ui-sm",className:"text-neutral3 block",children:S?"No completed reviews yet":"No items to review"}),o.jsx(ge,{variant:"ui-xs",className:"text-neutral3 mt-2 block",children:S?"Items marked as complete will appear here for auditing.":"When experiment results are flagged for review, they will appear here."})]})}):o.jsxs(me,{columns:Ze,className:"min-w-0",children:[o.jsxs(me.Top,{hasLeadingCell:!0,children:[S?o.jsx(me.TopCell,{children:" "}):o.jsx(me.TopSelectCell,{checked:le?!0:ve?"indeterminate":!1,onToggle:()=>Se(),"aria-label":"Select all"}),o.jsxs(me.TopCells,{colStart:2,children:[o.jsx(me.TopCell,{children:"Input"}),o.jsx(me.TopCell,{children:"Comment"}),o.jsx(me.TopCell,{children:"Tags"}),o.jsx(me.TopCell,{children:"Rating"}),o.jsx(me.TopCell,{children:"Scores"})]})]}),Y.map(Ee=>{const _e=Ee.scores?Object.entries(Ee.scores):[],Ce=p===Ee.id,Oe=o.jsxs(o.Fragment,{children:[o.jsx(me.Cell,{height:"compact",className:"min-w-0 text-neutral4",children:o.jsx("span",{className:"block truncate",children:_es(Ee.input,200)})}),o.jsx(me.Cell,{height:"compact",className:"min-w-0",children:Ee.comment?o.jsx(ge,{variant:"ui-xs",className:"text-neutral3 truncate",children:Ee.comment}):o.jsx(ge,{variant:"ui-xs",className:"text-neutral2",children:"—"})}),o.jsx(me.Cell,{height:"compact",className:"min-w-0",children:Ee.tags.length>0?o.jsx(ge,{variant:"ui-xs",className:"text-neutral4 truncate",children:Ee.tags.join(", ")}):o.jsx(ge,{variant:"ui-xs",className:"text-neutral2",children:"—"})}),o.jsxs(me.Cell,{height:"compact",children:[Ee.rating==="positive"&&o.jsx(Ue,{size:"sm",className:"text-positive1",children:o.jsx(fbe,{})}),Ee.rating==="negative"&&o.jsx(Ue,{size:"sm",className:"text-negative1",children:o.jsx(dbe,{})}),!Ee.rating&&o.jsx(ge,{variant:"ui-xs",className:"text-neutral2",children:"—"})]}),o.jsx(me.Cell,{height:"compact",children:_e.length>0?o.jsxs("div",{className:"flex items-center gap-1",children:[o.jsx(Ue,{size:"sm",className:"text-neutral3",children:o.jsx(rm,{})}),o.jsx(ge,{variant:"ui-xs",className:"text-neutral4 font-mono",children:_e[0][1].toFixed(2)}),_e.length>1&&o.jsxs(dn,{variant:"default",children:["+",_e.length-1]})]}):o.jsx(ge,{variant:"ui-xs",className:"text-neutral2",children:"—"})})]});return o.jsxs(me.RowWrapper,{children:[S?o.jsx(me.Cell,{height:"compact",className:"justify-items-center px-4",children:o.jsx("div",{role:"img","aria-label":Ee.error?"Error":"Success",title:Ee.error?"Error":"Success",className:K("w-2 h-2 rounded-full",Ee.error?"bg-red-700":"bg-green-600")})}):o.jsx(me.SelectCell,{checked:y.has(Ee.id),onToggle:()=>ye(Ee.id),"aria-label":`Select item ${Ee.id}`}),o.jsx(me.RowButton,{flushLeft:!0,colStart:2,featured:Ce,onClick:()=>he(Ee.id),children:Oe})]},Ee.id)})]})]}),xe&&o.jsx(o9t,{item:xe,isCompleted:S,tagVocabulary:Q,onRate:Ee=>J(xe.id,Ee),onSetTags:Ee=>{te(xe.id,Ee);for(const _e of Ee)Q.includes(_e)||V(_e)},onComment:Ee=>ee(xe.id,Ee),onRemove:()=>ae(xe.id),onComplete:S?void 0:()=>ce(xe.id),onPrevious:Pe,onNext:Ge,onClose:()=>h(null)})]})]})}function Ces({datasetId:e,onAddItemClick:t,onNavigateToDataset:n}){const{navigate:r}=yn(),[s,a]=ga(),{tab:i,activeVersion:l,handleTabChange:c}=yTe(s,a),[u,d]=g.useState(!1),[f,p]=g.useState(!1),[h,m]=g.useState(!1),[v,y]=g.useState([]),[b,S]=g.useState(!1),[w,k]=g.useState([]),[_,C]=g.useState(!1),[E,j]=g.useState([]),[N,I]=g.useState(0),[R,P]=g.useState(null),[L,M]=g.useState(""),[q]=A0e(L,300),{data:H}=Hx(e),{data:F=[],total:z,isLoading:B,setEndOfListElement:D,isFetchingNextPage:Q,hasNextPage:V}=E1(e,q||void 0,l),{total:$}=E1(e,void 0,l),[U,Z]=g.useState({}),{data:X,isLoading:te}=tD(e,void 0,U),{data:J}=tD(e),{deleteItems:ee}=Ei(),ae=X?.experiments??[],ce=J?.experiments??[],Y=EJr({hasSearchQuery:!!q,filteredItemsLength:F.length,unfilteredItemsTotal:$,itemsTotal:z}),{data:ne}=xTe(e),ue=ne?.length??0,pe=re=>{P(re)},le=()=>{P(null)},ve=re=>{y(re),m(!0)},ye=re=>{k(re),S(!0)},Se=re=>{S(re),re||(k([]),I(he=>he+1))},Ne=re=>{r(`/datasets/${e}/items?items=${re.join(",")}`)},ke=re=>{r(`/datasets/${e}/versions?ids=${re.join(",")}`)},Ie=re=>{j(re),C(!0)},ze=async()=>{await ee.mutateAsync({datasetId:e,itemIds:E}),De.success(`Deleted ${E.length} items`),C(!1),j([]),I(re=>re+1)},oe=re=>{m(!1),y([]),I(he=>he+1),n?.(re)},se=re=>{m(re),re||(y([]),I(he=>he+1))};return o.jsxs(o.Fragment,{children:[o.jsxs(cu,{defaultTab:"items",value:i,onValueChange:c,className:"grid grid-rows-[auto_1fr] h-full",children:[o.jsxs(uu,{children:[o.jsxs(qr,{value:"items",children:["Items ",o.jsx(Xs,{color:"gray",children:Y})]}),o.jsxs(qr,{value:"experiments",children:["Experiments",o.jsx(Xs,{color:"gray",children:ae.length})]}),o.jsxs(qr,{value:"review",children:["Review",ue>0&&o.jsx(Xs,{color:"orange",children:ue})]})]}),o.jsx(fs,{value:"items",className:"grid overflow-auto mt-5 pb-0",children:o.jsx(bes,{datasetId:e,items:F,isLoading:B,featuredItemId:R,onItemSelect:pe,onItemClose:le,onAddClick:t??(()=>{}),onImportClick:()=>d(!0),onImportJsonClick:()=>p(!0),onBulkDeleteClick:Ie,onCreateDatasetClick:ve,onAddToDatasetClick:ye,onCompareItemsClick:Ne,datasetName:H?.name,clearSelectionTrigger:N,setEndOfListElement:D,isFetchingNextPage:Q,hasNextPage:V,searchQuery:L,activeSearchQuery:q,onSearchChange:M,currentDatasetVersion:H?.version,onCompareVersionsClick:ke})}),o.jsx(fs,{value:"experiments",className:"grid overflow-auto mt-5 pb-0",children:o.jsx(VJr,{experiments:ae,allExperiments:ce,isLoading:te,datasetId:e,filters:U,onFiltersChange:Z})}),o.jsx(fs,{value:"review",className:"overflow-auto mt-2 pb-0",children:o.jsx(A9t,{datasetId:e})})]}),o.jsx(MJr,{datasetId:e,open:u,onOpenChange:d}),o.jsx(kes,{datasetId:e,open:f,onOpenChange:p}),o.jsx(fJr,{open:h,onOpenChange:se,items:v,onSuccess:oe}),o.jsx(pJr,{open:b,onOpenChange:Se,items:w,currentDatasetId:e}),o.jsx(Tt,{open:_,onOpenChange:C,children:o.jsxs(Tt.Content,{children:[o.jsxs(Tt.Header,{children:[o.jsx(Tt.Title,{children:"Delete Items"}),o.jsxs(Tt.Description,{children:["Are you sure you want to delete ",E.length," item",E.length!==1?"s":"","? This action cannot be undone."]})]}),o.jsxs(Tt.Footer,{children:[o.jsx(Tt.Cancel,{children:"Cancel"}),o.jsx(Tt.Action,{onClick:ze,children:ee.isPending?"Deleting...":"Delete"})]})]})})]})}function Ees(e){if(!(e instanceof Error))return null;const t=e.message.match(/- ({.*})$/);if(!t)return null;try{const n=JSON.parse(t[1]);if(n.field&&Array.isArray(n.errors))return{field:n.field,errors:n.errors}}catch{}return null}function Kre({field:e,errors:t}){return t.length?o.jsx("div",{className:"mt-2 space-y-1",children:t.map((n,r)=>o.jsxs("p",{className:"text-xs text-destructive",children:[o.jsxs("code",{className:"bg-destructive/10 px-1 rounded",children:[e,n.path!=="/"?n.path:""]}),": ",n.message]},r))}):null}function jes({datasetId:e,open:t,onOpenChange:n,onSuccess:r}){const[s,a]=g.useState("{}"),[i,l]=g.useState(""),[c,u]=g.useState(""),[d,f]=g.useState(""),[p,h]=g.useState(""),[m,v]=g.useState(null),{addItem:y}=Ei(),b=async C=>{C.preventDefault();let E;try{E=JSON.parse(s)}catch{De.error("Input must be valid JSON");return}let j;if(i.trim())try{j=JSON.parse(i)}catch{De.error("Ground Truth must be valid JSON");return}let N;if(c.trim())try{N=JSON.parse(c)}catch{De.error("Expected Trajectory must be valid JSON");return}let I;if(d.trim())try{const P=JSON.parse(d);if(!Array.isArray(P)){De.error("Tool Mocks must be a JSON array");return}I=P}catch{De.error("Tool Mocks must be valid JSON");return}let R;if(p.trim())try{R=JSON.parse(p)}catch{De.error("Request Context must be valid JSON");return}try{await y.mutateAsync({datasetId:e,input:E,groundTruth:j,expectedTrajectory:N,toolMocks:I,requestContext:R}),De.success("Item added successfully"),v(null),a("{}"),l(""),u(""),f(""),h(""),n(!1),r?.()}catch(P){const L=Ees(P);L?v(L):De.error(`Failed to add item: ${P instanceof Error?P.message:"Unknown error"}`)}},S=C=>{a(C),m?.field==="input"&&v(null)},w=C=>{l(C),m?.field==="groundTruth"&&v(null)},k=C=>{f(C),m?.field==="toolMocks"&&v(null)},_=()=>{a("{}"),l(""),u(""),f(""),h(""),v(null),n(!1)};return o.jsx(br,{open:t,onOpenChange:n,children:o.jsxs(xr,{className:"max-w-lg",children:[o.jsx(wr,{children:o.jsx(gr,{children:"Add Item"})}),o.jsx(Rr,{children:o.jsxs("form",{onSubmit:b,className:"space-y-4",children:[o.jsxs("div",{className:"space-y-2",children:[o.jsx(Rt,{htmlFor:"item-input",children:"Input (JSON) *"}),o.jsx(Qr,{value:s,onChange:S,showCopyButton:!1,className:"min-h-[120px]"}),m?.field==="input"&&o.jsx(Kre,{field:"input",errors:m.errors})]}),o.jsxs("div",{className:"space-y-2",children:[o.jsx(Rt,{htmlFor:"item-ground-truth",children:"Ground Truth (JSON, optional)"}),o.jsx(Qr,{value:i,onChange:w,showCopyButton:!1,className:"min-h-[80px]"}),m?.field==="groundTruth"&&o.jsx(Kre,{field:"groundTruth",errors:m.errors})]}),o.jsxs("div",{className:"space-y-2",children:[o.jsx(Rt,{htmlFor:"item-trajectory",children:"Expected Trajectory (JSON, optional)"}),o.jsx(Qr,{value:c,onChange:u,showCopyButton:!1,className:"min-h-[80px]"})]}),o.jsxs("div",{className:"space-y-2",children:[o.jsx(Rt,{htmlFor:"item-tool-mocks",children:"Tool Mocks (JSON array, optional)"}),o.jsx(Qr,{value:d,onChange:k,showCopyButton:!1,className:"min-h-[80px]"}),m?.field==="toolMocks"&&o.jsx(Kre,{field:"toolMocks",errors:m.errors})]}),o.jsxs("div",{className:"space-y-2",children:[o.jsx(Rt,{htmlFor:"item-request-context",children:"Request Context (JSON, optional)"}),o.jsx(Qr,{value:p,onChange:h,showCopyButton:!1,className:"min-h-[80px]"})]}),o.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[o.jsx(de,{type:"button",onClick:_,children:"Cancel"}),o.jsx(de,{type:"submit",variant:"primary",disabled:y.isPending,children:y.isPending?"Adding...":"Add Item"})]})]})})]})})}function Tes({item:e}){return o.jsx(ua,{withMargins:!1,children:o.jsxs(ua.Column,{children:[o.jsxs(ua.Title,{size:"smaller",children:[o.jsx(yN,{}),o.jsx("span",{className:"truncate",children:e.id}),o.jsx(Oa,{content:e.id,tooltip:`Copy item ID: ${e.id}`})]}),o.jsxs(ua.Description,{children:[o.jsxs(Al,{children:[o.jsx(Nlt,{})," Created ",er(new Date(e.createdAt),"MMM d, yyyy h:mm aaa")]}),e.datasetVersion!=null&&o.jsxs(Al,{children:[o.jsx(p_,{})," Version v",e.datasetVersion]})]})]})})}function wTe({item:e}){const t=e?.input?JSON.stringify(e.input,null,2):"null",n=e?.groundTruth?JSON.stringify(e.groundTruth,null,2):"null",r=e?.metadata?JSON.stringify(e.metadata,null,2):"null",s=e?.expectedTrajectory?JSON.stringify(e.expectedTrajectory,null,2):null;return o.jsxs(Uje,{children:[o.jsx(Ps.CodeSection,{title:"Input",icon:o.jsx(fO,{}),codeStr:t}),o.jsx(Ps.CodeSection,{title:"Ground Truth",icon:o.jsx(gg,{}),codeStr:n}),s&&o.jsx(Ps.CodeSection,{title:"Expected Trajectory",icon:o.jsx(lbe,{}),codeStr:s}),o.jsx(Ps.CodeSection,{title:"Metadata",icon:o.jsx(wN,{}),codeStr:r})]})}function Nes({selectedScorers:e,setSelectedScorers:t,disabled:n=!1,container:r}){const{data:s,isLoading:a}=ih(),i=g.useMemo(()=>s?Object.entries(s).map(([l,c])=>({value:l,label:c.scorer?.config?.name||l,description:c.scorer?.config?.description||""})):[],[s]);return o.jsxs("div",{className:"grid gap-2",children:[o.jsx(Rt,{children:"Scorers (Optional)"}),o.jsx(Jl,{multiple:!0,options:i,value:e,onValueChange:t,placeholder:"Select scorers...",searchPlaceholder:"Search scorers...",emptyText:"No scorers available",disabled:n||a,container:r})]})}const Ies=[{value:"agent",label:"Agent"},{value:"workflow",label:"Workflow"},{value:"scorer",label:"Scorer"}];function Aes({targetType:e,setTargetType:t,targetId:n,setTargetId:r,container:s}){const{data:a,isLoading:i}=km(),{data:l,isLoading:c}=Uy(),{data:u,isLoading:d}=ih(),f=e==="agent"?Object.entries(a??{}).map(([v,y])=>({value:v,label:y.name??v})):e==="workflow"?Object.entries(l??{}).map(([v,y])=>({value:v,label:y.name??v})):e==="scorer"?Object.entries(u??{}).map(([v,y])=>({value:v,label:y.scorer?.config?.name??v})):[],p=e==="agent"&&i||e==="workflow"&&c||e==="scorer"&&d,h=v=>{t(v),r("")},m=e==="agent"?"Agent":e==="workflow"?"Workflow":"Scorer";return o.jsxs("div",{className:"grid gap-6",children:[o.jsxs("div",{className:"grid gap-2",children:[o.jsx(Rt,{children:"Target Type"}),o.jsx(Jl,{options:Ies,value:e,onValueChange:h,placeholder:"Select target type",searchPlaceholder:"Search types...",emptyText:"No types available",container:s})]}),e&&o.jsxs("div",{className:"grid gap-2",children:[o.jsx(Rt,{children:m}),o.jsx(Jl,{options:f,value:n,onValueChange:r,placeholder:`Select ${e}`,searchPlaceholder:"Search...",emptyText:"No targets available",disabled:p,container:s})]})]})}function Res({requestContextSchema:e,onChange:t}){const n=g.useMemo(()=>{try{return lm(im(e))}catch(r){return console.error("Failed to parse requestContextSchema:",r),null}},[e]);return n?o.jsxs("div",{className:"space-y-2",children:[o.jsx(Rt,{children:"Request Context"}),o.jsx(a3,{schema:n,onValuesChange:t,className:"[&_button[type=submit]]:hidden"})]}):o.jsx("p",{className:"text-sm text-destructive",children:"Failed to parse request context schema"})}function Pes({datasetId:e,version:t,requestContextSchema:n,open:r,onOpenChange:s,onSuccess:a}){const i=g.useRef(null),[l,c]=g.useState(""),[u,d]=g.useState(""),[f,p]=g.useState([]),[h,m]=g.useState({}),[v,y]=g.useState(""),{triggerExperiment:b}=Ei(),S=!!(n&&Object.keys(n).length>0),w=l&&u,k=b.isPending,_=()=>{c(""),d(""),p([]),m({}),y("")},C=()=>{if(S){const N=Object.entries(h).filter(([,I])=>I!==void 0&&I!=="");return N.length>0?Object.fromEntries(N):void 0}if(v.trim()){let N;try{N=JSON.parse(v)}catch{throw new Error("Request Context must be valid JSON")}if(!N||typeof N!="object"||Array.isArray(N))throw new Error("Request Context must be a JSON object");return N}},E=async()=>{if(!w)return;let N;try{N=C()}catch(I){const R=I instanceof Error?I.message:"Request Context must be valid JSON";Ru.error(R);return}try{const I=await b.mutateAsync({datasetId:e,targetType:l,targetId:u,scorerIds:f.length>0?f:void 0,version:t,requestContext:N});Ru.success("Experiment triggered successfully"),s(!1),a?.(I.experimentId),_()}catch(I){const R=I instanceof Error?I.message:"Failed to trigger experiment";Ru.error(R)}},j=()=>{k||(s(!1),_())};return o.jsx(br,{open:r,onOpenChange:j,children:o.jsxs(xr,{ref:i,children:[o.jsxs(wr,{children:[o.jsx(gr,{children:"Run Experiment"}),o.jsx(Qs,{children:t?`Execute items from ${er(new Date(t),"MMM d, yyyy")} version against a target.`:"Execute all items in this dataset against a target."})]}),o.jsxs(Rr,{className:"grid gap-6",children:[o.jsx(Aes,{targetType:l,setTargetType:c,targetId:u,setTargetId:d,container:i}),l&&l!=="scorer"&&o.jsx(Nes,{selectedScorers:f,setSelectedScorers:p,disabled:k,container:i}),S?o.jsx(Res,{requestContextSchema:n,onChange:m}):o.jsxs("div",{className:"space-y-2",children:[o.jsx(Rt,{children:"Request Context (JSON, optional)"}),o.jsx(Qr,{value:v,onChange:y,showCopyButton:!1,className:"min-h-[80px]"})]})]}),o.jsxs(Cc,{className:"px-6 pt-4",children:[o.jsx(de,{onClick:j,disabled:k,children:"Cancel"}),o.jsx(de,{variant:"primary",onClick:E,disabled:!w||k,children:k?o.jsxs(o.Fragment,{children:[o.jsx(Gt,{className:"w-4 h-4"}),"Running..."]}):"Run"})]})]})})}const $es=e=>{const t=We();return wt({queryKey:["experiment-trace-light",e],queryFn:async()=>{if(!e)throw new Error("Trace ID is required");return t.getTraceLight(e)},enabled:!!e})},STe=e=>o.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 9.45892 8.88606",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:[o.jsx("path",{d:"M8.53702 7.36403C8.98547 7.36403 9.34918 7.70502 9.34918 8.12535C9.34906 8.54559 8.9854 8.88606 8.53702 8.88606H5.6839C5.23552 8.88606 4.87186 8.54559 4.87174 8.12535C4.87174 7.70502 5.23545 7.36403 5.6839 7.36403H8.53702Z",fill:"currentColor"}),o.jsx("path",{d:"M8.53702 3.67209C8.98547 3.67209 9.34918 4.01309 9.34918 4.43342C9.34911 4.8537 8.98543 5.19413 8.53702 5.19413H5.6839C5.23549 5.19413 4.87181 4.8537 4.87174 4.43342C4.87174 4.01309 5.23545 3.67209 5.6839 3.67209H8.53702Z",fill:"currentColor"}),o.jsx("path",{d:"M8.67155 0C9.10635 2.06584e-05 9.45892 0.341006 9.45892 0.761326C9.45878 1.18153 9.10627 1.52201 8.67155 1.52203H2.88163C2.4469 1.52203 2.0944 1.18154 2.09427 0.761326C2.09427 0.340993 2.44681 3.80132e-08 2.88163 0H8.67155Z",fill:"currentColor"}),o.jsx("path",{d:"M0.757606 0.760086V4.01122H3.50594V4.76883H0.759466L0.762566 5.4291C0.76837 6.70703 1.8058 7.73972 3.08374 7.73973H3.67953V8.49796H3.08374C1.38863 8.49795 0.0120204 7.1273 0.00433981 5.4322L0 4.39188V0.760086H0.757606Z",fill:"currentColor"})]});function Jre(e){try{return JSON.stringify(e??{})}catch{return String(e)}}function Mes({report:e}){const{served:t,unconsumed:n,liveCalls:r,failure:s}=e,a=[...t.map(i=>({outcome:"served",toolName:i.toolName,args:i.args})),...r.map(i=>({outcome:"live",toolName:i.toolName,args:i.args})),...n.map(i=>({outcome:"unconsumed",toolName:i.toolName,args:i.args}))];return o.jsxs("div",{className:"grid gap-2","data-testid":"tool-mock-report",children:[o.jsx(bn.SectionHeading,{icon:o.jsx(zp,{}),className:"mb-2",children:"Tool Mocks"}),s&&o.jsx(In,{variant:"destructive",title:"Mock mismatch",children:o.jsxs(In.Message,{children:[o.jsx("span",{className:"block",children:`Tool "${s.toolName}" was called with arguments that did not match an available mock (${s.code}).`}),o.jsxs("span",{className:"mt-1 block font-mono text-xs",children:["Called with: ",Jre(s.args)]}),n.length>0&&o.jsxs("span",{className:"mt-1 block font-mono text-xs",children:["Unconsumed mocks: ",n.map(i=>Jre(i.args)).join(", ")]})]})}),o.jsx("div",{className:"rounded border border-border1 divide-y divide-border1 text-sm",children:a.map((i,l)=>o.jsxs("div",{className:"flex items-center justify-between gap-2 px-3 py-1.5",children:[o.jsxs("span",{className:"min-w-0 truncate",children:[o.jsx("span",{className:"font-mono text-neutral4",children:i.toolName}),o.jsx("span",{className:"ml-2 font-mono text-xs text-neutral3",children:Jre(i.args)})]}),o.jsx("span",{className:`shrink-0 text-xs px-2 py-0.5 rounded ${Des(i.outcome)}`,children:i.outcome})]},`${i.outcome}-${i.toolName}-${l}`))})]})}function Des(e){switch(e){case"served":return"bg-accent1/10 text-accent1";case"live":return"bg-orange-500/10 text-orange-400";case"unconsumed":return"bg-neutral3/10 text-neutral4"}}function Les({result:e,scores:t,onPrevious:n,onNext:r,onClose:s,onShowTrace:a,onOpenInReview:i,onScoreClick:l,featuredScoreId:c,onFlagForReview:u,collapsed:d,onCollapsedChange:f}){const[p,h]=g.useState(!1),m=d??p,v=f??h,y=!!e?.error,b=tF(e?.input),S=tF(e?.output),w=tF(e?.groundTruth),k=u&&e.status!=="needs-review"&&e.status!=="complete",_=Array.isArray(e.tags)?e.tags:[];return o.jsxs(bn,{collapsed:m,children:[o.jsxs(bn.Header,{children:[o.jsxs(bn.Heading,{children:["Result ",o.jsxs("b",{children:["# ",e.id.length>12?`${e.id.slice(0,12)}…`:e.id]})]}),o.jsxs(Mr,{className:"ml-auto shrink-0",children:[f&&o.jsx(de,{size:"md",tooltip:m?"Expand panel":"Collapse panel",onClick:()=>v(!m),children:m?o.jsx(Plt,{}):o.jsx(Rlt,{})}),o.jsx(bn.NextPrevNav,{onPrevious:n,onNext:r,previousLabel:"Previous result",nextLabel:"Next result"}),o.jsxs(de,{size:"md",onClick:a,disabled:!e.traceId,children:[o.jsx(STe,{}),"Trace"]}),o.jsx(bn.CloseButton,{onClick:s,tooltip:"Close result panel"})]})]}),!m&&o.jsxs(bn.Content,{children:[o.jsxs("div",{className:"grid gap-4 mb-6",children:[o.jsxs(Bt,{children:[o.jsx(Bt.Key,{children:"Item Id"}),o.jsx(Bt.ValueWithCopyBtn,{copyTooltip:"Copy Item Id to clipboard",copyValue:e.itemId,children:e.itemId}),o.jsx(Bt.Key,{children:"Created"}),o.jsx(Bt.Value,{children:er(new Date(e.createdAt),"MMM d, yyyy 'at' h:mm a")})]}),y&&o.jsx(In,{variant:"destructive",title:"Error",children:o.jsx(In.Message,{children:tF(e?.error&&typeof e.error=="object"?e.error.message:e?.error)})}),t&&t.length>0&&o.jsxs(me,{columns:"1fr 1fr",children:[o.jsxs(me.Top,{children:[o.jsx(me.TopCell,{children:"Scorer"}),o.jsx(me.TopCell,{children:"Score"})]}),t.map(C=>o.jsxs(me.RowButton,{featured:c===C.id,onClick:()=>l?.(C.id),children:[o.jsx(me.Cell,{height:"compact",children:C.scorerId}),o.jsx(me.MonoCell,{children:C.score.toFixed(3)})]},C.id))]}),e.toolMockReport&&o.jsx(Mes,{report:e.toolMockReport}),(e.status||_.length>0||k)&&o.jsxs("div",{className:"grid gap-2",children:[o.jsx(bn.SectionHeading,{icon:o.jsx(wN,{}),className:"mb-2",children:"Review"}),(e.status||_.length>0)&&o.jsxs("div",{className:"flex flex-wrap gap-2 items-center",children:[e.status&&o.jsx("span",{className:`text-xs px-2 py-0.5 rounded-full font-medium ${e.status==="needs-review"?"bg-orange-500/10 text-orange-400":e.status==="complete"?"bg-accent1/10 text-accent1":"bg-neutral3/10 text-neutral4"}`,children:e.status}),_.map(C=>o.jsx("span",{className:"text-xs px-2 py-0.5 rounded bg-surface4 text-neutral4",children:C},C))]}),k&&o.jsx("div",{children:o.jsxs(de,{size:"sm",onClick:()=>u(e.id),children:[o.jsx(cq,{}),"Flag for Review"]})}),e.status==="needs-review"&&i&&o.jsx("div",{children:o.jsxs(de,{size:"sm",onClick:i,children:[o.jsx(_a,{}),"Review"]})})]})]}),o.jsxs("div",{className:"grid gap-3",children:[o.jsx(bn.CodeSection,{title:"Input",icon:o.jsx(yN,{}),codeStr:b}),o.jsx(bn.CodeSection,{title:"Output",icon:o.jsx(gg,{}),codeStr:S}),o.jsx(bn.CodeSection,{title:"Ground Truth",icon:o.jsx(ube,{}),codeStr:w})]})]})]})}function tF(e){return e==null?"-":typeof e=="string"?e:JSON.stringify(e,null,2)}function Fes({results:e,isLoading:t,featuredResultId:n,onResultClick:r,columns:s,scoresByItemId:a,scorerIds:i,setEndOfListElement:l,isFetchingNextPage:c,hasNextPage:u,selectedIds:d,onToggleSelect:f}){const p=!!(d&&f),h=[p?"auto":"",...s.map(v=>v.size)].filter(Boolean).join(" "),m=s.some(v=>v.name==="input");return t?o.jsx(tl,{columns:h}):o.jsxs(me,{columns:h,className:"min-w-0",children:[o.jsxs(me.Top,{hasLeadingCell:p,children:[p&&o.jsx(me.TopCell,{children:" "}),p?o.jsx(me.TopCells,{colStart:2,children:s.map(v=>o.jsx(me.TopCell,{children:v.label},v.name))}):s.map(v=>o.jsx(me.TopCell,{children:v.label},v.name))]}),e.length===0?o.jsx(me.NoMatch,{message:"No results yet"}):o.jsxs(o.Fragment,{children:[e.map(v=>{const y=!!v.error,b=v.id===n,S=o.jsxs(o.Fragment,{children:[o.jsx(me.IdCell,{id:v.itemId}),o.jsx(me.Cell,{height:"compact",children:o.jsxs(Wn,{children:[o.jsx(zn,{asChild:!0,children:o.jsx("div",{className:"flex items-center justify-center w-10 relative bg-transparent h-full",children:o.jsx("div",{role:"img","aria-label":y?"Error":"Success",className:K("w-2 h-2 rounded-full",y?"bg-red-700":"bg-green-600")})})}),o.jsx(Bn,{children:y?"Error":"Success"})]})}),m&&o.jsx(me.MonoCell,{children:Bes(zes(v.input),200)}),i?.map(w=>{const _=a?.[v.itemId]?.find(C=>C.scorerId===w);return o.jsx(me.Cell,{height:"compact",className:"font-mono text-neutral3 text-ui-smd",children:_!=null?_.score.toFixed(3):"-"},w)})]});return p?o.jsxs(me.RowWrapper,{children:[o.jsx(me.SelectCell,{checked:d.has(v.id),onToggle:()=>f(v.id),"aria-label":`Select result ${v.itemId}`}),o.jsx(me.RowButton,{flushLeft:!0,colStart:2,featured:b,onClick:()=>r(v.id),children:S})]},v.id):o.jsx(me.RowButton,{featured:b,onClick:()=>r(v.id),children:S},v.id)}),o.jsx(me.NextPageLoading,{isLoading:c,hasMore:u,setEndOfListElement:l})]})]})}function zes(e){return e==null?"-":typeof e=="string"?e:JSON.stringify(e,null,2)}function Bes(e,t){return e.length<=t?e:e.slice(0,t-1)+"..."}function Ues(e){const t=e.scorer;return t?.hasJudge===!1?!0:t?.hasJudge===!0?!1:!e.preprocessPrompt&&!e.analyzePrompt&&!e.generateScorePrompt&&!e.generateReasonPrompt}function qes({score:e,onNext:t,onPrevious:n,onClose:r,onShowTrace:s,collapsed:a,onCollapsedChange:i}){const[l,c]=g.useState(!1),u=a??l,d=i??c,f=Ues(e),p=f?"N/A — code-based scorer":"N/A — step not configured";return o.jsxs(bn,{collapsed:u,children:[o.jsxs(bn.Header,{children:[o.jsxs(bn.Heading,{children:["Score ",o.jsx("b",{children:e.scorerId})]}),o.jsxs(Mr,{className:"ml-auto shrink-0",children:[i&&o.jsx(de,{size:"md",tooltip:u?"Expand panel":"Collapse panel",onClick:()=>d(!u),children:u?o.jsx(Plt,{}):o.jsx(Rlt,{})}),(n||t)&&o.jsx(bn.NextPrevNav,{onPrevious:n,onNext:t,previousLabel:"Previous score",nextLabel:"Next score"}),s&&o.jsxs(de,{size:"md",onClick:s,disabled:!e.traceId,children:[o.jsx(STe,{}),"Trace"]}),o.jsx(bn.CloseButton,{onClick:r,tooltip:"Close score panel"})]})]}),!u&&o.jsx(bn.Content,{children:o.jsxs("div",{className:"grid gap-3",children:[o.jsx(bn.CodeSection,{title:`Score: ${e.score}`,icon:o.jsx(rm,{}),codeStr:e.reason||p,simplified:!0}),!f&&o.jsxs(o.Fragment,{children:[o.jsx(bn.CodeSection,{title:"Preprocess Prompt",icon:o.jsx(Oh,{}),codeStr:e.preprocessPrompt||p,simplified:!0}),o.jsx(bn.CodeSection,{title:"Analyze Prompt",icon:o.jsx(Oh,{}),codeStr:e.analyzePrompt||p,simplified:!0}),o.jsx(bn.CodeSection,{title:"Generate Score Prompt",icon:o.jsx(Oh,{}),codeStr:e.generateScorePrompt||p,simplified:!0}),o.jsx(bn.CodeSection,{title:"Generate Reason Prompt",icon:o.jsx(Oh,{}),codeStr:e.generateReasonPrompt||p,simplified:!0})]})]})})]})}const RQe=[{name:"scorer",label:"Scorer",size:"1fr"},{name:"avg",label:"Avg Score",size:"1fr"},{name:"count",label:"Items Scored",size:"1fr"}];function Ves({scoresByItemId:e,experimentStatus:t}){const n=g.useMemo(()=>{if(!e)return[];const r={};for(const s of Object.values(e))for(const a of s)r[a.scorerId]||(r[a.scorerId]={sum:0,count:0}),r[a.scorerId].sum+=a.score,r[a.scorerId].count++;return Object.entries(r).map(([s,{sum:a,count:i}])=>({scorerId:s,avg:a/i,count:i})).sort((s,a)=>s.scorerId.localeCompare(a.scorerId))},[e]);if(n.length===0){const r=t==="running"||t==="pending",s=e!==void 0;let a,i;return r?(a="Experiment in progress",i="Summary metrics will appear here once the experiment completes."):s?(a="No scorers configured",i="Add scorers when triggering an experiment to evaluate results and see summary metrics here."):(a="Loading scores",i="Fetching scorer results…"),o.jsx("div",{className:"flex h-full items-center justify-center py-12",children:o.jsx(Cr,{iconSlot:o.jsx(rm,{className:"w-8 h-8 text-neutral3"}),titleSlot:a,descriptionSlot:i})})}return o.jsxs(gn,{children:[o.jsxs(gn.Header,{columns:RQe,children:[o.jsx(gn.HeaderCol,{children:"Scorer"}),o.jsx(gn.HeaderCol,{children:"Avg Score"}),o.jsx(gn.HeaderCol,{children:"Items Scored"})]}),o.jsx(gn.Scroller,{children:o.jsx(gn.Items,{children:n.map(({scorerId:r,avg:s,count:a})=>o.jsxs(gn.Row,{columns:RQe,children:[o.jsx(gn.TextCell,{children:r}),o.jsx(gn.TextCell,{className:"font-mono",children:s.toFixed(3)}),o.jsx(gn.TextCell,{className:"font-mono",children:a})]},r))})})]})}function R9t({experimentId:e,datasetId:t,experimentStatus:n,results:r,isLoading:s,setEndOfListElement:a,isFetchingNextPage:i,hasNextPage:l}){const[c,u]=g.useState(null),[d,f]=g.useState(null),[p,h]=g.useState(void 0),[m,v]=g.useState(null),[y,b]=g.useState(new Set),[S,w]=g.useState(!1),[k,_]=g.useState(!1),[C,E]=g.useState(!1),[j,N]=g.useState(!1),{updateExperimentResult:I}=Ei(),R=g.useCallback(se=>{b(re=>{const he=new Set(re);return he.has(se)?he.delete(se):he.add(se),he})},[]),P=g.useCallback(()=>b(new Set),[]),L=g.useCallback(()=>{const se=r.filter(re=>!!re.error).map(re=>re.id);b(new Set(se))},[r]),M=g.useCallback(async se=>{if(S||se.length===0)return;w(!0);let re=0;const he=new Set;try{for(const xe of se)try{await I.mutateAsync({datasetId:t,experimentId:e,resultId:xe,status:"needs-review"}),re++,he.add(xe)}catch{}}finally{w(!1)}he.size>0&&b(xe=>{const je=new Set(xe);for(const Pe of he)je.delete(Pe);return je}),re>0&&De(`${re} result${re>1?"s":""} flagged for review`)},[t,e,S,I]),q=r.find(se=>se.id===c)??null,[H,F]=g.useState("summary"),[z,B]=g.useState(null),D=se=>{F(se),se!=="reviews"&&B(null)},{data:Q}=xTe(t),V=(Q??[]).filter(se=>se.experimentId===e).length,{data:$}=r9t(e,n),U=g.useMemo(()=>{if(!$)return[];const se=new Set;for(const re of Object.values($))for(const he of re)se.add(he.scorerId);return[...se].sort()},[$]),Z=se=>{u(se),f(null),h(void 0),v(null)},X=se=>{Z(se===c?null:se)},te=()=>{Z(null)},J=()=>{if(!q)return;const se=r.findIndex(re=>re.id===q.id);if(se>=0&&se<r.length-1)return()=>Z(r[se+1].id)},ee=()=>{if(!q)return;const se=r.findIndex(re=>re.id===q.id);if(se>0)return()=>Z(r[se-1].id)},ae=q?$?.[q.itemId]:void 0,ce=ae?.find(se=>se.id===m)??null,Y=se=>{v(se===m?null:se),f(null),h(void 0)},ne=()=>{if(!m||!ae)return;const se=ae.findIndex(re=>re.id===m);if(se>=0&&se<ae.length-1)return()=>v(ae[se+1].id)},ue=()=>{if(!m||!ae)return;const se=ae.findIndex(re=>re.id===m);if(se>0)return()=>v(ae[se-1].id)},{data:pe,isLoading:le}=$es(d),ve=pe?.spans,{data:ye,isLoading:Se}=oI(d,p),Ne=ye?.span,{handlePreviousSpan:ke,handleNextSpan:Ie}=GH(ve,p??null,h),ze=(()=>{const se=[],re=!!ce,he=!!d;return se.push(k?"auto":re||he?"2fr":"1fr"),re&&se.push(j?"auto":"3fr"),he&&se.push(C?"auto":"3fr"),he&&p&&se.push("3fr"),se.join(" ")})(),oe=g.useMemo(()=>[{name:"itemId",label:"Item ID",size:"7rem"},{name:"status",label:"Status",size:"5rem"},{name:"input",label:"Input",size:"minmax(15rem,1fr)"},...U.map(se=>({name:se,label:se,size:"12rem"}))],[U]);return o.jsxs(cu,{defaultTab:"summary",value:H,onValueChange:D,className:"grid grid-rows-[auto_1fr] h-full overflow-hidden",children:[o.jsxs(uu,{children:[o.jsx(qr,{value:"summary",children:"Summary"}),o.jsx(qr,{value:"results",children:"Results"}),o.jsxs(qr,{value:"reviews",children:["Reviews",V>0&&o.jsx(Xs,{color:"orange",children:V})]})]}),o.jsx(fs,{value:"summary",className:"overflow-y-auto mt-5",children:o.jsx(Ves,{scoresByItemId:$,experimentStatus:n})}),o.jsx(fs,{value:"reviews",className:"overflow-auto mt-2 pb-0",children:o.jsx(A9t,{datasetId:t,experimentId:e,featuredItemId:z})}),o.jsxs(fs,{value:"results",className:"grid grid-rows-[auto_1fr] overflow-hidden mt-2",children:[o.jsxs("div",{className:"mb-4",children:[y.size>0&&o.jsxs("div",{className:"flex items-center gap-2 px-4 py-2 bg-surface3",children:[o.jsxs(ge,{variant:"ui-xs",className:"text-neutral5 font-medium",children:[y.size," selected"]}),o.jsx("div",{className:"flex-1"}),o.jsxs(de,{variant:"outline",size:"sm",disabled:S,onClick:()=>M([...y]),children:[o.jsx(Ue,{size:"sm",children:o.jsx(cq,{})}),"Flag for Review"]}),o.jsx(de,{variant:"ghost",size:"sm",onClick:P,children:"Clear"})]}),r.length>0&&y.size===0&&!s&&o.jsx("div",{className:"flex items-center gap-2 px-4 py-2",children:o.jsx(de,{variant:"ghost",size:"sm",onClick:L,children:"Select loaded failures"})})]}),o.jsxs("div",{className:K("grid w-full h-full grid-cols-1 gap-4 overflow-y-auto",q&&"grid-cols-[1fr_1fr]"),children:[o.jsx("div",{className:"flex overflow-y-auto w-full",children:o.jsx("div",{className:"grid gap-8 content-start w-full overflow-y-auto",children:o.jsx(Fes,{results:r,isLoading:s,featuredResultId:c,onResultClick:X,columns:oe,scoresByItemId:$,scorerIds:U,setEndOfListElement:a,isFetchingNextPage:i,hasNextPage:l,selectedIds:y,onToggleSelect:R})})}),q&&o.jsxs("div",{className:"grid gap-4 max-h-full min-h-0 overflow-auto content-start",style:{gridTemplateRows:ze},children:[o.jsx(Les,{result:q,scores:ae,onPrevious:ee(),onNext:J(),onClose:te,onScoreClick:Y,featuredScoreId:m,onShowTrace:()=>{q.traceId&&(f(q.traceId),h(void 0),v(null),_(!0),E(!1))},onOpenInReview:()=>{B(q.id),F("reviews")},onFlagForReview:se=>M([se]),collapsed:k,onCollapsedChange:_}),ce&&o.jsx(qes,{score:ce,onNext:ne(),onPrevious:ue(),onClose:()=>v(null),onShowTrace:()=>{ce.traceId&&(f(ce.traceId),h(void 0),_(!0),N(!0),E(!1))},collapsed:j,onCollapsedChange:N}),d&&o.jsxs(o.Fragment,{children:[o.jsx(uTe,{traceId:d,spans:ve,isLoading:le,onClose:()=>{f(null),h(void 0),_(!1),N(!1)},onSpanSelect:h,initialSpanId:p??null,placement:"traces-list",showUnavailableFeaturesMsg:!1,collapsed:C,onCollapsedChange:E,LinkComponent:BD,traceHref:`/traces/${d}`}),p&&o.jsx(WH,{traceId:d,spanId:p,span:Ne,isLoading:Se,onPrevious:ke,onNext:Ie,onClose:()=>h(void 0)})]})]})]})]})]})}const Hes={pending:o.jsx(dO,{}),running:o.jsx(tfe,{}),completed:o.jsx(Js,{}),failed:o.jsx(vs,{})};function Wes({experiment:e,className:t}){const n=e.status,r=e.totalItems-e.succeededCount-e.failedCount;return o.jsxs("div",{className:K("grid justify-items-end gap-3",t),children:[o.jsxs("div",{className:"flex p-1 px-3 text-ui-lg capitalize text-neutral4 gap-2 items-center bg-surface5 rounded-lg ",children:[o.jsx("span",{className:K("w-5 h-5 flex items-center justify-center rounded-full text-black","[&>svg]:w-4 [&>svg]:h-4",{"bg-green-700":n==="completed","bg-red-700":n==="failed","bg-cyan-600":n==="running","bg-yellow-600":n==="pending"}),children:Hes[n]}),e.status]}),o.jsxs("div",{className:K("flex items-center gap-3 text-neutral3 text-ui-md ","[&>span]:flex [&>span]:gap-1 [&>span]:items-center ","[&_b]:text-neutral4 [&_b]:font-semibold"),children:[o.jsxs("span",{children:["Total: ",o.jsx("b",{children:e.totalItems})]}),o.jsxs("span",{children:["Succeeded: ",o.jsx("b",{children:e.succeededCount})]}),o.jsxs("span",{children:["Failed: ",o.jsx("b",{children:e.failedCount})]}),(n==="pending"||n==="running")&&o.jsxs("span",{children:["Pending: ",o.jsx("b",{children:r})]})]})]})}function Zes({onPrevious:e,onNext:t,previousAriaLabel:n="Previous",nextAriaLabel:r="Next"}){return o.jsxs(Mr,{spacing:"close",children:[o.jsxs(de,{onClick:e,disabled:!e,"aria-label":n,children:[o.jsx(Gq,{})," Prev"]}),o.jsxs(de,{onClick:t,disabled:!t,"aria-label":r,children:["Next",o.jsx(Wq,{})]})]})}function kTe({delta:e}){const t=e>0?o.jsx(Xs,{size:"small",color:"green",intensity:"muted",children:o.jsx(pD,{})}):e<0?o.jsx(Xs,{size:"small",color:"red",intensity:"muted",children:o.jsx(Cln,{})}):null;return o.jsxs("span",{className:K("font-mono text-sm text-neutral4 min-w-20"),children:[o.jsx("span",{className:"w-3 inline-block",children:e>0?"+ ":e<0?"- ":""}),Math.abs(e).toFixed(2)," ",t]})}function nF(e){return e==null?"-":typeof e=="string"?e:JSON.stringify(e,null,2)}function Ges({item:e,baselineId:t,contenderId:n,baselineVersion:r,contenderVersion:s,onPrevious:a,onNext:i,onClose:l}){const c=e.results[t],u=e.results[n],d=!!(c&&u),f=new Set;if(c)for(const h of Object.keys(c.scores))f.add(h);if(u)for(const h of Object.keys(u.scores))f.add(h);const p=[...f].sort();return o.jsxs(Gr,{withLeftSeparator:!0,children:[o.jsxs(Gr.Toolbar,{children:[o.jsx(Zes,{onPrevious:a,onNext:i,previousAriaLabel:"Previous comparison item",nextAriaLabel:"Next comparison item"}),o.jsx(Mr,{children:o.jsx(de,{onClick:l,"aria-label":"Close comparison detail panel",children:o.jsx(vs,{})})})]}),o.jsxs(Gr.Content,{className:"pb-6",children:[o.jsx(ua,{withMargins:!1,children:o.jsx(ua.Column,{children:o.jsxs(ua.Title,{size:"smaller",children:[o.jsx(yN,{})," ",e.itemId]})})}),d?o.jsx(o.Fragment,{children:o.jsxs(Uje,{children:[p.length>0&&o.jsxs("div",{className:"grid gap-3",children:[o.jsx("h4",{className:"text-sm font-medium text-neutral5",children:"Scores"}),o.jsx("div",{className:"grid gap-2",children:p.map(h=>{const m=c?.scores[h]??null,v=u?.scores[h]??null,y=m!=null&&v!=null?v-m:null;return o.jsxs("div",{className:"flex items-center justify-between gap-4 px-3 py-2 rounded-lg bg-surface2",children:[o.jsx("span",{className:"text-sm text-neutral5 font-medium",children:h}),o.jsxs("div",{className:"flex items-center gap-4",children:[o.jsxs("span",{className:"text-sm text-neutral3",children:[m!=null?m.toFixed(3):"-"," →"," ",v!=null?v.toFixed(3):"-"]}),y!=null&&o.jsx(kTe,{delta:y})]})]},h)})})]}),o.jsx(Ps.CodeSection,{title:o.jsxs(o.Fragment,{children:[o.jsx(Xs,{color:"purple",children:"Baseline "})," Experiment Output"]}),icon:o.jsx(gg,{}),codeStr:nF(c?.output)}),o.jsx(Ps.CodeSection,{title:o.jsxs(o.Fragment,{children:[o.jsx(Xs,{color:"cyan",children:"Contender "})," Experiment Output"]}),icon:o.jsx(gg,{}),codeStr:nF(u?.output)}),o.jsx(Ps.CodeSection,{title:"Item Input",icon:o.jsx(fO,{}),codeStr:nF(e.input)}),o.jsx(Ps.CodeSection,{title:"Item Ground Truth",icon:o.jsx(ube,{}),codeStr:nF(e.groundTruth)})]})}):o.jsx(In,{variant:"warning",title:"Comparison not available",children:o.jsx(In.Message,{children:(()=>{const h=c?"Contender":"Baseline",m=c?s:r;return o.jsxs(o.Fragment,{children:["The ",h," experiment was run against dataset",m!=null?` v. ${m}`:"",", which does not contain this item."]})})()})})]})]})}function Qes({items:e,baselineId:t,contenderId:n,scorerIds:r,featuredItemId:s,columns:a,onItemClick:i}){return o.jsx(Gr,{children:o.jsxs(gn,{children:[o.jsxs(gn.Header,{columns:a,children:[o.jsx(gn.HeaderCol,{children:"Item ID"}),!s&&r.map(l=>o.jsx(gn.HeaderCol,{className:"flex justify-center",children:l},l))]}),o.jsx(gn.Scroller,{children:o.jsx(gn.Items,{children:e.map(l=>{const c=l.results[t],u=l.results[n],d=!!(c&&u);return o.jsx(gn.Row,{children:o.jsxs(gn.RowButton,{item:{id:l.itemId},columns:a,isFeatured:s===l.itemId,onClick:i,children:[o.jsx(gn.IdCell,{id:l.itemId,className:d?"":"text-neutral1"}),!s&&o.jsx(o.Fragment,{children:r.map(f=>{const p=c?.scores[f]??null,h=u?.scores[f]??null,m=p!=null&&h!=null?h-p:null;return o.jsx(gn.Cell,{className:"flex items-center gap-5 justify-center font-mono",children:m!=null?o.jsxs(o.Fragment,{children:[o.jsxs("span",{className:"flex items-center text-neutral2 min-w-24",children:[p?.toFixed(2)," → ",h?.toFixed(2)]}),o.jsx(kTe,{delta:m})]}):o.jsx("span",{className:"text-neutral1",children:"-"})},f)})})]})},l.itemId)})})})]})})}const Yes={baseline:{label:"Baseline",color:"purple",customStyle:"items-end justify-items-end [&>div]:justify-end border-r-0 rounded-r-none"},contender:{label:"Contender",color:"cyan",customStyle:"items-start justify-items-start [&>div]:justify-start border-l-0 rounded-l-none"}};function PQe({datasetId:e,experiment:t,type:n}){const{Link:r}=yn(),{label:s,color:a,customStyle:i}=Yes[n];if(!t)return null;const l=t.createdAt?new Date(t.createdAt):null;return o.jsxs("div",{className:`grid border-2 border-border1 rounded-lg p-5 gap-3 ${i}`,children:[o.jsxs("div",{className:"flex items-center gap-3 w-full overflow-clip",children:[n==="contender"&&o.jsxs(Xs,{size:"small",color:a,children:[s,o.jsx(mm,{})]}),o.jsx(de,{as:r,href:`/datasets/${e}/experiments/${t.id}`,children:o.jsx("span",{className:"truncate min-w-0",children:t.id})}),n==="baseline"&&o.jsxs(Xs,{size:"small",color:a,children:[o.jsx(Nc,{})," ",s]})]}),o.jsxs("div",{className:"flex flex-wrap gap-x-4 gap-y-1 text-ui-sm text-neutral3",children:[o.jsxs(Al,{children:[o.jsx(ube,{})," ",t.targetType," / ",t.targetId]}),o.jsxs(Al,{children:[o.jsx(fq,{})," v",t.datasetVersion??"—"]}),l&&o.jsxs(Al,{children:[o.jsx(Ilt,{})," ",er(l,"MMM d, yyyy HH:mm")]})]})]})}function Xes({datasetId:e,experimentIdA:t,experimentIdB:n,onSwap:r}){const[s,a]=g.useState(null),{data:i,isLoading:l,error:c}=FKr(e,t,n),{data:u}=zU(e,t),{data:d}=zU(e,n),f=u&&d&&u.datasetVersion!==d.datasetVersion,p=g.useMemo(()=>{if(!i)return[];const E=new Set;for(const j of i.items)for(const N of Object.values(j.results))if(N)for(const I of Object.keys(N.scores))E.add(I);return[...E].sort()},[i]),h=g.useMemo(()=>{if(!i||p.length===0)return[];const E=i.baselineId,j=t===E?n:t;return p.map(N=>{let I=0,R=0,P=0,L=0;for(const F of i.items){const z=F.results[E]?.scores[N],B=F.results[j]?.scores[N];z!=null&&(I+=z,P++),B!=null&&(R+=B,L++)}const M=P>0?I/P:null,q=L>0?R/L:null,H=M!=null&&q!=null?q-M:null;return{scorerId:N,avgA:M,avgB:q,delta:H}})},[i,p,t,n]),m=[{name:"scorer",label:"Scorer",size:"1fr"},{name:"baselineAvg",label:"Baseline Avg",size:"1fr"},{name:"comparisonAvg",label:"Comparison Avg",size:"1fr"},{name:"delta",label:"Delta",size:"1fr"}],v=g.useMemo(()=>[{name:"itemId",label:"Item ID",size:"8rem"},...s?[]:p.map(E=>({name:E,label:E,size:"1fr"}))],[p,s]),y=i?.items.find(E=>E.itemId===s)??null,b=E=>{a(E===s?null:E)},S=()=>{a(null)},w=()=>{if(!i||!s)return;const E=i.items.findIndex(j=>j.itemId===s);if(E>=0&&E<i.items.length-1)return()=>a(i.items[E+1].itemId)},k=()=>{if(!i||!s)return;const E=i.items.findIndex(j=>j.itemId===s);if(E>0)return()=>a(i.items[E-1].itemId)};if(l)return o.jsx("div",{className:"flex items-center justify-center h-64",children:o.jsx(Gt,{})});if(c)return o.jsx(In,{variant:"warning",title:"Error loading comparison",children:o.jsx(In.Message,{children:c instanceof Error?c.message:"Unknown error"})});if(!i||i.items.length===0)return o.jsx("div",{className:"text-neutral4 text-sm text-center py-8",children:"No comparison data"});const _=i.baselineId,C=t===_?n:t;return o.jsxs("div",{className:"grid gap-10",children:[u&&d&&o.jsxs("div",{className:K("relative grid xl:grid-cols-[1fr_auto_1fr] gap-4 xl:gap-0"),children:[o.jsx(PQe,{datasetId:e,experiment:u,type:"baseline"}),o.jsx("div",{className:"relative flex items-center justify-center px-[2vw] before:absolute before:inset-y-0 before:left-1/2 before:-translate-x-1/2 before:w-[2px] before:bg-border1",children:o.jsx("div",{className:"relative z-1 bg-surface2 rounded-lg p-2",children:o.jsxs(Wn,{children:[o.jsx(zn,{asChild:!0,children:o.jsx(de,{onClick:r,children:"VS"})}),o.jsx(Bn,{children:"Switch the order"})]})})}),o.jsx(PQe,{datasetId:e,experiment:d,type:"contender"})]}),f&&o.jsx(In,{variant:"warning",title:"Version mismatch",children:o.jsxs(In.Message,{children:["These experiments used different dataset versions (v",u.datasetVersion," vs v",d.datasetVersion,"). Results may not be directly comparable."]})}),h.length>0&&o.jsxs(gn,{children:[o.jsxs(gn.Header,{columns:m,children:[o.jsx(gn.HeaderCol,{children:"Scorer"}),o.jsx(gn.HeaderCol,{className:"flex justify-center",children:o.jsxs(MGe,{children:[o.jsx(Xs,{color:"purple",size:"small",intensity:"muted",children:"Baseline"}),o.jsx(Xs,{color:"purple",size:"small",children:"Avg"})]})}),o.jsx(gn.HeaderCol,{className:"flex justify-center",children:o.jsxs(MGe,{children:[o.jsx(Xs,{color:"cyan",size:"small",intensity:"muted",children:"Contender"}),o.jsx(Xs,{color:"cyan",size:"small",children:"Avg"})]})}),o.jsx(gn.HeaderCol,{className:"flex justify-center",children:"Delta"})]}),o.jsx(gn.Scroller,{children:o.jsx(gn.Items,{children:h.map(({scorerId:E,avgA:j,avgB:N,delta:I})=>o.jsxs(gn.Row,{columns:m,children:[o.jsx(gn.TextCell,{children:E}),o.jsx(gn.TextCell,{className:"text-center font-mono",children:j!=null?j.toFixed(3):"-"}),o.jsx(gn.TextCell,{className:"text-center font-mono",children:N!=null?N.toFixed(3):"-"}),o.jsx(gn.TextCell,{className:"flex justify-center",children:I!=null?o.jsx(kTe,{delta:I}):"-"})]},E))})})]}),o.jsxs(sy,{className:K({"grid-cols-[1fr_2fr]":!!y}),children:[o.jsx(Qes,{items:i.items,baselineId:_,contenderId:C,scorerIds:p,featuredItemId:s,columns:v,onItemClick:b}),!!y&&o.jsx(Ges,{item:y,baselineId:_,contenderId:C,baselineVersion:u?.datasetVersion,contenderVersion:d?.datasetVersion,onPrevious:k(),onNext:w(),onClose:S})]})]})}function Kes({datasetId:e,itemId:t,onVersionSelect:n,onCompareVersionsClick:r,activeVersion:s}){const{data:a,isLoading:i}=vTe(e,t),[l,c]=g.useState(!1),[u,d]=g.useState(new Set),f=b=>{n?.(b)},p=b=>s==null?b.isLatest:b.datasetVersion===s,h=b=>{d(S=>{const w=new Set(S);if(w.has(b))w.delete(b);else if(w.size>=2){const[k]=Array.from(w);return new Set([k,b])}else w.add(b);return w})},m=()=>{c(!1),d(new Set)},v=()=>{c(!0)},y=()=>{u.size===2&&r?.([...u])};return o.jsxs(Gr,{className:"min-w-56",children:[l?o.jsx(Gr.Toolbar,{className:"grid justify-stretch gap-3 w-full",children:o.jsxs(Mr,{children:[o.jsx(de,{onClick:m,children:"Cancel"}),o.jsx(de,{variant:"primary",disabled:u.size!==2,onClick:y,tooltip:u.size!==2?"Check 2 versions to compare":void 0,className:"grow",children:"Compare"})]})}):o.jsx(o.Fragment,{children:(a||[]).length>1&&o.jsx(Gr.Toolbar,{children:o.jsxs(de,{onClick:v,className:"w-full",children:[o.jsx(Xw,{})," Compare Ver."]})})}),i?o.jsx(Jes,{}):o.jsxs(gn,{children:[o.jsx(gn.Header,{children:o.jsx(gn.HeaderCol,{children:"Item Version History"})}),o.jsx(gn.Scroller,{children:o.jsx(gn.Items,{children:a?.map(b=>{const S=String(b.datasetVersion),w=typeof b.updatedAt=="string"?new Date(b.updatedAt):b.updatedAt;return o.jsxs(gn.Row,{isSelected:l&&u.has(S),children:[l&&o.jsx(gn.LabelCell,{children:o.jsx(Mo,{checked:u.has(S),disabled:b.isDeleted,onCheckedChange:()=>{},onClick:k=>{k.stopPropagation(),b.isDeleted||h(S)},"aria-label":`Select version ${b.datasetVersion}`})}),o.jsx(gn.RowButton,{item:b,columns:[{name:"version",label:"Item Version History",size:"1fr"}],isFeatured:p(b),onClick:()=>f(b),className:"py-2",children:o.jsx(gn.VersionCell,{version:b.datasetVersion,date:w,isLatest:b.isLatest,isDeleted:b.isDeleted})})]},String(b.datasetVersion))})})})]})]})}function Jes(){return o.jsxs(gn,{children:[o.jsx(gn.Header,{columns:[{name:"version",label:"Item Version History",size:"1fr"}],children:o.jsx(gn.HeaderCol,{children:"Item Version History"})}),o.jsx(gn.Items,{children:Array.from({length:3}).map((e,t)=>o.jsx(gn.Row,{children:o.jsx(gn.RowButton,{columns:[{name:"version",label:"Item Version History",size:"1fr"}],children:o.jsx(gn.TextCell,{isLoading:!0,children:"Loading..."})})},t))})]})}function ets(e,t){if(t){const n=typeof t=="string"?new Date(t):t;return`v${e} ${er(n,"MMM dd 'at' H:mm:ss a")}`}return`v${e}`}function tts({datasetId:e,versionA:t,versionB:n,onVersionChange:r}){const{data:s}=nTe(e),a=(s??[]).map(i=>({value:String(i.version),label:`${ets(i.version,i.createdAt)}${i.isCurrent?" (current)":""}`}));return o.jsxs(Gr.Toolbar,{className:"grid grid-cols-[1fr_1fr_1fr_10rem] gap-4 w-full",children:[o.jsx("div",{}),o.jsx(Sc,{label:"Version A",labelIsHidden:!0,name:"version-a",placeholder:"Select version",options:a,value:t??"",onValueChange:i=>r?.(i,n??"")}),o.jsx(Sc,{label:"Version B",labelIsHidden:!0,name:"version-b",options:a,value:n??"",onValueChange:i=>r?.(t??"",i)}),o.jsx("div",{})]})}const nts=[{name:"id",label:"ID",size:"1fr"},{name:"versionA",label:"Version A",size:"1fr"},{name:"versionB",label:"Version B",size:"1fr"},{name:"compare",label:"Compare",size:"10rem"}],rts={added:{color:"blue",borderColor:"border-blue-900",icon:o.jsx(Vr,{}),tooltip:"Added in this version"},changed:{color:"orange",borderColor:"border-yellow-900",icon:o.jsx(Ylt,{}),tooltip:"Changed in this version"},same:{color:"green",borderColor:"border-green-900",icon:o.jsx(Qcn,{}),tooltip:"Same in both versions"}};function ese({red:e=!1,tooltip:t}){return o.jsxs(Wn,{children:[o.jsx(zn,{asChild:!0,children:o.jsx(Mln,{className:K("text-neutral3/40 w-5 h-5 ",{"text-red-900":e})})}),t&&o.jsx(Bn,{children:t})]})}function QS({variant:e,version:t}){if(!e)return o.jsxs("span",{className:"text-ui-md text-neutral4",children:["v. ",t]});const{color:n,icon:r,tooltip:s}=rts[e];return o.jsxs(Wn,{children:[o.jsx(zn,{asChild:!0,children:o.jsxs("div",{className:"grid grid-cols-[1fr_auto]",children:[t!==void 0&&o.jsxs("span",{className:"pr-3 text-ui-md text-neutral4 min-w-16 flex justify-end",children:["v. ",t]}),o.jsx(Xs,{color:n,size:"small",children:r})]})}),o.jsx(Bn,{children:s})]})}function sts(e,t){return e&&t&&e.datasetVersion===t.datasetVersion?"same":e&&t&&e.datasetVersion!==t.datasetVersion?"changed":e?"added":"removed"}function ats({datasetId:e,versionA:t,versionB:n,allItems:r,itemsAMap:s,itemsBMap:a}){const{Link:i}=yn(),l=t>n;return o.jsx(gn,{children:o.jsx(gn.Scroller,{children:o.jsx(gn.Items,{children:r.map(({id:c})=>{const u=s.get(c),d=a.get(c),f=sts(u,d);return o.jsxs(gn.Row,{columns:nts,children:[o.jsx(gn.IdCell,{id:c,isShortened:!1}),f!=="same"?o.jsxs(o.Fragment,{children:[u?.datasetVersion?o.jsx(gn.LinkCell,{LinkComponent:i,href:`/datasets/${e}/items/${c}`,className:"gap-2",children:!d&&l?o.jsx(QS,{variant:"added",version:u.datasetVersion}):f==="changed"&&l?o.jsx(QS,{variant:"changed",version:u.datasetVersion}):o.jsx(QS,{version:u.datasetVersion})}):o.jsx(gn.Cell,{className:"justify-center flex items-center",children:o.jsx(ese,{red:l,tooltip:l?"Deleted in this version":"Not present in this version"})}),d?.datasetVersion?o.jsx(gn.LinkCell,{LinkComponent:i,href:`/datasets/${e}/items/${c}`,className:"gap-2",children:!u&&!l?o.jsx(QS,{variant:"added",version:d.datasetVersion}):f==="changed"&&!l?o.jsx(QS,{variant:"changed",version:d.datasetVersion}):o.jsx(QS,{version:d.datasetVersion})}):o.jsx(gn.Cell,{className:"justify-center flex items-center",children:o.jsx(ese,{red:!l,tooltip:l?"Not present in this version":"Deleted in this version"})})]}):o.jsx(gn.LinkCell,{LinkComponent:i,href:`/datasets/${e}/items/${c}`,className:"col-span-2 gap-2",children:o.jsx(QS,{variant:"same",version:d?.datasetVersion})}),f==="changed"?o.jsx(gn.LinkCell,{LinkComponent:i,href:`/datasets/${e}/items/${c}/versions?ids=${u?.datasetVersion},${d?.datasetVersion}`,children:"Compare"}):o.jsx(gn.Cell,{children:o.jsx(ese,{tooltip:o.jsxs(o.Fragment,{children:["Comparing is available",o.jsx("br",{})," only for changed items"]})})})]},c)})})})})}const $Qe={needsReview:"#facc15",complete:"#22c55e"},its=[{label:"Needs Review",color:$Qe.needsReview},{label:"Reviewed",color:$Qe.complete}];function ots({reviewSummary:e,experiments:t,datasets:n,isLoading:r,isError:s}){const{data:a,maxVal:i,totalInPipeline:l}=g.useMemo(()=>{if(!e?.counts||!t)return{data:[],maxVal:0,totalInPipeline:0};const u=new Map;for(const m of t)u.set(m.id,m);const d=new Map;if(n)for(const m of n)d.set(m.id,m.name);let f=0,p=0;const h=[];for(const m of e.counts){const v=m.needsReview+m.complete;if(v===0)continue;p+=v,v>f&&(f=v);const y=u.get(m.experimentId),b=y?.datasetId?d.get(y.datasetId):void 0,S=b?`${b} · ${m.experimentId.slice(0,8)}`:m.experimentId.slice(0,8);h.push({name:S,values:[m.needsReview,m.complete]})}return{data:h,maxVal:f,totalInPipeline:p}},[e,t,n]),c=a.length>0;return o.jsxs(Ut,{children:[o.jsxs(Ut.TopBar,{children:[o.jsx(Ut.TitleAndDescription,{title:"Review Pipeline",description:"Items in review across experiments."}),c&&o.jsx(Ut.Summary,{value:String(l),label:"Items in pipeline"})]}),r?o.jsx(Ut.Loading,{}):s?o.jsx(Ut.Error,{message:"Failed to load review data"}):o.jsx(Ut.Content,{children:c?o.jsx(uN,{data:a,segments:its,maxVal:i,fmt:u=>String(u)}):o.jsx(Ut.NoData,{message:"No items have been sent to review yet"})})]})}function OTe(){const e=We();return wt({queryKey:["experiment-review-summary"],queryFn:()=>e.getExperimentReviewSummary()})}function P9t(e){const t=new Map;if(!e?.counts)return t;for(const n of e.counts)t.set(n.experimentId,{needsReview:n.needsReview,complete:n.complete,total:n.total});return t}function lts(e,t){const n=new Map,r=P9t(e);if(!r.size||!t)return n;for(const s of t){const a=r.get(s.id);if(!a||!s.datasetId||a.needsReview+a.complete===0)continue;const l=n.get(s.datasetId)??{needsReview:0,complete:0};l.needsReview+=a.needsReview,l.complete+=a.complete,n.set(s.datasetId,l)}return n}function cts(e){return e?.counts?e.counts.reduce((t,n)=>({needsReview:t.needsReview+n.needsReview,complete:t.complete+n.complete,inPipeline:t.inPipeline+n.needsReview+n.complete}),{needsReview:0,complete:0,inPipeline:0}):{needsReview:0,complete:0,inPipeline:0}}const uts=10;function dts(){const[e,t]=g.useState(!1),[n,r]=g.useState(""),[s,a]=g.useState("all"),[i,l]=g.useState("all"),[c,u]=g.useState("all"),[d,f]=g.useState(0),{data:p,isLoading:h,error:m}=$g({page:d,perPage:uts}),{data:v,isLoading:y,error:b}=JZ(),{data:S}=OTe(),w=g.useMemo(()=>p?.datasets??[],[p?.datasets]),k=p?.pagination?.hasMore??!1,_=g.useMemo(()=>v?.experiments??[],[v?.experiments]),C=g.useMemo(()=>rJr(w),[w]),E=g.useMemo(()=>lts(S,_),[S,_]),j=h||y,N=m||b,I=()=>t(!0),R=g.useCallback(()=>f(B=>B+1),[]),P=g.useCallback(()=>f(B=>Math.max(0,B-1)),[]),L=g.useCallback(B=>{r(B),f(0)},[]),M=g.useCallback(B=>{a(B),f(0)},[]),q=g.useCallback(B=>{l(B),f(0)},[]),H=g.useCallback(B=>{u(B),f(0)},[]);if(N&&gs(N))return o.jsx(lr,{children:o.jsx(Vs,{})});if(N&&ys(N))return o.jsx(lr,{children:o.jsx(Ds,{resource:"datasets"})});if(N)return o.jsx(lr,{children:o.jsx(zi,{title:"Failed to load datasets",message:N.message})});if(w.length===0&&!j&&d===0)return o.jsxs(o.Fragment,{children:[o.jsx(lr,{children:o.jsx(lJr,{onCreateClick:I})}),o.jsx(Fve,{open:e,onOpenChange:t})]});const F=s!=="all"||i!=="all"||c!=="all"||n!=="",z=()=>{r(""),a("all"),l("all"),u("all"),f(0)};return o.jsxs(Lt,{children:[o.jsx(Lt.TopArea,{children:o.jsx(dJr,{search:n,onSearchChange:L,targetFilter:s,onTargetFilterChange:M,experimentFilter:i,onExperimentFilterChange:q,tagFilter:c,onTagFilterChange:H,tagOptions:C,onReset:z,hasActiveFilters:F,onCreateClick:I})}),o.jsx(oJr,{datasets:w,experiments:_,reviewByDataset:E,isLoading:j,search:n,targetFilter:s,experimentFilter:i,tagFilter:c,currentPage:d,hasMore:k,onNextPage:R,onPrevPage:P}),o.jsx(Fve,{open:e,onOpenChange:t})]})}function rF({children:e}){return o.jsxs(Lt,{height:"full",children:[o.jsx("div",{}),o.jsx(Lt.MainArea,{isCentered:!0,children:e})]})}function fts(){const{datasetId:e}=ur(),t=bs(),[n,r]=ga(),{activeVersion:s}=yTe(n,r),[a,i]=g.useState(!1),[l,c]=g.useState(!1),[u,d]=g.useState(!1),[f,p]=g.useState(!1),[h,m]=g.useState(!1),{data:v,error:y,isLoading:b}=Hx(e),{data:S=[],isLoading:w}=E1(e,void 0,s),k=!w&&S.length===0;if(b)return null;if(y&&gs(y))return o.jsx(rF,{children:o.jsx(Vs,{})});if(y&&ys(y))return o.jsx(rF,{children:o.jsx(Ds,{resource:"datasets"})});if(y&&vOe(y)||!b&&!y&&!v)return o.jsx(rF,{children:o.jsx(Cr,{iconSlot:o.jsx(iy,{}),titleSlot:"Dataset not found",descriptionSlot:`No dataset with id "${e}".`,actionSlot:o.jsxs(de,{as:Ba,to:"/datasets",children:[o.jsx(Nc,{}),"Back to Datasets"]})})});if(y)return o.jsx(rF,{children:o.jsx(zi,{title:"Failed to load dataset",message:y instanceof Error?y.message:"An unexpected error occurred. Please try again."})});const _=E=>{t(`/datasets/${e}/experiments/${E}`)},C=()=>{t("/datasets")};return o.jsxs(o.Fragment,{children:[o.jsxs(Lt,{height:"full",children:[o.jsx(Lt.TopArea,{children:o.jsxs(Lt.Row,{children:[o.jsxs(Lt.Column,{children:[v?.description&&o.jsx("p",{className:"text-ui-smd text-neutral3 mb-1",children:v.description}),o.jsxs(Bt,{numOfCol:2,children:[o.jsx(Bt.Key,{children:"Created at"}),o.jsx(Bt.Value,{children:v?.createdAt?er(new Date(v.createdAt),"MMM d, yyyy"):""}),o.jsx(Bt.Key,{children:"Latest version"}),o.jsxs(Bt.Value,{children:["v",v?.version??""]})]})]}),o.jsx(Lt.Column,{children:o.jsxs(Mr,{children:[k?o.jsxs(Wn,{children:[o.jsx(zn,{asChild:!0,children:o.jsx("span",{className:"cursor-not-allowed",children:o.jsx("div",{className:"pointer-events-none opacity-50",inert:!0,"aria-disabled":"true",children:o.jsxs(de,{variant:"primary",children:[o.jsx(Fp,{}),s!=null?`Run on v${s}`:"Run Experiment"]})})})}),o.jsx(Bn,{children:"Add items to the dataset before running an experiment"})]}):o.jsxs(de,{variant:"primary",onClick:()=>i(!0),children:[o.jsx(Fp,{}),s!=null?`Run on v${s}`:"Run Experiment"]}),o.jsxs(pt,{children:[o.jsx(pt.Trigger,{asChild:!0,children:o.jsx(de,{size:"lg","aria-label":"Dataset actions menu",children:o.jsx(mD,{})})}),o.jsxs(pt.Content,{align:"end",className:"w-48",children:[o.jsxs(pt.Item,{onSelect:()=>d(!0),children:[o.jsx(Lp,{})," Edit Dataset"]}),o.jsxs(pt.Item,{onSelect:()=>m(!0),children:[o.jsx(Dp,{})," Duplicate Dataset"]}),o.jsxs(pt.Item,{onSelect:()=>p(!0),className:"text-red-500 focus:text-red-400",children:[o.jsx(au,{})," Delete Dataset"]})]})]})]})})]})}),o.jsx(Lt.MainArea,{children:o.jsx(Ces,{datasetId:e,onAddItemClick:()=>c(!0)})})]}),o.jsx(Pes,{datasetId:e,version:s??void 0,requestContextSchema:v?.requestContextSchema,open:a,onOpenChange:i,onSuccess:_}),o.jsx(jes,{datasetId:e,open:l,onOpenChange:c}),v&&o.jsx(vJr,{open:u,onOpenChange:d,dataset:{id:v.id,name:v.name,description:v?.description||"",targetType:v.targetType,inputSchema:v.inputSchema,groundTruthSchema:v.groundTruthSchema,requestContextSchema:v.requestContextSchema}}),v&&o.jsx(hJr,{open:h,onOpenChange:m,sourceDatasetId:v.id,sourceDatasetName:v.name,sourceDatasetDescription:v.description,sourceDatasetTargetType:v.targetType}),v&&o.jsx(bJr,{open:f,onOpenChange:p,datasetId:v.id,datasetName:v.name,onSuccess:C})]})}function $9t({experiment:e}){const{Link:t,paths:n}=yn(),{data:r}=km(),{data:s}=Uy(),{data:a}=ih(),i=()=>{switch(e.targetType){case"agent":return n.agentLink(e.targetId);case"workflow":return n.workflowLink(e.targetId);case"scorer":return n.scorerLink(e.targetId);default:return"#"}},l=()=>{const u=e.targetId;if(!u)return u;switch(e.targetType){case"agent":return r?.[u]?.name??u;case"workflow":return s?.[u]?.name??u;case"scorer":return a?.[u]?.scorer?.config?.name??u;default:return u}},c=e.agentVersion&&e.targetType==="agent"&&e.targetId?`${n.agentLink(e.targetId)}/editor?version=${encodeURIComponent(e.agentVersion)}`:null;return o.jsx(Lt.TopArea,{children:o.jsxs(Lt.Row,{children:[o.jsx(Lt.Column,{children:o.jsxs(Bt,{numOfCol:2,children:[o.jsx(Bt.Key,{children:"Created at"}),o.jsx(Bt.Value,{children:er(new Date(e.createdAt),"MMM d, yyyy 'at' h:mm a")}),e.completedAt&&o.jsxs(o.Fragment,{children:[o.jsx(Bt.Key,{children:"Completed at"}),o.jsx(Bt.Value,{children:er(new Date(e.completedAt),"MMM d, yyyy 'at' h:mm a")})]}),o.jsx(Bt.Key,{children:"Target"}),o.jsx(Bt.ValueLink,{href:i(),as:t,children:l()}),e.agentVersion&&o.jsxs(o.Fragment,{children:[o.jsx(Bt.Key,{children:"Version"}),c?o.jsx(Bt.ValueLink,{href:c,as:t,children:e.agentVersion}):o.jsx(Bt.Value,{children:e.agentVersion})]})]})}),o.jsx(Lt.Column,{children:o.jsx(Wes,{experiment:e})})]})})}function sF({children:e}){return o.jsxs(Lt,{height:"full",children:[o.jsx("div",{}),o.jsx(Lt.MainArea,{isCentered:!0,children:e})]})}function pts(){const{datasetId:e,experimentId:t}=ur(),{data:n,isLoading:r,error:s}=zU(e,t),{data:a,isLoading:i,setEndOfListElement:l,isFetchingNextPage:c,hasNextPage:u}=YZ({datasetId:e,experimentId:t,experimentStatus:n?.status});return!e||!t||r?null:s&&gs(s)?o.jsx(sF,{children:o.jsx(Vs,{})}):s&&ys(s)?o.jsx(sF,{children:o.jsx(Ds,{resource:"datasets"})}):s&&vOe(s)||!r&&!s&&!n?o.jsx(sF,{children:o.jsx(Cr,{iconSlot:o.jsx(tbe,{}),titleSlot:"Experiment not found",descriptionSlot:`No experiment with id "${t}".`,actionSlot:o.jsxs(de,{as:Ba,to:`/datasets/${e}?tab=experiments`,children:[o.jsx(Nc,{}),"Back to Dataset"]})})}):s?o.jsx(sF,{children:o.jsx(zi,{title:"Failed to load experiment",message:s instanceof Error?s.message:"An unexpected error occurred. Please try again."})}):o.jsxs(Lt,{height:"full",children:[o.jsx($9t,{experiment:n}),o.jsx(Lt.MainArea,{children:o.jsx(R9t,{experimentId:t,datasetId:e,experimentStatus:n.status,results:a??[],isLoading:i,setEndOfListElement:l,isFetchingNextPage:c,hasNextPage:u})})]})}function hts(){const{datasetId:e}=ur(),[t,n]=ga(),{error:r}=Hx(e??""),s=t.get("baseline")??"",a=t.get("contender")??"";return r&&gs(r)?o.jsx(ls,{children:o.jsx("div",{className:"flex h-full items-center justify-center",children:o.jsx(Vs,{})})}):r&&ys(r)?o.jsx(ls,{children:o.jsx("div",{className:"flex h-full items-center justify-center",children:o.jsx(Ds,{resource:"datasets"})})}):!e||!s||!a?o.jsx(ls,{children:o.jsx(wy,{children:o.jsxs("div",{className:"text-neutral4 text-center py-8",children:[o.jsx("p",{children:"Select two experiments to compare."}),o.jsxs("p",{className:"text-sm mt-2",children:["Use the URL format: /datasets/","{datasetId}","/experiments?baseline=","{experimentIdA}","&contender=","{experimentIdB}"]})]})})}):o.jsx(ls,{children:o.jsx(wy,{children:o.jsxs("div",{className:"max-w-[100rem] w-full px-12 mx-auto grid content-start ",children:[o.jsxs(ua,{children:[o.jsxs(ua.Column,{children:[o.jsxs(ua.Title,{children:[o.jsx(Xw,{})," Dataset Experiments Comparison"]}),o.jsxs(ua.Description,{children:["Comparing"," ",o.jsx(Ba,{to:`/datasets/${e}/experiments/${s}`,children:s.slice(0,8)})," vs"," ",o.jsx(Ba,{to:`/datasets/${e}/experiments/${a}`,children:a.slice(0,8)})]})]}),o.jsx(ua.Column,{children:o.jsxs(de,{as:Ba,to:`/datasets/${e}`,children:[o.jsx(Nc,{}),"Back to Dataset"]})})]}),o.jsx(Xes,{datasetId:e,experimentIdA:s,experimentIdB:a,onSwap:()=>{n({baseline:a,contender:s})}})]})})})}function mts(){const{datasetId:e,itemId:t}=ur(),{Link:n}=yn(),r=bs(),{data:s,isLoading:a,error:i}=vTe(e??"",t??""),{updateItem:l,deleteItem:c}=Ei(),{data:u}=Hx(e??""),d=s?.[0]??null,f=d?.isDeleted??!1,[p,h]=g.useState(null),m=g.useMemo(()=>!d||f?{input:"",groundTruth:"",metadata:"",trajectory:"",toolMocks:"",requestContext:""}:{input:JSON.stringify(d.input,null,2),groundTruth:d.groundTruth?JSON.stringify(d.groundTruth,null,2):"",metadata:d.metadata?JSON.stringify(d.metadata,null,2):"",trajectory:d.expectedTrajectory!=null?JSON.stringify(d.expectedTrajectory,null,2):"",toolMocks:d.toolMocks?.length?JSON.stringify(d.toolMocks,null,2):"",requestContext:d.requestContext?JSON.stringify(d.requestContext,null,2):""},[d,f]),v=d?.datasetVersion??0,[y,b]=g.useState(!1),[S,w]=g.useState(m.input),[k,_]=g.useState(m.groundTruth),[C,E]=g.useState(m.metadata),[j,N]=g.useState(m.trajectory),[I,R]=g.useState(m.toolMocks),[P,L]=g.useState(m.requestContext),[M,q]=g.useState(v);v!==M&&(q(v),w(m.input),_(m.groundTruth),E(m.metadata),N(m.trajectory),R(m.toolMocks),L(m.requestContext));const[H,F]=g.useState(!1),z=J=>{h(f?J:J.isLatest?null:J)},B=()=>{h(null)},D=!f&&p!=null,Q=()=>{D||b(!0)},V=()=>{D||F(!0)},$=async()=>{if(!e||!t)return;let J;try{J=JSON.parse(S)}catch{De.error("Input must be valid JSON");return}let ee;if(k.trim())try{ee=JSON.parse(k)}catch{De.error("Ground Truth must be valid JSON");return}let ae;if(C.trim())try{ae=JSON.parse(C)}catch{De.error("Metadata must be valid JSON");return}let ce;const Y=j!==m.trajectory;if(Y&&j.trim())try{ce=JSON.parse(j)}catch{De.error("Expected Trajectory must be valid JSON");return}let ne;const ue=I!==m.toolMocks;if(ue&&I.trim())try{const ve=JSON.parse(I);if(!Array.isArray(ve)){De.error("Tool Mocks must be a JSON array");return}ne=ve}catch{De.error("Tool Mocks must be valid JSON");return}let pe;const le=P!==m.requestContext;if(le&&P.trim())try{pe=JSON.parse(P)}catch{De.error("Request Context must be valid JSON");return}try{await l.mutateAsync({datasetId:e,itemId:t,input:J,groundTruth:ee,metadata:ae,...Y?{expectedTrajectory:ce??null}:{},...ue?{toolMocks:ne??[]}:{},...le?{requestContext:pe}:{}}),De.success("Item updated successfully"),b(!1)}catch(ve){De.error(`Failed to update item: ${ve instanceof Error?ve.message:"Unknown error"}`)}},U=()=>{d&&(w(JSON.stringify(d.input,null,2)),_(d.groundTruth?JSON.stringify(d.groundTruth,null,2):""),E(d.metadata?JSON.stringify(d.metadata,null,2):""),N(d.expectedTrajectory!=null?JSON.stringify(d.expectedTrajectory,null,2):""),R(d.toolMocks?.length?JSON.stringify(d.toolMocks,null,2):""),L(d.requestContext?JSON.stringify(d.requestContext,null,2):"")),b(!1)},Z=async()=>{if(!(!e||!t))try{await c.mutateAsync({datasetId:e,itemId:t}),De.success("Item deleted successfully"),F(!1),r(`/datasets/${e}`)}catch(J){De.error(`Failed to delete item: ${J instanceof Error?J.message:"Unknown error"}`)}},X=p??d,te=X?{id:t??"",datasetId:e??"",datasetVersion:X.datasetVersion,input:X.input,groundTruth:X.groundTruth,expectedTrajectory:X.expectedTrajectory,metadata:X.metadata,createdAt:X.createdAt,updatedAt:X.updatedAt}:null;return i&&gs(i)?o.jsx(ls,{children:o.jsx("div",{className:"flex h-full items-center justify-center",children:o.jsx(Vs,{})})}):i&&ys(i)?o.jsx(ls,{children:o.jsx("div",{className:"flex h-full items-center justify-center",children:o.jsx(Ds,{resource:"datasets"})})}):a?null:!e||!t||!s||s.length===0?o.jsx(ls,{children:o.jsx(wy,{children:o.jsx("div",{className:"text-neutral3 p-4",children:"Item not found"})})}):o.jsxs(o.Fragment,{children:[o.jsx(ls,{children:o.jsx("div",{className:"h-full overflow-hidden px-6 pb-4",children:o.jsxs("div",{className:"grid gap-6 max-w-[60rem] mx-auto grid-rows-[auto_1fr] h-full",children:[o.jsxs(ua,{children:[o.jsxs(ua.Column,{children:[o.jsxs(ua.Title,{children:[o.jsx(yN,{}),t," ",o.jsx(Oa,{content:t})]}),o.jsx(ua.Description,{children:o.jsxs(Al,{children:["Item of ",o.jsx(iy,{})," ",u?.name]})}),o.jsxs(ua.Description,{children:[o.jsxs(Al,{children:[o.jsx(Nlt,{})," Created at"," ",d?.createdAt?er(new Date(d.createdAt),"MMM d, yyyy"):""]}),o.jsxs(Al,{children:[o.jsx(p_,{})," Latest version v",d?.datasetVersion??""]})]})]}),o.jsx(ua.Column,{children:!y&&!f&&o.jsxs(Mr,{children:[o.jsxs(de,{onClick:Q,disabled:D,title:D?"Return to latest version to edit":void 0,children:[o.jsx(Ylt,{})," Edit"]}),o.jsxs(de,{onClick:V,disabled:D,title:D?"Return to latest version to delete":void 0,children:[o.jsx(au,{})," Delete"]})]})})]}),o.jsxs(sy,{className:y?"grid-cols-1":"grid-cols-[1fr_auto]",children:[o.jsxs(Gr,{withRightSeparator:!y,children:[f&&d&&o.jsx(In,{variant:"destructive",title:"Item deleted",children:o.jsxs(In.Message,{children:["This item was deleted at version v",d.datasetVersion]})}),!f&&D&&p&&o.jsx(In,{variant:"warning",title:"Previous version",action:o.jsxs(In.Button,{onClick:B,children:[o.jsx(_lt,{})," Return to the latest version"]}),children:o.jsxs(In.Message,{children:["Viewing version v",p.datasetVersion]})}),y?o.jsx(N9t,{inputValue:S,setInputValue:w,groundTruthValue:k,setGroundTruthValue:_,metadataValue:C,setMetadataValue:E,trajectoryValue:j,setTrajectoryValue:N,toolMocksValue:I,setToolMocksValue:R,requestContextValue:P,setRequestContextValue:L,validationErrors:null,onSave:$,onCancel:U,isSaving:l.isPending}):te?o.jsx(wTe,{item:te,Link:n}):o.jsx("div",{className:"text-neutral4 text-sm",children:"Item data not available"})]}),!y&&o.jsx(Gr,{children:o.jsx(Kes,{datasetId:e,itemId:t,onClose:()=>{},onVersionSelect:z,onCompareVersionsClick:J=>{r(`/datasets/${e}/items/${t}/versions?ids=${J.join(",")}`)},activeVersion:p?.datasetVersion??null})})]})]})})}),o.jsx(Tt,{open:H,onOpenChange:F,children:o.jsxs(Tt.Content,{children:[o.jsxs(Tt.Header,{children:[o.jsx(Tt.Title,{children:"Delete Item"}),o.jsx(Tt.Description,{children:"Are you sure you want to delete this item? This action cannot be undone."})]}),o.jsxs(Tt.Footer,{children:[o.jsx(Tt.Cancel,{children:"Cancel"}),o.jsx(Tt.Action,{onClick:Z,children:c.isPending?"Deleting...":"Delete"})]})]})})]})}function MQe(e){return JSON.stringify({input:e.input??null,groundTruth:e.groundTruth??null,metadata:e.metadata??null},null,2)}function gts(){const{datasetId:e}=ur(),[t,n]=ga(),r=t.get("items")?.split(",").filter(Boolean)??[],{data:s,error:a}=Hx(e??""),{Link:i}=yn(),[l,c]=g.useState(!1),{data:u}=BU(e??"",r[0]??""),{data:d}=BU(e??"",r[1]??"");return a&&gs(a)?o.jsx(ls,{children:o.jsx("div",{className:"flex h-full items-center justify-center",children:o.jsx(Vs,{})})}):a&&ys(a)?o.jsx(ls,{children:o.jsx("div",{className:"flex h-full items-center justify-center",children:o.jsx(Ds,{resource:"datasets"})})}):!e||r.length<2?o.jsx(ls,{children:o.jsx(wy,{children:o.jsx("div",{className:"text-neutral4 text-center py-8",children:o.jsx("p",{children:"Select at least two items to compare."})})})}):o.jsxs(ls,{children:[o.jsx(Iy,{owner:"dataset-items-compare",children:o.jsxs(de,{as:Ba,to:`/datasets/${e}`,variant:"outline",children:[o.jsx(Nc,{}),"Back to Dataset"]})}),o.jsx("div",{className:"h-full overflow-hidden px-[3vw] pb-4",children:o.jsxs("div",{className:K("grid gap-6 max-w-[140rem] mx-auto grid-rows-[auto_1fr] h-full",{"grid-rows-[auto_auto_1fr]":l}),children:[o.jsxs(ua,{children:[o.jsxs(ua.Column,{children:[o.jsxs(ua.Title,{children:[o.jsx(Xw,{}),"Compare Dataset Items"]}),o.jsx(ua.Description,{children:o.jsxs(Al,{children:["Comparing ",r.length," items of"," ",o.jsx(Ba,{to:`/datasets/${e}`,className:"text-info1 hover:underline",children:s?.name||e?.slice(0,8)})]})})]}),o.jsx(ua.Column,{children:o.jsx(Mr,{children:o.jsx(de,{variant:"primary",onClick:()=>c(f=>!f),children:l?o.jsxs(o.Fragment,{children:[o.jsx(Dlt,{})," Default View"]}):o.jsxs(o.Fragment,{children:[o.jsx(Bcn,{})," Diff View"]})})})})]}),o.jsx(sy,{className:"grid-cols-[1fr_3vw_1fr]",children:r.map((f,p)=>o.jsxs(g.Fragment,{children:[o.jsx(vts,{datasetId:e,itemId:f,Link:i,idx:p,itemIds:r,showContent:!l,onItemChange:h=>{const m=[...r];m[p]=h,n({items:m.join(",")})}}),p==0&&o.jsx("div",{className:K("bg-surface5 w-[3px] shrink-0 mx-[1.5vw]")})]},f))}),l&&u&&d&&o.jsx($_e,{codeA:MQe(u),codeB:MQe(d)})]})})]})}function vts({datasetId:e,itemId:t,Link:n,idx:r,itemIds:s,onItemChange:a,showContent:i=!0}){const{data:l,isLoading:c}=BU(e,t),{data:u}=E1(e),d=new Set(s.filter((p,h)=>h!==r)),f=(u??[]).map(p=>({value:p.id,label:p.id,disabled:d.has(p.id)}));return o.jsxs(Gr,{children:[o.jsxs(Gr.Toolbar,{className:"flex gap-4",children:[o.jsxs(da,{name:`compare-item-${r}`,value:t,onValueChange:a,children:[o.jsx(pa,{"aria-label":"Item",children:o.jsx(fa,{placeholder:"Select item"})}),o.jsx(ha,{children:f.map(p=>o.jsx(Lr,{value:p.value,disabled:p.disabled,children:p.label},p.value))})]}),o.jsxs(de,{as:n,to:`/datasets/${e}/items/${t}`,children:[o.jsx(p_,{}),"Versions"]})]}),i&&o.jsx(Gr.Content,{children:c?o.jsx("div",{className:"text-neutral4 text-sm",children:"Loading..."}):l?o.jsxs(o.Fragment,{children:[o.jsx(Tes,{item:l}),o.jsx(wTe,{item:l,Link:n})]}):o.jsxs("div",{className:"text-neutral4 text-sm",children:["Item ",t.slice(0,8)," not found"]})})]})}function DQe(e){return JSON.stringify({input:e.input??null,groundTruth:e.groundTruth??null,metadata:e.metadata??null},null,2)}function yts(){const{datasetId:e,itemId:t}=ur(),[n,r]=ga(),[s,a]=g.useState(!1),i=n.get("ids")?.split(",").map(Number).filter(h=>!isNaN(h)&&h>0)??[],{data:l,error:c}=Hx(e??""),{Link:u}=yn(),{data:d}=vTe(e??"",t??""),{data:f}=Bve(e??"",t??"",i[0]??0,l?.version),{data:p}=Bve(e??"",t??"",i[1]??0,l?.version);return c&&gs(c)?o.jsx(ls,{children:o.jsx("div",{className:"flex h-full items-center justify-center",children:o.jsx(Vs,{})})}):c&&ys(c)?o.jsx(ls,{children:o.jsx("div",{className:"flex h-full items-center justify-center",children:o.jsx(Ds,{resource:"datasets"})})}):!e||!t||i.length<2?o.jsx(ls,{children:o.jsx(wy,{children:o.jsx("div",{className:"text-neutral4 text-center py-8",children:o.jsx("p",{children:"Select at least two versions to compare."})})})}):o.jsxs(ls,{children:[o.jsx(Iy,{owner:"dataset-item-versions-compare",children:o.jsxs(de,{as:Ba,to:`/datasets/${e}/items/${t}`,variant:"outline",children:[o.jsx(Nc,{}),"Back to Item"]})}),o.jsx("div",{className:"h-full overflow-hidden px-[3vw] pb-4",children:o.jsxs("div",{className:K("grid gap-6 max-w-[140rem] mx-auto grid-rows-[auto_1fr] h-full",{"grid-rows-[auto_auto_1fr]":s}),children:[o.jsxs(ua,{children:[o.jsxs(ua.Column,{children:[o.jsxs(ua.Title,{children:[o.jsx(Xw,{}),"Compare Dataset Item Versions"]}),o.jsx(ua.Description,{children:o.jsxs(Al,{children:["Comparing ",i.length," versions of"," ",o.jsx(Ba,{to:`/datasets/${e}/items/${t}`,className:"text-info1 hover:underline",children:t})]})})]}),o.jsx(ua.Column,{children:o.jsx(Mr,{children:o.jsx(de,{variant:"primary",onClick:()=>a(h=>!h),children:s?o.jsxs(o.Fragment,{children:[o.jsx(Dlt,{})," Default View"]}):o.jsxs(o.Fragment,{children:[o.jsx(Cun,{})," Diff View"]})})})})]}),o.jsx(sy,{className:"grid-cols-[1fr_3vw_1fr]",children:i.map((h,m)=>o.jsxs(g.Fragment,{children:[o.jsx(bts,{datasetId:e,itemId:t,datasetVersion:h,latestVersion:l?.version,allVersions:d??[],versionNumbers:i,Link:u,idx:m,showContent:!s,onVersionChange:v=>{const y=[...i];y[m]=v,r({ids:y.join(",")})}}),m===0&&o.jsx("div",{className:K("bg-surface5 w-[3px] shrink-0 mx-[1.5vw]")})]},h))}),s&&f&&p&&o.jsx($_e,{codeA:DQe(f),codeB:DQe(p)})]})})]})}function bts({datasetId:e,itemId:t,datasetVersion:n,latestVersion:r,allVersions:s,versionNumbers:a,Link:i,idx:l,showContent:c=!0,onVersionChange:u}){const{data:d,isLoading:f}=Bve(e,t,n,r),p=new Set(a.filter((v,y)=>y!==l)),h=s.map(v=>{const y=typeof v.updatedAt=="string"?new Date(v.updatedAt):v.updatedAt;return{value:String(v.datasetVersion),label:o.jsxs(o.Fragment,{children:[o.jsxs("b",{children:["v. ",v.datasetVersion]})," - ",er(y,"MMM d, yyyy h:mm a"),v.isLatest?o.jsx(Xs,{color:"blue",size:"small",children:"Latest"}):null]}),disabled:p.has(v.datasetVersion)}}),m=d?{id:d.id,datasetId:e,datasetVersion:d.datasetVersion,input:d.input,groundTruth:d.groundTruth,metadata:d.metadata,createdAt:d.createdAt,updatedAt:d.updatedAt}:null;return o.jsxs(Gr,{children:[o.jsxs(Gr.Toolbar,{className:"grid gap-4 grid-cols-[auto_1fr]",children:[o.jsx(p_,{className:"w-6 h-6 opacity-50"}),o.jsxs(da,{name:`compare-version-${l}`,value:String(n),onValueChange:v=>u(Number(v)),children:[o.jsx(pa,{"aria-label":"Version",className:"w-full",children:o.jsx(fa,{placeholder:"Select version"})}),o.jsx(ha,{children:h.map(v=>o.jsx(Lr,{value:v.value,disabled:v.disabled,children:v.label},v.value))})]})]}),c&&o.jsx(Gr.Content,{children:f?o.jsx("div",{className:"text-neutral4 text-sm",children:"Loading..."}):!d||!m?o.jsxs("div",{className:"text-neutral4 text-sm",children:["Version ",n," not found"]}):o.jsx(wTe,{item:m,Link:i})})]})}function xts(){const{datasetId:e}=ur(),[t]=ga(),n=t.get("ids")?.split(",").map(Number).filter(v=>!isNaN(v)&&v>0)??[],r=bs(),{data:s,error:a}=Hx(e??""),i=E1(e??"",void 0,n[0]??null),l=E1(e??"",void 0,n[1]??null),c=g.useMemo(()=>i.data??[],[i.data]),u=g.useMemo(()=>l.data??[],[l.data]),d=g.useMemo(()=>{const v=new Map;for(const y of[...c,...u])v.has(y.id)||v.set(y.id,{id:y.id,createdAt:new Date(y.createdAt)});return[...v.values()].sort((y,b)=>b.createdAt.getTime()-y.createdAt.getTime())},[c,u]),f=g.useMemo(()=>new Map(c.map(v=>[v.id,v])),[c]),p=g.useMemo(()=>new Map(u.map(v=>[v.id,v])),[u]);if(a&&gs(a))return o.jsx(ls,{children:o.jsx("div",{className:"flex h-full items-center justify-center",children:o.jsx(Vs,{})})});if(a&&ys(a))return o.jsx(ls,{children:o.jsx("div",{className:"flex h-full items-center justify-center",children:o.jsx(Ds,{resource:"datasets"})})});if(!e||n.length<2)return o.jsx(ls,{children:o.jsx(wy,{children:o.jsx("div",{className:"text-neutral4 text-center py-8",children:o.jsx("p",{children:"Select at least two versions to compare."})})})});const h=(v,y,b)=>{r(`/datasets/${e}/items/${v}/versions?ids=${y?.datasetVersion??""},${b?.datasetVersion??""}`)},m=(v,y)=>{r(`/datasets/${e}/versions?ids=${v},${y}`,{replace:!0})};return o.jsx(ls,{children:o.jsx("div",{className:"h-full overflow-hidden px-[3vw] pb-4",children:o.jsxs("div",{className:"grid gap-6 max-w-[140rem] mx-auto grid-rows-[auto_1fr] h-full",children:[o.jsxs(ua,{children:[o.jsxs(ua.Column,{children:[o.jsxs(ua.Title,{children:[o.jsx(lfn,{})," Compare Dataset Versions"]}),o.jsx(ua.Description,{children:o.jsxs(Al,{children:[o.jsx(p_,{})," Comparing ",n.length," versions of"," ",s?.name||e?.slice(0,8)]})})]}),o.jsx(ua.Column,{children:o.jsxs(de,{as:Ba,to:`/datasets/${e}`,children:[o.jsx(Nc,{}),"Back to Dataset"]})})]}),o.jsx(sy,{children:o.jsxs(Gr,{children:[o.jsx(tts,{datasetId:e,versionA:String(n[0]),versionB:String(n[1]),onVersionChange:m}),o.jsx(ats,{datasetId:e,versionA:n[0],versionB:n[1],allItems:d,itemsAMap:f,itemsBMap:p,onItemClick:h})]})})]})})})}function qve({children:e,className:t}){return o.jsx("div",{className:K("flex flex-wrap gap-8",t),children:e})}function wts(e){if(!e||e.length<2)return null;const t=[...e].sort((i,l)=>new Date(i.createdAt).getTime()-new Date(l.createdAt).getTime()),n=Math.floor(t.length/2),r=n,s=t.length-n;if(r===0)return null;const a=(s-r)/r*100;return{changePct:Math.round(a*10)/10,prevValue:String(r)}}function Sts({scorers:e,datasets:t,experiments:n,avgScore:r,prevAvgScore:s,totalNeedsReview:a,isLoadingScorers:i,isLoadingDatasets:l,isLoadingExperiments:c,isLoadingScores:u,isLoadingReview:d}){const f=e?Object.keys(e).length:void 0,p=t?.length,h=n?.length,m=r!=null&&s!=null&&s!==0?{changePct:Math.round((r-s)/s*100*10)/10,prevValue:String(s)}:null,v=wts(n);return o.jsxs(o.Fragment,{children:[o.jsxs(Kr,{children:[o.jsx(Kr.Label,{children:"Total Scorers"}),i?o.jsx(Kr.Loading,{}):f!=null?o.jsxs(o.Fragment,{children:[o.jsx(Kr.Value,{children:String(f)}),o.jsx(Kr.NoChange,{message:"Static count"})]}):o.jsx(Kr.NoData,{})]}),o.jsxs(Kr,{children:[o.jsx(Kr.Label,{children:"Total Datasets"}),l?o.jsx(Kr.Loading,{}):p!=null?o.jsxs(o.Fragment,{children:[o.jsx(Kr.Value,{children:String(p)}),o.jsx(Kr.NoChange,{message:"Static count"})]}):o.jsx(Kr.NoData,{})]}),o.jsxs(Kr,{children:[o.jsx(Kr.Label,{children:"Avg Score"}),u?o.jsx(Kr.Loading,{}):r!=null?o.jsxs(o.Fragment,{children:[o.jsx(Kr.Value,{children:String(r)}),m?o.jsx(Kr.Change,{changePct:m.changePct,prevValue:m.prevValue}):o.jsx(Kr.NoChange,{})]}):o.jsx(Kr.NoData,{})]}),o.jsxs(Kr,{children:[o.jsx(Kr.Label,{children:"Total Experiments"}),c?o.jsx(Kr.Loading,{}):h!=null?o.jsxs(o.Fragment,{children:[o.jsx(Kr.Value,{children:String(h)}),v?o.jsx(Kr.Change,{changePct:v.changePct,prevValue:v.prevValue}):o.jsx(Kr.NoChange,{})]}):o.jsx(Kr.NoData,{})]}),o.jsxs(Kr,{children:[o.jsx(Kr.Label,{children:"Needs Review"}),d?o.jsx(Kr.Loading,{}):a!=null?o.jsxs(o.Fragment,{children:[o.jsx(Kr.Value,{children:String(a)}),a>0?o.jsx(Kr.NoChange,{message:"items pending review"}):o.jsx(Kr.NoChange,{message:"All caught up"})]}):o.jsx(Kr.NoData,{})]})]})}const LQe="auto 1fr auto auto auto auto auto auto auto";function kts(e){return e?(typeof e=="string"?new Date(e):e).toLocaleDateString("en-US",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}):"—"}const Ots={completed:"success",running:"warning",failed:"error",pending:"neutral"};function _ts({experiments:e,datasets:t,reviewByExperiment:n,isLoading:r,search:s="",statusFilter:a="all",datasetFilter:i="all"}){const{paths:l,Link:c}=yn(),u=g.useMemo(()=>{const p=new Map;return t?.forEach(h=>p.set(h.id,h.name)),p},[t]),d=g.useMemo(()=>[...e].sort((p,h)=>{const m=p.createdAt?new Date(p.createdAt).getTime():0;return(h.createdAt?new Date(h.createdAt).getTime():0)-m}),[e]),f=g.useMemo(()=>{const p=s.toLowerCase();return d.filter(h=>{const m=h.datasetId?u.get(h.datasetId)??"":"",v=!p||h.id.toLowerCase().includes(p)||m.toLowerCase().includes(p)||(h.targetId??"").toLowerCase().includes(p),y=a==="all"||h.status===a,b=i==="all"||h.datasetId===i;return v&&y&&b})},[d,s,u,a,i]);return r?o.jsx(tl,{columns:LQe}):o.jsxs(me,{columns:LQe,variant:"striped",children:[o.jsxs(me.Top,{children:[o.jsx(me.TopCell,{children:"Experiment"}),o.jsx(me.TopCell,{children:"Dataset"}),o.jsx(me.TopCell,{children:"Target"}),o.jsx(me.TopCell,{children:"Status"}),o.jsx(me.TopCell,{className:"text-center",children:"Items"}),o.jsx(me.TopCell,{className:"text-center",children:"Succeeded"}),o.jsx(me.TopCell,{className:"text-center",children:"Failed"}),o.jsx(me.TopCell,{className:"text-center",children:"Review"}),o.jsx(me.TopCell,{children:"Date"})]}),f.map(p=>{const h=p.datasetId?u.get(p.datasetId)??p.datasetId.slice(0,8):"—",m=p.status??"pending",v=p.succeededCount??0,y=p.failedCount??0,b=p.totalItems??0,S=b>0?Math.round(v/b*100):0;return o.jsxs(me.RowLink,{to:l.experimentLink(p.id),LinkComponent:c,children:[o.jsx(me.NameCell,{className:"font-mono",children:p.id.slice(0,8)}),o.jsx(me.TextCell,{children:h}),o.jsx(me.Cell,{children:o.jsxs("span",{className:"truncate",children:[p.targetType," ",p.targetId]})}),o.jsx(me.Cell,{children:o.jsx(pg,{variant:Ots[m]??"neutral",withDot:!0,children:m})}),o.jsx(me.TextCell,{className:"text-center",children:b}),o.jsx(me.TextCell,{className:"text-center",children:o.jsxs("span",{className:v>0?"text-accent1":"",children:[v," (",S,"%)"]})}),o.jsx(me.TextCell,{className:"text-center",children:o.jsx("span",{className:y>0?"text-accent2":"",children:y})}),o.jsx(me.Cell,{className:"text-center",children:(()=>{const w=n?.get(p.id);if(!w)return o.jsx("span",{className:"text-neutral2",children:"—"});const k=w.needsReview+w.complete;return k===0?o.jsx("span",{className:"text-neutral2",children:"—"}):w.needsReview>0?o.jsxs(Xs,{size:"small",color:"yellow",children:[w.needsReview," pending"]}):o.jsxs(Xs,{size:"small",color:"green",children:[w.complete,"/",k," reviewed"]})})()}),o.jsx(me.TextCell,{children:kts(p.createdAt)})]},p.id)})]})}const Cts=[{value:"all",label:"All statuses"},{value:"completed",label:"Completed"},{value:"running",label:"Running"},{value:"failed",label:"Failed"},{value:"pending",label:"Pending"}];function Ets(e){return[{value:"all",label:"All datasets"},...(e??[]).map(t=>({value:t.id,label:t.name}))]}const aF={completed:"#22c55e",running:"#facc15",pending:"#fb923c",failed:"#f87171"},jts=[{label:"Completed",color:aF.completed},{label:"Running",color:aF.running},{label:"Pending",color:aF.pending},{label:"Failed",color:aF.failed}];function Tts({experiments:e,datasets:t,isLoading:n,isError:r}){const{data:s,maxVal:a}=g.useMemo(()=>{if(!e||e.length===0)return{data:[],maxVal:0};const l=new Map;if(t)for(const f of t)l.set(f.id,f.name);const c=new Map;for(const f of e){const p=f.datasetId??"unknown";c.has(p)||c.set(p,{completed:0,running:0,pending:0,failed:0});const h=c.get(p),m=f.status;m in h&&h[m]++}let u=0;return{data:Array.from(c.entries()).map(([f,p])=>{const h=p.completed+p.running+p.pending+p.failed;return h>u&&(u=h),{name:l.get(f)??f.slice(0,12),values:[p.completed,p.running,p.pending,p.failed]}}),maxVal:u}},[e,t]),i=s.length>0;return o.jsxs(Ut,{children:[o.jsxs(Ut.TopBar,{children:[o.jsx(Ut.TitleAndDescription,{title:"Experiments by Dataset",description:"Experiment status breakdown per dataset."}),i&&o.jsx(Ut.Summary,{value:String(e?.length??0),label:"Total experiments"})]}),n?o.jsx(Ut.Loading,{}):r?o.jsx(Ut.Error,{message:"Failed to load experiments data"}):o.jsx(Ut.Content,{children:i?o.jsx(uN,{data:s,segments:jts,maxVal:a,fmt:l=>String(l)}):o.jsx(Ut.NoData,{message:"No experiments have been run yet"})})]})}const Nts=()=>o.jsx("div",{className:"flex h-full items-center justify-center",children:o.jsx(Cr,{iconSlot:o.jsx(Of,{}),titleSlot:"No Experiments yet",descriptionSlot:o.jsxs(o.Fragment,{children:["Run an experiment from a dataset to evaluate ",o.jsx("br",{}),"your agents and workflows."]}),actionSlot:o.jsx("div",{className:"flex flex-col items-center gap-2",children:o.jsxs(de,{variant:"ghost",as:"a",href:"https://mastra.ai/en/docs/evals/datasets/running-experiments",target:"_blank",rel:"noopener noreferrer",children:["Experiments Documentation ",o.jsx(_a,{})]})})})});function Its({search:e,onSearchChange:t,statusFilter:n,onStatusFilterChange:r,datasetFilter:s,onDatasetFilterChange:a,datasetOptions:i,onReset:l,hasActiveFilters:c}){return o.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[o.jsx(jf,{label:"Search experiments",placeholder:"Filter by experiment, dataset, or target",value:e,onSearch:t}),o.jsxs(Mr,{children:[o.jsx(Sc,{label:"Status",labelIsHidden:!0,name:"filter-status",options:[...Cts],value:n,onValueChange:r,className:"whitespace-nowrap"}),o.jsx(Sc,{label:"Dataset",labelIsHidden:!0,name:"filter-dataset",options:i,value:s,onValueChange:a,className:"whitespace-nowrap"}),l&&c&&o.jsxs(de,{onClick:l,size:"sm",variant:"default",children:[o.jsx(vs,{className:"size-3"})," Reset"]})]})]})}function Ats(){const{data:e,isLoading:t,error:n}=ih(),{data:r,isLoading:s,error:a}=$g(),{data:i,isLoading:l,error:c}=JZ(),{data:u,isLoading:d,isError:f,error:p}=UWr(),{data:h,isLoading:m,isError:v,error:y}=OTe(),b=r?.datasets,S=i?.experiments,w=g.useMemo(()=>cts(h),[h]),k=n||a||c||p||y;return k&&gs(k)?o.jsx(lr,{children:o.jsx(Vs,{})}):k&&ys(k)?o.jsx(lr,{children:o.jsx(Ds,{resource:"evaluation"})}):k?o.jsx(lr,{children:o.jsx(zi,{title:"Failed to load evaluation data",message:k.message})}):o.jsx(Lt,{width:"wide",height:"full",children:o.jsxs("div",{className:"flex flex-col gap-6",children:[o.jsx(qve,{children:o.jsx(Sts,{scorers:e,datasets:b,experiments:S,avgScore:u?.avgScore??null,prevAvgScore:u?.prevAvgScore??null,totalNeedsReview:w.needsReview,isLoadingScorers:t,isLoadingDatasets:s,isLoadingExperiments:l,isLoadingScores:d,isLoadingReview:m})}),o.jsx(eWr,{summaryData:u?.summaryData??[],overTimeData:u?.overTimeData??[],scorerNames:u?.scorerNames??[],avgScore:u?.avgScore??null,isLoading:d,isError:f}),o.jsxs("div",{className:"grid grid-cols-1 gap-6 lg:grid-cols-2",children:[o.jsx(uJr,{experiments:S,isLoading:l,isError:!!c}),o.jsx(Tts,{experiments:S,datasets:b,isLoading:l,isError:!!c})]}),o.jsx(ots,{reviewSummary:h,experiments:S,datasets:b,isLoading:m,isError:!!v})]})})}function Rts(){const[e,t]=g.useState(""),[n,r]=g.useState("all"),[s,a]=g.useState("all"),{data:i,isLoading:l,error:c}=$g(),{data:u,isLoading:d,error:f}=JZ(),{data:p}=OTe(),h=g.useMemo(()=>i?.datasets??[],[i?.datasets]),m=g.useMemo(()=>u?.experiments??[],[u?.experiments]),v=g.useMemo(()=>Ets(h),[h]),y=g.useMemo(()=>P9t(p),[p]),b=l||d,S=f||c;if(S&&gs(S))return o.jsx(lr,{children:o.jsx(Vs,{})});if(f&&ys(f))return o.jsx(lr,{children:o.jsx(Ds,{resource:"experiments"})});if(c&&ys(c))return o.jsx(lr,{children:o.jsx(Ds,{resource:"datasets"})});if(S)return o.jsx(lr,{children:o.jsx(zi,{title:"Failed to load experiments",message:S.message})});if(m.length===0&&!b)return o.jsx(lr,{children:o.jsx(Nts,{})});const w=n!=="all"||s!=="all"||e!=="",k=()=>{t(""),r("all"),a("all")};return o.jsxs(Lt,{children:[o.jsx(Lt.TopArea,{children:o.jsx(Its,{search:e,onSearchChange:t,statusFilter:n,onStatusFilterChange:r,datasetFilter:s,onDatasetFilterChange:a,datasetOptions:v,onReset:k,hasActiveFilters:w})}),o.jsx(_ts,{experiments:m,datasets:h,reviewByExperiment:y,isLoading:b,search:e,statusFilter:n,datasetFilter:s})]})}function iF({children:e}){return o.jsxs(Lt,{height:"full",children:[o.jsx("div",{}),o.jsx(Lt.MainArea,{isCentered:!0,children:e})]})}function Pts(){const{experimentId:e}=ur(),{data:t,isLoading:n}=JZ(),s=t?.experiments?.find(h=>h.id===e)?.datasetId??"",{data:a,isLoading:i,error:l}=zU(s,e??""),{data:c,isLoading:u,setEndOfListElement:d,isFetchingNextPage:f,hasNextPage:p}=YZ({datasetId:s,experimentId:e??"",experimentStatus:a?.status});return!e||n||i?null:l&&gs(l)?o.jsx(iF,{children:o.jsx(Vs,{})}):l&&ys(l)?o.jsx(iF,{children:o.jsx(Ds,{resource:"datasets"})}):l&&vOe(l)||!n&&!s||!i&&!l&&!a?o.jsx(iF,{children:o.jsx(Cr,{iconSlot:o.jsx(tbe,{}),titleSlot:"Experiment not found",descriptionSlot:`No experiment with id "${e}".`,actionSlot:o.jsxs(de,{as:Ba,to:"/experiments",children:[o.jsx(Nc,{}),"Back to Experiments"]})})}):l?o.jsx(iF,{children:o.jsx(zi,{title:"Failed to load experiment",message:l instanceof Error?l.message:"An unexpected error occurred. Please try again."})}):o.jsxs(Lt,{height:"full",children:[o.jsx($9t,{experiment:a}),o.jsx(Lt.MainArea,{children:o.jsx(R9t,{experimentId:e,datasetId:s,experimentStatus:a.status,results:c??[],isLoading:u,setEndOfListElement:d,isFetchingNextPage:f,hasNextPage:p})})]})}function $ts({connection:e,isAdmin:t,disconnectPending:n,onDisconnect:r}){return o.jsxs("li",{className:"flex items-center justify-between border-b py-2",children:[o.jsxs("div",{children:[o.jsx("div",{className:"font-mono text-xs",children:e.connectionId}),o.jsxs("div",{className:"text-xs text-gray-500",children:[e.label??"(no label)"," · ",e.status,e.scope?` · ${e.scope}`:"",t&&e.authorId?` · author: ${e.authorId}`:""]})]}),o.jsx("button",{type:"button",className:"text-red-600 underline disabled:opacity-50",onClick:r,disabled:n,children:"Disconnect"})]})}function M9t({connections:e,isAdmin:t,disconnectPending:n,onDisconnect:r}){return o.jsx("ul",{className:"space-y-1",children:e.map(s=>o.jsx($ts,{connection:s,isAdmin:t,disconnectPending:n,onDisconnect:()=>r(s.connectionId)},s.connectionId))})}function Mts({groups:e,isAdmin:t,disconnectPending:n,onDisconnect:r}){return o.jsx("div",{className:"space-y-4",children:e.map(([s,a])=>o.jsxs("div",{children:[o.jsx("h3",{className:"text-sm font-semibold text-gray-700","data-testid":`integration-author-group-${s}`,children:s==="shared"?"Shared":`Owned by ${s}`}),o.jsx(M9t,{connections:a,isAdmin:t,disconnectPending:n,onDisconnect:r})]},s))})}function Dts({providerId:e,toolkit:t,connections:n,groupedByAuthor:r,isAdmin:s,isLoading:a,error:i,disconnectPending:l,disconnectError:c,onDisconnect:u}){return o.jsxs("div",{className:"space-y-2 border rounded p-4",children:[o.jsx("h2",{className:"text-lg font-semibold",children:"Existing connections"}),!e||!t?o.jsx("p",{className:"text-gray-500",children:"Pick a provider and toolkit to list connections."}):a?o.jsx("p",{className:"text-gray-500",children:"Loading…"}):i?o.jsx("p",{className:"text-red-600",children:String(i)}):n.length===0?o.jsx("p",{className:"text-gray-500",children:"No connections."}):r?o.jsx(Mts,{groups:r,isAdmin:s,disconnectPending:l,onDisconnect:u}):o.jsx(M9t,{connections:n,isAdmin:s,disconnectPending:l,onDisconnect:u}),c?o.jsx("p",{className:"text-red-600",children:String(c)}):null]})}function Lts({providers:e,toolkits:t,providerId:n,toolkit:r,label:s,providersLoading:a,providersError:i,toolkitsLoading:l,toolkitsError:c,authorizePending:u,authorizeError:d,authorizedConnection:f,onProviderChange:p,onToolkitChange:h,onLabelChange:m,onConnect:v}){return o.jsxs("div",{className:"space-y-4 border rounded p-4",children:[o.jsxs("div",{className:"space-y-1",children:[o.jsx("label",{className:"block font-medium",htmlFor:"provider-select",children:"Provider"}),o.jsxs("select",{id:"provider-select",className:"border rounded px-2 py-1 w-full",value:n,onChange:y=>p(y.target.value),disabled:a,children:[o.jsx("option",{value:"",children:"— select provider —"}),e.map(y=>o.jsxs("option",{value:y.id,children:[y.displayName??y.name," (",y.id,")"]},y.id))]}),a&&o.jsx("span",{className:"text-gray-500",children:"Loading providers…"}),i?o.jsx("span",{className:"text-red-600",children:String(i)}):null]}),o.jsxs("div",{className:"space-y-1",children:[o.jsx("label",{className:"block font-medium",htmlFor:"toolkit-select",children:"Toolkit"}),o.jsxs("select",{id:"toolkit-select",className:"border rounded px-2 py-1 w-full",value:r,onChange:y=>h(y.target.value),disabled:!n||l,children:[o.jsx("option",{value:"",children:"— select toolkit —"}),t.map(y=>o.jsxs("option",{value:y.slug,children:[y.name," (",y.slug,")"]},y.slug))]}),l&&o.jsx("span",{className:"text-gray-500",children:"Loading toolkits…"}),c?o.jsx("span",{className:"text-red-600",children:String(c)}):null]}),o.jsxs("div",{className:"space-y-1",children:[o.jsx("label",{className:"block font-medium",htmlFor:"label-input",children:"Label (optional)"}),o.jsx("input",{id:"label-input",type:"text",className:"border rounded px-2 py-1 w-full",placeholder:"My personal Gmail",value:s,onChange:y=>m(y.target.value),disabled:!n||!r})]}),o.jsx("button",{type:"button",className:"bg-blue-600 text-white rounded px-4 py-2 disabled:opacity-50",onClick:v,disabled:!n||!r||u,children:u?"Authorizing…":"Connect"}),d?o.jsx("p",{className:"text-red-600",children:String(d)}):null,f&&o.jsxs("p",{className:"text-green-700",children:["Authorized: ",f.connectionId," (status: ",f.status,")"]})]})}const FQe=e=>e.authorId?.trim()||"shared",Fts=(e,t)=>{if(!t||new Set(e.map(FQe)).size<=1)return null;const r=new Map;for(const a of e){const i=FQe(a);r.set(i,[...r.get(i)??[],a])}const s=Array.from(r.entries());return s.sort(([a],[i])=>a==="shared"?1:i==="shared"?-1:a.localeCompare(i)),s},zts=["*","tool-providers:*","tool-providers:admin"];function Bts(){const{data:e}=Sm();return e?.permissions?.some(t=>zts.includes(t))??!1}function Uts(){const[e,t]=g.useState(""),[n,r]=g.useState(""),[s,a]=g.useState(""),i=dI(),l=cW(e||null),c=XIt(e||null,n||null),u=YIt(),d=ZIt(),f=Bts(),p=i.data?.providers??[],h=l.data?.data??[],m=g.useMemo(()=>c.data?.items??[],[c.data?.items]),v=g.useMemo(()=>Fts(m,f),[m,f]),y=w=>{t(w),r("")},b=()=>{!e||!n||u.mutate({providerId:e,toolkit:n,label:s.trim()||null},{onSuccess:()=>{a(""),c.refetch()}})},S=w=>{d.mutate({providerId:e,connectionId:w})};return o.jsxs("div",{className:"p-6 max-w-3xl space-y-6 text-sm",children:[o.jsx("h1",{className:"text-2xl font-semibold",children:"Integrations"}),o.jsx("p",{className:"text-gray-500",children:"Minimal page to verify the ToolProvider backend. Pick a provider and toolkit, then connect."}),o.jsx(Lts,{providers:p,toolkits:h,providerId:e,toolkit:n,label:s,providersLoading:i.isLoading,providersError:i.error,toolkitsLoading:l.isLoading,toolkitsError:l.error,authorizePending:u.isPending,authorizeError:u.error,authorizedConnection:u.data,onProviderChange:y,onToolkitChange:r,onLabelChange:a,onConnect:b}),o.jsx(Dts,{providerId:e,toolkit:n,connections:m,groupedByAuthor:v,isAdmin:f,isLoading:c.isLoading,error:c.error,disconnectPending:d.isPending,disconnectError:d.error,onDisconnect:S})]})}function qts({title:e,description:t,errorBanner:n,children:r}){return o.jsx("div",{"data-testid":"login-page",className:"flex min-h-screen items-center justify-center bg-surface1",children:o.jsxs("div",{className:"w-full max-w-sm space-y-6",children:[o.jsxs("div",{className:"flex flex-col items-center space-y-2",children:[o.jsx(Qh,{className:"h-10 w-10"}),o.jsx("h1",{className:"text-xl font-semibold text-neutral6",children:e})]}),t,n,r]})})}function D9t({redirectUri:e,onSuccess:t,initialMode:n="signin",errorMessage:r}){const{data:s,isLoading:a}=ac(),{mutate:i,isPending:l,error:c}=u1r(),{mutate:u,isPending:d,error:f}=f1r(),{mutate:p,isPending:h}=xNt(),[m,v]=g.useState(n),[y,b]=g.useState(""),[S,w]=g.useState(""),[k,_]=g.useState("");if(a)return o.jsx("div",{className:"flex min-h-screen items-center justify-center bg-surface1",children:o.jsx("div",{className:"text-neutral3",children:"Loading..."})});if(!s?.enabled||!s?.login)return o.jsx("div",{className:"flex min-h-screen items-center justify-center bg-surface1",children:o.jsx("div",{className:"text-neutral3",children:"Authentication is not configured"})});const{login:C}=s,E=C.type==="sso"||C.type==="both",j=C.type==="credentials"||C.type==="both",N=C.sso,I=C.signUpEnabled!==!1,R=m==="signin"||!I,P=R?l:d,L=R?c:f,M=()=>{t?t():e?window.location.href=e:window.location.href="/"},q=D=>{D.preventDefault(),R?i({email:S,password:k},{onSuccess:M}):u({email:S,password:k,name:y||void 0},{onSuccess:M})},H=()=>{p({redirectUri:e},{onSuccess:D=>{window.location.href=D.url}})},F=()=>{v(R?"signup":"signin")},z=C.description?o.jsxs("div",{className:"flex items-start gap-2.5 rounded-md border border-border1 bg-surface1 p-3",children:[o.jsx(yf,{className:"mt-0.5 h-4 w-4 shrink-0 text-neutral4"}),o.jsx("p",{className:"text-sm text-neutral3",children:C.description})]}):null,B=r?o.jsx("div",{className:"rounded-md bg-red-500/10 p-3 text-sm text-red-400",children:r}):null;return o.jsxs(qts,{title:R?"Sign in to Mastra Studio":"Create your account",description:z,errorBanner:B,children:[j&&o.jsxs("form",{onSubmit:q,className:"space-y-4",children:[!R&&o.jsxs("div",{className:"space-y-2",children:[o.jsx("label",{htmlFor:"name",className:"block text-sm text-neutral4",children:"Name"}),o.jsx(kn,{id:"name",type:"text",value:y,onChange:D=>b(D.target.value),placeholder:"Your name",variant:"default",size:"lg"})]}),o.jsxs("div",{className:"space-y-2",children:[o.jsx("label",{htmlFor:"email",className:"block text-sm text-neutral4",children:"Email"}),o.jsx(kn,{id:"email",type:"email",value:S,onChange:D=>w(D.target.value),placeholder:"you@example.com",required:!0,variant:"default",size:"lg"})]}),o.jsxs("div",{className:"space-y-2",children:[o.jsx("label",{htmlFor:"password",className:"block text-sm text-neutral4",children:"Password"}),o.jsx(kn,{id:"password",type:"password",value:k,onChange:D=>_(D.target.value),placeholder:R?"Enter your password":"Create a password",required:!0,variant:"default",size:"lg"})]}),L&&o.jsx("div",{className:"rounded-md bg-red-500/10 p-3 text-sm text-red-400",children:L.message}),o.jsx(de,{type:"submit",disabled:P,className:"w-full",size:"lg",children:P?R?"Signing in...":"Creating account...":R?"Sign in":"Create account"}),I&&o.jsxs("div",{className:"text-center text-sm",children:[o.jsx("span",{className:"text-neutral3",children:R?"Don't have an account? ":"Already have an account? "}),o.jsx("button",{type:"button",onClick:F,className:"text-neutral6 hover:underline",children:R?"Sign up":"Sign in"})]})]}),E&&j&&o.jsxs("div",{className:"relative",children:[o.jsx("div",{className:"absolute inset-0 flex items-center",children:o.jsx("div",{className:"w-full border-t border-border1"})}),o.jsx("div",{className:"relative flex justify-center text-sm",children:o.jsx("span",{className:"bg-surface1 px-2 text-neutral3",children:"or continue with"})})]}),E&&N&&o.jsxs(de,{onClick:H,disabled:h,className:"w-full",size:"lg",variant:"outline",children:[N.icon&&o.jsx("span",{className:"mr-2",children:N.icon}),h?"Redirecting...":N.text||"Sign in"]})]})}function Vts(){const[e]=ga(),t=bs(),n=e.get("redirect")||"/",s=e.get("mode")==="signup"?"signup":"signin",a=e.get("error_description")||e.get("error")||null,i=()=>{n.startsWith("http")?window.location.href=n:t(n,{replace:!0})};return o.jsx(D9t,{redirectUri:n,onSuccess:i,initialMode:s,errorMessage:a})}const Kf=Mi.KeyValueList;function Hts(e){return e instanceof Date?e:new Date(e)}function Wts({log:e,onClose:t,onTraceClick:n,onSpanClick:r,onPrevious:s,onNext:a,collapsed:i,onCollapsedChange:l}){const[c,u]=g.useState(!1),d=i??c,f=l??u,p=Hts(e.timestamp),h=e.traceId,m=e.spanId;return o.jsxs(Mi,{collapsed:d,children:[o.jsxs(Mi.Header,{children:[o.jsxs(Mi.Heading,{children:["Log ",o.jsx("b",{children:er(p,"MMM dd, HH:mm:ss.SSS")})]}),o.jsxs(Mr,{className:"ml-auto shrink-0",children:[l&&o.jsx(de,{size:"md",tooltip:d?"Expand panel":"Collapse panel",onClick:()=>f(!d),children:d?o.jsx(Qq,{}):o.jsx(Mxe,{})}),o.jsxs(Mr,{spacing:"close",children:[o.jsx(de,{size:"md",tooltip:"Previous log",onClick:s,disabled:!s,children:o.jsx(Gq,{})}),o.jsx(de,{size:"md",tooltip:"Next log",onClick:a,disabled:!a,children:o.jsx(Wq,{})})]}),o.jsx(Mi.CloseButton,{onClick:t})]})]}),!d&&o.jsxs(Mi.Content,{children:[o.jsx("p",{className:"text-ui-md text-neutral4 font-mono wrap-break-word whitespace-pre-wrap",children:e.message}),(h||m)&&o.jsxs("div",{className:K("grid gap-2 my-8","[&>button]:justify-between [&>button]:overflow-hidden"),children:[h&&o.jsxs(Mr,{spacing:"close",className:"min-w-0 w-full",children:[o.jsxs(de,{size:"md",className:"min-w-0 flex-1 overflow-hidden",onClick:()=>n?.(h),children:[o.jsx($z,{}),o.jsx("span",{children:"Trace"}),o.jsxs("span",{className:" ml-auto text-ui-sm text-neutral2 min-w-0 truncate",children:["# ",h]})]}),o.jsx(Oa,{content:h,size:"md",tooltip:"Copy Trace ID to clipboard"})]}),m&&o.jsxs(Mr,{spacing:"close",className:"min-w-0 w-full",children:[o.jsxs(de,{size:"md",className:"min-w-0 flex-1 overflow-hidden",disabled:!h||!r,onClick:()=>h&&r?.(h,m),children:[o.jsx($z,{}),o.jsx("span",{children:"Span"}),o.jsxs("span",{className:" ml-auto text-ui-sm text-neutral2 min-w-0 truncate",children:["# ",m]})]}),o.jsx(Oa,{content:m,size:"md",tooltip:"Copy Span ID to clipboard"})]})]}),o.jsxs(Kf,{className:"mb-6",children:[e.entityType&&o.jsxs(o.Fragment,{children:[o.jsx(Kf.Key,{children:"Entity Type"}),o.jsx(Kf.Value,{children:e.entityType})]}),e.entityName&&o.jsxs(o.Fragment,{children:[o.jsx(Kf.Key,{children:"Entity Name"}),o.jsx(Kf.Value,{children:e.entityName})]}),e.serviceName&&o.jsxs(o.Fragment,{children:[o.jsx(Kf.Key,{children:"Service"}),o.jsx(Kf.Value,{children:e.serviceName})]}),e.environment&&o.jsxs(o.Fragment,{children:[o.jsx(Kf.Key,{children:"Environment"}),o.jsx(Kf.Value,{children:e.environment})]}),e.source&&o.jsxs(o.Fragment,{children:[o.jsx(Kf.Key,{children:"Source"}),o.jsx(Kf.Value,{children:e.source})]}),e.metadata&&Object.keys(e.metadata).length>0&&o.jsx(o.Fragment,{children:Object.entries(e.metadata).map(([v,y])=>o.jsxs(g.Fragment,{children:[o.jsx(Kf.Key,{children:v}),o.jsx(Kf.Value,{children:String(y)})]},v))})]}),e.data&&Object.keys(e.data).length>0&&o.jsx(Mi.CodeSection,{title:"Data",codeStr:JSON.stringify(e.data,null,2),className:"mt-6"})]})]})}function Zts({error:e,resource:t,errorTitle:n}){if(gs(e))return o.jsx(Vs,{});if(ys(e))return o.jsx(Ds,{resource:t});if(hTt(e,"logs"))return o.jsx(Cr,{iconSlot:o.jsx(Yq,{}),titleSlot:"Logs are not available with your current storage",descriptionSlot:"The configured observability storage provider does not support listing logs. Switch to a storage provider with logs support to view runtime logs in Studio."});const r=e instanceof Error?e.message:void 0;return o.jsx(zi,{title:n,message:r??"Unknown error"})}function Gts({listSlot:e,logPanelSlot:t,tracePanelSlot:n,spanPanelSlot:r,logCollapsed:s}){const a=!!t;return o.jsxs("div",{className:K("grid h-full min-h-0 gap-4 items-start",a?"grid-cols-[1fr_1fr]":"grid-cols-[1fr]"),children:[e,a&&o.jsxs("div",{className:K("grid gap-4 h-full overflow-auto",n&&r?s?"grid-rows-[auto_1fr_1fr]":"grid-rows-[1fr_1fr_1fr]":n?s?"grid-rows-[auto_1fr]":"grid-rows-[1fr_1fr]":s?"grid-rows-[auto]":"grid-rows-[1fr]"),children:[t,n,r]})]})}const Qts={debug:{label:"DEBUG",color:"#71717a"},info:{label:"INFO",color:"#60a5fa"},warn:{label:"WARN",color:"#facc15"},error:{label:"ERROR",color:"#f87171"},fatal:{label:"FATAL",color:"#dc2626"}};function Yts({level:e}){const t=Qts[e];return o.jsx(ko,{height:"compact",children:o.jsx("span",{className:"uppercase text-ui-sm font-semibold",style:{color:t.color},children:t.label})})}function Xts({entityType:e,className:t}){const n=K("size-3.5 shrink-0 text-neutral2",t);switch(e.toLowerCase()){case Os.AGENT:return o.jsx(sl,{className:n,"aria-hidden":!0});case"workflow":case Os.WORKFLOW_RUN:return o.jsx(jd,{className:n,"aria-hidden":!0});case Os.TOOL:return o.jsx(eh,{className:n,"aria-hidden":!0});default:return null}}function Kts({entityType:e,entityName:t}){const n=e??"";return o.jsxs(ko,{height:"compact",className:"flex min-w-0 items-center gap-2",children:[o.jsx(Xts,{entityType:n}),t?o.jsx("span",{className:"min-w-0 text-ui-smd truncate",children:t}):"-"]})}function Jts({message:e}){return o.jsx(ko,{height:"compact",className:"text-neutral4 text-ui-smd min-w-0 truncate font-mono",children:e})}function ens({data:e}){if(!e||Object.keys(e).length===0)return o.jsx(ko,{height:"compact",children:null});const t=Object.entries(e).map(([n,r])=>{if(typeof r=="string")return`${n}: ${r}`;try{return`${n}: ${JSON.stringify(r)}`}catch{return`${n}: <unserializable>`}}).join(", ");return o.jsx(X1e,{children:t})}const Ul=Object.assign(k3,{Top:tH,TopCell:$_,TopCellWithTooltip:nH,TopCellSmart:G1t,RowWrapper:nSe,RowButton:O3,RowLink:Q1t,Spacer:tSe,NoMatch:eH,DateCell:K1e,TimeCell:J1e,LevelCell:Yts,EntityCell:Kts,MessageCell:Jts,DataCell:ens,NextPageLoading:JV}),zQe="6rem 9rem 5rem 10rem minmax(8rem,1fr) minmax(8rem,1fr)",tns=36,nns=8;function rns({logs:e,isLoading:t,isFetchingNextPage:n,hasNextPage:r,setEndOfListElement:s,logIdMap:a,featuredLogId:i,onLogClick:l}){const c=g.useRef(null),u=y9t({count:e.length,getScrollElement:()=>c.current,estimateSize:()=>tns,overscan:nns}),d=g.useRef(t);if(g.useEffect(()=>{d.current&&!t&&c.current?.dispatchEvent(new Event("scroll")),d.current=t},[t]),t)return o.jsx(tl,{columns:zQe});const f=u.getVirtualItems(),p=u.getTotalSize(),h=f[0]?.start??0,m=f.length>0?Math.max(0,p-(f[f.length-1]?.end??0)):0;return o.jsxs(Ul,{columns:zQe,variant:"striped",scrollRef:c,className:"min-w-0",children:[o.jsxs(Ul.Top,{children:[o.jsx(Ul.TopCell,{children:"Date"}),o.jsx(Ul.TopCell,{children:"Time"}),o.jsx(Ul.TopCell,{children:"Level"}),o.jsx(Ul.TopCell,{children:"Entity"}),o.jsx(Ul.TopCell,{children:"Message"}),o.jsx(Ul.TopCell,{children:"Data"})]}),e.length===0?o.jsx(Ul.NoMatch,{message:"No logs match your search"}):o.jsxs(o.Fragment,{children:[o.jsx(Ul.Spacer,{height:h}),f.map(v=>{const y=e[v.index];if(!y)return null;const b=a.get(y);if(!b)return null;const S=b===i;return o.jsxs(Ul.RowButton,{ref:u.measureElement,"data-index":v.index,onClick:()=>l(y),featured:S,variant:y.level==="error"||y.level==="fatal"?"error":"default",children:[o.jsx(Ul.DateCell,{timestamp:y.timestamp}),o.jsx(Ul.TimeCell,{timestamp:y.timestamp}),o.jsx(Ul.LevelCell,{level:y.level}),o.jsx(Ul.EntityCell,{entityType:y.entityType,entityName:y.entityName}),o.jsx(Ul.MessageCell,{message:y.message}),o.jsx(Ul.DataCell,{data:y.data})]},b)}),o.jsx(Ul.Spacer,{height:m})]}),o.jsx(Ul.NextPageLoading,{isLoading:n,hasMore:r,setEndOfListElement:s})]})}function sns({onClear:e,onRemoveAll:t,onSave:n,onRemoveSaved:r,isLoading:s,filterFields:a,filterTokens:i,onFilterTokensChange:l,autoFocusFilterFieldId:c}){const u=i.length>0,d=i.some(f=>ans(f,a));return o.jsxs("div",{className:K("grid grid-cols-[1fr_auto] gap-3 items-start"),children:[o.jsx(lTe,{fields:a,tokens:i,onTokensChange:l,disabled:s,autoFocusFieldId:c}),u&&o.jsx(iTe,{disabled:s,onClear:d?e:void 0,onRemoveAll:t,onSave:n,onRemoveSaved:r})]})}function ans(e,t){const n=t.find(r=>r.id===e.fieldId);return n?n.kind==="text"?typeof e.value=="string"&&e.value.trim()!=="":n.kind==="pick-multi"?n.multi?Array.isArray(e.value)&&e.value.length>0:typeof e.value=="string"&&e.value!==""&&e.value!=="Any":n.kind==="multi-select"?Array.isArray(e.value)&&e.value.length>0:!1:!1}const ins={"last-24h":"the last 24 hours","last-3d":"the last 3 days","last-7d":"the last 7 days","last-14d":"the last 14 days","last-30d":"the last 30 days"},tse="MMM d, yyyy HH:mm",nse="Pick a wider range or lower the logging level — verbose entries (debug, info) may be filtered out.";function ons({datePreset:e,dateFrom:t,dateTo:n}){return e&&e!=="all"&&e!=="custom"?{title:`No logs for ${ins[e]}`,description:nse}:t&&n?{title:`No logs between ${er(t,tse)} and ${er(n,tse)}`,description:nse}:t?{title:`No logs since ${er(t,tse)}`,description:nse}:{title:"No logs yet",description:"Logs will appear here once agents, workflows, or tools are executed."}}const lns=({datePreset:e,dateFrom:t,dateTo:n}={})=>{const{title:r,description:s}=ons({datePreset:e,dateFrom:t,dateTo:n});return o.jsx("div",{className:"flex h-full items-center justify-center",children:o.jsx(Cr,{iconSlot:o.jsx(Yq,{}),titleSlot:r,descriptionSlot:s,actionSlot:o.jsxs(de,{variant:"ghost",as:"a",href:"https://mastra.ai/en/docs/observability/logging",target:"_blank",rel:"noopener noreferrer",children:["Logging Documentation ",o.jsx(Dxe,{})]})})})},cns=20,uns=1e4;function dns(e,t,n){if(e?.pagination?.hasMore)return n+1}function fns(e){const t=new Set,n=[];for(const r of e.pages)for(const s of r.logs??[]){const a=s.logId??JSON.stringify(s);t.has(a)||(t.add(a),n.push(s))}return n}function pns(e){return hTt(e.state.error,"logs")?!1:uns}const hns=({filters:e}={})=>{const t=We(),{inView:n,setRef:r}=A_(),s=$1({queryKey:["logs",e],queryFn:({pageParam:p})=>t.listLogsVNext({pagination:{page:p,perPage:cns},filters:e,orderBy:{field:"timestamp",direction:"DESC"}}),initialPageParam:0,getNextPageParam:dns,select:fns,retry:!1,refetchInterval:pns}),{hasNextPage:a,isFetchingNextPage:i,fetchNextPage:l,data:c,isLoading:u,isError:d,error:f}=s;return g.useEffect(()=>{n&&a&&!i&&l()},[n,a,i,l]),{data:c,hasNextPage:a,isFetchingNextPage:i,fetchNextPage:l,isLoading:u,isError:d,error:f,setEndOfListElement:r}},oF={AGENT:Os.AGENT,WORKFLOW:Os.WORKFLOW_RUN,SCORER:Os.SCORER,INGEST:Os.RAG_INGESTION},L9t=[{label:"Agent",entityType:oF.AGENT},{label:"Workflow",entityType:oF.WORKFLOW},{label:"Scorer",entityType:oF.SCORER},{label:"Ingest",entityType:oF.INGEST}],mns=[{label:"Debug",value:"debug"},{label:"Info",value:"info"},{label:"Warn",value:"warn"},{label:"Error",value:"error"},{label:"Fatal",value:"fatal"}],Dx="rootEntityType",qb="datePreset",Vb="dateFrom",Hb="dateTo",gns=new Set(["all","last-24h","last-3d","last-7d","last-14d","last-30d","custom"]),_l={level:"filterLevel",tags:"filterTags",entityName:"filterEntityName",traceId:"filterTraceId",spanId:"filterSpanId",runId:"filterRunId",threadId:"filterThreadId",sessionId:"filterSessionId",requestId:"filterRequestId",resourceId:"filterResourceId",userId:"filterUserId",organizationId:"filterOrganizationId",serviceName:"filterServiceName",environment:"filterEnvironment",experimentId:"filterExperimentId"},X4=Object.keys(_l),_Te=new Set(["tags"]),CTe="mastra:logs:saved-filters";function vns(e,t=CTe){const n=Sns(e),r=e.get(qb);r&&n.set(qb,r);const s=e.get(Vb);s&&n.set(Vb,s);const a=e.get(Hb);a&&n.set(Hb,a);try{localStorage.setItem(t,n.toString())}catch{}}function yns(e=CTe){try{localStorage.removeItem(e)}catch{}}function BQe(e=CTe){try{const t=localStorage.getItem(e);if(!t)return null;const n=new URLSearchParams(t);return n.toString()?n:null}catch{return null}}function bns(e){if(e.has(qb)||e.has(Vb)||e.has(Hb)||e.has(Dx))return!0;for(const t of X4)if(e.has(_l[t]))return!0;return!1}function xns({availableTags:e,availableRootEntityNames:t,availableServiceNames:n,availableEnvironments:r,loading:s}){const a=[{id:"rootEntityType",label:"Primitive Type",kind:"pick-multi",searchable:!1,options:L9t.map(u=>({label:u.label,value:u.entityType})),placeholder:"Choose entity type",emptyText:"No entity types."},{id:"entityName",label:"Primitive Name",kind:"pick-multi",options:t.map(u=>({label:u,value:u})),placeholder:"Choose entity names",emptyText:"No entity names found.",isLoading:s?.entityNames},{id:"level",label:"Level",kind:"pick-multi",searchable:!1,options:mns.map(u=>({label:u.label,value:u.value})),placeholder:"Choose level",emptyText:"No levels."},{id:"tags",label:"Tags",kind:"pick-multi",multi:!0,options:e.map(u=>({label:u,value:u})),placeholder:"Choose tags",emptyText:"No tags found.",isLoading:s?.tags},{id:"serviceName",label:"Service Name",kind:"pick-multi",options:n.map(u=>({label:u,value:u})),placeholder:"Choose service names",emptyText:"No service names found.",isLoading:s?.serviceNames},{id:"environment",label:"Environment",kind:"pick-multi",options:r.map(u=>({label:u,value:u})),placeholder:"Choose environments",emptyText:"No environments found.",isLoading:s?.environments},{id:"traceId",label:"Trace ID",kind:"text"},{id:"spanId",label:"Span ID",kind:"text"},{id:"runId",label:"Run ID",kind:"text"},{id:"threadId",label:"Thread ID",kind:"text"},{id:"sessionId",label:"Session ID",kind:"text"},{id:"requestId",label:"Request ID",kind:"text"},{id:"resourceId",label:"Resource ID",kind:"text"},{id:"userId",label:"User ID",kind:"text"},{id:"organizationId",label:"Organization ID",kind:"text"},{id:"experimentId",label:"Experiment ID",kind:"text"}],i=(u,d)=>u.label.localeCompare(d.label),l=a.filter(u=>u.kind==="pick-multi").sort(i),c=a.filter(u=>u.kind==="text").sort(i);return[...l,...c]}function wns(e){const t=[],n=new Map([[Dx,"rootEntityType"]]);for(const s of X4)n.set(_l[s],s);const r=new Set;for(const[s]of e.entries()){const a=n.get(s);if(!a||r.has(a))continue;if(r.add(a),_Te.has(a)){const l=e.getAll(s);if(l.length===0)continue;t.push({fieldId:a,value:l.filter(Boolean)});continue}const i=e.get(s);i!==null&&t.push({fieldId:a,value:i})}return t}function Sns(e){const t=new URLSearchParams,n=e.get(Dx);n&&t.set(Dx,n);for(const r of X4){const s=_l[r];if(_Te.has(r)){for(const i of e.getAll(s))t.append(s,i);continue}const a=e.get(s);a&&t.set(s,a)}return t}function kns(e,t){e.delete(Dx);for(const n of X4)e.delete(_l[n]);for(const n of t){if(n.fieldId==="rootEntityType"&&typeof n.value=="string"){e.set(Dx,n.value);continue}const r=_l[n.fieldId];if(r){if(_Te.has(n.fieldId)&&Array.isArray(n.value)){if(n.value.length===0)e.append(r,"");else for(const s of n.value)e.append(r,s);continue}typeof n.value=="string"&&e.set(r,n.value.trim())}}}function Ons({rootEntityType:e,dateFrom:t,dateTo:n,tokens:r}){const s={};e&&(s.rootEntityType=e),(t||n)&&(s.timestamp={...t?{start:t}:{},...n?{end:n}:{}});for(const a of r){if(a.fieldId==="tags"){Array.isArray(a.value)&&a.value.length>0?s.tags=a.value:typeof a.value=="string"&&a.value.trim()&&(s.tags=[a.value.trim()]);continue}if(a.fieldId==="level"){typeof a.value=="string"&&a.value.trim()&&a.value!=="Any"&&(s.level=a.value);continue}if(typeof a.value=="string"&&a.value.trim()&&a.value!=="Any")switch(a.fieldId){case"entityName":s.rootEntityName=a.value;break;case"traceId":s.traceId=a.value;break;case"spanId":s.spanId=a.value;break;case"runId":s.runId=a.value;break;case"threadId":s.threadId=a.value;break;case"sessionId":s.sessionId=a.value;break;case"requestId":s.requestId=a.value;break;case"resourceId":s.resourceId=a.value;break;case"userId":s.userId=a.value;break;case"organizationId":s.organizationId=a.value;break;case"serviceName":s.serviceName=a.value;break;case"environment":s.environment=a.value;break;case"experimentId":s.experimentId=a.value;break}}return s}function _ns(e,t){return t.map(n=>{const r=e.find(s=>s.id===n.fieldId);return r?r.kind==="text"?{fieldId:n.fieldId,value:""}:r.kind==="pick-multi"?r.multi?{fieldId:n.fieldId,value:[]}:{fieldId:n.fieldId,value:"Any"}:n:n})}const Cns="Filters setting for Logs saved",Ens="Filters setting for Logs cleared up";function jns(e,t,n){const{storageKey:r,messages:s,skipHydration:a}={},[i,l]=g.useState(()=>BQe(r)!==null),c=g.useCallback(()=>{vns(e,r),l(!0);const f=s?.saved??Cns;f!==!1&&De.success(f)},[e,r,s?.saved]),u=g.useCallback(()=>{yns(r),l(!1);const f=s?.cleared??Ens;f!==!1&&De.success(f)},[r,s?.cleared]),d=g.useRef(!1);return g.useEffect(()=>{if(a||d.current||(d.current=!0,bns(e)))return;const f=BQe(r);f&&t(p=>{const h=new URLSearchParams(p);for(const[m,v]of f)h.append(m,v);return h},{replace:!0})},[]),{hasSavedFilters:i,handleSave:c,handleRemoveSaved:u}}function Tns(e){let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n)|0;return(t>>>0).toString(36)}function Nns(e){const t=new Map;for(const n of e){if(n.logId){t.set(n,n.logId);continue}const r=n.timestamp instanceof Date?n.timestamp.toISOString():n.timestamp;t.set(n,Tns(`${r}${n.message??""}${n.data?JSON.stringify(n.data):""}`))}return t}function Ins(e,t,n,r){const s=g.useMemo(()=>Nns(e),[e]),a=g.useMemo(()=>{const h=new Map;for(let m=0;m<e.length;m++){const v=s.get(e[m]);v&&h.set(v,{log:e[m],idx:m})}return h},[e,s]),l=(t?a.get(t):void 0)?.idx??-1,c=l>=0?e[l]:null,u=g.useCallback(h=>s.get(h),[s]),d=g.useCallback(h=>{const m=s.get(h);if(m){if(t===m){n({logId:null});return}n(r?{logId:m,traceId:h.traceId??null,spanId:null}:{logId:m})}},[s,t,r,n]),f=l>0?()=>{const h=e[l-1],m=s.get(h);m&&n(r?{logId:m,traceId:h.traceId??null,spanId:null}:{logId:m})}:void 0,p=l>=0&&l<e.length-1?()=>{const h=e[l+1],m=s.get(h);m&&n(r?{logId:m,traceId:h.traceId??null,spanId:null}:{logId:m})}:void 0;return{logIdMap:s,getLogId:u,featuredLog:c,handleLogClick:d,handlePreviousLog:f,handleNextLog:p}}const Vve="logId",Hve="traceId",Wve="spanId",DR=1440*60*1e3,Ans={"last-24h":DR,"last-3d":3*DR,"last-7d":7*DR,"last-14d":14*DR,"last-30d":30*DR};function lF(e){e.delete(Vve),e.delete(Hve),e.delete(Wve)}function Rns(e,t,n){const{onRemoveAll:r}={},s=g.useMemo(()=>{const _=e.get(qb);return _&&gns.has(_)?_:"last-24h"},[e]),a=e.get(Vb),i=e.get(Hb),l=g.useMemo(()=>{if(s==="custom"){if(!a)return;const C=new Date(a);return Number.isNaN(C.getTime())?void 0:C}if(s==="all")return;const _=Ans[s];return _?new Date(Date.now()-_):void 0},[s,a]),c=g.useMemo(()=>{if(s!=="custom"||!i)return;const _=new Date(i);return Number.isNaN(_.getTime())?void 0:_},[s,i]),u=g.useRef(s);u.current=s;const d=e.get(Vve),f=e.get(Hve),p=e.get(Wve),h=g.useMemo(()=>L9t.find(_=>_.entityType===e.get(Dx)),[e]),m=g.useMemo(()=>wns(e),[e]),v=g.useCallback(_=>{t(C=>{const E=new URLSearchParams(C);for(const[j,N]of Object.entries(_)){const I=j==="logId"?Vve:j==="traceId"?Hve:Wve;N?E.set(I,N):E.delete(I)}return E},{replace:!0})},[t]),y=g.useCallback(_=>{t(C=>{const E=new URLSearchParams(C);return kns(E,_),lF(E),E},{replace:!0})},[t]),b=y,S=g.useCallback((_,C)=>{if(u.current!=="custom")return;const E=C==="from"?Vb:Hb;t(j=>{const N=new URLSearchParams(j);return _?N.set(E,_.toISOString()):N.delete(E),lF(N),N},{replace:!0})},[t]),w=g.useCallback(_=>{u.current=_,t(C=>{const E=new URLSearchParams(C);return _==="last-24h"?(E.delete(qb),E.delete(Vb),E.delete(Hb)):_==="custom"?E.set(qb,"custom"):(E.set(qb,_),E.delete(Vb),E.delete(Hb)),lF(E),E},{replace:!0})},[t]),k=g.useCallback(()=>{t(_=>{const C=new URLSearchParams(_);C.delete(Dx);for(const E of X4)C.delete(_l[E]);return C.delete(qb),C.delete(Vb),C.delete(Hb),lF(C),C},{replace:!0}),r?.()},[t,r]);return g.useMemo(()=>({searchParams:e,setSearchParams:t,datePreset:s,selectedDateFrom:l,selectedDateTo:c,datePresetRef:u,featuredLogId:d,featuredTraceId:f,featuredSpanId:p,selectedEntityOption:h,filterTokens:m,handleFeaturedChange:v,handleFilterTokensChange:b,handleDateChange:S,handleDatePresetChange:w,handleRemoveAll:k,applyFilterTokens:y}),[e,t,s,l,c,u,d,f,p,h,m,v,b,S,w,k,y])}const wb=Mi.KeyValueList;function Pns({spanId:e,span:t,isLoading:n,onClose:r}){const s=t?.startedAt&&t?.endedAt?new Date(t.endedAt).getTime()-new Date(t.startedAt).getTime():null;return o.jsxs(Mi,{children:[o.jsxs(Mi.Header,{children:[o.jsxs(Mi.Heading,{children:["Span ",o.jsxs("b",{children:["# ",e]})]}),o.jsx(Mi.CloseButton,{onClick:r})]}),n?o.jsx(Mi.LoadingData,{children:"Loading span..."}):t?o.jsxs(Mi.Content,{children:[o.jsxs(wb,{children:[t.spanType&&o.jsxs(o.Fragment,{children:[o.jsx(wb.Key,{children:"Type"}),o.jsx(wb.Value,{children:t.spanType})]}),t.startedAt&&o.jsxs(o.Fragment,{children:[o.jsx(wb.Key,{children:"Started"}),o.jsx(wb.Value,{children:er(new Date(t.startedAt),"MMM dd, HH:mm:ss.SSS")})]}),t.endedAt&&o.jsxs(o.Fragment,{children:[o.jsx(wb.Key,{children:"Ended"}),o.jsx(wb.Value,{children:er(new Date(t.endedAt),"MMM dd, HH:mm:ss.SSS")})]}),s!=null&&o.jsxs(o.Fragment,{children:[o.jsx(wb.Key,{children:"Duration"}),o.jsx(wb.Value,{children:s<1e3?`${s}ms`:`${(s/1e3).toFixed(2)}s`})]})]}),o.jsx("br",{}),o.jsx(Mi.CodeSection,{title:"Input",icon:o.jsx(Dfe,{}),codeStr:JSON.stringify(t.input??null,null,2)}),o.jsx(Mi.CodeSection,{title:"Output",icon:o.jsx(Lfe,{}),codeStr:JSON.stringify(t.output??null,null,2)}),o.jsx(Mi.CodeSection,{title:"Metadata",icon:o.jsx(hw,{}),codeStr:JSON.stringify(t.metadata??null,null,2)}),o.jsx(Mi.CodeSection,{title:"Attributes",icon:o.jsx(hw,{}),codeStr:JSON.stringify(t.attributes??null,null,2)})]}):o.jsx(Mi.NoData,{children:"Span not found."})]})}function $ns(){const[e,t]=ga(),n=Rns(e,t),r=jns(e,t),[s,a]=g.useState(),[i,l]=g.useState(!1),{data:c=[],isPending:u}=gTe(),{data:d=[],isPending:f}=pTe({entityType:n.selectedEntityOption?.entityType,rootOnly:!0}),{data:p=[],isPending:h}=hTe(),{data:m=[],isPending:v}=mTe(),y=g.useMemo(()=>xns({availableTags:c,availableRootEntityNames:d,availableServiceNames:m,availableEnvironments:p,loading:{tags:u,entityNames:f,serviceNames:v,environments:h}}),[c,d,m,p,u,f,v,h]),b=g.useMemo(()=>Ons({rootEntityType:n.selectedEntityOption?.entityType,dateFrom:n.selectedDateFrom,dateTo:n.selectedDateTo,tokens:n.filterTokens}),[n.filterTokens,n.selectedDateFrom,n.selectedDateTo,n.selectedEntityOption]),{data:S=[],isLoading:w,error:k,isFetchingNextPage:_,hasNextPage:C,setEndOfListElement:E}=hns({filters:b}),{logIdMap:j,featuredLog:N,handleLogClick:I,handlePreviousLog:R,handleNextLog:P}=Ins(S,n.featuredLogId,n.handleFeaturedChange,n.featuredTraceId),{data:L,isLoading:M}=ZH(n.featuredTraceId??null),{data:q,isLoading:H}=oI(n.featuredTraceId??"",n.featuredSpanId??""),F=g.useCallback(()=>n.applyFilterTokens(_ns(y,n.filterTokens)),[y,n]),z=g.useCallback(()=>n.handleFeaturedChange({logId:null}),[n]),B=g.useCallback(X=>n.handleFeaturedChange({traceId:X,spanId:null}),[n]),D=g.useCallback((X,te)=>n.handleFeaturedChange({traceId:X,spanId:te}),[n]),Q=g.useCallback(()=>{n.handleFeaturedChange({traceId:null,spanId:null}),l(!1)},[n]),V=g.useCallback(()=>n.handleFeaturedChange({spanId:null}),[n]),$=g.useCallback(X=>n.handleFeaturedChange({spanId:X??null}),[n]),U=o.jsxs(Lt.TopArea,{children:[o.jsx(Lt.Row,{children:o.jsxs(Lt.Column,{className:"flex flex-wrap items-start justify-start gap-2",children:[o.jsx(aTe,{preset:n.datePreset,onPresetChange:n.handleDatePresetChange,dateFrom:n.selectedDateFrom,dateTo:n.selectedDateTo,onDateChange:n.handleDateChange,disabled:w,presets:["last-24h","last-3d","last-7d","last-14d","last-30d","custom"]}),o.jsx(cTe,{fields:y,tokens:n.filterTokens,onTokensChange:n.handleFilterTokensChange,disabled:w,onStartTextFilter:a})]})}),o.jsx(sns,{isLoading:w,filterFields:y,filterTokens:n.filterTokens,onFilterTokensChange:n.handleFilterTokensChange,onClear:F,onRemoveAll:n.handleRemoveAll,onSave:r.handleSave,onRemoveSaved:r.hasSavedFilters?r.handleRemoveSaved:void 0,autoFocusFilterFieldId:s})]});if(k)return o.jsxs(Lt,{width:"wide",height:"full",children:[U,o.jsx(Lt.MainArea,{isCentered:!0,children:o.jsx(Zts,{error:k,resource:"logs",errorTitle:"Failed to load logs"})})]});const Z=!!n.selectedEntityOption||n.filterTokens.length>0;return S.length===0&&!w&&!Z?o.jsxs(Lt,{width:"wide",height:"full",children:[U,o.jsx(Lt.MainArea,{isCentered:!0,children:o.jsx(lns,{datePreset:n.datePreset,dateFrom:n.selectedDateFrom,dateTo:n.selectedDateTo})})]}):o.jsxs(Lt,{width:"wide",height:"full",children:[U,o.jsx(Gts,{logCollapsed:i,listSlot:o.jsx(rns,{logs:S,isLoading:w,isFetchingNextPage:_,hasNextPage:C,setEndOfListElement:E,logIdMap:j,featuredLogId:n.featuredLogId,onLogClick:I}),logPanelSlot:N?o.jsx(Wts,{log:N,onClose:z,onTraceClick:B,onSpanClick:D,onPrevious:R,onNext:P,collapsed:i,onCollapsedChange:l}):null,tracePanelSlot:n.featuredTraceId?o.jsx($Et,{traceId:n.featuredTraceId,spans:L?.spans,isLoading:M,onClose:Q,onSpanSelect:$,selectedSpanId:n.featuredSpanId}):null,spanPanelSlot:n.featuredTraceId&&n.featuredSpanId?o.jsx(Pns,{spanId:n.featuredSpanId,span:q?.span,isLoading:H,onClose:V}):null})]})}function Mns({server:e}){const{paths:t,Link:n}=yn(),s=We().options.baseUrl,a=s?`${s}/api/mcp/${e.id}/sse`:"",{data:i}=M5t(e),l=Object.values(i||{}),c=l.length,u=l.filter(p=>p.toolType==="agent").length,d=l.filter(p=>p.toolType==="workflow").length,f=fm(e.name,50);return o.jsxs(me.RowLink,{to:t.mcpServerLink(e.id),LinkComponent:n,children:[o.jsx(me.NameCell,{children:f}),o.jsx(me.DescriptionCell,{children:a}),o.jsx(me.TextCell,{className:"text-center",children:u||""}),o.jsx(me.TextCell,{className:"text-center",children:c||""}),o.jsx(me.TextCell,{className:"text-center",children:d||""})]})}function Dns({mcpServers:e,isLoading:t,search:n=""}){const r=g.useMemo(()=>{const s=n.toLowerCase();return e.filter(a=>a.name?.toLowerCase().includes(s)||a.id?.toLowerCase().includes(s))},[e,n]);return t?o.jsx(tl,{columns:"auto 1fr auto auto auto"}):o.jsxs(me,{columns:"auto 1fr auto auto auto",variant:"striped",children:[o.jsxs(me.Top,{children:[o.jsx(me.TopCell,{children:"Name"}),o.jsx(me.TopCell,{children:"URL"}),o.jsx(me.TopCellSmart,{long:"Agents",short:o.jsx(sl,{}),tooltip:"Agent Tools",className:"text-center"}),o.jsx(me.TopCellSmart,{long:"Tools",short:o.jsx(eh,{}),tooltip:"Tools",className:"text-center"}),o.jsx(me.TopCellSmart,{long:"Workflows",short:o.jsx(jd,{}),tooltip:"Workflow Tools",className:"text-center"})]}),r.length===0&&n?o.jsx(me.NoMatch,{message:"No MCP Servers match your search"}):null,r.map(s=>o.jsx(Mns,{server:s},s.id))]})}const Lns=()=>o.jsx("div",{className:"flex h-full items-center justify-center",children:o.jsx(Cr,{iconSlot:o.jsx(Of,{}),titleSlot:"No MCP Servers yet",descriptionSlot:o.jsxs(o.Fragment,{children:["MCP servers are not configured yet. ",o.jsx("br",{}),"More information in the documentation."]}),actionSlot:o.jsxs(de,{variant:"ghost",as:"a",href:"https://mastra.ai/docs/tools-mcp/mcp-overview",target:"_blank",rel:"noopener noreferrer",children:["MCP Documentation ",o.jsx(_a,{})]})})}),Fns=()=>{const{data:e=[],isLoading:t,error:n}=MZ(),[r,s]=g.useState("");return n&&gs(n)?o.jsx(lr,{children:o.jsx(Vs,{})}):n&&ys(n)?o.jsx(lr,{children:o.jsx(Ds,{resource:"MCP servers"})}):n?o.jsx(lr,{children:o.jsx(zi,{title:"Failed to load MCP servers",message:n.message})}):e.length===0&&!t?o.jsx(lr,{children:o.jsx(Lns,{})}):o.jsxs(Lt,{children:[o.jsx(Lt.TopArea,{children:o.jsx("div",{className:"max-w-120",children:o.jsx(jf,{onSearch:s,label:"Filter MCP servers",placeholder:"Filter by name"})})}),o.jsx(Dns,{mcpServers:e,isLoading:t,search:r})]})},zns=(e,t)=>{const n=new Map,r=Object.keys(t);for(const s of r){const a=t[s],i=a.tools,l=Object.keys(i);for(const c of l){const u=i[c];n.has(u.id)||n.set(u.id,{...u,agents:[]}),n.get(u.id).agents.push({...a,id:s})}}for(const[s,a]of Object.entries(e))n.has(a.id)||n.set(a.id,{...a,agents:[]});return Array.from(n.values())};function Bns({tools:e,agents:t,isLoading:n,search:r=""}){const{paths:s,Link:a}=yn(),i=g.useMemo(()=>zns(e,t),[e,t]),l=g.useMemo(()=>i.filter(c=>c.id.toLowerCase().includes(r.toLowerCase())),[i,r]);return n?o.jsx(tl,{columns:"auto 1fr auto"}):o.jsxs(me,{columns:"auto 1fr auto",variant:"striped",children:[o.jsxs(me.Top,{children:[o.jsx(me.TopCell,{children:"Name"}),o.jsx(me.TopCell,{children:"Description"}),o.jsx(me.TopCellSmart,{long:"Agents",short:o.jsx(sl,{}),tooltip:"Attached Agents",className:"text-center"})]}),l.length===0&&r?o.jsx(me.NoMatch,{message:"No Tools match your search"}):null,l.map(c=>{const u=fm(c.id,50),d=fm(c.description??"",200),f=c.agents.length;return o.jsxs(me.RowLink,{to:s.toolLink(c.id),LinkComponent:a,children:[o.jsx(me.NameCell,{children:u}),o.jsx(me.DescriptionCell,{children:d}),o.jsx(me.TextCell,{className:"text-center",children:f||""})]},c.id)})]})}const Uns=()=>o.jsx("div",{className:"flex h-full items-center justify-center",children:o.jsx(Cr,{iconSlot:o.jsx(Of,{}),titleSlot:"No Tools yet",descriptionSlot:o.jsxs(o.Fragment,{children:["Mastra tools are not configured yet. ",o.jsx("br",{}),"More information in the documentation."]}),actionSlot:o.jsxs(de,{variant:"ghost",as:"a",href:"https://mastra.ai/docs/agents/using-tools-and-mcp",target:"_blank",rel:"noopener noreferrer",children:["Tools Documentation ",o.jsx(_a,{})]})})}),qns=()=>{const e=We();return Rn({mutationFn:async({toolId:t,input:n,requestContext:r})=>{const s=new u_;Object.entries(r??{}).forEach(([a,i])=>{s.set(a,i)});try{return await e.getTool(t).execute({data:n,requestContext:s})}catch(a){throw De.error("Error executing dev tool"),console.error("Error executing dev tool:",a),a}}})},Vns=({toolId:e})=>{const{canExecute:t}=il(),n=t("tools"),{data:r={}}=km(),s=g.useMemo(()=>{for(const v of Object.values(r))if(v.tools){const y=Object.values(v.tools).find(b=>b.id===e);if(y)return y}return null},[r,e]),{data:a,isLoading:i,error:l}=G0r(e,{enabled:!s}),c=s||a,{mutateAsync:u,isPending:d,data:f}=qns(),{requestContext:p}=_s();g.useEffect(()=>{if(l){const v=l instanceof Error?l.message:"Failed to load tool";De.error(`Error loading tool: ${v}`)}},[l]);const h=async(v,y)=>{if(!c)return;const b={...p??{},...y??{}};return u({toolId:c.id,input:v,requestContext:b})},m=c?.inputSchema?lm(im(yx(c?.inputSchema))):Ss({});return i?o.jsxs("div",{className:"p-6",children:[o.jsx(bt,{className:"h-8 w-48 mb-4"}),o.jsx(bt,{className:"h-32 w-full"})]}):l?null:c?n?o.jsx(Hje,{executionResult:f,isExecutingTool:d,zodInputSchema:m,handleExecuteTool:h,toolDescription:c.description,toolId:c.id,requestContextSchema:c.requestContextSchema}):o.jsx("div",{className:"py-12 text-center px-6",children:o.jsx(ge,{variant:"ui-sm",className:"text-neutral3",children:"You don't have permission to execute tools."})}):o.jsx("div",{className:"py-12 text-center px-6",children:o.jsx(ge,{variant:"header-md",className:"text-neutral3",children:"Tool not found"})})};function Hns({value:e,onValueChange:t,placeholder:n="Select a tool...",searchPlaceholder:r="Search tools...",emptyText:s="No tools found.",className:a,disabled:i=!1,variant:l}){const{data:c={},isLoading:u,isError:d,error:f}=cI(),{data:p={},isLoading:h,isError:m,error:v}=km(),{navigate:y,paths:b}=yn();g.useEffect(()=>{if(d){const _=f instanceof Error?f.message:"Failed to load tools";De.error(`Error loading tools: ${_}`)}},[d,f]),g.useEffect(()=>{if(m){const _=v instanceof Error?v.message:"Failed to load agents";De.error(`Error loading agents: ${_}`)}},[m,v]);const S=new Map;Object.values(p).forEach(_=>{_.tools&&Object.values(_.tools).forEach(C=>{S.has(C.id)||S.set(C.id,C)})}),Object.values(c).forEach(_=>{S.has(_.id)||S.set(_.id,_)});const w=Array.from(S.values()).map(_=>({label:_.id,value:_.id})),k=_=>{t?t(_):_&&_!==e&&y(b.toolLink(_))};return o.jsx(Jl,{options:w,value:e,onValueChange:k,placeholder:u||h?"Loading tools...":n,searchPlaceholder:r,emptyText:s,className:a,disabled:i||u||h||d||m,variant:l})}const Wns=({isLoading:e,server:t})=>{const[{sseUrl:n,httpStreamUrl:r},s]=g.useState({sseUrl:"",httpStreamUrl:""});if(g.useEffect(()=>{if(!t)return;const i=window.MASTRA_SERVER_HOST,l=window.MASTRA_SERVER_PORT;let c=null;i&&l&&(c=`http://${i}:${l}`);const u=c||"http://localhost:4111",d=`${u}/api/mcp/${t.id}/sse`,f=`${u}/api/mcp/${t.id}/mcp`;s({sseUrl:d,httpStreamUrl:f})},[t]),e)return null;if(!t)return o.jsx(wy,{children:o.jsx(ge,{as:"h1",variant:"header-md",className:"text-neutral3 font-medium py-20 text-center",children:"Server not found"})});const a=`npx -y mcp-remote ${n}`;return o.jsxs(wy,{isDivided:!0,children:[o.jsxs("div",{className:"px-8 py-12 mx-auto max-w-2xl w-full",children:[o.jsx(ge,{as:"h1",variant:"header-md",className:"text-neutral6 font-medium pb-4",children:t.name}),o.jsxs("div",{className:"flex items-center gap-1 pb-6",children:[o.jsx(dn,{icon:o.jsx(_Et,{className:"text-neutral6"}),className:"rounded-r-sm text-neutral4!",children:"Version"}),o.jsx(dn,{className:"rounded-l-sm text-neutral4!",children:t.version_detail.version})]}),o.jsx(ge,{className:"text-neutral3 pb-4",children:"This MCP server can be accessed through multiple transport methods. Choose the one that best fits your use case."}),o.jsxs("div",{className:"flex flex-col gap-4",children:[o.jsxs("div",{className:"rounded-lg border border-border1 bg-surface3 p-4",children:[o.jsx(dn,{icon:o.jsx("span",{className:"font-mono w-6 text-accent1 font-medium mr-1",children:"HTTP"}),children:"Regular HTTP Endpoint"}),o.jsx(ge,{className:"text-neutral3 pt-1 pb-2",children:"Use for stateless HTTP transport with streamable responses."}),o.jsxs("div",{className:"flex items-start gap-2",children:[o.jsx(ge,{className:"px-2 py-1 bg-surface4 rounded-lg",children:r}),o.jsx("div",{className:"pt-1",children:o.jsx(Oa,{tooltip:"Copy HTTP Stream URL",content:r})})]})]}),o.jsxs("div",{className:"rounded-lg border border-border1 bg-surface3 p-4",children:[o.jsx(dn,{icon:o.jsx("span",{className:"font-mono w-6 text-accent1 font-medium mr-1",children:"SSE"}),children:"Server-Sent Events"}),o.jsx(ge,{className:"text-neutral3 pt-1 pb-2",children:"Use for real-time communication via SSE."}),o.jsxs("div",{className:"flex items-start gap-2",children:[o.jsx(ge,{className:"px-2 py-1 bg-surface4 rounded-lg",children:n}),o.jsx("div",{className:"pt-1",children:o.jsx(Oa,{tooltip:"Copy SSE URL",content:n})})]})]}),o.jsxs("div",{className:"rounded-lg border border-border1 bg-surface3 p-4",children:[o.jsx(dn,{icon:o.jsx("span",{className:"font-mono w-6 text-accent1 font-medium mr-1",children:"CLI"}),children:"Command Line"}),o.jsx(ge,{className:"text-neutral3 pt-1 pb-2",children:"Use for local command-line access via npx and mcp-remote."}),o.jsxs("div",{className:"flex items-start gap-2",children:[o.jsx(ge,{className:"px-2 py-1 bg-surface4 rounded-lg",children:a}),o.jsx("div",{className:"pt-1",children:o.jsx(Oa,{tooltip:"Copy Command Line Config",content:a})})]})]})]})]}),o.jsx("div",{className:"h-full overflow-y-scroll border-l border-border1",children:o.jsx(Zns,{server:t})})]})},Zns=({server:e})=>{const{data:t={},isLoading:n}=M5t(e);if(n)return null;const r=Object.keys(t);return o.jsxs("div",{className:"p-5 overflow-y-scroll",children:[o.jsxs("div",{className:"text-neutral6 flex gap-2 items-center",children:[o.jsx(Ue,{size:"lg",className:"bg-surface4 rounded-md p-1",children:o.jsx(B_,{})}),o.jsx(ge,{variant:"header-md",as:"h2",className:"font-medium",children:"Available Tools"})]}),o.jsx("div",{className:"flex flex-col gap-2 pt-6",children:r.map(s=>{const a=t[s];return o.jsx(Qns,{tool:a,serverId:e.id},s)})})]})};function Gns(e){if(!e)return!1;const t=e.ui;return!!(typeof t?.resourceUri=="string"&&t.resourceUri.startsWith("ui://")||typeof e["ui/resourceUri"]=="string"&&e["ui/resourceUri"].startsWith("ui://"))}const Qns=({tool:e,serverId:t})=>{const n=g.useRef(null),{Link:r,paths:s}=yn(),a=o6t[e.toolType||"tool"],i=Gns(e._meta);return o.jsxs(Nf,{onClick:()=>n.current?.click(),children:[o.jsx(QIt,{children:o.jsx(a,{className:"group-hover/entity:text-accent6"})}),o.jsxs(Af,{children:[o.jsx(If,{children:o.jsxs("span",{className:"flex items-center gap-2",children:[o.jsx(r,{ref:n,href:s.mcpServerToolLink(t,e.id),children:e.id}),i&&o.jsx(dn,{className:"text-[10px] py-0",children:"App"})]})}),o.jsx(th,{children:e.description})]})]})},Yns=()=>{const{serverId:e}=ur(),{data:t=[],isLoading:n}=MZ(),r=t.find(s=>s.id===e);return o.jsx("div",{className:"h-full w-full overflow-hidden",children:o.jsx(Wns,{isLoading:n,server:r})})};function Xns(e){if(!e)return;const t=e.ui;if(t?.resourceUri)return t.resourceUri;const n=e["ui/resourceUri"];if(typeof n=="string")return n}const Kns=({toolId:e,serverId:t})=>{const{canExecute:n}=il(),r=n("tools"),s=We(),{data:a,isLoading:i,error:l}=mje(t,e),{mutateAsync:c,isPending:u,data:d}=g7r(t,e),f=a?Xns(a._meta):void 0,{data:p}=wt({queryKey:["mcp-app-resource",t,f],queryFn:async()=>f?(await s.readMcpServerResource(t,f)).contents[0]?.text??null:null,enabled:!!f}),h=g.useCallback(async(y,b)=>await c(b),[c]);g.useEffect(()=>{if(l){const y=l instanceof Error?l.message:"Failed to load tool";De.error(`Error loading tool: ${y}`)}},[l]);const m=async y=>{if(a)return await c(y)};if(i)return o.jsxs("div",{className:"p-6",children:[o.jsx(bt,{className:"h-8 w-48 mb-4"}),o.jsx(bt,{className:"h-32 w-full"})]});if(l)return null;if(!a)return o.jsx("div",{className:"py-12 text-center px-6",children:o.jsx(ge,{variant:"header-md",className:"text-neutral3",children:"Tool not found"})});if(!r)return o.jsx("div",{className:"py-12 text-center px-6",children:o.jsx(ge,{variant:"ui-sm",className:"text-neutral3",children:"You don't have permission to execute tools."})});let v;try{v=lm(im(a.inputSchema))}catch(y){console.error("Error processing input schema:",y),De.error("Failed to process tool input schema."),v=Ss({})}return o.jsxs("div",{className:"flex flex-col gap-4",children:[p&&o.jsx("div",{className:"border-b border-border1 p-4",children:o.jsx($5t,{html:p,toolName:a.name??a.id,onToolCall:h})}),o.jsx(Hje,{executionResult:d,isExecutingTool:u,zodInputSchema:v,handleExecuteTool:m,toolDescription:a.description||"",toolId:a.id})]})},Jns=()=>{const{serverId:e,toolId:t}=ur(),{data:n,isLoading:r}=mje(e,t);return r||!n?null:o.jsx("div",{className:"h-full w-full overflow-y-auto",children:o.jsx(Kns,{toolId:t,serverId:e})})},F9t=[{label:"Agent",entityType:Os.AGENT},{label:"Workflow",entityType:Os.WORKFLOW_RUN},{label:"Scorer",entityType:Os.SCORER},{label:"Ingest",entityType:Os.RAG_INGESTION}],dN="rootEntityType",fN={tags:"filterTags",entityId:"filterEntityId",entityName:"filterEntityName",runId:"filterRunId",threadId:"filterThreadId",sessionId:"filterSessionId",requestId:"filterRequestId",resourceId:"filterResourceId",userId:"filterUserId",organizationId:"filterOrganizationId",serviceName:"filterServiceName",environment:"filterEnvironment",experimentId:"filterExperimentId",provider:"filterProvider",model:"filterModel"},eG=Object.keys(fN),ETe="mastra:metrics:saved-filters";function ers(e){const t=ars(e);try{localStorage.setItem(ETe,t.toString())}catch{}}function trs(){try{localStorage.removeItem(ETe)}catch{}}function z9t(){try{const e=localStorage.getItem(ETe);if(!e)return null;const t=new URLSearchParams(e);return t.toString()?t:null}catch{return null}}function nrs(e){if(e.has(dN))return!0;for(const t of eG)if(e.has(fN[t]))return!0;return!1}function rrs({availableTags:e,availableEntityNames:t,availableServiceNames:n,availableEnvironments:r,loading:s}){const a=[{id:"rootEntityType",label:"Primitive Type",kind:"pick-multi",searchable:!1,options:F9t.map(u=>({label:u.label,value:u.entityType})),placeholder:"Choose entity type",emptyText:"No entity types."},{id:"entityName",label:"Primitive Name",kind:"pick-multi",options:t.map(u=>({label:u,value:u})),placeholder:"Choose entity names",emptyText:"No entity names found.",isLoading:s?.entityNames},{id:"entityId",label:"Primitive ID",kind:"text"},{id:"tags",label:"Tags",kind:"pick-multi",multi:!0,options:e.map(u=>({label:u,value:u})),placeholder:"Choose tags",emptyText:"No tags found.",isLoading:s?.tags},{id:"serviceName",label:"Service Name",kind:"pick-multi",options:n.map(u=>({label:u,value:u})),placeholder:"Choose service names",emptyText:"No service names found.",isLoading:s?.serviceNames},{id:"environment",label:"Environment",kind:"pick-multi",options:r.map(u=>({label:u,value:u})),placeholder:"Choose environments",emptyText:"No environments found.",isLoading:s?.environments},{id:"threadId",label:"Thread ID",kind:"text"},{id:"resourceId",label:"Resource ID",kind:"text"},{id:"userId",label:"User ID",kind:"text"},{id:"organizationId",label:"Organization ID",kind:"text"},{id:"runId",label:"Run ID",kind:"text"},{id:"sessionId",label:"Session ID",kind:"text"},{id:"requestId",label:"Request ID",kind:"text"},{id:"experimentId",label:"Experiment ID",kind:"text"}],i=(u,d)=>u.label.localeCompare(d.label),l=a.filter(u=>u.kind==="pick-multi").sort(i),c=a.filter(u=>u.kind==="text").sort(i);return[...l,...c]}function srs(e){const t=[],n=new Map([[dN,"rootEntityType"]]);for(const s of eG)n.set(fN[s],s);const r=new Set;for(const[s]of e.entries()){const a=n.get(s);if(!a||r.has(a))continue;if(r.add(a),a==="tags"){const l=e.getAll(s);if(l.length===0)continue;t.push({fieldId:a,value:l.filter(Boolean)});continue}if(a==="rootEntityType"||a==="entityName"||a==="serviceName"||a==="environment"||a==="provider"||a==="model"){const l=e.getAll(s);if(l.length>1){t.push({fieldId:a,value:l});continue}}const i=e.get(s);i!==null&&t.push({fieldId:a,value:i})}return t}function ars(e){const t=new URLSearchParams,n=e.getAll(dN);for(const r of n)t.append(dN,r);for(const r of eG){const s=fN[r],a=e.getAll(s);for(const i of a)t.append(s,i)}return t}function irs(e,t){e.delete(dN);for(const n of eG)e.delete(fN[n]);for(const n of t){const r=n.fieldId==="rootEntityType"?dN:fN[n.fieldId];if(r)if(Array.isArray(n.value)){const s=n.value.filter(a=>typeof a=="string"&&a!=="");if(s.length===0){n.fieldId==="tags"&&e.append(r,"");continue}for(const a of s)e.append(r,a)}else typeof n.value=="string"&&e.set(r,n.value.trim())}}const ors="Any";function UQe(e){const t=e.trim();return t===""||t===ors}const lrs=new Set(F9t.map(e=>e.entityType));function qQe(e){const t=e.trim();return lrs.has(t)?t:void 0}function crs(e){const t={};for(const n of e){const r=n.fieldId;if(Array.isArray(n.value)){const s=n.value.filter(a=>typeof a=="string").map(a=>a.trim()).filter(a=>!UQe(a));if(s.length===0)continue;if(r==="tags")t.tags=s;else if(r==="rootEntityType"){const a=qQe(s[0]);a&&(t.rootEntityType=a)}else t[r]=s[0]}else if(typeof n.value=="string"){if(UQe(n.value))continue;const s=n.value.trim();if(r==="rootEntityType"){const a=qQe(s);a&&(t.rootEntityType=a)}else t[r]=s}}return t}const B9t=[{label:"Last 24 hours",value:"24h"},{label:"Last 3 days",value:"3d"},{label:"Last 7 days",value:"7d"},{label:"Last 14 days",value:"14d"},{label:"Last 30 days",value:"30d"}],urs=new Set(B9t.map(e=>e.value));function drs(e){return typeof e=="string"&&(urs.has(e)||e==="custom")}const U9t=g.createContext({datePreset:"24h",setDatePreset:()=>{},customRange:void 0,setCustomRange:()=>{},dateRangeLabel:"Last 24 hours",filterTokens:[],setFilterTokens:()=>{},dimensionalFilter:{},dimensionalFilterKey:"{}",tracesBasePath:void 0,logsBasePath:void 0});function tG(){return g.useContext(U9t)}function frs(e,t){return e!=="custom"?B9t.find(n=>n.value===e)?.label??e:t?.from?t.to?`${er(t.from,"MMM d, yyyy")} – ${er(t.to,"MMM d, yyyy")}`:er(t.from,"MMM d, yyyy"):"Custom range"}function prs({children:e,preset:t,filterTokens:n,onPresetChange:r,onFilterTokensChange:s,customRange:a,onCustomRangeChange:i,tracesBasePath:l,logsBasePath:c}){const u=g.useMemo(()=>JSON.stringify(n),[n]),d=g.useMemo(()=>n,[u]),f=g.useMemo(()=>crs(d),[d]),p=g.useMemo(()=>JSON.stringify(f),[f]),h=frs(t,a),m=g.useMemo(()=>({datePreset:t,setDatePreset:r,customRange:a,setCustomRange:i??(()=>{}),dateRangeLabel:h,filterTokens:d,setFilterTokens:s,dimensionalFilter:f,dimensionalFilterKey:p,tracesBasePath:l,logsBasePath:c}),[t,r,a,i,h,d,s,f,p,l,c]);return o.jsx(U9t.Provider,{value:m,children:e})}const hrs=["last-24h","last-3d","last-7d","last-14d","last-30d","custom"];function mrs(e){switch(e){case"3d":return"last-3d";case"7d":return"last-7d";case"14d":return"last-14d";case"30d":return"last-30d";case"custom":return"custom";default:return"last-24h"}}function grs(e){switch(e){case"last-3d":return"3d";case"last-7d":return"7d";case"last-14d":return"14d";case"last-30d":return"30d";case"custom":return"custom";default:return"24h"}}function vrs(){const{datePreset:e,setDatePreset:t,customRange:n,setCustomRange:r}=tG(),s=g.useRef(e);s.current=e;const a=g.useRef(n);return a.current=n,o.jsx(aTe,{preset:mrs(e),onPresetChange:i=>{const l=grs(i);s.current=l,t(l)},dateFrom:n?.from,dateTo:n?.to,onDateChange:(i,l)=>{if(s.current!=="custom")return;const c={...a.current,[l]:i};a.current=c,r(c)},presets:hrs})}const rse={"24h":1440*60*1e3,"3d":4320*60*1e3,"7d":10080*60*1e3,"14d":336*60*60*1e3,"30d":720*60*60*1e3};function yrs(e,t,n){if(e!=="custom"){const r=rse[e]??rse["24h"];return{start:new Date(n-r),end:new Date(n)}}return{start:t?.from??new Date(n-rse["24h"]),end:t?.to??new Date(n)}}function Em(){const{datePreset:e,customRange:t,dimensionalFilter:n,dimensionalFilterKey:r}=tG(),s=g.useRef(null),a=e==="custom"?`custom:${t?.from?.getTime()??""}:${t?.to?.getTime()??""}`:`preset:${e}`;(!s.current||s.current.key!==a)&&(s.current={key:a,anchor:Date.now()});const i=s.current.anchor,l=g.useMemo(()=>yrs(e,t,i),[e,t,i]),c=g.useMemo(()=>({timestamp:l,...n}),[l,r]),u=g.useMemo(()=>`${a}|${r}`,[a,r]);return{datePreset:e,customRange:t,timestamp:l,filters:c,dimensionalFilter:n,filterKey:u}}function q9t(){const e=We(),{filters:t,filterKey:n}=Em();return wt({queryKey:["metrics","agent-runs-kpi",n],queryFn:()=>e.getMetricAggregate({name:["mastra_agent_duration_ms"],aggregation:"count",filters:t,comparePeriod:"previous_period"})})}function K4({href:e,LinkComponent:t="a"}){return o.jsx(de,{as:t,href:e,variant:"ghost",size:"icon-md",tooltip:"View in Traces","aria-label":"View in Traces",children:o.jsx(Kkn,{})})}function brs({href:e,LinkComponent:t="a"}){return o.jsx(de,{as:t,href:e,variant:"ghost",size:"icon-md",tooltip:"View errors in Logs","aria-label":"View errors in Logs",children:o.jsx($On,{})})}const xrs=[{dataKey:"p50",label:"p50",color:Pp.blue,aggregate:e=>({value:e.length>0?`${Math.round(e.reduce((t,n)=>t+n.p50,0)/e.length)}`:"0",suffix:"avg ms"})},{dataKey:"p95",label:"p95",color:Pp.yellow,aggregate:e=>({value:e.length>0?`${Math.round(e.reduce((t,n)=>t+n.p95,0)/e.length)}`:"0",suffix:"avg ms"})}];function sse({data:e,onPointClick:t}){return e.length===0?o.jsx(Ut.NoData,{message:"No latency data yet"}):o.jsx(LU,{data:e,series:xrs,onPointClick:t?n=>{const r=n;typeof r?.tsMs=="number"&&Number.isFinite(r.tsMs)&&t(r)}:void 0})}function wrs({data:e,isLoading:t,isError:n,onPointClick:r,actions:s}){const a=e?e.agentData.length>0?"agents":e.workflowData.length>0?"workflows":e.toolData.length>0?"tools":"agents":"agents",[i,l]=g.useState(a);g.useEffect(()=>{if(!e)return;const p={agents:e.agentData.length>0,workflows:e.workflowData.length>0,tools:e.toolData.length>0};!p[i]&&p[a]&&l(a)},[e,i,a]);const c=typeof s=="function"?s(i):s,u=!!e&&(e.agentData.length>0||e.workflowData.length>0||e.toolData.length>0),d=e?Object.values(e).filter(Array.isArray).flat().map(p=>p.p50).filter(p=>typeof p=="number"):[],f=d.length>0?`${Math.round(d.reduce((p,h)=>p+h,0)/d.length)}ms`:"—";return o.jsxs(Ut,{children:[o.jsxs(Ut.TopBar,{children:[o.jsx(Ut.TitleAndDescription,{title:"Latency",description:"Hourly p50 and p95 latency."}),u&&o.jsx(Ut.Summary,{value:f,label:"Avg p50"}),c?o.jsx(Ut.Actions,{children:c}):null]}),t?o.jsx(Ut.Loading,{}):n?o.jsx(Ut.Error,{message:"Failed to load latency data"}):o.jsx(Ut.Content,{children:u?o.jsxs(cu,{value:i,onValueChange:l,defaultTab:a,className:"overflow-visible",children:[o.jsxs(uu,{children:[o.jsx(qr,{value:"agents",children:"Agents"}),o.jsx(qr,{value:"workflows",children:"Workflows"}),o.jsx(qr,{value:"tools",children:"Tools"})]}),o.jsx(fs,{value:"agents",children:o.jsx(sse,{data:e.agentData,onPointClick:r?p=>r("agents",p):void 0})}),o.jsx(fs,{value:"workflows",children:o.jsx(sse,{data:e.workflowData,onPointClick:r?p=>r("workflows",p):void 0})}),o.jsx(fs,{value:"tools",children:o.jsx(sse,{data:e.toolData,onPointClick:r?p=>r("tools",p):void 0})})]}):o.jsx(Ut.NoData,{message:"No latency data yet"})})]})}function Srs(e){switch(e){case"24h":return"last-24h";case"3d":return"last-3d";case"7d":return"last-7d";case"14d":return"last-14d";case"30d":return"last-30d";case"custom":return"custom";default:return}}function krs(e,t){if(t==="1h"){const s=new Date(e);s.setUTCMinutes(0,0,0);const a=new Date(s.getTime()+3600*1e3);return{from:s,to:a}}const n=new Date(e);n.setUTCHours(0,0,0,0);const r=new Date(n.getTime()+1440*60*1e3);return{from:n,to:r}}function V9t(e,t,n,r,s,a,i){if(i){e.set(t,"custom"),e.set(n,i.from.toISOString()),e.set(r,i.to.toISOString());return}if(s==="custom"){e.set(t,"custom"),a?.from&&e.set(n,a.from.toISOString()),a?.to&&e.set(r,a.to.toISOString());return}const l=Srs(s);l&&e.set(t,l)}function To(e,t,n){typeof n=="string"&&n.length>0&&e.set(t,n)}function H9t(e,t,n){if(!(!Array.isArray(n)||n.length===0))for(const r of n)r&&e.append(t,r)}function VQe({preset:e,customRange:t,dashboardFilter:n,scope:r,tracesBasePath:s="/observability"}){const a=new URLSearchParams;a.set(xw,"branches"),V9t(a,ww,Sw,kw,e,t,r.window);const i=r.rootEntityType??n.rootEntityType;i&&a.set($x,i),r.status&&a.set(Mx,r.status),To(a,Ol.entityName,r.entityName??n.entityName),To(a,Ol.threadId,r.threadId??n.threadId),To(a,Ol.resourceId,r.resourceId??n.resourceId),To(a,Ol.entityId,n.entityId),To(a,Ol.runId,n.runId),To(a,Ol.sessionId,n.sessionId),To(a,Ol.requestId,n.requestId),To(a,Ol.userId,n.userId),To(a,Ol.organizationId,n.organizationId),To(a,Ol.experimentId,n.experimentId),To(a,Ol.serviceName,n.serviceName),To(a,Ol.environment,n.environment),H9t(a,Ol.tags,n.tags);const l=a.toString();return l?`${s}?${l}`:s}function Ors({preset:e,customRange:t,dashboardFilter:n,scope:r,logsBasePath:s="/logs"}){const a=new URLSearchParams;V9t(a,qb,Vb,Hb,e,t,r.window);const i=r.rootEntityType??n.rootEntityType;i&&a.set(Dx,i),To(a,_l.entityName,r.entityName??n.entityName),To(a,_l.threadId,r.threadId??n.threadId),To(a,_l.resourceId,r.resourceId??n.resourceId),To(a,_l.runId,n.runId),To(a,_l.sessionId,n.sessionId),To(a,_l.requestId,n.requestId),To(a,_l.userId,n.userId),To(a,_l.organizationId,n.organizationId),To(a,_l.experimentId,n.experimentId),To(a,_l.serviceName,n.serviceName),To(a,_l.environment,n.environment),H9t(a,_l.tags,n.tags),r.status==="error"&&a.append(_l.level,"error");const l=a.toString();return l?`${s}?${l}`:s}function jI(){const{datePreset:e,customRange:t,dimensionalFilter:n,tracesBasePath:r,logsBasePath:s}=tG(),a=g.useCallback((c={})=>VQe({preset:e,customRange:t,dashboardFilter:n,scope:c,tracesBasePath:r}),[e,t,n,r]),i=g.useCallback((c={})=>Ors({preset:e,customRange:t,dashboardFilter:n,scope:c,logsBasePath:s}),[e,t,n,s]),l=g.useCallback((c,u,d)=>{const f=krs(u,d);return VQe({preset:e,customRange:t,dashboardFilter:n,scope:{...c,window:f},tracesBasePath:r})},[e,t,n,r]);return{getTracesHref:a,getLogsHref:i,getBucketTracesHref:l}}const W9t="1h";async function ase(e,t,n){const r=await e.getMetricPercentiles({name:t,percentiles:[.5,.95],interval:W9t,filters:n}),s=r.series.find(l=>l.percentile===.5),a=r.series.find(l=>l.percentile===.95);if(!s||!a)return[];const i=new Map(a.points.map(l=>[new Date(l.timestamp).getTime(),l.value]));return s.points.map(l=>{const c=new Date(l.timestamp),u=c.getTime();return{time:c.toLocaleTimeString("en-US",{hour:"2-digit",minute:"2-digit",hour12:!1}),tsMs:u,p50:Math.round(l.value),p95:Math.round(i.get(u)??0)}})}function _rs(){const e=We(),{filters:t,filterKey:n}=Em();return wt({queryKey:["metrics","latency",n],queryFn:async()=>{const[r,s,a]=await Promise.all([ase(e,"mastra_agent_duration_ms",t),ase(e,"mastra_workflow_duration_ms",t),ase(e,"mastra_tool_duration_ms",t)]);return{agentData:r,workflowData:s,toolData:a,interval:W9t}}})}const HQe={agents:Os.AGENT,workflows:Os.WORKFLOW_RUN,tools:Os.TOOL};function Crs(){const{data:e,isLoading:t,isError:n}=_rs(),{getTracesHref:r,getBucketTracesHref:s}=jI(),{Link:a}=yn(),i=bs();return o.jsx(wrs,{data:e,isLoading:t,isError:n,onPointClick:(l,c)=>{Number.isFinite(c.tsMs)&&i(s({rootEntityType:HQe[l]},c.tsMs,"1h"))},actions:l=>o.jsx(K4,{href:r({rootEntityType:HQe[l]}),LinkComponent:a})})}function Ers(e){return e==="threads"||e==="resources"}function ise(e){return e.length<=12?e:`${e.slice(0,6)}…${e.slice(-4)}`}function jrs({threads:e,resources:t,getThreadRowHref:n,getResourceRowHref:r,actions:s,LinkComponent:a}){const[i,l]=g.useState("threads"),c=e.data?.map(y=>({...y,key:y.threadId}))??[],u=t.data?.map(y=>({...y,key:y.resourceId}))??[],d=c.length>0,f=u.length>0,p=e.data?.reduce((y,b)=>y+b.runs,0)??0,h=t.data?.reduce((y,b)=>y+b.threadCount,0)??0,m=i==="threads"?e:t,v=typeof s=="function"?s(i):s;return o.jsxs(Ut,{children:[o.jsxs(Ut.TopBar,{children:[o.jsx(Ut.TitleAndDescription,{title:"Memory",description:"Resource and Thread consumption"}),i==="threads"&&d&&o.jsx(Ut.Summary,{value:p.toLocaleString(),label:"Total runs"}),i==="resources"&&f&&o.jsx(Ut.Summary,{value:h.toLocaleString(),label:"Total threads"}),v?o.jsx(Ut.Actions,{children:v}):null]}),m.isLoading?o.jsx(Ut.Loading,{}):m.isError?o.jsx(Ut.Error,{message:"Failed to load memory data"}):o.jsx(Ut.Content,{children:o.jsxs(cu,{defaultTab:"threads",value:i,onValueChange:y=>{Ers(y)&&l(y)},className:"grid grid-rows-[auto_1fr] overflow-y-auto h-full",children:[o.jsxs(uu,{children:[o.jsx(qr,{value:"threads",children:"Threads"}),o.jsx(qr,{value:"resources",children:"Resources"})]}),o.jsx(fs,{value:"threads",children:d?o.jsxs(me,{columns:"auto auto auto auto auto",...Uve,children:[o.jsxs(me.Top,{children:[o.jsx(me.TopCell,{sticky:"start",children:"Thread ID"}),o.jsx(me.TopCell,{className:"justify-end text-right",children:"Resource ID"}),o.jsx(me.TopCell,{className:"justify-end text-right",children:"Runs"}),o.jsx(me.TopCell,{className:"justify-end text-right",children:"Tokens"}),o.jsx(me.TopCell,{className:"justify-end text-right",children:"Cost"})]}),c.map(y=>{const b=n?.(y),S=o.jsxs(o.Fragment,{children:[o.jsx(me.RowHeaderCell,{height:"compact",className:"text-ui-sm",children:ise(y.threadId)}),o.jsx(me.NumberCell,{children:y.resourceId?ise(y.resourceId):"—"}),o.jsx(me.NumberCell,{highlight:!0,children:y.runs.toLocaleString()}),o.jsx(me.NumberCell,{children:y.tokens>0?wc(y.tokens):"—"}),o.jsx(me.NumberCell,{children:y.cost!=null?bg(y.cost,y.costUnit):"—"})]});return b?o.jsx(me.RowLink,{to:b,LinkComponent:a,children:S},y.key):o.jsx(me.RowStatic,{children:S},y.key)})]}):o.jsx(Ut.NoData,{message:"No thread activity yet"})}),o.jsx(fs,{value:"resources",children:f?o.jsxs(me,{columns:"auto auto auto auto",...Uve,children:[o.jsxs(me.Top,{children:[o.jsx(me.TopCell,{sticky:"start",children:"Resource ID"}),o.jsx(me.TopCell,{className:"justify-end text-right",children:"Threads"}),o.jsx(me.TopCell,{className:"justify-end text-right",children:"Tokens"}),o.jsx(me.TopCell,{className:"justify-end text-right",children:"Cost"})]}),u.map(y=>{const b=r?.(y),S=o.jsxs(o.Fragment,{children:[o.jsx(me.RowHeaderCell,{height:"compact",className:"text-ui-sm",children:ise(y.resourceId)}),o.jsx(me.NumberCell,{highlight:!0,children:y.threadCount.toLocaleString()}),o.jsx(me.NumberCell,{children:y.tokens>0?wc(y.tokens):"—"}),o.jsx(me.NumberCell,{children:y.cost!=null?bg(y.cost,y.costUnit):"—"})]});return b?o.jsx(me.RowLink,{to:b,LinkComponent:a,children:S},y.key):o.jsx(me.RowStatic,{children:S},y.key)})]}):o.jsx(Ut.NoData,{message:"No resource activity yet"})})]})})]})}function J4(e,t,n){const r=e.get(t);if(r!==void 0)return r;const s=n();return e.set(t,s),s}const ose=20;function Trs(){const e=We(),{filters:t,filterKey:n}=Em();return wt({queryKey:["metrics","top-active-threads",n],queryFn:async()=>{const r={groupBy:["threadId","resourceId"],orderDirection:"DESC",filters:t},[s,a,i]=await Promise.all([e.getMetricBreakdown({...r,name:["mastra_agent_duration_ms"],aggregation:"count",limit:ose}),e.getMetricBreakdown({...r,name:["mastra_model_total_input_tokens"],aggregation:"sum",limit:ose}),e.getMetricBreakdown({...r,name:["mastra_model_total_output_tokens"],aggregation:"sum",limit:ose})]),l=new Map,c=d=>J4(l,d,()=>({tokens:0,cost:null,costUnit:null})),u=d=>{for(const f of d){const p=f.dimensions.threadId;if(!p)continue;const h=c(p);h.tokens+=f.value,f.estimatedCost!=null&&(h.cost=(h.cost??0)+f.estimatedCost,f.costUnit&&(h.costUnit=f.costUnit))}};return u(a.groups),u(i.groups),s.groups.filter(d=>!!d.dimensions.threadId).map(d=>{const f=d.dimensions.threadId,p=l.get(f);return{threadId:f,resourceId:d.dimensions.resourceId??null,runs:d.value,tokens:p?.tokens??0,cost:p?.cost??null,costUnit:p?.costUnit??null}})}})}const lse=20;function Nrs(){const e=We(),{filters:t,filterKey:n}=Em();return wt({queryKey:["metrics","top-resources-by-threads",n],queryFn:async()=>{const r={groupBy:["resourceId"],orderDirection:"DESC",filters:t},[s,a,i]=await Promise.all([e.getMetricBreakdown({...r,name:["mastra_agent_duration_ms"],aggregation:"count_distinct",distinctColumn:"threadId",limit:lse}),e.getMetricBreakdown({...r,name:["mastra_model_total_input_tokens"],aggregation:"sum",limit:lse}),e.getMetricBreakdown({...r,name:["mastra_model_total_output_tokens"],aggregation:"sum",limit:lse})]),l=new Map,c=d=>J4(l,d,()=>({tokens:0,cost:null,costUnit:null})),u=d=>{for(const f of d){const p=f.dimensions.resourceId;if(!p)continue;const h=c(p);h.tokens+=f.value,f.estimatedCost!=null&&(h.cost=(h.cost??0)+f.estimatedCost,f.costUnit&&(h.costUnit=f.costUnit))}};return u(a.groups),u(i.groups),s.groups.filter(d=>!!d.dimensions.resourceId).map(d=>{const f=d.dimensions.resourceId,p=l.get(f);return{resourceId:f,threadCount:d.value,tokens:p?.tokens??0,cost:p?.cost??null,costUnit:p?.costUnit??null}})}})}function Irs(){const e=Trs(),t=Nrs(),{getTracesHref:n}=jI(),{Link:r}=yn();return o.jsx(jrs,{threads:{data:e.data,isLoading:e.isLoading,isError:e.isError},resources:{data:t.data,isLoading:t.isLoading,isError:t.isError},LinkComponent:r,getThreadRowHref:s=>n({threadId:s.threadId,...s.resourceId?{resourceId:s.resourceId}:{}}),getResourceRowHref:s=>n({resourceId:s.resourceId})})}function e5({label:e,value:t,prevValue:n,changePct:r,isLoading:s,isError:a}){const i=t!=null;return o.jsxs(Kr,{children:[o.jsx(Kr.Label,{children:e}),o.jsx(Kr.Value,{className:i?void 0:"invisible",children:i?t:"—"}),a?o.jsx(Kr.Error,{}):s?o.jsx(Kr.Loading,{}):i?r!=null?o.jsx(Kr.Change,{changePct:r,prevValue:n}):o.jsx(Kr.NoChange,{}):o.jsx(Kr.NoData,{})]})}function Ars(){const e=We(),{filters:t,filterKey:n}=Em();return wt({queryKey:["metrics","active-resources-kpi",n],queryFn:()=>e.getMetricAggregate({name:["mastra_agent_duration_ms"],aggregation:"count_distinct",distinctColumn:"resourceId",filters:t,comparePeriod:"previous_period"})})}function Rrs(){const e=We(),{filters:t,filterKey:n}=Em();return wt({queryKey:["metrics","active-threads-kpi",n],queryFn:()=>e.getMetricAggregate({name:["mastra_agent_duration_ms"],aggregation:"count_distinct",distinctColumn:"threadId",filters:t,comparePeriod:"previous_period"})})}function Prs(){const e=We(),{filters:t,filterKey:n}=Em();return wt({queryKey:["metrics","model-cost-kpi",n],queryFn:async()=>{const r=await e.getMetricAggregate({name:["mastra_model_total_input_tokens","mastra_model_total_output_tokens"],aggregation:"sum",filters:t,comparePeriod:"previous_period"});return{cost:r.estimatedCost??null,costUnit:r.costUnit??null,previousCost:r.previousEstimatedCost??null,costChangePercent:r.costChangePercent??null}}})}function $rs(){const e=We(),{filters:t,filterKey:n}=Em();return wt({queryKey:["metrics","total-tokens-kpi",n],queryFn:async()=>{const[r,s]=await Promise.all([e.getMetricAggregate({name:["mastra_model_total_input_tokens"],aggregation:"sum",filters:t,comparePeriod:"previous_period"}),e.getMetricAggregate({name:["mastra_model_total_output_tokens"],aggregation:"sum",filters:t,comparePeriod:"previous_period"})]),a=r.value!=null||s.value!=null,i=r.previousValue!=null||s.previousValue!=null,l=(r.value??0)+(s.value??0),c=(r.previousValue??0)+(s.previousValue??0),u=i&&c>0?(l-c)/c*100:null;return{value:a?l:null,previousValue:i?c:null,changePercent:u}}})}function Mrs(){const{data:e,isLoading:t,isError:n}=q9t();return o.jsx(e5,{label:"Total Agent Runs",value:e?.value!=null?e.value.toLocaleString():null,prevValue:e?.previousValue!=null?e.previousValue.toLocaleString():void 0,changePct:e?.changePercent??null,isLoading:t,isError:n})}function Drs(){const{data:e,isLoading:t,isError:n}=Prs();return o.jsx(e5,{label:"Total Model Cost",value:e?.cost!=null?bg(e.cost,e.costUnit):null,prevValue:e?.previousCost!=null?bg(e.previousCost,e.costUnit):void 0,changePct:e?.costChangePercent??null,isLoading:t,isError:n})}function Lrs(){const{data:e,isLoading:t,isError:n}=$rs();return o.jsx(e5,{label:"Total Tokens",value:e?.value!=null?wc(e.value):null,prevValue:e?.previousValue!=null?wc(e.previousValue):void 0,changePct:e?.changePercent??null,isLoading:t,isError:n})}function Frs(){const{data:e,isLoading:t,isError:n}=Rrs();return o.jsx(e5,{label:"Total Threads",value:e?.value!=null?wc(e.value):null,prevValue:e?.previousValue!=null?wc(e.previousValue):void 0,changePct:e?.changePercent??null,isLoading:t,isError:n})}function zrs(){const{data:e,isLoading:t,isError:n}=Ars();return o.jsx(e5,{label:"Total Resources",value:e?.value!=null?wc(e.value):null,prevValue:e?.previousValue!=null?wc(e.previousValue):void 0,changePct:e?.changePercent??null,isLoading:t,isError:n})}function Brs({onClear:e,onRemoveAll:t,onSave:n,onRemoveSaved:r,isLoading:s,filterFields:a,filterTokens:i,onFilterTokensChange:l,autoFocusFilterFieldId:c}){const u=i.length>0,d=i.some(f=>Urs(f,a));return o.jsxs("div",{className:K("grid grid-cols-[1fr_auto] gap-3 items-start"),children:[o.jsx(lTe,{fields:a,tokens:i,onTokensChange:l,disabled:s,autoFocusFieldId:c}),u&&o.jsx(iTe,{disabled:s,onClear:d?e:void 0,onRemoveAll:t,onSave:n,onRemoveSaved:r})]})}function Urs(e,t){const n=t.find(r=>r.id===e.fieldId);return n?n.kind==="text"?typeof e.value=="string"&&e.value.trim()!=="":n.kind==="pick-multi"?n.multi?Array.isArray(e.value)&&e.value.length>0:typeof e.value=="string"&&e.value!==""&&e.value!=="Any":n.kind==="multi-select"?Array.isArray(e.value)&&e.value.length>0:!1:!1}function qrs({rows:e,isLoading:t,isError:n,getRowHref:r,actions:s,LinkComponent:a}){const i=!!e&&e.length>0;return o.jsxs(Ut,{children:[o.jsxs(Ut.TopBar,{children:[o.jsx(Ut.TitleAndDescription,{title:"Model Usage & Cost",description:"Token consumption by model."}),i&&(()=>{const l=e.reduce((d,f)=>d+(f.cost??0),0),c=new Set;for(const d of e)d.cost!=null&&d.costUnit&&c.add(d.costUnit);let u;return c.size===0?u=l>0?bg(l):"—":c.size===1?u=l>0?bg(l,[...c][0]):"—":u="Mixed",o.jsx(Ut.Summary,{value:u,label:"Total cost"})})(),s?o.jsx(Ut.Actions,{children:s}):null]}),t?o.jsx(Ut.Loading,{}):n?o.jsx(Ut.Error,{message:"Failed to load model usage data"}):o.jsx(Ut.Content,{children:i?o.jsxs(me,{columns:"auto auto auto auto auto auto",...Uve,children:[o.jsxs(me.Top,{children:[o.jsx(me.TopCell,{sticky:"start",children:"Model"}),o.jsx(me.TopCell,{className:"justify-end text-right",children:"Input"}),o.jsx(me.TopCell,{className:"justify-end text-right",children:"Output"}),o.jsx(me.TopCell,{className:"justify-end text-right",children:"Cache Read"}),o.jsx(me.TopCell,{className:"justify-end text-right",children:"Cache Write"}),o.jsx(me.TopCell,{className:"justify-end text-right",children:"Cost"})]}),e.map(l=>{const c=r?.(l),u=o.jsxs(o.Fragment,{children:[o.jsx(me.RowHeaderCell,{height:"compact",className:"text-ui-sm",children:l.model}),o.jsx(me.NumberCell,{children:l.input}),o.jsx(me.NumberCell,{children:l.output}),o.jsx(me.NumberCell,{children:l.cacheRead}),o.jsx(me.NumberCell,{children:l.cacheWrite}),o.jsx(me.NumberCell,{highlight:!0,children:l.cost!=null?bg(l.cost,l.costUnit):"—"})]});return c?o.jsx(me.RowLink,{to:c,LinkComponent:a,children:u},l.model):o.jsx(me.RowStatic,{children:u},l.model)})]}):o.jsx(Ut.NoData,{message:"No model usage data yet"})})]})}function Vrs(){const e=We(),{filters:t,filterKey:n}=Em();return wt({queryKey:["metrics","model-usage-cost",n],queryFn:async()=>{const[r,s,a,i]=await Promise.all(["mastra_model_total_input_tokens","mastra_model_total_output_tokens","mastra_model_input_cache_read_tokens","mastra_model_input_cache_write_tokens"].map(d=>e.getMetricBreakdown({name:[d],groupBy:["model"],aggregation:"sum",orderDirection:"DESC",filters:t}))),l=new Map,c=d=>J4(l,d,()=>({input:0,output:0,cacheRead:0,cacheWrite:0,cost:null,costUnit:null})),u=(d,f)=>{f.estimatedCost!=null&&(d.cost=(d.cost??0)+f.estimatedCost,f.costUnit&&(d.costUnit=f.costUnit))};for(const d of r.groups){const f=d.dimensions.model??"unknown",p=c(f);p.input=d.value,u(p,d)}for(const d of s.groups){const f=d.dimensions.model??"unknown",p=c(f);p.output=d.value,u(p,d)}for(const d of a.groups){const f=d.dimensions.model??"unknown",p=c(f);p.cacheRead=d.value}for(const d of i.groups){const f=d.dimensions.model??"unknown",p=c(f);p.cacheWrite=d.value}return Array.from(l.entries()).map(([d,f])=>({model:d,input:wc(f.input),output:wc(f.output),cacheRead:wc(f.cacheRead),cacheWrite:wc(f.cacheWrite),cost:f.cost,costUnit:f.costUnit})).sort((d,f)=>d.model.localeCompare(f.model))}})}function Hrs(){const{data:e,isLoading:t,isError:n}=Vrs(),{getTracesHref:r}=jI(),{Link:s}=yn();return o.jsx(qrs,{rows:e,isLoading:t,isError:n,LinkComponent:s,getRowHref:()=>r({rootEntityType:Os.AGENT}),actions:o.jsx(K4,{href:r({rootEntityType:Os.AGENT}),LinkComponent:s})})}function Wrs(e){return e==="tokens"||e==="cost"}function Zrs({data:e,isLoading:t,isError:n,getRowHref:r,actions:s,LinkComponent:a}){const[i,l]=g.useState("tokens"),c=e??[],u=c.length>0,d=c.reduce((b,S)=>b+S.total,0),f=c.filter(b=>b.cost!=null&&b.cost>0),p=new Set(f.map(b=>b.costUnit??"usd")),h=p.size<=1,m=h?[...p][0]??"usd":null,v=h?f.reduce((b,S)=>b+(S.cost??0),0):0,y=h&&v>0;return o.jsxs(Ut,{children:[o.jsxs(Ut.TopBar,{children:[o.jsx(Ut.TitleAndDescription,{title:"Token Usage by Agent",description:"Token consumption grouped by agent."}),u&&(i==="cost"&&y?o.jsx(Ut.Summary,{value:bg(v,m),label:"Total cost"}):o.jsx(Ut.Summary,{value:wc(d),label:"Total tokens"})),u&&s?o.jsx(Ut.Actions,{children:s}):null]}),t?o.jsx(Ut.Loading,{}):n?o.jsx(Ut.Error,{message:"Failed to load token usage data"}):o.jsx(Ut.Content,{children:u?o.jsxs(cu,{defaultTab:"tokens",value:i,onValueChange:b=>{Wrs(b)&&l(b)},className:"grid grid-rows-[auto_1fr] overflow-y-auto h-full",children:[o.jsxs(uu,{children:[o.jsx(qr,{value:"tokens",children:"Tokens"}),o.jsx(qr,{value:"cost",children:"Cost"})]}),o.jsx(fs,{value:"tokens",children:o.jsx(uN,{LinkComponent:a,data:c.map(b=>({name:b.name,values:[b.input,b.output],href:r?.(b)})),segments:[{label:"Input",color:Pp.blueDark},{label:"Output",color:Pp.blue}],maxVal:Math.max(...c.map(b=>b.input+b.output)),fmt:wc})}),o.jsx(fs,{value:"cost",children:y?o.jsx(uN,{LinkComponent:a,data:f.slice().sort((b,S)=>(S.cost??0)-(b.cost??0)).map(b=>({name:b.name,values:[b.cost],href:r?.(b)})),segments:[{label:"Cost",color:Pp.purple}],maxVal:Math.max(...f.map(b=>b.cost??0)),fmt:b=>bg(b,m)}):o.jsx(Ut.NoData,{message:"No cost data yet"})})]}):o.jsx(Ut.NoData,{message:"No token usage data yet"})})]})}function Grs(){const e=We(),{filters:t,filterKey:n}=Em();return wt({queryKey:["metrics","token-usage-by-agent",n],queryFn:async()=>{const r={groupBy:["entityName"],aggregation:"sum",orderDirection:"DESC",filters:t},[s,a]=await Promise.all([e.getMetricBreakdown({...r,name:["mastra_model_total_input_tokens"]}),e.getMetricBreakdown({...r,name:["mastra_model_total_output_tokens"]})]),i=new Map,l=u=>J4(i,u,()=>({input:0,output:0,cost:null,costUnit:null})),c=(u,d)=>{d.estimatedCost!=null&&(u.cost=(u.cost??0)+d.estimatedCost,d.costUnit&&(u.costUnit=d.costUnit))};for(const u of s.groups){const d=u.dimensions.entityName??"unknown",f=l(d);f.input=u.value,c(f,u)}for(const u of a.groups){const d=u.dimensions.entityName??"unknown",f=l(d);f.output=u.value,c(f,u)}return Array.from(i.entries()).map(([u,d])=>({name:u,input:d.input,output:d.output,total:d.input+d.output,cost:d.cost,costUnit:d.costUnit})).sort((u,d)=>d.total-u.total)}})}function Qrs(){const{data:e,isLoading:t,isError:n}=Grs(),{getTracesHref:r}=jI(),{Link:s}=yn();return o.jsx(Zrs,{data:e,isLoading:t,isError:n,LinkComponent:s,getRowHref:a=>r({rootEntityType:Os.AGENT,entityName:a.name}),actions:o.jsx(K4,{href:r({rootEntityType:Os.AGENT}),LinkComponent:s})})}function Zve(e,t=wc){return n=>({value:t(n.reduce((r,s)=>r+(typeof s[e]=="number"?s[e]:0),0))})}const Yrs=[{dataKey:"input",label:"Input tokens",color:Pp.blue,aggregate:Zve("input")},{dataKey:"output",label:"Output tokens",color:Pp.yellow,aggregate:Zve("output")}];function Xrs(e){return e==="tokens"||e==="cost"}function Krs({data:e,interval:t="1d",isLoading:n,isError:r,actions:s}){const[a,i]=g.useState("tokens"),l=e??[],c=l.map(k=>({...k})),u=l.length>0,d=l.reduce((k,_)=>k+_.total,0),f=l.filter(k=>k.cost!=null&&k.cost>0),p=f.map(k=>({...k})),h=new Set(f.map(k=>k.costUnit).filter(k=>!!k)),m=h.size===1&&f.every(k=>k.costUnit!=null),v=m?[...h][0]??null:null,y=m?f.reduce((k,_)=>k+(_.cost??0),0):0,b=m&&y>0,S=t==="1h"?"Input and output tokens per hour.":"Input and output tokens per day.",w=[{dataKey:"cost",label:"Cost",color:Pp.purple,aggregate:Zve("cost",k=>bg(k,v))}];return o.jsxs(Ut,{children:[o.jsxs(Ut.TopBar,{children:[o.jsx(Ut.TitleAndDescription,{title:"Token usage over time",description:S}),u&&(a==="cost"&&b?o.jsx(Ut.Summary,{value:bg(y,v),label:"Total cost"}):o.jsx(Ut.Summary,{value:wc(d),label:"Total tokens"})),u&&s?o.jsx(Ut.Actions,{children:s}):null]}),n?o.jsx(Ut.Loading,{}):r?o.jsx(Ut.Error,{message:"Failed to load token usage timeline"}):o.jsx(Ut.Content,{children:u?o.jsxs(cu,{defaultTab:"tokens",value:a,onValueChange:k=>{Xrs(k)&&i(k)},className:"overflow-visible",children:[o.jsxs(uu,{children:[o.jsx(qr,{value:"tokens",children:"Tokens"}),o.jsx(qr,{value:"cost",children:"Cost"})]}),o.jsx(fs,{value:"tokens",children:o.jsx(LU,{data:c,series:Yrs})}),o.jsx(fs,{value:"cost",children:b?o.jsx(LU,{data:p,series:w}):o.jsx(Ut.NoData,{message:"No cost data yet"})})]}):o.jsx(Ut.NoData,{message:"No token usage data yet"})})]})}function Jrs(e){return e==="24h"?"1h":"1d"}function ess(e,t){return t==="1h"?e.toLocaleTimeString("en-US",{hour:"2-digit",minute:"2-digit",hour12:!1}):e.toLocaleDateString("en-US",{month:"short",day:"2-digit"})}function WQe(e,t,n){for(const r of t?.points??[]){const s=new Date(r.timestamp).getTime();if(!Number.isFinite(s))continue;const a=e.get(s)??{tsMs:s,input:0,output:0,cost:null,costUnits:new Set,hasUnknownCostUnit:!1};a[n]+=r.value,r.estimatedCost!=null&&(a.cost=(a.cost??0)+r.estimatedCost,t?.costUnit?a.costUnits.add(t.costUnit):a.hasUnknownCostUnit=!0),e.set(s,a)}}function tss(e){return e.cost==null||e.hasUnknownCostUnit||e.costUnits.size!==1?null:[...e.costUnits][0]??null}function nss(){const e=We(),{datePreset:t,filters:n,filterKey:r}=Em(),s=Jrs(t);return wt({queryKey:["metrics","token-usage-timeseries",r,s],queryFn:async()=>{const[a,i]=await Promise.all([e.getMetricTimeSeries({name:["mastra_model_total_input_tokens"],interval:s,aggregation:"sum",filters:n}),e.getMetricTimeSeries({name:["mastra_model_total_output_tokens"],interval:s,aggregation:"sum",filters:n})]),l=new Map;return WQe(l,a.series[0],"input"),WQe(l,i.series[0],"output"),{data:Array.from(l.values()).sort((u,d)=>u.tsMs-d.tsMs).map(u=>{const d=new Date(u.tsMs);return{time:ess(d,s),tsMs:u.tsMs,input:u.input,output:u.output,total:u.input+u.output,cost:u.cost,costUnit:tss(u)}}),interval:s}}})}function rss(){const{data:e,isLoading:t,isError:n}=nss(),{getTracesHref:r}=jI(),{Link:s}=yn();return o.jsx(Krs,{data:e?.data,interval:e?.interval,isLoading:t,isError:n,actions:o.jsx(K4,{href:r(),LinkComponent:s})})}function cse({data:e,rowHrefs:t,errorHrefs:n,LinkComponent:r}){return o.jsx(uN,{LinkComponent:r,data:e.map(s=>{const a=n?.(s),i=t?.(s);return a?{name:s.name,values:[s.completed,s.errors],hrefs:[i,a]}:{name:s.name,values:[s.completed,s.errors],href:i}}),segments:[{label:"Completed",color:Pp.blueDark},{label:"Errors",color:Pp.pink}],maxVal:Math.max(...e.map(s=>s.completed+s.errors)),fmt:wc})}function sss({data:e,isLoading:t,isError:n,getRowHref:r,getErrorSegmentHref:s,actions:a,LinkComponent:i}){const[l,c]=g.useState("agents"),u=typeof a=="function"?a(l):a,d=!!e&&(e.agentData.length>0||e.workflowData.length>0||e.toolData.length>0),f=e?[...e.agentData,...e.workflowData,...e.toolData].reduce((m,v)=>m+v.completed+v.errors,0):0,p=m=>r?v=>r(m,v):void 0,h=m=>s?v=>s(m,v):void 0;return o.jsxs(Ut,{children:[o.jsxs(Ut.TopBar,{children:[o.jsx(Ut.TitleAndDescription,{title:"Trace Volume",description:"Runs and call counts."}),d&&o.jsx(Ut.Summary,{value:wc(f),label:"Total runs"}),u?o.jsx(Ut.Actions,{children:u}):null]}),t?o.jsx(Ut.Loading,{}):n?o.jsx(Ut.Error,{message:"Failed to load trace volume data"}):o.jsx(Ut.Content,{children:d?o.jsxs(cu,{value:l,onValueChange:c,defaultTab:"agents",className:"grid grid-rows-[auto_1fr] overflow-y-auto h-full",children:[o.jsxs(uu,{children:[o.jsx(qr,{value:"agents",children:"Agents"}),o.jsx(qr,{value:"workflows",children:"Workflows"}),o.jsx(qr,{value:"tools",children:"Tools"})]}),o.jsx(fs,{value:"agents",children:e.agentData.length>0?o.jsx(cse,{data:e.agentData,rowHrefs:p("agents"),errorHrefs:h("agents"),LinkComponent:i}):o.jsx(Ut.NoData,{message:"No agent data yet"})}),o.jsx(fs,{value:"workflows",children:e.workflowData.length>0?o.jsx(cse,{data:e.workflowData,rowHrefs:p("workflows"),errorHrefs:h("workflows"),LinkComponent:i}):o.jsx(Ut.NoData,{message:"No workflow data yet"})}),o.jsx(fs,{value:"tools",children:e.toolData.length>0?o.jsx(cse,{data:e.toolData,rowHrefs:p("tools"),errorHrefs:h("tools"),LinkComponent:i}):o.jsx(Ut.NoData,{message:"No tool data yet"})})]}):o.jsx(Ut.NoData,{message:"No trace volume data yet"})})]})}async function use(e,t,n){const r=await e.getMetricBreakdown({name:[t],groupBy:["entityName","status"],aggregation:"count",orderDirection:"DESC",filters:n}),s=new Map;for(const a of r.groups){const i=a.dimensions.entityName??"unknown",l=a.dimensions.status??"ok",c=J4(s,i,()=>({completed:0,errors:0}));l==="error"?c.errors+=a.value:c.completed+=a.value}return Array.from(s.entries()).map(([a,i])=>({name:a,...i})).sort((a,i)=>i.completed+i.errors-(a.completed+a.errors))}function ass(){const e=We(),{filters:t,filterKey:n}=Em();return wt({queryKey:["metrics","trace-volume",n],queryFn:async()=>{const[r,s,a]=await Promise.all([use(e,"mastra_agent_duration_ms",t),use(e,"mastra_workflow_duration_ms",t),use(e,"mastra_tool_duration_ms",t)]);return{agentData:r,workflowData:s,toolData:a}}})}const cF={agents:Os.AGENT,workflows:Os.WORKFLOW_RUN,tools:Os.TOOL};function iss(){const{data:e,isLoading:t,isError:n}=ass(),{getTracesHref:r,getLogsHref:s}=jI(),{Link:a}=yn();return o.jsx(sss,{data:e,isLoading:t,isError:n,LinkComponent:a,getRowHref:(i,l)=>r({rootEntityType:cF[i],entityName:l.name}),getErrorSegmentHref:(i,l)=>l.errors>0?s({rootEntityType:cF[i],entityName:l.name,status:"error"}):void 0,actions:i=>o.jsxs(o.Fragment,{children:[o.jsx(K4,{href:r({rootEntityType:cF[i]}),LinkComponent:a}),o.jsx(brs,{href:s({rootEntityType:cF[i],status:"error"}),LinkComponent:a})]})})}const oss=new Set(["ObservabilityStorageClickhouseVNext","ObservabilityStorageDuckDB","ObservabilityInMemory","ObservabilitySpanner","ObservabilityStoragePostgresVNext"]),dse="period",uF="dateFrom",dF="dateTo";function lss(){const[e,t]=ga(),n=e.get(dse),r=drs(n)?n:"24h",s=g.useMemo(()=>{if(r!=="custom")return;const d=h=>{if(!h)return;const m=new Date(h);return Number.isNaN(m.getTime())?void 0:m},f=d(e.get(uF)),p=d(e.get(dF));if(!(!f&&!p))return{from:f,to:p}},[r,e.toString()]),a=g.useMemo(()=>srs(e),[e.toString()]),i=g.useCallback(d=>{t(f=>{const p=new URLSearchParams(f);return d==="24h"?p.delete(dse):p.set(dse,d),d!=="custom"&&(p.delete(uF),p.delete(dF)),p},{replace:!0})},[t]),l=g.useCallback(d=>{t(f=>{const p=new URLSearchParams(f);return d?.from?p.set(uF,d.from.toISOString()):p.delete(uF),d?.to?p.set(dF,d.to.toISOString()):p.delete(dF),p},{replace:!0})},[t]),c=g.useCallback(d=>{t(f=>{const p=new URLSearchParams(f);return irs(p,d),p},{replace:!0})},[t]),u=g.useRef(!1);return g.useEffect(()=>{if(u.current||(u.current=!0,nrs(e)))return;const d=z9t();d&&t(f=>{const p=new URLSearchParams(f);for(const[h,m]of d)p.append(h,m);return p},{replace:!0})},[]),o.jsx(prs,{preset:r,filterTokens:a,onPresetChange:i,onFilterTokensChange:c,customRange:s,onCustomRangeChange:l,children:o.jsx(css,{})})}function css(){const[e]=ga(),{error:t,isLoading:n}=q9t(),{filterTokens:r,setFilterTokens:s}=tG(),[a,i]=g.useState(),{data:l,isLoading:c}=a4(),u=l?.observabilityStorageType,d=u?oss.has(u):!1,f=u==="ObservabilityInMemory",{data:p,isLoading:h}=gTe(),{data:m,isLoading:v}=pTe(),{data:y,isLoading:b}=mTe(),{data:S,isLoading:w}=hTe(),k=g.useMemo(()=>rrs({availableTags:p??[],availableEntityNames:m??[],availableServiceNames:y??[],availableEnvironments:S??[],loading:{tags:h,entityNames:v,serviceNames:b,environments:w}}),[p,m,y,S,h,v,b,w]),[_,C]=g.useState(()=>z9t()!==null),E=g.useCallback(()=>{ers(e),C(!0),De.success("Filters setting for Metrics saved")},[e]),j=g.useCallback(()=>{trs(),C(!1),De.success("Filters setting for Metrics cleared up")},[]),N=g.useCallback(()=>{s([])},[s]),I=g.useCallback(()=>{const R=r.map(P=>{const L=k.find(M=>M.id===P.fieldId);return L?L.kind==="text"?{fieldId:P.fieldId,value:""}:L.kind==="pick-multi"?L.multi?{fieldId:P.fieldId,value:[]}:{fieldId:P.fieldId,value:"Any"}:L.kind==="multi-select"?{fieldId:P.fieldId,value:[]}:P:P});s(R)},[k,r,s]);return t&&gs(t)?o.jsx(lr,{children:o.jsx(Vs,{})}):t&&ys(t)?o.jsx(lr,{children:o.jsx(Ds,{resource:"metrics"})}):t?o.jsx(lr,{children:o.jsx(zi,{title:"Failed to load metrics",message:t.message})}):o.jsxs(Lt,{width:"wide",height:"full",children:[o.jsxs(Lt.TopArea,{children:[o.jsx(Lt.Row,{children:o.jsxs(Lt.Column,{className:"flex flex-wrap items-start justify-start gap-2",children:[o.jsx(vrs,{}),o.jsx(cTe,{fields:k,tokens:r,onTokensChange:s,disabled:n,onStartTextFilter:i})]})}),o.jsx(Brs,{isLoading:n,filterFields:k,filterTokens:r,onFilterTokensChange:s,onClear:I,onRemoveAll:N,onSave:E,onRemoveSaved:_?j:void 0,autoFocusFilterFieldId:a})]}),c?null:d?o.jsxs("div",{className:"grid gap-8 content-start pb-10",children:[f&&o.jsx(In,{variant:"info",title:"Metrics are not persisted",children:o.jsx(In.Message,{children:"This project uses in-memory storage for observability. Metrics will be lost on every server restart. For persistent metrics, switch the observability storage to ClickHouse, DuckDB, Postgres v-next, or Spanner."})}),o.jsxs(qve,{children:[o.jsx(Mrs,{}),o.jsx(Drs,{}),o.jsx(Lrs,{}),o.jsx(Frs,{}),o.jsx(zrs,{})]}),o.jsxs(qve,{children:[o.jsx(Hrs,{}),o.jsx(Qrs,{}),o.jsx(rss,{}),o.jsx(Irs,{}),o.jsx(iss,{}),o.jsx(Crs,{})]})]}):o.jsx("div",{className:"flex h-full items-center justify-center",children:o.jsx(Cr,{iconSlot:o.jsx(Of,{}),titleSlot:"Metrics are not available with your current storage",descriptionSlot:"Metrics require ClickHouse, DuckDB, Postgres v-next, Spanner, or in-memory storage for observability. Other relational databases (LibSQL, MSSQL) and document stores (MongoDB) do not support metrics collection. To enable metrics on an existing project, switch the observability storage in the Mastra configuration.",actionSlot:o.jsxs(de,{variant:"ghost",as:"a",href:"https://mastra.ai/docs/observability/metrics/overview",target:"_blank",rel:"noopener noreferrer",children:["Metrics Documentation ",o.jsx(_a,{})]})})})]})}function uss(){const{paths:e}=yn(),{data:t,isLoading:n,error:r}=c6t(),{isCmsAvailable:s}=Y1(),[a,i]=g.useState(""),l=t?.promptBlocks??[];return r&&gs(r)?o.jsx(lr,{children:o.jsx(Vs,{})}):r&&ys(r)?o.jsx(lr,{children:o.jsx(Ds,{resource:"prompt blocks"})}):r?o.jsx(lr,{children:o.jsx(zi,{title:"Failed to load prompt blocks",message:r.message})}):l.length===0&&!n?o.jsx(lr,{children:o.jsx(WZr,{})}):o.jsxs(Lt,{children:[o.jsx(Lt.TopArea,{children:o.jsxs(Lt.Row,{align:"center",stack:"responsive",children:[o.jsx("div",{className:"max-w-120 flex-1",children:o.jsx(jf,{onSearch:i,label:"Filter prompts",placeholder:"Filter by name or description"})}),s&&o.jsxs(de,{as:Ba,to:e.cmsPromptBlockCreateLink(),variant:"primary",className:"shrink-0",children:[o.jsx(Vr,{}),"Create Prompt"]})]})}),o.jsx(HZr,{promptBlocks:l,isLoading:n,search:a})]})}function dss(){return o.jsx(Lt,{width:"narrow",children:o.jsx(Lt.MainArea,{children:o.jsx(Z7r,{children:o.jsx(mve,{})})})})}const fss=[{title:"Mastra APIs",description:"Explore and test the available REST API endpoints with the interactive Swagger UI.",icon:Wcn,href:"/swagger-ui",external:!1},{title:"Documentation",description:"Read the official Mastra documentation for guides, references, and tutorials.",icon:jlt,href:"https://mastra.ai/en/docs",external:!0},{title:"Github",description:"Browse the source code, report issues, and contribute to the Mastra project.",icon:_a,href:"https://github.com/mastra-ai/mastra",external:!0},{title:"Community",description:"Join the Mastra Discord community for help, discussion, and collaboration.",icon:Yj,href:"https://discord.gg/BTYqqHKUrf",external:!0},{title:"Share with your team",description:"Running Mastra Studio locally? Deploy to the cloud so your team can collaborate.",icon:Mlt,href:"https://mastra.ai/cloud",external:!0},{title:"Talk to our Sales team",description:"Get a custom demo, discuss on-prem deployments, and how we can help you accelerate getting agents into production.",icon:Tlt,href:"https://mastra.ai/contact?ref=studio",external:!0}];function pss(){return o.jsx(Lt,{width:"narrow",children:o.jsx(Lt.MainArea,{children:o.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4 max-w-3xl",children:fss.map(e=>o.jsxs("a",{href:e.href,...e.external?{target:"_blank",rel:"noreferrer"}:{},className:"group flex flex-col gap-3 rounded-lg border border-border1 bg-surface2 p-5 transition-colors hover:border-accent1 hover:bg-surface3",children:[o.jsxs("div",{className:"flex items-center gap-2.5",children:[o.jsx(e.icon,{className:"h-5 w-5 text-icon3 group-hover:text-accent1 transition-colors"}),o.jsx("span",{className:"text-ui-md font-medium text-text1",children:e.title}),e.external&&o.jsx(_a,{className:"h-3.5 w-3.5 text-icon3 ml-auto opacity-0 group-hover:opacity-100 transition-opacity"})]}),o.jsx("p",{className:"text-ui-sm text-text3 leading-relaxed",children:e.description})]},e.href))})})})}function hss(){const{data:e={},isLoading:t,error:n}=ih(),[r,s]=g.useState(""),[a,i]=g.useState("all");if(n&&gs(n))return o.jsx(lr,{children:o.jsx(Vs,{})});if(n&&ys(n))return o.jsx(lr,{children:o.jsx(Ds,{resource:"scorers"})});if(n)return o.jsx(lr,{children:o.jsx(zi,{title:"Failed to load scorers",message:n.message})});if(Object.keys(e).length===0&&!t)return o.jsx(lr,{children:o.jsx(aWr,{})});const l=a!=="all"||r!=="",c=()=>{s(""),i("all")};return o.jsxs(Lt,{children:[o.jsx(Lt.TopArea,{children:o.jsx(oWr,{search:r,onSearchChange:s,sourceFilter:a,onSourceFilterChange:i,onReset:c,hasActiveFilters:l})}),o.jsx(sWr,{scorers:e,isLoading:t,search:r,sourceFilter:a})]})}function mss(){const{scorerId:e}=ur(),[t,n]=ga(),r=t.get("scoreId")??void 0,[s,a]=g.useState(r),[i,l]=g.useState({value:"all",label:"All Entities",type:"ALL"}),{scorer:c,error:u}=$Hr(e),{data:d={},isLoading:f,error:p}=km(),{isLoading:h,error:m}=Uy(),{data:v=[],isLoading:y,error:b,isFetchingNextPage:S,hasNextPage:w,setEndOfListElement:k}=PHr({scorerId:e,entityId:i?.value==="all"?void 0:i?.value,entityType:i?.type==="ALL"?void 0:i?.type}),_=g.useMemo(()=>c?.agentIds?.filter(B=>d[B]).map(B=>({value:B,label:d[B].name,type:"AGENT"}))||[],[c?.agentIds,d]),C=g.useMemo(()=>c?.workflowIds?.map(B=>({value:B,label:B,type:"WORKFLOW"}))||[],[c?.workflowIds]),E=g.useMemo(()=>[{value:"all",label:"All Entities",type:"ALL"},..._,...C],[_,C]),j=t.get("entity")??"all",N=E.find(B=>B.value===j);N&&N.value!==i?.value&&l(N),g.useEffect(()=>{if(u){const B=u instanceof Error?u.message:"Failed to load scorer";De.error(`Error loading scorer: ${B}`)}},[u]),g.useEffect(()=>{if(p){const B=p instanceof Error?p.message:"Failed to load agents";De.error(`Error loading agents: ${B}`)}},[p]),g.useEffect(()=>{if(m){const B=m instanceof Error?m.message:"Failed to load workflows";De.error(`Error loading workflows: ${B}`)}},[m]);const I=B=>{B?.value&&n(D=>{const Q=new URLSearchParams(D);return Q.set("entity",B.value),Q})};g.useEffect(()=>{const B=t.get("scoreId")??void 0;if(B===s)return;if(!B){a(void 0);return}v.find(Q=>Q.id===B)&&a(B)},[t,v]);const R=g.useCallback(B=>{a(B||void 0),n(D=>{const Q=new URLSearchParams(D);return B?Q.set("scoreId",B):Q.delete("scoreId"),Q})},[n]);if(!c)return null;const P=gs(u)||gs(p)||gs(m),L=u&&ys(u),M=!P&&!L&&(u||p||m),q=!y&&v.length===0,H=i?.value!=="all",F=c?.scorer?.source==="stored"?o.jsx(Iy,{owner:"scorer-detail",children:o.jsxs(de,{variant:"default",as:Ba,to:`/cms/scorers/${e}/edit`,size:"sm",children:[o.jsx(Lp,{})," Edit"]})}):null;if(P||L||M||q&&!H){const B=(u instanceof Error?u.message:void 0)??(p instanceof Error?p.message:void 0)??(m instanceof Error?m.message:void 0)??"An unexpected error occurred";return o.jsxs(Lt,{width:"wide",height:"full",children:[F,o.jsx(Lt.MainArea,{isCentered:!0,children:P?o.jsx(Vs,{}):L?o.jsx(Ds,{resource:"scorers"}):M?o.jsx(zi,{title:"Failed to load scorer",message:B}):o.jsx(THr,{})})]})}return o.jsxs(Lt,{width:"wide",children:[F,o.jsx(Lt.TopArea,{children:o.jsx(NHr,{selectedEntity:i,entityOptions:E,onEntityChange:I,onReset:()=>{n(B=>{const D=new URLSearchParams(B);return D.set("entity","all"),D})},isLoading:y||f||h})}),o.jsx(jHr,{scores:v,isLoading:y,selectedScoreId:s,isFetchingNextPage:S,hasNextPage:w,setEndOfListElement:k,onScoreClick:R,errorMsg:b?.message})]})}function gss({label:e,description:t,htmlFor:n,className:r,children:s}){return o.jsxs("div",{className:K("flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",r),"data-slot":"settings-row",children:[o.jsxs("div",{children:[n?o.jsx(Rt,{htmlFor:n,className:"text-sm font-medium",children:e}):o.jsx("p",{className:"text-sm font-medium",children:e}),t&&o.jsx("p",{className:"text-sm text-neutral3",children:t})]}),s]})}const Z9t=[{value:"dark",label:"Dark",Icon:wdn},{value:"light",label:"Light",Icon:Nfn},{value:"system",label:"System",Icon:Wlt}],vss=e=>Z9t.some(t=>t.value===e);function yss({option:e}){const{Icon:t}=e;return o.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-center gap-2",children:[o.jsx(t,{"aria-hidden":"true",className:"h-4 w-4 shrink-0 opacity-70"}),o.jsx("span",{className:"min-w-0 truncate",children:e.label})]})}const bss=()=>{const{baseUrl:e,headers:t,apiPrefix:n}=qxe(),{theme:r,setTheme:s}=PN();return o.jsx(Lt,{width:"narrow",children:o.jsxs(Lt.MainArea,{className:"flex flex-col gap-5 mt-6",children:[o.jsx(Yge,{title:"Theme",description:"Customize the appearance of the studio.",children:o.jsx(gss,{label:"Theme mode",htmlFor:"theme",children:o.jsxs(da,{value:r,onValueChange:a=>{vss(a)&&s(a)},children:[o.jsx(pa,{id:"theme",className:"w-full sm:w-48",children:o.jsx(fa,{className:"inline-flex min-w-0 max-w-full items-center"})}),o.jsx(ha,{children:Z9t.map(a=>o.jsx(Lr,{value:a.value,children:o.jsx(yss,{option:a})},a.value))})]})})}),o.jsx(Yge,{title:"Mastra Connection",description:"Configure the Mastra instance URL, API prefix, and request headers used by the studio.",children:o.jsx(lRt,{initialConfig:{baseUrl:e,headers:t,apiPrefix:n}})})]})})};function xss(){const[e]=ga(),t=bs(),n=e.get("redirect")||"/",r=()=>{n.startsWith("http")?window.location.href=n:t(n,{replace:!0})};return o.jsx(D9t,{redirectUri:n,onSuccess:r,initialMode:"signup"})}const G9t=e=>o.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 15 15",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:[o.jsx("g",{clipPath:"url(#clip0_21999_22095)",children:o.jsx("path",{d:"M7.5 0.75C3.6325 0.75 0.5 3.8825 0.5 7.75C0.5 10.8475 2.50375 13.4637 5.28625 14.3912C5.63625 14.4525 5.7675 14.2425 5.7675 14.0587C5.7675 13.8925 5.75875 13.3412 5.75875 12.755C4 13.0787 3.545 12.3262 3.405 11.9325C3.32625 11.7312 2.985 11.11 2.6875 10.9437C2.4425 10.8125 2.0925 10.4887 2.67875 10.48C3.23 10.4712 3.62375 10.9875 3.755 11.1975C4.385 12.2562 5.39125 11.9587 5.79375 11.775C5.855 11.32 6.03875 11.0137 6.24 10.8387C4.6825 10.6637 3.055 10.06 3.055 7.3825C3.055 6.62125 3.32625 5.99125 3.7725 5.50125C3.7025 5.32625 3.4575 4.60875 3.8425 3.64625C3.8425 3.64625 4.42875 3.4625 5.7675 4.36375C6.3275 4.20625 6.9225 4.1275 7.5175 4.1275C8.1125 4.1275 8.7075 4.20625 9.2675 4.36375C10.6062 3.45375 11.1925 3.64625 11.1925 3.64625C11.5775 4.60875 11.3325 5.32625 11.2625 5.50125C11.7087 5.99125 11.98 6.6125 11.98 7.3825C11.98 10.0687 10.3438 10.6637 8.78625 10.8387C9.04 11.0575 9.25875 11.4775 9.25875 12.1337C9.25875 13.07 9.25 13.8225 9.25 14.0587C9.25 14.2425 9.38125 14.4612 9.73125 14.3912C11.1209 13.9221 12.3284 13.029 13.1839 11.8377C14.0393 10.6463 14.4996 9.21668 14.5 7.75C14.5 3.8825 11.3675 0.75 7.5 0.75Z",fill:"currentColor"})}),o.jsx("defs",{children:o.jsx("clipPath",{id:"clip0_21999_22095",children:o.jsx("rect",{width:"14",height:"14",fill:"currentColor",transform:"translate(0.5 0.75)"})})})]});function wss(e){return e.replace(/\/$/,"").split("/").pop()}function nG({children:e,className:t}){return o.jsx("div",{className:K("border border-border1 rounded-lg mt-12 py-8 lg:min-h-[25rem] transition-height px-4 lg:px-12",t),children:e})}function Sss({templates:e,linkComponent:t,className:n,isLoading:r}){const s=t||"a";return r?o.jsx("div",{className:K("grid gap-y-4",n),children:Array.from({length:5}).map((a,i)=>o.jsx("div",{className:"h-16 bg-surface3 animate-pulse rounded-lg"},i))}):o.jsx("div",{className:K("grid gap-y-4",n),children:e.map(a=>{const i=a?.agents||a?.tools||a?.networks||a?.workflows||a?.mcp;return o.jsxs("article",{className:K("border border-border1 rounded-lg overflow-hidden w-full grid grid-cols-[1fr_auto] bg-surface3 transition-colors hover:bg-surface4"),children:[o.jsxs(s,{to:`/templates/${a.slug}`,className:K("grid [&:hover_p]:text-neutral5",{"grid-cols-[8rem_1fr] lg:grid-cols-[12rem_1fr]":a.imageURL}),children:[a.imageURL&&o.jsx("div",{className:K("overflow-hidden"),children:o.jsx("div",{className:"w-full h-full bg-cover thumb transition-scale duration-150",style:{backgroundImage:`url(${a.imageURL})`}})}),o.jsxs("div",{className:K("grid py-3 px-6 w-full gap-0.5","[&_svg]:w-[1em] [&_svg]:h-[1em] [&_svg]:text-neutral3"),children:[o.jsx("h2",{className:"text-ui-lg text-neutral5",children:a.title}),o.jsx("p",{className:"text-ui-md text-neutral4 transition-colors duration-500",children:a.description}),o.jsxs("div",{className:"hidden 2xl:flex text-neutral3 text-ui-md flex-wrap items-center gap-4 mt-3",children:[i&&o.jsxs("ul",{className:K("flex gap-4 text-ui-md text-neutral3 m-0 p-0 list-none","[&>li]:flex [&>li]:items-center [&>li]:gap-0.5 text-neutral4"),children:[a?.agents&&a.agents.length>0&&o.jsxs("li",{children:[o.jsx(sl,{})," ",a.agents.length]}),a?.tools&&a.tools.length>0&&o.jsxs("li",{children:[o.jsx(eh,{})," ",a.tools.length]}),a?.networks&&a.networks.length>0&&o.jsxs("li",{children:[o.jsx(Zlt,{})," ",a.networks.length]}),a?.workflows&&a.workflows.length>0&&o.jsxs("li",{children:[o.jsx(vD,{})," ",a.workflows.length]}),a?.mcp&&a.mcp.length>0&&o.jsxs("li",{children:[o.jsx(B_,{})," ",a.mcp.length]})]}),i&&a.supportedProviders&&o.jsx("small",{children:"|"}),o.jsx("div",{className:"flex items-center text-neutral3 gap-4",children:a.supportedProviders.map(l=>o.jsx("span",{className:"",children:l},l))})]})]})]}),o.jsx("a",{href:a.githubUrl,className:K("group items-center gap-2 text-ui-md ml-auto pr-4 hidden","lg:flex"),target:"_blank",rel:"noopener noreferrer",children:o.jsxs("span",{className:"flex items-center gap-2 px-2 py-1 rounded bg-surface1 group-hover:bg-surface2 text-neutral3 transition-colors group-hover:text-neutral5",children:[o.jsx(G9t,{})," ",wss(a.githubUrl)]})})]},a.slug)})})}function kss({tagOptions:e,selectedTag:t,providerOptions:n,selectedProvider:r,onTagChange:s,onProviderChange:a,searchTerm:i,onSearchChange:l,onReset:c,className:u,isLoading:d}){return d?o.jsxs("div",{className:K("h-[6.5rem] flex items-center gap-8","[&>div]:bg-surface3 [&>div]:w-48 [&>div]:h-8 [&>div]:animate-pulse",u),children:[o.jsx("div",{})," ",o.jsx("div",{})," ",o.jsx("div",{})]}):o.jsxs("div",{className:K("flex flex-wrap mx-auto sticky top-0 gap-4 bg-surface2 py-8",u),children:[o.jsx(BT,{name:"search-templates",label:"Search templates",labelIsHidden:!0,value:i,onChange:f=>l?.(f.target.value),placeholder:"Search Template"}),o.jsx(Sc,{label:"Filter by tag",labelIsHidden:!0,name:"filter-tag",value:t,onValueChange:s,options:e}),o.jsx(Sc,{label:"Filter by provider",labelIsHidden:!0,name:"filter-provider",value:r,onValueChange:a,options:n}),c&&o.jsxs(de,{onClick:c,children:["Reset ",o.jsx(vs,{})]})]})}function Oss(){const{data:e,isLoading:t}=wYn(),{templates:n,tags:r,providers:s}=e??{templates:[],tags:[],providers:[]},[a,i]=g.useState("all"),[l,c]=g.useState("all"),[u,d]=g.useState(""),f=[{value:"all",label:"Any tag"}];(r||[]).forEach(S=>{f.push({value:S,label:S})});const p=[{value:"all",label:"Any provider"}];(s||[]).forEach(S=>{p.push({value:S,label:S})});const h=(S,w)=>{w==="tag"?i(S):w==="provider"&&c(S)},m=S=>{d(S)},v=()=>{i("all"),c("all"),d("")},y=n.filter(S=>!(u&&!S.title.toLowerCase().includes(u)&&!S.description.toLowerCase().includes(u)||a!=="all"&&!S.tags.includes(a)||l!=="all"&&!S.supportedProviders.includes(l))),b=u||a!=="all"||l!=="all";return o.jsxs(ls,{children:[o.jsx(e0e,{children:o.jsxs(Lpt,{children:[o.jsx(Ue,{children:o.jsx(Zv,{})}),"Templates"]})}),o.jsxs("div",{className:K("overflow-y-auto w-full h-full px-8 pb-12 z-10"),children:[o.jsx(kss,{selectedTag:a,onTagChange:S=>h(S,"tag"),tagOptions:f,selectedProvider:l,onProviderChange:S=>h(S,"provider"),providerOptions:p,searchTerm:u,onSearchChange:m,onReset:b?v:void 0,className:"max-w-[80rem]",isLoading:t}),o.jsx(Sss,{templates:y,linkComponent:Ba,className:"max-w-[80rem] mx-auto",isLoading:t})]})]})}const _ss="1.50.0-alpha.0";function Css({errorMsg:e,validationErrors:t}){const n=typeof e=="string"?e:e!=null?String(e):void 0,r=n?.includes("Invalid schema for function"),s=n?.includes("validation issue")||t&&t.length>0,a=()=>s?"Template installation completed but some validation issues remain. The template may still be functional, but you should review and fix these issues.":r?"There was an issue with the AI model configuration. This may be related to the selected model or AI SDK version compatibility.":"An unexpected error occurred during template installation.",i=()=>s?{icon:o.jsx(Ep,{className:"text-yellow-500"}),title:"Template Installed with Warnings"}:{icon:o.jsx(wun,{}),title:"Template Installation Failed"},{icon:l,title:c}=i();return o.jsxs(nG,{className:"space-y-4 text-neutral3 mb-8 content-center",children:[o.jsxs("div",{className:K("grid items-center justify-items-center gap-4 content-center","[&>svg]:w-8 [&>svg]:h-8"),children:[l,o.jsxs("div",{className:"text-center space-y-2",children:[o.jsx("p",{className:"text-ui-md font-medium text-neutral5",children:c}),o.jsx("p",{className:"text-ui-md text-neutral3",children:a()})]})]}),t&&t.length>0&&o.jsxs("details",{className:"text-xs",children:[o.jsxs("summary",{className:"cursor-pointer text-neutral3 hover:text-neutral4 select-none text-center",children:["Show Validation Issues (",t.length,")"]}),o.jsx("div",{className:"mt-4 p-3 bg-gray-100 dark:bg-gray-800 rounded text-xs overflow-auto max-h-60 text-left space-y-2",children:t.map((u,d)=>o.jsxs("div",{className:"border-l-2 border-red-400 pl-2",children:[o.jsx("div",{className:"font-medium text-red-600 dark:text-red-400",children:u.type==="typescript"?"🔴 TypeScript Error":"⚠️ Lint Error"}),o.jsx("div",{className:"text-xs font-mono text-gray-700 dark:text-gray-300 mt-1 whitespace-pre-wrap wrap-break-word",children:u.message})]},d))})]}),n&&!s&&o.jsxs("details",{className:"text-xs",children:[o.jsx("summary",{className:"cursor-pointer text-neutral3 hover:text-neutral4 select-none text-center",children:"Show Details"}),o.jsx("div",{className:"mt-4 p-3 bg-gray-100 dark:bg-gray-800 rounded text-xs font-mono overflow-auto max-h-60 text-left",children:o.jsx("div",{className:"whitespace-pre-wrap wrap-break-word",children:n})})]})]})}function Ess({providerOptions:e,selectedProvider:t,onProviderChange:n,variables:r,errors:s,handleInstallTemplate:a,handleVariableChange:i,isLoadingEnvVars:l,isInstalling:c,defaultModelProvider:u,defaultModelId:d,onModelUpdate:f}){return o.jsx(nG,{children:o.jsxs("div",{className:"max-w-[40rem] my-4 p-4 lg:p-8 mx-auto gap-8 grid",children:[o.jsxs("h2",{className:K("text-neutral4 text-header-sm font-semibold flex items-center gap-2","[&>svg]:w-[1.2em] [&_svg]:h-[1.2em] [&_svg]:opacity-70"),children:["Install Template ",o.jsx(Glt,{})]}),o.jsx(Sc,{name:"template-provider",options:e,label:"Template AI Model Provider",onValueChange:n,value:t,placeholder:"Select",layout:"horizontal"}),t&&Object.entries(r||{}).length>0&&o.jsxs(o.Fragment,{children:[o.jsx("h3",{className:"text-neutral3 text-ui-md",children:"Set required Environmental Variables"}),o.jsx("div",{className:"grid grid-cols-[1fr_1fr] gap-4 items-start",children:l?o.jsxs("div",{className:K("flex items-center justify-center col-span-2 text-neutral3 text-ui-sm gap-4","[&_svg]:opacity-50 [&_svg]:w-[1.1em] [&_svg]:h-[1.1em]","animate-in fade-in duration-300"),children:[o.jsx(Gt,{})," Loading variables..."]}):Object.entries(r).map(([p,h])=>o.jsxs(g.Fragment,{children:[o.jsx(yO,{name:`env-${p}`,labelIsHidden:!0,label:"Key",value:p,disabled:!0,className:"w-full"}),o.jsx(yO,{name:p,labelIsHidden:!0,label:"Value",value:h,onChange:i,errorMsg:s.includes(p)?"Value is required.":"",autoComplete:"off",className:"w-full"})]},p))}),o.jsxs("div",{className:"border-t border-border1 pt-12 mt-3.5 relative",children:[o.jsx("div",{className:"absolute w-8 h-8 rounded-full bg-surface2 top-0 left-1/2 -translate-x-1/2 -translate-y-4 text-ui-sm text-neutral3 flex items-center justify-center",children:"And"}),o.jsx("h3",{className:"text-neutral4 text-ui-lg",children:"Set AI Model for Template Installation"}),o.jsx("p",{className:"text-neutral3 text-ui-md mt-2 mb-8",children:"This model will be used by the workflow to process and install the template"}),o.jsx(zLt,{defaultProvider:u||"",defaultModel:d||"",updateModel:f||(()=>Promise.resolve({message:"Updated"})),closeEditor:()=>{},autoSave:!0,selectProviderPlaceholder:"Provider"})]})]}),t&&!l&&o.jsx(de,{className:K("flex items-center gap-2 mt-4 justify-center text-ui-md w-full bg-surface5 min-h-10 rounded-lg text-neutral5 hover:bg-surface6 transition-colors","[&>svg]:w-[1.1em] [&_svg]:h-[1.1em] [&_svg]:text-neutral5"),onClick:a,disabled:!t||!u||!d||s.length>0||c,children:c?o.jsxs(o.Fragment,{children:[o.jsx(Gt,{className:"w-4 h-4"})," Installing..."]}):o.jsxs(o.Fragment,{children:["Install ",o.jsx(mm,{})]})})]})})}function jss({title:e,description:t,githubUrl:n,isLoading:r,infoData:s,templateSlug:a}){const i=a?`feat/install-template-${a}`:"feat/install-template-[slug]";return o.jsxs(o.Fragment,{children:[o.jsx("div",{className:K("grid mt-8 items-center"),children:o.jsxs("div",{className:K("text-header-lg flex items-center gap-3","[&>svg]:w-[1.2em] [&>svg]:h-[1.2em] [&>svg]:opacity-50",{"[&>svg]:opacity-20":r}),children:[o.jsx(Zv,{}),o.jsx("h2",{className:K({"bg-surface4 flex rounded-lg min-w-[50%]":r}),children:r?o.jsx(o.Fragment,{children:" "}):e})]})}),o.jsxs("div",{className:"grid lg:grid-cols-[1fr_1fr] gap-x-24",children:[o.jsxs("div",{className:"grid",children:[o.jsx("p",{className:K("mb-4 text-ui-md text-neutral4 mt-2 leading-7",{"bg-surface4 rounded-lg ":r}),children:r?o.jsx(o.Fragment,{children:" "}):t}),!r&&a&&o.jsxs("div",{className:K("bg-surface2 border border-surface4 rounded-lg p-4 mb-4","flex items-start gap-3"),children:[o.jsx("div",{className:"shrink-0 mt-0.5",children:o.jsx(Fx,{className:"w-[1.1em] h-[1.1em] text-blue-500"})}),o.jsxs("div",{className:"flex-1 space-y-2",children:[o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx(sbe,{className:"w-[1em] h-[1em] text-neutral4"}),o.jsx("span",{className:"text-ui-md font-medium text-neutral5",children:"A new Git branch will be created"})]}),o.jsxs("div",{className:"text-ui-sm text-neutral4 space-y-1",children:[o.jsxs("div",{children:[o.jsx("span",{className:"font-medium",children:"Branch name:"})," ",o.jsx("code",{className:"bg-surface3 px-1.5 py-0.5 rounded text-ui-sm font-mono",children:i})]}),o.jsx("div",{children:"This ensures safe installation with easy rollback if needed. Your main branch remains unchanged."})]})]})]}),n&&o.jsxs("a",{href:n,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-2 mt-auto text-neutral3 text-ui-md hover:text-neutral5",children:[o.jsx(G9t,{}),n?.split("/")?.pop()]})]}),s&&o.jsx(Bje,{data:s,labelsAreHidden:!0,isLoading:r})]})]})}function Tss(e){switch(e){case"running":return o.jsx(Gt,{});case"success":return o.jsx(vx,{});case"failed":return o.jsx(Fu,{});default:return null}}function Nss({stepId:e,step:t,isActive:n,position:r}){const s=a=>a.charAt(0).toUpperCase()+a.slice(1).replace(/-/g," ");return o.jsxs("div",{className:K("grid gap-6 grid-cols-[1fr_auto] py-3 px-4 rounded-lg",ms.all,{"border border-dashed border-neutral2 bg-surface3":n}),children:[o.jsxs("div",{className:"grid grid-cols-[auto_1fr] gap-2",children:[o.jsxs("span",{className:K("text-ui-md min-w-6 flex justify-end",ms.colors,{"text-neutral5":n||t.status==="success","text-neutral3":!n&&t.status!=="success"}),children:[r,"."]}),o.jsxs("div",{children:[o.jsx("h4",{className:K("text-ui-md",ms.colors,{"text-neutral5":n||t.status==="success","text-neutral3":!n&&t.status!=="success"}),children:s(e)}),t.description&&o.jsx("p",{className:"text-ui-md text-neutral2 -mt-0.5",children:t.description})]})]}),o.jsx("div",{className:K("w-[1.75rem] h-[1.75rem] rounded-full flex items-center justify-center self-center",ms.all,{"border border-neutral2 border-dashed":t.status==="pending","[&>svg]:text-white [&>svg]:w-4 [&>svg]:h-4":t.status!=="running","w-[1.75rem] h-[1.75rem]":t.status==="running","bg-accent1Dark shadow-glow-accent1":t.status==="success","bg-accent2Dark shadow-glow-accent2":t.status==="failed","scale-110":t.status==="success"||t.status==="failed"}),children:Tss(t.status)})]})}function Iss({currentStep:e,steps:t=[],className:n}){return o.jsx("div",{className:K(n),children:t.map((r,s)=>o.jsx(Nss,{stepId:r.id,step:r,isActive:e?.id===r.id,position:s+1},r.id))})}function Ass({steps:e}){const t=e.length,n=e.filter(r=>r.status==="success").length;return o.jsxs("div",{className:"flex justify-center flex-col gap-4 content-center w-full",children:[o.jsx("div",{className:"grid grid-cols-[0_repeat(9,1fr)] w-full",children:e.map((r,s)=>o.jsx("div",{className:K("flex justify-end items-center relative h-[2rem]",ms.colors,{"bg-accent1Dark":r.status==="success"&&e?.[s-1]?.status==="success"}),children:o.jsx("div",{className:K("w-[2rem] h-[2rem] rounded-full flex items-center justify-center self-center absolute right-0 translate-x-[50%] bg-surface3 z-10 text-neutral3 font-bold text-ui-sm",ms.all,{"border border-neutral2 border-dashed":r.status==="pending","[&>svg]:text-surface1 [&>svg]:w-[1.1rem] [&>svg]:h-[1.1rem]":r.status!=="running","bg-accent1Dark text-white shadow-glow-accent1 scale-110":r.status==="success","bg-accent2Dark text-white shadow-glow-accent2 scale-110":r.status==="failed"}),children:r.status==="running"?o.jsx(Gt,{}):s+1})},r.id))}),o.jsxs("div",{className:K("text-xs text-neutral3 text-center",ms.colors),children:[n," of ",t," steps completed"]})]})}function Rss({name:e,streamResult:t,runId:n,workflowInfo:r}){const s=t?.phase||"initializing",a=t?.payload?.workflowState,i=t?.payload?.currentStep,l=t?.error,c=a?.steps||{},u=Object.keys(c).length>0,d=v=>v==="input"||v.endsWith(".input")||v.startsWith("Mapping_")&&/[0-9a-f]{8}/.test(v)||/[0-9a-f]{8,}/.test(v)?!1:r?.allSteps?v in r.allSteps:!0,f=Object.entries(c).filter(([v,y])=>d(v)),p=f.length,h=()=>{switch(s){case"initializing":return"Preparing template installation...";case"processing":return`Installing ${e} template`;case"completed":return"Template installation completed!";case"error":return"Template installation failed";default:return"Installing template..."}},m=f.map(([v,y])=>({id:v,status:y?.status,description:y?.description,title:v.charAt(0).toUpperCase()+v.slice(1).replace(/-/g," "),isActive:i?.id===v}));return o.jsxs(nG,{className:"space-y-6 text-neutral3 mb-8 content-center",children:[o.jsxs("div",{className:"text-center",children:[o.jsx("h3",{className:"text-lg font-semibold text-neutral5",children:h()}),(t?.runId||n)&&o.jsxs("div",{className:"mt-2 text-ui-sm text-neutral3",children:["Run ID: ",t?.runId??n]})]}),u&&p>0&&!["error"].includes(s)&&o.jsx("div",{className:"max-w-[30rem] w-full mx-auto px-6",children:o.jsx(Ass,{steps:m})}),l&&s==="error"&&o.jsxs("div",{className:K("rounded-lg text-neutral5 p-6 flex items-center gap-3 text-ui-md bg-red-500/10","[&>svg]:w-6 [&>svg]:h-6 [&>svg]:opacity-70 [&>svg]:text-red-500"),children:[o.jsx(Idn,{}),l||"Something went wrong"]}),u&&o.jsx(Iss,{steps:m,currentStep:i,className:"pb-4"}),!u&&s==="initializing"&&o.jsxs("div",{className:"text-center text-sm text-neutral3 grid gap-4 justify-items-center",children:[o.jsx(Gt,{}),o.jsx("p",{children:"This may take some time..."})]})]})}function Pss({name:e,installedEntities:t}){return o.jsxs(nG,{className:K("grid items-center justify-items-center gap-4 content-center","[&>svg]:w-8 [&>svg]:h-8"),children:[o.jsx(Glt,{}),o.jsx("h2",{className:"text-header-md",children:"Done!"}),o.jsxs("p",{className:"text-ui-md text-center text-neutral3 ",children:["The ",o.jsx("b",{className:"text-neutral4",children:e})," template has been successfully installed.",t&&t.length>0&&o.jsxs(o.Fragment,{children:[o.jsx("br",{})," Installed entities are listed below."]})]}),t&&t.length>0&&o.jsx(Bje,{data:t})]})}function $ss(){const{templateSlug:e}=ur(),[t,n]=ga(),[r,s]=g.useState(""),[a,i]=g.useState(""),[l,c]=g.useState(""),[u,d]=g.useState({}),[f,p]=g.useState([]),[h,m]=g.useState(null),[v,y]=g.useState(!1),[b,S]=g.useState(""),[w,k]=g.useState(!1),[_,C]=g.useState(!1),[E,j]=g.useState([]),{data:N,isLoading:I}=SYn({repoOrSlug:e,owner:"mastra-ai"}),P=_ss?.includes("beta")??!1?"beta":"main",{data:L,isLoading:M}=kYn({repo:N?.githubUrl?new URL(N.githubUrl).pathname.split("/")[2]:`template-${e}`,owner:"mastra-ai",branch:P}),{data:q,isLoading:H}=OYn(),{mutateAsync:F,isPending:z}=_Yn(),{mutateAsync:B}=CYn(),{streamInstall:D,streamResult:Q,isStreaming:V}=jYn(q),{observeInstall:$,streamResult:U,isStreaming:Z}=TYn(q);g.useEffect(()=>{const ne=t.get("runId");ne&&!v&&!h&&!V&&!Z&&(console.info("🔄 Checking completed run after hot reload:",{runId:ne}),S(ne),B({runId:ne}).then(ue=>{const pe=ue.snapshot;if(pe?.status==="success"&&pe?.result?.success)y(!0);else if(pe?.result?.success===!1)if(pe?.result?.validationResults&&!pe?.result?.validationResults?.valid&&pe?.result?.validationResults?.remainingErrors>0){const{remainingErrors:ve,errors:ye}=pe.result.validationResults,Se=`Template installation completed but ${ve} validation issue${ve>1?"s":""} remain unresolved.`;m(Se),j(ye||[])}else{const ve=pe?.result?.message||pe?.result?.error||"Template installation failed";m(typeof ve=="string"?ve:String(ve))}}).catch(ue=>{console.error("❌ Failed to fetch run details:",ue),m("Failed to retrieve installation status after reload")}))},[t,v,h,V,Z,B]),g.useEffect(()=>{const ne=t.get("runId"),ue=t.get("resume"),pe=t.get("provider");if(ne&&ue==="true"&&pe&&!V&&!Z&&!w&&!_&&q){S(ne),k(!0);try{B({runId:ne}).then(le=>{if(le.snapshot?.status==="running")return $.mutateAsync({runId:ne})}).then(()=>{n(le=>{const ve=new URLSearchParams(le);return ve.delete("resume"),ve})}).catch(le=>{console.error("❌ Failed to resume template installation:",le),le.message?.includes("404")||le.message?.includes("not found")?m("Template installation run not found. It may have expired or been completed."):m("Failed to resume template installation. Please try again.")})}catch(le){console.error("❌ Auto-resume failed with error:",le),m("Failed to resume template installation. Please refresh and try again.")}}},[t,e,V,Z,w,_,q,B,$,n]);const X=[{value:"openai",label:"OpenAI"},{value:"anthropic",label:"Anthropic"},{value:"groq",label:"Groq"},{value:"google",label:"Google"}],te=[{key:"tools",label:"Tools",value:N?.tools?.length?N.tools.map(ne=>ne).join(", "):"n/a",icon:o.jsx(eh,{})},{key:"agents",label:"Agents",value:N?.agents?.length?N.agents.map(ne=>ne).join(", "):"n/a",icon:o.jsx(sl,{})},{key:"workflows",label:"Workflows",value:N?.workflows?.length?N.workflows.map(ne=>ne).join(", "):"n/a",icon:o.jsx(vD,{})},{key:"providers",label:"Providers",value:N?.supportedProviders?.length?N.supportedProviders.join(", "):"n/a",icon:o.jsx(Rv,{})},{key:"tags",label:"Tags",value:N?.tags?.length?N.tags.join(", "):"n/a",icon:o.jsx(wN,{})}],J=[{...te[0]},{...te[1]},{...te[2]}].filter(ne=>ne.value!=="n/a");g.useEffect(()=>{L&&d(L)},[L]),g.useEffect(()=>{const ne=Q||U;ne?.phase==="error"&&ne?.error&&m(typeof ne.error=="string"?ne.error:String(ne.error))},[Q?.phase,Q?.error,U?.phase,U?.error]);const ee=ne=>{s(ne)},ae=async ne=>(i(ne.provider),c(ne.modelId),{message:"Model updated successfully"}),ce=async()=>{const ne=Object.entries(u).reduce((ue,[pe,le])=>(le===""&&ue.push(pe),ue),[]);if(ne.length>0){p(ne);return}if(N){m(null),y(!1),S(""),C(!0);try{const pe={repo:N.githubUrl||`https://github.com/mastra-ai/template-${N.slug}`,ref:P,slug:N.slug,variables:u},{runId:le}=await F({});S(le),n(ve=>{const ye=new URLSearchParams(ve);return ye.set("runId",le),ye.set("resume","true"),ye.set("provider",r||"openai"),ye}),await D.mutateAsync({inputData:pe,selectedModel:{provider:a,modelId:l},runId:le})}catch(ue){C(!1),m(ue?.message||"Template installation failed"),console.error("Template installation failed",ue)}}},Y=ne=>{const{name:ue,value:pe}=ne.target;pe.trim()===""?p(le=>[...le,ue]):p(le=>le.filter(ve=>ve!==ue)),d(le=>({...le,[ue]:pe}))};return o.jsx(ls,{children:o.jsx("div",{className:K("w-full lg:px-12 h-full overflow-y-scroll"),children:o.jsxs("div",{className:"p-6 w-full max-w-[80rem] mx-auto grid gap-y-4",children:[o.jsx(jss,{isLoading:I,title:N?.title,description:N?.longDescription,imageURL:N?.imageURL,githubUrl:N?.githubUrl,infoData:te,templateSlug:e}),N&&o.jsxs(o.Fragment,{children:[(V||Z)&&o.jsx(Rss,{name:N.title,streamResult:Z?U:Q,runId:b,workflowInfo:q}),v&&o.jsx(Pss,{name:N.title,installedEntities:J,linkComponent:Ba}),h&&o.jsx(Css,{errorMsg:h,validationErrors:E.length>0?E:Q?.validationResults?.errors||U?.validationResults?.errors}),!V&&!Z&&!v&&!h&&o.jsx(Ess,{providerOptions:X,selectedProvider:r,onProviderChange:ee,variables:u,setVariables:d,errors:f,setErrors:p,handleInstallTemplate:ce,handleVariableChange:Y,isLoadingEnvVars:M||H,isInstalling:z,defaultModelProvider:a,defaultModelId:l,onModelUpdate:ae})]})]})})})}const Mss=()=>{const{toolId:e,agentId:t}=ur();return o.jsx("div",{className:"h-full w-full overflow-y-auto",children:o.jsx(cZr,{toolId:e,agentId:t})})},Dss=()=>{const{toolId:e}=ur();return o.jsx("div",{className:"h-full w-full overflow-y-hidden",children:o.jsx(Vns,{toolId:e})})};function Lss(){const{traceId:e}=ur(),[t,n]=ga(),r=bs(),s=t.get("spanId")||void 0,a=t.get("tab"),i=a==="scoring"?"scoring":a==="feedback"?"feedback":"details",l=t.get("scoreId")||void 0,[c,u]=g.useState(s??null),[d,f]=g.useState(),[p,h]=g.useState(i),[m,v]=g.useState(0),[y,b]=g.useState(!1),{data:S,isLoading:w,error:k}=ZH(e),_=g.useMemo(()=>S?.spans??[],[S?.spans]),C=g.useMemo(()=>_.find(ae=>ae.parentSpanId==null),[_]),{data:E,isLoading:j}=oI(e,c??"");g.useEffect(()=>v(0),[e,c]);const{data:N,isLoading:I}=ih(),{data:R,isLoading:P}=s6t({traceId:e,spanId:c??void 0,page:m}),[L,M]=g.useState(0);g.useEffect(()=>M(0),[e,c]);const{data:q,isLoading:H}=C9t({traceId:e,page:L});g.useEffect(()=>{if(l&&R?.scores&&!d){const ae=R.scores.find(ce=>ce.id===l);ae&&f(ae)}},[l,R?.scores,d]);const F=g.useCallback(ae=>{const ce=new URLSearchParams(t);for(const[Y,ne]of Object.entries(ae))ne===null||ne===""?ce.delete(Y):ce.set(Y,ne);n(ce,{replace:!0})},[t,n]),z=g.useCallback(ae=>{const ce=ae??null,Y=ce===c;u(ce),Y||(f(void 0),h("details"),F({spanId:ce,tab:null,scoreId:null}))},[c,F]),B=g.useCallback(()=>{u(null),f(void 0),h("details"),F({spanId:null,tab:null,scoreId:null})},[F]),D=g.useCallback(ae=>{u(ae),f(void 0),h("details"),F({spanId:ae,tab:null,scoreId:null})},[F]),{handlePreviousSpan:Q,handleNextSpan:V}=GH(_,c,D),$=g.useCallback(ae=>{const ce=ae;h(ce),f(void 0),F({tab:ce==="details"?null:ce,scoreId:null})},[F]),U=g.useCallback(ae=>{f(ae),F({scoreId:ae.id})},[F]),Z=g.useCallback(()=>{f(void 0),F({scoreId:null})},[F]),X=g.useCallback(()=>{r("/observability")},[r]),te=g.useCallback(()=>{h("scoring"),C&&c!==C.spanId?(u(C.spanId),f(void 0),F({spanId:C.spanId,tab:"scoring",scoreId:null})):F({tab:"scoring"})},[C,c,F]),J=C?o.jsx(Iy,{owner:"trace-detail",children:o.jsxs(Mr,{children:[o.jsxs(de,{tooltip:"Evaluate Trace","aria-label":"Evaluate Trace",onClick:te,children:[o.jsx(hcn,{}),"Evaluate"]}),o.jsxs(de,{tooltip:"Save as Dataset Item","aria-label":"Save as Dataset Item",onClick:()=>b(!0),children:[o.jsx(gd,{}),"Save"]})]})}):null,ee=C?o.jsx(Lt.Row,{children:o.jsx(Lt.Column,{children:o.jsx(m9t,{rootSpan:C,numOfCol:3})})}):null;return k?o.jsxs(Lt,{height:"full",children:[J,ee&&o.jsx(Lt.TopArea,{children:ee}),o.jsx(Lt.MainArea,{isCentered:!0,children:o.jsx(g9t,{error:k,resource:"traces",errorTitle:"Failed to load trace"})})]}):o.jsxs(Lt,{children:[J,ee&&o.jsx(Lt.TopArea,{children:ee}),o.jsx(w9t,{rootSpanId:C?.spanId,traceId:e,isOpen:y,onClose:()=>b(!1)}),o.jsxs("div",{className:K("grid h-full min-h-0 gap-4 overflow-hidden items-start mt-4",c?"grid-cols-[2fr_3fr]":"grid-cols-[1fr]"),children:[o.jsx(uTe,{traceId:e,spans:_,isLoading:w,onClose:X,onSpanSelect:z,onEvaluateTrace:te,initialSpanId:c,placement:"trace-page",timelineChartWidth:c?"default":"wide"}),c&&!w&&o.jsxs("div",{className:K("grid gap-4 max-h-full min-h-0 overflow-auto",d?"grid-rows-[1fr_1fr]":"grid-rows-[1fr]"),children:[o.jsx(WH,{traceId:e,spanId:c,span:E?.span,isLoading:j,onClose:B,onPrevious:Q,onNext:V,activeTab:p,onTabChange:$,feedbackTabBadge:q?.pagination?.total??void 0,feedbackTabSlot:()=>o.jsx(k9t,{feedbackData:q,onPageChange:M,isLoadingFeedbackData:H}),scoringTabBadge:R?.pagination?.total??void 0,scoringTabSlot:({span:ae,traceId:ce,spanId:Y})=>o.jsxs("div",{className:"grid gap-6",children:[o.jsx(_9t,{traceId:ce,isTopLevelSpan:!ae.parentSpanId,spanId:Y,entityType:ae.attributes?.agentId||ae.entityType===Os.AGENT?"Agent":ae.attributes?.workflowId||ae.entityType===Os.WORKFLOW_RUN?"Workflow":void 0,scorers:N,isLoadingScorers:I}),o.jsx(O9t,{scoresData:R,onPageChange:v,isLoadingScoresData:P,onScoreSelect:U})]})}),d&&o.jsx(zje,{score:d,onClose:Z})]})]})]})}function Fss(){const{data:e,isLoading:t,error:n}=Uy(),[r,s]=g.useState("");return n&&gs(n)?o.jsx(lr,{children:o.jsx(Vs,{})}):n&&ys(n)?o.jsx(lr,{children:o.jsx(Ds,{resource:"workflows"})}):n?o.jsx(lr,{children:o.jsx(zi,{title:"Failed to load workflows",message:n.message})}):Object.keys(e||{}).length===0&&!t?o.jsx(lr,{children:o.jsx(bDr,{})}):o.jsxs(Lt,{children:[o.jsx(Lt.TopArea,{children:o.jsxs(Lt.Row,{align:"center",stack:"responsive",children:[o.jsx("div",{className:"max-w-120 flex-1",children:o.jsx(jf,{onSearch:s,label:"Filter workflows",placeholder:"Filter by name or description"})}),o.jsxs(de,{as:Ba,to:"/workflows/schedules",variant:"primary",className:"shrink-0",children:[o.jsx(hD,{}),"Schedules"]})]})}),o.jsx(yDr,{workflows:e||{},isLoading:t,search:r})]})}const zss={active:"bg-accent1",paused:"bg-accent3"},Bss={active:"text-accent1",paused:"text-accent3"},Q9t=({status:e})=>o.jsxs("span",{className:"inline-flex items-center gap-2 whitespace-nowrap",children:[o.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${zss[e]}`,"aria-hidden":!0}),o.jsx("span",{className:`text-ui-sm ${Bss[e]}`,children:e})]}),Fj=e=>!e||e<=0?"—":new Date(e).toLocaleString(),dP=e=>{if(!e||e<=0)return"—";const t=e-Date.now(),n=Math.abs(t),r=Math.floor(n/1e3);if(r<60)return t>=0?`in ${r}s`:`${r}s ago`;const s=Math.floor(r/60);if(s<60)return t>=0?`in ${s}m`:`${s}m ago`;const a=Math.floor(s/60);if(a<24)return t>=0?`in ${a}h`:`${a}h ago`;const i=Math.floor(a/24);return t>=0?`in ${i}d`:`${i}d ago`};function Y9t({status:e}){const{icon:t,color:n}=Uss(e);return o.jsxs("span",{className:`inline-flex items-center gap-1.5 whitespace-nowrap text-ui-sm ${n}`,children:[o.jsx("span",{className:"inline-flex shrink-0 items-center","aria-hidden":!0,children:t}),o.jsx("span",{children:e})]})}function Uss(e){switch(e){case"success":return{icon:o.jsx(Js,{size:14}),color:"text-accent1"};case"failed":return{icon:o.jsx(vs,{size:14}),color:"text-accent2"};case"running":return{icon:o.jsx(Gt,{}),color:"text-neutral3"};case"suspended":return{icon:o.jsx(lq,{size:14}),color:"text-accent3"};case"canceled":return{icon:o.jsx(Of,{size:14}),color:"text-neutral3"};case"pending":case"waiting":return{icon:o.jsx(dO,{size:14}),color:"text-neutral3"};default:return{icon:null,color:"text-neutral3"}}}const ZQe="auto auto auto auto 1fr";function qss(e){if(e===void 0)return"—";if(e<1e3)return`${e}ms`;if(e<6e4)return`${(e/1e3).toFixed(1)}s`;const t=Math.floor(e/6e4),n=Math.floor(e%6e4/1e3);return`${t}m ${n}s`}function Vss(e){const t=Math.abs(e),n=e<0?"-":"";return t<1e3?`${n}${t}ms`:t<6e4?`${n}${(t/1e3).toFixed(1)}s`:t<36e5?`${n}${(t/6e4).toFixed(1)}m`:`${n}${(t/36e5).toFixed(1)}h`}const Hss=3e4,Wss=5*6e4;function Zss({triggers:e,isLoading:t,workflowId:n,hasNextPage:r,isFetchingNextPage:s,setEndOfListElement:a}){const{Link:i,paths:l}=yn();return t?o.jsx(tl,{columns:ZQe}):e.length===0?o.jsx(ge,{variant:"ui-md",className:"text-neutral4 p-4",children:"No trigger history yet."}):o.jsxs(me,{columns:ZQe,className:"min-w-0",children:[o.jsxs(me.Top,{children:[o.jsx(me.TopCell,{children:"Run"}),o.jsx(me.TopCell,{children:"Status"}),o.jsx(me.TopCell,{children:"Started"}),o.jsx(me.TopCell,{children:"Duration"}),o.jsx(me.TopCell,{children:" "})]}),e.map(c=>{const u=c.actualFireAt-c.scheduledFireAt,d=Vss(u),f=`Scheduled ${Fj(c.scheduledFireAt)} — published ${Fj(c.actualFireAt)} (drift ${d})`,p=c.outcome==="failed",h=p?c.error:c.run?.error,m=Math.abs(u),v=!p&&m>Hss&&m<=Wss,y=`${c.scheduleId}-${c.runId}-${c.actualFireAt}`,b=!!(n&&c.runId&&!p),S=o.jsx("span",{className:b?"text-accent1 font-mono text-ui-sm whitespace-nowrap":"text-neutral3 font-mono text-ui-sm whitespace-nowrap",children:c.runId}),w=o.jsxs(o.Fragment,{children:[o.jsx(me.Cell,{height:"compact",children:S}),o.jsx(me.Cell,{height:"compact",children:o.jsxs("span",{className:"inline-flex items-center gap-2",children:[p?o.jsxs("span",{className:"inline-flex items-center gap-1.5 whitespace-nowrap text-ui-sm text-accent2",children:[o.jsx(Ep,{size:14}),"publish failed"]}):c.run?o.jsx(Y9t,{status:c.run.status}):o.jsx("span",{className:"inline-flex items-center gap-1.5 whitespace-nowrap text-ui-sm text-neutral3",children:"pending"}),h?o.jsxs(Wn,{children:[o.jsx(zn,{asChild:!0,children:o.jsx("span",{className:"text-accent2 inline-flex",children:o.jsx(Ep,{size:14})})}),o.jsx(Bn,{children:h})]}):null]})}),o.jsx(me.Cell,{height:"compact",children:o.jsxs("span",{className:"inline-flex items-center gap-2 whitespace-nowrap",children:[o.jsx("span",{title:f,children:dP(c.actualFireAt)}),v?o.jsxs(Wn,{children:[o.jsx(zn,{asChild:!0,children:o.jsx("span",{className:"text-accent3 inline-flex",children:o.jsx(Ep,{size:14})})}),o.jsxs(Bn,{children:["Published ",d," after the scheduled fire time"]})]}):null]})}),o.jsx(me.Cell,{height:"compact",children:c.run?o.jsx("span",{children:qss(c.run.durationMs)}):o.jsx("span",{className:"text-neutral4",children:"—"})}),o.jsx(me.Cell,{height:"compact",children:" "})]});return b?o.jsx(me.RowLink,{to:l.workflowRunLink(n,c.runId),LinkComponent:i,children:w},y):o.jsx(me.RowStatic,{children:w},y)}),o.jsx(me.NextPageLoading,{isLoading:s,hasMore:r,setEndOfListElement:a})]})}const Gss=e=>{const t=We();return wt({queryKey:["schedule",e],enabled:!!e,queryFn:async()=>{if(!e)throw new Error("scheduleId is required");return t.getSchedule(e)}})},GQe=25,Qss=e=>{const t=We(),{inView:n,setRef:r}=A_(),s=$1({queryKey:["schedule-triggers",e],enabled:!!e,initialPageParam:void 0,queryFn:async({pageParam:u})=>e?t.listScheduleTriggers(e,{limit:GQe,toActualFireAt:u}):{triggers:[]},getNextPageParam:u=>{if(!(!u?.triggers?.length||u.triggers.length<GQe))return u.triggers[u.triggers.length-1].actualFireAt},refetchInterval:u=>(u.state.data?.pages.flatMap(p=>p.triggers)??[]).some(p=>p.run?p.run.status==="pending"||p.run.status==="running"||p.run.status==="waiting":p.outcome==="published")?5e3:!1}),a=s.data?.pages.flatMap(u=>u?.triggers??[])??[],{hasNextPage:i,isFetchingNextPage:l,fetchNextPage:c}=s;return g.useEffect(()=>{n&&i&&!l&&c()},[n,i,l,c]),{...s,data:a,setEndOfListElement:r}},Yss=e=>{const t=We(),n=Hr();return Rn({mutationFn:async r=>{if(!e)throw new Error("scheduleId is required");return r==="pause"?t.pauseSchedule(e):t.resumeSchedule(e)},onSuccess:(r,s)=>{n.invalidateQueries({queryKey:["schedule",e]}),n.invalidateQueries({queryKey:["schedules"]}),De.success(s==="pause"?"Schedule paused":"Schedule resumed")},onError:r=>{De.error(r.message)}})};function fF({label:e,children:t}){return o.jsxs("div",{className:"flex flex-col gap-1",children:[o.jsx(ge,{variant:"ui-xs",className:"text-neutral4 uppercase tracking-wide",children:e}),o.jsx("div",{className:"text-ui-md",children:t})]})}function Xss(){const{scheduleId:e}=ur(),{paths:t}=yn(),{data:n,error:r}=Gss(e),{data:s,isLoading:a,error:i,hasNextPage:l,isFetchingNextPage:c,setEndOfListElement:u}=Qss(e),d=Yss(e);if(r&&gs(r))return o.jsx(lr,{children:o.jsx(Vs,{})});if(r&&ys(r))return o.jsx(lr,{children:o.jsx(Ds,{resource:"schedules"})});if(r)return o.jsx(lr,{children:o.jsx(zi,{title:"Failed to load schedule",message:r.message})});const f=n?.target.type==="workflow"?n.target.workflowId:void 0;return o.jsxs(Lt,{children:[o.jsx(Lt.TopArea,{children:o.jsx(Lt.Row,{className:"justify-end",children:o.jsxs(Lt.Column,{className:"flex justify-end gap-2",children:[o.jsxs(de,{as:Ba,to:t.schedulesLink(),variant:"ghost",children:[o.jsx(Nc,{}),"Back to schedules"]}),f?o.jsx(de,{as:Ba,to:t.workflowLink(f),variant:"ghost",children:"Open workflow"}):null,n?o.jsx(de,{onClick:()=>d.mutate(n.status==="active"?"pause":"resume"),disabled:d.isPending,"data-testid":"schedule-toggle-button",children:n.status==="active"?o.jsxs(o.Fragment,{children:[o.jsx(Qlt,{}),"Pause"]}):o.jsxs(o.Fragment,{children:[o.jsx(Fp,{}),"Resume"]})}):null]})})}),n?o.jsxs("div",{className:"grid gap-6 h-full overflow-hidden grid-cols-[minmax(0,20rem)_1fr]",children:[o.jsxs("div",{className:"flex flex-col gap-4 border border-border1 rounded-md p-4 h-fit",children:[o.jsx(fF,{label:"Workflow",children:f?o.jsx(Ba,{to:t.workflowLink(f),className:"text-accent1 hover:underline",children:f}):"—"}),o.jsxs(fF,{label:"Cron",children:[o.jsx("code",{className:"font-mono text-ui-md",children:n.cron}),n.timezone?o.jsx("span",{className:"text-neutral4 ml-2 text-ui-sm",children:n.timezone}):null]}),o.jsx(fF,{label:"Status",children:o.jsx(Q9t,{status:n.status})}),o.jsx(fF,{label:"Next fire",children:o.jsx("span",{title:Fj(n.nextFireAt),children:dP(n.nextFireAt)})})]}),o.jsxs("div",{className:"overflow-y-auto","data-testid":"schedule-triggers-panel",children:[o.jsx(ge,{variant:"ui-md",className:"mb-3",children:"Trigger history"}),i?o.jsx(zi,{title:"Failed to load trigger history",message:i.message}):o.jsx(Zss,{triggers:s??[],isLoading:a,workflowId:f,hasNextPage:l,isFetchingNextPage:c,setEndOfListElement:u})]})]}):null]})}const QQe="minmax(0, 1.2fr) minmax(0, 1.4fr) minmax(0, 1fr) auto auto auto";function Kss({schedules:e,isLoading:t,search:n=""}){const{paths:r,Link:s}=yn(),a=g.useMemo(()=>{const i=n.toLowerCase();return i?e.filter(l=>l.id.toLowerCase().includes(i)||l.target.workflowId.toLowerCase().includes(i)):e},[e,n]);return t?o.jsx(tl,{columns:QQe}):o.jsxs(me,{columns:QQe,variant:"striped",className:"min-w-0",children:[o.jsxs(me.Top,{children:[o.jsx(me.TopCell,{children:"Workflow"}),o.jsx(me.TopCell,{children:"Schedule ID"}),o.jsx(me.TopCell,{children:"Cron"}),o.jsx(me.TopCell,{children:"Status"}),o.jsx(me.TopCell,{children:"Next fire"}),o.jsx(me.TopCell,{children:"Last run"})]}),a.length===0&&n?o.jsx(me.NoMatch,{message:"No schedules match your search"}):null,a.length===0&&!n?o.jsx(me.NoMatch,{message:"No schedules configured"}):null,a.map(i=>o.jsxs(me.RowLink,{to:r.scheduleLink(i.id),LinkComponent:s,children:[o.jsx(me.NameCell,{children:i.target.workflowId}),o.jsx(me.Cell,{height:"compact",className:"min-w-0",children:o.jsx("span",{className:"block truncate font-mono text-ui-smd text-neutral3",title:i.id,children:i.id})}),o.jsx(me.Cell,{height:"compact",children:o.jsxs("span",{className:"inline-flex items-center gap-2 whitespace-nowrap",children:[o.jsx("code",{className:"font-mono text-ui-sm",children:i.cron}),i.timezone?o.jsx("span",{className:"text-neutral4 text-ui-xs",children:i.timezone}):null]})}),o.jsx(me.Cell,{height:"compact",children:o.jsx(Q9t,{status:i.status})}),o.jsx(me.Cell,{height:"compact",children:o.jsx("span",{className:"whitespace-nowrap",title:Fj(i.nextFireAt),children:dP(i.nextFireAt)})}),o.jsx(me.Cell,{height:"compact",children:i.lastRun?o.jsxs("span",{className:"inline-flex items-center gap-2 whitespace-nowrap",children:[o.jsx(Y9t,{status:i.lastRun.status}),o.jsx("span",{className:"text-neutral4 text-ui-sm",title:Fj(i.lastFireAt),children:i.lastFireAt?dP(i.lastFireAt):""})]}):i.lastFireAt?o.jsx("span",{className:"whitespace-nowrap",title:Fj(i.lastFireAt),children:dP(i.lastFireAt)}):o.jsx("span",{className:"text-neutral4",children:"Never"})})]},i.id))]})}function Jss({workflowId:e}={}){const{data:t,isLoading:n,error:r}=Kxe(e?{workflowId:e}:{}),[s,a]=g.useState("");return r?o.jsx(zi,{title:"Failed to load schedules",message:r.message}):o.jsxs("div",{className:"grid grid-rows-[auto_1fr] gap-4 h-full overflow-hidden",children:[o.jsx("div",{className:"max-w-120",children:o.jsx(jf,{onSearch:a,label:"Filter schedules",placeholder:"Filter by id or workflow"})}),o.jsx("div",{className:"overflow-y-auto",children:o.jsx(Kss,{schedules:t??[],isLoading:n,search:s})})]})}function eas(){const[e]=ga(),t=e.get("workflowId")??void 0,{error:n}=Kxe(t?{workflowId:t}:{});return n&&gs(n)?o.jsx(lr,{children:o.jsx(Vs,{})}):n&&ys(n)?o.jsx(lr,{children:o.jsx(Ds,{resource:"schedules"})}):o.jsx(Lt,{children:o.jsx("div",{className:"h-full",children:o.jsx(Jss,{workflowId:t})})})}function tas({stepGraph:e,open:t,workflowName:n}){const{nodes:r,edges:s}=N1e({stepGraph:e}),[a,i]=g.useState(!1),[l,c,u]=vwt(r),[d]=ywt(s),{edgeTypes:f,nodeTypes:p,styledEdges:h}=R2t({edges:d,workflowName:n,stepGraph:e});return g.useEffect(()=>{if(t){const m=setTimeout(()=>{i(!0)},500);return()=>clearTimeout(m)}},[t]),o.jsx("div",{className:"w-full h-full relative bg-surface1",children:a?o.jsxs(gwt,{nodes:l,edges:h,edgeTypes:f,fitView:!0,fitViewOptions:{maxZoom:1},minZoom:.01,maxZoom:1,nodeTypes:p,onNodesChange:u,children:[o.jsx(W_e,{position:"bottom-left"}),o.jsx(xwt,{variant:ey.Lines,gap:12,size:.5})]}):o.jsx("div",{className:"w-full h-full flex items-center justify-center",children:o.jsx(Gt,{})})})}function nas(){const{stepDetail:e,closeStepDetail:t}=ZV();return e?o.jsxs("div",{className:"flex flex-col h-full","data-testid":"workflow-step-detail-panel",children:[o.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border1 bg-surface1",children:[o.jsxs("div",{className:"flex items-center gap-2",children:[e.type==="map-config"&&o.jsx(efe,{className:"w-4 h-4",style:{color:Cu.map}}),e.type==="nested-graph"&&o.jsx(jd,{className:"w-4 h-4",style:{color:Cu.workflow}}),o.jsxs("div",{className:"flex flex-col",children:[o.jsx(ge,{variant:"ui-md",className:"text-neutral6 font-medium",children:e.type==="map-config"?`${e.stepName} Config`:`${e.stepName} Workflow`}),e.type==="map-config"&&e.stepId&&e.stepId!==e.stepName&&o.jsx(ge,{variant:"ui-xs",className:"text-neutral3",children:e.stepId})]})]}),o.jsx("button",{onClick:t,className:"p-1 hover:bg-surface3 rounded transition-colors","aria-label":"Close",children:o.jsx(vs,{className:"w-4 h-4 text-neutral3"})})]}),o.jsxs("div",{className:"flex-1 overflow-auto",children:[e.type==="map-config"&&e.mapConfig&&o.jsx(iP,{data:e.mapConfig}),e.type==="nested-graph"&&e.nestedGraph&&o.jsx("div",{className:"h-full min-h-[400px]",children:o.jsx(T1e,{children:o.jsx(tas,{stepGraph:e.nestedGraph.stepGraph,open:!0,workflowName:e.nestedGraph.fullStep})},`nested-graph-${e.nestedGraph.fullStep}`)})]})]}):null}function ras(e){const t=new Blob([JSON.stringify(e??null)]).size;return t<1024?`${t} B`:`${(t/1024).toFixed(1)} KB`}function sas(e,t){if(e&&typeof e=="object"&&!Array.isArray(e)){const n=Object.keys(e);if(n.length===1)return n[0]}return t}function aas({suspendedSteps:e,workflow:t,isStreaming:n,onResume:r}){return n||e.length===0?null:o.jsxs("div",{className:"space-y-5 rounded-lg border border-border1 bg-surface4 p-5","data-testid":"workflow-suspended-steps",children:[o.jsxs("div",{className:"flex items-center justify-between gap-3",children:[o.jsxs(ge,{as:"p",variant:"ui-md",className:"flex items-center gap-2 text-neutral6 font-semibold",children:[o.jsx(Ue,{children:o.jsx(lq,{})}),"Step suspended"]}),o.jsx(dn,{variant:"warning",children:"Needs input"})]}),e.map((s,a)=>{const i=t.allSteps[s.stepId];if(!i||i.isWorkflow)return null;const l=i?.resumeSchema?lm(im(yx(i.resumeSchema))):op(dr(),cT());return o.jsx(ias,{step:s,stepSchema:l,description:i.description,isStreaming:n,onResume:r},`${s.runId}-${s.stepId}-${a}`)})]})}function ias({step:e,stepSchema:t,description:n,isStreaming:r,onResume:s}){const[a,i]=g.useState(!1);return o.jsxs("div",{className:"space-y-5",children:[o.jsxs("div",{className:"space-y-2",children:[o.jsx(ge,{as:"p",variant:"ui-md",className:"text-neutral6 font-medium truncate",children:e.stepId}),n&&o.jsx(ge,{as:"p",variant:"ui-sm",className:"text-neutral3",children:n})]}),e.suspendPayload&&o.jsxs("div",{className:"space-y-2",children:[o.jsxs(ge,{as:"p",variant:"ui-sm",className:"flex items-center gap-2 text-neutral3",children:[o.jsx(Ue,{children:o.jsx(kdn,{})}),"The step is asking"]}),o.jsxs(xf,{open:a,onOpenChange:i,children:[o.jsxs(Od,{className:"flex w-full items-center justify-between gap-2 rounded-lg border border-border1 bg-surface3 px-3 py-2.5",children:[o.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[o.jsx(Ue,{children:o.jsx(ta,{className:K("transition-transform text-neutral3",{"transform rotate-90":a})})}),o.jsx(ge,{as:"span",variant:"ui-md",className:"text-neutral6 truncate",children:sas(e.suspendPayload,e.stepId)})]}),o.jsx(ge,{as:"span",variant:"ui-sm",className:"text-neutral3 shrink-0",children:ras(e.suspendPayload)})]}),o.jsx(_d,{children:o.jsx("div",{"data-testid":"suspended-payload",className:"pt-2",children:o.jsx(Qr,{data:e.suspendPayload,className:"w-full overflow-x-auto p-2",showCopyButton:!1})})})]})]}),o.jsxs("div",{className:"space-y-3",children:[o.jsxs(ge,{as:"p",variant:"ui-sm",className:"flex items-center gap-2 text-neutral3",children:[o.jsx(Ue,{children:o.jsx(Cdn,{})}),"Your response"]}),o.jsx("div",{className:"-mx-5",children:o.jsx(B7,{schema:t,isSubmitLoading:r,submitButtonLabel:"Resume",submitButtonIcon:o.jsx(Fp,{}),submitButtonFullWidth:!0,collapsible:!1,hideHeading:!0,hideInputTypeLabel:!0,onSubmit:l=>{const c=e.stepId?.split(".");s({stepId:c,runId:e.runId,suspendPayload:e.suspendPayload,resumeData:l,isLoading:!1})}})})]})]})}function oas(){const{result:e,runSnapshot:t,workflow:n,runId:r,isStreamingWorkflow:s}=g.useContext($l),{runId:a}=ur(),i=Ewt(e,r??""),l=LZn(),c=!!a,u=t?.status==="suspended",f=!!(a&&r&&a===r)&&e?.status==="suspended";return s||!n||i.length===0||c&&!u&&!f?null:o.jsx("div",{"data-testid":"workflow-suspended-overlay",className:"absolute top-2 right-2 z-20 w-[380px] max-w-[calc(100%-1rem)] max-h-[calc(100%-1rem)] overflow-y-auto rounded-lg shadow-lg animate-in fade-in-0 slide-in-from-top-2 zoom-in-95 duration-300",children:o.jsx(aas,{suspendedSteps:i,workflow:n,isStreaming:s,onResume:l})},r)}const las=e=>o.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:[o.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M5.99982 2.0625C3.8252 2.0625 2.06232 3.82538 2.06232 6C2.06232 8.17462 3.8252 9.9375 5.99982 9.9375C8.17444 9.9375 9.93732 8.17462 9.93732 6C9.93732 3.82538 8.17444 2.0625 5.99982 2.0625ZM0.937317 6C0.937317 3.20406 3.20388 0.9375 5.99982 0.9375C8.79576 0.9375 11.0623 3.20406 11.0623 6C11.0623 8.79594 8.79576 11.0625 5.99982 11.0625C3.20388 11.0625 0.937317 8.79594 0.937317 6Z",fill:"currentColor"}),o.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M7.97865 4.57004C8.22604 4.75795 8.27426 5.11082 8.08635 5.35821L6.05486 8.03279C5.94873 8.17251 5.78348 8.25471 5.60803 8.25505C5.43257 8.2554 5.267 8.17385 5.16032 8.03454L3.80937 6.27034C3.6205 6.02369 3.66733 5.67063 3.91398 5.48176C4.16063 5.29288 4.51369 5.33972 4.70257 5.58637L5.6051 6.76498L7.19048 4.67774C7.37839 4.43036 7.73126 4.38213 7.97865 4.57004Z",fill:"currentColor"})]}),cas=e=>o.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:[o.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M5.99982 2.0625C3.8252 2.0625 2.06232 3.82538 2.06232 6C2.06232 8.17462 3.8252 9.9375 5.99982 9.9375C8.17444 9.9375 9.93732 8.17462 9.93732 6C9.93732 3.82538 8.17444 2.0625 5.99982 2.0625ZM0.937317 6C0.937317 3.20406 3.20388 0.9375 5.99982 0.9375C8.79576 0.9375 11.0623 3.20406 11.0623 6C11.0623 8.79594 8.79576 11.0625 5.99982 11.0625C3.20388 11.0625 0.937317 8.79594 0.937317 6Z",fill:"currentColor"}),o.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M7.89741 4.10293C8.11707 4.32261 8.11706 4.67877 7.89738 4.89843L6.79517 6.00058L7.8962 7.10155C8.11588 7.32122 8.11589 7.67737 7.89623 7.89705C7.67656 8.11673 7.32041 8.11674 7.10073 7.89707L5.99965 6.79605L4.89856 7.89707C4.67889 8.11673 4.32273 8.11672 4.10307 7.89704C3.88341 7.67737 3.88342 7.32121 4.10309 7.10155L5.20413 6.00058L4.10191 4.89843C3.88224 4.67877 3.88223 4.32262 4.10189 4.10294C4.32155 3.88326 4.67771 3.88325 4.89738 4.10292L5.99965 5.20511L7.10191 4.10291C7.32159 3.88325 7.67774 3.88326 7.89741 4.10293Z",fill:"currentColor"})]}),uas=e=>e.includes("."),das=e=>e==="input"||e.endsWith(".input"),fas=1;function pas(e){return`${Number((e/1e3).toPrecision(3))}s`}function has(e,t){const n=Object.entries(e).filter(([i])=>!das(i));if(n.length===0)return[];const r=Math.min(...n.map(([,i])=>i.startedAt)),s=Math.max(...n.map(([,i])=>i.endedAt??t)),a=Math.max(s-r,1);return n.map(([i,l])=>{const c=l.endedAt===void 0,d=(l.endedAt??t)-l.startedAt,f=(l.startedAt-r)/a*100,p=Math.max(d/a*100,fas);return{stepId:i,step:l,status:l.status,offsetPct:f,widthPct:p,durationMs:d,isRunning:c,isNestedEntry:uas(i)}})}const mas=({status:e})=>o.jsxs(Ue,{children:[e==="success"&&o.jsx(las,{className:"text-accent1"}),e==="failed"&&o.jsx(cas,{className:"text-accent2"}),e==="suspended"&&o.jsx(lq,{className:"text-accent3"}),e==="waiting"&&o.jsx(Jde,{className:"text-accent5"}),e==="skipped"&&o.jsx(Jde,{className:"text-icon3"}),e==="running"&&o.jsx(oa,{className:"text-accent6 animate-spin"})]}),gas={success:"bg-accent1",failed:"bg-accent2",suspended:"bg-accent3",waiting:"bg-accent5",skipped:"bg-border1",running:"bg-accent6"};function X9t(e){return e.split(/[-_.\s]+/).filter(Boolean).map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join(" ")}const YQe=e=>e&&typeof e=="object"&&!Array.isArray(e)?e:{value:e},vas=e=>{const t=e;return O2t({duration:t.duration,date:t.date,isForEach:t.isForEach,mapConfig:t.mapConfig,canSuspend:t.canSuspend,isParallel:t.isParallel,stepGraph:t.stepGraph})},yas=({row:e,index:t,isSelected:n,isHovered:r,onSelectStep:s,onHoverStep:a,onOpenInput:i,onOpenOutput:l})=>{const c=vas(e.step),u=e.status==="running",d=!e.isNestedEntry;return o.jsxs("div",{role:"button",tabIndex:0,"data-testid":"workflow-timeline-row","data-workflow-step-key":e.stepId,"data-workflow-step-active":n?"true":void 0,"data-workflow-step-hovered":r?"true":void 0,"data-workflow-step-nested":e.isNestedEntry?"true":void 0,"aria-pressed":n,"aria-disabled":!d,onMouseEnter:()=>{d&&a(e.stepId)},onMouseLeave:()=>{d&&a(null)},onClick:()=>{d&&s(e.stepId)},onKeyDown:f=>{!d||f.key!=="Enter"&&f.key!==" "||(f.preventDefault(),s(e.stepId))},className:K("grid grid-cols-[auto_auto_auto_minmax(0,10rem)_minmax(0,1fr)_auto_5rem] items-center gap-2 rounded-md border border-transparent px-2 py-1 text-left transition-colors focus-visible:outline-hidden focus-visible:ring-1 focus-visible:ring-accent1",d&&"cursor-pointer",d&&"hover:bg-surface4",d&&r&&!n&&"border-neutral6 bg-surface4",d&&n&&"border-accent1",e.isNestedEntry&&"cursor-default opacity-55"),children:[o.jsx("div",{className:"flex justify-center",children:o.jsx(mas,{status:e.status})}),o.jsx("div",{className:"flex justify-center",children:o.jsx(de,{type:"button",variant:"ghost",size:"icon-sm",tooltip:"View step input",disabled:u,className:"text-neutral3 hover:text-neutral6 disabled:cursor-not-allowed disabled:opacity-40",onClick:f=>{f.stopPropagation(),u||i(e)},children:o.jsx(Ofn,{})})}),o.jsx("div",{className:"flex overflow-hidden",children:o.jsx(hU,{indicators:c,className:"shrink-0"})}),o.jsx(ge,{as:"span",variant:"ui-sm",className:"block min-w-0 max-w-full justify-self-stretch overflow-hidden text-ellipsis whitespace-nowrap text-left text-neutral6",children:X9t(e.stepId)}),o.jsx("div",{className:"relative h-2 min-w-0 rounded bg-surface4",children:o.jsx("div",{"data-testid":"workflow-timeline-bar","data-offset":String(e.offsetPct),"data-width":String(e.widthPct),className:`absolute top-0 h-full rounded ${gas[e.status]}`,style:{left:`${e.offsetPct}%`,width:`${e.widthPct}%`}})}),o.jsx("div",{className:"flex justify-center",children:o.jsx(de,{type:"button",variant:"ghost",size:"icon-sm",tooltip:"View step output",disabled:u,className:"text-neutral3 hover:text-neutral6 disabled:cursor-not-allowed disabled:opacity-40",onClick:f=>{f.stopPropagation(),u||l(e)},children:o.jsx(Sfn,{})})}),o.jsx(ge,{as:"span",variant:"ui-sm",className:"w-20 justify-self-end text-right text-neutral3 tabular-nums",children:pas(e.durationMs)})]},`timeline-item-${e.stepId}-${t}`)};function bas(){const{steps:e}=u4(),{selectedStepId:t,hoverStepId:n,setSelectedStepId:r,setHoverStepId:s}=sV(),[a,i]=g.useState(()=>Date.now()),[l,c]=g.useState(!1),[u,d]=g.useState(null),f=g.useRef(null);i0e(f,{enabled:!l});const p=has(e,a),h=p.some(m=>m.isRunning);return g.useEffect(()=>{if(!h)return;const m=setInterval(()=>i(Date.now()),100);return()=>clearInterval(m)},[h]),g.useEffect(()=>{if(l||p.length===0)return;const m=f.current;m&&(m.scrollTop=m.scrollHeight)},[l,p.length]),p.length===0?null:o.jsxs(o.Fragment,{children:[o.jsx("div",{"data-testid":"workflow-timeline",className:"pointer-events-none absolute right-0 bottom-0 z-20 px-2 pb-2",style:{left:"var(--workflow-left-panel-width, 0px)"},children:o.jsxs("div",{className:"pointer-events-auto flex max-h-64 w-full min-w-0 flex-col gap-3 overflow-hidden rounded-studio-panel border border-border1/50 bg-surface3 p-4 shadow-lg",children:[o.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-3",children:[o.jsx(ge,{as:"p",variant:"ui-md",className:"text-neutral3",children:"Timeline"}),o.jsx("button",{type:"button","aria-label":l?"Expand timeline":"Collapse timeline","aria-expanded":!l,onClick:()=>c(m=>!m),className:"rounded-md p-1 text-neutral3 transition-colors hover:bg-surface4 hover:text-neutral6",children:o.jsx(Sa,{className:K("h-4 w-4 transition-transform",l&&"-rotate-90")})})]}),!l&&o.jsx("div",{ref:f,"data-testid":"workflow-timeline-list",className:"flex min-h-0 flex-col gap-2 overflow-y-auto",children:p.map((m,v)=>o.jsx(yas,{row:m,index:v,isSelected:t===m.stepId,isHovered:n===m.stepId,onSelectStep:r,onHoverStep:s,onOpenInput:y=>d({type:"input",stepId:y.stepId,data:YQe(y.step.input)}),onOpenOutput:y=>d({type:"output",stepId:y.stepId,data:YQe(y.step.output)})},`timeline-item-${m.stepId}-${v}`))})]})}),o.jsx(br,{open:!!u,onOpenChange:m=>!m&&d(null),children:u&&o.jsx(Twt,{data:u.data,title:`${X9t(u.stepId)} ${u.type==="input"?"input":"output"}`})})]})}const xas=({workflowId:e,workflow:t,isLoading:n})=>{const{stepDetail:r}=ZV();return o.jsxs("div",{className:"flex h-full min-h-0",children:[o.jsx("div",{className:"flex h-full min-h-0 flex-1 flex-col",children:o.jsxs("div",{className:"relative min-h-0 flex-1 p-2 pb-0",children:[o.jsx(B2t,{workflowId:e,workflow:t,isLoading:n}),o.jsx(oas,{}),o.jsx(bas,{})]})}),r&&o.jsx("div",{className:"w-[420px] min-h-0 overflow-hidden border-l border-border1",children:o.jsx(nas,{})})]})},XQe=()=>{const{workflowId:e}=ur(),{data:t,isLoading:n,error:r}=S3(e);return r&&gs(r)?o.jsx("div",{className:"flex h-full items-center justify-center",children:o.jsx(Vs,{})}):r&&ys(r)?o.jsx("div",{className:"flex h-full items-center justify-center",children:o.jsx(Ds,{resource:"workflows"})}):o.jsx(Z1e,{children:o.jsx(xas,{workflowId:e,workflow:t??void 0,isLoading:n})})};function was(e,t){if(e==null)return{};var n,r,s=Rbt(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(s[n]=e[n])}return s}function Gve(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function Sas(e){if(Array.isArray(e))return Gve(e)}function kas(e){if(typeof Symbol<"u"&&e[Symbol.iterator]!=null||e["@@iterator"]!=null)return Array.from(e)}function Oas(e,t){if(e){if(typeof e=="string")return Gve(e,t);var n={}.toString.call(e).slice(8,-1);return n==="Object"&&e.constructor&&(n=e.constructor.name),n==="Map"||n==="Set"?Array.from(e):n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?Gve(e,t):void 0}}function _as(){throw new TypeError(`Invalid attempt to spread non-iterable instance.
|
|
727
|
+
]`})]})]})}function Ses({errors:e,maxErrors:t=5}){if(e.length===0)return null;const n=e.slice(0,t),r=e.length-t;return o.jsxs("div",{className:"bg-accent2/10 border border-accent2/30 rounded-md p-3",children:[o.jsxs("div",{className:"flex items-center gap-2 text-accent2 mb-2",children:[o.jsx(Ue,{children:o.jsx(Ep,{className:"w-4 h-4"})}),o.jsxs("span",{className:"font-medium text-sm",children:[e.length," validation error",e.length!==1?"s":""]})]}),o.jsx("ul",{className:"text-sm text-accent2/80 space-y-1",children:n.map((s,a)=>o.jsxs("li",{className:"flex gap-2",children:[o.jsx("span",{className:"shrink-0",children:"•"}),o.jsx("span",{children:s.message})]},a))}),r>0&&o.jsxs("div",{className:"text-xs text-accent2/60 mt-2",children:["+",r," more error",r!==1?"s":""]})]})}function kes({datasetId:e,open:t,onOpenChange:n,onSuccess:r}){const[s,a]=g.useState("upload"),[i,l]=g.useState(null),[c,u]=g.useState({current:0,total:0}),[d,f]=g.useState(null),[p,h]=g.useState(!1),{parseFile:m,isParsing:v,error:y}=QKr(),{batchInsertItems:b}=Ei(),S=g.useCallback(async I=>{try{const R=await m(I);l(R),a("preview")}catch{}},[m]),w=g.useCallback(async()=>{if(!i||i.items.length===0)return;a("importing"),h(!0);const{items:I}=i;u({current:0,total:I.length});try{await b.mutateAsync({datasetId:e,items:I.map(R=>({input:R.input,groundTruth:R.groundTruth,metadata:R.metadata}))}),f({success:I.length,errors:0})}catch{f({success:0,errors:I.length})}u({current:I.length,total:I.length}),h(!1),a("complete")},[i,b,e]),k=g.useCallback(()=>{n(!1),r?.(),d&&d.success>0&&De.success(`Imported ${d.success} item${d.success!==1?"s":""}`),setTimeout(()=>{a("upload"),l(null),u({current:0,total:0}),f(null)},150)},[n,r,d]),_=g.useCallback(()=>{p||(n(!1),setTimeout(()=>{a("upload"),l(null),u({current:0,total:0}),f(null)},150))},[p,n]),C=i&&i.items.length>0&&i.errors.length===0,E=()=>{switch(s){case"upload":return o.jsx(wes,{onFileSelect:S,isParsing:v,error:y?.message});case"preview":return i?o.jsx("div",{className:"flex flex-col gap-4",children:i.errors.length>0?o.jsxs(o.Fragment,{children:[o.jsx(Ses,{errors:i.errors}),o.jsx("div",{className:"text-sm text-neutral4",children:"Please fix the errors in your JSON file and try again."})]}):o.jsxs(o.Fragment,{children:[o.jsxs("div",{className:"text-sm text-neutral4",children:["Found ",i.items.length," valid item",i.items.length!==1?"s":""," to import."]}),o.jsx(xes,{items:i.items,maxRows:5})]})}):null;case"importing":return o.jsxs("div",{className:"flex flex-col items-center gap-4 py-8",children:[o.jsx(Gt,{}),o.jsxs("div",{className:"text-center",children:[o.jsx("div",{className:"text-lg font-medium text-neutral1",children:"Importing items..."}),o.jsxs("div",{className:"text-sm text-neutral4 mt-1",children:[c.current," of ",c.total]})]})]});case"complete":return o.jsxs("div",{className:"flex flex-col items-center gap-4 py-8",children:[o.jsx("div",{className:"text-4xl",children:d&&d.errors===0?"✓":"⚠"}),o.jsxs("div",{className:"text-center",children:[o.jsx("div",{className:"text-lg font-medium text-neutral1",children:"Import Complete"}),o.jsxs("div",{className:"text-sm text-neutral4 mt-1",children:[d?.success??0," item",d?.success!==1?"s":""," imported",d&&d.errors>0&&o.jsxs("span",{className:"text-accent2",children:[" ","(",d.errors," error",d.errors!==1?"s":"",")"]})]})]})]})}},j=()=>{switch(s){case"upload":return o.jsx(de,{onClick:_,children:"Cancel"});case"preview":return o.jsxs(o.Fragment,{children:[o.jsx(de,{onClick:()=>a("upload"),children:"Back"}),o.jsxs(de,{variant:"primary",onClick:w,disabled:!C,children:["Import ",i?.items.length??0," Item",i?.items.length!==1?"s":""]})]});case"importing":return null;case"complete":return o.jsx(de,{variant:"primary",onClick:k,children:"Done"})}},N={upload:"Import JSON",preview:"Preview Data",importing:"Importing",complete:"Import Complete"};return o.jsx(br,{open:t,onOpenChange:_,children:o.jsxs(xr,{className:"max-w-2xl max-h-[90vh]",children:[o.jsxs(wr,{children:[o.jsx(gr,{children:N[s]}),o.jsx(Qs,{children:"Import dataset items from a JSON file."})]}),o.jsx(Rr,{className:"min-h-[200px] max-h-[50vh] overflow-y-auto",children:E()}),o.jsx(Cc,{className:"px-6 pt-4 flex justify-end gap-2",children:j()})]})})}const xTe=e=>{const t=We(),{data:n}=tD(e),r=n?.experiments;return wt({queryKey:["dataset-review-items",e,r?.map(s=>s.id)],queryFn:async()=>!r||r.length===0?[]:(await Promise.all(r.map(async a=>{if(!a.datasetId)return[];try{const{results:i}=await t.listDatasetExperimentResults(a.datasetId,a.id);return i.filter(l=>l.status==="needs-review").map(l=>({id:l.id,input:l.input,output:l.output,error:l.error,itemId:l.itemId,experimentId:l.experimentId,datasetId:a.datasetId??void 0,traceId:l.traceId??void 0,scores:l.scores?Object.fromEntries(l.scores.map(c=>[c.scorerId,c.score??0])):{},tags:l.tags??[],comment:""}))}catch{return[]}}))).flat(),enabled:!!e&&!!r&&r.length>0,refetchOnWindowFocus:!1})},Oes=e=>{const t=We(),{data:n}=tD(e),r=n?.experiments;return wt({queryKey:["dataset-completed-items",e,r?.map(s=>s.id)],queryFn:async()=>!r||r.length===0?[]:(await Promise.all(r.map(async a=>{if(!a.datasetId)return[];try{const{results:i}=await t.listDatasetExperimentResults(a.datasetId,a.id);return i.filter(l=>l.status==="complete").map(l=>({id:l.id,input:l.input,output:l.output,error:l.error,itemId:l.itemId,experimentId:l.experimentId,datasetId:a.datasetId??void 0,traceId:l.traceId??void 0,scores:l.scores?Object.fromEntries(l.scores.map(c=>[c.scorerId,c.score??0])):{},tags:l.tags??[],comment:""}))}catch{return[]}}))).flat(),enabled:!!e&&!!r&&r.length>0,refetchOnWindowFocus:!1})};function _es(e,t){if(typeof e=="string")return e.length>t?e.slice(0,t)+"...":e;try{const n=JSON.stringify(e);return n.length>t?n.slice(0,t)+"...":n}catch{return String(e)}}function A9t({datasetId:e,experimentId:t,featuredItemId:n}){const r=We(),{data:s}=Hx(e),{data:a,isLoading:i}=xTe(e),{data:l,isLoading:c}=Oes(e),u=g.useMemo(()=>t?(a??[]).filter(Ee=>Ee.experimentId===t):a,[a,t]),d=g.useMemo(()=>t?(l??[]).filter(Ee=>Ee.experimentId===t):l,[l,t]),{updateExperimentResult:f}=Ei(),[p,h]=g.useState(n??null);g.useEffect(()=>{n!==void 0&&h(n)},[n]);const[m,v]=g.useState(null),[y,b]=g.useState(new Set),[S,w]=g.useState(!1),[k,_]=g.useState(!1),[C,E]=g.useState(!1),[j,N]=g.useState(""),[I,R]=g.useState(""),[P,L]=g.useState(""),[M,q]=g.useState([]),[H,F]=g.useState(!1),[z,B]=g.useState(null),D=g.useMemo(()=>z??u??[],[z,u]);g.useEffect(()=>{B(null)},[e,t]),g.useEffect(()=>{u&&z===null&&B(u)},[u,z]);const Q=g.useMemo(()=>{const Ee=new Set;if(s?.tags)for(const _e of s.tags)Ee.add(_e);for(const _e of D)for(const Ce of _e.tags)Ee.add(Ce);return[...Ee].sort()},[s,D]),V=g.useCallback(Ee=>{!s||!e||(s.tags??[]).includes(Ee)},[s,e]),$=g.useMemo(()=>m?m==="__untagged__"?D.filter(Ee=>Ee.tags.length===0):D.filter(Ee=>Ee.tags.includes(m)):D,[D,m]),U=g.useMemo(()=>{const Ee=new Map;for(const _e of D)for(const Ce of _e.tags)Ee.set(Ce,(Ee.get(Ce)??0)+1);return[...Ee.entries()].sort((_e,Ce)=>Ce[1]-_e[1])},[D]),Z=g.useMemo(()=>D.filter(Ee=>Ee.tags.length===0).length,[D]),X=g.useMemo(()=>{let Ee=0;return m&&Ee++,S&&Ee++,Ee},[m,S]),te=g.useCallback((Ee,_e)=>{B(Oe=>(Oe??[]).map(Re=>Re.id===Ee?{...Re,tags:_e}:Re));const Ce=D.find(Oe=>Oe.id===Ee);Ce?.experimentId&&Ce?.datasetId&&f.mutate({datasetId:Ce.datasetId,experimentId:Ce.experimentId,resultId:Ce.id,tags:_e})},[D,f]),J=g.useCallback((Ee,_e)=>{const Ce=D.find(Oe=>Oe.id===Ee);Ce?.traceId&&_e!==void 0&&r.createFeedback({feedback:{traceId:Ce.traceId,source:"studio",feedbackSource:"studio",feedbackType:"rating",value:_e==="positive"?1:-1,experimentId:Ce.experimentId??void 0,sourceId:Ce.id}}).catch(()=>{}),B(Oe=>(Oe??[]).map(Re=>Re.id===Ee?{...Re,rating:_e}:Re))},[D,r]),ee=g.useCallback((Ee,_e)=>{const Ce=D.find(Oe=>Oe.id===Ee);Ce?.traceId&&r.createFeedback({feedback:{traceId:Ce.traceId,source:"studio",feedbackSource:"studio",feedbackType:"comment",value:_e,comment:_e,experimentId:Ce.experimentId??void 0,sourceId:Ce.id}}).catch(()=>{}),B(Oe=>(Oe??[]).map(Re=>Re.id===Ee?{...Re,comment:_e}:Re))},[D,r]),ae=g.useCallback(Ee=>{const _e=D.find(Ce=>Ce.id===Ee);B(Ce=>(Ce??[]).filter(Oe=>Oe.id!==Ee)),b(Ce=>{const Oe=new Set(Ce);return Oe.delete(Ee),Oe}),p===Ee&&h(null),_e?.experimentId&&_e?.datasetId&&f.mutate({datasetId:_e.datasetId,experimentId:_e.experimentId,resultId:_e.id,status:null})},[D,f,p]),ce=g.useCallback(Ee=>{const _e=D.find(Ce=>Ce.id===Ee);B(Ce=>(Ce??[]).filter(Oe=>Oe.id!==Ee)),b(Ce=>{const Oe=new Set(Ce);return Oe.delete(Ee),Oe}),p===Ee&&h(null),_e?.experimentId&&_e?.datasetId&&f.mutate({datasetId:_e.datasetId,experimentId:_e.experimentId,resultId:_e.id,status:"complete"})},[D,f,p]),Y=g.useMemo(()=>{const Ee=S?d??[]:$;return!S||!m?Ee:m==="__untagged__"?Ee.filter(_e=>_e.tags.length===0):Ee.filter(_e=>_e.tags.includes(m))},[S,d,$,m]),ne=S?c:!1,ue=g.useMemo(()=>new Set(Y.map(Ee=>Ee.id)),[Y]),pe=g.useMemo(()=>[...y].filter(Ee=>ue.has(Ee)).length,[y,ue]),le=Y.length>0&&pe===Y.length,ve=pe>0&&!le,ye=g.useCallback(Ee=>{b(_e=>{const Ce=new Set(_e);return Ce.has(Ee)?Ce.delete(Ee):Ce.add(Ee),Ce})},[]),Se=g.useCallback(()=>{b(le?new Set:new Set(Y.map(Ee=>Ee.id)))},[le,Y]),Ne=g.useCallback(Ee=>{for(const _e of y){const Ce=D.find(Oe=>Oe.id===_e);Ce&&!Ce.tags.includes(Ee)&&te(_e,[...Ce.tags,Ee])}},[D,y,te]),ke=g.useCallback(Ee=>{for(const _e of y){const Ce=D.find(Oe=>Oe.id===_e);Ce&&Ce.tags.includes(Ee)&&te(_e,Ce.tags.filter(Oe=>Oe!==Ee))}},[D,y,te]),Ie=g.useCallback(()=>{for(const Ee of y)ce(Ee);b(new Set)},[y,ce]),ze=g.useCallback(()=>{for(const Ee of y)ae(Ee);b(new Set)},[y,ae]),oe=g.useCallback(()=>{N(""),E(!0)},[]),se=g.useCallback(async()=>{if(!(!I||!P)){_(!0),E(!1);try{const Ee=D.filter(Ce=>y.has(Ce.id));if(Ee.length===0){_(!1);return}const _e=await r.clusterFailures({modelId:`${I}/${P}`,items:Ee.map(Ce=>({id:Ce.id,input:Ce.input,output:Ce.output??void 0,error:typeof Ce.error=="string"?Ce.error:Ce.error?String(Ce.error):void 0,scores:Ce.scores,existingTags:Ce.tags.length>0?Ce.tags:void 0})),availableTags:Q.length>0?Q:void 0,prompt:j||void 0});_e.proposedTags&&_e.proposedTags.length>0&&(q(_e.proposedTags.map(Ce=>({...Ce,accepted:!0}))),F(!0))}catch(Ee){console.error("Analysis failed:",Ee)}finally{_(!1)}}},[I,P,D,y,r,Q,j]),re=g.useCallback(()=>{for(const Ee of M){if(!Ee.accepted)continue;const _e=D.find(Ce=>Ce.id===Ee.itemId);if(_e){const Ce=[...new Set([..._e.tags,...Ee.tags])];te(_e.id,Ce)}}F(!1)},[M,D,te]),he=g.useCallback(Ee=>{h(_e=>_e===Ee?null:Ee)},[]),xe=g.useMemo(()=>p?Y.find(Ee=>Ee.id===p)??null:null,[p,Y]),je=p?Y.findIndex(Ee=>Ee.id===p):-1,Pe=je>0?()=>h(Y[je-1].id):void 0,Ge=je>=0&&je<Y.length-1?()=>h(Y[je+1].id):void 0,Ze="auto minmax(15rem,1fr) 10rem 8rem 6rem 6rem";return i?o.jsx("div",{className:"flex-1 flex items-center justify-center",children:o.jsx(Gt,{className:"w-6 h-6"})}):o.jsxs("div",{className:"flex flex-1 min-h-0 overflow-hidden",children:[o.jsx(br,{open:C,onOpenChange:E,children:o.jsxs(xr,{children:[o.jsxs(wr,{children:[o.jsx(gr,{children:"Analyze Items"}),o.jsx(Qs,{children:"Use an LLM to automatically suggest tags for the selected items."})]}),o.jsxs("div",{className:"space-y-4 py-2",children:[o.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[o.jsxs("div",{children:[o.jsx(Rt,{className:"text-xs mb-1 block",children:"Provider"}),o.jsx(zy,{value:I,onValueChange:R})]}),o.jsxs("div",{children:[o.jsx(Rt,{className:"text-xs mb-1 block",children:"Model"}),o.jsx(By,{llmId:I,value:P,onValueChange:L})]})]}),o.jsxs(ge,{variant:"ui-xs",className:"text-neutral3",children:[y.size," item",y.size!==1?"s":""," will be analyzed"]}),o.jsxs("div",{children:[o.jsx(Rt,{className:"text-xs",children:"Instructions (optional)"}),o.jsx(Kl,{value:j,onChange:Ee=>N(Ee.target.value),placeholder:"E.g., Focus on safety issues and factual errors...",rows:3,className:"text-xs mt-1"})]})]}),o.jsxs(Cc,{children:[o.jsx(de,{variant:"outline",onClick:()=>E(!1),children:"Cancel"}),o.jsxs(de,{onClick:se,disabled:!I||!P||k,children:[k?o.jsx(Gt,{className:"w-4 h-4 mr-1"}):null,"Analyze"]})]})]})}),o.jsx(br,{open:H,onOpenChange:F,children:o.jsxs(xr,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[o.jsxs(wr,{children:[o.jsx(gr,{children:"Review Proposed Tags"}),o.jsxs(Qs,{children:[M.filter(Ee=>Ee.accepted).length," of ",M.length," proposals selected"]})]}),o.jsx("div",{className:"space-y-3 py-2",children:M.map((Ee,_e)=>{const Ce=D.find(Oe=>Oe.id===Ee.itemId);return o.jsx("div",{className:K("p-3 border rounded-lg",!Ee.accepted&&"opacity-50"),children:o.jsxs("div",{className:"flex items-start gap-2",children:[o.jsx(Mo,{checked:Ee.accepted,onCheckedChange:Oe=>q(Re=>Re.map((qe,Ye)=>Ye===_e?{...qe,accepted:!!Oe}:qe))}),o.jsxs("div",{className:"flex-1 min-w-0",children:[o.jsx(ge,{variant:"ui-xs",className:"text-neutral4 truncate block",children:Ce?typeof Ce.input=="string"?Ce.input.slice(0,100):JSON.stringify(Ce.input).slice(0,100):Ee.itemId}),o.jsx("div",{className:"flex gap-1 flex-wrap mt-1.5",children:Ee.tags.map((Oe,Re)=>o.jsx(c9t,{tag:Oe,onRename:qe=>q(Ye=>Ye.map((tt,At)=>At===_e?{...tt,tags:tt.tags.map((ot,zt)=>zt===Re?qe:ot)}:tt)),onRemove:()=>q(qe=>qe.map((Ye,tt)=>tt===_e?{...Ye,tags:Ye.tags.filter((At,ot)=>ot!==Re)}:Ye))},`${Oe}-${Re}`))}),Ee.reason&&o.jsx(ge,{variant:"ui-xs",className:"text-neutral3 mt-1 block italic",children:Ee.reason})]})]})},Ee.itemId)})}),o.jsxs(Cc,{children:[o.jsx(de,{variant:"outline",onClick:()=>F(!1),children:"Cancel"}),o.jsxs(de,{onClick:re,disabled:M.filter(Ee=>Ee.accepted).length===0,children:["Accept ",M.filter(Ee=>Ee.accepted).length," proposals"]})]})]})}),o.jsxs("div",{className:K("grid w-full h-full grid-cols-1 gap-4 overflow-y-auto",xe&&"grid-cols-[1fr_1fr]"),children:[o.jsxs("div",{className:"grid gap-8 content-start w-full overflow-y-auto",children:[o.jsxs("div",{className:"flex items-center justify-between w-full flex-wrap gap-4 gap-x-6",children:[o.jsxs("div",{className:"flex items-center gap-3",children:[o.jsxs(pt,{children:[o.jsx(pt.Trigger,{asChild:!0,children:o.jsxs(de,{variant:"outline",size:"md",children:[o.jsx(Flt,{}),"Filter",X>0&&o.jsx("span",{className:K("ml-0.5 inline-flex items-center justify-center rounded-full bg-accent1/50 text-neutral5 text-ui-sm w-5 h-5"),children:X})]})}),o.jsxs(pt.Content,{align:"start",className:K("min-w-48"),children:[o.jsxs(pt.Sub,{children:[o.jsxs(pt.SubTrigger,{children:["Status",S&&o.jsx("span",{className:K("ml-auto text-ui-sm text-accent1"),children:"1"})]}),o.jsxs(pt.SubContent,{children:[o.jsx(pt.CheckboxItem,{checked:!S,onCheckedChange:()=>{w(!1),h(null)},onSelect:Ee=>Ee.preventDefault(),children:"Review Queue"}),o.jsx(pt.CheckboxItem,{checked:S,onCheckedChange:()=>{w(!0),h(null)},onSelect:Ee=>Ee.preventDefault(),children:"Completed"})]})]}),o.jsxs(pt.Sub,{children:[o.jsxs(pt.SubTrigger,{children:["Tags",m&&o.jsx("span",{className:K("ml-auto text-ui-sm text-accent1"),children:"1"})]}),o.jsxs(pt.SubContent,{children:[o.jsx(pt.CheckboxItem,{checked:!m,onCheckedChange:()=>v(null),onSelect:Ee=>Ee.preventDefault(),children:"All"}),Z>0&&o.jsx(pt.CheckboxItem,{checked:m==="__untagged__",onCheckedChange:()=>v(m==="__untagged__"?null:"__untagged__"),onSelect:Ee=>Ee.preventDefault(),children:"Untagged"}),U.length>0&&o.jsx(pt.Separator,{}),U.map(([Ee])=>o.jsx(pt.CheckboxItem,{checked:m===Ee,onCheckedChange:()=>v(m===Ee?null:Ee),onSelect:_e=>_e.preventDefault(),children:Ee},Ee))]})]}),X>0&&o.jsxs(o.Fragment,{children:[o.jsx(pt.Separator,{}),o.jsxs(pt.Item,{onSelect:()=>{v(null),w(!1),h(null)},children:[o.jsx(vs,{}),"Clear all filters"]})]})]})]}),X>0&&o.jsxs(de,{variant:"outline",size:"md",onClick:()=>{v(null),w(!1),h(null)},children:[o.jsx(vs,{}),"Reset"]})]}),!S&&y.size>0&&o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx(l9t,{selectedCount:y.size,vocabulary:Q,onApplyTag:Ne,onRemoveTag:ke,onNewTag:Ee=>Ne(Ee)}),o.jsxs(pt,{children:[o.jsx(pt.Trigger,{asChild:!0,children:o.jsxs(de,{disabled:k,children:[k?o.jsx(Gt,{className:"w-4 h-4"}):o.jsx(Ue,{size:"sm",children:o.jsx(Sa,{})}),"Actions"]})}),o.jsxs(pt.Content,{align:"end",children:[o.jsxs(pt.Item,{onSelect:Ie,children:[o.jsx(Ue,{size:"sm",children:o.jsx(uO,{})}),"Complete"]}),o.jsxs(pt.Item,{onSelect:ze,children:[o.jsx(Ue,{size:"sm",children:o.jsx(au,{})}),"Remove"]}),o.jsx(pt.Separator,{}),o.jsxs(pt.Item,{onSelect:oe,children:[o.jsx(Ue,{size:"sm",children:o.jsx(wg,{})}),"Analyze"]})]})]})]})]}),ne?o.jsx("div",{className:"flex-1 flex items-center justify-center",children:o.jsx(Gt,{className:"w-6 h-6"})}):Y.length===0?o.jsx("div",{className:"flex-1 flex items-center justify-center",children:o.jsxs("div",{className:"text-center px-8",children:[o.jsx(ge,{variant:"ui-sm",className:"text-neutral3 block",children:S?"No completed reviews yet":"No items to review"}),o.jsx(ge,{variant:"ui-xs",className:"text-neutral3 mt-2 block",children:S?"Items marked as complete will appear here for auditing.":"When experiment results are flagged for review, they will appear here."})]})}):o.jsxs(me,{columns:Ze,className:"min-w-0",children:[o.jsxs(me.Top,{hasLeadingCell:!0,children:[S?o.jsx(me.TopCell,{children:" "}):o.jsx(me.TopSelectCell,{checked:le?!0:ve?"indeterminate":!1,onToggle:()=>Se(),"aria-label":"Select all"}),o.jsxs(me.TopCells,{colStart:2,children:[o.jsx(me.TopCell,{children:"Input"}),o.jsx(me.TopCell,{children:"Comment"}),o.jsx(me.TopCell,{children:"Tags"}),o.jsx(me.TopCell,{children:"Rating"}),o.jsx(me.TopCell,{children:"Scores"})]})]}),Y.map(Ee=>{const _e=Ee.scores?Object.entries(Ee.scores):[],Ce=p===Ee.id,Oe=o.jsxs(o.Fragment,{children:[o.jsx(me.Cell,{height:"compact",className:"min-w-0 text-neutral4",children:o.jsx("span",{className:"block truncate",children:_es(Ee.input,200)})}),o.jsx(me.Cell,{height:"compact",className:"min-w-0",children:Ee.comment?o.jsx(ge,{variant:"ui-xs",className:"text-neutral3 truncate",children:Ee.comment}):o.jsx(ge,{variant:"ui-xs",className:"text-neutral2",children:"—"})}),o.jsx(me.Cell,{height:"compact",className:"min-w-0",children:Ee.tags.length>0?o.jsx(ge,{variant:"ui-xs",className:"text-neutral4 truncate",children:Ee.tags.join(", ")}):o.jsx(ge,{variant:"ui-xs",className:"text-neutral2",children:"—"})}),o.jsxs(me.Cell,{height:"compact",children:[Ee.rating==="positive"&&o.jsx(Ue,{size:"sm",className:"text-positive1",children:o.jsx(fbe,{})}),Ee.rating==="negative"&&o.jsx(Ue,{size:"sm",className:"text-negative1",children:o.jsx(dbe,{})}),!Ee.rating&&o.jsx(ge,{variant:"ui-xs",className:"text-neutral2",children:"—"})]}),o.jsx(me.Cell,{height:"compact",children:_e.length>0?o.jsxs("div",{className:"flex items-center gap-1",children:[o.jsx(Ue,{size:"sm",className:"text-neutral3",children:o.jsx(rm,{})}),o.jsx(ge,{variant:"ui-xs",className:"text-neutral4 font-mono",children:_e[0][1].toFixed(2)}),_e.length>1&&o.jsxs(dn,{variant:"default",children:["+",_e.length-1]})]}):o.jsx(ge,{variant:"ui-xs",className:"text-neutral2",children:"—"})})]});return o.jsxs(me.RowWrapper,{children:[S?o.jsx(me.Cell,{height:"compact",className:"justify-items-center px-4",children:o.jsx("div",{role:"img","aria-label":Ee.error?"Error":"Success",title:Ee.error?"Error":"Success",className:K("w-2 h-2 rounded-full",Ee.error?"bg-red-700":"bg-green-600")})}):o.jsx(me.SelectCell,{checked:y.has(Ee.id),onToggle:()=>ye(Ee.id),"aria-label":`Select item ${Ee.id}`}),o.jsx(me.RowButton,{flushLeft:!0,colStart:2,featured:Ce,onClick:()=>he(Ee.id),children:Oe})]},Ee.id)})]})]}),xe&&o.jsx(o9t,{item:xe,isCompleted:S,tagVocabulary:Q,onRate:Ee=>J(xe.id,Ee),onSetTags:Ee=>{te(xe.id,Ee);for(const _e of Ee)Q.includes(_e)||V(_e)},onComment:Ee=>ee(xe.id,Ee),onRemove:()=>ae(xe.id),onComplete:S?void 0:()=>ce(xe.id),onPrevious:Pe,onNext:Ge,onClose:()=>h(null)})]})]})}function Ces({datasetId:e,onAddItemClick:t,onNavigateToDataset:n}){const{navigate:r}=yn(),[s,a]=ga(),{tab:i,activeVersion:l,handleTabChange:c}=yTe(s,a),[u,d]=g.useState(!1),[f,p]=g.useState(!1),[h,m]=g.useState(!1),[v,y]=g.useState([]),[b,S]=g.useState(!1),[w,k]=g.useState([]),[_,C]=g.useState(!1),[E,j]=g.useState([]),[N,I]=g.useState(0),[R,P]=g.useState(null),[L,M]=g.useState(""),[q]=A0e(L,300),{data:H}=Hx(e),{data:F=[],total:z,isLoading:B,setEndOfListElement:D,isFetchingNextPage:Q,hasNextPage:V}=E1(e,q||void 0,l),{total:$}=E1(e,void 0,l),[U,Z]=g.useState({}),{data:X,isLoading:te}=tD(e,void 0,U),{data:J}=tD(e),{deleteItems:ee}=Ei(),ae=X?.experiments??[],ce=J?.experiments??[],Y=EJr({hasSearchQuery:!!q,filteredItemsLength:F.length,unfilteredItemsTotal:$,itemsTotal:z}),{data:ne}=xTe(e),ue=ne?.length??0,pe=re=>{P(re)},le=()=>{P(null)},ve=re=>{y(re),m(!0)},ye=re=>{k(re),S(!0)},Se=re=>{S(re),re||(k([]),I(he=>he+1))},Ne=re=>{r(`/datasets/${e}/items?items=${re.join(",")}`)},ke=re=>{r(`/datasets/${e}/versions?ids=${re.join(",")}`)},Ie=re=>{j(re),C(!0)},ze=async()=>{await ee.mutateAsync({datasetId:e,itemIds:E}),De.success(`Deleted ${E.length} items`),C(!1),j([]),I(re=>re+1)},oe=re=>{m(!1),y([]),I(he=>he+1),n?.(re)},se=re=>{m(re),re||(y([]),I(he=>he+1))};return o.jsxs(o.Fragment,{children:[o.jsxs(cu,{defaultTab:"items",value:i,onValueChange:c,className:"grid grid-rows-[auto_1fr] h-full",children:[o.jsxs(uu,{children:[o.jsxs(qr,{value:"items",children:["Items ",o.jsx(Xs,{color:"gray",children:Y})]}),o.jsxs(qr,{value:"experiments",children:["Experiments",o.jsx(Xs,{color:"gray",children:ae.length})]}),o.jsxs(qr,{value:"review",children:["Review",ue>0&&o.jsx(Xs,{color:"orange",children:ue})]})]}),o.jsx(fs,{value:"items",className:"grid overflow-auto mt-5 pb-0",children:o.jsx(bes,{datasetId:e,items:F,isLoading:B,featuredItemId:R,onItemSelect:pe,onItemClose:le,onAddClick:t??(()=>{}),onImportClick:()=>d(!0),onImportJsonClick:()=>p(!0),onBulkDeleteClick:Ie,onCreateDatasetClick:ve,onAddToDatasetClick:ye,onCompareItemsClick:Ne,datasetName:H?.name,clearSelectionTrigger:N,setEndOfListElement:D,isFetchingNextPage:Q,hasNextPage:V,searchQuery:L,activeSearchQuery:q,onSearchChange:M,currentDatasetVersion:H?.version,onCompareVersionsClick:ke})}),o.jsx(fs,{value:"experiments",className:"grid overflow-auto mt-5 pb-0",children:o.jsx(VJr,{experiments:ae,allExperiments:ce,isLoading:te,datasetId:e,filters:U,onFiltersChange:Z})}),o.jsx(fs,{value:"review",className:"overflow-auto mt-2 pb-0",children:o.jsx(A9t,{datasetId:e})})]}),o.jsx(MJr,{datasetId:e,open:u,onOpenChange:d}),o.jsx(kes,{datasetId:e,open:f,onOpenChange:p}),o.jsx(fJr,{open:h,onOpenChange:se,items:v,onSuccess:oe}),o.jsx(pJr,{open:b,onOpenChange:Se,items:w,currentDatasetId:e}),o.jsx(Tt,{open:_,onOpenChange:C,children:o.jsxs(Tt.Content,{children:[o.jsxs(Tt.Header,{children:[o.jsx(Tt.Title,{children:"Delete Items"}),o.jsxs(Tt.Description,{children:["Are you sure you want to delete ",E.length," item",E.length!==1?"s":"","? This action cannot be undone."]})]}),o.jsxs(Tt.Footer,{children:[o.jsx(Tt.Cancel,{children:"Cancel"}),o.jsx(Tt.Action,{onClick:ze,children:ee.isPending?"Deleting...":"Delete"})]})]})})]})}function Ees(e){if(!(e instanceof Error))return null;const t=e.message.match(/- ({.*})$/);if(!t)return null;try{const n=JSON.parse(t[1]);if(n.field&&Array.isArray(n.errors))return{field:n.field,errors:n.errors}}catch{}return null}function Kre({field:e,errors:t}){return t.length?o.jsx("div",{className:"mt-2 space-y-1",children:t.map((n,r)=>o.jsxs("p",{className:"text-xs text-destructive",children:[o.jsxs("code",{className:"bg-destructive/10 px-1 rounded",children:[e,n.path!=="/"?n.path:""]}),": ",n.message]},r))}):null}function jes({datasetId:e,open:t,onOpenChange:n,onSuccess:r}){const[s,a]=g.useState("{}"),[i,l]=g.useState(""),[c,u]=g.useState(""),[d,f]=g.useState(""),[p,h]=g.useState(""),[m,v]=g.useState(null),{addItem:y}=Ei(),b=async C=>{C.preventDefault();let E;try{E=JSON.parse(s)}catch{De.error("Input must be valid JSON");return}let j;if(i.trim())try{j=JSON.parse(i)}catch{De.error("Ground Truth must be valid JSON");return}let N;if(c.trim())try{N=JSON.parse(c)}catch{De.error("Expected Trajectory must be valid JSON");return}let I;if(d.trim())try{const P=JSON.parse(d);if(!Array.isArray(P)){De.error("Tool Mocks must be a JSON array");return}I=P}catch{De.error("Tool Mocks must be valid JSON");return}let R;if(p.trim())try{R=JSON.parse(p)}catch{De.error("Request Context must be valid JSON");return}try{await y.mutateAsync({datasetId:e,input:E,groundTruth:j,expectedTrajectory:N,toolMocks:I,requestContext:R}),De.success("Item added successfully"),v(null),a("{}"),l(""),u(""),f(""),h(""),n(!1),r?.()}catch(P){const L=Ees(P);L?v(L):De.error(`Failed to add item: ${P instanceof Error?P.message:"Unknown error"}`)}},S=C=>{a(C),m?.field==="input"&&v(null)},w=C=>{l(C),m?.field==="groundTruth"&&v(null)},k=C=>{f(C),m?.field==="toolMocks"&&v(null)},_=()=>{a("{}"),l(""),u(""),f(""),h(""),v(null),n(!1)};return o.jsx(br,{open:t,onOpenChange:n,children:o.jsxs(xr,{className:"max-w-lg",children:[o.jsx(wr,{children:o.jsx(gr,{children:"Add Item"})}),o.jsx(Rr,{children:o.jsxs("form",{onSubmit:b,className:"space-y-4",children:[o.jsxs("div",{className:"space-y-2",children:[o.jsx(Rt,{htmlFor:"item-input",children:"Input (JSON) *"}),o.jsx(Qr,{value:s,onChange:S,showCopyButton:!1,className:"min-h-[120px]"}),m?.field==="input"&&o.jsx(Kre,{field:"input",errors:m.errors})]}),o.jsxs("div",{className:"space-y-2",children:[o.jsx(Rt,{htmlFor:"item-ground-truth",children:"Ground Truth (JSON, optional)"}),o.jsx(Qr,{value:i,onChange:w,showCopyButton:!1,className:"min-h-[80px]"}),m?.field==="groundTruth"&&o.jsx(Kre,{field:"groundTruth",errors:m.errors})]}),o.jsxs("div",{className:"space-y-2",children:[o.jsx(Rt,{htmlFor:"item-trajectory",children:"Expected Trajectory (JSON, optional)"}),o.jsx(Qr,{value:c,onChange:u,showCopyButton:!1,className:"min-h-[80px]"})]}),o.jsxs("div",{className:"space-y-2",children:[o.jsx(Rt,{htmlFor:"item-tool-mocks",children:"Tool Mocks (JSON array, optional)"}),o.jsx(Qr,{value:d,onChange:k,showCopyButton:!1,className:"min-h-[80px]"}),m?.field==="toolMocks"&&o.jsx(Kre,{field:"toolMocks",errors:m.errors})]}),o.jsxs("div",{className:"space-y-2",children:[o.jsx(Rt,{htmlFor:"item-request-context",children:"Request Context (JSON, optional)"}),o.jsx(Qr,{value:p,onChange:h,showCopyButton:!1,className:"min-h-[80px]"})]}),o.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[o.jsx(de,{type:"button",onClick:_,children:"Cancel"}),o.jsx(de,{type:"submit",variant:"primary",disabled:y.isPending,children:y.isPending?"Adding...":"Add Item"})]})]})})]})})}function Tes({item:e}){return o.jsx(ua,{withMargins:!1,children:o.jsxs(ua.Column,{children:[o.jsxs(ua.Title,{size:"smaller",children:[o.jsx(yN,{}),o.jsx("span",{className:"truncate",children:e.id}),o.jsx(Oa,{content:e.id,tooltip:`Copy item ID: ${e.id}`})]}),o.jsxs(ua.Description,{children:[o.jsxs(Al,{children:[o.jsx(Nlt,{})," Created ",er(new Date(e.createdAt),"MMM d, yyyy h:mm aaa")]}),e.datasetVersion!=null&&o.jsxs(Al,{children:[o.jsx(p_,{})," Version v",e.datasetVersion]})]})]})})}function wTe({item:e}){const t=e?.input?JSON.stringify(e.input,null,2):"null",n=e?.groundTruth?JSON.stringify(e.groundTruth,null,2):"null",r=e?.metadata?JSON.stringify(e.metadata,null,2):"null",s=e?.expectedTrajectory?JSON.stringify(e.expectedTrajectory,null,2):null;return o.jsxs(Uje,{children:[o.jsx(Ps.CodeSection,{title:"Input",icon:o.jsx(fO,{}),codeStr:t}),o.jsx(Ps.CodeSection,{title:"Ground Truth",icon:o.jsx(gg,{}),codeStr:n}),s&&o.jsx(Ps.CodeSection,{title:"Expected Trajectory",icon:o.jsx(lbe,{}),codeStr:s}),o.jsx(Ps.CodeSection,{title:"Metadata",icon:o.jsx(wN,{}),codeStr:r})]})}function Nes({selectedScorers:e,setSelectedScorers:t,disabled:n=!1,container:r}){const{data:s,isLoading:a}=ih(),i=g.useMemo(()=>s?Object.entries(s).map(([l,c])=>({value:l,label:c.scorer?.config?.name||l,description:c.scorer?.config?.description||""})):[],[s]);return o.jsxs("div",{className:"grid gap-2",children:[o.jsx(Rt,{children:"Scorers (Optional)"}),o.jsx(Jl,{multiple:!0,options:i,value:e,onValueChange:t,placeholder:"Select scorers...",searchPlaceholder:"Search scorers...",emptyText:"No scorers available",disabled:n||a,container:r})]})}const Ies=[{value:"agent",label:"Agent"},{value:"workflow",label:"Workflow"},{value:"scorer",label:"Scorer"}];function Aes({targetType:e,setTargetType:t,targetId:n,setTargetId:r,container:s}){const{data:a,isLoading:i}=km(),{data:l,isLoading:c}=Uy(),{data:u,isLoading:d}=ih(),f=e==="agent"?Object.entries(a??{}).map(([v,y])=>({value:v,label:y.name??v})):e==="workflow"?Object.entries(l??{}).map(([v,y])=>({value:v,label:y.name??v})):e==="scorer"?Object.entries(u??{}).map(([v,y])=>({value:v,label:y.scorer?.config?.name??v})):[],p=e==="agent"&&i||e==="workflow"&&c||e==="scorer"&&d,h=v=>{t(v),r("")},m=e==="agent"?"Agent":e==="workflow"?"Workflow":"Scorer";return o.jsxs("div",{className:"grid gap-6",children:[o.jsxs("div",{className:"grid gap-2",children:[o.jsx(Rt,{children:"Target Type"}),o.jsx(Jl,{options:Ies,value:e,onValueChange:h,placeholder:"Select target type",searchPlaceholder:"Search types...",emptyText:"No types available",container:s})]}),e&&o.jsxs("div",{className:"grid gap-2",children:[o.jsx(Rt,{children:m}),o.jsx(Jl,{options:f,value:n,onValueChange:r,placeholder:`Select ${e}`,searchPlaceholder:"Search...",emptyText:"No targets available",disabled:p,container:s})]})]})}function Res({requestContextSchema:e,onChange:t}){const n=g.useMemo(()=>{try{return lm(im(e))}catch(r){return console.error("Failed to parse requestContextSchema:",r),null}},[e]);return n?o.jsxs("div",{className:"space-y-2",children:[o.jsx(Rt,{children:"Request Context"}),o.jsx(a3,{schema:n,onValuesChange:t,className:"[&_button[type=submit]]:hidden"})]}):o.jsx("p",{className:"text-sm text-destructive",children:"Failed to parse request context schema"})}function Pes({datasetId:e,version:t,requestContextSchema:n,open:r,onOpenChange:s,onSuccess:a}){const i=g.useRef(null),[l,c]=g.useState(""),[u,d]=g.useState(""),[f,p]=g.useState([]),[h,m]=g.useState({}),[v,y]=g.useState(""),{triggerExperiment:b}=Ei(),S=!!(n&&Object.keys(n).length>0),w=l&&u,k=b.isPending,_=()=>{c(""),d(""),p([]),m({}),y("")},C=()=>{if(S){const N=Object.entries(h).filter(([,I])=>I!==void 0&&I!=="");return N.length>0?Object.fromEntries(N):void 0}if(v.trim()){let N;try{N=JSON.parse(v)}catch{throw new Error("Request Context must be valid JSON")}if(!N||typeof N!="object"||Array.isArray(N))throw new Error("Request Context must be a JSON object");return N}},E=async()=>{if(!w)return;let N;try{N=C()}catch(I){const R=I instanceof Error?I.message:"Request Context must be valid JSON";Ru.error(R);return}try{const I=await b.mutateAsync({datasetId:e,targetType:l,targetId:u,scorerIds:f.length>0?f:void 0,version:t,requestContext:N});Ru.success("Experiment triggered successfully"),s(!1),a?.(I.experimentId),_()}catch(I){const R=I instanceof Error?I.message:"Failed to trigger experiment";Ru.error(R)}},j=()=>{k||(s(!1),_())};return o.jsx(br,{open:r,onOpenChange:j,children:o.jsxs(xr,{ref:i,children:[o.jsxs(wr,{children:[o.jsx(gr,{children:"Run Experiment"}),o.jsx(Qs,{children:t?`Execute items from ${er(new Date(t),"MMM d, yyyy")} version against a target.`:"Execute all items in this dataset against a target."})]}),o.jsxs(Rr,{className:"grid gap-6",children:[o.jsx(Aes,{targetType:l,setTargetType:c,targetId:u,setTargetId:d,container:i}),l&&l!=="scorer"&&o.jsx(Nes,{selectedScorers:f,setSelectedScorers:p,disabled:k,container:i}),S?o.jsx(Res,{requestContextSchema:n,onChange:m}):o.jsxs("div",{className:"space-y-2",children:[o.jsx(Rt,{children:"Request Context (JSON, optional)"}),o.jsx(Qr,{value:v,onChange:y,showCopyButton:!1,className:"min-h-[80px]"})]})]}),o.jsxs(Cc,{className:"px-6 pt-4",children:[o.jsx(de,{onClick:j,disabled:k,children:"Cancel"}),o.jsx(de,{variant:"primary",onClick:E,disabled:!w||k,children:k?o.jsxs(o.Fragment,{children:[o.jsx(Gt,{className:"w-4 h-4"}),"Running..."]}):"Run"})]})]})})}const $es=e=>{const t=We();return wt({queryKey:["experiment-trace-light",e],queryFn:async()=>{if(!e)throw new Error("Trace ID is required");return t.getTraceLight(e)},enabled:!!e})},STe=e=>o.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 9.45892 8.88606",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:[o.jsx("path",{d:"M8.53702 7.36403C8.98547 7.36403 9.34918 7.70502 9.34918 8.12535C9.34906 8.54559 8.9854 8.88606 8.53702 8.88606H5.6839C5.23552 8.88606 4.87186 8.54559 4.87174 8.12535C4.87174 7.70502 5.23545 7.36403 5.6839 7.36403H8.53702Z",fill:"currentColor"}),o.jsx("path",{d:"M8.53702 3.67209C8.98547 3.67209 9.34918 4.01309 9.34918 4.43342C9.34911 4.8537 8.98543 5.19413 8.53702 5.19413H5.6839C5.23549 5.19413 4.87181 4.8537 4.87174 4.43342C4.87174 4.01309 5.23545 3.67209 5.6839 3.67209H8.53702Z",fill:"currentColor"}),o.jsx("path",{d:"M8.67155 0C9.10635 2.06584e-05 9.45892 0.341006 9.45892 0.761326C9.45878 1.18153 9.10627 1.52201 8.67155 1.52203H2.88163C2.4469 1.52203 2.0944 1.18154 2.09427 0.761326C2.09427 0.340993 2.44681 3.80132e-08 2.88163 0H8.67155Z",fill:"currentColor"}),o.jsx("path",{d:"M0.757606 0.760086V4.01122H3.50594V4.76883H0.759466L0.762566 5.4291C0.76837 6.70703 1.8058 7.73972 3.08374 7.73973H3.67953V8.49796H3.08374C1.38863 8.49795 0.0120204 7.1273 0.00433981 5.4322L0 4.39188V0.760086H0.757606Z",fill:"currentColor"})]});function Jre(e){try{return JSON.stringify(e??{})}catch{return String(e)}}function Mes({report:e}){const{served:t,unconsumed:n,liveCalls:r,failure:s}=e,a=[...t.map(i=>({outcome:"served",toolName:i.toolName,args:i.args})),...r.map(i=>({outcome:"live",toolName:i.toolName,args:i.args})),...n.map(i=>({outcome:"unconsumed",toolName:i.toolName,args:i.args}))];return o.jsxs("div",{className:"grid gap-2","data-testid":"tool-mock-report",children:[o.jsx(bn.SectionHeading,{icon:o.jsx(zp,{}),className:"mb-2",children:"Tool Mocks"}),s&&o.jsx(In,{variant:"destructive",title:"Mock mismatch",children:o.jsxs(In.Message,{children:[o.jsx("span",{className:"block",children:`Tool "${s.toolName}" was called with arguments that did not match an available mock (${s.code}).`}),o.jsxs("span",{className:"mt-1 block font-mono text-xs",children:["Called with: ",Jre(s.args)]}),n.length>0&&o.jsxs("span",{className:"mt-1 block font-mono text-xs",children:["Unconsumed mocks: ",n.map(i=>Jre(i.args)).join(", ")]})]})}),o.jsx("div",{className:"rounded border border-border1 divide-y divide-border1 text-sm",children:a.map((i,l)=>o.jsxs("div",{className:"flex items-center justify-between gap-2 px-3 py-1.5",children:[o.jsxs("span",{className:"min-w-0 truncate",children:[o.jsx("span",{className:"font-mono text-neutral4",children:i.toolName}),o.jsx("span",{className:"ml-2 font-mono text-xs text-neutral3",children:Jre(i.args)})]}),o.jsx("span",{className:`shrink-0 text-xs px-2 py-0.5 rounded ${Des(i.outcome)}`,children:i.outcome})]},`${i.outcome}-${i.toolName}-${l}`))})]})}function Des(e){switch(e){case"served":return"bg-accent1/10 text-accent1";case"live":return"bg-orange-500/10 text-orange-400";case"unconsumed":return"bg-neutral3/10 text-neutral4"}}function Les({result:e,scores:t,onPrevious:n,onNext:r,onClose:s,onShowTrace:a,onOpenInReview:i,onScoreClick:l,featuredScoreId:c,onFlagForReview:u,collapsed:d,onCollapsedChange:f}){const[p,h]=g.useState(!1),m=d??p,v=f??h,y=!!e?.error,b=tF(e?.input),S=tF(e?.output),w=tF(e?.groundTruth),k=u&&e.status!=="needs-review"&&e.status!=="complete",_=Array.isArray(e.tags)?e.tags:[];return o.jsxs(bn,{collapsed:m,children:[o.jsxs(bn.Header,{children:[o.jsxs(bn.Heading,{children:["Result ",o.jsxs("b",{children:["# ",e.id.length>12?`${e.id.slice(0,12)}…`:e.id]})]}),o.jsxs(Mr,{className:"ml-auto shrink-0",children:[f&&o.jsx(de,{size:"md",tooltip:m?"Expand panel":"Collapse panel",onClick:()=>v(!m),children:m?o.jsx(Plt,{}):o.jsx(Rlt,{})}),o.jsx(bn.NextPrevNav,{onPrevious:n,onNext:r,previousLabel:"Previous result",nextLabel:"Next result"}),o.jsxs(de,{size:"md",onClick:a,disabled:!e.traceId,children:[o.jsx(STe,{}),"Trace"]}),o.jsx(bn.CloseButton,{onClick:s,tooltip:"Close result panel"})]})]}),!m&&o.jsxs(bn.Content,{children:[o.jsxs("div",{className:"grid gap-4 mb-6",children:[o.jsxs(Bt,{children:[o.jsx(Bt.Key,{children:"Item Id"}),o.jsx(Bt.ValueWithCopyBtn,{copyTooltip:"Copy Item Id to clipboard",copyValue:e.itemId,children:e.itemId}),o.jsx(Bt.Key,{children:"Created"}),o.jsx(Bt.Value,{children:er(new Date(e.createdAt),"MMM d, yyyy 'at' h:mm a")})]}),y&&o.jsx(In,{variant:"destructive",title:"Error",children:o.jsx(In.Message,{children:tF(e?.error&&typeof e.error=="object"?e.error.message:e?.error)})}),t&&t.length>0&&o.jsxs(me,{columns:"1fr 1fr",children:[o.jsxs(me.Top,{children:[o.jsx(me.TopCell,{children:"Scorer"}),o.jsx(me.TopCell,{children:"Score"})]}),t.map(C=>o.jsxs(me.RowButton,{featured:c===C.id,onClick:()=>l?.(C.id),children:[o.jsx(me.Cell,{height:"compact",children:C.scorerId}),o.jsx(me.MonoCell,{children:C.score.toFixed(3)})]},C.id))]}),e.toolMockReport&&o.jsx(Mes,{report:e.toolMockReport}),(e.status||_.length>0||k)&&o.jsxs("div",{className:"grid gap-2",children:[o.jsx(bn.SectionHeading,{icon:o.jsx(wN,{}),className:"mb-2",children:"Review"}),(e.status||_.length>0)&&o.jsxs("div",{className:"flex flex-wrap gap-2 items-center",children:[e.status&&o.jsx("span",{className:`text-xs px-2 py-0.5 rounded-full font-medium ${e.status==="needs-review"?"bg-orange-500/10 text-orange-400":e.status==="complete"?"bg-accent1/10 text-accent1":"bg-neutral3/10 text-neutral4"}`,children:e.status}),_.map(C=>o.jsx("span",{className:"text-xs px-2 py-0.5 rounded bg-surface4 text-neutral4",children:C},C))]}),k&&o.jsx("div",{children:o.jsxs(de,{size:"sm",onClick:()=>u(e.id),children:[o.jsx(cq,{}),"Flag for Review"]})}),e.status==="needs-review"&&i&&o.jsx("div",{children:o.jsxs(de,{size:"sm",onClick:i,children:[o.jsx(_a,{}),"Review"]})})]})]}),o.jsxs("div",{className:"grid gap-3",children:[o.jsx(bn.CodeSection,{title:"Input",icon:o.jsx(yN,{}),codeStr:b}),o.jsx(bn.CodeSection,{title:"Output",icon:o.jsx(gg,{}),codeStr:S}),o.jsx(bn.CodeSection,{title:"Ground Truth",icon:o.jsx(ube,{}),codeStr:w})]})]})]})}function tF(e){return e==null?"-":typeof e=="string"?e:JSON.stringify(e,null,2)}function Fes({results:e,isLoading:t,featuredResultId:n,onResultClick:r,columns:s,scoresByItemId:a,scorerIds:i,setEndOfListElement:l,isFetchingNextPage:c,hasNextPage:u,selectedIds:d,onToggleSelect:f}){const p=!!(d&&f),h=[p?"auto":"",...s.map(v=>v.size)].filter(Boolean).join(" "),m=s.some(v=>v.name==="input");return t?o.jsx(tl,{columns:h}):o.jsxs(me,{columns:h,className:"min-w-0",children:[o.jsxs(me.Top,{hasLeadingCell:p,children:[p&&o.jsx(me.TopCell,{children:" "}),p?o.jsx(me.TopCells,{colStart:2,children:s.map(v=>o.jsx(me.TopCell,{children:v.label},v.name))}):s.map(v=>o.jsx(me.TopCell,{children:v.label},v.name))]}),e.length===0?o.jsx(me.NoMatch,{message:"No results yet"}):o.jsxs(o.Fragment,{children:[e.map(v=>{const y=!!v.error,b=v.id===n,S=o.jsxs(o.Fragment,{children:[o.jsx(me.IdCell,{id:v.itemId}),o.jsx(me.Cell,{height:"compact",children:o.jsxs(Wn,{children:[o.jsx(zn,{asChild:!0,children:o.jsx("div",{className:"flex items-center justify-center w-10 relative bg-transparent h-full",children:o.jsx("div",{role:"img","aria-label":y?"Error":"Success",className:K("w-2 h-2 rounded-full",y?"bg-red-700":"bg-green-600")})})}),o.jsx(Bn,{children:y?"Error":"Success"})]})}),m&&o.jsx(me.MonoCell,{children:Bes(zes(v.input),200)}),i?.map(w=>{const _=a?.[v.itemId]?.find(C=>C.scorerId===w);return o.jsx(me.Cell,{height:"compact",className:"font-mono text-neutral3 text-ui-smd",children:_!=null?_.score.toFixed(3):"-"},w)})]});return p?o.jsxs(me.RowWrapper,{children:[o.jsx(me.SelectCell,{checked:d.has(v.id),onToggle:()=>f(v.id),"aria-label":`Select result ${v.itemId}`}),o.jsx(me.RowButton,{flushLeft:!0,colStart:2,featured:b,onClick:()=>r(v.id),children:S})]},v.id):o.jsx(me.RowButton,{featured:b,onClick:()=>r(v.id),children:S},v.id)}),o.jsx(me.NextPageLoading,{isLoading:c,hasMore:u,setEndOfListElement:l})]})]})}function zes(e){return e==null?"-":typeof e=="string"?e:JSON.stringify(e,null,2)}function Bes(e,t){return e.length<=t?e:e.slice(0,t-1)+"..."}function Ues(e){const t=e.scorer;return t?.hasJudge===!1?!0:t?.hasJudge===!0?!1:!e.preprocessPrompt&&!e.analyzePrompt&&!e.generateScorePrompt&&!e.generateReasonPrompt}function qes({score:e,onNext:t,onPrevious:n,onClose:r,onShowTrace:s,collapsed:a,onCollapsedChange:i}){const[l,c]=g.useState(!1),u=a??l,d=i??c,f=Ues(e),p=f?"N/A — code-based scorer":"N/A — step not configured";return o.jsxs(bn,{collapsed:u,children:[o.jsxs(bn.Header,{children:[o.jsxs(bn.Heading,{children:["Score ",o.jsx("b",{children:e.scorerId})]}),o.jsxs(Mr,{className:"ml-auto shrink-0",children:[i&&o.jsx(de,{size:"md",tooltip:u?"Expand panel":"Collapse panel",onClick:()=>d(!u),children:u?o.jsx(Plt,{}):o.jsx(Rlt,{})}),(n||t)&&o.jsx(bn.NextPrevNav,{onPrevious:n,onNext:t,previousLabel:"Previous score",nextLabel:"Next score"}),s&&o.jsxs(de,{size:"md",onClick:s,disabled:!e.traceId,children:[o.jsx(STe,{}),"Trace"]}),o.jsx(bn.CloseButton,{onClick:r,tooltip:"Close score panel"})]})]}),!u&&o.jsx(bn.Content,{children:o.jsxs("div",{className:"grid gap-3",children:[o.jsx(bn.CodeSection,{title:`Score: ${e.score}`,icon:o.jsx(rm,{}),codeStr:e.reason||p,simplified:!0}),!f&&o.jsxs(o.Fragment,{children:[o.jsx(bn.CodeSection,{title:"Preprocess Prompt",icon:o.jsx(Oh,{}),codeStr:e.preprocessPrompt||p,simplified:!0}),o.jsx(bn.CodeSection,{title:"Analyze Prompt",icon:o.jsx(Oh,{}),codeStr:e.analyzePrompt||p,simplified:!0}),o.jsx(bn.CodeSection,{title:"Generate Score Prompt",icon:o.jsx(Oh,{}),codeStr:e.generateScorePrompt||p,simplified:!0}),o.jsx(bn.CodeSection,{title:"Generate Reason Prompt",icon:o.jsx(Oh,{}),codeStr:e.generateReasonPrompt||p,simplified:!0})]})]})})]})}const RQe=[{name:"scorer",label:"Scorer",size:"1fr"},{name:"avg",label:"Avg Score",size:"1fr"},{name:"count",label:"Items Scored",size:"1fr"}];function Ves({scoresByItemId:e,experimentStatus:t}){const n=g.useMemo(()=>{if(!e)return[];const r={};for(const s of Object.values(e))for(const a of s)r[a.scorerId]||(r[a.scorerId]={sum:0,count:0}),r[a.scorerId].sum+=a.score,r[a.scorerId].count++;return Object.entries(r).map(([s,{sum:a,count:i}])=>({scorerId:s,avg:a/i,count:i})).sort((s,a)=>s.scorerId.localeCompare(a.scorerId))},[e]);if(n.length===0){const r=t==="running"||t==="pending",s=e!==void 0;let a,i;return r?(a="Experiment in progress",i="Summary metrics will appear here once the experiment completes."):s?(a="No scorers configured",i="Add scorers when triggering an experiment to evaluate results and see summary metrics here."):(a="Loading scores",i="Fetching scorer results…"),o.jsx("div",{className:"flex h-full items-center justify-center py-12",children:o.jsx(Cr,{iconSlot:o.jsx(rm,{className:"w-8 h-8 text-neutral3"}),titleSlot:a,descriptionSlot:i})})}return o.jsxs(gn,{children:[o.jsxs(gn.Header,{columns:RQe,children:[o.jsx(gn.HeaderCol,{children:"Scorer"}),o.jsx(gn.HeaderCol,{children:"Avg Score"}),o.jsx(gn.HeaderCol,{children:"Items Scored"})]}),o.jsx(gn.Scroller,{children:o.jsx(gn.Items,{children:n.map(({scorerId:r,avg:s,count:a})=>o.jsxs(gn.Row,{columns:RQe,children:[o.jsx(gn.TextCell,{children:r}),o.jsx(gn.TextCell,{className:"font-mono",children:s.toFixed(3)}),o.jsx(gn.TextCell,{className:"font-mono",children:a})]},r))})})]})}function R9t({experimentId:e,datasetId:t,experimentStatus:n,results:r,isLoading:s,setEndOfListElement:a,isFetchingNextPage:i,hasNextPage:l}){const[c,u]=g.useState(null),[d,f]=g.useState(null),[p,h]=g.useState(void 0),[m,v]=g.useState(null),[y,b]=g.useState(new Set),[S,w]=g.useState(!1),[k,_]=g.useState(!1),[C,E]=g.useState(!1),[j,N]=g.useState(!1),{updateExperimentResult:I}=Ei(),R=g.useCallback(se=>{b(re=>{const he=new Set(re);return he.has(se)?he.delete(se):he.add(se),he})},[]),P=g.useCallback(()=>b(new Set),[]),L=g.useCallback(()=>{const se=r.filter(re=>!!re.error).map(re=>re.id);b(new Set(se))},[r]),M=g.useCallback(async se=>{if(S||se.length===0)return;w(!0);let re=0;const he=new Set;try{for(const xe of se)try{await I.mutateAsync({datasetId:t,experimentId:e,resultId:xe,status:"needs-review"}),re++,he.add(xe)}catch{}}finally{w(!1)}he.size>0&&b(xe=>{const je=new Set(xe);for(const Pe of he)je.delete(Pe);return je}),re>0&&De(`${re} result${re>1?"s":""} flagged for review`)},[t,e,S,I]),q=r.find(se=>se.id===c)??null,[H,F]=g.useState("summary"),[z,B]=g.useState(null),D=se=>{F(se),se!=="reviews"&&B(null)},{data:Q}=xTe(t),V=(Q??[]).filter(se=>se.experimentId===e).length,{data:$}=r9t(e,n),U=g.useMemo(()=>{if(!$)return[];const se=new Set;for(const re of Object.values($))for(const he of re)se.add(he.scorerId);return[...se].sort()},[$]),Z=se=>{u(se),f(null),h(void 0),v(null)},X=se=>{Z(se===c?null:se)},te=()=>{Z(null)},J=()=>{if(!q)return;const se=r.findIndex(re=>re.id===q.id);if(se>=0&&se<r.length-1)return()=>Z(r[se+1].id)},ee=()=>{if(!q)return;const se=r.findIndex(re=>re.id===q.id);if(se>0)return()=>Z(r[se-1].id)},ae=q?$?.[q.itemId]:void 0,ce=ae?.find(se=>se.id===m)??null,Y=se=>{v(se===m?null:se),f(null),h(void 0)},ne=()=>{if(!m||!ae)return;const se=ae.findIndex(re=>re.id===m);if(se>=0&&se<ae.length-1)return()=>v(ae[se+1].id)},ue=()=>{if(!m||!ae)return;const se=ae.findIndex(re=>re.id===m);if(se>0)return()=>v(ae[se-1].id)},{data:pe,isLoading:le}=$es(d),ve=pe?.spans,{data:ye,isLoading:Se}=oI(d,p),Ne=ye?.span,{handlePreviousSpan:ke,handleNextSpan:Ie}=GH(ve,p??null,h),ze=(()=>{const se=[],re=!!ce,he=!!d;return se.push(k?"auto":re||he?"2fr":"1fr"),re&&se.push(j?"auto":"3fr"),he&&se.push(C?"auto":"3fr"),he&&p&&se.push("3fr"),se.join(" ")})(),oe=g.useMemo(()=>[{name:"itemId",label:"Item ID",size:"7rem"},{name:"status",label:"Status",size:"5rem"},{name:"input",label:"Input",size:"minmax(15rem,1fr)"},...U.map(se=>({name:se,label:se,size:"12rem"}))],[U]);return o.jsxs(cu,{defaultTab:"summary",value:H,onValueChange:D,className:"grid grid-rows-[auto_1fr] h-full overflow-hidden",children:[o.jsxs(uu,{children:[o.jsx(qr,{value:"summary",children:"Summary"}),o.jsx(qr,{value:"results",children:"Results"}),o.jsxs(qr,{value:"reviews",children:["Reviews",V>0&&o.jsx(Xs,{color:"orange",children:V})]})]}),o.jsx(fs,{value:"summary",className:"overflow-y-auto mt-5",children:o.jsx(Ves,{scoresByItemId:$,experimentStatus:n})}),o.jsx(fs,{value:"reviews",className:"overflow-auto mt-2 pb-0",children:o.jsx(A9t,{datasetId:t,experimentId:e,featuredItemId:z})}),o.jsxs(fs,{value:"results",className:"grid grid-rows-[auto_1fr] overflow-hidden mt-2",children:[o.jsxs("div",{className:"mb-4",children:[y.size>0&&o.jsxs("div",{className:"flex items-center gap-2 px-4 py-2 bg-surface3",children:[o.jsxs(ge,{variant:"ui-xs",className:"text-neutral5 font-medium",children:[y.size," selected"]}),o.jsx("div",{className:"flex-1"}),o.jsxs(de,{variant:"outline",size:"sm",disabled:S,onClick:()=>M([...y]),children:[o.jsx(Ue,{size:"sm",children:o.jsx(cq,{})}),"Flag for Review"]}),o.jsx(de,{variant:"ghost",size:"sm",onClick:P,children:"Clear"})]}),r.length>0&&y.size===0&&!s&&o.jsx("div",{className:"flex items-center gap-2 px-4 py-2",children:o.jsx(de,{variant:"ghost",size:"sm",onClick:L,children:"Select loaded failures"})})]}),o.jsxs("div",{className:K("grid w-full h-full grid-cols-1 gap-4 overflow-y-auto",q&&"grid-cols-[1fr_1fr]"),children:[o.jsx("div",{className:"flex overflow-y-auto w-full",children:o.jsx("div",{className:"grid gap-8 content-start w-full overflow-y-auto",children:o.jsx(Fes,{results:r,isLoading:s,featuredResultId:c,onResultClick:X,columns:oe,scoresByItemId:$,scorerIds:U,setEndOfListElement:a,isFetchingNextPage:i,hasNextPage:l,selectedIds:y,onToggleSelect:R})})}),q&&o.jsxs("div",{className:"grid gap-4 max-h-full min-h-0 overflow-auto content-start",style:{gridTemplateRows:ze},children:[o.jsx(Les,{result:q,scores:ae,onPrevious:ee(),onNext:J(),onClose:te,onScoreClick:Y,featuredScoreId:m,onShowTrace:()=>{q.traceId&&(f(q.traceId),h(void 0),v(null),_(!0),E(!1))},onOpenInReview:()=>{B(q.id),F("reviews")},onFlagForReview:se=>M([se]),collapsed:k,onCollapsedChange:_}),ce&&o.jsx(qes,{score:ce,onNext:ne(),onPrevious:ue(),onClose:()=>v(null),onShowTrace:()=>{ce.traceId&&(f(ce.traceId),h(void 0),_(!0),N(!0),E(!1))},collapsed:j,onCollapsedChange:N}),d&&o.jsxs(o.Fragment,{children:[o.jsx(uTe,{traceId:d,spans:ve,isLoading:le,onClose:()=>{f(null),h(void 0),_(!1),N(!1)},onSpanSelect:h,initialSpanId:p??null,placement:"traces-list",showUnavailableFeaturesMsg:!1,collapsed:C,onCollapsedChange:E,LinkComponent:BD,traceHref:`/traces/${d}`}),p&&o.jsx(WH,{traceId:d,spanId:p,span:Ne,isLoading:Se,onPrevious:ke,onNext:Ie,onClose:()=>h(void 0)})]})]})]})]})]})}const Hes={pending:o.jsx(dO,{}),running:o.jsx(tfe,{}),completed:o.jsx(Js,{}),failed:o.jsx(vs,{})};function Wes({experiment:e,className:t}){const n=e.status,r=e.totalItems-e.succeededCount-e.failedCount;return o.jsxs("div",{className:K("grid justify-items-end gap-3",t),children:[o.jsxs("div",{className:"flex p-1 px-3 text-ui-lg capitalize text-neutral4 gap-2 items-center bg-surface5 rounded-lg ",children:[o.jsx("span",{className:K("w-5 h-5 flex items-center justify-center rounded-full text-black","[&>svg]:w-4 [&>svg]:h-4",{"bg-green-700":n==="completed","bg-red-700":n==="failed","bg-cyan-600":n==="running","bg-yellow-600":n==="pending"}),children:Hes[n]}),e.status]}),o.jsxs("div",{className:K("flex items-center gap-3 text-neutral3 text-ui-md ","[&>span]:flex [&>span]:gap-1 [&>span]:items-center ","[&_b]:text-neutral4 [&_b]:font-semibold"),children:[o.jsxs("span",{children:["Total: ",o.jsx("b",{children:e.totalItems})]}),o.jsxs("span",{children:["Succeeded: ",o.jsx("b",{children:e.succeededCount})]}),o.jsxs("span",{children:["Failed: ",o.jsx("b",{children:e.failedCount})]}),(n==="pending"||n==="running")&&o.jsxs("span",{children:["Pending: ",o.jsx("b",{children:r})]})]})]})}function Zes({onPrevious:e,onNext:t,previousAriaLabel:n="Previous",nextAriaLabel:r="Next"}){return o.jsxs(Mr,{spacing:"close",children:[o.jsxs(de,{onClick:e,disabled:!e,"aria-label":n,children:[o.jsx(Gq,{})," Prev"]}),o.jsxs(de,{onClick:t,disabled:!t,"aria-label":r,children:["Next",o.jsx(Wq,{})]})]})}function kTe({delta:e}){const t=e>0?o.jsx(Xs,{size:"small",color:"green",intensity:"muted",children:o.jsx(pD,{})}):e<0?o.jsx(Xs,{size:"small",color:"red",intensity:"muted",children:o.jsx(Cln,{})}):null;return o.jsxs("span",{className:K("font-mono text-sm text-neutral4 min-w-20"),children:[o.jsx("span",{className:"w-3 inline-block",children:e>0?"+ ":e<0?"- ":""}),Math.abs(e).toFixed(2)," ",t]})}function nF(e){return e==null?"-":typeof e=="string"?e:JSON.stringify(e,null,2)}function Ges({item:e,baselineId:t,contenderId:n,baselineVersion:r,contenderVersion:s,onPrevious:a,onNext:i,onClose:l}){const c=e.results[t],u=e.results[n],d=!!(c&&u),f=new Set;if(c)for(const h of Object.keys(c.scores))f.add(h);if(u)for(const h of Object.keys(u.scores))f.add(h);const p=[...f].sort();return o.jsxs(Gr,{withLeftSeparator:!0,children:[o.jsxs(Gr.Toolbar,{children:[o.jsx(Zes,{onPrevious:a,onNext:i,previousAriaLabel:"Previous comparison item",nextAriaLabel:"Next comparison item"}),o.jsx(Mr,{children:o.jsx(de,{onClick:l,"aria-label":"Close comparison detail panel",children:o.jsx(vs,{})})})]}),o.jsxs(Gr.Content,{className:"pb-6",children:[o.jsx(ua,{withMargins:!1,children:o.jsx(ua.Column,{children:o.jsxs(ua.Title,{size:"smaller",children:[o.jsx(yN,{})," ",e.itemId]})})}),d?o.jsx(o.Fragment,{children:o.jsxs(Uje,{children:[p.length>0&&o.jsxs("div",{className:"grid gap-3",children:[o.jsx("h4",{className:"text-sm font-medium text-neutral5",children:"Scores"}),o.jsx("div",{className:"grid gap-2",children:p.map(h=>{const m=c?.scores[h]??null,v=u?.scores[h]??null,y=m!=null&&v!=null?v-m:null;return o.jsxs("div",{className:"flex items-center justify-between gap-4 px-3 py-2 rounded-lg bg-surface2",children:[o.jsx("span",{className:"text-sm text-neutral5 font-medium",children:h}),o.jsxs("div",{className:"flex items-center gap-4",children:[o.jsxs("span",{className:"text-sm text-neutral3",children:[m!=null?m.toFixed(3):"-"," →"," ",v!=null?v.toFixed(3):"-"]}),y!=null&&o.jsx(kTe,{delta:y})]})]},h)})})]}),o.jsx(Ps.CodeSection,{title:o.jsxs(o.Fragment,{children:[o.jsx(Xs,{color:"purple",children:"Baseline "})," Experiment Output"]}),icon:o.jsx(gg,{}),codeStr:nF(c?.output)}),o.jsx(Ps.CodeSection,{title:o.jsxs(o.Fragment,{children:[o.jsx(Xs,{color:"cyan",children:"Contender "})," Experiment Output"]}),icon:o.jsx(gg,{}),codeStr:nF(u?.output)}),o.jsx(Ps.CodeSection,{title:"Item Input",icon:o.jsx(fO,{}),codeStr:nF(e.input)}),o.jsx(Ps.CodeSection,{title:"Item Ground Truth",icon:o.jsx(ube,{}),codeStr:nF(e.groundTruth)})]})}):o.jsx(In,{variant:"warning",title:"Comparison not available",children:o.jsx(In.Message,{children:(()=>{const h=c?"Contender":"Baseline",m=c?s:r;return o.jsxs(o.Fragment,{children:["The ",h," experiment was run against dataset",m!=null?` v. ${m}`:"",", which does not contain this item."]})})()})})]})]})}function Qes({items:e,baselineId:t,contenderId:n,scorerIds:r,featuredItemId:s,columns:a,onItemClick:i}){return o.jsx(Gr,{children:o.jsxs(gn,{children:[o.jsxs(gn.Header,{columns:a,children:[o.jsx(gn.HeaderCol,{children:"Item ID"}),!s&&r.map(l=>o.jsx(gn.HeaderCol,{className:"flex justify-center",children:l},l))]}),o.jsx(gn.Scroller,{children:o.jsx(gn.Items,{children:e.map(l=>{const c=l.results[t],u=l.results[n],d=!!(c&&u);return o.jsx(gn.Row,{children:o.jsxs(gn.RowButton,{item:{id:l.itemId},columns:a,isFeatured:s===l.itemId,onClick:i,children:[o.jsx(gn.IdCell,{id:l.itemId,className:d?"":"text-neutral1"}),!s&&o.jsx(o.Fragment,{children:r.map(f=>{const p=c?.scores[f]??null,h=u?.scores[f]??null,m=p!=null&&h!=null?h-p:null;return o.jsx(gn.Cell,{className:"flex items-center gap-5 justify-center font-mono",children:m!=null?o.jsxs(o.Fragment,{children:[o.jsxs("span",{className:"flex items-center text-neutral2 min-w-24",children:[p?.toFixed(2)," → ",h?.toFixed(2)]}),o.jsx(kTe,{delta:m})]}):o.jsx("span",{className:"text-neutral1",children:"-"})},f)})})]})},l.itemId)})})})]})})}const Yes={baseline:{label:"Baseline",color:"purple",customStyle:"items-end justify-items-end [&>div]:justify-end border-r-0 rounded-r-none"},contender:{label:"Contender",color:"cyan",customStyle:"items-start justify-items-start [&>div]:justify-start border-l-0 rounded-l-none"}};function PQe({datasetId:e,experiment:t,type:n}){const{Link:r}=yn(),{label:s,color:a,customStyle:i}=Yes[n];if(!t)return null;const l=t.createdAt?new Date(t.createdAt):null;return o.jsxs("div",{className:`grid border-2 border-border1 rounded-lg p-5 gap-3 ${i}`,children:[o.jsxs("div",{className:"flex items-center gap-3 w-full overflow-clip",children:[n==="contender"&&o.jsxs(Xs,{size:"small",color:a,children:[s,o.jsx(mm,{})]}),o.jsx(de,{as:r,href:`/datasets/${e}/experiments/${t.id}`,children:o.jsx("span",{className:"truncate min-w-0",children:t.id})}),n==="baseline"&&o.jsxs(Xs,{size:"small",color:a,children:[o.jsx(Nc,{})," ",s]})]}),o.jsxs("div",{className:"flex flex-wrap gap-x-4 gap-y-1 text-ui-sm text-neutral3",children:[o.jsxs(Al,{children:[o.jsx(ube,{})," ",t.targetType," / ",t.targetId]}),o.jsxs(Al,{children:[o.jsx(fq,{})," v",t.datasetVersion??"—"]}),l&&o.jsxs(Al,{children:[o.jsx(Ilt,{})," ",er(l,"MMM d, yyyy HH:mm")]})]})]})}function Xes({datasetId:e,experimentIdA:t,experimentIdB:n,onSwap:r}){const[s,a]=g.useState(null),{data:i,isLoading:l,error:c}=FKr(e,t,n),{data:u}=zU(e,t),{data:d}=zU(e,n),f=u&&d&&u.datasetVersion!==d.datasetVersion,p=g.useMemo(()=>{if(!i)return[];const E=new Set;for(const j of i.items)for(const N of Object.values(j.results))if(N)for(const I of Object.keys(N.scores))E.add(I);return[...E].sort()},[i]),h=g.useMemo(()=>{if(!i||p.length===0)return[];const E=i.baselineId,j=t===E?n:t;return p.map(N=>{let I=0,R=0,P=0,L=0;for(const F of i.items){const z=F.results[E]?.scores[N],B=F.results[j]?.scores[N];z!=null&&(I+=z,P++),B!=null&&(R+=B,L++)}const M=P>0?I/P:null,q=L>0?R/L:null,H=M!=null&&q!=null?q-M:null;return{scorerId:N,avgA:M,avgB:q,delta:H}})},[i,p,t,n]),m=[{name:"scorer",label:"Scorer",size:"1fr"},{name:"baselineAvg",label:"Baseline Avg",size:"1fr"},{name:"comparisonAvg",label:"Comparison Avg",size:"1fr"},{name:"delta",label:"Delta",size:"1fr"}],v=g.useMemo(()=>[{name:"itemId",label:"Item ID",size:"8rem"},...s?[]:p.map(E=>({name:E,label:E,size:"1fr"}))],[p,s]),y=i?.items.find(E=>E.itemId===s)??null,b=E=>{a(E===s?null:E)},S=()=>{a(null)},w=()=>{if(!i||!s)return;const E=i.items.findIndex(j=>j.itemId===s);if(E>=0&&E<i.items.length-1)return()=>a(i.items[E+1].itemId)},k=()=>{if(!i||!s)return;const E=i.items.findIndex(j=>j.itemId===s);if(E>0)return()=>a(i.items[E-1].itemId)};if(l)return o.jsx("div",{className:"flex items-center justify-center h-64",children:o.jsx(Gt,{})});if(c)return o.jsx(In,{variant:"warning",title:"Error loading comparison",children:o.jsx(In.Message,{children:c instanceof Error?c.message:"Unknown error"})});if(!i||i.items.length===0)return o.jsx("div",{className:"text-neutral4 text-sm text-center py-8",children:"No comparison data"});const _=i.baselineId,C=t===_?n:t;return o.jsxs("div",{className:"grid gap-10",children:[u&&d&&o.jsxs("div",{className:K("relative grid xl:grid-cols-[1fr_auto_1fr] gap-4 xl:gap-0"),children:[o.jsx(PQe,{datasetId:e,experiment:u,type:"baseline"}),o.jsx("div",{className:"relative flex items-center justify-center px-[2vw] before:absolute before:inset-y-0 before:left-1/2 before:-translate-x-1/2 before:w-[2px] before:bg-border1",children:o.jsx("div",{className:"relative z-1 bg-surface2 rounded-lg p-2",children:o.jsxs(Wn,{children:[o.jsx(zn,{asChild:!0,children:o.jsx(de,{onClick:r,children:"VS"})}),o.jsx(Bn,{children:"Switch the order"})]})})}),o.jsx(PQe,{datasetId:e,experiment:d,type:"contender"})]}),f&&o.jsx(In,{variant:"warning",title:"Version mismatch",children:o.jsxs(In.Message,{children:["These experiments used different dataset versions (v",u.datasetVersion," vs v",d.datasetVersion,"). Results may not be directly comparable."]})}),h.length>0&&o.jsxs(gn,{children:[o.jsxs(gn.Header,{columns:m,children:[o.jsx(gn.HeaderCol,{children:"Scorer"}),o.jsx(gn.HeaderCol,{className:"flex justify-center",children:o.jsxs(MGe,{children:[o.jsx(Xs,{color:"purple",size:"small",intensity:"muted",children:"Baseline"}),o.jsx(Xs,{color:"purple",size:"small",children:"Avg"})]})}),o.jsx(gn.HeaderCol,{className:"flex justify-center",children:o.jsxs(MGe,{children:[o.jsx(Xs,{color:"cyan",size:"small",intensity:"muted",children:"Contender"}),o.jsx(Xs,{color:"cyan",size:"small",children:"Avg"})]})}),o.jsx(gn.HeaderCol,{className:"flex justify-center",children:"Delta"})]}),o.jsx(gn.Scroller,{children:o.jsx(gn.Items,{children:h.map(({scorerId:E,avgA:j,avgB:N,delta:I})=>o.jsxs(gn.Row,{columns:m,children:[o.jsx(gn.TextCell,{children:E}),o.jsx(gn.TextCell,{className:"text-center font-mono",children:j!=null?j.toFixed(3):"-"}),o.jsx(gn.TextCell,{className:"text-center font-mono",children:N!=null?N.toFixed(3):"-"}),o.jsx(gn.TextCell,{className:"flex justify-center",children:I!=null?o.jsx(kTe,{delta:I}):"-"})]},E))})})]}),o.jsxs(sy,{className:K({"grid-cols-[1fr_2fr]":!!y}),children:[o.jsx(Qes,{items:i.items,baselineId:_,contenderId:C,scorerIds:p,featuredItemId:s,columns:v,onItemClick:b}),!!y&&o.jsx(Ges,{item:y,baselineId:_,contenderId:C,baselineVersion:u?.datasetVersion,contenderVersion:d?.datasetVersion,onPrevious:k(),onNext:w(),onClose:S})]})]})}function Kes({datasetId:e,itemId:t,onVersionSelect:n,onCompareVersionsClick:r,activeVersion:s}){const{data:a,isLoading:i}=vTe(e,t),[l,c]=g.useState(!1),[u,d]=g.useState(new Set),f=b=>{n?.(b)},p=b=>s==null?b.isLatest:b.datasetVersion===s,h=b=>{d(S=>{const w=new Set(S);if(w.has(b))w.delete(b);else if(w.size>=2){const[k]=Array.from(w);return new Set([k,b])}else w.add(b);return w})},m=()=>{c(!1),d(new Set)},v=()=>{c(!0)},y=()=>{u.size===2&&r?.([...u])};return o.jsxs(Gr,{className:"min-w-56",children:[l?o.jsx(Gr.Toolbar,{className:"grid justify-stretch gap-3 w-full",children:o.jsxs(Mr,{children:[o.jsx(de,{onClick:m,children:"Cancel"}),o.jsx(de,{variant:"primary",disabled:u.size!==2,onClick:y,tooltip:u.size!==2?"Check 2 versions to compare":void 0,className:"grow",children:"Compare"})]})}):o.jsx(o.Fragment,{children:(a||[]).length>1&&o.jsx(Gr.Toolbar,{children:o.jsxs(de,{onClick:v,className:"w-full",children:[o.jsx(Xw,{})," Compare Ver."]})})}),i?o.jsx(Jes,{}):o.jsxs(gn,{children:[o.jsx(gn.Header,{children:o.jsx(gn.HeaderCol,{children:"Item Version History"})}),o.jsx(gn.Scroller,{children:o.jsx(gn.Items,{children:a?.map(b=>{const S=String(b.datasetVersion),w=typeof b.updatedAt=="string"?new Date(b.updatedAt):b.updatedAt;return o.jsxs(gn.Row,{isSelected:l&&u.has(S),children:[l&&o.jsx(gn.LabelCell,{children:o.jsx(Mo,{checked:u.has(S),disabled:b.isDeleted,onCheckedChange:()=>{},onClick:k=>{k.stopPropagation(),b.isDeleted||h(S)},"aria-label":`Select version ${b.datasetVersion}`})}),o.jsx(gn.RowButton,{item:b,columns:[{name:"version",label:"Item Version History",size:"1fr"}],isFeatured:p(b),onClick:()=>f(b),className:"py-2",children:o.jsx(gn.VersionCell,{version:b.datasetVersion,date:w,isLatest:b.isLatest,isDeleted:b.isDeleted})})]},String(b.datasetVersion))})})})]})]})}function Jes(){return o.jsxs(gn,{children:[o.jsx(gn.Header,{columns:[{name:"version",label:"Item Version History",size:"1fr"}],children:o.jsx(gn.HeaderCol,{children:"Item Version History"})}),o.jsx(gn.Items,{children:Array.from({length:3}).map((e,t)=>o.jsx(gn.Row,{children:o.jsx(gn.RowButton,{columns:[{name:"version",label:"Item Version History",size:"1fr"}],children:o.jsx(gn.TextCell,{isLoading:!0,children:"Loading..."})})},t))})]})}function ets(e,t){if(t){const n=typeof t=="string"?new Date(t):t;return`v${e} ${er(n,"MMM dd 'at' H:mm:ss a")}`}return`v${e}`}function tts({datasetId:e,versionA:t,versionB:n,onVersionChange:r}){const{data:s}=nTe(e),a=(s??[]).map(i=>({value:String(i.version),label:`${ets(i.version,i.createdAt)}${i.isCurrent?" (current)":""}`}));return o.jsxs(Gr.Toolbar,{className:"grid grid-cols-[1fr_1fr_1fr_10rem] gap-4 w-full",children:[o.jsx("div",{}),o.jsx(Sc,{label:"Version A",labelIsHidden:!0,name:"version-a",placeholder:"Select version",options:a,value:t??"",onValueChange:i=>r?.(i,n??"")}),o.jsx(Sc,{label:"Version B",labelIsHidden:!0,name:"version-b",options:a,value:n??"",onValueChange:i=>r?.(t??"",i)}),o.jsx("div",{})]})}const nts=[{name:"id",label:"ID",size:"1fr"},{name:"versionA",label:"Version A",size:"1fr"},{name:"versionB",label:"Version B",size:"1fr"},{name:"compare",label:"Compare",size:"10rem"}],rts={added:{color:"blue",borderColor:"border-blue-900",icon:o.jsx(Vr,{}),tooltip:"Added in this version"},changed:{color:"orange",borderColor:"border-yellow-900",icon:o.jsx(Ylt,{}),tooltip:"Changed in this version"},same:{color:"green",borderColor:"border-green-900",icon:o.jsx(Qcn,{}),tooltip:"Same in both versions"}};function ese({red:e=!1,tooltip:t}){return o.jsxs(Wn,{children:[o.jsx(zn,{asChild:!0,children:o.jsx(Mln,{className:K("text-neutral3/40 w-5 h-5 ",{"text-red-900":e})})}),t&&o.jsx(Bn,{children:t})]})}function QS({variant:e,version:t}){if(!e)return o.jsxs("span",{className:"text-ui-md text-neutral4",children:["v. ",t]});const{color:n,icon:r,tooltip:s}=rts[e];return o.jsxs(Wn,{children:[o.jsx(zn,{asChild:!0,children:o.jsxs("div",{className:"grid grid-cols-[1fr_auto]",children:[t!==void 0&&o.jsxs("span",{className:"pr-3 text-ui-md text-neutral4 min-w-16 flex justify-end",children:["v. ",t]}),o.jsx(Xs,{color:n,size:"small",children:r})]})}),o.jsx(Bn,{children:s})]})}function sts(e,t){return e&&t&&e.datasetVersion===t.datasetVersion?"same":e&&t&&e.datasetVersion!==t.datasetVersion?"changed":e?"added":"removed"}function ats({datasetId:e,versionA:t,versionB:n,allItems:r,itemsAMap:s,itemsBMap:a}){const{Link:i}=yn(),l=t>n;return o.jsx(gn,{children:o.jsx(gn.Scroller,{children:o.jsx(gn.Items,{children:r.map(({id:c})=>{const u=s.get(c),d=a.get(c),f=sts(u,d);return o.jsxs(gn.Row,{columns:nts,children:[o.jsx(gn.IdCell,{id:c,isShortened:!1}),f!=="same"?o.jsxs(o.Fragment,{children:[u?.datasetVersion?o.jsx(gn.LinkCell,{LinkComponent:i,href:`/datasets/${e}/items/${c}`,className:"gap-2",children:!d&&l?o.jsx(QS,{variant:"added",version:u.datasetVersion}):f==="changed"&&l?o.jsx(QS,{variant:"changed",version:u.datasetVersion}):o.jsx(QS,{version:u.datasetVersion})}):o.jsx(gn.Cell,{className:"justify-center flex items-center",children:o.jsx(ese,{red:l,tooltip:l?"Deleted in this version":"Not present in this version"})}),d?.datasetVersion?o.jsx(gn.LinkCell,{LinkComponent:i,href:`/datasets/${e}/items/${c}`,className:"gap-2",children:!u&&!l?o.jsx(QS,{variant:"added",version:d.datasetVersion}):f==="changed"&&!l?o.jsx(QS,{variant:"changed",version:d.datasetVersion}):o.jsx(QS,{version:d.datasetVersion})}):o.jsx(gn.Cell,{className:"justify-center flex items-center",children:o.jsx(ese,{red:!l,tooltip:l?"Not present in this version":"Deleted in this version"})})]}):o.jsx(gn.LinkCell,{LinkComponent:i,href:`/datasets/${e}/items/${c}`,className:"col-span-2 gap-2",children:o.jsx(QS,{variant:"same",version:d?.datasetVersion})}),f==="changed"?o.jsx(gn.LinkCell,{LinkComponent:i,href:`/datasets/${e}/items/${c}/versions?ids=${u?.datasetVersion},${d?.datasetVersion}`,children:"Compare"}):o.jsx(gn.Cell,{children:o.jsx(ese,{tooltip:o.jsxs(o.Fragment,{children:["Comparing is available",o.jsx("br",{})," only for changed items"]})})})]},c)})})})})}const $Qe={needsReview:"#facc15",complete:"#22c55e"},its=[{label:"Needs Review",color:$Qe.needsReview},{label:"Reviewed",color:$Qe.complete}];function ots({reviewSummary:e,experiments:t,datasets:n,isLoading:r,isError:s}){const{data:a,maxVal:i,totalInPipeline:l}=g.useMemo(()=>{if(!e?.counts||!t)return{data:[],maxVal:0,totalInPipeline:0};const u=new Map;for(const m of t)u.set(m.id,m);const d=new Map;if(n)for(const m of n)d.set(m.id,m.name);let f=0,p=0;const h=[];for(const m of e.counts){const v=m.needsReview+m.complete;if(v===0)continue;p+=v,v>f&&(f=v);const y=u.get(m.experimentId),b=y?.datasetId?d.get(y.datasetId):void 0,S=b?`${b} · ${m.experimentId.slice(0,8)}`:m.experimentId.slice(0,8);h.push({name:S,values:[m.needsReview,m.complete]})}return{data:h,maxVal:f,totalInPipeline:p}},[e,t,n]),c=a.length>0;return o.jsxs(Ut,{children:[o.jsxs(Ut.TopBar,{children:[o.jsx(Ut.TitleAndDescription,{title:"Review Pipeline",description:"Items in review across experiments."}),c&&o.jsx(Ut.Summary,{value:String(l),label:"Items in pipeline"})]}),r?o.jsx(Ut.Loading,{}):s?o.jsx(Ut.Error,{message:"Failed to load review data"}):o.jsx(Ut.Content,{children:c?o.jsx(uN,{data:a,segments:its,maxVal:i,fmt:u=>String(u)}):o.jsx(Ut.NoData,{message:"No items have been sent to review yet"})})]})}function OTe(){const e=We();return wt({queryKey:["experiment-review-summary"],queryFn:()=>e.getExperimentReviewSummary()})}function P9t(e){const t=new Map;if(!e?.counts)return t;for(const n of e.counts)t.set(n.experimentId,{needsReview:n.needsReview,complete:n.complete,total:n.total});return t}function lts(e,t){const n=new Map,r=P9t(e);if(!r.size||!t)return n;for(const s of t){const a=r.get(s.id);if(!a||!s.datasetId||a.needsReview+a.complete===0)continue;const l=n.get(s.datasetId)??{needsReview:0,complete:0};l.needsReview+=a.needsReview,l.complete+=a.complete,n.set(s.datasetId,l)}return n}function cts(e){return e?.counts?e.counts.reduce((t,n)=>({needsReview:t.needsReview+n.needsReview,complete:t.complete+n.complete,inPipeline:t.inPipeline+n.needsReview+n.complete}),{needsReview:0,complete:0,inPipeline:0}):{needsReview:0,complete:0,inPipeline:0}}const uts=10;function dts(){const[e,t]=g.useState(!1),[n,r]=g.useState(""),[s,a]=g.useState("all"),[i,l]=g.useState("all"),[c,u]=g.useState("all"),[d,f]=g.useState(0),{data:p,isLoading:h,error:m}=$g({page:d,perPage:uts}),{data:v,isLoading:y,error:b}=JZ(),{data:S}=OTe(),w=g.useMemo(()=>p?.datasets??[],[p?.datasets]),k=p?.pagination?.hasMore??!1,_=g.useMemo(()=>v?.experiments??[],[v?.experiments]),C=g.useMemo(()=>rJr(w),[w]),E=g.useMemo(()=>lts(S,_),[S,_]),j=h||y,N=m||b,I=()=>t(!0),R=g.useCallback(()=>f(B=>B+1),[]),P=g.useCallback(()=>f(B=>Math.max(0,B-1)),[]),L=g.useCallback(B=>{r(B),f(0)},[]),M=g.useCallback(B=>{a(B),f(0)},[]),q=g.useCallback(B=>{l(B),f(0)},[]),H=g.useCallback(B=>{u(B),f(0)},[]);if(N&&gs(N))return o.jsx(lr,{children:o.jsx(Vs,{})});if(N&&ys(N))return o.jsx(lr,{children:o.jsx(Ds,{resource:"datasets"})});if(N)return o.jsx(lr,{children:o.jsx(zi,{title:"Failed to load datasets",message:N.message})});if(w.length===0&&!j&&d===0)return o.jsxs(o.Fragment,{children:[o.jsx(lr,{children:o.jsx(lJr,{onCreateClick:I})}),o.jsx(Fve,{open:e,onOpenChange:t})]});const F=s!=="all"||i!=="all"||c!=="all"||n!=="",z=()=>{r(""),a("all"),l("all"),u("all"),f(0)};return o.jsxs(Lt,{children:[o.jsx(Lt.TopArea,{children:o.jsx(dJr,{search:n,onSearchChange:L,targetFilter:s,onTargetFilterChange:M,experimentFilter:i,onExperimentFilterChange:q,tagFilter:c,onTagFilterChange:H,tagOptions:C,onReset:z,hasActiveFilters:F,onCreateClick:I})}),o.jsx(oJr,{datasets:w,experiments:_,reviewByDataset:E,isLoading:j,search:n,targetFilter:s,experimentFilter:i,tagFilter:c,currentPage:d,hasMore:k,onNextPage:R,onPrevPage:P}),o.jsx(Fve,{open:e,onOpenChange:t})]})}function rF({children:e}){return o.jsxs(Lt,{height:"full",children:[o.jsx("div",{}),o.jsx(Lt.MainArea,{isCentered:!0,children:e})]})}function fts(){const{datasetId:e}=ur(),t=bs(),[n,r]=ga(),{activeVersion:s}=yTe(n,r),[a,i]=g.useState(!1),[l,c]=g.useState(!1),[u,d]=g.useState(!1),[f,p]=g.useState(!1),[h,m]=g.useState(!1),{data:v,error:y,isLoading:b}=Hx(e),{data:S=[],isLoading:w}=E1(e,void 0,s),k=!w&&S.length===0;if(b)return null;if(y&&gs(y))return o.jsx(rF,{children:o.jsx(Vs,{})});if(y&&ys(y))return o.jsx(rF,{children:o.jsx(Ds,{resource:"datasets"})});if(y&&vOe(y)||!b&&!y&&!v)return o.jsx(rF,{children:o.jsx(Cr,{iconSlot:o.jsx(iy,{}),titleSlot:"Dataset not found",descriptionSlot:`No dataset with id "${e}".`,actionSlot:o.jsxs(de,{as:Ba,to:"/datasets",children:[o.jsx(Nc,{}),"Back to Datasets"]})})});if(y)return o.jsx(rF,{children:o.jsx(zi,{title:"Failed to load dataset",message:y instanceof Error?y.message:"An unexpected error occurred. Please try again."})});const _=E=>{t(`/datasets/${e}/experiments/${E}`)},C=()=>{t("/datasets")};return o.jsxs(o.Fragment,{children:[o.jsxs(Lt,{height:"full",children:[o.jsx(Lt.TopArea,{children:o.jsxs(Lt.Row,{children:[o.jsxs(Lt.Column,{children:[v?.description&&o.jsx("p",{className:"text-ui-smd text-neutral3 mb-1",children:v.description}),o.jsxs(Bt,{numOfCol:2,children:[o.jsx(Bt.Key,{children:"Created at"}),o.jsx(Bt.Value,{children:v?.createdAt?er(new Date(v.createdAt),"MMM d, yyyy"):""}),o.jsx(Bt.Key,{children:"Latest version"}),o.jsxs(Bt.Value,{children:["v",v?.version??""]})]})]}),o.jsx(Lt.Column,{children:o.jsxs(Mr,{children:[k?o.jsxs(Wn,{children:[o.jsx(zn,{asChild:!0,children:o.jsx("span",{className:"cursor-not-allowed",children:o.jsx("div",{className:"pointer-events-none opacity-50",inert:!0,"aria-disabled":"true",children:o.jsxs(de,{variant:"primary",children:[o.jsx(Fp,{}),s!=null?`Run on v${s}`:"Run Experiment"]})})})}),o.jsx(Bn,{children:"Add items to the dataset before running an experiment"})]}):o.jsxs(de,{variant:"primary",onClick:()=>i(!0),children:[o.jsx(Fp,{}),s!=null?`Run on v${s}`:"Run Experiment"]}),o.jsxs(pt,{children:[o.jsx(pt.Trigger,{asChild:!0,children:o.jsx(de,{size:"lg","aria-label":"Dataset actions menu",children:o.jsx(mD,{})})}),o.jsxs(pt.Content,{align:"end",className:"w-48",children:[o.jsxs(pt.Item,{onSelect:()=>d(!0),children:[o.jsx(Lp,{})," Edit Dataset"]}),o.jsxs(pt.Item,{onSelect:()=>m(!0),children:[o.jsx(Dp,{})," Duplicate Dataset"]}),o.jsxs(pt.Item,{onSelect:()=>p(!0),className:"text-red-500 focus:text-red-400",children:[o.jsx(au,{})," Delete Dataset"]})]})]})]})})]})}),o.jsx(Lt.MainArea,{children:o.jsx(Ces,{datasetId:e,onAddItemClick:()=>c(!0)})})]}),o.jsx(Pes,{datasetId:e,version:s??void 0,requestContextSchema:v?.requestContextSchema,open:a,onOpenChange:i,onSuccess:_}),o.jsx(jes,{datasetId:e,open:l,onOpenChange:c}),v&&o.jsx(vJr,{open:u,onOpenChange:d,dataset:{id:v.id,name:v.name,description:v?.description||"",targetType:v.targetType,inputSchema:v.inputSchema,groundTruthSchema:v.groundTruthSchema,requestContextSchema:v.requestContextSchema}}),v&&o.jsx(hJr,{open:h,onOpenChange:m,sourceDatasetId:v.id,sourceDatasetName:v.name,sourceDatasetDescription:v.description,sourceDatasetTargetType:v.targetType}),v&&o.jsx(bJr,{open:f,onOpenChange:p,datasetId:v.id,datasetName:v.name,onSuccess:C})]})}function $9t({experiment:e}){const{Link:t,paths:n}=yn(),{data:r}=km(),{data:s}=Uy(),{data:a}=ih(),i=()=>{switch(e.targetType){case"agent":return n.agentLink(e.targetId);case"workflow":return n.workflowLink(e.targetId);case"scorer":return n.scorerLink(e.targetId);default:return"#"}},l=()=>{const u=e.targetId;if(!u)return u;switch(e.targetType){case"agent":return r?.[u]?.name??u;case"workflow":return s?.[u]?.name??u;case"scorer":return a?.[u]?.scorer?.config?.name??u;default:return u}},c=e.agentVersion&&e.targetType==="agent"&&e.targetId?`${n.agentLink(e.targetId)}/editor?version=${encodeURIComponent(e.agentVersion)}`:null;return o.jsx(Lt.TopArea,{children:o.jsxs(Lt.Row,{children:[o.jsx(Lt.Column,{children:o.jsxs(Bt,{numOfCol:2,children:[o.jsx(Bt.Key,{children:"Created at"}),o.jsx(Bt.Value,{children:er(new Date(e.createdAt),"MMM d, yyyy 'at' h:mm a")}),e.completedAt&&o.jsxs(o.Fragment,{children:[o.jsx(Bt.Key,{children:"Completed at"}),o.jsx(Bt.Value,{children:er(new Date(e.completedAt),"MMM d, yyyy 'at' h:mm a")})]}),o.jsx(Bt.Key,{children:"Target"}),o.jsx(Bt.ValueLink,{href:i(),as:t,children:l()}),e.agentVersion&&o.jsxs(o.Fragment,{children:[o.jsx(Bt.Key,{children:"Version"}),c?o.jsx(Bt.ValueLink,{href:c,as:t,children:e.agentVersion}):o.jsx(Bt.Value,{children:e.agentVersion})]})]})}),o.jsx(Lt.Column,{children:o.jsx(Wes,{experiment:e})})]})})}function sF({children:e}){return o.jsxs(Lt,{height:"full",children:[o.jsx("div",{}),o.jsx(Lt.MainArea,{isCentered:!0,children:e})]})}function pts(){const{datasetId:e,experimentId:t}=ur(),{data:n,isLoading:r,error:s}=zU(e,t),{data:a,isLoading:i,setEndOfListElement:l,isFetchingNextPage:c,hasNextPage:u}=YZ({datasetId:e,experimentId:t,experimentStatus:n?.status});return!e||!t||r?null:s&&gs(s)?o.jsx(sF,{children:o.jsx(Vs,{})}):s&&ys(s)?o.jsx(sF,{children:o.jsx(Ds,{resource:"datasets"})}):s&&vOe(s)||!r&&!s&&!n?o.jsx(sF,{children:o.jsx(Cr,{iconSlot:o.jsx(tbe,{}),titleSlot:"Experiment not found",descriptionSlot:`No experiment with id "${t}".`,actionSlot:o.jsxs(de,{as:Ba,to:`/datasets/${e}?tab=experiments`,children:[o.jsx(Nc,{}),"Back to Dataset"]})})}):s?o.jsx(sF,{children:o.jsx(zi,{title:"Failed to load experiment",message:s instanceof Error?s.message:"An unexpected error occurred. Please try again."})}):o.jsxs(Lt,{height:"full",children:[o.jsx($9t,{experiment:n}),o.jsx(Lt.MainArea,{children:o.jsx(R9t,{experimentId:t,datasetId:e,experimentStatus:n.status,results:a??[],isLoading:i,setEndOfListElement:l,isFetchingNextPage:c,hasNextPage:u})})]})}function hts(){const{datasetId:e}=ur(),[t,n]=ga(),{error:r}=Hx(e??""),s=t.get("baseline")??"",a=t.get("contender")??"";return r&&gs(r)?o.jsx(ls,{children:o.jsx("div",{className:"flex h-full items-center justify-center",children:o.jsx(Vs,{})})}):r&&ys(r)?o.jsx(ls,{children:o.jsx("div",{className:"flex h-full items-center justify-center",children:o.jsx(Ds,{resource:"datasets"})})}):!e||!s||!a?o.jsx(ls,{children:o.jsx(wy,{children:o.jsxs("div",{className:"text-neutral4 text-center py-8",children:[o.jsx("p",{children:"Select two experiments to compare."}),o.jsxs("p",{className:"text-sm mt-2",children:["Use the URL format: /datasets/","{datasetId}","/experiments?baseline=","{experimentIdA}","&contender=","{experimentIdB}"]})]})})}):o.jsx(ls,{children:o.jsx(wy,{children:o.jsxs("div",{className:"max-w-[100rem] w-full px-12 mx-auto grid content-start ",children:[o.jsxs(ua,{children:[o.jsxs(ua.Column,{children:[o.jsxs(ua.Title,{children:[o.jsx(Xw,{})," Dataset Experiments Comparison"]}),o.jsxs(ua.Description,{children:["Comparing"," ",o.jsx(Ba,{to:`/datasets/${e}/experiments/${s}`,children:s.slice(0,8)})," vs"," ",o.jsx(Ba,{to:`/datasets/${e}/experiments/${a}`,children:a.slice(0,8)})]})]}),o.jsx(ua.Column,{children:o.jsxs(de,{as:Ba,to:`/datasets/${e}`,children:[o.jsx(Nc,{}),"Back to Dataset"]})})]}),o.jsx(Xes,{datasetId:e,experimentIdA:s,experimentIdB:a,onSwap:()=>{n({baseline:a,contender:s})}})]})})})}function mts(){const{datasetId:e,itemId:t}=ur(),{Link:n}=yn(),r=bs(),{data:s,isLoading:a,error:i}=vTe(e??"",t??""),{updateItem:l,deleteItem:c}=Ei(),{data:u}=Hx(e??""),d=s?.[0]??null,f=d?.isDeleted??!1,[p,h]=g.useState(null),m=g.useMemo(()=>!d||f?{input:"",groundTruth:"",metadata:"",trajectory:"",toolMocks:"",requestContext:""}:{input:JSON.stringify(d.input,null,2),groundTruth:d.groundTruth?JSON.stringify(d.groundTruth,null,2):"",metadata:d.metadata?JSON.stringify(d.metadata,null,2):"",trajectory:d.expectedTrajectory!=null?JSON.stringify(d.expectedTrajectory,null,2):"",toolMocks:d.toolMocks?.length?JSON.stringify(d.toolMocks,null,2):"",requestContext:d.requestContext?JSON.stringify(d.requestContext,null,2):""},[d,f]),v=d?.datasetVersion??0,[y,b]=g.useState(!1),[S,w]=g.useState(m.input),[k,_]=g.useState(m.groundTruth),[C,E]=g.useState(m.metadata),[j,N]=g.useState(m.trajectory),[I,R]=g.useState(m.toolMocks),[P,L]=g.useState(m.requestContext),[M,q]=g.useState(v);v!==M&&(q(v),w(m.input),_(m.groundTruth),E(m.metadata),N(m.trajectory),R(m.toolMocks),L(m.requestContext));const[H,F]=g.useState(!1),z=J=>{h(f?J:J.isLatest?null:J)},B=()=>{h(null)},D=!f&&p!=null,Q=()=>{D||b(!0)},V=()=>{D||F(!0)},$=async()=>{if(!e||!t)return;let J;try{J=JSON.parse(S)}catch{De.error("Input must be valid JSON");return}let ee;if(k.trim())try{ee=JSON.parse(k)}catch{De.error("Ground Truth must be valid JSON");return}let ae;if(C.trim())try{ae=JSON.parse(C)}catch{De.error("Metadata must be valid JSON");return}let ce;const Y=j!==m.trajectory;if(Y&&j.trim())try{ce=JSON.parse(j)}catch{De.error("Expected Trajectory must be valid JSON");return}let ne;const ue=I!==m.toolMocks;if(ue&&I.trim())try{const ve=JSON.parse(I);if(!Array.isArray(ve)){De.error("Tool Mocks must be a JSON array");return}ne=ve}catch{De.error("Tool Mocks must be valid JSON");return}let pe;const le=P!==m.requestContext;if(le&&P.trim())try{pe=JSON.parse(P)}catch{De.error("Request Context must be valid JSON");return}try{await l.mutateAsync({datasetId:e,itemId:t,input:J,groundTruth:ee,metadata:ae,...Y?{expectedTrajectory:ce??null}:{},...ue?{toolMocks:ne??[]}:{},...le?{requestContext:pe}:{}}),De.success("Item updated successfully"),b(!1)}catch(ve){De.error(`Failed to update item: ${ve instanceof Error?ve.message:"Unknown error"}`)}},U=()=>{d&&(w(JSON.stringify(d.input,null,2)),_(d.groundTruth?JSON.stringify(d.groundTruth,null,2):""),E(d.metadata?JSON.stringify(d.metadata,null,2):""),N(d.expectedTrajectory!=null?JSON.stringify(d.expectedTrajectory,null,2):""),R(d.toolMocks?.length?JSON.stringify(d.toolMocks,null,2):""),L(d.requestContext?JSON.stringify(d.requestContext,null,2):"")),b(!1)},Z=async()=>{if(!(!e||!t))try{await c.mutateAsync({datasetId:e,itemId:t}),De.success("Item deleted successfully"),F(!1),r(`/datasets/${e}`)}catch(J){De.error(`Failed to delete item: ${J instanceof Error?J.message:"Unknown error"}`)}},X=p??d,te=X?{id:t??"",datasetId:e??"",datasetVersion:X.datasetVersion,input:X.input,groundTruth:X.groundTruth,expectedTrajectory:X.expectedTrajectory,metadata:X.metadata,createdAt:X.createdAt,updatedAt:X.updatedAt}:null;return i&&gs(i)?o.jsx(ls,{children:o.jsx("div",{className:"flex h-full items-center justify-center",children:o.jsx(Vs,{})})}):i&&ys(i)?o.jsx(ls,{children:o.jsx("div",{className:"flex h-full items-center justify-center",children:o.jsx(Ds,{resource:"datasets"})})}):a?null:!e||!t||!s||s.length===0?o.jsx(ls,{children:o.jsx(wy,{children:o.jsx("div",{className:"text-neutral3 p-4",children:"Item not found"})})}):o.jsxs(o.Fragment,{children:[o.jsx(ls,{children:o.jsx("div",{className:"h-full overflow-hidden px-6 pb-4",children:o.jsxs("div",{className:"grid gap-6 max-w-[60rem] mx-auto grid-rows-[auto_1fr] h-full",children:[o.jsxs(ua,{children:[o.jsxs(ua.Column,{children:[o.jsxs(ua.Title,{children:[o.jsx(yN,{}),t," ",o.jsx(Oa,{content:t})]}),o.jsx(ua.Description,{children:o.jsxs(Al,{children:["Item of ",o.jsx(iy,{})," ",u?.name]})}),o.jsxs(ua.Description,{children:[o.jsxs(Al,{children:[o.jsx(Nlt,{})," Created at"," ",d?.createdAt?er(new Date(d.createdAt),"MMM d, yyyy"):""]}),o.jsxs(Al,{children:[o.jsx(p_,{})," Latest version v",d?.datasetVersion??""]})]})]}),o.jsx(ua.Column,{children:!y&&!f&&o.jsxs(Mr,{children:[o.jsxs(de,{onClick:Q,disabled:D,title:D?"Return to latest version to edit":void 0,children:[o.jsx(Ylt,{})," Edit"]}),o.jsxs(de,{onClick:V,disabled:D,title:D?"Return to latest version to delete":void 0,children:[o.jsx(au,{})," Delete"]})]})})]}),o.jsxs(sy,{className:y?"grid-cols-1":"grid-cols-[1fr_auto]",children:[o.jsxs(Gr,{withRightSeparator:!y,children:[f&&d&&o.jsx(In,{variant:"destructive",title:"Item deleted",children:o.jsxs(In.Message,{children:["This item was deleted at version v",d.datasetVersion]})}),!f&&D&&p&&o.jsx(In,{variant:"warning",title:"Previous version",action:o.jsxs(In.Button,{onClick:B,children:[o.jsx(_lt,{})," Return to the latest version"]}),children:o.jsxs(In.Message,{children:["Viewing version v",p.datasetVersion]})}),y?o.jsx(N9t,{inputValue:S,setInputValue:w,groundTruthValue:k,setGroundTruthValue:_,metadataValue:C,setMetadataValue:E,trajectoryValue:j,setTrajectoryValue:N,toolMocksValue:I,setToolMocksValue:R,requestContextValue:P,setRequestContextValue:L,validationErrors:null,onSave:$,onCancel:U,isSaving:l.isPending}):te?o.jsx(wTe,{item:te,Link:n}):o.jsx("div",{className:"text-neutral4 text-sm",children:"Item data not available"})]}),!y&&o.jsx(Gr,{children:o.jsx(Kes,{datasetId:e,itemId:t,onClose:()=>{},onVersionSelect:z,onCompareVersionsClick:J=>{r(`/datasets/${e}/items/${t}/versions?ids=${J.join(",")}`)},activeVersion:p?.datasetVersion??null})})]})]})})}),o.jsx(Tt,{open:H,onOpenChange:F,children:o.jsxs(Tt.Content,{children:[o.jsxs(Tt.Header,{children:[o.jsx(Tt.Title,{children:"Delete Item"}),o.jsx(Tt.Description,{children:"Are you sure you want to delete this item? This action cannot be undone."})]}),o.jsxs(Tt.Footer,{children:[o.jsx(Tt.Cancel,{children:"Cancel"}),o.jsx(Tt.Action,{onClick:Z,children:c.isPending?"Deleting...":"Delete"})]})]})})]})}function MQe(e){return JSON.stringify({input:e.input??null,groundTruth:e.groundTruth??null,metadata:e.metadata??null},null,2)}function gts(){const{datasetId:e}=ur(),[t,n]=ga(),r=t.get("items")?.split(",").filter(Boolean)??[],{data:s,error:a}=Hx(e??""),{Link:i}=yn(),[l,c]=g.useState(!1),{data:u}=BU(e??"",r[0]??""),{data:d}=BU(e??"",r[1]??"");return a&&gs(a)?o.jsx(ls,{children:o.jsx("div",{className:"flex h-full items-center justify-center",children:o.jsx(Vs,{})})}):a&&ys(a)?o.jsx(ls,{children:o.jsx("div",{className:"flex h-full items-center justify-center",children:o.jsx(Ds,{resource:"datasets"})})}):!e||r.length<2?o.jsx(ls,{children:o.jsx(wy,{children:o.jsx("div",{className:"text-neutral4 text-center py-8",children:o.jsx("p",{children:"Select at least two items to compare."})})})}):o.jsxs(ls,{children:[o.jsx(Iy,{owner:"dataset-items-compare",children:o.jsxs(de,{as:Ba,to:`/datasets/${e}`,variant:"outline",children:[o.jsx(Nc,{}),"Back to Dataset"]})}),o.jsx("div",{className:"h-full overflow-hidden px-[3vw] pb-4",children:o.jsxs("div",{className:K("grid gap-6 max-w-[140rem] mx-auto grid-rows-[auto_1fr] h-full",{"grid-rows-[auto_auto_1fr]":l}),children:[o.jsxs(ua,{children:[o.jsxs(ua.Column,{children:[o.jsxs(ua.Title,{children:[o.jsx(Xw,{}),"Compare Dataset Items"]}),o.jsx(ua.Description,{children:o.jsxs(Al,{children:["Comparing ",r.length," items of"," ",o.jsx(Ba,{to:`/datasets/${e}`,className:"text-info1 hover:underline",children:s?.name||e?.slice(0,8)})]})})]}),o.jsx(ua.Column,{children:o.jsx(Mr,{children:o.jsx(de,{variant:"primary",onClick:()=>c(f=>!f),children:l?o.jsxs(o.Fragment,{children:[o.jsx(Dlt,{})," Default View"]}):o.jsxs(o.Fragment,{children:[o.jsx(Bcn,{})," Diff View"]})})})})]}),o.jsx(sy,{className:"grid-cols-[1fr_3vw_1fr]",children:r.map((f,p)=>o.jsxs(g.Fragment,{children:[o.jsx(vts,{datasetId:e,itemId:f,Link:i,idx:p,itemIds:r,showContent:!l,onItemChange:h=>{const m=[...r];m[p]=h,n({items:m.join(",")})}}),p==0&&o.jsx("div",{className:K("bg-surface5 w-[3px] shrink-0 mx-[1.5vw]")})]},f))}),l&&u&&d&&o.jsx($_e,{codeA:MQe(u),codeB:MQe(d)})]})})]})}function vts({datasetId:e,itemId:t,Link:n,idx:r,itemIds:s,onItemChange:a,showContent:i=!0}){const{data:l,isLoading:c}=BU(e,t),{data:u}=E1(e),d=new Set(s.filter((p,h)=>h!==r)),f=(u??[]).map(p=>({value:p.id,label:p.id,disabled:d.has(p.id)}));return o.jsxs(Gr,{children:[o.jsxs(Gr.Toolbar,{className:"flex gap-4",children:[o.jsxs(da,{name:`compare-item-${r}`,value:t,onValueChange:a,children:[o.jsx(pa,{"aria-label":"Item",children:o.jsx(fa,{placeholder:"Select item"})}),o.jsx(ha,{children:f.map(p=>o.jsx(Lr,{value:p.value,disabled:p.disabled,children:p.label},p.value))})]}),o.jsxs(de,{as:n,to:`/datasets/${e}/items/${t}`,children:[o.jsx(p_,{}),"Versions"]})]}),i&&o.jsx(Gr.Content,{children:c?o.jsx("div",{className:"text-neutral4 text-sm",children:"Loading..."}):l?o.jsxs(o.Fragment,{children:[o.jsx(Tes,{item:l}),o.jsx(wTe,{item:l,Link:n})]}):o.jsxs("div",{className:"text-neutral4 text-sm",children:["Item ",t.slice(0,8)," not found"]})})]})}function DQe(e){return JSON.stringify({input:e.input??null,groundTruth:e.groundTruth??null,metadata:e.metadata??null},null,2)}function yts(){const{datasetId:e,itemId:t}=ur(),[n,r]=ga(),[s,a]=g.useState(!1),i=n.get("ids")?.split(",").map(Number).filter(h=>!isNaN(h)&&h>0)??[],{data:l,error:c}=Hx(e??""),{Link:u}=yn(),{data:d}=vTe(e??"",t??""),{data:f}=Bve(e??"",t??"",i[0]??0,l?.version),{data:p}=Bve(e??"",t??"",i[1]??0,l?.version);return c&&gs(c)?o.jsx(ls,{children:o.jsx("div",{className:"flex h-full items-center justify-center",children:o.jsx(Vs,{})})}):c&&ys(c)?o.jsx(ls,{children:o.jsx("div",{className:"flex h-full items-center justify-center",children:o.jsx(Ds,{resource:"datasets"})})}):!e||!t||i.length<2?o.jsx(ls,{children:o.jsx(wy,{children:o.jsx("div",{className:"text-neutral4 text-center py-8",children:o.jsx("p",{children:"Select at least two versions to compare."})})})}):o.jsxs(ls,{children:[o.jsx(Iy,{owner:"dataset-item-versions-compare",children:o.jsxs(de,{as:Ba,to:`/datasets/${e}/items/${t}`,variant:"outline",children:[o.jsx(Nc,{}),"Back to Item"]})}),o.jsx("div",{className:"h-full overflow-hidden px-[3vw] pb-4",children:o.jsxs("div",{className:K("grid gap-6 max-w-[140rem] mx-auto grid-rows-[auto_1fr] h-full",{"grid-rows-[auto_auto_1fr]":s}),children:[o.jsxs(ua,{children:[o.jsxs(ua.Column,{children:[o.jsxs(ua.Title,{children:[o.jsx(Xw,{}),"Compare Dataset Item Versions"]}),o.jsx(ua.Description,{children:o.jsxs(Al,{children:["Comparing ",i.length," versions of"," ",o.jsx(Ba,{to:`/datasets/${e}/items/${t}`,className:"text-info1 hover:underline",children:t})]})})]}),o.jsx(ua.Column,{children:o.jsx(Mr,{children:o.jsx(de,{variant:"primary",onClick:()=>a(h=>!h),children:s?o.jsxs(o.Fragment,{children:[o.jsx(Dlt,{})," Default View"]}):o.jsxs(o.Fragment,{children:[o.jsx(Cun,{})," Diff View"]})})})})]}),o.jsx(sy,{className:"grid-cols-[1fr_3vw_1fr]",children:i.map((h,m)=>o.jsxs(g.Fragment,{children:[o.jsx(bts,{datasetId:e,itemId:t,datasetVersion:h,latestVersion:l?.version,allVersions:d??[],versionNumbers:i,Link:u,idx:m,showContent:!s,onVersionChange:v=>{const y=[...i];y[m]=v,r({ids:y.join(",")})}}),m===0&&o.jsx("div",{className:K("bg-surface5 w-[3px] shrink-0 mx-[1.5vw]")})]},h))}),s&&f&&p&&o.jsx($_e,{codeA:DQe(f),codeB:DQe(p)})]})})]})}function bts({datasetId:e,itemId:t,datasetVersion:n,latestVersion:r,allVersions:s,versionNumbers:a,Link:i,idx:l,showContent:c=!0,onVersionChange:u}){const{data:d,isLoading:f}=Bve(e,t,n,r),p=new Set(a.filter((v,y)=>y!==l)),h=s.map(v=>{const y=typeof v.updatedAt=="string"?new Date(v.updatedAt):v.updatedAt;return{value:String(v.datasetVersion),label:o.jsxs(o.Fragment,{children:[o.jsxs("b",{children:["v. ",v.datasetVersion]})," - ",er(y,"MMM d, yyyy h:mm a"),v.isLatest?o.jsx(Xs,{color:"blue",size:"small",children:"Latest"}):null]}),disabled:p.has(v.datasetVersion)}}),m=d?{id:d.id,datasetId:e,datasetVersion:d.datasetVersion,input:d.input,groundTruth:d.groundTruth,metadata:d.metadata,createdAt:d.createdAt,updatedAt:d.updatedAt}:null;return o.jsxs(Gr,{children:[o.jsxs(Gr.Toolbar,{className:"grid gap-4 grid-cols-[auto_1fr]",children:[o.jsx(p_,{className:"w-6 h-6 opacity-50"}),o.jsxs(da,{name:`compare-version-${l}`,value:String(n),onValueChange:v=>u(Number(v)),children:[o.jsx(pa,{"aria-label":"Version",className:"w-full",children:o.jsx(fa,{placeholder:"Select version"})}),o.jsx(ha,{children:h.map(v=>o.jsx(Lr,{value:v.value,disabled:v.disabled,children:v.label},v.value))})]})]}),c&&o.jsx(Gr.Content,{children:f?o.jsx("div",{className:"text-neutral4 text-sm",children:"Loading..."}):!d||!m?o.jsxs("div",{className:"text-neutral4 text-sm",children:["Version ",n," not found"]}):o.jsx(wTe,{item:m,Link:i})})]})}function xts(){const{datasetId:e}=ur(),[t]=ga(),n=t.get("ids")?.split(",").map(Number).filter(v=>!isNaN(v)&&v>0)??[],r=bs(),{data:s,error:a}=Hx(e??""),i=E1(e??"",void 0,n[0]??null),l=E1(e??"",void 0,n[1]??null),c=g.useMemo(()=>i.data??[],[i.data]),u=g.useMemo(()=>l.data??[],[l.data]),d=g.useMemo(()=>{const v=new Map;for(const y of[...c,...u])v.has(y.id)||v.set(y.id,{id:y.id,createdAt:new Date(y.createdAt)});return[...v.values()].sort((y,b)=>b.createdAt.getTime()-y.createdAt.getTime())},[c,u]),f=g.useMemo(()=>new Map(c.map(v=>[v.id,v])),[c]),p=g.useMemo(()=>new Map(u.map(v=>[v.id,v])),[u]);if(a&&gs(a))return o.jsx(ls,{children:o.jsx("div",{className:"flex h-full items-center justify-center",children:o.jsx(Vs,{})})});if(a&&ys(a))return o.jsx(ls,{children:o.jsx("div",{className:"flex h-full items-center justify-center",children:o.jsx(Ds,{resource:"datasets"})})});if(!e||n.length<2)return o.jsx(ls,{children:o.jsx(wy,{children:o.jsx("div",{className:"text-neutral4 text-center py-8",children:o.jsx("p",{children:"Select at least two versions to compare."})})})});const h=(v,y,b)=>{r(`/datasets/${e}/items/${v}/versions?ids=${y?.datasetVersion??""},${b?.datasetVersion??""}`)},m=(v,y)=>{r(`/datasets/${e}/versions?ids=${v},${y}`,{replace:!0})};return o.jsx(ls,{children:o.jsx("div",{className:"h-full overflow-hidden px-[3vw] pb-4",children:o.jsxs("div",{className:"grid gap-6 max-w-[140rem] mx-auto grid-rows-[auto_1fr] h-full",children:[o.jsxs(ua,{children:[o.jsxs(ua.Column,{children:[o.jsxs(ua.Title,{children:[o.jsx(lfn,{})," Compare Dataset Versions"]}),o.jsx(ua.Description,{children:o.jsxs(Al,{children:[o.jsx(p_,{})," Comparing ",n.length," versions of"," ",s?.name||e?.slice(0,8)]})})]}),o.jsx(ua.Column,{children:o.jsxs(de,{as:Ba,to:`/datasets/${e}`,children:[o.jsx(Nc,{}),"Back to Dataset"]})})]}),o.jsx(sy,{children:o.jsxs(Gr,{children:[o.jsx(tts,{datasetId:e,versionA:String(n[0]),versionB:String(n[1]),onVersionChange:m}),o.jsx(ats,{datasetId:e,versionA:n[0],versionB:n[1],allItems:d,itemsAMap:f,itemsBMap:p,onItemClick:h})]})})]})})})}function qve({children:e,className:t}){return o.jsx("div",{className:K("flex flex-wrap gap-8",t),children:e})}function wts(e){if(!e||e.length<2)return null;const t=[...e].sort((i,l)=>new Date(i.createdAt).getTime()-new Date(l.createdAt).getTime()),n=Math.floor(t.length/2),r=n,s=t.length-n;if(r===0)return null;const a=(s-r)/r*100;return{changePct:Math.round(a*10)/10,prevValue:String(r)}}function Sts({scorers:e,datasets:t,experiments:n,avgScore:r,prevAvgScore:s,totalNeedsReview:a,isLoadingScorers:i,isLoadingDatasets:l,isLoadingExperiments:c,isLoadingScores:u,isLoadingReview:d}){const f=e?Object.keys(e).length:void 0,p=t?.length,h=n?.length,m=r!=null&&s!=null&&s!==0?{changePct:Math.round((r-s)/s*100*10)/10,prevValue:String(s)}:null,v=wts(n);return o.jsxs(o.Fragment,{children:[o.jsxs(Kr,{children:[o.jsx(Kr.Label,{children:"Total Scorers"}),i?o.jsx(Kr.Loading,{}):f!=null?o.jsxs(o.Fragment,{children:[o.jsx(Kr.Value,{children:String(f)}),o.jsx(Kr.NoChange,{message:"Static count"})]}):o.jsx(Kr.NoData,{})]}),o.jsxs(Kr,{children:[o.jsx(Kr.Label,{children:"Total Datasets"}),l?o.jsx(Kr.Loading,{}):p!=null?o.jsxs(o.Fragment,{children:[o.jsx(Kr.Value,{children:String(p)}),o.jsx(Kr.NoChange,{message:"Static count"})]}):o.jsx(Kr.NoData,{})]}),o.jsxs(Kr,{children:[o.jsx(Kr.Label,{children:"Avg Score"}),u?o.jsx(Kr.Loading,{}):r!=null?o.jsxs(o.Fragment,{children:[o.jsx(Kr.Value,{children:String(r)}),m?o.jsx(Kr.Change,{changePct:m.changePct,prevValue:m.prevValue}):o.jsx(Kr.NoChange,{})]}):o.jsx(Kr.NoData,{})]}),o.jsxs(Kr,{children:[o.jsx(Kr.Label,{children:"Total Experiments"}),c?o.jsx(Kr.Loading,{}):h!=null?o.jsxs(o.Fragment,{children:[o.jsx(Kr.Value,{children:String(h)}),v?o.jsx(Kr.Change,{changePct:v.changePct,prevValue:v.prevValue}):o.jsx(Kr.NoChange,{})]}):o.jsx(Kr.NoData,{})]}),o.jsxs(Kr,{children:[o.jsx(Kr.Label,{children:"Needs Review"}),d?o.jsx(Kr.Loading,{}):a!=null?o.jsxs(o.Fragment,{children:[o.jsx(Kr.Value,{children:String(a)}),a>0?o.jsx(Kr.NoChange,{message:"items pending review"}):o.jsx(Kr.NoChange,{message:"All caught up"})]}):o.jsx(Kr.NoData,{})]})]})}const LQe="auto 1fr auto auto auto auto auto auto auto";function kts(e){return e?(typeof e=="string"?new Date(e):e).toLocaleDateString("en-US",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}):"—"}const Ots={completed:"success",running:"warning",failed:"error",pending:"neutral"};function _ts({experiments:e,datasets:t,reviewByExperiment:n,isLoading:r,search:s="",statusFilter:a="all",datasetFilter:i="all"}){const{paths:l,Link:c}=yn(),u=g.useMemo(()=>{const p=new Map;return t?.forEach(h=>p.set(h.id,h.name)),p},[t]),d=g.useMemo(()=>[...e].sort((p,h)=>{const m=p.createdAt?new Date(p.createdAt).getTime():0;return(h.createdAt?new Date(h.createdAt).getTime():0)-m}),[e]),f=g.useMemo(()=>{const p=s.toLowerCase();return d.filter(h=>{const m=h.datasetId?u.get(h.datasetId)??"":"",v=!p||h.id.toLowerCase().includes(p)||m.toLowerCase().includes(p)||(h.targetId??"").toLowerCase().includes(p),y=a==="all"||h.status===a,b=i==="all"||h.datasetId===i;return v&&y&&b})},[d,s,u,a,i]);return r?o.jsx(tl,{columns:LQe}):o.jsxs(me,{columns:LQe,variant:"striped",children:[o.jsxs(me.Top,{children:[o.jsx(me.TopCell,{children:"Experiment"}),o.jsx(me.TopCell,{children:"Dataset"}),o.jsx(me.TopCell,{children:"Target"}),o.jsx(me.TopCell,{children:"Status"}),o.jsx(me.TopCell,{className:"text-center",children:"Items"}),o.jsx(me.TopCell,{className:"text-center",children:"Succeeded"}),o.jsx(me.TopCell,{className:"text-center",children:"Failed"}),o.jsx(me.TopCell,{className:"text-center",children:"Review"}),o.jsx(me.TopCell,{children:"Date"})]}),f.map(p=>{const h=p.datasetId?u.get(p.datasetId)??p.datasetId.slice(0,8):"—",m=p.status??"pending",v=p.succeededCount??0,y=p.failedCount??0,b=p.totalItems??0,S=b>0?Math.round(v/b*100):0;return o.jsxs(me.RowLink,{to:l.experimentLink(p.id),LinkComponent:c,children:[o.jsx(me.NameCell,{className:"font-mono",children:p.id.slice(0,8)}),o.jsx(me.TextCell,{children:h}),o.jsx(me.Cell,{children:o.jsxs("span",{className:"truncate",children:[p.targetType," ",p.targetId]})}),o.jsx(me.Cell,{children:o.jsx(pg,{variant:Ots[m]??"neutral",withDot:!0,children:m})}),o.jsx(me.TextCell,{className:"text-center",children:b}),o.jsx(me.TextCell,{className:"text-center",children:o.jsxs("span",{className:v>0?"text-accent1":"",children:[v," (",S,"%)"]})}),o.jsx(me.TextCell,{className:"text-center",children:o.jsx("span",{className:y>0?"text-accent2":"",children:y})}),o.jsx(me.Cell,{className:"text-center",children:(()=>{const w=n?.get(p.id);if(!w)return o.jsx("span",{className:"text-neutral2",children:"—"});const k=w.needsReview+w.complete;return k===0?o.jsx("span",{className:"text-neutral2",children:"—"}):w.needsReview>0?o.jsxs(Xs,{size:"small",color:"yellow",children:[w.needsReview," pending"]}):o.jsxs(Xs,{size:"small",color:"green",children:[w.complete,"/",k," reviewed"]})})()}),o.jsx(me.TextCell,{children:kts(p.createdAt)})]},p.id)})]})}const Cts=[{value:"all",label:"All statuses"},{value:"completed",label:"Completed"},{value:"running",label:"Running"},{value:"failed",label:"Failed"},{value:"pending",label:"Pending"}];function Ets(e){return[{value:"all",label:"All datasets"},...(e??[]).map(t=>({value:t.id,label:t.name}))]}const aF={completed:"#22c55e",running:"#facc15",pending:"#fb923c",failed:"#f87171"},jts=[{label:"Completed",color:aF.completed},{label:"Running",color:aF.running},{label:"Pending",color:aF.pending},{label:"Failed",color:aF.failed}];function Tts({experiments:e,datasets:t,isLoading:n,isError:r}){const{data:s,maxVal:a}=g.useMemo(()=>{if(!e||e.length===0)return{data:[],maxVal:0};const l=new Map;if(t)for(const f of t)l.set(f.id,f.name);const c=new Map;for(const f of e){const p=f.datasetId??"unknown";c.has(p)||c.set(p,{completed:0,running:0,pending:0,failed:0});const h=c.get(p),m=f.status;m in h&&h[m]++}let u=0;return{data:Array.from(c.entries()).map(([f,p])=>{const h=p.completed+p.running+p.pending+p.failed;return h>u&&(u=h),{name:l.get(f)??f.slice(0,12),values:[p.completed,p.running,p.pending,p.failed]}}),maxVal:u}},[e,t]),i=s.length>0;return o.jsxs(Ut,{children:[o.jsxs(Ut.TopBar,{children:[o.jsx(Ut.TitleAndDescription,{title:"Experiments by Dataset",description:"Experiment status breakdown per dataset."}),i&&o.jsx(Ut.Summary,{value:String(e?.length??0),label:"Total experiments"})]}),n?o.jsx(Ut.Loading,{}):r?o.jsx(Ut.Error,{message:"Failed to load experiments data"}):o.jsx(Ut.Content,{children:i?o.jsx(uN,{data:s,segments:jts,maxVal:a,fmt:l=>String(l)}):o.jsx(Ut.NoData,{message:"No experiments have been run yet"})})]})}const Nts=()=>o.jsx("div",{className:"flex h-full items-center justify-center",children:o.jsx(Cr,{iconSlot:o.jsx(Of,{}),titleSlot:"No Experiments yet",descriptionSlot:o.jsxs(o.Fragment,{children:["Run an experiment from a dataset to evaluate ",o.jsx("br",{}),"your agents and workflows."]}),actionSlot:o.jsx("div",{className:"flex flex-col items-center gap-2",children:o.jsxs(de,{variant:"ghost",as:"a",href:"https://mastra.ai/en/docs/evals/datasets/running-experiments",target:"_blank",rel:"noopener noreferrer",children:["Experiments Documentation ",o.jsx(_a,{})]})})})});function Its({search:e,onSearchChange:t,statusFilter:n,onStatusFilterChange:r,datasetFilter:s,onDatasetFilterChange:a,datasetOptions:i,onReset:l,hasActiveFilters:c}){return o.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[o.jsx(jf,{label:"Search experiments",placeholder:"Filter by experiment, dataset, or target",value:e,onSearch:t}),o.jsxs(Mr,{children:[o.jsx(Sc,{label:"Status",labelIsHidden:!0,name:"filter-status",options:[...Cts],value:n,onValueChange:r,className:"whitespace-nowrap"}),o.jsx(Sc,{label:"Dataset",labelIsHidden:!0,name:"filter-dataset",options:i,value:s,onValueChange:a,className:"whitespace-nowrap"}),l&&c&&o.jsxs(de,{onClick:l,size:"sm",variant:"default",children:[o.jsx(vs,{className:"size-3"})," Reset"]})]})]})}function Ats(){const{data:e,isLoading:t,error:n}=ih(),{data:r,isLoading:s,error:a}=$g(),{data:i,isLoading:l,error:c}=JZ(),{data:u,isLoading:d,isError:f,error:p}=UWr(),{data:h,isLoading:m,isError:v,error:y}=OTe(),b=r?.datasets,S=i?.experiments,w=g.useMemo(()=>cts(h),[h]),k=n||a||c||p||y;return k&&gs(k)?o.jsx(lr,{children:o.jsx(Vs,{})}):k&&ys(k)?o.jsx(lr,{children:o.jsx(Ds,{resource:"evaluation"})}):k?o.jsx(lr,{children:o.jsx(zi,{title:"Failed to load evaluation data",message:k.message})}):o.jsx(Lt,{width:"wide",height:"full",children:o.jsxs("div",{className:"flex flex-col gap-6",children:[o.jsx(qve,{children:o.jsx(Sts,{scorers:e,datasets:b,experiments:S,avgScore:u?.avgScore??null,prevAvgScore:u?.prevAvgScore??null,totalNeedsReview:w.needsReview,isLoadingScorers:t,isLoadingDatasets:s,isLoadingExperiments:l,isLoadingScores:d,isLoadingReview:m})}),o.jsx(eWr,{summaryData:u?.summaryData??[],overTimeData:u?.overTimeData??[],scorerNames:u?.scorerNames??[],avgScore:u?.avgScore??null,isLoading:d,isError:f}),o.jsxs("div",{className:"grid grid-cols-1 gap-6 lg:grid-cols-2",children:[o.jsx(uJr,{experiments:S,isLoading:l,isError:!!c}),o.jsx(Tts,{experiments:S,datasets:b,isLoading:l,isError:!!c})]}),o.jsx(ots,{reviewSummary:h,experiments:S,datasets:b,isLoading:m,isError:!!v})]})})}function Rts(){const[e,t]=g.useState(""),[n,r]=g.useState("all"),[s,a]=g.useState("all"),{data:i,isLoading:l,error:c}=$g(),{data:u,isLoading:d,error:f}=JZ(),{data:p}=OTe(),h=g.useMemo(()=>i?.datasets??[],[i?.datasets]),m=g.useMemo(()=>u?.experiments??[],[u?.experiments]),v=g.useMemo(()=>Ets(h),[h]),y=g.useMemo(()=>P9t(p),[p]),b=l||d,S=f||c;if(S&&gs(S))return o.jsx(lr,{children:o.jsx(Vs,{})});if(f&&ys(f))return o.jsx(lr,{children:o.jsx(Ds,{resource:"experiments"})});if(c&&ys(c))return o.jsx(lr,{children:o.jsx(Ds,{resource:"datasets"})});if(S)return o.jsx(lr,{children:o.jsx(zi,{title:"Failed to load experiments",message:S.message})});if(m.length===0&&!b)return o.jsx(lr,{children:o.jsx(Nts,{})});const w=n!=="all"||s!=="all"||e!=="",k=()=>{t(""),r("all"),a("all")};return o.jsxs(Lt,{children:[o.jsx(Lt.TopArea,{children:o.jsx(Its,{search:e,onSearchChange:t,statusFilter:n,onStatusFilterChange:r,datasetFilter:s,onDatasetFilterChange:a,datasetOptions:v,onReset:k,hasActiveFilters:w})}),o.jsx(_ts,{experiments:m,datasets:h,reviewByExperiment:y,isLoading:b,search:e,statusFilter:n,datasetFilter:s})]})}function iF({children:e}){return o.jsxs(Lt,{height:"full",children:[o.jsx("div",{}),o.jsx(Lt.MainArea,{isCentered:!0,children:e})]})}function Pts(){const{experimentId:e}=ur(),{data:t,isLoading:n}=JZ(),s=t?.experiments?.find(h=>h.id===e)?.datasetId??"",{data:a,isLoading:i,error:l}=zU(s,e??""),{data:c,isLoading:u,setEndOfListElement:d,isFetchingNextPage:f,hasNextPage:p}=YZ({datasetId:s,experimentId:e??"",experimentStatus:a?.status});return!e||n||i?null:l&&gs(l)?o.jsx(iF,{children:o.jsx(Vs,{})}):l&&ys(l)?o.jsx(iF,{children:o.jsx(Ds,{resource:"datasets"})}):l&&vOe(l)||!n&&!s||!i&&!l&&!a?o.jsx(iF,{children:o.jsx(Cr,{iconSlot:o.jsx(tbe,{}),titleSlot:"Experiment not found",descriptionSlot:`No experiment with id "${e}".`,actionSlot:o.jsxs(de,{as:Ba,to:"/experiments",children:[o.jsx(Nc,{}),"Back to Experiments"]})})}):l?o.jsx(iF,{children:o.jsx(zi,{title:"Failed to load experiment",message:l instanceof Error?l.message:"An unexpected error occurred. Please try again."})}):o.jsxs(Lt,{height:"full",children:[o.jsx($9t,{experiment:a}),o.jsx(Lt.MainArea,{children:o.jsx(R9t,{experimentId:e,datasetId:s,experimentStatus:a.status,results:c??[],isLoading:u,setEndOfListElement:d,isFetchingNextPage:f,hasNextPage:p})})]})}function $ts({connection:e,isAdmin:t,disconnectPending:n,onDisconnect:r}){return o.jsxs("li",{className:"flex items-center justify-between border-b py-2",children:[o.jsxs("div",{children:[o.jsx("div",{className:"font-mono text-xs",children:e.connectionId}),o.jsxs("div",{className:"text-xs text-gray-500",children:[e.label??"(no label)"," · ",e.status,e.scope?` · ${e.scope}`:"",t&&e.authorId?` · author: ${e.authorId}`:""]})]}),o.jsx("button",{type:"button",className:"text-red-600 underline disabled:opacity-50",onClick:r,disabled:n,children:"Disconnect"})]})}function M9t({connections:e,isAdmin:t,disconnectPending:n,onDisconnect:r}){return o.jsx("ul",{className:"space-y-1",children:e.map(s=>o.jsx($ts,{connection:s,isAdmin:t,disconnectPending:n,onDisconnect:()=>r(s.connectionId)},s.connectionId))})}function Mts({groups:e,isAdmin:t,disconnectPending:n,onDisconnect:r}){return o.jsx("div",{className:"space-y-4",children:e.map(([s,a])=>o.jsxs("div",{children:[o.jsx("h3",{className:"text-sm font-semibold text-gray-700","data-testid":`integration-author-group-${s}`,children:s==="shared"?"Shared":`Owned by ${s}`}),o.jsx(M9t,{connections:a,isAdmin:t,disconnectPending:n,onDisconnect:r})]},s))})}function Dts({providerId:e,toolkit:t,connections:n,groupedByAuthor:r,isAdmin:s,isLoading:a,error:i,disconnectPending:l,disconnectError:c,onDisconnect:u}){return o.jsxs("div",{className:"space-y-2 border rounded p-4",children:[o.jsx("h2",{className:"text-lg font-semibold",children:"Existing connections"}),!e||!t?o.jsx("p",{className:"text-gray-500",children:"Pick a provider and toolkit to list connections."}):a?o.jsx("p",{className:"text-gray-500",children:"Loading…"}):i?o.jsx("p",{className:"text-red-600",children:String(i)}):n.length===0?o.jsx("p",{className:"text-gray-500",children:"No connections."}):r?o.jsx(Mts,{groups:r,isAdmin:s,disconnectPending:l,onDisconnect:u}):o.jsx(M9t,{connections:n,isAdmin:s,disconnectPending:l,onDisconnect:u}),c?o.jsx("p",{className:"text-red-600",children:String(c)}):null]})}function Lts({providers:e,toolkits:t,providerId:n,toolkit:r,label:s,providersLoading:a,providersError:i,toolkitsLoading:l,toolkitsError:c,authorizePending:u,authorizeError:d,authorizedConnection:f,onProviderChange:p,onToolkitChange:h,onLabelChange:m,onConnect:v}){return o.jsxs("div",{className:"space-y-4 border rounded p-4",children:[o.jsxs("div",{className:"space-y-1",children:[o.jsx("label",{className:"block font-medium",htmlFor:"provider-select",children:"Provider"}),o.jsxs("select",{id:"provider-select",className:"border rounded px-2 py-1 w-full",value:n,onChange:y=>p(y.target.value),disabled:a,children:[o.jsx("option",{value:"",children:"— select provider —"}),e.map(y=>o.jsxs("option",{value:y.id,children:[y.displayName??y.name," (",y.id,")"]},y.id))]}),a&&o.jsx("span",{className:"text-gray-500",children:"Loading providers…"}),i?o.jsx("span",{className:"text-red-600",children:String(i)}):null]}),o.jsxs("div",{className:"space-y-1",children:[o.jsx("label",{className:"block font-medium",htmlFor:"toolkit-select",children:"Toolkit"}),o.jsxs("select",{id:"toolkit-select",className:"border rounded px-2 py-1 w-full",value:r,onChange:y=>h(y.target.value),disabled:!n||l,children:[o.jsx("option",{value:"",children:"— select toolkit —"}),t.map(y=>o.jsxs("option",{value:y.slug,children:[y.name," (",y.slug,")"]},y.slug))]}),l&&o.jsx("span",{className:"text-gray-500",children:"Loading toolkits…"}),c?o.jsx("span",{className:"text-red-600",children:String(c)}):null]}),o.jsxs("div",{className:"space-y-1",children:[o.jsx("label",{className:"block font-medium",htmlFor:"label-input",children:"Label (optional)"}),o.jsx("input",{id:"label-input",type:"text",className:"border rounded px-2 py-1 w-full",placeholder:"My personal Gmail",value:s,onChange:y=>m(y.target.value),disabled:!n||!r})]}),o.jsx("button",{type:"button",className:"bg-blue-600 text-white rounded px-4 py-2 disabled:opacity-50",onClick:v,disabled:!n||!r||u,children:u?"Authorizing…":"Connect"}),d?o.jsx("p",{className:"text-red-600",children:String(d)}):null,f&&o.jsxs("p",{className:"text-green-700",children:["Authorized: ",f.connectionId," (status: ",f.status,")"]})]})}const FQe=e=>e.authorId?.trim()||"shared",Fts=(e,t)=>{if(!t||new Set(e.map(FQe)).size<=1)return null;const r=new Map;for(const a of e){const i=FQe(a);r.set(i,[...r.get(i)??[],a])}const s=Array.from(r.entries());return s.sort(([a],[i])=>a==="shared"?1:i==="shared"?-1:a.localeCompare(i)),s},zts=["*","tool-providers:*","tool-providers:admin"];function Bts(){const{data:e}=Sm();return e?.permissions?.some(t=>zts.includes(t))??!1}function Uts(){const[e,t]=g.useState(""),[n,r]=g.useState(""),[s,a]=g.useState(""),i=dI(),l=cW(e||null),c=XIt(e||null,n||null),u=YIt(),d=ZIt(),f=Bts(),p=i.data?.providers??[],h=l.data?.data??[],m=g.useMemo(()=>c.data?.items??[],[c.data?.items]),v=g.useMemo(()=>Fts(m,f),[m,f]),y=w=>{t(w),r("")},b=()=>{!e||!n||u.mutate({providerId:e,toolkit:n,label:s.trim()||null},{onSuccess:()=>{a(""),c.refetch()}})},S=w=>{d.mutate({providerId:e,connectionId:w})};return o.jsxs("div",{className:"p-6 max-w-3xl space-y-6 text-sm",children:[o.jsx("h1",{className:"text-2xl font-semibold",children:"Integrations"}),o.jsx("p",{className:"text-gray-500",children:"Minimal page to verify the ToolProvider backend. Pick a provider and toolkit, then connect."}),o.jsx(Lts,{providers:p,toolkits:h,providerId:e,toolkit:n,label:s,providersLoading:i.isLoading,providersError:i.error,toolkitsLoading:l.isLoading,toolkitsError:l.error,authorizePending:u.isPending,authorizeError:u.error,authorizedConnection:u.data,onProviderChange:y,onToolkitChange:r,onLabelChange:a,onConnect:b}),o.jsx(Dts,{providerId:e,toolkit:n,connections:m,groupedByAuthor:v,isAdmin:f,isLoading:c.isLoading,error:c.error,disconnectPending:d.isPending,disconnectError:d.error,onDisconnect:S})]})}function qts({title:e,description:t,errorBanner:n,children:r}){return o.jsx("div",{"data-testid":"login-page",className:"flex min-h-screen items-center justify-center bg-surface1",children:o.jsxs("div",{className:"w-full max-w-sm space-y-6",children:[o.jsxs("div",{className:"flex flex-col items-center space-y-2",children:[o.jsx(Qh,{className:"h-10 w-10"}),o.jsx("h1",{className:"text-xl font-semibold text-neutral6",children:e})]}),t,n,r]})})}function D9t({redirectUri:e,onSuccess:t,initialMode:n="signin",errorMessage:r}){const{data:s,isLoading:a}=ac(),{mutate:i,isPending:l,error:c}=u1r(),{mutate:u,isPending:d,error:f}=f1r(),{mutate:p,isPending:h}=xNt(),[m,v]=g.useState(n),[y,b]=g.useState(""),[S,w]=g.useState(""),[k,_]=g.useState("");if(a)return o.jsx("div",{className:"flex min-h-screen items-center justify-center bg-surface1",children:o.jsx("div",{className:"text-neutral3",children:"Loading..."})});if(!s?.enabled||!s?.login)return o.jsx("div",{className:"flex min-h-screen items-center justify-center bg-surface1",children:o.jsx("div",{className:"text-neutral3",children:"Authentication is not configured"})});const{login:C}=s,E=C.type==="sso"||C.type==="both",j=C.type==="credentials"||C.type==="both",N=C.sso,I=C.signUpEnabled!==!1,R=m==="signin"||!I,P=R?l:d,L=R?c:f,M=()=>{t?t():e?window.location.href=e:window.location.href="/"},q=D=>{D.preventDefault(),R?i({email:S,password:k},{onSuccess:M}):u({email:S,password:k,name:y||void 0},{onSuccess:M})},H=()=>{p({redirectUri:e},{onSuccess:D=>{window.location.href=D.url}})},F=()=>{v(R?"signup":"signin")},z=C.description?o.jsxs("div",{className:"flex items-start gap-2.5 rounded-md border border-border1 bg-surface1 p-3",children:[o.jsx(yf,{className:"mt-0.5 h-4 w-4 shrink-0 text-neutral4"}),o.jsx("p",{className:"text-sm text-neutral3",children:C.description})]}):null,B=r?o.jsx("div",{className:"rounded-md bg-red-500/10 p-3 text-sm text-red-400",children:r}):null;return o.jsxs(qts,{title:R?"Sign in to Mastra Studio":"Create your account",description:z,errorBanner:B,children:[j&&o.jsxs("form",{onSubmit:q,className:"space-y-4",children:[!R&&o.jsxs("div",{className:"space-y-2",children:[o.jsx("label",{htmlFor:"name",className:"block text-sm text-neutral4",children:"Name"}),o.jsx(kn,{id:"name",type:"text",value:y,onChange:D=>b(D.target.value),placeholder:"Your name",variant:"default",size:"lg"})]}),o.jsxs("div",{className:"space-y-2",children:[o.jsx("label",{htmlFor:"email",className:"block text-sm text-neutral4",children:"Email"}),o.jsx(kn,{id:"email",type:"email",value:S,onChange:D=>w(D.target.value),placeholder:"you@example.com",required:!0,variant:"default",size:"lg"})]}),o.jsxs("div",{className:"space-y-2",children:[o.jsx("label",{htmlFor:"password",className:"block text-sm text-neutral4",children:"Password"}),o.jsx(kn,{id:"password",type:"password",value:k,onChange:D=>_(D.target.value),placeholder:R?"Enter your password":"Create a password",required:!0,variant:"default",size:"lg"})]}),L&&o.jsx("div",{className:"rounded-md bg-red-500/10 p-3 text-sm text-red-400",children:L.message}),o.jsx(de,{type:"submit",disabled:P,className:"w-full",size:"lg",children:P?R?"Signing in...":"Creating account...":R?"Sign in":"Create account"}),I&&o.jsxs("div",{className:"text-center text-sm",children:[o.jsx("span",{className:"text-neutral3",children:R?"Don't have an account? ":"Already have an account? "}),o.jsx("button",{type:"button",onClick:F,className:"text-neutral6 hover:underline",children:R?"Sign up":"Sign in"})]})]}),E&&j&&o.jsxs("div",{className:"relative",children:[o.jsx("div",{className:"absolute inset-0 flex items-center",children:o.jsx("div",{className:"w-full border-t border-border1"})}),o.jsx("div",{className:"relative flex justify-center text-sm",children:o.jsx("span",{className:"bg-surface1 px-2 text-neutral3",children:"or continue with"})})]}),E&&N&&o.jsxs(de,{onClick:H,disabled:h,className:"w-full",size:"lg",variant:"outline",children:[N.icon&&o.jsx("span",{className:"mr-2",children:N.icon}),h?"Redirecting...":N.text||"Sign in"]})]})}function Vts(){const[e]=ga(),t=bs(),n=e.get("redirect")||"/",s=e.get("mode")==="signup"?"signup":"signin",a=e.get("error_description")||e.get("error")||null,i=()=>{n.startsWith("http")?window.location.href=n:t(n,{replace:!0})};return o.jsx(D9t,{redirectUri:n,onSuccess:i,initialMode:s,errorMessage:a})}const Kf=Mi.KeyValueList;function Hts(e){return e instanceof Date?e:new Date(e)}function Wts({log:e,onClose:t,onTraceClick:n,onSpanClick:r,onPrevious:s,onNext:a,collapsed:i,onCollapsedChange:l}){const[c,u]=g.useState(!1),d=i??c,f=l??u,p=Hts(e.timestamp),h=e.traceId,m=e.spanId;return o.jsxs(Mi,{collapsed:d,children:[o.jsxs(Mi.Header,{children:[o.jsxs(Mi.Heading,{children:["Log ",o.jsx("b",{children:er(p,"MMM dd, HH:mm:ss.SSS")})]}),o.jsxs(Mr,{className:"ml-auto shrink-0",children:[l&&o.jsx(de,{size:"md",tooltip:d?"Expand panel":"Collapse panel",onClick:()=>f(!d),children:d?o.jsx(Qq,{}):o.jsx(Mxe,{})}),o.jsxs(Mr,{spacing:"close",children:[o.jsx(de,{size:"md",tooltip:"Previous log",onClick:s,disabled:!s,children:o.jsx(Gq,{})}),o.jsx(de,{size:"md",tooltip:"Next log",onClick:a,disabled:!a,children:o.jsx(Wq,{})})]}),o.jsx(Mi.CloseButton,{onClick:t})]})]}),!d&&o.jsxs(Mi.Content,{children:[o.jsx("p",{className:"text-ui-md text-neutral4 font-mono wrap-break-word whitespace-pre-wrap",children:e.message}),(h||m)&&o.jsxs("div",{className:K("grid gap-2 my-8","[&>button]:justify-between [&>button]:overflow-hidden"),children:[h&&o.jsxs(Mr,{spacing:"close",className:"min-w-0 w-full",children:[o.jsxs(de,{size:"md",className:"min-w-0 flex-1 overflow-hidden",onClick:()=>n?.(h),children:[o.jsx($z,{}),o.jsx("span",{children:"Trace"}),o.jsxs("span",{className:" ml-auto text-ui-sm text-neutral2 min-w-0 truncate",children:["# ",h]})]}),o.jsx(Oa,{content:h,size:"md",tooltip:"Copy Trace ID to clipboard"})]}),m&&o.jsxs(Mr,{spacing:"close",className:"min-w-0 w-full",children:[o.jsxs(de,{size:"md",className:"min-w-0 flex-1 overflow-hidden",disabled:!h||!r,onClick:()=>h&&r?.(h,m),children:[o.jsx($z,{}),o.jsx("span",{children:"Span"}),o.jsxs("span",{className:" ml-auto text-ui-sm text-neutral2 min-w-0 truncate",children:["# ",m]})]}),o.jsx(Oa,{content:m,size:"md",tooltip:"Copy Span ID to clipboard"})]})]}),o.jsxs(Kf,{className:"mb-6",children:[e.entityType&&o.jsxs(o.Fragment,{children:[o.jsx(Kf.Key,{children:"Entity Type"}),o.jsx(Kf.Value,{children:e.entityType})]}),e.entityName&&o.jsxs(o.Fragment,{children:[o.jsx(Kf.Key,{children:"Entity Name"}),o.jsx(Kf.Value,{children:e.entityName})]}),e.serviceName&&o.jsxs(o.Fragment,{children:[o.jsx(Kf.Key,{children:"Service"}),o.jsx(Kf.Value,{children:e.serviceName})]}),e.environment&&o.jsxs(o.Fragment,{children:[o.jsx(Kf.Key,{children:"Environment"}),o.jsx(Kf.Value,{children:e.environment})]}),e.source&&o.jsxs(o.Fragment,{children:[o.jsx(Kf.Key,{children:"Source"}),o.jsx(Kf.Value,{children:e.source})]}),e.metadata&&Object.keys(e.metadata).length>0&&o.jsx(o.Fragment,{children:Object.entries(e.metadata).map(([v,y])=>o.jsxs(g.Fragment,{children:[o.jsx(Kf.Key,{children:v}),o.jsx(Kf.Value,{children:String(y)})]},v))})]}),e.data&&Object.keys(e.data).length>0&&o.jsx(Mi.CodeSection,{title:"Data",codeStr:JSON.stringify(e.data,null,2),className:"mt-6"})]})]})}function Zts({error:e,resource:t,errorTitle:n}){if(gs(e))return o.jsx(Vs,{});if(ys(e))return o.jsx(Ds,{resource:t});if(hTt(e,"logs"))return o.jsx(Cr,{iconSlot:o.jsx(Yq,{}),titleSlot:"Logs are not available with your current storage",descriptionSlot:"The configured observability storage provider does not support listing logs. Switch to a storage provider with logs support to view runtime logs in Studio."});const r=e instanceof Error?e.message:void 0;return o.jsx(zi,{title:n,message:r??"Unknown error"})}function Gts({listSlot:e,logPanelSlot:t,tracePanelSlot:n,spanPanelSlot:r,logCollapsed:s}){const a=!!t;return o.jsxs("div",{className:K("grid h-full min-h-0 gap-4 items-start",a?"grid-cols-[1fr_1fr]":"grid-cols-[1fr]"),children:[e,a&&o.jsxs("div",{className:K("grid gap-4 h-full overflow-auto",n&&r?s?"grid-rows-[auto_1fr_1fr]":"grid-rows-[1fr_1fr_1fr]":n?s?"grid-rows-[auto_1fr]":"grid-rows-[1fr_1fr]":s?"grid-rows-[auto]":"grid-rows-[1fr]"),children:[t,n,r]})]})}const Qts={debug:{label:"DEBUG",color:"#71717a"},info:{label:"INFO",color:"#60a5fa"},warn:{label:"WARN",color:"#facc15"},error:{label:"ERROR",color:"#f87171"},fatal:{label:"FATAL",color:"#dc2626"}};function Yts({level:e}){const t=Qts[e];return o.jsx(ko,{height:"compact",children:o.jsx("span",{className:"uppercase text-ui-sm font-semibold",style:{color:t.color},children:t.label})})}function Xts({entityType:e,className:t}){const n=K("size-3.5 shrink-0 text-neutral2",t);switch(e.toLowerCase()){case Os.AGENT:return o.jsx(sl,{className:n,"aria-hidden":!0});case"workflow":case Os.WORKFLOW_RUN:return o.jsx(jd,{className:n,"aria-hidden":!0});case Os.TOOL:return o.jsx(eh,{className:n,"aria-hidden":!0});default:return null}}function Kts({entityType:e,entityName:t}){const n=e??"";return o.jsxs(ko,{height:"compact",className:"flex min-w-0 items-center gap-2",children:[o.jsx(Xts,{entityType:n}),t?o.jsx("span",{className:"min-w-0 text-ui-smd truncate",children:t}):"-"]})}function Jts({message:e}){return o.jsx(ko,{height:"compact",className:"text-neutral4 text-ui-smd min-w-0 truncate font-mono",children:e})}function ens({data:e}){if(!e||Object.keys(e).length===0)return o.jsx(ko,{height:"compact",children:null});const t=Object.entries(e).map(([n,r])=>{if(typeof r=="string")return`${n}: ${r}`;try{return`${n}: ${JSON.stringify(r)}`}catch{return`${n}: <unserializable>`}}).join(", ");return o.jsx(X1e,{children:t})}const Ul=Object.assign(k3,{Top:tH,TopCell:$_,TopCellWithTooltip:nH,TopCellSmart:G1t,RowWrapper:nSe,RowButton:O3,RowLink:Q1t,Spacer:tSe,NoMatch:eH,DateCell:K1e,TimeCell:J1e,LevelCell:Yts,EntityCell:Kts,MessageCell:Jts,DataCell:ens,NextPageLoading:JV}),zQe="6rem 9rem 5rem 10rem minmax(8rem,1fr) minmax(8rem,1fr)",tns=36,nns=8;function rns({logs:e,isLoading:t,isFetchingNextPage:n,hasNextPage:r,setEndOfListElement:s,logIdMap:a,featuredLogId:i,onLogClick:l}){const c=g.useRef(null),u=y9t({count:e.length,getScrollElement:()=>c.current,estimateSize:()=>tns,overscan:nns}),d=g.useRef(t);if(g.useEffect(()=>{d.current&&!t&&c.current?.dispatchEvent(new Event("scroll")),d.current=t},[t]),t)return o.jsx(tl,{columns:zQe});const f=u.getVirtualItems(),p=u.getTotalSize(),h=f[0]?.start??0,m=f.length>0?Math.max(0,p-(f[f.length-1]?.end??0)):0;return o.jsxs(Ul,{columns:zQe,variant:"striped",scrollRef:c,className:"min-w-0",children:[o.jsxs(Ul.Top,{children:[o.jsx(Ul.TopCell,{children:"Date"}),o.jsx(Ul.TopCell,{children:"Time"}),o.jsx(Ul.TopCell,{children:"Level"}),o.jsx(Ul.TopCell,{children:"Entity"}),o.jsx(Ul.TopCell,{children:"Message"}),o.jsx(Ul.TopCell,{children:"Data"})]}),e.length===0?o.jsx(Ul.NoMatch,{message:"No logs match your search"}):o.jsxs(o.Fragment,{children:[o.jsx(Ul.Spacer,{height:h}),f.map(v=>{const y=e[v.index];if(!y)return null;const b=a.get(y);if(!b)return null;const S=b===i;return o.jsxs(Ul.RowButton,{ref:u.measureElement,"data-index":v.index,onClick:()=>l(y),featured:S,variant:y.level==="error"||y.level==="fatal"?"error":"default",children:[o.jsx(Ul.DateCell,{timestamp:y.timestamp}),o.jsx(Ul.TimeCell,{timestamp:y.timestamp}),o.jsx(Ul.LevelCell,{level:y.level}),o.jsx(Ul.EntityCell,{entityType:y.entityType,entityName:y.entityName}),o.jsx(Ul.MessageCell,{message:y.message}),o.jsx(Ul.DataCell,{data:y.data})]},b)}),o.jsx(Ul.Spacer,{height:m})]}),o.jsx(Ul.NextPageLoading,{isLoading:n,hasMore:r,setEndOfListElement:s})]})}function sns({onClear:e,onRemoveAll:t,onSave:n,onRemoveSaved:r,isLoading:s,filterFields:a,filterTokens:i,onFilterTokensChange:l,autoFocusFilterFieldId:c}){const u=i.length>0,d=i.some(f=>ans(f,a));return o.jsxs("div",{className:K("grid grid-cols-[1fr_auto] gap-3 items-start"),children:[o.jsx(lTe,{fields:a,tokens:i,onTokensChange:l,disabled:s,autoFocusFieldId:c}),u&&o.jsx(iTe,{disabled:s,onClear:d?e:void 0,onRemoveAll:t,onSave:n,onRemoveSaved:r})]})}function ans(e,t){const n=t.find(r=>r.id===e.fieldId);return n?n.kind==="text"?typeof e.value=="string"&&e.value.trim()!=="":n.kind==="pick-multi"?n.multi?Array.isArray(e.value)&&e.value.length>0:typeof e.value=="string"&&e.value!==""&&e.value!=="Any":n.kind==="multi-select"?Array.isArray(e.value)&&e.value.length>0:!1:!1}const ins={"last-24h":"the last 24 hours","last-3d":"the last 3 days","last-7d":"the last 7 days","last-14d":"the last 14 days","last-30d":"the last 30 days"},tse="MMM d, yyyy HH:mm",nse="Pick a wider range or lower the logging level — verbose entries (debug, info) may be filtered out.";function ons({datePreset:e,dateFrom:t,dateTo:n}){return e&&e!=="all"&&e!=="custom"?{title:`No logs for ${ins[e]}`,description:nse}:t&&n?{title:`No logs between ${er(t,tse)} and ${er(n,tse)}`,description:nse}:t?{title:`No logs since ${er(t,tse)}`,description:nse}:{title:"No logs yet",description:"Logs will appear here once agents, workflows, or tools are executed."}}const lns=({datePreset:e,dateFrom:t,dateTo:n}={})=>{const{title:r,description:s}=ons({datePreset:e,dateFrom:t,dateTo:n});return o.jsx("div",{className:"flex h-full items-center justify-center",children:o.jsx(Cr,{iconSlot:o.jsx(Yq,{}),titleSlot:r,descriptionSlot:s,actionSlot:o.jsxs(de,{variant:"ghost",as:"a",href:"https://mastra.ai/en/docs/observability/logging",target:"_blank",rel:"noopener noreferrer",children:["Logging Documentation ",o.jsx(Dxe,{})]})})})},cns=20,uns=1e4;function dns(e,t,n){if(e?.pagination?.hasMore)return n+1}function fns(e){const t=new Set,n=[];for(const r of e.pages)for(const s of r.logs??[]){const a=s.logId??JSON.stringify(s);t.has(a)||(t.add(a),n.push(s))}return n}function pns(e){return hTt(e.state.error,"logs")?!1:uns}const hns=({filters:e}={})=>{const t=We(),{inView:n,setRef:r}=A_(),s=$1({queryKey:["logs",e],queryFn:({pageParam:p})=>t.listLogsVNext({pagination:{page:p,perPage:cns},filters:e,orderBy:{field:"timestamp",direction:"DESC"}}),initialPageParam:0,getNextPageParam:dns,select:fns,retry:!1,refetchInterval:pns}),{hasNextPage:a,isFetchingNextPage:i,fetchNextPage:l,data:c,isLoading:u,isError:d,error:f}=s;return g.useEffect(()=>{n&&a&&!i&&l()},[n,a,i,l]),{data:c,hasNextPage:a,isFetchingNextPage:i,fetchNextPage:l,isLoading:u,isError:d,error:f,setEndOfListElement:r}},oF={AGENT:Os.AGENT,WORKFLOW:Os.WORKFLOW_RUN,SCORER:Os.SCORER,INGEST:Os.RAG_INGESTION},L9t=[{label:"Agent",entityType:oF.AGENT},{label:"Workflow",entityType:oF.WORKFLOW},{label:"Scorer",entityType:oF.SCORER},{label:"Ingest",entityType:oF.INGEST}],mns=[{label:"Debug",value:"debug"},{label:"Info",value:"info"},{label:"Warn",value:"warn"},{label:"Error",value:"error"},{label:"Fatal",value:"fatal"}],Dx="rootEntityType",qb="datePreset",Vb="dateFrom",Hb="dateTo",gns=new Set(["all","last-24h","last-3d","last-7d","last-14d","last-30d","custom"]),_l={level:"filterLevel",tags:"filterTags",entityName:"filterEntityName",traceId:"filterTraceId",spanId:"filterSpanId",runId:"filterRunId",threadId:"filterThreadId",sessionId:"filterSessionId",requestId:"filterRequestId",resourceId:"filterResourceId",userId:"filterUserId",organizationId:"filterOrganizationId",serviceName:"filterServiceName",environment:"filterEnvironment",experimentId:"filterExperimentId"},X4=Object.keys(_l),_Te=new Set(["tags"]),CTe="mastra:logs:saved-filters";function vns(e,t=CTe){const n=Sns(e),r=e.get(qb);r&&n.set(qb,r);const s=e.get(Vb);s&&n.set(Vb,s);const a=e.get(Hb);a&&n.set(Hb,a);try{localStorage.setItem(t,n.toString())}catch{}}function yns(e=CTe){try{localStorage.removeItem(e)}catch{}}function BQe(e=CTe){try{const t=localStorage.getItem(e);if(!t)return null;const n=new URLSearchParams(t);return n.toString()?n:null}catch{return null}}function bns(e){if(e.has(qb)||e.has(Vb)||e.has(Hb)||e.has(Dx))return!0;for(const t of X4)if(e.has(_l[t]))return!0;return!1}function xns({availableTags:e,availableRootEntityNames:t,availableServiceNames:n,availableEnvironments:r,loading:s}){const a=[{id:"rootEntityType",label:"Primitive Type",kind:"pick-multi",searchable:!1,options:L9t.map(u=>({label:u.label,value:u.entityType})),placeholder:"Choose entity type",emptyText:"No entity types."},{id:"entityName",label:"Primitive Name",kind:"pick-multi",options:t.map(u=>({label:u,value:u})),placeholder:"Choose entity names",emptyText:"No entity names found.",isLoading:s?.entityNames},{id:"level",label:"Level",kind:"pick-multi",searchable:!1,options:mns.map(u=>({label:u.label,value:u.value})),placeholder:"Choose level",emptyText:"No levels."},{id:"tags",label:"Tags",kind:"pick-multi",multi:!0,options:e.map(u=>({label:u,value:u})),placeholder:"Choose tags",emptyText:"No tags found.",isLoading:s?.tags},{id:"serviceName",label:"Service Name",kind:"pick-multi",options:n.map(u=>({label:u,value:u})),placeholder:"Choose service names",emptyText:"No service names found.",isLoading:s?.serviceNames},{id:"environment",label:"Environment",kind:"pick-multi",options:r.map(u=>({label:u,value:u})),placeholder:"Choose environments",emptyText:"No environments found.",isLoading:s?.environments},{id:"traceId",label:"Trace ID",kind:"text"},{id:"spanId",label:"Span ID",kind:"text"},{id:"runId",label:"Run ID",kind:"text"},{id:"threadId",label:"Thread ID",kind:"text"},{id:"sessionId",label:"Session ID",kind:"text"},{id:"requestId",label:"Request ID",kind:"text"},{id:"resourceId",label:"Resource ID",kind:"text"},{id:"userId",label:"User ID",kind:"text"},{id:"organizationId",label:"Organization ID",kind:"text"},{id:"experimentId",label:"Experiment ID",kind:"text"}],i=(u,d)=>u.label.localeCompare(d.label),l=a.filter(u=>u.kind==="pick-multi").sort(i),c=a.filter(u=>u.kind==="text").sort(i);return[...l,...c]}function wns(e){const t=[],n=new Map([[Dx,"rootEntityType"]]);for(const s of X4)n.set(_l[s],s);const r=new Set;for(const[s]of e.entries()){const a=n.get(s);if(!a||r.has(a))continue;if(r.add(a),_Te.has(a)){const l=e.getAll(s);if(l.length===0)continue;t.push({fieldId:a,value:l.filter(Boolean)});continue}const i=e.get(s);i!==null&&t.push({fieldId:a,value:i})}return t}function Sns(e){const t=new URLSearchParams,n=e.get(Dx);n&&t.set(Dx,n);for(const r of X4){const s=_l[r];if(_Te.has(r)){for(const i of e.getAll(s))t.append(s,i);continue}const a=e.get(s);a&&t.set(s,a)}return t}function kns(e,t){e.delete(Dx);for(const n of X4)e.delete(_l[n]);for(const n of t){if(n.fieldId==="rootEntityType"&&typeof n.value=="string"){e.set(Dx,n.value);continue}const r=_l[n.fieldId];if(r){if(_Te.has(n.fieldId)&&Array.isArray(n.value)){if(n.value.length===0)e.append(r,"");else for(const s of n.value)e.append(r,s);continue}typeof n.value=="string"&&e.set(r,n.value.trim())}}}function Ons({rootEntityType:e,dateFrom:t,dateTo:n,tokens:r}){const s={};e&&(s.rootEntityType=e),(t||n)&&(s.timestamp={...t?{start:t}:{},...n?{end:n}:{}});for(const a of r){if(a.fieldId==="tags"){Array.isArray(a.value)&&a.value.length>0?s.tags=a.value:typeof a.value=="string"&&a.value.trim()&&(s.tags=[a.value.trim()]);continue}if(a.fieldId==="level"){typeof a.value=="string"&&a.value.trim()&&a.value!=="Any"&&(s.level=a.value);continue}if(typeof a.value=="string"&&a.value.trim()&&a.value!=="Any")switch(a.fieldId){case"entityName":s.rootEntityName=a.value;break;case"traceId":s.traceId=a.value;break;case"spanId":s.spanId=a.value;break;case"runId":s.runId=a.value;break;case"threadId":s.threadId=a.value;break;case"sessionId":s.sessionId=a.value;break;case"requestId":s.requestId=a.value;break;case"resourceId":s.resourceId=a.value;break;case"userId":s.userId=a.value;break;case"organizationId":s.organizationId=a.value;break;case"serviceName":s.serviceName=a.value;break;case"environment":s.environment=a.value;break;case"experimentId":s.experimentId=a.value;break}}return s}function _ns(e,t){return t.map(n=>{const r=e.find(s=>s.id===n.fieldId);return r?r.kind==="text"?{fieldId:n.fieldId,value:""}:r.kind==="pick-multi"?r.multi?{fieldId:n.fieldId,value:[]}:{fieldId:n.fieldId,value:"Any"}:n:n})}const Cns="Filters setting for Logs saved",Ens="Filters setting for Logs cleared up";function jns(e,t,n){const{storageKey:r,messages:s,skipHydration:a}={},[i,l]=g.useState(()=>BQe(r)!==null),c=g.useCallback(()=>{vns(e,r),l(!0);const f=s?.saved??Cns;f!==!1&&De.success(f)},[e,r,s?.saved]),u=g.useCallback(()=>{yns(r),l(!1);const f=s?.cleared??Ens;f!==!1&&De.success(f)},[r,s?.cleared]),d=g.useRef(!1);return g.useEffect(()=>{if(a||d.current||(d.current=!0,bns(e)))return;const f=BQe(r);f&&t(p=>{const h=new URLSearchParams(p);for(const[m,v]of f)h.append(m,v);return h},{replace:!0})},[]),{hasSavedFilters:i,handleSave:c,handleRemoveSaved:u}}function Tns(e){let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n)|0;return(t>>>0).toString(36)}function Nns(e){const t=new Map;for(const n of e){if(n.logId){t.set(n,n.logId);continue}const r=n.timestamp instanceof Date?n.timestamp.toISOString():n.timestamp;t.set(n,Tns(`${r}${n.message??""}${n.data?JSON.stringify(n.data):""}`))}return t}function Ins(e,t,n,r){const s=g.useMemo(()=>Nns(e),[e]),a=g.useMemo(()=>{const h=new Map;for(let m=0;m<e.length;m++){const v=s.get(e[m]);v&&h.set(v,{log:e[m],idx:m})}return h},[e,s]),l=(t?a.get(t):void 0)?.idx??-1,c=l>=0?e[l]:null,u=g.useCallback(h=>s.get(h),[s]),d=g.useCallback(h=>{const m=s.get(h);if(m){if(t===m){n({logId:null});return}n(r?{logId:m,traceId:h.traceId??null,spanId:null}:{logId:m})}},[s,t,r,n]),f=l>0?()=>{const h=e[l-1],m=s.get(h);m&&n(r?{logId:m,traceId:h.traceId??null,spanId:null}:{logId:m})}:void 0,p=l>=0&&l<e.length-1?()=>{const h=e[l+1],m=s.get(h);m&&n(r?{logId:m,traceId:h.traceId??null,spanId:null}:{logId:m})}:void 0;return{logIdMap:s,getLogId:u,featuredLog:c,handleLogClick:d,handlePreviousLog:f,handleNextLog:p}}const Vve="logId",Hve="traceId",Wve="spanId",DR=1440*60*1e3,Ans={"last-24h":DR,"last-3d":3*DR,"last-7d":7*DR,"last-14d":14*DR,"last-30d":30*DR};function lF(e){e.delete(Vve),e.delete(Hve),e.delete(Wve)}function Rns(e,t,n){const{onRemoveAll:r}={},s=g.useMemo(()=>{const _=e.get(qb);return _&&gns.has(_)?_:"last-24h"},[e]),a=e.get(Vb),i=e.get(Hb),l=g.useMemo(()=>{if(s==="custom"){if(!a)return;const C=new Date(a);return Number.isNaN(C.getTime())?void 0:C}if(s==="all")return;const _=Ans[s];return _?new Date(Date.now()-_):void 0},[s,a]),c=g.useMemo(()=>{if(s!=="custom"||!i)return;const _=new Date(i);return Number.isNaN(_.getTime())?void 0:_},[s,i]),u=g.useRef(s);u.current=s;const d=e.get(Vve),f=e.get(Hve),p=e.get(Wve),h=g.useMemo(()=>L9t.find(_=>_.entityType===e.get(Dx)),[e]),m=g.useMemo(()=>wns(e),[e]),v=g.useCallback(_=>{t(C=>{const E=new URLSearchParams(C);for(const[j,N]of Object.entries(_)){const I=j==="logId"?Vve:j==="traceId"?Hve:Wve;N?E.set(I,N):E.delete(I)}return E},{replace:!0})},[t]),y=g.useCallback(_=>{t(C=>{const E=new URLSearchParams(C);return kns(E,_),lF(E),E},{replace:!0})},[t]),b=y,S=g.useCallback((_,C)=>{if(u.current!=="custom")return;const E=C==="from"?Vb:Hb;t(j=>{const N=new URLSearchParams(j);return _?N.set(E,_.toISOString()):N.delete(E),lF(N),N},{replace:!0})},[t]),w=g.useCallback(_=>{u.current=_,t(C=>{const E=new URLSearchParams(C);return _==="last-24h"?(E.delete(qb),E.delete(Vb),E.delete(Hb)):_==="custom"?E.set(qb,"custom"):(E.set(qb,_),E.delete(Vb),E.delete(Hb)),lF(E),E},{replace:!0})},[t]),k=g.useCallback(()=>{t(_=>{const C=new URLSearchParams(_);C.delete(Dx);for(const E of X4)C.delete(_l[E]);return C.delete(qb),C.delete(Vb),C.delete(Hb),lF(C),C},{replace:!0}),r?.()},[t,r]);return g.useMemo(()=>({searchParams:e,setSearchParams:t,datePreset:s,selectedDateFrom:l,selectedDateTo:c,datePresetRef:u,featuredLogId:d,featuredTraceId:f,featuredSpanId:p,selectedEntityOption:h,filterTokens:m,handleFeaturedChange:v,handleFilterTokensChange:b,handleDateChange:S,handleDatePresetChange:w,handleRemoveAll:k,applyFilterTokens:y}),[e,t,s,l,c,u,d,f,p,h,m,v,b,S,w,k,y])}const wb=Mi.KeyValueList;function Pns({spanId:e,span:t,isLoading:n,onClose:r}){const s=t?.startedAt&&t?.endedAt?new Date(t.endedAt).getTime()-new Date(t.startedAt).getTime():null;return o.jsxs(Mi,{children:[o.jsxs(Mi.Header,{children:[o.jsxs(Mi.Heading,{children:["Span ",o.jsxs("b",{children:["# ",e]})]}),o.jsx(Mi.CloseButton,{onClick:r})]}),n?o.jsx(Mi.LoadingData,{children:"Loading span..."}):t?o.jsxs(Mi.Content,{children:[o.jsxs(wb,{children:[t.spanType&&o.jsxs(o.Fragment,{children:[o.jsx(wb.Key,{children:"Type"}),o.jsx(wb.Value,{children:t.spanType})]}),t.startedAt&&o.jsxs(o.Fragment,{children:[o.jsx(wb.Key,{children:"Started"}),o.jsx(wb.Value,{children:er(new Date(t.startedAt),"MMM dd, HH:mm:ss.SSS")})]}),t.endedAt&&o.jsxs(o.Fragment,{children:[o.jsx(wb.Key,{children:"Ended"}),o.jsx(wb.Value,{children:er(new Date(t.endedAt),"MMM dd, HH:mm:ss.SSS")})]}),s!=null&&o.jsxs(o.Fragment,{children:[o.jsx(wb.Key,{children:"Duration"}),o.jsx(wb.Value,{children:s<1e3?`${s}ms`:`${(s/1e3).toFixed(2)}s`})]})]}),o.jsx("br",{}),o.jsx(Mi.CodeSection,{title:"Input",icon:o.jsx(Dfe,{}),codeStr:JSON.stringify(t.input??null,null,2)}),o.jsx(Mi.CodeSection,{title:"Output",icon:o.jsx(Lfe,{}),codeStr:JSON.stringify(t.output??null,null,2)}),o.jsx(Mi.CodeSection,{title:"Metadata",icon:o.jsx(hw,{}),codeStr:JSON.stringify(t.metadata??null,null,2)}),o.jsx(Mi.CodeSection,{title:"Attributes",icon:o.jsx(hw,{}),codeStr:JSON.stringify(t.attributes??null,null,2)})]}):o.jsx(Mi.NoData,{children:"Span not found."})]})}function $ns(){const[e,t]=ga(),n=Rns(e,t),r=jns(e,t),[s,a]=g.useState(),[i,l]=g.useState(!1),{data:c=[],isPending:u}=gTe(),{data:d=[],isPending:f}=pTe({entityType:n.selectedEntityOption?.entityType,rootOnly:!0}),{data:p=[],isPending:h}=hTe(),{data:m=[],isPending:v}=mTe(),y=g.useMemo(()=>xns({availableTags:c,availableRootEntityNames:d,availableServiceNames:m,availableEnvironments:p,loading:{tags:u,entityNames:f,serviceNames:v,environments:h}}),[c,d,m,p,u,f,v,h]),b=g.useMemo(()=>Ons({rootEntityType:n.selectedEntityOption?.entityType,dateFrom:n.selectedDateFrom,dateTo:n.selectedDateTo,tokens:n.filterTokens}),[n.filterTokens,n.selectedDateFrom,n.selectedDateTo,n.selectedEntityOption]),{data:S=[],isLoading:w,error:k,isFetchingNextPage:_,hasNextPage:C,setEndOfListElement:E}=hns({filters:b}),{logIdMap:j,featuredLog:N,handleLogClick:I,handlePreviousLog:R,handleNextLog:P}=Ins(S,n.featuredLogId,n.handleFeaturedChange,n.featuredTraceId),{data:L,isLoading:M}=ZH(n.featuredTraceId??null),{data:q,isLoading:H}=oI(n.featuredTraceId??"",n.featuredSpanId??""),F=g.useCallback(()=>n.applyFilterTokens(_ns(y,n.filterTokens)),[y,n]),z=g.useCallback(()=>n.handleFeaturedChange({logId:null}),[n]),B=g.useCallback(X=>n.handleFeaturedChange({traceId:X,spanId:null}),[n]),D=g.useCallback((X,te)=>n.handleFeaturedChange({traceId:X,spanId:te}),[n]),Q=g.useCallback(()=>{n.handleFeaturedChange({traceId:null,spanId:null}),l(!1)},[n]),V=g.useCallback(()=>n.handleFeaturedChange({spanId:null}),[n]),$=g.useCallback(X=>n.handleFeaturedChange({spanId:X??null}),[n]),U=o.jsxs(Lt.TopArea,{children:[o.jsx(Lt.Row,{children:o.jsxs(Lt.Column,{className:"flex flex-wrap items-start justify-start gap-2",children:[o.jsx(aTe,{preset:n.datePreset,onPresetChange:n.handleDatePresetChange,dateFrom:n.selectedDateFrom,dateTo:n.selectedDateTo,onDateChange:n.handleDateChange,disabled:w,presets:["last-24h","last-3d","last-7d","last-14d","last-30d","custom"]}),o.jsx(cTe,{fields:y,tokens:n.filterTokens,onTokensChange:n.handleFilterTokensChange,disabled:w,onStartTextFilter:a})]})}),o.jsx(sns,{isLoading:w,filterFields:y,filterTokens:n.filterTokens,onFilterTokensChange:n.handleFilterTokensChange,onClear:F,onRemoveAll:n.handleRemoveAll,onSave:r.handleSave,onRemoveSaved:r.hasSavedFilters?r.handleRemoveSaved:void 0,autoFocusFilterFieldId:s})]});if(k)return o.jsxs(Lt,{width:"wide",height:"full",children:[U,o.jsx(Lt.MainArea,{isCentered:!0,children:o.jsx(Zts,{error:k,resource:"logs",errorTitle:"Failed to load logs"})})]});const Z=!!n.selectedEntityOption||n.filterTokens.length>0;return S.length===0&&!w&&!Z?o.jsxs(Lt,{width:"wide",height:"full",children:[U,o.jsx(Lt.MainArea,{isCentered:!0,children:o.jsx(lns,{datePreset:n.datePreset,dateFrom:n.selectedDateFrom,dateTo:n.selectedDateTo})})]}):o.jsxs(Lt,{width:"wide",height:"full",children:[U,o.jsx(Gts,{logCollapsed:i,listSlot:o.jsx(rns,{logs:S,isLoading:w,isFetchingNextPage:_,hasNextPage:C,setEndOfListElement:E,logIdMap:j,featuredLogId:n.featuredLogId,onLogClick:I}),logPanelSlot:N?o.jsx(Wts,{log:N,onClose:z,onTraceClick:B,onSpanClick:D,onPrevious:R,onNext:P,collapsed:i,onCollapsedChange:l}):null,tracePanelSlot:n.featuredTraceId?o.jsx($Et,{traceId:n.featuredTraceId,spans:L?.spans,isLoading:M,onClose:Q,onSpanSelect:$,selectedSpanId:n.featuredSpanId}):null,spanPanelSlot:n.featuredTraceId&&n.featuredSpanId?o.jsx(Pns,{spanId:n.featuredSpanId,span:q?.span,isLoading:H,onClose:V}):null})]})}function Mns({server:e}){const{paths:t,Link:n}=yn(),s=We().options.baseUrl,a=s?`${s}/api/mcp/${e.id}/sse`:"",{data:i}=M5t(e),l=Object.values(i||{}),c=l.length,u=l.filter(p=>p.toolType==="agent").length,d=l.filter(p=>p.toolType==="workflow").length,f=fm(e.name,50);return o.jsxs(me.RowLink,{to:t.mcpServerLink(e.id),LinkComponent:n,children:[o.jsx(me.NameCell,{children:f}),o.jsx(me.DescriptionCell,{children:a}),o.jsx(me.TextCell,{className:"text-center",children:u||""}),o.jsx(me.TextCell,{className:"text-center",children:c||""}),o.jsx(me.TextCell,{className:"text-center",children:d||""})]})}function Dns({mcpServers:e,isLoading:t,search:n=""}){const r=g.useMemo(()=>{const s=n.toLowerCase();return e.filter(a=>a.name?.toLowerCase().includes(s)||a.id?.toLowerCase().includes(s))},[e,n]);return t?o.jsx(tl,{columns:"auto 1fr auto auto auto"}):o.jsxs(me,{columns:"auto 1fr auto auto auto",variant:"striped",children:[o.jsxs(me.Top,{children:[o.jsx(me.TopCell,{children:"Name"}),o.jsx(me.TopCell,{children:"URL"}),o.jsx(me.TopCellSmart,{long:"Agents",short:o.jsx(sl,{}),tooltip:"Agent Tools",className:"text-center"}),o.jsx(me.TopCellSmart,{long:"Tools",short:o.jsx(eh,{}),tooltip:"Tools",className:"text-center"}),o.jsx(me.TopCellSmart,{long:"Workflows",short:o.jsx(jd,{}),tooltip:"Workflow Tools",className:"text-center"})]}),r.length===0&&n?o.jsx(me.NoMatch,{message:"No MCP Servers match your search"}):null,r.map(s=>o.jsx(Mns,{server:s},s.id))]})}const Lns=()=>o.jsx("div",{className:"flex h-full items-center justify-center",children:o.jsx(Cr,{iconSlot:o.jsx(Of,{}),titleSlot:"No MCP Servers yet",descriptionSlot:o.jsxs(o.Fragment,{children:["MCP servers are not configured yet. ",o.jsx("br",{}),"More information in the documentation."]}),actionSlot:o.jsxs(de,{variant:"ghost",as:"a",href:"https://mastra.ai/docs/tools-mcp/mcp-overview",target:"_blank",rel:"noopener noreferrer",children:["MCP Documentation ",o.jsx(_a,{})]})})}),Fns=()=>{const{data:e=[],isLoading:t,error:n}=MZ(),[r,s]=g.useState("");return n&&gs(n)?o.jsx(lr,{children:o.jsx(Vs,{})}):n&&ys(n)?o.jsx(lr,{children:o.jsx(Ds,{resource:"MCP servers"})}):n?o.jsx(lr,{children:o.jsx(zi,{title:"Failed to load MCP servers",message:n.message})}):e.length===0&&!t?o.jsx(lr,{children:o.jsx(Lns,{})}):o.jsxs(Lt,{children:[o.jsx(Lt.TopArea,{children:o.jsx("div",{className:"max-w-120",children:o.jsx(jf,{onSearch:s,label:"Filter MCP servers",placeholder:"Filter by name"})})}),o.jsx(Dns,{mcpServers:e,isLoading:t,search:r})]})},zns=(e,t)=>{const n=new Map,r=Object.keys(t);for(const s of r){const a=t[s],i=a.tools,l=Object.keys(i);for(const c of l){const u=i[c];n.has(u.id)||n.set(u.id,{...u,agents:[]}),n.get(u.id).agents.push({...a,id:s})}}for(const[s,a]of Object.entries(e))n.has(a.id)||n.set(a.id,{...a,agents:[]});return Array.from(n.values())};function Bns({tools:e,agents:t,isLoading:n,search:r=""}){const{paths:s,Link:a}=yn(),i=g.useMemo(()=>zns(e,t),[e,t]),l=g.useMemo(()=>i.filter(c=>c.id.toLowerCase().includes(r.toLowerCase())),[i,r]);return n?o.jsx(tl,{columns:"auto 1fr auto"}):o.jsxs(me,{columns:"auto 1fr auto",variant:"striped",children:[o.jsxs(me.Top,{children:[o.jsx(me.TopCell,{children:"Name"}),o.jsx(me.TopCell,{children:"Description"}),o.jsx(me.TopCellSmart,{long:"Agents",short:o.jsx(sl,{}),tooltip:"Attached Agents",className:"text-center"})]}),l.length===0&&r?o.jsx(me.NoMatch,{message:"No Tools match your search"}):null,l.map(c=>{const u=fm(c.id,50),d=fm(c.description??"",200),f=c.agents.length;return o.jsxs(me.RowLink,{to:s.toolLink(c.id),LinkComponent:a,children:[o.jsx(me.NameCell,{children:u}),o.jsx(me.DescriptionCell,{children:d}),o.jsx(me.TextCell,{className:"text-center",children:f||""})]},c.id)})]})}const Uns=()=>o.jsx("div",{className:"flex h-full items-center justify-center",children:o.jsx(Cr,{iconSlot:o.jsx(Of,{}),titleSlot:"No Tools yet",descriptionSlot:o.jsxs(o.Fragment,{children:["Mastra tools are not configured yet. ",o.jsx("br",{}),"More information in the documentation."]}),actionSlot:o.jsxs(de,{variant:"ghost",as:"a",href:"https://mastra.ai/docs/agents/using-tools-and-mcp",target:"_blank",rel:"noopener noreferrer",children:["Tools Documentation ",o.jsx(_a,{})]})})}),qns=()=>{const e=We();return Rn({mutationFn:async({toolId:t,input:n,requestContext:r})=>{const s=new u_;Object.entries(r??{}).forEach(([a,i])=>{s.set(a,i)});try{return await e.getTool(t).execute({data:n,requestContext:s})}catch(a){throw De.error("Error executing dev tool"),console.error("Error executing dev tool:",a),a}}})},Vns=({toolId:e})=>{const{canExecute:t}=il(),n=t("tools"),{data:r={}}=km(),s=g.useMemo(()=>{for(const v of Object.values(r))if(v.tools){const y=Object.values(v.tools).find(b=>b.id===e);if(y)return y}return null},[r,e]),{data:a,isLoading:i,error:l}=G0r(e,{enabled:!s}),c=s||a,{mutateAsync:u,isPending:d,data:f}=qns(),{requestContext:p}=_s();g.useEffect(()=>{if(l){const v=l instanceof Error?l.message:"Failed to load tool";De.error(`Error loading tool: ${v}`)}},[l]);const h=async(v,y)=>{if(!c)return;const b={...p??{},...y??{}};return u({toolId:c.id,input:v,requestContext:b})},m=c?.inputSchema?lm(im(yx(c?.inputSchema))):Ss({});return i?o.jsxs("div",{className:"p-6",children:[o.jsx(bt,{className:"h-8 w-48 mb-4"}),o.jsx(bt,{className:"h-32 w-full"})]}):l?null:c?n?o.jsx(Hje,{executionResult:f,isExecutingTool:d,zodInputSchema:m,handleExecuteTool:h,toolDescription:c.description,toolId:c.id,requestContextSchema:c.requestContextSchema}):o.jsx("div",{className:"py-12 text-center px-6",children:o.jsx(ge,{variant:"ui-sm",className:"text-neutral3",children:"You don't have permission to execute tools."})}):o.jsx("div",{className:"py-12 text-center px-6",children:o.jsx(ge,{variant:"header-md",className:"text-neutral3",children:"Tool not found"})})};function Hns({value:e,onValueChange:t,placeholder:n="Select a tool...",searchPlaceholder:r="Search tools...",emptyText:s="No tools found.",className:a,disabled:i=!1,variant:l}){const{data:c={},isLoading:u,isError:d,error:f}=cI(),{data:p={},isLoading:h,isError:m,error:v}=km(),{navigate:y,paths:b}=yn();g.useEffect(()=>{if(d){const _=f instanceof Error?f.message:"Failed to load tools";De.error(`Error loading tools: ${_}`)}},[d,f]),g.useEffect(()=>{if(m){const _=v instanceof Error?v.message:"Failed to load agents";De.error(`Error loading agents: ${_}`)}},[m,v]);const S=new Map;Object.values(p).forEach(_=>{_.tools&&Object.values(_.tools).forEach(C=>{S.has(C.id)||S.set(C.id,C)})}),Object.values(c).forEach(_=>{S.has(_.id)||S.set(_.id,_)});const w=Array.from(S.values()).map(_=>({label:_.id,value:_.id})),k=_=>{t?t(_):_&&_!==e&&y(b.toolLink(_))};return o.jsx(Jl,{options:w,value:e,onValueChange:k,placeholder:u||h?"Loading tools...":n,searchPlaceholder:r,emptyText:s,className:a,disabled:i||u||h||d||m,variant:l})}const Wns=({isLoading:e,server:t})=>{const[{sseUrl:n,httpStreamUrl:r},s]=g.useState({sseUrl:"",httpStreamUrl:""});if(g.useEffect(()=>{if(!t)return;const i=window.MASTRA_SERVER_HOST,l=window.MASTRA_SERVER_PORT;let c=null;i&&l&&(c=`http://${i}:${l}`);const u=c||"http://localhost:4111",d=`${u}/api/mcp/${t.id}/sse`,f=`${u}/api/mcp/${t.id}/mcp`;s({sseUrl:d,httpStreamUrl:f})},[t]),e)return null;if(!t)return o.jsx(wy,{children:o.jsx(ge,{as:"h1",variant:"header-md",className:"text-neutral3 font-medium py-20 text-center",children:"Server not found"})});const a=`npx -y mcp-remote ${n}`;return o.jsxs(wy,{isDivided:!0,children:[o.jsxs("div",{className:"px-8 py-12 mx-auto max-w-2xl w-full",children:[o.jsx(ge,{as:"h1",variant:"header-md",className:"text-neutral6 font-medium pb-4",children:t.name}),o.jsxs("div",{className:"flex items-center gap-1 pb-6",children:[o.jsx(dn,{icon:o.jsx(_Et,{className:"text-neutral6"}),className:"rounded-r-sm text-neutral4!",children:"Version"}),o.jsx(dn,{className:"rounded-l-sm text-neutral4!",children:t.version_detail.version})]}),o.jsx(ge,{className:"text-neutral3 pb-4",children:"This MCP server can be accessed through multiple transport methods. Choose the one that best fits your use case."}),o.jsxs("div",{className:"flex flex-col gap-4",children:[o.jsxs("div",{className:"rounded-lg border border-border1 bg-surface3 p-4",children:[o.jsx(dn,{icon:o.jsx("span",{className:"font-mono w-6 text-accent1 font-medium mr-1",children:"HTTP"}),children:"Regular HTTP Endpoint"}),o.jsx(ge,{className:"text-neutral3 pt-1 pb-2",children:"Use for stateless HTTP transport with streamable responses."}),o.jsxs("div",{className:"flex items-start gap-2",children:[o.jsx(ge,{className:"px-2 py-1 bg-surface4 rounded-lg",children:r}),o.jsx("div",{className:"pt-1",children:o.jsx(Oa,{tooltip:"Copy HTTP Stream URL",content:r})})]})]}),o.jsxs("div",{className:"rounded-lg border border-border1 bg-surface3 p-4",children:[o.jsx(dn,{icon:o.jsx("span",{className:"font-mono w-6 text-accent1 font-medium mr-1",children:"SSE"}),children:"Server-Sent Events"}),o.jsx(ge,{className:"text-neutral3 pt-1 pb-2",children:"Use for real-time communication via SSE."}),o.jsxs("div",{className:"flex items-start gap-2",children:[o.jsx(ge,{className:"px-2 py-1 bg-surface4 rounded-lg",children:n}),o.jsx("div",{className:"pt-1",children:o.jsx(Oa,{tooltip:"Copy SSE URL",content:n})})]})]}),o.jsxs("div",{className:"rounded-lg border border-border1 bg-surface3 p-4",children:[o.jsx(dn,{icon:o.jsx("span",{className:"font-mono w-6 text-accent1 font-medium mr-1",children:"CLI"}),children:"Command Line"}),o.jsx(ge,{className:"text-neutral3 pt-1 pb-2",children:"Use for local command-line access via npx and mcp-remote."}),o.jsxs("div",{className:"flex items-start gap-2",children:[o.jsx(ge,{className:"px-2 py-1 bg-surface4 rounded-lg",children:a}),o.jsx("div",{className:"pt-1",children:o.jsx(Oa,{tooltip:"Copy Command Line Config",content:a})})]})]})]})]}),o.jsx("div",{className:"h-full overflow-y-scroll border-l border-border1",children:o.jsx(Zns,{server:t})})]})},Zns=({server:e})=>{const{data:t={},isLoading:n}=M5t(e);if(n)return null;const r=Object.keys(t);return o.jsxs("div",{className:"p-5 overflow-y-scroll",children:[o.jsxs("div",{className:"text-neutral6 flex gap-2 items-center",children:[o.jsx(Ue,{size:"lg",className:"bg-surface4 rounded-md p-1",children:o.jsx(B_,{})}),o.jsx(ge,{variant:"header-md",as:"h2",className:"font-medium",children:"Available Tools"})]}),o.jsx("div",{className:"flex flex-col gap-2 pt-6",children:r.map(s=>{const a=t[s];return o.jsx(Qns,{tool:a,serverId:e.id},s)})})]})};function Gns(e){if(!e)return!1;const t=e.ui;return!!(typeof t?.resourceUri=="string"&&t.resourceUri.startsWith("ui://")||typeof e["ui/resourceUri"]=="string"&&e["ui/resourceUri"].startsWith("ui://"))}const Qns=({tool:e,serverId:t})=>{const n=g.useRef(null),{Link:r,paths:s}=yn(),a=o6t[e.toolType||"tool"],i=Gns(e._meta);return o.jsxs(Nf,{onClick:()=>n.current?.click(),children:[o.jsx(QIt,{children:o.jsx(a,{className:"group-hover/entity:text-accent6"})}),o.jsxs(Af,{children:[o.jsx(If,{children:o.jsxs("span",{className:"flex items-center gap-2",children:[o.jsx(r,{ref:n,href:s.mcpServerToolLink(t,e.id),children:e.id}),i&&o.jsx(dn,{className:"text-[10px] py-0",children:"App"})]})}),o.jsx(th,{children:e.description})]})]})},Yns=()=>{const{serverId:e}=ur(),{data:t=[],isLoading:n}=MZ(),r=t.find(s=>s.id===e);return o.jsx("div",{className:"h-full w-full overflow-hidden",children:o.jsx(Wns,{isLoading:n,server:r})})};function Xns(e){if(!e)return;const t=e.ui;if(t?.resourceUri)return t.resourceUri;const n=e["ui/resourceUri"];if(typeof n=="string")return n}const Kns=({toolId:e,serverId:t})=>{const{canExecute:n}=il(),r=n("tools"),s=We(),{data:a,isLoading:i,error:l}=mje(t,e),{mutateAsync:c,isPending:u,data:d}=g7r(t,e),f=a?Xns(a._meta):void 0,{data:p}=wt({queryKey:["mcp-app-resource",t,f],queryFn:async()=>f?(await s.readMcpServerResource(t,f)).contents[0]?.text??null:null,enabled:!!f}),h=g.useCallback(async(y,b)=>await c(b),[c]);g.useEffect(()=>{if(l){const y=l instanceof Error?l.message:"Failed to load tool";De.error(`Error loading tool: ${y}`)}},[l]);const m=async y=>{if(a)return await c(y)};if(i)return o.jsxs("div",{className:"p-6",children:[o.jsx(bt,{className:"h-8 w-48 mb-4"}),o.jsx(bt,{className:"h-32 w-full"})]});if(l)return null;if(!a)return o.jsx("div",{className:"py-12 text-center px-6",children:o.jsx(ge,{variant:"header-md",className:"text-neutral3",children:"Tool not found"})});if(!r)return o.jsx("div",{className:"py-12 text-center px-6",children:o.jsx(ge,{variant:"ui-sm",className:"text-neutral3",children:"You don't have permission to execute tools."})});let v;try{v=lm(im(a.inputSchema))}catch(y){console.error("Error processing input schema:",y),De.error("Failed to process tool input schema."),v=Ss({})}return o.jsxs("div",{className:"flex flex-col gap-4",children:[p&&o.jsx("div",{className:"border-b border-border1 p-4",children:o.jsx($5t,{html:p,toolName:a.name??a.id,onToolCall:h})}),o.jsx(Hje,{executionResult:d,isExecutingTool:u,zodInputSchema:v,handleExecuteTool:m,toolDescription:a.description||"",toolId:a.id})]})},Jns=()=>{const{serverId:e,toolId:t}=ur(),{data:n,isLoading:r}=mje(e,t);return r||!n?null:o.jsx("div",{className:"h-full w-full overflow-y-auto",children:o.jsx(Kns,{toolId:t,serverId:e})})},F9t=[{label:"Agent",entityType:Os.AGENT},{label:"Workflow",entityType:Os.WORKFLOW_RUN},{label:"Scorer",entityType:Os.SCORER},{label:"Ingest",entityType:Os.RAG_INGESTION}],dN="rootEntityType",fN={tags:"filterTags",entityId:"filterEntityId",entityName:"filterEntityName",runId:"filterRunId",threadId:"filterThreadId",sessionId:"filterSessionId",requestId:"filterRequestId",resourceId:"filterResourceId",userId:"filterUserId",organizationId:"filterOrganizationId",serviceName:"filterServiceName",environment:"filterEnvironment",experimentId:"filterExperimentId",provider:"filterProvider",model:"filterModel"},eG=Object.keys(fN),ETe="mastra:metrics:saved-filters";function ers(e){const t=ars(e);try{localStorage.setItem(ETe,t.toString())}catch{}}function trs(){try{localStorage.removeItem(ETe)}catch{}}function z9t(){try{const e=localStorage.getItem(ETe);if(!e)return null;const t=new URLSearchParams(e);return t.toString()?t:null}catch{return null}}function nrs(e){if(e.has(dN))return!0;for(const t of eG)if(e.has(fN[t]))return!0;return!1}function rrs({availableTags:e,availableEntityNames:t,availableServiceNames:n,availableEnvironments:r,loading:s}){const a=[{id:"rootEntityType",label:"Primitive Type",kind:"pick-multi",searchable:!1,options:F9t.map(u=>({label:u.label,value:u.entityType})),placeholder:"Choose entity type",emptyText:"No entity types."},{id:"entityName",label:"Primitive Name",kind:"pick-multi",options:t.map(u=>({label:u,value:u})),placeholder:"Choose entity names",emptyText:"No entity names found.",isLoading:s?.entityNames},{id:"entityId",label:"Primitive ID",kind:"text"},{id:"tags",label:"Tags",kind:"pick-multi",multi:!0,options:e.map(u=>({label:u,value:u})),placeholder:"Choose tags",emptyText:"No tags found.",isLoading:s?.tags},{id:"serviceName",label:"Service Name",kind:"pick-multi",options:n.map(u=>({label:u,value:u})),placeholder:"Choose service names",emptyText:"No service names found.",isLoading:s?.serviceNames},{id:"environment",label:"Environment",kind:"pick-multi",options:r.map(u=>({label:u,value:u})),placeholder:"Choose environments",emptyText:"No environments found.",isLoading:s?.environments},{id:"threadId",label:"Thread ID",kind:"text"},{id:"resourceId",label:"Resource ID",kind:"text"},{id:"userId",label:"User ID",kind:"text"},{id:"organizationId",label:"Organization ID",kind:"text"},{id:"runId",label:"Run ID",kind:"text"},{id:"sessionId",label:"Session ID",kind:"text"},{id:"requestId",label:"Request ID",kind:"text"},{id:"experimentId",label:"Experiment ID",kind:"text"}],i=(u,d)=>u.label.localeCompare(d.label),l=a.filter(u=>u.kind==="pick-multi").sort(i),c=a.filter(u=>u.kind==="text").sort(i);return[...l,...c]}function srs(e){const t=[],n=new Map([[dN,"rootEntityType"]]);for(const s of eG)n.set(fN[s],s);const r=new Set;for(const[s]of e.entries()){const a=n.get(s);if(!a||r.has(a))continue;if(r.add(a),a==="tags"){const l=e.getAll(s);if(l.length===0)continue;t.push({fieldId:a,value:l.filter(Boolean)});continue}if(a==="rootEntityType"||a==="entityName"||a==="serviceName"||a==="environment"||a==="provider"||a==="model"){const l=e.getAll(s);if(l.length>1){t.push({fieldId:a,value:l});continue}}const i=e.get(s);i!==null&&t.push({fieldId:a,value:i})}return t}function ars(e){const t=new URLSearchParams,n=e.getAll(dN);for(const r of n)t.append(dN,r);for(const r of eG){const s=fN[r],a=e.getAll(s);for(const i of a)t.append(s,i)}return t}function irs(e,t){e.delete(dN);for(const n of eG)e.delete(fN[n]);for(const n of t){const r=n.fieldId==="rootEntityType"?dN:fN[n.fieldId];if(r)if(Array.isArray(n.value)){const s=n.value.filter(a=>typeof a=="string"&&a!=="");if(s.length===0){n.fieldId==="tags"&&e.append(r,"");continue}for(const a of s)e.append(r,a)}else typeof n.value=="string"&&e.set(r,n.value.trim())}}const ors="Any";function UQe(e){const t=e.trim();return t===""||t===ors}const lrs=new Set(F9t.map(e=>e.entityType));function qQe(e){const t=e.trim();return lrs.has(t)?t:void 0}function crs(e){const t={};for(const n of e){const r=n.fieldId;if(Array.isArray(n.value)){const s=n.value.filter(a=>typeof a=="string").map(a=>a.trim()).filter(a=>!UQe(a));if(s.length===0)continue;if(r==="tags")t.tags=s;else if(r==="rootEntityType"){const a=qQe(s[0]);a&&(t.rootEntityType=a)}else t[r]=s[0]}else if(typeof n.value=="string"){if(UQe(n.value))continue;const s=n.value.trim();if(r==="rootEntityType"){const a=qQe(s);a&&(t.rootEntityType=a)}else t[r]=s}}return t}const B9t=[{label:"Last 24 hours",value:"24h"},{label:"Last 3 days",value:"3d"},{label:"Last 7 days",value:"7d"},{label:"Last 14 days",value:"14d"},{label:"Last 30 days",value:"30d"}],urs=new Set(B9t.map(e=>e.value));function drs(e){return typeof e=="string"&&(urs.has(e)||e==="custom")}const U9t=g.createContext({datePreset:"24h",setDatePreset:()=>{},customRange:void 0,setCustomRange:()=>{},dateRangeLabel:"Last 24 hours",filterTokens:[],setFilterTokens:()=>{},dimensionalFilter:{},dimensionalFilterKey:"{}",tracesBasePath:void 0,logsBasePath:void 0});function tG(){return g.useContext(U9t)}function frs(e,t){return e!=="custom"?B9t.find(n=>n.value===e)?.label??e:t?.from?t.to?`${er(t.from,"MMM d, yyyy")} – ${er(t.to,"MMM d, yyyy")}`:er(t.from,"MMM d, yyyy"):"Custom range"}function prs({children:e,preset:t,filterTokens:n,onPresetChange:r,onFilterTokensChange:s,customRange:a,onCustomRangeChange:i,tracesBasePath:l,logsBasePath:c}){const u=g.useMemo(()=>JSON.stringify(n),[n]),d=g.useMemo(()=>n,[u]),f=g.useMemo(()=>crs(d),[d]),p=g.useMemo(()=>JSON.stringify(f),[f]),h=frs(t,a),m=g.useMemo(()=>({datePreset:t,setDatePreset:r,customRange:a,setCustomRange:i??(()=>{}),dateRangeLabel:h,filterTokens:d,setFilterTokens:s,dimensionalFilter:f,dimensionalFilterKey:p,tracesBasePath:l,logsBasePath:c}),[t,r,a,i,h,d,s,f,p,l,c]);return o.jsx(U9t.Provider,{value:m,children:e})}const hrs=["last-24h","last-3d","last-7d","last-14d","last-30d","custom"];function mrs(e){switch(e){case"3d":return"last-3d";case"7d":return"last-7d";case"14d":return"last-14d";case"30d":return"last-30d";case"custom":return"custom";default:return"last-24h"}}function grs(e){switch(e){case"last-3d":return"3d";case"last-7d":return"7d";case"last-14d":return"14d";case"last-30d":return"30d";case"custom":return"custom";default:return"24h"}}function vrs(){const{datePreset:e,setDatePreset:t,customRange:n,setCustomRange:r}=tG(),s=g.useRef(e);s.current=e;const a=g.useRef(n);return a.current=n,o.jsx(aTe,{preset:mrs(e),onPresetChange:i=>{const l=grs(i);s.current=l,t(l)},dateFrom:n?.from,dateTo:n?.to,onDateChange:(i,l)=>{if(s.current!=="custom")return;const c={...a.current,[l]:i};a.current=c,r(c)},presets:hrs})}const rse={"24h":1440*60*1e3,"3d":4320*60*1e3,"7d":10080*60*1e3,"14d":336*60*60*1e3,"30d":720*60*60*1e3};function yrs(e,t,n){if(e!=="custom"){const r=rse[e]??rse["24h"];return{start:new Date(n-r),end:new Date(n)}}return{start:t?.from??new Date(n-rse["24h"]),end:t?.to??new Date(n)}}function Em(){const{datePreset:e,customRange:t,dimensionalFilter:n,dimensionalFilterKey:r}=tG(),s=g.useRef(null),a=e==="custom"?`custom:${t?.from?.getTime()??""}:${t?.to?.getTime()??""}`:`preset:${e}`;(!s.current||s.current.key!==a)&&(s.current={key:a,anchor:Date.now()});const i=s.current.anchor,l=g.useMemo(()=>yrs(e,t,i),[e,t,i]),c=g.useMemo(()=>({timestamp:l,...n}),[l,r]),u=g.useMemo(()=>`${a}|${r}`,[a,r]);return{datePreset:e,customRange:t,timestamp:l,filters:c,dimensionalFilter:n,filterKey:u}}function q9t(){const e=We(),{filters:t,filterKey:n}=Em();return wt({queryKey:["metrics","agent-runs-kpi",n],queryFn:()=>e.getMetricAggregate({name:["mastra_agent_duration_ms"],aggregation:"count",filters:t,comparePeriod:"previous_period"})})}function K4({href:e,LinkComponent:t="a"}){return o.jsx(de,{as:t,href:e,variant:"ghost",size:"icon-md",tooltip:"View in Traces","aria-label":"View in Traces",children:o.jsx(Kkn,{})})}function brs({href:e,LinkComponent:t="a"}){return o.jsx(de,{as:t,href:e,variant:"ghost",size:"icon-md",tooltip:"View errors in Logs","aria-label":"View errors in Logs",children:o.jsx($On,{})})}const xrs=[{dataKey:"p50",label:"p50",color:Pp.blue,aggregate:e=>({value:e.length>0?`${Math.round(e.reduce((t,n)=>t+n.p50,0)/e.length)}`:"0",suffix:"avg ms"})},{dataKey:"p95",label:"p95",color:Pp.yellow,aggregate:e=>({value:e.length>0?`${Math.round(e.reduce((t,n)=>t+n.p95,0)/e.length)}`:"0",suffix:"avg ms"})}];function sse({data:e,onPointClick:t}){return e.length===0?o.jsx(Ut.NoData,{message:"No latency data yet"}):o.jsx(LU,{data:e,series:xrs,onPointClick:t?n=>{const r=n;typeof r?.tsMs=="number"&&Number.isFinite(r.tsMs)&&t(r)}:void 0})}function wrs({data:e,isLoading:t,isError:n,onPointClick:r,actions:s}){const a=e?e.agentData.length>0?"agents":e.workflowData.length>0?"workflows":e.toolData.length>0?"tools":"agents":"agents",[i,l]=g.useState(a);g.useEffect(()=>{if(!e)return;const p={agents:e.agentData.length>0,workflows:e.workflowData.length>0,tools:e.toolData.length>0};!p[i]&&p[a]&&l(a)},[e,i,a]);const c=typeof s=="function"?s(i):s,u=!!e&&(e.agentData.length>0||e.workflowData.length>0||e.toolData.length>0),d=e?Object.values(e).filter(Array.isArray).flat().map(p=>p.p50).filter(p=>typeof p=="number"):[],f=d.length>0?`${Math.round(d.reduce((p,h)=>p+h,0)/d.length)}ms`:"—";return o.jsxs(Ut,{children:[o.jsxs(Ut.TopBar,{children:[o.jsx(Ut.TitleAndDescription,{title:"Latency",description:"Hourly p50 and p95 latency."}),u&&o.jsx(Ut.Summary,{value:f,label:"Avg p50"}),c?o.jsx(Ut.Actions,{children:c}):null]}),t?o.jsx(Ut.Loading,{}):n?o.jsx(Ut.Error,{message:"Failed to load latency data"}):o.jsx(Ut.Content,{children:u?o.jsxs(cu,{value:i,onValueChange:l,defaultTab:a,className:"overflow-visible",children:[o.jsxs(uu,{children:[o.jsx(qr,{value:"agents",children:"Agents"}),o.jsx(qr,{value:"workflows",children:"Workflows"}),o.jsx(qr,{value:"tools",children:"Tools"})]}),o.jsx(fs,{value:"agents",children:o.jsx(sse,{data:e.agentData,onPointClick:r?p=>r("agents",p):void 0})}),o.jsx(fs,{value:"workflows",children:o.jsx(sse,{data:e.workflowData,onPointClick:r?p=>r("workflows",p):void 0})}),o.jsx(fs,{value:"tools",children:o.jsx(sse,{data:e.toolData,onPointClick:r?p=>r("tools",p):void 0})})]}):o.jsx(Ut.NoData,{message:"No latency data yet"})})]})}function Srs(e){switch(e){case"24h":return"last-24h";case"3d":return"last-3d";case"7d":return"last-7d";case"14d":return"last-14d";case"30d":return"last-30d";case"custom":return"custom";default:return}}function krs(e,t){if(t==="1h"){const s=new Date(e);s.setUTCMinutes(0,0,0);const a=new Date(s.getTime()+3600*1e3);return{from:s,to:a}}const n=new Date(e);n.setUTCHours(0,0,0,0);const r=new Date(n.getTime()+1440*60*1e3);return{from:n,to:r}}function V9t(e,t,n,r,s,a,i){if(i){e.set(t,"custom"),e.set(n,i.from.toISOString()),e.set(r,i.to.toISOString());return}if(s==="custom"){e.set(t,"custom"),a?.from&&e.set(n,a.from.toISOString()),a?.to&&e.set(r,a.to.toISOString());return}const l=Srs(s);l&&e.set(t,l)}function To(e,t,n){typeof n=="string"&&n.length>0&&e.set(t,n)}function H9t(e,t,n){if(!(!Array.isArray(n)||n.length===0))for(const r of n)r&&e.append(t,r)}function VQe({preset:e,customRange:t,dashboardFilter:n,scope:r,tracesBasePath:s="/observability"}){const a=new URLSearchParams;a.set(xw,"branches"),V9t(a,ww,Sw,kw,e,t,r.window);const i=r.rootEntityType??n.rootEntityType;i&&a.set($x,i),r.status&&a.set(Mx,r.status),To(a,Ol.entityName,r.entityName??n.entityName),To(a,Ol.threadId,r.threadId??n.threadId),To(a,Ol.resourceId,r.resourceId??n.resourceId),To(a,Ol.entityId,n.entityId),To(a,Ol.runId,n.runId),To(a,Ol.sessionId,n.sessionId),To(a,Ol.requestId,n.requestId),To(a,Ol.userId,n.userId),To(a,Ol.organizationId,n.organizationId),To(a,Ol.experimentId,n.experimentId),To(a,Ol.serviceName,n.serviceName),To(a,Ol.environment,n.environment),H9t(a,Ol.tags,n.tags);const l=a.toString();return l?`${s}?${l}`:s}function Ors({preset:e,customRange:t,dashboardFilter:n,scope:r,logsBasePath:s="/logs"}){const a=new URLSearchParams;V9t(a,qb,Vb,Hb,e,t,r.window);const i=r.rootEntityType??n.rootEntityType;i&&a.set(Dx,i),To(a,_l.entityName,r.entityName??n.entityName),To(a,_l.threadId,r.threadId??n.threadId),To(a,_l.resourceId,r.resourceId??n.resourceId),To(a,_l.runId,n.runId),To(a,_l.sessionId,n.sessionId),To(a,_l.requestId,n.requestId),To(a,_l.userId,n.userId),To(a,_l.organizationId,n.organizationId),To(a,_l.experimentId,n.experimentId),To(a,_l.serviceName,n.serviceName),To(a,_l.environment,n.environment),H9t(a,_l.tags,n.tags),r.status==="error"&&a.append(_l.level,"error");const l=a.toString();return l?`${s}?${l}`:s}function jI(){const{datePreset:e,customRange:t,dimensionalFilter:n,tracesBasePath:r,logsBasePath:s}=tG(),a=g.useCallback((c={})=>VQe({preset:e,customRange:t,dashboardFilter:n,scope:c,tracesBasePath:r}),[e,t,n,r]),i=g.useCallback((c={})=>Ors({preset:e,customRange:t,dashboardFilter:n,scope:c,logsBasePath:s}),[e,t,n,s]),l=g.useCallback((c,u,d)=>{const f=krs(u,d);return VQe({preset:e,customRange:t,dashboardFilter:n,scope:{...c,window:f},tracesBasePath:r})},[e,t,n,r]);return{getTracesHref:a,getLogsHref:i,getBucketTracesHref:l}}const W9t="1h";async function ase(e,t,n){const r=await e.getMetricPercentiles({name:t,percentiles:[.5,.95],interval:W9t,filters:n}),s=r.series.find(l=>l.percentile===.5),a=r.series.find(l=>l.percentile===.95);if(!s||!a)return[];const i=new Map(a.points.map(l=>[new Date(l.timestamp).getTime(),l.value]));return s.points.map(l=>{const c=new Date(l.timestamp),u=c.getTime();return{time:c.toLocaleTimeString("en-US",{hour:"2-digit",minute:"2-digit",hour12:!1}),tsMs:u,p50:Math.round(l.value),p95:Math.round(i.get(u)??0)}})}function _rs(){const e=We(),{filters:t,filterKey:n}=Em();return wt({queryKey:["metrics","latency",n],queryFn:async()=>{const[r,s,a]=await Promise.all([ase(e,"mastra_agent_duration_ms",t),ase(e,"mastra_workflow_duration_ms",t),ase(e,"mastra_tool_duration_ms",t)]);return{agentData:r,workflowData:s,toolData:a,interval:W9t}}})}const HQe={agents:Os.AGENT,workflows:Os.WORKFLOW_RUN,tools:Os.TOOL};function Crs(){const{data:e,isLoading:t,isError:n}=_rs(),{getTracesHref:r,getBucketTracesHref:s}=jI(),{Link:a}=yn(),i=bs();return o.jsx(wrs,{data:e,isLoading:t,isError:n,onPointClick:(l,c)=>{Number.isFinite(c.tsMs)&&i(s({rootEntityType:HQe[l]},c.tsMs,"1h"))},actions:l=>o.jsx(K4,{href:r({rootEntityType:HQe[l]}),LinkComponent:a})})}function Ers(e){return e==="threads"||e==="resources"}function ise(e){return e.length<=12?e:`${e.slice(0,6)}…${e.slice(-4)}`}function jrs({threads:e,resources:t,getThreadRowHref:n,getResourceRowHref:r,actions:s,LinkComponent:a}){const[i,l]=g.useState("threads"),c=e.data?.map(y=>({...y,key:y.threadId}))??[],u=t.data?.map(y=>({...y,key:y.resourceId}))??[],d=c.length>0,f=u.length>0,p=e.data?.reduce((y,b)=>y+b.runs,0)??0,h=t.data?.reduce((y,b)=>y+b.threadCount,0)??0,m=i==="threads"?e:t,v=typeof s=="function"?s(i):s;return o.jsxs(Ut,{children:[o.jsxs(Ut.TopBar,{children:[o.jsx(Ut.TitleAndDescription,{title:"Memory",description:"Resource and Thread consumption"}),i==="threads"&&d&&o.jsx(Ut.Summary,{value:p.toLocaleString(),label:"Total runs"}),i==="resources"&&f&&o.jsx(Ut.Summary,{value:h.toLocaleString(),label:"Total threads"}),v?o.jsx(Ut.Actions,{children:v}):null]}),m.isLoading?o.jsx(Ut.Loading,{}):m.isError?o.jsx(Ut.Error,{message:"Failed to load memory data"}):o.jsx(Ut.Content,{children:o.jsxs(cu,{defaultTab:"threads",value:i,onValueChange:y=>{Ers(y)&&l(y)},className:"grid grid-rows-[auto_1fr] overflow-y-auto h-full",children:[o.jsxs(uu,{children:[o.jsx(qr,{value:"threads",children:"Threads"}),o.jsx(qr,{value:"resources",children:"Resources"})]}),o.jsx(fs,{value:"threads",children:d?o.jsxs(me,{columns:"auto auto auto auto auto",...Uve,children:[o.jsxs(me.Top,{children:[o.jsx(me.TopCell,{sticky:"start",children:"Thread ID"}),o.jsx(me.TopCell,{className:"justify-end text-right",children:"Resource ID"}),o.jsx(me.TopCell,{className:"justify-end text-right",children:"Runs"}),o.jsx(me.TopCell,{className:"justify-end text-right",children:"Tokens"}),o.jsx(me.TopCell,{className:"justify-end text-right",children:"Cost"})]}),c.map(y=>{const b=n?.(y),S=o.jsxs(o.Fragment,{children:[o.jsx(me.RowHeaderCell,{height:"compact",className:"text-ui-sm",children:ise(y.threadId)}),o.jsx(me.NumberCell,{children:y.resourceId?ise(y.resourceId):"—"}),o.jsx(me.NumberCell,{highlight:!0,children:y.runs.toLocaleString()}),o.jsx(me.NumberCell,{children:y.tokens>0?wc(y.tokens):"—"}),o.jsx(me.NumberCell,{children:y.cost!=null?bg(y.cost,y.costUnit):"—"})]});return b?o.jsx(me.RowLink,{to:b,LinkComponent:a,children:S},y.key):o.jsx(me.RowStatic,{children:S},y.key)})]}):o.jsx(Ut.NoData,{message:"No thread activity yet"})}),o.jsx(fs,{value:"resources",children:f?o.jsxs(me,{columns:"auto auto auto auto",...Uve,children:[o.jsxs(me.Top,{children:[o.jsx(me.TopCell,{sticky:"start",children:"Resource ID"}),o.jsx(me.TopCell,{className:"justify-end text-right",children:"Threads"}),o.jsx(me.TopCell,{className:"justify-end text-right",children:"Tokens"}),o.jsx(me.TopCell,{className:"justify-end text-right",children:"Cost"})]}),u.map(y=>{const b=r?.(y),S=o.jsxs(o.Fragment,{children:[o.jsx(me.RowHeaderCell,{height:"compact",className:"text-ui-sm",children:ise(y.resourceId)}),o.jsx(me.NumberCell,{highlight:!0,children:y.threadCount.toLocaleString()}),o.jsx(me.NumberCell,{children:y.tokens>0?wc(y.tokens):"—"}),o.jsx(me.NumberCell,{children:y.cost!=null?bg(y.cost,y.costUnit):"—"})]});return b?o.jsx(me.RowLink,{to:b,LinkComponent:a,children:S},y.key):o.jsx(me.RowStatic,{children:S},y.key)})]}):o.jsx(Ut.NoData,{message:"No resource activity yet"})})]})})]})}function J4(e,t,n){const r=e.get(t);if(r!==void 0)return r;const s=n();return e.set(t,s),s}const ose=20;function Trs(){const e=We(),{filters:t,filterKey:n}=Em();return wt({queryKey:["metrics","top-active-threads",n],queryFn:async()=>{const r={groupBy:["threadId","resourceId"],orderDirection:"DESC",filters:t},[s,a,i]=await Promise.all([e.getMetricBreakdown({...r,name:["mastra_agent_duration_ms"],aggregation:"count",limit:ose}),e.getMetricBreakdown({...r,name:["mastra_model_total_input_tokens"],aggregation:"sum",limit:ose}),e.getMetricBreakdown({...r,name:["mastra_model_total_output_tokens"],aggregation:"sum",limit:ose})]),l=new Map,c=d=>J4(l,d,()=>({tokens:0,cost:null,costUnit:null})),u=d=>{for(const f of d){const p=f.dimensions.threadId;if(!p)continue;const h=c(p);h.tokens+=f.value,f.estimatedCost!=null&&(h.cost=(h.cost??0)+f.estimatedCost,f.costUnit&&(h.costUnit=f.costUnit))}};return u(a.groups),u(i.groups),s.groups.filter(d=>!!d.dimensions.threadId).map(d=>{const f=d.dimensions.threadId,p=l.get(f);return{threadId:f,resourceId:d.dimensions.resourceId??null,runs:d.value,tokens:p?.tokens??0,cost:p?.cost??null,costUnit:p?.costUnit??null}})}})}const lse=20;function Nrs(){const e=We(),{filters:t,filterKey:n}=Em();return wt({queryKey:["metrics","top-resources-by-threads",n],queryFn:async()=>{const r={groupBy:["resourceId"],orderDirection:"DESC",filters:t},[s,a,i]=await Promise.all([e.getMetricBreakdown({...r,name:["mastra_agent_duration_ms"],aggregation:"count_distinct",distinctColumn:"threadId",limit:lse}),e.getMetricBreakdown({...r,name:["mastra_model_total_input_tokens"],aggregation:"sum",limit:lse}),e.getMetricBreakdown({...r,name:["mastra_model_total_output_tokens"],aggregation:"sum",limit:lse})]),l=new Map,c=d=>J4(l,d,()=>({tokens:0,cost:null,costUnit:null})),u=d=>{for(const f of d){const p=f.dimensions.resourceId;if(!p)continue;const h=c(p);h.tokens+=f.value,f.estimatedCost!=null&&(h.cost=(h.cost??0)+f.estimatedCost,f.costUnit&&(h.costUnit=f.costUnit))}};return u(a.groups),u(i.groups),s.groups.filter(d=>!!d.dimensions.resourceId).map(d=>{const f=d.dimensions.resourceId,p=l.get(f);return{resourceId:f,threadCount:d.value,tokens:p?.tokens??0,cost:p?.cost??null,costUnit:p?.costUnit??null}})}})}function Irs(){const e=Trs(),t=Nrs(),{getTracesHref:n}=jI(),{Link:r}=yn();return o.jsx(jrs,{threads:{data:e.data,isLoading:e.isLoading,isError:e.isError},resources:{data:t.data,isLoading:t.isLoading,isError:t.isError},LinkComponent:r,getThreadRowHref:s=>n({threadId:s.threadId,...s.resourceId?{resourceId:s.resourceId}:{}}),getResourceRowHref:s=>n({resourceId:s.resourceId})})}function e5({label:e,value:t,prevValue:n,changePct:r,isLoading:s,isError:a}){const i=t!=null;return o.jsxs(Kr,{children:[o.jsx(Kr.Label,{children:e}),o.jsx(Kr.Value,{className:i?void 0:"invisible",children:i?t:"—"}),a?o.jsx(Kr.Error,{}):s?o.jsx(Kr.Loading,{}):i?r!=null?o.jsx(Kr.Change,{changePct:r,prevValue:n}):o.jsx(Kr.NoChange,{}):o.jsx(Kr.NoData,{})]})}function Ars(){const e=We(),{filters:t,filterKey:n}=Em();return wt({queryKey:["metrics","active-resources-kpi",n],queryFn:()=>e.getMetricAggregate({name:["mastra_agent_duration_ms"],aggregation:"count_distinct",distinctColumn:"resourceId",filters:t,comparePeriod:"previous_period"})})}function Rrs(){const e=We(),{filters:t,filterKey:n}=Em();return wt({queryKey:["metrics","active-threads-kpi",n],queryFn:()=>e.getMetricAggregate({name:["mastra_agent_duration_ms"],aggregation:"count_distinct",distinctColumn:"threadId",filters:t,comparePeriod:"previous_period"})})}function Prs(){const e=We(),{filters:t,filterKey:n}=Em();return wt({queryKey:["metrics","model-cost-kpi",n],queryFn:async()=>{const r=await e.getMetricAggregate({name:["mastra_model_total_input_tokens","mastra_model_total_output_tokens"],aggregation:"sum",filters:t,comparePeriod:"previous_period"});return{cost:r.estimatedCost??null,costUnit:r.costUnit??null,previousCost:r.previousEstimatedCost??null,costChangePercent:r.costChangePercent??null}}})}function $rs(){const e=We(),{filters:t,filterKey:n}=Em();return wt({queryKey:["metrics","total-tokens-kpi",n],queryFn:async()=>{const[r,s]=await Promise.all([e.getMetricAggregate({name:["mastra_model_total_input_tokens"],aggregation:"sum",filters:t,comparePeriod:"previous_period"}),e.getMetricAggregate({name:["mastra_model_total_output_tokens"],aggregation:"sum",filters:t,comparePeriod:"previous_period"})]),a=r.value!=null||s.value!=null,i=r.previousValue!=null||s.previousValue!=null,l=(r.value??0)+(s.value??0),c=(r.previousValue??0)+(s.previousValue??0),u=i&&c>0?(l-c)/c*100:null;return{value:a?l:null,previousValue:i?c:null,changePercent:u}}})}function Mrs(){const{data:e,isLoading:t,isError:n}=q9t();return o.jsx(e5,{label:"Total Agent Runs",value:e?.value!=null?e.value.toLocaleString():null,prevValue:e?.previousValue!=null?e.previousValue.toLocaleString():void 0,changePct:e?.changePercent??null,isLoading:t,isError:n})}function Drs(){const{data:e,isLoading:t,isError:n}=Prs();return o.jsx(e5,{label:"Total Model Cost",value:e?.cost!=null?bg(e.cost,e.costUnit):null,prevValue:e?.previousCost!=null?bg(e.previousCost,e.costUnit):void 0,changePct:e?.costChangePercent??null,isLoading:t,isError:n})}function Lrs(){const{data:e,isLoading:t,isError:n}=$rs();return o.jsx(e5,{label:"Total Tokens",value:e?.value!=null?wc(e.value):null,prevValue:e?.previousValue!=null?wc(e.previousValue):void 0,changePct:e?.changePercent??null,isLoading:t,isError:n})}function Frs(){const{data:e,isLoading:t,isError:n}=Rrs();return o.jsx(e5,{label:"Total Threads",value:e?.value!=null?wc(e.value):null,prevValue:e?.previousValue!=null?wc(e.previousValue):void 0,changePct:e?.changePercent??null,isLoading:t,isError:n})}function zrs(){const{data:e,isLoading:t,isError:n}=Ars();return o.jsx(e5,{label:"Total Resources",value:e?.value!=null?wc(e.value):null,prevValue:e?.previousValue!=null?wc(e.previousValue):void 0,changePct:e?.changePercent??null,isLoading:t,isError:n})}function Brs({onClear:e,onRemoveAll:t,onSave:n,onRemoveSaved:r,isLoading:s,filterFields:a,filterTokens:i,onFilterTokensChange:l,autoFocusFilterFieldId:c}){const u=i.length>0,d=i.some(f=>Urs(f,a));return o.jsxs("div",{className:K("grid grid-cols-[1fr_auto] gap-3 items-start"),children:[o.jsx(lTe,{fields:a,tokens:i,onTokensChange:l,disabled:s,autoFocusFieldId:c}),u&&o.jsx(iTe,{disabled:s,onClear:d?e:void 0,onRemoveAll:t,onSave:n,onRemoveSaved:r})]})}function Urs(e,t){const n=t.find(r=>r.id===e.fieldId);return n?n.kind==="text"?typeof e.value=="string"&&e.value.trim()!=="":n.kind==="pick-multi"?n.multi?Array.isArray(e.value)&&e.value.length>0:typeof e.value=="string"&&e.value!==""&&e.value!=="Any":n.kind==="multi-select"?Array.isArray(e.value)&&e.value.length>0:!1:!1}function qrs({rows:e,isLoading:t,isError:n,getRowHref:r,actions:s,LinkComponent:a}){const i=!!e&&e.length>0;return o.jsxs(Ut,{children:[o.jsxs(Ut.TopBar,{children:[o.jsx(Ut.TitleAndDescription,{title:"Model Usage & Cost",description:"Token consumption by model."}),i&&(()=>{const l=e.reduce((d,f)=>d+(f.cost??0),0),c=new Set;for(const d of e)d.cost!=null&&d.costUnit&&c.add(d.costUnit);let u;return c.size===0?u=l>0?bg(l):"—":c.size===1?u=l>0?bg(l,[...c][0]):"—":u="Mixed",o.jsx(Ut.Summary,{value:u,label:"Total cost"})})(),s?o.jsx(Ut.Actions,{children:s}):null]}),t?o.jsx(Ut.Loading,{}):n?o.jsx(Ut.Error,{message:"Failed to load model usage data"}):o.jsx(Ut.Content,{children:i?o.jsxs(me,{columns:"auto auto auto auto auto auto",...Uve,children:[o.jsxs(me.Top,{children:[o.jsx(me.TopCell,{sticky:"start",children:"Model"}),o.jsx(me.TopCell,{className:"justify-end text-right",children:"Input"}),o.jsx(me.TopCell,{className:"justify-end text-right",children:"Output"}),o.jsx(me.TopCell,{className:"justify-end text-right",children:"Cache Read"}),o.jsx(me.TopCell,{className:"justify-end text-right",children:"Cache Write"}),o.jsx(me.TopCell,{className:"justify-end text-right",children:"Cost"})]}),e.map(l=>{const c=r?.(l),u=o.jsxs(o.Fragment,{children:[o.jsx(me.RowHeaderCell,{height:"compact",className:"text-ui-sm",children:l.model}),o.jsx(me.NumberCell,{children:l.input}),o.jsx(me.NumberCell,{children:l.output}),o.jsx(me.NumberCell,{children:l.cacheRead}),o.jsx(me.NumberCell,{children:l.cacheWrite}),o.jsx(me.NumberCell,{highlight:!0,children:l.cost!=null?bg(l.cost,l.costUnit):"—"})]});return c?o.jsx(me.RowLink,{to:c,LinkComponent:a,children:u},l.model):o.jsx(me.RowStatic,{children:u},l.model)})]}):o.jsx(Ut.NoData,{message:"No model usage data yet"})})]})}function Vrs(){const e=We(),{filters:t,filterKey:n}=Em();return wt({queryKey:["metrics","model-usage-cost",n],queryFn:async()=>{const[r,s,a,i]=await Promise.all(["mastra_model_total_input_tokens","mastra_model_total_output_tokens","mastra_model_input_cache_read_tokens","mastra_model_input_cache_write_tokens"].map(d=>e.getMetricBreakdown({name:[d],groupBy:["model"],aggregation:"sum",orderDirection:"DESC",filters:t}))),l=new Map,c=d=>J4(l,d,()=>({input:0,output:0,cacheRead:0,cacheWrite:0,cost:null,costUnit:null})),u=(d,f)=>{f.estimatedCost!=null&&(d.cost=(d.cost??0)+f.estimatedCost,f.costUnit&&(d.costUnit=f.costUnit))};for(const d of r.groups){const f=d.dimensions.model??"unknown",p=c(f);p.input=d.value,u(p,d)}for(const d of s.groups){const f=d.dimensions.model??"unknown",p=c(f);p.output=d.value,u(p,d)}for(const d of a.groups){const f=d.dimensions.model??"unknown",p=c(f);p.cacheRead=d.value}for(const d of i.groups){const f=d.dimensions.model??"unknown",p=c(f);p.cacheWrite=d.value}return Array.from(l.entries()).map(([d,f])=>({model:d,input:wc(f.input),output:wc(f.output),cacheRead:wc(f.cacheRead),cacheWrite:wc(f.cacheWrite),cost:f.cost,costUnit:f.costUnit})).sort((d,f)=>d.model.localeCompare(f.model))}})}function Hrs(){const{data:e,isLoading:t,isError:n}=Vrs(),{getTracesHref:r}=jI(),{Link:s}=yn();return o.jsx(qrs,{rows:e,isLoading:t,isError:n,LinkComponent:s,getRowHref:()=>r({rootEntityType:Os.AGENT}),actions:o.jsx(K4,{href:r({rootEntityType:Os.AGENT}),LinkComponent:s})})}function Wrs(e){return e==="tokens"||e==="cost"}function Zrs({data:e,isLoading:t,isError:n,getRowHref:r,actions:s,LinkComponent:a}){const[i,l]=g.useState("tokens"),c=e??[],u=c.length>0,d=c.reduce((b,S)=>b+S.total,0),f=c.filter(b=>b.cost!=null&&b.cost>0),p=new Set(f.map(b=>b.costUnit??"usd")),h=p.size<=1,m=h?[...p][0]??"usd":null,v=h?f.reduce((b,S)=>b+(S.cost??0),0):0,y=h&&v>0;return o.jsxs(Ut,{children:[o.jsxs(Ut.TopBar,{children:[o.jsx(Ut.TitleAndDescription,{title:"Token Usage by Agent",description:"Token consumption grouped by agent."}),u&&(i==="cost"&&y?o.jsx(Ut.Summary,{value:bg(v,m),label:"Total cost"}):o.jsx(Ut.Summary,{value:wc(d),label:"Total tokens"})),u&&s?o.jsx(Ut.Actions,{children:s}):null]}),t?o.jsx(Ut.Loading,{}):n?o.jsx(Ut.Error,{message:"Failed to load token usage data"}):o.jsx(Ut.Content,{children:u?o.jsxs(cu,{defaultTab:"tokens",value:i,onValueChange:b=>{Wrs(b)&&l(b)},className:"grid grid-rows-[auto_1fr] overflow-y-auto h-full",children:[o.jsxs(uu,{children:[o.jsx(qr,{value:"tokens",children:"Tokens"}),o.jsx(qr,{value:"cost",children:"Cost"})]}),o.jsx(fs,{value:"tokens",children:o.jsx(uN,{LinkComponent:a,data:c.map(b=>({name:b.name,values:[b.input,b.output],href:r?.(b)})),segments:[{label:"Input",color:Pp.blueDark},{label:"Output",color:Pp.blue}],maxVal:Math.max(...c.map(b=>b.input+b.output)),fmt:wc})}),o.jsx(fs,{value:"cost",children:y?o.jsx(uN,{LinkComponent:a,data:f.slice().sort((b,S)=>(S.cost??0)-(b.cost??0)).map(b=>({name:b.name,values:[b.cost],href:r?.(b)})),segments:[{label:"Cost",color:Pp.purple}],maxVal:Math.max(...f.map(b=>b.cost??0)),fmt:b=>bg(b,m)}):o.jsx(Ut.NoData,{message:"No cost data yet"})})]}):o.jsx(Ut.NoData,{message:"No token usage data yet"})})]})}function Grs(){const e=We(),{filters:t,filterKey:n}=Em();return wt({queryKey:["metrics","token-usage-by-agent",n],queryFn:async()=>{const r={groupBy:["entityName"],aggregation:"sum",orderDirection:"DESC",filters:t},[s,a]=await Promise.all([e.getMetricBreakdown({...r,name:["mastra_model_total_input_tokens"]}),e.getMetricBreakdown({...r,name:["mastra_model_total_output_tokens"]})]),i=new Map,l=u=>J4(i,u,()=>({input:0,output:0,cost:null,costUnit:null})),c=(u,d)=>{d.estimatedCost!=null&&(u.cost=(u.cost??0)+d.estimatedCost,d.costUnit&&(u.costUnit=d.costUnit))};for(const u of s.groups){const d=u.dimensions.entityName??"unknown",f=l(d);f.input=u.value,c(f,u)}for(const u of a.groups){const d=u.dimensions.entityName??"unknown",f=l(d);f.output=u.value,c(f,u)}return Array.from(i.entries()).map(([u,d])=>({name:u,input:d.input,output:d.output,total:d.input+d.output,cost:d.cost,costUnit:d.costUnit})).sort((u,d)=>d.total-u.total)}})}function Qrs(){const{data:e,isLoading:t,isError:n}=Grs(),{getTracesHref:r}=jI(),{Link:s}=yn();return o.jsx(Zrs,{data:e,isLoading:t,isError:n,LinkComponent:s,getRowHref:a=>r({rootEntityType:Os.AGENT,entityName:a.name}),actions:o.jsx(K4,{href:r({rootEntityType:Os.AGENT}),LinkComponent:s})})}function Zve(e,t=wc){return n=>({value:t(n.reduce((r,s)=>r+(typeof s[e]=="number"?s[e]:0),0))})}const Yrs=[{dataKey:"input",label:"Input tokens",color:Pp.blue,aggregate:Zve("input")},{dataKey:"output",label:"Output tokens",color:Pp.yellow,aggregate:Zve("output")}];function Xrs(e){return e==="tokens"||e==="cost"}function Krs({data:e,interval:t="1d",isLoading:n,isError:r,actions:s}){const[a,i]=g.useState("tokens"),l=e??[],c=l.map(k=>({...k})),u=l.length>0,d=l.reduce((k,_)=>k+_.total,0),f=l.filter(k=>k.cost!=null&&k.cost>0),p=f.map(k=>({...k})),h=new Set(f.map(k=>k.costUnit).filter(k=>!!k)),m=h.size===1&&f.every(k=>k.costUnit!=null),v=m?[...h][0]??null:null,y=m?f.reduce((k,_)=>k+(_.cost??0),0):0,b=m&&y>0,S=t==="1h"?"Input and output tokens per hour.":"Input and output tokens per day.",w=[{dataKey:"cost",label:"Cost",color:Pp.purple,aggregate:Zve("cost",k=>bg(k,v))}];return o.jsxs(Ut,{children:[o.jsxs(Ut.TopBar,{children:[o.jsx(Ut.TitleAndDescription,{title:"Token usage over time",description:S}),u&&(a==="cost"&&b?o.jsx(Ut.Summary,{value:bg(y,v),label:"Total cost"}):o.jsx(Ut.Summary,{value:wc(d),label:"Total tokens"})),u&&s?o.jsx(Ut.Actions,{children:s}):null]}),n?o.jsx(Ut.Loading,{}):r?o.jsx(Ut.Error,{message:"Failed to load token usage timeline"}):o.jsx(Ut.Content,{children:u?o.jsxs(cu,{defaultTab:"tokens",value:a,onValueChange:k=>{Xrs(k)&&i(k)},className:"overflow-visible",children:[o.jsxs(uu,{children:[o.jsx(qr,{value:"tokens",children:"Tokens"}),o.jsx(qr,{value:"cost",children:"Cost"})]}),o.jsx(fs,{value:"tokens",children:o.jsx(LU,{data:c,series:Yrs})}),o.jsx(fs,{value:"cost",children:b?o.jsx(LU,{data:p,series:w}):o.jsx(Ut.NoData,{message:"No cost data yet"})})]}):o.jsx(Ut.NoData,{message:"No token usage data yet"})})]})}function Jrs(e){return e==="24h"?"1h":"1d"}function ess(e,t){return t==="1h"?e.toLocaleTimeString("en-US",{hour:"2-digit",minute:"2-digit",hour12:!1}):e.toLocaleDateString("en-US",{month:"short",day:"2-digit"})}function WQe(e,t,n){for(const r of t?.points??[]){const s=new Date(r.timestamp).getTime();if(!Number.isFinite(s))continue;const a=e.get(s)??{tsMs:s,input:0,output:0,cost:null,costUnits:new Set,hasUnknownCostUnit:!1};a[n]+=r.value,r.estimatedCost!=null&&(a.cost=(a.cost??0)+r.estimatedCost,t?.costUnit?a.costUnits.add(t.costUnit):a.hasUnknownCostUnit=!0),e.set(s,a)}}function tss(e){return e.cost==null||e.hasUnknownCostUnit||e.costUnits.size!==1?null:[...e.costUnits][0]??null}function nss(){const e=We(),{datePreset:t,filters:n,filterKey:r}=Em(),s=Jrs(t);return wt({queryKey:["metrics","token-usage-timeseries",r,s],queryFn:async()=>{const[a,i]=await Promise.all([e.getMetricTimeSeries({name:["mastra_model_total_input_tokens"],interval:s,aggregation:"sum",filters:n}),e.getMetricTimeSeries({name:["mastra_model_total_output_tokens"],interval:s,aggregation:"sum",filters:n})]),l=new Map;return WQe(l,a.series[0],"input"),WQe(l,i.series[0],"output"),{data:Array.from(l.values()).sort((u,d)=>u.tsMs-d.tsMs).map(u=>{const d=new Date(u.tsMs);return{time:ess(d,s),tsMs:u.tsMs,input:u.input,output:u.output,total:u.input+u.output,cost:u.cost,costUnit:tss(u)}}),interval:s}}})}function rss(){const{data:e,isLoading:t,isError:n}=nss(),{getTracesHref:r}=jI(),{Link:s}=yn();return o.jsx(Krs,{data:e?.data,interval:e?.interval,isLoading:t,isError:n,actions:o.jsx(K4,{href:r(),LinkComponent:s})})}function cse({data:e,rowHrefs:t,errorHrefs:n,LinkComponent:r}){return o.jsx(uN,{LinkComponent:r,data:e.map(s=>{const a=n?.(s),i=t?.(s);return a?{name:s.name,values:[s.completed,s.errors],hrefs:[i,a]}:{name:s.name,values:[s.completed,s.errors],href:i}}),segments:[{label:"Completed",color:Pp.blueDark},{label:"Errors",color:Pp.pink}],maxVal:Math.max(...e.map(s=>s.completed+s.errors)),fmt:wc})}function sss({data:e,isLoading:t,isError:n,getRowHref:r,getErrorSegmentHref:s,actions:a,LinkComponent:i}){const[l,c]=g.useState("agents"),u=typeof a=="function"?a(l):a,d=!!e&&(e.agentData.length>0||e.workflowData.length>0||e.toolData.length>0),f=e?[...e.agentData,...e.workflowData,...e.toolData].reduce((m,v)=>m+v.completed+v.errors,0):0,p=m=>r?v=>r(m,v):void 0,h=m=>s?v=>s(m,v):void 0;return o.jsxs(Ut,{children:[o.jsxs(Ut.TopBar,{children:[o.jsx(Ut.TitleAndDescription,{title:"Trace Volume",description:"Runs and call counts."}),d&&o.jsx(Ut.Summary,{value:wc(f),label:"Total runs"}),u?o.jsx(Ut.Actions,{children:u}):null]}),t?o.jsx(Ut.Loading,{}):n?o.jsx(Ut.Error,{message:"Failed to load trace volume data"}):o.jsx(Ut.Content,{children:d?o.jsxs(cu,{value:l,onValueChange:c,defaultTab:"agents",className:"grid grid-rows-[auto_1fr] overflow-y-auto h-full",children:[o.jsxs(uu,{children:[o.jsx(qr,{value:"agents",children:"Agents"}),o.jsx(qr,{value:"workflows",children:"Workflows"}),o.jsx(qr,{value:"tools",children:"Tools"})]}),o.jsx(fs,{value:"agents",children:e.agentData.length>0?o.jsx(cse,{data:e.agentData,rowHrefs:p("agents"),errorHrefs:h("agents"),LinkComponent:i}):o.jsx(Ut.NoData,{message:"No agent data yet"})}),o.jsx(fs,{value:"workflows",children:e.workflowData.length>0?o.jsx(cse,{data:e.workflowData,rowHrefs:p("workflows"),errorHrefs:h("workflows"),LinkComponent:i}):o.jsx(Ut.NoData,{message:"No workflow data yet"})}),o.jsx(fs,{value:"tools",children:e.toolData.length>0?o.jsx(cse,{data:e.toolData,rowHrefs:p("tools"),errorHrefs:h("tools"),LinkComponent:i}):o.jsx(Ut.NoData,{message:"No tool data yet"})})]}):o.jsx(Ut.NoData,{message:"No trace volume data yet"})})]})}async function use(e,t,n){const r=await e.getMetricBreakdown({name:[t],groupBy:["entityName","status"],aggregation:"count",orderDirection:"DESC",filters:n}),s=new Map;for(const a of r.groups){const i=a.dimensions.entityName??"unknown",l=a.dimensions.status??"ok",c=J4(s,i,()=>({completed:0,errors:0}));l==="error"?c.errors+=a.value:c.completed+=a.value}return Array.from(s.entries()).map(([a,i])=>({name:a,...i})).sort((a,i)=>i.completed+i.errors-(a.completed+a.errors))}function ass(){const e=We(),{filters:t,filterKey:n}=Em();return wt({queryKey:["metrics","trace-volume",n],queryFn:async()=>{const[r,s,a]=await Promise.all([use(e,"mastra_agent_duration_ms",t),use(e,"mastra_workflow_duration_ms",t),use(e,"mastra_tool_duration_ms",t)]);return{agentData:r,workflowData:s,toolData:a}}})}const cF={agents:Os.AGENT,workflows:Os.WORKFLOW_RUN,tools:Os.TOOL};function iss(){const{data:e,isLoading:t,isError:n}=ass(),{getTracesHref:r,getLogsHref:s}=jI(),{Link:a}=yn();return o.jsx(sss,{data:e,isLoading:t,isError:n,LinkComponent:a,getRowHref:(i,l)=>r({rootEntityType:cF[i],entityName:l.name}),getErrorSegmentHref:(i,l)=>l.errors>0?s({rootEntityType:cF[i],entityName:l.name,status:"error"}):void 0,actions:i=>o.jsxs(o.Fragment,{children:[o.jsx(K4,{href:r({rootEntityType:cF[i]}),LinkComponent:a}),o.jsx(brs,{href:s({rootEntityType:cF[i],status:"error"}),LinkComponent:a})]})})}const oss=new Set(["ObservabilityStorageClickhouseVNext","ObservabilityStorageDuckDB","ObservabilityInMemory","ObservabilitySpanner","ObservabilityStoragePostgresVNext"]),dse="period",uF="dateFrom",dF="dateTo";function lss(){const[e,t]=ga(),n=e.get(dse),r=drs(n)?n:"24h",s=g.useMemo(()=>{if(r!=="custom")return;const d=h=>{if(!h)return;const m=new Date(h);return Number.isNaN(m.getTime())?void 0:m},f=d(e.get(uF)),p=d(e.get(dF));if(!(!f&&!p))return{from:f,to:p}},[r,e.toString()]),a=g.useMemo(()=>srs(e),[e.toString()]),i=g.useCallback(d=>{t(f=>{const p=new URLSearchParams(f);return d==="24h"?p.delete(dse):p.set(dse,d),d!=="custom"&&(p.delete(uF),p.delete(dF)),p},{replace:!0})},[t]),l=g.useCallback(d=>{t(f=>{const p=new URLSearchParams(f);return d?.from?p.set(uF,d.from.toISOString()):p.delete(uF),d?.to?p.set(dF,d.to.toISOString()):p.delete(dF),p},{replace:!0})},[t]),c=g.useCallback(d=>{t(f=>{const p=new URLSearchParams(f);return irs(p,d),p},{replace:!0})},[t]),u=g.useRef(!1);return g.useEffect(()=>{if(u.current||(u.current=!0,nrs(e)))return;const d=z9t();d&&t(f=>{const p=new URLSearchParams(f);for(const[h,m]of d)p.append(h,m);return p},{replace:!0})},[]),o.jsx(prs,{preset:r,filterTokens:a,onPresetChange:i,onFilterTokensChange:c,customRange:s,onCustomRangeChange:l,children:o.jsx(css,{})})}function css(){const[e]=ga(),{error:t,isLoading:n}=q9t(),{filterTokens:r,setFilterTokens:s}=tG(),[a,i]=g.useState(),{data:l,isLoading:c}=a4(),u=l?.observabilityStorageType,d=u?oss.has(u):!1,f=u==="ObservabilityInMemory",{data:p,isLoading:h}=gTe(),{data:m,isLoading:v}=pTe(),{data:y,isLoading:b}=mTe(),{data:S,isLoading:w}=hTe(),k=g.useMemo(()=>rrs({availableTags:p??[],availableEntityNames:m??[],availableServiceNames:y??[],availableEnvironments:S??[],loading:{tags:h,entityNames:v,serviceNames:b,environments:w}}),[p,m,y,S,h,v,b,w]),[_,C]=g.useState(()=>z9t()!==null),E=g.useCallback(()=>{ers(e),C(!0),De.success("Filters setting for Metrics saved")},[e]),j=g.useCallback(()=>{trs(),C(!1),De.success("Filters setting for Metrics cleared up")},[]),N=g.useCallback(()=>{s([])},[s]),I=g.useCallback(()=>{const R=r.map(P=>{const L=k.find(M=>M.id===P.fieldId);return L?L.kind==="text"?{fieldId:P.fieldId,value:""}:L.kind==="pick-multi"?L.multi?{fieldId:P.fieldId,value:[]}:{fieldId:P.fieldId,value:"Any"}:L.kind==="multi-select"?{fieldId:P.fieldId,value:[]}:P:P});s(R)},[k,r,s]);return t&&gs(t)?o.jsx(lr,{children:o.jsx(Vs,{})}):t&&ys(t)?o.jsx(lr,{children:o.jsx(Ds,{resource:"metrics"})}):t?o.jsx(lr,{children:o.jsx(zi,{title:"Failed to load metrics",message:t.message})}):o.jsxs(Lt,{width:"wide",height:"full",children:[o.jsxs(Lt.TopArea,{children:[o.jsx(Lt.Row,{children:o.jsxs(Lt.Column,{className:"flex flex-wrap items-start justify-start gap-2",children:[o.jsx(vrs,{}),o.jsx(cTe,{fields:k,tokens:r,onTokensChange:s,disabled:n,onStartTextFilter:i})]})}),o.jsx(Brs,{isLoading:n,filterFields:k,filterTokens:r,onFilterTokensChange:s,onClear:I,onRemoveAll:N,onSave:E,onRemoveSaved:_?j:void 0,autoFocusFilterFieldId:a})]}),c?null:d?o.jsxs("div",{className:"grid gap-8 content-start pb-10",children:[f&&o.jsx(In,{variant:"info",title:"Metrics are not persisted",children:o.jsx(In.Message,{children:"This project uses in-memory storage for observability. Metrics will be lost on every server restart. For persistent metrics, switch the observability storage to ClickHouse, DuckDB, Postgres v-next, or Spanner."})}),o.jsxs(qve,{children:[o.jsx(Mrs,{}),o.jsx(Drs,{}),o.jsx(Lrs,{}),o.jsx(Frs,{}),o.jsx(zrs,{})]}),o.jsxs(qve,{children:[o.jsx(Hrs,{}),o.jsx(Qrs,{}),o.jsx(rss,{}),o.jsx(Irs,{}),o.jsx(iss,{}),o.jsx(Crs,{})]})]}):o.jsx("div",{className:"flex h-full items-center justify-center",children:o.jsx(Cr,{iconSlot:o.jsx(Of,{}),titleSlot:"Metrics are not available with your current storage",descriptionSlot:"Metrics require ClickHouse, DuckDB, Postgres v-next, Spanner, or in-memory storage for observability. Other relational databases (LibSQL, MSSQL) and document stores (MongoDB) do not support metrics collection. To enable metrics on an existing project, switch the observability storage in the Mastra configuration.",actionSlot:o.jsxs(de,{variant:"ghost",as:"a",href:"https://mastra.ai/docs/observability/metrics/overview",target:"_blank",rel:"noopener noreferrer",children:["Metrics Documentation ",o.jsx(_a,{})]})})})]})}function uss(){const{paths:e}=yn(),{data:t,isLoading:n,error:r}=c6t(),{isCmsAvailable:s}=Y1(),[a,i]=g.useState(""),l=t?.promptBlocks??[];return r&&gs(r)?o.jsx(lr,{children:o.jsx(Vs,{})}):r&&ys(r)?o.jsx(lr,{children:o.jsx(Ds,{resource:"prompt blocks"})}):r?o.jsx(lr,{children:o.jsx(zi,{title:"Failed to load prompt blocks",message:r.message})}):l.length===0&&!n?o.jsx(lr,{children:o.jsx(WZr,{})}):o.jsxs(Lt,{children:[o.jsx(Lt.TopArea,{children:o.jsxs(Lt.Row,{align:"center",stack:"responsive",children:[o.jsx("div",{className:"max-w-120 flex-1",children:o.jsx(jf,{onSearch:i,label:"Filter prompts",placeholder:"Filter by name or description"})}),s&&o.jsxs(de,{as:Ba,to:e.cmsPromptBlockCreateLink(),variant:"primary",className:"shrink-0",children:[o.jsx(Vr,{}),"Create Prompt"]})]})}),o.jsx(HZr,{promptBlocks:l,isLoading:n,search:a})]})}function dss(){return o.jsx(Lt,{width:"narrow",children:o.jsx(Lt.MainArea,{children:o.jsx(Z7r,{children:o.jsx(mve,{})})})})}const fss=[{title:"Mastra APIs",description:"Explore and test the available REST API endpoints with the interactive Swagger UI.",icon:Wcn,href:"/swagger-ui",external:!1},{title:"Documentation",description:"Read the official Mastra documentation for guides, references, and tutorials.",icon:jlt,href:"https://mastra.ai/en/docs",external:!0},{title:"Github",description:"Browse the source code, report issues, and contribute to the Mastra project.",icon:_a,href:"https://github.com/mastra-ai/mastra",external:!0},{title:"Community",description:"Join the Mastra Discord community for help, discussion, and collaboration.",icon:Yj,href:"https://discord.gg/BTYqqHKUrf",external:!0},{title:"Share with your team",description:"Running Mastra Studio locally? Deploy to the cloud so your team can collaborate.",icon:Mlt,href:"https://mastra.ai/cloud",external:!0},{title:"Talk to our Sales team",description:"Get a custom demo, discuss on-prem deployments, and how we can help you accelerate getting agents into production.",icon:Tlt,href:"https://mastra.ai/contact?ref=studio",external:!0}];function pss(){return o.jsx(Lt,{width:"narrow",children:o.jsx(Lt.MainArea,{children:o.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4 max-w-3xl",children:fss.map(e=>o.jsxs("a",{href:e.href,...e.external?{target:"_blank",rel:"noreferrer"}:{},className:"group flex flex-col gap-3 rounded-lg border border-border1 bg-surface2 p-5 transition-colors hover:border-accent1 hover:bg-surface3",children:[o.jsxs("div",{className:"flex items-center gap-2.5",children:[o.jsx(e.icon,{className:"h-5 w-5 text-icon3 group-hover:text-accent1 transition-colors"}),o.jsx("span",{className:"text-ui-md font-medium text-text1",children:e.title}),e.external&&o.jsx(_a,{className:"h-3.5 w-3.5 text-icon3 ml-auto opacity-0 group-hover:opacity-100 transition-opacity"})]}),o.jsx("p",{className:"text-ui-sm text-text3 leading-relaxed",children:e.description})]},e.href))})})})}function hss(){const{data:e={},isLoading:t,error:n}=ih(),[r,s]=g.useState(""),[a,i]=g.useState("all");if(n&&gs(n))return o.jsx(lr,{children:o.jsx(Vs,{})});if(n&&ys(n))return o.jsx(lr,{children:o.jsx(Ds,{resource:"scorers"})});if(n)return o.jsx(lr,{children:o.jsx(zi,{title:"Failed to load scorers",message:n.message})});if(Object.keys(e).length===0&&!t)return o.jsx(lr,{children:o.jsx(aWr,{})});const l=a!=="all"||r!=="",c=()=>{s(""),i("all")};return o.jsxs(Lt,{children:[o.jsx(Lt.TopArea,{children:o.jsx(oWr,{search:r,onSearchChange:s,sourceFilter:a,onSourceFilterChange:i,onReset:c,hasActiveFilters:l})}),o.jsx(sWr,{scorers:e,isLoading:t,search:r,sourceFilter:a})]})}function mss(){const{scorerId:e}=ur(),[t,n]=ga(),r=t.get("scoreId")??void 0,[s,a]=g.useState(r),[i,l]=g.useState({value:"all",label:"All Entities",type:"ALL"}),{scorer:c,error:u}=$Hr(e),{data:d={},isLoading:f,error:p}=km(),{isLoading:h,error:m}=Uy(),{data:v=[],isLoading:y,error:b,isFetchingNextPage:S,hasNextPage:w,setEndOfListElement:k}=PHr({scorerId:e,entityId:i?.value==="all"?void 0:i?.value,entityType:i?.type==="ALL"?void 0:i?.type}),_=g.useMemo(()=>c?.agentIds?.filter(B=>d[B]).map(B=>({value:B,label:d[B].name,type:"AGENT"}))||[],[c?.agentIds,d]),C=g.useMemo(()=>c?.workflowIds?.map(B=>({value:B,label:B,type:"WORKFLOW"}))||[],[c?.workflowIds]),E=g.useMemo(()=>[{value:"all",label:"All Entities",type:"ALL"},..._,...C],[_,C]),j=t.get("entity")??"all",N=E.find(B=>B.value===j);N&&N.value!==i?.value&&l(N),g.useEffect(()=>{if(u){const B=u instanceof Error?u.message:"Failed to load scorer";De.error(`Error loading scorer: ${B}`)}},[u]),g.useEffect(()=>{if(p){const B=p instanceof Error?p.message:"Failed to load agents";De.error(`Error loading agents: ${B}`)}},[p]),g.useEffect(()=>{if(m){const B=m instanceof Error?m.message:"Failed to load workflows";De.error(`Error loading workflows: ${B}`)}},[m]);const I=B=>{B?.value&&n(D=>{const Q=new URLSearchParams(D);return Q.set("entity",B.value),Q})};g.useEffect(()=>{const B=t.get("scoreId")??void 0;if(B===s)return;if(!B){a(void 0);return}v.find(Q=>Q.id===B)&&a(B)},[t,v]);const R=g.useCallback(B=>{a(B||void 0),n(D=>{const Q=new URLSearchParams(D);return B?Q.set("scoreId",B):Q.delete("scoreId"),Q})},[n]);if(!c)return null;const P=gs(u)||gs(p)||gs(m),L=u&&ys(u),M=!P&&!L&&(u||p||m),q=!y&&v.length===0,H=i?.value!=="all",F=c?.scorer?.source==="stored"?o.jsx(Iy,{owner:"scorer-detail",children:o.jsxs(de,{variant:"default",as:Ba,to:`/cms/scorers/${e}/edit`,size:"sm",children:[o.jsx(Lp,{})," Edit"]})}):null;if(P||L||M||q&&!H){const B=(u instanceof Error?u.message:void 0)??(p instanceof Error?p.message:void 0)??(m instanceof Error?m.message:void 0)??"An unexpected error occurred";return o.jsxs(Lt,{width:"wide",height:"full",children:[F,o.jsx(Lt.MainArea,{isCentered:!0,children:P?o.jsx(Vs,{}):L?o.jsx(Ds,{resource:"scorers"}):M?o.jsx(zi,{title:"Failed to load scorer",message:B}):o.jsx(THr,{})})]})}return o.jsxs(Lt,{width:"wide",children:[F,o.jsx(Lt.TopArea,{children:o.jsx(NHr,{selectedEntity:i,entityOptions:E,onEntityChange:I,onReset:()=>{n(B=>{const D=new URLSearchParams(B);return D.set("entity","all"),D})},isLoading:y||f||h})}),o.jsx(jHr,{scores:v,isLoading:y,selectedScoreId:s,isFetchingNextPage:S,hasNextPage:w,setEndOfListElement:k,onScoreClick:R,errorMsg:b?.message})]})}function gss({label:e,description:t,htmlFor:n,className:r,children:s}){return o.jsxs("div",{className:K("flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",r),"data-slot":"settings-row",children:[o.jsxs("div",{children:[n?o.jsx(Rt,{htmlFor:n,className:"text-sm font-medium",children:e}):o.jsx("p",{className:"text-sm font-medium",children:e}),t&&o.jsx("p",{className:"text-sm text-neutral3",children:t})]}),s]})}const Z9t=[{value:"dark",label:"Dark",Icon:wdn},{value:"light",label:"Light",Icon:Nfn},{value:"system",label:"System",Icon:Wlt}],vss=e=>Z9t.some(t=>t.value===e);function yss({option:e}){const{Icon:t}=e;return o.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-center gap-2",children:[o.jsx(t,{"aria-hidden":"true",className:"h-4 w-4 shrink-0 opacity-70"}),o.jsx("span",{className:"min-w-0 truncate",children:e.label})]})}const bss=()=>{const{baseUrl:e,headers:t,apiPrefix:n}=qxe(),{theme:r,setTheme:s}=PN();return o.jsx(Lt,{width:"narrow",children:o.jsxs(Lt.MainArea,{className:"flex flex-col gap-5 mt-6",children:[o.jsx(Yge,{title:"Theme",description:"Customize the appearance of the studio.",children:o.jsx(gss,{label:"Theme mode",htmlFor:"theme",children:o.jsxs(da,{value:r,onValueChange:a=>{vss(a)&&s(a)},children:[o.jsx(pa,{id:"theme",className:"w-full sm:w-48",children:o.jsx(fa,{className:"inline-flex min-w-0 max-w-full items-center"})}),o.jsx(ha,{children:Z9t.map(a=>o.jsx(Lr,{value:a.value,children:o.jsx(yss,{option:a})},a.value))})]})})}),o.jsx(Yge,{title:"Mastra Connection",description:"Configure the Mastra instance URL, API prefix, and request headers used by the studio.",children:o.jsx(lRt,{initialConfig:{baseUrl:e,headers:t,apiPrefix:n}})})]})})};function xss(){const[e]=ga(),t=bs(),n=e.get("redirect")||"/",r=()=>{n.startsWith("http")?window.location.href=n:t(n,{replace:!0})};return o.jsx(D9t,{redirectUri:n,onSuccess:r,initialMode:"signup"})}const G9t=e=>o.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 15 15",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:[o.jsx("g",{clipPath:"url(#clip0_21999_22095)",children:o.jsx("path",{d:"M7.5 0.75C3.6325 0.75 0.5 3.8825 0.5 7.75C0.5 10.8475 2.50375 13.4637 5.28625 14.3912C5.63625 14.4525 5.7675 14.2425 5.7675 14.0587C5.7675 13.8925 5.75875 13.3412 5.75875 12.755C4 13.0787 3.545 12.3262 3.405 11.9325C3.32625 11.7312 2.985 11.11 2.6875 10.9437C2.4425 10.8125 2.0925 10.4887 2.67875 10.48C3.23 10.4712 3.62375 10.9875 3.755 11.1975C4.385 12.2562 5.39125 11.9587 5.79375 11.775C5.855 11.32 6.03875 11.0137 6.24 10.8387C4.6825 10.6637 3.055 10.06 3.055 7.3825C3.055 6.62125 3.32625 5.99125 3.7725 5.50125C3.7025 5.32625 3.4575 4.60875 3.8425 3.64625C3.8425 3.64625 4.42875 3.4625 5.7675 4.36375C6.3275 4.20625 6.9225 4.1275 7.5175 4.1275C8.1125 4.1275 8.7075 4.20625 9.2675 4.36375C10.6062 3.45375 11.1925 3.64625 11.1925 3.64625C11.5775 4.60875 11.3325 5.32625 11.2625 5.50125C11.7087 5.99125 11.98 6.6125 11.98 7.3825C11.98 10.0687 10.3438 10.6637 8.78625 10.8387C9.04 11.0575 9.25875 11.4775 9.25875 12.1337C9.25875 13.07 9.25 13.8225 9.25 14.0587C9.25 14.2425 9.38125 14.4612 9.73125 14.3912C11.1209 13.9221 12.3284 13.029 13.1839 11.8377C14.0393 10.6463 14.4996 9.21668 14.5 7.75C14.5 3.8825 11.3675 0.75 7.5 0.75Z",fill:"currentColor"})}),o.jsx("defs",{children:o.jsx("clipPath",{id:"clip0_21999_22095",children:o.jsx("rect",{width:"14",height:"14",fill:"currentColor",transform:"translate(0.5 0.75)"})})})]});function wss(e){return e.replace(/\/$/,"").split("/").pop()}function nG({children:e,className:t}){return o.jsx("div",{className:K("border border-border1 rounded-lg mt-12 py-8 lg:min-h-[25rem] transition-height px-4 lg:px-12",t),children:e})}function Sss({templates:e,linkComponent:t,className:n,isLoading:r}){const s=t||"a";return r?o.jsx("div",{className:K("grid gap-y-4",n),children:Array.from({length:5}).map((a,i)=>o.jsx("div",{className:"h-16 bg-surface3 animate-pulse rounded-lg"},i))}):o.jsx("div",{className:K("grid gap-y-4",n),children:e.map(a=>{const i=a?.agents||a?.tools||a?.networks||a?.workflows||a?.mcp;return o.jsxs("article",{className:K("border border-border1 rounded-lg overflow-hidden w-full grid grid-cols-[1fr_auto] bg-surface3 transition-colors hover:bg-surface4"),children:[o.jsxs(s,{to:`/templates/${a.slug}`,className:K("grid [&:hover_p]:text-neutral5",{"grid-cols-[8rem_1fr] lg:grid-cols-[12rem_1fr]":a.imageURL}),children:[a.imageURL&&o.jsx("div",{className:K("overflow-hidden"),children:o.jsx("div",{className:"w-full h-full bg-cover thumb transition-scale duration-150",style:{backgroundImage:`url(${a.imageURL})`}})}),o.jsxs("div",{className:K("grid py-3 px-6 w-full gap-0.5","[&_svg]:w-[1em] [&_svg]:h-[1em] [&_svg]:text-neutral3"),children:[o.jsx("h2",{className:"text-ui-lg text-neutral5",children:a.title}),o.jsx("p",{className:"text-ui-md text-neutral4 transition-colors duration-500",children:a.description}),o.jsxs("div",{className:"hidden 2xl:flex text-neutral3 text-ui-md flex-wrap items-center gap-4 mt-3",children:[i&&o.jsxs("ul",{className:K("flex gap-4 text-ui-md text-neutral3 m-0 p-0 list-none","[&>li]:flex [&>li]:items-center [&>li]:gap-0.5 text-neutral4"),children:[a?.agents&&a.agents.length>0&&o.jsxs("li",{children:[o.jsx(sl,{})," ",a.agents.length]}),a?.tools&&a.tools.length>0&&o.jsxs("li",{children:[o.jsx(eh,{})," ",a.tools.length]}),a?.networks&&a.networks.length>0&&o.jsxs("li",{children:[o.jsx(Zlt,{})," ",a.networks.length]}),a?.workflows&&a.workflows.length>0&&o.jsxs("li",{children:[o.jsx(vD,{})," ",a.workflows.length]}),a?.mcp&&a.mcp.length>0&&o.jsxs("li",{children:[o.jsx(B_,{})," ",a.mcp.length]})]}),i&&a.supportedProviders&&o.jsx("small",{children:"|"}),o.jsx("div",{className:"flex items-center text-neutral3 gap-4",children:a.supportedProviders.map(l=>o.jsx("span",{className:"",children:l},l))})]})]})]}),o.jsx("a",{href:a.githubUrl,className:K("group items-center gap-2 text-ui-md ml-auto pr-4 hidden","lg:flex"),target:"_blank",rel:"noopener noreferrer",children:o.jsxs("span",{className:"flex items-center gap-2 px-2 py-1 rounded bg-surface1 group-hover:bg-surface2 text-neutral3 transition-colors group-hover:text-neutral5",children:[o.jsx(G9t,{})," ",wss(a.githubUrl)]})})]},a.slug)})})}function kss({tagOptions:e,selectedTag:t,providerOptions:n,selectedProvider:r,onTagChange:s,onProviderChange:a,searchTerm:i,onSearchChange:l,onReset:c,className:u,isLoading:d}){return d?o.jsxs("div",{className:K("h-[6.5rem] flex items-center gap-8","[&>div]:bg-surface3 [&>div]:w-48 [&>div]:h-8 [&>div]:animate-pulse",u),children:[o.jsx("div",{})," ",o.jsx("div",{})," ",o.jsx("div",{})]}):o.jsxs("div",{className:K("flex flex-wrap mx-auto sticky top-0 gap-4 bg-surface2 py-8",u),children:[o.jsx(BT,{name:"search-templates",label:"Search templates",labelIsHidden:!0,value:i,onChange:f=>l?.(f.target.value),placeholder:"Search Template"}),o.jsx(Sc,{label:"Filter by tag",labelIsHidden:!0,name:"filter-tag",value:t,onValueChange:s,options:e}),o.jsx(Sc,{label:"Filter by provider",labelIsHidden:!0,name:"filter-provider",value:r,onValueChange:a,options:n}),c&&o.jsxs(de,{onClick:c,children:["Reset ",o.jsx(vs,{})]})]})}function Oss(){const{data:e,isLoading:t}=wYn(),{templates:n,tags:r,providers:s}=e??{templates:[],tags:[],providers:[]},[a,i]=g.useState("all"),[l,c]=g.useState("all"),[u,d]=g.useState(""),f=[{value:"all",label:"Any tag"}];(r||[]).forEach(S=>{f.push({value:S,label:S})});const p=[{value:"all",label:"Any provider"}];(s||[]).forEach(S=>{p.push({value:S,label:S})});const h=(S,w)=>{w==="tag"?i(S):w==="provider"&&c(S)},m=S=>{d(S)},v=()=>{i("all"),c("all"),d("")},y=n.filter(S=>!(u&&!S.title.toLowerCase().includes(u)&&!S.description.toLowerCase().includes(u)||a!=="all"&&!S.tags.includes(a)||l!=="all"&&!S.supportedProviders.includes(l))),b=u||a!=="all"||l!=="all";return o.jsxs(ls,{children:[o.jsx(e0e,{children:o.jsxs(Lpt,{children:[o.jsx(Ue,{children:o.jsx(Zv,{})}),"Templates"]})}),o.jsxs("div",{className:K("overflow-y-auto w-full h-full px-8 pb-12 z-10"),children:[o.jsx(kss,{selectedTag:a,onTagChange:S=>h(S,"tag"),tagOptions:f,selectedProvider:l,onProviderChange:S=>h(S,"provider"),providerOptions:p,searchTerm:u,onSearchChange:m,onReset:b?v:void 0,className:"max-w-[80rem]",isLoading:t}),o.jsx(Sss,{templates:y,linkComponent:Ba,className:"max-w-[80rem] mx-auto",isLoading:t})]})]})}const _ss="1.50.0-alpha.1";function Css({errorMsg:e,validationErrors:t}){const n=typeof e=="string"?e:e!=null?String(e):void 0,r=n?.includes("Invalid schema for function"),s=n?.includes("validation issue")||t&&t.length>0,a=()=>s?"Template installation completed but some validation issues remain. The template may still be functional, but you should review and fix these issues.":r?"There was an issue with the AI model configuration. This may be related to the selected model or AI SDK version compatibility.":"An unexpected error occurred during template installation.",i=()=>s?{icon:o.jsx(Ep,{className:"text-yellow-500"}),title:"Template Installed with Warnings"}:{icon:o.jsx(wun,{}),title:"Template Installation Failed"},{icon:l,title:c}=i();return o.jsxs(nG,{className:"space-y-4 text-neutral3 mb-8 content-center",children:[o.jsxs("div",{className:K("grid items-center justify-items-center gap-4 content-center","[&>svg]:w-8 [&>svg]:h-8"),children:[l,o.jsxs("div",{className:"text-center space-y-2",children:[o.jsx("p",{className:"text-ui-md font-medium text-neutral5",children:c}),o.jsx("p",{className:"text-ui-md text-neutral3",children:a()})]})]}),t&&t.length>0&&o.jsxs("details",{className:"text-xs",children:[o.jsxs("summary",{className:"cursor-pointer text-neutral3 hover:text-neutral4 select-none text-center",children:["Show Validation Issues (",t.length,")"]}),o.jsx("div",{className:"mt-4 p-3 bg-gray-100 dark:bg-gray-800 rounded text-xs overflow-auto max-h-60 text-left space-y-2",children:t.map((u,d)=>o.jsxs("div",{className:"border-l-2 border-red-400 pl-2",children:[o.jsx("div",{className:"font-medium text-red-600 dark:text-red-400",children:u.type==="typescript"?"🔴 TypeScript Error":"⚠️ Lint Error"}),o.jsx("div",{className:"text-xs font-mono text-gray-700 dark:text-gray-300 mt-1 whitespace-pre-wrap wrap-break-word",children:u.message})]},d))})]}),n&&!s&&o.jsxs("details",{className:"text-xs",children:[o.jsx("summary",{className:"cursor-pointer text-neutral3 hover:text-neutral4 select-none text-center",children:"Show Details"}),o.jsx("div",{className:"mt-4 p-3 bg-gray-100 dark:bg-gray-800 rounded text-xs font-mono overflow-auto max-h-60 text-left",children:o.jsx("div",{className:"whitespace-pre-wrap wrap-break-word",children:n})})]})]})}function Ess({providerOptions:e,selectedProvider:t,onProviderChange:n,variables:r,errors:s,handleInstallTemplate:a,handleVariableChange:i,isLoadingEnvVars:l,isInstalling:c,defaultModelProvider:u,defaultModelId:d,onModelUpdate:f}){return o.jsx(nG,{children:o.jsxs("div",{className:"max-w-[40rem] my-4 p-4 lg:p-8 mx-auto gap-8 grid",children:[o.jsxs("h2",{className:K("text-neutral4 text-header-sm font-semibold flex items-center gap-2","[&>svg]:w-[1.2em] [&_svg]:h-[1.2em] [&_svg]:opacity-70"),children:["Install Template ",o.jsx(Glt,{})]}),o.jsx(Sc,{name:"template-provider",options:e,label:"Template AI Model Provider",onValueChange:n,value:t,placeholder:"Select",layout:"horizontal"}),t&&Object.entries(r||{}).length>0&&o.jsxs(o.Fragment,{children:[o.jsx("h3",{className:"text-neutral3 text-ui-md",children:"Set required Environmental Variables"}),o.jsx("div",{className:"grid grid-cols-[1fr_1fr] gap-4 items-start",children:l?o.jsxs("div",{className:K("flex items-center justify-center col-span-2 text-neutral3 text-ui-sm gap-4","[&_svg]:opacity-50 [&_svg]:w-[1.1em] [&_svg]:h-[1.1em]","animate-in fade-in duration-300"),children:[o.jsx(Gt,{})," Loading variables..."]}):Object.entries(r).map(([p,h])=>o.jsxs(g.Fragment,{children:[o.jsx(yO,{name:`env-${p}`,labelIsHidden:!0,label:"Key",value:p,disabled:!0,className:"w-full"}),o.jsx(yO,{name:p,labelIsHidden:!0,label:"Value",value:h,onChange:i,errorMsg:s.includes(p)?"Value is required.":"",autoComplete:"off",className:"w-full"})]},p))}),o.jsxs("div",{className:"border-t border-border1 pt-12 mt-3.5 relative",children:[o.jsx("div",{className:"absolute w-8 h-8 rounded-full bg-surface2 top-0 left-1/2 -translate-x-1/2 -translate-y-4 text-ui-sm text-neutral3 flex items-center justify-center",children:"And"}),o.jsx("h3",{className:"text-neutral4 text-ui-lg",children:"Set AI Model for Template Installation"}),o.jsx("p",{className:"text-neutral3 text-ui-md mt-2 mb-8",children:"This model will be used by the workflow to process and install the template"}),o.jsx(zLt,{defaultProvider:u||"",defaultModel:d||"",updateModel:f||(()=>Promise.resolve({message:"Updated"})),closeEditor:()=>{},autoSave:!0,selectProviderPlaceholder:"Provider"})]})]}),t&&!l&&o.jsx(de,{className:K("flex items-center gap-2 mt-4 justify-center text-ui-md w-full bg-surface5 min-h-10 rounded-lg text-neutral5 hover:bg-surface6 transition-colors","[&>svg]:w-[1.1em] [&_svg]:h-[1.1em] [&_svg]:text-neutral5"),onClick:a,disabled:!t||!u||!d||s.length>0||c,children:c?o.jsxs(o.Fragment,{children:[o.jsx(Gt,{className:"w-4 h-4"})," Installing..."]}):o.jsxs(o.Fragment,{children:["Install ",o.jsx(mm,{})]})})]})})}function jss({title:e,description:t,githubUrl:n,isLoading:r,infoData:s,templateSlug:a}){const i=a?`feat/install-template-${a}`:"feat/install-template-[slug]";return o.jsxs(o.Fragment,{children:[o.jsx("div",{className:K("grid mt-8 items-center"),children:o.jsxs("div",{className:K("text-header-lg flex items-center gap-3","[&>svg]:w-[1.2em] [&>svg]:h-[1.2em] [&>svg]:opacity-50",{"[&>svg]:opacity-20":r}),children:[o.jsx(Zv,{}),o.jsx("h2",{className:K({"bg-surface4 flex rounded-lg min-w-[50%]":r}),children:r?o.jsx(o.Fragment,{children:" "}):e})]})}),o.jsxs("div",{className:"grid lg:grid-cols-[1fr_1fr] gap-x-24",children:[o.jsxs("div",{className:"grid",children:[o.jsx("p",{className:K("mb-4 text-ui-md text-neutral4 mt-2 leading-7",{"bg-surface4 rounded-lg ":r}),children:r?o.jsx(o.Fragment,{children:" "}):t}),!r&&a&&o.jsxs("div",{className:K("bg-surface2 border border-surface4 rounded-lg p-4 mb-4","flex items-start gap-3"),children:[o.jsx("div",{className:"shrink-0 mt-0.5",children:o.jsx(Fx,{className:"w-[1.1em] h-[1.1em] text-blue-500"})}),o.jsxs("div",{className:"flex-1 space-y-2",children:[o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx(sbe,{className:"w-[1em] h-[1em] text-neutral4"}),o.jsx("span",{className:"text-ui-md font-medium text-neutral5",children:"A new Git branch will be created"})]}),o.jsxs("div",{className:"text-ui-sm text-neutral4 space-y-1",children:[o.jsxs("div",{children:[o.jsx("span",{className:"font-medium",children:"Branch name:"})," ",o.jsx("code",{className:"bg-surface3 px-1.5 py-0.5 rounded text-ui-sm font-mono",children:i})]}),o.jsx("div",{children:"This ensures safe installation with easy rollback if needed. Your main branch remains unchanged."})]})]})]}),n&&o.jsxs("a",{href:n,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-2 mt-auto text-neutral3 text-ui-md hover:text-neutral5",children:[o.jsx(G9t,{}),n?.split("/")?.pop()]})]}),s&&o.jsx(Bje,{data:s,labelsAreHidden:!0,isLoading:r})]})]})}function Tss(e){switch(e){case"running":return o.jsx(Gt,{});case"success":return o.jsx(vx,{});case"failed":return o.jsx(Fu,{});default:return null}}function Nss({stepId:e,step:t,isActive:n,position:r}){const s=a=>a.charAt(0).toUpperCase()+a.slice(1).replace(/-/g," ");return o.jsxs("div",{className:K("grid gap-6 grid-cols-[1fr_auto] py-3 px-4 rounded-lg",ms.all,{"border border-dashed border-neutral2 bg-surface3":n}),children:[o.jsxs("div",{className:"grid grid-cols-[auto_1fr] gap-2",children:[o.jsxs("span",{className:K("text-ui-md min-w-6 flex justify-end",ms.colors,{"text-neutral5":n||t.status==="success","text-neutral3":!n&&t.status!=="success"}),children:[r,"."]}),o.jsxs("div",{children:[o.jsx("h4",{className:K("text-ui-md",ms.colors,{"text-neutral5":n||t.status==="success","text-neutral3":!n&&t.status!=="success"}),children:s(e)}),t.description&&o.jsx("p",{className:"text-ui-md text-neutral2 -mt-0.5",children:t.description})]})]}),o.jsx("div",{className:K("w-[1.75rem] h-[1.75rem] rounded-full flex items-center justify-center self-center",ms.all,{"border border-neutral2 border-dashed":t.status==="pending","[&>svg]:text-white [&>svg]:w-4 [&>svg]:h-4":t.status!=="running","w-[1.75rem] h-[1.75rem]":t.status==="running","bg-accent1Dark shadow-glow-accent1":t.status==="success","bg-accent2Dark shadow-glow-accent2":t.status==="failed","scale-110":t.status==="success"||t.status==="failed"}),children:Tss(t.status)})]})}function Iss({currentStep:e,steps:t=[],className:n}){return o.jsx("div",{className:K(n),children:t.map((r,s)=>o.jsx(Nss,{stepId:r.id,step:r,isActive:e?.id===r.id,position:s+1},r.id))})}function Ass({steps:e}){const t=e.length,n=e.filter(r=>r.status==="success").length;return o.jsxs("div",{className:"flex justify-center flex-col gap-4 content-center w-full",children:[o.jsx("div",{className:"grid grid-cols-[0_repeat(9,1fr)] w-full",children:e.map((r,s)=>o.jsx("div",{className:K("flex justify-end items-center relative h-[2rem]",ms.colors,{"bg-accent1Dark":r.status==="success"&&e?.[s-1]?.status==="success"}),children:o.jsx("div",{className:K("w-[2rem] h-[2rem] rounded-full flex items-center justify-center self-center absolute right-0 translate-x-[50%] bg-surface3 z-10 text-neutral3 font-bold text-ui-sm",ms.all,{"border border-neutral2 border-dashed":r.status==="pending","[&>svg]:text-surface1 [&>svg]:w-[1.1rem] [&>svg]:h-[1.1rem]":r.status!=="running","bg-accent1Dark text-white shadow-glow-accent1 scale-110":r.status==="success","bg-accent2Dark text-white shadow-glow-accent2 scale-110":r.status==="failed"}),children:r.status==="running"?o.jsx(Gt,{}):s+1})},r.id))}),o.jsxs("div",{className:K("text-xs text-neutral3 text-center",ms.colors),children:[n," of ",t," steps completed"]})]})}function Rss({name:e,streamResult:t,runId:n,workflowInfo:r}){const s=t?.phase||"initializing",a=t?.payload?.workflowState,i=t?.payload?.currentStep,l=t?.error,c=a?.steps||{},u=Object.keys(c).length>0,d=v=>v==="input"||v.endsWith(".input")||v.startsWith("Mapping_")&&/[0-9a-f]{8}/.test(v)||/[0-9a-f]{8,}/.test(v)?!1:r?.allSteps?v in r.allSteps:!0,f=Object.entries(c).filter(([v,y])=>d(v)),p=f.length,h=()=>{switch(s){case"initializing":return"Preparing template installation...";case"processing":return`Installing ${e} template`;case"completed":return"Template installation completed!";case"error":return"Template installation failed";default:return"Installing template..."}},m=f.map(([v,y])=>({id:v,status:y?.status,description:y?.description,title:v.charAt(0).toUpperCase()+v.slice(1).replace(/-/g," "),isActive:i?.id===v}));return o.jsxs(nG,{className:"space-y-6 text-neutral3 mb-8 content-center",children:[o.jsxs("div",{className:"text-center",children:[o.jsx("h3",{className:"text-lg font-semibold text-neutral5",children:h()}),(t?.runId||n)&&o.jsxs("div",{className:"mt-2 text-ui-sm text-neutral3",children:["Run ID: ",t?.runId??n]})]}),u&&p>0&&!["error"].includes(s)&&o.jsx("div",{className:"max-w-[30rem] w-full mx-auto px-6",children:o.jsx(Ass,{steps:m})}),l&&s==="error"&&o.jsxs("div",{className:K("rounded-lg text-neutral5 p-6 flex items-center gap-3 text-ui-md bg-red-500/10","[&>svg]:w-6 [&>svg]:h-6 [&>svg]:opacity-70 [&>svg]:text-red-500"),children:[o.jsx(Idn,{}),l||"Something went wrong"]}),u&&o.jsx(Iss,{steps:m,currentStep:i,className:"pb-4"}),!u&&s==="initializing"&&o.jsxs("div",{className:"text-center text-sm text-neutral3 grid gap-4 justify-items-center",children:[o.jsx(Gt,{}),o.jsx("p",{children:"This may take some time..."})]})]})}function Pss({name:e,installedEntities:t}){return o.jsxs(nG,{className:K("grid items-center justify-items-center gap-4 content-center","[&>svg]:w-8 [&>svg]:h-8"),children:[o.jsx(Glt,{}),o.jsx("h2",{className:"text-header-md",children:"Done!"}),o.jsxs("p",{className:"text-ui-md text-center text-neutral3 ",children:["The ",o.jsx("b",{className:"text-neutral4",children:e})," template has been successfully installed.",t&&t.length>0&&o.jsxs(o.Fragment,{children:[o.jsx("br",{})," Installed entities are listed below."]})]}),t&&t.length>0&&o.jsx(Bje,{data:t})]})}function $ss(){const{templateSlug:e}=ur(),[t,n]=ga(),[r,s]=g.useState(""),[a,i]=g.useState(""),[l,c]=g.useState(""),[u,d]=g.useState({}),[f,p]=g.useState([]),[h,m]=g.useState(null),[v,y]=g.useState(!1),[b,S]=g.useState(""),[w,k]=g.useState(!1),[_,C]=g.useState(!1),[E,j]=g.useState([]),{data:N,isLoading:I}=SYn({repoOrSlug:e,owner:"mastra-ai"}),P=_ss?.includes("beta")??!1?"beta":"main",{data:L,isLoading:M}=kYn({repo:N?.githubUrl?new URL(N.githubUrl).pathname.split("/")[2]:`template-${e}`,owner:"mastra-ai",branch:P}),{data:q,isLoading:H}=OYn(),{mutateAsync:F,isPending:z}=_Yn(),{mutateAsync:B}=CYn(),{streamInstall:D,streamResult:Q,isStreaming:V}=jYn(q),{observeInstall:$,streamResult:U,isStreaming:Z}=TYn(q);g.useEffect(()=>{const ne=t.get("runId");ne&&!v&&!h&&!V&&!Z&&(console.info("🔄 Checking completed run after hot reload:",{runId:ne}),S(ne),B({runId:ne}).then(ue=>{const pe=ue.snapshot;if(pe?.status==="success"&&pe?.result?.success)y(!0);else if(pe?.result?.success===!1)if(pe?.result?.validationResults&&!pe?.result?.validationResults?.valid&&pe?.result?.validationResults?.remainingErrors>0){const{remainingErrors:ve,errors:ye}=pe.result.validationResults,Se=`Template installation completed but ${ve} validation issue${ve>1?"s":""} remain unresolved.`;m(Se),j(ye||[])}else{const ve=pe?.result?.message||pe?.result?.error||"Template installation failed";m(typeof ve=="string"?ve:String(ve))}}).catch(ue=>{console.error("❌ Failed to fetch run details:",ue),m("Failed to retrieve installation status after reload")}))},[t,v,h,V,Z,B]),g.useEffect(()=>{const ne=t.get("runId"),ue=t.get("resume"),pe=t.get("provider");if(ne&&ue==="true"&&pe&&!V&&!Z&&!w&&!_&&q){S(ne),k(!0);try{B({runId:ne}).then(le=>{if(le.snapshot?.status==="running")return $.mutateAsync({runId:ne})}).then(()=>{n(le=>{const ve=new URLSearchParams(le);return ve.delete("resume"),ve})}).catch(le=>{console.error("❌ Failed to resume template installation:",le),le.message?.includes("404")||le.message?.includes("not found")?m("Template installation run not found. It may have expired or been completed."):m("Failed to resume template installation. Please try again.")})}catch(le){console.error("❌ Auto-resume failed with error:",le),m("Failed to resume template installation. Please refresh and try again.")}}},[t,e,V,Z,w,_,q,B,$,n]);const X=[{value:"openai",label:"OpenAI"},{value:"anthropic",label:"Anthropic"},{value:"groq",label:"Groq"},{value:"google",label:"Google"}],te=[{key:"tools",label:"Tools",value:N?.tools?.length?N.tools.map(ne=>ne).join(", "):"n/a",icon:o.jsx(eh,{})},{key:"agents",label:"Agents",value:N?.agents?.length?N.agents.map(ne=>ne).join(", "):"n/a",icon:o.jsx(sl,{})},{key:"workflows",label:"Workflows",value:N?.workflows?.length?N.workflows.map(ne=>ne).join(", "):"n/a",icon:o.jsx(vD,{})},{key:"providers",label:"Providers",value:N?.supportedProviders?.length?N.supportedProviders.join(", "):"n/a",icon:o.jsx(Rv,{})},{key:"tags",label:"Tags",value:N?.tags?.length?N.tags.join(", "):"n/a",icon:o.jsx(wN,{})}],J=[{...te[0]},{...te[1]},{...te[2]}].filter(ne=>ne.value!=="n/a");g.useEffect(()=>{L&&d(L)},[L]),g.useEffect(()=>{const ne=Q||U;ne?.phase==="error"&&ne?.error&&m(typeof ne.error=="string"?ne.error:String(ne.error))},[Q?.phase,Q?.error,U?.phase,U?.error]);const ee=ne=>{s(ne)},ae=async ne=>(i(ne.provider),c(ne.modelId),{message:"Model updated successfully"}),ce=async()=>{const ne=Object.entries(u).reduce((ue,[pe,le])=>(le===""&&ue.push(pe),ue),[]);if(ne.length>0){p(ne);return}if(N){m(null),y(!1),S(""),C(!0);try{const pe={repo:N.githubUrl||`https://github.com/mastra-ai/template-${N.slug}`,ref:P,slug:N.slug,variables:u},{runId:le}=await F({});S(le),n(ve=>{const ye=new URLSearchParams(ve);return ye.set("runId",le),ye.set("resume","true"),ye.set("provider",r||"openai"),ye}),await D.mutateAsync({inputData:pe,selectedModel:{provider:a,modelId:l},runId:le})}catch(ue){C(!1),m(ue?.message||"Template installation failed"),console.error("Template installation failed",ue)}}},Y=ne=>{const{name:ue,value:pe}=ne.target;pe.trim()===""?p(le=>[...le,ue]):p(le=>le.filter(ve=>ve!==ue)),d(le=>({...le,[ue]:pe}))};return o.jsx(ls,{children:o.jsx("div",{className:K("w-full lg:px-12 h-full overflow-y-scroll"),children:o.jsxs("div",{className:"p-6 w-full max-w-[80rem] mx-auto grid gap-y-4",children:[o.jsx(jss,{isLoading:I,title:N?.title,description:N?.longDescription,imageURL:N?.imageURL,githubUrl:N?.githubUrl,infoData:te,templateSlug:e}),N&&o.jsxs(o.Fragment,{children:[(V||Z)&&o.jsx(Rss,{name:N.title,streamResult:Z?U:Q,runId:b,workflowInfo:q}),v&&o.jsx(Pss,{name:N.title,installedEntities:J,linkComponent:Ba}),h&&o.jsx(Css,{errorMsg:h,validationErrors:E.length>0?E:Q?.validationResults?.errors||U?.validationResults?.errors}),!V&&!Z&&!v&&!h&&o.jsx(Ess,{providerOptions:X,selectedProvider:r,onProviderChange:ee,variables:u,setVariables:d,errors:f,setErrors:p,handleInstallTemplate:ce,handleVariableChange:Y,isLoadingEnvVars:M||H,isInstalling:z,defaultModelProvider:a,defaultModelId:l,onModelUpdate:ae})]})]})})})}const Mss=()=>{const{toolId:e,agentId:t}=ur();return o.jsx("div",{className:"h-full w-full overflow-y-auto",children:o.jsx(cZr,{toolId:e,agentId:t})})},Dss=()=>{const{toolId:e}=ur();return o.jsx("div",{className:"h-full w-full overflow-y-hidden",children:o.jsx(Vns,{toolId:e})})};function Lss(){const{traceId:e}=ur(),[t,n]=ga(),r=bs(),s=t.get("spanId")||void 0,a=t.get("tab"),i=a==="scoring"?"scoring":a==="feedback"?"feedback":"details",l=t.get("scoreId")||void 0,[c,u]=g.useState(s??null),[d,f]=g.useState(),[p,h]=g.useState(i),[m,v]=g.useState(0),[y,b]=g.useState(!1),{data:S,isLoading:w,error:k}=ZH(e),_=g.useMemo(()=>S?.spans??[],[S?.spans]),C=g.useMemo(()=>_.find(ae=>ae.parentSpanId==null),[_]),{data:E,isLoading:j}=oI(e,c??"");g.useEffect(()=>v(0),[e,c]);const{data:N,isLoading:I}=ih(),{data:R,isLoading:P}=s6t({traceId:e,spanId:c??void 0,page:m}),[L,M]=g.useState(0);g.useEffect(()=>M(0),[e,c]);const{data:q,isLoading:H}=C9t({traceId:e,page:L});g.useEffect(()=>{if(l&&R?.scores&&!d){const ae=R.scores.find(ce=>ce.id===l);ae&&f(ae)}},[l,R?.scores,d]);const F=g.useCallback(ae=>{const ce=new URLSearchParams(t);for(const[Y,ne]of Object.entries(ae))ne===null||ne===""?ce.delete(Y):ce.set(Y,ne);n(ce,{replace:!0})},[t,n]),z=g.useCallback(ae=>{const ce=ae??null,Y=ce===c;u(ce),Y||(f(void 0),h("details"),F({spanId:ce,tab:null,scoreId:null}))},[c,F]),B=g.useCallback(()=>{u(null),f(void 0),h("details"),F({spanId:null,tab:null,scoreId:null})},[F]),D=g.useCallback(ae=>{u(ae),f(void 0),h("details"),F({spanId:ae,tab:null,scoreId:null})},[F]),{handlePreviousSpan:Q,handleNextSpan:V}=GH(_,c,D),$=g.useCallback(ae=>{const ce=ae;h(ce),f(void 0),F({tab:ce==="details"?null:ce,scoreId:null})},[F]),U=g.useCallback(ae=>{f(ae),F({scoreId:ae.id})},[F]),Z=g.useCallback(()=>{f(void 0),F({scoreId:null})},[F]),X=g.useCallback(()=>{r("/observability")},[r]),te=g.useCallback(()=>{h("scoring"),C&&c!==C.spanId?(u(C.spanId),f(void 0),F({spanId:C.spanId,tab:"scoring",scoreId:null})):F({tab:"scoring"})},[C,c,F]),J=C?o.jsx(Iy,{owner:"trace-detail",children:o.jsxs(Mr,{children:[o.jsxs(de,{tooltip:"Evaluate Trace","aria-label":"Evaluate Trace",onClick:te,children:[o.jsx(hcn,{}),"Evaluate"]}),o.jsxs(de,{tooltip:"Save as Dataset Item","aria-label":"Save as Dataset Item",onClick:()=>b(!0),children:[o.jsx(gd,{}),"Save"]})]})}):null,ee=C?o.jsx(Lt.Row,{children:o.jsx(Lt.Column,{children:o.jsx(m9t,{rootSpan:C,numOfCol:3})})}):null;return k?o.jsxs(Lt,{height:"full",children:[J,ee&&o.jsx(Lt.TopArea,{children:ee}),o.jsx(Lt.MainArea,{isCentered:!0,children:o.jsx(g9t,{error:k,resource:"traces",errorTitle:"Failed to load trace"})})]}):o.jsxs(Lt,{children:[J,ee&&o.jsx(Lt.TopArea,{children:ee}),o.jsx(w9t,{rootSpanId:C?.spanId,traceId:e,isOpen:y,onClose:()=>b(!1)}),o.jsxs("div",{className:K("grid h-full min-h-0 gap-4 overflow-hidden items-start mt-4",c?"grid-cols-[2fr_3fr]":"grid-cols-[1fr]"),children:[o.jsx(uTe,{traceId:e,spans:_,isLoading:w,onClose:X,onSpanSelect:z,onEvaluateTrace:te,initialSpanId:c,placement:"trace-page",timelineChartWidth:c?"default":"wide"}),c&&!w&&o.jsxs("div",{className:K("grid gap-4 max-h-full min-h-0 overflow-auto",d?"grid-rows-[1fr_1fr]":"grid-rows-[1fr]"),children:[o.jsx(WH,{traceId:e,spanId:c,span:E?.span,isLoading:j,onClose:B,onPrevious:Q,onNext:V,activeTab:p,onTabChange:$,feedbackTabBadge:q?.pagination?.total??void 0,feedbackTabSlot:()=>o.jsx(k9t,{feedbackData:q,onPageChange:M,isLoadingFeedbackData:H}),scoringTabBadge:R?.pagination?.total??void 0,scoringTabSlot:({span:ae,traceId:ce,spanId:Y})=>o.jsxs("div",{className:"grid gap-6",children:[o.jsx(_9t,{traceId:ce,isTopLevelSpan:!ae.parentSpanId,spanId:Y,entityType:ae.attributes?.agentId||ae.entityType===Os.AGENT?"Agent":ae.attributes?.workflowId||ae.entityType===Os.WORKFLOW_RUN?"Workflow":void 0,scorers:N,isLoadingScorers:I}),o.jsx(O9t,{scoresData:R,onPageChange:v,isLoadingScoresData:P,onScoreSelect:U})]})}),d&&o.jsx(zje,{score:d,onClose:Z})]})]})]})}function Fss(){const{data:e,isLoading:t,error:n}=Uy(),[r,s]=g.useState("");return n&&gs(n)?o.jsx(lr,{children:o.jsx(Vs,{})}):n&&ys(n)?o.jsx(lr,{children:o.jsx(Ds,{resource:"workflows"})}):n?o.jsx(lr,{children:o.jsx(zi,{title:"Failed to load workflows",message:n.message})}):Object.keys(e||{}).length===0&&!t?o.jsx(lr,{children:o.jsx(bDr,{})}):o.jsxs(Lt,{children:[o.jsx(Lt.TopArea,{children:o.jsxs(Lt.Row,{align:"center",stack:"responsive",children:[o.jsx("div",{className:"max-w-120 flex-1",children:o.jsx(jf,{onSearch:s,label:"Filter workflows",placeholder:"Filter by name or description"})}),o.jsxs(de,{as:Ba,to:"/workflows/schedules",variant:"primary",className:"shrink-0",children:[o.jsx(hD,{}),"Schedules"]})]})}),o.jsx(yDr,{workflows:e||{},isLoading:t,search:r})]})}const zss={active:"bg-accent1",paused:"bg-accent3"},Bss={active:"text-accent1",paused:"text-accent3"},Q9t=({status:e})=>o.jsxs("span",{className:"inline-flex items-center gap-2 whitespace-nowrap",children:[o.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${zss[e]}`,"aria-hidden":!0}),o.jsx("span",{className:`text-ui-sm ${Bss[e]}`,children:e})]}),Fj=e=>!e||e<=0?"—":new Date(e).toLocaleString(),dP=e=>{if(!e||e<=0)return"—";const t=e-Date.now(),n=Math.abs(t),r=Math.floor(n/1e3);if(r<60)return t>=0?`in ${r}s`:`${r}s ago`;const s=Math.floor(r/60);if(s<60)return t>=0?`in ${s}m`:`${s}m ago`;const a=Math.floor(s/60);if(a<24)return t>=0?`in ${a}h`:`${a}h ago`;const i=Math.floor(a/24);return t>=0?`in ${i}d`:`${i}d ago`};function Y9t({status:e}){const{icon:t,color:n}=Uss(e);return o.jsxs("span",{className:`inline-flex items-center gap-1.5 whitespace-nowrap text-ui-sm ${n}`,children:[o.jsx("span",{className:"inline-flex shrink-0 items-center","aria-hidden":!0,children:t}),o.jsx("span",{children:e})]})}function Uss(e){switch(e){case"success":return{icon:o.jsx(Js,{size:14}),color:"text-accent1"};case"failed":return{icon:o.jsx(vs,{size:14}),color:"text-accent2"};case"running":return{icon:o.jsx(Gt,{}),color:"text-neutral3"};case"suspended":return{icon:o.jsx(lq,{size:14}),color:"text-accent3"};case"canceled":return{icon:o.jsx(Of,{size:14}),color:"text-neutral3"};case"pending":case"waiting":return{icon:o.jsx(dO,{size:14}),color:"text-neutral3"};default:return{icon:null,color:"text-neutral3"}}}const ZQe="auto auto auto auto 1fr";function qss(e){if(e===void 0)return"—";if(e<1e3)return`${e}ms`;if(e<6e4)return`${(e/1e3).toFixed(1)}s`;const t=Math.floor(e/6e4),n=Math.floor(e%6e4/1e3);return`${t}m ${n}s`}function Vss(e){const t=Math.abs(e),n=e<0?"-":"";return t<1e3?`${n}${t}ms`:t<6e4?`${n}${(t/1e3).toFixed(1)}s`:t<36e5?`${n}${(t/6e4).toFixed(1)}m`:`${n}${(t/36e5).toFixed(1)}h`}const Hss=3e4,Wss=5*6e4;function Zss({triggers:e,isLoading:t,workflowId:n,hasNextPage:r,isFetchingNextPage:s,setEndOfListElement:a}){const{Link:i,paths:l}=yn();return t?o.jsx(tl,{columns:ZQe}):e.length===0?o.jsx(ge,{variant:"ui-md",className:"text-neutral4 p-4",children:"No trigger history yet."}):o.jsxs(me,{columns:ZQe,className:"min-w-0",children:[o.jsxs(me.Top,{children:[o.jsx(me.TopCell,{children:"Run"}),o.jsx(me.TopCell,{children:"Status"}),o.jsx(me.TopCell,{children:"Started"}),o.jsx(me.TopCell,{children:"Duration"}),o.jsx(me.TopCell,{children:" "})]}),e.map(c=>{const u=c.actualFireAt-c.scheduledFireAt,d=Vss(u),f=`Scheduled ${Fj(c.scheduledFireAt)} — published ${Fj(c.actualFireAt)} (drift ${d})`,p=c.outcome==="failed",h=p?c.error:c.run?.error,m=Math.abs(u),v=!p&&m>Hss&&m<=Wss,y=`${c.scheduleId}-${c.runId}-${c.actualFireAt}`,b=!!(n&&c.runId&&!p),S=o.jsx("span",{className:b?"text-accent1 font-mono text-ui-sm whitespace-nowrap":"text-neutral3 font-mono text-ui-sm whitespace-nowrap",children:c.runId}),w=o.jsxs(o.Fragment,{children:[o.jsx(me.Cell,{height:"compact",children:S}),o.jsx(me.Cell,{height:"compact",children:o.jsxs("span",{className:"inline-flex items-center gap-2",children:[p?o.jsxs("span",{className:"inline-flex items-center gap-1.5 whitespace-nowrap text-ui-sm text-accent2",children:[o.jsx(Ep,{size:14}),"publish failed"]}):c.run?o.jsx(Y9t,{status:c.run.status}):o.jsx("span",{className:"inline-flex items-center gap-1.5 whitespace-nowrap text-ui-sm text-neutral3",children:"pending"}),h?o.jsxs(Wn,{children:[o.jsx(zn,{asChild:!0,children:o.jsx("span",{className:"text-accent2 inline-flex",children:o.jsx(Ep,{size:14})})}),o.jsx(Bn,{children:h})]}):null]})}),o.jsx(me.Cell,{height:"compact",children:o.jsxs("span",{className:"inline-flex items-center gap-2 whitespace-nowrap",children:[o.jsx("span",{title:f,children:dP(c.actualFireAt)}),v?o.jsxs(Wn,{children:[o.jsx(zn,{asChild:!0,children:o.jsx("span",{className:"text-accent3 inline-flex",children:o.jsx(Ep,{size:14})})}),o.jsxs(Bn,{children:["Published ",d," after the scheduled fire time"]})]}):null]})}),o.jsx(me.Cell,{height:"compact",children:c.run?o.jsx("span",{children:qss(c.run.durationMs)}):o.jsx("span",{className:"text-neutral4",children:"—"})}),o.jsx(me.Cell,{height:"compact",children:" "})]});return b?o.jsx(me.RowLink,{to:l.workflowRunLink(n,c.runId),LinkComponent:i,children:w},y):o.jsx(me.RowStatic,{children:w},y)}),o.jsx(me.NextPageLoading,{isLoading:s,hasMore:r,setEndOfListElement:a})]})}const Gss=e=>{const t=We();return wt({queryKey:["schedule",e],enabled:!!e,queryFn:async()=>{if(!e)throw new Error("scheduleId is required");return t.getSchedule(e)}})},GQe=25,Qss=e=>{const t=We(),{inView:n,setRef:r}=A_(),s=$1({queryKey:["schedule-triggers",e],enabled:!!e,initialPageParam:void 0,queryFn:async({pageParam:u})=>e?t.listScheduleTriggers(e,{limit:GQe,toActualFireAt:u}):{triggers:[]},getNextPageParam:u=>{if(!(!u?.triggers?.length||u.triggers.length<GQe))return u.triggers[u.triggers.length-1].actualFireAt},refetchInterval:u=>(u.state.data?.pages.flatMap(p=>p.triggers)??[]).some(p=>p.run?p.run.status==="pending"||p.run.status==="running"||p.run.status==="waiting":p.outcome==="published")?5e3:!1}),a=s.data?.pages.flatMap(u=>u?.triggers??[])??[],{hasNextPage:i,isFetchingNextPage:l,fetchNextPage:c}=s;return g.useEffect(()=>{n&&i&&!l&&c()},[n,i,l,c]),{...s,data:a,setEndOfListElement:r}},Yss=e=>{const t=We(),n=Hr();return Rn({mutationFn:async r=>{if(!e)throw new Error("scheduleId is required");return r==="pause"?t.pauseSchedule(e):t.resumeSchedule(e)},onSuccess:(r,s)=>{n.invalidateQueries({queryKey:["schedule",e]}),n.invalidateQueries({queryKey:["schedules"]}),De.success(s==="pause"?"Schedule paused":"Schedule resumed")},onError:r=>{De.error(r.message)}})};function fF({label:e,children:t}){return o.jsxs("div",{className:"flex flex-col gap-1",children:[o.jsx(ge,{variant:"ui-xs",className:"text-neutral4 uppercase tracking-wide",children:e}),o.jsx("div",{className:"text-ui-md",children:t})]})}function Xss(){const{scheduleId:e}=ur(),{paths:t}=yn(),{data:n,error:r}=Gss(e),{data:s,isLoading:a,error:i,hasNextPage:l,isFetchingNextPage:c,setEndOfListElement:u}=Qss(e),d=Yss(e);if(r&&gs(r))return o.jsx(lr,{children:o.jsx(Vs,{})});if(r&&ys(r))return o.jsx(lr,{children:o.jsx(Ds,{resource:"schedules"})});if(r)return o.jsx(lr,{children:o.jsx(zi,{title:"Failed to load schedule",message:r.message})});const f=n?.target.type==="workflow"?n.target.workflowId:void 0;return o.jsxs(Lt,{children:[o.jsx(Lt.TopArea,{children:o.jsx(Lt.Row,{className:"justify-end",children:o.jsxs(Lt.Column,{className:"flex justify-end gap-2",children:[o.jsxs(de,{as:Ba,to:t.schedulesLink(),variant:"ghost",children:[o.jsx(Nc,{}),"Back to schedules"]}),f?o.jsx(de,{as:Ba,to:t.workflowLink(f),variant:"ghost",children:"Open workflow"}):null,n?o.jsx(de,{onClick:()=>d.mutate(n.status==="active"?"pause":"resume"),disabled:d.isPending,"data-testid":"schedule-toggle-button",children:n.status==="active"?o.jsxs(o.Fragment,{children:[o.jsx(Qlt,{}),"Pause"]}):o.jsxs(o.Fragment,{children:[o.jsx(Fp,{}),"Resume"]})}):null]})})}),n?o.jsxs("div",{className:"grid gap-6 h-full overflow-hidden grid-cols-[minmax(0,20rem)_1fr]",children:[o.jsxs("div",{className:"flex flex-col gap-4 border border-border1 rounded-md p-4 h-fit",children:[o.jsx(fF,{label:"Workflow",children:f?o.jsx(Ba,{to:t.workflowLink(f),className:"text-accent1 hover:underline",children:f}):"—"}),o.jsxs(fF,{label:"Cron",children:[o.jsx("code",{className:"font-mono text-ui-md",children:n.cron}),n.timezone?o.jsx("span",{className:"text-neutral4 ml-2 text-ui-sm",children:n.timezone}):null]}),o.jsx(fF,{label:"Status",children:o.jsx(Q9t,{status:n.status})}),o.jsx(fF,{label:"Next fire",children:o.jsx("span",{title:Fj(n.nextFireAt),children:dP(n.nextFireAt)})})]}),o.jsxs("div",{className:"overflow-y-auto","data-testid":"schedule-triggers-panel",children:[o.jsx(ge,{variant:"ui-md",className:"mb-3",children:"Trigger history"}),i?o.jsx(zi,{title:"Failed to load trigger history",message:i.message}):o.jsx(Zss,{triggers:s??[],isLoading:a,workflowId:f,hasNextPage:l,isFetchingNextPage:c,setEndOfListElement:u})]})]}):null]})}const QQe="minmax(0, 1.2fr) minmax(0, 1.4fr) minmax(0, 1fr) auto auto auto";function Kss({schedules:e,isLoading:t,search:n=""}){const{paths:r,Link:s}=yn(),a=g.useMemo(()=>{const i=n.toLowerCase();return i?e.filter(l=>l.id.toLowerCase().includes(i)||l.target.workflowId.toLowerCase().includes(i)):e},[e,n]);return t?o.jsx(tl,{columns:QQe}):o.jsxs(me,{columns:QQe,variant:"striped",className:"min-w-0",children:[o.jsxs(me.Top,{children:[o.jsx(me.TopCell,{children:"Workflow"}),o.jsx(me.TopCell,{children:"Schedule ID"}),o.jsx(me.TopCell,{children:"Cron"}),o.jsx(me.TopCell,{children:"Status"}),o.jsx(me.TopCell,{children:"Next fire"}),o.jsx(me.TopCell,{children:"Last run"})]}),a.length===0&&n?o.jsx(me.NoMatch,{message:"No schedules match your search"}):null,a.length===0&&!n?o.jsx(me.NoMatch,{message:"No schedules configured"}):null,a.map(i=>o.jsxs(me.RowLink,{to:r.scheduleLink(i.id),LinkComponent:s,children:[o.jsx(me.NameCell,{children:i.target.workflowId}),o.jsx(me.Cell,{height:"compact",className:"min-w-0",children:o.jsx("span",{className:"block truncate font-mono text-ui-smd text-neutral3",title:i.id,children:i.id})}),o.jsx(me.Cell,{height:"compact",children:o.jsxs("span",{className:"inline-flex items-center gap-2 whitespace-nowrap",children:[o.jsx("code",{className:"font-mono text-ui-sm",children:i.cron}),i.timezone?o.jsx("span",{className:"text-neutral4 text-ui-xs",children:i.timezone}):null]})}),o.jsx(me.Cell,{height:"compact",children:o.jsx(Q9t,{status:i.status})}),o.jsx(me.Cell,{height:"compact",children:o.jsx("span",{className:"whitespace-nowrap",title:Fj(i.nextFireAt),children:dP(i.nextFireAt)})}),o.jsx(me.Cell,{height:"compact",children:i.lastRun?o.jsxs("span",{className:"inline-flex items-center gap-2 whitespace-nowrap",children:[o.jsx(Y9t,{status:i.lastRun.status}),o.jsx("span",{className:"text-neutral4 text-ui-sm",title:Fj(i.lastFireAt),children:i.lastFireAt?dP(i.lastFireAt):""})]}):i.lastFireAt?o.jsx("span",{className:"whitespace-nowrap",title:Fj(i.lastFireAt),children:dP(i.lastFireAt)}):o.jsx("span",{className:"text-neutral4",children:"Never"})})]},i.id))]})}function Jss({workflowId:e}={}){const{data:t,isLoading:n,error:r}=Kxe(e?{workflowId:e}:{}),[s,a]=g.useState("");return r?o.jsx(zi,{title:"Failed to load schedules",message:r.message}):o.jsxs("div",{className:"grid grid-rows-[auto_1fr] gap-4 h-full overflow-hidden",children:[o.jsx("div",{className:"max-w-120",children:o.jsx(jf,{onSearch:a,label:"Filter schedules",placeholder:"Filter by id or workflow"})}),o.jsx("div",{className:"overflow-y-auto",children:o.jsx(Kss,{schedules:t??[],isLoading:n,search:s})})]})}function eas(){const[e]=ga(),t=e.get("workflowId")??void 0,{error:n}=Kxe(t?{workflowId:t}:{});return n&&gs(n)?o.jsx(lr,{children:o.jsx(Vs,{})}):n&&ys(n)?o.jsx(lr,{children:o.jsx(Ds,{resource:"schedules"})}):o.jsx(Lt,{children:o.jsx("div",{className:"h-full",children:o.jsx(Jss,{workflowId:t})})})}function tas({stepGraph:e,open:t,workflowName:n}){const{nodes:r,edges:s}=N1e({stepGraph:e}),[a,i]=g.useState(!1),[l,c,u]=vwt(r),[d]=ywt(s),{edgeTypes:f,nodeTypes:p,styledEdges:h}=R2t({edges:d,workflowName:n,stepGraph:e});return g.useEffect(()=>{if(t){const m=setTimeout(()=>{i(!0)},500);return()=>clearTimeout(m)}},[t]),o.jsx("div",{className:"w-full h-full relative bg-surface1",children:a?o.jsxs(gwt,{nodes:l,edges:h,edgeTypes:f,fitView:!0,fitViewOptions:{maxZoom:1},minZoom:.01,maxZoom:1,nodeTypes:p,onNodesChange:u,children:[o.jsx(W_e,{position:"bottom-left"}),o.jsx(xwt,{variant:ey.Lines,gap:12,size:.5})]}):o.jsx("div",{className:"w-full h-full flex items-center justify-center",children:o.jsx(Gt,{})})})}function nas(){const{stepDetail:e,closeStepDetail:t}=ZV();return e?o.jsxs("div",{className:"flex flex-col h-full","data-testid":"workflow-step-detail-panel",children:[o.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border1 bg-surface1",children:[o.jsxs("div",{className:"flex items-center gap-2",children:[e.type==="map-config"&&o.jsx(efe,{className:"w-4 h-4",style:{color:Cu.map}}),e.type==="nested-graph"&&o.jsx(jd,{className:"w-4 h-4",style:{color:Cu.workflow}}),o.jsxs("div",{className:"flex flex-col",children:[o.jsx(ge,{variant:"ui-md",className:"text-neutral6 font-medium",children:e.type==="map-config"?`${e.stepName} Config`:`${e.stepName} Workflow`}),e.type==="map-config"&&e.stepId&&e.stepId!==e.stepName&&o.jsx(ge,{variant:"ui-xs",className:"text-neutral3",children:e.stepId})]})]}),o.jsx("button",{onClick:t,className:"p-1 hover:bg-surface3 rounded transition-colors","aria-label":"Close",children:o.jsx(vs,{className:"w-4 h-4 text-neutral3"})})]}),o.jsxs("div",{className:"flex-1 overflow-auto",children:[e.type==="map-config"&&e.mapConfig&&o.jsx(iP,{data:e.mapConfig}),e.type==="nested-graph"&&e.nestedGraph&&o.jsx("div",{className:"h-full min-h-[400px]",children:o.jsx(T1e,{children:o.jsx(tas,{stepGraph:e.nestedGraph.stepGraph,open:!0,workflowName:e.nestedGraph.fullStep})},`nested-graph-${e.nestedGraph.fullStep}`)})]})]}):null}function ras(e){const t=new Blob([JSON.stringify(e??null)]).size;return t<1024?`${t} B`:`${(t/1024).toFixed(1)} KB`}function sas(e,t){if(e&&typeof e=="object"&&!Array.isArray(e)){const n=Object.keys(e);if(n.length===1)return n[0]}return t}function aas({suspendedSteps:e,workflow:t,isStreaming:n,onResume:r}){return n||e.length===0?null:o.jsxs("div",{className:"space-y-5 rounded-lg border border-border1 bg-surface4 p-5","data-testid":"workflow-suspended-steps",children:[o.jsxs("div",{className:"flex items-center justify-between gap-3",children:[o.jsxs(ge,{as:"p",variant:"ui-md",className:"flex items-center gap-2 text-neutral6 font-semibold",children:[o.jsx(Ue,{children:o.jsx(lq,{})}),"Step suspended"]}),o.jsx(dn,{variant:"warning",children:"Needs input"})]}),e.map((s,a)=>{const i=t.allSteps[s.stepId];if(!i||i.isWorkflow)return null;const l=i?.resumeSchema?lm(im(yx(i.resumeSchema))):op(dr(),cT());return o.jsx(ias,{step:s,stepSchema:l,description:i.description,isStreaming:n,onResume:r},`${s.runId}-${s.stepId}-${a}`)})]})}function ias({step:e,stepSchema:t,description:n,isStreaming:r,onResume:s}){const[a,i]=g.useState(!1);return o.jsxs("div",{className:"space-y-5",children:[o.jsxs("div",{className:"space-y-2",children:[o.jsx(ge,{as:"p",variant:"ui-md",className:"text-neutral6 font-medium truncate",children:e.stepId}),n&&o.jsx(ge,{as:"p",variant:"ui-sm",className:"text-neutral3",children:n})]}),e.suspendPayload&&o.jsxs("div",{className:"space-y-2",children:[o.jsxs(ge,{as:"p",variant:"ui-sm",className:"flex items-center gap-2 text-neutral3",children:[o.jsx(Ue,{children:o.jsx(kdn,{})}),"The step is asking"]}),o.jsxs(xf,{open:a,onOpenChange:i,children:[o.jsxs(Od,{className:"flex w-full items-center justify-between gap-2 rounded-lg border border-border1 bg-surface3 px-3 py-2.5",children:[o.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[o.jsx(Ue,{children:o.jsx(ta,{className:K("transition-transform text-neutral3",{"transform rotate-90":a})})}),o.jsx(ge,{as:"span",variant:"ui-md",className:"text-neutral6 truncate",children:sas(e.suspendPayload,e.stepId)})]}),o.jsx(ge,{as:"span",variant:"ui-sm",className:"text-neutral3 shrink-0",children:ras(e.suspendPayload)})]}),o.jsx(_d,{children:o.jsx("div",{"data-testid":"suspended-payload",className:"pt-2",children:o.jsx(Qr,{data:e.suspendPayload,className:"w-full overflow-x-auto p-2",showCopyButton:!1})})})]})]}),o.jsxs("div",{className:"space-y-3",children:[o.jsxs(ge,{as:"p",variant:"ui-sm",className:"flex items-center gap-2 text-neutral3",children:[o.jsx(Ue,{children:o.jsx(Cdn,{})}),"Your response"]}),o.jsx("div",{className:"-mx-5",children:o.jsx(B7,{schema:t,isSubmitLoading:r,submitButtonLabel:"Resume",submitButtonIcon:o.jsx(Fp,{}),submitButtonFullWidth:!0,collapsible:!1,hideHeading:!0,hideInputTypeLabel:!0,onSubmit:l=>{const c=e.stepId?.split(".");s({stepId:c,runId:e.runId,suspendPayload:e.suspendPayload,resumeData:l,isLoading:!1})}})})]})]})}function oas(){const{result:e,runSnapshot:t,workflow:n,runId:r,isStreamingWorkflow:s}=g.useContext($l),{runId:a}=ur(),i=Ewt(e,r??""),l=LZn(),c=!!a,u=t?.status==="suspended",f=!!(a&&r&&a===r)&&e?.status==="suspended";return s||!n||i.length===0||c&&!u&&!f?null:o.jsx("div",{"data-testid":"workflow-suspended-overlay",className:"absolute top-2 right-2 z-20 w-[380px] max-w-[calc(100%-1rem)] max-h-[calc(100%-1rem)] overflow-y-auto rounded-lg shadow-lg animate-in fade-in-0 slide-in-from-top-2 zoom-in-95 duration-300",children:o.jsx(aas,{suspendedSteps:i,workflow:n,isStreaming:s,onResume:l})},r)}const las=e=>o.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:[o.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M5.99982 2.0625C3.8252 2.0625 2.06232 3.82538 2.06232 6C2.06232 8.17462 3.8252 9.9375 5.99982 9.9375C8.17444 9.9375 9.93732 8.17462 9.93732 6C9.93732 3.82538 8.17444 2.0625 5.99982 2.0625ZM0.937317 6C0.937317 3.20406 3.20388 0.9375 5.99982 0.9375C8.79576 0.9375 11.0623 3.20406 11.0623 6C11.0623 8.79594 8.79576 11.0625 5.99982 11.0625C3.20388 11.0625 0.937317 8.79594 0.937317 6Z",fill:"currentColor"}),o.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M7.97865 4.57004C8.22604 4.75795 8.27426 5.11082 8.08635 5.35821L6.05486 8.03279C5.94873 8.17251 5.78348 8.25471 5.60803 8.25505C5.43257 8.2554 5.267 8.17385 5.16032 8.03454L3.80937 6.27034C3.6205 6.02369 3.66733 5.67063 3.91398 5.48176C4.16063 5.29288 4.51369 5.33972 4.70257 5.58637L5.6051 6.76498L7.19048 4.67774C7.37839 4.43036 7.73126 4.38213 7.97865 4.57004Z",fill:"currentColor"})]}),cas=e=>o.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:[o.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M5.99982 2.0625C3.8252 2.0625 2.06232 3.82538 2.06232 6C2.06232 8.17462 3.8252 9.9375 5.99982 9.9375C8.17444 9.9375 9.93732 8.17462 9.93732 6C9.93732 3.82538 8.17444 2.0625 5.99982 2.0625ZM0.937317 6C0.937317 3.20406 3.20388 0.9375 5.99982 0.9375C8.79576 0.9375 11.0623 3.20406 11.0623 6C11.0623 8.79594 8.79576 11.0625 5.99982 11.0625C3.20388 11.0625 0.937317 8.79594 0.937317 6Z",fill:"currentColor"}),o.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M7.89741 4.10293C8.11707 4.32261 8.11706 4.67877 7.89738 4.89843L6.79517 6.00058L7.8962 7.10155C8.11588 7.32122 8.11589 7.67737 7.89623 7.89705C7.67656 8.11673 7.32041 8.11674 7.10073 7.89707L5.99965 6.79605L4.89856 7.89707C4.67889 8.11673 4.32273 8.11672 4.10307 7.89704C3.88341 7.67737 3.88342 7.32121 4.10309 7.10155L5.20413 6.00058L4.10191 4.89843C3.88224 4.67877 3.88223 4.32262 4.10189 4.10294C4.32155 3.88326 4.67771 3.88325 4.89738 4.10292L5.99965 5.20511L7.10191 4.10291C7.32159 3.88325 7.67774 3.88326 7.89741 4.10293Z",fill:"currentColor"})]}),uas=e=>e.includes("."),das=e=>e==="input"||e.endsWith(".input"),fas=1;function pas(e){return`${Number((e/1e3).toPrecision(3))}s`}function has(e,t){const n=Object.entries(e).filter(([i])=>!das(i));if(n.length===0)return[];const r=Math.min(...n.map(([,i])=>i.startedAt)),s=Math.max(...n.map(([,i])=>i.endedAt??t)),a=Math.max(s-r,1);return n.map(([i,l])=>{const c=l.endedAt===void 0,d=(l.endedAt??t)-l.startedAt,f=(l.startedAt-r)/a*100,p=Math.max(d/a*100,fas);return{stepId:i,step:l,status:l.status,offsetPct:f,widthPct:p,durationMs:d,isRunning:c,isNestedEntry:uas(i)}})}const mas=({status:e})=>o.jsxs(Ue,{children:[e==="success"&&o.jsx(las,{className:"text-accent1"}),e==="failed"&&o.jsx(cas,{className:"text-accent2"}),e==="suspended"&&o.jsx(lq,{className:"text-accent3"}),e==="waiting"&&o.jsx(Jde,{className:"text-accent5"}),e==="skipped"&&o.jsx(Jde,{className:"text-icon3"}),e==="running"&&o.jsx(oa,{className:"text-accent6 animate-spin"})]}),gas={success:"bg-accent1",failed:"bg-accent2",suspended:"bg-accent3",waiting:"bg-accent5",skipped:"bg-border1",running:"bg-accent6"};function X9t(e){return e.split(/[-_.\s]+/).filter(Boolean).map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join(" ")}const YQe=e=>e&&typeof e=="object"&&!Array.isArray(e)?e:{value:e},vas=e=>{const t=e;return O2t({duration:t.duration,date:t.date,isForEach:t.isForEach,mapConfig:t.mapConfig,canSuspend:t.canSuspend,isParallel:t.isParallel,stepGraph:t.stepGraph})},yas=({row:e,index:t,isSelected:n,isHovered:r,onSelectStep:s,onHoverStep:a,onOpenInput:i,onOpenOutput:l})=>{const c=vas(e.step),u=e.status==="running",d=!e.isNestedEntry;return o.jsxs("div",{role:"button",tabIndex:0,"data-testid":"workflow-timeline-row","data-workflow-step-key":e.stepId,"data-workflow-step-active":n?"true":void 0,"data-workflow-step-hovered":r?"true":void 0,"data-workflow-step-nested":e.isNestedEntry?"true":void 0,"aria-pressed":n,"aria-disabled":!d,onMouseEnter:()=>{d&&a(e.stepId)},onMouseLeave:()=>{d&&a(null)},onClick:()=>{d&&s(e.stepId)},onKeyDown:f=>{!d||f.key!=="Enter"&&f.key!==" "||(f.preventDefault(),s(e.stepId))},className:K("grid grid-cols-[auto_auto_auto_minmax(0,10rem)_minmax(0,1fr)_auto_5rem] items-center gap-2 rounded-md border border-transparent px-2 py-1 text-left transition-colors focus-visible:outline-hidden focus-visible:ring-1 focus-visible:ring-accent1",d&&"cursor-pointer",d&&"hover:bg-surface4",d&&r&&!n&&"border-neutral6 bg-surface4",d&&n&&"border-accent1",e.isNestedEntry&&"cursor-default opacity-55"),children:[o.jsx("div",{className:"flex justify-center",children:o.jsx(mas,{status:e.status})}),o.jsx("div",{className:"flex justify-center",children:o.jsx(de,{type:"button",variant:"ghost",size:"icon-sm",tooltip:"View step input",disabled:u,className:"text-neutral3 hover:text-neutral6 disabled:cursor-not-allowed disabled:opacity-40",onClick:f=>{f.stopPropagation(),u||i(e)},children:o.jsx(Ofn,{})})}),o.jsx("div",{className:"flex overflow-hidden",children:o.jsx(hU,{indicators:c,className:"shrink-0"})}),o.jsx(ge,{as:"span",variant:"ui-sm",className:"block min-w-0 max-w-full justify-self-stretch overflow-hidden text-ellipsis whitespace-nowrap text-left text-neutral6",children:X9t(e.stepId)}),o.jsx("div",{className:"relative h-2 min-w-0 rounded bg-surface4",children:o.jsx("div",{"data-testid":"workflow-timeline-bar","data-offset":String(e.offsetPct),"data-width":String(e.widthPct),className:`absolute top-0 h-full rounded ${gas[e.status]}`,style:{left:`${e.offsetPct}%`,width:`${e.widthPct}%`}})}),o.jsx("div",{className:"flex justify-center",children:o.jsx(de,{type:"button",variant:"ghost",size:"icon-sm",tooltip:"View step output",disabled:u,className:"text-neutral3 hover:text-neutral6 disabled:cursor-not-allowed disabled:opacity-40",onClick:f=>{f.stopPropagation(),u||l(e)},children:o.jsx(Sfn,{})})}),o.jsx(ge,{as:"span",variant:"ui-sm",className:"w-20 justify-self-end text-right text-neutral3 tabular-nums",children:pas(e.durationMs)})]},`timeline-item-${e.stepId}-${t}`)};function bas(){const{steps:e}=u4(),{selectedStepId:t,hoverStepId:n,setSelectedStepId:r,setHoverStepId:s}=sV(),[a,i]=g.useState(()=>Date.now()),[l,c]=g.useState(!1),[u,d]=g.useState(null),f=g.useRef(null);i0e(f,{enabled:!l});const p=has(e,a),h=p.some(m=>m.isRunning);return g.useEffect(()=>{if(!h)return;const m=setInterval(()=>i(Date.now()),100);return()=>clearInterval(m)},[h]),g.useEffect(()=>{if(l||p.length===0)return;const m=f.current;m&&(m.scrollTop=m.scrollHeight)},[l,p.length]),p.length===0?null:o.jsxs(o.Fragment,{children:[o.jsx("div",{"data-testid":"workflow-timeline",className:"pointer-events-none absolute right-0 bottom-0 z-20 px-2 pb-2",style:{left:"var(--workflow-left-panel-width, 0px)"},children:o.jsxs("div",{className:"pointer-events-auto flex max-h-64 w-full min-w-0 flex-col gap-3 overflow-hidden rounded-studio-panel border border-border1/50 bg-surface3 p-4 shadow-lg",children:[o.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-3",children:[o.jsx(ge,{as:"p",variant:"ui-md",className:"text-neutral3",children:"Timeline"}),o.jsx("button",{type:"button","aria-label":l?"Expand timeline":"Collapse timeline","aria-expanded":!l,onClick:()=>c(m=>!m),className:"rounded-md p-1 text-neutral3 transition-colors hover:bg-surface4 hover:text-neutral6",children:o.jsx(Sa,{className:K("h-4 w-4 transition-transform",l&&"-rotate-90")})})]}),!l&&o.jsx("div",{ref:f,"data-testid":"workflow-timeline-list",className:"flex min-h-0 flex-col gap-2 overflow-y-auto",children:p.map((m,v)=>o.jsx(yas,{row:m,index:v,isSelected:t===m.stepId,isHovered:n===m.stepId,onSelectStep:r,onHoverStep:s,onOpenInput:y=>d({type:"input",stepId:y.stepId,data:YQe(y.step.input)}),onOpenOutput:y=>d({type:"output",stepId:y.stepId,data:YQe(y.step.output)})},`timeline-item-${m.stepId}-${v}`))})]})}),o.jsx(br,{open:!!u,onOpenChange:m=>!m&&d(null),children:u&&o.jsx(Twt,{data:u.data,title:`${X9t(u.stepId)} ${u.type==="input"?"input":"output"}`})})]})}const xas=({workflowId:e,workflow:t,isLoading:n})=>{const{stepDetail:r}=ZV();return o.jsxs("div",{className:"flex h-full min-h-0",children:[o.jsx("div",{className:"flex h-full min-h-0 flex-1 flex-col",children:o.jsxs("div",{className:"relative min-h-0 flex-1 p-2 pb-0",children:[o.jsx(B2t,{workflowId:e,workflow:t,isLoading:n}),o.jsx(oas,{}),o.jsx(bas,{})]})}),r&&o.jsx("div",{className:"w-[420px] min-h-0 overflow-hidden border-l border-border1",children:o.jsx(nas,{})})]})},XQe=()=>{const{workflowId:e}=ur(),{data:t,isLoading:n,error:r}=S3(e);return r&&gs(r)?o.jsx("div",{className:"flex h-full items-center justify-center",children:o.jsx(Vs,{})}):r&&ys(r)?o.jsx("div",{className:"flex h-full items-center justify-center",children:o.jsx(Ds,{resource:"workflows"})}):o.jsx(Z1e,{children:o.jsx(xas,{workflowId:e,workflow:t??void 0,isLoading:n})})};function was(e,t){if(e==null)return{};var n,r,s=Rbt(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(s[n]=e[n])}return s}function Gve(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function Sas(e){if(Array.isArray(e))return Gve(e)}function kas(e){if(typeof Symbol<"u"&&e[Symbol.iterator]!=null||e["@@iterator"]!=null)return Array.from(e)}function Oas(e,t){if(e){if(typeof e=="string")return Gve(e,t);var n={}.toString.call(e).slice(8,-1);return n==="Object"&&e.constructor&&(n=e.constructor.name),n==="Map"||n==="Set"?Array.from(e):n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?Gve(e,t):void 0}}function _as(){throw new TypeError(`Invalid attempt to spread non-iterable instance.
|
|
728
728
|
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function Qve(e){return Sas(e)||kas(e)||Oas(e)||_as()}function rD(e){"@babel/helpers - typeof";return rD=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},rD(e)}function Cas(e,t){if(rD(e)!="object"||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t);if(rD(r)!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}function Eas(e){var t=Cas(e,"string");return rD(t)=="symbol"?t:t+""}function K9t(e,t,n){return(t=Eas(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function KQe(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(s){return Object.getOwnPropertyDescriptor(e,s).enumerable})),n.push.apply(n,r)}return n}function sj(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?KQe(Object(n),!0).forEach(function(r){K9t(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):KQe(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}function jas(e){var t=e.length;if(t===0||t===1)return e;if(t===2)return[e[0],e[1],"".concat(e[0],".").concat(e[1]),"".concat(e[1],".").concat(e[0])];if(t===3)return[e[0],e[1],e[2],"".concat(e[0],".").concat(e[1]),"".concat(e[0],".").concat(e[2]),"".concat(e[1],".").concat(e[0]),"".concat(e[1],".").concat(e[2]),"".concat(e[2],".").concat(e[0]),"".concat(e[2],".").concat(e[1]),"".concat(e[0],".").concat(e[1],".").concat(e[2]),"".concat(e[0],".").concat(e[2],".").concat(e[1]),"".concat(e[1],".").concat(e[0],".").concat(e[2]),"".concat(e[1],".").concat(e[2],".").concat(e[0]),"".concat(e[2],".").concat(e[0],".").concat(e[1]),"".concat(e[2],".").concat(e[1],".").concat(e[0])];if(t>=4)return[e[0],e[1],e[2],e[3],"".concat(e[0],".").concat(e[1]),"".concat(e[0],".").concat(e[2]),"".concat(e[0],".").concat(e[3]),"".concat(e[1],".").concat(e[0]),"".concat(e[1],".").concat(e[2]),"".concat(e[1],".").concat(e[3]),"".concat(e[2],".").concat(e[0]),"".concat(e[2],".").concat(e[1]),"".concat(e[2],".").concat(e[3]),"".concat(e[3],".").concat(e[0]),"".concat(e[3],".").concat(e[1]),"".concat(e[3],".").concat(e[2]),"".concat(e[0],".").concat(e[1],".").concat(e[2]),"".concat(e[0],".").concat(e[1],".").concat(e[3]),"".concat(e[0],".").concat(e[2],".").concat(e[1]),"".concat(e[0],".").concat(e[2],".").concat(e[3]),"".concat(e[0],".").concat(e[3],".").concat(e[1]),"".concat(e[0],".").concat(e[3],".").concat(e[2]),"".concat(e[1],".").concat(e[0],".").concat(e[2]),"".concat(e[1],".").concat(e[0],".").concat(e[3]),"".concat(e[1],".").concat(e[2],".").concat(e[0]),"".concat(e[1],".").concat(e[2],".").concat(e[3]),"".concat(e[1],".").concat(e[3],".").concat(e[0]),"".concat(e[1],".").concat(e[3],".").concat(e[2]),"".concat(e[2],".").concat(e[0],".").concat(e[1]),"".concat(e[2],".").concat(e[0],".").concat(e[3]),"".concat(e[2],".").concat(e[1],".").concat(e[0]),"".concat(e[2],".").concat(e[1],".").concat(e[3]),"".concat(e[2],".").concat(e[3],".").concat(e[0]),"".concat(e[2],".").concat(e[3],".").concat(e[1]),"".concat(e[3],".").concat(e[0],".").concat(e[1]),"".concat(e[3],".").concat(e[0],".").concat(e[2]),"".concat(e[3],".").concat(e[1],".").concat(e[0]),"".concat(e[3],".").concat(e[1],".").concat(e[2]),"".concat(e[3],".").concat(e[2],".").concat(e[0]),"".concat(e[3],".").concat(e[2],".").concat(e[1]),"".concat(e[0],".").concat(e[1],".").concat(e[2],".").concat(e[3]),"".concat(e[0],".").concat(e[1],".").concat(e[3],".").concat(e[2]),"".concat(e[0],".").concat(e[2],".").concat(e[1],".").concat(e[3]),"".concat(e[0],".").concat(e[2],".").concat(e[3],".").concat(e[1]),"".concat(e[0],".").concat(e[3],".").concat(e[1],".").concat(e[2]),"".concat(e[0],".").concat(e[3],".").concat(e[2],".").concat(e[1]),"".concat(e[1],".").concat(e[0],".").concat(e[2],".").concat(e[3]),"".concat(e[1],".").concat(e[0],".").concat(e[3],".").concat(e[2]),"".concat(e[1],".").concat(e[2],".").concat(e[0],".").concat(e[3]),"".concat(e[1],".").concat(e[2],".").concat(e[3],".").concat(e[0]),"".concat(e[1],".").concat(e[3],".").concat(e[0],".").concat(e[2]),"".concat(e[1],".").concat(e[3],".").concat(e[2],".").concat(e[0]),"".concat(e[2],".").concat(e[0],".").concat(e[1],".").concat(e[3]),"".concat(e[2],".").concat(e[0],".").concat(e[3],".").concat(e[1]),"".concat(e[2],".").concat(e[1],".").concat(e[0],".").concat(e[3]),"".concat(e[2],".").concat(e[1],".").concat(e[3],".").concat(e[0]),"".concat(e[2],".").concat(e[3],".").concat(e[0],".").concat(e[1]),"".concat(e[2],".").concat(e[3],".").concat(e[1],".").concat(e[0]),"".concat(e[3],".").concat(e[0],".").concat(e[1],".").concat(e[2]),"".concat(e[3],".").concat(e[0],".").concat(e[2],".").concat(e[1]),"".concat(e[3],".").concat(e[1],".").concat(e[0],".").concat(e[2]),"".concat(e[3],".").concat(e[1],".").concat(e[2],".").concat(e[0]),"".concat(e[3],".").concat(e[2],".").concat(e[0],".").concat(e[1]),"".concat(e[3],".").concat(e[2],".").concat(e[1],".").concat(e[0])]}var fse={};function Tas(e){if(e.length===0||e.length===1)return e;var t=e.join(".");return fse[t]||(fse[t]=jas(e)),fse[t]}function Nas(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0,r=e.filter(function(a){return a!=="token"}),s=Tas(r);return s.reduce(function(a,i){return sj(sj({},a),n[i])},t)}function JQe(e){return e.join(" ")}function Ias(e,t){var n=0;return function(r){return n+=1,r.map(function(s,a){return J9t({node:s,stylesheet:e,useInlineStyles:t,key:"code-segment-".concat(n,"-").concat(a)})})}}function J9t(e){var t=e.node,n=e.stylesheet,r=e.style,s=r===void 0?{}:r,a=e.useInlineStyles,i=e.key,l=t.properties,c=t.type,u=t.tagName,d=t.value;if(c==="text")return d;if(u){var f=Ias(n,a),p;if(!a)p=sj(sj({},l),{},{className:JQe(l.className)});else{var h=Object.keys(n).reduce(function(b,S){return S.split(".").forEach(function(w){b.includes(w)||b.push(w)}),b},[]),m=l.className&&l.className.includes("token")?["token"]:[],v=l.className&&m.concat(l.className.filter(function(b){return!h.includes(b)}));p=sj(sj({},l),{},{className:JQe(v)||void 0,style:Nas(l.className,Object.assign({},l.style,s),n)})}var y=f(t.children);return Le.createElement(u,PO({key:i},p),y)}}const Aas=(function(e,t){var n=e.listLanguages();return n.indexOf(t)!==-1});var Ras=["language","children","style","customStyle","codeTagProps","useInlineStyles","showLineNumbers","showInlineLineNumbers","startingLineNumber","lineNumberContainerStyle","lineNumberStyle","wrapLines","wrapLongLines","lineProps","renderer","PreTag","CodeTag","code","astGenerator"];function eYe(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(s){return Object.getOwnPropertyDescriptor(e,s).enumerable})),n.push.apply(n,r)}return n}function Ow(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?eYe(Object(n),!0).forEach(function(r){K9t(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):eYe(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}var Pas=/\n/g;function $as(e){return e.match(Pas)}function Mas(e){var t=e.lines,n=e.startingLineNumber,r=e.style;return t.map(function(s,a){var i=a+n;return Le.createElement("span",{key:"line-".concat(a),className:"react-syntax-highlighter-line-number",style:typeof r=="function"?r(i):r},"".concat(i,`
|
|
729
729
|
`))})}function Das(e){var t=e.codeString,n=e.codeStyle,r=e.containerStyle,s=r===void 0?{float:"left",paddingRight:"10px"}:r,a=e.numberStyle,i=a===void 0?{}:a,l=e.startingLineNumber;return Le.createElement("code",{style:Object.assign({},n,s)},Mas({lines:t.replace(/\n$/,"").split(`
|
|
730
730
|
`),style:i,startingLineNumber:l}))}function Las(e){return"".concat(e.toString().length,".25em")}function eFt(e,t){return{type:"element",tagName:"span",properties:{key:"line-number--".concat(e),className:["comment","linenumber","react-syntax-highlighter-line-number"],style:t},children:[{type:"text",value:e}]}}function tFt(e,t,n){var r={display:"inline-block",minWidth:Las(n),paddingRight:"1em",textAlign:"right",userSelect:"none"},s=typeof e=="function"?e(t):e,a=Ow(Ow({},r),s);return a}function j8(e){var t=e.children,n=e.lineNumber,r=e.lineNumberStyle,s=e.largestLineNumber,a=e.showInlineLineNumbers,i=e.lineProps,l=i===void 0?{}:i,c=e.className,u=c===void 0?[]:c,d=e.showLineNumbers,f=e.wrapLongLines,p=e.wrapLines,h=p===void 0?!1:p,m=h?Ow({},typeof l=="function"?l(n):l):{};if(m.className=m.className?[].concat(Qve(m.className.trim().split(/\s+/)),Qve(u)):u,n&&a){var v=tFt(r,n,s);t.unshift(eFt(n,v))}return f&d&&(m.style=Ow({display:"flex"},m.style)),{type:"element",tagName:"span",properties:m,children:t}}function nFt(e){for(var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:[],n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:[],r=0;r<e.length;r++){var s=e[r];if(s.type==="text")n.push(j8({children:[s],className:Qve(new Set(t))}));else if(s.children){var a=t.concat(s.properties.className);nFt(s.children,a).forEach(function(i){return n.push(i)})}}return n}function Fas(e,t,n,r,s,a,i,l,c){var u,d=nFt(e.value),f=[],p=-1,h=0;function m(_,C){var E=arguments.length>2&&arguments[2]!==void 0?arguments[2]:[];return j8({children:_,lineNumber:C,lineNumberStyle:l,largestLineNumber:i,showInlineLineNumbers:s,lineProps:n,className:E,showLineNumbers:r,wrapLongLines:c,wrapLines:t})}function v(_,C){if(r&&C&&s){var E=tFt(l,C,i);_.unshift(eFt(C,E))}return _}function y(_,C){var E=arguments.length>2&&arguments[2]!==void 0?arguments[2]:[];return t||E.length>0?m(_,C,E):v(_,C)}for(var b=function(){var C=d[h],E=C.children[0].value,j=$as(E);if(j){var N=E.split(`
|