@mastra/core 1.0.0-beta.3 → 1.0.0-beta.4

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 (146) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/dist/agent/index.cjs +9 -9
  3. package/dist/agent/index.js +2 -2
  4. package/dist/agent/message-list/index.cjs +3 -3
  5. package/dist/agent/message-list/index.d.ts +5 -0
  6. package/dist/agent/message-list/index.d.ts.map +1 -1
  7. package/dist/agent/message-list/index.js +1 -1
  8. package/dist/{chunk-OWX2PUFH.cjs → chunk-2NVBZKZI.cjs} +161 -129
  9. package/dist/chunk-2NVBZKZI.cjs.map +1 -0
  10. package/dist/{chunk-OQF4H5Y2.js → chunk-2OTDXX73.js} +4 -4
  11. package/dist/{chunk-OQF4H5Y2.js.map → chunk-2OTDXX73.js.map} +1 -1
  12. package/dist/{chunk-4DWZ4Z6H.js → chunk-3RW5EMSB.js} +3 -4
  13. package/dist/chunk-3RW5EMSB.js.map +1 -0
  14. package/dist/{chunk-N4SJ4YX7.cjs → chunk-3W5RQCCY.cjs} +40 -24
  15. package/dist/chunk-3W5RQCCY.cjs.map +1 -0
  16. package/dist/{chunk-XRIVPHXV.cjs → chunk-4RXG622P.cjs} +5 -5
  17. package/dist/{chunk-XRIVPHXV.cjs.map → chunk-4RXG622P.cjs.map} +1 -1
  18. package/dist/{chunk-VZGBVYXA.cjs → chunk-5WXEYDFI.cjs} +22 -23
  19. package/dist/chunk-5WXEYDFI.cjs.map +1 -0
  20. package/dist/{chunk-EZVRSZMK.cjs → chunk-CYVNOIXS.cjs} +11 -11
  21. package/dist/{chunk-EZVRSZMK.cjs.map → chunk-CYVNOIXS.cjs.map} +1 -1
  22. package/dist/{chunk-MCUX2D5Q.js → chunk-FVNT7VTO.js} +29 -13
  23. package/dist/chunk-FVNT7VTO.js.map +1 -0
  24. package/dist/{chunk-T3WZCEC4.js → chunk-IHJDOC3A.js} +34 -587
  25. package/dist/chunk-IHJDOC3A.js.map +1 -0
  26. package/dist/{chunk-QUKUN6NR.cjs → chunk-ISMGVGUM.cjs} +105 -5
  27. package/dist/chunk-ISMGVGUM.cjs.map +1 -0
  28. package/dist/{chunk-4RSHBKDJ.cjs → chunk-IWB65P37.cjs} +5 -5
  29. package/dist/{chunk-4RSHBKDJ.cjs.map → chunk-IWB65P37.cjs.map} +1 -1
  30. package/dist/{chunk-5CWWU22H.js → chunk-IWQDBVJK.js} +3 -3
  31. package/dist/{chunk-5CWWU22H.js.map → chunk-IWQDBVJK.js.map} +1 -1
  32. package/dist/{chunk-KOSW5PP5.js → chunk-MDKPL2R2.js} +464 -124
  33. package/dist/chunk-MDKPL2R2.js.map +1 -0
  34. package/dist/{chunk-UIZSWUKP.js → chunk-NZAXAFI3.js} +104 -6
  35. package/dist/chunk-NZAXAFI3.js.map +1 -0
  36. package/dist/{chunk-GRGPQ32U.js → chunk-RXDJL5QT.js} +3 -3
  37. package/dist/{chunk-GRGPQ32U.js.map → chunk-RXDJL5QT.js.map} +1 -1
  38. package/dist/{chunk-YQ7NLZZ3.cjs → chunk-S6OEQHEI.cjs} +61 -614
  39. package/dist/chunk-S6OEQHEI.cjs.map +1 -0
  40. package/dist/{chunk-G3OOCXAI.js → chunk-U7VECK2G.js} +4 -4
  41. package/dist/{chunk-G3OOCXAI.js.map → chunk-U7VECK2G.js.map} +1 -1
  42. package/dist/{chunk-G36A2JRR.cjs → chunk-VSM3NLUX.cjs} +296 -199
  43. package/dist/chunk-VSM3NLUX.cjs.map +1 -0
  44. package/dist/{chunk-3VOUB4ZU.cjs → chunk-VZC4BWWH.cjs} +8 -8
  45. package/dist/{chunk-3VOUB4ZU.cjs.map → chunk-VZC4BWWH.cjs.map} +1 -1
  46. package/dist/{chunk-BAMR7HKO.js → chunk-W3DD3XP5.js} +296 -199
  47. package/dist/chunk-W3DD3XP5.js.map +1 -0
  48. package/dist/{chunk-JTXVR2RA.cjs → chunk-WQSGX6XA.cjs} +5 -5
  49. package/dist/{chunk-JTXVR2RA.cjs.map → chunk-WQSGX6XA.cjs.map} +1 -1
  50. package/dist/{chunk-VU6DVS7J.js → chunk-WTYNK7Q4.js} +4 -4
  51. package/dist/{chunk-VU6DVS7J.js.map → chunk-WTYNK7Q4.js.map} +1 -1
  52. package/dist/{chunk-CKGIPST2.js → chunk-XXBWX7DT.js} +138 -106
  53. package/dist/chunk-XXBWX7DT.js.map +1 -0
  54. package/dist/{chunk-ZPMFINU2.cjs → chunk-ZCVTH3CH.cjs} +464 -130
  55. package/dist/chunk-ZCVTH3CH.cjs.map +1 -0
  56. package/dist/evals/index.cjs +4 -4
  57. package/dist/evals/index.js +1 -1
  58. package/dist/evals/scoreTraces/index.cjs +3 -3
  59. package/dist/evals/scoreTraces/index.js +1 -1
  60. package/dist/index.cjs +2 -2
  61. package/dist/index.js +1 -1
  62. package/dist/llm/index.cjs +14 -14
  63. package/dist/llm/index.js +5 -5
  64. package/dist/llm/model/aisdk/v5/model.d.ts.map +1 -1
  65. package/dist/loop/index.cjs +2 -2
  66. package/dist/loop/index.js +1 -1
  67. package/dist/loop/test-utils/generateText.d.ts.map +1 -1
  68. package/dist/loop/test-utils/resultObject.d.ts.map +1 -1
  69. package/dist/loop/test-utils/toUIMessageStream.d.ts.map +1 -1
  70. package/dist/loop/test-utils/utils.d.ts.map +1 -1
  71. package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts.map +1 -1
  72. package/dist/loop/workflows/agentic-execution/llm-mapping-step.d.ts.map +1 -1
  73. package/dist/mastra/index.cjs +2 -2
  74. package/dist/mastra/index.js +1 -1
  75. package/dist/memory/index.cjs +6 -6
  76. package/dist/memory/index.js +3 -3
  77. package/dist/models-dev-6PRLJKVZ.js +3 -0
  78. package/dist/{models-dev-GCVENVWA.js.map → models-dev-6PRLJKVZ.js.map} +1 -1
  79. package/dist/models-dev-WHMI5G6Y.cjs +12 -0
  80. package/dist/{models-dev-TIBJR6IG.cjs.map → models-dev-WHMI5G6Y.cjs.map} +1 -1
  81. package/dist/netlify-46I3SNNV.cjs +12 -0
  82. package/dist/{netlify-NTSNNT6F.cjs.map → netlify-46I3SNNV.cjs.map} +1 -1
  83. package/dist/netlify-EBQ6YUC6.js +3 -0
  84. package/dist/{netlify-O5NJW7CF.js.map → netlify-EBQ6YUC6.js.map} +1 -1
  85. package/dist/processors/index.cjs +11 -11
  86. package/dist/processors/index.js +1 -1
  87. package/dist/provider-registry-HDG6UMUC.js +3 -0
  88. package/dist/{provider-registry-74GMFZKT.js.map → provider-registry-HDG6UMUC.js.map} +1 -1
  89. package/dist/provider-registry-RP2W4B24.cjs +40 -0
  90. package/dist/{provider-registry-BZP3DIIV.cjs.map → provider-registry-RP2W4B24.cjs.map} +1 -1
  91. package/dist/relevance/index.cjs +2 -2
  92. package/dist/relevance/index.js +1 -1
  93. package/dist/server/auth.d.ts +11 -0
  94. package/dist/server/auth.d.ts.map +1 -1
  95. package/dist/server/index.cjs +10 -0
  96. package/dist/server/index.cjs.map +1 -1
  97. package/dist/server/index.js +10 -0
  98. package/dist/server/index.js.map +1 -1
  99. package/dist/storage/index.cjs +29 -29
  100. package/dist/storage/index.js +1 -1
  101. package/dist/stream/aisdk/v5/compat/prepare-tools.d.ts.map +1 -1
  102. package/dist/stream/index.cjs +11 -11
  103. package/dist/stream/index.js +2 -2
  104. package/dist/test-utils/llm-mock.cjs +66 -29
  105. package/dist/test-utils/llm-mock.cjs.map +1 -1
  106. package/dist/test-utils/llm-mock.d.ts +4 -2
  107. package/dist/test-utils/llm-mock.d.ts.map +1 -1
  108. package/dist/test-utils/llm-mock.js +66 -29
  109. package/dist/test-utils/llm-mock.js.map +1 -1
  110. package/dist/voice/aisdk/index.d.ts +3 -0
  111. package/dist/voice/aisdk/index.d.ts.map +1 -0
  112. package/dist/voice/aisdk/speech.d.ts +23 -0
  113. package/dist/voice/aisdk/speech.d.ts.map +1 -0
  114. package/dist/voice/aisdk/transcription.d.ts +22 -0
  115. package/dist/voice/aisdk/transcription.d.ts.map +1 -0
  116. package/dist/voice/composite-voice.d.ts +4 -3
  117. package/dist/voice/composite-voice.d.ts.map +1 -1
  118. package/dist/voice/index.cjs +12 -4
  119. package/dist/voice/index.d.ts +1 -0
  120. package/dist/voice/index.d.ts.map +1 -1
  121. package/dist/voice/index.js +1 -1
  122. package/dist/workflows/evented/index.cjs +10 -10
  123. package/dist/workflows/evented/index.js +1 -1
  124. package/dist/workflows/index.cjs +19 -19
  125. package/dist/workflows/index.js +1 -1
  126. package/package.json +10 -10
  127. package/dist/chunk-4DWZ4Z6H.js.map +0 -1
  128. package/dist/chunk-BAMR7HKO.js.map +0 -1
  129. package/dist/chunk-CKGIPST2.js.map +0 -1
  130. package/dist/chunk-G36A2JRR.cjs.map +0 -1
  131. package/dist/chunk-KOSW5PP5.js.map +0 -1
  132. package/dist/chunk-MCUX2D5Q.js.map +0 -1
  133. package/dist/chunk-N4SJ4YX7.cjs.map +0 -1
  134. package/dist/chunk-OWX2PUFH.cjs.map +0 -1
  135. package/dist/chunk-QUKUN6NR.cjs.map +0 -1
  136. package/dist/chunk-T3WZCEC4.js.map +0 -1
  137. package/dist/chunk-UIZSWUKP.js.map +0 -1
  138. package/dist/chunk-VZGBVYXA.cjs.map +0 -1
  139. package/dist/chunk-YQ7NLZZ3.cjs.map +0 -1
  140. package/dist/chunk-ZPMFINU2.cjs.map +0 -1
  141. package/dist/models-dev-GCVENVWA.js +0 -3
  142. package/dist/models-dev-TIBJR6IG.cjs +0 -12
  143. package/dist/netlify-NTSNNT6F.cjs +0 -12
  144. package/dist/netlify-O5NJW7CF.js +0 -3
  145. package/dist/provider-registry-74GMFZKT.js +0 -3
  146. package/dist/provider-registry-BZP3DIIV.cjs +0 -40
@@ -1858,6 +1858,12 @@ var MessageList = class _MessageList {
1858
1858
  return ti;
1859
1859
  });
1860
1860
  }
1861
+ if (!message.threadId && this.memoryInfo?.threadId) {
1862
+ message.threadId = this.memoryInfo.threadId;
1863
+ if (!message.resourceId && this.memoryInfo?.resourceId) {
1864
+ message.resourceId = this.memoryInfo.resourceId;
1865
+ }
1866
+ }
1861
1867
  return message;
1862
1868
  }
1863
1869
  aiV4UIMessageToMastraDBMessage(message, messageSource) {
@@ -1895,137 +1901,180 @@ var MessageList = class _MessageList {
1895
1901
  if (typeof coreMessage.content === "string") {
1896
1902
  parts.push({
1897
1903
  type: "text",
1898
- text: coreMessage.content,
1899
- // Preserve providerOptions from CoreMessage (e.g., for system messages with cacheControl)
1900
- ..."providerOptions" in coreMessage && coreMessage.providerOptions ? { providerMetadata: coreMessage.providerOptions } : {}
1904
+ text: coreMessage.content
1901
1905
  });
1902
1906
  } else if (Array.isArray(coreMessage.content)) {
1903
- for (const part of coreMessage.content) {
1904
- switch (part.type) {
1905
- case "text":
1907
+ for (const aiV4Part of coreMessage.content) {
1908
+ switch (aiV4Part.type) {
1909
+ case "text": {
1906
1910
  const prevPart = parts.at(-1);
1907
1911
  if (coreMessage.role === "assistant" && prevPart && prevPart.type === "tool-invocation") {
1908
1912
  parts.push({ type: "step-start" });
1909
1913
  }
1910
- const mergedProviderMetadata = {
1911
- ..."providerOptions" in coreMessage && coreMessage.providerOptions ? coreMessage.providerOptions : {},
1912
- ..."providerOptions" in part && part.providerOptions ? part.providerOptions : {}
1913
- };
1914
- parts.push({
1914
+ const part = {
1915
1915
  type: "text",
1916
- text: part.text,
1917
- ...Object.keys(mergedProviderMetadata).length > 0 ? { providerMetadata: mergedProviderMetadata } : {}
1918
- });
1916
+ text: aiV4Part.text
1917
+ };
1918
+ if (aiV4Part.providerOptions) {
1919
+ part.providerMetadata = aiV4Part.providerOptions;
1920
+ }
1921
+ parts.push(part);
1919
1922
  break;
1920
- case "tool-call":
1921
- parts.push({
1923
+ }
1924
+ case "tool-call": {
1925
+ const part = {
1922
1926
  type: "tool-invocation",
1923
1927
  toolInvocation: {
1924
1928
  state: "call",
1925
- toolCallId: part.toolCallId,
1926
- toolName: part.toolName,
1927
- args: part.args
1929
+ toolCallId: aiV4Part.toolCallId,
1930
+ toolName: aiV4Part.toolName,
1931
+ args: aiV4Part.args
1928
1932
  }
1929
- });
1933
+ };
1934
+ if (aiV4Part.providerOptions) {
1935
+ part.providerMetadata = aiV4Part.providerOptions;
1936
+ }
1937
+ parts.push(part);
1930
1938
  break;
1939
+ }
1931
1940
  case "tool-result":
1932
- let toolArgs = {};
1933
- const toolCallInSameMsg = coreMessage.content.find(
1934
- (p) => p.type === "tool-call" && p.toolCallId === part.toolCallId
1935
- );
1936
- if (toolCallInSameMsg && toolCallInSameMsg.type === "tool-call") {
1937
- toolArgs = toolCallInSameMsg.args;
1938
- }
1939
- if (Object.keys(toolArgs).length === 0) {
1940
- for (let i = this.messages.length - 1; i >= 0; i--) {
1941
- const msg = this.messages[i];
1942
- if (msg && msg.role === "assistant" && msg.content.parts) {
1943
- const toolCallPart = msg.content.parts.find(
1944
- (p) => p.type === "tool-invocation" && p.toolInvocation.toolCallId === part.toolCallId && p.toolInvocation.state === "call"
1945
- );
1946
- if (toolCallPart && toolCallPart.type === "tool-invocation" && toolCallPart.toolInvocation.args) {
1947
- toolArgs = toolCallPart.toolInvocation.args;
1948
- break;
1941
+ {
1942
+ let toolArgs = {};
1943
+ const toolCallInSameMsg = coreMessage.content.find(
1944
+ (p) => p.type === "tool-call" && p.toolCallId === aiV4Part.toolCallId
1945
+ );
1946
+ if (toolCallInSameMsg && toolCallInSameMsg.type === "tool-call") {
1947
+ toolArgs = toolCallInSameMsg.args;
1948
+ }
1949
+ if (Object.keys(toolArgs).length === 0) {
1950
+ for (let i = this.messages.length - 1; i >= 0; i--) {
1951
+ const msg = this.messages[i];
1952
+ if (msg && msg.role === "assistant" && msg.content.parts) {
1953
+ const toolCallPart = msg.content.parts.find(
1954
+ (p) => p.type === "tool-invocation" && p.toolInvocation.toolCallId === aiV4Part.toolCallId && p.toolInvocation.state === "call"
1955
+ );
1956
+ if (toolCallPart && toolCallPart.type === "tool-invocation" && toolCallPart.toolInvocation.args) {
1957
+ toolArgs = toolCallPart.toolInvocation.args;
1958
+ break;
1959
+ }
1949
1960
  }
1950
1961
  }
1951
1962
  }
1963
+ const invocation = {
1964
+ state: "result",
1965
+ toolCallId: aiV4Part.toolCallId,
1966
+ toolName: aiV4Part.toolName,
1967
+ result: aiV4Part.result ?? "",
1968
+ // undefined will cause AI SDK to throw an error, but for client side tool calls this really could be undefined
1969
+ args: toolArgs
1970
+ // Use the args from the corresponding tool-call
1971
+ };
1972
+ const part = {
1973
+ type: "tool-invocation",
1974
+ toolInvocation: invocation
1975
+ };
1976
+ if (aiV4Part.providerOptions) {
1977
+ part.providerMetadata = aiV4Part.providerOptions;
1978
+ }
1979
+ parts.push(part);
1980
+ toolInvocations.push(invocation);
1952
1981
  }
1953
- const invocation = {
1954
- state: "result",
1955
- toolCallId: part.toolCallId,
1956
- toolName: part.toolName,
1957
- result: part.result ?? "",
1958
- // undefined will cause AI SDK to throw an error, but for client side tool calls this really could be undefined
1959
- args: toolArgs
1960
- // Use the args from the corresponding tool-call
1961
- };
1962
- parts.push({
1963
- type: "tool-invocation",
1964
- toolInvocation: invocation
1965
- });
1966
- toolInvocations.push(invocation);
1967
1982
  break;
1968
1983
  case "reasoning":
1969
- parts.push({
1970
- type: "reasoning",
1971
- reasoning: "",
1972
- // leave this blank so we aren't double storing it in the db along with details
1973
- details: [{ type: "text", text: part.text, signature: part.signature }]
1974
- });
1984
+ {
1985
+ const part = {
1986
+ type: "reasoning",
1987
+ reasoning: "",
1988
+ // leave this blank so we aren't double storing it in the db along with details
1989
+ details: [{ type: "text", text: aiV4Part.text, signature: aiV4Part.signature }]
1990
+ };
1991
+ if (aiV4Part.providerOptions) {
1992
+ part.providerMetadata = aiV4Part.providerOptions;
1993
+ }
1994
+ parts.push(part);
1995
+ }
1975
1996
  break;
1976
1997
  case "redacted-reasoning":
1977
- parts.push({
1978
- type: "reasoning",
1979
- reasoning: "",
1980
- // No text reasoning for redacted parts
1981
- details: [{ type: "redacted", data: part.data }]
1982
- });
1998
+ {
1999
+ const part = {
2000
+ type: "reasoning",
2001
+ reasoning: "",
2002
+ // No text reasoning for redacted parts
2003
+ details: [{ type: "redacted", data: aiV4Part.data }]
2004
+ };
2005
+ if (aiV4Part.providerOptions) {
2006
+ part.providerMetadata = aiV4Part.providerOptions;
2007
+ }
2008
+ parts.push(part);
2009
+ }
1983
2010
  break;
1984
- case "image":
1985
- parts.push({
2011
+ case "image": {
2012
+ const part = {
1986
2013
  type: "file",
1987
- data: imageContentToString(part.image),
1988
- mimeType: part.mimeType
1989
- });
2014
+ data: imageContentToString(aiV4Part.image),
2015
+ mimeType: aiV4Part.mimeType
2016
+ };
2017
+ if (aiV4Part.providerOptions) {
2018
+ part.providerMetadata = aiV4Part.providerOptions;
2019
+ }
2020
+ parts.push(part);
1990
2021
  break;
1991
- case "file":
1992
- if (part.data instanceof URL) {
1993
- parts.push({
2022
+ }
2023
+ case "file": {
2024
+ if (aiV4Part.data instanceof URL) {
2025
+ const part = {
1994
2026
  type: "file",
1995
- data: part.data.toString(),
1996
- mimeType: part.mimeType
1997
- });
1998
- } else if (typeof part.data === "string") {
1999
- const categorized = categorizeFileData(part.data, part.mimeType);
2027
+ data: aiV4Part.data.toString(),
2028
+ mimeType: aiV4Part.mimeType
2029
+ };
2030
+ if (aiV4Part.providerOptions) {
2031
+ part.providerMetadata = aiV4Part.providerOptions;
2032
+ }
2033
+ parts.push(part);
2034
+ } else if (typeof aiV4Part.data === "string") {
2035
+ const categorized = categorizeFileData(aiV4Part.data, aiV4Part.mimeType);
2000
2036
  if (categorized.type === "url" || categorized.type === "dataUri") {
2001
- parts.push({
2037
+ const part = {
2002
2038
  type: "file",
2003
- data: part.data,
2039
+ data: aiV4Part.data,
2004
2040
  mimeType: categorized.mimeType || "image/png"
2005
- });
2041
+ };
2042
+ if (aiV4Part.providerOptions) {
2043
+ part.providerMetadata = aiV4Part.providerOptions;
2044
+ }
2045
+ parts.push(part);
2006
2046
  } else {
2007
2047
  try {
2008
- parts.push({
2048
+ const part = {
2009
2049
  type: "file",
2010
2050
  mimeType: categorized.mimeType || "image/png",
2011
- data: convertDataContentToBase64String(part.data)
2012
- });
2051
+ data: convertDataContentToBase64String(aiV4Part.data)
2052
+ };
2053
+ if (aiV4Part.providerOptions) {
2054
+ part.providerMetadata = aiV4Part.providerOptions;
2055
+ }
2056
+ parts.push(part);
2013
2057
  } catch (error) {
2014
2058
  console.error(`Failed to convert binary data to base64 in CoreMessage file part: ${error}`, error);
2015
2059
  }
2016
2060
  }
2017
2061
  } else {
2018
2062
  try {
2019
- parts.push({
2063
+ const part = {
2020
2064
  type: "file",
2021
- mimeType: part.mimeType,
2022
- data: convertDataContentToBase64String(part.data)
2023
- });
2065
+ mimeType: aiV4Part.mimeType,
2066
+ data: convertDataContentToBase64String(aiV4Part.data)
2067
+ };
2068
+ if (aiV4Part.providerOptions) {
2069
+ part.providerMetadata = aiV4Part.providerOptions;
2070
+ }
2071
+ parts.push(part);
2024
2072
  } catch (error) {
2025
2073
  console.error(`Failed to convert binary data to base64 in CoreMessage file part: ${error}`, error);
2026
2074
  }
2027
2075
  }
2028
2076
  break;
2077
+ }
2029
2078
  }
2030
2079
  }
2031
2080
  }
@@ -2036,6 +2085,9 @@ var MessageList = class _MessageList {
2036
2085
  if (toolInvocations.length) content.toolInvocations = toolInvocations;
2037
2086
  if (typeof coreMessage.content === `string`) content.content = coreMessage.content;
2038
2087
  if (experimentalAttachments.length) content.experimental_attachments = experimentalAttachments;
2088
+ if (coreMessage.providerOptions) {
2089
+ content.providerMetadata = coreMessage.providerOptions;
2090
+ }
2039
2091
  return {
2040
2092
  id,
2041
2093
  role: _MessageList.getRole(coreMessage),
@@ -2386,6 +2438,9 @@ var MessageList = class _MessageList {
2386
2438
  if (dbMsg.createdAt) metadata.createdAt = dbMsg.createdAt;
2387
2439
  if (dbMsg.threadId) metadata.threadId = dbMsg.threadId;
2388
2440
  if (dbMsg.resourceId) metadata.resourceId = dbMsg.resourceId;
2441
+ if (dbMsg.content.providerMetadata) {
2442
+ metadata.providerMetadata = dbMsg.content.providerMetadata;
2443
+ }
2389
2444
  const hasToolInvocationParts = dbMsg.content.parts?.some((p) => p.type === "tool-invocation");
2390
2445
  if (dbMsg.content.toolInvocations && !hasToolInvocationParts) {
2391
2446
  for (const invocation of dbMsg.content.toolInvocations) {
@@ -2452,18 +2507,20 @@ var MessageList = class _MessageList {
2452
2507
  continue;
2453
2508
  }
2454
2509
  if (part.type === "reasoning") {
2455
- const reasoningPart = part;
2456
- const text = reasoningPart.text || reasoningPart.reasoning || (reasoningPart.details?.reduce((p, c) => {
2510
+ const text = part.reasoning || (part.details?.reduce((p, c) => {
2457
2511
  if (c.type === `text` && c.text) return p + c.text;
2458
2512
  return p;
2459
2513
  }, "") ?? "");
2460
- if (text || reasoningPart.details?.length) {
2461
- parts.push({
2514
+ if (text || part.details?.length) {
2515
+ const v5UIPart = {
2462
2516
  type: "reasoning",
2463
2517
  text: text || "",
2464
- state: "done",
2465
- ...part.providerMetadata && { providerMetadata: part.providerMetadata }
2466
- });
2518
+ state: "done"
2519
+ };
2520
+ if (part.providerMetadata) {
2521
+ v5UIPart.providerMetadata = part.providerMetadata;
2522
+ }
2523
+ parts.push(v5UIPart);
2467
2524
  }
2468
2525
  continue;
2469
2526
  }
@@ -2476,12 +2533,15 @@ var MessageList = class _MessageList {
2476
2533
  }
2477
2534
  const categorized = typeof part.data === "string" ? categorizeFileData(part.data, part.mimeType) : { type: "raw", mimeType: part.mimeType};
2478
2535
  if (categorized.type === "url" && typeof part.data === "string") {
2479
- parts.push({
2536
+ const v5UIPart = {
2480
2537
  type: "file",
2481
2538
  url: part.data,
2482
- mediaType: categorized.mimeType || "image/png",
2483
- providerMetadata: part.providerMetadata
2484
- });
2539
+ mediaType: categorized.mimeType || "image/png"
2540
+ };
2541
+ if (part.providerMetadata) {
2542
+ v5UIPart.providerMetadata = part.providerMetadata;
2543
+ }
2544
+ parts.push(v5UIPart);
2485
2545
  } else {
2486
2546
  let filePartData;
2487
2547
  let extractedMimeType = part.mimeType;
@@ -2505,27 +2565,37 @@ var MessageList = class _MessageList {
2505
2565
  } else {
2506
2566
  dataUri = createDataUri(filePartData, finalMimeType);
2507
2567
  }
2508
- parts.push({
2568
+ const v5UIPart = {
2509
2569
  type: "file",
2510
2570
  url: dataUri,
2511
2571
  // Use url field with data URI
2512
- mediaType: finalMimeType,
2513
- providerMetadata: part.providerMetadata
2514
- });
2572
+ mediaType: finalMimeType
2573
+ };
2574
+ if (part.providerMetadata) {
2575
+ v5UIPart.providerMetadata = part.providerMetadata;
2576
+ }
2577
+ parts.push(v5UIPart);
2515
2578
  }
2516
2579
  } else if (part.type === "source") {
2517
- const sourcePart = part;
2518
- parts.push({
2580
+ const v5UIPart = {
2519
2581
  type: "source-url",
2520
- url: sourcePart.source.url,
2521
- ...part.providerMetadata && { providerMetadata: part.providerMetadata }
2522
- });
2582
+ url: part.source.url,
2583
+ sourceId: part.source.id,
2584
+ title: part.source.title
2585
+ };
2586
+ if (part.providerMetadata) {
2587
+ v5UIPart.providerMetadata = part.providerMetadata;
2588
+ }
2589
+ parts.push(v5UIPart);
2523
2590
  } else if (part.type === "text") {
2524
- parts.push({
2591
+ const v5UIPart = {
2525
2592
  type: "text",
2526
- text: part.text,
2527
- ...part.providerMetadata && { providerMetadata: part.providerMetadata }
2528
- });
2593
+ text: part.text
2594
+ };
2595
+ if (part.providerMetadata) {
2596
+ v5UIPart.providerMetadata = part.providerMetadata;
2597
+ }
2598
+ parts.push(v5UIPart);
2529
2599
  hasNonToolReasoningParts = true;
2530
2600
  } else {
2531
2601
  parts.push(part);
@@ -2689,32 +2759,69 @@ var MessageList = class _MessageList {
2689
2759
  }
2690
2760
  };
2691
2761
  }
2762
+ /**
2763
+ * Convert image or file to data URI or URL for V2 file part
2764
+ */
2765
+ static getDataStringFromAIV5DataPart = (part) => {
2766
+ let mimeType;
2767
+ let data;
2768
+ if ("data" in part) {
2769
+ mimeType = part.mediaType || "application/octet-stream";
2770
+ data = part.data;
2771
+ } else if ("image" in part) {
2772
+ mimeType = part.mediaType || "image/jpeg";
2773
+ data = part.image;
2774
+ } else {
2775
+ throw new MastraError({
2776
+ id: "MASTRA_AIV5_DATA_PART_INVALID",
2777
+ domain: "AGENT" /* AGENT */,
2778
+ category: "USER" /* USER */,
2779
+ text: "Invalid AIV5 data part in getDataStringFromAIV5DataPart",
2780
+ details: {
2781
+ part
2782
+ }
2783
+ });
2784
+ }
2785
+ if (data instanceof URL) {
2786
+ return data.toString();
2787
+ } else {
2788
+ if (data instanceof Buffer) {
2789
+ const base64 = data.toString("base64");
2790
+ return `data:${mimeType};base64,${base64}`;
2791
+ } else if (typeof data === "string") {
2792
+ return data.startsWith("data:") || data.startsWith("http") ? data : `data:${mimeType};base64,${data}`;
2793
+ } else if (data instanceof Uint8Array) {
2794
+ const base64 = Buffer.from(data).toString("base64");
2795
+ return `data:${mimeType};base64,${base64}`;
2796
+ } else if (data instanceof ArrayBuffer) {
2797
+ const base64 = Buffer.from(data).toString("base64");
2798
+ return `data:${mimeType};base64,${base64}`;
2799
+ } else {
2800
+ return "";
2801
+ }
2802
+ }
2803
+ };
2692
2804
  /**
2693
2805
  * Direct conversion from AIV5 ModelMessage to MastraDBMessage
2694
2806
  * Combines logic from aiV5ModelMessageToMastraMessageV3 + mastraMessageV3ToV2
2695
2807
  */
2696
2808
  static aiV5ModelMessageToMastraDBMessage(modelMsg, _messageSource) {
2697
2809
  const content = Array.isArray(modelMsg.content) ? modelMsg.content : [{ type: "text", text: modelMsg.content }];
2698
- const v2Parts = [];
2810
+ const mastraDBParts = [];
2699
2811
  const toolInvocations = [];
2700
2812
  const reasoningParts = [];
2701
2813
  const experimental_attachments = [];
2702
- const textParts = [];
2703
2814
  let lastPartWasToolResult = false;
2704
2815
  for (const part of content) {
2705
- const providerMetadata = {
2706
- ...modelMsg.providerMetadata || {},
2707
- ...part.providerMetadata || {}
2708
- };
2709
- const hasProviderMetadata = Object.keys(providerMetadata).length > 0;
2710
2816
  if (part.type === "text") {
2711
2817
  const textPart = {
2712
2818
  type: "text",
2713
- text: part.text,
2714
- ...hasProviderMetadata && { experimental_providerMetadata: providerMetadata }
2819
+ text: part.text
2715
2820
  };
2716
- v2Parts.push(textPart);
2717
- textParts.push({ text: part.text, providerMetadata: hasProviderMetadata ? providerMetadata : void 0 });
2821
+ if (part.providerOptions) {
2822
+ textPart.providerMetadata = part.providerOptions;
2823
+ }
2824
+ mastraDBParts.push(textPart);
2718
2825
  lastPartWasToolResult = false;
2719
2826
  } else if (part.type === "tool-call") {
2720
2827
  const toolCallPart = part;
@@ -2725,10 +2832,12 @@ var MessageList = class _MessageList {
2725
2832
  toolName: toolCallPart.toolName,
2726
2833
  args: toolCallPart.input,
2727
2834
  state: "call"
2728
- },
2729
- ...hasProviderMetadata && { providerMetadata }
2835
+ }
2730
2836
  };
2731
- v2Parts.push(toolInvocationPart);
2837
+ if (part.providerOptions) {
2838
+ toolInvocationPart.providerMetadata = part.providerOptions;
2839
+ }
2840
+ mastraDBParts.push(toolInvocationPart);
2732
2841
  toolInvocations.push({
2733
2842
  toolCallId: toolCallPart.toolCallId,
2734
2843
  toolName: toolCallPart.toolName,
@@ -2739,78 +2848,67 @@ var MessageList = class _MessageList {
2739
2848
  } else if (part.type === "tool-result") {
2740
2849
  const toolResultPart = part;
2741
2850
  const matchingCall = toolInvocations.find((inv) => inv.toolCallId === toolResultPart.toolCallId);
2742
- const matchingV2Part = v2Parts.find(
2851
+ const matchingV2Part = mastraDBParts.find(
2743
2852
  (p) => p.type === "tool-invocation" && "toolInvocation" in p && p.toolInvocation.toolCallId === toolResultPart.toolCallId
2744
2853
  );
2854
+ const updateMatchingCallInvocationResult = (toolResultPart2, matchingCall2) => {
2855
+ matchingCall2.state = "result";
2856
+ matchingCall2.result = typeof toolResultPart2.output === "object" && toolResultPart2.output && "value" in toolResultPart2.output ? toolResultPart2.output.value : toolResultPart2.output;
2857
+ };
2745
2858
  if (matchingCall) {
2746
- matchingCall.state = "result";
2747
- matchingCall.result = typeof toolResultPart.output === "object" && toolResultPart.output && "value" in toolResultPart.output ? toolResultPart.output.value : toolResultPart.output;
2859
+ updateMatchingCallInvocationResult(toolResultPart, matchingCall);
2748
2860
  } else {
2749
- const resultPartWithName = toolResultPart;
2750
- toolInvocations.push({
2861
+ const call = {
2862
+ state: "call",
2751
2863
  toolCallId: toolResultPart.toolCallId,
2752
- toolName: resultPartWithName.toolName || "unknown",
2753
- args: {},
2754
- result: typeof toolResultPart.output === "object" && toolResultPart.output && "value" in toolResultPart.output ? toolResultPart.output.value : toolResultPart.output,
2755
- state: "result"
2756
- });
2864
+ toolName: toolResultPart.toolName || "unknown",
2865
+ args: {}
2866
+ };
2867
+ updateMatchingCallInvocationResult(toolResultPart, call);
2868
+ toolInvocations.push(call);
2757
2869
  }
2758
2870
  if (matchingV2Part && matchingV2Part.type === "tool-invocation") {
2759
- matchingV2Part.toolInvocation.state = "result";
2760
- matchingV2Part.toolInvocation.result = typeof toolResultPart.output === "object" && toolResultPart.output && "value" in toolResultPart.output ? toolResultPart.output.value : toolResultPart.output;
2761
- if (hasProviderMetadata) {
2762
- matchingV2Part.providerMetadata = providerMetadata;
2763
- }
2871
+ updateMatchingCallInvocationResult(toolResultPart, matchingV2Part.toolInvocation);
2764
2872
  } else {
2765
- const resultPartWithName = toolResultPart;
2766
2873
  const toolInvocationPart = {
2767
2874
  type: "tool-invocation",
2768
2875
  toolInvocation: {
2769
2876
  toolCallId: toolResultPart.toolCallId,
2770
- toolName: resultPartWithName.toolName || "unknown",
2877
+ toolName: toolResultPart.toolName || "unknown",
2771
2878
  args: {},
2772
- result: typeof toolResultPart.output === "object" && toolResultPart.output && "value" in toolResultPart.output ? toolResultPart.output.value : toolResultPart.output,
2773
- state: "result"
2774
- },
2775
- ...hasProviderMetadata && { providerMetadata }
2879
+ state: "call"
2880
+ }
2776
2881
  };
2777
- v2Parts.push(toolInvocationPart);
2882
+ updateMatchingCallInvocationResult(toolResultPart, toolInvocationPart.toolInvocation);
2883
+ mastraDBParts.push(toolInvocationPart);
2778
2884
  }
2779
2885
  lastPartWasToolResult = true;
2780
2886
  } else if (part.type === "reasoning") {
2781
- const reasoningPart = part;
2782
2887
  const v2ReasoningPart = {
2783
2888
  type: "reasoning",
2784
- reasoning: reasoningPart.text,
2785
- details: [{ type: "text", text: reasoningPart.text }],
2786
- ...hasProviderMetadata && { providerMetadata }
2889
+ reasoning: "",
2890
+ // leave this blank so we aren't double storing it in the db along with details
2891
+ details: [{ type: "text", text: part.text }]
2787
2892
  };
2788
- v2Parts.push(v2ReasoningPart);
2789
- reasoningParts.push(reasoningPart.text);
2893
+ if (part.providerOptions) {
2894
+ v2ReasoningPart.providerMetadata = part.providerOptions;
2895
+ }
2896
+ mastraDBParts.push(v2ReasoningPart);
2897
+ reasoningParts.push(part.text);
2790
2898
  lastPartWasToolResult = false;
2791
2899
  } else if (part.type === "image") {
2792
2900
  const imagePart = part;
2793
- let imageData;
2794
- const mimeType = imagePart.mimeType || "image/jpeg";
2795
- if ("url" in imagePart && typeof imagePart.url === "string") {
2796
- imageData = imagePart.url;
2797
- } else if ("data" in imagePart) {
2798
- if (typeof imagePart.data === "string") {
2799
- imageData = imagePart.data.startsWith("data:") || imagePart.data.startsWith("http") ? imagePart.data : `data:${mimeType};base64,${imagePart.data}`;
2800
- } else {
2801
- const base64 = Buffer.from(imagePart.data).toString("base64");
2802
- imageData = `data:${mimeType};base64,${base64}`;
2803
- }
2804
- } else {
2805
- imageData = "";
2806
- }
2901
+ const mimeType = imagePart.mediaType || "image/jpeg";
2902
+ const imageData = this.getDataStringFromAIV5DataPart(imagePart);
2807
2903
  const imageFilePart = {
2808
2904
  type: "file",
2809
2905
  data: imageData,
2810
- mimeType,
2811
- ...hasProviderMetadata && { providerMetadata }
2906
+ mimeType
2812
2907
  };
2813
- v2Parts.push(imageFilePart);
2908
+ if (part.providerOptions) {
2909
+ imageFilePart.providerMetadata = part.providerOptions;
2910
+ }
2911
+ mastraDBParts.push(imageFilePart);
2814
2912
  experimental_attachments.push({
2815
2913
  url: imageData,
2816
2914
  contentType: mimeType
@@ -2819,26 +2917,16 @@ var MessageList = class _MessageList {
2819
2917
  } else if (part.type === "file") {
2820
2918
  const filePart = part;
2821
2919
  const mimeType = filePart.mediaType || "application/octet-stream";
2822
- let fileData;
2823
- if ("url" in filePart && typeof filePart.url === "string") {
2824
- fileData = filePart.url;
2825
- } else if ("data" in filePart) {
2826
- if (typeof filePart.data === "string") {
2827
- fileData = filePart.data.startsWith("data:") || filePart.data.startsWith("http") ? filePart.data : `data:${mimeType};base64,${filePart.data}`;
2828
- } else {
2829
- const base64 = Buffer.from(filePart.data).toString("base64");
2830
- fileData = `data:${mimeType};base64,${base64}`;
2831
- }
2832
- } else {
2833
- fileData = "";
2834
- }
2920
+ const fileData = this.getDataStringFromAIV5DataPart(filePart);
2835
2921
  const v2FilePart = {
2836
2922
  type: "file",
2837
2923
  data: fileData,
2838
- mimeType,
2839
- ...hasProviderMetadata && { providerMetadata }
2924
+ mimeType
2840
2925
  };
2841
- v2Parts.push(v2FilePart);
2926
+ if (part.providerOptions) {
2927
+ v2FilePart.providerMetadata = part.providerOptions;
2928
+ }
2929
+ mastraDBParts.push(v2FilePart);
2842
2930
  experimental_attachments.push({
2843
2931
  url: fileData,
2844
2932
  contentType: mimeType
@@ -2846,34 +2934,34 @@ var MessageList = class _MessageList {
2846
2934
  lastPartWasToolResult = false;
2847
2935
  }
2848
2936
  }
2849
- if (modelMsg.role === "assistant" && lastPartWasToolResult && v2Parts.length > 0) {
2850
- const lastPart = v2Parts[v2Parts.length - 1];
2937
+ if (modelMsg.role === "assistant" && lastPartWasToolResult && mastraDBParts.length > 0) {
2938
+ const lastPart = mastraDBParts[mastraDBParts.length - 1];
2851
2939
  if (lastPart && lastPart.type !== "text") {
2852
2940
  const emptyTextPart = { type: "text", text: "" };
2853
- v2Parts.push(emptyTextPart);
2854
- textParts.push({ text: "" });
2941
+ mastraDBParts.push(emptyTextPart);
2855
2942
  }
2856
2943
  }
2857
- let contentString = void 0;
2858
- if (textParts.length > 0) {
2859
- contentString = textParts.map((p) => p.text).join("\n");
2860
- }
2944
+ const contentString = mastraDBParts.filter((p) => p.type === "text").map((p) => p.text).join("\n");
2861
2945
  const metadata = {};
2862
2946
  const id = `id` in modelMsg && typeof modelMsg.id === `string` ? modelMsg.id : `msg-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
2863
- return {
2947
+ const message = {
2864
2948
  id,
2865
2949
  role: _MessageList.getRole(modelMsg),
2866
2950
  createdAt: /* @__PURE__ */ new Date(),
2867
2951
  content: {
2868
2952
  format: 2,
2869
- parts: v2Parts,
2953
+ parts: mastraDBParts,
2870
2954
  toolInvocations: toolInvocations.length > 0 ? toolInvocations : void 0,
2871
2955
  reasoning: reasoningParts.length > 0 ? reasoningParts.join("\n") : void 0,
2872
2956
  experimental_attachments: experimental_attachments.length > 0 ? experimental_attachments : void 0,
2873
- content: contentString,
2957
+ content: contentString || void 0,
2874
2958
  metadata
2875
2959
  }
2876
2960
  };
2961
+ if (modelMsg.providerOptions) {
2962
+ message.content.providerMetadata = modelMsg.providerOptions;
2963
+ }
2964
+ return message;
2877
2965
  }
2878
2966
  aiV4CoreMessagesToAIV5ModelMessages(messages, source) {
2879
2967
  return this.aiV5UIMessagesToAIV5ModelMessages(
@@ -2884,7 +2972,16 @@ var MessageList = class _MessageList {
2884
2972
  const sanitized = this.sanitizeV5UIMessages(messages, filterIncompleteToolCalls);
2885
2973
  const preprocessed = this.addStartStepPartsForAIV5(sanitized);
2886
2974
  const result = AIV5.convertToModelMessages(preprocessed);
2887
- return result;
2975
+ return result.map((modelMsg, index) => {
2976
+ const uiMsg = preprocessed[index];
2977
+ if (uiMsg?.metadata && typeof uiMsg.metadata === "object" && "providerMetadata" in uiMsg.metadata && uiMsg.metadata.providerMetadata) {
2978
+ return {
2979
+ ...modelMsg,
2980
+ providerOptions: uiMsg.metadata.providerMetadata
2981
+ };
2982
+ }
2983
+ return modelMsg;
2984
+ });
2888
2985
  }
2889
2986
  addStartStepPartsForAIV5(messages) {
2890
2987
  for (const message of messages) {
@@ -3017,5 +3114,5 @@ var MessageList = class _MessageList {
3017
3114
  };
3018
3115
 
3019
3116
  export { DefaultGeneratedFile, DefaultGeneratedFileWithType, MessageList, convertMessages };
3020
- //# sourceMappingURL=chunk-BAMR7HKO.js.map
3021
- //# sourceMappingURL=chunk-BAMR7HKO.js.map
3117
+ //# sourceMappingURL=chunk-W3DD3XP5.js.map
3118
+ //# sourceMappingURL=chunk-W3DD3XP5.js.map