mastra 1.40.3-alpha.8 → 1.40.3-alpha.9

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.3-alpha.8"
6
+ version: "1.40.3-alpha.9"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.40.3-alpha.8",
2
+ "version": "1.40.3-alpha.9",
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.3-alpha.8",
51
+ version: "1.40.3-alpha.9",
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-DWdHQHEj.js","./rolldown-runtime-BWaJ3C7D.js","./transitions.es-DEgr4I7d.js","./code-editor-BLzt8hly-Cyt_A_o5.js","./preload-helper-CRzLMJPS.js","./dist-Bb1O3cNb.js","./dist-CRSyDOHk.js","./dist-KpoPGPlt.js","./dist-Dq32n9F4.js","./dist-Cs7oVa-O.js","./lib-DQbroTw-.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-DWdHQHEj.js`);return{startStudio:e}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10]),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-C65yjtAO.js","./rolldown-runtime-BWaJ3C7D.js","./transitions.es-DEgr4I7d.js","./code-editor-BLzt8hly-Cyt_A_o5.js","./preload-helper-CRzLMJPS.js","./dist-Bb1O3cNb.js","./dist-CRSyDOHk.js","./dist-KpoPGPlt.js","./dist-Dq32n9F4.js","./dist-Cs7oVa-O.js","./lib-DQbroTw-.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-C65yjtAO.js`);return{startStudio:e}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10]),import.meta.url);t()}catch(e){console.error(`Mastra Studio failed to start`,e),r(e)}
@@ -876,7 +876,7 @@ Ask one simple question at a time.`;function jHr(e,t){let n=(0,G.useRef)(e);retu
876
876
  `),i=r.length-CSi;return!t||i<2?(0,K.jsx)(DSi,{text:e}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(DSi,{text:r.slice(0,CSi).join(`
877
877
  `)}),`
878
878
  `,(0,K.jsxs)(`span`,{className:`text-muted-foreground`,children:[`+`,i,` more lines`]})]})}function kSi({timestamp:e,fractionDigits:t=2}){let n=bx(e),r=nqe(e,{fractionDigits:t});return!n||!r?(0,K.jsx)(`time`,{children:String(e)}):(0,K.jsxs)(jn,{children:[(0,K.jsx)(dr,{render:(0,K.jsxs)(`time`,{dateTime:n.toISOString(),children:[r.day,` `,(0,K.jsx)(`span`,{className:`text-foreground`,children:r.time}),r.fraction]})}),(0,K.jsx)(qt,{side:`top`,align:`start`,children:(0,K.jsx)(est,{date:n,fractionDigits:t})})]})}function ASi({message:e,timestamp:t,fractionDigits:n,level:r,icon:i,fields:a,wrap:o=!0,collapse:s=!0}){let c=a?Object.entries(a):[];return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`span`,{className:`font-mono text-body-sm whitespace-nowrap text-muted-foreground tabular-nums`,children:t!==void 0&&(0,K.jsx)(kSi,{timestamp:t,fractionDigits:n})}),(0,K.jsx)(`span`,{className:T(`font-mono text-body-sm uppercase`,r&&cSi[r]),children:r}),(0,K.jsxs)(`span`,{className:T(`min-w-0 font-mono text-body-sm text-foreground @max-md:col-span-full`,o?`wrap-anywhere whitespace-pre-wrap`:`whitespace-pre`),children:[i&&(0,K.jsx)(uSi,{element:i.element,label:i.label}),(0,K.jsx)(OSi,{message:e,collapse:s}),c.length>0&&(0,K.jsx)(`span`,{className:`ml-3`,children:(0,K.jsx)(ESi,{entries:c})})]})]})}var jSi=new Date(2e3,11,28,23,59,59,999);function MSi({fractionDigits:e=2}){let t=nqe(jSi,{fractionDigits:e});return(0,K.jsxs)(`div`,{"aria-hidden":!0,className:`invisible col-span-full grid h-0 grid-cols-subgrid gap-x-4 overflow-hidden px-3 font-mono text-body-sm tabular-nums`,children:[(0,K.jsx)(`span`,{children:t&&`${t.day} ${t.time}${t.fraction}`}),(0,K.jsx)(`span`,{className:`uppercase`,children:`error`}),(0,K.jsx)(`span`,{})]})}var NSi={gridTemplateColumns:`auto auto minmax(0,1fr)`};function PSi({children:e,scrollRef:t,wrap:n=!0,fractionDigits:r,className:i}){return(0,K.jsx)(aSi,{className:T(`flex flex-col`,i),children:(0,K.jsx)(qb,{orientation:`both`,mask:!1,className:`flex min-h-0 flex-1 flex-col`,children:(0,K.jsx)(Kb,{ref:t,className:`min-h-0 flex-1 overscroll-x-none`,children:(0,K.jsxs)(`div`,{className:T(`grid content-start`,n?`w-full`:`w-max min-w-full`),style:NSi,children:[(0,K.jsx)(MSi,{fractionDigits:r}),e]})})})})}function FSi({level:e,featured:t},n,r){return T(`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-['']`,e?lSi[e]:`before:bg-border-strong`,(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 ISi({level:e,featured:t,className:n,...r}){return(0,K.jsx)(`div`,{className:FSi({level:e,featured:t},!1,n),"data-featured":t||void 0,...r})}function LSi({level:e,featured:t,className:n,type:r=`button`,...i}){return(0,K.jsx)(`button`,{type:r,className:FSi({level:e,featured:t},!0,n),"data-featured":t||void 0,...i})}function RSi({height:e}){return(0,K.jsx)(`div`,{"aria-hidden":!0,className:`col-span-full`,style:{height:e}})}Object.assign(PSi,{Frame:aSi,Header:oSi,HeaderCell:sSi,Row:ISi,RowButton:LSi,Line:ASi,Spacer:RSi});function zSi({log:e}){return(0,K.jsxs)(o9,{title:`Details`,children:[(0,K.jsx)(o9.Row,{label:`Level`,children:(0,K.jsx)(`span`,{className:T(`capitalize`,cSi[e.level]),children:e.level})}),e.entityType&&(0,K.jsx)(o9.Row,{label:`Entity type`,children:e.entityType}),e.entityName&&(0,K.jsx)(o9.Row,{label:`Entity name`,children:e.entityName}),e.serviceName&&(0,K.jsx)(o9.Row,{label:`Service`,children:e.serviceName}),e.environment&&(0,K.jsx)(o9.Row,{label:`Environment`,children:e.environment}),e.source&&(0,K.jsx)(o9.Row,{label:`Source`,children:e.source})]})}function BSi(e){if(e.trim().startsWith(`{`))try{return JSON.stringify(JSON.parse(e),null,2)}catch{return}}function VSi({message:e}){let t=BSi(e);return t===void 0?(0,K.jsx)(uj.CodeSection,{title:`Message`,codeStr:e,simplified:!0}):(0,K.jsx)(uj.CodeSection,{title:`Message`,codeStr:t})}function HSi(e){return e===null||[`string`,`number`,`boolean`].includes(typeof e)}function USi(e){return e!=null&&e!==``}function WSi({title:e,values:t}){let n=Object.entries(t??{});if(!n.every(([,e])=>HSi(e)))return(0,K.jsx)(uj.CodeSection,{title:e,codeStr:JSON.stringify(t,null,2)});let r=n.filter(([,e])=>USi(e));return r.length===0?null:(0,K.jsx)(o9,{title:e,children:r.map(([e,t])=>(0,K.jsx)(o9.Row,{label:e,mono:!0,children:String(t)},e))})}function GSi({log:e,onClose:t,onTraceClick:n,onSpanClick:r,onPrevious:i,onNext:a,depth:o,actions:s}){let c=e?wx(e.timestamp)??``:``;return(0,K.jsx)(uj,{open:!!e,onClose:t,title:e?`Log ${c}`:`Log`,depth:o,children:e&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(uj.Header,{children:[(0,K.jsx)(uj.CloseButton,{onClick:t}),(0,K.jsx)(uj.Heading,{children:`Log`}),(0,K.jsx)(uj.Metadata,{children:(0,K.jsx)(uj.Meta,{tooltip:c,children:c})}),(0,K.jsxs)(uj.HeaderActions,{children:[s,(0,K.jsx)(uj.NextPrevNav,{onPrevious:i,onNext:a,previousLabel:`Go to previous log`,nextLabel:`Go to next log`})]})]}),(0,K.jsx)(uj.Content,{children:(0,K.jsxs)(`div`,{className:`grid gap-6 p-2`,children:[(0,K.jsx)(zSi,{log:e}),(0,K.jsx)(VSi,{message:e.message}),(0,K.jsx)(WSi,{title:`Fields`,values:e.data}),(0,K.jsx)(WSi,{title:`Metadata`,values:e.metadata}),(e.traceId||e.spanId)&&(0,K.jsxs)(`div`,{className:`grid gap-2`,children:[e.traceId&&(0,K.jsxs)(XA,{className:`w-full min-w-0`,children:[(0,K.jsxs)(U,{className:`min-w-0 flex-1 justify-between overflow-hidden`,icon:(0,K.jsx)(nM,{}),onClick:()=>e.traceId&&n?.(e.traceId),children:[(0,K.jsx)(`span`,{children:`Trace`}),(0,K.jsxs)(W,{as:`span`,variant:`caption`,tone:`faint`,className:`ml-auto min-w-0 truncate`,children:[`# `,e.traceId]})]}),(0,K.jsx)(Gn,{content:e.traceId,tooltip:`Copy trace ID to clipboard`})]}),e.spanId&&(0,K.jsxs)(XA,{className:`w-full min-w-0`,children:[(0,K.jsxs)(U,{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,K.jsx)(nM,{}),children:[(0,K.jsx)(`span`,{children:`Span`}),(0,K.jsxs)(W,{as:`span`,variant:`caption`,tone:`faint`,className:`ml-auto min-w-0 truncate`,children:[`# `,e.spanId]})]}),(0,K.jsx)(Gn,{content:e.spanId,tooltip:`Copy span ID to clipboard`})]})]})]})})]})})}function KSi({error:e,resource:t,errorTitle:n}){if(Ej(e))return(0,K.jsx)(oI,{});if(Dj(e))return(0,K.jsx)(aI,{resource:t});if(Aj(e))return(0,K.jsx)(db,{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(kj(e,`logs`))return(0,K.jsx)(db,{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,K.jsx)(db,{tone:`error`,titleSlot:n,descriptionSlot:r??`Unknown error`})}var qSi={debug:`neutral`,info:`info`,warn:`warning`,error:`destructive`,fatal:`destructive`};function JSi({level:e}){return(0,K.jsx)(xM,{children:(0,K.jsx)(dx,{variant:qSi[e],children:e})})}function YSi({entityType:e,className:t}){let n=T(`size-3.5 shrink-0 text-subtle-foreground`,t);switch(e.toLowerCase()){case`agent`:return(0,K.jsx)(FM,{className:n,"aria-hidden":!0});case`workflow`:case`workflow_run`:return(0,K.jsx)(cx,{className:n,"aria-hidden":!0});case`tool`:return(0,K.jsx)(HM,{className:n,"aria-hidden":!0});default:return null}}function XSi({entityType:e,entityName:t}){return(0,K.jsxs)(xM,{className:`flex min-w-0 items-center gap-2`,children:[(0,K.jsx)(YSi,{entityType:e??``}),t?(0,K.jsx)(W,{as:`span`,variant:`body-sm`,className:`min-w-0 truncate`,children:t}):`-`]})}function ZSi({message:e}){return(0,K.jsx)(xM,{className:`min-w-0 truncate font-mono text-body-sm text-muted-foreground`,children:e})}function QSi({data:e}){if(!e||Object.keys(e).length===0)return(0,K.jsx)(xM,{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,K.jsx)(wM,{font:`mono`,children:t})}var c9=Object.assign(OM,{Top:NM,TopCell:AM,SortableTopCell:MM,TopCellWithTooltip:jM,TopCellSmart:vAt,RowWrapper:pAt,RowButton:kM,RowLink:dAt,Spacer:wAt,NoMatch:EM,DateCell:Nkt,TimeCell:Fkt,LevelCell:JSi,EntityCell:XSi,MessageCell:ZSi,DataCell:QSi,NextPageLoading:TM}),$Si=`6rem 9rem 5rem 10rem minmax(8rem,1fr) minmax(8rem,1fr)`,eCi=36,tCi=8;function nCi({logs:e,isLoading:t,isFetchingNextPage:n,hasNextPage:r,setEndOfListElement:i,logIdMap:a,featuredLogId:o,onLogClick:s,timestampSort:c,onSortChange:l}){let u=(0,G.useRef)(null),d=eei({count:e.length,getScrollElement:()=>u.current,estimateSize:()=>eCi,overscan:tCi}),{getRowProps:f}=PM({count:e.length,containerRef:u,onNavigate:e=>d.scrollToIndex(e),global:!0}),p=(0,G.useRef)(t);if((0,G.useEffect)(()=>{p.current&&!t&&u.current?.dispatchEvent(new Event(`scroll`)),p.current=t},[t]),t)return(0,K.jsx)(UM,{columns:$Si,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,K.jsxs)(c9,{columns:$Si,scrollRef:u,className:`min-w-0`,fit:`container`,children:[(0,K.jsxs)(c9.Top,{children:[l?(0,K.jsx)(c9.SortableTopCell,{sortKey:`timestamp`,sort:c,onSortChange:l,children:`Date`}):(0,K.jsx)(c9.TopCell,{children:`Date`}),(0,K.jsx)(c9.TopCell,{children:`Time`}),(0,K.jsx)(c9.TopCell,{children:`Level`}),(0,K.jsx)(c9.TopCell,{children:`Entity`}),(0,K.jsx)(c9.TopCell,{children:`Message`}),(0,K.jsx)(c9.TopCell,{children:`Data`})]}),e.length===0?(0,K.jsx)(c9.NoMatch,{message:`No logs match your search`}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(c9.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,K.jsxs)(c9.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,K.jsx)(c9.DateCell,{timestamp:n.timestamp}),(0,K.jsx)(c9.TimeCell,{timestamp:n.timestamp}),(0,K.jsx)(c9.LevelCell,{level:n.level}),(0,K.jsx)(c9.EntityCell,{entityType:n.entityType,entityName:n.entityName}),(0,K.jsx)(c9.MessageCell,{message:n.message}),(0,K.jsx)(c9.DataCell,{data:n.data})]},r)}),(0,K.jsx)(c9.Spacer,{height:_})]}),(0,K.jsx)(c9.NextPageLoading,{isLoading:n,hasMore:r,setEndOfListElement:i})]})}function rCi({onClear:e,onRemoveAll:t,onSave:n,onRemoveSaved:r,isLoading:i,filterFields:a,filterTokens:o,onFilterTokensChange:s,autoFocusFilterFieldId:c}){let l=o.length>0,u=o.some(e=>iCi(e,a));return l?(0,K.jsxs)(`div`,{className:T(`grid grid-cols-[1fr_auto] items-start gap-3`),children:[(0,K.jsx)(Qxi,{fields:a,tokens:o,onTokensChange:s,disabled:i,autoFocusFieldId:c}),l&&(0,K.jsx)(Hxi,{disabled:i,onClear:u?e:void 0,onRemoveAll:t,onSave:n,onRemoveSaved:r})]}):null}function iCi(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 aCi={"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`},oCi=`Pick a wider range or lower the logging level. Verbose entries (debug, info) may be filtered out.`;function sCi({datePreset:e,dateFrom:t,dateTo:n}){return e&&e!==`all`&&e!==`custom`?{title:`No logs for ${aCi[e]}`,description:oCi}:t&&n?{title:`No logs between ${Cx(t,`date-time`)} and ${Cx(n,`date-time`)}`,description:oCi}:t?{title:`No logs since ${Cx(t,`date-time`)}`,description:oCi}:{title:`No logs yet`,description:`Logs will appear here once agents, workflows, or tools are executed.`}}var cCi=({datePreset:e,dateFrom:t,dateTo:n}={})=>{let{title:r,description:i}=sCi({datePreset:e,dateFrom:t,dateTo:n});return(0,K.jsx)(db,{titleSlot:r,descriptionSlot:i,actionSlot:(0,K.jsx)(U,{variant:`ghost`,render:(0,K.jsx)(`a`,{href:`https://mastra.ai/en/docs/observability/logging`,target:`_blank`,rel:`noopener noreferrer`}),icon:(0,K.jsx)(qM,{}),children:`Logging documentation`}),variant:`fill`})},lCi=`Filters setting for Logs saved`,uCi=`Filters setting for Logs cleared up`;function dCi(e,t,n){let{storageKey:r,messages:i,skipHydration:a}=n??{},[o,s]=(0,G.useState)(()=>toi(r)!==null),c=(0,G.useCallback)(()=>{$ai(e,r),s(!0);let t=i?.saved??lCi;t!==!1&&vn.success(t)},[e,r,i?.saved]),l=(0,G.useCallback)(()=>{eoi(r),s(!1);let e=i?.cleared??uCi;e!==!1&&vn.success(e)},[r,i?.cleared]),u=(0,G.useRef)(!1);return(0,G.useEffect)(()=>{if(a||u.current||(u.current=!0,noi(e)))return;let n=toi(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 fCi(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 pCi(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,fCi(`${e}${n.message??``}${n.data?JSON.stringify(n.data):``}`))}return t}function mCi(e,t,n,r){let i=(0,G.useMemo)(()=>pCi(e),[e]),a=(0,G.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,G.useCallback)(e=>i.get(e),[i]),featuredLog:s,handleLogClick:(0,G.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 hCi=`logId`,gCi=`traceId`,_Ci=`spanId`,l9=864e5,vCi={"last-24h":l9,"last-3d":3*l9,"last-7d":7*l9,"last-14d":14*l9,"last-30d":30*l9};function u9(e){e.delete(hCi),e.delete(gCi),e.delete(_Ci)}function yCi(e,t,n){let{onRemoveAll:r}=n??{},i=(0,G.useMemo)(()=>{let t=e.get(N5);return t&&Xai.has(t)?t:qai},[e]),a=e.get(P5),o=e.get(F5),s=(0,G.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=vCi[i];return e?new Date(Date.now()-e):void 0},[i,a]),c=(0,G.useMemo)(()=>{if(i!==`custom`||!o)return;let e=new Date(o);return Number.isNaN(e.getTime())?void 0:e},[i,o]),l=(0,G.useRef)(i);l.current=i;let u=e.get(hCi),d=e.get(gCi),f=e.get(_Ci),p=(0,G.useMemo)(()=>Gai.find(t=>t.entityType===e.get(M5)),[e]),m=(0,G.useMemo)(()=>ioi(e),[e]),h=(0,G.useCallback)(e=>{t(t=>{let n=new URLSearchParams(t);for(let[t,r]of Object.entries(e)){let e=t===`logId`?hCi:t===`traceId`?gCi:_Ci;r?n.set(e,r):n.delete(e)}return n},{replace:!0})},[t]),g=(0,G.useCallback)(e=>{t(t=>{let n=new URLSearchParams(t);return ooi(n,e),u9(n),n},{replace:!0})},[t]),_=g,v=(0,G.useCallback)((e,n)=>{if(l.current!==`custom`)return;let r=n===`from`?P5:F5;t(t=>{let n=new URLSearchParams(t);return e?n.set(r,e.toISOString()):n.delete(r),u9(n),n},{replace:!0})},[t]),y=(0,G.useCallback)(e=>{l.current=e,t(t=>{let n=new URLSearchParams(t);return e===`last-24h`?(n.delete(N5),n.delete(P5),n.delete(F5)):e===`custom`?n.set(N5,`custom`):(n.set(N5,e),n.delete(P5),n.delete(F5)),u9(n),n},{replace:!0})},[t]),b=(0,G.useCallback)(()=>{t(e=>{let t=new URLSearchParams(e);t.delete(M5);for(let e of L5)t.delete(I5[e]);return t.delete(N5),t.delete(P5),t.delete(F5),u9(t),t},{replace:!0}),r?.()},[t,r]);return(0,G.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 bCi=20,xCi=1e4,SCi={field:`timestamp`,direction:`DESC`};function CCi(e,t,n){if(e?.pagination?.hasMore)return n+1}function wCi(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 TCi(e){return kj(e.state.error,`logs`)||Aj(e.state.error)?!1:xCi}var ECi=({filters:e,orderBy:t=SCi,queryOptions:n}={})=>{let r=X(),{inView:i,setRef:a}=hA(),{hasNextPage:o,isFetchingNextPage:s,fetchNextPage:c,data:l,isLoading:u,isError:d,error:f}=Jv({queryKey:[`logs`,e,t],queryFn:({pageParam:n})=>r.listLogsVNext({pagination:{page:n,perPage:bCi},filters:e,orderBy:t}),initialPageParam:0,getNextPageParam:CCi,select:wCi,retry:!1,refetchInterval:TCi,...n});return(0,G.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}},DCi=[vI(`/logs`)];function OCi(){let[e,t]=nb(),n=yCi(e,t),{sort:r,onSortChange:i}=pP({searchParams:e,setSearchParams:t,allowedKeys:Jai,defaultSort:Yai}),a=(0,G.useMemo)(()=>({field:`timestamp`,direction:r?.direction===`asc`?`ASC`:`DESC`}),[r?.direction]),o=dCi(e,t),[s,c]=(0,G.useState)(),{data:l=[],isPending:u}=Q2r(),{data:d=[],isPending:f}=O6({entityType:n.selectedEntityOption?.entityType,rootOnly:!0}),{data:p=[],isPending:m}=k6(),{data:h=[],isPending:g}=X2r(),_=(0,G.useMemo)(()=>roi({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}=ECi({filters:(0,G.useMemo)(()=>soi({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}=mCi(v,n.featuredLogId,n.handleFeaturedChange,n.featuredTraceId),{data:k,isLoading:A}=j6({traceId:n.featuredTraceId??null,queryOptions:{enabled:!!n.featuredTraceId}}),j=(0,G.useCallback)(()=>n.applyFilterTokens(coi(_,n.filterTokens)),[_,n]),M=(0,G.useCallback)(()=>n.handleFeaturedChange({logId:null}),[n]),N=(0,G.useCallback)(e=>n.handleFeaturedChange({traceId:e,spanId:null}),[n]),P=(0,G.useCallback)((e,t)=>n.handleFeaturedChange({traceId:e,spanId:t}),[n]),F=(0,G.useCallback)(()=>n.handleFeaturedChange({traceId:null,spanId:null}),[n]),I=(0,G.useCallback)(e=>n.handleFeaturedChange({spanId:e??null}),[n]),L=(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(_M,{children:(0,K.jsxs)(_M.Start,{children:[(0,K.jsx)(oOt,{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,K.jsx)(tSi,{fields:_,tokens:n.filterTokens,onTokensChange:n.handleFilterTokensChange,disabled:y,onStartTextFilter:c,size:`sm`})]})}),(0,K.jsx)(rCi,{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,K.jsxs)(Xb,{variant:`page`,breadcrumbs:(0,K.jsx)(IA,{crumbs:DCi}),actionRow:L,children:[(0,K.jsx)(`h1`,{className:`sr-only`,children:`Logs`}),(0,K.jsx)(`div`,{className:`flex h-full items-center justify-center`,children:(0,K.jsx)(KSi,{error:b,resource:`logs`,errorTitle:`Failed to load logs`})})]});let R=!!n.selectedEntityOption||n.filterTokens.length>0;return v.length===0&&!y&&!R?(0,K.jsxs)(Xb,{variant:`page`,breadcrumbs:(0,K.jsx)(IA,{crumbs:DCi}),actionRow:L,children:[(0,K.jsx)(`h1`,{className:`sr-only`,children:`Logs`}),(0,K.jsx)(cCi,{datePreset:n.datePreset,dateFrom:n.selectedDateFrom,dateTo:n.selectedDateTo})]}):(0,K.jsxs)(Xb,{variant:`page`,breadcrumbs:(0,K.jsx)(IA,{crumbs:DCi}),actionRow:L,children:[(0,K.jsx)(`h1`,{className:`sr-only`,children:`Logs`}),(0,K.jsx)(nCi,{logs:v,isLoading:y,isFetchingNextPage:x,hasNextPage:S,setEndOfListElement:C,logIdMap:w,featuredLogId:n.featuredLogId,onLogClick:E,timestampSort:r?.direction,onSortChange:i}),(0,K.jsx)(GSi,{log:T??void 0,onClose:M,onTraceClick:N,onSpanClick:P,onPrevious:D,onNext:O}),(0,K.jsx)(Thi,{depth:2,traceId:T?n.featuredTraceId??void 0:void 0,spans:k?.spans,isLoadingSpans:A,selectedSpanId:n.featuredSpanId??null,onSpanSelect:I,onClose:F})]})}function kCi(){let e=X();return Gv({queryKey:[`builtin-mcp-server`],queryFn:()=>e.getBuiltinMcpServer(),retry:!1})}var ACi=`<your-token>`;function jCi(e){return`'${e.replaceAll(`'`,`'\\''`)}'`}function MCi(e,{protectedServer:t}){let n=jCi(e),r=`Authorization: Bearer ${ACi}`,i=t?{headers:{Authorization:`Bearer ${ACi}`}}:{};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 NCi=`https://mastra.ai/docs/server/mcp`;function PCi(){let{data:e,error:t}=kCi();return e?(0,K.jsx)(FCi,{descriptor:e}):!t||Ej(t)||Dj(t)||Oj(t)?null:(0,K.jsx)(ICi,{children:(0,K.jsx)(NE,{variant:`destructive`,children:`Couldn't load the built-in MCP server. Try reloading the page.`})})}function FCi({descriptor:e}){return(0,K.jsx)(ICi,{status:(0,K.jsx)(LCi,{descriptor:e}),children:e.enabled?e.mcpPackageInstalled?(0,K.jsx)(VCi,{descriptor:e}):(0,K.jsx)(BCi,{}):(0,K.jsx)(zCi,{descriptor:e})})}function ICi({status:e,children:t}){return(0,K.jsxs)(AF,{role:`region`,"aria-label":`Mastra (built-in) MCP server`,children:[(0,K.jsxs)(jF,{className:`flex-row flex-wrap items-center gap-3 space-y-0 border-b border-border`,children:[(0,K.jsx)(MF,{className:`shrink-0`,children:`Mastra (built-in)`}),e]}),(0,K.jsx)(PF,{className:`flex flex-col gap-4`,children:t})]})}function LCi({descriptor:e}){let{label:t,variant:n}=RCi(e);return(0,K.jsx)(dx,{variant:n,emphasis:`subtle`,indicator:`dot`,children:t})}function RCi(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 zCi({descriptor:e}){return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(W,{tone:`muted`,children:e.disabledReason===`config`?(0,K.jsxs)(K.Fragment,{children:[`The built-in MCP server is turned off because `,(0,K.jsx)(cP,{children:`server.mcp.enabled`}),` is`,` `,(0,K.jsx)(cP,{children:`false`}),`.`]}):(0,K.jsxs)(K.Fragment,{children:[`The built-in MCP server only runs under `,(0,K.jsx)(cP,{children:`mastra dev`}),` unless the server has auth. Configure `,(0,K.jsx)(cP,{children:`server.auth`}),`, or set `,(0,K.jsx)(cP,{children:`server.mcp.enabled`}),` to`,` `,(0,K.jsx)(cP,{children:`true`}),`.`]})}),(0,K.jsx)(UCi,{})]})}function BCi(){return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(W,{tone:`muted`,children:[`The built-in MCP server is enabled, but it needs the `,(0,K.jsx)(cP,{children:`@mastra/mcp`}),` package. Install it and restart the server.`]}),(0,K.jsx)(bP,{code:`npm install @mastra/mcp`,lang:`bash`,copyTooltip:`Copy install command`}),(0,K.jsx)(UCi,{})]})}function VCi({descriptor:e}){let t=`${(X().options.baseUrl||window.location.origin).replace(/\/$/,``)}${e.path}`,n=MCi(t,{protectedServer:e.auth.type===`protected`}),[r,i]=(0,G.useState)(n[0].value),a=n.find(e=>e.value===r)??n[0];return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,K.jsx)(W,{as:`span`,variant:`label`,tone:`muted`,children:`Endpoint`}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-lg bg-muted py-2 pr-2 pl-3`,children:[(0,K.jsx)(W,{as:`span`,font:`mono`,className:`min-w-0 break-all`,children:t}),(0,K.jsx)(Gn,{tooltip:`Copy MCP endpoint URL`,content:t})]})]}),(0,K.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,K.jsx)(W,{as:`span`,variant:`label`,tone:`muted`,children:`Toolsets`}),(0,K.jsxs)(`ul`,{className:`flex flex-wrap gap-2`,"aria-label":`Toolsets`,children:[e.toolsets.map(e=>(0,K.jsx)(`li`,{children:(0,K.jsx)(dx,{variant:`neutral`,emphasis:`subtle`,children:HCi(e)})},e)),e.readOnly&&(0,K.jsx)(`li`,{children:(0,K.jsx)(dx,{variant:`info`,emphasis:`subtle`,children:`Read-only`})})]})]}),(0,K.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,K.jsx)(W,{as:`span`,variant:`label`,tone:`muted`,children:`Connect a client`}),(0,K.jsx)(bP,{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,K.jsx)(W,{variant:`body-sm`,tone:`muted`,children:`Tools are listed per caller, so connect a client to see the tools your token can use.`})]})]})}function HCi(e){let t=e.replaceAll(`_`,` `);return t.charAt(0).toUpperCase()+t.slice(1)}function UCi(){return(0,K.jsx)(`div`,{children:(0,K.jsx)(U,{variant:`ghost`,render:(0,K.jsx)(`a`,{href:NCi,target:`_blank`,rel:`noopener noreferrer`}),icon:(0,K.jsx)(qM,{}),children:`MCP server docs`})})}var WCi={name:e=>e.name||e.id};function GCi({server:e,rowProps:t}){let{paths:n,Link:r}=xa(),i=X().options.baseUrl,a=e.transports?.includes(`sse`)??!0?`sse`:`mcp`,o=i?`${i}/api/mcp/${e.id}/${a}`:``,{data:s}=_2t({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=qA(e.name,50);return(0,K.jsxs)(Z.RowLink,{to:n.mcpServerLink(e.id),LinkComponent:r,...t,children:[(0,K.jsx)(Z.NameCell,{children:f}),(0,K.jsx)(Z.DescriptionCell,{children:o}),(0,K.jsx)(Z.TextCell,{className:`text-center`,children:u||``}),(0,K.jsx)(Z.TextCell,{className:`text-center`,children:l||``}),(0,K.jsx)(Z.TextCell,{className:`text-center`,children:d||``})]})}function KCi({mcpServers:e,isLoading:t,search:n=``,sort:r,onSortChange:i}){let a=(0,G.useMemo)(()=>{let t=n.toLowerCase();return k4(e.filter(e=>e.name?.toLowerCase().includes(t)||e.id?.toLowerCase().includes(t)),r,WCi)},[e,n,r]),{containerRef:o,getRowProps:s}=PM({count:a.length,global:!0});return t?(0,K.jsx)(UM,{columns:`auto 1fr auto auto auto`}):(0,K.jsxs)(Z,{columns:`auto 1fr auto auto auto`,scrollRef:o,children:[(0,K.jsxs)(Z.Top,{children:[i?(0,K.jsx)(Z.SortableTopCell,{sortKey:`name`,sort:r?.key===`name`?r.direction:void 0,onSortChange:i,children:`Name`}):(0,K.jsx)(Z.TopCell,{children:`Name`}),(0,K.jsx)(Z.TopCell,{children:`URL`}),(0,K.jsx)(Z.TopCellSmart,{long:`Agents`,short:(0,K.jsx)(FM,{}),tooltip:`Agent tools`,className:`text-center`}),(0,K.jsx)(Z.TopCellSmart,{long:`Tools`,short:(0,K.jsx)(HM,{}),tooltip:`Tools`,className:`text-center`}),(0,K.jsx)(Z.TopCellSmart,{long:`Workflows`,short:(0,K.jsx)(cx,{}),tooltip:`Workflow tools`,className:`text-center`})]}),a.length===0&&n?(0,K.jsx)(Z.NoMatch,{message:`No MCP Servers match your search`}):null,a.map((e,t)=>(0,K.jsx)(GCi,{server:e,rowProps:s(t)},e.id))]})}var qCi=()=>(0,K.jsx)(db,{titleSlot:`No MCP Servers yet`,descriptionSlot:(0,K.jsxs)(K.Fragment,{children:[`MCP servers are not configured yet. `,(0,K.jsx)(`br`,{}),`More information in the documentation.`]}),actionSlot:(0,K.jsx)(U,{variant:`ghost`,render:(0,K.jsx)(`a`,{href:`https://mastra.ai/docs/tools-mcp/mcp-overview`,target:`_blank`,rel:`noopener noreferrer`}),icon:(0,K.jsx)(qM,{}),children:`MCP documentation`}),variant:`fill`}),d9=[vI(`/mcps`)],JCi=()=>{let{data:e=[],isLoading:t,error:n}=pI(),[r,i]=(0,G.useState)(``),[a,o]=(0,G.useState)();return n&&Ej(n)?(0,K.jsxs)(Xb,{variant:`page`,breadcrumbs:(0,K.jsx)(IA,{crumbs:d9}),children:[(0,K.jsx)(`h1`,{className:`sr-only`,children:`MCP Servers`}),(0,K.jsx)(oI,{variant:`fill`})]}):n&&Dj(n)?(0,K.jsxs)(Xb,{variant:`page`,breadcrumbs:(0,K.jsx)(IA,{crumbs:d9}),children:[(0,K.jsx)(`h1`,{className:`sr-only`,children:`MCP Servers`}),(0,K.jsx)(aI,{variant:`fill`,resource:`MCP servers`})]}):n?(0,K.jsxs)(Xb,{variant:`page`,breadcrumbs:(0,K.jsx)(IA,{crumbs:d9}),children:[(0,K.jsx)(`h1`,{className:`sr-only`,children:`MCP Servers`}),(0,K.jsx)(db,{tone:`error`,variant:`fill`,titleSlot:`Failed to load MCP servers`,descriptionSlot:n.message})]}):e.length===0&&!t?(0,K.jsxs)(Xb,{variant:`page`,breadcrumbs:(0,K.jsx)(IA,{crumbs:d9}),children:[(0,K.jsx)(`h1`,{className:`sr-only`,children:`MCP Servers`}),(0,K.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,K.jsx)(PCi,{}),(0,K.jsx)(qCi,{})]})]}):(0,K.jsxs)(Xb,{variant:`page`,breadcrumbs:(0,K.jsx)(IA,{crumbs:d9}),actionRow:(0,K.jsx)(_M,{children:(0,K.jsx)(_M.Start,{children:(0,K.jsx)(`div`,{className:`max-w-120 flex-1`,children:(0,K.jsx)($A,{...ej,onValueChange:i,label:`Search MCP servers`,placeholder:`Search by name`})})})}),children:[(0,K.jsx)(`h1`,{className:`sr-only`,children:`MCP Servers`}),(0,K.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,K.jsx)(PCi,{}),(0,K.jsx)(KCi,{mcpServers:e,isLoading:t,search:r,sort:a,onSortChange:(e,t)=>o({key:t,direction:e})})]})]})};function YCi(){let[e,t]=nb();return{eventName:e.get(`event`)??void 0,close:()=>t(e=>{let t=new URLSearchParams(e);return t.delete(`event`),t},{replace:!0})}}var XCi=e=>`?${new URLSearchParams({event:e}).toString()}`;function ZCi(e,{enabled:t=!0}={}){let n=X();return Gv({queryKey:[`mcp-server-events`,e],queryFn:()=>n.getMcpServerEvents(e),enabled:t})}function QCi(e,t){let n=X();return qv({mutationFn:r=>n.emitMcpServerEvent(e,t,r)})}function f9(e){if(e instanceof um&&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 $Ci={push:`blue`,poll:`neutral`,webhook:`purple`};function ewi({delivery:e}){return(0,K.jsx)(`span`,{className:`flex flex-wrap items-center gap-1`,children:e.map(e=>(0,K.jsx)(dx,{size:`xs`,variant:$Ci[e],emphasis:`subtle`,children:e},e))})}var twi=0,nwi=()=>`feed-${twi++}`;function rwi(e,t){return[...t,...e].slice(0,200)}function iwi(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:rwi(e.items,[{kind:`gap`,key:nwi()}])};case`occurrences`:{let n=[...t.occurrences].reverse().map(e=>({kind:`occurrence`,key:nwi(),occurrence:e}));return{...e,items:rwi(e.items,n)}}case`warning`:return{...e,warning:t.message};case`error`:return{...e,status:`error`,error:t.message}}}var awi={status:`idle`,items:[]};function owi(e,t){let n=X(),[r,i]=(0,G.useReducer)(iwi,awi),a=(0,G.useRef)(void 0),o=(0,G.useRef)(void 0),s=e=>{e&&(o.current=e),i({type:`cursor`,cursor:e})};(0,G.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:f9(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:f9(e)})}};return{...r,start:l,stop:c,pollOnce:u}}function p9(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function swi(e){return e.map(e=>JSON.stringify(e)).join(` | `)}function cwi(e){return e.map(m9).join(` | `)}function m9(e){return p9(e)?Array.isArray(e.enum)?swi(e.enum):`const`in e?JSON.stringify(e.const):Array.isArray(e.anyOf)?cwi(e.anyOf):Array.isArray(e.oneOf)?cwi(e.oneOf):Array.isArray(e.type)?e.type.join(` | `):e.type===`array`?`${m9(e.items)}[]`:dwi(e)?`Record<string, ${m9(e.additionalProperties)}>`:typeof e.type==`string`?e.type:`unknown`:`unknown`}function lwi(e,t,n,{defaultsAreOptional:r=!1}){let i=p9(t)?t:{},a=`default`in i;return{name:e,type:m9(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 uwi(e,t={}){if(!p9(e)||!p9(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])=>lwi(e,r,n,t))}function dwi(e){return p9(e)&&e.type===`object`&&!p9(e.properties)&&p9(e.additionalProperties)}function fwi(e){return p9(e)&&(e.type===`object`||p9(e.properties))}var pwi=[`type`,`properties`,`items`,`enum`,`const`,`anyOf`,`oneOf`,`allOf`,`$ref`];function mwi(e){return!p9(e)||!pwi.some(t=>t in e)}function h9(e){return p9(e)?XT(e):Y({})}function hwi({inputSchema:e,onChange:t}){return mwi(e)?(0,K.jsx)(W,{tone:`muted`,children:`This event takes no arguments.`}):(0,K.jsx)(dA,{schema:h9(e),onValuesChange:e=>t(e??{})})}function gwi({occurrence:e}){return(0,K.jsx)(AF,{children:(0,K.jsxs)(Ax,{children:[(0,K.jsxs)(jx,{className:`flex w-full cursor-pointer items-center gap-2 px-3 py-2 text-left`,children:[(0,K.jsx)(Gr,{direction:`right`,className:`size-4 shrink-0`}),(0,K.jsx)(W,{as:`span`,variant:`caption`,font:`mono`,className:`min-w-0 flex-1 truncate`,children:e.eventId}),e.eventId.startsWith(`mastra-test-`)&&(0,K.jsx)(dx,{size:`xs`,variant:`amber`,emphasis:`subtle`,children:`test`}),(0,K.jsx)(W,{as:`span`,variant:`caption`,font:`mono`,tone:`muted`,className:`shrink-0`,children:e.timestamp})]}),(0,K.jsx)(Mx,{children:(0,K.jsx)(fr,{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 _wi=`Gap: events may have been skipped`;function vwi({items:e}){return e.length===0?(0,K.jsx)(db,{iconSlot:(0,K.jsx)(o6,{}),titleSlot:`No events yet`,descriptionSlot:`Start listening or poll to see occurrences here.`}):(0,K.jsx)(`ol`,{"aria-label":`Occurrences`,className:`grid grid-cols-1 gap-2`,children:e.map(e=>(0,K.jsx)(`li`,{children:e.kind===`gap`?(0,K.jsx)(NE,{variant:`warning`,children:_wi}):(0,K.jsx)(gwi,{occurrence:e.occurrence})},e.key))})}var ywi={idle:`Not listening`,connecting:`Connecting…`,polling:`Polling…`,polled:`Polled`,stopped:`Stopped`,error:`Failed`};function bwi({status:e,canStream:t}){if(e===`live`)return(0,K.jsx)(dx,{variant:`green`,indicator:`pulse`,size:`sm`,children:`Listening`});let n=e===`idle`&&!t?`Not polled yet`:ywi[e];return(0,K.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(e===`connecting`||e===`polling`)&&(0,K.jsx)(pt,{size:`sm`}),(0,K.jsx)(W,{as:`span`,tone:`muted`,children:n})]})}function xwi({status:e,canStream:t,cursor:n}){return(0,K.jsxs)(`div`,{role:`status`,className:`flex min-w-0 flex-wrap items-center gap-3`,children:[(0,K.jsx)(bwi,{status:e,canStream:t}),n&&(0,K.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1`,children:[(0,K.jsx)(W,{as:`span`,variant:`caption`,tone:`muted`,children:`Cursor`}),(0,K.jsx)(W,{as:`span`,variant:`caption`,font:`mono`,className:`min-w-0 truncate`,children:n}),(0,K.jsx)(Gn,{tooltip:`Copy cursor`,content:n})]})]})}function Swi({serverId:e,event:t,onEmitted:n}){let{mutateAsync:r,isPending:i,isSuccess:a,error:o}=QCi(e,t.name);return(0,K.jsxs)(`section`,{"aria-label":`Send test event`,className:`grid grid-cols-1 gap-3`,children:[(0,K.jsx)(W,{as:`h3`,variant:`subheading`,children:`Send test event`}),(0,K.jsx)(dA,{schema:h9(t.payloadSchema),onSubmit:async e=>{try{await r(e??{}),n?.()}catch{}},isSubmitLoading:i,submitButtonLabel:`Send test event`}),a&&!o&&(0,K.jsx)(W,{tone:`muted`,children:`Test event sent.`}),o&&(0,K.jsx)(NE,{variant:`destructive`,children:f9(o)})]})}function Cwi({serverId:e,event:t,testEmit:n,canEmit:r}){let[i,a]=(0,G.useState)({}),o=owi(e,t.name),s=t.delivery.includes(`push`),c=o.status===`connecting`||o.status===`live`;return(0,K.jsxs)(`div`,{className:`grid grid-cols-1 content-start gap-6`,children:[(0,K.jsx)(hwi,{inputSchema:t.inputSchema,onChange:a}),(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,K.jsx)(xwi,{status:o.status,canStream:s,cursor:o.cursor}),s&&c&&(0,K.jsx)(U,{onClick:o.stop,children:`Stop`}),s&&!c&&(0,K.jsx)(U,{variant:`primary`,onClick:()=>void o.start(i),children:`Start`}),!s&&(0,K.jsx)(U,{variant:`primary`,disabled:o.status===`polling`,onClick:()=>void o.pollOnce(i),children:`Poll once`})]}),o.error&&(0,K.jsx)(NE,{variant:`destructive`,children:o.error}),o.warning&&(0,K.jsx)(NE,{variant:`warning`,children:o.warning}),n&&t.emittable&&r&&(0,K.jsx)(Swi,{serverId:e,event:t,onEmitted:s?void 0:()=>void o.pollOnce(i)}),(0,K.jsx)(vwi,{items:o.items})]})}function wwi({description:e}){let t=LF({collapsedHeight:140});return(0,K.jsx)(IF,{state:t,expandLabel:`Read more`,children:(0,K.jsx)(OF,{children:e})})}function Twi({description:e,overview:t,playground:n,canRun:r}){return(0,K.jsx)(K.Fragment,{children:(0,K.jsxs)(DE,{defaultTab:`overview`,className:`grid flex-1 grid-rows-[auto_1fr] gap-4 overflow-visible`,children:[(0,K.jsxs)(EE,{variant:`pill`,size:`sm`,children:[(0,K.jsx)(OE,{value:`overview`,children:`Overview`}),(0,K.jsx)(OE,{value:`playground`,disabled:!r,disabledTooltip:`You don't have permission to execute tools.`,children:`Playground`})]}),(0,K.jsxs)(kE,{value:`overview`,flush:!0,className:`content-start gap-6`,children:[e&&(0,K.jsx)(AF,{className:`p-4`,children:(0,K.jsx)(wwi,{description:e})}),t]}),(0,K.jsx)(kE,{value:`playground`,flush:!0,keepMounted:!0,className:`h-full`,children:r&&n})]})})}function g9(e){return(0,K.jsx)(EVr,{className:`min-h-control-md`,...e})}function Ewi(){return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`span`,{"aria-hidden":!0,className:`ml-0.5 text-destructive-indicator`,children:`*`}),(0,K.jsx)(`span`,{className:`sr-only`,children:` (required)`})]})}function Dwi({field:e}){return(0,K.jsxs)(K.Fragment,{children:[e.description,e.defaultValue!==void 0&&(0,K.jsxs)(`span`,{className:`block`,children:[`Default `,e.defaultValue]})]})}function Owi({field:e}){let t=!!e.description||e.defaultValue!==void 0;return(0,K.jsx)(v4,{title:(0,K.jsxs)(W,{as:`span`,variant:`body-sm`,font:`mono`,tone:`ink`,children:[e.name,e.required&&(0,K.jsx)(Ewi,{})]}),description:t?(0,K.jsx)(`span`,{className:`whitespace-normal`,children:(0,K.jsx)(Dwi,{field:e})}):void 0,children:(0,K.jsx)(W,{as:`span`,variant:`caption`,font:`mono`,tone:`muted`,children:e.type})})}function kwi({message:e}){return(0,K.jsx)(_4,{children:e})}function Awi({schema:e,emptyMessage:t,defaultsAreOptional:n}){if(mwi(e))return(0,K.jsx)(kwi,{message:t});if(!fwi(e)||dwi(e))return(0,K.jsx)(v4,{title:`Type`,children:(0,K.jsx)(W,{as:`span`,variant:`caption`,font:`mono`,tone:`muted`,children:m9(e)})});let r=uwi(e,{defaultsAreOptional:n});return r.length===0?(0,K.jsx)(kwi,{message:t}):r.map(e=>(0,K.jsx)(Owi,{field:e},e.name))}function _9({title:e,...t}){return(0,K.jsxs)(h4,{children:[(0,K.jsx)(g9,{children:(0,K.jsx)(g4,{children:e})}),(0,K.jsx)(Cj,{children:(0,K.jsx)(Awi,{...t})})]})}function jwi({serverId:e,eventName:t}){let{canExecute:n,canEdit:r}=Sb(),{data:i,isLoading:a}=ZCi(e),o=i?.events.find(e=>e.name===t);return a?(0,K.jsx)(uj.LoadingData,{}):!i||!o?(0,K.jsxs)(uj.NoData,{children:[`This server has no event "`,t,`".`]}):(0,K.jsx)(Twi,{description:o.description,overview:(0,K.jsxs)(`div`,{className:`grid grid-cols-1 gap-6`,children:[(0,K.jsx)(ewi,{delivery:o.delivery}),(0,K.jsx)(_9,{title:`Arguments`,schema:o.inputSchema,emptyMessage:`This event takes no arguments.`,defaultsAreOptional:!0}),(0,K.jsx)(_9,{title:`Payload`,schema:o.payloadSchema,emptyMessage:`No payload schema defined.`})]}),canRun:n(`mcp`),playground:(0,K.jsx)(Cwi,{serverId:e,event:o,testEmit:i.testEmit,canEmit:r(`mcp`)})})}function Mwi({serverId:e}){let{eventName:t,close:n}=YCi();return(0,K.jsxs)(uj,{open:t!==void 0,onClose:n,title:t??``,children:[(0,K.jsxs)(uj.Header,{children:[(0,K.jsxs)(uj.Heading,{children:[(0,K.jsx)(gr,{size:`sm`,className:`text-muted-foreground`,children:(0,K.jsx)(o6,{})}),(0,K.jsx)(`span`,{className:`truncate`,children:t})]}),(0,K.jsx)(uj.HeaderActions,{children:(0,K.jsx)(uj.CloseButton,{icon:`x`,tooltip:`Close event`,onClick:n})})]}),(0,K.jsx)(uj.Content,{className:`flex flex-col gap-4 px-3`,children:t&&(0,K.jsx)(jwi,{serverId:e,eventName:t},t)})]})}var Nwi=new Set([`completed`,`failed`,`cancelled`]),Pwi={working:`working`,input_required:`input required`,completed:`completed`,failed:`failed`,cancelled:`cancelled`},v9=e=>Nwi.has(e.status),Fwi=2e3,y9=e=>[`mcp-server-tasks`,e],Iwi=e=>!!e?.some(e=>!v9(e));function Lwi(e,t={}){let n=X();return Jv({queryKey:[...y9(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=>Iwi(e.tasks))?Fwi:!1})}function Rwi(e,{enabled:t=!0}={}){let n=X();return Gv({queryKey:[...y9(e),`surfaces`],queryFn:()=>n.getMcpServerTasks(e,{limit:1}),select:e=>e.surfaces,enabled:t})}function zwi(e,t){let n=X();return Gv({queryKey:[...y9(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&&!v9(e.state.data)?Fwi:!1})}function Bwi(e){let t=X();return qv({mutationFn:n=>t.findMcpServerTask(e,n)})}function Vwi(e){let t=X(),n=Av();return qv({mutationFn:n=>t.cancelMcpServerTask(e,n),onSettled:()=>n.invalidateQueries({queryKey:y9(e)})})}function Hwi(e){let t=X(),n=Av();return qv({mutationFn:({taskKey:n,inputResponses:r})=>t.answerMcpServerTaskInput(e,n,r),onSettled:()=>n.invalidateQueries({queryKey:y9(e)})})}function Uwi(){let[e,t]=nb();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 Wwi=(e,t=``)=>{let n=new URLSearchParams(t);return n.set(`task`,e),`?${n.toString()}`},b9=e=>`${e.slice(0,8)}…`,Gwi=new Set([`working`,`input_required`,`completed`,`failed`,`cancelled`]);function Kwi(){let[e,t]=nb(),n=e.get(`status`),r=e.get(`surface`),i=e.get(`client`);return{filters:{...n&&Gwi.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 qwi=e=>`${e.slice(0,8)}…`,Jwi={working:{variant:`info`,indicator:`pulse`},input_required:{variant:`warning`,indicator:`dot`},completed:{variant:`success`},failed:{variant:`destructive`},cancelled:{variant:`neutral`}};function Ywi({status:e}){let{variant:t,indicator:n}=Jwi[e];return(0,K.jsx)(dx,{size:`sm`,variant:t,emphasis:`subtle`,indicator:n,children:Pwi[e]})}function Xwi({serverId:e}){let{taskKey:t,close:n}=Uwi(),{data:r,isSuccess:i}=zwi(e,t);return(0,K.jsxs)(uj,{open:t!==void 0,onClose:n,title:r?.surface??`Task`,children:[(0,K.jsxs)(uj.Header,{children:[(0,K.jsxs)(uj.Heading,{children:[(0,K.jsx)(gr,{size:`sm`,className:`text-muted-foreground`,children:(0,K.jsx)(_Br,{})}),(0,K.jsx)(`span`,{className:`truncate`,children:r?`${r.surface} task`:`Task`})]}),(0,K.jsx)(uj.HeaderActions,{children:(0,K.jsx)(uj.CloseButton,{icon:`x`,tooltip:`Close task`,onClick:n})})]}),(0,K.jsx)(uj.Content,{className:`flex flex-col gap-4 px-3`,children:r?(0,K.jsx)(Zwi,{serverId:e,task:r},r.taskKey):i&&(0,K.jsx)(W,{tone:`muted`,children:`This task is no longer listed.`})})]})}function Zwi({serverId:e,task:t}){let n=Vwi(e),{canEdit:r,isLoading:i}=Sb(),a=!i&&r(`mcp`),o=Object.entries(t.inputRequests??{});return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(H4,{children:[(0,K.jsx)(H4.Key,{children:`Status`}),(0,K.jsx)(H4.Value,{children:(0,K.jsx)(Ywi,{status:t.status})}),t.statusMessage&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(H4.Key,{children:`Message`}),(0,K.jsx)(H4.Value,{children:t.statusMessage})]}),(0,K.jsx)(H4.Key,{children:`Created`}),(0,K.jsx)(H4.Value,{children:(0,K.jsx)(RE,{value:t.createdAt})}),(0,K.jsx)(H4.Key,{children:`Updated`}),(0,K.jsx)(H4.Value,{children:(0,K.jsx)(RE,{value:t.lastUpdatedAt})}),(0,K.jsx)(H4.Key,{children:`Expires`}),(0,K.jsx)(H4.Value,{children:t.expiresAt?(0,K.jsx)(RE,{value:t.expiresAt}):`never`}),(0,K.jsx)(H4.Key,{children:`Task key`}),(0,K.jsx)(H4.ValueWithCopyBtn,{copyValue:t.taskKey,copyTooltip:`Copy task key`,children:b9(t.taskKey)}),t.clientLabel&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(H4.Key,{children:`Client`}),(0,K.jsx)(H4.ValueWithCopyBtn,{copyValue:t.clientLabel,copyTooltip:`Copy client`,children:t.clientLabel})]}),(0,K.jsx)(H4.Key,{children:`Client key`}),(0,K.jsx)(H4.ValueWithCopyBtn,{copyValue:t.principalKey,copyTooltip:`Copy client key`,children:b9(t.principalKey)})]}),(0,K.jsx)(W,{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,K.jsx)($wi,{serverId:e,taskKey:t.taskKey,inputKey:n,request:r,canAnswer:a},n)),!v9(t)&&!i&&!a&&(0,K.jsx)(W,{tone:`muted`,variant:`caption`,children:`Cancelling or answering a task needs the mcp:write permission.`}),!v9(t)&&a&&(0,K.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,K.jsx)(U,{variant:`destructive-ghost`,className:`self-start`,loading:n.isPending,onClick:()=>n.mutate(t.taskKey),children:`Cancel task`}),n.error&&(0,K.jsx)(NE,{variant:`destructive`,children:eTi(n.error)})]}),t.result&&(0,K.jsx)(x9,{label:`Result`,value:t.result}),t.error&&(0,K.jsx)(x9,{label:`Error`,value:t.error})]})}var Qwi=Y({message:q().optional(),requestedSchema:ep(q(),Kf())});function $wi({serverId:e,taskKey:t,inputKey:n,request:r,canAnswer:i}){let a=Hwi(e),o=r.method===`elicitation/create`?Qwi.safeParse(r.params):void 0,s=e=>a.mutate({taskKey:t,inputResponses:{[n]:e}});return(0,K.jsxs)(`section`,{"aria-label":`Input request ${n}`,className:`flex flex-col gap-3`,children:[(0,K.jsx)(W,{as:`h3`,variant:`subheading`,children:`Input requested`}),o?.success&&!i?(0,K.jsxs)(K.Fragment,{children:[o.data.message&&(0,K.jsx)(W,{children:o.data.message}),(0,K.jsx)(x9,{label:`Request`,value:r})]}):o?.success?(0,K.jsxs)(K.Fragment,{children:[o.data.message&&(0,K.jsx)(W,{children:o.data.message}),(0,K.jsx)(dA,{schema:h9(o.data.requestedSchema),onSubmit:e=>s({action:`accept`,content:e??{}}),isSubmitLoading:a.isPending,submitButtonLabel:`Accept`,submitButtonVariant:`primary`,submitActions:(0,K.jsx)(U,{type:`button`,disabled:a.isPending,onClick:()=>s({action:`decline`}),children:`Decline`})})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(W,{tone:`muted`,children:[`Studio can't answer a `,r.method,` request; the client that started the task has to.`]}),(0,K.jsx)(x9,{label:`Request`,value:r})]}),a.error&&(0,K.jsx)(NE,{variant:`destructive`,children:eTi(a.error)})]})}function x9({label:e,value:t}){return(0,K.jsxs)(`section`,{className:`flex flex-col gap-2`,children:[(0,K.jsx)(W,{as:`h3`,variant:`subheading`,children:e}),(0,K.jsx)(fr,{value:JSON.stringify(t,null,2),language:`json`,editable:!1,lineNumbers:!1,"aria-label":`Task ${e.toLowerCase()}`})]})}function eTi(e){let t=f9(e);return t===`Task not found`?`The task is no longer waiting for this; the list has been refreshed.`:t}function tTi(e){if(!p9(e))return;if(p9(e.ui)&&typeof e.ui.resourceUri==`string`)return e.ui.resourceUri;let t=e[`ui/resourceUri`];return typeof t==`string`?t:void 0}function nTi(e){return p9(e)&&e.status===`suspended`}function rTi(e){return e<1e3?`${Math.round(e)} ms`:`${(e/1e3).toFixed(2)} s`}function iTi(e){return e===void 0?`undefined`:JSON.stringify(e,null,2)}function aTi(e){return e.status===`error`?e.error:iTi(e.output)}function oTi({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:sTi(n),durationMs:r}}}function sTi(e){return e instanceof Error?JSON.stringify({error:e.message},null,2):JSON.stringify({error:String(e)},null,2)}function cTi({zodInputSchema:e,isRunning:t,onRun:n,requestContextEntityType:r,requestContextEntityId:i}){let a=!oA(e),[o,s]=(0,G.useState)({view:`form`,value:void 0}),c=(0,G.useRef)(void 0),[l,u]=(0,G.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=nvt(o.value);if(!n.ok)return u([n.error]);let r=rvt(e,n.value);if(r)return u([r]);c.current=n.value,s({view:`form`,value:n.value})}function f(t){let r=ivt(e,t);r.ok?n(r.value):u(r.errors)}let p={isSubmitLoading:t,submitButtonLabel:`Run`,submitButtonIcon:(0,K.jsx)(Yw,{}),submitButtonVariant:`primary`};return(0,K.jsxs)(h4,{children:[(0,K.jsx)(g9,{action:(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(o4t,{entityType:r,entityId:i}),(0,K.jsx)(DE,{defaultTab:`form`,value:o.view,onValueChange:d,children:(0,K.jsxs)(EE,{size:`md`,children:[(0,K.jsxs)(OE,{value:`form`,disabled:t,children:[(0,K.jsx)(gr,{size:`sm`,children:(0,K.jsx)(wct,{})}),`Form`]}),(0,K.jsxs)(OE,{value:`json`,disabled:t,children:[(0,K.jsx)(gr,{size:`sm`,children:(0,K.jsx)(Qn,{})}),`JSON`]})]})})]}),children:(0,K.jsx)(g4,{children:`Request`})}),(0,K.jsx)(Cj,{children:(0,K.jsx)(`div`,{className:`p-4`,children:o.view===`json`?(0,K.jsxs)(`div`,{className:`grid gap-4`,children:[(0,K.jsxs)(gE,{invalid:l.length>0,children:[(0,K.jsx)(fr,{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,K.jsx)(bE,{children:l.map(e=>(0,K.jsx)(`span`,{className:`block`,children:e},e))})]}),(0,K.jsx)(BE,{...p,onSubmit:()=>f(o.value)})]}):(0,K.jsx)(dA,{...p,schema:e,defaultValues:o.value,onValuesChange:e=>{c.current=e},onSubmit:n,className:`gap-0`,children:!a&&(0,K.jsx)(W,{variant:`body-sm`,tone:`muted`,className:`pb-4`,children:`This tool takes no input. Run it as is.`})})})})]})}var lTi=_(`IconSend`,()=>(0,K.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 uTi({isRunning:e,lastRun:t}){return e?(0,K.jsx)(db,{iconSlot:(0,K.jsx)(pt,{}),titleSlot:`Running…`,descriptionSlot:`Waiting for the tool to respond.`}):t?t.status===`error`?(0,K.jsx)(yx,{code:aTi(t),className:`overflow-x-auto p-4 text-caption whitespace-pre`}):(0,K.jsx)(fr,{value:aTi(t),language:`json`,editable:!1,lineNumbers:!1,showCopyButton:!1,variant:`embedded`,"aria-label":`Tool response`,className:`p-4`}):(0,K.jsx)(db,{iconSlot:(0,K.jsx)(lTi,{}),titleSlot:`No response yet`,descriptionSlot:`Run the tool to see its output here.`})}function dTi({run:e}){return(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.status===`success`?(0,K.jsx)(dx,{variant:`success`,emphasis:`subtle`,indicator:`dot`,children:`Success`}):(0,K.jsx)(dx,{variant:`destructive`,emphasis:`subtle`,indicator:`dot`,children:`Error`}),(0,K.jsx)(W,{as:`span`,variant:`caption`,font:`mono`,tone:`muted`,children:rTi(e.durationMs)}),(0,K.jsx)(Gn,{content:aTi(e),copyMessage:`Response copied`,tooltip:`Copy response`,size:`icon-sm`})]})}function fTi({isRunning:e,lastRun:t}){return(0,K.jsxs)(h4,{className:`h-full`,children:[(0,K.jsx)(g9,{action:!e&&t&&(0,K.jsx)(dTi,{run:t}),children:(0,K.jsx)(g4,{children:`Response`})}),(0,K.jsx)(Cj,{className:T(`grid min-h-48 flex-1`,e||!t?`content-center`:`content-start`),children:(0,K.jsx)(uTi,{isRunning:e,lastRun:t})})]})}function pTi({zodInputSchema:e,execution:t,requestContextEntityType:n,requestContextEntityId:r}){let[i]=ex(n,r),[a,o]=(0,G.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,K.jsxs)(`div`,{className:`grid h-full grid-rows-[auto_1fr] gap-6`,children:[(0,K.jsx)(cTi,{zodInputSchema:e,isRunning:c,onRun:s,requestContextEntityType:n,requestContextEntityId:r}),(0,K.jsx)(fTi,{isRunning:c,lastRun:oTi(t,a)})]})}function mTi({serverId:e,tool:t}){let n=wcr(e),{mutateAsync:r,status:i,data:a,error:o}=g2t({serverId:e,toolId:t.name}),{data:s}=p2t({serverId:e,appResourceUri:tTi(t._meta)}),c=h9(t.inputSchema),l={execute:(e,t)=>r({data:e,requestContext:t}),status:i,output:a,error:o};return(0,K.jsxs)(`div`,{className:`grid content-start gap-6`,children:[s&&(0,K.jsx)(DOr,{html:s,toolName:t.name,onToolCall:n}),nTi(a)&&(0,K.jsxs)(NE,{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,K.jsx)(cP,{children:`inputRequests`}),` handler to finish the request.`]}),(0,K.jsx)(pTi,{zodInputSchema:c,execution:l,requestContextEntityType:`mcp-tool`,requestContextEntityId:`${e}:${t.name}`})]})}var hTi=(0,G.createContext)(void 0),gTi=hTi.Provider;function _Ti(){let e=(0,G.useContext)(hTi);if(e===void 0)throw Error(`useOpenToolId must be used inside ToolDrawer`);return e}function vTi({inputSchema:e,outputSchema:t,requestContextSchema:n,footer:r}){return(0,K.jsxs)(`div`,{className:`grid gap-6`,children:[(0,K.jsx)(_9,{title:`Input`,schema:e,emptyMessage:`This tool takes no input.`,defaultsAreOptional:!0}),(0,K.jsx)(_9,{title:`Output`,schema:t,emptyMessage:`No output schema defined.`}),n!==void 0&&(0,K.jsx)(_9,{title:`Request context`,schema:n,emptyMessage:`No request context fields.`,defaultsAreOptional:!0}),r]})}function yTi({serverId:e}){let t=_Ti(),{canExecute:n}=Sb(),{data:r,isLoading:i}=h2t({serverId:e,toolId:t});return i?(0,K.jsx)(uj.LoadingData,{}):r?(0,K.jsx)(Twi,{description:r.description,overview:(0,K.jsx)(vTi,{inputSchema:r.inputSchema}),canRun:n(`tools`),playground:(0,K.jsx)(mTi,{serverId:e,tool:r})}):(0,K.jsxs)(uj.NoData,{children:[`This server has no tool "`,t,`".`]})}var bTi=`auto 1fr auto`;function xTi({server:e}){let{data:t,isLoading:n,isError:r}=ZCi(e.id),i=t?.events??[],{Link:a}=xa(),{containerRef:o,getRowProps:s}=PM({count:i.length});return(0,K.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,K.jsx)(W,{as:`h2`,variant:`heading`,children:`Events`}),n&&(0,K.jsx)(UM,{columns:bTi}),r&&(0,K.jsx)(NE,{variant:`destructive`,children:`Could not load this server's events.`}),t&&(0,K.jsxs)(Z,{columns:bTi,scrollRef:o,children:[(0,K.jsxs)(Z.Top,{children:[(0,K.jsx)(Z.TopCell,{children:`Name`}),(0,K.jsx)(Z.TopCell,{children:`Description`}),(0,K.jsx)(Z.TopCell,{children:`Delivery`})]}),i.length===0&&(0,K.jsx)(Z.NoMatch,{message:`This server declares no events`}),i.map((t,n)=>(0,K.jsxs)(Z.RowLink,{to:`/mcps/${e.id}${XCi(t.name)}`,LinkComponent:a,...s(n),children:[(0,K.jsx)(Z.NameCell,{children:t.name}),(0,K.jsx)(Z.DescriptionCell,{children:t.description}),(0,K.jsx)(Z.TextCell,{children:(0,K.jsx)(ewi,{delivery:t.delivery})})]},t.name))]})]})}var STi=`minmax(0,1fr) auto auto auto auto auto auto auto`,CTi={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.`},wTi=[{id:`is`,label:`is`}],TTi=Object.entries(Pwi).map(([e,t])=>({value:e,label:t})),ETi=e=>e.stopPropagation(),DTi=e=>e.clientLabel??qwi(e.principalKey),OTi=e=>[`status`,`surface`,`client`].flatMap(t=>{let n=e[t];return n?[{id:t,fieldId:t,operatorId:`is`,value:n}]:[]}),kTi=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 ATi({server:e}){let{filters:t,setFilters:n}=Kwi(),{data:r,isLoading:i,isError:a,hasNextPage:o,fetchNextPage:s,isFetchingNextPage:c}=Lwi(e.id,t),{data:l=[]}=Rwi(e.id),u=(0,G.useMemo)(()=>r?.pages.flatMap(e=>e.tasks)??[],[r]),d=r?.pages[0]?.unavailable,{containerRef:f,getRowProps:p}=PM({count:u.length}),m=OTi(t).length>0,h=(0,G.useMemo)(()=>{let e=new Map(u.map(e=>[e.principalKey,DTi(e)]));return t.client&&!e.has(t.client)&&e.set(t.client,qwi(t.client)),[...e]},[u,t.client]),g=(0,G.useMemo)(()=>[{id:`status`,label:`Status`,icon:lP,color:Fj(`orange`),operators:[`is`],strict:!0,suggestions:TTi},{id:`surface`,label:`Surface`,icon:ox,color:Fj(`blue`),operators:[`is`],strict:!0,suggestions:l.map(e=>({value:e.name}))},{id:`client`,label:`Client`,icon:W2r,color:Fj(`purple`),operators:[`is`],suggestions:h.map(([e,t])=>({value:e,label:t}))}],[l,h]);return(0,K.jsxs)(`section`,{"aria-label":`Tasks`,className:`flex flex-col gap-3`,children:[(0,K.jsx)(W,{as:`h2`,variant:`heading`,children:`Tasks`}),a&&(0,K.jsx)(NE,{variant:`destructive`,children:`Could not load this server's tasks.`}),d&&(0,K.jsx)(NE,{variant:`info`,children:CTi[d]}),!d&&(0,K.jsxs)(_M,{children:[(0,K.jsx)(_M.Start,{children:(0,K.jsxs)(pM,{fields:g,operators:wTi,value:OTi(t),onValueChange:e=>n(kTi(e)),createItemId:e=>e,"aria-label":`Task filters`,className:`min-w-64 flex-1`,children:[(0,K.jsx)(pM.Chips,{}),(0,K.jsx)(pM.Input,{placeholder:`Filter tasks`})]})}),(0,K.jsx)(_M.End,{children:(0,K.jsx)(MTi,{serverId:e.id})})]}),i&&(0,K.jsx)(UM,{columns:STi}),r&&!d&&(0,K.jsxs)(Z,{columns:STi,scrollRef:f,children:[(0,K.jsxs)(Z.Top,{children:[(0,K.jsx)(Z.TopCell,{children:`Surface`}),(0,K.jsx)(Z.TopCell,{children:`Status`}),(0,K.jsx)(Z.TopCell,{children:`Created`}),(0,K.jsx)(Z.TopCell,{children:`Updated`}),(0,K.jsx)(Z.TopCell,{children:`Expires`}),(0,K.jsx)(Z.TopCell,{children:`Inputs`}),(0,K.jsx)(Z.TopCell,{children:`Key`}),(0,K.jsx)(Z.TopCell,{children:`Client`})]}),u.length===0&&(0,K.jsx)(Z.NoMatch,{message:m?`No tasks match these filters`:`No tasks yet`}),u.map((r,i)=>(0,K.jsx)(jTi,{serverId:e.id,task:r,rowProps:p(i),onFilterClient:()=>n({...t,client:r.principalKey})},r.taskKey))]}),o&&(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(U,{variant:`default`,size:`sm`,onClick:()=>s(),loading:c,children:`Load more`}),(0,K.jsxs)(W,{variant:`caption`,tone:`muted`,children:[`Showing the `,u.length,` most recent `,m?`matching `:``,`tasks.`]})]})]})}function jTi({serverId:e,task:t,rowProps:n,onFilterClient:r}){let{Link:i}=xa(),[a]=nb(),o=(0,G.useRef)(null);return(0,K.jsxs)(Z.RowWrapper,{...n,onSelectRow:()=>o.current?.click(),children:[(0,K.jsxs)(Z.RowLink,{ref:o,colEnd:-2,to:`/mcps/${e}${Wwi(t.taskKey,a)}`,LinkComponent:i,tabIndex:-1,onClick:ETi,"aria-label":`${t.surface} task ${b9(t.taskKey)}`,children:[(0,K.jsx)(Z.NameCell,{children:t.surface}),(0,K.jsx)(Z.Cell,{children:(0,K.jsx)(Ywi,{status:t.status})}),(0,K.jsx)(Z.CreatedCell,{timestamp:t.createdAt,preset:`day-time-seconds`}),(0,K.jsx)(Z.Cell,{className:`text-muted-foreground`,children:(0,K.jsx)(RE,{value:t.lastUpdatedAt})}),(0,K.jsx)(Z.Cell,{className:`text-muted-foreground`,children:t.expiresAt?(0,K.jsx)(RE,{value:t.expiresAt}):`never`}),(0,K.jsx)(Z.TextCell,{children:Object.keys(t.inputRequests??{}).length||`—`}),(0,K.jsx)(Z.TextCell,{font:`mono`,className:`text-muted-foreground`,children:b9(t.taskKey)})]}),(0,K.jsx)(Z.Cell,{className:`pr-2`,children:(0,K.jsx)(U,{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 ${DTi(t)}`,onClick:e=>{e.stopPropagation(),r()},children:DTi(t)})})]})}function MTi({serverId:e}){let[t,n]=(0,G.useState)(``),r=Bwi(e),{open:i}=Uwi();return(0,K.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,K.jsx)(ak,{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,K.jsx)(U,{type:`submit`,size:`sm`,variant:`default`,disabled:!t.trim(),loading:r.isPending,children:`Find`}),r.isError&&(0,K.jsx)(W,{variant:`caption`,role:`status`,className:`text-destructive-foreground`,children:`No task with that id.`})]})}var NTi={agent:FM,workflow:cx,tool:HM},PTi=`auto minmax(0, 1fr) auto`,FTi=`auto minmax(0, 1fr) auto auto`,ITi={tool:`Tool`,agent:`Agent`,workflow:`Workflow`};function LTi(e){return e in NTi}function RTi({type:e}){let t=LTi(e)?e:`tool`,n=NTi[t],r=ITi[t];return(0,K.jsxs)(jn,{children:[(0,K.jsx)(dr,{asChild:!0,children:(0,K.jsx)(`span`,{"aria-label":t,className:`inline-flex text-muted-foreground [&>svg]:size-icon-md`,children:(0,K.jsx)(n,{})})}),(0,K.jsx)(qt,{children:r})]})}var zTi=Y({ui:Y({resourceUri:q().optional()}).optional(),"ui/resourceUri":q().optional()});function BTi(e){let t=zTi.safeParse(e);return t.success?!!(t.data.ui?.resourceUri?.startsWith(`ui://`)||t.data[`ui/resourceUri`]?.startsWith(`ui://`)):!1}function VTi({surface:e}){return e?(0,K.jsxs)(jn,{children:[(0,K.jsx)(dr,{asChild:!0,children:(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,K.jsx)(dx,{size:`xs`,variant:e.mode===`always`?`info`:`neutral`,emphasis:`subtle`,children:e.mode}),e.required&&(0,K.jsx)(dx,{size:`xs`,variant:`warning`,emphasis:`subtle`,children:`required`}),e.recover&&(0,K.jsx)(dx,{size:`xs`,variant:`neutral`,emphasis:`subtle`,children:`recover`})]})}),(0,K.jsxs)(qt,{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 HTi({server:e}){let[t,n]=(0,G.useState)(``),{data:r={},isLoading:i}=_2t({selectedServer:e}),{Link:a,paths:o}=xa(),{data:s}=Rwi(e.id,{enabled:!!e.tasks_capability}),c=(0,G.useMemo)(()=>new Map(s?.map(e=>[e.name,e])),[s]),l=!!e.tasks_capability,u=l?FTi:PTi,d=(0,G.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}=PM({count:d.length});return(0,K.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,K.jsx)(W,{as:`h2`,variant:`heading`,children:`Available tools`}),(0,K.jsx)(`div`,{className:`max-w-120 flex-1`,children:(0,K.jsx)($A,{size:`sm`,debounceMs:300,className:`max-w-120`,onValueChange:n,label:`Search tools`,placeholder:`Search by name`})})]}),i?(0,K.jsx)(UM,{columns:u}):(0,K.jsxs)(Z,{columns:u,fit:`container`,scrollRef:f,children:[(0,K.jsxs)(Z.Top,{children:[(0,K.jsx)(Z.TopCell,{children:`Name`}),(0,K.jsx)(Z.TopCell,{children:`Description`}),(0,K.jsx)(Z.TopCell,{className:`justify-center text-center`,children:`Type`}),l&&(0,K.jsx)(Z.TopCell,{children:`Task`})]}),d.length===0&&t?(0,K.jsx)(Z.NoMatch,{message:`No tools match your search`}):null,d.map((t,n)=>(0,K.jsxs)(Z.RowLink,{to:o.mcpServerToolLink(e.id,t.name),LinkComponent:a,...p(n),children:[(0,K.jsx)(Z.NameCell,{children:(0,K.jsxs)(`span`,{className:`flex items-center gap-2`,children:[t.name,BTi(t._meta)&&(0,K.jsx)(dx,{size:`xs`,children:`App`})]})}),(0,K.jsx)(Z.DescriptionCell,{children:t.description}),(0,K.jsx)(Z.TextCell,{className:`justify-center text-center`,children:(0,K.jsx)(RTi,{type:t.toolType??`tool`})}),l&&(0,K.jsx)(Z.Cell,{children:(0,K.jsx)(VTi,{surface:c.get(t.name)})})]},t.name))]})]})}var UTi=({isLoading:e,server:t})=>{let[{sseUrl:n,httpStreamUrl:r},i]=(0,G.useState)({sseUrl:``,httpStreamUrl:``});if((0,G.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,K.jsx)(W,{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,K.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,K.jsx)(AF,{children:(0,K.jsxs)(DE,{defaultTab:`http`,children:[(0,K.jsxs)(jF,{className:`flex-row items-center justify-between gap-3 space-y-0 border-b border-border`,children:[(0,K.jsx)(MF,{className:`shrink-0`,children:`Connect`}),(0,K.jsx)(`div`,{className:`min-w-0`,children:(0,K.jsx)(EE,{variant:`pill-ghost`,size:`sm`,children:s.map(e=>(0,K.jsx)(OE,{value:e.value,children:e.label},e.value))})})]}),s.map(e=>(0,K.jsx)(kE,{value:e.value,flush:!0,children:(0,K.jsxs)(PF,{className:`flex flex-col gap-3`,children:[(0,K.jsx)(W,{tone:`muted`,children:e.description}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-lg bg-muted py-2 pr-2 pl-3`,children:[(0,K.jsx)(W,{as:`span`,font:`mono`,className:`min-w-0 break-all`,children:e.content}),(0,K.jsx)(Gn,{tooltip:e.tooltip,content:e.content})]})]})},e.value))]})}),(0,K.jsx)(HTi,{server:t}),t.tasks_capability&&(0,K.jsx)(ATi,{server:t}),t.events_capability&&(0,K.jsx)(xTi,{server:t})]})};function WTi(){let[e,t]=nb();return{toolId:e.get(`tool`)??void 0,close:()=>t(e=>{let t=new URLSearchParams(e);return t.delete(`tool`),t},{replace:!0})}}function GTi({children:e}){let{toolId:t,close:n}=WTi();return(0,K.jsxs)(uj,{open:t!==void 0,onClose:n,title:t??``,children:[(0,K.jsxs)(uj.Header,{children:[(0,K.jsxs)(uj.Heading,{children:[(0,K.jsx)(gr,{size:`sm`,className:`text-muted-foreground`,children:(0,K.jsx)(HM,{})}),(0,K.jsx)(`span`,{className:`truncate`,children:t})]}),(0,K.jsx)(uj.HeaderActions,{children:(0,K.jsx)(uj.CloseButton,{icon:`x`,tooltip:`Close tool`,onClick:n})})]}),(0,K.jsx)(uj.Content,{className:`flex flex-col gap-4 px-3`,children:t&&(0,K.jsx)(gTi,{value:t,children:e},t)})]})}var KTi=()=>{let{serverId:e}=Yy(),t=[vI(`/mcps`),X2t],{data:n=[],isLoading:r}=pI(),i=n.find(t=>t.id===e),a=i?.transports?.includes(`sse`)??!0,o=r||i?(0,K.jsxs)(Yb,{children:[(0,K.jsx)(Yb.Title,{isLoading:r,children:i?.name}),i&&(0,K.jsx)(Yb.Meta,{beside:!0,children:(0,K.jsxs)(dx,{size:`sm`,children:[`v`,i.version_detail.version]})}),i&&(0,K.jsx)(Yb.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,K.jsxs)(Xb,{variant:`page`,breadcrumbs:(0,K.jsx)(IA,{crumbs:t}),header:o,children:[(0,K.jsx)(UTi,{isLoading:r,server:i}),e&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(GTi,{children:(0,K.jsx)(yTi,{serverId:e})}),(0,K.jsx)(Mwi,{serverId:e}),(0,K.jsx)(Xwi,{serverId:e})]})]})},qTi=[{label:`Agent`,entityType:`agent`},{label:`Workflow`,entityType:`workflow_run`},{label:`Scorer`,entityType:`scorer`},{label:`Ingest`,entityType:`rag_ingestion`},{label:`Classifier`,entityType:`classifier`},{label:`MCP Server`,entityType:`mcp_server`}],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`},JTi=Object.keys(C9),YTi=`mastra:metrics:saved-filters`;function XTi(e){let t=uEi(e);try{localStorage.setItem(YTi,t.toString())}catch{}}function ZTi(){try{let e=localStorage.getItem(YTi);if(!e)return null;let t=new URLSearchParams(e);return t.toString()?t:null}catch{return null}}function QTi(e){if(e.has(`rootEntityType`))return!0;for(let t of JTi)if(e.has(C9[t]))return!0;return!1}var $Ti=`hasAll`,eEi=[{id:`is`,label:`is`},{id:$Ti,label:`has all of`,arity:`many`}],tEi={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`},nEi={provider:w6,model:kI},rEi=[`threadId`,`resourceId`,`userId`,`organizationId`,`runId`,`sessionId`,`requestId`,`experimentId`],iEi=e=>({id:e,label:tEi[e],icon:nEi[e]??r8(e),color:i8(e)}),aEi=(e,t)=>e.label.localeCompare(t.label);function oEi({availableTags:e,availableEntityNames:t,availableServiceNames:n,availableEnvironments:r}){let i=(e,t)=>({...iEi(e),operators:[`is`],strict:!0,suggestions:t}),a=e=>({...iEi(e),operators:[`is`]}),o=e=>e.map(e=>({value:e})),s=[i(`rootEntityType`,qTi.map(e=>({value:e.entityType,label:e.label}))),i(`entityName`,o(t)),{...i(`tags`,o(e)),operators:[$Ti]},i(`serviceName`,o(n)),i(`environment`,o(r))],c=rEi.map(a),l=[`provider`,`model`].map(e=>({...a(e),hidden:!0}));return[...s.toSorted(aEi),...c.toSorted(aEi),...l]}function sEi(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:$Ti,value:t}}let t=Array.isArray(e.value)?e.value[0]??``:e.value;return{id:e.fieldId,fieldId:e.fieldId,operatorId:`is`,value:pEi(t)?``:t}})}function cEi(e){return e.map(e=>({fieldId:e.fieldId,value:Array.isArray(e.value)?e.value.map(String):String(e.value)}))}function lEi(e){let t=[],n=new Map([[S9,`rootEntityType`]]);for(let e of JTi)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 uEi(e){let t=new URLSearchParams,n=e.getAll(S9);for(let e of n)t.append(S9,e);for(let n of JTi){let r=C9[n],i=e.getAll(r);for(let e of i)t.append(r,e)}return t}function dEi(e,t){e.delete(S9);for(let t of JTi)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 fEi=`Any`;function pEi(e){let t=e.trim();return t===``||t===fEi}var mEi=new Set(qTi.map(e=>e.entityType));function hEi(e){let t=e.trim();return mEi.has(t)?t:void 0}function gEi(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=>!pEi(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:hEi(e);n&&(t.rootEntityType=n)}else t[e]=r[0]}else if(typeof n.value==`string`){if(pEi(n.value))continue;let r=n.value.trim();if(e===`rootEntityType`){let e=hEi(r);e&&(t.rootEntityType=e)}else t[e]=r}}return t}var _Ei={first:0,normal:1,last:2},vEi=class extends Error{constructor(){super(`Skipped: nothing is waiting for this request any more`),this.name=`SkippedRequestError`}};function yEi(e){let t=0,n=[],r=()=>{t<e&&n.shift()?.start()};return{run(i,{priority:a=_Ei.normal,isWanted:o}={}){return new Promise((s,c)=>{let l=e=>{e&&o&&!o()?(c(new vEi),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 bEi=(0,G.createContext)(void 0);function xEi(){let e=(0,G.use)(bEi);if(!e)throw Error(`useAggregateLimiter must be used inside MetricsProvider or AggregateLimiterProvider`);return e}function SEi(e,t){let n=xEi(),r=Av();return({queryKey:i})=>n.run(e,{priority:t,isWanted:()=>(r.getQueryCache().find({queryKey:i,exact:!0})?.getObserversCount()??0)>0})}function CEi({children:e}){let t=(0,G.use)(bEi),[n]=(0,G.useState)(()=>t?void 0:yEi(3));return(0,K.jsx)(bEi,{value:t??n,children:e})}var wEi=864e5,TEi={"24h":wEi,"3d":2592e5,"7d":6048e5,"14d":12096e5,"30d":2592e6};function EEi(e,t,n){if(e!==`custom`){let t=TEi[e]??wEi;return{start:new Date(n-t),end:new Date(n)}}return{start:t?.from??new Date(n-wEi),end:t?.to??new Date(n)}}function DEi({datePreset:e,customRange:t,dimensionalFilter:n,dimensionalFilterKey:r}){let i=(0,G.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,G.useMemo)(()=>EEi(e,t,o),[e,t,o]);return{datePreset:e,customRange:t,timestamp:s,filters:(0,G.useMemo)(()=>({timestamp:s,...n}),[s,r]),dimensionalFilter:n,filterKey:(0,G.useMemo)(()=>`${a}|${r}`,[a,r])}}function OEi(e){let t=X(),{filters:n,filterKey:r,queryOptions:i}=e;return Gv({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 kEi(e){let t=X(),{filters:n,filterKey:r,queryOptions:i}=e;return Gv({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=>T6(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 AEi(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=T6(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 jEi(e){let t=X(),{filters:n,filterKey:r,queryOptions:i}=e;return Gv({queryKey:[`metrics`,`trace-volume`,r],queryFn:async()=>{let[e,r,i]=await Promise.all([AEi(t,`mastra_agent_duration_ms`,n),AEi(t,`mastra_workflow_duration_ms`,n),AEi(t,`mastra_tool_duration_ms`,n)]);return{agentData:e,workflowData:r,toolData:i}},...i})}var MEi=[{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`}],NEi=new Set(MEi.map(e=>e.value));function PEi(e){return typeof e==`string`&&(NEi.has(e)||e===`custom`)}var FEi=(0,G.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,G.useContext)(FEi)}function IEi(e,t){return e===`custom`?t?.from?t.to?`${Sx(t.from)} – ${Sx(t.to)}`:Sx(t.from)??``:`Custom range`:MEi.find(t=>t.value===e)?.label??e}var LEi=36e5;function REi(e,t){if(e!==`custom`)return`vs previous ${e}`;let n=t?.to?.getTime()??Date.now(),r=t?.from?.getTime()??n-24*LEi,i=Math.round((n-r)/LEi);return`vs previous ${i>24&&i%24==0?`${i/24}d`:`${i}h`}`}function zEi({children:e,preset:t,filterTokens:n,onPresetChange:r,onFilterTokensChange:i,customRange:a,onCustomRangeChange:o,scope:s}){let c=(0,G.useMemo)(()=>JSON.stringify(n),[n]),l=(0,G.useMemo)(()=>n,[c]),u=(0,G.useMemo)(()=>gEi(l),[l]),d=(0,G.useMemo)(()=>JSON.stringify(u),[u]),f=DEi({datePreset:t,customRange:a,dimensionalFilter:u,dimensionalFilterKey:d}),p=(0,G.useMemo)(()=>s??{},[s]),m=IEi(t,a),h=REi(t,a),g=(0,G.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,K.jsx)(FEi.Provider,{value:g,children:(0,K.jsx)(CEi,{children:e})})}var BEi=[`last-24h`,`last-3d`,`last-7d`,`last-14d`,`last-30d`,`custom`];function VEi(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 HEi(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 UEi=864e5;function WEi(){let{data:e}=G5(),t=e?.capabilities.traceRetentionDays;if(t===void 0)return;let n=new Date(Date.now()-t*UEi);return new Date(n.getFullYear(),n.getMonth(),n.getDate())}function GEi(){let{datePreset:e,setDatePreset:t,customRange:n,setCustomRange:r}=w9(),i=WEi();return(0,K.jsx)(lOt,{preset:VEi(e),onPresetChange:e=>t(HEi(e)),dateFrom:n?.from,dateTo:n?.to,onDateRangeChange:(e,t)=>r({from:e,to:t}),presets:BEi,minDate:i})}var KEi=G.forwardRef(({label:e,children:t,...n},r)=>(0,K.jsx)(U,{ref:r,variant:`ghost`,size:`icon-sm`,tooltip:e,"aria-label":e,...n,children:t}));KEi.displayName=`MetricsCardAction`;function qEi({children:e,className:t}){return(0,K.jsx)(`div`,{className:T(`-my-1 flex shrink-0 items-center gap-1 self-start`,t),children:e})}function JEi({children:e,className:t}){return(0,K.jsx)(`div`,{className:T(`overflow-x-auto overflow-y-hidden [&_tbody>tr:last-child]:border-b-0`,t),children:e})}function YEi({className:e,...t}){return(0,K.jsx)(U,{variant:`ghost`,size:`icon-sm`,className:T(`-my-1 shrink-0 cursor-grab active:cursor-grabbing`,e),...t,children:(0,K.jsx)(YM,{})})}function XEi({message:e=`Failed to load data`,className:t}){return(0,K.jsx)(`div`,{className:T(`flex flex-col items-center justify-center gap-3`,t),children:(0,K.jsx)(W,{variant:`caption`,className:`text-destructive-foreground`,children:e})})}function ZEi({label:e,value:t,change:n,isLoading:r=!1,className:i}){return(0,K.jsxs)(`div`,{className:T(`grid gap-1.5`,i),children:[(0,K.jsx)(`h3`,{className:`text-body-sm text-muted-foreground`,children:e}),(0,K.jsxs)(`span`,{className:`flex items-baseline gap-2`,children:[(0,K.jsx)(`span`,{className:T(`text-title text-foreground tabular-nums [text-box:trim-both_cap_alphabetic]`,r&&`relative min-w-24`),children:r?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`span`,{className:`invisible`,children:`0`}),(0,K.jsx)(Zb,{className:`absolute inset-0`})]}):t}),!r&&n&&(0,K.jsxs)(`span`,{className:`text-body-sm text-muted-foreground tabular-nums [text-box:trim-both_cap_alphabetic]`,children:[n,` vs previous`]})]})]})}function QEi({className:e}){return(0,K.jsx)(`div`,{className:T(`flex items-center justify-center`,e),children:(0,K.jsx)(pt,{size:`md`,variant:`pulse`,className:`text-subtle-foreground`})})}function $Ei({message:e=`No data yet`,className:t}){return(0,K.jsx)(`div`,{className:T(`flex h-full items-center justify-center`,t),children:(0,K.jsx)(W,{tone:`faint`,children:e})})}function eDi({children:e,className:t}){return(0,K.jsx)(AF,{className:T(`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 tDi({children:e,className:t,as:n=`h3`}){return(0,K.jsx)(n,{className:T(`text-subheading text-foreground`,t),children:e})}function nDi({title:e,value:t,onValueChange:n,options:r,className:i}){return(0,K.jsx)(`div`,{className:`flex min-w-0`,children:(0,K.jsxs)(TT,{modal:!1,children:[(0,K.jsxs)(TT.Trigger,{render:(0,K.jsx)(`button`,{type:`button`,className:T(`-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,K.jsx)(or,{className:`size-icon-sm text-muted-foreground`})]}),(0,K.jsx)(TT.Content,{align:`start`,children:(0,K.jsx)(TT.RadioOptions,{options:r,value:t,onValueChange:n,closeOnSelect:!0})})]})})}function rDi({children:e,className:t}){return(0,K.jsx)(`div`,{className:T(`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 iDi({children:e,className:t}){return(0,K.jsx)(`div`,{className:T(`flex items-start gap-4 [&>:first-child]:min-w-0 [&>:first-child]:flex-1`,t),children:e})}function aDi({value:e,isLoading:t=!1,className:n}){return(0,K.jsx)(`span`,{className:T(`order-last shrink-0 text-subheading text-foreground tabular-nums`,n),children:(0,K.jsx)(oDi,{value:e,isLoading:t})})}function oDi({value:e,isLoading:t}){return t?(0,K.jsx)(Qb,{line:`text-body`,className:`h-4 w-14`}):typeof e==`string`?e:(0,K.jsx)(`span`,{className:`inline-flex items-center gap-3`,children:e.map(e=>(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,K.jsx)(`span`,{"aria-hidden":!0,className:`size-2 shrink-0 rounded-[2px]`,style:{backgroundColor:e.color}}),(0,K.jsxs)(`span`,{className:`sr-only`,children:[e.label,` `]}),e.value]},e.label))})}var T9=Object.assign(eDi,{Root:eDi,Kpi:B4,TopBar:iDi,Toolbar:rDi,Actions:qEi,Action:KEi,DragHandle:YEi,Title:tDi,TitleMenu:nDi,Total:aDi,Headline:ZEi,Loading:QEi,Error:XEi,Content:JEi,NoData:$Ei}),sDi=`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 cDi({onClick:e}){return(0,K.jsx)(T9.Action,{label:`View in traces`,className:sDi,onClick:e,children:(0,K.jsx)(_I,{})})}function lDi({onClick:e}){return(0,K.jsx)(T9.Action,{label:`View errors in logs`,className:sDi,onClick:e,children:(0,K.jsx)(P2t,{})})}function E9({isEmpty:e=!1,emptyMessage:t=`No data in this range`,children:n}){return(0,K.jsxs)(`div`,{className:`relative flex min-h-0 flex-1 flex-col`,"data-chart-empty":e||void 0,children:[(0,K.jsx)(`div`,{className:T(`flex min-h-0 flex-1 flex-col`,e&&`invisible [&_.recharts-xAxis-tick-labels]:visible`),children:(0,K.jsx)(l5r.Provider,{value:e,children:n})}),e&&(0,K.jsx)(dDi,{message:t})]})}function uDi({className:e}){return(0,K.jsx)(`div`,{"aria-hidden":!0,className:T(`h-px bg-[linear-gradient(to_right,var(--border)_3px,transparent_3px)] bg-size-[6px_1px] opacity-50`,e)})}function dDi({message:e}){return(0,K.jsxs)(`div`,{className:`absolute inset-0 flex flex-col justify-between`,style:{paddingTop:j8.top,paddingBottom:22},children:[(0,K.jsx)(uDi,{}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(uDi,{className:`flex-1`}),(0,K.jsx)(W,{as:`span`,variant:`body-sm`,tone:`muted`,className:`max-w-[70%] text-center font-[450] text-balance`,children:e}),(0,K.jsx)(uDi,{className:`flex-1`})]}),(0,K.jsx)(uDi,{})]})}function D9({variant:e=`default`,title:t,href:n,LinkComponent:r,titleMenu:i,dragHandle:a,onTitleChange:o,total:s,change:c,isLoading:l=!1,actions:u,toolbar:d,isUpdating:f=!1,bodyHeight:p=`fixed`,className:m,children:h}){let g=T(`transition-opacity duration-200`,f&&`opacity-50`),_=e===`compact`,v=e===`hero`,y=!v&&p===`fixed`;return(0,K.jsxs)(T9,{className:T(`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`,_&&`h-84`,m),children:[(0,K.jsxs)(T9.TopBar,{children:[v?(0,K.jsx)(T9.Headline,{label:t,value:typeof s==`string`?s:`—`,change:c,isLoading:l,className:g}):(0,K.jsx)(pDi,{title:t,href:n,LinkComponent:r,titleMenu:i,dragHandle:a,onTitleChange:o}),u&&(0,K.jsx)(T9.Actions,{className:T(v&&`my-0 self-center`),children:u}),!v&&s!==void 0&&(0,K.jsx)(T9.Total,{value:s,isLoading:l,className:g})]}),(0,K.jsxs)(T9.Content,{className:T(`flex flex-col gap-4 overflow-visible`,_&&`min-h-0`),children:[d||y&&d!==void 0&&(0,K.jsx)(`div`,{"aria-hidden":!0,className:`min-h-6`}),(0,K.jsx)(`div`,{className:T(`relative flex min-h-0 min-w-0 flex-col`,fDi(e,p),g),children:h})]})]})}function fDi(e,t){if(e===`compact`)return`flex-1`;if(e!==`hero`)return t===`fit`?`min-h-60`:`min-h-60 flex-1`}function pDi({dragHandle:e,...t}){return e?(0,K.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5`,children:[(0,K.jsx)(T9.DragHandle,{...e}),(0,K.jsx)(mDi,{...t})]}):(0,K.jsx)(mDi,{...t})}function mDi({title:e,href:t,LinkComponent:n,titleMenu:r,onTitleChange:i}){return r?(0,K.jsx)(T9.TitleMenu,{title:e,...r}):t?(0,K.jsx)(`h3`,{className:`flex`,children:(0,K.jsx)(gDi,{href:t,LinkComponent:n,children:e})}):i?(0,K.jsx)(hDi,{title:e,onTitleChange:i}):(0,K.jsx)(T9.Title,{children:e})}function hDi({title:e,onTitleChange:t}){return(0,K.jsx)(`h3`,{className:`flex min-w-0`,children:(0,K.jsx)(`input`,{"aria-label":`Widget title`,defaultValue:e,...nD,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:T(`-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 gDi({href:e,LinkComponent:t,children:n}){return(0,K.jsxs)(t??`a`,{href:e,className:T(`-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,K.jsx)(FF,{"aria-hidden":!0,className:`size-icon-sm text-muted-foreground`})]})}function O9({error:e,onRetry:t}){return Ej(e)?(0,K.jsx)(oI,{}):Dj(e)?(0,K.jsx)(aI,{resource:`traces`}):(0,K.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-3`,children:[(0,K.jsx)(T9.Error,{message:`Couldn't load this data. Try again in a moment.`}),t&&(0,K.jsx)(U,{size:`sm`,icon:(0,K.jsx)(Ob,{}),onClick:t,children:`Retry`})]})}var _Di={2:`@3xl:grid-cols-2`,3:`@3xl:grid-cols-2 @7xl:grid-cols-3`},vDi={1:``,2:`@3xl:col-span-2`,full:`col-span-full`};function k9({children:e,columns:t=3,className:n}){return(0,K.jsx)(`div`,{className:T(`@container`,n),children:(0,K.jsx)(`div`,{className:T(`grid gap-4`,_Di[t]),children:e})})}function yDi({children:e,span:t=1,className:n}){return(0,K.jsx)(`div`,{className:T(`min-w-0 *:size-full *:min-w-0!`,vDi[t],n),children:e})}k9.Item=yDi;var bDi=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 xDi(e,t){if(t>=24)return Math.floor(e/bDi)*bDi;let n=new Date(e),r=Math.floor(n.getHours()/t)*t;return new Date(n.getFullYear(),n.getMonth(),n.getDate(),r).getTime()}function SDi(e,t){if(t>=24)return xDi(e,t)+bDi;let n=new Date(e);return xDi(new Date(n.getFullYear(),n.getMonth(),n.getDate(),n.getHours()+t).getTime(),t)}function CDi(e,t,n){let r=n8r(e,t),i=[];for(let a=xDi(e.getTime(),n);a<=t.getTime();a=SDi(a,n))i.push(a8r(a,n,r));return i}function wDi(e,t){let n=new Map(e.map((e,t)=>[e.ts,t]));return e=>n.get(xDi(new Date(e.timestamp).getTime(),t))}function M9(e,t){return{from:new Date(e),to:new Date(SDi(e,t))}}function N9(){let{datePreset:e,customRange:t,dimensionalFilter:n,dimensionalFilterKey:r,queryFilters:i}=w9(),a=DEi({datePreset:e,customRange:t,dimensionalFilter:n,dimensionalFilterKey:r});return i??a}var TDi={input:`mastra_model_total_input_tokens`,output:`mastra_model_total_output_tokens`,cacheRead:`mastra_model_input_cache_read_tokens`},EDi=`mastra_agent_duration_ms`;function DDi(){let e=X(),{filters:t,filterKey:n,timestamp:r}=N9(),{interval:i,stepHours:a}=A9(r.start,r.end);return Gv({queryKey:[`metrics`,`activity`,n,i],placeholderData:Lv,queryFn:async()=>{let n=n=>e.getMetricTimeSeries({name:[n],interval:i,aggregation:`sum`,filters:t}),[o,s,c,l]=await Promise.all([n(TDi.input),n(TDi.output),n(TDi.cacheRead),e.getMetricTimeSeries({name:[EDi],interval:i,aggregation:`count`,groupBy:[`status`],filters:t})]),u=CDi(r.start,r.end,a).map(e=>({...e,input:0,cacheRead:0,output:0,cost:0,completed:0,failed:0,failureRate:0})),d=wDi(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 ODi=[{dataKey:`input`,label:`Input`,color:T8.green},{dataKey:`cacheRead`,label:`Cache read`,color:T8.violet},{dataKey:`output`,label:`Output`,color:T8.sky}],kDi=[{dataKey:`cost`,label:`Cost`,color:T8.green}],ADi={tokens:`Token usage`,cost:`Model cost`},jDi=[{value:`tokens`,label:ADi.tokens},{value:`cost`,label:ADi.cost}];function MDi({onViewTraces:e,onTimeRangeClick:t}){let[n,r]=(0,G.useState)(`tokens`),{data:i=[],isLoading:a,isError:o,isPlaceholderData:s}=DDi(),{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?ODi:kDi,m={title:ADi[n],titleMenu:{value:n,onValueChange:r,options:jDi},actions:e&&(0,K.jsx)(cDi,{onClick:e}),toolbar:(0,K.jsx)(T9.Toolbar,{children:(0,K.jsx)(I8,{series:p})})};return o?(0,K.jsx)(D9,{...m,children:(0,K.jsx)(O9,{})}):(0,K.jsx)(D9,{...m,total:f?O8(u):A8(d),isLoading:a,isUpdating:s,children:(0,K.jsx)(E9,{isEmpty:!a&&u===0&&d===0,children:(0,K.jsx)(j7r,{data:i,series:p,height:`fill`,xLabels:`edges`,showLegend:!1,valueFormatter:f?O8:A8,axisFormatter:f?o5r:s5r,onBucketClick:t&&(e=>t(M9(Number(e.ts),l))),isLoading:a,...w8})})})}var NDi=[{dataKey:`failureRate`,label:`Failed runs`,color:T8.error}],PDi=e=>`${Math.round(e*100)}%`;function FDi({onViewErrors:e,onTimeRangeClick:t,titleMenu:n}){let{data:r=[],isLoading:i,isError:a,isPlaceholderData:o}=DDi(),{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,K.jsx)(lDi,{onClick:e}),toolbar:(0,K.jsx)(T9.Toolbar,{children:(0,K.jsx)(I8,{series:NDi})})};return a?(0,K.jsx)(D9,{...f,children:(0,K.jsx)(O9,{})}):(0,K.jsx)(D9,{...f,total:k8(l>0?u/l:0),isLoading:i,isUpdating:o,children:(0,K.jsx)(E9,{isEmpty:!i&&l===0,children:(0,K.jsx)(L8,{lineStyle:`thin`,data:r,series:NDi,height:`fill`,xLabels:`edges`,showLegend:!1,valueFormatter:k8,axisFormatter:PDi,yDomain:d,onBucketClick:t&&(e=>t(M9(Number(e.ts),c))),isLoading:i,...w8})})})}var IDi=[{dataKey:`completed`,label:`Completed`,color:T8.green},{dataKey:`failed`,label:`Failed`,color:T8.error}],LDi=[{value:`runs`,label:`Agent runs`},{value:`failure`,label:`Failure rate`}];function RDi({onTimeRangeClick:e,onFailureTimeRangeClick:t,onViewErrors:n}){let[r,i]=(0,G.useState)(`runs`),a={value:r,onValueChange:i,options:LDi};return r===`failure`?(0,K.jsx)(FDi,{titleMenu:a,onViewErrors:n,onTimeRangeClick:t}):(0,K.jsx)(zDi,{titleMenu:a,onTimeRangeClick:e})}function zDi({onTimeRangeClick:e,titleMenu:t}){let{data:n=[],isLoading:r,isError:i,isPlaceholderData:a}=DDi(),{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,K.jsx)(T9.Toolbar,{children:(0,K.jsx)(I8,{series:IDi})})};return i?(0,K.jsx)(D9,{...l,children:(0,K.jsx)(O9,{})}):(0,K.jsx)(D9,{...l,total:O8(c),isLoading:r,isUpdating:a,children:(0,K.jsx)(E9,{isEmpty:!r&&c===0,children:(0,K.jsx)(j7r,{data:n,series:IDi,height:`fill`,xLabels:`edges`,showLegend:!1,valueFormatter:O8,onBucketClick:e&&(t=>e(M9(Number(t.ts),s))),isLoading:r,...w8})})})}var BDi={.5:`p50`,.95:`p95`,.99:`p99`},VDi={agents:`mastra_agent_duration_ms`,workflows:`mastra_workflow_duration_ms`,tools:`mastra_tool_duration_ms`};function HDi(e){let t=X(),{filters:n,filterKey:r,timestamp:i}=N9(),{interval:a}=A9(i.start,i.end),o=j9(a);return Gv({queryKey:[`metrics`,`latency-percentiles`,e,r,a],placeholderData:Lv,queryFn:async()=>{let r=await t.getMetricPercentiles({name:VDi[e],percentiles:[.5,.95,.99],interval:a,filters:n}),s=CDi(i.start,i.end,o),c=wDi(s,o);for(let e of r.series){let t=BDi[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 UDi={agents:qm.AGENT,workflows:qm.WORKFLOW_RUN,tools:qm.TOOL},WDi=[{dataKey:`p50`,label:`P50`,color:T8.sky},{dataKey:`p95`,label:`P95`,color:T8.green,emphasis:!0},{dataKey:`p99`,label:`P99`,color:T8.violet}],GDi={agents:`Agent latency`,workflows:`Workflow latency`,tools:`Tool latency`},KDi=[{value:`agents`,label:GDi.agents},{value:`workflows`,label:GDi.workflows},{value:`tools`,label:GDi.tools}];function qDi({onViewTraces:e,onTimeRangeClick:t}){let[n,r]=(0,G.useState)(`agents`),{data:i=[],isLoading:a,isError:o,isPlaceholderData:s}=HDi(n),{timestamp:c}=N9(),l=j9(A9(c.start,c.end).interval),u=Math.max(0,...i.map(e=>e.p95??0)),d={title:GDi[n],titleMenu:{value:n,onValueChange:r,options:KDi},actions:e&&(0,K.jsx)(cDi,{onClick:()=>e(UDi[n])}),toolbar:(0,K.jsx)(T9.Toolbar,{children:(0,K.jsx)(I8,{series:WDi})})};return o?(0,K.jsx)(D9,{...d,children:(0,K.jsx)(O9,{})}):(0,K.jsx)(D9,{...d,total:a5r(u),isLoading:a,isUpdating:s,children:(0,K.jsx)(E9,{isEmpty:!a&&u===0,children:(0,K.jsx)(L8,{lineStyle:`thin`,data:i,series:WDi,height:`fill`,xLabels:`edges`,showLegend:!1,valueFormatter:a5r,axisFormatter:c5r,onBucketClick:t&&(e=>t(M9(Number(e.ts),l))),isLoading:a,...w8})})})}var JDi=`-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 YDi({row:e,columns:t,valueWidth:n,share:r,highlighted:i,dimmed:a,onHover:o,LinkComponent:s}){let c=T(JDi,i&&`bg-fill-subtle`,(e.href||e.onClick)&&`hover:bg-fill-subtle`);return(0,K.jsx)(`li`,{children:(0,K.jsxs)(XDi,{row:e,LinkComponent:s,className:c,style:{opacity:a?.5:1},onMouseEnter:o,children:[(0,K.jsx)(`span`,{className:`size-2 shrink-0 rounded-[2px]`,style:{backgroundColor:e.paint.color,opacity:e.paint.alpha}}),(0,K.jsx)(ZDi,{row:e}),t.map((t,n)=>(0,K.jsx)(`span`,{className:T(P9,`text-muted-foreground`,t.width??`w-16`),children:e.cells?.[n]},t.label)),(0,K.jsx)(`span`,{className:T(P9,`w-12 text-muted-foreground`),children:r}),(0,K.jsx)(`span`,{className:T(P9,`text-foreground`,n),children:e.value})]})})}function XDi({row:e,LinkComponent:t,...n}){return e.href?(0,K.jsx)(t??`a`,{href:e.href,...n}):e.onClick?(0,K.jsx)(`button`,{type:`button`,onClick:e.onClick,...n}):(0,K.jsx)(`div`,{...n})}function ZDi({row:e}){return typeof e.label==`string`?(0,K.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,title:e.title??e.label,children:(0,K.jsx)(W,{as:`span`,variant:`body-sm`,tone:`ink`,children:e.label})}):(0,K.jsx)(`span`,{className:`flex min-w-0 flex-1`,title:e.title,children:e.label})}var QDi=`var(--chart-share-1)`,$Di=[1,2,3,4,5].map(e=>`var(--chart-share-${e})`),eOi=[3,4,2,5,1].map(e=>`var(--chart-share-${e})`),tOi=[1,.7,.48,.32,.2,.14],nOi={color:`var(--chart-share-rest)`,alpha:1},rOi=50,iOi=`__rest`;function aOi(e,t,n){if(n===`hues`){let n=$Di.includes(e)?[e,...$Di.filter(t=>t!==e)]:[e,...eOi];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:tOi[n]??.1}))}var oOi=e=>e.reduce((e,t)=>e+Math.max(t.share,0),0);function sOi(e){return e.map(e=>Number.isFinite(e.share)&&e.share>0?e:{...e,share:0}).toSorted((e,t)=>t.share-e.share)}function cOi(e,{limit:t,other:n,color:r,palette:i}){if(e.length<=t+1){let t=lOi(e,r,i);return{shown:t,bar:t,rest:[]}}let a=e.slice(t),o=n?.(a),s={key:iOi,label:`Other (${a.length})`,share:oOi(a),value:o?.value,cells:o?.cells,paint:nOi,segment:iOi},c=lOi(e.slice(0,t),r,i);return{shown:[...c,s],bar:c,rest:a}}function lOi(e,t,n){let r=aOi(t,e.length,n);return e.map((e,t)=>({...e,paint:uOi(e)??r[t]??nOi,segment:e.key}))}var uOi=e=>e.color?{color:e.color,alpha:1}:void 0;function dOi(e,{count:t,color:n,palette:r}){let i=Math.min(t,e.length,rOi),a=lOi(e.slice(0,i),n,r),o=e.slice(i,t).map(e=>({...e,paint:nOi,segment:iOi}));return{shown:[...a,...o],bar:a,rest:e.slice(i)}}function fOi(e,t){let n=e.map(e=>({key:e.key,share:e.share,paint:e.paint})),r=t.length?[{key:iOi,share:oOi(t),paint:nOi}]:[],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 pOi(e,t){if(t!==void 0)return e.find(e=>e.key===t)?.segment??t}var mOi=(e,t)=>t!==void 0&&t!==e;function hOi(e,t){return t===void 0||t===e.key?!1:t!==`__rest`||e.segment!==`__rest`}var gOi=(e,t)=>{let n=e/(t||1);return n>0?n<.001?`<0.1%`:`${(n*100).toFixed(+(n<.1))}%`:`0%`};function _Oi({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,K.jsxs)(`li`,{className:`-mx-2 flex items-center gap-1`,children:[o>0&&(0,K.jsxs)(`button`,{type:`button`,onClick:i,className:s,children:[(0,K.jsx)(or,{className:`size-icon-sm shrink-0`}),`Show `,Math.min(o,r),` more`]}),e>n&&(0,K.jsxs)(`button`,{type:`button`,onClick:a,className:s,children:[(0,K.jsx)(q2,{className:`size-icon-sm shrink-0`}),`Show top `,n]}),o>0&&(0,K.jsxs)(`span`,{className:`ml-auto pr-2 text-body-sm text-subtle-foreground tabular-nums`,children:[c.format(e),` of `,c.format(t)]})]})}var vOi=[`w-32`,`w-24`,`w-36`,`w-20`,`w-28`];function yOi({className:e}){return(0,K.jsxs)(K.Fragment,{children:[`​`,(0,K.jsx)(Zb,{className:T(`absolute top-1/2 h-3.5 -translate-y-1/2`,e)})]})}function bOi({rows:e,columns:t,valueWidth:n,header:r}){return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`flex h-2`,children:(0,K.jsx)(Zb,{className:`size-full rounded-full`})}),r,(0,K.jsx)(`ul`,{className:`grid min-w-0 grid-cols-1 gap-0.5`,"aria-busy":!0,children:Array.from({length:e},(e,r)=>(0,K.jsxs)(`li`,{className:JDi,children:[(0,K.jsx)(Zb,{className:`size-2 shrink-0 rounded-[2px]`}),(0,K.jsx)(`span`,{className:`min-w-0 flex-1`,children:(0,K.jsx)(W,{as:`span`,variant:`body-sm`,className:`relative`,children:(0,K.jsx)(yOi,{className:T(`left-0`,vOi[r%vOi.length])})})}),t.map(e=>(0,K.jsx)(`span`,{className:T(P9,`relative`,e.width??`w-16`),children:(0,K.jsx)(yOi,{className:`right-0 w-10`})},e.label)),(0,K.jsx)(`span`,{className:T(P9,`relative w-12`),children:(0,K.jsx)(yOi,{className:`right-0 w-9`})}),(0,K.jsx)(`span`,{className:T(P9,`relative`,n),children:(0,K.jsx)(yOi,{className:`right-0 w-12`})})]},r))})]})}function xOi({className:e,...t}){return(0,K.jsx)(`div`,{className:T(`grid grid-cols-1`,e),children:(0,K.jsx)(SOi,{...t})})}function SOi({rows:e,columns:t=[],valueLabel:n,valueWidth:r=`w-14`,palette:i=`shades`,color:a=QDi,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,G.useState)(),[h,g]=(0,G.useState)(0),_=o+h*c,v=(0,K.jsx)(COi,{columns:t,valueLabel:n,valueWidth:r});if(d)return(0,K.jsx)(bOi,{rows:s===`other`?o+1:o,columns:t,valueWidth:r,header:v});let y=sOi(e);if(y.length===0)return(0,K.jsx)(W,{variant:`body-sm`,tone:`muted`,className:`py-6 text-center`,children:u});let b=oOi(y),x=s===`more`,{shown:S,bar:C,rest:w}=x?dOi(y,{count:_,color:a,palette:i}):cOi(y,{limit:o,other:l,color:a,palette:i}),T=fOi(C,w),E=pOi(S,p),D=()=>m(void 0);return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`flex h-2 gap-0.5`,onMouseLeave:D,children:T.map(e=>(0,K.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*(mOi(e.key,E)?.3:1)}},e.key))}),v,(0,K.jsxs)(`ul`,{className:`grid min-w-0 grid-cols-1 gap-0.5`,onMouseLeave:D,children:[S.map(e=>(0,K.jsx)(YDi,{row:e,columns:t,valueWidth:r,share:gOi(e.share,b),highlighted:p===e.key,dimmed:hOi(e,p),onHover:()=>m(e.key),LinkComponent:f},e.key)),x&&(0,K.jsx)(_Oi,{shown:Math.min(_,y.length),total:y.length,limit:o,pageSize:c,onMore:()=>g(e=>e+1),onLess:()=>g(0)})]})]})}function COi({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,K.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,K.jsx)(`span`,{className:T(`shrink-0 text-right whitespace-nowrap`,e.width),children:e.label},e.label))})}var wOi={agents:qm.AGENT,workflows:qm.WORKFLOW_RUN,tools:qm.TOOL},TOi=[{label:`Error rate`}],EOi={agents:`Agent runs`,workflows:`Workflow runs`,tools:`Tool calls`},DOi=[{value:`agents`,label:EOi.agents},{value:`workflows`,label:EOi.workflows},{value:`tools`,label:EOi.tools}],OOi=(e,t)=>k8(t>0?e/t:0);function kOi({onViewTraces:e,onViewErrors:t,onEntityClick:n}){let[r,i]=(0,G.useState)(`agents`),a=wOi[r],o=jEi({...N9(),queryOptions:{placeholderData:Lv}}),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:O8(e.completed+e.errors),cells:[OOi(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:EOi[r],titleMenu:{value:r,onValueChange:i,options:DOi},actions:(e||t)&&(0,K.jsxs)(K.Fragment,{children:[e&&(0,K.jsx)(cDi,{onClick:()=>e(a)}),t&&(0,K.jsx)(lDi,{onClick:()=>t(a)})]})};return o.isError?(0,K.jsx)(D9,{...d,children:(0,K.jsx)(O9,{})}):(0,K.jsx)(D9,{...d,total:O8(u),isLoading:o.isLoading,isUpdating:o.isPlaceholderData,children:(0,K.jsx)(E9,{children:(0,K.jsx)(xOi,{rows:c,columns:TOi,valueLabel:`Runs`,color:T8.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:O8(n),cells:[OOi(t,n)]}},emptyState:`No runs in this range.`,isLoading:o.isLoading},r)})})}var AOi=[`mastra_model_total_input_tokens`,`mastra_model_total_output_tokens`],jOi=100;function MOi(e){let t=X(),{filters:n,filterKey:r}=N9();return Gv({queryKey:[`metrics`,`token-spend`,e,r],placeholderData:Lv,queryFn:async()=>{let{groups:r}=await t.getMetricBreakdown({name:AOi,groupBy:[e],aggregation:`sum`,orderDirection:`DESC`,limit:jOi,filters:n});return r.map(t=>({key:String(t.dimensions[e]??`unknown`),tokens:t.value,cost:t.estimatedCost??0}))}})}var NOi={agents:`Usage by agent`,models:`Usage by model`,threads:`Usage by thread`},POi=[{value:`agents`,label:NOi.agents},{value:`models`,label:NOi.models},{value:`threads`,label:NOi.threads}],FOi={placeholderData:Lv},IOi=[{label:`Tokens`}];function LOi(e){let[t,n]=(0,G.useState)(`agents`);return t===`models`?(0,K.jsx)(zOi,{...e,onViewChange:n}):t===`threads`?(0,K.jsx)(BOi,{...e,onViewChange:n}):(0,K.jsx)(ROi,{...e,onViewChange:n})}function ROi(e){let{onAgentClick:t}=e,{data:n=[],isLoading:r,isPlaceholderData:i,isError:a}=kEi({...N9(),queryOptions:FOi}),o=n.map(e=>({key:e.name,cost:e.cost??0,tokens:e.total,onClick:t&&(()=>t(e.name))}));return(0,K.jsx)(VOi,{view:`agents`,...e,rows:o,isLoading:r,isUpdating:i,isError:a})}function zOi(e){let{onModelClick:t}=e,{data:n=[],isLoading:r,isPlaceholderData:i,isError:a}=MOi(`model`),o=n.map(e=>({...e,onClick:t&&(()=>t(e.key))}));return(0,K.jsx)(VOi,{view:`models`,...e,rows:o,isLoading:r,isUpdating:i,isError:a})}function BOi(e){let{onThreadClick:t}=e,{data:n=[],isLoading:r,isPlaceholderData:i,isError:a}=MOi(`threadId`),o=n.map(e=>({...e,onClick:t&&(()=>t(e.key))}));return(0,K.jsx)(VOi,{view:`threads`,...e,rows:o,isLoading:r,isUpdating:i,isError:a})}function VOi({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:A8(e.cost),cells:[O8(e.tokens)],onClick:e.onClick})),l={title:NOi[e],titleMenu:{value:e,onValueChange:t,options:POi},actions:n&&(0,K.jsx)(cDi,{onClick:n})};return o?(0,K.jsx)(D9,{...l,children:(0,K.jsx)(O9,{})}):(0,K.jsx)(D9,{...l,total:A8(r.reduce((e,t)=>e+t.cost,0)),isLoading:i,isUpdating:a,children:(0,K.jsx)(E9,{children:(0,K.jsx)(xOi,{rows:c,columns:IOi,valueLabel:`Cost`,color:T8.green,other:e=>({value:A8(e.reduce((e,t)=>e+t.share,0)),cells:[O8(e.reduce((e,t)=>e+(s.get(t.key)??0),0))]}),emptyState:`No model usage in this range.`,isLoading:i})})})}var HOi=100;function UOi(){let e=X(),{filters:t,filterKey:n,timestamp:r}=N9(),{interval:i}=A9(r.start,r.end),a=j9(i);return Gv({queryKey:[`metrics`,`scores`,n,i],placeholderData:Lv,queryFn:async()=>{let n=await e.listScores({filters:t,pagination:{page:0,perPage:HOi}}),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=CDi(r.start,r.end,a),u=wDi(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 WOi=[T8.green,T8.sky,T8.violet,T8.teal,T8.indigo],GOi=e=>e.toFixed(2),KOi=e=>String(+e.toFixed(2));function qOi(e){return e.map(({scorerId:e,name:t},n)=>({dataKey:e,label:t,color:WOi[n%WOi.length]??T8.neutral}))}function JOi(){let{data:e,isLoading:t,isError:n,isPlaceholderData:r}=UOi(),i=e?.scorers??[],a={title:`Scores`};return n?(0,K.jsx)(D9,{...a,children:(0,K.jsx)(O9,{})}):(0,K.jsx)(D9,{...a,isUpdating:r,children:(0,K.jsx)(E9,{isEmpty:!t&&i.length===0,children:(0,K.jsx)(L8,{lineStyle:`thin`,data:e?.buckets??[],series:qOi(i),height:`fill`,yDomain:[0,1],valueFormatter:GOi,axisFormatter:KOi,isLoading:t,...i5r})})})}var YOi=[`entityName`,`environment`,`threadId`,`resourceId`,`userId`,`organizationId`,`runId`,`sessionId`],XOi=[`provider`,`model`],ZOi=[`serviceName`,`requestId`,`experimentId`],QOi=(e,t)=>({op:`eq`,left:{path:e},right:{literal:t}});function $Oi(e){let t=ZOi.filter(t=>e[t]!==void 0);if(t.length)return{supported:!1,unsupportedFields:t};let n=[];e.rootEntityType&&n.push(QOi(`entityType`,e.rootEntityType));for(let t of YOi){let r=e[t];r!==void 0&&n.push(QOi(t,r))}for(let t of e.tags??[])n.push({op:`includes`,path:`tags`,value:t});for(let t of XOi){let r=e[t];r!==void 0&&n.push({spans:{some:QOi(t,r)}})}return n.length===0?{supported:!0,where:void 0}:{supported:!0,where:n.length===1?n[0]:{op:`and`,args:n}}}var eki=({start:e,end:t})=>({from:e.toISOString(),to:t.toISOString()}),tki=({start:e,end:t})=>A9(e,t).interval;function nki(e,t){let n=j9(tki(t)),r=CDi(t.start,t.end,n).map(e=>({...e,rows:[]})),i=wDi(r,n);for(let t of e)t.bucket&&r[i({timestamp:t.bucket,value:0})??-1]?.rows.push(t);return r}function rki({requiresRootSpanFields:e=!1}={}){let{data:t,isLoading:n}=G5(),{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=$Oi(i);return o.supported?{status:`ready`,scope:{timeRange:eki(r),...o.where?{where:o.where}:{},interval:tki(r),window:r}}:{status:`unsupported-filter`,unsupportedFields:o.unsupportedFields}}function F9(e,{priority:t,enabled:n}={}){let r=X();return a4r({request:e,enabled:n,queryOptions:{queryFn:SEi(()=>r.aggregateTraces(e),t),placeholderData:Lv,staleTime:1/0}})}var iki=[{measure:`countDistinct.resourceId`,dataKey:`resources`,label:`Resources`,color:T8.sky},{measure:`countDistinct.threadId`,dataKey:`threads`,label:`Threads`,color:T8.green},{measure:`countDistinct.userId`,dataKey:`users`,label:`Users`,color:T8.violet},{measure:`countDistinct.sessionId`,dataKey:`sessions`,label:`Sessions`,color:T8.teal}],aki=iki.map(e=>e.measure),oki=`Resources and threads`;function ski(e,t){return e?.measures[t.measure]??0}function cki({scope:e,onTimeRangeClick:t}){let n=F9({timeRange:e.timeRange,where:e.where,interval:e.interval,measures:aki,limit:10}),r=F9({timeRange:e.timeRange,where:e.where,measures:aki}),i=r.data?.rows[0],a=iki.filter(e=>ski(i,e)>0),o=a.map((e,t)=>({dataKey:e.dataKey,label:e.label,color:e.color,emphasis:t===0})),s=nki(n.data?.rows??[],e.window).map(({rows:e,...t})=>({...t,...Object.fromEntries(a.map(t=>[t.dataKey,ski(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:oki,total:l?void 0:a.length?a.map(e=>({label:e.label,value:O8(ski(i,e)),color:e.color})):O8(0),isLoading:r.isLoading,toolbar:o.length>0&&(0,K.jsx)(T9.Toolbar,{children:(0,K.jsx)(I8,{series:o})})};return f?(0,K.jsx)(D9,{...p,children:(0,K.jsx)(O9,{error:l,onRetry:()=>{n.error&&n.refetch(),r.error&&r.refetch()}})}):(0,K.jsx)(D9,{...p,isUpdating:n.isPlaceholderData||r.isPlaceholderData,children:(0,K.jsx)(E9,{isEmpty:!u&&!l&&a.length===0,children:(0,K.jsx)(L8,{lineStyle:`thin`,data:s,series:o,height:`fill`,xLabels:`edges`,showLegend:!1,valueFormatter:O8,axisFormatter:o5r,onBucketClick:t&&(e=>t({window:M9(Number(e.ts),c)})),isLoading:u,...w8})})})}var lki={serviceName:`service`,requestId:`request ID`,experimentId:`experiment`};function uki({requiresRootSpanFields:e,children:t,...n}){let r=rki({requiresRootSpanFields:e});return r.status===`unavailable`?null:r.status===`ready`?t(r.scope):(0,K.jsx)(D9,{...n,toolbar:null,children:r.status===`loading`?(0,K.jsx)(T9.Loading,{}):(0,K.jsx)(T9.NoData,{message:`Not available with a ${r.unsupportedFields.map(e=>lki[e]??e).join(` or `)} filter.`})})}function dki(e){return(0,K.jsx)(uki,{title:oki,children:t=>(0,K.jsx)(cki,{scope:t,...e})})}function fki(){return w9().scope}var pki=[`entityName`,`environment`,`serviceName`,`threadId`,`resourceId`,`userId`,`organizationId`,`runId`,`sessionId`,`requestId`,`experimentId`],mki=[`tags`,`provider`,`model`],hki=(e,t)=>({op:`eq`,left:{path:e},right:{literal:t}});function gki(e){let t=mki.filter(t=>e[t]!==void 0);if(t.length)return{supported:!1,unsupportedFields:t};let n=[];e.rootEntityType&&n.push(hki(`entityType`,e.rootEntityType));for(let t of pki){let r=e[t];r!==void 0&&n.push(hki(t,r))}return n.length===0?{supported:!0,where:void 0}:{supported:!0,where:n.length===1?n[0]:{op:`and`,args:n}}}function _ki(){let{data:e,isLoading:t}=G5(),{timestamp:n,dimensionalFilter:r}=N9();if(t)return{status:`loading`};if(e?.capabilities.spanAggregate!==!0)return{status:`unavailable`};let i=gki(r);return i.supported?{status:`ready`,scope:{timeRange:eki(n),...i.where?{where:i.where}:{},interval:tki(n),window:n}}:{status:`unsupported-filter`,unsupportedFields:i.unsupportedFields}}function vki(e,{priority:t,enabled:n}={}){let r=X();return i4r({request:e,enabled:n,queryOptions:{queryFn:SEi(()=>r.aggregateSpans(e),t),placeholderData:Lv,staleTime:1/0}})}var yki=`Breakdown`,bki={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 xki({tab:e,tabs:t,onTabChange:n,isUpdating:r,children:i}){return(0,K.jsx)(D9,{title:bki[e],titleMenu:t.length>1?{value:e,onValueChange:n,options:t.map(e=>({value:e,label:bki[e]}))}:void 0,isUpdating:r,bodyHeight:`fit`,children:i})}var Ski={agents:[`agent_run`],workflows:[`workflow_run`],tools:[`tool_call`,`mcp_tool_call`]},Cki=e=>e in Ski;function wki(e){let t=Ski[e];return t.length===1?{op:`eq`,left:{path:`spanType`},right:{literal:t[0]??``}}:{op:`in`,value:{path:`spanType`},set:[...t]}}var Tki=e=>e!==`workflows`&&e!==`tools`,Eki=e=>e!==`models`,Dki=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 Oki({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 kki({timeRange:e,where:t},n){return{timeRange:e,...t?{where:t}:{},groupBy:I9(`environments`,n),measures:[`count`,`errorRate`,`duration.p95`],limit:L9.trace}}function Aki(e){let t={op:`exists`,path:`threadId`};return e?{op:`and`,args:[t,e]}:t}function jki({timeRange:e,where:t},n){return{timeRange:e,where:Aki(t),groupBy:n?[`projectId`,`threadId`]:[`resourceId`,`threadId`],measures:[`count`,`errorRate`,`duration.p95`],limit:L9.trace}}function Mki(e,t,n){return e===`projects`?Oki(t):e===`environments`?kki(t,n):jki(t,n)}function Nki({timeRange:e,where:t}){return{timeRange:e,where:Aki(t),groupBy:[`resourceId`,`threadId`],measures:[`count`],limit:L9.trace}}function Pki(e){let t=new Map;for(let n of e){let e=Lki(n,`resourceId`);e&&t.set(Lki(n,`threadId`),e)}return t}var Fki=e=>e===`agents`||e===`workflows`?`countDistinct.traceId`:`count`;function Iki(e,{timeRange:t,where:n},r){let i=wki(e);return{timeRange:t,where:n?{op:`and`,args:[i,n]}:i,groupBy:I9(e,r),measures:[`count`,...Fki(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},Lki=(e,t)=>{let n=e.dimensions?.[t];return n==null?``:String(n)},Rki=(e,t)=>t.map(t=>e.dimensions[t]==null?``:String(e.dimensions[t])).join(`|`);function zki({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=Fki(e);for(let e of n){let n=l(t.map(t=>Lki(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(Rki(e,t)).count=e.value;for(let e of r??[]){let n=l(Rki(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 Bki({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=Fki(e);for(let e of n){let n=o(t.map(t=>Lki(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(Rki(e,t)).count=e.value;for(let e of r){let n=o(Rki(e,t));n.tokens=e.value,n.cost=e.estimatedCost??void 0}return a}function Vki(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 Hki(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:Uki(n,a,i),isNew:!1}}function Uki(e,t,n){return e===`errorRate`?t:n>0?t/n:void 0}function Wki(e,t){if(e.delta!==void 0&&e.delta!==0)return e.delta>0==(t===`count`)?`good`:`bad`}var Gki=[`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=X(),{filters:o,filterKey:s}=N9();return Gv({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`?Gki:[`mastra_model_total_input_tokens`],groupBy:e,aggregation:r===`tokens`?`sum`:`count`,orderDirection:`DESC`,limit:1e3,filters:{...o,...t,timestamp:n}})})}function Kki({start:e,end:t}){return{start:new Date(2*e.getTime()-t.getTime()),end:new Date(e.getTime())}}var qki=[`count`,`errorRate`,`p95`,`tokens`,`cost`],Jki=e=>qki.includes(e),Yki=e=>Dki(e)?`Spans`:`Traces`,Xki=`A trace is one end-to-end request, with every step it took.`,Zki=`A span is one step inside a trace, such as a tool call or a model call. One trace can have many.`,Qki=e=>Dki(e)?Zki:Xki,$ki={errorRate:`Errors`,p95:`P95 latency`,tokens:`Tokens`,cost:`Cost`},eAi=({start:e,end:t})=>`${Cx(e,`day-time`)} – ${Cx(t,`day-time`)}`;function tAi(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: ${eAi(e)}`,previous:`Previous: ${eAi(Kki(e))}`}}var nAi=(e,t)=>t&&e!==`projects`,rAi=(e,t)=>t===`count`?Yki(e):$ki[t];function iAi({tab:e,built:t,previous:n,truncated:r,groupBy:i,usage:a}){return e===`threads`?t.filter(e=>e.name!==``):!n||r?t:Vki(t,n,i,a)}function aAi(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 oAi=(e,t)=>e===`projects`?t.key:t.projectId;function sAi(e,t){let n=oAi(e,t),r=n?{projectId:n}:{};return Cki(e)?{...r,span:{spanTypes:Ski[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 cAi(e,t){return t&&t.toUpperCase()!==`USD`?`${O8(e)} ${t}`:A8(e)}function lAi(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}${k8(r)}`}function uAi(e){let t=Kki(e.window);return{...e,window:t,timeRange:eki(t)}}var dAi={good:`text-badge-green-foreground`,bad:`text-badge-red-foreground`};function fAi({trend:e,children:t}){return t===void 0?(0,K.jsx)(`span`,{className:`text-muted-foreground`,children:`—`}):(0,K.jsx)(`span`,{className:e?dAi[e]:`text-muted-foreground`,children:t})}function pAi({change:e,metric:t}){return e?(0,K.jsx)(fAi,{trend:Wki(e,t),children:lAi(e,t)}):(0,K.jsx)(fAi,{trend:void 0})}function mAi({window:e,label:t}){let{summary:n,current:r,previous:i}=tAi(e,t);return(0,K.jsxs)(`span`,{className:`grid gap-1`,children:[(0,K.jsx)(`span`,{children:n}),(0,K.jsx)(`span`,{className:`tabular-nums`,children:r}),(0,K.jsx)(`span`,{className:`tabular-nums`,children:i})]})}function hAi(){return(0,K.jsx)(`span`,{title:`No price for this model`,children:`Not priced`})}function gAi({row:e}){return e.cost===void 0?e.tokens?(0,K.jsx)(hAi,{}):`—`:cAi(e.cost,e.costUnit)}function B9({muted:e=!1,children:t}){return(0,K.jsx)(W,{as:`span`,variant:`body-sm`,tone:e?`muted`:void 0,className:`tabular-nums`,children:t})}function _Ai({mark:e,title:t,model:n}){return(0,K.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[e,(0,K.jsx)(`span`,{className:`truncate`,title:t,children:n?(0,K.jsx)(Dti,{parts:hUn(n.name,n.provider)}):t})]})}var vAi=e=>(0,K.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,K.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,K.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,K.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`})]}),yAi={agent:FM,workflow:cx,tool:HM},bAi={agents:`agent`,workflows:`workflow`,tools:`tool`};function xAi({entity:e}){let t=yAi[e];return(0,K.jsx)(_Un,{icon:(0,K.jsx)(t,{className:`size-3`})})}function SAi({provider:e}){return e?(0,K.jsx)(vUn,{provider:e}):(0,K.jsx)(_Un,{icon:(0,K.jsx)(vAi,{className:`size-icon-xs`})})}function CAi({tab:e,row:t}){let n=bAi[e];return n?(0,K.jsx)(xAi,{entity:n}):e===`models`?(0,K.jsx)(SAi,{provider:t.provider}):null}function wAi({tab:e,row:t}){let{projectLabel:n}=fki();return(0,K.jsx)(_Ai,{mark:(0,K.jsx)(CAi,{tab:e,row:t}),title:aAi(e,t,n),model:e===`models`&&t.name!==``?{name:t.name,provider:t.provider}:void 0})}function TAi({text:e}){return(0,K.jsx)(W,{as:`span`,variant:`body-sm`,tone:`muted`,className:`truncate`,title:e,children:e})}var EAi={asc:YA,desc:JA},DAi=`focus-visible:outline-1 focus-visible:outline-solid focus-visible:outline-border-focus focus-visible:-outline-offset-1`,OAi=`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 kAi({header:e,explained:t,sorted:n,className:r,...i}){let a=n&&EAi[n];return(0,K.jsxs)(`button`,{type:`button`,...i,className:T(`group/header flex items-center gap-1 rounded whitespace-nowrap hover:text-muted-foreground`,DAi,r),children:[(0,K.jsx)(`span`,{className:T(t&&OAi),children:e}),a&&(0,K.jsx)(a,{"aria-hidden":!0,className:`size-3`})]})}function AAi({header:e,explained:t,className:n,...r}){return(0,K.jsx)(`span`,{tabIndex:t?0:void 0,...r,className:T(`group/header rounded whitespace-nowrap`,DAi,n),children:(0,K.jsx)(`span`,{className:T(t&&OAi),children:e})})}function jAi({header:e,description:t,sorted:n,onSort:r}){let i=(0,G.useId)(),a=!!t,o=a?i:void 0,s=r?(0,K.jsx)(kAi,{header:e,explained:a,sorted:n,onClick:r,"aria-describedby":o}):(0,K.jsx)(AAi,{header:e,explained:a,"aria-describedby":o});return a?(0,K.jsxs)(jn,{children:[(0,K.jsx)(dr,{render:s}),(0,K.jsx)(qt,{id:i,keepMounted:!0,side:`top`,className:`max-w-72`,children:t})]}):s}var MAi=`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)]`,NAi=`pt-1.75 pb-2 text-body-sm`,PAi=T(`relative col-span-full grid grid-cols-subgrid items-center px-3`,NAi,MAi),FAi=[`w-32`,`w-24`,`w-36`,`w-20`,`w-28`],IAi=`a, button, input, select, textarea, label, [role="button"], [role="link"], [contenteditable]`;function LAi(e){if(!(e.target instanceof Element))return!1;let t=e.target.closest(IAi);return!!(t&&e.currentTarget.contains(t))}function RAi(e,t,n){return e.align===`end`?`right-0 w-10`:t>0?`left-0 w-16`:T(`left-0`,FAi[n%FAi.length])}function zAi({columns:e,rows:t,getRowKey:n,empty:r,pageSize:i,isLoading:a,...o}){return a?Array.from({length:i??5},(t,n)=>(0,K.jsx)(VAi,{columns:e,rowIndex:n},n)):t.length===0?i?r===void 0?(0,K.jsx)(BAi,{count:i}):(0,K.jsxs)(`div`,{role:`row`,className:`col-span-full grid *:col-start-1 *:row-start-1`,children:[(0,K.jsx)(BAi,{count:i}),(0,K.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,K.jsx)(`div`,{role:`row`,className:`col-span-full`,children:(0,K.jsx)(`p`,{role:`cell`,className:`py-8 text-center text-body-sm text-muted-foreground`,children:r})}):t.map(t=>(0,K.jsx)(HAi,{row:t,columns:e,...o},n(t)))}function BAi({count:e}){return e<=0?null:(0,K.jsx)(`div`,{"aria-hidden":!0,"data-slot":`metrics-table-filler`,className:`col-span-full`,children:Array.from({length:e},(e,t)=>(0,K.jsx)(`div`,{className:NAi,children:`​`},t))})}function VAi({columns:e,rowIndex:t}){return(0,K.jsx)(`div`,{role:`row`,"aria-busy":!0,className:PAi,children:e.map((e,n)=>(0,K.jsxs)(`div`,{role:`cell`,className:T(`relative flex min-w-0`,e.align===`end`&&`justify-end`),children:[`​`,(0,K.jsx)(Zb,{className:T(`absolute top-1/2 h-3.5 -translate-y-1/2`,RAi(e,n,t))})]},e.id))})}function HAi({row:e,columns:t,onRowClick:n,onRowHover:r,isRowDimmed:i,isRowActive:a,rowTitle:o}){let s=a?.(e)??!1,c=i?.(e)??!1;return(0,K.jsx)(`div`,{role:`row`,"aria-current":s||void 0,tabIndex:n?0:void 0,title:o?.(e),onClick:n?t=>{LAi(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:T(PAi,`rounded text-foreground transition-opacity duration-150`,n&&T(`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`,c&&`opacity-40`),children:t.map(t=>(0,K.jsx)(`div`,{role:`cell`,className:T(`flex min-w-0 items-center`,t.align===`end`&&`justify-end text-right`),children:t.cell(e)},t.id))})}var UAi=`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)]`,WAi={asc:`ascending`,desc:`descending`};function GAi(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 KAi(e,t){return typeof e==`number`&&typeof t==`number`?e-t:String(e).localeCompare(String(t))}function qAi(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*KAi(n,a)})}var JAi=e=>e.width??(e.align===`end`?`minmax(max-content,1fr)`:`max-content`);function YAi({columns:e,rows:t,getRowKey:n,sort:r,defaultSort:i,onSortChange:a,onRowClick:o,onRowHover:s,isRowDimmed:c,isRowActive:l,rowTitle:u,empty:d,pageSize:f,isLoading:p=!1,"aria-label":m,className:h}){let[g,_]=(0,G.useState)(i),[v,y]=(0,G.useState)(0),b=r??g,x=qAi(t,e,b),S=f?Math.ceil(x.length/f):1,C=Math.min(v,Math.max(0,S-1)),w=f?x.slice(C*f,(C+1)*f):x,E={gridTemplateColumns:e.map(JAi).join(` `)},D=!p&&S>1,O=e=>{let t=GAi(b,e)??i;_(t),y(0),a?.(t)};return(0,K.jsxs)(`div`,{className:T(`grid min-w-0 gap-3`,h),children:[(0,K.jsxs)(qb,{orientation:`horizontal`,children:[(0,K.jsxs)(`div`,{role:`table`,"aria-label":m,className:`grid min-w-min gap-x-4`,style:E,children:[(0,K.jsx)(`div`,{role:`row`,className:T(`relative col-span-full grid grid-cols-subgrid items-end px-3 pb-1.5 text-label text-muted-foreground`,UAi),children:e.map(e=>{let t=b?.column===e.id?b.direction:void 0;return(0,K.jsx)(`div`,{role:`columnheader`,"aria-sort":t&&WAi[t],className:T(`flex min-w-0 items-center gap-1`,e.align===`end`&&`justify-end text-right`),children:(0,K.jsx)(jAi,{header:e.header,description:e.description,sorted:t,onSort:e.sortValue?()=>O(e):void 0})},e.id)})}),(0,K.jsx)(zAi,{columns:e,rows:w,getRowKey:n,onRowClick:o,onRowHover:s,isRowDimmed:c,isRowActive:l,rowTitle:u,empty:d,pageSize:f,isLoading:p})]}),f!==void 0&&!p&&w.length>0&&(0,K.jsx)(BAi,{count:f-w.length})]}),D&&(0,K.jsx)(a8n,{page:C,pageCount:S,onPageChange:y})]})}var XAi=10,ZAi={column:`count`,direction:`desc`},QAi={projects:`Project`,agents:`Agent`,workflows:`Workflow`,tools:`Tool`,models:`Model`,threads:`Thread`,environments:`Environment`},$Ai={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 eji({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=fki(),[p,m]=(0,G.useState)(ZAi),[h,g]=(0,G.useState)(`count`),_=(e=ZAi)=>{m(e),Jki(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,K.jsx)(xki,{...d,tab:e,children:(0,K.jsx)(O9,{onRetry:()=>v.forEach(e=>e.isError&&void e.refetch())})});let b=Eki(e),x=i!==void 0,S=nAi(e,d.byProject),C=r?.data?.truncated===!0,w=y?[]:zki({tab:e,groupBy:t,aggregateRows:r?.data?.rows,usageGroups:i?.data?.groups,spanGroups:a?.data?.groups,resources:o?.data?Pki(o.data.rows):void 0}),T=[s,c,l].every(e=>!e||!e.isLoading&&!e.isError)&&!y?Bki({tab:e,groupBy:t,aggregateRows:s?.data?.rows,usageGroups:c?.data?.groups,spanGroups:l?.data?.groups}):void 0,E=iAi({tab:e,built:w,previous:T,truncated:C,groupBy:t,usage:x}),D=Yki(e),O=e=>T?Hki(e,T.get(e.key),h):void 0,k=e=>e.projectId?f.projectLabel?.(e.projectId)??e.projectId:`—`,A={id:`name`,header:QAi[e],width:`minmax(12rem,3fr)`,cell:t=>(0,K.jsx)(wAi,{tab:e,row:t})},j={id:`project`,header:`Project`,width:`minmax(8rem,2fr)`,cell:e=>(0,K.jsx)(TAi,{text:k(e)})},M={id:`resource`,header:`Resource`,width:`minmax(6rem,1fr)`,cell:e=>(0,K.jsx)(TAi,{text:e.resource??`—`})},N=[{id:`errorRate`,header:`Errors`,align:`end`,sortValue:e=>e.errorRate,cell:e=>(0,K.jsx)(B9,{muted:!0,children:e.errorRate===void 0?`—`:k8(e.errorRate)})},{id:`p95`,header:`P95 latency`,align:`end`,sortValue:e=>e.p95,cell:e=>(0,K.jsx)(B9,{muted:!0,children:e.p95===void 0?`—`:a5r(e.p95)})}],P=[{id:`tokens`,header:`Tokens`,align:`end`,sortValue:e=>e.tokens,cell:e=>(0,K.jsx)(B9,{muted:!0,children:e.tokens===void 0?`—`:O8(e.tokens)})},{id:`cost`,header:`Cost`,align:`end`,sortValue:e=>e.cost,cell:e=>(0,K.jsx)(B9,{muted:!0,children:(0,K.jsx)(gAi,{row:e})})}],F={id:`count`,header:D,align:`end`,description:Qki(e),sortValue:e=>e.count,cell:e=>(0,K.jsx)(B9,{children:O8(e.count)})},I={id:`change`,header:`% Change`,align:`end`,description:(0,K.jsx)(mAi,{window:n,label:rAi(e,h)}),sortValue:e=>O(e)?.change,cell:e=>(0,K.jsx)(B9,{children:(0,K.jsx)(pAi,{change:O(e),metric:h})})},L=[A,...S?[j]:[],...e===`threads`?[M]:[],...b?N:[],...x?P:[],F,I];return(0,K.jsx)(xki,{...d,tab:e,isUpdating:r?.isPlaceholderData,children:(0,K.jsxs)(E9,{children:[(0,K.jsx)(YAi,{"aria-label":`${QAi[e]} breakdown`,columns:L,rows:E,getRowKey:e=>e.key,sort:p,defaultSort:ZAi,onSortChange:_,onRowClick:d.onRowClick&&(t=>d.onRowClick?.(sAi(e,t))),pageSize:XAi,isLoading:y,empty:$Ai[e]},e),!y&&C&&(0,K.jsxs)(W,{variant:`caption`,tone:`muted`,className:`pt-2`,children:[`Showing the `,O8(u),` busiest; sorting covers only these.`]})]})})}var tji={entityType:`agent`};function nji({tab:e,scope:t,...n}){let r=I9(e,n.byProject),i=Tki(e),a=uAi(t),o=vki(Iki(e,t,n.byProject)),s=vki(Iki(e,a,n.byProject),{priority:_Ei.last}),c=z9({groupBy:r,filters:tji,window:t.window,enabled:i}),l=z9({groupBy:r,filters:tji,window:a.window,enabled:i});return(0,K.jsx)(eji,{...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 rji(e){let t=I9(`models`,e.byProject),{timestamp:n}=N9(),r=Kki(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,K.jsx)(eji,{...e,tab:`models`,groupBy:t,window:n,totals:i,spans:a,previousUsage:o,previousSpans:s,limit:L9.trace})}function iji({tab:e,scope:t,...n}){let r=I9(e,n.byProject),i=uAi(t),a=F9(Mki(e,t,n.byProject)),o=F9(Mki(e,i,n.byProject),{priority:_Ei.last}),s=F9(Nki(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,K.jsx)(eji,{...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 aji={serviceName:`service`,requestId:`request ID`,experimentId:`experiment`,tags:`tags`,provider:`provider`,model:`model`};function oji({tab:e,traceGate:t,spanGate:n,...r}){if(e===`models`)return(0,K.jsx)(rji,{...r},e);let i=Cki(e)?n:t;return i.status===`unsupported-filter`?(0,K.jsx)(xki,{...r,tab:e,children:(0,K.jsx)(T9.NoData,{message:`Not available with a ${i.unsupportedFields.map(e=>aji[e]??e).join(` or `)} filter.`})}):Cki(e)?n.status===`ready`&&(0,K.jsx)(nji,{...r,tab:e,scope:n.scope},e):t.status===`ready`&&(0,K.jsx)(iji,{...r,tab:e,scope:t.scope},e)}function sji({chosen:e,traceScope:t,spanGate:n,...r}){let i=F9(Oki(t)).data?.rows.filter(e=>(e.measures.count??0)>0).length,a=e??cji(i);return(0,K.jsx)(oji,{...r,tab:a,traceGate:{status:`ready`,scope:t},spanGate:n})}function cji(e){return e===void 0||e>=2?`projects`:`agents`}var lji=[`projects`,`agents`,`workflows`,`tools`,`models`,`threads`,`environments`],uji=lji.filter(e=>e!==`projects`);function dji({onRowClick:e}){let t=fki().projectLabel!==void 0,n=rki(),r=_ki(),[i,a]=(0,G.useState)();if(n.status===`unavailable`||r.status===`unavailable`)return null;if(n.status===`loading`||r.status===`loading`)return(0,K.jsx)(D9,{title:yki,bodyHeight:`fit`,children:(0,K.jsx)(T9.Loading,{})});let o={tabs:t?lji:uji,onTabChange:a,onRowClick:e,byProject:t};return t&&n.status===`ready`?(0,K.jsx)(sji,{...o,chosen:i,traceScope:n.scope,spanGate:r}):(0,K.jsx)(oji,{...o,tab:i??`agents`,traceGate:n,spanGate:r})}function fji(){let{data:e,isLoading:t}=G5();if(t)return`loading`;let n=e?.capabilities;return n?.traceAggregate===!0&&n.spanAggregate===!0?`unified`:`legacy`}var V9=[vI(`/metrics`)],pji=e=>e.fieldId===iM;function mji({fields:e}){let{filterTokens:t,setFilterTokens:n}=w9(),r=[oM,...sEi(t)];return(0,K.jsxs)(pM,{fields:[aM,...e],operators:eEi,value:r,onValueChange:e=>n(cEi(e.filter(e=>!pji(e)))),createItemId:e=>e,"aria-label":`Metrics filters`,className:`min-w-64 flex-1`,children:[(0,K.jsx)(pM.Chips,{renderChip:e=>pji(e)?(0,K.jsx)(GEi,{}):(0,K.jsx)(pM.Chip,{item:e})}),(0,K.jsx)(pM.Input,{placeholder:`Filter metrics`})]})}function hji({children:e,filterFields:t}){return(0,K.jsxs)(Xb,{variant:`page`,breadcrumbs:(0,K.jsx)(IA,{crumbs:V9}),actionRow:(0,K.jsx)(_M,{children:(0,K.jsx)(_M.Start,{children:(0,K.jsx)(mji,{fields:t})})}),children:[(0,K.jsx)(`h1`,{className:`sr-only`,children:`Metrics`}),e]})}function gji({error:e}){return Ej(e)?(0,K.jsx)(oI,{}):Dj(e)?(0,K.jsx)(aI,{resource:`metrics`}):(0,K.jsx)(db,{tone:`error`,titleSlot:`Failed to load storage capabilities`,descriptionSlot:e.message})}var _ji=oEi({availableTags:[],availableEntityNames:[],availableServiceNames:[],availableEnvironments:[]});function vji({children:e}){let{supportsMetrics:t,isLoading:n,error:r}=i7();return n?(0,K.jsx)(hji,{filterFields:_ji,children:(0,K.jsxs)(`div`,{className:`flex h-full items-center justify-center gap-2`,children:[(0,K.jsx)(pt,{"aria-label":`Loading storage capabilities`}),(0,K.jsx)(W,{as:`span`,variant:`caption`,tone:`muted`,children:`Loading storage capabilities`})]})}):r?(0,K.jsxs)(Xb,{variant:`page`,breadcrumbs:(0,K.jsx)(IA,{crumbs:V9}),children:[(0,K.jsx)(`h1`,{className:`sr-only`,children:`Metrics`}),(0,K.jsx)(`div`,{className:`flex h-full items-center justify-center`,children:(0,K.jsx)(gji,{error:r})})]}):t?e:(0,K.jsx)(hji,{filterFields:_ji,children:(0,K.jsx)(db,{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,K.jsx)(U,{variant:`ghost`,render:(0,K.jsx)(`a`,{href:`https://mastra.ai/docs/observability/metrics/overview`,target:`_blank`,rel:`noopener noreferrer`}),icon:(0,K.jsx)(qM,{}),children:`Metrics documentation`}),variant:`fill`})})}function yji(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 bji(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=yji(i);s&&e.set(t,s)}function H9(e,t,n){typeof n==`string`&&n.length>0&&e.set(t,n)}function xji(e,t,n){if(Array.isArray(n)&&n.length!==0)for(let r of n)r&&e.append(t,r)}function Sji({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 Cji({preset:e,customRange:t,dashboardFilter:n,scope:r,tracesBasePath:i=`/traces`}){let a=new URLSearchParams;a.set(W6,`branches`),bji(a,G6,K6,q6,e,t,r.window);let o=r.rootEntityType??n.rootEntityType;if(o&&a.set(H6,o),r.status&&a.set(U6,r.status),H9(a,Y6.entityName,r.entityName??n.entityName),H9(a,Y6.threadId,r.threadId??n.threadId),H9(a,Y6.resourceId,r.resourceId??n.resourceId),H9(a,Y6.runId,n.runId),H9(a,Y6.sessionId,r.sessionId??n.sessionId),H9(a,Y6.requestId,n.requestId),H9(a,Y6.userId,r.userId??n.userId),H9(a,Y6.organizationId,n.organizationId),H9(a,Y6.experimentId,n.experimentId),H9(a,Y6.serviceName,n.serviceName),H9(a,Y6.environment,r.environment??n.environment),xji(a,Y6.tags,n.tags),r.span&&a.append(l8,JSON.stringify(Sji(r.span))),r.model){let e={id:`metrics-model`,logic:`and`,nodes:[{id:`model`,fieldId:`spans.model`,value:r.model}]};a.append(l8,JSON.stringify(e))}let s=a.toString();return s?`${i}?${s}`:i}function wji({preset:e,customRange:t,dashboardFilter:n,scope:r,logsBasePath:i=`/logs`}){let a=new URLSearchParams;bji(a,N5,P5,F5,e,t,r.window);let o=r.rootEntityType??n.rootEntityType;o&&a.set(M5,o),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,n.sessionId),H9(a,I5.requestId,n.requestId),H9(a,I5.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,n.environment),xji(a,I5.tags,n.tags),r.status===`error`&&a.append(I5.level,`error`);let s=a.toString();return s?`${i}?${s}`:i}function Tji(){let{datePreset:e,customRange:t,dimensionalFilter:n}=w9(),r=Jy(),i={preset:e,customRange:t,dashboardFilter:n};return{openTraces:(e={})=>{r(Cji({...i,scope:e}))},openLogs:(e={})=>{r(wji({...i,scope:e}))}}}var Eji=`period`,Dji=`dateFrom`,Oji=`dateTo`;function kji(){let[e,t]=nb(),n=e.get(Eji),r=PEi(n)?n:`24h`,i=(0,G.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(Dji)),i=t(e.get(Oji));if(n||i)return{from:n,to:i}},[r,e.toString()]),a=(0,G.useMemo)(()=>lEi(e),[e.toString()]),o=(0,G.useCallback)(e=>{t(t=>{let n=new URLSearchParams(t);return e===`24h`?n.delete(Eji):n.set(Eji,e),e!==`custom`&&(n.delete(Dji),n.delete(Oji)),n},{replace:!0})},[t]),s=(0,G.useCallback)(e=>{t(t=>{let n=new URLSearchParams(t);return e?.from?n.set(Dji,e.from.toISOString()):n.delete(Dji),e?.to?n.set(Oji,e.to.toISOString()):n.delete(Oji),n},{replace:!0})},[t]),c=(0,G.useCallback)(e=>{t(t=>{let n=new URLSearchParams(t);return dEi(n,e),XTi(n),n},{replace:!0})},[t]),l=(0,G.useRef)(!1);return(0,G.useEffect)(()=>{if(l.current||(l.current=!0,QTi(e)))return;let n=ZTi();n&&t(e=>{let t=new URLSearchParams(e);for(let[e,r]of n)t.append(e,r);return t},{replace:!0})},[]),(0,K.jsx)(zEi,{preset:r,filterTokens:a,onPresetChange:o,onFilterTokensChange:c,customRange:i,onCustomRangeChange:s,children:(0,K.jsx)(vji,{children:(0,K.jsx)(Aji,{})})})}function Aji(){let{error:e}=OEi(N9()),{isInMemory:t}=i7(),{data:n}=Q2r(),{data:r}=O6(),{data:i}=X2r(),{data:a}=k6(),o=oEi({availableTags:n??[],availableEntityNames:r??[],availableServiceNames:i??[],availableEnvironments:a??[]});return e&&Ej(e)?(0,K.jsxs)(Xb,{variant:`page`,breadcrumbs:(0,K.jsx)(IA,{crumbs:V9}),children:[(0,K.jsx)(`h1`,{className:`sr-only`,children:`Metrics`}),(0,K.jsx)(oI,{variant:`fill`})]}):e&&Dj(e)?(0,K.jsxs)(Xb,{variant:`page`,breadcrumbs:(0,K.jsx)(IA,{crumbs:V9}),children:[(0,K.jsx)(`h1`,{className:`sr-only`,children:`Metrics`}),(0,K.jsx)(aI,{variant:`fill`,resource:`metrics`})]}):e?(0,K.jsxs)(Xb,{variant:`page`,breadcrumbs:(0,K.jsx)(IA,{crumbs:V9}),children:[(0,K.jsx)(`h1`,{className:`sr-only`,children:`Metrics`}),(0,K.jsx)(db,{tone:`error`,variant:`fill`,titleSlot:`Failed to load metrics`,descriptionSlot:e.message})]}):(0,K.jsx)(hji,{filterFields:o,children:(0,K.jsxs)(`div`,{className:`grid content-start gap-4`,children:[t&&(0,K.jsx)(NE,{variant:`info`,title:`Metrics are not persisted`,children:(0,K.jsx)(NE.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,K.jsx)(jji,{})]})})}function jji(){let{openTraces:e,openLogs:t}=Tji(),n=qm.AGENT,r=fji(),i=(0,K.jsx)(RDi,{onTimeRangeClick:t=>e({rootEntityType:n,window:t}),onViewErrors:()=>t({rootEntityType:n,status:`error`}),onFailureTimeRangeClick:t=>e({rootEntityType:n,status:`error`,window:t})}),a=(0,K.jsx)(qDi,{onViewTraces:t=>e({rootEntityType:t}),onTimeRangeClick:t=>e({window:t})}),o=(0,K.jsx)(LOi,{onViewTraces:()=>e(),onAgentClick:t=>e({rootEntityType:n,entityName:t}),onModelClick:t=>e({model:t}),onThreadClick:t=>e({threadId:t})}),s=(0,K.jsx)(MDi,{onViewTraces:()=>e(),onTimeRangeClick:t=>e({window:t})});return r===`unified`?(0,K.jsxs)(`div`,{className:`grid content-start gap-4 pb-6`,children:[(0,K.jsxs)(k9,{columns:2,children:[(0,K.jsx)(k9.Item,{children:s}),(0,K.jsx)(k9.Item,{children:i}),(0,K.jsx)(k9.Item,{children:a}),(0,K.jsx)(k9.Item,{children:(0,K.jsx)(dki,{onTimeRangeClick:e})})]}),(0,K.jsx)(dji,{onRowClick:e})]}):(0,K.jsxs)(`div`,{className:`grid content-start gap-4 pb-6`,children:[s,(0,K.jsxs)(k9,{columns:2,children:[(0,K.jsx)(k9.Item,{children:i}),(0,K.jsx)(k9.Item,{children:a})]}),(0,K.jsxs)(k9,{columns:2,children:[(0,K.jsx)(k9.Item,{children:(0,K.jsx)(kOi,{onViewTraces:t=>e({rootEntityType:t}),onViewErrors:e=>t({rootEntityType:e,status:`error`}),onEntityClick:(t,n)=>e({rootEntityType:t,entityName:n})})}),(0,K.jsx)(k9.Item,{children:o})]}),(0,K.jsx)(JOi,{})]})}function Mji(){let{isCmsAvailable:e}=w3(),{paths:t}=xa();return e?(0,K.jsx)(yUr,{href:t.cmsPromptBlockCreateLink(),tooltip:`Create a prompt`,children:`New prompt`}):null}var U9=[vI(`/prompts`)],Nji=50,Pji=[`updatedAt`];function Fji(){let{isCmsAvailable:e,isLoading:t}=w3(),n=!t&&e,[r,i]=(0,G.useState)(``),[a,o]=(0,G.useState)(0),[s,c]=nb(),{sort:l,onSortChange:u}=pP({searchParams:s,setSearchParams:c,allowedKeys:Pji}),{data:d,isLoading:f,error:p,isPlaceholderData:m}=IGr({page:a,perPage:Nji,orderBy:(0,G.useMemo)(()=>l?{field:l.key,direction:l.direction===`asc`?`ASC`:`DESC`}:void 0,[l])}),h=d?.promptBlocks??[],g=d?.hasMore??!1,_=(0,G.useCallback)(()=>{m||o(e=>e+1)},[m]),v=(0,G.useCallback)(()=>{m||o(e=>Math.max(0,e-1))},[m]),y=(0,G.useCallback)(e=>{i(e),o(0)},[]),b=(0,G.useCallback)((e,t)=>{u(e,t),o(0)},[u]);return p&&Ej(p)?(0,K.jsxs)(Xb,{variant:`page`,breadcrumbs:(0,K.jsx)(IA,{crumbs:U9}),children:[(0,K.jsx)(`h1`,{className:`sr-only`,children:`Prompts`}),(0,K.jsx)(oI,{variant:`fill`})]}):p&&Dj(p)?(0,K.jsxs)(Xb,{variant:`page`,breadcrumbs:(0,K.jsx)(IA,{crumbs:U9}),children:[(0,K.jsx)(`h1`,{className:`sr-only`,children:`Prompts`}),(0,K.jsx)(aI,{variant:`fill`,resource:`prompt blocks`})]}):p?(0,K.jsxs)(Xb,{variant:`page`,breadcrumbs:(0,K.jsx)(IA,{crumbs:U9}),children:[(0,K.jsx)(`h1`,{className:`sr-only`,children:`Prompts`}),(0,K.jsx)(db,{tone:`error`,variant:`fill`,titleSlot:`Failed to load prompt blocks`,descriptionSlot:p.message})]}):h.length===0&&!f&&a===0?(0,K.jsxs)(Xb,{variant:`page`,breadcrumbs:(0,K.jsx)(IA,{crumbs:U9}),children:[(0,K.jsx)(`h1`,{className:`sr-only`,children:`Prompts`}),(0,K.jsx)(EQr,{canCreate:n})]}):(0,K.jsxs)(Xb,{variant:`page`,breadcrumbs:(0,K.jsx)(IA,{crumbs:U9}),headerActions:(0,K.jsx)(Mji,{}),actionRow:(0,K.jsx)(_M,{children:(0,K.jsx)(_M.Start,{children:(0,K.jsx)(`div`,{className:`max-w-120 flex-1`,children:(0,K.jsx)($A,{...ej,onValueChange:y,label:`Search prompts`,placeholder:`Search by name or description`})})})}),children:[(0,K.jsx)(`h1`,{className:`sr-only`,children:`Prompts`}),(0,K.jsx)(OQr,{promptBlocks:h,isLoading:f,search:r,currentPage:a,hasMore:g,onNextPage:_,onPrevPage:v,updatedSort:l?.direction,onSortChange:b})]})}var Iji=_(`IconEarth`,()=>(0,K.jsxs)(K.Fragment,{children:[(0,K.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,K.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,K.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`})]})),Lji=[vI(`/resources`)],Rji=[{title:`Mastra APIs`,description:`Explore and test the available REST API endpoints with the interactive Swagger UI.`,icon:Iji,href:`/swagger-ui`,external:!1},{title:`Documentation`,description:`Read the official Mastra documentation for guides, references, and tutorials.`,icon:j2t,href:`https://mastra.ai/en/docs`,external:!0},{title:`Github`,description:`Browse the source code, report issues, and contribute to the Mastra project.`,icon:qM,href:`https://github.com/mastra-ai/mastra`,external:!0},{title:`Community`,description:`Join the Mastra Discord community for help, discussion, and collaboration.`,icon:SJ,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:A$n,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:SLr,href:`https://mastra.ai/contact?ref=studio`,external:!0}];function zji(){return(0,K.jsxs)(Xb,{variant:`page`,breadcrumbs:(0,K.jsx)(IA,{crumbs:Lji}),children:[(0,K.jsx)(`h1`,{className:`sr-only`,children:`Resources`}),(0,K.jsx)(`div`,{children:(0,K.jsx)(`div`,{className:`grid max-w-3xl grid-cols-1 gap-4 sm:grid-cols-2`,children:Rji.map(e=>(0,K.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,K.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,K.jsx)(e.icon,{className:T(`h-5 w-5 text-muted-foreground group-hover:text-info-indicator`,x)}),(0,K.jsx)(W,{as:`span`,variant:`subheading`,tone:`ink`,children:e.title}),e.external&&(0,K.jsx)(qM,{className:`ml-auto size-icon-sm text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100`})]}),(0,K.jsx)(W,{variant:`caption`,tone:`muted`,children:e.description})]},e.href))})})]})}function Bji(){let{isCmsAvailable:e}=w3(),{paths:t}=xa();return e?(0,K.jsx)(yUr,{href:t.cmsScorersCreateLink(),tooltip:`Create a scorer`,children:`New scorer`}):null}var W9=[vI(`/scorers`)];function Vji(){let{data:e={},isLoading:t,error:n}=mI(),[r,i]=(0,G.useState)(``),[a,o]=(0,G.useState)(`all`),[s,c]=(0,G.useState)();if(n&&Ej(n))return(0,K.jsxs)(Xb,{variant:`page`,breadcrumbs:(0,K.jsx)(IA,{crumbs:W9}),children:[(0,K.jsx)(`h1`,{className:`sr-only`,children:`Scorers`}),(0,K.jsx)(oI,{variant:`fill`})]});if(n&&Dj(n))return(0,K.jsxs)(Xb,{variant:`page`,breadcrumbs:(0,K.jsx)(IA,{crumbs:W9}),children:[(0,K.jsx)(`h1`,{className:`sr-only`,children:`Scorers`}),(0,K.jsx)(aI,{variant:`fill`,resource:`scorers`})]});if(n)return(0,K.jsxs)(Xb,{variant:`page`,breadcrumbs:(0,K.jsx)(IA,{crumbs:W9}),children:[(0,K.jsx)(`h1`,{className:`sr-only`,children:`Scorers`}),(0,K.jsx)(db,{tone:`error`,variant:`fill`,titleSlot:`Failed to load scorers`,descriptionSlot:n.message})]});if(Object.keys(e).length===0&&!t)return(0,K.jsxs)(Xb,{variant:`page`,breadcrumbs:(0,K.jsx)(IA,{crumbs:W9}),headerActions:(0,K.jsx)(Bji,{}),children:[(0,K.jsx)(`h1`,{className:`sr-only`,children:`Scorers`}),(0,K.jsx)(GWr,{})]});let l=a!==`all`||r!==``;return(0,K.jsxs)(Xb,{variant:`page`,breadcrumbs:(0,K.jsx)(IA,{crumbs:W9}),headerActions:(0,K.jsx)(Bji,{}),actionRow:(0,K.jsx)(qWr,{search:r,onSearchChange:i,sourceFilter:a,onSourceFilterChange:o,onReset:()=>{i(``),o(`all`)},hasActiveFilters:l}),children:[(0,K.jsx)(`h1`,{className:`sr-only`,children:`Scorers`}),(0,K.jsx)(WWr,{scorers:e,isLoading:t,search:r,sourceFilter:a,sort:s,onSortChange:(e,t)=>c({key:t,direction:e})})]})}var Hji=[`input`,`entity`],Uji={input:`Input`,entity:`Entity`};function Wji(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 Gji(){let[e,t]=(0,G.useState)(new Set),n=(0,G.useMemo)(()=>new Set(Hji.filter(t=>!e.has(t))),[e]);return{visibleColumns:n,columns:(0,G.useMemo)(()=>Wji(n),[n]),toggleColumn:(0,G.useCallback)(e=>{t(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[])}}function Kji({visibleColumns:e,toggleColumn:t}){return(0,K.jsxs)(TT,{children:[(0,K.jsx)(TT.Trigger,{asChild:!0,children:(0,K.jsx)(U,{icon:(0,K.jsx)(fI,{}),children:`Columns`})}),(0,K.jsxs)(TT.Content,{align:`end`,children:[(0,K.jsx)(TT.Label,{children:`Toggle columns`}),Hji.map(n=>(0,K.jsx)(TT.CheckboxItem,{checked:e.has(n),onClick:()=>t(n),children:Uji[n]},n))]})]})}var qji=[vI(`/scorers`),J2t],Jji=[`date`,`score`];function Yji(){let{scorerId:e}=Yy(),[t,n]=nb(),r=t.get(`scoreId`)??void 0,[i,a]=(0,G.useState)(r),[o,s]=(0,G.useState)(!1),c=Jy(),[l,u]=(0,G.useState)({value:`all`,label:`All Entities`,type:`ALL`}),{scorer:d,error:f}=UTt(e),p=Gji(),{data:m={},isLoading:h,error:g}=WA(),{isLoading:_,error:v}=gA({}),{sort:y,onSortChange:b}=pP({searchParams:t,setSearchParams:n,allowedKeys:Jji}),{data:x=[],isLoading:S,error:C,isFetchingNextPage:w,hasNextPage:T,setEndOfListElement:E}=HTt({scorerId:e,entityId:l?.value===`all`?void 0:l?.value,entityType:l?.type===`ALL`?void 0:l?.type}),D=(0,G.useMemo)(()=>k4(x,y,{date:e=>e.createdAt,score:e=>typeof e.score==`number`?e.score:void 0}),[x,y]),O=(0,G.useMemo)(()=>d?.agentIds?.filter(e=>m[e]).map(e=>({value:e,label:m[e].name,type:`AGENT`}))||[],[d?.agentIds,m]),k=(0,G.useMemo)(()=>d?.workflowIds?.map(e=>({value:e,label:e,type:`WORKFLOW`}))||[],[d?.workflowIds]),A=(0,G.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,G.useEffect)(()=>{if(f){let e=f instanceof Error?f.message:`Failed to load scorer`;vn.error(`Error loading scorer: ${e}`)}},[f]),(0,G.useEffect)(()=>{if(g){let e=g instanceof Error?g.message:`Failed to load agents`;vn.error(`Error loading agents: ${e}`)}},[g]),(0,G.useEffect)(()=>{if(v){let e=v instanceof Error?v.message:`Failed to load workflows`;vn.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,G.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,G.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=Ej(f)||Ej(g)||Ej(v),I=f&&Dj(f),L=!F&&!I&&(f||g||v),R=!S&&D.length===0,z=l?.value!==`all`,B=d?.source===`stored`,ee=e?(0,K.jsx)(c7,{open:o,onOpenChange:s,initialScorerIds:[e],onSuccess:e=>void c(`/experiments/${e}`)}):null,V=B?(0,K.jsxs)(TT,{children:[(0,K.jsx)(TT.Trigger,{asChild:!0,children:(0,K.jsx)(U,{size:`icon-lg`,"aria-label":`Scorer actions menu`,children:(0,K.jsx)(ET,{})})}),(0,K.jsx)(TT.Content,{align:`end`,className:`w-48`,children:(0,K.jsxs)(TT.Item,{onSelect:()=>void c(`/cms/scorers/${e}/edit`),children:[(0,K.jsx)(Bj,{}),` 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,K.jsxs)(Xb,{variant:`page`,breadcrumbs:(0,K.jsx)(IA,{crumbs:qji}),actionRow:!(F||I||L)&&V?(0,K.jsx)(_M,{children:(0,K.jsx)(_M.End,{children:V})}):void 0,children:[(0,K.jsx)(`h1`,{className:`sr-only`,children:e}),(0,K.jsx)(`div`,{className:`flex h-full items-center justify-center`,children:F?(0,K.jsx)(oI,{}):I?(0,K.jsx)(aI,{resource:`scorers`}):L?(0,K.jsx)(db,{tone:`error`,titleSlot:`Failed to load scorer`,descriptionSlot:t}):(0,K.jsx)(BWr,{onRunExperiment:()=>s(!0)})}),ee]})}return(0,K.jsxs)(Xb,{variant:`page`,breadcrumbs:(0,K.jsx)(IA,{crumbs:qji}),actionRow:(0,K.jsxs)(_M,{children:[(0,K.jsx)(_M.Start,{children:(0,K.jsx)(VWr,{selectedEntity:l,entityOptions:A,onEntityChange:N,onReset:()=>{n(e=>{let t=new URLSearchParams(e);return t.set(`entity`,`all`),t})},isLoading:S||h||_})}),(0,K.jsxs)(_M.End,{children:[(0,K.jsx)(Kji,{visibleColumns:p.visibleColumns,toggleColumn:p.toggleColumn}),(0,K.jsx)(U,{variant:`primary`,onClick:()=>s(!0),icon:(0,K.jsx)(ab,{}),children:`New experiment`}),V]})]}),children:[(0,K.jsx)(`h1`,{className:`sr-only`,children:e}),(0,K.jsx)(zWr,{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 Xji=_(`IconMoon`,()=>(0,K.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`})),Zji=_(`IconSun`,()=>(0,K.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`})),Qji=[{value:`system`,label:`System`,icon:(0,K.jsx)(vBr,{})},{value:`light`,label:`Light`,icon:(0,K.jsx)(Zji,{})},{value:`dark`,label:`Dark`,icon:(0,K.jsx)(Xji,{})}];function $ji(e,t){if(e.some(e=>e.value===t))return t;let[n]=e;return n?n.value:`system`}var eMi=({value:e,onChange:t,options:n=Qji,size:r=`md`,"aria-label":i=`Theme`,...a})=>{let{theme:o,setTheme:s}=Zr(),c=e??o,l=t??s,u=$ji(n,c);return(0,K.jsx)(uTt,{...a,"aria-label":i,iconOnly:!0,size:r===`xs`?`sm`:r,value:u,onValueChange:l,children:n.map(e=>(0,K.jsx)(dTt,{value:e.value,"aria-label":e.label,children:e.icon},e.value))})};function tMi(e){return Object.fromEntries(e.filter(e=>e.name.trim()).map(e=>[e.name.trim(),e.value]))}function nMi(e,t){return e.baseUrl.trim()===t.baseUrl.trim()&&e.apiPrefix.trim()===(t.apiPrefix??``).trim()&&JSON.stringify(tMi(e.headers))===JSON.stringify(t.headers)}function rMi({initialConfig:e}){let{setConfig:t}=kb(),n=(0,G.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,G.useState)(r),[o,s]=(0,G.useState)(),c=!nMi(i,e),l=(0,K.jsx)(U,{type:`button`,size:`sm`,icon:(0,K.jsx)(ab,{}),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:tMi(i.headers)}),vn.success(`Connection saved`)):s(`Enter the server URL`)}function f(){a(r()),s(void 0)}return(0,K.jsx)(`form`,{onSubmit:d,onReset:f,noValidate:!0,children:(0,K.jsxs)(Cj,{children:[(0,K.jsx)(Sj,{label:`Mastra instance URL`,description:`The server this studio talks to.`,errorMsg:o,children:(0,K.jsx)(ak,{name:`url`,value:i.baseUrl,placeholder:`http://localhost:4111`,spellCheck:!1,onChange:e=>{a(t=>({...t,baseUrl:e.target.value})),s(void 0)}})}),(0,K.jsx)(Sj,{label:`API prefix`,description:`Path in front of every API route.`,children:(0,K.jsx)(ak,{name:`apiPrefix`,value:i.apiPrefix,placeholder:`/api (default)`,spellCheck:!1,onChange:e=>a(t=>({...t,apiPrefix:e.target.value}))})}),i.headers.length===0?(0,K.jsx)(_4,{action:l,children:`No request headers`}):(0,K.jsx)(kVr,{action:l,children:i.headers.length===1?`1 request header`:`${i.headers.length} request headers`}),i.headers.map(e=>(0,K.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,K.jsx)(ak,{"aria-label":`Header name`,value:e.name,placeholder:`Authorization`,spellCheck:!1,onChange:t=>u(e.id,{name:t.target.value})}),(0,K.jsx)(ak,{"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,K.jsx)(U,{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,K.jsx)(rk,{})})]},e.id)),c?(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,K.jsx)(`span`,{className:`text-body-sm text-muted-foreground`,children:`Unsaved changes`}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(U,{type:`reset`,size:`sm`,variant:`ghost`,children:`Discard`}),(0,K.jsx)(U,{type:`submit`,size:`sm`,variant:`primary`,children:`Save changes`})]})]}):null]})})}function iMi(){let{baseUrl:e,apiPrefix:t,headers:n}=kb(),r=JSON.stringify([e,t??``,n]);return(0,K.jsxs)(h4,{children:[(0,K.jsx)(g4,{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,K.jsx)(rMi,{initialConfig:{baseUrl:e,apiPrefix:t,headers:n}},r)]})}var aMi=()=>(0,K.jsxs)(Xb,{variant:`settings`,title:`Settings`,children:[(0,K.jsxs)(h4,{children:[(0,K.jsx)(g4,{info:`Stored in this browser.`,children:`General`}),(0,K.jsx)(Cj,{children:(0,K.jsx)(Sj,{label:`Theme`,description:`Color scheme for the interface.`,children:(0,K.jsx)(eMi,{})})})]}),(0,K.jsx)(iMi,{})]});function oMi(){let[e]=nb(),t=Jy(),n=e.get(`redirect`)||`/`;return(0,K.jsx)(Bxi,{redirectUri:n,onSuccess:()=>{n.startsWith(`http`)?window.location.href=n:t(n,{replace:!0})},initialMode:`signup`})}var sMi=[`traces`,`spans`],cMi={traces:{icon:(0,K.jsx)(_I,{}),label:`Traces`},spans:{icon:(0,K.jsx)($H,{}),label:`Spans`},threads:{icon:(0,K.jsx)($q,{}),label:`Threads`}};function lMi({current:e,views:t=sMi,onViewChange:n}){return(0,K.jsx)(`nav`,{"aria-label":`Observability views`,children:(0,K.jsx)(DE,{value:e,defaultTab:e,onValueChange:n,children:(0,K.jsx)(EE,{variant:`pill-ghost`,children:t.map(e=>(0,K.jsxs)(OE,{value:e,children:[(0,K.jsx)(gr,{size:`xs`,children:cMi[e].icon}),(0,K.jsx)(W,{variant:`caption`,className:`text-inherit`,children:cMi[e].label})]},e))})})})}function uMi(){return(0,K.jsxs)(`div`,{role:`status`,"aria-label":`Loading views`,className:`flex min-h-control-md items-center gap-0.5`,children:[(0,K.jsx)(Zb,{className:`h-control-md w-20 rounded-full`}),(0,K.jsx)(Zb,{className:`h-control-md w-20 rounded-full`})]})}function dMi({current:e,views:{views:t,isLoading:n,showSwitch:r},onViewChange:i,breadcrumbs:a,children:o}){let[s,c]=(0,G.useState)(null),l=kai(),u;return n?u=(0,K.jsx)(uMi,{}):r&&(u=(0,K.jsx)(lMi,{current:e,views:t,onViewChange:i})),(0,K.jsx)(Xb,{variant:`page`,breadcrumbs:a({current:e,isLoading:n,showSwitch:r}),actionRow:(u||l)&&(0,K.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center justify-between gap-3`,children:[u,(0,K.jsx)(`div`,{ref:c,className:`flex min-w-0 grow justify-end`})]}),children:(0,K.jsx)(jsi.Provider,{value:s??void 0,children:o})})}function fMi({isLoading:e,enabled:t,heading:n,title:r,description:i,children:a}){return t?a:(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`h1`,{className:`sr-only`,children:n}),e?(0,K.jsxs)(`div`,{className:`flex h-full items-center justify-center gap-2`,children:[(0,K.jsx)(pt,{"aria-label":`Loading storage capabilities`}),(0,K.jsx)(W,{as:`span`,variant:`caption`,tone:`muted`,children:`Loading storage capabilities`})]}):(0,K.jsx)(db,{variant:`fill`,titleSlot:r,descriptionSlot:i})]})}function pMi({current:e,features:t}){let n=aci(),r=oci(),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 mMi={refetchInterval:({state:e})=>$si(e.error),refetchOnWindowFocus:!1};function hMi(e){let[t,n]=(0,G.useState)(()=>new URLSearchParams);return e||{searchParams:t,setSearchParams:e=>n(t=>typeof e==`function`?e(t):e)}}function gMi(e,{sortFields:t,withTokenSearch:n=!1,defaultDatePreset:r=A5}={}){let{searchParams:i,setSearchParams:a}=hMi(e),o=JSON.stringify(zai(i,r)),s=JSON.stringify(Vai(i)),{datePreset:c,dateFrom:l,dateTo:u}=(0,G.useMemo)(()=>zai(i,r),[o]),{tokens:d,groups:f}=(0,G.useMemo)(()=>{let e=Vai(i);return n?e:{...e,tokens:e.tokens.filter(e=>e.operatorId!==`hasAllTokens`)}},[s,n]),p=Uai(i,t??Mai),m=(0,G.useMemo)(()=>({field:p.field,direction:p.direction}),[p.field,p.direction]),h=l?.getTime(),g=u?.getTime(),_=(0,G.useMemo)(()=>{let e=new Date,t=t8r(c,h===void 0?void 0:new Date(h),g===void 0?void 0:new Date(g),e);return R6(t.dateFrom,t.dateTo,e)},[c,h,g]),v=(0,G.useRef)(null);(0,G.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=>Bai(t,e(zai(t,r)),r)),x=(0,G.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=bai(x.current,n,e,t),{datePreset:`custom`,dateFrom:e,dateTo:t})),D=e=>b(t=>{let n=xai(x.current,t);return x.current=void 0,n??{datePreset:e}}),O=(e,t)=>y(n=>Hai(n,{tokens:e,groups:t})),k=e=>y(t=>Wai(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 _Mi(e){return[`observability-list-head`,...e]}function vMi(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 yMi(e,t=!1){let n=Pv([e]),[r,i]=(0,G.useState)();return{anchorWindow:r?.selectionHash===n?r.window:void 0,reanchor:e=>i({selectionHash:n,window:vMi(e,new Date().toISOString(),t)})}}var bMi=()=>({rows:[],watermark:void 0});function xMi({queryKey:e,fetchHead:t,getId:n,getEndedAt:r,enabled:i,since:a,limit:o=50,maxRows:s=500,interval:c=Ysi,onOverflow:l}){let u=Av(),d=_Mi(e),{data:f}=Gv({queryKey:d,queryFn:async()=>{let e=u.getQueryData(d)??bMi(),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?.(),bMi();let m=c.length>0?Math.max(e.watermark??-1/0,...c):e.watermark;return{rows:[...f.values()],watermark:m}},initialData:bMi,staleTime:1/0,enabled:i,refetchInterval:e=>!Zsi(e.state.error)&&c,refetchOnWindowFocus:!1,refetchOnReconnect:!1,retry:!1});return{headRows:f.rows}}function SMi(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 CMi(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),SMi(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 wMi={traces:`Traces`,spans:`Spans`,threads:`Threads`};function TMi({current:e,isLoading:t,showSwitch:n}){if(!(t||n||e===`traces`))return wMi[e]}function EMi(e){let t=e.get(`traceId`),n=e.get(`spanId`);return t&&n?{traceId:t,spanId:n}:void 0}function DMi(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 OMi({traceId:e,spanId:t}){return new URLSearchParams({traceId:e,spanId:t})}function kMi(e){return e.get(`threadId`)??void 0}function AMi(e,t){let n=new URLSearchParams(e);return t?n.set(`threadId`,t):n.delete(`threadId`),n}var jMi=e=>`${e.traceId}:${e.spanId}`;function MMi(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 NMi({query:e,rolling:t,fixedStart:n=!1,autoRefetch:r=!0,limit:i,enabled:a=!0}){let o=X(),{anchorWindow:s,reanchor:c}=yMi(e,n),l=(0,G.useMemo)(()=>s?{...e,timeRange:{...e.timeRange,...s}}:e,[e,s]),u=S4r({query:l,limit:i,enabled:a,queryOptions:mMi}),{headRows:d}=xMi({queryKey:[`spans`,e],fetchHead:async t=>(await o.querySpans({...e,timeRange:{...e.timeRange,...vMi(e.timeRange,t,n)},orderBy:[{field:`endedAt`,direction:`desc`}],page:{limit:50}})).spans,getId:jMi,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,G.useMemo)(()=>p&&CMi(p,d,{getId:jMi,compare:MMi(f),hasNextPage:u.hasNextPage}),[p,d,f,u.hasNextPage]);return{...u,spans:m}}function PMi(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 FMi({timeRange:e,where:t,onZoom:n}){let r=sci(),i=(0,G.useMemo)(()=>({timeRange:e,...t?{where:t}:{},interval:p8r(e).interval,measures:[...o8r],limit:1}),[e,t]),a=!r.enabled||m8r(e),{data:o,isLoading:s,isError:c,isPlaceholderData:l}=i4r({request:i,enabled:!a,queryOptions:{placeholderData:Lv}}),u=(0,G.useMemo)(()=>y8r(o?.rows??[],e),[o,e]);return a?null:(0,K.jsx)(z7r,{label:`Spans over time`,resourceLabel:`Spans`,buckets:u,isLoading:s,isError:c,isUpdating:l,onZoom:n&&(t=>n(b8r(u,t,e)))})}var IMi=[`last-24h`,`last-3d`,`last-7d`,`last-14d`,`last-30d`,`custom`],LMi=[];function RMi({timeRange:e,withTokenSearch:t=!1}){let n=X(),{data:r}=G5(),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=LMi}=O6(),{data:u=LMi}=k6();return(0,G.useMemo)(()=>[aM,...C6(Soi({withContextFields:i,withTimeToFirstChunk:a,withTimeToFirstToken:o,withOutcomeFields:s,withModelFields:c,entityNames:l,environments:u,valueSuggestions:t=>l3r(n,e,`spans`,t)}),t)],[t,i,a,o,s,c,l,u,n,e])}function zMi({tokens:e,groups:t,onFiltersChange:n}){let r=(0,G.useMemo)(()=>s8(e),[e]),i=(0,G.useMemo)(()=>{let e=c8([],t);return{...e,nodes:[oM,...r,...e.nodes]}},[r,t]),a=(0,G.useCallback)(e=>{let t=b6r({...e,nodes:e.nodes.filter(e=>zj(e)||e.fieldId!==`timeRange`)});n(t.tokens,t.groups)},[n]);return{filterBarValue:i,onFilterBarChange:a,onFilterByField:(0,G.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(zj);a({...i,nodes:[...n,o,...s]})},[r,i,a])}}var BMi=e=>e;function VMi({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=RMi({timeRange:a,withTokenSearch:e}),{filterBarValue:g,onFilterBarChange:_}=zMi({tokens:o,groups:s,onFiltersChange:f});return(0,K.jsxs)(pM,{fields:h,operators:q3r,value:g,onValueChange:_,createItemId:BMi,describeSuggestionsError:p,maxDepth:3,"aria-label":`Span filters`,className:`min-w-64 flex-1`,children:[(0,K.jsx)(pM.Chips,{renderChip:e=>e.fieldId===`timeRange`?(0,K.jsx)(pM.TimeRange,{preset:t,onPresetChange:c,dateFrom:n,dateTo:r,minDate:i,onDateChange:l,onDateRangeChange:u,disabled:m,presets:IMi,defaultPreset:f8.datePreset,onReset:d&&(()=>d(f8.datePreset))}):(0,K.jsx)(pM.Chip,{item:e})}),(0,K.jsx)(pM.Input,{placeholder:`Filter spans`})]})}var HMi={supported:!1,isLoading:!1};function UMi(e){let t=K5(),n=aci(),r=oci();return e===`spans`?n:e===`threads`?r:t}var WMi=(0,G.memo)(function({scope:e,value:t,onChange:n,discoveryTimeRange:r,metricsSupport:i=HMi,queryEnabled:a=!0}){let o=b6[e],s=UMi(e),c=cci(),{data:l}=G5(),[u]=(0,G.useState)(()=>R6(void 0,void 0,new Date)),d=s.enabled&&a,f=d&&(l?.capabilities.traceQueryTimeToFirstChunk??!1),p=d&&(l?.capabilities.traceQueryTimeToFirstToken??!1),m=(0,G.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}=u3r({timeRange:r??u,queryOptions:{enabled:o.metadata&&d&&c.enabled}}),g=(0,G.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?x8r:i.supported?void 0:S8r;return(0,K.jsx)(G8r,{preferences:t,catalog:m,availableMetadataKeys:g,usageDisabledReason:_,withQueryTrace:d,disabled:s.isLoading,onToggleColumn:e=>n(T2r(t,e)),onAddCustomColumn:e=>n(E2r(t,e)),onRemoveCustomColumn:e=>n(D2r(t,e)),onAddMetadataColumn:e=>n(O2r(t,e)),onRemoveMetadataColumn:e=>n(k2r(t,e)),onReset:()=>n(o.defaults)})});function GMi({selection:e,onSelectionChange:t,renderPanel:n,urlState:r}){let{data:i,isLoading:a}=G5(),o=!!(i?.capabilities.spanQueryTokenSearch&&i.capabilities.spanAggregateTokenSearch),s=gMi(r,{sortFields:Nai,withTokenSearch:o}),{timeRange:c,tokens:l,groups:u}=s,d=Wsi({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,G.useMemo)(()=>a?d.preferences:w2r(d.preferences,{withTimeToFirstChunk:p,withTimeToFirstToken:m}),[d.preferences,a,p,m]),v=(0,G.useMemo)(()=>{let e=[`startedAt`];return p&&i?.capabilities.traceQueryTimeToFirstChunkSort&&x6(_,`timeToFirstChunk`)&&e.push(`timeToFirstChunkMs`),m&&i?.capabilities.traceQueryTimeToFirstTokenSort&&x6(_,`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,G.useMemo)(()=>Toi(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}=NMi({query:(0,G.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,G.useMemo)(()=>(C??[]).map(PMi),[C]),j=(0,G.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,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`h1`,{className:`sr-only`,children:`Spans`}),(0,K.jsx)(B8r,{toolbar:(0,K.jsxs)(K.Fragment,{children:[r&&(0,K.jsx)(zsi,{page:`spans`,...r,columns:d}),(0,K.jsxs)(_M,{children:[(0,K.jsx)(_M.Start,{children:(0,K.jsx)(VMi,{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,K.jsx)(_M.End,{children:(0,K.jsx)(WMi,{scope:`spans`,value:d.preferences,onChange:d.setPreferences})})]})]}),chart:(0,K.jsx)(FMi,{timeRange:c,where:S,onZoom:({from:e,to:t})=>s.onZoom(e,t)}),error:O?(0,K.jsx)(_6,{error:k,resource:`spans`,errorTitle:`Failed to load spans`}):void 0,empty:N?(0,K.jsx)(i2r,{resource:`spans`,datePreset:s.datePreset,dateFrom:s.dateFrom,dateTo:s.dateTo}):void 0,children:(0,K.jsx)(uei,{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 KMi({selection:e,spans:t,onSelect:n,onClose:r,onShowTrace:i}){let{data:a,isLoading:o}=A6({traceId:e.traceId,spanId:e.spanId}),s=r7(),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,K.jsx)(dai,{traceId:e.traceId,spanId:e.spanId,span:a?.span,isLoading:o,input:(0,K.jsx)(Q5,{}),output:(0,K.jsx)($5,{}),navigation:s,onPrevious:l?()=>n(l):void 0,onNext:u?()=>n(u):void 0,onClose:r,onShowTrace:i})}function qMi({selection:e,spans:t,onSelect:n,onClose:r,onShowTrace:i}){let a=uS();N0r(e?`${e.traceId}:${e.spanId}`:void 0,r);let o=e?(0,K.jsx)(KMi,{selection:e,spans:t,onSelect:n,onClose:r,onShowTrace:i}):null;return a?(0,K.jsx)(uj,{open:!!e,onClose:r,title:`Span details`,children:o}):o?(0,K.jsx)(c6,{owner:`span-detail`,children:(0,K.jsx)(uj,{variant:`inline`,title:`Span details`,children:o})}):null}function JMi(){let{enabled:e,isLoading:t}=aci(),n=Jy(),[r,i]=nb();return(0,K.jsx)(fMi,{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,K.jsx)(GMi,{urlState:{searchParams:r,setSearchParams:i},selection:EMi(r),onSelectionChange:e=>i(t=>DMi(t,e),{replace:!0}),renderPanel:e=>(0,K.jsx)(qMi,{...e,onShowTrace:e=>n(`/traces?${OMi(e)}`)})})})}async function YMi(){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 XMi({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 ZMi({repoOrSlug:e,owner:t}){let{templates:n}=await YMi(),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 XMi({repo:e,owner:t});if(r)return r;throw Error(`Template ${e} not found`)}return r}async function QMi({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(`
879
- `).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 $Mi=({queryOptions:e}={})=>Gv({queryKey:[`mastra-templates`],queryFn:YMi,...e}),eNi=({repoOrSlug:e,owner:t,queryOptions:n})=>Gv({queryKey:[`template-repo`,e,t],queryFn:()=>ZMi({repoOrSlug:e,owner:t}),...n}),tNi=({repo:e,owner:t,branch:n,queryOptions:r})=>Gv({queryKey:[`template-repo-env-vars`,e,t,n],queryFn:()=>QMi({repo:e,owner:t,branch:n}),...r}),nNi=({queryOptions:e}={})=>{let t=X();return Gv({queryKey:[`agent-builder-workflow`],queryFn:async()=>await t.getAgentBuilderAction(`merge-template`).details(),...e})},rNi=({queryOptions:e}={})=>{let t=X();return qv({mutationFn:async({runId:e})=>await t.getAgentBuilderAction(`merge-template`).createRun({runId:e}),...e})},iNi=({queryOptions:e}={})=>{let t=X();return qv({mutationFn:async({runId:e})=>await t.getAgentBuilderAction(`merge-template`).runById(e),...e})},aNi=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)},oNi=(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=aNi(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=aNi(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}},sNi=(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)}},cNi=(e,t)=>{let[n,r]=(0,G.useState)({}),[i,a]=(0,G.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}=oNi(a,s,e);s=c,r(c),(a.runId||i||t)&&sNi(a.runId||i||t,c)}}catch(t){console.error(`💥 [processStream] Error processing template installation stream:`,t);let{newState:n}=oNi({type:`error`,payload:{error:t instanceof Error?t.message:`Unknown error`}},s,e);r(n)}finally{a(!1),o.releaseLock()}}}},lNi=({workflowInfo:e,queryOptions:t}={})=>{let n=X(),{streamResult:r,isStreaming:i,processStream:a}=cNi(e);return{streamInstall:qv({mutationFn:async({inputData:e,selectedModel:t,runId:r})=>{for(let i=1;i<=3;i++)try{let i=n.getAgentBuilderAction(`merge-template`),o=new Ha;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}},uNi=({workflowInfo:e,queryOptions:t}={})=>{let n=X(),{streamResult:r,isStreaming:i,processStream:a}=cNi(e);return{observeInstall:qv({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 dNi(e){return e.replace(/\/$/,``).split(`/`).pop()}function fNi({templates:e,linkComponent:t,className:n,isLoading:r}){let i=t||`a`;return r?(0,K.jsx)(`div`,{className:T(`grid gap-y-4`,n),children:Array.from({length:5}).map((e,t)=>(0,K.jsx)(`div`,{className:`h-16 animate-pulse rounded-lg bg-card`},t))}):(0,K.jsx)(`div`,{className:T(`grid gap-y-4`,n),children:e.map(e=>{let t=e?.agents||e?.tools||e?.networks||e?.workflows||e?.mcp;return(0,K.jsxs)(`article`,{className:T(kr,`grid w-full grid-cols-[1fr_auto] overflow-hidden rounded-lg state-layer`),children:[(0,K.jsxs)(i,{to:`/templates/${e.slug}`,className:T(`group grid`,{"grid-cols-[8rem_1fr] lg:grid-cols-[12rem_1fr]":e.imageURL}),children:[e.imageURL&&(0,K.jsx)(`div`,{className:`overflow-hidden`,children:(0,K.jsx)(`div`,{className:`thumb transition-scale h-full w-full bg-cover duration-150`,style:{backgroundImage:`url(${e.imageURL})`}})}),(0,K.jsxs)(`div`,{className:T(`grid w-full gap-0.5 px-4 py-3`,`[&_svg]:h-[1em] [&_svg]:w-[1em] [&_svg]:text-muted-foreground`),children:[(0,K.jsx)(W,{as:`h2`,tone:`ink`,children:e.title}),(0,K.jsx)(W,{className:T(Nb,x),children:e.description}),(0,K.jsxs)(`div`,{className:`mt-3 hidden flex-wrap items-center gap-x-8 gap-y-4 text-muted-foreground 2xl:flex`,children:[t&&(0,K.jsxs)(`ul`,{className:T(`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,K.jsx)(`li`,{children:(0,K.jsxs)(W,{as:`span`,variant:`body`,className:`block`,children:[(0,K.jsx)(FM,{}),` `,e.agents.length]})}),e?.tools&&e.tools.length>0&&(0,K.jsx)(`li`,{children:(0,K.jsxs)(W,{as:`span`,variant:`body`,className:`block`,children:[(0,K.jsx)(HM,{}),` `,e.tools.length]})}),e?.networks&&e.networks.length>0&&(0,K.jsx)(`li`,{children:(0,K.jsxs)(W,{as:`span`,variant:`body`,className:`block`,children:[(0,K.jsx)(Mtt,{}),` `,e.networks.length]})}),e?.workflows&&e.workflows.length>0&&(0,K.jsx)(`li`,{children:(0,K.jsxs)(W,{as:`span`,variant:`body`,className:`block`,children:[(0,K.jsx)(cx,{}),` `,e.workflows.length]})}),e?.mcp&&e.mcp.length>0&&(0,K.jsx)(`li`,{children:(0,K.jsxs)(W,{as:`span`,variant:`body`,className:`block`,children:[(0,K.jsx)(LM,{}),` `,e.mcp.length]})})]}),(0,K.jsx)(`div`,{className:`flex items-center gap-4`,children:e.supportedProviders.map(e=>(0,K.jsx)(W,{tone:`muted`,as:`span`,variant:`body`,children:e},e))})]})]})]}),(0,K.jsx)(`a`,{href:e.githubUrl,className:T(`group ml-auto hidden items-center gap-2 pr-4`,`lg:flex`),target:`_blank`,rel:`noopener noreferrer`,children:(0,K.jsx)(W,{as:`span`,variant:`body`,children:(0,K.jsxs)(`span`,{className:T(`flex items-center gap-2 rounded bg-nested px-2 py-1`,ct,Nb,x),children:[(0,K.jsx)(T4,{}),` `,dNi(e.githubUrl)]})})})]},e.slug)})})}function pNi({tagOptions:e,selectedTag:t,providerOptions:n,selectedProvider:r,onTagChange:i,onProviderChange:a,searchTerm:o,onSearchChange:s,onReset:c,className:l,isLoading:u}){return u?(0,K.jsxs)(`div`,{className:T(`flex h-[6.5rem] items-center gap-5`,`[&>div]:h-8 [&>div]:w-48 [&>div]:animate-pulse [&>div]:bg-card`,l),children:[(0,K.jsx)(`div`,{}),` `,(0,K.jsx)(`div`,{}),` `,(0,K.jsx)(`div`,{})]}):(0,K.jsxs)(`div`,{className:T(`sticky top-0 mx-auto flex flex-wrap gap-1.5 bg-background py-5`,l),children:[(0,K.jsx)($A,{label:`Search templates`,placeholder:`Search templates`,size:`sm`,value:o,onValueChange:s}),(0,K.jsxs)(ZE,{value:t,onValueChange:i,children:[(0,K.jsx)($E,{"aria-label":`Search by tag`,size:`sm`,className:`w-auto`,children:(0,K.jsx)(QE,{placeholder:`Select an option`})}),(0,K.jsx)(eD,{children:e.map(e=>(0,K.jsx)(tD,{value:e.value,children:e.label},e.value))})]}),(0,K.jsxs)(ZE,{value:r,onValueChange:a,children:[(0,K.jsx)($E,{"aria-label":`Search by provider`,size:`sm`,className:`w-auto`,children:(0,K.jsx)(QE,{placeholder:`Select an option`})}),(0,K.jsx)(eD,{children:n.map(e=>(0,K.jsx)(tD,{value:e.value,children:e.label},e.value))})]}),c&&(0,K.jsx)(tM,{onClick:c})]})}var mNi=[{id:`templates`,label:`Templates`}];function hNi(){let{data:e,isLoading:t}=$Mi(),{templates:n,tags:r,providers:i}=e??{templates:[],tags:[],providers:[]},[a,o]=(0,G.useState)(`all`),[s,c]=(0,G.useState)(`all`),[l,u]=(0,G.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,K.jsxs)(Xb,{variant:`page`,breadcrumbs:(0,K.jsx)(IA,{crumbs:mNi}),children:[(0,K.jsx)(`h1`,{className:`sr-only`,children:`Templates`}),(0,K.jsx)(Pb,{children:(0,K.jsxs)(wWe,{children:[(0,K.jsx)(gr,{children:(0,K.jsx)(w4,{})}),`Templates`]})}),(0,K.jsx)(pNi,{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,K.jsx)(fNi,{templates:g,linkComponent:tb,isLoading:t})]})}var gNi=_(`IconEmojiSad`,()=>(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`circle`,{cx:`12`,cy:`12`,r:`9`,stroke:`currentColor`,strokeWidth:`2`}),(0,K.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,K.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,K.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 _Ni({children:e,className:t}){return(0,K.jsx)(`div`,{className:T(`transition-height mt-12 rounded-lg border border-border px-4 py-5 lg:min-h-[25rem] lg:px-12`,t),children:e})}function vNi({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,K.jsx)(mb,{className:`text-warning-foreground`}),title:`Template Installed with Warnings`}:{icon:(0,K.jsx)(gNi,{}),title:`Template Installation Failed`};return(0,K.jsxs)(_Ni,{className:`mb-5 content-center space-y-4 text-muted-foreground`,children:[(0,K.jsxs)(`div`,{className:`grid content-center items-center justify-items-center gap-4 [&>svg]:h-8 [&>svg]:w-8`,children:[o,(0,K.jsxs)(`div`,{className:`space-y-2 text-center`,children:[(0,K.jsx)(W,{variant:`subheading`,tone:`ink`,children:s}),(0,K.jsx)(W,{tone:`muted`,children:a()})]})]}),t&&t.length>0&&(0,K.jsxs)(`details`,{children:[(0,K.jsx)(`summary`,{className:T(`text-muted-foreground hover:text-foreground`,`cursor-pointer text-center select-none`),children:(0,K.jsxs)(W,{as:`span`,variant:`caption`,className:`block`,children:[`Show Validation Issues (`,t.length,`)`]})}),(0,K.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,K.jsxs)(`div`,{className:`border-l-2 border-destructive-indicator pl-2`,children:[(0,K.jsx)(W,{as:`p`,variant:`column`,className:`text-destructive-foreground`,children:e.type===`typescript`?`🔴 TypeScript Error`:`⚠️ Lint Error`}),(0,K.jsx)(yx,{className:`mt-1 text-caption wrap-break-word whitespace-pre-wrap text-muted-foreground`,code:e.message})]},t))})]}),n&&!i&&(0,K.jsxs)(`details`,{children:[(0,K.jsx)(`summary`,{className:T(`text-muted-foreground hover:text-foreground`,`cursor-pointer text-center select-none`),children:(0,K.jsx)(W,{as:`span`,variant:`caption`,className:`block`,children:`Show Details`})}),(0,K.jsx)(`div`,{className:`mt-4 max-h-60 overflow-auto rounded bg-muted p-3 text-left`,children:(0,K.jsx)(yx,{className:`text-caption wrap-break-word whitespace-pre-wrap`,code:n})})]})]})}function yNi({providerOptions:e,selectedProvider:t,onProviderChange:n,variables:r,errors:i,handleInstallTemplate:a,handleVariableChange:o,isLoadingEnvVars:s,isInstalling:c,defaultModelProvider:l,defaultModelId:u,onModelUpdate:d}){return(0,K.jsx)(_Ni,{children:(0,K.jsxs)(`div`,{className:`mx-auto my-4 grid max-w-[40rem] gap-5 p-4 lg:p-5`,children:[(0,K.jsxs)(W,{as:`h2`,variant:`heading`,tone:`muted`,className:T(`flex items-center gap-2`,`[&_svg]:h-[1.2em] [&_svg]:opacity-70 [&>svg]:w-[1.2em]`),children:[`Install Template `,(0,K.jsx)(w4,{})]}),(0,K.jsxs)(gE,{orientation:`horizontal`,children:[(0,K.jsx)(vE,{children:`Template AI Model Provider`}),(0,K.jsx)(Pat,{className:`flex-1`,children:(0,K.jsxs)(ZE,{name:`template-provider`,value:t,onValueChange:n,children:[(0,K.jsx)($E,{size:`md`,children:(0,K.jsx)(QE,{placeholder:`Select`})}),(0,K.jsx)(eD,{children:e.map(e=>(0,K.jsx)(tD,{value:e.value,children:e.label},e.value))})]})})]}),t&&Object.entries(r||{}).length>0&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(W,{as:`h3`,tone:`muted`,children:`Set required Environmental Variables`}),(0,K.jsx)(`div`,{className:`grid grid-cols-[1fr_1fr] items-start gap-4`,children:s?(0,K.jsxs)(`div`,{className:T(`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,K.jsx)(pt,{}),(0,K.jsxs)(W,{as:`span`,variant:`caption`,className:`block`,children:[` `,`Loading variables...`]})]}):Object.entries(r).map(([e,t])=>(0,K.jsxs)(G.Fragment,{children:[(0,K.jsxs)(gE,{className:`w-full`,children:[(0,K.jsx)(vE,{className:`sr-only`,children:`Key`}),(0,K.jsx)(ak,{name:`env-${e}`,value:e,disabled:!0,className:`w-full`})]}),(0,K.jsxs)(gE,{invalid:i.includes(e),className:`w-full`,children:[(0,K.jsx)(vE,{className:`sr-only`,children:`Value`}),(0,K.jsx)(ak,{name:e,value:t,onChange:o,autoComplete:`off`,className:`w-full`}),(0,K.jsx)(bE,{children:i.includes(e)?`Value is required.`:void 0})]})]},e))}),(0,K.jsxs)(`div`,{className:`relative mt-3.5 border-t border-border pt-12`,children:[(0,K.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,K.jsx)(W,{tone:`muted`,as:`span`,variant:`caption`,className:`block`,children:`And`})}),(0,K.jsx)(W,{as:`h3`,tone:`muted`,children:`Set AI Model for Template Installation`}),(0,K.jsx)(W,{tone:`muted`,className:`mt-2 mb-5`,children:`This model will be used by the workflow to process and install the template`}),(0,K.jsx)(T0r,{defaultProvider:l||``,defaultModel:u||``,updateModel:d||(()=>Promise.resolve({message:`Updated`})),closeEditor:()=>{},autoSave:!0,selectProviderPlaceholder:`Provider`})]})]}),t&&!s&&(0,K.jsx)(U,{className:T(`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||!l||!u||i.length>0,iconEnd:(0,K.jsx)(nM,{}),loading:c,children:`Install`})]})})}function bNi({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,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`mt-5 grid items-center`,children:(0,K.jsxs)(`div`,{className:T(`flex items-center gap-3`,`[&>svg]:h-[1.2em] [&>svg]:w-[1.2em] [&>svg]:opacity-50`,{"[&>svg]:opacity-20":r}),children:[(0,K.jsx)(w4,{}),(0,K.jsx)(`h2`,{className:T({"flex min-w-[50%] rounded-lg bg-muted":r}),children:(0,K.jsx)(W,{as:`span`,variant:`title`,className:`block`,children:r?(0,K.jsx)(K.Fragment,{children:`\xA0`}):e})})]})}),(0,K.jsxs)(`div`,{className:`grid gap-x-24 lg:grid-cols-[1fr_1fr]`,children:[(0,K.jsxs)(`div`,{className:`grid`,children:[(0,K.jsx)(W,{tone:`muted`,className:T(`mt-2 mb-4`,{"rounded-lg bg-muted":r}),children:r?(0,K.jsx)(K.Fragment,{children:`\xA0`}):t}),!r&&a&&(0,K.jsxs)(`div`,{className:T(`mb-4 rounded-lg bg-nested p-4`,`flex items-start gap-3`),children:[(0,K.jsx)(`div`,{className:`mt-0.5 shrink-0`,children:(0,K.jsx)(fb,{className:`h-[1.1em] w-[1.1em] text-info-indicator`})}),(0,K.jsxs)(`div`,{className:`flex-1 space-y-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(ix,{className:`h-[1em] w-[1em] text-muted-foreground`}),(0,K.jsx)(W,{as:`span`,variant:`subheading`,tone:`ink`,children:`A new Git branch will be created`})]}),(0,K.jsxs)(`div`,{className:`space-y-1`,children:[(0,K.jsxs)(W,{tone:`muted`,as:`p`,variant:`caption`,children:[(0,K.jsx)(W,{as:`span`,variant:`column`,children:`Branch name:`}),` `,(0,K.jsx)(cP,{children:o})]}),(0,K.jsx)(W,{tone:`muted`,as:`p`,variant:`caption`,children:`This ensures safe installation with easy rollback if needed. Your main branch remains unchanged.`})]})]})]}),n&&(0,K.jsxs)(`a`,{href:n,target:`_blank`,rel:`noopener noreferrer`,className:T(`text-muted-foreground hover:text-foreground`,`mt-auto flex items-center gap-2`),children:[(0,K.jsx)(T4,{}),(0,K.jsx)(W,{as:`span`,variant:`body`,className:`block`,children:n?.split(`/`)?.pop()})]})]}),i&&(0,K.jsx)(s0r,{data:i,labelsAreHidden:!0,isLoading:r})]})]})}function xNi(e){switch(e){case`running`:return(0,K.jsx)(pt,{size:`sm`,"aria-hidden":!0});case`success`:return(0,K.jsx)(Jt,{"aria-hidden":!0});case`failed`:return(0,K.jsx)(Px,{"aria-hidden":!0});default:return null}}function SNi(){return(0,K.jsx)(`svg`,{viewBox:`0 0 24 24`,className:`text-subtle-foreground`,"aria-hidden":!0,children:(0,K.jsx)(`circle`,{cx:`12`,cy:`12`,r:`8.5`,pathLength:`48`,fill:`none`,stroke:`currentcolor`,strokeWidth:`2.8`,strokeLinecap:`round`,strokeDasharray:`3 3`})})}function CNi({status:e,variant:t}){return t===`plain`?(0,K.jsx)(`span`,{className:T(`flex size-icon-md items-center justify-center self-center [&>svg]:size-icon-md`,c.colors,{"[&>svg]:text-success-indicator":e===`success`,"[&>svg]:text-destructive-foreground":e===`failed`}),children:e===`pending`?(0,K.jsx)(SNi,{}):xNi(e)}):(0,K.jsx)(`span`,{className:T(`flex size-7 items-center justify-center self-center rounded-full motion-reduce:transition-none`,c.colors,c.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:xNi(e)})}function wNi({step:e,isActive:t,position:n,variant:r=`default`}){let i=t||e.status===`success`?`ink`:`muted`;return(0,K.jsxs)(`div`,{className:T(`grid grid-cols-[1fr_auto] gap-6 rounded-lg px-4 py-3 motion-reduce:transition-none`,c.colors,{"border border-transparent":r==="default","border-dashed border-placeholder bg-card":t&&r==="default"}),children:[(0,K.jsxs)(`div`,{className:`grid min-w-0 grid-cols-[auto_1fr] gap-2`,children:[(0,K.jsxs)(W,{as:`span`,tone:i,className:T(`flex min-w-6 justify-end`,c.colors),children:[n,`.`]}),(0,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsx)(W,{as:`h4`,tone:i,className:c.colors,children:e.title}),e.description&&(0,K.jsx)(W,{tone:`faint`,className:T(`-mt-0.5`,{truncate:r===`plain`}),children:e.description})]})]}),(0,K.jsx)(CNi,{status:e.status,variant:r})]})}function TNi({currentStep:e,steps:t=[],className:n}){return(0,K.jsx)(`div`,{className:T(n),children:t.map((t,n)=>(0,K.jsx)(wNi,{step:t,isActive:e?.id===t.id,position:n+1},t.id))})}function ENi({steps:e}){let t=e.length,n=e.filter(e=>e.status===`success`).length;return(0,K.jsxs)(`div`,{className:`flex w-full flex-col content-center justify-center gap-4`,children:[(0,K.jsx)(`div`,{className:`grid w-full grid-cols-[0_repeat(9,1fr)]`,children:e.map((t,n)=>(0,K.jsx)(`div`,{className:T(`relative flex h-8 items-center justify-end`,c.colors,{"bg-success-subtle":t.status===`success`&&e?.[n-1]?.status===`success`}),children:(0,K.jsx)(`div`,{className:T(`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`,c.colors,c.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,K.jsx)(pt,{}):n+1})},t.id))}),(0,K.jsxs)(`div`,{className:T(`text-center text-caption text-muted-foreground`,c.colors),children:[n,` of `,t,` steps completed`]})]})}var DNi=(0,G.createContext)(3);function ONi({title:e,description:t,action:n,done:r,className:i,children:a}){let o=(0,G.useContext)(DNi);return(0,K.jsxs)(`li`,{className:T(`group/step grid grid-cols-[1.5rem_minmax(0,1fr)] gap-x-4 [counter-increment:ds-step]`,i),children:[(0,K.jsxs)(`div`,{className:`flex flex-col items-center`,children:[(0,K.jsx)(`span`,{className:T(`flex size-6 shrink-0 items-center justify-center rounded-full`,c.colors,r?`bg-success-indicator/18 text-success-indicator`:`bg-fill text-foreground`),children:r?(0,K.jsx)(Jt,{className:`size-icon-sm`,"aria-label":`Done`}):(0,K.jsx)(W,{as:`span`,variant:`column`,className:`before:content-[counter(ds-step)]`,"aria-hidden":!0})}),(0,K.jsx)(`span`,{"aria-hidden":!0,className:`w-px flex-1 bg-border group-last/step:hidden`})]}),(0,K.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-3 pb-8 group-last/step:pb-0`,children:[(0,K.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,K.jsxs)(`div`,{className:`flex min-h-6 flex-wrap items-center justify-between gap-x-6 gap-y-2`,children:[(0,K.jsx)(W,{as:o===2?`h2`:`h3`,variant:`label`,className:`text-pretty`,children:e}),n==null?null:(0,K.jsx)(`div`,{className:`flex shrink-0 items-center gap-2`,children:n})]}),t==null?null:(0,K.jsx)(W,{as:`p`,variant:`body-sm`,tone:`muted`,className:`max-w-[70ch] text-pretty`,children:t})]}),a]})]})}function kNi({headingLevel:e=3,className:t,children:n}){return(0,K.jsx)(DNi.Provider,{value:e,children:(0,K.jsx)(`ol`,{className:T(`flex flex-col [counter-reset:ds-step]`,t),children:n})})}Object.assign(kNi,{Step:ONi});function ANi({name:e,streamResult:t,runId:n,workflowInfo:r}){let i=t?.phase||`initializing`,a=t?.payload?.workflowState,o=t?.payload?.currentStep,s=t?.error,c=a?.steps||{},l=Object.keys(c).length>0,u=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,d=Object.entries(c).filter(([e,t])=>u(e)),f=d.length,p=()=>{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...`}},m=d.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,K.jsxs)(_Ni,{className:`mb-5 content-center space-y-6 text-muted-foreground`,children:[(0,K.jsxs)(`div`,{className:`text-center`,children:[(0,K.jsx)(W,{as:`h3`,variant:`heading`,tone:`ink`,children:p()}),(t?.runId||n)&&(0,K.jsxs)(W,{as:`p`,variant:`caption`,tone:`muted`,className:`mt-2`,children:[`Run ID: `,t?.runId??n]})]}),l&&f>0&&![`error`].includes(i)&&(0,K.jsx)(`div`,{className:`mx-auto w-full max-w-[30rem] px-4`,children:(0,K.jsx)(ENi,{steps:m})}),s&&i===`error`&&(0,K.jsxs)(`div`,{className:T(`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,K.jsx)(ub,{}),(0,K.jsx)(W,{as:`span`,variant:`body`,className:`block`,children:s||`Something went wrong`})]}),l&&(0,K.jsx)(TNi,{steps:m,currentStep:o,className:`pb-4`}),!l&&i===`initializing`&&(0,K.jsxs)(`div`,{className:T(`text-muted-foreground`,`grid justify-items-center gap-4 text-center`),children:[(0,K.jsx)(pt,{}),(0,K.jsx)(W,{as:`p`,variant:`body`,children:`This may take some time...`})]})]})}function jNi({name:e,installedEntities:t}){return(0,K.jsxs)(_Ni,{className:T(`grid content-center items-center justify-items-center gap-4`,`[&>svg]:h-8 [&>svg]:w-8`),children:[(0,K.jsx)(w4,{}),(0,K.jsx)(W,{as:`h2`,variant:`heading`,children:`Done!`}),(0,K.jsxs)(W,{tone:`muted`,className:`text-center`,children:[`The `,(0,K.jsx)(`b`,{className:`text-muted-foreground`,children:e}),` template has been successfully installed.`,t&&t.length>0&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`br`,{}),` Installed entities are listed below.`]})]}),t&&t.length>0&&(0,K.jsx)(s0r,{data:t})]})}function MNi(){let{templateSlug:e}=Yy(),t=[{id:`templates`,label:`Templates`,to:`/templates`},{id:`template`,label:K2t(e)}],[n,r]=nb(),[i,a]=(0,G.useState)(``),[o,s]=(0,G.useState)(``),[c,l]=(0,G.useState)(``),[u,d]=(0,G.useState)({}),[f,p]=(0,G.useState)([]),[m,h]=(0,G.useState)(null),[g,_]=(0,G.useState)(!1),[v,y]=(0,G.useState)(``),[b,x]=(0,G.useState)(!1),[S,C]=(0,G.useState)(!1),[w,T]=(0,G.useState)([]),{data:E,isLoading:D}=eNi({repoOrSlug:e,owner:`mastra-ai`}),O=`1.87.0-alpha.8`.includes(`beta`)??!1?`beta`:`main`,{data:k,isLoading:A}=tNi({repo:E?.githubUrl?new URL(E.githubUrl).pathname.split(`/`)[2]:`template-${e}`,owner:`mastra-ai`,branch:O}),{data:j,isLoading:M}=nNi(),{mutateAsync:N,isPending:P}=rNi(),{mutateAsync:F}=iNi(),{streamInstall:I,streamResult:L,isStreaming:R}=lNi({workflowInfo:j}),{observeInstall:z,streamResult:B,isStreaming:ee}=uNi({workflowInfo:j});(0,G.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,G.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,K.jsx)(HM,{})},{key:`agents`,label:`Agents`,value:E?.agents?.length?E.agents.map(e=>e).join(`, `):`n/a`,icon:(0,K.jsx)(FM,{})},{key:`workflows`,label:`Workflows`,value:E?.workflows?.length?E.workflows.map(e=>e).join(`, `):`n/a`,icon:(0,K.jsx)(cx,{})},{key:`providers`,label:`Providers`,value:E?.supportedProviders?.length?E.supportedProviders.join(`, `):`n/a`,icon:(0,K.jsx)(O3,{})},{key:`tags`,label:`Tags`,value:E?.tags?.length?E.tags.join(`, `):`n/a`,icon:(0,K.jsx)(hM,{})}],ne=[{...te[0]},{...te[1]},{...te[2]}].filter(e=>e.value!==`n/a`);return(0,G.useEffect)(()=>{k&&d(k)},[k]),(0,G.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,K.jsxs)(Xb,{variant:`page`,breadcrumbs:(0,K.jsx)(IA,{crumbs:t}),children:[(0,K.jsx)(`h1`,{className:`sr-only`,children:e}),(0,K.jsxs)(`div`,{className:`grid gap-y-6`,children:[(0,K.jsx)(bNi,{isLoading:D,title:E?.title,description:E?.longDescription,imageURL:E?.imageURL,githubUrl:E?.githubUrl,infoData:te,templateSlug:e}),E&&(0,K.jsxs)(K.Fragment,{children:[(R||ee)&&(0,K.jsx)(ANi,{name:E.title,streamResult:ee?B:L,runId:v,workflowInfo:j}),g&&(0,K.jsx)(jNi,{name:E.title,installedEntities:ne,linkComponent:tb}),m&&(0,K.jsx)(vNi,{errorMsg:m,validationErrors:w.length>0?w:L?.validationResults?.errors||B?.validationResults?.errors}),!R&&!ee&&!g&&!m&&(0,K.jsx)(yNi,{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 NNi=e=>e.threadId,PNi=e=>`traces`in e?e.traces:e.threads;function FNi(e,t){return`traces`in e?{traces:{...e.traces,...t}}:{threads:{...e.threads,...t}}}function INi(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 LNi({query:e,rolling:t,fixedStart:n=!1,autoRefetch:r=!0,limit:i,enabled:a=!0}){let o=X(),{anchorWindow:s,reanchor:c}=yMi(e,n),l=(0,G.useMemo)(()=>s?{...e,timeRange:FNi(e.timeRange,s)}:e,[e,s]),u=w4r({query:l,limit:i,enabled:a,queryOptions:mMi}),{headRows:d}=xMi({queryKey:[`threads`,e],fetchHead:async t=>(await o.queryTraceThreads({...e,timeRange:FNi(e.timeRange,vMi(PNi(e.timeRange),t,n)),orderBy:[{field:`endedAt`,direction:`desc`}],page:{limit:50}})).threads,getId:NNi,getEndedAt:e=>e.endedAt,since:Date.parse(PNi(l.timeRange).to),enabled:a&&t&&r&&u.threads!==void 0&&!u.isFetching&&!u.isError,onOverflow:()=>c(PNi(e.timeRange))}),{orderBy:f}=e,p=u.threads,m=(0,G.useMemo)(()=>p&&CMi(p,d,{getId:NNi,compare:INi(f),hasNextPage:u.hasNextPage}),[p,d,f,u.hasNextPage]);return{...u,threads:m}}function RNi(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 zNi=[`last-24h`,`last-3d`,`last-7d`,`last-14d`,`last-30d`,`custom`],BNi=[];function VNi(){let{data:e}=G5(),t=e?.capabilities.traceQueryTimeToFirstChunk??!1,n=e?.capabilities.traceQueryTimeToFirstToken??!1,{data:r=BNi}=O6(),{data:i=BNi}=k6();return(0,G.useMemo)(()=>[aM,...Roi({withTimeToFirstChunk:t,withTimeToFirstToken:n,entityNames:r,environments:i})],[t,n,r,i])}function HNi({tokens:e,groups:t,onFiltersChange:n}){let r=(0,G.useMemo)(()=>s8(e),[e]),i=(0,G.useMemo)(()=>{let e=c8([],t);return{...e,nodes:[oM,...r,...e.nodes]}},[r,t]),a=(0,G.useCallback)(e=>{let t=b6r({...e,nodes:e.nodes.filter(e=>zj(e)||e.fieldId!==`timeRange`)});n(t.tokens,t.groups)},[n]);return{filterBarValue:i,onFilterBarChange:a,onFilterByField:(0,G.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(zj);a({...i,nodes:[...n,o,...s]})},[r,i,a])}}var UNi=e=>e;function WNi({datePreset:e,dateFrom:t,dateTo:n,minDate:r,tokens:i,groups:a,onDatePresetChange:o,onDateChange:s,onDateRangeChange:c,onFiltersChange:l,disabled:u}){let d=VNi(),{filterBarValue:f,onFilterBarChange:p}=HNi({tokens:i,groups:a,onFiltersChange:l});return(0,K.jsxs)(pM,{fields:d,operators:q3r,value:f,onValueChange:p,createItemId:UNi,maxDepth:3,"aria-label":`Thread filters`,className:`min-w-64 flex-1`,children:[(0,K.jsx)(pM.Chips,{renderChip:i=>i.fieldId===`timeRange`?(0,K.jsx)(pM.TimeRange,{preset:e,onPresetChange:o,dateFrom:t,dateTo:n,minDate:r,onDateChange:s,onDateRangeChange:c,disabled:u,presets:zNi,defaultPreset:f8.datePreset}):(0,K.jsx)(pM.Chip,{item:i})}),(0,K.jsx)(pM.Input,{placeholder:`Filter threads`})]})}function GNi({selectedThreadId:e,onSelectedThreadChange:t,onOpenScore:n,urlState:r}){let i=gMi(r),{timeRange:a,tokens:o,groups:s,sort:c}=i,l=K5().enabled,u=lci().enabled,d=Wsi({scope:`threads`}),{data:f,isLoading:p}=G5(),m=f?.capabilities.traceQueryTimeToFirstChunk??!1,h=f?.capabilities.traceQueryTimeToFirstToken??!1,g=(0,G.useMemo)(()=>p?d.preferences:w2r(d.preferences,{withTimeToFirstChunk:m,withTimeToFirstToken:h}),[d.preferences,p,m,h]),{threads:_,hasNextPage:v,isFetchingNextPage:y,setEndOfListElement:b,isLoading:x,isError:S,error:C}=LNi({query:(0,G.useMemo)(()=>{let e=Voi(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,G.useMemo)(()=>(_??[]).map(RNi),[_]),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,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`h1`,{className:`sr-only`,children:`Threads`}),(0,K.jsx)(B8r,{toolbar:(0,K.jsxs)(K.Fragment,{children:[r&&(0,K.jsx)(zsi,{page:`threads`,...r,columns:d}),(0,K.jsxs)(_M,{children:[(0,K.jsx)(_M.Start,{children:(0,K.jsx)(WNi,{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,K.jsx)(_M.End,{children:(0,K.jsx)(WMi,{scope:`threads`,value:d.preferences,onChange:d.setPreferences})})]})]}),error:S?(0,K.jsx)(_6,{error:C,resource:`threads`,errorTitle:`Failed to load threads`}):void 0,empty:D?(0,K.jsx)(i2r,{resource:`threads`,datePreset:i.datePreset,dateFrom:i.dateFrom,dateTo:i.dateTo}):void 0,children:(0,K.jsx)(uei,{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,K.jsx)(aui,{open:!!e,threadId:e??``,depth:1,closeLabel:`Close`,withQueryTrace:l,withFeedback:u,onOpenScore:n,onClose:()=>t(void 0)})]})}function KNi(){let{enabled:e,isLoading:t}=oci(),n=Jy(),[r,i]=nb();return(0,K.jsx)(fMi,{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,K.jsx)(GNi,{urlState:{searchParams:r,setSearchParams:i},selectedThreadId:kMi(r),onSelectedThreadChange:e=>i(t=>AMi(t,e),{replace:!0}),onOpenScore:(e,t)=>n(XVn(e,t))})})}var qNi=()=>(0,K.jsx)(db,{titleSlot:`No Workflows yet`,descriptionSlot:(0,K.jsxs)(K.Fragment,{children:[`Mastra workflows are not configured yet. `,(0,K.jsx)(`br`,{}),`More information in the documentation.`]}),actionSlot:(0,K.jsx)(U,{variant:`ghost`,render:(0,K.jsx)(`a`,{href:`https://mastra.ai/docs/workflows/overview`,target:`_blank`,rel:`noopener noreferrer`}),icon:(0,K.jsx)(qM,{}),children:`Workflows documentation`}),variant:`fill`});function JNi(e,t,n){return k4(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 YNi(e){return Object.keys(e.steps??{}).filter(t=>e.allSteps?.[t]?.isWorkflow)}function XNi(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 ZNi(e,t,n){let r=XNi(t),i=[],a=(e,o,s,c,l,u)=>{let d=YNi(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 QNi=`auto 24rem minmax(0, 1fr) auto auto auto`;function $Ni({guides:e,isLastChild:t}){return(0,K.jsxs)(`span`,{"aria-hidden":!0,className:`-my-6 flex shrink-0 self-stretch`,children:[e.map((e,t)=>(0,K.jsx)(`span`,{className:T(`w-6`,e&&`border-l border-border`)},t)),(0,K.jsxs)(`span`,{className:`relative w-6`,children:[(0,K.jsx)(`span`,{className:T(`absolute top-0 left-0 border-l border-border`,t?`h-1/2`:`h-full`)}),(0,K.jsx)(`span`,{className:`absolute top-1/2 left-0 w-3.5 border-b border-border`})]})]})}function ePi({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,K.jsx)(`div`,{className:`flex items-center pl-5`,children:r?(0,K.jsx)(`button`,{type:`button`,"aria-expanded":t,"aria-label":`${t?`Collapse`:`Expand`} nested workflows of ${i}`,className:T(Mb,`relative grid size-5 shrink-0 place-items-center before:absolute before:-inset-1.5 before:content-['']`),onClick:e=>{e.stopPropagation(),n()},children:(0,K.jsx)(Gr,{direction:`right`,className:`size-4`})}):(0,K.jsx)(`span`,{className:`size-5 shrink-0`,"aria-hidden":!0})})}var tPi=e=>e.stopPropagation();function nPi({sortKey:e,sort:t,onSortChange:n,children:r}){return n?(0,K.jsx)(Z.SortableTopCell,{sortKey:e,sort:t?.key===e?t.direction:void 0,onSortChange:t=>n(t,e),children:r}):(0,K.jsx)(Z.TopCell,{children:r})}function rPi({row:e,isExpanded:t,onToggle:n,runCount:r,rowProps:i}){let{paths:a,Link:o}=xa(),s=(0,G.useRef)(null),{workflow:c,nestedIds:l}=e,u=qA(c.name,50),d=qA(c.description??``,200),f=Object.keys(c.steps??{}).length,p=r?.running??0,m=r?.suspended??0,h=l.length>0;return(0,K.jsxs)(Z.RowWrapper,{...i,onSelectRow:()=>s.current?.click(),children:[(0,K.jsx)(ePi,{row:e,isExpanded:t,onToggle:n}),(0,K.jsxs)(Z.RowLink,{ref:s,colStart:2,to:a.workflowLink(c.id),LinkComponent:o,tabIndex:-1,onClick:tPi,children:[(0,K.jsx)(Z.NameCell,{children:(0,K.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[e.depth>0?(0,K.jsx)($Ni,{guides:e.guides,isLastChild:e.isLastChild}):null,(0,K.jsx)(`span`,{className:`truncate`,children:u}),c.origin===`dynamic`?(0,K.jsx)(dx,{size:`xs`,variant:`blue`,title:`Registered via the dynamic-workflows API`,children:`Dynamic`}):null,h?(0,K.jsxs)(W,{as:`span`,variant:`body-sm`,tone:`muted`,title:`Nested workflows: ${l.join(`, `)}`,className:`inline-flex shrink-0 items-center gap-1`,children:[(0,K.jsx)(cx,{"aria-hidden":!0,className:`size-icon-sm`}),l.length]}):null]})}),(0,K.jsx)(Z.DescriptionCell,{children:d}),(0,K.jsx)(Z.TextCell,{className:`text-center`,children:p>0?(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-info-indicator`,"aria-label":`${p} run${p===1?``:`s`} in progress`,children:[(0,K.jsx)(`span`,{"aria-hidden":!0,className:`size-2 rounded-full bg-info-indicator motion-safe:animate-pulse`}),p]}):``}),(0,K.jsx)(Z.TextCell,{className:`text-center`,children:m>0?(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-warning-foreground`,"aria-label":`${m} run${m===1?``:`s`} awaiting input`,children:[(0,K.jsx)(Jw,{"aria-hidden":!0,className:`size-icon-sm`}),m]}):``}),(0,K.jsx)(Z.TextCell,{className:`text-center`,children:f||``})]})]})}function iPi({workflows:e,isLoading:t,search:n=``,sort:r,onSortChange:i,requestContext:a}){let[o,s]=(0,G.useState)(new Set),c=jvt({requestContext:a}),l=(0,G.useMemo)(()=>Object.entries(e).map(([e,t])=>({...t,id:e})),[e]),u=(0,G.useMemo)(()=>{let e=n.toLowerCase();return l.filter(t=>t.name?.toLowerCase().includes(e)||t.description?.toLowerCase().includes(e))},[l,n]),d=(0,G.useMemo)(()=>JNi(u,r,c),[u,r,c]),f=(0,G.useMemo)(()=>ZNi(d,e,o),[d,e,o]),p=(0,G.useMemo)(()=>{let e=new Map;for(let t of f)t.kind===`workflow`&&e.set(t.pathKey,e.size);return e},[f]),{containerRef:m,getRowProps:h}=PM({count:p.size,global:!0}),_=e=>{s(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return t?(0,K.jsx)(UM,{columns:QNi,fit:`container`}):(0,K.jsxs)(Z,{columns:QNi,fit:`container`,scrollRef:m,children:[(0,K.jsxs)(Z.Top,{children:[(0,K.jsx)(Z.TopCell,{children:(0,K.jsx)(`span`,{className:`sr-only`,children:`Expand`})}),(0,K.jsx)(nPi,{sortKey:`name`,sort:r,onSortChange:i,children:`Name`}),(0,K.jsx)(Z.TopCell,{children:`Description`}),(0,K.jsx)(nPi,{sortKey:`running`,sort:r,onSortChange:i,children:`Running`}),(0,K.jsx)(nPi,{sortKey:`suspended`,sort:r,onSortChange:i,children:`Pending input`}),(0,K.jsx)(nPi,{sortKey:`steps`,sort:r,onSortChange:i,children:`Number of steps`})]}),f.length===0&&n?(0,K.jsx)(Z.NoMatch,{message:`No Workflows match your search`}):null,f.map(e=>{let t=o.has(e.pathKey),n=()=>_(e.pathKey);return e.kind===`unregistered`?(0,K.jsxs)(Z.RowStatic,{className:`gap-0 px-0`,children:[(0,K.jsx)(ePi,{row:e,isExpanded:t,onToggle:n}),(0,K.jsxs)(`div`,{className:`col-span-5 col-start-2 grid grid-cols-subgrid gap-4 px-3`,children:[(0,K.jsx)(Z.NameCell,{children:(0,K.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,K.jsx)($Ni,{guides:e.guides,isLastChild:e.isLastChild}),(0,K.jsx)(`span`,{className:`truncate`,children:qA(e.stepId,50)}),(0,K.jsxs)(jn,{children:[(0,K.jsx)(dr,{render:(0,K.jsx)(W,{as:`span`,variant:`body-sm`,tone:`muted`}),role:`note`,tabIndex:0,className:T(`shrink-0 rounded-sm`,g),children:`not registered`}),(0,K.jsx)(qt,{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,K.jsx)(Z.DescriptionCell,{children:qA(e.description??``,200)}),(0,K.jsx)(Z.TextCell,{className:`text-center`,children:``}),(0,K.jsx)(Z.TextCell,{className:`text-center`,children:``}),(0,K.jsx)(Z.TextCell,{className:`text-center`,children:``})]})]},`workflow-${e.pathKey}`):(0,K.jsx)(rPi,{row:e,isExpanded:t,onToggle:n,runCount:c[e.workflow.id],rowProps:h(p.get(e.pathKey)??-1)},`workflow-${e.pathKey}`)})]})}var G9=[vI(`/workflows`)];function aPi(){let{data:e,isLoading:t,error:n}=gA(),[r,i]=(0,G.useState)(``),[a,o]=(0,G.useState)();return n&&Ej(n)?(0,K.jsxs)(Xb,{variant:`page`,breadcrumbs:(0,K.jsx)(IA,{crumbs:G9}),children:[(0,K.jsx)(`h1`,{className:`sr-only`,children:`Workflows`}),(0,K.jsx)(oI,{variant:`fill`})]}):n&&Dj(n)?(0,K.jsxs)(Xb,{variant:`page`,breadcrumbs:(0,K.jsx)(IA,{crumbs:G9}),children:[(0,K.jsx)(`h1`,{className:`sr-only`,children:`Workflows`}),(0,K.jsx)(aI,{variant:`fill`,resource:`workflows`})]}):n?(0,K.jsxs)(Xb,{variant:`page`,breadcrumbs:(0,K.jsx)(IA,{crumbs:G9}),children:[(0,K.jsx)(`h1`,{className:`sr-only`,children:`Workflows`}),(0,K.jsx)(db,{tone:`error`,variant:`fill`,titleSlot:`Failed to load workflows`,descriptionSlot:n.message})]}):Object.keys(e||{}).length===0&&!t?(0,K.jsxs)(Xb,{variant:`page`,breadcrumbs:(0,K.jsx)(IA,{crumbs:G9}),children:[(0,K.jsx)(`h1`,{className:`sr-only`,children:`Workflows`}),(0,K.jsx)(qNi,{})]}):(0,K.jsxs)(Xb,{variant:`page`,breadcrumbs:(0,K.jsx)(IA,{crumbs:G9}),actionRow:(0,K.jsxs)(_M,{children:[(0,K.jsx)(_M.Start,{children:(0,K.jsx)(`div`,{className:`max-w-120 flex-1`,children:(0,K.jsx)($A,{...ej,onValueChange:i,label:`Search workflows`,placeholder:`Search by name or description`})})}),(0,K.jsx)(_M.End,{children:(0,K.jsx)(U,{render:(0,K.jsx)(tb,{to:`/workflows/schedules`}),variant:`primary`,icon:(0,K.jsx)(ax,{}),children:`Schedules`})})]}),children:[(0,K.jsx)(`h1`,{className:`sr-only`,children:`Workflows`}),(0,K.jsx)(iPi,{workflows:e||{},isLoading:t,search:r,sort:a,onSortChange:(e,t)=>o({key:t,direction:e})})]})}var oPi={active:`bg-success-indicator`,paused:`bg-info-indicator`,completed:`bg-muted-foreground`},sPi={active:`text-success-indicator`,paused:`text-info-indicator`,completed:`text-muted-foreground`},cPi=({status:e})=>(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-2 whitespace-nowrap`,children:[(0,K.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full ${oPi[e]}`,"aria-hidden":!0}),(0,K.jsx)(W,{as:`span`,variant:`caption`,className:sPi[e],children:e})]});function lPi({status:e}){let{icon:t,color:n}=uPi(e);return(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 whitespace-nowrap ${n}`,children:[(0,K.jsx)(`span`,{className:`inline-flex shrink-0 items-center`,"aria-hidden":!0,children:t}),(0,K.jsx)(W,{as:`span`,variant:`caption`,children:e})]})}function uPi(e){switch(e){case`success`:return{icon:(0,K.jsx)(Jt,{className:`size-icon-sm`}),color:`text-success-indicator`};case`failed`:return{icon:(0,K.jsx)(Px,{className:`size-icon-sm`}),color:`text-destructive-foreground`};case`running`:return{icon:(0,K.jsx)(pt,{}),color:`text-muted-foreground`};case`suspended`:return{icon:(0,K.jsx)(Jw,{className:`size-icon-sm`}),color:`text-info-indicator`};case`canceled`:return{icon:(0,K.jsx)(lb,{className:`size-icon-sm`}),color:`text-muted-foreground`};case`pending`:case`waiting`:return{icon:(0,K.jsx)(fx,{className:`size-icon-sm`}),color:`text-muted-foreground`};default:return{icon:null,color:`text-muted-foreground`}}}var dPi=`auto auto auto auto 1fr`,fPi=3e4,pPi=3e5;function mPi({triggers:e,isLoading:t,workflowId:n,hasNextPage:r,isFetchingNextPage:i,setEndOfListElement:a}){let{Link:o,paths:s}=xa(),c=e=>!!(n&&e.runId&&e.outcome!==`failed`),l=e.filter(c).length,{containerRef:u,getRowProps:d}=PM({count:l}),f=-1;return t?(0,K.jsx)(UM,{columns:dPi}):e.length===0?(0,K.jsx)(W,{variant:`body`,tone:`muted`,className:`p-4`,children:`No trigger history yet.`}):(0,K.jsxs)(Z,{columns:dPi,className:`min-w-0`,scrollRef:u,children:[(0,K.jsxs)(Z.Top,{children:[(0,K.jsx)(Z.TopCell,{children:`Run`}),(0,K.jsx)(Z.TopCell,{children:`Status`}),(0,K.jsx)(Z.TopCell,{children:`Started`}),(0,K.jsx)(Z.TopCell,{children:`Duration`}),(0,K.jsx)(Z.TopCell,{children:` `})]}),e.map(e=>{let t=e.actualFireAt-e.scheduledFireAt,r=hx(t,{signed:!0}),i=e.outcome===`failed`,a=i?e.error:e.run?.error,l=Math.abs(t),u=!i&&l>fPi&&l<=pPi,p=`${e.scheduleId}-${e.runId}-${e.actualFireAt}`,m=c(e);m&&(f+=1);let h=(0,K.jsx)(W,{as:`span`,variant:`caption`,font:`mono`,tone:m?`ink`:`muted`,className:`whitespace-nowrap`,children:e.runId}),g=(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Z.Cell,{children:h}),(0,K.jsx)(Z.Cell,{children:(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[i?(0,K.jsxs)(W,{as:`span`,variant:`caption`,className:`inline-flex items-center gap-1.5 whitespace-nowrap text-destructive-foreground`,children:[(0,K.jsx)(mb,{className:`size-icon-sm`}),`publish failed`]}):e.run?(0,K.jsx)(lPi,{status:e.run.status}):(0,K.jsx)(W,{as:`span`,variant:`caption`,tone:`muted`,className:`inline-flex items-center gap-1.5 whitespace-nowrap`,children:`pending`}),a?(0,K.jsxs)(jn,{children:[(0,K.jsx)(dr,{asChild:!0,children:(0,K.jsx)(`span`,{className:`inline-flex text-destructive-foreground`,children:(0,K.jsx)(mb,{className:`size-icon-sm`})})}),(0,K.jsx)(qt,{children:a})]}):null]})}),(0,K.jsx)(Z.Cell,{children:(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-2 whitespace-nowrap`,children:[e.actualFireAt?(0,K.jsx)(RE,{value:e.actualFireAt}):`—`,u?(0,K.jsxs)(jn,{children:[(0,K.jsx)(dr,{asChild:!0,children:(0,K.jsx)(`span`,{className:`inline-flex text-info-indicator`,children:(0,K.jsx)(mb,{className:`size-icon-sm`})})}),(0,K.jsxs)(qt,{children:[`Published `,r,` after the scheduled fire time`]})]}):null]})}),(0,K.jsx)(Z.Cell,{children:e.run?(0,K.jsx)(W,{as:`span`,variant:`body-sm`,font:`mono`,children:hx(e.run.durationMs)||`—`}):(0,K.jsx)(`span`,{className:`text-muted-foreground`,children:`—`})}),(0,K.jsx)(Z.Cell,{children:` `})]});return m?(0,K.jsx)(Z.RowLink,{to:s.workflowRunLink(n,e.runId),LinkComponent:o,...d(f),children:g},p):(0,K.jsx)(Z.RowStatic,{children:g},p)}),(0,K.jsx)(Z.NextPageLoading,{isLoading:i,hasMore:r,setEndOfListElement:a})]})}var hPi={id:`workflow-schedules`,label:`Schedules`,icon:ax,to:`/workflows/schedules`};function K9({label:e,children:t}){return(0,K.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,K.jsx)(W,{variant:`meta`,tone:`muted`,className:`uppercase`,children:e}),(0,K.jsx)(`div`,{children:(0,K.jsx)(W,{as:`span`,variant:`body`,className:`block`,children:t})})]})}function gPi(){let{scheduleId:e}=Yy(),t=[vI(`/workflows`),hPi,{id:`schedule`,label:K2t(e),icon:ax}],{paths:n}=xa(),{data:r,error:i}=l4t({scheduleId:e,queryOptions:{enabled:!!e}}),{data:a,isLoading:o,error:s,hasNextPage:c,isFetchingNextPage:l,setEndOfListElement:u}=d4t({scheduleId:e,queryOptions:{enabled:!!e}}),d=f4t({scheduleId:e});if(i&&Ej(i))return(0,K.jsxs)(Xb,{variant:`page`,breadcrumbs:(0,K.jsx)(IA,{crumbs:t}),children:[(0,K.jsx)(`h1`,{className:`sr-only`,children:e}),(0,K.jsx)(oI,{variant:`fill`})]});if(i&&Dj(i))return(0,K.jsxs)(Xb,{variant:`page`,breadcrumbs:(0,K.jsx)(IA,{crumbs:t}),children:[(0,K.jsx)(`h1`,{className:`sr-only`,children:e}),(0,K.jsx)(aI,{variant:`fill`,resource:`schedules`})]});if(i)return(0,K.jsxs)(Xb,{variant:`page`,breadcrumbs:(0,K.jsx)(IA,{crumbs:t}),children:[(0,K.jsx)(`h1`,{className:`sr-only`,children:e}),(0,K.jsx)(db,{tone:`error`,variant:`fill`,titleSlot:`Failed to load schedule`,descriptionSlot:i.message})]});let f=r?.workflowId,p=r?.agentId;return(0,K.jsxs)(Xb,{variant:`page`,breadcrumbs:(0,K.jsx)(IA,{crumbs:t}),actionRow:(0,K.jsx)(_M,{children:(0,K.jsxs)(_M.End,{children:[(0,K.jsx)(U,{render:(0,K.jsx)(tb,{to:n.schedulesLink()}),variant:`ghost`,icon:(0,K.jsx)(_b,{}),children:`Back to schedules`}),f?(0,K.jsx)(U,{icon:(0,K.jsx)(cx,{}),render:(0,K.jsx)(tb,{to:n.workflowLink(f)}),variant:`ghost`,children:`Open workflow`}):null,r&&r.status!==`completed`?(0,K.jsx)(U,{onClick:()=>{let e=r.status===`active`?`pause`:`resume`;d.mutate(e,{onSuccess:()=>vn.success(e===`pause`?`Schedule paused`:`Schedule resumed`),onError:e=>vn.error(e.message)})},icon:r.status===`active`?(0,K.jsx)(Jw,{}):(0,K.jsx)(Yw,{}),loading:d.isPending,"data-testid":`schedule-toggle-button`,children:r.status===`active`?`Pause`:`Resume`}):null]})}),children:[(0,K.jsx)(`h1`,{className:`sr-only`,children:e}),r?(0,K.jsxs)(`div`,{className:`grid h-full grid-cols-[minmax(0,20rem)_1fr] gap-4 overflow-hidden`,children:[(0,K.jsxs)(`div`,{className:`flex h-fit flex-col gap-4 rounded-md border border-border p-4`,children:[(0,K.jsx)(K9,{label:p?`Agent`:`Workflow`,children:f?(0,K.jsx)(tb,{to:n.workflowLink(f),className:`text-foreground hover:underline`,children:f}):p?(0,K.jsx)(tb,{to:n.agentLink(p),className:`text-foreground hover:underline`,children:p}):`—`}),(0,K.jsxs)(K9,{label:r.cron?`Cron`:`Runs at`,children:[(0,K.jsx)(W,{as:`span`,variant:`body`,font:`mono`,children:r.cron??(r.runAt?new Date(r.runAt).toLocaleString():`—`)}),r.endAt?(0,K.jsxs)(`span`,{className:`ml-2 text-caption text-muted-foreground`,children:[`until `,new Date(r.endAt).toLocaleString()]}):null,r.timezone?(0,K.jsx)(W,{as:`span`,variant:`caption`,tone:`muted`,className:`ml-2`,children:r.timezone}):null]}),(0,K.jsx)(K9,{label:`Status`,children:(0,K.jsx)(cPi,{status:r.status})}),(0,K.jsx)(K9,{label:`Next fire`,children:r.nextFireAt?(0,K.jsx)(RE,{value:r.nextFireAt}):`—`})]}),(0,K.jsxs)(`div`,{className:`overflow-y-auto`,"data-testid":`schedule-triggers-panel`,children:[(0,K.jsx)(W,{variant:`body`,className:`mb-3`,children:`Trigger history`}),s?(0,K.jsx)(db,{tone:`error`,titleSlot:`Failed to load trigger history`,descriptionSlot:s.message}):(0,K.jsx)(mPi,{triggers:a??[],isLoading:o,workflowId:f,hasNextPage:c,isFetchingNextPage:l,setEndOfListElement:u})]})]}):null]})}var _Pi={target:e=>e.workflowId??e.agentId??``,status:e=>e.status,nextFireAt:e=>e.nextFireAt,lastFireAt:e=>e.lastFireAt},vPi=`minmax(0, 1.2fr) minmax(0, 1.4fr) minmax(0, 1fr) auto auto auto`;function yPi({schedules:e,isLoading:t,search:n=``,sort:r,onSortChange:i}){let{paths:a,Link:o}=xa(),s=(0,G.useMemo)(()=>{let t=n.toLowerCase();return k4(t?e.filter(e=>e.id.toLowerCase().includes(t)||(e.workflowId??e.agentId??``).toLowerCase().includes(t)):e,r,_Pi)},[e,n,r]),{containerRef:c,getRowProps:l}=PM({count:s.length,global:!0});if(t)return(0,K.jsx)(UM,{columns:vPi});let u=(e,t)=>i?(0,K.jsx)(Z.SortableTopCell,{sortKey:e,sort:r?.key===e?r.direction:void 0,onSortChange:i,children:t}):(0,K.jsx)(Z.TopCell,{children:t});return(0,K.jsxs)(Z,{columns:vPi,className:`min-w-0`,scrollRef:c,children:[(0,K.jsxs)(Z.Top,{children:[u(`target`,`Target`),(0,K.jsx)(Z.TopCell,{children:`Schedule ID`}),(0,K.jsx)(Z.TopCell,{children:`Cron`}),u(`status`,`Status`),u(`nextFireAt`,`Next fire`),u(`lastFireAt`,`Last run`)]}),s.length===0&&n?(0,K.jsx)(Z.NoMatch,{message:`No schedules match your search`}):null,s.length===0&&!n?(0,K.jsx)(Z.NoMatch,{message:`No schedules configured`}):null,s.map((e,t)=>(0,K.jsxs)(Z.RowLink,{to:a.scheduleLink(e.id),LinkComponent:o,...l(t),children:[(0,K.jsx)(Z.NameCell,{children:e.workflowId??e.agentId}),(0,K.jsx)(Z.Cell,{className:`min-w-0`,children:(0,K.jsx)(W,{as:`span`,variant:`body-sm`,tone:`muted`,font:`mono`,className:`block truncate`,title:e.id,children:e.id})}),(0,K.jsx)(Z.Cell,{children:(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-2 whitespace-nowrap`,children:[(0,K.jsx)(W,{as:`span`,variant:`caption`,font:`mono`,children:e.cron??(e.runAt?`once @ ${new Date(e.runAt).toLocaleString()}`:`—`)}),e.timezone?(0,K.jsx)(W,{as:`span`,variant:`meta`,tone:`muted`,children:e.timezone}):null]})}),(0,K.jsx)(Z.Cell,{children:(0,K.jsx)(cPi,{status:e.status})}),(0,K.jsx)(Z.Cell,{children:e.nextFireAt?(0,K.jsx)(RE,{value:e.nextFireAt}):`—`}),(0,K.jsx)(Z.Cell,{children:e.lastRun?(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-2 whitespace-nowrap`,children:[(0,K.jsx)(lPi,{status:e.lastRun.status}),e.lastFireAt?(0,K.jsx)(W,{as:`span`,variant:`caption`,tone:`muted`,children:(0,K.jsx)(RE,{value:e.lastFireAt})}):null]}):e.lastFireAt?(0,K.jsx)(RE,{value:e.lastFireAt}):(0,K.jsx)(`span`,{className:`text-muted-foreground`,children:`Never`})})]},e.id))]})}function bPi({workflowId:e}={}){let{data:t,isLoading:n,error:r}=bI(e?{workflowId:e}:{}),[i,a]=(0,G.useState)(``),[o,s]=(0,G.useState)();return r?(0,K.jsx)(db,{tone:`error`,titleSlot:`Failed to load schedules`,descriptionSlot:r.message}):(0,K.jsxs)(`div`,{className:`grid h-full grid-rows-[auto_1fr] gap-4 overflow-hidden`,children:[(0,K.jsx)(`div`,{className:`max-w-120`,children:(0,K.jsx)($A,{...ej,onValueChange:a,label:`Search schedules`,placeholder:`Search by id or workflow`})}),(0,K.jsx)(`div`,{className:`overflow-y-auto`,children:(0,K.jsx)(yPi,{schedules:t??[],isLoading:n,search:i,sort:o,onSortChange:(e,t)=>s({key:t,direction:e})})})]})}var xPi=[vI(`/workflows`),hPi];function SPi(){let[e]=nb(),t=e.get(`workflowId`)??void 0,{error:n}=bI(t?{workflowId:t}:{});return n&&Ej(n)?(0,K.jsxs)(Xb,{variant:`page`,breadcrumbs:(0,K.jsx)(IA,{crumbs:xPi}),children:[(0,K.jsx)(`h1`,{className:`sr-only`,children:`Schedules`}),(0,K.jsx)(oI,{variant:`fill`})]}):n&&Dj(n)?(0,K.jsxs)(Xb,{variant:`page`,breadcrumbs:(0,K.jsx)(IA,{crumbs:xPi}),children:[(0,K.jsx)(`h1`,{className:`sr-only`,children:`Schedules`}),(0,K.jsx)(aI,{variant:`fill`,resource:`schedules`})]}):(0,K.jsxs)(Xb,{variant:`page`,breadcrumbs:(0,K.jsx)(IA,{crumbs:xPi}),children:[(0,K.jsx)(`h1`,{className:`sr-only`,children:`Schedules`}),(0,K.jsx)(`div`,{className:`h-full`,children:(0,K.jsx)(bPi,{workflowId:t})})]})}var CPi=_(`IconArrowDownLeft`,()=>(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`path`,{d:`M6 9V18H15`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`}),(0,K.jsx)(`path`,{d:`M17.75 6.25L7 17`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`})]}),3),wPi={"--belt-hue":`var(--warning-indicator)`};function TPi(e){let t=new Blob([JSON.stringify(e??null)]).size;return t<1024?`${t} B`:`${(t/1024).toFixed(1)} KB`}function EPi(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 DPi({suspendedSteps:e,workflow:t,isStreaming:n,onResume:r}){return n||e.length===0?null:(0,K.jsxs)(`section`,{className:T(Gvt,`pointer-events-auto relative isolate`),"data-testid":`workflow-suspended-steps`,"aria-label":`Step suspended`,children:[(0,K.jsxs)(`div`,{className:`max-h-[calc(100cqh-64px)] overflow-y-auto overscroll-contain rounded-[inherit]`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-3 border-b border-border bg-background px-5 py-4`,children:[(0,K.jsxs)(W,{as:`h2`,variant:`column`,tone:`ink`,className:`flex items-center gap-2`,children:[(0,K.jsx)(gr,{children:(0,K.jsx)(Jw,{})}),`Step suspended`]}),(0,K.jsx)(dx,{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?XT(pE(n.resumeSchema)):ep(q(),Gf());return(0,K.jsx)(OPi,{step:e,stepSchema:i,description:n.description,onResume:r},`${e.runId}-${e.stepId}`)})]}),(0,K.jsx)(iqe,{status:`ready`,label:`Needs input`,className:`before:hidden`,style:wPi})]})}function OPi({step:e,stepSchema:t,description:n,onResume:r}){let[i,a]=(0,G.useState)(!1),[o,s]=(0,G.useState)(!1);return(0,K.jsxs)(`div`,{className:`space-y-5 p-5 [&+&]:border-t [&+&]:border-border`,children:[(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(W,{as:`p`,variant:`subheading`,tone:`ink`,className:`break-words`,children:e.stepId}),n&&(0,K.jsx)(W,{as:`p`,variant:`caption`,tone:`muted`,children:n})]}),e.suspendPayload!==void 0&&(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsxs)(W,{as:`p`,variant:`caption`,tone:`muted`,className:`flex items-center gap-2`,children:[(0,K.jsx)(gr,{children:(0,K.jsx)(CPi,{})}),`The step is asking`]}),(0,K.jsxs)(Ax,{open:i,onOpenChange:a,children:[(0,K.jsxs)(jx,{className:T(`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,K.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[(0,K.jsx)(gr,{children:(0,K.jsx)(Gr,{direction:`right`,className:`text-muted-foreground`})}),(0,K.jsx)(W,{as:`span`,variant:`body`,tone:`ink`,className:`truncate`,children:EPi(e.suspendPayload,e.stepId)})]}),(0,K.jsx)(W,{as:`span`,variant:`caption`,tone:`muted`,className:`shrink-0`,children:TPi(e.suspendPayload)})]}),(0,K.jsx)(Mx,{children:(0,K.jsx)(`div`,{"data-testid":`suspended-payload`,className:`pt-2`,children:(0,K.jsx)(fr,{value:JSON.stringify(e.suspendPayload,null,2),editable:!1,className:`w-full overflow-x-auto p-2`,showCopyButton:!1})})})]})]}),(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(W,{as:`p`,variant:`caption`,tone:`muted`,className:`flex items-center gap-2`,children:[(0,K.jsx)(gr,{children:(0,K.jsx)(_P,{})}),`Your response`]}),(0,K.jsx)(`div`,{className:`-mx-5`,children:(0,K.jsx)(svt,{schema:t,isSubmitLoading:o,submitButtonLabel:`Resume`,submitButtonVariant:`primary`,submitButtonIcon:(0,K.jsx)(Yw,{}),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){vn.error(e instanceof Error?e.message:`Error resuming workflow`)}finally{s(!1)}}})})]})]})}function kPi({hidden:e,requestContext:t,canResume:n}){let{result:r,workflow:i,runId:a,isStreamingWorkflow:o}=(0,G.useContext)(nx),s=eat(r,a),c=aat(t),l=r?.status===`suspended`&&s.length>0&&!o;return!i||!l||!n?null:(0,K.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,K.jsx)(DPi,{suspendedSteps:s,workflow:i,isStreaming:o,onResume:c})},a)}var APi=_(`IconSkip`,()=>(0,K.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`})),jPi={success:{label:`Completed`,icon:Jt},failed:{label:`Failed`,icon:ub},suspended:{label:`Needs input`,icon:Jw},waiting:{label:`Waiting`,icon:sx},paused:{label:`Paused`,icon:Jw},skipped:{label:`Skipped`,icon:APi},running:{label:`Running`,icon:fA},canceled:{label:`Canceled`,icon:lb}},MPi={label:`Status unavailable`,icon:eJ};function NPi({row:e,isSelected:t,isHovered:n,onSelectStep:r,onHoverStep:i,onOpenInput:a,onOpenOutput:o}){let s=Object.hasOwn(jPi,e.status)?jPi[e.status]:MPi,c=s.icon,l=Wot(e.status),u=e.stepId.slice(0,e.stepId.lastIndexOf(`.`)),d=e.isNestedEntry?e.stepId.slice(e.stepId.lastIndexOf(`.`)+1):e.stepId;return(0,K.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:T(`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,K.jsxs)(`button`,{type:`button`,"aria-disabled":e.isNestedEntry,"aria-pressed":t,onClick:()=>{e.isNestedEntry||r(e.stepId)},title:e.stepId,className:T(`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`,g),children:[(0,K.jsx)(`span`,{"aria-label":s.label,className:T(`grid size-6 flex-none place-items-center rounded-md bg-nested`,Got[l]),children:(0,K.jsx)(c,{"aria-hidden":!0,className:T(`size-3.5`,e.status===`running`&&`motion-safe:animate-spin`)})}),(0,K.jsxs)(`span`,{className:`min-w-0`,children:[(0,K.jsx)(W,{as:`span`,variant:`meta`,className:`block truncate`,children:d}),e.isNestedEntry&&(0,K.jsxs)(W,{as:`span`,variant:`meta`,tone:`muted`,className:`flex min-w-0 items-center gap-1`,children:[(0,K.jsx)(PKe,{"aria-hidden":!0,className:`size-icon-xs shrink-0`}),(0,K.jsx)(`span`,{className:`truncate`,children:u})]})]})]}),(0,K.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,K.jsx)(`div`,{"data-testid":`workflow-timeline-bar`,"data-offset":e.timing.offsetPct,"data-width":e.timing.widthPct,className:T(`absolute top-0 h-full min-w-0.5 rounded-sm`,Kot[l]),style:{left:`${e.timing.offsetPct}%`,width:`${e.timing.widthPct}%`}})}),(0,K.jsx)(W,{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,K.jsx)(W,{as:`span`,variant:`meta`,font:`mono`,children:hx(e.timing.durationMs)}):(0,K.jsx)(`span`,{"aria-label":`Timing unavailable`,children:`—`})}),(0,K.jsxs)(`div`,{className:`flex items-center`,children:[(0,K.jsx)(U,{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,K.jsx)(jE,{})}),(0,K.jsx)(U,{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,K.jsx)(AE,{})})]})]})}var PPi=e=>e.includes(`.`),FPi=e=>e===`input`||e.endsWith(`.input`),IPi=1;function LPi(e,t){let n=Yot(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 RPi(e,t){let n=Object.entries(e).filter(([e])=>!FPi(e)).map(([e,n])=>({stepId:e,step:n,...LPi(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,IPi),100-t)}}return{stepId:e,step:t,status:FE(t)?`suspended`:t.status,timing:s,spansSuspension:a,isRunning:r,isNestedEntry:PPi(e)}})}var zPi=_(`IconChevronGrabberVertical`,()=>(0,K.jsxs)(K.Fragment,{children:[(0,K.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,K.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`})]})),BPi=_(`IconChevronGrabberVerticalToward`,()=>(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`path`,{d:`M8 18.75L12 14.75L16 18.75`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`}),(0,K.jsx)(`path`,{d:`M8 5.25L12 9.25L16 5.25`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`})]}));function VPi(){let{steps:e}=tZ(),{selectedStepId:t,hoverStepId:n,setSelectedStepId:r,setHoverStepId:i}=tx(),[a,o]=(0,G.useState)(()=>Date.now()),[s,c]=(0,G.useState)(!0),[l,u]=(0,G.useState)(!1),{showData:d}=vA(),f=(0,G.useRef)(null),p=RPi(e,a),m=p.some(e=>e.isRunning);return EWe(f,{enabled:m&&!s}),(0,G.useEffect)(()=>{if(!m||s)return;let e=setInterval(()=>o(Date.now()),100);return()=>clearInterval(e)},[m,s]),p.length===0?null:(0,K.jsx)(`div`,{"data-testid":`workflow-timeline`,className:`relative z-20 shrink-0 px-2 pb-2`,children:(0,K.jsxs)(Ax,{open:!s,onOpenChange:e=>c(!e),className:T(kr,`@container/workflow-timeline pointer-events-auto overflow-hidden rounded-xl`),children:[(0,K.jsxs)(`div`,{className:`flex items-center`,children:[(0,K.jsxs)(jx,{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,K.jsx)(`span`,{children:(0,K.jsx)($H,{"aria-hidden":!0,className:`size-icon-md text-muted-foreground`})}),(0,K.jsx)(`span`,{children:`Timeline`}),(0,K.jsxs)(W,{as:`span`,variant:`meta`,tone:`muted`,children:[p.length,` events`]}),(0,K.jsx)(`span`,{className:`ml-auto`,children:(0,K.jsx)(Gr,{direction:`right`,className:`size-4`})})]}),!s&&(0,K.jsx)(U,{variant:`ghost`,size:`icon-sm`,tooltip:l?`Restore timeline height`:`Enlarge timeline`,"aria-pressed":l,onClick:()=>u(!l),className:`mr-2 shrink-0`,children:l?(0,K.jsx)(BPi,{}):(0,K.jsx)(zPi,{})})]}),(0,K.jsx)(Mx,{children:(0,K.jsx)(`div`,{ref:f,"data-testid":`workflow-timeline-list`,className:T(`overflow-auto overscroll-contain px-1.5 pb-1.5`,l?`max-h-[min(720px,calc(100dvh-112px))]`:`max-h-[min(320px,40dvh)]`),children:p.map(e=>(0,K.jsx)(NPi,{row:e,isSelected:t===e.stepId,isHovered:n===e.stepId,onSelectStep:r,onHoverStep:i,onOpenInput:(e,t)=>d({type:`step-input`,stepId:e.stepId},t),onOpenOutput:(e,t)=>d({type:`step-output`,stepId:e.stepId},t)},e.stepId))})})]})})}var HPi=({workflowId:e,workflow:t,isLoading:n})=>{let[r]=ex(`workflow`,e),{canExecute:i,isLoading:a}=Sb(),{stepDetail:o}=vA(),s=uS(),c=o?.type===`data`,l=(0,K.jsxs)(`div`,{className:`[container-type:size] relative h-full min-h-0`,children:[(0,K.jsx)(nir,{workflowId:e,workflow:t,isLoading:n,requestContext:r}),(0,K.jsx)(kPi,{hidden:c,requestContext:r,canResume:!a&&i(`workflows`)}),c&&(0,K.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,K.jsx)(rZ,{requestContext:r})}),(0,K.jsx)(`div`,{className:`pointer-events-none absolute right-0 bottom-0 left-[var(--workflow-left-panel-width,0px)] z-20`,children:(0,K.jsx)(VPi,{})})]});return s&&o&&!c?(0,K.jsx)(`div`,{className:`h-full min-h-0 overflow-hidden`,children:(0,K.jsx)(rZ,{requestContext:r})}):(0,K.jsxs)(`div`,{className:`relative h-full min-h-0`,children:[l,(0,K.jsxs)(V2,{className:`pointer-events-none absolute inset-0 z-30 min-h-0 w-full min-w-0 p-2`,children:[(0,K.jsx)(R2,{id:`workflow-graph`,className:`pointer-events-none min-w-0`}),o&&!c&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(H2,{className:`pointer-events-auto`}),(0,K.jsx)(R2,{id:`workflow-step-detail`,minSize:300,maxSize:`60%`,defaultSize:420,className:`min-w-0`,children:(0,K.jsx)(`div`,{className:`pointer-events-auto h-full min-h-0 overflow-hidden rounded-studio-panel border border-border bg-background`,children:(0,K.jsx)(rZ,{requestContext:r})})})]})]})]})},UPi=()=>{let{workflowId:e}=Yy(),{data:t,isLoading:n,error:r}=_A({workflowId:e,requestContext:ex(`workflow`,e)[0],queryOptions:{enabled:!!e}});return r&&Ej(r)?(0,K.jsx)(oI,{variant:`fill`}):r&&Dj(r)?(0,K.jsx)(aI,{variant:`fill`,resource:`workflows`}):(0,K.jsx)(HPi,{workflowId:e,workflow:t??void 0,isLoading:n})};function WPi(){let{workflowId:e}=Yy(),{error:t}=bI(e?{workflowId:e}:{});if(!e)return null;let n;return n=t&&Ej(t)?(0,K.jsx)(oI,{variant:`fill`}):t&&Dj(t)?(0,K.jsx)(aI,{variant:`fill`,resource:`schedules`}):(0,K.jsx)(`div`,{className:`h-full`,children:(0,K.jsx)(bPi,{workflowId:e})}),(0,K.jsxs)(Xb,{variant:`page`,children:[(0,K.jsx)(`h1`,{className:`sr-only`,children:`Schedules`}),n]})}function GPi(){let{workflowId:e}=Yy();return e?(0,K.jsx)(Sui,{scopedEntityId:e,scopedEntityType:qm.WORKFLOW_RUN}):null}var KPi=(0,G.createContext)(null);function q9(){let e=(0,G.useContext)(KPi);if(!e)throw Error(`Workspace components must be rendered inside <Workspace.Root>`);return e}function qPi(e){return(0,K.jsx)(bP,{...e,overflow:`scroll`,className:`rounded-none border-0 bg-transparent [&_pre]:p-4`})}function JPi(){return(0,K.jsxs)(`div`,{"aria-busy":`true`,className:`flex flex-col gap-2 p-4`,children:[(0,K.jsx)(Zb,{className:`h-4 w-1/2`}),(0,K.jsx)(Zb,{className:`h-4 w-5/6`}),(0,K.jsx)(Zb,{className:`h-4 w-2/3`})]})}var YPi=(0,G.lazy)(()=>Br(()=>import(`./code-editor-BLzt8hly-PE5zNvJf.js`).then(e=>e.n),__vite__mapDeps([5,6,1,4,7,8,9,10,11,3]),import.meta.url).then(e=>({default:e.CodeEditor})));function XPi({path:e,code:t,lang:n}){return t.length<=5e4?(0,K.jsx)(qPi,{code:t,lang:n}):(0,K.jsx)(G.Suspense,{fallback:(0,K.jsx)(JPi,{}),children:(0,K.jsx)(`div`,{className:`px-2 py-3`,children:(0,K.jsx)(YPi,{value:t,language:n??`text`,editable:!1,lineNumbers:!1,lineWrapping:!1,variant:`embedded`,"aria-label":e})})})}function ZPi(e,t){return Ej(e)?`Your session has expired. Sign in again to continue.`:Dj(e)?`You don't have permission to access this.`:Oj(e)?`This path no longer exists.`:e instanceof um&&e.status===501?`This workspace does not support this operation.`:t}function QPi({error:e,fallback:t,className:n}){return(0,K.jsx)(NE,{variant:`destructive`,className:n,children:(0,K.jsx)(NE.Message,{children:ZPi(e,t)})})}var $Pi=new Set([` `,` `,`
879
+ `).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 $Mi=({queryOptions:e}={})=>Gv({queryKey:[`mastra-templates`],queryFn:YMi,...e}),eNi=({repoOrSlug:e,owner:t,queryOptions:n})=>Gv({queryKey:[`template-repo`,e,t],queryFn:()=>ZMi({repoOrSlug:e,owner:t}),...n}),tNi=({repo:e,owner:t,branch:n,queryOptions:r})=>Gv({queryKey:[`template-repo-env-vars`,e,t,n],queryFn:()=>QMi({repo:e,owner:t,branch:n}),...r}),nNi=({queryOptions:e}={})=>{let t=X();return Gv({queryKey:[`agent-builder-workflow`],queryFn:async()=>await t.getAgentBuilderAction(`merge-template`).details(),...e})},rNi=({queryOptions:e}={})=>{let t=X();return qv({mutationFn:async({runId:e})=>await t.getAgentBuilderAction(`merge-template`).createRun({runId:e}),...e})},iNi=({queryOptions:e}={})=>{let t=X();return qv({mutationFn:async({runId:e})=>await t.getAgentBuilderAction(`merge-template`).runById(e),...e})},aNi=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)},oNi=(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=aNi(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=aNi(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}},sNi=(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)}},cNi=(e,t)=>{let[n,r]=(0,G.useState)({}),[i,a]=(0,G.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}=oNi(a,s,e);s=c,r(c),(a.runId||i||t)&&sNi(a.runId||i||t,c)}}catch(t){console.error(`💥 [processStream] Error processing template installation stream:`,t);let{newState:n}=oNi({type:`error`,payload:{error:t instanceof Error?t.message:`Unknown error`}},s,e);r(n)}finally{a(!1),o.releaseLock()}}}},lNi=({workflowInfo:e,queryOptions:t}={})=>{let n=X(),{streamResult:r,isStreaming:i,processStream:a}=cNi(e);return{streamInstall:qv({mutationFn:async({inputData:e,selectedModel:t,runId:r})=>{for(let i=1;i<=3;i++)try{let i=n.getAgentBuilderAction(`merge-template`),o=new Ha;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}},uNi=({workflowInfo:e,queryOptions:t}={})=>{let n=X(),{streamResult:r,isStreaming:i,processStream:a}=cNi(e);return{observeInstall:qv({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 dNi(e){return e.replace(/\/$/,``).split(`/`).pop()}function fNi({templates:e,linkComponent:t,className:n,isLoading:r}){let i=t||`a`;return r?(0,K.jsx)(`div`,{className:T(`grid gap-y-4`,n),children:Array.from({length:5}).map((e,t)=>(0,K.jsx)(`div`,{className:`h-16 animate-pulse rounded-lg bg-card`},t))}):(0,K.jsx)(`div`,{className:T(`grid gap-y-4`,n),children:e.map(e=>{let t=e?.agents||e?.tools||e?.networks||e?.workflows||e?.mcp;return(0,K.jsxs)(`article`,{className:T(kr,`grid w-full grid-cols-[1fr_auto] overflow-hidden rounded-lg state-layer`),children:[(0,K.jsxs)(i,{to:`/templates/${e.slug}`,className:T(`group grid`,{"grid-cols-[8rem_1fr] lg:grid-cols-[12rem_1fr]":e.imageURL}),children:[e.imageURL&&(0,K.jsx)(`div`,{className:`overflow-hidden`,children:(0,K.jsx)(`div`,{className:`thumb transition-scale h-full w-full bg-cover duration-150`,style:{backgroundImage:`url(${e.imageURL})`}})}),(0,K.jsxs)(`div`,{className:T(`grid w-full gap-0.5 px-4 py-3`,`[&_svg]:h-[1em] [&_svg]:w-[1em] [&_svg]:text-muted-foreground`),children:[(0,K.jsx)(W,{as:`h2`,tone:`ink`,children:e.title}),(0,K.jsx)(W,{className:T(Nb,x),children:e.description}),(0,K.jsxs)(`div`,{className:`mt-3 hidden flex-wrap items-center gap-x-8 gap-y-4 text-muted-foreground 2xl:flex`,children:[t&&(0,K.jsxs)(`ul`,{className:T(`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,K.jsx)(`li`,{children:(0,K.jsxs)(W,{as:`span`,variant:`body`,className:`block`,children:[(0,K.jsx)(FM,{}),` `,e.agents.length]})}),e?.tools&&e.tools.length>0&&(0,K.jsx)(`li`,{children:(0,K.jsxs)(W,{as:`span`,variant:`body`,className:`block`,children:[(0,K.jsx)(HM,{}),` `,e.tools.length]})}),e?.networks&&e.networks.length>0&&(0,K.jsx)(`li`,{children:(0,K.jsxs)(W,{as:`span`,variant:`body`,className:`block`,children:[(0,K.jsx)(Mtt,{}),` `,e.networks.length]})}),e?.workflows&&e.workflows.length>0&&(0,K.jsx)(`li`,{children:(0,K.jsxs)(W,{as:`span`,variant:`body`,className:`block`,children:[(0,K.jsx)(cx,{}),` `,e.workflows.length]})}),e?.mcp&&e.mcp.length>0&&(0,K.jsx)(`li`,{children:(0,K.jsxs)(W,{as:`span`,variant:`body`,className:`block`,children:[(0,K.jsx)(LM,{}),` `,e.mcp.length]})})]}),(0,K.jsx)(`div`,{className:`flex items-center gap-4`,children:e.supportedProviders.map(e=>(0,K.jsx)(W,{tone:`muted`,as:`span`,variant:`body`,children:e},e))})]})]})]}),(0,K.jsx)(`a`,{href:e.githubUrl,className:T(`group ml-auto hidden items-center gap-2 pr-4`,`lg:flex`),target:`_blank`,rel:`noopener noreferrer`,children:(0,K.jsx)(W,{as:`span`,variant:`body`,children:(0,K.jsxs)(`span`,{className:T(`flex items-center gap-2 rounded bg-nested px-2 py-1`,ct,Nb,x),children:[(0,K.jsx)(T4,{}),` `,dNi(e.githubUrl)]})})})]},e.slug)})})}function pNi({tagOptions:e,selectedTag:t,providerOptions:n,selectedProvider:r,onTagChange:i,onProviderChange:a,searchTerm:o,onSearchChange:s,onReset:c,className:l,isLoading:u}){return u?(0,K.jsxs)(`div`,{className:T(`flex h-[6.5rem] items-center gap-5`,`[&>div]:h-8 [&>div]:w-48 [&>div]:animate-pulse [&>div]:bg-card`,l),children:[(0,K.jsx)(`div`,{}),` `,(0,K.jsx)(`div`,{}),` `,(0,K.jsx)(`div`,{})]}):(0,K.jsxs)(`div`,{className:T(`sticky top-0 mx-auto flex flex-wrap gap-1.5 bg-background py-5`,l),children:[(0,K.jsx)($A,{label:`Search templates`,placeholder:`Search templates`,size:`sm`,value:o,onValueChange:s}),(0,K.jsxs)(ZE,{value:t,onValueChange:i,children:[(0,K.jsx)($E,{"aria-label":`Search by tag`,size:`sm`,className:`w-auto`,children:(0,K.jsx)(QE,{placeholder:`Select an option`})}),(0,K.jsx)(eD,{children:e.map(e=>(0,K.jsx)(tD,{value:e.value,children:e.label},e.value))})]}),(0,K.jsxs)(ZE,{value:r,onValueChange:a,children:[(0,K.jsx)($E,{"aria-label":`Search by provider`,size:`sm`,className:`w-auto`,children:(0,K.jsx)(QE,{placeholder:`Select an option`})}),(0,K.jsx)(eD,{children:n.map(e=>(0,K.jsx)(tD,{value:e.value,children:e.label},e.value))})]}),c&&(0,K.jsx)(tM,{onClick:c})]})}var mNi=[{id:`templates`,label:`Templates`}];function hNi(){let{data:e,isLoading:t}=$Mi(),{templates:n,tags:r,providers:i}=e??{templates:[],tags:[],providers:[]},[a,o]=(0,G.useState)(`all`),[s,c]=(0,G.useState)(`all`),[l,u]=(0,G.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,K.jsxs)(Xb,{variant:`page`,breadcrumbs:(0,K.jsx)(IA,{crumbs:mNi}),children:[(0,K.jsx)(`h1`,{className:`sr-only`,children:`Templates`}),(0,K.jsx)(Pb,{children:(0,K.jsxs)(wWe,{children:[(0,K.jsx)(gr,{children:(0,K.jsx)(w4,{})}),`Templates`]})}),(0,K.jsx)(pNi,{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,K.jsx)(fNi,{templates:g,linkComponent:tb,isLoading:t})]})}var gNi=_(`IconEmojiSad`,()=>(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`circle`,{cx:`12`,cy:`12`,r:`9`,stroke:`currentColor`,strokeWidth:`2`}),(0,K.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,K.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,K.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 _Ni({children:e,className:t}){return(0,K.jsx)(`div`,{className:T(`transition-height mt-12 rounded-lg border border-border px-4 py-5 lg:min-h-[25rem] lg:px-12`,t),children:e})}function vNi({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,K.jsx)(mb,{className:`text-warning-foreground`}),title:`Template Installed with Warnings`}:{icon:(0,K.jsx)(gNi,{}),title:`Template Installation Failed`};return(0,K.jsxs)(_Ni,{className:`mb-5 content-center space-y-4 text-muted-foreground`,children:[(0,K.jsxs)(`div`,{className:`grid content-center items-center justify-items-center gap-4 [&>svg]:h-8 [&>svg]:w-8`,children:[o,(0,K.jsxs)(`div`,{className:`space-y-2 text-center`,children:[(0,K.jsx)(W,{variant:`subheading`,tone:`ink`,children:s}),(0,K.jsx)(W,{tone:`muted`,children:a()})]})]}),t&&t.length>0&&(0,K.jsxs)(`details`,{children:[(0,K.jsx)(`summary`,{className:T(`text-muted-foreground hover:text-foreground`,`cursor-pointer text-center select-none`),children:(0,K.jsxs)(W,{as:`span`,variant:`caption`,className:`block`,children:[`Show Validation Issues (`,t.length,`)`]})}),(0,K.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,K.jsxs)(`div`,{className:`border-l-2 border-destructive-indicator pl-2`,children:[(0,K.jsx)(W,{as:`p`,variant:`column`,className:`text-destructive-foreground`,children:e.type===`typescript`?`🔴 TypeScript Error`:`⚠️ Lint Error`}),(0,K.jsx)(yx,{className:`mt-1 text-caption wrap-break-word whitespace-pre-wrap text-muted-foreground`,code:e.message})]},t))})]}),n&&!i&&(0,K.jsxs)(`details`,{children:[(0,K.jsx)(`summary`,{className:T(`text-muted-foreground hover:text-foreground`,`cursor-pointer text-center select-none`),children:(0,K.jsx)(W,{as:`span`,variant:`caption`,className:`block`,children:`Show Details`})}),(0,K.jsx)(`div`,{className:`mt-4 max-h-60 overflow-auto rounded bg-muted p-3 text-left`,children:(0,K.jsx)(yx,{className:`text-caption wrap-break-word whitespace-pre-wrap`,code:n})})]})]})}function yNi({providerOptions:e,selectedProvider:t,onProviderChange:n,variables:r,errors:i,handleInstallTemplate:a,handleVariableChange:o,isLoadingEnvVars:s,isInstalling:c,defaultModelProvider:l,defaultModelId:u,onModelUpdate:d}){return(0,K.jsx)(_Ni,{children:(0,K.jsxs)(`div`,{className:`mx-auto my-4 grid max-w-[40rem] gap-5 p-4 lg:p-5`,children:[(0,K.jsxs)(W,{as:`h2`,variant:`heading`,tone:`muted`,className:T(`flex items-center gap-2`,`[&_svg]:h-[1.2em] [&_svg]:opacity-70 [&>svg]:w-[1.2em]`),children:[`Install Template `,(0,K.jsx)(w4,{})]}),(0,K.jsxs)(gE,{orientation:`horizontal`,children:[(0,K.jsx)(vE,{children:`Template AI Model Provider`}),(0,K.jsx)(Pat,{className:`flex-1`,children:(0,K.jsxs)(ZE,{name:`template-provider`,value:t,onValueChange:n,children:[(0,K.jsx)($E,{size:`md`,children:(0,K.jsx)(QE,{placeholder:`Select`})}),(0,K.jsx)(eD,{children:e.map(e=>(0,K.jsx)(tD,{value:e.value,children:e.label},e.value))})]})})]}),t&&Object.entries(r||{}).length>0&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(W,{as:`h3`,tone:`muted`,children:`Set required Environmental Variables`}),(0,K.jsx)(`div`,{className:`grid grid-cols-[1fr_1fr] items-start gap-4`,children:s?(0,K.jsxs)(`div`,{className:T(`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,K.jsx)(pt,{}),(0,K.jsxs)(W,{as:`span`,variant:`caption`,className:`block`,children:[` `,`Loading variables...`]})]}):Object.entries(r).map(([e,t])=>(0,K.jsxs)(G.Fragment,{children:[(0,K.jsxs)(gE,{className:`w-full`,children:[(0,K.jsx)(vE,{className:`sr-only`,children:`Key`}),(0,K.jsx)(ak,{name:`env-${e}`,value:e,disabled:!0,className:`w-full`})]}),(0,K.jsxs)(gE,{invalid:i.includes(e),className:`w-full`,children:[(0,K.jsx)(vE,{className:`sr-only`,children:`Value`}),(0,K.jsx)(ak,{name:e,value:t,onChange:o,autoComplete:`off`,className:`w-full`}),(0,K.jsx)(bE,{children:i.includes(e)?`Value is required.`:void 0})]})]},e))}),(0,K.jsxs)(`div`,{className:`relative mt-3.5 border-t border-border pt-12`,children:[(0,K.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,K.jsx)(W,{tone:`muted`,as:`span`,variant:`caption`,className:`block`,children:`And`})}),(0,K.jsx)(W,{as:`h3`,tone:`muted`,children:`Set AI Model for Template Installation`}),(0,K.jsx)(W,{tone:`muted`,className:`mt-2 mb-5`,children:`This model will be used by the workflow to process and install the template`}),(0,K.jsx)(T0r,{defaultProvider:l||``,defaultModel:u||``,updateModel:d||(()=>Promise.resolve({message:`Updated`})),closeEditor:()=>{},autoSave:!0,selectProviderPlaceholder:`Provider`})]})]}),t&&!s&&(0,K.jsx)(U,{className:T(`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||!l||!u||i.length>0,iconEnd:(0,K.jsx)(nM,{}),loading:c,children:`Install`})]})})}function bNi({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,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`mt-5 grid items-center`,children:(0,K.jsxs)(`div`,{className:T(`flex items-center gap-3`,`[&>svg]:h-[1.2em] [&>svg]:w-[1.2em] [&>svg]:opacity-50`,{"[&>svg]:opacity-20":r}),children:[(0,K.jsx)(w4,{}),(0,K.jsx)(`h2`,{className:T({"flex min-w-[50%] rounded-lg bg-muted":r}),children:(0,K.jsx)(W,{as:`span`,variant:`title`,className:`block`,children:r?(0,K.jsx)(K.Fragment,{children:`\xA0`}):e})})]})}),(0,K.jsxs)(`div`,{className:`grid gap-x-24 lg:grid-cols-[1fr_1fr]`,children:[(0,K.jsxs)(`div`,{className:`grid`,children:[(0,K.jsx)(W,{tone:`muted`,className:T(`mt-2 mb-4`,{"rounded-lg bg-muted":r}),children:r?(0,K.jsx)(K.Fragment,{children:`\xA0`}):t}),!r&&a&&(0,K.jsxs)(`div`,{className:T(`mb-4 rounded-lg bg-nested p-4`,`flex items-start gap-3`),children:[(0,K.jsx)(`div`,{className:`mt-0.5 shrink-0`,children:(0,K.jsx)(fb,{className:`h-[1.1em] w-[1.1em] text-info-indicator`})}),(0,K.jsxs)(`div`,{className:`flex-1 space-y-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(ix,{className:`h-[1em] w-[1em] text-muted-foreground`}),(0,K.jsx)(W,{as:`span`,variant:`subheading`,tone:`ink`,children:`A new Git branch will be created`})]}),(0,K.jsxs)(`div`,{className:`space-y-1`,children:[(0,K.jsxs)(W,{tone:`muted`,as:`p`,variant:`caption`,children:[(0,K.jsx)(W,{as:`span`,variant:`column`,children:`Branch name:`}),` `,(0,K.jsx)(cP,{children:o})]}),(0,K.jsx)(W,{tone:`muted`,as:`p`,variant:`caption`,children:`This ensures safe installation with easy rollback if needed. Your main branch remains unchanged.`})]})]})]}),n&&(0,K.jsxs)(`a`,{href:n,target:`_blank`,rel:`noopener noreferrer`,className:T(`text-muted-foreground hover:text-foreground`,`mt-auto flex items-center gap-2`),children:[(0,K.jsx)(T4,{}),(0,K.jsx)(W,{as:`span`,variant:`body`,className:`block`,children:n?.split(`/`)?.pop()})]})]}),i&&(0,K.jsx)(s0r,{data:i,labelsAreHidden:!0,isLoading:r})]})]})}function xNi(e){switch(e){case`running`:return(0,K.jsx)(pt,{size:`sm`,"aria-hidden":!0});case`success`:return(0,K.jsx)(Jt,{"aria-hidden":!0});case`failed`:return(0,K.jsx)(Px,{"aria-hidden":!0});default:return null}}function SNi(){return(0,K.jsx)(`svg`,{viewBox:`0 0 24 24`,className:`text-subtle-foreground`,"aria-hidden":!0,children:(0,K.jsx)(`circle`,{cx:`12`,cy:`12`,r:`8.5`,pathLength:`48`,fill:`none`,stroke:`currentcolor`,strokeWidth:`2.8`,strokeLinecap:`round`,strokeDasharray:`3 3`})})}function CNi({status:e,variant:t}){return t===`plain`?(0,K.jsx)(`span`,{className:T(`flex size-icon-md items-center justify-center self-center [&>svg]:size-icon-md`,c.colors,{"[&>svg]:text-success-indicator":e===`success`,"[&>svg]:text-destructive-foreground":e===`failed`}),children:e===`pending`?(0,K.jsx)(SNi,{}):xNi(e)}):(0,K.jsx)(`span`,{className:T(`flex size-7 items-center justify-center self-center rounded-full motion-reduce:transition-none`,c.colors,c.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:xNi(e)})}function wNi({step:e,isActive:t,position:n,variant:r=`default`}){let i=t||e.status===`success`?`ink`:`muted`;return(0,K.jsxs)(`div`,{className:T(`grid grid-cols-[1fr_auto] gap-6 rounded-lg px-4 py-3 motion-reduce:transition-none`,c.colors,{"border border-transparent":r==="default","border-dashed border-placeholder bg-card":t&&r==="default"}),children:[(0,K.jsxs)(`div`,{className:`grid min-w-0 grid-cols-[auto_1fr] gap-2`,children:[(0,K.jsxs)(W,{as:`span`,tone:i,className:T(`flex min-w-6 justify-end`,c.colors),children:[n,`.`]}),(0,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsx)(W,{as:`h4`,tone:i,className:c.colors,children:e.title}),e.description&&(0,K.jsx)(W,{tone:`faint`,className:T(`-mt-0.5`,{truncate:r===`plain`}),children:e.description})]})]}),(0,K.jsx)(CNi,{status:e.status,variant:r})]})}function TNi({currentStep:e,steps:t=[],className:n}){return(0,K.jsx)(`div`,{className:T(n),children:t.map((t,n)=>(0,K.jsx)(wNi,{step:t,isActive:e?.id===t.id,position:n+1},t.id))})}function ENi({steps:e}){let t=e.length,n=e.filter(e=>e.status===`success`).length;return(0,K.jsxs)(`div`,{className:`flex w-full flex-col content-center justify-center gap-4`,children:[(0,K.jsx)(`div`,{className:`grid w-full grid-cols-[0_repeat(9,1fr)]`,children:e.map((t,n)=>(0,K.jsx)(`div`,{className:T(`relative flex h-8 items-center justify-end`,c.colors,{"bg-success-subtle":t.status===`success`&&e?.[n-1]?.status===`success`}),children:(0,K.jsx)(`div`,{className:T(`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`,c.colors,c.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,K.jsx)(pt,{}):n+1})},t.id))}),(0,K.jsxs)(`div`,{className:T(`text-center text-caption text-muted-foreground`,c.colors),children:[n,` of `,t,` steps completed`]})]})}var DNi=(0,G.createContext)(3);function ONi({title:e,description:t,action:n,done:r,className:i,children:a}){let o=(0,G.useContext)(DNi);return(0,K.jsxs)(`li`,{className:T(`group/step grid grid-cols-[1.5rem_minmax(0,1fr)] gap-x-4 [counter-increment:ds-step]`,i),children:[(0,K.jsxs)(`div`,{className:`flex flex-col items-center`,children:[(0,K.jsx)(`span`,{className:T(`flex size-6 shrink-0 items-center justify-center rounded-full`,c.colors,r?`bg-success-indicator/18 text-success-indicator`:`bg-fill text-foreground`),children:r?(0,K.jsx)(Jt,{className:`size-icon-sm`,"aria-label":`Done`}):(0,K.jsx)(W,{as:`span`,variant:`column`,className:`before:content-[counter(ds-step)]`,"aria-hidden":!0})}),(0,K.jsx)(`span`,{"aria-hidden":!0,className:`w-px flex-1 bg-border group-last/step:hidden`})]}),(0,K.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-3 pb-8 group-last/step:pb-0`,children:[(0,K.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,K.jsxs)(`div`,{className:`flex min-h-6 flex-wrap items-center justify-between gap-x-6 gap-y-2`,children:[(0,K.jsx)(W,{as:o===2?`h2`:`h3`,variant:`label`,className:`text-pretty`,children:e}),n==null?null:(0,K.jsx)(`div`,{className:`flex shrink-0 items-center gap-2`,children:n})]}),t==null?null:(0,K.jsx)(W,{as:`p`,variant:`body-sm`,tone:`muted`,className:`max-w-[70ch] text-pretty`,children:t})]}),a]})]})}function kNi({headingLevel:e=3,className:t,children:n}){return(0,K.jsx)(DNi.Provider,{value:e,children:(0,K.jsx)(`ol`,{className:T(`flex flex-col [counter-reset:ds-step]`,t),children:n})})}Object.assign(kNi,{Step:ONi});function ANi({name:e,streamResult:t,runId:n,workflowInfo:r}){let i=t?.phase||`initializing`,a=t?.payload?.workflowState,o=t?.payload?.currentStep,s=t?.error,c=a?.steps||{},l=Object.keys(c).length>0,u=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,d=Object.entries(c).filter(([e,t])=>u(e)),f=d.length,p=()=>{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...`}},m=d.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,K.jsxs)(_Ni,{className:`mb-5 content-center space-y-6 text-muted-foreground`,children:[(0,K.jsxs)(`div`,{className:`text-center`,children:[(0,K.jsx)(W,{as:`h3`,variant:`heading`,tone:`ink`,children:p()}),(t?.runId||n)&&(0,K.jsxs)(W,{as:`p`,variant:`caption`,tone:`muted`,className:`mt-2`,children:[`Run ID: `,t?.runId??n]})]}),l&&f>0&&![`error`].includes(i)&&(0,K.jsx)(`div`,{className:`mx-auto w-full max-w-[30rem] px-4`,children:(0,K.jsx)(ENi,{steps:m})}),s&&i===`error`&&(0,K.jsxs)(`div`,{className:T(`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,K.jsx)(ub,{}),(0,K.jsx)(W,{as:`span`,variant:`body`,className:`block`,children:s||`Something went wrong`})]}),l&&(0,K.jsx)(TNi,{steps:m,currentStep:o,className:`pb-4`}),!l&&i===`initializing`&&(0,K.jsxs)(`div`,{className:T(`text-muted-foreground`,`grid justify-items-center gap-4 text-center`),children:[(0,K.jsx)(pt,{}),(0,K.jsx)(W,{as:`p`,variant:`body`,children:`This may take some time...`})]})]})}function jNi({name:e,installedEntities:t}){return(0,K.jsxs)(_Ni,{className:T(`grid content-center items-center justify-items-center gap-4`,`[&>svg]:h-8 [&>svg]:w-8`),children:[(0,K.jsx)(w4,{}),(0,K.jsx)(W,{as:`h2`,variant:`heading`,children:`Done!`}),(0,K.jsxs)(W,{tone:`muted`,className:`text-center`,children:[`The `,(0,K.jsx)(`b`,{className:`text-muted-foreground`,children:e}),` template has been successfully installed.`,t&&t.length>0&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`br`,{}),` Installed entities are listed below.`]})]}),t&&t.length>0&&(0,K.jsx)(s0r,{data:t})]})}function MNi(){let{templateSlug:e}=Yy(),t=[{id:`templates`,label:`Templates`,to:`/templates`},{id:`template`,label:K2t(e)}],[n,r]=nb(),[i,a]=(0,G.useState)(``),[o,s]=(0,G.useState)(``),[c,l]=(0,G.useState)(``),[u,d]=(0,G.useState)({}),[f,p]=(0,G.useState)([]),[m,h]=(0,G.useState)(null),[g,_]=(0,G.useState)(!1),[v,y]=(0,G.useState)(``),[b,x]=(0,G.useState)(!1),[S,C]=(0,G.useState)(!1),[w,T]=(0,G.useState)([]),{data:E,isLoading:D}=eNi({repoOrSlug:e,owner:`mastra-ai`}),O=`1.87.0-alpha.9`.includes(`beta`)??!1?`beta`:`main`,{data:k,isLoading:A}=tNi({repo:E?.githubUrl?new URL(E.githubUrl).pathname.split(`/`)[2]:`template-${e}`,owner:`mastra-ai`,branch:O}),{data:j,isLoading:M}=nNi(),{mutateAsync:N,isPending:P}=rNi(),{mutateAsync:F}=iNi(),{streamInstall:I,streamResult:L,isStreaming:R}=lNi({workflowInfo:j}),{observeInstall:z,streamResult:B,isStreaming:ee}=uNi({workflowInfo:j});(0,G.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,G.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,K.jsx)(HM,{})},{key:`agents`,label:`Agents`,value:E?.agents?.length?E.agents.map(e=>e).join(`, `):`n/a`,icon:(0,K.jsx)(FM,{})},{key:`workflows`,label:`Workflows`,value:E?.workflows?.length?E.workflows.map(e=>e).join(`, `):`n/a`,icon:(0,K.jsx)(cx,{})},{key:`providers`,label:`Providers`,value:E?.supportedProviders?.length?E.supportedProviders.join(`, `):`n/a`,icon:(0,K.jsx)(O3,{})},{key:`tags`,label:`Tags`,value:E?.tags?.length?E.tags.join(`, `):`n/a`,icon:(0,K.jsx)(hM,{})}],ne=[{...te[0]},{...te[1]},{...te[2]}].filter(e=>e.value!==`n/a`);return(0,G.useEffect)(()=>{k&&d(k)},[k]),(0,G.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,K.jsxs)(Xb,{variant:`page`,breadcrumbs:(0,K.jsx)(IA,{crumbs:t}),children:[(0,K.jsx)(`h1`,{className:`sr-only`,children:e}),(0,K.jsxs)(`div`,{className:`grid gap-y-6`,children:[(0,K.jsx)(bNi,{isLoading:D,title:E?.title,description:E?.longDescription,imageURL:E?.imageURL,githubUrl:E?.githubUrl,infoData:te,templateSlug:e}),E&&(0,K.jsxs)(K.Fragment,{children:[(R||ee)&&(0,K.jsx)(ANi,{name:E.title,streamResult:ee?B:L,runId:v,workflowInfo:j}),g&&(0,K.jsx)(jNi,{name:E.title,installedEntities:ne,linkComponent:tb}),m&&(0,K.jsx)(vNi,{errorMsg:m,validationErrors:w.length>0?w:L?.validationResults?.errors||B?.validationResults?.errors}),!R&&!ee&&!g&&!m&&(0,K.jsx)(yNi,{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 NNi=e=>e.threadId,PNi=e=>`traces`in e?e.traces:e.threads;function FNi(e,t){return`traces`in e?{traces:{...e.traces,...t}}:{threads:{...e.threads,...t}}}function INi(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 LNi({query:e,rolling:t,fixedStart:n=!1,autoRefetch:r=!0,limit:i,enabled:a=!0}){let o=X(),{anchorWindow:s,reanchor:c}=yMi(e,n),l=(0,G.useMemo)(()=>s?{...e,timeRange:FNi(e.timeRange,s)}:e,[e,s]),u=w4r({query:l,limit:i,enabled:a,queryOptions:mMi}),{headRows:d}=xMi({queryKey:[`threads`,e],fetchHead:async t=>(await o.queryTraceThreads({...e,timeRange:FNi(e.timeRange,vMi(PNi(e.timeRange),t,n)),orderBy:[{field:`endedAt`,direction:`desc`}],page:{limit:50}})).threads,getId:NNi,getEndedAt:e=>e.endedAt,since:Date.parse(PNi(l.timeRange).to),enabled:a&&t&&r&&u.threads!==void 0&&!u.isFetching&&!u.isError,onOverflow:()=>c(PNi(e.timeRange))}),{orderBy:f}=e,p=u.threads,m=(0,G.useMemo)(()=>p&&CMi(p,d,{getId:NNi,compare:INi(f),hasNextPage:u.hasNextPage}),[p,d,f,u.hasNextPage]);return{...u,threads:m}}function RNi(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 zNi=[`last-24h`,`last-3d`,`last-7d`,`last-14d`,`last-30d`,`custom`],BNi=[];function VNi(){let{data:e}=G5(),t=e?.capabilities.traceQueryTimeToFirstChunk??!1,n=e?.capabilities.traceQueryTimeToFirstToken??!1,{data:r=BNi}=O6(),{data:i=BNi}=k6();return(0,G.useMemo)(()=>[aM,...Roi({withTimeToFirstChunk:t,withTimeToFirstToken:n,entityNames:r,environments:i})],[t,n,r,i])}function HNi({tokens:e,groups:t,onFiltersChange:n}){let r=(0,G.useMemo)(()=>s8(e),[e]),i=(0,G.useMemo)(()=>{let e=c8([],t);return{...e,nodes:[oM,...r,...e.nodes]}},[r,t]),a=(0,G.useCallback)(e=>{let t=b6r({...e,nodes:e.nodes.filter(e=>zj(e)||e.fieldId!==`timeRange`)});n(t.tokens,t.groups)},[n]);return{filterBarValue:i,onFilterBarChange:a,onFilterByField:(0,G.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(zj);a({...i,nodes:[...n,o,...s]})},[r,i,a])}}var UNi=e=>e;function WNi({datePreset:e,dateFrom:t,dateTo:n,minDate:r,tokens:i,groups:a,onDatePresetChange:o,onDateChange:s,onDateRangeChange:c,onFiltersChange:l,disabled:u}){let d=VNi(),{filterBarValue:f,onFilterBarChange:p}=HNi({tokens:i,groups:a,onFiltersChange:l});return(0,K.jsxs)(pM,{fields:d,operators:q3r,value:f,onValueChange:p,createItemId:UNi,maxDepth:3,"aria-label":`Thread filters`,className:`min-w-64 flex-1`,children:[(0,K.jsx)(pM.Chips,{renderChip:i=>i.fieldId===`timeRange`?(0,K.jsx)(pM.TimeRange,{preset:e,onPresetChange:o,dateFrom:t,dateTo:n,minDate:r,onDateChange:s,onDateRangeChange:c,disabled:u,presets:zNi,defaultPreset:f8.datePreset}):(0,K.jsx)(pM.Chip,{item:i})}),(0,K.jsx)(pM.Input,{placeholder:`Filter threads`})]})}function GNi({selectedThreadId:e,onSelectedThreadChange:t,onOpenScore:n,urlState:r}){let i=gMi(r),{timeRange:a,tokens:o,groups:s,sort:c}=i,l=K5().enabled,u=lci().enabled,d=Wsi({scope:`threads`}),{data:f,isLoading:p}=G5(),m=f?.capabilities.traceQueryTimeToFirstChunk??!1,h=f?.capabilities.traceQueryTimeToFirstToken??!1,g=(0,G.useMemo)(()=>p?d.preferences:w2r(d.preferences,{withTimeToFirstChunk:m,withTimeToFirstToken:h}),[d.preferences,p,m,h]),{threads:_,hasNextPage:v,isFetchingNextPage:y,setEndOfListElement:b,isLoading:x,isError:S,error:C}=LNi({query:(0,G.useMemo)(()=>{let e=Voi(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,G.useMemo)(()=>(_??[]).map(RNi),[_]),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,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`h1`,{className:`sr-only`,children:`Threads`}),(0,K.jsx)(B8r,{toolbar:(0,K.jsxs)(K.Fragment,{children:[r&&(0,K.jsx)(zsi,{page:`threads`,...r,columns:d}),(0,K.jsxs)(_M,{children:[(0,K.jsx)(_M.Start,{children:(0,K.jsx)(WNi,{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,K.jsx)(_M.End,{children:(0,K.jsx)(WMi,{scope:`threads`,value:d.preferences,onChange:d.setPreferences})})]})]}),error:S?(0,K.jsx)(_6,{error:C,resource:`threads`,errorTitle:`Failed to load threads`}):void 0,empty:D?(0,K.jsx)(i2r,{resource:`threads`,datePreset:i.datePreset,dateFrom:i.dateFrom,dateTo:i.dateTo}):void 0,children:(0,K.jsx)(uei,{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,K.jsx)(aui,{open:!!e,threadId:e??``,depth:1,closeLabel:`Close`,withQueryTrace:l,withFeedback:u,onOpenScore:n,onClose:()=>t(void 0)})]})}function KNi(){let{enabled:e,isLoading:t}=oci(),n=Jy(),[r,i]=nb();return(0,K.jsx)(fMi,{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,K.jsx)(GNi,{urlState:{searchParams:r,setSearchParams:i},selectedThreadId:kMi(r),onSelectedThreadChange:e=>i(t=>AMi(t,e),{replace:!0}),onOpenScore:(e,t)=>n(XVn(e,t))})})}var qNi=()=>(0,K.jsx)(db,{titleSlot:`No Workflows yet`,descriptionSlot:(0,K.jsxs)(K.Fragment,{children:[`Mastra workflows are not configured yet. `,(0,K.jsx)(`br`,{}),`More information in the documentation.`]}),actionSlot:(0,K.jsx)(U,{variant:`ghost`,render:(0,K.jsx)(`a`,{href:`https://mastra.ai/docs/workflows/overview`,target:`_blank`,rel:`noopener noreferrer`}),icon:(0,K.jsx)(qM,{}),children:`Workflows documentation`}),variant:`fill`});function JNi(e,t,n){return k4(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 YNi(e){return Object.keys(e.steps??{}).filter(t=>e.allSteps?.[t]?.isWorkflow)}function XNi(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 ZNi(e,t,n){let r=XNi(t),i=[],a=(e,o,s,c,l,u)=>{let d=YNi(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 QNi=`auto 24rem minmax(0, 1fr) auto auto auto`;function $Ni({guides:e,isLastChild:t}){return(0,K.jsxs)(`span`,{"aria-hidden":!0,className:`-my-6 flex shrink-0 self-stretch`,children:[e.map((e,t)=>(0,K.jsx)(`span`,{className:T(`w-6`,e&&`border-l border-border`)},t)),(0,K.jsxs)(`span`,{className:`relative w-6`,children:[(0,K.jsx)(`span`,{className:T(`absolute top-0 left-0 border-l border-border`,t?`h-1/2`:`h-full`)}),(0,K.jsx)(`span`,{className:`absolute top-1/2 left-0 w-3.5 border-b border-border`})]})]})}function ePi({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,K.jsx)(`div`,{className:`flex items-center pl-5`,children:r?(0,K.jsx)(`button`,{type:`button`,"aria-expanded":t,"aria-label":`${t?`Collapse`:`Expand`} nested workflows of ${i}`,className:T(Mb,`relative grid size-5 shrink-0 place-items-center before:absolute before:-inset-1.5 before:content-['']`),onClick:e=>{e.stopPropagation(),n()},children:(0,K.jsx)(Gr,{direction:`right`,className:`size-4`})}):(0,K.jsx)(`span`,{className:`size-5 shrink-0`,"aria-hidden":!0})})}var tPi=e=>e.stopPropagation();function nPi({sortKey:e,sort:t,onSortChange:n,children:r}){return n?(0,K.jsx)(Z.SortableTopCell,{sortKey:e,sort:t?.key===e?t.direction:void 0,onSortChange:t=>n(t,e),children:r}):(0,K.jsx)(Z.TopCell,{children:r})}function rPi({row:e,isExpanded:t,onToggle:n,runCount:r,rowProps:i}){let{paths:a,Link:o}=xa(),s=(0,G.useRef)(null),{workflow:c,nestedIds:l}=e,u=qA(c.name,50),d=qA(c.description??``,200),f=Object.keys(c.steps??{}).length,p=r?.running??0,m=r?.suspended??0,h=l.length>0;return(0,K.jsxs)(Z.RowWrapper,{...i,onSelectRow:()=>s.current?.click(),children:[(0,K.jsx)(ePi,{row:e,isExpanded:t,onToggle:n}),(0,K.jsxs)(Z.RowLink,{ref:s,colStart:2,to:a.workflowLink(c.id),LinkComponent:o,tabIndex:-1,onClick:tPi,children:[(0,K.jsx)(Z.NameCell,{children:(0,K.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[e.depth>0?(0,K.jsx)($Ni,{guides:e.guides,isLastChild:e.isLastChild}):null,(0,K.jsx)(`span`,{className:`truncate`,children:u}),c.origin===`dynamic`?(0,K.jsx)(dx,{size:`xs`,variant:`blue`,title:`Registered via the dynamic-workflows API`,children:`Dynamic`}):null,h?(0,K.jsxs)(W,{as:`span`,variant:`body-sm`,tone:`muted`,title:`Nested workflows: ${l.join(`, `)}`,className:`inline-flex shrink-0 items-center gap-1`,children:[(0,K.jsx)(cx,{"aria-hidden":!0,className:`size-icon-sm`}),l.length]}):null]})}),(0,K.jsx)(Z.DescriptionCell,{children:d}),(0,K.jsx)(Z.TextCell,{className:`text-center`,children:p>0?(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-info-indicator`,"aria-label":`${p} run${p===1?``:`s`} in progress`,children:[(0,K.jsx)(`span`,{"aria-hidden":!0,className:`size-2 rounded-full bg-info-indicator motion-safe:animate-pulse`}),p]}):``}),(0,K.jsx)(Z.TextCell,{className:`text-center`,children:m>0?(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-warning-foreground`,"aria-label":`${m} run${m===1?``:`s`} awaiting input`,children:[(0,K.jsx)(Jw,{"aria-hidden":!0,className:`size-icon-sm`}),m]}):``}),(0,K.jsx)(Z.TextCell,{className:`text-center`,children:f||``})]})]})}function iPi({workflows:e,isLoading:t,search:n=``,sort:r,onSortChange:i,requestContext:a}){let[o,s]=(0,G.useState)(new Set),c=jvt({requestContext:a}),l=(0,G.useMemo)(()=>Object.entries(e).map(([e,t])=>({...t,id:e})),[e]),u=(0,G.useMemo)(()=>{let e=n.toLowerCase();return l.filter(t=>t.name?.toLowerCase().includes(e)||t.description?.toLowerCase().includes(e))},[l,n]),d=(0,G.useMemo)(()=>JNi(u,r,c),[u,r,c]),f=(0,G.useMemo)(()=>ZNi(d,e,o),[d,e,o]),p=(0,G.useMemo)(()=>{let e=new Map;for(let t of f)t.kind===`workflow`&&e.set(t.pathKey,e.size);return e},[f]),{containerRef:m,getRowProps:h}=PM({count:p.size,global:!0}),_=e=>{s(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return t?(0,K.jsx)(UM,{columns:QNi,fit:`container`}):(0,K.jsxs)(Z,{columns:QNi,fit:`container`,scrollRef:m,children:[(0,K.jsxs)(Z.Top,{children:[(0,K.jsx)(Z.TopCell,{children:(0,K.jsx)(`span`,{className:`sr-only`,children:`Expand`})}),(0,K.jsx)(nPi,{sortKey:`name`,sort:r,onSortChange:i,children:`Name`}),(0,K.jsx)(Z.TopCell,{children:`Description`}),(0,K.jsx)(nPi,{sortKey:`running`,sort:r,onSortChange:i,children:`Running`}),(0,K.jsx)(nPi,{sortKey:`suspended`,sort:r,onSortChange:i,children:`Pending input`}),(0,K.jsx)(nPi,{sortKey:`steps`,sort:r,onSortChange:i,children:`Number of steps`})]}),f.length===0&&n?(0,K.jsx)(Z.NoMatch,{message:`No Workflows match your search`}):null,f.map(e=>{let t=o.has(e.pathKey),n=()=>_(e.pathKey);return e.kind===`unregistered`?(0,K.jsxs)(Z.RowStatic,{className:`gap-0 px-0`,children:[(0,K.jsx)(ePi,{row:e,isExpanded:t,onToggle:n}),(0,K.jsxs)(`div`,{className:`col-span-5 col-start-2 grid grid-cols-subgrid gap-4 px-3`,children:[(0,K.jsx)(Z.NameCell,{children:(0,K.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,K.jsx)($Ni,{guides:e.guides,isLastChild:e.isLastChild}),(0,K.jsx)(`span`,{className:`truncate`,children:qA(e.stepId,50)}),(0,K.jsxs)(jn,{children:[(0,K.jsx)(dr,{render:(0,K.jsx)(W,{as:`span`,variant:`body-sm`,tone:`muted`}),role:`note`,tabIndex:0,className:T(`shrink-0 rounded-sm`,g),children:`not registered`}),(0,K.jsx)(qt,{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,K.jsx)(Z.DescriptionCell,{children:qA(e.description??``,200)}),(0,K.jsx)(Z.TextCell,{className:`text-center`,children:``}),(0,K.jsx)(Z.TextCell,{className:`text-center`,children:``}),(0,K.jsx)(Z.TextCell,{className:`text-center`,children:``})]})]},`workflow-${e.pathKey}`):(0,K.jsx)(rPi,{row:e,isExpanded:t,onToggle:n,runCount:c[e.workflow.id],rowProps:h(p.get(e.pathKey)??-1)},`workflow-${e.pathKey}`)})]})}var G9=[vI(`/workflows`)];function aPi(){let{data:e,isLoading:t,error:n}=gA(),[r,i]=(0,G.useState)(``),[a,o]=(0,G.useState)();return n&&Ej(n)?(0,K.jsxs)(Xb,{variant:`page`,breadcrumbs:(0,K.jsx)(IA,{crumbs:G9}),children:[(0,K.jsx)(`h1`,{className:`sr-only`,children:`Workflows`}),(0,K.jsx)(oI,{variant:`fill`})]}):n&&Dj(n)?(0,K.jsxs)(Xb,{variant:`page`,breadcrumbs:(0,K.jsx)(IA,{crumbs:G9}),children:[(0,K.jsx)(`h1`,{className:`sr-only`,children:`Workflows`}),(0,K.jsx)(aI,{variant:`fill`,resource:`workflows`})]}):n?(0,K.jsxs)(Xb,{variant:`page`,breadcrumbs:(0,K.jsx)(IA,{crumbs:G9}),children:[(0,K.jsx)(`h1`,{className:`sr-only`,children:`Workflows`}),(0,K.jsx)(db,{tone:`error`,variant:`fill`,titleSlot:`Failed to load workflows`,descriptionSlot:n.message})]}):Object.keys(e||{}).length===0&&!t?(0,K.jsxs)(Xb,{variant:`page`,breadcrumbs:(0,K.jsx)(IA,{crumbs:G9}),children:[(0,K.jsx)(`h1`,{className:`sr-only`,children:`Workflows`}),(0,K.jsx)(qNi,{})]}):(0,K.jsxs)(Xb,{variant:`page`,breadcrumbs:(0,K.jsx)(IA,{crumbs:G9}),actionRow:(0,K.jsxs)(_M,{children:[(0,K.jsx)(_M.Start,{children:(0,K.jsx)(`div`,{className:`max-w-120 flex-1`,children:(0,K.jsx)($A,{...ej,onValueChange:i,label:`Search workflows`,placeholder:`Search by name or description`})})}),(0,K.jsx)(_M.End,{children:(0,K.jsx)(U,{render:(0,K.jsx)(tb,{to:`/workflows/schedules`}),variant:`primary`,icon:(0,K.jsx)(ax,{}),children:`Schedules`})})]}),children:[(0,K.jsx)(`h1`,{className:`sr-only`,children:`Workflows`}),(0,K.jsx)(iPi,{workflows:e||{},isLoading:t,search:r,sort:a,onSortChange:(e,t)=>o({key:t,direction:e})})]})}var oPi={active:`bg-success-indicator`,paused:`bg-info-indicator`,completed:`bg-muted-foreground`},sPi={active:`text-success-indicator`,paused:`text-info-indicator`,completed:`text-muted-foreground`},cPi=({status:e})=>(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-2 whitespace-nowrap`,children:[(0,K.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full ${oPi[e]}`,"aria-hidden":!0}),(0,K.jsx)(W,{as:`span`,variant:`caption`,className:sPi[e],children:e})]});function lPi({status:e}){let{icon:t,color:n}=uPi(e);return(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 whitespace-nowrap ${n}`,children:[(0,K.jsx)(`span`,{className:`inline-flex shrink-0 items-center`,"aria-hidden":!0,children:t}),(0,K.jsx)(W,{as:`span`,variant:`caption`,children:e})]})}function uPi(e){switch(e){case`success`:return{icon:(0,K.jsx)(Jt,{className:`size-icon-sm`}),color:`text-success-indicator`};case`failed`:return{icon:(0,K.jsx)(Px,{className:`size-icon-sm`}),color:`text-destructive-foreground`};case`running`:return{icon:(0,K.jsx)(pt,{}),color:`text-muted-foreground`};case`suspended`:return{icon:(0,K.jsx)(Jw,{className:`size-icon-sm`}),color:`text-info-indicator`};case`canceled`:return{icon:(0,K.jsx)(lb,{className:`size-icon-sm`}),color:`text-muted-foreground`};case`pending`:case`waiting`:return{icon:(0,K.jsx)(fx,{className:`size-icon-sm`}),color:`text-muted-foreground`};default:return{icon:null,color:`text-muted-foreground`}}}var dPi=`auto auto auto auto 1fr`,fPi=3e4,pPi=3e5;function mPi({triggers:e,isLoading:t,workflowId:n,hasNextPage:r,isFetchingNextPage:i,setEndOfListElement:a}){let{Link:o,paths:s}=xa(),c=e=>!!(n&&e.runId&&e.outcome!==`failed`),l=e.filter(c).length,{containerRef:u,getRowProps:d}=PM({count:l}),f=-1;return t?(0,K.jsx)(UM,{columns:dPi}):e.length===0?(0,K.jsx)(W,{variant:`body`,tone:`muted`,className:`p-4`,children:`No trigger history yet.`}):(0,K.jsxs)(Z,{columns:dPi,className:`min-w-0`,scrollRef:u,children:[(0,K.jsxs)(Z.Top,{children:[(0,K.jsx)(Z.TopCell,{children:`Run`}),(0,K.jsx)(Z.TopCell,{children:`Status`}),(0,K.jsx)(Z.TopCell,{children:`Started`}),(0,K.jsx)(Z.TopCell,{children:`Duration`}),(0,K.jsx)(Z.TopCell,{children:` `})]}),e.map(e=>{let t=e.actualFireAt-e.scheduledFireAt,r=hx(t,{signed:!0}),i=e.outcome===`failed`,a=i?e.error:e.run?.error,l=Math.abs(t),u=!i&&l>fPi&&l<=pPi,p=`${e.scheduleId}-${e.runId}-${e.actualFireAt}`,m=c(e);m&&(f+=1);let h=(0,K.jsx)(W,{as:`span`,variant:`caption`,font:`mono`,tone:m?`ink`:`muted`,className:`whitespace-nowrap`,children:e.runId}),g=(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Z.Cell,{children:h}),(0,K.jsx)(Z.Cell,{children:(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[i?(0,K.jsxs)(W,{as:`span`,variant:`caption`,className:`inline-flex items-center gap-1.5 whitespace-nowrap text-destructive-foreground`,children:[(0,K.jsx)(mb,{className:`size-icon-sm`}),`publish failed`]}):e.run?(0,K.jsx)(lPi,{status:e.run.status}):(0,K.jsx)(W,{as:`span`,variant:`caption`,tone:`muted`,className:`inline-flex items-center gap-1.5 whitespace-nowrap`,children:`pending`}),a?(0,K.jsxs)(jn,{children:[(0,K.jsx)(dr,{asChild:!0,children:(0,K.jsx)(`span`,{className:`inline-flex text-destructive-foreground`,children:(0,K.jsx)(mb,{className:`size-icon-sm`})})}),(0,K.jsx)(qt,{children:a})]}):null]})}),(0,K.jsx)(Z.Cell,{children:(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-2 whitespace-nowrap`,children:[e.actualFireAt?(0,K.jsx)(RE,{value:e.actualFireAt}):`—`,u?(0,K.jsxs)(jn,{children:[(0,K.jsx)(dr,{asChild:!0,children:(0,K.jsx)(`span`,{className:`inline-flex text-info-indicator`,children:(0,K.jsx)(mb,{className:`size-icon-sm`})})}),(0,K.jsxs)(qt,{children:[`Published `,r,` after the scheduled fire time`]})]}):null]})}),(0,K.jsx)(Z.Cell,{children:e.run?(0,K.jsx)(W,{as:`span`,variant:`body-sm`,font:`mono`,children:hx(e.run.durationMs)||`—`}):(0,K.jsx)(`span`,{className:`text-muted-foreground`,children:`—`})}),(0,K.jsx)(Z.Cell,{children:` `})]});return m?(0,K.jsx)(Z.RowLink,{to:s.workflowRunLink(n,e.runId),LinkComponent:o,...d(f),children:g},p):(0,K.jsx)(Z.RowStatic,{children:g},p)}),(0,K.jsx)(Z.NextPageLoading,{isLoading:i,hasMore:r,setEndOfListElement:a})]})}var hPi={id:`workflow-schedules`,label:`Schedules`,icon:ax,to:`/workflows/schedules`};function K9({label:e,children:t}){return(0,K.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,K.jsx)(W,{variant:`meta`,tone:`muted`,className:`uppercase`,children:e}),(0,K.jsx)(`div`,{children:(0,K.jsx)(W,{as:`span`,variant:`body`,className:`block`,children:t})})]})}function gPi(){let{scheduleId:e}=Yy(),t=[vI(`/workflows`),hPi,{id:`schedule`,label:K2t(e),icon:ax}],{paths:n}=xa(),{data:r,error:i}=l4t({scheduleId:e,queryOptions:{enabled:!!e}}),{data:a,isLoading:o,error:s,hasNextPage:c,isFetchingNextPage:l,setEndOfListElement:u}=d4t({scheduleId:e,queryOptions:{enabled:!!e}}),d=f4t({scheduleId:e});if(i&&Ej(i))return(0,K.jsxs)(Xb,{variant:`page`,breadcrumbs:(0,K.jsx)(IA,{crumbs:t}),children:[(0,K.jsx)(`h1`,{className:`sr-only`,children:e}),(0,K.jsx)(oI,{variant:`fill`})]});if(i&&Dj(i))return(0,K.jsxs)(Xb,{variant:`page`,breadcrumbs:(0,K.jsx)(IA,{crumbs:t}),children:[(0,K.jsx)(`h1`,{className:`sr-only`,children:e}),(0,K.jsx)(aI,{variant:`fill`,resource:`schedules`})]});if(i)return(0,K.jsxs)(Xb,{variant:`page`,breadcrumbs:(0,K.jsx)(IA,{crumbs:t}),children:[(0,K.jsx)(`h1`,{className:`sr-only`,children:e}),(0,K.jsx)(db,{tone:`error`,variant:`fill`,titleSlot:`Failed to load schedule`,descriptionSlot:i.message})]});let f=r?.workflowId,p=r?.agentId;return(0,K.jsxs)(Xb,{variant:`page`,breadcrumbs:(0,K.jsx)(IA,{crumbs:t}),actionRow:(0,K.jsx)(_M,{children:(0,K.jsxs)(_M.End,{children:[(0,K.jsx)(U,{render:(0,K.jsx)(tb,{to:n.schedulesLink()}),variant:`ghost`,icon:(0,K.jsx)(_b,{}),children:`Back to schedules`}),f?(0,K.jsx)(U,{icon:(0,K.jsx)(cx,{}),render:(0,K.jsx)(tb,{to:n.workflowLink(f)}),variant:`ghost`,children:`Open workflow`}):null,r&&r.status!==`completed`?(0,K.jsx)(U,{onClick:()=>{let e=r.status===`active`?`pause`:`resume`;d.mutate(e,{onSuccess:()=>vn.success(e===`pause`?`Schedule paused`:`Schedule resumed`),onError:e=>vn.error(e.message)})},icon:r.status===`active`?(0,K.jsx)(Jw,{}):(0,K.jsx)(Yw,{}),loading:d.isPending,"data-testid":`schedule-toggle-button`,children:r.status===`active`?`Pause`:`Resume`}):null]})}),children:[(0,K.jsx)(`h1`,{className:`sr-only`,children:e}),r?(0,K.jsxs)(`div`,{className:`grid h-full grid-cols-[minmax(0,20rem)_1fr] gap-4 overflow-hidden`,children:[(0,K.jsxs)(`div`,{className:`flex h-fit flex-col gap-4 rounded-md border border-border p-4`,children:[(0,K.jsx)(K9,{label:p?`Agent`:`Workflow`,children:f?(0,K.jsx)(tb,{to:n.workflowLink(f),className:`text-foreground hover:underline`,children:f}):p?(0,K.jsx)(tb,{to:n.agentLink(p),className:`text-foreground hover:underline`,children:p}):`—`}),(0,K.jsxs)(K9,{label:r.cron?`Cron`:`Runs at`,children:[(0,K.jsx)(W,{as:`span`,variant:`body`,font:`mono`,children:r.cron??(r.runAt?new Date(r.runAt).toLocaleString():`—`)}),r.endAt?(0,K.jsxs)(`span`,{className:`ml-2 text-caption text-muted-foreground`,children:[`until `,new Date(r.endAt).toLocaleString()]}):null,r.timezone?(0,K.jsx)(W,{as:`span`,variant:`caption`,tone:`muted`,className:`ml-2`,children:r.timezone}):null]}),(0,K.jsx)(K9,{label:`Status`,children:(0,K.jsx)(cPi,{status:r.status})}),(0,K.jsx)(K9,{label:`Next fire`,children:r.nextFireAt?(0,K.jsx)(RE,{value:r.nextFireAt}):`—`})]}),(0,K.jsxs)(`div`,{className:`overflow-y-auto`,"data-testid":`schedule-triggers-panel`,children:[(0,K.jsx)(W,{variant:`body`,className:`mb-3`,children:`Trigger history`}),s?(0,K.jsx)(db,{tone:`error`,titleSlot:`Failed to load trigger history`,descriptionSlot:s.message}):(0,K.jsx)(mPi,{triggers:a??[],isLoading:o,workflowId:f,hasNextPage:c,isFetchingNextPage:l,setEndOfListElement:u})]})]}):null]})}var _Pi={target:e=>e.workflowId??e.agentId??``,status:e=>e.status,nextFireAt:e=>e.nextFireAt,lastFireAt:e=>e.lastFireAt},vPi=`minmax(0, 1.2fr) minmax(0, 1.4fr) minmax(0, 1fr) auto auto auto`;function yPi({schedules:e,isLoading:t,search:n=``,sort:r,onSortChange:i}){let{paths:a,Link:o}=xa(),s=(0,G.useMemo)(()=>{let t=n.toLowerCase();return k4(t?e.filter(e=>e.id.toLowerCase().includes(t)||(e.workflowId??e.agentId??``).toLowerCase().includes(t)):e,r,_Pi)},[e,n,r]),{containerRef:c,getRowProps:l}=PM({count:s.length,global:!0});if(t)return(0,K.jsx)(UM,{columns:vPi});let u=(e,t)=>i?(0,K.jsx)(Z.SortableTopCell,{sortKey:e,sort:r?.key===e?r.direction:void 0,onSortChange:i,children:t}):(0,K.jsx)(Z.TopCell,{children:t});return(0,K.jsxs)(Z,{columns:vPi,className:`min-w-0`,scrollRef:c,children:[(0,K.jsxs)(Z.Top,{children:[u(`target`,`Target`),(0,K.jsx)(Z.TopCell,{children:`Schedule ID`}),(0,K.jsx)(Z.TopCell,{children:`Cron`}),u(`status`,`Status`),u(`nextFireAt`,`Next fire`),u(`lastFireAt`,`Last run`)]}),s.length===0&&n?(0,K.jsx)(Z.NoMatch,{message:`No schedules match your search`}):null,s.length===0&&!n?(0,K.jsx)(Z.NoMatch,{message:`No schedules configured`}):null,s.map((e,t)=>(0,K.jsxs)(Z.RowLink,{to:a.scheduleLink(e.id),LinkComponent:o,...l(t),children:[(0,K.jsx)(Z.NameCell,{children:e.workflowId??e.agentId}),(0,K.jsx)(Z.Cell,{className:`min-w-0`,children:(0,K.jsx)(W,{as:`span`,variant:`body-sm`,tone:`muted`,font:`mono`,className:`block truncate`,title:e.id,children:e.id})}),(0,K.jsx)(Z.Cell,{children:(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-2 whitespace-nowrap`,children:[(0,K.jsx)(W,{as:`span`,variant:`caption`,font:`mono`,children:e.cron??(e.runAt?`once @ ${new Date(e.runAt).toLocaleString()}`:`—`)}),e.timezone?(0,K.jsx)(W,{as:`span`,variant:`meta`,tone:`muted`,children:e.timezone}):null]})}),(0,K.jsx)(Z.Cell,{children:(0,K.jsx)(cPi,{status:e.status})}),(0,K.jsx)(Z.Cell,{children:e.nextFireAt?(0,K.jsx)(RE,{value:e.nextFireAt}):`—`}),(0,K.jsx)(Z.Cell,{children:e.lastRun?(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-2 whitespace-nowrap`,children:[(0,K.jsx)(lPi,{status:e.lastRun.status}),e.lastFireAt?(0,K.jsx)(W,{as:`span`,variant:`caption`,tone:`muted`,children:(0,K.jsx)(RE,{value:e.lastFireAt})}):null]}):e.lastFireAt?(0,K.jsx)(RE,{value:e.lastFireAt}):(0,K.jsx)(`span`,{className:`text-muted-foreground`,children:`Never`})})]},e.id))]})}function bPi({workflowId:e}={}){let{data:t,isLoading:n,error:r}=bI(e?{workflowId:e}:{}),[i,a]=(0,G.useState)(``),[o,s]=(0,G.useState)();return r?(0,K.jsx)(db,{tone:`error`,titleSlot:`Failed to load schedules`,descriptionSlot:r.message}):(0,K.jsxs)(`div`,{className:`grid h-full grid-rows-[auto_1fr] gap-4 overflow-hidden`,children:[(0,K.jsx)(`div`,{className:`max-w-120`,children:(0,K.jsx)($A,{...ej,onValueChange:a,label:`Search schedules`,placeholder:`Search by id or workflow`})}),(0,K.jsx)(`div`,{className:`overflow-y-auto`,children:(0,K.jsx)(yPi,{schedules:t??[],isLoading:n,search:i,sort:o,onSortChange:(e,t)=>s({key:t,direction:e})})})]})}var xPi=[vI(`/workflows`),hPi];function SPi(){let[e]=nb(),t=e.get(`workflowId`)??void 0,{error:n}=bI(t?{workflowId:t}:{});return n&&Ej(n)?(0,K.jsxs)(Xb,{variant:`page`,breadcrumbs:(0,K.jsx)(IA,{crumbs:xPi}),children:[(0,K.jsx)(`h1`,{className:`sr-only`,children:`Schedules`}),(0,K.jsx)(oI,{variant:`fill`})]}):n&&Dj(n)?(0,K.jsxs)(Xb,{variant:`page`,breadcrumbs:(0,K.jsx)(IA,{crumbs:xPi}),children:[(0,K.jsx)(`h1`,{className:`sr-only`,children:`Schedules`}),(0,K.jsx)(aI,{variant:`fill`,resource:`schedules`})]}):(0,K.jsxs)(Xb,{variant:`page`,breadcrumbs:(0,K.jsx)(IA,{crumbs:xPi}),children:[(0,K.jsx)(`h1`,{className:`sr-only`,children:`Schedules`}),(0,K.jsx)(`div`,{className:`h-full`,children:(0,K.jsx)(bPi,{workflowId:t})})]})}var CPi=_(`IconArrowDownLeft`,()=>(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`path`,{d:`M6 9V18H15`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`}),(0,K.jsx)(`path`,{d:`M17.75 6.25L7 17`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`})]}),3),wPi={"--belt-hue":`var(--warning-indicator)`};function TPi(e){let t=new Blob([JSON.stringify(e??null)]).size;return t<1024?`${t} B`:`${(t/1024).toFixed(1)} KB`}function EPi(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 DPi({suspendedSteps:e,workflow:t,isStreaming:n,onResume:r}){return n||e.length===0?null:(0,K.jsxs)(`section`,{className:T(Gvt,`pointer-events-auto relative isolate`),"data-testid":`workflow-suspended-steps`,"aria-label":`Step suspended`,children:[(0,K.jsxs)(`div`,{className:`max-h-[calc(100cqh-64px)] overflow-y-auto overscroll-contain rounded-[inherit]`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-3 border-b border-border bg-background px-5 py-4`,children:[(0,K.jsxs)(W,{as:`h2`,variant:`column`,tone:`ink`,className:`flex items-center gap-2`,children:[(0,K.jsx)(gr,{children:(0,K.jsx)(Jw,{})}),`Step suspended`]}),(0,K.jsx)(dx,{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?XT(pE(n.resumeSchema)):ep(q(),Gf());return(0,K.jsx)(OPi,{step:e,stepSchema:i,description:n.description,onResume:r},`${e.runId}-${e.stepId}`)})]}),(0,K.jsx)(iqe,{status:`ready`,label:`Needs input`,className:`before:hidden`,style:wPi})]})}function OPi({step:e,stepSchema:t,description:n,onResume:r}){let[i,a]=(0,G.useState)(!1),[o,s]=(0,G.useState)(!1);return(0,K.jsxs)(`div`,{className:`space-y-5 p-5 [&+&]:border-t [&+&]:border-border`,children:[(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(W,{as:`p`,variant:`subheading`,tone:`ink`,className:`break-words`,children:e.stepId}),n&&(0,K.jsx)(W,{as:`p`,variant:`caption`,tone:`muted`,children:n})]}),e.suspendPayload!==void 0&&(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsxs)(W,{as:`p`,variant:`caption`,tone:`muted`,className:`flex items-center gap-2`,children:[(0,K.jsx)(gr,{children:(0,K.jsx)(CPi,{})}),`The step is asking`]}),(0,K.jsxs)(Ax,{open:i,onOpenChange:a,children:[(0,K.jsxs)(jx,{className:T(`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,K.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[(0,K.jsx)(gr,{children:(0,K.jsx)(Gr,{direction:`right`,className:`text-muted-foreground`})}),(0,K.jsx)(W,{as:`span`,variant:`body`,tone:`ink`,className:`truncate`,children:EPi(e.suspendPayload,e.stepId)})]}),(0,K.jsx)(W,{as:`span`,variant:`caption`,tone:`muted`,className:`shrink-0`,children:TPi(e.suspendPayload)})]}),(0,K.jsx)(Mx,{children:(0,K.jsx)(`div`,{"data-testid":`suspended-payload`,className:`pt-2`,children:(0,K.jsx)(fr,{value:JSON.stringify(e.suspendPayload,null,2),editable:!1,className:`w-full overflow-x-auto p-2`,showCopyButton:!1})})})]})]}),(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(W,{as:`p`,variant:`caption`,tone:`muted`,className:`flex items-center gap-2`,children:[(0,K.jsx)(gr,{children:(0,K.jsx)(_P,{})}),`Your response`]}),(0,K.jsx)(`div`,{className:`-mx-5`,children:(0,K.jsx)(svt,{schema:t,isSubmitLoading:o,submitButtonLabel:`Resume`,submitButtonVariant:`primary`,submitButtonIcon:(0,K.jsx)(Yw,{}),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){vn.error(e instanceof Error?e.message:`Error resuming workflow`)}finally{s(!1)}}})})]})]})}function kPi({hidden:e,requestContext:t,canResume:n}){let{result:r,workflow:i,runId:a,isStreamingWorkflow:o}=(0,G.useContext)(nx),s=eat(r,a),c=aat(t),l=r?.status===`suspended`&&s.length>0&&!o;return!i||!l||!n?null:(0,K.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,K.jsx)(DPi,{suspendedSteps:s,workflow:i,isStreaming:o,onResume:c})},a)}var APi=_(`IconSkip`,()=>(0,K.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`})),jPi={success:{label:`Completed`,icon:Jt},failed:{label:`Failed`,icon:ub},suspended:{label:`Needs input`,icon:Jw},waiting:{label:`Waiting`,icon:sx},paused:{label:`Paused`,icon:Jw},skipped:{label:`Skipped`,icon:APi},running:{label:`Running`,icon:fA},canceled:{label:`Canceled`,icon:lb}},MPi={label:`Status unavailable`,icon:eJ};function NPi({row:e,isSelected:t,isHovered:n,onSelectStep:r,onHoverStep:i,onOpenInput:a,onOpenOutput:o}){let s=Object.hasOwn(jPi,e.status)?jPi[e.status]:MPi,c=s.icon,l=Wot(e.status),u=e.stepId.slice(0,e.stepId.lastIndexOf(`.`)),d=e.isNestedEntry?e.stepId.slice(e.stepId.lastIndexOf(`.`)+1):e.stepId;return(0,K.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:T(`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,K.jsxs)(`button`,{type:`button`,"aria-disabled":e.isNestedEntry,"aria-pressed":t,onClick:()=>{e.isNestedEntry||r(e.stepId)},title:e.stepId,className:T(`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`,g),children:[(0,K.jsx)(`span`,{"aria-label":s.label,className:T(`grid size-6 flex-none place-items-center rounded-md bg-nested`,Got[l]),children:(0,K.jsx)(c,{"aria-hidden":!0,className:T(`size-3.5`,e.status===`running`&&`motion-safe:animate-spin`)})}),(0,K.jsxs)(`span`,{className:`min-w-0`,children:[(0,K.jsx)(W,{as:`span`,variant:`meta`,className:`block truncate`,children:d}),e.isNestedEntry&&(0,K.jsxs)(W,{as:`span`,variant:`meta`,tone:`muted`,className:`flex min-w-0 items-center gap-1`,children:[(0,K.jsx)(PKe,{"aria-hidden":!0,className:`size-icon-xs shrink-0`}),(0,K.jsx)(`span`,{className:`truncate`,children:u})]})]})]}),(0,K.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,K.jsx)(`div`,{"data-testid":`workflow-timeline-bar`,"data-offset":e.timing.offsetPct,"data-width":e.timing.widthPct,className:T(`absolute top-0 h-full min-w-0.5 rounded-sm`,Kot[l]),style:{left:`${e.timing.offsetPct}%`,width:`${e.timing.widthPct}%`}})}),(0,K.jsx)(W,{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,K.jsx)(W,{as:`span`,variant:`meta`,font:`mono`,children:hx(e.timing.durationMs)}):(0,K.jsx)(`span`,{"aria-label":`Timing unavailable`,children:`—`})}),(0,K.jsxs)(`div`,{className:`flex items-center`,children:[(0,K.jsx)(U,{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,K.jsx)(jE,{})}),(0,K.jsx)(U,{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,K.jsx)(AE,{})})]})]})}var PPi=e=>e.includes(`.`),FPi=e=>e===`input`||e.endsWith(`.input`),IPi=1;function LPi(e,t){let n=Yot(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 RPi(e,t){let n=Object.entries(e).filter(([e])=>!FPi(e)).map(([e,n])=>({stepId:e,step:n,...LPi(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,IPi),100-t)}}return{stepId:e,step:t,status:FE(t)?`suspended`:t.status,timing:s,spansSuspension:a,isRunning:r,isNestedEntry:PPi(e)}})}var zPi=_(`IconChevronGrabberVertical`,()=>(0,K.jsxs)(K.Fragment,{children:[(0,K.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,K.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`})]})),BPi=_(`IconChevronGrabberVerticalToward`,()=>(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`path`,{d:`M8 18.75L12 14.75L16 18.75`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`}),(0,K.jsx)(`path`,{d:`M8 5.25L12 9.25L16 5.25`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`})]}));function VPi(){let{steps:e}=tZ(),{selectedStepId:t,hoverStepId:n,setSelectedStepId:r,setHoverStepId:i}=tx(),[a,o]=(0,G.useState)(()=>Date.now()),[s,c]=(0,G.useState)(!0),[l,u]=(0,G.useState)(!1),{showData:d}=vA(),f=(0,G.useRef)(null),p=RPi(e,a),m=p.some(e=>e.isRunning);return EWe(f,{enabled:m&&!s}),(0,G.useEffect)(()=>{if(!m||s)return;let e=setInterval(()=>o(Date.now()),100);return()=>clearInterval(e)},[m,s]),p.length===0?null:(0,K.jsx)(`div`,{"data-testid":`workflow-timeline`,className:`relative z-20 shrink-0 px-2 pb-2`,children:(0,K.jsxs)(Ax,{open:!s,onOpenChange:e=>c(!e),className:T(kr,`@container/workflow-timeline pointer-events-auto overflow-hidden rounded-xl`),children:[(0,K.jsxs)(`div`,{className:`flex items-center`,children:[(0,K.jsxs)(jx,{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,K.jsx)(`span`,{children:(0,K.jsx)($H,{"aria-hidden":!0,className:`size-icon-md text-muted-foreground`})}),(0,K.jsx)(`span`,{children:`Timeline`}),(0,K.jsxs)(W,{as:`span`,variant:`meta`,tone:`muted`,children:[p.length,` events`]}),(0,K.jsx)(`span`,{className:`ml-auto`,children:(0,K.jsx)(Gr,{direction:`right`,className:`size-4`})})]}),!s&&(0,K.jsx)(U,{variant:`ghost`,size:`icon-sm`,tooltip:l?`Restore timeline height`:`Enlarge timeline`,"aria-pressed":l,onClick:()=>u(!l),className:`mr-2 shrink-0`,children:l?(0,K.jsx)(BPi,{}):(0,K.jsx)(zPi,{})})]}),(0,K.jsx)(Mx,{children:(0,K.jsx)(`div`,{ref:f,"data-testid":`workflow-timeline-list`,className:T(`overflow-auto overscroll-contain px-1.5 pb-1.5`,l?`max-h-[min(720px,calc(100dvh-112px))]`:`max-h-[min(320px,40dvh)]`),children:p.map(e=>(0,K.jsx)(NPi,{row:e,isSelected:t===e.stepId,isHovered:n===e.stepId,onSelectStep:r,onHoverStep:i,onOpenInput:(e,t)=>d({type:`step-input`,stepId:e.stepId},t),onOpenOutput:(e,t)=>d({type:`step-output`,stepId:e.stepId},t)},e.stepId))})})]})})}var HPi=({workflowId:e,workflow:t,isLoading:n})=>{let[r]=ex(`workflow`,e),{canExecute:i,isLoading:a}=Sb(),{stepDetail:o}=vA(),s=uS(),c=o?.type===`data`,l=(0,K.jsxs)(`div`,{className:`[container-type:size] relative h-full min-h-0`,children:[(0,K.jsx)(nir,{workflowId:e,workflow:t,isLoading:n,requestContext:r}),(0,K.jsx)(kPi,{hidden:c,requestContext:r,canResume:!a&&i(`workflows`)}),c&&(0,K.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,K.jsx)(rZ,{requestContext:r})}),(0,K.jsx)(`div`,{className:`pointer-events-none absolute right-0 bottom-0 left-[var(--workflow-left-panel-width,0px)] z-20`,children:(0,K.jsx)(VPi,{})})]});return s&&o&&!c?(0,K.jsx)(`div`,{className:`h-full min-h-0 overflow-hidden`,children:(0,K.jsx)(rZ,{requestContext:r})}):(0,K.jsxs)(`div`,{className:`relative h-full min-h-0`,children:[l,(0,K.jsxs)(V2,{className:`pointer-events-none absolute inset-0 z-30 min-h-0 w-full min-w-0 p-2`,children:[(0,K.jsx)(R2,{id:`workflow-graph`,className:`pointer-events-none min-w-0`}),o&&!c&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(H2,{className:`pointer-events-auto`}),(0,K.jsx)(R2,{id:`workflow-step-detail`,minSize:300,maxSize:`60%`,defaultSize:420,className:`min-w-0`,children:(0,K.jsx)(`div`,{className:`pointer-events-auto h-full min-h-0 overflow-hidden rounded-studio-panel border border-border bg-background`,children:(0,K.jsx)(rZ,{requestContext:r})})})]})]})]})},UPi=()=>{let{workflowId:e}=Yy(),{data:t,isLoading:n,error:r}=_A({workflowId:e,requestContext:ex(`workflow`,e)[0],queryOptions:{enabled:!!e}});return r&&Ej(r)?(0,K.jsx)(oI,{variant:`fill`}):r&&Dj(r)?(0,K.jsx)(aI,{variant:`fill`,resource:`workflows`}):(0,K.jsx)(HPi,{workflowId:e,workflow:t??void 0,isLoading:n})};function WPi(){let{workflowId:e}=Yy(),{error:t}=bI(e?{workflowId:e}:{});if(!e)return null;let n;return n=t&&Ej(t)?(0,K.jsx)(oI,{variant:`fill`}):t&&Dj(t)?(0,K.jsx)(aI,{variant:`fill`,resource:`schedules`}):(0,K.jsx)(`div`,{className:`h-full`,children:(0,K.jsx)(bPi,{workflowId:e})}),(0,K.jsxs)(Xb,{variant:`page`,children:[(0,K.jsx)(`h1`,{className:`sr-only`,children:`Schedules`}),n]})}function GPi(){let{workflowId:e}=Yy();return e?(0,K.jsx)(Sui,{scopedEntityId:e,scopedEntityType:qm.WORKFLOW_RUN}):null}var KPi=(0,G.createContext)(null);function q9(){let e=(0,G.useContext)(KPi);if(!e)throw Error(`Workspace components must be rendered inside <Workspace.Root>`);return e}function qPi(e){return(0,K.jsx)(bP,{...e,overflow:`scroll`,className:`rounded-none border-0 bg-transparent [&_pre]:p-4`})}function JPi(){return(0,K.jsxs)(`div`,{"aria-busy":`true`,className:`flex flex-col gap-2 p-4`,children:[(0,K.jsx)(Zb,{className:`h-4 w-1/2`}),(0,K.jsx)(Zb,{className:`h-4 w-5/6`}),(0,K.jsx)(Zb,{className:`h-4 w-2/3`})]})}var YPi=(0,G.lazy)(()=>Br(()=>import(`./code-editor-BLzt8hly-PE5zNvJf.js`).then(e=>e.n),__vite__mapDeps([5,6,1,4,7,8,9,10,11,3]),import.meta.url).then(e=>({default:e.CodeEditor})));function XPi({path:e,code:t,lang:n}){return t.length<=5e4?(0,K.jsx)(qPi,{code:t,lang:n}):(0,K.jsx)(G.Suspense,{fallback:(0,K.jsx)(JPi,{}),children:(0,K.jsx)(`div`,{className:`px-2 py-3`,children:(0,K.jsx)(YPi,{value:t,language:n??`text`,editable:!1,lineNumbers:!1,lineWrapping:!1,variant:`embedded`,"aria-label":e})})})}function ZPi(e,t){return Ej(e)?`Your session has expired. Sign in again to continue.`:Dj(e)?`You don't have permission to access this.`:Oj(e)?`This path no longer exists.`:e instanceof um&&e.status===501?`This workspace does not support this operation.`:t}function QPi({error:e,fallback:t,className:n}){return(0,K.jsx)(NE,{variant:`destructive`,className:n,children:(0,K.jsx)(NE.Message,{children:ZPi(e,t)})})}var $Pi=new Set([` `,` `,`
880
880
  `,`\r`]),eFi=2e6;function tFi(e){try{JSON.parse(e)}catch{return}let t=``,n=0,r=()=>`
881
881
  `+` `.repeat(n);for(let i=0;i<e.length;i++){if(t.length>eFi)return;let a=e.charAt(i);if(!$Pi.has(a)){if(a===`"`){let n=i+1;for(;e[n]!==`"`;)n+=e[n]===`\\`?2:1;t+=e.slice(i,n+1),i=n}else if(a===`{`||a===`[`){let o=i+1;for(;$Pi.has(e.charAt(o));)o++;let s=a===`{`?`}`:`]`;e.charAt(o)===s?(t+=a+s,i=o):(n++,t+=a+r())}else a===`}`||a===`]`?(n--,t+=r()+a):t+=a===`,`?`,`+r():a===`:`?`: `:a}}return t}function nFi({path:e,content:t}){let n=tFi(t);return n===void 0||n===t?(0,K.jsx)(XPi,{path:e,code:t,lang:`json`}):(0,K.jsxs)(DE,{defaultTab:`formatted`,children:[(0,K.jsx)(`div`,{className:`pt-2 pl-2`,children:(0,K.jsxs)(EE,{children:[(0,K.jsx)(OE,{value:`formatted`,children:`Formatted`}),(0,K.jsx)(OE,{value:`raw`,children:`Raw`})]})}),(0,K.jsx)(kE,{value:`formatted`,flush:!0,children:(0,K.jsx)(XPi,{path:e,code:n,lang:`json`})}),(0,K.jsx)(kE,{value:`raw`,flush:!0,children:(0,K.jsx)(XPi,{path:e,code:t,lang:`json`})})]})}var rFi=(e,t)=>e===`.`?t:`${e}/${t}`,iFi=e=>e.split(`/`).slice(0,-1).map((e,t,n)=>n.slice(0,t+1).join(`/`)),aFi=e=>{let t=e.lastIndexOf(`/`);return t===-1?`.`:e.slice(0,t)},oFi=e=>{try{return decodeURIComponent(e)}catch{return}},sFi=(e,t)=>{if(!t||/^[a-z][a-z0-9+.-]*:|^\/|^#/i.test(t))return;let n=aFi(e)===`.`?[]:aFi(e).split(`/`);for(let e of(t.split(/[?#]/)[0]??``).split(`/`)){let t=oFi(e);if(t===void 0||t.includes(`/`))return;if(t!==``&&t!==`.`){if(t!==`..`)n.push(t);else if(n.pop()===void 0)return}}return n.length>0?n.join(`/`):void 0};function cFi({node:e,src:t,alt:n,...r}){let{activeFilePath:i}=q9(),a=i&&t?sFi(i,t):void 0;return!a||!KYn(a)?(0,K.jsx)(`img`,{src:t,alt:n,...r}):(0,K.jsx)(lFi,{path:a,alt:n,...r})}function lFi({path:e,alt:t,...n}){let{workspaceId:r}=q9(),{data:i}=mXn({workspaceId:r,path:e});return!i?.content||!i.mimeType?.startsWith(`image/`)?(0,K.jsx)(`span`,{children:t}):(0,K.jsx)(`img`,{src:`data:${i.mimeType};base64,${i.content}`,alt:t,...n})}var uFi=/^---\r?\n([\s\S]*?)\r?\n---[ \t]*(?:\r?\n|$)/;function dFi(e){let t=uFi.exec(e);return t?{frontmatter:t[1]??``,body:e.slice(t[0].length)}:{frontmatter:null,body:e}}function fFi({content:e,image:t}){let{frontmatter:n,body:r}=dFi(e);return(0,K.jsxs)(K.Fragment,{children:[n!==null&&(0,K.jsx)(`div`,{"data-testid":`workspace-frontmatter`,className:`border-b border-border`,children:(0,K.jsx)(bP,{code:n,lang:`yaml`,overflow:`wrap`,className:`rounded-none border-0 bg-transparent [&_pre]:p-4`})}),(0,K.jsx)(`div`,{className:`p-4`,children:(0,K.jsx)(OF,{components:t?{img:t}:void 0,children:r})})]})}function pFi(){let{activeFilePath:e}=q9();return e?(0,K.jsx)(W,{as:`span`,variant:`body-sm`,font:`mono`,tone:`muted`,className:`truncate`,"data-testid":`workspace-file-path`,children:e}):null}var mFi=e=>e.slice(0,8e3).includes(`\0`);function hFi({path:e,content:t,mimeType:n}){if(KYn(e,n))return(0,K.jsx)(`div`,{className:`flex justify-center p-4`,children:(0,K.jsx)(`img`,{src:`data:${n||`image/png`};base64,${t}`,alt:e.split(`/`).pop(),className:`max-w-full object-contain`})});if(qYn(e,n))return(0,K.jsx)(`div`,{className:`flex justify-center p-4`,children:(0,K.jsx)(`video`,{controls:!0,"aria-label":e.split(`/`).pop(),className:`max-w-full`,children:(0,K.jsx)(`source`,{src:`data:${YYn(e,n)};base64,${t}`,type:YYn(e,n)})})});if(mFi(t))return(0,K.jsx)(db,{titleSlot:`No preview available`,descriptionSlot:`This file isn’t text, so it can’t be shown here.`});if(XYn(e))return(0,K.jsx)(fFi,{content:t,image:cFi});let r=re(e);return r===`json`?(0,K.jsx)(nFi,{path:e,content:t},e):(0,K.jsx)(XPi,{path:e,code:t,lang:r})}function gFi({renderPreview:e}){let{workspaceId:t,activeFilePath:n}=q9(),{data:r,isLoading:i,error:a}=mXn({workspaceId:t,path:n,queryOptions:{enabled:!!n}});if(!n)return null;if(i)return(0,K.jsx)(JPi,{});if(!r)return(0,K.jsx)(QPi,{error:a??void 0,fallback:`Could not load file.`,className:`m-4`});let o={path:n,content:r.content,mimeType:r.mimeType};return e?.(o)??(0,K.jsx)(hFi,{...o})}function _Fi({labeled:e=!1}={}){let{workspaceId:t,onCreateDirectory:n,isReadOnly:r}=q9(),i=Av(),[a,o]=(0,G.useState)(!1),[s,c]=(0,G.useState)(``),[l,u]=(0,G.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`,aFi(d)]}),o(!1),c(``)}catch{}finally{u(!1)}}};return(0,K.jsxs)(K.Fragment,{children:[e?(0,K.jsx)(U,{variant:`ghost`,icon:(0,K.jsx)(eM,{}),onClick:()=>o(!0),children:`New folder`}):(0,K.jsx)(U,{variant:`ghost`,size:`icon-sm`,tooltip:`New folder`,onClick:()=>o(!0),children:(0,K.jsx)(eM,{})}),(0,K.jsx)(hS,{open:a,onOpenChange:o,pending:l,children:(0,K.jsx)(gS,{size:`sm`,children:(0,K.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),f()},children:[(0,K.jsx)(_S,{children:(0,K.jsx)(bS,{children:`New folder`})}),(0,K.jsx)(yS,{children:(0,K.jsx)(ak,{autoFocus:!0,"aria-label":`Folder path`,placeholder:`docs/guides`,value:s,onChange:e=>c(e.target.value)})}),(0,K.jsxs)(vS,{children:[(0,K.jsx)(SS,{children:`Cancel`}),(0,K.jsx)(U,{type:`submit`,variant:`primary`,disabled:!d,loading:l,children:`Create`})]})]})})})]})}function vFi(e){return`${e.topSource}/${e.name}`}function yFi(e){let t=eXn(e.topSource,e.name);return t?`${t.owner}/${t.repo}/${e.name}`:null}function bFi({open:e,onOpenChange:t,workspaceId:n,onInstall:r,isInstalling:i,installedSkillIds:a=[],installedSkillNames:o=[],writableMounts:s,installedSkillPaths:c}){let[l,u]=(0,G.useState)(``),[d,f]=(0,G.useState)(null),[p,m]=(0,G.useState)(),h=s?.some(e=>e.path===p)?p:s?.[0]?.path,{data:g,isLoading:_}=QYn({workspaceId:n,queryOptions:{enabled:!!n}}),v=ZYn({workspaceId:n}),y=(0,G.useMemo)(()=>d?.topSource?eXn(d.topSource,d.name):null,[d]),b=(0,G.useMemo)(()=>!y||!d?null:`https://skills.sh/${y.owner}/${y.repo}/${d.name}`,[y,d]),{data:x,isLoading:S}=$Yn({workspaceId:n,owner:y?.owner,repo:y?.repo,skillPath:d?.name,queryOptions:{enabled:!!n&&!!y&&!!d}}),C=_x(e=>{e.trim().length>=2&&v.mutate(e)},300),w=(0,G.useCallback)(e=>{u(e),C(e)},[C]),E=(0,G.useMemo)(()=>l.trim().length>=2?v.data?.skills??[]:g?.skills??[],[l,v.data,g]),D=v.isPending,O=l.trim().length>=2,k=(0,G.useMemo)(()=>{if(!d)return!1;let e=yFi(d);return!!(e&&a.includes(e)||o.includes(d.name))},[d,a,o]),A=(0,G.useCallback)(()=>{d&&y&&r({repository:`${y.owner}/${y.repo}`,skillName:d.name,mount:s&&s.length>1?h:void 0})},[d,y,r,s,h]),j=(0,G.useCallback)(e=>{e||(u(``),f(null),m(void 0)),t(e)},[t]);return(0,K.jsx)(hS,{open:e,onOpenChange:j,pending:i,children:(0,K.jsxs)(gS,{size:`xl`,className:`h-[80vh]`,children:[(0,K.jsxs)(_S,{children:[(0,K.jsx)(bS,{children:`Add Skill`}),(0,K.jsx)(xS,{children:`Search and install skills from the community registry`})]}),(0,K.jsxs)(yS,{layout:`fill`,children:[(0,K.jsx)($A,{label:`Search skills`,placeholder:`Search skills`,value:l,onValueChange:w}),(0,K.jsxs)(`div`,{className:`flex min-h-0 flex-1 gap-4`,children:[(0,K.jsxs)(`div`,{className:`flex min-h-0 w-1/2 flex-col`,children:[(0,K.jsx)(W,{as:`p`,variant:`eyebrow`,tone:`muted`,className:`mb-2`,children:O?`Search Results`:`Popular Skills`}),(0,K.jsx)(qb,{className:`flex-1 rounded-lg border border-border`,children:(0,K.jsx)(Kb,{className:!_&&!D&&E.length===0?`flex flex-col [&>div]:flex [&>div]:flex-1 [&>div]:flex-col`:void 0,children:_||D?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-5`,children:(0,K.jsx)(pt,{className:`text-muted-foreground`})}):E.length===0?(0,K.jsx)(db,{className:`flex-1`,titleSlot:O?`No skills found`:`No skills available`}):(0,K.jsx)(`div`,{className:`space-y-1 p-2`,children:E.map(e=>{let t=vFi(e),n=yFi(e),r=n&&a.includes(n)||o.includes(e.name),i=d?vFi(d):null;return(0,K.jsx)(`button`,{onClick:()=>f(e),className:T(`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,K.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(W,{as:`span`,variant:`subheading`,tone:`ink`,className:`truncate`,children:e.name}),r&&(0,K.jsxs)(W,{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,K.jsx)(Jt,{className:`size-icon-xs`}),`Installed`]})]}),(0,K.jsx)(W,{as:`p`,variant:`caption`,tone:`muted`,className:`truncate`,children:e.topSource})]}),(0,K.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1 text-muted-foreground`,children:[(0,K.jsx)(uP,{className:`size-icon-xs`}),(0,K.jsx)(W,{as:`span`,variant:`caption`,children:e.installs.toLocaleString()})]})]})},t)})})})})]}),(0,K.jsxs)(`div`,{className:`flex min-h-0 w-1/2 flex-col`,children:[(0,K.jsx)(W,{as:`p`,variant:`eyebrow`,tone:`muted`,className:`mb-2`,children:`Preview`}),(0,K.jsx)(`div`,{className:`flex flex-1 flex-col overflow-hidden rounded-lg border border-border`,children:d?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`border-b border-border bg-card p-4`,children:(0,K.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,K.jsx)(`div`,{className:`rounded-lg bg-muted p-2`,children:(0,K.jsx)(E4,{className:`size-icon-lg text-muted-foreground`})}),(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsx)(W,{as:`h3`,variant:`subheading`,tone:`ink`,className:`truncate`,children:d.name}),(0,K.jsxs)(`div`,{className:`mt-1 flex items-center gap-3 text-muted-foreground`,children:[(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(T4,{className:`size-icon-xs`}),(0,K.jsx)(W,{as:`span`,variant:`caption`,className:`block`,children:d.topSource})]}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(uP,{className:`size-icon-xs`}),(0,K.jsxs)(W,{as:`span`,variant:`caption`,className:`block`,children:[d.installs.toLocaleString(),` installs`]})]})]})]}),y&&(0,K.jsx)(`a`,{href:`https://github.com/${y.owner}/${y.repo}`,target:`_blank`,rel:`noopener noreferrer`,className:T(`text-muted-foreground hover:text-foreground`,`transition-[color] duration-fast ease-out-custom motion-reduce:transition-none`),title:`View on GitHub`,children:(0,K.jsx)(qM,{className:`size-icon-md`})})]})}),S?(0,K.jsx)(`div`,{className:`flex flex-1 items-center justify-center`,children:(0,K.jsx)(pt,{className:`text-muted-foreground`})}):x?(0,K.jsx)(qb,{className:`flex-1`,children:(0,K.jsx)(`div`,{className:`p-4`,children:(0,K.jsx)(OF,{children:x})})}):(0,K.jsx)(db,{className:`flex-1`,iconSlot:(0,K.jsx)(w4,{}),titleSlot:`Preview unavailable`,actionSlot:b&&(0,K.jsxs)(`a`,{href:b,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center gap-1 text-info-indicator hover:underline`,children:[(0,K.jsxs)(W,{as:`span`,variant:`caption`,className:`block`,children:[`View on skills.sh`,` `]}),(0,K.jsx)(qM,{className:`size-icon-xs`})]})})]}):(0,K.jsx)(db,{variant:`fill`,iconSlot:(0,K.jsx)(w4,{}),titleSlot:`Select a skill to preview`})})]})]}),d&&s&&s.length>1&&(0,K.jsxs)(gE,{orientation:`horizontal`,className:T(`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,K.jsx)($j,{className:`size-icon-md shrink-0 text-muted-foreground`}),(0,K.jsx)(vE,{className:`whitespace-nowrap`,children:`Install to`}),(0,K.jsxs)(ZE,{value:h,onValueChange:m,children:[(0,K.jsx)($E,{className:`flex-1`,children:(0,K.jsx)(QE,{})}),(0,K.jsx)(eD,{children:s.map(e=>{let t=e.displayName??e.name??e.provider??`unknown`;return(0,K.jsxs)(tD,{value:e.path,children:[t,` (`,e.path,`)`]},e.path)})})]})]})]}),d&&(0,K.jsxs)(vS,{children:[k&&s&&s.length>1&&(()=>{let e=c?.[d.name];if(!e)return null;let t=s.find(t=>e.startsWith(t.path+`/`)||e===t.path);return t?(0,K.jsxs)(W,{as:`span`,variant:`caption`,tone:`muted`,className:`mr-auto`,children:[`Installed at `,t.path]}):null})(),(0,K.jsx)(SS,{children:`Cancel`}),(0,K.jsx)(mS,{onConfirm:A,disabled:!y||k,"data-testid":`install-skill-button`,children:k?`Already installed`:`Install`})]})]})})}function xFi({labeled:e=!1}){let{workspaceId:t,addSkill:n}=q9(),[r,i]=(0,G.useState)(!1),[a,o]=(0,G.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,K.jsxs)(K.Fragment,{children:[e?(0,K.jsx)(U,{icon:(0,K.jsx)(JVr,{}),variant:`ghost`,onClick:()=>i(!0),children:`Add skill`}):(0,K.jsx)(U,{variant:`ghost`,size:`icon-sm`,"aria-label":`Add skill`,tooltip:`Add skill`,onClick:()=>i(!0),children:(0,K.jsx)(JVr,{})}),(0,K.jsx)(bFi,{...c,open:r,onOpenChange:i,workspaceId:t,onInstall:e=>void l(e),isInstalling:a})]})}function SFi({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,G.useState)(!1),[m,h]=(0,G.useState)(``),[g,_]=(0,G.useState)(()=>new Set(iFi(t??``))),[v,y]=(0,G.useState)(t);if(t!==v){y(t);let e=iFi(t??``).filter(e=>!g.has(e));e.length>0&&_(new Set([...g,...e]))}let b=a?.join(`
882
882
  `)??``,x=(0,G.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(`
@@ -101,7 +101,7 @@
101
101
  connectSSE();
102
102
  })();
103
103
  </script>
104
- <script type="module" crossorigin src="./assets/index--p7pVTCk.js"></script>
104
+ <script type="module" crossorigin src="./assets/index-CNyDrG0c.js"></script>
105
105
  <link rel="modulepreload" crossorigin href="./assets/preload-helper-CRzLMJPS.js">
106
106
  <link rel="stylesheet" crossorigin href="./assets/style-CPAFAxRe.css">
107
107
  </head>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mastra",
3
- "version": "1.40.3-alpha.8",
3
+ "version": "1.40.3-alpha.9",
4
4
  "license": "Apache-2.0",
5
5
  "description": "cli for mastra",
6
6
  "type": "module",
@@ -61,7 +61,7 @@
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.87.0-alpha.8",
64
+ "@mastra/deployer": "^1.87.0-alpha.9",
65
65
  "@mastra/loggers": "^1.3.12"
66
66
  },
67
67
  "devDependencies": {
@@ -83,9 +83,9 @@
83
83
  "zod": "^4.6.7",
84
84
  "@internal/factory-ui": "0.0.0",
85
85
  "@internal/lint": "0.0.152",
86
- "@internal/playground": "1.40.3-alpha.8",
86
+ "@internal/playground": "1.40.3-alpha.9",
87
87
  "@internal/types-builder": "0.0.127",
88
- "@mastra/core": "1.87.0-alpha.8"
88
+ "@mastra/core": "1.87.0-alpha.9"
89
89
  },
90
90
  "peerDependencies": {
91
91
  "@mastra/core": ">=1.85.1-0 <2.0.0-0"