@mastra/core 1.5.0 → 1.6.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 (237) hide show
  1. package/CHANGELOG.md +386 -0
  2. package/dist/agent/index.cjs +13 -13
  3. package/dist/agent/index.js +2 -2
  4. package/dist/agent/message-list/adapters/AIV5Adapter.d.ts.map +1 -1
  5. package/dist/agent/message-list/conversion/output-converter.d.ts.map +1 -1
  6. package/dist/agent/message-list/index.cjs +18 -18
  7. package/dist/agent/message-list/index.js +1 -1
  8. package/dist/agent/workflows/prepare-stream/index.d.ts +7 -7
  9. package/dist/agent/workflows/prepare-stream/prepare-memory-step.d.ts +7 -7
  10. package/dist/agent/workflows/prepare-stream/schema.d.ts +11 -11
  11. package/dist/{chunk-CQ4Z6ZAV.cjs → chunk-3U3XFMGJ.cjs} +7 -7
  12. package/dist/{chunk-CQ4Z6ZAV.cjs.map → chunk-3U3XFMGJ.cjs.map} +1 -1
  13. package/dist/{chunk-D57U4II4.js → chunk-4WG5K4CK.js} +9 -8
  14. package/dist/chunk-4WG5K4CK.js.map +1 -0
  15. package/dist/{chunk-UZFGMMKU.js → chunk-5K45E5VE.js} +37 -3
  16. package/dist/chunk-5K45E5VE.js.map +1 -0
  17. package/dist/{chunk-OQ5LZ6OV.cjs → chunk-5VQPSWPG.cjs} +149 -61
  18. package/dist/chunk-5VQPSWPG.cjs.map +1 -0
  19. package/dist/{chunk-AIRMLZ43.js → chunk-7EXW4AAG.js} +4 -4
  20. package/dist/{chunk-AIRMLZ43.js.map → chunk-7EXW4AAG.js.map} +1 -1
  21. package/dist/{chunk-S4VVZI4E.cjs → chunk-AYHSPIT6.cjs} +326 -5
  22. package/dist/chunk-AYHSPIT6.cjs.map +1 -0
  23. package/dist/{chunk-YW54RH77.cjs → chunk-DB7U2C5B.cjs} +12 -5
  24. package/dist/chunk-DB7U2C5B.cjs.map +1 -0
  25. package/dist/{chunk-DST75PA4.js → chunk-DGS2KGDI.js} +4 -4
  26. package/dist/{chunk-DST75PA4.js.map → chunk-DGS2KGDI.js.map} +1 -1
  27. package/dist/{chunk-YIN5F7VO.js → chunk-EEU5NHHU.js} +4254 -3958
  28. package/dist/chunk-EEU5NHHU.js.map +1 -0
  29. package/dist/{chunk-A6EWCOGA.cjs → chunk-H5S4PS44.cjs} +197 -27
  30. package/dist/chunk-H5S4PS44.cjs.map +1 -0
  31. package/dist/{chunk-3YMDR4OL.cjs → chunk-HTAUP7ER.cjs} +4 -4
  32. package/dist/{chunk-3YMDR4OL.cjs.map → chunk-HTAUP7ER.cjs.map} +1 -1
  33. package/dist/{chunk-OHLVZVIK.js → chunk-IC5OUWKJ.js} +12 -5
  34. package/dist/chunk-IC5OUWKJ.js.map +1 -0
  35. package/dist/{chunk-MZIMV2BB.js → chunk-IHDE4CJV.js} +244 -213
  36. package/dist/chunk-IHDE4CJV.js.map +1 -0
  37. package/dist/{chunk-3KJW4EMO.js → chunk-IHEYJDJP.js} +3 -3
  38. package/dist/{chunk-3KJW4EMO.js.map → chunk-IHEYJDJP.js.map} +1 -1
  39. package/dist/{chunk-CXVMDV2B.js → chunk-IOY7Y5GV.js} +197 -27
  40. package/dist/chunk-IOY7Y5GV.js.map +1 -0
  41. package/dist/{chunk-MDC6VYA6.cjs → chunk-KAVAKMOQ.cjs} +4 -8
  42. package/dist/chunk-KAVAKMOQ.cjs.map +1 -0
  43. package/dist/{chunk-7WC7ALDW.cjs → chunk-LNKS4TJ6.cjs} +6 -6
  44. package/dist/{chunk-7WC7ALDW.cjs.map → chunk-LNKS4TJ6.cjs.map} +1 -1
  45. package/dist/{chunk-R3364RAL.js → chunk-MWGGSA5Q.js} +4 -4
  46. package/dist/{chunk-R3364RAL.js.map → chunk-MWGGSA5Q.js.map} +1 -1
  47. package/dist/{chunk-QSN5KQXZ.cjs → chunk-O7PZ4VOO.cjs} +11 -11
  48. package/dist/{chunk-QSN5KQXZ.cjs.map → chunk-O7PZ4VOO.cjs.map} +1 -1
  49. package/dist/chunk-OQDRPRKM.cjs +46 -0
  50. package/dist/chunk-OQDRPRKM.cjs.map +1 -0
  51. package/dist/{chunk-YV2YGQRY.js → chunk-RHKNKJNM.js} +101 -13
  52. package/dist/chunk-RHKNKJNM.js.map +1 -0
  53. package/dist/{chunk-TPDMP7OD.js → chunk-RHYZ6CQN.js} +4 -8
  54. package/dist/chunk-RHYZ6CQN.js.map +1 -0
  55. package/dist/{chunk-G5JVVFIG.cjs → chunk-RZNHRIM7.cjs} +9 -9
  56. package/dist/{chunk-G5JVVFIG.cjs.map → chunk-RZNHRIM7.cjs.map} +1 -1
  57. package/dist/{chunk-JZ6TH4HQ.cjs → chunk-TL2TTA4X.cjs} +4260 -3962
  58. package/dist/chunk-TL2TTA4X.cjs.map +1 -0
  59. package/dist/{chunk-KNXZ7KYL.cjs → chunk-TVPANHLE.cjs} +40 -2
  60. package/dist/chunk-TVPANHLE.cjs.map +1 -0
  61. package/dist/{chunk-7S6LA43E.cjs → chunk-VJWRJWSC.cjs} +278 -248
  62. package/dist/chunk-VJWRJWSC.cjs.map +1 -0
  63. package/dist/chunk-X2HAI3OX.js +39 -0
  64. package/dist/chunk-X2HAI3OX.js.map +1 -0
  65. package/dist/{chunk-FZ5DRHKE.js → chunk-XB3DA67Q.js} +325 -5
  66. package/dist/chunk-XB3DA67Q.js.map +1 -0
  67. package/dist/{chunk-NUV3BLRH.cjs → chunk-XWZAKKFT.cjs} +17 -16
  68. package/dist/chunk-XWZAKKFT.cjs.map +1 -0
  69. package/dist/{chunk-4GB2GS4S.js → chunk-YM6245EM.js} +5 -5
  70. package/dist/{chunk-4GB2GS4S.js.map → chunk-YM6245EM.js.map} +1 -1
  71. package/dist/datasets/index.cjs +17 -17
  72. package/dist/datasets/index.js +2 -2
  73. package/dist/docs/SKILL.md +2 -1
  74. package/dist/docs/assets/SOURCE_MAP.json +417 -391
  75. package/dist/docs/references/docs-memory-observational-memory.md +2 -0
  76. package/dist/docs/references/docs-streaming-tool-streaming.md +6 -0
  77. package/dist/docs/references/docs-workspace-filesystem.md +21 -1
  78. package/dist/docs/references/reference-harness-harness-class.md +645 -0
  79. package/dist/docs/references/reference-memory-memory-class.md +1 -1
  80. package/dist/docs/references/reference-memory-observational-memory.md +1 -0
  81. package/dist/docs/references/reference-workspace-local-filesystem.md +25 -0
  82. package/dist/docs/references/reference-workspace-workspace-class.md +1 -24
  83. package/dist/docs/references/reference.md +1 -0
  84. package/dist/editor/types.d.ts +20 -1
  85. package/dist/editor/types.d.ts.map +1 -1
  86. package/dist/evals/base.d.ts.map +1 -1
  87. package/dist/evals/index.cjs +20 -20
  88. package/dist/evals/index.js +3 -3
  89. package/dist/evals/scoreTraces/index.cjs +5 -5
  90. package/dist/evals/scoreTraces/index.js +2 -2
  91. package/dist/events/index.cjs +6 -2
  92. package/dist/events/index.d.ts +1 -0
  93. package/dist/events/index.d.ts.map +1 -1
  94. package/dist/events/index.js +1 -1
  95. package/dist/harness/harness.d.ts +105 -35
  96. package/dist/harness/harness.d.ts.map +1 -1
  97. package/dist/harness/index.cjs +472 -64
  98. package/dist/harness/index.cjs.map +1 -1
  99. package/dist/harness/index.d.ts +2 -1
  100. package/dist/harness/index.d.ts.map +1 -1
  101. package/dist/harness/index.js +468 -62
  102. package/dist/harness/index.js.map +1 -1
  103. package/dist/harness/tools.d.ts +38 -0
  104. package/dist/harness/tools.d.ts.map +1 -1
  105. package/dist/harness/types.d.ts +64 -9
  106. package/dist/harness/types.d.ts.map +1 -1
  107. package/dist/index.cjs +2 -2
  108. package/dist/index.js +1 -1
  109. package/dist/llm/index.cjs +12 -12
  110. package/dist/llm/index.js +3 -3
  111. package/dist/llm/model/gateways/models-dev.d.ts.map +1 -1
  112. package/dist/loop/index.cjs +12 -12
  113. package/dist/loop/index.js +1 -1
  114. package/dist/loop/network/index.d.ts +6 -6
  115. package/dist/loop/network/index.d.ts.map +1 -1
  116. package/dist/loop/test-utils/options.d.ts.map +1 -1
  117. package/dist/loop/workflows/agentic-execution/index.d.ts +21 -21
  118. package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts +14 -14
  119. package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts.map +1 -1
  120. package/dist/loop/workflows/agentic-execution/llm-mapping-step.d.ts +7 -7
  121. package/dist/loop/workflows/agentic-execution/llm-mapping-step.d.ts.map +1 -1
  122. package/dist/loop/workflows/agentic-execution/tool-call-step.d.ts.map +1 -1
  123. package/dist/loop/workflows/agentic-loop/index.d.ts +21 -21
  124. package/dist/loop/workflows/agentic-loop/index.d.ts.map +1 -1
  125. package/dist/loop/workflows/schema.d.ts +30 -30
  126. package/dist/loop/workflows/stream.d.ts +0 -13
  127. package/dist/loop/workflows/stream.d.ts.map +1 -1
  128. package/dist/mastra/index.cjs +2 -2
  129. package/dist/mastra/index.js +1 -1
  130. package/dist/memory/index.cjs +14 -14
  131. package/dist/memory/index.js +1 -1
  132. package/dist/models-dev-6P4CM74H.js +3 -0
  133. package/dist/{models-dev-MDI5E2YA.js.map → models-dev-6P4CM74H.js.map} +1 -1
  134. package/dist/models-dev-CLLSNT5L.cjs +12 -0
  135. package/dist/{models-dev-BW2GAM3K.cjs.map → models-dev-CLLSNT5L.cjs.map} +1 -1
  136. package/dist/processor-provider/index.cjs +256 -0
  137. package/dist/processor-provider/index.cjs.map +1 -0
  138. package/dist/processor-provider/index.d.ts +5 -0
  139. package/dist/processor-provider/index.d.ts.map +1 -0
  140. package/dist/processor-provider/index.js +243 -0
  141. package/dist/processor-provider/index.js.map +1 -0
  142. package/dist/processor-provider/phase-filtered-processor.d.ts +22 -0
  143. package/dist/processor-provider/phase-filtered-processor.d.ts.map +1 -0
  144. package/dist/processor-provider/providers/index.d.ts +12 -0
  145. package/dist/processor-provider/providers/index.d.ts.map +1 -0
  146. package/dist/processor-provider/types.d.ts +65 -0
  147. package/dist/processor-provider/types.d.ts.map +1 -0
  148. package/dist/processors/index.cjs +41 -41
  149. package/dist/processors/index.js +1 -1
  150. package/dist/processors/memory/message-history.d.ts.map +1 -1
  151. package/dist/processors/step-schema.d.ts +14 -14
  152. package/dist/provider-registry-HMTFO5FV.cjs +40 -0
  153. package/dist/{provider-registry-4PH2JPIA.cjs.map → provider-registry-HMTFO5FV.cjs.map} +1 -1
  154. package/dist/provider-registry-TTZ2WN2P.js +3 -0
  155. package/dist/{provider-registry-VEJ3PN4S.js.map → provider-registry-TTZ2WN2P.js.map} +1 -1
  156. package/dist/relevance/index.cjs +3 -3
  157. package/dist/relevance/index.js +1 -1
  158. package/dist/storage/base.d.ts +2 -1
  159. package/dist/storage/base.d.ts.map +1 -1
  160. package/dist/storage/constants.cjs +68 -52
  161. package/dist/storage/constants.d.ts +6 -2
  162. package/dist/storage/constants.d.ts.map +1 -1
  163. package/dist/storage/constants.js +1 -1
  164. package/dist/storage/domains/index.d.ts +1 -0
  165. package/dist/storage/domains/index.d.ts.map +1 -1
  166. package/dist/storage/domains/inmemory-db.d.ts +4 -1
  167. package/dist/storage/domains/inmemory-db.d.ts.map +1 -1
  168. package/dist/storage/domains/mcp-servers/base.d.ts +47 -0
  169. package/dist/storage/domains/mcp-servers/base.d.ts.map +1 -0
  170. package/dist/storage/domains/mcp-servers/index.d.ts +3 -0
  171. package/dist/storage/domains/mcp-servers/index.d.ts.map +1 -0
  172. package/dist/storage/domains/mcp-servers/inmemory.d.ts +31 -0
  173. package/dist/storage/domains/mcp-servers/inmemory.d.ts.map +1 -0
  174. package/dist/storage/domains/memory/inmemory.d.ts.map +1 -1
  175. package/dist/storage/domains/observability/types.d.ts +44 -44
  176. package/dist/storage/domains/operations/inmemory.d.ts.map +1 -1
  177. package/dist/storage/index.cjs +178 -154
  178. package/dist/storage/index.js +2 -2
  179. package/dist/storage/mock.d.ts.map +1 -1
  180. package/dist/storage/types.d.ts +220 -6
  181. package/dist/storage/types.d.ts.map +1 -1
  182. package/dist/stream/MastraAgentNetworkStream.d.ts +1 -1
  183. package/dist/stream/MastraWorkflowStream.d.ts +1 -1
  184. package/dist/stream/aisdk/v5/input.d.ts.map +1 -1
  185. package/dist/stream/base/input.d.ts +19 -0
  186. package/dist/stream/base/input.d.ts.map +1 -1
  187. package/dist/stream/base/output.d.ts.map +1 -1
  188. package/dist/stream/index.cjs +11 -11
  189. package/dist/stream/index.js +2 -2
  190. package/dist/tool-loop-agent/index.cjs +4 -4
  191. package/dist/tool-loop-agent/index.js +1 -1
  192. package/dist/vector/index.cjs +9 -9
  193. package/dist/vector/index.js +2 -2
  194. package/dist/workflows/evented/execution-engine.d.ts.map +1 -1
  195. package/dist/workflows/evented/index.cjs +10 -10
  196. package/dist/workflows/evented/index.js +1 -1
  197. package/dist/workflows/evented/step-executor.d.ts.map +1 -1
  198. package/dist/workflows/evented/workflow-event-processor/index.d.ts.map +1 -1
  199. package/dist/workflows/index.cjs +25 -25
  200. package/dist/workflows/index.js +1 -1
  201. package/dist/workflows/step.d.ts.map +1 -1
  202. package/dist/workspace/constants/index.d.ts +1 -0
  203. package/dist/workspace/constants/index.d.ts.map +1 -1
  204. package/dist/workspace/index.cjs +64 -64
  205. package/dist/workspace/index.js +1 -1
  206. package/dist/workspace/tools/ast-edit.d.ts +97 -0
  207. package/dist/workspace/tools/ast-edit.d.ts.map +1 -0
  208. package/dist/workspace/tools/search.d.ts +1 -1
  209. package/dist/workspace/tools/tools.d.ts.map +1 -1
  210. package/package.json +12 -11
  211. package/processor-provider.d.ts +1 -0
  212. package/dist/chunk-4D4KB75Y.cjs +0 -9
  213. package/dist/chunk-4D4KB75Y.cjs.map +0 -1
  214. package/dist/chunk-7S6LA43E.cjs.map +0 -1
  215. package/dist/chunk-A6EWCOGA.cjs.map +0 -1
  216. package/dist/chunk-BVUMKER5.js +0 -7
  217. package/dist/chunk-BVUMKER5.js.map +0 -1
  218. package/dist/chunk-CXVMDV2B.js.map +0 -1
  219. package/dist/chunk-D57U4II4.js.map +0 -1
  220. package/dist/chunk-FZ5DRHKE.js.map +0 -1
  221. package/dist/chunk-JZ6TH4HQ.cjs.map +0 -1
  222. package/dist/chunk-KNXZ7KYL.cjs.map +0 -1
  223. package/dist/chunk-MDC6VYA6.cjs.map +0 -1
  224. package/dist/chunk-MZIMV2BB.js.map +0 -1
  225. package/dist/chunk-NUV3BLRH.cjs.map +0 -1
  226. package/dist/chunk-OHLVZVIK.js.map +0 -1
  227. package/dist/chunk-OQ5LZ6OV.cjs.map +0 -1
  228. package/dist/chunk-S4VVZI4E.cjs.map +0 -1
  229. package/dist/chunk-TPDMP7OD.js.map +0 -1
  230. package/dist/chunk-UZFGMMKU.js.map +0 -1
  231. package/dist/chunk-YIN5F7VO.js.map +0 -1
  232. package/dist/chunk-YV2YGQRY.js.map +0 -1
  233. package/dist/chunk-YW54RH77.cjs.map +0 -1
  234. package/dist/models-dev-BW2GAM3K.cjs +0 -12
  235. package/dist/models-dev-MDI5E2YA.js +0 -3
  236. package/dist/provider-registry-4PH2JPIA.cjs +0 -40
  237. package/dist/provider-registry-VEJ3PN4S.js +0 -3
@@ -1,17 +1,17 @@
1
1
  'use strict';
2
2
 
3
3
  var chunkRQ56ZSIR_cjs = require('./chunk-RQ56ZSIR.cjs');
4
- var chunkS4VVZI4E_cjs = require('./chunk-S4VVZI4E.cjs');
5
4
  var chunkZCBG4ZQT_cjs = require('./chunk-ZCBG4ZQT.cjs');
6
- var chunkJZ6TH4HQ_cjs = require('./chunk-JZ6TH4HQ.cjs');
7
- var chunkYW54RH77_cjs = require('./chunk-YW54RH77.cjs');
5
+ var chunkAYHSPIT6_cjs = require('./chunk-AYHSPIT6.cjs');
6
+ var chunkTL2TTA4X_cjs = require('./chunk-TL2TTA4X.cjs');
7
+ var chunkDB7U2C5B_cjs = require('./chunk-DB7U2C5B.cjs');
8
8
  var chunkZIEQA3YP_cjs = require('./chunk-ZIEQA3YP.cjs');
9
9
  var chunkPM3UIIBK_cjs = require('./chunk-PM3UIIBK.cjs');
10
10
  var chunkMR7ZWBL6_cjs = require('./chunk-MR7ZWBL6.cjs');
11
- var chunkQSN5KQXZ_cjs = require('./chunk-QSN5KQXZ.cjs');
11
+ var chunkO7PZ4VOO_cjs = require('./chunk-O7PZ4VOO.cjs');
12
12
  var chunkPHHJLGZU_cjs = require('./chunk-PHHJLGZU.cjs');
13
13
  var chunk6BJ7XHRH_cjs = require('./chunk-6BJ7XHRH.cjs');
14
- var chunk4D4KB75Y_cjs = require('./chunk-4D4KB75Y.cjs');
14
+ var chunkOQDRPRKM_cjs = require('./chunk-OQDRPRKM.cjs');
15
15
  var chunkQDH6MVJ7_cjs = require('./chunk-QDH6MVJ7.cjs');
16
16
  var chunkKRAGJ433_cjs = require('./chunk-KRAGJ433.cjs');
17
17
  var chunkKJBMTK5B_cjs = require('./chunk-KJBMTK5B.cjs');
@@ -1273,7 +1273,7 @@ var ProcessorRunner = class _ProcessorRunner {
1273
1273
  writer
1274
1274
  });
1275
1275
  const mutations = messageList.stopRecording();
1276
- if (result instanceof chunkYW54RH77_cjs.MessageList) {
1276
+ if (result instanceof chunkDB7U2C5B_cjs.MessageList) {
1277
1277
  if (result !== messageList) {
1278
1278
  throw new chunk4U7ZLI36_cjs.MastraError({
1279
1279
  category: "USER",
@@ -1529,7 +1529,7 @@ var ProcessorRunner = class _ProcessorRunner {
1529
1529
  retryCount
1530
1530
  });
1531
1531
  let mutations;
1532
- if (result instanceof chunkYW54RH77_cjs.MessageList) {
1532
+ if (result instanceof chunkDB7U2C5B_cjs.MessageList) {
1533
1533
  if (result !== messageList) {
1534
1534
  throw new chunk4U7ZLI36_cjs.MastraError({
1535
1535
  category: "USER",
@@ -1857,7 +1857,7 @@ var ProcessorRunner = class _ProcessorRunner {
1857
1857
  writer
1858
1858
  });
1859
1859
  const mutations = messageList.stopRecording();
1860
- if (result instanceof chunkYW54RH77_cjs.MessageList) {
1860
+ if (result instanceof chunkDB7U2C5B_cjs.MessageList) {
1861
1861
  if (result !== messageList) {
1862
1862
  throw new chunk4U7ZLI36_cjs.MastraError({
1863
1863
  category: "USER",
@@ -1927,7 +1927,7 @@ var ProcessorRunner = class _ProcessorRunner {
1927
1927
  processor,
1928
1928
  stepNumber
1929
1929
  }) {
1930
- if (result instanceof chunkYW54RH77_cjs.MessageList) {
1930
+ if (result instanceof chunkDB7U2C5B_cjs.MessageList) {
1931
1931
  if (result !== messageList) {
1932
1932
  throw new chunk4U7ZLI36_cjs.MastraError({
1933
1933
  category: "USER",
@@ -1962,7 +1962,7 @@ var ProcessorRunner = class _ProcessorRunner {
1962
1962
  }
1963
1963
  const { model: _model, ...rest } = result;
1964
1964
  if (result.model) {
1965
- const resolvedModel = await chunkQSN5KQXZ_cjs.resolveModelConfig(result.model);
1965
+ const resolvedModel = await chunkO7PZ4VOO_cjs.resolveModelConfig(result.model);
1966
1966
  const isSupported = isSupportedLanguageModel(resolvedModel);
1967
1967
  if (!isSupported) {
1968
1968
  throw new chunk4U7ZLI36_cjs.MastraError({
@@ -1982,6 +1982,58 @@ var ProcessorRunner = class _ProcessorRunner {
1982
1982
  return {};
1983
1983
  }
1984
1984
  };
1985
+
1986
+ // src/stream/base/input.ts
1987
+ function safeEnqueue(controller, chunk) {
1988
+ try {
1989
+ controller.enqueue(chunk);
1990
+ return true;
1991
+ } catch {
1992
+ return false;
1993
+ }
1994
+ }
1995
+ function safeClose(controller) {
1996
+ try {
1997
+ controller.close();
1998
+ return true;
1999
+ } catch {
2000
+ return false;
2001
+ }
2002
+ }
2003
+ function safeError(controller, error) {
2004
+ try {
2005
+ controller.error(error);
2006
+ return true;
2007
+ } catch {
2008
+ return false;
2009
+ }
2010
+ }
2011
+ var MastraModelInput = class extends chunkRO47SMI7_cjs.MastraBase {
2012
+ initialize({ runId, createStream, onResult }) {
2013
+ const self = this;
2014
+ const stream = new ReadableStream({
2015
+ async start(controller) {
2016
+ try {
2017
+ const stream2 = await createStream();
2018
+ onResult({
2019
+ warnings: stream2.warnings,
2020
+ request: stream2.request,
2021
+ rawResponse: stream2.rawResponse || stream2.response || {}
2022
+ });
2023
+ await self.transform({
2024
+ runId,
2025
+ stream: stream2.stream,
2026
+ controller
2027
+ });
2028
+ safeClose(controller);
2029
+ } catch (error) {
2030
+ safeError(controller, error);
2031
+ }
2032
+ }
2033
+ });
2034
+ return stream;
2035
+ }
2036
+ };
1985
2037
  function asJsonSchema(schema) {
1986
2038
  if (!schema) {
1987
2039
  return void 0;
@@ -3036,7 +3088,7 @@ var MastraModelOutput = class extends chunkRO47SMI7_cjs.MastraBase {
3036
3088
  );
3037
3089
  const responseMessages = self.messageList.get.response.aiV4.core();
3038
3090
  const lastResponseMessage = responseMessages[responseMessages.length - 1];
3039
- const outputText = lastResponseMessage ? chunkYW54RH77_cjs.coreContentToString(lastResponseMessage.content) : "";
3091
+ const outputText = lastResponseMessage ? chunkDB7U2C5B_cjs.coreContentToString(lastResponseMessage.content) : "";
3040
3092
  if (lastStep && outputText && outputText !== originalText) {
3041
3093
  lastStep.text = outputText;
3042
3094
  }
@@ -3604,12 +3656,12 @@ var MastraModelOutput = class extends chunkRO47SMI7_cjs.MastraBase {
3604
3656
  return;
3605
3657
  }
3606
3658
  const chunkHandler = (chunk) => {
3607
- controller.enqueue(chunk);
3659
+ safeEnqueue(controller, chunk);
3608
3660
  };
3609
3661
  const finishHandler = () => {
3610
3662
  self.#emitter.off("chunk", chunkHandler);
3611
3663
  self.#emitter.off("finish", finishHandler);
3612
- controller.close();
3664
+ safeClose(controller);
3613
3665
  };
3614
3666
  self.#emitter.on("chunk", chunkHandler);
3615
3667
  self.#emitter.on("finish", finishHandler);
@@ -4348,7 +4400,7 @@ function convertMastraChunkToAISDKv5({
4348
4400
  if (mode === "generate") {
4349
4401
  return {
4350
4402
  type: "file",
4351
- file: new chunkYW54RH77_cjs.DefaultGeneratedFile({
4403
+ file: new chunkDB7U2C5B_cjs.DefaultGeneratedFile({
4352
4404
  data: chunk.payload.data,
4353
4405
  mediaType: chunk.payload.mimeType
4354
4406
  })
@@ -4356,7 +4408,7 @@ function convertMastraChunkToAISDKv5({
4356
4408
  }
4357
4409
  return {
4358
4410
  type: "file",
4359
- file: new chunkYW54RH77_cjs.DefaultGeneratedFileWithType({
4411
+ file: new chunkDB7U2C5B_cjs.DefaultGeneratedFileWithType({
4360
4412
  data: chunk.payload.data,
4361
4413
  mediaType: chunk.payload.mimeType
4362
4414
  })
@@ -4634,36 +4686,6 @@ function runScorer({
4634
4686
  };
4635
4687
  chunkMR7ZWBL6_cjs.executeHook("onScorerRun" /* ON_SCORER_RUN */, payload);
4636
4688
  }
4637
- var EventEmitterPubSub = class extends chunk4D4KB75Y_cjs.PubSub {
4638
- emitter;
4639
- constructor(existingEmitter) {
4640
- super();
4641
- this.emitter = existingEmitter ?? new EventEmitter2__default.default();
4642
- }
4643
- async publish(topic, event) {
4644
- const id = crypto.randomUUID();
4645
- const createdAt = /* @__PURE__ */ new Date();
4646
- this.emitter.emit(topic, {
4647
- ...event,
4648
- id,
4649
- createdAt
4650
- });
4651
- }
4652
- async subscribe(topic, cb) {
4653
- this.emitter.on(topic, cb);
4654
- }
4655
- async unsubscribe(topic, cb) {
4656
- this.emitter.off(topic, cb);
4657
- }
4658
- async flush() {
4659
- }
4660
- /**
4661
- * Clean up all listeners during graceful shutdown.
4662
- */
4663
- async close() {
4664
- this.emitter.removeAllListeners();
4665
- }
4666
- };
4667
4689
  var TextPartSchema = z10.z.object({
4668
4690
  type: z10.z.literal("text"),
4669
4691
  text: z10.z.string()
@@ -8303,7 +8325,7 @@ function createStepFromProcessor(processor) {
8303
8325
  phase,
8304
8326
  // Auto-create MessageList from messages if not provided
8305
8327
  // This enables running processor workflows from the UI where messageList can't be serialized
8306
- messageList: messageList ?? (Array.isArray(messages) ? new chunkYW54RH77_cjs.MessageList().add(messages, "input").addSystem(systemMessages ?? []) : void 0),
8328
+ messageList: messageList ?? (Array.isArray(messages) ? new chunkDB7U2C5B_cjs.MessageList().add(messages, "input").addSystem(systemMessages ?? []) : void 0),
8307
8329
  stepNumber,
8308
8330
  systemMessages,
8309
8331
  streamParts,
@@ -8357,7 +8379,7 @@ function createStepFromProcessor(processor) {
8357
8379
  messageList: checkedMessageList,
8358
8380
  systemMessages: systemMessages ?? []
8359
8381
  });
8360
- if (result instanceof chunkYW54RH77_cjs.MessageList) {
8382
+ if (result instanceof chunkDB7U2C5B_cjs.MessageList) {
8361
8383
  if (result !== checkedMessageList) {
8362
8384
  throw new chunk4U7ZLI36_cjs.MastraError({
8363
8385
  category: "USER" /* USER */,
@@ -8521,7 +8543,7 @@ function createStepFromProcessor(processor) {
8521
8543
  messages,
8522
8544
  messageList: passThrough.messageList
8523
8545
  });
8524
- if (result instanceof chunkYW54RH77_cjs.MessageList) {
8546
+ if (result instanceof chunkDB7U2C5B_cjs.MessageList) {
8525
8547
  if (result !== passThrough.messageList) {
8526
8548
  throw new chunk4U7ZLI36_cjs.MastraError({
8527
8549
  category: "USER" /* USER */,
@@ -8588,7 +8610,7 @@ function createStepFromProcessor(processor) {
8588
8610
  systemMessages: systemMessages ?? [],
8589
8611
  steps: steps ?? []
8590
8612
  });
8591
- if (result instanceof chunkYW54RH77_cjs.MessageList) {
8613
+ if (result instanceof chunkDB7U2C5B_cjs.MessageList) {
8592
8614
  if (result !== checkedMessageList) {
8593
8615
  throw new chunk4U7ZLI36_cjs.MastraError({
8594
8616
  category: "USER" /* USER */,
@@ -9590,7 +9612,7 @@ var Run = class {
9590
9612
  this.executionEngine = params.executionEngine;
9591
9613
  this.executionGraph = params.executionGraph;
9592
9614
  this.#mastra = params.mastra;
9593
- this.pubsub = new EventEmitterPubSub();
9615
+ this.pubsub = new chunkOQDRPRKM_cjs.EventEmitterPubSub();
9594
9616
  this.retryConfig = params.retryConfig;
9595
9617
  this.cleanup = params.cleanup;
9596
9618
  this.disableScorers = params.disableScorers;
@@ -10635,34 +10657,6 @@ var PrepareStepProcessor = class {
10635
10657
  }
10636
10658
  };
10637
10659
 
10638
- // src/stream/base/input.ts
10639
- var MastraModelInput = class extends chunkRO47SMI7_cjs.MastraBase {
10640
- initialize({ runId, createStream, onResult }) {
10641
- const self = this;
10642
- const stream = new ReadableStream({
10643
- async start(controller) {
10644
- try {
10645
- const stream2 = await createStream();
10646
- onResult({
10647
- warnings: stream2.warnings,
10648
- request: stream2.request,
10649
- rawResponse: stream2.rawResponse || stream2.response || {}
10650
- });
10651
- await self.transform({
10652
- runId,
10653
- stream: stream2.stream,
10654
- controller
10655
- });
10656
- controller.close();
10657
- } catch (error) {
10658
- controller.error(error);
10659
- }
10660
- }
10661
- });
10662
- return stream;
10663
- }
10664
- };
10665
-
10666
10660
  // src/stream/aisdk/v5/input.ts
10667
10661
  function isNumericId(id) {
10668
10662
  return /^\d+$/.test(id);
@@ -10697,7 +10691,7 @@ var AISDKV5InputStream = class extends MastraModelInput {
10697
10691
  }
10698
10692
  transformedChunk.payload.id = idMap.get(originalId);
10699
10693
  }
10700
- controller.enqueue(transformedChunk);
10694
+ safeEnqueue(controller, transformedChunk);
10701
10695
  }
10702
10696
  }
10703
10697
  }
@@ -11011,9 +11005,7 @@ async function processOutputStream({
11011
11005
  providerOptions: chunk.payload.providerMetadata
11012
11006
  });
11013
11007
  }
11014
- if (isControllerOpen(controller)) {
11015
- controller.enqueue(chunk);
11016
- }
11008
+ safeEnqueue(controller, chunk);
11017
11009
  break;
11018
11010
  }
11019
11011
  case "text-delta": {
@@ -11023,18 +11015,14 @@ async function processOutputStream({
11023
11015
  textDeltas: textDeltasFromState,
11024
11016
  isStreaming: true
11025
11017
  });
11026
- if (isControllerOpen(controller)) {
11027
- controller.enqueue(chunk);
11028
- }
11018
+ safeEnqueue(controller, chunk);
11029
11019
  break;
11030
11020
  }
11031
11021
  case "text-end": {
11032
11022
  runState.setState({
11033
11023
  providerOptions: void 0
11034
11024
  });
11035
- if (isControllerOpen(controller)) {
11036
- controller.enqueue(chunk);
11037
- }
11025
+ safeEnqueue(controller, chunk);
11038
11026
  break;
11039
11027
  }
11040
11028
  case "tool-call-input-streaming-start": {
@@ -11050,9 +11038,7 @@ async function processOutputStream({
11050
11038
  logger?.error("Error calling onInputStart", error2);
11051
11039
  }
11052
11040
  }
11053
- if (isControllerOpen(controller)) {
11054
- controller.enqueue(chunk);
11055
- }
11041
+ safeEnqueue(controller, chunk);
11056
11042
  break;
11057
11043
  }
11058
11044
  case "tool-call-delta": {
@@ -11069,9 +11055,7 @@ async function processOutputStream({
11069
11055
  logger?.error("Error calling onInputDelta", error2);
11070
11056
  }
11071
11057
  }
11072
- if (isControllerOpen(controller)) {
11073
- controller.enqueue(chunk);
11074
- }
11058
+ safeEnqueue(controller, chunk);
11075
11059
  break;
11076
11060
  }
11077
11061
  case "reasoning-start": {
@@ -11098,14 +11082,10 @@ async function processOutputStream({
11098
11082
  createdAt: /* @__PURE__ */ new Date()
11099
11083
  };
11100
11084
  messageList.add(message, "response");
11101
- if (isControllerOpen(controller)) {
11102
- controller.enqueue(chunk);
11103
- }
11085
+ safeEnqueue(controller, chunk);
11104
11086
  break;
11105
11087
  }
11106
- if (isControllerOpen(controller)) {
11107
- controller.enqueue(chunk);
11108
- }
11088
+ safeEnqueue(controller, chunk);
11109
11089
  break;
11110
11090
  }
11111
11091
  case "reasoning-delta": {
@@ -11116,9 +11096,7 @@ async function processOutputStream({
11116
11096
  reasoningDeltas: reasoningDeltasFromState,
11117
11097
  providerOptions: chunk.payload.providerMetadata ?? runState.state.providerOptions
11118
11098
  });
11119
- if (isControllerOpen(controller)) {
11120
- controller.enqueue(chunk);
11121
- }
11099
+ safeEnqueue(controller, chunk);
11122
11100
  break;
11123
11101
  }
11124
11102
  case "reasoning-end": {
@@ -11144,9 +11122,7 @@ async function processOutputStream({
11144
11122
  reasoningDeltas: [],
11145
11123
  providerOptions: void 0
11146
11124
  });
11147
- if (isControllerOpen(controller)) {
11148
- controller.enqueue(chunk);
11149
- }
11125
+ safeEnqueue(controller, chunk);
11150
11126
  break;
11151
11127
  }
11152
11128
  case "file":
@@ -11169,7 +11145,7 @@ async function processOutputStream({
11169
11145
  createdAt: /* @__PURE__ */ new Date()
11170
11146
  };
11171
11147
  messageList.add(message, "response");
11172
- controller.enqueue(chunk);
11148
+ safeEnqueue(controller, chunk);
11173
11149
  }
11174
11150
  break;
11175
11151
  case "source":
@@ -11195,7 +11171,7 @@ async function processOutputStream({
11195
11171
  createdAt: /* @__PURE__ */ new Date()
11196
11172
  };
11197
11173
  messageList.add(message, "response");
11198
- controller.enqueue(chunk);
11174
+ safeEnqueue(controller, chunk);
11199
11175
  }
11200
11176
  break;
11201
11177
  case "finish":
@@ -11229,13 +11205,11 @@ async function processOutputStream({
11229
11205
  const error = chunk4U7ZLI36_cjs.getErrorFromUnknown(chunk.payload.error, {
11230
11206
  fallbackMessage: "Unknown error in agent stream"
11231
11207
  });
11232
- controller.enqueue({ ...chunk, payload: { ...chunk.payload, error } });
11208
+ safeEnqueue(controller, { ...chunk, payload: { ...chunk.payload, error } });
11233
11209
  await options?.onError?.({ error });
11234
11210
  break;
11235
11211
  default:
11236
- if (isControllerOpen(controller)) {
11237
- controller.enqueue(chunk);
11238
- }
11212
+ safeEnqueue(controller, chunk);
11239
11213
  }
11240
11214
  if ([
11241
11215
  "text-delta",
@@ -11399,19 +11373,17 @@ function createLLMExecutionStep({
11399
11373
  Object.assign(currentStep, processInputStepResult);
11400
11374
  } catch (error) {
11401
11375
  if (error instanceof TripWire) {
11402
- if (isControllerOpen(controller)) {
11403
- controller.enqueue({
11404
- type: "tripwire",
11405
- runId,
11406
- from: "AGENT" /* AGENT */,
11407
- payload: {
11408
- reason: error.message,
11409
- retry: error.options?.retry,
11410
- metadata: error.options?.metadata,
11411
- processorId: error.processorId
11412
- }
11413
- });
11414
- }
11376
+ safeEnqueue(controller, {
11377
+ type: "tripwire",
11378
+ runId,
11379
+ from: "AGENT" /* AGENT */,
11380
+ payload: {
11381
+ reason: error.message,
11382
+ retry: error.options?.retry,
11383
+ metadata: error.options?.metadata,
11384
+ processorId: error.processorId
11385
+ }
11386
+ });
11415
11387
  const runState3 = new AgenticRunState({
11416
11388
  _internal,
11417
11389
  model
@@ -11538,10 +11510,7 @@ Analyse the suspended tools: ${JSON.stringify(suspendedTools)}, using the messag
11538
11510
  warnings = warningsFromStream;
11539
11511
  request = requestFromStream || {};
11540
11512
  rawResponse = rawResponseFromStream;
11541
- if (!isControllerOpen(controller)) {
11542
- return;
11543
- }
11544
- controller.enqueue({
11513
+ safeEnqueue(controller, {
11545
11514
  runId,
11546
11515
  from: "AGENT" /* AGENT */,
11547
11516
  type: "step-start",
@@ -11623,20 +11592,16 @@ Analyse the suspended tools: ${JSON.stringify(suspendedTools)}, using the messag
11623
11592
  await options?.onAbort?.({
11624
11593
  steps: inputData?.output?.steps ?? []
11625
11594
  });
11626
- if (isControllerOpen(controller)) {
11627
- controller.enqueue({ type: "abort", runId, from: "AGENT" /* AGENT */, payload: {} });
11628
- }
11595
+ safeEnqueue(controller, { type: "abort", runId, from: "AGENT" /* AGENT */, payload: {} });
11629
11596
  return { callBail: true, outputStream: outputStream2, runState: runState2, stepTools: currentStep.tools };
11630
11597
  }
11631
11598
  if (isLastModel) {
11632
- if (isControllerOpen(controller)) {
11633
- controller.enqueue({
11634
- type: "error",
11635
- runId,
11636
- from: "AGENT" /* AGENT */,
11637
- payload: { error }
11638
- });
11639
- }
11599
+ safeEnqueue(controller, {
11600
+ type: "error",
11601
+ runId,
11602
+ from: "AGENT" /* AGENT */,
11603
+ payload: { error }
11604
+ });
11640
11605
  runState2.setState({
11641
11606
  hasErrored: true,
11642
11607
  stepResult: {
@@ -11717,7 +11682,8 @@ Analyse the suspended tools: ${JSON.stringify(suspendedTools)}, using the messag
11717
11682
  toolName: toolCall.toolName,
11718
11683
  args: toolCall.args
11719
11684
  },
11720
- ...toolCall.providerMetadata ? { providerMetadata: toolCall.providerMetadata } : {}
11685
+ providerMetadata: toolCall.providerMetadata,
11686
+ providerExecuted: toolCall.providerExecuted
11721
11687
  };
11722
11688
  })
11723
11689
  },
@@ -11972,7 +11938,7 @@ function createLLMMappingStep({ models, _internal, ...rest }, llmExecutionStep)
11972
11938
  };
11973
11939
  rest.messageList.add(msg, "response");
11974
11940
  }
11975
- const hasPendingHITL = inputData.some((tc) => tc.result === void 0 && !tc.error);
11941
+ const hasPendingHITL = inputData.some((tc) => tc.result === void 0 && !tc.error && !tc.providerExecuted);
11976
11942
  if (errorResults?.length > 0 && !hasPendingHITL) {
11977
11943
  const successfulResults = inputData.filter((tc) => tc.result !== void 0);
11978
11944
  if (successfulResults.length) {
@@ -11993,32 +11959,60 @@ function createLLMMappingStep({ models, _internal, ...rest }, llmExecutionStep)
11993
11959
  const processed = await processAndEnqueueChunk(chunk);
11994
11960
  if (processed) await rest.options?.onChunk?.(processed);
11995
11961
  }
11996
- const successMessageId = rest.experimental_generateMessageId?.() || _internal?.generateId?.();
11997
- const successMessage = {
11998
- id: successMessageId || "",
11999
- role: "assistant",
12000
- content: {
12001
- format: 2,
12002
- parts: await Promise.all(
12003
- successfulResults.map(async (toolCall) => {
12004
- const providerMetadata = await getProviderMetadataWithModelOutput(toolCall);
12005
- return {
12006
- type: "tool-invocation",
12007
- toolInvocation: {
12008
- state: "result",
12009
- toolCallId: toolCall.toolCallId,
12010
- toolName: toolCall.toolName,
12011
- args: toolCall.args,
12012
- result: toolCall.result
12013
- },
12014
- ...providerMetadata ? { providerMetadata } : {}
12015
- };
12016
- })
12017
- )
12018
- },
12019
- createdAt: /* @__PURE__ */ new Date()
12020
- };
12021
- rest.messageList.add(successMessage, "response");
11962
+ const clientResults = successfulResults.filter((tc) => !tc.providerExecuted);
11963
+ if (clientResults.length > 0) {
11964
+ const successMessageId = rest.experimental_generateMessageId?.() || _internal?.generateId?.();
11965
+ const successMessage = {
11966
+ id: successMessageId || "",
11967
+ role: "assistant",
11968
+ content: {
11969
+ format: 2,
11970
+ parts: await Promise.all(
11971
+ clientResults.map(async (toolCall) => {
11972
+ const providerMetadata = await getProviderMetadataWithModelOutput(toolCall);
11973
+ return {
11974
+ type: "tool-invocation",
11975
+ toolInvocation: {
11976
+ state: "result",
11977
+ toolCallId: toolCall.toolCallId,
11978
+ toolName: toolCall.toolName,
11979
+ args: toolCall.args,
11980
+ result: toolCall.result
11981
+ },
11982
+ ...providerMetadata ? { providerMetadata } : {}
11983
+ };
11984
+ })
11985
+ )
11986
+ },
11987
+ createdAt: /* @__PURE__ */ new Date()
11988
+ };
11989
+ rest.messageList.add(successMessage, "response");
11990
+ }
11991
+ if (successfulResults.some((tc) => tc.providerExecuted)) {
11992
+ const providerResults = successfulResults.filter((tc) => tc.providerExecuted);
11993
+ const providerMessageId = rest.experimental_generateMessageId?.() || _internal?.generateId?.();
11994
+ const providerMessage = {
11995
+ id: providerMessageId || "",
11996
+ role: "assistant",
11997
+ content: {
11998
+ format: 2,
11999
+ parts: providerResults.map((toolCall) => ({
12000
+ type: "tool-invocation",
12001
+ toolInvocation: {
12002
+ state: "result",
12003
+ toolCallId: toolCall.toolCallId,
12004
+ toolName: toolCall.toolName,
12005
+ args: toolCall.args,
12006
+ result: toolCall.result
12007
+ },
12008
+ ...toolCall.providerMetadata ? { providerMetadata: toolCall.providerMetadata } : {},
12009
+ providerExecuted: true
12010
+ }))
12011
+ },
12012
+ createdAt: /* @__PURE__ */ new Date()
12013
+ };
12014
+ rest.messageList.add(providerMessage, "response");
12015
+ }
12022
12016
  }
12023
12017
  initialResult.stepResult.isContinued = true;
12024
12018
  initialResult.stepResult.reason = "tool-calls";
@@ -12061,32 +12055,60 @@ function createLLMMappingStep({ models, _internal, ...rest }, llmExecutionStep)
12061
12055
  const processed = await processAndEnqueueChunk(chunk);
12062
12056
  if (processed) await rest.options?.onChunk?.(processed);
12063
12057
  }
12064
- const toolResultMessageId = rest.experimental_generateMessageId?.() || _internal?.generateId?.();
12065
- const toolResultMessage = {
12066
- id: toolResultMessageId || "",
12067
- role: "assistant",
12068
- content: {
12069
- format: 2,
12070
- parts: await Promise.all(
12071
- inputData.map(async (toolCall) => {
12072
- const providerMetadata = await getProviderMetadataWithModelOutput(toolCall);
12073
- return {
12074
- type: "tool-invocation",
12075
- toolInvocation: {
12076
- state: "result",
12077
- toolCallId: toolCall.toolCallId,
12078
- toolName: toolCall.toolName,
12079
- args: toolCall.args,
12080
- result: toolCall.result
12081
- },
12082
- ...providerMetadata ? { providerMetadata } : {}
12083
- };
12084
- })
12085
- )
12086
- },
12087
- createdAt: /* @__PURE__ */ new Date()
12088
- };
12089
- rest.messageList.add(toolResultMessage, "response");
12058
+ const clientExecutedToolCalls = inputData.filter((toolCall) => !toolCall.providerExecuted);
12059
+ if (clientExecutedToolCalls.length > 0) {
12060
+ const toolResultMessageId = rest.experimental_generateMessageId?.() || _internal?.generateId?.();
12061
+ const toolResultMessage = {
12062
+ id: toolResultMessageId || "",
12063
+ role: "assistant",
12064
+ content: {
12065
+ format: 2,
12066
+ parts: await Promise.all(
12067
+ clientExecutedToolCalls.map(async (toolCall) => {
12068
+ const providerMetadata = await getProviderMetadataWithModelOutput(toolCall);
12069
+ return {
12070
+ type: "tool-invocation",
12071
+ toolInvocation: {
12072
+ state: "result",
12073
+ toolCallId: toolCall.toolCallId,
12074
+ toolName: toolCall.toolName,
12075
+ args: toolCall.args,
12076
+ result: toolCall.result
12077
+ },
12078
+ ...providerMetadata ? { providerMetadata } : {}
12079
+ };
12080
+ })
12081
+ )
12082
+ },
12083
+ createdAt: /* @__PURE__ */ new Date()
12084
+ };
12085
+ rest.messageList.add(toolResultMessage, "response");
12086
+ }
12087
+ const providerExecutedToolCalls = inputData.filter((toolCall) => toolCall.providerExecuted);
12088
+ if (providerExecutedToolCalls.length > 0) {
12089
+ const providerResultMessageId = rest.experimental_generateMessageId?.() || _internal?.generateId?.();
12090
+ const providerResultMessage = {
12091
+ id: providerResultMessageId || "",
12092
+ role: "assistant",
12093
+ content: {
12094
+ format: 2,
12095
+ parts: providerExecutedToolCalls.map((toolCall) => ({
12096
+ type: "tool-invocation",
12097
+ toolInvocation: {
12098
+ state: "result",
12099
+ toolCallId: toolCall.toolCallId,
12100
+ toolName: toolCall.toolName,
12101
+ args: toolCall.args,
12102
+ result: toolCall.result
12103
+ },
12104
+ ...toolCall.providerMetadata ? { providerMetadata: toolCall.providerMetadata } : {},
12105
+ providerExecuted: true
12106
+ }))
12107
+ },
12108
+ createdAt: /* @__PURE__ */ new Date()
12109
+ };
12110
+ rest.messageList.add(providerResultMessage, "response");
12111
+ }
12090
12112
  return {
12091
12113
  ...initialResult,
12092
12114
  messages: {
@@ -12259,7 +12281,7 @@ function createToolCallStep({
12259
12281
  if (inputData.providerExecuted) {
12260
12282
  return {
12261
12283
  ...inputData,
12262
- result: inputData.output
12284
+ result: inputData.output ?? { providerExecuted: true, toolName: inputData.toolName }
12263
12285
  };
12264
12286
  }
12265
12287
  if (!tool2) {
@@ -12497,6 +12519,14 @@ function createToolCallStep({
12497
12519
  args.suspendedToolRunId = suspendedToolRunId;
12498
12520
  }
12499
12521
  }
12522
+ if (args === null || args === void 0) {
12523
+ return {
12524
+ error: new Error(
12525
+ `Tool "${inputData.toolName}" received invalid arguments \u2014 the provided JSON could not be parsed. Please provide valid JSON arguments.`
12526
+ ),
12527
+ ...inputData
12528
+ };
12529
+ }
12500
12530
  const result = await tool2.execute(args, toolOptions);
12501
12531
  if (tool2 && "onOutput" in tool2 && typeof tool2.onOutput === "function") {
12502
12532
  try {
@@ -12688,15 +12718,13 @@ function createAgenticLoopWorkflow(params) {
12688
12718
  const hasSteps = (typedInputData.output?.steps?.length ?? 0) > 0;
12689
12719
  const shouldEmitStepFinish = typedInputData.stepResult?.reason !== "tripwire" || hasSteps;
12690
12720
  if (shouldEmitStepFinish) {
12691
- if (isControllerOpen(controller)) {
12692
- controller.enqueue({
12693
- type: "step-finish",
12694
- runId,
12695
- from: "AGENT" /* AGENT */,
12696
- // @ts-expect-error TODO: Look into the proper types for this
12697
- payload: typedInputData
12698
- });
12699
- }
12721
+ safeEnqueue(controller, {
12722
+ type: "step-finish",
12723
+ runId,
12724
+ from: "AGENT" /* AGENT */,
12725
+ // @ts-expect-error TODO: Look into the proper types for this
12726
+ payload: typedInputData
12727
+ });
12700
12728
  }
12701
12729
  const reason = typedInputData.stepResult?.reason;
12702
12730
  if (reason === void 0) {
@@ -12707,9 +12735,6 @@ function createAgenticLoopWorkflow(params) {
12707
12735
  }
12708
12736
 
12709
12737
  // src/loop/workflows/stream.ts
12710
- function isControllerOpen(controller) {
12711
- return controller.desiredSize !== 0 && controller.desiredSize !== null;
12712
- }
12713
12738
  function workflowLoopStream({
12714
12739
  resumeContext,
12715
12740
  requireToolApproval,
@@ -12748,7 +12773,7 @@ function workflowLoopStream({
12748
12773
  };
12749
12774
  messageList.add(message, "response");
12750
12775
  }
12751
- void controller.enqueue(chunk);
12776
+ safeEnqueue(controller, chunk);
12752
12777
  };
12753
12778
  const agenticLoopWorkflow = createAgenticLoopWorkflow({
12754
12779
  resumeContext,
@@ -12791,7 +12816,7 @@ function workflowLoopStream({
12791
12816
  }
12792
12817
  };
12793
12818
  if (!resumeContext) {
12794
- controller.enqueue({
12819
+ safeEnqueue(controller, {
12795
12820
  type: "start",
12796
12821
  runId,
12797
12822
  from: "AGENT" /* AGENT */,
@@ -12823,7 +12848,7 @@ function workflowLoopStream({
12823
12848
  const error = chunk4U7ZLI36_cjs.getErrorFromUnknown(executionResult.error, {
12824
12849
  fallbackMessage: "Unknown error in agent workflow stream"
12825
12850
  });
12826
- controller.enqueue({
12851
+ safeEnqueue(controller, {
12827
12852
  type: "error",
12828
12853
  runId,
12829
12854
  from: "AGENT" /* AGENT */,
@@ -12836,11 +12861,11 @@ function workflowLoopStream({
12836
12861
  if (executionResult.status !== "suspended") {
12837
12862
  await agenticLoopWorkflow.deleteWorkflowRunById(runId);
12838
12863
  }
12839
- controller.close();
12864
+ safeClose(controller);
12840
12865
  return;
12841
12866
  }
12842
12867
  await agenticLoopWorkflow.deleteWorkflowRunById(runId);
12843
- controller.enqueue({
12868
+ safeEnqueue(controller, {
12844
12869
  type: "finish",
12845
12870
  runId,
12846
12871
  from: "AGENT" /* AGENT */,
@@ -12853,7 +12878,7 @@ function workflowLoopStream({
12853
12878
  }
12854
12879
  }
12855
12880
  });
12856
- controller.close();
12881
+ safeClose(controller);
12857
12882
  }
12858
12883
  });
12859
12884
  }
@@ -13154,16 +13179,19 @@ var MastraScorer = class _MastraScorer {
13154
13179
  tracingContext
13155
13180
  });
13156
13181
  if (workflowResult.status === "failed") {
13157
- throw new chunk4U7ZLI36_cjs.MastraError({
13158
- id: "MASTR_SCORER_FAILED_TO_RUN_WORKFLOW_FAILED",
13159
- domain: "SCORER" /* SCORER */,
13160
- category: "USER" /* USER */,
13161
- text: `Scorer Run Failed: ${workflowResult.error}`,
13162
- details: {
13163
- scorerId: this.config.id ?? this.config.name,
13164
- steps: this.steps.map((s) => s.name).join(", ")
13165
- }
13166
- });
13182
+ throw new chunk4U7ZLI36_cjs.MastraError(
13183
+ {
13184
+ id: "MASTR_SCORER_FAILED_TO_RUN_WORKFLOW_FAILED",
13185
+ domain: "SCORER" /* SCORER */,
13186
+ category: "USER" /* USER */,
13187
+ text: `Scorer Run Failed: ${typeof workflowResult.error === "string" ? workflowResult.error : workflowResult.error.message}`,
13188
+ details: {
13189
+ scorerId: this.config.id ?? this.config.name,
13190
+ steps: this.steps.map((s) => s.name).join(", ")
13191
+ }
13192
+ },
13193
+ workflowResult.error instanceof Error ? workflowResult.error : void 0
13194
+ );
13167
13195
  }
13168
13196
  return this.transformToScorerResult({ workflowResult, originalInput: run });
13169
13197
  }
@@ -13242,6 +13270,7 @@ var MastraScorer = class _MastraScorer {
13242
13270
  validateInputs: false
13243
13271
  }
13244
13272
  });
13273
+ workflow.__setLogger(this.#mastra?.getLogger() ?? chunk6BJ7XHRH_cjs.noopLogger);
13245
13274
  let chainedWorkflow = workflow;
13246
13275
  for (const step of workflowSteps) {
13247
13276
  chainedWorkflow = chainedWorkflow.then(step);
@@ -13278,7 +13307,7 @@ var MastraScorer = class _MastraScorer {
13278
13307
  }
13279
13308
  });
13280
13309
  }
13281
- const resolvedModel = await chunkQSN5KQXZ_cjs.resolveModelConfig(modelConfig, void 0, this.#mastra);
13310
+ const resolvedModel = await chunkO7PZ4VOO_cjs.resolveModelConfig(modelConfig, void 0, this.#mastra);
13282
13311
  const judge = new Agent({
13283
13312
  id: "judge",
13284
13313
  name: "judge",
@@ -14193,7 +14222,7 @@ async function prepareMemoryStep({
14193
14222
  );
14194
14223
  }
14195
14224
  } else {
14196
- const messageList = new chunkYW54RH77_cjs.MessageList({
14225
+ const messageList = new chunkDB7U2C5B_cjs.MessageList({
14197
14226
  threadId: thread?.id,
14198
14227
  resourceId: thread?.resourceId
14199
14228
  });
@@ -14256,7 +14285,7 @@ async function saveMessagesWithProcessors(memory, messages, processorRunner, con
14256
14285
  await memory.saveMessages({ messages });
14257
14286
  return;
14258
14287
  }
14259
- const messageList = new chunkYW54RH77_cjs.MessageList();
14288
+ const messageList = new chunkDB7U2C5B_cjs.MessageList();
14260
14289
  for (const msg of messages) {
14261
14290
  messageList.add(msg, "response");
14262
14291
  }
@@ -15723,7 +15752,7 @@ async function networkLoop({
15723
15752
  "resumeData": "string"
15724
15753
  }
15725
15754
  `;
15726
- const messageList = new chunkYW54RH77_cjs.MessageList();
15755
+ const messageList = new chunkDB7U2C5B_cjs.MessageList();
15727
15756
  messageList.addSystem(systemInstructions);
15728
15757
  messageList.add(task, "user");
15729
15758
  const result = llm.stream({
@@ -15987,6 +16016,7 @@ async function networkLoop({
15987
16016
  { requestContext }
15988
16017
  );
15989
16018
  }
16019
+ await new Promise((resolve) => setTimeout(resolve, 10));
15990
16020
  if (isComplete) {
15991
16021
  return {
15992
16022
  ...inputData,
@@ -16361,7 +16391,7 @@ ${skillInstructions}`;
16361
16391
  message: `Reference file "${referencePath}" not found in skill "${skillName}". Available references: ${availableRefs.join(", ") || "none"}`
16362
16392
  };
16363
16393
  }
16364
- const result = chunkS4VVZI4E_cjs.extractLines(fullContent, startLine, endLine);
16394
+ const result = chunkAYHSPIT6_cjs.extractLines(fullContent, startLine, endLine);
16365
16395
  return {
16366
16396
  success: true,
16367
16397
  content: result.content,
@@ -16407,7 +16437,7 @@ ${skillInstructions}`;
16407
16437
  message: `Script file "${scriptPath}" not found in skill "${skillName}". Available scripts: ${availableScripts.join(", ") || "none"}`
16408
16438
  };
16409
16439
  }
16410
- const result = chunkS4VVZI4E_cjs.extractLines(fullContent, startLine, endLine);
16440
+ const result = chunkAYHSPIT6_cjs.extractLines(fullContent, startLine, endLine);
16411
16441
  return {
16412
16442
  success: true,
16413
16443
  content: result.content,
@@ -16663,7 +16693,7 @@ var AgentLegacyHandler = class {
16663
16693
  methodType: methodType === "generate" ? "generateLegacy" : "streamLegacy",
16664
16694
  memoryConfig
16665
16695
  });
16666
- let messageList = new chunkYW54RH77_cjs.MessageList({
16696
+ let messageList = new chunkDB7U2C5B_cjs.MessageList({
16667
16697
  threadId,
16668
16698
  resourceId,
16669
16699
  generateMessageId: this.capabilities.mastra?.generateId?.bind(this.capabilities.mastra),
@@ -16794,7 +16824,7 @@ var AgentLegacyHandler = class {
16794
16824
  result: resToLog,
16795
16825
  threadId
16796
16826
  });
16797
- const messageListResponses = new chunkYW54RH77_cjs.MessageList({
16827
+ const messageListResponses = new chunkDB7U2C5B_cjs.MessageList({
16798
16828
  threadId,
16799
16829
  resourceId,
16800
16830
  generateMessageId: this.capabilities.mastra?.generateId?.bind(this.capabilities.mastra),
@@ -17833,7 +17863,7 @@ var prepareToolsStepOutputSchema = z10.z.object({
17833
17863
  var prepareMemoryStepOutputSchema = z10.z.object({
17834
17864
  threadExists: z10.z.boolean(),
17835
17865
  thread: storageThreadSchema.optional(),
17836
- messageList: z10.z.instanceof(chunkYW54RH77_cjs.MessageList),
17866
+ messageList: z10.z.instanceof(chunkDB7U2C5B_cjs.MessageList),
17837
17867
  /** Shared processor states map that persists across loop iterations for both input and output processors */
17838
17868
  processorStates: z10.z.instanceof(Map),
17839
17869
  /** Tripwire data when input processor triggered abort */
@@ -17873,7 +17903,7 @@ function createPrepareMemoryStep({
17873
17903
  outputSchema: prepareMemoryStepOutputSchema,
17874
17904
  execute: async ({ tracingContext }) => {
17875
17905
  const thread = threadFromArgs;
17876
- const messageList = new chunkYW54RH77_cjs.MessageList({
17906
+ const messageList = new chunkDB7U2C5B_cjs.MessageList({
17877
17907
  threadId: thread?.id,
17878
17908
  resourceId,
17879
17909
  generateMessageId: capabilities.generateMessageId,
@@ -19151,7 +19181,7 @@ ${errorMessages}`,
19151
19181
  */
19152
19182
  async resolveModelConfig(modelConfig, requestContext) {
19153
19183
  try {
19154
- return await chunkQSN5KQXZ_cjs.resolveModelConfig(modelConfig, requestContext, this.#mastra);
19184
+ return await chunkO7PZ4VOO_cjs.resolveModelConfig(modelConfig, requestContext, this.#mastra);
19155
19185
  } catch (error) {
19156
19186
  const mastraError = new chunk4U7ZLI36_cjs.MastraError({
19157
19187
  id: "AGENT_GET_MODEL_MISSING_MODEL_INSTANCE",
@@ -19362,7 +19392,7 @@ ${errorMessages}`,
19362
19392
  instructions
19363
19393
  }) {
19364
19394
  const llm = await this.getLLM({ requestContext, model });
19365
- const normMessage = new chunkYW54RH77_cjs.MessageList().add(message, "user").get.all.ui().at(-1);
19395
+ const normMessage = new chunkDB7U2C5B_cjs.MessageList().add(message, "user").get.all.ui().at(-1);
19366
19396
  if (!normMessage) {
19367
19397
  throw new Error(`Could not generate title from input ${JSON.stringify(message)}`);
19368
19398
  }
@@ -19385,7 +19415,7 @@ ${errorMessages}`,
19385
19415
  const systemInstructions = await this.resolveTitleInstructions(requestContext, instructions);
19386
19416
  let text = "";
19387
19417
  if (isSupportedLanguageModel(llm.getModel())) {
19388
- const messageList = new chunkYW54RH77_cjs.MessageList().add(
19418
+ const messageList = new chunkDB7U2C5B_cjs.MessageList().add(
19389
19419
  [
19390
19420
  {
19391
19421
  role: "system",
@@ -19438,7 +19468,7 @@ ${errorMessages}`,
19438
19468
  async genTitle(userMessage, requestContext, tracingContext, model, instructions) {
19439
19469
  try {
19440
19470
  if (userMessage) {
19441
- const normMessage = new chunkYW54RH77_cjs.MessageList().add(userMessage, "user").get.all.ui().at(-1);
19471
+ const normMessage = new chunkDB7U2C5B_cjs.MessageList().add(userMessage, "user").get.all.ui().at(-1);
19442
19472
  if (normMessage) {
19443
19473
  return await this.generateTitleFromUserMessage({
19444
19474
  message: normMessage,
@@ -19542,7 +19572,7 @@ ${errorMessages}`,
19542
19572
  if (!workspace) {
19543
19573
  return convertedWorkspaceTools;
19544
19574
  }
19545
- const workspaceTools = chunkS4VVZI4E_cjs.createWorkspaceTools(workspace);
19575
+ const workspaceTools = chunkAYHSPIT6_cjs.createWorkspaceTools(workspace);
19546
19576
  if (Object.keys(workspaceTools).length > 0) {
19547
19577
  this.logger.debug(`[Agent:${this.name}] - Adding workspace tools: ${Object.keys(workspaceTools).join(", ")}`, {
19548
19578
  runId
@@ -20522,7 +20552,7 @@ ${errorMessages}`,
20522
20552
  throw mastraError;
20523
20553
  }
20524
20554
  let headers;
20525
- if (resolvedModel instanceof chunkQSN5KQXZ_cjs.ModelRouterLanguageModel) {
20555
+ if (resolvedModel instanceof chunkO7PZ4VOO_cjs.ModelRouterLanguageModel) {
20526
20556
  headers = resolvedModel.config?.headers;
20527
20557
  }
20528
20558
  return [
@@ -20568,7 +20598,7 @@ ${errorMessages}`,
20568
20598
  throw mastraError;
20569
20599
  }
20570
20600
  let headers;
20571
- if (model2 instanceof chunkQSN5KQXZ_cjs.ModelRouterLanguageModel) {
20601
+ if (model2 instanceof chunkO7PZ4VOO_cjs.ModelRouterLanguageModel) {
20572
20602
  headers = model2.config?.headers;
20573
20603
  }
20574
20604
  return {
@@ -23434,7 +23464,7 @@ var ToolSearchProcessor = class {
23434
23464
  minScore: options.search?.minScore ?? 0
23435
23465
  };
23436
23466
  this.ttl = options.ttl ?? 36e5;
23437
- this.bm25Index = new chunkS4VVZI4E_cjs.BM25Index({}, TOOL_SEARCH_TOKENIZE_OPTIONS);
23467
+ this.bm25Index = new chunkAYHSPIT6_cjs.BM25Index({}, TOOL_SEARCH_TOKENIZE_OPTIONS);
23438
23468
  this.indexTools();
23439
23469
  if (this.ttl > 0) {
23440
23470
  this.scheduleCleanup();
@@ -23853,6 +23883,7 @@ var MessageHistory = class {
23853
23883
  return messageList;
23854
23884
  }
23855
23885
  await this.persistMessages({ messages: messagesToSave, threadId, resourceId });
23886
+ await new Promise((resolve) => setTimeout(resolve, 10));
23856
23887
  return messageList;
23857
23888
  }
23858
23889
  /**
@@ -24181,7 +24212,7 @@ var SemanticRecall = class {
24181
24212
  */
24182
24213
  formatCrossThreadMessages(messages, currentThreadId) {
24183
24214
  let result = ``;
24184
- const v1Messages = new chunkYW54RH77_cjs.MessageList().add(messages, "memory").get.all.v1();
24215
+ const v1Messages = new chunkDB7U2C5B_cjs.MessageList().add(messages, "memory").get.all.v1();
24185
24216
  let lastYmd = null;
24186
24217
  for (const msg of v1Messages) {
24187
24218
  const date = msg.createdAt;
@@ -24623,7 +24654,7 @@ https://mastra.ai/en/docs/memory/semantic-recall`
24623
24654
  );
24624
24655
  }
24625
24656
  if (typeof config.embedder === "string") {
24626
- this.embedder = new chunkQSN5KQXZ_cjs.ModelRouterEmbeddingModel(config.embedder);
24657
+ this.embedder = new chunkO7PZ4VOO_cjs.ModelRouterEmbeddingModel(config.embedder);
24627
24658
  } else {
24628
24659
  this.embedder = config.embedder;
24629
24660
  }
@@ -24662,7 +24693,7 @@ https://mastra.ai/en/docs/memory/overview`
24662
24693
  }
24663
24694
  setEmbedder(embedder, embedderOptions) {
24664
24695
  if (typeof embedder === "string") {
24665
- this.embedder = new chunkQSN5KQXZ_cjs.ModelRouterEmbeddingModel(embedder);
24696
+ this.embedder = new chunkO7PZ4VOO_cjs.ModelRouterEmbeddingModel(embedder);
24666
24697
  } else {
24667
24698
  this.embedder = embedder;
24668
24699
  }
@@ -25108,7 +25139,7 @@ var MockMemory = class extends MastraMemory {
25108
25139
  } = {}) {
25109
25140
  super({
25110
25141
  name: "mock",
25111
- storage: storage || new chunkJZ6TH4HQ_cjs.InMemoryStore(),
25142
+ storage: storage || new chunkTL2TTA4X_cjs.InMemoryStore(),
25112
25143
  options: {
25113
25144
  workingMemory: enableWorkingMemory ? { enabled: true, template: workingMemoryTemplate } : void 0,
25114
25145
  lastMessages: enableMessageHistory ? 10 : void 0
@@ -25317,7 +25348,6 @@ exports.BaseProcessor = BaseProcessor;
25317
25348
  exports.BatchPartsProcessor = BatchPartsProcessor;
25318
25349
  exports.ChunkFrom = ChunkFrom;
25319
25350
  exports.DefaultExecutionEngine = DefaultExecutionEngine;
25320
- exports.EventEmitterPubSub = EventEmitterPubSub;
25321
25351
  exports.ExecutionEngine = ExecutionEngine;
25322
25352
  exports.FilePartSchema = FilePartSchema;
25323
25353
  exports.ImagePartSchema = ImagePartSchema;
@@ -25416,5 +25446,5 @@ exports.validateStepRequestContext = validateStepRequestContext;
25416
25446
  exports.validateStepResumeData = validateStepResumeData;
25417
25447
  exports.validateStepStateData = validateStepStateData;
25418
25448
  exports.validateStepSuspendData = validateStepSuspendData;
25419
- //# sourceMappingURL=chunk-7S6LA43E.cjs.map
25420
- //# sourceMappingURL=chunk-7S6LA43E.cjs.map
25449
+ //# sourceMappingURL=chunk-VJWRJWSC.cjs.map
25450
+ //# sourceMappingURL=chunk-VJWRJWSC.cjs.map