@mastra/playground-ui 6.7.2-alpha.1 → 6.8.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/CHANGELOG.md CHANGED
@@ -1,5 +1,48 @@
1
1
  # @mastra/playground-ui
2
2
 
3
+ ## 6.8.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Toast error from workflow stream and resume stream ([#9460](https://github.com/mastra-ai/mastra/pull/9460))
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [[`b55bbce`](https://github.com/mastra-ai/mastra/commit/b55bbce89404d35fdd967012dd503fae343d4c2d), [`d6cb18e`](https://github.com/mastra-ai/mastra/commit/d6cb18e189fd0ac95d4934cf0d6f2866876d1a2e), [`d0ecff7`](https://github.com/mastra-ai/mastra/commit/d0ecff793d5cd50408cd8d1d113f02e28d897a3d), [`e84a959`](https://github.com/mastra-ai/mastra/commit/e84a9592bfdec4f1c9fdf108c9d4ea4e2ee8f7e3), [`e742d37`](https://github.com/mastra-ai/mastra/commit/e742d371f24ef8059670cc05e9aee308eac068b9)]:
12
+ - @mastra/client-js@0.16.8
13
+ - @mastra/core@0.23.3
14
+ - @mastra/react@0.0.14
15
+
16
+ ## 6.8.0-alpha.0
17
+
18
+ ### Minor Changes
19
+
20
+ - Toast error from workflow stream and resume stream ([#9460](https://github.com/mastra-ai/mastra/pull/9460))
21
+
22
+ ### Patch Changes
23
+
24
+ - Updated dependencies [[`b55bbce`](https://github.com/mastra-ai/mastra/commit/b55bbce89404d35fdd967012dd503fae343d4c2d), [`d6cb18e`](https://github.com/mastra-ai/mastra/commit/d6cb18e189fd0ac95d4934cf0d6f2866876d1a2e), [`d0ecff7`](https://github.com/mastra-ai/mastra/commit/d0ecff793d5cd50408cd8d1d113f02e28d897a3d), [`e84a959`](https://github.com/mastra-ai/mastra/commit/e84a9592bfdec4f1c9fdf108c9d4ea4e2ee8f7e3), [`e742d37`](https://github.com/mastra-ai/mastra/commit/e742d371f24ef8059670cc05e9aee308eac068b9)]:
25
+ - @mastra/client-js@0.16.8-alpha.0
26
+ - @mastra/core@0.23.3-alpha.0
27
+ - @mastra/react@0.0.14-alpha.0
28
+
29
+ ## 6.7.2
30
+
31
+ ### Patch Changes
32
+
33
+ - Update MainSidebar component to fit required changes in Cloud CTA link ([#9364](https://github.com/mastra-ai/mastra/pull/9364))
34
+
35
+ - Render zod unions and discriminated unions correctly in dynamic form. ([#9365](https://github.com/mastra-ai/mastra/pull/9365))
36
+
37
+ - Extract more components to playground-ui for sharing with cloud ([#9416](https://github.com/mastra-ai/mastra/pull/9416))
38
+
39
+ - Move some components to playground-ui for usage in cloud ([#9358](https://github.com/mastra-ai/mastra/pull/9358))
40
+
41
+ - Updated dependencies [[`f57a81e`](https://github.com/mastra-ai/mastra/commit/f57a81e6ce644e45bf1c9618778cc54c50a84ad4), [`2afd345`](https://github.com/mastra-ai/mastra/commit/2afd3450825b76e41f7973baddf13867ea042e40), [`fc79af3`](https://github.com/mastra-ai/mastra/commit/fc79af3915d1c456729cbd753673b0c0564340d8), [`eefc89e`](https://github.com/mastra-ai/mastra/commit/eefc89ee69f05bb71661473a807fc7dc03d56f17), [`60bd45d`](https://github.com/mastra-ai/mastra/commit/60bd45de021f0dfbe6583928f6da5169cb5585ba), [`a30093d`](https://github.com/mastra-ai/mastra/commit/a30093de98c1836dcd5dfddf09649010712b8c95), [`0fe7adb`](https://github.com/mastra-ai/mastra/commit/0fe7adb0f20f59a6bb41f235d01f8b7a880ea6e7), [`a42e496`](https://github.com/mastra-ai/mastra/commit/a42e49686a7486e2e9e9397fa98e5ff7a71dc1b0), [`3670db7`](https://github.com/mastra-ai/mastra/commit/3670db7e8e798f9d65fac5bfb732134a1f26ba7b), [`e40d4d0`](https://github.com/mastra-ai/mastra/commit/e40d4d0a0971b4505e7c9de73c656066c7565653), [`fc843ff`](https://github.com/mastra-ai/mastra/commit/fc843ff4d1d149317b6324553ce5ad7972062a78), [`ff16f9b`](https://github.com/mastra-ai/mastra/commit/ff16f9b9dbc701b26b6c4e9872f759f3880f9327), [`35e6cf7`](https://github.com/mastra-ai/mastra/commit/35e6cf722fef16ea0301eb9cf5a32fe9ccb12d22), [`30a2e36`](https://github.com/mastra-ai/mastra/commit/30a2e369485e0e59c4faa1d83c5635c2260b304c)]:
42
+ - @mastra/core@0.23.2
43
+ - @mastra/client-js@0.16.7
44
+ - @mastra/react@0.0.13
45
+
3
46
  ## 6.7.2-alpha.1
4
47
 
5
48
  ### Patch Changes
package/dist/index.cjs.js CHANGED
@@ -8133,6 +8133,110 @@ const useWorkflows = () => {
8133
8133
  });
8134
8134
  };
8135
8135
 
8136
+ const defaultOptions = {
8137
+ duration: 3e3,
8138
+ cancel: {
8139
+ label: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.X, { size: "14" }),
8140
+ onClick: () => {
8141
+ }
8142
+ },
8143
+ unstyled: true,
8144
+ classNames: {
8145
+ toast: "bg-[#0F0F0F] w-full backdrop-accent h-auto rounded-lg gap-2 border border p-4 flex items-start rounded-lg pointer-events-auto",
8146
+ title: "text-white font-semibold text-xs mb-1 -mt-1",
8147
+ description: "!text-text text-sm !font-light",
8148
+ cancelButton: "self-start !bg-transparent !p-0 flex items-center justify-center !text-text opacity-50 order-last hover:opacity-100",
8149
+ actionButton: "!bg-white flex items-center justify-center font-medium !text-black order-last hover:opacity-80"
8150
+ }
8151
+ };
8152
+ function getToastOptions(options) {
8153
+ const { classNames, ...rest } = defaultOptions;
8154
+ const { classNames: optionsClassNames, ...restOptions } = options || {};
8155
+ return {
8156
+ ...rest,
8157
+ classNames: {
8158
+ ...classNames,
8159
+ title: cn(classNames?.title, "mt-auto", optionsClassNames?.title),
8160
+ toast: cn(classNames?.toast, "!items-center", optionsClassNames?.toast),
8161
+ cancelButton: cn(classNames?.cancelButton, "!self-center", optionsClassNames?.cancelButton),
8162
+ actionButton: cn(classNames?.actionButton, optionsClassNames?.actionButton)
8163
+ },
8164
+ ...restOptions
8165
+ };
8166
+ }
8167
+ const toast = (message, options = {}) => {
8168
+ if (Array.isArray(message)) {
8169
+ return message.forEach((msg) => sonner.toast(msg, getToastOptions(options)));
8170
+ } else if (React.isValidElement(message)) {
8171
+ return sonner.toast(message, getToastOptions(options));
8172
+ } else if (typeof message === "string") {
8173
+ return sonner.toast(message, getToastOptions(options));
8174
+ }
8175
+ throw new Error("Invalid message type");
8176
+ };
8177
+ toast.success = (message, options = {}) => {
8178
+ switch (typeof message) {
8179
+ case "string":
8180
+ return sonner.toast.success(message, getToastOptions(options));
8181
+ case "object":
8182
+ return message.forEach((message2) => sonner.toast.success(message2, getToastOptions(options)));
8183
+ }
8184
+ };
8185
+ toast.error = (message, options = {}) => {
8186
+ switch (typeof message) {
8187
+ case "string":
8188
+ return sonner.toast.error(message, getToastOptions(options));
8189
+ case "object":
8190
+ return message.forEach((message2) => sonner.toast.error(message2, getToastOptions(options)));
8191
+ }
8192
+ };
8193
+ toast.warning = (message, options = {}) => {
8194
+ switch (typeof message) {
8195
+ case "string":
8196
+ return sonner.toast.warning(message, getToastOptions(options));
8197
+ case "object":
8198
+ return message.forEach((message2) => sonner.toast.warning(message2, getToastOptions(options)));
8199
+ }
8200
+ };
8201
+ toast.info = (message, options = {}) => {
8202
+ switch (typeof message) {
8203
+ case "string":
8204
+ return sonner.toast.info(message, getToastOptions(options));
8205
+ case "object":
8206
+ return message.forEach((message2) => sonner.toast.info(message2, getToastOptions(options)));
8207
+ }
8208
+ };
8209
+ toast.custom = (message, options = {}) => {
8210
+ return sonner.toast(message, getToastOptions(options));
8211
+ };
8212
+ toast.dismiss = (toastId) => {
8213
+ if (toastId) {
8214
+ sonner.toast.dismiss(toastId);
8215
+ }
8216
+ };
8217
+ toast.promise = ({
8218
+ myPromise,
8219
+ loadingMessage,
8220
+ successMessage,
8221
+ errorMessage,
8222
+ onSuccess,
8223
+ onError,
8224
+ options = {}
8225
+ }) => {
8226
+ return sonner.toast.promise(myPromise, {
8227
+ loading: loadingMessage ?? "Loading...",
8228
+ success: (data) => {
8229
+ onSuccess?.(data);
8230
+ return successMessage;
8231
+ },
8232
+ error: (err) => {
8233
+ onError?.(err);
8234
+ return errorMessage || err?.message || "Error...";
8235
+ },
8236
+ ...getToastOptions(options)
8237
+ });
8238
+ };
8239
+
8136
8240
  const useExecuteWorkflow = () => {
8137
8241
  const client = react$3.useMastraClient();
8138
8242
  const createWorkflowRun = reactQuery.useMutation({
@@ -8229,6 +8333,23 @@ const useStreamWorkflow = () => {
8229
8333
  }
8230
8334
  };
8231
8335
  }, []);
8336
+ const handleStreamError = (err, defaultMessage, setIsStreaming2) => {
8337
+ if (err instanceof TypeError) {
8338
+ return;
8339
+ }
8340
+ const errorMessage = err instanceof Error ? err.message : defaultMessage;
8341
+ toast.error(errorMessage);
8342
+ setIsStreaming2?.(false);
8343
+ };
8344
+ const handleWorkflowFinish = (value) => {
8345
+ if (value.type === "workflow-finish") {
8346
+ const streamStatus = value.payload?.workflowStatus;
8347
+ const metadata = value.payload?.metadata;
8348
+ if (streamStatus === "failed") {
8349
+ throw new Error(metadata?.errorMessage || "Workflow execution failed");
8350
+ }
8351
+ }
8352
+ };
8232
8353
  const streamWorkflow = reactQuery.useMutation({
8233
8354
  mutationFn: async ({
8234
8355
  workflowId,
@@ -8248,7 +8369,9 @@ const useStreamWorkflow = () => {
8248
8369
  });
8249
8370
  const workflow = client.getWorkflow(workflowId);
8250
8371
  const stream = await workflow.streamVNext({ runId, inputData, runtimeContext: runtimeContext$1, closeOnSuspend: true });
8251
- if (!stream) throw new Error("No stream returned");
8372
+ if (!stream) {
8373
+ return handleStreamError(new Error("No stream returned"), "No stream returned", setIsStreaming);
8374
+ }
8252
8375
  const reader = stream.getReader();
8253
8376
  readerRef.current = reader;
8254
8377
  try {
@@ -8267,10 +8390,13 @@ const useStreamWorkflow = () => {
8267
8390
  if (value.type === "workflow-step-suspended") {
8268
8391
  setIsStreaming(false);
8269
8392
  }
8393
+ if (value.type === "workflow-finish") {
8394
+ handleWorkflowFinish(value);
8395
+ }
8270
8396
  }
8271
8397
  }
8272
- } catch (error) {
8273
- console.error("Error streaming workflow:", error);
8398
+ } catch (err) {
8399
+ handleStreamError(err, "Error streaming workflow");
8274
8400
  } finally {
8275
8401
  if (isMountedRef.current) {
8276
8402
  setIsStreaming(false);
@@ -8300,7 +8426,9 @@ const useStreamWorkflow = () => {
8300
8426
  }
8301
8427
  const workflow = client.getWorkflow(workflowId);
8302
8428
  const stream = await workflow.observeStreamVNext({ runId });
8303
- if (!stream) throw new Error("No stream returned");
8429
+ if (!stream) {
8430
+ return handleStreamError(new Error("No stream returned"), "No stream returned", setIsStreaming);
8431
+ }
8304
8432
  const reader = stream.getReader();
8305
8433
  observerRef.current = reader;
8306
8434
  try {
@@ -8319,10 +8447,13 @@ const useStreamWorkflow = () => {
8319
8447
  if (value.type === "workflow-step-suspended") {
8320
8448
  setIsStreaming(false);
8321
8449
  }
8450
+ if (value.type === "workflow-finish") {
8451
+ handleWorkflowFinish(value);
8452
+ }
8322
8453
  }
8323
8454
  }
8324
- } catch (error) {
8325
- console.error("Error streaming workflow:", error);
8455
+ } catch (err) {
8456
+ handleStreamError(err, "Error observing workflow");
8326
8457
  } finally {
8327
8458
  if (isMountedRef.current) {
8328
8459
  setIsStreaming(false);
@@ -8353,7 +8484,9 @@ const useStreamWorkflow = () => {
8353
8484
  runtimeContext$1.set(key, value);
8354
8485
  });
8355
8486
  const stream = await workflow.resumeStreamVNext({ runId, step, resumeData, runtimeContext: runtimeContext$1 });
8356
- if (!stream) throw new Error("No stream returned");
8487
+ if (!stream) {
8488
+ return handleStreamError(new Error("No stream returned"), "No stream returned", setIsStreaming);
8489
+ }
8357
8490
  const reader = stream.getReader();
8358
8491
  resumeStreamRef.current = reader;
8359
8492
  try {
@@ -8372,10 +8505,13 @@ const useStreamWorkflow = () => {
8372
8505
  if (value.type === "workflow-step-suspended") {
8373
8506
  setIsStreaming(false);
8374
8507
  }
8508
+ if (value.type === "workflow-finish") {
8509
+ handleWorkflowFinish(value);
8510
+ }
8375
8511
  }
8376
8512
  }
8377
- } catch (error) {
8378
- console.error("Error resuming workflow stream:", error);
8513
+ } catch (err) {
8514
+ handleStreamError(err, "Error resuming workflow stream");
8379
8515
  } finally {
8380
8516
  if (isMountedRef.current) {
8381
8517
  setIsStreaming(false);
@@ -20339,6 +20475,10 @@ const useEvalsByAgentId = (agentId, type) => {
20339
20475
  });
20340
20476
  };
20341
20477
 
20478
+ Object.defineProperty(exports, "Toaster", {
20479
+ enumerable: true,
20480
+ get: () => sonner.Toaster
20481
+ });
20342
20482
  exports.AgentChat = AgentChat;
20343
20483
  exports.AgentCoinIcon = AgentCoinIcon;
20344
20484
  exports.AgentEntityHeader = AgentEntityHeader;
@@ -20547,6 +20687,7 @@ exports.parseError = parseError;
20547
20687
  exports.providerMapToIcon = providerMapToIcon;
20548
20688
  exports.scoresListColumns = scoresListColumns;
20549
20689
  exports.spanTypePrefixes = spanTypePrefixes;
20690
+ exports.toast = toast;
20550
20691
  exports.traceScoresListColumns = traceScoresListColumns;
20551
20692
  exports.tracesListColumns = tracesListColumns;
20552
20693
  exports.transformKey = transformKey;