@mastra/deployer-cloud 1.76.0-alpha.6 → 1.76.0-alpha.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/studio/assets/{CodeDiff.es-D8JrUO0B.js → CodeDiff.es-BNwUVtno.js} +1 -1
- package/dist/studio/assets/{core-CsIwu6ho.js → core-DAjwlaOw.js} +1 -1
- package/dist/studio/assets/{index-ImwRPnoG.js → index-BDYVFnUE.js} +2 -2
- package/dist/studio/assets/{index-BzwWtl00.js → index-ChTp2tEl.js} +1 -1
- package/dist/studio/assets/{main-BAXzEHDO.js → main-BokPXZai.js} +4 -4
- package/dist/studio/index.html +1 -1
- package/package.json +4 -4
|
@@ -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-DAjwlaOw.js","./index-ChTp2tEl.js","./engine-compile-CUTZfOIo.js","./index-2BQyy0xI.js","./preload-helper-PPVm8Dsz.js","./engine-javascript-DSQaR0Yq.js","./html-C2L_23MC.js","./javascript-ySlJ1b_l.js","./css-BPhBrDlE.js","./CodeDiff.es-BNwUVtno.js"])))=>i.map(i=>d[i]);
|
|
2
2
|
import{_ as Ii}from"./preload-helper-PPVm8Dsz.js";function XWt(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 i=Object.getOwnPropertyDescriptor(r,s);i&&Object.defineProperty(e,s,i.get?i:{enumerable:!0,get:()=>r[s]})}}}return Object.freeze(Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}))}function Sv(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var cne={exports:{}},uR={};var nMe;function JWt(){if(nMe)return uR;nMe=1;var e=Symbol.for("react.transitional.element"),t=Symbol.for("react.fragment");function n(r,s,i){var o=null;if(i!==void 0&&(o=""+i),s.key!==void 0&&(o=""+s.key),"key"in s){i={};for(var l in s)l!=="key"&&(i[l]=s[l])}else i=s;return s=i.ref,{$$typeof:e,type:r,key:o,ref:s!==void 0?s:null,props:i}}return uR.Fragment=t,uR.jsx=n,uR.jsxs=n,uR}var rMe;function eHt(){return rMe||(rMe=1,cne.exports=JWt()),cne.exports}var a=eHt(),une={exports:{}},Jr={},sMe;function tHt(){if(sMe)return Jr;sMe=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"),i=Symbol.for("react.profiler"),o=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"),h=Symbol.for("react.activity"),p=Symbol.iterator;function m(L){return L===null||typeof L!="object"?null:(L=p&&L[p]||L["@@iterator"],typeof L=="function"?L:null)}var v={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},y=Object.assign,x={};function b(L,$,z){this.props=L,this.context=$,this.refs=x,this.updater=z||v}b.prototype.isReactComponent={},b.prototype.setState=function(L,$){if(typeof L!="object"&&typeof L!="function"&&L!=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,L,$,"setState")},b.prototype.forceUpdate=function(L){this.updater.enqueueForceUpdate(this,L,"forceUpdate")};function S(){}S.prototype=b.prototype;function k(L,$,z){this.props=L,this.context=$,this.refs=x,this.updater=z||v}var j=k.prototype=new S;j.constructor=k,y(j,b.prototype),j.isPureReactComponent=!0;var C=Array.isArray;function T(){}var _={H:null,A:null,T:null,S:null},N=Object.prototype.hasOwnProperty;function I(L,$,z){var U=z.ref;return{$$typeof:t,type:L,key:$,ref:U!==void 0?U:null,props:z}}function A(L,$){return I(L.type,$,L.props)}function P(L){return typeof L=="object"&&L!==null&&L.$$typeof===t}function D(L){var $={"=":"=0",":":"=2"};return"$"+L.replace(/[=:]/g,function(z){return $[z]})}var F=/\/+/g;function Q(L,$){return typeof L=="object"&&L!==null&&L.key!=null?D(""+L.key):$.toString(36)}function q(L){switch(L.status){case"fulfilled":return L.value;case"rejected":throw L.reason;default:switch(typeof L.status=="string"?L.then(T,T):(L.status="pending",L.then(function($){L.status==="pending"&&(L.status="fulfilled",L.value=$)},function($){L.status==="pending"&&(L.status="rejected",L.reason=$)})),L.status){case"fulfilled":return L.value;case"rejected":throw L.reason}}throw L}function B(L,$,z,U,K){var ne=typeof L;(ne==="undefined"||ne==="boolean")&&(L=null);var X=!1;if(L===null)X=!0;else switch(ne){case"bigint":case"string":case"number":X=!0;break;case"object":switch(L.$$typeof){case t:case n:X=!0;break;case f:return X=L._init,B(X(L._payload),$,z,U,K)}}if(X)return K=K(L),X=U===""?"."+Q(L,0):U,C(K)?(z="",X!=null&&(z=X.replace(F,"$&/")+"/"),B(K,$,z,"",function(ue){return ue})):K!=null&&(P(K)&&(K=A(K,z+(K.key==null||L&&L.key===K.key?"":(""+K.key).replace(F,"$&/")+"/")+X)),$.push(K)),1;X=0;var te=U===""?".":U+":";if(C(L))for(var ie=0;ie<L.length;ie++)U=L[ie],ne=te+Q(U,ie),X+=B(U,$,z,ne,K);else if(ie=m(L),typeof ie=="function")for(L=ie.call(L),ie=0;!(U=L.next()).done;)U=U.value,ne=te+Q(U,ie++),X+=B(U,$,z,ne,K);else if(ne==="object"){if(typeof L.then=="function")return B(q(L),$,z,U,K);throw $=String(L),Error("Objects are not valid as a React child (found: "+($==="[object Object]"?"object with keys {"+Object.keys(L).join(", ")+"}":$)+"). If you meant to render a collection of children, use an array instead.")}return X}function V(L,$,z){if(L==null)return L;var U=[],K=0;return B(L,U,"","",function(ne){return $.call(z,ne,K++)}),U}function H(L){if(L._status===-1){var $=L._result;$=$(),$.then(function(z){(L._status===0||L._status===-1)&&(L._status=1,L._result=z)},function(z){(L._status===0||L._status===-1)&&(L._status=2,L._result=z)}),L._status===-1&&(L._status=0,L._result=$)}if(L._status===1)return L._result.default;throw L._result}var M=typeof reportError=="function"?reportError:function(L){if(typeof window=="object"&&typeof window.ErrorEvent=="function"){var $=new window.ErrorEvent("error",{bubbles:!0,cancelable:!0,message:typeof L=="object"&&L!==null&&typeof L.message=="string"?String(L.message):String(L),error:L});if(!window.dispatchEvent($))return}else if(typeof e=="object"&&typeof e.emit=="function"){e.emit("uncaughtException",L);return}console.error(L)},G={map:V,forEach:function(L,$,z){V(L,function(){$.apply(this,arguments)},z)},count:function(L){var $=0;return V(L,function(){$++}),$},toArray:function(L){return V(L,function($){return $})||[]},only:function(L){if(!P(L))throw Error("React.Children.only expected to receive a single React element child.");return L}};return Jr.Activity=h,Jr.Children=G,Jr.Component=b,Jr.Fragment=r,Jr.Profiler=i,Jr.PureComponent=k,Jr.StrictMode=s,Jr.Suspense=u,Jr.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=_,Jr.__COMPILER_RUNTIME={__proto__:null,c:function(L){return _.H.useMemoCache(L)}},Jr.cache=function(L){return function(){return L.apply(null,arguments)}},Jr.cacheSignal=function(){return null},Jr.cloneElement=function(L,$,z){if(L==null)throw Error("The argument must be a React element, but you passed "+L+".");var U=y({},L.props),K=L.key;if($!=null)for(ne in $.key!==void 0&&(K=""+$.key),$)!N.call($,ne)||ne==="key"||ne==="__self"||ne==="__source"||ne==="ref"&&$.ref===void 0||(U[ne]=$[ne]);var ne=arguments.length-2;if(ne===1)U.children=z;else if(1<ne){for(var X=Array(ne),te=0;te<ne;te++)X[te]=arguments[te+2];U.children=X}return I(L.type,K,U)},Jr.createContext=function(L){return L={$$typeof:l,_currentValue:L,_currentValue2:L,_threadCount:0,Provider:null,Consumer:null},L.Provider=L,L.Consumer={$$typeof:o,_context:L},L},Jr.createElement=function(L,$,z){var U,K={},ne=null;if($!=null)for(U in $.key!==void 0&&(ne=""+$.key),$)N.call($,U)&&U!=="key"&&U!=="__self"&&U!=="__source"&&(K[U]=$[U]);var X=arguments.length-2;if(X===1)K.children=z;else if(1<X){for(var te=Array(X),ie=0;ie<X;ie++)te[ie]=arguments[ie+2];K.children=te}if(L&&L.defaultProps)for(U in X=L.defaultProps,X)K[U]===void 0&&(K[U]=X[U]);return I(L,ne,K)},Jr.createRef=function(){return{current:null}},Jr.forwardRef=function(L){return{$$typeof:c,render:L}},Jr.isValidElement=P,Jr.lazy=function(L){return{$$typeof:f,_payload:{_status:-1,_result:L},_init:H}},Jr.memo=function(L,$){return{$$typeof:d,type:L,compare:$===void 0?null:$}},Jr.startTransition=function(L){var $=_.T,z={};_.T=z;try{var U=L(),K=_.S;K!==null&&K(z,U),typeof U=="object"&&U!==null&&typeof U.then=="function"&&U.then(T,M)}catch(ne){M(ne)}finally{$!==null&&z.types!==null&&($.types=z.types),_.T=$}},Jr.unstable_useCacheRefresh=function(){return _.H.useCacheRefresh()},Jr.use=function(L){return _.H.use(L)},Jr.useActionState=function(L,$,z){return _.H.useActionState(L,$,z)},Jr.useCallback=function(L,$){return _.H.useCallback(L,$)},Jr.useContext=function(L){return _.H.useContext(L)},Jr.useDebugValue=function(){},Jr.useDeferredValue=function(L,$){return _.H.useDeferredValue(L,$)},Jr.useEffect=function(L,$){return _.H.useEffect(L,$)},Jr.useEffectEvent=function(L){return _.H.useEffectEvent(L)},Jr.useId=function(){return _.H.useId()},Jr.useImperativeHandle=function(L,$,z){return _.H.useImperativeHandle(L,$,z)},Jr.useInsertionEffect=function(L,$){return _.H.useInsertionEffect(L,$)},Jr.useLayoutEffect=function(L,$){return _.H.useLayoutEffect(L,$)},Jr.useMemo=function(L,$){return _.H.useMemo(L,$)},Jr.useOptimistic=function(L,$){return _.H.useOptimistic(L,$)},Jr.useReducer=function(L,$,z){return _.H.useReducer(L,$,z)},Jr.useRef=function(L){return _.H.useRef(L)},Jr.useState=function(L){return _.H.useState(L)},Jr.useSyncExternalStore=function(L,$,z){return _.H.useSyncExternalStore(L,$,z)},Jr.useTransition=function(){return _.H.useTransition()},Jr.version="19.2.7",Jr}var iMe;function QA(){return iMe||(iMe=1,une.exports=tHt()),une.exports}var g=QA();const Me=Sv(g),ZA=XWt({__proto__:null,default:Me},[g]);var dne={exports:{}},dR={},fne={exports:{}},hne={};var oMe;function nHt(){return oMe||(oMe=1,(function(e){function t(q,B){var V=q.length;q.push(B);e:for(;0<V;){var H=V-1>>>1,M=q[H];if(0<s(M,B))q[H]=B,q[V]=M,V=H;else break e}}function n(q){return q.length===0?null:q[0]}function r(q){if(q.length===0)return null;var B=q[0],V=q.pop();if(V!==B){q[0]=V;e:for(var H=0,M=q.length,G=M>>>1;H<G;){var L=2*(H+1)-1,$=q[L],z=L+1,U=q[z];if(0>s($,V))z<M&&0>s(U,$)?(q[H]=U,q[z]=V,H=z):(q[H]=$,q[L]=V,H=L);else if(z<M&&0>s(U,V))q[H]=U,q[z]=V,H=z;else break e}}return B}function s(q,B){var V=q.sortIndex-B.sortIndex;return V!==0?V:q.id-B.id}if(e.unstable_now=void 0,typeof performance=="object"&&typeof performance.now=="function"){var i=performance;e.unstable_now=function(){return i.now()}}else{var o=Date,l=o.now();e.unstable_now=function(){return o.now()-l}}var c=[],u=[],d=1,f=null,h=3,p=!1,m=!1,v=!1,y=!1,x=typeof setTimeout=="function"?setTimeout:null,b=typeof clearTimeout=="function"?clearTimeout:null,S=typeof setImmediate<"u"?setImmediate:null;function k(q){for(var B=n(u);B!==null;){if(B.callback===null)r(u);else if(B.startTime<=q)r(u),B.sortIndex=B.expirationTime,t(c,B);else break;B=n(u)}}function j(q){if(v=!1,k(q),!m)if(n(c)!==null)m=!0,C||(C=!0,P());else{var B=n(u);B!==null&&Q(j,B.startTime-q)}}var C=!1,T=-1,_=5,N=-1;function I(){return y?!0:!(e.unstable_now()-N<_)}function A(){if(y=!1,C){var q=e.unstable_now();N=q;var B=!0;try{e:{m=!1,v&&(v=!1,b(T),T=-1),p=!0;var V=h;try{t:{for(k(q),f=n(c);f!==null&&!(f.expirationTime>q&&I());){var H=f.callback;if(typeof H=="function"){f.callback=null,h=f.priorityLevel;var M=H(f.expirationTime<=q);if(q=e.unstable_now(),typeof M=="function"){f.callback=M,k(q),B=!0;break t}f===n(c)&&r(c),k(q)}else r(c);f=n(c)}if(f!==null)B=!0;else{var G=n(u);G!==null&&Q(j,G.startTime-q),B=!1}}break e}finally{f=null,h=V,p=!1}B=void 0}}finally{B?P():C=!1}}}var P;if(typeof S=="function")P=function(){S(A)};else if(typeof MessageChannel<"u"){var D=new MessageChannel,F=D.port2;D.port1.onmessage=A,P=function(){F.postMessage(null)}}else P=function(){x(A,0)};function Q(q,B){T=x(function(){q(e.unstable_now())},B)}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(q){q.callback=null},e.unstable_forceFrameRate=function(q){0>q||125<q?console.error("forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported"):_=0<q?Math.floor(1e3/q):5},e.unstable_getCurrentPriorityLevel=function(){return h},e.unstable_next=function(q){switch(h){case 1:case 2:case 3:var B=3;break;default:B=h}var V=h;h=B;try{return q()}finally{h=V}},e.unstable_requestPaint=function(){y=!0},e.unstable_runWithPriority=function(q,B){switch(q){case 1:case 2:case 3:case 4:case 5:break;default:q=3}var V=h;h=q;try{return B()}finally{h=V}},e.unstable_scheduleCallback=function(q,B,V){var H=e.unstable_now();switch(typeof V=="object"&&V!==null?(V=V.delay,V=typeof V=="number"&&0<V?H+V:H):V=H,q){case 1:var M=-1;break;case 2:M=250;break;case 5:M=1073741823;break;case 4:M=1e4;break;default:M=5e3}return M=V+M,q={id:d++,callback:B,priorityLevel:q,startTime:V,expirationTime:M,sortIndex:-1},V>H?(q.sortIndex=V,t(u,q),n(c)===null&&q===n(u)&&(v?(b(T),T=-1):v=!0,Q(j,V-H))):(q.sortIndex=M,t(c,q),m||p||(m=!0,C||(C=!0,P()))),q},e.unstable_shouldYield=I,e.unstable_wrapCallback=function(q){var B=h;return function(){var V=h;h=B;try{return q.apply(this,arguments)}finally{h=V}}}})(hne)),hne}var aMe;function rHt(){return aMe||(aMe=1,fne.exports=nHt()),fne.exports}var pne={exports:{}},Bu={};var lMe;function sHt(){if(lMe)return Bu;lMe=1;var e=QA();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 i(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 o=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 Bu.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=r,Bu.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 i(c,u,null,d)},Bu.flushSync=function(c){var u=o.T,d=r.p;try{if(o.T=null,r.p=2,c)return c()}finally{o.T=u,r.p=d,r.d.f()}},Bu.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))},Bu.prefetchDNS=function(c){typeof c=="string"&&r.d.D(c)},Bu.preinit=function(c,u){if(typeof c=="string"&&u&&typeof u.as=="string"){var d=u.as,f=l(d,u.crossOrigin),h=typeof u.integrity=="string"?u.integrity:void 0,p=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:h,fetchPriority:p}):d==="script"&&r.d.X(c,{crossOrigin:f,integrity:h,fetchPriority:p,nonce:typeof u.nonce=="string"?u.nonce:void 0})}},Bu.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)},Bu.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})}},Bu.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)},Bu.requestFormReset=function(c){r.d.r(c)},Bu.unstable_batchedUpdates=function(c,u){return c(u)},Bu.useFormState=function(c,u,d){return o.H.useFormState(c,u,d)},Bu.useFormStatus=function(){return o.H.useHostTransitionStatus()},Bu.version="19.2.7",Bu}var cMe;function Gnt(){if(cMe)return pne.exports;cMe=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(),pne.exports=sHt(),pne.exports}var uMe;function iHt(){if(uMe)return dR;uMe=1;var e={env:{}};var t=rHt(),n=QA(),r=Gnt();function s(w){var O="https://react.dev/errors/"+w;if(1<arguments.length){O+="?args[]="+encodeURIComponent(arguments[1]);for(var E=2;E<arguments.length;E++)O+="&args[]="+encodeURIComponent(arguments[E])}return"Minified React error #"+w+"; visit "+O+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings."}function i(w){return!(!w||w.nodeType!==1&&w.nodeType!==9&&w.nodeType!==11)}function o(w){var O=w,E=w;if(w.alternate)for(;O.return;)O=O.return;else{w=O;do O=w,(O.flags&4098)!==0&&(E=O.return),w=O.return;while(w)}return O.tag===3?E:null}function l(w){if(w.tag===13){var O=w.memoizedState;if(O===null&&(w=w.alternate,w!==null&&(O=w.memoizedState)),O!==null)return O.dehydrated}return null}function c(w){if(w.tag===31){var O=w.memoizedState;if(O===null&&(w=w.alternate,w!==null&&(O=w.memoizedState)),O!==null)return O.dehydrated}return null}function u(w){if(o(w)!==w)throw Error(s(188))}function d(w){var O=w.alternate;if(!O){if(O=o(w),O===null)throw Error(s(188));return O!==w?null:w}for(var E=w,R=O;;){var W=E.return;if(W===null)break;var J=W.alternate;if(J===null){if(R=W.return,R!==null){E=R;continue}break}if(W.child===J.child){for(J=W.child;J;){if(J===E)return u(W),w;if(J===R)return u(W),O;J=J.sibling}throw Error(s(188))}if(E.return!==R.return)E=W,R=J;else{for(var oe=!1,be=W.child;be;){if(be===E){oe=!0,E=W,R=J;break}if(be===R){oe=!0,R=W,E=J;break}be=be.sibling}if(!oe){for(be=J.child;be;){if(be===E){oe=!0,E=J,R=W;break}if(be===R){oe=!0,R=J,E=W;break}be=be.sibling}if(!oe)throw Error(s(189))}}if(E.alternate!==R)throw Error(s(190))}if(E.tag!==3)throw Error(s(188));return E.stateNode.current===E?w:O}function f(w){var O=w.tag;if(O===5||O===26||O===27||O===6)return w;for(w=w.child;w!==null;){if(O=f(w),O!==null)return O;w=w.sibling}return null}var h=Object.assign,p=Symbol.for("react.element"),m=Symbol.for("react.transitional.element"),v=Symbol.for("react.portal"),y=Symbol.for("react.fragment"),x=Symbol.for("react.strict_mode"),b=Symbol.for("react.profiler"),S=Symbol.for("react.consumer"),k=Symbol.for("react.context"),j=Symbol.for("react.forward_ref"),C=Symbol.for("react.suspense"),T=Symbol.for("react.suspense_list"),_=Symbol.for("react.memo"),N=Symbol.for("react.lazy"),I=Symbol.for("react.activity"),A=Symbol.for("react.memo_cache_sentinel"),P=Symbol.iterator;function D(w){return w===null||typeof w!="object"?null:(w=P&&w[P]||w["@@iterator"],typeof w=="function"?w:null)}var F=Symbol.for("react.client.reference");function Q(w){if(w==null)return null;if(typeof w=="function")return w.$$typeof===F?null:w.displayName||w.name||null;if(typeof w=="string")return w;switch(w){case y:return"Fragment";case b:return"Profiler";case x:return"StrictMode";case C:return"Suspense";case T:return"SuspenseList";case I:return"Activity"}if(typeof w=="object")switch(w.$$typeof){case v:return"Portal";case k:return w.displayName||"Context";case S:return(w._context.displayName||"Context")+".Consumer";case j:var O=w.render;return w=w.displayName,w||(w=O.displayName||O.name||"",w=w!==""?"ForwardRef("+w+")":"ForwardRef"),w;case _:return O=w.displayName||null,O!==null?O:Q(w.type)||"Memo";case N:O=w._payload,w=w._init;try{return Q(w(O))}catch{}}return null}var q=Array.isArray,B=n.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,V=r.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,H={pending:!1,data:null,method:null,action:null},M=[],G=-1;function L(w){return{current:w}}function $(w){0>G||(w.current=M[G],M[G]=null,G--)}function z(w,O){G++,M[G]=w.current,w.current=O}var U=L(null),K=L(null),ne=L(null),X=L(null);function te(w,O){switch(z(ne,O),z(K,w),z(U,null),O.nodeType){case 9:case 11:w=(w=O.documentElement)&&(w=w.namespaceURI)?jRe(w):0;break;default:if(w=O.tagName,O=O.namespaceURI)O=jRe(O),w=CRe(O,w);else switch(w){case"svg":w=1;break;case"math":w=2;break;default:w=0}}$(U),z(U,w)}function ie(){$(U),$(K),$(ne)}function ue(w){w.memoizedState!==null&&z(X,w);var O=U.current,E=CRe(O,w.type);O!==E&&(z(K,w),z(U,E))}function ee(w){K.current===w&&($(U),$(K)),X.current===w&&($(X),oR._currentValue=H)}var se,re;function ae(w){if(se===void 0)try{throw Error()}catch(E){var O=E.stack.trim().match(/\n( *(at )?)/);se=O&&O[1]||"",re=-1<E.stack.indexOf(`
|
|
3
3
|
at`)?" (<anonymous>)":-1<E.stack.indexOf("@")?"@unknown:0:0":""}return`
|
|
4
4
|
`+se+w+re}var he=!1;function ve(w,O){if(!w||he)return"";he=!0;var E=Error.prepareStackTrace;Error.prepareStackTrace=void 0;try{var R={DetermineComponentFrameRoot:function(){try{if(O){var Lt=function(){throw Error()};if(Object.defineProperty(Lt.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(Lt,[])}catch(bt){var ht=bt}Reflect.construct(w,[],Lt)}else{try{Lt.call()}catch(bt){ht=bt}w.call(Lt.prototype)}}else{try{throw Error()}catch(bt){ht=bt}(Lt=w())&&typeof Lt.catch=="function"&&Lt.catch(function(){})}}catch(bt){if(bt&&ht&&typeof bt.stack=="string")return[bt.stack,ht.stack]}return[null,null]}};R.DetermineComponentFrameRoot.displayName="DetermineComponentFrameRoot";var W=Object.getOwnPropertyDescriptor(R.DetermineComponentFrameRoot,"name");W&&W.configurable&&Object.defineProperty(R.DetermineComponentFrameRoot,"name",{value:"DetermineComponentFrameRoot"});var J=R.DetermineComponentFrameRoot(),oe=J[0],be=J[1];if(oe&&be){var qe=oe.split(`
|
|
@@ -254,7 +254,7 @@ Error message: ${Tlt(n)}`,cause:n}),this[Dlt]=!0,this.value=t}static isInstance(
|
|
|
254
254
|
|
|
255
255
|
attempted value: ${o}
|
|
256
256
|
`+(l!==o?`result of cast: ${l}`:""))}return i}_cast(t,n){let r=t===void 0?t:this.transforms.reduce((s,i)=>i.call(this,s,t,this),t);return r===void 0&&(r=this.getDefault(n)),r}_validate(t,n={},r,s){let{path:i,originalValue:o=t,strict:l=this.spec.strict}=n,c=t;l||(c=this._cast(c,Object.assign({assert:!1},n)));let u=[];for(let d of Object.values(this.internalTests))d&&u.push(d);this.runTests({path:i,value:c,originalValue:o,options:n,tests:u},r,d=>{if(d.length)return s(d,c);this.runTests({path:i,value:c,originalValue:o,options:n,tests:this.tests},r,s)})}runTests(t,n,r){let s=!1,{tests:i,value:o,originalValue:l,path:c,options:u}=t,d=v=>{s||(s=!0,n(v,o))},f=v=>{s||(s=!0,r(v,o))},h=i.length,p=[];if(!h)return f([]);let m={value:o,originalValue:l,path:c,options:u,schema:this};for(let v=0;v<i.length;v++){const y=i[v];y(m,d,function(b){b&&(Array.isArray(b)?p.push(...b):p.push(b)),--h<=0&&f(p)})}}asNestedTest({key:t,index:n,parent:r,parentPath:s,originalParent:i,options:o}){const l=t??n;if(l==null)throw TypeError("Must include `key` or `index` for nested validations");const c=typeof l=="number";let u=r[l];const d=Object.assign({},o,{strict:!0,parent:r,value:u,originalValue:i[l],key:void 0,[c?"index":"key"]:l,path:c||l.includes(".")?`${s||""}[${c?l:`"${l}"`}]`:(s?`${s}.`:"")+t});return(f,h,p)=>this.resolve(d)._validate(u,d,h,p)}validate(t,n){var r;let s=this.resolve(Object.assign({},n,{value:t})),i=(r=n?.disableStackTrace)!=null?r:s.spec.disableStackTrace;return new Promise((o,l)=>s._validate(t,n,(c,u)=>{rm.isError(c)&&(c.value=u),l(c)},(c,u)=>{c.length?l(new rm(c,u,void 0,void 0,i)):o(u)}))}validateSync(t,n){var r;let s=this.resolve(Object.assign({},n,{value:t})),i,o=(r=n?.disableStackTrace)!=null?r:s.spec.disableStackTrace;return s._validate(t,Object.assign({},n,{sync:!0}),(l,c)=>{throw rm.isError(l)&&(l.value=c),l},(l,c)=>{if(l.length)throw new rm(l,t,void 0,void 0,o);i=c}),i}isValid(t,n){return this.validate(t,n).then(()=>!0,r=>{if(rm.isError(r))return!1;throw r})}isValidSync(t,n){try{return this.validateSync(t,n),!0}catch(r){if(rm.isError(r))return!1;throw r}}_getDefault(t){let n=this.spec.default;return n==null?n:typeof n=="function"?n.call(this,t):JE(n)}getDefault(t){return this.resolve(t||{})._getDefault(t)}default(t){return arguments.length===0?this._getDefault():this.clone({default:t})}strict(t=!0){return this.clone({strict:t})}nullability(t,n){const r=this.clone({nullable:t});return r.internalTests.nullable=ZT({message:n,name:"nullable",test(s){return s===null?this.schema.spec.nullable:!0}}),r}optionality(t,n){const r=this.clone({optional:t});return r.internalTests.optionality=ZT({message:n,name:"optionality",test(s){return s===void 0?this.schema.spec.optional:!0}}),r}optional(){return this.optionality(!0)}defined(t=Tb.defined){return this.optionality(!1,t)}nullable(){return this.nullability(!0)}nonNullable(t=Tb.notNull){return this.nullability(!1,t)}required(t=Tb.required){return this.clone().withMutation(n=>n.nonNullable(t).defined(t))}notRequired(){return this.clone().withMutation(t=>t.nullable().optional())}transform(t){let n=this.clone();return n.transforms.push(t),n}test(...t){let n;if(t.length===1?typeof t[0]=="function"?n={test:t[0]}:n=t[0]:t.length===2?n={name:t[0],test:t[1]}:n={name:t[0],message:t[1],test:t[2]},n.message===void 0&&(n.message=Tb.default),typeof n.test!="function")throw new TypeError("`test` is a required parameters");let r=this.clone(),s=ZT(n),i=n.exclusive||n.name&&r.exclusiveTests[n.name]===!0;if(n.exclusive&&!n.name)throw new TypeError("Exclusive tests must provide a unique `name` identifying the test");return n.name&&(r.exclusiveTests[n.name]=!!n.exclusive),r.tests=r.tests.filter(o=>!(o.OPTIONS.name===n.name&&(i||o.OPTIONS.test===s.OPTIONS.test))),r.tests.push(s),r}when(t,n){!Array.isArray(t)&&typeof t!="string"&&(n=t,t=".");let r=this.clone(),s=g1t(t).map(i=>new AL(i));return s.forEach(i=>{i.isSibling&&r.deps.push(i.key)}),r.conditions.push(typeof n=="function"?new wBe(s,n):wBe.fromOptions(s,n)),r}typeError(t){let n=this.clone();return n.internalTests.typeError=ZT({message:t,name:"typeError",skipAbsent:!0,test(r){return this.schema._typeCheck(r)?!0:this.createError({params:{type:this.schema.type}})}}),n}oneOf(t,n=Tb.oneOf){let r=this.clone();return t.forEach(s=>{r._whitelist.add(s),r._blacklist.delete(s)}),r.internalTests.whiteList=ZT({message:n,name:"oneOf",skipAbsent:!0,test(s){let i=this.schema._whitelist,o=i.resolveAll(this.resolve);return o.includes(s)?!0:this.createError({params:{values:Array.from(i).join(", "),resolved:o}})}}),r}notOneOf(t,n=Tb.notOneOf){let r=this.clone();return t.forEach(s=>{r._blacklist.add(s),r._whitelist.delete(s)}),r.internalTests.blacklist=ZT({message:n,name:"notOneOf",test(s){let i=this.schema._blacklist,o=i.resolveAll(this.resolve);return o.includes(s)?this.createError({params:{values:Array.from(i).join(", "),resolved:o}}):!0}}),r}strip(t=!0){let n=this.clone();return n.spec.strip=t,n}describe(t){const n=(t?this.resolve(t):this).clone(),{label:r,meta:s,optional:i,nullable:o}=n.spec;return{meta:s,label:r,optional:i,nullable:o,default:n.getDefault(t),type:n.type,oneOf:n._whitelist.describe(),notOneOf:n._blacklist.describe(),tests:n.tests.map(c=>({name:c.OPTIONS.name,params:c.OPTIONS.params})).filter((c,u,d)=>d.findIndex(f=>f.name===c.name)===u)}}};TC.prototype.__isYupSchema__=!0;for(const e of["validate","validateSync"])TC.prototype[`${e}At`]=function(t,n,r={}){const{parent:s,parentPath:i,schema:o}=zJn(this,t,n,r.context);return o[e](s&&s[i],Object.assign({},r,{parent:s,path:t}))};for(const e of["equals","is"])TC.prototype[e]=TC.prototype.oneOf;for(const e of["not","nope"])TC.prototype[e]=TC.prototype.notOneOf;var FJn=/^(\d{4}|[+-]\d{6})(?:-?(\d{2})(?:-?(\d{2}))?)?(?:[ T]?(\d{2}):?(\d{2})(?::?(\d{2})(?:[,.](\d{1,}))?)?(?:(Z)|([+-])(\d{2})(?::?(\d{2}))?)?)?$/;function BJn(e){const t=VJn(e);if(!t)return Date.parse?Date.parse(e):Number.NaN;if(t.z===void 0&&t.plusMinus===void 0)return new Date(t.year,t.month,t.day,t.hour,t.minute,t.second,t.millisecond).valueOf();let n=0;return t.z!=="Z"&&t.plusMinus!==void 0&&(n=t.hourOffset*60+t.minuteOffset,t.plusMinus==="+"&&(n=0-n)),Date.UTC(t.year,t.month,t.day,t.hour,t.minute+n,t.second,t.millisecond)}function VJn(e){var t,n;const r=FJn.exec(e);return r?{year:cb(r[1]),month:cb(r[2],1)-1,day:cb(r[3],1),hour:cb(r[4]),minute:cb(r[5]),second:cb(r[6]),millisecond:r[7]?cb(r[7].substring(0,3)):0,precision:(t=(n=r[7])==null?void 0:n.length)!=null?t:void 0,z:r[8]||void 0,plusMinus:r[9]||void 0,hourOffset:cb(r[10]),minuteOffset:cb(r[11])}:null}function cb(e,t=0){return Number(e)||t}var UJn=new Date(""),qJn=e=>Object.prototype.toString.call(e)==="[object Date]",QJn=class j1t extends TC{constructor(){super({type:"date",check(t){return qJn(t)&&!isNaN(t.getTime())}}),this.withMutation(()=>{this.transform((t,n,r)=>!r.spec.coerce||r.isType(t)||t===null?t:(t=BJn(t),isNaN(t)?j1t.INVALID_DATE:new Date(t)))})}prepareParam(t,n){let r;if(AL.isRef(t))r=t;else{let s=this.cast(t);if(!this._typeCheck(s))throw new TypeError(`\`${n}\` must be a Date or a value that can be \`cast()\` to a Date`);r=s}return r}min(t,n=xpe.min){let r=this.prepareParam(t,"min");return this.test({message:n,name:"min",exclusive:!0,params:{min:t},skipAbsent:!0,test(s){return s>=this.resolve(r)}})}max(t,n=xpe.max){let r=this.prepareParam(t,"max");return this.test({message:n,name:"max",exclusive:!0,params:{max:t},skipAbsent:!0,test(s){return s<=this.resolve(r)}})}};QJn.INVALID_DATE=UJn;function kBe(e,t){let n=e;for(const r of t)if(n=n[r],n===void 0)return;return n}function oD(e){if(e===null||typeof e!="object")return!1;const t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}const CSe=6048e5,ZJn=864e5,WJn=6e4,HJn=36e5,GJn=1e3,OBe=Symbol.for("constructDateFrom");function Lo(e,t){return typeof e=="function"?e(t):e&&typeof e=="object"&&OBe in e?e[OBe](t):e instanceof Date?new e.constructor(t):new Date(t)}function Hs(e,t){return Lo(t||e,e)}function cu(e,t,n){const r=Hs(e,n?.in);return isNaN(t)?Lo(n?.in||e,NaN):(t&&r.setDate(r.getDate()+t),r)}function gv(e,t,n){const r=Hs(e,n?.in);if(isNaN(t))return Lo(n?.in||e,NaN);if(!t)return r;const s=r.getDate(),i=Lo(n?.in||e,r.getTime());i.setMonth(r.getMonth()+t+1,0);const o=i.getDate();return s>=o?i:(r.setFullYear(i.getFullYear(),i.getMonth(),s),r)}let KJn={};function T_(){return KJn}function vp(e,t){const n=T_(),r=t?.weekStartsOn??t?.locale?.options?.weekStartsOn??n.weekStartsOn??n.locale?.options?.weekStartsOn??0,s=Hs(e,t?.in),i=s.getDay(),o=(i<r?7:0)+i-r;return s.setDate(s.getDate()-o),s.setHours(0,0,0,0),s}function k0(e,t){return vp(e,{...t,weekStartsOn:1})}function C1t(e,t){const n=Hs(e,t?.in),r=n.getFullYear(),s=Lo(n,0);s.setFullYear(r+1,0,4),s.setHours(0,0,0,0);const i=k0(s),o=Lo(n,0);o.setFullYear(r,0,4),o.setHours(0,0,0,0);const l=k0(o);return n.getTime()>=i.getTime()?r+1:n.getTime()>=l.getTime()?r:r-1}function YN(e){const t=Hs(e),n=new Date(Date.UTC(t.getFullYear(),t.getMonth(),t.getDate(),t.getHours(),t.getMinutes(),t.getSeconds(),t.getMilliseconds()));return n.setUTCFullYear(t.getFullYear()),+e-+n}function _P(e,...t){const n=Lo.bind(null,e||t.find(r=>typeof r=="object"));return t.map(n)}function XN(e,t){const n=Hs(e,t?.in);return n.setHours(0,0,0,0),n}function zy(e,t,n){const[r,s]=_P(n?.in,e,t),i=XN(r),o=XN(s),l=+i-YN(i),c=+o-YN(o);return Math.round((l-c)/ZJn)}function YJn(e,t){const n=C1t(e,t),r=Lo(e,0);return r.setFullYear(n,0,4),r.setHours(0,0,0,0),k0(r)}function bpe(e,t,n){return cu(e,t*7,n)}function XJn(e,t,n){return gv(e,t*12,n)}function JJn(e,t){let n,r=t?.in;return e.forEach(s=>{!r&&typeof s=="object"&&(r=Lo.bind(null,s));const i=Hs(s,r);(!n||n<i||isNaN(+i))&&(n=i)}),Lo(r,n||NaN)}function eer(e,t){let n,r=t?.in;return e.forEach(s=>{!r&&typeof s=="object"&&(r=Lo.bind(null,s));const i=Hs(s,r);(!n||n>i||isNaN(+i))&&(n=i)}),Lo(r,n||NaN)}function Qf(e,t,n){const[r,s]=_P(n?.in,e,t);return+XN(r)==+XN(s)}function _Se(e){return e instanceof Date||typeof e=="object"&&Object.prototype.toString.call(e)==="[object Date]"}function TSe(e){return!(!_Se(e)&&typeof e!="number"||isNaN(+Hs(e)))}function h5(e,t,n){const[r,s]=_P(n?.in,e,t),i=r.getFullYear()-s.getFullYear(),o=r.getMonth()-s.getMonth();return i*12+o}function ter(e,t,n){const[r,s]=_P(n?.in,e,t),i=vp(r,n),o=vp(s,n),l=+i-YN(i),c=+o-YN(o);return Math.round((l-c)/CSe)}function ESe(e,t){const n=Hs(e,t?.in),r=n.getMonth();return n.setFullYear(n.getFullYear(),r+1,0),n.setHours(23,59,59,999),n}function Xf(e,t){const n=Hs(e,t?.in);return n.setDate(1),n.setHours(0,0,0,0),n}function _1t(e,t){const n=Hs(e,t?.in);return n.setFullYear(n.getFullYear(),0,1),n.setHours(0,0,0,0),n}function ISe(e,t){const n=T_(),r=t?.weekStartsOn??t?.locale?.options?.weekStartsOn??n.weekStartsOn??n.locale?.options?.weekStartsOn??0,s=Hs(e,t?.in),i=s.getDay(),o=(i<r?-7:0)+6-(i-r);return s.setDate(s.getDate()+o),s.setHours(23,59,59,999),s}function T1t(e,t){return ISe(e,{...t,weekStartsOn:1})}const ner={lessThanXSeconds:{one:"less than a second",other:"less than {{count}} seconds"},xSeconds:{one:"1 second",other:"{{count}} seconds"},halfAMinute:"half a minute",lessThanXMinutes:{one:"less than a minute",other:"less than {{count}} minutes"},xMinutes:{one:"1 minute",other:"{{count}} minutes"},aboutXHours:{one:"about 1 hour",other:"about {{count}} hours"},xHours:{one:"1 hour",other:"{{count}} hours"},xDays:{one:"1 day",other:"{{count}} days"},aboutXWeeks:{one:"about 1 week",other:"about {{count}} weeks"},xWeeks:{one:"1 week",other:"{{count}} weeks"},aboutXMonths:{one:"about 1 month",other:"about {{count}} months"},xMonths:{one:"1 month",other:"{{count}} months"},aboutXYears:{one:"about 1 year",other:"about {{count}} years"},xYears:{one:"1 year",other:"{{count}} years"},overXYears:{one:"over 1 year",other:"over {{count}} years"},almostXYears:{one:"almost 1 year",other:"almost {{count}} years"}},rer=(e,t,n)=>{let r;const s=ner[e];return typeof s=="string"?r=s:t===1?r=s.one:r=s.other.replace("{{count}}",t.toString()),n?.addSuffix?n.comparison&&n.comparison>0?"in "+r:r+" ago":r};function yoe(e){return(t={})=>{const n=t.width?String(t.width):e.defaultWidth;return e.formats[n]||e.formats[e.defaultWidth]}}const ser={full:"EEEE, MMMM do, y",long:"MMMM do, y",medium:"MMM d, y",short:"MM/dd/yyyy"},ier={full:"h:mm:ss a zzzz",long:"h:mm:ss a z",medium:"h:mm:ss a",short:"h:mm a"},oer={full:"{{date}} 'at' {{time}}",long:"{{date}} 'at' {{time}}",medium:"{{date}}, {{time}}",short:"{{date}}, {{time}}"},aer={date:yoe({formats:ser,defaultWidth:"full"}),time:yoe({formats:ier,defaultWidth:"full"}),dateTime:yoe({formats:oer,defaultWidth:"full"})},ler={lastWeek:"'last' eeee 'at' p",yesterday:"'yesterday at' p",today:"'today at' p",tomorrow:"'tomorrow at' p",nextWeek:"eeee 'at' p",other:"P"},cer=(e,t,n,r)=>ler[e];function zR(e){return(t,n)=>{const r=n?.context?String(n.context):"standalone";let s;if(r==="formatting"&&e.formattingValues){const o=e.defaultFormattingWidth||e.defaultWidth,l=n?.width?String(n.width):o;s=e.formattingValues[l]||e.formattingValues[o]}else{const o=e.defaultWidth,l=n?.width?String(n.width):e.defaultWidth;s=e.values[l]||e.values[o]}const i=e.argumentCallback?e.argumentCallback(t):t;return s[i]}}const uer={narrow:["B","A"],abbreviated:["BC","AD"],wide:["Before Christ","Anno Domini"]},der={narrow:["1","2","3","4"],abbreviated:["Q1","Q2","Q3","Q4"],wide:["1st quarter","2nd quarter","3rd quarter","4th quarter"]},fer={narrow:["J","F","M","A","M","J","J","A","S","O","N","D"],abbreviated:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],wide:["January","February","March","April","May","June","July","August","September","October","November","December"]},her={narrow:["S","M","T","W","T","F","S"],short:["Su","Mo","Tu","We","Th","Fr","Sa"],abbreviated:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],wide:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]},per={narrow:{am:"a",pm:"p",midnight:"mi",noon:"n",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"},abbreviated:{am:"AM",pm:"PM",midnight:"midnight",noon:"noon",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"},wide:{am:"a.m.",pm:"p.m.",midnight:"midnight",noon:"noon",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"}},mer={narrow:{am:"a",pm:"p",midnight:"mi",noon:"n",morning:"in the morning",afternoon:"in the afternoon",evening:"in the evening",night:"at night"},abbreviated:{am:"AM",pm:"PM",midnight:"midnight",noon:"noon",morning:"in the morning",afternoon:"in the afternoon",evening:"in the evening",night:"at night"},wide:{am:"a.m.",pm:"p.m.",midnight:"midnight",noon:"noon",morning:"in the morning",afternoon:"in the afternoon",evening:"in the evening",night:"at night"}},ger=(e,t)=>{const n=Number(e),r=n%100;if(r>20||r<10)switch(r%10){case 1:return n+"st";case 2:return n+"nd";case 3:return n+"rd"}return n+"th"},ver={ordinalNumber:ger,era:zR({values:uer,defaultWidth:"wide"}),quarter:zR({values:der,defaultWidth:"wide",argumentCallback:e=>e-1}),month:zR({values:fer,defaultWidth:"wide"}),day:zR({values:her,defaultWidth:"wide"}),dayPeriod:zR({values:per,defaultWidth:"wide",formattingValues:mer,defaultFormattingWidth:"wide"})};function FR(e){return(t,n={})=>{const r=n.width,s=r&&e.matchPatterns[r]||e.matchPatterns[e.defaultMatchWidth],i=t.match(s);if(!i)return null;const o=i[0],l=r&&e.parsePatterns[r]||e.parsePatterns[e.defaultParseWidth],c=Array.isArray(l)?xer(l,f=>f.test(o)):yer(l,f=>f.test(o));let u;u=e.valueCallback?e.valueCallback(c):c,u=n.valueCallback?n.valueCallback(u):u;const d=t.slice(o.length);return{value:u,rest:d}}}function yer(e,t){for(const n in e)if(Object.prototype.hasOwnProperty.call(e,n)&&t(e[n]))return n}function xer(e,t){for(let n=0;n<e.length;n++)if(t(e[n]))return n}function ber(e){return(t,n={})=>{const r=t.match(e.matchPattern);if(!r)return null;const s=r[0],i=t.match(e.parsePattern);if(!i)return null;let o=e.valueCallback?e.valueCallback(i[0]):i[0];o=n.valueCallback?n.valueCallback(o):o;const l=t.slice(s.length);return{value:o,rest:l}}}const wer=/^(\d+)(th|st|nd|rd)?/i,Ser=/\d+/i,ker={narrow:/^(b|a)/i,abbreviated:/^(b\.?\s?c\.?|b\.?\s?c\.?\s?e\.?|a\.?\s?d\.?|c\.?\s?e\.?)/i,wide:/^(before christ|before common era|anno domini|common era)/i},Oer={any:[/^b/i,/^(a|c)/i]},jer={narrow:/^[1234]/i,abbreviated:/^q[1234]/i,wide:/^[1234](th|st|nd|rd)? quarter/i},Cer={any:[/1/i,/2/i,/3/i,/4/i]},_er={narrow:/^[jfmasond]/i,abbreviated:/^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/i,wide:/^(january|february|march|april|may|june|july|august|september|october|november|december)/i},Ter={narrow:[/^j/i,/^f/i,/^m/i,/^a/i,/^m/i,/^j/i,/^j/i,/^a/i,/^s/i,/^o/i,/^n/i,/^d/i],any:[/^ja/i,/^f/i,/^mar/i,/^ap/i,/^may/i,/^jun/i,/^jul/i,/^au/i,/^s/i,/^o/i,/^n/i,/^d/i]},Eer={narrow:/^[smtwf]/i,short:/^(su|mo|tu|we|th|fr|sa)/i,abbreviated:/^(sun|mon|tue|wed|thu|fri|sat)/i,wide:/^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)/i},Ier={narrow:[/^s/i,/^m/i,/^t/i,/^w/i,/^t/i,/^f/i,/^s/i],any:[/^su/i,/^m/i,/^tu/i,/^w/i,/^th/i,/^f/i,/^sa/i]},Ner={narrow:/^(a|p|mi|n|(in the|at) (morning|afternoon|evening|night))/i,any:/^([ap]\.?\s?m\.?|midnight|noon|(in the|at) (morning|afternoon|evening|night))/i},Aer={any:{am:/^a/i,pm:/^p/i,midnight:/^mi/i,noon:/^no/i,morning:/morning/i,afternoon:/afternoon/i,evening:/evening/i,night:/night/i}},Per={ordinalNumber:ber({matchPattern:wer,parsePattern:Ser,valueCallback:e=>parseInt(e,10)}),era:FR({matchPatterns:ker,defaultMatchWidth:"wide",parsePatterns:Oer,defaultParseWidth:"any"}),quarter:FR({matchPatterns:jer,defaultMatchWidth:"wide",parsePatterns:Cer,defaultParseWidth:"any",valueCallback:e=>e+1}),month:FR({matchPatterns:_er,defaultMatchWidth:"wide",parsePatterns:Ter,defaultParseWidth:"any"}),day:FR({matchPatterns:Eer,defaultMatchWidth:"wide",parsePatterns:Ier,defaultParseWidth:"any"}),dayPeriod:FR({matchPatterns:Ner,defaultMatchWidth:"any",parsePatterns:Aer,defaultParseWidth:"any"})},NSe={code:"en-US",formatDistance:rer,formatLong:aer,formatRelative:cer,localize:ver,match:Per,options:{weekStartsOn:0,firstWeekContainsDate:1}};function $er(e,t){const n=Hs(e,t?.in);return zy(n,_1t(n))+1}function ASe(e,t){const n=Hs(e,t?.in),r=+k0(n)-+YJn(n);return Math.round(r/CSe)+1}function PSe(e,t){const n=Hs(e,t?.in),r=n.getFullYear(),s=T_(),i=t?.firstWeekContainsDate??t?.locale?.options?.firstWeekContainsDate??s.firstWeekContainsDate??s.locale?.options?.firstWeekContainsDate??1,o=Lo(t?.in||e,0);o.setFullYear(r+1,0,i),o.setHours(0,0,0,0);const l=vp(o,t),c=Lo(t?.in||e,0);c.setFullYear(r,0,i),c.setHours(0,0,0,0);const u=vp(c,t);return+n>=+l?r+1:+n>=+u?r:r-1}function Rer(e,t){const n=T_(),r=t?.firstWeekContainsDate??t?.locale?.options?.firstWeekContainsDate??n.firstWeekContainsDate??n.locale?.options?.firstWeekContainsDate??1,s=PSe(e,t),i=Lo(t?.in||e,0);return i.setFullYear(s,0,r),i.setHours(0,0,0,0),vp(i,t)}function $Se(e,t){const n=Hs(e,t?.in),r=+vp(n,t)-+Rer(n,t);return Math.round(r/CSe)+1}function Xi(e,t){const n=e<0?"-":"",r=Math.abs(e).toString().padStart(t,"0");return n+r}const Bw={y(e,t){const n=e.getFullYear(),r=n>0?n:1-n;return Xi(t==="yy"?r%100:r,t.length)},M(e,t){const n=e.getMonth();return t==="M"?String(n+1):Xi(n+1,2)},d(e,t){return Xi(e.getDate(),t.length)},a(e,t){const n=e.getHours()/12>=1?"pm":"am";switch(t){case"a":case"aa":return n.toUpperCase();case"aaa":return n;case"aaaaa":return n[0];default:return n==="am"?"a.m.":"p.m."}},h(e,t){return Xi(e.getHours()%12||12,t.length)},H(e,t){return Xi(e.getHours(),t.length)},m(e,t){return Xi(e.getMinutes(),t.length)},s(e,t){return Xi(e.getSeconds(),t.length)},S(e,t){const n=t.length,r=e.getMilliseconds(),s=Math.trunc(r*Math.pow(10,n-3));return Xi(s,t.length)}},WT={midnight:"midnight",noon:"noon",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"},jBe={G:function(e,t,n){const r=e.getFullYear()>0?1:0;switch(t){case"G":case"GG":case"GGG":return n.era(r,{width:"abbreviated"});case"GGGGG":return n.era(r,{width:"narrow"});default:return n.era(r,{width:"wide"})}},y:function(e,t,n){if(t==="yo"){const r=e.getFullYear(),s=r>0?r:1-r;return n.ordinalNumber(s,{unit:"year"})}return Bw.y(e,t)},Y:function(e,t,n,r){const s=PSe(e,r),i=s>0?s:1-s;if(t==="YY"){const o=i%100;return Xi(o,2)}return t==="Yo"?n.ordinalNumber(i,{unit:"year"}):Xi(i,t.length)},R:function(e,t){const n=C1t(e);return Xi(n,t.length)},u:function(e,t){const n=e.getFullYear();return Xi(n,t.length)},Q:function(e,t,n){const r=Math.ceil((e.getMonth()+1)/3);switch(t){case"Q":return String(r);case"QQ":return Xi(r,2);case"Qo":return n.ordinalNumber(r,{unit:"quarter"});case"QQQ":return n.quarter(r,{width:"abbreviated",context:"formatting"});case"QQQQQ":return n.quarter(r,{width:"narrow",context:"formatting"});default:return n.quarter(r,{width:"wide",context:"formatting"})}},q:function(e,t,n){const r=Math.ceil((e.getMonth()+1)/3);switch(t){case"q":return String(r);case"qq":return Xi(r,2);case"qo":return n.ordinalNumber(r,{unit:"quarter"});case"qqq":return n.quarter(r,{width:"abbreviated",context:"standalone"});case"qqqqq":return n.quarter(r,{width:"narrow",context:"standalone"});default:return n.quarter(r,{width:"wide",context:"standalone"})}},M:function(e,t,n){const r=e.getMonth();switch(t){case"M":case"MM":return Bw.M(e,t);case"Mo":return n.ordinalNumber(r+1,{unit:"month"});case"MMM":return n.month(r,{width:"abbreviated",context:"formatting"});case"MMMMM":return n.month(r,{width:"narrow",context:"formatting"});default:return n.month(r,{width:"wide",context:"formatting"})}},L:function(e,t,n){const r=e.getMonth();switch(t){case"L":return String(r+1);case"LL":return Xi(r+1,2);case"Lo":return n.ordinalNumber(r+1,{unit:"month"});case"LLL":return n.month(r,{width:"abbreviated",context:"standalone"});case"LLLLL":return n.month(r,{width:"narrow",context:"standalone"});default:return n.month(r,{width:"wide",context:"standalone"})}},w:function(e,t,n,r){const s=$Se(e,r);return t==="wo"?n.ordinalNumber(s,{unit:"week"}):Xi(s,t.length)},I:function(e,t,n){const r=ASe(e);return t==="Io"?n.ordinalNumber(r,{unit:"week"}):Xi(r,t.length)},d:function(e,t,n){return t==="do"?n.ordinalNumber(e.getDate(),{unit:"date"}):Bw.d(e,t)},D:function(e,t,n){const r=$er(e);return t==="Do"?n.ordinalNumber(r,{unit:"dayOfYear"}):Xi(r,t.length)},E:function(e,t,n){const r=e.getDay();switch(t){case"E":case"EE":case"EEE":return n.day(r,{width:"abbreviated",context:"formatting"});case"EEEEE":return n.day(r,{width:"narrow",context:"formatting"});case"EEEEEE":return n.day(r,{width:"short",context:"formatting"});default:return n.day(r,{width:"wide",context:"formatting"})}},e:function(e,t,n,r){const s=e.getDay(),i=(s-r.weekStartsOn+8)%7||7;switch(t){case"e":return String(i);case"ee":return Xi(i,2);case"eo":return n.ordinalNumber(i,{unit:"day"});case"eee":return n.day(s,{width:"abbreviated",context:"formatting"});case"eeeee":return n.day(s,{width:"narrow",context:"formatting"});case"eeeeee":return n.day(s,{width:"short",context:"formatting"});default:return n.day(s,{width:"wide",context:"formatting"})}},c:function(e,t,n,r){const s=e.getDay(),i=(s-r.weekStartsOn+8)%7||7;switch(t){case"c":return String(i);case"cc":return Xi(i,t.length);case"co":return n.ordinalNumber(i,{unit:"day"});case"ccc":return n.day(s,{width:"abbreviated",context:"standalone"});case"ccccc":return n.day(s,{width:"narrow",context:"standalone"});case"cccccc":return n.day(s,{width:"short",context:"standalone"});default:return n.day(s,{width:"wide",context:"standalone"})}},i:function(e,t,n){const r=e.getDay(),s=r===0?7:r;switch(t){case"i":return String(s);case"ii":return Xi(s,t.length);case"io":return n.ordinalNumber(s,{unit:"day"});case"iii":return n.day(r,{width:"abbreviated",context:"formatting"});case"iiiii":return n.day(r,{width:"narrow",context:"formatting"});case"iiiiii":return n.day(r,{width:"short",context:"formatting"});default:return n.day(r,{width:"wide",context:"formatting"})}},a:function(e,t,n){const s=e.getHours()/12>=1?"pm":"am";switch(t){case"a":case"aa":return n.dayPeriod(s,{width:"abbreviated",context:"formatting"});case"aaa":return n.dayPeriod(s,{width:"abbreviated",context:"formatting"}).toLowerCase();case"aaaaa":return n.dayPeriod(s,{width:"narrow",context:"formatting"});default:return n.dayPeriod(s,{width:"wide",context:"formatting"})}},b:function(e,t,n){const r=e.getHours();let s;switch(r===12?s=WT.noon:r===0?s=WT.midnight:s=r/12>=1?"pm":"am",t){case"b":case"bb":return n.dayPeriod(s,{width:"abbreviated",context:"formatting"});case"bbb":return n.dayPeriod(s,{width:"abbreviated",context:"formatting"}).toLowerCase();case"bbbbb":return n.dayPeriod(s,{width:"narrow",context:"formatting"});default:return n.dayPeriod(s,{width:"wide",context:"formatting"})}},B:function(e,t,n){const r=e.getHours();let s;switch(r>=17?s=WT.evening:r>=12?s=WT.afternoon:r>=4?s=WT.morning:s=WT.night,t){case"B":case"BB":case"BBB":return n.dayPeriod(s,{width:"abbreviated",context:"formatting"});case"BBBBB":return n.dayPeriod(s,{width:"narrow",context:"formatting"});default:return n.dayPeriod(s,{width:"wide",context:"formatting"})}},h:function(e,t,n){if(t==="ho"){let r=e.getHours()%12;return r===0&&(r=12),n.ordinalNumber(r,{unit:"hour"})}return Bw.h(e,t)},H:function(e,t,n){return t==="Ho"?n.ordinalNumber(e.getHours(),{unit:"hour"}):Bw.H(e,t)},K:function(e,t,n){const r=e.getHours()%12;return t==="Ko"?n.ordinalNumber(r,{unit:"hour"}):Xi(r,t.length)},k:function(e,t,n){let r=e.getHours();return r===0&&(r=24),t==="ko"?n.ordinalNumber(r,{unit:"hour"}):Xi(r,t.length)},m:function(e,t,n){return t==="mo"?n.ordinalNumber(e.getMinutes(),{unit:"minute"}):Bw.m(e,t)},s:function(e,t,n){return t==="so"?n.ordinalNumber(e.getSeconds(),{unit:"second"}):Bw.s(e,t)},S:function(e,t){return Bw.S(e,t)},X:function(e,t,n){const r=e.getTimezoneOffset();if(r===0)return"Z";switch(t){case"X":return _Be(r);case"XXXX":case"XX":return RO(r);default:return RO(r,":")}},x:function(e,t,n){const r=e.getTimezoneOffset();switch(t){case"x":return _Be(r);case"xxxx":case"xx":return RO(r);default:return RO(r,":")}},O:function(e,t,n){const r=e.getTimezoneOffset();switch(t){case"O":case"OO":case"OOO":return"GMT"+CBe(r,":");default:return"GMT"+RO(r,":")}},z:function(e,t,n){const r=e.getTimezoneOffset();switch(t){case"z":case"zz":case"zzz":return"GMT"+CBe(r,":");default:return"GMT"+RO(r,":")}},t:function(e,t,n){const r=Math.trunc(+e/1e3);return Xi(r,t.length)},T:function(e,t,n){return Xi(+e,t.length)}};function CBe(e,t=""){const n=e>0?"-":"+",r=Math.abs(e),s=Math.trunc(r/60),i=r%60;return i===0?n+String(s):n+String(s)+t+Xi(i,2)}function _Be(e,t){return e%60===0?(e>0?"-":"+")+Xi(Math.abs(e)/60,2):RO(e,t)}function RO(e,t=""){const n=e>0?"-":"+",r=Math.abs(e),s=Xi(Math.trunc(r/60),2),i=Xi(r%60,2);return n+s+t+i}const TBe=(e,t)=>{switch(e){case"P":return t.date({width:"short"});case"PP":return t.date({width:"medium"});case"PPP":return t.date({width:"long"});default:return t.date({width:"full"})}},E1t=(e,t)=>{switch(e){case"p":return t.time({width:"short"});case"pp":return t.time({width:"medium"});case"ppp":return t.time({width:"long"});default:return t.time({width:"full"})}},Mer=(e,t)=>{const n=e.match(/(P+)(p+)?/)||[],r=n[1],s=n[2];if(!s)return TBe(e,t);let i;switch(r){case"P":i=t.dateTime({width:"short"});break;case"PP":i=t.dateTime({width:"medium"});break;case"PPP":i=t.dateTime({width:"long"});break;default:i=t.dateTime({width:"full"});break}return i.replace("{{date}}",TBe(r,t)).replace("{{time}}",E1t(s,t))},wpe={p:E1t,P:Mer},Der=/^D+$/,Ler=/^Y+$/,zer=["D","DD","YY","YYYY"];function I1t(e){return Der.test(e)}function N1t(e){return Ler.test(e)}function Spe(e,t,n){const r=Fer(e,t,n);if(console.warn(r),zer.includes(e))throw new RangeError(r)}function Fer(e,t,n){const r=e[0]==="Y"?"years":"days of the month";return`Use \`${e.toLowerCase()}\` instead of \`${e}\` (in \`${t}\`) for formatting ${r} to the input \`${n}\`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md`}const Ber=/[yYQqMLwIdDecihHKkms]o|(\w)\1*|''|'(''|[^'])+('|$)|./g,Ver=/P+p+|P+|p+|''|'(''|[^'])+('|$)|./g,Uer=/^'([^]*?)'?$/,qer=/''/g,Qer=/[a-zA-Z]/;function yk(e,t,n){const r=T_(),s=n?.locale??r.locale??NSe,i=n?.firstWeekContainsDate??n?.locale?.options?.firstWeekContainsDate??r.firstWeekContainsDate??r.locale?.options?.firstWeekContainsDate??1,o=n?.weekStartsOn??n?.locale?.options?.weekStartsOn??r.weekStartsOn??r.locale?.options?.weekStartsOn??0,l=Hs(e,n?.in);if(!TSe(l))throw new RangeError("Invalid time value");let c=t.match(Ver).map(d=>{const f=d[0];if(f==="p"||f==="P"){const h=wpe[f];return h(d,s.formatLong)}return d}).join("").match(Ber).map(d=>{if(d==="''")return{isToken:!1,value:"'"};const f=d[0];if(f==="'")return{isToken:!1,value:Zer(d)};if(jBe[f])return{isToken:!0,value:d};if(f.match(Qer))throw new RangeError("Format string contains an unescaped latin alphabet character `"+f+"`");return{isToken:!1,value:d}});s.localize.preprocessor&&(c=s.localize.preprocessor(l,c));const u={firstWeekContainsDate:i,weekStartsOn:o,locale:s};return c.map(d=>{if(!d.isToken)return d.value;const f=d.value;(!n?.useAdditionalWeekYearTokens&&N1t(f)||!n?.useAdditionalDayOfYearTokens&&I1t(f))&&Spe(f,t,String(e));const h=jBe[f[0]];return h(l,f,s.localize,u)}).join("")}function Zer(e){const t=e.match(Uer);return t?t[1].replace(qer,"'"):e}function Wer(e,t){const n=Hs(e,t?.in),r=n.getFullYear(),s=n.getMonth(),i=Lo(n,0);return i.setFullYear(r,s+1,0),i.setHours(0,0,0,0),i.getDate()}function Her(){return Object.assign({},T_())}function Ger(e,t){const n=Hs(e,t?.in).getDay();return n===0?7:n}function Ker(e){return Math.trunc(+Hs(e)/1e3)}function Yer(e,t){const n=Hs(e,t?.in),r=n.getMonth();return n.setFullYear(n.getFullYear(),r+1,0),n.setHours(0,0,0,0),Hs(n,t?.in)}function Xer(e,t){const n=Hs(e,t?.in);return ter(Yer(n,t),Xf(n,t),t)+1}function kpe(e,t){return+Hs(e)>+Hs(t)}function A1t(e,t){return+Hs(e)<+Hs(t)}function Jer(e,t){const n=etr(t)?new t(0):Lo(t,0);return n.setFullYear(e.getFullYear(),e.getMonth(),e.getDate()),n.setHours(e.getHours(),e.getMinutes(),e.getSeconds(),e.getMilliseconds()),n}function etr(e){return typeof e=="function"&&e.prototype?.constructor===e}const ttr=10;class P1t{subPriority=0;validate(t,n){return!0}}class ntr extends P1t{constructor(t,n,r,s,i){super(),this.value=t,this.validateValue=n,this.setValue=r,this.priority=s,i&&(this.subPriority=i)}validate(t,n){return this.validateValue(t,this.value,n)}set(t,n,r){return this.setValue(t,n,this.value,r)}}class rtr extends P1t{priority=ttr;subPriority=-1;constructor(t,n){super(),this.context=t||(r=>Lo(n,r))}set(t,n){return n.timestampIsSet?t:Lo(t,Jer(t,this.context))}}class Mi{run(t,n,r,s){const i=this.parse(t,n,r,s);return i?{setter:new ntr(i.value,this.validate,this.set,this.priority,this.subPriority),rest:i.rest}:null}validate(t,n,r){return!0}}class str extends Mi{priority=140;parse(t,n,r){switch(n){case"G":case"GG":case"GGG":return r.era(t,{width:"abbreviated"})||r.era(t,{width:"narrow"});case"GGGGG":return r.era(t,{width:"narrow"});default:return r.era(t,{width:"wide"})||r.era(t,{width:"abbreviated"})||r.era(t,{width:"narrow"})}}set(t,n,r){return n.era=r,t.setFullYear(r,0,1),t.setHours(0,0,0,0),t}incompatibleTokens=["R","u","t","T"]}const wl={month:/^(1[0-2]|0?\d)/,date:/^(3[0-1]|[0-2]?\d)/,dayOfYear:/^(36[0-6]|3[0-5]\d|[0-2]?\d?\d)/,week:/^(5[0-3]|[0-4]?\d)/,hour23h:/^(2[0-3]|[0-1]?\d)/,hour24h:/^(2[0-4]|[0-1]?\d)/,hour11h:/^(1[0-1]|0?\d)/,hour12h:/^(1[0-2]|0?\d)/,minute:/^[0-5]?\d/,second:/^[0-5]?\d/,singleDigit:/^\d/,twoDigits:/^\d{1,2}/,threeDigits:/^\d{1,3}/,fourDigits:/^\d{1,4}/,anyDigitsSigned:/^-?\d+/,singleDigitSigned:/^-?\d/,twoDigitsSigned:/^-?\d{1,2}/,threeDigitsSigned:/^-?\d{1,3}/,fourDigitsSigned:/^-?\d{1,4}/},Ty={basicOptionalMinutes:/^([+-])(\d{2})(\d{2})?|Z/,basic:/^([+-])(\d{2})(\d{2})|Z/,basicOptionalSeconds:/^([+-])(\d{2})(\d{2})((\d{2}))?|Z/,extended:/^([+-])(\d{2}):(\d{2})|Z/,extendedOptionalSeconds:/^([+-])(\d{2}):(\d{2})(:(\d{2}))?|Z/};function Sl(e,t){return e&&{value:t(e.value),rest:e.rest}}function Fa(e,t){const n=t.match(e);return n?{value:parseInt(n[0],10),rest:t.slice(n[0].length)}:null}function Ey(e,t){const n=t.match(e);if(!n)return null;if(n[0]==="Z")return{value:0,rest:t.slice(1)};const r=n[1]==="+"?1:-1,s=n[2]?parseInt(n[2],10):0,i=n[3]?parseInt(n[3],10):0,o=n[5]?parseInt(n[5],10):0;return{value:r*(s*HJn+i*WJn+o*GJn),rest:t.slice(n[0].length)}}function $1t(e){return Fa(wl.anyDigitsSigned,e)}function fl(e,t){switch(e){case 1:return Fa(wl.singleDigit,t);case 2:return Fa(wl.twoDigits,t);case 3:return Fa(wl.threeDigits,t);case 4:return Fa(wl.fourDigits,t);default:return Fa(new RegExp("^\\d{1,"+e+"}"),t)}}function tQ(e,t){switch(e){case 1:return Fa(wl.singleDigitSigned,t);case 2:return Fa(wl.twoDigitsSigned,t);case 3:return Fa(wl.threeDigitsSigned,t);case 4:return Fa(wl.fourDigitsSigned,t);default:return Fa(new RegExp("^-?\\d{1,"+e+"}"),t)}}function RSe(e){switch(e){case"morning":return 4;case"evening":return 17;case"pm":case"noon":case"afternoon":return 12;default:return 0}}function R1t(e,t){const n=t>0,r=n?t:1-t;let s;if(r<=50)s=e||100;else{const i=r+50,o=Math.trunc(i/100)*100,l=e>=i%100;s=e+o-(l?100:0)}return n?s:1-s}function M1t(e){return e%400===0||e%4===0&&e%100!==0}class itr extends Mi{priority=130;incompatibleTokens=["Y","R","u","w","I","i","e","c","t","T"];parse(t,n,r){const s=i=>({year:i,isTwoDigitYear:n==="yy"});switch(n){case"y":return Sl(fl(4,t),s);case"yo":return Sl(r.ordinalNumber(t,{unit:"year"}),s);default:return Sl(fl(n.length,t),s)}}validate(t,n){return n.isTwoDigitYear||n.year>0}set(t,n,r){const s=t.getFullYear();if(r.isTwoDigitYear){const o=R1t(r.year,s);return t.setFullYear(o,0,1),t.setHours(0,0,0,0),t}const i=!("era"in n)||n.era===1?r.year:1-r.year;return t.setFullYear(i,0,1),t.setHours(0,0,0,0),t}}class otr extends Mi{priority=130;parse(t,n,r){const s=i=>({year:i,isTwoDigitYear:n==="YY"});switch(n){case"Y":return Sl(fl(4,t),s);case"Yo":return Sl(r.ordinalNumber(t,{unit:"year"}),s);default:return Sl(fl(n.length,t),s)}}validate(t,n){return n.isTwoDigitYear||n.year>0}set(t,n,r,s){const i=PSe(t,s);if(r.isTwoDigitYear){const l=R1t(r.year,i);return t.setFullYear(l,0,s.firstWeekContainsDate),t.setHours(0,0,0,0),vp(t,s)}const o=!("era"in n)||n.era===1?r.year:1-r.year;return t.setFullYear(o,0,s.firstWeekContainsDate),t.setHours(0,0,0,0),vp(t,s)}incompatibleTokens=["y","R","u","Q","q","M","L","I","d","D","i","t","T"]}class atr extends Mi{priority=130;parse(t,n){return tQ(n==="R"?4:n.length,t)}set(t,n,r){const s=Lo(t,0);return s.setFullYear(r,0,4),s.setHours(0,0,0,0),k0(s)}incompatibleTokens=["G","y","Y","u","Q","q","M","L","w","d","D","e","c","t","T"]}class ltr extends Mi{priority=130;parse(t,n){return tQ(n==="u"?4:n.length,t)}set(t,n,r){return t.setFullYear(r,0,1),t.setHours(0,0,0,0),t}incompatibleTokens=["G","y","Y","R","w","I","i","e","c","t","T"]}class ctr extends Mi{priority=120;parse(t,n,r){switch(n){case"Q":case"QQ":return fl(n.length,t);case"Qo":return r.ordinalNumber(t,{unit:"quarter"});case"QQQ":return r.quarter(t,{width:"abbreviated",context:"formatting"})||r.quarter(t,{width:"narrow",context:"formatting"});case"QQQQQ":return r.quarter(t,{width:"narrow",context:"formatting"});default:return r.quarter(t,{width:"wide",context:"formatting"})||r.quarter(t,{width:"abbreviated",context:"formatting"})||r.quarter(t,{width:"narrow",context:"formatting"})}}validate(t,n){return n>=1&&n<=4}set(t,n,r){return t.setMonth((r-1)*3,1),t.setHours(0,0,0,0),t}incompatibleTokens=["Y","R","q","M","L","w","I","d","D","i","e","c","t","T"]}class utr extends Mi{priority=120;parse(t,n,r){switch(n){case"q":case"qq":return fl(n.length,t);case"qo":return r.ordinalNumber(t,{unit:"quarter"});case"qqq":return r.quarter(t,{width:"abbreviated",context:"standalone"})||r.quarter(t,{width:"narrow",context:"standalone"});case"qqqqq":return r.quarter(t,{width:"narrow",context:"standalone"});default:return r.quarter(t,{width:"wide",context:"standalone"})||r.quarter(t,{width:"abbreviated",context:"standalone"})||r.quarter(t,{width:"narrow",context:"standalone"})}}validate(t,n){return n>=1&&n<=4}set(t,n,r){return t.setMonth((r-1)*3,1),t.setHours(0,0,0,0),t}incompatibleTokens=["Y","R","Q","M","L","w","I","d","D","i","e","c","t","T"]}class dtr extends Mi{incompatibleTokens=["Y","R","q","Q","L","w","I","D","i","e","c","t","T"];priority=110;parse(t,n,r){const s=i=>i-1;switch(n){case"M":return Sl(Fa(wl.month,t),s);case"MM":return Sl(fl(2,t),s);case"Mo":return Sl(r.ordinalNumber(t,{unit:"month"}),s);case"MMM":return r.month(t,{width:"abbreviated",context:"formatting"})||r.month(t,{width:"narrow",context:"formatting"});case"MMMMM":return r.month(t,{width:"narrow",context:"formatting"});default:return r.month(t,{width:"wide",context:"formatting"})||r.month(t,{width:"abbreviated",context:"formatting"})||r.month(t,{width:"narrow",context:"formatting"})}}validate(t,n){return n>=0&&n<=11}set(t,n,r){return t.setMonth(r,1),t.setHours(0,0,0,0),t}}class ftr extends Mi{priority=110;parse(t,n,r){const s=i=>i-1;switch(n){case"L":return Sl(Fa(wl.month,t),s);case"LL":return Sl(fl(2,t),s);case"Lo":return Sl(r.ordinalNumber(t,{unit:"month"}),s);case"LLL":return r.month(t,{width:"abbreviated",context:"standalone"})||r.month(t,{width:"narrow",context:"standalone"});case"LLLLL":return r.month(t,{width:"narrow",context:"standalone"});default:return r.month(t,{width:"wide",context:"standalone"})||r.month(t,{width:"abbreviated",context:"standalone"})||r.month(t,{width:"narrow",context:"standalone"})}}validate(t,n){return n>=0&&n<=11}set(t,n,r){return t.setMonth(r,1),t.setHours(0,0,0,0),t}incompatibleTokens=["Y","R","q","Q","M","w","I","D","i","e","c","t","T"]}function htr(e,t,n){const r=Hs(e,n?.in),s=$Se(r,n)-t;return r.setDate(r.getDate()-s*7),Hs(r,n?.in)}class ptr extends Mi{priority=100;parse(t,n,r){switch(n){case"w":return Fa(wl.week,t);case"wo":return r.ordinalNumber(t,{unit:"week"});default:return fl(n.length,t)}}validate(t,n){return n>=1&&n<=53}set(t,n,r,s){return vp(htr(t,r,s),s)}incompatibleTokens=["y","R","u","q","Q","M","L","I","d","D","i","t","T"]}function mtr(e,t,n){const r=Hs(e,n?.in),s=ASe(r,n)-t;return r.setDate(r.getDate()-s*7),r}class gtr extends Mi{priority=100;parse(t,n,r){switch(n){case"I":return Fa(wl.week,t);case"Io":return r.ordinalNumber(t,{unit:"week"});default:return fl(n.length,t)}}validate(t,n){return n>=1&&n<=53}set(t,n,r){return k0(mtr(t,r))}incompatibleTokens=["y","Y","u","q","Q","M","L","w","d","D","e","c","t","T"]}const vtr=[31,28,31,30,31,30,31,31,30,31,30,31],ytr=[31,29,31,30,31,30,31,31,30,31,30,31];class xtr extends Mi{priority=90;subPriority=1;parse(t,n,r){switch(n){case"d":return Fa(wl.date,t);case"do":return r.ordinalNumber(t,{unit:"date"});default:return fl(n.length,t)}}validate(t,n){const r=t.getFullYear(),s=M1t(r),i=t.getMonth();return s?n>=1&&n<=ytr[i]:n>=1&&n<=vtr[i]}set(t,n,r){return t.setDate(r),t.setHours(0,0,0,0),t}incompatibleTokens=["Y","R","q","Q","w","I","D","i","e","c","t","T"]}class btr extends Mi{priority=90;subpriority=1;parse(t,n,r){switch(n){case"D":case"DD":return Fa(wl.dayOfYear,t);case"Do":return r.ordinalNumber(t,{unit:"date"});default:return fl(n.length,t)}}validate(t,n){const r=t.getFullYear();return M1t(r)?n>=1&&n<=366:n>=1&&n<=365}set(t,n,r){return t.setMonth(0,r),t.setHours(0,0,0,0),t}incompatibleTokens=["Y","R","q","Q","M","L","w","I","d","E","i","e","c","t","T"]}function MSe(e,t,n){const r=T_(),s=n?.weekStartsOn??n?.locale?.options?.weekStartsOn??r.weekStartsOn??r.locale?.options?.weekStartsOn??0,i=Hs(e,n?.in),o=i.getDay(),c=(t%7+7)%7,u=7-s,d=t<0||t>6?t-(o+u)%7:(c+u)%7-(o+u)%7;return cu(i,d,n)}class wtr extends Mi{priority=90;parse(t,n,r){switch(n){case"E":case"EE":case"EEE":return r.day(t,{width:"abbreviated",context:"formatting"})||r.day(t,{width:"short",context:"formatting"})||r.day(t,{width:"narrow",context:"formatting"});case"EEEEE":return r.day(t,{width:"narrow",context:"formatting"});case"EEEEEE":return r.day(t,{width:"short",context:"formatting"})||r.day(t,{width:"narrow",context:"formatting"});default:return r.day(t,{width:"wide",context:"formatting"})||r.day(t,{width:"abbreviated",context:"formatting"})||r.day(t,{width:"short",context:"formatting"})||r.day(t,{width:"narrow",context:"formatting"})}}validate(t,n){return n>=0&&n<=6}set(t,n,r,s){return t=MSe(t,r,s),t.setHours(0,0,0,0),t}incompatibleTokens=["D","i","e","c","t","T"]}class Str extends Mi{priority=90;parse(t,n,r,s){const i=o=>{const l=Math.floor((o-1)/7)*7;return(o+s.weekStartsOn+6)%7+l};switch(n){case"e":case"ee":return Sl(fl(n.length,t),i);case"eo":return Sl(r.ordinalNumber(t,{unit:"day"}),i);case"eee":return r.day(t,{width:"abbreviated",context:"formatting"})||r.day(t,{width:"short",context:"formatting"})||r.day(t,{width:"narrow",context:"formatting"});case"eeeee":return r.day(t,{width:"narrow",context:"formatting"});case"eeeeee":return r.day(t,{width:"short",context:"formatting"})||r.day(t,{width:"narrow",context:"formatting"});default:return r.day(t,{width:"wide",context:"formatting"})||r.day(t,{width:"abbreviated",context:"formatting"})||r.day(t,{width:"short",context:"formatting"})||r.day(t,{width:"narrow",context:"formatting"})}}validate(t,n){return n>=0&&n<=6}set(t,n,r,s){return t=MSe(t,r,s),t.setHours(0,0,0,0),t}incompatibleTokens=["y","R","u","q","Q","M","L","I","d","D","E","i","c","t","T"]}class ktr extends Mi{priority=90;parse(t,n,r,s){const i=o=>{const l=Math.floor((o-1)/7)*7;return(o+s.weekStartsOn+6)%7+l};switch(n){case"c":case"cc":return Sl(fl(n.length,t),i);case"co":return Sl(r.ordinalNumber(t,{unit:"day"}),i);case"ccc":return r.day(t,{width:"abbreviated",context:"standalone"})||r.day(t,{width:"short",context:"standalone"})||r.day(t,{width:"narrow",context:"standalone"});case"ccccc":return r.day(t,{width:"narrow",context:"standalone"});case"cccccc":return r.day(t,{width:"short",context:"standalone"})||r.day(t,{width:"narrow",context:"standalone"});default:return r.day(t,{width:"wide",context:"standalone"})||r.day(t,{width:"abbreviated",context:"standalone"})||r.day(t,{width:"short",context:"standalone"})||r.day(t,{width:"narrow",context:"standalone"})}}validate(t,n){return n>=0&&n<=6}set(t,n,r,s){return t=MSe(t,r,s),t.setHours(0,0,0,0),t}incompatibleTokens=["y","R","u","q","Q","M","L","I","d","D","E","i","e","t","T"]}function Otr(e,t,n){const r=Hs(e,n?.in),s=Ger(r,n),i=t-s;return cu(r,i,n)}class jtr extends Mi{priority=90;parse(t,n,r){const s=i=>i===0?7:i;switch(n){case"i":case"ii":return fl(n.length,t);case"io":return r.ordinalNumber(t,{unit:"day"});case"iii":return Sl(r.day(t,{width:"abbreviated",context:"formatting"})||r.day(t,{width:"short",context:"formatting"})||r.day(t,{width:"narrow",context:"formatting"}),s);case"iiiii":return Sl(r.day(t,{width:"narrow",context:"formatting"}),s);case"iiiiii":return Sl(r.day(t,{width:"short",context:"formatting"})||r.day(t,{width:"narrow",context:"formatting"}),s);default:return Sl(r.day(t,{width:"wide",context:"formatting"})||r.day(t,{width:"abbreviated",context:"formatting"})||r.day(t,{width:"short",context:"formatting"})||r.day(t,{width:"narrow",context:"formatting"}),s)}}validate(t,n){return n>=1&&n<=7}set(t,n,r){return t=Otr(t,r),t.setHours(0,0,0,0),t}incompatibleTokens=["y","Y","u","q","Q","M","L","w","d","D","E","e","c","t","T"]}class Ctr extends Mi{priority=80;parse(t,n,r){switch(n){case"a":case"aa":case"aaa":return r.dayPeriod(t,{width:"abbreviated",context:"formatting"})||r.dayPeriod(t,{width:"narrow",context:"formatting"});case"aaaaa":return r.dayPeriod(t,{width:"narrow",context:"formatting"});default:return r.dayPeriod(t,{width:"wide",context:"formatting"})||r.dayPeriod(t,{width:"abbreviated",context:"formatting"})||r.dayPeriod(t,{width:"narrow",context:"formatting"})}}set(t,n,r){return t.setHours(RSe(r),0,0,0),t}incompatibleTokens=["b","B","H","k","t","T"]}class _tr extends Mi{priority=80;parse(t,n,r){switch(n){case"b":case"bb":case"bbb":return r.dayPeriod(t,{width:"abbreviated",context:"formatting"})||r.dayPeriod(t,{width:"narrow",context:"formatting"});case"bbbbb":return r.dayPeriod(t,{width:"narrow",context:"formatting"});default:return r.dayPeriod(t,{width:"wide",context:"formatting"})||r.dayPeriod(t,{width:"abbreviated",context:"formatting"})||r.dayPeriod(t,{width:"narrow",context:"formatting"})}}set(t,n,r){return t.setHours(RSe(r),0,0,0),t}incompatibleTokens=["a","B","H","k","t","T"]}class Ttr extends Mi{priority=80;parse(t,n,r){switch(n){case"B":case"BB":case"BBB":return r.dayPeriod(t,{width:"abbreviated",context:"formatting"})||r.dayPeriod(t,{width:"narrow",context:"formatting"});case"BBBBB":return r.dayPeriod(t,{width:"narrow",context:"formatting"});default:return r.dayPeriod(t,{width:"wide",context:"formatting"})||r.dayPeriod(t,{width:"abbreviated",context:"formatting"})||r.dayPeriod(t,{width:"narrow",context:"formatting"})}}set(t,n,r){return t.setHours(RSe(r),0,0,0),t}incompatibleTokens=["a","b","t","T"]}class Etr extends Mi{priority=70;parse(t,n,r){switch(n){case"h":return Fa(wl.hour12h,t);case"ho":return r.ordinalNumber(t,{unit:"hour"});default:return fl(n.length,t)}}validate(t,n){return n>=1&&n<=12}set(t,n,r){const s=t.getHours()>=12;return s&&r<12?t.setHours(r+12,0,0,0):!s&&r===12?t.setHours(0,0,0,0):t.setHours(r,0,0,0),t}incompatibleTokens=["H","K","k","t","T"]}class Itr extends Mi{priority=70;parse(t,n,r){switch(n){case"H":return Fa(wl.hour23h,t);case"Ho":return r.ordinalNumber(t,{unit:"hour"});default:return fl(n.length,t)}}validate(t,n){return n>=0&&n<=23}set(t,n,r){return t.setHours(r,0,0,0),t}incompatibleTokens=["a","b","h","K","k","t","T"]}class Ntr extends Mi{priority=70;parse(t,n,r){switch(n){case"K":return Fa(wl.hour11h,t);case"Ko":return r.ordinalNumber(t,{unit:"hour"});default:return fl(n.length,t)}}validate(t,n){return n>=0&&n<=11}set(t,n,r){return t.getHours()>=12&&r<12?t.setHours(r+12,0,0,0):t.setHours(r,0,0,0),t}incompatibleTokens=["h","H","k","t","T"]}class Atr extends Mi{priority=70;parse(t,n,r){switch(n){case"k":return Fa(wl.hour24h,t);case"ko":return r.ordinalNumber(t,{unit:"hour"});default:return fl(n.length,t)}}validate(t,n){return n>=1&&n<=24}set(t,n,r){const s=r<=24?r%24:r;return t.setHours(s,0,0,0),t}incompatibleTokens=["a","b","h","H","K","t","T"]}class Ptr extends Mi{priority=60;parse(t,n,r){switch(n){case"m":return Fa(wl.minute,t);case"mo":return r.ordinalNumber(t,{unit:"minute"});default:return fl(n.length,t)}}validate(t,n){return n>=0&&n<=59}set(t,n,r){return t.setMinutes(r,0,0),t}incompatibleTokens=["t","T"]}class $tr extends Mi{priority=50;parse(t,n,r){switch(n){case"s":return Fa(wl.second,t);case"so":return r.ordinalNumber(t,{unit:"second"});default:return fl(n.length,t)}}validate(t,n){return n>=0&&n<=59}set(t,n,r){return t.setSeconds(r,0),t}incompatibleTokens=["t","T"]}class Rtr extends Mi{priority=30;parse(t,n){const r=s=>Math.trunc(s*Math.pow(10,-n.length+3));return Sl(fl(n.length,t),r)}set(t,n,r){return t.setMilliseconds(r),t}incompatibleTokens=["t","T"]}class Mtr extends Mi{priority=10;parse(t,n){switch(n){case"X":return Ey(Ty.basicOptionalMinutes,t);case"XX":return Ey(Ty.basic,t);case"XXXX":return Ey(Ty.basicOptionalSeconds,t);case"XXXXX":return Ey(Ty.extendedOptionalSeconds,t);default:return Ey(Ty.extended,t)}}set(t,n,r){return n.timestampIsSet?t:Lo(t,t.getTime()-YN(t)-r)}incompatibleTokens=["t","T","x"]}class Dtr extends Mi{priority=10;parse(t,n){switch(n){case"x":return Ey(Ty.basicOptionalMinutes,t);case"xx":return Ey(Ty.basic,t);case"xxxx":return Ey(Ty.basicOptionalSeconds,t);case"xxxxx":return Ey(Ty.extendedOptionalSeconds,t);default:return Ey(Ty.extended,t)}}set(t,n,r){return n.timestampIsSet?t:Lo(t,t.getTime()-YN(t)-r)}incompatibleTokens=["t","T","X"]}class Ltr extends Mi{priority=40;parse(t){return $1t(t)}set(t,n,r){return[Lo(t,r*1e3),{timestampIsSet:!0}]}incompatibleTokens="*"}class ztr extends Mi{priority=20;parse(t){return $1t(t)}set(t,n,r){return[Lo(t,r),{timestampIsSet:!0}]}incompatibleTokens="*"}const Ftr={G:new str,y:new itr,Y:new otr,R:new atr,u:new ltr,Q:new ctr,q:new utr,M:new dtr,L:new ftr,w:new ptr,I:new gtr,d:new xtr,D:new btr,E:new wtr,e:new Str,c:new ktr,i:new jtr,a:new Ctr,b:new _tr,B:new Ttr,h:new Etr,H:new Itr,K:new Ntr,k:new Atr,m:new Ptr,s:new $tr,S:new Rtr,X:new Mtr,x:new Dtr,t:new Ltr,T:new ztr},Btr=/[yYQqMLwIdDecihHKkms]o|(\w)\1*|''|'(''|[^'])+('|$)|./g,Vtr=/P+p+|P+|p+|''|'(''|[^'])+('|$)|./g,Utr=/^'([^]*?)'?$/,qtr=/''/g,Qtr=/\S/,Ztr=/[a-zA-Z]/;function Wtr(e,t,n,r){const s=()=>Lo(n,NaN),i=Her(),o=i.locale??NSe,l=i.firstWeekContainsDate??i.locale?.options?.firstWeekContainsDate??1,c=i.weekStartsOn??i.locale?.options?.weekStartsOn??0,u={firstWeekContainsDate:l,weekStartsOn:c,locale:o},d=[new rtr(r?.in,n)],f=t.match(Vtr).map(y=>{const x=y[0];if(x in wpe){const b=wpe[x];return b(y,o.formatLong)}return y}).join("").match(Btr),h=[];for(let y of f){N1t(y)&&Spe(y,t,e),I1t(y)&&Spe(y,t,e);const x=y[0],b=Ftr[x];if(b){const{incompatibleTokens:S}=b;if(Array.isArray(S)){const j=h.find(C=>S.includes(C.token)||C.token===x);if(j)throw new RangeError(`The format string mustn't contain \`${j.fullToken}\` and \`${y}\` at the same time`)}else if(b.incompatibleTokens==="*"&&h.length>0)throw new RangeError(`The format string mustn't contain \`${y}\` and any other token at the same time`);h.push({token:x,fullToken:y});const k=b.run(e,y,o.match,u);if(!k)return s();d.push(k.setter),e=k.rest}else{if(x.match(Ztr))throw new RangeError("Format string contains an unescaped latin alphabet character `"+x+"`");if(y==="''"?y="'":x==="'"&&(y=Htr(y)),e.indexOf(y)===0)e=e.slice(y.length);else return s()}}if(e.length>0&&Qtr.test(e))return s();const p=d.map(y=>y.priority).sort((y,x)=>x-y).filter((y,x,b)=>b.indexOf(y)===x).map(y=>d.filter(x=>x.priority===y).sort((x,b)=>b.subPriority-x.subPriority)).map(y=>y[0]);let m=Hs(n,r?.in);if(isNaN(+m))return s();const v={};for(const y of p){if(!y.validate(m,u))return s();const x=y.set(m,v,u);Array.isArray(x)?(m=x[0],Object.assign(v,x[1])):m=x}return m}function Htr(e){return e.match(Utr)[1].replace(qtr,"'")}function DSe(e,t,n){const[r,s]=_P(n?.in,e,t);return r.getFullYear()===s.getFullYear()&&r.getMonth()===s.getMonth()}function Gtr(e,t,n){const[r,s]=_P(n?.in,e,t);return r.getFullYear()===s.getFullYear()}function xoe(e,t,n){return cu(e,-t,n)}function boe(e,t,n){const r=Hs(e,n?.in),s=r.getFullYear(),i=r.getDate(),o=Lo(e,0);o.setFullYear(s,t,15),o.setHours(0,0,0,0);const l=Wer(o);return r.setMonth(t,Math.min(i,l)),r}function EBe(e,t,n){const r=Hs(e,n?.in);return isNaN(+r)?Lo(e,NaN):(r.setFullYear(t),r)}function D1t(e,t){const{getFieldState:n,formState:r}=Lr(),[s,i]=g.useState({expanded:t,dismissedSubmission:0}),o=n(e,r).invalid,l=o&&r.submitCount>s.dismissedSubmission;function c(u){i({expanded:u,dismissedSubmission:r.submitCount})}return{expanded:s.expanded||l,invalid:o,setExpanded:c}}const Ktr=["title","name","label"];function IBe(e){return e.find(t=>typeof t=="string"&&t.trim().length>0)}function Ytr(e){if(typeof e=="string")return e.trim();if(typeof e=="number"||typeof e=="boolean")return String(e);if(oD(e))return IBe(Ktr.map(t=>e[t]))??IBe(Object.values(e))}function Xtr({children:e,onRemove:t,index:n}){const r=g.useContext(HG),s=g.useContext(SSe),i=g.useContext(c1t),{control:o}=Lr(),l=Zn({control:o,name:r}),c=Ytr(l),u=g.useRef(null),{expanded:d,invalid:f,setExpanded:h}=D1t(r,!c),p=`Item ${n+1}${c?`: ${c}`:""}`;return a.jsxs(Kl,{open:d,onOpenChange:h,className:"overflow-hidden rounded-lg border border-border bg-background motion-reduce:[&_[data-slot=collapsible-content]]:transition-none motion-reduce:[&_svg]:transition-none",children:[a.jsxs("div",{className:"flex min-w-0 items-center gap-1 pr-1",children:[a.jsxs(Cl,{ref:u,"aria-label":f?`${p}, Needs input`:p,className:"flex min-h-11 min-w-0 flex-1 items-center gap-2 rounded-lg px-3 text-left text-caption focus-visible:-outline-offset-1",children:[a.jsx(Na,{direction:"right",className:"size-3.5 text-muted-foreground"}),a.jsxs("span",{className:"shrink-0 text-muted-foreground",children:["Item ",n+1]}),c&&a.jsx("span",{className:"truncate text-foreground",title:c,children:c}),f&&a.jsx(Y,{as:"span",variant:"meta",className:"ml-auto shrink-0 text-destructive-foreground",children:"Needs input"})]}),!s&&a.jsx(de,{type:"button",variant:"ghost",size:"icon-md",className:"size-11","aria-label":`Remove item ${n+1}`,onClick:()=>{t(),i?.current?.focus()},children:a.jsx(Xo,{})})]}),a.jsxs(_l,{keepMounted:!0,className:"border-t border-border p-3",children:[e,!s&&a.jsx("div",{className:"flex justify-end pt-2",children:a.jsx(de,{type:"button",className:"min-h-11","aria-label":`Done editing item ${n+1}`,onClick:()=>{h(!1),u.current?.focus()},icon:a.jsx(dr,{}),children:"Done"})})]})]})}function Jtr({label:e,children:t,onAddItem:n}){const r=g.useContext(SSe),s=g.Children.count(t),i=g.useRef(null);return a.jsxs("div",{className:"min-w-0",children:[a.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[a.jsxs(Y,{as:"h3",variant:"caption",tone:"muted",className:"flex items-center gap-1.5",children:[a.jsx(tCn,{"aria-hidden":!0,className:"size-3.5"}),e," ",a.jsx("span",{className:"tabular-nums",children:s})]}),!r&&a.jsxs(de,{ref:i,type:"button",variant:"ghost",size:"sm","aria-label":`Add ${e} item`,onClick:n,children:[a.jsx(ys,{}),"Add item"]})]}),s===0?a.jsx(Y,{as:"p",variant:"caption",tone:"muted",className:"py-2",children:"No items added"}):a.jsx(c1t,{value:i,children:a.jsx("div",{className:"flex flex-col gap-2",children:t})})]})}function enr(e){if(!e)return null;for(const t of e.elements){const n=t.tagName;if(n==="BUTTON"||n==="INPUT"){const r=t;if(r.type==="submit")return r}}return null}function L1t(e){return{checked(t){return e.indeterminate?{}:t?{"data-checked":""}:{"data-unchecked":""}},...jp}}const tnr=g.createContext(void 0);function nnr(){return g.useContext(tnr)}const z1t=g.createContext(void 0);function rnr(){const e=g.useContext(z1t);if(e===void 0)throw new Error(Ar(14));return e}const snr="data-parent",inr=g.forwardRef(function(t,n){const{checked:r,className:s,defaultChecked:i=!1,"aria-labelledby":o,disabled:l=!1,form:c,id:u,indeterminate:d=!1,inputRef:f,name:h,onCheckedChange:p,parent:m=!1,readOnly:v=!1,render:y,required:x=!1,uncheckedValue:b,value:S,nativeButton:k=!1,style:j,...C}=t,{clearErrors:T}=Ev(),{disabled:_,name:N,setDirty:I,setFilled:A,setFocused:P,setTouched:D,state:F,validationMode:Q,validityData:q,validation:B}=Nu(),V=pG(),{labelId:H,controlId:M,registerControlId:G,getDescriptionProps:L}=gd(),$=nnr(),z=$?.allValues===void 0?void 0:$.parent,U=z!==void 0,K=_||V.disabled||$?.disabled||l,ne=N??h,X=S??ne,te=Qi(),ie=Qi();let ue=u||M;U&&(m?ue=ie:X!==void 0?ue=`${z.id}-${X}`:ue||=ie);let ee={};U&&(m?ee=z.getParentProps():X!==void 0&&(ee=z.getChildProps(X)));const{checked:se=r,indeterminate:re=d,onCheckedChange:ae,...he}=ee,ve=$?.value,pe=g.useRef(null),ke=dl(()=>Symbol()),Ee=g.useRef(!1),{getButtonProps:Ue,buttonRef:Qe}=hd({disabled:K,native:k}),Be=$?.validation??B,[Ae,Fe]=Xd({controlled:X!==void 0&&ve!==void 0&&!m?ve.includes(X):se,default:i,name:"Checkbox",state:"checked"}),Ce=U?!!se:Ae,_e=U&&re||d;It(()=>{G!==ci&&(Ee.current=!0,G(ke.current,ue))},[ue,G,ke]),g.useEffect(()=>{const We=ke.current;return()=>{!Ee.current||G===ci||(Ee.current=!1,G(We,void 0))}},[G,ke]),S_(pe,te,Ae,void 0,!$&&!K,h);const je=g.useRef(null),ce=Be.registerInput,ye=$?X:void 0,De=g.useCallback(We=>ce(We,{controlRef:pe,value:ye}),[ce,ye]),Ie=tf(f,je,m?void 0:De),le=Rwe(o,H,je,!k,ue??void 0);It(()=>{je.current&&(je.current.indeterminate=_e,Ae&&A(!0))},[Ae,_e,A]),Xg(Ae,()=>{$||(T(ne),A(Ae),I(Ae!==q.initialValue),Be.change(Ae))});const xe=kl({checked:Ae,disabled:K,form:c,name:m?void 0:ne,id:k?void 0:ue??void 0,required:x,ref:Ie,style:ne?tP:uS,tabIndex:-1,type:"checkbox","aria-hidden":!0,onChange(We){if(We.nativeEvent.defaultPrevented)return;if(v){We.preventDefault();return}const tt=We.currentTarget.checked,st=Yt(Io,We.nativeEvent);if(p?.(tt,st),!st.isCanceled&&(ae?.(tt,st),!st.isCanceled&&(Fe(tt),X!==void 0&&$!==void 0&&!m&&!U))){const He=tt?[...$.value,X]:$.value.filter(ze=>ze!==X);$.setValue(He,st)}},onClick(We){We.stopPropagation()},onFocus(){pe.current?.focus()}},S!==void 0?{value:($?Ae&&S:S)||""}:si,L,We=>Be.getValidationProps(K,We));g.useEffect(()=>{if(!z||X===void 0)return;const We=z.disabledStatesRef.current;return We.set(X,K),()=>{We.delete(X)}},[z,K,X]);const Se=g.useMemo(()=>({...F,checked:Ce,disabled:K,readOnly:v,required:x,indeterminate:_e}),[F,Ce,K,v,x,_e]),Re=L1t(Se),Le=hn("span",t,{state:Se,ref:[Qe,pe,n],props:[{id:k?ue??void 0:te,role:"checkbox","aria-checked":_e?"mixed":Ce,"aria-readonly":v||void 0,"aria-required":x||void 0,"aria-labelledby":le,[snr]:m?"":void 0,onFocus(){K||P(!0)},onBlur(){const We=je.current;We&&(D(!0),P(!1),Q==="onBlur"&&Be.commit($?ve:We.checked))},onKeyDown(We){if(We.key!=="Enter"||(We.preventBaseUIHandler(),We.defaultPrevented))return;const tt=je.current?.form??null,st=We.currentTarget,He=We.nativeEvent,ze=We.preventDefault,kt=He.preventDefault;let me=!1;We.preventDefault=()=>{me=!0,ze.call(We)},He.preventDefault=()=>{me=!0,kt.call(He)},kt.call(He),yi(st).queueMicrotask(()=>{We.preventDefault=ze,He.preventDefault=kt,me||enr(tt)?.click()})},onClick(We){if(v||K)return;We.preventDefault();const tt=je.current;tt&&Cj(tt,We)}},C,he,Ue,L,We=>Be.getValidationProps(K,We)],stateAttributesMapping:Re});return a.jsxs(z1t.Provider,{value:Se,children:[Le,!Ae&&!$&&ne&&!m&&b!==void 0&&a.jsx("input",{type:"hidden",form:c,name:ne,value:b,disabled:K}),a.jsx("input",{...xe,suppressHydrationWarning:!0})]})}),onr=g.forwardRef(function(t,n){const{render:r,className:s,style:i,keepMounted:o=!1,...l}=t,c=rnr(),u=c.checked||c.indeterminate,{mounted:d,transitionStatus:f,setMounted:h}=eg(u),p=g.useRef(null),m={...c,transitionStatus:f};Wl({open:u,ref:p,onComplete(){u||h(!1)}});const y={...L1t(c),...kp},x=o||d,b=hn("span",t,{ref:[n,p],state:m,stateAttributesMapping:y,props:l});return x?b:null}),F1t=["flex size-4 shrink-0 cursor-pointer items-center justify-center","border border-border bg-fill-hover text-background",$i.all,"hover:border-border-strong hover:bg-fill-active","active:scale-95 active:border-border-hover active:bg-fill-strong",PU,"data-[checked]:border-foreground data-[checked]:bg-foreground data-[checked]:text-background","data-[checked]:hover:border-foreground/90 data-[checked]:hover:bg-foreground/90","data-[checked]:active:border-foreground/75 data-[checked]:active:bg-foreground/75","data-[disabled]:cursor-not-allowed data-[disabled]:border-border data-[disabled]:bg-fill-subtle data-[disabled]:active:scale-100","data-[disabled]:data-[checked]:border-muted-foreground data-[disabled]:data-[checked]:bg-muted-foreground data-[disabled]:data-[checked]:text-background"].join(" "),Wc=g.forwardRef(({className:e,checked:t,indeterminate:n,...r},s)=>{const i=t==="indeterminate";return a.jsx(inr,{ref:s,checked:i?!1:t,indeterminate:n??i,"data-slot":"checkbox",render:a.jsx("span",{...Tx(r)}),className:Z("peer rounded-[0.3125rem]",F1t,"data-[indeterminate]:border-foreground data-[indeterminate]:bg-foreground data-[indeterminate]:text-background","data-[indeterminate]:hover:border-foreground/90 data-[indeterminate]:hover:bg-foreground/90","data-[indeterminate]:active:border-foreground/75 data-[indeterminate]:active:bg-foreground/75","data-[disabled]:data-[indeterminate]:border-muted-foreground data-[disabled]:data-[indeterminate]:bg-muted-foreground data-[disabled]:data-[indeterminate]:text-background",e),...r,children:a.jsx(onr,{keepMounted:!0,className:Z("group/checkbox-indicator flex items-center justify-center text-current","scale-75 opacity-0 transition-[opacity,transform] duration-200 ease-out-custom","data-[checked]:scale-100 data-[checked]:opacity-100","data-[indeterminate]:scale-100 data-[indeterminate]:opacity-100","data-[starting-style]:scale-75 data-[starting-style]:opacity-0","data-[ending-style]:scale-75 data-[ending-style]:opacity-0"),children:a.jsx(anr,{})})})});Wc.displayName="Checkbox";function anr(){return a.jsxs(a.Fragment,{children:[a.jsx(dr,{className:Z("stroke-3.25 size-3 scale-95 transition-[stroke-dashoffset,transform] duration-200 ease-out-custom","[stroke-dasharray:28] [stroke-dashoffset:28]","group-data-[checked]/checkbox-indicator:[stroke-dashoffset:0]","group-data-[checked]/checkbox-indicator:scale-100","group-data-[indeterminate]/checkbox-indicator:hidden")}),a.jsx(cht,{className:Z("stroke-3.25 hidden size-3 scale-95 transition-transform duration-200 ease-out-custom","group-data-[indeterminate]/checkbox-indicator:block","group-data-[indeterminate]/checkbox-indicator:scale-100")})]})}const lnr=({field:e,label:t,inputProps:n})=>a.jsxs("div",{className:"flex items-center space-x-2",children:[a.jsx(Wc,{onCheckedChange:r=>{const s={target:{name:n.name,value:r}};n.onChange(s)},defaultChecked:e.default,disabled:n.disabled||n.readOnly}),a.jsx(ut,{required:e.required,children:t})]});var Ir=function(){return Ir=Object.assign||function(t){for(var n,r=1,s=arguments.length;r<s;r++){n=arguments[r];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i])}return t},Ir.apply(this,arguments)};function cnr(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var s=0,r=Object.getOwnPropertySymbols(e);s<r.length;s++)t.indexOf(r[s])<0&&Object.prototype.propertyIsEnumerable.call(e,r[s])&&(n[r[s]]=e[r[s]]);return n}function B1t(e,t,n){for(var r=0,s=t.length,i;r<s;r++)(i||!(r in t))&&(i||(i=Array.prototype.slice.call(t,0,r)),i[r]=t[r]);return e.concat(i||Array.prototype.slice.call(t))}function PL(e){return e.mode==="multiple"}function $L(e){return e.mode==="range"}function KG(e){return e.mode==="single"}var unr={root:"rdp",multiple_months:"rdp-multiple_months",with_weeknumber:"rdp-with_weeknumber",vhidden:"rdp-vhidden",button_reset:"rdp-button_reset",button:"rdp-button",caption:"rdp-caption",caption_start:"rdp-caption_start",caption_end:"rdp-caption_end",caption_between:"rdp-caption_between",caption_label:"rdp-caption_label",caption_dropdowns:"rdp-caption_dropdowns",dropdown:"rdp-dropdown",dropdown_month:"rdp-dropdown_month",dropdown_year:"rdp-dropdown_year",dropdown_icon:"rdp-dropdown_icon",months:"rdp-months",month:"rdp-month",table:"rdp-table",tbody:"rdp-tbody",tfoot:"rdp-tfoot",head:"rdp-head",head_row:"rdp-head_row",head_cell:"rdp-head_cell",nav:"rdp-nav",nav_button:"rdp-nav_button",nav_button_previous:"rdp-nav_button_previous",nav_button_next:"rdp-nav_button_next",nav_icon:"rdp-nav_icon",row:"rdp-row",weeknumber:"rdp-weeknumber",cell:"rdp-cell",day:"rdp-day",day_today:"rdp-day_today",day_outside:"rdp-day_outside",day_selected:"rdp-day_selected",day_disabled:"rdp-day_disabled",day_hidden:"rdp-day_hidden",day_range_start:"rdp-day_range_start",day_range_end:"rdp-day_range_end",day_range_middle:"rdp-day_range_middle"};function dnr(e,t){return yk(e,"LLLL y",t)}function fnr(e,t){return yk(e,"d",t)}function hnr(e,t){return yk(e,"LLLL",t)}function pnr(e){return"".concat(e)}function mnr(e,t){return yk(e,"cccccc",t)}function gnr(e,t){return yk(e,"yyyy",t)}var vnr=Object.freeze({__proto__:null,formatCaption:dnr,formatDay:fnr,formatMonthCaption:hnr,formatWeekNumber:pnr,formatWeekdayName:mnr,formatYearCaption:gnr}),ynr=function(e,t,n){return yk(e,"do MMMM (EEEE)",n)},xnr=function(){return"Month: "},bnr=function(){return"Go to next month"},wnr=function(){return"Go to previous month"},Snr=function(e,t){return yk(e,"cccc",t)},knr=function(e){return"Week n. ".concat(e)},Onr=function(){return"Year: "},jnr=Object.freeze({__proto__:null,labelDay:ynr,labelMonthDropdown:xnr,labelNext:bnr,labelPrevious:wnr,labelWeekNumber:knr,labelWeekday:Snr,labelYearDropdown:Onr});function Cnr(){var e="buttons",t=unr,n=NSe,r={},s={},i=1,o={},l=new Date;return{captionLayout:e,classNames:t,formatters:vnr,labels:jnr,locale:n,modifiersClassNames:r,modifiers:s,numberOfMonths:i,styles:o,today:l,mode:"default"}}function _nr(e){var t=e.fromYear,n=e.toYear,r=e.fromMonth,s=e.toMonth,i=e.fromDate,o=e.toDate;return r?i=Xf(r):t&&(i=new Date(t,0,1)),s?o=ESe(s):n&&(o=new Date(n,11,31)),{fromDate:i?XN(i):void 0,toDate:o?XN(o):void 0}}var V1t=g.createContext(void 0);function Tnr(e){var t,n=e.initialProps,r=Cnr(),s=_nr(n),i=s.fromDate,o=s.toDate,l=(t=n.captionLayout)!==null&&t!==void 0?t:r.captionLayout;l!=="buttons"&&(!i||!o)&&(l="buttons");var c;(KG(n)||PL(n)||$L(n))&&(c=n.onSelect);var u=Ir(Ir(Ir({},r),n),{captionLayout:l,classNames:Ir(Ir({},r.classNames),n.classNames),components:Ir({},n.components),formatters:Ir(Ir({},r.formatters),n.formatters),fromDate:i,labels:Ir(Ir({},r.labels),n.labels),mode:n.mode||r.mode,modifiers:Ir(Ir({},r.modifiers),n.modifiers),modifiersClassNames:Ir(Ir({},r.modifiersClassNames),n.modifiersClassNames),onSelect:c,styles:Ir(Ir({},r.styles),n.styles),toDate:o});return a.jsx(V1t.Provider,{value:u,children:e.children})}function ea(){var e=g.useContext(V1t);if(!e)throw new Error("useDayPicker must be used within a DayPickerProvider.");return e}function U1t(e){var t=ea(),n=t.locale,r=t.classNames,s=t.styles,i=t.formatters.formatCaption;return a.jsx("div",{className:r.caption_label,style:s.caption_label,"aria-live":"polite",role:"presentation",id:e.id,children:i(e.displayMonth,{locale:n})})}function Enr(e){return a.jsx("svg",Ir({width:"8px",height:"8px",viewBox:"0 0 120 120","data-testid":"iconDropdown"},e,{children:a.jsx("path",{d:"M4.22182541,48.2218254 C8.44222828,44.0014225 15.2388494,43.9273804 19.5496459,47.9996989 L19.7781746,48.2218254 L60,88.443 L100.221825,48.2218254 C104.442228,44.0014225 111.238849,43.9273804 115.549646,47.9996989 L115.778175,48.2218254 C119.998577,52.4422283 120.07262,59.2388494 116.000301,63.5496459 L115.778175,63.7781746 L67.7781746,111.778175 C63.5577717,115.998577 56.7611506,116.07262 52.4503541,112.000301 L52.2218254,111.778175 L4.22182541,63.7781746 C-0.0739418023,59.4824074 -0.0739418023,52.5175926 4.22182541,48.2218254 Z",fill:"currentColor",fillRule:"nonzero"})}))}function q1t(e){var t,n,r=e.onChange,s=e.value,i=e.children,o=e.caption,l=e.className,c=e.style,u=ea(),d=(n=(t=u.components)===null||t===void 0?void 0:t.IconDropdown)!==null&&n!==void 0?n:Enr;return a.jsxs("div",{className:l,style:c,children:[a.jsx("span",{className:u.classNames.vhidden,children:e["aria-label"]}),a.jsx("select",{name:e.name,"aria-label":e["aria-label"],className:u.classNames.dropdown,style:u.styles.dropdown,value:s,onChange:r,children:i}),a.jsxs("div",{className:u.classNames.caption_label,style:u.styles.caption_label,"aria-hidden":"true",children:[o,a.jsx(d,{className:u.classNames.dropdown_icon,style:u.styles.dropdown_icon})]})]})}function Inr(e){var t,n=ea(),r=n.fromDate,s=n.toDate,i=n.styles,o=n.locale,l=n.formatters.formatMonthCaption,c=n.classNames,u=n.components,d=n.labels.labelMonthDropdown;if(!r)return a.jsx(a.Fragment,{});if(!s)return a.jsx(a.Fragment,{});var f=[];if(Gtr(r,s))for(var h=Xf(r),p=r.getMonth();p<=s.getMonth();p++)f.push(boe(h,p));else for(var h=Xf(new Date),p=0;p<=11;p++)f.push(boe(h,p));var m=function(y){var x=Number(y.target.value),b=boe(Xf(e.displayMonth),x);e.onChange(b)},v=(t=u?.Dropdown)!==null&&t!==void 0?t:q1t;return a.jsx(v,{name:"months","aria-label":d(),className:c.dropdown_month,style:i.dropdown_month,onChange:m,value:e.displayMonth.getMonth(),caption:l(e.displayMonth,{locale:o}),children:f.map(function(y){return a.jsx("option",{value:y.getMonth(),children:l(y,{locale:o})},y.getMonth())})})}function Nnr(e){var t,n=e.displayMonth,r=ea(),s=r.fromDate,i=r.toDate,o=r.locale,l=r.styles,c=r.classNames,u=r.components,d=r.formatters.formatYearCaption,f=r.labels.labelYearDropdown,h=[];if(!s)return a.jsx(a.Fragment,{});if(!i)return a.jsx(a.Fragment,{});for(var p=s.getFullYear(),m=i.getFullYear(),v=p;v<=m;v++)h.push(EBe(_1t(new Date),v));var y=function(b){var S=EBe(Xf(n),Number(b.target.value));e.onChange(S)},x=(t=u?.Dropdown)!==null&&t!==void 0?t:q1t;return a.jsx(x,{name:"years","aria-label":f(),className:c.dropdown_year,style:l.dropdown_year,onChange:y,value:n.getFullYear(),caption:d(n,{locale:o}),children:h.map(function(b){return a.jsx("option",{value:b.getFullYear(),children:d(b,{locale:o})},b.getFullYear())})})}function Anr(e,t){var n=g.useState(e),r=n[0],s=n[1],i=t===void 0?r:t;return[i,s]}function Pnr(e){var t=e.month,n=e.defaultMonth,r=e.today,s=t||n||r||new Date,i=e.toDate,o=e.fromDate,l=e.numberOfMonths,c=l===void 0?1:l;if(i&&h5(i,s)<0){var u=-1*(c-1);s=gv(i,u)}return o&&h5(s,o)<0&&(s=o),Xf(s)}function $nr(){var e=ea(),t=Pnr(e),n=Anr(t,e.month),r=n[0],s=n[1],i=function(o){var l;if(!e.disableNavigation){var c=Xf(o);s(c),(l=e.onMonthChange)===null||l===void 0||l.call(e,c)}};return[r,i]}function Rnr(e,t){for(var n=t.reverseMonths,r=t.numberOfMonths,s=Xf(e),i=Xf(gv(s,r)),o=h5(i,s),l=[],c=0;c<o;c++){var u=gv(s,c);l.push(u)}return n&&(l=l.reverse()),l}function Mnr(e,t){if(!t.disableNavigation){var n=t.toDate,r=t.pagedNavigation,s=t.numberOfMonths,i=s===void 0?1:s,o=r?i:1,l=Xf(e);if(!n)return gv(l,o);var c=h5(n,e);if(!(c<i))return gv(l,o)}}function Dnr(e,t){if(!t.disableNavigation){var n=t.fromDate,r=t.pagedNavigation,s=t.numberOfMonths,i=s===void 0?1:s,o=r?i:1,l=Xf(e);if(!n)return gv(l,-o);var c=h5(l,n);if(!(c<=0))return gv(l,-o)}}var Q1t=g.createContext(void 0);function Lnr(e){var t=ea(),n=$nr(),r=n[0],s=n[1],i=Rnr(r,t),o=Mnr(r,t),l=Dnr(r,t),c=function(f){return i.some(function(h){return DSe(f,h)})},u=function(f,h){c(f)||(h&&A1t(f,h)?s(gv(f,1+t.numberOfMonths*-1)):s(f))},d={currentMonth:r,displayMonths:i,goToMonth:s,goToDate:u,previousMonth:l,nextMonth:o,isDateDisplayed:c};return a.jsx(Q1t.Provider,{value:d,children:e.children})}function RL(){var e=g.useContext(Q1t);if(!e)throw new Error("useNavigation must be used within a NavigationProvider");return e}function NBe(e){var t,n=ea(),r=n.classNames,s=n.styles,i=n.components,o=RL().goToMonth,l=function(d){o(gv(d,e.displayIndex?-e.displayIndex:0))},c=(t=i?.CaptionLabel)!==null&&t!==void 0?t:U1t,u=a.jsx(c,{id:e.id,displayMonth:e.displayMonth});return a.jsxs("div",{className:r.caption_dropdowns,style:s.caption_dropdowns,children:[a.jsx("div",{className:r.vhidden,children:u}),a.jsx(Inr,{onChange:l,displayMonth:e.displayMonth}),a.jsx(Nnr,{onChange:l,displayMonth:e.displayMonth})]})}function znr(e){return a.jsx("svg",Ir({width:"16px",height:"16px",viewBox:"0 0 120 120"},e,{children:a.jsx("path",{d:"M69.490332,3.34314575 C72.6145263,0.218951416 77.6798462,0.218951416 80.8040405,3.34314575 C83.8617626,6.40086786 83.9268205,11.3179931 80.9992143,14.4548388 L80.8040405,14.6568542 L35.461,60 L80.8040405,105.343146 C83.8617626,108.400868 83.9268205,113.317993 80.9992143,116.454839 L80.8040405,116.656854 C77.7463184,119.714576 72.8291931,119.779634 69.6923475,116.852028 L69.490332,116.656854 L18.490332,65.6568542 C15.4326099,62.5991321 15.367552,57.6820069 18.2951583,54.5451612 L18.490332,54.3431458 L69.490332,3.34314575 Z",fill:"currentColor",fillRule:"nonzero"})}))}function Fnr(e){return a.jsx("svg",Ir({width:"16px",height:"16px",viewBox:"0 0 120 120"},e,{children:a.jsx("path",{d:"M49.8040405,3.34314575 C46.6798462,0.218951416 41.6145263,0.218951416 38.490332,3.34314575 C35.4326099,6.40086786 35.367552,11.3179931 38.2951583,14.4548388 L38.490332,14.6568542 L83.8333725,60 L38.490332,105.343146 C35.4326099,108.400868 35.367552,113.317993 38.2951583,116.454839 L38.490332,116.656854 C41.5480541,119.714576 46.4651794,119.779634 49.602025,116.852028 L49.8040405,116.656854 L100.804041,65.6568542 C103.861763,62.5991321 103.926821,57.6820069 100.999214,54.5451612 L100.804041,54.3431458 L49.8040405,3.34314575 Z",fill:"currentColor"})}))}var nQ=g.forwardRef(function(e,t){var n=ea(),r=n.classNames,s=n.styles,i=[r.button_reset,r.button];e.className&&i.push(e.className);var o=i.join(" "),l=Ir(Ir({},s.button_reset),s.button);return e.style&&Object.assign(l,e.style),a.jsx("button",Ir({},e,{ref:t,type:"button",className:o,style:l}))});function Bnr(e){var t,n,r=ea(),s=r.dir,i=r.locale,o=r.classNames,l=r.styles,c=r.labels,u=c.labelPrevious,d=c.labelNext,f=r.components;if(!e.nextMonth&&!e.previousMonth)return a.jsx(a.Fragment,{});var h=u(e.previousMonth,{locale:i}),p=[o.nav_button,o.nav_button_previous].join(" "),m=d(e.nextMonth,{locale:i}),v=[o.nav_button,o.nav_button_next].join(" "),y=(t=f?.IconRight)!==null&&t!==void 0?t:Fnr,x=(n=f?.IconLeft)!==null&&n!==void 0?n:znr;return a.jsxs("div",{className:o.nav,style:l.nav,children:[!e.hidePrevious&&a.jsx(nQ,{name:"previous-month","aria-label":h,className:p,style:l.nav_button_previous,disabled:!e.previousMonth,onClick:e.onPreviousClick,children:s==="rtl"?a.jsx(y,{className:o.nav_icon,style:l.nav_icon}):a.jsx(x,{className:o.nav_icon,style:l.nav_icon})}),!e.hideNext&&a.jsx(nQ,{name:"next-month","aria-label":m,className:v,style:l.nav_button_next,disabled:!e.nextMonth,onClick:e.onNextClick,children:s==="rtl"?a.jsx(x,{className:o.nav_icon,style:l.nav_icon}):a.jsx(y,{className:o.nav_icon,style:l.nav_icon})})]})}function ABe(e){var t=ea().numberOfMonths,n=RL(),r=n.previousMonth,s=n.nextMonth,i=n.goToMonth,o=n.displayMonths,l=o.findIndex(function(m){return DSe(e.displayMonth,m)}),c=l===0,u=l===o.length-1,d=t>1&&(c||!u),f=t>1&&(u||!c),h=function(){r&&i(r)},p=function(){s&&i(s)};return a.jsx(Bnr,{displayMonth:e.displayMonth,hideNext:d,hidePrevious:f,nextMonth:s,previousMonth:r,onPreviousClick:h,onNextClick:p})}function Vnr(e){var t,n=ea(),r=n.classNames,s=n.disableNavigation,i=n.styles,o=n.captionLayout,l=n.components,c=(t=l?.CaptionLabel)!==null&&t!==void 0?t:U1t,u;return s?u=a.jsx(c,{id:e.id,displayMonth:e.displayMonth}):o==="dropdown"?u=a.jsx(NBe,{displayMonth:e.displayMonth,id:e.id}):o==="dropdown-buttons"?u=a.jsxs(a.Fragment,{children:[a.jsx(NBe,{displayMonth:e.displayMonth,displayIndex:e.displayIndex,id:e.id}),a.jsx(ABe,{displayMonth:e.displayMonth,displayIndex:e.displayIndex,id:e.id})]}):u=a.jsxs(a.Fragment,{children:[a.jsx(c,{id:e.id,displayMonth:e.displayMonth,displayIndex:e.displayIndex}),a.jsx(ABe,{displayMonth:e.displayMonth,id:e.id})]}),a.jsx("div",{className:r.caption,style:i.caption,children:u})}function Unr(e){var t=ea(),n=t.footer,r=t.styles,s=t.classNames.tfoot;return n?a.jsx("tfoot",{className:s,style:r.tfoot,children:a.jsx("tr",{children:a.jsx("td",{colSpan:8,children:n})})}):a.jsx(a.Fragment,{})}function qnr(e,t,n){for(var r=n?k0(new Date):vp(new Date,{locale:e,weekStartsOn:t}),s=[],i=0;i<7;i++){var o=cu(r,i);s.push(o)}return s}function Qnr(){var e=ea(),t=e.classNames,n=e.styles,r=e.showWeekNumber,s=e.locale,i=e.weekStartsOn,o=e.ISOWeek,l=e.formatters.formatWeekdayName,c=e.labels.labelWeekday,u=qnr(s,i,o);return a.jsxs("tr",{style:n.head_row,className:t.head_row,children:[r&&a.jsx("td",{style:n.head_cell,className:t.head_cell}),u.map(function(d,f){return a.jsx("th",{scope:"col",className:t.head_cell,style:n.head_cell,"aria-label":c(d,{locale:s}),children:l(d,{locale:s})},f)})]})}function Znr(){var e,t=ea(),n=t.classNames,r=t.styles,s=t.components,i=(e=s?.HeadRow)!==null&&e!==void 0?e:Qnr;return a.jsx("thead",{style:r.head,className:n.head,children:a.jsx(i,{})})}function Wnr(e){var t=ea(),n=t.locale,r=t.formatters.formatDay;return a.jsx(a.Fragment,{children:r(e.date,{locale:n})})}var LSe=g.createContext(void 0);function Hnr(e){if(!PL(e.initialProps)){var t={selected:void 0,modifiers:{disabled:[]}};return a.jsx(LSe.Provider,{value:t,children:e.children})}return a.jsx(Gnr,{initialProps:e.initialProps,children:e.children})}function Gnr(e){var t=e.initialProps,n=e.children,r=t.selected,s=t.min,i=t.max,o=function(u,d,f){var h,p;(h=t.onDayClick)===null||h===void 0||h.call(t,u,d,f);var m=!!(d.selected&&s&&r?.length===s);if(!m){var v=!!(!d.selected&&i&&r?.length===i);if(!v){var y=r?B1t([],r):[];if(d.selected){var x=y.findIndex(function(b){return Qf(u,b)});y.splice(x,1)}else y.push(u);(p=t.onSelect)===null||p===void 0||p.call(t,y,u,d,f)}}},l={disabled:[]};r&&l.disabled.push(function(u){var d=i&&r.length>i-1,f=r.some(function(h){return Qf(h,u)});return!!(d&&!f)});var c={selected:r,onDayClick:o,modifiers:l};return a.jsx(LSe.Provider,{value:c,children:n})}function zSe(){var e=g.useContext(LSe);if(!e)throw new Error("useSelectMultiple must be used within a SelectMultipleProvider");return e}function Knr(e,t){var n=t||{},r=n.from,s=n.to;return r&&s?Qf(s,e)&&Qf(r,e)?void 0:Qf(s,e)?{from:s,to:void 0}:Qf(r,e)?void 0:kpe(r,e)?{from:e,to:s}:{from:r,to:e}:s?kpe(e,s)?{from:s,to:e}:{from:e,to:s}:r?A1t(e,r)?{from:e,to:r}:{from:r,to:e}:{from:e,to:void 0}}var FSe=g.createContext(void 0);function Ynr(e){if(!$L(e.initialProps)){var t={selected:void 0,modifiers:{range_start:[],range_end:[],range_middle:[],disabled:[]}};return a.jsx(FSe.Provider,{value:t,children:e.children})}return a.jsx(Xnr,{initialProps:e.initialProps,children:e.children})}function Xnr(e){var t=e.initialProps,n=e.children,r=t.selected,s=r||{},i=s.from,o=s.to,l=t.min,c=t.max,u=function(p,m,v){var y,x;(y=t.onDayClick)===null||y===void 0||y.call(t,p,m,v);var b=Knr(p,r);(x=t.onSelect)===null||x===void 0||x.call(t,b,p,m,v)},d={range_start:[],range_end:[],range_middle:[],disabled:[]};if(i?(d.range_start=[i],o?(d.range_end=[o],Qf(i,o)||(d.range_middle=[{after:i,before:o}])):d.range_end=[i]):o&&(d.range_start=[o],d.range_end=[o]),l&&(i&&!o&&d.disabled.push({after:xoe(i,l-1),before:cu(i,l-1)}),i&&o&&d.disabled.push({after:i,before:cu(i,l-1)}),!i&&o&&d.disabled.push({after:xoe(o,l-1),before:cu(o,l-1)})),c){if(i&&!o&&(d.disabled.push({before:cu(i,-c+1)}),d.disabled.push({after:cu(i,c-1)})),i&&o){var f=zy(o,i)+1,h=c-f;d.disabled.push({before:xoe(i,h)}),d.disabled.push({after:cu(o,h)})}!i&&o&&(d.disabled.push({before:cu(o,-c+1)}),d.disabled.push({after:cu(o,c-1)}))}return a.jsx(FSe.Provider,{value:{selected:r,onDayClick:u,modifiers:d},children:n})}function BSe(){var e=g.useContext(FSe);if(!e)throw new Error("useSelectRange must be used within a SelectRangeProvider");return e}function $B(e){return Array.isArray(e)?B1t([],e):e!==void 0?[e]:[]}function Jnr(e){var t={};return Object.entries(e).forEach(function(n){var r=n[0],s=n[1];t[r]=$B(s)}),t}var vv;(function(e){e.Outside="outside",e.Disabled="disabled",e.Selected="selected",e.Hidden="hidden",e.Today="today",e.RangeStart="range_start",e.RangeEnd="range_end",e.RangeMiddle="range_middle"})(vv||(vv={}));var err=vv.Selected,ub=vv.Disabled,trr=vv.Hidden,nrr=vv.Today,woe=vv.RangeEnd,Soe=vv.RangeMiddle,koe=vv.RangeStart,rrr=vv.Outside;function srr(e,t,n){var r,s=(r={},r[err]=$B(e.selected),r[ub]=$B(e.disabled),r[trr]=$B(e.hidden),r[nrr]=[e.today],r[woe]=[],r[Soe]=[],r[koe]=[],r[rrr]=[],r);return e.fromDate&&s[ub].push({before:e.fromDate}),e.toDate&&s[ub].push({after:e.toDate}),PL(e)?s[ub]=s[ub].concat(t.modifiers[ub]):$L(e)&&(s[ub]=s[ub].concat(n.modifiers[ub]),s[koe]=n.modifiers[koe],s[Soe]=n.modifiers[Soe],s[woe]=n.modifiers[woe]),s}var Z1t=g.createContext(void 0);function irr(e){var t=ea(),n=zSe(),r=BSe(),s=srr(t,n,r),i=Jnr(t.modifiers),o=Ir(Ir({},s),i);return a.jsx(Z1t.Provider,{value:o,children:e.children})}function W1t(){var e=g.useContext(Z1t);if(!e)throw new Error("useModifiers must be used within a ModifiersProvider");return e}function orr(e){return!!(e&&typeof e=="object"&&"before"in e&&"after"in e)}function arr(e){return!!(e&&typeof e=="object"&&"from"in e)}function lrr(e){return!!(e&&typeof e=="object"&&"after"in e)}function crr(e){return!!(e&&typeof e=="object"&&"before"in e)}function urr(e){return!!(e&&typeof e=="object"&&"dayOfWeek"in e)}function drr(e,t){var n,r=t.from,s=t.to;if(r&&s){var i=zy(s,r)<0;i&&(n=[s,r],r=n[0],s=n[1]);var o=zy(e,r)>=0&&zy(s,e)>=0;return o}return s?Qf(s,e):r?Qf(r,e):!1}function frr(e){return _Se(e)}function hrr(e){return Array.isArray(e)&&e.every(_Se)}function prr(e,t){return t.some(function(n){if(typeof n=="boolean")return n;if(frr(n))return Qf(e,n);if(hrr(n))return n.includes(e);if(arr(n))return drr(e,n);if(urr(n))return n.dayOfWeek.includes(e.getDay());if(orr(n)){var r=zy(n.before,e),s=zy(n.after,e),i=r>0,o=s<0,l=kpe(n.before,n.after);return l?o&&i:i||o}return lrr(n)?zy(e,n.after)>0:crr(n)?zy(n.before,e)>0:typeof n=="function"?n(e):!1})}function VSe(e,t,n){var r=Object.keys(t).reduce(function(i,o){var l=t[o];return prr(e,l)&&i.push(o),i},[]),s={};return r.forEach(function(i){return s[i]=!0}),n&&!DSe(e,n)&&(s.outside=!0),s}function mrr(e,t){for(var n=Xf(e[0]),r=ESe(e[e.length-1]),s,i,o=n;o<=r;){var l=VSe(o,t),c=!l.disabled&&!l.hidden;if(!c){o=cu(o,1);continue}if(l.selected)return o;l.today&&!i&&(i=o),s||(s=o),o=cu(o,1)}return i||s}var grr=365;function H1t(e,t){var n=t.moveBy,r=t.direction,s=t.context,i=t.modifiers,o=t.retry,l=o===void 0?{count:0,lastFocused:e}:o,c=s.weekStartsOn,u=s.fromDate,d=s.toDate,f=s.locale,h={day:cu,week:bpe,month:gv,year:XJn,startOfWeek:function(y){return s.ISOWeek?k0(y):vp(y,{locale:f,weekStartsOn:c})},endOfWeek:function(y){return s.ISOWeek?T1t(y):ISe(y,{locale:f,weekStartsOn:c})}},p=h[n](e,r==="after"?1:-1);r==="before"&&u?p=JJn([u,p]):r==="after"&&d&&(p=eer([d,p]));var m=!0;if(i){var v=VSe(p,i);m=!v.disabled&&!v.hidden}return m?p:l.count>grr?l.lastFocused:H1t(p,{moveBy:n,direction:r,context:s,modifiers:i,retry:Ir(Ir({},l),{count:l.count+1})})}var G1t=g.createContext(void 0);function vrr(e){var t=RL(),n=W1t(),r=g.useState(),s=r[0],i=r[1],o=g.useState(),l=o[0],c=o[1],u=mrr(t.displayMonths,n),d=s??(l&&t.isDateDisplayed(l))?l:u,f=function(){c(s),i(void 0)},h=function(y){i(y)},p=ea(),m=function(y,x){if(s){var b=H1t(s,{moveBy:y,direction:x,context:p,modifiers:n});Qf(s,b)||(t.goToDate(b,s),h(b))}},v={focusedDay:s,focusTarget:d,blur:f,focus:h,focusDayAfter:function(){return m("day","after")},focusDayBefore:function(){return m("day","before")},focusWeekAfter:function(){return m("week","after")},focusWeekBefore:function(){return m("week","before")},focusMonthBefore:function(){return m("month","before")},focusMonthAfter:function(){return m("month","after")},focusYearBefore:function(){return m("year","before")},focusYearAfter:function(){return m("year","after")},focusStartOfWeek:function(){return m("startOfWeek","before")},focusEndOfWeek:function(){return m("endOfWeek","after")}};return a.jsx(G1t.Provider,{value:v,children:e.children})}function USe(){var e=g.useContext(G1t);if(!e)throw new Error("useFocusContext must be used within a FocusProvider");return e}function yrr(e,t){var n=W1t(),r=VSe(e,n,t);return r}var qSe=g.createContext(void 0);function xrr(e){if(!KG(e.initialProps)){var t={selected:void 0};return a.jsx(qSe.Provider,{value:t,children:e.children})}return a.jsx(brr,{initialProps:e.initialProps,children:e.children})}function brr(e){var t=e.initialProps,n=e.children,r=function(i,o,l){var c,u,d;if((c=t.onDayClick)===null||c===void 0||c.call(t,i,o,l),o.selected&&!t.required){(u=t.onSelect)===null||u===void 0||u.call(t,void 0,i,o,l);return}(d=t.onSelect)===null||d===void 0||d.call(t,i,i,o,l)},s={selected:t.selected,onDayClick:r};return a.jsx(qSe.Provider,{value:s,children:n})}function K1t(){var e=g.useContext(qSe);if(!e)throw new Error("useSelectSingle must be used within a SelectSingleProvider");return e}function wrr(e,t){var n=ea(),r=K1t(),s=zSe(),i=BSe(),o=USe(),l=o.focusDayAfter,c=o.focusDayBefore,u=o.focusWeekAfter,d=o.focusWeekBefore,f=o.blur,h=o.focus,p=o.focusMonthBefore,m=o.focusMonthAfter,v=o.focusYearBefore,y=o.focusYearAfter,x=o.focusStartOfWeek,b=o.focusEndOfWeek,S=function(B){var V,H,M,G;KG(n)?(V=r.onDayClick)===null||V===void 0||V.call(r,e,t,B):PL(n)?(H=s.onDayClick)===null||H===void 0||H.call(s,e,t,B):$L(n)?(M=i.onDayClick)===null||M===void 0||M.call(i,e,t,B):(G=n.onDayClick)===null||G===void 0||G.call(n,e,t,B)},k=function(B){var V;h(e),(V=n.onDayFocus)===null||V===void 0||V.call(n,e,t,B)},j=function(B){var V;f(),(V=n.onDayBlur)===null||V===void 0||V.call(n,e,t,B)},C=function(B){var V;(V=n.onDayMouseEnter)===null||V===void 0||V.call(n,e,t,B)},T=function(B){var V;(V=n.onDayMouseLeave)===null||V===void 0||V.call(n,e,t,B)},_=function(B){var V;(V=n.onDayPointerEnter)===null||V===void 0||V.call(n,e,t,B)},N=function(B){var V;(V=n.onDayPointerLeave)===null||V===void 0||V.call(n,e,t,B)},I=function(B){var V;(V=n.onDayTouchCancel)===null||V===void 0||V.call(n,e,t,B)},A=function(B){var V;(V=n.onDayTouchEnd)===null||V===void 0||V.call(n,e,t,B)},P=function(B){var V;(V=n.onDayTouchMove)===null||V===void 0||V.call(n,e,t,B)},D=function(B){var V;(V=n.onDayTouchStart)===null||V===void 0||V.call(n,e,t,B)},F=function(B){var V;(V=n.onDayKeyUp)===null||V===void 0||V.call(n,e,t,B)},Q=function(B){var V;switch(B.key){case"ArrowLeft":B.preventDefault(),B.stopPropagation(),n.dir==="rtl"?l():c();break;case"ArrowRight":B.preventDefault(),B.stopPropagation(),n.dir==="rtl"?c():l();break;case"ArrowDown":B.preventDefault(),B.stopPropagation(),u();break;case"ArrowUp":B.preventDefault(),B.stopPropagation(),d();break;case"PageUp":B.preventDefault(),B.stopPropagation(),B.shiftKey?v():p();break;case"PageDown":B.preventDefault(),B.stopPropagation(),B.shiftKey?y():m();break;case"Home":B.preventDefault(),B.stopPropagation(),x();break;case"End":B.preventDefault(),B.stopPropagation(),b();break}(V=n.onDayKeyDown)===null||V===void 0||V.call(n,e,t,B)},q={onClick:S,onFocus:k,onBlur:j,onKeyDown:Q,onKeyUp:F,onMouseEnter:C,onMouseLeave:T,onPointerEnter:_,onPointerLeave:N,onTouchCancel:I,onTouchEnd:A,onTouchMove:P,onTouchStart:D};return q}function Srr(){var e=ea(),t=K1t(),n=zSe(),r=BSe(),s=KG(e)?t.selected:PL(e)?n.selected:$L(e)?r.selected:void 0;return s}function krr(e){return Object.values(vv).includes(e)}function Orr(e,t){var n=[e.classNames.day];return Object.keys(t).forEach(function(r){var s=e.modifiersClassNames[r];if(s)n.push(s);else if(krr(r)){var i=e.classNames["day_".concat(r)];i&&n.push(i)}}),n}function jrr(e,t){var n=Ir({},e.styles.day);return Object.keys(t).forEach(function(r){var s;n=Ir(Ir({},n),(s=e.modifiersStyles)===null||s===void 0?void 0:s[r])}),n}function Crr(e,t,n){var r,s,i,o=ea(),l=USe(),c=yrr(e,t),u=wrr(e,c),d=Srr(),f=!!(o.onDayClick||o.mode!=="default");g.useEffect(function(){var C;c.outside||l.focusedDay&&f&&Qf(l.focusedDay,e)&&((C=n.current)===null||C===void 0||C.focus())},[l.focusedDay,e,n,f,c.outside]);var h=Orr(o,c).join(" "),p=jrr(o,c),m=!!(c.outside&&!o.showOutsideDays||c.hidden),v=(i=(s=o.components)===null||s===void 0?void 0:s.DayContent)!==null&&i!==void 0?i:Wnr,y=a.jsx(v,{date:e,displayMonth:t,activeModifiers:c}),x={style:p,className:h,children:y,role:"gridcell"},b=l.focusTarget&&Qf(l.focusTarget,e)&&!c.outside,S=l.focusedDay&&Qf(l.focusedDay,e),k=Ir(Ir(Ir({},x),(r={disabled:c.disabled,role:"gridcell"},r["aria-selected"]=c.selected,r.tabIndex=S||b?0:-1,r)),u),j={isButton:f,isHidden:m,activeModifiers:c,selectedDays:d,buttonProps:k,divProps:x};return j}function _rr(e){var t=g.useRef(null),n=Crr(e.date,e.displayMonth,t);return n.isHidden?a.jsx("div",{role:"gridcell"}):n.isButton?a.jsx(nQ,Ir({name:"day",ref:t},n.buttonProps)):a.jsx("div",Ir({},n.divProps))}function Trr(e){var t=e.number,n=e.dates,r=ea(),s=r.onWeekNumberClick,i=r.styles,o=r.classNames,l=r.locale,c=r.labels.labelWeekNumber,u=r.formatters.formatWeekNumber,d=u(Number(t),{locale:l});if(!s)return a.jsx("span",{className:o.weeknumber,style:i.weeknumber,children:d});var f=c(Number(t),{locale:l}),h=function(p){s(t,n,p)};return a.jsx(nQ,{name:"week-number","aria-label":f,className:o.weeknumber,style:i.weeknumber,onClick:h,children:d})}function Err(e){var t,n,r=ea(),s=r.styles,i=r.classNames,o=r.showWeekNumber,l=r.components,c=(t=l?.Day)!==null&&t!==void 0?t:_rr,u=(n=l?.WeekNumber)!==null&&n!==void 0?n:Trr,d;return o&&(d=a.jsx("td",{className:i.cell,style:s.cell,children:a.jsx(u,{number:e.weekNumber,dates:e.dates})})),a.jsxs("tr",{className:i.row,style:s.row,children:[d,e.dates.map(function(f){return a.jsx("td",{className:i.cell,style:s.cell,role:"presentation",children:a.jsx(c,{displayMonth:e.displayMonth,date:f})},Ker(f))})]})}function PBe(e,t,n){for(var r=n?.ISOWeek?T1t(t):ISe(t,n),s=n?.ISOWeek?k0(e):vp(e,n),i=zy(r,s),o=[],l=0;l<=i;l++)o.push(cu(s,l));var c=o.reduce(function(u,d){var f=n?.ISOWeek?ASe(d):$Se(d,n),h=u.find(function(p){return p.weekNumber===f});return h?(h.dates.push(d),u):(u.push({weekNumber:f,dates:[d]}),u)},[]);return c}function Irr(e,t){var n=PBe(Xf(e),ESe(e),t);if(t?.useFixedWeeks){var r=Xer(e,t);if(r<6){var s=n[n.length-1],i=s.dates[s.dates.length-1],o=bpe(i,6-r),l=PBe(bpe(i,1),o,t);n.push.apply(n,l)}}return n}function Nrr(e){var t,n,r,s=ea(),i=s.locale,o=s.classNames,l=s.styles,c=s.hideHead,u=s.fixedWeeks,d=s.components,f=s.weekStartsOn,h=s.firstWeekContainsDate,p=s.ISOWeek,m=Irr(e.displayMonth,{useFixedWeeks:!!u,ISOWeek:p,locale:i,weekStartsOn:f,firstWeekContainsDate:h}),v=(t=d?.Head)!==null&&t!==void 0?t:Znr,y=(n=d?.Row)!==null&&n!==void 0?n:Err,x=(r=d?.Footer)!==null&&r!==void 0?r:Unr;return a.jsxs("table",{id:e.id,className:o.table,style:l.table,role:"grid","aria-labelledby":e["aria-labelledby"],children:[!c&&a.jsx(v,{}),a.jsx("tbody",{className:o.tbody,style:l.tbody,children:m.map(function(b){return a.jsx(y,{displayMonth:e.displayMonth,dates:b.dates,weekNumber:b.weekNumber},b.weekNumber)})}),a.jsx(x,{displayMonth:e.displayMonth})]})}function Arr(){return!!(typeof window<"u"&&window.document&&window.document.createElement)}var Prr=Arr()?g.useLayoutEffect:g.useEffect,Ooe=!1,$rr=0;function $Be(){return"react-day-picker-".concat(++$rr)}function Rrr(e){var t,n=e??(Ooe?$Be():null),r=g.useState(n),s=r[0],i=r[1];return Prr(function(){s===null&&i($Be())},[]),g.useEffect(function(){Ooe===!1&&(Ooe=!0)},[]),(t=e??s)!==null&&t!==void 0?t:void 0}function Mrr(e){var t,n,r=ea(),s=r.dir,i=r.classNames,o=r.styles,l=r.components,c=RL().displayMonths,u=Rrr(r.id?"".concat(r.id,"-").concat(e.displayIndex):void 0),d=r.id?"".concat(r.id,"-grid-").concat(e.displayIndex):void 0,f=[i.month],h=o.month,p=e.displayIndex===0,m=e.displayIndex===c.length-1,v=!p&&!m;s==="rtl"&&(t=[p,m],m=t[0],p=t[1]),p&&(f.push(i.caption_start),h=Ir(Ir({},h),o.caption_start)),m&&(f.push(i.caption_end),h=Ir(Ir({},h),o.caption_end)),v&&(f.push(i.caption_between),h=Ir(Ir({},h),o.caption_between));var y=(n=l?.Caption)!==null&&n!==void 0?n:Vnr;return a.jsxs("div",{className:f.join(" "),style:h,children:[a.jsx(y,{id:u,displayMonth:e.displayMonth,displayIndex:e.displayIndex}),a.jsx(Nrr,{id:d,"aria-labelledby":u,displayMonth:e.displayMonth})]},e.displayIndex)}function Drr(e){var t=ea(),n=t.classNames,r=t.styles;return a.jsx("div",{className:n.months,style:r.months,children:e.children})}function Lrr(e){var t,n,r=e.initialProps,s=ea(),i=USe(),o=RL(),l=g.useState(!1),c=l[0],u=l[1];g.useEffect(function(){s.initialFocus&&i.focusTarget&&(c||(i.focus(i.focusTarget),u(!0)))},[s.initialFocus,c,i.focus,i.focusTarget,i]);var d=[s.classNames.root,s.className];s.numberOfMonths>1&&d.push(s.classNames.multiple_months),s.showWeekNumber&&d.push(s.classNames.with_weeknumber);var f=Ir(Ir({},s.styles.root),s.style),h=Object.keys(r).filter(function(m){return m.startsWith("data-")}).reduce(function(m,v){var y;return Ir(Ir({},m),(y={},y[v]=r[v],y))},{}),p=(n=(t=r.components)===null||t===void 0?void 0:t.Months)!==null&&n!==void 0?n:Drr;return a.jsx("div",Ir({className:d.join(" "),style:f,dir:s.dir,id:s.id,nonce:r.nonce,title:r.title,lang:r.lang},h,{children:a.jsx(p,{children:o.displayMonths.map(function(m,v){return a.jsx(Mrr,{displayIndex:v,displayMonth:m},v)})})}))}function zrr(e){var t=e.children,n=cnr(e,["children"]);return a.jsx(Tnr,{initialProps:n,children:a.jsx(Lnr,{children:a.jsx(xrr,{initialProps:n,children:a.jsx(Hnr,{initialProps:n,children:a.jsx(Ynr,{initialProps:n,children:a.jsx(irr,{children:a.jsx(vrr,{children:t})})})})})})})}function Frr(e){return a.jsx(zrr,Ir({},e,{children:a.jsx(Lrr,{initialProps:e})}))}function Ope({className:e,classNames:t,showOutsideDays:n=!0,...r}){return a.jsx(Frr,{showOutsideDays:n,className:Z("p-3",e),classNames:{months:"flex flex-col space-y-4 sm:space-y-0 ",month:"space-y-4 text-caption",caption:"flex justify-between pt-1 items-center pl-2",caption_label:"text-label text-foreground",nav:"flex items-center",nav_button_previous:Z(Fn,"flex size-7 items-center justify-center rounded-md bg-transparent p-0 hover:bg-fill-subtle"),nav_button_next:Z(Fn,"flex size-7 items-center justify-center rounded-md bg-transparent p-0 hover:bg-fill-subtle"),dropdown_month:"w-full border-collapse space-y-1",weeknumber:"flex",day:Z("relative p-0 text-center focus-within:relative focus-within:z-20 [&:has([aria-selected])]:bg-fill [&:has([aria-selected].day-outside)]:bg-fill-subtle [&:has([aria-selected].day-range-end)]:rounded-r-md",r.mode==="range"?"[&:has(>.day-range-end)]:rounded-r-md [&:has(>.day-range-start)]:rounded-l-md first:[&:has([aria-selected])]:rounded-l-md last:[&:has([aria-selected])]:rounded-r-md":"[&:has([aria-selected])]:rounded-md","size-8 p-0 text-caption hover:bg-fill-subtle aria-selected:opacity-100"),day_range_start:"day-range-start rounded-l-md",day_range_end:"day-range-end rounded-r-md",day_selected:Z("bg-foreground! text-sidebar! hover:bg-foreground/90! focus:bg-foreground/90! focus:text-sidebar!",r.mode!=="range"&&"rounded-md"),day_today:"bg-fill text-foreground",day_outside:"day-outside text-muted-foreground opacity-50 aria-selected:bg-fill-subtle aria-selected:text-muted-foreground aria-selected:opacity-30",day_disabled:"text-muted-foreground opacity-50",day_range_middle:"aria-selected:bg-fill aria-selected:text-foreground",day_hidden:"invisible",head_cell:"text-meta text-muted-foreground",...t},...r})}const Y1t=g.createContext(void 0);function ML(e){const t=g.useContext(Y1t);if(t===void 0&&!e)throw new Error(Ar(47));return t}const Brr={...W3,disabled:e=>e.disabled,instantType:e=>e.instantType,openMethod:e=>e.openMethod,openChangeReason:e=>e.openChangeReason,modal:e=>e.modal,focusManagerModal:e=>e.focusManagerModal,stickIfOpen:e=>e.stickIfOpen,titleElementId:e=>e.titleElementId,descriptionElementId:e=>e.descriptionElementId,openOnHover:e=>e.openOnHover,closeDelay:e=>e.closeDelay,adaptiveOrigin:e=>e.adaptiveOrigin};class Vrr extends p_{constructor(t,n,r){const s=new m_;super(Urr(t,s,n,r),qrr(s),Brr)}setOpen=(t,n)=>{const r=n.reason===Ma,s=n.reason===fv&&n.event.detail===0,i=!t&&(n.reason===d_||n.reason==null),o=b0e(n),l=this.select("activeTriggerId");if(!t&&n.reason===i0e&&n.trigger==null&&l!=null&&(n.trigger=this.context.triggerElements.getById(l)??this.select("activeTriggerElement")??void 0),this.context.onOpenChange?.(t,n),n.isCanceled)return;this.state.floatingRootContext.dispatchOpenChange(t,n);const c=()=>{const d={open:t,openChangeReason:n.reason};OH(d,t,n.trigger,o()),this.update(d)};r?(this.set("stickIfOpen",!0),this.context.stickIfOpenTimeout.start(Bdt,()=>{this.set("stickIfOpen",!1)}),wo.flushSync(c)):c();let u;s?u="click":i?u="dismiss":n.reason===p0&&(u="focus"),this.set("instantType",u)}}function Urr(e,t,n,r=!1){const s={...Z3(),disabled:!1,modal:!1,focusManagerModal:!1,instantType:void 0,openMethod:null,openChangeReason:null,titleElementId:void 0,descriptionElementId:void 0,stickIfOpen:!0,openOnHover:!1,closeDelay:0,adaptiveOrigin:void 0,...e};return s.open&&e?.mounted===void 0&&(s.mounted=!0),s.floatingRootContext=jH(t,n,r),s}function qrr(e){return{popupRef:g.createRef(),onOpenChange:void 0,onOpenChangeComplete:void 0,triggerFocusTargetRef:g.createRef(),beforeContentFocusGuardRef:g.createRef(),stickIfOpenTimeout:new Dm,triggerElements:e}}function RBe({props:e}){const{children:t,open:n,defaultOpen:r=!1,onOpenChange:s,onOpenChangeComplete:i,modal:o=!1,handle:l,triggerId:c,defaultTriggerId:u=null}=e,d=Zrr(l,{modal:o,open:r,openProp:n,activeTriggerId:u,triggerIdProp:c});d.useControlledProp("openProp",n),d.useControlledProp("triggerIdProp",c);const f=d.useState("open"),h=d.useState("mounted"),p=d.useState("payload");d.useContextCallback("onOpenChange",s),d.useContextCallback("onOpenChangeComplete",i),dft(d,f),U3(d);const{forceUnmount:m}=q3(f,d,()=>{d.update({stickIfOpen:!0,openChangeReason:null})});d.useSyncedValues({modal:o}),g.useEffect(()=>{f||d.context.stickIfOpenTimeout.clear()},[d,f]),g.useImperativeHandle(e.actionsRef,()=>({unmount:m,close:()=>d.setOpen(!1,Yt(L3))}),[m,d]);const v=f||h;return a.jsxs(Y1t.Provider,{value:d,children:[l&&a.jsx(B3,{handle:l,store:d}),v&&a.jsx(Wrr,{store:d,modal:o}),typeof t=="function"?t({payload:p}):t]})}function Qrr(e){return ML(!0)?a.jsx(RBe,{props:e}):a.jsx(g0e,{children:a.jsx(RBe,{props:e})})}function Zrr(e,t){const n=kH((r,s)=>new Vrr(t,r,s));return g.useEffect(()=>n.context.stickIfOpenTimeout.disposeEffect(),[n]),n}function Wrr({store:e,modal:t}){const n=e.useState("floatingRootContext"),r=h_(n,{outsidePressEvent:{mouse:t==="trap-focus"?"sloppy":"intentional",touch:"sloppy"}}),s=r.reference,i=r.floating;return Q3(e,{activeTriggerProps:s,inactiveTriggerProps:s,popupProps:i}),null}const Hrr=300,Grr=g.forwardRef(function(t,n){const{render:r,className:s,style:i,disabled:o=!1,nativeButton:l=!0,handle:c,payload:u,openOnHover:d=!1,delay:f=Hrr,closeDelay:h=0,id:p,...m}=t,v=ML(!0),x=H3(c)??v;if(!x)throw new Error(Ar(74));const b=Qi(p),S=x.useState("isTriggerActive",b),k=x.useState("floatingRootContext"),j=x.useState("isOpenedByTrigger",b),C=x.useState("triggerPopupId",b),T=g.useRef(null),{registerTrigger:_,isMountedByThisTrigger:N}=V3(b,T,x,{payload:u,disabled:o,openOnHover:d,closeDelay:h}),I=x.useState("openChangeReason"),A=x.useState("stickIfOpen"),P=x.useState("openMethod"),D=x.useState("focusManagerModal"),F=G3(k,{enabled:!o&&d&&(P!=="touch"||I!==fv),mouseOnly:!0,move:!1,handleClose:K3(),restMs:f,delay:{close:h},triggerElementRef:T,isActiveTrigger:S,isClosing:()=>x.select("transitionStatus")==="ending"}),Q=f_(k,{stickIfOpen:A}),q=tSe(()=>x.select("open"),ne=>{x.set("openMethod",ne)}),B=x.useState("triggerProps",N),{getButtonProps:V,buttonRef:H}=hd({disabled:o,native:l}),M={open(ne){return ne&&I===fv?kN.open(ne):rP.open(ne)}},{preFocusGuardRef:G,handlePreFocusGuardFocus:L,handleFocusTargetFocus:$}=lwt(x,T),U=hn("button",t,{state:{disabled:o,open:j},ref:[H,n,_,T],props:[Q.reference,F,B,q,{[f0e]:"",id:b,"aria-haspopup":"dialog","aria-expanded":j,"aria-controls":C},m,V],stateAttributesMapping:M}),K=a.jsx(g.Fragment,{children:U},b);return N&&!D?a.jsxs(g.Fragment,{children:[a.jsx(dS,{ref:G,onFocus:L}),K,a.jsx(dS,{ref:x.context.triggerFocusTargetRef,onFocus:$})]}):K}),X1t=g.createContext(void 0);function Krr(){const e=g.useContext(X1t);if(e===void 0)throw new Error(Ar(45));return e}const Yrr=g.forwardRef(function(t,n){const{keepMounted:r=!1,...s}=t;return ML().useState("mounted")||r?a.jsx(X1t.Provider,{value:r,children:a.jsx(F3,{ref:n,...s})}):null}),J1t=g.createContext(void 0);function Xrr(){const e=g.useContext(J1t);if(!e)throw new Error(Ar(46));return e}const Jrr=g.forwardRef(function(t,n){const{render:r,className:s,style:i,anchor:o,positionMethod:l,side:c,align:u,sideOffset:d,alignOffset:f,collisionBoundary:h="clipping-ancestors",collisionPadding:p,arrowPadding:m,sticky:v,disableAnchorTracking:y=!1,collisionAvoidance:x=vH,...b}=t,S=ML(),k=Krr(),j=yH(),C=S.useState("floatingRootContext"),T=S.useState("mounted"),_=S.useState("open"),N=S.useState("openChangeReason"),I=S.useState("activeTriggerElement"),A=S.useState("modal"),P=S.useState("openMethod"),D=S.useState("positionerElement"),F=S.useState("instantType"),Q=S.useState("transitionStatus"),q=S.useState("adaptiveOrigin"),B=g.useRef(null),V=SH(D),H=sP({anchor:o,floatingRootContext:C,positionMethod:l,mounted:T,side:c,sideOffset:d,align:u,alignOffset:f,arrowPadding:m,collisionBoundary:h,collisionPadding:p,sticky:v,disableAnchorTracking:y,keepMounted:k,nodeId:j,collisionAvoidance:x,adaptiveOrigin:q}),M=C.useState("domReferenceElement");It(()=>{const U=M,K=B.current;if(U&&(B.current=U),K&&U&&U!==K){S.set("instantType",void 0);const ne=new AbortController;return V(()=>{S.set("instantType","trigger-change")},ne.signal),()=>{ne.abort()}}},[M,V,S]);const G=A===!0&&N!==Ma;LG(_&&G,P==="touch",D,I);const L=S.useStateSetter("positionerElement"),$={open:_,side:H.side,align:H.align,anchorHidden:H.anchorHidden,instant:F},z=iP(t,$,{styles:H.positionerStyles,transitionStatus:Q,props:b,refs:[n,L],hidden:!T,inert:!_});return a.jsxs(J1t.Provider,{value:H,children:[T&&G&&a.jsx(TL,{inert:oP(!_),cutout:I}),a.jsx(m0e,{id:j,children:z})]})}),esr=g.createContext(void 0);function tsr(){const[e,t]=g.useState(0),n=pt(()=>(t(s=>s+1),()=>{t(s=>Math.max(0,s-1))}));return{context:g.useMemo(()=>({register:n}),[n]),hasClosePart:e>0}}const nsr=g.forwardRef(function(t,n){const{render:r,className:s,style:i,initialFocus:o,finalFocus:l,...c}=t,u=ML(),d=Xrr(),f=eSe()!=null,{context:h,hasClosePart:p}=tsr(),m=u.useState("open"),v=u.useState("openMethod"),y=u.useState("instantType"),x=u.useState("transitionStatus"),b=u.useState("popupProps"),S=u.useState("titleElementId"),k=u.useState("descriptionElementId"),j=u.useState("modal"),C=u.useState("mounted"),T=u.useState("openChangeReason"),_=u.useState("activeTriggerElement"),N=u.useState("floatingRootContext"),I=N.useState("floatingId"),A=u.useState("disabled"),P=u.useState("openOnHover"),D=u.useState("closeDelay");Wl({open:m,ref:u.context.popupRef,onComplete(){m&&u.context.onOpenChangeComplete?.(!0)}}),CH(N,{enabled:P&&!A,closeDelay:D});const F=o===void 0?lft(u.context.popupRef):o,Q=j!==!1&&p;u.useSyncedValue("focusManagerModal",Q);const q=u.useStateSetter("popupElement"),B={open:m,side:d.side,align:d.align,instant:y,transitionStatus:x},V=hn("div",t,{state:B,ref:[n,u.context.popupRef,q],props:[b,{id:I,role:"dialog",...lk,"aria-labelledby":S,"aria-describedby":k,onKeyDown(H){f&&gk.has(H.key)&&H.stopPropagation()}},y_(x),c],stateAttributesMapping:v_});return a.jsx(nP,{context:N,openInteractionType:v,modal:Q,disabled:!C||T===Ma,initialFocus:F,returnFocus:l,restoreFocus:"popup",previousFocusableElement:ei(_)?_:void 0,nextFocusableElement:u.context.triggerFocusTargetRef,beforeContentFocusGuardRef:u.context.beforeContentFocusGuardRef,children:a.jsx(esr.Provider,{value:h,children:V})})}),_p=Qrr,of=g.forwardRef(({className:e,asChild:t,render:n,children:r,variant:s,size:i,tooltip:o,...l},c)=>{const u=wwt({render:n,asChild:t,children:r,variant:s,size:i,tooltip:o,className:e});return a.jsx(Grr,{ref:c,className:u.className,render:u.render,...l,children:u.children})});of.displayName="PopoverTrigger";const lh=g.forwardRef(({className:e,container:t,align:n="center",alignOffset:r=0,side:s="bottom",sideOffset:i=4,anchor:o,positionMethod:l=jv,collisionBoundary:c,collisionPadding:u,sticky:d,arrowPadding:f,disableAnchorTracking:h,collisionAvoidance:p,...m},v)=>{const y=typeof e=="string"?e:void 0,x=U0(t),b={align:n,alignOffset:r,side:s,sideOffset:i,anchor:o,positionMethod:l,collisionBoundary:c,collisionPadding:u,sticky:d,arrowPadding:f,disableAnchorTracking:h,collisionAvoidance:p};return a.jsx(Yrr,{container:x,children:a.jsx(Jrr,{className:"z-50 outline-none",...b,children:a.jsx(nsr,{ref:v,"data-slot":"popover-content",className:Z("z-50 w-72 origin-[var(--transform-origin)] rounded-xl text-foreground focus-visible:outline-hidden",rh,"data-[closed]:animate-out data-[closed]:fade-out-0 data-[closed]:zoom-out-95 data-[open]:animate-in data-[open]:fade-in-0 data-[open]:zoom-in-95","data-[side=bottom]:slide-in-from-top-1 data-[side=left]:slide-in-from-right-1 data-[side=right]:slide-in-from-left-1 data-[side=top]:slide-in-from-bottom-1",y&&/\bp[trblxy]?-\S+/.test(y)?!1:"px-3 py-3.5",e),...m})})})});lh.displayName="PopoverContent";const rsr=({inputProps:e,field:t})=>{const{key:n,...r}=e,[s,i]=g.useState(void 0),[o,l]=g.useState(!1),c=Hgt();g.useEffect(()=>{if(t.default){const f=new Date(t.default);TSe(f)&&i(f)}},[t]);const u=f=>{i(f),f&&r.onChange({target:{value:f.toISOString(),name:e.name}}),l(!1)},d=()=>{i(void 0),r.onChange({target:{value:"",name:e.name}}),l(!1)};return a.jsxs(_p,{open:o,onOpenChange:l,children:[a.jsx(of,{asChild:!0,children:a.jsx(de,{...c,variant:"default",size:"lg",className:Z("w-full",N0e),icon:a.jsx($U,{}),children:s?a.jsx("span",{className:"text-foreground",children:yk(s,"PPP")}):a.jsx("span",{className:"text-muted-foreground",children:"Pick a date"})})}),a.jsxs(lh,{className:"w-auto bg-muted p-0",align:"start",children:[a.jsx(Ope,{mode:"single",selected:s,onSelect:u,month:s,onMonthChange:i}),s&&a.jsx("div",{className:"p-3 pt-0",children:a.jsx(de,{icon:a.jsx(Dn,{}),variant:"default",size:"lg",className:"w-full",onClick:d,children:"Clear"})})]})]})},ssr=({field:e,path:t})=>{const{uiComponents:n}=jSe(),{control:r}=Lr(),{fields:s,append:i,remove:o}=JXn({control:r,name:t.join(".")}),l=e.schema?.[0]?.type;let c;l==="object"?c={}:l==="array"?c=[]:c=null;const u=e.schema?.[0];return u?a.jsx(n.ArrayWrapper,{label:d5(e),field:e,onAddItem:()=>i(c),children:s.map((d,f)=>a.jsx(HG,{value:[...t,f.toString()].join("."),children:a.jsx(n.ArrayElementWrapper,{onRemove:()=>o(f),index:f,children:a.jsx(Rj,{field:u,path:[...t,f.toString()]})})},d.id))}):a.jsx(n.ErrorMessage,{error:`[AutoForm] Unable to determine array element schema for "${d5(e)}"`})},isr=({field:e,path:t})=>{const{uiComponents:n}=jSe();return a.jsx(HG,{value:t.join("."),children:a.jsx(n.ObjectWrapper,{label:d5(e),field:e,children:Object.entries(e.schema??[]).map(([r,s])=>a.jsx(Rj,{field:s,path:[...t,s.key]},`${t.join(".")}.${s.key}`))})})},Rj=({field:e,path:t})=>{const{formComponents:n,uiComponents:r}=jSe(),{register:s,formState:{errors:i,defaultValues:o},getValues:l,control:c}=Lr(),u=t.join("."),d=kBe(i,t)?.message,f=Zn({control:c,name:u}),h=f===void 0?l(u):f,p=g.useMemo(()=>{if(!o)return e.default;const x=kBe(o,t);return x===void 0?e.default:x},[o,t,e.default]),m=e.fieldConfig?.fieldWrapper||r.FieldWrapper;let v=()=>a.jsx(r.ErrorMessage,{error:`[AutoForm Configuration Error] No component found for type "${e.type}" nor a fallback`});e.type==="array"?v=ssr:e.type==="object"?v=isr:e.type in n?v=n[e.type]??v:"fallback"in n&&(v=n.fallback);const y={...e,default:p};return a.jsx(m,{label:d5(e),error:d,id:u,field:y,children:a.jsx(v,{label:d5(e),field:y,value:h,error:d,id:u,path:t,inputProps:{"aria-required":e.required||void 0,key:`${u}-input`,...e.fieldConfig?.inputProps,...s(u)}},u)})},osr=({field:e,path:t})=>{const{watch:n}=Lr(),r=t.join("."),s=n(r),o=(e.schema?.flatMap(h=>h.schema||[])||[])?.filter(h=>h.fieldConfig?.customData?.isLiteral)||[],l=o[0];if(!l)return null;const c=o?.reduce((h,p)=>{const m=(p.fieldConfig?.customData?.literalValues??[]).map(v=>[v,v]);return h.options?.push(...m),h},{key:l.key,required:l.required,type:"select",default:l.default,description:l.description,options:[],fieldConfig:l.fieldConfig}),u=e.schema?.reduce((h,p)=>{const m=p.schema?.find(x=>x.fieldConfig?.customData?.isLiteral),v=m?.fieldConfig?.customData?.literalValues?.[0],y=p.schema?.filter(x=>x.key!==m?.key)??[];return v&&(h[v]=y),h},{}),d=e.schema?.filter(h=>!h.schema?.find(m=>m.fieldConfig?.customData?.isLiteral)),f=s?.[c.key];return a.jsxs("div",{children:[a.jsx(Rj,{field:c,path:[...t,c.key]},`${r}.${c.key}`),f&&u?.[f]&&u[f].map(h=>a.jsx(Rj,{field:h,path:[...t,h.key]},`${r}.${h.key}`)),d&&d.map(h=>a.jsx(Rj,{field:h,path:[...t,h.key]},`${r}.${h.key}`))]},e.key)},asr=({error:e})=>a.jsx(Ht,{variant:"destructive",title:e}),lsr=["object","array"];function MBe({description:e,error:t}){return!e&&!t?null:a.jsxs(ft,{invalid:!!t,children:[e&&a.jsx(no,{children:e}),a.jsx(is,{children:t})]})}const csr=({label:e,children:t,field:n,error:r})=>{const s=n.fieldConfig?.description;if(n.type==="record")return a.jsxs(x0,{className:"gap-2 pb-4 last:pb-0",children:[a.jsx(pC,{required:n.required,children:e}),t,a.jsx(MBe,{description:s,error:r})]});if(lsr.includes(n.type))return a.jsxs("div",{className:"pb-4 last:pb-0",children:[t,a.jsx(MBe,{description:s,error:r})]});const i=n.type==="boolean";return a.jsxs(ft,{invalid:!!r,className:"pb-4 last:pb-0",children:[!i&&a.jsx(ut,{required:n.required,className:"block",children:e}),t,s&&a.jsx(no,{children:s}),a.jsx(is,{children:r})]})};function usr({className:e,...t}){return a.jsx("form",{"data-slot":"form",className:Z("flex flex-col gap-4",e),...t})}const eSt=g.forwardRef(function(t,n){return a.jsx(Zgt,{ref:n,...t})}),dsr=pd(Z("flex w-full text-ellipsis text-foreground",jn,"placeholder:text-muted-foreground placeholder:transition-opacity placeholder:duration-normal","focus:placeholder:opacity-70 motion-reduce:placeholder:transition-none","[&::-webkit-outer-spin-button]:m-0 [&::-webkit-outer-spin-button]:appearance-none","[&::-webkit-inner-spin-button]:m-0 [&::-webkit-inner-spin-button]:appearance-none","[&[type=number]]:[appearance:textfield]","[&::-webkit-search-cancel-button]:appearance-none"),{variants:{variant:{default:Z(Nft,"rounded-full",E0e),unstyled:A0e},size:{sm:Z(sv.sm,"px-[.75em]"),md:Z(sv.md,"px-[.75em]"),lg:Z(sv.lg,"px-[.85em]")}},defaultVariants:{variant:"default",size:"md"}});function Sn({className:e,size:t,testId:n,variant:r,error:s,autoComplete:i,...o}){return a.jsx(eSt,{className:Z(dsr({variant:Aft(r),size:t}),_ft,e),"data-testid":n,...TH(s),...o,...UG(i),...Tx(o)})}const jpe=Symbol("invalid");function DBe(e){if(e==="")return;const t=Number(e);return isNaN(t)?jpe:t}const fsr=({inputProps:e,field:t})=>{const{key:n,...r}=e;return a.jsx(Sn,{type:"number",step:"any",...r,defaultValue:t.default!==void 0?Number(t.default):void 0,onChange:s=>{const i=DBe(s.target.value);i!==jpe&&r.onChange({target:{value:i,name:e.name}})},onBlur:s=>{const i=DBe(s.target.value);i!==jpe&&r.onChange({target:{value:i,name:e.name}})}})};function hsr({label:e,children:t}){return e===GG||e===""?a.jsx("div",{className:"flex flex-col gap-2",children:t}):a.jsx(psr,{label:e,children:t})}function psr({label:e,children:t}){const n=g.useContext(HG),{expanded:r,invalid:s,setExpanded:i}=D1t(n,!1);return a.jsxs(Kl,{open:r,onOpenChange:i,className:"motion-reduce:[&_[data-slot=collapsible-content]]:transition-none motion-reduce:[&_svg]:transition-none",children:[a.jsxs(Cl,{className:"flex min-h-11 w-full items-center gap-2 text-left text-caption text-muted-foreground",children:[a.jsx(Na,{direction:"right",className:"size-3.5"}),a.jsxs("span",{className:"flex min-w-0 items-center gap-1.5",children:[a.jsx(Ua,{"aria-hidden":!0,className:"size-3.5"}),e]}),s&&a.jsx(Y,{as:"span",variant:"meta",className:"ml-auto shrink-0 text-destructive-foreground",children:"Needs input"})]}),a.jsx(_l,{keepMounted:!0,className:"border-l border-border pt-2 pl-4",children:t})]})}const msr=({inputProps:e,field:t})=>{const{onChange:n}=e,[r,s]=g.useState(()=>Object.entries(t.default||{}).map(([d,f])=>({id:d||Sa(),key:d,value:f})));g.useEffect(()=>{r.length===0&&s([{id:Sa(),key:"",value:""}])},[r]);const i=g.useCallback(d=>{const f=d.reduce((h,p)=>(p.key&&(h[p.key]=p.value),h),{});n?.({target:{value:f,name:e.name}})},[n,e.name]),o=(d,f,h)=>{s(p=>p.map(m=>m.id===d?{...m,[f]:h}:m))},l=()=>{i(r)},c=()=>{const d=[...r,{id:Sa(),key:"",value:""}];s(d),i(d)},u=d=>{const f=r.filter(h=>h.id!==d);f.length===0&&f.push({id:Sa(),key:"",value:""}),s(f),i(f)};return a.jsxs("div",{className:"grid gap-2",children:[r.map(d=>a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(Sn,{placeholder:"Key",className:"flex-1","aria-label":"Key",value:d.key,onChange:f=>o(d.id,"key",f.target.value),onBlur:l}),a.jsx(Sn,{placeholder:"Value",className:"flex-1","aria-label":"Value",value:d.value,onChange:f=>o(d.id,"value",f.target.value),onBlur:l}),a.jsx(de,{type:"button",variant:"ghost",size:"icon-md",tooltip:"Remove pair","aria-label":"Remove pair",onClick:()=>u(d.id),children:a.jsx(Oht,{})})]},d.id)),a.jsx(de,{type:"button",variant:"ghost",size:"sm",className:"justify-self-start",onClick:c,icon:a.jsx(ys,{}),children:"Add pair"})]})},gsr=({field:e,inputProps:t,value:n})=>{const{key:r,...s}=t;return a.jsxs(Vr,{...s,value:n,onValueChange:i=>{const o={target:{value:i,name:t.name}};s.onChange(o)},children:[a.jsx(qr,{children:a.jsx(Ur,{placeholder:"Select an option"})}),a.jsx(Qr,{children:(e.options||[]).map(([i,o])=>a.jsx(ir,{value:i,children:o},i))})]})},vsr=({inputProps:e,field:t})=>{const{key:n,className:r,...s}=e;return a.jsx(Eu,{...s,rows:1,className:Z("field-sizing-content max-h-48 min-h-control-md resize-none overflow-y-auto",r),defaultValue:t.default})},ysr=({children:e})=>a.jsx(de,{type:"submit",children:e}),xsr=({field:e,inputProps:t})=>{const n=t.name?.split(".")??[];return e.schema?.map((r,s)=>a.jsxs("div",{children:[a.jsx(Rj,{field:r,path:n},n.join(".")),s<(e.schema?.length??0)-1&&a.jsx(Y,{variant:"meta",className:"text-center",children:"OR"})]},r.key))};function bsr({schema:e,onSubmit:t,defaultValues:n,values:r,children:s,uiComponents:i,formComponents:o,withSubmit:l=!1,onFormInit:c,formProps:u={}}){const d=g.useMemo(()=>mJn(e),[e]),f=vk({defaultValues:{...gJn(e),...n},values:r});g.useEffect(()=>{c&&c(f)},[c,f]);const h=g.useCallback(async m=>{const v=e.validateSchema(m);if(v.success)await t?.(v.data,f);else{f.clearErrors();let y=!1;v.errors?.forEach(x=>{const b=x.path.join(".");f.setError(b,{type:"custom",message:x.message},{shouldFocus:!y}),y=!0;const S=x.path?.slice?.(0,-1);S?.length>0&&f.setError(S.join("."),{type:"custom",message:x.message})})}},[e,t,f]),p=g.useMemo(()=>({schema:d,uiComponents:i,formComponents:o}),[d,i,o]);return a.jsx(u5,{...f,children:a.jsx(jJn,{value:p,children:a.jsxs(i.Form,{onSubmit:f.handleSubmit(h),...u,children:[d.fields.map(m=>a.jsx(Rj,{field:m,path:[m.key]},m.key)),s,l&&a.jsx(i.SubmitButton,{children:"Submit"})]})})})}const wsr={Form:usr,FieldWrapper:csr,ErrorMessage:asr,SubmitButton:ysr,ObjectWrapper:hsr,ArrayWrapper:Jtr,ArrayElementWrapper:Xtr};function Ssr({uiComponents:e,formComponents:t,readOnly:n,...r}){const s=g.useMemo(()=>({...wsr,...e}),[e]),i=g.useMemo(()=>{const o=l=>n===void 0?l:{...l,readOnly:n};return{string:l=>a.jsx(vsr,{...l,inputProps:o(l.inputProps)}),number:l=>a.jsx(fsr,{...l,inputProps:o(l.inputProps)}),boolean:l=>a.jsx(lnr,{...l,inputProps:o(l.inputProps)}),date:l=>a.jsx(rsr,{...l,inputProps:o(l.inputProps)}),select:l=>a.jsx(gsr,{...l,inputProps:o(l.inputProps)}),record:l=>a.jsx(msr,{...l,inputProps:o(l.inputProps)}),union:l=>a.jsx(xsr,{...l,inputProps:o(l.inputProps)}),"discriminated-union":l=>a.jsx(osr,{...l,inputProps:o(l.inputProps)}),...t}},[n,t]);return a.jsx(SSe,{value:n===!0,children:a.jsx(bsr,{...r,uiComponents:s,formComponents:i})})}function tSt(e){return e!=null&&typeof e=="object"&&"_zod"in e}function Iu(e){if(!(e==null||typeof e!="object"))return tSt(e)?e._zod.def:e._def}function ksr(e){return typeof e.isOptional=="function"?e.isOptional():typeof e.safeParse=="function"?e.safeParse(void 0).success:!1}function Om(e){if(e.shape&&typeof e.shape=="object")return e.shape;const t=Iu(e);if(t?.shape)return typeof t.shape=="function"?t.shape():t.shape}function p5(e){const t=Iu(e);return t?"innerType"in t?p5(t.innerType):"schema"in t?p5(t.schema):e:e}function Osr(e){const t=Iu(e);if(t?.entries)return t.entries;if(t?.values)return t.values}function nSt(e){const t=Iu(e);return t?.element??t?.type}function jsr(e){return Iu(e)?.valueType}function rSt(e){const t=Iu(e);if(t?.values!==void 0)return Array.isArray(t.values)?t.values[0]:t.values;if(t?.value!==void 0)return t.value}function Csr(e){const t=Iu(e);if(t?.values!==void 0)return t.values;if(t?.value!==void 0)return[t.value]}function _sr(e){const t=Iu(e);if(t?.defaultValue!==void 0)return typeof t.defaultValue=="function"?t.defaultValue():t.defaultValue}function QSe(e){return Iu(e)?.options}function rQ(e){const t=Iu(e);if(t?.left&&t?.right)return{left:t.left,right:t.right};if(e.def?.left&&e.def?.right)return{left:e.def.left,right:e.def.right}}function Tsr(e){return Iu(e)?.checks??[]}function Esr(e){return e.some(t=>{if(tSt(t)){const n=Iu(t);return n?.check==="string_format"&&n?.format==="datetime"}return t.kind==="datetime"})}function sQ(e){const t=Om(e);if(t)return Object.keys(t).length===0;const n=rQ(e);return n?sQ(n.left)&&sQ(n.right):!1}function hj(e){const t=Iu(e);if(!t)return;const n=_sr(e);if(n!==void 0)return n;const r=rSt(e);if(r!==void 0&&(t.typeName==="ZodLiteral"||t.type==="literal"||e?.constructor?.name?.slice(1)==="ZodLiteral"))return r;if("innerType"in t)return hj(t.innerType);if("schema"in t)return hj(t.schema);if(Om(e)&&!("left"in t))return RB(e);if("left"in t&&"right"in t){const i=Om(t.left),o=Om(t.right),l=i?RB(t.left):hj(t.left),c=o?RB(t.right):hj(t.right);return{...l,...c}}}function RB(e){const t=Om(e);if(!t)return{};const n={};for(const[r,s]of Object.entries(t)){const i=hj(s);i!==void 0&&(n[r]=i)}return n}function sSt(e,t){if(t?.fieldType)return t.fieldType;const n=e?.constructor?.name?.slice(1),r=Iu(e),s=typeof r?.type=="string"?`Zod${r.type.charAt(0).toUpperCase()}${r.type.slice(1)}`:void 0,i=r?.typeName??s??n;if(i==="ZodObject"||i==="ZodIntersection")return"object";if(i==="ZodNumber")return"number";if(i==="ZodBoolean")return"boolean";if(i==="ZodString"){const o=Tsr(e);return Esr(o)?"date":"string"}if(i==="ZodEnum"||i==="ZodNativeEnum")return"select";if(i==="ZodArray")return"array";if(i==="ZodRecord")return"record";if(i==="ZodUnion"){const o=QSe(e);return o&&o.every(c=>{const u=Om(c);return u?Object.values(u).some(d=>{const f=d?.constructor?.name?.slice(1),h=Iu(d);return f==="ZodLiteral"||h?.typeName==="ZodLiteral"||h?.type==="literal"}):!1})?"discriminated-union":"union"}if(i==="ZodDiscriminatedUnion")return"discriminated-union";if(i==="ZodLiteral"){const o=rSt(e);return typeof o=="number"?"number":typeof o=="boolean"?"boolean":"string"}return"string"}function Cpe(e){const t=Iu(e);if(t){if(t.typeName==="ZodEffects"&&t.effect?.type==="refinement"){const n=t.effect?.refinement;if(n){const r=Object.getOwnPropertySymbols(n);for(const s of r){const i=n[s];if(i&&typeof i=="object")return i}}}if("innerType"in t)return Cpe(t.innerType);if("schema"in t)return Cpe(t.schema)}}function Yw(e,t){const n=p5(t),r=Cpe(t);let s=sSt(n,r);const i=hj(t),o=Osr(n);let l=[];o&&(Array.isArray(o)?l=o.map(b=>[b,b]):l=Object.entries(o));let c=[];const u=Om(n);u&&!rQ(n)&&(c=Object.entries(u).map(([b,S])=>Yw(b,S)));const d=QSe(n),f=n?.constructor?.name?.slice(1),h=Iu(n),p=typeof h?.type=="string"?`Zod${h.type.charAt(0).toUpperCase()}${h.type.slice(1)}`:void 0,m=h?.typeName??p??f;(m==="ZodUnion"||m==="ZodDiscriminatedUnion")&&d&&(c=Object.entries(d).map(([b,S])=>Yw(b,S)));const v=rQ(n);if(v){const{left:b,right:S}=v;let k=[],j=[];const C=Om(b);if(C)k=Object.entries(C).map(([_,N])=>Yw(_,N));else{const _=Yw(e,b);k=_.schema??[_],s=_.type}const T=Om(S);if(T)j=Object.entries(T).map(([_,N])=>Yw(_,N));else{const _=Yw(e,S);j=_.schema??[_],s=_.type}c=[...k,...j]}if(m==="ZodArray"){const b=nSt(n);b&&(c=[Yw("0",b)])}const y=m==="ZodLiteral",x=y?Csr(n):void 0;return{key:e,type:s,required:!ksr(t),default:i,description:n.description,fieldConfig:y||Object.keys(r??{})?.length>0?{...r,customData:{...r?.customData??{},...y?{isLiteral:y,literalValues:x}:{}}}:void 0,options:l,schema:c}}function Isr(e){const t=Om(e);return t?{fields:Object.entries(t).map(([r,s])=>Yw(r,s))}:{fields:[]}}function Nsr(e){const t=rQ(e);return t?[t.left,t.right]:QSe(e)}function LBe(e,t){const n={};for(const[r,s]of Object.entries(e)){const i=t(r),o=i?iQ(s,i):s;o!==void 0&&(n[r]=o)}return n}function zBe(e,t){if(!Object.values(t).every(s=>s===""||s===void 0)||e.safeParse(t).success)return!1;const r=e.safeParse(void 0);return r.success&&r.data===void 0}function iQ(e,t){const n=p5(t),r=Nsr(n);if(r){const l=r.reduce((c,u)=>iQ(c,u),e);return oD(l)&&zBe(t,l)?void 0:l}const s=Om(n);if(s&&oD(e)){const l=LBe(e,c=>s[c]);return zBe(t,l)?void 0:l}const i=jsr(n);if(i&&oD(e))return LBe(e,()=>i);if(Array.isArray(e)){const l=nSt(n);return l&&typeof l=="object"?e.map(c=>iQ(c,l)):e}if(!((e===""||e===null&&!t.safeParse(null).success)&&hj(t)===void 0))return e}class Asr{_schema;constructor(t){if(!t)throw new Error("CustomZodProvider: schema is required");this._schema=t}getDefaultValues(){return RB(this._schema)}validateSchema(t){const n=iQ(t,this._schema),s=this._schema.safeParse(n);if(s.success)return{success:!0,data:s.data};const i=s.error;return{success:!1,errors:(i.issues??i.errors??[]).map(l=>({path:l.path,message:l.message}))}}parseSchema(){return Isr(this._schema)}}function joe(e,t){return t?e[GG]:e}function Psr(e,t){return sQ(e)?yr({}):t?yr({[GG]:e.description?e:e.describe("Input")}):e}const iSt=g.createContext(null),$sr=({children:e})=>{const t=g.useContext(iSt);return t?a.jsx(BG,{...t,children:e}):null},Rsr={SubmitButton:$sr};function ZSe({schema:e,onSubmit:t,onValuesChange:n,defaultValues:r,isSubmitLoading:s,submitButtonLabel:i,submitButtonIcon:o,submitButtonVariant:l,submitButtonFullWidth:c,className:u,readOnly:d,children:f,submitActions:h,leftActions:p}){const m=Om(e)===void 0,v=g.useRef(null),y=g.useRef(n);g.useLayoutEffect(()=>{y.current=n},[n]),g.useEffect(()=>()=>v.current?.unsubscribe(),[]);const x=!!n,b=g.useCallback(T=>{v.current?.unsubscribe(),v.current=null,x&&(v.current=T.watch(_=>y.current?.(joe(_,m))),y.current?.(joe(T.getValues(),m)))},[x,m]),S=g.useMemo(()=>e?new Asr(Psr(e,m)):null,[e,m]),k=g.useMemo(()=>t?{isSubmitLoading:s,submitButtonLabel:i,submitButtonIcon:o,submitButtonVariant:l,submitButtonFullWidth:c,submitActions:h,leftActions:p}:null,[t,s,i,o,l,c,h,p]),j=g.useMemo(()=>m?r===void 0?void 0:{[GG]:r}:r,[m,r]),C=g.useCallback(async T=>{await t?.(joe(T,m))},[t,m]);return S?a.jsx(iSt.Provider,{value:k,children:a.jsx(Ssr,{schema:S,onSubmit:C,onFormInit:b,defaultValues:j,formProps:{className:u,noValidate:!0},uiComponents:Rsr,withSubmit:!0,readOnly:d,children:f})}):(console.error("no form schema found"),null)}function WSe(e){try{return{ok:!0,value:JSON.parse(e)}}catch(t){return{ok:!1,error:t instanceof Error?`Invalid JSON: ${t.message}`:"Invalid JSON"}}}function oSt(e,t){const n=sSt(p5(e));if(n==="object"&&!oD(t))return"Form input requires a JSON object. Correct the JSON first.";if(n==="array"&&!Array.isArray(t))return"Form input requires a JSON array. Correct the JSON first."}function aSt(e,t){const n=WSe(t);if(!n.ok)return{ok:!1,errors:[n.error]};const r=e.safeParse(n.value);return r.success?{ok:!0,value:r.data}:{ok:!1,errors:r.error.issues.map(s=>`${s.path.join(".")||"Input"}: ${s.message}`)}}const Msr=a.jsx(At,{children:a.jsx(Bc,{})});function Dsr(e,t){if(!t)return{type:"form",value:e};const n=e??hXn(),r=Mwt(n);return r?{type:"simple",value:r}:{type:"json",value:JSON.stringify(n,null,2)}}const HSe=({schema:e,defaultValues:t,isSubmitLoading:n,submitButtonLabel:r,onSubmit:s,children:i,isProcessorWorkflow:o,submitActions:l,leftActions:c,headingSlot:u,collapsible:d=!0,submitButtonIcon:f=Msr,submitButtonVariant:h="primary",submitButtonFullWidth:p,hideInputTypeLabel:m,inputTypeLabel:v="Run input",hideHeading:y})=>{const[x,b]=g.useState(()=>Dsr(t,o)),S=g.useRef(t),[k,j]=g.useState([]);function C(){return x.type==="json"?WSe(x.value):{ok:!0,value:x.type==="form"?S.current:x.value}}function T(F){const Q=aSt(e,F);Q.ok?s(Q.value):j(Q.errors)}function _(F){if(F===x.type)return;j([]);const Q=C();if(!Q.ok)return j([Q.error]);if(F==="json")return b({type:F,value:JSON.stringify(Q.value===void 0?{}:Q.value,null,2)});if(F==="simple"){const B=Mwt(Q.value);return B?b({type:F,value:B}):j(["Simple input requires a messages array with text parts and a string phase. Correct the JSON first."])}const q=oSt(e,Q.value);return q?j([q]):b({type:F,value:Q.value})}const N=a.jsx(Y,{as:"span",variant:"subheading",tone:"ink",children:"Trigger a run"}),I=!d&&!y,A=d||y||m,P=a.jsx(UXn,{value:x.type,onChange:_,disabled:n,includeSimple:o,compact:I}),D=a.jsxs(a.Fragment,{children:[!m&&a.jsxs("div",{className:"flex justify-between gap-3 px-5 py-3",children:[a.jsx(Y,{as:"p",variant:"caption",tone:"muted",children:v}),I&&a.jsx("div",{className:"shrink-0",children:P})]}),a.jsxs("div",{className:"px-5",children:[A&&a.jsx("div",{className:"pb-4",children:P}),a.jsx("div",{className:Z("pb-4",{"pointer-events-none opacity-50":n}),children:x.type==="json"?a.jsx(gXn,{value:x.value,onChange:F=>{b({type:"json",value:F}),j([])},errors:k,isSubmitLoading:n,submitButtonLabel:r,submitButtonIcon:f,submitButtonVariant:h,submitButtonFullWidth:p,onSubmit:()=>T(x.value),submitActions:l,leftActions:c,children:i}):x.type==="simple"&&o?a.jsx(VXn,{schema:e,value:x.value,onChange:F=>b({type:"simple",value:F}),isSubmitLoading:n,submitButtonLabel:r,submitButtonIcon:f,submitButtonVariant:h,submitButtonFullWidth:p,onSubmit:s,submitActions:l,leftActions:c,children:i}):a.jsx(Lsr,{schema:e,onValuesChange:F=>{S.current=F},defaultValues:x.value,isSubmitLoading:n,submitButtonLabel:r,submitButtonIcon:f,submitButtonVariant:h,submitButtonFullWidth:p,onSubmit:s,submitActions:l,leftActions:c,children:i})})]})]});return d?a.jsxs(Kl,{defaultOpen:!0,children:[a.jsxs(Cl,{className:"flex w-full items-center gap-2 pb-3 text-left",children:[a.jsx(Na,{direction:"right",className:"size-4 text-muted-foreground"}),u??N]}),a.jsx(_l,{keepMounted:!0,children:D})]}):a.jsxs(a.Fragment,{children:[!y&&a.jsx("div",{className:"border-b border-border pb-3",children:u??N}),a.jsx("div",{children:D})]})},Lsr=({schema:e,defaultValues:t,isSubmitLoading:n,submitButtonLabel:r,onSubmit:s,children:i,submitActions:o,leftActions:l,submitButtonIcon:c,submitButtonVariant:u,submitButtonFullWidth:d,onValuesChange:f})=>a.jsx(ZSe,{schema:e,defaultValues:t,onValuesChange:f,isSubmitLoading:n,submitButtonLabel:r,submitButtonIcon:c,submitButtonVariant:u,submitButtonFullWidth:d,onSubmit:s,readOnly:n,submitActions:o,leftActions:l,children:i});function zsr({zodSchema:e,isStreaming:t,onExecute:n,defaultValues:r,isViewingRun:s,isProcessorWorkflow:i,submitActions:o,leftActions:l,headingSlot:c,collapsible:u,submitButtonLabel:d="Run"}){return s?c&&a.jsx("div",{className:"pb-3",children:c}):e?a.jsx(HSe,{schema:e,defaultValues:r,isSubmitLoading:t,submitButtonLabel:d,inputTypeLabel:"Next run input",submitButtonVariant:"primary",submitButtonIcon:a.jsx(At,{children:a.jsx(Bc,{})}),onSubmit:n,isProcessorWorkflow:i,submitActions:o,leftActions:l,headingSlot:c,collapsible:u}):a.jsxs(a.Fragment,{children:[c&&a.jsx("div",{className:"border-b border-border pb-3",children:c}),a.jsxs("div",{className:"flex items-center justify-between gap-1 pt-3",children:[l??a.jsx("div",{}),a.jsxs("div",{className:"flex items-center gap-1",children:[o,a.jsxs(de,{variant:"primary",disabled:t,onClick:()=>n(null),children:[t?a.jsx(At,{children:a.jsx(fc,{className:"animate-spin"})}):a.jsx(At,{children:a.jsx(Bc,{})}),d]})]})]})]})}const Ol=e=>a.jsx("svg",{width:"16",height:"16",viewBox:"0 0 9.08789 8.97168",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:a.jsx("path",{d:"M1.98047 5.00977C2.17347 5.00977 2.33002 5.16639 2.33008 5.35938C2.33008 5.55242 2.17351 5.70898 1.98047 5.70898C1.27292 5.70915 0.699436 6.2827 0.699219 6.99023C0.699219 7.69795 1.27279 8.2723 1.98047 8.27246C2.68829 8.27246 3.2627 7.69805 3.2627 6.99023C3.26291 6.79738 3.4194 6.64063 3.6123 6.64062C3.80503 6.64084 3.9617 6.79751 3.96191 6.99023C3.96191 8.08413 3.07437 8.97168 1.98047 8.97168C0.886706 8.97152 0 8.08403 0 6.99023C0.000217392 5.89662 0.886841 5.00993 1.98047 5.00977ZM7.10742 5.00977C8.20105 5.00992 9.08767 5.89662 9.08789 6.99023C9.08789 8.08404 8.20119 8.97152 7.10742 8.97168C6.01359 8.97159 5.12598 8.08408 5.12598 6.99023C5.1262 6.79757 5.28294 6.64092 5.47559 6.64062C5.66849 6.64063 5.82497 6.79738 5.8252 6.99023C5.8252 7.698 6.39968 8.27238 7.10742 8.27246C7.81511 8.2723 8.38867 7.69796 8.38867 6.99023C8.38845 6.2827 7.81497 5.70914 7.10742 5.70898C6.91445 5.7089 6.75781 5.55236 6.75781 5.35938C6.75788 5.16644 6.91449 5.00985 7.10742 5.00977ZM4.54395 0C5.44471 0 6.17465 0.730134 6.1748 1.63086C6.1748 2.27964 5.79613 2.83941 5.24768 3.102C5.0501 3.1966 4.89355 3.37979 4.89355 3.59885V4.08919C4.89355 4.21279 4.94266 4.33133 5.03006 4.41873L6.80071 6.18938C6.87996 6.26863 6.99535 6.29199 7.10742 6.29199C7.49331 6.29206 7.80642 6.60438 7.80664 6.99023C7.80664 7.37627 7.49344 7.68938 7.10742 7.68945C6.72134 7.68945 6.4082 7.37632 6.4082 6.99023C6.40827 6.87818 6.38483 6.76276 6.3056 6.68353L4.8726 5.25053C4.69056 5.06849 4.39541 5.06853 4.21343 5.25061L2.78139 6.68339C2.70211 6.76271 2.67963 6.87809 2.67969 6.99023C2.67969 7.37632 2.36655 7.68945 1.98047 7.68945C1.59452 7.68929 1.28125 7.37622 1.28125 6.99023C1.28146 6.60443 1.59466 6.29215 1.98047 6.29199C2.09246 6.29199 2.2079 6.26771 2.28711 6.18854L4.05776 4.41874C4.1452 4.33133 4.19434 4.21276 4.19434 4.08912V3.59881C4.19434 3.37977 4.03781 3.19659 3.84026 3.10199C3.29183 2.83937 2.91309 2.2796 2.91309 1.63086C2.91324 0.730162 3.64322 4.61864e-05 4.54395 0Z",fill:"currentColor"})});function Fsr({workflow:e,workflowId:t}){const n=Object.keys(e.steps??{}).length;return a.jsxs("div",{className:"flex w-full items-center gap-2 px-5",children:[a.jsx(At,{className:"shrink-0 text-muted-foreground",children:a.jsx(Ol,{})}),a.jsx(Y,{as:"span",variant:"subheading",tone:"ink",className:"truncate",children:e.name??t}),a.jsx(Zi,{content:e.name??t,variant:"ghost",className:"shrink-0"}),a.jsxs(Mt,{className:"ml-auto shrink-0",children:[n," step",n===1?"":"s"]})]})}const lSt=g.createContext(void 0);function DL(){const e=g.useContext(lSt);if(e===void 0)throw new Error(Ar(53));return e}const Bsr=500,_pe=16;function O1(e,t,n){if(!e)return 0;const r=getComputedStyle(e),s=`${t}${n==="x"?"Inline":"Block"}`,i=parseFloat(r[`${s}Start`]);return n==="x"&&t==="margin"?i*2:i+parseFloat(r[`${s}End`])}const HT=e=>t=>t?{[e]:""}:null,YG={hasOverflowX:HT("data-has-overflow-x"),hasOverflowY:HT("data-has-overflow-y"),overflowXStart:HT("data-overflow-x-start"),overflowXEnd:HT("data-overflow-x-end"),overflowYStart:HT("data-overflow-y-start"),overflowYEnd:HT("data-overflow-y-end"),cornerHidden:()=>null},Vsr={x:0,y:0},FBe={width:0,height:0},Usr={xStart:!1,xEnd:!1,yStart:!1,yEnd:!1},qsr={x:!0,y:!0,corner:!0},Qsr=g.forwardRef(function(t,n){const{render:r,className:s,overflowEdgeThreshold:i,style:o,...l}=t,{xStart:c,xEnd:u,yStart:d,yEnd:f}=Zsr(i),h=Qi(),p=$o(),m=$o(),{nonce:v,disableStyleElements:y}=K1e(),[x,b]=g.useState(!1),[S,k]=g.useState(!1),[j,C]=g.useState(!1),[T,_]=g.useState(!1),[N,I]=g.useState(!1),[A,P]=g.useState(FBe),[D,F]=g.useState(FBe),[Q,q]=g.useState(Usr),[B,V]=g.useState(qsr),H=g.useRef(null),M=g.useRef(null),G=g.useRef(null),L=g.useRef(null),$=g.useRef(null),z=g.useRef(null),U=g.useRef(null),K=g.useRef(null),ne=g.useRef(0),X=g.useRef(0),te=g.useRef(0),ie=g.useRef(0),ue=g.useRef("vertical"),ee=g.useRef(Vsr),se=g.useRef(null);function re(Ce){const _e=Ce?C:k,je=Ce?p:m;_e(!0),je.start(Bsr,()=>{_e(!1)})}const ae=pt(Ce=>{const _e=Ce.x-ee.current.x,je=Ce.y-ee.current.y;ee.current=Ce,je!==0&&re(!0),_e!==0&&re(!1)}),he=pt(()=>{const Ce=M.current;Ce&&se.current===null&&(se.current=Ce.style.scrollSnapType,Ce.style.scrollSnapType="none")}),ve=pt(Ce=>{if(Ce.button!==0||K.current!==null&&(ue.current==="vertical"?$.current:z.current)?.hasPointerCapture(K.current))return;K.current=Ce.pointerId,ne.current=Ce.clientY,X.current=Ce.clientX,ue.current=Ce.currentTarget.getAttribute("data-orientation");const _e=M.current;_e&&(te.current=_e.scrollTop,ie.current=_e.scrollLeft,he()),(ue.current==="vertical"?$.current:z.current)?.setPointerCapture(Ce.pointerId)}),pe=pt(Ce=>{if(Ce.pointerId!==K.current)return;K.current=null,(ue.current==="vertical"?C:k)(!1),se.current!==null&&(M.current&&(M.current.style.scrollSnapType=se.current),se.current=null);const _e=ue.current==="vertical"?$.current:z.current;_e?.hasPointerCapture(Ce.pointerId)&&_e.releasePointerCapture(Ce.pointerId)}),ke=pt(Ce=>{if(Ce.pointerId!==K.current)return;if(Ce.buttons%2===0){pe(Ce);return}const _e=M.current;if(!_e)return;const je=ue.current==="vertical",ce=je?$.current:z.current,ye=je?G.current:L.current;if(!ce||!ye)return;const De=je?"y":"x",Ie=O1(ye,"padding",De),le=O1(ce,"margin",De),xe=je?ce.offsetHeight:ce.offsetWidth,Re=(je?ye.offsetHeight:ye.offsetWidth)-xe-Ie-le,Le=je?Ce.clientY-ne.current:Ce.clientX-X.current,We=Re<=0?0:Le/Re,tt=je?_e.scrollHeight:_e.scrollWidth,st=je?_e.clientHeight:_e.clientWidth,ze=(je?te.current:ie.current)+We*(tt-st);je?_e.scrollTop=ze:_e.scrollLeft=ze,Ce.preventDefault(),re(je)});function Ee(Ce){_(Ce.pointerType==="touch")}function Ue(Ce){if(Ee(Ce),Ce.pointerType!=="touch"){const _e=ln(H.current,Ce.target);b(_e)}}const Qe=g.useMemo(()=>({scrolling:S||j,hasOverflowX:!B.x,hasOverflowY:!B.y,overflowXStart:Q.xStart,overflowXEnd:Q.xEnd,overflowYStart:Q.yStart,overflowYEnd:Q.yEnd,cornerHidden:B.corner}),[S,j,B.x,B.y,B.corner,Q]),Be={role:"presentation",onPointerEnter:Ue,onPointerMove:Ue,onPointerDown:Ee,onPointerLeave(){b(!1)},style:{position:"relative","--scroll-area-corner-height":`${A.height}px`,"--scroll-area-corner-width":`${A.width}px`}},Ae=hn("div",t,{state:Qe,ref:[n,H],props:[Be,l],stateAttributesMapping:YG}),Fe=g.useMemo(()=>({handlePointerDown:ve,handlePointerMove:ke,handlePointerUp:pe,handleScroll:ae,disableViewportSnap:he,cornerSize:A,setCornerSize:P,thumbSize:D,setThumbSize:F,hasMeasuredScrollbar:N,setHasMeasuredScrollbar:I,touchModality:T,cornerRef:U,scrollingX:S,scrollingY:j,hovering:x,setHovering:b,viewportRef:M,scrollbarYRef:G,scrollbarXRef:L,thumbYRef:$,thumbXRef:z,rootId:h,hiddenState:B,setHiddenState:V,overflowEdges:Q,setOverflowEdges:q,viewportState:Qe,overflowEdgeThreshold:{xStart:c,xEnd:u,yStart:d,yEnd:f}}),[ve,ke,pe,ae,he,A,D,N,T,S,j,x,h,B,Q,Qe,c,u,d,f]);return a.jsxs(lSt.Provider,{value:Fe,children:[!y&&c5.getElement(v),Ae]})});function Zsr(e){const t=typeof e=="number"?{xStart:e,xEnd:e,yStart:e,yEnd:e}:e;return{xStart:Math.max(0,t?.xStart||0),xEnd:Math.max(0,t?.xEnd||0),yStart:Math.max(0,t?.yStart||0),yEnd:Math.max(0,t?.yEnd||0)}}const cSt=g.createContext(void 0);function Wsr(){const e=g.useContext(cSt);if(e===void 0)throw new Error(Ar(55));return e}const uSt=["--scroll-area-overflow-x-start","--scroll-area-overflow-x-end","--scroll-area-overflow-y-start","--scroll-area-overflow-y-end"];let BBe=!1;function Hsr(){BBe||kx||(typeof CSS<"u"&&"registerProperty"in CSS&&uSt.forEach(e=>{try{CSS.registerProperty({name:e,syntax:"<length>",inherits:!1,initialValue:"0px"})}catch{}}),BBe=!0)}const Gsr=g.forwardRef(function(t,n){const{render:r,className:s,style:i,...o}=t,{viewportRef:l,scrollbarYRef:c,scrollbarXRef:u,thumbYRef:d,thumbXRef:f,cornerRef:h,cornerSize:p,setCornerSize:m,setThumbSize:v,rootId:y,setHiddenState:x,hiddenState:b,setHasMeasuredScrollbar:S,handleScroll:k,touchModality:j,setHovering:C,setOverflowEdges:T,overflowEdgeThreshold:_,viewportState:N}=DL(),I=Ox(),A=g.useRef(!0),P=g.useRef([NaN,NaN,NaN,NaN]),D=$o(),F=$o(),Q=pt(()=>{const M=l.current,G=c.current,L=u.current,$=d.current,z=f.current,U=h.current;if(!M)return;const K=M.scrollHeight,ne=M.scrollWidth,X=M.clientHeight,te=M.clientWidth,ie=M.scrollTop,ue=M.scrollLeft,ee=P.current,se=Number.isNaN(ee[0]);if(ee[0]=X,ee[1]=K,ee[2]=te,ee[3]=ne,se&&S(!0),K===0||ne===0)return;const re=Ksr(M),ae=re.y,he=re.x,ve=te/ne,pe=X/K,ke=Math.max(0,ne-te),Ee=Math.max(0,K-X);let Ue=0,Qe=0;he||(Ue=fpe(I==="rtl"?-ue:ue,ke),Qe=ke-Ue);const Be=ae?0:fpe(ie,Ee),Ae=ae?0:Ee-Be,Fe=he?0:te,Ce=ae?0:X;let _e=0,je=0;!he&&!ae&&(_e=G?.offsetWidth||0,je=L?.offsetHeight||0);const ce=p.width===0&&p.height===0,ye=ce?_e:0,De=ce?je:0,Ie=O1(L,"padding","x"),le=O1(G,"padding","y"),xe=O1(z,"margin","x"),Se=O1($,"margin","y"),Re=Fe-Ie-xe,Le=Ce-le-Se,We=L?Math.min(L.offsetWidth-ye,Re):Re,tt=G?Math.min(G.offsetHeight-De,Le):Le,st=Math.max(_pe,We*ve),He=Math.max(_pe,tt*pe);if(v(me=>u9(me,{width:st,height:He})),G&&$){const me=G.offsetHeight-He-le-Se,Pe=VBe($,"--scroll-area-thumb-height",ie,Ee,K,He,me);$.style.transform=`translate3d(0,${Pe}px,0)`}if(L&&z){const me=L.offsetWidth-st-Ie-xe,Pe=I==="rtl"?-ue:ue,Xe=VBe(z,"--scroll-area-thumb-width",Pe,ke,ne,st,me);z.style.transform=`translate3d(${I==="rtl"?-Xe:Xe}px,0,0)`}const ze=[Ue,Qe,Be,Ae];uSt.forEach((me,Pe)=>{M.style.setProperty(me,`${ze[Pe]}px`)}),U&&m(me=>u9(me,{width:_e,height:je})),x(me=>u9(me,re));const kt={xStart:!he&&Ue>_.xStart,xEnd:!he&&Qe>_.xEnd,yStart:!ae&&Be>_.yStart,yEnd:!ae&&Ae>_.yEnd};T(me=>u9(me,kt))});It(()=>{Hsr()},[]),It(()=>{queueMicrotask(Q)},[Q,b,I,_.xStart,_.xEnd,_.yStart,_.yEnd]),It(()=>{l.current?.matches(":hover")&&C(!0)},[l,C]),It(()=>{const M=l.current;if(typeof ResizeObserver>"u"||!M)return;let G=!1;const L=new ResizeObserver(()=>{if(!G){G=!0;const $=P.current;if($[0]===M.clientHeight&&$[1]===M.scrollHeight&&$[2]===M.clientWidth&&$[3]===M.scrollWidth)return}Q()});return L.observe(M),F.start(0,()=>{const $=M.getAnimations({subtree:!0});$.length!==0&&Promise.allSettled($.map(z=>z.finished)).then(Q).catch(()=>{})}),()=>{L.disconnect(),F.clear()}},[Q,l,F]);function q(){A.current=!1}const B={role:"presentation",...y&&{"data-id":`${y}-viewport`},tabIndex:b.x&&b.y?-1:0,className:c5.className,style:{overflow:"scroll"},onScroll(){l.current&&(Q(),(j||!A.current)&&k({x:l.current.scrollLeft,y:l.current.scrollTop}),D.start(100,()=>{A.current=!0}))},onWheel:q,onPointerMove:q,onPointerEnter:q,onKeyDown:q},V=hn("div",t,{ref:[n,l],state:N,props:[B,o],stateAttributesMapping:YG}),H=g.useMemo(()=>({computeThumbPosition:Q}),[Q]);return a.jsx(cSt.Provider,{value:H,children:V})});function Ksr(e){const t=e.clientHeight>=e.scrollHeight,n=e.clientWidth>=e.scrollWidth;return{y:t,x:n,corner:t||n}}function u9(e,t){for(const n in t)if(e[n]!==t[n])return t;return e}function VBe(e,t,n,r,s,i,o){const l=Ni(n,0,r),c=n-l,u=Math.max(_pe,i*s/(s+Math.abs(c)));return e.style.setProperty(t,c?`${u}px`:""),(r?l/r*o:0)+(c>0?i-u:0)}const dSt=g.createContext(void 0);function Ysr(){const e=g.useContext(dSt);if(e===void 0)throw new Error(Ar(54));return e}const Xsr=g.forwardRef(function(t,n){const{render:r,className:s,orientation:i="vertical",keepMounted:o=!1,style:l,...c}=t,{hovering:u,scrollingX:d,scrollingY:f,hiddenState:h,scrollbarYRef:p,scrollbarXRef:m,viewportRef:v,thumbYRef:y,thumbXRef:x,handlePointerDown:b,handlePointerUp:S,handleScroll:k,disableViewportSnap:j,rootId:C,thumbSize:T,hasMeasuredScrollbar:_,viewportState:N}=DL(),I=i==="vertical",A={...N,hovering:u,scrolling:I?f:d,orientation:i},P=Ox(),D=!_&&!o,F=I?h.y:h.x,Q=o||!F;g.useEffect(()=>{if(!Q)return;const V=v.current,H=I?p.current:m.current;if(!H)return;function M(G){if(!V||G.ctrlKey)return;const L=!I,$=L?"scrollLeft":"scrollTop",z=L?G.deltaX:G.deltaY;if(z===0)return;const U=L?V.scrollWidth-V.clientWidth:V.scrollHeight-V.clientHeight,K=L&&P==="rtl"?-U:0,ne=L&&P==="rtl"?0:U,X=V[$];X<=K&&z<0||X>=ne&&z>0||(G.preventDefault(),V[$]=Math.min(ne,Math.max(K,X+z)),k({x:V.scrollLeft,y:V.scrollTop}))}return Fr(H,"wheel",M,{passive:!1})},[P,k,I,m,p,Q,v]);const q={...C&&{"data-id":`${C}-scrollbar`},onPointerDown(V){if(V.button!==0)return;const H=Ui(V.nativeEvent),M=I?y.current:x.current;if(M&&ln(M,H))return;const G=v.current;if(!G)return;const L=I?p.current:m.current;if(!M||!L)return;const $=I?"y":"x",z=O1(M,"margin",$),U=O1(L,"padding",$),K=I?M.offsetHeight:M.offsetWidth,ne=L.getBoundingClientRect(),X=I?V.clientY-ne.top-K/2-U+z/2:V.clientX-ne.left-K/2-U+z/2,te=I?G.scrollHeight:G.scrollWidth,ie=I?G.clientHeight:G.clientWidth,ee=(I?L.offsetHeight:L.offsetWidth)-K-U-z;if(ee<=0)return;const se=X/ee,re=te-ie;j(),I?G.scrollTop=se*re:P==="rtl"?G.scrollLeft=-(1-se)*re:G.scrollLeft=se*re,k({x:G.scrollLeft,y:G.scrollTop}),b(V)},onPointerUp:S,onPointerCancel:S,style:{position:"absolute",touchAction:"none",WebkitUserSelect:"none",userSelect:"none",visibility:D?"hidden":void 0,...I?{top:0,bottom:"var(--scroll-area-corner-height)",insetInlineEnd:0,"--scroll-area-thumb-height":`${T.height}px`}:{insetInlineStart:0,insetInlineEnd:"var(--scroll-area-corner-width)",bottom:0,"--scroll-area-thumb-width":`${T.width}px`}}},B=hn("div",t,{ref:[n,I?p:m],state:A,props:[q,c],stateAttributesMapping:YG});return Q?a.jsx(dSt.Provider,{value:i,children:B}):null}),Jsr=g.forwardRef(function(t,n){const{render:r,className:s,style:i,...o}=t,{computeThumbPosition:l}=Wsr(),{hasMeasuredScrollbar:c,viewportState:u}=DL(),d=g.useRef(null),f=g.useRef(c);return It(()=>{if(typeof ResizeObserver>"u")return;let p=!1;const m=new ResizeObserver(()=>{!p&&(p=!0,!f.current)||l()});return d.current&&m.observe(d.current),()=>{m.disconnect()}},[l]),hn("div",t,{ref:[n,d],state:u,stateAttributesMapping:YG,props:[{role:"presentation",style:{minWidth:"fit-content"}},o]})}),eir=g.forwardRef(function(t,n){const{render:r,className:s,style:i,...o}=t,{thumbYRef:l,thumbXRef:c,handlePointerDown:u,handlePointerMove:d,handlePointerUp:f,scrollingX:h,scrollingY:p,hasMeasuredScrollbar:m}=DL(),v=Ysr(),y=v==="vertical";return hn("div",t,{ref:[n,y?l:c],state:{scrolling:y?p:h,orientation:v},props:[{onPointerDown:u,onPointerMove:d,onPointerUp:f,onPointerCancel:f,style:{visibility:m?void 0:"hidden",...y?{height:"var(--scroll-area-thumb-height)"}:{width:"var(--scroll-area-thumb-width)"}}},o]})}),tir=g.forwardRef(function(t,n){const{render:r,className:s,style:i,...o}=t,{cornerRef:l,cornerSize:c,hiddenState:u}=DL(),d=hn("div",t,{ref:[n,l],props:[{style:{position:"absolute",bottom:0,insetInlineEnd:0,width:c.width,height:c.height}},o]});return u.corner?null:d}),nir=8,fSt=(e,{enabled:t=!0})=>{const n=g.useRef(t),r=g.useRef(null),s=g.useRef(!1),i=g.useRef(null);Me.useEffect(()=>{if(!t||!e?.current)return;const o=e.current,l=()=>{n.current&&(r.current!==null&&cancelAnimationFrame(r.current),r.current=requestAnimationFrame(()=>{n.current&&(o.scrollTop=o.scrollHeight),r.current=null}))},c=new MutationObserver(l);c.observe(o,{childList:!0,subtree:!0,characterData:!0});const u=new ResizeObserver(l);u.observe(o);const d=()=>{r.current!==null&&(cancelAnimationFrame(r.current),r.current=null)},f=()=>{n.current=!1,d()},h=()=>{s.current=!0,i.current!==null&&window.clearTimeout(i.current),i.current=window.setTimeout(()=>{s.current=!1,i.current=null},250)},p=y=>{h(),y.deltaY<0&&f()},m=y=>{h(),["ArrowUp","PageUp","Home"].includes(y.key)&&f()},v=y=>{const x=y.target,b=x.scrollTop+x.clientHeight,S=x.scrollHeight;if(b>=S-nir){n.current=!0;return}s.current&&(n.current=!1,d())};return o.addEventListener("wheel",p,{passive:!0}),o.addEventListener("touchmove",h,{passive:!0}),o.addEventListener("pointerdown",h),o.addEventListener("keydown",m),o.addEventListener("scroll",v),l(),()=>{o.removeEventListener("wheel",p),o.removeEventListener("touchmove",h),o.removeEventListener("pointerdown",h),o.removeEventListener("keydown",m),o.removeEventListener("scroll",v),c.disconnect(),u.disconnect(),d(),i.current!==null&&(window.clearTimeout(i.current),i.current=null)}},[t,e])},rir=100,sir=20,iir=1,oir=16,Tpe="2rem",d9="0px",air=["mask-t-from-[calc(100%-min(var(--scroll-area-fade-top),var(--scroll-area-overflow-y-start,0px)))]","mask-b-from-[calc(100%-min(var(--scroll-area-fade-bottom),var(--scroll-area-overflow-y-end,0px)))]","mask-l-from-[calc(100%-min(var(--scroll-area-fade-left),var(--scroll-area-overflow-x-start,0px)))]","mask-r-from-[calc(100%-min(var(--scroll-area-fade-right),var(--scroll-area-overflow-x-end,0px)))]"].join(" "),Vw=e=>e===!0?Tpe:e;function lir(e,t){if(e===!1)return{top:!1,bottom:!1,left:!1,right:!1};const n=(t==="vertical"||t==="both")&&Tpe,r=(t==="horizontal"||t==="both")&&Tpe,s={top:n,bottom:n,left:r,right:r};return e===!0||e===void 0||(e.y!==void 0&&(s.top=Vw(e.y),s.bottom=Vw(e.y)),e.x!==void 0&&(s.left=Vw(e.x),s.right=Vw(e.x)),e.top!==void 0&&(s.top=Vw(e.top)),e.bottom!==void 0&&(s.bottom=Vw(e.bottom)),e.left!==void 0&&(s.left=Vw(e.left)),e.right!==void 0&&(s.right=Vw(e.right))),s}const cir=e=>({"--scroll-area-fade-top":e.top||d9,"--scroll-area-fade-bottom":e.bottom||d9,"--scroll-area-fade-left":e.left||d9,"--scroll-area-fade-right":e.right||d9});function UBe(e,t,n){const r=e??t;return Number.isFinite(r)?Math.max(n,r):Math.max(n,t)}const qBe=({direction:e,label:t,onStartScrolling:n,onStopScrolling:r,onKeyboardScroll:s})=>{const i=e==="left"?cP:Rc;return a.jsx("button",{type:"button","aria-label":t,className:Z("absolute inset-y-1 z-10 hidden w-8 cursor-pointer items-center justify-center rounded-md border-0 bg-transparent hover:bg-fill-subtle active:bg-fill",Fn,jn,Ri,e==="left"?"left-1 group-data-[overflow-x-start]/scroll-area:flex":"right-1 group-data-[overflow-x-end]/scroll-area:flex"),onPointerDown:o=>n(e,o),onPointerUp:r,onPointerLeave:r,onPointerCancel:r,onBlur:r,onClick:o=>{o.detail===0&&s(e)},children:a.jsx(i,{"aria-hidden":"true",className:"size-4"})})},uir=({areaRef:e,scrollButtons:t})=>{const n=g.useRef(null),r=typeof t=="object"?t:void 0,s=UBe(r?.scrollSpeed,rir,iir),i=UBe(r?.scrollIntervalTime,sir,oir),o=r?.leftLabel??"Scroll left",l=r?.rightLabel??"Scroll right",c=g.useCallback(()=>{n.current&&(clearInterval(n.current),n.current=null)},[]),u=g.useCallback((f,h=1)=>{const p=e.current;p&&p.scrollBy({left:f==="right"?s*h:-s*h,behavior:"smooth"})},[e,s]),d=g.useCallback((f,h)=>{h?.preventDefault(),h?.stopPropagation(),h?.currentTarget.setPointerCapture?.(h.pointerId),c(),u(f,2),n.current=setInterval(()=>{u(f)},i)},[i,u,c]);return g.useEffect(()=>()=>{c()},[c]),a.jsxs(a.Fragment,{children:[a.jsx(qBe,{direction:"left",label:o,onStartScrolling:d,onStopScrolling:c,onKeyboardScroll:f=>u(f,2)}),a.jsx(qBe,{direction:"right",label:l,onStartScrolling:d,onStopScrolling:c,onKeyboardScroll:f=>u(f,2)})]})},GSe=g.createContext(null);function dir(){const e=g.use(GSe);if(!e)throw new Error("ScrollAreaViewport must be a direct child of ScrollArea");return e}function af({className:e,children:t,ref:n}){const r=dir(),{areaRef:s}=r,i=g.useMemo(()=>fk(s,n),[s,n]);return a.jsx(Gsr,{ref:i,className:Z(r.className,e),style:r.style,children:a.jsx(Jsr,{style:r.contentStyle,children:a.jsx(GSe,{value:null,children:t})})})}function Nr({className:e,children:t,maxHeight:n,autoScroll:r=!1,orientation:s="vertical",scrollButtons:i,mask:o,revealScrollbarOnHover:l=!0,...c}){const u=g.useRef(null);fSt(u,{enabled:r});const d=lir(o,s),f=Object.values(d).some(Boolean),h=cir(d);n&&(h.maxHeight=n),s==="vertical"?(h.overflowX="hidden",h.overflowY="scroll"):s==="horizontal"&&(h.overflowX="scroll",h.overflowY="hidden");const p=s==="vertical"?{minWidth:"0px"}:s==="horizontal"?{minHeight:"0px"}:void 0,m={areaRef:u,className:Z("size-full",f&&air),style:h,contentStyle:p},v=g.Children.toArray(t).filter(x=>g.isValidElement(x)&&x.type===af).length;if(v>1)throw new Error("ScrollArea takes at most one ScrollAreaViewport");const y=v===1;return a.jsxs(Qsr,{className:Z("group/scroll-area relative overflow-hidden",e),...c,children:[a.jsx(GSe,{value:m,children:y?t:a.jsx(af,{children:t})}),i&&s!=="vertical"&&a.jsx(uir,{areaRef:u,scrollButtons:i}),(s==="vertical"||s==="both")&&a.jsx(QBe,{orientation:"vertical",revealOnHover:l}),(s==="horizontal"||s==="both")&&a.jsx(QBe,{orientation:"horizontal",revealOnHover:l}),s==="both"&&a.jsx(tir,{})]})}function QBe({className:e,orientation:t="vertical",revealOnHover:n=!0,...r}){return a.jsx(Xsr,{"data-slot":"scroll-area-scrollbar",orientation:t,className:Z("flex touch-none transition-opacity duration-normal ease-out-custom select-none","opacity-0 data-[scrolling]:opacity-100 data-[scrolling]:duration-0",n&&"data-[hovering]:opacity-100",t==="vertical"&&"h-full w-1.5 p-px",t==="horizontal"&&"h-1.5 w-full flex-col p-px",e),...r,children:a.jsx(eir,{className:"relative flex-1 rounded-full bg-muted-foreground/30 hover:bg-muted-foreground/60"})})}function xk({initialKey:e,defaultValue:t,schema:n,serialize:r=JSON.stringify}){const[s]=g.useState(e),[i,o]=g.useState(()=>{try{const l=localStorage.getItem(s);if(l!==null){const c=n.safeParse(JSON.parse(l));if(c.success)return c.data}}catch{}return t});return g.useEffect(()=>{try{localStorage.setItem(s,r(i))}catch{}},[s,i,r]),[i,o]}function hSt({workflowId:e,paramsRunId:t,paramsRunStatus:n,workflow:r,isLoading:s,createWorkflowRun:i,streamWorkflow:o,observeWorkflowStream:l,isStreamingWorkflow:c,isCancellingWorkflowRun:u,cancelWorkflowRun:d,requestContext:f,runActionsSlot:h,canExecute:p}){const{result:m,setResult:v,payload:y,setPayload:x,setRunId:b,runId:S,runSnapshot:k,workflowError:j}=g.useContext(Hl),[C,T]=g.useState(!1),_=g.useRef(null),N=g.useRef(null),[I,A]=g.useState(),[P,D]=xk({initialKey:`workflow-run-resource-id:${e}`,defaultValue:"",schema:gt()}),F=t||S,Q=I?.runId===F?I:void 0,q=F?m:null,B=Pgt(q,F),{zodSchemaToUse:V,hasStateSchema:H}=YFn(r),M=eG(q?.status),G=q?.status==="paused";g.useEffect(()=>()=>_.current?.abort(),[]);const L=async ie=>{if(!r||C)return;_.current?.abort();const ue=new AbortController;_.current=ue,T(!0);try{A(void 0),v(null);const ee=P.trim()||void 0,se=await i({workflowId:e,resourceId:ee});if(ue.signal.aborted)return;b(se.runId),T(!1);const{initialState:re,inputData:ae}=ie??{},he=H?ae:ie;await o({workflowId:e,runId:se.runId,inputData:he,initialState:re,requestContext:f,resourceId:ee})}catch(ee){ue.signal.aborted||Ke.error(ee instanceof Error?ee.message:"Error executing workflow")}finally{ue.signal.aborted||T(!1)}},$=async()=>{if(!F)return;const ie=m?.status==="paused"||m?.status==="suspended"?m:void 0;try{const ue=await d({workflowId:e,runId:F});A({...ue,runId:F}),ie&&v({...ie,status:"canceled"})}catch{Ke.error("Error cancelling workflow run")}};if(g.useEffect(()=>{if(!t||!l)return;const ie=`${e}:${t}`;N.current!==ie&&(N.current=ie,l({workflowId:e,runId:t}))},[t,l,e]),s)return a.jsx(Nr,{className:"h-[calc(100vh-126px)] px-4 pt-2 pb-4",children:a.jsxs("div",{className:"space-y-4",children:[a.jsx(xt,{className:"h-10"}),a.jsx(xt,{className:"h-10"})]})});if(!r)return null;const z=B.length>0,U=q?.status==="running"||q?.status==="suspended",K=!!F,ne=q?.status??n??(c?"running":"pending"),X=a.jsx(t8n,{status:q?.status,cancelMessage:Q?.message??null,isCancelling:u,onCancel:$,disabled:!p}),te=K?a.jsx(oXn,{runId:F,status:ne,result:q,timestamp:k?.timestamp,resourceId:gpt(k)}):a.jsx(Fsr,{workflow:r,workflowId:e});return a.jsx("div",{className:"pt-3",children:a.jsxs("div",{children:[z&&c&&a.jsxs("div",{className:"-mt-5 flex items-center gap-2 border-b border-border bg-card px-5 py-2",children:[a.jsx(At,{children:a.jsx(fc,{className:"animate-spin text-foreground"})}),a.jsx(Y,{children:"Resuming workflow"})]}),p&&a.jsx(zsr,{zodSchema:V,defaultValues:y,isStreaming:C||c,onExecute:ie=>{x(ie),L(ie)},isViewingRun:K,isProcessorWorkflow:r?.isProcessorWorkflow,collapsible:!1,headingSlot:te,leftActions:t?void 0:a.jsx(w8n,{}),submitButtonLabel:C?"Starting…":"Run",submitActions:h?.({resourceId:P,setResourceId:D})},`${e}:${F||"new"}`),!p&&a.jsx(Y,{variant:"caption",tone:"muted",className:"px-5 py-2",children:"You don't have permission to execute workflows."}),M&&q&&a.jsx(UYn,{result:q,workflowError:j,className:"mx-5 mb-4"}),G&&p&&a.jsx("div",{className:"px-5 pt-3 pb-4",children:a.jsx(C8n,{requestContext:f,isStreaming:c,disabled:u||!!Q,children:X})}),U&&a.jsx("div",{"data-testid":"workflow-cancel-action",className:"flex justify-end px-5 pt-3 pb-4",children:X}),q&&a.jsx(IYn,{input:y,result:q},F)]})})}const fir=({workflowId:e,runId:t,observeWorkflowStream:n,...r})=>{const{runSnapshot:s,isLoadingRunExecutionResult:i}=g.useContext(Hl),o=g.useCallback(()=>{!t||!s||eG(s.status)||n?.({workflowId:e,runId:t,storedStatus:s.status})},[e,t,s,n]);return i?a.jsxs("div",{className:"space-y-4 p-4",children:[a.jsxs("div",{className:"flex items-start gap-3",children:[a.jsx(xt,{className:"size-5 shrink-0 rounded-full"}),a.jsxs("div",{className:"min-w-0 flex-1 space-y-2",children:[a.jsx(xt,{className:"h-4 w-24"}),a.jsx(xt,{className:"h-3 w-40"})]}),a.jsxs("div",{className:"shrink-0 space-y-2",children:[a.jsx(xt,{className:"ml-auto h-3 w-12"}),a.jsx(xt,{className:"ml-auto h-3 w-16"})]})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx(xt,{className:"h-4 w-24"}),a.jsx(xt,{className:"h-7 w-28 rounded-md"})]}),a.jsxs("div",{className:"space-y-3",children:[a.jsx(xt,{className:"h-9 w-full rounded-md"}),a.jsx(xt,{className:"h-9 w-full rounded-md"}),a.jsx(xt,{className:"h-9 w-3/4 rounded-md"})]})]}):!s||!t?a.jsx("div",{className:"p-4",children:a.jsx(Y,{variant:"body",tone:"ink",className:"text-center",children:"No previous run"})}):a.jsx(hSt,{...r,paramsRunId:t,paramsRunStatus:s.status,workflowId:e,observeWorkflowStream:o},`${e}:${t}`)};function hir({store:e,parentContext:t,isDrawer:n}){const r=e.useState("open"),s=e.useState("disablePointerDismissal"),i=e.useState("modal"),o=e.useState("popupElement"),l=e.useState("floatingRootContext"),[c,u]=g.useState(0),[d,f]=g.useState(0),h=c===0,p=h_(l,{outsidePressEvent(){return e.context.internalBackdropRef.current||e.context.backdropRef.current?"intentional":{mouse:i==="trap-focus"?"sloppy":"intentional",touch:"sloppy"}},outsidePress(m){if(!e.context.outsidePressEnabledRef.current||"button"in m&&m.button!==0)return!1;if("touches"in m){if(m.type==="touchend"){if(m.changedTouches.length!==1||m.touches.length!==0)return!1}else if(m.touches.length!==1)return!1}const v=Ui(m);if(h&&!s){if(i){const y=e.context.internalBackdropRef.current,x=e.context.backdropRef.current;return y||x?y===v||x===v||ln(v,o)&&!v?.hasAttribute("data-base-ui-portal"):!0}return!0}return!1},escapeKey:h});return Y0t(r&&i===!0,o),e.useContextCallback("onNestedDialogOpen",(m,v)=>{u(m),f(v)}),It(()=>(t?.onNestedDialogOpen&&(r?t.onNestedDialogOpen(c+1,d+(n?1:0)):t.onNestedDialogOpen(0,0)),()=>{t?.onNestedDialogOpen&&r&&t.onNestedDialogOpen(0,0)}),[n,r,c,d,t]),Q3(e,{activeTriggerProps:p.reference,inactiveTriggerProps:p.trigger,popupProps:p.floating,nestedOpenDialogCount:c,nestedOpenDrawerCount:d}),null}const pSt=g.createContext(void 0);function pf(e){const t=g.useContext(pSt);if(!e&&t===void 0)throw new Error(Ar(27));return t}const pir={...W3,modal:e=>e.modal,nested:e=>e.nested,nestedOpenDialogCount:e=>e.nestedOpenDialogCount,nestedOpenDrawerCount:e=>e.nestedOpenDrawerCount,disablePointerDismissal:e=>e.disablePointerDismissal,openMethod:e=>e.openMethod,descriptionElementId:e=>e.descriptionElementId,titleElementId:e=>e.titleElementId,viewportElement:e=>e.viewportElement,role:e=>e.role};class mir extends p_{constructor(t,n,r){const s=new m_,i=gir(t,s,n,r);super(i,vir(s),pir)}setOpen=(t,n)=>{if(n.preventUnmountOnClose=()=>{this.set("preventUnmountingOnClose",!0)},!t&&n.trigger==null&&this.state.activeTriggerId!=null&&(n.trigger=this.state.activeTriggerElement??void 0),this.context.onOpenChange?.(t,n),n.isCanceled)return;this.state.floatingRootContext.dispatchOpenChange(t,n);const r={open:t};OH(r,t,n.trigger),this.update(r)}}function gir(e,t,n,r=!1){const s={...Z3(),modal:!0,disablePointerDismissal:!1,viewportElement:null,descriptionElementId:void 0,titleElementId:void 0,openMethod:null,nested:!1,nestedOpenDialogCount:0,nestedOpenDrawerCount:0,role:"dialog",...e};return s.floatingRootContext=jH(t,n,r),s}function vir(e){return{popupRef:g.createRef(),backdropRef:g.createRef(),internalBackdropRef:g.createRef(),outsidePressEnabledRef:{current:!0},triggerElements:e,onOpenChange:void 0,onOpenChangeComplete:void 0}}function KSe(e,t){const{children:n,open:r,defaultOpen:s=!1,onOpenChange:i,onOpenChangeComplete:o,disablePointerDismissal:l=!1,modal:c=!0,actionsRef:u,handle:d,triggerId:f,defaultTriggerId:h=null}=t,p=e==="drawer",m=e==="alert-dialog",v=m?!0:c,y=m||l,x=m?"alertdialog":"dialog",b=pf(!0),S=b!=null,k={modal:v,disablePointerDismissal:y,nested:S,role:x},j=kH((A,P)=>new mir({open:s,openProp:r,activeTriggerId:h,triggerIdProp:f,...k},A,P),!0);j.useControlledProp("openProp",r),j.useControlledProp("triggerIdProp",f),j.useSyncedValues(k),j.useContextCallback("onOpenChange",i),j.useContextCallback("onOpenChangeComplete",o);const C=j.useState("open"),T=j.useState("mounted"),_=j.useState("payload");dft(j,C),U3(j);const{forceUnmount:N}=q3(C,j);g.useImperativeHandle(u,()=>({unmount:N,close:()=>j.setOpen(!1,Yt(L3))}),[N,j]);const I=C||T;return a.jsxs(pSt.Provider,{value:j,children:[d&&a.jsx(B3,{handle:d,store:j}),I&&a.jsx(hir,{store:j,parentContext:b?.context,isDrawer:p}),typeof n=="function"?n({payload:_}):n]})}function yir(e){return KSe("alert-dialog",e)}const xir=g.forwardRef(function(t,n){const{render:r,className:s,style:i,forceRender:o=!1,...l}=t,c=pf(),u=c.useState("open"),d=c.useState("nested"),f=c.useState("mounted"),h=c.useState("transitionStatus");return hn("div",t,{state:{open:u,transitionStatus:h},ref:[c.context.backdropRef,n],stateAttributesMapping:v_,props:[{role:"presentation",hidden:!f,style:{userSelect:"none",WebkitUserSelect:"none"}},l],enabled:o||!d})}),XG=g.forwardRef(function(t,n){const{render:r,className:s,style:i,disabled:o=!1,nativeButton:l=!0,...c}=t,u=pf(),d=u.useState("open"),{getButtonProps:f,buttonRef:h}=hd({disabled:o,native:l}),p={disabled:o};function m(v){d&&u.setOpen(!1,Yt(i0e,v.nativeEvent))}return hn("button",t,{state:p,ref:[n,h],props:[{onClick:m},c,f]})}),mSt=g.forwardRef(function(t,n){const{render:r,className:s,style:i,id:o,...l}=t,c=pf(),u=Qi(o);return c.useSyncedValueWithCleanup("descriptionElementId",u),hn("p",t,{ref:n,props:[{id:u},l]})}),gSt=g.createContext(void 0);function YSe(){const e=g.useContext(gSt);if(e===void 0)throw new Error(Ar(26));return e}const vSt={...g_,...kp,nestedDialogOpen(e){return e?{"data-nested-dialog-open":""}:null}},ySt=g.forwardRef(function(t,n){const{render:r,className:s,style:i,finalFocus:o,initialFocus:l,...c}=t,u=pf(),d=u.useState("descriptionElementId"),f=u.useState("disablePointerDismissal"),h=u.useState("floatingRootContext"),p=u.useState("popupProps"),m=u.useState("modal"),v=u.useState("mounted"),y=u.useState("nested"),x=u.useState("nestedOpenDialogCount"),b=u.useState("open"),S=u.useState("openMethod"),k=u.useState("titleElementId"),j=u.useState("transitionStatus"),C=u.useState("role"),T=h.useState("floatingId");YSe(),Wl({open:b,ref:u.context.popupRef,onComplete(){b&&u.context.onOpenChangeComplete?.(!0)}});const _=l===void 0?lft(u.context.popupRef):l,N=x>0,I=u.useStateSetter("popupElement"),P=hn("div",t,{state:{open:b,nested:y,transitionStatus:j,nestedDialogOpen:N},props:[p,{id:T,"aria-labelledby":k,"aria-describedby":d,role:C,...lk,hidden:!v,onKeyDown(D){gk.has(D.key)&&D.stopPropagation()},style:{"--nested-dialogs":x}},c],ref:[n,u.context.popupRef,I],stateAttributesMapping:vSt});return a.jsx(nP,{context:h,openInteractionType:S,disabled:!v,closeOnFocusOut:!f,initialFocus:_,returnFocus:o,modal:m!==!1,restoreFocus:"popup",children:P})}),xSt=g.forwardRef(function(t,n){const{keepMounted:r=!1,...s}=t,i=pf(),o=i.useState("mounted"),l=i.useState("modal"),c=i.useState("open");return o||r?a.jsx(gSt.Provider,{value:r,children:a.jsxs(F3,{ref:n,...s,children:[o&&l===!0&&a.jsx(TL,{ref:i.context.internalBackdropRef,inert:oP(!c)}),t.children]})}):null}),bSt=g.forwardRef(function(t,n){const{render:r,className:s,style:i,id:o,...l}=t,c=pf(),u=Qi(o);return c.useSyncedValueWithCleanup("titleElementId",u),hn("h2",t,{ref:n,props:[{id:u},l]})}),XSe=g.forwardRef(function(t,n){const{render:r,className:s,style:i,disabled:o=!1,nativeButton:l=!0,id:c,payload:u,handle:d,...f}=t,h=pf(!0),m=H3(d)??h;if(!m)throw new Error(Ar(79));const v=Qi(c),y=m.useState("floatingRootContext"),x=m.useState("isOpenedByTrigger",v),b=m.useState("triggerPopupId",v),S=g.useRef(null),{registerTrigger:k,isMountedByThisTrigger:j}=V3(v,S,m,{payload:u}),{getButtonProps:C,buttonRef:T}=hd({disabled:o,native:l}),_=f_(y),N=tSe(()=>m.select("open"),P=>{m.set("openMethod",P)}),I={disabled:o,open:x},A=m.useState("triggerProps",j);return hn("button",t,{state:I,ref:[T,n,k,S],props:[_.reference,A,N,{[f0e]:"",id:v,"aria-haspopup":"dialog","aria-expanded":x,"aria-controls":b},f,C],stateAttributesMapping:rP})}),bir=XSe,wir=g.forwardRef(function(t,n){const{render:r,className:s,style:i,children:o,...l}=t,c=YSe(),u=pf(),d=u.useState("open"),f=u.useState("nested"),h=u.useState("transitionStatus"),p=u.useState("nestedOpenDialogCount"),m=u.useState("mounted"),v=u.useStateSetter("viewportElement"),y=p>0;return hn("div",t,{enabled:c||m,state:{open:d,nested:f,transitionStatus:h,nestedDialogOpen:y},ref:[n,v],stateAttributesMapping:vSt,props:[{role:"presentation",hidden:!m,style:{pointerEvents:d?void 0:"none"},children:o},l]})});function Sir(e){return KSe("dialog",e)}const JSe=g.createContext({intent:"default",pending:!1});function JG(){return g.useContext(JSe)}const eK={sm:"min-h-control-sm",md:"min-h-control-md",lg:"min-h-control-lg"},tK="h-auto min-w-0 max-w-full whitespace-normal wrap-anywhere max-[22rem]:w-full",wSt=["dialog-popup-motion fixed top-1/2 left-1/2 z-50 flex w-[calc(100%-2rem)] -translate-1/2 flex-col rounded-xl py-3 outline-hidden","[&>form]:flex [&>form]:min-h-0 [&>form]:flex-1 [&>form]:flex-col [&>form]:gap-0",kft].join(" "),SSt={sm:"max-h-[calc(100dvh-4rem)] max-w-sm",md:"max-h-[calc(100dvh-4rem)] max-w-lg",lg:"max-h-[calc(100dvh-4rem)] max-w-2xl",xl:"max-h-[calc(100dvh-4rem)] max-w-4xl",full:"h-[calc(100dvh-2rem)]"};function rs({intent:e="default",pending:t=!1,onOpenChange:n,disablePointerDismissal:r,...s}){return a.jsx(JSe.Provider,{value:{intent:e,pending:t},children:a.jsx(Sir,{...s,disablePointerDismissal:r??e==="destructive",onOpenChange:(i,o)=>{if(!i&&t){o.cancel();return}n?.(i,o)}})})}const kSt=XSe,OSt=xSt;function jSt({className:e,...t}){return a.jsx(xir,{"data-slot":"dialog-overlay",className:Z("dialog-backdrop-motion fixed inset-0 z-50 bg-scrim backdrop-blur-xs",e),...t})}function ss({className:e,children:t,size:n="md",showOverlay:r=!0,showCloseButton:s=!0,overlayClassName:i,initialFocus:o,...l}){const{intent:c,pending:u}=JG(),d=g.useRef(null),f=c==="destructive";return a.jsxs(OSt,{children:[r&&a.jsx(jSt,{className:i}),a.jsxs(ySt,{"data-slot":"dialog-content","data-size":n,"data-intent":c,role:f?"alertdialog":"dialog",initialFocus:o??(f&&s?d:!0),"aria-busy":u||void 0,className:Z(wSt,SSt[n],"[&_[data-slot=dialog-header]]:pr-12",e),...l,children:[t,s&&a.jsx(XG,{ref:d,disabled:u,"data-slot":"dialog-close",className:"absolute top-4 right-4",render:a.jsx(de,{variant:"ghost",size:"icon-sm","aria-label":"Close",children:a.jsx(Dn,{})})})]})]})}function es({className:e,...t}){return a.jsx("div",{"data-slot":"dialog-header",className:Z("flex min-w-0 shrink-0 flex-col gap-1 px-5 py-2",e),...t})}function Yo({className:e,...t}){return a.jsx("div",{"data-slot":"dialog-footer",className:Z("flex shrink-0 flex-wrap items-center justify-end gap-2 px-5 py-2",e),...t})}function Hr({className:e,layout:t="scroll",flush:n=!1,children:r,...s}){const i=Z("flex min-w-0 flex-col gap-4 text-body wrap-break-word text-muted-foreground",!n&&"px-5 py-2",e);return t==="fill"?a.jsx("div",{"data-slot":"dialog-body",className:Z("min-h-0 flex-1",i),...s,children:r}):a.jsx(Nr,{className:"flex min-h-0 min-w-0 flex-1 flex-col",mask:!0,children:a.jsx(af,{className:"h-auto min-h-0",children:a.jsx("div",{"data-slot":"dialog-body",className:i,...s,children:r})})})}function Gr({className:e,...t}){return a.jsx(bSt,{className:Z("text-heading wrap-break-word text-foreground",e),...t})}function zo({className:e,...t}){return a.jsx(mSt,{className:Z("text-body wrap-break-word text-muted-foreground",e),...t})}function Ca({disabled:e,size:t="md",...n}){const{pending:r}=JG();return a.jsx(XG,{render:a.jsx(de,{size:t,variant:"ghost",className:Z(tK,eK[t]),children:n.children}),...n,disabled:e||r})}const kir={intent:"default",pending:!1};function Ut(e){return a.jsx(JSe.Provider,{value:kir,children:a.jsx(yir,{...e})})}function Oir({className:e,size:t="sm",...n}){return a.jsxs(OSt,{children:[a.jsx(jSt,{}),a.jsx(ySt,{"data-slot":"alert-dialog-content","data-size":t,className:Z(wSt,SSt[t],e),...n})]})}function jir({children:e,...t}){return a.jsx(XG,{render:a.jsx(de,{variant:"primary",size:"md",className:Z(tK,eK.md),children:e}),...t})}Ut.Trigger=bir;Ut.Content=Oir;Ut.Header=es;Ut.Footer=Yo;Ut.Body=Hr;Ut.Title=Gr;Ut.Description=zo;Ut.Action=jir;Ut.Cancel=Ca;const CSt=({children:e,"aria-label":t="Threads",embedded:n=!1})=>a.jsx("div",{className:Z("size-full",!n&&"pb-2 pl-2"),children:a.jsx("nav",{"aria-label":t,className:Z("flex h-full flex-col gap-1 overflow-y-auto p-1",!n&&Z(pr,"rounded-studio-panel")),children:e})}),Cir=({render:e,children:t})=>a.jsx(de,{render:e,variant:"ghost",className:"w-full justify-start rounded-xl px-3",children:t}),_ir=()=>a.jsx("div",{role:"separator","aria-orientation":"horizontal",className:"-mx-1 h-px shrink-0 bg-border/40"}),Epe=({children:e})=>a.jsx("ol",{className:"flex flex-col gap-1","data-testid":"thread-list",children:e}),Ipe=({as:e,href:t,to:n,isActive:r,onClick:s,onDelete:i,deleteLabel:o="delete",actions:l,className:c,children:u})=>a.jsxs("li",{className:"group relative",children:[a.jsx(de,{render:e?g.createElement(e,{href:t,to:n}):void 0,onClick:s,variant:"ghost",className:Z("w-full min-w-0 justify-start rounded-xl px-3 text-left",(i||l)&&"pr-9",r&&"bg-fill-hover text-foreground",c),children:a.jsx("span",{className:"min-w-0 flex-1",children:u})}),i&&a.jsx(de,{variant:"ghost",size:"icon-sm",className:"absolute top-1/2 right-1 -translate-y-1/2 opacity-0 transition-opacity group-focus-within:opacity-100 group-hover:opacity-100",onClick:i,"aria-label":o,children:a.jsx(Dn,{})}),l&&a.jsx("div",{className:"absolute top-1/2 right-px flex -translate-y-1/2 items-center opacity-0 transition-opacity group-focus-within:opacity-100 group-hover:opacity-100 has-data-popup-open:opacity-100",children:l})]}),_St=({children:e})=>a.jsx(Y,{as:"p",variant:"caption",tone:"muted",className:"px-3 py-2",children:e}),Tir=yr({status:ng(["running","failed","canceled","pending","waiting","paused","suspended","success"]),timestamp:sc().optional()}),Eir=yr({output:C4()});function Iir(e){const t=Tir.safeParse(e);return t.success?t.data:void 0}function Nir(e){if(e==null)return null;const t=_n().safeParse(e);if(t.success)return t.data;const n=Eir.safeParse(e),r=n.success?n.data.output:e;try{return JSON.stringify(r)}catch{return null}}function Air({timestamp:e,resourceId:t}){return e===void 0&&!t?null:a.jsxs(Y,{as:"span",variant:"meta",tone:"muted",className:"flex w-full min-w-0 items-center gap-1.5",children:[e!==void 0&&a.jsx("time",{className:"shrink-0",dateTime:new Date(e).toISOString(),children:os(e,"date-time")}),t&&a.jsx("span",{className:"min-w-0 truncate",title:`Resource ${t}`,children:e===void 0?t:`· ${t}`})]})}const Pir=({workflowId:e,runId:t,canDelete:n})=>{const[r,s]=g.useState(!0),[i,o]=g.useState(null),{Link:l,paths:c,navigate:u}=xn(),{isLoading:d,error:f,data:h,setEndOfListElement:p,isFetchingNextPage:m,hasNextPage:v}=CMn({workflowId:e,summary:!0}),{data:y}=hpt({workflowId:e,runId:t??"",queryOptions:{enabled:!!(e&&t)}}),x=Nir(y?.payload),{mutateAsync:b}=_Mn({workflowId:e}),S=async j=>{try{await b({runId:j}),Ke.success("Workflow run deleted successfully"),o(null),u(c.workflowLink(e))}catch{Ke.error("Failed to delete workflow run"),o(null)}},k=h||[];return a.jsxs(a.Fragment,{children:[a.jsxs(Kl,{open:r,onOpenChange:s,className:"flex min-h-0 flex-col",children:[a.jsxs(Cl,{className:"flex shrink-0 items-center gap-2 px-4 py-3 text-left text-caption text-muted-foreground",children:[a.jsx(Na,{direction:"right",className:"size-4 text-muted-foreground"}),a.jsx("span",{children:"Recent runs"}),!d&&!f&&a.jsxs(Y,{as:"span",variant:"meta",tone:"muted",children:[k.length,v?"+":""]})]}),a.jsx(_l,{keepMounted:!0,fill:!0,className:"flex min-h-0 flex-col",children:a.jsx(Nr,{className:"min-h-0 w-full flex-1",mask:{top:!1},children:d?a.jsx("div",{className:"p-4",children:a.jsx(xt,{className:"h-32"})}):a.jsx(CSt,{"aria-label":"Workflow runs",embedded:!0,children:k.length===0?a.jsx(_St,{children:f?"Unable to load workflow runs.":"Your run history will appear here once you run the workflow"}):a.jsxs(Epe,{children:[k.map(j=>{const C=j.runId===t,T=Iir(j.snapshot),_=C?x:null;return a.jsx(Ipe,{as:l,to:c.workflowRunLink(e,j.runId),isActive:C,onDelete:n?()=>o(j.runId):void 0,deleteLabel:"delete run",className:"h-auto min-h-0 items-stretch py-1",children:a.jsxs("span",{className:"flex w-full min-w-0 items-center gap-2.5 px-1 text-left",children:[T&&a.jsx("span",{className:"shrink-0",children:a.jsx(Pwt,{status:T.status})}),a.jsxs("span",{className:"flex min-w-0 flex-1 flex-col items-start gap-0.5",children:[a.jsx("span",{className:"flex w-full min-w-0 items-center gap-2",children:a.jsx(Y,{as:"span",variant:"column",tone:"ink",className:"min-w-0 flex-1 truncate",title:j.runId,children:j.runId})}),a.jsx(Air,{timestamp:Tfe(T?.timestamp),resourceId:gpt(j)}),_&&a.jsx(Y,{as:"span",variant:"caption",tone:"muted",className:"block w-full min-w-0 truncate",children:_})]})]})},`run-${j.runId}`)}),m&&a.jsx("li",{className:"flex items-center justify-center py-2",children:a.jsx(At,{children:a.jsx(En,{})})}),a.jsx("li",{children:a.jsx("div",{ref:p})})]})})})})]}),a.jsx($ir,{open:!!i,onOpenChange:()=>o(null),onDelete:()=>{i&&S(i)}})]})},$ir=({open:e,onOpenChange:t,onDelete:n})=>a.jsx(Ut,{open:e,onOpenChange:t,children:a.jsxs(Ut.Content,{children:[a.jsxs(Ut.Header,{children:[a.jsx(Ut.Title,{children:"Are you absolutely sure?"}),a.jsx(Ut.Description,{children:"This action cannot be undone. This will permanently delete the workflow run and remove it from our servers."})]}),a.jsxs(Ut.Footer,{children:[a.jsx(Ut.Cancel,{children:"Cancel"}),a.jsx(Ut.Action,{onClick:n,children:"Continue"})]})]})}),TSt=g.createContext(0);function f9(e,t=!1){return{maxZoom:1,padding:t?"20px":{left:`${e+40}px`,right:"40px",top:"40px",bottom:"64px"}}}const Rir=pd("pointer-events-none block 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-foreground/30 to-transparent opacity-0",pill:"h-10 w-0.5 rounded-full bg-foreground/30"}},defaultVariants:{variant:"line"}}),eke=({variant:e,className:t})=>a.jsx("span",{"aria-hidden":!0,className:Z(Rir({variant:e}),t)}),TP=(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),i=()=>r(s.matches);return i(),s.addEventListener("change",i),()=>s.removeEventListener("change",i)},[t]),n},tke=380,Mir="workflow-canvas-left-panel-width",Dir=8,ZBe=16,nke=`${pr} rounded-studio-panel`,ESt=g.createContext(void 0);function Coe(e,t){return Math.max(tke,Math.min(e,t))}function Lir(){const e=g.useContext(ESt);if(!e)return null;const t=s=>{s.button===0&&(s.preventDefault(),s.currentTarget.setPointerCapture(s.pointerId))},n=s=>{s.currentTarget.hasPointerCapture(s.pointerId)&&e.resizeTo(s.clientX)},r=s=>{s.key!=="ArrowLeft"&&s.key!=="ArrowRight"||(s.preventDefault(),e.resizeBy(s.key==="ArrowRight"?ZBe:-ZBe))};return a.jsx("div",{role:"separator","aria-orientation":"vertical","aria-label":"Resize panel","aria-valuenow":e.width,"aria-valuemin":tke,tabIndex:0,className:"group/resize pointer-events-auto absolute inset-y-0 left-full flex w-2 cursor-col-resize touch-none items-center justify-center outline-hidden",onPointerDown:t,onPointerMove:n,onKeyDown:r,children:a.jsx(eke,{className:"group-hover/resize:opacity-100 group-focus-visible/resize:via-border-focus group-focus-visible/resize:opacity-100 group-active/resize:via-foreground/45 group-active/resize:opacity-100"})})}const zir=({children:e,leftSlot:t})=>{const n=TP(),r=g.useRef(null),[s,i]=xk({initialKey:Mir,defaultValue:tke,schema:ps()}),[o,l]=g.useState(Number.POSITIVE_INFINITY);if(g.useLayoutEffect(()=>{const p=r.current;if(!p)return;const m=()=>l(Math.floor(p.getBoundingClientRect().width/2));m();const v=new ResizeObserver(m);return v.observe(p),()=>v.disconnect()},[n]),n)return a.jsxs("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden",children:[a.jsx("div",{className:"relative min-h-45 min-w-0 flex-1 overflow-hidden",children:e}),t&&a.jsx("div",{className:"min-h-0 min-w-0 basis-[44%] overflow-hidden bg-background",children:t})]});const c=Coe(s,o),u=p=>{const m=r.current;m&&i(Coe(p-m.getBoundingClientRect().left,o))},d=p=>i(Coe(c+p,o)),f=t?c-Dir:0,h={"--workflow-left-panel-width":`${f}px`};return a.jsxs("div",{className:"relative min-h-0 min-w-0 flex-1 overflow-hidden",style:h,children:[a.jsx(TSt,{value:f,children:a.jsx("div",{ref:r,className:"absolute inset-0 min-h-0 min-w-0 overflow-hidden",children:e})}),t&&a.jsx(ESt,{value:{width:c,resizeTo:u,resizeBy:d},children:a.jsx("div",{className:"pointer-events-none absolute inset-y-0 left-0 z-10 min-w-0",style:{width:c},children:t})})]})},ISt=Z(nke,"pointer-events-auto");function NSt({className:e,children:t}){return a.jsxs("div",{className:Z("relative flex min-h-0 min-w-0 flex-col",e),children:[t,a.jsx(Lir,{})]})}function Fir({workflowId:e,onClick:t}){const{Link:n,paths:r}=xn();return a.jsx(de,{render:a.jsx(n,{href:`${r.workflowLink(e)}/graph`}),variant:"ghost",size:"icon-md",tooltip:"New workflow run",onClick:t,children:a.jsx(ys,{})})}function Bir({children:e,workflowId:t,showNewRunButton:n,onNewRun:r}){const{result:s}=g.useContext(Hl),[i,o]=g.useState(!0);return a.jsx(NSt,{className:"max-h-[75%] flex-initial",children:a.jsxs(Kl,{render:a.jsx("section",{}),open:i,onOpenChange:o,"data-testid":"workflow-information-top-section",className:Z(ISt,"flex min-h-0 min-w-0 flex-col overflow-hidden"),children:[a.jsxs("div",{className:"flex shrink-0 items-center gap-1 pr-2",children:[a.jsxs(Cl,{className:"flex min-w-0 flex-1 items-center gap-2 px-4 py-3 text-column text-muted-foreground",children:[a.jsx(Na,{direction:"right",className:"size-4 text-muted-foreground"}),a.jsx("span",{children:"Workflow run"}),!i&&s?.status&&a.jsx(Rwt,{status:s.status})]}),n&&a.jsx(Fir,{workflowId:t,onClick:()=>{o(!0),r()}})]}),a.jsx(_l,{keepMounted:!0,fill:!0,className:"flex min-h-0 flex-col",children:a.jsx(Nr,{"data-testid":"workflow-information-top-scroll-area",className:"min-h-0 flex-1 border-t border-border",mask:{top:!1,bottom:!1},children:a.jsx(af,{className:"h-full",children:e})})})]})})}function Vir(e){return a.jsx(hSt,{...e})}function Uir({runId:e,observeWorkflowStream:t,...n}){return a.jsx(fir,{...n,runId:e,observeWorkflowStream:t})}function qir({workflowId:e,activeRunId:t,canDelete:n}){return a.jsx(NSt,{className:"mt-auto max-h-[min(35%,280px)] shrink-0",children:a.jsx("section",{className:Z(ISt,"flex min-h-0 min-w-0 flex-col overflow-hidden"),children:a.jsx(Pir,{workflowId:e,runId:t,canDelete:n})})})}function Qir({workflowId:e,initialRunId:t,requestContext:n,runActionsSlot:r,canExecute:s,canDelete:i}){const{data:o,isLoading:l,error:c}=lL({workflowId:e,requestContext:n,queryOptions:{enabled:!!e}}),{createWorkflowRun:u,streamWorkflow:d,isStreamingWorkflow:f,observeWorkflowStream:h,resumeWorkflow:p,cancelWorkflowRun:m,isCancellingWorkflowRun:v,clearData:y,runId:x}=g.useContext(Hl),{setSelectedStepId:b}=JH(),S=t||x,k={workflowId:e,workflow:o??void 0,isLoading:l,createWorkflowRun:u,streamWorkflow:d,resumeWorkflow:p,isStreamingWorkflow:f,isCancellingWorkflowRun:v,cancelWorkflowRun:m,requestContext:n,runActionsSlot:r,canExecute:s};if(g.useEffect(()=>{if(c){const C=c instanceof Error?c.message:"Failed to load workflow";Ke.error(`Error loading workflow: ${C}`)}},[c]),c)return null;if(!e)return a.jsx("div",{"data-testid":"workflow-information-panel",className:"workflow-information-panel pointer-events-none flex size-full min-h-0 flex-col gap-2 p-2"});const j=()=>{y(),b(null)};return a.jsxs("div",{"data-testid":"workflow-information-panel",className:"workflow-information-panel pointer-events-none flex size-full min-h-0 flex-col gap-2 p-2",children:[a.jsx(Bir,{workflowId:e,showNewRunButton:!!S,onNewRun:j,children:t?a.jsx(Uir,{...k,runId:t,observeWorkflowStream:h}):a.jsx(Vir,{...k})}),a.jsx(qir,{workflowId:e,activeRunId:S,canDelete:i})]})}function rke(e,t){return dpt(`mastra-tracing-options:${e}:${t}`)}const WBe={runId:"",payload:null,override:null};function Zir(e){const[t,n]=g.useState(WBe),r=e??t.runId,s=t.override?.runId===r?t.override.result:null,i=g.useCallback(d=>n(f=>({...f,runId:d})),[]),o=g.useCallback(d=>n(f=>({...f,payload:d})),[]),l=g.useCallback(d=>n(f=>({...f,override:d&&{runId:e??f.runId,result:d}})),[e]),c=g.useCallback(d=>n(f=>f.override?.runId===d?{...f,override:null}:f),[]),u=g.useCallback(()=>n(WBe),[]);return{runId:r,payload:t.payload,override:s,setRunId:i,setPayload:o,setResult:l,dropOverride:c,reset:u}}const Wir=5e3,Hir=e=>eG(e.state.data?.status)?!1:Wir;function Gir(e){return{...e,timestamp:Tfe(e.updatedAt)??Tfe(e.createdAt)}}function Kir(e,t,{poll:n}){const{data:r,isLoading:s}=hpt({workflowId:e,runId:t,queryOptions:{enabled:!!(e&&t),refetchInterval:n?Hir:void 0}});return{persistedRun:g.useMemo(()=>r&&Gir(r),[r]),isLoading:s}}function Yir({runId:e,debugMode:t,tracingOptions:n}){const[r,s]=g.useState(),{streamWorkflow:i,streamResult:o,isStreaming:l,observeWorkflowStream:c,closeStreamsAndReset:u,resumeWorkflowStream:d,timeTravelWorkflowStream:f}=mxn({debugMode:t,tracingOptions:n,onError:b=>Ke.error(b.message)}),h=r?.runId===e,p=h&&o?o:null,m=h&&l,v=h&&r?.mode==="observe",y=g.useCallback((b,S="execute")=>s({runId:b,mode:S}),[]),x=g.useCallback(()=>{u(),s(void 0)},[u]);return{result:p,isOpen:m,isObserving:v,select:y,close:x,streamWorkflow:i.mutateAsync,resumeWorkflowStream:d.mutateAsync,observeWorkflowStream:c.mutate,timeTravelWorkflowStream:f.mutateAsync}}const ske=g.createContext(null);function bk(){const e=g.useContext(ske);if(!e)throw new Error("useWorkflowStepDetail must be used within WorkflowStepDetailProvider");return e}const Xir={};function Jir({children:e,snapshot:t,workflowId:n,initialRunId:r,withoutTimeTravel:s=!1,requestContext:i=Xir,tracingOptions:o}){const l=g.useContext(ske)?.resetStepDetail,[c,u]=g.useState(!1),{data:d,isLoading:f,error:h}=lL({workflowId:n,requestContext:i,queryOptions:{enabled:!!n}}),p=mr(),m=gxn(),v=vxn(),{runId:y,payload:x,override:b,setRunId:S,setPayload:k,setResult:j,dropOverride:C,reset:T}=Zir(r),{result:_,isOpen:N,isObserving:I,select:A,close:P,streamWorkflow:D,resumeWorkflowStream:F,observeWorkflowStream:Q,timeTravelWorkflowStream:q}=Yir({runId:y,debugMode:c,tracingOptions:o}),B=b??_,V=!r&&eG(B?.status),H=r||(V?y:""),{persistedRun:M,isLoading:G}=Kir(n,H,{poll:!N}),L=M??t,$=g.useMemo(()=>L?BMn(L):null,[L]),z=g.useMemo(()=>UMn(B,$),[B,$]),U=r?L:void 0,K=I&&ZMn(z?.status),ne=N&&!K,X=g.useMemo(()=>U?QMn(U,$?.input):x,[U,$,x]),te=g.useCallback(pe=>{l?.(),S(pe)},[l,S]),ie=g.useCallback(()=>{l?.(),P(),T()},[l,P,T]);g.useEffect(()=>ie,[n,r,ie]);const ue=g.useCallback((pe,ke)=>{A(pe,ke),C(pe)},[A,C]),ee=g.useCallback((pe,ke)=>p.invalidateQueries({queryKey:fpt(pe,ke),exact:!0}),[p]),se=g.useCallback(async pe=>{ue(pe.runId),await D(pe)},[ue,D]),re=g.useCallback(async pe=>{ue(pe.runId);try{await F(pe)}finally{await ee(pe.workflowId,pe.runId)}},[ee,ue,F]),ae=g.useCallback(pe=>{if(pe.storedStatus==="suspended"){P();return}ue(pe.runId,"observe"),Q({workflowId:pe.workflowId,runId:pe.runId,storeRunResult:null})},[P,ue,Q]),he=g.useCallback(async pe=>{ue(pe.runId);try{await q(pe)}finally{await ee(pe.workflowId,pe.runId)}},[ee,ue,q]),ve=g.useMemo(()=>({workflowId:n,workflow:d??void 0,workflowError:h??null,isLoading:f,runId:y,setRunId:te,result:z,setResult:j,streamResult:_,payload:X,setPayload:k,clearData:ie,snapshot:t,runSnapshot:U,isLoadingRunExecutionResult:G,isStreamingWorkflow:ne,isCancellingWorkflowRun:v.isPending,createWorkflowRun:m.mutateAsync,streamWorkflow:se,resumeWorkflow:re,observeWorkflowStream:ae,timeTravelWorkflowStream:he,cancelWorkflowRun:v.mutateAsync,closeStreamsAndReset:P,withoutTimeTravel:s,debugMode:c,setDebugMode:u}),[n,d,h,f,y,te,z,j,_,X,k,ie,t,U,G,ne,v.isPending,m.mutateAsync,se,re,ae,he,v.mutateAsync,P,s,c]);return a.jsx(Hl.Provider,{value:ve,children:e})}function ike(e){return a.jsx(Jir,{...e,requestContext:xr("workflow",e.workflowId)[0],tracingOptions:rke("workflow",e.workflowId)[0]})}function ASt({children:e}){const[t,n]=g.useState(null),[r,s]=g.useState(null),i=g.useMemo(()=>({selectedStepId:t,hoverStepId:r,setSelectedStepId:n,setHoverStepId:s}),[t,r]);return a.jsx(ppt.Provider,{value:i,children:e})}function PSt({children:e}){const[t,n]=g.useState(null),r=g.useRef(void 0),s=g.useCallback(({stepName:d,stepId:f,mapConfig:h})=>{r.current=void 0,n({type:"map-config",stepName:d,stepId:f,mapConfig:h})},[]),i=g.useCallback(({label:d,stepGraph:f,fullStep:h})=>{r.current=void 0,n({type:"nested-graph",stepName:d,nestedGraph:{label:d,stepGraph:f,fullStep:h}})},[]),o=g.useCallback(()=>{r.current=void 0,n(null)},[]),l=g.useCallback(()=>{const d=r.current;o(),d?.isConnected&&d.focus({preventScroll:!0})},[o]),c=g.useCallback((d,f)=>{r.current=f,n({type:"data",selection:d})},[]),u=g.useMemo(()=>({stepDetail:t,showMapConfig:s,showNestedGraph:i,showData:c,closeStepDetail:l,resetStepDetail:o}),[t,s,i,c,l,o]);return a.jsx(ske.Provider,{value:u,children:e})}const eor=e=>a.jsx("svg",{width:"17",height:"16",viewBox:"0 0 17 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:a.jsx("path",{d:"M5.25684 12.6387L10.4003 3.36133H11.7432L6.5997 12.6387H5.25684Z",fill:"currentColor"})}),oke=({children:e,label:t,className:n,listClassName:r})=>a.jsx("nav",{"aria-label":t,className:n,children:a.jsx("ol",{className:Z("flex items-center gap-0.5",r),children:e})}),Nx=e=>a.jsx(xt,{className:"h-3 w-24",...e}),m5=({className:e,as:t,isCurrent:n,action:r,switcher:s,icon:i,isLoading:o,children:l,...c})=>{const u=t||"span",d=!!(n&&s);return a.jsxs(a.Fragment,{children:[a.jsxs("li",{className:Z("group flex h-control-sm min-w-0 items-center",n?"shrink":"shrink-0",d&&"relative rounded-full has-[[data-slot=crumb-switcher]_[data-popup-open]]:bg-fill-subtle has-[[data-slot=crumb-switcher]_button:enabled]:hover:bg-fill-subtle has-[[data-slot=crumb-switcher]_button:enabled]:active:bg-fill"),children:[a.jsxs(u,{"aria-current":n?"page":void 0,className:Z("inline-flex min-w-0 items-center gap-2 overflow-hidden rounded-full px-[.9em]",sv.sm,jn,n?"max-w-xs cursor-default text-foreground":Z(Fn,"max-w-48 cursor-pointer hover:bg-fill-subtle active:bg-fill"),e),...c,children:[i&&a.jsx(At,{className:Z("-ml-[.3em] shrink-0 opacity-50 group-hover:opacity-100","transition-opacity duration-normal ease-out-custom"),children:i}),o?a.jsx(Nx,{}):a.jsx("span",{className:"min-w-0 flex-1 truncate",children:l})]}),s&&a.jsx("span",{"data-slot":"crumb-switcher",className:Z("-ml-1 flex h-control-sm shrink-0 items-center",d&&"[&_button]:bg-transparent! [&_button:enabled]:after:absolute [&_button:enabled]:after:inset-0 [&_button:enabled]:after:rounded-full"),children:s}),r&&a.jsx("span",{className:"-ml-1 flex h-control-sm shrink-0 items-center",children:r})]}),!n&&a.jsx("li",{role:"separator",className:"flex h-full items-center",children:a.jsx(At,{className:"text-placeholder",children:a.jsx(eor,{})})})]})},EP={variant:"ghost",size:"icon-sm",align:"end"};function tor(e,t,n,r,s,i,o,l,c,u=2){const d=VSn(n.current,{event:e,orientation:r,loopFocus:s,rtl:i,cols:u,disabledIndices:o,minIndex:l,maxIndex:c,prevIndex:t>c?l:t,stopEvent:!0});return L1(n.current,d)?void 0:d}const $St=g.createContext(void 0),RSt=g.createContext(void 0),MSt=g.createContext(void 0),DSt=g.createContext(!1),LSt=g.createContext("");function og(){const e=g.useContext($St);if(!e)throw new Error(Ar(22));return e}function nK(){const e=g.useContext(RSt);if(!e)throw new Error(Ar(23));return e}function LL(){const e=g.useContext(MSt);if(!e)throw new Error(Ar(24));return e}function zSt(){return g.useContext(LSt)}function nor(){return g.useContext(DSt)}const dn={id:e=>e.id,labelId:e=>e.labelId,items:e=>e.items,selectedValue:e=>e.selectedValue,hasSelectedValue:e=>{const{selectedValue:t,selectionMode:n}=e;return t==null?!1:n==="multiple"&&Array.isArray(t)?t.length>0:!0},hasNullItemLabel:(e,t)=>t?Vwt(e.items):!1,open:e=>e.open,mounted:e=>e.mounted,forceMounted:e=>e.forceMounted,inline:e=>e.inline,activeIndex:e=>e.activeIndex,selectedIndex:e=>e.selectedIndex,isActive:(e,t)=>e.activeIndex===t,isSelected:(e,t)=>{const n=e.isItemEqualToValue,r=e.selectedValue;return Array.isArray(r)?r.some(s=>Vm(t,s,n)):Vm(t,r,n)},transitionStatus:e=>e.transitionStatus,popupProps:e=>e.popupProps,listProps:e=>e.listProps,inputProps:e=>e.inputProps,triggerProps:e=>e.triggerProps,itemProps:e=>e.itemProps,positionerElement:e=>e.positionerElement,listElement:e=>e.listElement,popupId:e=>e.popupId,triggerElement:e=>e.triggerElement,inputElement:e=>e.inputElement,inputGroupElement:e=>e.inputGroupElement,popupSide:e=>e.popupSide,openMethod:e=>e.openMethod,inputInsidePopup:e=>e.inputInsidePopup,inputOwnsFormValue:e=>e.inputOwnsFormValue,selectionMode:e=>e.selectionMode,name:e=>e.name,form:e=>e.form,disabled:e=>e.disabled,readOnly:e=>e.readOnly,required:e=>e.required,grid:e=>e.grid,virtualized:e=>e.virtualized,itemToStringLabel:e=>e.itemToStringLabel,isItemEqualToValue:e=>e.isItemEqualToValue,modal:e=>e.modal,autoHighlight:e=>e.autoHighlight};function FSt(e){return e==null?void 0:`${e}-popup`}function ror(e,t){return(n,r)=>n==null?!1:e.contains(n,r,t)}function ake(e){return Array.isArray(e)?e.map(t=>ake(t)).join(","):e==null?"":String(e)}const HBe=new Map;function sor(e={}){const t={usage:"search",sensitivity:"base",ignorePunctuation:!0,...e},n=`${ake(e.locale)}|${JSON.stringify(t)}`,r=HBe.get(n);if(r)return r;const s=new Intl.Collator(e.locale,t),i={contains(o,l,c){if(!l)return!0;const u=nm(o,c);for(let d=0;d<=u.length-l.length;d+=1)if(s.compare(u.slice(d,d+l.length),l)===0)return!0;return!1},startsWith(o,l,c){if(!l)return!0;const u=nm(o,c);return s.compare(u.slice(0,l.length),l)===0},endsWith(o,l,c){if(!l)return!0;const u=nm(o,c),d=l.length;return u.length>=d&&s.compare(u.slice(u.length-d),l)===0}};return HBe.set(n,i),i}const ior=sor;function BSt(e,t=!1){const{overflowY:n}=ld(e);return n!=="auto"&&n!=="scroll"?!1:t?e.clientHeight>0:e.scrollHeight>e.clientHeight}function oor(e,t=!1){const{overflowX:n}=ld(e);return n!=="auto"&&n!=="scroll"?!1:t?e.clientWidth>0:e.scrollWidth>e.clientWidth}function Npe(e,t,n=!1){return t==="vertical"?BSt(e,n):oor(e,n)}function aor(e,t,n){let r=e;for(;ei(r)&&r!==t&&!rv(r);){for(const s of n)if(Npe(r,s))return!0;r=dv(r)}return!1}function eI(e,t,n="vertical",r=!1){let s=ei(e)?e:null;for(;ei(s)&&s!==t&&!rv(s);){if(Npe(s,n,r))return s;s=dv(s)}return Npe(t,n,r)?t:null}const VSt=Symbol("none"),_oe={value:VSt,index:-1};function lor(e){const{id:t,onOpenChangeComplete:n,defaultSelectedValue:r=null,selectedValue:s,onSelectedValueChange:i,defaultInputValue:o,inputValue:l,open:c,defaultOpen:u=!1,selectionMode:d,onItemHighlighted:f,name:h,form:p,disabled:m=!1,readOnly:v=!1,required:y=!1,inputRef:x,grid:b=!1,items:S,filteredItems:k,filter:j,openOnInputClick:C=!0,autoHighlight:T=!1,keepHighlight:_=!1,highlightItemOnHover:N=!0,loopFocus:I=!0,itemToStringLabel:A,itemToStringValue:P,isItemEqualToValue:D=Fwt,virtualized:F=!1,inline:Q=!1,fillInputOnItemPress:q=!0,modal:B=!1,limit:V=-1,autoComplete:H="list",formAutoComplete:M,locale:G,submitOnItemClick:L=!1}=e,{clearErrors:$}=Ev(),{setDirty:z,validityData:U,setFilled:K,name:ne,disabled:X,setTouched:te,setFocused:ie,validationMode:ue,validation:ee}=Nu(),se=Ox(),re=hk({id:t}),ae=ior({locale:G}),[he,ve]=g.useState(!1),[pe,ke]=g.useState(null),Ee=g.useRef([]),Ue=g.useRef([]),Qe=g.useRef(null),Be=g.useRef(null),Ae=g.useRef(null),Fe=g.useRef(null),Ce=g.useRef(null),_e=g.useRef(!0),je=g.useRef(!1),ce=g.useRef(null),ye=g.useRef(null),De=g.useRef(null),Ie=g.useRef(_oe),le=g.useRef(null),xe=g.useRef([]),Se=g.useRef(null),Re=X||m,Le=ne??h,We=d==="multiple",tt=d==="single",st=l!==void 0||o!==void 0,He=S!==void 0,ze=k!==void 0;let kt;T==="always"?kt="always":kt=T?"input-change":!1;const[me,Pe]=Xd({controlled:s,default:We?r??zf:r,name:"Combobox",state:"selectedValue"}),Xe=g.useMemo(()=>j===null?()=>!0:j!==void 0?j:ror(ae,A),[j,ae,A]),wt=dl(()=>st?o??"":tt?nm(me,A):"").current,[Bt,Qt]=Xd({controlled:l,default:wt,name:"Combobox",state:"inputValue"}),[yt,bn]=Xd({controlled:c,default:u,name:"Combobox",state:"open"}),vn=uSe(S),we=pe??String(Bt).trim(),Ne=tt?nm(me,A):"",Ze=tt&&!he&&we!==""&&Ne.length===we.length&&ae.contains(Ne,we),ot=Ze?"":we,dt=He&&ze&&Ze,Wt=g.useMemo(()=>S?vn?S.flatMap(mn=>mn.items):S:zf,[S,vn]),Vt=g.useMemo(()=>{if(k&&!dt)return k;if(!S)return zf;if(vn){const In=S,Is=[];let Ti=0;for(const ta of In){if(V>-1&&Ti>=V)break;const $a=V>-1?V-Ti:1/0,Oo=ot===""?ta.items.slice(0,$a):[];if(ot!=="")for(const Yl of ta.items){if(Oo.length>=$a)break;Xe(Yl,ot,A)&&Oo.push(Yl)}if(Oo.length>0){const Yl={...ta,items:Oo};Is.push(Yl),Ti+=Oo.length}}return Is}if(ot==="")return V>-1?Wt.slice(0,V):Wt;const mn=[];for(const In of Wt){if(V>-1&&mn.length>=V)break;Xe(In,ot,A)&&mn.push(In)}return mn},[k,dt,S,vn,ot,V,Xe,A,Wt]),Tt=g.useMemo(()=>vn?Vt.flatMap(In=>In.items):Vt,[Vt,vn]),mt=dl(()=>{let mn=null;return Q&&yt&&He&&d!=="none"&&(mn=loe(Tt,me,D,We)),new oft({id:re,labelId:void 0,selectedValue:me,open:yt,items:S,selectionMode:d,listRef:Ee,labelsRef:Ue,popupRef:Qe,emptyRef:Ce,inputRef:Be,startDismissRef:Ae,endDismissRef:Fe,keyboardActiveRef:_e,chipsContainerRef:ce,clearRef:ye,valuesRef:xe,pointerDownItemRef:Se,selectionEventRef:De,name:Le,form:p,disabled:Re,readOnly:v,required:y,grid:b,virtualized:F,openOnInputClick:C,itemToStringLabel:A,isItemEqualToValue:D,modal:B,autoHighlight:kt,submitOnItemClick:L,hasInputValue:st,mounted:!1,forceMounted:!1,transitionStatus:"idle",inline:Q,activeIndex:null,selectedIndex:mn,popupProps:{},listProps:{},inputProps:{},triggerProps:{},itemProps:si,positionerElement:null,listElement:null,popupId:void 0,triggerElement:null,inputElement:null,inputGroupElement:null,popupSide:null,openMethod:null,inputInsidePopup:!0,inputOwnsFormValue:d==="none",onOpenChangeComplete:ci,setOpen:ci,setInputValue:ci,setSelectedValue:ci,setIndices:ci,handleSelection:ci,forceMount:ci,requestSubmit:ci})}).current,gn=d==="none"?Bt:me,un=g.useMemo(()=>d==="none"?gn:Array.isArray(me)?me.map(mn=>Wg(mn,P)):Wg(me,P),[gn,P,d,me]),Pn=pt(f),gr=pt(n),xs=St(mt,dn.activeIndex),zr=St(mt,dn.selectedIndex),Zr=St(mt,dn.positionerElement),fr=St(mt,dn.listElement),Ci=St(mt,dn.triggerElement),_i=St(mt,dn.inputElement),Pa=St(mt,dn.inputGroupElement),Yr=St(mt,dn.inline),Ka=St(mt,dn.inputInsidePopup),mg=St(mt,dn.inputOwnsFormValue),ga=aa(Ci),{mounted:xc,setMounted:ph,transitionStatus:Od}=eg(yt),{openMethod:$p,triggerProps:Rp}=nSe(yt),mh=pt(()=>un);S_(Ka?ga:Be,re,gn,mh,!Re,h);const Xr=pt(()=>{S?Ue.current=Tt.map(mn=>nm(mn,A)):mt.set("forceMounted",!0)}),Es=pt((mn,In,Is)=>{if(In===-1){if(Ie.current===_oe)return;Ie.current=_oe}else Ie.current={value:mn,index:In};Pn(mn,mH(Is,void 0,{index:In}))}),Ks=pt(mn=>{mt.update(mn);const In=mn.activeIndex;if(In===void 0)return;const Is=mn.type||Io;In===null?Es(void 0,-1,Is):Es(xe.current[In],In,Is)}),Ya=pt((mn,In)=>{if(je.current=In.reason===gy,e.onInputValueChange?.(mn,In),!In.isCanceled){if(In.reason===vI){yt&&pe!==null&&ke(null);const Is=In.event,Ti=Is.inputType;if(Is.type==="compositionend"||Ti!=null&&Ti!==""&&Ti!=="insertReplacementText"){const $a=mn.trim()!=="";$a&&ve(!0),le.current={hasQuery:$a};const Oo=mt.state.listElement;if(!mt.state.virtualized&&Oo){const Yl=Qe.current;for(const vf of yN(Oo.firstElementChild??Oo)){if(!ei(vf)||(Yl?!ln(Yl,vf):vf.getAttribute("role")==="dialog"))break;if(BSt(vf)){vf.scrollTop=0;break}}}$a&&kt&&mt.state.activeIndex==null&&(yt||Yr)&&mt.set("activeIndex",0)}}else In.reason===gy&&mn===""&&mt.state.inputInsidePopup&&(le.current={hasQuery:!1,selection:!0});Qt(mn)}}),gf=pt((mn,In)=>{if(yt!==mn&&(In.reason===d_&&He&&Tt.length===0&&!Ce.current&&In.allowPropagation(),e.onOpenChange?.(mn,In),!In.isCanceled&&(mn&&Ka&&!Yr&&pe!==null&&(ve(!1),ke(null),Bt!==""&&In.reason!==vI&&Ya("",Yt(gy,In.event))),!mn&&he&&(tt?(Yr||ke(we),we===""&&ve(!1)):We&&(Yr||ke(we),Ka&&Ks({activeIndex:null}),(!Ka||Yr)&&Ya("",Yt(gy,In.event)))),bn(mn),!mn&&Ka&&(In.reason===p0||In.reason===D3)&&(te(!0),ie(!1),ue==="onBlur")))){const Is=d==="none"?Bt:me;ee.commit(Is)}}),fi=pt((mn,In)=>{if(i?.(mn,In),In.isCanceled)return;Pe(mn),(d==="none"&&Qe.current&&q||tt&&!mt.state.inputInsidePopup)&&Ya(nm(mn,A),Yt(In.reason,In.event))}),jd=pt((mn,In)=>{const Is=Ui(mn),Ti=De.current??mn;De.current=null;const ta=Yt(D1,Ti),$a=Is?.closest("a")?.getAttribute("href");if($a){$a.startsWith("#")&&gf(!1,ta);return}if(We){const Oo=Array.isArray(me)?me:[],vf=vXn(Oo,In,D)?Bwt(Oo,In,D):[...Oo,In];if(fi(vf,ta),ta.isCanceled||!(Be.current?Be.current.value.trim()!=="":!1))return;mt.state.inputInsidePopup?Ya("",Yt(gy,ta.event)):gf(!1,ta)}else{if(fi(In,ta),ta.isCanceled)return;gf(!1,ta)}}),gg=pt(()=>{const mn=ee.inputRef.current?.form??mt.state.inputElement?.form;mn&&typeof mn.requestSubmit=="function"&&mn.requestSubmit()}),Fx=pt(()=>{if(ph(!1),gr?.(!1),ve(!1),ke(null),Ks(d==="none"?{activeIndex:null,selectedIndex:null}:{activeIndex:null}),We&&Be.current&&Be.current.value!==""&&!je.current&&Ya("",Yt(gy)),tt)if(mt.state.inputInsidePopup)Be.current&&Be.current.value!==""&&Ya("",Yt(gy));else{const mn=nm(me,A);Be.current&&Be.current.value!==mn&&Ya(mn,Yt(mn===""?gy:Io))}}),bc=g.useMemo(()=>Yr&&Zr?{current:Zr.closest('[role="dialog"]')}:Qe,[Yr,Zr]);Wl({enabled:!e.actionsRef,open:yt,ref:bc,onComplete(){yt||Fx()}}),g.useImperativeHandle(e.actionsRef,()=>({unmount:Fx}),[Fx]),It(function(){if(yt||(Se.current=null,d==="none"))return;const In=He?Wt:xe.current;Ks({selectedIndex:loe(In,me,D,We)})},[yt,me,d,We,He,Wt,D,Ks]),It(()=>{S&&(xe.current=Tt,Ee.current.length=Tt.length)},[S,Tt]),It(()=>{const mn=le.current;if(mn){const Yl=yt||Yr||mt.state.positionerElement?.hidden===!1;if(mn.hasQuery)kt&&Yl&&mt.set("activeIndex",0),le.current=null;else if(String(Bt).trim()===""&&(le.current=null,Yl)){const vf=mn.selection;kt==="always"&&!vf&&mt.state.selectionMode==="none"&&mt.set("activeIndex",0),queueMicrotask(()=>{if(!mt.state.open&&!mt.state.inline||Be.current&&Be.current.value.trim()!=="")return;const gh=mt.state.selectedValue,Qv=mt.state.selectionMode==="multiple",_z=Qv&&Array.isArray(gh)?gh[gh.length-1]:gh,eu=mt.state.selectionMode!=="none"&&_z!=null;if(eu||vf){const Ux=He||ze?Tt:xe.current;mt.set("activeIndex",eu?loe(Ux,gh,mt.state.isItemEqualToValue,Qv):null)}else kt==="always"&&mt.set("activeIndex",0)})}}if(!yt&&!Yr)return;const Is=He||ze?Tt:xe.current,Ti=mt.state.activeIndex;if(Ti==null){if(kt==="always"&&Is.length>0){mt.set("activeIndex",0);return}Es(void 0,-1,Io);return}if(Ti>=Is.length){Es(void 0,-1,Io),mt.set("activeIndex",null);return}const ta=Is[Ti],$a=Ie.current.value,Oo=$a!==VSt&&Vm(ta,$a,mt.state.isItemEqualToValue);(Ie.current.index!==Ti||!Oo)&&Es(ta,Ti,Io)},[xs,kt,Es,ze,He,Tt,Yr,yt,mt,Bt]),It(()=>{if(d==="none"){K(String(Bt)!=="");return}K(We?Array.isArray(me)&&me.length>0:me!=null)},[K,d,Bt,me,We]),g.useEffect(()=>{He&&kt&&Tt.length===0&&Ks({activeIndex:null})},[He,kt,Tt.length,Ks]);function Bk(mn){const In=U.initialValue;return Array.isArray(mn)&&Array.isArray(In)?!VG(mn,In,(Is,Ti)=>Vm(Is,Ti,D)):mn!==In}Xg(we,()=>{!yt||we===""||we===String(wt)||ve(!0)});function Vk(){const mn=nm(me,A);Bt!==mn&&Ya(mn,Yt(Io))}Xg(me,()=>{d!=="none"&&($(Le),z(Bk(me)),ee.change(me),tt&&!st&&!Ka&&Vk())}),Xg(Bt,()=>{d==="none"&&($(Le),z(Bt!==U.initialValue),ee.change(Bt))}),Xg(S,()=>{!tt||st||Ka||he||Vk()});const vg=hft({open:Yr?!0:yt,onOpenChange:gf,elements:{reference:Ka?Ci:_i,floating:Zr}}),Bx=b?"grid":"listbox",Uk=yt||Yr,x$=Uk?"true":"false",yg=g.useMemo(()=>{const mn=_i?.tagName==="INPUT",In=_i==null||mn,Is=In||Uk,Ti=In?{autoComplete:"off",spellCheck:"false",autoCorrect:"off",autoCapitalize:"none"}:{};return Is&&(Ti.role="combobox",Ti["aria-expanded"]=x$,Ti["aria-haspopup"]=Bx,Ti["aria-controls"]=Uk?fr?.id:void 0,Ti["aria-autocomplete"]=H),{reference:Ti,floating:{role:"presentation"}}},[_i,Uk,x$,Bx,fr?.id,H]),jz=f_(vg,{enabled:!v&&!Re&&C,event:"mousedown-only",toggle:!1,touchOpenDelay:Ka?0:100,reason:jSn}),qk=h_(vg,{enabled:!v&&!Re&&!Yr,outsidePressEvent:{mouse:"sloppy",touch:"intentional"},bubbles:Yr?!0:void 0,outsidePress(mn){const In=Ui(mn);return!ln(Ci,In)&&!ln(ye.current,In)&&!ln(ce.current,In)&&!ln(Pa,In)}}),Vx=j0e(vg,{enabled:!v&&!Re,id:re,listRef:Ee,activeIndex:xs,selectedIndex:zr,virtual:!0,loopFocus:I,allowEscape:I&&!kt,focusItemOnOpen:he||d==="none"&&!kt?!1:"auto",focusItemOnHover:N,resetOnPointerLeave:!_,orientation:b?"horizontal":void 0,rtl:se==="rtl",disabledIndices:zf,grid:b?tor:void 0,onNavigate(mn,In){!In&&!yt||Od==="ending"||Ks(In?{activeIndex:mn,type:_e.current?o0e:kdt}:{activeIndex:mn})}}),Qk=g.useMemo(()=>kl(Vx.reference,{onKeyDown(mn){b&&mt.state.activeIndex==null&&(mn.key==="ArrowLeft"||mn.key==="ArrowRight")&&mn.preventBaseUIHandler()}},qk.reference,jz.reference,yg.reference),[Vx.reference,qk.reference,jz.reference,yg.reference,b,mt]),b$=g.useMemo(()=>kl(lk,qk.floating),[qk.floating]),w$=g.useMemo(()=>kl(Vx.floating,yg.floating),[Vx.floating,yg.floating]),uw=g.useMemo(()=>{const mn=Vx.item;return mn?{...mn,onFocus:void 0}:si},[Vx.item]);Lwt(()=>{mt.update({inline:Q,popupProps:b$,listProps:w$,inputProps:Qk,triggerProps:Rp,itemProps:uw,setOpen:gf,setInputValue:Ya,setSelectedValue:fi,setIndices:Ks,handleSelection:jd,forceMount:Xr,requestSubmit:gg,onOpenChangeComplete:gr})}),It(()=>{mt.update({id:re,selectedValue:me,open:yt,mounted:xc,transitionStatus:Od,items:S,inline:Q,popupProps:b$,listProps:w$,inputProps:Qk,triggerProps:Rp,openMethod:$p,itemProps:uw,selectionMode:d,name:Le,form:p,disabled:Re,readOnly:v,required:y,grid:b,virtualized:F,openOnInputClick:C,itemToStringLabel:A,modal:B,autoHighlight:kt,isItemEqualToValue:D,submitOnItemClick:L,hasInputValue:st,inputOwnsFormValue:d==="none"&&(Q||!mt.state.inputInsidePopup)})},[mt,re,me,yt,xc,Od,S,b$,w$,Qk,uw,$p,Rp,d,Le,Re,v,y,b,F,C,A,B,D,L,st,Q,kt,p]);const xg=tf(x,ee.inputRef),S$=g.useMemo(()=>({query:we,hasItems:He,filteredItems:Vt,flatFilteredItems:Tt}),[we,He,Vt,Tt]),k$=g.useMemo(()=>Array.isArray(gn)?"":Wg(gn,P),[gn,P]),dw=We&&Array.isArray(me)&&me.length>0,qv=We||d==="none"&&mg?void 0:Le,Cz=g.useMemo(()=>!We||!Array.isArray(me)||!Le?null:me.map(mn=>{const In=Wg(mn,P);return a.jsx("input",{type:"hidden",form:p,name:Le,value:In,disabled:Re},In)}),[We,me,p,Le,P,Re]),O$=a.jsxs(g.Fragment,{children:[e.children,a.jsx("input",{...ee.getValidationProps(Re,{onFocus(){if(Ka){Ci?.focus();return}(Be.current||Ci)?.focus()},onChange(mn){if(mn.nativeEvent.defaultPrevented||Re||v)return;const In=mn.currentTarget.value,Is=In.toLowerCase(),Ti=Yt(Io,mn.nativeEvent),ta=()=>xe.current.findIndex(Oo=>Wg(Oo,P).toLowerCase()===Is||nm(Oo,A).toLowerCase()===Is);function $a(){if(We)return;if(d==="none"){Ya(In,Ti);return}let Oo=ta();Oo===-1&&(Oo=xe.current.findIndex((vf,gh)=>{const Qv=Ue.current[gh];return Qv!=null&&Qv.toLowerCase()===Is}));const Yl=Oo===-1?void 0:xe.current[Oo];Yl!=null&&fi?.(Yl,Ti)}tt&&(Xr(),S&&ta()===-1&&mt.set("forceMounted",!0)),queueMicrotask($a)}}),id:re&&qv==null?`${re}-hidden-input`:void 0,form:p,name:qv,autoComplete:M,disabled:Re,required:y&&!dw,readOnly:v,value:k$,ref:xg,style:qv?tP:uS,tabIndex:-1,"aria-hidden":!0,suppressHydrationWarning:!0}),Cz]});return a.jsx($St.Provider,{value:mt,children:a.jsx(RSt.Provider,{value:vg,children:a.jsx(DSt.Provider,{value:He,children:a.jsx(MSt.Provider,{value:S$,children:a.jsx(LSt.Provider,{value:Bt,children:O$})})})})})}function oQ(e){const{multiple:t=!1,defaultValue:n,value:r,onValueChange:s,autoComplete:i,...o}=e;return a.jsx(lor,{...o,selectionMode:t?"multiple":"single",selectedValue:r,defaultSelectedValue:n,onSelectedValueChange:s,formAutoComplete:i})}function GBe(e){const{children:t,placeholder:n}=e,r=og(),s=St(r,dn.itemToStringLabel),i=St(r,dn.selectedValue),o=St(r,dn.items),l=St(r,dn.selectionMode)==="multiple",c=St(r,dn.hasSelectedValue),u=!c&&n!=null&&t==null,d=St(r,dn.hasNullItemLabel,u);let f=null;return typeof t=="function"?f=t(i):t!=null?f=t:!c&&n!=null&&!d?f=n:l&&Array.isArray(i)?f=Uwt(i,o,s):f=dSe(i,o,s),a.jsx(g.Fragment,{children:f})}const USt={...kN,...jp,popupSide:e=>e?{"data-popup-side":e}:null,listEmpty:e=>e?{"data-list-empty":""}:null},cor=g.createContext(void 0);function uor(){return g.useContext(cor)}const qSt=g.createContext(void 0);function lke(e){const t=g.useContext(qSt);if(t===void 0&&!e)throw new Error(Ar(21));return t}const QSt=g.forwardRef(function(t,n){const r=og(),{buttonRef:s,getButtonProps:i}=hd({native:!1}),o=tf(n,s);function l(u){r.state.setOpen(!1,Yt(i0e,u.nativeEvent,u.currentTarget))}const c=i({onClick:l});return a.jsx("span",{ref:o,...c,"aria-label":"Dismiss",tabIndex:void 0,style:tP})});function ZSt(e){const t=St(e,dn.mounted),n=St(e,dn.popupSide),r=St(e,dn.positionerElement);return t&&r?n:null}function rK(){return LL().filteredItems.length===0}function dor(e){return e==="rtl"?["ArrowRight","ArrowLeft"]:["ArrowLeft","ArrowRight"]}function hor(e,t){const n=e>=t-1?t-2:e;return n>=0?n:void 0}function WSt(e,t,n){const r=e.state.listRef.current[t];r&&(e.state.selectionEventRef.current=n,r.click(),e.state.selectionEventRef.current=null)}const cke=g.forwardRef(function(t,n){const{render:r,className:s,disabled:i=!1,id:o,style:l,...c}=t,{state:u,disabled:d,setTouched:f,setFocused:h,validationMode:p,validation:m}=Nu(),{labelId:v}=gd(),y=uor(),b=!!lke(!0),S=og(),k=zSt(),j=Ox(),C=St(S,dn.required),T=St(S,dn.disabled),_=St(S,dn.readOnly),N=St(S,dn.name),I=St(S,dn.form),A=St(S,dn.selectionMode),P=St(S,dn.autoHighlight),D=St(S,dn.inputProps),F=St(S,dn.triggerProps),Q=St(S,dn.open),q=St(S,dn.mounted),B=St(S,dn.selectedValue),V=St(S,dn.id),H=St(S,dn.inline),M=St(S,dn.modal),G=!!P,L=ZSt(S),$=d||T||i,z=rK(),U=b||H,K=!U||M,ne=Qi(o??(U?void 0:V)),X=b?Mgt:u,[te,ie]=g.useState(null),ue=g.useRef(!1),ee=g.useRef(null),se=g.useRef(!1),re=A==="none"&&!b,ae=pt(Be=>{const Ae=b||S.state.inline;Ae&&!S.state.hasInputValue&&S.state.setInputValue("",Yt(Io)),S.update({inputElement:Be,inputInsidePopup:Ae,inputOwnsFormValue:re})}),he=b?c:m.getValidationProps($,c);function ve(){S.state.setIndices({activeIndex:null,selectedIndex:null,type:S.state.keyboardActiveRef.current?o0e:kdt})}function pe(){S.state.keyboardActiveRef.current=!1}const ke={...X,open:Q,disabled:$,readOnly:_,popupSide:L,listEmpty:z};function Ee(Be){if(!y)return;let Ae;const{highlightedChipIndex:Fe}=y,Ce=y.chipsRef.current.length,[_e,je]=dor(j);return Fe!==void 0?(Be.key===_e?(Be.preventDefault(),Fe>0?Ae=Fe-1:Ae=void 0):Be.key===je?(Be.preventDefault(),Fe<Ce-1?Ae=Fe+1:Ae=void 0):(Be.key==="Backspace"||Be.key==="Delete")&&(Be.preventDefault(),Ae=hor(Fe,B.length),ve()),Ae):(Be.key===_e&&(Be.currentTarget.selectionStart??0)===0&&B.length>0&&(Be.preventDefault(),Ae=Ce>0?Ce-1:void 0),Ae)}const Ue=hn("input",t,{state:ke,ref:[n,S.state.inputRef,ae],props:[D,F,{value:te??k,"aria-readonly":_||void 0,"aria-required":C||void 0,"aria-labelledby":v,disabled:$,readOnly:_,required:A==="none"?C:void 0,form:I,...re&&N&&{name:N},id:ne,onFocus(){if(h(!0),!H||!se.current)return;se.current=!1;const Be=ee.current;Be==null||!Object.hasOwn(S.state.valuesRef.current,Be)||S.state.setIndices({activeIndex:Be})},onBlur(){f(!0),h(!1);const Be=S.state.activeIndex;if(H&&Be!==null&&P!=="always"&&(ee.current=Be,se.current=!0,S.state.setIndices({activeIndex:null})),p==="onBlur"){const Ae=A==="none"?k:B;m.commit(Ae)}},onCompositionStart(Be){h4||(ue.current=!0,ie(Be.currentTarget.value))},onCompositionEnd(Be){ue.current=!1;const Ae=Be.currentTarget.value;ie(null),S.state.setInputValue(Ae,Yt(vI,Be.nativeEvent))},onChange(Be){const Ae=Be.nativeEvent,Fe=Ae.inputType,Ce=!Fe||Fe==="insertReplacementText",_e=ue.current||!Ce;function je(Ie){_||$||!Ie||!_e||(S.state.setOpen(!0,Yt(vI,Ae)),G||ve())}if(ue.current){const Ie=Be.currentTarget.value;ie(Ie),Ie===""&&!S.state.openOnInputClick&&!S.state.inputInsidePopup&&S.state.setOpen(!1,Yt(gy,Ae));const le=Ie.trim(),xe=G&&le!=="";je(le),Q&&S.state.activeIndex!==null&&!xe&&ve();return}const ce=Yt(vI,Ae);if(S.state.setInputValue(Be.currentTarget.value,ce),ce.isCanceled)return;const ye=Be.currentTarget.value==="",De=Yt(gy,Ae);ye&&!S.state.inputInsidePopup&&(A==="single"&&S.state.setSelectedValue(null,De),S.state.openOnInputClick||S.state.setOpen(!1,De)),je(Be.currentTarget.value.trim()),Q&&S.state.activeIndex!==null&&!G&&ve()},onKeyDown(Be){if($||_||Be.ctrlKey||Be.shiftKey||Be.altKey||Be.metaKey)return;S.state.keyboardActiveRef.current=!0;const Ae=Be.currentTarget,Fe=Ae.scrollWidth-Ae.clientWidth,Ce=j==="rtl";if(Be.key==="Home"){oc(Be);const ce=iLe&&Ce?Ae.value.length:0;Ae.setSelectionRange(ce,ce),Ae.scrollLeft=0;return}if(Be.key==="End"){oc(Be);const ce=iLe&&Ce?0:Ae.value.length;Ae.setSelectionRange(ce,ce),Ae.scrollLeft=Ce?-Fe:Fe;return}if(!q&&Be.key==="Escape"){const ce=A==="multiple"&&Array.isArray(B)?B.length===0:B===null,ye=Yt(d_,Be.nativeEvent),De=A==="multiple"?[]:null;S.state.setInputValue("",ye),S.state.setSelectedValue(De,ye),!ce&&!S.state.inline&&!ye.isPropagationAllowed&&Be.stopPropagation();return}if(y&&Be.key==="Backspace"&&Ae.value===""&&y.highlightedChipIndex===void 0&&Array.isArray(B)&&B.length>0){const ce=y.chipsRef.current.length,ye=ce>0?ce-1:B.length-1,De=B.filter((Ie,le)=>le!==ye);ve(),S.state.setSelectedValue(De,Yt(Io,Be.nativeEvent));return}const _e=y?.highlightedChipIndex!==void 0,je=Ee(Be);if(y?.setHighlightedChipIndex(je),je!==void 0?y?.chipsRef.current[je]?.focus():_e&&S.state.inputRef.current?.focus(),Be.which!==229&&Be.key==="Enter"&&Q){const ce=S.state.activeIndex,ye=Be.nativeEvent;if(ce===null){if(H)return;S.state.setOpen(!1,Yt(Io,ye));return}oc(Be),WSt(S,ce,ye)}},onPointerMove:pe,onPointerDown:pe},he],stateAttributesMapping:USt}),Qe=b?a.jsx($we.Provider,{value:Dgt,children:Ue}):Ue;return a.jsxs(g.Fragment,{children:[Q&&K&&a.jsx(QSt,{ref:S.state.startDismissRef}),Qe]})}),HSt=g.forwardRef(function(t,n){const{render:r,className:s,nativeButton:i=!0,disabled:o=!1,id:l,style:c,...u}=t,{state:d,disabled:f,setTouched:h,setFocused:p,validationMode:m,validation:v}=Nu(),{labelId:y}=gd(),x=og(),b=St(x,dn.selectionMode),S=St(x,dn.disabled),k=St(x,dn.readOnly),j=St(x,dn.required),C=St(x,dn.positionerElement),T=St(x,dn.listElement),_=St(x,dn.popupId),N=St(x,dn.triggerProps),I=St(x,dn.inputInsidePopup),A=St(x,dn.id),P=St(x,dn.labelId),D=St(x,dn.open),F=St(x,dn.selectedValue),Q=St(x,dn.activeIndex),q=St(x,dn.selectedIndex),B=St(x,dn.hasSelectedValue),V=nK(),H=zSt(),M=$o(),G=f||S||o,L=rK(),$=ZSt(x);hk({id:I?l:void 0});const z=I?l??A:l,U=fSe(y,P);let K;D&&I?K=_??FSt(A):D&&(K=T?.id);const ne=g.useRef("");function X(he){ne.current=he.pointerType}const{reference:te}=C0e(V,{enabled:!D&&!k&&!S&&b==="single",listRef:x.state.labelsRef,activeIndex:Q,selectedIndex:q,onMatch(he){const ve=x.state.valuesRef.current[he];ve!==void 0&&x.state.setSelectedValue(ve,Yt(Io))}}),{reference:ie}=f_(V,{enabled:!k&&!S,event:"mousedown"}),{buttonRef:ue,getButtonProps:ee}=hd({native:i,disabled:G}),se={...d,open:D,disabled:G,popupSide:$,listEmpty:L,placeholder:b==="none"?!1:!B},re=pt(he=>{x.set("triggerElement",he)});return hn("button",t,{ref:[n,ue,re],state:se,props:[N,ie,te,{id:z,tabIndex:I?0:-1,role:I?"combobox":void 0,"aria-expanded":D,"aria-haspopup":I?"dialog":"listbox","aria-controls":K,"aria-required":I&&j||void 0,"aria-labelledby":U,onPointerDown:X,onPointerEnter:X,onFocus(){p(!0),!(G||k)&&M.start(0,x.state.forceMount)},onBlur(he){if(!ln(C,he.relatedTarget)&&(h(!0),p(!1),m==="onBlur")){const ve=b==="none"?H:F;v.commit(ve)}},onMouseDown(he){if(G||k||(I||V.set("domReferenceElement",he.currentTarget),x.state.forceMount(),ne.current!=="touch"&&(x.state.inputRef.current?.focus(),I||he.preventDefault()),D))return;const ve=wr(he.currentTarget);function pe(ke){const Ee=x.state.triggerElement;if(!Ee)return;const Ue=Ui(ke),Qe=x.state.positionerElement,Be=x.state.listElement;ln(Ee,Ue)||ln(Qe,Ue)||ln(Be,Ue)||sSe(ke,Ee)||x.state.setOpen(!1,Yt(pH,ke))}I&&ve.addEventListener("mouseup",pe,{once:!0})},onKeyDown(he){k||(he.key==="ArrowDown"||he.key==="ArrowUp")&&(oc(he),x.state.setOpen(!0,Yt(p4,he.nativeEvent)),x.state.inputRef.current?.focus())}},v.getValidationProps(G,u),ee],stateAttributesMapping:USt})}),por=g.createContext(null);function mor(){return g.useContext(por)}function gor(e){const{children:t}=e,{filteredItems:n}=LL(),r=mor(),s=r?r.items:n;return a.jsx(g.Fragment,{children:s.map(t)})}const GSt=g.forwardRef(function(t,n){var r;const{render:s,className:i,style:o,children:l,...c}=t,u=og(),d=nK(),f=!!lke(!0),{filteredItems:h,hasItems:p}=LL(),m=St(u,dn.selectionMode),v=St(u,dn.grid),y=St(u,dn.listProps),x=St(u,dn.virtualized),b=St(u,dn.forceMounted),S=m==="multiple",k=h.length===0,j=pt(P=>{u.set("positionerElement",P)}),C=pt(P=>{u.set("listElement",P)}),T=g.useMemo(()=>typeof l=="function"?r||(r=a.jsx(gor,{children:l})):l,[l]),_={empty:k},N=d.useState("floatingId"),I=hn("div",t,{state:_,ref:[n,C,f?null:j],props:[y,{children:T,tabIndex:-1,id:N,role:v?"grid":"listbox","aria-multiselectable":S?"true":void 0,onKeyDown(P){if(!(u.state.disabled||u.state.readOnly)&&P.key==="Enter"){const D=u.state.activeIndex;if(D==null)return;oc(P),WSt(u,D,P.nativeEvent)}},onKeyDownCapture(){u.state.keyboardActiveRef.current=!0},onPointerMoveCapture(){u.state.keyboardActiveRef.current=!1}},c]});if(x)return I;const A=p&&!b?void 0:u.state.labelsRef;return a.jsx(SP,{elementsRef:u.state.listRef,labelsRef:A,children:I})}),vor="",yor=200;function xor(e){const t=e.ownerDocument.createTreeWalker(e,NodeFilter.SHOW_TEXT);let n=null;for(;t.nextNode();){const r=t.currentNode;r.nodeValue!==""&&(n=r)}return n}function KSt(){const e=$o(),t=g.useRef(null);return g.useEffect(()=>{if(M3)return;const n=t.current;if(n==null)return;const r=xor(n);if(r==null)return;const s=r.data,i=`${s}${vor}`;return r.nodeValue=i,e.start(yor,()=>{r.nodeValue===i&&(r.nodeValue=s)}),()=>{e.clear(),r.nodeValue===i&&(r.nodeValue=s)}},[t,e]),t}const KBe=g.forwardRef(function(t,n){const{render:r,className:s,style:i,children:o,...l}=t,c=KSt();return hn("div",t,{ref:[n,c],props:[{children:o,role:"status","aria-live":"polite","aria-atomic":!0},l]})}),YSt=g.createContext(void 0);function bor(){const e=g.useContext(YSt);if(e===void 0)throw new Error(Ar(20));return e}const uke=g.forwardRef(function(t,n){const{keepMounted:r=!1,...s}=t,i=og(),o=St(i,dn.mounted),l=St(i,dn.forceMounted);return o||r||l?a.jsx(YSt.Provider,{value:r,children:a.jsx(F3,{ref:n,...s})}):null}),dke=g.forwardRef(function(t,n){const{render:r,className:s,anchor:i,positionMethod:o,side:l,align:c,sideOffset:u,alignOffset:d,collisionBoundary:f="clipping-ancestors",collisionPadding:h,arrowPadding:p,sticky:m,disableAnchorTracking:v=!1,collisionAvoidance:y=h0e,style:x,...b}=t,S=og(),k=nK(),j=bor(),C=St(S,dn.modal),T=St(S,dn.open),_=St(S,dn.mounted),N=St(S,dn.openMethod),I=St(S,dn.positionerElement),A=St(S,dn.triggerElement),P=St(S,dn.inputElement),D=St(S,dn.inputGroupElement),F=St(S,dn.inputInsidePopup),Q=St(S,dn.transitionStatus),q=rK(),V=sP({anchor:i??(F?A:D??P),floatingRootContext:k,positionMethod:o,mounted:_,side:l,sideOffset:u,align:c,alignOffset:d,arrowPadding:p,collisionBoundary:f,collisionPadding:h,sticky:m,disableAnchorTracking:v,keepMounted:j,collisionAvoidance:y,lazyFlip:!0});LG(T&&C,N==="touch",I,A);const H={open:T,side:V.side,align:V.align,anchorHidden:V.anchorHidden,empty:q};It(()=>{S.set("popupSide",V.side)},[S,V.side]);const M=pt(L=>{S.set("positionerElement",L)}),G=iP(t,H,{styles:V.positionerStyles,transitionStatus:Q,props:b,refs:[n,M],hidden:!_,inert:!T});return a.jsxs(qSt.Provider,{value:V,children:[_&&C&&a.jsx(TL,{inert:oP(!T),cutout:D??P??A}),G]})}),wor={...g_,...kp},fke=g.forwardRef(function(t,n){const{render:r,className:s,style:i,initialFocus:o,finalFocus:l,...c}=t,u=og(),d=lke(),f=nK(),h=St(u,dn.mounted),p=St(u,dn.open),m=St(u,dn.openMethod),v=St(u,dn.popupProps),y=St(u,dn.transitionStatus),x=St(u,dn.inputInsidePopup),b=St(u,dn.inputElement),S=St(u,dn.modal),k=St(u,dn.id),j=rK(),C=c.id??(x?FSt(k):void 0);It(()=>(u.set("popupId",u.state.popupRef.current?.id||C),()=>{u.set("popupId",void 0)}),[u,C]),Wl({open:p,ref:u.state.popupRef,onComplete(){p&&u.state.onOpenChangeComplete(!0)}});const T={open:p,side:d.side,align:d.align,anchorHidden:d.anchorHidden,transitionStatus:y,empty:j},_=hn("div",t,{state:T,ref:[n,u.state.popupRef],props:[v,{id:C,role:x?"dialog":"presentation",onFocus(D){const F=Ui(D.nativeEvent);m!=="touch"&&(ln(u.state.listElement,F)||F===D.currentTarget)&&u.state.inputRef.current?.focus()}},y_(y),c],stateAttributesMapping:wor}),I=o===void 0?x?D=>D==="touch"?u.state.popupRef.current:b:!1:o;let A;l!=null?A=l:A=x?void 0:!1;const P=!x||S;return a.jsx(nP,{context:f,disabled:!h,modal:P,openInteractionType:m,initialFocus:I,returnFocus:A,getInsideElements:()=>[u.state.startDismissRef.current,u.state.endDismissRef.current],children:a.jsxs(g.Fragment,{children:[_,P&&a.jsx(QSt,{ref:u.state.endDismissRef})]})})}),XSt=g.createContext(void 0);function JSt(){const e=g.useContext(XSt);if(!e)throw new Error(Ar(19));return e}const Sor=g.createContext(!1);function kor(){return g.useContext(Sor)}function ekt(e){const{componentProps:t,forwardedRef:n,virtualized:r,indexFromFilter:s}=e,{render:i,className:o,style:l,value:c=null,index:u,disabled:d=!1,nativeButton:f=!1,...h}=t,p=g.useRef(null),m=V0({guess:!0,index:u,textRef:p}),v=og(),y=kor(),x=nor(),b=St(v,dn.selectionMode),S=St(v,dn.disabled),k=St(v,dn.readOnly),j=St(v,dn.isItemEqualToValue),C=S||d,T=b!=="none",_=u??s??m.index,N=_!==-1,I=St(v,dn.id),A=St(v,dn.isActive,_),P=St(v,dn.isSelected,c),D=St(v,dn.itemProps),F=g.useRef(null),Q=I!=null&&N?`${I}-${_}`:void 0,q=P&&T;It(()=>{if(!(N&&(r||u!=null)))return;const U=v.state.listRef.current;return U[_]=F.current,()=>{delete U[_]}},[N,r,_,u,v]),It(()=>{if(!N||x)return;const z=v.state.valuesRef.current;return z[_]=c,()=>{delete z[_]}},[N,x,_,c,v]),It(()=>{if(!N||x)return;const z=v.state.selectedValue,U=Array.isArray(z)?z[z.length-1]:z;Vm(c,U,j)&&v.set("selectedIndex",_)},[N,x,v,_,c,j]);const{getButtonProps:B,buttonRef:V}=hd({disabled:C,focusableWhenDisabled:!0,native:f,composite:!0}),H={disabled:C,selected:q,highlighted:A};function M(z){function U(){v.state.handleSelection(z,c)}v.state.submitOnItemClick?(wo.flushSync(U),v.state.requestSubmit()):U()}const G={id:Q,role:y?"gridcell":"option","aria-selected":T?q:void 0,tabIndex:void 0,onPointerDownCapture(z){z.isPrimary&&(v.state.pointerDownItemRef.current=z.currentTarget),z.preventDefault()},onMouseDown(z){z.preventDefault()},onClick(z){C||k||M(z.nativeEvent)},onMouseUp(z){const U=v.state.pointerDownItemRef.current===z.currentTarget;v.state.pointerDownItemRef.current=null,!(C||k||z.button!==0||U||!A)&&M(z.nativeEvent)}},L=hn("div",t,{ref:[V,n,m.ref,F],state:H,props:[D,G,h,B]}),$=g.useMemo(()=>({selected:q,textRef:p}),[q,p]);return a.jsx(XSt.Provider,{value:$,children:L})}function Oor(e){const{componentProps:t,forwardedRef:n}=e,r=og(),s=St(r,dn.isItemEqualToValue),{flatFilteredItems:i}=LL(),o=RI(i,t.value??null,s);return a.jsx(ekt,{componentProps:t,forwardedRef:n,virtualized:!0,indexFromFilter:o})}const tkt=g.memo(g.forwardRef(function(t,n){const r=og(),s=St(r,dn.virtualized);return s&&t.index==null?a.jsx(Oor,{componentProps:t,forwardedRef:n}):a.jsx(ekt,{componentProps:t,forwardedRef:n,virtualized:s,indexFromFilter:void 0})})),nkt=g.forwardRef(function(t,n){const{selected:r}=JSt();return t.keepMounted||r?a.jsx(jor,{...t,ref:n}):null}),jor=g.memo(g.forwardRef((e,t)=>{const{render:n,className:r,style:s,keepMounted:i,...o}=e,{selected:l}=JSt(),c=g.useRef(null),{transitionStatus:u,setMounted:d}=eg(l),h=hn("span",e,{ref:[t,c],state:{selected:l,transitionStatus:u},props:[{"aria-hidden":!0,children:"✔️"},o],stateAttributesMapping:kp});return Wl({open:l,ref:c,onComplete(){l||d(!1)}}),h})),rkt=g.forwardRef(function(t,n){const{render:r,className:s,style:i,children:o,...l}=t,{filteredItems:c}=LL(),u=og(),d=KSt(),f=c.length===0?o:null;return hn("div",t,{ref:[n,u.state.emptyRef,d],props:[{children:f,role:"status","aria-live":"polite","aria-atomic":!0},l]})});function Cor(e){return e==="link"?"ghost":e}function skt({variant:e,size:t,className:n}){const r=Cor(e);return Z(lP({variant:r,size:t}),r==="default"&&Eft,!$0e(t)&&Z(Ift,"justify-between"),T0e[r],"data-[placeholder]:text-muted-foreground",N0e,n)}const Ape=pd(ig,{variants:{multiple:{false:"",true:""}},defaultVariants:{multiple:!1}}),ls={root:"flex flex-col gap-1.5",chevron:"ml-2 h-4 w-4 shrink-0 text-muted-foreground",placeholder:"text-muted-foreground",popup:Z(CP,"max-h-none overflow-hidden p-0"),positioner:Z(jP,"pointer-events-auto"),searchContainer:AI.container,searchIcon:AI.icon,searchInput:Z(AI.input,"disabled:cursor-not-allowed disabled:opacity-50"),empty:Z(Gq,"empty:hidden"),list:"p-1 empty:p-0",listScroller:"max-h-dropdown overflow-y-auto overflow-x-hidden",item:Ape({multiple:!1}),itemMulti:Ape({multiple:!0}),itemRightSlot:"ml-auto flex items-center gap-2 shrink-0",checkContainer:Z(C_,"ml-0"),checkIcon:"size-full",optionText:"flex flex-col gap-0.5 min-w-0",optionLabel:"truncate",optionDescription:"text-caption text-muted-foreground truncate",optionEnd:"ml-auto flex items-center shrink-0"};function _or({children:e,className:t}){return a.jsx("div",{className:Z("grid gap-2 text-foreground",t),children:e})}function ikt({children:e,name:t,className:n}){return a.jsxs(Y,{variant:"body-sm",role:"alert",id:t!==void 0?`error-${t}`:void 0,className:Z("flex gap-1 text-destructive-foreground",n),children:[a.jsx(At,{size:"xs",className:"mt-1 shrink-0","aria-hidden":!0,children:a.jsx(uP,{})}),a.jsx("span",{children:e})]})}function okt({children:e}){return a.jsx(Y,{variant:"caption",tone:"muted",children:e})}function Tor({children:e,name:t,htmlFor:n=`input-${t}`,required:r,disabled:s=!1,size:i="default",className:o}){return a.jsxs("label",{htmlFor:n,className:Z("inline-flex items-center text-label",{"text-body":i==="bigger","text-foreground":!s,"text-muted-foreground":s},o),children:[e,r?a.jsxs(a.Fragment,{children:[a.jsx("span",{"aria-hidden":!0,className:Z("ml-0.5",s?"text-muted-foreground":"text-destructive-foreground"),children:"*"}),a.jsx("span",{className:"sr-only",children:" (required)"})]}):null]})}function Eor({children:e,className:t,layout:n="vertical",labelColumnWidth:r}){return a.jsx("div",{className:Z("relative grid gap-2 text-foreground",{"horizontal-field-block grid-cols-[auto_1fr] items-baseline":n==="horizontal"},t),style:n==="horizontal"&&r?{gridTemplateColumns:`${r} 1fr`}:void 0,children:e})}function Ior({name:e,helpText:t,errorMsg:n}){return a.jsx("div",{className:"h-[1lh] min-w-0 overflow-hidden text-body-sm [&>p]:truncate",children:n?a.jsx(ikt,{name:e,className:"truncate",children:n}):t?a.jsx(okt,{children:t}):null})}const Nor=Object.assign({},{Layout:Eor,Column:_or,Label:Tor,HelpText:okt,ErrorMsg:ikt,Message:Ior}),Aor=e=>`error-${e}`,YBe=[],Por=[];function Toe(e){return e.multiple===!0}const akt=g.forwardRef((e,t)=>a.jsx(tkt,{ref:Pu(t),...e}));akt.displayName="ComboboxItem";function XBe({option:e}){return a.jsxs("span",{className:ls.optionText,children:[a.jsx("span",{className:ls.optionLabel,children:e.label}),e.description&&a.jsx("span",{className:ls.optionDescription,children:e.description})]})}function Qa(e){const{options:t,placeholder:n=Toe(e)?"Select options...":"Select option...",searchPlaceholder:r="Search...",emptyText:s="No option found.",className:i,disabled:o=!1,variant:l="default",size:c="md",open:u,onOpenChange:d,container:f,id:h,"aria-label":p,"aria-describedby":m,align:v="start",showChevron:y=!0,iconOnlyValue:x=!1,allowCustomValue:b=!1,onInputValueChange:S,error:k,name:j}=e,C=Toe(e),T=C?e.clearLabel:void 0,_=mP(),N=g.useId(),I=j??N,A=[m,k?Aor(I):void 0].filter(Boolean).join(" ")||void 0,[P,D]=g.useState(""),F=P.trim(),Q=!C&&b&&F&&!t.some(X=>X.value===F)?{label:`Use “${F}”`,value:F}:void 0,q=Q?[Q,...t]:t,B=C?e.value??YBe:YBe,V=g.useMemo(()=>new Set(B),[B]),H=C?null:t.find(X=>X.value===e.value)??null,M=C?t.filter(X=>V.has(X.value)):Por,G=M.length===0?n:`${M.length} selected`,L=()=>{Toe(e)&&e.onValueChange?.([])},$=U0(f),z=Rv(),U=$0e(c),K=a.jsxs(a.Fragment,{children:[a.jsxs(HSt,{id:h,"aria-label":p??(h||_?void 0:C?"Select options":"Select option"),...Tx({"aria-label":p}),...TH(!!k),"aria-describedby":A,"data-shape":U?"icon":void 0,className:skt({variant:l,size:c,className:Z(x&&"w-auto px-2.5",i)}),children:[U?a.jsx("span",{className:"sr-only",children:C?G:a.jsx(GBe,{placeholder:n})}):C?a.jsx("span",{className:Z("truncate",M.length===0&&ls.placeholder),children:G}):a.jsxs("span",{className:Z("flex min-w-0 flex-1 items-center",x?"justify-center":"gap-2"),children:[H?.start,a.jsx("span",{className:"truncate",children:H?.displayLabel??a.jsx(GBe,{placeholder:n})})]}),y?a.jsx("span",{className:"flex shrink-0 items-center",children:a.jsx(qft,{className:Z(ls.chevron,(U||x)&&"ml-0")})}):null]}),a.jsx(uke,{container:$,children:a.jsx(dke,{align:v,sideOffset:4,positionMethod:jv,className:ls.positioner,children:a.jsxs(fke,{className:ls.popup,children:[a.jsxs("div",{className:ls.searchContainer,children:[a.jsx(Kd,{className:ls.searchIcon}),a.jsx(cke,{className:ls.searchInput,placeholder:r,...gp})]}),a.jsx(rkt,{className:ls.empty,children:s}),a.jsx(Nr,{maxHeight:"var(--spacing-dropdown)",children:a.jsx(af,{className:"scroll-py-8",children:a.jsx("div",{className:z.containerClassName,...z.getContainerProps({}),children:a.jsx(Bm,{menu:z,children:a.jsx(GSt,{className:ls.list,children:X=>{const te=V.has(X.value);return a.jsx(akt,{value:X,className:Ape({multiple:C}),children:C?a.jsxs(a.Fragment,{children:[X.start,a.jsx(XBe,{option:X}),a.jsxs("span",{className:ls.itemRightSlot,children:[X.end?a.jsx("div",{className:ls.optionEnd,children:X.end}):null,a.jsx("span",{className:ls.checkContainer,children:te?a.jsx(dr,{className:ls.checkIcon}):null})]})]}):a.jsxs(a.Fragment,{children:[X.start,a.jsx(XBe,{option:X}),a.jsxs("span",{className:ls.itemRightSlot,children:[X.end?a.jsx("div",{className:ls.optionEnd,children:X.end}):null,a.jsx("span",{className:ls.checkContainer,children:a.jsx(nkt,{children:a.jsx(dr,{className:ls.checkIcon})})})]})]})},X.value)}})})})})}),B.length>0&&T?a.jsx("div",{className:Z("border-t","border-border","p-1"),children:a.jsx(de,{type:"button",variant:"destructive-ghost",size:"sm",className:"w-full justify-start",onClick:L,icon:a.jsx(Dn,{}),children:T})}):null]})})})]}),ne=C?a.jsx(oQ,{multiple:!0,autoHighlight:!0,items:q,value:M,onValueChange:X=>e.onValueChange?.((X??[]).map(te=>te.value)),disabled:o,open:u,onOpenChange:d,children:K}):a.jsx(oQ,{autoHighlight:!0,items:q,value:H,inputValue:P,onInputValueChange:X=>{D(X),S?.(X)},onValueChange:X=>{X&&(e.onValueChange?.(X.value),D(""),S?.(""))},disabled:o,open:u,onOpenChange:d,children:K});return k?a.jsxs("div",{className:ls.root,children:[ne,a.jsx(Nor.ErrorMsg,{name:I,children:k})]}):ne}function $or({value:e,onValueChange:t,placeholder:n="Select a workflow...",searchPlaceholder:r="Search workflows...",emptyText:s="No workflows found.",className:i,disabled:o=!1,variant:l,size:c,"aria-label":u,align:d,requestContext:f}){const{data:h={},isLoading:p,isError:m,error:v}=Op({requestContext:f}),{navigate:y,paths:x}=xn();g.useEffect(()=>{if(m){const k=v instanceof Error?v.message:"Failed to load workflows";Ke.error(`Error loading workflows: ${k}`)}},[m,v]);const b=Object.keys(h).map(k=>({label:h[k]?.name||k,value:k})),S=k=>{t?t(k):k&&k!==e&&y(x.workflowLink(k))};return a.jsx(Qa,{options:b,value:e,onValueChange:S,placeholder:p?"Loading workflows...":n,searchPlaceholder:r,emptyText:s,className:i,disabled:o||p||m,variant:l,size:c,"aria-label":u,align:d})}function Ror(){const{workflowId:e}=jr(),{data:t,isLoading:n}=Op();return e?n?a.jsx(Nx,{}):t?.[e]?.name||e:null}function Mor(){const{workflowId:e}=jr();return e?a.jsx($or,{value:e,...EP,"aria-label":"Switch workflow"}):null}function Dor(){const{runId:e}=jr();return e?e.split("-")[0]:null}function Lor(){const{runId:e}=jr();return e?a.jsx(Zi,{content:e,tooltip:"Copy run id",variant:"ghost",size:"icon-sm"}):null}const zor=e=>a.jsxs("svg",{width:"17",height:"16",viewBox:"0 0 17 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:[a.jsx("path",{d:"M11.0313 7.97578C11.0313 9.34436 9.92183 10.4538 8.55324 10.4538C7.18466 10.4538 6.0752 9.34436 6.0752 7.97578C6.0752 6.60719 7.18466 5.49773 8.55324 5.49773C9.92183 5.49773 11.0313 6.60719 11.0313 7.97578ZM11.0313 7.97578H14.573",stroke:"currentColor",strokeWidth:"1.33333",strokeLinecap:"round"}),a.jsx("path",{d:"M12.967 4.46154C11.9273 3.14431 10.3165 2.29883 8.50814 2.29883C5.37277 2.29883 2.83105 4.84055 2.83105 7.97591C2.83105 11.1113 5.37277 13.653 8.50814 13.653C10.3165 13.653 11.9273 12.8075 12.967 11.4903",stroke:"currentColor",strokeWidth:"1.33333",strokeLinecap:"round"})]});function For(){return a.jsx(de,{render:a.jsx("a",{target:"_blank",rel:"noopener noreferrer",href:"/swagger-ui"}),variant:"ghost",size:"sm",icon:a.jsx(zor,{}),children:"API endpoints"})}function Bor(e){if("Component"in e&&e.Component){const t=e.Component;return a.jsx(t,{})}return"node"in e?e.node:e.label}function Dt({crumbs:e}){if(e.length===0)return null;const t=e.length-1;return a.jsx(oke,{label:"Breadcrumb",className:"min-w-0 flex-1 overflow-hidden",listClassName:"min-w-0",children:e.map((n,r)=>{const s=r===t,i=!s&&n.to,o=n.icon,l=n.Action,c=n.Switcher;return a.jsx(m5,{as:i?lc:"span",to:i?n.to:void 0,isCurrent:s,icon:o?a.jsx(o,{}):void 0,action:l?a.jsx(l,{}):void 0,switcher:c?a.jsx(c,{}):void 0,children:Bor(n)},n.id)})})}const IP=({queryOptions:e}={})=>{const t=Ye();return _t({queryKey:["mastra-packages"],queryFn:()=>t.getSystemPackages(),...e})},lkt=()=>{const{data:e,isLoading:t}=IP();return{hasObservability:!!(e?.observabilityEnabled??e?.packages?.some(r=>r.name==="@mastra/observability")),isLoading:t}},Vor=40,Uor="",Ppe=e=>new Date(e.createdAt).getTime(),qor=(e,t)=>Ppe(e)-Ppe(t),sK=({threadId:e,agentId:t,memory:n,requestContext:r,queryOptions:s})=>{const i=Ye();return Mm({queryKey:["memory","messages",e,t,r],initialPageParam:Uor,queryFn:n&&e?({pageParam:o})=>i.listThreadMessages(e,{agentId:t,requestContext:r,includeSystemReminders:!0,perPage:Vor,orderBy:{field:"createdAt",direction:"DESC"},filter:o?{dateRange:{end:new Date(o)}}:void 0}):$0,getNextPageParam:(o,l,c)=>{if(!o.hasMore||o.messages.length===0)return;const u=new Date(Math.min(...o.messages.map(Ppe))).toISOString();return u===c?void 0:u},select:o=>{const l=new Set,c=o.pages.flatMap(u=>u.messages).filter(u=>l.has(u.id)?!1:(l.add(u.id),!0)).sort(qor);return{...o,messages:c}},staleTime:0,gcTime:0,retry:!1,refetchOnWindowFocus:!1,...s})};function Qor({agentId:e,path:t,agentVersionId:n,requestContext:r,queryOptions:s}){const i=Ye();return _t({queryKey:["agent-plan",e,n,t,r],queryFn:()=>(n?i.getAgent(e,{versionId:n}):i.getAgent(e)).readPlan(t,r),retry:!1,...s})}const Zor={"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 Wor(e={}){const{enabled:t=!0,agentId:n,runId:r,threadId:s,resourceId:i,taskId:o}=e,l=Ye(),[c,u]=g.useState({}),[d,f]=g.useState(!1),[h,p]=g.useState(null),m=g.useRef(null),v=g.useRef(null),y=g.useRef(0),x=g.useMemo(()=>Object.values(c).filter(N=>N.status==="running"),[c]),b=g.useMemo(()=>Object.values(c).filter(N=>N.status==="completed"),[c]),S=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)},[]),j=g.useCallback(async()=>{const N=++y.current;k(),p(null);const I=new AbortController;m.current=I;try{const A=await l.streamBackgroundTasks({agentId:n,runId:r,threadId:s,resourceId:i,taskId:o});if(!A){p(new Error("Stream connection failed"));return}N===y.current&&f(!0);const P=A.getReader();for(v.current=P;!I.signal.aborted;){const{done:D,value:F}=await P.read();if(D)break;const Q=F;Q.type!=="background-task-output"&&u(q=>({...q,[Q.payload.taskId]:{...q[Q.payload.taskId],...Q.payload,status:Zor[Q.type],args:("args"in Q.payload?Q.payload.args:void 0)??q[Q.payload.taskId]?.args??{}}}))}}catch(A){A?.name!=="AbortError"&&N===y.current&&p(A instanceof Error?A:new Error(String(A)))}finally{N===y.current&&f(!1)}},[l,n,r,s,i,o,k]);g.useEffect(()=>{if(!t){k();return}return j(),k},[t,j,k]);const C=g.useCallback(()=>{k()},[k]),T=g.useCallback(()=>{j()},[j]);return{tasks:c,isConnected:d,error:h,disconnect:C,reconnect:T,runningTasks:x,completedTasks:b,failedTasks:S,clearCompletedAndFailedTasks:()=>{u(N=>{const I={...N};return Object.values(I).forEach(A=>{(A.status==="completed"||A.status==="failed"||A.status==="cancelled"||A.status==="timed_out")&&delete I[A.taskId]}),I})}}}const Hor=({backgroundTaskId:e,queryOptions:t})=>{const n=Ye();return _t({queryKey:["background-task",e],queryFn:()=>n.getBackgroundTask(e),...t})},Gor=(e,t)=>["browser-session-probe",e,t],Kor={hasSession:!0,screencastAvailable:!0},Yor=e=>!e||typeof e!="object"?!1:"status"in e&&e.status===404||"statusCode"in e&&e.statusCode===404;function Xor({agentId:e,threadId:t,queryOptions:n}){const r=Ye();return _t({queryKey:Gor(e,t),queryFn:async()=>{if(!e)return{hasSession:!1,screencastAvailable:!1};try{return await r.getAgent(e).browserSession(t)}catch(s){if(Yor(s))return Kor;throw s}},refetchOnWindowFocus:!0,staleTime:0,retry:1,...n})}const Jor="MODEL_NOT_ALLOWED";function ear(e){if(!e||typeof e!="object")return null;const t=e;if(t.status!==422)return null;const n=t.body;if(n?.error?.code!==Jor)return null;const r=n.error;return{message:r.message||t.message||"Model not allowed by admin policy",attempted:r.attempted,offendingLabel:r.offendingLabel}}const EC=({queryOptions:e,...t}={})=>{const n=Ye(),r=Object.keys(t).length>0?t:void 0;return _t({queryKey:["stored-agents",r],queryFn:()=>n.listStoredAgents(r),...e})},iK=({agentId:e,status:t,requestContext:n,queryOptions:r}={})=>{const s=Ye();return _t({queryKey:["stored-agent",e,t,n],queryFn:async()=>{if(!e)return null;try{return await s.getStoredAgent(e).details(n,{status:t})}catch(i){if(i&&typeof i=="object"&&"status"in i&&i.status===404)return null;throw i}},retry:!1,...r})},hke=({agentId:e,requestContext:t,queryOptions:n}={})=>{const r=Ye();return _t({queryKey:["stored-agent-dependents",e,t],queryFn:()=>r.getStoredAgent(e).dependents(t),retry:!1,...n})},IC=({agentId:e,requestContext:t,queryOptions:n}={})=>{const r=Ye(),s=mr(),i=o=>{ear(o)&&s.invalidateQueries({queryKey:["builder-settings"]})};return{createStoredAgent:kn({mutationFn:o=>r.createStoredAgent(o),onSuccess:o=>{s.setQueryData(["stored-agent",o.id,"draft",t],o),s.setQueryData(["stored-agent",o.id,void 0,t],o),s.invalidateQueries({queryKey:["stored-agents"]}),s.invalidateQueries({queryKey:["agents"]}),s.invalidateQueries({queryKey:["agent",o.id]})},onError:i,...n?.createStoredAgent}),updateStoredAgent:kn({mutationFn:o=>{if(!e)throw new Error("agentId is required for update");return r.getStoredAgent(e).update(o,t)},onSuccess:()=>{s.invalidateQueries({queryKey:["stored-agents"]}),s.invalidateQueries({queryKey:["agents"]}),e&&(s.invalidateQueries({queryKey:["stored-agent",e]}),s.invalidateQueries({queryKey:["agent",e]}))},onError:i,...n?.updateStoredAgent}),deleteStoredAgent:kn({mutationFn:()=>{if(!e)throw new Error("agentId is required for delete");return r.getStoredAgent(e).delete(t)},onSuccess:()=>{s.invalidateQueries({queryKey:["stored-agents"]}),s.invalidateQueries({queryKey:["agents"]}),e&&(s.removeQueries({queryKey:["stored-agent",e]}),s.removeQueries({queryKey:["agent",e]}))},...n?.deleteStoredAgent})}},zL=({agentId:e,params:t,requestContext:n,queryOptions:r})=>{const s=Ye();return _t({queryKey:["agent-versions",e,t,n],queryFn:e?()=>s.getStoredAgent(e).listVersions(t,n):$0,...r})},ckt=({agentId:e,versionId:t,requestContext:n,queryOptions:r})=>{const s=Ye();return _t({queryKey:["agent-version",e,t,n],queryFn:()=>s.getStoredAgent(e).getVersion(t,n),...r})},tar=({agentId:e,fromVersionId:t,toVersionId:n,requestContext:r,queryOptions:s})=>{const i=Ye();return _t({queryKey:["agent-versions-compare",e,t,n,r],queryFn:()=>i.getStoredAgent(e).compareVersions(t,n,r),...s})};function JBe(e){try{return JSON.stringify(JSON.parse(e),null,2)}catch{return e}}function nar(e,t,n,r){const s=Ye(),[i,o]=g.useState(!1),[l,c]=g.useState(null),[u,d]=g.useState("thread"),[f,h]=g.useState("markdown"),[p,m]=g.useState(!0),[v,y]=g.useState(!1),x=g.useRef(0),b=g.useCallback(async()=>{const k=++x.current;m(!0);try{if(!e||!t){c(null),m(!1);return}const j=await s.getWorkingMemory({agentId:e,threadId:t,resourceId:n,requestContext:r});if(k!==x.current)return;const{workingMemory:C,source:T,workingMemoryTemplate:_,threadExists:N}=j;if(o(N),c(C),d(T),h(_?.format||"markdown"),_?.format==="json"){let I="";C?I=JBe(C):_?.content?I=JBe(_.content):I="",c(I)}else c(C||_?.content||"")}catch(j){if(k!==x.current)return;c(null),console.error("Error fetching working memory",j)}finally{k===x.current&&m(!1)}},[e,t,n,s,r]);return g.useEffect(()=>{b()},[b]),{threadExists:i,workingMemoryData:l,workingMemorySource:u,workingMemoryFormat:f,isLoading:p,isUpdating:v,refetch:b,updateWorkingMemory:async k=>{y(!0);try{if(f==="json")try{JSON.parse(k)}catch{throw new Error("Invalid JSON working memory")}await s.updateWorkingMemory({agentId:e,threadId:t,workingMemory:k,resourceId:n,requestContext:r}),b()}catch(j){throw console.error("Error updating working memory",j),j}finally{y(!1)}}}}const yd=({agentId:e,requestContext:t,queryOptions:n}={})=>{const r=Ye();return _t({queryKey:["agent",e,t],queryFn:()=>e?r.getAgent(e).details(t):null,retry:!1,...n})},ch=({requestContext:e,queryOptions:t}={})=>{const n=Ye();return _t({queryKey:["agents",e],queryFn:()=>n.listAgents(e),...t})},rar=({agentId:e,queryOptions:t})=>{const n=Ye(),r=mr();return kn({mutationFn:async s=>n.getAgent(e).reorderModelList(s),onSuccess:()=>{r.invalidateQueries({queryKey:["agent",e]})},onError:s=>{console.error("Error reordering model list",s)},...t})},sar=({agentId:e,queryOptions:t})=>{const n=Ye(),r=mr();return kn({mutationFn:async s=>n.getAgent(e).updateModelInModelList(s),onSuccess:()=>{r.invalidateQueries({queryKey:["agent",e]})},onError:s=>{console.error("Error updating model in model list",s)},...t})};function iar({queryOptions:e}={}){const t=Ye();return kn({mutationFn:({agentId:n,threadId:r})=>t.getAgent(n).closeBrowser(r),onError:n=>{console.error("[useCloseBrowser] Error closing browser:",n)},...e})}function wk({queryOptions:e}={}){const t=Ye();return _t({queryKey:["stored-skills"],queryFn:()=>t.listStoredSkills(),...e})}const FL=({queryOptions:e}={})=>{const t=Ye();return _t({queryKey:["channels","platforms"],queryFn:()=>t.channels.listPlatforms(),staleTime:60*1e3,retry:!1,...e})},ukt=({platform:e,agentId:t,queryOptions:n})=>{const r=Ye();return _t({queryKey:["channels","installations",e,t],queryFn:()=>r.channels.listInstallations(e,t),staleTime:10*1e3,retry:!1,...n})},oar=({platform:e,queryOptions:t})=>{const n=Ye(),r=mr();return kn({mutationFn:s=>n.channels.reconcileInstallation(e,s),onSuccess:()=>{r.invalidateQueries({queryKey:["channels","installations",e]})},...t})},aar=({platform:e,queryOptions:t})=>{const n=Ye(),r=mr();return kn({mutationFn:({agentId:s,options:i})=>n.channels.connect(e,s,{...i,redirectUrl:window.location.href}),onSuccess:()=>{r.invalidateQueries({queryKey:["channels","installations",e]})},...t})},dkt=({platform:e,queryOptions:t})=>{const n=Ye(),r=mr();return kn({mutationFn:s=>n.channels.disconnect(e,s),onSuccess:()=>{r.invalidateQueries({queryKey:["channels","installations",e]})},...t})},lar=({queryOptions:e}={})=>{const t=Ye();return kn({mutationFn:async({agentId:n,toolId:r,input:s,playgroundRequestContext:i})=>{const o=new t_;return Object.entries(i??{}).forEach(([l,c])=>{o.set(l,c)}),t.getAgent(n).executeTool(r,{data:s,requestContext:o})},...e})};function car({value:e,onValueChange:t,placeholder:n="Select an agent...",searchPlaceholder:r="Search agents...",emptyText:s="No agents found.",className:i,disabled:o=!1,variant:l,size:c,"aria-label":u,align:d}){const{data:f={},isLoading:h,isError:p,error:m}=ch(),{navigate:v,paths:y}=xn();g.useEffect(()=>{if(p){const S=m instanceof Error?m.message:"Failed to load agents";Ke.error(`Error loading agents: ${S}`)}},[p,m]);const x=Object.keys(f).map(S=>({label:f[S]?.name||S,value:S})),b=S=>{t?t(S):S&&S!==e&&v(y.agentLink(S))};return a.jsx(Qa,{options:x,value:e,onValueChange:b,placeholder:h?"Loading agents...":n,searchPlaceholder:r,emptyText:s,className:i,disabled:o||h||p,variant:l,size:c,"aria-label":u,align:d})}function uar(){const{agentId:e}=jr(),{data:t,isLoading:n}=ch();return e?n?a.jsx(Nx,{}):t?.[e]?.name||e:null}function dar(){const{agentId:e}=jr();return e?a.jsx(car,{value:e,...EP,"aria-label":"Switch agent"}):null}const fkt=({datasetId:e,itemId:t,queryOptions:n})=>{const r=Ye();return _t({queryKey:["dataset-item",e,t],queryFn:()=>r.getDatasetItem(e,t),retry:!1,...n})},eVe=10,JN=({datasetId:e,search:t,version:n,orderBy:r,queryOptions:s})=>{const i=Ye(),{inView:o,setRef:l}=F0(),c=Mm({queryKey:["dataset-items",e,t,n,r],queryFn:async({pageParam:f})=>await i.listDatasetItems(e,{page:f,perPage:eVe,search:t||void 0,version:n||void 0,orderBy:r}),initialPageParam:0,getNextPageParam:(f,h,p)=>{if(f?.items?.length&&!((p+1)*eVe>=(f?.pagination?.total??0)))return p+1},retry:!1,...s}),u=c.data?.pages.flatMap(f=>f?.items??[])??[],d=c.data?.pages[0]?.pagination?.total;return g.useEffect(()=>{o&&c.hasNextPage&&!c.isFetchingNextPage&&c.fetchNextPage()},[o,c]),{...c,data:u,total:d,setEndOfListElement:l}},pl=({queryOptions:e}={})=>{const t=Ye(),n=mr(),r=kn({mutationFn:h=>t.createDataset(h),onSuccess:()=>{n.invalidateQueries({queryKey:["datasets"]})},...e?.createDataset}),s=kn({mutationFn:h=>t.updateDataset(h),onSuccess:(h,p)=>{n.invalidateQueries({queryKey:["datasets"]}),n.invalidateQueries({queryKey:["dataset",p.datasetId]})},...e?.updateDataset}),i=kn({mutationFn:h=>t.deleteDataset(h),onSuccess:()=>{n.invalidateQueries({queryKey:["datasets"]})},...e?.deleteDataset}),o=kn({mutationFn:h=>t.addDatasetItem(h),onSuccess:(h,p)=>{n.invalidateQueries({queryKey:["dataset-items",p.datasetId]}),n.invalidateQueries({queryKey:["dataset",p.datasetId]}),n.invalidateQueries({queryKey:["dataset-versions",p.datasetId]})},...e?.addItem}),l=kn({mutationFn:h=>t.updateDatasetItem(h),onSuccess:(h,p)=>{n.invalidateQueries({queryKey:["dataset-items",p.datasetId]}),n.invalidateQueries({queryKey:["dataset-item",p.datasetId,p.itemId]}),n.invalidateQueries({queryKey:["dataset-item-versions",p.datasetId,p.itemId]}),n.invalidateQueries({queryKey:["dataset-versions",p.datasetId]})},...e?.updateItem}),c=kn({mutationFn:({datasetId:h,itemId:p})=>t.deleteDatasetItem(h,p),onSuccess:(h,p)=>{n.invalidateQueries({queryKey:["dataset-items",p.datasetId]}),n.invalidateQueries({queryKey:["dataset",p.datasetId]}),n.invalidateQueries({queryKey:["dataset-versions",p.datasetId]})},...e?.deleteItem}),u=kn({mutationFn:({datasetId:h,itemId:p})=>t.purgeDatasetItem(h,p),onSuccess:(h,p)=>{n.invalidateQueries({queryKey:["dataset-items",p.datasetId]}),n.invalidateQueries({queryKey:["dataset-item",p.datasetId,p.itemId]}),n.invalidateQueries({queryKey:["dataset-item-versions",p.datasetId,p.itemId]}),n.invalidateQueries({queryKey:["dataset-experiment-results"]}),n.invalidateQueries({queryKey:["experiment-results"]}),n.invalidateQueries({queryKey:["review-items"]}),n.invalidateQueries({queryKey:["dataset-review-items"]}),n.invalidateQueries({queryKey:["dataset-completed-items"]}),n.invalidateQueries({queryKey:["experiment-review-summary"]})},...e?.purgeItem}),d=kn({mutationFn:h=>t.batchInsertDatasetItems(h),onSuccess:(h,p)=>{n.invalidateQueries({queryKey:["dataset-items",p.datasetId]}),n.invalidateQueries({queryKey:["dataset",p.datasetId]}),n.invalidateQueries({queryKey:["dataset-versions",p.datasetId]})},...e?.batchInsertItems}),f=kn({mutationFn:h=>t.batchDeleteDatasetItems(h),onSuccess:(h,p)=>{n.invalidateQueries({queryKey:["dataset-items",p.datasetId]}),n.invalidateQueries({queryKey:["dataset",p.datasetId]}),n.invalidateQueries({queryKey:["dataset-versions",p.datasetId]})},...e?.batchDeleteItems});return{createDataset:r,updateDataset:s,deleteDataset:i,addItem:o,updateItem:l,deleteItem:c,purgeItem:u,deleteItems:kn({mutationFn:async({datasetId:h,itemIds:p})=>t.batchDeleteDatasetItems({datasetId:h,itemIds:p}),onSuccess:(h,p)=>{n.invalidateQueries({queryKey:["dataset-items",p.datasetId]}),n.invalidateQueries({queryKey:["dataset",p.datasetId]}),n.invalidateQueries({queryKey:["dataset-versions",p.datasetId]})},...e?.deleteItems}),batchInsertItems:d,batchDeleteItems:f,triggerExperiment:kn({mutationFn:h=>t.triggerDatasetExperiment(h),onSuccess:(h,p)=>{n.invalidateQueries({queryKey:["dataset-experiments",p.datasetId]})},...e?.triggerExperiment}),deleteExperiment:kn({mutationFn:h=>t.deleteExperiment(h),onSuccess:()=>{n.invalidateQueries({queryKey:["experiments"]}),n.invalidateQueries({queryKey:["dataset-experiments"]}),n.invalidateQueries({queryKey:["dataset-experiment"]}),n.invalidateQueries({queryKey:["dataset-experiment-results"]}),n.invalidateQueries({queryKey:["review-items"]}),n.invalidateQueries({queryKey:["completed-items"]}),n.invalidateQueries({queryKey:["experiment-review-summary"]})},...e?.deleteExperiment}),updateExperiment:kn({mutationFn:h=>t.updateDatasetExperiment(h),onSuccess:(h,p)=>{n.invalidateQueries({queryKey:["experiments"]}),n.invalidateQueries({queryKey:["dataset-experiments",p.datasetId]}),n.invalidateQueries({queryKey:["dataset-experiment",p.datasetId,p.experimentId]})},...e?.updateExperiment}),updateExperimentResult:kn({mutationFn:h=>t.updateDatasetExperimentResult(h),onSuccess:(h,p)=>{n.invalidateQueries({queryKey:["experiment-results",p.experimentId]}),n.invalidateQueries({queryKey:["dataset-experiment-results"]}),n.invalidateQueries({queryKey:["review-items"]}),n.invalidateQueries({queryKey:["dataset-review-items"]}),n.invalidateQueries({queryKey:["dataset-completed-items"]}),n.invalidateQueries({queryKey:["experiment-review-summary"]})},...e?.updateExperimentResult})}},Sk=({pagination:e,queryOptions:t}={})=>{const n=Ye();return _t({queryKey:["datasets",e],queryFn:()=>n.listDatasets(e),placeholderData:r=>r,...t})},far=20,har=({filter:e,orderBy:t,queryOptions:n}={})=>{const r=Ye(),{inView:s,setRef:i}=F0(),o=e?.targetType||void 0,l=e?.targetId?[e.targetId]:void 0,c=Mm({queryKey:["datasets","infinite",{targetType:o,targetIds:l,orderBy:t}],queryFn:({pageParam:u})=>r.listDatasets({page:u,perPage:far,targetType:o,targetIds:l,orderBy:t}),initialPageParam:0,getNextPageParam:(u,d,f)=>{if(!(!u?.datasets?.length||!u.pagination?.hasMore))return f+1},select:u=>u.pages.flatMap(d=>d?.datasets??[]),...n});return g.useEffect(()=>{s&&c.hasNextPage&&!c.isFetchingNextPage&&c.fetchNextPage()},[s,c]),{...c,setEndOfListElement:i}},Mv=({datasetId:e,queryOptions:t})=>{const n=Ye();return _t({queryKey:["dataset",e],queryFn:()=>n.getDataset(e),...t})},par=({datasetId:e,experimentIdA:t,experimentIdB:n,options:r,queryOptions:s})=>{const i=Ye();return _t({queryKey:["compare-experiments",e,t,n,r],queryFn:()=>i.compareExperiments({datasetId:e,experimentIdA:t,experimentIdB:n,...r}),...s})},g5=({datasetId:e,experimentId:t,queryOptions:n})=>{const r=Ye();return _t({queryKey:["dataset-experiment",e,t],queryFn:()=>r.getDatasetExperiment(e,t),gcTime:0,staleTime:0,refetchInterval:s=>{const i=s.state.data?.status;return i==="running"||i==="pending"?2e3:!1},...n})},tVe=100,$pe=({datasetId:e,experimentId:t,experimentStatus:n,orderBy:r,queryOptions:s})=>{const i=Ye(),{inView:o,setRef:l}=F0(),c=Mm({queryKey:["dataset-experiment-results",e,t,n,r],queryFn:async({pageParam:u})=>i.listDatasetExperimentResults(e,t,{page:u,perPage:tVe,orderBy:r}),initialPageParam:0,getNextPageParam:(u,d,f)=>{if(u?.results?.length&&!((f+1)*tVe>=(u?.pagination?.total??0)))return f+1},refetchInterval:n==="running"||n==="pending"?2e3:!1,select:u=>u.pages.flatMap(d=>d?.results??[]),...s});return g.useEffect(()=>{o&&c.hasNextPage&&!c.isFetchingNextPage&&c.fetchNextPage()},[o,c]),{...c,setEndOfListElement:l}},AS=({experimentId:e,experimentStatus:t,queryOptions:n})=>{const r=Ye();return _t({queryKey:["dataset-experiment-scores",e,t],queryFn:async()=>{const s=[];let i=0;const o=100;for(;;){const c=await r.listScoresByRunId({runId:e,page:i,perPage:o});if(s.push(...c.scores),!c.pagination.hasMore)break;i++}const l={};for(const c of s)l[c.entityId]||(l[c.entityId]=[]),l[c.entityId].push(c);return l},refetchInterval:t==="running"||t==="pending"?2e3:!1,...n})},mar=({datasetId:e,itemId:t,queryOptions:n})=>{const r=Ye();return _t({queryKey:["dataset-item-versions",e,t],queryFn:async()=>((await r.getItemHistory(e,t))?.history??[]).map((s,i)=>({id:s.id,datasetId:s.datasetId,datasetVersion:s.datasetVersion,input:s.input,groundTruth:s.groundTruth,expectedTrajectory:s.expectedTrajectory,toolMocks:s.toolMocks??void 0,scorerIds:s.scorerIds??void 0,requestContext:s.requestContext??void 0,metadata:s.metadata??void 0,validTo:s.validTo,isDeleted:s.isDeleted,createdAt:s.createdAt,updatedAt:s.updatedAt,isLatest:i===0})),...n})},gar=({datasetId:e,itemId:t,datasetVersion:n,latestVersion:r,queryOptions:s})=>{const i=Ye();return _t({queryKey:["dataset-item-version",e,t,n],queryFn:async()=>{const o=await i.getDatasetItemVersion(e,t,n);return{id:o.id,datasetId:o.datasetId,datasetVersion:o.datasetVersion,input:o.input,groundTruth:o.groundTruth,expectedTrajectory:o.expectedTrajectory,toolMocks:o.toolMocks??void 0,scorerIds:o.scorerIds??void 0,requestContext:o.requestContext??void 0,metadata:o.metadata??void 0,validTo:null,isDeleted:!1,createdAt:o.createdAt,updatedAt:o.updatedAt,isLatest:r!=null?n===r:!1}},...s})},yar=10,hkt=({datasetId:e,queryOptions:t})=>{const n=Ye();return Mm({queryKey:["dataset-versions",e],queryFn:async({pageParam:r})=>n.listDatasetVersions(e,{page:r,perPage:yar}),initialPageParam:0,getNextPageParam:(r,s,i)=>{if(r?.pagination?.hasMore)return i+1},select:r=>r.pages.flatMap(s=>s?.versions??[]).map((s,i)=>({id:s.id,datasetId:s.datasetId,version:s.version,createdAt:s.createdAt,isCurrent:i===0})),...t})},pke=({pagination:e,queryOptions:t}={})=>{const n=Ye();return _t({queryKey:["experiments",e],queryFn:()=>n.listExperiments(e),...t})};function xar({workflowId:e,queryOptions:t}){const n=Ye();return _t({queryKey:["workflow-schema",e],queryFn:async()=>{if(!e)throw new Error("No workflow selected");return n.getWorkflow(e).getSchema()},staleTime:300*1e3,...t})}function pkt({value:e,onValueChange:t,placeholder:n="Select a dataset...",searchPlaceholder:r="Search datasets...",emptyText:s="No datasets found.",className:i,disabled:o=!1,variant:l,size:c,"aria-label":u,align:d,container:f}){const{data:h,isLoading:p,isError:m,error:v}=Sk(),{navigate:y,paths:x}=xn();g.useEffect(()=>{if(m){const j=v instanceof Error?v.message:"Failed to load datasets";Ke.error(`Error loading datasets: ${j}`)}},[m,v]);const S=(h?.datasets??[]).map(j=>({label:j.name,value:j.id})),k=j=>{t?t(j):j&&j!==e&&y(x.datasetLink(j))};return a.jsx(Qa,{options:S,value:e,onValueChange:k,placeholder:p?"Loading datasets...":n,searchPlaceholder:r,emptyText:s,className:i,disabled:o||p||m,variant:l,size:c,"aria-label":u,align:d,container:f})}function bar(){const{datasetId:e}=jr(),{data:t,isLoading:n}=Sk();return e?n?a.jsx(Nx,{}):t?.datasets?.find(r=>r.id===e)?.name??e:null}function war(){const{datasetId:e}=jr();return e?a.jsx(pkt,{value:e,...EP,"aria-label":"Switch dataset"}):null}const Sar=({serverId:e,appResourceUri:t,queryOptions:n})=>{const r=Ye();return _t({queryKey:["mcp-app-resource",e,t],queryFn:async()=>t?(await r.readMcpServerResource(e,t)).contents[0]?.text??null:null,enabled:t!==void 0,...n})};function mkt({queryOptions:e}={}){const t=Ye();return _t({queryKey:["mcp-app-tools"],queryFn:async()=>{const n={},{servers:r}=await t.getMcpServers();if(!r?.length)return n;const s=await Promise.allSettled(r.map(async i=>{const{tools:o}=await t.getMcpServerTools(i.id);return{serverId:i.id,tools:o}}));for(const i of s){if(i.status!=="fulfilled")continue;const{serverId:o,tools:l}=i.value;for(const c of l){const u=c._meta?.ui?.resourceUri;if(u){const d=c.name,f={serverId:o,toolId:d,toolName:c.name,resourceUri:u};n[d]=f,c.name!==d&&(n[c.name]=f),n[`${o}_${c.name}`]=f}}}return n},staleTime:6e4,refetchOnWindowFocus:!1,...e})}const kar=({serverId:e,toolId:t,requestContext:n,queryOptions:r})=>{const s=Ye();return _t({queryKey:["mcp-server-tool",e,t],queryFn:()=>s.getMcpServerTool(e,t).details(n),...r})},Oar=({serverId:e,toolId:t,queryOptions:n})=>{const r=Ye();return kn({mutationFn:({data:s,requestContext:i})=>r.getMcpServerTool(e,t).execute({data:s,requestContext:i}),...n})},gkt=({selectedServer:e,queryOptions:t})=>{const n=Ye();return _t({queryKey:["mcpserver-tools",e?.id],queryFn:async()=>{const r=(await n.getMcpServerTools(e?.id)).tools,s={};return r.forEach(i=>{s[i.name]=i}),s},retry:!1,refetchOnWindowFocus:!1,...t})},NP=({requestContext:e,queryOptions:t}={})=>{const n=Ye();return _t({queryKey:["mcp-servers"],queryFn:async()=>(await n.getMcpServers(e)).servers,...t})};async function nVe(e){if((e.headers.get("content-type")??"").includes("text/event-stream")){const t=(await e.text()).split(`
|
|
257
|
-
`);for(const n of t)if(n.startsWith("data:")){const r=n.slice(5).trim();if(r)return JSON.parse(r)}throw new Error("No data found in SSE response")}return e.json()}async function jar(e,t){const n={...t,"Content-Type":"application/json",Accept:"application/json, text/event-stream"},r=await fetch(e,{method:"POST",headers:n,credentials:"include",body:JSON.stringify({jsonrpc:"2.0",id:1,method:"initialize",params:{protocolVersion:"2025-03-26",capabilities:{},clientInfo:{name:"mastra-playground",version:"1.0.0"}}})});if(!r.ok)throw new Error(`Initialize failed: ${r.status} ${r.statusText}`);const s=r.headers.get("Mcp-Session-Id");await nVe(r);const i={...n};s&&(i["Mcp-Session-Id"]=s),await fetch(e,{method:"POST",headers:i,credentials:"include",body:JSON.stringify({jsonrpc:"2.0",method:"notifications/initialized"})});const o=await fetch(e,{method:"POST",headers:i,credentials:"include",body:JSON.stringify({jsonrpc:"2.0",id:2,method:"tools/list"})});if(!o.ok)throw new Error(`tools/list failed: ${o.status} ${o.statusText}`);return{tools:(await nVe(o)).result?.tools??[]}}const Car=({queryOptions:e}={})=>{const t=Ye().options?.headers??{};return kn({mutationFn:n=>jar(n,t),...e})};function vkt({value:e,onValueChange:t,placeholder:n="Select an MCP server...",searchPlaceholder:r="Search MCP servers...",emptyText:s="No MCP servers found.",className:i,disabled:o=!1,variant:l,size:c,"aria-label":u,align:d,container:f}){const{data:h=[],isLoading:p,isError:m,error:v}=NP(),{navigate:y,paths:x}=xn();g.useEffect(()=>{if(m){const k=v instanceof Error?v.message:"Failed to load MCP servers";Ke.error(`Error loading MCP servers: ${k}`)}},[m,v]);const b=h.map(k=>({label:k.name,value:k.id})),S=k=>{t?t(k):k&&k!==e&&y(x.mcpServerLink(k))};return a.jsx(Qa,{options:b,value:e,onValueChange:S,placeholder:p?"Loading MCP servers...":n,searchPlaceholder:r,emptyText:s,className:i,disabled:o||p||m,variant:l,size:c,"aria-label":u,align:d,container:f})}function _ar(){const{serverId:e}=jr(),{data:t,isLoading:n}=NP();return e?n?a.jsx(Nx,{}):t?.find(r=>r.id===e)?.name||e:null}function Tar(){const{serverId:e}=jr();return e?a.jsx(vkt,{value:e,...EP,"aria-label":"Switch MCP server"}):null}const E_=({requestContext:e,queryOptions:t}={})=>{const n=Ye();return _t({queryKey:["processors"],queryFn:()=>n.listProcessors(e),...t})},ykt=({processorId:e,requestContext:t,queryOptions:n})=>{const r=Ye();return _t({queryKey:["processor",e],queryFn:()=>r.getProcessor(e).details(t),...n})},Ear=({requestContext:e,queryOptions:t}={})=>{const n=Ye();return kn({mutationFn:async({processorId:r,phase:s,messages:i,agentId:o})=>n.getProcessor(r).execute({phase:s,messages:i,agentId:o,requestContext:e}),...t})};function Iar({value:e,onValueChange:t,placeholder:n="Select a processor...",searchPlaceholder:r="Search processors...",emptyText:s="No processors found.",className:i,disabled:o=!1,variant:l,size:c,"aria-label":u,align:d}){const{data:f={},isLoading:h,isError:p,error:m}=E_(),{navigate:v,paths:y}=xn();g.useEffect(()=>{if(p){const S=m instanceof Error?m.message:"Failed to load processors";Ke.error(`Error loading processors: ${S}`)}},[p,m]);const x=Object.keys(f).filter(S=>{const k=f[S];return k?.phases&&k.phases.length>0}).map(S=>({label:f[S]?.name||S,value:S})),b=S=>{t?t(S):S&&S!==e&&(f[S]?.isWorkflow?v(y.workflowLink(S)+"/graph"):v(y.processorLink(S)))};return a.jsx(Qa,{options:x,value:e,onValueChange:b,placeholder:h?"Loading processors...":n,searchPlaceholder:r,emptyText:s,className:i,disabled:o||h||p,variant:l,size:c,"aria-label":u,align:d})}function Nar(){const{processorId:e}=jr(),{data:t,isLoading:n}=E_();return e?n?a.jsx(Nx,{}):t?.[e]?.name||e:null}function Aar(){const{processorId:e}=jr();return e?a.jsx(Iar,{value:e,...EP,"aria-label":"Switch processor"}):null}const Eoe=[400,401,403,404,501];function js(e){if(!e||typeof e!="object")return!1;if("status"in e&&e.status===401||"statusCode"in e&&e.statusCode===401)return!0;if("message"in e){const t=e.message;if(typeof t=="string")return/\bstatus:\s*401\b/.test(t)}return!1}function Cs(e){if(!e||typeof e!="object")return!1;if("status"in e&&e.status===403||"statusCode"in e&&e.statusCode===403)return!0;if("message"in e){const t=e.message;if(typeof t=="string")return/\bstatus:\s*403\b/.test(t)}return!1}function kk(e){if(!e||typeof e!="object")return!1;if("status"in e&&e.status===404||"statusCode"in e&&e.statusCode===404)return!0;if("message"in e){const t=e.message;if(typeof t=="string")return/\bstatus:\s*404\b/.test(t)}return!1}function BL(e,t){if(!e||typeof e!="object"||!("message"in e))return!1;const n=e.message;return typeof n!="string"?!1:n.includes(`does not support listing ${t}`)}const Par=["Observability storage domain is not available","Scores storage domain is not available"];function VL(e){if(!e||typeof e!="object"||!("message"in e))return!1;const t=e.message;return typeof t!="string"?!1:Par.some(n=>t.includes(n))}function xkt(e){if(!e||typeof e!="object")return!1;if("status"in e){const t=e.status;return Eoe.includes(t)}if("statusCode"in e){const t=e.statusCode;return Eoe.includes(t)}if("message"in e){const t=e.message;if(typeof t=="string")return Eoe.some(n=>new RegExp(`\\bstatus:\\s*${n}\\b`).test(t))}return!1}function $ar(e,t){return xkt(t)?!1:e<3}const Rar=25,Mar=15e3;function Dar(e){return BL(e.state.error,"scores")||VL(e.state.error)?!1:Mar}function Lar(e,t,n){if(e?.pagination?.hasMore)return n+1}function zar(e){const t=new Set;return e.pages.flatMap(n=>n.scores??[]).filter(n=>t.has(n.id)?!1:(t.add(n.id),!0))}const Far=({scorerId:e,entityId:t,entityType:n,queryOptions:r})=>{const s=Ye(),{inView:i,setRef:o}=F0(),l=Mm({queryKey:["scores",e,t,n],queryFn:({pageParam:f})=>s.listScoresByScorerId({scorerId:e,page:f,perPage:Rar,entityId:t,entityType:n}),initialPageParam:0,getNextPageParam:Lar,select:f=>zar(f),refetchInterval:Dar,...r}),{hasNextPage:c,isFetchingNextPage:u,fetchNextPage:d}=l;return g.useEffect(()=>{i&&c&&!u&&d()},[i,c,u,d]),{...l,setEndOfListElement:o}},Bar=e=>{const t=Ye(),[n,r]=g.useState(null),[s,i]=g.useState(!0),[o,l]=g.useState(null);return g.useEffect(()=>{(async()=>{i(!0),l(null);try{const u=await t.getScorer(e);r(u)}catch(u){r(null);const d=u instanceof Error?u:new Error("Error fetching scorer");l(d),console.error("Error fetching scorer",u)}finally{i(!1)}})()},[e,t]),{scorer:n,isLoading:s,error:o}},bkt=({requestContext:e,queryOptions:t}={})=>{const n=Ye();return _t({queryKey:["scorers",e],queryFn:()=>n.listScorers(e),staleTime:0,gcTime:0,...t})},Var=15e3;function Uar(e){return BL(e.state.error,"scores")||VL(e.state.error)?!1:Var}const mke=({traceId:e="",spanId:t="",page:n,queryOptions:r})=>{const s=Ye();return _t({queryKey:["trace-span-scores",e,t,n],queryFn:()=>s.listScoresBySpan({traceId:e,spanId:t,page:n||0,perPage:10}),refetchInterval:Uar,gcTime:0,staleTime:0,...r})},qar=({queryOptions:e}={})=>{const t=Ye();return kn({mutationFn:async({scorerName:n,traceId:r,spanId:s})=>await t.score({scorerName:n,targets:[{traceId:r,spanId:s}]}),...e})},wkt=({scorerId:e,status:t,requestContext:n,queryOptions:r}={})=>{const s=Ye();return _t({queryKey:["stored-scorer",e,t,n],queryFn:()=>e?s.getStoredScorer(e).details(n,{status:t}):null,...r})},Skt=({scorerId:e,requestContext:t,queryOptions:n}={})=>{const r=Ye(),s=mr();return{createStoredScorer:kn({mutationFn:i=>r.createStoredScorer(i),onSuccess:()=>{s.invalidateQueries({queryKey:["stored-scorers"]}),s.invalidateQueries({queryKey:["scorers"]})},...n?.createStoredScorer}),updateStoredScorer:kn({mutationFn:i=>{if(!e)throw new Error("scorerId is required for update");return r.getStoredScorer(e).update(i,t)},onSuccess:()=>{s.invalidateQueries({queryKey:["stored-scorers"]}),s.invalidateQueries({queryKey:["scorers"]}),e&&s.invalidateQueries({queryKey:["stored-scorer",e]})},...n?.updateStoredScorer}),deleteStoredScorer:kn({mutationFn:()=>{if(!e)throw new Error("scorerId is required for delete");return r.getStoredScorer(e).delete(t)},onSuccess:()=>{s.invalidateQueries({queryKey:["stored-scorers"]}),s.invalidateQueries({queryKey:["scorers"]}),e&&s.invalidateQueries({queryKey:["stored-scorer",e]})},...n?.deleteStoredScorer})}},kkt=({scorerId:e,params:t,requestContext:n,queryOptions:r})=>{const s=Ye();return _t({queryKey:["scorer-versions",e,t,n],queryFn:()=>s.getStoredScorer(e).listVersions(t,n),...r})},Qar=({scorerId:e,versionId:t,requestContext:n,queryOptions:r})=>{const s=Ye();return _t({queryKey:["scorer-version",e,t,n],queryFn:()=>s.getStoredScorer(e).getVersion(t,n),...r})},ag=(e,t)=>bkt({...e,requestContext:t});function Zar({value:e,onValueChange:t,placeholder:n="Select a scorer...",searchPlaceholder:r="Search scorers...",emptyText:s="No scorers found.",className:i,disabled:o=!1,variant:l,size:c,"aria-label":u,align:d}){const{data:f={},isLoading:h,isError:p,error:m}=ag(),{navigate:v,paths:y}=xn();g.useEffect(()=>{if(p){const S=m instanceof Error?m.message:"Failed to load scorers";Ke.error(`Error loading scorers: ${S}`)}},[p,m]);const x=Object.keys(f).map(S=>({label:f[S]?.scorer.config.name||S,value:S})),b=S=>{t?t(S):S&&S!==e&&v(y.scorerLink(S))};return a.jsx(Qa,{options:x,value:e,onValueChange:b,placeholder:h?"Loading scorers...":n,searchPlaceholder:r,emptyText:s,className:i,disabled:o||h||p,variant:l,size:c,"aria-label":u,align:d})}function War(){const{scorerId:e}=jr(),{data:t,isLoading:n}=ag();return e?n?a.jsx(Nx,{}):t?.[e]?.scorer.config.name||e:null}function Har(){const{scorerId:e}=jr();return e?a.jsx(Zar,{value:e,...EP,"aria-label":"Switch scorer"}):null}function Gar(){const{scorerId:e}=jr(),{data:t,isLoading:n}=wkt({scorerId:e,status:"draft",queryOptions:{enabled:!!e}});return e?n?a.jsx(Nx,{}):t?.name??"Scorer not found":null}const ko=e=>a.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 8.82265 8.51434",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:[a.jsx("path",{d:"M6.76646 6.16953C6.56909 6.10559 6.40521 5.96585 6.31087 5.78107C6.21653 5.5963 6.19945 5.38161 6.2634 5.18424C6.32735 4.98687 6.46708 4.82299 6.65186 4.72865C6.83663 4.63431 7.05132 4.61723 7.24869 4.68118C7.45933 4.74996 7.6849 4.75913 7.90043 4.70768C8.11596 4.65622 8.31306 4.54615 8.46992 4.38963C8.62678 4.23312 8.73729 4.03626 8.78921 3.82084C8.84114 3.60542 8.83246 3.37984 8.76414 3.16904C8.69582 2.95825 8.57052 2.77046 8.4021 2.62646C8.23368 2.48246 8.02871 2.38785 7.80986 2.35311C7.59101 2.31836 7.36681 2.34484 7.16208 2.4296C6.95734 2.51436 6.78004 2.6541 6.64979 2.83337C6.39274 3.18567 6.05613 3.47228 5.66736 3.66987C5.27858 3.86747 4.84864 3.97046 4.41254 3.97046C3.97643 3.97046 3.54649 3.86747 3.15772 3.66987C2.76895 3.47228 2.43234 3.18567 2.17528 2.83337C2.04528 2.65368 1.86807 2.51346 1.66329 2.42826C1.45852 2.34306 1.23415 2.3162 1.01505 2.35065C0.795944 2.3851 0.590648 2.47951 0.421892 2.62344C0.253137 2.76736 0.127507 2.95519 0.0589124 3.16611C-0.00968171 3.37703 -0.0185632 3.60282 0.0332514 3.81848C0.0850661 4.03414 0.195555 4.23125 0.352484 4.38799C0.509413 4.54472 0.706659 4.65497 0.92238 4.70652C1.1381 4.75808 1.36388 4.74892 1.57472 4.68007C1.77224 4.61634 1.98698 4.63369 2.1717 4.72829C2.35643 4.82289 2.49601 4.987 2.55973 5.18452C2.62346 5.38203 2.60611 5.59677 2.51151 5.7815C2.41691 5.96623 2.2528 6.10581 2.05528 6.16953C1.84456 6.23788 1.65684 6.36317 1.51288 6.53155C1.36893 6.69993 1.27434 6.90485 1.23959 7.12364C1.20483 7.34242 1.23126 7.56656 1.31596 7.77126C1.40065 7.97597 1.5403 8.15326 1.71948 8.28354C1.89865 8.41382 2.11036 8.49201 2.33121 8.50946C2.55205 8.52692 2.77342 8.48296 2.97083 8.38244C3.16825 8.28193 3.33402 8.12877 3.44981 7.93992C3.56561 7.75106 3.62692 7.53386 3.62697 7.31233C3.62697 7.10501 3.70933 6.90619 3.85592 6.7596C4.00251 6.613 4.20134 6.53065 4.40865 6.53065C4.61596 6.53065 4.81479 6.613 4.96138 6.7596C5.10797 6.90619 5.19033 7.10501 5.19033 7.31233C5.19027 7.53399 5.25152 7.75136 5.36731 7.94037C5.4831 8.12939 5.64892 8.2827 5.84642 8.38334C6.04392 8.48399 6.26541 8.52804 6.4864 8.51063C6.70738 8.49322 6.91924 8.41502 7.09854 8.28469C7.27785 8.15436 7.41761 7.97698 7.50237 7.77216C7.58713 7.56734 7.61359 7.34307 7.57882 7.12414C7.54404 6.90522 7.44939 6.70018 7.30534 6.53171C7.16128 6.36323 6.97344 6.23789 6.76257 6.16953H6.76646Z",fill:"currentColor"}),a.jsx("path",{d:"M4.41198 2.40337C5.07565 2.40337 5.61367 1.86536 5.61367 1.20168C5.61367 0.538012 5.07565 0 4.41198 0C3.74831 0 3.2103 0.538012 3.2103 1.20168C3.2103 1.86536 3.74831 2.40337 4.41198 2.40337Z",fill:"currentColor"})]}),gke=e=>a.jsx("svg",{width:"16",height:"16",viewBox:"0 0 8.64637 9.45103",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:a.jsx("path",{d:"M7.80735 5.87241C7.63209 5.97219 7.43696 6.06166 7.22844 6.13866C6.46456 6.42068 5.43714 6.58649 4.32296 6.58649C3.20873 6.58649 2.18135 6.4207 1.41747 6.13866C1.20889 6.06164 1.01385 5.97223 0.838558 5.87241V7.59003C0.838558 7.62341 0.855765 7.70759 1.00172 7.83512C1.14707 7.96201 1.38219 8.09563 1.70829 8.21605C2.3572 8.45563 3.28149 8.61268 4.32296 8.61269C5.36456 8.61269 6.28937 8.45568 6.9383 8.21605C7.26428 8.09566 7.49888 7.96198 7.64419 7.83512C7.79024 7.70754 7.80735 7.62342 7.80735 7.59003V5.87241ZM7.80735 3.00789C7.63214 3.10763 7.4369 3.19647 7.22844 3.27345C6.46455 3.55549 5.43719 3.72129 4.32296 3.72129C3.20868 3.72128 2.18136 3.55552 1.41747 3.27345C1.20896 3.19645 1.01381 3.10766 0.838558 3.00789V4.72551C0.838558 4.7589 0.855657 4.84301 1.00172 4.97059C1.14707 5.09749 1.38219 5.23111 1.70829 5.35153C2.3572 5.59109 3.28154 5.74747 4.32296 5.74748C5.36456 5.74748 6.28937 5.59116 6.9383 5.35153C7.26432 5.23112 7.49887 5.09747 7.64419 4.97059C7.7536 4.87505 7.79089 4.80404 7.80257 4.76033L7.80735 4.72551V3.00789ZM7.80735 1.86099C7.80735 1.82758 7.79045 1.74291 7.64419 1.61522C7.49887 1.48838 7.26421 1.35534 6.9383 1.23497C6.28937 0.995339 5.36456 0.838331 4.32296 0.838331C3.28149 0.83834 2.3572 0.995383 1.70829 1.23497C1.38219 1.35539 1.14707 1.48832 1.00172 1.61522C0.855475 1.7429 0.838558 1.82758 0.838558 1.86099C0.838673 1.89462 0.855968 1.97882 1.00172 2.10607C1.14707 2.23297 1.38219 2.3659 1.70829 2.48632C2.3572 2.7259 3.28149 2.88295 4.32296 2.88296C5.36456 2.88296 6.28937 2.72595 6.9383 2.48632C7.26421 2.36595 7.49887 2.23291 7.64419 2.10607C7.78996 1.97881 7.80724 1.89462 7.80735 1.86099ZM8.64637 7.59003C8.64637 7.95465 8.44458 8.25006 8.1958 8.46728C7.94608 8.68529 7.60876 8.86274 7.22844 9.00318C6.46455 9.28522 5.43718 9.45102 4.32296 9.45102C3.20869 9.45101 2.18135 9.28525 1.41747 9.00318C1.03715 8.86274 0.699831 8.68529 0.450113 8.46728C0.201377 8.25007 0.000227451 7.9546 0.000227451 7.59003V1.86099C0.000227451 1.49643 0.201388 1.20095 0.450113 0.983742C0.699831 0.765728 1.03715 0.588275 1.41747 0.447838C2.18136 0.165769 3.20868 8.74396e-06 4.32296 0C5.43719 0 6.46455 0.165797 7.22844 0.447838C7.60876 0.588275 7.94608 0.765728 8.1958 0.983742C8.44457 1.20096 8.64637 1.49638 8.64637 1.86099V7.59003Z",fill:"currentColor"})}),Kar=e=>a.jsx("svg",{width:"16",height:"16",viewBox:"0 0 9.83952 9.3295",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:a.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M7.67171 0.838331H6.70163V4.05307L9.68767 8.09999C10.0634 8.6093 9.69869 9.32932 9.06643 9.3295H0.772551C0.140289 9.3293 -0.223777 8.60929 0.151995 8.09999L3.13804 4.05307V0.838331H2.17136V0H7.67171V0.838331ZM3.97705 4.32955L3.89513 4.44015L2.34681 6.53802H7.49285L5.94453 4.44015L5.86261 4.32955V0.860859H3.97705V4.32955Z",fill:"currentColor"})}),Yar=e=>a.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 10.0412 8.39395",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:[a.jsx("path",{d:"M0 0.916539C0 0.410349 0.410349 0 0.916539 0C1.42273 0 1.83308 0.410349 1.83308 0.916539C1.83308 1.42273 1.42273 1.83308 0.916539 1.83308C0.410349 1.83308 0 1.42273 0 0.916539Z",fill:"currentColor"}),a.jsx("path",{d:"M2.88569 0.916539C2.88569 0.410349 3.29604 0 3.80223 0C4.30842 0 4.71877 0.410349 4.71877 0.916539C4.71877 1.42273 4.30842 1.83308 3.80223 1.83308C3.29604 1.83308 2.88569 1.42273 2.88569 0.916539Z",fill:"currentColor"}),a.jsx("path",{d:"M5.77139 0.916539C5.77139 0.410349 6.18174 0 6.68793 0H9.12465C9.63084 0 10.0412 0.410349 10.0412 0.916539C10.0412 1.42273 9.63084 1.83308 9.12465 1.83308H6.68793C6.18174 1.83308 5.77139 1.42273 5.77139 0.916539Z",fill:"currentColor"}),a.jsx("path",{d:"M0 4.19696C0 3.69077 0.410351 3.28042 0.916541 3.28042C1.42273 3.28042 1.83308 3.69077 1.83308 4.19696C1.83308 4.70315 1.42273 5.1135 0.916541 5.1135C0.410351 5.1135 0 4.70315 0 4.19696Z",fill:"currentColor"}),a.jsx("path",{d:"M2.8857 4.19694C2.8857 3.69075 3.29605 3.2804 3.80224 3.2804C4.30843 3.2804 4.71877 3.69075 4.71877 4.19694C4.71877 4.70313 4.30843 5.11348 3.80224 5.11348C3.29605 5.11348 2.8857 4.70313 2.8857 4.19694Z",fill:"currentColor"}),a.jsx("path",{d:"M5.77139 4.19694C5.77139 3.69075 6.18174 3.2804 6.68793 3.2804H9.12466C9.63085 3.2804 10.0412 3.69075 10.0412 4.19694C10.0412 4.70313 9.63085 5.11348 9.12466 5.11348H6.68793C6.18174 5.11348 5.77139 4.70313 5.77139 4.19694Z",fill:"currentColor"}),a.jsx("path",{d:"M0 7.47738C0 6.97119 0.410351 6.56084 0.916541 6.56084C1.42273 6.56084 1.83308 6.97119 1.83308 7.47738C1.83308 7.98357 1.42273 8.39392 0.916541 8.39392C0.410351 8.39392 0 7.98357 0 7.47738Z",fill:"currentColor"}),a.jsx("path",{d:"M2.8857 7.47741C2.8857 6.97122 3.29605 6.56087 3.80224 6.56087C4.30843 6.56087 4.71877 6.97122 4.71877 7.47741C4.71877 7.9836 4.30843 8.39395 3.80224 8.39395C3.29605 8.39395 2.8857 7.9836 2.8857 7.47741Z",fill:"currentColor"}),a.jsx("path",{d:"M5.77139 7.47741C5.77139 6.97122 6.18174 6.56087 6.68793 6.56087H9.12466C9.63085 6.56087 10.0412 6.97122 10.0412 7.47741C10.0412 7.9836 9.63085 8.39395 9.12466 8.39395H6.68793C6.18174 8.39395 5.77139 7.9836 5.77139 7.47741Z",fill:"currentColor"})]}),I_=e=>a.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 9.52233 10.4982",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:[a.jsx("path",{d:"M2.39065 4.27882L4.93898 1.73049C5.10578 1.56368 5.37622 1.56368 5.54303 1.73049C5.70983 1.89729 5.70983 2.16773 5.54303 2.33454L2.9947 4.88287C2.53924 5.33834 2.53929 6.0768 2.99475 6.53226C3.45022 6.9877 4.18863 6.98771 4.64409 6.53226L7.19242 3.98393C7.35922 3.81713 7.62967 3.81714 7.79647 3.98393C7.96328 4.15074 7.96328 4.42118 7.79647 4.58798L5.24814 7.13631C4.45907 7.92537 3.17978 7.92536 2.39071 7.13631C1.60163 6.34724 1.60158 5.0679 2.39065 4.27882Z",fill:"currentColor"}),a.jsx("path",{d:"M3.50354 5.43862C3.5236 5.3983 3.55044 5.36049 3.58404 5.32688L6.06565 2.84527C6.52112 2.3898 6.52112 1.65128 6.06565 1.19581C5.61018 0.740366 4.87172 0.740412 4.41626 1.19587L0.729138 4.88287C0.562334 5.04967 0.291892 5.04968 0.125089 4.88287C-0.0416875 4.71607 -0.0417052 4.44562 0.125089 4.27882L3.81221 0.591824C4.60128 -0.197241 5.88062 -0.197289 6.6697 0.591765C7.12856 1.05062 7.32058 1.67529 7.24578 2.27292C7.84449 2.19687 8.47073 2.38872 8.93052 2.84849C9.7196 3.63757 9.7196 4.91697 8.93052 5.70605L8.20316 6.44191L6.20449 8.44058C5.83765 8.80741 5.83765 9.40219 6.20449 9.76902C6.37128 9.93582 6.37129 10.2063 6.20449 10.3731C6.03769 10.5399 5.76724 10.5399 5.60044 10.3731C4.9 9.67263 4.9 8.53697 5.60044 7.83653L7.59911 5.83786L8.32647 5.102C8.78194 4.64653 8.78194 3.90801 8.32647 3.45254C7.871 2.9971 7.13254 2.99714 6.67707 3.4526L4.17576 5.95392C4.00896 6.12072 3.73851 6.12071 3.57171 5.95392C3.43204 5.81425 3.40932 5.60193 3.50354 5.43862Z",fill:"currentColor"})]}),Xar=e=>a.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 8.98824 8.33142",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:[a.jsx("path",{d:"M5.70011e-05 6.409V0H1.04865V6.409C1.04875 6.89152 1.43994 7.28283 1.92248 7.28283H8.3581V8.33142H1.92248C0.860814 8.33142 0.000149953 7.47065 5.70011e-05 6.409Z",fill:"currentColor"}),a.jsx("path",{d:"M8.08006 0.945713C8.27714 0.733828 8.6087 0.72151 8.82077 0.918405C9.03289 1.11551 9.04518 1.44767 8.84808 1.6598L6.08595 4.63218C5.90127 4.83085 5.59525 4.85557 5.38074 4.68953L4.03177 3.64571L2.74765 5.07183C2.55386 5.28688 2.22206 5.30441 2.00694 5.11074C1.79189 4.91695 1.77435 4.58515 1.96803 4.37003L3.57915 2.58278L3.65357 2.51451C3.83887 2.37494 4.09997 2.37165 4.28982 2.51861L5.64358 3.56652L8.08006 0.945713Z",fill:"currentColor"})]});function YO(e){return a.jsx("svg",{width:"16",height:"16",viewBox:"0 0 10.123 10.123",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:a.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M4.50195 1.53809H5.62109V0H6.75098V1.53809H7.5293L7.64258 1.54395C8.19939 1.60066 8.63379 2.0708 8.63379 2.64258V3.37305H10.123V4.50195H8.63379V5.62109H10.123V6.75H8.63379V7.57812L8.62891 7.69141C8.57589 8.2109 8.16211 8.62387 7.64258 8.67676L7.5293 8.68262H6.75098V10.123H5.62109V8.68262H4.50195V10.123H3.37305V8.68262H2.59375L2.48047 8.67676C1.96102 8.62383 1.54817 8.21082 1.49512 7.69141L1.48926 7.57812V6.75H0V5.62109H1.48926V4.50195H0V3.37305H1.48926V2.64258C1.48926 2.07084 1.92371 1.60071 2.48047 1.54395L2.59375 1.53809H3.37305V0H4.50195V1.53809ZM2.61914 7.55273H7.50488V2.66699H2.61914V7.55273Z",fill:"currentColor"})})}const Jar=e=>a.jsx("svg",{width:"16",height:"16",viewBox:"0 0 11.185 11.185",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:a.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M9.57258 2.71626C9.57245 2.19794 9.14778 1.77075 8.61819 1.77075H2.56605C2.0377 1.77075 1.61179 2.19752 1.61165 2.71626V6.51162C1.61179 7.02856 2.03401 7.45487 2.5616 7.45713L3.12802 7.45935V9.21487L5.52178 7.55857L5.66764 7.45713H8.61819C9.14653 7.45713 9.57245 7.03036 9.57258 6.51162V2.71626ZM10.7099 6.51162C10.7097 7.66541 9.76766 8.59441 8.61819 8.59441H6.0223L3.51081 10.3336C3.25841 10.5083 2.86505 10.6555 2.4809 10.4558C2.09483 10.2551 1.99075 9.84577 1.99075 9.53473V8.51222C1.11705 8.26321 0.474488 7.46395 0.474378 6.51162V2.71626C0.474511 1.56248 1.41657 0.633479 2.56605 0.633479H8.61819C9.77051 0.633479 10.7097 1.56448 10.7099 2.71626V6.51162Z",fill:"currentColor"})}),Ax=e=>a.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 8.94379 8.92126",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:[a.jsx("path",{d:"M6.13251 5.43413C6.51629 5.43413 6.82744 5.74533 6.82748 6.1291C6.82748 6.5129 6.51631 6.82407 6.13251 6.82407C5.74877 6.824 5.43754 6.51286 5.43754 6.1291C5.43759 5.74537 5.74879 5.4342 6.13251 5.43413Z",fill:"currentColor"}),a.jsx("path",{d:"M5.92771 2.29722C6.13122 2.09376 6.46147 2.09379 6.665 2.29722C6.86843 2.50075 6.86846 2.831 6.665 3.03451L3.03724 6.66227C2.83373 6.86578 2.5035 6.86572 2.29995 6.66227C2.0965 6.45872 2.09644 6.12849 2.29995 5.92498L5.92771 2.29722Z",fill:"currentColor"}),a.jsx("path",{d:"M2.842 2.12791C3.22572 2.12799 3.53694 2.43914 3.53696 2.82288C3.53696 3.20664 3.22573 3.51777 2.842 3.51785C2.45819 3.51785 2.14703 3.20668 2.14703 2.82288C2.14705 2.4391 2.45821 2.12791 2.842 2.12791Z",fill:"currentColor"}),a.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M7.38455 0.00887484C8.26052 0.0979278 8.94379 0.837945 8.94379 1.73742V7.18384C8.94369 8.08322 8.26046 8.82334 7.38455 8.91238L7.20705 8.92126H1.73742L1.55992 8.91238C0.683828 8.82351 0.000101213 8.08336 0 7.18384V1.73742C0 0.837813 0.683761 0.0977507 1.55992 0.00887484L1.73742 0H7.20705L7.38455 0.00887484ZM1.73742 0.839013C1.24121 0.839013 0.839013 1.24121 0.839013 1.73742V7.18384C0.839121 7.67996 1.24128 8.08293 1.73742 8.08293H7.20705C7.70305 8.08276 8.10535 7.67985 8.10546 7.18384V1.73742C8.10546 1.24131 7.70312 0.83918 7.20705 0.839013H1.73742Z",fill:"currentColor"})]}),elr=e=>a.jsx("svg",{width:"17",height:"18",viewBox:"0 0 17 18",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:a.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M8.40864 11.9983C7.58064 11.9733 6.84164 11.6153 6.31564 11.0563C6.31464 11.0563 6.31464 11.0553 6.31464 11.0553C5.78864 10.4963 5.47564 9.73633 5.50064 8.90833C5.52564 8.08033 5.88464 7.34133 6.44364 6.81533C7.00264 6.28833 7.76264 5.97633 8.59064 6.00133C9.41864 6.02633 10.1576 6.38433 10.6836 6.94333H10.6846C11.2106 7.50333 11.5236 8.26233 11.4986 9.09033C11.4726 9.91833 11.1146 10.6583 10.5556 11.1843C9.99664 11.7103 9.23664 12.0233 8.40864 11.9983ZM16.1266 8.15033L14.3606 7.74033C14.2316 7.14133 14.0146 6.57633 13.7216 6.05733L14.7726 4.57933C14.9116 4.38533 14.8926 4.12033 14.7296 3.94633L13.9206 3.08733C13.7576 2.91333 13.4946 2.87933 13.2916 3.00533L11.7526 3.96533C11.2526 3.64133 10.7016 3.39033 10.1116 3.22633L9.80964 1.43833C9.76964 1.20333 9.56964 1.02833 9.33164 1.02133L8.15264 0.985326C7.91364 0.978326 7.70364 1.14033 7.64964 1.37233L7.24064 3.13933C6.64164 3.26733 6.07664 3.48433 5.55664 3.77733L4.07864 2.72633C3.88464 2.58833 3.61964 2.60633 3.44664 2.76933L2.58664 3.57833C2.41364 3.74133 2.37964 4.00533 2.50564 4.20733L3.46564 5.74633C3.14164 6.24633 2.89064 6.79833 2.72564 7.38833L0.937635 7.68933C0.702635 7.72933 0.528635 7.92933 0.520635 8.16733L0.485635 9.34733C0.477635 9.58533 0.639635 9.79533 0.872635 9.84933L2.63864 10.2583C2.76764 10.8573 2.98464 11.4233 3.27764 11.9423L2.22564 13.4203C2.08764 13.6143 2.10564 13.8793 2.26964 14.0523L3.07864 14.9123C3.24164 15.0853 3.50464 15.1203 3.70664 14.9933L5.24564 14.0333C5.74663 14.3583 6.29764 14.6093 6.88764 14.7733L7.18964 16.5613C7.22864 16.7963 7.42864 16.9713 7.66764 16.9783L8.84663 17.0143C9.08564 17.0213 9.29564 16.8593 9.34964 16.6273L9.75864 14.8603C10.3576 14.7323 10.9226 14.5153 11.4416 14.2213L12.9206 15.2733C13.1146 15.4113 13.3786 15.3933 13.5526 15.2293L14.4116 14.4213C14.5856 14.2573 14.6196 13.9943 14.4936 13.7923L13.5336 12.2533C13.8576 11.7523 14.1086 11.2013 14.2726 10.6113L16.0616 10.3103C16.2966 10.2703 16.4706 10.0703 16.4776 9.83233L16.5136 8.65233C16.5206 8.41433 16.3586 8.20433 16.1266 8.15033Z",fill:"currentColor"})}),ud=e=>a.jsx("svg",{width:"16",height:"16",viewBox:"0 0 11.185 11.185",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:a.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M5.0293 1.16491L4.81958 0.801671L4.81955 0.801686L5.0293 1.16491ZM5.75391 1.16491L5.96365 0.801686L5.96363 0.801671L5.75391 1.16491ZM9.04492 3.06531L9.25474 2.70212L9.25467 2.70208L9.04492 3.06531ZM9.40723 7.49304L9.82666 7.49332V7.49304H9.40723ZM9.04492 8.11999L8.8352 7.75675L8.83518 7.75676L9.04492 8.11999ZM5.75391 10.0204L5.96363 10.3836L5.96365 10.3836L5.75391 10.0204ZM5.0293 10.0204L4.81955 10.3836L4.81963 10.3837L5.0293 10.0204ZM1.73828 8.11999L1.94803 7.75676L1.948 7.75675L1.73828 8.11999ZM1.37598 7.49304H0.956538L0.956538 7.49332L1.37598 7.49304ZM1.73828 3.06531L1.94802 3.42854L1.94803 3.42853L1.73828 3.06531ZM5.59277 3.38366L5.59283 2.96423H5.59277V3.38366ZM3.38379 5.59167L2.96435 5.59159V5.59167H3.38379ZM5.59277 7.80066V8.2201H5.59283L5.59277 7.80066ZM7.80078 5.59167H8.22022V5.59159L7.80078 5.59167ZM5.0293 1.16491L5.23902 1.52816C5.33331 1.47372 5.44989 1.47372 5.54419 1.52816L5.75391 1.16491L5.96363 0.801671C5.60978 0.59738 5.17342 0.59738 4.81958 0.801671L5.0293 1.16491ZM5.75391 1.16491L5.54416 1.52814L8.83518 3.42853L9.04492 3.06531L9.25467 2.70208L5.96365 0.801686L5.75391 1.16491ZM9.04492 3.06531L8.83511 3.42849C8.92979 3.48319 8.98779 3.5839 8.98779 3.69226H9.40723H9.82666C9.82666 3.28328 9.60799 2.90619 9.25474 2.70212L9.04492 3.06531ZM9.40723 3.69226H8.98779V7.49304H9.40723H9.82666V3.69226H9.40723ZM9.40723 7.49304L8.98779 7.49276C8.98772 7.6015 8.92949 7.70231 8.8352 7.75675L9.04492 8.11999L9.25464 8.48324C9.60821 8.2791 9.82639 7.90167 9.82666 7.49332L9.40723 7.49304ZM9.04492 8.11999L8.83518 7.75676L5.54416 9.65715L5.75391 10.0204L5.96365 10.3836L9.25467 8.48322L9.04492 8.11999ZM5.75391 10.0204L5.54419 9.65714C5.44996 9.71154 5.33331 9.71156 5.23897 9.65711L5.0293 10.0204L4.81963 10.3837C5.17339 10.5878 5.60977 10.5879 5.96363 10.3836L5.75391 10.0204ZM5.0293 10.0204L5.23904 9.65715L1.94803 7.75676L1.73828 8.11999L1.52854 8.48322L4.81955 10.3836L5.0293 10.0204ZM1.73828 8.11999L1.948 7.75675C1.85371 7.70231 1.79549 7.6015 1.79541 7.49276L1.37598 7.49304L0.956538 7.49332C0.956809 7.90167 1.17499 8.2791 1.52856 8.48324L1.73828 8.11999ZM1.37598 7.49304H1.79542V3.69226H1.37598H0.956538V7.49304H1.37598ZM1.37598 3.69226H1.79542C1.79542 3.58378 1.85339 3.48318 1.94802 3.42854L1.73828 3.06531L1.52854 2.70207C1.17507 2.90617 0.956538 3.2833 0.956538 3.69226H1.37598ZM1.73828 3.06531L1.94803 3.42853L5.23904 1.52814L5.0293 1.16491L4.81955 0.801686L1.52854 2.70208L1.73828 3.06531ZM5.59277 3.38366V2.96423C4.14162 2.96423 2.96463 4.14015 2.96435 5.59159L3.38379 5.59167L3.80323 5.59175C3.80342 4.60382 4.60458 3.8031 5.59277 3.8031V3.38366ZM3.38379 5.59167H2.96435C2.96435 7.04322 4.14132 8.2201 5.59277 8.2201V7.80066V7.38122C4.6046 7.38122 3.80323 6.57991 3.80323 5.59167H3.38379ZM5.59277 7.80066L5.59283 8.2201C7.04429 8.2199 8.22022 7.04294 8.22022 5.59167H7.80078H7.38134C7.38134 6.57999 6.58061 7.38108 5.59272 7.38122L5.59277 7.80066ZM7.80078 5.59167L8.22022 5.59159C8.21994 4.14043 7.04398 2.96443 5.59283 2.96423L5.59277 3.38366L5.59272 3.8031C6.58062 3.80324 7.38115 4.60374 7.38134 5.59175L7.80078 5.59167Z",fill:"currentColor"})}),px=e=>a.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 9.45892 8.88606",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:[a.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"}),a.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"}),a.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"}),a.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"})]}),tlr=e=>a.jsx("svg",{width:"16",height:"16",viewBox:"0 0 9.55888 8.30616",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:a.jsx("path",{d:"M0 7.18794V1.11823C-4.80684e-08 0.5005 0.5005 2.79299e-06 1.11823 0H3.17924C3.48658 0 3.78038 0.126314 3.99163 0.349532L5.09347 1.5135C5.14625 1.56923 5.21948 1.60085 5.29623 1.60088H8.44065C9.05838 1.60088 9.55888 2.10206 9.55888 2.7198V7.18794C9.55888 7.80567 9.05838 8.30616 8.44065 8.30616H1.11823C0.500524 8.30614 4.41663e-06 7.80565 0 7.18794ZM0.838331 7.18794C0.838332 7.34235 0.963819 7.46781 1.11823 7.46783H8.44065C8.59509 7.46783 8.72055 7.34237 8.72055 7.18794V2.7198C8.72055 2.56536 8.59509 2.4399 8.44065 2.4399H5.29623C4.98896 2.43986 4.69506 2.31353 4.48384 2.09037L3.38268 0.925714C3.32987 0.869949 3.25604 0.838331 3.17924 0.838331H1.11823C0.963799 0.838334 0.838331 0.963798 0.838331 1.11823V7.18794Z",fill:"currentColor"})}),nlr=typeof window<"u"&&window.MASTRA_SIGNALS_UI==="true",rlr={name:"Intelligence",url:"/intelligence",activePaths:["/intelligence"],Icon:nht,isOnMastraPlatform:!0,hidden:!nlr},vke=[{key:"primitives",title:"Primitives",items:[{name:"Agents",url:"/agents",Icon:ko,isOnMastraPlatform:!0},{name:"Prompts",url:"/prompts",Icon:Jar,isOnMastraPlatform:!0},{name:"Workflows",url:"/workflows",Icon:Ol,isOnMastraPlatform:!0},{name:"Processors",url:"/processors",Icon:YO,isOnMastraPlatform:!1,foldable:!0},{name:"MCP Servers",url:"/mcps",Icon:I_,isOnMastraPlatform:!0,foldable:!0},{name:"Tools",url:"/tools",Icon:ud,isOnMastraPlatform:!0,foldable:!0},{name:"Workspaces",url:"/workspaces",Icon:tlr,isOnMastraPlatform:!0,foldable:!0}]},{key:"evaluation",title:"Evaluation",items:[{name:"Scorers",url:"/scorers",Icon:Ax,isOnMastraPlatform:!0},{name:"Datasets",url:"/datasets",Icon:gke,isOnMastraPlatform:!0},{name:"Experiments",url:"/experiments",Icon:Kar,isOnMastraPlatform:!0},{name:"Review Queue",url:"/experiments/review-queue",Icon:J3,isOnMastraPlatform:!0}]},{key:"observability",title:"Observability",items:[{name:"Metrics",url:"/metrics",Icon:Xar,isOnMastraPlatform:!0},{name:"Traces",url:"/traces",Icon:px,isOnMastraPlatform:!0},rlr,{name:"Logs",url:"/logs",Icon:Yar,isOnMastraPlatform:!0}]}],yke=[{name:"Settings",url:"/settings",Icon:elr,isOnMastraPlatform:!1},{name:"Resources",url:"/resources",Icon:Fft,isOnMastraPlatform:!0}],slr=[...vke.flatMap(e=>e.items),...yke];function ilr(e){return slr.find(t=>t.url===e)}function _s(e,t){const n=ilr(e);if(!n)throw new Error(`navCrumb: unknown nav url "${e}"`);return{id:`nav:${e}`,label:n.name,icon:n.Icon,to:e,...t}}const xke=e=>{if(!e)return"";try{return decodeURIComponent(e)}catch{return e}},bke=e=>{const t=xke(e);return t.length>8?`${t.slice(0,8)}...`:t},Okt={id:"agent",Component:uar,Switcher:dar},olr={id:"scorer",Component:War,Switcher:Har},alr={id:"processor",Component:Nar,Switcher:Aar},llr={id:"mcp-server",Component:_ar,Switcher:Tar},rVe={id:"workflow",Component:Ror,Switcher:Mor},oK={id:"dataset",Component:bar,Switcher:war},jkt={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",yml:"yaml",yaml:"yaml",diff:"diff",patch:"diff",css:"css",scss:"css",html:"html",htm:"html",xml:"xml",svg:"xml",sql:"sql"};let Ioe=null;function clr(){return Ioe||(Ioe=(async()=>{const[{createHighlighterCore:e},{createJavaScriptRegexEngine:t}]=await Promise.all([Ii(()=>import("./core-CsIwu6ho.js"),__vite__mapDeps([0,1,2,3,4]),import.meta.url),Ii(()=>import("./engine-javascript-DSQaR0Yq.js"),__vite__mapDeps([5,2,3]),import.meta.url)]);return e({themes:[Ii(()=>import("./github-light-DAi9KRSo.js"),[],import.meta.url),Ii(()=>import("./github-dark-DHJKELXO.js"),[],import.meta.url)],langs:[Ii(()=>import("./javascript-ySlJ1b_l.js"),[],import.meta.url),Ii(()=>import("./typescript-Dj6nwHGl.js"),[],import.meta.url),Ii(()=>import("./tsx-B6W0miNI.js"),[],import.meta.url),Ii(()=>import("./jsx-BAng5TT0.js"),[],import.meta.url),Ii(()=>import("./json-BQoSv7ci.js"),[],import.meta.url),Ii(()=>import("./bash-atvbtKCR.js"),[],import.meta.url),Ii(()=>import("./markdown-UIAJJxZW.js"),[],import.meta.url),Ii(()=>import("./python-DhUJRlN_.js"),[],import.meta.url),Ii(()=>import("./yaml-CVw76BM1.js"),[],import.meta.url),Ii(()=>import("./diff-BgYniUM_.js"),[],import.meta.url),Ii(()=>import("./css-BPhBrDlE.js"),[],import.meta.url),Ii(()=>import("./html-C2L_23MC.js"),__vite__mapDeps([6,7,8]),import.meta.url),Ii(()=>import("./xml-DGRTSKzu.js"),[],import.meta.url),Ii(()=>import("./sql-COK4E0Yg.js"),[],import.meta.url)],engine:t()})})()),Ioe}async function ulr(e,t){const n=jkt[t?.toLowerCase()];if(!n)return null;const r=await clr(),{tokens:s}=r.codeToTokens(e,{lang:n,defaultColor:!1,themes:{light:"github-light",dark:"github-dark"}});return s}function Ckt(e){const t=e?.split(".").pop()?.toLowerCase();return t?jkt[t]:void 0}function dlr({children:e,tooltip:t}){const r=`${typeof e=="string"?e.replace(/\s*\([^)]*\)/g,""):"Request context"} details`;return a.jsxs("div",{className:"flex items-center gap-1.5",children:[a.jsx(ut,{children:e}),t&&a.jsx(mc,{delay:10,children:a.jsxs(Ln,{children:[a.jsx(Rn,{asChild:!0,children:a.jsx("button",{type:"button","aria-label":r,className:Z(Fn,jn,"rounded-sm",Ri),children:a.jsx(At,{size:"xs",children:a.jsx(pp,{})})})}),a.jsx(Mn,{side:"top",className:"max-w-60",children:t})]})})]})}let sVe;const _kt=()=>sVe??=Promise.all([Ii(()=>import("./standalone-Dfz2oS5J.js"),[],import.meta.url),Ii(()=>import("./babel-lWBcy2sH.js"),[],import.meta.url),Ii(()=>import("./estree-Dd9JfUIE.js"),[],import.meta.url)]).catch(e=>{throw sVe=void 0,e}),v5=async e=>{const[t,n,r]=await _kt();return await t.format(e,{semi:!1,parser:"json",printWidth:80,tabWidth:2,plugins:[n,r]})},Tkt=async e=>{const[t,n,r]=await _kt();return await t.format(e,{parser:"babel-ts",printWidth:80,tabWidth:2,plugins:[n,r]})},aQ=e=>{try{const t=JSON.parse(e);return!!t&&typeof t=="object"}catch{return!1}},flr=ki(gt(),URn());function Noe(e,t){if(!e)return"__custom__";for(const[n,r]of Object.entries(e))if(JSON.stringify(r)===t)return n;return"__custom__"}function hlr(e){try{return JSON.stringify(JSON.parse(e))}catch{return null}}const Ekt=({label:e,presets:t,value:n,onSave:r,editorClassName:s="h-[400px]",labelTooltip:i,headerActions:o})=>{const l=JSON.stringify(n??{}),c=JSON.stringify(n??{},null,2),[u,d]=g.useState(c),[f,h]=g.useState(c),[p,m]=g.useState(()=>Noe(t,l)),{handleCopy:v}=Fm({text:u}),[y,x]=g.useState(l);y!==l&&(x(l),d(c),h(c),m(Noe(t,l)));const b=g.useMemo(()=>{const N=hlr(u);return N?N!==l:u!==f},[l,u,f]),S=()=>{let N;try{N=JSON.parse(u)}catch{Ke.error("Invalid JSON");return}const I=flr.safeParse(N);if(!I.success){Ke.error(`${e} must be a JSON object`);return}r(I.data)},k=()=>{d(f),m(Noe(t,l))},j=Z(Fn,jn),C=async()=>{if(!aQ(u)){Ke.error("Invalid JSON");return}const N=await v5(u);d(N)},T=async N=>{if(m(N),N==="__custom__"||!t)return;const I=t[N];if(I){const A=await v5(JSON.stringify(I));d(A)}},_=N=>{d(N),p!=="__custom__"&&m("__custom__")};return a.jsx(mc,{children:a.jsxs("div",{children:[a.jsxs(ft,{children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs(dlr,{tooltip:i,children:[e," (JSON)"]}),a.jsxs("div",{className:"flex items-center gap-2",children:[o,a.jsxs(Ln,{children:[a.jsx(Rn,{asChild:!0,children:a.jsx("button",{type:"button",onClick:C,className:j,children:a.jsx(At,{children:a.jsx(Ua,{})})})}),a.jsxs(Mn,{children:["Format the ",e," JSON"]})]}),a.jsxs(Ln,{children:[a.jsx(Rn,{asChild:!0,children:a.jsx("button",{type:"button",onClick:v,className:j,children:a.jsx(At,{children:a.jsx(Lm,{})})})}),a.jsxs(Mn,{children:["Copy ",e]})]})]})]}),t&&Object.keys(t).length>0&&a.jsxs(ft,{children:[a.jsxs(ut,{className:"sr-only",children:[e," preset"]}),a.jsxs(Vr,{value:p,onValueChange:T,children:[a.jsx(qr,{children:a.jsx(Ur,{placeholder:"Select a preset..."})}),a.jsxs(Qr,{children:[a.jsx(ir,{value:"__custom__",children:"Custom"}),Object.keys(t).map(N=>a.jsx(ir,{value:N,children:N},N))]})]})]}),a.jsx(Or,{value:u,onChange:_,showCopyButton:!1,className:s})]}),a.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[b&&a.jsx(de,{variant:"default",size:"icon-md",type:"button",tooltip:`Revert ${e} changes`,onClick:k,children:a.jsx(Dn,{})}),a.jsx(de,{icon:a.jsx(dr,{}),type:"button",onClick:S,children:"Save"})]})]})})},plr={align:"shift"};function Ikt({label:e,icon:t,open:n,onOpenChange:r,children:s}){return a.jsxs(_p,{open:n,onOpenChange:r,children:[a.jsx(of,{variant:"ghost",size:"icon-md",type:"button",tooltip:e,"aria-label":e,children:t}),a.jsx(lh,{align:"start",collisionAvoidance:plr,className:"w-[min(480px,calc(100vw-2rem))] p-0",children:a.jsx("div",{onSubmit:i=>i.stopPropagation(),children:a.jsx(Nr,{className:"w-full",maxHeight:"min(600px, calc(100dvh - 8rem))",children:a.jsx("div",{className:"space-y-4 p-4",children:s})})})})]})}function mlr(){return g.useMemo(()=>{const e=typeof window<"u"?window.MASTRA_REQUEST_CONTEXT_PRESETS:void 0;if(!e||e==="%%MASTRA_REQUEST_CONTEXT_PRESETS%%")return null;try{const t=JSON.parse(e);if(typeof t=="object"&&t!==null&&!Array.isArray(t))return t}catch{console.warn("Failed to parse request context presets")}return null},[])}function wke({entityType:e,entityId:t}){const[n,r]=g.useState(!1),[s,i]=xr(e,t),o=mlr(),l=c=>{i(c),Ke.success("Request context saved locally"),r(!1)};return a.jsx(Ikt,{label:"Request context",icon:a.jsx(cTn,{}),open:n,onOpenChange:r,children:a.jsx(Ekt,{label:"Request Context",presets:o,value:s,onSave:l,editorClassName:"h-[260px]"})})}function Nkt({entityType:e,entityId:t,extraFields:n,onSaveExtra:r,onOpenChange:s}){const[i,o]=g.useState(!1),[l,c]=rke(e,t),u=f=>{o(f),s?.(f)},d=f=>{c(f),r?.(),Ke.success("Run options saved locally"),u(!1)};return a.jsxs(Ikt,{label:"Run options",icon:a.jsx(px,{}),open:i,onOpenChange:u,children:[n,a.jsx(Ekt,{label:"Tracing Options",value:l,onSave:d,editorClassName:"h-[260px]"})]})}function glr({workflowId:e,resourceId:t,setResourceId:n}){const[r,s]=g.useState(t);return a.jsxs(a.Fragment,{children:[a.jsx(wke,{entityType:"workflow",entityId:e}),a.jsx(Nkt,{entityType:"workflow",entityId:e,onOpenChange:i=>{i&&s(t)},onSaveExtra:()=>n(r),extraFields:a.jsxs(ft,{children:[a.jsx(ut,{children:"Resource ID"}),a.jsx(Sn,{value:r,onChange:i=>s(i.target.value),placeholder:"e.g. tenant-42"}),a.jsx(no,{children:"Ignored when server auth derives the resource ID from the user."})]})})]})}function lQ({icon:e,label:t,tooltipContent:n,docsHref:r}){return a.jsxs(Ln,{children:[a.jsx(Rn,{render:a.jsx("span",{role:"button",tabIndex:0,"aria-disabled":"true","aria-label":t,className:"inline-flex",children:a.jsx(de,{variant:"ghost",size:"icon-md",disabled:!0,"aria-hidden":"true",tabIndex:-1,children:e})})}),a.jsx(Mn,{side:"bottom",className:"max-w-[calc(100dvw-1rem)]",children:a.jsxs("span",{children:[n," ",a.jsxs("a",{href:r,target:"_blank",rel:"noopener noreferrer",className:Z("inline-flex items-center gap-1 text-inherit underline hover:text-foreground",jn),children:["Learn more",a.jsx(Zs,{className:"size-3"})]})]})})]})}const vlr=({scheduleId:e,queryOptions:t})=>{const n=Ye();return _t({queryKey:["schedule",e],queryFn:async()=>{if(!e)throw new Error("scheduleId is required");return n.getSchedule(e)},...t})},aK=({queryOptions:e,...t}={})=>{const n=Ye();return _t({queryKey:["schedules",t],queryFn:async()=>(await n.listSchedules(t)).schedules,...e})},iVe=25,ylr=({scheduleId:e,queryOptions:t})=>{const n=Ye(),{inView:r,setRef:s}=F0(),i=Mm({queryKey:["schedule-triggers",e],initialPageParam:void 0,queryFn:async({pageParam:d})=>e?n.listScheduleTriggers(e,{limit:iVe,toActualFireAt:d}):{triggers:[]},getNextPageParam:d=>{if(!(!d?.triggers?.length||d.triggers.length<iVe))return d.triggers[d.triggers.length-1].actualFireAt},refetchInterval:d=>(d.state.data?.pages.flatMap(f=>f.triggers)??[]).some(f=>f.run?f.run.status==="pending"||f.run.status==="running"||f.run.status==="waiting":f.outcome==="published")?5e3:!1,...t}),o=i.data?.pages.flatMap(d=>d?.triggers??[])??[],{hasNextPage:l,isFetchingNextPage:c,fetchNextPage:u}=i;return g.useEffect(()=>{r&&l&&!c&&u()},[r,l,c,u]),{...i,data:o,setEndOfListElement:s}},xlr=({scheduleId:e,queryOptions:t})=>{const n=Ye(),r=mr();return kn({mutationFn:async s=>{if(!e)throw new Error("scheduleId is required");return s==="pause"?n.pauseSchedule(e):n.resumeSchedule(e)},onSuccess:()=>{r.invalidateQueries({queryKey:["schedule",e]}),r.invalidateQueries({queryKey:["schedules"]})},...t})};function Aoe({value:e,icon:t,label:n}){return a.jsxs(ni,{value:e,children:[a.jsx(At,{size:"xs",children:t}),a.jsx(Y,{variant:"caption",className:"text-inherit",children:n})]})}function blr({workflowId:e,activeTab:t,showObservability:n=!1}){const{navigate:r}=xn(),{data:s,isSuccess:i}=aK({workflowId:e}),o=s?.length??0,l=encodeURIComponent(e),c={graph:`/workflows/${l}/graph`,traces:`/workflows/${l}/traces`,schedules:`/workflows/${l}/schedules`},u=f=>{f!=="none"&&r(c[f])},d=i&&o===0;return a.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-2 p-1.5",children:[a.jsx(Qc,{value:t,defaultTab:t,onValueChange:u,className:"min-w-0",children:a.jsxs(Zc,{variant:"pill-ghost",children:[a.jsx(Aoe,{value:"graph",icon:a.jsx(Ol,{}),label:"Graph"}),n&&a.jsx(Aoe,{value:"traces",icon:a.jsx(px,{}),label:"Traces"}),!d&&a.jsx(Aoe,{value:"schedules",icon:a.jsx(g0,{}),label:o>0?`Schedules (${o})`:"Schedules"})]})}),(!n||d)&&a.jsxs("div",{className:"ml-auto flex shrink-0 items-center gap-0.5",children:[!n&&a.jsx(lQ,{icon:a.jsx(px,{}),label:"Traces",tooltipContent:a.jsxs(a.Fragment,{children:["Add ",a.jsx("code",{children:"@mastra/observability"})," to enable Traces."]}),docsHref:"https://mastra.ai/docs/observability/overview"}),d&&a.jsx(lQ,{icon:a.jsx(g0,{}),label:"Schedules",tooltipContent:"Configure a schedule on this workflow to enable Schedules.",docsHref:"https://mastra.ai/docs/workflows/scheduled-workflows"})]})]})}const wlr=({children:e})=>{const{workflowId:t,runId:n}=jr();return a.jsx(nwe,{resetKeys:[t,n],title:"Unable to display this workflow",description:"The workflow data could not be displayed. Try again or open another workflow.",children:a.jsx(Olr,{children:e})})},Slr=e=>e==="graph"||e==="traces"||e==="schedules",klr=({workflowId:e})=>{const t=Dr();return D0({"g$+t":()=>t(`/workflows/${encodeURIComponent(e)}/traces`)}),null};function Olr({children:e}){const{workflowId:t,runId:n}=jr(),r=Dbe("/workflows/:workflowId/:tab/*"),{isLoading:s}=lL({workflowId:t,requestContext:xr("workflow",t)[0],queryOptions:{enabled:!!t}}),{hasObservability:i}=lkt(),o=Slr(r?.params.tab)?r.params.tab:"none",l=[_s("/workflows"),n?{...rVe,to:`/workflows/${encodeURIComponent(t??"")}/graph`}:rVe,...n?[{id:"workflow-run",Component:Dor,Action:Lor}]:[]];if(!t)return a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:l}),children:[a.jsx("h1",{className:"sr-only",children:t}),a.jsx("div",{className:"flex h-full flex-col items-center justify-center",children:a.jsx(Y,{variant:"body",tone:"ink",className:"text-center",children:"No workflow ID provided"})})]});if(s&&o==="graph")return a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:l}),children:[a.jsx("h1",{className:"sr-only",children:t}),a.jsx(xt,{className:"h-full"})]});const c=u=>a.jsxs(Et,{variant:"fit",breadcrumbs:a.jsx(Dt,{crumbs:l}),headerActions:a.jsx(For,{}),children:[a.jsx("h1",{className:"sr-only",children:t}),a.jsxs("div",{className:"grid h-full min-h-0 grid-cols-[minmax(0,1fr)] grid-rows-[auto_minmax(0,1fr)]",children:[a.jsx(blr,{workflowId:t,activeTab:o,showObservability:i}),u]})]});return a.jsxs(Jnt,{children:[a.jsx(klr,{workflowId:t}),o==="graph"?a.jsx(PSt,{children:a.jsx(ike,{workflowId:t,initialRunId:n,children:a.jsx(ASt,{children:c(a.jsx(zir,{leftSlot:a.jsx(jlr,{workflowId:t,initialRunId:n}),children:e}))})})},t):c(e)]})}function jlr({workflowId:e,initialRunId:t}){const[n]=xr("workflow",e),{canExecute:r,canDelete:s}=Wa();return a.jsx(Qir,{workflowId:e,initialRunId:t,requestContext:n,runActionsSlot:i=>a.jsx(glr,{workflowId:e,...i}),canExecute:r("workflows"),canDelete:s("workflows")})}const Akt=pd(Z(pr,"rounded-xl transition-all duration-normal ease-out-custom motion-reduce:transition-none"),{variants:{elevation:{flat:"shadow-none",raised:""},interactive:{true:Z(aP,I0e,"cursor-pointer active:scale-99"),false:""}},compoundVariants:[{elevation:"flat",interactive:!0,class:jx}],defaultVariants:{elevation:"raised",interactive:!1}}),jl=g.forwardRef(({className:e,elevation:t,interactive:n,as:r,...s},i)=>{const o=r||(n?"button":"div");return a.jsx(o,{ref:i,type:o==="button"?"button":void 0,className:Z(Akt({elevation:t,interactive:n}),e),...s})});jl.displayName="Card";function Pkt({className:e,elevation:t,LinkComponent:n="a",...r}){return a.jsx(n,{className:Z(Akt({elevation:t,interactive:!0}),e),...r})}const cQ=g.forwardRef(({className:e,...t},n)=>a.jsx("div",{ref:n,className:Z("flex flex-col space-y-1.5 px-3 py-1",e),...t}));cQ.displayName="CardHeader";const Q0=g.forwardRef(({className:e,...t},n)=>a.jsx("h3",{ref:n,className:Z("text-subheading text-foreground",e),...t}));Q0.displayName="CardTitle";const Mj=g.forwardRef(({className:e,...t},n)=>a.jsx("p",{ref:n,className:Z("text-caption text-muted-foreground",e),...t}));Mj.displayName="CardDescription";const Clr=pd("",{variants:{density:{default:"p-3",compact:"p-2"}},defaultVariants:{density:"default"}}),Um=g.forwardRef(({className:e,density:t,...n},r)=>a.jsx("div",{ref:r,className:Z(Clr({density:t}),e),...n}));Um.displayName="CardContent";const _lr=g.forwardRef(({className:e,...t},n)=>a.jsx("div",{ref:n,className:Z("flex items-center p-3 pt-0",e),...t}));_lr.displayName="CardFooter";const oVe=["blue","green","orange","purple","pink","amber","cyan"];function Ske(e){let t=2166136261;for(let n=0;n<e.length;n+=1)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return t>>>0}const lK=e=>oVe[Ske(e)%oVe.length]??"blue",Tlr=e=>`var(--badge-${e}-indicator)`,Elr={blue:"bg-badge-blue-strong text-badge-blue-foreground",green:"bg-badge-green-strong text-badge-green-foreground",orange:"bg-badge-orange-strong text-badge-orange-foreground",purple:"bg-badge-purple-strong text-badge-purple-foreground",pink:"bg-badge-pink-strong text-badge-pink-foreground",amber:"bg-badge-amber-strong text-badge-amber-foreground",cyan:"bg-badge-cyan-strong text-badge-cyan-foreground"},$kt=e=>Elr[e],Ilr=e=>({background:`var(--badge-${e}-strong)`,foreground:`var(--badge-${e}-foreground)`,tint:`var(--badge-${e}-indicator)`}),aVe={goal:"green",outcome:"orange",behavior:"blue",sentiment:"purple"},lVe=["pink","amber"],Nlr={green:"fill-badge-green-strong",orange:"fill-badge-orange-strong",blue:"fill-badge-blue-strong",purple:"fill-badge-purple-strong",pink:"fill-badge-pink-strong",amber:"fill-badge-amber-strong"},Alr={green:"stroke-badge-green-edge",orange:"stroke-badge-orange-edge",blue:"stroke-badge-blue-edge",purple:"stroke-badge-purple-edge",pink:"stroke-badge-pink-edge",amber:"stroke-badge-amber-edge"};function kke(e){const t=e.toLowerCase();return(Object.hasOwn(aVe,t)?aVe[t]:void 0)??lVe[Ske(t)%lVe.length]??"pink"}function Px(e){return`var(--chart-${kke(e)})`}function Rkt(e){return Nlr[kke(e)]}function Plr(e){return Alr[kke(e)]}const AP=[{name:"goal",label:"Goal",description:"What the user wanted from the interaction.",order:0,builtIn:!0,enabled:!0,status:"ready"},{name:"sentiment",label:"Sentiment",description:"The tone the user expressed during the interaction.",order:1,builtIn:!0,enabled:!0,status:"ready"},{name:"behavior",label:"Behavior",description:"What the agent did in response.",order:2,builtIn:!0,enabled:!0,status:"ready"},{name:"outcome",label:"Outcome",description:"How the interaction ended.",order:3,builtIn:!0,enabled:!0,status:"ready"}];AP.map(e=>e.name);Object.fromEntries(AP.map(e=>[e.name,e.description]));function UL(e,t){const n=[...new Set(t??e.map(s=>s.name))],r=new Map(e.map(s=>[s.name,s.order]));return n.sort((s,i)=>{const o=r.get(s),l=r.get(i);return o===void 0&&l===void 0?0:o===void 0?1:l===void 0?-1:o-l})}function yp(e,t){return e.find(n=>n.name===t)?.label??$lr(t)}function PS(e,t){return e.find(n=>n.name===t)?.description||void 0}function $lr(e){return e.split(/[-_]+/).filter(Boolean).map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join(" ")}function cK(e){return`${e} ${e===1?"trace":"traces"}`}function Rlr(e){return`${e} ${e===1?"theme":"themes"}`}function Mkt(e,t){if(t<=0)return`${cK(e)} in this snapshot`;const n=Math.round(e/t);return`${e} of ${n} traces in this snapshot (${Math.round(t*100)}%)`}const Oke={timeZone:"UTC"};function y5(e){return PI(e,{...Oke,now:0})??e}function uK(e){return os(e,"date-time",Oke)??e}function Rpe(e,t){return KYn(e,t,Oke)??`${e}–${t}`}const Mlr=[["chat.completion","1.2s"],["tool.search_docs","340ms"],["workflow.support","2.8s"]],uQ=e=>({color:Px(e)}),cVe=()=>a.jsxs("div",{"aria-hidden":"true",className:"relative hidden h-full items-center lg:flex",children:[a.jsx("div",{className:"w-full border-t border-dashed border-border"}),a.jsx("span",{className:"absolute left-1/2 size-2.5 -translate-x-1/2 rounded-full bg-brand-green-indicator"})]});function x5(e){return new Intl.NumberFormat("en-US").format(e)}function Dlr(e,t){return t?{title:"No Trace Intelligence themes in this date range.",body:"Choose a wider snapshot date range, or wait for newly processed traces to form recurring themes."}:!e||e.status==="collecting"?{title:"Collecting traces for Trace Intelligence.",body:"Trace Intelligence starts grouping recurring patterns after your deployed agents send enough completed traces."}:e.status==="ready"?{title:"Trace Intelligence themes are ready.",body:"Select at least two available trace signal types to see how goals, outcomes, behaviors, and sentiment connect."}:{title:"Analyzing traces for Trace Intelligence.",body:"Trace signals have started processing. Themes appear after enough generated and embedded trace signals form recurring patterns."}}function Llr({progress:e}){const t=e.signalCatalog??AP,n=t.filter(s=>s.enabled).length,r=t.filter(s=>s.enabled&&s.status==="ready").length;return a.jsxs("dl",{className:"mt-4 grid gap-2 sm:grid-cols-3",children:[a.jsxs("div",{className:Z(pr,"rounded-md px-3 py-2"),children:[a.jsx("dt",{className:Da({tone:"muted",variant:"caption"}),children:"Traces analyzed"}),a.jsx("dd",{className:Z(Da({tone:"ink",variant:"heading"}),"mt-1"),children:x5(e.traceCount)})]}),a.jsxs("div",{className:Z(pr,"rounded-md px-3 py-2"),children:[a.jsx("dt",{className:Da({tone:"muted",variant:"caption"}),children:"Trace signal types ready"}),a.jsxs("dd",{className:Z(Da({tone:"ink",variant:"heading"}),"mt-1"),children:[e.signalCatalog?r:e.availableSignals.length," of ",n]})]}),a.jsxs("div",{className:Z(pr,"rounded-md px-3 py-2"),children:[a.jsx("dt",{className:Da({tone:"muted",variant:"caption"}),children:"Status"}),a.jsx("dd",{className:Z(Da({tone:"ink",variant:"heading"}),"mt-1 capitalize"),children:e.status})]})]})}function zlr({progress:e}){if(!e)return null;const t=e.signalCatalog??AP;return a.jsx("ul",{"aria-label":"Trace signal processing progress",className:"mt-3 grid gap-2 sm:grid-cols-2 lg:grid-cols-4",children:UL(t,t.filter(n=>n.enabled).map(n=>n.name)).map(n=>{const r=e.signals[n]??{generated:0,embedded:0},s=t.find(l=>l.name===n),i=yp(t,n),o=s?s.status==="ready":e.availableSignals.includes(n);return a.jsxs("li",{className:"rounded-md border border-border bg-background px-3 py-2",children:[a.jsxs("div",{className:"flex items-center justify-between gap-2",children:[a.jsx(Y,{as:"span",variant:"subheading",style:uQ(n),children:i}),a.jsx(Y,{as:"span",variant:"caption",tone:"muted",children:o?"Themes ready":"Processing"})]}),a.jsxs(Y,{variant:"caption",tone:"muted",className:"mt-1",children:[x5(r.generated)," generated · ",x5(r.embedded)," embedded"]})]},n)})})}function Flr({progress:e,signalCatalog:t}){const n=e?.signalCatalog??t,r=n.filter(s=>s.enabled&&s.status!=="ready");return r.length===0?null:a.jsxs("section",{className:"rounded-lg border border-border bg-background p-4","aria-labelledby":"pending-signals-heading",children:[a.jsx(Y,{as:"h2",variant:"subheading",tone:"ink",id:"pending-signals-heading",children:"Signals building themes"}),a.jsx(Y,{variant:"caption",tone:"muted",className:"mt-1",children:"Themes appear once enough new traces are analyzed, embedded, and clustered."}),a.jsx("ul",{"aria-label":"Pending trace signals",className:"mt-3 grid gap-2 sm:grid-cols-2",children:r.map(s=>{const i=e?.signals[s.name]??{generated:0,embedded:0};return a.jsxs("li",{className:Z(pr,"rounded-md px-3 py-2"),children:[a.jsxs("div",{className:"flex items-center justify-between gap-2",children:[a.jsx(Y,{font:"body",as:"span",variant:"subheading",style:uQ(s.name),children:yp(n,s.name)}),a.jsx(Y,{font:"body",as:"span",variant:"caption",tone:"muted",className:"capitalize",children:s.status})]}),PS(n,s.name)?a.jsx(Y,{font:"body",variant:"caption",tone:"muted",className:"mt-1",children:PS(n,s.name)}):null,a.jsxs(Y,{font:"body",variant:"caption",tone:"muted",className:"mt-1",children:[x5(i.generated)," generated · ",x5(i.embedded)," embedded"]})]},s.name)})})]})}const Mpe=({actionSlot:e,LinkComponent:t="a",progress:n,signalCatalog:r,isRangeEmpty:s})=>{const i=Dlr(n,s),o=r??n?.signalCatalog??AP,c=UL(o,o.filter(u=>u.enabled).map(u=>u.name)).map(u=>({key:u,label:yp(o,u),description:PS(o,u)}));return a.jsx("section",{className:"min-h-full w-full bg-sidebar p-6 md:px-10 lg:px-12 xl:px-[4.375rem]",children:a.jsxs("div",{className:"mx-auto w-full max-w-260",children:[a.jsxs("header",{children:[a.jsxs(Y,{variant:"eyebrow",tone:"muted",className:"flex items-center gap-2",children:[a.jsx("span",{"aria-hidden":"true",className:"size-2 rounded-full bg-brand-green-indicator"}),"Trace Intelligence"]}),a.jsx(Y,{as:"h1",variant:"display",tone:"ink",className:"mt-2",children:"Understand what drives every agent interaction"}),a.jsx(Y,{tone:"muted",className:"mt-2 max-w-180",children:"Trace Intelligence groups recurring goals, outcomes, behaviors, and sentiment across completed traces."})]}),a.jsxs("div",{role:"list","aria-label":"Trace Intelligence analysis pipeline",className:"mt-14 grid gap-4 lg:grid-cols-[17.5rem_4.5rem_17.5rem_4.5rem_minmax(0,1fr)] lg:gap-0",children:[a.jsxs("div",{role:"listitem",className:"min-h-50 p-5",children:[a.jsx(Y,{as:"h2",variant:"heading",tone:"ink",children:"Traces"}),a.jsx(Y,{variant:"caption",tone:"muted",className:"mt-0.5",children:"Every agent interaction"}),a.jsx(Y,{variant:"eyebrow",tone:"muted",className:"mt-5",children:"Input"}),a.jsx("div",{className:"mt-2.5 space-y-2",children:Mlr.map(([u,d])=>a.jsxs("div",{className:Z(pr,"flex items-center justify-between rounded px-3 py-1.5"),children:[a.jsx(Y,{as:"span",variant:"meta",font:"mono",tone:"muted",children:u}),a.jsx(Y,{as:"span",variant:"meta",font:"mono",tone:"muted",children:d})]},u))})]}),a.jsx(cVe,{}),a.jsxs(jl,{as:"div",role:"listitem",className:"flex min-h-50 flex-col items-center p-5 text-center",elevation:"raised",children:[a.jsx(Y,{as:"h2",variant:"heading",tone:"ink",children:"Trace Intelligence"}),a.jsx(Y,{variant:"caption",tone:"muted",className:"mt-0.5",children:"Finds recurring themes"}),a.jsx("div",{"aria-hidden":"true",className:"mt-5 flex size-14 items-center justify-center rounded-full border border-brand-green-indicator bg-fill-subtle",children:a.jsx(dP,{className:"size-4 text-brand-green-indicator"})}),a.jsx(Y,{variant:"meta",tone:"muted",className:"mt-3 max-w-40",children:"Clusters similar trace signals into themes for each dimension"})]}),a.jsx(cVe,{}),a.jsxs("div",{role:"listitem",className:"min-h-50 p-5",children:[a.jsx(Y,{as:"h2",variant:"heading",tone:"ink",children:"Theme analysis"}),a.jsx(Y,{variant:"caption",tone:"muted",className:"mt-0.5",children:"How recurring patterns connect"}),a.jsx(Y,{variant:"eyebrow",tone:"muted",className:"mt-5",children:"Output"}),a.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:c.map(u=>a.jsxs(Y,{as:"span",variant:"column",className:"inline-flex items-center gap-2 rounded border border-border bg-card px-2.5 py-1.5",style:uQ(u.key),children:[a.jsx("span",{"aria-hidden":"true",className:"size-1.5 rounded-full bg-current"}),u.label]},u.key))})]})]}),a.jsxs("section",{className:"mt-10","aria-labelledby":"signal-definitions-heading",children:[a.jsx(Y,{as:"h2",variant:"heading",tone:"ink",id:"signal-definitions-heading",children:"What each trace signal means"}),a.jsx("ul",{"aria-label":"Trace signal definitions",className:"mt-4 grid gap-3 sm:grid-cols-2",children:c.map(u=>a.jsxs("li",{className:"px-1 py-2",children:[a.jsx(Y,{as:"h3",variant:"subheading",style:uQ(u.key),children:u.label}),u.description?a.jsx(Y,{variant:"caption",tone:"muted",className:"mt-1.5",children:u.description}):null]},u.key))})]}),a.jsxs("aside",{className:"mt-9 rounded-md border border-border bg-background px-5 py-4",children:[a.jsxs("div",{className:"flex min-w-0 items-start gap-3",children:[a.jsx("span",{"aria-hidden":"true",className:"mt-1.5 size-2 shrink-0 rounded-full bg-warning-indicator"}),a.jsxs("div",{className:"min-w-0 flex-1",children:[a.jsxs(Y,{variant:"caption",tone:"muted",children:[a.jsx(Y,{as:"strong",variant:"column",tone:"ink",children:i.title})," ",i.body]}),n?a.jsx(Llr,{progress:n}):null,a.jsx(zlr,{progress:n})]})]}),a.jsxs("div",{className:"mt-4 flex shrink-0 flex-wrap items-center gap-2 sm:justify-end",children:[e,a.jsxs(de,{icon:a.jsx(Zs,{}),render:a.jsx("a",{href:"https://mastra.ai/en/docs/mastra-platform/trace-intelligence",target:"_blank",rel:"noopener noreferrer"}),size:"sm",children:["Read the docs",a.jsx("span",{className:"sr-only",children:" (opens in new tab)"})]}),a.jsx(de,{icon:a.jsx(px,{}),render:a.jsx(t,{href:"/traces"}),variant:"primary",size:"sm",children:"View incoming traces"})]})]})]})})};function uVe(e){return a.jsx(Mpe,{...e})}async function Blr(e){const t=await fetch(e,{credentials:"include"});if(!t.ok)throw Object.assign(new Error(`Trace Intelligence request failed (${t.status})`),{status:t.status});return t.json()}const g2={cacheScope:"oss-studio",request:Blr,LinkComponent:"a",getTraceHref:e=>`/traces?traceId=${encodeURIComponent(e)}`,signalCatalog:AP},jke=g.createContext(g2);function pa(){return g.useContext(jke)}function Vlr(e,t){const n=new URLSearchParams({entityType:t});return e(`/api/learning/entities?${n}`)}function Ulr(e,t,n){const r=new URLSearchParams({entityType:n});return e(`/api/learning/entities/${encodeURIComponent(t)}/progress?${r}`)}function Dkt(e,t,n,r,s,i,o=24){const l=new URLSearchParams({entityType:n,signalNames:r.join(","),presentation:"landmarks",limit:String(o)});return s&&l.set("from",s.toISOString()),i&&l.set("to",i.toISOString()),e(`/api/learning/entities/${encodeURIComponent(t)}/theme-snapshots?${l}`)}function Lkt(e,t,n,r,s,i=8){const o=new URLSearchParams({entityType:n,signalNames:r.join(","),snapshotId:s,themeLimitPerStage:String(i)});return e(`/api/learning/entities/${encodeURIComponent(t)}/theme-flow?${o}`)}function qlr(e,t,n,r,s,i){const o=new URLSearchParams({entityType:n,signalName:r,snapshotId:s});return e(Cke(t,i,`?${o}`))}function qL(e){return e.map(t=>`${t.signalName}:${t.kind==="theme"?t.themeId:"noise"}`).join(",")}function Qlr(e,t,n,r,s,i,o=20,l=0,c=[]){const u=new URLSearchParams({entityType:n,signalName:r,snapshotId:s,limit:String(o),offset:String(l)});return c.length>0&&u.set("filterThemes",qL(c)),e(Cke(t,i,`/examples?${u}`))}function Zlr(e,t,n,r,s,i=100){const o=new URLSearchParams({entityType:n,signalName:r,limit:String(i)});return e(Cke(t,s,`/history?${o}`))}function Wlr(e,t,n,r,s){const i=new URLSearchParams({entityType:n,signalName:r,snapshotId:s});return e(Fkt(t,`?${i}`))}function Hlr(e,t,n,r,s,i=20,o=0,l=[]){const c=new URLSearchParams({entityType:n,signalName:r,snapshotId:s,limit:String(i),offset:String(o)});return l.length>0&&c.set("filterThemes",qL(l)),e(Fkt(t,`/examples?${c}`))}async function zkt(e,t,n,r,s){const i=await dVe(e,t,n,r,s,0),o=[...i.paths],l={...i.themes};let c=i.nextOffset;for(;c!==void 0;){const u=await dVe(e,t,n,r,s,c);o.push(...u.paths),Object.assign(l,u.themes),c=u.nextOffset}return{snapshot:i.snapshot,signals:i.signals,themes:l,paths:o}}function dVe(e,t,n,r,s,i){const o=new URLSearchParams({entityType:n,signalNames:r.join(","),snapshotId:s,limit:"500",offset:String(i)});return e(`/api/learning/entities/${encodeURIComponent(t)}/theme-paths?${o}`)}function Glr(e,t){return e(`/api/learning/traces/${encodeURIComponent(t)}/summary`)}function Cke(e,t,n){return`/api/learning/entities/${encodeURIComponent(e)}/themes/${encodeURIComponent(t)}${n}`}function Fkt(e,t){return`/api/learning/entities/${encodeURIComponent(e)}/noise${t}`}function Bkt(e,t,n=!0){const{cacheScope:r,request:s}=pa();return _t({queryKey:["entity-learning",r,t,e,"progress"],queryFn:()=>Ulr(s,e??"",t),enabled:n&&!!e})}function Vkt(e){const{cacheScope:t,request:n}=pa();return _t({queryKey:["entity-learning",t,"entities",e],queryFn:()=>Vlr(n,e)})}function Ukt(e,t,n,r,s){const{cacheScope:i,request:o}=pa(),l=r?.toISOString(),c=s?.toISOString();return _t({queryKey:["entity-learning",i,t,e,"theme-snapshots",n,l,c],queryFn:()=>Dkt(o,e,t,n,r,s),enabled:n.length>=2,staleTime:3e4})}const Klr=.01;function Ylr(e,t){return String(e[t.id])}function Xlr(e,t){const n=String(e[`${t.id}Label`]),r=e[`${t.id}Description`];return typeof r=="string"&&r.trim()?`${n}
|
|
257
|
+
`);for(const n of t)if(n.startsWith("data:")){const r=n.slice(5).trim();if(r)return JSON.parse(r)}throw new Error("No data found in SSE response")}return e.json()}async function jar(e,t){const n={...t,"Content-Type":"application/json",Accept:"application/json, text/event-stream"},r=await fetch(e,{method:"POST",headers:n,credentials:"include",body:JSON.stringify({jsonrpc:"2.0",id:1,method:"initialize",params:{protocolVersion:"2025-03-26",capabilities:{},clientInfo:{name:"mastra-playground",version:"1.0.0"}}})});if(!r.ok)throw new Error(`Initialize failed: ${r.status} ${r.statusText}`);const s=r.headers.get("Mcp-Session-Id");await nVe(r);const i={...n};s&&(i["Mcp-Session-Id"]=s),await fetch(e,{method:"POST",headers:i,credentials:"include",body:JSON.stringify({jsonrpc:"2.0",method:"notifications/initialized"})});const o=await fetch(e,{method:"POST",headers:i,credentials:"include",body:JSON.stringify({jsonrpc:"2.0",id:2,method:"tools/list"})});if(!o.ok)throw new Error(`tools/list failed: ${o.status} ${o.statusText}`);return{tools:(await nVe(o)).result?.tools??[]}}const Car=({queryOptions:e}={})=>{const t=Ye().options?.headers??{};return kn({mutationFn:n=>jar(n,t),...e})};function vkt({value:e,onValueChange:t,placeholder:n="Select an MCP server...",searchPlaceholder:r="Search MCP servers...",emptyText:s="No MCP servers found.",className:i,disabled:o=!1,variant:l,size:c,"aria-label":u,align:d,container:f}){const{data:h=[],isLoading:p,isError:m,error:v}=NP(),{navigate:y,paths:x}=xn();g.useEffect(()=>{if(m){const k=v instanceof Error?v.message:"Failed to load MCP servers";Ke.error(`Error loading MCP servers: ${k}`)}},[m,v]);const b=h.map(k=>({label:k.name,value:k.id})),S=k=>{t?t(k):k&&k!==e&&y(x.mcpServerLink(k))};return a.jsx(Qa,{options:b,value:e,onValueChange:S,placeholder:p?"Loading MCP servers...":n,searchPlaceholder:r,emptyText:s,className:i,disabled:o||p||m,variant:l,size:c,"aria-label":u,align:d,container:f})}function _ar(){const{serverId:e}=jr(),{data:t,isLoading:n}=NP();return e?n?a.jsx(Nx,{}):t?.find(r=>r.id===e)?.name||e:null}function Tar(){const{serverId:e}=jr();return e?a.jsx(vkt,{value:e,...EP,"aria-label":"Switch MCP server"}):null}const E_=({requestContext:e,queryOptions:t}={})=>{const n=Ye();return _t({queryKey:["processors"],queryFn:()=>n.listProcessors(e),...t})},ykt=({processorId:e,requestContext:t,queryOptions:n})=>{const r=Ye();return _t({queryKey:["processor",e],queryFn:()=>r.getProcessor(e).details(t),...n})},Ear=({requestContext:e,queryOptions:t}={})=>{const n=Ye();return kn({mutationFn:async({processorId:r,phase:s,messages:i,agentId:o})=>n.getProcessor(r).execute({phase:s,messages:i,agentId:o,requestContext:e}),...t})};function Iar({value:e,onValueChange:t,placeholder:n="Select a processor...",searchPlaceholder:r="Search processors...",emptyText:s="No processors found.",className:i,disabled:o=!1,variant:l,size:c,"aria-label":u,align:d}){const{data:f={},isLoading:h,isError:p,error:m}=E_(),{navigate:v,paths:y}=xn();g.useEffect(()=>{if(p){const S=m instanceof Error?m.message:"Failed to load processors";Ke.error(`Error loading processors: ${S}`)}},[p,m]);const x=Object.keys(f).filter(S=>{const k=f[S];return k?.phases&&k.phases.length>0}).map(S=>({label:f[S]?.name||S,value:S})),b=S=>{t?t(S):S&&S!==e&&(f[S]?.isWorkflow?v(y.workflowLink(S)+"/graph"):v(y.processorLink(S)))};return a.jsx(Qa,{options:x,value:e,onValueChange:b,placeholder:h?"Loading processors...":n,searchPlaceholder:r,emptyText:s,className:i,disabled:o||h||p,variant:l,size:c,"aria-label":u,align:d})}function Nar(){const{processorId:e}=jr(),{data:t,isLoading:n}=E_();return e?n?a.jsx(Nx,{}):t?.[e]?.name||e:null}function Aar(){const{processorId:e}=jr();return e?a.jsx(Iar,{value:e,...EP,"aria-label":"Switch processor"}):null}const Eoe=[400,401,403,404,501];function js(e){if(!e||typeof e!="object")return!1;if("status"in e&&e.status===401||"statusCode"in e&&e.statusCode===401)return!0;if("message"in e){const t=e.message;if(typeof t=="string")return/\bstatus:\s*401\b/.test(t)}return!1}function Cs(e){if(!e||typeof e!="object")return!1;if("status"in e&&e.status===403||"statusCode"in e&&e.statusCode===403)return!0;if("message"in e){const t=e.message;if(typeof t=="string")return/\bstatus:\s*403\b/.test(t)}return!1}function kk(e){if(!e||typeof e!="object")return!1;if("status"in e&&e.status===404||"statusCode"in e&&e.statusCode===404)return!0;if("message"in e){const t=e.message;if(typeof t=="string")return/\bstatus:\s*404\b/.test(t)}return!1}function BL(e,t){if(!e||typeof e!="object"||!("message"in e))return!1;const n=e.message;return typeof n!="string"?!1:n.includes(`does not support listing ${t}`)}const Par=["Observability storage domain is not available","Scores storage domain is not available"];function VL(e){if(!e||typeof e!="object"||!("message"in e))return!1;const t=e.message;return typeof t!="string"?!1:Par.some(n=>t.includes(n))}function xkt(e){if(!e||typeof e!="object")return!1;if("status"in e){const t=e.status;return Eoe.includes(t)}if("statusCode"in e){const t=e.statusCode;return Eoe.includes(t)}if("message"in e){const t=e.message;if(typeof t=="string")return Eoe.some(n=>new RegExp(`\\bstatus:\\s*${n}\\b`).test(t))}return!1}function $ar(e,t){return xkt(t)?!1:e<3}const Rar=25,Mar=15e3;function Dar(e){return BL(e.state.error,"scores")||VL(e.state.error)?!1:Mar}function Lar(e,t,n){if(e?.pagination?.hasMore)return n+1}function zar(e){const t=new Set;return e.pages.flatMap(n=>n.scores??[]).filter(n=>t.has(n.id)?!1:(t.add(n.id),!0))}const Far=({scorerId:e,entityId:t,entityType:n,queryOptions:r})=>{const s=Ye(),{inView:i,setRef:o}=F0(),l=Mm({queryKey:["scores",e,t,n],queryFn:({pageParam:f})=>s.listScoresByScorerId({scorerId:e,page:f,perPage:Rar,entityId:t,entityType:n}),initialPageParam:0,getNextPageParam:Lar,select:f=>zar(f),refetchInterval:Dar,...r}),{hasNextPage:c,isFetchingNextPage:u,fetchNextPage:d}=l;return g.useEffect(()=>{i&&c&&!u&&d()},[i,c,u,d]),{...l,setEndOfListElement:o}},Bar=e=>{const t=Ye(),[n,r]=g.useState(null),[s,i]=g.useState(!0),[o,l]=g.useState(null);return g.useEffect(()=>{(async()=>{i(!0),l(null);try{const u=await t.getScorer(e);r(u)}catch(u){r(null);const d=u instanceof Error?u:new Error("Error fetching scorer");l(d),console.error("Error fetching scorer",u)}finally{i(!1)}})()},[e,t]),{scorer:n,isLoading:s,error:o}},bkt=({requestContext:e,queryOptions:t}={})=>{const n=Ye();return _t({queryKey:["scorers",e],queryFn:()=>n.listScorers(e),staleTime:0,gcTime:0,...t})},Var=15e3;function Uar(e){return BL(e.state.error,"scores")||VL(e.state.error)?!1:Var}const mke=({traceId:e="",spanId:t="",page:n,queryOptions:r})=>{const s=Ye();return _t({queryKey:["trace-span-scores",e,t,n],queryFn:()=>s.listScoresBySpan({traceId:e,spanId:t,page:n||0,perPage:10}),refetchInterval:Uar,gcTime:0,staleTime:0,...r})},qar=({queryOptions:e}={})=>{const t=Ye();return kn({mutationFn:async({scorerName:n,traceId:r,spanId:s})=>await t.score({scorerName:n,targets:[{traceId:r,spanId:s}]}),...e})},wkt=({scorerId:e,status:t,requestContext:n,queryOptions:r}={})=>{const s=Ye();return _t({queryKey:["stored-scorer",e,t,n],queryFn:()=>e?s.getStoredScorer(e).details(n,{status:t}):null,...r})},Skt=({scorerId:e,requestContext:t,queryOptions:n}={})=>{const r=Ye(),s=mr();return{createStoredScorer:kn({mutationFn:i=>r.createStoredScorer(i),onSuccess:()=>{s.invalidateQueries({queryKey:["stored-scorers"]}),s.invalidateQueries({queryKey:["scorers"]})},...n?.createStoredScorer}),updateStoredScorer:kn({mutationFn:i=>{if(!e)throw new Error("scorerId is required for update");return r.getStoredScorer(e).update(i,t)},onSuccess:()=>{s.invalidateQueries({queryKey:["stored-scorers"]}),s.invalidateQueries({queryKey:["scorers"]}),e&&s.invalidateQueries({queryKey:["stored-scorer",e]})},...n?.updateStoredScorer}),deleteStoredScorer:kn({mutationFn:()=>{if(!e)throw new Error("scorerId is required for delete");return r.getStoredScorer(e).delete(t)},onSuccess:()=>{s.invalidateQueries({queryKey:["stored-scorers"]}),s.invalidateQueries({queryKey:["scorers"]}),e&&s.invalidateQueries({queryKey:["stored-scorer",e]})},...n?.deleteStoredScorer})}},kkt=({scorerId:e,params:t,requestContext:n,queryOptions:r})=>{const s=Ye();return _t({queryKey:["scorer-versions",e,t,n],queryFn:()=>s.getStoredScorer(e).listVersions(t,n),...r})},Qar=({scorerId:e,versionId:t,requestContext:n,queryOptions:r})=>{const s=Ye();return _t({queryKey:["scorer-version",e,t,n],queryFn:()=>s.getStoredScorer(e).getVersion(t,n),...r})},ag=(e,t)=>bkt({...e,requestContext:t});function Zar({value:e,onValueChange:t,placeholder:n="Select a scorer...",searchPlaceholder:r="Search scorers...",emptyText:s="No scorers found.",className:i,disabled:o=!1,variant:l,size:c,"aria-label":u,align:d}){const{data:f={},isLoading:h,isError:p,error:m}=ag(),{navigate:v,paths:y}=xn();g.useEffect(()=>{if(p){const S=m instanceof Error?m.message:"Failed to load scorers";Ke.error(`Error loading scorers: ${S}`)}},[p,m]);const x=Object.keys(f).map(S=>({label:f[S]?.scorer.config.name||S,value:S})),b=S=>{t?t(S):S&&S!==e&&v(y.scorerLink(S))};return a.jsx(Qa,{options:x,value:e,onValueChange:b,placeholder:h?"Loading scorers...":n,searchPlaceholder:r,emptyText:s,className:i,disabled:o||h||p,variant:l,size:c,"aria-label":u,align:d})}function War(){const{scorerId:e}=jr(),{data:t,isLoading:n}=ag();return e?n?a.jsx(Nx,{}):t?.[e]?.scorer.config.name||e:null}function Har(){const{scorerId:e}=jr();return e?a.jsx(Zar,{value:e,...EP,"aria-label":"Switch scorer"}):null}function Gar(){const{scorerId:e}=jr(),{data:t,isLoading:n}=wkt({scorerId:e,status:"draft",queryOptions:{enabled:!!e}});return e?n?a.jsx(Nx,{}):t?.name??"Scorer not found":null}const ko=e=>a.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 8.82265 8.51434",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:[a.jsx("path",{d:"M6.76646 6.16953C6.56909 6.10559 6.40521 5.96585 6.31087 5.78107C6.21653 5.5963 6.19945 5.38161 6.2634 5.18424C6.32735 4.98687 6.46708 4.82299 6.65186 4.72865C6.83663 4.63431 7.05132 4.61723 7.24869 4.68118C7.45933 4.74996 7.6849 4.75913 7.90043 4.70768C8.11596 4.65622 8.31306 4.54615 8.46992 4.38963C8.62678 4.23312 8.73729 4.03626 8.78921 3.82084C8.84114 3.60542 8.83246 3.37984 8.76414 3.16904C8.69582 2.95825 8.57052 2.77046 8.4021 2.62646C8.23368 2.48246 8.02871 2.38785 7.80986 2.35311C7.59101 2.31836 7.36681 2.34484 7.16208 2.4296C6.95734 2.51436 6.78004 2.6541 6.64979 2.83337C6.39274 3.18567 6.05613 3.47228 5.66736 3.66987C5.27858 3.86747 4.84864 3.97046 4.41254 3.97046C3.97643 3.97046 3.54649 3.86747 3.15772 3.66987C2.76895 3.47228 2.43234 3.18567 2.17528 2.83337C2.04528 2.65368 1.86807 2.51346 1.66329 2.42826C1.45852 2.34306 1.23415 2.3162 1.01505 2.35065C0.795944 2.3851 0.590648 2.47951 0.421892 2.62344C0.253137 2.76736 0.127507 2.95519 0.0589124 3.16611C-0.00968171 3.37703 -0.0185632 3.60282 0.0332514 3.81848C0.0850661 4.03414 0.195555 4.23125 0.352484 4.38799C0.509413 4.54472 0.706659 4.65497 0.92238 4.70652C1.1381 4.75808 1.36388 4.74892 1.57472 4.68007C1.77224 4.61634 1.98698 4.63369 2.1717 4.72829C2.35643 4.82289 2.49601 4.987 2.55973 5.18452C2.62346 5.38203 2.60611 5.59677 2.51151 5.7815C2.41691 5.96623 2.2528 6.10581 2.05528 6.16953C1.84456 6.23788 1.65684 6.36317 1.51288 6.53155C1.36893 6.69993 1.27434 6.90485 1.23959 7.12364C1.20483 7.34242 1.23126 7.56656 1.31596 7.77126C1.40065 7.97597 1.5403 8.15326 1.71948 8.28354C1.89865 8.41382 2.11036 8.49201 2.33121 8.50946C2.55205 8.52692 2.77342 8.48296 2.97083 8.38244C3.16825 8.28193 3.33402 8.12877 3.44981 7.93992C3.56561 7.75106 3.62692 7.53386 3.62697 7.31233C3.62697 7.10501 3.70933 6.90619 3.85592 6.7596C4.00251 6.613 4.20134 6.53065 4.40865 6.53065C4.61596 6.53065 4.81479 6.613 4.96138 6.7596C5.10797 6.90619 5.19033 7.10501 5.19033 7.31233C5.19027 7.53399 5.25152 7.75136 5.36731 7.94037C5.4831 8.12939 5.64892 8.2827 5.84642 8.38334C6.04392 8.48399 6.26541 8.52804 6.4864 8.51063C6.70738 8.49322 6.91924 8.41502 7.09854 8.28469C7.27785 8.15436 7.41761 7.97698 7.50237 7.77216C7.58713 7.56734 7.61359 7.34307 7.57882 7.12414C7.54404 6.90522 7.44939 6.70018 7.30534 6.53171C7.16128 6.36323 6.97344 6.23789 6.76257 6.16953H6.76646Z",fill:"currentColor"}),a.jsx("path",{d:"M4.41198 2.40337C5.07565 2.40337 5.61367 1.86536 5.61367 1.20168C5.61367 0.538012 5.07565 0 4.41198 0C3.74831 0 3.2103 0.538012 3.2103 1.20168C3.2103 1.86536 3.74831 2.40337 4.41198 2.40337Z",fill:"currentColor"})]}),gke=e=>a.jsx("svg",{width:"16",height:"16",viewBox:"0 0 8.64637 9.45103",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:a.jsx("path",{d:"M7.80735 5.87241C7.63209 5.97219 7.43696 6.06166 7.22844 6.13866C6.46456 6.42068 5.43714 6.58649 4.32296 6.58649C3.20873 6.58649 2.18135 6.4207 1.41747 6.13866C1.20889 6.06164 1.01385 5.97223 0.838558 5.87241V7.59003C0.838558 7.62341 0.855765 7.70759 1.00172 7.83512C1.14707 7.96201 1.38219 8.09563 1.70829 8.21605C2.3572 8.45563 3.28149 8.61268 4.32296 8.61269C5.36456 8.61269 6.28937 8.45568 6.9383 8.21605C7.26428 8.09566 7.49888 7.96198 7.64419 7.83512C7.79024 7.70754 7.80735 7.62342 7.80735 7.59003V5.87241ZM7.80735 3.00789C7.63214 3.10763 7.4369 3.19647 7.22844 3.27345C6.46455 3.55549 5.43719 3.72129 4.32296 3.72129C3.20868 3.72128 2.18136 3.55552 1.41747 3.27345C1.20896 3.19645 1.01381 3.10766 0.838558 3.00789V4.72551C0.838558 4.7589 0.855657 4.84301 1.00172 4.97059C1.14707 5.09749 1.38219 5.23111 1.70829 5.35153C2.3572 5.59109 3.28154 5.74747 4.32296 5.74748C5.36456 5.74748 6.28937 5.59116 6.9383 5.35153C7.26432 5.23112 7.49887 5.09747 7.64419 4.97059C7.7536 4.87505 7.79089 4.80404 7.80257 4.76033L7.80735 4.72551V3.00789ZM7.80735 1.86099C7.80735 1.82758 7.79045 1.74291 7.64419 1.61522C7.49887 1.48838 7.26421 1.35534 6.9383 1.23497C6.28937 0.995339 5.36456 0.838331 4.32296 0.838331C3.28149 0.83834 2.3572 0.995383 1.70829 1.23497C1.38219 1.35539 1.14707 1.48832 1.00172 1.61522C0.855475 1.7429 0.838558 1.82758 0.838558 1.86099C0.838673 1.89462 0.855968 1.97882 1.00172 2.10607C1.14707 2.23297 1.38219 2.3659 1.70829 2.48632C2.3572 2.7259 3.28149 2.88295 4.32296 2.88296C5.36456 2.88296 6.28937 2.72595 6.9383 2.48632C7.26421 2.36595 7.49887 2.23291 7.64419 2.10607C7.78996 1.97881 7.80724 1.89462 7.80735 1.86099ZM8.64637 7.59003C8.64637 7.95465 8.44458 8.25006 8.1958 8.46728C7.94608 8.68529 7.60876 8.86274 7.22844 9.00318C6.46455 9.28522 5.43718 9.45102 4.32296 9.45102C3.20869 9.45101 2.18135 9.28525 1.41747 9.00318C1.03715 8.86274 0.699831 8.68529 0.450113 8.46728C0.201377 8.25007 0.000227451 7.9546 0.000227451 7.59003V1.86099C0.000227451 1.49643 0.201388 1.20095 0.450113 0.983742C0.699831 0.765728 1.03715 0.588275 1.41747 0.447838C2.18136 0.165769 3.20868 8.74396e-06 4.32296 0C5.43719 0 6.46455 0.165797 7.22844 0.447838C7.60876 0.588275 7.94608 0.765728 8.1958 0.983742C8.44457 1.20096 8.64637 1.49638 8.64637 1.86099V7.59003Z",fill:"currentColor"})}),Kar=e=>a.jsx("svg",{width:"16",height:"16",viewBox:"0 0 9.83952 9.3295",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:a.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M7.67171 0.838331H6.70163V4.05307L9.68767 8.09999C10.0634 8.6093 9.69869 9.32932 9.06643 9.3295H0.772551C0.140289 9.3293 -0.223777 8.60929 0.151995 8.09999L3.13804 4.05307V0.838331H2.17136V0H7.67171V0.838331ZM3.97705 4.32955L3.89513 4.44015L2.34681 6.53802H7.49285L5.94453 4.44015L5.86261 4.32955V0.860859H3.97705V4.32955Z",fill:"currentColor"})}),Yar=e=>a.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 10.0412 8.39395",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:[a.jsx("path",{d:"M0 0.916539C0 0.410349 0.410349 0 0.916539 0C1.42273 0 1.83308 0.410349 1.83308 0.916539C1.83308 1.42273 1.42273 1.83308 0.916539 1.83308C0.410349 1.83308 0 1.42273 0 0.916539Z",fill:"currentColor"}),a.jsx("path",{d:"M2.88569 0.916539C2.88569 0.410349 3.29604 0 3.80223 0C4.30842 0 4.71877 0.410349 4.71877 0.916539C4.71877 1.42273 4.30842 1.83308 3.80223 1.83308C3.29604 1.83308 2.88569 1.42273 2.88569 0.916539Z",fill:"currentColor"}),a.jsx("path",{d:"M5.77139 0.916539C5.77139 0.410349 6.18174 0 6.68793 0H9.12465C9.63084 0 10.0412 0.410349 10.0412 0.916539C10.0412 1.42273 9.63084 1.83308 9.12465 1.83308H6.68793C6.18174 1.83308 5.77139 1.42273 5.77139 0.916539Z",fill:"currentColor"}),a.jsx("path",{d:"M0 4.19696C0 3.69077 0.410351 3.28042 0.916541 3.28042C1.42273 3.28042 1.83308 3.69077 1.83308 4.19696C1.83308 4.70315 1.42273 5.1135 0.916541 5.1135C0.410351 5.1135 0 4.70315 0 4.19696Z",fill:"currentColor"}),a.jsx("path",{d:"M2.8857 4.19694C2.8857 3.69075 3.29605 3.2804 3.80224 3.2804C4.30843 3.2804 4.71877 3.69075 4.71877 4.19694C4.71877 4.70313 4.30843 5.11348 3.80224 5.11348C3.29605 5.11348 2.8857 4.70313 2.8857 4.19694Z",fill:"currentColor"}),a.jsx("path",{d:"M5.77139 4.19694C5.77139 3.69075 6.18174 3.2804 6.68793 3.2804H9.12466C9.63085 3.2804 10.0412 3.69075 10.0412 4.19694C10.0412 4.70313 9.63085 5.11348 9.12466 5.11348H6.68793C6.18174 5.11348 5.77139 4.70313 5.77139 4.19694Z",fill:"currentColor"}),a.jsx("path",{d:"M0 7.47738C0 6.97119 0.410351 6.56084 0.916541 6.56084C1.42273 6.56084 1.83308 6.97119 1.83308 7.47738C1.83308 7.98357 1.42273 8.39392 0.916541 8.39392C0.410351 8.39392 0 7.98357 0 7.47738Z",fill:"currentColor"}),a.jsx("path",{d:"M2.8857 7.47741C2.8857 6.97122 3.29605 6.56087 3.80224 6.56087C4.30843 6.56087 4.71877 6.97122 4.71877 7.47741C4.71877 7.9836 4.30843 8.39395 3.80224 8.39395C3.29605 8.39395 2.8857 7.9836 2.8857 7.47741Z",fill:"currentColor"}),a.jsx("path",{d:"M5.77139 7.47741C5.77139 6.97122 6.18174 6.56087 6.68793 6.56087H9.12466C9.63085 6.56087 10.0412 6.97122 10.0412 7.47741C10.0412 7.9836 9.63085 8.39395 9.12466 8.39395H6.68793C6.18174 8.39395 5.77139 7.9836 5.77139 7.47741Z",fill:"currentColor"})]}),I_=e=>a.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 9.52233 10.4982",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:[a.jsx("path",{d:"M2.39065 4.27882L4.93898 1.73049C5.10578 1.56368 5.37622 1.56368 5.54303 1.73049C5.70983 1.89729 5.70983 2.16773 5.54303 2.33454L2.9947 4.88287C2.53924 5.33834 2.53929 6.0768 2.99475 6.53226C3.45022 6.9877 4.18863 6.98771 4.64409 6.53226L7.19242 3.98393C7.35922 3.81713 7.62967 3.81714 7.79647 3.98393C7.96328 4.15074 7.96328 4.42118 7.79647 4.58798L5.24814 7.13631C4.45907 7.92537 3.17978 7.92536 2.39071 7.13631C1.60163 6.34724 1.60158 5.0679 2.39065 4.27882Z",fill:"currentColor"}),a.jsx("path",{d:"M3.50354 5.43862C3.5236 5.3983 3.55044 5.36049 3.58404 5.32688L6.06565 2.84527C6.52112 2.3898 6.52112 1.65128 6.06565 1.19581C5.61018 0.740366 4.87172 0.740412 4.41626 1.19587L0.729138 4.88287C0.562334 5.04967 0.291892 5.04968 0.125089 4.88287C-0.0416875 4.71607 -0.0417052 4.44562 0.125089 4.27882L3.81221 0.591824C4.60128 -0.197241 5.88062 -0.197289 6.6697 0.591765C7.12856 1.05062 7.32058 1.67529 7.24578 2.27292C7.84449 2.19687 8.47073 2.38872 8.93052 2.84849C9.7196 3.63757 9.7196 4.91697 8.93052 5.70605L8.20316 6.44191L6.20449 8.44058C5.83765 8.80741 5.83765 9.40219 6.20449 9.76902C6.37128 9.93582 6.37129 10.2063 6.20449 10.3731C6.03769 10.5399 5.76724 10.5399 5.60044 10.3731C4.9 9.67263 4.9 8.53697 5.60044 7.83653L7.59911 5.83786L8.32647 5.102C8.78194 4.64653 8.78194 3.90801 8.32647 3.45254C7.871 2.9971 7.13254 2.99714 6.67707 3.4526L4.17576 5.95392C4.00896 6.12072 3.73851 6.12071 3.57171 5.95392C3.43204 5.81425 3.40932 5.60193 3.50354 5.43862Z",fill:"currentColor"})]}),Xar=e=>a.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 8.98824 8.33142",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:[a.jsx("path",{d:"M5.70011e-05 6.409V0H1.04865V6.409C1.04875 6.89152 1.43994 7.28283 1.92248 7.28283H8.3581V8.33142H1.92248C0.860814 8.33142 0.000149953 7.47065 5.70011e-05 6.409Z",fill:"currentColor"}),a.jsx("path",{d:"M8.08006 0.945713C8.27714 0.733828 8.6087 0.72151 8.82077 0.918405C9.03289 1.11551 9.04518 1.44767 8.84808 1.6598L6.08595 4.63218C5.90127 4.83085 5.59525 4.85557 5.38074 4.68953L4.03177 3.64571L2.74765 5.07183C2.55386 5.28688 2.22206 5.30441 2.00694 5.11074C1.79189 4.91695 1.77435 4.58515 1.96803 4.37003L3.57915 2.58278L3.65357 2.51451C3.83887 2.37494 4.09997 2.37165 4.28982 2.51861L5.64358 3.56652L8.08006 0.945713Z",fill:"currentColor"})]});function YO(e){return a.jsx("svg",{width:"16",height:"16",viewBox:"0 0 10.123 10.123",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:a.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M4.50195 1.53809H5.62109V0H6.75098V1.53809H7.5293L7.64258 1.54395C8.19939 1.60066 8.63379 2.0708 8.63379 2.64258V3.37305H10.123V4.50195H8.63379V5.62109H10.123V6.75H8.63379V7.57812L8.62891 7.69141C8.57589 8.2109 8.16211 8.62387 7.64258 8.67676L7.5293 8.68262H6.75098V10.123H5.62109V8.68262H4.50195V10.123H3.37305V8.68262H2.59375L2.48047 8.67676C1.96102 8.62383 1.54817 8.21082 1.49512 7.69141L1.48926 7.57812V6.75H0V5.62109H1.48926V4.50195H0V3.37305H1.48926V2.64258C1.48926 2.07084 1.92371 1.60071 2.48047 1.54395L2.59375 1.53809H3.37305V0H4.50195V1.53809ZM2.61914 7.55273H7.50488V2.66699H2.61914V7.55273Z",fill:"currentColor"})})}const Jar=e=>a.jsx("svg",{width:"16",height:"16",viewBox:"0 0 11.185 11.185",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:a.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M9.57258 2.71626C9.57245 2.19794 9.14778 1.77075 8.61819 1.77075H2.56605C2.0377 1.77075 1.61179 2.19752 1.61165 2.71626V6.51162C1.61179 7.02856 2.03401 7.45487 2.5616 7.45713L3.12802 7.45935V9.21487L5.52178 7.55857L5.66764 7.45713H8.61819C9.14653 7.45713 9.57245 7.03036 9.57258 6.51162V2.71626ZM10.7099 6.51162C10.7097 7.66541 9.76766 8.59441 8.61819 8.59441H6.0223L3.51081 10.3336C3.25841 10.5083 2.86505 10.6555 2.4809 10.4558C2.09483 10.2551 1.99075 9.84577 1.99075 9.53473V8.51222C1.11705 8.26321 0.474488 7.46395 0.474378 6.51162V2.71626C0.474511 1.56248 1.41657 0.633479 2.56605 0.633479H8.61819C9.77051 0.633479 10.7097 1.56448 10.7099 2.71626V6.51162Z",fill:"currentColor"})}),Ax=e=>a.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 8.94379 8.92126",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:[a.jsx("path",{d:"M6.13251 5.43413C6.51629 5.43413 6.82744 5.74533 6.82748 6.1291C6.82748 6.5129 6.51631 6.82407 6.13251 6.82407C5.74877 6.824 5.43754 6.51286 5.43754 6.1291C5.43759 5.74537 5.74879 5.4342 6.13251 5.43413Z",fill:"currentColor"}),a.jsx("path",{d:"M5.92771 2.29722C6.13122 2.09376 6.46147 2.09379 6.665 2.29722C6.86843 2.50075 6.86846 2.831 6.665 3.03451L3.03724 6.66227C2.83373 6.86578 2.5035 6.86572 2.29995 6.66227C2.0965 6.45872 2.09644 6.12849 2.29995 5.92498L5.92771 2.29722Z",fill:"currentColor"}),a.jsx("path",{d:"M2.842 2.12791C3.22572 2.12799 3.53694 2.43914 3.53696 2.82288C3.53696 3.20664 3.22573 3.51777 2.842 3.51785C2.45819 3.51785 2.14703 3.20668 2.14703 2.82288C2.14705 2.4391 2.45821 2.12791 2.842 2.12791Z",fill:"currentColor"}),a.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M7.38455 0.00887484C8.26052 0.0979278 8.94379 0.837945 8.94379 1.73742V7.18384C8.94369 8.08322 8.26046 8.82334 7.38455 8.91238L7.20705 8.92126H1.73742L1.55992 8.91238C0.683828 8.82351 0.000101213 8.08336 0 7.18384V1.73742C0 0.837813 0.683761 0.0977507 1.55992 0.00887484L1.73742 0H7.20705L7.38455 0.00887484ZM1.73742 0.839013C1.24121 0.839013 0.839013 1.24121 0.839013 1.73742V7.18384C0.839121 7.67996 1.24128 8.08293 1.73742 8.08293H7.20705C7.70305 8.08276 8.10535 7.67985 8.10546 7.18384V1.73742C8.10546 1.24131 7.70312 0.83918 7.20705 0.839013H1.73742Z",fill:"currentColor"})]}),elr=e=>a.jsx("svg",{width:"17",height:"18",viewBox:"0 0 17 18",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:a.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M8.40864 11.9983C7.58064 11.9733 6.84164 11.6153 6.31564 11.0563C6.31464 11.0563 6.31464 11.0553 6.31464 11.0553C5.78864 10.4963 5.47564 9.73633 5.50064 8.90833C5.52564 8.08033 5.88464 7.34133 6.44364 6.81533C7.00264 6.28833 7.76264 5.97633 8.59064 6.00133C9.41864 6.02633 10.1576 6.38433 10.6836 6.94333H10.6846C11.2106 7.50333 11.5236 8.26233 11.4986 9.09033C11.4726 9.91833 11.1146 10.6583 10.5556 11.1843C9.99664 11.7103 9.23664 12.0233 8.40864 11.9983ZM16.1266 8.15033L14.3606 7.74033C14.2316 7.14133 14.0146 6.57633 13.7216 6.05733L14.7726 4.57933C14.9116 4.38533 14.8926 4.12033 14.7296 3.94633L13.9206 3.08733C13.7576 2.91333 13.4946 2.87933 13.2916 3.00533L11.7526 3.96533C11.2526 3.64133 10.7016 3.39033 10.1116 3.22633L9.80964 1.43833C9.76964 1.20333 9.56964 1.02833 9.33164 1.02133L8.15264 0.985326C7.91364 0.978326 7.70364 1.14033 7.64964 1.37233L7.24064 3.13933C6.64164 3.26733 6.07664 3.48433 5.55664 3.77733L4.07864 2.72633C3.88464 2.58833 3.61964 2.60633 3.44664 2.76933L2.58664 3.57833C2.41364 3.74133 2.37964 4.00533 2.50564 4.20733L3.46564 5.74633C3.14164 6.24633 2.89064 6.79833 2.72564 7.38833L0.937635 7.68933C0.702635 7.72933 0.528635 7.92933 0.520635 8.16733L0.485635 9.34733C0.477635 9.58533 0.639635 9.79533 0.872635 9.84933L2.63864 10.2583C2.76764 10.8573 2.98464 11.4233 3.27764 11.9423L2.22564 13.4203C2.08764 13.6143 2.10564 13.8793 2.26964 14.0523L3.07864 14.9123C3.24164 15.0853 3.50464 15.1203 3.70664 14.9933L5.24564 14.0333C5.74663 14.3583 6.29764 14.6093 6.88764 14.7733L7.18964 16.5613C7.22864 16.7963 7.42864 16.9713 7.66764 16.9783L8.84663 17.0143C9.08564 17.0213 9.29564 16.8593 9.34964 16.6273L9.75864 14.8603C10.3576 14.7323 10.9226 14.5153 11.4416 14.2213L12.9206 15.2733C13.1146 15.4113 13.3786 15.3933 13.5526 15.2293L14.4116 14.4213C14.5856 14.2573 14.6196 13.9943 14.4936 13.7923L13.5336 12.2533C13.8576 11.7523 14.1086 11.2013 14.2726 10.6113L16.0616 10.3103C16.2966 10.2703 16.4706 10.0703 16.4776 9.83233L16.5136 8.65233C16.5206 8.41433 16.3586 8.20433 16.1266 8.15033Z",fill:"currentColor"})}),ud=e=>a.jsx("svg",{width:"16",height:"16",viewBox:"0 0 11.185 11.185",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:a.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M5.0293 1.16491L4.81958 0.801671L4.81955 0.801686L5.0293 1.16491ZM5.75391 1.16491L5.96365 0.801686L5.96363 0.801671L5.75391 1.16491ZM9.04492 3.06531L9.25474 2.70212L9.25467 2.70208L9.04492 3.06531ZM9.40723 7.49304L9.82666 7.49332V7.49304H9.40723ZM9.04492 8.11999L8.8352 7.75675L8.83518 7.75676L9.04492 8.11999ZM5.75391 10.0204L5.96363 10.3836L5.96365 10.3836L5.75391 10.0204ZM5.0293 10.0204L4.81955 10.3836L4.81963 10.3837L5.0293 10.0204ZM1.73828 8.11999L1.94803 7.75676L1.948 7.75675L1.73828 8.11999ZM1.37598 7.49304H0.956538L0.956538 7.49332L1.37598 7.49304ZM1.73828 3.06531L1.94802 3.42854L1.94803 3.42853L1.73828 3.06531ZM5.59277 3.38366L5.59283 2.96423H5.59277V3.38366ZM3.38379 5.59167L2.96435 5.59159V5.59167H3.38379ZM5.59277 7.80066V8.2201H5.59283L5.59277 7.80066ZM7.80078 5.59167H8.22022V5.59159L7.80078 5.59167ZM5.0293 1.16491L5.23902 1.52816C5.33331 1.47372 5.44989 1.47372 5.54419 1.52816L5.75391 1.16491L5.96363 0.801671C5.60978 0.59738 5.17342 0.59738 4.81958 0.801671L5.0293 1.16491ZM5.75391 1.16491L5.54416 1.52814L8.83518 3.42853L9.04492 3.06531L9.25467 2.70208L5.96365 0.801686L5.75391 1.16491ZM9.04492 3.06531L8.83511 3.42849C8.92979 3.48319 8.98779 3.5839 8.98779 3.69226H9.40723H9.82666C9.82666 3.28328 9.60799 2.90619 9.25474 2.70212L9.04492 3.06531ZM9.40723 3.69226H8.98779V7.49304H9.40723H9.82666V3.69226H9.40723ZM9.40723 7.49304L8.98779 7.49276C8.98772 7.6015 8.92949 7.70231 8.8352 7.75675L9.04492 8.11999L9.25464 8.48324C9.60821 8.2791 9.82639 7.90167 9.82666 7.49332L9.40723 7.49304ZM9.04492 8.11999L8.83518 7.75676L5.54416 9.65715L5.75391 10.0204L5.96365 10.3836L9.25467 8.48322L9.04492 8.11999ZM5.75391 10.0204L5.54419 9.65714C5.44996 9.71154 5.33331 9.71156 5.23897 9.65711L5.0293 10.0204L4.81963 10.3837C5.17339 10.5878 5.60977 10.5879 5.96363 10.3836L5.75391 10.0204ZM5.0293 10.0204L5.23904 9.65715L1.94803 7.75676L1.73828 8.11999L1.52854 8.48322L4.81955 10.3836L5.0293 10.0204ZM1.73828 8.11999L1.948 7.75675C1.85371 7.70231 1.79549 7.6015 1.79541 7.49276L1.37598 7.49304L0.956538 7.49332C0.956809 7.90167 1.17499 8.2791 1.52856 8.48324L1.73828 8.11999ZM1.37598 7.49304H1.79542V3.69226H1.37598H0.956538V7.49304H1.37598ZM1.37598 3.69226H1.79542C1.79542 3.58378 1.85339 3.48318 1.94802 3.42854L1.73828 3.06531L1.52854 2.70207C1.17507 2.90617 0.956538 3.2833 0.956538 3.69226H1.37598ZM1.73828 3.06531L1.94803 3.42853L5.23904 1.52814L5.0293 1.16491L4.81955 0.801686L1.52854 2.70208L1.73828 3.06531ZM5.59277 3.38366V2.96423C4.14162 2.96423 2.96463 4.14015 2.96435 5.59159L3.38379 5.59167L3.80323 5.59175C3.80342 4.60382 4.60458 3.8031 5.59277 3.8031V3.38366ZM3.38379 5.59167H2.96435C2.96435 7.04322 4.14132 8.2201 5.59277 8.2201V7.80066V7.38122C4.6046 7.38122 3.80323 6.57991 3.80323 5.59167H3.38379ZM5.59277 7.80066L5.59283 8.2201C7.04429 8.2199 8.22022 7.04294 8.22022 5.59167H7.80078H7.38134C7.38134 6.57999 6.58061 7.38108 5.59272 7.38122L5.59277 7.80066ZM7.80078 5.59167L8.22022 5.59159C8.21994 4.14043 7.04398 2.96443 5.59283 2.96423L5.59277 3.38366L5.59272 3.8031C6.58062 3.80324 7.38115 4.60374 7.38134 5.59175L7.80078 5.59167Z",fill:"currentColor"})}),px=e=>a.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 9.45892 8.88606",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:[a.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"}),a.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"}),a.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"}),a.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"})]}),tlr=e=>a.jsx("svg",{width:"16",height:"16",viewBox:"0 0 9.55888 8.30616",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:a.jsx("path",{d:"M0 7.18794V1.11823C-4.80684e-08 0.5005 0.5005 2.79299e-06 1.11823 0H3.17924C3.48658 0 3.78038 0.126314 3.99163 0.349532L5.09347 1.5135C5.14625 1.56923 5.21948 1.60085 5.29623 1.60088H8.44065C9.05838 1.60088 9.55888 2.10206 9.55888 2.7198V7.18794C9.55888 7.80567 9.05838 8.30616 8.44065 8.30616H1.11823C0.500524 8.30614 4.41663e-06 7.80565 0 7.18794ZM0.838331 7.18794C0.838332 7.34235 0.963819 7.46781 1.11823 7.46783H8.44065C8.59509 7.46783 8.72055 7.34237 8.72055 7.18794V2.7198C8.72055 2.56536 8.59509 2.4399 8.44065 2.4399H5.29623C4.98896 2.43986 4.69506 2.31353 4.48384 2.09037L3.38268 0.925714C3.32987 0.869949 3.25604 0.838331 3.17924 0.838331H1.11823C0.963799 0.838334 0.838331 0.963798 0.838331 1.11823V7.18794Z",fill:"currentColor"})}),nlr=typeof window<"u"&&window.MASTRA_SIGNALS_UI==="true",rlr={name:"Intelligence",url:"/intelligence",activePaths:["/intelligence"],Icon:nht,isOnMastraPlatform:!0,hidden:!nlr},vke=[{key:"primitives",title:"Primitives",items:[{name:"Agents",url:"/agents",Icon:ko,isOnMastraPlatform:!0},{name:"Prompts",url:"/prompts",Icon:Jar,isOnMastraPlatform:!0},{name:"Workflows",url:"/workflows",Icon:Ol,isOnMastraPlatform:!0},{name:"Processors",url:"/processors",Icon:YO,isOnMastraPlatform:!1,foldable:!0},{name:"MCP Servers",url:"/mcps",Icon:I_,isOnMastraPlatform:!0,foldable:!0},{name:"Tools",url:"/tools",Icon:ud,isOnMastraPlatform:!0,foldable:!0},{name:"Workspaces",url:"/workspaces",Icon:tlr,isOnMastraPlatform:!0,foldable:!0}]},{key:"evaluation",title:"Evaluation",items:[{name:"Scorers",url:"/scorers",Icon:Ax,isOnMastraPlatform:!0},{name:"Datasets",url:"/datasets",Icon:gke,isOnMastraPlatform:!0},{name:"Experiments",url:"/experiments",Icon:Kar,isOnMastraPlatform:!0},{name:"Review Queue",url:"/experiments/review-queue",Icon:J3,isOnMastraPlatform:!0}]},{key:"observability",title:"Observability",items:[{name:"Metrics",url:"/metrics",Icon:Xar,isOnMastraPlatform:!0},{name:"Traces",url:"/traces",Icon:px,isOnMastraPlatform:!0},rlr,{name:"Logs",url:"/logs",Icon:Yar,isOnMastraPlatform:!0}]}],yke=[{name:"Settings",url:"/settings",Icon:elr,isOnMastraPlatform:!1},{name:"Resources",url:"/resources",Icon:Fft,isOnMastraPlatform:!0}],slr=[...vke.flatMap(e=>e.items),...yke];function ilr(e){return slr.find(t=>t.url===e)}function _s(e,t){const n=ilr(e);if(!n)throw new Error(`navCrumb: unknown nav url "${e}"`);return{id:`nav:${e}`,label:n.name,icon:n.Icon,to:e,...t}}const xke=e=>{if(!e)return"";try{return decodeURIComponent(e)}catch{return e}},bke=e=>{const t=xke(e);return t.length>8?`${t.slice(0,8)}...`:t},Okt={id:"agent",Component:uar,Switcher:dar},olr={id:"scorer",Component:War,Switcher:Har},alr={id:"processor",Component:Nar,Switcher:Aar},llr={id:"mcp-server",Component:_ar,Switcher:Tar},rVe={id:"workflow",Component:Ror,Switcher:Mor},oK={id:"dataset",Component:bar,Switcher:war},jkt={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",yml:"yaml",yaml:"yaml",diff:"diff",patch:"diff",css:"css",scss:"css",html:"html",htm:"html",xml:"xml",svg:"xml",sql:"sql"};let Ioe=null;function clr(){return Ioe||(Ioe=(async()=>{const[{createHighlighterCore:e},{createJavaScriptRegexEngine:t}]=await Promise.all([Ii(()=>import("./core-DAjwlaOw.js"),__vite__mapDeps([0,1,2,3,4]),import.meta.url),Ii(()=>import("./engine-javascript-DSQaR0Yq.js"),__vite__mapDeps([5,2,3]),import.meta.url)]);return e({themes:[Ii(()=>import("./github-light-DAi9KRSo.js"),[],import.meta.url),Ii(()=>import("./github-dark-DHJKELXO.js"),[],import.meta.url)],langs:[Ii(()=>import("./javascript-ySlJ1b_l.js"),[],import.meta.url),Ii(()=>import("./typescript-Dj6nwHGl.js"),[],import.meta.url),Ii(()=>import("./tsx-B6W0miNI.js"),[],import.meta.url),Ii(()=>import("./jsx-BAng5TT0.js"),[],import.meta.url),Ii(()=>import("./json-BQoSv7ci.js"),[],import.meta.url),Ii(()=>import("./bash-atvbtKCR.js"),[],import.meta.url),Ii(()=>import("./markdown-UIAJJxZW.js"),[],import.meta.url),Ii(()=>import("./python-DhUJRlN_.js"),[],import.meta.url),Ii(()=>import("./yaml-CVw76BM1.js"),[],import.meta.url),Ii(()=>import("./diff-BgYniUM_.js"),[],import.meta.url),Ii(()=>import("./css-BPhBrDlE.js"),[],import.meta.url),Ii(()=>import("./html-C2L_23MC.js"),__vite__mapDeps([6,7,8]),import.meta.url),Ii(()=>import("./xml-DGRTSKzu.js"),[],import.meta.url),Ii(()=>import("./sql-COK4E0Yg.js"),[],import.meta.url)],engine:t()})})()),Ioe}async function ulr(e,t){const n=jkt[t?.toLowerCase()];if(!n)return null;const r=await clr(),{tokens:s}=r.codeToTokens(e,{lang:n,defaultColor:!1,themes:{light:"github-light",dark:"github-dark"}});return s}function Ckt(e){const t=e?.split(".").pop()?.toLowerCase();return t?jkt[t]:void 0}function dlr({children:e,tooltip:t}){const r=`${typeof e=="string"?e.replace(/\s*\([^)]*\)/g,""):"Request context"} details`;return a.jsxs("div",{className:"flex items-center gap-1.5",children:[a.jsx(ut,{children:e}),t&&a.jsx(mc,{delay:10,children:a.jsxs(Ln,{children:[a.jsx(Rn,{asChild:!0,children:a.jsx("button",{type:"button","aria-label":r,className:Z(Fn,jn,"rounded-sm",Ri),children:a.jsx(At,{size:"xs",children:a.jsx(pp,{})})})}),a.jsx(Mn,{side:"top",className:"max-w-60",children:t})]})})]})}let sVe;const _kt=()=>sVe??=Promise.all([Ii(()=>import("./standalone-Dfz2oS5J.js"),[],import.meta.url),Ii(()=>import("./babel-lWBcy2sH.js"),[],import.meta.url),Ii(()=>import("./estree-Dd9JfUIE.js"),[],import.meta.url)]).catch(e=>{throw sVe=void 0,e}),v5=async e=>{const[t,n,r]=await _kt();return await t.format(e,{semi:!1,parser:"json",printWidth:80,tabWidth:2,plugins:[n,r]})},Tkt=async e=>{const[t,n,r]=await _kt();return await t.format(e,{parser:"babel-ts",printWidth:80,tabWidth:2,plugins:[n,r]})},aQ=e=>{try{const t=JSON.parse(e);return!!t&&typeof t=="object"}catch{return!1}},flr=ki(gt(),URn());function Noe(e,t){if(!e)return"__custom__";for(const[n,r]of Object.entries(e))if(JSON.stringify(r)===t)return n;return"__custom__"}function hlr(e){try{return JSON.stringify(JSON.parse(e))}catch{return null}}const Ekt=({label:e,presets:t,value:n,onSave:r,editorClassName:s="h-[400px]",labelTooltip:i,headerActions:o})=>{const l=JSON.stringify(n??{}),c=JSON.stringify(n??{},null,2),[u,d]=g.useState(c),[f,h]=g.useState(c),[p,m]=g.useState(()=>Noe(t,l)),{handleCopy:v}=Fm({text:u}),[y,x]=g.useState(l);y!==l&&(x(l),d(c),h(c),m(Noe(t,l)));const b=g.useMemo(()=>{const N=hlr(u);return N?N!==l:u!==f},[l,u,f]),S=()=>{let N;try{N=JSON.parse(u)}catch{Ke.error("Invalid JSON");return}const I=flr.safeParse(N);if(!I.success){Ke.error(`${e} must be a JSON object`);return}r(I.data)},k=()=>{d(f),m(Noe(t,l))},j=Z(Fn,jn),C=async()=>{if(!aQ(u)){Ke.error("Invalid JSON");return}const N=await v5(u);d(N)},T=async N=>{if(m(N),N==="__custom__"||!t)return;const I=t[N];if(I){const A=await v5(JSON.stringify(I));d(A)}},_=N=>{d(N),p!=="__custom__"&&m("__custom__")};return a.jsx(mc,{children:a.jsxs("div",{children:[a.jsxs(ft,{children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs(dlr,{tooltip:i,children:[e," (JSON)"]}),a.jsxs("div",{className:"flex items-center gap-2",children:[o,a.jsxs(Ln,{children:[a.jsx(Rn,{asChild:!0,children:a.jsx("button",{type:"button",onClick:C,className:j,children:a.jsx(At,{children:a.jsx(Ua,{})})})}),a.jsxs(Mn,{children:["Format the ",e," JSON"]})]}),a.jsxs(Ln,{children:[a.jsx(Rn,{asChild:!0,children:a.jsx("button",{type:"button",onClick:v,className:j,children:a.jsx(At,{children:a.jsx(Lm,{})})})}),a.jsxs(Mn,{children:["Copy ",e]})]})]})]}),t&&Object.keys(t).length>0&&a.jsxs(ft,{children:[a.jsxs(ut,{className:"sr-only",children:[e," preset"]}),a.jsxs(Vr,{value:p,onValueChange:T,children:[a.jsx(qr,{children:a.jsx(Ur,{placeholder:"Select a preset..."})}),a.jsxs(Qr,{children:[a.jsx(ir,{value:"__custom__",children:"Custom"}),Object.keys(t).map(N=>a.jsx(ir,{value:N,children:N},N))]})]})]}),a.jsx(Or,{value:u,onChange:_,showCopyButton:!1,className:s})]}),a.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[b&&a.jsx(de,{variant:"default",size:"icon-md",type:"button",tooltip:`Revert ${e} changes`,onClick:k,children:a.jsx(Dn,{})}),a.jsx(de,{icon:a.jsx(dr,{}),type:"button",onClick:S,children:"Save"})]})]})})},plr={align:"shift"};function Ikt({label:e,icon:t,open:n,onOpenChange:r,children:s}){return a.jsxs(_p,{open:n,onOpenChange:r,children:[a.jsx(of,{variant:"ghost",size:"icon-md",type:"button",tooltip:e,"aria-label":e,children:t}),a.jsx(lh,{align:"start",collisionAvoidance:plr,className:"w-[min(480px,calc(100vw-2rem))] p-0",children:a.jsx("div",{onSubmit:i=>i.stopPropagation(),children:a.jsx(Nr,{className:"w-full",maxHeight:"min(600px, calc(100dvh - 8rem))",children:a.jsx("div",{className:"space-y-4 p-4",children:s})})})})]})}function mlr(){return g.useMemo(()=>{const e=typeof window<"u"?window.MASTRA_REQUEST_CONTEXT_PRESETS:void 0;if(!e||e==="%%MASTRA_REQUEST_CONTEXT_PRESETS%%")return null;try{const t=JSON.parse(e);if(typeof t=="object"&&t!==null&&!Array.isArray(t))return t}catch{console.warn("Failed to parse request context presets")}return null},[])}function wke({entityType:e,entityId:t}){const[n,r]=g.useState(!1),[s,i]=xr(e,t),o=mlr(),l=c=>{i(c),Ke.success("Request context saved locally"),r(!1)};return a.jsx(Ikt,{label:"Request context",icon:a.jsx(cTn,{}),open:n,onOpenChange:r,children:a.jsx(Ekt,{label:"Request Context",presets:o,value:s,onSave:l,editorClassName:"h-[260px]"})})}function Nkt({entityType:e,entityId:t,extraFields:n,onSaveExtra:r,onOpenChange:s}){const[i,o]=g.useState(!1),[l,c]=rke(e,t),u=f=>{o(f),s?.(f)},d=f=>{c(f),r?.(),Ke.success("Run options saved locally"),u(!1)};return a.jsxs(Ikt,{label:"Run options",icon:a.jsx(px,{}),open:i,onOpenChange:u,children:[n,a.jsx(Ekt,{label:"Tracing Options",value:l,onSave:d,editorClassName:"h-[260px]"})]})}function glr({workflowId:e,resourceId:t,setResourceId:n}){const[r,s]=g.useState(t);return a.jsxs(a.Fragment,{children:[a.jsx(wke,{entityType:"workflow",entityId:e}),a.jsx(Nkt,{entityType:"workflow",entityId:e,onOpenChange:i=>{i&&s(t)},onSaveExtra:()=>n(r),extraFields:a.jsxs(ft,{children:[a.jsx(ut,{children:"Resource ID"}),a.jsx(Sn,{value:r,onChange:i=>s(i.target.value),placeholder:"e.g. tenant-42"}),a.jsx(no,{children:"Ignored when server auth derives the resource ID from the user."})]})})]})}function lQ({icon:e,label:t,tooltipContent:n,docsHref:r}){return a.jsxs(Ln,{children:[a.jsx(Rn,{render:a.jsx("span",{role:"button",tabIndex:0,"aria-disabled":"true","aria-label":t,className:"inline-flex",children:a.jsx(de,{variant:"ghost",size:"icon-md",disabled:!0,"aria-hidden":"true",tabIndex:-1,children:e})})}),a.jsx(Mn,{side:"bottom",className:"max-w-[calc(100dvw-1rem)]",children:a.jsxs("span",{children:[n," ",a.jsxs("a",{href:r,target:"_blank",rel:"noopener noreferrer",className:Z("inline-flex items-center gap-1 text-inherit underline hover:text-foreground",jn),children:["Learn more",a.jsx(Zs,{className:"size-3"})]})]})})]})}const vlr=({scheduleId:e,queryOptions:t})=>{const n=Ye();return _t({queryKey:["schedule",e],queryFn:async()=>{if(!e)throw new Error("scheduleId is required");return n.getSchedule(e)},...t})},aK=({queryOptions:e,...t}={})=>{const n=Ye();return _t({queryKey:["schedules",t],queryFn:async()=>(await n.listSchedules(t)).schedules,...e})},iVe=25,ylr=({scheduleId:e,queryOptions:t})=>{const n=Ye(),{inView:r,setRef:s}=F0(),i=Mm({queryKey:["schedule-triggers",e],initialPageParam:void 0,queryFn:async({pageParam:d})=>e?n.listScheduleTriggers(e,{limit:iVe,toActualFireAt:d}):{triggers:[]},getNextPageParam:d=>{if(!(!d?.triggers?.length||d.triggers.length<iVe))return d.triggers[d.triggers.length-1].actualFireAt},refetchInterval:d=>(d.state.data?.pages.flatMap(f=>f.triggers)??[]).some(f=>f.run?f.run.status==="pending"||f.run.status==="running"||f.run.status==="waiting":f.outcome==="published")?5e3:!1,...t}),o=i.data?.pages.flatMap(d=>d?.triggers??[])??[],{hasNextPage:l,isFetchingNextPage:c,fetchNextPage:u}=i;return g.useEffect(()=>{r&&l&&!c&&u()},[r,l,c,u]),{...i,data:o,setEndOfListElement:s}},xlr=({scheduleId:e,queryOptions:t})=>{const n=Ye(),r=mr();return kn({mutationFn:async s=>{if(!e)throw new Error("scheduleId is required");return s==="pause"?n.pauseSchedule(e):n.resumeSchedule(e)},onSuccess:()=>{r.invalidateQueries({queryKey:["schedule",e]}),r.invalidateQueries({queryKey:["schedules"]})},...t})};function Aoe({value:e,icon:t,label:n}){return a.jsxs(ni,{value:e,children:[a.jsx(At,{size:"xs",children:t}),a.jsx(Y,{variant:"caption",className:"text-inherit",children:n})]})}function blr({workflowId:e,activeTab:t,showObservability:n=!1}){const{navigate:r}=xn(),{data:s,isSuccess:i}=aK({workflowId:e}),o=s?.length??0,l=encodeURIComponent(e),c={graph:`/workflows/${l}/graph`,traces:`/workflows/${l}/traces`,schedules:`/workflows/${l}/schedules`},u=f=>{f!=="none"&&r(c[f])},d=i&&o===0;return a.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-2 p-1.5",children:[a.jsx(Qc,{value:t,defaultTab:t,onValueChange:u,className:"min-w-0",children:a.jsxs(Zc,{variant:"pill-ghost",children:[a.jsx(Aoe,{value:"graph",icon:a.jsx(Ol,{}),label:"Graph"}),n&&a.jsx(Aoe,{value:"traces",icon:a.jsx(px,{}),label:"Traces"}),!d&&a.jsx(Aoe,{value:"schedules",icon:a.jsx(g0,{}),label:o>0?`Schedules (${o})`:"Schedules"})]})}),(!n||d)&&a.jsxs("div",{className:"ml-auto flex shrink-0 items-center gap-0.5",children:[!n&&a.jsx(lQ,{icon:a.jsx(px,{}),label:"Traces",tooltipContent:a.jsxs(a.Fragment,{children:["Add ",a.jsx("code",{children:"@mastra/observability"})," to enable Traces."]}),docsHref:"https://mastra.ai/docs/observability/overview"}),d&&a.jsx(lQ,{icon:a.jsx(g0,{}),label:"Schedules",tooltipContent:"Configure a schedule on this workflow to enable Schedules.",docsHref:"https://mastra.ai/docs/workflows/scheduled-workflows"})]})]})}const wlr=({children:e})=>{const{workflowId:t,runId:n}=jr();return a.jsx(nwe,{resetKeys:[t,n],title:"Unable to display this workflow",description:"The workflow data could not be displayed. Try again or open another workflow.",children:a.jsx(Olr,{children:e})})},Slr=e=>e==="graph"||e==="traces"||e==="schedules",klr=({workflowId:e})=>{const t=Dr();return D0({"g$+t":()=>t(`/workflows/${encodeURIComponent(e)}/traces`)}),null};function Olr({children:e}){const{workflowId:t,runId:n}=jr(),r=Dbe("/workflows/:workflowId/:tab/*"),{isLoading:s}=lL({workflowId:t,requestContext:xr("workflow",t)[0],queryOptions:{enabled:!!t}}),{hasObservability:i}=lkt(),o=Slr(r?.params.tab)?r.params.tab:"none",l=[_s("/workflows"),n?{...rVe,to:`/workflows/${encodeURIComponent(t??"")}/graph`}:rVe,...n?[{id:"workflow-run",Component:Dor,Action:Lor}]:[]];if(!t)return a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:l}),children:[a.jsx("h1",{className:"sr-only",children:t}),a.jsx("div",{className:"flex h-full flex-col items-center justify-center",children:a.jsx(Y,{variant:"body",tone:"ink",className:"text-center",children:"No workflow ID provided"})})]});if(s&&o==="graph")return a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:l}),children:[a.jsx("h1",{className:"sr-only",children:t}),a.jsx(xt,{className:"h-full"})]});const c=u=>a.jsxs(Et,{variant:"fit",breadcrumbs:a.jsx(Dt,{crumbs:l}),headerActions:a.jsx(For,{}),children:[a.jsx("h1",{className:"sr-only",children:t}),a.jsxs("div",{className:"grid h-full min-h-0 grid-cols-[minmax(0,1fr)] grid-rows-[auto_minmax(0,1fr)]",children:[a.jsx(blr,{workflowId:t,activeTab:o,showObservability:i}),u]})]});return a.jsxs(Jnt,{children:[a.jsx(klr,{workflowId:t}),o==="graph"?a.jsx(PSt,{children:a.jsx(ike,{workflowId:t,initialRunId:n,children:a.jsx(ASt,{children:c(a.jsx(zir,{leftSlot:a.jsx(jlr,{workflowId:t,initialRunId:n}),children:e}))})})},t):c(e)]})}function jlr({workflowId:e,initialRunId:t}){const[n]=xr("workflow",e),{canExecute:r,canDelete:s}=Wa();return a.jsx(Qir,{workflowId:e,initialRunId:t,requestContext:n,runActionsSlot:i=>a.jsx(glr,{workflowId:e,...i}),canExecute:r("workflows"),canDelete:s("workflows")})}const Akt=pd(Z(pr,"rounded-xl transition-all duration-normal ease-out-custom motion-reduce:transition-none"),{variants:{elevation:{flat:"shadow-none",raised:""},interactive:{true:Z(aP,I0e,"cursor-pointer active:scale-99"),false:""}},compoundVariants:[{elevation:"flat",interactive:!0,class:jx}],defaultVariants:{elevation:"raised",interactive:!1}}),jl=g.forwardRef(({className:e,elevation:t,interactive:n,as:r,...s},i)=>{const o=r||(n?"button":"div");return a.jsx(o,{ref:i,type:o==="button"?"button":void 0,className:Z(Akt({elevation:t,interactive:n}),e),...s})});jl.displayName="Card";function Pkt({className:e,elevation:t,LinkComponent:n="a",...r}){return a.jsx(n,{className:Z(Akt({elevation:t,interactive:!0}),e),...r})}const cQ=g.forwardRef(({className:e,...t},n)=>a.jsx("div",{ref:n,className:Z("flex flex-col space-y-1.5 px-3 py-1",e),...t}));cQ.displayName="CardHeader";const Q0=g.forwardRef(({className:e,...t},n)=>a.jsx("h3",{ref:n,className:Z("text-subheading text-foreground",e),...t}));Q0.displayName="CardTitle";const Mj=g.forwardRef(({className:e,...t},n)=>a.jsx("p",{ref:n,className:Z("text-caption text-muted-foreground",e),...t}));Mj.displayName="CardDescription";const Clr=pd("",{variants:{density:{default:"p-3",compact:"p-2"}},defaultVariants:{density:"default"}}),Um=g.forwardRef(({className:e,density:t,...n},r)=>a.jsx("div",{ref:r,className:Z(Clr({density:t}),e),...n}));Um.displayName="CardContent";const _lr=g.forwardRef(({className:e,...t},n)=>a.jsx("div",{ref:n,className:Z("flex items-center p-3 pt-0",e),...t}));_lr.displayName="CardFooter";const oVe=["blue","green","orange","purple","pink","amber","cyan"];function Ske(e){let t=2166136261;for(let n=0;n<e.length;n+=1)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return t>>>0}const lK=e=>oVe[Ske(e)%oVe.length]??"blue",Tlr=e=>`var(--badge-${e}-indicator)`,Elr={blue:"bg-badge-blue-strong text-badge-blue-foreground",green:"bg-badge-green-strong text-badge-green-foreground",orange:"bg-badge-orange-strong text-badge-orange-foreground",purple:"bg-badge-purple-strong text-badge-purple-foreground",pink:"bg-badge-pink-strong text-badge-pink-foreground",amber:"bg-badge-amber-strong text-badge-amber-foreground",cyan:"bg-badge-cyan-strong text-badge-cyan-foreground"},$kt=e=>Elr[e],Ilr=e=>({background:`var(--badge-${e}-strong)`,foreground:`var(--badge-${e}-foreground)`,tint:`var(--badge-${e}-indicator)`}),aVe={goal:"green",outcome:"orange",behavior:"blue",sentiment:"purple"},lVe=["pink","amber"],Nlr={green:"fill-badge-green-strong",orange:"fill-badge-orange-strong",blue:"fill-badge-blue-strong",purple:"fill-badge-purple-strong",pink:"fill-badge-pink-strong",amber:"fill-badge-amber-strong"},Alr={green:"stroke-badge-green-edge",orange:"stroke-badge-orange-edge",blue:"stroke-badge-blue-edge",purple:"stroke-badge-purple-edge",pink:"stroke-badge-pink-edge",amber:"stroke-badge-amber-edge"};function kke(e){const t=e.toLowerCase();return(Object.hasOwn(aVe,t)?aVe[t]:void 0)??lVe[Ske(t)%lVe.length]??"pink"}function Px(e){return`var(--chart-${kke(e)})`}function Rkt(e){return Nlr[kke(e)]}function Plr(e){return Alr[kke(e)]}const AP=[{name:"goal",label:"Goal",description:"What the user wanted from the interaction.",order:0,builtIn:!0,enabled:!0,status:"ready"},{name:"sentiment",label:"Sentiment",description:"The tone the user expressed during the interaction.",order:1,builtIn:!0,enabled:!0,status:"ready"},{name:"behavior",label:"Behavior",description:"What the agent did in response.",order:2,builtIn:!0,enabled:!0,status:"ready"},{name:"outcome",label:"Outcome",description:"How the interaction ended.",order:3,builtIn:!0,enabled:!0,status:"ready"}];AP.map(e=>e.name);Object.fromEntries(AP.map(e=>[e.name,e.description]));function UL(e,t){const n=[...new Set(t??e.map(s=>s.name))],r=new Map(e.map(s=>[s.name,s.order]));return n.sort((s,i)=>{const o=r.get(s),l=r.get(i);return o===void 0&&l===void 0?0:o===void 0?1:l===void 0?-1:o-l})}function yp(e,t){return e.find(n=>n.name===t)?.label??$lr(t)}function PS(e,t){return e.find(n=>n.name===t)?.description||void 0}function $lr(e){return e.split(/[-_]+/).filter(Boolean).map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join(" ")}function cK(e){return`${e} ${e===1?"trace":"traces"}`}function Rlr(e){return`${e} ${e===1?"theme":"themes"}`}function Mkt(e,t){if(t<=0)return`${cK(e)} in this snapshot`;const n=Math.round(e/t);return`${e} of ${n} traces in this snapshot (${Math.round(t*100)}%)`}const Oke={timeZone:"UTC"};function y5(e){return PI(e,{...Oke,now:0})??e}function uK(e){return os(e,"date-time",Oke)??e}function Rpe(e,t){return KYn(e,t,Oke)??`${e}–${t}`}const Mlr=[["chat.completion","1.2s"],["tool.search_docs","340ms"],["workflow.support","2.8s"]],uQ=e=>({color:Px(e)}),cVe=()=>a.jsxs("div",{"aria-hidden":"true",className:"relative hidden h-full items-center lg:flex",children:[a.jsx("div",{className:"w-full border-t border-dashed border-border"}),a.jsx("span",{className:"absolute left-1/2 size-2.5 -translate-x-1/2 rounded-full bg-brand-green-indicator"})]});function x5(e){return new Intl.NumberFormat("en-US").format(e)}function Dlr(e,t){return t?{title:"No Trace Intelligence themes in this date range.",body:"Choose a wider snapshot date range, or wait for newly processed traces to form recurring themes."}:!e||e.status==="collecting"?{title:"Collecting traces for Trace Intelligence.",body:"Trace Intelligence starts grouping recurring patterns after your deployed agents send enough completed traces."}:e.status==="ready"?{title:"Trace Intelligence themes are ready.",body:"Select at least two available trace signal types to see how goals, outcomes, behaviors, and sentiment connect."}:{title:"Analyzing traces for Trace Intelligence.",body:"Trace signals have started processing. Themes appear after enough generated and embedded trace signals form recurring patterns."}}function Llr({progress:e}){const t=e.signalCatalog??AP,n=t.filter(s=>s.enabled).length,r=t.filter(s=>s.enabled&&s.status==="ready").length;return a.jsxs("dl",{className:"mt-4 grid gap-2 sm:grid-cols-3",children:[a.jsxs("div",{className:Z(pr,"rounded-md px-3 py-2"),children:[a.jsx("dt",{className:Da({tone:"muted",variant:"caption"}),children:"Traces analyzed"}),a.jsx("dd",{className:Z(Da({tone:"ink",variant:"heading"}),"mt-1"),children:x5(e.traceCount)})]}),a.jsxs("div",{className:Z(pr,"rounded-md px-3 py-2"),children:[a.jsx("dt",{className:Da({tone:"muted",variant:"caption"}),children:"Trace signal types ready"}),a.jsxs("dd",{className:Z(Da({tone:"ink",variant:"heading"}),"mt-1"),children:[e.signalCatalog?r:e.availableSignals.length," of ",n]})]}),a.jsxs("div",{className:Z(pr,"rounded-md px-3 py-2"),children:[a.jsx("dt",{className:Da({tone:"muted",variant:"caption"}),children:"Status"}),a.jsx("dd",{className:Z(Da({tone:"ink",variant:"heading"}),"mt-1 capitalize"),children:e.status})]})]})}function zlr({progress:e}){if(!e)return null;const t=e.signalCatalog??AP;return a.jsx("ul",{"aria-label":"Trace signal processing progress",className:"mt-3 grid gap-2 sm:grid-cols-2 lg:grid-cols-4",children:UL(t,t.filter(n=>n.enabled).map(n=>n.name)).map(n=>{const r=e.signals[n]??{generated:0,embedded:0},s=t.find(l=>l.name===n),i=yp(t,n),o=s?s.status==="ready":e.availableSignals.includes(n);return a.jsxs("li",{className:"rounded-md border border-border bg-background px-3 py-2",children:[a.jsxs("div",{className:"flex items-center justify-between gap-2",children:[a.jsx(Y,{as:"span",variant:"subheading",style:uQ(n),children:i}),a.jsx(Y,{as:"span",variant:"caption",tone:"muted",children:o?"Themes ready":"Processing"})]}),a.jsxs(Y,{variant:"caption",tone:"muted",className:"mt-1",children:[x5(r.generated)," generated · ",x5(r.embedded)," embedded"]})]},n)})})}function Flr({progress:e,signalCatalog:t}){const n=e?.signalCatalog??t,r=n.filter(s=>s.enabled&&s.status!=="ready");return r.length===0?null:a.jsxs("section",{className:"rounded-lg border border-border bg-background p-4","aria-labelledby":"pending-signals-heading",children:[a.jsx(Y,{as:"h2",variant:"subheading",tone:"ink",id:"pending-signals-heading",children:"Signals building themes"}),a.jsx(Y,{variant:"caption",tone:"muted",className:"mt-1",children:"Themes appear once enough new traces are analyzed, embedded, and clustered."}),a.jsx("ul",{"aria-label":"Pending trace signals",className:"mt-3 grid gap-2 sm:grid-cols-2",children:r.map(s=>{const i=e?.signals[s.name]??{generated:0,embedded:0};return a.jsxs("li",{className:Z(pr,"rounded-md px-3 py-2"),children:[a.jsxs("div",{className:"flex items-center justify-between gap-2",children:[a.jsx(Y,{font:"body",as:"span",variant:"subheading",style:uQ(s.name),children:yp(n,s.name)}),a.jsx(Y,{font:"body",as:"span",variant:"caption",tone:"muted",className:"capitalize",children:s.status})]}),PS(n,s.name)?a.jsx(Y,{font:"body",variant:"caption",tone:"muted",className:"mt-1",children:PS(n,s.name)}):null,a.jsxs(Y,{font:"body",variant:"caption",tone:"muted",className:"mt-1",children:[x5(i.generated)," generated · ",x5(i.embedded)," embedded"]})]},s.name)})})]})}const Mpe=({actionSlot:e,LinkComponent:t="a",progress:n,signalCatalog:r,isRangeEmpty:s})=>{const i=Dlr(n,s),o=r??n?.signalCatalog??AP,c=UL(o,o.filter(u=>u.enabled).map(u=>u.name)).map(u=>({key:u,label:yp(o,u),description:PS(o,u)}));return a.jsx("section",{className:"min-h-full w-full bg-sidebar p-6 md:px-10 lg:px-12 xl:px-[4.375rem]",children:a.jsxs("div",{className:"mx-auto w-full max-w-260",children:[a.jsxs("header",{children:[a.jsxs(Y,{variant:"eyebrow",tone:"muted",className:"flex items-center gap-2",children:[a.jsx("span",{"aria-hidden":"true",className:"size-2 rounded-full bg-brand-green-indicator"}),"Trace Intelligence"]}),a.jsx(Y,{as:"h1",variant:"display",tone:"ink",className:"mt-2",children:"Understand what drives every agent interaction"}),a.jsx(Y,{tone:"muted",className:"mt-2 max-w-180",children:"Trace Intelligence groups recurring goals, outcomes, behaviors, and sentiment across completed traces."})]}),a.jsxs("div",{role:"list","aria-label":"Trace Intelligence analysis pipeline",className:"mt-14 grid gap-4 lg:grid-cols-[17.5rem_4.5rem_17.5rem_4.5rem_minmax(0,1fr)] lg:gap-0",children:[a.jsxs("div",{role:"listitem",className:"min-h-50 p-5",children:[a.jsx(Y,{as:"h2",variant:"heading",tone:"ink",children:"Traces"}),a.jsx(Y,{variant:"caption",tone:"muted",className:"mt-0.5",children:"Every agent interaction"}),a.jsx(Y,{variant:"eyebrow",tone:"muted",className:"mt-5",children:"Input"}),a.jsx("div",{className:"mt-2.5 space-y-2",children:Mlr.map(([u,d])=>a.jsxs("div",{className:Z(pr,"flex items-center justify-between rounded px-3 py-1.5"),children:[a.jsx(Y,{as:"span",variant:"meta",font:"mono",tone:"muted",children:u}),a.jsx(Y,{as:"span",variant:"meta",font:"mono",tone:"muted",children:d})]},u))})]}),a.jsx(cVe,{}),a.jsxs(jl,{as:"div",role:"listitem",className:"flex min-h-50 flex-col items-center p-5 text-center",elevation:"raised",children:[a.jsx(Y,{as:"h2",variant:"heading",tone:"ink",children:"Trace Intelligence"}),a.jsx(Y,{variant:"caption",tone:"muted",className:"mt-0.5",children:"Finds recurring themes"}),a.jsx("div",{"aria-hidden":"true",className:"mt-5 flex size-14 items-center justify-center rounded-full border border-brand-green-indicator bg-fill-subtle",children:a.jsx(dP,{className:"size-4 text-brand-green-indicator"})}),a.jsx(Y,{variant:"meta",tone:"muted",className:"mt-3 max-w-40",children:"Clusters similar trace signals into themes for each dimension"})]}),a.jsx(cVe,{}),a.jsxs("div",{role:"listitem",className:"min-h-50 p-5",children:[a.jsx(Y,{as:"h2",variant:"heading",tone:"ink",children:"Theme analysis"}),a.jsx(Y,{variant:"caption",tone:"muted",className:"mt-0.5",children:"How recurring patterns connect"}),a.jsx(Y,{variant:"eyebrow",tone:"muted",className:"mt-5",children:"Output"}),a.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:c.map(u=>a.jsxs(Y,{as:"span",variant:"column",className:"inline-flex items-center gap-2 rounded border border-border bg-card px-2.5 py-1.5",style:uQ(u.key),children:[a.jsx("span",{"aria-hidden":"true",className:"size-1.5 rounded-full bg-current"}),u.label]},u.key))})]})]}),a.jsxs("section",{className:"mt-10","aria-labelledby":"signal-definitions-heading",children:[a.jsx(Y,{as:"h2",variant:"heading",tone:"ink",id:"signal-definitions-heading",children:"What each trace signal means"}),a.jsx("ul",{"aria-label":"Trace signal definitions",className:"mt-4 grid gap-3 sm:grid-cols-2",children:c.map(u=>a.jsxs("li",{className:"px-1 py-2",children:[a.jsx(Y,{as:"h3",variant:"subheading",style:uQ(u.key),children:u.label}),u.description?a.jsx(Y,{variant:"caption",tone:"muted",className:"mt-1.5",children:u.description}):null]},u.key))})]}),a.jsxs("aside",{className:"mt-9 rounded-md border border-border bg-background px-5 py-4",children:[a.jsxs("div",{className:"flex min-w-0 items-start gap-3",children:[a.jsx("span",{"aria-hidden":"true",className:"mt-1.5 size-2 shrink-0 rounded-full bg-warning-indicator"}),a.jsxs("div",{className:"min-w-0 flex-1",children:[a.jsxs(Y,{variant:"caption",tone:"muted",children:[a.jsx(Y,{as:"strong",variant:"column",tone:"ink",children:i.title})," ",i.body]}),n?a.jsx(Llr,{progress:n}):null,a.jsx(zlr,{progress:n})]})]}),a.jsxs("div",{className:"mt-4 flex shrink-0 flex-wrap items-center gap-2 sm:justify-end",children:[e,a.jsxs(de,{icon:a.jsx(Zs,{}),render:a.jsx("a",{href:"https://mastra.ai/en/docs/mastra-platform/trace-intelligence",target:"_blank",rel:"noopener noreferrer"}),size:"sm",children:["Read the docs",a.jsx("span",{className:"sr-only",children:" (opens in new tab)"})]}),a.jsx(de,{icon:a.jsx(px,{}),render:a.jsx(t,{href:"/traces"}),variant:"primary",size:"sm",children:"View incoming traces"})]})]})]})})};function uVe(e){return a.jsx(Mpe,{...e})}async function Blr(e){const t=await fetch(e,{credentials:"include"});if(!t.ok)throw Object.assign(new Error(`Trace Intelligence request failed (${t.status})`),{status:t.status});return t.json()}const g2={cacheScope:"oss-studio",request:Blr,LinkComponent:"a",getTraceHref:e=>`/traces?traceId=${encodeURIComponent(e)}`,signalCatalog:AP},jke=g.createContext(g2);function pa(){return g.useContext(jke)}function Vlr(e,t){const n=new URLSearchParams({entityType:t});return e(`/api/learning/entities?${n}`)}function Ulr(e,t,n){const r=new URLSearchParams({entityType:n});return e(`/api/learning/entities/${encodeURIComponent(t)}/progress?${r}`)}function Dkt(e,t,n,r,s,i,o=24){const l=new URLSearchParams({entityType:n,signalNames:r.join(","),presentation:"landmarks",limit:String(o)});return s&&l.set("from",s.toISOString()),i&&l.set("to",i.toISOString()),e(`/api/learning/entities/${encodeURIComponent(t)}/theme-snapshots?${l}`)}function Lkt(e,t,n,r,s,i=8){const o=new URLSearchParams({entityType:n,signalNames:r.join(","),snapshotId:s,themeLimitPerStage:String(i)});return e(`/api/learning/entities/${encodeURIComponent(t)}/theme-flow?${o}`)}function qlr(e,t,n,r,s,i){const o=new URLSearchParams({entityType:n,signalName:r,snapshotId:s});return e(Cke(t,i,`?${o}`))}function qL(e){return e.map(t=>`${t.signalName}:${t.kind==="theme"?t.themeId:"noise"}`).join(",")}function Qlr(e,t,n,r,s,i,o=20,l=0,c=[]){const u=new URLSearchParams({entityType:n,signalName:r,snapshotId:s,limit:String(o),offset:String(l)});return c.length>0&&u.set("filterThemes",qL(c)),e(Cke(t,i,`/examples?${u}`))}function Zlr(e,t,n,r,s,i=100){const o=new URLSearchParams({entityType:n,signalName:r,limit:String(i)});return e(Cke(t,s,`/history?${o}`))}function Wlr(e,t,n,r,s){const i=new URLSearchParams({entityType:n,signalName:r,snapshotId:s});return e(Fkt(t,`?${i}`))}function Hlr(e,t,n,r,s,i=20,o=0,l=[]){const c=new URLSearchParams({entityType:n,signalName:r,snapshotId:s,limit:String(i),offset:String(o)});return l.length>0&&c.set("filterThemes",qL(l)),e(Fkt(t,`/examples?${c}`))}async function zkt(e,t,n,r,s){const i=await dVe(e,t,n,r,s,0),o=[...i.paths],l={...i.themes};let c=i.nextOffset;for(;c!==void 0;){const u=await dVe(e,t,n,r,s,c);o.push(...u.paths),Object.assign(l,u.themes),c=u.nextOffset}return{snapshot:i.snapshot,signals:i.signals,themes:l,paths:o}}function dVe(e,t,n,r,s,i){const o=new URLSearchParams({entityType:n,signalNames:r.join(","),snapshotId:s,limit:"500",offset:String(i)});return e(`/api/learning/entities/${encodeURIComponent(t)}/theme-paths?${o}`)}function Glr(e,t){return e(`/api/learning/traces/${encodeURIComponent(t)}/summary`)}function Cke(e,t,n){return`/api/learning/entities/${encodeURIComponent(e)}/themes/${encodeURIComponent(t)}${n}`}function Fkt(e,t){return`/api/learning/entities/${encodeURIComponent(e)}/noise${t}`}function Bkt(e,t,n=!0){const{cacheScope:r,request:s}=pa();return _t({queryKey:["entity-learning",r,t,e,"progress"],queryFn:()=>Ulr(s,e??"",t),enabled:n&&!!e})}function Vkt(e){const{cacheScope:t,request:n}=pa();return _t({queryKey:["entity-learning",t,"entities",e],queryFn:()=>Vlr(n,e)})}function Ukt(e,t,n,r,s){const{cacheScope:i,request:o}=pa(),l=r?.toISOString(),c=s?.toISOString();return _t({queryKey:["entity-learning",i,t,e,"theme-snapshots",n,l,c],queryFn:()=>Dkt(o,e,t,n,r,s),enabled:n.length>=2,staleTime:3e4})}const Klr=.01;function Ylr(e,t){return String(e[t.id])}function Xlr(e,t){const n=String(e[`${t.id}Label`]),r=e[`${t.id}Description`];return typeof r=="string"&&r.trim()?`${n}
|
|
258
258
|
${r}`:n}function Jlr(e,t){return Number(e[`${t.id}TraceCount`])}function ecr(e){const t=new Map;for(const i of e.stages)for(const o of i.nodes)t.set(o.nodeId,{signalName:i.signalName,node:o});const n=new Set(e.links.flatMap(i=>{const o=t.get(i.sourceNodeId),l=t.get(i.targetNodeId);return[...o?[o.signalName]:[],...l?[l.signalName]:[]]})),r=e.stages.filter(i=>n.has(i.signalName)).map(i=>({id:i.signalName,label:ncr(i.signalName)})),s=[];for(const i of e.links){const o=t.get(i.sourceNodeId),l=t.get(i.targetNodeId);!o||!l||s.push({[o.signalName]:o.node.nodeId,[`${o.signalName}Label`]:pVe(o.node),[`${o.signalName}Description`]:o.node.description,[`${o.signalName}TraceCount`]:o.node.traceCount,[l.signalName]:l.node.nodeId,[`${l.signalName}Label`]:pVe(l.node),[`${l.signalName}Description`]:l.node.description,[`${l.signalName}TraceCount`]:l.node.traceCount,traceCount:i.traceCount,layoutTraceCount:"layoutTraceCount"in i?i.layoutTraceCount:i.traceCount})}return{columns:r,records:s}}function tcr(e){return ecr(e)}function fVe(e,t){return e.length===0?[]:[...new Set([(t-1+e.length)%e.length,t,(t+1)%e.length])].sort((r,s)=>r-s).flatMap(r=>{const s=e[r];return s?[s.snapshotId]:[]})}function hVe(e,t){const n=e.stages.map(l=>{const c=new Map;for(const d of t){const f=d.stages.find(h=>h.signalName===l.signalName);for(const h of f?.nodes??[])c.has(h.nodeId)||c.set(h.nodeId,c.size)}const u=l.nodes.filter(d=>d.traceCount>0).sort((d,f)=>(c.get(d.nodeId)??Number.MAX_SAFE_INTEGER)-(c.get(f.nodeId)??Number.MAX_SAFE_INTEGER));return{...l,nodes:u}}),r=new Set(n.flatMap(l=>l.nodes.map(c=>c.nodeId))),s=new Map,i=new Map;for(const l of t)for(const c of l.links){const u=`${c.sourceNodeId}\0${c.targetNodeId}`;s.set(u,Math.max(s.get(u)??0,c.traceCount)),i.has(u)||i.set(u,i.size)}const o=e.links.filter(l=>l.traceCount>0&&r.has(l.sourceNodeId)&&r.has(l.targetNodeId)).sort((l,c)=>{const u=`${l.sourceNodeId}\0${l.targetNodeId}`,d=`${c.sourceNodeId}\0${c.targetNodeId}`;return(i.get(u)??0)-(i.get(d)??0)}).map(l=>{const c=`${l.sourceNodeId}\0${l.targetNodeId}`;return{...l,layoutTraceCount:Math.max(Klr,s.get(c)??l.traceCount)}});return{...e,stages:n,links:o}}function pVe(e){return e.kind==="noise"?"Noise":e.label}function ncr(e){return`${e.slice(0,1).toUpperCase()}${e.slice(1)}`}function b5(e,t){const n=e.cutoffAt?uK(e.cutoffAt):Rpe(e.startedAt,e.endedAt);if(!t)return n;const{traceCount:r,themeCount:s}=rcr(t);return`${n} · ${cK(r)} · ${Rlr(s)}`}function rcr(e){return{traceCount:e.stages[0]?.traceCount??e.snapshot.traceCount,themeCount:e.stages.reduce((t,n)=>t+n.nodes.filter(r=>r.kind==="theme").length,0)}}function Cc(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 scr=typeof Symbol=="function"&&Symbol.observable||"@@observable",mVe=scr,Poe=()=>Math.random().toString(36).substring(7).split("").join("."),icr={INIT:`@@redux/INIT${Poe()}`,REPLACE:`@@redux/REPLACE${Poe()}`,PROBE_UNKNOWN_ACTION:()=>`@@redux/PROBE_UNKNOWN_ACTION${Poe()}`},dQ=icr;function _ke(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 Tke(e,t,n){if(typeof e!="function")throw new Error(Cc(2));if(typeof t=="function"&&typeof n=="function"||typeof n=="function"&&typeof arguments[3]=="function")throw new Error(Cc(0));if(typeof t=="function"&&typeof n>"u"&&(n=t,t=void 0),typeof n<"u"){if(typeof n!="function")throw new Error(Cc(1));return n(Tke)(e,t)}let r=e,s=t,i=new Map,o=i,l=0,c=!1;function u(){o===i&&(o=new Map,i.forEach((y,x)=>{o.set(x,y)}))}function d(){if(c)throw new Error(Cc(3));return s}function f(y){if(typeof y!="function")throw new Error(Cc(4));if(c)throw new Error(Cc(5));let x=!0;u();const b=l++;return o.set(b,y),function(){if(x){if(c)throw new Error(Cc(6));x=!1,u(),o.delete(b),i=null}}}function h(y){if(!_ke(y))throw new Error(Cc(7));if(typeof y.type>"u")throw new Error(Cc(8));if(typeof y.type!="string")throw new Error(Cc(17));if(c)throw new Error(Cc(9));try{c=!0,s=r(s,y)}finally{c=!1}return(i=o).forEach(b=>{b()}),y}function p(y){if(typeof y!="function")throw new Error(Cc(10));r=y,h({type:dQ.REPLACE})}function m(){const y=f;return{subscribe(x){if(typeof x!="object"||x===null)throw new Error(Cc(11));function b(){const k=x;k.next&&k.next(d())}return b(),{unsubscribe:y(b)}},[mVe](){return this}}}return h({type:dQ.INIT}),{dispatch:h,subscribe:f,getState:d,replaceReducer:p,[mVe]:m}}function ocr(e){Object.keys(e).forEach(t=>{const n=e[t];if(typeof n(void 0,{type:dQ.INIT})>"u")throw new Error(Cc(12));if(typeof n(void 0,{type:dQ.PROBE_UNKNOWN_ACTION()})>"u")throw new Error(Cc(13))})}function qkt(e){const t=Object.keys(e),n={};for(let i=0;i<t.length;i++){const o=t[i];typeof e[o]=="function"&&(n[o]=e[o])}const r=Object.keys(n);let s;try{ocr(n)}catch(i){s=i}return function(o={},l){if(s)throw s;let c=!1;const u={};for(let d=0;d<r.length;d++){const f=r[d],h=n[f],p=o[f],m=h(p,l);if(typeof m>"u")throw l&&l.type,new Error(Cc(14));u[f]=m,c=c||m!==p}return c=c||r.length!==Object.keys(o).length,c?u:o}}function gVe(e,t){return function(...n){return t(e.apply(this,n))}}function vVe(e,t){if(typeof e=="function")return gVe(e,t);if(typeof e!="object"||e===null)throw new Error(Cc(16));const n={};for(const r in e){const s=e[r];typeof s=="function"&&(n[r]=gVe(s,t))}return n}function w5(...e){return e.length===0?t=>t:e.length===1?e[0]:e.reduce((t,n)=>(...r)=>t(n(...r)))}function Qkt(...e){return t=>(n,r)=>{const s=t(n,r);let i=()=>{throw new Error(Cc(15))};const o={getState:s.getState,dispatch:(c,...u)=>i(c,...u)},l=e.map(c=>c(o));return i=w5(...l)(s.dispatch),{...s,dispatch:i}}}function Zkt(e){return _ke(e)&&"type"in e&&typeof e.type=="string"}var $oe={exports:{}},Roe={};var yVe;function acr(){if(yVe)return Roe;yVe=1;var e=QA();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,i=e.useEffect,o=e.useMemo,l=e.useDebugValue;return Roe.useSyncExternalStoreWithSelector=function(c,u,d,f,h){var p=s(null);if(p.current===null){var m={hasValue:!1,value:null};p.current=m}else m=p.current;p=o(function(){function y(j){if(!x){if(x=!0,b=j,j=f(j),h!==void 0&&m.hasValue){var C=m.value;if(h(C,j))return S=C}return S=j}if(C=S,n(b,j))return C;var T=f(j);return h!==void 0&&h(C,T)?(b=j,C):(b=j,S=T)}var x=!1,b,S,k=d===void 0?null:d;return[function(){return y(u())},k===null?void 0:function(){return y(k())}]},[u,d,f,h]);var v=r(c,p[0],p[1]);return i(function(){m.hasValue=!0,m.value=v},[v]),l(v),v},Roe}var xVe;function lcr(){return xVe||(xVe=1,$oe.exports=acr()),$oe.exports}lcr();var ccr=g.version.startsWith("19"),ucr=Symbol.for(ccr?"react.transitional.element":"react.element"),dcr=Symbol.for("react.portal"),fcr=Symbol.for("react.fragment"),hcr=Symbol.for("react.strict_mode"),pcr=Symbol.for("react.profiler"),mcr=Symbol.for("react.consumer"),gcr=Symbol.for("react.context"),Wkt=Symbol.for("react.forward_ref"),vcr=Symbol.for("react.suspense"),ycr=Symbol.for("react.suspense_list"),Eke=Symbol.for("react.memo"),xcr=Symbol.for("react.lazy"),bcr=Wkt,wcr=Eke;function Scr(e){if(typeof e=="object"&&e!==null){const{$$typeof:t}=e;switch(t){case ucr:switch(e=e.type,e){case fcr:case pcr:case hcr:case vcr:case ycr:return e;default:switch(e=e&&e.$$typeof,e){case gcr:case Wkt:case xcr:case Eke:return e;case mcr:return e;default:return t}}case dcr:return t}}}function kcr(e){return Scr(e)===Eke}function Ocr(e,t,n,r,{areStatesEqual:s,areOwnPropsEqual:i,areStatePropsEqual:o}){let l=!1,c,u,d,f,h;function p(b,S){return c=b,u=S,d=e(c,u),f=t(r,u),h=n(d,f,u),l=!0,h}function m(){return d=e(c,u),t.dependsOnOwnProps&&(f=t(r,u)),h=n(d,f,u),h}function v(){return e.dependsOnOwnProps&&(d=e(c,u)),t.dependsOnOwnProps&&(f=t(r,u)),h=n(d,f,u),h}function y(){const b=e(c,u),S=!o(b,d);return d=b,S&&(h=n(d,f,u)),h}function x(b,S){const k=!i(S,u),j=!s(b,c,S,u);return c=b,u=S,k&&j?m():k?v():j?y():h}return function(S,k){return l?x(S,k):p(S,k)}}function jcr(e,{initMapStateToProps:t,initMapDispatchToProps:n,initMergeProps:r,...s}){const i=t(e,s),o=n(e,s),l=r(e,s);return Ocr(i,o,l,e,s)}function Ccr(e,t){const n={};for(const r in e){const s=e[r];typeof s=="function"&&(n[r]=(...i)=>t(s(...i)))}return n}function Dpe(e){return function(n){const r=e(n);function s(){return r}return s.dependsOnOwnProps=!1,s}}function bVe(e){return e.dependsOnOwnProps?!!e.dependsOnOwnProps:e.length!==1}function Hkt(e,t){return function(r,{displayName:s}){const i=function(l,c){return i.dependsOnOwnProps?i.mapToProps(l,c):i.mapToProps(l,void 0)};return i.dependsOnOwnProps=!0,i.mapToProps=function(l,c){i.mapToProps=e,i.dependsOnOwnProps=bVe(e);let u=i(l,c);return typeof u=="function"&&(i.mapToProps=u,i.dependsOnOwnProps=bVe(u),u=i(l,c)),u},i}}function Ike(e,t){return(n,r)=>{throw new Error(`Invalid value of type ${typeof e} for ${t} argument when connecting component ${r.wrappedComponentName}.`)}}function _cr(e){return e&&typeof e=="object"?Dpe(t=>Ccr(e,t)):e?typeof e=="function"?Hkt(e):Ike(e,"mapDispatchToProps"):Dpe(t=>({dispatch:t}))}function Tcr(e){return e?typeof e=="function"?Hkt(e):Ike(e,"mapStateToProps"):Dpe(()=>({}))}function Ecr(e,t,n){return{...n,...e,...t}}function Icr(e){return function(n,{displayName:r,areMergedPropsEqual:s}){let i=!1,o;return function(c,u,d){const f=e(c,u,d);return i?s(f,o)||(o=f):(i=!0,o=f),o}}}function Ncr(e){return e?typeof e=="function"?Icr(e):Ike(e,"mergeProps"):()=>Ecr}function Acr(e){e()}function Pcr(){let e=null,t=null;return{clear(){e=null,t=null},notify(){Acr(()=>{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 wVe={notify(){},get:()=>[]};function Gkt(e,t){let n,r=wVe,s=0,i=!1;function o(v){d();const y=r.subscribe(v);let x=!1;return()=>{x||(x=!0,y(),f())}}function l(){r.notify()}function c(){m.onStateChange&&m.onStateChange()}function u(){return i}function d(){s++,n||(n=t?t.addNestedSub(c):e.subscribe(c),r=Pcr())}function f(){s--,n&&s===0&&(n(),n=void 0,r.clear(),r=wVe)}function h(){i||(i=!0,d())}function p(){i&&(i=!1,f())}const m={addNestedSub:o,notifyNestedSubs:l,handleChangeWrapper:c,isSubscribed:u,trySubscribe:h,tryUnsubscribe:p,getListeners:()=>r};return m}var $cr=()=>typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",Rcr=$cr(),Mcr=()=>typeof navigator<"u"&&navigator.product==="ReactNative",Dcr=Mcr(),Lcr=()=>Rcr||Dcr?g.useLayoutEffect:g.useEffect,fQ=Lcr();function SVe(e,t){return e===t?e!==0||t!==0||1/e===1/t:e!==e&&t!==t}function MB(e,t){if(SVe(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])||!SVe(e[n[s]],t[n[s]]))return!1;return!0}var zcr={childContextTypes:!0,contextType:!0,contextTypes:!0,defaultProps:!0,displayName:!0,getDefaultProps:!0,getDerivedStateFromError:!0,getDerivedStateFromProps:!0,mixins:!0,propTypes:!0,type:!0},Fcr={name:!0,length:!0,prototype:!0,caller:!0,callee:!0,arguments:!0,arity:!0},Bcr={$$typeof:!0,render:!0,defaultProps:!0,displayName:!0,propTypes:!0},Kkt={$$typeof:!0,compare:!0,defaultProps:!0,displayName:!0,propTypes:!0,type:!0},Vcr={[bcr]:Bcr,[wcr]:Kkt};function kVe(e){return kcr(e)?Kkt:Vcr[e.$$typeof]||zcr}var Ucr=Object.defineProperty,qcr=Object.getOwnPropertyNames,OVe=Object.getOwnPropertySymbols,Qcr=Object.getOwnPropertyDescriptor,Zcr=Object.getPrototypeOf,jVe=Object.prototype;function Lpe(e,t){if(typeof t!="string"){if(jVe){const i=Zcr(t);i&&i!==jVe&&Lpe(e,i)}let n=qcr(t);OVe&&(n=n.concat(OVe(t)));const r=kVe(e),s=kVe(t);for(let i=0;i<n.length;++i){const o=n[i];if(!Fcr[o]&&!(s&&s[o])&&!(r&&r[o])){const l=Qcr(t,o);try{Ucr(e,o,l)}catch{}}}}return e}var Wcr=Symbol.for("react-redux-context"),Hcr=typeof globalThis<"u"?globalThis:{};function Gcr(){if(!g.createContext)return{};const e=Hcr[Wcr]??=new Map;let t=e.get(g.createContext);return t||(t=g.createContext(null),e.set(g.createContext,t)),t}var Ykt=Gcr(),Kcr=[null,null];function Ycr(e,t,n){fQ(()=>e(...t),n)}function Xcr(e,t,n,r,s,i){e.current=r,n.current=!1,s.current&&(s.current=null,i())}function Jcr(e,t,n,r,s,i,o,l,c,u,d){if(!e)return()=>{};let f=!1,h=null;const p=()=>{if(f||!l.current)return;const v=t.getState();let y,x;try{y=r(v,s.current)}catch(b){x=b,h=b}x||(h=null),y===i.current?o.current||u():(i.current=y,c.current=y,o.current=!0,d())};return n.onStateChange=p,n.trySubscribe(),p(),()=>{if(f=!0,n.tryUnsubscribe(),n.onStateChange=null,h)throw h}}function eur(e,t){return e===t}function tur(e,t,n,{pure:r,areStatesEqual:s=eur,areOwnPropsEqual:i=MB,areStatePropsEqual:o=MB,areMergedPropsEqual:l=MB,forwardRef:c=!1,context:u=Ykt}={}){const d=u,f=Tcr(e),h=_cr(t),p=Ncr(n),m=!!e;return y=>{const x=y.displayName||y.name||"Component",b=`Connect(${x})`,S={shouldHandleStateChanges:m,displayName:b,wrappedComponentName:x,WrappedComponent:y,initMapStateToProps:f,initMapDispatchToProps:h,initMergeProps:p,areStatesEqual:s,areStatePropsEqual:o,areOwnPropsEqual:i,areMergedPropsEqual:l};function k(T){const[_,N,I]=g.useMemo(()=>{const{reactReduxForwardedRef:ee,...se}=T;return[T.context,ee,se]},[T]),A=g.useMemo(()=>{let ee=d;return _?.Consumer,ee},[_,d]),P=g.useContext(A),D=!!T.store&&!!T.store.getState&&!!T.store.dispatch,F=!!P&&!!P.store,Q=D?T.store:P.store,q=F?P.getServerState:Q.getState,B=g.useMemo(()=>jcr(Q.dispatch,S),[Q]),[V,H]=g.useMemo(()=>{if(!m)return Kcr;const ee=Gkt(Q,D?void 0:P.subscription),se=ee.notifyNestedSubs.bind(ee);return[ee,se]},[Q,D,P]),M=g.useMemo(()=>D?P:{...P,subscription:V},[D,P,V]),G=g.useRef(void 0),L=g.useRef(I),$=g.useRef(void 0),z=g.useRef(!1),U=g.useRef(!1),K=g.useRef(void 0);fQ(()=>(U.current=!0,()=>{U.current=!1}),[]);const ne=g.useMemo(()=>()=>$.current&&I===L.current?$.current:B(Q.getState(),I),[Q,I]),X=g.useMemo(()=>se=>V?Jcr(m,Q,V,B,L,G,z,U,$,H,se):()=>{},[V]);Ycr(Xcr,[L,G,z,I,$,H]);let te;try{te=g.useSyncExternalStore(X,ne,q?()=>B(q(),I):ne)}catch(ee){throw K.current&&(ee.message+=`
|
|
259
259
|
The error may be correlated with this previous error:
|
|
260
260
|
${K.current.stack}
|
|
@@ -672,7 +672,7 @@ window.parent.postMessage({jsonrpc:'2.0',method:'ui/notifications/sandbox-proxy-
|
|
|
672
672
|
`),r=t.split(`
|
|
673
673
|
`),s=n.length,i=r.length,o=Array.from({length:s+1},()=>new Array(i+1).fill(0));for(let d=1;d<=s;d++)for(let f=1;f<=i;f++)n[d-1]===r[f-1]?o[d][f]=o[d-1][f-1]+1:o[d][f]=Math.max(o[d-1][f],o[d][f-1]);const l=[];let c=s,u=i;for(;c>0||u>0;)c>0&&u>0&&n[c-1]===r[u-1]?(l.push({type:"equal",text:n[c-1]}),c--,u--):u>0&&(c===0||o[c][u-1]>=o[c-1][u])?(l.push({type:"added",text:r[u-1]}),u--):(l.push({type:"removed",text:n[c-1]}),c--);return l.reverse()}function aye(e){return e.type==="prompt_block"&&typeof e.content=="string"?e.content:null}function Qps({promptBlockId:e}){const{data:t}=pz({blockId:e,queryOptions:{enabled:!!e}}),n=t?.content??"";return n?a.jsx(Zi,{content:n,tooltip:"Copy prompt block text",size:"sm"}):null}function CM({block:e}){const t=aye(e);return t?a.jsx(Zi,{content:t,tooltip:"Copy prompt text",size:"sm"}):e.type==="prompt_block_ref"&&(typeof e.promptBlockId=="string"||typeof e.id=="string")?a.jsx(Qps,{promptBlockId:e.promptBlockId??e.id}):null}function Zps({previousBlocks:e,currentBlocks:t}){const n=Array.isArray(e)?e:[],r=Array.isArray(t)?t:[],s=r.map(l=>aye(l)??""),i=n.map(l=>aye(l)??"");if(n.length<=1&&r.length<=1){const l=i[0]??"",c=s[0]??"",u=n[0];if(l===c)return a.jsxs("div",{className:"relative rounded-md border border-border bg-background p-3",children:[u&&a.jsx("div",{className:"absolute top-2 right-2",children:a.jsx(CM,{block:u})}),a.jsx(Y,{variant:"caption",tone:"muted",font:"mono",className:"whitespace-pre-wrap",children:l||"(empty)"})]});const d=qJe(l,c);return a.jsxs("div",{className:"relative overflow-hidden rounded-md border border-border",children:[u&&a.jsx("div",{className:"absolute top-2 right-2 z-10",children:a.jsx(CM,{block:u})}),d.map((f,h)=>a.jsxs(Y,{as:"p",variant:"body",tone:"muted",className:Z("px-3 py-0.5 wrap-break-word whitespace-pre-wrap",f.type==="removed"&&"bg-destructive-subtle text-destructive-subtle-foreground",f.type==="added"&&"bg-success-subtle text-success-subtle-foreground"),children:[a.jsx("span",{className:"mr-2 inline-block w-4 shrink-0 text-muted-foreground/50 select-none",children:f.type==="removed"?"−":f.type==="added"?"+":" "}),f.text||" "]},h))]})}const o=Math.max(n.length,r.length);return a.jsx("div",{className:"flex flex-col gap-2",children:Array.from({length:o},(l,c)=>{const u=n[c],d=r[c],f=i[c]??"",h=s[c]??"";if(!u&&d)return a.jsxs("div",{className:"rounded-md border border-success-edge bg-success-subtle p-3",children:[a.jsx(Y,{variant:"meta",className:"mb-1 text-success-subtle-foreground",children:"+ Added block"}),a.jsx(Y,{variant:"caption",className:"whitespace-pre-wrap text-success-subtle-foreground",children:h})]},c);if(u&&!d)return a.jsxs("div",{className:"relative rounded-md border border-destructive-edge bg-destructive-subtle p-3",children:[a.jsx("div",{className:"absolute top-2 right-2",children:a.jsx(CM,{block:u})}),a.jsx(Y,{variant:"meta",className:"mb-1 text-destructive-subtle-foreground",children:"− Removed in latest"}),a.jsx(Y,{variant:"caption",className:"whitespace-pre-wrap text-destructive-subtle-foreground",children:f})]},c);if(f===h)return a.jsxs("div",{className:"relative rounded-md border border-border bg-background p-3",children:[u&&a.jsx("div",{className:"absolute top-2 right-2",children:a.jsx(CM,{block:u})}),a.jsx(Y,{variant:"caption",tone:"muted",font:"mono",className:"whitespace-pre-wrap",children:f||"(empty)"})]},c);const p=qJe(f,h);return a.jsxs("div",{className:"relative overflow-hidden rounded-md border border-border",children:[u&&a.jsx("div",{className:"absolute top-2 right-2 z-10",children:a.jsx(CM,{block:u})}),p.map((m,v)=>a.jsxs(Y,{as:"p",variant:"body",tone:"muted",className:Z("px-3 py-0.5 wrap-break-word whitespace-pre-wrap",m.type==="removed"&&"bg-destructive-subtle text-destructive-subtle-foreground",m.type==="added"&&"bg-success-subtle text-success-subtle-foreground"),children:[a.jsx("span",{className:"mr-2 inline-block w-4 shrink-0 text-muted-foreground/50 select-none",children:m.type==="removed"?"−":m.type==="added"?"+":" "}),m.text||" "]},v))]},c)})})}function Wps({promptBlockId:e}){const{data:t,isLoading:n}=pz({blockId:e,queryOptions:{enabled:!!e}});if(n)return a.jsx("div",{className:"flex items-center justify-center py-4",children:a.jsx(En,{className:"h-4 w-4"})});const r=t?.content??"";return a.jsxs("div",{className:"relative rounded-md border border-border bg-background p-3",children:[r&&a.jsx("div",{className:"absolute top-2 right-2",children:a.jsx(Zi,{content:r,tooltip:"Copy prompt block text",size:"sm"})}),t?.name&&a.jsx(Y,{variant:"meta",tone:"muted",className:"mb-1",children:t.name}),a.jsx(Y,{variant:"caption",tone:"muted",font:"mono",className:"whitespace-pre-wrap",children:r||"(empty)"})]})}function k7t({blocks:e}){const t=Array.isArray(e)?e:[];return t.length===0?a.jsx(Y,{variant:"caption",tone:"muted",className:"py-2",children:"No instruction blocks configured"}):a.jsx("div",{className:"flex flex-col gap-2",children:t.map((n,r)=>{if(n.type==="prompt_block_ref"){const i=n.promptBlockId??n.id;return a.jsx(Wps,{promptBlockId:i},i??r)}const s=typeof n.content=="string"?n.content:"";return a.jsxs("div",{className:"relative rounded-md border border-border bg-background p-3",children:[s&&a.jsx("div",{className:"absolute top-2 right-2",children:a.jsx(Zi,{content:s,tooltip:"Copy prompt text",size:"sm"})}),a.jsx(Y,{variant:"caption",tone:"muted",font:"mono",className:"whitespace-pre-wrap",children:s||"(empty)"})]},n.id??r)})})}function Hps({previousTools:e,currentTools:t}){const n=new Set(e?Object.keys(e):[]),r=new Set(t?Object.keys(t):[]),s=[...new Set([...n,...r])].sort();return a.jsx("div",{className:"flex flex-col gap-1.5",children:s.map(i=>{const o=n.has(i),l=r.has(i);let c;return o&&l?c="same":o?c="removed":c="added",a.jsxs("div",{className:Z("flex items-center gap-2 rounded-md border px-3 py-1.5",c==="removed"&&"border-destructive-edge bg-destructive-subtle",c==="added"&&"border-success-edge bg-success-subtle",c==="same"&&"border-border bg-background"),children:[a.jsx(Y,{variant:"caption",font:"mono",className:Z(c==="removed"&&"text-destructive-subtle-foreground line-through",c==="added"&&"text-success-subtle-foreground"),children:i}),c==="removed"&&a.jsx(Mt,{variant:"destructive",className:"ml-auto",children:"removed in latest"}),c==="added"&&a.jsx(Mt,{variant:"success",className:"ml-auto",children:"added in latest"})]},i)})})}function Gps({tools:e}){const t=e?Object.entries(e):[];return t.length===0?a.jsx(Y,{variant:"caption",tone:"muted",className:"py-2",children:"No tools configured"}):a.jsx("div",{className:"flex flex-col gap-1.5",children:t.map(([n,r])=>a.jsxs("div",{className:"rounded-md border border-border bg-background px-3 py-1.5",children:[a.jsx(Y,{variant:"caption",tone:"ink",font:"mono",children:n}),r?.description?a.jsx(Y,{variant:"meta",tone:"muted",className:"mt-0.5",children:String(r.description)}):null]},n))})}function Kps({previousVars:e,currentVars:t}){const n=e?.properties??{},r=t?.properties??{},s=new Set(Object.keys(n)),i=new Set(Object.keys(r)),o=[...new Set([...s,...i])].sort();return o.length===0?a.jsx(Y,{variant:"caption",tone:"muted",className:"py-2",children:"No variables configured"}):a.jsx("div",{className:"flex flex-col gap-1.5",children:o.map(l=>{const c=s.has(l),u=i.has(l);let d;return c&&u?d="same":c?d="removed":d="added",a.jsxs("div",{className:Z("flex items-center gap-2 rounded-md border px-3 py-1.5",d==="removed"&&"border-destructive-edge bg-destructive-subtle",d==="added"&&"border-success-edge bg-success-subtle",d==="same"&&"border-border bg-background"),children:[a.jsx(Y,{variant:"caption",font:"mono",className:Z(d==="removed"&&"text-destructive-subtle-foreground line-through",d==="added"&&"text-success-subtle-foreground"),children:`{{${l}}}`}),d==="removed"&&a.jsx(Mt,{variant:"destructive",className:"ml-auto",children:"removed in latest"}),d==="added"&&a.jsx(Mt,{variant:"success",className:"ml-auto",children:"added in latest"})]},l)})})}function Yps({variables:e}){const t=e?.properties??{},n=Object.entries(t);return n.length===0?a.jsx(Y,{variant:"caption",tone:"muted",className:"py-2",children:"No variables configured"}):a.jsx("div",{className:"flex flex-col gap-1.5",children:n.map(([r,s])=>a.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-border bg-background px-3 py-1.5",children:[a.jsx(Y,{variant:"caption",tone:"ink",font:"mono",children:`{{${r}}}`}),s?.type?a.jsx(Mt,{children:String(s.type)}):null]},r))})}function Xps({agentId:e,selectedVersionId:t,latestVersionId:n}){const{form:r}=El(),s=r.watch("tools"),i=r.watch("variables"),o=r.watch("instructionBlocks"),l=s?Object.keys(s).length:0,{data:c,isLoading:u}=tar({agentId:e,fromVersionId:t,toVersionId:n,queryOptions:{enabled:!!e&&!!t&&!!n}}),d=g.useMemo(()=>{const x=new Map;if(c?.diffs)for(const b of c.diffs)x.set(b.field,{previousValue:b.previousValue,currentValue:b.currentValue});return x},[c]),f=d.get("instructions"),h=d.get("tools"),p=d.get("requestContextSchema"),m=f?a.jsx(Mt,{variant:"warning",size:"sm",children:"modified"}):null,v=h?a.jsx(Mt,{variant:"warning",size:"sm",children:"modified"}):l>0?a.jsx(Mt,{size:"sm",children:`${l}`}):null,y=p?a.jsx(Mt,{variant:"warning",size:"sm",children:"modified"}):null;return u?a.jsx("div",{className:"flex items-center justify-center py-5",children:a.jsx(En,{className:"h-5 w-5"})}):a.jsxs(Qc,{defaultTab:"variables",className:"flex min-h-full flex-col overflow-visible",children:[a.jsxs(Zc,{variant:"pill-ghost",className:"shrink-0",children:[a.jsx(ni,{value:"variables",children:a.jsx(HI,{title:"Variables",icon:a.jsx(Ua,{}),badge:y})}),a.jsx(ni,{value:"instructions",children:a.jsx(HI,{title:"System Prompt",icon:a.jsx(dP,{}),badge:m})}),a.jsx(ni,{value:"tools",children:a.jsx(HI,{title:"Tools",icon:a.jsx(cd,{}),badge:v})})]}),a.jsx(No,{value:"variables",className:"px-4 py-4",children:p?a.jsx(Kps,{previousVars:p.previousValue,currentVars:p.currentValue}):a.jsx(Yps,{variables:i})}),a.jsx(No,{value:"instructions",className:"px-4 py-4",children:f?a.jsx(Zps,{previousBlocks:f.previousValue,currentBlocks:f.currentValue}):a.jsx(k7t,{blocks:o})}),a.jsx(No,{value:"tools",className:"px-4 py-4",children:h?a.jsx(Hps,{previousTools:h.previousValue,currentTools:h.currentValue}):a.jsx(Gps,{tools:s})})]})}function Jps({agentId:e,selectedVersionId:t,latestVersionId:n}){const{form:r,readOnly:s,isCodeAgentOverride:i,editorConfig:o}=El(),{isInstructionsLocked:l}=X_(i,o),c=r.watch("tools"),u=r.watch("instructionBlocks"),d=r.watch("variables"),f=c?Object.keys(c).length:0,h=g.useMemo(()=>Object.entries(d?.properties??{}),[d]),p=s&&!!t&&!!n&&t!==n;return a.jsxs("div",{className:"flex h-full flex-col",children:[a.jsx("div",{className:"border-b border-border px-4 py-3"}),a.jsx(Nr,{className:"min-h-0 flex-1",children:p?a.jsx(Xps,{agentId:e,selectedVersionId:t,latestVersionId:n}):a.jsxs(Qc,{defaultTab:"variables",className:"flex min-h-full flex-col overflow-visible",children:[a.jsxs(Zc,{variant:"pill-ghost",className:"shrink-0",children:[a.jsx(ni,{value:"variables",children:a.jsx(HI,{title:"Variables",icon:a.jsx(Ua,{})})}),a.jsx(ni,{value:"instructions",children:a.jsx(HI,{title:"System Prompt",icon:a.jsx(dP,{})})}),a.jsx(ni,{value:"tools",children:a.jsx(HI,{title:"Tools",icon:a.jsx(cd,{}),badge:f>0?a.jsx(Mt,{size:"sm",children:`${f}`}):void 0})})]}),a.jsx(No,{value:"variables",className:"py-0",children:a.jsxs("div",{className:"flex flex-col gap-1 px-4 py-4",children:[h.length>0?a.jsx("div",{className:"flex flex-col",children:h.map(([m,v])=>a.jsx(S7t,{name:m,prop:v,depth:0},m))}):null,a.jsx(Y,{variant:"meta",tone:"muted",className:"mt-1",children:h.length>0?"Defined via requestContextSchema in code.":"No variables defined. Add a requestContextSchema to your agent to define variables."})]})}),a.jsxs(No,{value:"instructions",className:"px-4 py-0 pb-4",children:[a.jsx("div",{className:"flex flex-col gap-3 pt-4 pb-2",children:a.jsxs(Y,{variant:"caption",tone:"muted",children:["Add instruction blocks to your agent. Blocks are combined in order to form the system prompt. You can"," ",a.jsxs(Ln,{children:[a.jsx(Rn,{className:Z("inline cursor-pointer underline decoration-dotted",Fn,jn),children:"use variables"}),a.jsx(Mn,{side:"bottom",align:"start",className:"max-w-72",children:a.jsxs("span",{children:["Use ",a.jsx(ih,{className:"text-column text-foreground",children:"{{variableName}}"})," syntax to insert dynamic values into your instruction blocks."]})})]})," ","as part of your instruction blocks."]})}),s||l?a.jsx(k7t,{blocks:u}):a.jsx(G9t,{})]}),a.jsx(No,{value:"tools",className:"px-4 py-0 pb-4",children:a.jsx(K9t,{})})]})})]})}function Mce(e){return typeof e=="object"&&e!==null}function ems(e){if(!Mce(e))return{};const t={};return typeof e.maxSteps=="number"&&(t.maxSteps=e.maxSteps),Mce(e.modelSettings)&&(t.modelSettings=e.modelSettings),Mce(e.providerOptions)&&(t.providerOptions=e.providerOptions),t}function cNe(e){if(!e)return{modelSettings:{}};const t=ems(e.defaultOptions),{maxOutputTokens:n,...r}=t.modelSettings??{};return{modelSettings:{...r,...n!==void 0&&{maxTokens:n},...t.maxSteps!==void 0&&{maxSteps:t.maxSteps},...t.providerOptions!==void 0&&{providerOptions:t.providerOptions}}}}function uNe({agentId:e}){return a.jsxs(a.Fragment,{children:[a.jsx(wke,{entityType:"agent",entityId:e}),a.jsx(Nkt,{entityType:"agent",entityId:e})]})}function tms({ctx:e}){const{isDirty:t}=ySe({control:e.form.control}),n=e.handleSaveDraft,r=e.isSavingDraft??!1,s=e.isCodeSourceAgent??!1;if(!t)return null;const i=s?"Save to filesystem":"Save draft",o=s?"You have unsaved changes to the agent configuration. Save to filesystem to ensure the chat uses your latest changes.":"You have unsaved changes to the agent configuration. Save your draft to ensure the chat uses your latest changes.";return a.jsx(Ht,{variant:"warning",title:"Unsaved changes",className:"mx-4 mt-3 mb-0",action:n&&a.jsx(de,{type:"button",variant:"default",size:"sm",onClick:()=>n(),disabled:r,icon:a.jsx(zm,{}),children:r?"Saving...":i}),children:a.jsx(Ht.Message,{children:o})})}function nms({agentId:e,agentName:t,modelVersion:n,agentVersionId:r,hasMemory:s}){const i=g.useMemo(()=>Sa(),[e]),o=xr("agent",e)[0],l=Object.keys(o).length>0,c=DKr(),{data:u}=yd({agentId:e,requestContext:xr("agent",e)[0],queryOptions:{enabled:!!e}}),d=g.useMemo(()=>cNe(u),[u]);return a.jsx(W2t,{agentId:e,defaultSettings:d,children:a.jsx(sX,{children:a.jsxs(iX,{agentId:e,threadId:i,enabled:!!(u?.hasBrowser??u?.browserTools?.length),children:[a.jsx(qIe,{children:a.jsx(lX,{children:a.jsx(BYr,{enabled:!0,threadId:i,agentId:e,requestContext:l?o:void 0,children:a.jsxs("div",{className:"flex h-full flex-col",children:[c&&a.jsx(tms,{ctx:c}),a.jsx("div",{className:"min-h-0 flex-1",children:a.jsx(jNe,{agentId:e,agentName:t,modelVersion:n,agentVersionId:r,supportsMemory:u?.supportsMemory,threadId:i,memory:s,modelList:u?.modelList,isNewThread:!0,runOptionsSlot:a.jsx(uNe,{agentId:e})},i)})]})})},i)}),a.jsx(v2t,{})]},`session-${e}-${i}`)},`browser-${e}-${i}`)})}function rms({agentId:e,activeVersionId:t,selectedVersionId:n,onVersionSelect:r,isDirty:s,isSavingDraft:i,isPublishing:o,hasDraft:l,readOnly:c,isCodeSourceAgent:u=!1,showCodeModeActions:d=!1,canOpenPr:f=!1,openPrTitle:h,onSaveDraft:p,onPublish:m,onDownloadJson:v,onOpenPr:y,isViewingPreviousVersion:x=!1}){const[b,S]=g.useState(!1),[k,j]=g.useState(""),{data:C}=zL({agentId:e,params:{orderBy:{direction:"DESC"}},queryOptions:{enabled:!!e}}),T=g.useMemo(()=>C?.versions??[],[C?.versions]),_=T[0],I=(t?T.find(q=>q.id===t):void 0)?.versionNumber,A=g.useMemo(()=>T.map(q=>{const B=q.id===t,V=I!==void 0&&q.versionNumber>I;return{value:q.id,label:`${u?"Save":"v"}${q.versionNumber} - ${os(q.createdAt,"date-time")??""}`,description:q.changeMessage||void 0,end:u?a.jsx(Mt,{variant:B?"success":"info",children:B?"Current":"Saved"}):B?a.jsx(Mt,{variant:"success",children:"Published"}):V?a.jsx(Mt,{variant:"info",children:"Draft"}):void 0}}),[T,t,I,u]),P=n??_?.id??"",D=c||!s||i||o,F=u?"Code mode saves write override JSON to filesystem-backed editor storage. This dropdown shows saved override snapshots for this agent.":"Changes are saved as draft versions. When you're ready, publish a version to make it the active configuration used in production.",Q=g.useCallback(async()=>{if(i)return;const q=k.trim();await p(q||void 0),S(!1),j("")},[k,p,i]);return{versionSelector:a.jsxs("div",{className:"flex items-center gap-2 border-b border-border bg-card px-4 py-3",children:[T.length>0?a.jsx(Qa,{options:A,value:P,onValueChange:r,placeholder:"Select version...",variant:"ghost",className:"min-w-0 flex-1"}):a.jsx(Y,{variant:"meta",tone:"muted",children:u?"No filesystem saves yet":"No versions yet"}),P&&a.jsx(Zi,{content:P,tooltip:"Copy version ID",size:"sm"}),a.jsxs(Ln,{children:[a.jsx(Rn,{"aria-label":"Version information",className:Z("shrink-0 rounded-sm",Ri,Fn,jn),children:a.jsx(At,{size:"xs",children:a.jsx(pp,{})})}),a.jsx(Mn,{side:"bottom",align:"start",className:"max-w-56",children:F})]}),a.jsxs("div",{className:"ml-auto flex shrink-0 items-center gap-2",children:[c&&a.jsx(Mt,{variant:"warning",children:"Read-only"}),!c&&l&&!u&&a.jsx(Mt,{variant:"info",children:"Unpublished"})]})]}),actionBar:a.jsxs("div",{className:"flex items-center justify-end border-t border-border bg-card px-3 py-2",children:[d?a.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-2",children:[a.jsx(de,{variant:"default",size:"md",onClick:()=>{v?.()},icon:a.jsx(hp,{}),children:"Download JSON"}),f?a.jsx(de,{variant:"primary",size:"md",onClick:()=>{y?.()},title:h,icon:a.jsx(eht,{}),children:"Open PR"}):a.jsx(de,{variant:"primary",size:"md",onClick:()=>{p()},disabled:D,children:i?a.jsxs(a.Fragment,{children:[a.jsx(En,{className:"size-3.5"}),"Saving…"]}):a.jsxs(a.Fragment,{children:[a.jsx(At,{size:"xs",children:a.jsx(zm,{})}),"Save to filesystem"]})})]}):c&&!x?null:a.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-2",children:[a.jsxs(Ql,{children:[a.jsx(de,{variant:"default",onClick:()=>p(),disabled:D,children:i?a.jsxs(a.Fragment,{children:[a.jsx(En,{className:"size-3.5"}),"Saving…"]}):a.jsxs(a.Fragment,{children:[a.jsx(At,{size:"xs",children:a.jsx(zm,{})}),"Save New Version"]})}),a.jsxs(ct,{children:[a.jsx(ct.Trigger,{asChild:!0,children:a.jsx(de,{variant:"default",disabled:D,"aria-label":"More save options",children:a.jsx(zc,{className:"size-3.5"})})}),a.jsx(ct.Content,{align:"end",children:a.jsxs(ct.Item,{onSelect:()=>S(!0),children:[a.jsx(At,{size:"xs",children:a.jsx(nL,{})}),"Save with message"]})})]})]}),a.jsx(de,{variant:"primary",size:"md",onClick:m,disabled:x?n===t||o||i:c||!l||o||i,children:o?a.jsxs(a.Fragment,{children:[a.jsx(En,{className:"size-3.5"}),"Publishing…"]}):a.jsxs(a.Fragment,{children:[a.jsx(At,{size:"xs",children:a.jsx(dr,{})}),x?"Publish This Version":"Publish"]})})]}),a.jsx(rs,{open:b,onOpenChange:S,pending:i,children:a.jsxs(ss,{children:[a.jsxs(es,{children:[a.jsx(Gr,{children:"Save New Version"}),a.jsx(zo,{children:"Add a message to describe the changes in this version."})]}),a.jsx(Hr,{children:a.jsxs(ft,{children:[a.jsx(ut,{children:"Change message"}),a.jsx(Sn,{placeholder:"Describe what changed...",value:k,onChange:q=>j(q.target.value),onKeyDown:q=>{q.key==="Enter"&&Q()},disabled:i,autoFocus:!0})]})}),a.jsxs(Yo,{children:[a.jsx(Ca,{children:"Cancel"}),a.jsx(ja,{onConfirm:Q,children:"Save Version"})]})]})})]})}}function sms({agentId:e,activeVersionId:t,selectedVersionId:n,latestVersionId:r,onVersionSelect:s,isDirty:i,isSavingDraft:o,isPublishing:l,hasDraft:c,readOnly:u,isCodeSourceAgent:d,showCodeModeActions:f,canOpenPr:h,openPrTitle:p,onSaveDraft:m,onPublish:v,onDownloadJson:y,onOpenPr:x,isViewingPreviousVersion:b}){const{versionSelector:S,actionBar:k}=rms({agentId:e,activeVersionId:t,selectedVersionId:n,onVersionSelect:s,isDirty:i,isSavingDraft:o,isPublishing:l,hasDraft:c,readOnly:u,isCodeSourceAgent:d,showCodeModeActions:f,canOpenPr:h,openPrTitle:p,onSaveDraft:m,onPublish:v,onDownloadJson:y,onOpenPr:x,isViewingPreviousVersion:b});return a.jsxs(lNe,{children:[S,a.jsx("div",{className:"px-4 pt-3",children:a.jsx(Y,{variant:"caption",tone:"muted",children:"Edit your agent's system prompt, tools, and variables below."})}),a.jsx("div",{className:"min-h-0 flex-1",children:a.jsx(Jps,{agentId:e,selectedVersionId:n,latestVersionId:r})}),k]})}function ims({agentId:e,agentName:t,modelVersion:n,agentVersionId:r,hasMemory:s,activeVersionId:i,selectedVersionId:o,latestVersionId:l,onVersionSelect:c,isDirty:u,isSavingDraft:d,isPublishing:f,hasDraft:h,readOnly:p,isCodeSourceAgent:m,showCodeModeActions:v,canOpenPr:y,openPrTitle:x,onSaveDraft:b,onPublish:S,onDownloadJson:k,onOpenPr:j,isViewingPreviousVersion:C}){return a.jsx(Xve,{agentId:e,leftDrawerLabel:"Open configuration",leftSlot:a.jsx(sms,{agentId:e,activeVersionId:i,selectedVersionId:o,latestVersionId:l,onVersionSelect:c,isDirty:u,isSavingDraft:d,isPublishing:f,hasDraft:h,readOnly:p,isCodeSourceAgent:m,showCodeModeActions:v,canOpenPr:y,openPrTitle:x,onSaveDraft:b,onPublish:S,onDownloadJson:k,onOpenPr:j,isViewingPreviousVersion:C}),children:a.jsx(nms,{agentId:e,agentName:t,modelVersion:n,agentVersionId:r,hasMemory:s})})}const oms=3e4;function O7t(e){return BL(e.state.error,"feedback")||VL(e.state.error)?!1:oms}function dNe(e,t,n){const r=e.get(t);if(r!==void 0)return r;const s=n();return e.set(t,s),s}const fNe={input:"Input",inputStep:"Input step",llmRequest:"LLM request",llmResponse:"LLM response",outputStream:"Output stream",outputResult:"Output result",outputStep:"Output step",toolResult:"Tool result",requestError:"Request error"};function CJ(e){const t=e.attributes?.processorPhase;return typeof t=="string"&&Object.hasOwn(fNe,t)?t:void 0}function j7t(e,t){const n=CJ(e);if(!(!n||Object.keys(t).length===0))return{phase:n,phaseLabel:fNe[n],data:t}}function ams(e,t){return j7t(e,t)}function lms(e,t){return j7t(e,t)}const cms=["processorPhase","processorExecutor","processorIndex","hookDurationMs","messageListMutations","tripwireAbort"];function C7t(e){const t=CJ(e);if(!t)return;const n=e.attributes??{},r=Array.isArray(n.messageListMutations)?n.messageListMutations:void 0,s=typeof n.tripwireAbort=="object"&&n.tripwireAbort!==null?n.tripwireAbort:void 0,i=new Set(cms);n.messageListMutations!==void 0&&!r&&i.delete("messageListMutations"),n.tripwireAbort!==void 0&&!s&&i.delete("tripwireAbort");const o={};for(const[l,c]of Object.entries(n))i.has(l)||(o[l]=c);return{phase:t,phaseLabel:fNe[t],executor:n.processorExecutor,processorIndex:n.processorIndex,hookDurationMs:n.hookDurationMs,messageListMutations:r,tripwireAbort:s,...Object.keys(o).length>0?{rest:o}:{}}}const Sj=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),Dce=e=>e.status==="suspended"||e.status==="aborted"||e.status==="interrupted",ums=["agent_run","model_step","model_inference"];function _7t(e){const t=e.input;if(t==null)return;if(e.spanType==="agent_run"&&e.metadata?.resumed===!0)return{type:"agent-run-resume",value:Sj(t)?t:{resumeData:t}};if(CJ(e)){const r=Sj(t)?ams(e,t):void 0;return r?{type:"processor",value:r}:{type:"json",value:t}}if(typeof t=="string")return{type:"text",value:t};if(Array.isArray(t))return ums.includes(e.spanType)?{type:"messages",value:t}:{type:"json",value:t};if(!Sj(t))return{type:"json",value:t};const n=e.spanType==="agent_run";if((n||e.spanType==="model_generation")&&"messages"in t){const{messages:r}=t;if(typeof r=="string")return{type:"text",value:r};if(Array.isArray(r))return{type:"messages",value:r};if(Sj(r))return{type:"messages",value:[r]}}if(n){if(typeof t.role=="string")return{type:"messages",value:[t]};if("toolCallId"in t||"toolName"in t||"resumeData"in t)return{type:"agent-run-resume",value:t}}return{type:"json",value:t}}function T7t(e){const t=e.output;if(t!=null){if(CJ(e)){const n=Sj(t)?lms(e,t):void 0;return n?{type:"processor",value:n}:{type:"json",value:t}}if(typeof t=="string")return{type:"text",value:t};if(!Sj(t))return{type:"json",value:t};switch(e.spanType){case"agent_run":return Dce(t)?{type:"interrupted",value:t}:{type:"agent-run-result",value:t};case"model_generation":return Dce(t)?{type:"interrupted",value:t}:{type:"model-generation-result",value:t};case"model_step":return Dce(t)?{type:"interrupted",value:t}:{type:"model-step-result",value:t};case"model_inference":return{type:"model-step-result",value:t};default:return{type:"json",value:t}}}}const dms=e=>Sj(e)&&typeof e.message=="string";function fms(e){return dms(e.error)?e.error:void 0}const vz=300*1e3;function hms({traceId:e,spanId:t,depth:n,queryOptions:r}){return Ye(),_t({queryKey:["branch",e,t,n],queryFn:async()=>{throw new Error("traceId and spanId are required")},staleTime:0,...r})}const A2={AGENT:"agent",WORKFLOW:"workflow_run",SCORER:"scorer",INGEST:"rag_ingestion"};function QJe(e){return Object.values(sd).find(t=>t===e)}const hNe=({entityType:e,rootOnly:t=!1,queryOptions:n}={})=>{const r=Ye();return _t({queryKey:e?["observability-entity-names","by-type",e]:["observability-entity-names","all",t?"root-only":"all-types"],queryFn:async()=>{try{if(e){const i=QJe(e);return i?await r.getEntityNames({entityType:i}):{names:[]}}if(!t)return await r.getEntityNames();const s=await Promise.all(Object.values(A2).map(i=>{const o=QJe(i);return o?r.getEntityNames({entityType:o}):{names:[]}}));return{names:Array.from(new Set(s.flatMap(i=>i?.names??[]))).sort()}}catch{return{names:[]}}},select:s=>s?.names??[],retry:!1,staleTime:vz,...n})},pNe=({queryOptions:e}={})=>{const t=Ye();return _t({queryKey:["observability-environments"],queryFn:async()=>{try{return await t.getEnvironments()}catch{return{environments:[]}}},select:n=>n?.environments??[],retry:!1,staleTime:vz,...e})},E7t=({queryOptions:e}={})=>{const t=Ye();return _t({queryKey:["observability-service-names"],queryFn:async()=>{try{return await t.getServiceNames()}catch{return{serviceNames:[]}}},select:n=>n?.serviceNames??[],retry:!1,staleTime:vz,...e})},pms=1e3*60*60*24*30;function mNe({traceId:e,spanId:t,queryOptions:n}){const r=Ye();return _t({queryKey:["span-detail",e,t],queryFn:async()=>{if(!e||!t)throw new Error("Trace ID and Span ID are required");return r.getSpan(e,t)},staleTime:s=>s.state.data?.span?.endedAt?pms:0,...n})}const I7t=({queryOptions:e}={})=>{const t=Ye();return _t({queryKey:["observability-tags"],queryFn:async()=>{try{return await t.getTags()}catch{return{tags:[]}}},select:n=>n?.tags??[],retry:!1,staleTime:vz,...e})};function mms({threadId:e,queryOptions:t}){const n=Ye(),{data:r}=_t({queryKey:["thread-trace-count",e],queryFn:()=>n.listTracesLight({filters:{threadId:e??""},pagination:{page:0,perPage:25}}),select:s=>(s.spans?.length??0)>1,...t});return r??!1}const gNe=(e,t)=>({queryKey:["trace-spans",t],queryFn:async()=>{if(!t)throw new Error("Trace ID is required");return await e.getTrace(t)},staleTime:0});function J_({traceId:e,passive:t=!1,queryOptions:n}){const r=Ye(),{queryKey:s,queryFn:i,enabled:o,staleTime:l}=gNe(r,e);return _t({queryKey:s,queryFn:i,enabled:o,staleTime:l,refetchOnMount:!t,refetchOnWindowFocus:!t,refetchOnReconnect:!t,...n})}function gms(){const e=Ye(),t=mr();return n=>t.fetchQuery(gNe(e,n))}function vms({traceId:e,anchorSpanId:t,listMode:n,depth:r,queryOptions:s}){const i=n==="branches",o=J_({traceId:e,queryOptions:{enabled:!!e,...s?.trace}});return hms({traceId:null,spanId:null,depth:r,queryOptions:{enabled:i,...s?.branch}}),{spans:o.data?.spans,anchorSpanId:void 0,isLoading:o.isLoading,isError:o.isError,error:o.error}}function yms(e){return e?.page.next??void 0}function xms(e){const t=new Set;return e.pages.flatMap(n=>n.traces.filter(r=>t.has(r.traceId)?!1:(t.add(r.traceId),!0)))}const Lce=e=>typeof e=="string"?e:e.toISOString();function bms(e){return{traceId:e.traceId,rootSpanId:e.spanId,name:e.name,entityId:e.entityId??null,parentSpanId:e.parentSpanId??null,createdAt:Lce(e.createdAt),metadata:e.metadata??null,inputPreview:e.inputPreview??null,threadId:e.threadId??null,resourceId:e.resourceId??null,startedAt:Lce(e.startedAt),endedAt:e.endedAt==null?e.endedAt:Lce(e.endedAt),entityName:e.entityName??null,entityType:e.entityType??null,environment:null,status:e.status}}function wms(e){const t=new Set;return e.pages.flatMap(n=>n.spans.flatMap(r=>t.has(r.traceId)?[]:(t.add(r.traceId),[bms(r)])))}function Sms(e){return e.pagination?.hasMore?e.pagination.page+1:void 0}function kms({query:e,limit:t=25,enabled:n=!0,withQueryTrace:r=!0,legacyFilters:s,queryOptions:i}){const o=Ye(),{inView:l,setRef:c}=F0(),u=Mm({queryKey:["trace-query",e,t],queryFn:e?async({pageParam:I})=>{const A=await new sj({...o.options,retries:0}).queryTraces({...e,page:{limit:t,after:I??null}});if("traces"in A&&"page"in A)return A;throw new Error("Expected a cursor-paginated trace query response")}:$0,initialPageParam:void 0,getNextPageParam:yms,select:xms,retry:!1,placeholderData:ox,enabled:n&&r,...i?.traceQuery}),d=e?.orderBy,f=d?.[0]?.direction==="asc"?"ASC":"DESC",h=Mm({queryKey:["trace-query-legacy",s,t,d],queryFn:({pageParam:I})=>o.listTracesLight({filters:s,pagination:{page:I,perPage:t},orderBy:{field:"startedAt",direction:f}}),initialPageParam:0,getNextPageParam:Sms,select:wms,retry:!1,placeholderData:ox,enabled:n&&!r,...i?.legacy}),{data:p,hasNextPage:m,isFetchingNextPage:v,fetchNextPage:y,isLoading:x,isPlaceholderData:b,isFetching:S,isRefetching:k,fetchStatus:j,isError:C,error:T,refetch:_,isFetchNextPageError:N}=r?u:h;return g.useEffect(()=>{n&&l&&m&&!S&&!N&&y()},[n,l,m,S,N,y]),{data:p,hasNextPage:m,isFetchingNextPage:v,fetchNextPage:y,isLoading:x,isPlaceholderData:b,isFetching:S,isRefetching:k,fetchStatus:j,isError:C,error:T,refetch:_,setEndOfListElement:c}}const lye="mastra_model_total_input_tokens",N7t="mastra_model_total_output_tokens",ZJe=500;function Oms(e){const t=[];for(let n=0;n<e.length;n+=ZJe)t.push(e.slice(n,n+ZJe));return t}function jms(){return{estimatedCost:0,hasEstimatedCost:!1,costUnits:new Set,hasUnknownCostUnit:!1}}function Cms(e,t){for(const n of t.groups){const r=n.dimensions.traceId,s=n.dimensions.name;if(!r||s!==lye&&s!==N7t)continue;const i=dNe(e,r,jms),o=s===lye?"inputTokens":"outputTokens";i[o]=(i[o]??0)+n.value,n.estimatedCost!=null&&(i.estimatedCost+=n.estimatedCost,i.hasEstimatedCost=!0,n.costUnit?i.costUnits.add(n.costUnit.toLowerCase()):i.hasUnknownCostUnit=!0)}}function _ms(e){const t=new Map;for(const[n,r]of e){const s={inputTokens:r.inputTokens,outputTokens:r.outputTokens};r.hasEstimatedCost&&!r.hasUnknownCostUnit&&r.costUnits.size===1&&(s.estimatedCost=r.estimatedCost,s.costUnit=[...r.costUnits][0]),t.set(n,s)}return t}function cye({traceIds:e,enabled:t,autoRefetch:n,queryOptions:r}){const s=Ye(),i=[...new Set(e)].toSorted(),o=`${s.options.baseUrl||(typeof window>"u"?"local":window.location.origin||"local")}:${s.options.apiPrefix??"/api"}`;return _t({queryKey:["trace-usage",o,i],enabled:t&&i.length>0,queryFn:async()=>{const l=Oms(i),c=await Promise.allSettled(l.map(d=>s.getMetricBreakdown({name:[lye,N7t],aggregation:"sum",groupBy:["traceId","name"],filters:{traceIds:d},limit:d.length*2}))),u=new Map;for(const d of c)d.status==="fulfilled"&&Cms(u,d.value);return _ms(u)},placeholderData:(l,c)=>c?.queryKey[1]===o?l:void 0,refetchInterval:t&&n?1e4:!1,...r})}const A7t=({traceId:e,spanId:t,queryOptions:n})=>{const r=Ye(),s=mr();return kn({mutationFn:({text:i})=>r.createFeedback({feedback:{traceId:e,...t?{spanId:t}:{},feedbackType:"comment",feedbackSource:"user",value:i}}),onSuccess:()=>s.invalidateQueries({queryKey:t?["span-feedback",e,t]:["trace-feedback",e]}),...n})},P7t=({traceId:e,spanId:t,queryOptions:n})=>{const r=Ye(),s=mr();return kn({mutationFn:({feedbackId:i})=>r.deleteFeedback({feedbackIds:[i]}),onSuccess:()=>s.invalidateQueries({queryKey:t?["span-feedback",e,t]:["trace-feedback",e]}),...n})},vNe=({traceId:e="",spanId:t="",page:n,queryOptions:r})=>{const s=Ye(),i=n??0;return _t({queryKey:["span-feedback",e,t,i],queryFn:()=>s.listFeedback({filters:{traceId:e,spanId:t},pagination:{page:i,perPage:10}}),refetchInterval:O7t,gcTime:0,staleTime:0,...r})},_J=({traceId:e="",page:t,queryOptions:n})=>{const r=Ye(),s=t??0;return _t({queryKey:["trace-feedback",e,s],queryFn:()=>r.listFeedback({filters:{traceId:e},pagination:{page:s,perPage:10}}),select:i=>{const o=i.feedback.filter(l=>!l.spanId);return i.pagination?{...i,feedback:o,pagination:{...i.pagination,total:o.length}}:{...i,feedback:o}},refetchInterval:O7t,gcTime:0,staleTime:0,...n})},$7t=100,WJe={canonicalFields:[],observedFields:[],observedFieldsTruncated:!1},Tms="TRACE_QUERY_DISCOVERY_UNSUPPORTED",Ems=e=>e instanceof nx&&typeof e.body=="object"&&e.body!==null&&e.body.code===Tms,Ims=e=>["trace-query-fields",e.from,e.to],R7t=(e,t,n,r)=>async({query:s,signal:i})=>{const{values:o}=await e.getTraceQueryValues({timeRange:t,predicateScope:n,path:r,search:s.trim()||void 0,limit:$7t},{signal:i});return o.map(({value:l})=>({value:l}))},Nms=({timeRange:e,queryOptions:t})=>{const n=Ye(),r=_t({queryKey:Ims(e),queryFn:async({signal:o})=>{try{return await n.getTraceQueryFields({timeRange:e,predicateScope:"trace",limit:$7t},{signal:o})}catch(l){if(Ems(l))return WJe;throw l}},retry:!1,staleTime:vz,placeholderData:ox,...t}),s=r.data?.observedFields,i=r.data?.canonicalFields??WJe.canonicalFields;return{fields:g.useMemo(()=>(s??[]).map(o=>({path:o.path,suggestions:R7t(n,e,"trace",o.path)})),[s,n,e]),canonicalFields:i,isLoading:r.isLoading,error:r.error}};function Ams(){const e=Ye();return`mastra:traces:columns:${e.options.baseUrl||(typeof window>"u"?"local":window.location.origin||"local")}:${e.options.apiPrefix??"/api"}`}const uye=(e,t)=>e==="number"?Number(t):e==="boolean"?t.toLowerCase()==="true":t,hl=e=>"kind"in e&&e.kind==="group",yNe=new Set(["runId","sessionId","requestId","userId","organizationId","serviceName","experimentId"]),Pms=["is","isNot","in","notIn","exists","notExists","gt","gte","lt","lte","matches","notMatches"],xNe=e=>Pms.includes(e),dye=e=>"nodes"in e,$ms={is:"eq",isNot:"ne",in:"in",notIn:"notIn",exists:"exists",notExists:"notExists",gt:"gt",gte:"gte",lt:"lt",lte:"lte",matches:"matches",notMatches:"notMatches"},M7t=new Set(["durationMs","spans.durationMs","scores.score","feedback.value"]),Rms=new Set(["entityType","status","entityName","environment","traceId","threadId","resourceId","durationMs"]),Mms=new Set(["threadId","resourceId","environment","durationMs"]),D7t={isNot:"is",notIn:"in",notExists:"exists",notMatches:"matches"},Dms=e=>e in D7t,L7t=["spans","scores","feedback"];function Lms(e){if(e==="entityId")return{scope:"spans",path:"entityId"};for(const t of L7t)if(e.startsWith(`${t}.`)&&e.length>t.length+1)return{scope:t,path:e.slice(t.length+1)};return{path:e}}function HJe(e,t,n){const r=$ms[e];switch(r){case"exists":case"notExists":return{op:r,path:t};case"in":case"notIn":return n.length?{op:r,value:{path:t},set:n}:void 0;case"matches":case"notMatches":{const[s]=n;return typeof s=="string"?{op:r,left:{path:t},right:{literal:s}}:void 0}default:{if(!n.length)return;if(n.length>1){if(r==="eq")return{op:"in",value:{path:t},set:n};if(r==="ne")return{op:"notIn",value:{path:t},set:n}}const[s]=n;return s===void 0?void 0:{op:r,left:{path:t},right:{literal:s}}}}}function zms(e,t){if(e==="exists"||e==="notExists")return{op:e,path:"tags"};const n=e==="notIn"||e==="isNot",r=t.map(i=>({op:n?"notIncludes":"includes",path:"tags",value:i})),s=r.length<=1?r[0]:{op:n?"and":"or",args:r};return!s||!n?s:{op:"or",args:[s,{op:"notExists",path:"tags"}]}}const Fms=new Set(["spans.error"]);function Bms(e,t){if(yNe.has(e.fieldId)||t.has(e.fieldId))return;const n=e.operatorId??(e.fieldId==="tags"?"in":"is"),r=n==="exists"||n==="notExists";if(Fms.has(e.fieldId)&&!r)return;const s=(Array.isArray(e.value)?e.value:[e.value]).filter(f=>typeof f=="string"&&!!f.trim()&&!bNe(f,n));if(!s.length&&!r)return;if(e.fieldId==="tags"){const f=zms(n,s);return f?{predicate:f}:void 0}let i=e.fieldId,o=s;if(i.startsWith("metadata.")){if(i.length===9)return}else if(i==="rootEntityType"||i==="entityType")i="entityType";else if(i==="status"){if(o=s.filter(f=>f!=="running"),!o.length&&!r)return}else if(M7t.has(i)&&(o=s.map(Number).filter(f=>!Number.isNaN(f)),!o.length&&!r))return;if((n==="matches"||n==="notMatches")&&(o=o.filter(f=>/[\p{L}\p{M}\p{N}]/u.test(String(f))),!o.length))return;const{scope:l,path:c}=Lms(i),u=i.startsWith("metadata.");if(!l&&!u&&!Rms.has(i))return;if(l&&Dms(n)){const f=HJe(D7t[n],c,o);return f?{predicate:{[l]:{none:f}}}:void 0}const d=HJe(n,c,o);if(d)return l?{scope:l,predicate:d}:(n==="isNot"||n==="notIn")&&(u||Mms.has(i))?{predicate:{op:"or",args:[d,{op:"notExists",path:c}]}}:{predicate:d}}function z7t(e,{mergeRelated:t,excludedFieldIds:n}){const r=[],s={spans:[],scores:[],feedback:[]};for(const i of e){const o=Bms(i,n);o&&("scope"in o?t?s[o.scope].push(o.predicate):r.push({[o.scope]:{some:o.predicate}}):r.push(o.predicate))}for(const i of L7t){const[o,...l]=s[i];if(!o)continue;const c=l.length?{op:"and",args:[o,...l]}:o;r.push({[i]:{some:c}})}return r}function F7t(e,t){const n=e.nodes.filter(s=>!dye(s)),r=z7t(n,{mergeRelated:e.logic==="and",excludedFieldIds:t});for(const s of e.nodes){if(!dye(s))continue;const i=F7t(s,t);i&&r.push(i)}if(r.length!==0)return r.length===1?r[0]:{op:e.logic,args:r}}function GJe({rootEntityType:e,status:t,dateFrom:n,dateTo:r,tokens:s,groups:i=[],excludedFieldIds:o=new Set,now:l}){const c=[];e&&c.push({op:"eq",left:{path:"entityType"},right:{literal:e}}),t&&t!=="running"&&c.push({op:"eq",left:{path:"status"},right:{literal:t}}),c.push(...z7t(s,{mergeRelated:!0,excludedFieldIds:o}));for(const u of i){const d=F7t(u,o);d&&c.push(d)}return{timeRange:{from:(n??new Date(l.getTime()-10080*60*1e3)).toISOString(),to:(r??l).toISOString()},...c.length?{where:{op:"and",args:c}}:{}}}const Vms=744*60*60*1e3;function Ums(e){const t=new Date(e.to).getTime(),n=new Date(e.from).getTime(),r=t-Vms;return n>=r&&n<t?e:{from:new Date(r).toISOString(),to:e.to}}const B7t=[{label:"Agent",entityType:A2.AGENT},{label:"Workflow",entityType:A2.WORKFLOW},{label:"Scorer",entityType:A2.SCORER},{label:"Ingest",entityType:A2.INGEST}],qms=[{label:"Running",value:"running"},{label:"Success",value:"success"},{label:"Error",value:"error"}],d3="metadata.",lW="filterMetadata.",V7t=e=>e.startsWith(d3)&&e.length>d3.length,TJ=e=>e.startsWith(lW)&&e.length>lW.length,Qms=e=>lW+e.slice(d3.length),Zms=e=>d3+e.slice(lW.length),XS="rootEntityType",JS="status",T1="listMode",uV="anchorSpanId",Wms=new Set(["traces","branches"]),E1="datePreset",l1="dateFrom",c1="dateTo",Hms=new Set(["all","last-24h","last-3d","last-7d","last-14d","last-30d","custom"]),yl={tags:"filterTags",entityId:"filterEntityId",entityName:"filterEntityName",traceId:"filterTraceId",durationMs:"filterDurationMs",runId:"filterRunId",threadId:"filterThreadId",sessionId:"filterSessionId",requestId:"filterRequestId",resourceId:"filterResourceId",userId:"filterUserId",organizationId:"filterOrganizationId",serviceName:"filterServiceName",environment:"filterEnvironment",experimentId:"filterExperimentId","spans.name":"filterSpanName","spans.spanType":"filterSpanType","spans.model":"filterSpanModel","spans.provider":"filterSpanProvider","spans.durationMs":"filterSpanDurationMs","spans.error":"filterSpanError","scores.scorerId":"filterScorerId","scores.score":"filterScore","feedback.feedbackType":"filterFeedbackType","feedback.value":"filterFeedbackValue","feedback.comment":"filterFeedbackComment"},EJ=Object.keys(yl),U7t=".op",GC=e=>e+U7t,q7t=e=>e.endsWith(U7t),Q7t=e=>e==="exists"||e==="notExists",Gms=e=>e==="in"||e==="notIn",DA=e=>e.operatorId??(Array.isArray(e.value)?"in":"is"),bNe=(e,t)=>e==="Any"&&t!=="matches"&&t!=="notMatches",fye=(e,t)=>{const n=e.get(GC(t));return n!==null&&xNe(n)?n:void 0},Kms=new Set(["running","success","error"]),wNe="mastra:traces:saved-filters";function Yms(e,t=wNe){const n=xgs(e),r=e.get(E1);r&&r!=="custom"&&n.set(E1,r);const s=ONe(n).filter(i=>i.nodes.length>0);n.delete(KC);for(const i of s)n.append(KC,kNe(i));if(!n.toString()){Xms(t);return}try{localStorage.setItem(t,n.toString())}catch{}}function Xms(e=wNe){try{localStorage.removeItem(e)}catch{}}function Jms(e=wNe){try{const t=localStorage.getItem(e);if(!t)return null;const n=new URLSearchParams(t);return n.toString()?n:null}catch{return null}}function egs(e){if(e.has(E1)||e.has(l1)||e.has(c1)||e.has(XS)||e.has(JS)||e.has(T1)||e.has(KC))return!0;for(const t of EJ)if(e.has(yl[t]))return!0;for(const t of e.keys())if(TJ(t))return!0;return!1}const tgs=[{id:"is",label:"is"},{id:"isNot",label:"is not"},{id:"in",label:"is any of",arity:"many"},{id:"notIn",label:"is none of",arity:"many"},{id:"exists",label:"exists",arity:"none"},{id:"notExists",label:"does not exist",arity:"none"},{id:"gt",label:"greater than"},{id:"gte",label:"at least"},{id:"lt",label:"less than"},{id:"lte",label:"at most"},{id:"matches",label:"matches",freeText:!0},{id:"notMatches",label:"does not match",freeText:!0}],P2=["is","isNot","in","notIn","exists","notExists"],ngs=[...P2,"matches","notMatches"],KJe=["is","isNot","in","notIn"],rgs=["is","isNot","gt","gte","lt","lte","exists","notExists"],sgs=["gt","gte","lt","lte"],igs=["exists","notExists"],ogs=["in","notIn","exists","notExists"],ags={in:"includes",notIn:"notIncludes",exists:"exists",notExists:"notExists"},YJe=["is","in"],lgs=["is"],cgs={rootEntityType:"Primitive type",entityName:"Primitive name",entityId:"Primitive ID",status:"Status",tags:"Tags",serviceName:"Service Name",environment:"Environment",traceId:"Trace ID",runId:"Run ID",threadId:"Thread ID",sessionId:"Session ID",requestId:"Request ID",resourceId:"Resource ID",userId:"User ID",organizationId:"Organization ID",experimentId:"Experiment ID","spans.name":"Span name","spans.spanType":"Span type","spans.model":"Model","spans.provider":"Provider",durationMs:"Duration (ms)","spans.durationMs":"Span duration (ms)","spans.error":"Span error","scores.scorerId":"Scorer","scores.score":"Score","feedback.feedbackType":"Feedback type","feedback.value":"Feedback value","feedback.comment":"Feedback comment"},ugs={timeRange:ON,rootEntityType:Bft,entityName:uk,entityId:Jft,status:Sjn,tags:RIn,serviceName:cIn,environment:_v,traceId:jht,runId:Bc,threadId:nL,sessionId:tL,requestId:pht,resourceId:x_,userId:nNn,organizationId:D0e,experimentId:DH,"spans.name":CN,"spans.spanType":hIn,"spans.model":dP,"spans.provider":yfe,durationMs:v0,"spans.durationMs":v0,"spans.error":Yd,"scores.scorerId":Cv,"scores.score":jEn,"feedback.feedbackType":qIn,"feedback.value":hP,"feedback.comment":VTn},Z7t=e=>ugs[e],SNe=e=>"var(--muted-foreground)",FE=e=>({id:e,label:cgs[e]??e,icon:Z7t(e),color:SNe()}),dgs=["entityId","traceId","runId","threadId","sessionId","requestId","resourceId","userId","organizationId","experimentId"],fgs=["spans.name","spans.spanType","spans.model","spans.provider","spans.durationMs","spans.error","scores.scorerId","scores.score","feedback.feedbackType","feedback.value","feedback.comment"],W7t=new Set(["spans.error"]),hgs=new Set(["spans.name","feedback.comment"]),pgs=new Set(["feedback.comment"]),hE=(e,t)=>e.label.localeCompare(t.label);function mgs(e,t){const n=e.find(i=>i.path==="tags");if(!n)return;const r=ogs.filter(i=>n.operators.includes(ags[i]??""));if(r.length===0)return;const s=n.valueSuggestions?t?.("trace","tags"):void 0;return{...FE("tags"),operators:r,...s?{suggestions:s}:{}}}function ggs({availableRootEntityNames:e,availableEnvironments:t,hiddenFieldIds:n=[],metadataFields:r=[],canonicalTraceFields:s=[],valueSuggestions:i,withQueryTrace:o=!0,withRootDuration:l=!1}){const c=(k,j,C=P2)=>({...FE(k),operators:C,strict:!0,suggestions:j}),u=k=>({...FE(k),operators:k==="traceId"?KJe:P2}),d=k=>{const[j,C]=k.split("."),T=pgs.has(k)?void 0:i?.(j,C);return{...FE(k),operators:hgs.has(k)?ngs:P2,...T?{strict:!0,suggestions:T}:{}}},f=k=>({...FE(k),type:"number",operators:rgs}),h=k=>({...FE(k),operators:igs}),p=[c("rootEntityType",B7t.map(k=>({value:k.entityType,label:k.label})),YJe),c("entityName",e.map(k=>({value:k})),KJe),c("status",qms.filter(k=>k.value!=="running").map(k=>({value:k.value,label:k.label})),YJe),c("environment",t.map(k=>({value:k})))],m=dgs.map(u),v=["spans","scores","feedback"].flatMap(k=>fgs.filter(j=>j.startsWith(`${k}.`)).map(j=>M7t.has(j)?f(j):W7t.has(j)?h(j):d(j)).sort(hE)),y=r.filter(({path:k})=>V7t(k)).map(({path:k,suggestions:j})=>({id:k,label:k.slice(d3.length),icon:Ua,color:SNe(),operators:P2,suggestions:j})),x=mgs(s,i),b=x?[x]:[],S=new Set(n);return o?[...[...p,...b].sort(hE),...[...m,...l?[{...f("durationMs"),operators:sgs}]:[]].sort(hE),...v,...y.sort(hE)].filter(k=>!yNe.has(k.id)).map(k=>S.has(k.id)?{...k,hidden:!0}:k):[...p.sort(hE),...m.sort(hE)].map(k=>({...k,operators:lgs,...S.has(k.id)?{hidden:!0}:{}}))}function H7t(e){return e.map(t=>({id:t.fieldId,fieldId:t.fieldId,operatorId:DA(t),value:bNe(t.value,DA(t))?"":t.value}))}function G7t(e){return e.map(K7t)}function K7t(e){const t={fieldId:e.fieldId,value:Array.isArray(e.value)?e.value.map(String):String(e.value)};return xNe(e.operatorId)&&e.operatorId!==DA(t)&&(t.operatorId=e.operatorId),t}function XJe(e,t){return{logic:"and",nodes:[...H7t(e),...t.map(Y7t)]}}function Y7t(e){return{id:e.id,kind:"group",logic:e.logic,nodes:e.nodes.map(t=>dye(t)?Y7t(t):{id:t.id??t.fieldId,fieldId:t.fieldId,operatorId:DA(t),value:bNe(t.value,DA(t))?"":t.value})}}function vgs(e){const t=e.nodes.filter(r=>!hl(r)),n=e.nodes.filter(hl).map(X7t);return{tokens:G7t(t),groups:n}}function X7t(e){const t=e.nodes.map(n=>hl(n)?X7t(n):{id:n.id,...K7t(n)});return{id:e.id,logic:e.logic,nodes:t}}function ygs(e){const t=[],n=new Map([[XS,"rootEntityType"],[JS,"status"]]);for(const s of EJ)n.set(yl[s],s);const r=new Set;for(const[s]of e.entries()){if(q7t(s))continue;const i=TJ(s)?Zms(s):n.get(s);if(!i||r.has(i))continue;r.add(i);const o=fye(e,s),l=e.getAll(s);if(W7t.has(i)&&(o?!Q7t(o):l[0]))continue;if(i==="tags"||Gms(o)){t.push({fieldId:i,value:l.filter(Boolean),...o?{operatorId:o}:{}});continue}const c=l[0];c!==void 0&&t.push({fieldId:i,value:c,...o?{operatorId:o}:{}})}return t}function xgs(e){const t=new URLSearchParams,n=e.get(XS);n&&t.set(XS,n);const r=e.get(JS);r&&t.set(JS,r);const s=e.get(T1);s&&t.set(T1,s);const i=l=>{const c=fye(e,l),u=e.getAll(l).filter(d=>d||Q7t(c));if(u.length){for(const d of u)t.append(l,d);c&&t.set(GC(l),c)}};for(const l of EJ){const c=yl[l];if(l==="tags"){for(const d of e.getAll(c))t.append(c,d);const u=fye(e,c);u&&e.has(c)&&t.set(GC(c),u);continue}i(c)}const o=new Set;for(const l of e.keys())!TJ(l)||q7t(l)||o.has(l)||(o.add(l),i(l));for(const l of ONe(e))t.append(KC,kNe(l));return t}function JJe(e,t,n=[]){e.delete(XS),e.delete(JS),e.delete(KC);for(const r of EJ){const s=yl[r];e.delete(s),e.delete(GC(s))}for(const r of Array.from(e.keys()))TJ(r)&&e.delete(r);for(const r of t){if(r.fieldId==="rootEntityType"&&typeof r.value=="string"){e.set(XS,r.value);continue}if(r.fieldId==="status"&&typeof r.value=="string"){e.set(JS,r.value);continue}const s=V7t(r.fieldId)?Qms(r.fieldId):yl[r.fieldId];if(!s)continue;if(Array.isArray(r.value))if(r.value.length===0)e.append(s,"");else for(const l of r.value)e.append(s,l);else e.set(s,r.value.trim());const i=DA(r),o=r.fieldId==="tags"?"in":"is";i!==o&&e.set(GC(s),i)}for(const r of n)e.append(KC,kNe(r))}const KC="filterGroup",kNe=e=>JSON.stringify(e);function ONe(e){return e.getAll(KC).map(bgs).filter(t=>t!==void 0)}function bgs(e){try{return eBt(JSON.parse(e))}catch{return}}const J7t=e=>typeof e=="object"&&e!==null,wgs=e=>Array.isArray(e)&&e.every(t=>typeof t=="string");function eBt(e){if(!J7t(e)||typeof e.id!="string"||e.logic!=="and"&&e.logic!=="or"||!Array.isArray(e.nodes))return;const t=e.nodes.map(Sgs).filter(n=>n!==void 0);return{id:e.id,logic:e.logic,nodes:t}}function Sgs(e){if(!J7t(e))return;if("nodes"in e)return eBt(e);if(typeof e.id!="string"||typeof e.fieldId!="string"||typeof e.value!="string"&&!wgs(e.value))return;const t={id:e.id,fieldId:e.fieldId,value:e.value};return typeof e.operatorId=="string"&&xNe(e.operatorId)&&(t.operatorId=e.operatorId),t}function kgs({rootEntityType:e,status:t,dateFrom:n,dateTo:r,tokens:s}){const i={};e&&(i.entityType=e),t&&(i.status=t),n&&(i.startedAt={start:n}),r&&(i.endedAt={end:r});for(const o of s){if(o.fieldId==="tags"){Array.isArray(o.value)&&o.value.length>0?i.tags=o.value:typeof o.value=="string"&&o.value.trim()&&(i.tags=[o.value.trim()]);continue}if(typeof o.value=="string"&&o.value.trim()&&o.value!=="Any")switch(o.fieldId){case"entityId":i.entityId=o.value;break;case"entityName":i.entityName=o.value;break;case"traceId":i.traceId=o.value;break;case"runId":i.runId=o.value;break;case"threadId":i.threadId=o.value;break;case"sessionId":i.sessionId=o.value;break;case"requestId":i.requestId=o.value;break;case"resourceId":i.resourceId=o.value;break;case"userId":i.userId=o.value;break;case"organizationId":i.organizationId=o.value;break;case"serviceName":i.serviceName=o.value;break;case"environment":i.environment=o.value;break;case"experimentId":i.experimentId=o.value;break}}return i}function zce({value:e,icon:t,label:n}){return a.jsxs(ni,{value:e,children:[a.jsx(At,{size:"xs",children:t}),a.jsx(Y,{variant:"caption",className:"text-inherit",children:n})]})}function Ogs({agentId:e,activeTab:t,threadId:n,showPlayground:r=!1,showObservability:s=!1}){const{navigate:i}=xn(),o={chat:`/agents/${e}/threads/${n??"new"}`,versions:`/agents/${e}/editor`,traces:n?`/agents/${e}/traces?${new URLSearchParams({[yl.threadId]:n})}`:`/agents/${e}/traces`},l=c=>{c!=="none"&&i(o[c])};return a.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-2 p-1.5",children:[a.jsx(Qc,{value:t,defaultTab:t,onValueChange:l,className:"min-w-0",children:a.jsxs(Zc,{variant:"pill-ghost",children:[a.jsx(zce,{value:"chat",icon:a.jsx(nL,{}),label:"Chat"}),s&&a.jsx(zce,{value:"traces",icon:a.jsx(px,{}),label:"Traces"}),r&&a.jsx(zce,{value:"versions",icon:a.jsx(CN,{}),label:"Editor"})]})}),(!s||!r)&&a.jsxs("div",{className:"ml-auto flex shrink-0 items-center gap-0.5",children:[!s&&a.jsx(lQ,{icon:a.jsx(px,{}),label:"Traces",tooltipContent:a.jsxs(a.Fragment,{children:["Add ",a.jsx("code",{children:"@mastra/observability"})," to enable Traces."]}),docsHref:"https://mastra.ai/docs/observability/overview"}),!r&&a.jsx(lQ,{icon:a.jsx(CN,{}),label:"Editor",tooltipContent:"Add @mastra/editor to enable the Editor.",docsHref:"https://mastra.ai/docs/editor/overview"})]})]})}const jgs=({agentId:e})=>{const t=Ye(),{data:n=[]}=FL(),r=n.filter(l=>l.isConfigured),s=aS({queries:r.map(l=>({queryKey:["channels","installations",l.id,e],queryFn:()=>t.channels.listInstallations(l.id,e),staleTime:10*1e3,retry:!1}))}),i=r.flatMap((l,c)=>{const u=s[c]?.data;return!u||u.some(d=>d.status==="active")?[]:[{platform:l,isPending:u.some(d=>d.status==="pending")}]});if(i.length===0)return null;const o=s.some(l=>l.data?.length);return a.jsx(jl,{elevation:"flat","data-testid":"agent-channels-card",children:a.jsxs(Um,{className:"flex flex-col gap-1",children:[a.jsx(Q0,{children:o?"Finish connecting your channels":"Connect your channels"}),a.jsx("ul",{className:"divide-y divide-border",children:i.map(({platform:l,isPending:c})=>a.jsx(Cgs,{platform:l,agentId:e,isPending:c},l.id))})]})})};function Cgs({platform:e,agentId:t,isPending:n}){const{connect:r,isConnecting:s}=rX(e.id);return __e({platform:e.id,agentId:t,hasPendingInstall:n}),a.jsxs("li",{className:"flex items-center gap-3 py-2.5",children:[a.jsx(nX,{platform:e.id,className:"h-5 w-5 shrink-0"}),a.jsx(Y,{as:"span",variant:"body",tone:"ink",className:"min-w-0 flex-1 truncate",children:e.name}),n?a.jsx(Mt,{variant:"warning",size:"sm",indicator:"dot",children:"Pending"}):null,a.jsx(de,{icon:a.jsx(BH,{}),size:"sm",variant:"default",onClick:()=>r(t),disabled:s,children:s?"Connecting...":"Connect"})]})}function hye(){return a.jsxs("div",{className:"min-h-0 space-y-4 overflow-hidden pt-4",children:[a.jsx("div",{className:"flex justify-start",children:a.jsx(xt,{className:"h-10 w-2/3 rounded-2xl"})}),a.jsx("div",{className:"flex justify-end",children:a.jsx(xt,{className:"h-12 w-3/5 rounded-2xl"})}),a.jsx("div",{className:"flex justify-start",children:a.jsxs("div",{className:"w-4/5 space-y-2",children:[a.jsx(xt,{className:"h-4 w-full rounded-full"}),a.jsx(xt,{className:"h-4 w-5/6 rounded-full"}),a.jsx(xt,{className:"h-4 w-2/3 rounded-full"})]})})]})}function tBt(){return a.jsx("div",{className:"grid h-full min-h-0 w-full overflow-hidden px-4 py-4 md:px-10",children:a.jsxs("div",{className:"mx-auto grid h-full min-h-0 w-full max-w-[80ch] grid-rows-[1fr_auto]",children:[a.jsx(hye,{}),a.jsx(nBt,{})]})})}function nBt(){return a.jsxs("div",{className:"rounded-3xl border border-border bg-background px-3 py-2.5",children:[a.jsx(xt,{className:"h-5 w-1/2 rounded-full"}),a.jsxs("div",{className:"mt-4 flex items-center justify-between",children:[a.jsx(xt,{className:"h-control-md w-24 rounded-full"}),a.jsx(xt,{className:"h-control-md w-control-md rounded-full"})]})]})}function _gs(){return a.jsx("div",{className:"flex h-full min-h-0 w-full flex-col items-center justify-center px-4 py-4 md:px-10","data-testid":"agent-landing-skeleton","aria-busy":"true",children:a.jsxs("div",{className:"flex w-full max-w-[80ch] flex-col gap-6",children:[a.jsxs("div",{className:"flex flex-col items-center gap-4",children:[a.jsx(xt,{className:"h-avatar-lg w-avatar-lg rounded-full"}),a.jsx(xt,{className:"h-7 w-2/3 rounded-full"})]}),a.jsx(nBt,{}),a.jsxs("div",{className:"flex flex-col gap-1 px-3",children:[a.jsx(xt,{className:"h-control-md w-2/3 rounded-full"}),a.jsx(xt,{className:"h-control-md w-1/2 rounded-full"}),a.jsx(xt,{className:"h-control-md w-3/5 rounded-full"})]})]})})}const S7=({label:e,children:t})=>a.jsxs("div",{className:"space-y-2",children:[a.jsx(Y,{as:"p",variant:"body",tone:"muted",children:e}),t]});function Tgs(e,t){if(!e||$2t(e).toLowerCase()!=="anthropic")return!1;if(!t)return!0;const r=t.toLowerCase();return/[^0-9]4[.-]5/.test(r)||/[^0-9][5-9][.-]\d/.test(r)}function Egs({provider:e,modelId:t,settings:n,setSettings:r}){const s=Tgs(e,t),i=g.useEffectEvent(()=>{r({...n,modelSettings:{...n?.modelSettings,topP:void 0}})}),o=e&&t?`${e}-${t}`:void 0,l=n?.modelSettings?.topP,c=n?.modelSettings?.temperature;return g.useEffect(()=>{s&&o&&(l===void 0||c===void 0||i())},[s,o,l,c]),{hasSamplingRestriction:s}}const Igs=({canEdit:e=!0})=>{const{settings:t,setSettings:n}=L_e(),[r,s]=g.useState(""),[i,o]=g.useState(!1),[l,c]=g.useState(null),{handleCopy:u}=Fm({text:r}),d=JSON.stringify(t?.modelSettings?.providerOptions??{});g.useEffect(()=>{(async()=>{if(!aQ(d)){c("Invalid JSON");return}const v=await v5(d);s(v)})()},[d]);const f=async()=>{if(c(null),!aQ(r)){c("Invalid JSON");return}const m=await v5(r);s(m)},h=async()=>{try{c(null);const m=JSON.parse(r);n({...t,modelSettings:{...t?.modelSettings,providerOptions:m}}),o(!0),setTimeout(()=>{o(!1)},1e3)}catch(m){console.error("error",m),c("Invalid JSON")}},p=Z(Fn,jn);return a.jsx(mc,{children:a.jsxs("div",{className:"@container/advanced",children:[a.jsxs("div",{className:"grid grid-cols-1 gap-2 pb-2 @xs/advanced:grid-cols-2",children:[a.jsxs(ft,{children:[a.jsx(ut,{children:"Frequency Penalty"}),a.jsx(Sn,{type:"number",step:"0.1",min:"-1",max:"1",readOnly:!e,value:t?.modelSettings?.frequencyPenalty??"",onChange:m=>n({...t,modelSettings:{...t?.modelSettings,frequencyPenalty:m.target.value?Number(m.target.value):void 0}})})]}),a.jsxs(ft,{children:[a.jsx(ut,{children:"Presence Penalty"}),a.jsx(Sn,{type:"number",step:"0.1",min:"-1",max:"1",readOnly:!e,value:t?.modelSettings?.presencePenalty??"",onChange:m=>n({...t,modelSettings:{...t?.modelSettings,presencePenalty:m.target.value?Number(m.target.value):void 0}})})]}),a.jsxs(ft,{children:[a.jsx(ut,{children:"Top K"}),a.jsx(Sn,{type:"number",readOnly:!e,value:t?.modelSettings?.topK||"",onChange:m=>n({...t,modelSettings:{...t?.modelSettings,topK:m.target.value?Number(m.target.value):void 0}})})]}),a.jsxs(ft,{children:[a.jsx(ut,{children:"Max Tokens"}),a.jsx(Sn,{type:"number",readOnly:!e,value:t?.modelSettings?.maxTokens||"",onChange:m=>n({...t,modelSettings:{...t?.modelSettings,maxTokens:m.target.value?Number(m.target.value):void 0}})})]}),a.jsxs(ft,{children:[a.jsx(ut,{children:"Max Steps"}),a.jsx(Sn,{type:"number",readOnly:!e,value:t?.modelSettings?.maxSteps||"",onChange:m=>n({...t,modelSettings:{...t?.modelSettings,maxSteps:m.target.value?Number(m.target.value):void 0}})})]}),a.jsxs(ft,{children:[a.jsx(ut,{children:"Max Retries"}),a.jsx(Sn,{type:"number",readOnly:!e,value:t?.modelSettings?.maxRetries||"",onChange:m=>n({...t,modelSettings:{...t?.modelSettings,maxRetries:m.target.value?Number(m.target.value):void 0}})})]}),a.jsxs(ft,{children:[a.jsx(ut,{children:"Seed"}),a.jsx(Sn,{type:"number",readOnly:!e,value:t?.modelSettings?.seed||"",onChange:m=>n({...t,modelSettings:{...t?.modelSettings,seed:m.target.value?Number(m.target.value):void 0}})})]})]}),a.jsxs(ft,{invalid:!!l,className:"gap-1",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx(ut,{children:"Provider Options"}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsxs(Ln,{children:[a.jsx(Rn,{asChild:!0,children:a.jsx("button",{type:"button",onClick:f,className:p,"aria-label":"Format Provider Options",children:a.jsx(At,{children:a.jsx(Ua,{})})})}),a.jsx(Mn,{children:"Format the Provider Options JSON"})]}),a.jsxs(Ln,{children:[a.jsx(Rn,{asChild:!0,children:a.jsx("button",{type:"button",onClick:u,className:p,"aria-label":"Copy Provider Options",children:a.jsx(At,{children:a.jsx(Lm,{})})})}),a.jsx(Mn,{children:"Copy Provider Options"})]}),e&&a.jsxs(Ln,{children:[a.jsx(Rn,{asChild:!0,children:a.jsx("button",{type:"button",onClick:h,className:p,"aria-label":"Save Provider Options",children:a.jsx(At,{children:i?a.jsx(dr,{}):a.jsx(zm,{})})})}),a.jsx(Mn,{children:i?"Saved":"Save Provider Options"})]})]})]}),a.jsx(Or,{value:r,onChange:s,language:"json",editable:e,showCopyButton:!1,className:"h-75"}),a.jsx(is,{children:l})]})]})})},Ngs=({hasMemory:e,hasSubAgents:t,disabled:n})=>{const r=e&&t,s=n||!r,i=a.jsxs(um,{disabled:s,children:[a.jsx(Jh,{value:"network",className:"text-foreground"}),a.jsx(ut,{children:"Network"})]});if(r)return i;const o=[];return e||o.push("memory enabled"),t||o.push("at least one sub-agent"),a.jsxs(Ln,{children:[a.jsx(Rn,{asChild:!0,children:i}),a.jsx(Mn,{children:a.jsxs("p",{children:["Network is not available. Please make sure you have ",o.join(" and "),"."]})})]})},Ags=({supported:e,disabled:t})=>{const n=t||!e,r=a.jsxs(um,{disabled:n,children:[a.jsx(Jh,{value:"streamSubscription",className:"text-foreground"}),a.jsx(ut,{children:"Stream subscription (default)"})]});return e?r:a.jsxs(Ln,{children:[a.jsx(Rn,{asChild:!0,children:r}),a.jsx(Mn,{children:a.jsx("p",{children:"Stream subscription is not supported for this agent."})})]})},Pgs=({agentId:e})=>{const{data:t,isLoading:n}=yd({agentId:e,requestContext:xr("agent",e)[0],queryOptions:{enabled:!!e}}),{data:r,isLoading:s}=$k({agentId:e,requestContext:xr("agent",e)[0],queryOptions:{enabled:!!e}}),{settings:i,setSettings:o,resetAll:l}=L_e(),{canEdit:c}=Wa(),[u,d]=g.useState(!1),[f,h]=g.useState(!1),p=c("agents"),{hasSamplingRestriction:m}=Egs({provider:t?.provider,modelId:t?.modelId,settings:i,setSettings:o});if(!n&&!t)return null;const v=!!r?.result,y=!!(t&&Object.keys(t.agents||{}).length>0),x=t?.modelVersion,b=x==="v2"||x==="v3",S=t?.supportsMemory!==!1;let k;t&&(b?i?.modelSettings?.chatWithNetwork?k="network":i?.modelSettings?.chatWithGenerate?k="generate":i?.modelSettings?.chatWithLegacyStream||!S?k="stream":k="streamSubscription":k=i?.modelSettings?.chatWithGenerateLegacy?"generateLegacy":"streamLegacy");const j=m&&(i?.modelSettings?.temperature!==void 0||i?.modelSettings?.topP!==void 0);return a.jsxs(a.Fragment,{children:[a.jsxs(_p,{open:f,onOpenChange:(C,T)=>{if(!C&&u){T?.cancel?.();return}h(C)},children:[a.jsx(of,{asChild:!0,children:a.jsx(de,{variant:"ghost",size:"icon-md",type:"button",tooltip:"Model settings","data-testid":"composer-model-settings-trigger",children:a.jsx(SIn,{})})}),a.jsx(lh,{align:"start",className:"w-80 p-4",children:n||s?a.jsx(xt,{className:"h-40 w-full","data-testid":"composer-model-settings-skeleton"}):a.jsxs("section",{className:"@container space-y-5",children:[a.jsx(S7,{label:"Chat Method",children:a.jsxs(N6,{value:k,disabled:!p,onValueChange:C=>p&&o({...i,modelSettings:{...i?.modelSettings,chatWithGenerateLegacy:C==="generateLegacy",chatWithGenerate:C==="generate",chatWithLegacyStream:C==="stream",chatWithNetwork:C==="network"}}),className:"flex flex-col gap-3",children:[!b&&a.jsxs(um,{disabled:!p,children:[a.jsx(Jh,{value:"generateLegacy",className:"text-foreground"}),a.jsx(ut,{children:"Generate (Legacy)"})]}),b&&a.jsxs(um,{disabled:!p,children:[a.jsx(Jh,{value:"generate",className:"text-foreground"}),a.jsx(ut,{children:"Generate"})]}),!b&&a.jsxs(um,{disabled:!p,children:[a.jsx(Jh,{value:"streamLegacy",className:"text-foreground"}),a.jsx(ut,{children:"Stream (Legacy)"})]}),b&&a.jsx(Ags,{supported:S,disabled:!p}),b&&a.jsxs(um,{disabled:!p,children:[a.jsx(Jh,{value:"stream",className:"text-foreground"}),a.jsx(ut,{children:"Stream"})]}),b&&a.jsx(Ngs,{hasMemory:v,hasSubAgents:y,disabled:!p})]})}),a.jsx(S7,{label:"Require Tool Approval",children:a.jsx(Wc,{checked:i?.modelSettings?.requireToolApproval,disabled:!p,onCheckedChange:C=>p&&o({...i,modelSettings:{...i?.modelSettings,requireToolApproval:C}})})}),j&&a.jsxs("div",{"data-testid":"sampling-restriction-banner",className:"flex items-center gap-2 rounded bg-card px-3 py-2 text-muted-foreground",children:[a.jsx(pp,{className:"h-3.5 w-3.5 shrink-0"}),a.jsx(Y,{as:"span",variant:"caption",children:i?.modelSettings?.temperature!==void 0?"Claude 4.5+ models only accept Temperature OR Top P. Clear Temperature to use Top P.":"Claude 4.5+ models only accept Temperature OR Top P. Setting Temperature will clear Top P."})]}),a.jsx(S7,{label:"Temperature",children:a.jsxs("div",{className:"flex flex-row items-center justify-between gap-2",children:[a.jsx(Ove,{value:[i?.modelSettings?.temperature??-.1],max:1,min:-.1,step:.1,disabled:!p,onValueChange:C=>p&&o({...i,modelSettings:{...i?.modelSettings,temperature:C[0]<0?void 0:C[0]}})}),a.jsx(Y,{as:"p",variant:"caption",tone:"muted",children:i?.modelSettings?.temperature??"n/a"})]})}),a.jsx(S7,{label:"Top P",children:a.jsxs("div",{className:"flex flex-row items-center justify-between gap-2",children:[a.jsx(Ove,{disabled:!p,onValueChange:C=>p&&o({...i,modelSettings:{...i?.modelSettings,topP:C[0]<0?void 0:C[0]}}),value:[i?.modelSettings?.topP??-.1],max:1,min:-.1,step:.1}),a.jsx(Y,{as:"p",variant:"caption",tone:"muted",children:i?.modelSettings?.topP??"n/a"})]})}),a.jsxs("div",{className:"flex items-center justify-between gap-2 pt-1",children:[a.jsx(de,{icon:a.jsx(b_,{}),variant:"ghost",size:"sm",type:"button",disabled:!p,onClick:()=>p&&l(),children:"Reset"}),a.jsx(de,{icon:a.jsx(rL,{}),variant:"default",size:"sm",type:"button",disabled:!p,onClick:()=>d(!0),children:"Advanced Settings"})]})]})})]}),a.jsx(rs,{open:u,onOpenChange:d,children:a.jsxs(ss,{size:"lg",children:[a.jsx(es,{children:a.jsx(Gr,{children:"Advanced model settings"})}),a.jsx(Hr,{children:a.jsx(Igs,{canEdit:p})})]})})]})},$gs=()=>{const{data:e}=IP();return{isLiveKitAvailable:e?.liveKitConnectionRouteEnabled!==!1}},Rgs="/voice/livekit/connection-details",eet="lk.agent.state",Mgs="lk.transcription",Dgs="lk.transcription_final";function Lgs(e,t,n,r,s){return(e.find(l=>l.id===t)?e.map(l=>l.id===t?{...l,text:l.text+r,final:l.final||s}:l):[...e,{id:t,role:n,text:r,final:s}]).slice(-20)}const zgs=({agentId:e,threadId:t,onCallStarted:n})=>{const{baseUrl:r,headers:s}=sL(),{isLiveKitAvailable:i}=$gs(),o=mr(),l=g.useRef(n);g.useEffect(()=>{l.current=n},[n]);const[c,u]=g.useState("idle"),[d,f]=g.useState("initializing"),[h,p]=g.useState([]),m=g.useRef(null),v=g.useRef(null),y=g.useRef(null),x=g.useRef(0),b=g.useRef(null),S=g.useCallback(()=>{t&&o.invalidateQueries({queryKey:["memory","messages",t]}),e&&o.invalidateQueries({queryKey:["memory","threads",e,e]})},[e,o,t]),k=g.useCallback(()=>{y.current&&clearTimeout(y.current),y.current=setTimeout(()=>{y.current=null,S()},600)},[S]),j=g.useCallback(()=>{x.current+=1,b.current?.abort(),b.current=null;const _=m.current;m.current=null,_&&_.disconnect(),y.current&&(clearTimeout(y.current),y.current=null),v.current=null,u("idle"),f("initializing")},[]);g.useEffect(()=>j,[j]);const C=g.useCallback(()=>{j(),p([]),S()},[j,S]),T=g.useCallback(async()=>{if(c!=="idle"||!i)return;const _=x.current+=1,N=new AbortController;b.current=N;const I=()=>x.current!==_;u("connecting"),p([]);try{const A=await fetch(`${r}${Rgs}`,{method:"POST",headers:{...s,"content-type":"application/json"},body:JSON.stringify({agentId:e,threadId:t,resourceId:e}),signal:N.signal});if(I())return;if(!A.ok){const V=await A.json().catch(()=>({}));throw new Error(V.error??"LiveKit voice is not configured for this server. Add liveKitConnectionRoute() to server.apiRoutes and run a voice worker.")}const P=await A.json();if(I())return;const{Room:D,RoomEvent:F,Track:Q}=await Ii(async()=>{const{Room:V,RoomEvent:H,Track:M}=await import("./livekit-client.esm-CKIgC2IJ.js");return{Room:V,RoomEvent:H,Track:M}},[],import.meta.url);if(I())return;const q=new D;m.current=q;const B=new Audio;if(B.autoplay=!0,v.current=B,q.on(F.TrackSubscribed,V=>{V.kind===Q.Kind.Audio&&v.current&&V.attach(v.current)}),q.on(F.ParticipantAttributesChanged,(V,H)=>{const M=V[eet]??H.attributes[eet];M&&H.identity!==P.participantName&&f(M)}),q.on(F.Disconnected,()=>{m.current===q&&j()}),q.registerTextStreamHandler(Mgs,async(V,H)=>{const M=H.identity===P.participantName?"user":"agent",G=V.info.attributes?.[Dgs]==="true";for await(const L of V)p($=>Lgs($,V.info.id,M,L,G));M==="agent"&&k()}),await q.connect(P.serverUrl,P.participantToken),I()){q.disconnect(),m.current===q&&(m.current=null);return}if(await q.localParticipant.setMicrophoneEnabled(!0),I()){q.disconnect(),m.current===q&&(m.current=null);return}u("active"),S(),await Promise.resolve(l.current?.()).catch(()=>{})}catch(A){if(N.signal.aborted||I())return;j(),xu.error(A instanceof Error?A.message:"Failed to start the voice call.")}},[e,r,j,s,i,S,k,c,t]);return{status:c,agentState:d,captions:h,isLiveKitAvailable:i,start:()=>{T()},stop:C}},Fgs=({voiceCall:e})=>{const{isLiveKitAvailable:t}=e;return e.status==="idle"?a.jsx(de,{variant:"ghost",size:"icon-md",type:"button","aria-label":"Start voice call","aria-disabled":!t||void 0,tooltip:t?"Start voice call":"Configure @mastra/livekit to start voice calls.","data-testid":"voice-call-button",onClick:()=>e.start(),children:a.jsx(EEn,{})}):e.status==="connecting"?a.jsx(de,{variant:"ghost",size:"icon-md",type:"button",tooltip:"Connecting…","data-testid":"voice-call-button",children:a.jsx(fc,{className:"animate-spin"})}):a.jsx(de,{variant:"destructive-ghost",size:"icon-md",type:"button",tooltip:"End voice call","data-testid":"voice-call-button",onClick:()=>e.stop(),children:a.jsx(_En,{})})},Bgs={initializing:"Connecting…",listening:"Listening…",thinking:"Thinking…",speaking:"Speaking…"},tet=(e,t)=>{for(let n=e.length-1;n>=0;n--)if(e[n]?.role===t)return e[n]},Vgs=({voiceCall:e})=>{if(e.status==="idle")return null;const t=tet(e.captions,"user"),n=tet(e.captions,"agent"),r=e.status==="connecting"?"Connecting…":Bgs[e.agentState];return a.jsxs("div",{"data-testid":"voice-call-panel",className:Z(pr,"mx-auto mb-2 w-full max-w-3xl rounded-[16px] px-4 py-3"),children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("span",{className:Z("h-2 w-2 rounded-full",e.status==="connecting"&&"bg-muted-foreground",e.status==="active"&&e.agentState==="speaking"&&"animate-pulse bg-success-indicator",e.status==="active"&&e.agentState!=="speaking"&&"bg-success-indicator")}),a.jsx(Y,{as:"span",variant:"caption",tone:"muted",children:r})]}),t&&a.jsx(Y,{variant:"caption",tone:"muted",className:"mt-2 truncate","data-testid":"voice-caption-user",children:t.text}),n&&a.jsx(Y,{variant:"caption",tone:"ink",className:"mt-1","data-testid":"voice-caption-agent",children:n.text})]})},Ugs=300,qgs=[],Qgs=(e,t)=>{const[n,r]=g.useState(!1);return g.useEffect(()=>{if(!e){r(!1);return}const s=setTimeout(()=>r(!0),t);return()=>clearTimeout(s)},[e,t]),n},Zgs=e=>e?e.content.parts.some(n=>{if(n.type==="reasoning"||n.type==="text")return"state"in n&&n.state==="streaming";if(n.type==="tool-invocation")return"toolInvocation"in n&&n.toolInvocation.state!=="result";if(n.type==="dynamic-tool"||n.type.startsWith("tool-")){const r="state"in n?n.state:void 0;return r!=="output-available"&&r!=="output-error"}return!1}):!1,Wgs=({turns:e})=>e.length===0?null:a.jsx("div",{"data-testid":"thread-rail-layer",className:"pointer-events-none absolute inset-y-0 left-4 z-20 hidden @min-[58rem]:block",children:a.jsx(kYr,{turns:e,className:"pointer-events-auto sticky top-1/2 -translate-y-1/2"})}),Hgs=({agentName:e,agentId:t,threadId:n,suggestedPrompts:r,hasModelList:s,hideModelSwitcher:i,runOptionsSlot:o,refreshThreadList:l,isHistoryLoading:c,onLoadPrevious:u,isLoadingPrevious:d})=>{const f=g.useRef(null),{draft:h,updateDraft:p}=QIe(n),m=vKr(),{isRunning:v}=a$(),[y]=xr("agent",t??""),{isSpeaking:x,readAloud:b,stop:S}=cas(t,y,{onError:B=>xu.error(B instanceof Error?B.message:"Voice generation failed.")}),{hasSession:k,viewMode:j}=_6(),C=k&&(j==="collapsed"||j==="expanded"),T=m.length===0,_=m[m.length-1],N=v&&(_?.role!=="assistant"||!Zgs(_)),I=Qgs(N,Ugs),A=g.useMemo(()=>MYr(m),[m]),P=g.useMemo(()=>new Set(A.map(B=>B.messageId)),[A]),D=LYr(m,{key:yve,opensTurn:B=>P.has(B.id)}),F=T&&!c,[Q,q]=g.useState(F);return g.useEffect(()=>{if(Q!==F){if(F||!v){q(F);return}bp(()=>q(!1))}},[F,Q,v]),a.jsx(gas,{controlled:h&&p?{value:h.attachments,onChange:B=>p(V=>({...V,attachments:typeof B=="function"?B(V.attachments):B}))}:void 0,children:a.jsx(Ag,{className:"h-full",scroller:{autoScroll:!0,defaultScrollPosition:"last-anchor",onReachStart:u,preserveScrollOnPrepend:!!u},"data-testid":"thread-wrapper",children:a.jsx(Ag.Stage,{children:a.jsxs(Ag.Viewport,{style:{overflowAnchor:"none"},children:[a.jsx(Wgs,{turns:A}),a.jsxs(Ag.Content,{className:Q?"flex-none":void 0,children:[d&&a.jsx(Ag.Column,{"data-testid":"thread-history-older-skeleton","aria-busy":"true","aria-label":"Loading older messages",className:"py-3",children:a.jsx(hye,{})}),T&&c?a.jsx(Ag.Column,{"data-testid":"thread-history-skeleton","aria-busy":"true",className:"flex-1 py-4",children:a.jsx(hye,{})}):Q?null:a.jsxs(Ag.Column,{ref:f,"data-testid":"thread-message-column",className:"relative flex-1 gap-4 py-4",children:[a.jsx(zas,{containerRef:f}),a.jsx(fDt,{children:D.map((B,V)=>{const H=V===D.length-1,M=H&&v&&B.opensTurn&&V>0;return a.jsxs(Ag.Turn,{opensTurn:B.opensTurn,holdsRoom:M,className:"gap-4",children:[B.entries.map(G=>a.jsx(Y_e,{messageId:G.id,scrollAnchor:P.has(G.id),children:a.jsx(Fve,{message:G,hasModelList:s,isSpeaking:x,onReadAloud:b,onStopSpeaking:S})},yve(G))),H&&I&&a.jsx(Wge,{})]},B.key)})}),!v&&a.jsx(qYr,{})]})]}),a.jsxs(Ag.Dock,{"data-testid":Q?"thread-landing":void 0,className:Q?"static flex flex-1 flex-col justify-center py-12 before:hidden":void 0,children:[Q?null:a.jsx(Ag.ScrollButton,{}),a.jsxs(Ag.Column,{className:Q?"gap-6 px-1 md:px-1":"gap-2 px-1 md:px-1",children:[Q?a.jsxs(a.Fragment,{children:[a.jsx(Ggs,{agentName:e}),t?a.jsx(jgs,{agentId:t}):null]}):a.jsxs(a.Fragment,{children:[C&&t&&n&&a.jsx(g2t,{agentName:e}),a.jsx(bls,{})]}),a.jsx("div",{className:Q?"starter-prompt":void 0,children:a.jsx(Kgs,{agentId:t,threadId:n,hasModelList:s,hideModelSwitcher:i,runOptionsSlot:o,refreshThreadList:l})}),Q?a.jsx(Zas,{prompts:r??qgs}):null]})]})]})})})})},Ggs=({agentName:e})=>a.jsxs("div",{"data-testid":"thread-welcome",className:"flex w-full flex-col items-center gap-4",children:[a.jsx("div",{className:"starter-heading",children:a.jsx(FS,{name:e||"Agent",size:"lg"})}),a.jsxs(Y,{as:"h1",variant:"display",tone:"muted",className:"starter-heading mx-auto max-w-2xl text-center font-normal text-balance",children:["What can ",a.jsx("span",{className:"font-medium text-foreground",children:e||"this agent"})," do for you today?"]})]}),Kgs=({agentId:e,threadId:t,hasModelList:n,hideModelSwitcher:r,runOptionsSlot:s,refreshThreadList:i})=>{const{threadInput:o,setThreadInput:l,updateDraft:c,draftStatus:u}=QIe(t),d=g.useRef(null),f=g.useRef(!1),h=g.useRef(0);g.useEffect(()=>()=>{h.current++},[]);const[p,m]=g.useState(),v=F_e(),{attachments:y,toCoreUserMessages:x,clear:b,restore:S,isAddingAttachments:k}=uz(),{isRunning:j,canSendWhileStreaming:C,cancelRun:T}=a$(),[_,N]=g.useState(0),{canExecute:I}=Wa(),A=I("agents"),P=!A||!!u?.restoring;Uas(d,{threadId:t,disabled:P});const D=zgs({agentId:e,threadId:t,onCallStarted:i}),F=o.trim().length===0&&y.length===0,Q=j&&!C,q=async()=>{if(F||Q||!A||u?.restoring||k||f.current)return;f.current=!0;const B=h.current,V=y,H=new Set(V.map(L=>L.id)),M=L=>L?`${o}
|
|
674
674
|
|
|
675
|
-
${L}`:o,G=()=>{h.current===B&&(c?c(L=>({text:M(L.text),attachments:[...V,...L.attachments]})):(l(M),S(V)),m("Your message could not be sent. Your draft has been restored."))};m(void 0);try{const L=y.length>0?await x():void 0;if(h.current!==B)return;c?c($=>({text:$.text===o?"":$.text,attachments:$.attachments.filter(z=>!H.has(z.id))})):(l(""),b()),N($=>$+1),Promise.resolve(v({message:o,attachments:L})).then($=>{$===!1&&G()})}catch{h.current===B&&m("Attachments could not be prepared. Your draft has been kept.")}finally{f.current=!1}};return a.jsxs("div",{className:"relative",style:{viewTransitionName:"agent-chat-composer"},children:[a.jsx(Vgs,{voiceCall:D}),(p||u?.error)&&a.jsx(Y,{variant:"caption",role:"alert",children:p||u?.error}),u?.restoring&&a.jsx(Y,{variant:"caption",role:"status",className:"sr-only",children:"Restoring draft…"}),a.jsx(Las,{disabled:!A||u?.restoring,children:a.jsx(xDt,{className:"relative",onSubmit:B=>{B.preventDefault(),q()},children:a.jsx(wDt,{busy:j,children:a.jsxs(bDt,{sendingPulseKey:_,children:[a.jsx($as,{}),a.jsx(kDt,{ref:d,value:o,placeholder:A?"Enter your message...":"You don't have permission to execute agents",onChange:B=>{l(B.target.value)},onKeyDown:B=>{if(!(B.nativeEvent.isComposing||B.keyCode===229)&&B.key==="Enter"&&!B.shiftKey){if(Q)return;B.preventDefault(),B.stopPropagation(),q()}},disabled:P}),e&&!n&&!r&&a.jsx(Vds,{}),a.jsx(ODt,{children:a.jsx(Xgs,{canExecute:A,agentId:e,runOptionsSlot:s,showModelSwitcher:!!(e&&!n&&!r),isEmpty:F,isRunning:j,canSendWhileStreaming:C,onCancel:()=>{T()},onSetText:B=>{l(B)},voiceCall:D})})]})})})})]})},Ygs=({agentId:e,onTranscript:t})=>{const[n]=xr("agent",e??""),{start:r,stop:s,isListening:i,transcript:o}=bxn({agentId:e,requestContext:n});return g.useEffect(()=>{o&&g.startTransition(()=>t(o))},[t,o]),a.jsx(de,{variant:"ghost",size:"icon-md",type:"button",tooltip:i?"Stop dictation":"Start dictation",onClick:()=>i?s():r(),children:i?a.jsx(pye,{}):a.jsx(HTn,{})})},Xgs=({canExecute:e=!0,agentId:t,showModelSwitcher:n,runOptionsSlot:r,isEmpty:s,isRunning:i,canSendWhileStreaming:o,onCancel:l,onSetText:c,voiceCall:u})=>a.jsxs(a.Fragment,{children:[(n&&t||r)&&a.jsxs("div",{className:"flex max-w-full shrink-0 items-center gap-1.5",children:[n&&t&&a.jsxs(a.Fragment,{children:[a.jsx(Bds,{}),a.jsx(Pgs,{agentId:t})]}),r]}),a.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[e&&a.jsx(vas,{}),e&&a.jsx(Ygs,{agentId:t,onTranscript:c}),e&&t&&u&&a.jsx(Fgs,{voiceCall:u})]}),a.jsx(Jgs,{canExecute:e,isEmpty:s,isRunning:i,canSendWhileStreaming:o,onCancel:l})]})]}),Jgs=({canExecute:e=!0,isEmpty:t,isRunning:n,canSendWhileStreaming:r,onCancel:s})=>{const{isAddingAttachments:i}=uz();return n&&!r?a.jsx(de,{variant:"default",size:"icon-md",type:"button",tooltip:"Cancel",onClick:s,children:a.jsx(pye,{})}):a.jsxs(a.Fragment,{children:[a.jsx(de,{type:"submit",variant:"default",size:"icon-md",tooltip:e?"Send":"No permission to execute",disabled:!e||t||i,children:a.jsx(ck,{})}),n&&a.jsx(de,{variant:"default",size:"icon-md",type:"button",tooltip:"Cancel",onClick:s,children:a.jsx(pye,{})})]})},pye=()=>a.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:Fn,children:[a.jsx("circle",{cx:"12",cy:"12",r:"10"}),a.jsx("rect",{width:"6",height:"6",x:"9",y:"9",rx:"1"})]}),jNe=({agentId:e,agentName:t,threadId:n,memory:r,refreshThreadList:s,modelVersion:i,agentVersionId:o,supportsMemory:l,modelList:c,messageId:u,suggestedPrompts:d,isNewThread:f,hideModelSwitcher:h,runOptionsSlot:p})=>{const{settings:m}=L_e(),v=xr("agent",e)[0],{data:y,isLoading:x,fetchNextPage:b,hasNextPage:S,isFetchingNextPage:k}=sK({agentId:e,threadId:f?void 0:n,memory:r??!1,requestContext:v});g.useEffect(()=>{u&&y&&!x&&setTimeout(()=>{const _=document.querySelector(`[data-message-id="${u}"]`);_&&(_.scrollIntoView({behavior:"smooth",block:"center"}),_.classList.add("bg-muted"),setTimeout(()=>{_.classList.remove("bg-muted")},2e3))},100)},[u,y,x]);const j=g.useRef({threadId:n,messages:[]});j.current.threadId!==n&&(j.current={threadId:n,messages:[]});const C=y?.messages??j.current.messages,T=()=>{k||b()};return a.jsx(BKr,{agentId:e,agentName:t,modelVersion:i,agentVersionId:o,supportsMemory:l,threadId:n,initialMessages:C,refreshThreadList:s,settings:m,requestContext:v,children:a.jsx(Hgs,{agentName:t??"",agentId:e,threadId:n,suggestedPrompts:d,hasModelList:!!c,hideModelSwitcher:h,refreshThreadList:s,runOptionsSlot:p,isHistoryLoading:x,onLoadPrevious:S?T:void 0,isLoadingPrevious:k})})};function cW(){return a.jsx(Xt,{tone:"error",titleSlot:"Agent not found",descriptionSlot:"This agent may have been renamed or removed. Reload to check again, or choose another agent.",actionSlot:a.jsxs("div",{className:"flex flex-wrap justify-center gap-2",children:[a.jsx(de,{onClick:()=>window.location.reload(),children:"Reload"}),a.jsx(de,{render:a.jsx(lc,{to:"/agents"}),children:"Choose agent"})]})})}function net(){const{agentId:e,threadId:t}=jr(),[n]=oi(),{data:r,isLoading:s,error:i}=yd({agentId:e,requestContext:xr("agent",e)[0],queryOptions:{enabled:!!e}}),{data:o}=$k({agentId:e,requestContext:xr("agent",e)[0],queryOptions:{enabled:!!e}}),l=Dr(),c=t==="new",u=g.useMemo(()=>Sa(),[t]),d=!!o?.result,{refetch:f}=R_e({resourceId:e,agentId:e,isMemoryEnabled:d,requestContext:xr("agent",e)[0],queryOptions:{enabled:!!d}});g.useEffect(()=>{d&&(t||l(`/agents/${e}/session/new`))},[d,t,e,l]);const h=n.get("messageId")??void 0,p=g.useMemo(()=>cNe(r),[r]);if(i&&js(i))return a.jsx(ai,{variant:"fill"});if(i&&Cs(i))return a.jsx(Gs,{variant:"fill",resource:"agents"});if(s)return a.jsx(evs,{});if(i&&kk(i))return a.jsx(cW,{});if(i)return a.jsx(Xt,{tone:"error",titleSlot:"Failed to load agent",descriptionSlot:i.message});if(!r)return a.jsx(cW,{});const m=c?u:t??u,v=async()=>{await f(),c&&l(`/agents/${e}/session/${u}`)};return a.jsx(W2t,{agentId:e,defaultSettings:p,children:a.jsx(iDt,{agentId:e,threadId:m,resourceId:e,children:a.jsx(sX,{children:a.jsx(iX,{agentId:e,threadId:m,enabled:!!(r?.hasBrowser??r?.browserTools?.length),children:a.jsx(qIe,{children:a.jsx(lDt,{children:a.jsx(lX,{children:a.jsxs(Et,{variant:"fit",children:[a.jsx("h1",{className:"sr-only",children:e}),a.jsx(Z2t,{}),a.jsx("div",{className:"relative grid h-full min-h-0",children:a.jsx(jNe,{agentId:e,agentName:r?.name,modelVersion:r?.modelVersion,supportsMemory:r?.supportsMemory,threadId:m,memory:d,refreshThreadList:v,modelList:r?.modelList,messageId:h,isNewThread:c,hideModelSwitcher:!0,runOptionsSlot:a.jsx(uNe,{agentId:e})},m)})]})})})})},`session-${e}-${m}`)},`browser-${e}-${m}`)})})}const evs=()=>a.jsxs(Et,{variant:"fit",children:[a.jsx("h1",{className:"sr-only",children:"Agent session"}),a.jsx(Z2t,{}),a.jsx("div",{className:"relative grid h-full overflow-y-auto pt-4","data-testid":"agent-session-skeleton","aria-busy":"true",children:a.jsx(tBt,{})})]}),tvs={purple:{icon:"text-badge-purple-indicator"},amber:{icon:"text-badge-amber-indicator"},emerald:{icon:"text-badge-green-indicator"},sky:{icon:"text-badge-blue-indicator"},cyan:{icon:"text-badge-cyan-indicator"},orange:{icon:"text-badge-orange-indicator"}},GI=e=>e?Object.keys(e).length:0,IJ=e=>e>0?String(e):"Off",rBt=e=>(e?.inputProcessors?.length??0)+(e?.outputProcessors?.length??0),sBt=e=>!!e?.result,iBt=(e,t)=>!!(t&&e&&e.editor!==!1);function v$({view:e,label:t,status:n,description:r,docsHref:s,enabled:i,tone:o,icon:l}){const c=tvs[o].icon;return e==="chip"?a.jsx("span",{"aria-label":`${t}: ${n}`,className:Z("pointer-events-none inline-flex h-5 min-w-5 items-center justify-center rounded-full px-1 text-muted-foreground",i?c:void 0),children:a.jsx("span",{className:"size-3 shrink-0 [&>svg]:size-3",children:l})}):a.jsxs("a",{"aria-label":`${t}: ${n}`,href:s,target:"_blank",rel:"noopener noreferrer",className:Z("group/capability-row flex min-w-0 items-start gap-2 rounded-md px-2 py-1.5","hover:bg-fill-subtle",Ri,Fn,jn),children:[a.jsx("span",{className:Z("mt-0.5 size-3.5 shrink-0 text-muted-foreground [&>svg]:size-3.5",jn,i?c:"group-hover/capability-row:text-foreground"),children:l}),a.jsxs("span",{className:"min-w-0 flex-1",children:[a.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[a.jsx(Y,{as:"span",variant:"meta",tone:"ink",className:"min-w-0 truncate",children:t}),a.jsx(Y,{as:"span",variant:"meta",tone:"muted",className:"shrink-0 tabular-nums",children:n})]}),a.jsx(Y,{as:"span",variant:"meta",tone:"muted",className:"mt-0.5 block",children:r})]}),a.jsx(Zs,{className:Z("mt-0.5 size-3 shrink-0 text-muted-foreground group-hover/capability-row:text-foreground",jn)})]})}function ret({agentId:e,view:t}){const{data:n,isLoading:r}=$k({agentId:e,requestContext:xr("agent",e)[0],queryOptions:{enabled:!!e}}),s=sBt(n),i=s?n?.memoryType==="gateway"?"Gateway":"On":"Off",o=r?"Checking":i;return a.jsx(v$,{view:t,label:"Memory",status:o,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:a.jsx(o$,{})})}function set({agentId:e,view:t}){const{data:n,isLoading:r}=yd({agentId:e,requestContext:xr("agent",e)[0],queryOptions:{enabled:!!e}}),{isCmsAvailable:s,isLoading:i}=zx(),o=iBt(n,s),l=n?.editor===!1,c=zL({agentId:e,params:{orderBy:{field:"createdAt",direction:"DESC"}},queryOptions:{enabled:!!e&&o}}),u=c.data?.total??c.data?.versions.length??0,d=r||i||o&&c.isLoading,f=u>0?String(u):"Ready",p=d?"Checking":o?f:l?"Locked":"Off",v=o?"Editor is available for versioned agent overrides.":l?"This code-defined agent explicitly disables editor overrides.":"Register MastraEditor to enable versioned agent overrides.";return a.jsx(v$,{view:t,label:"Editor",status:p,description:v,docsHref:"https://mastra.ai/docs/editor/overview",enabled:o,tone:"amber",icon:a.jsx(Fc,{})})}function iet({agentId:e,view:t}){const{data:n,isLoading:r}=yd({agentId:e,requestContext:xr("agent",e)[0],queryOptions:{enabled:!!e}}),s=GI(n?.tools);return a.jsx(v$,{view:t,label:"Tools",status:r?"Checking":IJ(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:a.jsx(cd,{})})}function oet({agentId:e,view:t}){const{data:n,isLoading:r}=yd({agentId:e,requestContext:xr("agent",e)[0],queryOptions:{enabled:!!e}}),s=GI(n?.workflows);return a.jsx(v$,{view:t,label:"Workflows",status:r?"Checking":IJ(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:a.jsx(dk,{})})}function aet({agentId:e,view:t}){const{data:n,isLoading:r}=yd({agentId:e,requestContext:xr("agent",e)[0],queryOptions:{enabled:!!e}}),s=GI(n?.agents);return a.jsx(v$,{view:t,label:"Sub-agents",status:r?"Checking":IJ(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:a.jsx(M0e,{})})}function cet({agentId:e,view:t}){const{data:n,isLoading:r}=yd({agentId:e,requestContext:xr("agent",e)[0],queryOptions:{enabled:!!e}}),s=rBt(n);return a.jsx(v$,{view:t,label:"Processors",status:r?"Checking":IJ(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:a.jsx(wht,{})})}function nvs({agentId:e}){const{data:t}=$k({agentId:e,requestContext:xr("agent",e)[0],queryOptions:{enabled:!!e}}),{data:n}=yd({agentId:e,requestContext:xr("agent",e)[0],queryOptions:{enabled:!!e}}),{isCmsAvailable:r}=zx(),s=[sBt(t),iBt(n,r),GI(n?.tools)>0,GI(n?.workflows)>0,GI(n?.agents)>0,rBt(n)>0],i=s.filter(Boolean).length;return a.jsxs(Y,{as:"span",variant:"meta",tone:"muted",className:"shrink-0",children:[i,"/",s.length]})}function rvs({agentId:e}){const[t,n]=g.useState(!1);return a.jsx(Kl,{open:t,onOpenChange:n,children:a.jsxs("div",{className:"shrink-0 border-t border-border",children:[a.jsx(Cl,{asChild:!0,"aria-label":t?"Hide capability details":"Show capability details",children:a.jsxs("button",{type:"button","data-testid":"agent-capabilities-footer",className:Z("flex w-full cursor-pointer items-center gap-1.5 px-2 py-2 text-left hover:bg-fill-subtle focus-visible:bg-fill-subtle active:bg-fill aria-expanded:bg-fill-hover data-[panel-open]:bg-fill-hover",jx,Fn,jn),children:[a.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-1.5 overflow-hidden",children:[a.jsx(ret,{agentId:e,view:"chip"}),a.jsx(set,{agentId:e,view:"chip"}),a.jsx(iet,{agentId:e,view:"chip"}),a.jsx(oet,{agentId:e,view:"chip"}),a.jsx(aet,{agentId:e,view:"chip"}),a.jsx(cet,{agentId:e,view:"chip"})]}),a.jsx(nvs,{agentId:e}),a.jsx(Na,{direction:"right",className:"size-3.5 text-muted-foreground"})]})}),a.jsx(_l,{className:"px-2 pb-2",children:a.jsxs("div",{className:"grid gap-1",children:[a.jsx(ret,{agentId:e,view:"row"}),a.jsx(set,{agentId:e,view:"row"}),a.jsx(iet,{agentId:e,view:"row"}),a.jsx(oet,{agentId:e,view:"row"}),a.jsx(aet,{agentId:e,view:"row"}),a.jsx(cet,{agentId:e,view:"row"})]})})]})})}function svs(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 ivs(e){return typeof e=="object"&&e!==null&&"parts"in e&&Array.isArray(e.parts)}function ovs(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 avs(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 lvs(e){const t=[];for(const n of e){const r=svs(n.content);if(ivs(r))for(const s of r.parts)ovs(s)&&t.push(avs(s,new Date(n.createdAt).toISOString()))}return t.sort((n,r)=>n.timestamp.localeCompare(r.timestamp)),t}function LA(e){return/[Zz+-]\d{0,4}$/.test(e.trim())?new Date(e).getTime():new Date(e.trim().replace(" ","T")+"Z").getTime()}function cvs(e){if(e.length===0)return{tMin:0,tMax:1};let t=1/0,n=-1/0;for(const r of e){const s=LA(r);s<t&&(t=s),s>n&&(n=s)}return t===n?{tMin:t,tMax:t+1}:{tMin:t,tMax:n}}function yz(e,t){return(LA(e)-t.tMin)/(t.tMax-t.tMin)}function CNe(e,t){return new Date(t.tMin+e*(t.tMax-t.tMin))}function uvs(e,t){return CNe(e,t).getTime()}function oBt(e){const t=e.lastObservedAt??e.updatedAt;return typeof t=="string"?t:new Date(t).toISOString()}function dvs(e){return LA(oBt(e))}function fvs(e,t){if(t==null)return null;const r=e.map(s=>({id:s.id,t:LA(oBt(s))})).toSorted((s,i)=>s.t-i.t).findLast(s=>s.t<=t);return r?r.id:null}function uet(e){const t=e.lastObservedAt??e.updatedAt;return typeof t=="string"?t:new Date(t).toISOString()}function hvs(e){return[...e].sort((t,n)=>LA(uet(t))-LA(uet(n)))}function pvs({markers:e,omRecords:t,observationThreshold:n,reflectionThreshold:r}){const s=[...e].filter(o=>o.type==="status"&&(o.pendingTokens!=null||o.observationTokens!=null)).sort((o,l)=>o.timestamp.localeCompare(l.timestamp)).at(-1),i=hvs(t).at(-1);return{messageTokens:s?.pendingTokens??i?.pendingMessageTokens,messageThreshold:s?.observationThreshold??n,memoryTokens:s?.observationTokens??i?.observationTokenCount,memoryThreshold:s?.reflectionThreshold??r}}function ID(e){const t=e.lastObservedAt??e.updatedAt;return typeof t=="string"?t:new Date(t).toISOString()}function mvs(e,t,n){const r=e.map(i=>({ts:String(ID(i)),pendingMessageTokens:i.pendingMessageTokens})),s=t.flatMap(i=>i.pendingTokens==null?[]:{ts:i.timestamp,pendingMessageTokens:i.pendingTokens});return[...r,...s].sort((i,o)=>i.ts.localeCompare(o.ts)).map(i=>({t:yz(i.ts,n),pendingMessageTokens:i.pendingMessageTokens}))}function gvs(e,t,n){const r=[...e.map(i=>({ts:String(ID(i)),observationTokenCount:i.observationTokenCount})),...t.flatMap(i=>i.type!=="status"||i.observationTokens==null?[]:{ts:i.timestamp,observationTokenCount:i.observationTokens})].sort((i,o)=>i.ts.localeCompare(o.ts));let s=0;return r.map(i=>(s=Math.max(s,i.observationTokenCount),{t:yz(i.ts,n),observationTokenCount:s}))}function vvs(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,i)=>s.ts.localeCompare(i.ts));let r=0;return n.map(s=>(r=Math.max(0,r+s.bufferedObservationTokenCount),{t:yz(s.ts,t),bufferedObservationTokenCount:r}))}function yvs(e,t){return[...e].sort((n,r)=>String(ID(n)).localeCompare(String(ID(r)))).map(n=>({t:yz(String(ID(n)),t),event:1}))}function xvs(e,t){return[...e].sort((n,r)=>new Date(n.createdAt).getTime()-new Date(r.createdAt).getTime()).map(n=>({t:yz(new Date(n.createdAt).toISOString(),t),event:1,role:n.role}))}function bvs(e,t,n){const r=new Map;for(const c of e)c.t!==void 0&&r.set(c.t,Number(c[t]??0));const s=n.reduce((c,u)=>{const d=c.get(u.t);return d?d.push(u):c.set(u.t,[u]),c},new Map),i=Array.from(new Set([...r.keys(),...s.keys()])).sort((c,u)=>c-u);let o=0;const l=[];for(const c of i){const u=r.get(c);u!=null&&(o=u);const d=s.get(c);if(d)for(const f of d)l.push({...f,t:c,[t]:o});else l.push({t:c,[t]:o})}return l}function wvs(e,t,n){if(n==null)return;const r=Math.max(0,...e.map(s=>Number(s[t])||0));return Math.max(r,n)}function Svs(e){return e==null?null:Number(e)}function kvs(e){return!!e?.event}const Ovs="var(--chart-green)",jvs="var(--chart-amber)",det="var(--chart-pink)";function Cvs({domain:e}){const t=[0,.25,.5,.75,1];return a.jsxs("div",{className:"grid grid-cols-[6rem_1fr] items-center",children:[a.jsx(Y,{variant:"meta",tone:"muted",className:"flex items-center self-stretch border-r border-border pl-3",children:"Time"}),a.jsx("div",{className:"flex justify-between px-1 py-1.5",children:t.map(n=>a.jsx(Y,{tone:"muted",as:"span",variant:"meta",font:"mono",children:os(CNe(n,e),"date-time-seconds",{timeZone:"UTC"})},n))})]})}function _Ne({active:e,payload:t,domain:n,showValue:r}){if(!e||!t?.length)return null;const s=t[0]?.payload?.t,i=n!=null&&s!=null?os(CNe(s,n),"date-time-seconds",{timeZone:"UTC"}):null,o=t.filter(l=>l.name!=="t"&&l.name!=="time"&&l.value!=null);return r?a.jsxs("div",{className:`${rh} flex flex-col gap-0.5 rounded px-2 py-1.5 tabular-nums`,children:[i&&a.jsxs("div",{className:"flex items-center justify-between gap-3",children:[a.jsx(Y,{as:"span",variant:"meta",tone:"muted",children:"time"}),a.jsx(Y,{as:"span",variant:"meta",font:"mono",tone:"ink",children:i})]}),o.map(l=>a.jsxs("div",{className:"flex items-center justify-between gap-3",children:[a.jsx(Y,{as:"span",variant:"meta",tone:"muted",children:l.name}),a.jsx(Y,{as:"span",variant:"meta",tone:"ink",children:typeof l.value=="number"?Math.round(l.value).toLocaleString():String(l.value)})]},l.name))]}):a.jsx(Y,{as:"p",variant:"meta",className:`${rh} rounded px-2 py-1`,children:i&&a.jsx(Y,{as:"span",variant:"meta",font:"mono",tone:"ink",children:i})})}function _vs({label:e,data:t,dataKey:n,color:r,gradientId:s,domain:i,zoomDomain:o,threshold:l}){const c=wvs(t,n,l);return a.jsxs("div",{className:"relative grid grid-cols-[6rem_1fr] items-center border-b border-border hover:z-10",children:[a.jsx(Y,{variant:"meta",tone:"muted",className:"flex items-center self-stretch border-r border-border pl-3",children:e}),a.jsx("div",{children:a.jsx(oA,{width:"100%",height:32,children:a.jsxs(o$r,{data:t,margin:{top:0,right:0,bottom:0,left:0},children:[a.jsx("defs",{children:a.jsxs("linearGradient",{id:s,x1:"0",y1:"0",x2:"0",y2:"1",children:[a.jsx("stop",{offset:"0%",stopColor:r,stopOpacity:.35}),a.jsx("stop",{offset:"100%",stopColor:r,stopOpacity:.03})]})}),a.jsx(h6,{dataKey:"t",type:"number",domain:o,allowDataOverflow:!0,hide:!0}),a.jsx(p6,{type:"number",domain:c!=null?[0,c]:void 0,hide:!0}),a.jsx(l6,{content:a.jsx(_Ne,{domain:i,showValue:!0}),cursor:{stroke:"var(--border)"}}),a.jsx(yY,{type:"linear",dataKey:n,stroke:r,strokeWidth:1,fill:`url(#${s})`,isAnimationActive:!1}),l!=null&&a.jsx(gY,{y:l,stroke:"var(--border-strong)",strokeDasharray:"4 3"})]})})})]})}function Tvs({label:e,data:t,color:n,height:r=32,domain:s,zoomDomain:i}){return a.jsxs("div",{className:"relative grid grid-cols-[6rem_1fr] items-center border-b border-border hover:z-10",children:[a.jsx(Y,{variant:"meta",tone:"muted",className:"flex items-center self-stretch border-r border-border pl-3",children:e}),a.jsx("div",{children:a.jsx(oA,{width:"100%",height:r,children:a.jsxs(s$r,{margin:{top:0,right:0,bottom:0,left:0},children:[a.jsx(h6,{dataKey:"t",type:"number",domain:i,allowDataOverflow:!0,hide:!0}),a.jsx(p6,{dataKey:"event",type:"number",domain:[0,2],hide:!0}),a.jsx(l6,{content:a.jsx(_Ne,{domain:s}),cursor:!1}),a.jsx(vIt,{data:t,fill:n,isAnimationActive:!1,shape:o=>{const l=o.cx;return a.jsxs("g",{children:[a.jsx("rect",{x:l-6,y:0,width:12,height:r,fill:"transparent"}),a.jsx("rect",{x:l-1.5,y:0,width:3,height:r,fill:n})]})}})]})})})]})}function fet({label:e,areaData:t,areaDataKey:n,eventData:r,color:s,gradientId:i,domain:o,zoomDomain:l,threshold:c,height:u=44,onSelectT:d}){const f=bvs(t,n,r);return a.jsxs("div",{className:"relative grid grid-cols-[6rem_1fr] items-center border-b border-border hover:z-10",children:[a.jsx(Y,{variant:"meta",tone:"muted",className:"flex items-center self-stretch border-r border-border pl-3",children:e}),a.jsx("div",{children:a.jsx(oA,{width:"100%",height:u,children:a.jsxs(Hje,{margin:{top:0,right:0,bottom:0,left:0},onClick:h=>{const p=Svs(h?.activeLabel);p!=null&&d&&d(p)},className:d?"cursor-pointer":void 0,children:[a.jsx("defs",{children:a.jsxs("linearGradient",{id:i,x1:"0",y1:"0",x2:"0",y2:"1",children:[a.jsx("stop",{offset:"0%",stopColor:s,stopOpacity:.35}),a.jsx("stop",{offset:"100%",stopColor:s,stopOpacity:.06})]})}),a.jsx(h6,{dataKey:"t",type:"number",domain:l,allowDataOverflow:!0,hide:!0}),a.jsx(p6,{yAxisId:"area",dataKey:n,type:"number",hide:!0,domain:[0,"dataMax"]}),a.jsx(l6,{content:a.jsx(_Ne,{domain:o,showValue:!0}),cursor:!1}),a.jsx(yY,{yAxisId:"area",data:f,type:"linear",dataKey:n,stroke:s,strokeWidth:1,fill:`url(#${i})`,isAnimationActive:!1,activeDot:{r:5,stroke:s,strokeWidth:2,fill:"var(--background)"},dot:h=>kvs(h.payload)?a.jsx("circle",{cx:h.cx,cy:h.cy,r:4,fill:s}):a.jsx(a.Fragment,{})}),c!=null&&a.jsx(gY,{yAxisId:"area",y:c,stroke:"var(--border-strong)",strokeDasharray:"4 3"})]})})})]})}function Evs({tDomain:e,zoomLeft:t,zoomRight:n,onZoomLeftChange:r,onZoomRightChange:s,onReset:i}){const o=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(h=>{const p=o.current;if(!p)return null;const m=p.getBoundingClientRect(),v=Math.max(0,Math.min(1,(h-m.left)/m.width));return e.tMin+v*(e.tMax-e.tMin)},[e.tMin,e.tMax]);return g.useEffect(()=>{const h=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)))},p=()=>{l.current=null};return window.addEventListener("mousemove",h),window.addEventListener("mouseup",p),()=>{window.removeEventListener("mousemove",h),window.removeEventListener("mouseup",p)}},[f,t,n,r,s]),a.jsxs("div",{className:"grid grid-cols-[6rem_1fr] items-center border-b border-border",children:[a.jsxs("div",{className:"flex items-center gap-1 self-stretch border-r border-border pl-3",children:[a.jsx(Y,{variant:"meta",tone:"muted",children:"Zoom"}),a.jsx(de,{variant:"ghost",size:"icon-sm","aria-label":"Reset zoom",onClick:i,children:a.jsx(b_,{className:"size-3"})})]}),a.jsxs("div",{ref:o,"data-zoom-track":"",className:"relative h-6 cursor-pointer select-none",onMouseDown:h=>{const p=f(h.clientX);if(p==null)return;h.preventDefault();const m=Math.abs(p-t),v=Math.abs(p-n);m<=v?(r(Math.min(p,n)),l.current="left"):(s(Math.max(p,t)),l.current="right")},children:[a.jsx("div",{"data-zoom-part":"before",className:"absolute inset-y-0 left-0 bg-background/60",style:{width:`${u}%`}}),a.jsx("div",{"data-zoom-part":"band",className:"absolute inset-y-0 border-y border-surface-rim bg-fill-subtle",style:{left:`${u}%`,right:`${100-d}%`}}),a.jsx("div",{"data-zoom-part":"after",className:"absolute inset-y-0 right-0 bg-background/60",style:{width:`${100-d}%`}}),a.jsx("div",{"data-zoom-handle":"left",className:"absolute inset-y-0 w-1 cursor-col-resize bg-foreground/50 hover:bg-foreground",style:{left:`${u}%`,transform:"translateX(-50%)"},onMouseDown:h=>{h.preventDefault(),h.stopPropagation(),l.current="left"}}),a.jsx("div",{"data-zoom-handle":"right",className:"absolute inset-y-0 w-1 cursor-col-resize bg-foreground/50 hover:bg-foreground",style:{left:`${d}%`,transform:"translateX(-50%)"},onMouseDown:h=>{h.preventDefault(),h.stopPropagation(),l.current="right"}})]})]})}const Ivs={tMin:0,tMax:1};function Nvs({omRecords:e,markers:t,messages:n,tDomain:r,observationThreshold:s,reflectionThreshold:i,onSelectTimestamp:o,zoomRange:l,onZoomRangeChange:c}){const u=r??Ivs,d=g.useCallback(Q=>{o?.(uvs(Q,u))},[o,u]),f=l!=null&&c!=null,[h,p]=g.useState(u.tMin),[m,v]=g.useState(u.tMax);g.useEffect(()=>{f||(p(u.tMin),v(u.tMax))},[u.tMin,u.tMax,f]);const y=f?l.left:h,x=f?l.right:m,b=g.useCallback(Q=>{f?c({left:Q,right:x}):p(Q)},[f,c,x]),S=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}):(p(u.tMin),v(u.tMax))},[f,c,u.tMin,u.tMax]),j=u.tMax-u.tMin,C=j>0?(y-u.tMin)/j:0,T=j>0?(x-u.tMin)/j:1,_=[C,T],N=g.useMemo(()=>xvs(n,u),[n,u]),I=g.useMemo(()=>mvs(e,t,u),[e,t,u]),A=g.useMemo(()=>gvs(e,t,u),[e,t,u]),P=g.useMemo(()=>vvs(t,u),[t,u]),D=g.useMemo(()=>yvs(e,u),[e,u]);return N.length>0||I.length>0||A.length>0||D.length>0?a.jsxs("div",{className:"flex flex-col pr-2 pb-2 [&_.recharts-surface]:outline-none",children:[a.jsx(fet,{label:"Messages",areaData:I,areaDataKey:"pendingMessageTokens",eventData:N,color:Ovs,gradientId:"grad-messages",domain:u,zoomDomain:_,threshold:s,onSelectT:o?d:void 0}),a.jsx(fet,{label:"Observations",areaData:A,areaDataKey:"observationTokenCount",eventData:D,color:jvs,gradientId:"grad-observations",domain:u,zoomDomain:_,threshold:i,onSelectT:o?d:void 0}),P.length>0&&a.jsx(_vs,{label:"Buffered obs",data:P,dataKey:"bufferedObservationTokenCount",color:det,gradientId:"grad-buffered-obs",domain:u,zoomDomain:_,threshold:i}),D.length>0&&a.jsx(Tvs,{label:"Events",data:D,color:det,domain:u,zoomDomain:_}),a.jsx(Cvs,{domain:u}),a.jsx(Evs,{tDomain:u,zoomLeft:y,zoomRight:x,onZoomLeftChange:b,onZoomRightChange:S,onReset:k})]}):null}const Avs=g.lazy(()=>Ii(async()=>{const{CodeDiff:e}=await import("./CodeDiff.es-D8JrUO0B.js");return{CodeDiff:e}},__vite__mapDeps([9,4,1,3]),import.meta.url).then(({CodeDiff:e})=>({default:e})));function Pvs(e){if(!e)return null;const t=e.match(/^(\d{1,2}):(\d{2})$/);if(!t)return e;const[,n,r]=t;return os(new Date(2e3,0,1,Number(n),Number(r)),"time")??e}function $vs(e,t){if(t)return{card:"bg-transparent border-transparent",text:"text-muted-foreground",time:"text-muted-foreground"};if(!e)return{card:"border-border bg-background",text:"text-foreground",time:"text-muted-foreground"};const n=Ave[e];return{card:n.card,text:"text-foreground",time:n.time}}function Rvs(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[o,l]of Object.entries(Nve))if(n.startsWith(o)){r=l,n=n.slice(o.length).trimStart();break}let s=null;const i=n.match(/^\((\d{1,2}:\d{2})\)/);if(i){const[o,l]=i;o!==void 0&&l!==void 0&&(s=l,n=n.slice(o.length).trimStart())}if(n)return{text:n,time:s,priority:r,children:[]}}return{text:t,time:null,priority:null,children:[]}}function Mvs(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 i=s.split(`
|
|
675
|
+
${L}`:o,G=()=>{h.current===B&&(c?c(L=>({text:M(L.text),attachments:[...V,...L.attachments]})):(l(M),S(V)),m("Your message could not be sent. Your draft has been restored."))};m(void 0);try{const L=y.length>0?await x():void 0;if(h.current!==B)return;c?c($=>({text:$.text===o?"":$.text,attachments:$.attachments.filter(z=>!H.has(z.id))})):(l(""),b()),N($=>$+1),Promise.resolve(v({message:o,attachments:L})).then($=>{$===!1&&G()})}catch{h.current===B&&m("Attachments could not be prepared. Your draft has been kept.")}finally{f.current=!1}};return a.jsxs("div",{className:"relative",style:{viewTransitionName:"agent-chat-composer"},children:[a.jsx(Vgs,{voiceCall:D}),(p||u?.error)&&a.jsx(Y,{variant:"caption",role:"alert",children:p||u?.error}),u?.restoring&&a.jsx(Y,{variant:"caption",role:"status",className:"sr-only",children:"Restoring draft…"}),a.jsx(Las,{disabled:!A||u?.restoring,children:a.jsx(xDt,{className:"relative",onSubmit:B=>{B.preventDefault(),q()},children:a.jsx(wDt,{busy:j,children:a.jsxs(bDt,{sendingPulseKey:_,children:[a.jsx($as,{}),a.jsx(kDt,{ref:d,value:o,placeholder:A?"Enter your message...":"You don't have permission to execute agents",onChange:B=>{l(B.target.value)},onKeyDown:B=>{if(!(B.nativeEvent.isComposing||B.keyCode===229)&&B.key==="Enter"&&!B.shiftKey){if(Q)return;B.preventDefault(),B.stopPropagation(),q()}},disabled:P}),e&&!n&&!r&&a.jsx(Vds,{}),a.jsx(ODt,{children:a.jsx(Xgs,{canExecute:A,agentId:e,runOptionsSlot:s,showModelSwitcher:!!(e&&!n&&!r),isEmpty:F,isRunning:j,canSendWhileStreaming:C,onCancel:()=>{T()},onSetText:B=>{l(B)},voiceCall:D})})]})})})})]})},Ygs=({agentId:e,onTranscript:t})=>{const[n]=xr("agent",e??""),{start:r,stop:s,isListening:i,transcript:o}=bxn({agentId:e,requestContext:n});return g.useEffect(()=>{o&&g.startTransition(()=>t(o))},[t,o]),a.jsx(de,{variant:"ghost",size:"icon-md",type:"button",tooltip:i?"Stop dictation":"Start dictation",onClick:()=>i?s():r(),children:i?a.jsx(pye,{}):a.jsx(HTn,{})})},Xgs=({canExecute:e=!0,agentId:t,showModelSwitcher:n,runOptionsSlot:r,isEmpty:s,isRunning:i,canSendWhileStreaming:o,onCancel:l,onSetText:c,voiceCall:u})=>a.jsxs(a.Fragment,{children:[(n&&t||r)&&a.jsxs("div",{className:"flex max-w-full shrink-0 items-center gap-1.5",children:[n&&t&&a.jsxs(a.Fragment,{children:[a.jsx(Bds,{}),a.jsx(Pgs,{agentId:t})]}),r]}),a.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[e&&a.jsx(vas,{}),e&&a.jsx(Ygs,{agentId:t,onTranscript:c}),e&&t&&u&&a.jsx(Fgs,{voiceCall:u})]}),a.jsx(Jgs,{canExecute:e,isEmpty:s,isRunning:i,canSendWhileStreaming:o,onCancel:l})]})]}),Jgs=({canExecute:e=!0,isEmpty:t,isRunning:n,canSendWhileStreaming:r,onCancel:s})=>{const{isAddingAttachments:i}=uz();return n&&!r?a.jsx(de,{variant:"default",size:"icon-md",type:"button",tooltip:"Cancel",onClick:s,children:a.jsx(pye,{})}):a.jsxs(a.Fragment,{children:[a.jsx(de,{type:"submit",variant:"default",size:"icon-md",tooltip:e?"Send":"No permission to execute",disabled:!e||t||i,children:a.jsx(ck,{})}),n&&a.jsx(de,{variant:"default",size:"icon-md",type:"button",tooltip:"Cancel",onClick:s,children:a.jsx(pye,{})})]})},pye=()=>a.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:Fn,children:[a.jsx("circle",{cx:"12",cy:"12",r:"10"}),a.jsx("rect",{width:"6",height:"6",x:"9",y:"9",rx:"1"})]}),jNe=({agentId:e,agentName:t,threadId:n,memory:r,refreshThreadList:s,modelVersion:i,agentVersionId:o,supportsMemory:l,modelList:c,messageId:u,suggestedPrompts:d,isNewThread:f,hideModelSwitcher:h,runOptionsSlot:p})=>{const{settings:m}=L_e(),v=xr("agent",e)[0],{data:y,isLoading:x,fetchNextPage:b,hasNextPage:S,isFetchingNextPage:k}=sK({agentId:e,threadId:f?void 0:n,memory:r??!1,requestContext:v});g.useEffect(()=>{u&&y&&!x&&setTimeout(()=>{const _=document.querySelector(`[data-message-id="${u}"]`);_&&(_.scrollIntoView({behavior:"smooth",block:"center"}),_.classList.add("bg-muted"),setTimeout(()=>{_.classList.remove("bg-muted")},2e3))},100)},[u,y,x]);const j=g.useRef({threadId:n,messages:[]});j.current.threadId!==n&&(j.current={threadId:n,messages:[]});const C=y?.messages??j.current.messages,T=()=>{k||b()};return a.jsx(BKr,{agentId:e,agentName:t,modelVersion:i,agentVersionId:o,supportsMemory:l,threadId:n,initialMessages:C,refreshThreadList:s,settings:m,requestContext:v,children:a.jsx(Hgs,{agentName:t??"",agentId:e,threadId:n,suggestedPrompts:d,hasModelList:!!c,hideModelSwitcher:h,refreshThreadList:s,runOptionsSlot:p,isHistoryLoading:x,onLoadPrevious:S?T:void 0,isLoadingPrevious:k})})};function cW(){return a.jsx(Xt,{tone:"error",titleSlot:"Agent not found",descriptionSlot:"This agent may have been renamed or removed. Reload to check again, or choose another agent.",actionSlot:a.jsxs("div",{className:"flex flex-wrap justify-center gap-2",children:[a.jsx(de,{onClick:()=>window.location.reload(),children:"Reload"}),a.jsx(de,{render:a.jsx(lc,{to:"/agents"}),children:"Choose agent"})]})})}function net(){const{agentId:e,threadId:t}=jr(),[n]=oi(),{data:r,isLoading:s,error:i}=yd({agentId:e,requestContext:xr("agent",e)[0],queryOptions:{enabled:!!e}}),{data:o}=$k({agentId:e,requestContext:xr("agent",e)[0],queryOptions:{enabled:!!e}}),l=Dr(),c=t==="new",u=g.useMemo(()=>Sa(),[t]),d=!!o?.result,{refetch:f}=R_e({resourceId:e,agentId:e,isMemoryEnabled:d,requestContext:xr("agent",e)[0],queryOptions:{enabled:!!d}});g.useEffect(()=>{d&&(t||l(`/agents/${e}/session/new`))},[d,t,e,l]);const h=n.get("messageId")??void 0,p=g.useMemo(()=>cNe(r),[r]);if(i&&js(i))return a.jsx(ai,{variant:"fill"});if(i&&Cs(i))return a.jsx(Gs,{variant:"fill",resource:"agents"});if(s)return a.jsx(evs,{});if(i&&kk(i))return a.jsx(cW,{});if(i)return a.jsx(Xt,{tone:"error",titleSlot:"Failed to load agent",descriptionSlot:i.message});if(!r)return a.jsx(cW,{});const m=c?u:t??u,v=async()=>{await f(),c&&l(`/agents/${e}/session/${u}`)};return a.jsx(W2t,{agentId:e,defaultSettings:p,children:a.jsx(iDt,{agentId:e,threadId:m,resourceId:e,children:a.jsx(sX,{children:a.jsx(iX,{agentId:e,threadId:m,enabled:!!(r?.hasBrowser??r?.browserTools?.length),children:a.jsx(qIe,{children:a.jsx(lDt,{children:a.jsx(lX,{children:a.jsxs(Et,{variant:"fit",children:[a.jsx("h1",{className:"sr-only",children:e}),a.jsx(Z2t,{}),a.jsx("div",{className:"relative grid h-full min-h-0",children:a.jsx(jNe,{agentId:e,agentName:r?.name,modelVersion:r?.modelVersion,supportsMemory:r?.supportsMemory,threadId:m,memory:d,refreshThreadList:v,modelList:r?.modelList,messageId:h,isNewThread:c,hideModelSwitcher:!0,runOptionsSlot:a.jsx(uNe,{agentId:e})},m)})]})})})})},`session-${e}-${m}`)},`browser-${e}-${m}`)})})}const evs=()=>a.jsxs(Et,{variant:"fit",children:[a.jsx("h1",{className:"sr-only",children:"Agent session"}),a.jsx(Z2t,{}),a.jsx("div",{className:"relative grid h-full overflow-y-auto pt-4","data-testid":"agent-session-skeleton","aria-busy":"true",children:a.jsx(tBt,{})})]}),tvs={purple:{icon:"text-badge-purple-indicator"},amber:{icon:"text-badge-amber-indicator"},emerald:{icon:"text-badge-green-indicator"},sky:{icon:"text-badge-blue-indicator"},cyan:{icon:"text-badge-cyan-indicator"},orange:{icon:"text-badge-orange-indicator"}},GI=e=>e?Object.keys(e).length:0,IJ=e=>e>0?String(e):"Off",rBt=e=>(e?.inputProcessors?.length??0)+(e?.outputProcessors?.length??0),sBt=e=>!!e?.result,iBt=(e,t)=>!!(t&&e&&e.editor!==!1);function v$({view:e,label:t,status:n,description:r,docsHref:s,enabled:i,tone:o,icon:l}){const c=tvs[o].icon;return e==="chip"?a.jsx("span",{"aria-label":`${t}: ${n}`,className:Z("pointer-events-none inline-flex h-5 min-w-5 items-center justify-center rounded-full px-1 text-muted-foreground",i?c:void 0),children:a.jsx("span",{className:"size-3 shrink-0 [&>svg]:size-3",children:l})}):a.jsxs("a",{"aria-label":`${t}: ${n}`,href:s,target:"_blank",rel:"noopener noreferrer",className:Z("group/capability-row flex min-w-0 items-start gap-2 rounded-md px-2 py-1.5","hover:bg-fill-subtle",Ri,Fn,jn),children:[a.jsx("span",{className:Z("mt-0.5 size-3.5 shrink-0 text-muted-foreground [&>svg]:size-3.5",jn,i?c:"group-hover/capability-row:text-foreground"),children:l}),a.jsxs("span",{className:"min-w-0 flex-1",children:[a.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[a.jsx(Y,{as:"span",variant:"meta",tone:"ink",className:"min-w-0 truncate",children:t}),a.jsx(Y,{as:"span",variant:"meta",tone:"muted",className:"shrink-0 tabular-nums",children:n})]}),a.jsx(Y,{as:"span",variant:"meta",tone:"muted",className:"mt-0.5 block",children:r})]}),a.jsx(Zs,{className:Z("mt-0.5 size-3 shrink-0 text-muted-foreground group-hover/capability-row:text-foreground",jn)})]})}function ret({agentId:e,view:t}){const{data:n,isLoading:r}=$k({agentId:e,requestContext:xr("agent",e)[0],queryOptions:{enabled:!!e}}),s=sBt(n),i=s?n?.memoryType==="gateway"?"Gateway":"On":"Off",o=r?"Checking":i;return a.jsx(v$,{view:t,label:"Memory",status:o,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:a.jsx(o$,{})})}function set({agentId:e,view:t}){const{data:n,isLoading:r}=yd({agentId:e,requestContext:xr("agent",e)[0],queryOptions:{enabled:!!e}}),{isCmsAvailable:s,isLoading:i}=zx(),o=iBt(n,s),l=n?.editor===!1,c=zL({agentId:e,params:{orderBy:{field:"createdAt",direction:"DESC"}},queryOptions:{enabled:!!e&&o}}),u=c.data?.total??c.data?.versions.length??0,d=r||i||o&&c.isLoading,f=u>0?String(u):"Ready",p=d?"Checking":o?f:l?"Locked":"Off",v=o?"Editor is available for versioned agent overrides.":l?"This code-defined agent explicitly disables editor overrides.":"Register MastraEditor to enable versioned agent overrides.";return a.jsx(v$,{view:t,label:"Editor",status:p,description:v,docsHref:"https://mastra.ai/docs/editor/overview",enabled:o,tone:"amber",icon:a.jsx(Fc,{})})}function iet({agentId:e,view:t}){const{data:n,isLoading:r}=yd({agentId:e,requestContext:xr("agent",e)[0],queryOptions:{enabled:!!e}}),s=GI(n?.tools);return a.jsx(v$,{view:t,label:"Tools",status:r?"Checking":IJ(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:a.jsx(cd,{})})}function oet({agentId:e,view:t}){const{data:n,isLoading:r}=yd({agentId:e,requestContext:xr("agent",e)[0],queryOptions:{enabled:!!e}}),s=GI(n?.workflows);return a.jsx(v$,{view:t,label:"Workflows",status:r?"Checking":IJ(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:a.jsx(dk,{})})}function aet({agentId:e,view:t}){const{data:n,isLoading:r}=yd({agentId:e,requestContext:xr("agent",e)[0],queryOptions:{enabled:!!e}}),s=GI(n?.agents);return a.jsx(v$,{view:t,label:"Sub-agents",status:r?"Checking":IJ(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:a.jsx(M0e,{})})}function cet({agentId:e,view:t}){const{data:n,isLoading:r}=yd({agentId:e,requestContext:xr("agent",e)[0],queryOptions:{enabled:!!e}}),s=rBt(n);return a.jsx(v$,{view:t,label:"Processors",status:r?"Checking":IJ(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:a.jsx(wht,{})})}function nvs({agentId:e}){const{data:t}=$k({agentId:e,requestContext:xr("agent",e)[0],queryOptions:{enabled:!!e}}),{data:n}=yd({agentId:e,requestContext:xr("agent",e)[0],queryOptions:{enabled:!!e}}),{isCmsAvailable:r}=zx(),s=[sBt(t),iBt(n,r),GI(n?.tools)>0,GI(n?.workflows)>0,GI(n?.agents)>0,rBt(n)>0],i=s.filter(Boolean).length;return a.jsxs(Y,{as:"span",variant:"meta",tone:"muted",className:"shrink-0",children:[i,"/",s.length]})}function rvs({agentId:e}){const[t,n]=g.useState(!1);return a.jsx(Kl,{open:t,onOpenChange:n,children:a.jsxs("div",{className:"shrink-0 border-t border-border",children:[a.jsx(Cl,{asChild:!0,"aria-label":t?"Hide capability details":"Show capability details",children:a.jsxs("button",{type:"button","data-testid":"agent-capabilities-footer",className:Z("flex w-full cursor-pointer items-center gap-1.5 px-2 py-2 text-left hover:bg-fill-subtle focus-visible:bg-fill-subtle active:bg-fill aria-expanded:bg-fill-hover data-[panel-open]:bg-fill-hover",jx,Fn,jn),children:[a.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-1.5 overflow-hidden",children:[a.jsx(ret,{agentId:e,view:"chip"}),a.jsx(set,{agentId:e,view:"chip"}),a.jsx(iet,{agentId:e,view:"chip"}),a.jsx(oet,{agentId:e,view:"chip"}),a.jsx(aet,{agentId:e,view:"chip"}),a.jsx(cet,{agentId:e,view:"chip"})]}),a.jsx(nvs,{agentId:e}),a.jsx(Na,{direction:"right",className:"size-3.5 text-muted-foreground"})]})}),a.jsx(_l,{className:"px-2 pb-2",children:a.jsxs("div",{className:"grid gap-1",children:[a.jsx(ret,{agentId:e,view:"row"}),a.jsx(set,{agentId:e,view:"row"}),a.jsx(iet,{agentId:e,view:"row"}),a.jsx(oet,{agentId:e,view:"row"}),a.jsx(aet,{agentId:e,view:"row"}),a.jsx(cet,{agentId:e,view:"row"})]})})]})})}function svs(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 ivs(e){return typeof e=="object"&&e!==null&&"parts"in e&&Array.isArray(e.parts)}function ovs(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 avs(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 lvs(e){const t=[];for(const n of e){const r=svs(n.content);if(ivs(r))for(const s of r.parts)ovs(s)&&t.push(avs(s,new Date(n.createdAt).toISOString()))}return t.sort((n,r)=>n.timestamp.localeCompare(r.timestamp)),t}function LA(e){return/[Zz+-]\d{0,4}$/.test(e.trim())?new Date(e).getTime():new Date(e.trim().replace(" ","T")+"Z").getTime()}function cvs(e){if(e.length===0)return{tMin:0,tMax:1};let t=1/0,n=-1/0;for(const r of e){const s=LA(r);s<t&&(t=s),s>n&&(n=s)}return t===n?{tMin:t,tMax:t+1}:{tMin:t,tMax:n}}function yz(e,t){return(LA(e)-t.tMin)/(t.tMax-t.tMin)}function CNe(e,t){return new Date(t.tMin+e*(t.tMax-t.tMin))}function uvs(e,t){return CNe(e,t).getTime()}function oBt(e){const t=e.lastObservedAt??e.updatedAt;return typeof t=="string"?t:new Date(t).toISOString()}function dvs(e){return LA(oBt(e))}function fvs(e,t){if(t==null)return null;const r=e.map(s=>({id:s.id,t:LA(oBt(s))})).toSorted((s,i)=>s.t-i.t).findLast(s=>s.t<=t);return r?r.id:null}function uet(e){const t=e.lastObservedAt??e.updatedAt;return typeof t=="string"?t:new Date(t).toISOString()}function hvs(e){return[...e].sort((t,n)=>LA(uet(t))-LA(uet(n)))}function pvs({markers:e,omRecords:t,observationThreshold:n,reflectionThreshold:r}){const s=[...e].filter(o=>o.type==="status"&&(o.pendingTokens!=null||o.observationTokens!=null)).sort((o,l)=>o.timestamp.localeCompare(l.timestamp)).at(-1),i=hvs(t).at(-1);return{messageTokens:s?.pendingTokens??i?.pendingMessageTokens,messageThreshold:s?.observationThreshold??n,memoryTokens:s?.observationTokens??i?.observationTokenCount,memoryThreshold:s?.reflectionThreshold??r}}function ID(e){const t=e.lastObservedAt??e.updatedAt;return typeof t=="string"?t:new Date(t).toISOString()}function mvs(e,t,n){const r=e.map(i=>({ts:String(ID(i)),pendingMessageTokens:i.pendingMessageTokens})),s=t.flatMap(i=>i.pendingTokens==null?[]:{ts:i.timestamp,pendingMessageTokens:i.pendingTokens});return[...r,...s].sort((i,o)=>i.ts.localeCompare(o.ts)).map(i=>({t:yz(i.ts,n),pendingMessageTokens:i.pendingMessageTokens}))}function gvs(e,t,n){const r=[...e.map(i=>({ts:String(ID(i)),observationTokenCount:i.observationTokenCount})),...t.flatMap(i=>i.type!=="status"||i.observationTokens==null?[]:{ts:i.timestamp,observationTokenCount:i.observationTokens})].sort((i,o)=>i.ts.localeCompare(o.ts));let s=0;return r.map(i=>(s=Math.max(s,i.observationTokenCount),{t:yz(i.ts,n),observationTokenCount:s}))}function vvs(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,i)=>s.ts.localeCompare(i.ts));let r=0;return n.map(s=>(r=Math.max(0,r+s.bufferedObservationTokenCount),{t:yz(s.ts,t),bufferedObservationTokenCount:r}))}function yvs(e,t){return[...e].sort((n,r)=>String(ID(n)).localeCompare(String(ID(r)))).map(n=>({t:yz(String(ID(n)),t),event:1}))}function xvs(e,t){return[...e].sort((n,r)=>new Date(n.createdAt).getTime()-new Date(r.createdAt).getTime()).map(n=>({t:yz(new Date(n.createdAt).toISOString(),t),event:1,role:n.role}))}function bvs(e,t,n){const r=new Map;for(const c of e)c.t!==void 0&&r.set(c.t,Number(c[t]??0));const s=n.reduce((c,u)=>{const d=c.get(u.t);return d?d.push(u):c.set(u.t,[u]),c},new Map),i=Array.from(new Set([...r.keys(),...s.keys()])).sort((c,u)=>c-u);let o=0;const l=[];for(const c of i){const u=r.get(c);u!=null&&(o=u);const d=s.get(c);if(d)for(const f of d)l.push({...f,t:c,[t]:o});else l.push({t:c,[t]:o})}return l}function wvs(e,t,n){if(n==null)return;const r=Math.max(0,...e.map(s=>Number(s[t])||0));return Math.max(r,n)}function Svs(e){return e==null?null:Number(e)}function kvs(e){return!!e?.event}const Ovs="var(--chart-green)",jvs="var(--chart-amber)",det="var(--chart-pink)";function Cvs({domain:e}){const t=[0,.25,.5,.75,1];return a.jsxs("div",{className:"grid grid-cols-[6rem_1fr] items-center",children:[a.jsx(Y,{variant:"meta",tone:"muted",className:"flex items-center self-stretch border-r border-border pl-3",children:"Time"}),a.jsx("div",{className:"flex justify-between px-1 py-1.5",children:t.map(n=>a.jsx(Y,{tone:"muted",as:"span",variant:"meta",font:"mono",children:os(CNe(n,e),"date-time-seconds",{timeZone:"UTC"})},n))})]})}function _Ne({active:e,payload:t,domain:n,showValue:r}){if(!e||!t?.length)return null;const s=t[0]?.payload?.t,i=n!=null&&s!=null?os(CNe(s,n),"date-time-seconds",{timeZone:"UTC"}):null,o=t.filter(l=>l.name!=="t"&&l.name!=="time"&&l.value!=null);return r?a.jsxs("div",{className:`${rh} flex flex-col gap-0.5 rounded px-2 py-1.5 tabular-nums`,children:[i&&a.jsxs("div",{className:"flex items-center justify-between gap-3",children:[a.jsx(Y,{as:"span",variant:"meta",tone:"muted",children:"time"}),a.jsx(Y,{as:"span",variant:"meta",font:"mono",tone:"ink",children:i})]}),o.map(l=>a.jsxs("div",{className:"flex items-center justify-between gap-3",children:[a.jsx(Y,{as:"span",variant:"meta",tone:"muted",children:l.name}),a.jsx(Y,{as:"span",variant:"meta",tone:"ink",children:typeof l.value=="number"?Math.round(l.value).toLocaleString():String(l.value)})]},l.name))]}):a.jsx(Y,{as:"p",variant:"meta",className:`${rh} rounded px-2 py-1`,children:i&&a.jsx(Y,{as:"span",variant:"meta",font:"mono",tone:"ink",children:i})})}function _vs({label:e,data:t,dataKey:n,color:r,gradientId:s,domain:i,zoomDomain:o,threshold:l}){const c=wvs(t,n,l);return a.jsxs("div",{className:"relative grid grid-cols-[6rem_1fr] items-center border-b border-border hover:z-10",children:[a.jsx(Y,{variant:"meta",tone:"muted",className:"flex items-center self-stretch border-r border-border pl-3",children:e}),a.jsx("div",{children:a.jsx(oA,{width:"100%",height:32,children:a.jsxs(o$r,{data:t,margin:{top:0,right:0,bottom:0,left:0},children:[a.jsx("defs",{children:a.jsxs("linearGradient",{id:s,x1:"0",y1:"0",x2:"0",y2:"1",children:[a.jsx("stop",{offset:"0%",stopColor:r,stopOpacity:.35}),a.jsx("stop",{offset:"100%",stopColor:r,stopOpacity:.03})]})}),a.jsx(h6,{dataKey:"t",type:"number",domain:o,allowDataOverflow:!0,hide:!0}),a.jsx(p6,{type:"number",domain:c!=null?[0,c]:void 0,hide:!0}),a.jsx(l6,{content:a.jsx(_Ne,{domain:i,showValue:!0}),cursor:{stroke:"var(--border)"}}),a.jsx(yY,{type:"linear",dataKey:n,stroke:r,strokeWidth:1,fill:`url(#${s})`,isAnimationActive:!1}),l!=null&&a.jsx(gY,{y:l,stroke:"var(--border-strong)",strokeDasharray:"4 3"})]})})})]})}function Tvs({label:e,data:t,color:n,height:r=32,domain:s,zoomDomain:i}){return a.jsxs("div",{className:"relative grid grid-cols-[6rem_1fr] items-center border-b border-border hover:z-10",children:[a.jsx(Y,{variant:"meta",tone:"muted",className:"flex items-center self-stretch border-r border-border pl-3",children:e}),a.jsx("div",{children:a.jsx(oA,{width:"100%",height:r,children:a.jsxs(s$r,{margin:{top:0,right:0,bottom:0,left:0},children:[a.jsx(h6,{dataKey:"t",type:"number",domain:i,allowDataOverflow:!0,hide:!0}),a.jsx(p6,{dataKey:"event",type:"number",domain:[0,2],hide:!0}),a.jsx(l6,{content:a.jsx(_Ne,{domain:s}),cursor:!1}),a.jsx(vIt,{data:t,fill:n,isAnimationActive:!1,shape:o=>{const l=o.cx;return a.jsxs("g",{children:[a.jsx("rect",{x:l-6,y:0,width:12,height:r,fill:"transparent"}),a.jsx("rect",{x:l-1.5,y:0,width:3,height:r,fill:n})]})}})]})})})]})}function fet({label:e,areaData:t,areaDataKey:n,eventData:r,color:s,gradientId:i,domain:o,zoomDomain:l,threshold:c,height:u=44,onSelectT:d}){const f=bvs(t,n,r);return a.jsxs("div",{className:"relative grid grid-cols-[6rem_1fr] items-center border-b border-border hover:z-10",children:[a.jsx(Y,{variant:"meta",tone:"muted",className:"flex items-center self-stretch border-r border-border pl-3",children:e}),a.jsx("div",{children:a.jsx(oA,{width:"100%",height:u,children:a.jsxs(Hje,{margin:{top:0,right:0,bottom:0,left:0},onClick:h=>{const p=Svs(h?.activeLabel);p!=null&&d&&d(p)},className:d?"cursor-pointer":void 0,children:[a.jsx("defs",{children:a.jsxs("linearGradient",{id:i,x1:"0",y1:"0",x2:"0",y2:"1",children:[a.jsx("stop",{offset:"0%",stopColor:s,stopOpacity:.35}),a.jsx("stop",{offset:"100%",stopColor:s,stopOpacity:.06})]})}),a.jsx(h6,{dataKey:"t",type:"number",domain:l,allowDataOverflow:!0,hide:!0}),a.jsx(p6,{yAxisId:"area",dataKey:n,type:"number",hide:!0,domain:[0,"dataMax"]}),a.jsx(l6,{content:a.jsx(_Ne,{domain:o,showValue:!0}),cursor:!1}),a.jsx(yY,{yAxisId:"area",data:f,type:"linear",dataKey:n,stroke:s,strokeWidth:1,fill:`url(#${i})`,isAnimationActive:!1,activeDot:{r:5,stroke:s,strokeWidth:2,fill:"var(--background)"},dot:h=>kvs(h.payload)?a.jsx("circle",{cx:h.cx,cy:h.cy,r:4,fill:s}):a.jsx(a.Fragment,{})}),c!=null&&a.jsx(gY,{yAxisId:"area",y:c,stroke:"var(--border-strong)",strokeDasharray:"4 3"})]})})})]})}function Evs({tDomain:e,zoomLeft:t,zoomRight:n,onZoomLeftChange:r,onZoomRightChange:s,onReset:i}){const o=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(h=>{const p=o.current;if(!p)return null;const m=p.getBoundingClientRect(),v=Math.max(0,Math.min(1,(h-m.left)/m.width));return e.tMin+v*(e.tMax-e.tMin)},[e.tMin,e.tMax]);return g.useEffect(()=>{const h=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)))},p=()=>{l.current=null};return window.addEventListener("mousemove",h),window.addEventListener("mouseup",p),()=>{window.removeEventListener("mousemove",h),window.removeEventListener("mouseup",p)}},[f,t,n,r,s]),a.jsxs("div",{className:"grid grid-cols-[6rem_1fr] items-center border-b border-border",children:[a.jsxs("div",{className:"flex items-center gap-1 self-stretch border-r border-border pl-3",children:[a.jsx(Y,{variant:"meta",tone:"muted",children:"Zoom"}),a.jsx(de,{variant:"ghost",size:"icon-sm","aria-label":"Reset zoom",onClick:i,children:a.jsx(b_,{className:"size-3"})})]}),a.jsxs("div",{ref:o,"data-zoom-track":"",className:"relative h-6 cursor-pointer select-none",onMouseDown:h=>{const p=f(h.clientX);if(p==null)return;h.preventDefault();const m=Math.abs(p-t),v=Math.abs(p-n);m<=v?(r(Math.min(p,n)),l.current="left"):(s(Math.max(p,t)),l.current="right")},children:[a.jsx("div",{"data-zoom-part":"before",className:"absolute inset-y-0 left-0 bg-background/60",style:{width:`${u}%`}}),a.jsx("div",{"data-zoom-part":"band",className:"absolute inset-y-0 border-y border-surface-rim bg-fill-subtle",style:{left:`${u}%`,right:`${100-d}%`}}),a.jsx("div",{"data-zoom-part":"after",className:"absolute inset-y-0 right-0 bg-background/60",style:{width:`${100-d}%`}}),a.jsx("div",{"data-zoom-handle":"left",className:"absolute inset-y-0 w-1 cursor-col-resize bg-foreground/50 hover:bg-foreground",style:{left:`${u}%`,transform:"translateX(-50%)"},onMouseDown:h=>{h.preventDefault(),h.stopPropagation(),l.current="left"}}),a.jsx("div",{"data-zoom-handle":"right",className:"absolute inset-y-0 w-1 cursor-col-resize bg-foreground/50 hover:bg-foreground",style:{left:`${d}%`,transform:"translateX(-50%)"},onMouseDown:h=>{h.preventDefault(),h.stopPropagation(),l.current="right"}})]})]})}const Ivs={tMin:0,tMax:1};function Nvs({omRecords:e,markers:t,messages:n,tDomain:r,observationThreshold:s,reflectionThreshold:i,onSelectTimestamp:o,zoomRange:l,onZoomRangeChange:c}){const u=r??Ivs,d=g.useCallback(Q=>{o?.(uvs(Q,u))},[o,u]),f=l!=null&&c!=null,[h,p]=g.useState(u.tMin),[m,v]=g.useState(u.tMax);g.useEffect(()=>{f||(p(u.tMin),v(u.tMax))},[u.tMin,u.tMax,f]);const y=f?l.left:h,x=f?l.right:m,b=g.useCallback(Q=>{f?c({left:Q,right:x}):p(Q)},[f,c,x]),S=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}):(p(u.tMin),v(u.tMax))},[f,c,u.tMin,u.tMax]),j=u.tMax-u.tMin,C=j>0?(y-u.tMin)/j:0,T=j>0?(x-u.tMin)/j:1,_=[C,T],N=g.useMemo(()=>xvs(n,u),[n,u]),I=g.useMemo(()=>mvs(e,t,u),[e,t,u]),A=g.useMemo(()=>gvs(e,t,u),[e,t,u]),P=g.useMemo(()=>vvs(t,u),[t,u]),D=g.useMemo(()=>yvs(e,u),[e,u]);return N.length>0||I.length>0||A.length>0||D.length>0?a.jsxs("div",{className:"flex flex-col pr-2 pb-2 [&_.recharts-surface]:outline-none",children:[a.jsx(fet,{label:"Messages",areaData:I,areaDataKey:"pendingMessageTokens",eventData:N,color:Ovs,gradientId:"grad-messages",domain:u,zoomDomain:_,threshold:s,onSelectT:o?d:void 0}),a.jsx(fet,{label:"Observations",areaData:A,areaDataKey:"observationTokenCount",eventData:D,color:jvs,gradientId:"grad-observations",domain:u,zoomDomain:_,threshold:i,onSelectT:o?d:void 0}),P.length>0&&a.jsx(_vs,{label:"Buffered obs",data:P,dataKey:"bufferedObservationTokenCount",color:det,gradientId:"grad-buffered-obs",domain:u,zoomDomain:_,threshold:i}),D.length>0&&a.jsx(Tvs,{label:"Events",data:D,color:det,domain:u,zoomDomain:_}),a.jsx(Cvs,{domain:u}),a.jsx(Evs,{tDomain:u,zoomLeft:y,zoomRight:x,onZoomLeftChange:b,onZoomRightChange:S,onReset:k})]}):null}const Avs=g.lazy(()=>Ii(async()=>{const{CodeDiff:e}=await import("./CodeDiff.es-BNwUVtno.js");return{CodeDiff:e}},__vite__mapDeps([9,4,1,3]),import.meta.url).then(({CodeDiff:e})=>({default:e})));function Pvs(e){if(!e)return null;const t=e.match(/^(\d{1,2}):(\d{2})$/);if(!t)return e;const[,n,r]=t;return os(new Date(2e3,0,1,Number(n),Number(r)),"time")??e}function $vs(e,t){if(t)return{card:"bg-transparent border-transparent",text:"text-muted-foreground",time:"text-muted-foreground"};if(!e)return{card:"border-border bg-background",text:"text-foreground",time:"text-muted-foreground"};const n=Ave[e];return{card:n.card,text:"text-foreground",time:n.time}}function Rvs(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[o,l]of Object.entries(Nve))if(n.startsWith(o)){r=l,n=n.slice(o.length).trimStart();break}let s=null;const i=n.match(/^\((\d{1,2}:\d{2})\)/);if(i){const[o,l]=i;o!==void 0&&l!==void 0&&(s=l,n=n.slice(o.length).trimStart())}if(n)return{text:n,time:s,priority:r,children:[]}}return{text:t,time:null,priority:null,children:[]}}function Mvs(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 i=s.split(`
|
|
676
676
|
`),o=[];let l=null,c=null;for(const u of i){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("("),x=y===-1?"":m.slice(y+1,-1);y>0&&x&&!x.includes(")")&&(v=x.trim(),m=m.slice(0,y).trim())}if(m){l={title:m,relativeTime:v,items:[]},o.push(l),c=null;continue}}l||(l={title:"Recent",relativeTime:null,items:[]},o.push(l));const h=(u.match(/^(\s*)/)?.[1]?.length??0)>=2&&(d.startsWith("* ->")||d.startsWith("->")||d.startsWith("-")),p=Rvs(u);if(p){if(h&&c){c.children.push(p);continue}l.items.push(p),c=p}}return o}function aBt({items:e,nested:t=!1}){return a.jsx("div",{className:t?"space-y-2 border-l border-border pl-4":"space-y-3",children:e.map((n,r)=>{const s=$vs(n.priority,t);return a.jsx("div",{className:"space-y-2",children:a.jsxs("div",{className:"flex items-start gap-3",children:[a.jsx("div",{className:"w-12 shrink-0 pt-2 text-right",children:n.time&&a.jsx(Y,{as:"span",variant:"meta",font:"mono",className:s.time,children:Pvs(n.time)})}),a.jsxs("div",{className:Z("min-w-0 flex-1 rounded-md border px-3 py-2",s.card),children:[a.jsx(Y,{className:Z("break-words whitespace-pre-wrap",s.text),children:n.text}),n.children.length>0&&a.jsx("div",{className:"mt-3",children:a.jsx(aBt,{items:n.children,nested:!0})})]})]})},`${n.text.slice(0,20)}-${r}`)})})}function Dvs({observations:e}){const t=g.useMemo(()=>Mvs(e),[e]);return t.length===0?a.jsx(Y,{variant:"caption",tone:"muted",className:"italic",children:"Initialized"}):a.jsx("div",{className:"space-y-5",children:t.map((n,r)=>a.jsxs("section",{className:"space-y-3",children:[a.jsx("div",{className:"flex items-baseline justify-between gap-3 border-b border-border pb-2",children:a.jsxs("div",{className:"min-w-0",children:[a.jsx(Y,{as:"h3",variant:"column",tone:"ink",children:n.title}),n.relativeTime&&a.jsx(Y,{variant:"meta",tone:"muted",children:n.relativeTime})]})}),a.jsx(aBt,{items:n.items})]},`${n.title}-${r}`))})}function Lvs({records:e,selectedRecordId:t,onSelectRecord:n}){return e.length<=1?null:a.jsxs("div",{className:"flex w-50 min-w-45 flex-col overflow-hidden border-l border-border",children:[a.jsx("div",{className:"border-b border-border px-4 py-2",children:a.jsx(Y,{tone:"ink",children:"History"})}),a.jsx("div",{className:"flex-1 overflow-y-auto",children:e.map(r=>{const s=r.id===t;return a.jsx("button",{type:"button",onClick:()=>n(r.id),className:Z("text-foreground","w-full cursor-pointer truncate border-l-2 border-l-transparent px-3 py-2 text-left hover:bg-fill-subtle",s&&"border-l-foreground bg-fill-hover"),children:a.jsx(Y,{as:"span",variant:"caption",className:"block",children:r.activeObservations||a.jsx("span",{className:"text-muted-foreground italic",children:r.isObserving||r.isReflecting?"Processing…":"Initialized"})})},r.id)})})]})}function zvs({records:e,selectedRecordId:t,onSelectRecord:n,isLoading:r}){const[s,i]=g.useState(!1),o=g.useMemo(()=>[...e].sort((f,h)=>new Date(f.createdAt).getTime()-new Date(h.createdAt).getTime()),[e]),l=t?o.find(f=>f.id===t):o[o.length-1],c=l?o.findIndex(f=>f.id===l.id):-1,u=c>0?o[c-1]:null;if(g.useEffect(()=>{const f=o.at(-1);!t&&f&&n(f.id)},[t,o,n]),r)return a.jsxs("div",{className:"space-y-4 p-4",children:[a.jsx(xt,{className:"h-6 w-40"}),a.jsx(xt,{className:"h-32 w-full"}),a.jsx(xt,{className:"h-32 w-full"})]});if(!l)return a.jsx(Xt,{titleSlot:"No observations",descriptionSlot:"No observational memory snapshots available for this thread.",variant:"fill"});const d=typeof l.activeObservations=="string"?l.activeObservations:"";return a.jsxs("div",{className:"flex size-full overflow-hidden",children:[a.jsxs("div",{className:"flex min-w-0 flex-1 flex-col overflow-hidden",children:[u&&a.jsx("div",{className:"border-b border-border px-4 py-2",children:a.jsx("div",{className:"flex items-start justify-end gap-3",children:a.jsxs(ft,{orientation:"horizontal",className:"gap-1.5",children:[a.jsx(Wc,{checked:s,onCheckedChange:f=>i(f===!0)}),a.jsx(ut,{size:"smaller",children:"Show diff"})]})})}),a.jsx("div",{"data-testid":"observation-detail-body",className:"flex-1 overflow-y-auto p-4",children:s&&u?a.jsx(g.Suspense,{fallback:a.jsx(xt,{className:"h-32"}),children:a.jsx(Avs,{codeA:typeof u.activeObservations=="string"?u.activeObservations:"",codeB:d,filename:"observations.md",layout:"unified",className:"rounded-xl"})}):d?a.jsx(Dvs,{observations:d}):a.jsx(Y,{variant:"caption",tone:"muted",className:"italic",children:l.isObserving||l.isReflecting?"Processing…":"Initialized"})})]}),a.jsx(Lvs,{records:o,selectedRecordId:l.id,onSelectRecord:n})]})}function het(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")}const Fvs={messages:"text-chart-blue",memory:"text-chart-purple",warning:"text-warning-foreground"};function pet({label:e,value:t,max:n,tone:r}){const s=Math.max(0,Math.min(100,t/n*100));return a.jsxs("div",{className:Z("min-w-0 flex-1",Fvs[r]),children:[a.jsxs("div",{className:"mb-1 flex items-center justify-between gap-2",children:[a.jsx(Y,{as:"span",variant:"meta",tone:"ink",className:"uppercase",children:e}),a.jsxs(Y,{as:"span",variant:"meta",tone:"muted",className:"tabular-nums",children:[het(t),"/",het(n),"k"]})]}),a.jsx("div",{className:"h-1.5 overflow-hidden rounded-full bg-white/[0.08]",children:a.jsx("div",{className:"h-full rounded-full bg-current/80",style:{width:`${s}%`}})})]})}function Bvs({messageTokens:e,messageThreshold:t,memoryTokens:n,memoryThreshold:r,memoryLabel:s="Memory"}){const i=e!=null&&t!=null&&t>0,o=n!=null&&r!=null&&r>0;return!i&&!o?null:a.jsx("div",{className:"border-b border-border px-3 py-2",children:a.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row",children:[i?a.jsx(pet,{label:"Messages",value:e,max:t,tone:"messages"}):null,o?a.jsx(pet,{label:s,value:n,max:r,tone:"memory"}):null]})})}function Vvs({messages:e,omRecords:t,isLoading:n=!1,onClose:r,selectedTimestamp:s,onSelectTimestamp:i,contextWindow:o}){const[l,c]=g.useState(null),u=g.useMemo(()=>lvs(e),[e]),d=g.useMemo(()=>cvs(e.map(j=>new Date(j.createdAt).toISOString())),[e]),f=g.useMemo(()=>pvs({markers:u,omRecords:t}),[u,t]),h=o?.memoryTokens??f.memoryTokens,p=o?.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,x=g.useMemo(()=>y?t:t.filter(j=>{const C=dvs(j);return C>=m.left&&C<=m.right}),[t,y,m.left,m.right]),b=g.useMemo(()=>s!=null?fvs(x,s):null,[x,s]),S=l!=null&&x.some(j=>j.id===l)?l:null,k=b??S;return a.jsxs("div",{className:"flex size-full flex-col overflow-hidden",children:[a.jsxs("div",{className:"flex shrink-0 items-center gap-2 border-b border-border px-3 py-2.5",children:[a.jsx(de,{type:"button",variant:"ghost",size:"icon-sm",tooltip:"Back to memory",onClick:()=>r?.(),children:a.jsx(md,{})}),a.jsxs("span",{className:"flex min-w-0 items-center gap-1.5 text-foreground",children:[a.jsx(o$,{className:"size-4 shrink-0"}),a.jsx(Y,{as:"span",variant:"column",children:"Observational memory"})]})]}),n?a.jsxs("div",{"data-testid":"memory-studio-loading",className:"flex flex-1 flex-col gap-3 p-4",children:[a.jsx(xt,{className:"h-6 w-40"}),a.jsx(xt,{className:"h-32 w-full"}),a.jsx(xt,{className:"h-16 w-full"})]}):a.jsxs("div",{className:"grid min-h-0 flex-1 grid-rows-[1fr_auto] overflow-hidden",children:[a.jsx("div",{className:"flex min-h-0 flex-col overflow-hidden",children:a.jsx(zvs,{records:x,selectedRecordId:k,onSelectRecord:c,isLoading:n})}),a.jsxs("div",{className:"border-t border-border",children:[a.jsx(Bvs,{messageTokens:o?.messageTokens??f.messageTokens,messageThreshold:o?.messageThreshold??f.messageThreshold,memoryTokens:h,memoryThreshold:p,memoryLabel:"Observations"}),a.jsx(Nvs,{omRecords:t,markers:u,messages:e,tDomain:d,onSelectTimestamp:i,zoomRange:m,onZoomRangeChange:v})]})]})]})}const Uvs=2e3;function qvs({agentId:e,threadId:t}){const{isPanelOpen:n,closePanel:r,selectedTimestamp:s,setSelectedTimestamp:i}=dX(),{isObservingFromStream:o,isReflectingFromStream:l,observationsUpdatedAt:c,streamProgress:u}=uX(),d=o||l,{data:f}=$_e({threadId:t,agentId:e,requestContext:xr("agent",e)[0],queryOptions:{enabled:!!t&&t!=="new"&&!!e}}),h=f?.resourceId??e,{data:p}=Rk({agentId:e,requestContext:xr("agent",e)[0],queryOptions:{enabled:!!e}}),{data:m,isLoading:v,refetch:y}=U2t({agentId:n?e:void 0,threadId:n?t:void 0,resourceId:h}),{data:x,isLoading:b,refetch:S}=cKr({threadId:n?t:void 0});if(g.useEffect(()=>{!n||c===0||(y(),S())},[n,c,y,S]),g.useEffect(()=>{if(!n||!d)return;const T=setInterval(()=>{y(),S()},Uvs);return()=>clearInterval(T)},[n,d,y,S]),!n)return null;const k=p?.config?.observationalMemory,j=u?.threadId===t?u:null,C=UIe({record:m?.record,liveProgress:j,agentConfig:k});return a.jsx("div",{"data-testid":"memory-sidebar-om-detail-subpanel",className:"h-full min-h-0 min-w-0 overflow-hidden bg-card",children:a.jsx(Vvs,{messages:x?.messages??[],omRecords:m?.history??[],isLoading:v||b,onClose:r,selectedTimestamp:s,onSelectTimestamp:i,contextWindow:{messageTokens:C.messageTokens,messageThreshold:C.messageThreshold,memoryTokens:C.observationTokens,memoryThreshold:C.observationThreshold}})})}function Qvs(e){const{data:t}=Rk({agentId:e,requestContext:xr("agent",e)[0],queryOptions:{enabled:!!e}}),n=t?.config;return{recentMessages:h9t(n?.lastMessages,n?.messageHistory),semanticRecallOn:!!n?.semanticRecall,workingMemoryOn:!!n?.workingMemory?.enabled,observationalOn:!!n?.observationalMemory?.enabled}}const met="agent-memory-sidebar-tab-v2",Zvs=()=>{const[e,t]=g.useState(()=>{const r=sessionStorage.getItem(met)||"threads";return r==="threads"||r==="memory"?r:"threads"}),n=g.useCallback(r=>{t(r),sessionStorage.setItem(met,r)},[]);return{selectedTab:e,handleTabChange:n}},Wvs=e=>e>=85?"bg-warning-indicator":e>=60?"bg-info-indicator":"bg-success-indicator";function k7({icon:e,tooltip:t,enabled:n,value:r}){return a.jsxs(Ln,{children:[a.jsx(Rn,{asChild:!0,children:a.jsxs("span",{className:Z("inline-flex items-center gap-1 rounded-full border px-1.5 py-0.5 transition-colors duration-normal",n?"border-border bg-muted text-foreground":"border-border text-muted-foreground/50"),children:[a.jsx(e,{className:"h-3 w-3 shrink-0"}),r!==void 0&&a.jsx(Y,{as:"span",variant:"meta",className:"tabular-nums",children:r})]})}),a.jsx(Mn,{children:t})]})}function Hvs(){return a.jsxs("div",{"data-testid":"memory-sidebar-skeleton",className:"flex h-full min-h-0 w-full flex-col gap-2.5 p-3",children:[a.jsx(xt,{className:"h-3 w-28"}),a.jsx(xt,{className:"h-3 w-20"}),a.jsx(xt,{className:"h-3 w-24"}),a.jsx(xt,{className:"h-3 w-16"})]})}function Gvs({agentId:e,threadId:t,threads:n,onDelete:r,isThreadsLoading:s}){return a.jsx(lNe,{children:a.jsx(Kvs,{agentId:e,threadId:t,threads:n,onDelete:r,isThreadsLoading:s})})}function Kvs({agentId:e,threadId:t,threads:n,onDelete:r,threadsSlot:s,isThreadsLoading:i}){const{data:o,isLoading:l}=$k({agentId:e,requestContext:xr("agent",e)[0],queryOptions:{enabled:!!e}}),c=!!o?.result,u=o?.memoryType,{selectedTab:d,handleTabChange:f}=Zvs(),{isPanelOpen:h}=dX(),{streamProgress:p}=uX(),{recentMessages:m,semanticRecallOn:v,workingMemoryOn:y,observationalOn:x}=Qvs(e),b=d==="memory",S=g.useRef(null),k=g.useRef(null),[j,C]=g.useState({height:0,offset:0}),T=x&&h,_=p?.threadId===t?p:null,{data:N}=$_e({threadId:t,agentId:e,requestContext:xr("agent",e)[0],queryOptions:{enabled:!!t&&t!=="new"&&!!e}}),{data:I}=Rk({agentId:e,requestContext:xr("agent",e)[0],queryOptions:{enabled:!!e}}),{data:A}=U2t({agentId:x?e:void 0,threadId:x?t:void 0,resourceId:N?.resourceId??e}),P=I?.config?.observationalMemory,{messageTokens:D,messageThreshold:F}=UIe({record:A?.record,liveProgress:_,agentConfig:P}),q=(!!_||!!A?.record)&&F>0?Math.min(100,Math.round(D/F*100)):void 0;return g.useLayoutEffect(()=>{if(b||T||!c)return;const B=S.current,V=k.current;if(!B||!V)return;const H=()=>{const G=getComputedStyle(B),L=Number.parseFloat(G.borderTopWidth)||0,$=Number.parseFloat(G.borderBottomWidth)||0,z=Number.parseFloat(G.marginTop)||0,U=Number.parseFloat(G.marginBottom)||0,K=Math.ceil(V.getBoundingClientRect().height+L+$),ne=Math.ceil(K+z+U);C(X=>X.height===K&&X.offset===ne?X:{height:K,offset:ne})};if(H(),typeof ResizeObserver>"u")return;const M=new ResizeObserver(H);return M.observe(V),()=>M.disconnect()},[c,m.description,q,x,v,b,T,y]),l?a.jsx(Hvs,{}):T?a.jsx("div",{"data-testid":"memory-sidebar-panel",className:"h-full min-h-0 min-w-0",children:a.jsx(qvs,{agentId:e,threadId:t})}):a.jsxs("div",{className:"flex h-full min-h-0 w-full flex-col overflow-hidden",children:[a.jsxs("div",{className:"relative min-h-0 flex-1 overflow-hidden",children:[a.jsx("div",{"aria-hidden":b&&c,inert:b&&c?!0:void 0,"data-testid":"memory-sidebar-thread-layer",className:Z("memory-sidebar-thread-layer absolute inset-0 flex min-h-0 flex-col overflow-hidden",b&&c?"pointer-events-none opacity-0":"opacity-100"),children:a.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",style:{paddingBottom:c&&j.offset||void 0},children:s||(c?a.jsx(f9t,{resourceId:e,resourceType:"agent",threads:n??[],threadId:t,onDelete:r??(()=>{}),embedded:!0,isLoading:i},e):a.jsx(Xt,{titleSlot:"Memory not enabled",descriptionSlot:"Conversations are only saved as threads when the agent has memory configured.",actionSlot:a.jsx(de,{icon:a.jsx(Zs,{}),render:a.jsx("a",{href:"https://mastra.ai/docs/memory/overview",target:"_blank",rel:"noopener noreferrer"}),children:"View documentation"})}))})}),c?a.jsxs("div",{ref:S,"data-testid":"memory-sidebar-overlay",className:Z("memory-sidebar-overlay absolute inset-x-0 bottom-0 z-10 box-border flex min-h-0 flex-col overflow-hidden",b?Z(pr,"top-1 m-1 rounded-xl"):"state-layer m-1 rounded-xl border border-surface-rim bg-muted"),style:{height:b?void 0:j.height||void 0},children:[a.jsxs("button",{ref:k,type:"button",onClick:()=>f(b?"threads":"memory"),"aria-pressed":b,"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:[a.jsxs("span",{className:"flex items-center justify-between gap-2",children:[a.jsxs("span",{className:"flex min-w-0 items-center gap-1.5 text-foreground",children:[a.jsx(o$,{className:"h-4 w-4 shrink-0"}),a.jsx(Y,{as:"span",variant:"column",children:"Memory"})]}),b?a.jsx(zc,{className:"h-4 w-4 shrink-0 text-muted-foreground"}):a.jsx(PH,{className:"h-4 w-4 shrink-0 text-muted-foreground"})]}),b?null:a.jsx(mc,{delay:150,timeout:400,children:a.jsxs("span",{"data-testid":"memory-config-badges",className:"mt-1.5 flex flex-wrap items-center gap-1.5",children:[a.jsx(k7,{icon:nL,tooltip:m.description,enabled:m.enabled,value:m.maxMessages}),a.jsx(k7,{icon:Kd,tooltip:v?"Semantic recall is on - retrieves relevant past messages":"Semantic recall is off",enabled:v}),a.jsx(k7,{icon:lEn,tooltip:y?"Working memory is on - persists notes across the conversation":"Working memory is off",enabled:y}),a.jsx(k7,{icon:Ba,tooltip:x?"Observational memory is on - learns from the conversation":"Observational memory is off",enabled:x})]})}),q!==void 0?a.jsx("span",{"data-testid":"memory-card-observation-bar","data-percent":q,className:"mt-2 block h-1 w-full overflow-hidden rounded-full bg-fill",children:a.jsx("span",{className:Z("block h-full rounded-full transition-all duration-normal",Wvs(q)),style:{width:`${q}%`}})}):null]}),b&&a.jsx("div",{className:"memory-card-content min-h-0 flex-1 overflow-y-auto border-t border-border",children:a.jsx(Jds,{agentId:e,threadId:t,memoryType:u})})]}):null]}),a.jsx(rvs,{agentId:e})]})}function Yvs({agentId:e,threadId:t}){const n=xr("agent",e)[0],{mutateAsync:r}=uKr(n),{paths:s,navigate:i}=xn(),{data:o}=$k({agentId:e,requestContext:n,queryOptions:{enabled:!!e}}),l=!!o?.result,{data:c,isLoading:u}=R_e({agentId:e,isMemoryEnabled:l,resourceId:e,requestContext:n,queryOptions:{enabled:l}}),d=(c??[]).map(h=>({...h,createdAt:new Date(h.createdAt),updatedAt:new Date(h.updatedAt)})),f=async h=>{try{await r({threadId:h,agentId:e})}catch{Ke.error("Failed to delete chat");return}Ke.success("Chat deleted successfully"),h===t&&i(s.agentNewThreadLink(e))};return a.jsx(Gvs,{agentId:e,threadId:t,threads:d,onDelete:f,isThreadsLoading:u})}const Xvs=()=>{const e=fX();return D0({"{":()=>e?.toggle()}),null},Ad=e=>e.nullable().transform(t=>t??void 0).optional(),get=zn({frequencyPenalty:Ad(ps()),presencePenalty:Ad(ps()),maxRetries:Ad(ps()),maxSteps:Ad(ps()),maxTokens:Ad(ps()),temperature:Ad(ps()),topK:Ad(ps()),topP:Ad(ps()),seed:Ad(ps()),providerOptions:Ad(ki(gt(),ki(gt(),gMn()))),chatWithGenerateLegacy:Ad(La()),chatWithGenerate:Ad(La()),chatWithLegacyStream:Ad(La()),chatWithNetwork:Ad(La()),requireToolApproval:Ad(La())}),Jvs=zn({provider:gt(),model:gt()}),lBt=ki(gt(),ua());function eys(e){const t=lBt.safeParse(e);if(!t.success)return;const n={};for(const[r,s]of Object.entries(get.shape)){if(!Object.hasOwn(t.data,r))continue;const i=s.safeParse(t.data[r]);i.success&&(n[r]=i.data)}return get.parse(n)}const tys=lBt.transform(e=>{const t=Jvs.safeParse(e.selection);return{selection:t.success?t.data:void 0,modelSettings:eys(e.modelSettings)}});function nys(e){return JSON.stringify({...e,modelSettings:e.modelSettings&&Object.fromEntries(Object.entries(e.modelSettings).map(([t,n])=>[t,n===void 0?null:n]))})}function rys(e){const t=`mastra-thread-preferences-${JSON.stringify([e.agentId,e.threadId])}`;return a.jsx(sys,{...e,storageKey:t},t)}function sys({children:e,defaultProvider:t,defaultModel:n,defaultSettings:r,storageKey:s}){const[i,o]=xk({initialKey:s,defaultValue:{},schema:tys,serialize:nys}),{data:l,isError:c}=L0(),u=l?.modelPolicy,{models:d,isLoading:f,isError:h}=J0({enabled:u?.active===!0}),p=u?.active&&u.allowed!==void 0,m=!!l&&!c&&!(p&&(f||h)),v=i.selection,y=!u?.active||u.allowed===void 0||d.some(I=>io(I.provider)===io(v?.provider??"")&&(!v?.model||I.model===v.model)),x=u?.active&&u.pickerVisible===!1,b=m&&!x&&y?v:void 0,k=!c&&u?.active&&(x||m&&v&&!y)?u?.default:void 0,j=c||p&&h&&!x?"Unable to verify model policy. Using the agent default until policy data is available. Your saved model is unchanged.":void 0,C=b?.provider??k?.provider??t,T=b?.model??k?.modelId??n,_=(b||k)&&C&&T?`${C}/${T}`:void 0,N={modelSettings:{...pve.modelSettings,...r?.modelSettings,...i.modelSettings}};return a.jsx(Z_e.Provider,{value:{provider:C,model:T,modelOverride:_,modelWarning:j,setProvider:I=>o(A=>({...A,selection:{provider:I,model:""}})),setModel:(I,A)=>o(P=>({...P,selection:{provider:I,model:A}}))},children:a.jsx(D_e.Provider,{value:{settings:N,setSettings:I=>o(A=>({...A,modelSettings:I.modelSettings})),resetAll:()=>o(I=>({...I,modelSettings:void 0}))},children:e})})}const iys=6;function oys(e){const t=e?.suggestedPrompts;if(!Array.isArray(t))return[];const n=[],r=new Set;for(const s of t){if(typeof s!="string")continue;const i=s.trim();if(!(!i||r.has(i))&&(n.push(i),r.add(i),n.length===iys))break}return n}function ays(){const{agentId:e,threadId:t}=jr(),n=Ye(),{data:r,error:s}=Zl(),i=r&&Sp(r),o=i?r.user.id:void 0,l=r?.enabled===!1||!!i,c=[n.options.baseUrl,n.options.apiPrefix,o,e],u=JSON.stringify([...c,t??"new"]),[d]=oi(),{data:f,isLoading:h,error:p}=yd({agentId:e,requestContext:xr("agent",e)[0],queryOptions:{enabled:!!e}}),{data:m,isLoading:v}=$k({agentId:e,requestContext:xr("agent",e)[0],queryOptions:{enabled:!!e}}),y=Dr(),x=fX(),b=g.useRef(null),S=t==="new",k=g.useMemo(()=>Sa(),[t]),j=JSON.stringify([...c,k]),C=g.useRef(void 0);g.useLayoutEffect(()=>(C.current=S?j:void 0,()=>{C.current=void 0}),[S,j]);const T=!!m?.result,{data:_,isLoading:N,refetch:I}=R_e({agentId:e,isMemoryEnabled:T,resourceId:e,requestContext:xr("agent",e)[0],queryOptions:{enabled:!!T}}),A=d.get("messageId")??void 0,P=oys(f?.metadata),D=g.useMemo(()=>cNe(f),[f]);if(p&&js(p))return a.jsx(ai,{variant:"fill"});if(p&&Cs(p))return a.jsx(Gs,{variant:"fill",resource:"agents"});if(!r&&s)return a.jsx(Xt,{tone:"error",titleSlot:"Failed to check authentication",descriptionSlot:"Reload the page to try again. Your saved drafts have not been changed."});if(h||!r)return a.jsx(Xve,{agentId:e,leftSlot:S&&!v&&!T?void 0:a.jsx(cys,{agentId:e}),leftDrawerLabel:"Threads",children:S?a.jsx(_gs,{}):a.jsx(uys,{})});if(p&&kk(p))return a.jsx(cW,{});if(p)return a.jsx(Xt,{tone:"error",titleSlot:"Failed to load agent",descriptionSlot:p.message});if(!f)return a.jsx(cW,{});const F=S?k:t??k,Q=S&&!T&&(N||!_?.length),q=async()=>{if(S&&C.current===j){const B=b.current;l&&await B?.move(j),C.current===j&&B===b.current&&y(`/agents/${e}/threads/${k}`,{replace:!0})}x?.expandIfAutoCollapsed(),await I()};return a.jsx(rys,{agentId:e,threadId:F,defaultProvider:io(f.provider??""),defaultModel:f.modelId??"",defaultSettings:D,children:a.jsx(iDt,{agentId:e,threadId:F,resourceId:e,children:a.jsx(sX,{children:a.jsx(iX,{agentId:e,threadId:F,enabled:!!(f?.hasBrowser??f?.browserTools?.length),children:a.jsx(qIe,{ref:b,persistence:l?{key:u,threadId:F}:void 0,children:a.jsx(lDt,{children:a.jsx(MKr,{children:a.jsxs(lX,{children:[a.jsx(Xvs,{}),a.jsx(Xve,{agentId:e,leftSlot:Q?void 0:a.jsx(Yvs,{agentId:e,threadId:F}),leftDrawerLabel:"Threads",children:a.jsx("div",{className:"relative flex h-full min-h-0 flex-col",children:a.jsx("div",{className:"relative grid min-h-0 flex-1",children:a.jsx(jNe,{agentId:e,agentName:f?.name,modelVersion:f?.modelVersion,supportsMemory:f?.supportsMemory,threadId:F,memory:T,refreshThreadList:q,modelList:f?.modelList,messageId:A,suggestedPrompts:P,isNewThread:S,runOptionsSlot:a.jsx(uNe,{agentId:e})})})},F)})]},`${e}-${F}`)},`memory-timeline-${e}-${F}`)})},`${l}:${JSON.stringify([...c,F])}`)},`session-${e}-${F}`)},`browser-${e}-${F}`)})})}function lys(){const{agentId:e}=jr();return a.jsx(zKr,{children:a.jsx(ays,{})},e)}const cys=({agentId:e})=>a.jsx(lNe,{children:a.jsx(f9t,{threads:[],threadId:"",onDelete:()=>{},resourceId:e,resourceType:"agent",embedded:!0,isLoading:!0})}),uys=()=>a.jsx("div",{className:"relative grid h-full overflow-y-auto pt-4","data-testid":"agent-thread-skeleton","aria-busy":"true",children:a.jsx(tBt,{})}),cBt=()=>{const{data:e}=IP();return e?.editorSource==="code"?"code":"db"},xz=()=>{const e=window.MASTRA_CLOUD_API_ENDPOINT,t=window.MASTRA_PLATFORM_PROJECT_ID,n=window.MASTRA_ORGANIZATION_ID,r=window.MASTRA_PLATFORM_OBSERVABILITY_ENDPOINT;return{isMastraPlatform:!!e,mastraPlatformEndpoint:e,mastraPlatformApiEndpoint:e,mastraPlatformProjectId:t,mastraOrganizationId:n,platformObservabilityEndpoint:r}};function dys(){const{agentId:e}=jr(),[t,n]=g.useState(null),{data:r,isLoading:s,error:i}=yd({agentId:e,requestContext:xr("agent",e)[0],queryOptions:{enabled:!!e}}),{data:o}=$k({agentId:e,requestContext:xr("agent",e)[0],queryOptions:{enabled:!!e}}),l=cBt(),{isMastraPlatform:c,mastraPlatformApiEndpoint:u,mastraPlatformProjectId:d}=xz(),{data:f,isLoading:h}=zL({agentId:e,params:{orderBy:{direction:"DESC"}},queryOptions:{enabled:!!e}}),p=(f?.versions?.length??0)>0,{data:m,isLoading:v}=iK({agentId:e,status:"draft",queryOptions:{enabled:!!e&&p}}),y=r?.source==="code",x=y&&l==="code",b=!X_(y,r?.editor).isFullyLocked,S=x&&b,k=S&&c&&!!u&&!!d,j=k?"Open a pull request for these JSON changes":void 0,C=s||h||p&&v,T=!!o?.result,{data:_}=ckt({agentId:e??"",versionId:t??"",queryOptions:{enabled:!!e&&!!t}}),N=m?.activeVersionId,I=f?.versions?.[0],A=!!(I&&I.id!==N),P=!!t&&!!_,D=P&&t!==I?.id,F=g.useMemo(()=>P&&_?_:m||(r?x7t(r):{}),[P,_,m,r]),{form:Q,handlePublish:q,handleSaveDraft:B,handleDownloadJson:V,handleOpenPr:H,isSubmitting:M,isSavingDraft:G,isDirty:L}=aNe({mode:"edit",agentId:e??"",dataSource:F,isCodeAgentOverride:y,hasStoredOverride:y&&!!m,editorConfig:r?.editor,saveSuccessMessage:x?"Saved to filesystem":void 0,onSuccess:()=>{}}),$=g.useCallback(async()=>{D&&t?await q(t):await q()},[q,D,t]),z=g.useCallback(async()=>{!u||!d||await H({platformApiEndpoint:u,projectId:d})},[H,u,d]),U=g.useCallback(K=>{K===I?.id?n(null):n(K)},[I?.id]);return i&&js(i)?a.jsx(ai,{variant:"fill"}):i&&Cs(i)?a.jsx(Gs,{variant:"fill",resource:"agents"}):C?a.jsx(En,{fill:!0}):i&&kk(i)?a.jsx("div",{className:"py-4 text-center",children:"Agent not found"}):i?a.jsx(Xt,{tone:"error",titleSlot:"Failed to load agent",descriptionSlot:i.message}):r?a.jsx(uDt,{form:Q,mode:"edit",agentId:e,isSubmitting:M,isSavingDraft:G,handlePublish:q,handleSaveDraft:B,isCodeAgentOverride:y,isCodeSourceAgent:x,readOnly:D||!b,editorConfig:r?.editor,children:a.jsx(ims,{agentId:e,agentName:r?.name,modelVersion:r?.modelVersion,agentVersionId:t??I?.id,hasMemory:T,activeVersionId:N,selectedVersionId:t??void 0,latestVersionId:I?.id,onVersionSelect:U,isDirty:L,isSavingDraft:G,isPublishing:M,hasDraft:A,readOnly:D||!b,isCodeSourceAgent:x,showCodeModeActions:S,canOpenPr:k,openPrTitle:j,onSaveDraft:B,onPublish:$,onDownloadJson:V,onOpenPr:z,isViewingPreviousVersion:D})}):a.jsx("div",{className:"py-4 text-center",children:"Agent not found"})}const vet=/mac|iphone|ipad|ipod/i;function fys(){if(typeof navigator>"u")return!1;const e=navigator,t=e.userAgentData?.platform||e.platform||"",n=e.userAgent||"";return vet.test(t)||vet.test(n)}function TNe(){const[e]=g.useState(fys);return e}function hys(e){const t=TNe();return g.useMemo(()=>{const n=e.trim().toUpperCase();return`${t?"⌘":"Ctrl"} ${n}`},[t,e])}const ENe="root",pys=e=>Array.isArray(e)?{logic:"and",nodes:e}:e,mys=(e,t)=>t?e.nodes.filter(n=>!hl(n)):e,Fce=e=>{const t=[],n=(r,s)=>{for(const i of r)hl(i)?n(i.nodes,i.id):t.push(s?{item:i,groupId:s}:{item:i})};return n(e.nodes,void 0),t},uBt=(e,t)=>{for(const n of e){if(!hl(n))continue;if(n.id===t)return n;const r=uBt(n.nodes,t);if(r)return r}},dBt=(e,t)=>uBt(e.nodes,t),gys=(e,t)=>{const n=(r,s)=>{for(const i of r){if(!hl(i))continue;if(i.id===t)return s;const o=n(i.nodes,s+1);if(o)return o}return 0};return n(e.nodes,1)},INe=e=>e.nodes.reduce((t,n)=>t+(hl(n)?INe(n):1),0),fBt=e=>[e.id,...e.nodes.flatMap(t=>hl(t)?fBt(t):[t.id])],NJ=(e,t,n)=>e.map(r=>hl(r)?r.id===t?n(r):{...r,nodes:NJ(r.nodes,t,n)}:r),hBt=(e,t)=>e.map(n=>hl(n)?{...n,nodes:hBt(n.nodes,t)}:t(n)),NNe=(e,t)=>e.filter(t).map(n=>hl(n)?{...n,nodes:NNe(n.nodes,t)}:n),vys=(e,t,n)=>({...e,nodes:hBt(e.nodes,r=>r.id===t?{...r,...n}:r)}),yet=(e,t)=>({...e,nodes:NNe(e.nodes,n=>n.id!==t)}),pBt=e=>e.flatMap(t=>{if(!hl(t))return[t];const n=pBt(t.nodes);return n.length===0?[]:[{...t,nodes:n}]}),mBt=e=>({...e,nodes:pBt(e.nodes)}),xet=(e,t,n)=>!t||t===ENe?{...e,nodes:[...e.nodes,n]}:{...e,nodes:NJ(e.nodes,t,r=>({...r,nodes:[...r.nodes,n]}))},yys=(e,t,n)=>t===ENe?{...e,logic:n}:{...e,nodes:NJ(e.nodes,t,r=>({...r,logic:n}))},xys=(e,t,n)=>!t||t===ENe?{...e,nodes:[...e.nodes,n]}:{...e,nodes:NJ(e.nodes,t,r=>({...r,nodes:[...r.nodes,n]}))},bys=(e,t)=>mBt({...e,nodes:NNe(e.nodes,n=>hl(n)||t.has(n.id))}),mye=["field","operator","value","remove"],wys=[...mye].reverse(),Sys=3,ANe="data-filter-bar-scope",Bce=e=>e?.closest(`[${ANe}]`)??null,bet=e=>e?e.operatorId?"operator":"field":"none",gBt=g.createContext(null);function Xc(){const e=g.useContext(gBt);if(!e)throw new Error("FilterBar compound components must be rendered inside <FilterBar>.");return e}let wet=0;function ket(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():(wet+=1,`filter-${wet}`)}function vBt(e){return e?.arity==="many"?[]:""}const WO=(e,t=new Set)=>{for(const n of e)t.add(n.id),hl(n)&&WO(n.nodes,t);return t},yBt=(e,t,n)=>{const r=new Map(t.map(o=>[o.id,o])),s=new Set,i=[];for(const o of e){const l=r.get(o.id);l?(s.add(o.id),i.push(hl(l)&&hl(o)?{...l,nodes:yBt(o.nodes,l.nodes,n)}:l)):n.has(o.id)&&i.push(o)}for(const o of t)s.has(o.id)||i.push(o);return i};function kys({fields:e,operators:t,value:n,onValueChange:r,createItemId:s,maxDepth:i=Sys,ariaLabel:o,children:l}){const c=g.useRef(new Map),u=g.useRef(null),d=Array.isArray(n),f=g.useMemo(()=>pys(n),[n]),h=g.useRef(f);h.current=f;const[p,m]=g.useState(""),[v,y]=g.useState(()=>new Set),[x,b]=g.useState(void 0),[S,k]=g.useState(null),j=g.useCallback(je=>r(mys(je,d)),[r,d]),C=g.useCallback(je=>e.find(ce=>ce.id===je),[e]),T=g.useCallback(je=>t.find(ce=>ce.id===je),[t]),_=g.useCallback(je=>{if(!je.operators)return t;const ce=new Set(je.operators);return t.filter(ye=>ce.has(ye.id))},[t]),N=g.useCallback(je=>m(je),[]),[I,A]=g.useState(null),P=g.useRef(I);P.current=I;const[D,F]=g.useState(null),Q=g.useCallback(()=>F(je=>je?{...je,glint:!1}:null),[]),[q,B]=g.useState(()=>new Set),V=g.useCallback(je=>{B(ce=>{if(!ce.has(je))return ce;const ye=new Set(ce);return ye.delete(je),ye})},[]),H=g.useCallback(je=>{const ce=[...je];ce.length!==0&&B(ye=>new Set([...ye,...ce]))},[]),M=g.useRef(f.nodes),{rendered:G,items:L,leaving:$,rootGroupOf:z}=g.useMemo(()=>{const je=WO(f.nodes);let ce=q.size===0?f:{...f,nodes:yBt(M.current,f.nodes,q)};D&&!je.has(D.item.id)&&(ce=xet(ce,D.groupId,D.item)),M.current=ce.nodes;const ye=WO(ce.nodes),De=new Set([...q].filter(le=>ye.has(le)&&!je.has(le))),Ie=new Map;for(const le of ce.nodes)if(hl(le))for(const{item:xe}of Fce({nodes:[le]}))Ie.set(xe.id,le.id);return{rendered:ce,items:Fce(ce).map(le=>le.item),leaving:De,rootGroupOf:Ie}},[f,D,q]),U=g.useCallback(je=>s&&x===void 0?s(je):ket(),[s,x]),K=g.useCallback(je=>{F(null),A(ce=>je?{...je,id:ce?.fieldId===je.fieldId?ce.id:U(je.fieldId),from:bet(ce),groupId:x}:null)},[U,x]),ne=g.useCallback(({fieldId:je,operatorId:ce},ye)=>{const De=P.current?.id??U(je),Ie=P.current?.groupId??x,le={id:De,fieldId:je,operatorId:ce,value:ye};j(xet(h.current,Ie,le)),F({item:le,from:bet(P.current),glint:!0,groupId:Ie}),A(null),N("Filter added")},[j,N,U,x]),X=g.useCallback((je,ce)=>{j(vys(h.current,je,ce))},[j]),te=g.useCallback(je=>{H([je]),j(yet(h.current,je)),F(null),N("Filter removed")},[j,N,H]),ie=g.useCallback(je=>{b(ce=>ce&&je.has(ce)?void 0:ce)},[]),ue=g.useCallback(je=>{const ce=h.current,ye=dBt(ce,je),De=new Set(ye?fBt(ye):[je]);H(De),j(yet(ce,je)),F(null),A(null),ie(De),k(Ie=>Ie===je?null:Ie),N("Advanced filter removed")},[j,N,H,ie]),ee=g.useCallback((je,ce)=>{const ye={id:ket(),kind:"group",logic:ce,nodes:[]};return j(xys(h.current,je,ye)),F(null),A(null),b(ye.id),N(je?"Nested group added":"Advanced filter added"),ye.id},[j,N]),se=g.useCallback((je,ce)=>{j(yys(h.current,je,ce)),N(`Conditions joined with ${ce}`)},[j,N]),re=g.useCallback(je=>gys(h.current,je),[]),ae=g.useCallback(je=>{if(k(je),je!==null)return;const ce=h.current,ye=mBt(ce),De=WO(ye.nodes),Ie=new Set([...WO(ce.nodes)].filter(le=>!De.has(le)));Ie.size>0&&(H(Ie),j(ye)),A(null),b(void 0)},[j,H]),he=g.useCallback(()=>{u.current?.focus()},[]),ve=g.useCallback(je=>{b(je),A(null),je===void 0&&he()},[he]),pe=g.useCallback(()=>{const je=h.current,ce=bys(je,v),ye=WO(ce.nodes),De=new Set([...WO(je.nodes)].filter(Ie=>!ye.has(Ie)));H(De),j(ce),F(null),A(null),b(void 0),k(null),N("All filters removed")},[j,N,v,H]),ke=Fce(f).some(({item:je})=>!v.has(je.id)),Ee=g.useCallback((je,ce)=>{y(ye=>{if(ye.has(je)===ce)return ye;const De=new Set(ye);return ce?De.add(je):De.delete(je),De})},[]),Ue=g.useCallback((je,ce,ye)=>{const De=`${je}:${ce}`;ye?c.current.set(De,ye):c.current.delete(De)},[]),Qe=g.useCallback(je=>{je?u.current=je:u.current?.isConnected||(u.current=null)},[]),Be=g.useRef(L);Be.current=L;const Ae=g.useRef(z);Ae.current=z;const Fe=g.useCallback((je,ce,ye)=>{const De=Be.current,Ie=Ae.current,le=De[je-ce],xe=le?[...mye].map(Le=>c.current.get(`${le.id}:${Le}`)).find(Boolean):null,Se=Bce(typeof document>"u"?null:document.activeElement)??Bce(xe)??void 0,Re=ce===-1?wys:mye;for(let Le=je;Le>=0&&Le<De.length;Le+=ce){const We=De[Le];if(!We)break;const tt=[We.id,Ie.get(We.id)].filter(st=>st!==void 0);for(const st of tt)for(const He of[ye,...Re]){const ze=c.current.get(`${st}:${He}`);if(ze&&(Se===void 0||Bce(ze)===Se))return ze.focus(),!0}}return!1},[]),Ce=g.useCallback(je=>{Fe(je+1,1,"value")||Fe(je-1,-1,"value")||he()},[Fe,he]),_e=g.useMemo(()=>({fields:e,operators:t,items:L,expression:G,groupsEnabled:!d,maxDepth:i,draft:I,setDraft:K,commitDraft:ne,lastCommit:D,settleCommit:Q,updateItem:X,removeItem:te,leaving:$,settleRemove:V,clear:pe,hasRemovableItems:ke,registerNonRemovable:Ee,addGroup:ee,removeGroup:ue,setLogic:se,getGroupDepth:re,openGroupId:S,setOpenGroup:ae,inputTarget:x,openGroupInput:ve,getField:C,getOperator:T,getFieldOperators:_,registerSegment:Ue,registerInput:Qe,focusChip:Fe,focusInput:he,focusAfterRemove:Ce,announce:N,announcement:p,ariaLabel:o}),[e,t,L,G,d,i,I,K,ne,D,Q,X,te,$,V,pe,ke,Ee,ee,ue,se,re,S,ae,x,ve,C,T,_,Ue,Qe,Fe,he,Ce,N,p,o]);return a.jsx(gBt.Provider,{value:_e,children:l})}function xBt({option:e}){return a.jsxs(a.Fragment,{children:[e.start,a.jsx("span",{className:"min-w-0 truncate",children:e.label??e.value})]})}const bBt=g.forwardRef((e,t)=>a.jsx(tkt,{ref:Pu(t),...e}));bBt.displayName="FilterBarOptionItem";function KI({getKey:e,renderOption:t,isSelected:n,isLoading:r,error:s,emptyText:i="No results.","aria-label":o,"aria-multiselectable":l}){const c=!r&&s===void 0,u=Rv();return a.jsxs(a.Fragment,{children:[r&&a.jsxs(KBe,{className:ls.empty,children:[a.jsx(En,{size:"sm"}),a.jsx("span",{children:"Loading…"})]}),!r&&s!==void 0&&a.jsx(KBe,{className:ls.empty,children:"Couldn't load values."}),a.jsx(rkt,{className:ls.empty,children:c?i:null}),a.jsx("div",{className:Z(ls.listScroller,"max-h-[min(var(--spacing-dropdown),60dvh)]",u.containerClassName),...u.getContainerProps({}),children:a.jsx(Bm,{menu:u,children:a.jsx(GSt,{"aria-label":o,"aria-multiselectable":l,className:ls.list,children:d=>{const f=n?.(d)??!1;return a.jsxs(bBt,{value:d,"data-selected":f||void 0,className:Z(ls.item,"min-w-0"),children:[a.jsx("span",{className:"flex min-w-0 flex-1 items-center gap-1.5 truncate",children:t(d)}),a.jsx("span",{className:ls.itemRightSlot,children:a.jsx("span",{className:ls.checkContainer,children:n?f&&a.jsx(dr,{className:ls.checkIcon}):a.jsx(nkt,{children:a.jsx(dr,{className:ls.checkIcon})})})})]},e(d))}})})})]})}function PNe(e,t){const n=t.toLowerCase().split(/\s+/).filter(Boolean);if(n.length===0)return!0;const r=e.toLowerCase();return n.every(s=>r.includes(s))}function $Ne(e,t,n){return PNe(n?n(e):String(e),t)}const Oys=150,jys=[{value:"true",label:"True"},{value:"false",label:"False"}],wBt=e=>e?.suggestions??(e?.type==="boolean"?jys:void 0);function Cys({field:e,operatorId:t,query:n,enabled:r}){const s=wBt(e),i=typeof s=="function"?s:void 0,o=Array.isArray(s)?s:void 0,[l,c]=g.useState([]),[u,d]=g.useState(!1),[f,h]=g.useState(void 0),p=g.useRef(0),m=g.useRef(i);m.current=i;const v=!!i;return g.useEffect(()=>{if(!v||!r){c([]),d(!1),h(void 0);return}const x=++p.current,b=new AbortController;d(!0);const S=setTimeout(()=>{Promise.resolve().then(()=>m.current?.({query:n,operatorId:t,signal:b.signal})??[]).then(k=>{x===p.current&&(c(k),h(void 0),d(!1))}).catch(k=>{x!==p.current||b.signal.aborted||(h(k),d(!1))})},Oys);return()=>{clearTimeout(S),b.abort()}},[v,r,n,t]),{options:g.useMemo(()=>o?o.filter(x=>PNe(x.label??x.value,n)):l,[o,l,n]),isLoading:!!i&&u,error:f,hasSuggestions:!!s}}const Oet=e=>Array.isArray(e)?e.map(String):[];function SBt({field:e,operator:t,query:n,enabled:r,initialValue:s,setQuery:i,onCommit:o}){const l=t?.arity==="many",[c,u]=g.useState(()=>Oet(s)),d=g.useRef(s);d.current=s,g.useEffect(()=>{u(r?Oet(d.current):[])},[r]);const f=t?.freeText===!0,h=Cys({field:f?void 0:e,operatorId:t?.id??"",query:n,enabled:r}),p=e?.type,m=(!e?.strict||f)&&p!=="boolean",v=g.useMemo(()=>{if(!l)return h.options;const I=_ys(c,h.options,h.hasSuggestions,n);return I.length===0?h.options:[...h.options,...I]},[l,c,h.options,h.hasSuggestions,n]),y=g.useCallback(I=>{u(A=>A.includes(I)?A.filter(P=>P!==I):[...A,I])},[]),x=g.useCallback(I=>o(Array.isArray(I)?I.map(A=>uye(p,A)):uye(p,I)),[o,p]),b=g.useCallback(I=>{l?y(I.value):x(I.value)},[l,y,x]),S=g.useCallback(()=>c.length===0?!1:(x(c),!0),[c,x]),k=g.useCallback(I=>m&&I.length>0&&(p!=="number"||Number.isFinite(Number(I)))&&(!f||/[\p{L}\p{M}\p{N}]/u.test(I)),[m,f,p]);function j(){const I=n.trim();return k(I)?(u(A=>A.includes(I)?A:[...A,I]),i(""),!0):!1}const C=g.useCallback(()=>{const I=n.trim();return k(I)?(x(l?c.includes(I)?c:[...c,I]:I),!0):!1},[k,n,l,c,x]);function T(){return l?j():C()}function _(){return h.options.length===0?C()||S():S()||C()}function N(I,A){return I.key!=="Enter"?!1:l&&(I.ctrlKey||I.metaKey)?(I.preventDefault(),_()):A===null?(I.preventDefault(),T()):!1}return{isMany:l,selected:c,toggle:y,options:v,isLoading:h.isLoading,error:h.error,hasSuggestions:h.hasSuggestions,hasOptions:h.hasSuggestions||v.length>0,allowFreeText:m,canCommitQuery:k(n.trim()),handleSelect:b,handleKeyDown:N,submitFreeText:T,commitDone:_}}function _ys(e,t,n,r){const s=new Set(t.map(o=>o.value)),i=o=>!n||PNe(o,r);return e.filter(o=>!s.has(o)&&i(o)).map(o=>({value:o}))}const AJ=Z("filter-bar-segment flex max-w-48 min-w-0 items-center gap-1 overflow-hidden px-2 text-label whitespace-nowrap outline-none"),kBt="sm",OBt={autoHighlight:"always",keepHighlight:!0},jBt=Z("filter-bar-chip relative flex max-w-full items-stretch divide-x divide-border overflow-hidden rounded-full py-px",EH,np[kBt]),YI=Z(AJ,"cursor-pointer hover:bg-fill-subtle hover:text-foreground","focus-visible:bg-fill-hover focus-visible:text-foreground data-[popup-open]:bg-fill-hover data-[popup-open]:text-foreground");function PJ({field:e,label:t}){const n=e?.icon;return a.jsxs(a.Fragment,{children:[n&&a.jsx(n,{className:"size-[1.1em] shrink-0","aria-hidden":!0}),a.jsx("span",{className:"truncate",children:t??e?.label})]})}const gye=e=>e?.color?{color:e.color}:void 0,Tys=(e,t)=>e==="none"?0:e==="field"||t?1:2,uW=(e,t)=>{const n=wBt(t),r=Array.isArray(n)?n:void 0,s=i=>r?.find(o=>o.value===String(i))?.label??String(i);return Array.isArray(e)?e.map(s).join(", "):s(e)},Eys=(e,t)=>!Array.isArray(e)||e.length<2?uW(e,t):`${uW(e.slice(0,1),t)} +${e.length-1}`,CBt=g.createContext(null),Lk=()=>{const e=g.useContext(CBt);if(!e)throw new Error("FilterBarChip segments must be rendered inside <FilterBarChip>.");return e};function Iys(e){return e instanceof Element&&!!e.closest('[data-slot="filter-bar-editor"]')}function yx({item:e,readOnly:t=!1,removable:n=!0,draft:r=!1,className:s,children:i}){const o=Xc(),[l,c]=g.useState(null),u=o.getField(e.fieldId),d=o.getOperator(e.operatorId),f=o.items.findIndex(I=>I.id===e.id),h=g.useRef(null),p=o.leaving.has(e.id),m=!r&&(t||!n),{registerNonRemovable:v,settleRemove:y}=o;g.useEffect(()=>(v(e.id,m),()=>v(e.id,!1)),[v,e.id,m]),g.useEffect(()=>{const I=h.current;if(!p||!I)return;const A=typeof I.getAnimations=="function"?I.getAnimations({subtree:!0}):[];if(A.length===0){y(e.id);return}let P=!1;return Promise.all(A.map(D=>D.finished)).then(()=>{P||y(e.id)}).catch(()=>{}),()=>{P=!0}},[p,e.id,y]);const x=u?o.getFieldOperators(u).length===1:!1,b=[u?.label??e.fieldId,x?"":d?.label??e.operatorId,r?"":uW(e.value,u)].filter(Boolean).join(" "),S=!r&&o.lastCommit?.item.id===e.id?o.lastCommit:null,k=r?o.draft?.from??"none":S?.from??"none",j=Tys(k,x),C=S?.glint??!1,T=g.useCallback(I=>{if(t||r||p||Iys(I.target))return;const A=Array.from(h.current?.querySelectorAll("[data-filter-bar-segment]")??[]),P=A.findIndex(D=>D===I.target);switch(I.key){case"ArrowRight":{I.preventDefault();const D=A[P+1];D?D.focus():o.focusChip(f+1,1,"field")||o.focusInput();return}case"ArrowLeft":{I.preventDefault();const D=A[P-1];D?D.focus():o.focusChip(f-1,-1,"remove");return}case"Delete":case"Backspace":if(!n)return;I.preventDefault(),o.removeItem(e.id),o.focusAfterRemove(f);return}},[t,r,p,n,o,f,e.id]),_=g.useMemo(()=>({item:e,index:f,field:u,operator:d,openSegment:l,setOpenSegment:c,readOnly:t,draft:r,leaving:p,operatorImplied:x}),[e,f,u,d,l,t,r,p,x]),N=i??a.jsxs(a.Fragment,{children:[a.jsx(IBt,{}),a.jsx(NBt,{}),a.jsx(ABt,{}),n&&a.jsx(PBt,{})]});return a.jsx(CBt.Provider,{value:_,children:a.jsxs("div",{ref:h,role:"group","aria-label":b,"aria-hidden":r||p||void 0,"data-slot":"filter-bar-chip","data-draft":r||void 0,"data-readonly":t||void 0,"data-leaving":p||void 0,"data-shine":C&&!p||void 0,className:Z(jBt,p&&"pointer-events-none",s),style:{"--filter-bar-segments-settled":j,"--filter-bar-chip-shine":u?.color??"currentColor"},onKeyDown:T,onClick:I=>I.stopPropagation(),onAnimationEnd:I=>{I.animationName==="filter-bar-chip-shine"&&o.settleCommit()},children:[t&&a.jsx("span",{className:Z(AJ,"pr-0 text-muted-foreground [--filter-bar-segment-padding:0.5rem_0]"),title:"This filter is locked",children:a.jsx(Tu,{className:"size-[1.1em]"})}),N]})})}const _Bt=g.createContext({highlighted:null});function RNe({placeholder:e,icon:t=Kd,inputMode:n,onKeyDown:r}){const{highlighted:s}=g.useContext(_Bt);return a.jsxs("div",{className:ls.searchContainer,children:[a.jsx(t,{className:ls.searchIcon}),a.jsx(cke,{className:ls.searchInput,placeholder:e,inputMode:n,...gp,onKeyDown:i=>r?.(i,s)})]})}function MNe({segment:e,label:t,fullLabel:n=t,ariaLabel:r,items:s,itemToString:i,filter:o,value:l=null,query:c,onQueryChange:u,onSelect:d,onOpen:f,children:h}){const p=Xc(),m=Lk(),v=U0(),y=m.openSegment===e,[x,b]=g.useState(null),S=e==="field",k=S?a.jsx(PJ,{field:m.field,label:t}):a.jsx("span",{className:"truncate",children:t});return m.readOnly||m.draft||m.leaving?a.jsx("span",{className:Z(AJ,S&&"text-foreground"),style:S?gye(m.field):void 0,title:n,children:k}):a.jsxs(oQ,{items:s,itemToStringLabel:i,itemToStringValue:i,filter:o,value:l,onValueChange:(j,C)=>{C.cancel(),j!==null&&d(j)},inputValue:c,onInputValueChange:(j,C)=>{C.reason==="input-change"&&u(j)},onItemHighlighted:j=>b(j??null),open:y,onOpenChange:j=>{j?f?.():u(""),m.setOpenSegment(j?e:null)},...OBt,modal:!1,children:[a.jsx(HSt,{ref:j=>p.registerSegment(m.item.id,e,j),render:a.jsx("button",{type:"button","data-filter-bar-segment":"",tabIndex:e==="value"?0:-1,"aria-label":`${r}: ${n}`,title:n,className:Z(YI,S&&"text-foreground"),style:S?gye(m.field):void 0}),children:k}),a.jsx(uke,{container:v,children:a.jsx(dke,{align:"start",sideOffset:__,positionMethod:jv,className:ls.positioner,children:a.jsx(fke,{className:Z(ls.popup,"min-w-44"),"data-slot":"filter-bar-editor",children:a.jsx(_Bt.Provider,{value:{highlighted:x},children:h})})})})]})}const Nys=e=>e.label,Ays=e=>e.label,Pys=e=>e.label??e.value;function $ys(){const e=Xc(),t=Lk(),[n,r]=g.useState(""),s=g.useCallback(i=>{const o=e.getFieldOperators(i),l=o.find(u=>u.id===t.item.operatorId)??o[0],c=l?.arity!==t.operator?.arity;e.updateItem(t.item.id,{fieldId:i.id,operatorId:l?.id??t.item.operatorId,value:c||i.id!==t.item.fieldId?vBt(l):t.item.value}),t.setOpenSegment(null)},[e,t]);return a.jsxs(MNe,{segment:"field",ariaLabel:"Field",label:t.field?.label??t.item.fieldId,items:e.fields,itemToString:Nys,filter:$Ne,value:t.field,query:n,onQueryChange:r,onSelect:s,children:[a.jsx(RNe,{placeholder:"Change field…"}),a.jsx(KI,{"aria-label":"Fields",getKey:i=>i.id,renderOption:i=>a.jsx(PJ,{field:i}),emptyText:"No matching field."})]})}function Rys(){const e=Xc(),t=Lk(),[n,r]=g.useState(""),s=g.useMemo(()=>t.field?e.getFieldOperators(t.field):e.operators,[e,t.field]),i=g.useCallback(o=>{const l=(o.arity??"one")!==(t.operator?.arity??"one");e.updateItem(t.item.id,{operatorId:o.id,value:l?vBt(o):t.item.value}),t.setOpenSegment(null)},[e,t]);return a.jsxs(MNe,{segment:"operator",ariaLabel:"Operator",label:t.operator?.label??t.item.operatorId,items:s,itemToString:Ays,filter:$Ne,value:t.operator,query:n,onQueryChange:r,onSelect:i,children:[a.jsx(RNe,{placeholder:"Change operator…"}),a.jsx(KI,{"aria-label":"Operators",getKey:o=>o.id,renderOption:o=>o.label,emptyText:"No matching operator."})]})}function Mys(){const e=Xc(),t=Lk(),n=t.openSegment==="value",[r,s]=g.useState(""),i=g.useCallback(()=>t.setOpenSegment(null),[t]),o=g.useCallback(u=>{e.updateItem(t.item.id,{value:u}),i()},[e,t.item.id,i]),l=SBt({field:t.field,operator:t.operator,query:r,enabled:n,initialValue:t.item.value,setQuery:s,onCommit:o}),c=Bys[t.field?.type??"text"];return a.jsx(MNe,{segment:"value",ariaLabel:"Value",label:Eys(t.item.value,t.field)||"…",fullLabel:uW(t.item.value,t.field)||"…",items:l.options,itemToString:Pys,filter:null,query:r,onQueryChange:s,onSelect:l.handleSelect,onOpen:()=>s(!Array.isArray(t.item.value)&&!t.field?.suggestions?String(t.item.value):""),children:a.jsx(c,{step:l,onCancel:i})})}function TBt({step:e,onCancel:t}){const n=Lk(),r=TNe()?"⌘↵":"Ctrl ↵";return a.jsxs(a.Fragment,{children:[e.hasOptions&&a.jsx(KI,{"aria-label":"Values","aria-multiselectable":e.isMany||void 0,getKey:s=>s.value,renderOption:s=>a.jsx(xBt,{option:s}),isSelected:s=>e.isMany?e.selected.includes(s.value):String(n.item.value)===s.value,isLoading:e.isLoading,error:e.error,emptyText:e.allowFreeText?"No suggestions — press Enter to use your text.":"No matching value."}),e.isMany&&a.jsxs("div",{className:"flex items-center justify-end gap-1 border-t border-border p-1",children:[a.jsx(de,{size:"sm",variant:"ghost",onClick:t,children:"Cancel"}),a.jsxs(de,{size:"sm",variant:"default",onClick:()=>e.commitDone(),children:["Done",a.jsx(Qd,{size:"xs",children:r})]})]})]})}function Dys(e,t){return e.hasSuggestions?e.allowFreeText?`Search or type a ${t}…`:`Search ${t}s…`:`Type a ${t}…`}function EBt({step:e,onCancel:t,inputMode:n,noun:r}){return a.jsxs(a.Fragment,{children:[a.jsx(RNe,{icon:e.hasSuggestions?Kd:Fc,inputMode:n,placeholder:Dys(e,r),onKeyDown:(s,i)=>{const o=e.hasSuggestions?i:null;(e.handleKeyDown(s,o)||s.key==="Enter"&&o===null)&&s.preventBaseUIHandler()}}),a.jsx(TBt,{step:e,onCancel:t})]})}function Lys(e){return a.jsx(EBt,{...e,noun:"value"})}function zys(e){return a.jsx(EBt,{...e,inputMode:"decimal",noun:"number"})}function Fys(e){return a.jsx(TBt,{...e})}const Bys={text:Lys,number:zys,boolean:Fys};function IBt(){return a.jsx($ys,{})}function NBt(){const e=Lk();return e.operatorImplied||e.draft&&!e.operator?null:a.jsx(Rys,{})}function ABt(){const e=Lk();return e.draft||(e.operator?.arity??"one")==="none"?null:a.jsx(Mys,{})}function PBt(){const e=Xc(),t=Lk();if(t.readOnly||t.draft)return null;const n=Z(YI,"px-1.5 text-muted-foreground [--filter-bar-segment-padding:0.375rem]");if(t.leaving)return a.jsx("span",{className:n,children:a.jsx(Dn,{className:"size-[1.1em]"})});const r=`Remove ${t.field?.label??t.item.fieldId} filter`;return a.jsx("button",{type:"button","data-filter-bar-segment":"",tabIndex:-1,"aria-label":r,title:r,ref:s=>e.registerSegment(t.item.id,"remove",s),className:n,onClick:()=>{e.removeItem(t.item.id),e.focusAfterRemove(t.index)},children:a.jsx(Dn,{className:"size-[1.1em]"})})}yx.Field=IBt;yx.Operator=NBt;yx.Value=ABt;yx.Remove=PBt;const Vys=e=>"label"in e&&e.label?e.label:"value"in e?e.value:"",Uys=[],$Bt="__filter-bar-advanced__",qys={id:$Bt,label:"Advanced filter…",icon:Ua,operators:[]};function RBt(e){return Xc().inputTarget!==e.groupId?null:a.jsx(Qys,{...e})}function Qys({placeholder:e="Filter…",className:t,"aria-label":n="Add filter",groupId:r,onLeave:s}){const i=Xc(),o=U0(),l=g.useRef(null),[c,u]=g.useState(!1),[d,f]=g.useState(""),[h,p]=g.useState(null),[m,v]=g.useState(!1),y=TNe()?"⌘↵":"Ctrl ↵",{draft:x,setDraft:b,commitDraft:S}=i,k=x?x.operatorId?"value":"operator":"field",j=x?i.getField(x.fieldId):void 0,C=x?.operatorId?i.getOperator(x.operatorId):void 0,T=g.useMemo(()=>j?i.getFieldOperators(j):[],[i,j]),_=i.groupsEnabled&&r===void 0,N=g.useMemo(()=>{const X=i.fields.filter(te=>!te.hidden);return _?[...X,qys]:X},[i.fields,_]),I=r?dBt(i.expression,r):void 0;g.useEffect(()=>{r&&l.current?.focus()},[r]);const A=g.useCallback(X=>{wo.flushSync(()=>v(!0)),X(),v(!1)},[]),P=g.useCallback(X=>A(()=>b(X)),[A,b]),D=g.useCallback(()=>{b(null),f("")},[b]),F=g.useCallback(()=>{u(!1),D()},[D]),Q=g.useCallback((X,te,ie)=>{A(()=>S({fieldId:X,operatorId:te},ie)),f(""),l.current?.focus()},[A,S]),q=g.useCallback((X,te)=>{if(te.arity==="none"){Q(X,te.id,"");return}P({fieldId:X,operatorId:te.id}),f("")},[Q,P]),B=g.useCallback(X=>{if(X.id===$Bt){const ue=i.addGroup(void 0,"or");i.setOpenGroup(ue),i.openGroupInput(ue),f(""),u(!1);return}const[te,...ie]=i.getFieldOperators(X);if(X.search&&te&&d.trim()!==""){Q(X.id,te.id,uye(X.type,d));return}if(te&&ie.length===0){q(X.id,te);return}P({fieldId:X.id}),f("")},[i,Q,d,q,P]),V=SBt({field:j,operator:C,query:d,enabled:c&&k==="value",setQuery:f,onCommit:X=>{x?.operatorId&&Q(x.fieldId,x.operatorId,X)}}),H=g.useCallback(()=>r?(i.openGroupInput(void 0),s?.(),!0):!1,[i,r,s]),M=g.useCallback(()=>{if(k==="value"&&x){const X=j?T.length===1:!1;P(X?null:{fieldId:x.fieldId})}else k==="operator"?P(null):H()||u(!1);f("")},[k,x,j,T,P,H]),G=X=>{k==="field"?B(X):k==="operator"&&x?q(x.fieldId,X):V.handleSelect(X)},L=X=>{if(X.key==="Escape"){X.preventDefault(),X.stopPropagation(),X.preventBaseUIHandler(),M();return}if(!c&&(X.key==="ArrowDown"||X.key==="Enter")){X.preventDefault(),X.preventBaseUIHandler(),u(!0);return}if(d===""){if(X.key==="Backspace"){if(X.preventDefault(),X.preventBaseUIHandler(),k!=="field")M();else if(I){const te=I.nodes.findLast(ie=>!i.leaving.has(ie.id));te?i.removeItem(te.id):H()}else{const te=i.items.findLast(ie=>!i.leaving.has(ie.id));te&&i.removeItem(te.id)}return}if(X.key==="ArrowLeft"&&k==="field"){i.focusChip(i.items.length-1,-1,"remove")&&X.preventDefault();return}}if(c){if(X.key==="Tab"&&h&&k!=="value"&&(k==="operator"||d!=="")){X.preventDefault(),X.preventBaseUIHandler(),G(h);return}if(k==="value"){const te=V.hasSuggestions?h:null;(V.handleKeyDown(X,te)||X.key==="Enter"&&te===null)&&X.preventBaseUIHandler()}}},$={field:N,operator:T,value:V.options},z=m?Uys:$[k],U=g.useCallback((X,te,ie)=>"search"in X&&X.search===!0||$Ne(X,te,ie),[]),K=k==="field"?"Search fields…":k==="operator"?"Search operators…":"Search values…",ne=k==="field"?e:k==="operator"?"Operator…":V.hasSuggestions&&V.allowFreeText?"Search or type a value…":j?.type==="number"?"Number…":"Value…";return a.jsx(a.Fragment,{children:a.jsxs(oQ,{items:z,itemToStringLabel:Vys,filter:k==="value"?null:U,value:null,onValueChange:(X,te)=>{te.cancel(),X&&G(X)},inputValue:d,onInputValueChange:(X,te)=>{te.reason==="input-change"&&(f(X),c||u(!0))},onItemHighlighted:X=>p(X??null),open:c,onOpenChange:(X,te)=>{!X&&te.reason==="escape-key"||!X&&te.reason==="outside-press"&&te.event.target instanceof Node&&l.current?.contains(te.event.target)||(X?u(!0):F())},...OBt,modal:!1,children:[a.jsxs("div",{"data-slot":"filter-bar-input-trigger",className:Z(skt({variant:"default",size:kBt}),"w-auto cursor-text","focus-within:bg-fill-hover",rjn,k==="field"?"min-w-40":"min-w-28",t),children:[a.jsx(oht,{"aria-hidden":!0,className:"-ml-[.3em] shrink-0 text-muted-foreground"}),a.jsx(cke,{ref:X=>{l.current=X,i.registerInput(X)},"aria-label":n,spellCheck:!1,...gp,"data-slot":"filter-bar-input","data-step":k,"data-target":I?.id,inputMode:k==="value"&&j?.type==="number"?"decimal":void 0,placeholder:ne,className:Z(A0e,"min-w-0 flex-1 bg-transparent","placeholder:text-muted-foreground placeholder:transition-opacity placeholder:duration-normal focus:placeholder:opacity-70"),onFocus:()=>u(!0),onKeyDown:L})]}),a.jsx(uke,{container:o,children:a.jsx(dke,{align:"start",sideOffset:__,positionMethod:jv,className:ls.positioner,children:a.jsxs(fke,{className:Z(ls.popup,"min-w-56"),"data-slot":"filter-bar-editor",children:[(k!=="value"||V.hasSuggestions)&&a.jsxs("div",{className:Z(ls.searchContainer,"cursor-text"),"data-slot":"filter-bar-search",onMouseDown:X=>X.preventDefault(),onClick:()=>l.current?.focus(),children:[a.jsx(Kd,{className:ls.searchIcon}),a.jsx("span",{className:Z(ls.searchInput,"flex items-center truncate",d===""&&ls.placeholder),children:d===""?K:d})]}),k==="field"&&a.jsx(KI,{"aria-label":"Fields",getKey:X=>X.id,renderOption:X=>a.jsxs(a.Fragment,{children:[a.jsx(PJ,{field:X}),X.search&&d!==""&&a.jsxs("span",{className:"min-w-0 truncate text-muted-foreground",children:[i.getFieldOperators(X)[0]?.label,' "',d,'"']})]}),emptyText:"No matching field."}),k==="operator"&&a.jsx(KI,{"aria-label":"Operators",getKey:X=>X.id,renderOption:X=>X.label,emptyText:"No matching operator."}),k==="value"&&V.hasOptions&&a.jsx(KI,{"aria-label":"Values","aria-multiselectable":V.isMany||void 0,getKey:X=>X.value,renderOption:X=>a.jsx(xBt,{option:X}),isSelected:X=>V.isMany&&V.selected.includes(X.value),isLoading:V.isLoading,error:V.error,emptyText:V.allowFreeText?"No suggestions — press Enter to use your text.":"No matching value."}),k==="value"&&!V.hasSuggestions&&a.jsxs("div",{className:"flex items-center justify-between gap-2 py-1 pr-1 pl-[.9em]",children:[a.jsx(Y,{variant:"caption",tone:"muted",children:"Type a value"}),a.jsxs(de,{size:"sm",variant:"default",disabled:!V.canCommitQuery,onMouseDown:X=>X.preventDefault(),onClick:()=>V.submitFreeText(),children:["Apply",a.jsx(Qd,{size:"xs",children:"↵"})]})]}),k==="value"&&V.isMany&&a.jsx("div",{className:"flex items-center justify-end gap-1 border-t border-border p-1",children:a.jsxs(de,{size:"sm",variant:"default",onMouseDown:X=>X.preventDefault(),onClick:()=>V.commitDone(),children:["Done",a.jsx(Qd,{size:"xs",children:y})]})})]})})})]})})}function MBt(e,t,n){const{settleRemove:r}=Xc();g.useEffect(()=>{const s=n.current;if(!t||!s)return;const i=typeof s.getAnimations=="function"?s.getAnimations({subtree:!0}):[];if(i.length===0){r(e);return}let o=!1;return Promise.all(i.map(l=>l.finished)).then(()=>{o||r(e)}).catch(()=>{}),()=>{o=!0}},[t,e,r,n])}const DBt="flex h-control-sm w-14 shrink-0 items-center justify-center rounded-md text-column tracking-wide text-muted-foreground uppercase";function Zys({groupId:e,logic:t,className:n}){const r=Xc(),s=t==="and"?"or":"and";return a.jsx("button",{type:"button","data-slot":"filter-bar-logic","data-logic":t,"aria-label":`Joined with ${t}, switch to ${s}`,title:`Switch to ${s}`,className:Z(DBt,"filter-bar-logic cursor-pointer border border-border bg-fill-subtle outline-none","hover:bg-fill-hover hover:text-foreground focus-visible:bg-fill-hover focus-visible:text-foreground",n),onClick:()=>r.setLogic(e,s),children:t})}function Wys({groupId:e,logic:t}){const n=Xc();return a.jsx("div",{role:"radiogroup","aria-label":"Group logic",className:"flex h-control-sm items-center gap-0.5 rounded-md border border-border bg-fill-subtle p-0.5",children:["and","or"].map(r=>a.jsx("button",{type:"button",role:"radio","aria-checked":t===r,"aria-label":`Join with ${r}`,className:Z("h-full cursor-pointer rounded-sm px-1.5 text-column tracking-wide uppercase outline-none","focus-visible:bg-fill-hover",t===r?"bg-fill-hover text-foreground":"text-muted-foreground hover:text-foreground"),onClick:()=>t!==r&&n.setLogic(e,r),children:r},r))})}function LBt({group:e,depth:t,onRemove:n,removeLabel:r="Remove group",className:s}){const i=Xc(),o=g.useRef(null),l=g.useRef(!1),c=i.inputTarget===e.id,u=t<i.maxDepth;g.useEffect(()=>{c||!l.current||(l.current=!1,o.current?.focus())},[c]);const d=[],f=h=>d.length===0?a.jsx("span",{className:DBt,children:"where"},`${h}:where`):a.jsx(Zys,{groupId:e.id,logic:e.logic},`${h}:logic`);for(const h of e.nodes)d.push(a.jsxs(g.Fragment,{children:[f(h.id),hl(h)?a.jsx(Hys,{group:h,depth:t+1}):a.jsx(yx,{item:h,className:"w-fit"})]},h.id));if(i.draft&&i.draft.groupId===e.id){const{id:h,fieldId:p,operatorId:m=""}=i.draft;d.push(a.jsxs(g.Fragment,{children:[f(h),a.jsx(yx,{draft:!0,item:{id:h,fieldId:p,operatorId:m,value:""},className:"w-fit"})]},h))}return c&&d.push(a.jsxs(g.Fragment,{children:[f("input"),a.jsx(RBt,{groupId:e.id,placeholder:"Add condition…",onLeave:()=>{l.current=!0}})]},"input")),a.jsxs("div",{"data-slot":"filter-bar-group-editor","data-depth":t,role:"group","aria-label":`Conditions joined with ${e.logic}`,className:Z("flex min-w-0 flex-col",s),children:[d.length>0&&a.jsx("div",{className:"grid grid-cols-[auto_minmax(0,1fr)] items-start gap-x-2 gap-y-1.5 p-2",children:d}),a.jsxs("div",{"data-slot":"filter-bar-editor-actions",className:Z("flex w-full items-center gap-1 p-1",d.length>0&&"border-t border-border"),children:[!c&&a.jsx(de,{ref:o,variant:"ghost",size:"sm",icon:a.jsx(ys,{}),onClick:()=>i.openGroupInput(e.id),children:"Condition"}),a.jsx(de,{variant:"ghost",size:"sm",icon:a.jsx(mS,{}),className:"text-muted-foreground",tooltip:u?void 0:`Groups can nest ${i.maxDepth} levels deep`,disabled:!u,onClick:()=>i.addGroup(e.id,e.logic==="and"?"or":"and"),children:"Group"}),n&&a.jsx(de,{variant:"ghost",size:"sm",icon:a.jsx(Xo,{}),className:"ml-auto text-muted-foreground","aria-label":r,onClick:n,children:"Clear all"})]})]})}function Hys({group:e,depth:t}){const n=Xc(),r=g.useRef(null),s=n.leaving.has(e.id);MBt(e.id,s,r);const i=INe(e);return a.jsxs("div",{ref:r,"data-slot":"filter-bar-editor-nested","data-leaving":s||void 0,"aria-hidden":s||void 0,className:Z("filter-bar-editor-nested w-full overflow-hidden rounded-lg border border-border",s&&"pointer-events-none"),children:[a.jsxs("div",{className:"flex items-center gap-2 border-b border-border px-2 py-1",children:[a.jsx(fP,{className:"size-3.5 text-muted-foreground"}),a.jsx(Y,{as:"span",variant:"label",tone:"ink",children:"Group"}),a.jsxs(Y,{as:"span",variant:"label",tone:"muted",children:["· ",i," ",i===1?"condition":"conditions"]}),a.jsxs("div",{className:"ml-auto flex items-center gap-1",children:[a.jsx(Wys,{groupId:e.id,logic:e.logic}),a.jsx(de,{variant:"ghost",size:"icon-sm",tooltip:"Remove group",disabled:s,onClick:()=>n.removeGroup(e.id),children:a.jsx(Xo,{})})]})]}),a.jsx(LBt,{group:e,depth:t})]})}function zBt({group:e,className:t}){const n=Xc(),r=g.useRef(null),s=g.useRef(null),i=n.leaving.has(e.id),o=n.openGroupId===e.id,l=INe(e),c=n.items.findIndex(h=>FBt(e,h.id)),u=c===-1?n.items.length:c;MBt(e.id,i,r);const d=h=>{if(i)return;const p=Array.from(r.current?.querySelectorAll("[data-filter-bar-segment]")??[]),m=p.findIndex(v=>v===h.target);if(m!==-1)switch(h.key){case"ArrowRight":{h.preventDefault();const v=p[m+1];v?v.focus():n.focusChip(u+l,1,"field")||n.focusInput();return}case"ArrowLeft":{h.preventDefault();const v=p[m-1];v?v.focus():n.focusChip(u-1,-1,"remove");return}case"Delete":case"Backspace":h.preventDefault(),f();return}},f=()=>{n.removeGroup(e.id),n.focusAfterRemove(u)};return a.jsxs(_p,{open:o,onOpenChange:h=>n.setOpenGroup(h?e.id:null),children:[a.jsxs("div",{ref:r,role:"group","aria-label":`Advanced filter, ${l} ${l===1?"condition":"conditions"}`,"aria-hidden":i||void 0,"data-slot":"filter-bar-advanced","data-leaving":i||void 0,className:Z("filter-bar-advanced",jBt,i&&"pointer-events-none",t),onKeyDown:d,children:[a.jsxs(of,{ref:h=>{s.current=h,n.registerSegment(e.id,"field",i?null:h)},render:a.jsx("button",{type:"button"}),"data-filter-bar-segment":"field",className:Z(YI,"gap-1.5"),title:"Edit advanced filter",children:[a.jsx(Ua,{className:"size-[1.1em] shrink-0","aria-hidden":!0}),a.jsx("span",{className:"truncate",children:"Advanced filter"}),l>0&&a.jsx(Y,{as:"span",variant:"column",tone:"muted","aria-hidden":!0,children:l})]}),i?a.jsx("span",{"aria-hidden":!0,className:Z(YI,"px-1.5"),children:a.jsx(Dn,{className:"size-[1.1em]"})}):a.jsx("button",{type:"button",ref:h=>n.registerSegment(e.id,"remove",h),"data-filter-bar-segment":"remove","aria-label":"Remove advanced filter",title:"Remove advanced filter",className:Z(YI,"px-1.5"),onClick:f,children:a.jsx(Dn,{className:"size-[1.1em]"})})]}),a.jsxs(lh,{align:"start",className:"w-[min(92vw,44rem)] p-0",[ANe]:"advanced",finalFocus:s,children:[a.jsxs("div",{className:"flex items-center gap-2 border-b border-border px-3 py-2",children:[a.jsx(Ua,{className:"size-3.5 text-muted-foreground"}),a.jsx(Y,{as:"span",variant:"label",tone:"ink",children:"Advanced filter"}),a.jsx(Y,{as:"span",variant:"column",tone:"muted",className:"rounded-md bg-fill-subtle px-1.5",children:l}),a.jsx(de,{variant:"ghost",size:"icon-sm",className:"ml-auto",tooltip:"Close",onClick:()=>n.setOpenGroup(null),children:a.jsx(Dn,{})})]}),a.jsx(LBt,{group:e,depth:1,removeLabel:"Remove advanced filter",onRemove:()=>{n.setOpenGroup(null),f()}})]})]})}const FBt=(e,t)=>e.nodes.some(n=>n.id===t?!0:"kind"in n&&FBt(n,t));function Gys({label:e}){const t=Xc();return t.hasRemovableItems?a.jsx(de,{variant:"ghost",size:"icon-sm","aria-label":e,tooltip:e,onClick:n=>{n.stopPropagation(),t.clear(),t.focusInput()},children:a.jsx(Dn,{})}):null}function Kys({className:e,clearLabel:t,children:n}){const r=Xc();return a.jsxs("div",{role:"group","aria-label":r.ariaLabel,"data-slot":"filter-bar",[ANe]:"bar",className:Z("flex w-full flex-wrap items-center gap-1",e),children:[n,a.jsx("span",{className:"flex shrink-0 items-center empty:hidden",children:a.jsx(Gys,{label:t})}),a.jsx(I0,{"aria-live":"polite",children:r.announcement})]})}function nv({fields:e,operators:t,value:n,onValueChange:r,createItemId:s,maxDepth:i,"aria-label":o="Filters",clearLabel:l="Clear filters",className:c,children:u}){return a.jsx(kys,{fields:e,operators:t,value:n,onValueChange:r,createItemId:s,maxDepth:i,ariaLabel:o,children:a.jsx(Kys,{className:c,clearLabel:l,children:u})})}function Yys({renderChip:e=Xys}){const t=Xc(),n=[];for(const r of t.expression.nodes){const s=hl(r)?a.jsx(zBt,{group:r}):e(r);s!==null&&n.push(a.jsx(g.Fragment,{children:s},r.id))}if(t.draft&&!t.draft.groupId){const{id:r,fieldId:s,operatorId:i=""}=t.draft;n.push(a.jsx(g.Fragment,{children:a.jsx(yx,{draft:!0,item:{id:r,fieldId:s,operatorId:i,value:""}})},r))}return a.jsx(a.Fragment,{children:n})}const Xys=e=>a.jsx(yx,{item:e});nv.Chips=Yys;nv.Chip=yx;nv.AdvancedChip=zBt;nv.Input=RBt;const Jys=1440*60*1e3,bz=({queryOptions:e}={})=>{const t=Ye();return _t({queryKey:["observability-capabilities"],queryFn:()=>t.getObservabilityCapabilities(),retry:!1,staleTime:Jys,...e})},$J=()=>{const{data:e,isLoading:t}=bz();return{isLoading:t,enabled:!t&&(e?.capabilities.traceQuery??!0)}},exs=()=>{const{data:e,isLoading:t}=bz();return{isLoading:t,enabled:!t&&(e?.capabilities.traceQueryDiscovery??!0)}},txs=()=>{const{data:e,isLoading:t}=bz();return{isLoading:t,enabled:!t&&(e?.capabilities.traceQueryRootDuration??!1)}},nxs=()=>{const{data:e,isLoading:t}=bz();return{isLoading:t,enabled:!t&&(e?.capabilities.feedback??!0)}};function rxs(e){return e.startsWith("agent-")}function sxs(e){return e.match(/^(?:mcp_)?tool:\s*'(.*?)'/)?.[1]??e}function BBt(e){return VBt(e,[])}function VBt(e,t){if(!e)return t;for(const n of e){const r=n.stepType==="tool_call"||n.stepType==="mcp_tool_call";if(r&&n.name){const s=sxs(n.name),i="toolArgs"in n?n.toolArgs:void 0,o="toolResult"in n?n.toolResult:void 0;t.push({toolName:s,args:i??{},output:o??null,...rxs(s)?{matchArgs:"ignore"}:{}})}!r&&n.children?.length&&VBt(n.children,t)}return t}function ixs(e){const t=(()=>{try{const r=JSON.stringify(e.input);return r?r.length>40?`${r.slice(0,40)}…`:r:""}catch{return""}})(),n=vx(e.id)??e.id;return t?`${n} — ${t}`:n}function oxs({traceId:e,isOpen:t,onClose:n,level:r=2}){const s=Ye(),{data:i,isLoading:o}=_t({queryKey:["trace-trajectory",e],queryFn:()=>s.getTraceTrajectory(e??""),enabled:t&&!!e}),l=i?.steps?BBt(i.steps):[],c=l.length>0?Ky(l,2):"";return a.jsxs(xo,{dialogTitle:"Add Tool Mocks to Item",dialogDescription:"Append trace-derived tool mocks to an existing dataset item",isOpen:t,onClose:n,level:r,children:[a.jsxs(xo.Top,{children:[a.jsxs(Hd,{children:[a.jsx(Ba,{})," ",vx(e)]}),"›",a.jsxs(Hd,{children:[a.jsx(cd,{})," Add Tool Mocks to Item"]})]}),a.jsxs(xo.Content,{children:[a.jsx(xo.Header,{children:a.jsxs(xo.Heading,{children:[a.jsx(cd,{})," Add Tool Mocks to Item"]})}),o?a.jsx(Y,{as:"p",variant:"body",tone:"muted",className:"px-2 py-4",children:"Loading tool calls from trace..."}):a.jsx(axs,{initialMocksJson:c,onClose:n},e??"no-trace")]})]})}function axs({initialMocksJson:e,onClose:t}){const[n,r]=g.useState(""),[s,i]=g.useState(""),[o,l]=g.useState(e),{data:c,isLoading:u}=Sk(),d=c?.datasets??[],{data:f=[],isLoading:h}=JN({datasetId:n,queryOptions:{enabled:!!n}}),{data:p,isFetching:m}=fkt({datasetId:n,itemId:s,queryOptions:{enabled:!!n&&!!s}}),{updateItem:v}=pl(),y=(()=>{if(!o.trim())return!1;try{const S=JSON.parse(o);return Array.isArray(S)&&S.length>0}catch{return!1}})(),x=S=>{r(S),i("")},b=async S=>{if(S.preventDefault(),!n||!s){Ke.error("Please select a dataset and an item");return}let k;try{const T=o.trim()?JSON.parse(o):[];if(!Array.isArray(T)){Ke.error("Tool Mocks must be a JSON array");return}k=T}catch{Ke.error("Tool Mocks must be valid JSON");return}if(k.length===0){Ke.error("There are no tool mocks to add");return}if(!p||p.id!==s){Ke.error("Item is still loading, please try again");return}const C=[...p.toolMocks??[],...k];try{await v.mutateAsync({datasetId:n,itemId:s,toolMocks:C}),Ke.success(`Added ${k.length} tool mock(s) to the item`),t()}catch(T){Ke.error(`Failed to add tool mocks: ${T instanceof Error?T.message:"Unknown error"}`)}};return a.jsxs(Ga,{onSubmit:b,children:[a.jsxs(ft,{children:[a.jsx(ut,{required:!0,children:"Dataset"}),a.jsxs(Vr,{value:n,onValueChange:x,disabled:u,children:[a.jsx(qr,{children:a.jsx(Ur,{placeholder:u?"Loading datasets...":"Select a dataset"})}),a.jsx(Qr,{children:d.length===0?a.jsx(Y,{as:"p",variant:"body",tone:"muted",className:"px-2 py-4 text-center",children:"No datasets available"}):d.map(S=>a.jsx(ir,{value:S.id,children:S.name},S.id))})]})]}),a.jsxs(ft,{children:[a.jsx(ut,{required:!0,children:"Item"}),a.jsxs(Vr,{value:s,onValueChange:i,disabled:!n||h,children:[a.jsx(qr,{children:a.jsx(Ur,{placeholder:n?h?"Loading items...":"Select an item":"Select a dataset first"})}),a.jsx(Qr,{children:f.length===0?a.jsx(Y,{as:"p",variant:"body",tone:"muted",className:"px-2 py-4 text-center",children:"No items available"}):f.map(S=>a.jsx(ir,{value:S.id,children:ixs(S)},S.id))})]})]}),a.jsxs(ft,{children:[a.jsx(ut,{children:"Tool Mocks (JSON)"}),a.jsx(Or,{value:o,onChange:l,showCopyButton:!1,className:"min-h-40"}),a.jsx(no,{children:"Seeded from the trace's tool calls. Edit or remove entries before appending."})]}),a.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[a.jsx(de,{icon:a.jsx(Dn,{}),type:"button",onClick:t,children:"Cancel"}),a.jsx(de,{icon:a.jsx(ys,{}),type:"submit",variant:"default",disabled:v.isPending||m||!y||!n||!s||p?.id!==s,children:v.isPending?"Adding...":"Append Tool Mocks"})]})]})}function lxs(e){if(e?.input==null)return"{}";const t=e.input,r=e.spanType==="agent_run"&&t&&typeof t=="object"&&!Array.isArray(t)&&"messages"in t?t.messages??e.input:e.input;return Ky(r,2)}function cxs({traceDetails:e,rootSpanId:t,traceId:n,isOpen:r,onClose:s,level:i=2}){const o=Ye(),{data:l}=mNe({traceId:!e&&r?n:null,spanId:!e&&r?t:null,queryOptions:{enabled:!!(!e&&r&&n)&&!!(!e&&r&&t)}}),c=e??l?.span,{data:u,isLoading:d}=_t({queryKey:["trace-trajectory",n],queryFn:()=>o.getTraceTrajectory(n??""),enabled:r&&!!n}),f=u?.steps&&u.steps.length>0?Ky({steps:u.steps.map(m=>{const{name:v,stepType:y,children:x,...b}=m,S={name:v,stepType:y};for(const[k,j]of Object.entries(b))j!=null&&k!=="durationMs"&&k!=="metadata"&&(S[k]=j);return S}),ordering:"relaxed"},2):void 0,h=u?.steps?BBt(u.steps):[],p=h.length>0?Ky(h,2):void 0;return a.jsx($8t,{initialInput:lxs(c),initialGroundTruth:c?.output!=null?Ky(c.output,2):"",initialTrajectory:f,trajectoryLoading:d,initialToolMocks:p,breadcrumb:a.jsxs(Hd,{children:[a.jsx(Ba,{})," ",vx(n)]}),isOpen:r,onClose:s,level:i,source:n?{type:"trace",referenceId:n}:void 0})}const uxs={"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"},Vce="Pick a wider time range — older traces may fall outside the current window.";function dxs({datePreset:e,dateFrom:t,dateTo:n}){return e&&e!=="all"&&e!=="custom"?{title:`No traces for ${uxs[e]}`,description:Vce}:t&&n?{title:`No traces between ${os(t,"date-time")} and ${os(n,"date-time")}`,description:Vce}:t?{title:`No traces since ${os(t,"date-time")}`,description:Vce}:{title:"No traces yet",description:"Traces will appear here once agents, workflows, or tools are executed."}}const fxs=({datePreset:e,dateFrom:t,dateTo:n}={})=>{const{title:r,description:s}=dxs({datePreset:e,dateFrom:t,dateTo:n});return a.jsx(Xt,{titleSlot:r,descriptionSlot:s,variant:"fill"})};function UBt({queryOptions:e}={}){const t=Ye(),n=mr();return kn({mutationFn:({feedbackId:r,reviewStatus:s})=>t.updateFeedbackReviewStatus({feedbackId:r,reviewStatus:s}),onSuccess:()=>Promise.all([n.invalidateQueries({queryKey:["trace-feedback"]}),n.invalidateQueries({queryKey:["span-feedback"]})]),...e})}function hxs(e){return e==="needs-review"?"warning":e==="complete"||e==="reviewed"?"success":"neutral"}function DNe({status:e,children:t,...n}){return a.jsx(Mt,{size:"xs",...n,variant:hxs(e),children:t??e})}function pxs(e){const t=e.author;return t?t.name||t.email||t.id:void 0}const qBt=g.createContext(null);function eT(){const e=g.useContext(qBt);if(!e)throw new Error("Comment compounds must be rendered within Comment");return e}const mxs=pd("flex flex-col",{variants:{variant:{default:"gap-2",embed:Z(pr,"gap-1 rounded-xl p-3"),thread:""}},defaultVariants:{variant:"default"}}),QBt=g.forwardRef(({className:e,variant:t="default",...n},r)=>a.jsx(qBt.Provider,{value:t,children:a.jsx("div",{ref:r,"data-slot":"comment","data-variant":t,className:Z(mxs({variant:t}),e),...n})}));QBt.displayName="Comment";const gxs={default:"gap-3",embed:"gap-2",thread:""},ZBt=g.forwardRef(({className:e,...t},n)=>{const r=eT();return a.jsx("ul",{ref:n,"data-slot":"comment-list",className:Z("flex flex-col",gxs[r],e),...t})});ZBt.displayName="CommentList";const vxs={default:"flex flex-col gap-1",embed:"flex flex-col gap-1",thread:"relative flex gap-2 rounded-lg px-2 hover:bg-fill-subtle"},vye=g.forwardRef(({className:e,continued:t=!1,highlighted:n=!1,...r},s)=>{const i=eT(),o=i==="thread"?"div":"li";return a.jsx(o,{ref:s,"data-slot":"comment-item",className:Z("group/comment-item",vxs[i],i==="thread"&&(t?"py-0.5":"py-1.5"),n&&"bg-info-subtle",e),...r})});vye.displayName="CommentItem";const WBt=g.forwardRef(({className:e,...t},n)=>a.jsx("div",{ref:n,"data-slot":"comment-item-avatar",className:Z("w-6 shrink-0 pt-0.5",e),...t}));WBt.displayName="CommentItemAvatar";const HBt=g.forwardRef(({className:e,...t},n)=>a.jsx("div",{ref:n,"data-slot":"comment-item-content",className:Z("min-w-0 flex-1",e),...t}));HBt.displayName="CommentItemContent";const yxs={default:"flex items-center gap-2",embed:"flex items-center gap-2",thread:"flex items-baseline gap-1.5"},yye=g.forwardRef(({className:e,...t},n)=>{const r=eT();return a.jsx("div",{ref:n,"data-slot":"comment-item-header",className:Z(yxs[r],e),...t})});yye.displayName="CommentItemHeader";const xxs={default:"subheading",embed:"subheading",thread:"column"},bxs={default:"text-foreground",embed:"text-foreground",thread:"truncate text-foreground"},GBt=g.forwardRef(({className:e,...t},n)=>{const r=eT();return a.jsx(Y,{ref:n,as:"span",variant:xxs[r],"data-slot":"comment-item-author",className:Z(bxs[r],e),...t})});GBt.displayName="CommentItemAuthor";const wxs={default:"text-caption text-muted-foreground",embed:"text-caption text-muted-foreground",thread:"text-meta text-placeholder shrink-0"},KBt=g.forwardRef(({className:e,...t},n)=>{const r=eT();return a.jsx("time",{ref:n,"data-slot":"comment-item-timestamp",className:Z(wxs[r],e),...t})});KBt.displayName="CommentItemTimestamp";const Sxs={default:"body",embed:"body",thread:"caption"},kxs={default:"whitespace-pre-wrap text-foreground border-l border-border pl-3",embed:"whitespace-pre-wrap text-foreground",thread:""},YBt=g.forwardRef(({className:e,...t},n)=>{const r=eT();return ewe({defaultTagName:r==="thread"?"div":"p",props:{...t,ref:n,"data-slot":"comment-item-body",className:Z(Da({variant:Sxs[r]}),kxs[r],e)}})});YBt.displayName="CommentItemBody";const Oxs={default:"flex items-center gap-1 opacity-0 group-focus-within/comment-item:opacity-100 group-hover/comment-item:opacity-100 motion-safe:transition-opacity",embed:"",thread:"ml-auto flex shrink-0 items-center gap-0.5 self-center transition-opacity duration-200 ease-out motion-reduce:transition-none pointer-fine:opacity-0 pointer-fine:group-focus-within/comment-item:opacity-100 pointer-fine:group-hover/comment-item:opacity-100"},XBt=g.forwardRef(({className:e,...t},n)=>{const r=eT();return r==="embed"?null:a.jsx("div",{ref:n,"data-slot":"comment-item-actions",className:Z(Oxs[r],e),...t})});XBt.displayName="CommentItemActions";function jxs({status:e}){const t=e==="reviewed"?"reviewed":"needs-review";return a.jsx(DNe,{"data-slot":"feedback-review-status",status:t,children:t==="reviewed"?"Reviewed":"Needs review"})}function Cxs(e){const t=e.comment||(typeof e.value=="string"?e.value:"");return t||(e.feedbackType==="thumbs"?e.value===1?"👍":"👎":String(e.value??""))}function _xs({variant:e,items:t,onRequestDelete:n,isDeleting:r,onMarkReviewed:s,pendingFeedbackId:i}){const o=t.map((l,c)=>{const u=new Date(l.timestamp),d=pxs(l),f=d?a.jsx(FS,{name:d,src:l.author?.avatarUrl,size:"sm"}):null,h=d&&a.jsx(GBt,{children:d}),p=a.jsx(KBt,{dateTime:u.toISOString(),children:os(u,"date-time")}),m=l.feedbackId,v=a.jsx(jxs,{status:l.reviewStatus}),y=!!(s&&m&&l.reviewStatus!=="reviewed"),x=!!(n&&m),b=m&&(y||x)&&a.jsx(XBt,{children:a.jsxs(ct,{children:[a.jsx(ct.Trigger,{render:a.jsx(de,{size:"icon-sm",variant:"ghost","aria-label":"Feedback actions",children:a.jsx(jN,{})})}),a.jsxs(ct.Content,{align:"end",children:[y&&a.jsxs(ct.Item,{disabled:i===m,onSelect:()=>s?.(m),children:[a.jsx(At,{size:"xs",children:a.jsx(J3,{})}),"Mark reviewed"]}),x&&a.jsxs(ct.Item,{disabled:r,onSelect:()=>n?.(m),children:[a.jsx(At,{size:"xs",children:a.jsx(Xo,{})}),"Delete feedback"]})]})]})}),S=a.jsx(YBt,{children:Cxs(l)}),k=m??`${l.traceId}-${c}`;return e==="thread"?a.jsxs(vye,{children:[f&&a.jsx(WBt,{children:f}),a.jsxs(HBt,{children:[a.jsxs(yye,{children:[h,p,v,b]}),S]})]},k):a.jsxs(vye,{children:[a.jsxs(yye,{children:[f,h,p,v,b]}),S]},k)});return e==="thread"?a.jsx(a.Fragment,{children:o}):a.jsx(ZBt,{children:o})}function JBt({feedbackData:e,isLoadingFeedbackData:t,onPageChange:n,onSubmit:r,isSubmitting:s=!1,onDelete:i,isDeleting:o=!1,variant:l="thread",onMarkReviewed:c,pendingFeedbackId:u}){const[d,f]=g.useState(""),[h,p]=g.useState(),m=d.trim().length===0||s,v=e?.feedback??[],y=e?.pagination?.page??0,x=e?.pagination?.hasMore??!1,b=async()=>{if(!(!h||!i))try{await i(h),p(void 0)}catch{}};return a.jsxs(QBt,{variant:l,className:"min-h-0 gap-3",children:[a.jsx("form",{"aria-label":"Leave feedback",className:"flex w-full items-center gap-2",onSubmit:async S=>{if(S.preventDefault(),!m)try{await r(d.trim()),f("")}catch{}},children:a.jsxs(BNt,{size:"sm",children:[a.jsx(VNt,{"aria-label":"Leave feedback",placeholder:"Leave feedback...",value:d,onChange:S=>f(S.target.value)}),a.jsx(Hme,{align:"inline-end",children:a.jsx(UNt,{type:"submit","aria-label":"Send feedback",disabled:m,children:a.jsx(ck,{})})})]})}),a.jsx("div",{className:"min-h-0 overflow-y-auto",children:t?a.jsx(Y,{variant:"body",tone:"muted",children:"Loading feedback..."}):v.length===0?a.jsx(Y,{variant:"body",tone:"muted",className:"text-center",children:"No feedback yet"}):a.jsx(_xs,{variant:l,items:v,onRequestDelete:i?p:void 0,isDeleting:o,onMarkReviewed:c,pendingFeedbackId:u})}),(x||y>0)&&a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(de,{icon:a.jsx(cP,{}),size:"sm",variant:"ghost",disabled:y===0,onClick:()=>n?.(y-1),children:"Previous"}),a.jsx(de,{icon:a.jsx(Rc,{}),size:"sm",variant:"ghost",disabled:!x,onClick:()=>n?.(y+1),children:"Next"})]}),a.jsx(Ut,{open:h!==void 0,onOpenChange:S=>{!S&&!o&&p(void 0)},children:a.jsxs(Ut.Content,{children:[a.jsxs(Ut.Header,{children:[a.jsx(Ut.Title,{children:"Delete feedback?"}),a.jsx(Ut.Description,{children:"This permanently deletes this feedback comment. This action cannot be undone."})]}),a.jsxs(Ut.Footer,{children:[a.jsx(Ut.Cancel,{disabled:o,children:"Cancel"}),a.jsx(de,{icon:a.jsx(Xo,{}),variant:"primary",disabled:o,onClick:b,children:o?"Deleting…":"Delete"})]})]})})]})}function eVt({traceId:e,spanId:t}){const[n,r]=g.useState(0),{data:s,isLoading:i}=vNe({traceId:e,spanId:t,page:n,queryOptions:{enabled:!!e&&!!t}}),{mutateAsync:o,isPending:l}=A7t({traceId:e,spanId:t}),{mutateAsync:c,isPending:u}=P7t({traceId:e,spanId:t}),d=UBt();return a.jsx(JBt,{feedbackData:s,isLoadingFeedbackData:i,onPageChange:r,onSubmit:f=>o({text:f}),isSubmitting:l,onDelete:f=>c({feedbackId:f}),isDeleting:u,onMarkReviewed:f=>d.mutate({feedbackId:f,reviewStatus:"reviewed"}),pendingFeedbackId:d.isPending?d.variables.feedbackId:void 0})}const Txs=["type","input","duration","endTime","environment","inputTokens","outputTokens","totalTokens","estimatedCost"],LNe=["inputTokens","outputTokens","totalTokens","estimatedCost"],tVt=["traceId","threadId","resourceId","entityId"],nVt={traceId:"Trace ID",threadId:"Thread ID",resourceId:"Resource ID",entityId:"Primitive ID"},Hb={visibleColumns:["type","input","duration","estimatedCost"],customColumns:[],metadataKeys:[]},rVt=3,Exs=new Set([2,rVt]),Ixs=new Set(Txs),Nxs=new Set(LNe),Axs=new Set(tVt);function Pxs(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function $xs(e){return typeof e=="string"&&Ixs.has(e)}function Rxs(e){return typeof e=="string"&&Axs.has(e)}function Mxs(e){if(!Array.isArray(e))return[];const t=e.filter(n=>typeof n=="string").map(n=>n.trim()).filter(Boolean);return[...new Set(t)]}function Dxs(e){if(!e)return Hb;try{const t=JSON.parse(e);if(!Pxs(t)||!Exs.has(t.version))return Hb;const n=Array.isArray(t.visibleColumns)?[...new Set(t.visibleColumns.filter($xs))]:[...Hb.visibleColumns],r=Array.isArray(t.customColumns)?[...new Set(t.customColumns.filter(Rxs))]:[];return{visibleColumns:n,customColumns:r,metadataKeys:Mxs(t.metadataKeys)}}catch{return Hb}}function Lxs(e){return JSON.stringify({version:rVt,visibleColumns:e.visibleColumns,customColumns:e.customColumns,metadataKeys:e.metadataKeys})}function zxs(e){const t=new Set(e.visibleColumns),n=["startTime"];t.has("type")&&n.push("type"),n.push("name"),t.has("input")&&n.push("input"),n.push("status");for(const r of["duration","endTime","environment",...LNe])t.has(r)&&n.push(r);return n.push(...e.customColumns.map(r=>`custom:${r}`)),n.push(...e.metadataKeys.map(r=>`metadata:${r}`)),n}function sVt(e){const t=new Set(e.visibleColumns),n=["11rem"];t.has("type")&&n.push("7rem"),n.push(t.has("input")?"14rem":"minmax(8rem,1fr)"),t.has("input")&&n.push("minmax(8rem,1fr)"),n.push("6rem"),t.has("duration")&&n.push("7rem"),t.has("endTime")&&n.push("11rem"),t.has("environment")&&n.push("8rem"),t.has("inputTokens")&&n.push("8rem"),t.has("outputTokens")&&n.push("8rem"),t.has("totalTokens")&&n.push("8rem"),t.has("estimatedCost")&&n.push("8rem");for(const r of e.customColumns)n.push("minmax(8rem,14rem)");for(const r of e.metadataKeys)n.push("minmax(8rem,14rem)");return n.join(" ")}const Fxs=/^(?:agent|workflow|scorer) run: '(.+?)'(.*)$/;function Bxs(e){return e&&e.replace(Fxs,"$1$2")}function Vxs(e,t){if(!e||!Object.prototype.hasOwnProperty.call(e,t))return;const n=e[t];if(n!=null){if(typeof n=="string")return n;if(typeof n=="number"||typeof n=="boolean"||typeof n=="bigint")return String(n);try{return JSON.stringify(n)??void 0}catch{return}}}function Oc(e,t){return e.visibleColumns.includes(t)}function Uxs(e){return e.visibleColumns.some(iVt)}function iVt(e){return Nxs.has(e)}const qxs=[],Qxs=["type","input","duration","endTime","environment"],jet={type:"Primitive type",input:"Input",duration:"Duration",endTime:"End",environment:"Environment",inputTokens:"Input tokens",outputTokens:"Output tokens",totalTokens:"Total tokens",estimatedCost:"Estimated cost"};function Zxs({preferences:e,availableMetadataKeys:t=qxs,usageDisabledReason:n,withQueryTrace:r=!0,onToggleColumn:s,onAddCustomColumn:i,onRemoveCustomColumn:o,onAddMetadataColumn:l,onRemoveMetadataColumn:c,onReset:u}){const[d,f]=g.useState(!1),[h,p]=g.useState(""),[m,v]=g.useState(),y=g.useMemo(()=>{const S=t.filter(k=>!e.metadataKeys.includes(k));return h&&!S.includes(h)&&S.push(h),S.map(k=>({label:k,value:k}))},[t,e.metadataKeys,h]),x=S=>{f(S),S||(p(""),v(void 0))},b=S=>{S.preventDefault();const k=h.trim();if(!k){v("Enter a metadata key.");return}if(e.metadataKeys.includes(k)){v("That metadata column is already visible.");return}l(k),x(!1)};return a.jsxs(a.Fragment,{children:[a.jsxs(ct,{children:[a.jsx(ct.Trigger,{render:a.jsx(de,{variant:"ghost",size:"md",icon:a.jsx(Wft,{"aria-hidden":!0}),children:"Columns"})}),a.jsxs(ct.Content,{align:"end",className:"min-w-56",children:[a.jsx(ct.Label,{children:"Standard columns"}),Qxs.map(S=>a.jsx(ct.CheckboxItem,{checked:e.visibleColumns.includes(S),onCheckedChange:()=>s(S),children:jet[S]},S)),a.jsx(ct.Separator,{}),a.jsx(ct.Label,{children:"Usage columns"}),LNe.map(S=>a.jsx(ct.CheckboxItem,{checked:e.visibleColumns.includes(S),disabled:!!n,onCheckedChange:()=>s(S),children:jet[S]},S)),n&&a.jsx(Y,{variant:"meta",tone:"faint",className:"px-2 py-1",role:"note",children:n}),a.jsx(ct.Separator,{}),a.jsx(ct.Label,{children:"Custom columns"}),tVt.map(S=>{const k=e.customColumns.includes(S);return a.jsx(ct.CheckboxItem,{checked:k,onCheckedChange:()=>k?o(S):i(S),children:nVt[S]},S)}),(r||e.metadataKeys.length>0)&&a.jsxs(a.Fragment,{children:[a.jsx(ct.Separator,{}),a.jsx(ct.Label,{children:"Metadata columns"}),e.metadataKeys.map(S=>a.jsx(ct.CheckboxItem,{checked:!0,title:S,onCheckedChange:()=>c(S),children:S},S)),r&&a.jsxs(ct.Item,{onSelect:()=>f(!0),children:[a.jsx(ys,{"aria-hidden":!0}),"Add metadata column"]})]}),a.jsx(ct.Separator,{}),a.jsx(ct.Item,{onSelect:u,children:"Reset to defaults"})]})]}),r&&a.jsx(rs,{open:d,onOpenChange:x,children:a.jsx(ss,{children:a.jsxs(Ga,{onSubmit:b,className:"gap-0",children:[a.jsxs(es,{children:[a.jsx(Gr,{children:"Add metadata column"}),a.jsx(zo,{children:"Pick a top-level trace metadata key observed in the current time range, or type one. Only the key is saved, never its values."})]}),a.jsx(Hr,{children:a.jsxs(ft,{invalid:!!m,children:[a.jsx(ut,{children:"Metadata key"}),a.jsx(Qa,{options:y,value:h,onValueChange:S=>{p(S),v(void 0)},allowCustomValue:!0,placeholder:"Select a metadata key…",searchPlaceholder:"Search metadata keys…",emptyText:"No metadata keys observed. Type one to add it."}),a.jsx(is,{children:m})]})}),a.jsxs(Yo,{children:[a.jsx(Ca,{children:"Cancel"}),a.jsx(ja,{type:"submit",children:"Add column"})]})]})})})]})}function dW({traceId:e,variant:t}){const[n,r]=g.useState(0),{data:s,isLoading:i}=_J({traceId:e,page:n,queryOptions:{enabled:!!e}}),{mutateAsync:o,isPending:l}=A7t({traceId:e}),{mutateAsync:c,isPending:u}=P7t({traceId:e}),d=UBt();return a.jsx(JBt,{feedbackData:s,isLoadingFeedbackData:i,onPageChange:r,onSubmit:f=>o({text:f}),isSubmitting:l,onDelete:f=>c({feedbackId:f}),isDeleting:u,variant:t,onMarkReviewed:f=>d.mutate({feedbackId:f,reviewStatus:"reviewed"}),pendingFeedbackId:d.isPending?d.variables.feedbackId:void 0})}const zA="timeRange",xye={id:zA,label:"Time",icon:Z7t(zA),color:SNe(),type:"text",operators:["is"],hidden:!0},fW={id:zA,fieldId:zA,operatorId:"is",value:""},Wxs=e=>e instanceof HTMLElement&&e.hasAttribute("data-filter-bar-segment");function Hxs(e){const t=Xc();return a.jsxs(yx,{item:fW,removable:!1,children:[a.jsx("span",{className:Z(AJ,"text-foreground"),style:gye(xye),children:a.jsx(PJ,{field:xye})}),a.jsx("div",{className:"contents",onKeyDown:n=>{Wxs(n.target)||n.stopPropagation()},children:a.jsx(MY,{...e,renderTrigger:({label:n,disabled:r})=>a.jsx("button",{type:"button",ref:s=>t.registerSegment(fW.id,"value",s),"data-filter-bar-segment":"",disabled:r,"aria-label":`Value: ${n}`,title:n,className:YI,children:a.jsx("span",{className:"truncate",children:n})})})})]})}function zNe({error:e,resource:t,errorTitle:n}){if(js(e))return a.jsx(ai,{});if(Cs(e))return a.jsx(Gs,{resource:t});const r=e instanceof Error?Q5r(e):void 0;return a.jsx(Xt,{tone:"error",titleSlot:n,descriptionSlot:r?.error??"Unknown error"})}function Gxs(e,t,n){const r=new Array(e);return new Proxy(r,{get(s,i,o){if(typeof i=="string"){const l=i.charCodeAt(0);if(l>=48&&l<=57){const c=+i;if(Number.isInteger(c)&&c>=0&&c<e){let u=s[c];if(!u){const d=t[c*2];u=s[c]={index:c,key:n(c),start:d,size:t[c*2+1],end:d+t[c*2+1],lane:0}}return u}}if(i==="length")return e}return Reflect.get(s,i,o)}})}function pE(e,t,n){let r=n.initialDeps??[],s,i=!0;function o(){const l=e();return(l.length!==r.length||l.some((u,d)=>r[d]!==u))&&(r=l,s=t(...l),n?.onChange&&!(i&&n.skipInitialOnChange)&&n.onChange(s),i=!1),s}return o.updateDeps=l=>{r=l},o}function Cet(e,t){if(e===void 0)throw new Error("Unexpected undefined");return e}const Kxs=(e,t)=>Math.abs(e-t)<1.01,Yxs=(e,t,n)=>{let r;return function(...s){e.clearTimeout(r),r=e.setTimeout(()=>t.apply(this,s),n)}};let _M;const Uce=()=>{if(_M!==void 0)return _M;if(typeof navigator>"u")return _M=!1;if(/iP(hone|od|ad)/.test(navigator.userAgent))return _M=!0;const e=navigator.maxTouchPoints;return _M=navigator.platform==="MacIntel"&&e!==void 0&&e>0},_et=e=>{const{offsetWidth:t,offsetHeight:n}=e;return{width:t,height:n}},Xxs=e=>e,Jxs=e=>{const t=Math.max(e.startIndex-e.overscan,0),r=Math.min(e.endIndex+e.overscan,e.count-1)-t+1,s=new Array(r);for(let i=0;i<r;i++)s[i]=t+i;return s},ebs=(e,t)=>{const n=e.scrollElement;if(!n)return;const r=e.targetWindow;if(!r)return;const s=o=>{const{width:l,height:c}=o;t({width:Math.round(l),height:Math.round(c)})};if(s(_et(n)),!r.ResizeObserver)return()=>{};const i=new r.ResizeObserver(o=>{const l=()=>{const c=o[0];if(c?.borderBoxSize){const u=c.borderBoxSize[0];if(u){s({width:u.inlineSize,height:u.blockSize});return}}s(_et(n))};e.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(l):l()});return i.observe(n,{box:"border-box"}),()=>{i.unobserve(n)}},hW={passive:!0},tbs=typeof window>"u"?!0:"onscrollend"in window,nbs=(e,t,n)=>{const r=e.scrollElement;if(!r)return;const s=e.targetWindow;if(!s)return;const i=e.options.useScrollendEvent&&tbs;let o=0;const l=i?null:Yxs(s,()=>t(o,!1),e.options.isScrollingResetDelay),c=f=>()=>{o=n(r),l?.(),t(o,f)},u=c(!0),d=c(!1);return r.addEventListener("scroll",u,hW),i&&r.addEventListener("scrollend",d,hW),()=>{r.removeEventListener("scroll",u),i&&r.removeEventListener("scrollend",d)}},rbs=(e,t)=>nbs(e,t,n=>{const{horizontal:r,isRtl:s}=e.options;return r?n.scrollLeft*(s&&-1||1):n.scrollTop}),sbs=(e,t,n)=>{if(n.options.useCachedMeasurements){const r=n.indexFromElement(e),s=n.options.getItemKey(r);return n.itemSizeCache.get(s)??n.options.estimateSize(r)}if(t?.borderBoxSize){const r=t.borderBoxSize[0];if(r)return Math.round(r[n.options.horizontal?"inlineSize":"blockSize"])}if(!t){const r=n.indexFromElement(e),s=n.options.getItemKey(r),i=n.itemSizeCache.get(s);if(i!==void 0)return i}return e[n.options.horizontal?"offsetWidth":"offsetHeight"]},ibs=(e,{adjustments:t=0,behavior:n},r)=>{var s,i;(i=(s=r.scrollElement)==null?void 0:s.scrollTo)==null||i.call(s,{[r.options.horizontal?"left":"top"]:e+t,behavior:n})},obs=ibs;class abs{constructor(t){this.unsubs=[],this.scrollElement=null,this.targetWindow=null,this.isScrolling=!1,this.scrollState=null,this.measurementsCache=[],this._flatMeasurements=null,this.itemSizeCache=new Map,this.itemSizeCacheVersion=0,this.laneAssignments=new Map,this.pendingMin=null,this.prevLanes=void 0,this.lanesChangedFlag=!1,this.lanesSettling=!1,this.pendingScrollAnchor=null,this.scrollRect=null,this.scrollOffset=null,this.scrollDirection=null,this.scrollAdjustments=0,this._iosDeferredAdjustment=0,this._iosTouching=!1,this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._intendedScrollOffset=null,this.elementsCache=new Map,this.now=()=>{var n,r,s;return((s=(r=(n=this.targetWindow)==null?void 0:n.performance)==null?void 0:r.now)==null?void 0:s.call(r))??Date.now()},this.observer=(()=>{let n=null;const r=()=>n||(!this.targetWindow||!this.targetWindow.ResizeObserver?null:n=new this.targetWindow.ResizeObserver(s=>{s.forEach(i=>{const o=()=>{const l=i.target,c=this.indexFromElement(l);if(!l.isConnected){this.observer.unobserve(l);for(const[u,d]of this.elementsCache)if(d===l){this.elementsCache.delete(u);break}return}this.shouldMeasureDuringScroll(c)&&this.resizeItem(c,this.options.measureElement(l,i,this))};this.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(o):o()})}));return{disconnect:()=>{var s;(s=r())==null||s.disconnect(),n=null},observe:s=>{var i;return(i=r())==null?void 0:i.observe(s,{box:"border-box"})},unobserve:s=>{var i;return(i=r())==null?void 0:i.unobserve(s)}}})(),this.range=null,this.setOptions=n=>{var r,s;const i={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:Xxs,rangeExtractor:Jxs,onChange:()=>{},measureElement:sbs,initialRect:{width:0,height:0},scrollMargin:0,gap:0,indexAttribute:"data-index",initialMeasurementsCache:[],lanes:1,anchorTo:"start",followOnAppend:!1,scrollEndThreshold:1,isScrollingResetDelay:150,enabled:!0,isRtl:!1,useScrollendEvent:!1,useAnimationFrameWithResizeObserver:!1,laneAssignmentMode:"estimate",useCachedMeasurements:!1};for(const h in n){const p=n[h];p!==void 0&&(i[h]=p)}const o=this.options;let l=null,c=null,u=!1;if(o!==void 0&&o.enabled&&i.enabled&&i.anchorTo==="end"&&this.scrollElement!==null){const h=o.count,p=i.count,m=this.getMeasurements(),v=h>0?((r=m[0])==null?void 0:r.key)??o.getItemKey(0):null,y=h>0?((s=m[h-1])==null?void 0:s.key)??o.getItemKey(h-1):null;if(p!==h||h>0&&p>0&&(i.getItemKey(0)!==v||i.getItemKey(p-1)!==y)){u=!0;const S=h>0?this.getVirtualItemForOffset(this.getScrollOffset())??m[0]:null;S&&(l=[S.key,this.getScrollOffset()-S.start]);const k=i.followOnAppend===!0?"auto":i.followOnAppend||null;k&&p>h&&this.isAtEnd(o.scrollEndThreshold)&&(h===0||i.getItemKey(p-1)!==y)&&(c=k)}}this.options=i,u&&(this.pendingMin=0,this.itemSizeCacheVersion++);let d=!1,f=0;if(l&&this.scrollOffset!==null){const[h,p]=l,m=this.getMeasurements(),{count:v,getItemKey:y}=this.options;let x=0;for(;x<v&&y(x)!==h;)x++;if(x<v){const b=m[x];if(b){const S=b.start+p;S!==this.scrollOffset&&(f=S-this.scrollOffset,this.scrollOffset=S,d=!0)}}}(d||c)&&(this.pendingScrollAnchor=[d?l[0]:null,d?l[1]:0,c,f])},this.notify=n=>{var r,s;(s=(r=this.options).onChange)==null||s.call(r,this,n)},this.maybeNotify=pE(()=>(this.calculateRange(),[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]),n=>{this.notify(n)},{key:!1,debug:()=>this.options.debug,initialDeps:[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]}),this.cleanup=()=>{this.unsubs.filter(Boolean).forEach(n=>n()),this.unsubs=[],this.observer.disconnect(),this.rafId!=null&&this.targetWindow&&(this.targetWindow.cancelAnimationFrame(this.rafId),this.rafId=null),this.scrollState=null,this.scrollElement=null,this.targetWindow=null},this._didMount=()=>()=>{this.cleanup()},this._willUpdate=()=>{var n;const r=this.options.enabled?this.options.getScrollElement():null;if(this.scrollElement!==r){if(this.cleanup(),!r){this.maybeNotify();return}if(this.scrollElement=r,this.scrollElement&&"ownerDocument"in this.scrollElement?this.targetWindow=this.scrollElement.ownerDocument.defaultView:this.targetWindow=((n=this.scrollElement)==null?void 0:n.window)??null,this.elementsCache.forEach(i=>{this.observer.observe(i)}),this.unsubs.push(this.options.observeElementRect(this,i=>{this.scrollRect=i,this.maybeNotify()})),this.unsubs.push(this.options.observeElementOffset(this,(i,o)=>{if(o&&this._intendedScrollOffset===null&&i===this.scrollOffset)return;this._intendedScrollOffset!==null&&Math.abs(i-this._intendedScrollOffset)<1.5&&(i=this._intendedScrollOffset),this._intendedScrollOffset=null,this.scrollAdjustments=0;const l=this.getScrollOffset();this.scrollDirection=o?l===i?this.scrollDirection:l<i?"forward":"backward":null,this.scrollOffset=i,this.isScrolling=o,this._flushIosDeferredIfReady(),this.scrollState&&this.scheduleScrollReconcile(),this.maybeNotify()})),"addEventListener"in this.scrollElement){const i=this.scrollElement,o=()=>{this._iosTouching=!0,this._iosJustTouchEnded=!1,this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)},l=()=>{this._iosTouching=!1,!(!Uce()||this.targetWindow==null)&&(this._iosJustTouchEnded=!0,this._iosTouchEndTimerId=this.targetWindow.setTimeout(()=>{this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._flushIosDeferredIfReady()},150))};i.addEventListener("touchstart",o,hW),i.addEventListener("touchend",l,hW),this.unsubs.push(()=>{i.removeEventListener("touchstart",o),i.removeEventListener("touchend",l),this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)})}this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})}const s=this.pendingScrollAnchor;if(this.pendingScrollAnchor=null,s&&this.scrollElement&&this.options.enabled){const[i,o,l,c]=s;i!==null&&!l&&(Uce()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded)?c!==0&&(this._iosDeferredAdjustment+=c):this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})),l&&this.scrollToEnd({behavior:l})}},this._flushIosDeferredIfReady=()=>{if(this._iosDeferredAdjustment===0||this.isScrolling||this._iosTouching||this._iosJustTouchEnded)return;const n=this.getScrollOffset(),r=this.getMaxScrollOffset();if(n<0||n>r)return;const s=this._iosDeferredAdjustment;this._iosDeferredAdjustment=0,this._scrollToOffset(n,{adjustments:this.scrollAdjustments+=s,behavior:void 0})},this.rafId=null,this.getSize=()=>this.options.enabled?(this.scrollRect=this.scrollRect??this.options.initialRect,this.scrollRect[this.options.horizontal?"width":"height"]):(this.scrollRect=null,0),this.getScrollOffset=()=>this.options.enabled?(this.scrollOffset=this.scrollOffset??(typeof this.options.initialOffset=="function"?this.options.initialOffset():this.options.initialOffset),this.scrollOffset):(this.scrollOffset=null,0),this.getFurthestMeasurement=(n,r)=>{const s=new Map,i=new Map;for(let o=r-1;o>=0;o--){const l=n[o];if(s.has(l.lane))continue;const c=i.get(l.lane);if(c==null||l.end>c.end?i.set(l.lane,l):l.end<c.end&&s.set(l.lane,!0),s.size===this.options.lanes)break}return i.size===this.options.lanes?Array.from(i.values()).sort((o,l)=>o.end===l.end?o.index-l.index:o.end-l.end)[0]:void 0},this.getMeasurementOptions=pE(()=>[this.options.count,this.options.paddingStart,this.options.scrollMargin,this.options.getItemKey,this.options.enabled,this.options.lanes,this.options.laneAssignmentMode],(n,r,s,i,o,l,c)=>(this.prevLanes!==void 0&&this.prevLanes!==l&&(this.lanesChangedFlag=!0),this.prevLanes=l,this.pendingMin=null,{count:n,paddingStart:r,scrollMargin:s,getItemKey:i,enabled:o,lanes:l,laneAssignmentMode:c}),{key:!1}),this.getMeasurements=pE(()=>[this.getMeasurementOptions(),this.itemSizeCacheVersion],({count:n,paddingStart:r,scrollMargin:s,getItemKey:i,enabled:o,lanes:l,laneAssignmentMode:c},u)=>{const d=this.itemSizeCache;if(!o)return this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),[];if(this.laneAssignments.size>n)for(const m of this.laneAssignments.keys())m>=n&&this.laneAssignments.delete(m);this.lanesChangedFlag&&(this.lanesChangedFlag=!1,this.lanesSettling=!0,this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),this.pendingMin=null),this.measurementsCache.length===0&&!this.lanesSettling&&(this.measurementsCache=this.options.initialMeasurementsCache,this.measurementsCache.forEach(m=>{this.itemSizeCache.set(m.key,m.size)}));const f=this.lanesSettling?0:this.pendingMin??0;if(this.pendingMin=null,this.lanesSettling&&this.measurementsCache.length===n&&(this.lanesSettling=!1),l===1){const m=this.options.gap,v=n*2;let y=this._flatMeasurements;if(!y||y.length<v){const S=new Float64Array(v);y&&f>0&&S.set(y.subarray(0,f*2)),y=S,this._flatMeasurements=y}let x;if(f===0)x=r+s;else{const S=f-1;x=y[S*2]+y[S*2+1]+m}for(let S=f;S<n;S++){const k=i(S),j=d.get(k),C=typeof j=="number"?j:this.options.estimateSize(S);y[S*2]=x,y[S*2+1]=C,x+=C+m}const b=Gxs(n,y,i);return this.measurementsCache=b,b}const h=this.measurementsCache.slice(0,f),p=new Array(l).fill(void 0);for(let m=0;m<f;m++){const v=h[m];v&&(p[v.lane]=m)}for(let m=f;m<n;m++){const v=i(m),y=this.laneAssignments.get(m);let x,b;const S=c==="estimate"||d.has(v);if(y!==void 0&&this.options.lanes>1){x=y;const T=p[x],_=T!==void 0?h[T]:void 0;b=_?_.end+this.options.gap:r+s}else{const T=this.options.lanes===1?h[m-1]:this.getFurthestMeasurement(h,m);b=T?T.end+this.options.gap:r+s,x=T?T.lane:m%this.options.lanes,this.options.lanes>1&&S&&this.laneAssignments.set(m,x)}const k=d.get(v),j=typeof k=="number"?k:this.options.estimateSize(m),C=b+j;h[m]={index:m,start:b,size:j,end:C,key:v,lane:x},p[x]=m}return this.measurementsCache=h,h},{key:!1,debug:()=>this.options.debug}),this.calculateRange=pE(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(n,r,s,i)=>n.length===0||r===0?(this.range=null,null):(this.range=cbs(n,r,s,i,i===1&&this._flatMeasurements!=null?this._flatMeasurements:null),this.range),{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=pE(()=>{let n=null,r=null;const s=this.calculateRange();return s&&(n=s.startIndex,r=s.endIndex),this.maybeNotify.updateDeps([this.isScrolling,n,r]),[this.options.rangeExtractor,this.options.overscan,this.options.count,n,r]},(n,r,s,i,o)=>i===null||o===null?[]:n({startIndex:i,endIndex:o,overscan:r,count:s}),{key:!1,debug:()=>this.options.debug}),this.indexFromElement=n=>{const r=this.options.indexAttribute,s=n.getAttribute(r);return s?parseInt(s,10):(console.warn(`Missing attribute name '${r}={index}' on measured element.`),-1)},this.shouldMeasureDuringScroll=n=>{var r;if(!this.scrollState||this.scrollState.behavior!=="smooth")return!0;const s=this.scrollState.index??((r=this.getVirtualItemForOffset(this.scrollState.lastTargetOffset))==null?void 0:r.index);if(s!==void 0&&this.range){const i=Math.max(this.options.overscan,Math.ceil((this.range.endIndex-this.range.startIndex)/2)),o=Math.max(0,s-i),l=Math.min(this.options.count-1,s+i);return n>=o&&n<=l}return!0},this.measureElement=n=>{if(!n){this.elementsCache.forEach((o,l)=>{o.isConnected||(this.observer.unobserve(o),this.elementsCache.delete(l))});return}const r=this.indexFromElement(n),s=this.options.getItemKey(r),i=this.elementsCache.get(s);i!==n&&(i&&this.observer.unobserve(i),this.observer.observe(n),this.elementsCache.set(s,n)),(!this.isScrolling||this.scrollState)&&this.shouldMeasureDuringScroll(r)&&this.resizeItem(r,this.options.measureElement(n,void 0,this))},this.resizeItem=(n,r)=>{var s,i;if(n<0||n>=this.options.count)return;let o,l,c;const u=this._flatMeasurements;if(this.options.lanes===1&&u!==null)c=this.options.getItemKey(n),l=u[n*2],o=u[n*2+1];else{const h=this.measurementsCache[n];if(!h)return;c=h.key,l=h.start,o=h.size}const d=this.itemSizeCache.get(c)??o,f=r-d;if(f!==0){const h=this.options.anchorTo==="end"&&((s=this.scrollState)==null?void 0:s.behavior)!=="smooth"&&this.getVirtualDistanceFromEnd()<=this.options.scrollEndThreshold,p=h?this.getTotalSize():0,m=((i=this.scrollState)==null?void 0:i.behavior)!=="smooth"&&(this.shouldAdjustScrollPositionOnItemSizeChange!==void 0?this.shouldAdjustScrollPositionOnItemSizeChange(this.measurementsCache[n]??{index:n,key:c,start:l,size:o,end:l+o,lane:0},f,this):l<this.getScrollOffset()+this.scrollAdjustments&&(!this.itemSizeCache.has(c)||this.scrollDirection!=="backward"));(this.pendingMin===null||n<this.pendingMin)&&(this.pendingMin=n),this.itemSizeCache.set(c,r),this.itemSizeCacheVersion++,h?this.applyScrollAdjustment(this.getTotalSize()-p):m&&this.applyScrollAdjustment(f),this.notify(!1)}},this.getVirtualItems=pE(()=>[this.getVirtualIndexes(),this.getMeasurements()],(n,r)=>{const s=[];for(let i=0,o=n.length;i<o;i++){const l=n[i],c=r[l];s.push(c)}return s},{key:!1,debug:()=>this.options.debug}),this.getVirtualItemForOffset=n=>{const r=this.getMeasurements();if(r.length===0)return;const s=this._flatMeasurements,i=this.options.lanes===1&&s!=null,o=oVt(0,r.length-1,i?l=>s[l*2]:l=>Cet(r[l]).start,n);return Cet(r[o])},this.getMaxScrollOffset=()=>{if(!this.scrollElement)return 0;if("scrollHeight"in this.scrollElement)return this.options.horizontal?this.scrollElement.scrollWidth-this.scrollElement.clientWidth:this.scrollElement.scrollHeight-this.scrollElement.clientHeight;{const n=this.scrollElement.document.documentElement;return this.options.horizontal?n.scrollWidth-this.scrollElement.innerWidth:n.scrollHeight-this.scrollElement.innerHeight}},this.getVirtualDistanceFromEnd=()=>Math.max(this.getTotalSize()-this.getSize()-this.getScrollOffset(),0),this.getDistanceFromEnd=()=>Math.max(this.getMaxScrollOffset()-this.getScrollOffset(),0),this.isAtEnd=(n=this.options.scrollEndThreshold)=>this.getDistanceFromEnd()<=n,this.getOffsetForAlignment=(n,r,s=0)=>{if(!this.scrollElement)return 0;const i=this.getSize(),o=this.getScrollOffset();r==="auto"&&(r=n>=o+i?"end":"start"),r==="center"?n+=(s-i)/2:r==="end"&&(n-=i);const l=this.getMaxScrollOffset();return Math.max(Math.min(l,n),0)},this.getOffsetForIndex=(n,r="auto")=>{n=Math.max(0,Math.min(n,this.options.count-1));const s=this.getSize(),i=this.getScrollOffset(),o=this.measurementsCache[n];if(!o)return;if(r==="auto")if(o.end>=i+s-this.options.scrollPaddingEnd)r="end";else if(o.start<=i+this.options.scrollPaddingStart)r="start";else return[i,r];if(r==="end"&&n===this.options.count-1)return[this.getMaxScrollOffset(),r];const l=r==="end"?o.end+this.options.scrollPaddingEnd:o.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(l,r,o.size),r]},this.scrollToOffset=(n,{align:r="start",behavior:s="auto"}={})=>{const i=this.getOffsetForAlignment(n,r),o=this.now();this.scrollState={index:null,align:r,behavior:s,startedAt:o,lastTargetOffset:i,stableFrames:0},this._scrollToOffset(i,{adjustments:void 0,behavior:s}),this.scheduleScrollReconcile()},this.scrollToIndex=(n,{align:r="auto",behavior:s="auto"}={})=>{n=Math.max(0,Math.min(n,this.options.count-1));const i=this.getOffsetForIndex(n,r);if(!i)return;const[o,l]=i,c=this.now();this.scrollState={index:n,align:l,behavior:s,startedAt:c,lastTargetOffset:o,stableFrames:0},this._scrollToOffset(o,{adjustments:void 0,behavior:s}),this.scheduleScrollReconcile()},this.scrollBy=(n,{behavior:r="auto"}={})=>{const s=this.getScrollOffset()+n,i=this.now();this.scrollState={index:null,align:"start",behavior:r,startedAt:i,lastTargetOffset:s,stableFrames:0},this._scrollToOffset(s,{adjustments:void 0,behavior:r}),this.scheduleScrollReconcile()},this.scrollToEnd=({behavior:n="auto"}={})=>{if(this.options.count>0){this.scrollToIndex(this.options.count-1,{align:"end",behavior:n});return}this.scrollToOffset(Math.max(this.getTotalSize()-this.getSize(),0),{behavior:n})},this.getTotalSize=()=>{var n;const r=this.getMeasurements();let s;if(r.length===0)s=this.options.paddingStart;else if(this.options.lanes===1){const i=r.length-1,o=this._flatMeasurements;o!=null?s=o[i*2]+o[i*2+1]:s=((n=r[i])==null?void 0:n.end)??0}else{const i=Array(this.options.lanes).fill(null);let o=r.length-1;for(;o>=0&&i.some(l=>l===null);){const l=r[o];i[l.lane]===null&&(i[l.lane]=l.end),o--}s=Math.max(...i.filter(l=>l!==null))}return Math.max(s-this.options.scrollMargin+this.options.paddingEnd,0)},this.takeSnapshot=()=>{const n=[];if(this.itemSizeCache.size===0)return n;const r=this.getMeasurements();for(const s of r)s&&this.itemSizeCache.has(s.key)&&n.push({index:s.index,key:s.key,start:s.start,size:s.size,end:s.end,lane:s.lane});return n},this._scrollToOffset=(n,{adjustments:r,behavior:s})=>{this._intendedScrollOffset=n+(r??0),this.options.scrollToFn(n,{behavior:s,adjustments:r},this)},this.measure=()=>{this.pendingMin=null,this.itemSizeCache.clear(),this.laneAssignments.clear(),this.itemSizeCacheVersion++,this.notify(!1)},this.setOptions(t)}applyScrollAdjustment(t,n){t!==0&&(Uce()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded)?this._iosDeferredAdjustment+=t:(this._scrollToOffset(this.getScrollOffset(),{adjustments:this.scrollAdjustments+=t,behavior:n}),this.scrollOffset!==null&&(this.scrollOffset+=this.scrollAdjustments,this.scrollAdjustments=0)))}scheduleScrollReconcile(){if(!this.targetWindow){this.scrollState=null;return}this.rafId==null&&(this.rafId=this.targetWindow.requestAnimationFrame(()=>{this.rafId=null,this.reconcileScroll()}))}reconcileScroll(){if(!this.scrollState||!this.scrollElement)return;if(this.now()-this.scrollState.startedAt>5e3){this.scrollState=null;return}const r=this.scrollState.index!=null?this.getOffsetForIndex(this.scrollState.index,this.scrollState.align):void 0,s=r?r[0]:this.scrollState.lastTargetOffset,i=1,o=s!==this.scrollState.lastTargetOffset;if(!o&&Kxs(s,this.getScrollOffset())){if(this.scrollState.stableFrames++,this.scrollState.stableFrames>=i){this.getScrollOffset()!==s&&this._scrollToOffset(s,{adjustments:void 0,behavior:"auto"}),this.scrollState=null;return}}else if(this.scrollState.stableFrames=0,o){const l=this.getSize()||600,c=Math.abs(s-this.getScrollOffset()),u=this.scrollState.behavior==="smooth"&&c>l;this.scrollState.lastTargetOffset=s,u||(this.scrollState.behavior="auto"),this._scrollToOffset(s,{adjustments:void 0,behavior:u?"smooth":"auto"})}this.scheduleScrollReconcile()}}const oVt=(e,t,n,r)=>{for(;e<=t;){const s=(e+t)/2|0,i=n(s);if(i<r)e=s+1;else if(i>r)t=s-1;else return s}return e>0?e-1:0};function lbs(e,t,n){let r=0;for(;r<=t;){const s=(r+t)/2|0,i=e[s*2];if(i<n)r=s+1;else if(i>n)t=s-1;else return s}return r>0?r-1:0}function cbs(e,t,n,r,s){const i=e.length-1;if(e.length<=r)return{startIndex:0,endIndex:i};if(r===1&&s!==null){const u=lbs(s,i,n);let d=u;const f=n+t;for(;d<i&&s[d*2]+s[d*2+1]<f;)d++;return{startIndex:u,endIndex:d}}let l=oVt(0,i,u=>e[u].start,n),c=l;if(r===1)for(;c<i&&e[c].end<n+t;)c++;else if(r>1){const u=Array(r).fill(0);for(;c<i&&u.some(f=>f<n+t);){const f=e[c];u[f.lane]=f.end,c++}const d=Array(r).fill(n+t);for(;l>=0&&d.some(f=>f>=n);){const f=e[l];d[f.lane]=f.start,l--}l=Math.max(0,l-l%r),c=Math.min(i,c+(r-1-c%r))}return{startIndex:l,endIndex:c}}const qce=typeof document<"u"?g.useLayoutEffect:g.useEffect;function ubs({useFlushSync:e=!0,directDomUpdates:t=!1,directDomUpdatesMode:n="transform",...r}){const s=g.useReducer(u=>u+1,0)[1],i=g.useRef({enabled:t,mode:n,container:null,lastSize:null,lastPositions:new WeakMap,prevRange:null});i.current.enabled=t,i.current.mode=n;const o=u=>{const d=i.current;if(!d.enabled||!d.container)return;const f=u.getTotalSize();if(f!==d.lastSize){d.lastSize=f;const x=u.options.horizontal?"width":"height";d.container.style[x]=`${f}px`}const h=!!u.options.horizontal,p=d.mode==="transform",m=h?"left":"top",v=u.options.scrollMargin,y=u.getVirtualItems();for(const x of y){const b=x.start-v,S=u.elementsCache.get(x.key);S&&d.lastPositions.get(S)!==b&&(d.lastPositions.set(S,b),p?S.style.transform=h?`translate3d(${b}px, 0, 0)`:`translate3d(0, ${b}px, 0)`:S.style[m]=`${b}px`)}},l={...r,onChange:(u,d)=>{var f;const h=i.current;let p=!0;if(h.enabled){o(u);const m=u.range,v=h.prevRange;p=!v||v.isScrolling!==u.isScrolling||v.startIndex!==m?.startIndex||v.endIndex!==m?.endIndex,p&&(h.prevRange=m?{startIndex:m.startIndex,endIndex:m.endIndex,isScrolling:u.isScrolling}:null)}p&&(e&&d?wo.flushSync(s):s()),(f=r.onChange)==null||f.call(r,u,d)}},[c]=g.useState(()=>{const u=new abs(l);return Object.assign(u,{containerRef:d=>{const f=i.current;if(f.container=d,f.lastSize=null,d&&f.enabled){const h=u.getTotalSize();f.lastSize=h;const p=u.options.horizontal?"width":"height";d.style[p]=`${h}px`}}})});return c.setOptions(l),qce(()=>c._didMount(),[]),qce(()=>c._willUpdate()),qce(()=>{o(c)}),c}function aVt(e){return ubs({observeElementRect:ebs,observeElementOffset:rbs,scrollToFn:obs,...e})}function pW(e,t){const n=NS(e)?.getTime(),r=NS(t)?.getTime();if(!(n===void 0||r===void 0||r<n))return r-n}function dbs(e,t=100){if(e==null)return"";const n=Array.isArray(e)?e:e&&typeof e=="object"&&!Array.isArray(e)&&Array.isArray(e.messages)?e.messages:null;if(n){const o=n.filter(l=>l?.role==="user").map(l=>typeof l.content=="string"?l.content:Array.isArray(l.content)?l.content.map(c=>typeof c=="string"?c:c?.type==="text"&&typeof c.text=="string"?c.text:"").filter(Boolean).join(" "):"").filter(Boolean).join(" | ");return o.length>t?o.slice(0,t)+"…":o}if(typeof e=="string")return e.length>t?e.slice(0,t)+"…":e;const r=JSON.stringify(e);return r.length>t?r.slice(0,t)+"…":r}function fbs(e){return e?.attributes?.finishReason==="length"}function hbs(e){const t=e?.attributes?.usage;if(!t)return"The model stopped generating because it reached the maximum token limit. The response was truncated and may be incomplete.";const n=t.inputTokens??0,r=t.outputTokens??0,s=t.totalTokens??n+r;return n>0||r>0?`The model stopped generating because it reached the maximum token limit. The response was truncated and may be incomplete.
|
|
677
677
|
|
|
678
678
|
Token usage: ${n} input + ${r} output = ${s} total`:`The model stopped generating because it reached the maximum token limit (${s} tokens). The response was truncated and may be incomplete.`}const pbs=new Intl.NumberFormat("en-US",{notation:"compact",maximumSignificantDigits:3}),mbs=new Intl.NumberFormat("en-US"),gbs=new Set(Intl.supportedValuesOf("currency"));function lVt(e){return e!==void 0&&gbs.has(e.toUpperCase())}function bye(e,t){return new Intl.NumberFormat("en-US",{style:"currency",currency:e,...t})}function H1(e,{currency:t}={}){if(!lVt(t))return pbs.format(e);const n=Math.abs(e);return n<100?vbs(e,{currency:t}):n<1e3?bye(t,{maximumFractionDigits:0}).format(e):bye(t,{notation:"compact",maximumSignificantDigits:3}).format(e)}function vbs(e,{currency:t}={}){if(!lVt(t))return mbs.format(e);const n=bye(t,{}),r=10**-(n.resolvedOptions().maximumFractionDigits??2);return e!==0&&Math.abs(e)<r?`${e<0?"-":""}<${n.format(r)}`:n.format(e)}function RJ(e,t){const n=!t||t.toLowerCase()==="usd",r=e>0&&e<.01?"<0.01":e.toFixed(2);return n?r.startsWith("<")?"<$0.01":`$${r}`:`${r} ${t}`}const ybs=36,xbs=8,bbs=20;function wbs(e,t){return e[t]}function Sbs(e,t){const n=new Set;for(const r of e){const s=r[t];if(typeof s=="string"&&s&&n.add(s),n.size>=bbs)break}return[...n]}function kbs(e){if(!(e?.inputTokens===void 0&&e?.outputTokens===void 0))return(e?.inputTokens??0)+(e?.outputTokens??0)}function Obs({traces:e,isLoading:t,isFetchingNextPage:n,hasNextPage:r,setEndOfListElement:s,filtersApplied:i,featuredTraceId:o,featuredSpanId:l,isBranchesMode:c,recentlyAddedKeys:u,columnPreferences:d=Hb,usageByTraceId:f,onTraceClick:h,createdSort:p,onSortChange:m,onFilterByField:v,listId:y="all-traces"}){const x=g.useRef(null),b=sVt(d),S=zxs(d),k=aVt({count:e.length,getScrollElement:()=>x.current,estimateSize:()=>ybs,overscan:xbs}),{getRowProps:j}=Du({count:e.length,containerRef:x,onNavigate:I=>k.scrollToIndex(I),global:!0}),C=k.getVirtualItems(),T=k.getTotalSize(),_=C[0]?.start??0,N=C.length>0?Math.max(0,T-(C[C.length-1]?.end??0)):0;return a.jsxs(Yi,{reorderable:!0,id:y,columns:b,columnKeys:S,fit:"container",scrollRef:x,className:"min-w-0",children:[a.jsxs(Yi.Top,{children:[m?a.jsx(Yi.SortableTopCell,{sortKey:"startedAt",sort:p,onSortChange:m,children:"Start"}):a.jsx(Yi.TopCell,{children:"Start"}),Oc(d,"type")&&a.jsx(Yi.TopCell,{children:"Primitive type"}),a.jsx(Yi.TopCell,{children:"Primitive name"}),Oc(d,"input")&&a.jsx(Yi.TopCell,{children:"Input"}),a.jsx(Yi.TopCell,{children:"Status"}),Oc(d,"duration")&&a.jsx(Yi.TopCell,{className:"justify-end text-right",children:"Duration"}),Oc(d,"endTime")&&a.jsx(Yi.TopCell,{children:"End"}),Oc(d,"environment")&&a.jsx(Yi.TopCell,{children:"Environment"}),Oc(d,"inputTokens")&&a.jsx(Yi.TopCell,{className:"justify-end text-right",children:"Input tokens"}),Oc(d,"outputTokens")&&a.jsx(Yi.TopCell,{className:"justify-end text-right",children:"Output tokens"}),Oc(d,"totalTokens")&&a.jsx(Yi.TopCell,{className:"justify-end text-right",children:"Total tokens"}),Oc(d,"estimatedCost")&&a.jsx(Yi.TopCell,{className:"justify-end text-right",children:"Est. cost"}),d.customColumns.map(I=>{const A=nVt[I],P=v?Sbs(e,I):[];return!v||P.length===0?a.jsx(Yi.TopCell,{children:A},I):a.jsx(Yi.TopCell,{className:"overflow-visible",children:a.jsxs(ct,{children:[a.jsx(ct.Trigger,{render:a.jsxs("button",{type:"button",className:Z("flex min-w-0 items-center gap-1 rounded-sm hover:text-foreground",Ri),children:[a.jsx("span",{className:"min-w-0 truncate",children:A}),a.jsx(oht,{"aria-hidden":!0,className:"size-[1.2em] shrink-0"})]})}),a.jsxs(ct.Content,{align:"start",children:[a.jsx(ct.Label,{children:"Filter by value"}),P.map(D=>a.jsx(ct.Item,{onSelect:()=>v(I,D),children:a.jsx(Y,{as:"span",variant:"body-sm",font:"mono",className:"min-w-0 truncate",children:D})},D))]})]})},I)}),d.metadataKeys.map(I=>a.jsx(Yi.TopCellWithTooltip,{tooltip:I,children:I},I))]}),t?a.jsx(FNt,{columnCount:oCe(b).length}):e.length===0?a.jsx(Yi.NoMatch,{message:i?"No traces found for applied filters":"No traces found yet"}):a.jsxs(a.Fragment,{children:[a.jsx(Yi.Spacer,{height:_}),C.map(I=>{const A=e[I.index];if(!A)return null;const P=A.traceId===o&&(l==null||A.spanId===l),D=`${A.traceId}:${A.spanId??""}`,F=u?.has(D)??!1,Q=A.startedAt??A.createdAt,q=f?.get(A.traceId);return a.jsxs(Yi.RowButton,{ref:k.measureElement,"data-index":I.index,...j(I.index),onClick:()=>h(A),featured:P,className:Z(F&&"animate-row-highlight"),children:[a.jsx(Yi.CreatedCell,{timestamp:Q,preset:"day-time-seconds"}),Oc(d,"type")&&a.jsx(Yi.TypeCell,{entityType:A.entityType}),a.jsx(Yi.NameCell,{name:A.entityName||A.name,parentSpanId:A.parentSpanId,showLevelTooltip:c}),Oc(d,"input")&&a.jsx(Yi.InputCell,{input:A.inputPreview??dbs(A.input)}),a.jsx(Yi.StatusCell,{status:A.status}),Oc(d,"duration")&&a.jsx(Te.NumberCell,{font:"mono",children:sf(pW(A.startedAt,A.endedAt))}),Oc(d,"endTime")&&a.jsx(Yi.CreatedCell,{timestamp:A.endedAt??"",preset:"day-time-seconds"}),Oc(d,"environment")&&a.jsx(Te.TextCell,{children:A.environment||"—"}),Oc(d,"inputTokens")&&a.jsx(Te.NumberCell,{children:q?.inputTokens===void 0?void 0:H1(q.inputTokens)}),Oc(d,"outputTokens")&&a.jsx(Te.NumberCell,{children:q?.outputTokens===void 0?void 0:H1(q.outputTokens)}),Oc(d,"totalTokens")&&a.jsx(Te.NumberCell,{children:(()=>{const B=kbs(q);return B===void 0?void 0:H1(B)})()}),Oc(d,"estimatedCost")&&a.jsx(Te.NumberCell,{children:q?.estimatedCost===void 0?void 0:RJ(q.estimatedCost,q.costUnit)}),d.customColumns.map(B=>a.jsx(Te.TextCell,{font:"mono",children:wbs(A,B)??void 0},B)),d.metadataKeys.map(B=>{const V=Vxs(A.metadata,B);return a.jsx(Te.TextCell,{font:"mono",children:V},B)})]},D)}),a.jsx(Yi.Spacer,{height:N}),a.jsx(Yi.NextPageLoading,{isLoading:n,hasMore:r,setEndOfListElement:s})]})]})}function jbs({columnPreferences:e=Hb}){const t=sVt(e);return a.jsxs("div",{className:"flex h-full min-h-0 flex-col gap-2",role:"status","aria-label":"Loading traces","data-testid":"traces-page-skeleton",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(xt,{className:"h-control-md min-w-64 flex-1"}),a.jsx(xt,{className:"h-control-md w-28"})]}),a.jsx($u,{columns:t,fit:"container"})]})}function Qce(e){if(typeof window>"u")return Hb;try{return Dxs(window.localStorage.getItem(e)??void 0)}catch{return Hb}}function Cbs(e,t){if(!(typeof window>"u"))try{window.localStorage.setItem(e,Lxs(t))}catch{}}function _bs(){const e=Ams(),[t,n]=g.useState(()=>({storageKey:e,preferences:Qce(e),shouldPersist:!1})),r=t.storageKey===e?t.preferences:Qce(e);g.useEffect(()=>{t.storageKey===e&&t.shouldPersist&&Cbs(e,t.preferences)},[t,e]);const s=f=>{n(h=>{const p=h.storageKey===e?h.preferences:Qce(e),m=f(p);return{storageKey:e,preferences:m,shouldPersist:!0}})};return{preferences:r,toggleColumn:f=>{s(h=>{const p=h.visibleColumns.includes(f);return{...h,visibleColumns:p?h.visibleColumns.filter(m=>m!==f):[...h.visibleColumns,f]}})},addCustomColumn:f=>{s(h=>h.customColumns.includes(f)?h:{...h,customColumns:[...h.customColumns,f]})},removeCustomColumn:f=>{s(h=>({...h,customColumns:h.customColumns.filter(p=>p!==f)}))},addMetadataColumn:f=>{const h=f.trim();h&&s(p=>p.metadataKeys.includes(h)?p:{...p,metadataKeys:[...p.metadataKeys,h]})},removeMetadataColumn:f=>{s(h=>({...h,metadataKeys:h.metadataKeys.filter(p=>p!==f)}))},resetColumns:()=>s(()=>Hb)}}function Tet(e,t){if(!t?.length)return e;const n=new URLSearchParams(e);for(const r of t)n.delete(r),n.delete(GC(r));return n}function Tbs(e,t,n){const{storageKey:r,skipHydration:s,excludeParams:i}=n??{},o=g.useRef(!1);return g.useEffect(()=>{if(s||o.current||(o.current=!0,egs(e)))return;const l=Jms(r),c=l&&Tet(l,i);c?.toString()&&t(u=>{const d=new URLSearchParams(u);for(const[f,h]of c)d.append(f,h);return d},{replace:!0})},[]),g.useCallback((l,c)=>{t(u=>{const d=typeof l=="function"?l(u):l;return Yms(Tet(d,i),r),d},c)},[t,r,i])}function Ebs(e,t,n,r){const s=g.useMemo(()=>t?e.findIndex(c=>c.traceId===t&&n==null):-1,[e,t,n]),i=c=>r(c.traceId,void 0),o=s>0?()=>{const c=e[s-1];c&&i(c)}:void 0,l=s>=0&&s<e.length-1?()=>{const c=e[s+1];c&&i(c)}:void 0;return{featuredTraceIdx:s,handlePreviousTrace:o,handleNextTrace:l}}const dV="traceId",Ob="spanId",hy="tab",Zce="spanView",py="scoreId",$2="highlightSpanIds",TM=1440*60*1e3,Ibs={"last-24h":TM,"last-3d":3*TM,"last-7d":7*TM,"last-14d":14*TM,"last-30d":30*TM};function mE(e){e.delete(dV),e.delete(Ob),e.delete(uV),e.delete(hy),e.delete(py),e.delete($2)}function Nbs(e,t,n){const{onRemoveAll:r}={},s=g.useMemo(()=>{const z=e.get(E1);return z&&z!=="all"&&Hms.has(z)?z:"last-7d"},[e]),i=e.get(l1),o=e.get(c1),l=g.useMemo(()=>{if(s==="custom"){if(!i)return;const U=new Date(i);return Number.isNaN(U.getTime())?void 0:U}const z=Ibs[s];return z?new Date(Date.now()-z):void 0},[s,i]),c=g.useMemo(()=>{if(s!=="custom"||!o)return;const z=new Date(o);return Number.isNaN(z.getTime())?void 0:z},[s,o]),u=g.useRef(s);u.current=s;const d=e.get(dV)||void 0,f=e.get(Ob)||void 0,h=e.get(uV)||void 0,p=e.get(hy),m=p==="feedback"?"feedback":p==="details"?"details":void 0,v=e.get(Zce)==="timeline"?"timeline":"tree",y=e.get(py)||void 0,x=e.get($2),b=g.useMemo(()=>x?x.split(",").filter(Boolean):[],[x]),S=g.useMemo(()=>{const z=e.get(T1);return z&&Wms.has(z)?z:"traces"},[e]),k=g.useMemo(()=>B7t.find(z=>z.entityType===e.get(XS)),[e]),j=g.useMemo(()=>{const z=e.get(JS);return z&&Kms.has(z)?z:void 0},[e]),C=g.useMemo(()=>ygs(e),[e]),T=g.useMemo(()=>ONe(e),[e]),_=g.useCallback((z,U,K)=>{t(ne=>{const X=new URLSearchParams(ne);return z?X.set(dV,z):X.delete(dV),U?X.set(Ob,U):X.delete(Ob),K?X.set(uV,K):X.delete(uV),X.delete(hy),X.delete(py),X.delete($2),X},{replace:!0})},[t]),N=g.useCallback(()=>_(""),[_]),I=g.useCallback(z=>{const U=e.get(Ob)||null;z!==U&&t(K=>{const ne=new URLSearchParams(K);return z?ne.set(Ob,z):ne.delete(Ob),ne.delete(hy),ne.delete(py),ne},{replace:!0})},[e,t]),A=g.useCallback(()=>I(null),[I]),P=g.useCallback(z=>{t(U=>{const K=new URLSearchParams(U);return z==="timeline"?K.set(Zce,z):K.delete(Zce),K},{replace:!0})},[t]),D=g.useCallback(z=>{const U=e.get(hy)||null;z!==U&&t(K=>{const ne=new URLSearchParams(K);return z&&z!=="details"?ne.set(hy,z):ne.delete(hy),ne.delete(py),ne},{replace:!0})},[e,t]),F=g.useCallback((z,U)=>{const K=U&&U!=="details"?U:null;z===(e.get(Ob)||null)&&K===(e.get(hy)||null)&&!e.get(py)||t(X=>{const te=new URLSearchParams(X);return te.set(Ob,z),K?te.set(hy,K):te.delete(hy),te.delete(py),te},{replace:!0})},[e,t]),Q=g.useCallback(z=>{const U=e.get(py)||null;z!==U&&t(K=>{const ne=new URLSearchParams(K);return z?ne.set(py,z):ne.delete(py),ne},{replace:!0})},[e,t]),q=g.useCallback(z=>{t(U=>{const K=new URLSearchParams(U);return z.length===0?K.delete($2):K.set($2,z.join(",")),K},{replace:!0})},[t]),B=g.useCallback((z,U=[])=>{t(K=>{const ne=new URLSearchParams(K);return JJe(ne,z,U),mE(ne),ne},{replace:!0})},[t]),V=B,H=g.useCallback((z,U)=>{if(u.current!=="custom")return;const K=U==="from"?l1:c1;t(ne=>{const X=new URLSearchParams(ne);return z?X.set(K,z.toISOString()):X.delete(K),mE(X),X},{replace:!0})},[t]),M=g.useCallback((z,U)=>{u.current==="custom"&&t(K=>{const ne=new URLSearchParams(K);return z?ne.set(l1,z.toISOString()):ne.delete(l1),U?ne.set(c1,U.toISOString()):ne.delete(c1),mE(ne),ne},{replace:!0})},[t]),G=g.useCallback(z=>{u.current=z,t(U=>{const K=new URLSearchParams(U);return z==="last-7d"?(K.delete(E1),K.delete(l1),K.delete(c1)):z==="custom"?K.set(E1,"custom"):(K.set(E1,z),K.delete(l1),K.delete(c1)),mE(K),K},{replace:!0})},[t]),L=g.useCallback(z=>{t(U=>{const K=new URLSearchParams(U);return z==="traces"?K.delete(T1):K.set(T1,z),mE(K),K},{replace:!0})},[t]),$=g.useCallback(()=>{t(z=>{const U=new URLSearchParams(z);return U.delete(T1),JJe(U,[]),mE(U),U},{replace:!0}),r?.()},[t,r]);return{searchParams:e,setSearchParams:t,datePreset:s,selectedDateFrom:l,selectedDateTo:c,datePresetRef:u,traceIdParam:d,spanIdParam:f,anchorSpanIdParam:h,spanTabParam:m,spanViewParam:v,scoreIdParam:y,highlightSpanIdsParam:b,listMode:S,selectedEntityOption:k,selectedStatus:j,filterTokens:C,filterGroups:T,handleTraceClick:_,handleTraceClose:N,handleSpanChange:I,handleSpanClose:A,handleSpanTabChange:D,handleSpanViewChange:P,handleSpanChangeWithTab:F,handleScoreChange:Q,handleHighlightSpans:q,handleListModeChange:L,handleFilterTokensChange:V,handleDateChange:H,handleDateRangeChange:M,handleDatePresetChange:G,handleRemoveAll:$,applyFilterTokens:B}}function Abs(e){return e.map(t=>({traceId:t.traceId,spanId:t.rootSpanId,parentSpanId:t.parentSpanId,name:Bxs(t.name),createdAt:t.createdAt,inputPreview:t.inputPreview,metadata:t.metadata,entityId:t.entityId,entityName:t.entityName,entityType:t.entityType,threadId:t.threadId,resourceId:t.resourceId,environment:t.environment,status:t.status,startedAt:t.startedAt,endedAt:t.endedAt}))}function cVt({query:e,orderBy:t,rolling:n=!0,initialAutoRefetch:r=!0,withQueryTrace:s,legacyFilters:i,limit:o,enabled:l}){const[c,u]=g.useState(()=>new Date),[d,f]=g.useState(r),h=kms({queryOptions:{traceQuery:{refetchInterval:d&&!n?1e4:!1,refetchOnWindowFocus:d},legacy:{refetchInterval:d&&!n?1e4:!1,refetchOnWindowFocus:d}},query:t?{...e(c),orderBy:t}:e(c),withQueryTrace:s,legacyFilters:i,limit:o,enabled:l});return g.useEffect(()=>{if(!d||!n||h.error)return;const p=setInterval(()=>u(new Date),1e4);return()=>clearInterval(p)},[d,n,h.error]),{...h,rows:Abs(h.data??[]),autoRefetch:d,setAutoRefetch:f}}const wye="sort",Sye="dir",Pbs="page";function $bs(e,t,n){const r=e.get(wye);if(!r||!t.includes(r))return n;const i=e.get(Sye)==="desc"?"desc":"asc";return{key:r,direction:i}}function zk({searchParams:e,setSearchParams:t,allowedKeys:n,defaultSort:r}){const s=e.get(wye),i=e.get(Sye),o=g.useMemo(()=>$bs(e,n,r),[s,i,n,r]),l=g.useCallback((c,u)=>{t(d=>{const f=new URLSearchParams(d);return f.set(wye,u),f.set(Sye,c),f.delete(Pbs),f},{replace:!0})},[t]);return{sort:o,onSortChange:l}}const Rbs=new Set(["ObservabilityStorageClickhouseVNext","ObservabilityStorageDuckDB","ObservabilityInMemory","ObservabilitySpanner","ObservabilityStoragePostgresVNext"]),wz=()=>{const{isMastraPlatform:e}=xz(),{data:t,isLoading:n,error:r}=bz(),s=t?.observabilityStorageType,i=t?.capabilities?.metrics??(s?Rbs.has(s):!1);return{supportsMetrics:e||i,isInMemory:!e&&s==="ObservabilityInMemory",isLoading:!e&&n,error:e?void 0:r}};function Us({value:e,className:t}){return a.jsx(cl,{code:JSON.stringify(e??null,null,2),lang:"json","data-slot":"span-payload-json",className:Z(pr,"rounded-lg p-3 text-wrap break-all text-muted-foreground",t,"text-caption")})}function FNe({value:e}){if(typeof e!="object"||e===null||Array.isArray(e))return a.jsx(Us,{value:e});const t=e,n=t.url??t.image??t.data,r=t.mediaType??t.mimeType;if(typeof n!="string"||!/^https?:\/\//i.test(n))return a.jsx(Us,{value:e});try{const i=new URL(n);if(i.username||i.password)return a.jsx(Us,{value:e})}catch{return a.jsx(Us,{value:e})}const s=typeof t.filename=="string"?t.filename:typeof t.name=="string"?t.name:void 0;return a.jsx(QI,{type:t.type==="image"||typeof r=="string"&&r.startsWith("image/")?"image":"file",contentType:typeof r=="string"?r:void 0,src:n,name:s})}const Eet=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function uVt({value:e,showLabel:t=!0}){if(!Eet(e))return a.jsx(Us,{value:e});const n=e.type==="tool-invocation"?e.toolInvocation:e;if(!Eet(n)||typeof n.toolName!="string"||!n.toolName)return a.jsx(Us,{value:e});const r="args"in n?n.args:n.input,s="result"in n?n.result:n.output,i=n.isError===!0||n.state==="output-error",o=typeof n.errorText=="string"?n.errorText:void 0,{icon:l,label:c,detail:u,description:d}=D_(n.toolName,r),f=r!==void 0||s!==void 0||o!==void 0;return a.jsxs("div",{"data-slot":"span-payload-tool",className:"flex flex-col gap-2",children:[t&&a.jsx(ND,{children:e.type==="tool-result"?"Tool result":"Tool call"}),a.jsx(J_e,{status:i?"error":"idle",header:a.jsx(ZY,{icon:a.jsx(l,{"aria-hidden":!0}),label:c,detail:u,description:d}),children:f&&a.jsxs("div",{className:"flex flex-col gap-3",children:[r!==void 0&&a.jsx(cp,{label:"Arguments",children:a.jsx(Us,{value:r})}),s!==void 0&&a.jsx(cp,{label:"Result",children:a.jsx(Us,{value:s})}),o!==void 0&&a.jsx(cp,{label:"Error",children:a.jsx(Us,{value:o})})]})})]})}function ND({children:e}){return a.jsx(Y,{as:"span",variant:"meta",tone:"faint",className:"block uppercase",children:e})}function cp({label:e,children:t}){return a.jsxs("div",{"data-slot":"span-payload-field",className:"flex flex-col gap-1.5",children:[a.jsx(ND,{children:e}),t]})}function ek({children:e}){return a.jsx("div",{"data-slot":"span-payload-markdown",className:"text-foreground",children:a.jsx(pc,{children:e})})}function xm({label:e,children:t,defaultOpen:n=!1}){return a.jsxs(Kl,{defaultOpen:n,children:[a.jsxs(Cl,{className:"flex items-center gap-1 text-meta text-placeholder uppercase",children:[a.jsx(Na,{direction:"right",className:"size-3"}),e]}),a.jsx(_l,{className:"pt-1.5",children:t})]})}function BNe({toolCalls:e}){return a.jsx("ul",{"data-slot":"span-payload-tool-calls",className:"flex flex-col gap-2",children:e.map((t,n)=>a.jsx("li",{children:a.jsx(uVt,{value:t,showLabel:!1})},n))})}const mW=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function Mbs(e){const t=e.split(`
|
|
@@ -696,7 +696,7 @@ Token usage: ${n} input + ${r} output = ${s} total`:`The model stopped generatin
|
|
|
696
696
|
]`,jSs=[{name:"input",description:"What the agent receives. A string or any JSON value.",required:!0},{name:"groundTruth",description:"Expected answer used by scorers.",required:!1},{name:"metadata",description:"Any object, useful for filtering and grouping.",required:!1}];function CSs(){const{isCopied:e,handleCopy:t}=Fm({text:ett,showToast:!1});return a.jsxs("div",{className:"flex flex-col gap-4",children:[a.jsx(Y,{variant:"column",tone:"ink",className:"flex h-8 items-center",children:"Each item looks like this"}),a.jsx("dl",{className:"divide-y divide-border rounded-lg border border-border",children:jSs.map(n=>a.jsxs("div",{className:"grid grid-cols-[7rem_1fr] gap-3 px-3 py-2.5",children:[a.jsx("dt",{className:Da({tone:"ink",variant:"meta"}),children:a.jsx(ih,{children:n.name})}),a.jsxs("dd",{className:"flex flex-col items-start gap-1.5 text-muted-foreground",children:[a.jsx(Y,{as:"span",variant:"meta",children:n.description}),n.required?a.jsx(Mt,{variant:"success",size:"xs",children:"required"}):a.jsx(Mt,{variant:"neutral",emphasis:"subtle",size:"xs",children:"optional"})]})]},n.name))}),a.jsxs("div",{className:"overflow-hidden rounded-lg border border-border",children:[a.jsxs("div",{className:"flex items-center justify-between border-b border-border bg-card py-1.5 pr-1.5 pl-3",children:[a.jsx(Y,{as:"span",variant:"meta",tone:"muted",font:"mono",children:"example.json"}),a.jsx(de,{icon:e?a.jsx(dr,{}):a.jsx(Lm,{}),variant:"ghost",size:"sm",onClick:t,children:e?"Copied":"Copy"})]}),a.jsx(Or,{variant:"embedded",language:"json",editable:!1,lineNumbers:!1,showCopyButton:!1,value:ett,className:"p-3"})]}),a.jsx(de,{variant:"ghost",render:a.jsx("a",{href:OSs,target:"_blank",rel:"noopener noreferrer"}),className:"self-start",icon:a.jsx(Zs,{}),children:"Datasets documentation"})]})}const tue=10,_Ss=`[
|
|
697
697
|
{ "input": "…", "groundTruth": "…" }
|
|
698
698
|
]`,ttt="flex min-h-0 flex-1 flex-col py-0";function TSs({tab:e,onTabChange:t,file:n,onFileSelect:r,onReplace:s,pastedText:i,onPastedTextChange:o,validation:l,isImporting:c}){return a.jsxs(Qc,{value:e,defaultTab:"upload",onValueChange:t,className:"flex h-full flex-col gap-3",children:[a.jsxs(Zc,{variant:"pill",children:[a.jsx(ni,{value:"upload",children:"Upload file"}),a.jsx(ni,{value:"paste",children:"Paste JSON"})]}),a.jsx(No,{value:"upload",className:ttt,children:n?a.jsx(ASs,{file:n,validation:l,onReplace:s,isImporting:c}):a.jsx(ESs,{onFileSelect:r,disabled:c})}),a.jsx(No,{value:"paste",className:ttt,children:a.jsx(Or,{"aria-label":"JSON items",language:"json",lineNumbers:!1,showCopyButton:!1,placeholder:_Ss,value:i,onChange:o,editable:!c,className:"min-h-50 flex-1"})})]})}function ESs({onFileSelect:e,disabled:t}){const[n,r]=g.useState(!1),s=g.useCallback(c=>{const u=c.target.files?.[0];u&&e(u),c.target.value=""},[e]),i=g.useCallback(c=>{c.preventDefault(),c.stopPropagation(),r(!0)},[]),o=g.useCallback(c=>{c.preventDefault(),c.stopPropagation(),r(!1)},[]),l=g.useCallback(c=>{if(c.preventDefault(),c.stopPropagation(),r(!1),t)return;const u=c.dataTransfer.files?.[0];u&&e(u)},[t,e]);return a.jsxs("div",{"data-testid":"json-dropzone",onDragOver:i,onDragLeave:o,onDrop:l,className:Z("relative flex flex-1 flex-col items-center justify-center gap-3 rounded-lg border border-dashed border-border bg-card px-4 py-6 text-center","hover:border-success-edge hover:bg-success-subtle",n&&"border-success-edge bg-success-subtle",t&&"cursor-wait opacity-60"),children:[a.jsx("input",{type:"file",accept:".json,application/json","aria-label":"Choose a JSON file",onChange:s,disabled:t,className:"absolute inset-0 cursor-pointer opacity-0"}),a.jsx("div",{className:"flex size-9 items-center justify-center rounded-md border border-border bg-background text-muted-foreground",children:a.jsx(qH,{className:"size-4"})}),a.jsxs("div",{className:"flex flex-col gap-1",children:[a.jsx(Y,{tone:"ink",children:"Drop a JSON file here"}),a.jsxs(Y,{variant:"caption",tone:"muted",children:["or ",a.jsx("span",{className:"underline",children:"choose a file"})," from your computer"]})]}),a.jsxs(Y,{variant:"meta",tone:"muted",children:[".json · an array of items · up to ",GNe]})]})}function ISs(e){return e>=1024*1024?`${(e/(1024*1024)).toFixed(1)} MB`:`${Math.max(1,Math.round(e/1024))} KB`}function NSs(e){return typeof e=="string"?e:JSON.stringify(e)??""}function ASs({file:e,validation:t,onReplace:n,isImporting:r}){const s="rows"in t?t.rows:[],i="total"in t?t.total:0,o=s.slice(0,tue);return a.jsxs("div",{"data-testid":"json-file-card",className:"rounded-lg border border-border",children:[a.jsxs("div",{className:"flex items-center gap-2 px-3 py-2",children:[a.jsx(RH,{className:"size-4 shrink-0 text-muted-foreground"}),a.jsx(Y,{as:"span",variant:"caption",tone:"ink",font:"mono",className:"min-w-0 flex-1 truncate",children:e.name}),a.jsx(Y,{as:"span",variant:"meta",tone:"muted",className:"shrink-0",children:ISs(e.size)}),a.jsx(de,{icon:a.jsx(ux,{}),variant:"ghost",size:"sm",onClick:n,disabled:r,children:"Replace"})]}),o.map(l=>a.jsxs("div",{className:"grid grid-cols-[2rem_1fr_auto] items-center gap-2 border-t border-border px-3 py-1.5",children:[a.jsx(Y,{as:"span",variant:"meta",tone:"muted",children:l.index}),a.jsx(Y,{as:"span",variant:"caption",tone:"ink",font:"mono",className:"truncate",children:NSs(l.input)}),l.hasInput?l.hasGroundTruth?null:a.jsx(Mt,{variant:"warning",size:"xs",children:"no groundTruth"}):a.jsx(Mt,{variant:"destructive",size:"xs",children:"no input"})]},l.index)),i>tue&&a.jsxs(Y,{as:"p",variant:"meta",tone:"muted",className:"border-t border-border px-3 py-1.5",children:["+ ",i-tue," more"]})]})}const PSs=e=>new Promise((t,n)=>{const r=new FileReader;r.onload=()=>t(r.result),r.onerror=()=>n(r.error),r.readAsText(e)});function $Ss({datasetId:e,datasetName:t,open:n,onOpenChange:r,onSuccess:s}){const[i,o]=g.useState("upload"),[l,c]=g.useState(null),[u,d]=g.useState(""),[f,h]=g.useState(null),[p,m]=g.useState(""),[v,y]=g.useState(!1),x=g.useRef(0),{batchInsertItems:b}=pl(),S=i==="upload"?u:p,k=g.useMemo(()=>i==="upload"&&f?{status:"error",kind:"parse",message:f}:$1s(S),[i,f,S]),j=g.useCallback(async I=>{const A=++x.current;if(!I.name.toLowerCase().endsWith(".json")){h("Only .json files are supported");return}if(I.size>UVt){h(`File is larger than ${GNe}`);return}try{const P=await PSs(I);if(A!==x.current)return;c({name:I.name,size:I.size}),d(P),h(null)}catch{if(A!==x.current)return;h("Could not read the file")}},[]),C=g.useCallback(()=>{x.current++,c(null),d(""),h(null)},[]),T=g.useCallback(()=>{x.current++,o("upload"),c(null),d(""),h(null),m("")},[]),_=g.useCallback(()=>{r(!1),setTimeout(T,150)},[r,T]),N=g.useCallback(async()=>{if(k.status==="ready"){y(!0);try{await b.mutateAsync({datasetId:e,items:k.items}),Ke.success(`Imported ${k.total} item${k.total!==1?"s":""}`),s?.(),r(!1),setTimeout(T,150)}catch(I){Ke.error(I instanceof Error?I.message:"Failed to import items")}finally{y(!1)}}},[k,b,e,s,r,T]);return a.jsx(rs,{open:n,onOpenChange:_,pending:v,children:a.jsxs(ss,{size:"xl",children:[a.jsxs(es,{children:[a.jsx(Gr,{children:"Import into dataset"}),a.jsxs(zo,{children:["Add items to ",t?a.jsx("span",{className:"text-foreground",children:t}):"this dataset"," from a JSON file or paste them directly."]})]}),a.jsx(Hr,{flush:!0,children:a.jsxs("div",{className:"grid divide-y divide-border md:grid-cols-[1.15fr_1fr] md:divide-x md:divide-y-0",children:[a.jsx("div",{className:"flex min-h-[360px] flex-col p-4",children:a.jsx(TSs,{tab:i,onTabChange:o,file:l,onFileSelect:j,onReplace:C,pastedText:p,onPastedTextChange:m,validation:k,isImporting:v})}),a.jsx("div",{className:"p-4",children:a.jsx(CSs,{})})]})}),a.jsxs(Yo,{children:[a.jsx(RSs,{validation:k}),a.jsx(Ca,{children:"Cancel"}),a.jsxs(ja,{onConfirm:N,disabled:k.status!=="ready",children:[v&&a.jsx(En,{}),k.status==="ready"?`Import ${k.total} item${k.total!==1?"s":""}`:"Import"]})]})]})})}function RSs({validation:e}){const t=Z("size-1.5 shrink-0 rounded-full",e.status==="idle"&&"bg-muted-foreground",e.status==="ready"&&"bg-success-indicator",e.status==="error"&&"bg-destructive-indicator");let n;switch(e.status){case"idle":n="No items yet";break;case"ready":n=a.jsxs(a.Fragment,{children:[a.jsx(Y,{as:"b",variant:"label",tone:"ink",children:e.total})," ","item",e.total!==1?"s":""," ready",e.missingGroundTruthCount>0&&` · ${e.missingGroundTruthCount} without groundTruth`]});break;case"error":switch(e.kind){case"parse":n=`Not valid JSON — ${e.message}`;break;case"not-array":n="Top level must be an array of items";break;case"empty":n="The array has no items";break;case"too-large":n=`JSON is larger than ${GNe}`;break;case"missing-input":n=a.jsxs(a.Fragment,{children:[a.jsx(Y,{as:"b",variant:"label",tone:"ink",children:e.missingInputCount})," ","of ",e.total," item",e.total!==1?"s":""," ",e.missingInputCount!==1?"have":"has"," no"," ",a.jsx(ih,{children:"input"})]});break}break}return a.jsxs("div",{role:"status",className:"mr-auto flex min-w-0 items-center gap-2",children:[a.jsx("span",{className:t}),a.jsx(Y,{tone:"muted",as:"span",variant:"caption",className:"truncate",children:n})]})}function MSs(e){if(!(e instanceof HTMLElement))return!1;if(e.isContentEditable)return!0;const t=e.tagName;return t==="INPUT"||t==="TEXTAREA"||t==="SELECT"?!0:!!e.closest('[role="dialog"]:not([data-item-panel])')}function GVt({active:e,onPrevious:t,onNext:n,onClose:r}){g.useEffect(()=>{if(!e)return;const s=i=>{i.defaultPrevented||MSs(i.target)||(i.key==="PageUp"?(i.preventDefault(),t?.()):i.key==="PageDown"?(i.preventDefault(),n?.()):i.key==="Escape"&&(i.preventDefault(),r()))};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[e,t,n,r])}const KVt=g.createContext(null);function DSs({datasetId:e,items:t,isLoadingItems:n,children:r}){const s=Dr(),o=Dbe("/datasets/:datasetId/items/:itemId")?.params.itemId,l=g.useCallback(p=>{s(`/datasets/${e}/items/${encodeURIComponent(p)}`)},[s,e]),c=g.useCallback(()=>{s(`/datasets/${e}`)},[s,e]),u=g.useMemo(()=>o?t.findIndex(p=>p.id===o):-1,[t,o]),d=g.useMemo(()=>{if(u<=0)return;const p=t[u-1].id;return()=>l(p)},[u,t,l]),f=g.useMemo(()=>{if(u<0||u>=t.length-1)return;const p=t[u+1].id;return()=>l(p)},[u,t,l]);GVt({active:!!o,onPrevious:d,onNext:f,onClose:c});const h=g.useMemo(()=>({datasetId:e,items:t,isLoadingItems:n,currentItemId:o,openItem:l,close:c,goToPreviousItem:d,goToNextItem:f}),[e,t,n,o,l,c,d,f]);return a.jsx(KVt.Provider,{value:h,children:r})}function YVt(){const e=g.useContext(KVt);if(!e)throw new Error("useDatasetItemPanel must be used within a DatasetItemPanelProvider");return e}const LSs=["createdAt"];function zSs({datasetId:e,onAddItemClick:t,onNavigateToDataset:n,leftSlot:r,rightSlot:s,belowToolbarSlot:i}){const[o,l]=oi(),{activeVersion:c}=KNe(o,l),{sort:u,onSortChange:d}=zk({searchParams:o,setSearchParams:l,allowedKeys:LSs}),f=g.useMemo(()=>u?{field:u.key,direction:u.direction==="asc"?"ASC":"DESC"}:void 0,[u]),[h,p]=g.useState(!1),[m,v]=g.useState(!1),[y,x]=g.useState(!1),[b,S]=g.useState([]),[k,j]=g.useState(!1),[C,T]=g.useState([]),[_,N]=g.useState(!1),[I,A]=g.useState([]),[P,D]=g.useState(0),[F,Q]=g.useState(""),[q]=TY(F,300),{data:B}=Mv({datasetId:e,queryOptions:{enabled:!!e}}),{data:V=[],isLoading:H,setEndOfListElement:M,isFetchingNextPage:G,hasNextPage:L}=JN({datasetId:e,search:q||void 0,version:c,orderBy:f,queryOptions:{enabled:!!e}}),{deleteItems:$}=pl(),{currentItemId:z,openItem:U,close:K}=YVt(),ne=ae=>{z===ae?K():U(ae)},X=ae=>{S(ae),x(!0)},te=ae=>{T(ae),j(!0)},ie=ae=>{j(ae),ae||(T([]),D(he=>he+1))},ue=ae=>{A(ae),N(!0)},ee=async()=>{await $.mutateAsync({datasetId:e,itemIds:I}),Ke.success(`Deleted ${I.length} items`),N(!1),A([]),D(ae=>ae+1)},se=ae=>{x(!1),S([]),D(he=>he+1),n?.(ae)},re=ae=>{x(ae),ae||(S([]),D(he=>he+1))};return a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"grid h-full overflow-auto",children:a.jsx(kSs,{items:V,leftSlot:r,rightSlot:s,belowToolbarSlot:i,isLoading:H,onItemClick:ne,featuredItemId:z,onAddClick:t??(()=>{}),onImportClick:()=>p(!0),onImportJsonClick:()=>v(!0),onBulkDeleteClick:ue,onCreateDatasetClick:X,onAddToDatasetClick:te,datasetName:B?.name,clearSelectionTrigger:P,setEndOfListElement:M,isFetchingNextPage:G,hasNextPage:L,searchQuery:F,activeSearchQuery:q,onSearchChange:Q,sort:u,onSortChange:d,currentDatasetVersion:B?.version})}),a.jsx(gSs,{datasetId:e,open:h,onOpenChange:p}),a.jsx($Ss,{datasetId:e,datasetName:B?.name,open:m,onOpenChange:v}),a.jsx(Y1s,{open:y,onOpenChange:re,items:b,onSuccess:se}),a.jsx(X1s,{open:k,onOpenChange:ie,items:C,currentDatasetId:e}),a.jsx(Ut,{open:_,onOpenChange:N,children:a.jsxs(Ut.Content,{children:[a.jsxs(Ut.Header,{children:[a.jsx(Ut.Title,{children:"Delete Items"}),a.jsxs(Ut.Description,{children:["Are you sure you want to delete ",I.length," item",I.length!==1?"s":"","? This action cannot be undone."]})]}),a.jsxs(Ut.Footer,{children:[a.jsx(Ut.Cancel,{children:"Cancel"}),a.jsx(Ut.Action,{onClick:ee,children:$.isPending?"Deleting...":"Delete"})]})]})})]})}const ntt="__create_tag__";function FSs({datasetId:e}){const{data:t}=Mv({datasetId:e,queryOptions:{enabled:!!e}}),{data:n}=Sk(),{updateDataset:r}=pl(),[s,i]=g.useState(""),o=g.useMemo(()=>Array.isArray(t?.tags)?t.tags:[],[t?.tags]),l=g.useMemo(()=>DVt(n?.datasets??[]),[n?.datasets]),c=g.useMemo(()=>{const h=l.map(v=>({label:v,value:v,end:o.includes(v)?a.jsx(dr,{"data-testid":"tag-applied",className:"size-3.5"}):void 0})),p=s.trim();return p.length>0&&!l.includes(p)&&!o.includes(p)?[{label:`Create "${p}"`,value:ntt},...h]:h},[l,o,s]),u=h=>{r.mutate({datasetId:e,tags:h},{onError:()=>Ke.error("Failed to update tags")})},d=h=>{const p=h===ntt?s.trim():h;!p||o.includes(p)||u([...o,p])},f=h=>{u(o.filter(p=>p!==h))};return a.jsxs("div",{"data-testid":"dataset-tags-editor",className:"flex flex-wrap items-center gap-2",children:[o.map(h=>a.jsxs(DJ,{value:h,size:"md",className:"gap-1 pr-1",children:[h,a.jsx("button",{type:"button","aria-label":`Remove tag ${h}`,disabled:r.isPending,onClick:()=>f(h),className:"cursor-pointer rounded-sm hover:opacity-70 disabled:opacity-50",children:a.jsx(Dn,{className:"size-3"})})]},h)),a.jsx(Qa,{options:c,value:void 0,onValueChange:d,onInputValueChange:i,placeholder:a.jsxs("span",{className:"flex items-center gap-1.5",children:[a.jsx(uk,{className:"size-3.5"}),"Add tag"]}),searchPlaceholder:"Search or create tag...",emptyText:"Type to create a tag",variant:"ghost",size:"sm",className:"w-auto min-w-0",disabled:r.isPending})]})}function XVt({overrideEnabled:e,onOverrideEnabledChange:t,selectedScorerIds:n,onSelectedScorerIdsChange:r,disabled:s=!1}){return a.jsxs("div",{className:"grid gap-3",children:[a.jsxs(ft,{orientation:"horizontal",disabled:s,className:"gap-3",children:[a.jsx(hc,{checked:e,onCheckedChange:t}),a.jsx(ut,{children:"Override dataset scorers"})]}),a.jsx(Y,{variant:"caption",tone:"muted",children:e?"Only selected scorers run for this item. Leave empty to run no scorers.":"Use scorers attached to the dataset."}),e?a.jsx(zJ,{selectedScorers:n,setSelectedScorers:r,disabled:s,label:"Item scorers",helperText:"Choose from scorers that can be resolved by this Mastra instance."}):null]})}function XI({field:e,errors:t}){return t.length===0?null:a.jsx(is,{children:a.jsx("span",{className:"space-y-1",children:t.map(n=>a.jsxs("span",{className:"block",children:[a.jsxs("code",{className:"rounded bg-destructive-subtle px-1",children:[e,n.path!=="/"?n.path:""]}),": ",n.message]},`${n.path}:${n.message}`))})})}function BSs(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 VSs({datasetId:e,open:t,onOpenChange:n,onSuccess:r}){const[s,i]=g.useState("{}"),[o,l]=g.useState(""),[c,u]=g.useState(""),[d,f]=g.useState(""),[h,p]=g.useState(!1),[m,v]=g.useState([]),[y,x]=g.useState(""),[b,S]=g.useState(null),{addItem:k}=pl(),j=()=>{i("{}"),l(""),u(""),f(""),p(!1),v([]),x(""),S(null)},C=P=>{j(),n(P)},T=async P=>{P.preventDefault();let D;try{D=JSON.parse(s)}catch{Ke.error("Input must be valid JSON");return}let F;if(o.trim())try{F=JSON.parse(o)}catch{Ke.error("Ground Truth must be valid JSON");return}let Q;if(c.trim())try{Q=JSON.parse(c)}catch{Ke.error("Expected Trajectory must be valid JSON");return}let q;if(d.trim())try{const V=JSON.parse(d);if(!Array.isArray(V)){Ke.error("Tool Mocks must be a JSON array");return}q=V}catch{Ke.error("Tool Mocks must be valid JSON");return}let B;if(y.trim())try{B=JSON.parse(y)}catch{Ke.error("Request Context must be valid JSON");return}try{await k.mutateAsync({datasetId:e,input:D,groundTruth:F,expectedTrajectory:Q,toolMocks:q,scorerIds:h?m:void 0,requestContext:B}),Ke.success("Item added successfully"),C(!1),r?.()}catch(V){const H=BSs(V);H?S(H):Ke.error(`Failed to add item: ${V instanceof Error?V.message:"Unknown error"}`)}},_=P=>{i(P),b?.field==="input"&&S(null)},N=P=>{l(P),b?.field==="groundTruth"&&S(null)},I=P=>{f(P),b?.field==="toolMocks"&&S(null)},A=()=>{C(!1)};return a.jsxs(xo,{dialogTitle:"Add Item",dialogDescription:"Create a new dataset item",isOpen:t,onClose:A,level:1,children:[a.jsx(xo.Top,{children:"Add Item"}),a.jsxs(xo.Content,{children:[a.jsx(xo.Header,{children:a.jsx(xo.Heading,{children:"Add Item"})}),a.jsxs(Ga,{onSubmit:T,children:[a.jsxs(ft,{invalid:b?.field==="input",children:[a.jsx(ut,{required:!0,children:"Input (JSON)"}),a.jsx(Or,{value:s,onChange:_,showCopyButton:!1,className:"min-h-[240px]"}),b?.field==="input"&&a.jsx(XI,{field:"input",errors:b.errors})]}),a.jsxs(ft,{invalid:b?.field==="groundTruth",children:[a.jsx(ut,{children:"Ground Truth (JSON, optional)"}),a.jsx(Or,{value:o,onChange:N,showCopyButton:!1,className:"min-h-[200px]"}),b?.field==="groundTruth"&&a.jsx(XI,{field:"groundTruth",errors:b.errors})]}),a.jsxs(ft,{children:[a.jsx(ut,{children:"Expected Trajectory (JSON, optional)"}),a.jsx(Or,{value:c,onChange:u,showCopyButton:!1,className:"min-h-[200px]"})]}),a.jsxs(ft,{invalid:b?.field==="toolMocks",children:[a.jsx(ut,{children:"Tool Mocks (JSON array, optional)"}),a.jsx(Or,{value:d,onChange:I,showCopyButton:!1,className:"min-h-[200px]"}),b?.field==="toolMocks"&&a.jsx(XI,{field:"toolMocks",errors:b.errors})]}),a.jsx(XVt,{overrideEnabled:h,onOverrideEnabledChange:p,selectedScorerIds:m,onSelectedScorerIdsChange:v,disabled:k.isPending}),a.jsxs(ft,{children:[a.jsx(ut,{children:"Request Context (JSON, optional)"}),a.jsx(Or,{value:y,onChange:x,showCopyButton:!1,className:"min-h-[200px]"})]}),a.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[a.jsx(de,{icon:a.jsx(Dn,{}),type:"button",onClick:A,children:"Cancel"}),a.jsx(de,{icon:a.jsx(ys,{}),type:"submit",variant:"primary",disabled:k.isPending,children:k.isPending?"Adding...":"Add Item"})]})]})]})]})}const NO=e=>JSON.stringify(e??null,null,2),USs=[{key:"input",title:"Input",icon:a.jsx(v4,{}),value:e=>NO(e.input)},{key:"groundTruth",title:"Ground Truth",icon:a.jsx(z1,{}),value:e=>NO(e.groundTruth)},{key:"expectedTrajectory",title:"Expected Trajectory",icon:a.jsx(Y0e,{}),value:e=>e.expectedTrajectory!=null?NO(e.expectedTrajectory):void 0},{key:"toolMocks",title:"Tool Mocks",icon:a.jsx(cd,{}),value:e=>NO(e.toolMocks??[])},{key:"scorerIds",title:"Scorers",icon:a.jsx(iht,{}),value:e=>e.scorerIds===void 0?"Inherited from dataset":NO(e.scorerIds)},{key:"requestContext",title:"Request Context",icon:a.jsx(Ua,{}),value:e=>e.requestContext!=null?NO(e.requestContext):void 0},{key:"metadata",title:"Metadata",icon:a.jsx(uk,{}),value:e=>NO(e.metadata)}];function Tye({item:e,diff:t}){return a.jsxs(a.Fragment,{children:[a.jsxs(zt,{children:[a.jsx(zt.Key,{children:"Dataset Id"}),a.jsx(zt.ValueWithCopyBtn,{copyTooltip:"Copy Dataset Id to clipboard",copyValue:e.datasetId,children:e.datasetId}),a.jsx(zt.Key,{children:"Version"}),a.jsxs(zt.Value,{children:["v",e.datasetVersion]}),a.jsx(zt.Key,{children:"Created"}),a.jsx(zt.Value,{children:os(e.createdAt,"date-time")}),a.jsx(zt.Key,{children:"Updated"}),a.jsx(zt.Value,{children:e.updatedAt&&new Date(e.updatedAt).getTime()!==new Date(e.createdAt).getTime()?os(e.updatedAt,"date-time"):"n/a"})]}),a.jsx("div",{className:"mt-3 grid gap-3",children:USs.map(n=>{const r=n.value(e),s=t?n.value(t.against):void 0;return r===void 0&&s===void 0?null:a.jsx(Ot.CodeSection,{title:n.title,icon:n.icon,codeStr:r??"",diff:t?{against:s??"",side:t.side}:void 0},n.key)})})]})}function qSs({inputValue:e,setInputValue:t,groundTruthValue:n,setGroundTruthValue:r,metadataValue:s,setMetadataValue:i,trajectoryValue:o,setTrajectoryValue:l,toolMocksValue:c,setToolMocksValue:u,scorerOverrideEnabled:d,setScorerOverrideEnabled:f,selectedScorerIds:h,setSelectedScorerIds:p,requestContextValue:m,setRequestContextValue:v,validationErrors:y,onSave:x,onCancel:b,isSaving:S}){return a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"mb-4",children:a.jsxs(Y,{as:"h3",variant:"heading",className:"flex items-center gap-2",children:[a.jsx(Fc,{className:"h-5 w-5"})," Edit Item"]})}),a.jsxs("div",{className:"space-y-6",children:[a.jsxs(ft,{invalid:y?.field==="input",children:[a.jsx(ut,{required:!0,children:"Input (JSON)"}),a.jsx(Or,{value:e,onChange:t,showCopyButton:!1,className:"min-h-[120px]"}),y?.field==="input"&&a.jsx(XI,{field:"input",errors:y.errors})]}),a.jsxs(ft,{invalid:y?.field==="groundTruth",children:[a.jsx(ut,{children:"Ground Truth (JSON, optional)"}),a.jsx(Or,{value:n,onChange:r,showCopyButton:!1,className:"min-h-[100px]"}),y?.field==="groundTruth"&&a.jsx(XI,{field:"groundTruth",errors:y.errors})]}),a.jsxs(ft,{children:[a.jsx(ut,{children:"Expected Trajectory (JSON, optional)"}),a.jsx(Or,{value:o,onChange:l,showCopyButton:!1,className:"min-h-[80px]"})]}),a.jsxs(ft,{invalid:y?.field==="toolMocks",children:[a.jsx(ut,{children:"Tool Mocks (JSON array, optional)"}),a.jsxs(no,{children:["Ordered static mocks served in place of executing the tool. Each entry is"," ",a.jsx("code",{children:'{ "toolName", "args", "output" }'}),". Calling a mocked tool with non-matching args fails the item; unmocked tools run live."]}),a.jsx(Or,{value:c,onChange:u,showCopyButton:!1,className:"min-h-[100px]"}),y?.field==="toolMocks"&&a.jsx(XI,{field:"toolMocks",errors:y.errors})]}),a.jsx(XVt,{overrideEnabled:d,onOverrideEnabledChange:f,selectedScorerIds:h,onSelectedScorerIdsChange:p,disabled:S}),a.jsxs(ft,{children:[a.jsx(ut,{children:"Request Context (JSON, optional)"}),a.jsx(Or,{value:m,onChange:v,showCopyButton:!1,className:"min-h-[80px]"})]}),a.jsxs(ft,{children:[a.jsx(ut,{children:"Metadata (JSON, optional)"}),a.jsx(Or,{value:s,onChange:i,showCopyButton:!1,className:"min-h-[80px]"})]}),a.jsxs("div",{className:"flex gap-2 pt-4",children:[a.jsx(de,{icon:a.jsx(dr,{}),variant:"primary",onClick:x,disabled:S,children:S?"Saving...":"Save Changes"}),a.jsx(de,{icon:a.jsx(Dn,{}),onClick:b,disabled:S,children:"Cancel"})]})]})]})}const QSs=[{value:"agent",label:"Agent"},{value:"workflow",label:"Workflow"},{value:"scorer",label:"Scorer"}];function ZSs({targetType:e,setTargetType:t,targetId:n,setTargetId:r,container:s}){const{data:i,isLoading:o}=ch(),{data:l,isLoading:c}=Op({}),{data:u,isLoading:d}=ag(),f=e==="agent"?Object.entries(i??{}).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})):[],h=e==="agent"&&o||e==="workflow"&&c||e==="scorer"&&d,p=v=>{t(v),r("")},m=e==="agent"?"Agent":e==="workflow"?"Workflow":"Scorer";return a.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[a.jsxs(ft,{children:[a.jsx(ut,{children:"Target Type"}),a.jsx(Qa,{options:QSs,value:e,onValueChange:p,placeholder:"Select target type",searchPlaceholder:"Search types...",emptyText:"No types available",container:s})]}),e&&a.jsxs(ft,{children:[a.jsx(ut,{children:m}),a.jsx(Qa,{options:f,value:n,onValueChange:r,placeholder:`Select ${e}`,searchPlaceholder:"Search...",emptyText:"No targets available",disabled:h,container:s})]})]})}const WSs=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform);function HSs({requestContextSchema:e,onChange:t}){const n=g.useMemo(()=>{try{return OS(e)}catch(r){return console.error("Failed to parse requestContextSchema:",r),null}},[e]);return n?a.jsxs(x0,{children:[a.jsx(pC,{children:"Request Context"}),a.jsx(ZSe,{schema:n,onValuesChange:t,className:"[&_button[type=submit]]:hidden"})]}):a.jsx("div",{role:"alert",children:a.jsx(Ht,{variant:"destructive",children:"Failed to parse request context schema"})})}function nue({index:e,done:t,isLast:n,children:r}){return a.jsxs("li",{className:"flex gap-4",children:[a.jsxs("div",{className:"flex flex-col items-center",children:[a.jsx(Y,{as:"span",variant:"meta",tone:"muted","aria-hidden":"true",className:Z("flex size-6 shrink-0 items-center justify-center rounded-full border",t?"border-success-edge bg-success-subtle text-success-subtle-foreground":"border-border"),children:e}),!n&&a.jsx("span",{"aria-hidden":"true",className:"mt-2 w-px flex-1 bg-border"})]}),a.jsx("div",{className:Z("min-w-0 flex-1 space-y-3",!n&&"pb-4"),children:r})]})}function FJ({initialDatasetId:e,initialDatasetVersion:t,initialScorerIds:n,initialTargetType:r,initialTargetId:s,initialName:i,initialDescription:o,open:l,onOpenChange:c,onSuccess:u}){const d=g.useRef(null),[f,h]=g.useState(i??""),[p,m]=g.useState(o??""),[v,y]=g.useState(e??""),[x,b]=g.useState(t??null),[S,k]=g.useState(r??""),[j,C]=g.useState(s??""),[T,_]=g.useState(n??null),[N,I]=g.useState({}),[A,P]=g.useState(""),{triggerExperiment:D}=pl(),{data:F}=Mv({datasetId:v,queryOptions:{enabled:!!v}}),{total:Q}=JN({datasetId:v,search:void 0,version:x,queryOptions:{enabled:!!v}}),q=F?.requestContextSchema,B=F?.scorerIds??[],V=T===null&&B.length>0,H=T??B,M=!!(q&&Object.keys(q).length>0),G=!!(v&&S&&j&&f.trim()),L=D.isPending,$=[!f.trim()&&"name",!v&&"dataset",!j&&"target"].filter(Boolean),z=M?Object.values(N).some(ue=>ue!==void 0&&ue!==""):A.trim().length>0,U=ue=>{y(ue),b(null),_(n??null),I({})},K=()=>{h(i??""),m(o??""),y(e??""),b(t??null),k(r??""),C(s??""),_(n??null),I({}),P("")},ne=()=>{if(M){const ue=Object.entries(N).filter(([,ee])=>ee!==void 0&&ee!=="");return ue.length>0?Object.fromEntries(ue):void 0}if(A.trim()){let ue;try{ue=JSON.parse(A)}catch{throw new Error("Request Context must be valid JSON")}if(!ue||typeof ue!="object"||Array.isArray(ue))throw new Error("Request Context must be a JSON object");return ue}},X=async()=>{if(!v||!S||!j||!f.trim())return;let ue;try{ue=ne()}catch(ee){const se=ee instanceof Error?ee.message:"Request Context must be valid JSON";xu.error(se);return}try{const ee=await D.mutateAsync({datasetId:v,name:f.trim(),description:p.trim()||void 0,targetType:S,targetId:j,scorerIds:H.length>0?H:void 0,version:x??void 0,requestContext:ue});xu.success("Experiment triggered successfully"),c(!1),u?.(ee.experimentId),K()}catch(ee){const se=ee instanceof Error?ee.message:"Failed to trigger experiment";xu.error(se)}},te=()=>{c(!1),K()},ie=ue=>{(ue.metaKey||ue.ctrlKey)&&ue.key==="Enter"&&G&&!L&&(ue.preventDefault(),X())};return a.jsx(rs,{open:l,onOpenChange:te,pending:L,children:a.jsxs(ss,{ref:d,size:"lg",onKeyDown:ie,children:[a.jsxs(es,{children:[a.jsx(Gr,{children:"Run experiment"}),a.jsx(zo,{children:"Pick a dataset, choose what to run it against, and optionally score the results."})]}),a.jsxs(Hr,{children:[a.jsxs("div",{className:"space-y-4",children:[a.jsxs(ft,{children:[a.jsx(ut,{required:!0,children:"Name"}),a.jsx(Sn,{required:!0,value:f,onChange:ue=>h(ue.target.value),placeholder:"Enter experiment name",autoFocus:!0,disabled:L})]}),a.jsxs(ft,{children:[a.jsx(ut,{children:"Description"}),a.jsx(Eu,{value:p,onChange:ue=>m(ue.target.value),placeholder:"Enter experiment description (optional)",disabled:L,rows:2})]})]}),a.jsxs("ol",{className:"list-none",children:[a.jsxs(nue,{index:1,done:!!v,children:[a.jsxs("div",{className:"grid grid-cols-[1fr_140px] gap-3",children:[a.jsxs(ft,{children:[a.jsx(ut,{children:"Dataset"}),a.jsx(pkt,{value:v,onValueChange:U,container:d})]}),v&&a.jsxs(ft,{children:[a.jsx(ut,{children:"Version"}),a.jsx(HVt,{datasetId:v,value:x,onValueChange:b,container:d})]})]}),v&&Q!==void 0&&a.jsxs(Y,{variant:"meta",tone:"muted",children:[Q," ",Q===1?"item":"items"]})]}),a.jsxs(nue,{index:2,done:!!j,children:[a.jsx(ZSs,{targetType:S,setTargetType:k,targetId:j,setTargetId:C,container:d}),S&&!j&&a.jsxs(Y,{variant:"meta",tone:"muted",children:["Choose ",S==="agent"?"an":"a"," ",S," to run"]})]}),a.jsx(nue,{index:3,done:H.length>0,isLast:!0,children:a.jsx(zJ,{selectedScorers:H,setSelectedScorers:_,disabled:L,container:d,helperText:V?"Pre-filled from the dataset's default scorers.":"Scores are computed after each item runs."})})]}),a.jsxs(Kl,{children:[a.jsxs(Cl,{className:"flex items-center gap-2 text-caption",children:[a.jsx(Na,{direction:"right",className:"size-4"}),"Request Context (JSON, optional)",z&&a.jsx(Mt,{size:"xs",variant:"blue",children:"set"})]}),a.jsx(_l,{className:"pt-3",children:M?a.jsx(HSs,{requestContextSchema:q,onChange:I}):a.jsx(Or,{value:A,onChange:P,showCopyButton:!1,"aria-label":"Request context JSON",className:"min-h-[160px]"})})]})]}),a.jsxs(Yo,{children:[a.jsx("p",{"data-testid":"experiment-run-status","aria-live":"polite",className:"mr-auto flex items-center gap-2",children:$.length===0?a.jsxs(a.Fragment,{children:[a.jsx(Mt,{variant:"success",indicator:"dot",children:"Ready"}),a.jsxs(Y,{as:"span",variant:"meta",tone:"muted",children:[Q??0," items · ",S," · ",H.length," scorers"]})]}):a.jsxs(Mt,{variant:"neutral",indicator:"dot",children:["Missing ",$.join(", ")]})}),a.jsx(Ca,{children:"Cancel"}),a.jsx(ja,{onConfirm:X,disabled:!G,children:L?a.jsxs(a.Fragment,{children:[a.jsx(En,{className:"h-4 w-4"}),"Running..."]}):a.jsxs(a.Fragment,{children:["Run",a.jsxs("span",{className:"ml-1 inline-flex gap-0.5","aria-hidden":"true",children:[a.jsx(Qd,{size:"xs",children:WSs?"⌘":"Ctrl"}),a.jsx(Qd,{size:"xs",children:"↵"})]})]})})]})]})})}const JVt=g.createContext(null);function GSs({experimentId:e,datasetId:t,experimentStatus:n,results:r,isLoadingResults:s,hasNextPage:i,children:o}){const l=Dr(),u=Dbe("/experiments/:experimentId/items/:itemId")?.params.itemId,d=g.useCallback(y=>{l(`/experiments/${e}/items/${encodeURIComponent(y)}`)},[l,e]),f=g.useCallback(()=>{l(`/experiments/${e}`)},[l,e]),h=g.useMemo(()=>u?r.findIndex(y=>y.itemId===u):-1,[r,u]),p=g.useMemo(()=>{if(h<=0)return;const y=r[h-1].itemId;return()=>d(y)},[h,r,d]),m=g.useMemo(()=>{if(h<0||h>=r.length-1)return;const y=r[h+1].itemId;return()=>d(y)},[h,r,d]);GVt({active:!!u,onPrevious:p,onNext:m,onClose:f});const v=g.useMemo(()=>({experimentId:e,datasetId:t,experimentStatus:n,results:r,isLoadingResults:s,hasNextPage:i,currentItemId:u,openItem:d,close:f,goToPreviousItem:p,goToNextItem:m}),[e,t,n,r,s,i,u,d,f,p,m]);return a.jsx(JVt.Provider,{value:v,children:o})}function eUt(){const e=g.useContext(JVt);if(!e)throw new Error("useExperimentItemPanel must be used within an ExperimentItemPanelProvider");return e}const KSs=new Set(["itemId","id","status","input","tags","scores","startedAt"]);function tUt({results:e,isLoading:t,featuredResultId:n,onResultClick:r,columns:s,scoresByItemId:i,scorerIds:o,setEndOfListElement:l,isFetchingNextPage:c,hasNextPage:u,emptyMessage:d="No results yet",selectedIds:f,onToggleSelect:h,onToggleSelectAll:p,sort:m,onSortChange:v}){const{Link:y,paths:x}=xn(),b=!!(f&&h),S=s.filter(B=>KSs.has(B.name)||o?.includes(B.name)),k=[b?"2rem":"",...S.map(B=>B.size)].filter(Boolean).join(" "),j=B=>S.some(V=>V.name===B),C=j("itemId")||j("id"),T=j("status"),_=j("input"),N=j("tags"),I=j("scores"),A=j("startedAt"),P=f?e.filter(B=>f.has(B.id)).length:0,D=e.length>0&&P===e.length,{containerRef:F,getRowProps:Q}=Du({count:e.length}),q=B=>o?.includes(B.name)?a.jsx(Te.TopCell,{children:a.jsxs(y,{href:x.scorerLink(B.name),className:"flex min-w-0 items-center gap-1.5 hover:underline [&>svg]:size-3.5 [&>svg]:shrink-0",children:[a.jsx(Ax,{}),a.jsx("span",{className:"min-w-0 truncate",children:B.label})]})},B.name):B.name==="startedAt"&&v?a.jsx(Te.SortableTopCell,{sortKey:"startedAt",sort:m?.key==="startedAt"?m.direction:void 0,onSortChange:v,children:B.label},B.name):a.jsx(Te.TopCell,{children:B.label},B.name);return t?a.jsx($u,{columns:k}):a.jsxs(Te,{columns:k,className:"min-w-0",scrollRef:F,fit:"container",children:[a.jsxs(Te.Top,{hasLeadingCell:b,children:[b&&(p?a.jsx(Te.TopSelectCell,{checked:D?!0:P>0?"indeterminate":!1,onToggle:p,"aria-label":"Select all"}):a.jsx(Te.TopCell,{children:" "})),b?a.jsx(Te.TopCells,{colStart:2,children:S.map(q)}):S.map(q)]}),e.length===0?a.jsx(Te.NoMatch,{message:d}):a.jsxs(a.Fragment,{children:[e.map((B,V)=>{const H=!!B.error,M=B.id===n,G=a.jsxs(a.Fragment,{children:[C&&a.jsxs(Te.Cell,{className:"flex items-center gap-1.5 text-muted-foreground",children:[a.jsx("span",{children:B.itemId?.slice(0,8)??""}),H&&a.jsxs(Ln,{children:[a.jsx(Rn,{render:a.jsx(uP,{role:"img","aria-label":"Error",className:"size-3.5 text-destructive-foreground"})}),a.jsx(Mn,{children:XSs(B.error)})]})]}),T&&a.jsx(Te.Cell,{className:"flex items-center","data-testid":`result-status-${B.id}`,children:B.status?a.jsx(DNe,{status:B.status}):a.jsx("span",{className:"text-placeholder",children:"—"})}),_&&a.jsx(Te.TextCell,{font:"mono",children:eks(JSs(B.input),200)}),N&&a.jsx(Te.Cell,{className:"flex items-center gap-1 overflow-hidden","data-testid":`result-tags-${B.id}`,children:B.tags?.map(L=>a.jsx(DJ,{value:L,className:"shrink-0"},L))}),I&&a.jsx(Te.Cell,{children:a.jsx(YSs,{scores:B.scores})}),A&&(B.startedAt?a.jsx(Te.CreatedCell,{timestamp:B.startedAt}):a.jsx(Te.Cell,{className:"text-placeholder",children:"—"})),o?.map(L=>{const z=i?.[B.itemId]?.find(U=>U.scorerId===L);return a.jsx(Te.Cell,{className:"text-muted-foreground tabular-nums",children:z!=null?z.score.toFixed(3):"-"},L)})]});return b?a.jsxs(Te.RowWrapper,{children:[a.jsx(Te.SelectCell,{checked:f.has(B.id),onToggle:()=>h(B.id),"aria-label":`Select result ${B.itemId}`}),a.jsx(Te.RowButton,{colStart:2,featured:M,"data-selected":M||void 0,onClick:()=>r(B.id),...Q(V),children:G})]},B.id):a.jsx(Te.RowButton,{featured:M,"data-selected":M||void 0,onClick:()=>r(B.id),...Q(V),children:G},B.id)}),a.jsx(Te.NextPageLoading,{isLoading:c,hasMore:u,setEndOfListElement:l})]})]})}function YSs({scores:e}){const t=Array.isArray(e)?e.map(n=>n.score).filter(n=>n!=null):Object.values(e??{});return t.length===0?a.jsx(Y,{variant:"meta",tone:"faint",children:"—"}):a.jsxs("div",{className:"flex items-center gap-1",children:[a.jsx(At,{size:"xs",className:"text-muted-foreground",children:a.jsx(Cv,{})}),a.jsx(Y,{variant:"meta",tone:"muted",font:"mono",children:t[0].toFixed(2)}),t.length>1&&a.jsxs(Mt,{children:["+",t.length-1]})]})}function XSs(e){return e&&typeof e=="object"&&"message"in e&&typeof e.message=="string"?e.message||"Error":typeof e=="string"&&e?e:"Error"}function JSs(e){return e==null?"-":typeof e=="string"?e:JSON.stringify(e,null,2)}function eks(e,t){return e.length<=t?e:e.slice(0,t-1)+"..."}function tks({experimentId:e,experimentStatus:t,results:n,isLoading:r,setEndOfListElement:s,isFetchingNextPage:i,hasNextPage:o,selectedIds:l,onToggleSelect:c,sort:u,onSortChange:d}){const{currentItemId:f,openItem:h,close:p}=eUt(),m=g.useMemo(()=>f?n.find(S=>S.itemId===f)?.id??null:null,[n,f]),{data:v}=AS({experimentId:e,experimentStatus:t,queryOptions:{enabled:!!e}}),y=g.useMemo(()=>{if(!v)return[];const S=new Set;for(const k of Object.values(v))for(const j of k)S.add(j.scorerId);return[...S].sort()},[v]),x=g.useCallback(S=>{const k=n.find(j=>j.id===S);k&&(k.itemId===f?p():h(k.itemId))},[n,f,p,h]),b=g.useMemo(()=>[{name:"itemId",label:"Item ID",size:"auto"},{name:"status",label:"Status",size:"auto"},{name:"input",label:"Input",size:"1fr"},{name:"tags",label:"Tags",size:"auto"},{name:"startedAt",label:"Created",size:"auto"},...y.map(S=>({name:S,label:S,size:"auto"}))],[y]);return a.jsx("div",{className:"h-full min-h-0 min-w-0 overflow-y-auto",children:a.jsx(tUt,{results:n,isLoading:r,featuredResultId:m,onResultClick:x,columns:b,scoresByItemId:v,scorerIds:y,setEndOfListElement:s,isFetchingNextPage:i,hasNextPage:o,selectedIds:l,onToggleSelect:c,sort:u,onSortChange:d})})}const rtt={pending:{icon:a.jsx(ON,{className:"size-4 text-warning-foreground"}),label:"Pending"},running:{icon:a.jsx(En,{size:"sm"}),label:"Running"},completed:{icon:a.jsx(Qft,{className:"size-4 text-muted-foreground"}),label:"Completed"},failed:{icon:a.jsx(L0e,{className:"size-4 text-destructive-foreground"}),label:"Failed"}};function nks({status:e,className:t}){const n=rtt[e]??rtt.pending;return a.jsxs(Ln,{children:[a.jsx(Rn,{render:a.jsx("span",{tabIndex:0,className:Z("flex shrink-0 items-center",t),children:n.icon})}),a.jsx(Mn,{children:n.label})]})}function rks({children:e,className:t}){return a.jsx("div",{className:Z("grid content-start gap-4 overflow-y-auto",t),children:e})}function sks({children:e,className:t}){return a.jsx("div",{className:"flex w-full overflow-y-auto",children:a.jsx("div",{className:Z("grid w-full content-start gap-4 overflow-y-auto",t),children:e})})}function iks({children:e,className:t}){return a.jsx("div",{className:Z("flex w-full flex-wrap items-center justify-between gap-3 gap-x-4",t),children:e})}const nUt=Object.assign(sks,{Content:rks,Toolbar:iks});function oks({children:e,className:t}){return a.jsx("div",{className:Z("grid size-full grid-cols-1 overflow-y-auto",t),children:e})}const aks=({experimentId:e,experimentStatus:t,supportsMetrics:n,queryOptions:r})=>{const s=Ye(),i=!!e&&n,o=_t({queryKey:["experiment-metrics",e],refetchInterval:t==="running"||t==="pending"?2e3:!1,queryFn:async()=>{if(!e)throw new Error("experimentId is required");const l={experimentId:e},[c,u,d]=await Promise.all([s.getMetricAggregate({name:["mastra_model_total_input_tokens","mastra_model_total_output_tokens"],aggregation:"sum",filters:l}),s.getMetricAggregate({name:["mastra_agent_duration_ms"],aggregation:"avg",filters:l}),s.getMetricAggregate({name:["mastra_agent_duration_ms"],aggregation:"count",filters:l})]);return{totalTokens:c.value??null,estimatedCost:c.estimatedCost??null,costUnit:c.costUnit??null,avgAgentDurationMs:u.value??null,agentRuns:d.value??null}},...r});return{data:o.data,isLoading:o.isLoading,isEnabled:i}},lks=({traceId:e,queryOptions:t})=>{const n=Ye();return _t({queryKey:["experiment-trace-light",e],queryFn:async()=>{if(!e)throw new Error("Trace ID is required");return n.getTraceLight(e)},...t})};function rUt({datasetId:e,target:t,queryOptions:n}){const r=Ye(),s={perPage:100};return t?.targetType&&(s.targetType=t.targetType),t?.targetId&&(s.targetId=t.targetId),_t({queryKey:["experiments",s],queryFn:()=>r.listExperiments(s),...n})}function cks({datasetId:e,target:t,orderBy:n,queryOptions:r}){const s=Ye(),{inView:i,setRef:o}=F0(),l=t?.targetType||void 0,c=t?.targetId||void 0,u=Mm({queryKey:e?["dataset-experiments",e,"infinite",{targetType:l,targetId:c,orderBy:n}]:["experiments","infinite",{targetType:l,targetId:c,orderBy:n}],queryFn:({pageParam:d})=>{const f={page:d,perPage:100};return l&&(f.targetType=l),c&&(f.targetId=c),n&&(f.orderBy=n),e?s.listDatasetExperiments(e,f):s.listExperiments(f)},initialPageParam:0,getNextPageParam:(d,f,h)=>{if(!(!d?.experiments?.length||!d.pagination?.hasMore))return h+1},select:d=>d.pages.flatMap(f=>f?.experiments??[]),...r});return g.useEffect(()=>{i&&u.hasNextPage&&!u.isFetchingNextPage&&u.fetchNextPage()},[i,u]),{...u,setEndOfListElement:o}}const uks={agent:"blue",workflow:"cyan",model:"purple",mcp:"green",tool:"amber",workspace:"orange"},dks=Object.keys(uks);[...dks];function fks(e,t){if(t){const n=typeof t=="string"?new Date(t):t;return`v${e} ${os(n,"date-time")}`}return`v${e}`}function hks({datasetId:e,versionA:t,versionB:n,onVersionChange:r}){const{data:s}=hkt({datasetId:e,queryOptions:{enabled:!!e}}),i=(s??[]).map(o=>({value:String(o.version),label:`${fks(o.version,o.createdAt)}${o.isCurrent?" (current)":""}`}));return a.jsxs(nUt.Toolbar,{className:"grid w-full grid-cols-[1fr_1fr_1fr_10rem] gap-4",children:[a.jsx("div",{}),a.jsxs(Vr,{value:t??"",onValueChange:o=>r?.(o,n??""),children:[a.jsx(qr,{"aria-label":"Version A",size:"md",children:a.jsx(Ur,{placeholder:"Select version"})}),a.jsx(Qr,{children:i.map(o=>a.jsx(ir,{value:o.value,children:o.label},o.value))})]}),a.jsxs(Vr,{value:n??"",onValueChange:o=>r?.(t??"",o),children:[a.jsx(qr,{"aria-label":"Version B",size:"md",children:a.jsx(Ur,{placeholder:"Select an option"})}),a.jsx(Qr,{children:i.map(o=>a.jsx(ir,{value:o.value,children:o.label},o.value))})]}),a.jsx("div",{})]})}const mV={added:{badgeVariant:"info",borderColor:"border-info-edge",icon:a.jsx(ys,{}),tooltip:"Added in this version"},changed:{badgeVariant:"warning",borderColor:"border-warning-edge",icon:a.jsx(SEn,{}),tooltip:"Changed in this version"},same:{badgeVariant:"success",borderColor:"border-success-edge",icon:a.jsx(Hft,{}),tooltip:"Same in both versions"}};function rue({red:e=!1,tooltip:t}){return a.jsxs(Ln,{children:[a.jsx(Rn,{render:a.jsx("span",{}),role:"img",tabIndex:0,"aria-label":t,className:Z("rounded",Ri),children:a.jsx(Lft,{className:Z("h-5 w-5 text-muted-foreground/40",{"text-destructive-foreground":e})})}),a.jsx(Mn,{children:t})]})}function O7({href:e,tooltip:t,className:n,children:r}){const{Link:s}=xn(),i=a.jsx(s,{href:e,className:Z("flex w-full items-center justify-center gap-4 rounded-lg px-3 py-2 text-left hover:bg-fill-subtle",$i.colors,Ri,n),children:r});return t===void 0?i:a.jsxs(Ln,{children:[a.jsx(Rn,{render:i}),a.jsx(Mn,{children:t})]})}function sue({variant:e,version:t}){if(!e)return a.jsxs(Y,{as:"span",tone:"muted",children:["v. ",t]});const{badgeVariant:n,icon:r,tooltip:s}=mV[e];return a.jsxs("div",{className:"grid grid-cols-[1fr_auto]",children:[t!==void 0&&a.jsxs(Y,{as:"span",tone:"muted",className:"flex min-w-16 justify-end pr-3",children:["v. ",t]}),a.jsx("span",{className:"inline-flex",role:"img","aria-label":s,children:a.jsx(Mt,{variant:n,size:"xs",icon:r})})]})}function pks(e,t){return e&&t&&e.datasetVersion===t.datasetVersion?"same":e&&t&&e.datasetVersion!==t.datasetVersion?"changed":e?"added":"removed"}function stt({otherVersionExists:e,status:t,isNewer:n}){if(!e&&n)return"added";if(t==="changed"&&n)return"changed"}function mks({datasetId:e,versionA:t,versionB:n,allItems:r,itemsAMap:s,itemsBMap:i}){const o=t>n;return a.jsx("div",{className:"overflow-y-auto",children:a.jsx("ul",{className:"grid content-start",children:r.map(({id:l})=>{const c=s.get(l),u=i.get(l),d=pks(c,u),f=stt({otherVersionExists:u!==void 0,status:d,isNewer:o}),h=stt({otherVersionExists:c!==void 0,status:d,isNewer:!o});return a.jsxs("li",{className:Z("text-foreground","grid grid-cols-[1fr_1fr_1fr_10rem] gap-3 overflow-hidden rounded-lg border border-transparent border-t-border px-3 py-[3px] pb-[2px] first:border-t-transparent",$i.colors),children:[a.jsx(Y,{as:"p",variant:"body",tone:"faint",className:"truncate py-[0.6rem]",children:l}),d!=="same"?a.jsxs(a.Fragment,{children:[c?.datasetVersion?a.jsx(O7,{href:`/datasets/${e}/items/${l}`,className:"gap-2",tooltip:f?mV[f].tooltip:void 0,children:a.jsx(sue,{variant:f,version:c.datasetVersion})}):a.jsx("div",{className:"flex items-center justify-center",children:a.jsx(rue,{red:o,tooltip:o?"Deleted in this version":"Not present in this version"})}),u?.datasetVersion?a.jsx(O7,{href:`/datasets/${e}/items/${l}`,className:"gap-2",tooltip:h?mV[h].tooltip:void 0,children:a.jsx(sue,{variant:h,version:u.datasetVersion})}):a.jsx("div",{className:"flex items-center justify-center",children:a.jsx(rue,{red:!o,tooltip:o?"Not present in this version":"Deleted in this version"})})]}):a.jsx(O7,{href:`/datasets/${e}/items/${l}`,className:"col-span-2 gap-2",tooltip:mV.same.tooltip,children:a.jsx(sue,{variant:"same",version:u?.datasetVersion})}),d==="changed"?a.jsx(O7,{href:`/datasets/${e}/items/${l}/versions?version=${c?.datasetVersion}&compare=${u?.datasetVersion}`,children:"Compare"}):a.jsx("div",{children:a.jsx(rue,{tooltip:"Comparing is available only for changed items"})})]},l)})})})}function gks(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 vks({item:e,itemId:t,fallback:n,onClose:r,...s}){const i=e?.id??t;return a.jsx(Ot,{open:!!i,onClose:r,title:`Dataset item ${i??""}`,children:e?a.jsx(yks,{item:e,onClose:r,...s},e.id):t?a.jsxs(a.Fragment,{children:[a.jsxs(Ot.Header,{children:[a.jsx(Ot.CloseButton,{onClick:r,tooltip:"Close detail panel"}),a.jsxs(Ot.Heading,{children:["Item",a.jsx(Ot.CopyId,{id:t})]})]}),n]}):null})}function yks({datasetId:e,item:t,items:n,onItemChange:r,onClose:s}){const{Link:i}=xn(),{updateItem:o,deleteItem:l}=pl(),[c,u]=g.useState(!1),[d,f]=g.useState(""),[h,p]=g.useState(""),[m,v]=g.useState(""),[y,x]=g.useState(""),[b,S]=g.useState(""),[k,j]=g.useState(t.scorerIds!==void 0),[C,T]=g.useState(t.scorerIds??[]),[_,N]=g.useState(""),[I,A]=g.useState(null),[P,D]=g.useState(!1);g.useEffect(()=>{t&&(f(JSON.stringify(t.input,null,2)),p(t.groundTruth?JSON.stringify(t.groundTruth,null,2):""),v(t.metadata?JSON.stringify(t.metadata,null,2):""),x(t.expectedTrajectory?JSON.stringify(t.expectedTrajectory,null,2):""),S(t.toolMocks?.length?JSON.stringify(t.toolMocks,null,2):""),j(t.scorerIds!==void 0),T(t.scorerIds??[]),N(t.requestContext?JSON.stringify(t.requestContext,null,2):""),u(!1),D(!1),A(null))},[t?.id]);const F=n.findIndex(L=>L.id===t.id),Q=F>0?()=>r(n[F-1].id):void 0,q=F>=0&&F<n.length-1?()=>r(n[F+1].id):void 0,B=async()=>{let L;try{L=JSON.parse(d)}catch{Ke.error("Input must be valid JSON");return}let $;if(h.trim())try{$=JSON.parse(h)}catch{Ke.error("Ground Truth must be valid JSON");return}let z;if(m.trim())try{z=JSON.parse(m)}catch{Ke.error("Metadata must be valid JSON");return}let U=null;if(y.trim())try{U=JSON.parse(y)}catch{Ke.error("Expected Trajectory must be valid JSON");return}let K;if(b.trim())try{const te=JSON.parse(b);if(!Array.isArray(te)){Ke.error("Tool Mocks must be a JSON array");return}K=te}catch{Ke.error("Tool Mocks must be valid JSON");return}else K=[];let ne;if(_.trim())try{ne=JSON.parse(_)}catch{Ke.error("Request Context must be valid JSON");return}let X;k?X=C:t.scorerIds!==void 0&&(X=null);try{const te=await o.mutateAsync({datasetId:e,itemId:t.id,input:L,groundTruth:$,metadata:z,expectedTrajectory:U,toolMocks:K,scorerIds:X,requestContext:ne});Ke.success("Item updated successfully"),j(te.scorerIds!==void 0),T(te.scorerIds??[]),u(!1),A(null)}catch(te){const ie=gks(te);ie?A(ie):Ke.error(`Failed to update item: ${te instanceof Error?te.message:"Unknown error"}`)}},V=()=>{f(JSON.stringify(t.input,null,2)),p(t.groundTruth?JSON.stringify(t.groundTruth,null,2):""),v(t.metadata?JSON.stringify(t.metadata,null,2):""),x(t.expectedTrajectory?JSON.stringify(t.expectedTrajectory,null,2):""),S(t.toolMocks?.length?JSON.stringify(t.toolMocks,null,2):""),j(t.scorerIds!==void 0),T(t.scorerIds??[]),N(t.requestContext?JSON.stringify(t.requestContext,null,2):""),u(!1),A(null)},H=L=>{f(L),I?.field==="input"&&A(null)},M=L=>{p(L),I?.field==="groundTruth"&&A(null)},G=async()=>{try{await l.mutateAsync({datasetId:e,itemId:t.id}),Ke.success("Item deleted successfully"),D(!1),s()}catch(L){Ke.error(`Failed to delete item: ${L instanceof Error?L.message:"Unknown error"}`)}};return a.jsxs(a.Fragment,{children:[a.jsxs(Ot.Header,{children:[a.jsx(Ot.CloseButton,{onClick:s,tooltip:"Close detail panel"}),a.jsxs(Ot.Heading,{children:["Item",a.jsx(Ot.CopyId,{id:t.id})]}),a.jsxs(Ot.HeaderActions,{children:[!c&&a.jsxs(a.Fragment,{children:[a.jsx(de,{render:a.jsx(i,{href:`/datasets/${e}/items/${t.id}/versions?version=${t.datasetVersion}`}),size:"sm",variant:"ghost",tooltip:"Go to item versions history","aria-label":"Go to item versions history",children:a.jsx(K0e,{})}),a.jsxs(ct,{children:[a.jsx(ct.Trigger,{asChild:!0,children:a.jsx(de,{size:"sm",variant:"ghost",tooltip:"Open actions menu","aria-label":"Open actions menu",children:a.jsx(M0,{})})}),a.jsxs(ct.Content,{align:"end",className:"w-48",children:[a.jsxs(ct.Item,{onSelect:()=>u(!0),children:[a.jsx(Fc,{}),"Edit"]}),a.jsxs(ct.Item,{onSelect:()=>D(!0),variant:"destructive",children:[a.jsx(Xo,{}),"Delete Item"]})]})]})]}),a.jsx(Ot.NextPrevNav,{onPrevious:Q,onNext:q,previousLabel:"Go to previous item",nextLabel:"Go to next item"})]})]}),a.jsx(Ot.Content,{children:c?a.jsx(qSs,{inputValue:d,setInputValue:H,groundTruthValue:h,setGroundTruthValue:M,metadataValue:m,setMetadataValue:v,trajectoryValue:y,setTrajectoryValue:x,toolMocksValue:b,setToolMocksValue:S,scorerOverrideEnabled:k,setScorerOverrideEnabled:j,selectedScorerIds:C,setSelectedScorerIds:T,requestContextValue:_,setRequestContextValue:N,validationErrors:I,onSave:B,onCancel:V,isSaving:o.isPending}):a.jsx(Tye,{item:t})}),a.jsx(Ut,{open:P,onOpenChange:D,children:a.jsxs(Ut.Content,{children:[a.jsxs(Ut.Header,{children:[a.jsx(Ut.Title,{children:"Delete Item"}),a.jsx(Ut.Description,{children:"Are you sure you want to delete this item? This action cannot be undone."})]}),a.jsxs(Ut.Footer,{children:[a.jsx(Ut.Cancel,{children:"Cancel"}),a.jsx(Ut.Action,{onClick:G,children:l.isPending?"Deleting...":"Yes, Delete"})]})]})})]})}function xks(){const{datasetId:e,items:t,isLoadingItems:n,currentItemId:r,openItem:s,close:i}=YVt(),o=g.useMemo(()=>r?t.find(d=>d.id===r):void 0,[t,r]),{data:l,isLoading:c}=fkt({datasetId:o?"":e,itemId:!o&&r?r:"",queryOptions:{enabled:!!(!o&&e)&&!!(!o&&r&&r)}}),u=o??l??void 0;return a.jsx(vks,{datasetId:e,item:u,itemId:r,fallback:n||c?a.jsx(Ot.LoadingData,{}):a.jsxs(Ot.NoData,{children:['No loaded item "',r,'".']}),items:t,onItemChange:s,onClose:i})}function j7({crumbs:e,children:t}){return a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:e}),children:[a.jsx("h1",{className:"sr-only",children:"Dataset"}),a.jsx("div",{}),a.jsx("div",{className:"flex h-full items-center justify-center",children:t})]})}function bks(){const{datasetId:e,itemId:t}=jr(),n=[_s("/datasets"),{...oK,to:`/datasets/${encodeURIComponent(e)}`},...t?[{id:"dataset-items",label:"Items"},{id:"dataset-item",label:bke(t)}]:[]],r=Dr(),[s,i]=oi(),{activeVersion:o,handleVersionChange:l}=KNe(s,i),[c,u]=g.useState(!1),[d,f]=g.useState(!1),[h,p]=g.useState(!1),[m,v]=g.useState(!1),{data:y,error:x,isLoading:b}=Mv({datasetId:e,queryOptions:{enabled:!!e}}),{data:S=[],isLoading:k}=JN({datasetId:e,search:void 0,version:o,queryOptions:{enabled:!!e}}),j=!k&&S.length===0;if(b)return null;if(x&&js(x))return a.jsx(j7,{crumbs:n,children:a.jsx(ai,{})});if(x&&Cs(x))return a.jsx(j7,{crumbs:n,children:a.jsx(Gs,{resource:"datasets"})});if(x&&kk(x)||!b&&!x&&!y)return a.jsx(j7,{crumbs:n,children:a.jsx(Xt,{titleSlot:"Dataset not found",descriptionSlot:`No dataset with id "${e}".`,actionSlot:a.jsx(de,{render:a.jsx(lc,{to:"/datasets"}),icon:a.jsx(md,{}),children:"Back to Datasets"})})});if(x)return a.jsx(j7,{crumbs:n,children:a.jsx(Xt,{tone:"error",titleSlot:"Failed to load dataset",descriptionSlot:x instanceof Error?x.message:"An unexpected error occurred. Please try again."})});const C=_=>{r(`/experiments/${_}`)},T=()=>{r("/datasets")};return a.jsxs(DSs,{datasetId:e,items:S,isLoadingItems:k,children:[a.jsxs("div",{className:"h-full",children:[a.jsxs(Et,{variant:"fit",breadcrumbs:a.jsx(Dt,{crumbs:n}),children:[a.jsx("h1",{className:"sr-only",children:e}),a.jsx("div",{children:a.jsx(zSs,{datasetId:e,onAddItemClick:()=>f(!0),belowToolbarSlot:a.jsx(FSs,{datasetId:e}),leftSlot:a.jsx(Y,{as:"span",variant:"caption",tone:"muted",className:"mr-3 whitespace-nowrap",children:y?.createdAt?`Created ${os(y.createdAt,"date-time")}`:""}),rightSlot:a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(de,{render:a.jsx(lc,{to:`/experiments?dataset=${e}`}),icon:a.jsx(DH,{}),children:"View experiments"}),a.jsx(HVt,{datasetId:e,value:o,onValueChange:l,currentVersion:y?.version,className:"w-36"}),j?a.jsxs(Ln,{children:[a.jsx(Rn,{asChild:!0,children:a.jsx("span",{className:"cursor-not-allowed",children:a.jsx("div",{className:"pointer-events-none opacity-50",inert:!0,"aria-disabled":"true",children:a.jsx(de,{variant:"primary",icon:a.jsx(Bc,{}),children:"Run Experiment"})})})}),a.jsx(Mn,{children:"Add items to the dataset before running an experiment"})]}):a.jsx(de,{variant:"primary",onClick:()=>u(!0),icon:a.jsx(Bc,{}),children:"Run Experiment"}),a.jsxs(ct,{children:[a.jsx(ct.Trigger,{asChild:!0,children:a.jsx(de,{size:"lg","aria-label":"Dataset actions menu",children:a.jsx(M0,{})})}),a.jsxs(ct.Content,{align:"end",className:"w-48",children:[a.jsxs(ct.Item,{onSelect:()=>{r(`/datasets/${e}/edit`)},children:[a.jsx(Fc,{})," Edit Dataset"]}),a.jsxs(ct.Item,{onSelect:()=>v(!0),children:[a.jsx(Lm,{})," Duplicate Dataset"]}),a.jsxs(ct.Item,{onSelect:()=>p(!0),variant:"destructive",children:[a.jsx(Xo,{})," Delete Dataset"]})]})]})]})})})]}),a.jsx(xks,{})]}),a.jsx(FJ,{initialDatasetId:e,initialDatasetVersion:o??void 0,open:c,onOpenChange:u,onSuccess:C},`${e}:${o??"latest"}`),a.jsx(VSs,{datasetId:e,open:d,onOpenChange:f}),y&&a.jsx(J1s,{open:m,onOpenChange:v,sourceDatasetId:y.id,sourceDatasetName:y.name,sourceDatasetDescription:y.description,sourceDatasetTargetType:y.targetType}),y&&a.jsx(rSs,{open:h,onOpenChange:p,datasetId:y.id,datasetName:y.name,onSuccess:T})]})}const sUt=[_s("/datasets"),oK,{id:"dataset-edit",label:"Edit dataset"}];function iue({children:e}){return a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:sUt}),children:[a.jsx("h1",{className:"sr-only",children:"Edit dataset"}),a.jsx("div",{}),a.jsx("div",{className:"flex h-full items-center justify-center",children:e})]})}function wks(){const{datasetId:e}=jr(),t=Dr(),{data:n,error:r,isLoading:s}=Mv({datasetId:e,queryOptions:{enabled:!!e}}),i=()=>{t(`/datasets/${e}`)};return s?null:r&&js(r)?a.jsx(iue,{children:a.jsx(ai,{})}):r&&Cs(r)?a.jsx(iue,{children:a.jsx(Gs,{resource:"datasets"})}):r||!n?a.jsx(iue,{children:a.jsx(Xt,{tone:"error",titleSlot:"Failed to load dataset",descriptionSlot:r instanceof Error?r.message:"An unexpected error occurred. Please try again."})}):a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:sUt}),children:[a.jsx("h1",{className:"sr-only",children:"Edit dataset"}),a.jsx("div",{}),a.jsx("div",{className:"flex h-full items-center justify-center",children:a.jsxs("div",{className:"w-full max-w-2xl overflow-y-auto px-4 py-5",children:[a.jsx(qh,{className:"mb-6 p-0",children:a.jsxs(qh.Column,{children:[a.jsxs(qh.Title,{children:[a.jsx(cx,{})," Edit dataset"]}),a.jsx(qh.Description,{children:n.name})]})}),a.jsx(jl,{className:"p-4",children:a.jsx(nSs,{dataset:{id:n.id,name:n.name,description:n.description||"",inputSchema:n.inputSchema,groundTruthSchema:n.groundTruthSchema,requestContextSchema:n.requestContextSchema,scorerIds:n.scorerIds},onSuccess:i,onCancel:i})})]})})]})}function itt(e,t){return{id:e.id,datasetId:t,datasetVersion:e.datasetVersion,input:e.input,groundTruth:e.groundTruth,expectedTrajectory:e.expectedTrajectory,toolMocks:e.toolMocks,scorerIds:e.scorerIds,requestContext:e.requestContext,metadata:e.metadata,createdAt:e.createdAt,updatedAt:e.updatedAt}}function ott(e,t){return e.map(n=>{const r=typeof n.updatedAt=="string"?new Date(n.updatedAt):n.updatedAt;return{value:String(n.datasetVersion),label:a.jsxs("span",{className:"flex w-full items-center gap-2",children:[a.jsxs("span",{children:[a.jsxs("b",{children:["v. ",n.datasetVersion]})," · ",os(r,"date-time")]}),n.isLatest?a.jsx(Mt,{variant:"blue",size:"xs",className:"ml-auto",children:"Latest"}):null]}),disabled:t?.has(n.datasetVersion)??!1}})}function att(e){const t=Number(e);return e!=null&&Number.isFinite(t)&&t>0?t:null}function Sks(){const{datasetId:e,itemId:t}=jr(),[n,r]=oi(),s=[_s("/datasets"),oK,{id:"dataset-item",label:bke(t),to:e&&t?`/datasets/${encodeURIComponent(e)}/items/${encodeURIComponent(t)}`:void 0},{id:"dataset-item-versions",label:"Item Version History"}],i=att(n.get("version")),o=att(n.get("compare")),l=n.get("view")==="diff",{data:c,error:u}=Mv({datasetId:e??"",queryOptions:{enabled:!!e}}),{data:d,isLoading:f}=mar({datasetId:e??"",itemId:t??"",queryOptions:{enabled:!!e&&!!t}}),h=(i!=null?d?.find(T=>T.datasetVersion===i):void 0)??d?.[0],p=h?.datasetVersion??null,m=o!=null&&o!==p?o:null,{data:v,isLoading:y}=gar({datasetId:e??"",itemId:t??"",datasetVersion:m??0,latestVersion:c?.version,queryOptions:{enabled:!!e&&!!t&&(m??0)>0}}),x=(T,_)=>r(N=>{const I=new URLSearchParams(N);return _==null?I.delete(T):I.set(T,String(_)),I},{replace:!0});if(u&&js(u))return a.jsxs(Et,{variant:"fit",breadcrumbs:a.jsx(Dt,{crumbs:s}),children:[a.jsx("h1",{className:"sr-only",children:"Item Version History"}),a.jsx(ai,{variant:"fill"})]});if(u&&Cs(u))return a.jsxs(Et,{variant:"fit",breadcrumbs:a.jsx(Dt,{crumbs:s}),children:[a.jsx("h1",{className:"sr-only",children:"Item Version History"}),a.jsx(Gs,{variant:"fill",resource:"datasets"})]});if(!e||!t)return a.jsxs(Et,{variant:"fit",breadcrumbs:a.jsx(Dt,{crumbs:s}),children:[a.jsx("h1",{className:"sr-only",children:"Item Version History"}),a.jsx("div",{className:"grid h-full min-w-min content-start items-start overflow-x-auto overflow-y-auto",children:a.jsx("div",{className:"py-5 text-center text-muted-foreground",children:a.jsx("p",{children:"Item not found."})})})]});const b=!!(h&&v),S=l&&b,k=h?itt(h,e):null,j=v?itt(v,e):null,C=(h?.datasetVersion??0)<(v?.datasetVersion??0);return a.jsxs(Et,{variant:"fit",breadcrumbs:a.jsx(Dt,{crumbs:s}),headerActions:b&&a.jsx(de,{variant:"ghost",size:"sm",onClick:()=>x("view",l?null:"diff"),children:l?a.jsxs(a.Fragment,{children:[a.jsx(F0e,{})," Default View"]}):a.jsxs(a.Fragment,{children:[a.jsx(H_n,{})," Diff View"]})}),children:[a.jsx("h1",{className:"sr-only",children:"Item Version History"}),a.jsxs("div",{className:"grid min-h-0 grid-cols-1 gap-4 md:grid-cols-2",children:[a.jsxs(jl,{className:"grid min-h-0 grid-rows-[auto_1fr] overflow-hidden",children:[a.jsx(cQ,{children:a.jsx(ltt,{label:"Version",value:p!=null?String(p):"",options:ott(d??[],m!=null?new Set([m]):void 0),onValueChange:T=>x("version",Number(T))})}),a.jsx(Um,{className:"grid content-start gap-5 overflow-y-auto",children:f?a.jsx(Y,{as:"p",variant:"body",tone:"muted",children:"Loading..."}):k?a.jsx(Tye,{item:k,diff:S&&j?{against:j,side:C?"a":"b"}:void 0}):a.jsx(Y,{as:"p",variant:"body",tone:"muted",children:"Item data not available"})})]}),a.jsxs(jl,{className:"grid min-h-0 grid-rows-[auto_1fr] overflow-hidden",children:[a.jsx(cQ,{children:a.jsx(ltt,{label:"Compare version",value:m!=null?String(m):"",placeholder:"Select a version to compare",options:ott(d??[],p!=null?new Set([p]):void 0),onValueChange:T=>x("compare",Number(T))})}),a.jsx(Um,{className:"grid content-start gap-5 overflow-y-auto",children:m==null?a.jsx(Xt,{className:"h-full",titleSlot:"No version selected",descriptionSlot:"Pick a version above to compare it with the one on the left."}):y?a.jsx(Y,{as:"p",variant:"body",tone:"muted",children:"Loading..."}):j?a.jsx(Tye,{item:j,diff:S&&k?{against:k,side:C?"b":"a"}:void 0}):a.jsxs(Y,{as:"p",variant:"body",tone:"muted",children:["Version ",m," not found"]})})]})]})]})}function ltt({label:e,value:t,options:n,placeholder:r="Select version",onValueChange:s}){return a.jsxs("div",{className:"grid grid-cols-[auto_1fr] items-center gap-4",children:[a.jsx(K0e,{className:"size-4 opacity-50"}),a.jsxs(Vr,{value:t,onValueChange:s,children:[a.jsx(qr,{"aria-label":e,className:"w-full",children:a.jsx(Ur,{placeholder:r,className:"flex-1"})}),a.jsx(Qr,{children:n.map(i=>a.jsx(ir,{value:i.value,disabled:i.disabled,children:i.label},i.value))})]})]})}const C7=[_s("/datasets"),oK,{id:"dataset-versions",label:"Versions"}];function kks(){const{datasetId:e}=jr(),[t]=oi(),n=t.get("ids")?.split(",").map(Number).filter(m=>!isNaN(m)&&m>0)??[],r=Dr(),{data:s,error:i}=Mv({datasetId:e??"",queryOptions:{enabled:!!e}}),o=JN({datasetId:e??"",search:void 0,version:n[0]??null,queryOptions:{enabled:!!e}}),l=JN({datasetId:e??"",search:void 0,version:n[1]??null,queryOptions:{enabled:!!e}}),c=g.useMemo(()=>o.data??[],[o.data]),u=g.useMemo(()=>l.data??[],[l.data]),d=g.useMemo(()=>{const m=new Map;for(const v of[...c,...u])m.has(v.id)||m.set(v.id,{id:v.id,createdAt:new Date(v.createdAt)});return[...m.values()].sort((v,y)=>y.createdAt.getTime()-v.createdAt.getTime())},[c,u]),f=g.useMemo(()=>new Map(c.map(m=>[m.id,m])),[c]),h=g.useMemo(()=>new Map(u.map(m=>[m.id,m])),[u]);if(i&&js(i))return a.jsxs(Et,{variant:"fit",breadcrumbs:a.jsx(Dt,{crumbs:C7}),children:[a.jsx("h1",{className:"sr-only",children:"Versions"}),a.jsx(ai,{variant:"fill"})]});if(i&&Cs(i))return a.jsxs(Et,{variant:"fit",breadcrumbs:a.jsx(Dt,{crumbs:C7}),children:[a.jsx("h1",{className:"sr-only",children:"Versions"}),a.jsx(Gs,{variant:"fill",resource:"datasets"})]});if(!e||n.length<2)return a.jsxs(Et,{variant:"fit",breadcrumbs:a.jsx(Dt,{crumbs:C7}),children:[a.jsx("h1",{className:"sr-only",children:"Versions"}),a.jsx("div",{className:"grid h-full min-w-min content-start items-start overflow-x-auto overflow-y-auto",children:a.jsx("div",{className:"py-5 text-center text-muted-foreground",children:a.jsx("p",{children:"Select at least two versions to compare."})})})]});const p=(m,v)=>{r(`/datasets/${e}/versions?ids=${m},${v}`,{replace:!0})};return a.jsxs(Et,{variant:"fit",breadcrumbs:a.jsx(Dt,{crumbs:C7}),children:[a.jsx("h1",{className:"sr-only",children:"Versions"}),a.jsx("div",{className:"h-full overflow-hidden px-[3vw] pb-4",children:a.jsxs("div",{className:"mx-auto grid h-full max-w-[140rem] grid-rows-[auto_1fr] gap-4",children:[a.jsxs(qh,{children:[a.jsxs(qh.Column,{children:[a.jsxs(qh.Title,{children:[a.jsx(nIn,{})," Compare Dataset Versions"]}),a.jsx(qh.Description,{children:a.jsxs(Hd,{children:[a.jsx(K0e,{})," Comparing ",n.length," versions of"," ",s?.name||e?.slice(0,8)]})})]}),a.jsx(qh.Column,{children:a.jsx(de,{render:a.jsx(lc,{to:`/datasets/${e}`}),icon:a.jsx(md,{}),children:"Back to Dataset"})})]}),a.jsx(oks,{children:a.jsxs(nUt,{children:[a.jsx(hks,{datasetId:e,versionA:String(n[0]),versionB:String(n[1]),onVersionChange:p}),a.jsx(mks,{datasetId:e,versionA:n[0],versionB:n[1],allItems:d,itemsAMap:f,itemsBMap:h})]})})]})})]})}const Oks=[_s("/datasets"),{id:"dataset-new",label:"Create new dataset"}];function jks(){const e=Dr(),[t]=oi(),n=t.get("targetType"),r=LJ(n)?n:void 0,s=t.get("targetIds"),i=r&&s?s.split(",").map(l=>l.trim()).filter(Boolean):void 0,o=l=>{e(`/datasets/${l}`)};return a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:Oks}),children:[a.jsx("h1",{className:"sr-only",children:"Create new dataset"}),a.jsx("div",{}),a.jsx("div",{className:"flex h-full items-center justify-center",children:a.jsxs("div",{className:"w-full max-w-2xl overflow-y-auto px-4 py-5",children:[a.jsx(qh,{className:"mb-6 p-0",children:a.jsxs(qh.Column,{children:[a.jsxs(qh.Title,{children:[a.jsx(cx,{})," Create new dataset"]}),a.jsx(qh.Description,{children:"Datasets group test cases used to evaluate your agents and workflows."})]})}),a.jsx(jl,{className:"p-4",children:a.jsx(H1s,{targetType:r,targetIds:i,onSuccess:o,onCancel:()=>{e(-1)}})})]})})]})}const iUt=(e,{experimentId:t,targetType:n,targetId:r,experiments:s,isLoadingExperiments:i=!1,queryOptions:o})=>{const l=Ye(),c=s!==void 0,{data:u,isLoading:d}=rUt({datasetId:void 0,target:{targetType:n,targetId:r},queryOptions:{enabled:!c}}),f=c?s:u?.experiments,h=c?i:d,p=t?f?.filter(v=>v.id===t):f,m=_t({queryKey:["review-items",e,t??"all",c?"supplied":"discovered",c?void 0:n||"all",c?void 0:r||"all",p?.map(v=>[v.datasetId,v.id])],queryFn:async()=>!p||p.length===0?[]:(await Promise.all(p.map(async v=>{if(!v.datasetId)return[];try{const{results:y}=await l.listDatasetExperimentResults(v.datasetId,v.id);return y.filter(x=>x.status===e).map(x=>({id:x.id,input:x.input,output:x.output,error:x.error,itemId:x.itemId,experimentId:x.experimentId,datasetId:v.datasetId??void 0,traceId:x.traceId??void 0,scores:x.scores?Object.fromEntries(x.scores.map(b=>[b.scorerId,b.score??0])):{},tags:x.tags??[],createdAt:x.createdAt,status:x.status,groundTruth:x.groundTruth,toolMockReport:x.toolMockReport}))}catch{return[]}}))).flat(),enabled:!!f,refetchOnWindowFocus:!1,...o});return{...m,isLoading:m.isLoading||h}},Cks=(e={})=>iUt("needs-review",e),_ks=(e={})=>iUt("complete",e);function Tks({queryOptions:e}={}){const t=Ye();return _t({queryKey:["experiment-review-summary"],queryFn:()=>t.getExperimentReviewSummary(),...e})}function oUt({open:e,onOpenChange:t,experimentId:n,experimentName:r,onSuccess:s}){const{deleteExperiment:i}=pl(),o=async()=>{try{await i.mutateAsync(n),Ke.success("Experiment deleted successfully"),t(!1),s?.()}catch(l){Ke.error(`Failed to delete experiment: ${l instanceof Error?l.message:"Unknown error"}`)}};return a.jsx(Ut,{open:e,onOpenChange:t,children:a.jsxs(Ut.Content,{children:[a.jsxs(Ut.Header,{children:[a.jsx(Ut.Title,{children:"Delete Experiment"}),a.jsxs(Ut.Description,{children:['Are you sure you want to delete "',r||n,'"? This will permanently delete the experiment, all its results, and the traces it produced, including their spans and any scores, feedback, metrics and logs attached to those traces. This action cannot be undone.']})]}),a.jsxs(Ut.Footer,{children:[a.jsx(Ut.Cancel,{children:"Cancel"}),a.jsx(de,{icon:a.jsx(Xo,{}),variant:"primary",onClick:o,disabled:i.isPending,children:i.isPending?"Deleting...":"Delete"})]})]})})}const Eks="minmax(9rem,1fr)",Iks="minmax(8rem,16rem)",Nks="1fr",Aks="auto auto auto auto auto auto auto",ay={experiment:"Experiment",description:"Description",dataset:"Dataset",target:"Target",status:"Status",items:"Items",succeeded:"Processed",failed:"Errored",review:"Review",date:"Date"},Pks={completed:"neutral",running:"warning",failed:"destructive",pending:"neutral"},$ks={completed:"Run completed",running:"Run in progress",failed:"Run failed",pending:"Run queued"};function aUt(e){const t=vx(e.id)??e.id;return e.name||`Experiment #${t}`}const Rks=60;function Mks({experiment:e}){return a.jsx("span",{className:"block min-w-0 truncate text-left text-muted-foreground",children:aUt(e)})}function Dks({experiment:e}){const t=e.description;if(!t)return a.jsx("span",{className:"text-placeholder",children:"—"});const n=a.jsx("span",{className:"block min-w-0 truncate text-left text-muted-foreground",children:t});return t.length<=Rks?n:a.jsxs(Ln,{children:[a.jsx(Rn,{asChild:!0,children:n}),a.jsx(Mn,{children:t})]})}function lUt(){const{data:e}=ch(),{data:t}=Op(),{data:n}=ag(),{data:r}=E_();return{agents:e,workflows:t,scorers:n,processors:r}}const cUt={agent:ko,workflow:Ol,scorer:Ax,processor:YO},uUt={agent:"Agent",workflow:"Workflow",scorer:"Scorer",processor:"Processor"},Lks="External (caller-run)";function dUt(e,{agents:t,workflows:n,scorers:r,processors:s}){const{targetType:i,targetId:o}=e;if(!o)return Lks;switch(i){case"agent":return t?.[o]?.name??o;case"workflow":return n?.[o]?.name??o;case"scorer":return r?.[o]?.scorer?.config?.name??o;case"processor":return s?.[o]?.name??o;default:return o}}function zks({experiment:e,datasetName:t,review:n}){const r=e.status??"pending",s=e.succeededCount??0,i=e.failedCount??0,o=e.totalItems??0;return a.jsxs(a.Fragment,{children:[a.jsx(Te.Cell,{children:a.jsx(Mks,{experiment:e})}),a.jsx(Te.Cell,{children:a.jsx(Dks,{experiment:e})}),t!==void 0&&a.jsx(Te.TextCell,{children:t}),a.jsx(Te.Cell,{children:a.jsx(Fks,{experiment:e})}),a.jsx(Te.Cell,{children:a.jsx(Mt,{variant:Pks[r]??"neutral",indicator:"dot",children:$ks[r]??r})}),a.jsx(Te.TextCell,{className:"text-center",children:o}),a.jsx(Te.TextCell,{className:"text-center",children:s}),a.jsx(Te.TextCell,{className:"text-center",children:a.jsx("span",{className:i>0?"text-destructive-foreground":"",children:i})}),a.jsx(Te.Cell,{className:"text-center",children:a.jsx(Bks,{review:n})}),a.jsx(Te.TextCell,{children:os(e.createdAt,"date")??"—"})]})}function Fks({experiment:e}){const t=lUt(),n=dUt(e,t),r=e.targetId?e.targetType:null,s=r?cUt[r]:null;return a.jsxs("span",{className:"flex min-w-0 items-center gap-1.5 [&_svg]:size-3.5 [&_svg]:shrink-0",children:[s&&a.jsx("span",{className:"flex text-muted-foreground",role:"img","aria-label":uUt[r],children:a.jsx(s,{})}),a.jsx("span",{className:r?"truncate":"truncate text-placeholder",children:n})]})}function Bks({review:e}){if(!e)return a.jsx("span",{className:"text-placeholder",children:"—"});const t=e.needsReview+e.complete;return t===0?a.jsx("span",{className:"text-placeholder",children:"—"}):e.needsReview>0?a.jsxs(Mt,{size:"xs",variant:"warning",children:[e.needsReview," pending"]}):a.jsxs(Mt,{size:"xs",variant:"success",children:[e.complete,"/",t," reviewed"]})}const fUt=`${Eks} ${Iks} ${Nks} ${Aks}`,ctt=`${fUt} auto`,Vks=[{label:ay.experiment},{label:ay.description},{label:ay.dataset},{label:ay.target},{label:ay.status,sortKey:"status"},{label:ay.items,className:"text-center"},{label:ay.succeeded,className:"text-center"},{label:ay.failed,className:"text-center"},{label:ay.review,className:"text-center"},{label:ay.date,sortKey:"createdAt"}],hUt=e=>e.stopPropagation();function Uks({experiment:e,rowProps:t,onSelect:n,featured:r,onDelete:s,children:i}){const{paths:o,Link:l}=xn(),c=g.useRef(null);return a.jsxs(Te.RowWrapper,{...t,onSelectRow:n??(()=>c.current?.click()),children:[n?a.jsx(Te.RowButton,{colEnd:-2,featured:r,tabIndex:-1,onClick:u=>{u.stopPropagation(),n()},children:i}):a.jsx(Te.RowLink,{ref:c,colEnd:-2,to:o.experimentLink(e.id),LinkComponent:l,tabIndex:-1,onClick:hUt,children:i}),a.jsx(Te.ActionsCell,{className:"pl-2",children:a.jsx(de,{type:"button",variant:"ghost",size:"icon-sm",tooltip:"Delete experiment","aria-label":`Delete experiment ${e.name??e.id}`,onClick:u=>{u.stopPropagation(),s()},children:a.jsx(Xo,{className:"size-4"})})})]})}function qks({experiments:e,datasets:t,reviewByExperiment:n,isLoading:r,search:s="",statusFilter:i="all",datasetFilter:o="all",selection:l,onSelectExperiment:c,selectedExperimentId:u,keyboardGlobal:d=!0,isFetchingNextPage:f,hasNextPage:h,setEndOfListElement:p,sort:m,onSortChange:v}){const y=l!==void 0,x=g.useMemo(()=>{const I=new Map;return t?.forEach(A=>I.set(A.id,A.name)),I},[t]),b=g.useMemo(()=>m?e:[...e].sort((I,A)=>{const P=I.createdAt?new Date(I.createdAt).getTime():0;return(A.createdAt?new Date(A.createdAt).getTime():0)-P}),[e,m]),S=g.useMemo(()=>{const I=s.toLowerCase();return b.filter(A=>{const P=A.datasetId?x.get(A.datasetId)??"":"",D=!I||A.id.toLowerCase().includes(I)||(A.name??"").toLowerCase().includes(I)||P.toLowerCase().includes(I)||(A.targetId??"").toLowerCase().includes(I),F=i==="all"||A.status===i,Q=o==="all"||A.datasetId===o;return D&&F&&Q})},[b,s,x,i,o]),{containerRef:k,getRowProps:j}=Du({count:S.length,global:d}),[C,T]=g.useState(null);if(r)return a.jsx($u,{columns:ctt});const _=y?`auto ${fUt}`:ctt,N=Vks.map(I=>I.sortKey&&v?a.jsx(Te.SortableTopCell,{className:I.className,sortKey:I.sortKey,sort:m?.key===I.sortKey?m.direction:void 0,onSortChange:v,children:I.label},I.label):a.jsx(Te.TopCell,{className:I.className,children:I.label},I.label));return a.jsxs(Te,{columns:_,scrollRef:k,children:[a.jsx(Te.Top,{hasLeadingCell:y,children:y?a.jsxs(a.Fragment,{children:[a.jsx(Te.TopCell,{children:" "}),a.jsx(Te.TopCells,{colStart:2,children:N})]}):a.jsxs(a.Fragment,{children:[N,a.jsx(Te.TopCell,{"aria-hidden":!0,children:null})]})}),S.map((I,A)=>{const P=I.datasetId?x.get(I.datasetId)??vx(I.datasetId)??I.datasetId:"—",D=a.jsx(zks,{experiment:I,datasetName:P,review:n?.get(I.id)});if(!l)return a.jsx(Uks,{experiment:I,rowProps:j(A),onSelect:c?()=>c(I):void 0,featured:u===I.id,onDelete:()=>T(I),children:D},I.id);const F=l.selectedExperimentIds.includes(I.id),Q=()=>l.onToggleSelection(I.id);return a.jsxs(Te.RowWrapper,{...j(A),onSelectRow:Q,children:[a.jsx(Te.SelectCell,{checked:F,onToggle:Q,"aria-label":`Select experiment ${I.id}`}),a.jsx(Te.RowButton,{colStart:2,featured:F,tabIndex:-1,onClick:hUt,children:D})]},I.id)}),a.jsx(Te.NextPageLoading,{isLoading:f,hasMore:h,setEndOfListElement:p}),C&&a.jsx(oUt,{open:!0,onOpenChange:I=>{I||T(null)},experimentId:C.id,experimentName:C.name??void 0})]})}const Qks=[{value:"all",label:"All statuses"},{value:"completed",label:"Completed"},{value:"running",label:"Running"},{value:"failed",label:"Failed"},{value:"pending",label:"Pending"}];function Zks(e){return[{value:"all",label:"All datasets"},...(e??[]).map(t=>({value:t.id,label:t.name}))]}const Wks=({onRunExperiment:e})=>a.jsx(Xt,{titleSlot:"No Experiments yet",descriptionSlot:a.jsxs(a.Fragment,{children:["Run an experiment from a dataset to evaluate ",a.jsx("br",{}),"your agents and workflows."]}),actionSlot:a.jsxs("div",{className:"flex flex-col items-center gap-2",children:[e&&a.jsx(de,{variant:"primary",onClick:e,icon:a.jsx(Bc,{}),children:"Run Experiment"}),a.jsx(de,{variant:"ghost",render:a.jsx("a",{href:"https://mastra.ai/docs/evals/experiments",target:"_blank",rel:"noopener noreferrer"}),icon:a.jsx(Zs,{}),children:"Experiments Documentation"})]}),variant:"fill"});function Hks({search:e,onSearchChange:t,statusFilter:n,onStatusFilterChange:r,datasetFilter:s,onDatasetFilterChange:i,datasetOptions:o,targetType:l,onTargetTypeChange:c,targetId:u,onTargetIdChange:d,onReset:f,hasActiveFilters:h,onRunClick:p,runTooltip:m="Run an experiment",onCompareClick:v,selection:y}){const x=y?.selectedCount===2&&!y.compareDisabledReason;return a.jsxs(Xn,{children:[a.jsxs(Xn.Start,{children:[a.jsx("div",{className:"max-w-120 flex-1",children:a.jsx(Ru,{label:"Search experiments",placeholder:"Filter by experiment, dataset, or target",value:e,onSearch:t})}),a.jsxs(Vr,{value:n,onValueChange:r,children:[a.jsx(qr,{"aria-label":"Status",size:"md",className:"whitespace-nowrap",children:a.jsx(Ur,{placeholder:"Select an option"})}),a.jsx(Qr,{children:Qks.map(b=>a.jsx(ir,{value:b.value,children:b.label},b.value))})]}),a.jsxs(Vr,{value:s,onValueChange:i,children:[a.jsx(qr,{"aria-label":"Dataset",size:"md",className:"whitespace-nowrap",children:a.jsx(Ur,{placeholder:"Select an option"})}),a.jsx(Qr,{children:o.map(b=>a.jsx(ir,{value:b.value,children:b.label},b.value))})]}),a.jsx(FVt,{targetType:l,targetId:u,onTargetTypeChange:c,onTargetIdChange:d}),f&&h&&a.jsx(de,{onClick:f,size:"sm",variant:"default",icon:a.jsx(Dn,{}),children:"Reset"})]}),y?a.jsx(Xn.End,{children:a.jsxs(Ql,{className:"whitespace-nowrap",children:[a.jsxs(Yh,{className:"gap-2",children:[a.jsxs(Mt,{size:"sm",variant:y.selectedCount<2?"destructive":"success",children:[y.selectedCount," / 2"]}),"selected",y.compareDisabledReason&&a.jsxs("span",{className:"text-destructive-foreground",children:["· ",y.compareDisabledReason]})]}),a.jsx(de,{variant:"primary",disabled:!x,onClick:y.onExecuteCompare,icon:a.jsx(KLe,{}),children:"Compare Experiments"}),a.jsx(de,{icon:a.jsx(Dn,{}),onClick:y.onCancelSelection,children:"Cancel"})]})}):a.jsxs(Xn.End,{children:[v&&a.jsx(de,{onClick:v,tooltip:"Select two experiments of the same dataset to compare",icon:a.jsx(KLe,{}),children:"Compare"}),p&&a.jsx(de,{onClick:p,tooltip:m,variant:"primary",icon:a.jsx(Bc,{}),children:"Run Experiment"})]})]})}const Gks={present:!1,output:null,metadata:null,comment:null,error:null,startedAt:null,completedAt:null,scores:[]},utt=e=>e?e instanceof Date?e.toISOString():e:null,dtt=e=>{const t=new Map;for(const n of e??[])t.set(n.itemId,n);return t},ftt=(e,t,n)=>{if(!e)return Gks;const r=new Map;for(const s of n??[])r.set(s.scorerId,s.reason??null);return{present:!0,output:e.output,metadata:t?.metadata??null,comment:t?.comment??null,error:t?.error??null,startedAt:utt(t?.startedAt),completedAt:utt(t?.completedAt),scores:Object.entries(e.scores).map(([s,i])=>({scorerId:s,value:i,reason:r.get(s)??null})).sort((s,i)=>s.scorerId.localeCompare(i.scorerId))}},Kks=({comparison:e,baselineId:t,contenderId:n,baselineResults:r,contenderResults:s,baselineScores:i,contenderScores:o})=>{if(!e)return[];const l=dtt(r),c=dtt(s);return e.items.map(u=>{const d=ftt(u.results[t],l.get(u.itemId),i?.[u.itemId]),f=ftt(u.results[n],c.get(u.itemId),o?.[u.itemId]),h={};for(const p of new Set([...d.scores,...f.scores].map(m=>m.scorerId))){const m=d.scores.find(y=>y.scorerId===p)?.value??null,v=f.scores.find(y=>y.scorerId===p)?.value??null;h[p]=m!=null&&v!=null?v-m:null}return{itemId:u.itemId,input:u.input,groundTruth:u.groundTruth,baseline:d,contender:f,deltas:h}})};function tj({title:e,actions:t,tone:n="default",defaultOpen:r=!0,children:s}){return a.jsxs(Kl,{defaultOpen:r,className:"grid gap-2",children:[a.jsxs("div",{className:"flex min-h-6 items-center justify-between gap-2",children:[a.jsxs(Cl,{className:Z("flex items-center gap-1.5",n==="negative"?"text-destructive-foreground":"text-foreground","text-subheading"),children:[a.jsx(Na,{direction:"right",className:"size-4"}),e]}),t]}),a.jsx(_l,{role:"region","aria-label":e,children:s})]})}function htt({label:e,value:t}){return t==null?null:a.jsx(tj,{title:e,defaultOpen:!1,children:a.jsx(cl,{className:"max-h-40 overflow-auto rounded-md bg-card p-3 text-caption whitespace-pre-wrap text-muted-foreground",code:typeof t=="string"?t:JSON.stringify(t,null,2)})})}function pUt({delta:e}){const t=e>0?"text-success-indicator":e<0?"text-destructive-foreground":"text-muted-foreground";return a.jsxs("span",{className:Z("inline-flex min-w-20 items-center gap-1 tabular-nums",t),children:[a.jsx(Y,{as:"span",className:"inline-block w-3",children:e>0?"+":e<0?"-":""}),a.jsx(Y,{as:"span",children:Math.abs(e).toFixed(2)}),e>0?a.jsx(R0e,{className:"size-3.5"}):e<0?a.jsx(Rft,{className:"size-3.5"}):null]})}function mUt({scorerId:e,value:t,delta:n,reason:r}){const{Link:s,paths:i}=xn();return a.jsxs("div",{className:"grid gap-1 rounded-lg bg-background px-3 py-2",children:[a.jsxs("div",{className:"flex items-center justify-between gap-4",children:[a.jsxs(s,{href:i.scorerLink(e),"aria-label":`Open ${e}`,className:"flex min-w-0 items-center gap-1.5 text-foreground hover:underline [&>svg]:size-3.5 [&>svg]:shrink-0",children:[a.jsx(Ax,{}),a.jsx(Y,{as:"span",variant:"subheading",className:"min-w-0 truncate",children:e})]}),a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx(Y,{as:"span",tone:"muted",className:"tabular-nums",children:t!=null?t.toFixed(2):"-"}),n!=null&&a.jsx(pUt,{delta:n})]})]}),r&&a.jsx(Y,{tone:"muted",children:r})]})}function ptt(e){return e==null?"-":typeof e=="string"?e:JSON.stringify(e,null,2)}function Yks(e){if(!e.startedAt||!e.completedAt)return null;const t=new Date(e.completedAt).getTime()-new Date(e.startedAt).getTime();return sf(t)??null}const Xks=Z(pr,"max-h-[30vh] overflow-y-auto rounded-xl p-4 break-all whitespace-pre-wrap");function mtt({side:e,row:t,showDeltas:n,isLoading:r}){const s=t[e],i=Yks(s);if(r)return a.jsx("div",{className:"flex h-32 items-center justify-center",children:a.jsx(En,{})});if(!s.present)return a.jsx(Y,{tone:"muted",className:"py-5 text-center",children:"Not present in this experiment"});const o=ptt(s.output);return a.jsxs("div",{className:"grid content-start gap-5",children:[i&&a.jsxs(Ln,{children:[a.jsx(Rn,{render:a.jsxs(Y,{tone:"muted",className:"flex items-center justify-end gap-1.5 [&>svg]:size-3.5",children:[a.jsx(ON,{}),a.jsx(Y,{as:"span",variant:"body",font:"mono",children:i})]})}),a.jsx(Mn,{children:"Run duration"})]}),s.error?a.jsx(tj,{title:"Error",tone:"negative",actions:a.jsx(Zi,{content:s.error.message}),children:a.jsx(Y,{tone:"muted",className:"rounded-xl border border-destructive-edge bg-destructive-subtle p-4 break-words",children:s.error.message})}):a.jsx(tj,{title:"Output",actions:a.jsx(Zi,{content:o}),children:a.jsx(cl,{className:Z(Xks,"font-mono text-body text-muted-foreground"),code:o})}),s.scores.length>0&&a.jsx(tj,{title:"Scores",children:a.jsx("div",{className:"grid gap-2",children:s.scores.map(l=>a.jsx(mUt,{scorerId:l.scorerId,value:l.value,delta:n?t.deltas[l.scorerId]:null,reason:l.reason},l.scorerId))})}),s.comment&&a.jsx(tj,{title:"Comment",defaultOpen:!1,children:a.jsx(Y,{tone:"muted",children:s.comment})}),s.metadata&&Object.keys(s.metadata).length>0&&a.jsx(tj,{title:"Metadata",defaultOpen:!1,children:a.jsx("dl",{className:"grid gap-1",children:Object.entries(s.metadata).map(([l,c])=>a.jsxs("div",{className:"flex items-start justify-between gap-4",children:[a.jsx("dt",{className:Da({tone:"muted",variant:"body"}),children:l}),a.jsx("dd",{className:Z(Da({tone:"ink",variant:"body",font:"mono"}),"break-all"),children:ptt(c)})]},l))})})]})}const Jks={baseline:"Baseline",contender:"Contender"},eOs={baseline:"purple",contender:"blue"},tOs="flex min-w-0 items-center gap-1.5 hover:underline [&>svg]:size-3.5 [&>svg]:shrink-0";function gtt({side:e,experiment:t,summary:n,showDeltas:r,versionMismatch:s}){const{Link:i,paths:o}=xn(),l=Jks[e],c=t?vx(t.id)??t.id:null,u=t?.createdAt?new Date(t.createdAt):null,d=n??[];return a.jsxs("div",{className:"grid content-start gap-3",children:[a.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[a.jsx(Mt,{variant:eOs[e],size:"xs",children:l}),t&&a.jsx(de,{render:a.jsx(i,{href:`/experiments/${t.id}`}),size:"sm","aria-label":`Open experiment ${t.name||c}`,children:a.jsx("span",{className:"min-w-0 truncate",children:t.name||c})})]}),t&&a.jsxs("div",{className:"flex flex-wrap gap-x-4 gap-y-1 text-muted-foreground",children:[t.name&&a.jsxs(Hd,{children:[a.jsx(x_,{})," ",c]}),t.targetType==="agent"&&t.targetId?a.jsxs(i,{href:o.agentLink(t.targetId),className:tOs,children:[a.jsx(ko,{}),a.jsx("span",{className:"min-w-0 truncate",children:t.targetId})]}):a.jsxs(Hd,{children:[a.jsx(kht,{})," ",t.targetId]}),a.jsxs(Hd,{className:Z(s&&"text-warning-foreground"),children:[a.jsx(tL,{})," v",t.datasetVersion??"—",s&&" · different dataset version"]}),u&&a.jsxs(Hd,{children:[a.jsx($U,{})," ",os(u,"date-time")]})]}),d.length>0&&a.jsx(tj,{title:"Overall score",children:a.jsx("div",{className:"grid gap-2",children:d.map(({scorerId:f,average:h,delta:p})=>a.jsx(mUt,{scorerId:f,value:h,delta:r?p:null},f))})})]})}const yE="min-w-0 px-4 py-3";function nOs({datasetId:e,experimentIdA:t,experimentIdB:n}){const{Link:r,paths:s}=xn(),{data:i,isLoading:o,error:l}=par({datasetId:e,experimentIdA:t,experimentIdB:n,queryOptions:{enabled:!!e&&!!t&&!!n}}),{data:c,isLoading:u}=g5({datasetId:e,experimentId:t,queryOptions:{enabled:!!e&&!!t}}),{data:d,isLoading:f}=g5({datasetId:e,experimentId:n,queryOptions:{enabled:!!e&&!!n}}),h=c&&d&&c.datasetVersion!==d.datasetVersion,p=i?.baselineId??t,m=t===p?n:t,v=c?.id===p?c:d,y=c?.id===m?c:d,{data:x,isLoading:b}=$pe({datasetId:e,experimentId:p,experimentStatus:v?.status,queryOptions:{enabled:!!e&&!!p}}),{data:S,isLoading:k}=$pe({datasetId:e,experimentId:m,experimentStatus:y?.status,queryOptions:{enabled:!!e&&!!m}}),{data:j}=AS({experimentId:p,experimentStatus:v?.status,queryOptions:{enabled:!!p}}),{data:C}=AS({experimentId:m,experimentStatus:y?.status,queryOptions:{enabled:!!m}}),T=g.useMemo(()=>Kks({comparison:i,baselineId:p,contenderId:m,baselineResults:x,contenderResults:S,baselineScores:j,contenderScores:C}),[i,p,m,x,S,j,C]),_=g.useMemo(()=>[...new Set(T.flatMap(I=>Object.keys(I.deltas)))].sort(),[T]),N=g.useMemo(()=>{const I=(D,F)=>{const Q=T.map(q=>q[D].scores.find(B=>B.scorerId===F)?.value).filter(q=>q!=null);return Q.length>0?Q.reduce((q,B)=>q+B,0)/Q.length:null},A=_.map(D=>({scorerId:D,average:I("baseline",D),delta:null})),P=_.map(D=>{const F=I("baseline",D),Q=I("contender",D);return{scorerId:D,average:Q,delta:F!=null&&Q!=null?Q-F:null}});return{baseline:A,contender:P}},[T,_]);return o||u||f?a.jsx("div",{className:"flex h-64 items-center justify-center",children:a.jsx(En,{})}):l?a.jsx(Ht,{variant:"warning",title:"Error loading comparison",children:a.jsx(Ht.Message,{children:l instanceof Error?l.message:"Unknown error"})}):!i||i.items.length===0?a.jsx(Y,{as:"p",variant:"body",tone:"muted",className:"py-5 text-center",children:"No comparison data"}):a.jsx("div",{className:"grid gap-4",children:a.jsxs("div",{role:"table","aria-label":"Experiments comparison",className:"grid",children:[a.jsxs("div",{role:"row",className:"grid border-y border-border xl:grid-cols-[minmax(20rem,24rem)_1fr_1fr] xl:divide-x xl:divide-border",children:[a.jsx("div",{role:"columnheader","aria-label":"Items",className:Z("text-muted-foreground",`${yE} uppercase`),children:a.jsx(Y,{as:"span",variant:"caption",className:"block",children:"Items"})}),a.jsx("div",{role:"columnheader","aria-label":"Baseline",className:yE,children:a.jsx(gtt,{side:"baseline",experiment:v??void 0,summary:N.baseline,versionMismatch:h??void 0})}),a.jsx("div",{role:"columnheader","aria-label":"Contender",className:yE,children:a.jsx(gtt,{side:"contender",experiment:y??void 0,summary:N.contender,versionMismatch:h??void 0,showDeltas:!0})})]}),T.map(I=>{const A=Object.entries(I.deltas).flatMap(([P,D])=>D==null||D===0?[]:[{scorerId:P,delta:D}]);return a.jsxs("div",{role:"row","aria-label":I.itemId,className:"grid border-b border-border xl:grid-cols-[minmax(20rem,24rem)_1fr_1fr] xl:divide-x xl:divide-border",children:[a.jsxs("div",{role:"cell",className:`${yE} grid content-start gap-1`,children:[a.jsx(r,{href:s.datasetItemLink(e,I.itemId),"aria-label":`Open item ${I.itemId}`,className:Z(I.baseline.present&&I.contender.present?"text-muted-foreground":"text-placeholder","flex items-start gap-1.5 break-all hover:underline [&>svg]:mt-0.5 [&>svg]:size-3.5 [&>svg]:shrink-0"),children:a.jsx(Y,{as:"span",variant:"caption",font:"mono",className:"min-w-0",children:I.itemId})}),A.length>0&&a.jsx("span",{className:"flex flex-wrap items-center gap-2",children:A.map(({scorerId:P,delta:D})=>a.jsx(pUt,{delta:D},P))}),a.jsxs("div",{className:"grid pt-3",children:[a.jsx(htt,{label:"Input",value:I.input}),a.jsx(htt,{label:"Ground truth",value:I.groundTruth})]})]}),a.jsx("div",{role:"cell","aria-label":"Baseline",className:yE,children:a.jsx(mtt,{side:"baseline",row:I,isLoading:b})}),a.jsx("div",{role:"cell","aria-label":"Contender",className:yE,children:a.jsx(mtt,{side:"contender",row:I,isLoading:k,showDeltas:!0})})]},I.itemId)})]})})}function rOs(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}const xE=[_s("/experiments")],sOs=["createdAt","status"];function iOs(){const[e,t]=g.useState(""),[n,r]=g.useState("all"),[s,i]=g.useState(!1),[o,l]=g.useState(!1),[c,u]=g.useState([]),d=Dr(),[f,h]=oi(),{sort:p,onSortChange:m}=zk({searchParams:f,setSearchParams:h,allowedKeys:sOs}),v=g.useMemo(()=>p?{field:p.key,direction:p.direction==="asc"?"ASC":"DESC"}:void 0,[p]),y=f.get("dataset")??"all",x=g.useCallback(ue=>{h(ee=>{const se=new URLSearchParams(ee);return ue==="all"?se.delete("dataset"):se.set("dataset",ue),se},{replace:!0})},[h]),{targetType:b,targetId:S,setTargetType:k,setTargetId:j}=BVt(),{data:C,isLoading:T,error:_}=Sk(),{data:N,isLoading:I,error:A,isFetchingNextPage:P,hasNextPage:D,setEndOfListElement:F}=cks({datasetId:y==="all"?void 0:y,target:{targetType:b,targetId:S},orderBy:v}),{data:Q}=Tks(),q=g.useMemo(()=>C?.datasets??[],[C?.datasets]),B=g.useMemo(()=>N??[],[N]),V=g.useMemo(()=>Zks(q),[q]),H=g.useMemo(()=>rOs(Q),[Q]),M=T||I,G=A||_,L=ue=>{const ee=new Set(B.map(se=>se.id));u(se=>{const re=se.filter(ae=>ee.has(ae));return re.includes(ue)?re.filter(ae=>ae!==ue):re.length>=2?[re[0],ue]:[...re,ue]})},$=()=>{u([]),l(!1)},{selectedIds:z,selectedDatasetIds:U}=g.useMemo(()=>{const ue=new Map(B.map(se=>[se.id,se.datasetId])),ee=c.filter(se=>ue.has(se));return{selectedIds:ee,selectedDatasetIds:new Set(ee.map(se=>ue.get(se)))}},[B,c]),K=z.length===2&&U.size!==1?"not the same dataset":void 0,ne=()=>{if(z.length!==2||K)return;const[ue,ee]=z,[se]=U;if(!se)return;const re=new URLSearchParams({dataset:se,baseline:ue,contender:ee});d(`/experiments/compare?${re.toString()}`)};if(G&&js(G))return a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:xE}),children:[a.jsx("h1",{className:"sr-only",children:"Experiments"}),a.jsx(ai,{variant:"fill"})]});if(A&&Cs(A))return a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:xE}),children:[a.jsx("h1",{className:"sr-only",children:"Experiments"}),a.jsx(Gs,{variant:"fill",resource:"experiments"})]});if(_&&Cs(_))return a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:xE}),children:[a.jsx("h1",{className:"sr-only",children:"Experiments"}),a.jsx(Gs,{variant:"fill",resource:"datasets"})]});if(G)return a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:xE}),children:[a.jsx("h1",{className:"sr-only",children:"Experiments"}),a.jsx(Xt,{tone:"error",variant:"fill",titleSlot:"Failed to load experiments",descriptionSlot:G.message})]});const X=a.jsx(FJ,{open:s,onOpenChange:i,onSuccess:ue=>{d(`/experiments/${ue}`)}});if(B.length===0&&!M&&y==="all"&&!b)return a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:xE}),children:[a.jsx("h1",{className:"sr-only",children:"Experiments"}),a.jsx(Wks,{onRunExperiment:()=>i(!0)}),X]});const te=n!=="all"||y!=="all"||e!==""||b!=="",ie=()=>{t(""),r("all"),h(ue=>{const ee=new URLSearchParams(ue);return ee.delete("dataset"),ee.delete(qj),ee.delete(I1),ee},{replace:!0})};return a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:xE}),actionRow:a.jsx(Hks,{search:e,onSearchChange:t,statusFilter:n,onStatusFilterChange:r,datasetFilter:y,onDatasetFilterChange:x,datasetOptions:V,targetType:b,onTargetTypeChange:k,targetId:S,onTargetIdChange:j,onReset:ie,hasActiveFilters:te,onRunClick:()=>i(!0),onCompareClick:()=>l(!0),selection:o?{selectedCount:z.length,onExecuteCompare:ne,onCancelSelection:$,compareDisabledReason:K}:void 0}),children:[a.jsx("h1",{className:"sr-only",children:"Experiments"}),a.jsx(qks,{experiments:B,datasets:q,reviewByExperiment:H,isLoading:M,search:e,statusFilter:n,datasetFilter:y,isFetchingNextPage:P,hasNextPage:D,setEndOfListElement:F,sort:p,onSortChange:m,selection:o?{selectedExperimentIds:z,onToggleSelection:L}:void 0}),X]})}function _7({experimentId:e}){const{Link:t,paths:n}=xn();return a.jsx(de,{render:a.jsx(t,{href:n.experimentLink(e)}),size:"sm","aria-label":`Open experiment ${e}`,children:e.slice(0,8)})}function oOs({datasetId:e,experimentIdA:t,experimentIdB:n}){const[,r]=oi(),s=g5({datasetId:e,experimentId:t}),i=g5({datasetId:e,experimentId:n}),o=s.isLoading||i.isLoading,l=s.error??i.error;return l&&js(l)?a.jsxs(a.Fragment,{children:[a.jsx(Y,{as:"h1",variant:"heading",className:"sr-only",children:"Compare"}),a.jsx(ai,{variant:"fill"})]}):l&&Cs(l)?a.jsxs(a.Fragment,{children:[a.jsx(Y,{as:"h1",variant:"heading",className:"sr-only",children:"Compare"}),a.jsx(Gs,{variant:"fill",resource:"experiments"})]}):l&&!kk(l)?a.jsxs(a.Fragment,{children:[a.jsx(Y,{as:"h1",variant:"heading",className:"sr-only",children:"Compare"}),a.jsx(Xt,{tone:"error",variant:"fill",titleSlot:"Failed to load experiments",descriptionSlot:l.message})]}):!o&&(l||!s.data||!i.data)?a.jsxs(a.Fragment,{children:[a.jsx(Y,{as:"h1",variant:"heading",className:"sr-only",children:"Compare"}),a.jsx("div",{className:"grid h-full min-w-min content-start items-start overflow-x-auto overflow-y-auto",children:a.jsxs("div",{className:"py-5 text-center text-muted-foreground",children:[a.jsxs(Y,{as:"p",children:["Experiments must belong to the same dataset (",e,") to be compared."]}),a.jsxs(Y,{className:"mt-2 flex items-center justify-center gap-2",children:["One of",a.jsx(_7,{experimentId:t}),"and",a.jsx(_7,{experimentId:n}),"was not found in it."]})]})})]}):a.jsx("div",{className:"grid h-full min-w-min content-start items-start overflow-x-auto overflow-y-auto",children:a.jsxs("div",{className:"grid w-full content-start",children:[a.jsxs("div",{className:"flex items-center justify-between gap-4 px-4 py-3",children:[a.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[a.jsx(Y,{as:"h1",variant:"heading",tone:"ink",children:"Experiments comparison"}),a.jsxs(Y,{variant:"caption",tone:"muted",className:"flex items-center gap-2",children:[a.jsx(_7,{experimentId:t}),"and",a.jsx(_7,{experimentId:n})]})]}),a.jsxs(Ln,{children:[a.jsx(Rn,{render:a.jsx(de,{onClick:()=>r({dataset:e,baseline:n,contender:t}),icon:a.jsx(Mft,{}),children:"Swap sides"})}),a.jsx(Mn,{children:"Switch baseline and contender"})]})]}),a.jsx(nOs,{datasetId:e,experimentIdA:t,experimentIdB:n})]})})}function aOs(){const[e]=oi(),t=e.get("dataset")??void 0,n=e.get("baseline")??void 0,r=e.get("contender")??void 0;return!t||!n||!r?a.jsxs(a.Fragment,{children:[a.jsx(Y,{as:"h1",variant:"heading",className:"sr-only",children:"Compare"}),a.jsx("div",{className:"grid h-full min-w-min content-start items-start overflow-x-auto overflow-y-auto",children:a.jsxs("div",{className:"py-5 text-center text-muted-foreground",children:[a.jsx(Y,{as:"p",children:"Select two experiments to compare."}),a.jsxs(Y,{className:"mt-2",children:["Use the URL format: /experiments/compare?dataset=","{datasetId}","&baseline=","{experimentIdA}","&contender=","{experimentIdB}"]})]})})]}):a.jsx(oOs,{datasetId:t,experimentIdA:n,experimentIdB:r})}const lOs=[_s("/experiments"),{id:"experiments-compare",label:"Compare"}];function cOs(){return a.jsx(Et,{variant:"fit",breadcrumbs:a.jsx(Dt,{crumbs:lOs}),children:a.jsx(aOs,{})})}function uOs(e){const{data:t}=J_({traceId:e,queryOptions:{enabled:!!e}}),r=t?.spans.find(o=>!o.parentSpanId)?.entityType==="agent",{supportsMetrics:s}=wz(),i=cye({traceIds:e?[e]:[],enabled:r&&s,autoRefetch:!1});return e?i.data?.get(e):void 0}const vtt="__create_tag__";function gUt({selectedResults:e,vocabulary:t,onAddTag:n,disabled:r,appearance:s="toolbar"}){const[i,o]=g.useState(""),l=g.useMemo(()=>[...t].sort(),[t]),c=g.useMemo(()=>{if(e.length===0)return new Set;const[f,...h]=e;return new Set((f.tags??[]).filter(p=>h.every(m=>(m.tags??[]).includes(p))))},[e]),u=g.useMemo(()=>{const f=l.map(m=>({label:m,value:m,end:c.has(m)?a.jsx(dr,{"data-testid":"tag-applied",className:"size-3.5"}):void 0})),h=i.trim();return h.length>0&&!l.includes(h)?[{label:`Create "${h}"`,value:vtt},...f]:f},[l,c,i]),d=f=>{const h=f===vtt?i.trim():f;!h||c.has(h)||n(h)};return a.jsx(Qa,{"data-testid":"experiment-results-tag-picker",options:u,value:void 0,onValueChange:d,onInputValueChange:o,placeholder:a.jsxs("span",{className:"flex items-center gap-1.5",children:[a.jsx(uk,{className:"size-3.5"}),"Add tag"]}),searchPlaceholder:"Search or create tag...",emptyText:"Type to create a tag",variant:s==="inline"?"ghost":"default",size:s==="inline"?"sm":"md",className:"w-auto min-w-0",disabled:r})}function oue(e){try{return JSON.stringify(e??{})}catch{return String(e)}}function dOs({report:e}){const{served:t,unconsumed:n,liveCalls:r,failure:s}=e,i=[...t.map(o=>({outcome:"served",toolName:o.toolName,args:o.args})),...r.map(o=>({outcome:"live",toolName:o.toolName,args:o.args})),...n.map(o=>({outcome:"unconsumed",toolName:o.toolName,args:o.args}))];return a.jsxs("div",{className:"grid gap-2","data-testid":"tool-mock-report",children:[a.jsx(Ot.SectionHeading,{icon:a.jsx(cd,{}),children:"Tool Mocks"}),s&&a.jsx(Ht,{variant:"destructive",title:"Mock mismatch",children:a.jsxs(Ht.Message,{children:[a.jsx("span",{className:"block",children:`Tool "${s.toolName}" was called with arguments that did not match an available mock (${s.code}).`}),a.jsxs(Y,{as:"span",variant:"caption",className:"mt-1 block",children:["Called with: ",a.jsx(ih,{children:oue(s.args)})]}),n.length>0&&a.jsxs(Y,{as:"span",variant:"caption",className:"mt-1 block",children:["Unconsumed mocks: ",a.jsx(ih,{children:n.map(o=>oue(o.args)).join(", ")})]})]})}),a.jsx("div",{className:"divide-y divide-border rounded border border-border",children:i.map((o,l)=>a.jsxs("div",{className:"flex items-center justify-between gap-2 px-3 py-1.5",children:[a.jsxs(Y,{as:"span",variant:"body",className:"min-w-0 truncate",children:[a.jsx(Y,{as:"span",variant:"body-sm",tone:"muted",font:"mono",children:o.toolName}),a.jsx(Y,{as:"span",variant:"caption",tone:"muted",font:"mono",className:"ml-2",children:oue(o.args)})]}),a.jsx(Y,{as:"span",variant:"caption",className:`shrink-0 rounded px-2 py-0.5 ${fOs(o.outcome)}`,children:o.outcome})]},`${o.outcome}-${o.toolName}-${l}`))})]})}function fOs(e){switch(e){case"served":return"bg-success-subtle text-success-subtle-foreground";case"live":return"bg-badge-orange-subtle text-badge-orange-foreground";case"unconsumed":return"bg-muted-foreground/10 text-muted-foreground"}}function hOs({result:e,itemId:t,fallback:n,title:r,onClose:s,...i}){const o=r??(t?`Experiment item ${t}`:`Result ${e?.id??""}`);return a.jsx(Ot,{open:!!(e??t),onClose:s,title:o,depth:1,size:"half",children:e?a.jsx(pOs,{result:e,onClose:s,...i}):t?a.jsxs(a.Fragment,{children:[a.jsxs(Ot.Header,{children:[a.jsx(Ot.CloseButton,{onClick:s,tooltip:"Close result panel"}),a.jsxs(Ot.Heading,{children:["Experiment item",a.jsx(Ot.CopyId,{id:t})]})]}),n]}):null})}function pOs({result:e,scores:t,onPrevious:n,onNext:r,onClose:s,onShowTrace:i,onScoreClick:o,featuredScoreId:l,onFlagForReview:c,onTagsChange:u,tagVocabulary:d=[],isUpdatingTags:f=!1,experimentLink:h,onComplete:p,feedbackTabSlot:m}){const v=!!e?.error,y=T7(e?.input),x=T7(e?.output),b=T7(e?.groundTruth),S=c&&e.status!=="needs-review"&&e.status!=="complete",k=Array.isArray(e.tags)?e.tags:[],j=g.useMemo(()=>[e],[e]),C=!!u||k.length>0,{Link:T}=xn(),_=m&&e.traceId?e.traceId:void 0,{data:N}=_J({traceId:_,queryOptions:{enabled:!!_}}),I=uOs(e.traceId),A=a.jsxs(Ot.Content,{children:[a.jsxs("div",{className:"mb-6 grid gap-4",children:[a.jsxs(zt,{children:[a.jsx(zt.Key,{children:"Item Id"}),a.jsx(zt.ValueWithCopyBtn,{copyTooltip:"Copy Item Id to clipboard",copyValue:e.itemId,children:e.itemId}),e.createdAt&&a.jsxs(a.Fragment,{children:[a.jsx(zt.Key,{children:"Created"}),a.jsx(zt.Value,{children:os(e.createdAt,"date-time")})]}),e.status&&a.jsxs(a.Fragment,{children:[a.jsx(zt.Key,{children:"Status"}),a.jsx(zt.Value,{children:a.jsx(DNe,{status:e.status})})]}),C&&a.jsxs(a.Fragment,{children:[a.jsx(zt.Key,{children:"Tags"}),a.jsx(zt.Value,{children:a.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[k.map(P=>a.jsxs(DJ,{value:P,className:u?"gap-1 pr-1":void 0,children:[P,u&&a.jsx("button",{type:"button","aria-label":`Remove tag ${P}`,disabled:f,onClick:()=>u(k.filter(D=>D!==P)),className:"cursor-pointer rounded-sm hover:opacity-70 disabled:opacity-50",children:a.jsx(Dn,{className:"size-3"})})]},P)),u&&a.jsx(gUt,{appearance:"inline",selectedResults:j,vocabulary:d,onAddTag:P=>u([...k,P]),disabled:f})]})})]}),I&&a.jsxs(a.Fragment,{children:[a.jsx(zt.Key,{children:"Input tokens"}),a.jsx(zt.Value,{children:I.inputTokens!==void 0?H1(I.inputTokens):"—"}),a.jsx(zt.Key,{children:"Output tokens"}),a.jsx(zt.Value,{children:I.outputTokens!==void 0?H1(I.outputTokens):"—"}),a.jsx(zt.Key,{children:"Cost"}),a.jsx(zt.Value,{children:I.estimatedCost!==void 0?RJ(I.estimatedCost,I.costUnit):"—"})]})]}),v&&a.jsx(Ht,{variant:"destructive",title:"Error",children:a.jsx(Ht.Message,{children:T7(e?.error&&typeof e.error=="object"?e.error.message:e?.error)})}),t&&t.length>0&&a.jsxs(Te,{columns:"1fr 1fr",children:[a.jsxs(Te.Top,{children:[a.jsx(Te.TopCell,{children:"Scorer"}),a.jsx(Te.TopCell,{children:"Score"})]}),t.map(P=>o?a.jsxs(Te.RowButton,{featured:l===P.id,onClick:()=>o(P.id),children:[a.jsx(Te.Cell,{children:P.scorerId}),a.jsx(Te.TextCell,{font:"mono",children:P.score.toFixed(3)})]},P.id):a.jsxs(Te.RowStatic,{children:[a.jsx(Te.Cell,{children:P.scorerId}),a.jsx(Te.TextCell,{font:"mono",children:P.score.toFixed(3)})]},P.id))]}),e.toolMockReport&&a.jsx(dOs,{report:e.toolMockReport})]}),a.jsxs("div",{className:"grid gap-3",children:[a.jsx(Ot.CodeSection,{title:"Input",icon:a.jsx(Gft,{}),codeStr:y}),a.jsx(Ot.CodeSection,{title:"Output",icon:a.jsx(z1,{}),codeStr:x}),e.groundTruth!==void 0&&a.jsx(Ot.CodeSection,{title:"Ground Truth",icon:a.jsx(kht,{}),codeStr:b})]})]});return a.jsxs(a.Fragment,{children:[a.jsxs(Ot.Header,{children:[a.jsx(Ot.CloseButton,{onClick:s,tooltip:"Close result panel"}),a.jsxs(Ot.Heading,{children:["Result",a.jsx(Ot.CopyId,{id:e.id})]}),a.jsxs(Ot.HeaderActions,{children:[S&&a.jsx(de,{size:"sm",variant:"primary",onClick:()=>c(e.id),icon:a.jsx(J3,{}),children:"Flag for Review"}),p&&e.status==="needs-review"&&a.jsx(de,{size:"sm",variant:"primary",onClick:p,icon:a.jsx(Y3,{}),children:"Mark as reviewed"}),h&&a.jsx(de,{size:"sm",variant:"ghost",render:a.jsx(T,{href:h}),tooltip:"See experiment","aria-label":"See experiment",children:a.jsx(DH,{})}),e.traceId&&i&&a.jsx(de,{size:"sm",variant:"ghost",onClick:i,tooltip:"See trace","aria-label":"See trace",children:a.jsx(px,{})}),a.jsx(Ot.NextPrevNav,{onPrevious:n,onNext:r,previousLabel:"Go to previous result",nextLabel:"Go to next result"})]})]}),_?a.jsxs(Qc,{defaultTab:"details",className:"grid h-full min-h-0 grid-rows-[auto_1fr]",children:[a.jsx(Ot.Header,{children:a.jsxs(Zc,{variant:"pill-ghost",size:"sm",children:[a.jsx(ni,{value:"details",children:"Details"}),a.jsxs(ni,{value:"feedback",children:["Feedback",N?.pagination?.total!=null&&a.jsxs(a.Fragment,{children:[" (",N.pagination.total,")"]})]})]})}),a.jsx(No,{value:"details",flush:!0,children:A}),a.jsx(No,{value:"feedback",flush:!0,children:a.jsx(Ot.Content,{children:m({traceId:_})})})]}):A]})}function T7(e){return e==null?"-":typeof e=="string"?e:JSON.stringify(e,null,2)}function mOs(e){const t=e.scorer;return t?.hasJudge===!1?!0:t?.hasJudge===!0?!1:!e.preprocessPrompt&&!e.analyzePrompt&&!e.generateScorePrompt&&!e.generateReasonPrompt}function gOs({score:e,onNext:t,onPrevious:n,onClose:r,onShowTrace:s}){return a.jsx(Ot,{open:!!e,onClose:r,title:e?`Score ${e.scorerId}`:"Score",depth:2,children:e&&a.jsx(vOs,{score:e,onNext:t,onPrevious:n,onClose:r,onShowTrace:s})})}function vOs({score:e,onNext:t,onPrevious:n,onClose:r,onShowTrace:s}){const i=mOs(e),o=i?"N/A — code-based scorer":"N/A — step not configured";return a.jsxs(a.Fragment,{children:[a.jsxs(Ot.Header,{children:[a.jsx(Ot.CloseButton,{onClick:r,tooltip:"Close score panel"}),a.jsxs(Ot.Heading,{children:["Score",a.jsx(Ot.CopyId,{id:e.scorerId})]}),a.jsxs(Ot.HeaderActions,{children:[s&&e.traceId&&a.jsx(de,{size:"sm",variant:"ghost",onClick:s,tooltip:"See trace","aria-label":"See trace",children:a.jsx(px,{})}),(n||t)&&a.jsx(Ot.NextPrevNav,{onPrevious:n,onNext:t,previousLabel:"Go to previous score",nextLabel:"Go to next score"})]})]}),a.jsx(Ot.Content,{children:a.jsxs("div",{className:"grid gap-3",children:[a.jsx(Ot.CodeSection,{title:`Score: ${e.score}`,icon:a.jsx(Cv,{}),codeStr:e.reason||o,simplified:!0}),!i&&a.jsxs(a.Fragment,{children:[a.jsx(Ot.CodeSection,{title:"Preprocess Prompt",icon:a.jsx(em,{}),codeStr:e.preprocessPrompt||o,simplified:!0}),a.jsx(Ot.CodeSection,{title:"Analyze Prompt",icon:a.jsx(em,{}),codeStr:e.analyzePrompt||o,simplified:!0}),a.jsx(Ot.CodeSection,{title:"Generate Score Prompt",icon:a.jsx(em,{}),codeStr:e.generateScorePrompt||o,simplified:!0}),a.jsx(Ot.CodeSection,{title:"Generate Reason Prompt",icon:a.jsx(em,{}),codeStr:e.generateReasonPrompt||o,simplified:!0})]})]})})]})}function vUt(e,t){const[n,r]=g.useState(null),[s,i]=g.useState(void 0),[o,l]=g.useState(null),[c,u]=g.useState(t);t!==c&&(u(t),r(null),i(void 0),l(null));const d=e?.find(f=>f.id===o)??null;return{featuredTraceId:n,setFeaturedTraceId:r,featuredSpanId:s,setFeaturedSpanId:i,featuredScoreId:o,setFeaturedScoreId:l,featuredScore:d}}function yUt({result:e,scores:t,state:n,withQueryTrace:r,withFeedback:s,...i}){const o=vUt(t,e?.id),{navigate:l}=xn(),{featuredTraceId:c,setFeaturedTraceId:u,featuredSpanId:d,setFeaturedSpanId:f,featuredScoreId:h,setFeaturedScoreId:p,featuredScore:m}=n??o,v=I=>{p(A=>I===A?null:I),u(null),f(void 0)},y=I=>{I&&(u(I),f(void 0),p(null))},x=()=>{if(!h||!t)return;const I=t.findIndex(A=>A.id===h);if(I>=0&&I<t.length-1)return()=>p(t[I+1].id)},b=()=>{if(!h||!t)return;const I=t.findIndex(A=>A.id===h);if(I>0)return()=>p(t[I-1].id)},{data:S,isLoading:k}=lks({traceId:c,queryOptions:{enabled:!!c}}),j=S?.spans,C=j?.find(I=>!I.parentSpanId),{data:T}=_J({traceId:c??void 0,queryOptions:{enabled:s&&!!c}}),{data:_}=vNe({traceId:c??void 0,spanId:d,queryOptions:{enabled:s&&!!c&&!!d}}),{data:N}=mke({traceId:c??void 0,spanId:C?.spanId,page:0,queryOptions:{enabled:!!c&&!!C?.spanId}});return a.jsxs(a.Fragment,{children:[a.jsx(hOs,{...i,result:e,scores:t,onScoreClick:v,featuredScoreId:h,onShowTrace:e?.traceId?()=>y(e.traceId):void 0,feedbackTabSlot:s?({traceId:I})=>a.jsx(dW,{traceId:I},I):void 0}),a.jsx(gOs,{score:m??void 0,onNext:x(),onPrevious:b(),onClose:()=>p(null),onShowTrace:m?()=>y(m.traceId):void 0}),a.jsx(QNe,{size:"wide",depth:2,traceId:c??void 0,spans:j,isLoadingSpans:k,selectedSpanId:d??null,onClose:()=>{u(null),f(void 0)},onSpanSelect:f,showUnavailableFeaturesMsg:!1,traceHref:c?`/traces?traceId=${encodeURIComponent(c)}`:void 0,anchorSpanId:C?.spanId,withQueryTrace:r,withFeedback:s,onOpenScore:(I,A)=>l(ACe(I,A)),feedbackTabBadge:s?T?.pagination?.total??void 0:void 0,feedbackTabSlot:s?({traceId:I})=>a.jsx(dW,{traceId:I}):void 0,scoresTabBadge:N?.pagination?.total??void 0,scoresTabSlot:({traceId:I,rootSpanId:A})=>A?a.jsx(EIe,{traceId:I,spanId:A,onScoreSelect:P=>{t?.some(D=>D.id===P)&&(u(null),f(void 0),p(P))}}):null,spanFeedbackTabBadge:s?_?.pagination?.total??void 0:void 0,spanFeedbackTabSlot:s?({traceId:I,spanId:A})=>I&&A?a.jsx(eVt,{traceId:I,spanId:A},`${I}:${A}`):null:void 0})]})}function xUt(e,t){const{data:n}=Mv({datasetId:e,queryOptions:{enabled:!!e}});return g.useMemo(()=>[...new Set([...n?.tags??[],...t.flatMap(r=>r.tags??[])])].sort(),[n?.tags,t])}function yOs({withQueryTrace:e,withFeedback:t}){const{currentItemId:n,experimentId:r,datasetId:s,experimentStatus:i,results:o,isLoadingResults:l,hasNextPage:c,close:u,goToPreviousItem:d,goToNextItem:f}=eUt(),h=g.useMemo(()=>n?o.find(j=>j.itemId===n):void 0,[o,n]),{data:p}=AS({experimentId:r,experimentStatus:i,queryOptions:{enabled:!!r}}),{updateExperimentResult:m}=pl(),v=g.useCallback(async j=>{try{await m.mutateAsync({datasetId:s,experimentId:r,resultId:j,status:"needs-review"}),Ke("Result flagged for review")}catch{Ke.error("Failed to flag result for review")}},[s,r,m]),y=xUt(s,o),x=g.useCallback(async(j,C)=>{try{await m.mutateAsync({datasetId:s,experimentId:r,resultId:j,tags:C})}catch{Ke.error("Failed to update tags")}},[s,r,m]),b=g.useCallback(async j=>{try{await m.mutateAsync({datasetId:s,experimentId:r,resultId:j,status:"complete"}),Ke("Result marked as reviewed")}catch{Ke.error("Failed to complete result")}},[s,r,m]),S=h?p?.[h.itemId]:void 0,k=vUt(S,h?.id);return a.jsx(yUt,{result:h,itemId:n,fallback:l||c?a.jsx(Ot.LoadingData,{}):a.jsxs(Ot.NoData,{children:['No loaded result for item "',n,'".']}),scores:S,state:k,withQueryTrace:e,withFeedback:t,onPrevious:d,onNext:f,onClose:u,onComplete:h?()=>b(h.id):void 0,onFlagForReview:h?()=>{v(h.id)}:void 0,onTagsChange:h?j=>{x(h.id,j)}:void 0,tagVocabulary:y,isUpdatingTags:m.isPending})}function xOs({selection:e}){const{selectedIds:t,selectedResults:n,tagVocabulary:r,isFlagging:s,isTagging:i}=e;if(t.size===0)return null;const o=s||i;return a.jsxs("div",{className:"flex items-center gap-2 whitespace-nowrap",children:[a.jsxs(de,{disabled:o,onClick:e.flagSelectedForReview,icon:a.jsx(J3,{}),children:["Flag ",t.size," to review"]}),a.jsx(gUt,{selectedResults:n,vocabulary:r,onAddTag:e.addTagToSelected,disabled:o}),a.jsx(de,{icon:a.jsx(Dn,{}),variant:"ghost",onClick:e.clearSelection,children:"Clear"})]})}function bUt(e){const{data:t}=AS({experimentId:e.id,experimentStatus:e.status,queryOptions:{enabled:!!e.id}});return g.useMemo(()=>{if(e.scorerIds?.length)return e.scorerIds;if(!t)return[];const n=new Set;for(const r of Object.values(t))for(const s of r)n.add(s.scorerId);return[...n].sort()},[e.scorerIds,t])}function aue({icon:e,typeLabel:t,subject:n,description:r,isLast:s=!1}){return a.jsxs("li",{className:"relative grid grid-cols-[auto_1fr] gap-x-2.5 pb-4 last:pb-0",children:[a.jsxs("div",{className:"flex flex-col items-center",children:[a.jsxs(Ln,{children:[a.jsx(Rn,{render:a.jsx("span",{className:"flex size-5 shrink-0 items-center justify-center text-muted-foreground [&_svg]:size-3.5",role:"img","aria-label":t}),children:e}),a.jsx(Mn,{children:t})]}),!s&&a.jsx("span",{"aria-hidden":!0,className:"mt-1 w-px flex-1 bg-border"})]}),a.jsxs("div",{className:"grid min-w-0 grid-cols-1 gap-0.5",children:[a.jsx("div",{className:"flex min-h-5 items-center",children:a.jsx(Y,{tone:"ink",as:"span",variant:"caption",className:"block min-w-0",children:n})}),a.jsx(Y,{variant:"meta",tone:"faint",children:r})]})]})}const lue="text-foreground inline-flex max-w-full min-w-0 items-center gap-1.5 hover:underline";function bOs({experiment:e,className:t}){const{Link:n,paths:r}=xn(),s=lUt(),{scorers:i}=s,{data:o,isLoading:l}=Mv({datasetId:e.datasetId??"",queryOptions:{enabled:!!e.datasetId}}),c=bUt(e),u=e.targetType,d=e.targetId,f=dUt(e,s),h=(()=>{if(!d)return null;switch(u){case"agent":return r.agentLink(d);case"workflow":return r.workflowLink(d);case"scorer":return r.scorerLink(d);default:return null}})(),p=u&&cUt[u]||ko,m=u&&uUt[u]||"Evaluation target";return a.jsxs("ol",{className:Z("grid",t),children:[a.jsx(aue,{icon:a.jsx(gke,{}),typeLabel:"Dataset",description:`Each item will be passed to the ${m.toLowerCase()}`,subject:e.datasetId?a.jsxs(n,{href:r.datasetLink(e.datasetId),className:lue,children:[a.jsx("span",{className:"truncate",children:l?a.jsx(xt,{className:"h-4 w-28"}):o?.name??e.datasetId}),e.datasetVersion!=null&&a.jsxs("span",{className:"shrink-0 text-muted-foreground",children:["(v",e.datasetVersion,")"]})]}):a.jsx("span",{className:"text-muted-foreground",children:"No dataset"})}),a.jsx(aue,{icon:a.jsx(p,{}),typeLabel:m,description:"Its output is then scored",subject:h?a.jsx(n,{href:h,className:lue,children:a.jsx("span",{className:"truncate",children:f})}):a.jsx("span",{className:"truncate text-muted-foreground",children:f})}),a.jsx(aue,{icon:a.jsx(Ax,{}),typeLabel:"Scorers",description:"It gives a score by comparing ground truth",isLast:!0,subject:c.length===0?a.jsx("span",{className:"text-muted-foreground",children:"No scorer has produced a score yet"}):a.jsx("ul",{className:"grid min-w-0 gap-0.5",children:c.map(v=>{const y=i?.[v]?.scorer?.config?.name??v;return a.jsx("li",{className:"min-w-0",children:a.jsx(n,{href:r.scorerLink(v),className:lue,children:a.jsx("span",{className:"truncate",children:y})})},v)})})})]})}function bE({label:e,children:t}){return a.jsxs(a.Fragment,{children:[a.jsx(zt.Key,{children:e}),a.jsx(zt.Value,{className:"flex flex-wrap items-baseline justify-end gap-x-1.5 text-right",children:t})]})}function wOs({experiment:e,metrics:t}){const{data:n}=AS({experimentId:e.id,experimentStatus:e.status,queryOptions:{enabled:!!e.id}}),r=e.status==="running"||e.status==="pending",s=g.useMemo(()=>{if(!n)return;const c=Object.values(n).flat();if(c.length!==0)return c.reduce((u,d)=>u+d.score,0)/c.length},[n]),i=e.startedAt??e.createdAt,o=i?new Date(i):null,l=(()=>{if(e.status==="running")return"Running…";if(!e.startedAt||!e.completedAt)return"—";const c=new Date(e.completedAt).getTime()-new Date(e.startedAt).getTime();return sf(c)??"—"})();return a.jsxs(zt,{children:[a.jsx(bE,{label:"Avg score",children:s===void 0?a.jsx("span",{className:"text-muted-foreground",children:"—"}):a.jsxs(a.Fragment,{children:[a.jsx("span",{children:s.toFixed(3)}),r&&a.jsx("span",{className:"text-muted-foreground",children:"· so far"})]})}),a.jsx(bE,{label:"Items",children:r?a.jsxs("span",{className:"text-muted-foreground",children:[(e.succeededCount??0)+(e.failedCount??0),"/",e.totalItems," items processed"]}):a.jsxs(a.Fragment,{children:[a.jsxs("span",{children:[e.totalItems," item",e.totalItems===1?"":"s"]}),(e.failedCount??0)>0&&a.jsxs("span",{className:"text-destructive-foreground",children:["· ",e.failedCount," errored"]})]})}),a.jsx(bE,{label:"Started",children:o?a.jsx("span",{title:lSe(o),children:os(o,"date-time")}):a.jsx("span",{children:"—"})}),a.jsx(bE,{label:"Duration",children:a.jsx("span",{children:l})}),t?.isEnabled&&a.jsxs(a.Fragment,{children:[a.jsx(bE,{label:"Tokens",children:t.data?.totalTokens==null?a.jsx("span",{className:"text-muted-foreground",children:"—"}):a.jsxs(a.Fragment,{children:[a.jsx("span",{children:H1(t.data.totalTokens)}),t.data.estimatedCost!=null&&a.jsxs("span",{className:"text-muted-foreground",children:["· ",RJ(t.data.estimatedCost,t.data.costUnit)]}),r&&a.jsx("span",{className:"text-muted-foreground",children:"· so far"})]})}),a.jsx(bE,{label:"Latency (avg)",children:t.data?.avgAgentDurationMs==null?a.jsx("span",{className:"text-muted-foreground",children:"—"}):a.jsx(Y,{as:"span",variant:"body-sm",font:"mono",children:sf(Math.round(t.data.avgAgentDurationMs))})})]})]})}function SOs({scoresByItemId:e,experimentStatus:t}){const{Link:n,paths:r}=xn(),{data:s}=ag(),i=g.useMemo(()=>{if(!e)return[];const o={};for(const l of Object.values(e))for(const c of l)o[c.scorerId]||(o[c.scorerId]={sum:0,count:0}),o[c.scorerId].sum+=c.score,o[c.scorerId].count++;return Object.entries(o).map(([l,{sum:c,count:u}])=>({scorerId:l,avg:c/u})).sort((l,c)=>l.scorerId.localeCompare(c.scorerId))},[e]);if(i.length===0){const o=t==="running"||t==="pending",l=e!==void 0;let c,u;return o?(c="Experiment in progress",u="Summary metrics will appear here once the experiment completes."):l?(c="No scorers configured",u="Add scorers when triggering an experiment to evaluate results and see summary metrics here."):(c="Loading scores",u="Fetching scorer results…"),a.jsxs("div",{className:"flex items-start gap-2 text-muted-foreground",children:[a.jsx(Cv,{className:"size-4 shrink-0 text-muted-foreground"}),a.jsxs("div",{className:"grid min-w-0 gap-0.5",children:[a.jsx(Y,{as:"span",variant:"caption",tone:"muted",children:c}),a.jsx(Y,{as:"span",variant:"caption",children:u})]})]})}return a.jsx("div",{className:"flex flex-col gap-2",children:i.map(({scorerId:o,avg:l})=>{const c=s?.[o]?.scorer?.config?.name??o;return a.jsxs(Kf,{className:"min-w-0 p-3",children:[a.jsxs(n,{href:r.scorerLink(o),className:"flex min-w-0 items-center gap-1.5 text-muted-foreground hover:underline [&>svg]:size-3 [&>svg]:shrink-0 [&>svg]:text-muted-foreground",children:[a.jsxs(Ln,{children:[a.jsx(Rn,{render:a.jsx(Ax,{role:"img","aria-label":"Scorer"})}),a.jsx(Mn,{children:"Scorer"})]}),a.jsx(Y,{as:"span",variant:"caption",className:"truncate",children:c})]}),a.jsxs(Y,{as:"strong",variant:"subheading",tone:"muted",children:[l.toFixed(3),a.jsx(Y,{as:"span",variant:"caption",tone:"muted",className:"ml-1.5",children:"avg score"})]})]},o)})})}function cue({title:e,children:t}){return a.jsxs("section",{className:"grid grid-cols-1 gap-3",children:[a.jsx(Y,{as:"h2",variant:"subheading",tone:"ink",children:e}),t]})}function kOs({experiment:e,metrics:t,className:n}){const{Link:r,paths:s}=xn(),{data:i}=AS({experimentId:e.id,experimentStatus:e.status,queryOptions:{enabled:!!e.id}}),o=e.agentVersion&&e.targetType==="agent"&&e.targetId?`${s.agentLink(e.targetId)}/editor?version=${encodeURIComponent(e.agentVersion)}`:null;return a.jsxs(jl,{as:"aside","aria-label":"Experiment details",className:Z("grid grid-cols-1 content-start gap-5 p-5",n),children:[a.jsxs(cue,{title:"Pipeline",children:[a.jsx(bOs,{experiment:e}),e.agentVersion&&a.jsxs(zt,{children:[a.jsx(zt.Key,{children:"Version"}),o?a.jsx(zt.ValueLink,{href:o,as:r,children:e.agentVersion}):a.jsx(zt.Value,{children:e.agentVersion})]})]}),a.jsx(cue,{title:"Run",children:a.jsx(wOs,{experiment:e,metrics:t})}),a.jsx(cue,{title:"Scorers",children:a.jsx(SOs,{scoresByItemId:i,experimentStatus:e.status})})]})}function OOs({experiment:e,open:t,onOpenChange:n}){const[r,s]=g.useState(e.name??""),[i,o]=g.useState(e.description??""),{updateExperiment:l}=pl(),c=!!r.trim(),u=async d=>{if(d.preventDefault(),!(!c||l.isPending||!e.datasetId))try{await l.mutateAsync({datasetId:e.datasetId,experimentId:e.id,name:r.trim(),description:i.trim()}),Ke.success("Experiment renamed"),n(!1)}catch(f){Ke.error(`Failed to rename experiment: ${f instanceof Error?f.message:"Unknown error"}`)}};return a.jsx(rs,{open:t,onOpenChange:n,pending:l.isPending,children:a.jsxs(ss,{children:[a.jsx(es,{children:a.jsx(Gr,{children:"Rename Experiment"})}),a.jsxs(Ga,{onSubmit:u,children:[a.jsxs(Hr,{children:[a.jsxs(ft,{children:[a.jsx(ut,{required:!0,children:"Name"}),a.jsx(Sn,{required:!0,value:r,onChange:d=>s(d.target.value),placeholder:"Enter experiment name",autoFocus:!0})]}),a.jsxs(ft,{children:[a.jsx(ut,{children:"Description"}),a.jsx(Sn,{value:i,onChange:d=>o(d.target.value),placeholder:"Enter experiment description (optional)"})]})]}),a.jsxs(Yo,{children:[a.jsx(Ca,{children:"Cancel"}),a.jsx(ja,{type:"submit",disabled:!c,children:l.isPending?"Saving...":"Save"})]})]})]})})}const jOs=["agent","workflow","scorer"];function COs({experiment:e}){const[t,n]=g.useState(!1),r=Dr(),{paths:s}=xn(),i=bUt(e),o=jOs.find(l=>l===e.targetType);return!e.datasetId||!o||!e.targetId?null:a.jsxs(a.Fragment,{children:[a.jsx(de,{variant:"primary",onClick:()=>n(!0),tooltip:"Run this experiment again with the same configuration",icon:a.jsx(Bc,{}),children:"Rerun"}),t&&a.jsx(FJ,{open:!0,onOpenChange:n,initialDatasetId:e.datasetId,initialDatasetVersion:e.datasetVersion??void 0,initialTargetType:o,initialTargetId:e.targetId,initialScorerIds:i,initialName:e.name??void 0,initialDescription:e.description??void 0,onSuccess:l=>{r(s.experimentLink(l))}},i.join(","))]})}function _Os({experiment:e,onDeleteClick:t,children:n}){const{Link:r}=xn(),[s,i]=g.useState(!1),o=!!e.datasetId,l=o||!!t;return a.jsxs(a.Fragment,{children:[a.jsxs(Xn,{children:[a.jsxs(Xn.Start,{className:"whitespace-nowrap",children:[a.jsx(COs,{experiment:e}),a.jsx(de,{render:a.jsx(r,{href:$5r(e.id)}),icon:a.jsx(J3,{}),children:"Review queue"}),l&&a.jsxs(ct,{children:[a.jsx(ct.Trigger,{asChild:!0,children:a.jsx(de,{size:"lg","aria-label":"Experiment actions menu",children:a.jsx(M0,{})})}),a.jsxs(ct.Content,{align:"start",className:"w-48",children:[o&&a.jsxs(ct.Item,{onSelect:()=>i(!0),children:[a.jsx(Fc,{})," Rename Experiment"]}),t&&a.jsxs(ct.Item,{onSelect:t,variant:"destructive",children:[a.jsx(Xo,{})," Delete Experiment"]})]})]})]}),n&&a.jsx(Xn.End,{children:n})]}),s&&a.jsx(OOs,{experiment:e,open:!0,onOpenChange:i})]})}const wUt=()=>{const{experimentId:e}=jr(),{data:t}=pke();return{experimentId:e,experiment:t?.experiments?.find(n=>n.id===e)}};function TOs(){const{experimentId:e,experiment:t}=wUt();if(!e)return null;const n=e.length>8?`${e.slice(0,8)}...`:e;return t?.name||n}function EOs(){const{experiment:e}=wUt();return e?a.jsx(nks,{status:e.status}):null}function IOs({datasetId:e,experimentId:t}){const[n,r]=g.useState(!1),{updateExperimentResult:s}=pl();return{addTag:g.useCallback(async(o,l)=>{const c=l.filter(d=>!(d.tags??[]).includes(o));if(n||c.length===0)return;r(!0);let u=0;try{u=(await Promise.allSettled(c.map(f=>s.mutateAsync({datasetId:e,experimentId:t,resultId:f.id,tags:[...f.tags??[],o]})))).filter(f=>f.status==="fulfilled").length}finally{r(!1)}u>0?Ke(`Tag "${o}" added to ${u} result${u>1?"s":""}`):Ke.error("Failed to add tag")},[e,t,n,s]),isPending:n}}function NOs({datasetId:e,experimentId:t,results:n}){const[r,s]=g.useState(new Set),[i,o]=g.useState(!1),{updateExperimentResult:l}=pl(),{addTag:c,isPending:u}=IOs({datasetId:e,experimentId:t}),d=xUt(e,n),f=g.useMemo(()=>n.filter(y=>r.has(y.id)),[n,r]),h=g.useCallback(y=>{s(x=>{const b=new Set(x);return b.has(y)?b.delete(y):b.add(y),b})},[]),p=g.useCallback(()=>s(new Set),[]),m=g.useCallback(async()=>{if(i||r.size===0)return;o(!0);const y=new Set;try{for(const x of r)try{await l.mutateAsync({datasetId:e,experimentId:t,resultId:x,status:"needs-review"}),y.add(x)}catch{}}finally{o(!1)}y.size>0&&(s(x=>{const b=new Set(x);for(const S of y)b.delete(S);return b}),Ke(`${y.size} result${y.size>1?"s":""} flagged for review`))},[e,t,i,r,l]),v=g.useCallback(y=>c(y,f),[c,f]);return{selectedIds:r,selectedResults:f,toggleSelect:h,clearSelection:p,flagSelectedForReview:m,isFlagging:i,addTagToSelected:v,isTagging:u,tagVocabulary:d}}const AOs=[],POs=["startedAt"];function E7({crumbs:e,children:t}){return a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:e}),children:[a.jsx("h1",{className:"sr-only",children:"Experiment"}),a.jsx("div",{}),a.jsx("div",{className:"flex h-full items-center justify-center",children:t})]})}function $Os(){const{experimentId:e,itemId:t}=jr(),n=[_s("/experiments"),{id:"experiment",Component:TOs,icon:EOs,to:e?`/experiments/${encodeURIComponent(e)}`:void 0},...t?[{id:"experiment-items",label:"Items"},{id:"experiment-item",label:bke(t)}]:[]],r=Dr(),[s,i]=g.useState(!1),o=$J(),[l,c]=oi(),{sort:u,onSortChange:d}=zk({searchParams:l,setSearchParams:c,allowedKeys:POs}),f=g.useMemo(()=>u?{field:u.key,direction:u.direction==="asc"?"ASC":"DESC"}:void 0,[u]),{data:h,isLoading:p}=pke(),v=h?.experiments?.find(P=>P.id===e)?.datasetId??"",{data:y,isLoading:x,error:b}=g5({datasetId:v,experimentId:e??"",queryOptions:{enabled:!!v&&!!e}}),{data:S,isLoading:k,setEndOfListElement:j,isFetchingNextPage:C,hasNextPage:T}=$pe({datasetId:v,experimentId:e??"",experimentStatus:y?.status,orderBy:f,queryOptions:{enabled:!!v&&!!e}}),{supportsMetrics:_}=wz(),N=aks({experimentId:e,experimentStatus:y?.status,supportsMetrics:_,queryOptions:{enabled:!!e&&_}}),I=NOs({datasetId:v,experimentId:e??"",results:S??AOs});if(!e||p||x)return null;if(b&&js(b))return a.jsx(E7,{crumbs:n,children:a.jsx(ai,{})});if(b&&Cs(b))return a.jsx(E7,{crumbs:n,children:a.jsx(Gs,{resource:"datasets"})});const A=a.jsx(E7,{crumbs:n,children:a.jsx(Xt,{titleSlot:"Experiment not found",descriptionSlot:`No experiment with id "${e}".`,actionSlot:a.jsx(de,{render:a.jsx(lc,{to:"/experiments"}),icon:a.jsx(md,{}),children:"Back to Experiments"})})});return b&&kk(b)?A:b?a.jsx(E7,{crumbs:n,children:a.jsx(Xt,{tone:"error",titleSlot:"Failed to load experiment",descriptionSlot:b instanceof Error?b.message:"An unexpected error occurred. Please try again."})}):!v||!y?A:a.jsx(GSs,{experimentId:e,datasetId:v,experimentStatus:y.status,results:S??[],isLoadingResults:k,hasNextPage:T,children:a.jsxs("div",{className:"h-full",children:[a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:n}),actionRow:a.jsx(_Os,{experiment:y,onDeleteClick:()=>i(!0),children:a.jsx(xOs,{selection:I})}),children:[a.jsx("h1",{className:"sr-only",children:e}),a.jsxs("div",{className:"grid grid-cols-[1fr_auto] gap-4 overflow-visible",children:[a.jsx(tks,{experimentId:e,experimentStatus:y.status,results:S??[],isLoading:k,setEndOfListElement:j,isFetchingNextPage:C,hasNextPage:T,selectedIds:I.selectedIds,onToggleSelect:I.toggleSelect,sort:u,onSortChange:d}),a.jsx(kOs,{experiment:y,metrics:N,className:"w-80 overflow-y-auto"})]})]}),a.jsx(yOs,{withQueryTrace:o.enabled,withFeedback:o.enabled}),a.jsx(oUt,{open:s,onOpenChange:i,experimentId:e,experimentName:y.name??void 0,onSuccess:()=>r("/experiments")})]})})}function ROs({tag:e,onRename:t,onRemove:n}){const[r,s]=g.useState(!1),[i,o]=g.useState(e),l=g.useRef(null);g.useEffect(()=>{r&&(l.current?.focus(),l.current?.select())},[r]);const c=()=>{const u=i.trim();u&&u!==e&&t(u),s(!1)};return r?a.jsxs("span",{className:"inline-flex items-center gap-0.5 rounded-md border border-border bg-card px-1",children:[a.jsx(Sn,{variant:"unstyled",ref:l,value:i,onChange:u=>o(u.target.value),onKeyDown:u=>{u.key==="Enter"&&(u.preventDefault(),c()),u.key==="Escape"&&(o(e),s(!1))},onBlur:c,className:"h-auto w-20 bg-transparent px-0 py-0.5 text-caption text-muted-foreground outline-hidden"}),a.jsx("button",{type:"button",onMouseDown:u=>{u.preventDefault(),c()},className:Z(Fn,"p-0.5"),children:a.jsx(dr,{className:"h-3 w-3"})})]}):a.jsxs("span",{className:"group inline-flex items-center gap-0.5 rounded-md border border-border bg-card px-1.5 py-0.5 text-muted-foreground",children:[a.jsx(Y,{as:"span",variant:"caption",children:e}),a.jsx("button",{type:"button",onClick:()=>{o(e),s(!0)},className:Z(Fn,"p-0.5 opacity-0 transition-opacity group-hover:opacity-100"),title:"Edit tag",children:a.jsx(Fc,{className:"h-3 w-3"})}),a.jsx("button",{type:"button",onClick:n,className:"p-0.5 text-placeholder opacity-0 transition-opacity group-hover:opacity-100 hover:text-destructive-foreground",title:"Remove tag",children:a.jsx(Dn,{className:"h-3 w-3"})})]})}function MOs({selectedCount:e,vocabulary:t,onApplyTag:n,onRemoveTag:r,onNewTag:s,size:i="sm"}){const[o,l]=g.useState(!1),[c,u]=g.useState(""),d=t.filter(h=>h.toLowerCase().includes(c.toLowerCase())),f=c.trim()&&!t.includes(c.trim());return a.jsxs(_p,{open:o,onOpenChange:l,children:[a.jsx(of,{asChild:!0,children:a.jsxs(de,{size:i,icon:a.jsx(uk,{}),children:["Tag ",e," items"]})}),a.jsxs(lh,{className:"w-56 p-2",align:"end",children:[a.jsx(Sn,{value:c,onChange:h=>u(h.target.value),onKeyDown:h=>{h.key==="Enter"&&c.trim()&&(h.preventDefault(),f?s(c.trim()):n(c.trim()),u(""))},placeholder:"Search or create tag...",className:"mb-1 h-7 text-caption",autoFocus:!0}),a.jsxs("div",{className:"max-h-40 space-y-0.5 overflow-y-auto",children:[d.map(h=>a.jsxs("div",{className:"flex items-center justify-between rounded px-2 py-1 hover:bg-fill-subtle",children:[a.jsx("button",{type:"button",onClick:()=>n(h),className:"flex-1 text-left text-muted-foreground",children:a.jsx(Y,{as:"span",variant:"caption",className:"block",children:h})}),a.jsx("button",{type:"button",onClick:()=>r(h),className:"ml-2 text-placeholder hover:text-destructive-foreground",children:a.jsx(Dn,{className:"h-3 w-3"})})]},h)),f&&a.jsx("button",{type:"button",onClick:()=>{s(c.trim()),u("")},className:"w-full rounded px-2 py-1 text-left text-info-indicator hover:bg-fill-subtle",children:a.jsxs(Y,{as:"span",variant:"caption",className:"block",children:['Create & apply "',c.trim(),'"']})})]})]})]})}const DOs=[{name:"itemId",label:"Item ID",size:"auto"},{name:"input",label:"Input",size:"minmax(0,1fr)"},{name:"tags",label:"Tags",size:"auto"},{name:"scores",label:"Scores",size:"6rem"}],uue="__untagged__",I7="all",LOs=[{value:"review",label:"Review queue"},{value:"completed",label:"Completed"}];function zOs({datasetId:e,experimentId:t,experiments:n,isLoadingExperiments:r,targetType:s,targetId:i,featuredItemId:o,toolbarStart:l,renderFilters:c,toolbarEnd:u,onCreateScorer:d,breadcrumbs:f,withQueryTrace:h,withFeedback:p}){const m=Ye(),{paths:v}=xn(),{data:y}=Mv({datasetId:e??"",queryOptions:{enabled:!!e}}),{data:x,isLoading:b}=Cks({experimentId:t,targetType:s,targetId:i,experiments:n,isLoadingExperiments:r}),{data:S,isLoading:k}=_ks({experimentId:t,targetType:s,targetId:i,experiments:n,isLoadingExperiments:r}),{updateExperimentResult:j}=pl(),[C,T]=g.useState(o??null);g.useEffect(()=>{o!==void 0&&T(o)},[o]);const[_,N]=g.useState(null),[I,A]=g.useState(new Set),[P,D]=g.useState(!1),[F,Q]=g.useState(!1),[q,B]=g.useState(!1),[V,H]=g.useState(""),[M,G]=g.useState(""),[L,$]=g.useState(""),[z,U]=g.useState([]),[K,ne]=g.useState(!1),X=g.useMemo(()=>x??[],[x]),te=g.useMemo(()=>{const me=new Set;if(y?.tags)for(const Pe of y.tags)me.add(Pe);for(const Pe of X)for(const Xe of Pe.tags)me.add(Xe);return[...me].sort()},[y,X]),ie=g.useCallback(me=>{!y||!e||(y.tags??[]).includes(me)},[y,e]),ue=g.useMemo(()=>_?_===uue?X.filter(me=>me.tags.length===0):X.filter(me=>me.tags.includes(_)):X,[X,_]),ee=g.useMemo(()=>{const me=new Map;let Pe=0;for(const wt of X){wt.tags.length===0&&Pe++;for(const Bt of wt.tags)me.set(Bt,(me.get(Bt)??0)+1)}const Xe=[...me.entries()].sort((wt,Bt)=>Bt[1]-wt[1]).map(([wt])=>({value:wt,label:wt}));return[{value:I7,label:"All tags"},...Pe>0?[{value:uue,label:"Untagged"}]:[],...Xe]},[X]),se=!!_||P,re=g.useCallback(()=>{N(null),D(!1),T(null)},[]),ae=g.useCallback((me,Pe)=>{const Xe=X.find(wt=>wt.id===me);Xe?.experimentId&&Xe?.datasetId&&j.mutate({datasetId:Xe.datasetId,experimentId:Xe.experimentId,resultId:Xe.id,tags:Pe})},[X,j]),he=g.useCallback(me=>{const Pe=X.find(Xe=>Xe.id===me);A(Xe=>{const wt=new Set(Xe);return wt.delete(me),wt}),C===me&&T(null),Pe?.experimentId&&Pe?.datasetId&&j.mutate({datasetId:Pe.datasetId,experimentId:Pe.experimentId,resultId:Pe.id,status:null})},[X,j,C]),ve=g.useCallback(me=>{const Pe=X.find(Xe=>Xe.id===me);A(Xe=>{const wt=new Set(Xe);return wt.delete(me),wt}),C===me&&T(null),Pe?.experimentId&&Pe?.datasetId&&j.mutate({datasetId:Pe.datasetId,experimentId:Pe.experimentId,resultId:Pe.id,status:"complete"})},[X,j,C]),pe=g.useMemo(()=>{const me=P?S??[]:ue;return!P||!_?me:_===uue?me.filter(Pe=>Pe.tags.length===0):me.filter(Pe=>Pe.tags.includes(_))},[P,S,ue,_]),ke=P?k:!1,Ee=g.useMemo(()=>new Set(pe.map(me=>me.id)),[pe]),Ue=g.useMemo(()=>[...I].filter(me=>Ee.has(me)).length,[I,Ee]),Qe=pe.length>0&&Ue===pe.length,Be=g.useCallback(me=>{A(Pe=>{const Xe=new Set(Pe);return Xe.has(me)?Xe.delete(me):Xe.add(me),Xe})},[]),Ae=g.useCallback(()=>{A(Qe?new Set:new Set(pe.map(me=>me.id)))},[Qe,pe]),Fe=g.useCallback(me=>{for(const Pe of I){const Xe=X.find(wt=>wt.id===Pe);Xe&&!Xe.tags.includes(me)&&ae(Pe,[...Xe.tags,me])}},[X,I,ae]),Ce=g.useCallback(me=>{for(const Pe of I){const Xe=X.find(wt=>wt.id===Pe);Xe&&Xe.tags.includes(me)&&ae(Pe,Xe.tags.filter(wt=>wt!==me))}},[X,I,ae]),_e=g.useCallback(()=>{for(const me of I)ve(me);A(new Set)},[I,ve]),je=g.useCallback(()=>{for(const me of I)he(me);A(new Set)},[I,he]),ce=g.useCallback(()=>{H(""),B(!0)},[]),ye=g.useCallback(async()=>{if(!(!M||!L)){Q(!0),B(!1);try{const me=X.filter(Xe=>I.has(Xe.id));if(me.length===0){Q(!1);return}const Pe=await m.clusterFailures({modelId:`${M}/${L}`,items:me.map(Xe=>({id:Xe.id,input:Xe.input,output:Xe.output??void 0,error:typeof Xe.error=="string"?Xe.error:Xe.error?String(Xe.error):void 0,scores:Xe.scores,existingTags:Xe.tags.length>0?Xe.tags:void 0})),availableTags:te.length>0?te:void 0,prompt:V||void 0});Pe.proposedTags&&Pe.proposedTags.length>0&&(U(Pe.proposedTags.map(Xe=>({...Xe,accepted:!0}))),ne(!0))}catch(me){console.error("Analysis failed:",me)}finally{Q(!1)}}},[M,L,X,I,m,te,V]),De=g.useCallback(()=>{for(const me of z){if(!me.accepted)continue;const Pe=X.find(Xe=>Xe.id===me.itemId);if(Pe){const Xe=[...new Set([...Pe.tags,...me.tags])];ae(Pe.id,Xe)}}ne(!1)},[z,X,ae]),Ie=g.useCallback(me=>{T(Pe=>Pe===me?null:me)},[]),le=g.useMemo(()=>C?pe.find(me=>me.id===C)??null:null,[C,pe]),{data:xe}=AS({experimentId:le?.experimentId??"",queryOptions:{enabled:!!le?.experimentId}}),Se=C?pe.findIndex(me=>me.id===C):-1,Re=Se>0?()=>T(pe[Se-1].id):void 0,Le=Se>=0&&Se<pe.length-1?()=>T(pe[Se+1].id):void 0,We=!P&&I.size>0,tt=!!d&&!P&&ue.length>0,st=P?"completed":"review",He=me=>{D(me==="completed"),T(null)},ze=a.jsxs(Xn,{children:[a.jsx(Xn.Start,{children:c?a.jsxs(a.Fragment,{children:[l,c({status:st,onStatusChange:He,tag:_,onTagChange:N,tagOptions:ee.filter(me=>me.value!==I7)})]}):a.jsxs(a.Fragment,{children:[l,a.jsxs(Vr,{value:st,onValueChange:me=>He(me==="completed"?"completed":"review"),children:[a.jsx(qr,{"aria-label":"Status",size:"md",className:"whitespace-nowrap",children:a.jsx(Ur,{placeholder:"Select an option"})}),a.jsx(Qr,{children:LOs.map(me=>a.jsx(ir,{value:me.value,children:me.label},me.value))})]}),ee.length>1&&a.jsxs(Vr,{value:_??I7,onValueChange:me=>N(me===I7?null:me),children:[a.jsx(qr,{"aria-label":"Tags",size:"md",className:"whitespace-nowrap",children:a.jsx(Ur,{placeholder:"Select an option"})}),a.jsx(Qr,{children:ee.map(me=>a.jsx(ir,{value:me.value,children:me.label},me.value))})]}),se&&a.jsx(de,{onClick:re,size:"sm",variant:"default",icon:a.jsx(Dn,{}),children:"Reset"})]})}),(We||u||tt)&&a.jsxs(Xn.End,{children:[u,tt&&a.jsxs(de,{size:"md",onClick:()=>d?.(ue.map(me=>({input:me.input,output:me.output}))),children:[a.jsx(At,{size:"xs",children:a.jsx(Cv,{})}),"Create Scorer"]}),We&&a.jsxs(a.Fragment,{children:[a.jsx(MOs,{size:"md",selectedCount:I.size,vocabulary:te,onApplyTag:Fe,onRemoveTag:Ce,onNewTag:me=>Fe(me)}),a.jsx(de,{variant:"primary",onClick:_e,icon:a.jsx(Y3,{}),children:"Mark as reviewed"}),a.jsxs(ct,{children:[a.jsx(ct.Trigger,{asChild:!0,children:a.jsx(de,{disabled:F,"aria-label":"More actions",children:F?a.jsx(En,{className:"h-4 w-4"}):a.jsx(jN,{})})}),a.jsxs(ct.Content,{align:"end",children:[a.jsxs(ct.Item,{onSelect:ce,children:[a.jsx(At,{size:"xs",children:a.jsx(UH,{})}),"Analyze"]}),a.jsx(ct.Separator,{}),a.jsxs(ct.Item,{onSelect:je,children:[a.jsx(At,{size:"xs",children:a.jsx(Xo,{})}),"Remove from queue"]})]})]})]})]})]});if(b)return a.jsxs(Et,{breadcrumbs:f,actionRow:ze,children:[a.jsx("h1",{className:"sr-only",children:"Review Queue"}),a.jsx(En,{fill:!0})]});const kt=a.jsx(yUt,{withQueryTrace:h,withFeedback:p,result:le??void 0,title:`Review item ${le?.id??""}`,scores:le?xe?.[le.itemId]:void 0,experimentLink:le?.experimentId?v.experimentItemLink(le.experimentId,le.itemId):void 0,tagVocabulary:te,onTagsChange:P||!le?void 0:me=>{ae(le.id,me);for(const Pe of me)te.includes(Pe)||ie(Pe)},onComplete:P||!le?void 0:()=>ve(le.id),onPrevious:Re,onNext:Le,onClose:()=>T(null)});return a.jsxs(Et,{breadcrumbs:f,actionRow:ze,children:[a.jsx("h1",{className:"sr-only",children:"Review Queue"}),a.jsx(rs,{open:q,onOpenChange:B,children:a.jsxs(ss,{children:[a.jsxs(es,{children:[a.jsx(Gr,{children:"Analyze Items"}),a.jsx(zo,{children:"Use an LLM to automatically suggest tags for the selected items."})]}),a.jsxs(Hr,{children:[a.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[a.jsxs(ft,{className:"gap-1",children:[a.jsx(ut,{children:"Provider"}),a.jsx(Ek,{value:M,onValueChange:G})]}),a.jsxs(ft,{className:"gap-1",children:[a.jsx(ut,{children:"Model"}),a.jsx(Ik,{llmId:M,value:L,onValueChange:$})]})]}),a.jsxs(Y,{variant:"meta",tone:"muted",children:[I.size," item",I.size!==1?"s":""," will be analyzed"]}),a.jsxs(ft,{className:"gap-1",children:[a.jsx(ut,{children:"Instructions (optional)"}),a.jsx(Eu,{className:"text-caption",value:V,onChange:me=>H(me.target.value),placeholder:"E.g., Focus on safety issues and factual errors...",rows:3})]})]}),a.jsxs(Yo,{children:[a.jsx(Ca,{children:"Cancel"}),a.jsx(ja,{onConfirm:ye,disabled:!M||!L||F,children:"Analyze"})]})]})}),a.jsx(rs,{open:K,onOpenChange:ne,children:a.jsxs(ss,{size:"lg",children:[a.jsxs(es,{children:[a.jsx(Gr,{children:"Review Proposed Tags"}),a.jsxs(zo,{children:[z.filter(me=>me.accepted).length," of ",z.length," proposals selected"]})]}),a.jsx(Hr,{children:z.map((me,Pe)=>{const Xe=X.find(wt=>wt.id===me.itemId);return a.jsx("div",{className:Z("rounded-lg border p-3",!me.accepted&&"opacity-50"),children:a.jsxs("div",{className:"flex items-start gap-2",children:[a.jsx(Wc,{checked:me.accepted,onCheckedChange:wt=>U(Bt=>Bt.map((Qt,yt)=>yt===Pe?{...Qt,accepted:!!wt}:Qt))}),a.jsxs("div",{className:"min-w-0 flex-1",children:[a.jsx(Y,{variant:"meta",tone:"muted",className:"block truncate",children:Xe?typeof Xe.input=="string"?Xe.input.slice(0,100):JSON.stringify(Xe.input).slice(0,100):me.itemId}),a.jsx("div",{className:"mt-1.5 flex flex-wrap gap-1",children:me.tags.map((wt,Bt)=>a.jsx(ROs,{tag:wt,onRename:Qt=>U(yt=>yt.map((bn,vn)=>vn===Pe?{...bn,tags:bn.tags.map((we,Ne)=>Ne===Bt?Qt:we)}:bn)),onRemove:()=>U(Qt=>Qt.map((yt,bn)=>bn===Pe?{...yt,tags:yt.tags.filter((vn,we)=>we!==Bt)}:yt))},`${wt}-${Bt}`))}),me.reason&&a.jsx(Y,{variant:"meta",tone:"muted",className:"mt-1 block italic",children:me.reason})]})]})},me.itemId)})}),a.jsxs(Yo,{children:[a.jsx(Ca,{children:"Cancel"}),a.jsxs(ja,{onConfirm:De,disabled:z.filter(me=>me.accepted).length===0,children:["Accept ",z.filter(me=>me.accepted).length," proposals"]})]})]})}),a.jsxs("div",{className:"grid h-full min-h-0 w-full grid-cols-1 gap-4 overflow-hidden",children:[a.jsx("div",{className:"min-h-0 w-full overflow-hidden",children:ke?a.jsx(En,{fill:!0}):pe.length===0?a.jsx(Xt,{titleSlot:P?"No completed reviews yet":"No items to review",descriptionSlot:P?"Items marked as complete will appear here for auditing.":"When experiment results are flagged for review, they will appear here.",variant:"fill"}):a.jsx(tUt,{results:pe,isLoading:!1,featuredResultId:C,onResultClick:Ie,columns:DOs,selectedIds:P?void 0:I,onToggleSelect:P?void 0:Be,onToggleSelectAll:P?void 0:Ae})}),kt]})]})}const BJ="targetType",VJ="targetId",UJ="experiment",qJ="status",QJ="tag",ytt={agent:"Agent",workflow:"Workflow",scorer:"Scorer",processor:"Processor"},FOs=[{value:"review",label:"Review queue"},{value:"completed",label:"Completed"}],xtt={[BJ]:{icon:Bft,hue:"purple"},[VJ]:{icon:Jft,hue:"pink"},[UJ]:{icon:DH,hue:"pink"},[qJ]:{icon:Y3,hue:"orange"},[QJ]:{icon:uk,hue:"pink"}},NM=(e,t)=>({id:e,label:t,icon:xtt[e].icon,color:Tlr(xtt[e].hue),strict:!0}),BOs=[{id:"is",label:"is"}],AM=(e,t)=>({id:e,fieldId:e,operatorId:"is",value:t}),VOs=({targetType:e,targetId:t,experimentId:n,status:r,tag:s})=>{const i=[];return e&&i.push(AM(BJ,e)),t&&i.push(AM(VJ,t)),n&&i.push(AM(UJ,n)),r!=="review"&&i.push(AM(qJ,r)),s&&i.push(AM(QJ,s)),i},UOs=e=>{const t=s=>{const i=e.find(o=>o.fieldId===s);return typeof i?.value=="string"?i.value:""},n=t(BJ),r=LJ(n)?n:"";return{targetType:r,targetId:r?t(VJ):"",experimentId:t(UJ),status:t(qJ)==="completed"?"completed":"review",tag:t(QJ)||null}};function qOs({targetType:e,targetId:t,experimentId:n,status:r,tag:s,experiments:i,tagOptions:o,onChange:l}){const{data:c}=ch({queryOptions:{enabled:e==="agent"}}),{data:u}=Op({queryOptions:{enabled:e==="workflow"}}),{data:d}=ag({enabled:e==="scorer"}),{data:f}=E_({queryOptions:{enabled:e==="processor"}}),h=g.useMemo(()=>{const m=e==="agent"?Object.entries(c??{}).map(([v,y])=>({value:v,label:y.name??v})):e==="workflow"?Object.entries(u??{}).map(([v,y])=>({value:v,label:y.name??v})):e==="scorer"?Object.entries(d??{}).map(([v,y])=>({value:v,label:y.scorer?.config?.name??v})):e==="processor"?Object.entries(f??{}).map(([v,y])=>({value:v,label:y.name??v})):[];return[{...NM(BJ,"Target type"),suggestions:HNe.map(v=>({value:v,label:ytt[v]}))},{...NM(VJ,e?ytt[e]:"Target"),hidden:!e,suggestions:m},{...NM(UJ,"Experiment"),suggestions:i.map(v=>({value:v.id,label:aUt(v)}))},{...NM(qJ,"Status"),suggestions:FOs},{...NM(QJ,"Tag"),hidden:o.length===0,suggestions:o}]},[e,c,u,d,f,i,o]),p=g.useMemo(()=>VOs({targetType:e,targetId:t,experimentId:n,status:r,tag:s}),[e,t,n,r,s]);return a.jsxs(nv,{fields:h,operators:BOs,value:p,onValueChange:m=>l(UOs(m)),createItemId:m=>m,"aria-label":"Review queue filters",className:"min-w-64 flex-1",children:[a.jsx(nv.Chips,{}),a.jsx(nv.Input,{placeholder:"Filter review queue…"})]})}const N7=[_s("/experiments"),_s("/experiments/review-queue")],due="experiment",btt="review";function QOs(){const[e,t]=oi(),n=e.get(qj),r=LJ(n)?n:"",s=r?e.get(I1)??"":"",i=e.get(due),o=e.get(btt),{Link:l,paths:c}=xn(),u=$J(),{data:d,error:f}=rUt({datasetId:void 0,target:{targetType:r,targetId:s}}),h=d?.experiments.find(m=>m.id===i),p=(m,v)=>{m.status!==v.status&&v.onStatusChange(m.status),m.tag!==v.tag&&v.onTagChange(m.tag),t(y=>{const x=new URLSearchParams(y),b=m.targetType!==r,k=b||m.targetId!==s?"":m.experimentId,j=b?"":m.targetId;return m.targetType?x.set(qj,m.targetType):x.delete(qj),j?x.set(I1,j):x.delete(I1),k?x.set(due,k):x.delete(due),x.delete(btt),x},{replace:!0})};return f&&js(f)?a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:N7}),children:[a.jsx("h1",{className:"sr-only",children:"Review Queue"}),a.jsx(ai,{variant:"fill"})]}):f&&Cs(f)?a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:N7}),children:[a.jsx("h1",{className:"sr-only",children:"Review Queue"}),a.jsx(Gs,{variant:"fill",resource:"experiments"})]}):f?a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:N7}),children:[a.jsx("h1",{className:"sr-only",children:"Review Queue"}),a.jsx(Xt,{tone:"error",variant:"fill",titleSlot:"Failed to load experiments",descriptionSlot:f.message})]}):a.jsx(zOs,{withQueryTrace:u.enabled,withFeedback:u.enabled,breadcrumbs:a.jsx(Dt,{crumbs:N7}),datasetId:h?.datasetId??void 0,experimentId:i??void 0,targetType:r,targetId:s,featuredItemId:o,renderFilters:m=>a.jsx(qOs,{targetType:r,targetId:s,experimentId:i??"",status:m.status,tag:m.tag,experiments:d?.experiments??[],tagOptions:m.tagOptions,onChange:v=>p(v,m)}),toolbarEnd:i?a.jsx(de,{render:a.jsx(l,{href:c.experimentLink(i)}),icon:a.jsx(R0e,{}),children:"See experiment"}):void 0})}function ZOs({connection:e,isAdmin:t,disconnectPending:n,onDisconnect:r}){return a.jsxs("li",{className:"flex items-center justify-between border-b py-2",children:[a.jsxs("div",{children:[a.jsx(Y,{as:"p",variant:"caption",font:"mono",children:e.connectionId}),a.jsxs(Y,{as:"p",variant:"caption",tone:"muted",children:[e.label??"(no label)"," · ",e.status,e.scope?` · ${e.scope}`:"",t&&e.authorId?` · author: ${e.authorId}`:""]})]}),a.jsx("button",{type:"button",className:"text-destructive-foreground underline disabled:opacity-50",onClick:r,disabled:n,children:"Disconnect"})]})}function SUt({connections:e,isAdmin:t,disconnectPending:n,onDisconnect:r}){return a.jsx("ul",{className:"space-y-1",children:e.map(s=>a.jsx(ZOs,{connection:s,isAdmin:t,disconnectPending:n,onDisconnect:()=>r(s.connectionId)},s.connectionId))})}function WOs({groups:e,isAdmin:t,disconnectPending:n,onDisconnect:r}){return a.jsx("div",{className:"space-y-4",children:e.map(([s,i])=>a.jsxs("div",{children:[a.jsx(Y,{as:"h3",variant:"subheading",tone:"ink","data-testid":`integration-author-group-${s}`,children:s==="shared"?"Shared":`Owned by ${s}`}),a.jsx(SUt,{connections:i,isAdmin:t,disconnectPending:n,onDisconnect:r})]},s))})}function HOs({providerId:e,toolkit:t,connections:n,groupedByAuthor:r,isAdmin:s,isLoading:i,error:o,disconnectPending:l,disconnectError:c,onDisconnect:u}){return a.jsxs("div",{className:"space-y-2 rounded border p-4",children:[a.jsx(Y,{as:"h2",variant:"heading",children:"Existing connections"}),!e||!t?a.jsx("p",{className:"text-muted-foreground",children:"Pick a provider and toolkit to list connections."}):i?a.jsx("p",{className:"text-muted-foreground",children:"Loading…"}):o?a.jsx("p",{className:"text-destructive-foreground",children:String(o)}):n.length===0?a.jsx("p",{className:"text-muted-foreground",children:"No connections."}):r?a.jsx(WOs,{groups:r,isAdmin:s,disconnectPending:l,onDisconnect:u}):a.jsx(SUt,{connections:n,isAdmin:s,disconnectPending:l,onDisconnect:u}),c?a.jsx("p",{className:"text-destructive-foreground",children:String(c)}):null]})}function GOs({providers:e,toolkits:t,providerId:n,toolkit:r,label:s,providersLoading:i,providersError:o,toolkitsLoading:l,toolkitsError:c,authorizePending:u,authorizeError:d,authorizedConnection:f,onProviderChange:h,onToolkitChange:p,onLabelChange:m,onConnect:v}){return a.jsxs("div",{className:"space-y-4 rounded border p-4",children:[a.jsxs(ft,{invalid:!!o,disabled:i,children:[a.jsx(ut,{children:"Provider"}),a.jsxs(Vr,{value:n,onValueChange:h,children:[a.jsx(qr,{children:a.jsx(Ur,{placeholder:i?"Loading providers…":"Select provider"})}),a.jsx(Qr,{children:e.map(y=>a.jsx(ir,{value:y.id,children:`${y.displayName??y.name} (${y.id})`},y.id))})]}),a.jsx(is,{children:o?String(o):void 0})]}),a.jsxs(ft,{invalid:!!c,disabled:!n||l,children:[a.jsx(ut,{children:"Toolkit"}),a.jsxs(Vr,{value:r,onValueChange:p,children:[a.jsx(qr,{children:a.jsx(Ur,{placeholder:l?"Loading toolkits…":"Select toolkit"})}),a.jsx(Qr,{children:t.map(y=>a.jsx(ir,{value:y.slug,children:`${y.name} (${y.slug})`},y.slug))})]}),a.jsx(is,{children:c?String(c):void 0})]}),a.jsxs(ft,{disabled:!n||!r,children:[a.jsx(ut,{children:"Label (optional)"}),a.jsx(Sn,{placeholder:"My personal Gmail",value:s,onChange:y=>m(y.target.value)})]}),a.jsx(de,{type:"button",variant:"primary",onClick:v,disabled:!n||!r||u,children:u?"Authorizing…":"Connect"}),d?a.jsx("div",{role:"alert",children:a.jsx(Ht,{variant:"destructive",children:String(d)})}):null,f?a.jsxs(Ht,{variant:"success",children:["Authorized: ",f.connectionId," (status: ",f.status,")"]}):null]})}const wtt=e=>e.authorId?.trim()||"shared",KOs=(e,t)=>{if(!t||new Set(e.map(wtt)).size<=1)return null;const r=new Map;for(const i of e){const o=wtt(i);r.set(o,[...r.get(o)??[],i])}const s=Array.from(r.entries());return s.sort(([i],[o])=>i==="shared"?1:o==="shared"?-1:i.localeCompare(o)),s},YOs=["*","tool-providers:*","tool-providers:admin"];function XOs(){const{data:e}=Ym();return e?.permissions?.some(t=>YOs.includes(t))??!1}const JOs=[{id:"integrations",label:"Integrations"}];function ejs(){const[e,t]=g.useState(""),[n,r]=g.useState(""),[s,i]=g.useState(""),o=XP(),l=FY({providerId:e||null,queryOptions:{enabled:!!e}}),c=VPt({providerId:e||null,toolkit:n||null}),u=FPt(),d=BPt(),f=XOs(),h=o.data?.providers??[],p=l.data?.data??[],m=g.useMemo(()=>c.data?.items??[],[c.data?.items]),v=g.useMemo(()=>KOs(m,f),[m,f]),y=S=>{t(S),r("")},x=()=>{!e||!n||u.mutate({providerId:e,toolkit:n,label:s.trim()||null},{onSuccess:()=>{i(""),c.refetch()}})},b=S=>{d.mutate({providerId:e,connectionId:S})};return a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:JOs}),children:[a.jsx("h1",{className:"sr-only",children:"Integrations"}),a.jsxs("div",{className:"max-w-3xl space-y-6",children:[a.jsx(Y,{as:"p",variant:"body",tone:"muted",children:"Minimal page to verify the ToolProvider backend. Pick a provider and toolkit, then connect."}),a.jsx(GOs,{providers:h,toolkits:p,providerId:e,toolkit:n,label:s,providersLoading:o.isLoading,providersError:o.error,toolkitsLoading:l.isLoading,toolkitsError:l.error,authorizePending:u.isPending,authorizeError:u.error,authorizedConnection:u.data,onProviderChange:y,onToolkitChange:r,onLabelChange:i,onConnect:x}),a.jsx(HOs,{providerId:e,toolkit:n,connections:m,groupedByAuthor:v,isAdmin:f,isLoading:c.isLoading,error:c.error,disconnectPending:d.isPending,disconnectError:d.error,onDisconnect:b})]})]})}function tjs({title:e,description:t,errorBanner:n,children:r}){return a.jsxs("div",{"data-testid":"login-page",className:"w-full max-w-sm space-y-6 p-6",children:[a.jsxs("div",{className:"flex flex-col items-center space-y-2",children:[a.jsx(T0,{className:"h-10 w-10"}),a.jsx(Y,{as:"h1",variant:"heading",tone:"ink",children:e})]}),t,n,r]})}function kUt({redirectUri:e,onSuccess:t,initialMode:n="signin",errorMessage:r}){const{data:s,isLoading:i}=Zl(),{mutate:o,isPending:l,error:c}=ubn(),{mutate:u,isPending:d,error:f}=fbn(),{mutate:h,isPending:p}=dut(),[m,v]=g.useState(n),[y,x]=g.useState(""),[b,S]=g.useState(""),[k,j]=g.useState("");if(i)return a.jsx("div",{className:"text-muted-foreground",children:"Loading..."});if(!s?.enabled||!s?.login)return a.jsx("div",{className:"text-muted-foreground",children:"Authentication is not configured"});const{login:C}=s,T=C.type==="sso"||C.type==="both",_=C.type==="credentials"||C.type==="both",N=C.sso,I=C.signUpEnabled!==!1,A=m==="signin"||!I,P=A?l:d,D=A?c:f,F=()=>{t?t():e?window.location.href=e:window.location.href=cX("/")},Q=M=>{M.preventDefault(),A?o({email:b,password:k},{onSuccess:F}):u({email:b,password:k,name:y||void 0},{onSuccess:F})},q=()=>{h({redirectUri:e},{onSuccess:M=>{window.location.href=M.url}})},B=()=>{v(A?"signup":"signin")},V=C.description?a.jsxs("div",{className:"flex items-start gap-2.5 rounded-md border border-border bg-sidebar p-3",children:[a.jsx(Tu,{className:"mt-0.5 h-4 w-4 shrink-0 text-muted-foreground"}),a.jsx(Y,{tone:"muted",children:C.description})]}):null,H=r?a.jsx("div",{role:"alert",children:a.jsx(Ht,{variant:"destructive",children:r})}):null;return a.jsxs(tjs,{title:A?"Sign in to Mastra Studio":"Create your account",description:V,errorBanner:H,children:[_&&a.jsxs(Ga,{onSubmit:Q,children:[!A&&a.jsxs(ft,{children:[a.jsx(ut,{children:"Name"}),a.jsx(Sn,{name:"name",type:"text",autoComplete:"name",value:y,onChange:M=>x(M.target.value),placeholder:"Your name",variant:"default",size:"lg"})]}),a.jsxs(ft,{children:[a.jsx(ut,{required:!0,children:"Email"}),a.jsx(Sn,{name:"email",type:"email",autoComplete:"email",value:b,onChange:M=>S(M.target.value),placeholder:"you@example.com",required:!0,variant:"default",size:"lg"}),a.jsx(is,{})]}),a.jsxs(ft,{children:[a.jsx(ut,{required:!0,children:"Password"}),a.jsx(Sn,{name:"password",type:"password",autoComplete:A?"current-password":"new-password",value:k,onChange:M=>j(M.target.value),placeholder:A?"Enter your password":"Create a password",required:!0,variant:"default",size:"lg"}),a.jsx(is,{})]}),D?a.jsx("div",{role:"alert",children:a.jsx(Ht,{variant:"destructive",children:D.message})}):null,a.jsx(de,{icon:a.jsx(Q0e,{}),type:"submit",disabled:P,className:"w-full",size:"lg",children:P?A?"Signing in...":"Creating account...":A?"Sign in":"Create account"}),I&&a.jsxs("div",{className:"text-center",children:[a.jsx(Y,{as:"span",variant:"body",tone:"muted",children:A?"Don't have an account? ":"Already have an account? "}),a.jsx("button",{type:"button",onClick:B,className:"text-foreground hover:underline",children:a.jsx(Y,{as:"span",variant:"body",className:"block",children:A?"Sign up":"Sign in"})})]})]}),T&&_&&a.jsxs("div",{className:"relative",children:[a.jsx("div",{className:"absolute inset-0 flex items-center",children:a.jsx("div",{className:"w-full border-t border-border"})}),a.jsx("div",{className:"relative flex justify-center",children:a.jsx(Y,{as:"span",variant:"body",tone:"muted",className:"bg-sidebar px-2",children:"or continue with"})})]}),T&&N&&a.jsxs(de,{onClick:q,disabled:p,className:"w-full",size:"lg",children:[N.icon&&a.jsx("span",{className:"mr-2",children:N.icon}),p?"Redirecting...":N.text||"Sign in"]})]})}function njs(){const[e]=oi(),t=Dr(),n=e.get("redirect")||"/",s=e.get("mode")==="signup"?"signup":"signin",i=e.get("error_description")||e.get("error")||null,o=()=>{n.startsWith("http")?window.location.href=n:t(n,{replace:!0})};return a.jsx(kUt,{redirectUri:n,onSuccess:o,initialMode:s,errorMessage:i})}function OUt({disabled:e,onClear:t,onRemoveAll:n,onSave:r,onRemoveSaved:s}){const i=!!(n||r||s);return!t&&!i?null:a.jsxs("div",{className:"flex items-center gap-2",children:[t&&a.jsx(de,{disabled:e,size:"md",onClick:t,icon:a.jsx(Dn,{}),children:"Clear"}),i&&a.jsxs(ct,{children:[a.jsx(ct.Trigger,{asChild:!0,children:a.jsx(de,{disabled:e,size:"md","aria-label":"More filter actions",children:a.jsx(M0,{})})}),a.jsxs(ct.Content,{align:"end",children:[n&&a.jsxs(ct.Item,{onSelect:()=>n(),children:[a.jsx(Dn,{}),"Remove all filters"]}),n&&(r||s)&&a.jsx(ct.Separator,{}),r&&a.jsxs(ct.Item,{onSelect:()=>r(),children:[a.jsx(zm,{}),"Save filters for next time"]}),s&&a.jsxs(ct.Item,{onSelect:()=>s(),children:[a.jsx(Xo,{}),"Remove saved filters"]})]})]})]})}const rjs=Z(ig,"min-w-0 focus:text-foreground");function fue({role:e,checked:t,label:n,onClick:r}){return a.jsxs("button",{ref:Pu(),type:"button",role:e,"aria-checked":t,"data-selected":t||void 0,"data-pick-multi-item":"",title:n,className:rjs,onClick:r,children:[a.jsx("span",{className:"min-w-0 flex-1 truncate",children:n}),t&&a.jsx("span",{className:C_,children:a.jsx(dr,{})})]})}function jUt({field:e,tokens:t,onChange:n}){const[r,s]=g.useState(""),i=Rv(),o={className:Z("max-h-[80dvh] overflow-auto p-1",i.containerClassName),...i.getContainerProps({})},l=g.useMemo(()=>{const f=r.trim().toLowerCase();return f?e.options.filter(h=>h.label.toLowerCase().includes(f)):e.options},[e.options,r]),c=g.useMemo(()=>t.find(f=>f.fieldId===e.id),[t,e.id]),u=typeof c?.value=="string"?c.value:e.multi?void 0:e.defaultValue,d=g.useMemo(()=>{const f=c?.value;return Array.isArray(f)?f:typeof f=="string"?[f]:[]},[c]);return a.jsxs(a.Fragment,{children:[e.searchable!==!1&&a.jsxs("div",{className:AI.container,children:[a.jsx(Kd,{className:AI.icon}),a.jsx("input",{type:"text",value:r,onChange:f=>s(f.target.value),placeholder:`Search ${e.label.toLowerCase()}...`,className:AI.input,...gp,onKeyDown:f=>{if(f.key!=="ArrowDown")return;const p=f.currentTarget.closest("[data-pick-multi-panel]")?.querySelector("[data-pick-multi-item]:not([disabled])");p&&(f.preventDefault(),f.stopPropagation(),p.focus())}})]}),e.isLoading?a.jsxs("div",{className:Z(Gq,"m-1"),children:[a.jsx(En,{size:"sm",className:"size-3 text-muted-foreground"}),"Loading options…"]}):l.length===0?a.jsx("div",{className:Z(Gq,"m-1"),children:e.emptyText??"No option found."}):e.multi?a.jsx("div",{...o,children:a.jsx(Bm,{menu:i,children:l.map(f=>{const h=d.includes(f.value);return a.jsx(fue,{role:"checkbox",checked:h,label:f.label,onClick:()=>n(e.id,h?d.filter(p=>p!==f.value):[...d,f.value])},f.value)})})}):a.jsx("div",{role:"radiogroup",...o,children:a.jsxs(Bm,{menu:i,children:[l.map(f=>a.jsx(fue,{role:"radio",checked:u===f.value,label:f.label,onClick:()=>n(e.id,f.value)},f.value)),!e.omitAnyOption&&a.jsx(fue,{role:"radio",checked:u==="Any",label:"Any",onClick:()=>n(e.id,"Any")})]})})]})}function YNe(e){return Array.isArray(e)?e.length===0?"Any":e.join(", "):e}const sjs="This filter is set by the current context and cannot be removed here.";function ijs(e,t){return e.kind==="pick-multi"&&e.options?Array.isArray(t)?t.length===0?"Any":t.map(n=>e.options.find(r=>r.value===n)?.label??n).join(", "):e.options.find(n=>n.value===t)?.label??t:YNe(t)}function ojs({field:e,value:t,tooltipContent:n}){const r=ijs(e,t),s=`${e.label} filter is locked by context`;return a.jsx(mc,{delayDuration:150,children:a.jsxs(Ln,{children:[a.jsx(Rn,{asChild:!0,children:a.jsxs(Ql,{"data-locked-field-id":e.id,"data-property-filter-pill":"locked",tabIndex:0,"aria-label":s,children:[a.jsx(Yh,{children:e.label}),a.jsx(Yh,{children:"is"}),a.jsx(Yh,{children:r}),a.jsx(Yh,{children:a.jsx(Tu,{})})]})}),a.jsx(Mn,{children:n})]})})}function ajs({field:e,value:t,onChange:n,onRemove:r,disabled:s,autoFocus:i}){const[o,l]=g.useState(t),c=g.useRef(null);return g.useEffect(()=>{o.trim()!==t&&l(t)},[t]),g.useEffect(()=>{i&&c.current?.focus()},[i]),a.jsxs(Ql,{children:[a.jsx(Yh,{children:e.label}),a.jsx(Yh,{children:"is"}),a.jsx(Sn,{ref:c,disabled:s,value:o,placeholder:e.placeholder??`Enter ${e.label}`,onChange:u=>{const d=u.target.value;l(d),d.trim()!==t&&n(d)},onKeyDown:u=>{if(u.key==="Enter"){u.preventDefault();const d=o.trim();d!==t&&n(d)}else u.key==="Escape"&&(u.preventDefault(),l(t),u.currentTarget.blur())}}),a.jsx(de,{type:"button",disabled:s,"aria-label":`Remove ${e.label} filter`,onMouseDown:u=>u.preventDefault(),onClick:r,children:a.jsx(Dn,{})})]})}function ljs({field:e,token:t,tokens:n,onChange:r,onRemove:s,disabled:i}){const[o,l]=g.useState(!1);return a.jsxs(Ql,{children:[a.jsx(Yh,{children:e.label}),a.jsx(Yh,{children:"is"}),a.jsxs(_p,{open:o,onOpenChange:l,children:[a.jsx(of,{asChild:!0,children:a.jsx(de,{type:"button",disabled:i,children:YNe(t.value)})}),a.jsx(lh,{align:"start",sideOffset:__,className:"w-64 p-0","data-pick-multi-panel":!0,children:a.jsx(jUt,{field:e,tokens:n,onChange:r})})]}),a.jsx(de,{type:"button",disabled:i,"aria-label":`Remove ${e.label} filter`,onClick:s,children:a.jsx(Dn,{})})]})}function CUt({fields:e,tokens:t,onTokensChange:n,disabled:r,autoFocusFieldId:s,lockedFieldIds:i,lockedTooltipContent:o=sjs}){if(t.length===0)return null;const l=new Set(i??[]),c=(d,f)=>{const h=[...t];h[d]=f,n(h)},u=d=>{n(t.filter((f,h)=>h!==d))};return a.jsx("div",{className:"flex flex-wrap items-center gap-2",children:t.map((d,f)=>{const h=e.find(p=>p.id===d.fieldId);return h?l.has(d.fieldId)?a.jsx(ojs,{field:h,value:d.value,tooltipContent:o},`${d.fieldId}-${f}`):h.kind==="text"&&!Array.isArray(d.value)?a.jsx(ajs,{field:h,value:d.value,disabled:r,autoFocus:s===d.fieldId,onChange:p=>c(f,{fieldId:d.fieldId,value:p}),onRemove:()=>u(f)},`${d.fieldId}-${f}`):h.kind==="pick-multi"?a.jsx(ljs,{field:h,token:d,tokens:t,disabled:r,onChange:(p,m)=>c(f,{fieldId:p,value:m}),onRemove:()=>u(f)},`${d.fieldId}-${f}`):a.jsxs(Ql,{children:[a.jsx(Yh,{children:h.label}),a.jsx(Yh,{children:"is"}),a.jsx(Yh,{children:YNe(d.value)}),a.jsx(de,{type:"button",disabled:r,"aria-label":`Remove ${h.label} filter`,onClick:()=>u(f),children:a.jsx(Dn,{})})]},`${d.fieldId}-${f}`):null})})}const _Ut=Z(ig,"focus:text-foreground"),XNe=g.forwardRef((e,t)=>a.jsx("button",{type:"button",role:"menuitem","data-filter-item":"",ref:Pu(t),...e}));XNe.displayName="FilterMenuButton";function TUt({fields:e,tokens:t,onTokensChange:n,label:r="Add Filter",disabled:s,size:i,onStartTextFilter:o,hiddenFieldIds:l}){const c=g.useMemo(()=>{if(!l||l.length===0)return e;const P=new Set(l);return e.filter(D=>!P.has(D.id))},[e,l]),[u,d]=g.useState(!1),f=Rv(),[h,p]=g.useState(),[m,v]=g.useState([]),[y,x]=g.useState(),[b,S]=g.useState(),k=g.useRef(!1),j=g.useCallback(P=>{S(D=>D===P?void 0:P)},[]),C=g.useCallback(()=>S(void 0),[]);g.useEffect(()=>{u||S(void 0)},[u]);const T=g.useMemo(()=>c.find(P=>P.id===h),[c,h]),_=g.useMemo(()=>{const P=new Set;for(const D of t){const F=e.find(Q=>Q.id===D.fieldId);F&&F.kind!=="pick-multi"&&P.add(D.fieldId)}return P},[t,e]),N=g.useCallback(()=>{p(void 0),v([]),x(void 0)},[]);g.useEffect(()=>{u||N()},[u,N]);const I=g.useCallback((P,D)=>{const F=t.findIndex(q=>q.fieldId===P);if(Array.isArray(D)&&D.length===0){if(F===-1)return;n(t.filter((q,B)=>B!==F));return}if(F===-1){n([...t,{fieldId:P,value:D}]);return}const Q=[...t];Q[F]={fieldId:P,value:D},n(Q)},[n,t]),A=g.useCallback(()=>{if(!T){x("Choose a property first.");return}if(_.has(T.id)){x(`Remove the existing ${T.label} filter before adding another.`);return}if(m.length===0){x(`Choose at least one ${T.label.toLowerCase()} value.`);return}n([...t,{fieldId:T.id,value:m}]),d(!1)},[m,n,T,_,t]);return a.jsxs(_p,{open:u,onOpenChange:d,children:[a.jsx(of,{asChild:!0,children:a.jsx(de,{size:i,disabled:s,icon:a.jsx(YLe,{}),children:r})}),a.jsx(lh,{align:"end",sideOffset:__,className:Z("w-64",T?"p-3":"p-1"),initialFocus:!1,finalFocus:()=>k.current?(k.current=!1,!1):!0,children:a.jsxs("div",{className:Z("grid",T&&"gap-3"),children:[T&&a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("button",{type:"button","aria-label":"Back to properties",className:Z(Fn,jn),onClick:N,children:a.jsx(md,{className:"size-4"})}),a.jsx(q_n,{className:"size-4 shrink-0 text-muted-foreground"}),a.jsx(Y,{as:"span",variant:"caption",tone:"muted",children:`${T.label} · is`})]}),!T&&a.jsx("div",{role:"menu",className:Z("max-h-[80dvh] overflow-auto",f.containerClassName),...f.getContainerProps({}),onKeyDown:P=>{if(P.key!=="ArrowDown"&&P.key!=="ArrowUp"&&P.key!=="Home"&&P.key!=="End")return;const D=Array.from(P.currentTarget.querySelectorAll("[data-filter-item]:not([disabled])"));if(D.length===0)return;P.preventDefault();const F=document.activeElement,Q=D.findIndex(B=>B===F);let q;P.key==="Home"?q=0:P.key==="End"?q=D.length-1:P.key==="ArrowDown"?q=Q<0?0:(Q+1)%D.length:q=Q<=0?D.length-1:Q-1,D[q]?.focus()},children:a.jsx(Bm,{menu:f,children:c.length>0?c.map(P=>{const D=_.has(P.id);return P.kind==="pick-multi"?a.jsx(cjs,{field:P,tokens:t,onChange:I,open:b===P.id,onToggle:j,onClose:C},P.id):a.jsxs(XNe,{className:Z(_Ut,"group"),disabled:D,onClick:()=>{if(x(void 0),P.kind==="text"){n([...t,{fieldId:P.id,value:""}]),o?.(P.id),k.current=!0,d(!1);return}p(P.id)},children:[a.jsx("span",{className:"truncate",children:P.label}),D?a.jsx("span",{className:"ml-auto text-muted-foreground",children:"In use"}):a.jsx("span",{className:Z(EL,"text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100 group-focus:opacity-100"),children:a.jsx(ys,{})})]},P.id)}):a.jsx("div",{className:Gq,children:"No matching property."})})}),T&&a.jsxs(ft,{invalid:!!y,children:[a.jsx(Qa,{multiple:!0,options:T.options??[],value:m,onValueChange:P=>{v(P),x(void 0)},placeholder:T.placeholder??`Choose ${T.label}`,searchPlaceholder:`Search ${T.label.toLowerCase()}...`,emptyText:T.emptyText??"No option found.",size:"md","aria-label":T.label}),a.jsx(is,{children:y})]}),T&&a.jsxs("div",{className:"flex items-center justify-end gap-2",children:[a.jsx(de,{icon:a.jsx(Dn,{}),variant:"ghost",size:"md",onClick:()=>d(!1),children:"Cancel"}),a.jsx(de,{icon:a.jsx(YLe,{}),size:"md",onClick:A,children:"Add filter"})]})]})})]})}function cjs({field:e,tokens:t,onChange:n,open:r,onToggle:s,onClose:i}){const o=g.useRef(null);return a.jsxs(_p,{open:r,onOpenChange:l=>{l?s(e.id):i()},children:[a.jsx(of,{asChild:!0,children:a.jsxs(XNe,{className:_Ut,onKeyDown:l=>{l.key!=="ArrowRight"&&l.key!=="ArrowLeft"||(r||s(e.id),l.preventDefault(),requestAnimationFrame(()=>{o.current?.querySelector('input, button, [tabindex]:not([tabindex="-1"])')?.focus()}))},children:[r&&a.jsx(Rc,{className:"text-muted-foreground"}),a.jsx("span",{className:"truncate",children:e.label}),!r&&a.jsx("span",{className:Z(EL,"text-muted-foreground"),children:a.jsx(Rc,{})})]})}),a.jsx(lh,{ref:o,side:"right",align:"start",sideOffset:__,className:"w-64 p-0",initialFocus:!1,onKeyDown:l=>{if(l.key!=="ArrowDown"&&l.key!=="ArrowUp"&&l.key!=="Home"&&l.key!=="End")return;const c=Array.from(l.currentTarget.querySelectorAll("[data-pick-multi-item]:not([disabled])"));if(c.length===0)return;l.preventDefault(),l.stopPropagation();const u=document.activeElement,d=c.findIndex(h=>h===u);let f;l.key==="Home"?f=0:l.key==="End"?f=c.length-1:l.key==="ArrowDown"?f=d<0?0:(d+1)%c.length:f=d<=0?c.length-1:d-1,c[f]?.focus()},"data-pick-multi-panel":!0,children:a.jsx(jUt,{field:e,tokens:t,onChange:n})})]})}function ujs({log:e,onClose:t,onTraceClick:n,onSpanClick:r,onPrevious:s,onNext:i,depth:o}){const l=e?OC(e.timestamp)??"":"";return a.jsx(Ot,{open:!!e,onClose:t,title:e?`Log ${l}`:"Log",depth:o,children:e&&a.jsxs(a.Fragment,{children:[a.jsxs(Ot.Header,{children:[a.jsx(Ot.CloseButton,{onClick:t}),a.jsxs(Ot.Heading,{children:["Log · ",l]}),a.jsx(Ot.HeaderActions,{children:a.jsx(Ot.NextPrevNav,{onPrevious:s,onNext:i,previousLabel:"Go to previous log",nextLabel:"Go to next log"})})]}),a.jsx(Ot.Content,{children:a.jsxs("div",{className:"grid gap-6 p-2",children:[a.jsxs(zt,{children:[e.entityType&&a.jsxs(a.Fragment,{children:[a.jsx(zt.Key,{children:"Entity Type"}),a.jsx(zt.Value,{children:e.entityType})]}),e.entityName&&a.jsxs(a.Fragment,{children:[a.jsx(zt.Key,{children:"Entity Name"}),a.jsx(zt.Value,{children:e.entityName})]}),e.serviceName&&a.jsxs(a.Fragment,{children:[a.jsx(zt.Key,{children:"Service"}),a.jsx(zt.Value,{children:e.serviceName})]}),e.environment&&a.jsxs(a.Fragment,{children:[a.jsx(zt.Key,{children:"Environment"}),a.jsx(zt.Value,{children:e.environment})]}),e.source&&a.jsxs(a.Fragment,{children:[a.jsx(zt.Key,{children:"Source"}),a.jsx(zt.Value,{children:e.source})]}),e.metadata&&Object.entries(e.metadata).map(([c,u])=>a.jsxs(g.Fragment,{children:[a.jsx(zt.Key,{children:c}),a.jsx(zt.Value,{children:String(u)})]},c))]}),a.jsx(Ot.CodeSection,{title:"Message",codeStr:e.message,simplified:!0}),(e.traceId||e.spanId)&&a.jsxs("div",{className:"grid gap-2",children:[e.traceId&&a.jsxs(Ql,{className:"w-full min-w-0",children:[a.jsxs(de,{className:"min-w-0 flex-1 justify-between overflow-hidden",icon:a.jsx(fp,{}),onClick:()=>e.traceId&&n?.(e.traceId),children:[a.jsx("span",{children:"Trace"}),a.jsxs(Y,{as:"span",variant:"caption",tone:"faint",className:"ml-auto min-w-0 truncate",children:["# ",e.traceId]})]}),a.jsx(Zi,{content:e.traceId,tooltip:"Copy Trace ID to clipboard"})]}),e.spanId&&a.jsxs(Ql,{className:"w-full min-w-0",children:[a.jsxs(de,{className:"min-w-0 flex-1 justify-between overflow-hidden",disabled:!e.traceId||!r,onClick:()=>e.traceId&&e.spanId&&r?.(e.traceId,e.spanId),icon:a.jsx(fp,{}),children:[a.jsx("span",{children:"Span"}),a.jsxs(Y,{as:"span",variant:"caption",tone:"faint",className:"ml-auto min-w-0 truncate",children:["# ",e.spanId]})]}),a.jsx(Zi,{content:e.spanId,tooltip:"Copy Span ID to clipboard"})]})]}),e.data&&Object.keys(e.data).length>0&&a.jsx(Ot.CodeSection,{title:"Data",codeStr:JSON.stringify(e.data,null,2)})]})})]})})}function djs({error:e,resource:t,errorTitle:n}){if(js(e))return a.jsx(ai,{});if(Cs(e))return a.jsx(Gs,{resource:t});if(VL(e))return a.jsx(Xt,{titleSlot:"Observability storage is not available",descriptionSlot:"The observability storage domain is disabled or not configured. Enable it in your storage configuration to view logs in Studio."});if(BL(e,"logs"))return a.jsx(Xt,{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 a.jsx(Xt,{tone:"error",titleSlot:n,descriptionSlot:r??"Unknown error"})}const fjs={debug:"neutral",info:"info",warn:"warning",error:"destructive",fatal:"destructive"};function hjs({level:e}){return a.jsx(ma,{children:a.jsx(Mt,{variant:fjs[e],children:e})})}function pjs({entityType:e,className:t}){const n=Z("size-3.5 shrink-0 text-placeholder",t);switch(e.toLowerCase()){case"agent":return a.jsx(ko,{className:n,"aria-hidden":!0});case"workflow":case"workflow_run":return a.jsx(Ol,{className:n,"aria-hidden":!0});case"tool":return a.jsx(ud,{className:n,"aria-hidden":!0});default:return null}}function mjs({entityType:e,entityName:t}){const n=e??"";return a.jsxs(ma,{className:"flex min-w-0 items-center gap-2",children:[a.jsx(pjs,{entityType:n}),t?a.jsx(Y,{as:"span",variant:"body-sm",className:"min-w-0 truncate",children:t}):"-"]})}function gjs({message:e}){return a.jsx(ma,{className:"min-w-0 truncate font-mono text-body-sm text-muted-foreground",children:e})}function vjs({data:e}){if(!e||Object.keys(e).length===0)return a.jsx(ma,{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 a.jsx(aCe,{font:"mono",children:t})}const Rl=Object.assign(g6,{Top:y6,TopCell:X0,SortableTopCell:RY,TopCellWithTooltip:$Y,TopCellSmart:MNt,RowWrapper:dCe,RowButton:v6,RowLink:uCe,Spacer:fCe,NoMatch:PY,DateCell:CNt,TimeCell:TNt,LevelCell:hjs,EntityCell:mjs,MessageCell:gjs,DataCell:vjs,NextPageLoading:AY}),Stt="6rem 9rem 5rem 10rem minmax(8rem,1fr) minmax(8rem,1fr)",yjs=36,xjs=8;function bjs({logs:e,isLoading:t,isFetchingNextPage:n,hasNextPage:r,setEndOfListElement:s,logIdMap:i,featuredLogId:o,onLogClick:l,timestampSort:c,onSortChange:u}){const d=g.useRef(null),f=aVt({count:e.length,getScrollElement:()=>d.current,estimateSize:()=>yjs,overscan:xjs}),{getRowProps:h}=Du({count:e.length,containerRef:d,onNavigate:b=>f.scrollToIndex(b),global:!0}),p=g.useRef(t);if(g.useEffect(()=>{p.current&&!t&&d.current?.dispatchEvent(new Event("scroll")),p.current=t},[t]),t)return a.jsx($u,{columns:Stt,fit:"container"});const m=f.getVirtualItems(),v=f.getTotalSize(),y=m[0]?.start??0,x=m.length>0?Math.max(0,v-(m[m.length-1]?.end??0)):0;return a.jsxs(Rl,{columns:Stt,scrollRef:d,className:"min-w-0",fit:"container",children:[a.jsxs(Rl.Top,{children:[u?a.jsx(Rl.SortableTopCell,{sortKey:"timestamp",sort:c,onSortChange:u,children:"Date"}):a.jsx(Rl.TopCell,{children:"Date"}),a.jsx(Rl.TopCell,{children:"Time"}),a.jsx(Rl.TopCell,{children:"Level"}),a.jsx(Rl.TopCell,{children:"Entity"}),a.jsx(Rl.TopCell,{children:"Message"}),a.jsx(Rl.TopCell,{children:"Data"})]}),e.length===0?a.jsx(Rl.NoMatch,{message:"No logs match your search"}):a.jsxs(a.Fragment,{children:[a.jsx(Rl.Spacer,{height:y}),m.map(b=>{const S=e[b.index];if(!S)return null;const k=i.get(S);if(!k)return null;const j=k===o;return a.jsxs(Rl.RowButton,{ref:f.measureElement,"data-index":b.index,...h(b.index),onClick:()=>l(S),featured:j,variant:S.level==="error"||S.level==="fatal"?"error":"default",children:[a.jsx(Rl.DateCell,{timestamp:S.timestamp}),a.jsx(Rl.TimeCell,{timestamp:S.timestamp}),a.jsx(Rl.LevelCell,{level:S.level}),a.jsx(Rl.EntityCell,{entityType:S.entityType,entityName:S.entityName}),a.jsx(Rl.MessageCell,{message:S.message}),a.jsx(Rl.DataCell,{data:S.data})]},k)}),a.jsx(Rl.Spacer,{height:x})]}),a.jsx(Rl.NextPageLoading,{isLoading:n,hasMore:r,setEndOfListElement:s})]})}function wjs({onClear:e,onRemoveAll:t,onSave:n,onRemoveSaved:r,isLoading:s,filterFields:i,filterTokens:o,onFilterTokensChange:l,autoFocusFilterFieldId:c}){const u=o.length>0,d=o.some(f=>Sjs(f,i));return u?a.jsxs("div",{className:Z("grid grid-cols-[1fr_auto] items-start gap-3"),children:[a.jsx(CUt,{fields:i,tokens:o,onTokensChange:l,disabled:s,autoFocusFieldId:c}),u&&a.jsx(OUt,{disabled:s,onClear:d?e:void 0,onRemoveAll:t,onSave:n,onRemoveSaved:r})]}):null}function Sjs(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 kjs={"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"},hue="Pick a wider range or lower the logging level — verbose entries (debug, info) may be filtered out.";function Ojs({datePreset:e,dateFrom:t,dateTo:n}){return e&&e!=="all"&&e!=="custom"?{title:`No logs for ${kjs[e]}`,description:hue}:t&&n?{title:`No logs between ${os(t,"date-time")} and ${os(n,"date-time")}`,description:hue}:t?{title:`No logs since ${os(t,"date-time")}`,description:hue}:{title:"No logs yet",description:"Logs will appear here once agents, workflows, or tools are executed."}}const jjs=({datePreset:e,dateFrom:t,dateTo:n}={})=>{const{title:r,description:s}=Ojs({datePreset:e,dateFrom:t,dateTo:n});return a.jsx(Xt,{titleSlot:r,descriptionSlot:s,actionSlot:a.jsx(de,{variant:"ghost",render:a.jsx("a",{href:"https://mastra.ai/en/docs/observability/logging",target:"_blank",rel:"noopener noreferrer"}),icon:a.jsx(Zs,{}),children:"Logging Documentation"}),variant:"fill"})},A7={AGENT:"agent",WORKFLOW:"workflow_run",SCORER:"scorer",INGEST:"rag_ingestion"},EUt=[{label:"Agent",entityType:A7.AGENT},{label:"Workflow",entityType:A7.WORKFLOW},{label:"Scorer",entityType:A7.SCORER},{label:"Ingest",entityType:A7.INGEST}],Cjs=[{label:"Debug",value:"debug"},{label:"Info",value:"info"},{label:"Warn",value:"warn"},{label:"Error",value:"error"},{label:"Fatal",value:"fatal"}],A0="rootEntityType",Lb="datePreset",zb="dateFrom",Fb="dateTo",_js=new Set(["all","last-24h","last-3d","last-7d","last-14d","last-30d","custom"]),Dl={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"},kz=Object.keys(Dl),JNe=new Set(["tags"]),eAe="mastra:logs:saved-filters";function Tjs(e,t=eAe){const n=Pjs(e),r=e.get(Lb);r&&n.set(Lb,r);const s=e.get(zb);s&&n.set(zb,s);const i=e.get(Fb);i&&n.set(Fb,i);try{localStorage.setItem(t,n.toString())}catch{}}function Ejs(e=eAe){try{localStorage.removeItem(e)}catch{}}function ktt(e=eAe){try{const t=localStorage.getItem(e);if(!t)return null;const n=new URLSearchParams(t);return n.toString()?n:null}catch{return null}}function Ijs(e){if(e.has(Lb)||e.has(zb)||e.has(Fb)||e.has(A0))return!0;for(const t of kz)if(e.has(Dl[t]))return!0;return!1}function Njs({availableTags:e,availableRootEntityNames:t,availableServiceNames:n,availableEnvironments:r,loading:s}){const i=[{id:"rootEntityType",label:"Primitive type",kind:"pick-multi",searchable:!1,options:EUt.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:Cjs.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"}],o=(u,d)=>u.label.localeCompare(d.label),l=i.filter(u=>u.kind==="pick-multi").sort(o),c=i.filter(u=>u.kind==="text").sort(o);return[...l,...c]}function Ajs(e){const t=[],n=new Map([[A0,"rootEntityType"]]);for(const s of kz)n.set(Dl[s],s);const r=new Set;for(const[s]of e.entries()){const i=n.get(s);if(!i||r.has(i))continue;if(r.add(i),JNe.has(i)){const l=e.getAll(s);if(l.length===0)continue;t.push({fieldId:i,value:l.filter(Boolean)});continue}const o=e.get(s);o!==null&&t.push({fieldId:i,value:o})}return t}function Pjs(e){const t=new URLSearchParams,n=e.get(A0);n&&t.set(A0,n);for(const r of kz){const s=Dl[r];if(JNe.has(r)){for(const o of e.getAll(s))t.append(s,o);continue}const i=e.get(s);i&&t.set(s,i)}return t}function $js(e,t){e.delete(A0);for(const n of kz)e.delete(Dl[n]);for(const n of t){if(n.fieldId==="rootEntityType"&&typeof n.value=="string"){e.set(A0,n.value);continue}const r=Dl[n.fieldId];if(r){if(JNe.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 Rjs({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 i of r){if(i.fieldId==="tags"){Array.isArray(i.value)&&i.value.length>0?s.tags=i.value:typeof i.value=="string"&&i.value.trim()&&(s.tags=[i.value.trim()]);continue}if(i.fieldId==="level"){typeof i.value=="string"&&i.value.trim()&&i.value!=="Any"&&(s.level=i.value);continue}if(typeof i.value=="string"&&i.value.trim()&&i.value!=="Any")switch(i.fieldId){case"entityName":s.rootEntityName=i.value;break;case"traceId":s.traceId=i.value;break;case"spanId":s.spanId=i.value;break;case"runId":s.runId=i.value;break;case"threadId":s.threadId=i.value;break;case"sessionId":s.sessionId=i.value;break;case"requestId":s.requestId=i.value;break;case"resourceId":s.resourceId=i.value;break;case"userId":s.userId=i.value;break;case"organizationId":s.organizationId=i.value;break;case"serviceName":s.serviceName=i.value;break;case"environment":s.environment=i.value;break;case"experimentId":s.experimentId=i.value;break}}return s}function Mjs(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 Djs="Filters setting for Logs saved",Ljs="Filters setting for Logs cleared up";function zjs(e,t,n){const{storageKey:r,messages:s,skipHydration:i}={},[o,l]=g.useState(()=>ktt(r)!==null),c=g.useCallback(()=>{Tjs(e,r),l(!0);const f=s?.saved??Djs;f!==!1&&Ke.success(f)},[e,r,s?.saved]),u=g.useCallback(()=>{Ejs(r),l(!1);const f=s?.cleared??Ljs;f!==!1&&Ke.success(f)},[r,s?.cleared]),d=g.useRef(!1);return g.useEffect(()=>{if(i||d.current||(d.current=!0,Ijs(e)))return;const f=ktt(r);f&&t(h=>{const p=new URLSearchParams(h);for(const[m,v]of f)p.append(m,v);return p},{replace:!0})},[]),{hasSavedFilters:o,handleSave:c,handleRemoveSaved:u}}function Fjs(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 Bjs(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,Fjs(`${r}${n.message??""}${n.data?JSON.stringify(n.data):""}`))}return t}function Vjs(e,t,n,r){const s=g.useMemo(()=>Bjs(e),[e]),i=g.useMemo(()=>{const p=new Map;for(const[m,v]of e.entries()){const y=s.get(v);y&&p.set(y,{log:v,idx:m})}return p},[e,s]),l=(t?i.get(t):void 0)?.idx??-1,c=l>=0?e[l]??null:null,u=g.useCallback(p=>s.get(p),[s]),d=g.useCallback(p=>{const m=s.get(p);if(m){if(t===m){n({logId:null});return}n(r?{logId:m,traceId:p.traceId??null,spanId:null}:{logId:m})}},[s,t,r,n]),f=l>0?()=>{const p=e[l-1];if(!p)return;const m=s.get(p);m&&n(r?{logId:m,traceId:p.traceId??null,spanId:null}:{logId:m})}:void 0,h=l>=0&&l<e.length-1?()=>{const p=e[l+1];if(!p)return;const m=s.get(p);m&&n(r?{logId:m,traceId:p.traceId??null,spanId:null}:{logId:m})}:void 0;return{logIdMap:s,getLogId:u,featuredLog:c,handleLogClick:d,handlePreviousLog:f,handleNextLog:h}}const Eye="logId",Iye="traceId",Nye="spanId",PM=1440*60*1e3,Ujs={"last-24h":PM,"last-3d":3*PM,"last-7d":7*PM,"last-14d":14*PM,"last-30d":30*PM};function P7(e){e.delete(Eye),e.delete(Iye),e.delete(Nye)}function qjs(e,t,n){const{onRemoveAll:r}={},s=g.useMemo(()=>{const j=e.get(Lb);return j&&_js.has(j)?j:"last-24h"},[e]),i=e.get(zb),o=e.get(Fb),l=g.useMemo(()=>{if(s==="custom"){if(!i)return;const C=new Date(i);return Number.isNaN(C.getTime())?void 0:C}if(s==="all")return;const j=Ujs[s];return j?new Date(Date.now()-j):void 0},[s,i]),c=g.useMemo(()=>{if(s!=="custom"||!o)return;const j=new Date(o);return Number.isNaN(j.getTime())?void 0:j},[s,o]),u=g.useRef(s);u.current=s;const d=e.get(Eye),f=e.get(Iye),h=e.get(Nye),p=g.useMemo(()=>EUt.find(j=>j.entityType===e.get(A0)),[e]),m=g.useMemo(()=>Ajs(e),[e]),v=g.useCallback(j=>{t(C=>{const T=new URLSearchParams(C);for(const[_,N]of Object.entries(j)){const I=_==="logId"?Eye:_==="traceId"?Iye:Nye;N?T.set(I,N):T.delete(I)}return T},{replace:!0})},[t]),y=g.useCallback(j=>{t(C=>{const T=new URLSearchParams(C);return $js(T,j),P7(T),T},{replace:!0})},[t]),x=y,b=g.useCallback((j,C)=>{if(u.current!=="custom")return;const T=C==="from"?zb:Fb;t(_=>{const N=new URLSearchParams(_);return j?N.set(T,j.toISOString()):N.delete(T),P7(N),N},{replace:!0})},[t]),S=g.useCallback(j=>{u.current=j,t(C=>{const T=new URLSearchParams(C);return j==="last-24h"?(T.delete(Lb),T.delete(zb),T.delete(Fb)):j==="custom"?T.set(Lb,"custom"):(T.set(Lb,j),T.delete(zb),T.delete(Fb)),P7(T),T},{replace:!0})},[t]),k=g.useCallback(()=>{t(j=>{const C=new URLSearchParams(j);C.delete(A0);for(const T of kz)C.delete(Dl[T]);return C.delete(Lb),C.delete(zb),C.delete(Fb),P7(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:h,selectedEntityOption:p,filterTokens:m,handleFeaturedChange:v,handleFilterTokensChange:x,handleDateChange:b,handleDatePresetChange:S,handleRemoveAll:k,applyFilterTokens:y}),[e,t,s,l,c,u,d,f,h,p,m,v,x,b,S,k,y])}const Qjs=20,Zjs=1e4,Wjs={field:"timestamp",direction:"DESC"};function Hjs(e,t,n){if(e?.pagination?.hasMore)return n+1}function Gjs(e){const t=new Set,n=[];for(const r of e.pages)for(const s of r.logs??[]){const i=s.logId??JSON.stringify(s);t.has(i)||(t.add(i),n.push(s))}return n}function Kjs(e){return BL(e.state.error,"logs")||VL(e.state.error)?!1:Zjs}const Yjs=({filters:e,orderBy:t=Wjs,queryOptions:n}={})=>{const r=Ye(),{inView:s,setRef:i}=F0(),{hasNextPage:o,isFetchingNextPage:l,fetchNextPage:c,data:u,isLoading:d,isError:f,error:h}=Mm({queryKey:["logs",e,t],queryFn:({pageParam:p})=>r.listLogsVNext({pagination:{page:p,perPage:Qjs},filters:e,orderBy:t}),initialPageParam:0,getNextPageParam:Hjs,select:Gjs,retry:!1,refetchInterval:Kjs,...n});return g.useEffect(()=>{s&&o&&!l&&c()},[s,o,l,c]),{data:u,hasNextPage:o,isFetchingNextPage:l,fetchNextPage:c,isLoading:d,isError:f,error:h,setEndOfListElement:i}},pue=[_s("/logs")],Xjs=["timestamp"],Jjs={key:"timestamp",direction:"desc"};function eCs(){const[e,t]=oi(),n=Dr(),r=qjs(e,t),s=$J(),{sort:i,onSortChange:o}=zk({searchParams:e,setSearchParams:t,allowedKeys:Xjs,defaultSort:Jjs}),l=g.useMemo(()=>({field:"timestamp",direction:i?.direction==="asc"?"ASC":"DESC"}),[i?.direction]),c=zjs(e,t),[u,d]=g.useState(),{data:f=[],isPending:h}=I7t(),{data:p=[],isPending:m}=hNe({entityType:r.selectedEntityOption?.entityType,rootOnly:!0}),{data:v=[],isPending:y}=pNe(),{data:x=[],isPending:b}=E7t(),S=g.useMemo(()=>Njs({availableTags:f,availableRootEntityNames:p,availableServiceNames:x,availableEnvironments:v,loading:{tags:h,entityNames:m,serviceNames:b,environments:y}}),[f,p,x,v,h,m,b,y]),k=g.useMemo(()=>Rjs({rootEntityType:r.selectedEntityOption?.entityType,dateFrom:r.selectedDateFrom,dateTo:r.selectedDateTo,tokens:r.filterTokens}),[r.filterTokens,r.selectedDateFrom,r.selectedDateTo,r.selectedEntityOption]),{data:j=[],isLoading:C,error:T,isFetchingNextPage:_,hasNextPage:N,setEndOfListElement:I}=Yjs({filters:k,orderBy:l}),{logIdMap:A,featuredLog:P,handleLogClick:D,handlePreviousLog:F,handleNextLog:Q}=Vjs(j,r.featuredLogId,r.handleFeaturedChange,r.featuredTraceId),{data:q,isLoading:B}=J_({traceId:r.featuredTraceId??null,queryOptions:{enabled:!!r.featuredTraceId}}),V=g.useCallback(()=>r.applyFilterTokens(Mjs(S,r.filterTokens)),[S,r]),H=g.useCallback(()=>r.handleFeaturedChange({logId:null}),[r]),M=g.useCallback(K=>r.handleFeaturedChange({traceId:K,spanId:null}),[r]),G=g.useCallback((K,ne)=>r.handleFeaturedChange({traceId:K,spanId:ne}),[r]),L=g.useCallback(()=>r.handleFeaturedChange({traceId:null,spanId:null}),[r]),$=g.useCallback(K=>r.handleFeaturedChange({spanId:K??null}),[r]),z=a.jsxs(a.Fragment,{children:[a.jsx(Xn,{children:a.jsxs(Xn.Start,{children:[a.jsx(MY,{preset:r.datePreset,onPresetChange:r.handleDatePresetChange,dateFrom:r.selectedDateFrom,dateTo:r.selectedDateTo,onDateChange:r.handleDateChange,disabled:C,presets:["last-24h","last-3d","last-7d","last-14d","last-30d","custom"]}),a.jsx(TUt,{fields:S,tokens:r.filterTokens,onTokensChange:r.handleFilterTokensChange,disabled:C,onStartTextFilter:d})]})}),a.jsx(wjs,{isLoading:C,filterFields:S,filterTokens:r.filterTokens,onFilterTokensChange:r.handleFilterTokensChange,onClear:V,onRemoveAll:r.handleRemoveAll,onSave:c.handleSave,onRemoveSaved:c.hasSavedFilters?c.handleRemoveSaved:void 0,autoFocusFilterFieldId:u})]});if(T)return a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:pue}),actionRow:z,children:[a.jsx("h1",{className:"sr-only",children:"Logs"}),a.jsx("div",{className:"flex h-full items-center justify-center",children:a.jsx(djs,{error:T,resource:"logs",errorTitle:"Failed to load logs"})})]});const U=!!r.selectedEntityOption||r.filterTokens.length>0;return j.length===0&&!C&&!U?a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:pue}),actionRow:z,children:[a.jsx("h1",{className:"sr-only",children:"Logs"}),a.jsx(jjs,{datePreset:r.datePreset,dateFrom:r.selectedDateFrom,dateTo:r.selectedDateTo})]}):a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:pue}),actionRow:z,children:[a.jsx("h1",{className:"sr-only",children:"Logs"}),a.jsx(bjs,{logs:j,isLoading:C,isFetchingNextPage:_,hasNextPage:N,setEndOfListElement:I,logIdMap:A,featuredLogId:r.featuredLogId,onLogClick:D,timestampSort:i?.direction,onSortChange:o}),a.jsx(ujs,{log:P??void 0,onClose:H,onTraceClick:M,onSpanClick:G,onPrevious:F,onNext:Q}),a.jsx(QNe,{depth:2,traceId:P?r.featuredTraceId??void 0:void 0,spans:q?.spans,isLoadingSpans:B,selectedSpanId:r.featuredSpanId??null,onSpanSelect:$,onClose:L,withQueryTrace:s.enabled,withFeedback:s.enabled,onOpenScore:(K,ne)=>n(ACe(K,ne))})]})}const tCs={name:e=>e.name||e.id};function nCs({server:e,rowProps:t}){const{paths:n,Link:r}=xn(),i=Ye().options.baseUrl,l=e.transports?.includes("sse")??!0?"sse":"mcp",c=i?`${i}/api/mcp/${e.id}/${l}`:"",{data:u}=gkt({selectedServer:e}),d=Object.values(u||{}),f=d.length,h=d.filter(v=>v.toolType==="agent").length,p=d.filter(v=>v.toolType==="workflow").length,m=uf(e.name,50);return a.jsxs(Te.RowLink,{to:n.mcpServerLink(e.id),LinkComponent:r,...t,children:[a.jsx(Te.NameCell,{children:m}),a.jsx(Te.DescriptionCell,{children:c}),a.jsx(Te.TextCell,{className:"text-center",children:h||""}),a.jsx(Te.TextCell,{className:"text-center",children:f||""}),a.jsx(Te.TextCell,{className:"text-center",children:p||""})]})}function rCs({mcpServers:e,isLoading:t,search:n="",sort:r,onSortChange:s}){const i=g.useMemo(()=>{const c=n.toLowerCase();return Pk(e.filter(u=>u.name?.toLowerCase().includes(c)||u.id?.toLowerCase().includes(c)),r,tCs)},[e,n,r]),{containerRef:o,getRowProps:l}=Du({count:i.length,global:!0});return t?a.jsx($u,{columns:"auto 1fr auto auto auto"}):a.jsxs(Te,{columns:"auto 1fr auto auto auto",scrollRef:o,children:[a.jsxs(Te.Top,{children:[s?a.jsx(Te.SortableTopCell,{sortKey:"name",sort:r?.key==="name"?r.direction:void 0,onSortChange:s,children:"Name"}):a.jsx(Te.TopCell,{children:"Name"}),a.jsx(Te.TopCell,{children:"URL"}),a.jsx(Te.TopCellSmart,{long:"Agents",short:a.jsx(ko,{}),tooltip:"Agent Tools",className:"text-center"}),a.jsx(Te.TopCellSmart,{long:"Tools",short:a.jsx(ud,{}),tooltip:"Tools",className:"text-center"}),a.jsx(Te.TopCellSmart,{long:"Workflows",short:a.jsx(Ol,{}),tooltip:"Workflow Tools",className:"text-center"})]}),i.length===0&&n?a.jsx(Te.NoMatch,{message:"No MCP Servers match your search"}):null,i.map((c,u)=>a.jsx(nCs,{server:c,rowProps:l(u)},c.id))]})}const sCs=()=>a.jsx(Xt,{titleSlot:"No MCP Servers yet",descriptionSlot:a.jsxs(a.Fragment,{children:["MCP servers are not configured yet. ",a.jsx("br",{}),"More information in the documentation."]}),actionSlot:a.jsx(de,{variant:"ghost",render:a.jsx("a",{href:"https://mastra.ai/docs/tools-mcp/mcp-overview",target:"_blank",rel:"noopener noreferrer"}),icon:a.jsx(Zs,{}),children:"MCP Documentation"}),variant:"fill"}),$M=[_s("/mcps")],iCs=()=>{const{data:e=[],isLoading:t,error:n}=NP(),[r,s]=g.useState(""),[i,o]=g.useState();return n&&js(n)?a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:$M}),children:[a.jsx("h1",{className:"sr-only",children:"MCP Servers"}),a.jsx(ai,{variant:"fill"})]}):n&&Cs(n)?a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:$M}),children:[a.jsx("h1",{className:"sr-only",children:"MCP Servers"}),a.jsx(Gs,{variant:"fill",resource:"MCP servers"})]}):n?a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:$M}),children:[a.jsx("h1",{className:"sr-only",children:"MCP Servers"}),a.jsx(Xt,{tone:"error",variant:"fill",titleSlot:"Failed to load MCP servers",descriptionSlot:n.message})]}):e.length===0&&!t?a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:$M}),children:[a.jsx("h1",{className:"sr-only",children:"MCP Servers"}),a.jsx(sCs,{})]}):a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:$M}),actionRow:a.jsx(Xn,{children:a.jsx(Xn.Start,{children:a.jsx("div",{className:"max-w-120 flex-1",children:a.jsx(Ru,{onSearch:s,label:"Filter MCP servers",placeholder:"Filter by name"})})})}),children:[a.jsx("h1",{className:"sr-only",children:"MCP Servers"}),a.jsx(rCs,{mcpServers:e,isLoading:t,search:r,sort:i,onSortChange:(l,c)=>o({key:c,direction:l})})]})};function Jf(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function oCs(e){if(!Jf(e))return;if(Jf(e.ui)&&typeof e.ui.resourceUri=="string")return e.ui.resourceUri;const t=e["ui/resourceUri"];return typeof t=="string"?t:void 0}function aCs(e){return Jf(e)&&e.status==="suspended"}function lCs(e){return e<1e3?`${Math.round(e)} ms`:`${(e/1e3).toFixed(2)} s`}function cCs(e){return e===void 0?"undefined":JSON.stringify(e,null,2)}function IUt(e){return e.status==="error"?e.error:cCs(e.output)}function uCs({status:e,output:t,error:n},r){if(r!==void 0){if(e==="success")return{status:"success",output:t,durationMs:r};if(e==="error")return{status:"error",error:dCs(n),durationMs:r}}}function dCs(e){return e instanceof Error?JSON.stringify({error:e.message},null,2):JSON.stringify({error:String(e)},null,2)}function ZJ(e){return a.jsx(Hve,{className:"min-h-control-md",...e})}function fCs({zodInputSchema:e,isRunning:t,onRun:n,requestContextEntityType:r,requestContextEntityId:s}){const i=!sQ(e),[o,l]=g.useState({view:"form",value:void 0}),c=g.useRef(void 0),[u,d]=g.useState([]);function f(m){if(m===o.view)return;if(d([]),o.view==="form")return l({view:"json",value:JSON.stringify(c.current??{},null,2)});const v=WSe(o.value);if(!v.ok)return d([v.error]);const y=oSt(e,v.value);if(y)return d([y]);c.current=v.value,l({view:"form",value:v.value})}function h(m){const v=aSt(e,m);v.ok?n(v.value):d(v.errors)}const p={isSubmitLoading:t,submitButtonLabel:"Run",submitButtonIcon:a.jsx(Bc,{}),submitButtonVariant:"primary"};return a.jsxs($A,{children:[a.jsx(ZJ,{action:a.jsxs("div",{className:"flex items-center gap-1",children:[a.jsx(wke,{entityType:r,entityId:s}),a.jsx(Qc,{defaultTab:"form",value:o.view,onValueChange:f,children:a.jsxs(Zc,{size:"md",children:[a.jsxs(ni,{value:"form",disabled:t,children:[a.jsx(At,{size:"sm",children:a.jsx(mht,{})}),"Form"]}),a.jsxs(ni,{value:"json",disabled:t,children:[a.jsx(At,{size:"sm",children:a.jsx(Ua,{})}),"JSON"]})]})})]}),children:a.jsx(RA,{children:"Request"})}),a.jsx(p$,{children:a.jsx("div",{className:"p-4",children:o.view==="json"?a.jsxs("div",{className:"grid gap-4",children:[a.jsxs(ft,{invalid:u.length>0,children:[a.jsx(Or,{variant:"embedded",language:"json",value:o.value,onChange:m=>{l({view:"json",value:m}),d([])},editable:!t,"aria-label":"Request JSON"}),u.length>0&&a.jsx(is,{children:u.map(m=>a.jsx("span",{className:"block",children:m},m))})]}),a.jsx(BG,{...p,onSubmit:()=>h(o.value)})]}):a.jsx(ZSe,{...p,schema:e,defaultValues:o.value,onValuesChange:m=>{c.current=m},onSubmit:n,className:"gap-0",children:!i&&a.jsx(Y,{variant:"body-sm",tone:"muted",className:"pb-4",children:"This tool takes no input. Run it as is."})})})})]})}function hCs({isRunning:e,lastRun:t}){return e?a.jsx(Xt,{iconSlot:a.jsx(En,{}),titleSlot:"Running…",descriptionSlot:"Waiting for the tool to respond."}):t?a.jsx(cl,{code:IUt(t),lang:"json",className:"overflow-x-auto p-4 text-caption whitespace-pre"}):a.jsx(Xt,{iconSlot:a.jsx(oIn,{}),titleSlot:"No response yet",descriptionSlot:"Run the tool to see its output here."})}function pCs({run:e}){return a.jsxs("div",{className:"flex items-center gap-2",children:[e.status==="success"?a.jsx(Mt,{variant:"success",emphasis:"subtle",indicator:"dot",children:"Success"}):a.jsx(Mt,{variant:"destructive",emphasis:"subtle",indicator:"dot",children:"Error"}),a.jsx(Y,{as:"span",variant:"caption",font:"mono",tone:"muted",children:lCs(e.durationMs)}),a.jsx(Zi,{content:IUt(e),copyMessage:"Response copied",tooltip:"Copy response",size:"icon-sm"})]})}function mCs({isRunning:e,lastRun:t}){return a.jsxs($A,{className:"h-full",children:[a.jsx(ZJ,{action:!e&&t&&a.jsx(pCs,{run:t}),children:a.jsx(RA,{children:"Response"})}),a.jsx(p$,{className:"grid min-h-48 flex-1 content-center",children:a.jsx(hCs,{isRunning:e,lastRun:t})})]})}function NUt({zodInputSchema:e,execution:t,requestContextEntityType:n,requestContextEntityId:r}){const[s]=xr(n,r),[i,o]=g.useState(),l=async u=>{const d=performance.now();await t.execute(u,s).catch(()=>{}),o(performance.now()-d)},c=t.status==="pending";return a.jsxs("div",{className:"grid h-full grid-rows-[auto_1fr] gap-6",children:[a.jsx(fCs,{zodInputSchema:e,isRunning:c,onRun:l,requestContextEntityType:n,requestContextEntityId:r}),a.jsx(mCs,{isRunning:c,lastRun:uCs(t,i)})]})}function AUt(e){return Jf(e)?OS(e):yr({})}function gCs({serverId:e,tool:t}){const{mutateAsync:n,status:r,data:s,error:i}=Oar({serverId:e,toolId:t.name}),{data:o}=Sar({serverId:e,appResourceUri:oCs(t._meta)}),l=AUt(t.inputSchema),c={execute:(u,d)=>n({data:u,requestContext:d}),status:r,output:s,error:i};return a.jsxs("div",{className:"grid content-start gap-6",children:[o&&a.jsx(p8t,{html:o,toolName:t.name,onToolCall:(u,d)=>n({data:d})}),aCs(s)&&a.jsxs(Ht,{variant:"warning",children:["This tool asked for more input, which Studio cannot provide. The suspend payload below shows what it needs. Call it from an MCP client with an ",a.jsx(ih,{children:"inputRequests"})," handler to finish the request."]}),a.jsx(NUt,{zodInputSchema:l,execution:c,requestContextEntityType:"mcp-tool",requestContextEntityId:`${e}:${t.name}`})]})}const PUt=g.createContext(void 0),vCs=PUt.Provider;function tAe(){const e=g.useContext(PUt);if(e===void 0)throw new Error("useOpenToolId must be used inside ToolDrawer");return e}function yCs({description:e}){const t=cTe({collapsedHeight:140});return a.jsx(yX,{state:t,expandLabel:"Read more",children:a.jsx(pc,{children:e})})}function $Ut({description:e,overview:t,playground:n,canRun:r}){return a.jsx(a.Fragment,{children:a.jsxs(Qc,{defaultTab:"overview",className:"grid flex-1 grid-rows-[auto_1fr] gap-4 overflow-visible",children:[a.jsxs(Zc,{variant:"pill",size:"sm",children:[a.jsx(ni,{value:"overview",children:"Overview"}),a.jsx(ni,{value:"playground",disabled:!r,disabledTooltip:"You don't have permission to execute tools.",children:"Playground"})]}),a.jsxs(No,{value:"overview",flush:!0,className:"content-start gap-6",children:[e&&a.jsx(jl,{className:"p-4",children:a.jsx(yCs,{description:e})}),t]}),a.jsx(No,{value:"playground",flush:!0,keepMounted:!0,className:"h-full",children:r&&n})]})})}function xCs(e){return e.map(t=>JSON.stringify(t)).join(" | ")}function Ott(e){return e.map(f3).join(" | ")}function f3(e){return Jf(e)?Array.isArray(e.enum)?xCs(e.enum):"const"in e?JSON.stringify(e.const):Array.isArray(e.anyOf)?Ott(e.anyOf):Array.isArray(e.oneOf)?Ott(e.oneOf):Array.isArray(e.type)?e.type.join(" | "):e.type==="array"?`${f3(e.items)}[]`:RUt(e)?`Record<string, ${f3(e.additionalProperties)}>`:typeof e.type=="string"?e.type:"unknown":"unknown"}function bCs(e,t,n,{defaultsAreOptional:r=!1}){const s=Jf(t)?t:{},i="default"in s;return{name:e,type:f3(s),required:n.has(e)&&!(r&&i),description:typeof s.description=="string"?s.description:void 0,defaultValue:i?JSON.stringify(s.default):void 0}}function wCs(e,t={}){if(!Jf(e)||!Jf(e.properties))return[];const n=new Set(Array.isArray(e.required)?e.required.filter(r=>typeof r=="string"):[]);return Object.entries(e.properties).map(([r,s])=>bCs(r,s,n,t))}function RUt(e){return Jf(e)&&e.type==="object"&&!Jf(e.properties)&&Jf(e.additionalProperties)}function SCs(e){return Jf(e)&&(e.type==="object"||Jf(e.properties))}const kCs=["type","properties","items","enum","const","anyOf","oneOf","allOf","$ref"];function OCs(e){return!Jf(e)||!kCs.some(t=>t in e)}function jCs(){return a.jsxs(a.Fragment,{children:[a.jsx("span",{"aria-hidden":!0,className:"ml-0.5 text-destructive-indicator",children:"*"}),a.jsx("span",{className:"sr-only",children:" (required)"})]})}function CCs({field:e}){return a.jsxs(a.Fragment,{children:[e.description,e.defaultValue!==void 0&&a.jsxs("span",{className:"block",children:["Default ",e.defaultValue]})]})}function _Cs({field:e}){const t=!!e.description||e.defaultValue!==void 0;return a.jsx(dz,{label:a.jsxs(Y,{as:"span",variant:"body-sm",font:"mono",tone:"ink",children:[e.name,e.required&&a.jsx(jCs,{})]}),description:t&&a.jsx(CCs,{field:e}),children:a.jsx(Y,{as:"span",variant:"caption",font:"mono",tone:"muted",children:e.type})})}function Aye({message:e}){return a.jsx(dz,{label:a.jsx(Y,{as:"span",variant:"body-sm",tone:"muted",children:e})})}function TCs({schema:e,emptyMessage:t,defaultsAreOptional:n}){if(OCs(e))return a.jsx(Aye,{message:t});if(!SCs(e)||RUt(e))return a.jsx(dz,{label:"Type",children:a.jsx(Y,{as:"span",variant:"caption",font:"mono",tone:"muted",children:f3(e)})});const r=wCs(e,{defaultsAreOptional:n});return r.length===0?a.jsx(Aye,{message:t}):r.map(s=>a.jsx(_Cs,{field:s},s.name))}function mue({title:e,...t}){return a.jsxs($A,{children:[a.jsx(ZJ,{children:a.jsx(RA,{children:e})}),a.jsx(p$,{children:a.jsx(TCs,{...t})})]})}function MUt({inputSchema:e,outputSchema:t,requestContextSchema:n,footer:r}){return a.jsxs("div",{className:"grid gap-6",children:[a.jsx(mue,{title:"Input",schema:e,emptyMessage:"This tool takes no input.",defaultsAreOptional:!0}),a.jsx(mue,{title:"Output",schema:t,emptyMessage:"No output schema defined."}),n!==void 0&&a.jsx(mue,{title:"Request context",schema:n,emptyMessage:"No request context fields.",defaultsAreOptional:!0}),r]})}function ECs({serverId:e}){const t=tAe(),{canExecute:n}=Wa(),{data:r,isLoading:s}=kar({serverId:e,toolId:t});return s?a.jsx(Ot.LoadingData,{}):r?a.jsx($Ut,{description:r.description,overview:a.jsx(MUt,{inputSchema:r.inputSchema}),canRun:n("tools"),playground:a.jsx(gCs,{serverId:e,tool:r})}):a.jsxs(Ot.NoData,{children:['This server has no tool "',t,'".']})}const DUt={agent:ko,workflow:Ol,tool:ud},jtt="auto 1fr auto",ICs={tool:"Tool",agent:"Agent",workflow:"Workflow"};function NCs(e){return e in DUt}function ACs({type:e}){const t=NCs(e)?e:"tool",n=DUt[t],r=ICs[t];return a.jsxs(Ln,{children:[a.jsx(Rn,{asChild:!0,children:a.jsx("span",{"aria-label":t,className:"inline-flex text-muted-foreground [&>svg]:size-4",children:a.jsx(n,{})})}),a.jsx(Mn,{children:r})]})}const PCs=yr({ui:yr({resourceUri:_n().optional()}).optional(),"ui/resourceUri":_n().optional()});function $Cs(e){const t=PCs.safeParse(e);return t.success?!!(t.data.ui?.resourceUri?.startsWith("ui://")||t.data["ui/resourceUri"]?.startsWith("ui://")):!1}function RCs({server:e}){const[t,n]=g.useState(""),{data:r={},isLoading:s}=gkt({selectedServer:e}),{Link:i,paths:o}=xn(),l=g.useMemo(()=>{const d=t.toLowerCase();return Object.values(r).filter(f=>f.name.toLowerCase().includes(d)||f.description?.toLowerCase().includes(d))},[r,t]),{containerRef:c,getRowProps:u}=Du({count:l.length});return a.jsxs("section",{className:"flex flex-col gap-3",children:[a.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[a.jsx(Y,{as:"h2",variant:"heading",children:"Available tools"}),a.jsx("div",{className:"max-w-120 flex-1",children:a.jsx(Ru,{onSearch:n,label:"Filter tools",placeholder:"Filter by name",shortcutDisabled:!0})})]}),s?a.jsx($u,{columns:jtt}):a.jsxs(Te,{columns:jtt,scrollRef:c,children:[a.jsxs(Te.Top,{children:[a.jsx(Te.TopCell,{children:"Name"}),a.jsx(Te.TopCell,{children:"Description"}),a.jsx(Te.TopCell,{className:"justify-center text-center",children:"Type"})]}),l.length===0&&t?a.jsx(Te.NoMatch,{message:"No tools match your search"}):null,l.map((d,f)=>a.jsxs(Te.RowLink,{to:o.mcpServerToolLink(e.id,d.name),LinkComponent:i,...u(f),children:[a.jsx(Te.NameCell,{children:a.jsxs("span",{className:"flex items-center gap-2",children:[d.name,$Cs(d._meta)&&a.jsx(Mt,{size:"xs",children:"App"})]})}),a.jsx(Te.DescriptionCell,{children:d.description}),a.jsx(Te.TextCell,{className:"justify-center text-center",children:a.jsx(ACs,{type:d.toolType??"tool"})})]},d.name))]})]})}const MCs=({isLoading:e,server:t})=>{const[{sseUrl:n,httpStreamUrl:r},s]=g.useState({sseUrl:"",httpStreamUrl:""});if(g.useEffect(()=>{if(!t)return;const c=window.MASTRA_SERVER_HOST,u=window.MASTRA_SERVER_PORT;let d=null;c&&u&&(d=`http://${c}:${u}`);const f=d||"http://localhost:4111",h=`${f}/api/mcp/${t.id}/sse`,p=`${f}/api/mcp/${t.id}/mcp`;s({sseUrl:h,httpStreamUrl:p})},[t]),e)return null;if(!t)return a.jsx(Y,{as:"h1",variant:"heading",tone:"muted",className:"py-20 text-center",children:"Server not found"});const i=t.transports?.includes("sse")??!0,o=`npx -y mcp-remote ${i?n:r}`,l=[{value:"http",label:"HTTP",description:"Use for stateless HTTP transport with streamable responses.",content:r,tooltip:"Copy HTTP Stream URL"},...i?[{value:"sse",label:"SSE",description:"Use for real-time communication via SSE.",content:n,tooltip:"Copy SSE URL"}]:[],{value:"cli",label:"CLI",description:"Use for local command-line access via npx and mcp-remote.",content:o,tooltip:"Copy Command Line Config"}];return a.jsxs("div",{className:"flex flex-col gap-6 pt-4",children:[a.jsx(jl,{children:a.jsxs(Qc,{defaultTab:"http",children:[a.jsxs(cQ,{className:"flex-row items-center justify-between gap-3 space-y-0 border-b border-border",children:[a.jsx(Q0,{className:"shrink-0",children:"Connect"}),a.jsx("div",{className:"min-w-0",children:a.jsx(Zc,{variant:"pill-ghost",size:"sm",children:l.map(c=>a.jsx(ni,{value:c.value,children:c.label},c.value))})})]}),l.map(c=>a.jsx(No,{value:c.value,flush:!0,children:a.jsxs(Um,{className:"flex flex-col gap-3",children:[a.jsx(Y,{tone:"muted",children:c.description}),a.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg bg-muted py-2 pr-2 pl-3",children:[a.jsx(Y,{as:"span",font:"mono",className:"min-w-0 break-all",children:c.content}),a.jsx(Zi,{tooltip:c.tooltip,content:c.content})]})]})},c.value))]})}),a.jsx(RCs,{server:t})]})};function LUt(){const[e,t]=oi();return{toolId:e.get("tool")??void 0,close:()=>t(s=>{const i=new URLSearchParams(s);return i.delete("tool"),i},{replace:!0})}}function nAe({children:e}){const{toolId:t,close:n}=LUt();return a.jsxs(Ot,{open:t!==void 0,onClose:n,title:t??"",children:[a.jsxs(Ot.Header,{children:[a.jsxs(Ot.Heading,{children:[a.jsx(At,{size:"sm",className:"text-muted-foreground",children:a.jsx(ud,{})}),a.jsx("span",{className:"truncate",children:t})]}),a.jsx(Ot.HeaderActions,{children:a.jsx(Ot.CloseButton,{icon:"x",tooltip:"Close tool",onClick:n})})]}),a.jsx(Ot.Content,{className:"flex flex-col gap-4 px-3",children:t&&a.jsx(vCs,{value:t,children:e},t)})]})}const DCs=()=>{const{serverId:e}=jr(),t=[_s("/mcps"),llr],{data:n=[],isLoading:r}=NP(),s=n.find(l=>l.id===e),i=s?.transports?.includes("sse")??!0,o=r||s?a.jsxs($c,{children:[a.jsx($c.Title,{isLoading:r,children:s?.name}),s&&a.jsx($c.Meta,{beside:!0,children:a.jsxs(Mt,{size:"sm",children:["v",s.version_detail.version]})}),s&&a.jsx($c.Description,{children:i?"This MCP server can be accessed through multiple transport methods. Choose the one that best fits your use case.":"This MCP server speaks Streamable HTTP only (protocol 2026-07-28)."})]}):void 0;return a.jsxs(Et,{variant:"narrow",breadcrumbs:a.jsx(Dt,{crumbs:t}),header:o,children:[a.jsx(MCs,{isLoading:r,server:s}),e&&a.jsx(nAe,{children:a.jsx(ECs,{serverId:e})})]})},zUt=[{label:"Agent",entityType:"agent"},{label:"Workflow",entityType:"workflow_run"},{label:"Scorer",entityType:"scorer"},{label:"Ingest",entityType:"rag_ingestion"}],FA="rootEntityType",BA={tags:"filterTags",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"},WJ=Object.keys(BA),rAe="mastra:metrics:saved-filters";function LCs(e){const t=VCs(e);try{localStorage.setItem(rAe,t.toString())}catch{}}function zCs(){try{localStorage.removeItem(rAe)}catch{}}function FUt(){try{const e=localStorage.getItem(rAe);if(!e)return null;const t=new URLSearchParams(e);return t.toString()?t:null}catch{return null}}function FCs(e){if(e.has(FA))return!0;for(const t of WJ)if(e.has(BA[t]))return!0;return!1}function BUt({availableTags:e,availableEntityNames:t,availableServiceNames:n,availableEnvironments:r,loading:s}){const i=[{id:"rootEntityType",label:"Primitive type",kind:"pick-multi",searchable:!1,options:zUt.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:"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"}],o=(u,d)=>u.label.localeCompare(d.label),l=i.filter(u=>u.kind==="pick-multi").sort(o),c=i.filter(u=>u.kind==="text").sort(o);return[...l,...c]}function BCs(e){const t=[],n=new Map([[FA,"rootEntityType"]]);for(const s of WJ)n.set(BA[s],s);const r=new Set;for(const[s]of e.entries()){const i=n.get(s);if(!i||r.has(i))continue;if(r.add(i),i==="tags"){const l=e.getAll(s);if(l.length===0)continue;t.push({fieldId:i,value:l.filter(Boolean)});continue}if(i==="rootEntityType"||i==="entityName"||i==="serviceName"||i==="environment"||i==="provider"||i==="model"){const l=e.getAll(s);if(l.length>1){t.push({fieldId:i,value:l});continue}}const o=e.get(s);o!==null&&t.push({fieldId:i,value:o})}return t}function VCs(e){const t=new URLSearchParams,n=e.getAll(FA);for(const r of n)t.append(FA,r);for(const r of WJ){const s=BA[r],i=e.getAll(s);for(const o of i)t.append(s,o)}return t}function UCs(e,t){e.delete(FA);for(const n of WJ)e.delete(BA[n]);for(const n of t){const r=n.fieldId==="rootEntityType"?FA:BA[n.fieldId];if(r)if(Array.isArray(n.value)){const s=n.value.filter(i=>typeof i=="string"&&i!=="");if(s.length===0){n.fieldId==="tags"&&e.append(r,"");continue}for(const i of s)e.append(r,i)}else typeof n.value=="string"&&e.set(r,n.value.trim())}}const qCs="Any";function Ctt(e){const t=e.trim();return t===""||t===qCs}const QCs=new Set(zUt.map(e=>e.entityType));function _tt(e){const t=e.trim();return QCs.has(t)?t:void 0}function ZCs(e){const t={};for(const n of e){const r=n.fieldId;if(Array.isArray(n.value)){const s=n.value.filter(i=>typeof i=="string").map(i=>i.trim()).filter(i=>!Ctt(i));if(s.length===0)continue;if(r==="tags")t.tags=s;else if(r==="rootEntityType"){const i=s[0],o=i!==void 0?_tt(i):void 0;o&&(t.rootEntityType=o)}else t[r]=s[0]}else if(typeof n.value=="string"){if(Ctt(n.value))continue;const s=n.value.trim();if(r==="rootEntityType"){const i=_tt(s);i&&(t.rootEntityType=i)}else t[r]=s}}return t}const VUt=[{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"}],WCs=new Set(VUt.map(e=>e.value));function HCs(e){return typeof e=="string"&&(WCs.has(e)||e==="custom")}const UUt=g.createContext({datePreset:"24h",setDatePreset:()=>{},customRange:void 0,setCustomRange:()=>{},dateRangeLabel:"Last 24 hours",comparisonLabel:"vs previous 24h",filterTokens:[],setFilterTokens:()=>{},dimensionalFilter:{},dimensionalFilterKey:"{}"});function Fk(){return g.useContext(UUt)}function GCs(e,t){return e!=="custom"?VUt.find(n=>n.value===e)?.label??e:t?.from?t.to?`${PI(t.from)} – ${PI(t.to)}`:PI(t.from)??"":"Custom range"}const Ttt=3600*1e3;function KCs(e,t){if(e!=="custom")return`vs previous ${e}`;const n=t?.to?.getTime()??Date.now(),r=t?.from?.getTime()??n-24*Ttt,s=Math.round((n-r)/Ttt);return`vs previous ${s>24&&s%24===0?`${s/24}d`:`${s}h`}`}function YCs({children:e,preset:t,filterTokens:n,onPresetChange:r,onFilterTokensChange:s,customRange:i,onCustomRangeChange:o}){const l=g.useMemo(()=>JSON.stringify(n),[n]),c=g.useMemo(()=>n,[l]),u=g.useMemo(()=>ZCs(c),[c]),d=g.useMemo(()=>JSON.stringify(u),[u]),f=GCs(t,i),h=KCs(t,i),p=g.useMemo(()=>({datePreset:t,setDatePreset:r,customRange:i,setCustomRange:o??(()=>{}),dateRangeLabel:f,comparisonLabel:h,filterTokens:c,setFilterTokens:s,dimensionalFilter:u,dimensionalFilterKey:d}),[t,r,i,o,f,h,c,s,u,d]);return a.jsx(UUt.Provider,{value:p,children:e})}const XCs=["last-24h","last-3d","last-7d","last-14d","last-30d","custom"];function JCs(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 e_s(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 t_s(){const{datePreset:e,setDatePreset:t,customRange:n,setCustomRange:r}=Fk(),s=g.useRef(e);s.current=e;const i=g.useRef(n);return i.current=n,a.jsx(MY,{preset:JCs(e),onPresetChange:o=>{const l=e_s(o);s.current=l,t(l)},dateFrom:n?.from,dateTo:n?.to,onDateChange:(o,l)=>{if(s.current!=="custom")return;const c={...i.current,[l]:o};i.current=c,r(c)},presets:XCs})}function HJ({onClick:e}){return a.jsx(de,{onClick:e,variant:"ghost",size:"icon-md",tooltip:"View in Traces","aria-label":"View in Traces",children:a.jsx(Ba,{})})}function qUt({onClick:e}){return a.jsx(de,{onClick:e,variant:"ghost",size:"icon-md",tooltip:"View errors in Logs","aria-label":"View errors in Logs",children:a.jsx(RTn,{})})}function n_s({children:e,reveal:t="always",className:n}){return a.jsx("div",{className:Z("flex shrink-0 items-center gap-1 self-center",t==="hover"&&"opacity-0 transition-opacity duration-150 group-hover/metrics-card:opacity-100 focus-within:opacity-100",n),children:e})}function r_s({children:e,className:t}){return a.jsx("div",{className:Z("overflow-x-auto overflow-y-hidden [&_tbody>tr:last-child]:border-b-0",t),children:e})}function QUt({children:e,className:t}){return a.jsx(Y,{tone:"faint",className:Z("mt-0.5",t),children:e})}function s_s({message:e="Failed to load data",className:t}){return a.jsx("div",{className:Z("flex flex-col items-center justify-center gap-3",t),children:a.jsx(Y,{variant:"caption",className:"text-destructive-foreground",children:e})})}function i_s({className:e}){return a.jsx("div",{className:Z("flex items-center justify-center",e),children:a.jsx(En,{size:"md",variant:"pulse",className:"text-placeholder"})})}function o_s({message:e="No data yet",className:t}){return a.jsx("div",{className:Z("flex h-full items-center justify-center",t),children:a.jsx(Y,{tone:"faint",children:e})})}function Ett({children:e,className:t}){return a.jsx(jl,{className:Z("group/metrics-card grid min-h-72 min-w-80 flex-1 grid-rows-[auto_1fr] gap-4 px-4 py-3 2xl:min-w-120 md:min-w-88 lg:min-w-sm xl:min-w-104",t),children:e})}function a_s({value:e,label:t,isLoading:n=!1,className:r}){return n?a.jsxs("div",{className:Z("order-last flex shrink-0 flex-col items-end",r),children:[a.jsx(zU,{line:"text-body",className:"h-4 w-14"}),t&&a.jsx(zU,{line:"text-body mt-0.5",className:"w-10"})]}):a.jsxs("div",{className:Z("order-last text-right",r),children:[a.jsx(Y,{tone:"muted",className:"tabular-nums",children:e}),t&&a.jsx(Y,{tone:"faint",className:"mt-0.5",children:t})]})}function l_s({value:e,onValueChange:t,children:n}){return a.jsx(Qc,{value:e,onValueChange:t,defaultTab:e,children:a.jsx(Zc,{variant:"pill-ghost",size:"sm",children:n})})}function c_s({className:e,...t}){return a.jsx(ni,{...t,className:Z("h-6 px-2.5 text-column",e)})}function ZUt({children:e,className:t,as:n="h2"}){return a.jsx(n,{className:Z("text-body text-foreground",t),children:e})}function u_s(e){if("children"in e)return a.jsx("div",{className:e.className,children:e.children});const{title:t,description:n,titleAs:r}=e;return a.jsxs("div",{className:e.className,children:[a.jsx(ZUt,{as:r,children:t}),n&&a.jsx(QUt,{children:n})]})}function d_s({children:e,className:t}){return a.jsx("div",{className:Z("flex min-w-0 flex-wrap items-center justify-between gap-x-4 gap-y-2 [&>*:first-child]:min-w-0 [&>*:last-child:not(:first-child)]:ml-auto",t),children:e})}function f_s({children:e,className:t}){return a.jsx("div",{className:Z("flex items-start gap-4 [&>:first-child]:min-w-0 [&>:first-child]:flex-1",t),children:e})}const gi=Object.assign(Ett,{Root:Ett,Kpi:Kf,TopBar:f_s,Toolbar:d_s,Tabs:l_s,Tab:c_s,Actions:n_s,TitleAndDescription:u_s,Title:ZUt,Description:QUt,Summary:a_s,Loading:i_s,Error:s_s,Content:r_s,NoData:o_s});function tT({isEmpty:e=!1,emptyMessage:t="No data in this range.",children:n}){return a.jsxs("div",{className:"relative flex min-h-0 flex-1 flex-col",children:[n,e&&a.jsx(gi.NoData,{message:t,className:"absolute inset-0"})]})}function oh({title:e,description:t,summary:n,actions:r,toolbar:s,isUpdating:i=!1,className:o,children:l}){const c=Z("transition-opacity duration-200",i&&"opacity-50");return a.jsxs(gi,{className:Z("min-h-0! min-w-0!",o),children:[a.jsxs(gi.TopBar,{children:[a.jsx(gi.TitleAndDescription,{title:e,description:t}),r&&a.jsx(gi.Actions,{reveal:"hover",children:r}),n&&a.jsx("div",{className:Z("order-last flex w-24 shrink-0 justify-end",c),children:n})]}),a.jsxs(gi.Content,{className:"flex flex-col gap-4 overflow-visible",children:[s,a.jsx("div",{className:Z("relative flex h-60 min-h-0 min-w-0 flex-col",c),children:l})]})]})}function nT(){return a.jsx(gi.Error,{message:"Couldn't load this data. Try again in a moment.",className:"h-full"})}function GJ({label:e,icon:t,isError:n=!1,...r}){return a.jsxs(Kf,{children:[a.jsx(Kf.Label,{icon:a.jsx(t,{}),children:e}),n?a.jsx(h_s,{}):a.jsx(p_s,{...r})]})}function h_s(){return a.jsxs(a.Fragment,{children:[a.jsx(Kf.ValueRow,{className:"mt-1",children:a.jsx(Kf.Value,{children:"—"})}),a.jsx(Kf.Footer,{detail:a.jsx("span",{className:"text-destructive-foreground",children:"Couldn't load"})})]})}function p_s({value:e,change:t,lowerIsBetter:n,detail:r,previous:s,comparison:i,isLoading:o=!1,isUpdating:l=!1}){const c=Z("transition-opacity duration-200",l&&"opacity-50");return a.jsxs(a.Fragment,{children:[a.jsxs(Kf.ValueRow,{className:Z("mt-1",c),isLoading:o,children:[a.jsx(Kf.Value,{children:e}),t!==void 0&&a.jsx(Kf.Change,{changePct:t,comparison:i,lowerIsBetter:n,prevValue:s})]}),a.jsx(Kf.Footer,{detail:r,prevValue:t===void 0?void 0:s,isLoading:o,className:c})]})}const m_s={2:"@3xl:grid-cols-2",3:"@3xl:grid-cols-2 @7xl:grid-cols-3"},g_s={1:"",2:"@3xl:col-span-2",full:"col-span-full"};function Jw({children:e,columns:t=3,className:n}){return a.jsx("div",{className:Z("@container",n),children:a.jsx("div",{className:Z("grid gap-4",m_s[t]),children:e})})}function v_s({children:e,span:t=1,className:n}){return a.jsx("div",{className:Z("min-w-0 *:w-full *:min-w-0!",g_s[t],n),children:e})}Jw.Item=v_s;const Pye=1440*60*1e3,y_s={"24h":Pye,"3d":4320*60*1e3,"7d":10080*60*1e3,"14d":336*60*60*1e3,"30d":720*60*60*1e3};function x_s(e,t,n){if(e!=="custom"){const r=y_s[e]??Pye;return{start:new Date(n-r),end:new Date(n)}}return{start:t?.from??new Date(n-Pye),end:t?.to??new Date(n)}}function b_s({datePreset:e,customRange:t,dimensionalFilter:n,dimensionalFilterKey:r}){const s=g.useRef(null),i=e==="custom"?`custom:${t?.from?.getTime()??""}:${t?.to?.getTime()??""}`:`preset:${e}`;(!s.current||s.current.key!==i)&&(s.current={key:i,anchor:Date.now()});const o=s.current.anchor,l=g.useMemo(()=>x_s(e,t,o),[e,t,o]);return{datePreset:e,customRange:t,timestamp:l,filters:g.useMemo(()=>({timestamp:l,...n}),[l,r]),dimensionalFilter:n,filterKey:g.useMemo(()=>`${i}|${r}`,[i,r])}}function w_s(e){const t=Ye(),{filters:n,filterKey:r,queryOptions:s}=e;return _t({queryKey:["metrics","active-threads-kpi",r],queryFn:()=>t.getMetricAggregate({name:["mastra_agent_duration_ms"],aggregation:"count_distinct",distinctColumn:"threadId",filters:n,comparePeriod:"previous_period"}),...s})}function WUt(e){const t=Ye(),{filters:n,filterKey:r,queryOptions:s}=e;return _t({queryKey:["metrics","agent-runs-kpi",r],queryFn:()=>t.getMetricAggregate({name:["mastra_agent_duration_ms"],aggregation:"count",filters:n,comparePeriod:"previous_period"}),...s})}function S_s(e){const t=Ye(),{filters:n,filterKey:r,queryOptions:s}=e;return _t({queryKey:["metrics","model-cost-kpi",r],queryFn:async()=>{const i=await t.getMetricAggregate({name:["mastra_model_total_input_tokens","mastra_model_total_output_tokens"],aggregation:"sum",filters:n,comparePeriod:"previous_period"});return{cost:i.estimatedCost??null,costUnit:i.costUnit??null,previousCost:i.previousEstimatedCost??null,costChangePercent:i.costChangePercent??null}},...s})}new Set(Intl.supportedValuesOf("currency"));function k_s(e){const t=Ye(),{filters:n,filterKey:r,queryOptions:s}=e;return _t({queryKey:["metrics","token-usage-by-agent",r],queryFn:async()=>{const i={groupBy:["entityName"],aggregation:"sum",orderDirection:"DESC",filters:n},[o,l]=await Promise.all([t.getMetricBreakdown({...i,name:["mastra_model_total_input_tokens"]}),t.getMetricBreakdown({...i,name:["mastra_model_total_output_tokens"]})]),c=new Map,u=f=>dNe(c,f,()=>({input:0,output:0,cost:null,costUnit:null})),d=(f,h)=>{h.estimatedCost!=null&&(f.cost=(f.cost??0)+h.estimatedCost,h.costUnit&&(f.costUnit=h.costUnit))};for(const f of o.groups){const h=u(f.dimensions.entityName??"unknown");h.input=f.value,d(h,f)}for(const f of l.groups){const h=u(f.dimensions.entityName??"unknown");h.output=f.value,d(h,f)}return Array.from(c.entries()).map(([f,h])=>({name:f,input:h.input,output:h.output,total:h.input+h.output,cost:h.cost,costUnit:h.costUnit})).sort((f,h)=>h.total-f.total)},...s})}function O_s(e){const t=Ye(),{filters:n,filterKey:r,queryOptions:s}=e;return _t({queryKey:["metrics","total-tokens-kpi",r],queryFn:async()=>{const[i,o]=await Promise.all([t.getMetricAggregate({name:["mastra_model_total_input_tokens"],aggregation:"sum",filters:n,comparePeriod:"previous_period"}),t.getMetricAggregate({name:["mastra_model_total_output_tokens"],aggregation:"sum",filters:n,comparePeriod:"previous_period"})]),l=i.value!=null||o.value!=null,c=i.previousValue!=null||o.previousValue!=null,u=(i.value??0)+(o.value??0),d=(i.previousValue??0)+(o.previousValue??0),f=c&&d>0?(u-d)/d*100:null;return{value:l?u:null,previousValue:c?d:null,changePercent:f}},...s})}async function gue(e,t,n){const r=await e.getMetricBreakdown({name:[t],groupBy:["entityName","status"],aggregation:"count",orderDirection:"DESC",filters:n}),s=new Map;for(const i of r.groups){const o=i.dimensions.entityName??"unknown",l=i.dimensions.status??"ok",c=dNe(s,o,()=>({completed:0,errors:0}));l==="error"?c.errors+=i.value:c.completed+=i.value}return Array.from(s.entries()).map(([i,o])=>({name:i,...o})).sort((i,o)=>o.completed+o.errors-(i.completed+i.errors))}function j_s(e){const t=Ye(),{filters:n,filterKey:r,queryOptions:s}=e;return _t({queryKey:["metrics","trace-volume",r],queryFn:async()=>{const[i,o,l]=await Promise.all([gue(t,"mastra_agent_duration_ms",n),gue(t,"mastra_workflow_duration_ms",n),gue(t,"mastra_tool_duration_ms",n)]);return{agentData:i,workflowData:o,toolData:l}},...s})}function mf(){const{datePreset:e,customRange:t,dimensionalFilter:n,dimensionalFilterKey:r}=Fk();return b_s({datePreset:e,customRange:t,dimensionalFilter:n,dimensionalFilterKey:r})}function av(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e4?`${(e/1e3).toFixed(1)}K`:e>=1e3?`${(e/1e3).toFixed(2)}K`:String(Math.round(e))}function Itt(e){return e>=1e4?`${(e/1e3).toFixed(1)}s`:e>=1e3?`${(e/1e3).toFixed(2)}s`:`${Math.round(e)}ms`}function $ye(e){const t=e*100;return t===0?"0%":t<.1?"<0.1%":`${t<10?t.toFixed(2):t.toFixed(1)}%`}function Qj(e){return e>0&&e<.01?"<$0.01":`$${e.toFixed(2)}`}function C_s(e){return e>=1e6?`${+(e/1e6).toFixed(1)}M`:e>=1e3?`${+(e/1e3).toFixed(1)}K`:String(Math.round(e))}function __s(e){return e>=1e3?`${+(e/1e3).toFixed(1)}s`:`${Math.round(e)}ms`}function T_s({children:e,className:t}){return a.jsx("div",{className:"@container",children:a.jsx("div",{className:Z("grid gap-4 *:min-w-0! @xl:grid-cols-2 @3xl:has-[>:nth-child(5)]:grid-cols-3 @4xl:grid-cols-[repeat(auto-fit,minmax(12rem,1fr))] @6xl:has-[>:nth-child(5)]:grid-cols-[repeat(auto-fit,minmax(12rem,1fr))]!",t),children:e})})}const KJ={placeholderData:ox},sAe=e=>e==null?"—":av(e),E_s=e=>e==null?"—":Qj(e),YJ=e=>e==null||!Number.isFinite(e)?void 0:e,iAe=e=>e==null?void 0:av(e),I_s=e=>e==null?void 0:Qj(e);function N_s(){return a.jsxs(T_s,{children:[a.jsx(A_s,{}),a.jsx(P_s,{}),a.jsx($_s,{}),a.jsx(R_s,{})]})}function A_s(){const{comparisonLabel:e}=Fk(),{data:t,isLoading:n,isPlaceholderData:r,isError:s}=WUt({...mf(),queryOptions:KJ});return a.jsx(GJ,{label:"Agent runs",icon:M0e,value:sAe(t?.value),change:YJ(t?.changePercent),detail:"in this range",previous:iAe(t?.previousValue),comparison:e,isLoading:n,isUpdating:r,isError:s})}function P_s(){const{comparisonLabel:e}=Fk(),{data:t,isLoading:n,isPlaceholderData:r,isError:s}=S_s({...mf(),queryOptions:KJ});return a.jsx(GJ,{label:"Model cost",icon:HCn,value:E_s(t?.cost),change:YJ(t?.costChangePercent),lowerIsBetter:!0,detail:"estimated",previous:I_s(t?.previousCost),comparison:e,isLoading:n,isUpdating:r,isError:s})}function $_s(){const{comparisonLabel:e}=Fk(),{data:t,isLoading:n,isPlaceholderData:r,isError:s}=O_s({...mf(),queryOptions:KJ});return a.jsx(GJ,{label:"Tokens",icon:x_,value:sAe(t?.value),change:YJ(t?.changePercent),detail:"input and output",previous:iAe(t?.previousValue),comparison:e,isLoading:n,isUpdating:r,isError:s})}function R_s(){const{comparisonLabel:e}=Fk(),{data:t,isLoading:n,isPlaceholderData:r,isError:s}=w_s({...mf(),queryOptions:KJ});return a.jsx(GJ,{label:"Threads",icon:H0e,value:sAe(t?.value),change:YJ(t?.changePercent),detail:"with agent runs",previous:iAe(t?.previousValue),comparison:e,isLoading:n,isUpdating:r,isError:s})}const HUt=36e5,M_s=24*HUt,D_s=(e,t)=>t.getTime()-e.getTime()>M_s+HUt,$7=e=>e.toLocaleDateString("en-US",{month:"short",day:"numeric"}),Ntt=e=>e.toLocaleTimeString("en-US",{hour:"numeric"});function L_s(e,t,n){const r=new Date(e);if(t>=24)return{ts:e,label:$7(r),edgeLabel:$7(r),time:r.toLocaleDateString("en-US",{weekday:"short",month:"short",day:"numeric"})};const s=r.toLocaleString("en-US",{month:"short",day:"numeric",hour:"numeric"}),i=`${$7(r)}, ${Ntt(r)}`;return n?{ts:e,label:r.getHours()===0?$7(r):i,edgeLabel:i,time:s}:{ts:e,label:Ntt(r),edgeLabel:i,time:s}}const GUt=36e5,R7=24*GUt,M7=GUt;function rT(e,t){const n=t.getTime()-e.getTime();return n<=R7+M7?{interval:"1h",stepHours:1}:n<=3*R7+M7?{interval:"1h",stepHours:3}:n<=7*R7+M7?{interval:"1h",stepHours:6}:n<=14*R7+M7?{interval:"1h",stepHours:12}:{interval:"1d",stepHours:24}}const oAe=e=>e==="1h"?1:24;function aAe(e,t){const n=new Date(e);if(t>=24)return new Date(n.getFullYear(),n.getMonth(),n.getDate()).getTime();const r=Math.floor(n.getHours()/t)*t;return new Date(n.getFullYear(),n.getMonth(),n.getDate(),r).getTime()}function KUt(e,t){const n=new Date(e);return t>=24?new Date(n.getFullYear(),n.getMonth(),n.getDate()+1).getTime():aAe(new Date(n.getFullYear(),n.getMonth(),n.getDate(),n.getHours()+t).getTime(),t)}function lAe(e,t,n){const r=D_s(e,t),s=[];for(let i=aAe(e.getTime(),n);i<=t.getTime();i=KUt(i,n))s.push(L_s(i,n,r));return s}function cAe(e,t){const n=new Map(e.map((r,s)=>[r.ts,s]));return r=>n.get(aAe(new Date(r.timestamp).getTime(),t))}function XJ(e,t){return{from:new Date(e),to:new Date(KUt(e,t))}}const vue={input:"mastra_model_total_input_tokens",output:"mastra_model_total_output_tokens",cacheRead:"mastra_model_input_cache_read_tokens"},z_s="mastra_agent_duration_ms";function uAe(){const e=Ye(),{filters:t,filterKey:n,timestamp:r}=mf(),{interval:s,stepHours:i}=rT(r.start,r.end);return _t({queryKey:["metrics","activity",n,s],placeholderData:ox,queryFn:async()=>{const o=v=>e.getMetricTimeSeries({name:[v],interval:s,aggregation:"sum",filters:t}),[l,c,u,d]=await Promise.all([o(vue.input),o(vue.output),o(vue.cacheRead),e.getMetricTimeSeries({name:[z_s],interval:s,aggregation:"count",groupBy:["status"],filters:t})]),f=lAe(r.start,r.end,i).map(v=>({...v,input:0,cacheRead:0,output:0,cost:0,completed:0,failed:0,failureRate:0})),h=cAe(f,i),p=v=>{const y=h(v);return y===void 0?void 0:f[y]},m=(v,y)=>{for(const x of v){const b=p(x);b&&(b[y]+=x.value,y!=="cacheRead"&&(b.cost+=x.estimatedCost??0))}};for(const v of l.series)m(v.points,"input");for(const v of c.series)m(v.points,"output");for(const v of u.series)m(v.points,"cacheRead");for(const v of d.series){const y=/error|fail/i.test(v.name)?"failed":"completed";for(const x of v.points){const b=p(x);b&&(b[y]+=x.value)}}for(const v of f){v.input=Math.max(v.input-v.cacheRead,0);const y=v.completed+v.failed;v.failureRate=y>0?v.failed/y:0}return f}})}const dAe={xKey:"label",timestampKey:"ts",tooltipLabelKey:"time"},fAe={...dAe,xKey:"edgeLabel"},hu={green:"var(--chart-share-1)",sky:"var(--chart-share-2)",violet:"var(--chart-share-3)",teal:"var(--chart-share-4)",indigo:"var(--chart-share-5)",error:"var(--chart-red)",neutral:"var(--muted-foreground)"};function JJ({data:e,series:t,className:n}){return a.jsx("div",{className:Z("flex flex-wrap items-center gap-x-4 gap-y-1",n),children:t.map(r=>{const s=e?r.aggregate?.(e):void 0;return a.jsxs("div",{className:"inline-flex items-center gap-1.5",children:[r.dashed?a.jsx("span",{className:"h-0 w-3 shrink-0 border-t-2 border-dashed",style:{borderColor:r.color}}):a.jsx("div",{className:"size-2 shrink-0 rounded-[2px]",style:{backgroundColor:r.color}}),a.jsx(Y,{as:"span",variant:"body-sm",tone:"muted",className:"max-w-48 truncate",children:r.label}),s&&a.jsxs(Y,{as:"span",variant:"body-sm",tone:"muted",className:"-ml-1 tabular-nums",children:[s.value,s.suffix&&a.jsxs(Y,{as:"span",variant:"body-sm",tone:"faint",children:[" ",s.suffix]})]})]},r.dataKey)})})}function YUt({active:e,payload:t,label:n,suffix:r,formatValue:s=c=>c.toLocaleString("en-US"),showTotal:i=!1,labelKey:o,formatByKey:l}){if(!e||!t?.length)return null;const c=p=>typeof p=="number"&&Number.isFinite(p),u=t.reduce((p,m)=>p+(c(m.value)?m.value:0),0),d=o?String(t[0]?.payload?.[o]??n??""):n,f=p=>l?.[String(p.dataKey)]??s,h=p=>c(p.value)?f(p)(p.value):typeof p.value=="number"||p.value==null?"—":p.value;return a.jsxs(Gje,{children:[a.jsx(Y,{variant:"column",tone:"ink",className:"mb-1",children:d}),a.jsxs("div",{className:"grid grid-cols-[auto_1fr_auto] items-center gap-x-2 gap-y-1",children:[t.map(p=>a.jsxs("div",{className:"contents",children:[a.jsx("span",{className:"size-2 rounded-[2px]",style:{backgroundColor:p.color}}),a.jsx(Y,{as:"span",variant:"caption",tone:"muted",className:"max-w-40 truncate",children:p.name}),a.jsxs("span",{className:"text-right font-mono text-foreground tabular-nums",children:[h(p),c(p.value)&&r]})]},p.name)),i&&a.jsxs("div",{className:"col-span-3 grid grid-cols-subgrid items-center border-t border-border pt-1",children:[a.jsx(Y,{as:"span",variant:"caption",tone:"muted",className:"col-span-2",children:"Total"}),a.jsxs("span",{className:"text-right font-mono text-foreground tabular-nums",children:[s(u),r]})]})]})]})}const eee={top:8,right:0,bottom:0,left:0},hAe=22,pAe=11;function F_s(e,t){let n=t;const r=()=>(n=(n*9301+49297)%233280,n/233280);let s=.45;return Array.from({length:e},()=>(s=Math.min(.85,Math.max(.25,s+(r()-.5)*.3)),s))}function XUt({kind:e,height:t=210,className:n}){const r=`ghost${g.useId().replace(/:/g,"")}`,s=Aht(),i=F_s(e==="bar"?24:16,e==="bar"?7:11),{ghost:o,mask:l,peak:c}=e==="bar"?B_s(i):V_s(i),u=a.jsxs(a.Fragment,{children:[a.jsxs("defs",{children:[a.jsxs("linearGradient",{id:`${r}-band`,x1:"0",y1:"0",x2:"1",y2:"0",children:[a.jsx("stop",{offset:"0",stopColor:"var(--foreground)",stopOpacity:0}),a.jsx("stop",{offset:"0.5",stopColor:"var(--foreground)",stopOpacity:c}),a.jsx("stop",{offset:"1",stopColor:"var(--foreground)",stopOpacity:0})]}),a.jsx("mask",{id:`${r}-mask`,maskUnits:"userSpaceOnUse",x:"0",y:"0",width:"100",height:"100",children:l})]}),o,a.jsx("g",{mask:`url(#${r}-mask)`,children:a.jsx("rect",{width:40,height:100,fill:`url(#${r}-band)`,className:"animate-[chart-ghost-sweep_2s_infinite]",style:{animationDelay:s}})})]}),d=a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"min-h-0 flex-1",style:{paddingTop:eee.top},children:a.jsx("svg",{viewBox:"0 0 100 100",preserveAspectRatio:"none",className:"block size-full","aria-hidden":!0,children:u})}),a.jsx("div",{style:{height:hAe}})]});return t==="fill"?a.jsx("div",{role:"status","aria-label":"Loading chart",className:Z("relative min-h-45 w-full flex-1",n),children:a.jsx("div",{className:"absolute inset-0 flex flex-col",children:d})}):a.jsx("div",{role:"status","aria-label":"Loading chart",className:Z("flex w-full flex-col",n),style:{height:t},children:d})}function B_s(e){const t=100/e.length,n=e.map((r,s)=>a.jsx("rect",{x:s*t+t*.15,width:t*.7,y:100-r*100,height:r*100,rx:.4},s));return{ghost:a.jsx("g",{fill:"var(--foreground)",fillOpacity:.07,children:n}),mask:a.jsx("g",{fill:"white",children:n}),peak:.09}}function V_s(e){const t=100/(e.length-1),n=e.map((i,o)=>[o*t,100-i*100]),r=n.map(([i,o],l)=>{const c=n[l-1];if(!c)return`M${i},${o}`;const[u,d]=c,f=(u+i)/2;return`C${f},${d} ${f},${o} ${i},${o}`}).join(" "),s=`${r} L100,100 L0,100 Z`;return{ghost:a.jsxs(a.Fragment,{children:[a.jsx("path",{d:s,fill:"var(--foreground)",fillOpacity:.025}),a.jsx("path",{d:r,fill:"none",stroke:"var(--foreground)",strokeOpacity:.12,strokeWidth:1.75,vectorEffect:"non-scaling-stroke"})]}),mask:a.jsxs(a.Fragment,{children:[a.jsx("path",{d:s,fill:"white",fillOpacity:.2}),a.jsx("path",{d:r,fill:"none",stroke:"white",strokeWidth:1.75,vectorEffect:"non-scaling-stroke"})]}),peak:.18}}const JUt={vertical:!1,stroke:"var(--border)",strokeDasharray:"3 3",strokeOpacity:.5},U_s={stroke:"var(--border)",strokeDasharray:"3 3",strokeWidth:.8};function eqt(){const e=g.useRef(null),[t,n]=g.useState({width:0,height:0});return g.useLayoutEffect(()=>{const s=e.current?.getBoundingClientRect();s&&n({width:s.width,height:s.height})},[]),{size:t,onResize:(s,i)=>n(o=>o.width===s&&o.height===i?o:{width:s,height:i}),ref:e}}function q_s(e){if(!e)return 3;const t=e-hAe-eee.top;return Math.min(5,Math.max(3,Math.round(t/48)+1))}const gV=6e4,Att=1440*gV,Q_s=[5,10,15,30,60,120,180,240,360,720,1440,2880,10080],Z_s=48,tqt=e=>e.length*pAe*.58;function W_s(e,t,n,r="auto"){const s=t.length-1;if(s<0)return new Set;const i=new Set([0,s]);if(r==="edges"||t.length<3)return i;const o=Math.max(...t.map(p=>tqt(p))),l=Math.floor(n/(o+Z_s));if(l<3)return i;const c=e.every(H_s)?e:void 0,u=c?(c[1]??0)-(c[0]??0):0,d=c?((c[s]??0)-(c[0]??0)+u)/gV:0,f=c?Q_s.find(p=>p*gV>=u&&p*gV%u===0&&d/p<=l):void 0;if(!c||!(u>0)||f===void 0){const p=Math.ceil(t.length/l),m=new Set;for(let v=0;v<=s;v+=p)m.add(v);return m.has(s)||(s%p<p/2&&m.delete(s-s%p),m.add(s)),m.size<3?i:m}const h=new Set;return c.forEach((p,m)=>{const v=new Date(p),y=new Date(v.getFullYear(),v.getMonth(),v.getDate()).getTime(),x=u>=Att||v.getHours()===0&&v.getMinutes()===0;(f<1440?v.getSeconds()===0&&(v.getHours()*60+v.getMinutes())%f===0:x&&Math.round(y/Att)%(f/1440)===0)&&h.add(m)}),h.size<3?i:h}function H_s(e){return typeof e=="number"&&Number.isFinite(e)}const nqt=3,rqt=e=>e!==void 0&&Number.isFinite(e)&&e>0?e:0;function G_s(e,t,n,{gap:r=0,minSize:s=nqt}={}){const i=e.map(rqt),o=i[t]??0;if(!(o>0)||!Number.isFinite(n.y)||!Number.isFinite(n.height))return;const l=n.height/o,c=i.slice(0,t).reduce((k,j)=>k+j,0),u=n.y+n.height+c*l,d=i.flatMap((k,j)=>k>0?[j]:[]),f=i.reduce((k,j)=>k+j,0)*l,h=r*(d.length-1),p=k=>m[k]??0,m=i.map(k=>k>0&&f>0?Math.max(k*l*(f-h)/f,0):0),v=d.filter(k=>p(k)<s),y=d.filter(k=>p(k)>=s),x=v.reduce((k,j)=>k+s-p(j),0),b=y.reduce((k,j)=>k+p(j)-s,0);for(const k of v)m[k]=s;for(const k of y)m[k]=b>=x?p(k)-(b>0?(p(k)-s)/b*x:0):s;let S=u;for(const k of d){if(S-=p(k),k===t)return{y:S,height:p(k)};S-=r}}function K_s(e,t,{minSize:n=nqt}={}){if(!(!(rqt(e)>0)||!Number.isFinite(t.y)||!Number.isFinite(t.height)))return t.height>=n?t:{y:t.y+t.height-n,height:n}}function Y_s({x:e=0,y:t=0,payload:n,picked:r,count:s,plotWidth:i}){if(!n||!i||!r.has(n.index))return null;const o=String(n.value),l=n.offset??0,c=l>0?e-l*(2*n.index+1):e-n.index*i/Math.max(s-1,1),u=tqt(o)/2,d=Math.min(Math.max(e,c+u),c+i-u);return a.jsx("text",{x:d,y:t,dy:"0.71em",textAnchor:"middle",fontSize:pAe,fill:edt,children:o})}const Rye=new Intl.NumberFormat("en",{notation:"compact",maximumFractionDigits:1}),sqt={fontSize:pAe,fill:edt};function iqt({data:e,xKey:t,timestampKey:n,xLabels:r,plotWidth:s}){const i=e.map(c=>String(c[t]??"")),o=e.map(c=>{const u=c[n];return typeof u=="number"?u:void 0}),l=W_s(o,i,s,r);return a.jsx(h6,{dataKey:t,height:hAe,tick:c=>a.jsx(Y_s,{...c,picked:l,count:e.length,plotWidth:s}),tickLine:!1,axisLine:!1,tickMargin:6,interval:0})}const oqt=44;function Mye({id:e=0,show:t,size:n,formatter:r,domain:s,right:i=!1}){return a.jsx(p6,{yAxisId:e,hide:!t,orientation:i?"right":"left",tick:sqt,tickLine:!1,axisLine:!1,width:"auto",tickMargin:4,tickFormatter:r,domain:s,tickCount:q_s(n.height)})}function aqt({height:e,plotRef:t,onResize:n,clickable:r,children:s}){const i=Z("w-full [&_.recharts-surface]:overflow-visible [&_.recharts-surface]:outline-none","[&_*:focus:not(:focus-visible)]:outline-none",r&&"[&_.recharts-surface]:cursor-pointer");return e==="fill"?a.jsx("div",{className:"relative min-h-45 flex-1",children:a.jsx("div",{ref:t,className:Z("absolute inset-0",i),children:a.jsx(oA,{width:"100%",height:"100%",onResize:n,children:s})})}):a.jsx("div",{ref:t,className:i,style:{height:e},children:a.jsx(oA,{width:"100%",height:"100%",onResize:n,children:s})})}function lqt(){return`chart${g.useId().replace(/:/g,"")}`}const X_s=2,J_s=2,eTs=.75,tTs=.55,nTs=3,rTs=.3;function sTs({fill:e,color:t,capped:n,keys:r,dataKey:s}){return function({x:o=0,width:l=0,index:c,payload:u,...d}){const f=r.map(S=>Number(u?.[S])||0),h=r.indexOf(s),p={y:d.y??0,height:Math.max(d.height??0,0)},m=r.length>1?G_s(f,h,p,{gap:J_s}):K_s(f[h]??0,p);if(!m)return a.jsx("g",{});const{y:v,height:y}=m,x=Math.min(X_s,Math.floor(y/3)),b={"data-bucket":c,style:{transition:"opacity 150ms ease-out"}};return n?a.jsxs("g",{...b,children:[a.jsx(zI,{x:o,y:v,width:l,height:y,radius:x,fill:t,fillOpacity:tTs}),a.jsx(zI,{x:o,y:v,width:l,height:Math.min(nTs,y),radius:x,fill:t})]}):a.jsx("g",{...b,children:a.jsx(zI,{x:o,y:v,width:l,height:y,radius:x,fill:e})})}}function iTs({scope:e,setter:t}){const[n,r]=g.useState();return g.useLayoutEffect(()=>{t.current=r},[t]),n===void 0?null:a.jsx("style",{children:`[data-chart-scope="${e}"] [data-bucket]:not([data-bucket="${n}"]){opacity:${rTs}}`})}function cqt(e){const{data:t,series:n,overlay:r,height:s=210,showLegend:i=!0,isLoading:o=!1,className:l}=e,c=lqt(),u=Z(s==="fill"&&"flex min-h-0 flex-1 flex-col",l),d=r?[...n,{...r,dashed:!0}]:n;return a.jsxs("div",{className:u,"data-chart-scope":c,children:[i&&a.jsx(JJ,{data:o?void 0:t,series:d,className:"mb-4"}),o?a.jsx(XUt,{kind:"bar",height:s}):a.jsx(oTs,{...e,id:c})]})}function oTs({data:e,series:t,height:n=210,yDomain:r,valueFormatter:s,axisFormatter:i,referenceLine:o,variant:l="gradient",showYAxis:c=!0,showTotal:u=t.length>1,xKey:d="time",timestampKey:f="tsMs",xLabels:h="auto",tooltipLabelKey:p,onBucketClick:m,overlay:v,id:y}){const x=g.useRef(()=>{}),{size:b,onResize:S,ref:k}=eqt(),j=t.map(I=>I.dataKey).join("\0"),C=t.map(I=>I.color).join("\0"),T=g.useMemo(()=>{const I=j.split("\0"),A=C.split("\0");return I.map((P,D)=>sTs({fill:`url(#${y}-bar-${D})`,color:A[D]??"",capped:l==="capped",keys:I,dataKey:P}))},[j,C,l,y]),_=s??Rye.format,N=b.width-(c?oqt:0);return a.jsxs(a.Fragment,{children:[a.jsx(iTs,{scope:y,setter:x}),a.jsx(aqt,{height:n,plotRef:k,onResize:S,clickable:!!m,children:a.jsxs(Hje,{data:e,margin:eee,onMouseMove:I=>{const A=I?.activeTooltipIndex;x.current(A==null?void 0:Number(A))},onMouseLeave:()=>x.current(void 0),onClick:I=>{const A=I?.activeTooltipIndex,P=A==null?void 0:e[Number(A)];m&&P&&m(P,Number(A))},children:[a.jsx("defs",{children:t.map((I,A)=>a.jsxs("linearGradient",{id:`${y}-bar-${A}`,x1:"0",y1:"0",x2:"0",y2:"1",children:[a.jsx("stop",{offset:"0%",stopColor:I.color,stopOpacity:1}),a.jsx("stop",{offset:"100%",stopColor:I.color,stopOpacity:eTs})]},I.dataKey))}),a.jsx(Rje,{...JUt}),iqt({data:e,xKey:d,timestampKey:f,xLabels:h,plotWidth:N}),Mye({show:c,size:b,formatter:i??_,domain:r}),v&&Mye({id:"overlay",show:!1,size:b,formatter:v.valueFormatter??Rye.format,right:!0}),a.jsx(l6,{cursor:!1,content:a.jsx(YUt,{formatValue:_,showTotal:u&&!v,labelKey:p,formatByKey:v?.valueFormatter?{[v.dataKey]:v.valueFormatter}:void 0})}),t.map((I,A)=>a.jsx(mIt,{dataKey:I.dataKey,name:I.label,stackId:"1",fill:I.color,maxBarSize:28,isAnimationActive:!1,shape:T[A]},I.dataKey)),v&&a.jsx(Fje,{yAxisId:"overlay",type:"monotone",dataKey:v.dataKey,name:v.label,stroke:v.color,strokeWidth:1.75,strokeDasharray:"4 3",dot:!1,activeDot:{r:3.5,fill:v.color,stroke:"var(--background)",strokeWidth:2},isAnimationActive:!1,connectNulls:!0}),o&&a.jsx(gY,{y:o.value,ifOverflow:"extendDomain",stroke:o.color,strokeDasharray:"4 4",label:{value:o.label,position:"insideTopLeft",...sqt}})]})})]})}const aTs=[{dataKey:"input",label:"Input",color:hu.green},{dataKey:"cacheRead",label:"Cache read",color:hu.violet},{dataKey:"output",label:"Output",color:hu.sky}],lTs=[{dataKey:"cost",label:"Cost",color:hu.green}],cTs=e=>`$${e.toFixed(e<10?1:0)}`;function uTs({onViewTraces:e,onTimeRangeClick:t}){const[n,r]=g.useState("tokens"),{data:s=[],isLoading:i,isError:o,isPlaceholderData:l}=uAe(),{timestamp:c}=mf(),{stepHours:u}=rT(c.start,c.end),d=s.reduce((v,y)=>v+y.input+y.cacheRead+y.output,0),f=s.reduce((v,y)=>v+y.cost,0),h=n==="tokens",p=h?aTs:lTs,m={title:"Token usage",description:h?"Input, cache reads and output.":"Estimated model spend.",actions:e&&a.jsx(HJ,{onClick:e}),toolbar:a.jsxs(gi.Toolbar,{children:[a.jsx(JJ,{series:p}),a.jsxs(gi.Tabs,{value:n,onValueChange:r,children:[a.jsx(gi.Tab,{value:"tokens",children:"Tokens"}),a.jsx(gi.Tab,{value:"cost",children:"Cost"})]})]})};return o?a.jsx(oh,{...m,children:a.jsx(nT,{})}):a.jsx(oh,{...m,summary:a.jsx(gi.Summary,{value:h?av(d):Qj(f),label:h?"tokens":"cost",isLoading:i}),isUpdating:l,children:a.jsx(tT,{isEmpty:!i&&d===0&&f===0,emptyMessage:"No model calls in this range.",children:a.jsx(cqt,{data:s,series:p,height:"fill",showLegend:!1,valueFormatter:h?av:Qj,axisFormatter:h?C_s:cTs,onBucketClick:t&&(v=>t(XJ(Number(v.ts),u))),isLoading:i,...dAe})})})}const dTs=[{dataKey:"completed",label:"Completed",color:hu.green},{dataKey:"failed",label:"Failed",color:hu.error}];function fTs({onTimeRangeClick:e}){const{data:t=[],isLoading:n,isError:r,isPlaceholderData:s}=uAe(),{timestamp:i}=mf(),{stepHours:o}=rT(i.start,i.end),l=t.reduce((u,d)=>u+d.completed+d.failed,0),c={title:"Agent runs",description:"Completed and failed runs."};return r?a.jsx(oh,{...c,children:a.jsx(nT,{})}):a.jsx(oh,{...c,summary:a.jsx(gi.Summary,{value:av(l),label:"runs",isLoading:n}),isUpdating:s,children:a.jsx(tT,{isEmpty:!n&&l===0,emptyMessage:"No agent runs in this range.",children:a.jsx(cqt,{data:t,series:dTs,height:"fill",xLabels:"edges",valueFormatter:av,onBucketClick:e&&(u=>e(XJ(Number(u.ts),o))),isLoading:n,...fAe})})})}const Ptt=1.75,hTs=.12,pTs=12;function mTs({points:e}){const[t,n]=e??[];return!t||!n?null:a.jsx("line",{x1:0,x2:0,y1:t.y,y2:n.y,...U_s,className:"pointer-events-none transition-transform duration-150 ease-out",style:{transform:`translateX(${t.x}px)`}})}function mAe(e){const{data:t,series:n,height:r=210,showLegend:s=!0,isLoading:i=!1,className:o}=e,l=Z(r==="fill"&&"flex min-h-0 flex-1 flex-col",o);return a.jsxs("div",{className:l,children:[s&&a.jsx(JJ,{data:i?void 0:t,series:n,className:"mb-4"}),i?a.jsx(XUt,{kind:"line",height:r}):a.jsx(gTs,{...e})]})}function gTs({data:e,series:t,height:n=210,yDomain:r,onPointClick:s,onBucketClick:i,xKey:o="time",timestampKey:l="tsMs",xLabels:c="auto",tooltipLabelKey:u,showDots:d=!1,valueFormatter:f,axisFormatter:h,showYAxis:p=!0}){const m=lqt(),{size:v,onResize:y,ref:x}=eqt(),b=f??Rye.format,S=C=>e.filter(T=>typeof T[C]=="number").length<=pTs,k=v.width-(p?oqt:0),j=C=>({r:3.5,fill:C.color,stroke:"var(--background)",strokeWidth:2,...s&&{style:{cursor:"pointer"},onClick:(T,_)=>{$tt(_)&&$tt(_.payload)&&s(_.payload,C.dataKey)}}});return a.jsx(aqt,{height:n,plotRef:x,onResize:y,clickable:!!i,children:a.jsxs(Hje,{data:e,margin:eee,onClick:C=>{const T=C?.activeTooltipIndex,_=T==null?void 0:e[Number(T)];i&&_&&i(_,Number(T))},children:[a.jsx("defs",{children:t.map((C,T)=>a.jsxs("linearGradient",{id:`${m}-area-${T}`,x1:"0",y1:"0",x2:"0",y2:"1",children:[a.jsx("stop",{offset:"0%",stopColor:C.color,stopOpacity:hTs}),a.jsx("stop",{offset:"95%",stopColor:C.color,stopOpacity:0})]},C.dataKey))}),a.jsx(Rje,{...JUt}),iqt({data:e,xKey:o,timestampKey:l,xLabels:c,plotWidth:k}),Mye({show:p,size:v,formatter:h??b,domain:r}),a.jsx(l6,{content:a.jsx(YUt,{formatValue:b,labelKey:u}),cursor:a.jsx(mTs,{})}),t.map((C,T)=>{const _={type:"monotone",dataKey:C.dataKey,name:C.label,stroke:C.color,strokeWidth:C.emphasis?Ptt+.5:Ptt,strokeDasharray:C.dashed?"4 3":void 0,dot:d||S(C.dataKey)?{r:3,fill:C.color,strokeWidth:0}:!1,activeDot:j(C),isAnimationActive:!1,connectNulls:!0};return C.dashed?a.jsx(Fje,{..._},C.dataKey):a.jsx(yY,{..._,fill:`url(#${m}-area-${T})`,fillOpacity:1},C.dataKey)})]})})}function $tt(e){return typeof e=="object"&&e!==null}const vTs=[{dataKey:"failureRate",label:"Failed runs",color:hu.error}],yTs=e=>`${Math.round(e*100)}%`;function xTs({onViewErrors:e,onTimeRangeClick:t}){const{data:n=[],isLoading:r,isError:s,isPlaceholderData:i}=uAe(),{timestamp:o}=mf(),{stepHours:l}=rT(o.start,o.end),c=n.reduce((h,p)=>h+p.completed+p.failed,0),u=n.reduce((h,p)=>h+p.failed,0),d=u===0?[0,1]:void 0,f={title:"Failure rate",description:"Share of agent runs that failed.",actions:e&&a.jsx(qUt,{onClick:e})};return s?a.jsx(oh,{...f,children:a.jsx(nT,{})}):a.jsx(oh,{...f,summary:a.jsx(gi.Summary,{value:$ye(c>0?u/c:0),label:"failed",isLoading:r}),isUpdating:i,children:a.jsx(tT,{isEmpty:!r&&c===0,emptyMessage:"No agent runs in this range.",children:a.jsx(mAe,{data:n,series:vTs,height:"fill",xLabels:"edges",valueFormatter:$ye,axisFormatter:yTs,yDomain:d,onBucketClick:t&&(h=>t(XJ(Number(h.ts),l))),isLoading:r,...fAe})})})}const bTs={agents:"mastra_agent_duration_ms",workflows:"mastra_workflow_duration_ms",tools:"mastra_tool_duration_ms"},Rtt=["agents","workflows","tools"];function wTs(){const e=Ye(),{filters:t,filterKey:n,timestamp:r}=mf(),{interval:s}=rT(r.start,r.end),i=oAe(s);return _t({queryKey:["metrics","latency-percentiles",n,s],placeholderData:ox,queryFn:async()=>{const o=await Promise.all(Rtt.map(u=>e.getMetricPercentiles({name:bTs[u],percentiles:[.5,.95],interval:s,filters:t}))),l=lAe(r.start,r.end,i),c=cAe(l,i);return o.forEach((u,d)=>{const f=Rtt[d];if(f)for(const h of u.series){const p=STs(f,h.percentile);if(p)for(const m of h.points){const v=l[c(m)??-1];v&&(v[p]=Math.round(m.value))}}}),l}})}function STs(e,t){if(t===.5)return`${e}P50`;if(t===.95)return`${e}P95`}const kTs={agents:sd.AGENT,workflows:sd.WORKFLOW_RUN,tools:sd.TOOL};function OTs(e){return[{dataKey:`${e}P50`,label:"P50",color:hu.sky},{dataKey:`${e}P95`,label:"P95",color:hu.green,emphasis:!0}]}const jTs={agents:"agent runs",workflows:"workflow runs",tools:"tool calls"};function CTs({onViewTraces:e,onTimeRangeClick:t}){const[n,r]=g.useState("agents"),{data:s=[],isLoading:i,isError:o,isPlaceholderData:l}=wTs(),{timestamp:c}=mf(),u=oAe(rT(c.start,c.end).interval),d=OTs(n),f=Math.max(0,...s.map(p=>p[`${n}P95`]??0)),h={title:"Latency",description:"Duration percentiles.",actions:e&&a.jsx(HJ,{onClick:()=>e(kTs[n])}),toolbar:a.jsxs(gi.Toolbar,{children:[a.jsx(JJ,{series:d}),a.jsxs(gi.Tabs,{value:n,onValueChange:r,children:[a.jsx(gi.Tab,{value:"agents",children:"Agents"}),a.jsx(gi.Tab,{value:"workflows",children:"Workflows"}),a.jsx(gi.Tab,{value:"tools",children:"Tools"})]})]})};return o?a.jsx(oh,{...h,children:a.jsx(nT,{})}):a.jsx(oh,{...h,summary:a.jsx(gi.Summary,{value:f>0?Itt(f):"—",label:"peak P95",isLoading:i}),isUpdating:l,children:a.jsx(tT,{isEmpty:!i&&f===0,emptyMessage:`No ${jTs[n]} in this range.`,children:a.jsx(mAe,{data:s,series:d,height:"fill",xLabels:"edges",showLegend:!1,valueFormatter:Itt,axisFormatter:__s,onBucketClick:t&&(p=>t(XJ(Number(p.ts),u))),isLoading:i,...fAe})})})}function uqt({columns:e=[],valueLabel:t,valueWidth:n="w-14",className:r}){return a.jsxs("div",{"aria-hidden":!0,className:Z("flex shrink-0 items-center gap-3 text-column text-placeholder",r),children:[e.map(s=>a.jsx("span",{className:Z("shrink-0 text-right",s.width??"w-16"),children:s.label},s.label)),a.jsx("span",{className:"w-12 shrink-0 text-right",children:"Share"}),a.jsx("span",{className:Z("shrink-0 text-right",n),children:t})]})}const dqt="-mx-2 flex w-[calc(100%+1rem)] items-center gap-3 rounded-md px-2 py-1 text-left",JI="shrink-0 text-right text-body-sm tabular-nums";function _Ts({row:e,columns:t,valueWidth:n,share:r,highlighted:s,dimmed:i,onHover:o,LinkComponent:l}){const c=Z(dqt,"transition-[background-color,opacity] duration-150",s&&"bg-fill-subtle",(e.href||e.onClick)&&"hover:bg-fill-subtle");return a.jsx("li",{children:a.jsxs(TTs,{row:e,LinkComponent:l,className:c,style:{opacity:i?.5:1},onMouseEnter:o,children:[a.jsx("span",{className:"size-2 shrink-0 rounded-[2px]",style:{backgroundColor:e.paint.color,opacity:e.paint.alpha}}),a.jsx(ETs,{row:e}),t.map((u,d)=>a.jsx("span",{className:Z(JI,"text-muted-foreground",u.width??"w-16"),children:e.cells?.[d]},u.label)),a.jsx("span",{className:Z(JI,"w-12 text-muted-foreground"),children:r}),a.jsx("span",{className:Z(JI,"text-foreground",n),children:e.value})]})})}function TTs({row:e,LinkComponent:t,...n}){if(e.href){const r=t??"a";return a.jsx(r,{href:e.href,...n})}return e.onClick?a.jsx("button",{type:"button",onClick:e.onClick,...n}):a.jsx("div",{...n})}function ETs({row:e}){return typeof e.label!="string"?a.jsx("span",{className:"flex min-w-0 flex-1",title:e.title,children:e.label}):a.jsx("span",{className:"min-w-0 flex-1 truncate",title:e.title??e.label,children:a.jsx(Y,{as:"span",variant:"body-sm",tone:"ink",children:e.label})})}const ITs="var(--chart-share-1)",Mtt=[1,2,3,4,5].map(e=>`var(--chart-share-${e})`),NTs=[3,4,2,5,1].map(e=>`var(--chart-share-${e})`),ATs=[1,.7,.48,.32,.2,.14],tee={color:"var(--chart-share-rest)",alpha:1},PTs=50,XC="__rest";function fqt(e,t,n){if(n==="hues"){const r=Mtt.includes(e)?[e,...Mtt.filter(s=>s!==e)]:[e,...NTs];return Array.from({length:t},(s,i)=>({color:r[i%r.length]??e,alpha:[1,.55,.3][Math.floor(i/r.length)]??.2}))}return Array.from({length:t},(r,s)=>({color:e,alpha:ATs[s]??.1}))}const gAe=e=>e.reduce((t,n)=>t+Math.max(n.share,0),0);function $Ts(e){return e.map(t=>Number.isFinite(t.share)&&t.share>0?t:{...t,share:0}).toSorted((t,n)=>n.share-t.share)}function RTs(e,{limit:t,other:n,color:r,palette:s}){if(e.length<=t+1)return{shown:Dtt(e,r,s),rest:[]};const i=e.slice(t),o=n?.(i),l={key:XC,label:`Other (${i.length})`,share:gAe(i),value:o?.value,cells:o?.cells,paint:tee,segment:XC};return{shown:[...Dtt(e.slice(0,t),r,s),l],rest:i}}function Dtt(e,t,n){const r=fqt(t,e.length,n);return e.map((s,i)=>({...s,paint:r[i]??tee,segment:s.key}))}function MTs(e,{count:t,activeKey:n,color:r,palette:s}){const i=Math.min(t,e.length,PTs),o=fqt(r,i,s),l=new Map(e.map((u,d)=>[u.key,d]));return{shown:DTs(e,t,n).map(u=>{const d=l.get(u.key)??e.length;return{...u,paint:o[d]??tee,segment:d<i?u.key:XC}}),rest:e.slice(i)}}function DTs(e,t,n){const r=e.slice(0,t),s=n?e.findIndex(o=>o.key===n):-1,i=s>=t?e[s]:void 0;return i?[...r,i]:r}function LTs(e,t){const n=e.filter(o=>o.segment!==XC).map(o=>({key:o.key,share:o.share,paint:o.paint})),r=t.length?[{key:XC,share:gAe(t),paint:tee}]:[],s=[...n,...r].filter(o=>o.share>0),i=s.reduce((o,l)=>o+l.share,0);return s.map(o=>({key:o.key,paint:o.paint,grow:o.share/i*100}))}function zTs(e,t){if(t!==void 0)return e.find(n=>n.key===t)?.segment??t}const FTs=(e,t)=>t!==void 0&&t!==e;function BTs(e,t){return t===void 0||t===e.key?!1:!(t===XC&&e.segment===XC)}const VTs=(e,t)=>{const n=e/(t||1);return n>0?n<.001?"<0.1%":`${(n*100).toFixed(n<.1?1:0)}%`:"0%"};function UTs({shown:e,total:t,limit:n,pageSize:r,onMore:s,onLess:i}){if(t<=n)return null;const o=t-e,l="flex items-center gap-1.5 rounded-md px-2 py-1 text-body-sm font-medium text-muted-foreground transition-colors duration-150 hover:bg-fill-subtle hover:text-foreground",c=new Intl.NumberFormat("en",{notation:"compact",maximumFractionDigits:1});return a.jsxs("li",{className:"-mx-2 flex items-center gap-1",children:[o>0&&a.jsxs("button",{type:"button",onClick:s,className:l,children:[a.jsx(zc,{className:"size-3.5 shrink-0"}),"Show ",Math.min(o,r)," more"]}),e>n&&a.jsxs("button",{type:"button",onClick:i,className:l,children:[a.jsx(PH,{className:"size-3.5 shrink-0"}),"Show top ",n]}),o>0&&a.jsxs("span",{className:"ml-auto pr-2 text-body-sm text-placeholder tabular-nums",children:[c.format(e)," of ",c.format(t)]})]})}const Ltt=["w-32","w-24","w-36","w-20","w-28"];function D7({className:e}){return a.jsxs(a.Fragment,{children:["",a.jsx(xt,{className:Z("absolute top-1/2 h-3.5 -translate-y-1/2",e)})]})}function qTs({rows:e,columns:t,valueWidth:n}){return a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"flex h-2",children:a.jsx(xt,{className:"size-full rounded-full"})}),a.jsx("ul",{className:"grid min-w-0 grid-cols-1 gap-0.5","aria-busy":!0,children:Array.from({length:e},(r,s)=>a.jsxs("li",{className:dqt,children:[a.jsx(xt,{className:"size-2 shrink-0 rounded-[2px]"}),a.jsx("span",{className:"min-w-0 flex-1",children:a.jsx(Y,{as:"span",variant:"body-sm",className:"relative",children:a.jsx(D7,{className:Z("left-0",Ltt[s%Ltt.length])})})}),t.map(i=>a.jsx("span",{className:Z(JI,"relative",i.width??"w-16"),children:a.jsx(D7,{className:"right-0 w-10"})},i.label)),a.jsx("span",{className:Z(JI,"relative w-12"),children:a.jsx(D7,{className:"right-0 w-9"})}),a.jsx("span",{className:Z(JI,"relative",n),children:a.jsx(D7,{className:"right-0 w-12"})})]},s))})]})}function h3({showHeader:e=!0,className:t,...n}){const{columns:r=[],valueLabel:s,valueWidth:i="w-14"}=n;return a.jsxs("div",{className:Z("grid grid-cols-1 gap-4",t),children:[e&&a.jsx("div",{className:"flex justify-end",children:a.jsx(uqt,{columns:r,valueLabel:s,valueWidth:i})}),a.jsx(QTs,{...n})]})}function QTs({rows:e,columns:t=[],valueLabel:n,valueWidth:r="w-14",palette:s="shades",color:i=ITs,limit:o=5,overflow:l="other",pageSize:c=50,other:u,activeKey:d,emptyState:f="No data in this range.",isLoading:h=!1,LinkComponent:p}){const[m,v]=g.useState(),[y,x]=g.useState(0),b=o+y*c;if(h)return a.jsx(qTs,{rows:l==="other"?o+1:o,columns:t,valueWidth:r});const S=$Ts(e);if(S.length===0)return a.jsx(Y,{variant:"body-sm",tone:"muted",className:"py-6 text-center",children:f});const k=gAe(S),j=l==="more",{shown:C,rest:T}=j?MTs(S,{count:b,activeKey:d,color:i,palette:s}):RTs(S,{limit:o,other:u,color:i,palette:s}),_=LTs(C,T),N=zTs(C,m),I=()=>v(void 0);return a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"flex h-2 gap-0.5",onMouseLeave:I,children:_.map(A=>a.jsx("span",{"data-testid":"metrics-share-segment",onMouseEnter:()=>v(A.key),className:"h-full min-w-[3px] transition-opacity duration-150 first:rounded-l-full last:rounded-r-full",style:{flex:`${A.grow} 1 0`,backgroundColor:A.paint.color,opacity:A.paint.alpha*(FTs(A.key,N)?.3:1)}},A.key))}),a.jsxs("ul",{className:"grid min-w-0 grid-cols-1 gap-0.5",onMouseLeave:I,children:[C.map(A=>a.jsx(_Ts,{row:A,columns:t,valueWidth:r,share:VTs(A.share,k),highlighted:m===A.key||d===A.key,dimmed:BTs(A,m),onHover:()=>v(A.key),LinkComponent:p},A.key)),j&&a.jsx(UTs,{shown:Math.min(b,S.length),total:S.length,limit:o,pageSize:c,onMore:()=>x(A=>A+1),onLess:()=>x(0)})]})]})}h3.Header=uqt;const ZTs={agents:sd.AGENT,workflows:sd.WORKFLOW_RUN,tools:sd.TOOL},ztt=[{label:"Error rate"}],Ftt=(e,t)=>$ye(t>0?e/t:0);function WTs({onViewTraces:e,onViewErrors:t,onEntityClick:n}){const[r,s]=g.useState("agents"),i=ZTs[r],o=j_s({...mf(),queryOptions:{placeholderData:ox}}),l={agents:o.data?.agentData??[],workflows:o.data?.workflowData??[],tools:o.data?.toolData??[]},c=l[r],u=c.map(p=>({key:p.name,label:p.name,share:p.completed+p.errors,value:av(p.completed+p.errors),cells:[Ftt(p.errors,p.completed+p.errors)],onClick:n&&(()=>n(i,p.name))})),d=new Map(c.map(p=>[p.name,p.errors])),f=[...l.agents,...l.workflows,...l.tools].reduce((p,m)=>p+m.completed+m.errors,0),h={title:"Trace volume",description:"Runs and calls, with error rate.",actions:(e||t)&&a.jsxs(a.Fragment,{children:[e&&a.jsx(HJ,{onClick:()=>e(i)}),t&&a.jsx(qUt,{onClick:()=>t(i)})]}),toolbar:a.jsxs(gi.Toolbar,{children:[a.jsxs(gi.Tabs,{value:r,onValueChange:s,children:[a.jsx(gi.Tab,{value:"agents",children:"Agents"}),a.jsx(gi.Tab,{value:"workflows",children:"Workflows"}),a.jsx(gi.Tab,{value:"tools",children:"Tools"})]}),a.jsx(h3.Header,{columns:ztt,valueLabel:"Runs"})]})};return o.isError?a.jsx(oh,{...h,children:a.jsx(nT,{})}):a.jsx(oh,{...h,summary:a.jsx(gi.Summary,{value:av(f),label:"runs and calls",isLoading:o.isLoading}),isUpdating:o.isPlaceholderData,children:a.jsx(tT,{children:a.jsx(h3,{rows:u,columns:ztt,valueLabel:"Runs",showHeader:!1,color:hu.sky,other:p=>{const m=p.reduce((y,x)=>y+(d.get(x.key)??0),0),v=p.reduce((y,x)=>y+x.share,0);return{value:av(v),cells:[Ftt(m,v)]}},emptyState:"No runs in this range.",isLoading:o.isLoading},r)})})}const HTs=["mastra_model_total_input_tokens","mastra_model_total_output_tokens"],GTs=100;function hqt(e){const t=Ye(),{filters:n,filterKey:r}=mf();return _t({queryKey:["metrics","token-spend",e,r],placeholderData:ox,queryFn:async()=>{const{groups:s}=await t.getMetricBreakdown({name:HTs,groupBy:[e],aggregation:"sum",orderDirection:"DESC",limit:GTs,filters:n});return s.map(i=>({key:String(i.dimensions[e]??"unknown"),tokens:i.value,cost:i.estimatedCost??0}))}})}const KTs={placeholderData:ox},Btt=[{label:"Tokens"}];function YTs(e){const[t,n]=g.useState("agents");return t==="models"?a.jsx(JTs,{...e,onViewChange:n}):t==="threads"?a.jsx(eEs,{...e,onViewChange:n}):a.jsx(XTs,{...e,onViewChange:n})}function XTs(e){const{onAgentClick:t}=e,{data:n=[],isLoading:r,isPlaceholderData:s,isError:i}=k_s({...mf(),queryOptions:KTs}),o=n.map(l=>({key:l.name,cost:l.cost??0,tokens:l.total,onClick:t&&(()=>t(l.name))}));return a.jsx(vAe,{view:"agents",...e,rows:o,isLoading:r,isUpdating:s,isError:i})}function JTs(e){const{onModelClick:t}=e,{data:n=[],isLoading:r,isPlaceholderData:s,isError:i}=hqt("model"),o=n.map(l=>({...l,onClick:t&&(()=>t(l.key))}));return a.jsx(vAe,{view:"models",...e,rows:o,isLoading:r,isUpdating:s,isError:i})}function eEs(e){const{onThreadClick:t}=e,{data:n=[],isLoading:r,isPlaceholderData:s,isError:i}=hqt("threadId"),o=n.map(l=>({...l,onClick:t&&(()=>t(l.key))}));return a.jsx(vAe,{view:"threads",...e,rows:o,isLoading:r,isUpdating:s,isError:i})}function vAe({view:e,onViewChange:t,onViewTraces:n,rows:r,isLoading:s,isUpdating:i,isError:o}){const l=new Map(r.map(d=>[d.key,d.tokens])),c=r.map(d=>({key:d.key,label:d.key,share:d.cost,value:Qj(d.cost),cells:[av(d.tokens)],onClick:d.onClick})),u={title:"Usage",description:"Who is spending: cost share, with tokens.",actions:n&&a.jsx(HJ,{onClick:n}),toolbar:a.jsxs(gi.Toolbar,{children:[a.jsxs(gi.Tabs,{value:e,onValueChange:t,children:[a.jsx(gi.Tab,{value:"agents",children:"Agents"}),a.jsx(gi.Tab,{value:"models",children:"Models"}),a.jsx(gi.Tab,{value:"threads",children:"Threads"})]}),a.jsx(h3.Header,{columns:Btt,valueLabel:"Cost"})]})};return o?a.jsx(oh,{...u,children:a.jsx(nT,{})}):a.jsx(oh,{...u,summary:a.jsx(gi.Summary,{value:Qj(r.reduce((d,f)=>d+f.cost,0)),label:"cost",isLoading:s}),isUpdating:i,children:a.jsx(tT,{children:a.jsx(h3,{rows:c,columns:Btt,valueLabel:"Cost",showHeader:!1,color:hu.green,other:d=>({value:Qj(d.reduce((f,h)=>f+h.share,0)),cells:[av(d.reduce((f,h)=>f+(l.get(h.key)??0),0))]}),emptyState:"No model usage in this range.",isLoading:s})})})}const tEs=100;function nEs(){const e=Ye(),{filters:t,filterKey:n,timestamp:r}=mf(),{interval:s}=rT(r.start,r.end),i=oAe(s);return _t({queryKey:["metrics","scores",n,s],placeholderData:ox,queryFn:async()=>{const o=await e.listScores({filters:t,pagination:{page:0,perPage:tEs}}),l=new Map(o.scores.map(p=>[p.scorerId,p.scorerName??p.scorerId])),c=[...l.keys()].toSorted(),u=await Promise.all(c.map(p=>Promise.all([e.getScoreAggregate({scorerId:p,aggregation:"avg",filters:t}),e.getScoreTimeSeries({scorerId:p,aggregation:"avg",interval:s,filters:t})]))),d=lAe(r.start,r.end,i),f=cAe(d,i),h=[];return u.forEach(([p,m],v)=>{const y=c[v];if(y){h.push({scorerId:y,name:l.get(y)??y,average:p.value??0});for(const x of m.series)for(const b of x.points){const S=d[f(b)??-1];S&&(S[y]=b.value)}}}),{scorers:h,buckets:d}}})}const Vtt=[hu.green,hu.sky,hu.violet,hu.teal,hu.indigo],pqt=e=>e.toFixed(2),rEs=e=>e.toFixed(1);function sEs(e){return e.map(({scorerId:t,name:n,average:r},s)=>({dataKey:t,label:n,color:Vtt[s%Vtt.length]??hu.neutral,aggregate:()=>({value:pqt(r)})}))}function iEs(){const{data:e,isLoading:t,isError:n,isPlaceholderData:r}=nEs(),s=e?.scorers??[],i={title:"Scores",description:"Average scorer result, 0 to 1."};return n?a.jsx(oh,{...i,children:a.jsx(nT,{})}):a.jsx(oh,{...i,summary:a.jsx(gi.Summary,{value:String(s.length),label:s.length===1?"scorer":"scorers",isLoading:t}),isUpdating:r,children:a.jsx(tT,{isEmpty:!t&&s.length===0,emptyMessage:"No scores in this range.",children:a.jsx(mAe,{data:e?.buckets??[],series:sEs(s),height:"fill",yDomain:[0,1],valueFormatter:pqt,axisFormatter:rEs,isLoading:t,...dAe})})})}const AD=[_s("/metrics")];function oEs({onClear:e,onRemoveAll:t,onSave:n,onRemoveSaved:r,isLoading:s,filterFields:i,filterTokens:o,onFilterTokensChange:l,autoFocusFilterFieldId:c}){const u=o.length>0,d=o.some(f=>aEs(f,i));return u?a.jsxs("div",{className:Z("grid grid-cols-[1fr_auto] items-start gap-3"),children:[a.jsx(CUt,{fields:i,tokens:o,onTokensChange:l,disabled:s,autoFocusFieldId:c}),u&&a.jsx(OUt,{disabled:s,onClear:d?e:void 0,onRemoveAll:t,onSave:n,onRemoveSaved:r})]}):null}function aEs(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 Dye({children:e,filterFields:t,isLoading:n=!1}){const[r]=oi(),{filterTokens:s,setFilterTokens:i}=Fk(),[o,l]=g.useState(),[c,u]=g.useState(()=>!!FUt()),d=()=>{LCs(r),u(!0),Ke.success("Filters setting for Metrics saved")},f=()=>{zCs(),u(!1),Ke.success("Filters setting for Metrics cleared up")},h=()=>{const p=s.map(m=>{const v=t.find(y=>y.id===m.fieldId);return v?v.kind==="text"?{fieldId:m.fieldId,value:""}:v.kind==="pick-multi"?v.multi?{fieldId:m.fieldId,value:[]}:{fieldId:m.fieldId,value:"Any"}:v.kind==="multi-select"?{fieldId:m.fieldId,value:[]}:m:m});i(p)};return a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:AD}),actionRow:a.jsxs(a.Fragment,{children:[a.jsx(Xn,{children:a.jsxs(Xn.Start,{children:[a.jsx(t_s,{}),a.jsx(TUt,{fields:t,tokens:s,onTokensChange:i,disabled:n,onStartTextFilter:l})]})}),a.jsx(oEs,{isLoading:n,filterFields:t,filterTokens:s,onFilterTokensChange:i,onClear:h,onRemoveAll:()=>i([]),onSave:d,onRemoveSaved:c?f:void 0,autoFocusFilterFieldId:o})]}),children:[a.jsx("h1",{className:"sr-only",children:"Metrics"}),e]})}function lEs({error:e}){return js(e)?a.jsx(ai,{}):Cs(e)?a.jsx(Gs,{resource:"metrics"}):a.jsx(Xt,{tone:"error",titleSlot:"Failed to load storage capabilities",descriptionSlot:e.message})}const Utt=BUt({availableTags:[],availableEntityNames:[],availableServiceNames:[],availableEnvironments:[]});function cEs({children:e}){const{supportsMetrics:t,isLoading:n,error:r}=wz();return n?a.jsx(Dye,{filterFields:Utt,isLoading:!0,children:a.jsxs("div",{className:"flex h-full items-center justify-center gap-2",children:[a.jsx(En,{"aria-label":"Loading storage capabilities"}),a.jsx(Y,{as:"span",variant:"caption",tone:"muted",children:"Loading storage capabilities"})]})}):r?a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:AD}),children:[a.jsx("h1",{className:"sr-only",children:"Metrics"}),a.jsx("div",{className:"flex h-full items-center justify-center",children:a.jsx(lEs,{error:r})})]}):t?e:a.jsx(Dye,{filterFields:Utt,children:a.jsx(Xt,{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:a.jsx(de,{variant:"ghost",render:a.jsx("a",{href:"https://mastra.ai/docs/observability/metrics/overview",target:"_blank",rel:"noopener noreferrer"}),icon:a.jsx(Zs,{}),children:"Metrics Documentation"}),variant:"fill"})})}function uEs(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 mqt(e,t,n,r,s,i,o){if(o){e.set(t,"custom"),e.set(n,o.from.toISOString()),e.set(r,o.to.toISOString());return}if(s==="custom"){e.set(t,"custom"),i?.from&&e.set(n,i.from.toISOString()),i?.to&&e.set(r,i.to.toISOString());return}const l=uEs(s);l&&e.set(t,l)}function rl(e,t,n){typeof n=="string"&&n.length>0&&e.set(t,n)}function gqt(e,t,n){if(!(!Array.isArray(n)||n.length===0))for(const r of n)r&&e.append(t,r)}function dEs({preset:e,customRange:t,dashboardFilter:n,scope:r,tracesBasePath:s="/traces"}){const i=new URLSearchParams;i.set(T1,"branches"),mqt(i,E1,l1,c1,e,t,r.window);const o=r.rootEntityType??n.rootEntityType;o&&i.set(XS,o),r.status&&i.set(JS,r.status),rl(i,yl.entityName,r.entityName??n.entityName),rl(i,yl.threadId,r.threadId??n.threadId),rl(i,yl.resourceId,r.resourceId??n.resourceId),rl(i,yl.runId,n.runId),rl(i,yl.sessionId,n.sessionId),rl(i,yl.requestId,n.requestId),rl(i,yl.userId,n.userId),rl(i,yl.organizationId,n.organizationId),rl(i,yl.experimentId,n.experimentId),rl(i,yl.serviceName,n.serviceName),rl(i,yl.environment,n.environment),gqt(i,yl.tags,n.tags);const l=i.toString();return l?`${s}?${l}`:s}function fEs({preset:e,customRange:t,dashboardFilter:n,scope:r,logsBasePath:s="/logs"}){const i=new URLSearchParams;mqt(i,Lb,zb,Fb,e,t,r.window);const o=r.rootEntityType??n.rootEntityType;o&&i.set(A0,o),rl(i,Dl.entityName,r.entityName??n.entityName),rl(i,Dl.threadId,r.threadId??n.threadId),rl(i,Dl.resourceId,r.resourceId??n.resourceId),rl(i,Dl.runId,n.runId),rl(i,Dl.sessionId,n.sessionId),rl(i,Dl.requestId,n.requestId),rl(i,Dl.userId,n.userId),rl(i,Dl.organizationId,n.organizationId),rl(i,Dl.experimentId,n.experimentId),rl(i,Dl.serviceName,n.serviceName),rl(i,Dl.environment,n.environment),gqt(i,Dl.tags,n.tags),r.status==="error"&&i.append(Dl.level,"error");const l=i.toString();return l?`${s}?${l}`:s}function hEs(){const{datePreset:e,customRange:t,dimensionalFilter:n}=Fk(),r=Dr(),s={preset:e,customRange:t,dashboardFilter:n};return{openTraces:(l={})=>{r(dEs({...s,scope:l}))},openLogs:(l={})=>{r(fEs({...s,scope:l}))}}}const yue="period",L7="dateFrom",z7="dateTo";function pEs(){const[e,t]=oi(),n=e.get(yue),r=HCs(n)?n:"24h",s=g.useMemo(()=>{if(r!=="custom")return;const d=p=>{if(!p)return;const m=new Date(p);return Number.isNaN(m.getTime())?void 0:m},f=d(e.get(L7)),h=d(e.get(z7));if(!(!f&&!h))return{from:f,to:h}},[r,e.toString()]),i=g.useMemo(()=>BCs(e),[e.toString()]),o=g.useCallback(d=>{t(f=>{const h=new URLSearchParams(f);return d==="24h"?h.delete(yue):h.set(yue,d),d!=="custom"&&(h.delete(L7),h.delete(z7)),h},{replace:!0})},[t]),l=g.useCallback(d=>{t(f=>{const h=new URLSearchParams(f);return d?.from?h.set(L7,d.from.toISOString()):h.delete(L7),d?.to?h.set(z7,d.to.toISOString()):h.delete(z7),h},{replace:!0})},[t]),c=g.useCallback(d=>{t(f=>{const h=new URLSearchParams(f);return UCs(h,d),h},{replace:!0})},[t]),u=g.useRef(!1);return g.useEffect(()=>{if(u.current||(u.current=!0,FCs(e)))return;const d=FUt();d&&t(f=>{const h=new URLSearchParams(f);for(const[p,m]of d)h.append(p,m);return h},{replace:!0})},[]),a.jsx(YCs,{preset:r,filterTokens:i,onPresetChange:o,onFilterTokensChange:c,customRange:s,onCustomRangeChange:l,children:a.jsx(cEs,{children:a.jsx(mEs,{})})})}function mEs(){const{error:e,isLoading:t}=WUt(mf()),{isInMemory:n}=wz(),{data:r,isLoading:s}=I7t(),{data:i,isLoading:o}=hNe(),{data:l,isLoading:c}=E7t(),{data:u,isLoading:d}=pNe(),f=g.useMemo(()=>BUt({availableTags:r??[],availableEntityNames:i??[],availableServiceNames:l??[],availableEnvironments:u??[],loading:{tags:s,entityNames:o,serviceNames:c,environments:d}}),[r,i,l,u,s,o,c,d]);return e&&js(e)?a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:AD}),children:[a.jsx("h1",{className:"sr-only",children:"Metrics"}),a.jsx(ai,{variant:"fill"})]}):e&&Cs(e)?a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:AD}),children:[a.jsx("h1",{className:"sr-only",children:"Metrics"}),a.jsx(Gs,{variant:"fill",resource:"metrics"})]}):e?a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:AD}),children:[a.jsx("h1",{className:"sr-only",children:"Metrics"}),a.jsx(Xt,{tone:"error",variant:"fill",titleSlot:"Failed to load metrics",descriptionSlot:e.message})]}):a.jsx(Dye,{filterFields:f,isLoading:t,children:a.jsxs("div",{className:"grid content-start gap-4",children:[n&&a.jsx(Ht,{variant:"info",title:"Metrics are not persisted",children:a.jsx(Ht.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."})}),a.jsx(gEs,{})]})})}function gEs(){const{openTraces:e,openLogs:t}=hEs(),n=sd.AGENT;return a.jsxs("div",{className:"grid content-start gap-4 pb-6",children:[a.jsx(N_s,{}),a.jsx(uTs,{onViewTraces:()=>e(),onTimeRangeClick:r=>e({window:r})}),a.jsxs(Jw,{columns:3,children:[a.jsx(Jw.Item,{children:a.jsx(fTs,{onTimeRangeClick:r=>e({rootEntityType:n,window:r})})}),a.jsx(Jw.Item,{children:a.jsx(xTs,{onViewErrors:()=>t({rootEntityType:n,status:"error"}),onTimeRangeClick:r=>e({rootEntityType:n,status:"error",window:r})})}),a.jsx(Jw.Item,{span:2,className:"@7xl:col-span-1",children:a.jsx(CTs,{onViewTraces:r=>e({rootEntityType:r}),onTimeRangeClick:r=>e({window:r})})})]}),a.jsxs(Jw,{columns:2,children:[a.jsx(Jw.Item,{children:a.jsx(WTs,{onViewTraces:r=>e({rootEntityType:r}),onViewErrors:r=>t({rootEntityType:r,status:"error"}),onEntityClick:(r,s)=>e({rootEntityType:r,entityName:s})})}),a.jsx(Jw.Item,{children:a.jsx(YTs,{onViewTraces:()=>e(),onAgentClick:r=>e({rootEntityType:n,entityName:r}),onModelClick:r=>e({model:r}),onThreadClick:r=>e({threadId:r})})})]}),a.jsx(iEs,{})]})}function vEs(){const{isCmsAvailable:e}=zx(),{paths:t}=xn();return e?a.jsx(aX,{href:t.cmsPromptBlockCreateLink(),tooltip:"Create a prompt",children:"New prompt"}):null}const RM=[_s("/prompts")],yEs=50,xEs=["updatedAt"];function bEs(){const[e,t]=g.useState(""),[n,r]=g.useState(0),[s,i]=oi(),{sort:o,onSortChange:l}=zk({searchParams:s,setSearchParams:i,allowedKeys:xEs}),c=g.useMemo(()=>o?{field:o.key,direction:o.direction==="asc"?"ASC":"DESC"}:void 0,[o]),{data:u,isLoading:d,error:f,isPlaceholderData:h}=P9t({page:n,perPage:yEs,orderBy:c}),p=u?.promptBlocks??[],m=u?.hasMore??!1,v=g.useCallback(()=>{h||r(S=>S+1)},[h]),y=g.useCallback(()=>{h||r(S=>Math.max(0,S-1))},[h]),x=g.useCallback(S=>{t(S),r(0)},[]),b=g.useCallback((S,k)=>{l(S,k),r(0)},[l]);return f&&js(f)?a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:RM}),children:[a.jsx("h1",{className:"sr-only",children:"Prompts"}),a.jsx(ai,{variant:"fill"})]}):f&&Cs(f)?a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:RM}),children:[a.jsx("h1",{className:"sr-only",children:"Prompts"}),a.jsx(Gs,{variant:"fill",resource:"prompt blocks"})]}):f?a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:RM}),children:[a.jsx("h1",{className:"sr-only",children:"Prompts"}),a.jsx(Xt,{tone:"error",variant:"fill",titleSlot:"Failed to load prompt blocks",descriptionSlot:f.message})]}):p.length===0&&!d&&n===0?a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:RM}),children:[a.jsx("h1",{className:"sr-only",children:"Prompts"}),a.jsx(xhs,{})]}):a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:RM}),headerActions:a.jsx(vEs,{}),actionRow:a.jsx(Xn,{children:a.jsx(Xn.Start,{children:a.jsx("div",{className:"max-w-120 flex-1",children:a.jsx(Ru,{onSearch:x,label:"Filter prompts",placeholder:"Filter by name or description"})})})}),children:[a.jsx("h1",{className:"sr-only",children:"Prompts"}),a.jsx(yhs,{promptBlocks:p,isLoading:d,search:e,currentPage:n,hasMore:m,onNextPage:v,onPrevPage:y,updatedSort:o?.direction,onSortChange:b})]})}const wEs=[_s("/resources")],SEs=[{title:"Mastra APIs",description:"Explore and test the available REST API endpoints with the interactive Swagger UI.",icon:i_n,href:"/swagger-ui",external:!1},{title:"Documentation",description:"Read the official Mastra documentation for guides, references, and tutorials.",icon:Fft,href:"https://mastra.ai/en/docs",external:!0},{title:"Github",description:"Browse the source code, report issues, and contribute to the Mastra project.",icon:Zs,href:"https://github.com/mastra-ai/mastra",external:!0},{title:"Community",description:"Join the Mastra Discord community for help, discussion, and collaboration.",icon:nL,href:"https://discord.gg/mastra-ai",external:!0},{title:"Share with your team",description:"Running Mastra Studio locally? Deploy to the cloud so your team can collaborate.",icon:z0e,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:D0e,href:"https://mastra.ai/contact?ref=studio",external:!0}];function kEs(){return a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:wEs}),children:[a.jsx("h1",{className:"sr-only",children:"Resources"}),a.jsx("div",{children:a.jsx("div",{className:"grid max-w-3xl grid-cols-1 gap-4 sm:grid-cols-2",children:SEs.map(e=>a.jsxs("a",{href:e.href,...e.external?{target:"_blank",rel:"noreferrer"}:{},className:"group state-layer flex flex-col gap-3 rounded-lg border border-border bg-background p-5 hover:border-border-strong",children:[a.jsxs("div",{className:"flex items-center gap-2.5",children:[a.jsx(e.icon,{className:Z("h-5 w-5 text-muted-foreground group-hover:text-info-indicator",jn)}),a.jsx(Y,{as:"span",variant:"subheading",tone:"ink",children:e.title}),e.external&&a.jsx(Zs,{className:"ml-auto h-3.5 w-3.5 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100"})]}),a.jsx(Y,{variant:"caption",tone:"muted",children:e.description})]},e.href))})})]})}function qtt(){const{isCmsAvailable:e}=zx(),{paths:t}=xn();return e?a.jsx(aX,{href:t.cmsScorersCreateLink(),tooltip:"Create a scorer",children:"New scorer"}):null}const MM=[_s("/scorers")];function OEs(){const{data:e={},isLoading:t,error:n}=ag(),[r,s]=g.useState(""),[i,o]=g.useState("all"),[l,c]=g.useState();if(n&&js(n))return a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:MM}),children:[a.jsx("h1",{className:"sr-only",children:"Scorers"}),a.jsx(ai,{variant:"fill"})]});if(n&&Cs(n))return a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:MM}),children:[a.jsx("h1",{className:"sr-only",children:"Scorers"}),a.jsx(Gs,{variant:"fill",resource:"scorers"})]});if(n)return a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:MM}),children:[a.jsx("h1",{className:"sr-only",children:"Scorers"}),a.jsx(Xt,{tone:"error",variant:"fill",titleSlot:"Failed to load scorers",descriptionSlot:n.message})]});if(Object.keys(e).length===0&&!t)return a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:MM}),headerActions:a.jsx(qtt,{}),children:[a.jsx("h1",{className:"sr-only",children:"Scorers"}),a.jsx(uus,{})]});const u=i!=="all"||r!=="",d=()=>{s(""),o("all")};return a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:MM}),headerActions:a.jsx(qtt,{}),actionRow:a.jsx(fus,{search:r,onSearchChange:s,sourceFilter:i,onSourceFilterChange:o,onReset:d,hasActiveFilters:u}),children:[a.jsx("h1",{className:"sr-only",children:"Scorers"}),a.jsx(cus,{scorers:e,isLoading:t,search:r,sourceFilter:i,sort:l,onSortChange:(f,h)=>c({key:h,direction:f})})]})}const vqt=["input","entity"],jEs={input:"Input",entity:"Entity"};function CEs(e){const t=["auto","auto","minmax(0, 10rem)"];return e.has("entity")&&t.push("minmax(0, 14rem)"),e.has("input")&&t.push("minmax(0, 40rem)"),t.join(" ")}function _Es(){const[e,t]=g.useState(new Set),n=g.useMemo(()=>new Set(vqt.filter(i=>!e.has(i))),[e]),r=g.useMemo(()=>CEs(n),[n]),s=g.useCallback(i=>{t(o=>{const l=new Set(o);return l.has(i)?l.delete(i):l.add(i),l})},[]);return{visibleColumns:n,columns:r,toggleColumn:s}}function TEs({visibleColumns:e,toggleColumn:t}){return a.jsxs(ct,{children:[a.jsx(ct.Trigger,{asChild:!0,children:a.jsx(de,{icon:a.jsx(Wft,{}),children:"Columns"})}),a.jsxs(ct.Content,{align:"end",children:[a.jsx(ct.Label,{children:"Toggle columns"}),vqt.map(n=>a.jsx(ct.CheckboxItem,{checked:e.has(n),onClick:()=>t(n),children:jEs[n]},n))]})]})}const Qtt=[_s("/scorers"),olr],EEs=["date","score"];function IEs(){const{scorerId:e}=jr(),[t,n]=oi(),r=t.get("scoreId")??void 0,[s,i]=g.useState(r),[o,l]=g.useState(!1),c=Dr(),[u,d]=g.useState({value:"all",label:"All Entities",type:"ALL"}),{scorer:f,error:h}=Bar(e),p=_Es(),{data:m={},isLoading:v,error:y}=ch(),{isLoading:x,error:b}=Op({}),{sort:S,onSortChange:k}=zk({searchParams:t,setSearchParams:n,allowedKeys:EEs}),{data:j=[],isLoading:C,error:T,isFetchingNextPage:_,hasNextPage:N,setEndOfListElement:I}=Far({scorerId:e,entityId:u?.value==="all"?void 0:u?.value,entityType:u?.type==="ALL"?void 0:u?.type}),A=g.useMemo(()=>Pk(j,S,{date:X=>X.createdAt,score:X=>typeof X.score=="number"?X.score:void 0}),[j,S]),P=g.useMemo(()=>f?.agentIds?.filter(X=>m[X]).map(X=>({value:X,label:m[X].name,type:"AGENT"}))||[],[f?.agentIds,m]),D=g.useMemo(()=>f?.workflowIds?.map(X=>({value:X,label:X,type:"WORKFLOW"}))||[],[f?.workflowIds]),F=g.useMemo(()=>[{value:"all",label:"All Entities",type:"ALL"},...P,...D],[P,D]),Q=t.get("entity")??"all",q=F.find(X=>X.value===Q);q&&q.value!==u?.value&&d(q),g.useEffect(()=>{if(h){const X=h instanceof Error?h.message:"Failed to load scorer";Ke.error(`Error loading scorer: ${X}`)}},[h]),g.useEffect(()=>{if(y){const X=y instanceof Error?y.message:"Failed to load agents";Ke.error(`Error loading agents: ${X}`)}},[y]),g.useEffect(()=>{if(b){const X=b instanceof Error?b.message:"Failed to load workflows";Ke.error(`Error loading workflows: ${X}`)}},[b]);const B=X=>{X?.value&&n(te=>{const ie=new URLSearchParams(te);return ie.set("entity",X.value),ie})};g.useEffect(()=>{const X=t.get("scoreId")??void 0;if(X===s)return;if(!X){i(void 0);return}A.find(ie=>ie.id===X)&&i(X)},[t,A]);const V=g.useCallback(X=>{i(X||void 0),n(te=>{const ie=new URLSearchParams(te);return X?ie.set("scoreId",X):ie.delete("scoreId"),ie})},[n]);if(!f)return null;const H=js(h)||js(y)||js(b),M=h&&Cs(h),G=!H&&!M&&(h||y||b),L=!C&&A.length===0,$=u?.value!=="all",z=f?.source==="stored",U=e?a.jsx(FJ,{open:o,onOpenChange:l,initialScorerIds:[e],onSuccess:X=>{c(`/experiments/${X}`)}}):null,K=z?a.jsxs(ct,{children:[a.jsx(ct.Trigger,{asChild:!0,children:a.jsx(de,{size:"lg","aria-label":"Scorer actions menu",children:a.jsx(M0,{})})}),a.jsx(ct.Content,{align:"end",className:"w-48",children:a.jsxs(ct.Item,{onSelect:()=>{c(`/cms/scorers/${e}/edit`)},children:[a.jsx(Fc,{})," Edit Scorer"]})})]}):null;if(H||M||G||L&&!$){const X=(h instanceof Error?h.message:void 0)??(y instanceof Error?y.message:void 0)??(b instanceof Error?b.message:void 0)??"An unexpected error occurred",te=H||M||G;return a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:Qtt}),actionRow:!te&&K?a.jsx(Xn,{children:a.jsx(Xn.End,{children:K})}):void 0,children:[a.jsx("h1",{className:"sr-only",children:e}),a.jsx("div",{className:"flex h-full items-center justify-center",children:H?a.jsx(ai,{}):M?a.jsx(Gs,{resource:"scorers"}):G?a.jsx(Xt,{tone:"error",titleSlot:"Failed to load scorer",descriptionSlot:X}):a.jsx(Hcs,{onRunExperiment:()=>l(!0)})}),U]})}return a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:Qtt}),actionRow:a.jsxs(Xn,{children:[a.jsx(Xn.Start,{children:a.jsx(aus,{selectedEntity:u,entityOptions:F,onEntityChange:B,onReset:()=>{n(X=>{const te=new URLSearchParams(X);return te.set("entity","all"),te})},isLoading:C||v||x})}),a.jsxs(Xn.End,{children:[a.jsx(TEs,{visibleColumns:p.visibleColumns,toggleColumn:p.toggleColumn}),a.jsx(de,{variant:"primary",onClick:()=>l(!0),icon:a.jsx(Bc,{}),children:"Run Experiment"}),K]})]}),children:[a.jsx("h1",{className:"sr-only",children:e}),a.jsx(Wcs,{scores:A,isLoading:C,selectedScoreId:s,isFetchingNextPage:_,hasNextPage:N,setEndOfListElement:I,onScoreClick:V,errorMsg:T?.message,columnsState:p,sort:S,onSortChange:k}),U]})}const yqt=g.createContext(void 0);function NEs({value:e,onValueChange:t,"aria-label":n,size:r="md",iconOnly:s=!1,className:i,children:o,...l}){const c=g.useRef(new Map),u=g.useRef(null),d={iconOnly:s,registerItem:(h,p)=>c.current.set(h,p),unregisterItem:h=>c.current.delete(h)},f=h=>typeof h=="string"&&c.current.has(h);return g.useLayoutEffect(()=>{const h=u.current,p=c.current.get(e);if(!h)return;if(!p){h.hidden=!0;return}const m=()=>{h.style.width=`${p.offsetWidth}px`,h.style.transform=`translateX(${p.offsetLeft}px)`};m();let v;h.hidden&&(h.hidden=!1,v=requestAnimationFrame(()=>h.setAttribute("data-ready","")));const y=typeof ResizeObserver>"u"?void 0:new ResizeObserver(m);return c.current.forEach(x=>y?.observe(x)),()=>{v!==void 0&&cancelAnimationFrame(v),y?.disconnect()}},[e,o]),a.jsx(yqt.Provider,{value:d,children:a.jsxs(q4t,{...l,value:e,onValueChange:h=>{f(h)&&t(h)},"aria-label":n,...Tx({"aria-label":n,"aria-labelledby":l["aria-labelledby"]}),"data-slot":"segmented-control","data-size":r,className:Z(pr,"relative inline-flex w-fit shrink-0 items-stretch rounded-full p-0.5",s&&"gap-0.5",np[r],"data-[disabled]:opacity-50",i),children:[a.jsx("span",{ref:u,hidden:!0,"aria-hidden":"true","data-slot":"segmented-control-thumb",className:Z("pointer-events-none absolute inset-y-0.5 left-0 rounded-full bg-fill-hover ring-1 ring-border ring-inset","motion-safe:data-[ready]:transition-[transform,width] motion-safe:data-[ready]:duration-normal motion-safe:data-[ready]:ease-out-custom")}),o]})})}function AEs({value:e,disabled:t,className:n,children:r,ref:s,...i}){const o=g.useContext(yqt);if(!o)throw new Error("SegmentedControlItem must be used inside a SegmentedControl");const{iconOnly:l,registerItem:c,unregisterItem:u}=o,d=fk(s,f=>(f&&c(e,f),()=>u(e)));return a.jsx(U4t,{...i,render:a.jsx("span",{"aria-labelledby":i["aria-labelledby"]}),ref:d,value:e,disabled:t,"data-slot":"segmented-control-item",className:Z("relative inline-flex cursor-pointer items-center justify-center gap-1.5 rounded-full text-label whitespace-nowrap select-none",l?"aspect-square":"px-3",t&&"opacity-50","[&_svg]:size-3.5 [&_svg]:shrink-0","text-muted-foreground hover:text-foreground data-[checked]:text-foreground","focus-visible:outline-1 focus-visible:-outline-offset-1 focus-visible:outline-border-focus","data-[disabled]:cursor-not-allowed data-[disabled]:hover:text-muted-foreground",jn,n),children:r})}const PEs=[{value:"system",label:"System",icon:a.jsx(uht,{})},{value:"light",label:"Light",icon:a.jsx(AIn,{})},{value:"dark",label:"Dark",icon:a.jsx(JTn,{})}];function $Es(e,t){if(e.some(r=>r.value===t))return t;const[n]=e;return n?n.value:"system"}const REs=({value:e,onChange:t,options:n=PEs,size:r="md","aria-label":s="Theme",...i})=>{const{theme:o,setTheme:l}=Q1e(),c=e??o,u=t??l,d=$Es(n,c);return a.jsx(NEs,{...i,"aria-label":s,iconOnly:!0,size:r==="xs"?"sm":r,value:d,onValueChange:u,children:n.map(f=>a.jsx(AEs,{value:f.value,"aria-label":f.label,children:f.icon},f.value))})},MEs=[_s("/settings")],DEs=()=>{const{baseUrl:e,headers:t,apiPrefix:n}=sL();return a.jsxs(Et,{variant:"fit",breadcrumbs:a.jsx(Dt,{crumbs:MEs}),children:[a.jsx("h1",{className:"sr-only",children:"Settings"}),a.jsx($us,{children:a.jsxs("div",{className:"mx-auto flex max-w-4xl flex-col gap-8",children:[a.jsxs($A,{children:[a.jsxs(Hve,{children:[a.jsx(RA,{children:"General"}),a.jsx(mXe,{children:"Stored in this browser."})]}),a.jsx(p$,{children:a.jsx(dz,{label:"Theme",description:"Customize the appearance of the studio.",children:a.jsx(REs,{})})})]}),a.jsxs($A,{children:[a.jsxs(Hve,{children:[a.jsx(RA,{children:"Mastra Connection"}),a.jsx(mXe,{children:"Configure the Mastra instance URL, API prefix, and request headers used by the studio."})]}),a.jsx(s9t,{variant:"factory",initialConfig:{baseUrl:e,headers:t,apiPrefix:n}})]})]})})]})};function LEs(){const[e]=oi(),t=Dr(),n=e.get("redirect")||"/",r=()=>{n.startsWith("http")?window.location.href=n:t(n,{replace:!0})};return a.jsx(kUt,{redirectUri:n,onSuccess:r,initialMode:"signup"})}async function xqt(){const e=await fetch("https://mastra.ai/api/templates.json");if(!e.ok)throw new Error(`Failed to fetch templates: ${e.statusText}`);const t=[{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"]},...await e.json()];return{templates:t,tags:Array.from(new Set(t.flatMap(n=>n.tags))),providers:Array.from(new Set(t.flatMap(n=>n.supportedProviders)))}}async function zEs({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 FEs({repoOrSlug:e,owner:t}){const{templates:n}=await xqt(),r=n.find(s=>s.slug===e);if(!r){if(e.startsWith("template-")){const i=n.find(o=>`template-${o.slug}`===e);if(i)return i}const s=await zEs({repo:e,owner:t});if(s)return s;throw new Error(`Template ${e} not found`)}return r}async function BEs({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(`
|
|
699
|
-
`).reduce((i,o)=>{if(!o||o.startsWith("#"))return i;const[l,c]=o.split("=");return l&&(i[l]=c?.split("")?.every(u=>u==="*")?"":c?.replaceAll('"',"")),i},{}):{}}const VEs=({queryOptions:e}={})=>_t({queryKey:["mastra-templates"],queryFn:xqt,...e}),UEs=({repoOrSlug:e,owner:t,queryOptions:n})=>_t({queryKey:["template-repo",e,t],queryFn:()=>FEs({repoOrSlug:e,owner:t}),...n}),qEs=({repo:e,owner:t,branch:n,queryOptions:r})=>_t({queryKey:["template-repo-env-vars",e,t,n],queryFn:()=>BEs({repo:e,owner:t,branch:n}),...r}),QEs=({queryOptions:e}={})=>{const t=Ye();return _t({queryKey:["agent-builder-workflow"],queryFn:async()=>await t.getAgentBuilderAction("merge-template").details(),...e})},ZEs=({queryOptions:e}={})=>{const t=Ye();return kn({mutationFn:async({runId:n})=>await t.getAgentBuilderAction("merge-template").createRun({runId:n}),...e})},WEs=({queryOptions:e}={})=>{const t=Ye();return kn({mutationFn:async({runId:n})=>await t.getAgentBuilderAction("merge-template").runById(n),...e})},Ztt=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)},Wtt=(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((s,i)=>(s[i]={id:i,description:n.allSteps[i].description,status:"pending"},s),{})}}),e.type==="start"||e.type==="workflow-start"){const s={};n?.allSteps&&Object.entries(n.allSteps).forEach(([o,l])=>{s[o]={id:l.id,description:l.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:s},currentStep:null}}}if(e.type==="step-start"||e.type==="workflow-step-start"){const s=e.payload.id;r={...r,phase:"processing",payload:{...r.payload,currentStep:{id:s,status:"running",startTime:new Date,...e.payload},workflowState:{...r.payload.workflowState,steps:{...r.payload.workflowState.steps,[s]:{...r.payload.workflowState.steps[s],status:"running",startTime:new Date,...e.payload}}}}}}if(e.type==="step-result"||e.type==="workflow-step-result"){const s=e.payload.id,i=e.payload.status,o=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,[s]:{...r.payload.workflowState.steps[s],status:e.payload.status,output:e.payload.output,error:e.payload.error,endTime:new Date}}}}},i==="failed"&&o){const l=Ztt(o);r={...r,status:"failed",error:l,phase:"error",failedStep:{id:s,error:l,description:e.payload.description||s},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 s=Ztt(e.payload.error);r={...r,status:"failed",error:s,phase:"error",payload:{...r.payload,workflowState:{...r.payload.workflowState,status:"failed"}},errorTimestamp:new Date}}return{newState:r}},HEs=(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)}},bqt=(e,t)=>{const[n,r]=g.useState({}),[s,i]=g.useState(!1);return{streamResult:n,isStreaming:s,processStream:async(l,c)=>{if(i(!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:h}=await u.read();if(f)break;const{newState:p}=Wtt(h,d,e);if(d=p,r(p),h.runId||c||t){const m=h.runId||c||t;HEs(m,p)}}}catch(f){console.error("💥 [processStream] Error processing template installation stream:",f);const{newState:h}=Wtt({type:"error",payload:{error:f instanceof Error?f.message:"Unknown error"}},d,e);r(h)}finally{i(!1),u.releaseLock()}}}},GEs=({workflowInfo:e,queryOptions:t}={})=>{const n=Ye(),{streamResult:r,isStreaming:s,processStream:i}=bqt(e);return{streamInstall:kn({mutationFn:async({inputData:o,selectedModel:l,runId:c})=>{for(let d=1;d<=3;d++)try{const f=n.getAgentBuilderAction("merge-template"),h=new t_;h.set("selectedModel",l);const p=await f.stream({inputData:o,requestContext:h},c);await i(p,c);return}catch(f){console.error(`💥 [streamInstall] Attempt ${d} failed:`,f);const h=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),h){const p=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:",p),new Error(p)}throw console.error("❌ [streamInstall] Non-network error or max retries reached, throwing:",f),f}},...t?.streamInstall}),streamResult:r,isStreaming:s}},KEs=({workflowInfo:e,queryOptions:t}={})=>{const n=Ye(),{streamResult:r,isStreaming:s,processStream:i}=bqt(e);return{observeInstall:kn({mutationFn:async({runId:o})=>{for(let u=1;u<=3;u++)try{const d=await n.getAgentBuilderAction("merge-template").observeStream({runId:o});await i(d,o);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(h=>setTimeout(h,2e3));continue}throw console.error("❌ [observeInstall] Non-network error or max retries reached, throwing:",d),d}},...t?.observeInstall}),streamResult:r,isStreaming:s}};function YEs(e){return e.replace(/\/$/,"").split("/").pop()}function XEs({templates:e,linkComponent:t,className:n,isLoading:r}){const s=t||"a";return r?a.jsx("div",{className:Z("grid gap-y-4",n),children:Array.from({length:5}).map((i,o)=>a.jsx("div",{className:"h-16 animate-pulse rounded-lg bg-card"},o))}):a.jsx("div",{className:Z("grid gap-y-4",n),children:e.map(i=>{const o=i?.agents||i?.tools||i?.networks||i?.workflows||i?.mcp;return a.jsxs("article",{className:Z(pr,"state-layer grid w-full grid-cols-[1fr_auto] overflow-hidden rounded-lg"),children:[a.jsxs(s,{to:`/templates/${i.slug}`,className:Z("group grid",{"grid-cols-[8rem_1fr] lg:grid-cols-[12rem_1fr]":i.imageURL}),children:[i.imageURL&&a.jsx("div",{className:"overflow-hidden",children:a.jsx("div",{className:"thumb transition-scale h-full w-full bg-cover duration-150",style:{backgroundImage:`url(${i.imageURL})`}})}),a.jsxs("div",{className:Z("grid w-full gap-0.5 px-4 py-3","[&_svg]:h-[1em] [&_svg]:w-[1em] [&_svg]:text-muted-foreground"),children:[a.jsx(Y,{as:"h2",tone:"ink",children:i.title}),a.jsx(Y,{className:Z(dx,jn),children:i.description}),a.jsxs("div",{className:"mt-3 hidden flex-wrap items-center gap-4 text-muted-foreground 2xl:flex",children:[o&&a.jsxs("ul",{className:Z("text-muted-foreground","m-0 flex list-none gap-4 p-0","[&>li]:flex [&>li]:items-center [&>li]:gap-0.5"),children:[i?.agents&&i.agents.length>0&&a.jsx("li",{children:a.jsxs(Y,{as:"span",variant:"body",className:"block",children:[a.jsx(ko,{})," ",i.agents.length]})}),i?.tools&&i.tools.length>0&&a.jsx("li",{children:a.jsxs(Y,{as:"span",variant:"body",className:"block",children:[a.jsx(ud,{})," ",i.tools.length]})}),i?.networks&&i.networks.length>0&&a.jsx("li",{children:a.jsxs(Y,{as:"span",variant:"body",className:"block",children:[a.jsx(dht,{})," ",i.networks.length]})}),i?.workflows&&i.workflows.length>0&&a.jsx("li",{children:a.jsxs(Y,{as:"span",variant:"body",className:"block",children:[a.jsx(dk,{})," ",i.workflows.length]})}),i?.mcp&&i.mcp.length>0&&a.jsx("li",{children:a.jsxs(Y,{as:"span",variant:"body",className:"block",children:[a.jsx(I_,{})," ",i.mcp.length]})})]}),o&&i.supportedProviders&&a.jsx("small",{children:a.jsx(Y,{as:"span",variant:"body",children:"|"})}),a.jsx("div",{className:"flex items-center gap-4",children:i.supportedProviders.map(l=>a.jsx(Y,{tone:"muted",as:"span",variant:"body",children:l},l))})]})]})]}),a.jsx("a",{href:i.githubUrl,className:Z("group ml-auto hidden items-center gap-2 pr-4","lg:flex"),target:"_blank",rel:"noopener noreferrer",children:a.jsx(Y,{as:"span",variant:"body",children:a.jsxs("span",{className:Z("flex items-center gap-2 rounded bg-sidebar px-2 py-1",Oft,dx,jn),children:[a.jsx(oX,{})," ",YEs(i.githubUrl)]})})})]},i.slug)})})}function JEs({tagOptions:e,selectedTag:t,providerOptions:n,selectedProvider:r,onTagChange:s,onProviderChange:i,searchTerm:o,onSearchChange:l,onReset:c,className:u,isLoading:d}){return d?a.jsxs("div",{className:Z("flex h-[6.5rem] items-center gap-5","[&>div]:h-8 [&>div]:w-48 [&>div]:animate-pulse [&>div]:bg-card",u),children:[a.jsx("div",{})," ",a.jsx("div",{})," ",a.jsx("div",{})]}):a.jsxs("div",{className:Z("sticky top-0 mx-auto flex flex-wrap gap-4 bg-background py-5",u),children:[a.jsx(qc,{label:"Search templates",placeholder:"Search Template",value:o,onValueChange:l}),a.jsxs(Vr,{value:t,onValueChange:s,children:[a.jsx(qr,{"aria-label":"Filter by tag",size:"md",children:a.jsx(Ur,{placeholder:"Select an option"})}),a.jsx(Qr,{children:e.map(f=>a.jsx(ir,{value:f.value,children:f.label},f.value))})]}),a.jsxs(Vr,{value:r,onValueChange:i,children:[a.jsx(qr,{"aria-label":"Filter by provider",size:"md",children:a.jsx(Ur,{placeholder:"Select an option"})}),a.jsx(Qr,{children:n.map(f=>a.jsx(ir,{value:f.value,children:f.label},f.value))})]}),c&&a.jsx(de,{onClick:c,icon:a.jsx(Dn,{}),children:"Reset"})]})}const eIs=[{id:"templates",label:"Templates"}];function tIs(){const{data:e,isLoading:t}=VEs(),{templates:n,tags:r,providers:s}=e??{templates:[],tags:[],providers:[]},[i,o]=g.useState("all"),[l,c]=g.useState("all"),[u,d]=g.useState(""),f=[{value:"all",label:"Any tag"}];(r||[]).forEach(b=>{f.push({value:b,label:b})});const h=[{value:"all",label:"Any provider"}];(s||[]).forEach(b=>{h.push({value:b,label:b})});const p=(b,S)=>{S==="tag"?o(b):S==="provider"&&c(b)},m=b=>{d(b)},v=()=>{o("all"),c("all"),d("")},y=n.filter(b=>!(u&&!b.title.toLowerCase().includes(u)&&!b.description.toLowerCase().includes(u)||i!=="all"&&!b.tags.includes(i)||l!=="all"&&!b.supportedProviders.includes(l))),x=u||i!=="all"||l!=="all";return a.jsxs(Et,{variant:"fit",breadcrumbs:a.jsx(Dt,{crumbs:eIs}),children:[a.jsx("h1",{className:"sr-only",children:"Templates"}),a.jsx(iL,{children:a.jsxs(Nht,{children:[a.jsx(At,{children:a.jsx(F1,{})}),"Templates"]})}),a.jsxs("div",{className:Z("z-10 h-full w-full overflow-y-auto px-5 pb-12"),children:[a.jsx(JEs,{selectedTag:i,onTagChange:b=>p(b,"tag"),tagOptions:f,selectedProvider:l,onProviderChange:b=>p(b,"provider"),providerOptions:h,searchTerm:u,onSearchChange:m,onReset:x?v:void 0,className:"max-w-[80rem]",isLoading:t}),a.jsx(XEs,{templates:y,linkComponent:lc,className:"mx-auto max-w-[80rem]",isLoading:t})]})]})}const nIs="1.76.0-alpha.6";function nee({children:e,className:t}){return a.jsx("div",{className:Z("transition-height mt-12 rounded-lg border border-border px-4 py-5 lg:min-h-[25rem] lg:px-12",t),children:e})}function rIs({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,i=()=>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.",o=()=>s?{icon:a.jsx(Yd,{className:"text-warning-foreground"}),title:"Template Installed with Warnings"}:{icon:a.jsx(y_n,{}),title:"Template Installation Failed"},{icon:l,title:c}=o();return a.jsxs(nee,{className:"mb-5 content-center space-y-4 text-muted-foreground",children:[a.jsxs("div",{className:"grid content-center items-center justify-items-center gap-4 [&>svg]:h-8 [&>svg]:w-8",children:[l,a.jsxs("div",{className:"space-y-2 text-center",children:[a.jsx(Y,{variant:"subheading",tone:"ink",children:c}),a.jsx(Y,{tone:"muted",children:i()})]})]}),t&&t.length>0&&a.jsxs("details",{children:[a.jsx("summary",{className:Z(Fn,"cursor-pointer text-center select-none"),children:a.jsxs(Y,{as:"span",variant:"caption",className:"block",children:["Show Validation Issues (",t.length,")"]})}),a.jsx("div",{className:"mt-4 max-h-60 space-y-2 overflow-auto rounded bg-muted p-3 text-left",children:t.map((u,d)=>a.jsxs("div",{className:"border-l-2 border-destructive-indicator pl-2",children:[a.jsx(Y,{as:"p",variant:"column",className:"text-destructive-foreground",children:u.type==="typescript"?"🔴 TypeScript Error":"⚠️ Lint Error"}),a.jsx(cl,{className:"mt-1 text-caption wrap-break-word whitespace-pre-wrap text-muted-foreground",code:u.message})]},d))})]}),n&&!s&&a.jsxs("details",{children:[a.jsx("summary",{className:Z(Fn,"cursor-pointer text-center select-none"),children:a.jsx(Y,{as:"span",variant:"caption",className:"block",children:"Show Details"})}),a.jsx("div",{className:"mt-4 max-h-60 overflow-auto rounded bg-muted p-3 text-left",children:a.jsx(cl,{className:"text-caption wrap-break-word whitespace-pre-wrap",code:n})})]})]})}const sIs=g.createContext(null);function iIs(){const e=g.useContext(sIs);return e||{registerResetFn:()=>{},triggerReset:()=>{}}}const wqt=({defaultProvider:e,defaultModel:t,updateModel:n,resetModel:r})=>{const[s]=g.useState(e),[i]=g.useState(t),[o,l]=g.useState(t),[c,u]=g.useState(e||""),[d,f]=g.useState(!1),[h,p]=g.useState(!1),[m,v]=g.useState(!1),{data:y,isLoading:x}=x6(),b=z0(),{models:S}=J0(),k=g.useMemo(()=>y?.providers||[],[y]);g.useEffect(()=>{l(t),u(e||"")},[t,e]);const j=io(c),T=UI(k,j)?.id||j,_=async F=>{if(l(F),F&&T){f(!0);try{const Q=await n({provider:T,modelId:F});console.info("Model updated:",Q)}catch(Q){console.error("Failed to update model:",Q)}finally{f(!1)}}},N=F=>{const Q=io(F);u(Q),Q!==j&&(l(""),v(!0))},{registerResetFn:I}=iIs();if(g.useEffect(()=>(I(()=>{if(h||m)return;if(j&&j!==s&&(!o||o==="")){u(io(s)),l(i);const V=UI(k,s)?.id||s;V&&i&&n({provider:V,modelId:i}).catch(H=>{console.error("Failed to reset model:",H)})}}),()=>{I(null)}),[I,j,o,s,i,n,h,m,k]),x)return a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(En,{}),a.jsx(Y,{as:"span",tone:"muted",children:"Loading providers..."})]});const A=async()=>{if(!r){console.warn("Reset model function not provided");return}try{f(!0),await r()}catch(F){console.error("Failed to reset model:",F)}finally{f(!1)}},P=UI(k,j);if(b.active&&b.pickerVisible===!1){const F=b.default&&b.default.provider&&b.default.modelId?`${b.default.provider}/${b.default.modelId}`:c&&o?`${c}/${o}`:"Locked by admin";return a.jsxs("div",{className:Z(pr,"flex items-center gap-2 rounded-md px-3 py-2"),"data-testid":"agent-metadata-model-locked",children:[a.jsx(Tu,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),a.jsx(Y,{as:"span",variant:"caption",tone:"ink",className:"truncate",children:F}),a.jsx(Y,{as:"span",variant:"meta",tone:"muted",className:"ml-auto shrink-0",children:"Set by admin"})]})}const D=!!(j&&o)&&b.active&&b.allowed!==void 0&&!S.some(F=>io(F.provider)===j&&F.model===o);return a.jsxs("div",{className:"@container",children:[a.jsxs("div",{className:"flex w-full flex-col items-stretch gap-2 @xs:flex-row @xs:items-center",children:[a.jsx("div",{className:"w-full @xs:w-2/5",children:a.jsx(Ek,{value:j,onValueChange:N,open:h,onOpenChange:p})}),a.jsx("div",{className:"w-full @xs:w-3/5",children:a.jsx(Ik,{llmId:j,value:o,onValueChange:_,open:m,onOpenChange:v})}),a.jsx(de,{variant:"default",size:"md",onClick:A,disabled:d,className:"flex items-center gap-1.5 border-0! whitespace-nowrap",title:"Reset to original model",children:a.jsx(b_,{className:"h-3.5 w-3.5"})})]}),D&&a.jsx("div",{className:"p-2 pt-2","data-testid":"agent-metadata-model-stale-warning",children:a.jsx(Ht,{variant:"warning",title:"Model not allowed",children:a.jsxs(Ht.Message,{children:[a.jsxs("code",{className:"rounded bg-fill-hover px-1 py-0.5",children:[c,"/",o]})," ","is no longer allowed by the admin policy. Pick a different model to save changes."]})})}),P&&!P.connected&&a.jsx("div",{className:"p-2 pt-2",children:a.jsx(Ht,{variant:"warning",title:"Provider not connected",children:a.jsxs(Ht.Message,{children:["Set the"," ",a.jsx("code",{className:"rounded bg-fill-hover px-1 py-0.5",children:Array.isArray(P.envVar)?P.envVar.join(", "):P.envVar})," ","environment"," ",Array.isArray(P.envVar)&&P.envVar.length>1?"variables":"variable"," to use this provider."]})})})]})};function oIs({providerOptions:e,selectedProvider:t,onProviderChange:n,variables:r,errors:s,handleInstallTemplate:i,handleVariableChange:o,isLoadingEnvVars:l,isInstalling:c,defaultModelProvider:u,defaultModelId:d,onModelUpdate:f}){return a.jsx(nee,{children:a.jsxs("div",{className:"mx-auto my-4 grid max-w-[40rem] gap-5 p-4 lg:p-5",children:[a.jsxs(Y,{as:"h2",variant:"heading",tone:"muted",className:Z("flex items-center gap-2","[&_svg]:h-[1.2em] [&_svg]:opacity-70 [&>svg]:w-[1.2em]"),children:["Install Template ",a.jsx(fht,{})]}),a.jsxs(ft,{orientation:"horizontal",children:[a.jsx(ut,{children:"Template AI Model Provider"}),a.jsx(Ggt,{className:"flex-1",children:a.jsxs(Vr,{name:"template-provider",value:t,onValueChange:n,children:[a.jsx(qr,{size:"md",children:a.jsx(Ur,{placeholder:"Select"})}),a.jsx(Qr,{children:e.map(h=>a.jsx(ir,{value:h.value,children:h.label},h.value))})]})})]}),t&&Object.entries(r||{}).length>0&&a.jsxs(a.Fragment,{children:[a.jsx(Y,{as:"h3",tone:"muted",children:"Set required Environmental Variables"}),a.jsx("div",{className:"grid grid-cols-[1fr_1fr] items-start gap-4",children:l?a.jsxs("div",{className:Z("text-muted-foreground","col-span-2 flex items-center justify-center gap-4","[&_svg]:h-[1.1em] [&_svg]:w-[1.1em] [&_svg]:opacity-50","animate-in duration-300 fade-in"),children:[a.jsx(En,{}),a.jsxs(Y,{as:"span",variant:"caption",className:"block",children:[" ","Loading variables..."]})]}):Object.entries(r).map(([h,p])=>a.jsxs(g.Fragment,{children:[a.jsxs(ft,{className:"w-full",children:[a.jsx(ut,{className:"sr-only",children:"Key"}),a.jsx(Sn,{name:`env-${h}`,value:h,disabled:!0,className:"w-full"})]}),a.jsxs(ft,{invalid:s.includes(h),className:"w-full",children:[a.jsx(ut,{className:"sr-only",children:"Value"}),a.jsx(Sn,{name:h,value:p,onChange:o,autoComplete:"off",className:"w-full"}),a.jsx(is,{children:s.includes(h)?"Value is required.":void 0})]})]},h))}),a.jsxs("div",{className:"relative mt-3.5 border-t border-border pt-12",children:[a.jsx("div",{className:"absolute top-0 left-1/2 flex h-8 w-8 -translate-x-1/2 -translate-y-4 items-center justify-center rounded-full bg-background",children:a.jsx(Y,{tone:"muted",as:"span",variant:"caption",className:"block",children:"And"})}),a.jsx(Y,{as:"h3",tone:"muted",children:"Set AI Model for Template Installation"}),a.jsx(Y,{tone:"muted",className:"mt-2 mb-5",children:"This model will be used by the workflow to process and install the template"}),a.jsx(wqt,{defaultProvider:u||"",defaultModel:d||"",updateModel:f||(()=>Promise.resolve({message:"Updated"})),closeEditor:()=>{},autoSave:!0,selectProviderPlaceholder:"Provider"})]})]}),t&&!l&&a.jsx(de,{className:Z("state-layer mt-4 flex min-h-10 w-full items-center justify-center gap-2 rounded-lg bg-card text-foreground","[&_svg]:h-[1.1em] [&_svg]:text-foreground [&>svg]:w-[1.1em]"),onClick:i,disabled:!t||!u||!d||s.length>0||c,children:c?a.jsxs(a.Fragment,{children:[a.jsx(En,{className:"h-4 w-4"})," Installing..."]}):a.jsxs(a.Fragment,{children:["Install ",a.jsx(fp,{})]})})]})})}function aIs({title:e,description:t,githubUrl:n,isLoading:r,infoData:s,templateSlug:i}){const o=i?`feat/install-template-${i}`:"feat/install-template-[slug]";return a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"mt-5 grid items-center",children:a.jsxs("div",{className:Z("flex items-center gap-3","[&>svg]:h-[1.2em] [&>svg]:w-[1.2em] [&>svg]:opacity-50",{"[&>svg]:opacity-20":r}),children:[a.jsx(F1,{}),a.jsx("h2",{className:Z({"flex min-w-[50%] rounded-lg bg-muted":r}),children:a.jsx(Y,{as:"span",variant:"title",className:"block",children:r?a.jsx(a.Fragment,{children:" "}):e})})]})}),a.jsxs("div",{className:"grid gap-x-24 lg:grid-cols-[1fr_1fr]",children:[a.jsxs("div",{className:"grid",children:[a.jsx(Y,{tone:"muted",className:Z("mt-2 mb-4",{"rounded-lg bg-muted":r}),children:r?a.jsx(a.Fragment,{children:" "}):t}),!r&&i&&a.jsxs("div",{className:Z("mb-4 rounded-lg border border-border bg-background p-4","flex items-start gap-3"),children:[a.jsx("div",{className:"mt-0.5 shrink-0",children:a.jsx(pp,{className:"h-[1.1em] w-[1.1em] text-info-indicator"})}),a.jsxs("div",{className:"flex-1 space-y-2",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(CN,{className:"h-[1em] w-[1em] text-muted-foreground"}),a.jsx(Y,{as:"span",variant:"subheading",tone:"ink",children:"A new Git branch will be created"})]}),a.jsxs("div",{className:"space-y-1",children:[a.jsxs(Y,{tone:"muted",as:"p",variant:"caption",children:[a.jsx(Y,{as:"span",variant:"column",children:"Branch name:"})," ",a.jsx(ih,{children:o})]}),a.jsx(Y,{tone:"muted",as:"p",variant:"caption",children:"This ensures safe installation with easy rollback if needed. Your main branch remains unchanged."})]})]})]}),n&&a.jsxs("a",{href:n,target:"_blank",rel:"noopener noreferrer",className:Z(Fn,"mt-auto flex items-center gap-2"),children:[a.jsx(oX,{}),a.jsx(Y,{as:"span",variant:"body",className:"block",children:n?.split("/")?.pop()})]})]}),s&&a.jsx($Ie,{data:s,labelsAreHidden:!0,isLoading:r})]})]})}function Htt(e){switch(e){case"running":return a.jsx(En,{size:"sm","aria-hidden":!0});case"success":return a.jsx(dr,{"aria-hidden":!0});case"failed":return a.jsx(Dn,{"aria-hidden":!0});default:return null}}function lIs(){return a.jsx("svg",{viewBox:"0 0 24 24",className:"text-placeholder","aria-hidden":!0,children:a.jsx("circle",{cx:"12",cy:"12",r:"8.5",pathLength:"48",fill:"none",stroke:"currentcolor",strokeWidth:"2.8",strokeLinecap:"round",strokeDasharray:"3 3"})})}function cIs({status:e,variant:t}){return t==="plain"?a.jsx("span",{className:Z("flex size-4 items-center justify-center self-center [&>svg]:size-4",$i.colors,{"[&>svg]:text-success-indicator":e==="success","[&>svg]:text-destructive-foreground":e==="failed"}),children:e==="pending"?a.jsx(lIs,{}):Htt(e)}):a.jsx("span",{className:Z("flex size-7 items-center justify-center self-center rounded-full motion-reduce:transition-none",$i.colors,$i.transform,{"[&>svg]:text-success-indicator":e==="success","[&>svg]:text-destructive-foreground":e==="failed","border border-dashed border-placeholder":e==="pending","[&>svg]:size-4":e!=="running","bg-success-subtle":e==="success","bg-destructive-subtle":e==="failed","scale-110":e==="success"||e==="failed"}),children:Htt(e)})}function uIs({step:e,isActive:t,position:n,variant:r="default"}){const s=t||e.status==="success"?"ink":"muted";return a.jsxs("div",{className:Z("grid grid-cols-[1fr_auto] gap-6 rounded-lg px-4 py-3 motion-reduce:transition-none",$i.colors,{"border border-transparent":r==="default","border-dashed border-placeholder bg-card":t&&r==="default"}),children:[a.jsxs("div",{className:"grid min-w-0 grid-cols-[auto_1fr] gap-2",children:[a.jsxs(Y,{as:"span",tone:s,className:Z("flex min-w-6 justify-end",$i.colors),children:[n,"."]}),a.jsxs("div",{className:"min-w-0",children:[a.jsx(Y,{as:"h4",tone:s,className:$i.colors,children:e.title}),e.description&&a.jsx(Y,{tone:"faint",className:Z("-mt-0.5",{truncate:r==="plain"}),children:e.description})]})]}),a.jsx(cIs,{status:e.status,variant:r})]})}function dIs({currentStep:e,steps:t=[],className:n}){return a.jsx("div",{className:Z(n),children:t.map((r,s)=>a.jsx(uIs,{step:r,isActive:e?.id===r.id,position:s+1},r.id))})}function fIs({steps:e}){const t=e.length,n=e.filter(r=>r.status==="success").length;return a.jsxs("div",{className:"flex w-full flex-col content-center justify-center gap-4",children:[a.jsx("div",{className:"grid w-full grid-cols-[0_repeat(9,1fr)]",children:e.map((r,s)=>a.jsx("div",{className:Z("relative flex h-8 items-center justify-end",$i.colors,{"bg-success-subtle":r.status==="success"&&e?.[s-1]?.status==="success"}),children:a.jsx("div",{className:Z("absolute right-0 z-10 flex size-8 translate-x-1/2 items-center justify-center self-center rounded-full bg-fill text-column text-muted-foreground motion-reduce:transition-none",$i.colors,$i.transform,{"border border-dashed border-placeholder":r.status==="pending","scale-110 bg-success-subtle text-success-subtle-foreground":r.status==="success","scale-110 bg-destructive-subtle text-destructive-subtle-foreground":r.status==="failed"}),children:r.status==="running"?a.jsx(En,{}):s+1})},r.id))}),a.jsxs("div",{className:Z("text-center text-caption text-muted-foreground",$i.colors),children:[n," of ",t," steps completed"]})]})}function hIs({name:e,streamResult:t,runId:n,workflowInfo:r}){const s=t?.phase||"initializing",i=t?.payload?.workflowState,o=t?.payload?.currentStep,l=t?.error,c=i?.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)),h=f.length,p=()=>{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:o?.id===v}));return a.jsxs(nee,{className:"mb-5 content-center space-y-6 text-muted-foreground",children:[a.jsxs("div",{className:"text-center",children:[a.jsx(Y,{as:"h3",variant:"heading",tone:"ink",children:p()}),(t?.runId||n)&&a.jsxs(Y,{as:"p",variant:"caption",tone:"muted",className:"mt-2",children:["Run ID: ",t?.runId??n]})]}),u&&h>0&&!["error"].includes(s)&&a.jsx("div",{className:"mx-auto w-full max-w-[30rem] px-4",children:a.jsx(fIs,{steps:m})}),l&&s==="error"&&a.jsxs("div",{className:Z("text-foreground","flex items-center gap-3 rounded-lg bg-destructive-subtle p-4","[&>svg]:h-6 [&>svg]:w-6 [&>svg]:text-destructive-foreground [&>svg]:opacity-70"),children:[a.jsx(fEn,{}),a.jsx(Y,{as:"span",variant:"body",className:"block",children:l||"Something went wrong"})]}),u&&a.jsx(dIs,{steps:m,currentStep:o,className:"pb-4"}),!u&&s==="initializing"&&a.jsxs("div",{className:Z("text-muted-foreground","grid justify-items-center gap-4 text-center"),children:[a.jsx(En,{}),a.jsx(Y,{as:"p",variant:"body",children:"This may take some time..."})]})]})}function pIs({name:e,installedEntities:t}){return a.jsxs(nee,{className:Z("grid content-center items-center justify-items-center gap-4","[&>svg]:h-8 [&>svg]:w-8"),children:[a.jsx(fht,{}),a.jsx(Y,{as:"h2",variant:"heading",children:"Done!"}),a.jsxs(Y,{tone:"muted",className:"text-center",children:["The ",a.jsx("b",{className:"text-muted-foreground",children:e})," template has been successfully installed.",t&&t.length>0&&a.jsxs(a.Fragment,{children:[a.jsx("br",{})," Installed entities are listed below."]})]}),t&&t.length>0&&a.jsx($Ie,{data:t})]})}function mIs(){const{templateSlug:e}=jr(),t=[{id:"templates",label:"Templates",to:"/templates"},{id:"template",label:xke(e)}],[n,r]=oi(),[s,i]=g.useState(""),[o,l]=g.useState(""),[c,u]=g.useState(""),[d,f]=g.useState({}),[h,p]=g.useState([]),[m,v]=g.useState(null),[y,x]=g.useState(!1),[b,S]=g.useState(""),[k,j]=g.useState(!1),[C,T]=g.useState(!1),[_,N]=g.useState([]),{data:I,isLoading:A}=UEs({repoOrSlug:e,owner:"mastra-ai"}),D=nIs?.includes("beta")??!1?"beta":"main",{data:F,isLoading:Q}=qEs({repo:I?.githubUrl?new URL(I.githubUrl).pathname.split("/")[2]:`template-${e}`,owner:"mastra-ai",branch:D}),{data:q,isLoading:B}=QEs(),{mutateAsync:V,isPending:H}=ZEs(),{mutateAsync:M}=WEs(),{streamInstall:G,streamResult:L,isStreaming:$}=GEs({workflowInfo:q}),{observeInstall:z,streamResult:U,isStreaming:K}=KEs({workflowInfo:q});g.useEffect(()=>{const re=n.get("runId");re&&!y&&!m&&!$&&!K&&(console.info("🔄 Checking completed run after hot reload:",{runId:re}),S(re),M({runId:re}).then(ae=>{const he=ae.snapshot;if(he?.status==="success"&&he?.result?.success)x(!0);else if(he?.result?.success===!1)if(he?.result?.validationResults&&!he?.result?.validationResults?.valid&&he?.result?.validationResults?.remainingErrors>0){const{remainingErrors:pe,errors:ke}=he.result.validationResults,Ee=`Template installation completed but ${pe} validation issue${pe>1?"s":""} remain unresolved.`;v(Ee),N(ke||[])}else{const pe=he?.result?.message||he?.result?.error||"Template installation failed";v(typeof pe=="string"?pe:String(pe))}}).catch(ae=>{console.error("❌ Failed to fetch run details:",ae),v("Failed to retrieve installation status after reload")}))},[n,y,m,$,K,M]),g.useEffect(()=>{const re=n.get("runId"),ae=n.get("resume"),he=n.get("provider");if(re&&ae==="true"&&he&&!$&&!K&&!k&&!C&&q){S(re),j(!0);try{M({runId:re}).then(ve=>{if(ve.snapshot?.status==="running")return z.mutateAsync({runId:re})}).then(()=>{r(ve=>{const pe=new URLSearchParams(ve);return pe.delete("resume"),pe})}).catch(ve=>{console.error("❌ Failed to resume template installation:",ve),ve.message?.includes("404")||ve.message?.includes("not found")?v("Template installation run not found. It may have expired or been completed."):v("Failed to resume template installation. Please try again.")})}catch(ve){console.error("❌ Auto-resume failed with error:",ve),v("Failed to resume template installation. Please refresh and try again.")}}},[n,e,$,K,k,C,q,M,z,r]);const ne=[{value:"openai",label:"OpenAI"},{value:"anthropic",label:"Anthropic"},{value:"groq",label:"Groq"},{value:"google",label:"Google"}],X=[{key:"tools",label:"Tools",value:I?.tools?.length?I.tools.map(re=>re).join(", "):"n/a",icon:a.jsx(ud,{})},{key:"agents",label:"Agents",value:I?.agents?.length?I.agents.map(re=>re).join(", "):"n/a",icon:a.jsx(ko,{})},{key:"workflows",label:"Workflows",value:I?.workflows?.length?I.workflows.map(re=>re).join(", "):"n/a",icon:a.jsx(dk,{})},{key:"providers",label:"Providers",value:I?.supportedProviders?.length?I.supportedProviders.join(", "):"n/a",icon:a.jsx(m0,{})},{key:"tags",label:"Tags",value:I?.tags?.length?I.tags.join(", "):"n/a",icon:a.jsx(uk,{})}],te=[{...X[0]},{...X[1]},{...X[2]}].filter(re=>re.value!=="n/a");g.useEffect(()=>{F&&f(F)},[F]),g.useEffect(()=>{const re=L||U;re?.phase==="error"&&re?.error&&v(typeof re.error=="string"?re.error:String(re.error))},[L?.phase,L?.error,U?.phase,U?.error]);const ie=re=>{i(re)},ue=async re=>(l(re.provider),u(re.modelId),{message:"Model updated successfully"}),ee=async()=>{const re=Object.entries(d).reduce((ae,[he,ve])=>(ve===""&&ae.push(he),ae),[]);if(re.length>0){p(re);return}if(I){v(null),x(!1),S(""),T(!0);try{const he={repo:I.githubUrl||`https://github.com/mastra-ai/template-${I.slug}`,ref:D,slug:I.slug,variables:d},{runId:ve}=await V({});S(ve),r(pe=>{const ke=new URLSearchParams(pe);return ke.set("runId",ve),ke.set("resume","true"),ke.set("provider",s||"openai"),ke}),await G.mutateAsync({inputData:he,selectedModel:{provider:o,modelId:c},runId:ve})}catch(ae){T(!1),v(ae?.message||"Template installation failed"),console.error("Template installation failed",ae)}}},se=re=>{const{name:ae,value:he}=re.target;he.trim()===""?p(ve=>[...ve,ae]):p(ve=>ve.filter(pe=>pe!==ae)),f(ve=>({...ve,[ae]:he}))};return a.jsxs(Et,{variant:"fit",breadcrumbs:a.jsx(Dt,{crumbs:t}),children:[a.jsx("h1",{className:"sr-only",children:e}),a.jsx("div",{className:Z("h-full w-full overflow-y-scroll lg:px-12"),children:a.jsxs("div",{className:"mx-auto grid w-full max-w-[80rem] gap-y-4 p-4",children:[a.jsx(aIs,{isLoading:A,title:I?.title,description:I?.longDescription,imageURL:I?.imageURL,githubUrl:I?.githubUrl,infoData:X,templateSlug:e}),I&&a.jsxs(a.Fragment,{children:[($||K)&&a.jsx(hIs,{name:I.title,streamResult:K?U:L,runId:b,workflowInfo:q}),y&&a.jsx(pIs,{name:I.title,installedEntities:te,linkComponent:lc}),m&&a.jsx(rIs,{errorMsg:m,validationErrors:_.length>0?_:L?.validationResults?.errors||U?.validationResults?.errors}),!$&&!K&&!y&&!m&&a.jsx(oIs,{providerOptions:ne,selectedProvider:s,onProviderChange:ie,variables:d,setVariables:f,errors:h,setErrors:p,handleInstallTemplate:ee,handleVariableChange:se,isLoadingEnvVars:Q||B,isInstalling:H,defaultModelProvider:o,defaultModelId:c,onModelUpdate:ue})]})]})})]})}const gIs=()=>a.jsx(Xt,{titleSlot:"No Workflows yet",descriptionSlot:a.jsxs(a.Fragment,{children:["Mastra workflows are not configured yet. ",a.jsx("br",{}),"More information in the documentation."]}),actionSlot:a.jsx(de,{variant:"ghost",render:a.jsx("a",{href:"https://mastra.ai/docs/workflows/overview",target:"_blank",rel:"noopener noreferrer"}),icon:a.jsx(Zs,{}),children:"Workflows Documentation"}),variant:"fill"});function vIs(e,t,n){return Pk(e,t,{name:r=>r.name,running:r=>n[r.id]?.running??0,suspended:r=>n[r.id]?.suspended??0,steps:r=>Object.keys(r.steps??{}).length})}function yIs(e){return Object.keys(e.steps??{}).filter(t=>e.allSteps?.[t]?.isWorkflow)}function xIs(e){const t=new Map;for(const[n,r]of Object.entries(e))t.set(n,n),r.name&&t.set(r.name,n);return t}function bIs(e,t,n){const r=xIs(t),s=[],i=(o,l,c,u,d,f)=>{const h=yIs(o).filter(v=>{const y=r.get(v);return y===void 0||!u.has(y)});if(s.push({kind:"workflow",workflow:o,pathKey:l,depth:c,nestedIds:h,guides:d,isLastChild:f}),!n.has(l)||h.length===0)return;const p=new Set(u).add(o.id),m=c===0?[]:[...d,!f];for(const[v,y]of h.entries()){const x=v===h.length-1,b=r.get(y);if(b===void 0){s.push({kind:"unregistered",stepId:y,description:o.allSteps?.[y]?.description,pathKey:`${l}/${y}`,depth:c+1,guides:m,isLastChild:x});continue}const S=t[b];S&&i({...S,id:b},`${l}/${b}`,c+1,p,m,x)}};for(const o of e)i(o,o.id,0,new Set([o.id]),[],!1);return s}const Gtt="auto 24rem minmax(0, 1fr) auto auto auto";function Sqt({guides:e,isLastChild:t}){return a.jsxs("span",{"aria-hidden":!0,className:"-my-6 flex shrink-0 self-stretch",children:[e.map((n,r)=>a.jsx("span",{className:Z("w-6",n&&"border-l border-border")},r)),a.jsxs("span",{className:"relative w-6",children:[a.jsx("span",{className:Z("absolute top-0 left-0 border-l border-border",t?"h-1/2":"h-full")}),a.jsx("span",{className:"absolute top-1/2 left-0 w-3.5 border-b border-border"})]})]})}function kqt({row:e,isExpanded:t,onToggle:n}){const r=e.kind==="workflow"&&e.nestedIds.length>0,s=e.kind==="workflow"?e.workflow.name:e.stepId;return a.jsx("div",{className:"flex items-center pl-5",children:r?a.jsx("button",{type:"button","aria-expanded":t,"aria-label":`${t?"Collapse":"Expand"} nested workflows of ${s}`,className:Z(Fn,"relative grid size-5 shrink-0 place-items-center before:absolute before:-inset-1.5 before:content-['']"),onClick:i=>{i.stopPropagation(),n()},children:a.jsx(Na,{direction:"right",className:"size-4"})}):a.jsx("span",{className:"size-5 shrink-0","aria-hidden":!0})})}const wIs=e=>e.stopPropagation();function F7({sortKey:e,sort:t,onSortChange:n,children:r}){return n?a.jsx(Te.SortableTopCell,{sortKey:e,sort:t?.key===e?t.direction:void 0,onSortChange:s=>n(s,e),children:r}):a.jsx(Te.TopCell,{children:r})}function SIs({row:e,isExpanded:t,onToggle:n,runCount:r,rowProps:s}){const{paths:i,Link:o}=xn(),l=g.useRef(null),{workflow:c,nestedIds:u}=e,d=uf(c.name,50),f=uf(c.description??"",200),h=Object.keys(c.steps??{}).length,p=r?.running??0,m=r?.suspended??0,v=u.length>0;return a.jsxs(Te.RowWrapper,{...s,onSelectRow:()=>l.current?.click(),children:[a.jsx(kqt,{row:e,isExpanded:t,onToggle:n}),a.jsxs(Te.RowLink,{ref:l,colStart:2,to:i.workflowLink(c.id),LinkComponent:o,tabIndex:-1,onClick:wIs,children:[a.jsx(Te.NameCell,{children:a.jsxs("span",{className:"flex items-center gap-1.5",children:[e.depth>0?a.jsx(Sqt,{guides:e.guides,isLastChild:e.isLastChild}):null,a.jsx("span",{className:"truncate",children:d}),c.origin==="dynamic"?a.jsx(Mt,{size:"xs",variant:"blue",title:"Registered via the dynamic-workflows API",children:"Dynamic"}):null,v?a.jsxs(Y,{as:"span",variant:"body-sm",tone:"muted",title:`Nested workflows: ${u.join(", ")}`,className:"inline-flex shrink-0 items-center gap-1",children:[a.jsx(dk,{"aria-hidden":!0,className:"size-3.5"}),u.length]}):null]})}),a.jsx(Te.DescriptionCell,{children:f}),a.jsx(Te.TextCell,{className:"text-center",children:p>0?a.jsxs("span",{className:"inline-flex items-center gap-1.5 text-info-indicator","aria-label":`${p} run${p===1?"":"s"} in progress`,children:[a.jsx("span",{"aria-hidden":!0,className:"size-2 rounded-full bg-info-indicator motion-safe:animate-pulse"}),p]}):""}),a.jsx(Te.TextCell,{className:"text-center",children:m>0?a.jsxs("span",{className:"inline-flex items-center gap-1.5 text-warning-foreground","aria-label":`${m} run${m===1?"":"s"} awaiting input`,children:[a.jsx(vS,{"aria-hidden":!0,className:"size-3.5"}),m]}):""}),a.jsx(Te.TextCell,{className:"text-center",children:h||""})]})]})}function kIs({workflows:e,isLoading:t,search:n="",sort:r,onSortChange:s,requestContext:i}){const[o,l]=g.useState(new Set),c=AMn({requestContext:i}),u=g.useMemo(()=>Object.entries(e).map(([x,b])=>({...b,id:x})),[e]),d=g.useMemo(()=>{const x=n.toLowerCase();return u.filter(b=>b.name?.toLowerCase().includes(x)||b.description?.toLowerCase().includes(x))},[u,n]),f=g.useMemo(()=>vIs(d,r,c),[d,r,c]),h=g.useMemo(()=>bIs(f,e,o),[f,e,o]),p=g.useMemo(()=>{const x=new Map;for(const b of h)b.kind==="workflow"&&x.set(b.pathKey,x.size);return x},[h]),{containerRef:m,getRowProps:v}=Du({count:p.size,global:!0}),y=x=>{l(b=>{const S=new Set(b);return S.has(x)?S.delete(x):S.add(x),S})};return t?a.jsx($u,{columns:Gtt,fit:"container"}):a.jsxs(Te,{columns:Gtt,fit:"container",scrollRef:m,children:[a.jsxs(Te.Top,{children:[a.jsx(Te.TopCell,{children:a.jsx("span",{className:"sr-only",children:"Expand"})}),a.jsx(F7,{sortKey:"name",sort:r,onSortChange:s,children:"Name"}),a.jsx(Te.TopCell,{children:"Description"}),a.jsx(F7,{sortKey:"running",sort:r,onSortChange:s,children:"Running"}),a.jsx(F7,{sortKey:"suspended",sort:r,onSortChange:s,children:"Pending input"}),a.jsx(F7,{sortKey:"steps",sort:r,onSortChange:s,children:"Number of steps"})]}),h.length===0&&n?a.jsx(Te.NoMatch,{message:"No Workflows match your search"}):null,h.map(x=>{const b=o.has(x.pathKey),S=()=>y(x.pathKey);return x.kind==="unregistered"?a.jsxs(Te.RowStatic,{className:"gap-0 px-0",children:[a.jsx(kqt,{row:x,isExpanded:b,onToggle:S}),a.jsxs("div",{className:"col-span-5 col-start-2 grid grid-cols-subgrid gap-4 px-3",children:[a.jsx(Te.NameCell,{children:a.jsxs("span",{className:"flex items-center gap-1.5",children:[a.jsx(Sqt,{guides:x.guides,isLastChild:x.isLastChild}),a.jsx("span",{className:"truncate",children:uf(x.stepId,50)}),a.jsxs(Ln,{children:[a.jsx(Rn,{render:a.jsx(Y,{as:"span",variant:"body-sm",tone:"muted"}),role:"note",tabIndex:0,className:Z("shrink-0 rounded-sm",Ri),children:"not registered"}),a.jsx(Mn,{className:"max-w-72",children:"Runs as a step of its parent workflow. Add it to the workflows of your Mastra instance to open, run, and inspect it on its own page."})]})]})}),a.jsx(Te.DescriptionCell,{children:uf(x.description??"",200)}),a.jsx(Te.TextCell,{className:"text-center",children:""}),a.jsx(Te.TextCell,{className:"text-center",children:""}),a.jsx(Te.TextCell,{className:"text-center",children:""})]})]},`workflow-${x.pathKey}`):a.jsx(SIs,{row:x,isExpanded:b,onToggle:S,runCount:c[x.workflow.id],rowProps:v(p.get(x.pathKey)??-1)},`workflow-${x.pathKey}`)})]})}const DM=[_s("/workflows")];function OIs(){const{data:e,isLoading:t,error:n}=Op(),[r,s]=g.useState(""),[i,o]=g.useState();return n&&js(n)?a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:DM}),children:[a.jsx("h1",{className:"sr-only",children:"Workflows"}),a.jsx(ai,{variant:"fill"})]}):n&&Cs(n)?a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:DM}),children:[a.jsx("h1",{className:"sr-only",children:"Workflows"}),a.jsx(Gs,{variant:"fill",resource:"workflows"})]}):n?a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:DM}),children:[a.jsx("h1",{className:"sr-only",children:"Workflows"}),a.jsx(Xt,{tone:"error",variant:"fill",titleSlot:"Failed to load workflows",descriptionSlot:n.message})]}):Object.keys(e||{}).length===0&&!t?a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:DM}),children:[a.jsx("h1",{className:"sr-only",children:"Workflows"}),a.jsx(gIs,{})]}):a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:DM}),actionRow:a.jsxs(Xn,{children:[a.jsx(Xn.Start,{children:a.jsx("div",{className:"max-w-120 flex-1",children:a.jsx(Ru,{onSearch:s,label:"Filter workflows",placeholder:"Filter by name or description"})})}),a.jsx(Xn.End,{children:a.jsx(de,{render:a.jsx(lc,{to:"/workflows/schedules"}),variant:"primary",icon:a.jsx(g0,{}),children:"Schedules"})})]}),children:[a.jsx("h1",{className:"sr-only",children:"Workflows"}),a.jsx(kIs,{workflows:e||{},isLoading:t,search:r,sort:i,onSortChange:(l,c)=>o({key:c,direction:l})})]})}const jIs={active:"bg-success-indicator",paused:"bg-info-indicator",completed:"bg-muted-foreground"},CIs={active:"text-success-indicator",paused:"text-info-indicator",completed:"text-muted-foreground"},Oqt=({status:e})=>a.jsxs("span",{className:"inline-flex items-center gap-2 whitespace-nowrap",children:[a.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${jIs[e]}`,"aria-hidden":!0}),a.jsx(Y,{as:"span",variant:"caption",className:CIs[e],children:e})]});function jqt({status:e}){const{icon:t,color:n}=_Is(e);return a.jsxs("span",{className:`inline-flex items-center gap-1.5 whitespace-nowrap ${n}`,children:[a.jsx("span",{className:"inline-flex shrink-0 items-center","aria-hidden":!0,children:t}),a.jsx(Y,{as:"span",variant:"caption",children:e})]})}function _Is(e){switch(e){case"success":return{icon:a.jsx(dr,{size:14}),color:"text-success-indicator"};case"failed":return{icon:a.jsx(Dn,{size:14}),color:"text-destructive-foreground"};case"running":return{icon:a.jsx(En,{}),color:"text-muted-foreground"};case"suspended":return{icon:a.jsx($H,{size:14}),color:"text-info-indicator"};case"canceled":return{icon:a.jsx(X3,{size:14}),color:"text-muted-foreground"};case"pending":case"waiting":return{icon:a.jsx(ON,{size:14}),color:"text-muted-foreground"};default:return{icon:null,color:"text-muted-foreground"}}}const Ktt="auto auto auto auto 1fr",TIs=3e4,EIs=5*6e4;function IIs({triggers:e,isLoading:t,workflowId:n,hasNextPage:r,isFetchingNextPage:s,setEndOfListElement:i}){const{Link:o,paths:l}=xn(),c=p=>!!(n&&p.runId&&p.outcome!=="failed"),u=e.filter(c).length,{containerRef:d,getRowProps:f}=Du({count:u});let h=-1;return t?a.jsx($u,{columns:Ktt}):e.length===0?a.jsx(Y,{variant:"body",tone:"muted",className:"p-4",children:"No trigger history yet."}):a.jsxs(Te,{columns:Ktt,className:"min-w-0",scrollRef:d,children:[a.jsxs(Te.Top,{children:[a.jsx(Te.TopCell,{children:"Run"}),a.jsx(Te.TopCell,{children:"Status"}),a.jsx(Te.TopCell,{children:"Started"}),a.jsx(Te.TopCell,{children:"Duration"}),a.jsx(Te.TopCell,{children:" "})]}),e.map(p=>{const m=p.actualFireAt-p.scheduledFireAt,v=sf(m,{signed:!0}),y=p.outcome==="failed",x=y?p.error:p.run?.error,b=Math.abs(m),S=!y&&b>TIs&&b<=EIs,k=`${p.scheduleId}-${p.runId}-${p.actualFireAt}`,j=c(p);j&&(h+=1);const C=a.jsx(Y,{as:"span",variant:"caption",font:"mono",tone:j?"ink":"muted",className:"whitespace-nowrap",children:p.runId}),T=a.jsxs(a.Fragment,{children:[a.jsx(Te.Cell,{children:C}),a.jsx(Te.Cell,{children:a.jsxs("span",{className:"inline-flex items-center gap-2",children:[y?a.jsxs(Y,{as:"span",variant:"caption",className:"inline-flex items-center gap-1.5 whitespace-nowrap text-destructive-foreground",children:[a.jsx(Yd,{size:14}),"publish failed"]}):p.run?a.jsx(jqt,{status:p.run.status}):a.jsx(Y,{as:"span",variant:"caption",tone:"muted",className:"inline-flex items-center gap-1.5 whitespace-nowrap",children:"pending"}),x?a.jsxs(Ln,{children:[a.jsx(Rn,{asChild:!0,children:a.jsx("span",{className:"inline-flex text-destructive-foreground",children:a.jsx(Yd,{size:14})})}),a.jsx(Mn,{children:x})]}):null]})}),a.jsx(Te.Cell,{children:a.jsxs("span",{className:"inline-flex items-center gap-2 whitespace-nowrap",children:[p.actualFireAt?a.jsx($I,{value:p.actualFireAt}):"—",S?a.jsxs(Ln,{children:[a.jsx(Rn,{asChild:!0,children:a.jsx("span",{className:"inline-flex text-info-indicator",children:a.jsx(Yd,{size:14})})}),a.jsxs(Mn,{children:["Published ",v," after the scheduled fire time"]})]}):null]})}),a.jsx(Te.Cell,{children:p.run?a.jsx(Y,{as:"span",variant:"body-sm",font:"mono",children:sf(p.run.durationMs)||"—"}):a.jsx("span",{className:"text-muted-foreground",children:"—"})}),a.jsx(Te.Cell,{children:" "})]});return j?a.jsx(Te.RowLink,{to:l.workflowRunLink(n,p.runId),LinkComponent:o,...f(h),children:T},k):a.jsx(Te.RowStatic,{children:T},k)}),a.jsx(Te.NextPageLoading,{isLoading:s,hasMore:r,setEndOfListElement:i})]})}const Cqt={id:"workflow-schedules",label:"Schedules",icon:g0,to:"/workflows/schedules"};function B7({label:e,children:t}){return a.jsxs("div",{className:"flex flex-col gap-1",children:[a.jsx(Y,{variant:"meta",tone:"muted",className:"uppercase",children:e}),a.jsx("div",{children:a.jsx(Y,{as:"span",variant:"body",className:"block",children:t})})]})}function NIs(){const{scheduleId:e}=jr(),t=[_s("/workflows"),Cqt,{id:"schedule",label:xke(e),icon:g0}],{paths:n}=xn(),{data:r,error:s}=vlr({scheduleId:e,queryOptions:{enabled:!!e}}),{data:i,isLoading:o,error:l,hasNextPage:c,isFetchingNextPage:u,setEndOfListElement:d}=ylr({scheduleId:e,queryOptions:{enabled:!!e}}),f=xlr({scheduleId:e});if(s&&js(s))return a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:t}),children:[a.jsx("h1",{className:"sr-only",children:e}),a.jsx(ai,{variant:"fill"})]});if(s&&Cs(s))return a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:t}),children:[a.jsx("h1",{className:"sr-only",children:e}),a.jsx(Gs,{variant:"fill",resource:"schedules"})]});if(s)return a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:t}),children:[a.jsx("h1",{className:"sr-only",children:e}),a.jsx(Xt,{tone:"error",variant:"fill",titleSlot:"Failed to load schedule",descriptionSlot:s.message})]});const h=r?.workflowId,p=r?.agentId;return a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:t}),actionRow:a.jsx(Xn,{children:a.jsxs(Xn.End,{children:[a.jsx(de,{render:a.jsx(lc,{to:n.schedulesLink()}),variant:"ghost",icon:a.jsx(md,{}),children:"Back to schedules"}),h?a.jsx(de,{icon:a.jsx(Ol,{}),render:a.jsx(lc,{to:n.workflowLink(h)}),variant:"ghost",children:"Open workflow"}):null,r?a.jsx(de,{onClick:()=>{const m=r.status==="active"?"pause":"resume";f.mutate(m,{onSuccess:()=>Ke.success(m==="pause"?"Schedule paused":"Schedule resumed"),onError:v=>Ke.error(v.message)})},disabled:f.isPending,"data-testid":"schedule-toggle-button",children:r.status==="active"?a.jsxs(a.Fragment,{children:[a.jsx(vS,{}),"Pause"]}):a.jsxs(a.Fragment,{children:[a.jsx(Bc,{}),"Resume"]})}):null]})}),children:[a.jsx("h1",{className:"sr-only",children:e}),r?a.jsxs("div",{className:"grid h-full grid-cols-[minmax(0,20rem)_1fr] gap-4 overflow-hidden",children:[a.jsxs("div",{className:"flex h-fit flex-col gap-4 rounded-md border border-border p-4",children:[a.jsx(B7,{label:p?"Agent":"Workflow",children:h?a.jsx(lc,{to:n.workflowLink(h),className:"text-foreground hover:underline",children:h}):p?a.jsx(lc,{to:n.agentLink(p),className:"text-foreground hover:underline",children:p}):"—"}),a.jsxs(B7,{label:"Cron",children:[a.jsx(Y,{as:"span",variant:"body",font:"mono",children:r.cron}),r.timezone?a.jsx(Y,{as:"span",variant:"caption",tone:"muted",className:"ml-2",children:r.timezone}):null]}),a.jsx(B7,{label:"Status",children:a.jsx(Oqt,{status:r.status})}),a.jsx(B7,{label:"Next fire",children:r.nextFireAt?a.jsx($I,{value:r.nextFireAt}):"—"})]}),a.jsxs("div",{className:"overflow-y-auto","data-testid":"schedule-triggers-panel",children:[a.jsx(Y,{variant:"body",className:"mb-3",children:"Trigger history"}),l?a.jsx(Xt,{tone:"error",titleSlot:"Failed to load trigger history",descriptionSlot:l.message}):a.jsx(IIs,{triggers:i??[],isLoading:o,workflowId:h,hasNextPage:c,isFetchingNextPage:u,setEndOfListElement:d})]})]}):null]})}const AIs={target:e=>e.workflowId??e.agentId??"",status:e=>e.status,nextFireAt:e=>e.nextFireAt,lastFireAt:e=>e.lastFireAt},Ytt="minmax(0, 1.2fr) minmax(0, 1.4fr) minmax(0, 1fr) auto auto auto";function PIs({schedules:e,isLoading:t,search:n="",sort:r,onSortChange:s}){const{paths:i,Link:o}=xn(),l=g.useMemo(()=>{const f=n.toLowerCase(),h=f?e.filter(p=>p.id.toLowerCase().includes(f)||(p.workflowId??p.agentId??"").toLowerCase().includes(f)):e;return Pk(h,r,AIs)},[e,n,r]),{containerRef:c,getRowProps:u}=Du({count:l.length,global:!0});if(t)return a.jsx($u,{columns:Ytt});const d=(f,h)=>s?a.jsx(Te.SortableTopCell,{sortKey:f,sort:r?.key===f?r.direction:void 0,onSortChange:s,children:h}):a.jsx(Te.TopCell,{children:h});return a.jsxs(Te,{columns:Ytt,className:"min-w-0",scrollRef:c,children:[a.jsxs(Te.Top,{children:[d("target","Target"),a.jsx(Te.TopCell,{children:"Schedule ID"}),a.jsx(Te.TopCell,{children:"Cron"}),d("status","Status"),d("nextFireAt","Next fire"),d("lastFireAt","Last run")]}),l.length===0&&n?a.jsx(Te.NoMatch,{message:"No schedules match your search"}):null,l.length===0&&!n?a.jsx(Te.NoMatch,{message:"No schedules configured"}):null,l.map((f,h)=>a.jsxs(Te.RowLink,{to:i.scheduleLink(f.id),LinkComponent:o,...u(h),children:[a.jsx(Te.NameCell,{children:f.workflowId??f.agentId}),a.jsx(Te.Cell,{className:"min-w-0",children:a.jsx(Y,{as:"span",variant:"body-sm",tone:"muted",font:"mono",className:"block truncate",title:f.id,children:f.id})}),a.jsx(Te.Cell,{children:a.jsxs("span",{className:"inline-flex items-center gap-2 whitespace-nowrap",children:[a.jsx(Y,{as:"span",variant:"caption",font:"mono",children:f.cron}),f.timezone?a.jsx(Y,{as:"span",variant:"meta",tone:"muted",children:f.timezone}):null]})}),a.jsx(Te.Cell,{children:a.jsx(Oqt,{status:f.status})}),a.jsx(Te.Cell,{children:f.nextFireAt?a.jsx($I,{value:f.nextFireAt}):"—"}),a.jsx(Te.Cell,{children:f.lastRun?a.jsxs("span",{className:"inline-flex items-center gap-2 whitespace-nowrap",children:[a.jsx(jqt,{status:f.lastRun.status}),f.lastFireAt?a.jsx(Y,{as:"span",variant:"caption",tone:"muted",children:a.jsx($I,{value:f.lastFireAt})}):null]}):f.lastFireAt?a.jsx($I,{value:f.lastFireAt}):a.jsx("span",{className:"text-muted-foreground",children:"Never"})})]},f.id))]})}function _qt({workflowId:e}={}){const{data:t,isLoading:n,error:r}=aK(e?{workflowId:e}:{}),[s,i]=g.useState(""),[o,l]=g.useState();return r?a.jsx(Xt,{tone:"error",titleSlot:"Failed to load schedules",descriptionSlot:r.message}):a.jsxs("div",{className:"grid h-full grid-rows-[auto_1fr] gap-4 overflow-hidden",children:[a.jsx("div",{className:"max-w-120",children:a.jsx(Ru,{onSearch:i,label:"Filter schedules",placeholder:"Filter by id or workflow"})}),a.jsx("div",{className:"overflow-y-auto",children:a.jsx(PIs,{schedules:t??[],isLoading:n,search:s,sort:o,onSortChange:(c,u)=>l({key:u,direction:c})})})]})}const xue=[_s("/workflows"),Cqt];function $Is(){const[e]=oi(),t=e.get("workflowId")??void 0,{error:n}=aK(t?{workflowId:t}:{});return n&&js(n)?a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:xue}),children:[a.jsx("h1",{className:"sr-only",children:"Schedules"}),a.jsx(ai,{variant:"fill"})]}):n&&Cs(n)?a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:xue}),children:[a.jsx("h1",{className:"sr-only",children:"Schedules"}),a.jsx(Gs,{variant:"fill",resource:"schedules"})]}):a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:xue}),children:[a.jsx("h1",{className:"sr-only",children:"Schedules"}),a.jsx("div",{className:"h-full",children:a.jsx(_qt,{workflowId:t})})]})}const RIs={"--belt-hue":"var(--warning-indicator)"};function MIs(e){const t=new Blob([JSON.stringify(e??null)]).size;return t<1024?`${t} B`:`${(t/1024).toFixed(1)} KB`}function DIs(e,t){if(e&&typeof e=="object"&&!Array.isArray(e)){const n=Object.keys(e),[r]=n;if(n.length===1&&r)return r}return t}function LIs({suspendedSteps:e,workflow:t,isStreaming:n,onResume:r}){return n||e.length===0?null:a.jsxs("section",{className:Z(nke,"pointer-events-auto relative isolate"),"data-testid":"workflow-suspended-steps","aria-label":"Step suspended",children:[a.jsxs("div",{className:"max-h-[calc(100cqh-64px)] overflow-y-auto overscroll-contain rounded-[inherit]",children:[a.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-border bg-background px-5 py-4",children:[a.jsxs(Y,{as:"h2",variant:"column",tone:"ink",className:"flex items-center gap-2",children:[a.jsx(At,{children:a.jsx($H,{})}),"Step suspended"]}),a.jsx(Mt,{variant:"orange",emphasis:"subtle",children:"Needs input"})]}),e.map(s=>{const i=t.allSteps[s.stepId];if(!i||i.isWorkflow)return null;const o=i?.resumeSchema?OS(rC(i.resumeSchema)):Nf(_n(),Bf());return a.jsx(zIs,{step:s,stepSchema:o,description:i.description,onResume:r},`${s.runId}-${s.stepId}`)})]}),a.jsx(a4t,{status:"ready",label:"Needs input",className:"before:hidden",style:RIs})]})}function zIs({step:e,stepSchema:t,description:n,onResume:r}){const[s,i]=g.useState(!1),[o,l]=g.useState(!1),c=async u=>{l(!0);try{await r({stepId:e.stepId.split("."),runId:e.runId,resumeData:u})}catch(d){Ke.error(d instanceof Error?d.message:"Error resuming workflow")}finally{l(!1)}};return a.jsxs("div",{className:"space-y-5 p-5 [&+&]:border-t [&+&]:border-border",children:[a.jsxs("div",{className:"space-y-2",children:[a.jsx(Y,{as:"p",variant:"subheading",tone:"ink",className:"break-words",children:e.stepId}),n&&a.jsx(Y,{as:"p",variant:"caption",tone:"muted",children:n})]}),e.suspendPayload!==void 0&&a.jsxs("div",{className:"space-y-2",children:[a.jsxs(Y,{as:"p",variant:"caption",tone:"muted",className:"flex items-center gap-2",children:[a.jsx(At,{children:a.jsx(tEn,{})}),"The step is asking"]}),a.jsxs(Kl,{open:s,onOpenChange:i,children:[a.jsxs(Cl,{className:Z(pr,"flex w-full items-center justify-between gap-2 rounded-lg px-3 py-2.5"),children:[a.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[a.jsx(At,{children:a.jsx(Na,{direction:"right",className:"text-muted-foreground"})}),a.jsx(Y,{as:"span",variant:"body",tone:"ink",className:"truncate",children:DIs(e.suspendPayload,e.stepId)})]}),a.jsx(Y,{as:"span",variant:"caption",tone:"muted",className:"shrink-0",children:MIs(e.suspendPayload)})]}),a.jsx(_l,{children:a.jsx("div",{"data-testid":"suspended-payload",className:"pt-2",children:a.jsx(Or,{value:JSON.stringify(e.suspendPayload,null,2),editable:!1,className:"w-full overflow-x-auto p-2",showCopyButton:!1})})})]})]}),a.jsxs("div",{className:"space-y-3",children:[a.jsxs(Y,{as:"p",variant:"caption",tone:"muted",className:"flex items-center gap-2",children:[a.jsx(At,{children:a.jsx(iEn,{})}),"Your response"]}),a.jsx("div",{className:"-mx-5",children:a.jsx(HSe,{schema:t,isSubmitLoading:o,submitButtonLabel:"Resume",submitButtonVariant:"primary",submitButtonIcon:a.jsx(Bc,{}),submitButtonFullWidth:!0,collapsible:!1,hideHeading:!0,hideInputTypeLabel:!0,onSubmit:c})})]})]})}function FIs({hidden:e,requestContext:t,canResume:n}){const{result:r,workflow:s,runId:i,isStreamingWorkflow:o}=g.useContext(Hl),l=Pgt(r,i),c=JFn(t),u=r?.status==="suspended"&&l.length>0&&!o;return!s||!u||!n?null:a.jsx("div",{hidden:e,"data-testid":"workflow-suspended-overlay",className:"pointer-events-none absolute top-12 right-2 z-30 w-95 max-w-[calc(100%-16px)] animate-in duration-300 fade-in-0 slide-in-from-top-2 motion-reduce:animate-none",children:a.jsx(LIs,{suspendedSteps:l,workflow:s,isStreaming:o,onResume:c})},i)}const Xtt={success:{label:"Completed",icon:dr},failed:{label:"Failed",icon:L0e},suspended:{label:"Needs input",icon:vS},waiting:{label:"Waiting",icon:v0},paused:{label:"Paused",icon:vS},skipped:{label:"Skipped",icon:xIn},running:{label:"Running",icon:fc},canceled:{label:"Canceled",icon:X3}},BIs={label:"Status unavailable",icon:RCn};function VIs({row:e,isSelected:t,isHovered:n,onSelectStep:r,onHoverStep:s,onOpenInput:i,onOpenOutput:o}){const l=Object.hasOwn(Xtt,e.status)?Xtt[e.status]:BIs,c=l.icon,u=oSe(e.status),d=e.stepId.slice(0,e.stepId.lastIndexOf(".")),f=e.isNestedEntry?e.stepId.slice(e.stepId.lastIndexOf(".")+1):e.stepId;return a.jsxs("div",{"data-testid":"workflow-timeline-row","data-workflow-step-key":e.stepId,onMouseEnter:()=>!e.isNestedEntry&&s(e.stepId),onMouseLeave:()=>!e.isNestedEntry&&s(null),className:Z("grid grid-cols-[minmax(130px,1fr)_minmax(64px,1fr)_56px_64px] items-center gap-3 rounded-md px-2 py-1","@max-[540px]/workflow-timeline:grid-cols-[minmax(0,1fr)_48px_64px] @max-[540px]/workflow-timeline:gap-x-1.5 @max-[540px]/workflow-timeline:gap-y-1 @max-[540px]/workflow-timeline:py-2",(t||n)&&"bg-fill-subtle"),children:[a.jsxs("button",{type:"button","aria-disabled":e.isNestedEntry,"aria-pressed":t,onClick:()=>{e.isNestedEntry||r(e.stepId)},title:e.stepId,className:Z("text-foreground","flex min-h-9 min-w-0 cursor-pointer items-center gap-2.5 text-left focus-visible:rounded-sm aria-disabled:cursor-default",Ri),children:[a.jsx("span",{"aria-label":l.label,className:Z("grid size-6 flex-none place-items-center rounded-md border border-border bg-background",Awt[u]),children:a.jsx(c,{"aria-hidden":!0,className:Z("size-3.5",e.status==="running"&&"motion-safe:animate-spin")})}),a.jsxs("span",{className:"min-w-0",children:[a.jsx(Y,{as:"span",variant:"meta",className:"block truncate",children:f}),e.isNestedEntry&&a.jsxs(Y,{as:"span",variant:"meta",tone:"muted",className:"flex min-w-0 items-center gap-1",children:[a.jsx(B0e,{"aria-hidden":!0,className:"size-3 shrink-0"}),a.jsx("span",{className:"truncate",children:d})]})]})]}),a.jsx("div",{className:"relative h-5 min-w-0 overflow-hidden rounded-sm bg-muted @max-[540px]/workflow-timeline:col-span-full @max-[540px]/workflow-timeline:row-start-2 @max-[540px]/workflow-timeline:ml-[34px]","aria-hidden":!0,children:e.timing&&a.jsx("div",{"data-testid":"workflow-timeline-bar","data-offset":e.timing.offsetPct,"data-width":e.timing.widthPct,className:Z("absolute top-0 h-full min-w-0.5 rounded-sm",qYn[u]),style:{left:`${e.timing.offsetPct}%`,width:`${e.timing.widthPct}%`}})}),a.jsx(Y,{as:"span",variant:"meta",tone:"muted",className:"text-right whitespace-nowrap",title:e.timing&&e.spansSuspension?"Includes time spent suspended waiting for input":void 0,children:e.timing?a.jsx(Y,{as:"span",variant:"meta",font:"mono",children:sf(e.timing.durationMs)}):a.jsx("span",{"aria-label":"Timing unavailable",children:"—"})}),a.jsxs("div",{className:"flex items-center",children:[a.jsx(de,{type:"button",variant:"ghost",size:"icon-sm",tooltip:"View step input",disabled:e.step.input===void 0,onClick:h=>i(e,h.currentTarget),children:a.jsx(IH,{})}),a.jsx(de,{type:"button",variant:"ghost",size:"icon-sm",tooltip:"View step output",disabled:e.step.output===void 0,onClick:h=>o(e,h.currentTarget),children:a.jsx(AH,{})})]})]})}const UIs=e=>e.includes("."),qIs=e=>e==="input"||e.endsWith(".input"),Jtt=1;function QIs(e,t){const n=aSe(e),r=n?.isLive?Math.max(t,n.start):n?.end;return{span:n&&r!==void 0?{start:n.start,end:r}:void 0,isLive:n?.isLive??!1,spansSuspension:n?.spansSuspension??!1}}function ZIs(e,t){const n=Object.entries(e).filter(([l])=>!qIs(l)).map(([l,c])=>({stepId:l,step:c,...QIs(c,t)})).sort((l,c)=>(l.span?.start??1/0)-(c.span?.start??1/0)||l.stepId.localeCompare(c.stepId)),r=n.flatMap(l=>l.span?[l.span]:[]),s=Math.min(...r.map(l=>l.start)),i=Math.max(s,...r.map(l=>l.end)),o=Math.max(i-s,1);return n.map(({stepId:l,step:c,span:u,isLive:d,spansSuspension:f})=>{let h;if(u){const p=u.end-u.start,m=Math.min((u.start-s)/o*100,100-Jtt),v=Math.min(Math.max(p/o*100,Jtt),100-m);h={durationMs:p,offsetPct:m,widthPct:v}}return{stepId:l,step:c,status:FG(c)?"suspended":c.status,timing:h,spansSuspension:f,isRunning:d,isNestedEntry:UIs(l)}})}function WIs(){const{steps:e}=u$(),{selectedStepId:t,hoverStepId:n,setSelectedStepId:r,setHoverStepId:s}=JH(),[i,o]=g.useState(()=>Date.now()),[l,c]=g.useState(!0),[u,d]=g.useState(!1),{showData:f}=bk(),h=g.useRef(null),p=ZIs(e,i),m=p.some(v=>v.isRunning);return fSt(h,{enabled:m&&!l}),g.useEffect(()=>{if(!m||l)return;const v=setInterval(()=>o(Date.now()),100);return()=>clearInterval(v)},[m,l]),p.length===0?null:a.jsx("div",{"data-testid":"workflow-timeline",className:"relative z-20 shrink-0 px-2 pb-2",children:a.jsxs(Kl,{open:!l,onOpenChange:v=>c(!v),className:Z(pr,"@container/workflow-timeline pointer-events-auto overflow-hidden rounded-xl"),children:[a.jsxs("div",{className:"flex items-center",children:[a.jsxs(Cl,{className:"flex min-h-11 min-w-0 flex-1 items-center gap-2 px-3.5 py-2.5 text-caption text-foreground hover:bg-fill-subtle","aria-label":l?"Expand timeline":"Collapse timeline",children:[a.jsx("span",{children:a.jsx(Vft,{"aria-hidden":!0,className:"size-4 text-muted-foreground"})}),a.jsx("span",{children:"Timeline"}),a.jsxs(Y,{as:"span",variant:"meta",tone:"muted",children:[p.length," events"]}),a.jsx("span",{className:"ml-auto",children:a.jsx(Na,{direction:"right",className:"size-4"})})]}),!l&&a.jsx(de,{variant:"ghost",size:"icon-sm",tooltip:u?"Restore timeline height":"Enlarge timeline","aria-pressed":u,onClick:()=>d(!u),className:"mr-2 shrink-0",children:u?a.jsx(xCn,{}):a.jsx(qft,{})})]}),a.jsx(_l,{children:a.jsx("div",{ref:h,"data-testid":"workflow-timeline-list",className:Z("overflow-auto overscroll-contain px-1.5 pb-1.5",u?"max-h-[min(720px,calc(100dvh-112px))]":"max-h-[min(320px,40dvh)]"),children:p.map(v=>a.jsx(VIs,{row:v,isSelected:t===v.stepId,isHovered:n===v.stepId,onSelectStep:r,onHoverStep:s,onOpenInput:(y,x)=>f({type:"step-input",stepId:y.stepId},x),onOpenOutput:(y,x)=>f({type:"step-output",stepId:y.stepId},x)},v.stepId))})})]})})}const HIs=({workflowId:e,workflow:t,isLoading:n})=>{const[r]=xr("workflow",e),{canExecute:s,isLoading:i}=Wa(),{stepDetail:o}=bk(),l=TP(),c=o?.type==="data",u=a.jsxs("div",{className:"[container-type:size] relative h-full min-h-0",children:[a.jsx(O4t,{workflowId:e,workflow:t,isLoading:n,requestContext:r}),a.jsx(FIs,{hidden:c,requestContext:r,canResume:!i&&s("workflows")}),c&&a.jsx("div",{className:"pointer-events-auto absolute top-12 right-2 z-30 flex max-h-[calc(100cqh-64px)] w-[440px] max-w-[calc(100%-16px)] flex-col",children:a.jsx(oV,{requestContext:r})}),a.jsx("div",{className:"pointer-events-none absolute right-0 bottom-0 left-[var(--workflow-left-panel-width,0px)] z-20",children:a.jsx(WIs,{})})]});return l&&o&&!c?a.jsx("div",{className:"h-full min-h-0 overflow-hidden",children:a.jsx(oV,{requestContext:r})}):a.jsxs("div",{className:"relative h-full min-h-0",children:[u,a.jsxs(m$,{className:"pointer-events-none absolute inset-0 z-30 min-h-0 w-full min-w-0 p-2",children:[a.jsx(lp,{id:"workflow-graph",className:"pointer-events-none min-w-0"}),o&&!c&&a.jsxs(a.Fragment,{children:[a.jsx(YS,{className:"pointer-events-auto"}),a.jsx(lp,{id:"workflow-step-detail",minSize:300,maxSize:"60%",defaultSize:420,className:"min-w-0",children:a.jsx("div",{className:"pointer-events-auto h-full min-h-0 overflow-hidden rounded-studio-panel border border-border bg-background",children:a.jsx(oV,{requestContext:r})})})]})]})]})},ent=()=>{const{workflowId:e}=jr(),{data:t,isLoading:n,error:r}=lL({workflowId:e,requestContext:xr("workflow",e)[0],queryOptions:{enabled:!!e}});return r&&js(r)?a.jsx(ai,{variant:"fill"}):r&&Cs(r)?a.jsx(Gs,{variant:"fill",resource:"workflows"}):a.jsx(HIs,{workflowId:e,workflow:t??void 0,isLoading:n})};function GIs(){const{workflowId:e}=jr(),{error:t}=aK(e?{workflowId:e}:{});if(!e)return null;let n;return t&&js(t)?n=a.jsx(ai,{variant:"fill"}):t&&Cs(t)?n=a.jsx(Gs,{variant:"fill",resource:"schedules"}):n=a.jsx("div",{className:"h-full",children:a.jsx(_qt,{workflowId:e})}),a.jsxs(Et,{children:[a.jsx("h1",{className:"sr-only",children:"Schedules"}),n]})}function KIs(){const{workflowId:e}=jr();return e?a.jsx(ZNe,{scopedEntityId:e,scopedEntityType:sd.WORKFLOW_RUN}):null}const Tqt=g.createContext(null);function Jc(){const e=g.useContext(Tqt);if(!e)throw new Error("Workspace components must be rendered inside <Workspace.Root>");return e}const YIs=e=>e?.status;function XIs(e,t){return js(e)?"Your session has expired. Sign in again to continue.":Cs(e)?"You don't have permission to access this.":kk(e)?"This path no longer exists.":YIs(e)===501?"This workspace does not support this operation.":t}function ree({error:e,fallback:t,className:n}){return a.jsx(Ht,{variant:"destructive",className:n,children:a.jsx(Ht.Message,{children:XIs(e,t)})})}const JIs=/^---\r?\n([\s\S]*?)\r?\n---[ \t]*(?:\r?\n|$)/;function eNs(e){const t=JIs.exec(e);return t?{frontmatter:t[1]??"",body:e.slice(t[0].length)}:{frontmatter:null,body:e}}function tNs({content:e}){const{frontmatter:t,body:n}=eNs(e);return a.jsxs(a.Fragment,{children:[t!==null&&a.jsx("div",{"data-testid":"workspace-frontmatter",className:"border-b border-border",children:a.jsx(n$,{code:t,lang:"yaml",overflow:"wrap",className:"rounded-none border-0 bg-transparent [&_pre]:p-4"})}),a.jsx("div",{className:"p-4",children:a.jsx(pc,{children:n})})]})}function nNs(){const{activeFilePath:e}=Jc();return e?a.jsx(Y,{as:"span",variant:"body-sm",font:"mono",tone:"muted",className:"truncate","data-testid":"workspace-file-path",children:e}):null}function rNs({path:e,content:t,mimeType:n}){return u$t(e,n)?a.jsx("div",{className:"flex justify-center p-4",children:a.jsx("img",{src:`data:${n||"image/png"};base64,${t}`,alt:e.split("/").pop(),className:"max-w-full object-contain"})}):d$t(e,n)?a.jsx("div",{className:"flex justify-center p-4",children:a.jsx("video",{controls:!0,"aria-label":e.split("/").pop(),className:"max-w-full",children:a.jsx("source",{src:`data:${YHe(e,n)};base64,${t}`,type:YHe(e,n)})})}):vLr(e)?a.jsx(tNs,{content:t}):a.jsx(n$,{code:t,lang:Ckt(e),overflow:"scroll",className:"rounded-none border-0 bg-transparent [&_pre]:p-4"})}function sNs({renderPreview:e}){const{workspaceId:t,activeFilePath:n}=Jc(),{data:r,isLoading:s,error:i}=CLr({workspaceId:t,path:n,queryOptions:{enabled:!!n}});if(!n)return null;if(s)return a.jsxs("div",{"aria-busy":"true",className:"flex flex-col gap-2 p-4",children:[a.jsx(xt,{className:"h-4 w-1/2"}),a.jsx(xt,{className:"h-4 w-5/6"}),a.jsx(xt,{className:"h-4 w-2/3"})]});if(!r)return a.jsx(ree,{error:i,fallback:"Could not load file.",className:"m-4"});const o={path:n,content:r.content,mimeType:r.mimeType};return e?.(o)??a.jsx(rNs,{...o})}const VA=".",Eqt=(e,t)=>e===VA?t:`${e}/${t}`,tnt=e=>e.split("/").slice(0,-1).map((t,n,r)=>r.slice(0,n+1).join("/")),Iqt=e=>{const t=e.lastIndexOf("/");return t===-1?VA:e.slice(0,t)};function Nqt({labeled:e=!1}={}){const{workspaceId:t,onCreateDirectory:n,isReadOnly:r}=Jc(),s=mr(),[i,o]=g.useState(!1),[l,c]=g.useState(""),[u,d]=g.useState(!1);if(!n||r(VA))return null;const f=l.trim().replace(/^\.?\/+|\/+$/g,""),h=async()=>{if(f){d(!0);try{await n(f),await s.invalidateQueries({queryKey:["workspace",t,"fs","list",Iqt(f)]}),o(!1),c("")}catch{}finally{d(!1)}}};return a.jsxs(a.Fragment,{children:[e?a.jsx(de,{variant:"ghost",icon:a.jsx(mS,{}),onClick:()=>o(!0),children:"New folder"}):a.jsx(de,{variant:"ghost",size:"icon-sm",tooltip:"New folder",onClick:()=>o(!0),children:a.jsx(mS,{})}),a.jsx(rs,{open:i,onOpenChange:o,pending:u,children:a.jsx(ss,{size:"sm",children:a.jsxs("form",{onSubmit:p=>{p.preventDefault(),h()},children:[a.jsx(es,{children:a.jsx(Gr,{children:"New folder"})}),a.jsx(Hr,{children:a.jsx(Sn,{autoFocus:!0,"aria-label":"Folder path",placeholder:"docs/guides",value:l,onChange:p=>c(p.target.value)})}),a.jsxs(Yo,{children:[a.jsx(Ca,{children:"Cancel"}),a.jsx(de,{type:"submit",variant:"primary",disabled:!f||u,children:"Create"})]})]})})})]})}function nnt(e){return`${e.topSource}/${e.name}`}function rnt(e){const t=f$t(e.topSource,e.name);return t?`${t.owner}/${t.repo}/${e.name}`:null}function iNs({open:e,onOpenChange:t,workspaceId:n,onInstall:r,isInstalling:s,installedSkillIds:i=[],installedSkillNames:o=[],writableMounts:l,installedSkillPaths:c}){const[u,d]=g.useState(""),[f,h]=g.useState(null),[p,m]=g.useState(),v=l?.some(Q=>Q.path===p)?p:l?.[0]?.path,{data:y,isLoading:x}=xLr({workspaceId:n,queryOptions:{enabled:!!n}}),b=yLr({workspaceId:n}),S=g.useMemo(()=>f?.topSource?f$t(f.topSource,f.name):null,[f]),k=g.useMemo(()=>!S||!f?null:`https://skills.sh/${S.owner}/${S.repo}/${f.name}`,[S,f]),{data:j,isLoading:C}=bLr({workspaceId:n,owner:S?.owner,repo:S?.repo,skillPath:f?.name,queryOptions:{enabled:!!n&&!!S&&!!f}}),T=Y0(Q=>{Q.trim().length>=2&&b.mutate(Q)},300),_=g.useCallback(Q=>{d(Q),T(Q)},[T]),N=g.useMemo(()=>u.trim().length>=2?b.data?.skills??[]:y?.skills??[],[u,b.data,y]),I=b.isPending,A=u.trim().length>=2,P=g.useMemo(()=>{if(!f)return!1;const Q=rnt(f);return!!(Q&&i.includes(Q)||o.includes(f.name))},[f,i,o]),D=g.useCallback(()=>{!f||!S||r({repository:`${S.owner}/${S.repo}`,skillName:f.name,mount:l&&l.length>1?v:void 0})},[f,S,r,l,v]),F=g.useCallback(Q=>{Q||(d(""),h(null),m(void 0)),t(Q)},[t]);return a.jsx(rs,{open:e,onOpenChange:F,pending:s,children:a.jsxs(ss,{size:"xl",className:"h-[80vh]",children:[a.jsxs(es,{children:[a.jsx(Gr,{children:"Add Skill"}),a.jsx(zo,{children:"Search and install skills from the community registry"})]}),a.jsxs(Hr,{layout:"fill",children:[a.jsx(qc,{label:"Search skills",placeholder:"Search skills...",value:u,onValueChange:_}),a.jsxs("div",{className:"flex min-h-0 flex-1 gap-4",children:[a.jsxs("div",{className:"flex min-h-0 w-1/2 flex-col",children:[a.jsx(Y,{as:"p",variant:"eyebrow",tone:"muted",className:"mb-2",children:A?"Search Results":"Popular Skills"}),a.jsx(Nr,{className:"flex-1 rounded-lg border border-border",children:a.jsx(af,{className:!x&&!I&&N.length===0?"flex flex-col [&>div]:flex [&>div]:flex-1 [&>div]:flex-col":void 0,children:x||I?a.jsx("div",{className:"flex items-center justify-center py-5",children:a.jsx(fc,{className:"size-6 animate-spin text-muted-foreground"})}):N.length===0?a.jsxs("div",{className:"flex flex-1 flex-col items-center-safe justify-center-safe py-5 text-muted-foreground",children:[a.jsx(X3,{className:"mb-2 size-8"}),a.jsx(Y,{children:A?"No skills found":"No skills available"})]}):a.jsx("div",{className:"space-y-1 p-2",children:N.map(Q=>{const q=nnt(Q),B=rnt(Q),V=B&&i.includes(B)||o.includes(Q.name),H=f?nnt(f):null;return a.jsx("button",{onClick:()=>h(Q),className:Z("w-full rounded-md px-3 py-2 text-left","hover:bg-fill-subtle",H===q&&"border border-border-strong bg-fill-hover"),children:a.jsxs("div",{className:"flex items-start justify-between gap-2",children:[a.jsxs("div",{className:"min-w-0 flex-1",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(Y,{as:"span",variant:"subheading",tone:"ink",className:"truncate",children:Q.name}),V&&a.jsxs(Y,{as:"span",variant:"meta",className:"inline-flex items-center gap-1 rounded bg-info-subtle px-1.5 py-0.5 text-info-subtle-foreground",children:[a.jsx(dr,{className:"size-2.5"}),"Installed"]})]}),a.jsx(Y,{as:"p",variant:"caption",tone:"muted",className:"truncate",children:Q.topSource})]}),a.jsxs("div",{className:"flex shrink-0 items-center gap-1 text-muted-foreground",children:[a.jsx(hp,{className:"size-3"}),a.jsx(Y,{as:"span",variant:"caption",children:Q.installs.toLocaleString()})]})]})},q)})})})})]}),a.jsxs("div",{className:"flex min-h-0 w-1/2 flex-col",children:[a.jsx(Y,{as:"p",variant:"eyebrow",tone:"muted",className:"mb-2",children:"Preview"}),a.jsx("div",{className:"flex flex-1 flex-col overflow-hidden rounded-lg border border-border",children:f?a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"border-b border-border bg-card p-4",children:a.jsxs("div",{className:"flex items-start gap-3",children:[a.jsx("div",{className:"rounded-lg bg-muted p-2",children:a.jsx(T6,{className:"size-5 text-muted-foreground"})}),a.jsxs("div",{className:"min-w-0 flex-1",children:[a.jsx(Y,{as:"h3",variant:"subheading",tone:"ink",className:"truncate",children:f.name}),a.jsxs("div",{className:"mt-1 flex items-center gap-3 text-muted-foreground",children:[a.jsxs("span",{className:"flex items-center gap-1",children:[a.jsx(oX,{className:"size-3"}),a.jsx(Y,{as:"span",variant:"caption",className:"block",children:f.topSource})]}),a.jsxs("span",{className:"flex items-center gap-1",children:[a.jsx(hp,{className:"size-3"}),a.jsxs(Y,{as:"span",variant:"caption",className:"block",children:[f.installs.toLocaleString()," installs"]})]})]})]}),S&&a.jsx("a",{href:`https://github.com/${S.owner}/${S.repo}`,target:"_blank",rel:"noopener noreferrer",className:Z(Fn,jn),title:"View on GitHub",children:a.jsx(Zs,{className:"size-4"})})]})}),C?a.jsx("div",{className:"flex flex-1 items-center justify-center",children:a.jsx(fc,{className:"size-6 animate-spin text-muted-foreground"})}):j?a.jsx(Nr,{className:"flex-1",children:a.jsx("div",{className:"p-4",children:a.jsx(pc,{children:j})})}):a.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center text-muted-foreground",children:[a.jsx(F1,{className:"mb-2 size-8"}),a.jsx(Y,{children:"Preview unavailable"}),k&&a.jsxs("a",{href:k,target:"_blank",rel:"noopener noreferrer",className:"mt-2 flex items-center gap-1 text-info-indicator hover:underline",children:[a.jsxs(Y,{as:"span",variant:"caption",className:"block",children:["View on skills.sh"," "]}),a.jsx(Zs,{className:"size-3"})]})]})]}):a.jsxs("div",{className:"flex h-full flex-col items-center justify-center text-muted-foreground",children:[a.jsx(F1,{className:"mb-2 size-8"}),a.jsx(Y,{children:"Select a skill to preview"})]})})]})]}),f&&l&&l.length>1&&a.jsxs(ft,{orientation:"horizontal",className:Z(pr,"gap-3 rounded-lg p-3"),children:[a.jsx(fP,{className:"size-4 shrink-0 text-muted-foreground"}),a.jsx(ut,{className:"whitespace-nowrap",children:"Install to"}),a.jsxs(Vr,{value:v,onValueChange:m,children:[a.jsx(qr,{className:"flex-1",children:a.jsx(Ur,{})}),a.jsx(Qr,{children:l.map(Q=>{const q=Q.displayName??Q.name??Q.provider??"unknown";return a.jsxs(ir,{value:Q.path,children:[q," (",Q.path,")"]},Q.path)})})]})]})]}),f&&a.jsxs(Yo,{children:[P&&l&&l.length>1&&(()=>{const Q=c?.[f.name];if(!Q)return null;const q=l.find(B=>Q.startsWith(B.path+"/")||Q===B.path);return q?a.jsxs(Y,{as:"span",variant:"caption",tone:"muted",className:"mr-auto",children:["Installed at ",q.path]}):null})(),a.jsx(Ca,{children:"Cancel"}),a.jsx(ja,{onConfirm:D,disabled:!S||P,"data-testid":"install-skill-button",children:s?"Installing...":P?"Already Installed":"Install"})]})]})})}function Aqt({labeled:e=!1}){const{workspaceId:t,addSkill:n}=Jc(),[r,s]=g.useState(!1),[i,o]=g.useState(!1);if(!n)return null;const{onInstall:l,...c}=n,u=async d=>{o(!0);try{await l(d),s(!1)}catch{}finally{o(!1)}};return a.jsxs(a.Fragment,{children:[e?a.jsxs(de,{variant:"ghost",onClick:()=>s(!0),children:[a.jsx(bfe,{}),"Add skill"]}):a.jsx(de,{variant:"ghost",size:"icon-sm","aria-label":"Add skill",tooltip:"Add skill",onClick:()=>s(!0),children:a.jsx(bfe,{})}),a.jsx(iNs,{...c,open:r,onOpenChange:s,workspaceId:t,onInstall:d=>{u(d)},isInstalling:i})]})}function oNs({workspaceId:e,activeFilePath:t,onDelete:n,onCreateDirectory:r,onActiveFileChange:s,readOnlyPaths:i,searchFiles:o=!0,searchSkills:l=!0,fileCount:c,skillCount:u,addSkill:d,children:f}){const[h,p]=g.useState(!1),[m,v]=g.useState(""),[y,x]=g.useState(()=>new Set(tnt(t??""))),[b,S]=g.useState(t);if(t!==b){S(t);const C=tnt(t??"").filter(T=>!y.has(T));C.length>0&&x(new Set([...y,...C]))}const k=i?.join(`
|
|
699
|
+
`).reduce((i,o)=>{if(!o||o.startsWith("#"))return i;const[l,c]=o.split("=");return l&&(i[l]=c?.split("")?.every(u=>u==="*")?"":c?.replaceAll('"',"")),i},{}):{}}const VEs=({queryOptions:e}={})=>_t({queryKey:["mastra-templates"],queryFn:xqt,...e}),UEs=({repoOrSlug:e,owner:t,queryOptions:n})=>_t({queryKey:["template-repo",e,t],queryFn:()=>FEs({repoOrSlug:e,owner:t}),...n}),qEs=({repo:e,owner:t,branch:n,queryOptions:r})=>_t({queryKey:["template-repo-env-vars",e,t,n],queryFn:()=>BEs({repo:e,owner:t,branch:n}),...r}),QEs=({queryOptions:e}={})=>{const t=Ye();return _t({queryKey:["agent-builder-workflow"],queryFn:async()=>await t.getAgentBuilderAction("merge-template").details(),...e})},ZEs=({queryOptions:e}={})=>{const t=Ye();return kn({mutationFn:async({runId:n})=>await t.getAgentBuilderAction("merge-template").createRun({runId:n}),...e})},WEs=({queryOptions:e}={})=>{const t=Ye();return kn({mutationFn:async({runId:n})=>await t.getAgentBuilderAction("merge-template").runById(n),...e})},Ztt=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)},Wtt=(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((s,i)=>(s[i]={id:i,description:n.allSteps[i].description,status:"pending"},s),{})}}),e.type==="start"||e.type==="workflow-start"){const s={};n?.allSteps&&Object.entries(n.allSteps).forEach(([o,l])=>{s[o]={id:l.id,description:l.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:s},currentStep:null}}}if(e.type==="step-start"||e.type==="workflow-step-start"){const s=e.payload.id;r={...r,phase:"processing",payload:{...r.payload,currentStep:{id:s,status:"running",startTime:new Date,...e.payload},workflowState:{...r.payload.workflowState,steps:{...r.payload.workflowState.steps,[s]:{...r.payload.workflowState.steps[s],status:"running",startTime:new Date,...e.payload}}}}}}if(e.type==="step-result"||e.type==="workflow-step-result"){const s=e.payload.id,i=e.payload.status,o=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,[s]:{...r.payload.workflowState.steps[s],status:e.payload.status,output:e.payload.output,error:e.payload.error,endTime:new Date}}}}},i==="failed"&&o){const l=Ztt(o);r={...r,status:"failed",error:l,phase:"error",failedStep:{id:s,error:l,description:e.payload.description||s},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 s=Ztt(e.payload.error);r={...r,status:"failed",error:s,phase:"error",payload:{...r.payload,workflowState:{...r.payload.workflowState,status:"failed"}},errorTimestamp:new Date}}return{newState:r}},HEs=(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)}},bqt=(e,t)=>{const[n,r]=g.useState({}),[s,i]=g.useState(!1);return{streamResult:n,isStreaming:s,processStream:async(l,c)=>{if(i(!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:h}=await u.read();if(f)break;const{newState:p}=Wtt(h,d,e);if(d=p,r(p),h.runId||c||t){const m=h.runId||c||t;HEs(m,p)}}}catch(f){console.error("💥 [processStream] Error processing template installation stream:",f);const{newState:h}=Wtt({type:"error",payload:{error:f instanceof Error?f.message:"Unknown error"}},d,e);r(h)}finally{i(!1),u.releaseLock()}}}},GEs=({workflowInfo:e,queryOptions:t}={})=>{const n=Ye(),{streamResult:r,isStreaming:s,processStream:i}=bqt(e);return{streamInstall:kn({mutationFn:async({inputData:o,selectedModel:l,runId:c})=>{for(let d=1;d<=3;d++)try{const f=n.getAgentBuilderAction("merge-template"),h=new t_;h.set("selectedModel",l);const p=await f.stream({inputData:o,requestContext:h},c);await i(p,c);return}catch(f){console.error(`💥 [streamInstall] Attempt ${d} failed:`,f);const h=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),h){const p=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:",p),new Error(p)}throw console.error("❌ [streamInstall] Non-network error or max retries reached, throwing:",f),f}},...t?.streamInstall}),streamResult:r,isStreaming:s}},KEs=({workflowInfo:e,queryOptions:t}={})=>{const n=Ye(),{streamResult:r,isStreaming:s,processStream:i}=bqt(e);return{observeInstall:kn({mutationFn:async({runId:o})=>{for(let u=1;u<=3;u++)try{const d=await n.getAgentBuilderAction("merge-template").observeStream({runId:o});await i(d,o);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(h=>setTimeout(h,2e3));continue}throw console.error("❌ [observeInstall] Non-network error or max retries reached, throwing:",d),d}},...t?.observeInstall}),streamResult:r,isStreaming:s}};function YEs(e){return e.replace(/\/$/,"").split("/").pop()}function XEs({templates:e,linkComponent:t,className:n,isLoading:r}){const s=t||"a";return r?a.jsx("div",{className:Z("grid gap-y-4",n),children:Array.from({length:5}).map((i,o)=>a.jsx("div",{className:"h-16 animate-pulse rounded-lg bg-card"},o))}):a.jsx("div",{className:Z("grid gap-y-4",n),children:e.map(i=>{const o=i?.agents||i?.tools||i?.networks||i?.workflows||i?.mcp;return a.jsxs("article",{className:Z(pr,"state-layer grid w-full grid-cols-[1fr_auto] overflow-hidden rounded-lg"),children:[a.jsxs(s,{to:`/templates/${i.slug}`,className:Z("group grid",{"grid-cols-[8rem_1fr] lg:grid-cols-[12rem_1fr]":i.imageURL}),children:[i.imageURL&&a.jsx("div",{className:"overflow-hidden",children:a.jsx("div",{className:"thumb transition-scale h-full w-full bg-cover duration-150",style:{backgroundImage:`url(${i.imageURL})`}})}),a.jsxs("div",{className:Z("grid w-full gap-0.5 px-4 py-3","[&_svg]:h-[1em] [&_svg]:w-[1em] [&_svg]:text-muted-foreground"),children:[a.jsx(Y,{as:"h2",tone:"ink",children:i.title}),a.jsx(Y,{className:Z(dx,jn),children:i.description}),a.jsxs("div",{className:"mt-3 hidden flex-wrap items-center gap-4 text-muted-foreground 2xl:flex",children:[o&&a.jsxs("ul",{className:Z("text-muted-foreground","m-0 flex list-none gap-4 p-0","[&>li]:flex [&>li]:items-center [&>li]:gap-0.5"),children:[i?.agents&&i.agents.length>0&&a.jsx("li",{children:a.jsxs(Y,{as:"span",variant:"body",className:"block",children:[a.jsx(ko,{})," ",i.agents.length]})}),i?.tools&&i.tools.length>0&&a.jsx("li",{children:a.jsxs(Y,{as:"span",variant:"body",className:"block",children:[a.jsx(ud,{})," ",i.tools.length]})}),i?.networks&&i.networks.length>0&&a.jsx("li",{children:a.jsxs(Y,{as:"span",variant:"body",className:"block",children:[a.jsx(dht,{})," ",i.networks.length]})}),i?.workflows&&i.workflows.length>0&&a.jsx("li",{children:a.jsxs(Y,{as:"span",variant:"body",className:"block",children:[a.jsx(dk,{})," ",i.workflows.length]})}),i?.mcp&&i.mcp.length>0&&a.jsx("li",{children:a.jsxs(Y,{as:"span",variant:"body",className:"block",children:[a.jsx(I_,{})," ",i.mcp.length]})})]}),o&&i.supportedProviders&&a.jsx("small",{children:a.jsx(Y,{as:"span",variant:"body",children:"|"})}),a.jsx("div",{className:"flex items-center gap-4",children:i.supportedProviders.map(l=>a.jsx(Y,{tone:"muted",as:"span",variant:"body",children:l},l))})]})]})]}),a.jsx("a",{href:i.githubUrl,className:Z("group ml-auto hidden items-center gap-2 pr-4","lg:flex"),target:"_blank",rel:"noopener noreferrer",children:a.jsx(Y,{as:"span",variant:"body",children:a.jsxs("span",{className:Z("flex items-center gap-2 rounded bg-sidebar px-2 py-1",Oft,dx,jn),children:[a.jsx(oX,{})," ",YEs(i.githubUrl)]})})})]},i.slug)})})}function JEs({tagOptions:e,selectedTag:t,providerOptions:n,selectedProvider:r,onTagChange:s,onProviderChange:i,searchTerm:o,onSearchChange:l,onReset:c,className:u,isLoading:d}){return d?a.jsxs("div",{className:Z("flex h-[6.5rem] items-center gap-5","[&>div]:h-8 [&>div]:w-48 [&>div]:animate-pulse [&>div]:bg-card",u),children:[a.jsx("div",{})," ",a.jsx("div",{})," ",a.jsx("div",{})]}):a.jsxs("div",{className:Z("sticky top-0 mx-auto flex flex-wrap gap-4 bg-background py-5",u),children:[a.jsx(qc,{label:"Search templates",placeholder:"Search Template",value:o,onValueChange:l}),a.jsxs(Vr,{value:t,onValueChange:s,children:[a.jsx(qr,{"aria-label":"Filter by tag",size:"md",children:a.jsx(Ur,{placeholder:"Select an option"})}),a.jsx(Qr,{children:e.map(f=>a.jsx(ir,{value:f.value,children:f.label},f.value))})]}),a.jsxs(Vr,{value:r,onValueChange:i,children:[a.jsx(qr,{"aria-label":"Filter by provider",size:"md",children:a.jsx(Ur,{placeholder:"Select an option"})}),a.jsx(Qr,{children:n.map(f=>a.jsx(ir,{value:f.value,children:f.label},f.value))})]}),c&&a.jsx(de,{onClick:c,icon:a.jsx(Dn,{}),children:"Reset"})]})}const eIs=[{id:"templates",label:"Templates"}];function tIs(){const{data:e,isLoading:t}=VEs(),{templates:n,tags:r,providers:s}=e??{templates:[],tags:[],providers:[]},[i,o]=g.useState("all"),[l,c]=g.useState("all"),[u,d]=g.useState(""),f=[{value:"all",label:"Any tag"}];(r||[]).forEach(b=>{f.push({value:b,label:b})});const h=[{value:"all",label:"Any provider"}];(s||[]).forEach(b=>{h.push({value:b,label:b})});const p=(b,S)=>{S==="tag"?o(b):S==="provider"&&c(b)},m=b=>{d(b)},v=()=>{o("all"),c("all"),d("")},y=n.filter(b=>!(u&&!b.title.toLowerCase().includes(u)&&!b.description.toLowerCase().includes(u)||i!=="all"&&!b.tags.includes(i)||l!=="all"&&!b.supportedProviders.includes(l))),x=u||i!=="all"||l!=="all";return a.jsxs(Et,{variant:"fit",breadcrumbs:a.jsx(Dt,{crumbs:eIs}),children:[a.jsx("h1",{className:"sr-only",children:"Templates"}),a.jsx(iL,{children:a.jsxs(Nht,{children:[a.jsx(At,{children:a.jsx(F1,{})}),"Templates"]})}),a.jsxs("div",{className:Z("z-10 h-full w-full overflow-y-auto px-5 pb-12"),children:[a.jsx(JEs,{selectedTag:i,onTagChange:b=>p(b,"tag"),tagOptions:f,selectedProvider:l,onProviderChange:b=>p(b,"provider"),providerOptions:h,searchTerm:u,onSearchChange:m,onReset:x?v:void 0,className:"max-w-[80rem]",isLoading:t}),a.jsx(XEs,{templates:y,linkComponent:lc,className:"mx-auto max-w-[80rem]",isLoading:t})]})]})}const nIs="1.76.0-alpha.7";function nee({children:e,className:t}){return a.jsx("div",{className:Z("transition-height mt-12 rounded-lg border border-border px-4 py-5 lg:min-h-[25rem] lg:px-12",t),children:e})}function rIs({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,i=()=>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.",o=()=>s?{icon:a.jsx(Yd,{className:"text-warning-foreground"}),title:"Template Installed with Warnings"}:{icon:a.jsx(y_n,{}),title:"Template Installation Failed"},{icon:l,title:c}=o();return a.jsxs(nee,{className:"mb-5 content-center space-y-4 text-muted-foreground",children:[a.jsxs("div",{className:"grid content-center items-center justify-items-center gap-4 [&>svg]:h-8 [&>svg]:w-8",children:[l,a.jsxs("div",{className:"space-y-2 text-center",children:[a.jsx(Y,{variant:"subheading",tone:"ink",children:c}),a.jsx(Y,{tone:"muted",children:i()})]})]}),t&&t.length>0&&a.jsxs("details",{children:[a.jsx("summary",{className:Z(Fn,"cursor-pointer text-center select-none"),children:a.jsxs(Y,{as:"span",variant:"caption",className:"block",children:["Show Validation Issues (",t.length,")"]})}),a.jsx("div",{className:"mt-4 max-h-60 space-y-2 overflow-auto rounded bg-muted p-3 text-left",children:t.map((u,d)=>a.jsxs("div",{className:"border-l-2 border-destructive-indicator pl-2",children:[a.jsx(Y,{as:"p",variant:"column",className:"text-destructive-foreground",children:u.type==="typescript"?"🔴 TypeScript Error":"⚠️ Lint Error"}),a.jsx(cl,{className:"mt-1 text-caption wrap-break-word whitespace-pre-wrap text-muted-foreground",code:u.message})]},d))})]}),n&&!s&&a.jsxs("details",{children:[a.jsx("summary",{className:Z(Fn,"cursor-pointer text-center select-none"),children:a.jsx(Y,{as:"span",variant:"caption",className:"block",children:"Show Details"})}),a.jsx("div",{className:"mt-4 max-h-60 overflow-auto rounded bg-muted p-3 text-left",children:a.jsx(cl,{className:"text-caption wrap-break-word whitespace-pre-wrap",code:n})})]})]})}const sIs=g.createContext(null);function iIs(){const e=g.useContext(sIs);return e||{registerResetFn:()=>{},triggerReset:()=>{}}}const wqt=({defaultProvider:e,defaultModel:t,updateModel:n,resetModel:r})=>{const[s]=g.useState(e),[i]=g.useState(t),[o,l]=g.useState(t),[c,u]=g.useState(e||""),[d,f]=g.useState(!1),[h,p]=g.useState(!1),[m,v]=g.useState(!1),{data:y,isLoading:x}=x6(),b=z0(),{models:S}=J0(),k=g.useMemo(()=>y?.providers||[],[y]);g.useEffect(()=>{l(t),u(e||"")},[t,e]);const j=io(c),T=UI(k,j)?.id||j,_=async F=>{if(l(F),F&&T){f(!0);try{const Q=await n({provider:T,modelId:F});console.info("Model updated:",Q)}catch(Q){console.error("Failed to update model:",Q)}finally{f(!1)}}},N=F=>{const Q=io(F);u(Q),Q!==j&&(l(""),v(!0))},{registerResetFn:I}=iIs();if(g.useEffect(()=>(I(()=>{if(h||m)return;if(j&&j!==s&&(!o||o==="")){u(io(s)),l(i);const V=UI(k,s)?.id||s;V&&i&&n({provider:V,modelId:i}).catch(H=>{console.error("Failed to reset model:",H)})}}),()=>{I(null)}),[I,j,o,s,i,n,h,m,k]),x)return a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(En,{}),a.jsx(Y,{as:"span",tone:"muted",children:"Loading providers..."})]});const A=async()=>{if(!r){console.warn("Reset model function not provided");return}try{f(!0),await r()}catch(F){console.error("Failed to reset model:",F)}finally{f(!1)}},P=UI(k,j);if(b.active&&b.pickerVisible===!1){const F=b.default&&b.default.provider&&b.default.modelId?`${b.default.provider}/${b.default.modelId}`:c&&o?`${c}/${o}`:"Locked by admin";return a.jsxs("div",{className:Z(pr,"flex items-center gap-2 rounded-md px-3 py-2"),"data-testid":"agent-metadata-model-locked",children:[a.jsx(Tu,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),a.jsx(Y,{as:"span",variant:"caption",tone:"ink",className:"truncate",children:F}),a.jsx(Y,{as:"span",variant:"meta",tone:"muted",className:"ml-auto shrink-0",children:"Set by admin"})]})}const D=!!(j&&o)&&b.active&&b.allowed!==void 0&&!S.some(F=>io(F.provider)===j&&F.model===o);return a.jsxs("div",{className:"@container",children:[a.jsxs("div",{className:"flex w-full flex-col items-stretch gap-2 @xs:flex-row @xs:items-center",children:[a.jsx("div",{className:"w-full @xs:w-2/5",children:a.jsx(Ek,{value:j,onValueChange:N,open:h,onOpenChange:p})}),a.jsx("div",{className:"w-full @xs:w-3/5",children:a.jsx(Ik,{llmId:j,value:o,onValueChange:_,open:m,onOpenChange:v})}),a.jsx(de,{variant:"default",size:"md",onClick:A,disabled:d,className:"flex items-center gap-1.5 border-0! whitespace-nowrap",title:"Reset to original model",children:a.jsx(b_,{className:"h-3.5 w-3.5"})})]}),D&&a.jsx("div",{className:"p-2 pt-2","data-testid":"agent-metadata-model-stale-warning",children:a.jsx(Ht,{variant:"warning",title:"Model not allowed",children:a.jsxs(Ht.Message,{children:[a.jsxs("code",{className:"rounded bg-fill-hover px-1 py-0.5",children:[c,"/",o]})," ","is no longer allowed by the admin policy. Pick a different model to save changes."]})})}),P&&!P.connected&&a.jsx("div",{className:"p-2 pt-2",children:a.jsx(Ht,{variant:"warning",title:"Provider not connected",children:a.jsxs(Ht.Message,{children:["Set the"," ",a.jsx("code",{className:"rounded bg-fill-hover px-1 py-0.5",children:Array.isArray(P.envVar)?P.envVar.join(", "):P.envVar})," ","environment"," ",Array.isArray(P.envVar)&&P.envVar.length>1?"variables":"variable"," to use this provider."]})})})]})};function oIs({providerOptions:e,selectedProvider:t,onProviderChange:n,variables:r,errors:s,handleInstallTemplate:i,handleVariableChange:o,isLoadingEnvVars:l,isInstalling:c,defaultModelProvider:u,defaultModelId:d,onModelUpdate:f}){return a.jsx(nee,{children:a.jsxs("div",{className:"mx-auto my-4 grid max-w-[40rem] gap-5 p-4 lg:p-5",children:[a.jsxs(Y,{as:"h2",variant:"heading",tone:"muted",className:Z("flex items-center gap-2","[&_svg]:h-[1.2em] [&_svg]:opacity-70 [&>svg]:w-[1.2em]"),children:["Install Template ",a.jsx(fht,{})]}),a.jsxs(ft,{orientation:"horizontal",children:[a.jsx(ut,{children:"Template AI Model Provider"}),a.jsx(Ggt,{className:"flex-1",children:a.jsxs(Vr,{name:"template-provider",value:t,onValueChange:n,children:[a.jsx(qr,{size:"md",children:a.jsx(Ur,{placeholder:"Select"})}),a.jsx(Qr,{children:e.map(h=>a.jsx(ir,{value:h.value,children:h.label},h.value))})]})})]}),t&&Object.entries(r||{}).length>0&&a.jsxs(a.Fragment,{children:[a.jsx(Y,{as:"h3",tone:"muted",children:"Set required Environmental Variables"}),a.jsx("div",{className:"grid grid-cols-[1fr_1fr] items-start gap-4",children:l?a.jsxs("div",{className:Z("text-muted-foreground","col-span-2 flex items-center justify-center gap-4","[&_svg]:h-[1.1em] [&_svg]:w-[1.1em] [&_svg]:opacity-50","animate-in duration-300 fade-in"),children:[a.jsx(En,{}),a.jsxs(Y,{as:"span",variant:"caption",className:"block",children:[" ","Loading variables..."]})]}):Object.entries(r).map(([h,p])=>a.jsxs(g.Fragment,{children:[a.jsxs(ft,{className:"w-full",children:[a.jsx(ut,{className:"sr-only",children:"Key"}),a.jsx(Sn,{name:`env-${h}`,value:h,disabled:!0,className:"w-full"})]}),a.jsxs(ft,{invalid:s.includes(h),className:"w-full",children:[a.jsx(ut,{className:"sr-only",children:"Value"}),a.jsx(Sn,{name:h,value:p,onChange:o,autoComplete:"off",className:"w-full"}),a.jsx(is,{children:s.includes(h)?"Value is required.":void 0})]})]},h))}),a.jsxs("div",{className:"relative mt-3.5 border-t border-border pt-12",children:[a.jsx("div",{className:"absolute top-0 left-1/2 flex h-8 w-8 -translate-x-1/2 -translate-y-4 items-center justify-center rounded-full bg-background",children:a.jsx(Y,{tone:"muted",as:"span",variant:"caption",className:"block",children:"And"})}),a.jsx(Y,{as:"h3",tone:"muted",children:"Set AI Model for Template Installation"}),a.jsx(Y,{tone:"muted",className:"mt-2 mb-5",children:"This model will be used by the workflow to process and install the template"}),a.jsx(wqt,{defaultProvider:u||"",defaultModel:d||"",updateModel:f||(()=>Promise.resolve({message:"Updated"})),closeEditor:()=>{},autoSave:!0,selectProviderPlaceholder:"Provider"})]})]}),t&&!l&&a.jsx(de,{className:Z("state-layer mt-4 flex min-h-10 w-full items-center justify-center gap-2 rounded-lg bg-card text-foreground","[&_svg]:h-[1.1em] [&_svg]:text-foreground [&>svg]:w-[1.1em]"),onClick:i,disabled:!t||!u||!d||s.length>0||c,children:c?a.jsxs(a.Fragment,{children:[a.jsx(En,{className:"h-4 w-4"})," Installing..."]}):a.jsxs(a.Fragment,{children:["Install ",a.jsx(fp,{})]})})]})})}function aIs({title:e,description:t,githubUrl:n,isLoading:r,infoData:s,templateSlug:i}){const o=i?`feat/install-template-${i}`:"feat/install-template-[slug]";return a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"mt-5 grid items-center",children:a.jsxs("div",{className:Z("flex items-center gap-3","[&>svg]:h-[1.2em] [&>svg]:w-[1.2em] [&>svg]:opacity-50",{"[&>svg]:opacity-20":r}),children:[a.jsx(F1,{}),a.jsx("h2",{className:Z({"flex min-w-[50%] rounded-lg bg-muted":r}),children:a.jsx(Y,{as:"span",variant:"title",className:"block",children:r?a.jsx(a.Fragment,{children:" "}):e})})]})}),a.jsxs("div",{className:"grid gap-x-24 lg:grid-cols-[1fr_1fr]",children:[a.jsxs("div",{className:"grid",children:[a.jsx(Y,{tone:"muted",className:Z("mt-2 mb-4",{"rounded-lg bg-muted":r}),children:r?a.jsx(a.Fragment,{children:" "}):t}),!r&&i&&a.jsxs("div",{className:Z("mb-4 rounded-lg border border-border bg-background p-4","flex items-start gap-3"),children:[a.jsx("div",{className:"mt-0.5 shrink-0",children:a.jsx(pp,{className:"h-[1.1em] w-[1.1em] text-info-indicator"})}),a.jsxs("div",{className:"flex-1 space-y-2",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(CN,{className:"h-[1em] w-[1em] text-muted-foreground"}),a.jsx(Y,{as:"span",variant:"subheading",tone:"ink",children:"A new Git branch will be created"})]}),a.jsxs("div",{className:"space-y-1",children:[a.jsxs(Y,{tone:"muted",as:"p",variant:"caption",children:[a.jsx(Y,{as:"span",variant:"column",children:"Branch name:"})," ",a.jsx(ih,{children:o})]}),a.jsx(Y,{tone:"muted",as:"p",variant:"caption",children:"This ensures safe installation with easy rollback if needed. Your main branch remains unchanged."})]})]})]}),n&&a.jsxs("a",{href:n,target:"_blank",rel:"noopener noreferrer",className:Z(Fn,"mt-auto flex items-center gap-2"),children:[a.jsx(oX,{}),a.jsx(Y,{as:"span",variant:"body",className:"block",children:n?.split("/")?.pop()})]})]}),s&&a.jsx($Ie,{data:s,labelsAreHidden:!0,isLoading:r})]})]})}function Htt(e){switch(e){case"running":return a.jsx(En,{size:"sm","aria-hidden":!0});case"success":return a.jsx(dr,{"aria-hidden":!0});case"failed":return a.jsx(Dn,{"aria-hidden":!0});default:return null}}function lIs(){return a.jsx("svg",{viewBox:"0 0 24 24",className:"text-placeholder","aria-hidden":!0,children:a.jsx("circle",{cx:"12",cy:"12",r:"8.5",pathLength:"48",fill:"none",stroke:"currentcolor",strokeWidth:"2.8",strokeLinecap:"round",strokeDasharray:"3 3"})})}function cIs({status:e,variant:t}){return t==="plain"?a.jsx("span",{className:Z("flex size-4 items-center justify-center self-center [&>svg]:size-4",$i.colors,{"[&>svg]:text-success-indicator":e==="success","[&>svg]:text-destructive-foreground":e==="failed"}),children:e==="pending"?a.jsx(lIs,{}):Htt(e)}):a.jsx("span",{className:Z("flex size-7 items-center justify-center self-center rounded-full motion-reduce:transition-none",$i.colors,$i.transform,{"[&>svg]:text-success-indicator":e==="success","[&>svg]:text-destructive-foreground":e==="failed","border border-dashed border-placeholder":e==="pending","[&>svg]:size-4":e!=="running","bg-success-subtle":e==="success","bg-destructive-subtle":e==="failed","scale-110":e==="success"||e==="failed"}),children:Htt(e)})}function uIs({step:e,isActive:t,position:n,variant:r="default"}){const s=t||e.status==="success"?"ink":"muted";return a.jsxs("div",{className:Z("grid grid-cols-[1fr_auto] gap-6 rounded-lg px-4 py-3 motion-reduce:transition-none",$i.colors,{"border border-transparent":r==="default","border-dashed border-placeholder bg-card":t&&r==="default"}),children:[a.jsxs("div",{className:"grid min-w-0 grid-cols-[auto_1fr] gap-2",children:[a.jsxs(Y,{as:"span",tone:s,className:Z("flex min-w-6 justify-end",$i.colors),children:[n,"."]}),a.jsxs("div",{className:"min-w-0",children:[a.jsx(Y,{as:"h4",tone:s,className:$i.colors,children:e.title}),e.description&&a.jsx(Y,{tone:"faint",className:Z("-mt-0.5",{truncate:r==="plain"}),children:e.description})]})]}),a.jsx(cIs,{status:e.status,variant:r})]})}function dIs({currentStep:e,steps:t=[],className:n}){return a.jsx("div",{className:Z(n),children:t.map((r,s)=>a.jsx(uIs,{step:r,isActive:e?.id===r.id,position:s+1},r.id))})}function fIs({steps:e}){const t=e.length,n=e.filter(r=>r.status==="success").length;return a.jsxs("div",{className:"flex w-full flex-col content-center justify-center gap-4",children:[a.jsx("div",{className:"grid w-full grid-cols-[0_repeat(9,1fr)]",children:e.map((r,s)=>a.jsx("div",{className:Z("relative flex h-8 items-center justify-end",$i.colors,{"bg-success-subtle":r.status==="success"&&e?.[s-1]?.status==="success"}),children:a.jsx("div",{className:Z("absolute right-0 z-10 flex size-8 translate-x-1/2 items-center justify-center self-center rounded-full bg-fill text-column text-muted-foreground motion-reduce:transition-none",$i.colors,$i.transform,{"border border-dashed border-placeholder":r.status==="pending","scale-110 bg-success-subtle text-success-subtle-foreground":r.status==="success","scale-110 bg-destructive-subtle text-destructive-subtle-foreground":r.status==="failed"}),children:r.status==="running"?a.jsx(En,{}):s+1})},r.id))}),a.jsxs("div",{className:Z("text-center text-caption text-muted-foreground",$i.colors),children:[n," of ",t," steps completed"]})]})}function hIs({name:e,streamResult:t,runId:n,workflowInfo:r}){const s=t?.phase||"initializing",i=t?.payload?.workflowState,o=t?.payload?.currentStep,l=t?.error,c=i?.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)),h=f.length,p=()=>{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:o?.id===v}));return a.jsxs(nee,{className:"mb-5 content-center space-y-6 text-muted-foreground",children:[a.jsxs("div",{className:"text-center",children:[a.jsx(Y,{as:"h3",variant:"heading",tone:"ink",children:p()}),(t?.runId||n)&&a.jsxs(Y,{as:"p",variant:"caption",tone:"muted",className:"mt-2",children:["Run ID: ",t?.runId??n]})]}),u&&h>0&&!["error"].includes(s)&&a.jsx("div",{className:"mx-auto w-full max-w-[30rem] px-4",children:a.jsx(fIs,{steps:m})}),l&&s==="error"&&a.jsxs("div",{className:Z("text-foreground","flex items-center gap-3 rounded-lg bg-destructive-subtle p-4","[&>svg]:h-6 [&>svg]:w-6 [&>svg]:text-destructive-foreground [&>svg]:opacity-70"),children:[a.jsx(fEn,{}),a.jsx(Y,{as:"span",variant:"body",className:"block",children:l||"Something went wrong"})]}),u&&a.jsx(dIs,{steps:m,currentStep:o,className:"pb-4"}),!u&&s==="initializing"&&a.jsxs("div",{className:Z("text-muted-foreground","grid justify-items-center gap-4 text-center"),children:[a.jsx(En,{}),a.jsx(Y,{as:"p",variant:"body",children:"This may take some time..."})]})]})}function pIs({name:e,installedEntities:t}){return a.jsxs(nee,{className:Z("grid content-center items-center justify-items-center gap-4","[&>svg]:h-8 [&>svg]:w-8"),children:[a.jsx(fht,{}),a.jsx(Y,{as:"h2",variant:"heading",children:"Done!"}),a.jsxs(Y,{tone:"muted",className:"text-center",children:["The ",a.jsx("b",{className:"text-muted-foreground",children:e})," template has been successfully installed.",t&&t.length>0&&a.jsxs(a.Fragment,{children:[a.jsx("br",{})," Installed entities are listed below."]})]}),t&&t.length>0&&a.jsx($Ie,{data:t})]})}function mIs(){const{templateSlug:e}=jr(),t=[{id:"templates",label:"Templates",to:"/templates"},{id:"template",label:xke(e)}],[n,r]=oi(),[s,i]=g.useState(""),[o,l]=g.useState(""),[c,u]=g.useState(""),[d,f]=g.useState({}),[h,p]=g.useState([]),[m,v]=g.useState(null),[y,x]=g.useState(!1),[b,S]=g.useState(""),[k,j]=g.useState(!1),[C,T]=g.useState(!1),[_,N]=g.useState([]),{data:I,isLoading:A}=UEs({repoOrSlug:e,owner:"mastra-ai"}),D=nIs?.includes("beta")??!1?"beta":"main",{data:F,isLoading:Q}=qEs({repo:I?.githubUrl?new URL(I.githubUrl).pathname.split("/")[2]:`template-${e}`,owner:"mastra-ai",branch:D}),{data:q,isLoading:B}=QEs(),{mutateAsync:V,isPending:H}=ZEs(),{mutateAsync:M}=WEs(),{streamInstall:G,streamResult:L,isStreaming:$}=GEs({workflowInfo:q}),{observeInstall:z,streamResult:U,isStreaming:K}=KEs({workflowInfo:q});g.useEffect(()=>{const re=n.get("runId");re&&!y&&!m&&!$&&!K&&(console.info("🔄 Checking completed run after hot reload:",{runId:re}),S(re),M({runId:re}).then(ae=>{const he=ae.snapshot;if(he?.status==="success"&&he?.result?.success)x(!0);else if(he?.result?.success===!1)if(he?.result?.validationResults&&!he?.result?.validationResults?.valid&&he?.result?.validationResults?.remainingErrors>0){const{remainingErrors:pe,errors:ke}=he.result.validationResults,Ee=`Template installation completed but ${pe} validation issue${pe>1?"s":""} remain unresolved.`;v(Ee),N(ke||[])}else{const pe=he?.result?.message||he?.result?.error||"Template installation failed";v(typeof pe=="string"?pe:String(pe))}}).catch(ae=>{console.error("❌ Failed to fetch run details:",ae),v("Failed to retrieve installation status after reload")}))},[n,y,m,$,K,M]),g.useEffect(()=>{const re=n.get("runId"),ae=n.get("resume"),he=n.get("provider");if(re&&ae==="true"&&he&&!$&&!K&&!k&&!C&&q){S(re),j(!0);try{M({runId:re}).then(ve=>{if(ve.snapshot?.status==="running")return z.mutateAsync({runId:re})}).then(()=>{r(ve=>{const pe=new URLSearchParams(ve);return pe.delete("resume"),pe})}).catch(ve=>{console.error("❌ Failed to resume template installation:",ve),ve.message?.includes("404")||ve.message?.includes("not found")?v("Template installation run not found. It may have expired or been completed."):v("Failed to resume template installation. Please try again.")})}catch(ve){console.error("❌ Auto-resume failed with error:",ve),v("Failed to resume template installation. Please refresh and try again.")}}},[n,e,$,K,k,C,q,M,z,r]);const ne=[{value:"openai",label:"OpenAI"},{value:"anthropic",label:"Anthropic"},{value:"groq",label:"Groq"},{value:"google",label:"Google"}],X=[{key:"tools",label:"Tools",value:I?.tools?.length?I.tools.map(re=>re).join(", "):"n/a",icon:a.jsx(ud,{})},{key:"agents",label:"Agents",value:I?.agents?.length?I.agents.map(re=>re).join(", "):"n/a",icon:a.jsx(ko,{})},{key:"workflows",label:"Workflows",value:I?.workflows?.length?I.workflows.map(re=>re).join(", "):"n/a",icon:a.jsx(dk,{})},{key:"providers",label:"Providers",value:I?.supportedProviders?.length?I.supportedProviders.join(", "):"n/a",icon:a.jsx(m0,{})},{key:"tags",label:"Tags",value:I?.tags?.length?I.tags.join(", "):"n/a",icon:a.jsx(uk,{})}],te=[{...X[0]},{...X[1]},{...X[2]}].filter(re=>re.value!=="n/a");g.useEffect(()=>{F&&f(F)},[F]),g.useEffect(()=>{const re=L||U;re?.phase==="error"&&re?.error&&v(typeof re.error=="string"?re.error:String(re.error))},[L?.phase,L?.error,U?.phase,U?.error]);const ie=re=>{i(re)},ue=async re=>(l(re.provider),u(re.modelId),{message:"Model updated successfully"}),ee=async()=>{const re=Object.entries(d).reduce((ae,[he,ve])=>(ve===""&&ae.push(he),ae),[]);if(re.length>0){p(re);return}if(I){v(null),x(!1),S(""),T(!0);try{const he={repo:I.githubUrl||`https://github.com/mastra-ai/template-${I.slug}`,ref:D,slug:I.slug,variables:d},{runId:ve}=await V({});S(ve),r(pe=>{const ke=new URLSearchParams(pe);return ke.set("runId",ve),ke.set("resume","true"),ke.set("provider",s||"openai"),ke}),await G.mutateAsync({inputData:he,selectedModel:{provider:o,modelId:c},runId:ve})}catch(ae){T(!1),v(ae?.message||"Template installation failed"),console.error("Template installation failed",ae)}}},se=re=>{const{name:ae,value:he}=re.target;he.trim()===""?p(ve=>[...ve,ae]):p(ve=>ve.filter(pe=>pe!==ae)),f(ve=>({...ve,[ae]:he}))};return a.jsxs(Et,{variant:"fit",breadcrumbs:a.jsx(Dt,{crumbs:t}),children:[a.jsx("h1",{className:"sr-only",children:e}),a.jsx("div",{className:Z("h-full w-full overflow-y-scroll lg:px-12"),children:a.jsxs("div",{className:"mx-auto grid w-full max-w-[80rem] gap-y-4 p-4",children:[a.jsx(aIs,{isLoading:A,title:I?.title,description:I?.longDescription,imageURL:I?.imageURL,githubUrl:I?.githubUrl,infoData:X,templateSlug:e}),I&&a.jsxs(a.Fragment,{children:[($||K)&&a.jsx(hIs,{name:I.title,streamResult:K?U:L,runId:b,workflowInfo:q}),y&&a.jsx(pIs,{name:I.title,installedEntities:te,linkComponent:lc}),m&&a.jsx(rIs,{errorMsg:m,validationErrors:_.length>0?_:L?.validationResults?.errors||U?.validationResults?.errors}),!$&&!K&&!y&&!m&&a.jsx(oIs,{providerOptions:ne,selectedProvider:s,onProviderChange:ie,variables:d,setVariables:f,errors:h,setErrors:p,handleInstallTemplate:ee,handleVariableChange:se,isLoadingEnvVars:Q||B,isInstalling:H,defaultModelProvider:o,defaultModelId:c,onModelUpdate:ue})]})]})})]})}const gIs=()=>a.jsx(Xt,{titleSlot:"No Workflows yet",descriptionSlot:a.jsxs(a.Fragment,{children:["Mastra workflows are not configured yet. ",a.jsx("br",{}),"More information in the documentation."]}),actionSlot:a.jsx(de,{variant:"ghost",render:a.jsx("a",{href:"https://mastra.ai/docs/workflows/overview",target:"_blank",rel:"noopener noreferrer"}),icon:a.jsx(Zs,{}),children:"Workflows Documentation"}),variant:"fill"});function vIs(e,t,n){return Pk(e,t,{name:r=>r.name,running:r=>n[r.id]?.running??0,suspended:r=>n[r.id]?.suspended??0,steps:r=>Object.keys(r.steps??{}).length})}function yIs(e){return Object.keys(e.steps??{}).filter(t=>e.allSteps?.[t]?.isWorkflow)}function xIs(e){const t=new Map;for(const[n,r]of Object.entries(e))t.set(n,n),r.name&&t.set(r.name,n);return t}function bIs(e,t,n){const r=xIs(t),s=[],i=(o,l,c,u,d,f)=>{const h=yIs(o).filter(v=>{const y=r.get(v);return y===void 0||!u.has(y)});if(s.push({kind:"workflow",workflow:o,pathKey:l,depth:c,nestedIds:h,guides:d,isLastChild:f}),!n.has(l)||h.length===0)return;const p=new Set(u).add(o.id),m=c===0?[]:[...d,!f];for(const[v,y]of h.entries()){const x=v===h.length-1,b=r.get(y);if(b===void 0){s.push({kind:"unregistered",stepId:y,description:o.allSteps?.[y]?.description,pathKey:`${l}/${y}`,depth:c+1,guides:m,isLastChild:x});continue}const S=t[b];S&&i({...S,id:b},`${l}/${b}`,c+1,p,m,x)}};for(const o of e)i(o,o.id,0,new Set([o.id]),[],!1);return s}const Gtt="auto 24rem minmax(0, 1fr) auto auto auto";function Sqt({guides:e,isLastChild:t}){return a.jsxs("span",{"aria-hidden":!0,className:"-my-6 flex shrink-0 self-stretch",children:[e.map((n,r)=>a.jsx("span",{className:Z("w-6",n&&"border-l border-border")},r)),a.jsxs("span",{className:"relative w-6",children:[a.jsx("span",{className:Z("absolute top-0 left-0 border-l border-border",t?"h-1/2":"h-full")}),a.jsx("span",{className:"absolute top-1/2 left-0 w-3.5 border-b border-border"})]})]})}function kqt({row:e,isExpanded:t,onToggle:n}){const r=e.kind==="workflow"&&e.nestedIds.length>0,s=e.kind==="workflow"?e.workflow.name:e.stepId;return a.jsx("div",{className:"flex items-center pl-5",children:r?a.jsx("button",{type:"button","aria-expanded":t,"aria-label":`${t?"Collapse":"Expand"} nested workflows of ${s}`,className:Z(Fn,"relative grid size-5 shrink-0 place-items-center before:absolute before:-inset-1.5 before:content-['']"),onClick:i=>{i.stopPropagation(),n()},children:a.jsx(Na,{direction:"right",className:"size-4"})}):a.jsx("span",{className:"size-5 shrink-0","aria-hidden":!0})})}const wIs=e=>e.stopPropagation();function F7({sortKey:e,sort:t,onSortChange:n,children:r}){return n?a.jsx(Te.SortableTopCell,{sortKey:e,sort:t?.key===e?t.direction:void 0,onSortChange:s=>n(s,e),children:r}):a.jsx(Te.TopCell,{children:r})}function SIs({row:e,isExpanded:t,onToggle:n,runCount:r,rowProps:s}){const{paths:i,Link:o}=xn(),l=g.useRef(null),{workflow:c,nestedIds:u}=e,d=uf(c.name,50),f=uf(c.description??"",200),h=Object.keys(c.steps??{}).length,p=r?.running??0,m=r?.suspended??0,v=u.length>0;return a.jsxs(Te.RowWrapper,{...s,onSelectRow:()=>l.current?.click(),children:[a.jsx(kqt,{row:e,isExpanded:t,onToggle:n}),a.jsxs(Te.RowLink,{ref:l,colStart:2,to:i.workflowLink(c.id),LinkComponent:o,tabIndex:-1,onClick:wIs,children:[a.jsx(Te.NameCell,{children:a.jsxs("span",{className:"flex items-center gap-1.5",children:[e.depth>0?a.jsx(Sqt,{guides:e.guides,isLastChild:e.isLastChild}):null,a.jsx("span",{className:"truncate",children:d}),c.origin==="dynamic"?a.jsx(Mt,{size:"xs",variant:"blue",title:"Registered via the dynamic-workflows API",children:"Dynamic"}):null,v?a.jsxs(Y,{as:"span",variant:"body-sm",tone:"muted",title:`Nested workflows: ${u.join(", ")}`,className:"inline-flex shrink-0 items-center gap-1",children:[a.jsx(dk,{"aria-hidden":!0,className:"size-3.5"}),u.length]}):null]})}),a.jsx(Te.DescriptionCell,{children:f}),a.jsx(Te.TextCell,{className:"text-center",children:p>0?a.jsxs("span",{className:"inline-flex items-center gap-1.5 text-info-indicator","aria-label":`${p} run${p===1?"":"s"} in progress`,children:[a.jsx("span",{"aria-hidden":!0,className:"size-2 rounded-full bg-info-indicator motion-safe:animate-pulse"}),p]}):""}),a.jsx(Te.TextCell,{className:"text-center",children:m>0?a.jsxs("span",{className:"inline-flex items-center gap-1.5 text-warning-foreground","aria-label":`${m} run${m===1?"":"s"} awaiting input`,children:[a.jsx(vS,{"aria-hidden":!0,className:"size-3.5"}),m]}):""}),a.jsx(Te.TextCell,{className:"text-center",children:h||""})]})]})}function kIs({workflows:e,isLoading:t,search:n="",sort:r,onSortChange:s,requestContext:i}){const[o,l]=g.useState(new Set),c=AMn({requestContext:i}),u=g.useMemo(()=>Object.entries(e).map(([x,b])=>({...b,id:x})),[e]),d=g.useMemo(()=>{const x=n.toLowerCase();return u.filter(b=>b.name?.toLowerCase().includes(x)||b.description?.toLowerCase().includes(x))},[u,n]),f=g.useMemo(()=>vIs(d,r,c),[d,r,c]),h=g.useMemo(()=>bIs(f,e,o),[f,e,o]),p=g.useMemo(()=>{const x=new Map;for(const b of h)b.kind==="workflow"&&x.set(b.pathKey,x.size);return x},[h]),{containerRef:m,getRowProps:v}=Du({count:p.size,global:!0}),y=x=>{l(b=>{const S=new Set(b);return S.has(x)?S.delete(x):S.add(x),S})};return t?a.jsx($u,{columns:Gtt,fit:"container"}):a.jsxs(Te,{columns:Gtt,fit:"container",scrollRef:m,children:[a.jsxs(Te.Top,{children:[a.jsx(Te.TopCell,{children:a.jsx("span",{className:"sr-only",children:"Expand"})}),a.jsx(F7,{sortKey:"name",sort:r,onSortChange:s,children:"Name"}),a.jsx(Te.TopCell,{children:"Description"}),a.jsx(F7,{sortKey:"running",sort:r,onSortChange:s,children:"Running"}),a.jsx(F7,{sortKey:"suspended",sort:r,onSortChange:s,children:"Pending input"}),a.jsx(F7,{sortKey:"steps",sort:r,onSortChange:s,children:"Number of steps"})]}),h.length===0&&n?a.jsx(Te.NoMatch,{message:"No Workflows match your search"}):null,h.map(x=>{const b=o.has(x.pathKey),S=()=>y(x.pathKey);return x.kind==="unregistered"?a.jsxs(Te.RowStatic,{className:"gap-0 px-0",children:[a.jsx(kqt,{row:x,isExpanded:b,onToggle:S}),a.jsxs("div",{className:"col-span-5 col-start-2 grid grid-cols-subgrid gap-4 px-3",children:[a.jsx(Te.NameCell,{children:a.jsxs("span",{className:"flex items-center gap-1.5",children:[a.jsx(Sqt,{guides:x.guides,isLastChild:x.isLastChild}),a.jsx("span",{className:"truncate",children:uf(x.stepId,50)}),a.jsxs(Ln,{children:[a.jsx(Rn,{render:a.jsx(Y,{as:"span",variant:"body-sm",tone:"muted"}),role:"note",tabIndex:0,className:Z("shrink-0 rounded-sm",Ri),children:"not registered"}),a.jsx(Mn,{className:"max-w-72",children:"Runs as a step of its parent workflow. Add it to the workflows of your Mastra instance to open, run, and inspect it on its own page."})]})]})}),a.jsx(Te.DescriptionCell,{children:uf(x.description??"",200)}),a.jsx(Te.TextCell,{className:"text-center",children:""}),a.jsx(Te.TextCell,{className:"text-center",children:""}),a.jsx(Te.TextCell,{className:"text-center",children:""})]})]},`workflow-${x.pathKey}`):a.jsx(SIs,{row:x,isExpanded:b,onToggle:S,runCount:c[x.workflow.id],rowProps:v(p.get(x.pathKey)??-1)},`workflow-${x.pathKey}`)})]})}const DM=[_s("/workflows")];function OIs(){const{data:e,isLoading:t,error:n}=Op(),[r,s]=g.useState(""),[i,o]=g.useState();return n&&js(n)?a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:DM}),children:[a.jsx("h1",{className:"sr-only",children:"Workflows"}),a.jsx(ai,{variant:"fill"})]}):n&&Cs(n)?a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:DM}),children:[a.jsx("h1",{className:"sr-only",children:"Workflows"}),a.jsx(Gs,{variant:"fill",resource:"workflows"})]}):n?a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:DM}),children:[a.jsx("h1",{className:"sr-only",children:"Workflows"}),a.jsx(Xt,{tone:"error",variant:"fill",titleSlot:"Failed to load workflows",descriptionSlot:n.message})]}):Object.keys(e||{}).length===0&&!t?a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:DM}),children:[a.jsx("h1",{className:"sr-only",children:"Workflows"}),a.jsx(gIs,{})]}):a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:DM}),actionRow:a.jsxs(Xn,{children:[a.jsx(Xn.Start,{children:a.jsx("div",{className:"max-w-120 flex-1",children:a.jsx(Ru,{onSearch:s,label:"Filter workflows",placeholder:"Filter by name or description"})})}),a.jsx(Xn.End,{children:a.jsx(de,{render:a.jsx(lc,{to:"/workflows/schedules"}),variant:"primary",icon:a.jsx(g0,{}),children:"Schedules"})})]}),children:[a.jsx("h1",{className:"sr-only",children:"Workflows"}),a.jsx(kIs,{workflows:e||{},isLoading:t,search:r,sort:i,onSortChange:(l,c)=>o({key:c,direction:l})})]})}const jIs={active:"bg-success-indicator",paused:"bg-info-indicator",completed:"bg-muted-foreground"},CIs={active:"text-success-indicator",paused:"text-info-indicator",completed:"text-muted-foreground"},Oqt=({status:e})=>a.jsxs("span",{className:"inline-flex items-center gap-2 whitespace-nowrap",children:[a.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${jIs[e]}`,"aria-hidden":!0}),a.jsx(Y,{as:"span",variant:"caption",className:CIs[e],children:e})]});function jqt({status:e}){const{icon:t,color:n}=_Is(e);return a.jsxs("span",{className:`inline-flex items-center gap-1.5 whitespace-nowrap ${n}`,children:[a.jsx("span",{className:"inline-flex shrink-0 items-center","aria-hidden":!0,children:t}),a.jsx(Y,{as:"span",variant:"caption",children:e})]})}function _Is(e){switch(e){case"success":return{icon:a.jsx(dr,{size:14}),color:"text-success-indicator"};case"failed":return{icon:a.jsx(Dn,{size:14}),color:"text-destructive-foreground"};case"running":return{icon:a.jsx(En,{}),color:"text-muted-foreground"};case"suspended":return{icon:a.jsx($H,{size:14}),color:"text-info-indicator"};case"canceled":return{icon:a.jsx(X3,{size:14}),color:"text-muted-foreground"};case"pending":case"waiting":return{icon:a.jsx(ON,{size:14}),color:"text-muted-foreground"};default:return{icon:null,color:"text-muted-foreground"}}}const Ktt="auto auto auto auto 1fr",TIs=3e4,EIs=5*6e4;function IIs({triggers:e,isLoading:t,workflowId:n,hasNextPage:r,isFetchingNextPage:s,setEndOfListElement:i}){const{Link:o,paths:l}=xn(),c=p=>!!(n&&p.runId&&p.outcome!=="failed"),u=e.filter(c).length,{containerRef:d,getRowProps:f}=Du({count:u});let h=-1;return t?a.jsx($u,{columns:Ktt}):e.length===0?a.jsx(Y,{variant:"body",tone:"muted",className:"p-4",children:"No trigger history yet."}):a.jsxs(Te,{columns:Ktt,className:"min-w-0",scrollRef:d,children:[a.jsxs(Te.Top,{children:[a.jsx(Te.TopCell,{children:"Run"}),a.jsx(Te.TopCell,{children:"Status"}),a.jsx(Te.TopCell,{children:"Started"}),a.jsx(Te.TopCell,{children:"Duration"}),a.jsx(Te.TopCell,{children:" "})]}),e.map(p=>{const m=p.actualFireAt-p.scheduledFireAt,v=sf(m,{signed:!0}),y=p.outcome==="failed",x=y?p.error:p.run?.error,b=Math.abs(m),S=!y&&b>TIs&&b<=EIs,k=`${p.scheduleId}-${p.runId}-${p.actualFireAt}`,j=c(p);j&&(h+=1);const C=a.jsx(Y,{as:"span",variant:"caption",font:"mono",tone:j?"ink":"muted",className:"whitespace-nowrap",children:p.runId}),T=a.jsxs(a.Fragment,{children:[a.jsx(Te.Cell,{children:C}),a.jsx(Te.Cell,{children:a.jsxs("span",{className:"inline-flex items-center gap-2",children:[y?a.jsxs(Y,{as:"span",variant:"caption",className:"inline-flex items-center gap-1.5 whitespace-nowrap text-destructive-foreground",children:[a.jsx(Yd,{size:14}),"publish failed"]}):p.run?a.jsx(jqt,{status:p.run.status}):a.jsx(Y,{as:"span",variant:"caption",tone:"muted",className:"inline-flex items-center gap-1.5 whitespace-nowrap",children:"pending"}),x?a.jsxs(Ln,{children:[a.jsx(Rn,{asChild:!0,children:a.jsx("span",{className:"inline-flex text-destructive-foreground",children:a.jsx(Yd,{size:14})})}),a.jsx(Mn,{children:x})]}):null]})}),a.jsx(Te.Cell,{children:a.jsxs("span",{className:"inline-flex items-center gap-2 whitespace-nowrap",children:[p.actualFireAt?a.jsx($I,{value:p.actualFireAt}):"—",S?a.jsxs(Ln,{children:[a.jsx(Rn,{asChild:!0,children:a.jsx("span",{className:"inline-flex text-info-indicator",children:a.jsx(Yd,{size:14})})}),a.jsxs(Mn,{children:["Published ",v," after the scheduled fire time"]})]}):null]})}),a.jsx(Te.Cell,{children:p.run?a.jsx(Y,{as:"span",variant:"body-sm",font:"mono",children:sf(p.run.durationMs)||"—"}):a.jsx("span",{className:"text-muted-foreground",children:"—"})}),a.jsx(Te.Cell,{children:" "})]});return j?a.jsx(Te.RowLink,{to:l.workflowRunLink(n,p.runId),LinkComponent:o,...f(h),children:T},k):a.jsx(Te.RowStatic,{children:T},k)}),a.jsx(Te.NextPageLoading,{isLoading:s,hasMore:r,setEndOfListElement:i})]})}const Cqt={id:"workflow-schedules",label:"Schedules",icon:g0,to:"/workflows/schedules"};function B7({label:e,children:t}){return a.jsxs("div",{className:"flex flex-col gap-1",children:[a.jsx(Y,{variant:"meta",tone:"muted",className:"uppercase",children:e}),a.jsx("div",{children:a.jsx(Y,{as:"span",variant:"body",className:"block",children:t})})]})}function NIs(){const{scheduleId:e}=jr(),t=[_s("/workflows"),Cqt,{id:"schedule",label:xke(e),icon:g0}],{paths:n}=xn(),{data:r,error:s}=vlr({scheduleId:e,queryOptions:{enabled:!!e}}),{data:i,isLoading:o,error:l,hasNextPage:c,isFetchingNextPage:u,setEndOfListElement:d}=ylr({scheduleId:e,queryOptions:{enabled:!!e}}),f=xlr({scheduleId:e});if(s&&js(s))return a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:t}),children:[a.jsx("h1",{className:"sr-only",children:e}),a.jsx(ai,{variant:"fill"})]});if(s&&Cs(s))return a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:t}),children:[a.jsx("h1",{className:"sr-only",children:e}),a.jsx(Gs,{variant:"fill",resource:"schedules"})]});if(s)return a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:t}),children:[a.jsx("h1",{className:"sr-only",children:e}),a.jsx(Xt,{tone:"error",variant:"fill",titleSlot:"Failed to load schedule",descriptionSlot:s.message})]});const h=r?.workflowId,p=r?.agentId;return a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:t}),actionRow:a.jsx(Xn,{children:a.jsxs(Xn.End,{children:[a.jsx(de,{render:a.jsx(lc,{to:n.schedulesLink()}),variant:"ghost",icon:a.jsx(md,{}),children:"Back to schedules"}),h?a.jsx(de,{icon:a.jsx(Ol,{}),render:a.jsx(lc,{to:n.workflowLink(h)}),variant:"ghost",children:"Open workflow"}):null,r?a.jsx(de,{onClick:()=>{const m=r.status==="active"?"pause":"resume";f.mutate(m,{onSuccess:()=>Ke.success(m==="pause"?"Schedule paused":"Schedule resumed"),onError:v=>Ke.error(v.message)})},disabled:f.isPending,"data-testid":"schedule-toggle-button",children:r.status==="active"?a.jsxs(a.Fragment,{children:[a.jsx(vS,{}),"Pause"]}):a.jsxs(a.Fragment,{children:[a.jsx(Bc,{}),"Resume"]})}):null]})}),children:[a.jsx("h1",{className:"sr-only",children:e}),r?a.jsxs("div",{className:"grid h-full grid-cols-[minmax(0,20rem)_1fr] gap-4 overflow-hidden",children:[a.jsxs("div",{className:"flex h-fit flex-col gap-4 rounded-md border border-border p-4",children:[a.jsx(B7,{label:p?"Agent":"Workflow",children:h?a.jsx(lc,{to:n.workflowLink(h),className:"text-foreground hover:underline",children:h}):p?a.jsx(lc,{to:n.agentLink(p),className:"text-foreground hover:underline",children:p}):"—"}),a.jsxs(B7,{label:"Cron",children:[a.jsx(Y,{as:"span",variant:"body",font:"mono",children:r.cron}),r.timezone?a.jsx(Y,{as:"span",variant:"caption",tone:"muted",className:"ml-2",children:r.timezone}):null]}),a.jsx(B7,{label:"Status",children:a.jsx(Oqt,{status:r.status})}),a.jsx(B7,{label:"Next fire",children:r.nextFireAt?a.jsx($I,{value:r.nextFireAt}):"—"})]}),a.jsxs("div",{className:"overflow-y-auto","data-testid":"schedule-triggers-panel",children:[a.jsx(Y,{variant:"body",className:"mb-3",children:"Trigger history"}),l?a.jsx(Xt,{tone:"error",titleSlot:"Failed to load trigger history",descriptionSlot:l.message}):a.jsx(IIs,{triggers:i??[],isLoading:o,workflowId:h,hasNextPage:c,isFetchingNextPage:u,setEndOfListElement:d})]})]}):null]})}const AIs={target:e=>e.workflowId??e.agentId??"",status:e=>e.status,nextFireAt:e=>e.nextFireAt,lastFireAt:e=>e.lastFireAt},Ytt="minmax(0, 1.2fr) minmax(0, 1.4fr) minmax(0, 1fr) auto auto auto";function PIs({schedules:e,isLoading:t,search:n="",sort:r,onSortChange:s}){const{paths:i,Link:o}=xn(),l=g.useMemo(()=>{const f=n.toLowerCase(),h=f?e.filter(p=>p.id.toLowerCase().includes(f)||(p.workflowId??p.agentId??"").toLowerCase().includes(f)):e;return Pk(h,r,AIs)},[e,n,r]),{containerRef:c,getRowProps:u}=Du({count:l.length,global:!0});if(t)return a.jsx($u,{columns:Ytt});const d=(f,h)=>s?a.jsx(Te.SortableTopCell,{sortKey:f,sort:r?.key===f?r.direction:void 0,onSortChange:s,children:h}):a.jsx(Te.TopCell,{children:h});return a.jsxs(Te,{columns:Ytt,className:"min-w-0",scrollRef:c,children:[a.jsxs(Te.Top,{children:[d("target","Target"),a.jsx(Te.TopCell,{children:"Schedule ID"}),a.jsx(Te.TopCell,{children:"Cron"}),d("status","Status"),d("nextFireAt","Next fire"),d("lastFireAt","Last run")]}),l.length===0&&n?a.jsx(Te.NoMatch,{message:"No schedules match your search"}):null,l.length===0&&!n?a.jsx(Te.NoMatch,{message:"No schedules configured"}):null,l.map((f,h)=>a.jsxs(Te.RowLink,{to:i.scheduleLink(f.id),LinkComponent:o,...u(h),children:[a.jsx(Te.NameCell,{children:f.workflowId??f.agentId}),a.jsx(Te.Cell,{className:"min-w-0",children:a.jsx(Y,{as:"span",variant:"body-sm",tone:"muted",font:"mono",className:"block truncate",title:f.id,children:f.id})}),a.jsx(Te.Cell,{children:a.jsxs("span",{className:"inline-flex items-center gap-2 whitespace-nowrap",children:[a.jsx(Y,{as:"span",variant:"caption",font:"mono",children:f.cron}),f.timezone?a.jsx(Y,{as:"span",variant:"meta",tone:"muted",children:f.timezone}):null]})}),a.jsx(Te.Cell,{children:a.jsx(Oqt,{status:f.status})}),a.jsx(Te.Cell,{children:f.nextFireAt?a.jsx($I,{value:f.nextFireAt}):"—"}),a.jsx(Te.Cell,{children:f.lastRun?a.jsxs("span",{className:"inline-flex items-center gap-2 whitespace-nowrap",children:[a.jsx(jqt,{status:f.lastRun.status}),f.lastFireAt?a.jsx(Y,{as:"span",variant:"caption",tone:"muted",children:a.jsx($I,{value:f.lastFireAt})}):null]}):f.lastFireAt?a.jsx($I,{value:f.lastFireAt}):a.jsx("span",{className:"text-muted-foreground",children:"Never"})})]},f.id))]})}function _qt({workflowId:e}={}){const{data:t,isLoading:n,error:r}=aK(e?{workflowId:e}:{}),[s,i]=g.useState(""),[o,l]=g.useState();return r?a.jsx(Xt,{tone:"error",titleSlot:"Failed to load schedules",descriptionSlot:r.message}):a.jsxs("div",{className:"grid h-full grid-rows-[auto_1fr] gap-4 overflow-hidden",children:[a.jsx("div",{className:"max-w-120",children:a.jsx(Ru,{onSearch:i,label:"Filter schedules",placeholder:"Filter by id or workflow"})}),a.jsx("div",{className:"overflow-y-auto",children:a.jsx(PIs,{schedules:t??[],isLoading:n,search:s,sort:o,onSortChange:(c,u)=>l({key:u,direction:c})})})]})}const xue=[_s("/workflows"),Cqt];function $Is(){const[e]=oi(),t=e.get("workflowId")??void 0,{error:n}=aK(t?{workflowId:t}:{});return n&&js(n)?a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:xue}),children:[a.jsx("h1",{className:"sr-only",children:"Schedules"}),a.jsx(ai,{variant:"fill"})]}):n&&Cs(n)?a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:xue}),children:[a.jsx("h1",{className:"sr-only",children:"Schedules"}),a.jsx(Gs,{variant:"fill",resource:"schedules"})]}):a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:xue}),children:[a.jsx("h1",{className:"sr-only",children:"Schedules"}),a.jsx("div",{className:"h-full",children:a.jsx(_qt,{workflowId:t})})]})}const RIs={"--belt-hue":"var(--warning-indicator)"};function MIs(e){const t=new Blob([JSON.stringify(e??null)]).size;return t<1024?`${t} B`:`${(t/1024).toFixed(1)} KB`}function DIs(e,t){if(e&&typeof e=="object"&&!Array.isArray(e)){const n=Object.keys(e),[r]=n;if(n.length===1&&r)return r}return t}function LIs({suspendedSteps:e,workflow:t,isStreaming:n,onResume:r}){return n||e.length===0?null:a.jsxs("section",{className:Z(nke,"pointer-events-auto relative isolate"),"data-testid":"workflow-suspended-steps","aria-label":"Step suspended",children:[a.jsxs("div",{className:"max-h-[calc(100cqh-64px)] overflow-y-auto overscroll-contain rounded-[inherit]",children:[a.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-border bg-background px-5 py-4",children:[a.jsxs(Y,{as:"h2",variant:"column",tone:"ink",className:"flex items-center gap-2",children:[a.jsx(At,{children:a.jsx($H,{})}),"Step suspended"]}),a.jsx(Mt,{variant:"orange",emphasis:"subtle",children:"Needs input"})]}),e.map(s=>{const i=t.allSteps[s.stepId];if(!i||i.isWorkflow)return null;const o=i?.resumeSchema?OS(rC(i.resumeSchema)):Nf(_n(),Bf());return a.jsx(zIs,{step:s,stepSchema:o,description:i.description,onResume:r},`${s.runId}-${s.stepId}`)})]}),a.jsx(a4t,{status:"ready",label:"Needs input",className:"before:hidden",style:RIs})]})}function zIs({step:e,stepSchema:t,description:n,onResume:r}){const[s,i]=g.useState(!1),[o,l]=g.useState(!1),c=async u=>{l(!0);try{await r({stepId:e.stepId.split("."),runId:e.runId,resumeData:u})}catch(d){Ke.error(d instanceof Error?d.message:"Error resuming workflow")}finally{l(!1)}};return a.jsxs("div",{className:"space-y-5 p-5 [&+&]:border-t [&+&]:border-border",children:[a.jsxs("div",{className:"space-y-2",children:[a.jsx(Y,{as:"p",variant:"subheading",tone:"ink",className:"break-words",children:e.stepId}),n&&a.jsx(Y,{as:"p",variant:"caption",tone:"muted",children:n})]}),e.suspendPayload!==void 0&&a.jsxs("div",{className:"space-y-2",children:[a.jsxs(Y,{as:"p",variant:"caption",tone:"muted",className:"flex items-center gap-2",children:[a.jsx(At,{children:a.jsx(tEn,{})}),"The step is asking"]}),a.jsxs(Kl,{open:s,onOpenChange:i,children:[a.jsxs(Cl,{className:Z(pr,"flex w-full items-center justify-between gap-2 rounded-lg px-3 py-2.5"),children:[a.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[a.jsx(At,{children:a.jsx(Na,{direction:"right",className:"text-muted-foreground"})}),a.jsx(Y,{as:"span",variant:"body",tone:"ink",className:"truncate",children:DIs(e.suspendPayload,e.stepId)})]}),a.jsx(Y,{as:"span",variant:"caption",tone:"muted",className:"shrink-0",children:MIs(e.suspendPayload)})]}),a.jsx(_l,{children:a.jsx("div",{"data-testid":"suspended-payload",className:"pt-2",children:a.jsx(Or,{value:JSON.stringify(e.suspendPayload,null,2),editable:!1,className:"w-full overflow-x-auto p-2",showCopyButton:!1})})})]})]}),a.jsxs("div",{className:"space-y-3",children:[a.jsxs(Y,{as:"p",variant:"caption",tone:"muted",className:"flex items-center gap-2",children:[a.jsx(At,{children:a.jsx(iEn,{})}),"Your response"]}),a.jsx("div",{className:"-mx-5",children:a.jsx(HSe,{schema:t,isSubmitLoading:o,submitButtonLabel:"Resume",submitButtonVariant:"primary",submitButtonIcon:a.jsx(Bc,{}),submitButtonFullWidth:!0,collapsible:!1,hideHeading:!0,hideInputTypeLabel:!0,onSubmit:c})})]})]})}function FIs({hidden:e,requestContext:t,canResume:n}){const{result:r,workflow:s,runId:i,isStreamingWorkflow:o}=g.useContext(Hl),l=Pgt(r,i),c=JFn(t),u=r?.status==="suspended"&&l.length>0&&!o;return!s||!u||!n?null:a.jsx("div",{hidden:e,"data-testid":"workflow-suspended-overlay",className:"pointer-events-none absolute top-12 right-2 z-30 w-95 max-w-[calc(100%-16px)] animate-in duration-300 fade-in-0 slide-in-from-top-2 motion-reduce:animate-none",children:a.jsx(LIs,{suspendedSteps:l,workflow:s,isStreaming:o,onResume:c})},i)}const Xtt={success:{label:"Completed",icon:dr},failed:{label:"Failed",icon:L0e},suspended:{label:"Needs input",icon:vS},waiting:{label:"Waiting",icon:v0},paused:{label:"Paused",icon:vS},skipped:{label:"Skipped",icon:xIn},running:{label:"Running",icon:fc},canceled:{label:"Canceled",icon:X3}},BIs={label:"Status unavailable",icon:RCn};function VIs({row:e,isSelected:t,isHovered:n,onSelectStep:r,onHoverStep:s,onOpenInput:i,onOpenOutput:o}){const l=Object.hasOwn(Xtt,e.status)?Xtt[e.status]:BIs,c=l.icon,u=oSe(e.status),d=e.stepId.slice(0,e.stepId.lastIndexOf(".")),f=e.isNestedEntry?e.stepId.slice(e.stepId.lastIndexOf(".")+1):e.stepId;return a.jsxs("div",{"data-testid":"workflow-timeline-row","data-workflow-step-key":e.stepId,onMouseEnter:()=>!e.isNestedEntry&&s(e.stepId),onMouseLeave:()=>!e.isNestedEntry&&s(null),className:Z("grid grid-cols-[minmax(130px,1fr)_minmax(64px,1fr)_56px_64px] items-center gap-3 rounded-md px-2 py-1","@max-[540px]/workflow-timeline:grid-cols-[minmax(0,1fr)_48px_64px] @max-[540px]/workflow-timeline:gap-x-1.5 @max-[540px]/workflow-timeline:gap-y-1 @max-[540px]/workflow-timeline:py-2",(t||n)&&"bg-fill-subtle"),children:[a.jsxs("button",{type:"button","aria-disabled":e.isNestedEntry,"aria-pressed":t,onClick:()=>{e.isNestedEntry||r(e.stepId)},title:e.stepId,className:Z("text-foreground","flex min-h-9 min-w-0 cursor-pointer items-center gap-2.5 text-left focus-visible:rounded-sm aria-disabled:cursor-default",Ri),children:[a.jsx("span",{"aria-label":l.label,className:Z("grid size-6 flex-none place-items-center rounded-md border border-border bg-background",Awt[u]),children:a.jsx(c,{"aria-hidden":!0,className:Z("size-3.5",e.status==="running"&&"motion-safe:animate-spin")})}),a.jsxs("span",{className:"min-w-0",children:[a.jsx(Y,{as:"span",variant:"meta",className:"block truncate",children:f}),e.isNestedEntry&&a.jsxs(Y,{as:"span",variant:"meta",tone:"muted",className:"flex min-w-0 items-center gap-1",children:[a.jsx(B0e,{"aria-hidden":!0,className:"size-3 shrink-0"}),a.jsx("span",{className:"truncate",children:d})]})]})]}),a.jsx("div",{className:"relative h-5 min-w-0 overflow-hidden rounded-sm bg-muted @max-[540px]/workflow-timeline:col-span-full @max-[540px]/workflow-timeline:row-start-2 @max-[540px]/workflow-timeline:ml-[34px]","aria-hidden":!0,children:e.timing&&a.jsx("div",{"data-testid":"workflow-timeline-bar","data-offset":e.timing.offsetPct,"data-width":e.timing.widthPct,className:Z("absolute top-0 h-full min-w-0.5 rounded-sm",qYn[u]),style:{left:`${e.timing.offsetPct}%`,width:`${e.timing.widthPct}%`}})}),a.jsx(Y,{as:"span",variant:"meta",tone:"muted",className:"text-right whitespace-nowrap",title:e.timing&&e.spansSuspension?"Includes time spent suspended waiting for input":void 0,children:e.timing?a.jsx(Y,{as:"span",variant:"meta",font:"mono",children:sf(e.timing.durationMs)}):a.jsx("span",{"aria-label":"Timing unavailable",children:"—"})}),a.jsxs("div",{className:"flex items-center",children:[a.jsx(de,{type:"button",variant:"ghost",size:"icon-sm",tooltip:"View step input",disabled:e.step.input===void 0,onClick:h=>i(e,h.currentTarget),children:a.jsx(IH,{})}),a.jsx(de,{type:"button",variant:"ghost",size:"icon-sm",tooltip:"View step output",disabled:e.step.output===void 0,onClick:h=>o(e,h.currentTarget),children:a.jsx(AH,{})})]})]})}const UIs=e=>e.includes("."),qIs=e=>e==="input"||e.endsWith(".input"),Jtt=1;function QIs(e,t){const n=aSe(e),r=n?.isLive?Math.max(t,n.start):n?.end;return{span:n&&r!==void 0?{start:n.start,end:r}:void 0,isLive:n?.isLive??!1,spansSuspension:n?.spansSuspension??!1}}function ZIs(e,t){const n=Object.entries(e).filter(([l])=>!qIs(l)).map(([l,c])=>({stepId:l,step:c,...QIs(c,t)})).sort((l,c)=>(l.span?.start??1/0)-(c.span?.start??1/0)||l.stepId.localeCompare(c.stepId)),r=n.flatMap(l=>l.span?[l.span]:[]),s=Math.min(...r.map(l=>l.start)),i=Math.max(s,...r.map(l=>l.end)),o=Math.max(i-s,1);return n.map(({stepId:l,step:c,span:u,isLive:d,spansSuspension:f})=>{let h;if(u){const p=u.end-u.start,m=Math.min((u.start-s)/o*100,100-Jtt),v=Math.min(Math.max(p/o*100,Jtt),100-m);h={durationMs:p,offsetPct:m,widthPct:v}}return{stepId:l,step:c,status:FG(c)?"suspended":c.status,timing:h,spansSuspension:f,isRunning:d,isNestedEntry:UIs(l)}})}function WIs(){const{steps:e}=u$(),{selectedStepId:t,hoverStepId:n,setSelectedStepId:r,setHoverStepId:s}=JH(),[i,o]=g.useState(()=>Date.now()),[l,c]=g.useState(!0),[u,d]=g.useState(!1),{showData:f}=bk(),h=g.useRef(null),p=ZIs(e,i),m=p.some(v=>v.isRunning);return fSt(h,{enabled:m&&!l}),g.useEffect(()=>{if(!m||l)return;const v=setInterval(()=>o(Date.now()),100);return()=>clearInterval(v)},[m,l]),p.length===0?null:a.jsx("div",{"data-testid":"workflow-timeline",className:"relative z-20 shrink-0 px-2 pb-2",children:a.jsxs(Kl,{open:!l,onOpenChange:v=>c(!v),className:Z(pr,"@container/workflow-timeline pointer-events-auto overflow-hidden rounded-xl"),children:[a.jsxs("div",{className:"flex items-center",children:[a.jsxs(Cl,{className:"flex min-h-11 min-w-0 flex-1 items-center gap-2 px-3.5 py-2.5 text-caption text-foreground hover:bg-fill-subtle","aria-label":l?"Expand timeline":"Collapse timeline",children:[a.jsx("span",{children:a.jsx(Vft,{"aria-hidden":!0,className:"size-4 text-muted-foreground"})}),a.jsx("span",{children:"Timeline"}),a.jsxs(Y,{as:"span",variant:"meta",tone:"muted",children:[p.length," events"]}),a.jsx("span",{className:"ml-auto",children:a.jsx(Na,{direction:"right",className:"size-4"})})]}),!l&&a.jsx(de,{variant:"ghost",size:"icon-sm",tooltip:u?"Restore timeline height":"Enlarge timeline","aria-pressed":u,onClick:()=>d(!u),className:"mr-2 shrink-0",children:u?a.jsx(xCn,{}):a.jsx(qft,{})})]}),a.jsx(_l,{children:a.jsx("div",{ref:h,"data-testid":"workflow-timeline-list",className:Z("overflow-auto overscroll-contain px-1.5 pb-1.5",u?"max-h-[min(720px,calc(100dvh-112px))]":"max-h-[min(320px,40dvh)]"),children:p.map(v=>a.jsx(VIs,{row:v,isSelected:t===v.stepId,isHovered:n===v.stepId,onSelectStep:r,onHoverStep:s,onOpenInput:(y,x)=>f({type:"step-input",stepId:y.stepId},x),onOpenOutput:(y,x)=>f({type:"step-output",stepId:y.stepId},x)},v.stepId))})})]})})}const HIs=({workflowId:e,workflow:t,isLoading:n})=>{const[r]=xr("workflow",e),{canExecute:s,isLoading:i}=Wa(),{stepDetail:o}=bk(),l=TP(),c=o?.type==="data",u=a.jsxs("div",{className:"[container-type:size] relative h-full min-h-0",children:[a.jsx(O4t,{workflowId:e,workflow:t,isLoading:n,requestContext:r}),a.jsx(FIs,{hidden:c,requestContext:r,canResume:!i&&s("workflows")}),c&&a.jsx("div",{className:"pointer-events-auto absolute top-12 right-2 z-30 flex max-h-[calc(100cqh-64px)] w-[440px] max-w-[calc(100%-16px)] flex-col",children:a.jsx(oV,{requestContext:r})}),a.jsx("div",{className:"pointer-events-none absolute right-0 bottom-0 left-[var(--workflow-left-panel-width,0px)] z-20",children:a.jsx(WIs,{})})]});return l&&o&&!c?a.jsx("div",{className:"h-full min-h-0 overflow-hidden",children:a.jsx(oV,{requestContext:r})}):a.jsxs("div",{className:"relative h-full min-h-0",children:[u,a.jsxs(m$,{className:"pointer-events-none absolute inset-0 z-30 min-h-0 w-full min-w-0 p-2",children:[a.jsx(lp,{id:"workflow-graph",className:"pointer-events-none min-w-0"}),o&&!c&&a.jsxs(a.Fragment,{children:[a.jsx(YS,{className:"pointer-events-auto"}),a.jsx(lp,{id:"workflow-step-detail",minSize:300,maxSize:"60%",defaultSize:420,className:"min-w-0",children:a.jsx("div",{className:"pointer-events-auto h-full min-h-0 overflow-hidden rounded-studio-panel border border-border bg-background",children:a.jsx(oV,{requestContext:r})})})]})]})]})},ent=()=>{const{workflowId:e}=jr(),{data:t,isLoading:n,error:r}=lL({workflowId:e,requestContext:xr("workflow",e)[0],queryOptions:{enabled:!!e}});return r&&js(r)?a.jsx(ai,{variant:"fill"}):r&&Cs(r)?a.jsx(Gs,{variant:"fill",resource:"workflows"}):a.jsx(HIs,{workflowId:e,workflow:t??void 0,isLoading:n})};function GIs(){const{workflowId:e}=jr(),{error:t}=aK(e?{workflowId:e}:{});if(!e)return null;let n;return t&&js(t)?n=a.jsx(ai,{variant:"fill"}):t&&Cs(t)?n=a.jsx(Gs,{variant:"fill",resource:"schedules"}):n=a.jsx("div",{className:"h-full",children:a.jsx(_qt,{workflowId:e})}),a.jsxs(Et,{children:[a.jsx("h1",{className:"sr-only",children:"Schedules"}),n]})}function KIs(){const{workflowId:e}=jr();return e?a.jsx(ZNe,{scopedEntityId:e,scopedEntityType:sd.WORKFLOW_RUN}):null}const Tqt=g.createContext(null);function Jc(){const e=g.useContext(Tqt);if(!e)throw new Error("Workspace components must be rendered inside <Workspace.Root>");return e}const YIs=e=>e?.status;function XIs(e,t){return js(e)?"Your session has expired. Sign in again to continue.":Cs(e)?"You don't have permission to access this.":kk(e)?"This path no longer exists.":YIs(e)===501?"This workspace does not support this operation.":t}function ree({error:e,fallback:t,className:n}){return a.jsx(Ht,{variant:"destructive",className:n,children:a.jsx(Ht.Message,{children:XIs(e,t)})})}const JIs=/^---\r?\n([\s\S]*?)\r?\n---[ \t]*(?:\r?\n|$)/;function eNs(e){const t=JIs.exec(e);return t?{frontmatter:t[1]??"",body:e.slice(t[0].length)}:{frontmatter:null,body:e}}function tNs({content:e}){const{frontmatter:t,body:n}=eNs(e);return a.jsxs(a.Fragment,{children:[t!==null&&a.jsx("div",{"data-testid":"workspace-frontmatter",className:"border-b border-border",children:a.jsx(n$,{code:t,lang:"yaml",overflow:"wrap",className:"rounded-none border-0 bg-transparent [&_pre]:p-4"})}),a.jsx("div",{className:"p-4",children:a.jsx(pc,{children:n})})]})}function nNs(){const{activeFilePath:e}=Jc();return e?a.jsx(Y,{as:"span",variant:"body-sm",font:"mono",tone:"muted",className:"truncate","data-testid":"workspace-file-path",children:e}):null}function rNs({path:e,content:t,mimeType:n}){return u$t(e,n)?a.jsx("div",{className:"flex justify-center p-4",children:a.jsx("img",{src:`data:${n||"image/png"};base64,${t}`,alt:e.split("/").pop(),className:"max-w-full object-contain"})}):d$t(e,n)?a.jsx("div",{className:"flex justify-center p-4",children:a.jsx("video",{controls:!0,"aria-label":e.split("/").pop(),className:"max-w-full",children:a.jsx("source",{src:`data:${YHe(e,n)};base64,${t}`,type:YHe(e,n)})})}):vLr(e)?a.jsx(tNs,{content:t}):a.jsx(n$,{code:t,lang:Ckt(e),overflow:"scroll",className:"rounded-none border-0 bg-transparent [&_pre]:p-4"})}function sNs({renderPreview:e}){const{workspaceId:t,activeFilePath:n}=Jc(),{data:r,isLoading:s,error:i}=CLr({workspaceId:t,path:n,queryOptions:{enabled:!!n}});if(!n)return null;if(s)return a.jsxs("div",{"aria-busy":"true",className:"flex flex-col gap-2 p-4",children:[a.jsx(xt,{className:"h-4 w-1/2"}),a.jsx(xt,{className:"h-4 w-5/6"}),a.jsx(xt,{className:"h-4 w-2/3"})]});if(!r)return a.jsx(ree,{error:i,fallback:"Could not load file.",className:"m-4"});const o={path:n,content:r.content,mimeType:r.mimeType};return e?.(o)??a.jsx(rNs,{...o})}const VA=".",Eqt=(e,t)=>e===VA?t:`${e}/${t}`,tnt=e=>e.split("/").slice(0,-1).map((t,n,r)=>r.slice(0,n+1).join("/")),Iqt=e=>{const t=e.lastIndexOf("/");return t===-1?VA:e.slice(0,t)};function Nqt({labeled:e=!1}={}){const{workspaceId:t,onCreateDirectory:n,isReadOnly:r}=Jc(),s=mr(),[i,o]=g.useState(!1),[l,c]=g.useState(""),[u,d]=g.useState(!1);if(!n||r(VA))return null;const f=l.trim().replace(/^\.?\/+|\/+$/g,""),h=async()=>{if(f){d(!0);try{await n(f),await s.invalidateQueries({queryKey:["workspace",t,"fs","list",Iqt(f)]}),o(!1),c("")}catch{}finally{d(!1)}}};return a.jsxs(a.Fragment,{children:[e?a.jsx(de,{variant:"ghost",icon:a.jsx(mS,{}),onClick:()=>o(!0),children:"New folder"}):a.jsx(de,{variant:"ghost",size:"icon-sm",tooltip:"New folder",onClick:()=>o(!0),children:a.jsx(mS,{})}),a.jsx(rs,{open:i,onOpenChange:o,pending:u,children:a.jsx(ss,{size:"sm",children:a.jsxs("form",{onSubmit:p=>{p.preventDefault(),h()},children:[a.jsx(es,{children:a.jsx(Gr,{children:"New folder"})}),a.jsx(Hr,{children:a.jsx(Sn,{autoFocus:!0,"aria-label":"Folder path",placeholder:"docs/guides",value:l,onChange:p=>c(p.target.value)})}),a.jsxs(Yo,{children:[a.jsx(Ca,{children:"Cancel"}),a.jsx(de,{type:"submit",variant:"primary",disabled:!f||u,children:"Create"})]})]})})})]})}function nnt(e){return`${e.topSource}/${e.name}`}function rnt(e){const t=f$t(e.topSource,e.name);return t?`${t.owner}/${t.repo}/${e.name}`:null}function iNs({open:e,onOpenChange:t,workspaceId:n,onInstall:r,isInstalling:s,installedSkillIds:i=[],installedSkillNames:o=[],writableMounts:l,installedSkillPaths:c}){const[u,d]=g.useState(""),[f,h]=g.useState(null),[p,m]=g.useState(),v=l?.some(Q=>Q.path===p)?p:l?.[0]?.path,{data:y,isLoading:x}=xLr({workspaceId:n,queryOptions:{enabled:!!n}}),b=yLr({workspaceId:n}),S=g.useMemo(()=>f?.topSource?f$t(f.topSource,f.name):null,[f]),k=g.useMemo(()=>!S||!f?null:`https://skills.sh/${S.owner}/${S.repo}/${f.name}`,[S,f]),{data:j,isLoading:C}=bLr({workspaceId:n,owner:S?.owner,repo:S?.repo,skillPath:f?.name,queryOptions:{enabled:!!n&&!!S&&!!f}}),T=Y0(Q=>{Q.trim().length>=2&&b.mutate(Q)},300),_=g.useCallback(Q=>{d(Q),T(Q)},[T]),N=g.useMemo(()=>u.trim().length>=2?b.data?.skills??[]:y?.skills??[],[u,b.data,y]),I=b.isPending,A=u.trim().length>=2,P=g.useMemo(()=>{if(!f)return!1;const Q=rnt(f);return!!(Q&&i.includes(Q)||o.includes(f.name))},[f,i,o]),D=g.useCallback(()=>{!f||!S||r({repository:`${S.owner}/${S.repo}`,skillName:f.name,mount:l&&l.length>1?v:void 0})},[f,S,r,l,v]),F=g.useCallback(Q=>{Q||(d(""),h(null),m(void 0)),t(Q)},[t]);return a.jsx(rs,{open:e,onOpenChange:F,pending:s,children:a.jsxs(ss,{size:"xl",className:"h-[80vh]",children:[a.jsxs(es,{children:[a.jsx(Gr,{children:"Add Skill"}),a.jsx(zo,{children:"Search and install skills from the community registry"})]}),a.jsxs(Hr,{layout:"fill",children:[a.jsx(qc,{label:"Search skills",placeholder:"Search skills...",value:u,onValueChange:_}),a.jsxs("div",{className:"flex min-h-0 flex-1 gap-4",children:[a.jsxs("div",{className:"flex min-h-0 w-1/2 flex-col",children:[a.jsx(Y,{as:"p",variant:"eyebrow",tone:"muted",className:"mb-2",children:A?"Search Results":"Popular Skills"}),a.jsx(Nr,{className:"flex-1 rounded-lg border border-border",children:a.jsx(af,{className:!x&&!I&&N.length===0?"flex flex-col [&>div]:flex [&>div]:flex-1 [&>div]:flex-col":void 0,children:x||I?a.jsx("div",{className:"flex items-center justify-center py-5",children:a.jsx(fc,{className:"size-6 animate-spin text-muted-foreground"})}):N.length===0?a.jsxs("div",{className:"flex flex-1 flex-col items-center-safe justify-center-safe py-5 text-muted-foreground",children:[a.jsx(X3,{className:"mb-2 size-8"}),a.jsx(Y,{children:A?"No skills found":"No skills available"})]}):a.jsx("div",{className:"space-y-1 p-2",children:N.map(Q=>{const q=nnt(Q),B=rnt(Q),V=B&&i.includes(B)||o.includes(Q.name),H=f?nnt(f):null;return a.jsx("button",{onClick:()=>h(Q),className:Z("w-full rounded-md px-3 py-2 text-left","hover:bg-fill-subtle",H===q&&"border border-border-strong bg-fill-hover"),children:a.jsxs("div",{className:"flex items-start justify-between gap-2",children:[a.jsxs("div",{className:"min-w-0 flex-1",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(Y,{as:"span",variant:"subheading",tone:"ink",className:"truncate",children:Q.name}),V&&a.jsxs(Y,{as:"span",variant:"meta",className:"inline-flex items-center gap-1 rounded bg-info-subtle px-1.5 py-0.5 text-info-subtle-foreground",children:[a.jsx(dr,{className:"size-2.5"}),"Installed"]})]}),a.jsx(Y,{as:"p",variant:"caption",tone:"muted",className:"truncate",children:Q.topSource})]}),a.jsxs("div",{className:"flex shrink-0 items-center gap-1 text-muted-foreground",children:[a.jsx(hp,{className:"size-3"}),a.jsx(Y,{as:"span",variant:"caption",children:Q.installs.toLocaleString()})]})]})},q)})})})})]}),a.jsxs("div",{className:"flex min-h-0 w-1/2 flex-col",children:[a.jsx(Y,{as:"p",variant:"eyebrow",tone:"muted",className:"mb-2",children:"Preview"}),a.jsx("div",{className:"flex flex-1 flex-col overflow-hidden rounded-lg border border-border",children:f?a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"border-b border-border bg-card p-4",children:a.jsxs("div",{className:"flex items-start gap-3",children:[a.jsx("div",{className:"rounded-lg bg-muted p-2",children:a.jsx(T6,{className:"size-5 text-muted-foreground"})}),a.jsxs("div",{className:"min-w-0 flex-1",children:[a.jsx(Y,{as:"h3",variant:"subheading",tone:"ink",className:"truncate",children:f.name}),a.jsxs("div",{className:"mt-1 flex items-center gap-3 text-muted-foreground",children:[a.jsxs("span",{className:"flex items-center gap-1",children:[a.jsx(oX,{className:"size-3"}),a.jsx(Y,{as:"span",variant:"caption",className:"block",children:f.topSource})]}),a.jsxs("span",{className:"flex items-center gap-1",children:[a.jsx(hp,{className:"size-3"}),a.jsxs(Y,{as:"span",variant:"caption",className:"block",children:[f.installs.toLocaleString()," installs"]})]})]})]}),S&&a.jsx("a",{href:`https://github.com/${S.owner}/${S.repo}`,target:"_blank",rel:"noopener noreferrer",className:Z(Fn,jn),title:"View on GitHub",children:a.jsx(Zs,{className:"size-4"})})]})}),C?a.jsx("div",{className:"flex flex-1 items-center justify-center",children:a.jsx(fc,{className:"size-6 animate-spin text-muted-foreground"})}):j?a.jsx(Nr,{className:"flex-1",children:a.jsx("div",{className:"p-4",children:a.jsx(pc,{children:j})})}):a.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center text-muted-foreground",children:[a.jsx(F1,{className:"mb-2 size-8"}),a.jsx(Y,{children:"Preview unavailable"}),k&&a.jsxs("a",{href:k,target:"_blank",rel:"noopener noreferrer",className:"mt-2 flex items-center gap-1 text-info-indicator hover:underline",children:[a.jsxs(Y,{as:"span",variant:"caption",className:"block",children:["View on skills.sh"," "]}),a.jsx(Zs,{className:"size-3"})]})]})]}):a.jsxs("div",{className:"flex h-full flex-col items-center justify-center text-muted-foreground",children:[a.jsx(F1,{className:"mb-2 size-8"}),a.jsx(Y,{children:"Select a skill to preview"})]})})]})]}),f&&l&&l.length>1&&a.jsxs(ft,{orientation:"horizontal",className:Z(pr,"gap-3 rounded-lg p-3"),children:[a.jsx(fP,{className:"size-4 shrink-0 text-muted-foreground"}),a.jsx(ut,{className:"whitespace-nowrap",children:"Install to"}),a.jsxs(Vr,{value:v,onValueChange:m,children:[a.jsx(qr,{className:"flex-1",children:a.jsx(Ur,{})}),a.jsx(Qr,{children:l.map(Q=>{const q=Q.displayName??Q.name??Q.provider??"unknown";return a.jsxs(ir,{value:Q.path,children:[q," (",Q.path,")"]},Q.path)})})]})]})]}),f&&a.jsxs(Yo,{children:[P&&l&&l.length>1&&(()=>{const Q=c?.[f.name];if(!Q)return null;const q=l.find(B=>Q.startsWith(B.path+"/")||Q===B.path);return q?a.jsxs(Y,{as:"span",variant:"caption",tone:"muted",className:"mr-auto",children:["Installed at ",q.path]}):null})(),a.jsx(Ca,{children:"Cancel"}),a.jsx(ja,{onConfirm:D,disabled:!S||P,"data-testid":"install-skill-button",children:s?"Installing...":P?"Already Installed":"Install"})]})]})})}function Aqt({labeled:e=!1}){const{workspaceId:t,addSkill:n}=Jc(),[r,s]=g.useState(!1),[i,o]=g.useState(!1);if(!n)return null;const{onInstall:l,...c}=n,u=async d=>{o(!0);try{await l(d),s(!1)}catch{}finally{o(!1)}};return a.jsxs(a.Fragment,{children:[e?a.jsxs(de,{variant:"ghost",onClick:()=>s(!0),children:[a.jsx(bfe,{}),"Add skill"]}):a.jsx(de,{variant:"ghost",size:"icon-sm","aria-label":"Add skill",tooltip:"Add skill",onClick:()=>s(!0),children:a.jsx(bfe,{})}),a.jsx(iNs,{...c,open:r,onOpenChange:s,workspaceId:t,onInstall:d=>{u(d)},isInstalling:i})]})}function oNs({workspaceId:e,activeFilePath:t,onDelete:n,onCreateDirectory:r,onActiveFileChange:s,readOnlyPaths:i,searchFiles:o=!0,searchSkills:l=!0,fileCount:c,skillCount:u,addSkill:d,children:f}){const[h,p]=g.useState(!1),[m,v]=g.useState(""),[y,x]=g.useState(()=>new Set(tnt(t??""))),[b,S]=g.useState(t);if(t!==b){S(t);const C=tnt(t??"").filter(T=>!y.has(T));C.length>0&&x(new Set([...y,...C]))}const k=i?.join(`
|
|
700
700
|
`)??"",j=g.useMemo(()=>({workspaceId:e,activeFilePath:t,setActiveFilePath:s,isSearching:h,setSearching:C=>{p(C),C||v("")},query:m,setQuery:v,onDelete:n,onCreateDirectory:r,isReadOnly:C=>(k?k.split(`
|
|
701
701
|
`):[]).some(_=>_==="."||C===_||C.startsWith(`${_}/`)),searchFiles:o,searchSkills:l,fileCount:c,skillCount:u,addSkill:d,openFolders:y,setFolderOpen:(C,T)=>x(_=>{if(_.has(C)===T)return _;const N=new Set(_);return T?N.add(C):N.delete(C),N})}),[e,t,h,m,n,r,s,k,o,l,c,u,d,y]);return a.jsx(Tqt.Provider,{value:j,children:f})}const Pqt=e=>a.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:a.jsx("path",{d:"M9 1.5H4C3.44772 1.5 3 1.94772 3 2.5V13.5C3 14.0523 3.44772 14.5 4 14.5H12C12.5523 14.5 13 14.0523 13 13.5V5.5M9 1.5L13 5.5M9 1.5V5.5H13",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round"})}),aNs=e=>a.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:a.jsx("path",{d:"M7.25 12.5C10.1495 12.5 12.5 10.1495 12.5 7.25C12.5 4.35051 10.1495 2 7.25 2C4.35051 2 2 4.35051 2 7.25C2 10.1495 4.35051 12.5 7.25 12.5ZM11 11L14 14",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round"})});function lNs(){const{isSearching:e,setSearching:t,searchFiles:n,searchSkills:r}=Jc();return!n&&!r?null:a.jsx(de,{variant:"ghost",size:"icon-sm",tooltip:"Search files and skills","aria-pressed":e,onClick:()=>t(!e),children:a.jsx(aNs,{})})}function cNs(){const{isSearching:e}=Jc();return e?a.jsx(dNs,{}):a.jsx(uNs,{})}const snt=(e,t)=>`${e} ${t}${e===1?"":"s"}`;function uNs(){const{fileCount:e,skillCount:t}=Jc();return a.jsxs(Y,{as:"span",variant:"label",tone:"muted",className:"block min-w-0 truncate",children:[a.jsx("span",{children:e===void 0?"Files":snt(e,"File")}),t===void 0?null:a.jsxs(a.Fragment,{children:[a.jsx(Y,{as:"span",variant:"label",tone:"faint","aria-hidden":!0,className:"mx-1.5",children:"·"}),a.jsx("span",{children:snt(t,"Skill")})]})]})}function dNs(){const{setSearching:e,setQuery:t}=Jc(),[n,r]=g.useState(""),[,s]=g.useTransition();return a.jsxs("div",{className:"flex items-center gap-1",children:[a.jsx(Sn,{type:"search",size:"sm",autoFocus:!0,"aria-label":"Search query",placeholder:"Search files and skills",value:n,onChange:i=>{const o=i.target.value;r(o),s(()=>t(o))},onKeyDown:i=>{i.key==="Escape"&&e(!1)}}),a.jsx(de,{variant:"ghost",size:"icon-sm",tooltip:"Close search",onClick:()=>e(!1),children:a.jsx(Dn,{})})]})}function fNs(){const{workspaceId:e,query:t,activeFilePath:n,setActiveFilePath:r,searchFiles:s,searchSkills:i}=Jc(),{data:o,isLoading:l,isError:c,error:u}=ILr({workspaceId:e,query:t,files:s,skills:i,queryOptions:{enabled:t.trim().length>0&&(s||i)}});return t.trim()?l?a.jsxs("div",{"aria-busy":"true",className:"flex flex-col gap-2 p-2",children:[a.jsx(xt,{className:"h-4 w-3/4"}),a.jsx(xt,{className:"h-4 w-2/3"})]}):c?a.jsx(ree,{error:u,fallback:"Search failed.",className:"m-2"}):o?.length?a.jsx("ul",{"aria-label":"Search results",className:"flex flex-col py-1",children:o.map(d=>a.jsx("li",{children:a.jsxs("button",{type:"button",title:d.path,onClick:()=>r(d.path),className:Z("text-foreground","flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left hover:bg-fill-subtle",n===d.path&&"bg-fill"),children:[a.jsx(At,{size:"sm",children:d.kind==="skill"?a.jsx(T6,{}):a.jsx(Pqt,{})}),a.jsx(Y,{as:"span",variant:"body-sm",className:"truncate",children:d.label})]})},d.path))}):a.jsx(Xt,{titleSlot:"No results"}):a.jsx(Xt,{titleSlot:"Search files and skills",descriptionSlot:"Type to find matching content."})}function hNs({mount:e}){switch(e.icon||e.provider){case"aws-s3":case"s3":return a.jsx(PPt,{className:"text-foreground"});case"google-cloud":case"google-cloud-storage":case"gcs":return a.jsx(RPt,{});case"azure-blob":case"azure":return a.jsx($Pt,{className:"text-badge-blue-indicator"});case"cloudflare":case"cloudflare-r2":case"r2":return a.jsx(yfe,{className:"text-badge-orange-indicator"});case"minio":return a.jsx(xfe,{className:"text-badge-red-indicator"});case"database":return a.jsx(cx,{className:"text-badge-green-indicator"});case"local":case"folder":return a.jsx(fP,{className:"text-badge-amber-indicator"});case"hard-drive":return a.jsx(xfe,{className:"text-muted-foreground"});default:return a.jsx(yfe,{className:"text-muted-foreground"})}}const pNs=e=>a.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:a.jsx("path",{d:"M2.5 4H13.5M6 4V2.5H10V4M4 4L4.75 13.5H11.25L12 4M6.75 6.5V11M9.25 6.5V11",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round"})}),mNs=e=>{const t=["B","KB","MB","GB","TB"],n=e>0?Math.min(Math.floor(Math.log(e)/Math.log(1024)),t.length-1):0;return`${parseFloat((e/1024**n).toFixed(1))} ${t[n]}`};function gNs(){const{workspaceId:e,activeFilePath:t,setActiveFilePath:n}=Jc(),{data:r,isLoading:s,error:i}=k6({workspaceId:e,path:VA}),[o,l]=g.useState(null);return s?a.jsx(wNs,{}):r?a.jsxs(a.Fragment,{children:[a.jsx(kr,{"aria-label":"Workspace files",selectedId:t,onSelect:n,className:"py-1",children:a.jsx($qt,{entries:r,parent:VA,onRequestDelete:l})}),a.jsx(bNs,{entry:o,onClose:()=>l(null)})]}):a.jsx(ree,{error:i,fallback:"Could not load files.",className:"m-2"})}function $qt({entries:e,parent:t,onRequestDelete:n}){return e.map(r=>{const s=Eqt(t,r.name);return r.type==="directory"?a.jsx(vNs,{name:r.name,path:s,mount:r.mount,onRequestDelete:n},r.name):a.jsx(xNs,{name:r.name,size:r.size,path:s,onRequestDelete:n},r.name)})}function Rqt({children:e}){return a.jsx("span",{className:"ml-auto flex shrink-0 items-center gap-1 opacity-0 group-focus-within:opacity-100 group-hover:opacity-100",children:e})}function Mqt({name:e,onClick:t}){return a.jsx(de,{variant:"destructive-ghost",size:"icon-sm",tooltip:`Delete ${e}`,onClick:n=>{n.stopPropagation(),t()},onKeyDown:n=>n.stopPropagation(),children:a.jsx(pNs,{})})}function vNs({name:e,path:t,mount:n,onRequestDelete:r}){const{workspaceId:s,onDelete:i,onCreateDirectory:o,isReadOnly:l,openFolders:c,setFolderOpen:u}=Jc(),d=c.has(t),{isLoading:f}=k6({workspaceId:s,path:t,queryOptions:{enabled:d}}),[h,p]=g.useState(!1),m=i&&!l(t),v=o&&!l(t);return a.jsxs(kr.Folder,{id:t,open:d,onOpenChange:y=>u(t,y),children:[a.jsxs(kr.FolderTrigger,{actions:m||v?a.jsxs(Rqt,{children:[v?a.jsx(de,{variant:"ghost",size:"icon-sm",tooltip:`New folder in ${e}`,onClick:y=>{y.stopPropagation(),u(t,!0),p(!0)},onKeyDown:y=>y.stopPropagation(),children:a.jsx(mS,{})}):null,m?a.jsx(Mqt,{name:e,onClick:()=>r({path:t,type:"directory"})}):null]}):void 0,children:[a.jsx(kr.Icon,{children:n?a.jsx("span",{role:"img","aria-label":`Mount: ${n.displayName??n.provider}`,title:[n.displayName??n.provider,n.description].filter(Boolean).join(" — "),className:"flex",children:a.jsx(hNs,{mount:n})}):a.jsx(vVt,{})}),a.jsx(kr.Label,{children:e}),n?.status==="error"?a.jsx("span",{role:"img","aria-label":`Mount error: ${n.error??"unavailable"}`,title:n.error,className:"flex shrink-0",children:a.jsx(uP,{className:"size-3 text-destructive-foreground"})}):null,n&&l(t)?a.jsx("span",{role:"img","aria-label":"Read-only",title:"Read-only",className:"flex shrink-0",children:a.jsx(Tu,{className:"size-3 text-muted-foreground"})}):null,d&&f?a.jsx("span",{className:"flex shrink-0 animate-in delay-200 fill-mode-backwards fade-in",children:a.jsx(En,{size:"sm","aria-label":`Loading ${e}`,className:"size-3 text-muted-foreground"})}):null]}),a.jsx(kr.FolderContent,{children:d?a.jsx(yNs,{path:t,creating:h,onCreated:()=>p(!1),onRequestDelete:r}):null})]})}function yNs({path:e,creating:t,onCreated:n,onRequestDelete:r}){const{workspaceId:s,onCreateDirectory:i}=Jc(),o=mr(),{data:l,isLoading:c,error:u}=k6({workspaceId:s,path:e}),d=async f=>{try{await i?.(Eqt(e,f.replace(/^\/+|\/+$/g,"")))}catch{return}n(),await o.invalidateQueries({queryKey:["workspace",s,"fs","list",e]})};return a.jsxs(a.Fragment,{children:[t?a.jsx(kr.Input,{type:"folder",placeholder:"Folder name",onSubmit:f=>{d(f)},onCancel:n}):null,c?null:l?a.jsx($qt,{entries:l,parent:e,onRequestDelete:r}):a.jsx(ree,{error:u,fallback:"Could not load folder.",className:"my-1 mr-1"})]})}function xNs({name:e,size:t,path:n,onRequestDelete:r}){const{onDelete:s,isReadOnly:i,activeFilePath:o}=Jc(),l=s&&!i(n),c=n===o,u=g.useRef(null);return g.useEffect(()=>{c&&u.current?.scrollIntoView?.({block:"nearest"})},[c]),a.jsxs(kr.File,{ref:u,id:n,children:[a.jsx(kr.Icon,{children:a.jsx(Pqt,{})}),a.jsx(kr.Label,{children:e}),a.jsxs(Rqt,{children:[t!==void 0?a.jsx(Y,{as:"span",variant:"caption",tone:"faint",font:"mono",children:mNs(t)}):null,l?a.jsx(Mqt,{name:e,onClick:()=>r({path:n,type:"file"})}):null]})]})}function bNs({entry:e,onClose:t}){const{workspaceId:n,activeFilePath:r,setActiveFilePath:s,onDelete:i}=Jc(),o=mr(),[l,c]=g.useState(!1),u=e?.path.split("/").pop(),d=async()=>{if(!(!e||!i)){c(!0);try{await i(e)}catch{return}finally{c(!1)}(r===e.path||r?.startsWith(`${e.path}/`))&&s(void 0),o.removeQueries({queryKey:["workspace",n,"fs","list",e.path]}),await o.invalidateQueries({queryKey:["workspace",n,"fs","list",Iqt(e.path)]}),t()}};let f=null;return e&&(f=e.type==="directory"?`This permanently deletes the folder "${u}" and everything inside it.`:`This permanently deletes "${u}".`),a.jsx(Ut,{open:e!==null,onOpenChange:h=>{!h&&!l&&t()},children:a.jsxs(Ut.Content,{children:[a.jsxs(Ut.Header,{children:[a.jsxs(Ut.Title,{children:["Delete ",e?.type==="directory"?"folder":"file","?"]}),a.jsxs(Ut.Description,{children:[f," This action cannot be undone."]})]}),a.jsxs(Ut.Footer,{children:[a.jsx(Ut.Cancel,{disabled:l,children:"Cancel"}),a.jsx(de,{variant:"destructive",disabled:l,onClick:()=>{d()},children:l?"Deleting…":"Delete"})]})]})})}function wNs(){return a.jsxs("div",{"data-testid":"workspace-tree-skeleton","aria-busy":"true",className:"flex flex-col gap-2 py-2 pl-[18px]",children:[a.jsx(xt,{className:"h-4 w-3/4"}),a.jsx(xt,{className:"h-4 w-1/2"}),a.jsx(xt,{className:"h-4 w-2/3"})]})}function SNs({children:e,...t}){return a.jsx(oNs,{...t,children:a.jsx(kNs,{children:e})})}function kNs({children:e}){const{workspaceId:t}=Jc(),{data:n,error:r}=k6({workspaceId:t,path:VA});return(n?n.length===0:kk(r))?a.jsx(Xt,{variant:"fill",titleSlot:"This workspace is empty",descriptionSlot:"Files written by your agents will show up here.",actionSlot:a.jsxs("div",{className:"flex flex-wrap items-center justify-center gap-2",children:[a.jsx(Nqt,{labeled:!0}),a.jsx(Aqt,{labeled:!0})]})}):a.jsx("div",{className:"size-full overflow-hidden",children:a.jsx(m$,{className:"size-full min-h-0 min-w-0",orientation:"horizontal",children:e})})}function ONs({children:e}){return a.jsxs(a.Fragment,{children:[a.jsx(tNe,{direction:"left",id:"workspace-aside",minSize:200,maxSize:"50%",defaultSize:"25%",collapsible:!1,className:"min-w-0",children:a.jsx("div",{className:"flex h-full min-h-0 flex-col",children:e})}),a.jsx(YS,{className:"w-px bg-border"})]})}function jNs({children:e,actions:t}){const{isSearching:n}=Jc();return a.jsxs("div",{className:"flex h-11 shrink-0 items-center gap-2 border-b border-border px-3",children:[a.jsx("div",{className:"min-w-0 flex-1",children:e}),t&&!n?a.jsx("div",{className:"flex shrink-0 items-center gap-1",children:t}):null]})}function CNs(){const{isSearching:e}=Jc();return a.jsx(Nr,{className:"min-h-0 flex-1 px-2 py-1",children:e?a.jsx(fNs,{}):a.jsx(gNs,{})})}function _Ns({children:e}){return a.jsx(lp,{id:"workspace-active-file",className:"flex min-w-0 flex-col",minSize:30,children:e})}function TNs({children:e}){return a.jsx("div",{className:"flex h-11 shrink-0 items-center gap-2 border-b border-border px-4",children:e})}function ENs({renderPreview:e}){const{activeFilePath:t}=Jc();return t?a.jsx(Nr,{className:"min-h-0 flex-1",children:a.jsx(sNs,{renderPreview:e})}):a.jsx(Xt,{variant:"fill",titleSlot:"Select a file"})}const Pg={Root:SNs,Aside:ONs,AsideHeader:jNs,Search:cNs,SearchToggle:lNs,CreateDirectory:Nqt,Tree:CNs,ActiveFile:_Ns,ActiveFileHeader:TNs,FilePath:nNs,ActiveFileContent:ENs};function INs({asideActions:e,renderPreview:t,...n}){return a.jsxs(Pg.Root,{...n,children:[a.jsxs(Pg.Aside,{children:[a.jsx(Pg.AsideHeader,{actions:a.jsxs(a.Fragment,{children:[a.jsx(Pg.SearchToggle,{}),a.jsx(Pg.CreateDirectory,{}),a.jsx(Aqt,{}),e]}),children:a.jsx(Pg.Search,{})}),a.jsx(Pg.Tree,{})]}),a.jsxs(Pg.ActiveFile,{children:[a.jsx(Pg.ActiveFileHeader,{children:a.jsx(Pg.FilePath,{})}),a.jsx(Pg.ActiveFileContent,{renderPreview:t})]})]})}const NNs=()=>a.jsx(Xt,{titleSlot:"No Workspaces yet",descriptionSlot:a.jsxs(a.Fragment,{children:["Add a workspace to your Mastra configuration to ",a.jsx("br",{}),"manage files, skills, and enable semantic search."]}),actionSlot:a.jsx(de,{variant:"ghost",render:a.jsx("a",{href:"https://mastra.ai/en/docs/workspace/overview",target:"_blank",rel:"noopener noreferrer"}),icon:a.jsx(Zs,{}),children:"Workspaces Documentation"}),variant:"fill"}),ANs=()=>a.jsx(Xt,{titleSlot:"Workspace Not Configured",descriptionSlot:a.jsxs(a.Fragment,{children:["No workspace is configured. Add a workspace to your ",a.jsx("br",{}),"Mastra configuration to manage files, skills, and enable semantic search."]}),actionSlot:a.jsx(de,{variant:"ghost",render:a.jsx("a",{href:"https://mastra.ai/en/docs/workspace/overview",target:"_blank",rel:"noopener noreferrer"}),icon:a.jsx(Zs,{}),children:"Workspaces Documentation"}),variant:"fill"}),PNs=()=>a.jsx(Xt,{titleSlot:"Workspace Not Supported",descriptionSlot:a.jsxs(a.Fragment,{children:["The workspace feature requires a newer version of ",a.jsx("code",{className:"text-foreground",children:"@mastra/core"}),".",a.jsx("br",{}),"Please upgrade your dependencies to enable workspace functionality."]}),actionSlot:a.jsx(de,{variant:"ghost",render:a.jsx("a",{href:"https://mastra.ai/en/docs/workspace/overview",target:"_blank",rel:"noopener noreferrer"}),icon:a.jsx(Zs,{}),children:"Workspaces Documentation"}),variant:"fill"}),bue=".agents/skills",$Ns=e=>e.replace(/^\.?\/+|\/+$/g,"");function RNs({workspaceId:e,showInitWarning:t,skills:n}){const{data:r}=k6({workspaceId:e,path:bue,queryOptions:{enabled:!!n}}),s=n&&r?r.filter(i=>i.type==="directory"&&!n.some(o=>o.name===i.name||$Ns(o.path)===`${bue}/${i.name}`)):[];return!t&&s.length===0?null:a.jsxs("div",{className:"flex shrink-0 flex-col gap-2 border-b border-border p-3",children:[t&&a.jsx(Ht,{variant:"warning",children:a.jsxs(Ht.Message,{children:["File search requires ",a.jsx("code",{children:"workspace.init()"})," to index files from your configured"," ",a.jsx("code",{children:"autoIndexPaths"}),"."]})}),s.length>0&&a.jsx(Ht,{variant:"warning",title:"Skills installed but not discovered",children:a.jsxs(Ht.Message,{children:[s.map(i=>i.name).join(", ")," ",s.length===1?"is":"are"," in"," ",a.jsx("code",{children:bue})," but not discovered. Add this path to your workspace skills configuration to see ",s.length===1?"it":"them","."]})})]})}const Gw=[_s("/workspaces")],int=e=>Cs(e)?"you don't have permission to modify this workspace":e instanceof Error?e.message:"Unknown error";function ont(){const{workspaceId:e}=jr(),[t,n]=oi(),r=Dr(),s=mr(),i=t.get("file"),{data:o,error:l,isLoading:c}=p$t(),u=o?.workspaces??[],d=e??u[0]?.id,{data:f,isLoading:h,error:p}=h$t({workspaceId:d,queryOptions:{enabled:!!d}}),m=js(l)||js(p),v=Cs(l)||Cs(p),y=Fge(l)||Fge(p),x=d?u.find(pe=>pe.id===d):void 0,b=pe=>{const ke=new URLSearchParams(t);for(const[Ee,Ue]of Object.entries(pe))Ue===null?ke.delete(Ee):ke.set(Ee,Ue);n(ke)},S=pe=>{r(`/workspaces/${pe}`)},k=pe=>{b({file:pe??null})},j=i??void 0,C=OLr(),T=jLr(),{data:_,refetch:N}=NLr({workspaceId:d,queryOptions:{enabled:!!d}}),I=wLr(),A=SLr(),P=kLr(),D=pe=>{const ke=/^\.agents\/skills\/([^/]+)$/.exec(pe);return ke?ue.find(Ue=>Ue.path?.replace(/^\.?\/+|\/+$/g,"")===pe)?.name??ke[1]:void 0},F=async()=>{if(d)try{const pe=await A.mutateAsync({workspaceId:d}),ke=pe.updated.filter(Ee=>!Ee.success);ke.length>0?Ke.error(`Failed to update ${ke.map(Ee=>Ee.skillName).join(", ")}`):Ke.success(`${pe.updated.length} skill(s) updated`),s.invalidateQueries({queryKey:["workspace",d,"fs"]})}catch(pe){Ke.error(`Failed to update skills: ${pe instanceof Error?pe.message:"Unknown error"}`)}},Q=async({path:pe,type:ke})=>{if(!d)return;const Ee=ke==="directory"?D(pe):void 0;if(!Ee){try{await C.mutateAsync({path:pe,recursive:!0,force:!0,workspaceId:d})}catch(Ue){throw Ke.error(`Failed to delete ${pe}: ${int(Ue)}`),Ue}return}try{if(!(await P.mutateAsync({workspaceId:d,skillName:Ee})).success)throw new Error(`Failed to remove skill "${Ee}"`);Ke.success(`Skill "${Ee}" removed`),N()}catch(Ue){throw Ke.error(Ue instanceof Error?Ue.message:"Failed to remove skill"),Ue}},q=f?.isWorkspaceConfigured??!1,B=f?.capabilities?.hasFilesystem??!1,V=f?.capabilities?.hasSkills??!1,H=x?.safety?.readOnly??!1,{canEdit:M,canDelete:G,canExecute:L,isLoading:$}=Wa(),z=!$&&M("workspaces")&&!H,U=!$&&G("workspaces")&&!H,K=!$&&L("workspaces"),ne=B&&V&&z,X=f?.mounts,te=X?.filter(pe=>!pe.readOnly).map(pe=>({path:pe.path,displayName:pe.displayName,icon:pe.icon,provider:pe.provider,name:pe.name})),ie=async pe=>{if(d)try{const ke=await I.mutateAsync({...pe,workspaceId:d});if(!ke.success)throw new Error("Unknown error");s.invalidateQueries({queryKey:["workspace",d,"fs"]}),N(),Ke.success(`Skill "${ke.skillName}" installed successfully (${ke.filesWritten} files)`)}catch(ke){throw Ke.error(`Failed to install skill: ${ke instanceof Error?ke.message:"Unknown error"}`),ke}},ue=_?.skills??[],ee=_?.isSkillsConfigured??!1,se=K&&B&&!!(f?.capabilities?.canBM25||f?.capabilities?.canVector),re=K&&V&&ee&&ue.length>0,ae=H?["."]:(X??[]).filter(pe=>pe.readOnly).map(pe=>pe.path.replace(/^\/+|\/+$/g,"")||".");if(c)return a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:Gw}),children:[a.jsx("h1",{className:"sr-only",children:"Workspaces"}),a.jsx(En,{fill:!0})]});if(m)return a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:Gw}),children:[a.jsx("h1",{className:"sr-only",children:"Workspaces"}),a.jsx(ai,{variant:"fill"})]});if(v)return a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:Gw}),children:[a.jsx("h1",{className:"sr-only",children:"Workspaces"}),a.jsx(Gs,{variant:"fill",resource:"workspaces"})]});if(y)return a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:Gw}),children:[a.jsx("h1",{className:"sr-only",children:"Workspaces"}),a.jsx(PNs,{})]});const he=l||p;if(he)return a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:Gw}),children:[a.jsx("h1",{className:"sr-only",children:"Workspaces"}),a.jsx(Xt,{tone:"error",variant:"fill",titleSlot:"Failed to load workspace",descriptionSlot:he.message})]});if(!c&&u.length===0)return a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:Gw}),children:[a.jsx("h1",{className:"sr-only",children:"Workspaces"}),a.jsx(NNs,{})]});if(!h&&!c&&!q)return a.jsxs(Et,{breadcrumbs:a.jsx(Dt,{crumbs:Gw}),children:[a.jsx("h1",{className:"sr-only",children:"Workspaces"}),a.jsx(ANs,{})]});const ve=u.map(pe=>({value:pe.id,label:pe.name,description:pe.source==="agent"?`Agent: ${pe.agentName}`:"Global workspace",end:a.jsxs("span",{className:"flex shrink-0 gap-1",children:[pe.safety?.readOnly&&a.jsx(Mt,{size:"xs",variant:"warning",children:"Read-only"}),pe.capabilities.hasFilesystem&&a.jsx(Mt,{size:"xs",children:"FS"}),pe.capabilities.hasSandbox&&a.jsx(Mt,{size:"xs",children:"Sandbox"}),pe.capabilities.hasSkills&&a.jsx(Mt,{size:"xs",children:"Skills"})]})}));return a.jsxs(Et,{variant:"fit",breadcrumbs:a.jsx(Dt,{crumbs:Gw}),headerActions:a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(Qa,{"aria-label":"Workspace",variant:"ghost",className:"w-auto",options:ve,value:x?.id,onValueChange:S,placeholder:"Select workspace",searchPlaceholder:"Search workspaces...",emptyText:"No workspaces found."}),H&&a.jsx(Mt,{size:"xs",variant:"warning",children:"Read-only"})]}),children:[a.jsx("h1",{className:"sr-only",children:"Workspaces"}),a.jsxs("div",{className:"flex min-h-0 flex-col",children:[B&&d&&a.jsx(RNs,{workspaceId:d,showInitWarning:se&&!h&&f?.status!=="ready",skills:V&&_?ue:void 0}),B&&d&&a.jsx("div",{className:"min-h-0 flex-1",children:a.jsx(INs,{workspaceId:d,activeFilePath:j,onActiveFileChange:k,readOnlyPaths:ae,skillCount:V&&_?ue.length:void 0,searchFiles:se,searchSkills:re,onCreateDirectory:z?async pe=>{try{await T.mutateAsync({path:pe,recursive:!0,workspaceId:d})}catch(ke){throw Ke.error(`Failed to create ${pe}: ${int(ke)}`),ke}}:void 0,asideActions:ne&&ue.some(pe=>pe.path?.includes(".agents/skills/"))?a.jsx(de,{variant:"ghost",size:"icon-sm",tooltip:"Update skills",disabled:A.isPending,onClick:()=>{F()},children:a.jsx(ux,{className:A.isPending?"animate-spin":void 0})}):void 0,addSkill:ne?{onInstall:ie,installedSkillIds:ue.filter(pe=>pe.skillsShSource).map(pe=>`${pe.skillsShSource.owner}/${pe.skillsShSource.repo}/${pe.name}`),installedSkillNames:ue.filter(pe=>!pe.skillsShSource).map(pe=>pe.name),writableMounts:te,installedSkillPaths:Object.fromEntries(ue.filter(pe=>pe.path).map(pe=>[pe.name,pe.path]))}:void 0,onDelete:U?Q:void 0},d)}),!B&&!h&&a.jsx("div",{className:"min-h-0 flex-1",children:a.jsx(Xt,{variant:"fill",titleSlot:"No filesystem or skills configured",descriptionSlot:"Add a filesystem or skills to this workspace to browse its files here."})})]})]})}function Dqt({children:e,className:t,mobileHeader:n,ref:r,sidebar:s,...i}){return a.jsxs("div",{ref:r,"data-slot":"app-shell",className:Z("h-full min-h-0",s&&"lg:grid lg:grid-cols-[auto_minmax(0,1fr)] lg:grid-rows-[1fr]",t),...i,children:[s,a.jsxs("div",{"data-slot":"app-shell-content",className:"flex h-full min-h-0 min-w-0 flex-col",children:[n,a.jsx("div",{"data-slot":"app-shell-body",className:Z("flex min-h-0 flex-1 flex-col","max-lg:p-1.5 lg:py-2 lg:pr-2",s?"lg:pl-0":"lg:pl-2"),children:e})]})]})}function Lqt({children:e,className:t}){return a.jsx("div",{"data-slot":"main-card",className:Z("relative min-h-0 flex-1 overflow-hidden rounded-studio-frame p-px",_0e,t),children:e})}function MNs(){return a.jsxs("div",{className:"h-screen bg-sidebar",children:[a.jsx(ZH,{position:"bottom-right"}),a.jsx(q1e,{defaultTheme:"system",children:a.jsx(mc,{delayDuration:0,children:a.jsx(Dqt,{children:a.jsx(Lqt,{className:"flex items-center justify-center overflow-y-auto",children:a.jsx(lx,{})})})})})]})}function DNs({className:e,children:t,...n}){return a.jsx("footer",{"data-slot":"sidebar-footer",className:Z("mt-auto shrink-0 space-y-1.5",e),...n,children:t})}const yAe=Me.createContext(null),zqt=Me.createContext(null);function cw(){return Me.useContext(yAe)}function pg(){const e=Me.useContext(yAe),t=Me.useContext(zqt);if(!e||!t)throw new Error("useSidebar must be used within a SidebarProvider.");return{...e,...t}}const LNs=g.forwardRef(function({className:t,children:n,action:r,...s},i){const{state:o}=pg();return a.jsxs("div",{ref:i,"data-slot":"sidebar-footer-meta","data-state":o,className:Z("grid min-h-10 grid-cols-[minmax(0,1fr)_auto_0fr] items-center border-t border-border px-2 py-1 text-meta text-muted-foreground","transition-[grid-template-columns] duration-slow ease-out-custom motion-reduce:transition-none",o==="collapsed"&&"grid-cols-[minmax(0,1fr)_auto_minmax(0,1fr)] px-0",t),...s,children:[a.jsx("div",{"aria-hidden":o==="collapsed",className:Z("min-w-0 truncate transition-opacity duration-normal ease-out-custom motion-reduce:transition-none",o==="collapsed"&&"opacity-0"),children:n}),r,a.jsx("span",{"aria-hidden":!0})]})}),zNs=`url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E")`,FNs=76,BNs=100,VNs=60,UNs=22.5,qNs=.18,ant=110,Fqt=[0,.08,.16,.25,.34,.44,.55,.66,.78,.89,1],Bqt={neutral:{colorVar:"--foreground",peak:.08,grain:!0,text:"text-muted-foreground"},warning:{colorVar:"--warning-indicator",peak:.16,grain:!1,text:"text-warning-foreground"},danger:{colorVar:"--destructive-indicator",peak:.16,grain:!1,text:"text-destructive-foreground"}};function Vqt(e){const t=1-e;return t*t*t}function QNs(e,t){return`linear-gradient(to right, ${Fqt.map(r=>{const s=(t*Vqt(r)*100).toFixed(2);return`color-mix(in oklch, var(${e}) ${s}%, transparent) ${(r*100).toFixed(0)}%`}).join(", ")})`}function lnt(e,t){const n=Fqt.map(r=>{const s=(t+(100-t)*r).toFixed(2);return`rgb(0 0 0 / ${Vqt(r).toFixed(3)}) ${s}%`});return`linear-gradient(${e}, rgb(0 0 0 / 1) 0%, ${n.join(", ")})`}const ZNs=`${lnt("to bottom",VNs)}, ${lnt("to right",UNs)}`;function cnt({tone:e}){const t=Bqt[e];return a.jsx("span",{"aria-hidden":!0,"data-slot":"sidebar-meter-bloom",className:"pointer-events-none absolute inset-x-0 top-0 -z-10",style:{height:BNs,backgroundImage:QNs(t.colorVar,t.peak),maskImage:ZNs,maskComposite:"intersect"},children:t.grain?a.jsx("span",{"aria-hidden":!0,className:"absolute inset-0",style:{backgroundImage:zNs,backgroundRepeat:"repeat",backgroundSize:`${ant}px ${ant}px`,opacity:qNs}}):null})}const WNs=g.forwardRef(function({label:t,value:n,status:r,tone:s="neutral",icon:i,action:o,href:l,linkLabel:c,LinkComponent:u,state:d,className:f,...h},p){const m=cw(),v=d??m?.state??"default",y=u??m?.LinkComponent??"a",x=v==="collapsed",b=Bqt[s];return x?a.jsxs("div",{ref:p,"data-slot":"sidebar-meter","data-tone":s,"data-state":v,className:Z("relative isolate flex items-center justify-center overflow-hidden rounded-lg border border-border bg-background px-1 py-2",f),...h,children:[a.jsx(cnt,{tone:s}),l?a.jsx(y,{href:l,className:"absolute inset-0 rounded-lg","aria-label":c}):null,a.jsx(Y,{as:"span",variant:"meta",tone:"ink",className:"pointer-events-none relative tabular-nums",children:n})]}):a.jsxs("div",{ref:p,"data-slot":"sidebar-meter","data-tone":s,"data-state":v,className:Z("relative isolate flex flex-col justify-center overflow-hidden rounded-lg border border-border bg-background px-3",l&&aP,f),style:{height:FNs},...h,children:[a.jsx(cnt,{tone:s}),l?a.jsx(y,{href:l,className:"absolute inset-0 rounded-lg","aria-label":c}):null,a.jsxs("div",{className:"pointer-events-none relative",children:[a.jsxs("div",{className:"flex items-center gap-1.5",children:[s==="neutral"?null:i,a.jsx(Y,{as:"span",variant:"column",tone:"muted",children:t}),o?a.jsx("span",{className:"pointer-events-auto",children:o}):null]}),a.jsx(Y,{variant:"heading",tone:"ink",className:"mt-0.5 leading-tight tabular-nums",children:n}),r?a.jsx("div",{className:"mt-1 text-meta",children:a.jsx("p",{className:Z("truncate",b.text),children:r})}):null]})]})});function HNs({logo:e,title:t,className:n,...r}){const{state:s}=pg();return a.jsxs("div",{"data-slot":"sidebar-brand",className:Z("flex min-w-0 flex-1 items-center gap-2",n),...r,children:[e?a.jsx("span",{className:"shrink-0",children:e}):null,s==="collapsed"?a.jsx(I0,{children:t}):a.jsx(Y,{as:"span",variant:"subheading",tone:"ink",className:"truncate font-body tracking-tight",children:t})]})}const GNs=g.forwardRef(function({className:t,children:n,...r},s){const{state:i,isMobile:o}=pg();return a.jsx("header",{ref:s,"data-slot":"sidebar-command-header","data-state":i,className:Z("flex h-header-default shrink-0 items-center gap-1 overflow-hidden",i==="collapsed"?"px-3":"pr-2 pl-3.5",i!=="collapsed"&&!o&&"w-[calc(var(--sidebar-width)-1rem)]",i==="collapsed"&&"[&_[data-slot=sidebar-search-trigger]]:hidden",t),...r,children:n})});function Uqt({className:e,onClick:t,...n}){const{desktopState:r,isMobile:s,toggleSidebar:i}=pg(),o=r==="collapsed";return s?null:a.jsxs(Ln,{children:[a.jsx(Rn,{render:a.jsx("button",{type:"button","aria-label":"Toggle sidebar","aria-expanded":!o,...n,onClick:l=>{t?.(l),l.defaultPrevented||i()},className:Z("flex items-center justify-center rounded-md text-muted-foreground","size-7",!o&&"ml-auto","hover:bg-fill-subtle hover:text-foreground","transition-colors duration-normal ease-out-custom motion-reduce:transition-none",Ri,"[&_svg]:size-4 [&_svg]:text-muted-foreground [&:hover_svg]:text-foreground",e),children:a.jsx(hht,{})})}),a.jsx(Mn,{children:a.jsxs("span",{className:"inline-flex items-center gap-1.5",children:["Toggle Sidebar",a.jsx(Qd,{size:"xs",className:"bg-muted text-muted-foreground",children:"["})]})})]})}const unt="animate-[sidebar-hold_var(--resize-dur)] motion-reduce:animate-none";function KNs({className:e,children:t,collapsedLogo:n,actions:r,...s}){const i=cw(),o=i?.state==="collapsed",l=i?.isMobile??!1;return a.jsxs("header",{"data-slot":"sidebar-header",className:Z("flex h-header-default shrink-0 items-center gap-2",o?"px-1":"pr-2 pl-3.5",o&&r&&"h-auto flex-col gap-3 py-3",!o&&!l&&"w-[calc(var(--sidebar-width)-1rem)]",e),...s,children:[o&&n?a.jsxs("div",{className:"group/collapsed-logo relative ml-0.5 grid size-9 shrink-0 place-items-center",children:[a.jsx("span",{className:Z(unt,"grid place-items-center transition-opacity duration-normal [--sidebar-hold-opacity:1] group-focus-within/collapsed-logo:opacity-0 group-hover/sidebar:opacity-0 motion-reduce:transition-none"),children:n}),l?null:a.jsx("div",{className:Z(unt,"absolute inset-0 grid place-items-center opacity-0 transition-opacity duration-normal [--sidebar-hold-opacity:0] group-hover/sidebar:opacity-100 focus-within:opacity-100 motion-reduce:transition-none"),children:a.jsx(Uqt,{})})]}):t,r]})}const YNs=g.forwardRef(function({className:t,children:n,shortcut:r,type:s="button",...i},o){return a.jsxs("button",{ref:o,"data-slot":"sidebar-search-trigger",type:s,className:Z("group inline-flex size-control-md shrink-0 items-center justify-center gap-1.5 rounded-full border border-transparent hover:bg-fill-subtle",Fn,jn,Ri,"[&_svg]:size-4 [&_svg]:shrink-0",r&&"w-auto px-2",t),...i,children:[n,r?a.jsx(Qd,{size:"xs",className:Z("bg-surface-overlay-soft active:scale-100",dx),children:r}):null]})});function XNs({"aria-label":e="Main",children:t,className:n,...r}){const s=cw()?.isMobile??!1;return a.jsx("nav",{"aria-label":e,className:Z("-mr-1.5 flex min-h-0 flex-1 flex-col","[&_[data-slot=scroll-area-scrollbar][data-orientation=vertical]]:w-1 [&_[data-slot=scroll-area-scrollbar][data-orientation=vertical]]:p-0","focus-within:[&_[data-slot=scroll-area-scrollbar][data-orientation=vertical][data-has-overflow-y]]:opacity-100",s&&"[&_a]:min-h-11 [&_a]:touch-manipulation [&_button]:min-h-11 [&_button]:touch-manipulation",n),...r,children:a.jsx(Nr,{className:"min-h-0 flex-1",mask:{top:"3rem",bottom:"5rem"},children:a.jsx(af,{className:"px-0.5",children:a.jsx("div",{className:"pr-1.5",children:t})})})})}function qqt({children:e,icon:t,action:n,className:r,state:s,href:i,isActive:o,LinkComponent:l,...c}){const u=cw(),f=(s??u?.state??"default")==="default",h=l??u?.LinkComponent??"a",p=o?"text-foreground":"text-muted-foreground";return a.jsx("div",{className:Z("flex min-w-0 items-center",f?"mt-3 min-h-7":"h-10",r),children:f?a.jsxs(a.Fragment,{children:[t?a.jsx("span",{"aria-hidden":"true",className:Z("flex shrink-0 pl-3 [&_svg]:size-4",p),children:t}):null,a.jsx("header",{...c,className:Z("max-w-full min-w-0 flex-1 truncate text-column",t?"pl-2":"pl-3",p),children:i?a.jsx(h,{href:i,className:Z("block min-w-0 truncate transition-colors duration-normal",{"hover:text-foreground":!o,"text-foreground":o}),children:e}):e}),n]}):a.jsxs(a.Fragment,{children:[a.jsx(I0,{asChild:!0,children:a.jsx("header",{...c,children:e})}),a.jsx("div",{"aria-hidden":"true",className:"mx-3 h-px flex-1 bg-border"}),n?a.jsx(I0,{children:n}):null]})})}function xAe({children:e,className:t,state:n,...r}){const s=cw();return(n??s?.state??"default")==="collapsed"?a.jsx(I0,{children:e}):a.jsx("span",{...r,className:Z("min-w-0 flex-1 truncate text-left",t),children:e})}const JNs=pd("flex min-w-0 cursor-pointer items-center rounded-lg text-label whitespace-nowrap",{variants:{size:{sm:np.sm,md:np.md,lg:np.lg}},defaultVariants:{size:"md"}}),eAs=e=>e<=0?"gap-2 py-1 px-3":e===1?`gap-2 py-1 pr-3 pl-8 ${np.md}`:e===2?`gap-2 py-1 pr-3 pl-10 ${np.md}`:`gap-2 py-1 pr-3 pl-12 ${np.md}`,tAs=Z("rounded-lg text-muted-foreground hover:text-foreground",aP),nAs="bg-fill text-foreground",rAs=Z("my-2 border border-transparent bg-brand-green text-black hover:text-black hover:brightness-95"),Qqt=({isActive:e,isFeatured:t})=>Z(tAs,e&&nAs,t&&rAs),Zqt=({isCollapsed:e,level:t=0,size:n})=>Z(JNs({size:n}),"w-full justify-start",jn,"[&_svg]:size-4 [&_svg]:shrink-0",Ri,!e&&eAs(t),e&&"gap-0 px-[13.5px] py-0"),Wqt=({isActive:e,isCollapsed:t,isFeatured:n,level:r,size:s}={})=>Z(Zqt({isCollapsed:t,level:r,size:s}),Qqt({isActive:e,isFeatured:n}));function bAe({link:e,state:t,children:n,isActive:r,size:s,render:i,action:o,className:l,LinkComponent:c,level:u,subItems:d,asChild:f=!1,...h}){if(i&&f)throw new Error("SidebarNavLink accepts either `render` or `asChild`, not both.");const p=cw(),m=t??p?.state??"default",v=c??p?.LinkComponent??"a",y=m==="collapsed",x=e?.variant==="featured",b=u??(e?.indent?1:0),S=y?void 0:o,k=S?Z(Zqt({level:b,size:s}),"flex-1 pr-1"):Z(Wqt({isActive:r,isCollapsed:y,isFeatured:x,level:b,size:s}),e?.opensView&&!y&&"pr-1");return a.jsxs("li",{...h,className:Z("relative flex min-w-0 flex-col",l),children:[a.jsx(aAs,{action:S,surfaceClassName:Qqt({isActive:r,isFeatured:x}),children:a.jsx(oAs,{label:iAs(e,y),children:sAs({render:i,asChild:f,children:n,link:e,state:m,Link:v,isActive:r,className:k})})}),!y&&d]})}function sAs({render:e,asChild:t,children:n,link:r,state:s,Link:i,isActive:o,className:l}){const c=o?"page":void 0,u=r?.opensView&&s!=="collapsed"?a.jsx(Rc,{"aria-hidden":"true",className:"!size-3.5"}):null;if(e||t){const f=e??n;if(!Me.isValidElement(f))throw new Error("SidebarNavLink requires a valid React element child when `asChild` is true so it can apply `SlottedNavChildProps` and merge `itemClassName`.");return Me.cloneElement(f,{className:Z(l,f.props.className),"aria-current":c,children:a.jsxs(a.Fragment,{children:[f.props.children,u]})})}if(!r)return n;const d=/^(https?:)?\/\//.test(r.url)?{target:"_blank",rel:"noreferrer"}:{};return a.jsxs(i,{href:r.url,...d,"aria-current":c,className:l,children:[r.icon,a.jsx(xAe,{state:s,children:r.name}),n,u]})}function iAs(e,t){if(e)return e.tooltipMsg?t?`${e.name} | ${e.tooltipMsg}`:e.tooltipMsg:t?e.name:void 0}function oAs({label:e,children:t}){return Me.isValidElement(t)?a.jsxs(Ln,{disabled:!e,children:[a.jsx(Rn,{render:t}),e?a.jsx(Mn,{side:"right",align:"center",sideOffset:16,children:e}):null]}):t}function aAs({action:e,surfaceClassName:t,children:n}){return e?a.jsxs("div",{className:Z("flex min-w-0 items-center pr-1",t),children:[n,e]}):n}function wAe({className:e,children:t,...n}){return a.jsx("ul",{className:Z("grid grid-cols-[minmax(0,1fr)] content-center items-start gap-0.5",e),...n,children:t})}function Hqt({className:e,children:t,...n}){return a.jsx("section",{className:Z("relative grid grid-cols-[minmax(0,1fr)] content-center items-start",e),...n,children:t})}function Gqt({className:e,...t}){return a.jsx("div",{role:"separator","aria-orientation":"horizontal",className:Z("relative min-h-5",'[&:after]:absolute [&:after]:inset-x-3 [&:after]:top-1/2 [&:after]:block [&:after]:h-0 [&:after]:border-t [&:after]:border-border [&:after]:content-[""]',e),...t})}const Kqt=Me.createContext(void 0);function Yqt(){const e=Me.useContext(Kqt);if(!e)throw new Error("Sidebar.NavStack components must be used within Sidebar.NavStack.");return e}function lAs({value:e,rootValue:t="root",onValueChange:n,children:r,className:s,...i}){function o(l){n(t),requestAnimationFrame(()=>{const c=l?.current;c&&!c.closest("[inert]")&&c.focus()})}return a.jsx(Kqt.Provider,{value:{activeValue:e,rootValue:t,closeView:o},children:a.jsx("div",{"data-slot":"sidebar-nav-stack","data-value":e,className:Z("relative grid min-w-0 overflow-hidden",s),...i,children:r})})}function Xqt(e,t,n){return Z("col-start-1 row-start-1 min-w-0 transition-[opacity,translate] duration-normal ease-out-custom will-change-[opacity,translate] motion-reduce:transition-none",e&&"relative translate-x-0 opacity-100",!e&&"pointer-events-none absolute inset-0 opacity-0",!e&&t==="root"&&"-translate-x-2",!e&&t==="view"&&"translate-x-2",n)}function cAs({children:e,className:t,...n}){const{state:r}=pg(),{activeValue:s,rootValue:i}=Yqt(),o=r==="collapsed"||s===i;return a.jsx("div",{...n,"data-slot":"sidebar-nav-stack-root","aria-hidden":!o,inert:!o,className:Xqt(o,"root",t),children:e})}function uAs({value:e,title:t,backLabel:n="Back to main navigation",returnFocusRef:r,onBack:s,children:i,className:o,...l}){const{state:c}=pg(),{activeValue:u,closeView:d}=Yqt(),f=c!=="collapsed"&&u===e,h=Me.useRef(null),p=Me.useRef(f);Me.useEffect(()=>{f&&!p.current&&h.current?.focus(),p.current=f},[f]),Me.useEffect(()=>{if(!f)return;function v(y){y.key!=="Escape"||y.defaultPrevented||(y.preventDefault(),d(r),s?.())}return document.addEventListener("keydown",v),()=>document.removeEventListener("keydown",v)},[f,d,s,r]);function m(){d(r),s?.()}return a.jsxs("div",{...l,"data-slot":"sidebar-nav-stack-view","data-value":e,"aria-hidden":!f,inert:!f,className:Xqt(f,"view",o),children:[a.jsxs("button",{ref:h,type:"button","aria-label":`${n}: ${t}`,onClick:m,className:Z(Wqt(),"mb-2 grid grid-cols-[2rem_1fr_2rem] px-1"),children:[a.jsx(md,{className:"justify-self-center","aria-hidden":"true"}),a.jsx("span",{className:"min-w-0 truncate text-center",children:t}),a.jsx("span",{"aria-hidden":"true"})]}),i]})}const dAs=Object.assign(lAs,{Root:cAs,View:uAs});function fAs({className:e,icon:t,"aria-label":n="Open navigation menu",onClick:r,...s}){const{isMobile:i,mobileTriggerRef:o,setOpenMobile:l}=pg();return a.jsx("button",{ref:o,type:"button","aria-label":n,"aria-hidden":!i,tabIndex:i?0:-1,"data-mobile-only":!0,...s,onClick:c=>{r?.(c),c.defaultPrevented||l(!0)},className:Z("inline-flex size-10 items-center justify-center rounded-md","[[data-sidebar-mobile='false']_&]:hidden","[[data-sidebar-mobile-present='true']_&]:invisible",Fn,"hover:bg-fill-subtle",Ri,e),children:t??a.jsx(aht,{className:"size-5"})})}const dnt="sidebar:state",fnt="sidebar:width",hnt="--sidebar-width",wue=(e,t,n)=>Math.min(n,Math.max(t,e)),hAs=typeof window<"u"?Me.useLayoutEffect:Me.useEffect;function Jqt({children:e,defaultState:t="default",defaultWidth:n=240,minWidth:r=200,maxWidth:s=480,collapseBelow:i,collapsedWidth:o=64,disableKeyboardShortcut:l=!0,storageKey:c,mobileBreakpoint:u=1024,mobileWidth:d=360,LinkComponent:f}){const h=Math.max(0,Math.min(r,s)),p=Math.max(h,s),m=Math.max(0,Math.min(o,p)),v=wue(n,h,p),y=i??h,x=c?`${c}:${dnt}`:dnt,b=c?`${c}:${fnt}`:fnt,S=()=>{if(typeof window>"u")return{state:t,width:v};try{let re=t,ae=v;const he=window.localStorage.getItem(x);(he==="collapsed"||he==="default")&&(re=he);const ve=window.localStorage.getItem(b);if(ve!==null){const pe=Number(ve);Number.isFinite(pe)&&(ae=wue(pe,h,p))}return{state:re,width:ae}}catch{return{state:t,width:v}}},k=Me.useRef(null);k.current===null&&(k.current=S());const j=k.current,[C,T]=Me.useState(j.state),[_,N]=Me.useState(j.width),[I,A]=Me.useState(!1),[P,D]=Me.useState(!1),[F,Q]=Me.useState(!1),q=Me.useRef(!1),B=Me.useRef(null),V=Me.useRef(j.width),H=Me.useRef(j.state);H.current=C;const M=Me.useRef(null);Me.useEffect(()=>{if(typeof window>"u")return;const re=window.matchMedia(`(max-width: ${u-1}px)`),ae=()=>A(re.matches);return ae(),re.addEventListener("change",ae),()=>re.removeEventListener("change",ae)},[u]);const G=Me.useCallback(re=>{q.current=re,re&&Q(!0),D(re)},[]);Me.useEffect(()=>{!I&&P&&(G(!1),Q(!1))},[I,P,G]);const L=Me.useCallback(re=>{const ae=M.current;ae&&ae.style.setProperty(hnt,`${re}px`)},[]);hAs(()=>{L(C==="collapsed"?m:V.current)},[C,m,L]);const $=Me.useCallback(re=>{try{window.localStorage.setItem(x,re)}catch{}},[x]),z=Me.useCallback(()=>{if(I){G(!q.current);return}T(re=>{const ae=re==="default"?"collapsed":"default";return H.current=ae,$(ae),ae})},[I,$,G]),U=Me.useCallback(re=>{const ae=wue(re,h,p);V.current=ae,L(ae)},[h,p,L]),K=Me.useCallback(()=>{H.current="collapsed",$("collapsed"),T("collapsed")},[$]),ne=Me.useCallback(()=>{H.current="default",$("default"),T("default")},[$]),X=Me.useCallback(()=>{N(V.current);try{window.localStorage.setItem(x,H.current),window.localStorage.setItem(b,String(V.current))}catch{}},[x,b]),te=Me.useCallback(re=>{const ae=M.current;ae&&(re?ae.setAttribute("data-sidebar-gesture","active"):ae.removeAttribute("data-sidebar-gesture"))},[]);Me.useEffect(()=>{if(l)return;const re=ae=>{if(ae.code==="KeyB"&&(ae.metaKey||ae.ctrlKey)&&!(ae.altKey||ae.shiftKey)){if(ae.target instanceof HTMLElement){const he=ae.target.tagName;if(he==="INPUT"||he==="TEXTAREA"||he==="SELECT"||ae.target.isContentEditable)return}ae.preventDefault(),z()}};return window.addEventListener("keydown",re),()=>window.removeEventListener("keydown",re)},[l,z]);const ie=I?"default":C,ue=Me.useMemo(()=>({state:ie,desktopState:C,width:_,minWidth:h,maxWidth:p,collapseBelow:y,collapsedWidth:m,isMobile:I,toggleSidebar:z,setWidth:U,collapse:K,expand:ne,commit:X,setGestureActive:te,LinkComponent:f}),[ie,C,_,h,p,y,m,I,z,U,K,ne,X,te,f]),ee=Me.useMemo(()=>({openMobile:P,mobileTriggerRef:B,setOpenMobile:G,setMobileDrawerPresent:Q}),[P,G]),se={[hnt]:`${j.state==="collapsed"?m:j.width}px`,"--sidebar-width-mobile":`${d}px`,display:"contents"};return a.jsx("div",{ref:M,"data-sidebar-scope":!0,"data-sidebar-state":C,"data-sidebar-mobile":I?"true":"false","data-sidebar-mobile-present":F?"true":"false",style:se,suppressHydrationWarning:!0,children:a.jsx(yAe.Provider,{value:ue,children:a.jsx(zqt.Provider,{value:ee,children:e})})})}const pnt=10,pAs=5;function mAs({children:e,className:t,mobileMode:n="drawer"}){const{state:r,width:s,minWidth:i,maxWidth:o,collapseBelow:l,collapsedWidth:c,isMobile:u,openMobile:d,mobileTriggerRef:f,setOpenMobile:h,setMobileDrawerPresent:p,setWidth:m,collapse:v,expand:y,commit:x,toggleSidebar:b,setGestureActive:S}=pg(),k=r==="collapsed",j=k&&c===0,C=g.useRef(!1),T=g.useRef(null);g.useEffect(()=>()=>{T.current?.(),T.current=null},[]);const _=g.useCallback(D=>{if(D.button!==0)return;D.preventDefault(),C.current=!1,S(!0);const F=D.clientX,Q=D.currentTarget,q=D.pointerId;try{Q.setPointerCapture(q)}catch{}const B=Q.parentElement,V=B?B.getBoundingClientRect().left:0,H=document.body.style.cursor,M=document.body.style.userSelect,G=$=>{if($.pointerId!==q)return;const z=$.clientX-F;if(!C.current){if(Math.abs(z)<=pAs)return;C.current=!0,document.body.style.cursor="col-resize",document.body.style.userSelect="none"}const U=$.clientX-V;if(l>0&&U<l){v();return}y(),m(U)},L=$=>{$&&$.pointerId!==q||(window.removeEventListener("pointermove",G),window.removeEventListener("pointerup",L),window.removeEventListener("pointercancel",L),document.body.style.cursor=H,document.body.style.userSelect=M,S(!1),x(),T.current=null)};T.current=()=>L(),window.addEventListener("pointermove",G),window.addEventListener("pointerup",L),window.addEventListener("pointercancel",L)},[l,m,y,v,x,S]),N=g.useCallback(()=>{if(C.current){C.current=!1;return}b()},[b]),I=g.useCallback(D=>{switch(D.key){case"Enter":case" ":{D.preventDefault(),b();return}case"ArrowLeft":{if(D.preventDefault(),k)return;m(s-pnt),x();return}case"ArrowRight":{if(D.preventDefault(),k){y(),x();return}m(s+pnt),x();return}case"Home":{D.preventDefault(),y(),m(i),x();return}case"End":{D.preventDefault(),y(),m(o),x();return}}},[k,s,i,o,m,y,x,b]),A=g.useCallback(D=>{if(!(D.target instanceof Element))return;const F=D.target.closest("a");!F||!F.hasAttribute("href")||D.button!==0||D.metaKey||D.ctrlKey||D.shiftKey||D.altKey||F.target==="_blank"||F.hasAttribute("download")||h(!1)},[h]);if(u)return a.jsx(GP,{side:"left",open:d,onOpenChange:h,onOpenChangeComplete:D=>{D||p(!1)},children:a.jsxs(_Y,{"data-mobile-mode":n,finalFocus:f,showCloseButton:n==="drawer",className:Z("border-0 bg-sidebar text-foreground",n==="takeover"?"w-[calc(100%-3.5rem)] max-w-none overflow-visible rounded-l-none rounded-r-3xl pt-[env(safe-area-inset-top)] pb-[env(safe-area-inset-bottom)]":"w-3/4 max-w-(--sidebar-width-mobile) overflow-hidden rounded-none",t),children:[n==="takeover"?a.jsx(kY,{asChild:!0,children:a.jsx("button",{type:"button","aria-label":"Close",className:"group absolute top-2 -right-12 z-10 inline-flex size-11 touch-manipulation items-center justify-center transition-opacity duration-fast group-data-[ending-style]/popup:opacity-0 focus-visible:outline-hidden motion-reduce:duration-0",children:a.jsx("span",{className:Z(rh,dx,Oft,"inline-flex size-9 items-center justify-center rounded-full backdrop-blur-sm group-focus-visible:ring-1 group-focus-visible:ring-border-focus"),children:a.jsx(aht,{className:"size-4"})})})}):null,a.jsx(I0,{asChild:!0,children:a.jsx(KP,{children:"Navigation"})}),a.jsx(I0,{asChild:!0,children:a.jsx(m6,{children:"Primary site navigation drawer"})}),a.jsx("div",{onClick:A,className:Z("flex h-full min-h-0 flex-col overflow-hidden py-2",n==="takeover"?"px-4":"px-3"),children:e})]})});const P=k?c:s;return a.jsxs("div",{className:Z("sidebar-layout group/sidebar t-resize relative min-h-0 shrink-0 self-stretch bg-sidebar text-foreground","w-(--sidebar-width)","in-data-[sidebar-gesture=active]:transition-none",t,j&&"border-r-0 border-transparent"),children:[a.jsx("div",{className:Z("flex h-full min-h-0 flex-col overflow-hidden","transition-opacity duration-200 motion-reduce:transition-none","p-2",j&&"pointer-events-none p-0 opacity-0"),children:e}),a.jsx("div",{role:"separator","aria-orientation":"vertical","aria-valuenow":k?void 0:P,"aria-valuemin":k?void 0:i,"aria-valuemax":k?void 0:o,"aria-valuetext":k?"collapsed":`${P} pixels`,"aria-label":`Resize sidebar. Arrow keys to resize, Enter to ${k?"expand":"collapse"}.`,tabIndex:0,onPointerDown:_,onClick:N,onKeyDown:I,className:Z("group absolute top-0 -right-1 z-10 h-full w-2 cursor-col-resize touch-none","flex items-center justify-center","focus-visible:outline-hidden"),children:a.jsx(eke,{className:Z("via-foreground/30 group-hover:opacity-100","group-focus-visible:via-border-focus group-focus-visible:opacity-100","in-data-[sidebar-gesture=active]:via-foreground/45 in-data-[sidebar-gesture=active]:opacity-100")})})]})}function gAs({"aria-label":e="Sidebar",mobileMode:t="takeover",variant:n="default",children:r,...s}){const i=cw(),o=n==="raised"&&!i?.isMobile;return a.jsx("aside",{"aria-label":e,className:"contents",children:a.jsx(mAs,{mobileMode:t,...s,children:o?a.jsx("div",{"data-slot":"sidebar-surface",className:Z("-mr-2 -ml-4 flex min-h-0 flex-1 flex-col overflow-hidden rounded-r-xl py-1.5",i?.state==="collapsed"?"pr-2 pl-4":"pr-3.5 pl-5.5",_0e),children:r}):r})})}const see=["sidebar","more","hidden"],eQt={sidebar:"Always show",more:"Hide in More menu",hidden:"Never show"},vAs=ki(gt(),hf(see)),yAs="mastra:sidebar:link-visibility";function p3(e){return`${e.url}:${e.name}`}function mnt(e,t){return`${e}:${t.name}`}function tQt(e,t){return e.defaultVisible??t<2?"sidebar":"more"}function nQt(e){return see.some(t=>t===e)}function xAs({open:e,onOpenChange:t,returnFocusRef:n,sections:r,placementOf:s,onPlacementChange:i}){const o=g.useId(),l=r.filter(c=>(c.moreLinks?.length??0)>0);return a.jsx(rs,{open:e,onOpenChange:t,children:a.jsxs(ss,{size:"md",finalFocus:n,children:[a.jsxs(es,{children:[a.jsx(Gr,{children:"Customize sidebar"}),a.jsx(zo,{children:"Choose where each optional link appears. Changes save automatically in this browser."})]}),a.jsx(Hr,{className:"space-y-5",children:l.map(c=>{const u=c.moreLinks??[],d=c.title?`${o}-${c.key}`:void 0;return a.jsxs("section",{"aria-labelledby":d,"aria-label":d?void 0:c.key,className:"space-y-2",children:[c.title?a.jsx(Y,{as:"h3",id:d,variant:"label",tone:"muted",children:c.title}):null,a.jsx("ul",{className:"divide-y divide-border rounded-lg border border-border",children:u.map(f=>a.jsxs("li",{className:"flex min-h-11 items-center gap-2.5 py-1.5 pr-1.5 pl-3",children:[a.jsx("span",{"aria-hidden":"true",className:"flex shrink-0 text-muted-foreground [&_svg]:size-4",children:f.icon}),a.jsx(Y,{as:"span",variant:"body-sm",className:"min-w-0 flex-1 truncate",children:f.name}),a.jsxs(Vr,{value:s(c.key,f,u.length),onValueChange:h=>{nQt(h)&&i(c.key,f,h)},children:[a.jsx(qr,{size:"sm",variant:"ghost",className:"w-44 shrink-0","aria-label":`${f.name} placement`,children:a.jsx(Ur,{})}),a.jsx(Qr,{children:see.map(h=>a.jsx(ir,{value:h,children:eQt[h]},h))})]})]},p3(f)))})]},c.key)})})]})})}function SAe({link:e,activeCandidates:t,level:n=0,isActive:r,...s}){const i=e.children??[];return a.jsx(bAe,{...s,link:e,isActive:r?.(e,t)??e.isActive,level:n,subItems:i.length>0?a.jsx(wAe,{className:"mt-0.5",children:i.map(o=>a.jsx(SAe,{link:o,activeCandidates:t,level:n+1,isActive:r},p3(o)))}):null})}function bAs({link:e,activeCandidates:t,isActive:n,placement:r,onPlacementChange:s,onCustomize:i}){const o=g.useRef(null);return a.jsxs(yo,{children:[a.jsx(yo.Trigger,{ref:l=>{o.current=l},render:a.jsx(SAe,{link:e,activeCandidates:t,isActive:n})}),a.jsxs(yo.Content,{"aria-label":`${e.name} options`,children:[a.jsx(yo.RadioGroup,{value:r,onValueChange:l=>{nQt(l)&&s(l)},children:see.map(l=>a.jsx(yo.RadioItem,{value:l,children:eQt[l]},l))}),a.jsx(yo.Separator,{}),a.jsx(yo.Item,{onClick:()=>i(o.current?.querySelector("a")??null),children:"Customize sidebar…"})]})]})}function wAs({links:e,activeCandidates:t,isActive:n,placementOf:r,onPlacementChange:s,onCustomize:i}){const l=cw()?.LinkComponent??"a",c=v=>n?.(v,t)??v.isActive??!1,u=e.filter(v=>c(v)||r(v)==="sidebar"),d=e.filter(v=>!u.includes(v)&&r(v)==="more"),f=e.some(v=>r(v)!==tQt(v,e.length)),h=e.length>1||d.length>0||f,p=g.useRef(null);function m(v,y=!1){return a.jsxs(g.Fragment,{children:[a.jsxs(ct.Item,{nativeButton:!1,inset:y,render:a.jsx(l,{href:v.url,.../^(https?:)?\/\//.test(v.url)?{target:"_blank",rel:"noreferrer"}:{}}),"aria-current":c(v)?"page":void 0,children:[v.icon,v.name]}),v.children?.map(x=>m(x,!0))]},p3(v))}return a.jsxs(a.Fragment,{children:[u.map(v=>a.jsx(bAs,{link:v,activeCandidates:t,isActive:n,placement:r(v),onPlacementChange:y=>s(v,y),onCustomize:y=>i(y,()=>p.current)},p3(v))),h?a.jsxs(ct,{modal:!1,children:[a.jsx(bAe,{link:{name:"More",url:"",icon:a.jsx(jN,{})},render:a.jsxs(ct.Trigger,{ref:p,render:a.jsx("button",{type:"button"}),"aria-label":"More",children:[a.jsx(jN,{"aria-hidden":"true"}),a.jsx(xAe,{children:"More"})]})}),a.jsxs(ct.Content,{align:"start","aria-label":"More navigation",className:"min-w-44",children:[d.map(v=>m(v)),d.length>0&&a.jsx(ct.Separator,{}),a.jsxs(ct.Item,{onClick:()=>i(p.current,()=>p.current),children:[a.jsx(rL,{}),"Customize sidebar"]})]})]}):null]})}function SAs({sections:e,isActive:t,className:n,visibilityStorageKey:r}){const s=g.useId(),[i,o]=g.useState(!1),l=g.useRef(null),c=g.useRef(()=>null),[u,d]=xk({initialKey:r,defaultValue:{},schema:vAs});function f(v,y,x){return u[mnt(v,y)]??tQt(y,x)}function h(v,y){l.current=v,c.current=y,o(!0)}function p(v){!v&&!l.current?.isConnected&&(l.current=c.current()),o(v)}function m(v,y,x){d(b=>({...b,[mnt(v,y)]:x}))}return a.jsxs(a.Fragment,{children:[e.map(v=>{const y=v.links.length>0&&v.separator,x=v.title?`${s}-${v.key}`:void 0,b=v.moreLinks??[],S=[...v.links,...b];return a.jsxs(Hqt,{className:n,"aria-labelledby":x,"aria-label":x?void 0:v.key,children:[y?a.jsx(Gqt,{className:"[&:after]:border-border"}):null,v.title?a.jsx(qqt,{id:x,href:v.href,isActive:v.isHeaderActive,children:v.title}):null,a.jsxs(wAe,{children:[v.links.map(k=>a.jsx(SAe,{link:k,activeCandidates:S,isActive:t},p3(k))),b.length>0?a.jsx(wAs,{links:b,activeCandidates:S,isActive:t,placementOf:k=>f(v.key,k,b.length),onPlacementChange:(k,j)=>m(v.key,k,j),onCustomize:h}):null]})]},v.key)}),a.jsx(xAs,{open:i,onOpenChange:p,returnFocusRef:l,sections:e,placementOf:f,onPlacementChange:m})]})}function kAs({visibilityStorageKey:e=yAs,...t}){return a.jsx(SAs,{...t,visibilityStorageKey:e},e)}const ho=Object.assign(gAs,{Brand:HNs,CommandHeader:GNs,Footer:DNs,FooterMeta:LNs,Header:KNs,Meter:WNs,MobileTrigger:fAs,Nav:XNs,NavHeader:qqt,NavLabel:xAe,NavLink:bAe,NavList:wAe,NavSection:Hqt,NavSeparator:Gqt,NavStack:dAs,Provider:Jqt,SearchTrigger:YNs,Sections:kAs,Trigger:Uqt});function OAs(){const{data:e,isLoading:t}=Zl(),{isLoading:n,canAccessAgentBuilder:r}=Cx();return t||n?{isVisible:!1}:e?!!e.enabled&&!Sp(e)?{isVisible:!1}:{isVisible:r}:{isVisible:!1}}function rQt(){const{isImpersonating:e,impersonatedRole:t,stopImpersonation:n}=HH();return!e||!t?null:a.jsxs("div",{className:"mx-3 mb-2 flex items-center gap-2 rounded-md border border-info-edge bg-info-subtle px-3 py-1.5",children:[a.jsx(Ba,{className:"h-3.5 w-3.5 shrink-0 text-info-subtle-foreground"}),a.jsxs(Y,{variant:"meta",className:"truncate text-info-subtle-foreground",children:["Previewing ",a.jsx("span",{className:"font-medium capitalize",children:t.name})," experience"]}),a.jsx("button",{type:"button",onClick:n,className:"ml-auto shrink-0 rounded p-0.5 text-info-subtle-foreground hover:bg-info-edge",title:"Exit role preview",children:a.jsx(Dn,{className:"h-3 w-3"})})]})}var gnt=1,jAs=.9,CAs=.8,_As=.17,Sue=.1,kue=.999,TAs=.9999,EAs=.99,IAs=/[\\\/_+.#"@\[\(\{&]/,NAs=/[\\\/_+.#"@\[\(\{&]/g,AAs=/[\s-]/,sQt=/[\s-]/g;function Lye(e,t,n,r,s,i,o){if(i===t.length)return s===e.length?gnt:EAs;var l=`${s},${i}`;if(o[l]!==void 0)return o[l];for(var c=r.charAt(i),u=n.indexOf(c,s),d=0,f,h,p,m;u>=0;)f=Lye(e,t,n,r,u+1,i+1,o),f>d&&(u===s?f*=gnt:IAs.test(e.charAt(u-1))?(f*=CAs,p=e.slice(s,u-1).match(NAs),p&&s>0&&(f*=Math.pow(kue,p.length))):AAs.test(e.charAt(u-1))?(f*=jAs,m=e.slice(s,u-1).match(sQt),m&&s>0&&(f*=Math.pow(kue,m.length))):(f*=_As,s>0&&(f*=Math.pow(kue,u-s))),e.charAt(u)!==t.charAt(i)&&(f*=TAs)),(f<Sue&&n.charAt(u-1)===r.charAt(i+1)||r.charAt(i+1)===r.charAt(i)&&n.charAt(u-1)!==r.charAt(i))&&(h=Lye(e,t,n,r,u+1,i+2,o),h*Sue>f&&(f=h*Sue)),f>d&&(d=f),u=n.indexOf(c,u+1);return o[l]=d,d}function vnt(e){return e.toLowerCase().replace(sQt," ")}function PAs(e,t,n){return e=n&&n.length>0?`${e+" "+n.join(" ")}`:e,Lye(e,t,vnt(e),vnt(t),0,0,{})}function G1(e,t,{checkForDefaultPrevented:n=!0}={}){return function(s){if(e?.(s),n===!1||!s||!s.defaultPrevented)return t?.(s)}}function ynt(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function UA(...e){return t=>{let n=!1;const r=e.map(s=>{const i=ynt(s,t);return!n&&typeof i=="function"&&(n=!0),i});if(n)return()=>{for(let s=0;s<r.length;s++){const i=r[s];typeof i=="function"?i():ynt(e[s],null)}}}}function sT(...e){return g.useCallback(UA(...e),e)}function $As(e,t=[]){let n=[];function r(i,o){const l=g.createContext(o);l.displayName=i+"Context";const c=n.length;n=[...n,o];const u=f=>{const{scope:h,children:p,...m}=f,v=h?.[e]?.[c]||l,y=g.useMemo(()=>m,Object.values(m));return a.jsx(v.Provider,{value:y,children:p})};u.displayName=i+"Provider";function d(f,h,p={}){const{optional:m=!1}=p,v=h?.[e]?.[c]||l,y=g.useContext(v);if(y)return y;if(o!==void 0)return o;if(!m)throw new Error(`\`${f}\` must be used within \`${i}\``)}return[u,d]}const s=()=>{const i=n.map(o=>g.createContext(o));return function(l){const c=l?.[e]||i;return g.useMemo(()=>({[`__scope${e}`]:{...l,[e]:c}}),[l,c])}};return s.scopeName=e,[r,RAs(s,...t)]}function RAs(...e){const t=e[0];if(e.length===1)return t;const n=()=>{const r=e.map(s=>({useScope:s(),scopeName:s.scopeName}));return function(i){const o=r.reduce((l,{useScope:c,scopeName:u})=>{const f=c(i)[`__scope${u}`];return{...l,...f}},{});return g.useMemo(()=>({[`__scope${t.scopeName}`]:o}),[o])}};return n.scopeName=t.scopeName,n}var m3=globalThis?.document?g.useLayoutEffect:()=>{},MAs=ZA[" useId ".trim().toString()]||(()=>{}),DAs=0;function u0(e){const[t,n]=g.useState(MAs());return m3(()=>{n(r=>r??String(DAs++))},[e]),t?`radix-${t}`:""}var LAs=ZA[" useInsertionEffect ".trim().toString()]||m3;function zAs({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[s,i,o]=FAs({defaultProp:t,onChange:n}),l=e!==void 0,c=l?e:s;{const d=g.useRef(e!==void 0);g.useEffect(()=>{const f=d.current;f!==l&&console.warn(`${r} is changing from ${f?"controlled":"uncontrolled"} to ${l?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),d.current=l},[l,r])}const u=g.useCallback(d=>{if(l){const f=BAs(d)?d(e):d;f!==e&&o.current?.(f)}else i(d)},[l,e,i,o]);return[c,u]}function FAs({defaultProp:e,onChange:t}){const[n,r]=g.useState(e),s=g.useRef(n),i=g.useRef(t);return LAs(()=>{i.current=t},[t]),g.useEffect(()=>{s.current!==n&&(i.current?.(n),s.current=n)},[n,s]),[n,r,i]}function BAs(e){return typeof e=="function"}function iQt(e){const t=g.forwardRef((n,r)=>{let{children:s,...i}=n,o=null,l=!1;const c=[];xnt(s)&&typeof V7=="function"&&(s=V7(s._payload)),g.Children.forEach(s,h=>{if(ZAs(h)){l=!0;const p=h;let m="child"in p.props?p.props.child:p.props.children;xnt(m)&&typeof V7=="function"&&(m=V7(m._payload)),o=UAs(p,m),c.push(o?.props?.children)}else c.push(h)}),o?o=g.cloneElement(o,void 0,c):!l&&g.Children.count(s)===1&&g.isValidElement(s)&&(o=s);const u=o?QAs(o):void 0,d=sT(r,u);if(!o){if(s||s===0)throw new Error(l?KAs(e):GAs(e));return s}const f=qAs(i,o.props??{});return o.type!==g.Fragment&&(f.ref=r?d:u),g.cloneElement(o,f)});return t.displayName=`${e}.Slot`,t}var VAs=Symbol.for("radix.slottable"),UAs=(e,t)=>{if("child"in e.props){const n=e.props.child;return g.isValidElement(n)?g.cloneElement(n,void 0,e.props.children(n.props.children)):null}return g.isValidElement(t)?t:null};function qAs(e,t){const n={...t};for(const r in t){const s=e[r],i=t[r];/^on[A-Z]/.test(r)?s&&i?n[r]=(...l)=>{const c=i(...l);return s(...l),c}:s&&(n[r]=s):r==="style"?n[r]={...s,...i}:r==="className"&&(n[r]=[s,i].filter(Boolean).join(" "))}return{...e,...n}}function QAs(e){let t=Object.getOwnPropertyDescriptor(e.props,"ref")?.get,n=t&&"isReactWarning"in t&&t.isReactWarning;return n?e.ref:(t=Object.getOwnPropertyDescriptor(e,"ref")?.get,n=t&&"isReactWarning"in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}function ZAs(e){return g.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===VAs}var WAs=Symbol.for("react.lazy");function xnt(e){return e!=null&&typeof e=="object"&&"$$typeof"in e&&e.$$typeof===WAs&&"_payload"in e&&HAs(e._payload)}function HAs(e){return typeof e=="object"&&e!==null&&"then"in e}var GAs=e=>`${e} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`,KAs=e=>`${e} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`,V7=ZA[" use ".trim().toString()],YAs=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Fu=YAs.reduce((e,t)=>{const n=iQt(`Primitive.${t}`),r=g.forwardRef((s,i)=>{const{asChild:o,...l}=s,c=o?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),a.jsx(c,{...l,ref:i})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function XAs(e,t){e&&wo.flushSync(()=>e.dispatchEvent(t))}function g3(e){const t=g.useRef(e);return g.useEffect(()=>{t.current=e}),g.useMemo(()=>((...n)=>t.current?.(...n)),[])}var JAs="DismissableLayer",zye="dismissableLayer.update",ePs="dismissableLayer.pointerDownOutside",tPs="dismissableLayer.focusOutside",bnt,kAe=g.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set,dismissableSurfaces:new Set}),oQt=g.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,deferPointerDownOutside:r=!1,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:o,onInteractOutside:l,onDismiss:c,...u}=e,d=g.useContext(kAe),[f,h]=g.useState(null),p=f?.ownerDocument??globalThis?.document,[,m]=g.useState({}),v=sT(t,h),y=Array.from(d.layers),[x]=[...d.layersWithOutsidePointerEventsDisabled].slice(-1),b=x?y.indexOf(x):-1,S=f?y.indexOf(f):-1,k=d.layersWithOutsidePointerEventsDisabled.size>0,j=S>=b,C=g.useRef(!1),T=oPs(A=>{i?.(A),l?.(A),A.defaultPrevented||c?.()},{ownerDocument:p,deferPointerDownOutside:r,isDeferredPointerDownOutsideRef:C,dismissableSurfaces:d.dismissableSurfaces,shouldHandlePointerDownOutside:g.useCallback(A=>{if(!(A instanceof Node))return!1;const P=[...d.branches].some(D=>D.contains(A));return j&&!P},[d.branches,j])}),_=aPs(A=>{if(r&&C.current)return;const P=A.target;[...d.branches].some(F=>F.contains(P))||(o?.(A),l?.(A),A.defaultPrevented||c?.())},p),N=f?S===y.length-1:!1,I=g3(A=>{A.key==="Escape"&&(s?.(A),!A.defaultPrevented&&c&&(A.preventDefault(),c()))});return g.useEffect(()=>{if(N)return p.addEventListener("keydown",I,{capture:!0}),()=>p.removeEventListener("keydown",I,{capture:!0})},[p,N,I]),g.useEffect(()=>{if(f)return n&&(d.layersWithOutsidePointerEventsDisabled.size===0&&(bnt=p.body.style.pointerEvents,p.body.style.pointerEvents="none"),d.layersWithOutsidePointerEventsDisabled.add(f)),d.layers.add(f),wnt(),()=>{n&&(d.layersWithOutsidePointerEventsDisabled.delete(f),d.layersWithOutsidePointerEventsDisabled.size===0&&(p.body.style.pointerEvents=bnt))}},[f,p,n,d]),g.useEffect(()=>()=>{f&&(d.layers.delete(f),d.layersWithOutsidePointerEventsDisabled.delete(f),wnt())},[f,d]),g.useEffect(()=>{const A=()=>m({});return document.addEventListener(zye,A),()=>document.removeEventListener(zye,A)},[]),a.jsx(Fu.div,{...u,ref:v,style:{pointerEvents:k?j?"auto":"none":void 0,...e.style},onFocusCapture:G1(e.onFocusCapture,_.onFocusCapture),onBlurCapture:G1(e.onBlurCapture,_.onBlurCapture),onPointerDownCapture:G1(e.onPointerDownCapture,T.onPointerDownCapture)})});oQt.displayName=JAs;var nPs="DismissableLayerBranch",rPs=g.forwardRef((e,t)=>{const n=g.useContext(kAe),r=g.useRef(null),s=sT(t,r);return g.useEffect(()=>{const i=r.current;if(i)return n.branches.add(i),()=>{n.branches.delete(i)}},[n.branches]),a.jsx(Fu.div,{...e,ref:s})});rPs.displayName=nPs;function sPs(){const e=g.useContext(kAe),[t,n]=g.useState(null);return g.useEffect(()=>{if(t)return e.dismissableSurfaces.add(t),()=>{e.dismissableSurfaces.delete(t)}},[t,e.dismissableSurfaces]),n}var iPs=()=>!0;function oPs(e,t){const{ownerDocument:n=globalThis?.document,deferPointerDownOutside:r=!1,isDeferredPointerDownOutsideRef:s,dismissableSurfaces:i,shouldHandlePointerDownOutside:o=iPs}=t,l=g3(e),c=g.useRef(!1),u=g.useRef(!1),d=g.useRef(new Map),f=g.useRef(()=>{});return g.useEffect(()=>{function h(){u.current=!1,s.current=!1,d.current.clear()}function p(){return Array.from(d.current.values()).some(Boolean)}function m(S){if(!u.current)return;const k=S.target;k instanceof Node&&[...i].some(C=>C.contains(k))||d.current.set(S.type,!0),S.type==="click"&&window.setTimeout(()=>{u.current&&f.current()},0)}function v(S){u.current&&d.current.set(S.type,!1)}const y=S=>{if(S.target&&!c.current){let k=function(){n.removeEventListener("click",f.current);const C=p();h(),C||aQt(ePs,l,j,{discrete:!0})};if(!o(S.target)){n.removeEventListener("click",f.current),h(),c.current=!1;return}const j={originalEvent:S};u.current=!0,s.current=r&&S.button===0,d.current.clear(),!r||S.button!==0?k():(n.removeEventListener("click",f.current),f.current=k,n.addEventListener("click",f.current,{once:!0}))}else n.removeEventListener("click",f.current),h();c.current=!1},x=["pointerup","mousedown","mouseup","touchstart","touchend","click"];for(const S of x)n.addEventListener(S,m,!0),n.addEventListener(S,v);const b=window.setTimeout(()=>{n.addEventListener("pointerdown",y)},0);return()=>{window.clearTimeout(b),n.removeEventListener("pointerdown",y),n.removeEventListener("click",f.current);for(const S of x)n.removeEventListener(S,m,!0),n.removeEventListener(S,v)}},[n,l,r,s,i,o]),{onPointerDownCapture:()=>c.current=!0}}function aPs(e,t=globalThis?.document){const n=g3(e),r=g.useRef(!1);return g.useEffect(()=>{const s=i=>{i.target&&!r.current&&aQt(tPs,n,{originalEvent:i},{discrete:!1})};return t.addEventListener("focusin",s),()=>t.removeEventListener("focusin",s)},[t,n]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}function wnt(){const e=new CustomEvent(zye);document.dispatchEvent(e)}function aQt(e,t,n,{discrete:r}){const s=n.originalEvent.target,i=new CustomEvent(e,{bubbles:!1,cancelable:!0,detail:n});t&&s.addEventListener(e,t,{once:!0}),r?XAs(s,i):s.dispatchEvent(i)}var Oue="focusScope.autoFocusOnMount",jue="focusScope.autoFocusOnUnmount",Snt={bubbles:!1,cancelable:!0},lPs="FocusScope",lQt=g.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:s,onUnmountAutoFocus:i,...o}=e,[l,c]=g.useState(null),u=g3(s),d=g3(i),f=g.useRef(null),h=sT(t,c),p=g.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;g.useEffect(()=>{if(r){let v=function(S){if(p.paused||!l)return;const k=S.target;l.contains(k)?f.current=k:e1(f.current,{select:!0})},y=function(S){if(p.paused||!l)return;const k=S.relatedTarget;k!==null&&(l.contains(k)||e1(f.current,{select:!0}))},x=function(S){if(document.activeElement===document.body)for(const j of S)j.removedNodes.length>0&&e1(l)};document.addEventListener("focusin",v),document.addEventListener("focusout",y);const b=new MutationObserver(x);return l&&b.observe(l,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",v),document.removeEventListener("focusout",y),b.disconnect()}}},[r,l,p.paused]),g.useEffect(()=>{if(l){Ont.add(p);const v=document.activeElement;if(!l.contains(v)){const x=new CustomEvent(Oue,Snt);l.addEventListener(Oue,u),l.dispatchEvent(x),x.defaultPrevented||(cPs(pPs(cQt(l)),{select:!0}),document.activeElement===v&&e1(l))}return()=>{l.removeEventListener(Oue,u),setTimeout(()=>{const x=new CustomEvent(jue,Snt);l.addEventListener(jue,d),l.dispatchEvent(x),x.defaultPrevented||e1(v??document.body,{select:!0}),l.removeEventListener(jue,d),Ont.remove(p)},0)}}},[l,u,d,p]);const m=g.useCallback(v=>{if(!n&&!r||p.paused)return;const y=v.key==="Tab"&&!v.altKey&&!v.ctrlKey&&!v.metaKey,x=document.activeElement;if(y&&x){const b=v.currentTarget,[S,k]=uPs(b);S&&k?!v.shiftKey&&x===k?(v.preventDefault(),n&&e1(S,{select:!0})):v.shiftKey&&x===S&&(v.preventDefault(),n&&e1(k,{select:!0})):x===b&&v.preventDefault()}},[n,r,p.paused]);return a.jsx(Fu.div,{tabIndex:-1,...o,ref:h,onKeyDown:m})});lQt.displayName=lPs;function cPs(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(e1(r,{select:t}),document.activeElement!==n)return}function uPs(e){const t=cQt(e),n=knt(t,e),r=knt(t.reverse(),e);return[n,r]}function cQt(e){const t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:r=>{const s=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||s?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;n.nextNode();)t.push(n.currentNode);return t}function knt(e,t){const n=typeof t.checkVisibility=="function"&&t.checkVisibility({checkVisibilityCSS:!0});for(const r of e)if(!(n?!r.checkVisibility({checkVisibilityCSS:!0}):dPs(r,{upTo:t})))return r}function dPs(e,{upTo:t}){if(getComputedStyle(e).visibility==="hidden")return!0;for(;e;){if(t!==void 0&&e===t)return!1;if(getComputedStyle(e).display==="none")return!0;e=e.parentElement}return!1}function fPs(e){return e instanceof HTMLInputElement&&"select"in e}function e1(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&fPs(e)&&t&&e.select()}}var Ont=hPs();function hPs(){let e=[];return{add(t){const n=e[0];t!==n&&n?.pause(),e=jnt(e,t),e.unshift(t)},remove(t){e=jnt(e,t),e[0]?.resume()}}}function jnt(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function pPs(e){return e.filter(t=>t.tagName!=="A")}var mPs="Portal",uQt=g.forwardRef((e,t)=>{const{container:n,...r}=e,[s,i]=g.useState(!1);m3(()=>i(!0),[]);const o=n||s&&globalThis?.document?.body;return o?wo.createPortal(a.jsx(Fu.div,{...r,ref:t}),o):null});uQt.displayName=mPs;function gPs(e,t){return g.useReducer((n,r)=>t[n][r]??n,e)}var iee=e=>{const{present:t,children:n}=e,r=vPs(t),s=typeof n=="function"?n({present:r.isPresent}):g.Children.only(n),i=yPs(r.ref,xPs(s));return typeof n=="function"||r.isPresent?g.cloneElement(s,{ref:i}):null};iee.displayName="Presence";function vPs(e){const[t,n]=g.useState(),r=g.useRef(null),s=g.useRef(e),i=g.useRef("none"),o=g.useRef(void 0),l=e?"mounted":"unmounted",[c,u]=gPs(l,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return g.useEffect(()=>{c==="mounted"?(i.current=o.current??LM(r.current),o.current=void 0):i.current="none"},[c]),m3(()=>{const d=r.current,f=s.current;if(f!==e){const p=i.current,m=LM(d);e?(o.current=m,u("MOUNT")):m==="none"||d?.display==="none"?u("UNMOUNT"):u(f&&p!==m?"ANIMATION_OUT":"UNMOUNT"),s.current=e}},[e,u]),m3(()=>{if(t){let d;const f=t.ownerDocument.defaultView??window,h=m=>{const y=LM(r.current).includes(CSS.escape(m.animationName));if(m.target===t&&y&&(u("ANIMATION_END"),!s.current)){const x=t.style.animationFillMode;t.style.animationFillMode="forwards",d=f.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=x)})}},p=m=>{m.target===t&&(i.current=LM(r.current))};return t.addEventListener("animationstart",p),t.addEventListener("animationcancel",h),t.addEventListener("animationend",h),()=>{f.clearTimeout(d),t.removeEventListener("animationstart",p),t.removeEventListener("animationcancel",h),t.removeEventListener("animationend",h)}}else u("ANIMATION_END")},[t,u]),{isPresent:["mounted","unmountSuspended"].includes(c),ref:g.useCallback(d=>{if(d){const f=getComputedStyle(d);r.current=f,o.current=LM(f)}else r.current=null;n(d)},[])}}function Cnt(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function yPs(...e){const t=g.useRef(e);return t.current=e,g.useCallback(n=>{const r=t.current;let s=!1;const i=r.map(o=>{const l=Cnt(o,n);return!s&&typeof l=="function"&&(s=!0),l});if(s)return()=>{for(let o=0;o<i.length;o++){const l=i[o];typeof l=="function"?l():Cnt(r[o],null)}}},[])}function LM(e){return e?.animationName||"none"}function xPs(e){let t=Object.getOwnPropertyDescriptor(e.props,"ref")?.get,n=t&&"isReactWarning"in t&&t.isReactWarning;return n?e.ref:(t=Object.getOwnPropertyDescriptor(e,"ref")?.get,n=t&&"isReactWarning"in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}var U7=0,wE=null;function bPs(){g.useEffect(()=>{wE||(wE={start:_nt(),end:_nt()});const{start:e,end:t}=wE;return document.body.firstElementChild!==e&&document.body.insertAdjacentElement("afterbegin",e),document.body.lastElementChild!==t&&document.body.insertAdjacentElement("beforeend",t),U7++,()=>{U7===1&&(wE?.start.remove(),wE?.end.remove(),wE=null),U7=Math.max(0,U7-1)}},[])}function _nt(){const e=document.createElement("span");return e.setAttribute("data-radix-focus-guard",""),e.tabIndex=0,e.style.outline="none",e.style.opacity="0",e.style.position="fixed",e.style.pointerEvents="none",e}var Ny=function(){return Ny=Object.assign||function(t){for(var n,r=1,s=arguments.length;r<s;r++){n=arguments[r];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i])}return t},Ny.apply(this,arguments)};function dQt(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var s=0,r=Object.getOwnPropertySymbols(e);s<r.length;s++)t.indexOf(r[s])<0&&Object.prototype.propertyIsEnumerable.call(e,r[s])&&(n[r[s]]=e[r[s]]);return n}function wPs(e,t,n){if(n||arguments.length===2)for(var r=0,s=t.length,i;r<s;r++)(i||!(r in t))&&(i||(i=Array.prototype.slice.call(t,0,r)),i[r]=t[r]);return e.concat(i||Array.prototype.slice.call(t))}var vV="right-scroll-bar-position",yV="width-before-scroll-bar",SPs="with-scroll-bars-hidden",kPs="--removed-body-scroll-bar-size";function Cue(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function OPs(e,t){var n=g.useState(function(){return{value:e,callback:t,facade:{get current(){return n.value},set current(r){var s=n.value;s!==r&&(n.value=r,n.callback(r,s))}}}})[0];return n.callback=t,n.facade}var jPs=typeof window<"u"?g.useLayoutEffect:g.useEffect,Tnt=new WeakMap;function CPs(e,t){var n=OPs(null,function(r){return e.forEach(function(s){return Cue(s,r)})});return jPs(function(){var r=Tnt.get(n);if(r){var s=new Set(r),i=new Set(e),o=n.current;s.forEach(function(l){i.has(l)||Cue(l,null)}),i.forEach(function(l){s.has(l)||Cue(l,o)})}Tnt.set(n,e)},[e]),n}function _Ps(e){return e}function TPs(e,t){t===void 0&&(t=_Ps);var n=[],r=!1,s={read:function(){if(r)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return n.length?n[n.length-1]:e},useMedium:function(i){var o=t(i,r);return n.push(o),function(){n=n.filter(function(l){return l!==o})}},assignSyncMedium:function(i){for(r=!0;n.length;){var o=n;n=[],o.forEach(i)}n={push:function(l){return i(l)},filter:function(){return n}}},assignMedium:function(i){r=!0;var o=[];if(n.length){var l=n;n=[],l.forEach(i),o=n}var c=function(){var d=o;o=[],d.forEach(i)},u=function(){return Promise.resolve().then(c)};u(),n={push:function(d){o.push(d),u()},filter:function(d){return o=o.filter(d),n}}}};return s}function EPs(e){e===void 0&&(e={});var t=TPs(null);return t.options=Ny({async:!0,ssr:!1},e),t}var fQt=function(e){var t=e.sideCar,n=dQt(e,["sideCar"]);if(!t)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=t.read();if(!r)throw new Error("Sidecar medium not found");return g.createElement(r,Ny({},n))};fQt.isSideCarExport=!0;function IPs(e,t){return e.useMedium(t),fQt}var hQt=EPs(),_ue=function(){},oee=g.forwardRef(function(e,t){var n=g.useRef(null),r=g.useState({onScrollCapture:_ue,onWheelCapture:_ue,onTouchMoveCapture:_ue}),s=r[0],i=r[1],o=e.forwardProps,l=e.children,c=e.className,u=e.removeScrollBar,d=e.enabled,f=e.shards,h=e.sideCar,p=e.noRelative,m=e.noIsolation,v=e.inert,y=e.allowPinchZoom,x=e.as,b=x===void 0?"div":x,S=e.gapMode,k=dQt(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),j=h,C=CPs([n,t]),T=Ny(Ny({},k),s);return g.createElement(g.Fragment,null,d&&g.createElement(j,{sideCar:hQt,removeScrollBar:u,shards:f,noRelative:p,noIsolation:m,inert:v,setCallbacks:i,allowPinchZoom:!!y,lockRef:n,gapMode:S}),o?g.cloneElement(g.Children.only(l),Ny(Ny({},T),{ref:C})):g.createElement(b,Ny({},T,{className:c,ref:C}),l))});oee.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1};oee.classNames={fullWidth:yV,zeroRight:vV};var NPs=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function APs(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=NPs();return t&&e.setAttribute("nonce",t),e}function PPs(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function $Ps(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var RPs=function(){var e=0,t=null;return{add:function(n){e==0&&(t=APs())&&(PPs(t,n),$Ps(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},MPs=function(){var e=RPs();return function(t,n){g.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},pQt=function(){var e=MPs(),t=function(n){var r=n.styles,s=n.dynamic;return e(r,s),null};return t},DPs={left:0,top:0,right:0,gap:0},Tue=function(e){return parseInt(e||"",10)||0},LPs=function(e){var t=window.getComputedStyle(document.body),n=t[e==="padding"?"paddingLeft":"marginLeft"],r=t[e==="padding"?"paddingTop":"marginTop"],s=t[e==="padding"?"paddingRight":"marginRight"];return[Tue(n),Tue(r),Tue(s)]},zPs=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return DPs;var t=LPs(e),n=document.documentElement.clientWidth,r=window.innerWidth;return{left:t[0],top:t[1],right:t[2],gap:Math.max(0,r-n+t[2]-t[0])}},FPs=pQt(),eN="data-scroll-locked",BPs=function(e,t,n,r){var s=e.left,i=e.top,o=e.right,l=e.gap;return n===void 0&&(n="margin"),`
|
|
702
702
|
.`.concat(SPs,` {
|