mastra 1.40.2-alpha.9 → 1.40.2

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.
@@ -3,7 +3,7 @@ name: mastra
3
3
  description: Documentation for mastra. Use when working with mastra APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "mastra"
6
- version: "1.40.2-alpha.9"
6
+ version: "1.40.2"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.40.2-alpha.9",
2
+ "version": "1.40.2",
3
3
  "package": "mastra",
4
4
  "exports": {
5
5
  "PosthogAnalytics": {
package/dist/index.js CHANGED
@@ -48,7 +48,7 @@ import { isDeepStrictEqual } from "util";
48
48
  // package.json
49
49
  var package_default = {
50
50
  name: "mastra",
51
- version: "1.40.2-alpha.9",
51
+ version: "1.40.2",
52
52
  license: "Apache-2.0",
53
53
  description: "cli for mastra",
54
54
  type: "module",
@@ -1,2 +1,2 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./main-B2dVWRoj.js","./rolldown-runtime-BWaJ3C7D.js","./lib-DtdM3YyA.js","./preload-helper-CRzLMJPS.js","./dist-Bb1O3cNb.js","./dist-Dq32n9F4.js","./dist-KpoPGPlt.js","./dist-Cs7oVa-O.js","./dist-CRSyDOHk.js"])))=>i.map(i=>d[i]);
2
- import{t as e}from"./preload-helper-CRzLMJPS.js";(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),t.credentials=e.crossOrigin===`use-credentials`?`include`:e.crossOrigin===`anonymous`?`omit`:`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var t=!1;function n(e){return e instanceof Error?e.stack||e.message:String(e)}function r(e,{showDetails:r=t}={}){let i=document.getElementById(`root`);if(!i||i.childElementCount>0)return;let a=document.createElement(`main`);a.setAttribute(`role`,`alert`),a.style.cssText=`min-height:100vh;background:#0b0d10;color:#f4f4f5;font-family:"Mona Sans Variable",ui-sans-serif,system-ui,sans-serif;padding:32px;box-sizing:border-box;`;let o=document.createElement(`h1`);o.textContent=`Mastra Studio failed to start`,o.style.cssText=`font-size:20px;line-height:1.4;margin:0 0 8px;`;let s=document.createElement(`p`);if(s.textContent=r?`The startup module failed before React could render. Check the Vite terminal and browser console for the original request details.`:`The startup module failed before React could render. Run Studio in development mode to view detailed diagnostics.`,s.style.cssText=`color:#a1a1aa;max-width:760px;margin:0 0 20px;line-height:1.6;`,a.append(o,s),r){let t=document.createElement(`pre`);t.textContent=n(e),t.style.cssText=`white-space:pre-wrap;overflow:auto;background:#18181b;border:1px solid #3f3f46;border-radius:8px;padding:16px;max-width:100%;line-height:1.5;`,a.append(t)}i.replaceChildren(a)}try{let{startStudio:t}=await e(async()=>{let{startStudio:e}=await import(`./main-B2dVWRoj.js`);return{startStudio:e}},__vite__mapDeps([0,1,2,3,4,5,6,7,8]),import.meta.url);t()}catch(e){console.error(`Mastra Studio failed to start`,e),r(e)}
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./main-BhWoo2De.js","./rolldown-runtime-BWaJ3C7D.js","./lib-DtdM3YyA.js","./preload-helper-CRzLMJPS.js","./dist-Bb1O3cNb.js","./dist-Dq32n9F4.js","./dist-KpoPGPlt.js","./dist-Cs7oVa-O.js","./dist-CRSyDOHk.js"])))=>i.map(i=>d[i]);
2
+ import{t as e}from"./preload-helper-CRzLMJPS.js";(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),t.credentials=e.crossOrigin===`use-credentials`?`include`:e.crossOrigin===`anonymous`?`omit`:`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var t=!1;function n(e){return e instanceof Error?e.stack||e.message:String(e)}function r(e,{showDetails:r=t}={}){let i=document.getElementById(`root`);if(!i||i.childElementCount>0)return;let a=document.createElement(`main`);a.setAttribute(`role`,`alert`),a.style.cssText=`min-height:100vh;background:#0b0d10;color:#f4f4f5;font-family:"Mona Sans Variable",ui-sans-serif,system-ui,sans-serif;padding:32px;box-sizing:border-box;`;let o=document.createElement(`h1`);o.textContent=`Mastra Studio failed to start`,o.style.cssText=`font-size:20px;line-height:1.4;margin:0 0 8px;`;let s=document.createElement(`p`);if(s.textContent=r?`The startup module failed before React could render. Check the Vite terminal and browser console for the original request details.`:`The startup module failed before React could render. Run Studio in development mode to view detailed diagnostics.`,s.style.cssText=`color:#a1a1aa;max-width:760px;margin:0 0 20px;line-height:1.6;`,a.append(o,s),r){let t=document.createElement(`pre`);t.textContent=n(e),t.style.cssText=`white-space:pre-wrap;overflow:auto;background:#18181b;border:1px solid #3f3f46;border-radius:8px;padding:16px;max-width:100%;line-height:1.5;`,a.append(t)}i.replaceChildren(a)}try{let{startStudio:t}=await e(async()=>{let{startStudio:e}=await import(`./main-BhWoo2De.js`);return{startStudio:e}},__vite__mapDeps([0,1,2,3,4,5,6,7,8]),import.meta.url);t()}catch(e){console.error(`Mastra Studio failed to start`,e),r(e)}
@@ -884,6 +884,6 @@ Ask one simple question at a time.`;function TZr(e,t){let n=(0,W.useRef)(e);retu
884
884
  `),i=r.length-xMi;return!t||i<2?(0,G.jsx)(G.Fragment,{children:e}):(0,G.jsxs)(G.Fragment,{children:[r.slice(0,xMi).join(`
885
885
  `),`
886
886
  `,(0,G.jsxs)(`span`,{className:`text-muted-foreground`,children:[`+`,i,` more lines`]})]})}function EMi({timestamp:e}){let t=DZe(e);return t?(0,G.jsxs)(`time`,{dateTime:fC(e)?.toISOString(),children:[t.day,` `,(0,G.jsx)(`span`,{className:`text-foreground`,children:t.time}),t.fraction]}):(0,G.jsx)(`time`,{children:String(e)})}function DMi({timestamp:e,level:t,message:n,fields:r,wrap:i=!0,collapse:a=!0}){let o=r?Object.entries(r):[];return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{className:`font-mono text-body-sm whitespace-nowrap text-muted-foreground tabular-nums`,children:(0,G.jsx)(EMi,{timestamp:e})}),(0,G.jsx)(`span`,{className:c(`font-mono text-body-sm uppercase`,yMi[t]),children:t}),(0,G.jsxs)(`span`,{className:c(`min-w-0 font-mono text-body-sm text-foreground @max-md:col-span-full`,i?`wrap-anywhere whitespace-pre-wrap`:`whitespace-pre`),children:[(0,G.jsx)(TMi,{message:n,collapse:a}),o.length>0&&(0,G.jsx)(`span`,{className:`ml-3`,children:(0,G.jsx)(wMi,{entries:o})})]})]})}var OMi={gridTemplateColumns:`auto auto minmax(0,1fr)`};function kMi({children:e,scrollRef:t,wrap:n=!0,className:r}){return(0,G.jsx)(gMi,{className:c(`flex flex-col`,r),children:(0,G.jsx)(AS,{orientation:`both`,mask:!1,className:`flex min-h-0 flex-1 flex-col`,children:(0,G.jsx)(kS,{ref:t,className:`min-h-0 flex-1 overscroll-x-none`,children:(0,G.jsx)(`div`,{className:c(`grid content-start`,n?`w-full`:`w-max min-w-full`),style:OMi,children:e})})})})}function AMi({level:e,featured:t},n,r){return c(`relative col-span-full grid min-h-6 grid-cols-subgrid items-start gap-x-4 gap-y-1 px-3 py-0.5 text-left`,`before:absolute before:inset-y-1 before:left-1 before:w-0.5 before:rounded-full before:content-['']`,bMi[e],(e===`error`||e===`fatal`)&&`bg-destructive-subtle`,t&&`bg-surface-panel`,n&&[`cursor-pointer after:pointer-events-none after:absolute after:inset-0 after:content-[''] hover:after:bg-fill-subtle focus-visible:bg-surface-panel`,`focus-visible:outline-1 focus-visible:outline-solid focus-visible:outline-border-focus focus-visible:-outline-offset-1`],r)}function jMi({level:e,featured:t,className:n,...r}){return(0,G.jsx)(`div`,{className:AMi({level:e,featured:t},!1,n),"data-featured":t||void 0,...r})}function MMi({level:e,featured:t,className:n,type:r=`button`,...i}){return(0,G.jsx)(`button`,{type:r,className:AMi({level:e,featured:t},!0,n),"data-featured":t||void 0,...i})}function NMi({height:e}){return(0,G.jsx)(`div`,{"aria-hidden":!0,className:`col-span-full`,style:{height:e}})}Object.assign(kMi,{Frame:gMi,Header:_Mi,HeaderCell:vMi,Row:jMi,RowButton:MMi,Line:DMi,Spacer:NMi});function PMi({log:e}){return(0,G.jsxs)(p9,{title:`Details`,children:[(0,G.jsx)(p9.Row,{label:`Level`,children:(0,G.jsx)(`span`,{className:c(`capitalize`,yMi[e.level]),children:e.level})}),e.entityType&&(0,G.jsx)(p9.Row,{label:`Entity type`,children:e.entityType}),e.entityName&&(0,G.jsx)(p9.Row,{label:`Entity name`,children:e.entityName}),e.serviceName&&(0,G.jsx)(p9.Row,{label:`Service`,children:e.serviceName}),e.environment&&(0,G.jsx)(p9.Row,{label:`Environment`,children:e.environment}),e.source&&(0,G.jsx)(p9.Row,{label:`Source`,children:e.source})]})}function FMi(e){if(e.trim().startsWith(`{`))try{return JSON.stringify(JSON.parse(e),null,2)}catch{return}}function IMi({message:e}){let t=FMi(e);return t===void 0?(0,G.jsx)(MN.CodeSection,{title:`Message`,codeStr:e,simplified:!0}):(0,G.jsx)(MN.CodeSection,{title:`Message`,codeStr:t})}function LMi(e){return e===null||[`string`,`number`,`boolean`].includes(typeof e)}function RMi(e){return e!=null&&e!==``}function zMi({title:e,values:t}){let n=Object.entries(t??{});if(!n.every(([,e])=>LMi(e)))return(0,G.jsx)(MN.CodeSection,{title:e,codeStr:JSON.stringify(t,null,2)});let r=n.filter(([,e])=>RMi(e));return r.length===0?null:(0,G.jsx)(p9,{title:e,children:r.map(([e,t])=>(0,G.jsx)(p9.Row,{label:e,mono:!0,children:String(t)},e))})}function BMi({log:e,onClose:t,onTraceClick:n,onSpanClick:r,onPrevious:i,onNext:a,depth:o,actions:s}){let c=e?gC(e.timestamp)??``:``;return(0,G.jsx)(MN,{open:!!e,onClose:t,title:e?`Log ${c}`:`Log`,depth:o,children:e&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(MN.Header,{children:[(0,G.jsx)(MN.CloseButton,{onClick:t}),(0,G.jsx)(MN.Heading,{children:`Log`}),(0,G.jsx)(MN.Metadata,{children:(0,G.jsx)(MN.Meta,{tooltip:c,children:c})}),(0,G.jsxs)(MN.HeaderActions,{children:[s,(0,G.jsx)(MN.NextPrevNav,{onPrevious:i,onNext:a,previousLabel:`Go to previous log`,nextLabel:`Go to next log`})]})]}),(0,G.jsx)(MN.Content,{children:(0,G.jsxs)(`div`,{className:`grid gap-6 p-2`,children:[(0,G.jsx)(PMi,{log:e}),(0,G.jsx)(IMi,{message:e.message}),(0,G.jsx)(zMi,{title:`Fields`,values:e.data}),(0,G.jsx)(zMi,{title:`Metadata`,values:e.metadata}),(e.traceId||e.spanId)&&(0,G.jsxs)(`div`,{className:`grid gap-2`,children:[e.traceId&&(0,G.jsxs)(xN,{className:`w-full min-w-0`,children:[(0,G.jsxs)(X,{className:`min-w-0 flex-1 justify-between overflow-hidden`,icon:(0,G.jsx)(mP,{}),onClick:()=>e.traceId&&n?.(e.traceId),children:[(0,G.jsx)(`span`,{children:`Trace`}),(0,G.jsxs)(T,{as:`span`,variant:`caption`,tone:`faint`,className:`ml-auto min-w-0 truncate`,children:[`# `,e.traceId]})]}),(0,G.jsx)(dC,{content:e.traceId,tooltip:`Copy trace ID to clipboard`})]}),e.spanId&&(0,G.jsxs)(xN,{className:`w-full min-w-0`,children:[(0,G.jsxs)(X,{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:(0,G.jsx)(mP,{}),children:[(0,G.jsx)(`span`,{children:`Span`}),(0,G.jsxs)(T,{as:`span`,variant:`caption`,tone:`faint`,className:`ml-auto min-w-0 truncate`,children:[`# `,e.spanId]})]}),(0,G.jsx)(dC,{content:e.spanId,tooltip:`Copy span ID to clipboard`})]})]})]})})]})})}function VMi({error:e,resource:t,errorTitle:n}){if(JN(e))return(0,G.jsx)(vR,{});if(YN(e))return(0,G.jsx)(_R,{resource:t});if(QN(e))return(0,G.jsx)(Vx,{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(ZN(e,`logs`))return(0,G.jsx)(Vx,{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.`});let r=e instanceof Error?e.message:void 0;return(0,G.jsx)(Vx,{tone:`error`,titleSlot:n,descriptionSlot:r??`Unknown error`})}var HMi={debug:`neutral`,info:`info`,warn:`warning`,error:`destructive`,fatal:`destructive`};function UMi({level:e}){return(0,G.jsx)(AP,{children:(0,G.jsx)(YS,{variant:HMi[e],children:e})})}function WMi({entityType:e,className:t}){let n=c(`size-3.5 shrink-0 text-subtle-foreground`,t);switch(e.toLowerCase()){case`agent`:return(0,G.jsx)(WP,{className:n,"aria-hidden":!0});case`workflow`:case`workflow_run`:return(0,G.jsx)(KS,{className:n,"aria-hidden":!0});case`tool`:return(0,G.jsx)(ZP,{className:n,"aria-hidden":!0});default:return null}}function GMi({entityType:e,entityName:t}){return(0,G.jsxs)(AP,{className:`flex min-w-0 items-center gap-2`,children:[(0,G.jsx)(WMi,{entityType:e??``}),t?(0,G.jsx)(T,{as:`span`,variant:`body-sm`,className:`min-w-0 truncate`,children:t}):`-`]})}function KMi({message:e}){return(0,G.jsx)(AP,{className:`min-w-0 truncate font-mono text-body-sm text-muted-foreground`,children:e})}function qMi({data:e}){if(!e||Object.keys(e).length===0)return(0,G.jsx)(AP,{children:null});let t=Object.entries(e).map(([e,t])=>{if(typeof t==`string`)return`${e}: ${t}`;try{return`${e}: ${JSON.stringify(t)}`}catch{return`${e}: <unserializable>`}}).join(`, `);return(0,G.jsx)(NP,{font:`mono`,children:t})}var m9=Object.assign(LP,{Top:HP,TopCell:zP,SortableTopCell:VP,TopCellWithTooltip:BP,TopCellSmart:Rzt,RowWrapper:Nzt,RowButton:RP,RowLink:jzt,Spacer:Wzt,NoMatch:FP,DateCell:$Rt,TimeCell:tzt,LevelCell:UMi,EntityCell:GMi,MessageCell:KMi,DataCell:qMi,NextPageLoading:PP}),JMi=`6rem 9rem 5rem 10rem minmax(8rem,1fr) minmax(8rem,1fr)`,YMi=36,XMi=8;function ZMi({logs:e,isLoading:t,isFetchingNextPage:n,hasNextPage:r,setEndOfListElement:i,logIdMap:a,featuredLogId:o,onLogClick:s,timestampSort:c,onSortChange:l}){let u=(0,W.useRef)(null),d=qli({count:e.length,getScrollElement:()=>u.current,estimateSize:()=>YMi,overscan:XMi}),{getRowProps:f}=UP({count:e.length,containerRef:u,onNavigate:e=>d.scrollToIndex(e),global:!0}),p=(0,W.useRef)(t);if((0,W.useEffect)(()=>{p.current&&!t&&u.current?.dispatchEvent(new Event(`scroll`)),p.current=t},[t]),t)return(0,G.jsx)(QP,{columns:JMi,fit:`container`});let m=d.getVirtualItems(),h=d.getTotalSize(),g=m[0]?.start??0,_=m.length>0?Math.max(0,h-(m[m.length-1]?.end??0)):0;return(0,G.jsxs)(m9,{columns:JMi,scrollRef:u,className:`min-w-0`,fit:`container`,children:[(0,G.jsxs)(m9.Top,{children:[l?(0,G.jsx)(m9.SortableTopCell,{sortKey:`timestamp`,sort:c,onSortChange:l,children:`Date`}):(0,G.jsx)(m9.TopCell,{children:`Date`}),(0,G.jsx)(m9.TopCell,{children:`Time`}),(0,G.jsx)(m9.TopCell,{children:`Level`}),(0,G.jsx)(m9.TopCell,{children:`Entity`}),(0,G.jsx)(m9.TopCell,{children:`Message`}),(0,G.jsx)(m9.TopCell,{children:`Data`})]}),e.length===0?(0,G.jsx)(m9.NoMatch,{message:`No logs match your search`}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(m9.Spacer,{height:g}),m.map(t=>{let n=e[t.index];if(!n)return null;let r=a.get(n);if(!r)return null;let i=r===o;return(0,G.jsxs)(m9.RowButton,{ref:d.measureElement,"data-index":t.index,...f(t.index),onClick:()=>s(n),featured:i,variant:n.level===`error`||n.level===`fatal`?`error`:`default`,children:[(0,G.jsx)(m9.DateCell,{timestamp:n.timestamp}),(0,G.jsx)(m9.TimeCell,{timestamp:n.timestamp}),(0,G.jsx)(m9.LevelCell,{level:n.level}),(0,G.jsx)(m9.EntityCell,{entityType:n.entityType,entityName:n.entityName}),(0,G.jsx)(m9.MessageCell,{message:n.message}),(0,G.jsx)(m9.DataCell,{data:n.data})]},r)}),(0,G.jsx)(m9.Spacer,{height:_})]}),(0,G.jsx)(m9.NextPageLoading,{isLoading:n,hasMore:r,setEndOfListElement:i})]})}function QMi({onClear:e,onRemoveAll:t,onSave:n,onRemoveSaved:r,isLoading:i,filterFields:a,filterTokens:o,onFilterTokensChange:s,autoFocusFilterFieldId:l}){let u=o.length>0,d=o.some(e=>$Mi(e,a));return u?(0,G.jsxs)(`div`,{className:c(`grid grid-cols-[1fr_auto] items-start gap-3`),children:[(0,G.jsx)(lMi,{fields:a,tokens:o,onTokensChange:s,disabled:i,autoFocusFieldId:l}),u&&(0,G.jsx)($ji,{disabled:i,onClear:d?e:void 0,onRemoveAll:t,onSave:n,onRemoveSaved:r})]}):null}function $Mi(e,t){let n=t.find(t=>t.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}var eNi={"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`},tNi=`Pick a wider range or lower the logging level. Verbose entries (debug, info) may be filtered out.`;function nNi({datePreset:e,dateFrom:t,dateTo:n}){return e&&e!==`all`&&e!==`custom`?{title:`No logs for ${eNi[e]}`,description:tNi}:t&&n?{title:`No logs between ${hC(t,`date-time`)} and ${hC(n,`date-time`)}`,description:tNi}:t?{title:`No logs since ${hC(t,`date-time`)}`,description:tNi}:{title:`No logs yet`,description:`Logs will appear here once agents, workflows, or tools are executed.`}}var rNi=({datePreset:e,dateFrom:t,dateTo:n}={})=>{let{title:r,description:i}=nNi({datePreset:e,dateFrom:t,dateTo:n});return(0,G.jsx)(Vx,{titleSlot:r,descriptionSlot:i,actionSlot:(0,G.jsx)(X,{variant:`ghost`,render:(0,G.jsx)(`a`,{href:`https://mastra.ai/en/docs/observability/logging`,target:`_blank`,rel:`noopener noreferrer`}),icon:(0,G.jsx)(nF,{}),children:`Logging documentation`}),variant:`fill`})},iNi=`Filters setting for Logs saved`,aNi=`Filters setting for Logs cleared up`;function oNi(e,t,n){let{storageKey:r,messages:i,skipHydration:a}=n??{},[o,s]=(0,W.useState)(()=>igi(r)!==null),c=(0,W.useCallback)(()=>{ngi(e,r),s(!0);let t=i?.saved??iNi;t!==!1&&Qx.success(t)},[e,r,i?.saved]),l=(0,W.useCallback)(()=>{rgi(r),s(!1);let e=i?.cleared??aNi;e!==!1&&Qx.success(e)},[r,i?.cleared]),u=(0,W.useRef)(!1);return(0,W.useEffect)(()=>{if(a||u.current||(u.current=!0,agi(e)))return;let n=igi(r);n&&t(e=>{let t=new URLSearchParams(e);for(let[e,r]of n)t.append(e,r);return t},{replace:!0})},[]),{hasSavedFilters:o,handleSave:c,handleRemoveSaved:l}}function sNi(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 cNi(e){let t=new Map;for(let n of e){if(n.logId){t.set(n,n.logId);continue}let e=n.timestamp instanceof Date?n.timestamp.toISOString():n.timestamp;t.set(n,sNi(`${e}${n.message??``}${n.data?JSON.stringify(n.data):``}`))}return t}function lNi(e,t,n,r){let i=(0,W.useMemo)(()=>cNi(e),[e]),a=(0,W.useMemo)(()=>{let t=new Map;for(let[n,r]of e.entries()){let e=i.get(r);e&&t.set(e,{log:r,idx:n})}return t},[e,i]),o=(t?a.get(t):void 0)?.idx??-1,s=o>=0?e[o]??null:null;return{logIdMap:i,getLogId:(0,W.useCallback)(e=>i.get(e),[i]),featuredLog:s,handleLogClick:(0,W.useCallback)(e=>{let a=i.get(e);a&&n(t===a?{logId:null}:r?{logId:a,traceId:e.traceId??null,spanId:null}:{logId:a})},[i,t,r,n]),handlePreviousLog:o>0?()=>{let t=e[o-1];if(!t)return;let a=i.get(t);a&&n(r?{logId:a,traceId:t.traceId??null,spanId:null}:{logId:a})}:void 0,handleNextLog:o>=0&&o<e.length-1?()=>{let t=e[o+1];if(!t)return;let a=i.get(t);a&&n(r?{logId:a,traceId:t.traceId??null,spanId:null}:{logId:a})}:void 0}}var uNi=`logId`,dNi=`traceId`,fNi=`spanId`,h9=864e5,pNi={"last-24h":h9,"last-3d":3*h9,"last-7d":7*h9,"last-14d":14*h9,"last-30d":30*h9};function mNi(e){e.delete(uNi),e.delete(dNi),e.delete(fNi)}function hNi(e,t,n){let{onRemoveAll:r}=n??{},i=(0,W.useMemo)(()=>{let t=e.get(b7);return t&&$hi.has(t)?t:Xhi},[e]),a=e.get(x7),o=e.get(S7),s=(0,W.useMemo)(()=>{if(i===`custom`){if(!a)return;let e=new Date(a);return Number.isNaN(e.getTime())?void 0:e}if(i===`all`)return;let e=pNi[i];return e?new Date(Date.now()-e):void 0},[i,a]),c=(0,W.useMemo)(()=>{if(i!==`custom`||!o)return;let e=new Date(o);return Number.isNaN(e.getTime())?void 0:e},[i,o]),l=(0,W.useRef)(i);l.current=i;let u=e.get(uNi),d=e.get(dNi),f=e.get(fNi),p=(0,W.useMemo)(()=>Jhi.find(t=>t.entityType===e.get(y7)),[e]),m=(0,W.useMemo)(()=>sgi(e),[e]),h=(0,W.useCallback)(e=>{t(t=>{let n=new URLSearchParams(t);for(let[t,r]of Object.entries(e)){let e=t===`logId`?uNi:t===`traceId`?dNi:fNi;r?n.set(e,r):n.delete(e)}return n},{replace:!0})},[t]),g=(0,W.useCallback)(e=>{t(t=>{let n=new URLSearchParams(t);return lgi(n,e),mNi(n),n},{replace:!0})},[t]),_=g,v=(0,W.useCallback)((e,n)=>{if(l.current!==`custom`)return;let r=n===`from`?x7:S7;t(t=>{let n=new URLSearchParams(t);return e?n.set(r,e.toISOString()):n.delete(r),mNi(n),n},{replace:!0})},[t]),y=(0,W.useCallback)(e=>{l.current=e,t(t=>{let n=new URLSearchParams(t);return e===`last-24h`?(n.delete(b7),n.delete(x7),n.delete(S7)):e===`custom`?n.set(b7,`custom`):(n.set(b7,e),n.delete(x7),n.delete(S7)),mNi(n),n},{replace:!0})},[t]),b=(0,W.useCallback)(()=>{t(e=>{let t=new URLSearchParams(e);t.delete(y7);for(let e of w7)t.delete(C7[e]);return t.delete(b7),t.delete(x7),t.delete(S7),mNi(t),t},{replace:!0}),r?.()},[t,r]);return(0,W.useMemo)(()=>({searchParams:e,setSearchParams:t,datePreset:i,selectedDateFrom:s,selectedDateTo:c,datePresetRef:l,featuredLogId:u,featuredTraceId:d,featuredSpanId:f,selectedEntityOption:p,filterTokens:m,handleFeaturedChange:h,handleFilterTokensChange:_,handleDateChange:v,handleDatePresetChange:y,handleRemoveAll:b,applyFilterTokens:g}),[e,t,i,s,c,l,u,d,f,p,m,h,_,v,y,b,g])}var gNi=20,_Ni=1e4,vNi={field:`timestamp`,direction:`DESC`};function yNi(e,t,n){if(e?.pagination?.hasMore)return n+1}function bNi(e){let t=new Set,n=[];for(let r of e.pages)for(let e of r.logs??[]){let r=e.logId??JSON.stringify(e);t.has(r)||(t.add(r),n.push(e))}return n}function xNi(e){return ZN(e.state.error,`logs`)||QN(e.state.error)?!1:_Ni}var SNi=({filters:e,orderBy:t=vNi,queryOptions:n}={})=>{let r=Y(),{inView:i,setRef:a}=UM(),{hasNextPage:o,isFetchingNextPage:s,fetchNextPage:c,data:l,isLoading:u,isError:d,error:f}=C_({queryKey:[`logs`,e,t],queryFn:({pageParam:n})=>r.listLogsVNext({pagination:{page:n,perPage:gNi},filters:e,orderBy:t}),initialPageParam:0,getNextPageParam:yNi,select:bNi,retry:!1,refetchInterval:xNi,...n});return(0,W.useEffect)(()=>{i&&o&&!s&&c()},[i,o,s,c]),{data:l,hasNextPage:o,isFetchingNextPage:s,fetchNextPage:c,isLoading:u,isError:d,error:f,setEndOfListElement:a}},CNi=[AR(`/logs`)];function wNi(){let[e,t]=Av(),n=hNi(e,t),{sort:r,onSortChange:i}=TI({searchParams:e,setSearchParams:t,allowedKeys:Zhi,defaultSort:Qhi}),a=(0,W.useMemo)(()=>({field:`timestamp`,direction:r?.direction===`asc`?`ASC`:`DESC`}),[r?.direction]),o=oNi(e,t),[s,c]=(0,W.useState)(),{data:l=[],isPending:u}=jni(),{data:d=[],isPending:f}=q8({entityType:n.selectedEntityOption?.entityType,rootOnly:!0}),{data:p=[],isPending:m}=J8(),{data:h=[],isPending:g}=kni(),_=(0,W.useMemo)(()=>ogi({availableTags:l,availableRootEntityNames:d,availableServiceNames:h,availableEnvironments:p,loading:{tags:u,entityNames:f,serviceNames:g,environments:m}}),[l,d,h,p,u,f,g,m]),{data:v=[],isLoading:y,error:b,isFetchingNextPage:x,hasNextPage:S,setEndOfListElement:C}=SNi({filters:(0,W.useMemo)(()=>ugi({rootEntityType:n.selectedEntityOption?.entityType,dateFrom:n.selectedDateFrom,dateTo:n.selectedDateTo,tokens:n.filterTokens}),[n.filterTokens,n.selectedDateFrom,n.selectedDateTo,n.selectedEntityOption]),orderBy:a}),{logIdMap:w,featuredLog:T,handleLogClick:E,handlePreviousLog:D,handleNextLog:O}=lNi(v,n.featuredLogId,n.handleFeaturedChange,n.featuredTraceId),{data:k,isLoading:A}=X8({traceId:n.featuredTraceId??null,queryOptions:{enabled:!!n.featuredTraceId}}),j=(0,W.useCallback)(()=>n.applyFilterTokens(dgi(_,n.filterTokens)),[_,n]),M=(0,W.useCallback)(()=>n.handleFeaturedChange({logId:null}),[n]),N=(0,W.useCallback)(e=>n.handleFeaturedChange({traceId:e,spanId:null}),[n]),P=(0,W.useCallback)((e,t)=>n.handleFeaturedChange({traceId:e,spanId:t}),[n]),F=(0,W.useCallback)(()=>n.handleFeaturedChange({traceId:null,spanId:null}),[n]),I=(0,W.useCallback)(e=>n.handleFeaturedChange({spanId:e??null}),[n]),L=(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(EP,{children:(0,G.jsxs)(EP.Start,{children:[(0,G.jsx)(kLt,{preset:n.datePreset,onPresetChange:n.handleDatePresetChange,dateFrom:n.selectedDateFrom,dateTo:n.selectedDateTo,onDateChange:n.handleDateChange,disabled:y,presets:[`last-24h`,`last-3d`,`last-7d`,`last-14d`,`last-30d`,`custom`]}),(0,G.jsx)(fMi,{fields:_,tokens:n.filterTokens,onTokensChange:n.handleFilterTokensChange,disabled:y,onStartTextFilter:c,size:`sm`})]})}),(0,G.jsx)(QMi,{isLoading:y,filterFields:_,filterTokens:n.filterTokens,onFilterTokensChange:n.handleFilterTokensChange,onClear:j,onRemoveAll:n.handleRemoveAll,onSave:o.handleSave,onRemoveSaved:o.hasSavedFilters?o.handleRemoveSaved:void 0,autoFocusFilterFieldId:s})]});if(b)return(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:CNi}),actionRow:L,children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`Logs`}),(0,G.jsx)(`div`,{className:`flex h-full items-center justify-center`,children:(0,G.jsx)(VMi,{error:b,resource:`logs`,errorTitle:`Failed to load logs`})})]});let R=!!n.selectedEntityOption||n.filterTokens.length>0;return v.length===0&&!y&&!R?(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:CNi}),actionRow:L,children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`Logs`}),(0,G.jsx)(rNi,{datePreset:n.datePreset,dateFrom:n.selectedDateFrom,dateTo:n.selectedDateTo})]}):(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:CNi}),actionRow:L,children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`Logs`}),(0,G.jsx)(ZMi,{logs:v,isLoading:y,isFetchingNextPage:x,hasNextPage:S,setEndOfListElement:C,logIdMap:w,featuredLogId:n.featuredLogId,onLogClick:E,timestampSort:r?.direction,onSortChange:i}),(0,G.jsx)(BMi,{log:T??void 0,onClose:M,onTraceClick:N,onSpanClick:P,onPrevious:D,onNext:O}),(0,G.jsx)(VTi,{depth:2,traceId:T?n.featuredTraceId??void 0:void 0,spans:k?.spans,isLoadingSpans:A,selectedSpanId:n.featuredSpanId??null,onSpanSelect:I,onClose:F})]})}function TNi(){let e=Y();return b_({queryKey:[`builtin-mcp-server`],queryFn:()=>e.getBuiltinMcpServer(),retry:!1})}var ENi=`<your-token>`;function DNi(e){return`'${e.replaceAll(`'`,`'\\''`)}'`}function ONi(e,{protectedServer:t}){let n=DNi(e),r=`Authorization: Bearer ${ENi}`,i=t?{headers:{Authorization:`Bearer ${ENi}`}}:{};return[{value:`claude-code`,label:`Claude Code`,lang:`bash`,code:`claude mcp add --transport http mastra ${n}${t?` --header "${r}"`:``}`},{value:`cursor`,label:`Cursor`,lang:`json`,code:JSON.stringify({mcpServers:{mastra:{url:e,...i}}},null,2)},{value:`vscode`,label:`VS Code`,lang:`json`,code:JSON.stringify({servers:{mastra:{type:`http`,url:e,...i}}},null,2)},{value:`inspector`,label:`MCP Inspector`,lang:`bash`,code:`npx @modelcontextprotocol/inspector --cli ${n} --transport http${t?` --header "${r}"`:``} --method tools/list`}]}var kNi=`https://mastra.ai/docs/server/mcp`;function ANi(){let{data:e,error:t}=TNi();return e?(0,G.jsx)(jNi,{descriptor:e}):!t||JN(t)||YN(t)||XN(t)?null:(0,G.jsx)(MNi,{children:(0,G.jsx)(mk,{variant:`destructive`,children:`Couldn't load the built-in MCP server. Try reloading the page.`})})}function jNi({descriptor:e}){return(0,G.jsx)(MNi,{status:(0,G.jsx)(NNi,{descriptor:e}),children:e.enabled?e.mcpPackageInstalled?(0,G.jsx)(LNi,{descriptor:e}):(0,G.jsx)(INi,{}):(0,G.jsx)(FNi,{descriptor:e})})}function MNi({status:e,children:t}){return(0,G.jsxs)(HL,{role:`region`,"aria-label":`Mastra (built-in) MCP server`,children:[(0,G.jsxs)(UL,{className:`flex-row flex-wrap items-center gap-3 space-y-0 border-b border-border`,children:[(0,G.jsx)(WL,{className:`shrink-0`,children:`Mastra (built-in)`}),e]}),(0,G.jsx)(KL,{className:`flex flex-col gap-4`,children:t})]})}function NNi({descriptor:e}){let{label:t,variant:n}=PNi(e);return(0,G.jsx)(YS,{variant:n,emphasis:`subtle`,indicator:`dot`,children:t})}function PNi(e){if(!e.enabled)return{label:`Disabled`,variant:`neutral`};if(!e.mcpPackageInstalled)return{label:`Not installed`,variant:`warning`};let{auth:t}=e;return t.type===`protected`?{label:`Protected by ${t.provider??`server auth`}`,variant:`success`}:t.devOnly?{label:`Open in dev only`,variant:`info`}:{label:`Open to anyone`,variant:`warning`}}function FNi({descriptor:e}){return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(T,{tone:`muted`,children:e.disabledReason===`config`?(0,G.jsxs)(G.Fragment,{children:[`The built-in MCP server is turned off because `,(0,G.jsx)(bI,{children:`server.mcp.enabled`}),` is`,` `,(0,G.jsx)(bI,{children:`false`}),`.`]}):(0,G.jsxs)(G.Fragment,{children:[`The built-in MCP server only runs under `,(0,G.jsx)(bI,{children:`mastra dev`}),` unless the server has auth. Configure `,(0,G.jsx)(bI,{children:`server.auth`}),`, or set `,(0,G.jsx)(bI,{children:`server.mcp.enabled`}),` to`,` `,(0,G.jsx)(bI,{children:`true`}),`.`]})}),(0,G.jsx)(zNi,{})]})}function INi(){return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(T,{tone:`muted`,children:[`The built-in MCP server is enabled, but it needs the `,(0,G.jsx)(bI,{children:`@mastra/mcp`}),` package. Install it and restart the server.`]}),(0,G.jsx)(MI,{code:`npm install @mastra/mcp`,lang:`bash`,copyTooltip:`Copy install command`}),(0,G.jsx)(zNi,{})]})}function LNi({descriptor:e}){let t=`${(Y().options.baseUrl||window.location.origin).replace(/\/$/,``)}${e.path}`,n=ONi(t,{protectedServer:e.auth.type===`protected`}),[r,i]=(0,W.useState)(n[0].value),a=n.find(e=>e.value===r)??n[0];return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,G.jsx)(T,{as:`span`,variant:`label`,tone:`muted`,children:`Endpoint`}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-lg bg-muted py-2 pr-2 pl-3`,children:[(0,G.jsx)(T,{as:`span`,font:`mono`,className:`min-w-0 break-all`,children:t}),(0,G.jsx)(dC,{tooltip:`Copy MCP endpoint URL`,content:t})]})]}),(0,G.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,G.jsx)(T,{as:`span`,variant:`label`,tone:`muted`,children:`Toolsets`}),(0,G.jsxs)(`ul`,{className:`flex flex-wrap gap-2`,"aria-label":`Toolsets`,children:[e.toolsets.map(e=>(0,G.jsx)(`li`,{children:(0,G.jsx)(YS,{variant:`neutral`,emphasis:`subtle`,children:RNi(e)})},e)),e.readOnly&&(0,G.jsx)(`li`,{children:(0,G.jsx)(YS,{variant:`info`,emphasis:`subtle`,children:`Read-only`})})]})]}),(0,G.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,G.jsx)(T,{as:`span`,variant:`label`,tone:`muted`,children:`Connect a client`}),(0,G.jsx)(MI,{code:a.code,lang:a.lang,options:n.map(({value:e,label:t})=>({value:e,label:t})),value:r,onValueChange:i,selector:`tabs`,copyTooltip:`Copy snippet`}),(0,G.jsx)(T,{variant:`body-sm`,tone:`muted`,children:`Tools are listed per caller, so connect a client to see the tools your token can use.`})]})]})}function RNi(e){let t=e.replaceAll(`_`,` `);return t.charAt(0).toUpperCase()+t.slice(1)}function zNi(){return(0,G.jsx)(`div`,{children:(0,G.jsx)(X,{variant:`ghost`,render:(0,G.jsx)(`a`,{href:kNi,target:`_blank`,rel:`noopener noreferrer`}),icon:(0,G.jsx)(nF,{}),children:`MCP server docs`})})}var BNi={name:e=>e.name||e.id};function VNi({server:e,rowProps:t}){let{paths:n,Link:r}=on(),i=Y().options.baseUrl,a=e.transports?.includes(`sse`)??!0?`sse`:`mcp`,o=i?`${i}/api/mcp/${e.id}/${a}`:``,{data:s}=Ptn({selectedServer:e}),c=Object.values(s||{}),l=c.length,u=c.filter(e=>e.toolType===`agent`).length,d=c.filter(e=>e.toolType===`workflow`).length,f=vN(e.name,50);return(0,G.jsxs)(Z.RowLink,{to:n.mcpServerLink(e.id),LinkComponent:r,...t,children:[(0,G.jsx)(Z.NameCell,{children:f}),(0,G.jsx)(Z.DescriptionCell,{children:o}),(0,G.jsx)(Z.TextCell,{className:`text-center`,children:u||``}),(0,G.jsx)(Z.TextCell,{className:`text-center`,children:l||``}),(0,G.jsx)(Z.TextCell,{className:`text-center`,children:d||``})]})}function HNi({mcpServers:e,isLoading:t,search:n=``,sort:r,onSortChange:i}){let a=(0,W.useMemo)(()=>{let t=n.toLowerCase();return P6(e.filter(e=>e.name?.toLowerCase().includes(t)||e.id?.toLowerCase().includes(t)),r,BNi)},[e,n,r]),{containerRef:o,getRowProps:s}=UP({count:a.length,global:!0});return t?(0,G.jsx)(QP,{columns:`auto 1fr auto auto auto`}):(0,G.jsxs)(Z,{columns:`auto 1fr auto auto auto`,scrollRef:o,children:[(0,G.jsxs)(Z.Top,{children:[i?(0,G.jsx)(Z.SortableTopCell,{sortKey:`name`,sort:r?.key===`name`?r.direction:void 0,onSortChange:i,children:`Name`}):(0,G.jsx)(Z.TopCell,{children:`Name`}),(0,G.jsx)(Z.TopCell,{children:`URL`}),(0,G.jsx)(Z.TopCellSmart,{long:`Agents`,short:(0,G.jsx)(WP,{}),tooltip:`Agent tools`,className:`text-center`}),(0,G.jsx)(Z.TopCellSmart,{long:`Tools`,short:(0,G.jsx)(ZP,{}),tooltip:`Tools`,className:`text-center`}),(0,G.jsx)(Z.TopCellSmart,{long:`Workflows`,short:(0,G.jsx)(KS,{}),tooltip:`Workflow tools`,className:`text-center`})]}),a.length===0&&n?(0,G.jsx)(Z.NoMatch,{message:`No MCP Servers match your search`}):null,a.map((e,t)=>(0,G.jsx)(VNi,{server:e,rowProps:s(t)},e.id))]})}var UNi=()=>(0,G.jsx)(Vx,{titleSlot:`No MCP Servers yet`,descriptionSlot:(0,G.jsxs)(G.Fragment,{children:[`MCP servers are not configured yet. `,(0,G.jsx)(`br`,{}),`More information in the documentation.`]}),actionSlot:(0,G.jsx)(X,{variant:`ghost`,render:(0,G.jsx)(`a`,{href:`https://mastra.ai/docs/tools-mcp/mcp-overview`,target:`_blank`,rel:`noopener noreferrer`}),icon:(0,G.jsx)(nF,{}),children:`MCP documentation`}),variant:`fill`}),g9=[AR(`/mcps`)],WNi=()=>{let{data:e=[],isLoading:t,error:n}=TR(),[r,i]=(0,W.useState)(``),[a,o]=(0,W.useState)();return n&&JN(n)?(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:g9}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`MCP Servers`}),(0,G.jsx)(vR,{variant:`fill`})]}):n&&YN(n)?(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:g9}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`MCP Servers`}),(0,G.jsx)(_R,{variant:`fill`,resource:`MCP servers`})]}):n?(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:g9}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`MCP Servers`}),(0,G.jsx)(Vx,{tone:`error`,variant:`fill`,titleSlot:`Failed to load MCP servers`,descriptionSlot:n.message})]}):e.length===0&&!t?(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:g9}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`MCP Servers`}),(0,G.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,G.jsx)(ANi,{}),(0,G.jsx)(UNi,{})]})]}):(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:g9}),actionRow:(0,G.jsx)(EP,{children:(0,G.jsx)(EP.Start,{children:(0,G.jsx)(`div`,{className:`max-w-120 flex-1`,children:(0,G.jsx)(CN,{...wN,onValueChange:i,label:`Search MCP servers`,placeholder:`Search by name`})})})}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`MCP Servers`}),(0,G.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,G.jsx)(ANi,{}),(0,G.jsx)(HNi,{mcpServers:e,isLoading:t,search:r,sort:a,onSortChange:(e,t)=>o({key:t,direction:e})})]})]})};function GNi(){let[e,t]=Av();return{eventName:e.get(`event`)??void 0,close:()=>t(e=>{let t=new URLSearchParams(e);return t.delete(`event`),t},{replace:!0})}}var KNi=e=>`?${new URLSearchParams({event:e}).toString()}`;function qNi(e,{enabled:t=!0}={}){let n=Y();return b_({queryKey:[`mcp-server-events`,e],queryFn:()=>n.getMcpServerEvents(e),enabled:t})}function JNi(e,t){let n=Y();return S_({mutationFn:r=>n.emitMcpServerEvent(e,t,r)})}function YNi(e){if(e instanceof Hf&&typeof e.body==`object`&&e.body!==null){let t=`error`in e.body?e.body.error:void 0;if(typeof t==`string`&&t)return t}return`The event request failed.`}var XNi={push:`blue`,poll:`neutral`,webhook:`purple`};function ZNi({delivery:e}){return(0,G.jsx)(`span`,{className:`flex flex-wrap items-center gap-1`,children:e.map(e=>(0,G.jsx)(YS,{size:`xs`,variant:XNi[e],emphasis:`subtle`,children:e},e))})}var QNi=0,$Ni=()=>`feed-${QNi++}`;function ePi(e,t){return[...t,...e].slice(0,200)}function tPi(e,t){switch(t.type){case`status`:return{...e,status:t.status,error:void 0,warning:void 0};case`cursor`:return t.cursor?{...e,cursor:t.cursor}:e;case`gap`:return{...e,items:ePi(e.items,[{kind:`gap`,key:$Ni()}])};case`occurrences`:{let n=[...t.occurrences].reverse().map(e=>({kind:`occurrence`,key:$Ni(),occurrence:e}));return{...e,items:ePi(e.items,n)}}case`warning`:return{...e,warning:t.message};case`error`:return{...e,status:`error`,error:t.message}}}var nPi={status:`idle`,items:[]};function rPi(e,t){let n=Y(),[r,i]=(0,W.useReducer)(tPi,nPi),a=(0,W.useRef)(void 0),o=(0,W.useRef)(void 0),s=e=>{e&&(o.current=e),i({type:`cursor`,cursor:e})};(0,W.useEffect)(()=>()=>a.current?.abort(),[]);let c=()=>{a.current?.abort(),a.current=void 0,i({type:`status`,status:`stopped`})},l=async r=>{a.current?.abort();let c=new AbortController;a.current=c,i({type:`status`,status:`connecting`});try{let a=n.streamMcpServerEvent(e,t,{arguments:r,cursor:o.current},{signal:c.signal});for await(let e of a){if(c.signal.aborted)return;if(e.type===`active`)i({type:`status`,status:`live`}),s(e.cursor),e.truncated&&i({type:`gap`});else if(e.type===`event`)i({type:`occurrences`,occurrences:[e.occurrence]}),s(e.occurrence.cursor);else if(e.type===`heartbeat`)s(e.cursor);else if(e.type===`error`)i({type:`warning`,message:e.message});else break}c.signal.aborted||i({type:`status`,status:`stopped`})}catch(e){if(c.signal.aborted)return;i({type:`error`,message:YNi(e)})}finally{a.current===c&&(a.current=void 0)}},u=async r=>{i({type:`status`,status:`polling`});try{let a=await n.pollMcpServerEvent(e,t,{arguments:r,cursor:o.current});a.truncated&&i({type:`gap`}),i({type:`occurrences`,occurrences:a.events}),s(a.cursor),i({type:`status`,status:`polled`})}catch(e){i({type:`error`,message:YNi(e)})}};return{...r,start:l,stop:c,pollOnce:u}}function _9(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function iPi(e){return e.map(e=>JSON.stringify(e)).join(` | `)}function aPi(e){return e.map(v9).join(` | `)}function v9(e){return _9(e)?Array.isArray(e.enum)?iPi(e.enum):`const`in e?JSON.stringify(e.const):Array.isArray(e.anyOf)?aPi(e.anyOf):Array.isArray(e.oneOf)?aPi(e.oneOf):Array.isArray(e.type)?e.type.join(` | `):e.type===`array`?`${v9(e.items)}[]`:cPi(e)?`Record<string, ${v9(e.additionalProperties)}>`:typeof e.type==`string`?e.type:`unknown`:`unknown`}function oPi(e,t,n,{defaultsAreOptional:r=!1}){let i=_9(t)?t:{},a=`default`in i;return{name:e,type:v9(i),required:n.has(e)&&!(r&&a),description:typeof i.description==`string`?i.description:void 0,defaultValue:a?JSON.stringify(i.default):void 0}}function sPi(e,t={}){if(!_9(e)||!_9(e.properties))return[];let n=new Set(Array.isArray(e.required)?e.required.filter(e=>typeof e==`string`):[]);return Object.entries(e.properties).map(([e,r])=>oPi(e,r,n,t))}function cPi(e){return _9(e)&&e.type===`object`&&!_9(e.properties)&&_9(e.additionalProperties)}function lPi(e){return _9(e)&&(e.type===`object`||_9(e.properties))}var uPi=[`type`,`properties`,`items`,`enum`,`const`,`anyOf`,`oneOf`,`allOf`,`$ref`];function dPi(e){return!_9(e)||!uPi.some(t=>t in e)}function y9(e){return _9(e)?MO(e):J({})}function fPi({inputSchema:e,onChange:t}){return dPi(e)?(0,G.jsx)(T,{tone:`muted`,children:`This event takes no arguments.`}):(0,G.jsx)(zM,{schema:y9(e),onValuesChange:e=>t(e??{})})}function pPi({occurrence:e}){return(0,G.jsx)(HL,{children:(0,G.jsxs)(SC,{children:[(0,G.jsxs)(CC,{className:`flex w-full cursor-pointer items-center gap-2 px-3 py-2 text-left`,children:[(0,G.jsx)(y,{direction:`right`,className:`size-4 shrink-0`}),(0,G.jsx)(T,{as:`span`,variant:`caption`,font:`mono`,className:`min-w-0 flex-1 truncate`,children:e.eventId}),e.eventId.startsWith(`mastra-test-`)&&(0,G.jsx)(YS,{size:`xs`,variant:`amber`,emphasis:`subtle`,children:`test`}),(0,G.jsx)(T,{as:`span`,variant:`caption`,font:`mono`,tone:`muted`,className:`shrink-0`,children:e.timestamp})]}),(0,G.jsx)(wC,{children:(0,G.jsx)(hw,{value:JSON.stringify(e.data,null,2),language:`json`,editable:!1,lineNumbers:!1,showCopyButton:!1,variant:`embedded`,"aria-label":`Event ${e.eventId} data`,className:`px-3 pb-3`})})]})})}var mPi=`Gap: events may have been skipped`;function hPi({items:e}){return e.length===0?(0,G.jsx)(Vx,{iconSlot:(0,G.jsx)(Wei,{}),titleSlot:`No events yet`,descriptionSlot:`Start listening or poll to see occurrences here.`}):(0,G.jsx)(`ol`,{"aria-label":`Occurrences`,className:`grid grid-cols-1 gap-2`,children:e.map(e=>(0,G.jsx)(`li`,{children:e.kind===`gap`?(0,G.jsx)(mk,{variant:`warning`,children:mPi}):(0,G.jsx)(pPi,{occurrence:e.occurrence})},e.key))})}var gPi={idle:`Not listening`,connecting:`Connecting…`,polling:`Polling…`,polled:`Polled`,stopped:`Stopped`,error:`Failed`};function _Pi({status:e,canStream:t}){if(e===`live`)return(0,G.jsx)(YS,{variant:`green`,indicator:`pulse`,size:`sm`,children:`Listening`});let n=e===`idle`&&!t?`Not polled yet`:gPi[e];return(0,G.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(e===`connecting`||e===`polling`)&&(0,G.jsx)(Mv,{size:`sm`}),(0,G.jsx)(T,{as:`span`,tone:`muted`,children:n})]})}function vPi({status:e,canStream:t,cursor:n}){return(0,G.jsxs)(`div`,{role:`status`,className:`flex min-w-0 flex-wrap items-center gap-3`,children:[(0,G.jsx)(_Pi,{status:e,canStream:t}),n&&(0,G.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1`,children:[(0,G.jsx)(T,{as:`span`,variant:`caption`,tone:`muted`,children:`Cursor`}),(0,G.jsx)(T,{as:`span`,variant:`caption`,font:`mono`,className:`min-w-0 truncate`,children:n}),(0,G.jsx)(dC,{tooltip:`Copy cursor`,content:n})]})]})}function yPi({serverId:e,event:t,onEmitted:n}){let{mutateAsync:r,isPending:i,isSuccess:a,error:o}=JNi(e,t.name);return(0,G.jsxs)(`section`,{"aria-label":`Send test event`,className:`grid grid-cols-1 gap-3`,children:[(0,G.jsx)(T,{as:`h3`,variant:`subheading`,children:`Send test event`}),(0,G.jsx)(zM,{schema:y9(t.payloadSchema),onSubmit:async e=>{try{await r(e??{}),n?.()}catch{}},isSubmitLoading:i,submitButtonLabel:`Send test event`}),a&&!o&&(0,G.jsx)(T,{tone:`muted`,children:`Test event sent.`}),o&&(0,G.jsx)(mk,{variant:`destructive`,children:YNi(o)})]})}function bPi({serverId:e,event:t,testEmit:n,canEmit:r}){let[i,a]=(0,W.useState)({}),o=rPi(e,t.name),s=t.delivery.includes(`push`),c=o.status===`connecting`||o.status===`live`;return(0,G.jsxs)(`div`,{className:`grid grid-cols-1 content-start gap-6`,children:[(0,G.jsx)(fPi,{inputSchema:t.inputSchema,onChange:a}),(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,G.jsx)(vPi,{status:o.status,canStream:s,cursor:o.cursor}),s&&c&&(0,G.jsx)(X,{onClick:o.stop,children:`Stop`}),s&&!c&&(0,G.jsx)(X,{variant:`primary`,onClick:()=>void o.start(i),children:`Start`}),!s&&(0,G.jsx)(X,{variant:`primary`,disabled:o.status===`polling`,onClick:()=>void o.pollOnce(i),children:`Poll once`})]}),o.error&&(0,G.jsx)(mk,{variant:`destructive`,children:o.error}),o.warning&&(0,G.jsx)(mk,{variant:`warning`,children:o.warning}),n&&t.emittable&&r&&(0,G.jsx)(yPi,{serverId:e,event:t,onEmitted:s?void 0:()=>void o.pollOnce(i)}),(0,G.jsx)(hPi,{items:o.items})]})}function xPi({description:e}){let t=YL({collapsedHeight:140});return(0,G.jsx)(JL,{state:t,expandLabel:`Read more`,children:(0,G.jsx)(BL,{children:e})})}function SPi({description:e,overview:t,playground:n,canRun:r}){return(0,G.jsx)(G.Fragment,{children:(0,G.jsxs)(ck,{defaultTab:`overview`,className:`grid flex-1 grid-rows-[auto_1fr] gap-4 overflow-visible`,children:[(0,G.jsxs)(sk,{variant:`pill`,size:`sm`,children:[(0,G.jsx)(lk,{value:`overview`,children:`Overview`}),(0,G.jsx)(lk,{value:`playground`,disabled:!r,disabledTooltip:`You don't have permission to execute tools.`,children:`Playground`})]}),(0,G.jsxs)(uk,{value:`overview`,flush:!0,className:`content-start gap-6`,children:[e&&(0,G.jsx)(HL,{className:`p-4`,children:(0,G.jsx)(xPi,{description:e})}),t]}),(0,G.jsx)(uk,{value:`playground`,flush:!0,keepMounted:!0,className:`h-full`,children:r&&n})]})})}function CPi(e){return(0,G.jsx)(jPt,{className:`min-h-control-md`,...e})}function wPi(){return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{"aria-hidden":!0,className:`ml-0.5 text-destructive-indicator`,children:`*`}),(0,G.jsx)(`span`,{className:`sr-only`,children:` (required)`})]})}function TPi({field:e}){return(0,G.jsxs)(G.Fragment,{children:[e.description,e.defaultValue!==void 0&&(0,G.jsxs)(`span`,{className:`block`,children:[`Default `,e.defaultValue]})]})}function EPi({field:e}){let t=!!e.description||e.defaultValue!==void 0;return(0,G.jsx)(GN,{title:(0,G.jsxs)(T,{as:`span`,variant:`body-sm`,font:`mono`,tone:`ink`,children:[e.name,e.required&&(0,G.jsx)(wPi,{})]}),description:t?(0,G.jsx)(`span`,{className:`whitespace-normal`,children:(0,G.jsx)(TPi,{field:e})}):void 0,children:(0,G.jsx)(T,{as:`span`,variant:`caption`,font:`mono`,tone:`muted`,children:e.type})})}function DPi({message:e}){return(0,G.jsx)(WN,{children:e})}function OPi({schema:e,emptyMessage:t,defaultsAreOptional:n}){if(dPi(e))return(0,G.jsx)(DPi,{message:t});if(!lPi(e)||cPi(e))return(0,G.jsx)(GN,{title:`Type`,children:(0,G.jsx)(T,{as:`span`,variant:`caption`,font:`mono`,tone:`muted`,children:v9(e)})});let r=sPi(e,{defaultsAreOptional:n});return r.length===0?(0,G.jsx)(DPi,{message:t}):r.map(e=>(0,G.jsx)(EPi,{field:e},e.name))}function b9({title:e,...t}){return(0,G.jsxs)(HN,{children:[(0,G.jsx)(CPi,{children:(0,G.jsx)(UN,{children:e})}),(0,G.jsx)(VN,{children:(0,G.jsx)(OPi,{...t})})]})}function kPi({serverId:e,eventName:t}){let{canExecute:n,canEdit:r}=aS(),{data:i,isLoading:a}=qNi(e),o=i?.events.find(e=>e.name===t);return a?(0,G.jsx)(MN.LoadingData,{}):!i||!o?(0,G.jsxs)(MN.NoData,{children:[`This server has no event "`,t,`".`]}):(0,G.jsx)(SPi,{description:o.description,overview:(0,G.jsxs)(`div`,{className:`grid grid-cols-1 gap-6`,children:[(0,G.jsx)(ZNi,{delivery:o.delivery}),(0,G.jsx)(b9,{title:`Arguments`,schema:o.inputSchema,emptyMessage:`This event takes no arguments.`,defaultsAreOptional:!0}),(0,G.jsx)(b9,{title:`Payload`,schema:o.payloadSchema,emptyMessage:`No payload schema defined.`})]}),canRun:n(`mcp`),playground:(0,G.jsx)(bPi,{serverId:e,event:o,testEmit:i.testEmit,canEmit:r(`mcp`)})})}function APi({serverId:e}){let{eventName:t,close:n}=GNi();return(0,G.jsxs)(MN,{open:t!==void 0,onClose:n,title:t??``,children:[(0,G.jsxs)(MN.Header,{children:[(0,G.jsxs)(MN.Heading,{children:[(0,G.jsx)(vx,{size:`sm`,className:`text-muted-foreground`,children:(0,G.jsx)(Wei,{})}),(0,G.jsx)(`span`,{className:`truncate`,children:t})]}),(0,G.jsx)(MN.HeaderActions,{children:(0,G.jsx)(MN.CloseButton,{icon:`x`,tooltip:`Close event`,onClick:n})})]}),(0,G.jsx)(MN.Content,{className:`flex flex-col gap-4 px-3`,children:t&&(0,G.jsx)(kPi,{serverId:e,eventName:t},t)})]})}var jPi=new Set([`completed`,`failed`,`cancelled`]),MPi={working:`working`,input_required:`input required`,completed:`completed`,failed:`failed`,cancelled:`cancelled`},NPi=e=>jPi.has(e.status),PPi=2e3,x9=e=>[`mcp-server-tasks`,e],FPi=e=>!!e?.some(e=>!NPi(e));function IPi(e,t={}){let n=Y();return C_({queryKey:[...x9(e),`list`,t],queryFn:({pageParam:r})=>n.getMcpServerTasks(e,{...t,cursor:r}),initialPageParam:void 0,getNextPageParam:e=>e.nextCursor,refetchInterval:e=>e.state.data?.pages.some(e=>FPi(e.tasks))?PPi:!1})}function LPi(e,{enabled:t=!0}={}){let n=Y();return b_({queryKey:[...x9(e),`surfaces`],queryFn:()=>n.getMcpServerTasks(e,{limit:1}),select:e=>e.surfaces,enabled:t})}function RPi(e,t){let n=Y();return b_({queryKey:[...x9(e),`task`,t],queryFn:async()=>(await n.getMcpServerTasks(e,{key:t,limit:1})).tasks[0]??null,enabled:t!==void 0,refetchInterval:e=>e.state.data&&!NPi(e.state.data)?PPi:!1})}function zPi(e){let t=Y();return S_({mutationFn:n=>t.findMcpServerTask(e,n)})}function BPi(e){let t=Y(),n=a_();return S_({mutationFn:n=>t.cancelMcpServerTask(e,n),onSettled:()=>n.invalidateQueries({queryKey:x9(e)})})}function VPi(e){let t=Y(),n=a_();return S_({mutationFn:({taskKey:n,inputResponses:r})=>t.answerMcpServerTaskInput(e,n,r),onSettled:()=>n.invalidateQueries({queryKey:x9(e)})})}function HPi(){let[e,t]=Av();return{taskKey:e.get(`task`)??void 0,open:e=>t(t=>{let n=new URLSearchParams(t);return n.set(`task`,e),n},{replace:!0}),close:()=>t(e=>{let t=new URLSearchParams(e);return t.delete(`task`),t},{replace:!0})}}var UPi=(e,t=``)=>{let n=new URLSearchParams(t);return n.set(`task`,e),`?${n.toString()}`},WPi=e=>`${e.slice(0,8)}…`,GPi=new Set([`working`,`input_required`,`completed`,`failed`,`cancelled`]);function KPi(){let[e,t]=Av(),n=e.get(`status`),r=e.get(`surface`),i=e.get(`client`);return{filters:{...n&&GPi.has(n)&&{status:n},...r&&{surface:r},...i&&{client:i}},setFilters:e=>t(t=>{let n=new URLSearchParams(t);for(let t of[`status`,`surface`,`client`]){let r=e[t];r?n.set(t,r):n.delete(t)}return n},{replace:!0})}}var qPi=e=>`${e.slice(0,8)}…`,JPi={working:{variant:`info`,indicator:`pulse`},input_required:{variant:`warning`,indicator:`dot`},completed:{variant:`success`},failed:{variant:`destructive`},cancelled:{variant:`neutral`}};function YPi({status:e}){let{variant:t,indicator:n}=JPi[e];return(0,G.jsx)(YS,{size:`sm`,variant:t,emphasis:`subtle`,indicator:n,children:MPi[e]})}function XPi({serverId:e}){let{taskKey:t,close:n}=HPi(),{data:r,isSuccess:i}=RPi(e,t);return(0,G.jsxs)(MN,{open:t!==void 0,onClose:n,title:r?.surface??`Task`,children:[(0,G.jsxs)(MN.Header,{children:[(0,G.jsxs)(MN.Heading,{children:[(0,G.jsx)(vx,{size:`sm`,className:`text-muted-foreground`,children:(0,G.jsx)(yYr,{})}),(0,G.jsx)(`span`,{className:`truncate`,children:r?`${r.surface} task`:`Task`})]}),(0,G.jsx)(MN.HeaderActions,{children:(0,G.jsx)(MN.CloseButton,{icon:`x`,tooltip:`Close task`,onClick:n})})]}),(0,G.jsx)(MN.Content,{className:`flex flex-col gap-4 px-3`,children:r?(0,G.jsx)(ZPi,{serverId:e,task:r},r.taskKey):i&&(0,G.jsx)(T,{tone:`muted`,children:`This task is no longer listed.`})})]})}function ZPi({serverId:e,task:t}){let n=BPi(e),{canEdit:r,isLoading:i}=aS(),a=!i&&r(`mcp`),o=Object.entries(t.inputRequests??{});return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(U6,{children:[(0,G.jsx)(U6.Key,{children:`Status`}),(0,G.jsx)(U6.Value,{children:(0,G.jsx)(YPi,{status:t.status})}),t.statusMessage&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(U6.Key,{children:`Message`}),(0,G.jsx)(U6.Value,{children:t.statusMessage})]}),(0,G.jsx)(U6.Key,{children:`Created`}),(0,G.jsx)(U6.Value,{children:(0,G.jsx)(yk,{value:t.createdAt})}),(0,G.jsx)(U6.Key,{children:`Updated`}),(0,G.jsx)(U6.Value,{children:(0,G.jsx)(yk,{value:t.lastUpdatedAt})}),(0,G.jsx)(U6.Key,{children:`Expires`}),(0,G.jsx)(U6.Value,{children:t.expiresAt?(0,G.jsx)(yk,{value:t.expiresAt}):`never`}),(0,G.jsx)(U6.Key,{children:`Task key`}),(0,G.jsx)(U6.ValueWithCopyBtn,{copyValue:t.taskKey,copyTooltip:`Copy task key`,children:WPi(t.taskKey)}),t.clientLabel&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(U6.Key,{children:`Client`}),(0,G.jsx)(U6.ValueWithCopyBtn,{copyValue:t.clientLabel,copyTooltip:`Copy client`,children:t.clientLabel})]}),(0,G.jsx)(U6.Key,{children:`Client key`}),(0,G.jsx)(U6.ValueWithCopyBtn,{copyValue:t.principalKey,copyTooltip:`Copy client key`,children:WPi(t.principalKey)})]}),(0,G.jsx)(T,{tone:`muted`,variant:`caption`,children:`Keys are hashes: the task id and the client's credentials stay with the client that started the task.`}),o.map(([n,r])=>(0,G.jsx)($Pi,{serverId:e,taskKey:t.taskKey,inputKey:n,request:r,canAnswer:a},n)),!NPi(t)&&!i&&!a&&(0,G.jsx)(T,{tone:`muted`,variant:`caption`,children:`Cancelling or answering a task needs the mcp:write permission.`}),!NPi(t)&&a&&(0,G.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,G.jsx)(X,{variant:`destructive-ghost`,className:`self-start`,loading:n.isPending,onClick:()=>n.mutate(t.taskKey),children:`Cancel task`}),n.error&&(0,G.jsx)(mk,{variant:`destructive`,children:tFi(n.error)})]}),t.result&&(0,G.jsx)(eFi,{label:`Result`,value:t.result}),t.error&&(0,G.jsx)(eFi,{label:`Error`,value:t.error})]})}var QPi=J({message:K().optional(),requestedSchema:Dd(K(),pd())});function $Pi({serverId:e,taskKey:t,inputKey:n,request:r,canAnswer:i}){let a=VPi(e),o=r.method===`elicitation/create`?QPi.safeParse(r.params):void 0,s=e=>a.mutate({taskKey:t,inputResponses:{[n]:e}});return(0,G.jsxs)(`section`,{"aria-label":`Input request ${n}`,className:`flex flex-col gap-3`,children:[(0,G.jsx)(T,{as:`h3`,variant:`subheading`,children:`Input requested`}),o?.success&&!i?(0,G.jsxs)(G.Fragment,{children:[o.data.message&&(0,G.jsx)(T,{children:o.data.message}),(0,G.jsx)(eFi,{label:`Request`,value:r})]}):o?.success?(0,G.jsxs)(G.Fragment,{children:[o.data.message&&(0,G.jsx)(T,{children:o.data.message}),(0,G.jsx)(zM,{schema:y9(o.data.requestedSchema),onSubmit:e=>s({action:`accept`,content:e??{}}),isSubmitLoading:a.isPending,submitButtonLabel:`Accept`,submitButtonVariant:`primary`,submitActions:(0,G.jsx)(X,{type:`button`,disabled:a.isPending,onClick:()=>s({action:`decline`}),children:`Decline`})})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(T,{tone:`muted`,children:[`Studio can't answer a `,r.method,` request; the client that started the task has to.`]}),(0,G.jsx)(eFi,{label:`Request`,value:r})]}),a.error&&(0,G.jsx)(mk,{variant:`destructive`,children:tFi(a.error)})]})}function eFi({label:e,value:t}){return(0,G.jsxs)(`section`,{className:`flex flex-col gap-2`,children:[(0,G.jsx)(T,{as:`h3`,variant:`subheading`,children:e}),(0,G.jsx)(hw,{value:JSON.stringify(t,null,2),language:`json`,editable:!1,lineNumbers:!1,"aria-label":`Task ${e.toLowerCase()}`})]})}function tFi(e){let t=YNi(e);return t===`Task not found`?`The task is no longer waiting for this; the list has been refreshed.`:t}function nFi(e){if(!_9(e))return;if(_9(e.ui)&&typeof e.ui.resourceUri==`string`)return e.ui.resourceUri;let t=e[`ui/resourceUri`];return typeof t==`string`?t:void 0}function rFi(e){return _9(e)&&e.status===`suspended`}function iFi(e){return e<1e3?`${Math.round(e)} ms`:`${(e/1e3).toFixed(2)} s`}function aFi(e){return e===void 0?`undefined`:JSON.stringify(e,null,2)}function oFi(e){return e.status===`error`?e.error:aFi(e.output)}function sFi({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:cFi(n),durationMs:r}}}function cFi(e){return e instanceof Error?JSON.stringify({error:e.message},null,2):JSON.stringify({error:String(e)},null,2)}function lFi({zodInputSchema:e,isRunning:t,onRun:n,requestContextEntityType:r,requestContextEntityId:i}){let a=!qEt(e),[o,s]=(0,W.useState)({view:`form`,value:void 0}),c=(0,W.useRef)(void 0),[l,u]=(0,W.useState)([]);function d(t){if(t===o.view)return;if(u([]),o.view===`form`)return s({view:`json`,value:JSON.stringify(c.current??{},null,2)});let n=cDt(o.value);if(!n.ok)return u([n.error]);let r=lDt(e,n.value);if(r)return u([r]);c.current=n.value,s({view:`form`,value:n.value})}function f(t){let r=uDt(e,t);r.ok?n(r.value):u(r.errors)}let p={isSubmitLoading:t,submitButtonLabel:`Run`,submitButtonIcon:(0,G.jsx)(jD,{}),submitButtonVariant:`primary`};return(0,G.jsxs)(HN,{children:[(0,G.jsx)(CPi,{action:(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(Cnn,{entityType:r,entityId:i}),(0,G.jsx)(ck,{defaultTab:`form`,value:o.view,onValueChange:d,children:(0,G.jsxs)(sk,{size:`md`,children:[(0,G.jsxs)(lk,{value:`form`,disabled:t,children:[(0,G.jsx)(vx,{size:`sm`,children:(0,G.jsx)(C_t,{})}),`Form`]}),(0,G.jsxs)(lk,{value:`json`,disabled:t,children:[(0,G.jsx)(vx,{size:`sm`,children:(0,G.jsx)(US,{})}),`JSON`]})]})})]}),children:(0,G.jsx)(UN,{children:`Request`})}),(0,G.jsx)(VN,{children:(0,G.jsx)(`div`,{className:`p-4`,children:o.view===`json`?(0,G.jsxs)(`div`,{className:`grid gap-4`,children:[(0,G.jsxs)(ZO,{invalid:l.length>0,children:[(0,G.jsx)(hw,{variant:`embedded`,language:`json`,value:o.value,onChange:e=>{s({view:`json`,value:e}),u([])},editable:!t,"aria-label":`Request JSON`}),l.length>0&&(0,G.jsx)(tk,{children:l.map(e=>(0,G.jsx)(`span`,{className:`block`,children:e},e))})]}),(0,G.jsx)(xk,{...p,onSubmit:()=>f(o.value)})]}):(0,G.jsx)(zM,{...p,schema:e,defaultValues:o.value,onValuesChange:e=>{c.current=e},onSubmit:n,className:`gap-0`,children:!a&&(0,G.jsx)(T,{variant:`body-sm`,tone:`muted`,className:`pb-4`,children:`This tool takes no input. Run it as is.`})})})})]})}var uFi=H(`IconSend`,()=>(0,G.jsx)(`path`,{d:`M13.1282 21.1524C13.3813 22.1224 14.7454 22.1581 15.0489 21.2027L20.1669 5.09042C20.4124 4.31745 19.6841 3.58908 18.9111 3.83461L2.79884 8.95262C1.84336 9.25613 1.8791 10.6203 2.84916 10.8733L10.4343 12.852C10.7846 12.9434 11.0581 13.217 11.1495 13.5672L13.1282 21.1524Z`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`}));function dFi({isRunning:e,lastRun:t}){return e?(0,G.jsx)(Vx,{iconSlot:(0,G.jsx)(Mv,{}),titleSlot:`Running…`,descriptionSlot:`Waiting for the tool to respond.`}):t?t.status===`error`?(0,G.jsx)(aC,{code:oFi(t),className:`overflow-x-auto p-4 text-caption whitespace-pre`}):(0,G.jsx)(hw,{value:oFi(t),language:`json`,editable:!1,lineNumbers:!1,showCopyButton:!1,variant:`embedded`,"aria-label":`Tool response`,className:`p-4`}):(0,G.jsx)(Vx,{iconSlot:(0,G.jsx)(uFi,{}),titleSlot:`No response yet`,descriptionSlot:`Run the tool to see its output here.`})}function fFi({run:e}){return(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.status===`success`?(0,G.jsx)(YS,{variant:`success`,emphasis:`subtle`,indicator:`dot`,children:`Success`}):(0,G.jsx)(YS,{variant:`destructive`,emphasis:`subtle`,indicator:`dot`,children:`Error`}),(0,G.jsx)(T,{as:`span`,variant:`caption`,font:`mono`,tone:`muted`,children:iFi(e.durationMs)}),(0,G.jsx)(dC,{content:oFi(e),copyMessage:`Response copied`,tooltip:`Copy response`,size:`icon-sm`})]})}function pFi({isRunning:e,lastRun:t}){return(0,G.jsxs)(HN,{className:`h-full`,children:[(0,G.jsx)(CPi,{action:!e&&t&&(0,G.jsx)(fFi,{run:t}),children:(0,G.jsx)(UN,{children:`Response`})}),(0,G.jsx)(VN,{className:c(`grid min-h-48 flex-1`,e||!t?`content-center`:`content-start`),children:(0,G.jsx)(dFi,{isRunning:e,lastRun:t})})]})}function mFi({zodInputSchema:e,execution:t,requestContextEntityType:n,requestContextEntityId:r}){let[i]=LS(n,r),[a,o]=(0,W.useState)(),s=async e=>{let n=performance.now();await t.execute(e,i).catch(()=>void 0),o(performance.now()-n)},c=t.status===`pending`;return(0,G.jsxs)(`div`,{className:`grid h-full grid-rows-[auto_1fr] gap-6`,children:[(0,G.jsx)(lFi,{zodInputSchema:e,isRunning:c,onRun:s,requestContextEntityType:n,requestContextEntityId:r}),(0,G.jsx)(pFi,{isRunning:c,lastRun:sFi(t,a)})]})}function hFi({serverId:e,tool:t}){let n=M_r(e),{mutateAsync:r,status:i,data:a,error:o}=Ntn({serverId:e,toolId:t.name}),{data:s}=Atn({serverId:e,appResourceUri:nFi(t._meta)}),c=y9(t.inputSchema),l={execute:(e,t)=>r({data:e,requestContext:t}),status:i,output:a,error:o};return(0,G.jsxs)(`div`,{className:`grid content-start gap-6`,children:[s&&(0,G.jsx)(FLr,{html:s,toolName:t.name,onToolCall:n}),rFi(a)&&(0,G.jsxs)(mk,{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 `,(0,G.jsx)(bI,{children:`inputRequests`}),` handler to finish the request.`]}),(0,G.jsx)(mFi,{zodInputSchema:c,execution:l,requestContextEntityType:`mcp-tool`,requestContextEntityId:`${e}:${t.name}`})]})}var gFi=(0,W.createContext)(void 0),_Fi=gFi.Provider;function vFi(){let e=(0,W.useContext)(gFi);if(e===void 0)throw Error(`useOpenToolId must be used inside ToolDrawer`);return e}function yFi({inputSchema:e,outputSchema:t,requestContextSchema:n,footer:r}){return(0,G.jsxs)(`div`,{className:`grid gap-6`,children:[(0,G.jsx)(b9,{title:`Input`,schema:e,emptyMessage:`This tool takes no input.`,defaultsAreOptional:!0}),(0,G.jsx)(b9,{title:`Output`,schema:t,emptyMessage:`No output schema defined.`}),n!==void 0&&(0,G.jsx)(b9,{title:`Request context`,schema:n,emptyMessage:`No request context fields.`,defaultsAreOptional:!0}),r]})}function bFi({serverId:e}){let t=vFi(),{canExecute:n}=aS(),{data:r,isLoading:i}=Mtn({serverId:e,toolId:t});return i?(0,G.jsx)(MN.LoadingData,{}):r?(0,G.jsx)(SPi,{description:r.description,overview:(0,G.jsx)(yFi,{inputSchema:r.inputSchema}),canRun:n(`tools`),playground:(0,G.jsx)(hFi,{serverId:e,tool:r})}):(0,G.jsxs)(MN.NoData,{children:[`This server has no tool "`,t,`".`]})}var xFi=`auto 1fr auto`;function SFi({server:e}){let{data:t,isLoading:n,isError:r}=qNi(e.id),i=t?.events??[],{Link:a}=on(),{containerRef:o,getRowProps:s}=UP({count:i.length});return(0,G.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,G.jsx)(T,{as:`h2`,variant:`heading`,children:`Events`}),n&&(0,G.jsx)(QP,{columns:xFi}),r&&(0,G.jsx)(mk,{variant:`destructive`,children:`Could not load this server's events.`}),t&&(0,G.jsxs)(Z,{columns:xFi,scrollRef:o,children:[(0,G.jsxs)(Z.Top,{children:[(0,G.jsx)(Z.TopCell,{children:`Name`}),(0,G.jsx)(Z.TopCell,{children:`Description`}),(0,G.jsx)(Z.TopCell,{children:`Delivery`})]}),i.length===0&&(0,G.jsx)(Z.NoMatch,{message:`This server declares no events`}),i.map((t,n)=>(0,G.jsxs)(Z.RowLink,{to:`/mcps/${e.id}${KNi(t.name)}`,LinkComponent:a,...s(n),children:[(0,G.jsx)(Z.NameCell,{children:t.name}),(0,G.jsx)(Z.DescriptionCell,{children:t.description}),(0,G.jsx)(Z.TextCell,{children:(0,G.jsx)(ZNi,{delivery:t.delivery})})]},t.name))]})]})}var CFi=`minmax(0,1fr) auto auto auto auto auto auto auto`,wFi={not_listable:`This server's task store can't be listed.`,resource_scoped:`The task list needs a Studio session that is not scoped to a resource.`},TFi=[{id:`is`,label:`is`}],EFi=Object.entries(MPi).map(([e,t])=>({value:e,label:t})),DFi=e=>e.stopPropagation(),OFi=e=>e.clientLabel??qPi(e.principalKey),kFi=e=>[`status`,`surface`,`client`].flatMap(t=>{let n=e[t];return n?[{id:t,fieldId:t,operatorId:`is`,value:n}]:[]}),AFi=e=>{let t=t=>{let n=e.find(e=>e.fieldId===t)?.value;return typeof n==`string`&&n?n:void 0};return{status:t(`status`),surface:t(`surface`),client:t(`client`)}};function jFi({server:e}){let{filters:t,setFilters:n}=KPi(),{data:r,isLoading:i,isError:a,hasNextPage:o,fetchNextPage:s,isFetchingNextPage:c}=IPi(e.id,t),{data:l=[]}=LPi(e.id),u=(0,W.useMemo)(()=>r?.pages.flatMap(e=>e.tasks)??[],[r]),d=r?.pages[0]?.unavailable,{containerRef:f,getRowProps:p}=UP({count:u.length}),m=kFi(t).length>0,h=(0,W.useMemo)(()=>{let e=new Map(u.map(e=>[e.principalKey,OFi(e)]));return t.client&&!e.has(t.client)&&e.set(t.client,qPi(t.client)),[...e]},[u,t.client]),g=(0,W.useMemo)(()=>[{id:`status`,label:`Status`,icon:xI,color:tP(`orange`),operators:[`is`],strict:!0,suggestions:EFi},{id:`surface`,label:`Surface`,icon:WS,color:tP(`blue`),operators:[`is`],strict:!0,suggestions:l.map(e=>({value:e.name}))},{id:`client`,label:`Client`,icon:Cni,color:tP(`purple`),operators:[`is`],suggestions:h.map(([e,t])=>({value:e,label:t}))}],[l,h]);return(0,G.jsxs)(`section`,{"aria-label":`Tasks`,className:`flex flex-col gap-3`,children:[(0,G.jsx)(T,{as:`h2`,variant:`heading`,children:`Tasks`}),a&&(0,G.jsx)(mk,{variant:`destructive`,children:`Could not load this server's tasks.`}),d&&(0,G.jsx)(mk,{variant:`info`,children:wFi[d]}),!d&&(0,G.jsxs)(EP,{children:[(0,G.jsx)(EP.Start,{children:(0,G.jsxs)(SP,{fields:g,operators:TFi,value:kFi(t),onValueChange:e=>n(AFi(e)),createItemId:e=>e,"aria-label":`Task filters`,className:`min-w-64 flex-1`,children:[(0,G.jsx)(SP.Chips,{}),(0,G.jsx)(SP.Input,{placeholder:`Filter tasks`})]})}),(0,G.jsx)(EP.End,{children:(0,G.jsx)(NFi,{serverId:e.id})})]}),i&&(0,G.jsx)(QP,{columns:CFi}),r&&!d&&(0,G.jsxs)(Z,{columns:CFi,scrollRef:f,children:[(0,G.jsxs)(Z.Top,{children:[(0,G.jsx)(Z.TopCell,{children:`Surface`}),(0,G.jsx)(Z.TopCell,{children:`Status`}),(0,G.jsx)(Z.TopCell,{children:`Created`}),(0,G.jsx)(Z.TopCell,{children:`Updated`}),(0,G.jsx)(Z.TopCell,{children:`Expires`}),(0,G.jsx)(Z.TopCell,{children:`Inputs`}),(0,G.jsx)(Z.TopCell,{children:`Key`}),(0,G.jsx)(Z.TopCell,{children:`Client`})]}),u.length===0&&(0,G.jsx)(Z.NoMatch,{message:m?`No tasks match these filters`:`No tasks yet`}),u.map((r,i)=>(0,G.jsx)(MFi,{serverId:e.id,task:r,rowProps:p(i),onFilterClient:()=>n({...t,client:r.principalKey})},r.taskKey))]}),o&&(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(X,{variant:`default`,size:`sm`,onClick:()=>s(),loading:c,children:`Load more`}),(0,G.jsxs)(T,{variant:`caption`,tone:`muted`,children:[`Showing the `,u.length,` most recent `,m?`matching `:``,`tasks.`]})]})]})}function MFi({serverId:e,task:t,rowProps:n,onFilterClient:r}){let{Link:i}=on(),[a]=Av(),o=(0,W.useRef)(null);return(0,G.jsxs)(Z.RowWrapper,{...n,onSelectRow:()=>o.current?.click(),children:[(0,G.jsxs)(Z.RowLink,{ref:o,colEnd:-2,to:`/mcps/${e}${UPi(t.taskKey,a)}`,LinkComponent:i,tabIndex:-1,onClick:DFi,"aria-label":`${t.surface} task ${WPi(t.taskKey)}`,children:[(0,G.jsx)(Z.NameCell,{children:t.surface}),(0,G.jsx)(Z.Cell,{children:(0,G.jsx)(YPi,{status:t.status})}),(0,G.jsx)(Z.CreatedCell,{timestamp:t.createdAt,preset:`day-time-seconds`}),(0,G.jsx)(Z.Cell,{className:`text-muted-foreground`,children:(0,G.jsx)(yk,{value:t.lastUpdatedAt})}),(0,G.jsx)(Z.Cell,{className:`text-muted-foreground`,children:t.expiresAt?(0,G.jsx)(yk,{value:t.expiresAt}):`never`}),(0,G.jsx)(Z.TextCell,{children:Object.keys(t.inputRequests??{}).length||`—`}),(0,G.jsx)(Z.TextCell,{font:`mono`,className:`text-muted-foreground`,children:WPi(t.taskKey)})]}),(0,G.jsx)(Z.Cell,{className:`pr-2`,children:(0,G.jsx)(X,{type:`button`,variant:`ghost`,size:`sm`,className:`w-full justify-start font-mono`,tooltip:`Show only this client's tasks`,"aria-label":`Show only tasks from client ${OFi(t)}`,onClick:e=>{e.stopPropagation(),r()},children:OFi(t)})})]})}function NFi({serverId:e}){let[t,n]=(0,W.useState)(``),r=zPi(e),{open:i}=HPi();return(0,G.jsxs)(`form`,{onSubmit:e=>{e.preventDefault();let a=t.trim();a&&r.mutate(a,{onSuccess:({task:e})=>{n(``),i(e.taskKey)}})},className:`flex items-center gap-2`,"aria-label":`Find a task by MCP task id`,children:[(0,G.jsx)(Bj,{size:`sm`,value:t,onChange:e=>{n(e.target.value),r.reset()},placeholder:`MCP task id`,"aria-label":`MCP task id`,"aria-invalid":r.isError||void 0,className:`w-56 font-mono`}),(0,G.jsx)(X,{type:`submit`,size:`sm`,variant:`default`,disabled:!t.trim(),loading:r.isPending,children:`Find`}),r.isError&&(0,G.jsx)(T,{variant:`caption`,role:`status`,className:`text-destructive-foreground`,children:`No task with that id.`})]})}var PFi={agent:WP,workflow:KS,tool:ZP},FFi=`auto minmax(0, 1fr) auto`,IFi=`auto minmax(0, 1fr) auto auto`,LFi={tool:`Tool`,agent:`Agent`,workflow:`Workflow`};function RFi(e){return e in PFi}function zFi({type:e}){let t=RFi(e)?e:`tool`,n=PFi[t],r=LFi[t];return(0,G.jsxs)(mx,{children:[(0,G.jsx)(hx,{asChild:!0,children:(0,G.jsx)(`span`,{"aria-label":t,className:`inline-flex text-muted-foreground [&>svg]:size-icon-md`,children:(0,G.jsx)(n,{})})}),(0,G.jsx)(gx,{children:r})]})}var BFi=J({ui:J({resourceUri:K().optional()}).optional(),"ui/resourceUri":K().optional()});function VFi(e){let t=BFi.safeParse(e);return t.success?!!(t.data.ui?.resourceUri?.startsWith(`ui://`)||t.data[`ui/resourceUri`]?.startsWith(`ui://`)):!1}function HFi({surface:e}){return e?(0,G.jsxs)(mx,{children:[(0,G.jsx)(hx,{asChild:!0,children:(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,G.jsx)(YS,{size:`xs`,variant:e.mode===`always`?`info`:`neutral`,emphasis:`subtle`,children:e.mode}),e.required&&(0,G.jsx)(YS,{size:`xs`,variant:`warning`,emphasis:`subtle`,children:`required`}),e.recover&&(0,G.jsx)(YS,{size:`xs`,variant:`neutral`,emphasis:`subtle`,children:`recover`})]})}),(0,G.jsxs)(gx,{children:[e.mode===`always`?`Always runs as a task`:`Runs as a task when the client asks for one`,e.required?`; clients without task support are refused`:``,e.recover?`; resumed after a server restart`:``]})]}):null}function UFi({server:e}){let[t,n]=(0,W.useState)(``),{data:r={},isLoading:i}=Ptn({selectedServer:e}),{Link:a,paths:o}=on(),{data:s}=LPi(e.id,{enabled:!!e.tasks_capability}),c=(0,W.useMemo)(()=>new Map(s?.map(e=>[e.name,e])),[s]),l=!!e.tasks_capability,u=l?IFi:FFi,d=(0,W.useMemo)(()=>{let e=t.toLowerCase();return Object.values(r).filter(t=>t.name.toLowerCase().includes(e)||t.description?.toLowerCase().includes(e))},[r,t]),{containerRef:f,getRowProps:p}=UP({count:d.length});return(0,G.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,G.jsx)(T,{as:`h2`,variant:`heading`,children:`Available tools`}),(0,G.jsx)(`div`,{className:`max-w-120 flex-1`,children:(0,G.jsx)(CN,{size:`sm`,debounceMs:300,className:`max-w-120`,onValueChange:n,label:`Search tools`,placeholder:`Search by name`})})]}),i?(0,G.jsx)(QP,{columns:u}):(0,G.jsxs)(Z,{columns:u,fit:`container`,scrollRef:f,children:[(0,G.jsxs)(Z.Top,{children:[(0,G.jsx)(Z.TopCell,{children:`Name`}),(0,G.jsx)(Z.TopCell,{children:`Description`}),(0,G.jsx)(Z.TopCell,{className:`justify-center text-center`,children:`Type`}),l&&(0,G.jsx)(Z.TopCell,{children:`Task`})]}),d.length===0&&t?(0,G.jsx)(Z.NoMatch,{message:`No tools match your search`}):null,d.map((t,n)=>(0,G.jsxs)(Z.RowLink,{to:o.mcpServerToolLink(e.id,t.name),LinkComponent:a,...p(n),children:[(0,G.jsx)(Z.NameCell,{children:(0,G.jsxs)(`span`,{className:`flex items-center gap-2`,children:[t.name,VFi(t._meta)&&(0,G.jsx)(YS,{size:`xs`,children:`App`})]})}),(0,G.jsx)(Z.DescriptionCell,{children:t.description}),(0,G.jsx)(Z.TextCell,{className:`justify-center text-center`,children:(0,G.jsx)(zFi,{type:t.toolType??`tool`})}),l&&(0,G.jsx)(Z.Cell,{children:(0,G.jsx)(HFi,{surface:c.get(t.name)})})]},t.name))]})]})}var WFi=({isLoading:e,server:t})=>{let[{sseUrl:n,httpStreamUrl:r},i]=(0,W.useState)({sseUrl:``,httpStreamUrl:``});if((0,W.useEffect)(()=>{if(!t)return;let e=window.MASTRA_SERVER_HOST,n=window.MASTRA_SERVER_PORT,r=null;e&&n&&(r=`http://${e}:${n}`);let a=r||`http://localhost:4111`,o=`${a}/api/mcp/${t.id}/sse`,s=`${a}/api/mcp/${t.id}/mcp`;i({sseUrl:o,httpStreamUrl:s})},[t]),e)return null;if(!t)return(0,G.jsx)(T,{as:`h1`,variant:`heading`,tone:`muted`,className:`py-20 text-center`,children:`Server not found`});let a=t.transports?.includes(`sse`)??!0,o=`npx -y mcp-remote ${a?n:r}`,s=[{value:`http`,label:`HTTP`,description:`Use for stateless HTTP transport with streamable responses.`,content:r,tooltip:`Copy HTTP Stream URL`},...a?[{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(0,G.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,G.jsx)(HL,{children:(0,G.jsxs)(ck,{defaultTab:`http`,children:[(0,G.jsxs)(UL,{className:`flex-row items-center justify-between gap-3 space-y-0 border-b border-border`,children:[(0,G.jsx)(WL,{className:`shrink-0`,children:`Connect`}),(0,G.jsx)(`div`,{className:`min-w-0`,children:(0,G.jsx)(sk,{variant:`pill-ghost`,size:`sm`,children:s.map(e=>(0,G.jsx)(lk,{value:e.value,children:e.label},e.value))})})]}),s.map(e=>(0,G.jsx)(uk,{value:e.value,flush:!0,children:(0,G.jsxs)(KL,{className:`flex flex-col gap-3`,children:[(0,G.jsx)(T,{tone:`muted`,children:e.description}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-lg bg-muted py-2 pr-2 pl-3`,children:[(0,G.jsx)(T,{as:`span`,font:`mono`,className:`min-w-0 break-all`,children:e.content}),(0,G.jsx)(dC,{tooltip:e.tooltip,content:e.content})]})]})},e.value))]})}),(0,G.jsx)(UFi,{server:t}),t.tasks_capability&&(0,G.jsx)(jFi,{server:t}),t.events_capability&&(0,G.jsx)(SFi,{server:t})]})};function GFi(){let[e,t]=Av();return{toolId:e.get(`tool`)??void 0,close:()=>t(e=>{let t=new URLSearchParams(e);return t.delete(`tool`),t},{replace:!0})}}function KFi({children:e}){let{toolId:t,close:n}=GFi();return(0,G.jsxs)(MN,{open:t!==void 0,onClose:n,title:t??``,children:[(0,G.jsxs)(MN.Header,{children:[(0,G.jsxs)(MN.Heading,{children:[(0,G.jsx)(vx,{size:`sm`,className:`text-muted-foreground`,children:(0,G.jsx)(ZP,{})}),(0,G.jsx)(`span`,{className:`truncate`,children:t})]}),(0,G.jsx)(MN.HeaderActions,{children:(0,G.jsx)(MN.CloseButton,{icon:`x`,tooltip:`Close tool`,onClick:n})})]}),(0,G.jsx)(MN.Content,{className:`flex flex-col gap-4 px-3`,children:t&&(0,G.jsx)(_Fi,{value:t,children:e},t)})]})}var qFi=()=>{let{serverId:e}=wv(),t=[AR(`/mcps`),pnn],{data:n=[],isLoading:r}=TR(),i=n.find(t=>t.id===e),a=i?.transports?.includes(`sse`)??!0,o=r||i?(0,G.jsxs)(MS,{children:[(0,G.jsx)(MS.Title,{isLoading:r,children:i?.name}),i&&(0,G.jsx)(MS.Meta,{beside:!0,children:(0,G.jsxs)(YS,{size:`sm`,children:[`v`,i.version_detail.version]})}),i&&(0,G.jsx)(MS.Description,{children:a?`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(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:t}),header:o,children:[(0,G.jsx)(WFi,{isLoading:r,server:i}),e&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(KFi,{children:(0,G.jsx)(bFi,{serverId:e})}),(0,G.jsx)(APi,{serverId:e}),(0,G.jsx)(XPi,{serverId:e})]})]})},JFi=[{label:`Agent`,entityType:`agent`},{label:`Workflow`,entityType:`workflow_run`},{label:`Scorer`,entityType:`scorer`},{label:`Ingest`,entityType:`rag_ingestion`},{label:`Classifier`,entityType:`classifier`}],S9=`rootEntityType`,C9={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`},YFi=Object.keys(C9),XFi=`mastra:metrics:saved-filters`;function ZFi(e){let t=dIi(e);try{localStorage.setItem(XFi,t.toString())}catch{}}function QFi(){try{let e=localStorage.getItem(XFi);if(!e)return null;let t=new URLSearchParams(e);return t.toString()?t:null}catch{return null}}function $Fi(e){if(e.has(`rootEntityType`))return!0;for(let t of YFi)if(e.has(C9[t]))return!0;return!1}var eIi=`hasAll`,tIi=[{id:`is`,label:`is`},{id:eIi,label:`has all of`,arity:`many`}],nIi={rootEntityType:`Primitive type`,entityName:`Primitive name`,tags:`Tags`,serviceName:`Service Name`,environment:`Environment`,threadId:`Thread ID`,resourceId:`Resource ID`,userId:`User ID`,organizationId:`Organization ID`,runId:`Run ID`,sessionId:`Session ID`,requestId:`Request ID`,experimentId:`Experiment ID`,provider:`Provider`,model:`Model`},rIi={provider:U8,model:VR},iIi=[`threadId`,`resourceId`,`userId`,`organizationId`,`runId`,`sessionId`,`requestId`,`experimentId`],aIi=e=>({id:e,label:nIi[e],icon:rIi[e]??Qii(e),color:d5(e)}),oIi=(e,t)=>e.label.localeCompare(t.label);function sIi({availableTags:e,availableEntityNames:t,availableServiceNames:n,availableEnvironments:r}){let i=(e,t)=>({...aIi(e),operators:[`is`],strict:!0,suggestions:t}),a=e=>({...aIi(e),operators:[`is`]}),o=e=>e.map(e=>({value:e})),s=[i(`rootEntityType`,JFi.map(e=>({value:e.entityType,label:e.label}))),i(`entityName`,o(t)),{...i(`tags`,o(e)),operators:[eIi]},i(`serviceName`,o(n)),i(`environment`,o(r))],c=iIi.map(a),l=[`provider`,`model`].map(e=>({...a(e),hidden:!0}));return[...s.toSorted(oIi),...c.toSorted(oIi),...l]}function cIi(e){return e.map(e=>{if(e.fieldId===`tags`){let t=[e.value].flat().filter(e=>e!==``);return{id:e.fieldId,fieldId:e.fieldId,operatorId:eIi,value:t}}let t=Array.isArray(e.value)?e.value[0]??``:e.value;return{id:e.fieldId,fieldId:e.fieldId,operatorId:`is`,value:mIi(t)?``:t}})}function lIi(e){return e.map(e=>({fieldId:e.fieldId,value:Array.isArray(e.value)?e.value.map(String):String(e.value)}))}function uIi(e){let t=[],n=new Map([[S9,`rootEntityType`]]);for(let e of YFi)n.set(C9[e],e);let r=new Set;for(let[i]of e.entries()){let a=n.get(i);if(!a||r.has(a))continue;if(r.add(a),a===`tags`){let n=e.getAll(i);if(n.length===0)continue;t.push({fieldId:a,value:n.filter(Boolean)});continue}if(a===`rootEntityType`||a===`entityName`||a===`serviceName`||a===`environment`||a===`provider`||a===`model`){let n=e.getAll(i);if(n.length>1){t.push({fieldId:a,value:n});continue}}let o=e.get(i);o!==null&&t.push({fieldId:a,value:o})}return t}function dIi(e){let t=new URLSearchParams,n=e.getAll(S9);for(let e of n)t.append(S9,e);for(let n of YFi){let r=C9[n],i=e.getAll(r);for(let e of i)t.append(r,e)}return t}function fIi(e,t){e.delete(S9);for(let t of YFi)e.delete(C9[t]);for(let n of t){let t=n.fieldId===`rootEntityType`?S9:C9[n.fieldId];if(t){if(Array.isArray(n.value)){let r=n.value.filter(e=>typeof e==`string`&&e!==``);if(r.length===0){n.fieldId===`tags`&&e.append(t,``);continue}for(let n of r)e.append(t,n)}else typeof n.value==`string`&&e.set(t,n.value.trim())}}}var pIi=`Any`;function mIi(e){let t=e.trim();return t===``||t===pIi}var hIi=new Set(JFi.map(e=>e.entityType));function gIi(e){let t=e.trim();return hIi.has(t)?t:void 0}function _Ii(e){let t={};for(let n of e){let e=n.fieldId;if(Array.isArray(n.value)){let r=n.value.filter(e=>typeof e==`string`).map(e=>e.trim()).filter(e=>!mIi(e));if(r.length===0)continue;if(e===`tags`)t.tags=r;else if(e===`rootEntityType`){let e=r[0],n=e===void 0?void 0:gIi(e);n&&(t.rootEntityType=n)}else t[e]=r[0]}else if(typeof n.value==`string`){if(mIi(n.value))continue;let r=n.value.trim();if(e===`rootEntityType`){let e=gIi(r);e&&(t.rootEntityType=e)}else t[e]=r}}return t}var vIi={first:0,normal:1,last:2},yIi=class extends Error{constructor(){super(`Skipped: nothing is waiting for this request any more`),this.name=`SkippedRequestError`}};function bIi(e){let t=0,n=[],r=()=>{t<e&&n.shift()?.start()};return{run(i,{priority:a=vIi.normal,isWanted:o}={}){return new Promise((s,c)=>{let l=e=>{e&&o&&!o()?(c(new yIi),r()):(t++,i().then(s,c).finally(()=>{t--,r()}))};if(t<e&&n.length===0){l(!1);return}let u={priority:a,start:()=>l(!0)},d=n.findIndex(e=>e.priority>a);d===-1?n.push(u):n.splice(d,0,u)})}}}var xIi=(0,W.createContext)(void 0);function SIi(){let e=(0,W.use)(xIi);if(!e)throw Error(`useAggregateLimiter must be used inside MetricsProvider or AggregateLimiterProvider`);return e}function CIi(e,t){let n=SIi(),r=a_();return({queryKey:i})=>n.run(e,{priority:t,isWanted:()=>(r.getQueryCache().find({queryKey:i,exact:!0})?.getObserversCount()??0)>0})}function wIi({children:e}){let t=(0,W.use)(xIi),[n]=(0,W.useState)(()=>t?void 0:bIi(3));return(0,G.jsx)(xIi,{value:t??n,children:e})}var TIi=864e5,EIi={"24h":TIi,"3d":2592e5,"7d":6048e5,"14d":12096e5,"30d":2592e6};function DIi(e,t,n){if(e!==`custom`){let t=EIi[e]??TIi;return{start:new Date(n-t),end:new Date(n)}}return{start:t?.from??new Date(n-TIi),end:t?.to??new Date(n)}}function OIi({datePreset:e,customRange:t,dimensionalFilter:n,dimensionalFilterKey:r}){let i=(0,W.useRef)(null),a=e===`custom`?`custom:${t?.from?.getTime()??``}:${t?.to?.getTime()??``}`:`preset:${e}`;i.current&&i.current.key===a||(i.current={key:a,anchor:Date.now()});let o=i.current.anchor,s=(0,W.useMemo)(()=>DIi(e,t,o),[e,t,o]);return{datePreset:e,customRange:t,timestamp:s,filters:(0,W.useMemo)(()=>({timestamp:s,...n}),[s,r]),dimensionalFilter:n,filterKey:(0,W.useMemo)(()=>`${a}|${r}`,[a,r])}}function kIi(e){let t=Y(),{filters:n,filterKey:r,queryOptions:i}=e;return b_({queryKey:[`metrics`,`agent-runs-kpi`,r],queryFn:()=>t.getMetricAggregate({name:[`mastra_agent_duration_ms`],aggregation:`count`,filters:n,comparePeriod:`previous_period`}),...i})}new Intl.NumberFormat(`en-US`,{notation:`compact`,maximumSignificantDigits:3}),new Intl.NumberFormat(`en-US`),new Set(Intl.supportedValuesOf(`currency`));function AIi(e){let t=Y(),{filters:n,filterKey:r,queryOptions:i}=e;return b_({queryKey:[`metrics`,`token-usage-by-agent`,r],queryFn:async()=>{let e={groupBy:[`entityName`],aggregation:`sum`,orderDirection:`DESC`,filters:n},[r,i]=await Promise.all([t.getMetricBreakdown({...e,name:[`mastra_model_total_input_tokens`]}),t.getMetricBreakdown({...e,name:[`mastra_model_total_output_tokens`]})]),a=new Map,o=e=>W8(a,e,()=>({input:0,output:0,cost:null,costUnit:null})),s=(e,t)=>{t.estimatedCost!=null&&(e.cost=(e.cost??0)+t.estimatedCost,t.costUnit&&(e.costUnit=t.costUnit))};for(let e of r.groups){let t=o(e.dimensions.entityName??`unknown`);t.input=e.value,s(t,e)}for(let e of i.groups){let t=o(e.dimensions.entityName??`unknown`);t.output=e.value,s(t,e)}return Array.from(a.entries()).map(([e,t])=>({name:e,input:t.input,output:t.output,total:t.input+t.output,cost:t.cost,costUnit:t.costUnit})).sort((e,t)=>t.total-e.total)},...i})}async function jIi(e,t,n){let r=await e.getMetricBreakdown({name:[t],groupBy:[`entityName`,`status`],aggregation:`count`,orderDirection:`DESC`,filters:n}),i=new Map;for(let e of r.groups){let t=e.dimensions.entityName??`unknown`,n=e.dimensions.status??`ok`,r=W8(i,t,()=>({completed:0,errors:0}));n===`error`?r.errors+=e.value:r.completed+=e.value}return Array.from(i.entries()).map(([e,t])=>({name:e,...t})).sort((e,t)=>t.completed+t.errors-(e.completed+e.errors))}function MIi(e){let t=Y(),{filters:n,filterKey:r,queryOptions:i}=e;return b_({queryKey:[`metrics`,`trace-volume`,r],queryFn:async()=>{let[e,r,i]=await Promise.all([jIi(t,`mastra_agent_duration_ms`,n),jIi(t,`mastra_workflow_duration_ms`,n),jIi(t,`mastra_tool_duration_ms`,n)]);return{agentData:e,workflowData:r,toolData:i}},...i})}var NIi=[{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`}],PIi=new Set(NIi.map(e=>e.value));function FIi(e){return typeof e==`string`&&(PIi.has(e)||e===`custom`)}var IIi=(0,W.createContext)({datePreset:`24h`,setDatePreset:()=>{},customRange:void 0,setCustomRange:()=>{},dateRangeLabel:`Last 24 hours`,comparisonLabel:`vs previous 24h`,filterTokens:[],setFilterTokens:()=>{},dimensionalFilter:{},dimensionalFilterKey:`{}`,queryFilters:void 0,scope:{}});function w9(){return(0,W.useContext)(IIi)}function LIi(e,t){return e===`custom`?t?.from?t.to?`${mC(t.from)} – ${mC(t.to)}`:mC(t.from)??``:`Custom range`:NIi.find(t=>t.value===e)?.label??e}var RIi=36e5;function zIi(e,t){if(e!==`custom`)return`vs previous ${e}`;let n=t?.to?.getTime()??Date.now(),r=t?.from?.getTime()??n-24*RIi,i=Math.round((n-r)/RIi);return`vs previous ${i>24&&i%24==0?`${i/24}d`:`${i}h`}`}function BIi({children:e,preset:t,filterTokens:n,onPresetChange:r,onFilterTokensChange:i,customRange:a,onCustomRangeChange:o,scope:s}){let c=(0,W.useMemo)(()=>JSON.stringify(n),[n]),l=(0,W.useMemo)(()=>n,[c]),u=(0,W.useMemo)(()=>_Ii(l),[l]),d=(0,W.useMemo)(()=>JSON.stringify(u),[u]),f=OIi({datePreset:t,customRange:a,dimensionalFilter:u,dimensionalFilterKey:d}),p=(0,W.useMemo)(()=>s??{},[s]),m=LIi(t,a),h=zIi(t,a),g=(0,W.useMemo)(()=>({datePreset:t,setDatePreset:r,customRange:a,setCustomRange:o??(()=>{}),dateRangeLabel:m,comparisonLabel:h,filterTokens:l,setFilterTokens:i,dimensionalFilter:u,dimensionalFilterKey:d,queryFilters:f,scope:p}),[t,r,a,o,m,h,l,i,u,d,f,p]);return(0,G.jsx)(IIi.Provider,{value:g,children:(0,G.jsx)(wIi,{children:e})})}var VIi=[`last-24h`,`last-3d`,`last-7d`,`last-14d`,`last-30d`,`custom`];function HIi(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 UIi(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`}}var WIi=864e5;function GIi(){let{data:e}=O7(),t=e?.capabilities.traceRetentionDays;if(t===void 0)return;let n=new Date(Date.now()-t*WIi);return new Date(n.getFullYear(),n.getMonth(),n.getDate())}function KIi(){let{datePreset:e,setDatePreset:t,customRange:n,setCustomRange:r}=w9(),i=GIi();return(0,G.jsx)(PLt,{preset:HIi(e),onPresetChange:e=>t(UIi(e)),dateFrom:n?.from,dateTo:n?.to,onDateRangeChange:(e,t)=>r({from:e,to:t}),presets:VIi,minDate:i})}var qIi=W.forwardRef(({label:e,children:t,...n},r)=>(0,G.jsx)(X,{ref:r,variant:`ghost`,size:`icon-sm`,tooltip:e,"aria-label":e,...n,children:t}));qIi.displayName=`MetricsCardAction`;function JIi({children:e,className:t}){return(0,G.jsx)(`div`,{className:c(`-my-1 flex shrink-0 items-center gap-1 self-start`,t),children:e})}function YIi({children:e,className:t}){return(0,G.jsx)(`div`,{className:c(`overflow-x-auto overflow-y-hidden [&_tbody>tr:last-child]:border-b-0`,t),children:e})}function XIi({className:e,...t}){return(0,G.jsx)(X,{variant:`ghost`,size:`icon-sm`,className:c(`-my-1 shrink-0 cursor-grab active:cursor-grabbing`,e),...t,children:(0,G.jsx)(iF,{})})}function ZIi({message:e=`Failed to load data`,className:t}){return(0,G.jsx)(`div`,{className:c(`flex flex-col items-center justify-center gap-3`,t),children:(0,G.jsx)(T,{variant:`caption`,className:`text-destructive-foreground`,children:e})})}function QIi({label:e,value:t,change:n,isLoading:r=!1,className:i}){return(0,G.jsxs)(`div`,{className:c(`grid gap-1.5`,i),children:[(0,G.jsx)(`h3`,{className:`text-body-sm text-muted-foreground`,children:e}),(0,G.jsxs)(`span`,{className:`flex items-baseline gap-2`,children:[(0,G.jsx)(`span`,{className:c(`text-title text-foreground tabular-nums [text-box:trim-both_cap_alphabetic]`,r&&`relative min-w-24`),children:r?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{className:`invisible`,children:`0`}),(0,G.jsx)(PS,{className:`absolute inset-0`})]}):t}),!r&&n&&(0,G.jsxs)(`span`,{className:`text-body-sm text-muted-foreground tabular-nums [text-box:trim-both_cap_alphabetic]`,children:[n,` vs previous`]})]})]})}function $Ii({className:e}){return(0,G.jsx)(`div`,{className:c(`flex items-center justify-center`,e),children:(0,G.jsx)(Mv,{size:`md`,variant:`pulse`,className:`text-subtle-foreground`})})}function eLi({message:e=`No data yet`,className:t}){return(0,G.jsx)(`div`,{className:c(`flex h-full items-center justify-center`,t),children:(0,G.jsx)(T,{tone:`faint`,children:e})})}function tLi({children:e,className:t}){return(0,G.jsx)(HL,{className:c(`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 nLi({children:e,className:t,as:n=`h3`}){return(0,G.jsx)(n,{className:c(`text-subheading text-foreground`,t),children:e})}function rLi({title:e,value:t,onValueChange:n,options:r,className:i}){return(0,G.jsx)(`div`,{className:`flex min-w-0`,children:(0,G.jsxs)(sO,{modal:!1,children:[(0,G.jsxs)(sO.Trigger,{render:(0,G.jsx)(`button`,{type:`button`,className:c(`-mx-1.5 -my-0.5 flex items-center gap-1 self-start rounded-md px-1.5 py-0.5 text-left text-subheading text-foreground hover:bg-fill-subtle`,i)}),children:[e,(0,G.jsx)(_,{className:`size-icon-sm text-muted-foreground`})]}),(0,G.jsx)(sO.Content,{align:`start`,children:(0,G.jsx)(sO.RadioOptions,{options:r,value:t,onValueChange:n,closeOnSelect:!0})})]})})}function iLi({children:e,className:t}){return(0,G.jsx)(`div`,{className:c(`flex min-h-6 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 aLi({children:e,className:t}){return(0,G.jsx)(`div`,{className:c(`flex items-start gap-4 [&>:first-child]:min-w-0 [&>:first-child]:flex-1`,t),children:e})}function oLi({value:e,isLoading:t=!1,className:n}){return(0,G.jsx)(`span`,{className:c(`order-last shrink-0 text-subheading text-foreground tabular-nums`,n),children:(0,G.jsx)(sLi,{value:e,isLoading:t})})}function sLi({value:e,isLoading:t}){return t?(0,G.jsx)(FS,{line:`text-body`,className:`h-4 w-14`}):typeof e==`string`?e:(0,G.jsx)(`span`,{className:`inline-flex items-center gap-3`,children:e.map(e=>(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,G.jsx)(`span`,{"aria-hidden":!0,className:`size-2 shrink-0 rounded-[2px]`,style:{backgroundColor:e.color}}),(0,G.jsxs)(`span`,{className:`sr-only`,children:[e.label,` `]}),e.value]},e.label))})}var T9=Object.assign(tLi,{Root:tLi,Kpi:V6,TopBar:aLi,Toolbar:iLi,Actions:JIi,Action:qIi,DragHandle:XIi,Title:nLi,TitleMenu:rLi,Total:oLi,Headline:QIi,Loading:$Ii,Error:ZIi,Content:YIi,NoData:eLi}),cLi=`pointer-events-none absolute opacity-0 pointer-coarse:pointer-events-auto pointer-coarse:static pointer-coarse:opacity-100 group-hover/metrics-card:pointer-events-auto group-hover/metrics-card:static group-hover/metrics-card:opacity-100 motion-safe:group-hover/metrics-card:transition-opacity group-focus-within/metrics-card:pointer-events-auto group-focus-within/metrics-card:static group-focus-within/metrics-card:opacity-100 motion-safe:group-focus-within/metrics-card:transition-opacity group-has-data-popup-open/metrics-card:pointer-events-auto group-has-data-popup-open/metrics-card:static group-has-data-popup-open/metrics-card:opacity-100`;function lLi({onClick:e}){return(0,G.jsx)(T9.Action,{label:`View in traces`,className:cLi,onClick:e,children:(0,G.jsx)(kR,{})})}function uLi({onClick:e}){return(0,G.jsx)(T9.Action,{label:`View errors in logs`,className:cLi,onClick:e,children:(0,G.jsx)(Ztn,{})})}function E9({isEmpty:e=!1,emptyMessage:t=`No data in this range`,children:n}){return(0,G.jsxs)(`div`,{className:`relative flex min-h-0 flex-1 flex-col`,"data-chart-empty":e||void 0,children:[(0,G.jsx)(`div`,{className:c(`flex min-h-0 flex-1 flex-col`,e&&`invisible [&_.recharts-xAxis-tick-labels]:visible`),children:(0,G.jsx)(asi.Provider,{value:e,children:n})}),e&&(0,G.jsx)(fLi,{message:t})]})}function dLi({className:e}){return(0,G.jsx)(`div`,{"aria-hidden":!0,className:c(`h-px bg-[linear-gradient(to_right,var(--border)_3px,transparent_3px)] bg-size-[6px_1px] opacity-50`,e)})}function fLi({message:e}){return(0,G.jsxs)(`div`,{className:`absolute inset-0 flex flex-col justify-between`,style:{paddingTop:M5.top,paddingBottom:22},children:[(0,G.jsx)(dLi,{}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(dLi,{className:`flex-1`}),(0,G.jsx)(T,{as:`span`,variant:`body-sm`,tone:`muted`,className:`max-w-[70%] text-center font-[450] text-balance`,children:e}),(0,G.jsx)(dLi,{className:`flex-1`})]}),(0,G.jsx)(dLi,{})]})}function D9({variant:e=`default`,title:t,href:n,LinkComponent:r,titleMenu:i,dragHandle:a,onTitleChange:o,total:s,change:l,isLoading:u=!1,actions:d,toolbar:f,isUpdating:p=!1,bodyHeight:m=`fixed`,className:h,children:g}){let _=c(`transition-opacity duration-200`,p&&`opacity-50`),v=e===`compact`,y=e===`hero`,b=!y&&m===`fixed`;return(0,G.jsxs)(T9,{className:c(`min-h-0! min-w-0! grid-cols-1`,`[&:has([data-slot=chart-skeleton])_[data-slot=chart-legend]]:invisible`,`[&:has([data-chart-empty])_[data-slot=chart-legend]]:invisible`,v&&`h-84`,h),children:[(0,G.jsxs)(T9.TopBar,{children:[y?(0,G.jsx)(T9.Headline,{label:t,value:typeof s==`string`?s:`—`,change:l,isLoading:u,className:_}):(0,G.jsx)(mLi,{title:t,href:n,LinkComponent:r,titleMenu:i,dragHandle:a,onTitleChange:o}),d&&(0,G.jsx)(T9.Actions,{className:c(y&&`my-0 self-center`),children:d}),!y&&s!==void 0&&(0,G.jsx)(T9.Total,{value:s,isLoading:u,className:_})]}),(0,G.jsxs)(T9.Content,{className:c(`flex flex-col gap-4 overflow-visible`,v&&`min-h-0`),children:[f||b&&f!==void 0&&(0,G.jsx)(`div`,{"aria-hidden":!0,className:`min-h-6`}),(0,G.jsx)(`div`,{className:c(`relative flex min-h-0 min-w-0 flex-col`,pLi(e,m),_),children:g})]})]})}function pLi(e,t){if(e===`compact`)return`flex-1`;if(e!==`hero`)return t===`fit`?`min-h-60`:`min-h-60 flex-1`}function mLi({dragHandle:e,...t}){return e?(0,G.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5`,children:[(0,G.jsx)(T9.DragHandle,{...e}),(0,G.jsx)(hLi,{...t})]}):(0,G.jsx)(hLi,{...t})}function hLi({title:e,href:t,LinkComponent:n,titleMenu:r,onTitleChange:i}){return r?(0,G.jsx)(T9.TitleMenu,{title:e,...r}):t?(0,G.jsx)(`h3`,{className:`flex`,children:(0,G.jsx)(_Li,{href:t,LinkComponent:n,children:e})}):i?(0,G.jsx)(gLi,{title:e,onTitleChange:i}):(0,G.jsx)(T9.Title,{children:e})}function gLi({title:e,onTitleChange:t}){return(0,G.jsx)(`h3`,{className:`flex min-w-0`,children:(0,G.jsx)(`input`,{"aria-label":`Widget title`,defaultValue:e,...Lk,onBlur:n=>{let r=n.currentTarget.value.trim();n.currentTarget.value=r,r!==e&&t(r)},onKeyDown:t=>{t.key===`Escape`&&(t.currentTarget.value=e),(t.key===`Enter`||t.key===`Escape`)&&(t.preventDefault(),t.currentTarget.blur())},className:c(`-mx-1.5 -my-0.5 field-sizing-content min-w-12 truncate rounded-md bg-transparent px-1.5 py-0.5`,`text-body zoom-safe-text font-medium text-foreground`,`outline-1 -outline-offset-1 outline-transparent outline-dashed hover:outline-border-strong focus:outline-border-focus`)},e)})}function _Li({href:e,LinkComponent:t,children:n}){return(0,G.jsxs)(t??`a`,{href:e,className:c(`-mx-1.5 -my-0.5 inline-flex items-center gap-1.5 rounded-md px-1.5 py-0.5 text-subheading text-foreground hover:bg-fill-subtle`,`focus-visible:outline-1 focus-visible:-outline-offset-1 focus-visible:outline-border-focus focus-visible:outline-solid`),children:[n,(0,G.jsx)(qL,{"aria-hidden":!0,className:`size-icon-sm text-muted-foreground`})]})}function O9({error:e,onRetry:t}){return JN(e)?(0,G.jsx)(vR,{}):YN(e)?(0,G.jsx)(_R,{resource:`traces`}):(0,G.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-3`,children:[(0,G.jsx)(T9.Error,{message:`Couldn't load this data. Try again in a moment.`}),t&&(0,G.jsx)(X,{size:`sm`,icon:(0,G.jsx)(dS,{}),onClick:t,children:`Retry`})]})}var vLi={2:`@3xl:grid-cols-2`,3:`@3xl:grid-cols-2 @7xl:grid-cols-3`},yLi={1:``,2:`@3xl:col-span-2`,full:`col-span-full`};function k9({children:e,columns:t=3,className:n}){return(0,G.jsx)(`div`,{className:c(`@container`,n),children:(0,G.jsx)(`div`,{className:c(`grid gap-4`,vLi[t]),children:e})})}function bLi({children:e,span:t=1,className:n}){return(0,G.jsx)(`div`,{className:c(`min-w-0 *:size-full *:min-w-0!`,yLi[t],n),children:e})}k9.Item=bLi;var xLi=864e5;function A9(e,t){let n=t.getTime()-e.getTime();return n<=9e7?{interval:`1h`,stepHours:1}:n<=2628e5?{interval:`1h`,stepHours:3}:n<=6084e5?{interval:`1h`,stepHours:6}:n<=12132e5?{interval:`1h`,stepHours:12}:{interval:`1d`,stepHours:24}}var j9=e=>e===`1h`?1:24;function SLi(e,t){if(t>=24)return Math.floor(e/xLi)*xLi;let n=new Date(e),r=Math.floor(n.getHours()/t)*t;return new Date(n.getFullYear(),n.getMonth(),n.getDate(),r).getTime()}function CLi(e,t){if(t>=24)return SLi(e,t)+xLi;let n=new Date(e);return SLi(new Date(n.getFullYear(),n.getMonth(),n.getDate(),n.getHours()+t).getTime(),t)}function wLi(e,t,n){let r=Yai(e,t),i=[];for(let a=SLi(e.getTime(),n);a<=t.getTime();a=CLi(a,n))i.push(Qai(a,n,r));return i}function TLi(e,t){let n=new Map(e.map((e,t)=>[e.ts,t]));return e=>n.get(SLi(new Date(e.timestamp).getTime(),t))}function M9(e,t){return{from:new Date(e),to:new Date(CLi(e,t))}}function N9(){let{datePreset:e,customRange:t,dimensionalFilter:n,dimensionalFilterKey:r,queryFilters:i}=w9(),a=OIi({datePreset:e,customRange:t,dimensionalFilter:n,dimensionalFilterKey:r});return i??a}var ELi={input:`mastra_model_total_input_tokens`,output:`mastra_model_total_output_tokens`,cacheRead:`mastra_model_input_cache_read_tokens`},DLi=`mastra_agent_duration_ms`;function OLi(){let e=Y(),{filters:t,filterKey:n,timestamp:r}=N9(),{interval:i,stepHours:a}=A9(r.start,r.end);return b_({queryKey:[`metrics`,`activity`,n,i],placeholderData:f_,queryFn:async()=>{let n=n=>e.getMetricTimeSeries({name:[n],interval:i,aggregation:`sum`,filters:t}),[o,s,c,l]=await Promise.all([n(ELi.input),n(ELi.output),n(ELi.cacheRead),e.getMetricTimeSeries({name:[DLi],interval:i,aggregation:`count`,groupBy:[`status`],filters:t})]),u=wLi(r.start,r.end,a).map(e=>({...e,input:0,cacheRead:0,output:0,cost:0,completed:0,failed:0,failureRate:0})),d=TLi(u,a),f=e=>{let t=d(e);return t===void 0?void 0:u[t]},p=(e,t)=>{for(let n of e){let e=f(n);e&&(e[t]+=n.value,t!==`cacheRead`&&(e.cost+=n.estimatedCost??0))}};for(let e of o.series)p(e.points,`input`);for(let e of s.series)p(e.points,`output`);for(let e of c.series)p(e.points,`cacheRead`);for(let e of l.series){let t=/error|fail/i.test(e.name)?`failed`:`completed`;for(let n of e.points){let e=f(n);e&&(e[t]+=n.value)}}for(let e of u){e.input=Math.max(e.input-e.cacheRead,0);let t=e.completed+e.failed;e.failureRate=t>0?e.failed/t:0}return u}})}var kLi=[{dataKey:`input`,label:`Input`,color:D5.green},{dataKey:`cacheRead`,label:`Cache read`,color:D5.violet},{dataKey:`output`,label:`Output`,color:D5.sky}],ALi=[{dataKey:`cost`,label:`Cost`,color:D5.green}],jLi={tokens:`Token usage`,cost:`Model cost`},MLi=[{value:`tokens`,label:jLi.tokens},{value:`cost`,label:jLi.cost}];function NLi({onViewTraces:e,onTimeRangeClick:t}){let[n,r]=(0,W.useState)(`tokens`),{data:i=[],isLoading:a,isError:o,isPlaceholderData:s}=OLi(),{timestamp:c}=N9(),{stepHours:l}=A9(c.start,c.end),u=i.reduce((e,t)=>e+t.input+t.cacheRead+t.output,0),d=i.reduce((e,t)=>e+t.cost,0),f=n===`tokens`,p=f?kLi:ALi,m={title:jLi[n],titleMenu:{value:n,onValueChange:r,options:MLi},actions:e&&(0,G.jsx)(lLi,{onClick:e}),toolbar:(0,G.jsx)(T9.Toolbar,{children:(0,G.jsx)(I5,{series:p})})};return o?(0,G.jsx)(D9,{...m,children:(0,G.jsx)(O9,{})}):(0,G.jsx)(D9,{...m,total:f?k5(u):j5(d),isLoading:a,isUpdating:s,children:(0,G.jsx)(E9,{isEmpty:!a&&u===0&&d===0,children:(0,G.jsx)(Cci,{data:i,series:p,height:`fill`,xLabels:`edges`,showLegend:!1,valueFormatter:f?k5:j5,axisFormatter:f?nsi:rsi,onBucketClick:t&&(e=>t(M9(Number(e.ts),l))),isLoading:a,...E5})})})}var PLi=[{dataKey:`failureRate`,label:`Failed runs`,color:D5.error}],FLi=e=>`${Math.round(e*100)}%`;function ILi({onViewErrors:e,onTimeRangeClick:t,titleMenu:n}){let{data:r=[],isLoading:i,isError:a,isPlaceholderData:o}=OLi(),{timestamp:s}=N9(),{stepHours:c}=A9(s.start,s.end),l=r.reduce((e,t)=>e+t.completed+t.failed,0),u=r.reduce((e,t)=>e+t.failed,0),d=u===0?[0,1]:void 0,f={title:`Failure rate`,titleMenu:n,actions:e&&(0,G.jsx)(uLi,{onClick:e}),toolbar:(0,G.jsx)(T9.Toolbar,{children:(0,G.jsx)(I5,{series:PLi})})};return a?(0,G.jsx)(D9,{...f,children:(0,G.jsx)(O9,{})}):(0,G.jsx)(D9,{...f,total:A5(l>0?u/l:0),isLoading:i,isUpdating:o,children:(0,G.jsx)(E9,{isEmpty:!i&&l===0,children:(0,G.jsx)(tci,{lineStyle:`thin`,data:r,series:PLi,height:`fill`,xLabels:`edges`,showLegend:!1,valueFormatter:A5,axisFormatter:FLi,yDomain:d,onBucketClick:t&&(e=>t(M9(Number(e.ts),c))),isLoading:i,...E5})})})}var LLi=[{dataKey:`completed`,label:`Completed`,color:D5.green},{dataKey:`failed`,label:`Failed`,color:D5.error}],RLi=[{value:`runs`,label:`Agent runs`},{value:`failure`,label:`Failure rate`}];function zLi({onTimeRangeClick:e,onFailureTimeRangeClick:t,onViewErrors:n}){let[r,i]=(0,W.useState)(`runs`),a={value:r,onValueChange:i,options:RLi};return r===`failure`?(0,G.jsx)(ILi,{titleMenu:a,onViewErrors:n,onTimeRangeClick:t}):(0,G.jsx)(BLi,{titleMenu:a,onTimeRangeClick:e})}function BLi({onTimeRangeClick:e,titleMenu:t}){let{data:n=[],isLoading:r,isError:i,isPlaceholderData:a}=OLi(),{timestamp:o}=N9(),{stepHours:s}=A9(o.start,o.end),c=n.reduce((e,t)=>e+t.completed+t.failed,0),l={title:`Agent runs`,titleMenu:t,toolbar:(0,G.jsx)(T9.Toolbar,{children:(0,G.jsx)(I5,{series:LLi})})};return i?(0,G.jsx)(D9,{...l,children:(0,G.jsx)(O9,{})}):(0,G.jsx)(D9,{...l,total:k5(c),isLoading:r,isUpdating:a,children:(0,G.jsx)(E9,{isEmpty:!r&&c===0,children:(0,G.jsx)(Cci,{data:n,series:LLi,height:`fill`,xLabels:`edges`,showLegend:!1,valueFormatter:k5,onBucketClick:e&&(t=>e(M9(Number(t.ts),s))),isLoading:r,...E5})})})}var VLi={.5:`p50`,.95:`p95`,.99:`p99`},HLi={agents:`mastra_agent_duration_ms`,workflows:`mastra_workflow_duration_ms`,tools:`mastra_tool_duration_ms`};function ULi(e){let t=Y(),{filters:n,filterKey:r,timestamp:i}=N9(),{interval:a}=A9(i.start,i.end),o=j9(a);return b_({queryKey:[`metrics`,`latency-percentiles`,e,r,a],placeholderData:f_,queryFn:async()=>{let r=await t.getMetricPercentiles({name:HLi[e],percentiles:[.5,.95,.99],interval:a,filters:n}),s=wLi(i.start,i.end,o),c=TLi(s,o);for(let e of r.series){let t=VLi[e.percentile];if(t)for(let n of e.points){let e=s[c(n)??-1];e&&(e[t]=Math.round(n.value))}}return s}})}var WLi={agents:Sp.AGENT,workflows:Sp.WORKFLOW_RUN,tools:Sp.TOOL},GLi=[{dataKey:`p50`,label:`P50`,color:D5.sky},{dataKey:`p95`,label:`P95`,color:D5.green,emphasis:!0},{dataKey:`p99`,label:`P99`,color:D5.violet}],KLi={agents:`Agent latency`,workflows:`Workflow latency`,tools:`Tool latency`},qLi=[{value:`agents`,label:KLi.agents},{value:`workflows`,label:KLi.workflows},{value:`tools`,label:KLi.tools}];function JLi({onViewTraces:e,onTimeRangeClick:t}){let[n,r]=(0,W.useState)(`agents`),{data:i=[],isLoading:a,isError:o,isPlaceholderData:s}=ULi(n),{timestamp:c}=N9(),l=j9(A9(c.start,c.end).interval),u=Math.max(0,...i.map(e=>e.p95??0)),d={title:KLi[n],titleMenu:{value:n,onValueChange:r,options:qLi},actions:e&&(0,G.jsx)(lLi,{onClick:()=>e(WLi[n])}),toolbar:(0,G.jsx)(T9.Toolbar,{children:(0,G.jsx)(I5,{series:GLi})})};return o?(0,G.jsx)(D9,{...d,children:(0,G.jsx)(O9,{})}):(0,G.jsx)(D9,{...d,total:tsi(u),isLoading:a,isUpdating:s,children:(0,G.jsx)(E9,{isEmpty:!a&&u===0,children:(0,G.jsx)(tci,{lineStyle:`thin`,data:i,series:GLi,height:`fill`,xLabels:`edges`,showLegend:!1,valueFormatter:tsi,axisFormatter:isi,onBucketClick:t&&(e=>t(M9(Number(e.ts),l))),isLoading:a,...E5})})})}var YLi=`-mx-2 flex w-[calc(100%+1rem)] items-center gap-3 rounded-md px-2 py-1 text-left`,P9=`shrink-0 text-right text-body-sm tabular-nums`;function XLi({row:e,columns:t,valueWidth:n,share:r,highlighted:i,dimmed:a,onHover:o,LinkComponent:s}){let l=c(YLi,i&&`bg-fill-subtle`,(e.href||e.onClick)&&`hover:bg-fill-subtle`);return(0,G.jsx)(`li`,{children:(0,G.jsxs)(ZLi,{row:e,LinkComponent:s,className:l,style:{opacity:a?.5:1},onMouseEnter:o,children:[(0,G.jsx)(`span`,{className:`size-2 shrink-0 rounded-[2px]`,style:{backgroundColor:e.paint.color,opacity:e.paint.alpha}}),(0,G.jsx)(QLi,{row:e}),t.map((t,n)=>(0,G.jsx)(`span`,{className:c(P9,`text-muted-foreground`,t.width??`w-16`),children:e.cells?.[n]},t.label)),(0,G.jsx)(`span`,{className:c(P9,`w-12 text-muted-foreground`),children:r}),(0,G.jsx)(`span`,{className:c(P9,`text-foreground`,n),children:e.value})]})})}function ZLi({row:e,LinkComponent:t,...n}){return e.href?(0,G.jsx)(t??`a`,{href:e.href,...n}):e.onClick?(0,G.jsx)(`button`,{type:`button`,onClick:e.onClick,...n}):(0,G.jsx)(`div`,{...n})}function QLi({row:e}){return typeof e.label==`string`?(0,G.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,title:e.title??e.label,children:(0,G.jsx)(T,{as:`span`,variant:`body-sm`,tone:`ink`,children:e.label})}):(0,G.jsx)(`span`,{className:`flex min-w-0 flex-1`,title:e.title,children:e.label})}var $Li=`var(--chart-share-1)`,eRi=[1,2,3,4,5].map(e=>`var(--chart-share-${e})`),tRi=[3,4,2,5,1].map(e=>`var(--chart-share-${e})`),nRi=[1,.7,.48,.32,.2,.14],rRi={color:`var(--chart-share-rest)`,alpha:1},iRi=50,aRi=`__rest`;function oRi(e,t,n){if(n===`hues`){let n=eRi.includes(e)?[e,...eRi.filter(t=>t!==e)]:[e,...tRi];return Array.from({length:t},(t,r)=>({color:n[r%n.length]??e,alpha:[1,.55,.3][Math.floor(r/n.length)]??.2}))}return Array.from({length:t},(t,n)=>({color:e,alpha:nRi[n]??.1}))}var sRi=e=>e.reduce((e,t)=>e+Math.max(t.share,0),0);function cRi(e){return e.map(e=>Number.isFinite(e.share)&&e.share>0?e:{...e,share:0}).toSorted((e,t)=>t.share-e.share)}function lRi(e,{limit:t,other:n,color:r,palette:i}){if(e.length<=t+1){let t=uRi(e,r,i);return{shown:t,bar:t,rest:[]}}let a=e.slice(t),o=n?.(a),s={key:aRi,label:`Other (${a.length})`,share:sRi(a),value:o?.value,cells:o?.cells,paint:rRi,segment:aRi},c=uRi(e.slice(0,t),r,i);return{shown:[...c,s],bar:c,rest:a}}function uRi(e,t,n){let r=oRi(t,e.length,n);return e.map((e,t)=>({...e,paint:dRi(e)??r[t]??rRi,segment:e.key}))}var dRi=e=>e.color?{color:e.color,alpha:1}:void 0;function fRi(e,{count:t,color:n,palette:r}){let i=Math.min(t,e.length,iRi),a=uRi(e.slice(0,i),n,r),o=e.slice(i,t).map(e=>({...e,paint:rRi,segment:aRi}));return{shown:[...a,...o],bar:a,rest:e.slice(i)}}function pRi(e,t){let n=e.map(e=>({key:e.key,share:e.share,paint:e.paint})),r=t.length?[{key:aRi,share:sRi(t),paint:rRi}]:[],i=[...n,...r].filter(e=>e.share>0),a=i.reduce((e,t)=>e+t.share,0);return i.map(e=>({key:e.key,paint:e.paint,grow:e.share/a*100}))}function mRi(e,t){if(t!==void 0)return e.find(e=>e.key===t)?.segment??t}var hRi=(e,t)=>t!==void 0&&t!==e;function gRi(e,t){return t===void 0||t===e.key?!1:t!==`__rest`||e.segment!==`__rest`}var _Ri=(e,t)=>{let n=e/(t||1);return n>0?n<.001?`<0.1%`:`${(n*100).toFixed(+(n<.1))}%`:`0%`};function vRi({shown:e,total:t,limit:n,pageSize:r,onMore:i,onLess:a}){if(t<=n)return null;let o=t-e,s=`flex items-center gap-1.5 rounded-md px-2 py-1 text-label text-muted-foreground transition-colors duration-150 hover:bg-fill-subtle hover:text-foreground`,c=new Intl.NumberFormat(`en`,{notation:`compact`,maximumFractionDigits:1});return(0,G.jsxs)(`li`,{className:`-mx-2 flex items-center gap-1`,children:[o>0&&(0,G.jsxs)(`button`,{type:`button`,onClick:i,className:s,children:[(0,G.jsx)(_,{className:`size-icon-sm shrink-0`}),`Show `,Math.min(o,r),` more`]}),e>n&&(0,G.jsxs)(`button`,{type:`button`,onClick:a,className:s,children:[(0,G.jsx)(d,{className:`size-icon-sm shrink-0`}),`Show top `,n]}),o>0&&(0,G.jsxs)(`span`,{className:`ml-auto pr-2 text-body-sm text-subtle-foreground tabular-nums`,children:[c.format(e),` of `,c.format(t)]})]})}var yRi=[`w-32`,`w-24`,`w-36`,`w-20`,`w-28`];function bRi({className:e}){return(0,G.jsxs)(G.Fragment,{children:[`​`,(0,G.jsx)(PS,{className:c(`absolute top-1/2 h-3.5 -translate-y-1/2`,e)})]})}function xRi({rows:e,columns:t,valueWidth:n,header:r}){return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`flex h-2`,children:(0,G.jsx)(PS,{className:`size-full rounded-full`})}),r,(0,G.jsx)(`ul`,{className:`grid min-w-0 grid-cols-1 gap-0.5`,"aria-busy":!0,children:Array.from({length:e},(e,r)=>(0,G.jsxs)(`li`,{className:YLi,children:[(0,G.jsx)(PS,{className:`size-2 shrink-0 rounded-[2px]`}),(0,G.jsx)(`span`,{className:`min-w-0 flex-1`,children:(0,G.jsx)(T,{as:`span`,variant:`body-sm`,className:`relative`,children:(0,G.jsx)(bRi,{className:c(`left-0`,yRi[r%yRi.length])})})}),t.map(e=>(0,G.jsx)(`span`,{className:c(P9,`relative`,e.width??`w-16`),children:(0,G.jsx)(bRi,{className:`right-0 w-10`})},e.label)),(0,G.jsx)(`span`,{className:c(P9,`relative w-12`),children:(0,G.jsx)(bRi,{className:`right-0 w-9`})}),(0,G.jsx)(`span`,{className:c(P9,`relative`,n),children:(0,G.jsx)(bRi,{className:`right-0 w-12`})})]},r))})]})}function SRi({className:e,...t}){return(0,G.jsx)(`div`,{className:c(`grid grid-cols-1`,e),children:(0,G.jsx)(CRi,{...t})})}function CRi({rows:e,columns:t=[],valueLabel:n,valueWidth:r=`w-14`,palette:i=`shades`,color:a=$Li,limit:o=5,overflow:s=`other`,pageSize:c=50,other:l,emptyState:u=`No data in this range.`,isLoading:d=!1,LinkComponent:f}){let[p,m]=(0,W.useState)(),[h,g]=(0,W.useState)(0),_=o+h*c,v=(0,G.jsx)(wRi,{columns:t,valueLabel:n,valueWidth:r});if(d)return(0,G.jsx)(xRi,{rows:s===`other`?o+1:o,columns:t,valueWidth:r,header:v});let y=cRi(e);if(y.length===0)return(0,G.jsx)(T,{variant:`body-sm`,tone:`muted`,className:`py-6 text-center`,children:u});let b=sRi(y),x=s===`more`,{shown:S,bar:C,rest:w}=x?fRi(y,{count:_,color:a,palette:i}):lRi(y,{limit:o,other:l,color:a,palette:i}),E=pRi(C,w),D=mRi(S,p),O=()=>m(void 0);return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`flex h-2 gap-0.5`,onMouseLeave:O,children:E.map(e=>(0,G.jsx)(`span`,{"data-testid":`share-bar-segment`,onMouseEnter:()=>m(e.key),className:`h-full min-w-[3px] first:rounded-l-full last:rounded-r-full`,style:{flex:`${e.grow} 1 0`,backgroundColor:e.paint.color,opacity:e.paint.alpha*(hRi(e.key,D)?.3:1)}},e.key))}),v,(0,G.jsxs)(`ul`,{className:`grid min-w-0 grid-cols-1 gap-0.5`,onMouseLeave:O,children:[S.map(e=>(0,G.jsx)(XLi,{row:e,columns:t,valueWidth:r,share:_Ri(e.share,b),highlighted:p===e.key,dimmed:gRi(e,p),onHover:()=>m(e.key),LinkComponent:f},e.key)),x&&(0,G.jsx)(vRi,{shown:Math.min(_,y.length),total:y.length,limit:o,pageSize:c,onMore:()=>g(e=>e+1),onLess:()=>g(0)})]})]})}function wRi({columns:e,valueLabel:t,valueWidth:n}){let r=[...e.map(e=>({label:e.label,width:e.width??`w-16`})),{label:`Share`,width:`w-12`},{label:t,width:n}];return(0,G.jsx)(`div`,{"aria-hidden":!0,className:`flex items-center justify-end gap-3 pt-3 pb-0.5 text-column text-muted-foreground`,children:r.map(e=>(0,G.jsx)(`span`,{className:c(`shrink-0 text-right whitespace-nowrap`,e.width),children:e.label},e.label))})}var TRi={agents:Sp.AGENT,workflows:Sp.WORKFLOW_RUN,tools:Sp.TOOL},ERi=[{label:`Error rate`}],DRi={agents:`Agent runs`,workflows:`Workflow runs`,tools:`Tool calls`},ORi=[{value:`agents`,label:DRi.agents},{value:`workflows`,label:DRi.workflows},{value:`tools`,label:DRi.tools}],kRi=(e,t)=>A5(t>0?e/t:0);function ARi({onViewTraces:e,onViewErrors:t,onEntityClick:n}){let[r,i]=(0,W.useState)(`agents`),a=TRi[r],o=MIi({...N9(),queryOptions:{placeholderData:f_}}),s={agents:o.data?.agentData??[],workflows:o.data?.workflowData??[],tools:o.data?.toolData??[]}[r],c=s.map(e=>({key:e.name,label:e.name,share:e.completed+e.errors,value:k5(e.completed+e.errors),cells:[kRi(e.errors,e.completed+e.errors)],onClick:n&&(()=>n(a,e.name))})),l=new Map(s.map(e=>[e.name,e.errors])),u=s.reduce((e,t)=>e+t.completed+t.errors,0),d={title:DRi[r],titleMenu:{value:r,onValueChange:i,options:ORi},actions:(e||t)&&(0,G.jsxs)(G.Fragment,{children:[e&&(0,G.jsx)(lLi,{onClick:()=>e(a)}),t&&(0,G.jsx)(uLi,{onClick:()=>t(a)})]})};return o.isError?(0,G.jsx)(D9,{...d,children:(0,G.jsx)(O9,{})}):(0,G.jsx)(D9,{...d,total:k5(u),isLoading:o.isLoading,isUpdating:o.isPlaceholderData,children:(0,G.jsx)(E9,{children:(0,G.jsx)(SRi,{rows:c,columns:ERi,valueLabel:`Runs`,color:D5.sky,other:e=>{let t=e.reduce((e,t)=>e+(l.get(t.key)??0),0),n=e.reduce((e,t)=>e+t.share,0);return{value:k5(n),cells:[kRi(t,n)]}},emptyState:`No runs in this range.`,isLoading:o.isLoading},r)})})}var jRi=[`mastra_model_total_input_tokens`,`mastra_model_total_output_tokens`],MRi=100;function NRi(e){let t=Y(),{filters:n,filterKey:r}=N9();return b_({queryKey:[`metrics`,`token-spend`,e,r],placeholderData:f_,queryFn:async()=>{let{groups:r}=await t.getMetricBreakdown({name:jRi,groupBy:[e],aggregation:`sum`,orderDirection:`DESC`,limit:MRi,filters:n});return r.map(t=>({key:String(t.dimensions[e]??`unknown`),tokens:t.value,cost:t.estimatedCost??0}))}})}var PRi={agents:`Usage by agent`,models:`Usage by model`,threads:`Usage by thread`},FRi=[{value:`agents`,label:PRi.agents},{value:`models`,label:PRi.models},{value:`threads`,label:PRi.threads}],IRi={placeholderData:f_},LRi=[{label:`Tokens`}];function RRi(e){let[t,n]=(0,W.useState)(`agents`);return t===`models`?(0,G.jsx)(BRi,{...e,onViewChange:n}):t===`threads`?(0,G.jsx)(VRi,{...e,onViewChange:n}):(0,G.jsx)(zRi,{...e,onViewChange:n})}function zRi(e){let{onAgentClick:t}=e,{data:n=[],isLoading:r,isPlaceholderData:i,isError:a}=AIi({...N9(),queryOptions:IRi}),o=n.map(e=>({key:e.name,cost:e.cost??0,tokens:e.total,onClick:t&&(()=>t(e.name))}));return(0,G.jsx)(HRi,{view:`agents`,...e,rows:o,isLoading:r,isUpdating:i,isError:a})}function BRi(e){let{onModelClick:t}=e,{data:n=[],isLoading:r,isPlaceholderData:i,isError:a}=NRi(`model`),o=n.map(e=>({...e,onClick:t&&(()=>t(e.key))}));return(0,G.jsx)(HRi,{view:`models`,...e,rows:o,isLoading:r,isUpdating:i,isError:a})}function VRi(e){let{onThreadClick:t}=e,{data:n=[],isLoading:r,isPlaceholderData:i,isError:a}=NRi(`threadId`),o=n.map(e=>({...e,onClick:t&&(()=>t(e.key))}));return(0,G.jsx)(HRi,{view:`threads`,...e,rows:o,isLoading:r,isUpdating:i,isError:a})}function HRi({view:e,onViewChange:t,onViewTraces:n,rows:r,isLoading:i,isUpdating:a,isError:o}){let s=new Map(r.map(e=>[e.key,e.tokens])),c=r.map(e=>({key:e.key,label:e.key,share:e.cost,value:j5(e.cost),cells:[k5(e.tokens)],onClick:e.onClick})),l={title:PRi[e],titleMenu:{value:e,onValueChange:t,options:FRi},actions:n&&(0,G.jsx)(lLi,{onClick:n})};return o?(0,G.jsx)(D9,{...l,children:(0,G.jsx)(O9,{})}):(0,G.jsx)(D9,{...l,total:j5(r.reduce((e,t)=>e+t.cost,0)),isLoading:i,isUpdating:a,children:(0,G.jsx)(E9,{children:(0,G.jsx)(SRi,{rows:c,columns:LRi,valueLabel:`Cost`,color:D5.green,other:e=>({value:j5(e.reduce((e,t)=>e+t.share,0)),cells:[k5(e.reduce((e,t)=>e+(s.get(t.key)??0),0))]}),emptyState:`No model usage in this range.`,isLoading:i})})})}var URi=100;function WRi(){let e=Y(),{filters:t,filterKey:n,timestamp:r}=N9(),{interval:i}=A9(r.start,r.end),a=j9(i);return b_({queryKey:[`metrics`,`scores`,n,i],placeholderData:f_,queryFn:async()=>{let n=await e.listScores({filters:t,pagination:{page:0,perPage:URi}}),o=new Map(n.scores.map(e=>[e.scorerId,e.scorerName??e.scorerId])),s=[...o.keys()].toSorted(),c=await Promise.all(s.map(n=>Promise.all([e.getScoreAggregate({scorerId:n,aggregation:`avg`,filters:t}),e.getScoreTimeSeries({scorerId:n,aggregation:`avg`,interval:i,filters:t})]))),l=wLi(r.start,r.end,a),u=TLi(l,a),d=[];return c.forEach(([e,t],n)=>{let r=s[n];if(r){d.push({scorerId:r,name:o.get(r)??r,average:e.value??0});for(let e of t.series)for(let t of e.points){let e=l[u(t)??-1];e&&(e[r]=t.value)}}}),{scorers:d,buckets:l}}})}var GRi=[D5.green,D5.sky,D5.violet,D5.teal,D5.indigo],KRi=e=>e.toFixed(2),qRi=e=>String(+e.toFixed(2));function JRi(e){return e.map(({scorerId:e,name:t},n)=>({dataKey:e,label:t,color:GRi[n%GRi.length]??D5.neutral}))}function YRi(){let{data:e,isLoading:t,isError:n,isPlaceholderData:r}=WRi(),i=e?.scorers??[],a={title:`Scores`};return n?(0,G.jsx)(D9,{...a,children:(0,G.jsx)(O9,{})}):(0,G.jsx)(D9,{...a,isUpdating:r,children:(0,G.jsx)(E9,{isEmpty:!t&&i.length===0,children:(0,G.jsx)(tci,{lineStyle:`thin`,data:e?.buckets??[],series:JRi(i),height:`fill`,yDomain:[0,1],valueFormatter:KRi,axisFormatter:qRi,isLoading:t,...$oi})})})}var XRi=[`entityName`,`environment`,`threadId`,`resourceId`,`userId`,`organizationId`,`runId`,`sessionId`],ZRi=[`provider`,`model`],QRi=[`serviceName`,`requestId`,`experimentId`],$Ri=(e,t)=>({op:`eq`,left:{path:e},right:{literal:t}});function ezi(e){let t=QRi.filter(t=>e[t]!==void 0);if(t.length)return{supported:!1,unsupportedFields:t};let n=[];e.rootEntityType&&n.push($Ri(`entityType`,e.rootEntityType));for(let t of XRi){let r=e[t];r!==void 0&&n.push($Ri(t,r))}for(let t of e.tags??[])n.push({op:`includes`,path:`tags`,value:t});for(let t of ZRi){let r=e[t];r!==void 0&&n.push({spans:{some:$Ri(t,r)}})}return n.length===0?{supported:!0,where:void 0}:{supported:!0,where:n.length===1?n[0]:{op:`and`,args:n}}}var tzi=({start:e,end:t})=>({from:e.toISOString(),to:t.toISOString()}),nzi=({start:e,end:t})=>A9(e,t).interval;function rzi(e,t){let n=j9(nzi(t)),r=wLi(t.start,t.end,n).map(e=>({...e,rows:[]})),i=TLi(r,n);for(let t of e)t.bucket&&r[i({timestamp:t.bucket,value:0})??-1]?.rows.push(t);return r}function izi({requiresRootSpanFields:e=!1}={}){let{data:t,isLoading:n}=O7(),{timestamp:r,dimensionalFilter:i}=N9();if(n)return{status:`loading`};let a=t?.capabilities;if(a?.traceAggregate!==!0||e&&a.traceQueryRootSpanFields!==!0)return{status:`unavailable`};let o=ezi(i);return o.supported?{status:`ready`,scope:{timeRange:tzi(r),...o.where?{where:o.where}:{},interval:nzi(r),window:r}}:{status:`unsupported-filter`,unsupportedFields:o.unsupportedFields}}function F9(e,{priority:t,enabled:n}={}){let r=Y();return Lni({request:e,enabled:n,queryOptions:{queryFn:CIi(()=>r.aggregateTraces(e),t),placeholderData:f_,staleTime:1/0}})}var azi=[{measure:`countDistinct.resourceId`,dataKey:`resources`,label:`Resources`,color:D5.sky},{measure:`countDistinct.threadId`,dataKey:`threads`,label:`Threads`,color:D5.green},{measure:`countDistinct.userId`,dataKey:`users`,label:`Users`,color:D5.violet},{measure:`countDistinct.sessionId`,dataKey:`sessions`,label:`Sessions`,color:D5.teal}],ozi=azi.map(e=>e.measure),szi=`Resources and threads`;function czi(e,t){return e?.measures[t.measure]??0}function lzi({scope:e,onTimeRangeClick:t}){let n=F9({timeRange:e.timeRange,where:e.where,interval:e.interval,measures:ozi,limit:10}),r=F9({timeRange:e.timeRange,where:e.where,measures:ozi}),i=r.data?.rows[0],a=azi.filter(e=>czi(i,e)>0),o=a.map((e,t)=>({dataKey:e.dataKey,label:e.label,color:e.color,emphasis:t===0})),s=rzi(n.data?.rows??[],e.window).map(({rows:e,...t})=>({...t,...Object.fromEntries(a.map(t=>[t.dataKey,czi(e[0],t)]))})),c=j9(e.interval===`1d`?`1d`:`1h`),l=n.error??r.error,u=n.isLoading||r.isLoading,d=n.isFetching||r.isFetching,f=!!l&&!d,p={title:szi,total:l?void 0:a.length?a.map(e=>({label:e.label,value:k5(czi(i,e)),color:e.color})):k5(0),isLoading:r.isLoading,toolbar:o.length>0&&(0,G.jsx)(T9.Toolbar,{children:(0,G.jsx)(I5,{series:o})})};return f?(0,G.jsx)(D9,{...p,children:(0,G.jsx)(O9,{error:l,onRetry:()=>{n.error&&n.refetch(),r.error&&r.refetch()}})}):(0,G.jsx)(D9,{...p,isUpdating:n.isPlaceholderData||r.isPlaceholderData,children:(0,G.jsx)(E9,{isEmpty:!u&&!l&&a.length===0,children:(0,G.jsx)(tci,{lineStyle:`thin`,data:s,series:o,height:`fill`,xLabels:`edges`,showLegend:!1,valueFormatter:k5,axisFormatter:nsi,onBucketClick:t&&(e=>t({window:M9(Number(e.ts),c)})),isLoading:u,...E5})})})}var uzi={serviceName:`service`,requestId:`request ID`,experimentId:`experiment`};function dzi({requiresRootSpanFields:e,children:t,...n}){let r=izi({requiresRootSpanFields:e});return r.status===`unavailable`?null:r.status===`ready`?t(r.scope):(0,G.jsx)(D9,{...n,toolbar:null,children:r.status===`loading`?(0,G.jsx)(T9.Loading,{}):(0,G.jsx)(T9.NoData,{message:`Not available with a ${r.unsupportedFields.map(e=>uzi[e]??e).join(` or `)} filter.`})})}function fzi(e){return(0,G.jsx)(dzi,{title:szi,children:t=>(0,G.jsx)(lzi,{scope:t,...e})})}function pzi(){return w9().scope}var mzi=[`entityName`,`environment`,`serviceName`,`threadId`,`resourceId`,`userId`,`organizationId`,`runId`,`sessionId`,`requestId`,`experimentId`],hzi=[`tags`,`provider`,`model`],gzi=(e,t)=>({op:`eq`,left:{path:e},right:{literal:t}});function _zi(e){let t=hzi.filter(t=>e[t]!==void 0);if(t.length)return{supported:!1,unsupportedFields:t};let n=[];e.rootEntityType&&n.push(gzi(`entityType`,e.rootEntityType));for(let t of mzi){let r=e[t];r!==void 0&&n.push(gzi(t,r))}return n.length===0?{supported:!0,where:void 0}:{supported:!0,where:n.length===1?n[0]:{op:`and`,args:n}}}function vzi(){let{data:e,isLoading:t}=O7(),{timestamp:n,dimensionalFilter:r}=N9();if(t)return{status:`loading`};if(e?.capabilities.spanAggregate!==!0)return{status:`unavailable`};let i=_zi(r);return i.supported?{status:`ready`,scope:{timeRange:tzi(n),...i.where?{where:i.where}:{},interval:nzi(n),window:n}}:{status:`unsupported-filter`,unsupportedFields:i.unsupportedFields}}function yzi(e,{priority:t,enabled:n}={}){let r=Y();return Ini({request:e,enabled:n,queryOptions:{queryFn:CIi(()=>r.aggregateSpans(e),t),placeholderData:f_,staleTime:1/0}})}var bzi=`Breakdown`,xzi={projects:`Breakdown by project`,agents:`Breakdown by agent`,workflows:`Breakdown by workflow`,tools:`Breakdown by tool`,models:`Breakdown by model`,threads:`Breakdown by thread`,environments:`Breakdown by environment`};function Szi({tab:e,tabs:t,onTabChange:n,isUpdating:r,children:i}){return(0,G.jsx)(D9,{title:xzi[e],titleMenu:t.length>1?{value:e,onValueChange:n,options:t.map(e=>({value:e,label:xzi[e]}))}:void 0,isUpdating:r,bodyHeight:`fit`,children:i})}var Czi={agents:[`agent_run`],workflows:[`workflow_run`],tools:[`tool_call`,`mcp_tool_call`]},wzi=e=>e in Czi;function Tzi(e){let t=Czi[e];return t.length===1?{op:`eq`,left:{path:`spanType`},right:{literal:t[0]??``}}:{op:`in`,value:{path:`spanType`},set:[...t]}}var Ezi=e=>e!==`workflows`&&e!==`tools`,Dzi=e=>e!==`models`,Ozi=e=>e===`tools`||e===`models`;function I9(e,t){if(e===`projects`)return[`projectId`];let n=(...e)=>t?[`projectId`,...e]:e;return e===`environments`?n(`environment`):e===`threads`?n(`threadId`):e===`models`?n(`provider`,`model`):n(`entityName`)}var L9={trace:1e3,span:500};function kzi({timeRange:e,where:t}){return{timeRange:e,...t?{where:t}:{},groupBy:[`projectId`],measures:[`count`,`errorRate`,`duration.p95`,`countDistinct.resourceId`,`countDistinct.threadId`],limit:L9.trace}}function Azi({timeRange:e,where:t},n){return{timeRange:e,...t?{where:t}:{},groupBy:I9(`environments`,n),measures:[`count`,`errorRate`,`duration.p95`],limit:L9.trace}}function jzi(e){let t={op:`exists`,path:`threadId`};return e?{op:`and`,args:[t,e]}:t}function Mzi({timeRange:e,where:t},n){return{timeRange:e,where:jzi(t),groupBy:n?[`projectId`,`threadId`]:[`resourceId`,`threadId`],measures:[`count`,`errorRate`,`duration.p95`],limit:L9.trace}}function Nzi(e,t,n){return e===`projects`?kzi(t):e===`environments`?Azi(t,n):Mzi(t,n)}function Pzi({timeRange:e,where:t}){return{timeRange:e,where:jzi(t),groupBy:[`resourceId`,`threadId`],measures:[`count`],limit:L9.trace}}function Fzi(e){let t=new Map;for(let n of e){let e=Rzi(n,`resourceId`);e&&t.set(Rzi(n,`threadId`),e)}return t}var Izi=e=>e===`agents`||e===`workflows`?`countDistinct.traceId`:`count`;function Lzi(e,{timeRange:t,where:n},r){let i=Tzi(e);return{timeRange:t,where:n?{op:`and`,args:[i,n]}:i,groupBy:I9(e,r),measures:[`count`,...Izi(e)===`count`?[]:[`countDistinct.traceId`],`errorCount`,`errorRate`,`duration.p95`],limit:L9.span}}var R9=(e,t)=>{let n=e.measures[t];return typeof n==`number`&&Number.isFinite(n)?n:void 0},Rzi=(e,t)=>{let n=e.dimensions?.[t];return n==null?``:String(n)},zzi=(e,t)=>t.map(t=>e.dimensions[t]==null?``:String(e.dimensions[t])).join(`|`);function Bzi({tab:e,groupBy:t,aggregateRows:n=[],usageGroups:r,spanGroups:i=[],resources:a}){let o=new Map,s=t.indexOf(`projectId`),c=t.indexOf(`provider`),l=e=>{let t=o.get(e);if(!t){let n=e.split(`|`);t={key:e,...s>=0?{projectId:n[s]??``}:{},...c>=0?{provider:n[c]??``}:{},name:n[n.length-1]??``,count:0,...r?{tokens:0}:{}},o.set(e,t)}return t},u=Izi(e);for(let e of n){let n=l(t.map(t=>Rzi(e,t)).join(`|`));n.count=R9(e,u)??0,n.errorRate=R9(e,`errorRate`),n.p95=R9(e,`duration.p95`),n.resources=R9(e,`countDistinct.resourceId`),n.threads=R9(e,`countDistinct.threadId`)}for(let e of i)l(zzi(e,t)).count=e.value;for(let e of r??[]){let n=l(zzi(e,t));n.tokens=e.value,n.cost=e.estimatedCost??void 0,n.costUnit=n.cost===void 0?void 0:e.costUnit??void 0}if(a)for(let e of o.values()){let t=a.get(e.name);t&&(e.resource=t)}return[...o.values()]}function Vzi({tab:e,groupBy:t,aggregateRows:n=[],usageGroups:r=[],spanGroups:i=[]}){let a=new Map,o=e=>{let t=a.get(e);return t||a.set(e,t={}),t},s=Izi(e);for(let e of n){let n=o(t.map(t=>Rzi(e,t)).join(`|`));n.count=R9(e,s)??0,n.errorRate=R9(e,`errorRate`),n.p95=R9(e,`duration.p95`)}for(let e of i)o(zzi(e,t)).count=e.value;for(let e of r){let n=o(zzi(e,t));n.tokens=e.value,n.cost=e.estimatedCost??void 0}return a}function Hzi(e,t,n,r){let i=new Set(e.map(e=>e.key)),a=n.indexOf(`projectId`),o=n.indexOf(`provider`),s=[];for(let[e,n]of t){if(i.has(e)||!((n.count??0)>0||(n.tokens??0)>0))continue;let t=e.split(`|`);s.push({key:e,...a>=0?{projectId:t[a]??``}:{},...o>=0?{provider:t[o]??``}:{},name:t[t.length-1]??``,count:0,...r?{tokens:0}:{},...r&&n.cost!==void 0?{cost:0}:{}})}return[...e,...s]}function Uzi(e,t,n){let r=e[n];if(r===void 0)return{isNew:!1};let i=t?.[n];if(i===void 0)return{isNew:n===`count`||n===`tokens`||n===`cost`?r>0:!1};let a=r-i;return{delta:a,change:Wzi(n,a,i),isNew:!1}}function Wzi(e,t,n){return e===`errorRate`?t:n>0?t/n:void 0}function Gzi(e,t){if(e.delta!==void 0&&e.delta!==0)return e.delta>0==(t===`count`)?`good`:`bad`}var Kzi=[`mastra_model_total_input_tokens`,`mastra_model_total_output_tokens`];function z9({groupBy:e,filters:t,window:n,measure:r=`tokens`,enabled:i=!0}){let a=Y(),{filters:o,filterKey:s}=N9();return b_({queryKey:[`metrics`,`cost-breakdown`,r,e,t,s,n.start.toISOString(),n.end.toISOString()],staleTime:1/0,enabled:i,queryFn:()=>a.getMetricBreakdown({name:r===`tokens`?Kzi:[`mastra_model_total_input_tokens`],groupBy:e,aggregation:r===`tokens`?`sum`:`count`,orderDirection:`DESC`,limit:1e3,filters:{...o,...t,timestamp:n}})})}function qzi({start:e,end:t}){return{start:new Date(2*e.getTime()-t.getTime()),end:new Date(e.getTime())}}var Jzi=[`count`,`errorRate`,`p95`,`tokens`,`cost`],Yzi=e=>Jzi.includes(e),Xzi=e=>Ozi(e)?`Spans`:`Traces`,Zzi=`A trace is one end-to-end request, with every step it took.`,Qzi=`A span is one step inside a trace, such as a tool call or a model call. One trace can have many.`,$zi=e=>Ozi(e)?Qzi:Zzi,eBi={errorRate:`Errors`,p95:`P95 latency`,tokens:`Tokens`,cost:`Cost`},tBi=e=>e.toLocaleString(`en-US`,{month:`short`,day:`numeric`,hour:`numeric`,minute:`2-digit`}),nBi=({start:e,end:t})=>`${tBi(e)} – ${tBi(t)}`;function rBi(e,t){return{summary:`Change in ${t.toLowerCase()} from the previous range of the same length. Sort by another column to compare that instead.`,current:`Selected: ${nBi(e)}`,previous:`Previous: ${nBi(qzi(e))}`}}var iBi=(e,t)=>t&&e!==`projects`,aBi=(e,t)=>t===`count`?Xzi(e):eBi[t];function oBi({tab:e,built:t,previous:n,truncated:r,groupBy:i,usage:a}){return e===`threads`?t.filter(e=>e.name!==``):!n||r?t:Hzi(t,n,i,a)}function sBi(e,t,n){return e===`projects`?n?.(t.key)??t.key:t.name?t.name:e===`environments`?`No environment`:e===`models`?`Unknown model`:`Unnamed`}var cBi=(e,t)=>e===`projects`?t.key:t.projectId;function lBi(e,t){let n=cBi(e,t),r=n?{projectId:n}:{};return wzi(e)?{...r,span:{spanTypes:Czi[e],entityName:t.name}}:e===`environments`?t.name?{...r,environment:t.name}:r:e===`threads`?{...r,threadId:t.name}:e===`models`&&t.name?{...r,model:t.name}:r}function uBi(e,t){return t&&t.toUpperCase()!==`USD`?`${k5(e)} ${t}`:j5(e)}function dBi(e,t){if(e.isNew)return`New`;if(e.change===void 0)return`—`;if(e.change===0)return t===`errorRate`?`0 pt`:`0%`;let n=e.change>0?`+`:`−`,r=Math.abs(e.change);return t===`errorRate`?r<5e-4?`${n}<0.1 pt`:`${n}${(r*100).toFixed(1)} pt`:`${n}${A5(r)}`}function fBi(e){let t=qzi(e.window);return{...e,window:t,timeRange:tzi(t)}}var pBi={good:`text-badge-green-foreground`,bad:`text-badge-red-foreground`};function mBi({trend:e,children:t}){return t===void 0?(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:`—`}):(0,G.jsx)(`span`,{className:e?pBi[e]:`text-muted-foreground`,children:t})}function hBi({change:e,metric:t}){return e?(0,G.jsx)(mBi,{trend:Gzi(e,t),children:dBi(e,t)}):(0,G.jsx)(mBi,{trend:void 0})}function gBi({window:e,label:t}){let{summary:n,current:r,previous:i}=rBi(e,t);return(0,G.jsxs)(`span`,{className:`grid gap-1`,children:[(0,G.jsx)(`span`,{children:n}),(0,G.jsx)(`span`,{className:`tabular-nums`,children:r}),(0,G.jsx)(`span`,{className:`tabular-nums`,children:i})]})}function _Bi(){return(0,G.jsx)(`span`,{title:`No price for this model`,children:`Not priced`})}function vBi({row:e}){return e.cost===void 0?e.tokens?(0,G.jsx)(_Bi,{}):`—`:uBi(e.cost,e.costUnit)}function B9({muted:e=!1,children:t}){return(0,G.jsx)(T,{as:`span`,variant:`body-sm`,tone:e?`muted`:void 0,className:`tabular-nums`,children:t})}function yBi({mark:e,title:t,model:n}){return(0,G.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[e,(0,G.jsx)(`span`,{className:`truncate`,title:t,children:n?(0,G.jsx)(Sdi,{parts:MQn(n.name,n.provider)}):t})]})}var bBi=e=>(0,G.jsxs)(`svg`,{width:`19.125`,height:`18`,viewBox:`-1.0625 -1 19.125 18`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,...e,children:[(0,G.jsx)(`path`,{d:`M4.31445 3.16083C3.78402 3.16083 3.27531 3.37154 2.90024 3.74661C2.52517 4.12169 2.31445 4.63039 2.31445 5.16083V5.66083C2.31445 6.19126 2.52517 6.69997 2.90024 7.07504C3.27531 7.45011 3.78402 7.66083 4.31445 7.66083C4.84489 7.66083 5.35359 7.45011 5.72867 7.07504C6.10374 6.69997 6.31445 6.19126 6.31445 5.66083V5.16083C6.31445 4.63039 6.10374 4.12169 5.72867 3.74661C5.35359 3.37154 4.84489 3.16083 4.31445 3.16083Z`,fill:`currentColor`}),(0,G.jsx)(`path`,{d:`M6.76666 9.50235C6.57678 9.28532 6.30244 9.16083 6.01407 9.16083H4.50201C4.10791 9.16078 3.71766 9.23838 3.35356 9.38921C3.11733 9.48706 2.8951 9.6145 2.69205 9.76806C2.48056 9.928 2.38001 10.1888 2.38001 10.454V13.0642C2.38001 13.6165 2.82773 14.0642 3.38001 14.0642H8.55436C9.4135 14.0642 9.87269 13.0523 9.30695 12.4057L6.76666 9.50235Z`,fill:`currentColor`}),(0,G.jsx)(`path`,{fillRule:`evenodd`,clipRule:`evenodd`,d:`M12.0686 2.26107C12.0686 2.17635 11.9999 2.10767 11.9152 2.10767H10.9948C10.91 2.10767 10.8414 2.17635 10.8414 2.26107V3.85184C10.8414 3.95606 10.7397 4.02994 10.6406 3.99773L9.12775 3.50619C9.04718 3.48001 8.96063 3.52411 8.93445 3.60468L8.65003 4.48004C8.62385 4.56062 8.66795 4.64716 8.74852 4.67334L10.2611 5.1648C10.3602 5.19701 10.399 5.31655 10.3378 5.40086L9.40289 6.68765C9.35309 6.75619 9.36829 6.85212 9.43683 6.90192L10.1815 7.44292C10.25 7.49272 10.3459 7.47752 10.3957 7.40898L11.3309 6.12181C11.3922 6.03749 11.5179 6.03749 11.5791 6.12181L12.5143 7.40904C12.5641 7.47758 12.6601 7.49278 12.7286 7.44298L13.4732 6.90198C13.5418 6.85218 13.557 6.75625 13.5072 6.68771L12.5723 5.40091C12.511 5.3166 12.5499 5.19705 12.649 5.16485L14.1615 4.67338C14.2421 4.6472 14.2862 4.56066 14.26 4.48009L13.9756 3.60473C13.9494 3.52415 13.8629 3.48006 13.7823 3.50624L12.2694 3.99782C12.1703 4.03003 12.0686 3.95615 12.0686 3.85193V2.26107Z`,fill:`currentColor`})]}),xBi={agent:WP,workflow:KS,tool:ZP},SBi={agents:`agent`,workflows:`workflow`,tools:`tool`};function CBi({entity:e}){let t=xBi[e];return(0,G.jsx)(PQn,{icon:(0,G.jsx)(t,{className:`size-3`})})}function wBi({provider:e}){return e?(0,G.jsx)(FQn,{provider:e}):(0,G.jsx)(PQn,{icon:(0,G.jsx)(bBi,{className:`size-icon-xs`})})}function TBi({tab:e,row:t}){let n=SBi[e];return n?(0,G.jsx)(CBi,{entity:n}):e===`models`?(0,G.jsx)(wBi,{provider:t.provider}):null}function EBi({tab:e,row:t}){let{projectLabel:n}=pzi();return(0,G.jsx)(yBi,{mark:(0,G.jsx)(TBi,{tab:e,row:t}),title:sBi(e,t,n),model:e===`models`&&t.name!==``?{name:t.name,provider:t.provider}:void 0})}function DBi({text:e}){return(0,G.jsx)(T,{as:`span`,variant:`body-sm`,tone:`muted`,className:`truncate`,title:e,children:e})}var OBi={asc:bN,desc:yN},kBi=`focus-visible:outline-1 focus-visible:outline-solid focus-visible:outline-border-focus focus-visible:-outline-offset-1`,ABi=`cursor-help underline decoration-dotted decoration-placeholder/45 underline-offset-4 transition-[text-decoration-color] duration-150 group-hover/header:decoration-placeholder group-focus-visible/header:decoration-placeholder`;function jBi({header:e,explained:t,sorted:n,className:r,...i}){let a=n&&OBi[n];return(0,G.jsxs)(`button`,{type:`button`,...i,className:c(`group/header flex items-center gap-1 rounded whitespace-nowrap hover:text-muted-foreground`,kBi,r),children:[(0,G.jsx)(`span`,{className:c(t&&ABi),children:e}),a&&(0,G.jsx)(a,{"aria-hidden":!0,className:`size-3`})]})}function MBi({header:e,explained:t,className:n,...r}){return(0,G.jsx)(`span`,{tabIndex:t?0:void 0,...r,className:c(`group/header rounded whitespace-nowrap`,kBi,n),children:(0,G.jsx)(`span`,{className:c(t&&ABi),children:e})})}function NBi({header:e,description:t,sorted:n,onSort:r}){let i=(0,W.useId)(),a=!!t,o=a?i:void 0,s=r?(0,G.jsx)(jBi,{header:e,explained:a,sorted:n,onClick:r,"aria-describedby":o}):(0,G.jsx)(MBi,{header:e,explained:a,"aria-describedby":o});return a?(0,G.jsxs)(mx,{children:[(0,G.jsx)(hx,{render:s}),(0,G.jsx)(gx,{id:i,keepMounted:!0,side:`top`,className:`max-w-72`,children:t})]}):s}var PBi=`isolate before:absolute before:inset-x-0 before:-top-px before:bottom-0 before:-z-10 before:rounded hover:before:bg-fill-subtle after:absolute after:inset-x-0 after:bottom-0 after:h-px after:bg-border last:after:hidden after:[mask-image:linear-gradient(to_right,transparent,black_6px,black_calc(100%-6px),transparent)] hover:after:[mask-image:linear-gradient(to_right,transparent,black_24px,black_calc(100%-24px),transparent)] [&:has(+:hover)]:after:[mask-image:linear-gradient(to_right,transparent,black_24px,black_calc(100%-24px),transparent)]`,FBi=`pt-1.75 pb-2 text-body-sm`,IBi=c(`relative col-span-full grid grid-cols-subgrid items-center px-3`,FBi,PBi),LBi=[`w-32`,`w-24`,`w-36`,`w-20`,`w-28`],RBi=`a, button, input, select, textarea, label, [role="button"], [role="link"], [contenteditable]`;function zBi(e){if(!(e.target instanceof Element))return!1;let t=e.target.closest(RBi);return!!(t&&e.currentTarget.contains(t))}function BBi(e,t,n){return e.align===`end`?`right-0 w-10`:t>0?`left-0 w-16`:c(`left-0`,LBi[n%LBi.length])}function VBi({columns:e,rows:t,getRowKey:n,empty:r,pageSize:i,isLoading:a,...o}){return a?Array.from({length:i??5},(t,n)=>(0,G.jsx)(UBi,{columns:e,rowIndex:n},n)):t.length===0?i?r===void 0?(0,G.jsx)(HBi,{count:i}):(0,G.jsxs)(`div`,{role:`row`,className:`col-span-full grid *:col-start-1 *:row-start-1`,children:[(0,G.jsx)(HBi,{count:i}),(0,G.jsx)(`p`,{role:`cell`,className:`flex items-center justify-center px-3 py-4 text-center text-body-sm text-muted-foreground`,children:r})]}):r===void 0?null:(0,G.jsx)(`div`,{role:`row`,className:`col-span-full`,children:(0,G.jsx)(`p`,{role:`cell`,className:`py-8 text-center text-body-sm text-muted-foreground`,children:r})}):t.map(t=>(0,G.jsx)(WBi,{row:t,columns:e,...o},n(t)))}function HBi({count:e}){return e<=0?null:(0,G.jsx)(`div`,{"aria-hidden":!0,"data-slot":`metrics-table-filler`,className:`col-span-full`,children:Array.from({length:e},(e,t)=>(0,G.jsx)(`div`,{className:FBi,children:`​`},t))})}function UBi({columns:e,rowIndex:t}){return(0,G.jsx)(`div`,{role:`row`,"aria-busy":!0,className:IBi,children:e.map((e,n)=>(0,G.jsxs)(`div`,{role:`cell`,className:c(`relative flex min-w-0`,e.align===`end`&&`justify-end`),children:[`​`,(0,G.jsx)(PS,{className:c(`absolute top-1/2 h-3.5 -translate-y-1/2`,BBi(e,n,t))})]},e.id))})}function WBi({row:e,columns:t,onRowClick:n,onRowHover:r,isRowDimmed:i,isRowActive:a,rowTitle:o}){let s=a?.(e)??!1,l=i?.(e)??!1;return(0,G.jsx)(`div`,{role:`row`,"aria-current":s||void 0,tabIndex:n?0:void 0,title:o?.(e),onClick:n?t=>{zBi(t)||n?.(e)}:void 0,onKeyDown:n?t=>{t.target===t.currentTarget&&(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),n?.(e))}:void 0,onMouseEnter:r?()=>r(e):void 0,onMouseLeave:r?()=>r(void 0):void 0,className:c(IBi,`rounded text-foreground transition-opacity duration-150`,n&&c(`cursor-pointer`,`focus-visible:outline-1 focus-visible:outline-solid focus-visible:outline-border-focus focus-visible:-outline-offset-1`),s&&`before:bg-fill-subtle`,l&&`opacity-40`),children:t.map(t=>(0,G.jsx)(`div`,{role:`cell`,className:c(`flex min-w-0 items-center`,t.align===`end`&&`justify-end text-right`),children:t.cell(e)},t.id))})}var GBi=`after:absolute after:inset-x-0 after:bottom-0 after:h-px after:bg-border after:[mask-image:linear-gradient(to_right,transparent,black_6px,black_calc(100%-6px),transparent)] [&:has(+:hover)]:after:[mask-image:linear-gradient(to_right,transparent,black_24px,black_calc(100%-24px),transparent)]`,KBi={asc:`ascending`,desc:`descending`};function qBi(e,t){let n=t.firstDirection??`desc`;if(e?.column!==t.id)return{column:t.id,direction:n};if(e.direction===n)return{column:t.id,direction:n===`desc`?`asc`:`desc`}}function JBi(e,t){return typeof e==`number`&&typeof t==`number`?e-t:String(e).localeCompare(String(t))}function YBi(e,t,n){let r=t.find(e=>e.id===n?.column)?.sortValue;if(!n||!r)return e;let i=n.direction===`desc`?-1:1;return e.toSorted((e,t)=>{let n=r(e),a=r(t);return n===void 0&&a===void 0?0:n===void 0?1:a===void 0?-1:i*JBi(n,a)})}var XBi=e=>e.width??(e.align===`end`?`minmax(max-content,1fr)`:`max-content`);function ZBi({columns:e,rows:t,getRowKey:n,sort:r,defaultSort:i,onSortChange:a,onRowClick:o,onRowHover:s,isRowDimmed:l,isRowActive:u,rowTitle:d,empty:f,pageSize:p,isLoading:m=!1,"aria-label":h,className:g}){let[_,v]=(0,W.useState)(i),[y,b]=(0,W.useState)(0),x=r??_,S=YBi(t,e,x),C=p?Math.ceil(S.length/p):1,w=Math.min(y,Math.max(0,C-1)),T=p?S.slice(w*p,(w+1)*p):S,E={gridTemplateColumns:e.map(XBi).join(` `)},D=!m&&C>1,O=e=>{let t=qBi(x,e)??i;v(t),b(0),a?.(t)};return(0,G.jsxs)(`div`,{className:c(`grid min-w-0 gap-3`,g),children:[(0,G.jsxs)(AS,{orientation:`horizontal`,children:[(0,G.jsxs)(`div`,{role:`table`,"aria-label":h,className:`grid min-w-min gap-x-4`,style:E,children:[(0,G.jsx)(`div`,{role:`row`,className:c(`relative col-span-full grid grid-cols-subgrid items-end px-3 pb-1.5 text-label text-muted-foreground`,GBi),children:e.map(e=>{let t=x?.column===e.id?x.direction:void 0;return(0,G.jsx)(`div`,{role:`columnheader`,"aria-sort":t&&KBi[t],className:c(`flex min-w-0 items-center gap-1`,e.align===`end`&&`justify-end text-right`),children:(0,G.jsx)(NBi,{header:e.header,description:e.description,sorted:t,onSort:e.sortValue?()=>O(e):void 0})},e.id)})}),(0,G.jsx)(VBi,{columns:e,rows:T,getRowKey:n,onRowClick:o,onRowHover:s,isRowDimmed:l,isRowActive:u,rowTitle:d,empty:f,pageSize:p,isLoading:m})]}),p!==void 0&&!m&&T.length>0&&(0,G.jsx)(HBi,{count:p-T.length})]}),D&&(0,G.jsx)(gar,{page:w,pageCount:C,onPageChange:b})]})}var QBi=10,$Bi={column:`count`,direction:`desc`},eVi={projects:`Project`,agents:`Agent`,workflows:`Workflow`,tools:`Tool`,models:`Model`,threads:`Thread`,environments:`Environment`},tVi={projects:`No traces in this range.`,agents:`No agent runs in this range.`,workflows:`No workflow runs in this range.`,tools:`No tool calls in this range.`,models:`No model usage in this range.`,threads:`No traces with a thread in this range.`,environments:`No traces in this range.`};function nVi({tab:e,groupBy:t,window:n,aggregate:r,totals:i,spans:a,resources:o,previousAggregate:s,previousUsage:c,previousSpans:l,limit:u,...d}){let f=pzi(),[p,m]=(0,W.useState)($Bi),[h,g]=(0,W.useState)(`count`),_=(e=$Bi)=>{m(e),Yzi(e.column)&&g(e.column)},v=[r,i,a].filter(e=>e!==void 0),y=v.some(e=>e.isLoading);if(!v.some(e=>e.isFetching)&&v.some(e=>e.isError))return(0,G.jsx)(Szi,{...d,tab:e,children:(0,G.jsx)(O9,{onRetry:()=>v.forEach(e=>e.isError&&void e.refetch())})});let b=Dzi(e),x=i!==void 0,S=iBi(e,d.byProject),C=r?.data?.truncated===!0,w=y?[]:Bzi({tab:e,groupBy:t,aggregateRows:r?.data?.rows,usageGroups:i?.data?.groups,spanGroups:a?.data?.groups,resources:o?.data?Fzi(o.data.rows):void 0}),E=[s,c,l].every(e=>!e||!e.isLoading&&!e.isError)&&!y?Vzi({tab:e,groupBy:t,aggregateRows:s?.data?.rows,usageGroups:c?.data?.groups,spanGroups:l?.data?.groups}):void 0,D=oBi({tab:e,built:w,previous:E,truncated:C,groupBy:t,usage:x}),O=Xzi(e),k=e=>E?Uzi(e,E.get(e.key),h):void 0,A=e=>e.projectId?f.projectLabel?.(e.projectId)??e.projectId:`—`,j={id:`name`,header:eVi[e],width:`minmax(12rem,3fr)`,cell:t=>(0,G.jsx)(EBi,{tab:e,row:t})},M={id:`project`,header:`Project`,width:`minmax(8rem,2fr)`,cell:e=>(0,G.jsx)(DBi,{text:A(e)})},N={id:`resource`,header:`Resource`,width:`minmax(6rem,1fr)`,cell:e=>(0,G.jsx)(DBi,{text:e.resource??`—`})},P=[{id:`errorRate`,header:`Errors`,align:`end`,sortValue:e=>e.errorRate,cell:e=>(0,G.jsx)(B9,{muted:!0,children:e.errorRate===void 0?`—`:A5(e.errorRate)})},{id:`p95`,header:`P95 latency`,align:`end`,sortValue:e=>e.p95,cell:e=>(0,G.jsx)(B9,{muted:!0,children:e.p95===void 0?`—`:tsi(e.p95)})}],F=[{id:`tokens`,header:`Tokens`,align:`end`,sortValue:e=>e.tokens,cell:e=>(0,G.jsx)(B9,{muted:!0,children:e.tokens===void 0?`—`:k5(e.tokens)})},{id:`cost`,header:`Cost`,align:`end`,sortValue:e=>e.cost,cell:e=>(0,G.jsx)(B9,{muted:!0,children:(0,G.jsx)(vBi,{row:e})})}],I={id:`count`,header:O,align:`end`,description:$zi(e),sortValue:e=>e.count,cell:e=>(0,G.jsx)(B9,{children:k5(e.count)})},L={id:`change`,header:`% Change`,align:`end`,description:(0,G.jsx)(gBi,{window:n,label:aBi(e,h)}),sortValue:e=>k(e)?.change,cell:e=>(0,G.jsx)(B9,{children:(0,G.jsx)(hBi,{change:k(e),metric:h})})},R=[j,...S?[M]:[],...e===`threads`?[N]:[],...b?P:[],...x?F:[],I,L];return(0,G.jsx)(Szi,{...d,tab:e,isUpdating:r?.isPlaceholderData,children:(0,G.jsxs)(E9,{children:[(0,G.jsx)(ZBi,{"aria-label":`${eVi[e]} breakdown`,columns:R,rows:D,getRowKey:e=>e.key,sort:p,defaultSort:$Bi,onSortChange:_,onRowClick:d.onRowClick&&(t=>d.onRowClick?.(lBi(e,t))),pageSize:QBi,isLoading:y,empty:tVi[e]},e),!y&&C&&(0,G.jsxs)(T,{variant:`caption`,tone:`muted`,className:`pt-2`,children:[`Showing the `,k5(u),` busiest; sorting covers only these.`]})]})})}var rVi={entityType:`agent`};function iVi({tab:e,scope:t,...n}){let r=I9(e,n.byProject),i=Ezi(e),a=fBi(t),o=yzi(Lzi(e,t,n.byProject)),s=yzi(Lzi(e,a,n.byProject),{priority:vIi.last}),c=z9({groupBy:r,filters:rVi,window:t.window,enabled:i}),l=z9({groupBy:r,filters:rVi,window:a.window,enabled:i});return(0,G.jsx)(nVi,{...n,tab:e,groupBy:r,window:t.window,aggregate:o,totals:i?c:void 0,previousAggregate:s,previousUsage:i?l:void 0,limit:L9.span})}function aVi(e){let t=I9(`models`,e.byProject),{timestamp:n}=N9(),r=qzi(n),i=z9({groupBy:t,window:n}),a=z9({groupBy:t,window:n,measure:`modelSpans`}),o=z9({groupBy:t,window:r}),s=z9({groupBy:t,window:r,measure:`modelSpans`});return(0,G.jsx)(nVi,{...e,tab:`models`,groupBy:t,window:n,totals:i,spans:a,previousUsage:o,previousSpans:s,limit:L9.trace})}function oVi({tab:e,scope:t,...n}){let r=I9(e,n.byProject),i=fBi(t),a=F9(Nzi(e,t,n.byProject)),o=F9(Nzi(e,i,n.byProject),{priority:vIi.last}),s=F9(Pzi(t),{enabled:e===`threads`&&n.byProject}),c=z9({groupBy:r,window:t.window}),l=n.byProject?s:a,u=z9({groupBy:r,window:i.window});return(0,G.jsx)(nVi,{...n,tab:e,groupBy:r,window:t.window,aggregate:a,totals:c,resources:e===`threads`?l:void 0,previousAggregate:o,previousUsage:u,limit:L9.trace})}var sVi={serviceName:`service`,requestId:`request ID`,experimentId:`experiment`,tags:`tags`,provider:`provider`,model:`model`};function cVi({tab:e,traceGate:t,spanGate:n,...r}){if(e===`models`)return(0,G.jsx)(aVi,{...r},e);let i=wzi(e)?n:t;return i.status===`unsupported-filter`?(0,G.jsx)(Szi,{...r,tab:e,children:(0,G.jsx)(T9.NoData,{message:`Not available with a ${i.unsupportedFields.map(e=>sVi[e]??e).join(` or `)} filter.`})}):wzi(e)?n.status===`ready`&&(0,G.jsx)(iVi,{...r,tab:e,scope:n.scope},e):t.status===`ready`&&(0,G.jsx)(oVi,{...r,tab:e,scope:t.scope},e)}function lVi({chosen:e,traceScope:t,spanGate:n,...r}){let i=F9(kzi(t)).data?.rows.filter(e=>(e.measures.count??0)>0).length,a=e??uVi(i);return(0,G.jsx)(cVi,{...r,tab:a,traceGate:{status:`ready`,scope:t},spanGate:n})}function uVi(e){return e===void 0||e>=2?`projects`:`agents`}var dVi=[`projects`,`agents`,`workflows`,`tools`,`models`,`threads`,`environments`],fVi=dVi.filter(e=>e!==`projects`);function pVi({onRowClick:e}){let t=pzi().projectLabel!==void 0,n=izi(),r=vzi(),[i,a]=(0,W.useState)();if(n.status===`unavailable`||r.status===`unavailable`)return null;if(n.status===`loading`||r.status===`loading`)return(0,G.jsx)(D9,{title:bzi,bodyHeight:`fit`,children:(0,G.jsx)(T9.Loading,{})});let o={tabs:t?dVi:fVi,onTabChange:a,onRowClick:e,byProject:t};return t&&n.status===`ready`?(0,G.jsx)(lVi,{...o,chosen:i,traceScope:n.scope,spanGate:r}):(0,G.jsx)(cVi,{...o,tab:i??`agents`,traceGate:n,spanGate:r})}function mVi(){let{data:e,isLoading:t}=O7();if(t)return`loading`;let n=e?.capabilities;return n?.traceAggregate===!0&&n.spanAggregate===!0?`unified`:`legacy`}var V9=[AR(`/metrics`)],hVi=e=>e.fieldId===MLt;function gVi({fields:e}){let{filterTokens:t,setFilterTokens:n}=w9(),r=[hP,...cIi(t)];return(0,G.jsxs)(SP,{fields:[NLt,...e],operators:tIi,value:r,onValueChange:e=>n(lIi(e.filter(e=>!hVi(e)))),createItemId:e=>e,"aria-label":`Metrics filters`,className:`min-w-64 flex-1`,children:[(0,G.jsx)(SP.Chips,{renderChip:e=>hVi(e)?(0,G.jsx)(KIi,{}):(0,G.jsx)(SP.Chip,{item:e})}),(0,G.jsx)(SP.Input,{placeholder:`Filter metrics`})]})}function _Vi({children:e,filterFields:t}){return(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:V9}),actionRow:(0,G.jsx)(EP,{children:(0,G.jsx)(EP.Start,{children:(0,G.jsx)(gVi,{fields:t})})}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`Metrics`}),e]})}function vVi({error:e}){return JN(e)?(0,G.jsx)(vR,{}):YN(e)?(0,G.jsx)(_R,{resource:`metrics`}):(0,G.jsx)(Vx,{tone:`error`,titleSlot:`Failed to load storage capabilities`,descriptionSlot:e.message})}var yVi=sIi({availableTags:[],availableEntityNames:[],availableServiceNames:[],availableEnvironments:[]});function bVi({children:e}){let{supportsMetrics:t,isLoading:n,error:r}=F7();return n?(0,G.jsx)(_Vi,{filterFields:yVi,children:(0,G.jsxs)(`div`,{className:`flex h-full items-center justify-center gap-2`,children:[(0,G.jsx)(Mv,{"aria-label":`Loading storage capabilities`}),(0,G.jsx)(T,{as:`span`,variant:`caption`,tone:`muted`,children:`Loading storage capabilities`})]})}):r?(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:V9}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`Metrics`}),(0,G.jsx)(`div`,{className:`flex h-full items-center justify-center`,children:(0,G.jsx)(vVi,{error:r})})]}):t?e:(0,G.jsx)(_Vi,{filterFields:yVi,children:(0,G.jsx)(Vx,{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:(0,G.jsx)(X,{variant:`ghost`,render:(0,G.jsx)(`a`,{href:`https://mastra.ai/docs/observability/metrics/overview`,target:`_blank`,rel:`noopener noreferrer`}),icon:(0,G.jsx)(nF,{}),children:`Metrics documentation`}),variant:`fill`})})}function xVi(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 SVi(e,t,n,r,i,a,o){if(o){e.set(t,`custom`),e.set(n,o.from.toISOString()),e.set(r,o.to.toISOString());return}if(i===`custom`){e.set(t,`custom`),a?.from&&e.set(n,a.from.toISOString()),a?.to&&e.set(r,a.to.toISOString());return}let s=xVi(i);s&&e.set(t,s)}function H9(e,t,n){typeof n==`string`&&n.length>0&&e.set(t,n)}function CVi(e,t,n){if(Array.isArray(n)&&n.length!==0)for(let r of n)r&&e.append(t,r)}function wVi({spanTypes:e,entityName:t,status:n}){let r=[e.length===1?{id:`type`,fieldId:`spans.spanType`,value:e[0]??``}:{id:`type`,fieldId:`spans.spanType`,value:[...e],operatorId:`in`},{id:`entity`,fieldId:`spans.entityName`,value:t}];return n&&r.push({id:`status`,fieldId:`spans.status`,value:n}),{id:`metrics-span`,logic:`and`,nodes:r}}function TVi({preset:e,customRange:t,dashboardFilter:n,scope:r,tracesBasePath:i=`/traces`}){let a=new URLSearchParams;a.set(e5,`branches`),SVi(a,t5,n5,r5,e,t,r.window);let o=r.rootEntityType??n.rootEntityType;if(o&&a.set(yii,o),r.status&&a.set(bii,r.status),H9(a,i5.entityName,r.entityName??n.entityName),H9(a,i5.threadId,r.threadId??n.threadId),H9(a,i5.resourceId,r.resourceId??n.resourceId),H9(a,i5.runId,n.runId),H9(a,i5.sessionId,r.sessionId??n.sessionId),H9(a,i5.requestId,n.requestId),H9(a,i5.userId,r.userId??n.userId),H9(a,i5.organizationId,n.organizationId),H9(a,i5.experimentId,n.experimentId),H9(a,i5.serviceName,n.serviceName),H9(a,i5.environment,r.environment??n.environment),CVi(a,i5.tags,n.tags),r.span&&a.append(m5,JSON.stringify(wVi(r.span))),r.model){let e={id:`metrics-model`,logic:`and`,nodes:[{id:`model`,fieldId:`spans.model`,value:r.model}]};a.append(m5,JSON.stringify(e))}let s=a.toString();return s?`${i}?${s}`:i}function EVi({preset:e,customRange:t,dashboardFilter:n,scope:r,logsBasePath:i=`/logs`}){let a=new URLSearchParams;SVi(a,b7,x7,S7,e,t,r.window);let o=r.rootEntityType??n.rootEntityType;o&&a.set(y7,o),H9(a,C7.entityName,r.entityName??n.entityName),H9(a,C7.threadId,r.threadId??n.threadId),H9(a,C7.resourceId,r.resourceId??n.resourceId),H9(a,C7.runId,n.runId),H9(a,C7.sessionId,n.sessionId),H9(a,C7.requestId,n.requestId),H9(a,C7.userId,n.userId),H9(a,C7.organizationId,n.organizationId),H9(a,C7.experimentId,n.experimentId),H9(a,C7.serviceName,n.serviceName),H9(a,C7.environment,n.environment),CVi(a,C7.tags,n.tags),r.status===`error`&&a.append(C7.level,`error`);let s=a.toString();return s?`${i}?${s}`:i}function DVi(){let{datePreset:e,customRange:t,dimensionalFilter:n}=w9(),r=Cv(),i={preset:e,customRange:t,dashboardFilter:n};return{openTraces:(e={})=>{r(TVi({...i,scope:e}))},openLogs:(e={})=>{r(EVi({...i,scope:e}))}}}var OVi=`period`,kVi=`dateFrom`,AVi=`dateTo`;function jVi(){let[e,t]=Av(),n=e.get(OVi),r=FIi(n)?n:`24h`,i=(0,W.useMemo)(()=>{if(r!==`custom`)return;let t=e=>{if(!e)return;let t=new Date(e);return Number.isNaN(t.getTime())?void 0:t},n=t(e.get(kVi)),i=t(e.get(AVi));if(n||i)return{from:n,to:i}},[r,e.toString()]),a=(0,W.useMemo)(()=>uIi(e),[e.toString()]),o=(0,W.useCallback)(e=>{t(t=>{let n=new URLSearchParams(t);return e===`24h`?n.delete(OVi):n.set(OVi,e),e!==`custom`&&(n.delete(kVi),n.delete(AVi)),n},{replace:!0})},[t]),s=(0,W.useCallback)(e=>{t(t=>{let n=new URLSearchParams(t);return e?.from?n.set(kVi,e.from.toISOString()):n.delete(kVi),e?.to?n.set(AVi,e.to.toISOString()):n.delete(AVi),n},{replace:!0})},[t]),c=(0,W.useCallback)(e=>{t(t=>{let n=new URLSearchParams(t);return fIi(n,e),ZFi(n),n},{replace:!0})},[t]),l=(0,W.useRef)(!1);return(0,W.useEffect)(()=>{if(l.current||(l.current=!0,$Fi(e)))return;let n=QFi();n&&t(e=>{let t=new URLSearchParams(e);for(let[e,r]of n)t.append(e,r);return t},{replace:!0})},[]),(0,G.jsx)(BIi,{preset:r,filterTokens:a,onPresetChange:o,onFilterTokensChange:c,customRange:i,onCustomRangeChange:s,children:(0,G.jsx)(bVi,{children:(0,G.jsx)(MVi,{})})})}function MVi(){let{error:e}=kIi(N9()),{isInMemory:t}=F7(),{data:n}=jni(),{data:r}=q8(),{data:i}=kni(),{data:a}=J8(),o=sIi({availableTags:n??[],availableEntityNames:r??[],availableServiceNames:i??[],availableEnvironments:a??[]});return e&&JN(e)?(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:V9}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`Metrics`}),(0,G.jsx)(vR,{variant:`fill`})]}):e&&YN(e)?(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:V9}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`Metrics`}),(0,G.jsx)(_R,{variant:`fill`,resource:`metrics`})]}):e?(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:V9}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`Metrics`}),(0,G.jsx)(Vx,{tone:`error`,variant:`fill`,titleSlot:`Failed to load metrics`,descriptionSlot:e.message})]}):(0,G.jsx)(_Vi,{filterFields:o,children:(0,G.jsxs)(`div`,{className:`grid content-start gap-4`,children:[t&&(0,G.jsx)(mk,{variant:`info`,title:`Metrics are not persisted`,children:(0,G.jsx)(mk.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.`})}),(0,G.jsx)(NVi,{})]})})}function NVi(){let{openTraces:e,openLogs:t}=DVi(),n=Sp.AGENT,r=mVi(),i=(0,G.jsx)(zLi,{onTimeRangeClick:t=>e({rootEntityType:n,window:t}),onViewErrors:()=>t({rootEntityType:n,status:`error`}),onFailureTimeRangeClick:t=>e({rootEntityType:n,status:`error`,window:t})}),a=(0,G.jsx)(JLi,{onViewTraces:t=>e({rootEntityType:t}),onTimeRangeClick:t=>e({window:t})}),o=(0,G.jsx)(RRi,{onViewTraces:()=>e(),onAgentClick:t=>e({rootEntityType:n,entityName:t}),onModelClick:t=>e({model:t}),onThreadClick:t=>e({threadId:t})}),s=(0,G.jsx)(NLi,{onViewTraces:()=>e(),onTimeRangeClick:t=>e({window:t})});return r===`unified`?(0,G.jsxs)(`div`,{className:`grid content-start gap-4 pb-6`,children:[(0,G.jsxs)(k9,{columns:2,children:[(0,G.jsx)(k9.Item,{children:s}),(0,G.jsx)(k9.Item,{children:i}),(0,G.jsx)(k9.Item,{children:a}),(0,G.jsx)(k9.Item,{children:(0,G.jsx)(fzi,{onTimeRangeClick:e})})]}),(0,G.jsx)(pVi,{onRowClick:e})]}):(0,G.jsxs)(`div`,{className:`grid content-start gap-4 pb-6`,children:[s,(0,G.jsxs)(k9,{columns:2,children:[(0,G.jsx)(k9.Item,{children:i}),(0,G.jsx)(k9.Item,{children:a})]}),(0,G.jsxs)(k9,{columns:2,children:[(0,G.jsx)(k9.Item,{children:(0,G.jsx)(ARi,{onViewTraces:t=>e({rootEntityType:t}),onViewErrors:e=>t({rootEntityType:e,status:`error`}),onEntityClick:(t,n)=>e({rootEntityType:t,entityName:n})})}),(0,G.jsx)(k9.Item,{children:o})]}),(0,G.jsx)(YRi,{})]})}function PVi(){let{isCmsAvailable:e}=f8(),{paths:t}=on();return e?(0,G.jsx)(pQr,{href:t.cmsPromptBlockCreateLink(),tooltip:`Create a prompt`,children:`New prompt`}):null}var U9=[AR(`/prompts`)],FVi=50,IVi=[`updatedAt`];function LVi(){let{isCmsAvailable:e,isLoading:t}=f8(),n=!t&&e,[r,i]=(0,W.useState)(``),[a,o]=(0,W.useState)(0),[s,c]=Av(),{sort:l,onSortChange:u}=TI({searchParams:s,setSearchParams:c,allowedKeys:IVi}),{data:d,isLoading:f,error:p,isPlaceholderData:m}=F1r({page:a,perPage:FVi,orderBy:(0,W.useMemo)(()=>l?{field:l.key,direction:l.direction===`asc`?`ASC`:`DESC`}:void 0,[l])}),h=d?.promptBlocks??[],g=d?.hasMore??!1,_=(0,W.useCallback)(()=>{m||o(e=>e+1)},[m]),v=(0,W.useCallback)(()=>{m||o(e=>Math.max(0,e-1))},[m]),y=(0,W.useCallback)(e=>{i(e),o(0)},[]),b=(0,W.useCallback)((e,t)=>{u(e,t),o(0)},[u]);return p&&JN(p)?(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:U9}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`Prompts`}),(0,G.jsx)(vR,{variant:`fill`})]}):p&&YN(p)?(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:U9}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`Prompts`}),(0,G.jsx)(_R,{variant:`fill`,resource:`prompt blocks`})]}):p?(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:U9}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`Prompts`}),(0,G.jsx)(Vx,{tone:`error`,variant:`fill`,titleSlot:`Failed to load prompt blocks`,descriptionSlot:p.message})]}):h.length===0&&!f&&a===0?(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:U9}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`Prompts`}),(0,G.jsx)(G5r,{canCreate:n})]}):(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:U9}),headerActions:(0,G.jsx)(PVi,{}),actionRow:(0,G.jsx)(EP,{children:(0,G.jsx)(EP.Start,{children:(0,G.jsx)(`div`,{className:`max-w-120 flex-1`,children:(0,G.jsx)(CN,{...wN,onValueChange:y,label:`Search prompts`,placeholder:`Search by name or description`})})})}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`Prompts`}),(0,G.jsx)(q5r,{promptBlocks:h,isLoading:f,search:r,currentPage:a,hasMore:g,onNextPage:_,onPrevPage:v,updatedSort:l?.direction,onSortChange:b})]})}var RVi=H(`IconEarth`,()=>(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`path`,{d:`M21 12C21 16.9706 16.9706 21 12 21C7.02944 21 3 16.9706 3 12C3 7.02944 7.02944 3 12 3C16.9706 3 21 7.02944 21 12Z`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`}),(0,G.jsx)(`path`,{d:`M13.725 16.8649C14.4822 16.8649 15.1643 16.4076 15.4518 15.7071C15.7636 14.9477 15.5426 14.0737 14.9073 13.5537L13.5144 12.4136C13.1981 12.1547 12.8101 11.999 12.4026 11.9673L11.8411 11.9237C11.3675 11.8868 10.9057 12.0832 10.6037 12.4498C10.2249 12.9095 10.1641 13.5534 10.45 14.0759L11.4075 15.8252C11.7584 16.4663 12.431 16.8649 13.1619 16.8649H13.725Z`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`}),(0,G.jsx)(`path`,{d:`M4.17188 8.07009L6.08243 9.75205C6.85862 10.4354 8.04586 10.3426 8.70645 9.54695C8.9552 9.24735 9.29283 9.03467 9.67046 8.93967L11.8146 8.40028C12.5298 8.22035 13.088 7.66138 13.2669 6.94588L14.1264 3.50879`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`})]})),zVi=[AR(`/resources`)],BVi=[{title:`Mastra APIs`,description:`Explore and test the available REST API endpoints with the interactive Swagger UI.`,icon:RVi,href:`/swagger-ui`,external:!1},{title:`Documentation`,description:`Read the official Mastra documentation for guides, references, and tutorials.`,icon:Jtn,href:`https://mastra.ai/en/docs`,external:!0},{title:`Github`,description:`Browse the source code, report issues, and contribute to the Mastra project.`,icon:nF,href:`https://github.com/mastra-ai/mastra`,external:!0},{title:`Community`,description:`Join the Mastra Discord community for help, discussion, and collaboration.`,icon:PX,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:V7n,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:wKr,href:`https://mastra.ai/contact?ref=studio`,external:!0}];function VVi(){return(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:zVi}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`Resources`}),(0,G.jsx)(`div`,{children:(0,G.jsx)(`div`,{className:`grid max-w-3xl grid-cols-1 gap-4 sm:grid-cols-2`,children:BVi.map(e=>(0,G.jsxs)(`a`,{href:e.href,...e.external?{target:`_blank`,rel:`noreferrer`}:{},className:`group flex flex-col gap-3 rounded-lg border border-border bg-background state-layer p-5 hover:border-border-strong`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,G.jsx)(e.icon,{className:c(`h-5 w-5 text-muted-foreground group-hover:text-info-indicator`,A)}),(0,G.jsx)(T,{as:`span`,variant:`subheading`,tone:`ink`,children:e.title}),e.external&&(0,G.jsx)(nF,{className:`ml-auto size-icon-sm text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100`})]}),(0,G.jsx)(T,{variant:`caption`,tone:`muted`,children:e.description})]},e.href))})})]})}function HVi(){let{isCmsAvailable:e}=f8(),{paths:t}=on();return e?(0,G.jsx)(pQr,{href:t.cmsScorersCreateLink(),tooltip:`Create a scorer`,children:`New scorer`}):null}var W9=[AR(`/scorers`)];function UVi(){let{data:e={},isLoading:t,error:n}=ER(),[r,i]=(0,W.useState)(``),[a,o]=(0,W.useState)(`all`),[s,c]=(0,W.useState)();if(n&&JN(n))return(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:W9}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`Scorers`}),(0,G.jsx)(vR,{variant:`fill`})]});if(n&&YN(n))return(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:W9}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`Scorers`}),(0,G.jsx)(_R,{variant:`fill`,resource:`scorers`})]});if(n)return(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:W9}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`Scorers`}),(0,G.jsx)(Vx,{tone:`error`,variant:`fill`,titleSlot:`Failed to load scorers`,descriptionSlot:n.message})]});if(Object.keys(e).length===0&&!t)return(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:W9}),headerActions:(0,G.jsx)(HVi,{}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`Scorers`}),(0,G.jsx)(U$r,{})]});let l=a!==`all`||r!==``;return(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:W9}),headerActions:(0,G.jsx)(HVi,{}),actionRow:(0,G.jsx)(G$r,{search:r,onSearchChange:i,sourceFilter:a,onSourceFilterChange:o,onReset:()=>{i(``),o(`all`)},hasActiveFilters:l}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`Scorers`}),(0,G.jsx)(H$r,{scorers:e,isLoading:t,search:r,sourceFilter:a,sort:s,onSortChange:(e,t)=>c({key:t,direction:e})})]})}var WVi=[`input`,`entity`],GVi={input:`Input`,entity:`Entity`};function KVi(e){let 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 qVi(){let[e,t]=(0,W.useState)(new Set),n=(0,W.useMemo)(()=>new Set(WVi.filter(t=>!e.has(t))),[e]);return{visibleColumns:n,columns:(0,W.useMemo)(()=>KVi(n),[n]),toggleColumn:(0,W.useCallback)(e=>{t(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[])}}function JVi({visibleColumns:e,toggleColumn:t}){return(0,G.jsxs)(sO,{children:[(0,G.jsx)(sO.Trigger,{asChild:!0,children:(0,G.jsx)(X,{icon:(0,G.jsx)(wR,{}),children:`Columns`})}),(0,G.jsxs)(sO.Content,{align:`end`,children:[(0,G.jsx)(sO.Label,{children:`Toggle columns`}),WVi.map(n=>(0,G.jsx)(sO.CheckboxItem,{checked:e.has(n),onClick:()=>t(n),children:GVi[n]},n))]})]})}var YVi=[AR(`/scorers`),dnn],XVi=[`date`,`score`];function ZVi(){let{scorerId:e}=wv(),[t,n]=Av(),r=t.get(`scoreId`)??void 0,[i,a]=(0,W.useState)(r),[o,s]=(0,W.useState)(!1),c=Cv(),[l,u]=(0,W.useState)({value:`all`,label:`All Entities`,type:`ALL`}),{scorer:d,error:f}=dFt(e),p=qVi(),{data:m={},isLoading:h,error:g}=hN(),{isLoading:_,error:v}=WM({}),{sort:y,onSortChange:b}=TI({searchParams:t,setSearchParams:n,allowedKeys:XVi}),{data:x=[],isLoading:S,error:C,isFetchingNextPage:w,hasNextPage:T,setEndOfListElement:E}=uFt({scorerId:e,entityId:l?.value===`all`?void 0:l?.value,entityType:l?.type===`ALL`?void 0:l?.type}),D=(0,W.useMemo)(()=>P6(x,y,{date:e=>e.createdAt,score:e=>typeof e.score==`number`?e.score:void 0}),[x,y]),O=(0,W.useMemo)(()=>d?.agentIds?.filter(e=>m[e]).map(e=>({value:e,label:m[e].name,type:`AGENT`}))||[],[d?.agentIds,m]),k=(0,W.useMemo)(()=>d?.workflowIds?.map(e=>({value:e,label:e,type:`WORKFLOW`}))||[],[d?.workflowIds]),A=(0,W.useMemo)(()=>[{value:`all`,label:`All Entities`,type:`ALL`},...O,...k],[O,k]),j=t.get(`entity`)??`all`,M=A.find(e=>e.value===j);M&&M.value!==l?.value&&u(M),(0,W.useEffect)(()=>{if(f){let e=f instanceof Error?f.message:`Failed to load scorer`;Qx.error(`Error loading scorer: ${e}`)}},[f]),(0,W.useEffect)(()=>{if(g){let e=g instanceof Error?g.message:`Failed to load agents`;Qx.error(`Error loading agents: ${e}`)}},[g]),(0,W.useEffect)(()=>{if(v){let e=v instanceof Error?v.message:`Failed to load workflows`;Qx.error(`Error loading workflows: ${e}`)}},[v]);let N=e=>{e?.value&&n(t=>{let n=new URLSearchParams(t);return n.set(`entity`,e.value),n})};(0,W.useEffect)(()=>{let e=t.get(`scoreId`)??void 0;e!==i&&(e?D.find(t=>t.id===e)&&a(e):a(void 0))},[t,D]);let P=(0,W.useCallback)(e=>{a(e||void 0),n(t=>{let n=new URLSearchParams(t);return e?n.set(`scoreId`,e):n.delete(`scoreId`),n})},[n]);if(!d)return null;let F=JN(f)||JN(g)||JN(v),I=f&&YN(f),L=!F&&!I&&(f||g||v),R=!S&&D.length===0,z=l?.value!==`all`,B=d?.source===`stored`,ee=e?(0,G.jsx)(lSi,{open:o,onOpenChange:s,initialScorerIds:[e],onSuccess:e=>void c(`/experiments/${e}`)}):null,V=B?(0,G.jsxs)(sO,{children:[(0,G.jsx)(sO.Trigger,{asChild:!0,children:(0,G.jsx)(X,{size:`icon-lg`,"aria-label":`Scorer actions menu`,children:(0,G.jsx)(cO,{})})}),(0,G.jsx)(sO.Content,{align:`end`,className:`w-48`,children:(0,G.jsxs)(sO.Item,{onSelect:()=>void c(`/cms/scorers/${e}/edit`),children:[(0,G.jsx)(oP,{}),` Edit scorer`]})})]}):null;if(F||I||L||R&&!z){let t=(f instanceof Error?f.message:void 0)??(g instanceof Error?g.message:void 0)??(v instanceof Error?v.message:void 0)??`An unexpected error occurred`;return(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:YVi}),actionRow:!(F||I||L)&&V?(0,G.jsx)(EP,{children:(0,G.jsx)(EP.End,{children:V})}):void 0,children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:e}),(0,G.jsx)(`div`,{className:`flex h-full items-center justify-center`,children:F?(0,G.jsx)(vR,{}):I?(0,G.jsx)(_R,{resource:`scorers`}):L?(0,G.jsx)(Vx,{tone:`error`,titleSlot:`Failed to load scorer`,descriptionSlot:t}):(0,G.jsx)(R$r,{onRunExperiment:()=>s(!0)})}),ee]})}return(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:YVi}),actionRow:(0,G.jsxs)(EP,{children:[(0,G.jsx)(EP.Start,{children:(0,G.jsx)(z$r,{selectedEntity:l,entityOptions:A,onEntityChange:N,onReset:()=>{n(e=>{let t=new URLSearchParams(e);return t.set(`entity`,`all`),t})},isLoading:S||h||_})}),(0,G.jsxs)(EP.End,{children:[(0,G.jsx)(JVi,{visibleColumns:p.visibleColumns,toggleColumn:p.toggleColumn}),(0,G.jsx)(X,{variant:`primary`,onClick:()=>s(!0),icon:(0,G.jsx)(Fx,{}),children:`New experiment`}),V]})]}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:e}),(0,G.jsx)(L$r,{scores:D,isLoading:S,selectedScoreId:i,isFetchingNextPage:w,hasNextPage:T,setEndOfListElement:E,onScoreClick:P,errorMsg:C?.message,columnsState:p,sort:y,onSortChange:b}),ee]})}var QVi=H(`IconMoon`,()=>(0,G.jsx)(`path`,{d:`M20.9638 12.7674C19.8361 13.5447 18.4693 13.9998 16.9961 13.9998C13.1301 13.9998 9.99609 10.8657 9.99609 6.99975C9.99609 5.52667 10.4511 4.15987 11.2283 3.03223C6.61911 3.42277 3 7.28768 3 11.9979C3 16.9674 7.0286 20.996 11.9981 20.996C16.7084 20.996 20.5734 17.3767 20.9638 12.7674Z`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`})),$Vi=H(`IconSun`,()=>(0,G.jsx)(`path`,{d:`M12 3V2M12 22V21M18.3598 5.64005L19.0698 4.93005M4.93016 19.07L5.64016 18.36M21 12H22M2 12H3M18.3598 18.36L19.0698 19.07M4.93016 4.93005L5.64016 5.64005M15.5355 8.46447C17.4882 10.4171 17.4882 13.5829 15.5355 15.5355C13.5829 17.4882 10.4171 17.4882 8.46447 15.5355C6.51185 13.5829 6.51185 10.4171 8.46447 8.46447C10.4171 6.51185 13.5829 6.51185 15.5355 8.46447Z`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`})),eHi=[{value:`system`,label:`System`,icon:(0,G.jsx)(bYr,{})},{value:`light`,label:`Light`,icon:(0,G.jsx)($Vi,{})},{value:`dark`,label:`Dark`,icon:(0,G.jsx)(QVi,{})}];function tHi(e,t){if(e.some(e=>e.value===t))return t;let[n]=e;return n?n.value:`system`}var nHi=({value:e,onChange:t,options:n=eHi,size:r=`md`,"aria-label":i=`Theme`,...a})=>{let{theme:o,setTheme:s}=B(),c=e??o,l=t??s,u=tHi(n,c);return(0,G.jsx)(SPt,{...a,"aria-label":i,iconOnly:!0,size:r===`xs`?`sm`:r,value:u,onValueChange:l,children:n.map(e=>(0,G.jsx)(CPt,{value:e.value,"aria-label":e.label,children:e.icon},e.value))})};function rHi(e){return Object.fromEntries(e.filter(e=>e.name.trim()).map(e=>[e.name.trim(),e.value]))}function iHi(e,t){return e.baseUrl.trim()===t.baseUrl.trim()&&e.apiPrefix.trim()===(t.apiPrefix??``).trim()&&JSON.stringify(rHi(e.headers))===JSON.stringify(t.headers)}function aHi({initialConfig:e}){let{setConfig:t}=fS(),n=(0,W.useRef)(0),r=()=>({baseUrl:e.baseUrl,apiPrefix:e.apiPrefix??``,headers:Object.entries(e.headers).map(([e,t])=>({id:n.current++,name:e,value:t}))}),[i,a]=(0,W.useState)(r),[o,s]=(0,W.useState)(),c=!iHi(i,e),l=(0,G.jsx)(X,{type:`button`,size:`sm`,icon:(0,G.jsx)(Fx,{}),onClick:()=>a(e=>({...e,headers:[...e.headers,{id:n.current++,name:``,value:``}]})),children:`Add header`}),u=(e,t)=>a(n=>({...n,headers:n.headers.map(n=>n.id===e?{...n,...t}:n)}));function d(e){e.preventDefault(),i.baseUrl.trim()?(t({baseUrl:i.baseUrl.trim(),apiPrefix:i.apiPrefix.trim()||void 0,headers:rHi(i.headers)}),Qx.success(`Connection saved`)):s(`Enter the server URL`)}function f(){a(r()),s(void 0)}return(0,G.jsx)(`form`,{onSubmit:d,onReset:f,noValidate:!0,children:(0,G.jsxs)(VN,{children:[(0,G.jsx)(BN,{label:`Mastra instance URL`,description:`The server this studio talks to.`,errorMsg:o,children:(0,G.jsx)(Bj,{name:`url`,value:i.baseUrl,placeholder:`http://localhost:4111`,spellCheck:!1,onChange:e=>{a(t=>({...t,baseUrl:e.target.value})),s(void 0)}})}),(0,G.jsx)(BN,{label:`API prefix`,description:`Path in front of every API route.`,children:(0,G.jsx)(Bj,{name:`apiPrefix`,value:i.apiPrefix,placeholder:`/api (default)`,spellCheck:!1,onChange:e=>a(t=>({...t,apiPrefix:e.target.value}))})}),i.headers.length===0?(0,G.jsx)(WN,{action:l,children:`No request headers`}):(0,G.jsx)(PPt,{action:l,children:i.headers.length===1?`1 request header`:`${i.headers.length} request headers`}),i.headers.map(e=>(0,G.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,G.jsx)(Bj,{"aria-label":`Header name`,value:e.name,placeholder:`Authorization`,spellCheck:!1,onChange:t=>u(e.id,{name:t.target.value})}),(0,G.jsx)(Bj,{"aria-label":e.name?`Value of ${e.name}`:`Header value`,value:e.value,placeholder:`Bearer <token>`,spellCheck:!1,onChange:t=>u(e.id,{value:t.target.value})}),(0,G.jsx)(X,{type:`button`,size:`icon-md`,variant:`ghost`,"aria-label":e.name?`Remove ${e.name}`:`Remove header`,tooltip:`Remove header`,onClick:()=>a(t=>({...t,headers:t.headers.filter(t=>t.id!==e.id)})),children:(0,G.jsx)(Rj,{})})]},e.id)),c?(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,G.jsx)(`span`,{className:`text-body-sm text-muted-foreground`,children:`Unsaved changes`}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(X,{type:`reset`,size:`sm`,variant:`ghost`,children:`Discard`}),(0,G.jsx)(X,{type:`submit`,size:`sm`,variant:`primary`,children:`Save changes`})]})]}):null]})})}function oHi(){let{baseUrl:e,apiPrefix:t,headers:n}=fS(),r=JSON.stringify([e,t??``,n]);return(0,G.jsxs)(HN,{children:[(0,G.jsx)(UN,{info:`The Mastra instance the studio talks to, the path in front of its API routes, and the headers sent with every request.`,children:`Mastra connection`}),(0,G.jsx)(aHi,{initialConfig:{baseUrl:e,apiPrefix:t,headers:n}},r)]})}var sHi=()=>(0,G.jsxs)(NS,{variant:`settings`,title:`Settings`,children:[(0,G.jsxs)(HN,{children:[(0,G.jsx)(UN,{info:`Stored in this browser.`,children:`General`}),(0,G.jsx)(VN,{children:(0,G.jsx)(BN,{label:`Theme`,description:`Color scheme for the interface.`,children:(0,G.jsx)(nHi,{})})})]}),(0,G.jsx)(oHi,{})]});function cHi(){let[e]=Av(),t=Cv(),n=e.get(`redirect`)||`/`;return(0,G.jsx)(Zji,{redirectUri:n,onSuccess:()=>{n.startsWith(`http`)?window.location.href=n:t(n,{replace:!0})},initialMode:`signup`})}var lHi=[`traces`,`spans`],uHi={traces:{icon:(0,G.jsx)(kR,{}),label:`Traces`},spans:{icon:(0,G.jsx)(dG,{}),label:`Spans`},threads:{icon:(0,G.jsx)(lX,{}),label:`Threads`}};function dHi({current:e,views:t=lHi,onViewChange:n}){return(0,G.jsx)(`nav`,{"aria-label":`Observability views`,children:(0,G.jsx)(ck,{value:e,defaultTab:e,onValueChange:n,children:(0,G.jsx)(sk,{variant:`pill-ghost`,children:t.map(e=>(0,G.jsxs)(lk,{value:e,children:[(0,G.jsx)(vx,{size:`xs`,children:uHi[e].icon}),(0,G.jsx)(T,{variant:`caption`,className:`text-inherit`,children:uHi[e].label})]},e))})})})}function fHi(){return(0,G.jsxs)(`div`,{role:`status`,"aria-label":`Loading views`,className:`flex min-h-control-md items-center gap-0.5`,children:[(0,G.jsx)(PS,{className:`h-control-md w-20 rounded-full`}),(0,G.jsx)(PS,{className:`h-control-md w-20 rounded-full`})]})}function pHi({current:e,views:{views:t,isLoading:n,showSwitch:r},onViewChange:i,breadcrumbs:a,children:o}){let[s,c]=(0,W.useState)(null),l=jhi(),u;return n?u=(0,G.jsx)(fHi,{}):r&&(u=(0,G.jsx)(dHi,{current:e,views:t,onViewChange:i})),(0,G.jsx)(NS,{variant:`page`,breadcrumbs:a({current:e,isLoading:n,showSwitch:r}),actionRow:(u||l)&&(0,G.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center justify-between gap-3`,children:[u,(0,G.jsx)(`div`,{ref:c,className:`flex min-w-0 grow justify-end`})]}),children:(0,G.jsx)(R_i.Provider,{value:s??void 0,children:o})})}function mHi({isLoading:e,enabled:t,heading:n,title:r,description:i,children:a}){return t?a:(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:n}),e?(0,G.jsxs)(`div`,{className:`flex h-full items-center justify-center gap-2`,children:[(0,G.jsx)(Mv,{"aria-label":`Loading storage capabilities`}),(0,G.jsx)(T,{as:`span`,variant:`caption`,tone:`muted`,children:`Loading storage capabilities`})]}):(0,G.jsx)(Vx,{variant:`fill`,titleSlot:r,descriptionSlot:i})]})}function hHi({current:e,features:t}){let n=fvi(),r=pvi(),i=[`traces`];n.enabled&&t?.spanQuery===!0&&i.push(`spans`),r.enabled&&t?.threadQuery===!0&&i.push(`threads`);let a=n.isLoading||r.isLoading;return{views:i,isLoading:a,showSwitch:!a&&i.length>1&&i.includes(e)}}var gHi={refetchInterval:({state:e})=>ovi(e.error),refetchOnWindowFocus:!1};function _Hi(e){let[t,n]=(0,W.useState)(()=>new URLSearchParams);return e||{searchParams:t,setSearchParams:e=>n(t=>typeof e==`function`?e(t):e)}}function vHi(e,{sortFields:t,withTokenSearch:n=!1,defaultDatePreset:r=Ihi}={}){let{searchParams:i,setSearchParams:a}=_Hi(e),o=JSON.stringify(Hhi(i,r)),s=JSON.stringify(Whi(i)),{datePreset:c,dateFrom:l,dateTo:u}=(0,W.useMemo)(()=>Hhi(i,r),[o]),{tokens:d,groups:f}=(0,W.useMemo)(()=>{let e=Whi(i);return n?e:{...e,tokens:e.tokens.filter(e=>e.operatorId!==`hasAllTokens`)}},[s,n]),p=Khi(i,t??Phi),m=(0,W.useMemo)(()=>({field:p.field,direction:p.direction}),[p.field,p.direction]),h=l?.getTime(),g=u?.getTime(),_=(0,W.useMemo)(()=>{let e=new Date,t=Jai(c,h===void 0?void 0:new Date(h),g===void 0?void 0:new Date(g),e);return lii(t.dateFrom,t.dateTo,e)},[c,h,g]),v=(0,W.useRef)(null);(0,W.useLayoutEffect)(()=>{v.current=null},[i]);let y=e=>{let t=v.current??i,n=new URLSearchParams(t);e(n),n.toString()!==t.toString()&&(v.current=n,a(n,{replace:!0}))},b=e=>y(t=>Uhi(t,e(Hhi(t,r)),r)),x=(0,W.useRef)(void 0),S=e=>{x.current=void 0,b(e)},C=e=>S(t=>e===`custom`?{...t,datePreset:e}:{datePreset:e}),w=(e,t)=>S(n=>n.datePreset===`custom`?t===`from`?{...n,dateFrom:e}:{...n,dateTo:e}:n),T=(e,t)=>S(n=>n.datePreset===`custom`?{...n,dateFrom:e,dateTo:t}:n),E=(e,t)=>b(n=>(x.current=Shi(x.current,n,e,t),{datePreset:`custom`,dateFrom:e,dateTo:t})),D=e=>b(t=>{let n=Chi(x.current,t);return x.current=void 0,n??{datePreset:e}}),O=(e,t)=>y(n=>Ghi(n,{tokens:e,groups:t})),k=e=>y(t=>qhi(t,e)),A=d.length>0||f.length>0;return{datePreset:c,dateFrom:l,dateTo:u,timeRange:_,rolling:u===void 0,tokens:d,groups:f,sort:m,setSort:k,onDatePresetChange:C,onDateChange:w,onDateRangeChange:T,onZoom:E,onDateReset:D,onFiltersChange:O,contentFiltersApplied:A,filtersApplied:A||c!==r}}function yHi(e){return[`observability-list-head`,...e]}function bHi(e,t,n=!1){if(n)return{from:e.from,to:t};let r=Date.parse(e.to)-Date.parse(e.from);return{from:new Date(Date.parse(t)-r).toISOString(),to:t}}function xHi(e,t=!1){let n=l_([e]),[r,i]=(0,W.useState)();return{anchorWindow:r?.selectionHash===n?r.window:void 0,reanchor:e=>i({selectionHash:n,window:bHi(e,new Date().toISOString(),t)})}}var SHi=()=>({rows:[],watermark:void 0});function CHi({queryKey:e,fetchHead:t,getId:n,getEndedAt:r,enabled:i,since:a,limit:o=50,maxRows:s=500,interval:c=nvi,onOverflow:l}){let u=a_(),d=yHi(e),{data:f}=b_({queryKey:d,queryFn:async()=>{let e=u.getQueryData(d)??SHi(),i=await t(new Date().toISOString()),c=i.map(e=>Date.parse(r(e)??``)).filter(Number.isFinite),f=new Map(e.rows.map(e=>[n(e),e]));for(let e of i)f.set(n(e),e);let p=e.watermark??a;if(p!==void 0&&i.length>=o&&c.length>0&&Math.min(...c)>p||f.size>s)return l?.(),SHi();let m=c.length>0?Math.max(e.watermark??-1/0,...c):e.watermark;return{rows:[...f.values()],watermark:m}},initialData:SHi,staleTime:1/0,enabled:i,refetchInterval:e=>!ivi(e.state.error)&&c,refetchOnWindowFocus:!1,refetchOnReconnect:!1,retry:!1});return{headRows:f.rows}}function wHi(e,t){if(e===t)return!0;let n=e,r=t,i=Object.keys(n);return i.length===Object.keys(r).length&&i.every(e=>Object.is(n[e],r[e]))}function THi(e,t,n){if(t.length===0)return e;let{getId:r,compare:i,hasNextPage:a}=n,o=new Map(t.map(e=>[r(e),e])),s=!1,c=[];for(let t of e){let e=r(t),n=o.get(e);n===void 0?c.push(t):(o.delete(e),wHi(t,n)?c.push(t):i(t,n)===0?(c.push(n),s=!0):(o.set(e,n),s=!0))}let l=[...o.values()].sort(i);if(l.length===0)return s?c:e;let u=c[c.length-1],d=[],f=0;for(let e of l){if(a&&(u===void 0||i(e,u)>=0))break;for(let t=c[f];t!==void 0&&i(t,e)<=0;t=c[++f])d.push(t);d.push(e),s=!0}return d.push(...c.slice(f)),s?d:e}var EHi={traces:`Traces`,spans:`Spans`,threads:`Threads`};function DHi({current:e,isLoading:t,showSwitch:n}){if(!(t||n||e===`traces`))return EHi[e]}function OHi(e){let t=e.get(`traceId`),n=e.get(`spanId`);return t&&n?{traceId:t,spanId:n}:void 0}function kHi(e,t){let n=new URLSearchParams(e);return t?(n.set(`traceId`,t.traceId),n.set(`spanId`,t.spanId)):(n.delete(`traceId`),n.delete(`spanId`)),n}function AHi({traceId:e,spanId:t}){return new URLSearchParams({traceId:e,spanId:t})}function jHi(e){return e.get(`threadId`)??void 0}function MHi(e,t){let n=new URLSearchParams(e);return t?n.set(`threadId`,t):n.delete(`threadId`),n}var NHi=e=>`${e.traceId}:${e.spanId}`;function PHi(e){let{field:t=`startedAt`,direction:n=`desc`}=e?.[0]??{},r=n===`asc`?1:-1;return(e,n)=>{let i=e[t],a=n[t];if(i!==a){if(i==null)return 1;if(a==null)return-1;if(i<a)return-r;if(i>a)return r}return e.traceId.localeCompare(n.traceId)||e.spanId.localeCompare(n.spanId)}}function FHi({query:e,rolling:t,fixedStart:n=!1,autoRefetch:r=!0,limit:i,enabled:a=!0}){let o=Y(),{anchorWindow:s,reanchor:c}=xHi(e,n),l=(0,W.useMemo)(()=>s?{...e,timeRange:{...e.timeRange,...s}}:e,[e,s]),u=tri({query:l,limit:i,enabled:a,queryOptions:gHi}),{headRows:d}=CHi({queryKey:[`spans`,e],fetchHead:async t=>(await o.querySpans({...e,timeRange:{...e.timeRange,...bHi(e.timeRange,t,n)},orderBy:[{field:`endedAt`,direction:`desc`}],page:{limit:50}})).spans,getId:NHi,getEndedAt:e=>e.endedAt,since:Date.parse(l.timeRange.to),enabled:a&&t&&r&&u.spans!==void 0&&!u.isFetching&&!u.isError,onOverflow:()=>c(e.timeRange)}),{orderBy:f}=e,p=u.spans,m=(0,W.useMemo)(()=>p&&THi(p,d,{getId:NHi,compare:PHi(f),hasNextPage:u.hasNextPage}),[p,d,f,u.hasNextPage]);return{...u,spans:m}}function IHi(e){return{traceId:e.traceId,spanId:e.spanId,parentSpanId:e.parentSpanId,name:e.name,entityType:e.entityType,entityId:e.entityId,threadId:e.threadId,resourceId:e.resourceId,environment:e.environment,model:e.model,provider:e.provider,status:e.status,outcome:e.outcome,stopReason:e.stopReason,stopReasonContext:e.stopReasonContext,inputPreview:e.inputPreview,outputPreview:e.outputPreview??void 0,errorPreview:e.errorPreview??void 0,startedAt:e.startedAt,endedAt:e.endedAt,createdAt:e.startedAt,timeToFirstChunkMs:e.timeToFirstChunkMs,timeToFirstTokenMs:e.timeToFirstTokenMs}}function LHi({timeRange:e,where:t,onZoom:n}){let r=mvi(),i=(0,W.useMemo)(()=>({timeRange:e,...t?{where:t}:{},interval:soi(e).interval,measures:[...$ai],limit:1}),[e,t]),a=!r.enabled||coi(e),{data:o,isLoading:s,isError:c,isPlaceholderData:l}=Ini({request:i,enabled:!a,queryOptions:{placeholderData:f_}}),u=(0,W.useMemo)(()=>poi(o?.rows??[],e),[o,e]);return a?null:(0,G.jsx)(jci,{label:`Spans over time`,resourceLabel:`Spans`,buckets:u,isLoading:s,isError:c,isUpdating:l,onZoom:n&&(t=>n(moi(u,t,e)))})}var RHi=[`last-24h`,`last-3d`,`last-7d`,`last-14d`,`last-30d`,`custom`],zHi=[];function BHi({timeRange:e,withTokenSearch:t=!1}){let n=Y(),{data:r}=O7(),i=r?.capabilities.spanQueryContextFields??!1,a=r?.capabilities.traceQueryTimeToFirstChunk??!1,o=r?.capabilities.traceQueryTimeToFirstToken??!1,s=r?.capabilities.spanQueryOutcomeFields??!1,c=r?.capabilities.spanQueryModelFields??!1,{data:l=zHi}=q8(),{data:u=zHi}=J8();return(0,W.useMemo)(()=>[NLt,...hni(Dgi({withContextFields:i,withTimeToFirstChunk:a,withTimeToFirstToken:o,withOutcomeFields:s,withModelFields:c,entityNames:l,environments:u,valueSuggestions:t=>Uri(n,e,`spans`,t)}),t)],[t,i,a,o,s,c,l,u,n,e])}function VHi({tokens:e,groups:t,onFiltersChange:n}){let r=(0,W.useMemo)(()=>sai(e),[e]),i=(0,W.useMemo)(()=>{let e=uai([],t);return{...e,nodes:[hP,...r,...e.nodes]}},[r,t]),a=(0,W.useCallback)(e=>{let t=fai({...e,nodes:e.nodes.filter(e=>aP(e)||e.fieldId!==`timeRange`)});n(t.tokens,t.groups)},[n]);return{filterBarValue:i,onFilterBarChange:a,onFilterByField:(0,W.useCallback)((e,t)=>{let n=r.filter(t=>t.fieldId!==e),o={id:`${e}:${t}`,fieldId:e,operatorId:`is`,value:t},s=i.nodes.filter(aP);a({...i,nodes:[...n,o,...s]})},[r,i,a])}}var HHi=e=>e;function UHi({withTokenSearch:e=!1,datePreset:t,dateFrom:n,dateTo:r,minDate:i,timeRange:a,tokens:o,groups:s,onDatePresetChange:c,onDateChange:l,onDateRangeChange:u,onDateReset:d,onFiltersChange:f,describeSuggestionsError:p,disabled:m}){let h=BHi({timeRange:a,withTokenSearch:e}),{filterBarValue:g,onFilterBarChange:_}=VHi({tokens:o,groups:s,onFiltersChange:f});return(0,G.jsxs)(SP,{fields:h,operators:Fii,value:g,onValueChange:_,createItemId:HHi,describeSuggestionsError:p,maxDepth:3,"aria-label":`Span filters`,className:`min-w-64 flex-1`,children:[(0,G.jsx)(SP.Chips,{renderChip:e=>e.fieldId===`timeRange`?(0,G.jsx)(SP.TimeRange,{preset:t,onPresetChange:c,dateFrom:n,dateTo:r,minDate:i,onDateChange:l,onDateRangeChange:u,disabled:m,presets:RHi,defaultPreset:g5.datePreset,onReset:d&&(()=>d(g5.datePreset))}):(0,G.jsx)(SP.Chip,{item:e})}),(0,G.jsx)(SP.Input,{placeholder:`Filter spans`})]})}var WHi={supported:!1,isLoading:!1};function GHi(e){let t=k7(),n=fvi(),r=pvi();return e===`spans`?n:e===`threads`?r:t}var KHi=(0,W.memo)(function({scope:e,value:t,onChange:n,discoveryTimeRange:r,metricsSupport:i=WHi,queryEnabled:a=!0}){let o=V8[e],s=GHi(e),c=hvi(),{data:l}=O7(),[u]=(0,W.useState)(()=>lii(void 0,void 0,new Date)),d=s.enabled&&a,f=d&&(l?.capabilities.traceQueryTimeToFirstChunk??!1),p=d&&(l?.capabilities.traceQueryTimeToFirstToken??!1),m=(0,W.useMemo)(()=>{if(f&&p)return o;let e=o.standardColumns.filter(e=>(f||e!==`timeToFirstChunk`)&&(p||e!==`timeToFirstToken`));return{...o,standardColumns:e}},[o,f,p]),{fields:h}=Wri({timeRange:r??u,queryOptions:{enabled:o.metadata&&d&&c.enabled}}),g=(0,W.useMemo)(()=>{let e=new Set;for(let t of h){let n=t.path.replace(/^metadata\./,``).split(`.`)[0];n&&e.add(n)}return[...e].sort()},[h]),_=i.isLoading?goi:i.supported?void 0:_oi;return(0,G.jsx)(Boi,{preferences:t,catalog:m,availableMetadataKeys:g,usageDisabledReason:_,withQueryTrace:d,disabled:s.isLoading,onToggleColumn:e=>n(nni(t,e)),onAddCustomColumn:e=>n(rni(t,e)),onRemoveCustomColumn:e=>n(ini(t,e)),onAddMetadataColumn:e=>n(ani(t,e)),onRemoveMetadataColumn:e=>n(oni(t,e)),onReset:()=>n(o.defaults)})});function qHi({selection:e,onSelectionChange:t,renderPanel:n,urlState:r}){let{data:i,isLoading:a}=O7(),o=!!(i?.capabilities.spanQueryTokenSearch&&i.capabilities.spanAggregateTokenSearch),s=vHi(r,{sortFields:Fhi,withTokenSearch:o}),{timeRange:c,tokens:l,groups:u}=s,d=Z_i({scope:`spans`}),f=i?.capabilities.spanQueryContextFields??!1,p=i?.capabilities.traceQueryTimeToFirstChunk??!1,m=i?.capabilities.traceQueryTimeToFirstToken??!1,h=i?.capabilities.spanQueryOutcomeFields??!1,g=i?.capabilities.spanQueryModelFields??!1,_=(0,W.useMemo)(()=>a?d.preferences:tni(d.preferences,{withTimeToFirstChunk:p,withTimeToFirstToken:m}),[d.preferences,a,p,m]),v=(0,W.useMemo)(()=>{let e=[`startedAt`];return p&&i?.capabilities.traceQueryTimeToFirstChunkSort&&H8(_,`timeToFirstChunk`)&&e.push(`timeToFirstChunkMs`),m&&i?.capabilities.traceQueryTimeToFirstTokenSort&&H8(_,`timeToFirstToken`)&&e.push(`timeToFirstTokenMs`),e},[i,p,m,_]),y=v.includes(s.sort.field)?s.sort:{field:`startedAt`,direction:`desc`},{field:b,direction:x}=y,S=(0,W.useMemo)(()=>Agi(l,u,{withTokenSearch:o,withContextFields:f,withOutcomeFields:h,withModelFields:g,withTimeToFirstChunk:p,withTimeToFirstToken:m}),[l,u,o,f,h,g,p,m]),{spans:C,hasNextPage:w,isFetchingNextPage:T,setEndOfListElement:E,isLoading:D,isError:O,error:k}=FHi({query:(0,W.useMemo)(()=>({timeRange:c,orderBy:[{field:b,direction:x}],where:S}),[c,b,x,S]),enabled:!a,rolling:s.rolling,fixedStart:s.datePreset===`custom`}),A=(0,W.useMemo)(()=>(C??[]).map(IHi),[C]),j=(0,W.useMemo)(()=>A.flatMap(e=>e.spanId?[{traceId:e.traceId,spanId:e.spanId}]:[]),[A]),M=n=>{n.spanId&&t(e?.traceId===n.traceId&&e.spanId===n.spanId?void 0:{traceId:n.traceId,spanId:n.spanId})},N=!D&&!O&&A.length===0&&!s.contentFiltersApplied&&!e;return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`Spans`}),(0,G.jsx)(Foi,{toolbar:(0,G.jsxs)(G.Fragment,{children:[r&&(0,G.jsx)(K_i,{page:`spans`,...r,columns:d}),(0,G.jsxs)(EP,{children:[(0,G.jsx)(EP.Start,{children:(0,G.jsx)(UHi,{withTokenSearch:o,datePreset:s.datePreset,dateFrom:s.dateFrom,dateTo:s.dateTo,timeRange:c,tokens:l,groups:u,onDatePresetChange:s.onDatePresetChange,onDateChange:s.onDateChange,onDateRangeChange:s.onDateRangeChange,onDateReset:s.onDateReset,onFiltersChange:s.onFiltersChange,disabled:D})}),(0,G.jsx)(EP.End,{children:(0,G.jsx)(KHi,{scope:`spans`,value:d.preferences,onChange:d.setPreferences})})]})]}),chart:(0,G.jsx)(LHi,{timeRange:c,where:S,onZoom:({from:e,to:t})=>s.onZoom(e,t)}),error:O?(0,G.jsx)(B8,{error:k,resource:`spans`,errorTitle:`Failed to load spans`}):void 0,empty:N?(0,G.jsx)(Nti,{resource:`spans`,datePreset:s.datePreset,dateFrom:s.dateFrom,dateTo:s.dateTo}):void 0,children:(0,G.jsx)(rui,{listId:`all-spans`,traces:A,columnPreferences:_,isLoading:D,isFetchingNextPage:T,hasNextPage:w,setEndOfListElement:E,filtersApplied:s.filtersApplied,resource:`spans`,isBranchesMode:!0,sort:y,sortableFields:v,onSortChange:s.setSort,featuredTraceId:e?.traceId,featuredSpanId:e?.spanId,onTraceClick:M})}),n({selection:e,spans:j,onSelect:t,onClose:()=>t(void 0)})]})}function JHi({selection:e,spans:t,onSelect:n,onClose:r,onShowTrace:i}){let{data:a,isLoading:o}=Y8({traceId:e.traceId,spanId:e.spanId}),s=dbi(),c=t.findIndex(t=>t.traceId===e.traceId&&t.spanId===e.spanId),l=c>0?t[c-1]:void 0,u=c>=0&&c<t.length-1?t[c+1]:void 0;return(0,G.jsx)(fhi,{traceId:e.traceId,spanId:e.spanId,span:a?.span,isLoading:o,input:(0,G.jsx)(Dyi,{}),output:(0,G.jsx)(Oyi,{}),navigation:s,onPrevious:l?()=>n(l):void 0,onNext:u?()=>n(u):void 0,onClose:r,onShowTrace:i})}function YHi({selection:e,spans:t,onSelect:n,onClose:r,onShowTrace:i}){let a=Kw();iti(e?`${e.traceId}:${e.spanId}`:void 0,r);let o=e?(0,G.jsx)(JHi,{selection:e,spans:t,onSelect:n,onClose:r,onShowTrace:i}):null;return a?(0,G.jsx)(MN,{open:!!e,onClose:r,title:`Span details`,children:o}):o?(0,G.jsx)(F8,{owner:`span-detail`,children:(0,G.jsx)(MN,{variant:`inline`,title:`Span details`,children:o})}):null}function XHi(){let{enabled:e,isLoading:t}=fvi(),n=Cv(),[r,i]=Av();return(0,G.jsx)(mHi,{enabled:e,isLoading:t,heading:`Spans`,title:`Query spans capability not activated`,description:`Your observability storage does not support span queries. Switch to a store that declares the span-query capability to list spans.`,children:(0,G.jsx)(qHi,{urlState:{searchParams:r,setSearchParams:i},selection:OHi(r),onSelectionChange:e=>i(t=>kHi(t,e),{replace:!0}),renderPanel:e=>(0,G.jsx)(YHi,{...e,onShowTrace:e=>n(`/traces?${AHi(e)}`)})})})}async function ZHi(){let e=await fetch(`https://mastra.ai/api/templates.json`);if(!e.ok)throw Error(`Failed to fetch templates: ${e.statusText}`);let 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(e=>e.tags))),providers:Array.from(new Set(t.flatMap(e=>e.supportedProviders)))}}async function QHi({repo:e,owner:t}){let n=await fetch(`https://api.github.com/repos/${t}/${e}`);if(!n.ok)throw Error(`Failed to fetch template: ${n.statusText}`);let r=await n.json();if(!r.is_template)throw 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 $Hi({repoOrSlug:e,owner:t}){let{templates:n}=await ZHi(),r=n.find(t=>t.slug===e);if(!r){if(t===`mastra-ai`&&e.startsWith(`template-`)){let t=n.find(t=>`template-${t.slug}`===e);if(t)return t}let r=await QHi({repo:e,owner:t});if(r)return r;throw Error(`Template ${e} not found`)}return r}async function eUi({repo:e,owner:t,branch:n}){let r=`https://raw.githubusercontent.com/${t}/${e}/${n}/.env.example`,i=await fetch(r);return i.ok?(await i.text()).split(`
887
- `).reduce((e,t)=>{if(!t||t.startsWith(`#`))return e;let[n,r]=t.split(`=`);return n&&(e[n]=r?.split(``)?.every(e=>e===`*`)?``:r?.replaceAll(`"`,``)),e},{}):{}}var tUi=({queryOptions:e}={})=>b_({queryKey:[`mastra-templates`],queryFn:ZHi,...e}),nUi=({repoOrSlug:e,owner:t,queryOptions:n})=>b_({queryKey:[`template-repo`,e,t],queryFn:()=>$Hi({repoOrSlug:e,owner:t}),...n}),rUi=({repo:e,owner:t,branch:n,queryOptions:r})=>b_({queryKey:[`template-repo-env-vars`,e,t,n],queryFn:()=>eUi({repo:e,owner:t,branch:n}),...r}),iUi=({queryOptions:e}={})=>{let t=Y();return b_({queryKey:[`agent-builder-workflow`],queryFn:async()=>await t.getAgentBuilderAction(`merge-template`).details(),...e})},aUi=({queryOptions:e}={})=>{let t=Y();return S_({mutationFn:async({runId:e})=>await t.getAgentBuilderAction(`merge-template`).createRun({runId:e}),...e})},oUi=({queryOptions:e}={})=>{let t=Y();return S_({mutationFn:async({runId:e})=>await t.getAgentBuilderAction(`merge-template`).runById(e),...e})},sUi=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)},cUi=(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((e,t)=>(e[t]={id:t,description:n.allSteps[t].description,status:`pending`},e),{})}}),e.type===`start`||e.type===`workflow-start`){let t={};n?.allSteps&&Object.entries(n.allSteps).forEach(([e,n])=>{t[e]={id:n.id,description:n.description,status:`pending`}});let i=e.runId||e.payload?.runId;r={...r,runId:i,eventTimestamp:new Date().toISOString(),status:`running`,phase:`initializing`,payload:{workflowState:{status:`running`,steps:t},currentStep:null}}}if(e.type===`step-start`||e.type===`workflow-step-start`){let t=e.payload.id;r={...r,phase:`processing`,payload:{...r.payload,currentStep:{id:t,status:`running`,startTime:new Date,...e.payload},workflowState:{...r.payload.workflowState,steps:{...r.payload.workflowState.steps,[t]:{...r.payload.workflowState.steps[t],status:`running`,startTime:new Date,...e.payload}}}}}}if(e.type===`step-result`||e.type===`workflow-step-result`){let t=e.payload.id,n=e.payload.status,i=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,[t]:{...r.payload.workflowState.steps[t],status:e.payload.status,output:e.payload.output,error:e.payload.error,endTime:new Date}}}}},n===`failed`&&i){let n=sUi(i);r={...r,status:`failed`,error:n,phase:`error`,failedStep:{id:t,error:n,description:e.payload.description||t},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=r.phase===`error`||r.status===`failed`?{...r,completedAt:new Date}:{...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`){let t=sUi(e.payload.error);r={...r,status:`failed`,error:t,phase:`error`,payload:{...r.payload,workflowState:{...r.payload.workflowState,status:`failed`}},errorTimestamp:new Date}}return{newState:r}},lUi=(e,t)=>{try{localStorage.setItem(`template-install-${e}`,JSON.stringify({state:t,timestamp:Date.now()}))}catch(e){console.warn(`Failed to save template state to localStorage:`,e)}},uUi=(e,t)=>{let[n,r]=(0,W.useState)({}),[i,a]=(0,W.useState)(!1);return{streamResult:n,isStreaming:i,processStream:async(n,i)=>{if(a(!0),r({}),!n)throw Error(`No stream returned`);let o=n.getReader(),s={runId:i||t,eventTimestamp:new Date().toISOString(),phase:`running`,payload:{workflowState:{steps:{}},currentStep:null}};try{for(;;){let{done:n,value:a}=await o.read();if(n)break;let{newState:c}=cUi(a,s,e);s=c,r(c),(a.runId||i||t)&&lUi(a.runId||i||t,c)}}catch(t){console.error(`💥 [processStream] Error processing template installation stream:`,t);let{newState:n}=cUi({type:`error`,payload:{error:t instanceof Error?t.message:`Unknown error`}},s,e);r(n)}finally{a(!1),o.releaseLock()}}}},dUi=({workflowInfo:e,queryOptions:t}={})=>{let n=Y(),{streamResult:r,isStreaming:i,processStream:a}=uUi(e);return{streamInstall:S_({mutationFn:async({inputData:e,selectedModel:t,runId:r})=>{for(let i=1;i<=3;i++)try{let i=n.getAgentBuilderAction(`merge-template`),o=new Dn;o.set(`selectedModel`,t);let s=await i.stream({inputData:e,requestContext:o},r);await a(s,r);return}catch(e){console.error(`💥 [streamInstall] Attempt ${i} failed:`,e);let t=e?.message?.includes(`Failed to fetch`)||e?.message?.includes(`NetworkError`)||e?.message?.includes(`network error`)||e?.message?.includes(`fetch`)||e?.code===`NETWORK_ERROR`||e?.name===`TypeError`;if(console.warn(`Stream attempt ${i}/3 failed:`,e),t){let e=r?`Network error during template installation (likely hot reload). Please refresh the page to resume from where you left off using runId: ${r}`:`Network error during template installation (likely hot reload). Please try again.`;throw console.error(`🔌 Stream network error:`,e),Error(e)}throw console.error(`❌ [streamInstall] Non-network error or max retries reached, throwing:`,e),e}},...t?.streamInstall}),streamResult:r,isStreaming:i}},fUi=({workflowInfo:e,queryOptions:t}={})=>{let n=Y(),{streamResult:r,isStreaming:i,processStream:a}=uUi(e);return{observeInstall:S_({mutationFn:async({runId:e})=>{let t=2e3;for(let r=1;r<=3;r++)try{let t=await n.getAgentBuilderAction(`merge-template`).observeStream({runId:e});await a(t,e);return}catch(e){console.error(`💥 [observeInstall] Attempt ${r} failed:`,e);let n=e?.message?.includes(`Failed to fetch`)||e?.message?.includes(`NetworkError`)||e?.message?.includes(`network error`)||e?.message?.includes(`fetch`)||e?.code===`NETWORK_ERROR`||e?.name===`TypeError`;if(console.warn(`ObserveStream attempt ${r}/3 failed:`,e),n&&r<3){console.info(`🔄 ObserveStream network error detected (likely hot reload), retrying in ${t}ms... (attempt ${r+1}/3)`),await new Promise(e=>setTimeout(e,t));continue}throw console.error(`❌ [observeInstall] Non-network error or max retries reached, throwing:`,e),e}},...t?.observeInstall}),streamResult:r,isStreaming:i}};function pUi(e){return e.replace(/\/$/,``).split(`/`).pop()}function mUi({templates:e,linkComponent:t,className:n,isLoading:r}){let i=t||`a`;return r?(0,G.jsx)(`div`,{className:c(`grid gap-y-4`,n),children:Array.from({length:5}).map((e,t)=>(0,G.jsx)(`div`,{className:`h-16 animate-pulse rounded-lg bg-card`},t))}):(0,G.jsx)(`div`,{className:c(`grid gap-y-4`,n),children:e.map(e=>{let t=e?.agents||e?.tools||e?.networks||e?.workflows||e?.mcp;return(0,G.jsxs)(`article`,{className:c(Pv,`grid w-full grid-cols-[1fr_auto] overflow-hidden rounded-lg state-layer`),children:[(0,G.jsxs)(i,{to:`/templates/${e.slug}`,className:c(`group grid`,{"grid-cols-[8rem_1fr] lg:grid-cols-[12rem_1fr]":e.imageURL}),children:[e.imageURL&&(0,G.jsx)(`div`,{className:`overflow-hidden`,children:(0,G.jsx)(`div`,{className:`thumb transition-scale h-full w-full bg-cover duration-150`,style:{backgroundImage:`url(${e.imageURL})`}})}),(0,G.jsxs)(`div`,{className:c(`grid w-full gap-0.5 px-4 py-3`,`[&_svg]:h-[1em] [&_svg]:w-[1em] [&_svg]:text-muted-foreground`),children:[(0,G.jsx)(T,{as:`h2`,tone:`ink`,children:e.title}),(0,G.jsx)(T,{className:c(gS,A),children:e.description}),(0,G.jsxs)(`div`,{className:`mt-3 hidden flex-wrap items-center gap-x-8 gap-y-4 text-muted-foreground 2xl:flex`,children:[t&&(0,G.jsxs)(`ul`,{className:c(`text-muted-foreground`,`m-0 flex list-none gap-4 p-0`,`[&>li]:flex [&>li]:items-center [&>li]:gap-0.5`),children:[e?.agents&&e.agents.length>0&&(0,G.jsx)(`li`,{children:(0,G.jsxs)(T,{as:`span`,variant:`body`,className:`block`,children:[(0,G.jsx)(WP,{}),` `,e.agents.length]})}),e?.tools&&e.tools.length>0&&(0,G.jsx)(`li`,{children:(0,G.jsxs)(T,{as:`span`,variant:`body`,className:`block`,children:[(0,G.jsx)(ZP,{}),` `,e.tools.length]})}),e?.networks&&e.networks.length>0&&(0,G.jsx)(`li`,{children:(0,G.jsxs)(T,{as:`span`,variant:`body`,className:`block`,children:[(0,G.jsx)(Mut,{}),` `,e.networks.length]})}),e?.workflows&&e.workflows.length>0&&(0,G.jsx)(`li`,{children:(0,G.jsxs)(T,{as:`span`,variant:`body`,className:`block`,children:[(0,G.jsx)(KS,{}),` `,e.workflows.length]})}),e?.mcp&&e.mcp.length>0&&(0,G.jsx)(`li`,{children:(0,G.jsxs)(T,{as:`span`,variant:`body`,className:`block`,children:[(0,G.jsx)(KP,{}),` `,e.mcp.length]})})]}),(0,G.jsx)(`div`,{className:`flex items-center gap-4`,children:e.supportedProviders.map(e=>(0,G.jsx)(T,{tone:`muted`,as:`span`,variant:`body`,children:e},e))})]})]})]}),(0,G.jsx)(`a`,{href:e.githubUrl,className:c(`group ml-auto hidden items-center gap-2 pr-4`,`lg:flex`),target:`_blank`,rel:`noopener noreferrer`,children:(0,G.jsx)(T,{as:`span`,variant:`body`,children:(0,G.jsxs)(`span`,{className:c(`flex items-center gap-2 rounded bg-nested px-2 py-1`,hBe,gS,A),children:[(0,G.jsx)(A6,{}),` `,pUi(e.githubUrl)]})})})]},e.slug)})})}function hUi({tagOptions:e,selectedTag:t,providerOptions:n,selectedProvider:r,onTagChange:i,onProviderChange:a,searchTerm:o,onSearchChange:s,onReset:l,className:u,isLoading:d}){return d?(0,G.jsxs)(`div`,{className:c(`flex h-[6.5rem] items-center gap-5`,`[&>div]:h-8 [&>div]:w-48 [&>div]:animate-pulse [&>div]:bg-card`,u),children:[(0,G.jsx)(`div`,{}),` `,(0,G.jsx)(`div`,{}),` `,(0,G.jsx)(`div`,{})]}):(0,G.jsxs)(`div`,{className:c(`sticky top-0 mx-auto flex flex-wrap gap-1.5 bg-background py-5`,u),children:[(0,G.jsx)(CN,{label:`Search templates`,placeholder:`Search templates`,size:`sm`,value:o,onValueChange:s}),(0,G.jsxs)(Mk,{value:t,onValueChange:i,children:[(0,G.jsx)(Pk,{"aria-label":`Search by tag`,size:`sm`,className:`w-auto`,children:(0,G.jsx)(Nk,{placeholder:`Select an option`})}),(0,G.jsx)(Fk,{children:e.map(e=>(0,G.jsx)(Ik,{value:e.value,children:e.label},e.value))})]}),(0,G.jsxs)(Mk,{value:r,onValueChange:a,children:[(0,G.jsx)(Pk,{"aria-label":`Search by provider`,size:`sm`,className:`w-auto`,children:(0,G.jsx)(Nk,{placeholder:`Select an option`})}),(0,G.jsx)(Fk,{children:n.map(e=>(0,G.jsx)(Ik,{value:e.value,children:e.label},e.value))})]}),l&&(0,G.jsx)(gLt,{onClick:l})]})}var gUi=[{id:`templates`,label:`Templates`}];function _Ui(){let{data:e,isLoading:t}=tUi(),{templates:n,tags:r,providers:i}=e??{templates:[],tags:[],providers:[]},[a,o]=(0,W.useState)(`all`),[s,c]=(0,W.useState)(`all`),[l,u]=(0,W.useState)(``),d=[{value:`all`,label:`Any tag`}];(r||[]).forEach(e=>{d.push({value:e,label:e})});let f=[{value:`all`,label:`Any provider`}];(i||[]).forEach(e=>{f.push({value:e,label:e})});let p=(e,t)=>{t===`tag`?o(e):t===`provider`&&c(e)},m=e=>{u(e)},h=()=>{o(`all`),c(`all`),u(``)},g=n.filter(e=>!(l&&!e.title.toLowerCase().includes(l)&&!e.description.toLowerCase().includes(l)||a!==`all`&&!e.tags.includes(a)||s!==`all`&&!e.supportedProviders.includes(s)));return(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:gUi}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`Templates`}),(0,G.jsx)(_S,{children:(0,G.jsxs)(zJe,{children:[(0,G.jsx)(vx,{children:(0,G.jsx)(k6,{})}),`Templates`]})}),(0,G.jsx)(hUi,{selectedTag:a,onTagChange:e=>p(e,`tag`),tagOptions:d,selectedProvider:s,onProviderChange:e=>p(e,`provider`),providerOptions:f,searchTerm:l,onSearchChange:m,onReset:l||a!==`all`||s!==`all`?h:void 0,isLoading:t}),(0,G.jsx)(mUi,{templates:g,linkComponent:kv,isLoading:t})]})}var vUi=H(`IconEmojiSad`,()=>(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`circle`,{cx:`12`,cy:`12`,r:`9`,stroke:`currentColor`,strokeWidth:`2`}),(0,G.jsx)(`path`,{d:`M10.75 9.9C10.75 11.0046 10.0784 11.75 9.25 11.75C8.42157 11.75 7.75 11.0046 7.75 9.9C7.75 8.79543 8.42157 8 9.25 8C10.0784 8 10.75 8.79543 10.75 9.9Z`,fill:`currentColor`}),(0,G.jsx)(`path`,{d:`M16.25 9.9C16.25 11.0046 15.5784 11.75 14.75 11.75C13.9216 11.75 13.25 11.0046 13.25 9.9C13.25 8.79543 13.9216 8 14.75 8C15.5784 8 16.25 8.79543 16.25 9.9Z`,fill:`currentColor`}),(0,G.jsx)(`path`,{d:`M7.89328 15.4758C7.7698 15.623 7.69925 15.8109 7.70417 16.0051C7.70903 16.1992 7.78791 16.3827 7.92489 16.5166C8.06187 16.6504 8.24712 16.7251 8.44131 16.7254C8.63557 16.7259 8.82181 16.651 8.9661 16.5242C9.05273 16.4499 9.14033 16.3801 9.23093 16.313C10.042 15.7109 11.0211 15.4001 12.0034 15.4C12.9856 15.3986 13.964 15.7081 14.7725 16.3111C14.8628 16.3783 14.9501 16.4481 15.0364 16.5226C15.1803 16.6498 15.3663 16.7253 15.5606 16.7254C15.7548 16.7256 15.9403 16.6515 16.0776 16.5181C16.215 16.3846 16.2944 16.2014 16.2999 16.0073C16.3054 15.8131 16.2354 15.625 16.1124 15.4774C16.0126 15.3603 15.909 15.2487 15.799 15.1403C14.816 14.1611 13.4082 13.5927 12.002 13.6C10.5957 13.595 9.19111 14.1644 8.20718 15.1399C8.09708 15.2479 7.99334 15.3591 7.89328 15.4758Z`,fill:`currentColor`})]}));function yUi({children:e,className:t}){return(0,G.jsx)(`div`,{className:c(`transition-height mt-12 rounded-lg border border-border px-4 py-5 lg:min-h-[25rem] lg:px-12`,t),children:e})}function bUi({errorMsg:e,validationErrors:t}){let n=typeof e==`string`?e:e==null?void 0:String(e),r=n?.includes(`Invalid schema for function`),i=n?.includes(`validation issue`)||t&&t.length>0,a=()=>i?`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.`,{icon:o,title:s}=i?{icon:(0,G.jsx)(Wx,{className:`text-warning-foreground`}),title:`Template Installed with Warnings`}:{icon:(0,G.jsx)(vUi,{}),title:`Template Installation Failed`};return(0,G.jsxs)(yUi,{className:`mb-5 content-center space-y-4 text-muted-foreground`,children:[(0,G.jsxs)(`div`,{className:`grid content-center items-center justify-items-center gap-4 [&>svg]:h-8 [&>svg]:w-8`,children:[o,(0,G.jsxs)(`div`,{className:`space-y-2 text-center`,children:[(0,G.jsx)(T,{variant:`subheading`,tone:`ink`,children:s}),(0,G.jsx)(T,{tone:`muted`,children:a()})]})]}),t&&t.length>0&&(0,G.jsxs)(`details`,{children:[(0,G.jsx)(`summary`,{className:c(`text-muted-foreground hover:text-foreground`,`cursor-pointer text-center select-none`),children:(0,G.jsxs)(T,{as:`span`,variant:`caption`,className:`block`,children:[`Show Validation Issues (`,t.length,`)`]})}),(0,G.jsx)(`div`,{className:`mt-4 max-h-60 space-y-2 overflow-auto rounded bg-muted p-3 text-left`,children:t.map((e,t)=>(0,G.jsxs)(`div`,{className:`border-l-2 border-destructive-indicator pl-2`,children:[(0,G.jsx)(T,{as:`p`,variant:`column`,className:`text-destructive-foreground`,children:e.type===`typescript`?`🔴 TypeScript Error`:`⚠️ Lint Error`}),(0,G.jsx)(aC,{className:`mt-1 text-caption wrap-break-word whitespace-pre-wrap text-muted-foreground`,code:e.message})]},t))})]}),n&&!i&&(0,G.jsxs)(`details`,{children:[(0,G.jsx)(`summary`,{className:c(`text-muted-foreground hover:text-foreground`,`cursor-pointer text-center select-none`),children:(0,G.jsx)(T,{as:`span`,variant:`caption`,className:`block`,children:`Show Details`})}),(0,G.jsx)(`div`,{className:`mt-4 max-h-60 overflow-auto rounded bg-muted p-3 text-left`,children:(0,G.jsx)(aC,{className:`text-caption wrap-break-word whitespace-pre-wrap`,code:n})})]})]})}function xUi({providerOptions:e,selectedProvider:t,onProviderChange:n,variables:r,errors:i,handleInstallTemplate:a,handleVariableChange:o,isLoadingEnvVars:s,isInstalling:l,defaultModelProvider:u,defaultModelId:d,onModelUpdate:f}){return(0,G.jsx)(yUi,{children:(0,G.jsxs)(`div`,{className:`mx-auto my-4 grid max-w-[40rem] gap-5 p-4 lg:p-5`,children:[(0,G.jsxs)(T,{as:`h2`,variant:`heading`,tone:`muted`,className:c(`flex items-center gap-2`,`[&_svg]:h-[1.2em] [&_svg]:opacity-70 [&>svg]:w-[1.2em]`),children:[`Install Template `,(0,G.jsx)(k6,{})]}),(0,G.jsxs)(ZO,{orientation:`horizontal`,children:[(0,G.jsx)($O,{children:`Template AI Model Provider`}),(0,G.jsx)(Fmt,{className:`flex-1`,children:(0,G.jsxs)(Mk,{name:`template-provider`,value:t,onValueChange:n,children:[(0,G.jsx)(Pk,{size:`md`,children:(0,G.jsx)(Nk,{placeholder:`Select`})}),(0,G.jsx)(Fk,{children:e.map(e=>(0,G.jsx)(Ik,{value:e.value,children:e.label},e.value))})]})})]}),t&&Object.entries(r||{}).length>0&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(T,{as:`h3`,tone:`muted`,children:`Set required Environmental Variables`}),(0,G.jsx)(`div`,{className:`grid grid-cols-[1fr_1fr] items-start gap-4`,children:s?(0,G.jsxs)(`div`,{className:c(`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:[(0,G.jsx)(Mv,{}),(0,G.jsxs)(T,{as:`span`,variant:`caption`,className:`block`,children:[` `,`Loading variables...`]})]}):Object.entries(r).map(([e,t])=>(0,G.jsxs)(W.Fragment,{children:[(0,G.jsxs)(ZO,{className:`w-full`,children:[(0,G.jsx)($O,{className:`sr-only`,children:`Key`}),(0,G.jsx)(Bj,{name:`env-${e}`,value:e,disabled:!0,className:`w-full`})]}),(0,G.jsxs)(ZO,{invalid:i.includes(e),className:`w-full`,children:[(0,G.jsx)($O,{className:`sr-only`,children:`Value`}),(0,G.jsx)(Bj,{name:e,value:t,onChange:o,autoComplete:`off`,className:`w-full`}),(0,G.jsx)(tk,{children:i.includes(e)?`Value is required.`:void 0})]})]},e))}),(0,G.jsxs)(`div`,{className:`relative mt-3.5 border-t border-border pt-12`,children:[(0,G.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:(0,G.jsx)(T,{tone:`muted`,as:`span`,variant:`caption`,className:`block`,children:`And`})}),(0,G.jsx)(T,{as:`h3`,tone:`muted`,children:`Set AI Model for Template Installation`}),(0,G.jsx)(T,{tone:`muted`,className:`mt-2 mb-5`,children:`This model will be used by the workflow to process and install the template`}),(0,G.jsx)(Yei,{defaultProvider:u||``,defaultModel:d||``,updateModel:f||(()=>Promise.resolve({message:`Updated`})),closeEditor:()=>{},autoSave:!0,selectProviderPlaceholder:`Provider`})]})]}),t&&!s&&(0,G.jsx)(X,{className:c(`mt-4 flex min-h-10 w-full items-center justify-center gap-2 rounded-lg bg-card state-layer text-foreground`,`[&_svg]:h-[1.1em] [&_svg]:text-foreground [&>svg]:w-[1.1em]`),onClick:a,disabled:!t||!u||!d||i.length>0,iconEnd:(0,G.jsx)(mP,{}),loading:l,children:`Install`})]})})}function SUi({title:e,description:t,githubUrl:n,isLoading:r,infoData:i,templateSlug:a}){let o=a?`feat/install-template-${a}`:`feat/install-template-[slug]`;return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`mt-5 grid items-center`,children:(0,G.jsxs)(`div`,{className:c(`flex items-center gap-3`,`[&>svg]:h-[1.2em] [&>svg]:w-[1.2em] [&>svg]:opacity-50`,{"[&>svg]:opacity-20":r}),children:[(0,G.jsx)(k6,{}),(0,G.jsx)(`h2`,{className:c({"flex min-w-[50%] rounded-lg bg-muted":r}),children:(0,G.jsx)(T,{as:`span`,variant:`title`,className:`block`,children:r?(0,G.jsx)(G.Fragment,{children:`\xA0`}):e})})]})}),(0,G.jsxs)(`div`,{className:`grid gap-x-24 lg:grid-cols-[1fr_1fr]`,children:[(0,G.jsxs)(`div`,{className:`grid`,children:[(0,G.jsx)(T,{tone:`muted`,className:c(`mt-2 mb-4`,{"rounded-lg bg-muted":r}),children:r?(0,G.jsx)(G.Fragment,{children:`\xA0`}):t}),!r&&a&&(0,G.jsxs)(`div`,{className:c(`mb-4 rounded-lg bg-nested p-4`,`flex items-start gap-3`),children:[(0,G.jsx)(`div`,{className:`mt-0.5 shrink-0`,children:(0,G.jsx)(Hx,{className:`h-[1.1em] w-[1.1em] text-info-indicator`})}),(0,G.jsxs)(`div`,{className:`flex-1 space-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(VS,{className:`h-[1em] w-[1em] text-muted-foreground`}),(0,G.jsx)(T,{as:`span`,variant:`subheading`,tone:`ink`,children:`A new Git branch will be created`})]}),(0,G.jsxs)(`div`,{className:`space-y-1`,children:[(0,G.jsxs)(T,{tone:`muted`,as:`p`,variant:`caption`,children:[(0,G.jsx)(T,{as:`span`,variant:`column`,children:`Branch name:`}),` `,(0,G.jsx)(bI,{children:o})]}),(0,G.jsx)(T,{tone:`muted`,as:`p`,variant:`caption`,children:`This ensures safe installation with easy rollback if needed. Your main branch remains unchanged.`})]})]})]}),n&&(0,G.jsxs)(`a`,{href:n,target:`_blank`,rel:`noopener noreferrer`,className:c(`text-muted-foreground hover:text-foreground`,`mt-auto flex items-center gap-2`),children:[(0,G.jsx)(A6,{}),(0,G.jsx)(T,{as:`span`,variant:`body`,className:`block`,children:n?.split(`/`)?.pop()})]})]}),i&&(0,G.jsx)(Aei,{data:i,labelsAreHidden:!0,isLoading:r})]})]})}function CUi(e){switch(e){case`running`:return(0,G.jsx)(Mv,{size:`sm`,"aria-hidden":!0});case`success`:return(0,G.jsx)(cC,{"aria-hidden":!0});case`failed`:return(0,G.jsx)(gw,{"aria-hidden":!0});default:return null}}function wUi(){return(0,G.jsx)(`svg`,{viewBox:`0 0 24 24`,className:`text-subtle-foreground`,"aria-hidden":!0,children:(0,G.jsx)(`circle`,{cx:`12`,cy:`12`,r:`8.5`,pathLength:`48`,fill:`none`,stroke:`currentcolor`,strokeWidth:`2.8`,strokeLinecap:`round`,strokeDasharray:`3 3`})})}function TUi({status:e,variant:t}){return t===`plain`?(0,G.jsx)(`span`,{className:c(`flex size-icon-md items-center justify-center self-center [&>svg]:size-icon-md`,u.colors,{"[&>svg]:text-success-indicator":e===`success`,"[&>svg]:text-destructive-foreground":e===`failed`}),children:e===`pending`?(0,G.jsx)(wUi,{}):CUi(e)}):(0,G.jsx)(`span`,{className:c(`flex size-7 items-center justify-center self-center rounded-full motion-reduce:transition-none`,u.colors,u.transform,{"[&>svg]:text-success-indicator":e===`success`,"[&>svg]:text-destructive-foreground":e===`failed`,"border border-dashed border-placeholder":e===`pending`,"[&>svg]:size-icon-md":e!==`running`,"bg-success-subtle":e===`success`,"bg-destructive-subtle":e===`failed`,"scale-110":e===`success`||e===`failed`}),children:CUi(e)})}function EUi({step:e,isActive:t,position:n,variant:r=`default`}){let i=t||e.status===`success`?`ink`:`muted`;return(0,G.jsxs)(`div`,{className:c(`grid grid-cols-[1fr_auto] gap-6 rounded-lg px-4 py-3 motion-reduce:transition-none`,u.colors,{"border border-transparent":r==="default","border-dashed border-placeholder bg-card":t&&r==="default"}),children:[(0,G.jsxs)(`div`,{className:`grid min-w-0 grid-cols-[auto_1fr] gap-2`,children:[(0,G.jsxs)(T,{as:`span`,tone:i,className:c(`flex min-w-6 justify-end`,u.colors),children:[n,`.`]}),(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(T,{as:`h4`,tone:i,className:u.colors,children:e.title}),e.description&&(0,G.jsx)(T,{tone:`faint`,className:c(`-mt-0.5`,{truncate:r===`plain`}),children:e.description})]})]}),(0,G.jsx)(TUi,{status:e.status,variant:r})]})}function DUi({currentStep:e,steps:t=[],className:n}){return(0,G.jsx)(`div`,{className:c(n),children:t.map((t,n)=>(0,G.jsx)(EUi,{step:t,isActive:e?.id===t.id,position:n+1},t.id))})}function OUi({steps:e}){let t=e.length,n=e.filter(e=>e.status===`success`).length;return(0,G.jsxs)(`div`,{className:`flex w-full flex-col content-center justify-center gap-4`,children:[(0,G.jsx)(`div`,{className:`grid w-full grid-cols-[0_repeat(9,1fr)]`,children:e.map((t,n)=>(0,G.jsx)(`div`,{className:c(`relative flex h-8 items-center justify-end`,u.colors,{"bg-success-subtle":t.status===`success`&&e?.[n-1]?.status===`success`}),children:(0,G.jsx)(`div`,{className:c(`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`,u.colors,u.transform,{"border border-dashed border-placeholder":t.status===`pending`,"scale-110 bg-success-subtle text-success-subtle-foreground":t.status===`success`,"scale-110 bg-destructive-subtle text-destructive-subtle-foreground":t.status===`failed`}),children:t.status===`running`?(0,G.jsx)(Mv,{}):n+1})},t.id))}),(0,G.jsxs)(`div`,{className:c(`text-center text-caption text-muted-foreground`,u.colors),children:[n,` of `,t,` steps completed`]})]})}var kUi=(0,W.createContext)(3);function AUi({title:e,description:t,action:n,done:r,className:i,children:a}){let o=(0,W.useContext)(kUi);return(0,G.jsxs)(`li`,{className:c(`group/step grid grid-cols-[1.5rem_minmax(0,1fr)] gap-x-4 [counter-increment:ds-step]`,i),children:[(0,G.jsxs)(`div`,{className:`flex flex-col items-center`,children:[(0,G.jsx)(`span`,{className:c(`flex size-6 shrink-0 items-center justify-center rounded-full`,u.colors,r?`bg-success-indicator/18 text-success-indicator`:`bg-fill text-foreground`),children:r?(0,G.jsx)(cC,{className:`size-icon-sm`,"aria-label":`Done`}):(0,G.jsx)(T,{as:`span`,variant:`column`,className:`before:content-[counter(ds-step)]`,"aria-hidden":!0})}),(0,G.jsx)(`span`,{"aria-hidden":!0,className:`w-px flex-1 bg-border group-last/step:hidden`})]}),(0,G.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-3 pb-8 group-last/step:pb-0`,children:[(0,G.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,G.jsxs)(`div`,{className:`flex min-h-6 flex-wrap items-center justify-between gap-x-6 gap-y-2`,children:[(0,G.jsx)(T,{as:o===2?`h2`:`h3`,variant:`label`,className:`text-pretty`,children:e}),n==null?null:(0,G.jsx)(`div`,{className:`flex shrink-0 items-center gap-2`,children:n})]}),t==null?null:(0,G.jsx)(T,{as:`p`,variant:`body-sm`,tone:`muted`,className:`max-w-[70ch] text-pretty`,children:t})]}),a]})]})}function jUi({headingLevel:e=3,className:t,children:n}){return(0,G.jsx)(kUi.Provider,{value:e,children:(0,G.jsx)(`ol`,{className:c(`flex flex-col [counter-reset:ds-step]`,t),children:n})})}Object.assign(jUi,{Step:AUi});function MUi({name:e,streamResult:t,runId:n,workflowInfo:r}){let i=t?.phase||`initializing`,a=t?.payload?.workflowState,o=t?.payload?.currentStep,s=t?.error,l=a?.steps||{},u=Object.keys(l).length>0,d=e=>e===`input`||e.endsWith(`.input`)||e.startsWith(`Mapping_`)&&/[0-9a-f]{8}/.test(e)||/[0-9a-f]{8,}/.test(e)?!1:!r?.allSteps||e in r.allSteps,f=Object.entries(l).filter(([e,t])=>d(e)),p=f.length,m=()=>{switch(i){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...`}},h=f.map(([e,t])=>({id:e,status:t?.status,description:t?.description,title:e.charAt(0).toUpperCase()+e.slice(1).replace(/-/g,` `),isActive:o?.id===e}));return(0,G.jsxs)(yUi,{className:`mb-5 content-center space-y-6 text-muted-foreground`,children:[(0,G.jsxs)(`div`,{className:`text-center`,children:[(0,G.jsx)(T,{as:`h3`,variant:`heading`,tone:`ink`,children:m()}),(t?.runId||n)&&(0,G.jsxs)(T,{as:`p`,variant:`caption`,tone:`muted`,className:`mt-2`,children:[`Run ID: `,t?.runId??n]})]}),u&&p>0&&![`error`].includes(i)&&(0,G.jsx)(`div`,{className:`mx-auto w-full max-w-[30rem] px-4`,children:(0,G.jsx)(OUi,{steps:h})}),s&&i===`error`&&(0,G.jsxs)(`div`,{className:c(`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:[(0,G.jsx)(Bx,{}),(0,G.jsx)(T,{as:`span`,variant:`body`,className:`block`,children:s||`Something went wrong`})]}),u&&(0,G.jsx)(DUi,{steps:h,currentStep:o,className:`pb-4`}),!u&&i===`initializing`&&(0,G.jsxs)(`div`,{className:c(`text-muted-foreground`,`grid justify-items-center gap-4 text-center`),children:[(0,G.jsx)(Mv,{}),(0,G.jsx)(T,{as:`p`,variant:`body`,children:`This may take some time...`})]})]})}function NUi({name:e,installedEntities:t}){return(0,G.jsxs)(yUi,{className:c(`grid content-center items-center justify-items-center gap-4`,`[&>svg]:h-8 [&>svg]:w-8`),children:[(0,G.jsx)(k6,{}),(0,G.jsx)(T,{as:`h2`,variant:`heading`,children:`Done!`}),(0,G.jsxs)(T,{tone:`muted`,className:`text-center`,children:[`The `,(0,G.jsx)(`b`,{className:`text-muted-foreground`,children:e}),` template has been successfully installed.`,t&&t.length>0&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`br`,{}),` Installed entities are listed below.`]})]}),t&&t.length>0&&(0,G.jsx)(Aei,{data:t})]})}function PUi(){let{templateSlug:e}=wv(),t=[{id:`templates`,label:`Templates`,to:`/templates`},{id:`template`,label:lnn(e)}],[n,r]=Av(),[i,a]=(0,W.useState)(``),[o,s]=(0,W.useState)(``),[c,l]=(0,W.useState)(``),[u,d]=(0,W.useState)({}),[f,p]=(0,W.useState)([]),[m,h]=(0,W.useState)(null),[g,_]=(0,W.useState)(!1),[v,y]=(0,W.useState)(``),[b,x]=(0,W.useState)(!1),[S,C]=(0,W.useState)(!1),[w,T]=(0,W.useState)([]),{data:E,isLoading:D}=nUi({repoOrSlug:e,owner:`mastra-ai`}),O=`1.86.0-alpha.9`.includes(`beta`)??!1?`beta`:`main`,{data:k,isLoading:A}=rUi({repo:E?.githubUrl?new URL(E.githubUrl).pathname.split(`/`)[2]:`template-${e}`,owner:`mastra-ai`,branch:O}),{data:j,isLoading:M}=iUi(),{mutateAsync:N,isPending:P}=aUi(),{mutateAsync:F}=oUi(),{streamInstall:I,streamResult:L,isStreaming:R}=dUi({workflowInfo:j}),{observeInstall:z,streamResult:B,isStreaming:ee}=fUi({workflowInfo:j});(0,W.useEffect)(()=>{let e=n.get(`runId`);!e||g||m||R||ee||(console.info(`🔄 Checking completed run after hot reload:`,{runId:e}),y(e),F({runId:e}).then(e=>{let t=e.snapshot;if(t?.status===`success`&&t?.result?.success)_(!0);else if(t?.result?.success===!1){if(t?.result?.validationResults&&!t?.result?.validationResults?.valid&&t?.result?.validationResults?.remainingErrors>0){let{remainingErrors:e,errors:n}=t.result.validationResults,r=`Template installation completed but ${e} validation issue${e>1?`s`:``} remain unresolved.`;h(r),T(n||[])}else{let e=t?.result?.message||t?.result?.error||`Template installation failed`;h(typeof e==`string`?e:String(e))}}}).catch(e=>{console.error(`❌ Failed to fetch run details:`,e),h(`Failed to retrieve installation status after reload`)}))},[n,g,m,R,ee,F]),(0,W.useEffect)(()=>{let e=n.get(`runId`),t=n.get(`resume`),i=n.get(`provider`);if(e&&t===`true`&&i&&!R&&!ee&&!b&&!S&&j){y(e),x(!0);try{F({runId:e}).then(t=>{if(t.snapshot?.status===`running`)return z.mutateAsync({runId:e})}).then(()=>{r(e=>{let t=new URLSearchParams(e);return t.delete(`resume`),t})}).catch(e=>{console.error(`❌ Failed to resume template installation:`,e),e.message?.includes(`404`)||e.message?.includes(`not found`)?h(`Template installation run not found. It may have expired or been completed.`):h(`Failed to resume template installation. Please try again.`)})}catch(e){console.error(`❌ Auto-resume failed with error:`,e),h(`Failed to resume template installation. Please refresh and try again.`)}}},[n,e,R,ee,b,S,j,F,z,r]);let V=[{value:`openai`,label:`OpenAI`},{value:`anthropic`,label:`Anthropic`},{value:`groq`,label:`Groq`},{value:`google`,label:`Google`}],te=[{key:`tools`,label:`Tools`,value:E?.tools?.length?E.tools.map(e=>e).join(`, `):`n/a`,icon:(0,G.jsx)(ZP,{})},{key:`agents`,label:`Agents`,value:E?.agents?.length?E.agents.map(e=>e).join(`, `):`n/a`,icon:(0,G.jsx)(WP,{})},{key:`workflows`,label:`Workflows`,value:E?.workflows?.length?E.workflows.map(e=>e).join(`, `):`n/a`,icon:(0,G.jsx)(KS,{})},{key:`providers`,label:`Providers`,value:E?.supportedProviders?.length?E.supportedProviders.join(`, `):`n/a`,icon:(0,G.jsx)(h8,{})},{key:`tags`,label:`Tags`,value:E?.tags?.length?E.tags.join(`, `):`n/a`,icon:(0,G.jsx)(wP,{})}],ne=[{...te[0]},{...te[1]},{...te[2]}].filter(e=>e.value!==`n/a`);return(0,W.useEffect)(()=>{k&&d(k)},[k]),(0,W.useEffect)(()=>{let e=L||B;e?.phase===`error`&&e?.error&&h(typeof e.error==`string`?e.error:String(e.error))},[L?.phase,L?.error,B?.phase,B?.error]),(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:t}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:e}),(0,G.jsxs)(`div`,{className:`grid gap-y-6`,children:[(0,G.jsx)(SUi,{isLoading:D,title:E?.title,description:E?.longDescription,imageURL:E?.imageURL,githubUrl:E?.githubUrl,infoData:te,templateSlug:e}),E&&(0,G.jsxs)(G.Fragment,{children:[(R||ee)&&(0,G.jsx)(MUi,{name:E.title,streamResult:ee?B:L,runId:v,workflowInfo:j}),g&&(0,G.jsx)(NUi,{name:E.title,installedEntities:ne,linkComponent:kv}),m&&(0,G.jsx)(bUi,{errorMsg:m,validationErrors:w.length>0?w:L?.validationResults?.errors||B?.validationResults?.errors}),!R&&!ee&&!g&&!m&&(0,G.jsx)(xUi,{providerOptions:V,selectedProvider:i,onProviderChange:e=>{a(e)},variables:u,setVariables:d,errors:f,setErrors:p,handleInstallTemplate:async()=>{let e=Object.entries(u).reduce((e,[t,n])=>(n===``&&e.push(t),e),[]);if(e.length>0)p(e);else if(E){h(null),_(!1),y(``),C(!0);try{let e={repo:E.githubUrl||`https://github.com/mastra-ai/template-${E.slug}`,ref:O,slug:E.slug,variables:u},{runId:t}=await N({});y(t),r(e=>{let n=new URLSearchParams(e);return n.set(`runId`,t),n.set(`resume`,`true`),n.set(`provider`,i||`openai`),n}),await I.mutateAsync({inputData:e,selectedModel:{provider:o,modelId:c},runId:t})}catch(e){C(!1),h(e?.message||`Template installation failed`),console.error(`Template installation failed`,e)}}},handleVariableChange:e=>{let{name:t,value:n}=e.target;n.trim()===``?p(e=>[...e,t]):p(e=>e.filter(e=>e!==t)),d(e=>({...e,[t]:n}))},isLoadingEnvVars:A||M,isInstalling:P,defaultModelProvider:o,defaultModelId:c,onModelUpdate:async e=>(s(e.provider),l(e.modelId),{message:`Model updated successfully`})})]})]})]})}var FUi=e=>e.threadId,IUi=e=>`traces`in e?e.traces:e.threads;function LUi(e,t){return`traces`in e?{traces:{...e.traces,...t}}:{threads:{...e.threads,...t}}}function RUi(e){let{field:t=`endedAt`,direction:n=`desc`}=e?.[0]??{},r=n===`asc`?1:-1;return(e,n)=>{let i=e[t],a=n[t];if(i!==a){if(i==null)return 1;if(a==null)return-1;if(i<a)return-r;if(i>a)return r}return e.threadId.localeCompare(n.threadId)}}function zUi({query:e,rolling:t,fixedStart:n=!1,autoRefetch:r=!0,limit:i,enabled:a=!0}){let o=Y(),{anchorWindow:s,reanchor:c}=xHi(e,n),l=(0,W.useMemo)(()=>s?{...e,timeRange:LUi(e.timeRange,s)}:e,[e,s]),u=rri({query:l,limit:i,enabled:a,queryOptions:gHi}),{headRows:d}=CHi({queryKey:[`threads`,e],fetchHead:async t=>(await o.queryTraceThreads({...e,timeRange:LUi(e.timeRange,bHi(IUi(e.timeRange),t,n)),orderBy:[{field:`endedAt`,direction:`desc`}],page:{limit:50}})).threads,getId:FUi,getEndedAt:e=>e.endedAt,since:Date.parse(IUi(l.timeRange).to),enabled:a&&t&&r&&u.threads!==void 0&&!u.isFetching&&!u.isError,onOverflow:()=>c(IUi(e.timeRange))}),{orderBy:f}=e,p=u.threads,m=(0,W.useMemo)(()=>p&&THi(p,d,{getId:FUi,compare:RUi(f),hasNextPage:u.hasNextPage}),[p,d,f,u.hasNextPage]);return{...u,threads:m}}function BUi(e){return{traceId:e.lastTraceId,name:e.entityName??e.threadId,entityType:e.entityType,entityId:e.entityId,entityName:e.entityName,threadId:e.threadId,resourceId:e.resourceId,environment:e.environment,status:e.status,inputPreview:e.inputPreview,outputPreview:e.outputPreview??void 0,errorPreview:e.errorPreview??void 0,startedAt:e.startedAt,endedAt:e.endedAt,traceCount:e.traceCount,timeToFirstChunkMs:e.timeToFirstChunkMs,timeToFirstTokenMs:e.timeToFirstTokenMs,createdAt:e.startedAt}}var VUi=[`last-24h`,`last-3d`,`last-7d`,`last-14d`,`last-30d`,`custom`],HUi=[];function UUi(){let{data:e}=O7(),t=e?.capabilities.traceQueryTimeToFirstChunk??!1,n=e?.capabilities.traceQueryTimeToFirstToken??!1,{data:r=HUi}=q8(),{data:i=HUi}=J8();return(0,W.useMemo)(()=>[NLt,...Ugi({withTimeToFirstChunk:t,withTimeToFirstToken:n,entityNames:r,environments:i})],[t,n,r,i])}function WUi({tokens:e,groups:t,onFiltersChange:n}){let r=(0,W.useMemo)(()=>sai(e),[e]),i=(0,W.useMemo)(()=>{let e=uai([],t);return{...e,nodes:[hP,...r,...e.nodes]}},[r,t]),a=(0,W.useCallback)(e=>{let t=fai({...e,nodes:e.nodes.filter(e=>aP(e)||e.fieldId!==`timeRange`)});n(t.tokens,t.groups)},[n]);return{filterBarValue:i,onFilterBarChange:a,onFilterByField:(0,W.useCallback)((e,t)=>{let n=r.filter(t=>t.fieldId!==e),o={id:`${e}:${t}`,fieldId:e,operatorId:`is`,value:t},s=i.nodes.filter(aP);a({...i,nodes:[...n,o,...s]})},[r,i,a])}}var GUi=e=>e;function KUi({datePreset:e,dateFrom:t,dateTo:n,minDate:r,tokens:i,groups:a,onDatePresetChange:o,onDateChange:s,onDateRangeChange:c,onFiltersChange:l,disabled:u}){let d=UUi(),{filterBarValue:f,onFilterBarChange:p}=WUi({tokens:i,groups:a,onFiltersChange:l});return(0,G.jsxs)(SP,{fields:d,operators:Fii,value:f,onValueChange:p,createItemId:GUi,maxDepth:3,"aria-label":`Thread filters`,className:`min-w-64 flex-1`,children:[(0,G.jsx)(SP.Chips,{renderChip:i=>i.fieldId===`timeRange`?(0,G.jsx)(SP.TimeRange,{preset:e,onPresetChange:o,dateFrom:t,dateTo:n,minDate:r,onDateChange:s,onDateRangeChange:c,disabled:u,presets:VUi,defaultPreset:g5.datePreset}):(0,G.jsx)(SP.Chip,{item:i})}),(0,G.jsx)(SP.Input,{placeholder:`Filter threads`})]})}function qUi({selectedThreadId:e,onSelectedThreadChange:t,onOpenScore:n,urlState:r}){let i=vHi(r),{timeRange:a,tokens:o,groups:s,sort:c}=i,l=k7().enabled,u=gvi().enabled,d=Z_i({scope:`threads`}),{data:f,isLoading:p}=O7(),m=f?.capabilities.traceQueryTimeToFirstChunk??!1,h=f?.capabilities.traceQueryTimeToFirstToken??!1,g=(0,W.useMemo)(()=>p?d.preferences:tni(d.preferences,{withTimeToFirstChunk:m,withTimeToFirstToken:h}),[d.preferences,p,m,h]),{threads:_,hasNextPage:v,isFetchingNextPage:y,setEndOfListElement:b,isLoading:x,isError:S,error:C}=zUi({query:(0,W.useMemo)(()=>{let e=Kgi(o,s,{withTimeToFirstChunk:m,withTimeToFirstToken:h});return{timeRange:{traces:a},orderBy:[{field:`startedAt`,direction:c.direction}],...e?{where:e}:{}}},[a,c,o,s,m,h]),rolling:i.rolling,fixedStart:i.datePreset===`custom`}),w=(0,W.useMemo)(()=>(_??[]).map(BUi),[_]),T=w.find(t=>t.threadId===e),E=e=>{e.threadId&&t(e.threadId)},D=!x&&!S&&w.length===0&&!i.contentFiltersApplied&&!e;return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`Threads`}),(0,G.jsx)(Foi,{toolbar:(0,G.jsxs)(G.Fragment,{children:[r&&(0,G.jsx)(K_i,{page:`threads`,...r,columns:d}),(0,G.jsxs)(EP,{children:[(0,G.jsx)(EP.Start,{children:(0,G.jsx)(KUi,{datePreset:i.datePreset,dateFrom:i.dateFrom,dateTo:i.dateTo,tokens:o,groups:s,onDatePresetChange:i.onDatePresetChange,onDateChange:i.onDateChange,onDateRangeChange:i.onDateRangeChange,onFiltersChange:i.onFiltersChange,disabled:x})}),(0,G.jsx)(EP.End,{children:(0,G.jsx)(KHi,{scope:`threads`,value:d.preferences,onChange:d.setPreferences})})]})]}),error:S?(0,G.jsx)(B8,{error:C,resource:`threads`,errorTitle:`Failed to load threads`}):void 0,empty:D?(0,G.jsx)(Nti,{resource:`threads`,datePreset:i.datePreset,dateFrom:i.dateFrom,dateTo:i.dateTo}):void 0,children:(0,G.jsx)(rui,{listId:`all-threads`,columnPreferences:g,outcomeColumn:!1,traces:w,isLoading:x,isFetchingNextPage:y,hasNextPage:v,setEndOfListElement:b,filtersApplied:i.filtersApplied,resource:`threads`,sort:c,onSortChange:e=>i.setSort({field:`startedAt`,direction:e.direction}),featuredTraceId:T?.traceId,onTraceClick:E})}),(0,G.jsx)(_bi,{open:!!e,threadId:e??``,depth:1,closeLabel:`Close`,withQueryTrace:l,withFeedback:u,onOpenScore:n,onClose:()=>t(void 0)})]})}function JUi(){let{enabled:e,isLoading:t}=pvi(),n=Cv(),[r,i]=Av();return(0,G.jsx)(mHi,{enabled:e,isLoading:t,heading:`Threads`,title:`Query threads capability not activated`,description:`Your observability storage does not support thread row queries. Switch to a store that declares the thread-query-rows capability to list threads.`,children:(0,G.jsx)(qUi,{urlState:{searchParams:r,setSearchParams:i},selectedThreadId:jHi(r),onSelectedThreadChange:e=>i(t=>MHi(t,e),{replace:!0}),onOpenScore:(e,t)=>n(pZn(e,t))})})}var YUi=()=>(0,G.jsx)(Vx,{titleSlot:`No Workflows yet`,descriptionSlot:(0,G.jsxs)(G.Fragment,{children:[`Mastra workflows are not configured yet. `,(0,G.jsx)(`br`,{}),`More information in the documentation.`]}),actionSlot:(0,G.jsx)(X,{variant:`ghost`,render:(0,G.jsx)(`a`,{href:`https://mastra.ai/docs/workflows/overview`,target:`_blank`,rel:`noopener noreferrer`}),icon:(0,G.jsx)(nF,{}),children:`Workflows documentation`}),variant:`fill`});function XUi(e,t,n){return P6(e,t,{name:e=>e.name,running:e=>n[e.id]?.running??0,suspended:e=>n[e.id]?.suspended??0,steps:e=>Object.keys(e.steps??{}).length})}function ZUi(e){return Object.keys(e.steps??{}).filter(t=>e.allSteps?.[t]?.isWorkflow)}function QUi(e){let t=new Map;for(let[n,r]of Object.entries(e))t.set(n,n),r.name&&t.set(r.name,n);return t}function $Ui(e,t,n){let r=QUi(t),i=[],a=(e,o,s,c,l,u)=>{let d=ZUi(e).filter(e=>{let t=r.get(e);return t===void 0||!c.has(t)});if(i.push({kind:`workflow`,workflow:e,pathKey:o,depth:s,nestedIds:d,guides:l,isLastChild:u}),!n.has(o)||d.length===0)return;let f=new Set(c).add(e.id),p=s===0?[]:[...l,!u];for(let[n,c]of d.entries()){let l=n===d.length-1,u=r.get(c);if(u===void 0){i.push({kind:`unregistered`,stepId:c,description:e.allSteps?.[c]?.description,pathKey:`${o}/${c}`,depth:s+1,guides:p,isLastChild:l});continue}let m=t[u];m&&a({...m,id:u},`${o}/${u}`,s+1,f,p,l)}};for(let t of e)a(t,t.id,0,new Set([t.id]),[],!1);return i}var eWi=`auto 24rem minmax(0, 1fr) auto auto auto`;function tWi({guides:e,isLastChild:t}){return(0,G.jsxs)(`span`,{"aria-hidden":!0,className:`-my-6 flex shrink-0 self-stretch`,children:[e.map((e,t)=>(0,G.jsx)(`span`,{className:c(`w-6`,e&&`border-l border-border`)},t)),(0,G.jsxs)(`span`,{className:`relative w-6`,children:[(0,G.jsx)(`span`,{className:c(`absolute top-0 left-0 border-l border-border`,t?`h-1/2`:`h-full`)}),(0,G.jsx)(`span`,{className:`absolute top-1/2 left-0 w-3.5 border-b border-border`})]})]})}function nWi({row:e,isExpanded:t,onToggle:n}){let r=e.kind===`workflow`&&e.nestedIds.length>0,i=e.kind===`workflow`?e.workflow.name:e.stepId;return(0,G.jsx)(`div`,{className:`flex items-center pl-5`,children:r?(0,G.jsx)(`button`,{type:`button`,"aria-expanded":t,"aria-label":`${t?`Collapse`:`Expand`} nested workflows of ${i}`,className:c(hS,`relative grid size-5 shrink-0 place-items-center before:absolute before:-inset-1.5 before:content-['']`),onClick:e=>{e.stopPropagation(),n()},children:(0,G.jsx)(y,{direction:`right`,className:`size-4`})}):(0,G.jsx)(`span`,{className:`size-5 shrink-0`,"aria-hidden":!0})})}var rWi=e=>e.stopPropagation();function iWi({sortKey:e,sort:t,onSortChange:n,children:r}){return n?(0,G.jsx)(Z.SortableTopCell,{sortKey:e,sort:t?.key===e?t.direction:void 0,onSortChange:t=>n(t,e),children:r}):(0,G.jsx)(Z.TopCell,{children:r})}function aWi({row:e,isExpanded:t,onToggle:n,runCount:r,rowProps:i}){let{paths:a,Link:o}=on(),s=(0,W.useRef)(null),{workflow:c,nestedIds:l}=e,u=vN(c.name,50),d=vN(c.description??``,200),f=Object.keys(c.steps??{}).length,p=r?.running??0,m=r?.suspended??0,h=l.length>0;return(0,G.jsxs)(Z.RowWrapper,{...i,onSelectRow:()=>s.current?.click(),children:[(0,G.jsx)(nWi,{row:e,isExpanded:t,onToggle:n}),(0,G.jsxs)(Z.RowLink,{ref:s,colStart:2,to:a.workflowLink(c.id),LinkComponent:o,tabIndex:-1,onClick:rWi,children:[(0,G.jsx)(Z.NameCell,{children:(0,G.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[e.depth>0?(0,G.jsx)(tWi,{guides:e.guides,isLastChild:e.isLastChild}):null,(0,G.jsx)(`span`,{className:`truncate`,children:u}),c.origin===`dynamic`?(0,G.jsx)(YS,{size:`xs`,variant:`blue`,title:`Registered via the dynamic-workflows API`,children:`Dynamic`}):null,h?(0,G.jsxs)(T,{as:`span`,variant:`body-sm`,tone:`muted`,title:`Nested workflows: ${l.join(`, `)}`,className:`inline-flex shrink-0 items-center gap-1`,children:[(0,G.jsx)(KS,{"aria-hidden":!0,className:`size-icon-sm`}),l.length]}):null]})}),(0,G.jsx)(Z.DescriptionCell,{children:d}),(0,G.jsx)(Z.TextCell,{className:`text-center`,children:p>0?(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-info-indicator`,"aria-label":`${p} run${p===1?``:`s`} in progress`,children:[(0,G.jsx)(`span`,{"aria-hidden":!0,className:`size-2 rounded-full bg-info-indicator motion-safe:animate-pulse`}),p]}):``}),(0,G.jsx)(Z.TextCell,{className:`text-center`,children:m>0?(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-warning-foreground`,"aria-label":`${m} run${m===1?``:`s`} awaiting input`,children:[(0,G.jsx)(AD,{"aria-hidden":!0,className:`size-icon-sm`}),m]}):``}),(0,G.jsx)(Z.TextCell,{className:`text-center`,children:f||``})]})]})}function oWi({workflows:e,isLoading:t,search:n=``,sort:r,onSortChange:i,requestContext:a}){let[o,s]=(0,W.useState)(new Set),l=LDt({requestContext:a}),u=(0,W.useMemo)(()=>Object.entries(e).map(([e,t])=>({...t,id:e})),[e]),d=(0,W.useMemo)(()=>{let e=n.toLowerCase();return u.filter(t=>t.name?.toLowerCase().includes(e)||t.description?.toLowerCase().includes(e))},[u,n]),f=(0,W.useMemo)(()=>XUi(d,r,l),[d,r,l]),m=(0,W.useMemo)(()=>$Ui(f,e,o),[f,e,o]),h=(0,W.useMemo)(()=>{let e=new Map;for(let t of m)t.kind===`workflow`&&e.set(t.pathKey,e.size);return e},[m]),{containerRef:g,getRowProps:_}=UP({count:h.size,global:!0}),v=e=>{s(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return t?(0,G.jsx)(QP,{columns:eWi,fit:`container`}):(0,G.jsxs)(Z,{columns:eWi,fit:`container`,scrollRef:g,children:[(0,G.jsxs)(Z.Top,{children:[(0,G.jsx)(Z.TopCell,{children:(0,G.jsx)(`span`,{className:`sr-only`,children:`Expand`})}),(0,G.jsx)(iWi,{sortKey:`name`,sort:r,onSortChange:i,children:`Name`}),(0,G.jsx)(Z.TopCell,{children:`Description`}),(0,G.jsx)(iWi,{sortKey:`running`,sort:r,onSortChange:i,children:`Running`}),(0,G.jsx)(iWi,{sortKey:`suspended`,sort:r,onSortChange:i,children:`Pending input`}),(0,G.jsx)(iWi,{sortKey:`steps`,sort:r,onSortChange:i,children:`Number of steps`})]}),m.length===0&&n?(0,G.jsx)(Z.NoMatch,{message:`No Workflows match your search`}):null,m.map(e=>{let t=o.has(e.pathKey),n=()=>v(e.pathKey);return e.kind===`unregistered`?(0,G.jsxs)(Z.RowStatic,{className:`gap-0 px-0`,children:[(0,G.jsx)(nWi,{row:e,isExpanded:t,onToggle:n}),(0,G.jsxs)(`div`,{className:`col-span-5 col-start-2 grid grid-cols-subgrid gap-4 px-3`,children:[(0,G.jsx)(Z.NameCell,{children:(0,G.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(tWi,{guides:e.guides,isLastChild:e.isLastChild}),(0,G.jsx)(`span`,{className:`truncate`,children:vN(e.stepId,50)}),(0,G.jsxs)(mx,{children:[(0,G.jsx)(hx,{render:(0,G.jsx)(T,{as:`span`,variant:`body-sm`,tone:`muted`}),role:`note`,tabIndex:0,className:c(`shrink-0 rounded-sm`,p),children:`not registered`}),(0,G.jsx)(gx,{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.`})]})]})}),(0,G.jsx)(Z.DescriptionCell,{children:vN(e.description??``,200)}),(0,G.jsx)(Z.TextCell,{className:`text-center`,children:``}),(0,G.jsx)(Z.TextCell,{className:`text-center`,children:``}),(0,G.jsx)(Z.TextCell,{className:`text-center`,children:``})]})]},`workflow-${e.pathKey}`):(0,G.jsx)(aWi,{row:e,isExpanded:t,onToggle:n,runCount:l[e.workflow.id],rowProps:_(h.get(e.pathKey)??-1)},`workflow-${e.pathKey}`)})]})}var G9=[AR(`/workflows`)];function sWi(){let{data:e,isLoading:t,error:n}=WM(),[r,i]=(0,W.useState)(``),[a,o]=(0,W.useState)();return n&&JN(n)?(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:G9}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`Workflows`}),(0,G.jsx)(vR,{variant:`fill`})]}):n&&YN(n)?(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:G9}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`Workflows`}),(0,G.jsx)(_R,{variant:`fill`,resource:`workflows`})]}):n?(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:G9}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`Workflows`}),(0,G.jsx)(Vx,{tone:`error`,variant:`fill`,titleSlot:`Failed to load workflows`,descriptionSlot:n.message})]}):Object.keys(e||{}).length===0&&!t?(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:G9}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`Workflows`}),(0,G.jsx)(YUi,{})]}):(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:G9}),actionRow:(0,G.jsxs)(EP,{children:[(0,G.jsx)(EP.Start,{children:(0,G.jsx)(`div`,{className:`max-w-120 flex-1`,children:(0,G.jsx)(CN,{...wN,onValueChange:i,label:`Search workflows`,placeholder:`Search by name or description`})})}),(0,G.jsx)(EP.End,{children:(0,G.jsx)(X,{render:(0,G.jsx)(kv,{to:`/workflows/schedules`}),variant:`primary`,icon:(0,G.jsx)(HS,{}),children:`Schedules`})})]}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`Workflows`}),(0,G.jsx)(oWi,{workflows:e||{},isLoading:t,search:r,sort:a,onSortChange:(e,t)=>o({key:t,direction:e})})]})}var cWi={active:`bg-success-indicator`,paused:`bg-info-indicator`,completed:`bg-muted-foreground`},lWi={active:`text-success-indicator`,paused:`text-info-indicator`,completed:`text-muted-foreground`},uWi=({status:e})=>(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-2 whitespace-nowrap`,children:[(0,G.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full ${cWi[e]}`,"aria-hidden":!0}),(0,G.jsx)(T,{as:`span`,variant:`caption`,className:lWi[e],children:e})]});function dWi({status:e}){let{icon:t,color:n}=fWi(e);return(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 whitespace-nowrap ${n}`,children:[(0,G.jsx)(`span`,{className:`inline-flex shrink-0 items-center`,"aria-hidden":!0,children:t}),(0,G.jsx)(T,{as:`span`,variant:`caption`,children:e})]})}function fWi(e){switch(e){case`success`:return{icon:(0,G.jsx)(cC,{className:`size-icon-sm`}),color:`text-success-indicator`};case`failed`:return{icon:(0,G.jsx)(gw,{className:`size-icon-sm`}),color:`text-destructive-foreground`};case`running`:return{icon:(0,G.jsx)(Mv,{}),color:`text-muted-foreground`};case`suspended`:return{icon:(0,G.jsx)(AD,{className:`size-icon-sm`}),color:`text-info-indicator`};case`canceled`:return{icon:(0,G.jsx)(zx,{className:`size-icon-sm`}),color:`text-muted-foreground`};case`pending`:case`waiting`:return{icon:(0,G.jsx)(XS,{className:`size-icon-sm`}),color:`text-muted-foreground`};default:return{icon:null,color:`text-muted-foreground`}}}var pWi=`auto auto auto auto 1fr`,mWi=3e4,hWi=3e5;function gWi({triggers:e,isLoading:t,workflowId:n,hasNextPage:r,isFetchingNextPage:i,setEndOfListElement:a}){let{Link:o,paths:s}=on(),c=e=>!!(n&&e.runId&&e.outcome!==`failed`),l=e.filter(c).length,{containerRef:u,getRowProps:d}=UP({count:l}),f=-1;return t?(0,G.jsx)(QP,{columns:pWi}):e.length===0?(0,G.jsx)(T,{variant:`body`,tone:`muted`,className:`p-4`,children:`No trigger history yet.`}):(0,G.jsxs)(Z,{columns:pWi,className:`min-w-0`,scrollRef:u,children:[(0,G.jsxs)(Z.Top,{children:[(0,G.jsx)(Z.TopCell,{children:`Run`}),(0,G.jsx)(Z.TopCell,{children:`Status`}),(0,G.jsx)(Z.TopCell,{children:`Started`}),(0,G.jsx)(Z.TopCell,{children:`Duration`}),(0,G.jsx)(Z.TopCell,{children:` `})]}),e.map(e=>{let t=e.actualFireAt-e.scheduledFireAt,r=$S(t,{signed:!0}),i=e.outcome===`failed`,a=i?e.error:e.run?.error,l=Math.abs(t),u=!i&&l>mWi&&l<=hWi,p=`${e.scheduleId}-${e.runId}-${e.actualFireAt}`,m=c(e);m&&(f+=1);let h=(0,G.jsx)(T,{as:`span`,variant:`caption`,font:`mono`,tone:m?`ink`:`muted`,className:`whitespace-nowrap`,children:e.runId}),g=(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Z.Cell,{children:h}),(0,G.jsx)(Z.Cell,{children:(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[i?(0,G.jsxs)(T,{as:`span`,variant:`caption`,className:`inline-flex items-center gap-1.5 whitespace-nowrap text-destructive-foreground`,children:[(0,G.jsx)(Wx,{className:`size-icon-sm`}),`publish failed`]}):e.run?(0,G.jsx)(dWi,{status:e.run.status}):(0,G.jsx)(T,{as:`span`,variant:`caption`,tone:`muted`,className:`inline-flex items-center gap-1.5 whitespace-nowrap`,children:`pending`}),a?(0,G.jsxs)(mx,{children:[(0,G.jsx)(hx,{asChild:!0,children:(0,G.jsx)(`span`,{className:`inline-flex text-destructive-foreground`,children:(0,G.jsx)(Wx,{className:`size-icon-sm`})})}),(0,G.jsx)(gx,{children:a})]}):null]})}),(0,G.jsx)(Z.Cell,{children:(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-2 whitespace-nowrap`,children:[e.actualFireAt?(0,G.jsx)(yk,{value:e.actualFireAt}):`—`,u?(0,G.jsxs)(mx,{children:[(0,G.jsx)(hx,{asChild:!0,children:(0,G.jsx)(`span`,{className:`inline-flex text-info-indicator`,children:(0,G.jsx)(Wx,{className:`size-icon-sm`})})}),(0,G.jsxs)(gx,{children:[`Published `,r,` after the scheduled fire time`]})]}):null]})}),(0,G.jsx)(Z.Cell,{children:e.run?(0,G.jsx)(T,{as:`span`,variant:`body-sm`,font:`mono`,children:$S(e.run.durationMs)||`—`}):(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:`—`})}),(0,G.jsx)(Z.Cell,{children:` `})]});return m?(0,G.jsx)(Z.RowLink,{to:s.workflowRunLink(n,e.runId),LinkComponent:o,...d(f),children:g},p):(0,G.jsx)(Z.RowStatic,{children:g},p)}),(0,G.jsx)(Z.NextPageLoading,{isLoading:i,hasMore:r,setEndOfListElement:a})]})}var _Wi={id:`workflow-schedules`,label:`Schedules`,icon:HS,to:`/workflows/schedules`};function vWi({label:e,children:t}){return(0,G.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,G.jsx)(T,{variant:`meta`,tone:`muted`,className:`uppercase`,children:e}),(0,G.jsx)(`div`,{children:(0,G.jsx)(T,{as:`span`,variant:`body`,className:`block`,children:t})})]})}function yWi(){let{scheduleId:e}=wv(),t=[AR(`/workflows`),_Wi,{id:`schedule`,label:lnn(e),icon:HS}],{paths:n}=on(),{data:r,error:i}=Enn({scheduleId:e,queryOptions:{enabled:!!e}}),{data:a,isLoading:o,error:s,hasNextPage:c,isFetchingNextPage:l,setEndOfListElement:u}=Onn({scheduleId:e,queryOptions:{enabled:!!e}}),d=knn({scheduleId:e});if(i&&JN(i))return(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:t}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:e}),(0,G.jsx)(vR,{variant:`fill`})]});if(i&&YN(i))return(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:t}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:e}),(0,G.jsx)(_R,{variant:`fill`,resource:`schedules`})]});if(i)return(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:t}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:e}),(0,G.jsx)(Vx,{tone:`error`,variant:`fill`,titleSlot:`Failed to load schedule`,descriptionSlot:i.message})]});let f=r?.workflowId,p=r?.agentId;return(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:t}),actionRow:(0,G.jsx)(EP,{children:(0,G.jsxs)(EP.End,{children:[(0,G.jsx)(X,{render:(0,G.jsx)(kv,{to:n.schedulesLink()}),variant:`ghost`,icon:(0,G.jsx)(eS,{}),children:`Back to schedules`}),f?(0,G.jsx)(X,{icon:(0,G.jsx)(KS,{}),render:(0,G.jsx)(kv,{to:n.workflowLink(f)}),variant:`ghost`,children:`Open workflow`}):null,r&&r.status!==`completed`?(0,G.jsx)(X,{onClick:()=>{let e=r.status===`active`?`pause`:`resume`;d.mutate(e,{onSuccess:()=>Qx.success(e===`pause`?`Schedule paused`:`Schedule resumed`),onError:e=>Qx.error(e.message)})},icon:r.status===`active`?(0,G.jsx)(AD,{}):(0,G.jsx)(jD,{}),loading:d.isPending,"data-testid":`schedule-toggle-button`,children:r.status===`active`?`Pause`:`Resume`}):null]})}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:e}),r?(0,G.jsxs)(`div`,{className:`grid h-full grid-cols-[minmax(0,20rem)_1fr] gap-4 overflow-hidden`,children:[(0,G.jsxs)(`div`,{className:`flex h-fit flex-col gap-4 rounded-md border border-border p-4`,children:[(0,G.jsx)(vWi,{label:p?`Agent`:`Workflow`,children:f?(0,G.jsx)(kv,{to:n.workflowLink(f),className:`text-foreground hover:underline`,children:f}):p?(0,G.jsx)(kv,{to:n.agentLink(p),className:`text-foreground hover:underline`,children:p}):`—`}),(0,G.jsxs)(vWi,{label:r.cron?`Cron`:`Runs at`,children:[(0,G.jsx)(T,{as:`span`,variant:`body`,font:`mono`,children:r.cron??(r.runAt?new Date(r.runAt).toLocaleString():`—`)}),r.endAt?(0,G.jsxs)(`span`,{className:`ml-2 text-caption text-muted-foreground`,children:[`until `,new Date(r.endAt).toLocaleString()]}):null,r.timezone?(0,G.jsx)(T,{as:`span`,variant:`caption`,tone:`muted`,className:`ml-2`,children:r.timezone}):null]}),(0,G.jsx)(vWi,{label:`Status`,children:(0,G.jsx)(uWi,{status:r.status})}),(0,G.jsx)(vWi,{label:`Next fire`,children:r.nextFireAt?(0,G.jsx)(yk,{value:r.nextFireAt}):`—`})]}),(0,G.jsxs)(`div`,{className:`overflow-y-auto`,"data-testid":`schedule-triggers-panel`,children:[(0,G.jsx)(T,{variant:`body`,className:`mb-3`,children:`Trigger history`}),s?(0,G.jsx)(Vx,{tone:`error`,titleSlot:`Failed to load trigger history`,descriptionSlot:s.message}):(0,G.jsx)(gWi,{triggers:a??[],isLoading:o,workflowId:f,hasNextPage:c,isFetchingNextPage:l,setEndOfListElement:u})]})]}):null]})}var bWi={target:e=>e.workflowId??e.agentId??``,status:e=>e.status,nextFireAt:e=>e.nextFireAt,lastFireAt:e=>e.lastFireAt},xWi=`minmax(0, 1.2fr) minmax(0, 1.4fr) minmax(0, 1fr) auto auto auto`;function SWi({schedules:e,isLoading:t,search:n=``,sort:r,onSortChange:i}){let{paths:a,Link:o}=on(),s=(0,W.useMemo)(()=>{let t=n.toLowerCase();return P6(t?e.filter(e=>e.id.toLowerCase().includes(t)||(e.workflowId??e.agentId??``).toLowerCase().includes(t)):e,r,bWi)},[e,n,r]),{containerRef:c,getRowProps:l}=UP({count:s.length,global:!0});if(t)return(0,G.jsx)(QP,{columns:xWi});let u=(e,t)=>i?(0,G.jsx)(Z.SortableTopCell,{sortKey:e,sort:r?.key===e?r.direction:void 0,onSortChange:i,children:t}):(0,G.jsx)(Z.TopCell,{children:t});return(0,G.jsxs)(Z,{columns:xWi,className:`min-w-0`,scrollRef:c,children:[(0,G.jsxs)(Z.Top,{children:[u(`target`,`Target`),(0,G.jsx)(Z.TopCell,{children:`Schedule ID`}),(0,G.jsx)(Z.TopCell,{children:`Cron`}),u(`status`,`Status`),u(`nextFireAt`,`Next fire`),u(`lastFireAt`,`Last run`)]}),s.length===0&&n?(0,G.jsx)(Z.NoMatch,{message:`No schedules match your search`}):null,s.length===0&&!n?(0,G.jsx)(Z.NoMatch,{message:`No schedules configured`}):null,s.map((e,t)=>(0,G.jsxs)(Z.RowLink,{to:a.scheduleLink(e.id),LinkComponent:o,...l(t),children:[(0,G.jsx)(Z.NameCell,{children:e.workflowId??e.agentId}),(0,G.jsx)(Z.Cell,{className:`min-w-0`,children:(0,G.jsx)(T,{as:`span`,variant:`body-sm`,tone:`muted`,font:`mono`,className:`block truncate`,title:e.id,children:e.id})}),(0,G.jsx)(Z.Cell,{children:(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-2 whitespace-nowrap`,children:[(0,G.jsx)(T,{as:`span`,variant:`caption`,font:`mono`,children:e.cron??(e.runAt?`once @ ${new Date(e.runAt).toLocaleString()}`:`—`)}),e.timezone?(0,G.jsx)(T,{as:`span`,variant:`meta`,tone:`muted`,children:e.timezone}):null]})}),(0,G.jsx)(Z.Cell,{children:(0,G.jsx)(uWi,{status:e.status})}),(0,G.jsx)(Z.Cell,{children:e.nextFireAt?(0,G.jsx)(yk,{value:e.nextFireAt}):`—`}),(0,G.jsx)(Z.Cell,{children:e.lastRun?(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-2 whitespace-nowrap`,children:[(0,G.jsx)(dWi,{status:e.lastRun.status}),e.lastFireAt?(0,G.jsx)(T,{as:`span`,variant:`caption`,tone:`muted`,children:(0,G.jsx)(yk,{value:e.lastFireAt})}):null]}):e.lastFireAt?(0,G.jsx)(yk,{value:e.lastFireAt}):(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:`Never`})})]},e.id))]})}function CWi({workflowId:e}={}){let{data:t,isLoading:n,error:r}=MR(e?{workflowId:e}:{}),[i,a]=(0,W.useState)(``),[o,s]=(0,W.useState)();return r?(0,G.jsx)(Vx,{tone:`error`,titleSlot:`Failed to load schedules`,descriptionSlot:r.message}):(0,G.jsxs)(`div`,{className:`grid h-full grid-rows-[auto_1fr] gap-4 overflow-hidden`,children:[(0,G.jsx)(`div`,{className:`max-w-120`,children:(0,G.jsx)(CN,{...wN,onValueChange:a,label:`Search schedules`,placeholder:`Search by id or workflow`})}),(0,G.jsx)(`div`,{className:`overflow-y-auto`,children:(0,G.jsx)(SWi,{schedules:t??[],isLoading:n,search:i,sort:o,onSortChange:(e,t)=>s({key:t,direction:e})})})]})}var wWi=[AR(`/workflows`),_Wi];function TWi(){let[e]=Av(),t=e.get(`workflowId`)??void 0,{error:n}=MR(t?{workflowId:t}:{});return n&&JN(n)?(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:wWi}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`Schedules`}),(0,G.jsx)(vR,{variant:`fill`})]}):n&&YN(n)?(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:wWi}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`Schedules`}),(0,G.jsx)(_R,{variant:`fill`,resource:`schedules`})]}):(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:wWi}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`Schedules`}),(0,G.jsx)(`div`,{className:`h-full`,children:(0,G.jsx)(CWi,{workflowId:t})})]})}var EWi=H(`IconArrowDownLeft`,()=>(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`path`,{d:`M6 9V18H15`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`}),(0,G.jsx)(`path`,{d:`M17.75 6.25L7 17`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`})]}),3),DWi={"--belt-hue":`var(--warning-indicator)`};function OWi(e){let t=new Blob([JSON.stringify(e??null)]).size;return t<1024?`${t} B`:`${(t/1024).toFixed(1)} KB`}function kWi(e,t){if(e&&typeof e==`object`&&!Array.isArray(e)){let t=Object.keys(e),[n]=t;if(t.length===1&&n)return n}return t}function AWi({suspendedSteps:e,workflow:t,isStreaming:n,onResume:r}){return n||e.length===0?null:(0,G.jsxs)(`section`,{className:c(ZDt,`pointer-events-auto relative isolate`),"data-testid":`workflow-suspended-steps`,"aria-label":`Step suspended`,children:[(0,G.jsxs)(`div`,{className:`max-h-[calc(100cqh-64px)] overflow-y-auto overscroll-contain rounded-[inherit]`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-3 border-b border-border bg-background px-5 py-4`,children:[(0,G.jsxs)(T,{as:`h2`,variant:`column`,tone:`ink`,className:`flex items-center gap-2`,children:[(0,G.jsx)(vx,{children:(0,G.jsx)(AD,{})}),`Step suspended`]}),(0,G.jsx)(YS,{variant:`orange`,emphasis:`subtle`,children:`Needs input`})]}),e.map(e=>{let n=t.allSteps[e.stepId];if(!n||n.isWorkflow)return null;let i=n?.resumeSchema?MO(JO(n.resumeSchema)):Dd(K(),fd());return(0,G.jsx)(jWi,{step:e,stepSchema:i,description:n.description,onResume:r},`${e.runId}-${e.stepId}`)})]}),(0,G.jsx)(kZe,{status:`ready`,label:`Needs input`,className:`before:hidden`,style:DWi})]})}function jWi({step:e,stepSchema:t,description:n,onResume:r}){let[i,a]=(0,W.useState)(!1),[o,s]=(0,W.useState)(!1);return(0,G.jsxs)(`div`,{className:`space-y-5 p-5 [&+&]:border-t [&+&]:border-border`,children:[(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(T,{as:`p`,variant:`subheading`,tone:`ink`,className:`break-words`,children:e.stepId}),n&&(0,G.jsx)(T,{as:`p`,variant:`caption`,tone:`muted`,children:n})]}),e.suspendPayload!==void 0&&(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(T,{as:`p`,variant:`caption`,tone:`muted`,className:`flex items-center gap-2`,children:[(0,G.jsx)(vx,{children:(0,G.jsx)(EWi,{})}),`The step is asking`]}),(0,G.jsxs)(SC,{open:i,onOpenChange:a,children:[(0,G.jsxs)(CC,{className:c(`bg-card hover:bg-card active:bg-card shadow-raised [--field:var(--field-on-surface)] [--field-disabled:var(--field-on-surface)] [--field-hover:var(--field-hover-on-surface)] [--field-open:var(--field-open-on-surface)]`,`flex w-full items-center justify-between gap-2 rounded-lg px-3 py-2.5`),children:[(0,G.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[(0,G.jsx)(vx,{children:(0,G.jsx)(y,{direction:`right`,className:`text-muted-foreground`})}),(0,G.jsx)(T,{as:`span`,variant:`body`,tone:`ink`,className:`truncate`,children:kWi(e.suspendPayload,e.stepId)})]}),(0,G.jsx)(T,{as:`span`,variant:`caption`,tone:`muted`,className:`shrink-0`,children:OWi(e.suspendPayload)})]}),(0,G.jsx)(wC,{children:(0,G.jsx)(`div`,{"data-testid":`suspended-payload`,className:`pt-2`,children:(0,G.jsx)(hw,{value:JSON.stringify(e.suspendPayload,null,2),editable:!1,className:`w-full overflow-x-auto p-2`,showCopyButton:!1})})})]})]}),(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(T,{as:`p`,variant:`caption`,tone:`muted`,className:`flex items-center gap-2`,children:[(0,G.jsx)(vx,{children:(0,G.jsx)(kI,{})}),`Your response`]}),(0,G.jsx)(`div`,{className:`-mx-5`,children:(0,G.jsx)(pDt,{schema:t,isSubmitLoading:o,submitButtonLabel:`Resume`,submitButtonVariant:`primary`,submitButtonIcon:(0,G.jsx)(jD,{}),submitButtonFullWidth:!0,collapsible:!1,hideHeading:!0,hideInputTypeLabel:!0,onSubmit:async t=>{s(!0);try{await r({stepId:e.stepId.split(`.`),runId:e.runId,resumeData:t})}catch(e){Qx.error(e instanceof Error?e.message:`Error resuming workflow`)}finally{s(!1)}}})})]})]})}function MWi({hidden:e,requestContext:t,canResume:n}){let{result:r,workflow:i,runId:a,isStreamingWorkflow:o}=(0,W.useContext)(zS),s=tmt(r,a),c=omt(t),l=r?.status===`suspended`&&s.length>0&&!o;return!i||!l||!n?null:(0,G.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:(0,G.jsx)(AWi,{suspendedSteps:s,workflow:i,isStreaming:o,onResume:c})},a)}var NWi=H(`IconSkip`,()=>(0,G.jsx)(`path`,{d:`M19 5V19M6.52732 5.16646L15.5625 11.1835C16.1458 11.5719 16.1458 12.4281 15.5625 12.8165L6.52732 18.8335C5.87447 19.2683 5 18.8008 5 18.017V5.98298C5 5.1992 5.87447 4.7317 6.52732 5.16646Z`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`})),PWi={success:{label:`Completed`,icon:cC},failed:{label:`Failed`,icon:Bx},suspended:{label:`Needs input`,icon:AD},waiting:{label:`Waiting`,icon:GS},paused:{label:`Paused`,icon:AD},skipped:{label:`Skipped`,icon:NWi},running:{label:`Running`,icon:BM},canceled:{label:`Canceled`,icon:zx}},FWi={label:`Status unavailable`,icon:uX};function IWi({row:e,isSelected:t,isHovered:n,onSelectStep:r,onHoverStep:i,onOpenInput:a,onOpenOutput:o}){let s=Object.hasOwn(PWi,e.status)?PWi[e.status]:FWi,l=s.icon,u=Ght(e.status),d=e.stepId.slice(0,e.stepId.lastIndexOf(`.`)),f=e.isNestedEntry?e.stepId.slice(e.stepId.lastIndexOf(`.`)+1):e.stepId;return(0,G.jsxs)(`div`,{"data-testid":`workflow-timeline-row`,"data-workflow-step-key":e.stepId,onMouseEnter:()=>!e.isNestedEntry&&i(e.stepId),onMouseLeave:()=>!e.isNestedEntry&&i(null),className:c(`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:[(0,G.jsxs)(`button`,{type:`button`,"aria-disabled":e.isNestedEntry,"aria-pressed":t,onClick:()=>{e.isNestedEntry||r(e.stepId)},title:e.stepId,className:c(`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`,p),children:[(0,G.jsx)(`span`,{"aria-label":s.label,className:c(`grid size-6 flex-none place-items-center rounded-md bg-nested`,Kht[u]),children:(0,G.jsx)(l,{"aria-hidden":!0,className:c(`size-3.5`,e.status===`running`&&`motion-safe:animate-spin`)})}),(0,G.jsxs)(`span`,{className:`min-w-0`,children:[(0,G.jsx)(T,{as:`span`,variant:`meta`,className:`block truncate`,children:f}),e.isNestedEntry&&(0,G.jsxs)(T,{as:`span`,variant:`meta`,tone:`muted`,className:`flex min-w-0 items-center gap-1`,children:[(0,G.jsx)(JXe,{"aria-hidden":!0,className:`size-icon-xs shrink-0`}),(0,G.jsx)(`span`,{className:`truncate`,children:d})]})]})]}),(0,G.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&&(0,G.jsx)(`div`,{"data-testid":`workflow-timeline-bar`,"data-offset":e.timing.offsetPct,"data-width":e.timing.widthPct,className:c(`absolute top-0 h-full min-w-0.5 rounded-sm`,qht[u]),style:{left:`${e.timing.offsetPct}%`,width:`${e.timing.widthPct}%`}})}),(0,G.jsx)(T,{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?(0,G.jsx)(T,{as:`span`,variant:`meta`,font:`mono`,children:$S(e.timing.durationMs)}):(0,G.jsx)(`span`,{"aria-label":`Timing unavailable`,children:`—`})}),(0,G.jsxs)(`div`,{className:`flex items-center`,children:[(0,G.jsx)(X,{type:`button`,variant:`ghost`,size:`icon-sm`,tooltip:`View step input`,disabled:e.step.input===void 0,onClick:t=>a(e,t.currentTarget),children:(0,G.jsx)(fk,{})}),(0,G.jsx)(X,{type:`button`,variant:`ghost`,size:`icon-sm`,tooltip:`View step output`,disabled:e.step.output===void 0,onClick:t=>o(e,t.currentTarget),children:(0,G.jsx)(dk,{})})]})]})}var LWi=e=>e.includes(`.`),RWi=e=>e===`input`||e.endsWith(`.input`),zWi=1;function BWi(e,t){let n=Xht(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 VWi(e,t){let n=Object.entries(e).filter(([e])=>!RWi(e)).map(([e,n])=>({stepId:e,step:n,...BWi(n,t)})).sort((e,t)=>(e.span?.start??1/0)-(t.span?.start??1/0)||e.stepId.localeCompare(t.stepId)),r=n.flatMap(e=>e.span?[e.span]:[]),i=Math.min(...r.map(e=>e.start)),a=Math.max(i,...r.map(e=>e.end)),o=Math.max(a-i,1);return n.map(({stepId:e,step:t,span:n,isLive:r,spansSuspension:a})=>{let s;if(n){let e=n.end-n.start,t=Math.min((n.start-i)/o*100,99);s={durationMs:e,offsetPct:t,widthPct:Math.min(Math.max(e/o*100,zWi),100-t)}}return{stepId:e,step:t,status:gk(t)?`suspended`:t.status,timing:s,spansSuspension:a,isRunning:r,isNestedEntry:LWi(e)}})}var HWi=H(`IconChevronGrabberVertical`,()=>(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`path`,{d:`M8 8.99985L11.2929 5.70696C11.6834 5.31643 12.3166 5.31643 12.7071 5.70696L16 8.99985`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`}),(0,G.jsx)(`path`,{d:`M8 15L11.2929 18.2929C11.6834 18.6834 12.3166 18.6834 12.7071 18.2929L16 15`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`})]})),UWi=H(`IconChevronGrabberVerticalToward`,()=>(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`path`,{d:`M8 18.75L12 14.75L16 18.75`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`}),(0,G.jsx)(`path`,{d:`M8 5.25L12 9.25L16 5.25`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`})]}));function WWi(){let{steps:e}=p$(),{selectedStepId:t,hoverStepId:n,setSelectedStepId:r,setHoverStepId:i}=RS(),[a,o]=(0,W.useState)(()=>Date.now()),[s,l]=(0,W.useState)(!0),[u,d]=(0,W.useState)(!1),{showData:f}=KM(),p=(0,W.useRef)(null),m=VWi(e,a),h=m.some(e=>e.isRunning);return VJe(p,{enabled:h&&!s}),(0,W.useEffect)(()=>{if(!h||s)return;let e=setInterval(()=>o(Date.now()),100);return()=>clearInterval(e)},[h,s]),m.length===0?null:(0,G.jsx)(`div`,{"data-testid":`workflow-timeline`,className:`relative z-20 shrink-0 px-2 pb-2`,children:(0,G.jsxs)(SC,{open:!s,onOpenChange:e=>l(!e),className:c(Pv,`@container/workflow-timeline pointer-events-auto overflow-hidden rounded-xl`),children:[(0,G.jsxs)(`div`,{className:`flex items-center`,children:[(0,G.jsxs)(CC,{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":s?`Expand timeline`:`Collapse timeline`,children:[(0,G.jsx)(`span`,{children:(0,G.jsx)(dG,{"aria-hidden":!0,className:`size-icon-md text-muted-foreground`})}),(0,G.jsx)(`span`,{children:`Timeline`}),(0,G.jsxs)(T,{as:`span`,variant:`meta`,tone:`muted`,children:[m.length,` events`]}),(0,G.jsx)(`span`,{className:`ml-auto`,children:(0,G.jsx)(y,{direction:`right`,className:`size-4`})})]}),!s&&(0,G.jsx)(X,{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?(0,G.jsx)(UWi,{}):(0,G.jsx)(HWi,{})})]}),(0,G.jsx)(wC,{children:(0,G.jsx)(`div`,{ref:p,"data-testid":`workflow-timeline-list`,className:c(`overflow-auto overscroll-contain px-1.5 pb-1.5`,u?`max-h-[min(720px,calc(100dvh-112px))]`:`max-h-[min(320px,40dvh)]`),children:m.map(e=>(0,G.jsx)(IWi,{row:e,isSelected:t===e.stepId,isHovered:n===e.stepId,onSelectStep:r,onHoverStep:i,onOpenInput:(e,t)=>f({type:`step-input`,stepId:e.stepId},t),onOpenOutput:(e,t)=>f({type:`step-output`,stepId:e.stepId},t)},e.stepId))})})]})})}var GWi=({workflowId:e,workflow:t,isLoading:n})=>{let[r]=LS(`workflow`,e),{canExecute:i,isLoading:a}=aS(),{stepDetail:o}=KM(),s=Kw(),c=o?.type===`data`,l=(0,G.jsxs)(`div`,{className:`[container-type:size] relative h-full min-h-0`,children:[(0,G.jsx)(mpr,{workflowId:e,workflow:t,isLoading:n,requestContext:r}),(0,G.jsx)(MWi,{hidden:c,requestContext:r,canResume:!a&&i(`workflows`)}),c&&(0,G.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:(0,G.jsx)(h$,{requestContext:r})}),(0,G.jsx)(`div`,{className:`pointer-events-none absolute right-0 bottom-0 left-[var(--workflow-left-panel-width,0px)] z-20`,children:(0,G.jsx)(WWi,{})})]});return s&&o&&!c?(0,G.jsx)(`div`,{className:`h-full min-h-0 overflow-hidden`,children:(0,G.jsx)(h$,{requestContext:r})}):(0,G.jsxs)(`div`,{className:`relative h-full min-h-0`,children:[l,(0,G.jsxs)($3,{className:`pointer-events-none absolute inset-0 z-30 min-h-0 w-full min-w-0 p-2`,children:[(0,G.jsx)(X3,{id:`workflow-graph`,className:`pointer-events-none min-w-0`}),o&&!c&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(e6,{className:`pointer-events-auto`}),(0,G.jsx)(X3,{id:`workflow-step-detail`,minSize:300,maxSize:`60%`,defaultSize:420,className:`min-w-0`,children:(0,G.jsx)(`div`,{className:`pointer-events-auto h-full min-h-0 overflow-hidden rounded-studio-panel border border-border bg-background`,children:(0,G.jsx)(h$,{requestContext:r})})})]})]})]})},KWi=()=>{let{workflowId:e}=wv(),{data:t,isLoading:n,error:r}=GM({workflowId:e,requestContext:LS(`workflow`,e)[0],queryOptions:{enabled:!!e}});return r&&JN(r)?(0,G.jsx)(vR,{variant:`fill`}):r&&YN(r)?(0,G.jsx)(_R,{variant:`fill`,resource:`workflows`}):(0,G.jsx)(GWi,{workflowId:e,workflow:t??void 0,isLoading:n})};function qWi(){let{workflowId:e}=wv(),{error:t}=MR(e?{workflowId:e}:{});if(!e)return null;let n;return n=t&&JN(t)?(0,G.jsx)(vR,{variant:`fill`}):t&&YN(t)?(0,G.jsx)(_R,{variant:`fill`,resource:`schedules`}):(0,G.jsx)(`div`,{className:`h-full`,children:(0,G.jsx)(CWi,{workflowId:e})}),(0,G.jsxs)(NS,{variant:`page`,children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`Schedules`}),n]})}function JWi(){let{workflowId:e}=wv();return e?(0,G.jsx)(Nbi,{scopedEntityId:e,scopedEntityType:Sp.WORKFLOW_RUN}):null}var YWi=(0,W.createContext)(null);function K9(){let e=(0,W.useContext)(YWi);if(!e)throw Error(`Workspace components must be rendered inside <Workspace.Root>`);return e}var XWi=e=>e?.status;function ZWi(e,t){return JN(e)?`Your session has expired. Sign in again to continue.`:YN(e)?`You don't have permission to access this.`:XN(e)?`This path no longer exists.`:XWi(e)===501?`This workspace does not support this operation.`:t}function QWi({error:e,fallback:t,className:n}){return(0,G.jsx)(mk,{variant:`destructive`,className:n,children:(0,G.jsx)(mk.Message,{children:ZWi(e,t)})})}var $Wi=/^---\r?\n([\s\S]*?)\r?\n---[ \t]*(?:\r?\n|$)/;function eGi(e){let t=$Wi.exec(e);return t?{frontmatter:t[1]??``,body:e.slice(t[0].length)}:{frontmatter:null,body:e}}function tGi({content:e}){let{frontmatter:t,body:n}=eGi(e);return(0,G.jsxs)(G.Fragment,{children:[t!==null&&(0,G.jsx)(`div`,{"data-testid":`workspace-frontmatter`,className:`border-b border-border`,children:(0,G.jsx)(MI,{code:t,lang:`yaml`,overflow:`wrap`,className:`rounded-none border-0 bg-transparent [&_pre]:p-4`})}),(0,G.jsx)(`div`,{className:`p-4`,children:(0,G.jsx)(BL,{children:n})})]})}function nGi(){let{activeFilePath:e}=K9();return e?(0,G.jsx)(T,{as:`span`,variant:`body-sm`,font:`mono`,tone:`muted`,className:`truncate`,"data-testid":`workspace-file-path`,children:e}):null}function rGi({path:e,content:t,mimeType:n}){return a6n(e,n)?(0,G.jsx)(`div`,{className:`flex justify-center p-4`,children:(0,G.jsx)(`img`,{src:`data:${n||`image/png`};base64,${t}`,alt:e.split(`/`).pop(),className:`max-w-full object-contain`})}):o6n(e,n)?(0,G.jsx)(`div`,{className:`flex justify-center p-4`,children:(0,G.jsx)(`video`,{controls:!0,"aria-label":e.split(`/`).pop(),className:`max-w-full`,children:(0,G.jsx)(`source`,{src:`data:${c6n(e,n)};base64,${t}`,type:c6n(e,n)})})}):l6n(e)?(0,G.jsx)(tGi,{content:t}):(0,G.jsx)(MI,{code:t,lang:lZe(e),overflow:`scroll`,className:`rounded-none border-0 bg-transparent [&_pre]:p-4`})}function iGi({renderPreview:e}){let{workspaceId:t,activeFilePath:n}=K9(),{data:r,isLoading:i,error:a}=w6n({workspaceId:t,path:n,queryOptions:{enabled:!!n}});if(!n)return null;if(i)return(0,G.jsxs)(`div`,{"aria-busy":`true`,className:`flex flex-col gap-2 p-4`,children:[(0,G.jsx)(PS,{className:`h-4 w-1/2`}),(0,G.jsx)(PS,{className:`h-4 w-5/6`}),(0,G.jsx)(PS,{className:`h-4 w-2/3`})]});if(!r)return(0,G.jsx)(QWi,{error:a,fallback:`Could not load file.`,className:`m-4`});let o={path:n,content:r.content,mimeType:r.mimeType};return e?.(o)??(0,G.jsx)(rGi,{...o})}var aGi=(e,t)=>e===`.`?t:`${e}/${t}`,oGi=e=>e.split(`/`).slice(0,-1).map((e,t,n)=>n.slice(0,t+1).join(`/`)),sGi=e=>{let t=e.lastIndexOf(`/`);return t===-1?`.`:e.slice(0,t)};function cGi({labeled:e=!1}={}){let{workspaceId:t,onCreateDirectory:n,isReadOnly:r}=K9(),i=a_(),[a,o]=(0,W.useState)(!1),[s,c]=(0,W.useState)(``),[l,u]=(0,W.useState)(!1);if(!n||r(`.`))return null;let d=s.trim().replace(/^\.?\/+|\/+$/g,``),f=async()=>{if(d){u(!0);try{await n(d),await i.invalidateQueries({queryKey:[`workspace`,t,`fs`,`list`,sGi(d)]}),o(!1),c(``)}catch{}finally{u(!1)}}};return(0,G.jsxs)(G.Fragment,{children:[e?(0,G.jsx)(X,{variant:`ghost`,icon:(0,G.jsx)(pP,{}),onClick:()=>o(!0),children:`New folder`}):(0,G.jsx)(X,{variant:`ghost`,size:`icon-sm`,tooltip:`New folder`,onClick:()=>o(!0),children:(0,G.jsx)(pP,{})}),(0,G.jsx)(Zw,{open:a,onOpenChange:o,pending:l,children:(0,G.jsx)(Qw,{size:`sm`,children:(0,G.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),f()},children:[(0,G.jsx)($w,{children:(0,G.jsx)(nT,{children:`New folder`})}),(0,G.jsx)(tT,{children:(0,G.jsx)(Bj,{autoFocus:!0,"aria-label":`Folder path`,placeholder:`docs/guides`,value:s,onChange:e=>c(e.target.value)})}),(0,G.jsxs)(eT,{children:[(0,G.jsx)(iT,{children:`Cancel`}),(0,G.jsx)(X,{type:`submit`,variant:`primary`,disabled:!d,loading:l,children:`Create`})]})]})})})]})}function lGi(e){return`${e.topSource}/${e.name}`}function uGi(e){let t=p6n(e.topSource,e.name);return t?`${t.owner}/${t.repo}/${e.name}`:null}function dGi({open:e,onOpenChange:t,workspaceId:n,onInstall:r,isInstalling:i,installedSkillIds:a=[],installedSkillNames:o=[],writableMounts:s,installedSkillPaths:l}){let[u,d]=(0,W.useState)(``),[f,p]=(0,W.useState)(null),[m,h]=(0,W.useState)(),g=s?.some(e=>e.path===m)?m:s?.[0]?.path,{data:_,isLoading:v}=d6n({workspaceId:n,queryOptions:{enabled:!!n}}),y=u6n({workspaceId:n}),b=(0,W.useMemo)(()=>f?.topSource?p6n(f.topSource,f.name):null,[f]),x=(0,W.useMemo)(()=>!b||!f?null:`https://skills.sh/${b.owner}/${b.repo}/${f.name}`,[b,f]),{data:S,isLoading:C}=f6n({workspaceId:n,owner:b?.owner,repo:b?.repo,skillPath:f?.name,queryOptions:{enabled:!!n&&!!b&&!!f}}),w=rC(e=>{e.trim().length>=2&&y.mutate(e)},300),E=(0,W.useCallback)(e=>{d(e),w(e)},[w]),D=(0,W.useMemo)(()=>u.trim().length>=2?y.data?.skills??[]:_?.skills??[],[u,y.data,_]),O=y.isPending,k=u.trim().length>=2,A=(0,W.useMemo)(()=>{if(!f)return!1;let e=uGi(f);return!!(e&&a.includes(e)||o.includes(f.name))},[f,a,o]),j=(0,W.useCallback)(()=>{f&&b&&r({repository:`${b.owner}/${b.repo}`,skillName:f.name,mount:s&&s.length>1?g:void 0})},[f,b,r,s,g]),M=(0,W.useCallback)(e=>{e||(d(``),p(null),h(void 0)),t(e)},[t]);return(0,G.jsx)(Zw,{open:e,onOpenChange:M,pending:i,children:(0,G.jsxs)(Qw,{size:`xl`,className:`h-[80vh]`,children:[(0,G.jsxs)($w,{children:[(0,G.jsx)(nT,{children:`Add Skill`}),(0,G.jsx)(rT,{children:`Search and install skills from the community registry`})]}),(0,G.jsxs)(tT,{layout:`fill`,children:[(0,G.jsx)(CN,{label:`Search skills`,placeholder:`Search skills`,value:u,onValueChange:E}),(0,G.jsxs)(`div`,{className:`flex min-h-0 flex-1 gap-4`,children:[(0,G.jsxs)(`div`,{className:`flex min-h-0 w-1/2 flex-col`,children:[(0,G.jsx)(T,{as:`p`,variant:`eyebrow`,tone:`muted`,className:`mb-2`,children:k?`Search Results`:`Popular Skills`}),(0,G.jsx)(AS,{className:`flex-1 rounded-lg border border-border`,children:(0,G.jsx)(kS,{className:!v&&!O&&D.length===0?`flex flex-col [&>div]:flex [&>div]:flex-1 [&>div]:flex-col`:void 0,children:v||O?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-5`,children:(0,G.jsx)(Mv,{className:`text-muted-foreground`})}):D.length===0?(0,G.jsx)(Vx,{className:`flex-1`,titleSlot:k?`No skills found`:`No skills available`}):(0,G.jsx)(`div`,{className:`space-y-1 p-2`,children:D.map(e=>{let t=lGi(e),n=uGi(e),r=n&&a.includes(n)||o.includes(e.name),i=f?lGi(f):null;return(0,G.jsx)(`button`,{onClick:()=>p(e),className:c(`w-full rounded-md px-3 py-2 text-left`,`hover:bg-fill-subtle`,i===t&&`border border-border-strong bg-fill-hover`),children:(0,G.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(T,{as:`span`,variant:`subheading`,tone:`ink`,className:`truncate`,children:e.name}),r&&(0,G.jsxs)(T,{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:[(0,G.jsx)(cC,{className:`size-icon-xs`}),`Installed`]})]}),(0,G.jsx)(T,{as:`p`,variant:`caption`,tone:`muted`,className:`truncate`,children:e.topSource})]}),(0,G.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1 text-muted-foreground`,children:[(0,G.jsx)(SI,{className:`size-icon-xs`}),(0,G.jsx)(T,{as:`span`,variant:`caption`,children:e.installs.toLocaleString()})]})]})},t)})})})})]}),(0,G.jsxs)(`div`,{className:`flex min-h-0 w-1/2 flex-col`,children:[(0,G.jsx)(T,{as:`p`,variant:`eyebrow`,tone:`muted`,className:`mb-2`,children:`Preview`}),(0,G.jsx)(`div`,{className:`flex flex-1 flex-col overflow-hidden rounded-lg border border-border`,children:f?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`border-b border-border bg-card p-4`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,G.jsx)(`div`,{className:`rounded-lg bg-muted p-2`,children:(0,G.jsx)(j6,{className:`size-icon-lg text-muted-foreground`})}),(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsx)(T,{as:`h3`,variant:`subheading`,tone:`ink`,className:`truncate`,children:f.name}),(0,G.jsxs)(`div`,{className:`mt-1 flex items-center gap-3 text-muted-foreground`,children:[(0,G.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(A6,{className:`size-icon-xs`}),(0,G.jsx)(T,{as:`span`,variant:`caption`,className:`block`,children:f.topSource})]}),(0,G.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(SI,{className:`size-icon-xs`}),(0,G.jsxs)(T,{as:`span`,variant:`caption`,className:`block`,children:[f.installs.toLocaleString(),` installs`]})]})]})]}),b&&(0,G.jsx)(`a`,{href:`https://github.com/${b.owner}/${b.repo}`,target:`_blank`,rel:`noopener noreferrer`,className:c(`text-muted-foreground hover:text-foreground`,`transition-[color] duration-fast ease-out-custom motion-reduce:transition-none`),title:`View on GitHub`,children:(0,G.jsx)(nF,{className:`size-icon-md`})})]})}),C?(0,G.jsx)(`div`,{className:`flex flex-1 items-center justify-center`,children:(0,G.jsx)(Mv,{className:`text-muted-foreground`})}):S?(0,G.jsx)(AS,{className:`flex-1`,children:(0,G.jsx)(`div`,{className:`p-4`,children:(0,G.jsx)(BL,{children:S})})}):(0,G.jsx)(Vx,{className:`flex-1`,iconSlot:(0,G.jsx)(k6,{}),titleSlot:`Preview unavailable`,actionSlot:x&&(0,G.jsxs)(`a`,{href:x,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center gap-1 text-info-indicator hover:underline`,children:[(0,G.jsxs)(T,{as:`span`,variant:`caption`,className:`block`,children:[`View on skills.sh`,` `]}),(0,G.jsx)(nF,{className:`size-icon-xs`})]})})]}):(0,G.jsx)(Vx,{variant:`fill`,iconSlot:(0,G.jsx)(k6,{}),titleSlot:`Select a skill to preview`})})]})]}),f&&s&&s.length>1&&(0,G.jsxs)(ZO,{orientation:`horizontal`,className:c(`bg-card hover:bg-card active:bg-card shadow-raised [--field:var(--field-on-surface)] [--field-disabled:var(--field-on-surface)] [--field-hover:var(--field-hover-on-surface)] [--field-open:var(--field-open-on-surface)]`,`gap-3 rounded-lg p-3`),children:[(0,G.jsx)(fP,{className:`size-icon-md shrink-0 text-muted-foreground`}),(0,G.jsx)($O,{className:`whitespace-nowrap`,children:`Install to`}),(0,G.jsxs)(Mk,{value:g,onValueChange:h,children:[(0,G.jsx)(Pk,{className:`flex-1`,children:(0,G.jsx)(Nk,{})}),(0,G.jsx)(Fk,{children:s.map(e=>{let t=e.displayName??e.name??e.provider??`unknown`;return(0,G.jsxs)(Ik,{value:e.path,children:[t,` (`,e.path,`)`]},e.path)})})]})]})]}),f&&(0,G.jsxs)(eT,{children:[A&&s&&s.length>1&&(()=>{let e=l?.[f.name];if(!e)return null;let t=s.find(t=>e.startsWith(t.path+`/`)||e===t.path);return t?(0,G.jsxs)(T,{as:`span`,variant:`caption`,tone:`muted`,className:`mr-auto`,children:[`Installed at `,t.path]}):null})(),(0,G.jsx)(iT,{children:`Cancel`}),(0,G.jsx)(Xw,{onConfirm:j,disabled:!b||A,"data-testid":`install-skill-button`,children:A?`Already installed`:`Install`})]})]})})}function fGi({labeled:e=!1}){let{workspaceId:t,addSkill:n}=K9(),[r,i]=(0,W.useState)(!1),[a,o]=(0,W.useState)(!1);if(!n)return null;let{onInstall:s,...c}=n,l=async e=>{o(!0);try{await s(e),i(!1)}catch{}finally{o(!1)}};return(0,G.jsxs)(G.Fragment,{children:[e?(0,G.jsx)(X,{icon:(0,G.jsx)(HXr,{}),variant:`ghost`,onClick:()=>i(!0),children:`Add skill`}):(0,G.jsx)(X,{variant:`ghost`,size:`icon-sm`,"aria-label":`Add skill`,tooltip:`Add skill`,onClick:()=>i(!0),children:(0,G.jsx)(HXr,{})}),(0,G.jsx)(dGi,{...c,open:r,onOpenChange:i,workspaceId:t,onInstall:e=>void l(e),isInstalling:a})]})}function pGi({workspaceId:e,activeFilePath:t,onDelete:n,onCreateDirectory:r,onActiveFileChange:i,readOnlyPaths:a,searchFiles:o=!0,searchSkills:s=!0,fileCount:c,skillCount:l,addSkill:u,children:d}){let[f,p]=(0,W.useState)(!1),[m,h]=(0,W.useState)(``),[g,_]=(0,W.useState)(()=>new Set(oGi(t??``))),[v,y]=(0,W.useState)(t);if(t!==v){y(t);let e=oGi(t??``).filter(e=>!g.has(e));e.length>0&&_(new Set([...g,...e]))}let b=a?.join(`
887
+ `).reduce((e,t)=>{if(!t||t.startsWith(`#`))return e;let[n,r]=t.split(`=`);return n&&(e[n]=r?.split(``)?.every(e=>e===`*`)?``:r?.replaceAll(`"`,``)),e},{}):{}}var tUi=({queryOptions:e}={})=>b_({queryKey:[`mastra-templates`],queryFn:ZHi,...e}),nUi=({repoOrSlug:e,owner:t,queryOptions:n})=>b_({queryKey:[`template-repo`,e,t],queryFn:()=>$Hi({repoOrSlug:e,owner:t}),...n}),rUi=({repo:e,owner:t,branch:n,queryOptions:r})=>b_({queryKey:[`template-repo-env-vars`,e,t,n],queryFn:()=>eUi({repo:e,owner:t,branch:n}),...r}),iUi=({queryOptions:e}={})=>{let t=Y();return b_({queryKey:[`agent-builder-workflow`],queryFn:async()=>await t.getAgentBuilderAction(`merge-template`).details(),...e})},aUi=({queryOptions:e}={})=>{let t=Y();return S_({mutationFn:async({runId:e})=>await t.getAgentBuilderAction(`merge-template`).createRun({runId:e}),...e})},oUi=({queryOptions:e}={})=>{let t=Y();return S_({mutationFn:async({runId:e})=>await t.getAgentBuilderAction(`merge-template`).runById(e),...e})},sUi=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)},cUi=(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((e,t)=>(e[t]={id:t,description:n.allSteps[t].description,status:`pending`},e),{})}}),e.type===`start`||e.type===`workflow-start`){let t={};n?.allSteps&&Object.entries(n.allSteps).forEach(([e,n])=>{t[e]={id:n.id,description:n.description,status:`pending`}});let i=e.runId||e.payload?.runId;r={...r,runId:i,eventTimestamp:new Date().toISOString(),status:`running`,phase:`initializing`,payload:{workflowState:{status:`running`,steps:t},currentStep:null}}}if(e.type===`step-start`||e.type===`workflow-step-start`){let t=e.payload.id;r={...r,phase:`processing`,payload:{...r.payload,currentStep:{id:t,status:`running`,startTime:new Date,...e.payload},workflowState:{...r.payload.workflowState,steps:{...r.payload.workflowState.steps,[t]:{...r.payload.workflowState.steps[t],status:`running`,startTime:new Date,...e.payload}}}}}}if(e.type===`step-result`||e.type===`workflow-step-result`){let t=e.payload.id,n=e.payload.status,i=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,[t]:{...r.payload.workflowState.steps[t],status:e.payload.status,output:e.payload.output,error:e.payload.error,endTime:new Date}}}}},n===`failed`&&i){let n=sUi(i);r={...r,status:`failed`,error:n,phase:`error`,failedStep:{id:t,error:n,description:e.payload.description||t},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=r.phase===`error`||r.status===`failed`?{...r,completedAt:new Date}:{...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`){let t=sUi(e.payload.error);r={...r,status:`failed`,error:t,phase:`error`,payload:{...r.payload,workflowState:{...r.payload.workflowState,status:`failed`}},errorTimestamp:new Date}}return{newState:r}},lUi=(e,t)=>{try{localStorage.setItem(`template-install-${e}`,JSON.stringify({state:t,timestamp:Date.now()}))}catch(e){console.warn(`Failed to save template state to localStorage:`,e)}},uUi=(e,t)=>{let[n,r]=(0,W.useState)({}),[i,a]=(0,W.useState)(!1);return{streamResult:n,isStreaming:i,processStream:async(n,i)=>{if(a(!0),r({}),!n)throw Error(`No stream returned`);let o=n.getReader(),s={runId:i||t,eventTimestamp:new Date().toISOString(),phase:`running`,payload:{workflowState:{steps:{}},currentStep:null}};try{for(;;){let{done:n,value:a}=await o.read();if(n)break;let{newState:c}=cUi(a,s,e);s=c,r(c),(a.runId||i||t)&&lUi(a.runId||i||t,c)}}catch(t){console.error(`💥 [processStream] Error processing template installation stream:`,t);let{newState:n}=cUi({type:`error`,payload:{error:t instanceof Error?t.message:`Unknown error`}},s,e);r(n)}finally{a(!1),o.releaseLock()}}}},dUi=({workflowInfo:e,queryOptions:t}={})=>{let n=Y(),{streamResult:r,isStreaming:i,processStream:a}=uUi(e);return{streamInstall:S_({mutationFn:async({inputData:e,selectedModel:t,runId:r})=>{for(let i=1;i<=3;i++)try{let i=n.getAgentBuilderAction(`merge-template`),o=new Dn;o.set(`selectedModel`,t);let s=await i.stream({inputData:e,requestContext:o},r);await a(s,r);return}catch(e){console.error(`💥 [streamInstall] Attempt ${i} failed:`,e);let t=e?.message?.includes(`Failed to fetch`)||e?.message?.includes(`NetworkError`)||e?.message?.includes(`network error`)||e?.message?.includes(`fetch`)||e?.code===`NETWORK_ERROR`||e?.name===`TypeError`;if(console.warn(`Stream attempt ${i}/3 failed:`,e),t){let e=r?`Network error during template installation (likely hot reload). Please refresh the page to resume from where you left off using runId: ${r}`:`Network error during template installation (likely hot reload). Please try again.`;throw console.error(`🔌 Stream network error:`,e),Error(e)}throw console.error(`❌ [streamInstall] Non-network error or max retries reached, throwing:`,e),e}},...t?.streamInstall}),streamResult:r,isStreaming:i}},fUi=({workflowInfo:e,queryOptions:t}={})=>{let n=Y(),{streamResult:r,isStreaming:i,processStream:a}=uUi(e);return{observeInstall:S_({mutationFn:async({runId:e})=>{let t=2e3;for(let r=1;r<=3;r++)try{let t=await n.getAgentBuilderAction(`merge-template`).observeStream({runId:e});await a(t,e);return}catch(e){console.error(`💥 [observeInstall] Attempt ${r} failed:`,e);let n=e?.message?.includes(`Failed to fetch`)||e?.message?.includes(`NetworkError`)||e?.message?.includes(`network error`)||e?.message?.includes(`fetch`)||e?.code===`NETWORK_ERROR`||e?.name===`TypeError`;if(console.warn(`ObserveStream attempt ${r}/3 failed:`,e),n&&r<3){console.info(`🔄 ObserveStream network error detected (likely hot reload), retrying in ${t}ms... (attempt ${r+1}/3)`),await new Promise(e=>setTimeout(e,t));continue}throw console.error(`❌ [observeInstall] Non-network error or max retries reached, throwing:`,e),e}},...t?.observeInstall}),streamResult:r,isStreaming:i}};function pUi(e){return e.replace(/\/$/,``).split(`/`).pop()}function mUi({templates:e,linkComponent:t,className:n,isLoading:r}){let i=t||`a`;return r?(0,G.jsx)(`div`,{className:c(`grid gap-y-4`,n),children:Array.from({length:5}).map((e,t)=>(0,G.jsx)(`div`,{className:`h-16 animate-pulse rounded-lg bg-card`},t))}):(0,G.jsx)(`div`,{className:c(`grid gap-y-4`,n),children:e.map(e=>{let t=e?.agents||e?.tools||e?.networks||e?.workflows||e?.mcp;return(0,G.jsxs)(`article`,{className:c(Pv,`grid w-full grid-cols-[1fr_auto] overflow-hidden rounded-lg state-layer`),children:[(0,G.jsxs)(i,{to:`/templates/${e.slug}`,className:c(`group grid`,{"grid-cols-[8rem_1fr] lg:grid-cols-[12rem_1fr]":e.imageURL}),children:[e.imageURL&&(0,G.jsx)(`div`,{className:`overflow-hidden`,children:(0,G.jsx)(`div`,{className:`thumb transition-scale h-full w-full bg-cover duration-150`,style:{backgroundImage:`url(${e.imageURL})`}})}),(0,G.jsxs)(`div`,{className:c(`grid w-full gap-0.5 px-4 py-3`,`[&_svg]:h-[1em] [&_svg]:w-[1em] [&_svg]:text-muted-foreground`),children:[(0,G.jsx)(T,{as:`h2`,tone:`ink`,children:e.title}),(0,G.jsx)(T,{className:c(gS,A),children:e.description}),(0,G.jsxs)(`div`,{className:`mt-3 hidden flex-wrap items-center gap-x-8 gap-y-4 text-muted-foreground 2xl:flex`,children:[t&&(0,G.jsxs)(`ul`,{className:c(`text-muted-foreground`,`m-0 flex list-none gap-4 p-0`,`[&>li]:flex [&>li]:items-center [&>li]:gap-0.5`),children:[e?.agents&&e.agents.length>0&&(0,G.jsx)(`li`,{children:(0,G.jsxs)(T,{as:`span`,variant:`body`,className:`block`,children:[(0,G.jsx)(WP,{}),` `,e.agents.length]})}),e?.tools&&e.tools.length>0&&(0,G.jsx)(`li`,{children:(0,G.jsxs)(T,{as:`span`,variant:`body`,className:`block`,children:[(0,G.jsx)(ZP,{}),` `,e.tools.length]})}),e?.networks&&e.networks.length>0&&(0,G.jsx)(`li`,{children:(0,G.jsxs)(T,{as:`span`,variant:`body`,className:`block`,children:[(0,G.jsx)(Mut,{}),` `,e.networks.length]})}),e?.workflows&&e.workflows.length>0&&(0,G.jsx)(`li`,{children:(0,G.jsxs)(T,{as:`span`,variant:`body`,className:`block`,children:[(0,G.jsx)(KS,{}),` `,e.workflows.length]})}),e?.mcp&&e.mcp.length>0&&(0,G.jsx)(`li`,{children:(0,G.jsxs)(T,{as:`span`,variant:`body`,className:`block`,children:[(0,G.jsx)(KP,{}),` `,e.mcp.length]})})]}),(0,G.jsx)(`div`,{className:`flex items-center gap-4`,children:e.supportedProviders.map(e=>(0,G.jsx)(T,{tone:`muted`,as:`span`,variant:`body`,children:e},e))})]})]})]}),(0,G.jsx)(`a`,{href:e.githubUrl,className:c(`group ml-auto hidden items-center gap-2 pr-4`,`lg:flex`),target:`_blank`,rel:`noopener noreferrer`,children:(0,G.jsx)(T,{as:`span`,variant:`body`,children:(0,G.jsxs)(`span`,{className:c(`flex items-center gap-2 rounded bg-nested px-2 py-1`,hBe,gS,A),children:[(0,G.jsx)(A6,{}),` `,pUi(e.githubUrl)]})})})]},e.slug)})})}function hUi({tagOptions:e,selectedTag:t,providerOptions:n,selectedProvider:r,onTagChange:i,onProviderChange:a,searchTerm:o,onSearchChange:s,onReset:l,className:u,isLoading:d}){return d?(0,G.jsxs)(`div`,{className:c(`flex h-[6.5rem] items-center gap-5`,`[&>div]:h-8 [&>div]:w-48 [&>div]:animate-pulse [&>div]:bg-card`,u),children:[(0,G.jsx)(`div`,{}),` `,(0,G.jsx)(`div`,{}),` `,(0,G.jsx)(`div`,{})]}):(0,G.jsxs)(`div`,{className:c(`sticky top-0 mx-auto flex flex-wrap gap-1.5 bg-background py-5`,u),children:[(0,G.jsx)(CN,{label:`Search templates`,placeholder:`Search templates`,size:`sm`,value:o,onValueChange:s}),(0,G.jsxs)(Mk,{value:t,onValueChange:i,children:[(0,G.jsx)(Pk,{"aria-label":`Search by tag`,size:`sm`,className:`w-auto`,children:(0,G.jsx)(Nk,{placeholder:`Select an option`})}),(0,G.jsx)(Fk,{children:e.map(e=>(0,G.jsx)(Ik,{value:e.value,children:e.label},e.value))})]}),(0,G.jsxs)(Mk,{value:r,onValueChange:a,children:[(0,G.jsx)(Pk,{"aria-label":`Search by provider`,size:`sm`,className:`w-auto`,children:(0,G.jsx)(Nk,{placeholder:`Select an option`})}),(0,G.jsx)(Fk,{children:n.map(e=>(0,G.jsx)(Ik,{value:e.value,children:e.label},e.value))})]}),l&&(0,G.jsx)(gLt,{onClick:l})]})}var gUi=[{id:`templates`,label:`Templates`}];function _Ui(){let{data:e,isLoading:t}=tUi(),{templates:n,tags:r,providers:i}=e??{templates:[],tags:[],providers:[]},[a,o]=(0,W.useState)(`all`),[s,c]=(0,W.useState)(`all`),[l,u]=(0,W.useState)(``),d=[{value:`all`,label:`Any tag`}];(r||[]).forEach(e=>{d.push({value:e,label:e})});let f=[{value:`all`,label:`Any provider`}];(i||[]).forEach(e=>{f.push({value:e,label:e})});let p=(e,t)=>{t===`tag`?o(e):t===`provider`&&c(e)},m=e=>{u(e)},h=()=>{o(`all`),c(`all`),u(``)},g=n.filter(e=>!(l&&!e.title.toLowerCase().includes(l)&&!e.description.toLowerCase().includes(l)||a!==`all`&&!e.tags.includes(a)||s!==`all`&&!e.supportedProviders.includes(s)));return(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:gUi}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`Templates`}),(0,G.jsx)(_S,{children:(0,G.jsxs)(zJe,{children:[(0,G.jsx)(vx,{children:(0,G.jsx)(k6,{})}),`Templates`]})}),(0,G.jsx)(hUi,{selectedTag:a,onTagChange:e=>p(e,`tag`),tagOptions:d,selectedProvider:s,onProviderChange:e=>p(e,`provider`),providerOptions:f,searchTerm:l,onSearchChange:m,onReset:l||a!==`all`||s!==`all`?h:void 0,isLoading:t}),(0,G.jsx)(mUi,{templates:g,linkComponent:kv,isLoading:t})]})}var vUi=H(`IconEmojiSad`,()=>(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`circle`,{cx:`12`,cy:`12`,r:`9`,stroke:`currentColor`,strokeWidth:`2`}),(0,G.jsx)(`path`,{d:`M10.75 9.9C10.75 11.0046 10.0784 11.75 9.25 11.75C8.42157 11.75 7.75 11.0046 7.75 9.9C7.75 8.79543 8.42157 8 9.25 8C10.0784 8 10.75 8.79543 10.75 9.9Z`,fill:`currentColor`}),(0,G.jsx)(`path`,{d:`M16.25 9.9C16.25 11.0046 15.5784 11.75 14.75 11.75C13.9216 11.75 13.25 11.0046 13.25 9.9C13.25 8.79543 13.9216 8 14.75 8C15.5784 8 16.25 8.79543 16.25 9.9Z`,fill:`currentColor`}),(0,G.jsx)(`path`,{d:`M7.89328 15.4758C7.7698 15.623 7.69925 15.8109 7.70417 16.0051C7.70903 16.1992 7.78791 16.3827 7.92489 16.5166C8.06187 16.6504 8.24712 16.7251 8.44131 16.7254C8.63557 16.7259 8.82181 16.651 8.9661 16.5242C9.05273 16.4499 9.14033 16.3801 9.23093 16.313C10.042 15.7109 11.0211 15.4001 12.0034 15.4C12.9856 15.3986 13.964 15.7081 14.7725 16.3111C14.8628 16.3783 14.9501 16.4481 15.0364 16.5226C15.1803 16.6498 15.3663 16.7253 15.5606 16.7254C15.7548 16.7256 15.9403 16.6515 16.0776 16.5181C16.215 16.3846 16.2944 16.2014 16.2999 16.0073C16.3054 15.8131 16.2354 15.625 16.1124 15.4774C16.0126 15.3603 15.909 15.2487 15.799 15.1403C14.816 14.1611 13.4082 13.5927 12.002 13.6C10.5957 13.595 9.19111 14.1644 8.20718 15.1399C8.09708 15.2479 7.99334 15.3591 7.89328 15.4758Z`,fill:`currentColor`})]}));function yUi({children:e,className:t}){return(0,G.jsx)(`div`,{className:c(`transition-height mt-12 rounded-lg border border-border px-4 py-5 lg:min-h-[25rem] lg:px-12`,t),children:e})}function bUi({errorMsg:e,validationErrors:t}){let n=typeof e==`string`?e:e==null?void 0:String(e),r=n?.includes(`Invalid schema for function`),i=n?.includes(`validation issue`)||t&&t.length>0,a=()=>i?`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.`,{icon:o,title:s}=i?{icon:(0,G.jsx)(Wx,{className:`text-warning-foreground`}),title:`Template Installed with Warnings`}:{icon:(0,G.jsx)(vUi,{}),title:`Template Installation Failed`};return(0,G.jsxs)(yUi,{className:`mb-5 content-center space-y-4 text-muted-foreground`,children:[(0,G.jsxs)(`div`,{className:`grid content-center items-center justify-items-center gap-4 [&>svg]:h-8 [&>svg]:w-8`,children:[o,(0,G.jsxs)(`div`,{className:`space-y-2 text-center`,children:[(0,G.jsx)(T,{variant:`subheading`,tone:`ink`,children:s}),(0,G.jsx)(T,{tone:`muted`,children:a()})]})]}),t&&t.length>0&&(0,G.jsxs)(`details`,{children:[(0,G.jsx)(`summary`,{className:c(`text-muted-foreground hover:text-foreground`,`cursor-pointer text-center select-none`),children:(0,G.jsxs)(T,{as:`span`,variant:`caption`,className:`block`,children:[`Show Validation Issues (`,t.length,`)`]})}),(0,G.jsx)(`div`,{className:`mt-4 max-h-60 space-y-2 overflow-auto rounded bg-muted p-3 text-left`,children:t.map((e,t)=>(0,G.jsxs)(`div`,{className:`border-l-2 border-destructive-indicator pl-2`,children:[(0,G.jsx)(T,{as:`p`,variant:`column`,className:`text-destructive-foreground`,children:e.type===`typescript`?`🔴 TypeScript Error`:`⚠️ Lint Error`}),(0,G.jsx)(aC,{className:`mt-1 text-caption wrap-break-word whitespace-pre-wrap text-muted-foreground`,code:e.message})]},t))})]}),n&&!i&&(0,G.jsxs)(`details`,{children:[(0,G.jsx)(`summary`,{className:c(`text-muted-foreground hover:text-foreground`,`cursor-pointer text-center select-none`),children:(0,G.jsx)(T,{as:`span`,variant:`caption`,className:`block`,children:`Show Details`})}),(0,G.jsx)(`div`,{className:`mt-4 max-h-60 overflow-auto rounded bg-muted p-3 text-left`,children:(0,G.jsx)(aC,{className:`text-caption wrap-break-word whitespace-pre-wrap`,code:n})})]})]})}function xUi({providerOptions:e,selectedProvider:t,onProviderChange:n,variables:r,errors:i,handleInstallTemplate:a,handleVariableChange:o,isLoadingEnvVars:s,isInstalling:l,defaultModelProvider:u,defaultModelId:d,onModelUpdate:f}){return(0,G.jsx)(yUi,{children:(0,G.jsxs)(`div`,{className:`mx-auto my-4 grid max-w-[40rem] gap-5 p-4 lg:p-5`,children:[(0,G.jsxs)(T,{as:`h2`,variant:`heading`,tone:`muted`,className:c(`flex items-center gap-2`,`[&_svg]:h-[1.2em] [&_svg]:opacity-70 [&>svg]:w-[1.2em]`),children:[`Install Template `,(0,G.jsx)(k6,{})]}),(0,G.jsxs)(ZO,{orientation:`horizontal`,children:[(0,G.jsx)($O,{children:`Template AI Model Provider`}),(0,G.jsx)(Fmt,{className:`flex-1`,children:(0,G.jsxs)(Mk,{name:`template-provider`,value:t,onValueChange:n,children:[(0,G.jsx)(Pk,{size:`md`,children:(0,G.jsx)(Nk,{placeholder:`Select`})}),(0,G.jsx)(Fk,{children:e.map(e=>(0,G.jsx)(Ik,{value:e.value,children:e.label},e.value))})]})})]}),t&&Object.entries(r||{}).length>0&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(T,{as:`h3`,tone:`muted`,children:`Set required Environmental Variables`}),(0,G.jsx)(`div`,{className:`grid grid-cols-[1fr_1fr] items-start gap-4`,children:s?(0,G.jsxs)(`div`,{className:c(`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:[(0,G.jsx)(Mv,{}),(0,G.jsxs)(T,{as:`span`,variant:`caption`,className:`block`,children:[` `,`Loading variables...`]})]}):Object.entries(r).map(([e,t])=>(0,G.jsxs)(W.Fragment,{children:[(0,G.jsxs)(ZO,{className:`w-full`,children:[(0,G.jsx)($O,{className:`sr-only`,children:`Key`}),(0,G.jsx)(Bj,{name:`env-${e}`,value:e,disabled:!0,className:`w-full`})]}),(0,G.jsxs)(ZO,{invalid:i.includes(e),className:`w-full`,children:[(0,G.jsx)($O,{className:`sr-only`,children:`Value`}),(0,G.jsx)(Bj,{name:e,value:t,onChange:o,autoComplete:`off`,className:`w-full`}),(0,G.jsx)(tk,{children:i.includes(e)?`Value is required.`:void 0})]})]},e))}),(0,G.jsxs)(`div`,{className:`relative mt-3.5 border-t border-border pt-12`,children:[(0,G.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:(0,G.jsx)(T,{tone:`muted`,as:`span`,variant:`caption`,className:`block`,children:`And`})}),(0,G.jsx)(T,{as:`h3`,tone:`muted`,children:`Set AI Model for Template Installation`}),(0,G.jsx)(T,{tone:`muted`,className:`mt-2 mb-5`,children:`This model will be used by the workflow to process and install the template`}),(0,G.jsx)(Yei,{defaultProvider:u||``,defaultModel:d||``,updateModel:f||(()=>Promise.resolve({message:`Updated`})),closeEditor:()=>{},autoSave:!0,selectProviderPlaceholder:`Provider`})]})]}),t&&!s&&(0,G.jsx)(X,{className:c(`mt-4 flex min-h-10 w-full items-center justify-center gap-2 rounded-lg bg-card state-layer text-foreground`,`[&_svg]:h-[1.1em] [&_svg]:text-foreground [&>svg]:w-[1.1em]`),onClick:a,disabled:!t||!u||!d||i.length>0,iconEnd:(0,G.jsx)(mP,{}),loading:l,children:`Install`})]})})}function SUi({title:e,description:t,githubUrl:n,isLoading:r,infoData:i,templateSlug:a}){let o=a?`feat/install-template-${a}`:`feat/install-template-[slug]`;return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`mt-5 grid items-center`,children:(0,G.jsxs)(`div`,{className:c(`flex items-center gap-3`,`[&>svg]:h-[1.2em] [&>svg]:w-[1.2em] [&>svg]:opacity-50`,{"[&>svg]:opacity-20":r}),children:[(0,G.jsx)(k6,{}),(0,G.jsx)(`h2`,{className:c({"flex min-w-[50%] rounded-lg bg-muted":r}),children:(0,G.jsx)(T,{as:`span`,variant:`title`,className:`block`,children:r?(0,G.jsx)(G.Fragment,{children:`\xA0`}):e})})]})}),(0,G.jsxs)(`div`,{className:`grid gap-x-24 lg:grid-cols-[1fr_1fr]`,children:[(0,G.jsxs)(`div`,{className:`grid`,children:[(0,G.jsx)(T,{tone:`muted`,className:c(`mt-2 mb-4`,{"rounded-lg bg-muted":r}),children:r?(0,G.jsx)(G.Fragment,{children:`\xA0`}):t}),!r&&a&&(0,G.jsxs)(`div`,{className:c(`mb-4 rounded-lg bg-nested p-4`,`flex items-start gap-3`),children:[(0,G.jsx)(`div`,{className:`mt-0.5 shrink-0`,children:(0,G.jsx)(Hx,{className:`h-[1.1em] w-[1.1em] text-info-indicator`})}),(0,G.jsxs)(`div`,{className:`flex-1 space-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(VS,{className:`h-[1em] w-[1em] text-muted-foreground`}),(0,G.jsx)(T,{as:`span`,variant:`subheading`,tone:`ink`,children:`A new Git branch will be created`})]}),(0,G.jsxs)(`div`,{className:`space-y-1`,children:[(0,G.jsxs)(T,{tone:`muted`,as:`p`,variant:`caption`,children:[(0,G.jsx)(T,{as:`span`,variant:`column`,children:`Branch name:`}),` `,(0,G.jsx)(bI,{children:o})]}),(0,G.jsx)(T,{tone:`muted`,as:`p`,variant:`caption`,children:`This ensures safe installation with easy rollback if needed. Your main branch remains unchanged.`})]})]})]}),n&&(0,G.jsxs)(`a`,{href:n,target:`_blank`,rel:`noopener noreferrer`,className:c(`text-muted-foreground hover:text-foreground`,`mt-auto flex items-center gap-2`),children:[(0,G.jsx)(A6,{}),(0,G.jsx)(T,{as:`span`,variant:`body`,className:`block`,children:n?.split(`/`)?.pop()})]})]}),i&&(0,G.jsx)(Aei,{data:i,labelsAreHidden:!0,isLoading:r})]})]})}function CUi(e){switch(e){case`running`:return(0,G.jsx)(Mv,{size:`sm`,"aria-hidden":!0});case`success`:return(0,G.jsx)(cC,{"aria-hidden":!0});case`failed`:return(0,G.jsx)(gw,{"aria-hidden":!0});default:return null}}function wUi(){return(0,G.jsx)(`svg`,{viewBox:`0 0 24 24`,className:`text-subtle-foreground`,"aria-hidden":!0,children:(0,G.jsx)(`circle`,{cx:`12`,cy:`12`,r:`8.5`,pathLength:`48`,fill:`none`,stroke:`currentcolor`,strokeWidth:`2.8`,strokeLinecap:`round`,strokeDasharray:`3 3`})})}function TUi({status:e,variant:t}){return t===`plain`?(0,G.jsx)(`span`,{className:c(`flex size-icon-md items-center justify-center self-center [&>svg]:size-icon-md`,u.colors,{"[&>svg]:text-success-indicator":e===`success`,"[&>svg]:text-destructive-foreground":e===`failed`}),children:e===`pending`?(0,G.jsx)(wUi,{}):CUi(e)}):(0,G.jsx)(`span`,{className:c(`flex size-7 items-center justify-center self-center rounded-full motion-reduce:transition-none`,u.colors,u.transform,{"[&>svg]:text-success-indicator":e===`success`,"[&>svg]:text-destructive-foreground":e===`failed`,"border border-dashed border-placeholder":e===`pending`,"[&>svg]:size-icon-md":e!==`running`,"bg-success-subtle":e===`success`,"bg-destructive-subtle":e===`failed`,"scale-110":e===`success`||e===`failed`}),children:CUi(e)})}function EUi({step:e,isActive:t,position:n,variant:r=`default`}){let i=t||e.status===`success`?`ink`:`muted`;return(0,G.jsxs)(`div`,{className:c(`grid grid-cols-[1fr_auto] gap-6 rounded-lg px-4 py-3 motion-reduce:transition-none`,u.colors,{"border border-transparent":r==="default","border-dashed border-placeholder bg-card":t&&r==="default"}),children:[(0,G.jsxs)(`div`,{className:`grid min-w-0 grid-cols-[auto_1fr] gap-2`,children:[(0,G.jsxs)(T,{as:`span`,tone:i,className:c(`flex min-w-6 justify-end`,u.colors),children:[n,`.`]}),(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(T,{as:`h4`,tone:i,className:u.colors,children:e.title}),e.description&&(0,G.jsx)(T,{tone:`faint`,className:c(`-mt-0.5`,{truncate:r===`plain`}),children:e.description})]})]}),(0,G.jsx)(TUi,{status:e.status,variant:r})]})}function DUi({currentStep:e,steps:t=[],className:n}){return(0,G.jsx)(`div`,{className:c(n),children:t.map((t,n)=>(0,G.jsx)(EUi,{step:t,isActive:e?.id===t.id,position:n+1},t.id))})}function OUi({steps:e}){let t=e.length,n=e.filter(e=>e.status===`success`).length;return(0,G.jsxs)(`div`,{className:`flex w-full flex-col content-center justify-center gap-4`,children:[(0,G.jsx)(`div`,{className:`grid w-full grid-cols-[0_repeat(9,1fr)]`,children:e.map((t,n)=>(0,G.jsx)(`div`,{className:c(`relative flex h-8 items-center justify-end`,u.colors,{"bg-success-subtle":t.status===`success`&&e?.[n-1]?.status===`success`}),children:(0,G.jsx)(`div`,{className:c(`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`,u.colors,u.transform,{"border border-dashed border-placeholder":t.status===`pending`,"scale-110 bg-success-subtle text-success-subtle-foreground":t.status===`success`,"scale-110 bg-destructive-subtle text-destructive-subtle-foreground":t.status===`failed`}),children:t.status===`running`?(0,G.jsx)(Mv,{}):n+1})},t.id))}),(0,G.jsxs)(`div`,{className:c(`text-center text-caption text-muted-foreground`,u.colors),children:[n,` of `,t,` steps completed`]})]})}var kUi=(0,W.createContext)(3);function AUi({title:e,description:t,action:n,done:r,className:i,children:a}){let o=(0,W.useContext)(kUi);return(0,G.jsxs)(`li`,{className:c(`group/step grid grid-cols-[1.5rem_minmax(0,1fr)] gap-x-4 [counter-increment:ds-step]`,i),children:[(0,G.jsxs)(`div`,{className:`flex flex-col items-center`,children:[(0,G.jsx)(`span`,{className:c(`flex size-6 shrink-0 items-center justify-center rounded-full`,u.colors,r?`bg-success-indicator/18 text-success-indicator`:`bg-fill text-foreground`),children:r?(0,G.jsx)(cC,{className:`size-icon-sm`,"aria-label":`Done`}):(0,G.jsx)(T,{as:`span`,variant:`column`,className:`before:content-[counter(ds-step)]`,"aria-hidden":!0})}),(0,G.jsx)(`span`,{"aria-hidden":!0,className:`w-px flex-1 bg-border group-last/step:hidden`})]}),(0,G.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-3 pb-8 group-last/step:pb-0`,children:[(0,G.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,G.jsxs)(`div`,{className:`flex min-h-6 flex-wrap items-center justify-between gap-x-6 gap-y-2`,children:[(0,G.jsx)(T,{as:o===2?`h2`:`h3`,variant:`label`,className:`text-pretty`,children:e}),n==null?null:(0,G.jsx)(`div`,{className:`flex shrink-0 items-center gap-2`,children:n})]}),t==null?null:(0,G.jsx)(T,{as:`p`,variant:`body-sm`,tone:`muted`,className:`max-w-[70ch] text-pretty`,children:t})]}),a]})]})}function jUi({headingLevel:e=3,className:t,children:n}){return(0,G.jsx)(kUi.Provider,{value:e,children:(0,G.jsx)(`ol`,{className:c(`flex flex-col [counter-reset:ds-step]`,t),children:n})})}Object.assign(jUi,{Step:AUi});function MUi({name:e,streamResult:t,runId:n,workflowInfo:r}){let i=t?.phase||`initializing`,a=t?.payload?.workflowState,o=t?.payload?.currentStep,s=t?.error,l=a?.steps||{},u=Object.keys(l).length>0,d=e=>e===`input`||e.endsWith(`.input`)||e.startsWith(`Mapping_`)&&/[0-9a-f]{8}/.test(e)||/[0-9a-f]{8,}/.test(e)?!1:!r?.allSteps||e in r.allSteps,f=Object.entries(l).filter(([e,t])=>d(e)),p=f.length,m=()=>{switch(i){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...`}},h=f.map(([e,t])=>({id:e,status:t?.status,description:t?.description,title:e.charAt(0).toUpperCase()+e.slice(1).replace(/-/g,` `),isActive:o?.id===e}));return(0,G.jsxs)(yUi,{className:`mb-5 content-center space-y-6 text-muted-foreground`,children:[(0,G.jsxs)(`div`,{className:`text-center`,children:[(0,G.jsx)(T,{as:`h3`,variant:`heading`,tone:`ink`,children:m()}),(t?.runId||n)&&(0,G.jsxs)(T,{as:`p`,variant:`caption`,tone:`muted`,className:`mt-2`,children:[`Run ID: `,t?.runId??n]})]}),u&&p>0&&![`error`].includes(i)&&(0,G.jsx)(`div`,{className:`mx-auto w-full max-w-[30rem] px-4`,children:(0,G.jsx)(OUi,{steps:h})}),s&&i===`error`&&(0,G.jsxs)(`div`,{className:c(`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:[(0,G.jsx)(Bx,{}),(0,G.jsx)(T,{as:`span`,variant:`body`,className:`block`,children:s||`Something went wrong`})]}),u&&(0,G.jsx)(DUi,{steps:h,currentStep:o,className:`pb-4`}),!u&&i===`initializing`&&(0,G.jsxs)(`div`,{className:c(`text-muted-foreground`,`grid justify-items-center gap-4 text-center`),children:[(0,G.jsx)(Mv,{}),(0,G.jsx)(T,{as:`p`,variant:`body`,children:`This may take some time...`})]})]})}function NUi({name:e,installedEntities:t}){return(0,G.jsxs)(yUi,{className:c(`grid content-center items-center justify-items-center gap-4`,`[&>svg]:h-8 [&>svg]:w-8`),children:[(0,G.jsx)(k6,{}),(0,G.jsx)(T,{as:`h2`,variant:`heading`,children:`Done!`}),(0,G.jsxs)(T,{tone:`muted`,className:`text-center`,children:[`The `,(0,G.jsx)(`b`,{className:`text-muted-foreground`,children:e}),` template has been successfully installed.`,t&&t.length>0&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`br`,{}),` Installed entities are listed below.`]})]}),t&&t.length>0&&(0,G.jsx)(Aei,{data:t})]})}function PUi(){let{templateSlug:e}=wv(),t=[{id:`templates`,label:`Templates`,to:`/templates`},{id:`template`,label:lnn(e)}],[n,r]=Av(),[i,a]=(0,W.useState)(``),[o,s]=(0,W.useState)(``),[c,l]=(0,W.useState)(``),[u,d]=(0,W.useState)({}),[f,p]=(0,W.useState)([]),[m,h]=(0,W.useState)(null),[g,_]=(0,W.useState)(!1),[v,y]=(0,W.useState)(``),[b,x]=(0,W.useState)(!1),[S,C]=(0,W.useState)(!1),[w,T]=(0,W.useState)([]),{data:E,isLoading:D}=nUi({repoOrSlug:e,owner:`mastra-ai`}),O=`1.86.0`.includes(`beta`)??!1?`beta`:`main`,{data:k,isLoading:A}=rUi({repo:E?.githubUrl?new URL(E.githubUrl).pathname.split(`/`)[2]:`template-${e}`,owner:`mastra-ai`,branch:O}),{data:j,isLoading:M}=iUi(),{mutateAsync:N,isPending:P}=aUi(),{mutateAsync:F}=oUi(),{streamInstall:I,streamResult:L,isStreaming:R}=dUi({workflowInfo:j}),{observeInstall:z,streamResult:B,isStreaming:ee}=fUi({workflowInfo:j});(0,W.useEffect)(()=>{let e=n.get(`runId`);!e||g||m||R||ee||(console.info(`🔄 Checking completed run after hot reload:`,{runId:e}),y(e),F({runId:e}).then(e=>{let t=e.snapshot;if(t?.status===`success`&&t?.result?.success)_(!0);else if(t?.result?.success===!1){if(t?.result?.validationResults&&!t?.result?.validationResults?.valid&&t?.result?.validationResults?.remainingErrors>0){let{remainingErrors:e,errors:n}=t.result.validationResults,r=`Template installation completed but ${e} validation issue${e>1?`s`:``} remain unresolved.`;h(r),T(n||[])}else{let e=t?.result?.message||t?.result?.error||`Template installation failed`;h(typeof e==`string`?e:String(e))}}}).catch(e=>{console.error(`❌ Failed to fetch run details:`,e),h(`Failed to retrieve installation status after reload`)}))},[n,g,m,R,ee,F]),(0,W.useEffect)(()=>{let e=n.get(`runId`),t=n.get(`resume`),i=n.get(`provider`);if(e&&t===`true`&&i&&!R&&!ee&&!b&&!S&&j){y(e),x(!0);try{F({runId:e}).then(t=>{if(t.snapshot?.status===`running`)return z.mutateAsync({runId:e})}).then(()=>{r(e=>{let t=new URLSearchParams(e);return t.delete(`resume`),t})}).catch(e=>{console.error(`❌ Failed to resume template installation:`,e),e.message?.includes(`404`)||e.message?.includes(`not found`)?h(`Template installation run not found. It may have expired or been completed.`):h(`Failed to resume template installation. Please try again.`)})}catch(e){console.error(`❌ Auto-resume failed with error:`,e),h(`Failed to resume template installation. Please refresh and try again.`)}}},[n,e,R,ee,b,S,j,F,z,r]);let V=[{value:`openai`,label:`OpenAI`},{value:`anthropic`,label:`Anthropic`},{value:`groq`,label:`Groq`},{value:`google`,label:`Google`}],te=[{key:`tools`,label:`Tools`,value:E?.tools?.length?E.tools.map(e=>e).join(`, `):`n/a`,icon:(0,G.jsx)(ZP,{})},{key:`agents`,label:`Agents`,value:E?.agents?.length?E.agents.map(e=>e).join(`, `):`n/a`,icon:(0,G.jsx)(WP,{})},{key:`workflows`,label:`Workflows`,value:E?.workflows?.length?E.workflows.map(e=>e).join(`, `):`n/a`,icon:(0,G.jsx)(KS,{})},{key:`providers`,label:`Providers`,value:E?.supportedProviders?.length?E.supportedProviders.join(`, `):`n/a`,icon:(0,G.jsx)(h8,{})},{key:`tags`,label:`Tags`,value:E?.tags?.length?E.tags.join(`, `):`n/a`,icon:(0,G.jsx)(wP,{})}],ne=[{...te[0]},{...te[1]},{...te[2]}].filter(e=>e.value!==`n/a`);return(0,W.useEffect)(()=>{k&&d(k)},[k]),(0,W.useEffect)(()=>{let e=L||B;e?.phase===`error`&&e?.error&&h(typeof e.error==`string`?e.error:String(e.error))},[L?.phase,L?.error,B?.phase,B?.error]),(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:t}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:e}),(0,G.jsxs)(`div`,{className:`grid gap-y-6`,children:[(0,G.jsx)(SUi,{isLoading:D,title:E?.title,description:E?.longDescription,imageURL:E?.imageURL,githubUrl:E?.githubUrl,infoData:te,templateSlug:e}),E&&(0,G.jsxs)(G.Fragment,{children:[(R||ee)&&(0,G.jsx)(MUi,{name:E.title,streamResult:ee?B:L,runId:v,workflowInfo:j}),g&&(0,G.jsx)(NUi,{name:E.title,installedEntities:ne,linkComponent:kv}),m&&(0,G.jsx)(bUi,{errorMsg:m,validationErrors:w.length>0?w:L?.validationResults?.errors||B?.validationResults?.errors}),!R&&!ee&&!g&&!m&&(0,G.jsx)(xUi,{providerOptions:V,selectedProvider:i,onProviderChange:e=>{a(e)},variables:u,setVariables:d,errors:f,setErrors:p,handleInstallTemplate:async()=>{let e=Object.entries(u).reduce((e,[t,n])=>(n===``&&e.push(t),e),[]);if(e.length>0)p(e);else if(E){h(null),_(!1),y(``),C(!0);try{let e={repo:E.githubUrl||`https://github.com/mastra-ai/template-${E.slug}`,ref:O,slug:E.slug,variables:u},{runId:t}=await N({});y(t),r(e=>{let n=new URLSearchParams(e);return n.set(`runId`,t),n.set(`resume`,`true`),n.set(`provider`,i||`openai`),n}),await I.mutateAsync({inputData:e,selectedModel:{provider:o,modelId:c},runId:t})}catch(e){C(!1),h(e?.message||`Template installation failed`),console.error(`Template installation failed`,e)}}},handleVariableChange:e=>{let{name:t,value:n}=e.target;n.trim()===``?p(e=>[...e,t]):p(e=>e.filter(e=>e!==t)),d(e=>({...e,[t]:n}))},isLoadingEnvVars:A||M,isInstalling:P,defaultModelProvider:o,defaultModelId:c,onModelUpdate:async e=>(s(e.provider),l(e.modelId),{message:`Model updated successfully`})})]})]})]})}var FUi=e=>e.threadId,IUi=e=>`traces`in e?e.traces:e.threads;function LUi(e,t){return`traces`in e?{traces:{...e.traces,...t}}:{threads:{...e.threads,...t}}}function RUi(e){let{field:t=`endedAt`,direction:n=`desc`}=e?.[0]??{},r=n===`asc`?1:-1;return(e,n)=>{let i=e[t],a=n[t];if(i!==a){if(i==null)return 1;if(a==null)return-1;if(i<a)return-r;if(i>a)return r}return e.threadId.localeCompare(n.threadId)}}function zUi({query:e,rolling:t,fixedStart:n=!1,autoRefetch:r=!0,limit:i,enabled:a=!0}){let o=Y(),{anchorWindow:s,reanchor:c}=xHi(e,n),l=(0,W.useMemo)(()=>s?{...e,timeRange:LUi(e.timeRange,s)}:e,[e,s]),u=rri({query:l,limit:i,enabled:a,queryOptions:gHi}),{headRows:d}=CHi({queryKey:[`threads`,e],fetchHead:async t=>(await o.queryTraceThreads({...e,timeRange:LUi(e.timeRange,bHi(IUi(e.timeRange),t,n)),orderBy:[{field:`endedAt`,direction:`desc`}],page:{limit:50}})).threads,getId:FUi,getEndedAt:e=>e.endedAt,since:Date.parse(IUi(l.timeRange).to),enabled:a&&t&&r&&u.threads!==void 0&&!u.isFetching&&!u.isError,onOverflow:()=>c(IUi(e.timeRange))}),{orderBy:f}=e,p=u.threads,m=(0,W.useMemo)(()=>p&&THi(p,d,{getId:FUi,compare:RUi(f),hasNextPage:u.hasNextPage}),[p,d,f,u.hasNextPage]);return{...u,threads:m}}function BUi(e){return{traceId:e.lastTraceId,name:e.entityName??e.threadId,entityType:e.entityType,entityId:e.entityId,entityName:e.entityName,threadId:e.threadId,resourceId:e.resourceId,environment:e.environment,status:e.status,inputPreview:e.inputPreview,outputPreview:e.outputPreview??void 0,errorPreview:e.errorPreview??void 0,startedAt:e.startedAt,endedAt:e.endedAt,traceCount:e.traceCount,timeToFirstChunkMs:e.timeToFirstChunkMs,timeToFirstTokenMs:e.timeToFirstTokenMs,createdAt:e.startedAt}}var VUi=[`last-24h`,`last-3d`,`last-7d`,`last-14d`,`last-30d`,`custom`],HUi=[];function UUi(){let{data:e}=O7(),t=e?.capabilities.traceQueryTimeToFirstChunk??!1,n=e?.capabilities.traceQueryTimeToFirstToken??!1,{data:r=HUi}=q8(),{data:i=HUi}=J8();return(0,W.useMemo)(()=>[NLt,...Ugi({withTimeToFirstChunk:t,withTimeToFirstToken:n,entityNames:r,environments:i})],[t,n,r,i])}function WUi({tokens:e,groups:t,onFiltersChange:n}){let r=(0,W.useMemo)(()=>sai(e),[e]),i=(0,W.useMemo)(()=>{let e=uai([],t);return{...e,nodes:[hP,...r,...e.nodes]}},[r,t]),a=(0,W.useCallback)(e=>{let t=fai({...e,nodes:e.nodes.filter(e=>aP(e)||e.fieldId!==`timeRange`)});n(t.tokens,t.groups)},[n]);return{filterBarValue:i,onFilterBarChange:a,onFilterByField:(0,W.useCallback)((e,t)=>{let n=r.filter(t=>t.fieldId!==e),o={id:`${e}:${t}`,fieldId:e,operatorId:`is`,value:t},s=i.nodes.filter(aP);a({...i,nodes:[...n,o,...s]})},[r,i,a])}}var GUi=e=>e;function KUi({datePreset:e,dateFrom:t,dateTo:n,minDate:r,tokens:i,groups:a,onDatePresetChange:o,onDateChange:s,onDateRangeChange:c,onFiltersChange:l,disabled:u}){let d=UUi(),{filterBarValue:f,onFilterBarChange:p}=WUi({tokens:i,groups:a,onFiltersChange:l});return(0,G.jsxs)(SP,{fields:d,operators:Fii,value:f,onValueChange:p,createItemId:GUi,maxDepth:3,"aria-label":`Thread filters`,className:`min-w-64 flex-1`,children:[(0,G.jsx)(SP.Chips,{renderChip:i=>i.fieldId===`timeRange`?(0,G.jsx)(SP.TimeRange,{preset:e,onPresetChange:o,dateFrom:t,dateTo:n,minDate:r,onDateChange:s,onDateRangeChange:c,disabled:u,presets:VUi,defaultPreset:g5.datePreset}):(0,G.jsx)(SP.Chip,{item:i})}),(0,G.jsx)(SP.Input,{placeholder:`Filter threads`})]})}function qUi({selectedThreadId:e,onSelectedThreadChange:t,onOpenScore:n,urlState:r}){let i=vHi(r),{timeRange:a,tokens:o,groups:s,sort:c}=i,l=k7().enabled,u=gvi().enabled,d=Z_i({scope:`threads`}),{data:f,isLoading:p}=O7(),m=f?.capabilities.traceQueryTimeToFirstChunk??!1,h=f?.capabilities.traceQueryTimeToFirstToken??!1,g=(0,W.useMemo)(()=>p?d.preferences:tni(d.preferences,{withTimeToFirstChunk:m,withTimeToFirstToken:h}),[d.preferences,p,m,h]),{threads:_,hasNextPage:v,isFetchingNextPage:y,setEndOfListElement:b,isLoading:x,isError:S,error:C}=zUi({query:(0,W.useMemo)(()=>{let e=Kgi(o,s,{withTimeToFirstChunk:m,withTimeToFirstToken:h});return{timeRange:{traces:a},orderBy:[{field:`startedAt`,direction:c.direction}],...e?{where:e}:{}}},[a,c,o,s,m,h]),rolling:i.rolling,fixedStart:i.datePreset===`custom`}),w=(0,W.useMemo)(()=>(_??[]).map(BUi),[_]),T=w.find(t=>t.threadId===e),E=e=>{e.threadId&&t(e.threadId)},D=!x&&!S&&w.length===0&&!i.contentFiltersApplied&&!e;return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`Threads`}),(0,G.jsx)(Foi,{toolbar:(0,G.jsxs)(G.Fragment,{children:[r&&(0,G.jsx)(K_i,{page:`threads`,...r,columns:d}),(0,G.jsxs)(EP,{children:[(0,G.jsx)(EP.Start,{children:(0,G.jsx)(KUi,{datePreset:i.datePreset,dateFrom:i.dateFrom,dateTo:i.dateTo,tokens:o,groups:s,onDatePresetChange:i.onDatePresetChange,onDateChange:i.onDateChange,onDateRangeChange:i.onDateRangeChange,onFiltersChange:i.onFiltersChange,disabled:x})}),(0,G.jsx)(EP.End,{children:(0,G.jsx)(KHi,{scope:`threads`,value:d.preferences,onChange:d.setPreferences})})]})]}),error:S?(0,G.jsx)(B8,{error:C,resource:`threads`,errorTitle:`Failed to load threads`}):void 0,empty:D?(0,G.jsx)(Nti,{resource:`threads`,datePreset:i.datePreset,dateFrom:i.dateFrom,dateTo:i.dateTo}):void 0,children:(0,G.jsx)(rui,{listId:`all-threads`,columnPreferences:g,outcomeColumn:!1,traces:w,isLoading:x,isFetchingNextPage:y,hasNextPage:v,setEndOfListElement:b,filtersApplied:i.filtersApplied,resource:`threads`,sort:c,onSortChange:e=>i.setSort({field:`startedAt`,direction:e.direction}),featuredTraceId:T?.traceId,onTraceClick:E})}),(0,G.jsx)(_bi,{open:!!e,threadId:e??``,depth:1,closeLabel:`Close`,withQueryTrace:l,withFeedback:u,onOpenScore:n,onClose:()=>t(void 0)})]})}function JUi(){let{enabled:e,isLoading:t}=pvi(),n=Cv(),[r,i]=Av();return(0,G.jsx)(mHi,{enabled:e,isLoading:t,heading:`Threads`,title:`Query threads capability not activated`,description:`Your observability storage does not support thread row queries. Switch to a store that declares the thread-query-rows capability to list threads.`,children:(0,G.jsx)(qUi,{urlState:{searchParams:r,setSearchParams:i},selectedThreadId:jHi(r),onSelectedThreadChange:e=>i(t=>MHi(t,e),{replace:!0}),onOpenScore:(e,t)=>n(pZn(e,t))})})}var YUi=()=>(0,G.jsx)(Vx,{titleSlot:`No Workflows yet`,descriptionSlot:(0,G.jsxs)(G.Fragment,{children:[`Mastra workflows are not configured yet. `,(0,G.jsx)(`br`,{}),`More information in the documentation.`]}),actionSlot:(0,G.jsx)(X,{variant:`ghost`,render:(0,G.jsx)(`a`,{href:`https://mastra.ai/docs/workflows/overview`,target:`_blank`,rel:`noopener noreferrer`}),icon:(0,G.jsx)(nF,{}),children:`Workflows documentation`}),variant:`fill`});function XUi(e,t,n){return P6(e,t,{name:e=>e.name,running:e=>n[e.id]?.running??0,suspended:e=>n[e.id]?.suspended??0,steps:e=>Object.keys(e.steps??{}).length})}function ZUi(e){return Object.keys(e.steps??{}).filter(t=>e.allSteps?.[t]?.isWorkflow)}function QUi(e){let t=new Map;for(let[n,r]of Object.entries(e))t.set(n,n),r.name&&t.set(r.name,n);return t}function $Ui(e,t,n){let r=QUi(t),i=[],a=(e,o,s,c,l,u)=>{let d=ZUi(e).filter(e=>{let t=r.get(e);return t===void 0||!c.has(t)});if(i.push({kind:`workflow`,workflow:e,pathKey:o,depth:s,nestedIds:d,guides:l,isLastChild:u}),!n.has(o)||d.length===0)return;let f=new Set(c).add(e.id),p=s===0?[]:[...l,!u];for(let[n,c]of d.entries()){let l=n===d.length-1,u=r.get(c);if(u===void 0){i.push({kind:`unregistered`,stepId:c,description:e.allSteps?.[c]?.description,pathKey:`${o}/${c}`,depth:s+1,guides:p,isLastChild:l});continue}let m=t[u];m&&a({...m,id:u},`${o}/${u}`,s+1,f,p,l)}};for(let t of e)a(t,t.id,0,new Set([t.id]),[],!1);return i}var eWi=`auto 24rem minmax(0, 1fr) auto auto auto`;function tWi({guides:e,isLastChild:t}){return(0,G.jsxs)(`span`,{"aria-hidden":!0,className:`-my-6 flex shrink-0 self-stretch`,children:[e.map((e,t)=>(0,G.jsx)(`span`,{className:c(`w-6`,e&&`border-l border-border`)},t)),(0,G.jsxs)(`span`,{className:`relative w-6`,children:[(0,G.jsx)(`span`,{className:c(`absolute top-0 left-0 border-l border-border`,t?`h-1/2`:`h-full`)}),(0,G.jsx)(`span`,{className:`absolute top-1/2 left-0 w-3.5 border-b border-border`})]})]})}function nWi({row:e,isExpanded:t,onToggle:n}){let r=e.kind===`workflow`&&e.nestedIds.length>0,i=e.kind===`workflow`?e.workflow.name:e.stepId;return(0,G.jsx)(`div`,{className:`flex items-center pl-5`,children:r?(0,G.jsx)(`button`,{type:`button`,"aria-expanded":t,"aria-label":`${t?`Collapse`:`Expand`} nested workflows of ${i}`,className:c(hS,`relative grid size-5 shrink-0 place-items-center before:absolute before:-inset-1.5 before:content-['']`),onClick:e=>{e.stopPropagation(),n()},children:(0,G.jsx)(y,{direction:`right`,className:`size-4`})}):(0,G.jsx)(`span`,{className:`size-5 shrink-0`,"aria-hidden":!0})})}var rWi=e=>e.stopPropagation();function iWi({sortKey:e,sort:t,onSortChange:n,children:r}){return n?(0,G.jsx)(Z.SortableTopCell,{sortKey:e,sort:t?.key===e?t.direction:void 0,onSortChange:t=>n(t,e),children:r}):(0,G.jsx)(Z.TopCell,{children:r})}function aWi({row:e,isExpanded:t,onToggle:n,runCount:r,rowProps:i}){let{paths:a,Link:o}=on(),s=(0,W.useRef)(null),{workflow:c,nestedIds:l}=e,u=vN(c.name,50),d=vN(c.description??``,200),f=Object.keys(c.steps??{}).length,p=r?.running??0,m=r?.suspended??0,h=l.length>0;return(0,G.jsxs)(Z.RowWrapper,{...i,onSelectRow:()=>s.current?.click(),children:[(0,G.jsx)(nWi,{row:e,isExpanded:t,onToggle:n}),(0,G.jsxs)(Z.RowLink,{ref:s,colStart:2,to:a.workflowLink(c.id),LinkComponent:o,tabIndex:-1,onClick:rWi,children:[(0,G.jsx)(Z.NameCell,{children:(0,G.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[e.depth>0?(0,G.jsx)(tWi,{guides:e.guides,isLastChild:e.isLastChild}):null,(0,G.jsx)(`span`,{className:`truncate`,children:u}),c.origin===`dynamic`?(0,G.jsx)(YS,{size:`xs`,variant:`blue`,title:`Registered via the dynamic-workflows API`,children:`Dynamic`}):null,h?(0,G.jsxs)(T,{as:`span`,variant:`body-sm`,tone:`muted`,title:`Nested workflows: ${l.join(`, `)}`,className:`inline-flex shrink-0 items-center gap-1`,children:[(0,G.jsx)(KS,{"aria-hidden":!0,className:`size-icon-sm`}),l.length]}):null]})}),(0,G.jsx)(Z.DescriptionCell,{children:d}),(0,G.jsx)(Z.TextCell,{className:`text-center`,children:p>0?(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-info-indicator`,"aria-label":`${p} run${p===1?``:`s`} in progress`,children:[(0,G.jsx)(`span`,{"aria-hidden":!0,className:`size-2 rounded-full bg-info-indicator motion-safe:animate-pulse`}),p]}):``}),(0,G.jsx)(Z.TextCell,{className:`text-center`,children:m>0?(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-warning-foreground`,"aria-label":`${m} run${m===1?``:`s`} awaiting input`,children:[(0,G.jsx)(AD,{"aria-hidden":!0,className:`size-icon-sm`}),m]}):``}),(0,G.jsx)(Z.TextCell,{className:`text-center`,children:f||``})]})]})}function oWi({workflows:e,isLoading:t,search:n=``,sort:r,onSortChange:i,requestContext:a}){let[o,s]=(0,W.useState)(new Set),l=LDt({requestContext:a}),u=(0,W.useMemo)(()=>Object.entries(e).map(([e,t])=>({...t,id:e})),[e]),d=(0,W.useMemo)(()=>{let e=n.toLowerCase();return u.filter(t=>t.name?.toLowerCase().includes(e)||t.description?.toLowerCase().includes(e))},[u,n]),f=(0,W.useMemo)(()=>XUi(d,r,l),[d,r,l]),m=(0,W.useMemo)(()=>$Ui(f,e,o),[f,e,o]),h=(0,W.useMemo)(()=>{let e=new Map;for(let t of m)t.kind===`workflow`&&e.set(t.pathKey,e.size);return e},[m]),{containerRef:g,getRowProps:_}=UP({count:h.size,global:!0}),v=e=>{s(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return t?(0,G.jsx)(QP,{columns:eWi,fit:`container`}):(0,G.jsxs)(Z,{columns:eWi,fit:`container`,scrollRef:g,children:[(0,G.jsxs)(Z.Top,{children:[(0,G.jsx)(Z.TopCell,{children:(0,G.jsx)(`span`,{className:`sr-only`,children:`Expand`})}),(0,G.jsx)(iWi,{sortKey:`name`,sort:r,onSortChange:i,children:`Name`}),(0,G.jsx)(Z.TopCell,{children:`Description`}),(0,G.jsx)(iWi,{sortKey:`running`,sort:r,onSortChange:i,children:`Running`}),(0,G.jsx)(iWi,{sortKey:`suspended`,sort:r,onSortChange:i,children:`Pending input`}),(0,G.jsx)(iWi,{sortKey:`steps`,sort:r,onSortChange:i,children:`Number of steps`})]}),m.length===0&&n?(0,G.jsx)(Z.NoMatch,{message:`No Workflows match your search`}):null,m.map(e=>{let t=o.has(e.pathKey),n=()=>v(e.pathKey);return e.kind===`unregistered`?(0,G.jsxs)(Z.RowStatic,{className:`gap-0 px-0`,children:[(0,G.jsx)(nWi,{row:e,isExpanded:t,onToggle:n}),(0,G.jsxs)(`div`,{className:`col-span-5 col-start-2 grid grid-cols-subgrid gap-4 px-3`,children:[(0,G.jsx)(Z.NameCell,{children:(0,G.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(tWi,{guides:e.guides,isLastChild:e.isLastChild}),(0,G.jsx)(`span`,{className:`truncate`,children:vN(e.stepId,50)}),(0,G.jsxs)(mx,{children:[(0,G.jsx)(hx,{render:(0,G.jsx)(T,{as:`span`,variant:`body-sm`,tone:`muted`}),role:`note`,tabIndex:0,className:c(`shrink-0 rounded-sm`,p),children:`not registered`}),(0,G.jsx)(gx,{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.`})]})]})}),(0,G.jsx)(Z.DescriptionCell,{children:vN(e.description??``,200)}),(0,G.jsx)(Z.TextCell,{className:`text-center`,children:``}),(0,G.jsx)(Z.TextCell,{className:`text-center`,children:``}),(0,G.jsx)(Z.TextCell,{className:`text-center`,children:``})]})]},`workflow-${e.pathKey}`):(0,G.jsx)(aWi,{row:e,isExpanded:t,onToggle:n,runCount:l[e.workflow.id],rowProps:_(h.get(e.pathKey)??-1)},`workflow-${e.pathKey}`)})]})}var G9=[AR(`/workflows`)];function sWi(){let{data:e,isLoading:t,error:n}=WM(),[r,i]=(0,W.useState)(``),[a,o]=(0,W.useState)();return n&&JN(n)?(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:G9}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`Workflows`}),(0,G.jsx)(vR,{variant:`fill`})]}):n&&YN(n)?(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:G9}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`Workflows`}),(0,G.jsx)(_R,{variant:`fill`,resource:`workflows`})]}):n?(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:G9}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`Workflows`}),(0,G.jsx)(Vx,{tone:`error`,variant:`fill`,titleSlot:`Failed to load workflows`,descriptionSlot:n.message})]}):Object.keys(e||{}).length===0&&!t?(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:G9}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`Workflows`}),(0,G.jsx)(YUi,{})]}):(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:G9}),actionRow:(0,G.jsxs)(EP,{children:[(0,G.jsx)(EP.Start,{children:(0,G.jsx)(`div`,{className:`max-w-120 flex-1`,children:(0,G.jsx)(CN,{...wN,onValueChange:i,label:`Search workflows`,placeholder:`Search by name or description`})})}),(0,G.jsx)(EP.End,{children:(0,G.jsx)(X,{render:(0,G.jsx)(kv,{to:`/workflows/schedules`}),variant:`primary`,icon:(0,G.jsx)(HS,{}),children:`Schedules`})})]}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`Workflows`}),(0,G.jsx)(oWi,{workflows:e||{},isLoading:t,search:r,sort:a,onSortChange:(e,t)=>o({key:t,direction:e})})]})}var cWi={active:`bg-success-indicator`,paused:`bg-info-indicator`,completed:`bg-muted-foreground`},lWi={active:`text-success-indicator`,paused:`text-info-indicator`,completed:`text-muted-foreground`},uWi=({status:e})=>(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-2 whitespace-nowrap`,children:[(0,G.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full ${cWi[e]}`,"aria-hidden":!0}),(0,G.jsx)(T,{as:`span`,variant:`caption`,className:lWi[e],children:e})]});function dWi({status:e}){let{icon:t,color:n}=fWi(e);return(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 whitespace-nowrap ${n}`,children:[(0,G.jsx)(`span`,{className:`inline-flex shrink-0 items-center`,"aria-hidden":!0,children:t}),(0,G.jsx)(T,{as:`span`,variant:`caption`,children:e})]})}function fWi(e){switch(e){case`success`:return{icon:(0,G.jsx)(cC,{className:`size-icon-sm`}),color:`text-success-indicator`};case`failed`:return{icon:(0,G.jsx)(gw,{className:`size-icon-sm`}),color:`text-destructive-foreground`};case`running`:return{icon:(0,G.jsx)(Mv,{}),color:`text-muted-foreground`};case`suspended`:return{icon:(0,G.jsx)(AD,{className:`size-icon-sm`}),color:`text-info-indicator`};case`canceled`:return{icon:(0,G.jsx)(zx,{className:`size-icon-sm`}),color:`text-muted-foreground`};case`pending`:case`waiting`:return{icon:(0,G.jsx)(XS,{className:`size-icon-sm`}),color:`text-muted-foreground`};default:return{icon:null,color:`text-muted-foreground`}}}var pWi=`auto auto auto auto 1fr`,mWi=3e4,hWi=3e5;function gWi({triggers:e,isLoading:t,workflowId:n,hasNextPage:r,isFetchingNextPage:i,setEndOfListElement:a}){let{Link:o,paths:s}=on(),c=e=>!!(n&&e.runId&&e.outcome!==`failed`),l=e.filter(c).length,{containerRef:u,getRowProps:d}=UP({count:l}),f=-1;return t?(0,G.jsx)(QP,{columns:pWi}):e.length===0?(0,G.jsx)(T,{variant:`body`,tone:`muted`,className:`p-4`,children:`No trigger history yet.`}):(0,G.jsxs)(Z,{columns:pWi,className:`min-w-0`,scrollRef:u,children:[(0,G.jsxs)(Z.Top,{children:[(0,G.jsx)(Z.TopCell,{children:`Run`}),(0,G.jsx)(Z.TopCell,{children:`Status`}),(0,G.jsx)(Z.TopCell,{children:`Started`}),(0,G.jsx)(Z.TopCell,{children:`Duration`}),(0,G.jsx)(Z.TopCell,{children:` `})]}),e.map(e=>{let t=e.actualFireAt-e.scheduledFireAt,r=$S(t,{signed:!0}),i=e.outcome===`failed`,a=i?e.error:e.run?.error,l=Math.abs(t),u=!i&&l>mWi&&l<=hWi,p=`${e.scheduleId}-${e.runId}-${e.actualFireAt}`,m=c(e);m&&(f+=1);let h=(0,G.jsx)(T,{as:`span`,variant:`caption`,font:`mono`,tone:m?`ink`:`muted`,className:`whitespace-nowrap`,children:e.runId}),g=(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Z.Cell,{children:h}),(0,G.jsx)(Z.Cell,{children:(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[i?(0,G.jsxs)(T,{as:`span`,variant:`caption`,className:`inline-flex items-center gap-1.5 whitespace-nowrap text-destructive-foreground`,children:[(0,G.jsx)(Wx,{className:`size-icon-sm`}),`publish failed`]}):e.run?(0,G.jsx)(dWi,{status:e.run.status}):(0,G.jsx)(T,{as:`span`,variant:`caption`,tone:`muted`,className:`inline-flex items-center gap-1.5 whitespace-nowrap`,children:`pending`}),a?(0,G.jsxs)(mx,{children:[(0,G.jsx)(hx,{asChild:!0,children:(0,G.jsx)(`span`,{className:`inline-flex text-destructive-foreground`,children:(0,G.jsx)(Wx,{className:`size-icon-sm`})})}),(0,G.jsx)(gx,{children:a})]}):null]})}),(0,G.jsx)(Z.Cell,{children:(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-2 whitespace-nowrap`,children:[e.actualFireAt?(0,G.jsx)(yk,{value:e.actualFireAt}):`—`,u?(0,G.jsxs)(mx,{children:[(0,G.jsx)(hx,{asChild:!0,children:(0,G.jsx)(`span`,{className:`inline-flex text-info-indicator`,children:(0,G.jsx)(Wx,{className:`size-icon-sm`})})}),(0,G.jsxs)(gx,{children:[`Published `,r,` after the scheduled fire time`]})]}):null]})}),(0,G.jsx)(Z.Cell,{children:e.run?(0,G.jsx)(T,{as:`span`,variant:`body-sm`,font:`mono`,children:$S(e.run.durationMs)||`—`}):(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:`—`})}),(0,G.jsx)(Z.Cell,{children:` `})]});return m?(0,G.jsx)(Z.RowLink,{to:s.workflowRunLink(n,e.runId),LinkComponent:o,...d(f),children:g},p):(0,G.jsx)(Z.RowStatic,{children:g},p)}),(0,G.jsx)(Z.NextPageLoading,{isLoading:i,hasMore:r,setEndOfListElement:a})]})}var _Wi={id:`workflow-schedules`,label:`Schedules`,icon:HS,to:`/workflows/schedules`};function vWi({label:e,children:t}){return(0,G.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,G.jsx)(T,{variant:`meta`,tone:`muted`,className:`uppercase`,children:e}),(0,G.jsx)(`div`,{children:(0,G.jsx)(T,{as:`span`,variant:`body`,className:`block`,children:t})})]})}function yWi(){let{scheduleId:e}=wv(),t=[AR(`/workflows`),_Wi,{id:`schedule`,label:lnn(e),icon:HS}],{paths:n}=on(),{data:r,error:i}=Enn({scheduleId:e,queryOptions:{enabled:!!e}}),{data:a,isLoading:o,error:s,hasNextPage:c,isFetchingNextPage:l,setEndOfListElement:u}=Onn({scheduleId:e,queryOptions:{enabled:!!e}}),d=knn({scheduleId:e});if(i&&JN(i))return(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:t}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:e}),(0,G.jsx)(vR,{variant:`fill`})]});if(i&&YN(i))return(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:t}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:e}),(0,G.jsx)(_R,{variant:`fill`,resource:`schedules`})]});if(i)return(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:t}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:e}),(0,G.jsx)(Vx,{tone:`error`,variant:`fill`,titleSlot:`Failed to load schedule`,descriptionSlot:i.message})]});let f=r?.workflowId,p=r?.agentId;return(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:t}),actionRow:(0,G.jsx)(EP,{children:(0,G.jsxs)(EP.End,{children:[(0,G.jsx)(X,{render:(0,G.jsx)(kv,{to:n.schedulesLink()}),variant:`ghost`,icon:(0,G.jsx)(eS,{}),children:`Back to schedules`}),f?(0,G.jsx)(X,{icon:(0,G.jsx)(KS,{}),render:(0,G.jsx)(kv,{to:n.workflowLink(f)}),variant:`ghost`,children:`Open workflow`}):null,r&&r.status!==`completed`?(0,G.jsx)(X,{onClick:()=>{let e=r.status===`active`?`pause`:`resume`;d.mutate(e,{onSuccess:()=>Qx.success(e===`pause`?`Schedule paused`:`Schedule resumed`),onError:e=>Qx.error(e.message)})},icon:r.status===`active`?(0,G.jsx)(AD,{}):(0,G.jsx)(jD,{}),loading:d.isPending,"data-testid":`schedule-toggle-button`,children:r.status===`active`?`Pause`:`Resume`}):null]})}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:e}),r?(0,G.jsxs)(`div`,{className:`grid h-full grid-cols-[minmax(0,20rem)_1fr] gap-4 overflow-hidden`,children:[(0,G.jsxs)(`div`,{className:`flex h-fit flex-col gap-4 rounded-md border border-border p-4`,children:[(0,G.jsx)(vWi,{label:p?`Agent`:`Workflow`,children:f?(0,G.jsx)(kv,{to:n.workflowLink(f),className:`text-foreground hover:underline`,children:f}):p?(0,G.jsx)(kv,{to:n.agentLink(p),className:`text-foreground hover:underline`,children:p}):`—`}),(0,G.jsxs)(vWi,{label:r.cron?`Cron`:`Runs at`,children:[(0,G.jsx)(T,{as:`span`,variant:`body`,font:`mono`,children:r.cron??(r.runAt?new Date(r.runAt).toLocaleString():`—`)}),r.endAt?(0,G.jsxs)(`span`,{className:`ml-2 text-caption text-muted-foreground`,children:[`until `,new Date(r.endAt).toLocaleString()]}):null,r.timezone?(0,G.jsx)(T,{as:`span`,variant:`caption`,tone:`muted`,className:`ml-2`,children:r.timezone}):null]}),(0,G.jsx)(vWi,{label:`Status`,children:(0,G.jsx)(uWi,{status:r.status})}),(0,G.jsx)(vWi,{label:`Next fire`,children:r.nextFireAt?(0,G.jsx)(yk,{value:r.nextFireAt}):`—`})]}),(0,G.jsxs)(`div`,{className:`overflow-y-auto`,"data-testid":`schedule-triggers-panel`,children:[(0,G.jsx)(T,{variant:`body`,className:`mb-3`,children:`Trigger history`}),s?(0,G.jsx)(Vx,{tone:`error`,titleSlot:`Failed to load trigger history`,descriptionSlot:s.message}):(0,G.jsx)(gWi,{triggers:a??[],isLoading:o,workflowId:f,hasNextPage:c,isFetchingNextPage:l,setEndOfListElement:u})]})]}):null]})}var bWi={target:e=>e.workflowId??e.agentId??``,status:e=>e.status,nextFireAt:e=>e.nextFireAt,lastFireAt:e=>e.lastFireAt},xWi=`minmax(0, 1.2fr) minmax(0, 1.4fr) minmax(0, 1fr) auto auto auto`;function SWi({schedules:e,isLoading:t,search:n=``,sort:r,onSortChange:i}){let{paths:a,Link:o}=on(),s=(0,W.useMemo)(()=>{let t=n.toLowerCase();return P6(t?e.filter(e=>e.id.toLowerCase().includes(t)||(e.workflowId??e.agentId??``).toLowerCase().includes(t)):e,r,bWi)},[e,n,r]),{containerRef:c,getRowProps:l}=UP({count:s.length,global:!0});if(t)return(0,G.jsx)(QP,{columns:xWi});let u=(e,t)=>i?(0,G.jsx)(Z.SortableTopCell,{sortKey:e,sort:r?.key===e?r.direction:void 0,onSortChange:i,children:t}):(0,G.jsx)(Z.TopCell,{children:t});return(0,G.jsxs)(Z,{columns:xWi,className:`min-w-0`,scrollRef:c,children:[(0,G.jsxs)(Z.Top,{children:[u(`target`,`Target`),(0,G.jsx)(Z.TopCell,{children:`Schedule ID`}),(0,G.jsx)(Z.TopCell,{children:`Cron`}),u(`status`,`Status`),u(`nextFireAt`,`Next fire`),u(`lastFireAt`,`Last run`)]}),s.length===0&&n?(0,G.jsx)(Z.NoMatch,{message:`No schedules match your search`}):null,s.length===0&&!n?(0,G.jsx)(Z.NoMatch,{message:`No schedules configured`}):null,s.map((e,t)=>(0,G.jsxs)(Z.RowLink,{to:a.scheduleLink(e.id),LinkComponent:o,...l(t),children:[(0,G.jsx)(Z.NameCell,{children:e.workflowId??e.agentId}),(0,G.jsx)(Z.Cell,{className:`min-w-0`,children:(0,G.jsx)(T,{as:`span`,variant:`body-sm`,tone:`muted`,font:`mono`,className:`block truncate`,title:e.id,children:e.id})}),(0,G.jsx)(Z.Cell,{children:(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-2 whitespace-nowrap`,children:[(0,G.jsx)(T,{as:`span`,variant:`caption`,font:`mono`,children:e.cron??(e.runAt?`once @ ${new Date(e.runAt).toLocaleString()}`:`—`)}),e.timezone?(0,G.jsx)(T,{as:`span`,variant:`meta`,tone:`muted`,children:e.timezone}):null]})}),(0,G.jsx)(Z.Cell,{children:(0,G.jsx)(uWi,{status:e.status})}),(0,G.jsx)(Z.Cell,{children:e.nextFireAt?(0,G.jsx)(yk,{value:e.nextFireAt}):`—`}),(0,G.jsx)(Z.Cell,{children:e.lastRun?(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-2 whitespace-nowrap`,children:[(0,G.jsx)(dWi,{status:e.lastRun.status}),e.lastFireAt?(0,G.jsx)(T,{as:`span`,variant:`caption`,tone:`muted`,children:(0,G.jsx)(yk,{value:e.lastFireAt})}):null]}):e.lastFireAt?(0,G.jsx)(yk,{value:e.lastFireAt}):(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:`Never`})})]},e.id))]})}function CWi({workflowId:e}={}){let{data:t,isLoading:n,error:r}=MR(e?{workflowId:e}:{}),[i,a]=(0,W.useState)(``),[o,s]=(0,W.useState)();return r?(0,G.jsx)(Vx,{tone:`error`,titleSlot:`Failed to load schedules`,descriptionSlot:r.message}):(0,G.jsxs)(`div`,{className:`grid h-full grid-rows-[auto_1fr] gap-4 overflow-hidden`,children:[(0,G.jsx)(`div`,{className:`max-w-120`,children:(0,G.jsx)(CN,{...wN,onValueChange:a,label:`Search schedules`,placeholder:`Search by id or workflow`})}),(0,G.jsx)(`div`,{className:`overflow-y-auto`,children:(0,G.jsx)(SWi,{schedules:t??[],isLoading:n,search:i,sort:o,onSortChange:(e,t)=>s({key:t,direction:e})})})]})}var wWi=[AR(`/workflows`),_Wi];function TWi(){let[e]=Av(),t=e.get(`workflowId`)??void 0,{error:n}=MR(t?{workflowId:t}:{});return n&&JN(n)?(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:wWi}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`Schedules`}),(0,G.jsx)(vR,{variant:`fill`})]}):n&&YN(n)?(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:wWi}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`Schedules`}),(0,G.jsx)(_R,{variant:`fill`,resource:`schedules`})]}):(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:wWi}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`Schedules`}),(0,G.jsx)(`div`,{className:`h-full`,children:(0,G.jsx)(CWi,{workflowId:t})})]})}var EWi=H(`IconArrowDownLeft`,()=>(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`path`,{d:`M6 9V18H15`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`}),(0,G.jsx)(`path`,{d:`M17.75 6.25L7 17`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`})]}),3),DWi={"--belt-hue":`var(--warning-indicator)`};function OWi(e){let t=new Blob([JSON.stringify(e??null)]).size;return t<1024?`${t} B`:`${(t/1024).toFixed(1)} KB`}function kWi(e,t){if(e&&typeof e==`object`&&!Array.isArray(e)){let t=Object.keys(e),[n]=t;if(t.length===1&&n)return n}return t}function AWi({suspendedSteps:e,workflow:t,isStreaming:n,onResume:r}){return n||e.length===0?null:(0,G.jsxs)(`section`,{className:c(ZDt,`pointer-events-auto relative isolate`),"data-testid":`workflow-suspended-steps`,"aria-label":`Step suspended`,children:[(0,G.jsxs)(`div`,{className:`max-h-[calc(100cqh-64px)] overflow-y-auto overscroll-contain rounded-[inherit]`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-3 border-b border-border bg-background px-5 py-4`,children:[(0,G.jsxs)(T,{as:`h2`,variant:`column`,tone:`ink`,className:`flex items-center gap-2`,children:[(0,G.jsx)(vx,{children:(0,G.jsx)(AD,{})}),`Step suspended`]}),(0,G.jsx)(YS,{variant:`orange`,emphasis:`subtle`,children:`Needs input`})]}),e.map(e=>{let n=t.allSteps[e.stepId];if(!n||n.isWorkflow)return null;let i=n?.resumeSchema?MO(JO(n.resumeSchema)):Dd(K(),fd());return(0,G.jsx)(jWi,{step:e,stepSchema:i,description:n.description,onResume:r},`${e.runId}-${e.stepId}`)})]}),(0,G.jsx)(kZe,{status:`ready`,label:`Needs input`,className:`before:hidden`,style:DWi})]})}function jWi({step:e,stepSchema:t,description:n,onResume:r}){let[i,a]=(0,W.useState)(!1),[o,s]=(0,W.useState)(!1);return(0,G.jsxs)(`div`,{className:`space-y-5 p-5 [&+&]:border-t [&+&]:border-border`,children:[(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(T,{as:`p`,variant:`subheading`,tone:`ink`,className:`break-words`,children:e.stepId}),n&&(0,G.jsx)(T,{as:`p`,variant:`caption`,tone:`muted`,children:n})]}),e.suspendPayload!==void 0&&(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(T,{as:`p`,variant:`caption`,tone:`muted`,className:`flex items-center gap-2`,children:[(0,G.jsx)(vx,{children:(0,G.jsx)(EWi,{})}),`The step is asking`]}),(0,G.jsxs)(SC,{open:i,onOpenChange:a,children:[(0,G.jsxs)(CC,{className:c(`bg-card hover:bg-card active:bg-card shadow-raised [--field:var(--field-on-surface)] [--field-disabled:var(--field-on-surface)] [--field-hover:var(--field-hover-on-surface)] [--field-open:var(--field-open-on-surface)]`,`flex w-full items-center justify-between gap-2 rounded-lg px-3 py-2.5`),children:[(0,G.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[(0,G.jsx)(vx,{children:(0,G.jsx)(y,{direction:`right`,className:`text-muted-foreground`})}),(0,G.jsx)(T,{as:`span`,variant:`body`,tone:`ink`,className:`truncate`,children:kWi(e.suspendPayload,e.stepId)})]}),(0,G.jsx)(T,{as:`span`,variant:`caption`,tone:`muted`,className:`shrink-0`,children:OWi(e.suspendPayload)})]}),(0,G.jsx)(wC,{children:(0,G.jsx)(`div`,{"data-testid":`suspended-payload`,className:`pt-2`,children:(0,G.jsx)(hw,{value:JSON.stringify(e.suspendPayload,null,2),editable:!1,className:`w-full overflow-x-auto p-2`,showCopyButton:!1})})})]})]}),(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(T,{as:`p`,variant:`caption`,tone:`muted`,className:`flex items-center gap-2`,children:[(0,G.jsx)(vx,{children:(0,G.jsx)(kI,{})}),`Your response`]}),(0,G.jsx)(`div`,{className:`-mx-5`,children:(0,G.jsx)(pDt,{schema:t,isSubmitLoading:o,submitButtonLabel:`Resume`,submitButtonVariant:`primary`,submitButtonIcon:(0,G.jsx)(jD,{}),submitButtonFullWidth:!0,collapsible:!1,hideHeading:!0,hideInputTypeLabel:!0,onSubmit:async t=>{s(!0);try{await r({stepId:e.stepId.split(`.`),runId:e.runId,resumeData:t})}catch(e){Qx.error(e instanceof Error?e.message:`Error resuming workflow`)}finally{s(!1)}}})})]})]})}function MWi({hidden:e,requestContext:t,canResume:n}){let{result:r,workflow:i,runId:a,isStreamingWorkflow:o}=(0,W.useContext)(zS),s=tmt(r,a),c=omt(t),l=r?.status===`suspended`&&s.length>0&&!o;return!i||!l||!n?null:(0,G.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:(0,G.jsx)(AWi,{suspendedSteps:s,workflow:i,isStreaming:o,onResume:c})},a)}var NWi=H(`IconSkip`,()=>(0,G.jsx)(`path`,{d:`M19 5V19M6.52732 5.16646L15.5625 11.1835C16.1458 11.5719 16.1458 12.4281 15.5625 12.8165L6.52732 18.8335C5.87447 19.2683 5 18.8008 5 18.017V5.98298C5 5.1992 5.87447 4.7317 6.52732 5.16646Z`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`})),PWi={success:{label:`Completed`,icon:cC},failed:{label:`Failed`,icon:Bx},suspended:{label:`Needs input`,icon:AD},waiting:{label:`Waiting`,icon:GS},paused:{label:`Paused`,icon:AD},skipped:{label:`Skipped`,icon:NWi},running:{label:`Running`,icon:BM},canceled:{label:`Canceled`,icon:zx}},FWi={label:`Status unavailable`,icon:uX};function IWi({row:e,isSelected:t,isHovered:n,onSelectStep:r,onHoverStep:i,onOpenInput:a,onOpenOutput:o}){let s=Object.hasOwn(PWi,e.status)?PWi[e.status]:FWi,l=s.icon,u=Ght(e.status),d=e.stepId.slice(0,e.stepId.lastIndexOf(`.`)),f=e.isNestedEntry?e.stepId.slice(e.stepId.lastIndexOf(`.`)+1):e.stepId;return(0,G.jsxs)(`div`,{"data-testid":`workflow-timeline-row`,"data-workflow-step-key":e.stepId,onMouseEnter:()=>!e.isNestedEntry&&i(e.stepId),onMouseLeave:()=>!e.isNestedEntry&&i(null),className:c(`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:[(0,G.jsxs)(`button`,{type:`button`,"aria-disabled":e.isNestedEntry,"aria-pressed":t,onClick:()=>{e.isNestedEntry||r(e.stepId)},title:e.stepId,className:c(`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`,p),children:[(0,G.jsx)(`span`,{"aria-label":s.label,className:c(`grid size-6 flex-none place-items-center rounded-md bg-nested`,Kht[u]),children:(0,G.jsx)(l,{"aria-hidden":!0,className:c(`size-3.5`,e.status===`running`&&`motion-safe:animate-spin`)})}),(0,G.jsxs)(`span`,{className:`min-w-0`,children:[(0,G.jsx)(T,{as:`span`,variant:`meta`,className:`block truncate`,children:f}),e.isNestedEntry&&(0,G.jsxs)(T,{as:`span`,variant:`meta`,tone:`muted`,className:`flex min-w-0 items-center gap-1`,children:[(0,G.jsx)(JXe,{"aria-hidden":!0,className:`size-icon-xs shrink-0`}),(0,G.jsx)(`span`,{className:`truncate`,children:d})]})]})]}),(0,G.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&&(0,G.jsx)(`div`,{"data-testid":`workflow-timeline-bar`,"data-offset":e.timing.offsetPct,"data-width":e.timing.widthPct,className:c(`absolute top-0 h-full min-w-0.5 rounded-sm`,qht[u]),style:{left:`${e.timing.offsetPct}%`,width:`${e.timing.widthPct}%`}})}),(0,G.jsx)(T,{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?(0,G.jsx)(T,{as:`span`,variant:`meta`,font:`mono`,children:$S(e.timing.durationMs)}):(0,G.jsx)(`span`,{"aria-label":`Timing unavailable`,children:`—`})}),(0,G.jsxs)(`div`,{className:`flex items-center`,children:[(0,G.jsx)(X,{type:`button`,variant:`ghost`,size:`icon-sm`,tooltip:`View step input`,disabled:e.step.input===void 0,onClick:t=>a(e,t.currentTarget),children:(0,G.jsx)(fk,{})}),(0,G.jsx)(X,{type:`button`,variant:`ghost`,size:`icon-sm`,tooltip:`View step output`,disabled:e.step.output===void 0,onClick:t=>o(e,t.currentTarget),children:(0,G.jsx)(dk,{})})]})]})}var LWi=e=>e.includes(`.`),RWi=e=>e===`input`||e.endsWith(`.input`),zWi=1;function BWi(e,t){let n=Xht(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 VWi(e,t){let n=Object.entries(e).filter(([e])=>!RWi(e)).map(([e,n])=>({stepId:e,step:n,...BWi(n,t)})).sort((e,t)=>(e.span?.start??1/0)-(t.span?.start??1/0)||e.stepId.localeCompare(t.stepId)),r=n.flatMap(e=>e.span?[e.span]:[]),i=Math.min(...r.map(e=>e.start)),a=Math.max(i,...r.map(e=>e.end)),o=Math.max(a-i,1);return n.map(({stepId:e,step:t,span:n,isLive:r,spansSuspension:a})=>{let s;if(n){let e=n.end-n.start,t=Math.min((n.start-i)/o*100,99);s={durationMs:e,offsetPct:t,widthPct:Math.min(Math.max(e/o*100,zWi),100-t)}}return{stepId:e,step:t,status:gk(t)?`suspended`:t.status,timing:s,spansSuspension:a,isRunning:r,isNestedEntry:LWi(e)}})}var HWi=H(`IconChevronGrabberVertical`,()=>(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`path`,{d:`M8 8.99985L11.2929 5.70696C11.6834 5.31643 12.3166 5.31643 12.7071 5.70696L16 8.99985`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`}),(0,G.jsx)(`path`,{d:`M8 15L11.2929 18.2929C11.6834 18.6834 12.3166 18.6834 12.7071 18.2929L16 15`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`})]})),UWi=H(`IconChevronGrabberVerticalToward`,()=>(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`path`,{d:`M8 18.75L12 14.75L16 18.75`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`}),(0,G.jsx)(`path`,{d:`M8 5.25L12 9.25L16 5.25`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`})]}));function WWi(){let{steps:e}=p$(),{selectedStepId:t,hoverStepId:n,setSelectedStepId:r,setHoverStepId:i}=RS(),[a,o]=(0,W.useState)(()=>Date.now()),[s,l]=(0,W.useState)(!0),[u,d]=(0,W.useState)(!1),{showData:f}=KM(),p=(0,W.useRef)(null),m=VWi(e,a),h=m.some(e=>e.isRunning);return VJe(p,{enabled:h&&!s}),(0,W.useEffect)(()=>{if(!h||s)return;let e=setInterval(()=>o(Date.now()),100);return()=>clearInterval(e)},[h,s]),m.length===0?null:(0,G.jsx)(`div`,{"data-testid":`workflow-timeline`,className:`relative z-20 shrink-0 px-2 pb-2`,children:(0,G.jsxs)(SC,{open:!s,onOpenChange:e=>l(!e),className:c(Pv,`@container/workflow-timeline pointer-events-auto overflow-hidden rounded-xl`),children:[(0,G.jsxs)(`div`,{className:`flex items-center`,children:[(0,G.jsxs)(CC,{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":s?`Expand timeline`:`Collapse timeline`,children:[(0,G.jsx)(`span`,{children:(0,G.jsx)(dG,{"aria-hidden":!0,className:`size-icon-md text-muted-foreground`})}),(0,G.jsx)(`span`,{children:`Timeline`}),(0,G.jsxs)(T,{as:`span`,variant:`meta`,tone:`muted`,children:[m.length,` events`]}),(0,G.jsx)(`span`,{className:`ml-auto`,children:(0,G.jsx)(y,{direction:`right`,className:`size-4`})})]}),!s&&(0,G.jsx)(X,{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?(0,G.jsx)(UWi,{}):(0,G.jsx)(HWi,{})})]}),(0,G.jsx)(wC,{children:(0,G.jsx)(`div`,{ref:p,"data-testid":`workflow-timeline-list`,className:c(`overflow-auto overscroll-contain px-1.5 pb-1.5`,u?`max-h-[min(720px,calc(100dvh-112px))]`:`max-h-[min(320px,40dvh)]`),children:m.map(e=>(0,G.jsx)(IWi,{row:e,isSelected:t===e.stepId,isHovered:n===e.stepId,onSelectStep:r,onHoverStep:i,onOpenInput:(e,t)=>f({type:`step-input`,stepId:e.stepId},t),onOpenOutput:(e,t)=>f({type:`step-output`,stepId:e.stepId},t)},e.stepId))})})]})})}var GWi=({workflowId:e,workflow:t,isLoading:n})=>{let[r]=LS(`workflow`,e),{canExecute:i,isLoading:a}=aS(),{stepDetail:o}=KM(),s=Kw(),c=o?.type===`data`,l=(0,G.jsxs)(`div`,{className:`[container-type:size] relative h-full min-h-0`,children:[(0,G.jsx)(mpr,{workflowId:e,workflow:t,isLoading:n,requestContext:r}),(0,G.jsx)(MWi,{hidden:c,requestContext:r,canResume:!a&&i(`workflows`)}),c&&(0,G.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:(0,G.jsx)(h$,{requestContext:r})}),(0,G.jsx)(`div`,{className:`pointer-events-none absolute right-0 bottom-0 left-[var(--workflow-left-panel-width,0px)] z-20`,children:(0,G.jsx)(WWi,{})})]});return s&&o&&!c?(0,G.jsx)(`div`,{className:`h-full min-h-0 overflow-hidden`,children:(0,G.jsx)(h$,{requestContext:r})}):(0,G.jsxs)(`div`,{className:`relative h-full min-h-0`,children:[l,(0,G.jsxs)($3,{className:`pointer-events-none absolute inset-0 z-30 min-h-0 w-full min-w-0 p-2`,children:[(0,G.jsx)(X3,{id:`workflow-graph`,className:`pointer-events-none min-w-0`}),o&&!c&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(e6,{className:`pointer-events-auto`}),(0,G.jsx)(X3,{id:`workflow-step-detail`,minSize:300,maxSize:`60%`,defaultSize:420,className:`min-w-0`,children:(0,G.jsx)(`div`,{className:`pointer-events-auto h-full min-h-0 overflow-hidden rounded-studio-panel border border-border bg-background`,children:(0,G.jsx)(h$,{requestContext:r})})})]})]})]})},KWi=()=>{let{workflowId:e}=wv(),{data:t,isLoading:n,error:r}=GM({workflowId:e,requestContext:LS(`workflow`,e)[0],queryOptions:{enabled:!!e}});return r&&JN(r)?(0,G.jsx)(vR,{variant:`fill`}):r&&YN(r)?(0,G.jsx)(_R,{variant:`fill`,resource:`workflows`}):(0,G.jsx)(GWi,{workflowId:e,workflow:t??void 0,isLoading:n})};function qWi(){let{workflowId:e}=wv(),{error:t}=MR(e?{workflowId:e}:{});if(!e)return null;let n;return n=t&&JN(t)?(0,G.jsx)(vR,{variant:`fill`}):t&&YN(t)?(0,G.jsx)(_R,{variant:`fill`,resource:`schedules`}):(0,G.jsx)(`div`,{className:`h-full`,children:(0,G.jsx)(CWi,{workflowId:e})}),(0,G.jsxs)(NS,{variant:`page`,children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`Schedules`}),n]})}function JWi(){let{workflowId:e}=wv();return e?(0,G.jsx)(Nbi,{scopedEntityId:e,scopedEntityType:Sp.WORKFLOW_RUN}):null}var YWi=(0,W.createContext)(null);function K9(){let e=(0,W.useContext)(YWi);if(!e)throw Error(`Workspace components must be rendered inside <Workspace.Root>`);return e}var XWi=e=>e?.status;function ZWi(e,t){return JN(e)?`Your session has expired. Sign in again to continue.`:YN(e)?`You don't have permission to access this.`:XN(e)?`This path no longer exists.`:XWi(e)===501?`This workspace does not support this operation.`:t}function QWi({error:e,fallback:t,className:n}){return(0,G.jsx)(mk,{variant:`destructive`,className:n,children:(0,G.jsx)(mk.Message,{children:ZWi(e,t)})})}var $Wi=/^---\r?\n([\s\S]*?)\r?\n---[ \t]*(?:\r?\n|$)/;function eGi(e){let t=$Wi.exec(e);return t?{frontmatter:t[1]??``,body:e.slice(t[0].length)}:{frontmatter:null,body:e}}function tGi({content:e}){let{frontmatter:t,body:n}=eGi(e);return(0,G.jsxs)(G.Fragment,{children:[t!==null&&(0,G.jsx)(`div`,{"data-testid":`workspace-frontmatter`,className:`border-b border-border`,children:(0,G.jsx)(MI,{code:t,lang:`yaml`,overflow:`wrap`,className:`rounded-none border-0 bg-transparent [&_pre]:p-4`})}),(0,G.jsx)(`div`,{className:`p-4`,children:(0,G.jsx)(BL,{children:n})})]})}function nGi(){let{activeFilePath:e}=K9();return e?(0,G.jsx)(T,{as:`span`,variant:`body-sm`,font:`mono`,tone:`muted`,className:`truncate`,"data-testid":`workspace-file-path`,children:e}):null}function rGi({path:e,content:t,mimeType:n}){return a6n(e,n)?(0,G.jsx)(`div`,{className:`flex justify-center p-4`,children:(0,G.jsx)(`img`,{src:`data:${n||`image/png`};base64,${t}`,alt:e.split(`/`).pop(),className:`max-w-full object-contain`})}):o6n(e,n)?(0,G.jsx)(`div`,{className:`flex justify-center p-4`,children:(0,G.jsx)(`video`,{controls:!0,"aria-label":e.split(`/`).pop(),className:`max-w-full`,children:(0,G.jsx)(`source`,{src:`data:${c6n(e,n)};base64,${t}`,type:c6n(e,n)})})}):l6n(e)?(0,G.jsx)(tGi,{content:t}):(0,G.jsx)(MI,{code:t,lang:lZe(e),overflow:`scroll`,className:`rounded-none border-0 bg-transparent [&_pre]:p-4`})}function iGi({renderPreview:e}){let{workspaceId:t,activeFilePath:n}=K9(),{data:r,isLoading:i,error:a}=w6n({workspaceId:t,path:n,queryOptions:{enabled:!!n}});if(!n)return null;if(i)return(0,G.jsxs)(`div`,{"aria-busy":`true`,className:`flex flex-col gap-2 p-4`,children:[(0,G.jsx)(PS,{className:`h-4 w-1/2`}),(0,G.jsx)(PS,{className:`h-4 w-5/6`}),(0,G.jsx)(PS,{className:`h-4 w-2/3`})]});if(!r)return(0,G.jsx)(QWi,{error:a,fallback:`Could not load file.`,className:`m-4`});let o={path:n,content:r.content,mimeType:r.mimeType};return e?.(o)??(0,G.jsx)(rGi,{...o})}var aGi=(e,t)=>e===`.`?t:`${e}/${t}`,oGi=e=>e.split(`/`).slice(0,-1).map((e,t,n)=>n.slice(0,t+1).join(`/`)),sGi=e=>{let t=e.lastIndexOf(`/`);return t===-1?`.`:e.slice(0,t)};function cGi({labeled:e=!1}={}){let{workspaceId:t,onCreateDirectory:n,isReadOnly:r}=K9(),i=a_(),[a,o]=(0,W.useState)(!1),[s,c]=(0,W.useState)(``),[l,u]=(0,W.useState)(!1);if(!n||r(`.`))return null;let d=s.trim().replace(/^\.?\/+|\/+$/g,``),f=async()=>{if(d){u(!0);try{await n(d),await i.invalidateQueries({queryKey:[`workspace`,t,`fs`,`list`,sGi(d)]}),o(!1),c(``)}catch{}finally{u(!1)}}};return(0,G.jsxs)(G.Fragment,{children:[e?(0,G.jsx)(X,{variant:`ghost`,icon:(0,G.jsx)(pP,{}),onClick:()=>o(!0),children:`New folder`}):(0,G.jsx)(X,{variant:`ghost`,size:`icon-sm`,tooltip:`New folder`,onClick:()=>o(!0),children:(0,G.jsx)(pP,{})}),(0,G.jsx)(Zw,{open:a,onOpenChange:o,pending:l,children:(0,G.jsx)(Qw,{size:`sm`,children:(0,G.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),f()},children:[(0,G.jsx)($w,{children:(0,G.jsx)(nT,{children:`New folder`})}),(0,G.jsx)(tT,{children:(0,G.jsx)(Bj,{autoFocus:!0,"aria-label":`Folder path`,placeholder:`docs/guides`,value:s,onChange:e=>c(e.target.value)})}),(0,G.jsxs)(eT,{children:[(0,G.jsx)(iT,{children:`Cancel`}),(0,G.jsx)(X,{type:`submit`,variant:`primary`,disabled:!d,loading:l,children:`Create`})]})]})})})]})}function lGi(e){return`${e.topSource}/${e.name}`}function uGi(e){let t=p6n(e.topSource,e.name);return t?`${t.owner}/${t.repo}/${e.name}`:null}function dGi({open:e,onOpenChange:t,workspaceId:n,onInstall:r,isInstalling:i,installedSkillIds:a=[],installedSkillNames:o=[],writableMounts:s,installedSkillPaths:l}){let[u,d]=(0,W.useState)(``),[f,p]=(0,W.useState)(null),[m,h]=(0,W.useState)(),g=s?.some(e=>e.path===m)?m:s?.[0]?.path,{data:_,isLoading:v}=d6n({workspaceId:n,queryOptions:{enabled:!!n}}),y=u6n({workspaceId:n}),b=(0,W.useMemo)(()=>f?.topSource?p6n(f.topSource,f.name):null,[f]),x=(0,W.useMemo)(()=>!b||!f?null:`https://skills.sh/${b.owner}/${b.repo}/${f.name}`,[b,f]),{data:S,isLoading:C}=f6n({workspaceId:n,owner:b?.owner,repo:b?.repo,skillPath:f?.name,queryOptions:{enabled:!!n&&!!b&&!!f}}),w=rC(e=>{e.trim().length>=2&&y.mutate(e)},300),E=(0,W.useCallback)(e=>{d(e),w(e)},[w]),D=(0,W.useMemo)(()=>u.trim().length>=2?y.data?.skills??[]:_?.skills??[],[u,y.data,_]),O=y.isPending,k=u.trim().length>=2,A=(0,W.useMemo)(()=>{if(!f)return!1;let e=uGi(f);return!!(e&&a.includes(e)||o.includes(f.name))},[f,a,o]),j=(0,W.useCallback)(()=>{f&&b&&r({repository:`${b.owner}/${b.repo}`,skillName:f.name,mount:s&&s.length>1?g:void 0})},[f,b,r,s,g]),M=(0,W.useCallback)(e=>{e||(d(``),p(null),h(void 0)),t(e)},[t]);return(0,G.jsx)(Zw,{open:e,onOpenChange:M,pending:i,children:(0,G.jsxs)(Qw,{size:`xl`,className:`h-[80vh]`,children:[(0,G.jsxs)($w,{children:[(0,G.jsx)(nT,{children:`Add Skill`}),(0,G.jsx)(rT,{children:`Search and install skills from the community registry`})]}),(0,G.jsxs)(tT,{layout:`fill`,children:[(0,G.jsx)(CN,{label:`Search skills`,placeholder:`Search skills`,value:u,onValueChange:E}),(0,G.jsxs)(`div`,{className:`flex min-h-0 flex-1 gap-4`,children:[(0,G.jsxs)(`div`,{className:`flex min-h-0 w-1/2 flex-col`,children:[(0,G.jsx)(T,{as:`p`,variant:`eyebrow`,tone:`muted`,className:`mb-2`,children:k?`Search Results`:`Popular Skills`}),(0,G.jsx)(AS,{className:`flex-1 rounded-lg border border-border`,children:(0,G.jsx)(kS,{className:!v&&!O&&D.length===0?`flex flex-col [&>div]:flex [&>div]:flex-1 [&>div]:flex-col`:void 0,children:v||O?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-5`,children:(0,G.jsx)(Mv,{className:`text-muted-foreground`})}):D.length===0?(0,G.jsx)(Vx,{className:`flex-1`,titleSlot:k?`No skills found`:`No skills available`}):(0,G.jsx)(`div`,{className:`space-y-1 p-2`,children:D.map(e=>{let t=lGi(e),n=uGi(e),r=n&&a.includes(n)||o.includes(e.name),i=f?lGi(f):null;return(0,G.jsx)(`button`,{onClick:()=>p(e),className:c(`w-full rounded-md px-3 py-2 text-left`,`hover:bg-fill-subtle`,i===t&&`border border-border-strong bg-fill-hover`),children:(0,G.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(T,{as:`span`,variant:`subheading`,tone:`ink`,className:`truncate`,children:e.name}),r&&(0,G.jsxs)(T,{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:[(0,G.jsx)(cC,{className:`size-icon-xs`}),`Installed`]})]}),(0,G.jsx)(T,{as:`p`,variant:`caption`,tone:`muted`,className:`truncate`,children:e.topSource})]}),(0,G.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1 text-muted-foreground`,children:[(0,G.jsx)(SI,{className:`size-icon-xs`}),(0,G.jsx)(T,{as:`span`,variant:`caption`,children:e.installs.toLocaleString()})]})]})},t)})})})})]}),(0,G.jsxs)(`div`,{className:`flex min-h-0 w-1/2 flex-col`,children:[(0,G.jsx)(T,{as:`p`,variant:`eyebrow`,tone:`muted`,className:`mb-2`,children:`Preview`}),(0,G.jsx)(`div`,{className:`flex flex-1 flex-col overflow-hidden rounded-lg border border-border`,children:f?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`border-b border-border bg-card p-4`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,G.jsx)(`div`,{className:`rounded-lg bg-muted p-2`,children:(0,G.jsx)(j6,{className:`size-icon-lg text-muted-foreground`})}),(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsx)(T,{as:`h3`,variant:`subheading`,tone:`ink`,className:`truncate`,children:f.name}),(0,G.jsxs)(`div`,{className:`mt-1 flex items-center gap-3 text-muted-foreground`,children:[(0,G.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(A6,{className:`size-icon-xs`}),(0,G.jsx)(T,{as:`span`,variant:`caption`,className:`block`,children:f.topSource})]}),(0,G.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(SI,{className:`size-icon-xs`}),(0,G.jsxs)(T,{as:`span`,variant:`caption`,className:`block`,children:[f.installs.toLocaleString(),` installs`]})]})]})]}),b&&(0,G.jsx)(`a`,{href:`https://github.com/${b.owner}/${b.repo}`,target:`_blank`,rel:`noopener noreferrer`,className:c(`text-muted-foreground hover:text-foreground`,`transition-[color] duration-fast ease-out-custom motion-reduce:transition-none`),title:`View on GitHub`,children:(0,G.jsx)(nF,{className:`size-icon-md`})})]})}),C?(0,G.jsx)(`div`,{className:`flex flex-1 items-center justify-center`,children:(0,G.jsx)(Mv,{className:`text-muted-foreground`})}):S?(0,G.jsx)(AS,{className:`flex-1`,children:(0,G.jsx)(`div`,{className:`p-4`,children:(0,G.jsx)(BL,{children:S})})}):(0,G.jsx)(Vx,{className:`flex-1`,iconSlot:(0,G.jsx)(k6,{}),titleSlot:`Preview unavailable`,actionSlot:x&&(0,G.jsxs)(`a`,{href:x,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center gap-1 text-info-indicator hover:underline`,children:[(0,G.jsxs)(T,{as:`span`,variant:`caption`,className:`block`,children:[`View on skills.sh`,` `]}),(0,G.jsx)(nF,{className:`size-icon-xs`})]})})]}):(0,G.jsx)(Vx,{variant:`fill`,iconSlot:(0,G.jsx)(k6,{}),titleSlot:`Select a skill to preview`})})]})]}),f&&s&&s.length>1&&(0,G.jsxs)(ZO,{orientation:`horizontal`,className:c(`bg-card hover:bg-card active:bg-card shadow-raised [--field:var(--field-on-surface)] [--field-disabled:var(--field-on-surface)] [--field-hover:var(--field-hover-on-surface)] [--field-open:var(--field-open-on-surface)]`,`gap-3 rounded-lg p-3`),children:[(0,G.jsx)(fP,{className:`size-icon-md shrink-0 text-muted-foreground`}),(0,G.jsx)($O,{className:`whitespace-nowrap`,children:`Install to`}),(0,G.jsxs)(Mk,{value:g,onValueChange:h,children:[(0,G.jsx)(Pk,{className:`flex-1`,children:(0,G.jsx)(Nk,{})}),(0,G.jsx)(Fk,{children:s.map(e=>{let t=e.displayName??e.name??e.provider??`unknown`;return(0,G.jsxs)(Ik,{value:e.path,children:[t,` (`,e.path,`)`]},e.path)})})]})]})]}),f&&(0,G.jsxs)(eT,{children:[A&&s&&s.length>1&&(()=>{let e=l?.[f.name];if(!e)return null;let t=s.find(t=>e.startsWith(t.path+`/`)||e===t.path);return t?(0,G.jsxs)(T,{as:`span`,variant:`caption`,tone:`muted`,className:`mr-auto`,children:[`Installed at `,t.path]}):null})(),(0,G.jsx)(iT,{children:`Cancel`}),(0,G.jsx)(Xw,{onConfirm:j,disabled:!b||A,"data-testid":`install-skill-button`,children:A?`Already installed`:`Install`})]})]})})}function fGi({labeled:e=!1}){let{workspaceId:t,addSkill:n}=K9(),[r,i]=(0,W.useState)(!1),[a,o]=(0,W.useState)(!1);if(!n)return null;let{onInstall:s,...c}=n,l=async e=>{o(!0);try{await s(e),i(!1)}catch{}finally{o(!1)}};return(0,G.jsxs)(G.Fragment,{children:[e?(0,G.jsx)(X,{icon:(0,G.jsx)(HXr,{}),variant:`ghost`,onClick:()=>i(!0),children:`Add skill`}):(0,G.jsx)(X,{variant:`ghost`,size:`icon-sm`,"aria-label":`Add skill`,tooltip:`Add skill`,onClick:()=>i(!0),children:(0,G.jsx)(HXr,{})}),(0,G.jsx)(dGi,{...c,open:r,onOpenChange:i,workspaceId:t,onInstall:e=>void l(e),isInstalling:a})]})}function pGi({workspaceId:e,activeFilePath:t,onDelete:n,onCreateDirectory:r,onActiveFileChange:i,readOnlyPaths:a,searchFiles:o=!0,searchSkills:s=!0,fileCount:c,skillCount:l,addSkill:u,children:d}){let[f,p]=(0,W.useState)(!1),[m,h]=(0,W.useState)(``),[g,_]=(0,W.useState)(()=>new Set(oGi(t??``))),[v,y]=(0,W.useState)(t);if(t!==v){y(t);let e=oGi(t??``).filter(e=>!g.has(e));e.length>0&&_(new Set([...g,...e]))}let b=a?.join(`
888
888
  `)??``,x=(0,W.useMemo)(()=>({workspaceId:e,activeFilePath:t,setActiveFilePath:i,isSearching:f,setSearching:e=>{p(e),e||h(``)},query:m,setQuery:h,onDelete:n,onCreateDirectory:r,isReadOnly:e=>(b?b.split(`
889
889
  `):[]).some(t=>t===`.`||e===t||e.startsWith(`${t}/`)),searchFiles:o,searchSkills:s,fileCount:c,skillCount:l,addSkill:u,openFolders:g,setFolderOpen:(e,t)=>_(n=>{if(n.has(e)===t)return n;let r=new Set(n);return t?r.add(e):r.delete(e),r})}),[e,t,f,m,n,r,i,b,o,s,c,l,u,g]);return(0,G.jsx)(YWi.Provider,{value:x,children:d})}var mGi=e=>(0,G.jsx)(`svg`,{width:`18`,height:`18`,viewBox:`-1 -1 18 18`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,...e,children:(0,G.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`})}),hGi=e=>(0,G.jsx)(`svg`,{width:`18`,height:`18`,viewBox:`-1 -1 18 18`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,...e,children:(0,G.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 gGi(){let{isSearching:e,setSearching:t,searchFiles:n,searchSkills:r}=K9();return!n&&!r?null:(0,G.jsx)(X,{variant:`ghost`,size:`icon-sm`,tooltip:`Search files and skills`,"aria-pressed":e,onClick:()=>t(!e),children:(0,G.jsx)(hGi,{})})}function _Gi(){let{isSearching:e}=K9();return e?(0,G.jsx)(bGi,{}):(0,G.jsx)(yGi,{})}var vGi=(e,t)=>`${e} ${t}${e===1?``:`s`}`;function yGi(){let{fileCount:e,skillCount:t}=K9();return(0,G.jsx)(T,{as:`span`,variant:`label`,tone:`muted`,className:`block min-w-0`,children:(0,G.jsxs)(TC,{singleLine:!0,children:[(0,G.jsx)(TC.Item,{children:e===void 0?`Files`:vGi(e,`File`)}),t===void 0?null:(0,G.jsx)(TC.Item,{children:vGi(t,`Skill`)})]})})}function bGi(){let{setSearching:e,setQuery:t}=K9(),[n,r]=(0,W.useState)(``),[,i]=(0,W.useTransition)();return(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(Bj,{type:`search`,size:`sm`,autoFocus:!0,"aria-label":`Search query`,placeholder:`Search files and skills`,value:n,onChange:e=>{let n=e.target.value;r(n),i(()=>t(n))},onKeyDown:t=>{t.key===`Escape`&&e(!1)}}),(0,G.jsx)(X,{variant:`ghost`,size:`icon-sm`,tooltip:`Close search`,onClick:()=>e(!1),children:(0,G.jsx)(gw,{})})]})}function xGi(){let{workspaceId:e,query:t,activeFilePath:n,setActiveFilePath:r,searchFiles:i,searchSkills:a}=K9(),{data:o,isLoading:s,isError:l,error:u}=O6n({workspaceId:e,query:t,files:i,skills:a,queryOptions:{enabled:t.trim().length>0&&(i||a)}});return t.trim()?s?(0,G.jsxs)(`div`,{"aria-busy":`true`,className:`flex flex-col gap-2 p-2`,children:[(0,G.jsx)(PS,{className:`h-4 w-3/4`}),(0,G.jsx)(PS,{className:`h-4 w-2/3`})]}):l?(0,G.jsx)(QWi,{error:u,fallback:`Search failed.`,className:`m-2`}):o?.length?(0,G.jsx)(`ul`,{"aria-label":`Search results`,className:`flex flex-col py-1`,children:o.map(e=>(0,G.jsx)(`li`,{children:(0,G.jsxs)(`button`,{type:`button`,title:e.path,onClick:()=>r(e.path),className:c(`text-foreground`,`flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left hover:bg-fill-subtle`,n===e.path&&`bg-fill`),children:[(0,G.jsx)(vx,{size:`sm`,children:e.kind===`skill`?(0,G.jsx)(j6,{}):(0,G.jsx)(mGi,{})}),(0,G.jsx)(T,{as:`span`,variant:`body-sm`,className:`truncate`,children:e.label})]})},e.path))}):(0,G.jsx)(Vx,{titleSlot:`No results`}):(0,G.jsx)(Vx,{titleSlot:`Search files and skills`,descriptionSlot:`Type to find matching content.`})}function SGi({mount:e}){switch(e.icon||e.provider){case`aws-s3`:case`s3`:return(0,G.jsx)(GZn,{className:`text-foreground`});case`google-cloud`:case`google-cloud-storage`:case`gcs`:return(0,G.jsx)(XZn,{});case`azure-blob`:case`azure`:return(0,G.jsx)(JZn,{className:`text-badge-blue-indicator`});case`cloudflare`:case`cloudflare-r2`:case`r2`:return(0,G.jsx)(U8,{className:`text-badge-orange-indicator`});case`neon`:return(0,G.jsx)(U8,{className:`text-badge-green-indicator`});case`minio`:return(0,G.jsx)(Adr,{className:`text-badge-red-indicator`});case`database`:return(0,G.jsx)(aT,{className:`text-badge-green-indicator`});case`local`:case`folder`:return(0,G.jsx)(fP,{className:`text-badge-amber-indicator`});case`hard-drive`:return(0,G.jsx)(Adr,{className:`text-muted-foreground`});default:return(0,G.jsx)(U8,{className:`text-muted-foreground`})}}var CGi=e=>(0,G.jsx)(`svg`,{width:`18`,height:`18`,viewBox:`-1 -1 18 18`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,...e,children:(0,G.jsx)(`path`,{d:`M1.5 8.5V8C1.5 7.60218 1.65804 7.22064 1.93934 6.93934C2.22064 6.65804 2.60218 6.5 3 6.5H13C13.3978 6.5 13.7794 6.65804 14.0607 6.93934C14.342 7.22064 14.5 7.60218 14.5 8V8.5M8.70667 4.20667L7.29333 2.79333C7.20048 2.70037 7.09022 2.62661 6.96886 2.57628C6.84749 2.52595 6.71739 2.50003 6.586 2.5H3C2.60218 2.5 2.22064 2.65804 1.93934 2.93934C1.65804 3.22064 1.5 3.60218 1.5 4V12C1.5 12.3978 1.65804 12.7794 1.93934 13.0607C2.22064 13.342 2.60218 13.5 3 13.5H13C13.3978 13.5 13.7794 13.342 14.0607 13.0607C14.342 12.7794 14.5 12.3978 14.5 12V6C14.5 5.60218 14.342 5.22064 14.0607 4.93934C13.7794 4.65804 13.3978 4.5 13 4.5H9.414C9.14887 4.49977 8.89402 4.39426 8.70667 4.20667Z`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`})}),wGi=e=>{let 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 TGi(){let{workspaceId:e,activeFilePath:t,setActiveFilePath:n}=K9(),{data:r,isLoading:i,error:a}=jX({workspaceId:e,path:`.`}),[o,s]=(0,W.useState)(null);return i?(0,G.jsx)(NGi,{}):r?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(w8,{"aria-label":`Workspace files`,selectedId:t,onSelect:n,className:`py-1`,children:(0,G.jsx)(EGi,{entries:r,parent:`.`,onRequestDelete:s})}),(0,G.jsx)(MGi,{entry:o,onClose:()=>s(null)})]}):(0,G.jsx)(QWi,{error:a,fallback:`Could not load files.`,className:`m-2`})}function EGi({entries:e,parent:t,onRequestDelete:n}){return e.map(e=>{let r=aGi(t,e.name);return e.type===`directory`?(0,G.jsx)(kGi,{name:e.name,path:r,mount:e.mount,onRequestDelete:n},e.name):(0,G.jsx)(jGi,{name:e.name,size:e.size,path:r,onRequestDelete:n},e.name)})}function DGi({children:e}){return(0,G.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 OGi({name:e,onClick:t}){return(0,G.jsx)(X,{variant:`destructive-ghost`,size:`icon-sm`,tooltip:`Delete ${e}`,onClick:e=>{e.stopPropagation(),t()},onKeyDown:e=>e.stopPropagation(),children:(0,G.jsx)(Rj,{})})}function kGi({name:e,path:t,mount:n,onRequestDelete:r}){let{workspaceId:i,onDelete:a,onCreateDirectory:o,isReadOnly:s,openFolders:c,setFolderOpen:l}=K9(),u=c.has(t),{isLoading:d}=jX({workspaceId:i,path:t,queryOptions:{enabled:u}}),[f,p]=(0,W.useState)(!1),m=a&&!s(t),h=o&&!s(t);return(0,G.jsxs)(w8.Folder,{id:t,open:u,onOpenChange:e=>l(t,e),children:[(0,G.jsxs)(w8.FolderTrigger,{actions:m||h?(0,G.jsxs)(DGi,{children:[h?(0,G.jsx)(X,{variant:`ghost`,size:`icon-sm`,tooltip:`New folder in ${e}`,onClick:e=>{e.stopPropagation(),l(t,!0),p(!0)},onKeyDown:e=>e.stopPropagation(),children:(0,G.jsx)(pP,{})}):null,m?(0,G.jsx)(OGi,{name:e,onClick:()=>r({path:t,type:`directory`})}):null]}):void 0,children:[(0,G.jsx)(w8.Icon,{children:n?(0,G.jsx)(`span`,{role:`img`,"aria-label":`Mount: ${n.displayName??n.provider}`,title:[n.displayName??n.provider,n.description].filter(Boolean).join(`: `),className:`flex`,children:(0,G.jsx)(SGi,{mount:n})}):(0,G.jsx)(CGi,{})}),(0,G.jsx)(w8.Label,{children:e}),n?.status===`error`?(0,G.jsx)(`span`,{role:`img`,"aria-label":`Mount error: ${n.error??`unavailable`}`,title:n.error,className:`flex shrink-0`,children:(0,G.jsx)(Ux,{className:`size-icon-xs text-destructive-foreground`})}):null,n&&s(t)?(0,G.jsx)(`span`,{role:`img`,"aria-label":`Read-only`,title:`Read-only`,className:`flex shrink-0`,children:(0,G.jsx)(zN,{className:`size-icon-xs text-muted-foreground`})}):null,u&&d?(0,G.jsx)(`span`,{className:`flex shrink-0 animate-in delay-200 fill-mode-backwards fade-in`,children:(0,G.jsx)(Mv,{size:`sm`,"aria-label":`Loading ${e}`,className:`size-3 text-muted-foreground`})}):null]}),(0,G.jsx)(w8.FolderContent,{children:u?(0,G.jsx)(AGi,{path:t,creating:f,onCreated:()=>p(!1),onRequestDelete:r}):null})]})}function AGi({path:e,creating:t,onCreated:n,onRequestDelete:r}){let{workspaceId:i,onCreateDirectory:a}=K9(),o=a_(),{data:s,isLoading:c,error:l}=jX({workspaceId:i,path:e}),u=async t=>{try{await a?.(aGi(e,t.replace(/^\/+|\/+$/g,``)))}catch{return}n(),await o.invalidateQueries({queryKey:[`workspace`,i,`fs`,`list`,e]})};return(0,G.jsxs)(G.Fragment,{children:[t?(0,G.jsx)(w8.Input,{type:`folder`,placeholder:`Folder name`,onSubmit:e=>void u(e),onCancel:n}):null,c?null:s?(0,G.jsx)(EGi,{entries:s,parent:e,onRequestDelete:r}):(0,G.jsx)(QWi,{error:l,fallback:`Could not load folder.`,className:`my-1 mr-1`})]})}function jGi({name:e,size:t,path:n,onRequestDelete:r}){let{onDelete:i,isReadOnly:a,activeFilePath:o}=K9(),s=i&&!a(n),c=n===o,l=(0,W.useRef)(null);return(0,W.useEffect)(()=>{c&&l.current?.scrollIntoView?.({block:`nearest`})},[c]),(0,G.jsxs)(w8.File,{ref:l,id:n,children:[(0,G.jsx)(w8.Icon,{children:(0,G.jsx)(mGi,{})}),(0,G.jsx)(w8.Label,{children:e}),(0,G.jsxs)(DGi,{children:[t===void 0?null:(0,G.jsx)(T,{as:`span`,variant:`caption`,tone:`faint`,font:`mono`,children:wGi(t)}),s?(0,G.jsx)(OGi,{name:e,onClick:()=>r({path:n,type:`file`})}):null]})]})}function MGi({entry:e,onClose:t}){let{workspaceId:n,activeFilePath:r,setActiveFilePath:i,onDelete:a}=K9(),o=a_(),[s,c]=(0,W.useState)(!1),l=e?.path.split(`/`).pop(),u=async()=>{if(e&&a){c(!0);try{await a(e)}catch{return}finally{c(!1)}(r===e.path||r?.startsWith(`${e.path}/`))&&i(void 0),o.removeQueries({queryKey:[`workspace`,n,`fs`,`list`,e.path]}),await o.invalidateQueries({queryKey:[`workspace`,n,`fs`,`list`,sGi(e.path)]}),t()}},d=null;return e&&(d=e.type===`directory`?`This permanently deletes the folder "${l}" and everything inside it.`:`This permanently deletes "${l}".`),(0,G.jsx)(HM,{open:e!==null,onOpenChange:e=>{!e&&!s&&t()},children:(0,G.jsxs)(HM.Content,{children:[(0,G.jsxs)(HM.Header,{children:[(0,G.jsxs)(HM.Title,{children:[`Delete `,e?.type===`directory`?`folder`:`file`,`?`]}),(0,G.jsxs)(HM.Description,{children:[d,` This action cannot be undone.`]})]}),(0,G.jsxs)(HM.Footer,{children:[(0,G.jsx)(HM.Cancel,{disabled:s,children:`Cancel`}),(0,G.jsx)(X,{variant:`destructive`,onClick:()=>void u(),loading:s,children:`Delete`})]})]})})}function NGi(){return(0,G.jsxs)(`div`,{"data-testid":`workspace-tree-skeleton`,"aria-busy":`true`,className:`flex flex-col gap-2 py-2 pl-[18px]`,children:[(0,G.jsx)(PS,{className:`h-4 w-3/4`}),(0,G.jsx)(PS,{className:`h-4 w-1/2`}),(0,G.jsx)(PS,{className:`h-4 w-2/3`})]})}function PGi({children:e,...t}){return(0,G.jsx)(pGi,{...t,children:(0,G.jsx)(FGi,{children:e})})}function FGi({children:e}){let{workspaceId:t}=K9(),{data:n,error:r}=jX({workspaceId:t,path:`.`});return(n?n.length===0:XN(r))?(0,G.jsx)(Vx,{variant:`fill`,titleSlot:`This workspace is empty`,descriptionSlot:`Files written by your agents will show up here.`,actionSlot:(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center justify-center gap-2`,children:[(0,G.jsx)(cGi,{labeled:!0}),(0,G.jsx)(fGi,{labeled:!0})]})}):(0,G.jsx)(`div`,{className:`size-full overflow-hidden`,children:(0,G.jsx)($3,{className:`size-full min-h-0 min-w-0`,orientation:`horizontal`,children:e})})}function IGi({children:e}){return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Z3,{direction:`left`,id:`workspace-aside`,minSize:200,maxSize:`50%`,defaultSize:`25%`,collapsible:!1,className:`min-w-0`,children:(0,G.jsx)(`div`,{className:`flex h-full min-h-0 flex-col`,children:e})}),(0,G.jsx)(e6,{className:`w-px bg-border`})]})}function LGi({children:e,actions:t}){let{isSearching:n}=K9();return(0,G.jsxs)(`div`,{className:`flex h-11 shrink-0 items-center gap-2 border-b border-border px-3`,children:[(0,G.jsx)(`div`,{className:`min-w-0 flex-1`,children:e}),t&&!n?(0,G.jsx)(`div`,{className:`flex shrink-0 items-center gap-1`,children:t}):null]})}function RGi(){let{isSearching:e}=K9();return(0,G.jsx)(AS,{className:`min-h-0 flex-1 px-2 py-1`,children:e?(0,G.jsx)(xGi,{}):(0,G.jsx)(TGi,{})})}function zGi({children:e}){return(0,G.jsx)(X3,{id:`workspace-active-file`,className:`flex min-w-0 flex-col`,minSize:30,children:e})}function BGi({children:e}){return(0,G.jsx)(`div`,{className:`flex h-11 shrink-0 items-center gap-2 border-b border-border px-4`,children:e})}function VGi({renderPreview:e}){let{activeFilePath:t}=K9();return t?(0,G.jsx)(AS,{className:`min-h-0 flex-1`,children:(0,G.jsx)(iGi,{renderPreview:e})}):(0,G.jsx)(Vx,{variant:`fill`,titleSlot:`Select a file`})}var q9={Root:PGi,Aside:IGi,AsideHeader:LGi,Search:_Gi,SearchToggle:gGi,CreateDirectory:cGi,Tree:RGi,ActiveFile:zGi,ActiveFileHeader:BGi,FilePath:nGi,ActiveFileContent:VGi};function HGi({asideActions:e,renderPreview:t,...n}){return(0,G.jsxs)(q9.Root,{...n,children:[(0,G.jsxs)(q9.Aside,{children:[(0,G.jsx)(q9.AsideHeader,{actions:(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(q9.SearchToggle,{}),(0,G.jsx)(q9.CreateDirectory,{}),(0,G.jsx)(fGi,{}),e]}),children:(0,G.jsx)(q9.Search,{})}),(0,G.jsx)(q9.Tree,{})]}),(0,G.jsxs)(q9.ActiveFile,{children:[(0,G.jsx)(q9.ActiveFileHeader,{children:(0,G.jsx)(q9.FilePath,{})}),(0,G.jsx)(q9.ActiveFileContent,{renderPreview:t})]})]})}var UGi=()=>(0,G.jsx)(Vx,{titleSlot:`No Workspaces yet`,descriptionSlot:(0,G.jsxs)(G.Fragment,{children:[`Add a workspace to your Mastra configuration to `,(0,G.jsx)(`br`,{}),`manage files, skills, and enable semantic search.`]}),actionSlot:(0,G.jsx)(X,{variant:`ghost`,render:(0,G.jsx)(`a`,{href:`https://mastra.ai/en/docs/workspace/overview`,target:`_blank`,rel:`noopener noreferrer`}),icon:(0,G.jsx)(nF,{}),children:`Workspaces documentation`}),variant:`fill`}),WGi=()=>(0,G.jsx)(Vx,{titleSlot:`Workspace Not Configured`,descriptionSlot:(0,G.jsxs)(G.Fragment,{children:[`No workspace is configured. Add a workspace to your `,(0,G.jsx)(`br`,{}),`Mastra configuration to manage files, skills, and enable semantic search.`]}),actionSlot:(0,G.jsx)(X,{variant:`ghost`,render:(0,G.jsx)(`a`,{href:`https://mastra.ai/en/docs/workspace/overview`,target:`_blank`,rel:`noopener noreferrer`}),icon:(0,G.jsx)(nF,{}),children:`Workspaces documentation`}),variant:`fill`}),GGi=()=>(0,G.jsx)(Vx,{titleSlot:`Workspace Not Supported`,descriptionSlot:(0,G.jsxs)(G.Fragment,{children:[`The workspace feature requires a newer version of `,(0,G.jsx)(`code`,{className:`text-foreground`,children:`@mastra/core`}),`.`,(0,G.jsx)(`br`,{}),`Please upgrade your dependencies to enable workspace functionality.`]}),actionSlot:(0,G.jsx)(X,{variant:`ghost`,render:(0,G.jsx)(`a`,{href:`https://mastra.ai/en/docs/workspace/overview`,target:`_blank`,rel:`noopener noreferrer`}),icon:(0,G.jsx)(nF,{}),children:`Workspaces documentation`}),variant:`fill`}),KGi=`.agents/skills`,qGi=e=>e.replace(/^\.?\/+|\/+$/g,``);function JGi({workspaceId:e,showInitWarning:t,skills:n}){let{data:r}=jX({workspaceId:e,path:KGi,queryOptions:{enabled:!!n}}),i=n&&r?r.filter(e=>e.type===`directory`&&!n.some(t=>t.name===e.name||qGi(t.path)===`${KGi}/${e.name}`)):[];return!t&&i.length===0?null:(0,G.jsxs)(`div`,{className:`flex shrink-0 flex-col gap-2 border-b border-border p-3`,children:[t&&(0,G.jsx)(mk,{variant:`warning`,children:(0,G.jsxs)(mk.Message,{children:[`File search requires `,(0,G.jsx)(`code`,{children:`workspace.init()`}),` to index files from your configured`,` `,(0,G.jsx)(`code`,{children:`autoIndexPaths`}),`.`]})}),i.length>0&&(0,G.jsx)(mk,{variant:`warning`,title:`Skills installed but not discovered`,children:(0,G.jsxs)(mk.Message,{children:[i.map(e=>e.name).join(`, `),` `,i.length===1?`is`:`are`,` in`,` `,(0,G.jsx)(`code`,{children:KGi}),` but not discovered. Add this path to your workspace skills configuration to see `,i.length===1?`it`:`them`,`.`]})})]})}var J9=[AR(`/workspaces`)],YGi=e=>YN(e)?`you don't have permission to modify this workspace`:e instanceof Error?e.message:`Unknown error`;function XGi(){let{workspaceId:e}=wv(),[t,n]=Av(),r=Cv(),i=a_(),a=t.get(`file`),{data:o,error:s,isLoading:c}=y6n(),l=o?.workspaces??[],u=e??l[0]?.id,{data:d,isLoading:f,error:p}=v6n({workspaceId:u,queryOptions:{enabled:!!u}}),m=JN(s)||JN(p),h=YN(s)||YN(p),g=e6n(s)||e6n(p),_=u?l.find(e=>e.id===u):void 0,v=e=>{let r=new URLSearchParams(t);for(let[t,n]of Object.entries(e))n===null?r.delete(t):r.set(t,n);n(r)},y=e=>{r(`/workspaces/${e}`)},b=e=>{v({file:e??null})},x=a??void 0,S=x6n(),C=S6n(),w=d?.isWorkspaceConfigured??!1,T=d?.capabilities?.hasDynamicFilesystem??!1,E=(d?.capabilities?.hasFilesystem??!1)&&!T,D=d?.capabilities?.hasSkills??!1,{data:O,refetch:k}=k6n({workspaceId:u,queryOptions:{enabled:!!u&&E}}),A=m6n(),j=h6n(),M=g6n(),N=e=>{let t=/^\.agents\/skills\/([^/]+)$/.exec(e);if(t)return ie.find(t=>t.path?.replace(/^\.?\/+|\/+$/g,``)===e)?.name??t[1]},P=async()=>{if(u)try{let e=await j.mutateAsync({workspaceId:u}),t=e.updated.filter(e=>!e.success);t.length>0?Qx.error(`Failed to update ${t.map(e=>e.skillName).join(`, `)}`):Qx.success(`${e.updated.length} skill(s) updated`),i.invalidateQueries({queryKey:[`workspace`,u,`fs`]})}catch(e){Qx.error(`Failed to update skills: ${e instanceof Error?e.message:`Unknown error`}`)}},F=async({path:e,type:t})=>{if(!u)return;let n=t===`directory`?N(e):void 0;if(n)try{if(!(await M.mutateAsync({workspaceId:u,skillName:n})).success)throw Error(`Failed to remove skill "${n}"`);Qx.success(`Skill "${n}" removed`),k()}catch(e){throw Qx.error(e instanceof Error?e.message:`Failed to remove skill`),e}else try{await S.mutateAsync({path:e,recursive:!0,force:!0,workspaceId:u})}catch(t){throw Qx.error(`Failed to delete ${e}: ${YGi(t)}`),t}},I=_?.safety?.readOnly??!1,{canEdit:L,canDelete:R,canExecute:z,isLoading:B}=aS(),ee=!B&&L(`workspaces`)&&!I,V=!B&&R(`workspaces`)&&!I,te=!B&&z(`workspaces`),ne=E&&D&&ee,H=d?.mounts,U=H?.filter(e=>!e.readOnly).map(e=>({path:e.path,displayName:e.displayName,icon:e.icon,provider:e.provider,name:e.name})),re=async e=>{if(u)try{let t=await A.mutateAsync({...e,workspaceId:u});if(!t.success)throw Error(`Unknown error`);i.invalidateQueries({queryKey:[`workspace`,u,`fs`]}),k(),Qx.success(`Skill "${t.skillName}" installed successfully (${t.filesWritten} files)`)}catch(e){throw Qx.error(`Failed to install skill: ${e instanceof Error?e.message:`Unknown error`}`),e}},ie=O?.skills??[],ae=O?.isSkillsConfigured??!1,oe=te&&E&&!!(d?.capabilities?.canBM25||d?.capabilities?.canVector),se=te&&D&&ae&&ie.length>0,ce=I?[`.`]:(H??[]).filter(e=>e.readOnly).map(e=>e.path.replace(/^\/+|\/+$/g,``)||`.`);if(c)return(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:J9}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`Workspaces`}),(0,G.jsx)(Ft,{fill:!0})]});if(m)return(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:J9}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`Workspaces`}),(0,G.jsx)(vR,{variant:`fill`})]});if(h)return(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:J9}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`Workspaces`}),(0,G.jsx)(_R,{variant:`fill`,resource:`workspaces`})]});if(g)return(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:J9}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`Workspaces`}),(0,G.jsx)(GGi,{})]});let le=s||p;if(le)return(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:J9}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`Workspaces`}),(0,G.jsx)(Vx,{tone:`error`,variant:`fill`,titleSlot:`Failed to load workspace`,descriptionSlot:le.message})]});if(!c&&l.length===0)return(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:J9}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`Workspaces`}),(0,G.jsx)(UGi,{})]});if(!f&&!c&&!w)return(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:J9}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`Workspaces`}),(0,G.jsx)(WGi,{})]});let ue=l.map(e=>({value:e.id,label:e.name,description:e.source===`agent`?`Agent: ${e.agentName}`:`Global workspace`,end:(0,G.jsxs)(`span`,{className:`flex shrink-0 gap-1`,children:[e.safety?.readOnly&&(0,G.jsx)(YS,{size:`xs`,variant:`warning`,children:`Read-only`}),e.capabilities.hasFilesystem&&(0,G.jsx)(YS,{size:`xs`,children:`FS`}),e.capabilities.hasSandbox&&(0,G.jsx)(YS,{size:`xs`,children:`Sandbox`}),e.capabilities.hasSkills&&(0,G.jsx)(YS,{size:`xs`,children:`Skills`})]})}));return(0,G.jsxs)(NS,{variant:`page`,body:`fixed`,breadcrumbs:(0,G.jsx)(lN,{crumbs:J9}),headerActions:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(cN,{"aria-label":`Workspace`,variant:`ghost`,className:`w-auto`,options:ue,value:_?.id,onValueChange:y,placeholder:`Select workspace`,searchPlaceholder:`Search workspaces`,emptyText:`No workspaces found.`}),I&&(0,G.jsx)(YS,{size:`xs`,variant:`warning`,children:`Read-only`})]}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`Workspaces`}),(0,G.jsxs)(`div`,{className:`flex min-h-0 flex-col`,children:[E&&u&&(0,G.jsx)(JGi,{workspaceId:u,showInitWarning:oe&&!f&&d?.status!==`ready`,skills:D&&O?ie:void 0}),E&&u&&(0,G.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,G.jsx)(HGi,{workspaceId:u,activeFilePath:x,onActiveFileChange:b,readOnlyPaths:ce,skillCount:D&&O?ie.length:void 0,searchFiles:oe,searchSkills:se,onCreateDirectory:ee?async e=>{try{await C.mutateAsync({path:e,recursive:!0,workspaceId:u})}catch(t){throw Qx.error(`Failed to create ${e}: ${YGi(t)}`),t}}:void 0,asideActions:ne&&ie.some(e=>e.path?.includes(`.agents/skills/`))?(0,G.jsx)(X,{variant:`ghost`,size:`icon-sm`,tooltip:`Update skills`,onClick:()=>void P(),loading:j.isPending,children:(0,G.jsx)(mS,{})}):void 0,addSkill:ne?{onInstall:re,installedSkillIds:ie.filter(e=>e.skillsShSource).map(e=>`${e.skillsShSource.owner}/${e.skillsShSource.repo}/${e.name}`),installedSkillNames:ie.filter(e=>!e.skillsShSource).map(e=>e.name),writableMounts:U,installedSkillPaths:Object.fromEntries(ie.filter(e=>e.path).map(e=>[e.name,e.path]))}:void 0,onDelete:V?F:void 0},u)}),T&&!f&&(0,G.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,G.jsx)(Vx,{variant:`fill`,titleSlot:`Filesystem resolved per request`,descriptionSlot:`This workspace creates its filesystem when an agent runs, so its files can't be browsed here.`})}),!E&&!T&&!f&&(0,G.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,G.jsx)(Vx,{variant:`fill`,titleSlot:`No filesystem or skills configured`,descriptionSlot:`Add a filesystem or skills to this workspace to browse its files here.`})})]})]})}function ZGi({children:e,className:t,edgeToEdge:n,mobileHeader:r,ref:i,sidebar:a,...o}){let s=n!==void 0;return(0,G.jsxs)(`div`,{ref:i,"data-slot":`app-shell`,className:c(`h-full min-h-0`,a&&`lg:grid lg:grid-cols-[auto_minmax(0,1fr)] lg:grid-rows-[1fr]`,t),...o,children:[a,(0,G.jsxs)(`div`,{"data-slot":`app-shell-content`,className:`flex h-full min-h-0 min-w-0 flex-col`,"data-sidebar-reveal-layer":`page`,children:[r,(0,G.jsx)(`div`,{"data-slot":`app-shell-body`,className:c(`flex min-h-0 flex-1 flex-col`,s&&`transition-[padding] duration-(--resize-dur) ease-(--resize-ease) motion-reduce:transition-none!`,s&&`in-data-[sidebar-gesture=active]:transition-none!`,!n&&`lg:py-2 lg:pr-2`,!n&&(a?`lg:pl-0`:`lg:pl-2`)),children:e})]})]})}function QGi({children:e,className:t,edgeToEdge:n}){let r=n!==void 0;return(0,G.jsx)(`div`,{"data-slot":`main-card`,className:c(`relative min-h-0 flex-1 overflow-hidden border-surface-rim`,r&&`transition-[border-radius,border-width,box-shadow] duration-(--resize-dur) ease-(--resize-ease) motion-reduce:transition-none!`,r&&`in-data-[sidebar-gesture=active]:transition-none!`,!n&&`lg:rounded-studio-frame lg:border lg:shadow-(--elevation-raised)`,pBe,t),children:e})}function $Gi(){return(0,G.jsxs)(`div`,{className:`h-screen bg-sidebar`,children:[(0,G.jsx)(Yx,{position:`bottom-right`}),(0,G.jsx)(M,{defaultTheme:`system`,children:(0,G.jsx)(px,{delayDuration:0,children:(0,G.jsx)(ZGi,{children:(0,G.jsx)(QGi,{className:`flex items-center justify-center overflow-y-auto`,children:(0,G.jsx)(Ov,{})})})})})]})}function eKi(){let{data:e,isLoading:t}=T_(),{isLoading:n,canAccessAgentBuilder:r}=oS();return t||n||!e||e.enabled&&!w_(e)?{isVisible:!1}:{isVisible:r}}function tKi(){let{isImpersonating:e,impersonatedRole:t,stopImpersonation:n}=iS();return!e||!t?null:(0,G.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:[(0,G.jsx)(tS,{className:`size-icon-sm shrink-0 text-info-subtle-foreground`}),(0,G.jsxs)(T,{variant:`meta`,className:`truncate text-info-subtle-foreground`,children:[`Previewing `,(0,G.jsx)(`span`,{className:`font-medium capitalize`,children:t.name}),` experience`]}),(0,G.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:(0,G.jsx)(gw,{className:`size-icon-xs`})})]})}function nKi({children:e,contentClassName:t,commandClassName:n,showOverlay:r=!0,overlayClassName:i,...a}){return(0,G.jsx)(b2n,{size:`xl`,showOverlay:r,overlayClassName:c(`bg-sidebar/40 backdrop-blur-none`,i),contentClassName:c(`command-palette-popup overflow-visible bg-transparent shadow-none`,t),commandClassName:c(`command-palette-shell gap-2 overflow-visible rounded-none bg-transparent text-muted-foreground shadow-none backdrop-blur-none`,`[&_[data-slot=command-input-wrapper]_svg]:text-muted-foreground`,`**:[[cmdk-input]]:h-full **:[[cmdk-input]]:text-body`,`**:[[cmdk-group-heading]]:px-2 **:[[cmdk-group-heading]]:pt-2 **:[[cmdk-group-heading]]:pb-1 **:[[cmdk-group]]:p-0`,`**:[[cmdk-item]]:px-2 **:[[cmdk-item]]:py-1.5`,n),...a,children:e})}function rKi({wrapperClassName:e,...t}){return(0,G.jsx)(XY,{wrapperClassName:c(`command-palette-surface command-palette-surface-input`,wx,`h-11 shrink-0 rounded-xl border-0 px-3 pr-11`,e),...t})}function iKi({children:e,className:t,...n}){return(0,G.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,G.jsx)(`div`,{className:c(`grid h-full min-h-0 grid-rows-[auto_minmax(0,1fr)] gap-2 md:grid-cols-[13rem_minmax(0,1fr)] md:grid-rows-none`,t),...n,children:e})})}function aKi({children:e,className:t,...n}){return(0,G.jsx)(`aside`,{className:c(`command-palette-surface command-palette-surface-rail flex max-h-[min(14rem,32dvh)] min-h-0 flex-col overflow-hidden rounded-xl p-2 md:h-full md:max-h-none`,Fv,t),...n,children:(0,G.jsx)(AS,{className:`-m-1 min-h-0 flex-1 p-1`,children:(0,G.jsx)(kS,{className:`pr-1`,children:(0,G.jsx)(`div`,{className:`flex flex-col gap-1`,children:e})})})})}function oKi({icon:e,label:t,count:n,active:r,onSelect:i}){return(0,G.jsxs)(`button`,{type:`button`,className:c(hS,`flex h-9 w-full cursor-pointer items-center gap-2 rounded-lg border border-transparent px-2.5 text-left text-body-sm hover:border-border hover:bg-fill-subtle data-[active=true]:border-border data-[active=true]:bg-fill-hover data-[active=true]:text-foreground`,`transition-[color,transform] duration-fast ease-out-custom active:scale-[0.99] motion-reduce:transition-none`),"data-active":r,"aria-pressed":r,onClick:i,children:[(0,G.jsx)(`span`,{className:`flex size-icon-md shrink-0 items-center justify-center [&>svg]:size-icon-md`,children:e}),(0,G.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:t}),(0,G.jsx)(T,{as:`span`,variant:`meta`,tone:`muted`,className:`rounded-md border border-border bg-muted/70 px-1.5 py-0.5 leading-none`,children:n})]})}function sKi({children:e,footer:t,...n}){return(0,G.jsxs)(`div`,{role:`region`,className:c(`command-palette-surface command-palette-surface-results command-palette-results-panel relative flex min-h-0 min-w-0 flex-col overflow-hidden rounded-xl`,Fv),...n,children:[(0,G.jsx)(ZY,{scrollArea:!0,scrollAreaClassName:`min-h-0 flex-1 rounded-none`,scrollAreaViewportClassName:`command-palette-scroll-viewport`,className:`command-palette-list max-h-none rounded-none border-none bg-transparent shadow-none`,children:e}),t]})}function Y9({icon:e,title:t,subtitle:n,path:r,badge:i,shortcut:a,className:o,...s}){return(0,G.jsxs)(eX,{className:c(`group h-auto items-start gap-3 rounded-lg border border-transparent px-3 py-2.5 data-[selected=true]:border-border`,o),...s,children:[(0,G.jsx)(`span`,{className:c(`mt-0.5 flex size-4 max-w-4 min-w-4 shrink-0 basis-4 items-center justify-center text-muted-foreground group-data-[selected=true]:text-foreground [&>svg]:!size-4 [&>svg]:shrink-0`),children:e}),(0,G.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col gap-1`,children:[(0,G.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[(0,G.jsx)(T,{as:`span`,variant:`label`,tone:`ink`,className:`truncate`,children:t}),i&&(0,G.jsx)(T,{as:`span`,variant:`meta`,tone:`muted`,className:`shrink-0 rounded-md border border-border bg-muted/60 px-1.5 py-0.5 leading-none uppercase`,children:i})]}),(n||r)&&(0,G.jsxs)(T,{as:`span`,variant:`meta`,tone:`muted`,className:`flex min-w-0 items-center gap-2`,children:[n&&(0,G.jsx)(`span`,{className:`min-w-0 truncate`,children:n}),r&&(0,G.jsx)(T,{as:`span`,variant:`meta`,tone:`muted`,font:`mono`,className:`max-w-52 truncate rounded-md border border-border bg-muted/70 px-1.5 py-0.5 leading-none`,children:r})]})]}),a&&(0,G.jsx)(S2n,{children:a})]})}function cKi({label:e}){return(0,G.jsxs)(`div`,{className:`command-palette-footer pointer-events-none absolute inset-x-0 bottom-0 z-20 flex items-end justify-between gap-3 px-3 pt-3 pb-2 text-meta text-muted-foreground`,children:[(0,G.jsx)(`span`,{className:`truncate`,children:e}),(0,G.jsxs)(`span`,{className:`flex shrink-0 items-center gap-1.5`,children:[(0,G.jsx)(Px,{size:`sm`,children:`↑`}),(0,G.jsx)(Px,{size:`sm`,children:`↓`}),(0,G.jsx)(Px,{size:`sm`,children:`↵`}),(0,G.jsx)(Px,{size:`sm`,children:`Esc`})]})]})}var X9=!1,lKi=new Set,uKi=()=>{lKi.forEach(e=>e())},dKi=e=>(lKi.add(e),()=>lKi.delete(e)),fKi=()=>X9,pKi=e=>{let t=typeof e==`function`?e(X9):e;t!==X9&&(X9=t,uKi())},mKi=({enableShortcut:e=!0}={})=>{let t=(0,W.useSyncExternalStore)(dKi,fKi,fKi),n=(0,W.useCallback)(e=>{pKi(e)},[]),r=(0,W.useCallback)(()=>{pKi(e=>!e)},[]);return(0,W.useEffect)(()=>{if(!e)return;let t=e=>{e.key===`k`&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),r())};return document.addEventListener(`keydown`,t),()=>document.removeEventListener(`keydown`,t)},[e,r]),{open:t,setOpen:n,toggle:r}};function hKi(e,t){return[e.name,e.url,t,`path route navigate`].filter(Boolean).join(` `)}function gKi(e){return!e||e===`Studio`?`Path`:e}function _Ki(e){return`/traces?entity=${encodeURIComponent(e)}`}var vKi=({scopeOptions:e,activeScope:t,onScopeChange:n})=>(0,G.jsx)(aKi,{"aria-label":`Search categories`,children:e.map(e=>(0,G.jsx)(oKi,{icon:e.icon,label:e.label,count:e.count,active:t===e.id,onSelect:()=>n(e.id)},e.id))}),yKi=({sidebar:e,activeScope:t,closeCommand:n})=>!e||t!==`all`&&t!==`settings`?null:(0,G.jsx)($Y,{heading:`Commands`,children:(0,G.jsx)(Y9,{value:`toggle sidebar collapse expand layout panel`,onSelect:()=>{e.toggleSidebar(),n()},icon:(0,G.jsx)($1r,{}),title:`Toggle sidebar`,subtitle:`Studio layout`})}),bKi=({sections:e,handleSelect:t})=>(0,G.jsx)(G.Fragment,{children:e.map(e=>(0,G.jsx)($Y,{heading:e.title,children:e.items.map(n=>{let r=n.Icon;return(0,G.jsx)(Y9,{value:hKi(n,e.title),onSelect:()=>t(n.url),icon:(0,G.jsx)(r,{}),title:n.name,subtitle:`Studio path`,path:n.url,badge:gKi(e.title)},n.url)})},e.key))}),xKi=({visible:e,entries:t,paths:n,handleSelect:r})=>!e||t.length===0?null:(0,G.jsx)($Y,{heading:`Agents`,children:t.map(([e,t])=>(0,G.jsx)(Y9,{value:`${t.name} ${e} chat agent conversation thread ${n.agentLink(e)}`,onSelect:()=>r(n.agentLink(e)),icon:(0,G.jsx)(WP,{}),title:t.name,subtitle:`Agent chat`,path:n.agentLink(e),badge:`Agent`},e))}),SKi=({visible:e,entries:t,paths:n,handleSelect:r})=>!e||t.length===0?null:(0,G.jsx)($Y,{heading:`Workflows`,children:t.map(([e,t])=>(0,G.jsx)(Y9,{value:`${t.name} ${e} graph workflow view ${n.workflowLink(e)}`,onSelect:()=>r(n.workflowLink(e)),icon:(0,G.jsx)(KS,{}),title:t.name,subtitle:`Workflow graph`,path:n.workflowLink(e),badge:`Workflow`},e))}),CKi=({visible:e,entries:t,paths:n,handleSelect:r})=>!e||t.length===0?null:(0,G.jsx)($Y,{heading:`Tools`,children:t.map(([e,t])=>(0,G.jsx)(Y9,{value:`tool ${t.id} ${e} ${n.toolLink(e)}`,onSelect:()=>r(n.toolLink(e)),icon:(0,G.jsx)(ZP,{}),title:t.id,subtitle:`Tool definition`,path:n.toolLink(e),badge:`Tool`},e))}),wKi=({visible:e,entries:t,paths:n,handleSelect:r})=>!e||t.length===0?null:(0,G.jsx)($Y,{heading:`Processors`,children:t.map(e=>{let t=e.name||e.id,i=e.isWorkflow?n.workflowLink(e.id)+`/graph`:n.processorLink(e.id);return(0,G.jsx)(Y9,{value:`processor ${t} ${e.id} ${i}`,onSelect:()=>r(i),icon:(0,G.jsx)(VR,{}),title:t,subtitle:e.isWorkflow?`Workflow processor`:`Processor`,path:i,badge:`Processor`},e.id)})}),TKi=({visible:e,entries:t,paths:n,handleSelect:r})=>!e||t.length===0?null:(0,G.jsx)($Y,{heading:`MCP Servers`,children:t.map(e=>(0,G.jsx)(Y9,{value:`mcp server ${e.name} ${e.id} ${n.mcpServerLink(e.id)}`,onSelect:()=>r(n.mcpServerLink(e.id)),icon:(0,G.jsx)(KP,{}),title:e.name,subtitle:`MCP server`,path:n.mcpServerLink(e.id),badge:`MCP`},e.id))}),EKi=({visible:e,agentEntries:t,workflowEntries:n,handleSelect:r})=>e?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)($Y,{heading:`Observability`,children:[(0,G.jsx)(Y9,{value:`observability traces telemetry signals /traces`,onSelect:()=>r(`/traces`),icon:(0,G.jsx)(tS,{}),title:`Traces`,subtitle:`Runtime traces`,path:`/traces`,badge:`Signal`}),(0,G.jsx)(Y9,{value:`metrics usage latency performance tokens /metrics`,onSelect:()=>r(`/metrics`),icon:(0,G.jsx)(G6,{}),title:`Metrics`,subtitle:`Runtime metrics`,path:`/metrics`,badge:`Signal`}),(0,G.jsx)(Y9,{value:`logs events runtime /logs`,onSelect:()=>r(`/logs`),icon:(0,G.jsx)(tS,{}),title:`Logs`,subtitle:`Runtime logs`,path:`/logs`,badge:`Signal`})]}),t.length>0&&(0,G.jsx)($Y,{heading:`Agent Traces`,children:t.map(([e,t])=>{let n=_Ki(e);return(0,G.jsx)(Y9,{value:`${t.name} ${e} traces agent observability telemetry`,onSelect:()=>r(n),icon:(0,G.jsx)(tS,{}),title:t.name,subtitle:`Agent traces`,path:n,badge:`Trace`},e)})}),n.length>0&&(0,G.jsx)($Y,{heading:`Workflow Traces`,children:n.map(([e,t])=>{let n=_Ki(t.name);return(0,G.jsx)(Y9,{value:`${t.name} ${e} traces workflow observability telemetry`,onSelect:()=>r(n),icon:(0,G.jsx)(tS,{}),title:t.name,subtitle:`Workflow traces`,path:n,badge:`Trace`},e)})})]}):null,DKi=({visible:e,entries:t,paths:n,handleSelect:r})=>!e||t.length===0?null:(0,G.jsx)($Y,{heading:`Scorers`,children:t.map(([e,t])=>{let i=t.scorer?.config?.name||t.scorer?.config?.id||e;return(0,G.jsx)(Y9,{value:`scorer score evaluation ${i} ${e} ${n.scorerLink(e)}`,onSelect:()=>r(n.scorerLink(e)),icon:(0,G.jsx)(G6,{}),title:i,subtitle:`Evaluation scorer`,path:n.scorerLink(e),badge:`Scorer`},e)})}),OKi=()=>{let{open:e,setOpen:t}=mKi(),{navigate:n,paths:r}=on(),{isMastraPlatform:i}=L8(),a=t8(),[o,s]=W.useState(`all`),{data:c={}}=hN(),{data:l={}}=WM(),{data:u={}}=cX(),{data:d={}}=nP(),{data:f=[]}=TR(),{data:p={}}=ER(),{isCmsAvailable:m,isLoading:h}=f8(),{hasPermission:g,hasAnyPermission:_,isLoading:v}=aS(),y=e=>{t(e),e||s(`all`)},b=()=>y(!1),x=e=>{n(e),b()},S=W.useCallback(e=>{if(e.hidden||e.url===`/prompts`&&!m&&!h||i&&!e.isOnMastraPlatform)return!1;let t=lS(e.url);return v&&t&&t!==`public`?!1:uS(t,g,_)},[_,g,m,h,i,v]),C=Object.entries(c),w=Object.entries(l),T=Object.entries(u),E=Object.values(d).filter(e=>e.phases&&e.phases.length>0),D=Object.entries(p),O=W.useMemo(()=>{let e=[];for(let t of ann){let n=t.items.filter(S);n.length>0&&e.push({key:t.key,title:t.title,items:n})}let t=[...onn.filter(S),...i?[]:[{name:`Templates`,url:`/templates`,Icon:k6,isOnMastraPlatform:!1}]];return t.length===0?e:[...e,{key:`studio`,title:`Studio`,items:t}]},[S,i]),k=O.reduce((e,t)=>e+t.items.length,0),A=T.length+E.length+f.length,j=D.length,M=C.length+w.length+3,N=O.find(e=>e.key===`studio`)?.items.length??0,P=k+C.length+w.length+A+j+M,F=[{id:`all`,label:`All`,icon:(0,G.jsx)(ZM,{}),count:P},{id:`paths`,label:`Paths`,icon:(0,G.jsx)(nBt,{}),count:k},{id:`agents`,label:`Agents`,icon:(0,G.jsx)(WP,{}),count:C.length},{id:`workflows`,label:`Workflows`,icon:(0,G.jsx)(KS,{}),count:w.length},{id:`tooling`,label:`Tooling`,icon:(0,G.jsx)(B_i,{}),count:A},{id:`evaluation`,label:`Evaluation`,icon:(0,G.jsx)(G6,{}),count:j},{id:`observability`,label:`Intelligence`,icon:(0,G.jsx)(tS,{}),count:M},{id:`settings`,label:`Studio`,icon:(0,G.jsx)(fX,{}),count:N}],I=o===`all`||o===`paths`,L=o===`all`||o===`agents`,R=o===`all`||o===`workflows`,z=o===`all`||o===`tooling`,B=o===`all`||o===`evaluation`,ee=o===`all`||o===`observability`,V=o===`settings`,te=W.useMemo(()=>{let e=[];for(let t of O)V?t.key===`studio`&&e.push(t):(o===`evaluation`&&t.key===`evaluation`||o===`observability`&&t.key===`observability`||I&&(o===`all`||t.key!==`studio`))&&e.push(t);return e},[o,O,I,V]);return(0,G.jsxs)(nKi,{open:e,onOpenChange:y,title:`Mastra Studio Search`,description:`Search Studio routes and runtime entities`,children:[(0,G.jsx)(rKi,{placeholder:`Search Studio, agents, workflows, tools, paths`}),(0,G.jsxs)(iKi,{children:[(0,G.jsx)(vKi,{scopeOptions:F,activeScope:o,onScopeChange:s}),(0,G.jsxs)(sKi,{"aria-label":`Search results`,footer:(0,G.jsx)(cKi,{label:`Studio search`}),children:[(0,G.jsx)(QY,{children:`No matching results.`}),(0,G.jsx)(yKi,{sidebar:a,activeScope:o,closeCommand:b}),(0,G.jsx)(bKi,{sections:te,handleSelect:x}),(0,G.jsx)(xKi,{visible:L,entries:C,paths:r,handleSelect:x}),(0,G.jsx)(SKi,{visible:R,entries:w,paths:r,handleSelect:x}),(0,G.jsx)(CKi,{visible:z,entries:T,paths:r,handleSelect:x}),(0,G.jsx)(wKi,{visible:z,entries:E,paths:r,handleSelect:x}),(0,G.jsx)(TKi,{visible:z,entries:f,paths:r,handleSelect:x}),(0,G.jsx)(EKi,{visible:ee,agentEntries:C,workflowEntries:w,handleSelect:x}),(0,G.jsx)(DKi,{visible:B,entries:D,paths:r,handleSelect:x})]})]})]})};function kKi(e,t,n=[]){let r=e=>t===e||t.startsWith(e+`/`);return n.some(t=>t!==e&&t.url.startsWith(e.url+`/`)&&r(t.url))?!1:r(e.url)?!0:e.activePaths?.some(r)??!1}function AKi(e){let{Icon:t}=e;return{name:e.name,url:e.url,icon:(0,G.jsx)(t,{})}}function jKi(){let{state:e,isMobile:t,setOpenMobile:n}=n8(),{setOpen:r}=mKi({enableShortcut:!1}),i=JFt(`K`),a=Sv().pathname,{isMastraPlatform:o}=L8(),{data:s}=T_(),{isCmsAvailable:c,isLoading:l}=f8(),{hasPermission:u,hasAnyPermission:d,isLoading:f}=aS(),{data:p}=thr(),m=p!==void 0&&p.status!==`not-mounted`,h=s&&w_(s),g=new Set([`/prompts`]),{isVisible:_}=eKi(),v=a===`/agent-builder`||a.startsWith(`/agent-builder/`),y=()=>{t&&n(!1),r(!0)},b=e=>{if(e.hidden||e.url===`/connections`&&!m||g.has(e.url)&&!c&&!l||o&&!e.isOnMastraPlatform)return!1;if(f){let t=lS(e.url);if(t&&t!==`public`)return!1}return!!uS(lS(e.url),u,d)},{data:x}=TR(),{data:S}=y6n(),C=onn.filter(b),w=ann.map(e=>{let t=e.items.filter(b),n=e=>({...AKi(e),isActive:kKi(e,a,t)});return{key:e.key,title:e.title,href:e.href,isHeaderActive:!(!e.href||a!==e.href||t.some(e=>kKi(e,a,t))),links:t.filter(e=>!e.foldable).map(n),moreLinks:t.filter(e=>e.foldable).map(e=>({...n(e),defaultVisible:e.url===`/mcps`&&!!x?.length||e.url===`/workspaces`&&!!S?.workspaces.length}))}});return(0,G.jsxs)(i8,{"aria-label":`Sidebar`,children:[(0,G.jsxs)(i8.Header,{collapsedLogo:(0,G.jsx)(I6,{className:`size-6`}),actions:h&&(0,G.jsx)(xQr,{}),children:[(0,G.jsx)(i8.Brand,{logo:(0,G.jsx)(I6,{className:`size-6`}),title:`Mastra Studio`}),!t&&(0,G.jsx)(i8.SearchTrigger,{"aria-label":`Search and navigate`,shortcut:i,onClick:y}),(0,G.jsx)(i8.Trigger,{})]}),_&&(0,G.jsx)(i8.NavList,{className:`mb-1`,children:(0,G.jsx)(i8.NavLink,{state:e,link:{name:`Agent Builder`,url:`/agent-builder`,icon:(0,G.jsx)(WS,{})},isActive:v})}),(0,G.jsx)(tKi,{}),(0,G.jsx)(i8.Nav,{children:(0,G.jsx)(i8.Sections,{sections:w,visibilityStorageKey:`mastra:studio:sidebar-visibility`})}),(0,G.jsx)(i8.Footer,{children:(0,G.jsxs)(i8.NavList,{children:[C.map(t=>(0,G.jsx)(i8.NavLink,{state:e,link:AKi(t),isActive:kKi(t,a)},t.name)),(0,G.jsx)(Y4r,{state:e})]})})]})}var MKi=()=>{let{baseUrl:e,headers:t,apiPrefix:n,setConfig:r}=fS(),[i,a]=(0,W.useState)(()=>Object.entries(t).map(([e,t])=>({name:e,value:t})));return(0,G.jsx)(px,{delayDuration:0,children:(0,G.jsxs)(NN,{onSubmit:t=>{t.preventDefault();let a=new FormData(t.currentTarget),o={};for(let e=0;e<i.length;e++){let t=a.get(`headers.${e}.name`),n=a.get(`headers.${e}.value`);typeof t==`string`&&typeof n==`string`&&(o[t]=n)}r({headers:o,baseUrl:e,apiPrefix:n}),Qx.success(`Headers saved`)},className:`w-full max-w-md gap-6 text-left`,children:[(0,G.jsx)(J1r,{headers:i,onAddHeader:e=>{a(t=>[...t,e])},onRemoveHeader:e=>{a(t=>t.filter((t,n)=>n!==e))}}),(0,G.jsx)(X,{icon:(0,G.jsx)(W6,{}),type:`submit`,className:`ml-auto`,children:`Save headers`})]})})};function NKi({children:e,loginUrl:t=`/login`,signupUrl:n=`/signup`}){let{data:r,isLoading:i}=T_();if(i||!r?.enabled||w_(r))return(0,G.jsx)(G.Fragment,{children:e});let a=typeof window<`u`?window.location.href:void 0;return r.login?(0,G.jsx)(`div`,{className:`flex h-full w-full items-center justify-center`,children:(0,G.jsxs)(`div`,{className:`flex flex-col items-center space-y-6 text-center`,children:[(0,G.jsx)(I6,{className:`h-16 w-16 opacity-50`}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(T,{as:`h2`,variant:`heading`,tone:`ink`,children:`Sign in to continue`}),(0,G.jsx)(`p`,{className:`max-w-sm text-muted-foreground`,children:`You need to sign in to access this page.`})]}),r.login.description&&(0,G.jsxs)(`div`,{className:`flex items-start gap-2.5 rounded-md bg-nested p-3 text-left`,children:[(0,G.jsx)(zN,{className:`mt-0.5 size-icon-md shrink-0 text-muted-foreground`}),(0,G.jsx)(T,{tone:`muted`,className:`max-w-sm`,children:r.login.description})]}),(0,G.jsx)(_Qr,{config:r.login,redirectUri:a,loginUrl:t}),(r.login.type===`credentials`||r.login.type===`both`)&&r.login.signUpEnabled!==!1&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(T,{as:`span`,variant:`body`,tone:`muted`,children:`Don't have an account? `}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>{let e=new URL(gQr(n),window.location.origin);a&&e.searchParams.set(`redirect`,a),window.location.href=e.toString()},className:`text-foreground hover:underline`,children:(0,G.jsx)(T,{as:`span`,variant:`body`,className:`block`,children:`Sign up`})})]})]})}):(0,G.jsx)(`div`,{className:`flex h-full w-full items-center justify-center`,children:(0,G.jsxs)(`div`,{className:`flex flex-col items-center space-y-6 text-center`,children:[(0,G.jsx)(I6,{className:`h-16 w-16 opacity-50`}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(T,{as:`h2`,variant:`heading`,tone:`ink`,children:`Authentication Required`}),(0,G.jsx)(`p`,{className:`max-w-sm text-muted-foreground`,children:`Add the authorization header that Studio needs to reach your Mastra server.`})]}),(0,G.jsx)(MKi,{})]})})}var PKi=`experimental-ui:`,FKi=`current`,IKi=W.createContext(null);function LKi(e,t){let n=window.localStorage.getItem(PKi+e);return n&&t.has(n)?n:FKi}function RKi({experiments:e,children:t}){let n=W.useMemo(()=>new Map(e.map(e=>[e.key,new Set(e.variants.map(e=>e.value))])),[e]),[r,i]=W.useState({});W.useLayoutEffect(()=>{let t={};for(let r of e){let e=n.get(r.key);t[r.key]=LKi(r.key,e)}i(t)},[e,n]);let a=W.useCallback(e=>r[e]??FKi,[r]),o=W.useCallback((e,t)=>{window.localStorage.setItem(PKi+e,t),i(n=>({...n,[e]:t}))},[]),s=W.useMemo(()=>({experiments:e,getVariant:a,setVariant:o}),[e,a,o]);return(0,G.jsx)(IKi.Provider,{value:s,children:t})}var zKi=[{key:`entity-list-page`,name:`Entity List page UI`,path:[`/agents`,`/prompts`,`/tools`,`/datasets`,`/scorers`,`/mcps`,`/workflows`,`/processors`],variants:[{value:`current`,label:`Current state`},{value:`new-proposal`,label:`New proposal`}]}],BKi=()=>({experimentalUIEnabled:typeof window<`u`&&window.MASTRA_EXPERIMENTAL_UI===`true`}),VKi=()=>{let{toggleSidebar:e}=n8();return Ix({"[":e},{repeat:!1}),null};function HKi(){let{setOpenMobile:e}=n8(),{setOpen:t}=mKi({enableShortcut:!1});return(0,G.jsxs)(`header`,{className:`sticky top-0 z-20 flex h-12 shrink-0 items-center justify-between gap-3 border-b border-border bg-sidebar px-3 lg:hidden`,children:[(0,G.jsxs)(`div`,{className:`flex min-w-0 items-center gap-3`,children:[(0,G.jsx)(i8.MobileTrigger,{}),(0,G.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[(0,G.jsx)(I6,{className:`size-[1.5rem] shrink-0`}),(0,G.jsx)(T,{variant:`body-sm`,font:`display`,as:`span`,className:`whitespace-nowrap`,children:`Mastra Studio`})]})]}),(0,G.jsx)(X,{type:`button`,variant:`ghost`,size:`icon-md`,tooltip:`Search`,"aria-label":`Search and navigate`,onClick:()=>{e(!1),t(!0)},className:`shrink-0`,children:(0,G.jsx)(ZM,{})})]})}var UKi={"studio-frame":100,"route-side-panel":0},WKi={overflow:`visible`};function GKi({children:e,className:t}){let n=Kw(),{hasPanel:r,panelHandle:i,onPanelResize:a}=I8(),{defaultLayout:o,onLayoutChange:s}=FWr({id:`studio-frame-layout-v1`,storage:localStorage});return(0,G.jsx)(`div`,{className:`relative flex min-h-0 flex-1`,children:(0,G.jsxs)($3,{className:`min-h-0 flex-1`,style:WKi,orientation:`horizontal`,defaultLayout:o??UKi,onLayoutChange:s,children:[(0,G.jsx)(X3,{id:`studio-frame`,className:c(`min-w-0`,t),style:WKi,children:e}),r&&!n&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(e6,{className:`w-2`}),(0,G.jsx)(Z3,{id:`route-side-panel`,ref:i,direction:`right`,collapsible:!0,collapsedSize:0,hideExpandButton:!0,minSize:370,maxSize:`50%`,defaultSize:560,className:`min-w-0`,onResize:e=>a(e.inPixels),children:(0,G.jsx)(tti,{className:`h-full min-h-0`})})]})]})})}function KKi({children:e}){let{data:t,isFetched:n}=T_(),{pathname:r}=Sv(),i=!(n&&t?.enabled&&!w_(t));return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(OKi,{}),(0,G.jsx)(ZGi,{sidebar:i?(0,G.jsx)(jKi,{}):void 0,mobileHeader:i?(0,G.jsx)(HKi,{}):void 0,children:(0,G.jsx)(GKi,{className:`flex min-h-0 flex-1 flex-col`,children:(0,G.jsx)(QGi,{children:(0,G.jsx)(NKi,{children:(0,G.jsx)(LJe,{resetKeys:[r],children:e})})})})})]})}var qKi=({children:e})=>{let{experimentalUIEnabled:t}=BKi(),{Link:n}=on();return(0,G.jsxs)(`div`,{className:`h-screen bg-sidebar`,children:[(0,G.jsx)(Yx,{position:`bottom-right`}),(0,G.jsx)(M,{defaultTheme:`system`,children:(0,G.jsx)(px,{delayDuration:0,children:(0,G.jsx)(RKi,{experiments:t?zKi:[],children:(0,G.jsxs)(i8.Provider,{LinkComponent:n,children:[(0,G.jsx)(VKi,{}),(0,G.jsx)(eti,{children:(0,G.jsx)(KKi,{children:e})})]})})})})]})},JKi=({children:e})=>(0,G.jsxs)(`div`,{className:`h-screen bg-sidebar`,children:[(0,G.jsx)(Yx,{position:`bottom-right`}),(0,G.jsx)(M,{defaultTheme:`system`,children:(0,G.jsx)(px,{delayDuration:0,children:(0,G.jsx)(`div`,{className:`h-full overflow-y-auto`,children:(0,G.jsx)(NKi,{children:e})})})})]}),YKi={name:`Agents`,url:`/agent-builder/agents`,icon:(0,G.jsx)(WP,{})},XKi={name:`Skills`,url:`/agent-builder/skills`,icon:(0,G.jsx)(Dmr,{className:`size-icon-lg`})},ZKi={name:`Favorites`,url:`/agent-builder/favorite`,icon:(0,G.jsx)(sY,{className:`size-icon-lg`})},QKi={name:`Library`,url:`/agent-builder/library`,icon:(0,G.jsx)(OR,{className:`size-icon-lg`})},$Ki={name:`Infra`,url:`/agent-builder/infrastructure`,icon:(0,G.jsx)(bni,{className:`size-icon-lg`})};function eqi(){let{Link:e}=on(),{pathname:t}=Sv(),n=cY(),{canManageSkills:r,canUseFavorites:i}=oS(),{hasPermission:a}=aS(),o=a(`infrastructure:read`),s=(0,W.useMemo)(()=>{let e=[YKi];return n.skills&&r&&e.push(XKi),i&&e.push(ZKi),e.push(QKi),o&&e.push($Ki),e},[n.skills,r,i,o]);return(0,G.jsx)(`nav`,{"aria-label":`Primary`,className:`fixed inset-x-0 bottom-0 z-40 border-t border-border bg-sidebar/95 pb-[env(safe-area-inset-bottom)] backdrop-blur-sm md:hidden`,children:(0,G.jsx)(`ul`,{className:`grid`,style:{gridTemplateColumns:`repeat(${s.length}, minmax(0, 1fr))`},children:s.map(n=>{let r=t.startsWith(n.url);return(0,G.jsx)(`li`,{children:(0,G.jsxs)(e,{href:n.url,"aria-current":r?`page`:void 0,className:c(r?`text-foreground`:`text-muted-foreground`,`relative flex flex-col items-center justify-center gap-1 py-2`,A,r?`before:absolute before:inset-x-0 before:-top-px before:h-0.5 before:bg-current`:`hover:text-foreground`),children:[(0,G.jsx)(`span`,{className:`flex size-6 items-center justify-center`,"aria-hidden":`true`,children:(0,G.jsx)(T,{as:`span`,variant:`caption`,className:`block`,children:n.icon})}),(0,G.jsx)(T,{as:`span`,variant:`caption`,children:n.name})]})},n.name)})})})}var tqi={name:`My agents`,url:`/agent-builder/agents`,icon:(0,G.jsx)(WP,{})},nqi={name:`Favorites`,url:`/agent-builder/favorite`,icon:(0,G.jsx)(sY,{})},rqi={name:`Library`,url:`/agent-builder/library`,icon:(0,G.jsx)(OR,{})},iqi={name:`Skills`,url:`/agent-builder/skills`,icon:(0,G.jsx)(Dmr,{className:`size-icon-md`})},aqi={name:`Infrastructure`,url:`/agent-builder/infrastructure`,icon:(0,G.jsx)(bni,{className:`size-icon-md`})};function oqi({forceExpanded:e=!1}={}){let{Link:t}=on(),{state:n,isMobile:r}=n8(),{pathname:i}=Sv(),a=cY(),{canManageSkills:o,canUseFavorites:s}=oS(),{hasPermission:c}=aS(),l=c(`infrastructure:read`),u=e?`default`:n,{data:d}=T_(),f=d&&w_(d),p=[tqi];a.skills&&o&&p.push(iqi),s&&p.push(nqi),p.push(rqi);let m=(0,G.jsx)(t,{href:`/agents`,"aria-label":`Back to Mastra Studio`,children:(0,G.jsx)(I6,{className:`size-6`})});return(0,G.jsxs)(i8,{className:`h-full`,mobileMode:`drawer`,children:[!e&&(0,G.jsxs)(i8.Header,{collapsedLogo:m,actions:f&&(0,G.jsx)(xQr,{}),children:[(0,G.jsx)(t,{href:`/agents`,"aria-label":`Back to Mastra Studio`,className:`min-w-0 flex-1`,children:(0,G.jsx)(i8.Brand,{logo:(0,G.jsx)(I6,{className:`size-6`}),title:`Mastra Studio`})}),!r&&(0,G.jsx)(i8.Trigger,{})]}),(0,G.jsx)(tKi,{}),(0,G.jsx)(i8.Nav,{children:(0,G.jsx)(i8.NavSection,{children:(0,G.jsx)(i8.NavList,{children:p.map(e=>{let n=i.startsWith(e.url);return(0,G.jsx)(i8.NavLink,{LinkComponent:t,state:u,link:e,isActive:n},e.name)})})})}),!e&&(0,G.jsx)(i8.Footer,{children:l&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(i8.NavSeparator,{}),(0,G.jsx)(i8.NavSection,{children:(0,G.jsx)(i8.NavList,{children:(0,G.jsx)(i8.NavLink,{LinkComponent:t,state:u,link:aqi,isActive:i.startsWith(aqi.url)})})})]})})]})}var Z9=()=>(0,G.jsx)(`div`,{className:`h-screen bg-sidebar`,children:(0,G.jsxs)(l2r,{children:[(0,G.jsxs)(`div`,{className:`grid h-full grid-rows-1 md:grid-cols-[auto_1fr] md:divide-x md:divide-border`,children:[(0,G.jsx)(`div`,{className:`hidden md:block`,children:(0,G.jsx)(oqi,{})}),(0,G.jsx)(`div`,{className:`flex h-full min-h-0 flex-col`,children:(0,G.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto bg-transparent pb-[calc(3.5rem+env(safe-area-inset-bottom))] md:pb-0`,children:(0,G.jsx)(Ov,{})})})]}),(0,G.jsx)(eqi,{})]})}),sqi=()=>(0,G.jsx)(`div`,{className:`grid h-screen grid-cols-[minmax(0,1fr)] grid-rows-1 bg-sidebar`,children:(0,G.jsx)(Ov,{})}),cqi=()=>{let{toggle:e}=I8();return Ix({"]":e}),null};function lqi(e){if(e)try{return JO(e)}catch{return}}function uqi(e){let t=lqi(e.inputSchema);return{inputSchema:t,outputSchema:lqi(e.outputSchema),requestContextSchema:lqi(e.requestContextSchema),zodInputSchema:y9(t)}}function dqi(e,t){let{data:n={},isLoading:r,isError:i}=hN(),a=Object.entries(n).filter(([,t])=>Object.values(t.tools??{}).some(t=>t.id===e)).map(([e,t])=>({id:e,name:t.name||e}));return{agents:[...a.filter(e=>e.id===t),...a.filter(e=>e.id!==t)],isLoading:r,isError:i}}function fqi({agent:e,isCurrent:t}){let{Link:n,paths:r}=on(),i=(0,G.jsx)(Z.NameCell,{children:(0,G.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[(0,G.jsx)(vx,{size:`sm`,className:`shrink-0 text-muted-foreground`,children:(0,G.jsx)(WP,{})}),e.name]})});return t?(0,G.jsxs)(Z.RowStatic,{children:[i,(0,G.jsx)(Z.Cell,{children:(0,G.jsx)(YS,{variant:`neutral`,emphasis:`subtle`,children:`Current`})})]}):(0,G.jsxs)(Z.RowLink,{to:r.agentLink(e.id),LinkComponent:n,children:[i,(0,G.jsx)(`span`,{})]})}function pqi({isLoading:e,isError:t,isEmpty:n}){if(e)return`Loading agents…`;if(t)return`Couldn't load the agents that use this tool.`;if(n)return`No agents use this tool yet.`}function mqi({toolId:e,currentAgentId:t}){let{agents:n,isLoading:r,isError:i}=dqi(e,t),a=pqi({isLoading:r,isError:i,isEmpty:n.length===0});return a?(0,G.jsx)(VN,{children:(0,G.jsx)(DPi,{message:a})}):(0,G.jsx)(Z,{columns:`minmax(0,1fr) auto`,fit:`container`,children:n.map(e=>(0,G.jsx)(fqi,{agent:e,isCurrent:e.id===t},e.id))})}function hqi(e){return(0,G.jsxs)(HN,{children:[(0,G.jsx)(CPi,{children:(0,G.jsx)(UN,{children:`Used by`})}),(0,G.jsx)(mqi,{...e})]})}function gqi({tool:e,execution:t,currentAgentId:n,requestContextEntityType:r,requestContextEntityId:i}){let{canExecute:a}=aS(),{inputSchema:o,outputSchema:s,requestContextSchema:c,zodInputSchema:l}=uqi(e);return(0,G.jsx)(SPi,{description:e.description,overview:(0,G.jsx)(yFi,{inputSchema:o,outputSchema:s,requestContextSchema:c,footer:(0,G.jsx)(hqi,{toolId:e.id,currentAgentId:n})}),canRun:a(`tools`),playground:(0,G.jsx)(mFi,{zodInputSchema:l,execution:t,requestContextEntityType:r,requestContextEntityId:i})})}function _qi({agentId:e}){let t=vFi(),[n]=LS(`agent`,e),{data:r,isLoading:i}=mN({agentId:e,requestContext:n}),{mutateAsync:a,status:o,data:s,error:c}=xjt(),l=Object.values(r?.tools??{}).find(e=>e.id===t),u={execute:(n,r)=>a({agentId:e,toolId:t,input:n,playgroundRequestContext:r}),status:o,output:s,error:c};return i?(0,G.jsx)(MN.LoadingData,{}):l?(0,G.jsx)(gqi,{tool:l,execution:u,currentAgentId:e,requestContextEntityType:`agent-tool`,requestContextEntityId:`${e}:${l.id}`}):(0,G.jsxs)(MN.NoData,{children:[`This agent has no tool "`,t,`".`]})}var vqi=({agentId:e})=>{let t=Cv();return Ix({"g$+t":()=>t(`/agents/${e}/traces`)}),null},yqi=i5.threadId;function bqi(e,t,n){if(e===`chat`){let e=F_(`/agents/:agentId/threads/:threadId`,t)?.params.threadId;return e===`new`?void 0:e}if(e===`traces`){let e=new URLSearchParams(n),t=e.get(o5(yqi));return t&&t!==`is`?void 0:e.get(yqi)||void 0}}function xqi({children:e}){return(0,G.jsx)(F8,{owner:`agent-detail`,children:e})}var Sqi=({children:e})=>{let{agentId:t}=wv(),n=Sv(),{isCmsAvailable:r}=f8(),{hasObservability:i}=KAt(),{canCreateAgent:a}=HZn(),{paths:o}=on(),s=I8(),c=jt.has(`datasets`),l=r&&c,u=i&&c,{data:d}=mN({agentId:t,requestContext:LS(`agent`,t)[0],queryOptions:{enabled:!!t}}),f=lY(d?.provider??``),p=d?.modelId??``,m=n.pathname.includes(`/threads`)?`chat`:n.pathname.includes(`/editor`)?`versions`:n.pathname.includes(`/traces`)?`traces`:`none`,h=bqi(m,n.pathname,n.search),g=h?`/agents/${t}/traces?${new URLSearchParams({[yqi]:h})}`:`/agents/${t}/traces`,{handleCopy:_,isCopied:v}=uC({text:`${window.location.origin}${gQr(`/agents/${encodeURIComponent(t)}/session`)}`,copyMessage:`Session URL copied to clipboard!`}),y=o.cmsAgentEditLink(t);return(0,G.jsx)(FQr,{defaultProvider:f,defaultModel:p,children:(0,G.jsxs)(en,{children:[(0,G.jsx)(vqi,{agentId:t}),(0,G.jsx)(cqi,{}),(0,G.jsx)(KFi,{children:(0,G.jsx)(_qi,{agentId:t})}),(0,G.jsx)(I6n,{agent:{id:t,name:d?.name||t},overviewHref:`/agents`,switcher:(0,G.jsx)(wjt,{}),actions:{editHref:a&&d?.source===`stored`?y:void 0,onShare:_,isShareCopied:v},tabs:{activeTab:m,chatHref:`/agents/${t}/threads/${h??`new`}`,tracesHref:g,versionsHref:`/agents/${t}/editor`,showPlayground:l,showObservability:u},config:m===`versions`?void 0:{shortcut:`]`,dock:{open:!s.isCollapsed,toggle:s.toggle,Mount:xqi},children:()=>(0,G.jsx)(FQ,{children:(0,G.jsx)(ati,{agentId:t})},t)},children:e})]})},`${t}:${f}/${p}`)};function Cqi(e,t){let n=e.page,r=new Map([...e.ancestors,n].map(e=>[e.id,e]));return{name:n.name,kind:n.isScope?n.displayLabel??`Scope`:`Page`,pageRef:PDi(n,r),childCount:t?.pages.length?`${t.pages.length}${t.nextCursor?`+`:``}`:void 0}}function wqi(e,t){let n=e.split(`#`)[0]?.split(`:`)[0];return!!(n&&e.includes(`:`)&&t?.pages.some(e=>e.isScope&&e.address?.split(`:`)[0]===n))}function Tqi(e){let t=Y(),n=Iji().data?.[0]?.key,r=e.pageId??e.pageRef,i=b_({queryKey:[`knowledge`,n,`tree`,null,null],queryFn:n?async()=>t.getKnowledge(n).tree({}):p_,staleTime:3e4}),a=e.pageId!==void 0||e.pageRef!==void 0&&wqi(e.pageRef,i.data),{data:o}=b_({queryKey:[`knowledge`,n,`page`,r,null],queryFn:n&&r&&a?async()=>t.getKnowledge(n).page(r):p_,retry:!1,staleTime:3e4}),s=o?.page.id,c=b_({queryKey:[`knowledge`,n,`tree`,s??null,null],queryFn:n&&s?async()=>t.getKnowledge(n).tree({parentId:s}):p_,staleTime:3e4});return o?Cqi(o,c.data):void 0}function Eqi({children:e}){return(0,G.jsx)(iir,{pageHref:XZ,refHref:XZ,usePagePreview:Tqi,children:e})}var Dqi=()=>{let e=Cv();return Ix({"g$+a":()=>e(`/agents`),"g$+p":()=>e(`/prompts`),"g$+w":()=>e(`/workflows`),"g$+c":()=>e(`/processors`),"g$+m":()=>e(`/mcps`),"g$+o":()=>e(`/tools`),"g$+k":()=>e(`/workspaces`),"g$+s":()=>e(`/scorers`),"g$+d":()=>e(`/datasets`),"g$+x":()=>e(`/experiments`),"g$+q":()=>e(`/experiments/review-queue`),"g$+n":()=>e(`/metrics`),"g$+t":()=>e(`/traces`),"g$+l":()=>e(`/logs`),"g$+,":()=>e(`/settings`),"g$+h":()=>e(`/resources`)}),null},Oqi=AR(`/traces`);function kqi(e){return e.startsWith(`/spans`)?`spans`:e.startsWith(`/threads`)?`threads`:`traces`}function Aqi({children:e}){let{pathname:t}=Sv(),n=Cv(),r=kqi(t),i=hHi({current:r,features:A7});return(0,G.jsx)(pHi,{current:r,views:i,onViewChange:e=>n(`/${e}`),breadcrumbs:e=>{let t=DHi(e);return(0,G.jsx)(lN,{crumbs:t?[Oqi,{id:e.current,label:t}]:[Oqi]})},children:e})}var jqi=()=>(0,G.jsx)(Vx,{titleSlot:`No Processors yet`,descriptionSlot:`Configure processors. Add input or output processors to your agents to transform messages.`,actionSlot:(0,G.jsx)(X,{variant:`ghost`,render:(0,G.jsx)(`a`,{href:`https://mastra.ai/docs/agents/processors`,target:`_blank`,rel:`noopener noreferrer`}),icon:(0,G.jsx)(nF,{}),children:`Processors documentation`}),variant:`fill`}),Mqi=[`input`,`inputStep`,`outputStep`,`outputStream`,`outputResult`],Nqi={name:e=>e.name||e.id,agents:e=>e.agentIds?.length??0};function Pqi({processors:e,isLoading:t,search:n=``,sort:r,onSortChange:i}){let{paths:a,Link:o}=on(),s=(0,W.useMemo)(()=>Object.values(e??{}).filter(e=>e.phases&&e.phases.length>0),[e]),c=(0,W.useMemo)(()=>{let e=n.toLowerCase();return P6(s.filter(t=>t.id.toLowerCase().includes(e)||(t.name||``).toLowerCase().includes(e)),r,Nqi)},[s,n,r]),{containerRef:l,getRowProps:u}=UP({count:c.length,global:!0});if(t)return(0,G.jsx)(QP,{columns:`auto 1fr auto auto auto auto auto auto`});let d=e=>r?.key===e?r.direction:void 0;return(0,G.jsxs)(Z,{columns:`auto 1fr auto auto auto auto auto auto`,scrollRef:l,children:[(0,G.jsxs)(Z.Top,{children:[i?(0,G.jsx)(Z.SortableTopCell,{sortKey:`name`,sort:d(`name`),onSortChange:i,children:`Name`}):(0,G.jsx)(Z.TopCell,{children:`Name`}),(0,G.jsx)(Z.TopCell,{children:`Description`}),(0,G.jsx)(Z.TopCellSmart,{long:`Input`,short:`Input`,tooltip:`Contains input phase`,className:`text-center`}),(0,G.jsx)(Z.TopCellSmart,{long:`Input Step`,short:(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(EI,{}),` Step`]}),tooltip:`Contains input step phase`,className:`text-center`}),(0,G.jsx)(Z.TopCellSmart,{long:`Output Step`,short:(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(DI,{}),` Step`]}),tooltip:`Contains output step phase`,className:`text-center`}),(0,G.jsx)(Z.TopCellSmart,{long:`Output Stream`,short:(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(DI,{}),` Stream`]}),tooltip:`Contains output stream phase`,className:`text-center`}),(0,G.jsx)(Z.TopCellSmart,{long:`Output Result`,short:(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(DI,{}),` Result`]}),tooltip:`Contains output result phase`,className:`text-center`}),i?(0,G.jsx)(Z.SortableTopCell,{sortKey:`agents`,sort:d(`agents`),onSortChange:i,align:`end`,children:`Used by`}):(0,G.jsx)(Z.TopCellSmart,{short:`Used by`,long:`Used by Agents`,className:`text-center`})]}),c.length===0&&n?(0,G.jsx)(Z.NoMatch,{message:`No Processors match your search`}):null,c.map((e,t)=>{let n=vN(e.name||e.id,50),r=vN(e.description??``,200),i=e.agentIds?.length??0,s=new Set(e.phases||[]),c=e.isWorkflow?a.workflowLink(e.id)+`/graph`:a.processorLink(e.id);return(0,G.jsxs)(Z.RowLink,{to:c,LinkComponent:o,...u(t),children:[(0,G.jsx)(Z.NameCell,{children:n}),(0,G.jsx)(Z.DescriptionCell,{children:r}),Mqi.map(e=>(0,G.jsx)(Z.TextCell,{className:`text-center`,children:s.has(e)&&(0,G.jsx)(cC,{className:`mx-auto size-icon-md`})},e)),(0,G.jsx)(Z.TextCell,{className:`text-center`,children:i||``})]},e.id)})]})}var Q9=[AR(`/processors`)];function Fqi(){let{data:e={},isLoading:t,error:n}=nP(),[r,i]=(0,W.useState)(``),[a,o]=(0,W.useState)();return n&&JN(n)?(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:Q9}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`Processors`}),(0,G.jsx)(vR,{variant:`fill`})]}):n&&YN(n)?(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:Q9}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`Processors`}),(0,G.jsx)(_R,{variant:`fill`,resource:`processors`})]}):n?(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:Q9}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`Processors`}),(0,G.jsx)(Vx,{tone:`error`,variant:`fill`,titleSlot:`Failed to load processors`,descriptionSlot:n.message})]}):Object.keys(e).length===0&&!t?(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:Q9}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`Processors`}),(0,G.jsx)(jqi,{})]}):(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:Q9}),actionRow:(0,G.jsx)(EP,{children:(0,G.jsx)(EP.Start,{children:(0,G.jsx)(`div`,{className:`max-w-120 flex-1`,children:(0,G.jsx)(CN,{...wN,onValueChange:i,label:`Search processors`,placeholder:`Search by name`})})})}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`Processors`}),(0,G.jsx)(Pqi,{processors:e,isLoading:t,search:r,sort:a,onSortChange:(e,t)=>o({key:t,direction:e})})]})}var Iqi={input:`Input - Process input messages before LLM (once at start)`,inputStep:`Input Step - Process at each agentic loop step`,outputStream:`Output Stream - Process streaming chunks`,outputResult:`Output Result - Process complete output after streaming`,outputStep:`Output Step - Process after each LLM response (before tools)`,toolResult:`Tool Result - Process tool output before it is added to the message list`,llmRequest:`LLM Request - Transform the provider prompt before each LLM call`};function Lqi({processorId:e}){let{data:t,isLoading:n,error:r}=DFt({processorId:e,queryOptions:{enabled:!!e}});return(0,W.useEffect)(()=>{if(r){let e=r instanceof Error?r.message:`Failed to load processor`;Qx.error(`Error loading processor: ${e}`)}},[r]),n?(0,G.jsxs)(`div`,{className:`p-4`,children:[(0,G.jsx)(PS,{className:`mb-4 h-8 w-48`}),(0,G.jsx)(PS,{className:`h-32 w-full`})]}):r?null:t?(0,G.jsx)(Rqi,{processor:t}):(0,G.jsx)(`div`,{className:`px-4 py-8 text-center`,children:(0,G.jsx)(T,{variant:`heading`,tone:`muted`,children:`Processor not found`})})}function Rqi({processor:e}){let t=mw(),[n,r]=(0,W.useState)(e.phases[0]||`input`),[i,a]=(0,W.useState)(e.configurations[0]?.agentId||``),[o,s]=(0,W.useState)(`Hello, this is a test message.`),[c,l]=(0,W.useState)(null),[u,d]=(0,W.useState)(),f=OFt(),p=async()=>{d(void 0),l(null);let t=n===`outputStep`||n===`outputResult`?`assistant`:`user`,r=[{id:crypto.randomUUID(),role:t,createdAt:new Date,content:{format:2,parts:[{type:`text`,text:o}]}}];try{let t=await f.mutateAsync({processorId:e.id,phase:n,messages:r,agentId:i||void 0});l(t),!t.success&&t.error&&d(t.error)}catch(e){d(e.message||`An error occurred`)}},m=c?JSON.stringify(c,null,2):`{}`;return(0,G.jsxs)(`div`,{className:`relative grid h-full min-w-min grid-cols-[auto_1fr] overflow-x-auto overflow-y-auto`,children:[(0,G.jsxs)(`div`,{className:`w-[22rem] overflow-y-auto border-r border-border`,children:[(0,G.jsx)(zqi,{processor:e}),(0,G.jsxs)(`div`,{className:`space-y-5 p-5`,children:[(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(ZO,{children:[(0,G.jsx)($O,{children:`Phase`}),(0,G.jsxs)(Mk,{value:n,onValueChange:t=>{let n=e.phases.find(e=>e===t);n&&r(n)},children:[(0,G.jsx)(Pk,{className:`w-full`,children:(0,G.jsx)(Nk,{placeholder:`Select phase`})}),(0,G.jsx)(Fk,{children:e.phases.map(e=>(0,G.jsx)(Ik,{value:e,children:e},e))})]})]}),(0,G.jsx)(T,{variant:`meta`,tone:`muted`,children:Iqi[n]})]}),e.configurations.length>1&&(0,G.jsxs)(ZO,{children:[(0,G.jsx)($O,{children:`Agent Configuration`}),(0,G.jsxs)(Mk,{value:i,onValueChange:a,children:[(0,G.jsx)(Pk,{className:`w-full`,children:(0,G.jsx)(Nk,{placeholder:`Select agent`})}),(0,G.jsx)(Fk,{children:e.configurations.map(e=>(0,G.jsxs)(Ik,{value:e.agentId,children:[e.agentName,` (`,e.type,`)`]},e.agentId))})]})]}),(0,G.jsxs)(ZO,{children:[(0,G.jsx)($O,{children:`Test Message`}),(0,G.jsx)(zk,{value:o,onChange:e=>s(e.target.value),placeholder:`Enter a test message`,rows:4})]}),(0,G.jsx)(X,{icon:(0,G.jsx)(jD,{}),onClick:p,disabled:n===`outputStream`||n===`llmRequest`,className:`w-full`,loading:f.isPending,children:`Run processor`}),n===`outputStream`&&(0,G.jsx)(T,{variant:`meta`,className:`text-warning-foreground`,children:`Output Stream phase cannot be executed directly. Use streaming instead.`}),n===`llmRequest`&&(0,G.jsx)(T,{variant:`meta`,className:`text-warning-foreground`,children:`LLM Request phase cannot be executed directly. It runs on the provider prompt during an agent call.`}),c&&(0,G.jsxs)(`div`,{className:`space-y-2 border-t border-border pt-4`,children:[(0,G.jsx)(T,{variant:`caption`,tone:`muted`,children:`Status`}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(YS,{variant:c.success?`success`:`destructive`,children:c.success?`Success`:`Failed`}),c.tripwire?.triggered&&(0,G.jsx)(YS,{variant:`info`,children:`Tripwire Triggered`})]}),c.tripwire?.triggered&&c.tripwire.reason&&(0,G.jsxs)(`div`,{className:`mt-2 rounded-md border border-warning-edge bg-warning-subtle p-3`,children:[(0,G.jsx)(T,{variant:`column`,className:`text-warning-subtle-foreground`,children:`Tripwire Reason`}),(0,G.jsx)(T,{variant:`caption`,tone:`muted`,className:`mt-1`,children:c.tripwire.reason})]})]})]})]}),(0,G.jsx)(`div`,{className:`absolute top-4 right-4 z-10`,children:(0,G.jsx)(dC,{content:m,tooltip:`Copy JSON result to clipboard`})}),(0,G.jsx)(`div`,{className:`relative h-full overflow-x-auto overflow-y-auto p-5`,children:(0,G.jsx)(fw,{value:u||m,editable:!0,theme:t,extensions:[ht,pw],basicSetup:{foldGutter:!1}})})]})}function zqi({processor:e}){return(0,G.jsxs)(`div`,{className:`border-b border-border px-5 pt-5 pb-4`,children:[(0,G.jsx)(T,{variant:`heading`,tone:`faint`,className:`mb-2`,children:e.name||e.id}),e.name&&e.name!==e.id&&(0,G.jsx)(T,{variant:`caption`,tone:`muted`,className:`mb-3`,children:e.id}),(0,G.jsx)(`div`,{className:`mt-3 flex flex-wrap gap-1`,children:e.phases.map(e=>(0,G.jsx)(YS,{children:e},e))}),(0,G.jsx)(`div`,{className:`mt-3`,children:(0,G.jsxs)(T,{variant:`meta`,tone:`muted`,children:[`Attached to `,e.configurations.length,` agent`,e.configurations.length===1?``:`s`]})})]})}var Bqi=[AR(`/processors`),fnn];function Vqi(){let{processorId:e}=wv(),{data:t,isLoading:n,error:r}=DFt({processorId:e,queryOptions:{enabled:!!e}}),i=JN(r)||YN(r);return!n&&!i&&t?.isWorkflow?(0,G.jsx)(Dv,{to:`/workflows/${e}/graph`,replace:!0}):(0,G.jsxs)(NS,{variant:`page`,body:!n&&!r?`fixed`:`scroll`,breadcrumbs:(0,G.jsx)(lN,{crumbs:Bqi}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:e}),(0,G.jsx)(Hqi,{processorId:e,isLoading:n,error:r})]})}function Hqi({processorId:e,isLoading:t,error:n}){return n&&JN(n)?(0,G.jsx)(vR,{variant:`fill`}):n&&YN(n)?(0,G.jsx)(_R,{variant:`fill`,resource:`processors`}):t?(0,G.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,G.jsx)(PS,{className:`h-8 w-48`}),(0,G.jsx)(PS,{className:`h-32 w-full`})]}):(0,G.jsx)(`div`,{className:`h-full w-full overflow-y-hidden`,children:(0,G.jsx)(Lqi,{processorId:e})})}function Uqi(){let e=vFi(),{data:t,isLoading:n}=l4n({toolId:e}),{mutateAsync:r,status:i,data:a,error:o}=u4n(),s={execute:(t,n)=>r({toolId:e,input:t,requestContext:n}),status:i,output:a,error:o};return n?(0,G.jsx)(MN.LoadingData,{}):t?(0,G.jsx)(gqi,{tool:t,execution:s,requestContextEntityType:`tool`,requestContextEntityId:t.id}):(0,G.jsxs)(MN.NoData,{children:[`Tool "`,e,`" not found.`]})}var Wqi=()=>(0,G.jsx)(Vx,{titleSlot:`No Tools yet`,descriptionSlot:(0,G.jsxs)(G.Fragment,{children:[`Mastra tools are not configured yet. `,(0,G.jsx)(`br`,{}),`More information in the documentation.`]}),actionSlot:(0,G.jsx)(X,{variant:`ghost`,render:(0,G.jsx)(`a`,{href:`https://mastra.ai/docs/agents/using-tools-and-mcp`,target:`_blank`,rel:`noopener noreferrer`}),icon:(0,G.jsx)(nF,{}),children:`Tools documentation`}),variant:`fill`}),Gqi=(e,t)=>{let n=new Map,r=Object.keys(t);for(let e of r){let r=t[e],i=r.tools,a=Object.keys(i);for(let t of a){let a=i[t];n.has(a.id)||n.set(a.id,{...a,agents:[]}),n.get(a.id).agents.push({...r,id:e})}}for(let[t,r]of Object.entries(e))n.has(r.id)||n.set(r.id,{...r,agents:[]});return Array.from(n.values())},Kqi={name:e=>e.id,agents:e=>e.agents.length};function qqi({tools:e,agents:t,isLoading:n,search:r=``,sort:i,onSortChange:a,selectedToolId:o}){let{paths:s,Link:c}=on(),l=(0,W.useMemo)(()=>Gqi(e,t),[e,t]),u=(0,W.useMemo)(()=>P6(l.filter(e=>e.id.toLowerCase().includes(r.toLowerCase())),i,Kqi),[l,r,i]),{containerRef:d,getRowProps:f}=UP({count:u.length,global:!0});if(n)return(0,G.jsx)(QP,{columns:`auto 1fr auto`});let p=e=>i?.key===e?i.direction:void 0;return(0,G.jsxs)(Z,{columns:`auto 1fr auto`,scrollRef:d,children:[(0,G.jsxs)(Z.Top,{children:[a?(0,G.jsx)(Z.SortableTopCell,{sortKey:`name`,sort:p(`name`),onSortChange:a,children:`Name`}):(0,G.jsx)(Z.TopCell,{children:`Name`}),(0,G.jsx)(Z.TopCell,{children:`Description`}),a?(0,G.jsx)(Z.SortableTopCell,{sortKey:`agents`,sort:p(`agents`),onSortChange:a,align:`end`,children:`Agents`}):(0,G.jsx)(Z.TopCellSmart,{long:`Agents`,short:(0,G.jsx)(WP,{}),tooltip:`Attached agents`,className:`text-center`})]}),u.length===0&&r?(0,G.jsx)(Z.NoMatch,{message:`No Tools match your search`}):null,u.map((e,t)=>{let n=vN(e.id,50),r=vN(e.description??``,200),i=e.agents.length;return(0,G.jsxs)(Z.RowLink,{to:s.toolLink(e.id),LinkComponent:c,featured:e.id===o,...f(t),children:[(0,G.jsx)(Z.NameCell,{children:n}),(0,G.jsx)(Z.DescriptionCell,{children:r}),(0,G.jsx)(Z.TextCell,{className:`text-center`,children:i||``})]},e.id)})]})}var $9=[AR(`/tools`)];function Jqi(){let{data:e={},isLoading:t,error:n}=hN(),{data:r={},isLoading:i,error:a}=cX(),[o,s]=(0,W.useState)(``),[c,l]=(0,W.useState)(),{toolId:u}=GFi(),d=t||i,f=a||n;return f&&JN(f)?(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:$9}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`Tools`}),(0,G.jsx)(vR,{variant:`fill`})]}):f&&YN(f)?(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:$9}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`Tools`}),(0,G.jsx)(_R,{variant:`fill`,resource:`tools`})]}):f?(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:$9}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`Tools`}),(0,G.jsx)(Vx,{tone:`error`,variant:`fill`,titleSlot:`Failed to load tools`,descriptionSlot:f.message})]}):Object.keys(r).length===0&&!d?(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:$9}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`Tools`}),(0,G.jsx)(Wqi,{})]}):(0,G.jsxs)(NS,{variant:`page`,breadcrumbs:(0,G.jsx)(lN,{crumbs:$9}),actionRow:(0,G.jsx)(EP,{children:(0,G.jsx)(EP.Start,{children:(0,G.jsx)(`div`,{className:`max-w-120 flex-1`,children:(0,G.jsx)(CN,{...wN,onValueChange:s,label:`Search tools`,placeholder:`Search by name`})})})}),children:[(0,G.jsx)(`h1`,{className:`sr-only`,children:`Tools`}),(0,G.jsx)(qqi,{tools:r,agents:e,isLoading:d,search:o,sort:c,onSortChange:(e,t)=>l({key:t,direction:e}),selectedToolId:u}),(0,G.jsx)(KFi,{children:(0,G.jsx)(Uqi,{})})]})}var Yqi=()=>{let e=Cv();return(0,G.jsx)(an,{Link:sS,navigate:t=>e(t),paths:iY,children:(0,G.jsxs)($t,{children:[(0,G.jsx)(Dqi,{}),(0,G.jsx)(Eqi,{children:(0,G.jsx)(qKi,{children:(0,G.jsx)(bJe,{children:(0,G.jsx)(Ov,{})})})})]})})},Xqi=()=>{let e=Cv();return(0,G.jsx)(an,{Link:sS,navigate:t=>e(t),paths:iY,children:(0,G.jsx)(JKi,{children:(0,G.jsx)(Ov,{})})})},Zqi=!!window.MASTRA_CLOUD_API_ENDPOINT,Qqi=jt.has(`datasets`),$qi=[{index:!0,element:(0,G.jsx)(Hbi,{})},{path:`instruction-blocks`,element:(0,G.jsx)(Ubi,{})},{path:`tools`,element:(0,G.jsx)(qbi,{})},{path:`agents`,element:(0,G.jsx)(Fbi,{})},{path:`scorers`,element:(0,G.jsx)(Gbi,{})},{path:`workflows`,element:(0,G.jsx)(Ybi,{})},{path:`skills`,element:(0,G.jsx)(Kbi,{})},{path:`memory`,element:(0,G.jsx)(Wbi,{})},{path:`variables`,element:(0,G.jsx)(Jbi,{})}],eJi=[{element:(0,G.jsx)($Gi,{}),children:[{path:`/login`,element:(0,G.jsx)(Qji,{})},{path:`/signup`,element:(0,G.jsx)(cHi,{})}]},{path:`/agent-builder`,element:(0,G.jsx)(mJe,{paths:iY}),children:[{index:!0,element:(0,G.jsx)(gZn,{})},{path:`agents`,element:(0,G.jsx)(Z9,{}),children:[{index:!0,element:(0,G.jsx)(c4n,{})}]},{path:`agents`,element:(0,G.jsx)(sqi,{}),children:[{path:`create`,element:(0,G.jsx)(x4n,{})},{path:`:id`,loader:({params:e})=>V_(`/agent-builder/agents/${e.id}/view`)},{path:`:id/edit`,element:(0,G.jsx)(lYr,{})},{path:`:id/view`,element:(0,G.jsx)(mXr,{})}]},{path:`skills`,element:(0,G.jsx)(Z9,{}),children:[{index:!0,element:(0,G.jsx)(QXr,{})}]},{path:`skills`,element:(0,G.jsx)(sqi,{}),children:[{path:`create`,element:(0,G.jsx)(nZr,{})},{path:`:id`,loader:({params:e})=>V_(`/agent-builder/skills/${e.id}/edit`)},{path:`:id/edit`,element:(0,G.jsx)(OZr,{})},{path:`:id/view`,element:(0,G.jsx)(IZr,{})}]},{path:`infrastructure`,element:(0,G.jsx)(Z9,{}),children:[{index:!0,element:(0,G.jsx)(zXr,{})}]},{path:`favorite`,element:(0,G.jsx)(Z9,{}),children:[{index:!0,element:(0,G.jsx)(TXr,{})}]},{path:`library`,element:(0,G.jsx)(Z9,{}),children:[{index:!0,element:(0,G.jsx)(BXr,{})}]}]},{element:(0,G.jsx)(Xqi,{}),children:[{path:`/agents/:agentId/session`,element:(0,G.jsx)(Z7r,{})},{path:`/agents/:agentId/session/:threadId`,element:(0,G.jsx)(Z7r,{})}]},{element:(0,G.jsx)(Yqi,{}),children:[...Zqi?[]:[{path:`/settings`,element:(0,G.jsx)(sHi,{})},{path:`/templates`,element:(0,G.jsx)(_Ui,{})},{path:`/templates/:templateSlug`,element:(0,G.jsx)(PUi,{})}],{path:`/logs`,element:(0,G.jsx)(wNi,{})},{path:`/scorers`,element:(0,G.jsx)(UVi,{})},{path:`/scorers/:scorerId`,element:(0,G.jsx)(ZVi,{})},{path:`/metrics`,element:(0,G.jsx)(jVi,{})},{path:`/intelligence`,element:(0,G.jsx)(Ezn,{})},{path:`/intelligence/entities/:entityType/:entityId`,element:(0,G.jsx)(Fzn,{})},{element:(0,G.jsx)(Aqi,{children:(0,G.jsx)(Ov,{})}),children:[{path:`/traces`,element:(0,G.jsx)(Nbi,{})},{path:`/spans`,element:(0,G.jsx)(XHi,{})},{path:`/threads`,element:(0,G.jsx)(JUi,{})}]},{path:`/traces/:traceId`,loader:({params:e,request:t})=>{let n=new URL(t.url).searchParams;return n.set(`traceId`,e.traceId??``),V_(`/traces?${n.toString()}`)}},{path:`/observability`,loader:({request:e})=>V_(`/traces${new URL(e.url).search}`)},{path:`/resources`,element:(0,G.jsx)(VVi,{})},{path:`/agents`,element:(0,G.jsx)(hQr,{})},{path:`/cms/agents/create`,element:(0,G.jsx)(Lbi,{}),children:$qi},{path:`/cms/agents/:agentId/edit`,element:(0,G.jsx)(Vbi,{}),children:$qi},{path:`/cms/scorers/create`,element:(0,G.jsx)(nxi,{})},{path:`/cms/scorers/:scorerId/edit`,element:(0,G.jsx)(oxi,{})},{path:`/prompts`,element:(0,G.jsx)(LVi,{})},{path:`/cms/prompts/create`,element:(0,G.jsx)(Zbi,{})},{path:`/cms/prompts/:promptBlockId/edit`,element:(0,G.jsx)(exi,{})},{path:`/agents/:agentId`,element:(0,G.jsx)(Sqi,{children:(0,G.jsx)(Ov,{})}),children:[{index:!0,loader:lZn},{path:`chat`,loader:uZn},{path:`chat/:threadId`,loader:uZn},{path:`threads`,loader:cZn},{path:`threads/:threadId`,element:(0,G.jsx)(Oei,{})},{path:`overview`,loader:fZn},{path:`settings`,loader:fZn},...Qqi?[{path:`editor`,element:(0,G.jsx)(uti,{})}]:[],{path:`traces`,element:(0,G.jsx)(Pbi,{})},{path:`channels`,loader:({params:e})=>V_(`/agents/${e.agentId}/threads/new`)}]},{path:`/tools`,element:(0,G.jsx)(Jqi,{})},{path:`/integrations`,element:(0,G.jsx)(qEi,{})},{path:`/connections`,element:(0,G.jsx)(_xi,{})},{path:`/processors`,element:(0,G.jsx)(Fqi,{})},{path:`/processors/:processorId`,element:(0,G.jsx)(Vqi,{})},{path:`/mcps`,element:(0,G.jsx)(WNi,{})},{path:`/mcps/:serverId`,element:(0,G.jsx)(qFi,{})},{path:`/workspaces`,element:(0,G.jsx)(XGi,{})},{path:`/workspaces/:workspaceId`,element:(0,G.jsx)(XGi,{})},{path:`/workspaces/:workspaceId/skills/:skillName`,loader:({params:e,request:t})=>V_(rY(e.workspaceId,new URL(t.url).searchParams.get(`path`)))},{path:`/workflows`,element:(0,G.jsx)(sWi,{})},{path:`/workflows/schedules`,element:(0,G.jsx)(TWi,{})},{path:`/workflows/schedules/:scheduleId`,element:(0,G.jsx)(yWi,{})},{path:`/workflows/:workflowId`,element:(0,G.jsx)(Mnn,{children:(0,G.jsx)(Ov,{})}),children:[{index:!0,loader:({params:e})=>V_(`/workflows/${e.workflowId}/graph`)},{path:`graph`,element:(0,G.jsx)(KWi,{})},{path:`graph/:runId`,element:(0,G.jsx)(KWi,{})},{path:`traces`,element:(0,G.jsx)(JWi,{})},{path:`schedules`,element:(0,G.jsx)(qWi,{})}]},{path:`/knowledge`,element:(0,G.jsx)(Yji,{})},...Qqi?[{path:`/datasets`,element:(0,G.jsx)(bxi,{})},{path:`/datasets/:datasetId`,element:(0,G.jsx)(dSi,{}),children:[{path:`items/:itemId`,element:null}]},{path:`/datasets/:datasetId/edit`,element:(0,G.jsx)(fSi,{})},{path:`/datasets/:datasetId/items/:itemId/versions`,element:(0,G.jsx)(pSi,{})},{path:`/experiments`,element:(0,G.jsx)(jTi,{})},{path:`/experiments/compare`,element:(0,G.jsx)(ZTi,{})},{path:`/experiments/review-queue`,element:(0,G.jsx)(IEi,{})},{path:`/experiments/:experimentId`,element:(0,G.jsx)(_Ei,{}),children:[{path:`items/:itemId`,element:null}]},{path:`/datasets/:datasetId/versions`,element:(0,G.jsx)(mSi,{})}]:[],{index:!0,element:(0,G.jsx)(mZn,{})}]}];function tJi(){let e=window.MASTRA_STUDIO_BASE_PATH||``,{baseUrl:t,headers:n,apiPrefix:r,isLoading:i}=fS(),a=(0,W.useMemo)(()=>t?MFe(t,r):void 0,[t,r]),o=(0,W.useMemo)(()=>({...n,"x-mastra-client-type":`studio`}),[n]),s=(0,W.useMemo)(()=>Jze(eJi,{basename:e}),[e]);return i?(0,G.jsx)(Ft,{fill:`screen`}):t?(0,G.jsx)(hPe,{baseUrl:t,headers:o,apiPrefix:r,customFetch:a,children:(0,G.jsx)(uJe,{children:(0,G.jsx)(sZn,{children:(0,G.jsx)(MJe,{baseUrl:t,children:(0,G.jsx)(Oze,{router:s})})})})}):(0,G.jsx)(X4r,{})}function nJi(){let e=window.MASTRA_SERVER_PROTOCOL||`http`,t=window.MASTRA_SERVER_HOST||`localhost`,n=window.MASTRA_SERVER_PORT||4111,r=window.MASTRA_API_PREFIX||`/api`,i=window.MASTRA_CLOUD_API_ENDPOINT||``,a=window.MASTRA_AUTO_DETECT_URL===`true`,o=i||(a?window.location.origin:`${e}://${t}:${n}`);return(0,G.jsx)(Pen,{children:(0,G.jsx)(jJe,{endpoint:o,defaultApiPrefix:r,children:(0,G.jsx)(tJi,{})})})}function rJi(){(0,At.createRoot)(document.getElementById(`root`)).render((0,G.jsx)(W.StrictMode,{children:(0,G.jsx)(nJi,{})}))}export{rJi as startStudio};
@@ -101,7 +101,7 @@
101
101
  connectSSE();
102
102
  })();
103
103
  </script>
104
- <script type="module" crossorigin src="./assets/index-Bb18bYfu.js"></script>
104
+ <script type="module" crossorigin src="./assets/index-y7atQeWR.js"></script>
105
105
  <link rel="modulepreload" crossorigin href="./assets/preload-helper-CRzLMJPS.js">
106
106
  <link rel="stylesheet" crossorigin href="./assets/style-CLhrNGTk.css">
107
107
  </head>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mastra",
3
- "version": "1.40.2-alpha.9",
3
+ "version": "1.40.2",
4
4
  "license": "Apache-2.0",
5
5
  "description": "cli for mastra",
6
6
  "type": "module",
@@ -61,8 +61,8 @@
61
61
  "strip-json-comments": "^5.0.3",
62
62
  "tinyglobby": "^0.2.17",
63
63
  "yocto-spinner": "^1.1.0",
64
- "@mastra/deployer": "^1.86.0-alpha.9",
65
- "@mastra/loggers": "^1.3.12-alpha.0"
64
+ "@mastra/deployer": "^1.86.0",
65
+ "@mastra/loggers": "^1.3.12"
66
66
  },
67
67
  "devDependencies": {
68
68
  "@commander-js/extra-typings": "^14.0.0",
@@ -82,10 +82,10 @@
82
82
  "vitest": "5.1.0",
83
83
  "zod": "^4.6.7",
84
84
  "@internal/factory-ui": "0.0.0",
85
- "@internal/lint": "0.0.151",
86
- "@internal/playground": "1.40.2-alpha.9",
87
- "@internal/types-builder": "0.0.126",
88
- "@mastra/core": "1.86.0-alpha.9"
85
+ "@internal/lint": "0.0.152",
86
+ "@internal/playground": "1.40.2",
87
+ "@internal/types-builder": "0.0.127",
88
+ "@mastra/core": "1.86.0"
89
89
  },
90
90
  "peerDependencies": {
91
91
  "@mastra/core": ">=1.85.1-0 <2.0.0-0"