@mastra/playground-ui 5.1.2-alpha.1 → 5.1.2-alpha.3

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.cjs.js CHANGED
@@ -3,9 +3,10 @@
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
5
  require('./index.css');const jsxRuntime = require('react/jsx-runtime');
6
+ const React = require('react');
7
+ const clientJs = require('@mastra/client-js');
6
8
  const react = require('@assistant-ui/react');
7
9
  const lucideReact = require('lucide-react');
8
- const React = require('react');
9
10
  const reactSlot = require('@radix-ui/react-slot');
10
11
  const TooltipPrimitive = require('@radix-ui/react-tooltip');
11
12
  const AvatarPrimitive = require('@radix-ui/react-avatar');
@@ -21,7 +22,6 @@ const CodeMirror = require('@uiw/react-codemirror');
21
22
  const DialogPrimitive = require('@radix-ui/react-dialog');
22
23
  const shallow = require('zustand/shallow');
23
24
  const di = require('@mastra/core/di');
24
- const clientJs = require('@mastra/client-js');
25
25
  const zustand = require('zustand');
26
26
  const middleware = require('zustand/middleware');
27
27
  const dateFns = require('date-fns');
@@ -84,6 +84,31 @@ const SelectPrimitive__namespace = /*#__PURE__*/_interopNamespaceDefault(SelectP
84
84
  const LabelPrimitive__namespace = /*#__PURE__*/_interopNamespaceDefault(LabelPrimitive);
85
85
  const SliderPrimitive__namespace = /*#__PURE__*/_interopNamespaceDefault(SliderPrimitive);
86
86
 
87
+ const createMastraClient = (baseUrl, mastraClientHeaders = {}) => {
88
+ return new clientJs.MastraClient({
89
+ baseUrl: baseUrl || "",
90
+ // only add the header if the baseUrl is not provided i.e it's a local dev environment
91
+ headers: !baseUrl ? { ...mastraClientHeaders, "x-mastra-dev-playground": "true" } : mastraClientHeaders
92
+ });
93
+ };
94
+
95
+ const MastraClientContext = React.createContext(void 0);
96
+ const MastraClientProvider = ({
97
+ children,
98
+ baseUrl,
99
+ headers
100
+ }) => {
101
+ const client = createMastraClient(baseUrl, headers);
102
+ return /* @__PURE__ */ jsxRuntime.jsx(MastraClientContext.Provider, { value: { client }, children });
103
+ };
104
+ const useMastraClient = () => {
105
+ const context = React.useContext(MastraClientContext);
106
+ if (context === void 0) {
107
+ throw new Error("useMastraClient must be used within a MastraClientProvider");
108
+ }
109
+ return context.client;
110
+ };
111
+
87
112
  function r(e){var t,f,n="";if("string"==typeof e||"number"==typeof e)n+=e;else if("object"==typeof e)if(Array.isArray(e)){var o=e.length;for(t=0;t<o;t++)e[t]&&(f=r(e[t]))&&(n&&(n+=" "),n+=f);}else for(f in e)e[f]&&(n&&(n+=" "),n+=f);return n}function clsx(){for(var e,t,f=0,n="",o=arguments.length;f<o;f++)(e=arguments[f])&&(t=r(e))&&(n&&(n+=" "),n+=t);return n}
88
113
 
89
114
  const falsyToString = (value)=>typeof value === "boolean" ? `${value}` : value === 0 ? "0" : value;
@@ -4485,14 +4510,6 @@ const CircleStopIcon = () => {
4485
4510
  return /* @__PURE__ */ jsxRuntime.jsx("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 16 16", fill: "currentColor", width: "16", height: "16", children: /* @__PURE__ */ jsxRuntime.jsx("rect", { width: "10", height: "10", x: "3", y: "3", rx: "2" }) });
4486
4511
  };
4487
4512
 
4488
- const createMastraClient = (baseUrl) => {
4489
- return new clientJs.MastraClient({
4490
- baseUrl: baseUrl || "",
4491
- // only add the header if the baseUrl is not provided i.e it's a local dev environment
4492
- headers: !baseUrl ? { "x-mastra-dev-playground": "true" } : {}
4493
- });
4494
- };
4495
-
4496
4513
  const fileToBase64 = async (file) => {
4497
4514
  return new Promise((resolve, reject) => {
4498
4515
  const reader = new FileReader();
@@ -4534,7 +4551,6 @@ function MastraRuntimeProvider({
4534
4551
  agentName,
4535
4552
  memory,
4536
4553
  threadId,
4537
- baseUrl,
4538
4554
  refreshThreadList,
4539
4555
  modelSettings = {},
4540
4556
  chatWithGenerate,
@@ -4575,7 +4591,7 @@ function MastraRuntimeProvider({
4575
4591
  }
4576
4592
  }
4577
4593
  }, [initialMessages, threadId, memory]);
4578
- const mastra = createMastraClient(baseUrl);
4594
+ const mastra = useMastraClient();
4579
4595
  const agent = mastra.getAgent(agentId);
4580
4596
  const onNew = async (message) => {
4581
4597
  if (message.content[0]?.type !== "text") throw new Error("Only text messages are supported");
@@ -4933,7 +4949,6 @@ const AgentChat = ({
4933
4949
  threadId,
4934
4950
  initialMessages,
4935
4951
  memory,
4936
- baseUrl,
4937
4952
  refreshThreadList,
4938
4953
  showFileSupport
4939
4954
  }) => {
@@ -4947,7 +4962,6 @@ const AgentChat = ({
4947
4962
  threadId,
4948
4963
  initialMessages,
4949
4964
  memory,
4950
- baseUrl,
4951
4965
  refreshThreadList,
4952
4966
  modelSettings,
4953
4967
  chatWithGenerate,
@@ -5127,10 +5141,10 @@ const TabsContent = React__namespace.forwardRef(({ className, ...props }, ref) =
5127
5141
  ));
5128
5142
  TabsContent.displayName = TabsPrimitive__namespace.Content.displayName;
5129
5143
 
5130
- const useEvalsByAgentId = (agentId, type, baseUrl) => {
5144
+ const useEvalsByAgentId = (agentId, type) => {
5131
5145
  const [evals, setEvals] = React.useState([]);
5132
5146
  const [isLoading, setIsLoading] = React.useState(true);
5133
- const client = createMastraClient(baseUrl);
5147
+ const client = useMastraClient();
5134
5148
  const fetchEvals = async (_agentId) => {
5135
5149
  setIsLoading(true);
5136
5150
  const activeAgentId = _agentId ?? agentId;
@@ -5168,18 +5182,14 @@ const tabIndicatorClass = cn(
5168
5182
  "focus-visible:outline-none"
5169
5183
  );
5170
5184
  const tabContentClass = cn("data-[state=inactive]:mt-0 min-h-0 h-full grid grid-rows-[1fr]");
5171
- function AgentEvals({ agentId, baseUrl }) {
5185
+ function AgentEvals({ agentId }) {
5172
5186
  const [activeTab, setActiveTab] = React.useState("live");
5173
5187
  const {
5174
5188
  evals: liveEvals,
5175
5189
  isLoading: isLiveLoading,
5176
5190
  refetchEvals: refetchLiveEvals
5177
- } = useEvalsByAgentId(agentId, "live", baseUrl);
5178
- const {
5179
- evals: ciEvals,
5180
- isLoading: isCiLoading,
5181
- refetchEvals: refetchCiEvals
5182
- } = useEvalsByAgentId(agentId, "ci", baseUrl);
5191
+ } = useEvalsByAgentId(agentId, "live");
5192
+ const { evals: ciEvals, isLoading: isCiLoading, refetchEvals: refetchCiEvals } = useEvalsByAgentId(agentId, "ci");
5183
5193
  const contextValue = {
5184
5194
  handleRefresh,
5185
5195
  isLoading: activeTab === "live" ? isLiveLoading : isCiLoading
@@ -6230,7 +6240,6 @@ function MastraNetworkRuntimeProvider({
6230
6240
  initialMessages,
6231
6241
  memory,
6232
6242
  threadId,
6233
- baseUrl,
6234
6243
  refreshThreadList,
6235
6244
  modelSettings = {}
6236
6245
  }) {
@@ -6246,7 +6255,7 @@ function MastraNetworkRuntimeProvider({
6246
6255
  }
6247
6256
  }
6248
6257
  }, [initialMessages, threadId, memory, messages]);
6249
- const mastra = createMastraClient(baseUrl);
6258
+ const mastra = useMastraClient();
6250
6259
  const network = mastra.getNetwork(agentId);
6251
6260
  const onNew = async (message) => {
6252
6261
  if (message.content[0]?.type !== "text") throw new Error("Only text messages are supported");
@@ -6728,10 +6737,10 @@ const sanitizeWorkflowWatchResult = (record) => {
6728
6737
  };
6729
6738
  return sanitizedRecord;
6730
6739
  };
6731
- const useLegacyWorkflow = (workflowId, baseUrl) => {
6740
+ const useLegacyWorkflow = (workflowId) => {
6732
6741
  const [legacyWorkflow, setLegacyWorkflow] = React.useState(null);
6733
6742
  const [isLoading, setIsLoading] = React.useState(true);
6734
- const client = createMastraClient(baseUrl);
6743
+ const client = useMastraClient();
6735
6744
  React.useEffect(() => {
6736
6745
  const fetchWorkflow = async () => {
6737
6746
  setIsLoading(true);
@@ -6773,10 +6782,10 @@ const useLegacyWorkflow = (workflowId, baseUrl) => {
6773
6782
  }, [workflowId]);
6774
6783
  return { legacyWorkflow, isLoading };
6775
6784
  };
6776
- const useWorkflow = (workflowId, baseUrl) => {
6785
+ const useWorkflow = (workflowId) => {
6777
6786
  const [workflow, setWorkflow] = React.useState(null);
6778
6787
  const [isLoading, setIsLoading] = React.useState(true);
6779
- const client = createMastraClient(baseUrl);
6788
+ const client = useMastraClient();
6780
6789
  React.useEffect(() => {
6781
6790
  const fetchWorkflow = async () => {
6782
6791
  setIsLoading(true);
@@ -6800,8 +6809,8 @@ const useWorkflow = (workflowId, baseUrl) => {
6800
6809
  }, [workflowId]);
6801
6810
  return { workflow, isLoading };
6802
6811
  };
6803
- const useExecuteWorkflow = (baseUrl) => {
6804
- const client = createMastraClient(baseUrl);
6812
+ const useExecuteWorkflow = () => {
6813
+ const client = useMastraClient();
6805
6814
  const createLegacyWorkflowRun = async ({ workflowId, prevRunId }) => {
6806
6815
  try {
6807
6816
  const workflow = client.getLegacyWorkflow(workflowId);
@@ -6880,11 +6889,12 @@ const useExecuteWorkflow = (baseUrl) => {
6880
6889
  startAsyncWorkflowRun
6881
6890
  };
6882
6891
  };
6883
- const useWatchWorkflow = (baseUrl) => {
6892
+ const useWatchWorkflow = () => {
6884
6893
  const [isWatchingLegacyWorkflow, setIsWatchingLegacyWorkflow] = React.useState(false);
6885
6894
  const [isWatchingWorkflow, setIsWatchingWorkflow] = React.useState(false);
6886
6895
  const [legacyWatchResult, setLegacyWatchResult] = React.useState(null);
6887
6896
  const [watchResult, setWatchResult] = React.useState(null);
6897
+ const client = useMastraClient();
6888
6898
  const debouncedSetLegacyWorkflowWatchResult = useDebounce.useDebouncedCallback((record) => {
6889
6899
  const formattedResults = Object.entries(record.results || {}).reduce(
6890
6900
  (acc, [key, value]) => {
@@ -6913,7 +6923,6 @@ const useWatchWorkflow = (baseUrl) => {
6913
6923
  const watchLegacyWorkflow = async ({ workflowId, runId }) => {
6914
6924
  try {
6915
6925
  setIsWatchingLegacyWorkflow(true);
6916
- const client = createMastraClient(baseUrl);
6917
6926
  const workflow = client.getLegacyWorkflow(workflowId);
6918
6927
  await workflow.watch({ runId }, (record) => {
6919
6928
  try {
@@ -6939,7 +6948,6 @@ const useWatchWorkflow = (baseUrl) => {
6939
6948
  const watchWorkflow = async ({ workflowId, runId }) => {
6940
6949
  try {
6941
6950
  setIsWatchingWorkflow(true);
6942
- const client = createMastraClient(baseUrl);
6943
6951
  const workflow = client.getWorkflow(workflowId);
6944
6952
  await workflow.watch({ runId }, (record) => {
6945
6953
  try {
@@ -6967,9 +6975,10 @@ const useWatchWorkflow = (baseUrl) => {
6967
6975
  watchResult
6968
6976
  };
6969
6977
  };
6970
- const useResumeWorkflow = (baseUrl) => {
6978
+ const useResumeWorkflow = () => {
6971
6979
  const [isResumingLegacyWorkflow, setIsResumingLegacyWorkflow] = React.useState(false);
6972
6980
  const [isResumingWorkflow, setIsResumingWorkflow] = React.useState(false);
6981
+ const client = useMastraClient();
6973
6982
  const resumeLegacyWorkflow = async ({
6974
6983
  workflowId,
6975
6984
  stepId,
@@ -6978,7 +6987,6 @@ const useResumeWorkflow = (baseUrl) => {
6978
6987
  }) => {
6979
6988
  try {
6980
6989
  setIsResumingLegacyWorkflow(true);
6981
- const client = createMastraClient(baseUrl);
6982
6990
  const response = await client.getLegacyWorkflow(workflowId).resume({ stepId, runId, context });
6983
6991
  return response;
6984
6992
  } catch (error) {
@@ -6997,7 +7005,6 @@ const useResumeWorkflow = (baseUrl) => {
6997
7005
  }) => {
6998
7006
  try {
6999
7007
  setIsResumingWorkflow(true);
7000
- const client = createMastraClient(baseUrl);
7001
7008
  const runtimeContext$1 = new runtimeContext.RuntimeContext();
7002
7009
  Object.entries(playgroundRuntimeContext).forEach(([key, value]) => {
7003
7010
  runtimeContext$1.set(key, value);
@@ -8280,8 +8287,8 @@ const lodashTitleCase = (str) => {
8280
8287
  return camelCased.replace(/([A-Z])/g, " $1").replace(/^./, (str2) => str2.toUpperCase()).trim();
8281
8288
  };
8282
8289
 
8283
- function LegacyWorkflowGraph({ workflowId, baseUrl }) {
8284
- const { legacyWorkflow, isLoading } = useLegacyWorkflow(workflowId, baseUrl);
8290
+ function LegacyWorkflowGraph({ workflowId }) {
8291
+ const { legacyWorkflow, isLoading } = useLegacyWorkflow(workflowId);
8285
8292
  if (isLoading) {
8286
8293
  return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-4", children: /* @__PURE__ */ jsxRuntime.jsx(Skeleton, { className: "h-[600px]" }) });
8287
8294
  }
@@ -9153,18 +9160,17 @@ const WorkflowResult = ({ jsonResult, sanitizedJsonResult }) => {
9153
9160
 
9154
9161
  function LegacyWorkflowTrigger({
9155
9162
  workflowId,
9156
- baseUrl,
9157
9163
  setRunId
9158
9164
  }) {
9159
9165
  const { legacyResult: result, setLegacyResult: setResult, payload, setPayload } = React.useContext(WorkflowRunContext);
9160
- const { isLoading, legacyWorkflow: workflow } = useLegacyWorkflow(workflowId, baseUrl);
9161
- const { createLegacyWorkflowRun: createWorkflowRun, startLegacyWorkflowRun: startWorkflowRun } = useExecuteWorkflow(baseUrl);
9166
+ const { isLoading, legacyWorkflow: workflow } = useLegacyWorkflow(workflowId);
9167
+ const { createLegacyWorkflowRun: createWorkflowRun, startLegacyWorkflowRun: startWorkflowRun } = useExecuteWorkflow();
9162
9168
  const {
9163
9169
  watchLegacyWorkflow: watchWorkflow,
9164
9170
  legacyWatchResult: watchResult,
9165
9171
  isWatchingLegacyWorkflow: isWatchingWorkflow
9166
- } = useWatchWorkflow(baseUrl);
9167
- const { resumeLegacyWorkflow: resumeWorkflow, isResumingLegacyWorkflow: isResumingWorkflow } = useResumeWorkflow(baseUrl);
9172
+ } = useWatchWorkflow();
9173
+ const { resumeLegacyWorkflow: resumeWorkflow, isResumingLegacyWorkflow: isResumingWorkflow } = useResumeWorkflow();
9168
9174
  const [suspendedSteps, setSuspendedSteps] = React.useState([]);
9169
9175
  const [isRunning, setIsRunning] = React.useState(false);
9170
9176
  const triggerSchema = workflow?.triggerSchema;
@@ -9589,8 +9595,8 @@ function WorkflowGraphInner({ workflow, onShowTrace }) {
9589
9595
  ) });
9590
9596
  }
9591
9597
 
9592
- function WorkflowGraph({ workflowId, baseUrl, onShowTrace }) {
9593
- const { workflow, isLoading } = useWorkflow(workflowId, baseUrl);
9598
+ function WorkflowGraph({ workflowId, onShowTrace }) {
9599
+ const { workflow, isLoading } = useWorkflow(workflowId);
9594
9600
  if (isLoading) {
9595
9601
  return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-4", children: /* @__PURE__ */ jsxRuntime.jsx(Skeleton, { className: "h-[600px]" }) });
9596
9602
  }
@@ -9624,17 +9630,13 @@ const WorkflowStatus = ({ stepId, status }) => {
9624
9630
  );
9625
9631
  };
9626
9632
 
9627
- function WorkflowTrigger({
9628
- workflowId,
9629
- baseUrl,
9630
- setRunId
9631
- }) {
9633
+ function WorkflowTrigger({ workflowId, setRunId }) {
9632
9634
  const { runtimeContext } = usePlaygroundStore();
9633
9635
  const { result, setResult, payload, setPayload } = React.useContext(WorkflowRunContext);
9634
- const { isLoading, workflow } = useWorkflow(workflowId, baseUrl);
9635
- const { createWorkflowRun, startWorkflowRun } = useExecuteWorkflow(baseUrl);
9636
- const { watchWorkflow, watchResult, isWatchingWorkflow } = useWatchWorkflow(baseUrl);
9637
- const { resumeWorkflow, isResumingWorkflow } = useResumeWorkflow(baseUrl);
9636
+ const { isLoading, workflow } = useWorkflow(workflowId);
9637
+ const { createWorkflowRun, startWorkflowRun } = useExecuteWorkflow();
9638
+ const { watchWorkflow, watchResult, isWatchingWorkflow } = useWatchWorkflow();
9639
+ const { resumeWorkflow, isResumingWorkflow } = useResumeWorkflow();
9638
9640
  const [suspendedSteps, setSuspendedSteps] = React.useState([]);
9639
9641
  const [isRunning, setIsRunning] = React.useState(false);
9640
9642
  const triggerSchema = workflow?.inputSchema;
@@ -10124,9 +10126,9 @@ function usePolling({
10124
10126
  };
10125
10127
  }
10126
10128
 
10127
- const useTraces = (componentName, baseUrl, isWorkflow = false) => {
10129
+ const useTraces = (componentName, isWorkflow = false) => {
10128
10130
  const [traces, setTraces] = React.useState([]);
10129
- const client = React.useMemo(() => createMastraClient(baseUrl), [baseUrl]);
10131
+ const client = React.useMemo(() => useMastraClient(), []);
10130
10132
  const fetchFn = React.useCallback(async () => {
10131
10133
  try {
10132
10134
  const res = await client.getTelemetry({
@@ -10221,6 +10223,7 @@ exports.LatencyIcon = LatencyIcon;
10221
10223
  exports.LegacyWorkflowGraph = LegacyWorkflowGraph;
10222
10224
  exports.LegacyWorkflowTrigger = LegacyWorkflowTrigger;
10223
10225
  exports.LogsIcon = LogsIcon;
10226
+ exports.MastraClientProvider = MastraClientProvider;
10224
10227
  exports.MastraResizablePanel = MastraResizablePanel;
10225
10228
  exports.McpCoinIcon = McpCoinIcon;
10226
10229
  exports.McpServerIcon = McpServerIcon;
@@ -10261,6 +10264,7 @@ exports.WorkflowTraces = WorkflowTraces;
10261
10264
  exports.WorkflowTrigger = WorkflowTrigger;
10262
10265
  exports.refineTraces = refineTraces;
10263
10266
  exports.useCurrentRun = useCurrentRun;
10267
+ exports.useMastraClient = useMastraClient;
10264
10268
  exports.usePlaygroundStore = usePlaygroundStore;
10265
10269
  exports.usePolling = usePolling;
10266
10270
  exports.useSpeechRecognition = useSpeechRecognition;