@mastra/playground-ui 5.0.4 → 5.0.5-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.css CHANGED
@@ -6,7 +6,7 @@
6
6
  background-color: inherit;
7
7
  }
8
8
 
9
- [hidden]:where(:not([hidden=until-found])) {
9
+ [hidden]:where(:not([hidden='until-found'])) {
10
10
  display: none !important;
11
11
  }
12
12
 
@@ -18,4 +18,4 @@
18
18
  color: #e6e6e6 !important;
19
19
  background-color: #121212 !important;
20
20
  border: none !important;
21
- }
21
+ }
package/dist/index.es.js CHANGED
@@ -3113,6 +3113,7 @@ const defaultComponents = unstable_memoizeMarkdownComponents({
3113
3113
  });
3114
3114
 
3115
3115
  const sizes = {
3116
+ sm: "[&>svg]:h-icon-sm [&>svg]:w-icon-sm",
3116
3117
  default: "[&>svg]:h-icon-default [&>svg]:w-icon-default",
3117
3118
  lg: "[&>svg]:h-icon-lg [&>svg]:w-icon-lg"
3118
3119
  };
@@ -4316,6 +4317,20 @@ function MastraRuntimeProvider({
4316
4317
  ] });
4317
4318
  }
4318
4319
 
4320
+ const useAgentStore = create()(
4321
+ persist(
4322
+ (set) => ({
4323
+ modelSettings: {},
4324
+ setModelSettings: (modelSettings) => set((state) => ({ modelSettings: { ...state.modelSettings, ...modelSettings } })),
4325
+ chatWithGenerate: {},
4326
+ setChatWithGenerate: (chatWithGenerate) => set((state) => ({ chatWithGenerate: { ...state.chatWithGenerate, ...chatWithGenerate } }))
4327
+ }),
4328
+ {
4329
+ name: "mastra-agent-store"
4330
+ }
4331
+ )
4332
+ );
4333
+
4319
4334
  const defaultModelSettings$1 = {
4320
4335
  maxRetries: 2,
4321
4336
  maxSteps: 5,
@@ -4323,12 +4338,24 @@ const defaultModelSettings$1 = {
4323
4338
  topP: 1
4324
4339
  };
4325
4340
  const AgentContext = createContext({});
4326
- function AgentProvider({ children }) {
4327
- const [modelSettings, setModelSettings] = useState(defaultModelSettings$1);
4328
- const [chatWithGenerate, setChatWithGenerate] = useState(false);
4341
+ function AgentProvider({ agentId, children }) {
4342
+ const {
4343
+ modelSettings: modelSettingsStore,
4344
+ setModelSettings: setModelSettingsStore,
4345
+ chatWithGenerate: chatWithGenerateStore,
4346
+ setChatWithGenerate: setChatWithGenerateStore
4347
+ } = useAgentStore();
4348
+ const modelSettings = modelSettingsStore[agentId] || defaultModelSettings$1;
4349
+ const setModelSettings = (modelSettings2) => {
4350
+ setModelSettingsStore({ [agentId]: modelSettings2 });
4351
+ };
4329
4352
  const resetModelSettings = () => {
4330
4353
  setModelSettings(defaultModelSettings$1);
4331
4354
  };
4355
+ const chatWithGenerate = chatWithGenerateStore[agentId] || false;
4356
+ const setChatWithGenerate = (chatWithGenerate2) => {
4357
+ setChatWithGenerateStore({ [agentId]: chatWithGenerate2 });
4358
+ };
4332
4359
  return /* @__PURE__ */ jsx(
4333
4360
  AgentContext.Provider,
4334
4361
  {
@@ -4380,7 +4407,7 @@ const AgentChat = ({
4380
4407
  modelSettings,
4381
4408
  chatWithGenerate,
4382
4409
  runtimeContext,
4383
- children: /* @__PURE__ */ jsx("div", { className: "h-full pb-4", children: /* @__PURE__ */ jsx(Thread, { agentName: agentName ?? "" }) })
4410
+ children: /* @__PURE__ */ jsx("div", { className: "h-full pb-4 bg-surface1", children: /* @__PURE__ */ jsx(Thread, { agentName: agentName ?? "" }) })
4384
4411
  }
4385
4412
  );
4386
4413
  };
@@ -5166,11 +5193,17 @@ const TraceTree = ({ children }) => {
5166
5193
  const variantClasses = {
5167
5194
  agent: "bg-accent1"
5168
5195
  };
5169
- const Time = ({ durationMs, tokenCount, variant, progressPercent }) => {
5196
+ const Time = ({ durationMs, tokenCount, variant, progressPercent, offsetPercent }) => {
5170
5197
  const variantClass = variant ? variantClasses[variant] : "bg-accent3";
5171
5198
  const percent = Math.min(100, progressPercent);
5172
5199
  return /* @__PURE__ */ jsxs("div", { className: "w-[80px] xl:w-[166px] shrink-0", children: [
5173
- /* @__PURE__ */ jsx("div", { className: "bg-surface4 relative h-[6px] w-full rounded-full p-px overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: clsx("absolute h-1 rounded-full", variantClass), style: { width: `${percent}%` } }) }),
5200
+ /* @__PURE__ */ jsx("div", { className: "bg-surface4 relative h-[6px] w-full rounded-full p-px overflow-hidden", children: /* @__PURE__ */ jsx(
5201
+ "div",
5202
+ {
5203
+ className: clsx("absolute h-1 rounded-full", variantClass),
5204
+ style: { width: `${percent}%`, left: `${offsetPercent}%` }
5205
+ }
5206
+ ) }),
5174
5207
  /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-4 pt-0.5", children: [
5175
5208
  /* @__PURE__ */ jsxs(Txt, { variant: "ui-sm", className: "text-icon2 font-medium", children: [
5176
5209
  toSigFigs(durationMs, 3),
@@ -5184,14 +5217,6 @@ const Time = ({ durationMs, tokenCount, variant, progressPercent }) => {
5184
5217
  ] });
5185
5218
  };
5186
5219
 
5187
- const TraceDurationContext = createContext(0);
5188
- const useTraceDuration = () => {
5189
- return useContext(TraceDurationContext);
5190
- };
5191
- const TraceDurationProvider = ({ children, durationMs }) => {
5192
- return /* @__PURE__ */ jsx(TraceDurationContext.Provider, { value: durationMs, children });
5193
- };
5194
-
5195
5220
  const spanIconMap = {
5196
5221
  tool: ToolsIcon,
5197
5222
  agent: AgentIcon,
@@ -5212,14 +5237,25 @@ const spanVariantClasses = {
5212
5237
  eval: "text-accent4",
5213
5238
  other: "text-icon6"
5214
5239
  };
5215
- const Span = ({ children, durationMs, variant, tokenCount, spans, isRoot, onClick, isActive }) => {
5240
+ const Span = ({
5241
+ children,
5242
+ durationMs,
5243
+ variant,
5244
+ tokenCount,
5245
+ spans,
5246
+ isRoot,
5247
+ onClick,
5248
+ isActive,
5249
+ offsetMs,
5250
+ totalDurationMs
5251
+ }) => {
5216
5252
  const [isExpanded, setIsExpanded] = useState(true);
5217
- const traceDuration = useTraceDuration();
5218
5253
  const VariantIcon = spanIconMap[variant];
5219
5254
  const variantClass = spanVariantClasses[variant];
5220
- const progressPercent = durationMs / traceDuration * 100;
5255
+ const progressPercent = durationMs / totalDurationMs * 100;
5256
+ const offsetPercent = offsetMs / totalDurationMs * 100;
5221
5257
  const TextEl = onClick ? "button" : "div";
5222
- return /* @__PURE__ */ jsx(TraceDurationProvider, { durationMs, children: /* @__PURE__ */ jsxs("li", { children: [
5258
+ return /* @__PURE__ */ jsxs("li", { children: [
5223
5259
  /* @__PURE__ */ jsxs("div", { className: clsx("flex justify-between items-center gap-2 rounded-md pl-2", isActive && "bg-surface4"), children: [
5224
5260
  /* @__PURE__ */ jsxs("div", { className: "flex h-8 items-center gap-1 min-w-0", children: [
5225
5261
  spans ? /* @__PURE__ */ jsx(
@@ -5244,20 +5280,30 @@ const Span = ({ children, durationMs, variant, tokenCount, spans, isRoot, onClic
5244
5280
  durationMs,
5245
5281
  tokenCount,
5246
5282
  variant: variant === "agent" ? "agent" : void 0,
5247
- progressPercent
5283
+ progressPercent,
5284
+ offsetPercent
5248
5285
  }
5249
5286
  )
5250
5287
  ] }),
5251
5288
  isExpanded && spans && /* @__PURE__ */ jsx("div", { className: "ml-4", children: spans })
5252
- ] }) });
5289
+ ] });
5253
5290
  };
5254
5291
 
5255
5292
  const Spans = ({ children }) => {
5256
5293
  return /* @__PURE__ */ jsx("ol", { children });
5257
5294
  };
5258
5295
 
5259
- const Trace = ({ name, spans, durationMs, tokenCount, onClick, variant, isActive }) => {
5260
- return /* @__PURE__ */ jsx(TraceDurationProvider, { durationMs, children: /* @__PURE__ */ jsx(
5296
+ const Trace = ({
5297
+ name,
5298
+ spans,
5299
+ durationMs,
5300
+ tokenCount,
5301
+ onClick,
5302
+ variant,
5303
+ isActive,
5304
+ totalDurationMs
5305
+ }) => {
5306
+ return /* @__PURE__ */ jsx(
5261
5307
  Span,
5262
5308
  {
5263
5309
  isRoot: true,
@@ -5266,9 +5312,11 @@ const Trace = ({ name, spans, durationMs, tokenCount, onClick, variant, isActive
5266
5312
  spans: /* @__PURE__ */ jsx(Spans, { children: spans }),
5267
5313
  onClick,
5268
5314
  isActive,
5315
+ offsetMs: 0,
5316
+ totalDurationMs,
5269
5317
  children: name
5270
5318
  }
5271
- ) });
5319
+ );
5272
5320
  };
5273
5321
 
5274
5322
  const getSpanVariant = (span) => {
@@ -5293,40 +5341,71 @@ const getSpanVariant = (span) => {
5293
5341
  return "other";
5294
5342
  };
5295
5343
 
5296
- function buildTree(items, parentSpanId = null) {
5297
- return items.filter((item) => item.parentSpanId === parentSpanId).map((item) => ({
5298
- ...item,
5299
- children: buildTree(items, item.id)
5300
- }));
5344
+ function buildTree(spans, minStartTime, totalDurationMs, parentSpanId = null) {
5345
+ return spans.filter((span) => span.parentSpanId === parentSpanId).map((span) => {
5346
+ return {
5347
+ ...span,
5348
+ children: buildTree(spans, minStartTime, totalDurationMs, span.id),
5349
+ offset: (span.startTime - minStartTime) / 1e3,
5350
+ // ns to ms
5351
+ duration: span.duration / 1e3,
5352
+ totalDurationMs
5353
+ };
5354
+ });
5301
5355
  }
5302
- const NestedSpans = ({ spans }) => {
5356
+ const createSpanTree = (spans) => {
5357
+ if (spans.length === 0) return [];
5358
+ let minStartTime;
5359
+ let maxEndTime;
5360
+ const orderedTree = [];
5361
+ const listSize = spans.length;
5362
+ for (let i = listSize - 1; i >= 0; i--) {
5363
+ const span = spans[i];
5364
+ if (!minStartTime || span.startTime < minStartTime) {
5365
+ minStartTime = span.startTime;
5366
+ }
5367
+ if (!maxEndTime || span.endTime > maxEndTime) {
5368
+ maxEndTime = span.endTime;
5369
+ }
5370
+ if (span.name !== ".insert" && span.name !== "mastra.getStorage") {
5371
+ orderedTree.push(span);
5372
+ }
5373
+ }
5374
+ if (!minStartTime || !maxEndTime) return [];
5375
+ const totalDurationMs = (maxEndTime - minStartTime) / 1e3;
5376
+ return buildTree(orderedTree, minStartTime, totalDurationMs);
5377
+ };
5378
+
5379
+ const NestedSpans = ({ spanNodes }) => {
5303
5380
  const { span: activeSpan, setSpan } = useContext(TraceContext);
5304
- return /* @__PURE__ */ jsx(Spans, { children: spans.map((span) => {
5305
- const isActive = span.id === activeSpan?.id;
5381
+ return /* @__PURE__ */ jsx(Spans, { children: spanNodes.map((spanNode) => {
5382
+ const isActive = spanNode.id === activeSpan?.id;
5306
5383
  return /* @__PURE__ */ jsx(
5307
5384
  Span,
5308
5385
  {
5309
- spans: span.children.length > 0 && /* @__PURE__ */ jsx(NestedSpans, { spans: span.children }),
5310
- durationMs: span.duration / 1e3,
5311
- variant: getSpanVariant(span),
5386
+ spans: spanNode.children.length > 0 && /* @__PURE__ */ jsx(NestedSpans, { spanNodes: spanNode.children }),
5387
+ durationMs: spanNode.duration,
5388
+ offsetMs: spanNode.offset,
5389
+ variant: getSpanVariant(spanNode),
5312
5390
  isActive,
5313
- onClick: () => setSpan(span),
5314
- children: span.name
5391
+ onClick: () => setSpan(spanNode),
5392
+ totalDurationMs: spanNode.totalDurationMs,
5393
+ children: spanNode.name
5315
5394
  },
5316
- span.id
5395
+ spanNode.id
5317
5396
  );
5318
5397
  }) });
5319
5398
  };
5320
5399
  function SpanView({ trace }) {
5321
- const shallowCopy = [...trace];
5322
- const tree = buildTree(shallowCopy.reverse());
5323
5400
  const { span: activeSpan, setSpan } = useContext(TraceContext);
5401
+ const tree = createSpanTree(trace);
5324
5402
  return /* @__PURE__ */ jsx(TraceTree, { children: tree.map((node) => /* @__PURE__ */ jsx(
5325
5403
  Trace,
5326
5404
  {
5327
5405
  name: node.name,
5328
- durationMs: node.duration / 1e3,
5329
- spans: /* @__PURE__ */ jsx(NestedSpans, { spans: node.children }),
5406
+ durationMs: node.duration,
5407
+ totalDurationMs: node.totalDurationMs,
5408
+ spans: /* @__PURE__ */ jsx(NestedSpans, { spanNodes: node.children }),
5330
5409
  variant: getSpanVariant(node),
5331
5410
  isActive: node.id === activeSpan?.id,
5332
5411
  onClick: () => setSpan(node)
@@ -5462,8 +5541,7 @@ const refineTraces = (traces, isWorkflow = false) => {
5462
5541
  const parentSpan = value.find((span) => !span.parentSpanId || !listOfSpanIds.has(span.parentSpanId));
5463
5542
  const enrichedSpans = value.map((span) => ({
5464
5543
  ...span,
5465
- parentSpanId: parentSpan?.id === span.id ? null : span?.parentSpanId,
5466
- relativePercentage: parentSpan ? span.duration / parentSpan.duration : 0
5544
+ parentSpanId: parentSpan?.id === span.id ? null : span?.parentSpanId
5467
5545
  }));
5468
5546
  const failedStatus = value.find((span) => span.status.code !== 0)?.status;
5469
5547
  return {
@@ -8911,6 +8989,41 @@ const DarkLogo = (props) => /* @__PURE__ */ jsxs("svg", { width: "100", height:
8911
8989
  )
8912
8990
  ] });
8913
8991
 
8992
+ const Entity = ({ children, className, onClick }) => {
8993
+ return /* @__PURE__ */ jsx(
8994
+ "div",
8995
+ {
8996
+ tabIndex: onClick ? 0 : void 0,
8997
+ onKeyDown: (e) => {
8998
+ if (!onClick) return;
8999
+ if (e.key === "Enter" || e.key === " ") {
9000
+ e.preventDefault();
9001
+ onClick?.();
9002
+ }
9003
+ },
9004
+ className: clsx(
9005
+ "flex gap-3 group/entity bg-surface3 rounded-lg border-sm border-border1 py-3 px-4",
9006
+ onClick && "cursor-pointer hover:bg-surface4 transition-all",
9007
+ className
9008
+ ),
9009
+ onClick,
9010
+ children
9011
+ }
9012
+ );
9013
+ };
9014
+ const EntityIcon = ({ children, className }) => {
9015
+ return /* @__PURE__ */ jsx(Icon, { size: "lg", className: clsx("text-icon3 mt-1", className), children });
9016
+ };
9017
+ const EntityName = ({ children, className }) => {
9018
+ return /* @__PURE__ */ jsx(Txt, { as: "p", variant: "ui-lg", className: clsx("text-icon6 font-medium", className), children });
9019
+ };
9020
+ const EntityDescription = ({ children, className }) => {
9021
+ return /* @__PURE__ */ jsx(Txt, { as: "p", variant: "ui-sm", className: clsx("text-icon3", className), children });
9022
+ };
9023
+ const EntityContent = ({ children, className }) => {
9024
+ return /* @__PURE__ */ jsx("div", { className, children });
9025
+ };
9026
+
8914
9027
  function usePolling({
8915
9028
  fetchFn,
8916
9029
  interval = 3e3,
@@ -9065,5 +9178,5 @@ const useTraces = (componentName, baseUrl, isWorkflow = false) => {
9065
9178
  return { traces, firstCallLoading, error };
9066
9179
  };
9067
9180
 
9068
- export { AgentChat, AgentCoinIcon, AgentContext, AgentEvals, AgentIcon, AgentProvider, AgentTraces, AiIcon, ApiIcon, Badge$1 as Badge, BranchIcon, Breadcrumb, Button, Cell, CheckIcon, ChevronIcon, CommitIcon, CrossIcon, Crumb, DarkLogo, DataTable, DateTimeCell, DbIcon, DebugIcon, DeploymentIcon, DividerIcon, DocsIcon, DynamicForm, EntryCell, EnvIcon, EvaluatorCoinIcon, FiltersIcon, GithubCoinIcon, GithubIcon, GoogleIcon, Header, HeaderAction, HeaderGroup, HeaderTitle, HomeIcon, Icon, InfoIcon, JudgeIcon, LatencyIcon, LogsIcon, MastraResizablePanel, MemoryIcon, NetworkChat, NetworkContext, NetworkProvider, OpenAIIcon, PromptIcon, RepoIcon, Row, ScoreIcon, SettingsIcon, SlashIcon, Table, Tbody, Th, Thead, ThreadDeleteButton, ThreadItem, ThreadLink, ThreadList, Threads, ToolsIcon, TraceContext, TraceIcon, TraceProvider, TsIcon, Txt, TxtCell, UnitCell, VNextWorkflowGraph, VNextWorkflowTrigger, VariablesIcon, WorkflowCoinIcon, WorkflowGraph, WorkflowIcon, WorkflowRunContext, WorkflowRunProvider, WorkflowTraces, WorkflowTrigger, refineTraces, usePlaygroundStore, usePolling, useTraces };
9181
+ export { AgentChat, AgentCoinIcon, AgentContext, AgentEvals, AgentIcon, AgentProvider, AgentTraces, AiIcon, ApiIcon, Badge$1 as Badge, BranchIcon, Breadcrumb, Button, Cell, CheckIcon, ChevronIcon, CommitIcon, CrossIcon, Crumb, DarkLogo, DataTable, DateTimeCell, DbIcon, DebugIcon, DeploymentIcon, DividerIcon, DocsIcon, DynamicForm, Entity, EntityContent, EntityDescription, EntityIcon, EntityName, EntryCell, EnvIcon, EvaluatorCoinIcon, FiltersIcon, GithubCoinIcon, GithubIcon, GoogleIcon, Header, HeaderAction, HeaderGroup, HeaderTitle, HomeIcon, Icon, InfoIcon, JudgeIcon, LatencyIcon, LogsIcon, MastraResizablePanel, MemoryIcon, NetworkChat, NetworkContext, NetworkProvider, OpenAIIcon, PromptIcon, RepoIcon, Row, ScoreIcon, SettingsIcon, SlashIcon, Table, Tbody, Th, Thead, ThreadDeleteButton, ThreadItem, ThreadLink, ThreadList, Threads, ToolsIcon, TraceContext, TraceIcon, TraceProvider, TsIcon, Txt, TxtCell, UnitCell, VNextWorkflowGraph, VNextWorkflowTrigger, VariablesIcon, WorkflowCoinIcon, WorkflowGraph, WorkflowIcon, WorkflowRunContext, WorkflowRunProvider, WorkflowTraces, WorkflowTrigger, refineTraces, usePlaygroundStore, usePolling, useTraces };
9069
9182
  //# sourceMappingURL=index.es.js.map