@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
@@ -114,6 +114,25 @@ const mapWorkflowStreamChunkToWatchResult = (prev, chunk) => {
114
114
  steps: newSteps
115
115
  };
116
116
  }
117
+ if (chunk.type === "workflow-step-progress") {
118
+ const progressSteps = {
119
+ ...prev?.steps,
120
+ [chunk.payload.id]: {
121
+ ...prev?.steps?.[chunk.payload.id],
122
+ foreachProgress: {
123
+ completedCount: chunk.payload.completedCount,
124
+ totalCount: chunk.payload.totalCount,
125
+ currentIndex: chunk.payload.currentIndex,
126
+ iterationStatus: chunk.payload.iterationStatus,
127
+ iterationOutput: chunk.payload.iterationOutput
128
+ }
129
+ }
130
+ };
131
+ return {
132
+ ...prev,
133
+ steps: progressSteps
134
+ };
135
+ }
117
136
  if (chunk.type === "workflow-step-result") {
118
137
  return {
119
138
  ...prev,
@@ -967,125 +986,6 @@ const resolveToChildMessages = (messages) => {
967
986
  return childMessages;
968
987
  };
969
988
 
970
- // src/request-context/index.ts
971
- var RequestContext = class {
972
- registry = /* @__PURE__ */ new Map();
973
- constructor(iterable) {
974
- this.registry = new Map(iterable);
975
- }
976
- /**
977
- * set a value with strict typing if `Values` is a Record and the key exists in it.
978
- */
979
- set(key, value) {
980
- this.registry.set(key, value);
981
- }
982
- /**
983
- * Get a value with its type
984
- */
985
- get(key) {
986
- return this.registry.get(key);
987
- }
988
- /**
989
- * Check if a key exists in the container
990
- */
991
- has(key) {
992
- return this.registry.has(key);
993
- }
994
- /**
995
- * Delete a value by key
996
- */
997
- delete(key) {
998
- return this.registry.delete(key);
999
- }
1000
- /**
1001
- * Clear all values from the container
1002
- */
1003
- clear() {
1004
- this.registry.clear();
1005
- }
1006
- /**
1007
- * Get all keys in the container
1008
- */
1009
- keys() {
1010
- return this.registry.keys();
1011
- }
1012
- /**
1013
- * Get all values in the container
1014
- */
1015
- values() {
1016
- return this.registry.values();
1017
- }
1018
- /**
1019
- * Get all entries in the container.
1020
- * Returns a discriminated union of tuples for proper type narrowing when iterating.
1021
- */
1022
- entries() {
1023
- return this.registry.entries();
1024
- }
1025
- /**
1026
- * Get the size of the container
1027
- */
1028
- size() {
1029
- return this.registry.size;
1030
- }
1031
- /**
1032
- * Execute a function for each entry in the container.
1033
- * The callback receives properly typed key-value pairs.
1034
- */
1035
- forEach(callbackfn) {
1036
- this.registry.forEach(callbackfn);
1037
- }
1038
- /**
1039
- * Custom JSON serialization method.
1040
- * Converts the internal Map to a plain object for proper JSON serialization.
1041
- * Non-serializable values (e.g., RPC proxies, functions, circular references)
1042
- * are skipped to prevent serialization errors when storing to database.
1043
- */
1044
- toJSON() {
1045
- const result = {};
1046
- for (const [key, value] of this.registry.entries()) {
1047
- if (this.isSerializable(value)) {
1048
- result[key] = value;
1049
- }
1050
- }
1051
- return result;
1052
- }
1053
- /**
1054
- * Check if a value can be safely serialized to JSON.
1055
- */
1056
- isSerializable(value) {
1057
- if (value === null || value === void 0) return true;
1058
- if (typeof value === "function") return false;
1059
- if (typeof value === "symbol") return false;
1060
- if (typeof value !== "object") return true;
1061
- try {
1062
- JSON.stringify(value);
1063
- return true;
1064
- } catch {
1065
- return false;
1066
- }
1067
- }
1068
- /**
1069
- * Get all values as a typed object for destructuring.
1070
- * Returns Record<string, any> when untyped, or the Values type when typed.
1071
- *
1072
- * @example
1073
- * ```typescript
1074
- * const ctx = new RequestContext<{ userId: string; apiKey: string }>();
1075
- * ctx.set('userId', 'user-123');
1076
- * ctx.set('apiKey', 'key-456');
1077
- * const { userId, apiKey } = ctx.all;
1078
- * ```
1079
- */
1080
- get all() {
1081
- return Object.fromEntries(this.registry);
1082
- }
1083
- };
1084
-
1085
- function getDefaultExportFromCjs (x) {
1086
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
1087
- }
1088
-
1089
989
  var __create$4 = Object.create;
1090
990
  var __defProp$6 = Object.defineProperty;
1091
991
  var __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor;
@@ -3269,8 +3169,8 @@ var require_get_vercel_oidc_token = __commonJS$3({
3269
3169
  }
3270
3170
  try {
3271
3171
  const [{ getTokenPayload, isExpired }, { refreshToken }] = await Promise.all([
3272
- await Promise.resolve().then(() => require('./token-util-NEHG7TUY-U7CX7GS4-CwzYo-I6.cjs')),
3273
- await Promise.resolve().then(() => require('./token-6GSAFR2W-XRCSVUPZ-CxcM_lpA.cjs'))
3172
+ await Promise.resolve().then(() => require('./token-util-NEHG7TUY-U7CX7GS4-D1wA3Puq.cjs')),
3173
+ await Promise.resolve().then(() => require('./token-6GSAFR2W-XRCSVUPZ-B7ZkFki_.cjs'))
3274
3174
  ]);
3275
3175
  if (!token || isExpired(getTokenPayload(token))) {
3276
3176
  await refreshToken();
@@ -5866,6 +5766,125 @@ var MastraBaseError = class extends Error {
5866
5766
  var MastraError = class extends MastraBaseError {
5867
5767
  };
5868
5768
 
5769
+ // src/request-context/index.ts
5770
+ var RequestContext = class {
5771
+ registry = /* @__PURE__ */ new Map();
5772
+ constructor(iterable) {
5773
+ this.registry = new Map(iterable);
5774
+ }
5775
+ /**
5776
+ * set a value with strict typing if `Values` is a Record and the key exists in it.
5777
+ */
5778
+ set(key, value) {
5779
+ this.registry.set(key, value);
5780
+ }
5781
+ /**
5782
+ * Get a value with its type
5783
+ */
5784
+ get(key) {
5785
+ return this.registry.get(key);
5786
+ }
5787
+ /**
5788
+ * Check if a key exists in the container
5789
+ */
5790
+ has(key) {
5791
+ return this.registry.has(key);
5792
+ }
5793
+ /**
5794
+ * Delete a value by key
5795
+ */
5796
+ delete(key) {
5797
+ return this.registry.delete(key);
5798
+ }
5799
+ /**
5800
+ * Clear all values from the container
5801
+ */
5802
+ clear() {
5803
+ this.registry.clear();
5804
+ }
5805
+ /**
5806
+ * Get all keys in the container
5807
+ */
5808
+ keys() {
5809
+ return this.registry.keys();
5810
+ }
5811
+ /**
5812
+ * Get all values in the container
5813
+ */
5814
+ values() {
5815
+ return this.registry.values();
5816
+ }
5817
+ /**
5818
+ * Get all entries in the container.
5819
+ * Returns a discriminated union of tuples for proper type narrowing when iterating.
5820
+ */
5821
+ entries() {
5822
+ return this.registry.entries();
5823
+ }
5824
+ /**
5825
+ * Get the size of the container
5826
+ */
5827
+ size() {
5828
+ return this.registry.size;
5829
+ }
5830
+ /**
5831
+ * Execute a function for each entry in the container.
5832
+ * The callback receives properly typed key-value pairs.
5833
+ */
5834
+ forEach(callbackfn) {
5835
+ this.registry.forEach(callbackfn);
5836
+ }
5837
+ /**
5838
+ * Custom JSON serialization method.
5839
+ * Converts the internal Map to a plain object for proper JSON serialization.
5840
+ * Non-serializable values (e.g., RPC proxies, functions, circular references)
5841
+ * are skipped to prevent serialization errors when storing to database.
5842
+ */
5843
+ toJSON() {
5844
+ const result = {};
5845
+ for (const [key, value] of this.registry.entries()) {
5846
+ if (this.isSerializable(value)) {
5847
+ result[key] = value;
5848
+ }
5849
+ }
5850
+ return result;
5851
+ }
5852
+ /**
5853
+ * Check if a value can be safely serialized to JSON.
5854
+ */
5855
+ isSerializable(value) {
5856
+ if (value === null || value === void 0) return true;
5857
+ if (typeof value === "function") return false;
5858
+ if (typeof value === "symbol") return false;
5859
+ if (typeof value !== "object") return true;
5860
+ try {
5861
+ JSON.stringify(value);
5862
+ return true;
5863
+ } catch {
5864
+ return false;
5865
+ }
5866
+ }
5867
+ /**
5868
+ * Get all values as a typed object for destructuring.
5869
+ * Returns Record<string, any> when untyped, or the Values type when typed.
5870
+ *
5871
+ * @example
5872
+ * ```typescript
5873
+ * const ctx = new RequestContext<{ userId: string; apiKey: string }>();
5874
+ * ctx.set('userId', 'user-123');
5875
+ * ctx.set('apiKey', 'key-456');
5876
+ * const { userId, apiKey } = ctx.all;
5877
+ * ```
5878
+ */
5879
+ get all() {
5880
+ return Object.fromEntries(this.registry);
5881
+ }
5882
+ };
5883
+
5884
+ function getDefaultExportFromCjs (x) {
5885
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
5886
+ }
5887
+
5869
5888
  // ../_vendored/ai_v4/dist/chunk-OPIPXJLE.js
5870
5889
  var __create$2 = Object.create;
5871
5890
  var __defProp$3 = Object.defineProperty;
@@ -10207,6 +10226,16 @@ function findToolCallArgs(messages, toolCallId) {
10207
10226
  function filterDataParts(parts) {
10208
10227
  return parts.filter((part) => !part.type.startsWith("data-"));
10209
10228
  }
10229
+ function filterEmptyTextParts(parts) {
10230
+ const hasNonEmptyParts = parts.some((part) => !(part.type === "text" && part.text === ""));
10231
+ if (!hasNonEmptyParts) return parts;
10232
+ return parts.filter((part) => {
10233
+ if (part.type === "text") {
10234
+ return part.text !== "";
10235
+ }
10236
+ return true;
10237
+ });
10238
+ }
10210
10239
  var AIV4Adapter = class {
10211
10240
  /**
10212
10241
  * Convert MastraDBMessage to AI SDK V4 UIMessage
@@ -10342,9 +10371,10 @@ var AIV4Adapter = class {
10342
10371
  * Convert AI SDK V4 UIMessage to MastraDBMessage
10343
10372
  */
10344
10373
  static fromUIMessage(message, ctx, messageSource) {
10374
+ const filteredParts = message.parts ? filterEmptyTextParts(message.parts) : [];
10345
10375
  const content = {
10346
10376
  format: 2,
10347
- parts: message.parts
10377
+ parts: filteredParts
10348
10378
  };
10349
10379
  if (message.toolInvocations) content.toolInvocations = message.toolInvocations;
10350
10380
  if (message.reasoning) content.reasoning = message.reasoning;
@@ -10541,9 +10571,10 @@ var AIV4Adapter = class {
10541
10571
  }
10542
10572
  }
10543
10573
  }
10574
+ const filteredParts = filterEmptyTextParts(parts);
10544
10575
  const content = {
10545
10576
  format: 2,
10546
- parts
10577
+ parts: filteredParts
10547
10578
  };
10548
10579
  if (toolInvocations.length) content.toolInvocations = toolInvocations;
10549
10580
  if (typeof coreMessage.content === `string`) content.content = coreMessage.content;
@@ -10569,6 +10600,16 @@ var AIV4Adapter = class {
10569
10600
  };
10570
10601
 
10571
10602
  // src/agent/message-list/adapters/AIV5Adapter.ts
10603
+ function filterEmptyTextParts2(parts) {
10604
+ const hasNonEmptyParts = parts.some((part) => !(part.type === "text" && part.text === ""));
10605
+ if (!hasNonEmptyParts) return parts;
10606
+ return parts.filter((part) => {
10607
+ if (part.type === "text") {
10608
+ return part.text !== "";
10609
+ }
10610
+ return true;
10611
+ });
10612
+ }
10572
10613
  function getToolName(type) {
10573
10614
  if (typeof type === "object" && type && "type" in type) {
10574
10615
  type = type.type;
@@ -10901,6 +10942,7 @@ var AIV5Adapter = class {
10901
10942
  }
10902
10943
  return null;
10903
10944
  }).filter((p) => p !== null);
10945
+ const filteredV2Parts = filterEmptyTextParts2(v2Parts);
10904
10946
  return {
10905
10947
  id: uiMsg.id,
10906
10948
  role: uiMsg.role,
@@ -10909,7 +10951,7 @@ var AIV5Adapter = class {
10909
10951
  resourceId,
10910
10952
  content: {
10911
10953
  format: 2,
10912
- parts: v2Parts,
10954
+ parts: filteredV2Parts,
10913
10955
  toolInvocations,
10914
10956
  reasoning,
10915
10957
  experimental_attachments,
@@ -10969,7 +11011,6 @@ var AIV5Adapter = class {
10969
11011
  const toolInvocations = [];
10970
11012
  const reasoningParts = [];
10971
11013
  const experimental_attachments = [];
10972
- let lastPartWasToolResult = false;
10973
11014
  for (const part of content) {
10974
11015
  if (part.type === "text") {
10975
11016
  const textPart = {
@@ -10980,7 +11021,6 @@ var AIV5Adapter = class {
10980
11021
  textPart.providerMetadata = part.providerOptions;
10981
11022
  }
10982
11023
  mastraDBParts.push(textPart);
10983
- lastPartWasToolResult = false;
10984
11024
  } else if (part.type === "tool-call") {
10985
11025
  const toolCallPart = part;
10986
11026
  const toolInvocationPart = {
@@ -11002,7 +11042,6 @@ var AIV5Adapter = class {
11002
11042
  args: toolCallPart.input,
11003
11043
  state: "call"
11004
11044
  });
11005
- lastPartWasToolResult = false;
11006
11045
  } else if (part.type === "tool-result") {
11007
11046
  const toolResultPart = part;
11008
11047
  const matchingCall = toolInvocations.find((inv) => inv.toolCallId === toolResultPart.toolCallId);
@@ -11040,7 +11079,6 @@ var AIV5Adapter = class {
11040
11079
  updateMatchingCallInvocationResult(toolResultPart, toolInvocationPart.toolInvocation);
11041
11080
  mastraDBParts.push(toolInvocationPart);
11042
11081
  }
11043
- lastPartWasToolResult = true;
11044
11082
  } else if (part.type === "reasoning") {
11045
11083
  const v2ReasoningPart = {
11046
11084
  type: "reasoning",
@@ -11052,7 +11090,6 @@ var AIV5Adapter = class {
11052
11090
  }
11053
11091
  mastraDBParts.push(v2ReasoningPart);
11054
11092
  reasoningParts.push(part.text);
11055
- lastPartWasToolResult = false;
11056
11093
  } else if (part.type === "image") {
11057
11094
  const imagePart = part;
11058
11095
  const mimeType = imagePart.mediaType || "image/jpeg";
@@ -11070,7 +11107,6 @@ var AIV5Adapter = class {
11070
11107
  url: imageData,
11071
11108
  contentType: mimeType
11072
11109
  });
11073
- lastPartWasToolResult = false;
11074
11110
  } else if (part.type === "file") {
11075
11111
  const filePart = part;
11076
11112
  const mimeType = filePart.mediaType || "application/octet-stream";
@@ -11088,17 +11124,10 @@ var AIV5Adapter = class {
11088
11124
  url: fileData,
11089
11125
  contentType: mimeType
11090
11126
  });
11091
- lastPartWasToolResult = false;
11092
11127
  }
11093
11128
  }
11094
- if (modelMsg.role === "assistant" && lastPartWasToolResult && mastraDBParts.length > 0) {
11095
- const lastPart = mastraDBParts[mastraDBParts.length - 1];
11096
- if (lastPart && lastPart.type !== "text") {
11097
- const emptyTextPart = { type: "text", text: "" };
11098
- mastraDBParts.push(emptyTextPart);
11099
- }
11100
- }
11101
- const contentString = mastraDBParts.filter((p) => p.type === "text").map((p) => p.text).join("\n");
11129
+ const filteredMastraDBParts = filterEmptyTextParts2(mastraDBParts);
11130
+ const contentString = filteredMastraDBParts.filter((p) => p.type === "text").map((p) => p.text).join("\n");
11102
11131
  const metadata = "metadata" in modelMsg && modelMsg.metadata !== null && modelMsg.metadata !== void 0 ? modelMsg.metadata : {};
11103
11132
  const id = `id` in modelMsg && typeof modelMsg.id === `string` ? modelMsg.id : `msg-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
11104
11133
  const message = {
@@ -11107,7 +11136,7 @@ var AIV5Adapter = class {
11107
11136
  createdAt: /* @__PURE__ */ new Date(),
11108
11137
  content: {
11109
11138
  format: 2,
11110
- parts: mastraDBParts,
11139
+ parts: filteredMastraDBParts,
11111
11140
  toolInvocations: toolInvocations.length > 0 ? toolInvocations : void 0,
11112
11141
  reasoning: reasoningParts.length > 0 ? reasoningParts.join("\n") : void 0,
11113
11142
  experimental_attachments: experimental_attachments.length > 0 ? experimental_attachments : void 0,
@@ -11666,6 +11695,12 @@ function sanitizeV5UIMessages(messages, filterIncompleteToolCalls = false) {
11666
11695
  if (typeof p.type === "string" && p.type.startsWith("data-")) {
11667
11696
  return false;
11668
11697
  }
11698
+ if (p.type === "text" && (!("text" in p) || p.text === "" || p.text?.trim() === "")) {
11699
+ const hasNonEmptyParts = m.parts.some(
11700
+ (part) => !(part.type === "text" && (!("text" in part) || part.text === "" || part.text?.trim() === ""))
11701
+ );
11702
+ if (hasNonEmptyParts) return false;
11703
+ }
11669
11704
  if (!isToolUIPart(p)) return true;
11670
11705
  if (filterIncompleteToolCalls) {
11671
11706
  return p.state === "output-available" || p.state === "output-error";
@@ -27751,4 +27786,4 @@ exports.useCreateWorkflowRun = useCreateWorkflowRun;
27751
27786
  exports.useEntity = useEntity;
27752
27787
  exports.useMastraClient = useMastraClient;
27753
27788
  exports.useStreamWorkflow = useStreamWorkflow;
27754
- //# sourceMappingURL=index-DUTv-1fm.cjs.map
27789
+ //# sourceMappingURL=index-kMIXwQyE.cjs.map