@mastra/playground-ui 6.1.3 → 6.1.4-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.es.js CHANGED
@@ -20,6 +20,8 @@ import CodeMirror, { EditorView } from '@uiw/react-codemirror';
20
20
  import { toast } from 'sonner';
21
21
  import * as DialogPrimitive from '@radix-ui/react-dialog';
22
22
  import { useDebouncedCallback } from 'use-debounce';
23
+ import { create } from 'zustand';
24
+ import { persist } from 'zustand/middleware';
23
25
  import { useQuery, QueryClient, QueryClientProvider } from '@tanstack/react-query';
24
26
  import './index.css';export * from '@tanstack/react-query';
25
27
  import { MarkerType, Handle, Position, useNodesState, useEdgesState, ReactFlow, Controls, Background, BackgroundVariant, ReactFlowProvider, useViewport, useReactFlow, Panel } from '@xyflow/react';
@@ -34,7 +36,7 @@ import prettierPluginEstree from 'prettier/plugins/estree';
34
36
  import { C as Colors, I as IconColors } from './colors-DrbbnW3f.js';
35
37
  import jsonSchemaToZod from 'json-schema-to-zod';
36
38
  import { parse } from 'superjson';
37
- import z$2, { z, ZodObject } from 'zod';
39
+ import z$2, { z, ZodObject, ZodIntersection } from 'zod';
38
40
  import { AutoForm as AutoForm$1, buildZodFieldConfig } from '@autoform/react';
39
41
  import * as CheckboxPrimitive from '@radix-ui/react-checkbox';
40
42
  import { format, isValid, formatDate, formatDistanceToNow } from 'date-fns';
@@ -47,8 +49,6 @@ import { ZodProvider, getFieldConfigInZodStack, getDefaultValueInZodStack } from
47
49
  import { z as z$1 } from 'zod/v3';
48
50
  import { CodeBlock as CodeBlock$1 } from 'react-code-block';
49
51
  import * as SliderPrimitive from '@radix-ui/react-slider';
50
- import { create } from 'zustand';
51
- import { persist } from 'zustand/middleware';
52
52
  import * as RadioGroupPrimitive from '@radix-ui/react-radio-group';
53
53
  import { useReactTable, getCoreRowModel, flexRender } from '@tanstack/react-table';
54
54
  import { useShallow } from 'zustand/shallow';
@@ -4513,11 +4513,24 @@ function Skeleton({ className, ...props }) {
4513
4513
  return /* @__PURE__ */ jsx("div", { className: cn("animate-pulse rounded-md bg-muted/50", className), ...props });
4514
4514
  }
4515
4515
 
4516
+ const usePlaygroundStore = create()(
4517
+ persist(
4518
+ (set) => ({
4519
+ runtimeContext: {},
4520
+ setRuntimeContext: (runtimeContext) => set({ runtimeContext })
4521
+ }),
4522
+ {
4523
+ name: "mastra-playground-store"
4524
+ }
4525
+ )
4526
+ );
4527
+
4516
4528
  const useWorkflow = (workflowId) => {
4517
4529
  const client = useMastraClient();
4530
+ const { runtimeContext } = usePlaygroundStore();
4518
4531
  return useQuery({
4519
4532
  queryKey: ["workflow", workflowId],
4520
- queryFn: () => client.getWorkflow(workflowId).details(),
4533
+ queryFn: () => client.getWorkflow(workflowId).details(runtimeContext),
4521
4534
  retry: false,
4522
4535
  refetchOnWindowFocus: false
4523
4536
  });
@@ -4535,7 +4548,8 @@ const useLegacyWorkflow = (workflowId) => {
4535
4548
  setIsLoading(false);
4536
4549
  return;
4537
4550
  }
4538
- const res = await client.getLegacyWorkflow(workflowId).details();
4551
+ const { runtimeContext } = usePlaygroundStore.getState();
4552
+ const res = await client.getLegacyWorkflow(workflowId).details(runtimeContext);
4539
4553
  if (!res) {
4540
4554
  setLegacyWorkflow(null);
4541
4555
  console.error("Error fetching legacy workflow");
@@ -4546,7 +4560,7 @@ const useLegacyWorkflow = (workflowId) => {
4546
4560
  const stepsWithWorkflow = await Promise.all(
4547
4561
  Object.values(steps)?.map(async (step) => {
4548
4562
  if (!step.workflowId) return step;
4549
- const wFlow = await client.getLegacyWorkflow(step.workflowId).details();
4563
+ const wFlow = await client.getLegacyWorkflow(step.workflowId).details(runtimeContext);
4550
4564
  if (!wFlow) return step;
4551
4565
  return { ...step, stepGraph: wFlow.stepGraph, stepSubscriberGraph: wFlow.stepSubscriberGraph };
4552
4566
  })
@@ -7140,6 +7154,7 @@ function inferFieldType(schema, fieldConfig) {
7140
7154
  return fieldConfig.fieldType;
7141
7155
  }
7142
7156
  if (schema instanceof z.ZodObject) return "object";
7157
+ if (schema instanceof z.ZodIntersection) return "object";
7143
7158
  if (schema instanceof z.ZodNumber) return "number";
7144
7159
  if (schema instanceof z.ZodBoolean) return "boolean";
7145
7160
  if (schema instanceof z.ZodString) {
@@ -7176,6 +7191,15 @@ function parseField(key, schema) {
7176
7191
  if (baseSchema instanceof z$1.ZodObject || baseSchema instanceof z.ZodObject) {
7177
7192
  subSchema = Object.entries(baseSchema.shape).map(([key2, field]) => parseField(key2, field));
7178
7193
  }
7194
+ if (baseSchema instanceof z$1.ZodIntersection || baseSchema instanceof z.ZodIntersection) {
7195
+ const subSchemaLeft = Object.entries(baseSchema._def.left.shape).map(
7196
+ ([key2, field]) => parseField(key2, field)
7197
+ );
7198
+ const subSchemaRight = Object.entries(baseSchema._def.right.shape).map(
7199
+ ([key2, field]) => parseField(key2, field)
7200
+ );
7201
+ subSchema = [...subSchemaLeft, ...subSchemaRight];
7202
+ }
7179
7203
  if (baseSchema instanceof z$1.ZodArray || baseSchema instanceof z.ZodArray) {
7180
7204
  subSchema = [parseField("0", baseSchema._zod.def.element)];
7181
7205
  }
@@ -7223,6 +7247,9 @@ function isEmptyZodObject(schema) {
7223
7247
  if (schema instanceof ZodObject) {
7224
7248
  return Object.keys(schema.shape).length === 0;
7225
7249
  }
7250
+ if (schema instanceof ZodIntersection) {
7251
+ return isEmptyZodObject(schema._def.left) || isEmptyZodObject(schema._def.right);
7252
+ }
7226
7253
  return false;
7227
7254
  }
7228
7255
  function DynamicForm({
@@ -7829,18 +7856,6 @@ function WorkflowGraph({ workflowId, onShowTrace, workflow, isLoading, onSendEve
7829
7856
  );
7830
7857
  }
7831
7858
 
7832
- const usePlaygroundStore = create()(
7833
- persist(
7834
- (set) => ({
7835
- runtimeContext: {},
7836
- setRuntimeContext: (runtimeContext) => set({ runtimeContext })
7837
- }),
7838
- {
7839
- name: "mastra-playground-store"
7840
- }
7841
- )
7842
- );
7843
-
7844
7859
  const WorkflowStatus = ({ stepId, status, result }) => {
7845
7860
  return /* @__PURE__ */ jsx(
7846
7861
  WorkflowCard,
@@ -15290,9 +15305,11 @@ function RelationWrapper({ description, children }) {
15290
15305
  }
15291
15306
 
15292
15307
  function EntryListTextCell({ children, isLoading }) {
15293
- const randomWidth = useMemo(() => {
15294
- return Math.floor(Math.random() * (90 - 50 + 1)) + 50;
15308
+ const [randomWidth, setRandomWidth] = useState(void 0);
15309
+ useEffect(() => {
15310
+ setRandomWidth(Math.floor(Math.random() * (90 - 50 + 1)) + 50);
15295
15311
  }, []);
15312
+ if (!randomWidth) return null;
15296
15313
  return /* @__PURE__ */ jsx("div", { className: "text-icon4 text-[0.875rem] truncate ", children: isLoading ? /* @__PURE__ */ jsx(
15297
15314
  "div",
15298
15315
  {
@@ -15428,9 +15445,10 @@ function EntryList({
15428
15445
  onClick: isLoading ? void 0 : onItemClick,
15429
15446
  columns,
15430
15447
  isLoading,
15431
- children: (columns || []).map((col) => {
15448
+ children: (columns || []).map((col, index) => {
15432
15449
  const isValidReactElement = isValidElement(item?.[col.name]);
15433
- return isValidReactElement ? item?.[col.name] : /* @__PURE__ */ jsx(EntryListTextCell, { isLoading, children: item?.[col.name] }, col.name);
15450
+ const key = `${index}-${item.id}`;
15451
+ return isValidReactElement ? /* @__PURE__ */ jsx(React__default.Fragment, { children: item?.[col.name] }, key) : /* @__PURE__ */ jsx(EntryListTextCell, { isLoading, children: item?.[col.name] }, key);
15434
15452
  })
15435
15453
  },
15436
15454
  item.id
@@ -17997,10 +18015,14 @@ function TraceSpanUsage({ traceUsage, traceSpans = [], spanUsage, className }) {
17997
18015
  );
17998
18016
  }
17999
18017
 
18000
- function getTraceInfo(trace) {
18018
+ function getTraceInfo(trace, computeAgentsLink, computeWorkflowsLink) {
18001
18019
  if (!trace) {
18002
18020
  return [];
18003
18021
  }
18022
+ const agentsLink = computeAgentsLink ? computeAgentsLink() : "/agents";
18023
+ const workflowsLink = computeWorkflowsLink ? computeWorkflowsLink() : "/workflows";
18024
+ const agentLink = computeAgentsLink ? `${agentsLink}/${trace?.metadata?.resourceId}` : `/agents/${trace?.metadata?.resourceId}`;
18025
+ const workflowLink = computeWorkflowsLink ? `${workflowsLink}/${trace?.metadata?.resourceId}` : `/workflows/${trace?.metadata?.resourceId}`;
18004
18026
  return [
18005
18027
  {
18006
18028
  key: "entityId",
@@ -18009,7 +18031,7 @@ function getTraceInfo(trace) {
18009
18031
  {
18010
18032
  id: trace?.metadata?.resourceId,
18011
18033
  name: trace?.attributes?.agentId || trace?.attributes?.workflowId || "-",
18012
- path: trace?.attributes?.agentId ? `/agents/${trace?.metadata?.resourceId}` : trace?.attributes?.workflowId ? `/workflows/${trace?.metadata?.resourceId}` : void 0
18034
+ path: trace?.attributes?.agentId ? agentLink : trace?.attributes?.workflowId ? workflowLink : void 0
18013
18035
  }
18014
18036
  ]
18015
18037
  },
@@ -18020,7 +18042,7 @@ function getTraceInfo(trace) {
18020
18042
  {
18021
18043
  id: trace?.attributes?.agentId || trace?.attributes?.workflowId,
18022
18044
  name: trace?.attributes?.agentId ? "Agent" : trace?.attributes?.workflowId ? "Workflow" : "-",
18023
- path: trace?.attributes?.agentId ? `/agents` : trace?.attributes?.workflowId ? `/workflows` : void 0
18045
+ path: trace?.attributes?.agentId ? agentsLink : trace?.attributes?.workflowId ? workflowsLink : void 0
18024
18046
  }
18025
18047
  ]
18026
18048
  },
@@ -18156,7 +18178,9 @@ function TraceDialog({
18156
18178
  onClose,
18157
18179
  onNext,
18158
18180
  onPrevious,
18159
- isLoadingSpans
18181
+ isLoadingSpans,
18182
+ computeAgentsLink,
18183
+ computeWorkflowsLink
18160
18184
  }) {
18161
18185
  const { Link } = useLinkComponent();
18162
18186
  const [dialogIsOpen, setDialogIsOpen] = useState(false);
@@ -18206,7 +18230,7 @@ function TraceDialog({
18206
18230
  const currentIndex = flatSpans.findIndex((span) => span.id === selectedSpanId);
18207
18231
  return currentIndex > 0;
18208
18232
  };
18209
- const traceInfo = getTraceInfo(traceDetails);
18233
+ const traceInfo = getTraceInfo(traceDetails, computeAgentsLink, computeWorkflowsLink);
18210
18234
  const selectedSpanInfo = getSpanInfo({ span: selectedSpan, withTraceId: !combinedView, withSpanId: combinedView });
18211
18235
  return /* @__PURE__ */ jsxs(Fragment, { children: [
18212
18236
  /* @__PURE__ */ jsxs(