@mastra/react 0.2.2 → 0.2.3-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.
Files changed (22) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/dist/{chunk-REDZDNFN-C5a6GuK0.js → chunk-REDZDNFN-B9d_O-oZ.js} +2 -2
  3. package/dist/{chunk-REDZDNFN-C5a6GuK0.js.map → chunk-REDZDNFN-B9d_O-oZ.js.map} +1 -1
  4. package/dist/{chunk-REDZDNFN-vi5yKtN5.cjs → chunk-REDZDNFN-Dre-QyMV.cjs} +2 -2
  5. package/dist/{chunk-REDZDNFN-vi5yKtN5.cjs.map → chunk-REDZDNFN-Dre-QyMV.cjs.map} +1 -1
  6. package/dist/{index-OZrcVzMn.js → index-BrKmSy1n.js} +176 -141
  7. package/dist/index-BrKmSy1n.js.map +1 -0
  8. package/dist/{index-DUTv-1fm.cjs → index-kMIXwQyE.cjs} +176 -141
  9. package/dist/index-kMIXwQyE.cjs.map +1 -0
  10. package/dist/index.cjs +1 -1
  11. package/dist/index.js +1 -1
  12. package/dist/{token-6GSAFR2W-XRCSVUPZ-CxcM_lpA.cjs → token-6GSAFR2W-XRCSVUPZ-B7ZkFki_.cjs} +3 -3
  13. package/dist/{token-6GSAFR2W-XRCSVUPZ-CxcM_lpA.cjs.map → token-6GSAFR2W-XRCSVUPZ-B7ZkFki_.cjs.map} +1 -1
  14. package/dist/{token-6GSAFR2W-XRCSVUPZ-oh_q0WOI.js → token-6GSAFR2W-XRCSVUPZ-DJZ6OlXQ.js} +3 -3
  15. package/dist/{token-6GSAFR2W-XRCSVUPZ-oh_q0WOI.js.map → token-6GSAFR2W-XRCSVUPZ-DJZ6OlXQ.js.map} +1 -1
  16. package/dist/{token-util-NEHG7TUY-U7CX7GS4-D2Go4cJt.js → token-util-NEHG7TUY-U7CX7GS4-CUomXYUl.js} +2 -2
  17. package/dist/{token-util-NEHG7TUY-U7CX7GS4-D2Go4cJt.js.map → token-util-NEHG7TUY-U7CX7GS4-CUomXYUl.js.map} +1 -1
  18. package/dist/{token-util-NEHG7TUY-U7CX7GS4-CwzYo-I6.cjs → token-util-NEHG7TUY-U7CX7GS4-D1wA3Puq.cjs} +2 -2
  19. package/dist/{token-util-NEHG7TUY-U7CX7GS4-CwzYo-I6.cjs.map → token-util-NEHG7TUY-U7CX7GS4-D1wA3Puq.cjs.map} +1 -1
  20. package/package.json +3 -3
  21. package/dist/index-DUTv-1fm.cjs.map +0 -1
  22. package/dist/index-OZrcVzMn.js.map +0 -1
@@ -94,6 +94,25 @@ const mapWorkflowStreamChunkToWatchResult = (prev, chunk) => {
94
94
  steps: newSteps
95
95
  };
96
96
  }
97
+ if (chunk.type === "workflow-step-progress") {
98
+ const progressSteps = {
99
+ ...prev?.steps,
100
+ [chunk.payload.id]: {
101
+ ...prev?.steps?.[chunk.payload.id],
102
+ foreachProgress: {
103
+ completedCount: chunk.payload.completedCount,
104
+ totalCount: chunk.payload.totalCount,
105
+ currentIndex: chunk.payload.currentIndex,
106
+ iterationStatus: chunk.payload.iterationStatus,
107
+ iterationOutput: chunk.payload.iterationOutput
108
+ }
109
+ }
110
+ };
111
+ return {
112
+ ...prev,
113
+ steps: progressSteps
114
+ };
115
+ }
97
116
  if (chunk.type === "workflow-step-result") {
98
117
  return {
99
118
  ...prev,
@@ -947,125 +966,6 @@ const resolveToChildMessages = (messages) => {
947
966
  return childMessages;
948
967
  };
949
968
 
950
- // src/request-context/index.ts
951
- var RequestContext = class {
952
- registry = /* @__PURE__ */ new Map();
953
- constructor(iterable) {
954
- this.registry = new Map(iterable);
955
- }
956
- /**
957
- * set a value with strict typing if `Values` is a Record and the key exists in it.
958
- */
959
- set(key, value) {
960
- this.registry.set(key, value);
961
- }
962
- /**
963
- * Get a value with its type
964
- */
965
- get(key) {
966
- return this.registry.get(key);
967
- }
968
- /**
969
- * Check if a key exists in the container
970
- */
971
- has(key) {
972
- return this.registry.has(key);
973
- }
974
- /**
975
- * Delete a value by key
976
- */
977
- delete(key) {
978
- return this.registry.delete(key);
979
- }
980
- /**
981
- * Clear all values from the container
982
- */
983
- clear() {
984
- this.registry.clear();
985
- }
986
- /**
987
- * Get all keys in the container
988
- */
989
- keys() {
990
- return this.registry.keys();
991
- }
992
- /**
993
- * Get all values in the container
994
- */
995
- values() {
996
- return this.registry.values();
997
- }
998
- /**
999
- * Get all entries in the container.
1000
- * Returns a discriminated union of tuples for proper type narrowing when iterating.
1001
- */
1002
- entries() {
1003
- return this.registry.entries();
1004
- }
1005
- /**
1006
- * Get the size of the container
1007
- */
1008
- size() {
1009
- return this.registry.size;
1010
- }
1011
- /**
1012
- * Execute a function for each entry in the container.
1013
- * The callback receives properly typed key-value pairs.
1014
- */
1015
- forEach(callbackfn) {
1016
- this.registry.forEach(callbackfn);
1017
- }
1018
- /**
1019
- * Custom JSON serialization method.
1020
- * Converts the internal Map to a plain object for proper JSON serialization.
1021
- * Non-serializable values (e.g., RPC proxies, functions, circular references)
1022
- * are skipped to prevent serialization errors when storing to database.
1023
- */
1024
- toJSON() {
1025
- const result = {};
1026
- for (const [key, value] of this.registry.entries()) {
1027
- if (this.isSerializable(value)) {
1028
- result[key] = value;
1029
- }
1030
- }
1031
- return result;
1032
- }
1033
- /**
1034
- * Check if a value can be safely serialized to JSON.
1035
- */
1036
- isSerializable(value) {
1037
- if (value === null || value === void 0) return true;
1038
- if (typeof value === "function") return false;
1039
- if (typeof value === "symbol") return false;
1040
- if (typeof value !== "object") return true;
1041
- try {
1042
- JSON.stringify(value);
1043
- return true;
1044
- } catch {
1045
- return false;
1046
- }
1047
- }
1048
- /**
1049
- * Get all values as a typed object for destructuring.
1050
- * Returns Record<string, any> when untyped, or the Values type when typed.
1051
- *
1052
- * @example
1053
- * ```typescript
1054
- * const ctx = new RequestContext<{ userId: string; apiKey: string }>();
1055
- * ctx.set('userId', 'user-123');
1056
- * ctx.set('apiKey', 'key-456');
1057
- * const { userId, apiKey } = ctx.all;
1058
- * ```
1059
- */
1060
- get all() {
1061
- return Object.fromEntries(this.registry);
1062
- }
1063
- };
1064
-
1065
- function getDefaultExportFromCjs (x) {
1066
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
1067
- }
1068
-
1069
969
  var __create$4 = Object.create;
1070
970
  var __defProp$6 = Object.defineProperty;
1071
971
  var __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor;
@@ -3249,8 +3149,8 @@ var require_get_vercel_oidc_token = __commonJS$3({
3249
3149
  }
3250
3150
  try {
3251
3151
  const [{ getTokenPayload, isExpired }, { refreshToken }] = await Promise.all([
3252
- await import('./token-util-NEHG7TUY-U7CX7GS4-D2Go4cJt.js'),
3253
- await import('./token-6GSAFR2W-XRCSVUPZ-oh_q0WOI.js')
3152
+ await import('./token-util-NEHG7TUY-U7CX7GS4-CUomXYUl.js'),
3153
+ await import('./token-6GSAFR2W-XRCSVUPZ-DJZ6OlXQ.js')
3254
3154
  ]);
3255
3155
  if (!token || isExpired(getTokenPayload(token))) {
3256
3156
  await refreshToken();
@@ -5846,6 +5746,125 @@ var MastraBaseError = class extends Error {
5846
5746
  var MastraError = class extends MastraBaseError {
5847
5747
  };
5848
5748
 
5749
+ // src/request-context/index.ts
5750
+ var RequestContext = class {
5751
+ registry = /* @__PURE__ */ new Map();
5752
+ constructor(iterable) {
5753
+ this.registry = new Map(iterable);
5754
+ }
5755
+ /**
5756
+ * set a value with strict typing if `Values` is a Record and the key exists in it.
5757
+ */
5758
+ set(key, value) {
5759
+ this.registry.set(key, value);
5760
+ }
5761
+ /**
5762
+ * Get a value with its type
5763
+ */
5764
+ get(key) {
5765
+ return this.registry.get(key);
5766
+ }
5767
+ /**
5768
+ * Check if a key exists in the container
5769
+ */
5770
+ has(key) {
5771
+ return this.registry.has(key);
5772
+ }
5773
+ /**
5774
+ * Delete a value by key
5775
+ */
5776
+ delete(key) {
5777
+ return this.registry.delete(key);
5778
+ }
5779
+ /**
5780
+ * Clear all values from the container
5781
+ */
5782
+ clear() {
5783
+ this.registry.clear();
5784
+ }
5785
+ /**
5786
+ * Get all keys in the container
5787
+ */
5788
+ keys() {
5789
+ return this.registry.keys();
5790
+ }
5791
+ /**
5792
+ * Get all values in the container
5793
+ */
5794
+ values() {
5795
+ return this.registry.values();
5796
+ }
5797
+ /**
5798
+ * Get all entries in the container.
5799
+ * Returns a discriminated union of tuples for proper type narrowing when iterating.
5800
+ */
5801
+ entries() {
5802
+ return this.registry.entries();
5803
+ }
5804
+ /**
5805
+ * Get the size of the container
5806
+ */
5807
+ size() {
5808
+ return this.registry.size;
5809
+ }
5810
+ /**
5811
+ * Execute a function for each entry in the container.
5812
+ * The callback receives properly typed key-value pairs.
5813
+ */
5814
+ forEach(callbackfn) {
5815
+ this.registry.forEach(callbackfn);
5816
+ }
5817
+ /**
5818
+ * Custom JSON serialization method.
5819
+ * Converts the internal Map to a plain object for proper JSON serialization.
5820
+ * Non-serializable values (e.g., RPC proxies, functions, circular references)
5821
+ * are skipped to prevent serialization errors when storing to database.
5822
+ */
5823
+ toJSON() {
5824
+ const result = {};
5825
+ for (const [key, value] of this.registry.entries()) {
5826
+ if (this.isSerializable(value)) {
5827
+ result[key] = value;
5828
+ }
5829
+ }
5830
+ return result;
5831
+ }
5832
+ /**
5833
+ * Check if a value can be safely serialized to JSON.
5834
+ */
5835
+ isSerializable(value) {
5836
+ if (value === null || value === void 0) return true;
5837
+ if (typeof value === "function") return false;
5838
+ if (typeof value === "symbol") return false;
5839
+ if (typeof value !== "object") return true;
5840
+ try {
5841
+ JSON.stringify(value);
5842
+ return true;
5843
+ } catch {
5844
+ return false;
5845
+ }
5846
+ }
5847
+ /**
5848
+ * Get all values as a typed object for destructuring.
5849
+ * Returns Record<string, any> when untyped, or the Values type when typed.
5850
+ *
5851
+ * @example
5852
+ * ```typescript
5853
+ * const ctx = new RequestContext<{ userId: string; apiKey: string }>();
5854
+ * ctx.set('userId', 'user-123');
5855
+ * ctx.set('apiKey', 'key-456');
5856
+ * const { userId, apiKey } = ctx.all;
5857
+ * ```
5858
+ */
5859
+ get all() {
5860
+ return Object.fromEntries(this.registry);
5861
+ }
5862
+ };
5863
+
5864
+ function getDefaultExportFromCjs (x) {
5865
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
5866
+ }
5867
+
5849
5868
  // ../_vendored/ai_v4/dist/chunk-OPIPXJLE.js
5850
5869
  var __create$2 = Object.create;
5851
5870
  var __defProp$3 = Object.defineProperty;
@@ -10187,6 +10206,16 @@ function findToolCallArgs(messages, toolCallId) {
10187
10206
  function filterDataParts(parts) {
10188
10207
  return parts.filter((part) => !part.type.startsWith("data-"));
10189
10208
  }
10209
+ function filterEmptyTextParts(parts) {
10210
+ const hasNonEmptyParts = parts.some((part) => !(part.type === "text" && part.text === ""));
10211
+ if (!hasNonEmptyParts) return parts;
10212
+ return parts.filter((part) => {
10213
+ if (part.type === "text") {
10214
+ return part.text !== "";
10215
+ }
10216
+ return true;
10217
+ });
10218
+ }
10190
10219
  var AIV4Adapter = class {
10191
10220
  /**
10192
10221
  * Convert MastraDBMessage to AI SDK V4 UIMessage
@@ -10322,9 +10351,10 @@ var AIV4Adapter = class {
10322
10351
  * Convert AI SDK V4 UIMessage to MastraDBMessage
10323
10352
  */
10324
10353
  static fromUIMessage(message, ctx, messageSource) {
10354
+ const filteredParts = message.parts ? filterEmptyTextParts(message.parts) : [];
10325
10355
  const content = {
10326
10356
  format: 2,
10327
- parts: message.parts
10357
+ parts: filteredParts
10328
10358
  };
10329
10359
  if (message.toolInvocations) content.toolInvocations = message.toolInvocations;
10330
10360
  if (message.reasoning) content.reasoning = message.reasoning;
@@ -10521,9 +10551,10 @@ var AIV4Adapter = class {
10521
10551
  }
10522
10552
  }
10523
10553
  }
10554
+ const filteredParts = filterEmptyTextParts(parts);
10524
10555
  const content = {
10525
10556
  format: 2,
10526
- parts
10557
+ parts: filteredParts
10527
10558
  };
10528
10559
  if (toolInvocations.length) content.toolInvocations = toolInvocations;
10529
10560
  if (typeof coreMessage.content === `string`) content.content = coreMessage.content;
@@ -10549,6 +10580,16 @@ var AIV4Adapter = class {
10549
10580
  };
10550
10581
 
10551
10582
  // src/agent/message-list/adapters/AIV5Adapter.ts
10583
+ function filterEmptyTextParts2(parts) {
10584
+ const hasNonEmptyParts = parts.some((part) => !(part.type === "text" && part.text === ""));
10585
+ if (!hasNonEmptyParts) return parts;
10586
+ return parts.filter((part) => {
10587
+ if (part.type === "text") {
10588
+ return part.text !== "";
10589
+ }
10590
+ return true;
10591
+ });
10592
+ }
10552
10593
  function getToolName(type) {
10553
10594
  if (typeof type === "object" && type && "type" in type) {
10554
10595
  type = type.type;
@@ -10881,6 +10922,7 @@ var AIV5Adapter = class {
10881
10922
  }
10882
10923
  return null;
10883
10924
  }).filter((p) => p !== null);
10925
+ const filteredV2Parts = filterEmptyTextParts2(v2Parts);
10884
10926
  return {
10885
10927
  id: uiMsg.id,
10886
10928
  role: uiMsg.role,
@@ -10889,7 +10931,7 @@ var AIV5Adapter = class {
10889
10931
  resourceId,
10890
10932
  content: {
10891
10933
  format: 2,
10892
- parts: v2Parts,
10934
+ parts: filteredV2Parts,
10893
10935
  toolInvocations,
10894
10936
  reasoning,
10895
10937
  experimental_attachments,
@@ -10949,7 +10991,6 @@ var AIV5Adapter = class {
10949
10991
  const toolInvocations = [];
10950
10992
  const reasoningParts = [];
10951
10993
  const experimental_attachments = [];
10952
- let lastPartWasToolResult = false;
10953
10994
  for (const part of content) {
10954
10995
  if (part.type === "text") {
10955
10996
  const textPart = {
@@ -10960,7 +11001,6 @@ var AIV5Adapter = class {
10960
11001
  textPart.providerMetadata = part.providerOptions;
10961
11002
  }
10962
11003
  mastraDBParts.push(textPart);
10963
- lastPartWasToolResult = false;
10964
11004
  } else if (part.type === "tool-call") {
10965
11005
  const toolCallPart = part;
10966
11006
  const toolInvocationPart = {
@@ -10982,7 +11022,6 @@ var AIV5Adapter = class {
10982
11022
  args: toolCallPart.input,
10983
11023
  state: "call"
10984
11024
  });
10985
- lastPartWasToolResult = false;
10986
11025
  } else if (part.type === "tool-result") {
10987
11026
  const toolResultPart = part;
10988
11027
  const matchingCall = toolInvocations.find((inv) => inv.toolCallId === toolResultPart.toolCallId);
@@ -11020,7 +11059,6 @@ var AIV5Adapter = class {
11020
11059
  updateMatchingCallInvocationResult(toolResultPart, toolInvocationPart.toolInvocation);
11021
11060
  mastraDBParts.push(toolInvocationPart);
11022
11061
  }
11023
- lastPartWasToolResult = true;
11024
11062
  } else if (part.type === "reasoning") {
11025
11063
  const v2ReasoningPart = {
11026
11064
  type: "reasoning",
@@ -11032,7 +11070,6 @@ var AIV5Adapter = class {
11032
11070
  }
11033
11071
  mastraDBParts.push(v2ReasoningPart);
11034
11072
  reasoningParts.push(part.text);
11035
- lastPartWasToolResult = false;
11036
11073
  } else if (part.type === "image") {
11037
11074
  const imagePart = part;
11038
11075
  const mimeType = imagePart.mediaType || "image/jpeg";
@@ -11050,7 +11087,6 @@ var AIV5Adapter = class {
11050
11087
  url: imageData,
11051
11088
  contentType: mimeType
11052
11089
  });
11053
- lastPartWasToolResult = false;
11054
11090
  } else if (part.type === "file") {
11055
11091
  const filePart = part;
11056
11092
  const mimeType = filePart.mediaType || "application/octet-stream";
@@ -11068,17 +11104,10 @@ var AIV5Adapter = class {
11068
11104
  url: fileData,
11069
11105
  contentType: mimeType
11070
11106
  });
11071
- lastPartWasToolResult = false;
11072
11107
  }
11073
11108
  }
11074
- if (modelMsg.role === "assistant" && lastPartWasToolResult && mastraDBParts.length > 0) {
11075
- const lastPart = mastraDBParts[mastraDBParts.length - 1];
11076
- if (lastPart && lastPart.type !== "text") {
11077
- const emptyTextPart = { type: "text", text: "" };
11078
- mastraDBParts.push(emptyTextPart);
11079
- }
11080
- }
11081
- const contentString = mastraDBParts.filter((p) => p.type === "text").map((p) => p.text).join("\n");
11109
+ const filteredMastraDBParts = filterEmptyTextParts2(mastraDBParts);
11110
+ const contentString = filteredMastraDBParts.filter((p) => p.type === "text").map((p) => p.text).join("\n");
11082
11111
  const metadata = "metadata" in modelMsg && modelMsg.metadata !== null && modelMsg.metadata !== void 0 ? modelMsg.metadata : {};
11083
11112
  const id = `id` in modelMsg && typeof modelMsg.id === `string` ? modelMsg.id : `msg-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
11084
11113
  const message = {
@@ -11087,7 +11116,7 @@ var AIV5Adapter = class {
11087
11116
  createdAt: /* @__PURE__ */ new Date(),
11088
11117
  content: {
11089
11118
  format: 2,
11090
- parts: mastraDBParts,
11119
+ parts: filteredMastraDBParts,
11091
11120
  toolInvocations: toolInvocations.length > 0 ? toolInvocations : void 0,
11092
11121
  reasoning: reasoningParts.length > 0 ? reasoningParts.join("\n") : void 0,
11093
11122
  experimental_attachments: experimental_attachments.length > 0 ? experimental_attachments : void 0,
@@ -11646,6 +11675,12 @@ function sanitizeV5UIMessages(messages, filterIncompleteToolCalls = false) {
11646
11675
  if (typeof p.type === "string" && p.type.startsWith("data-")) {
11647
11676
  return false;
11648
11677
  }
11678
+ if (p.type === "text" && (!("text" in p) || p.text === "" || p.text?.trim() === "")) {
11679
+ const hasNonEmptyParts = m.parts.some(
11680
+ (part) => !(part.type === "text" && (!("text" in part) || part.text === "" || part.text?.trim() === ""))
11681
+ );
11682
+ if (hasNonEmptyParts) return false;
11683
+ }
11649
11684
  if (!isToolUIPart(p)) return true;
11650
11685
  if (filterIncompleteToolCalls) {
11651
11686
  return p.state === "output-available" || p.state === "output-error";
@@ -27665,4 +27700,4 @@ function useCancelWorkflowRun() {
27665
27700
  }
27666
27701
 
27667
27702
  export { MessageUsages as $, EntryTitleClass as A, EntryTitle as B, CodeBlockClass as C, CodeBlock as D, Entity as E, CodeCopyButton as F, Icon as G, IconButtonClass as H, IconSizes as I, IconButton as J, AgentIcon as K, ToolsIcon as L, MastraReactProvider as M, Tooltip as N, TooltipContentClass as O, TooltipContent as P, TooltipTrigger as Q, MessageClass as R, Message as S, ToolApprovalClass as T, MessageContentClass as U, MessageContent as V, WorkflowIcon as W, MessageActionsClass as X, MessageActions as Y, MessageUsagesClass as Z, __commonJS$3 as _, __require2 as a, MessageUsageClass as a0, MessageUsage as a1, MessageUsageEntryClass as a2, MessageUsageEntry as a3, MessageUsageValueClass as a4, MessageUsageValue as a5, MessageListClass as a6, MessageList as a7, MessageStreamingClass as a8, MessageStreaming as a9, useCreateWorkflowRun as aa, useCancelWorkflowRun as ab, useStreamWorkflow as ac, useChat as b, resolveToChildMessages as c, toAssistantUIMessage as d, useEntity as e, EntityTriggerClass as f, EntityTriggerVariantClasses as g, EntityTrigger as h, EntityContentClass as i, EntityContent as j, EntityCaret as k, ToolApproval as l, mapWorkflowStreamChunkToWatchResult as m, ToolApprovalTitleClass as n, ToolApprovalTitle as o, ToolApprovalHeaderClass as p, ToolApprovalHeader as q, require_token_error as r, ToolApprovalContentClass as s, toUIMessage as t, useMastraClient as u, ToolApprovalContent as v, ToolApprovalActionsClass as w, ToolApprovalActions as x, EntryClass as y, Entry as z };
27668
- //# sourceMappingURL=index-OZrcVzMn.js.map
27703
+ //# sourceMappingURL=index-BrKmSy1n.js.map