@mastra/core 1.0.0-beta.1 → 1.0.0-beta.10

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 (562) hide show
  1. package/CHANGELOG.md +1128 -0
  2. package/dist/agent/agent-legacy.d.ts +19 -22
  3. package/dist/agent/agent-legacy.d.ts.map +1 -1
  4. package/dist/agent/agent-types.test-d.d.ts +2 -0
  5. package/dist/agent/agent-types.test-d.d.ts.map +1 -0
  6. package/dist/agent/agent.d.ts +6 -6
  7. package/dist/agent/agent.d.ts.map +1 -1
  8. package/dist/agent/agent.types.d.ts +6 -4
  9. package/dist/agent/agent.types.d.ts.map +1 -1
  10. package/dist/agent/index.cjs +9 -9
  11. package/dist/agent/index.js +2 -2
  12. package/dist/agent/message-list/index.cjs +3 -3
  13. package/dist/agent/message-list/index.d.ts +60 -3
  14. package/dist/agent/message-list/index.d.ts.map +1 -1
  15. package/dist/agent/message-list/index.js +1 -1
  16. package/dist/agent/message-list/prompt/attachments-to-parts.d.ts.map +1 -1
  17. package/dist/agent/message-list/prompt/convert-file.d.ts +1 -1
  18. package/dist/agent/message-list/prompt/convert-file.d.ts.map +1 -1
  19. package/dist/agent/message-list/prompt/download-assets.d.ts.map +1 -1
  20. package/dist/agent/save-queue/index.d.ts +3 -1
  21. package/dist/agent/save-queue/index.d.ts.map +1 -1
  22. package/dist/agent/test-utils.d.ts +37 -0
  23. package/dist/agent/test-utils.d.ts.map +1 -1
  24. package/dist/agent/trip-wire.d.ts.map +1 -1
  25. package/dist/agent/types.d.ts +21 -6
  26. package/dist/agent/types.d.ts.map +1 -1
  27. package/dist/agent/utils.d.ts +3 -3
  28. package/dist/agent/utils.d.ts.map +1 -1
  29. package/dist/agent/workflows/prepare-stream/index.d.ts +9 -7
  30. package/dist/agent/workflows/prepare-stream/index.d.ts.map +1 -1
  31. package/dist/agent/workflows/prepare-stream/map-results-step.d.ts +3 -3
  32. package/dist/agent/workflows/prepare-stream/map-results-step.d.ts.map +1 -1
  33. package/dist/agent/workflows/prepare-stream/prepare-memory-step.d.ts +6 -5
  34. package/dist/agent/workflows/prepare-stream/prepare-memory-step.d.ts.map +1 -1
  35. package/dist/agent/workflows/prepare-stream/prepare-tools-step.d.ts +2 -1
  36. package/dist/agent/workflows/prepare-stream/prepare-tools-step.d.ts.map +1 -1
  37. package/dist/agent/workflows/prepare-stream/schema.d.ts +8 -8
  38. package/dist/agent/workflows/prepare-stream/schema.d.ts.map +1 -1
  39. package/dist/agent/workflows/prepare-stream/stream-step.d.ts +11 -1
  40. package/dist/agent/workflows/prepare-stream/stream-step.d.ts.map +1 -1
  41. package/dist/base.cjs +2 -2
  42. package/dist/base.js +1 -1
  43. package/dist/bundler/index.cjs +2 -2
  44. package/dist/bundler/index.js +1 -1
  45. package/dist/cache/index.cjs +3 -3
  46. package/dist/cache/index.js +1 -1
  47. package/dist/{chunk-4CDL2QJT.js → chunk-267YOF47.js} +121 -36
  48. package/dist/chunk-267YOF47.js.map +1 -0
  49. package/dist/{chunk-OJNJA5ZI.js → chunk-3CKZSDTQ.js} +3 -3
  50. package/dist/{chunk-OJNJA5ZI.js.map → chunk-3CKZSDTQ.js.map} +1 -1
  51. package/dist/{chunk-JV2KH24V.js → chunk-3GKKHF36.js} +693 -375
  52. package/dist/chunk-3GKKHF36.js.map +1 -0
  53. package/dist/{chunk-TQTAMPSC.js → chunk-3N3QE4ZK.js} +3 -3
  54. package/dist/chunk-3N3QE4ZK.js.map +1 -0
  55. package/dist/{chunk-QUKUN6NR.cjs → chunk-4JKEUSCC.cjs} +107 -7
  56. package/dist/chunk-4JKEUSCC.cjs.map +1 -0
  57. package/dist/{chunk-XEVG546F.js → chunk-4Q3Z6QRE.js} +178 -12
  58. package/dist/chunk-4Q3Z6QRE.js.map +1 -0
  59. package/dist/{chunk-CBAB7GOD.cjs → chunk-6BJ7XHRH.cjs} +2 -2
  60. package/dist/{chunk-CBAB7GOD.cjs.map → chunk-6BJ7XHRH.cjs.map} +1 -1
  61. package/dist/{chunk-JUBFO5J3.js → chunk-6CYYFT4O.js} +11378 -8189
  62. package/dist/chunk-6CYYFT4O.js.map +1 -0
  63. package/dist/{chunk-W7UH2PWL.js → chunk-6ONQWD6S.js} +1124 -325
  64. package/dist/chunk-6ONQWD6S.js.map +1 -0
  65. package/dist/{chunk-GRBGQ2GE.js → chunk-6TBWJV35.js} +5 -3
  66. package/dist/chunk-6TBWJV35.js.map +1 -0
  67. package/dist/chunk-6XCINXZ7.cjs +194 -0
  68. package/dist/chunk-6XCINXZ7.cjs.map +1 -0
  69. package/dist/{chunk-E7K4FTLN.cjs → chunk-72YCRTEX.cjs} +18 -2
  70. package/dist/chunk-72YCRTEX.cjs.map +1 -0
  71. package/dist/{chunk-MA7TEM62.cjs → chunk-7THRV5KZ.cjs} +762 -27
  72. package/dist/chunk-7THRV5KZ.cjs.map +1 -0
  73. package/dist/{chunk-76K3IYWM.js → chunk-ADADLFDR.js} +3 -3
  74. package/dist/{chunk-76K3IYWM.js.map → chunk-ADADLFDR.js.map} +1 -1
  75. package/dist/{chunk-DSNPWVIG.cjs → chunk-AF74UXR5.cjs} +4 -3
  76. package/dist/chunk-AF74UXR5.cjs.map +1 -0
  77. package/dist/{chunk-DNEURYF3.cjs → chunk-BCRRHJGV.cjs} +206 -65
  78. package/dist/chunk-BCRRHJGV.cjs.map +1 -0
  79. package/dist/chunk-BWYU7D33.js +192 -0
  80. package/dist/chunk-BWYU7D33.js.map +1 -0
  81. package/dist/{chunk-MV7KHWUT.js → chunk-BXONP7HX.js} +391 -15
  82. package/dist/chunk-BXONP7HX.js.map +1 -0
  83. package/dist/chunk-CDRYT2A5.js +513 -0
  84. package/dist/chunk-CDRYT2A5.js.map +1 -0
  85. package/dist/{chunk-CB575O6L.cjs → chunk-CZEJQSWB.cjs} +473 -124
  86. package/dist/chunk-CZEJQSWB.cjs.map +1 -0
  87. package/dist/chunk-DD2VNRQM.js +62 -0
  88. package/dist/chunk-DD2VNRQM.js.map +1 -0
  89. package/dist/{chunk-KEXGB7FK.cjs → chunk-DGV2FWB4.cjs} +7 -7
  90. package/dist/{chunk-KEXGB7FK.cjs.map → chunk-DGV2FWB4.cjs.map} +1 -1
  91. package/dist/{chunk-Y63IFHEZ.cjs → chunk-EOPEDKLG.cjs} +4 -4
  92. package/dist/chunk-EOPEDKLG.cjs.map +1 -0
  93. package/dist/{chunk-UIZSWUKP.js → chunk-F2GAJSBI.js} +105 -7
  94. package/dist/chunk-F2GAJSBI.js.map +1 -0
  95. package/dist/{chunk-VOY2RXOC.cjs → chunk-G4IFCTL5.cjs} +182 -15
  96. package/dist/chunk-G4IFCTL5.cjs.map +1 -0
  97. package/dist/chunk-KJBMTK5B.cjs +64 -0
  98. package/dist/chunk-KJBMTK5B.cjs.map +1 -0
  99. package/dist/{chunk-S6URFGCZ.js → chunk-LSHPJWM5.js} +3 -3
  100. package/dist/{chunk-S6URFGCZ.js.map → chunk-LSHPJWM5.js.map} +1 -1
  101. package/dist/chunk-MGCGWPQJ.cjs +275 -0
  102. package/dist/chunk-MGCGWPQJ.cjs.map +1 -0
  103. package/dist/chunk-MRFUISXC.cjs +4981 -0
  104. package/dist/chunk-MRFUISXC.cjs.map +1 -0
  105. package/dist/chunk-MSZP3FNH.cjs +518 -0
  106. package/dist/chunk-MSZP3FNH.cjs.map +1 -0
  107. package/dist/{chunk-KJ2SW6VA.js → chunk-NRUZYMHE.js} +4 -3
  108. package/dist/chunk-NRUZYMHE.js.map +1 -0
  109. package/dist/{chunk-VOQ3ULMT.js → chunk-NUA6TSRD.js} +752 -17
  110. package/dist/chunk-NUA6TSRD.js.map +1 -0
  111. package/dist/chunk-OEIVMCWX.js +4959 -0
  112. package/dist/chunk-OEIVMCWX.js.map +1 -0
  113. package/dist/{chunk-CINNK34N.js → chunk-OIDPIW42.js} +26 -11
  114. package/dist/chunk-OIDPIW42.js.map +1 -0
  115. package/dist/{chunk-CD56CXVE.cjs → chunk-OYIDRI3A.cjs} +32 -17
  116. package/dist/chunk-OYIDRI3A.cjs.map +1 -0
  117. package/dist/{chunk-2ZVKF4HP.cjs → chunk-P2D2VO2O.cjs} +1129 -328
  118. package/dist/chunk-P2D2VO2O.cjs.map +1 -0
  119. package/dist/{chunk-JPGVRWWL.js → chunk-PK2A5WBG.js} +472 -125
  120. package/dist/chunk-PK2A5WBG.js.map +1 -0
  121. package/dist/{chunk-X7JMA3IY.js → chunk-PSCMWPLC.js} +2 -2
  122. package/dist/{chunk-X7JMA3IY.js.map → chunk-PSCMWPLC.js.map} +1 -1
  123. package/dist/{chunk-WM6CK2F3.cjs → chunk-QD3UWFAV.cjs} +130 -48
  124. package/dist/chunk-QD3UWFAV.cjs.map +1 -0
  125. package/dist/{chunk-MSWTA73A.cjs → chunk-SL7Q6IZF.cjs} +11426 -8219
  126. package/dist/chunk-SL7Q6IZF.cjs.map +1 -0
  127. package/dist/{chunk-ECFXGXWO.cjs → chunk-SSPUH2N7.cjs} +693 -375
  128. package/dist/chunk-SSPUH2N7.cjs.map +1 -0
  129. package/dist/{chunk-BMAFVZ2D.cjs → chunk-T2VLUFGG.cjs} +4 -4
  130. package/dist/{chunk-BMAFVZ2D.cjs.map → chunk-T2VLUFGG.cjs.map} +1 -1
  131. package/dist/chunk-THZTRBFS.js +268 -0
  132. package/dist/chunk-THZTRBFS.js.map +1 -0
  133. package/dist/{chunk-Y6ROD72V.cjs → chunk-UIGRFDO6.cjs} +4 -4
  134. package/dist/{chunk-Y6ROD72V.cjs.map → chunk-UIGRFDO6.cjs.map} +1 -1
  135. package/dist/{chunk-J7O6WENZ.cjs → chunk-UVHSM2GU.cjs} +6 -2
  136. package/dist/chunk-UVHSM2GU.cjs.map +1 -0
  137. package/dist/{chunk-GGYKYORQ.cjs → chunk-WX2DLWXF.cjs} +407 -22
  138. package/dist/chunk-WX2DLWXF.cjs.map +1 -0
  139. package/dist/{chunk-H6CZGPZD.js → chunk-XRJQ5ZA7.js} +179 -38
  140. package/dist/chunk-XRJQ5ZA7.js.map +1 -0
  141. package/dist/{chunk-KIZIOFZC.js → chunk-Y36Y5MTD.js} +17 -3
  142. package/dist/chunk-Y36Y5MTD.js.map +1 -0
  143. package/dist/{chunk-IQO7ANVS.cjs → chunk-YWMMBIOM.cjs} +21 -20
  144. package/dist/chunk-YWMMBIOM.cjs.map +1 -0
  145. package/dist/{chunk-I4CXL4SR.js → chunk-Z57R5WS4.js} +16 -15
  146. package/dist/chunk-Z57R5WS4.js.map +1 -0
  147. package/dist/deployer/index.cjs +2 -2
  148. package/dist/deployer/index.js +1 -1
  149. package/dist/di/index.cjs +10 -2
  150. package/dist/di/index.d.ts +1 -1
  151. package/dist/di/index.d.ts.map +1 -1
  152. package/dist/di/index.js +1 -1
  153. package/dist/evals/base.d.ts +10 -2
  154. package/dist/evals/base.d.ts.map +1 -1
  155. package/dist/evals/base.test-utils.d.ts +25 -25
  156. package/dist/evals/index.cjs +9 -9
  157. package/dist/evals/index.js +2 -2
  158. package/dist/evals/scoreTraces/index.cjs +7 -6
  159. package/dist/evals/scoreTraces/index.cjs.map +1 -1
  160. package/dist/evals/scoreTraces/index.js +4 -3
  161. package/dist/evals/scoreTraces/index.js.map +1 -1
  162. package/dist/evals/scoreTraces/scoreTracesWorkflow.d.ts.map +1 -1
  163. package/dist/evals/types.d.ts +25 -24
  164. package/dist/evals/types.d.ts.map +1 -1
  165. package/dist/index.cjs +2 -2
  166. package/dist/index.js +1 -1
  167. package/dist/integration/index.cjs +2 -2
  168. package/dist/integration/index.js +1 -1
  169. package/dist/llm/index.cjs +30 -10
  170. package/dist/llm/index.d.ts +2 -0
  171. package/dist/llm/index.d.ts.map +1 -1
  172. package/dist/llm/index.js +5 -1
  173. package/dist/llm/model/aisdk/v5/model.d.ts +47 -0
  174. package/dist/llm/model/aisdk/v5/model.d.ts.map +1 -0
  175. package/dist/llm/model/gateway-resolver.d.ts.map +1 -1
  176. package/dist/llm/model/gateways/azure.d.ts +36 -0
  177. package/dist/llm/model/gateways/azure.d.ts.map +1 -0
  178. package/dist/llm/model/gateways/base.d.ts +9 -4
  179. package/dist/llm/model/gateways/base.d.ts.map +1 -1
  180. package/dist/llm/model/gateways/constants.d.ts.map +1 -1
  181. package/dist/llm/model/gateways/index.d.ts +4 -1
  182. package/dist/llm/model/gateways/index.d.ts.map +1 -1
  183. package/dist/llm/model/gateways/models-dev.d.ts +3 -2
  184. package/dist/llm/model/gateways/models-dev.d.ts.map +1 -1
  185. package/dist/llm/model/gateways/netlify.d.ts +4 -3
  186. package/dist/llm/model/gateways/netlify.d.ts.map +1 -1
  187. package/dist/llm/model/is-v2-model.d.ts +3 -0
  188. package/dist/llm/model/is-v2-model.d.ts.map +1 -0
  189. package/dist/llm/model/model-method-from-agent.d.ts +4 -0
  190. package/dist/llm/model/model-method-from-agent.d.ts.map +1 -0
  191. package/dist/llm/model/model.d.ts.map +1 -1
  192. package/dist/llm/model/model.loop.d.ts +2 -2
  193. package/dist/llm/model/model.loop.d.ts.map +1 -1
  194. package/dist/llm/model/model.loop.types.d.ts +2 -0
  195. package/dist/llm/model/model.loop.types.d.ts.map +1 -1
  196. package/dist/llm/model/provider-options.d.ts +4 -1
  197. package/dist/llm/model/provider-options.d.ts.map +1 -1
  198. package/dist/llm/model/provider-registry.d.ts +11 -1
  199. package/dist/llm/model/provider-registry.d.ts.map +1 -1
  200. package/dist/llm/model/provider-types.generated.d.ts +473 -24
  201. package/dist/llm/model/registry-generator.d.ts +12 -0
  202. package/dist/llm/model/registry-generator.d.ts.map +1 -1
  203. package/dist/llm/model/resolve-model.d.ts +1 -1
  204. package/dist/llm/model/resolve-model.d.ts.map +1 -1
  205. package/dist/llm/model/router.d.ts +12 -5
  206. package/dist/llm/model/router.d.ts.map +1 -1
  207. package/dist/llm/model/shared.types.d.ts +10 -4
  208. package/dist/llm/model/shared.types.d.ts.map +1 -1
  209. package/dist/logger/constants.d.ts +1 -0
  210. package/dist/logger/constants.d.ts.map +1 -1
  211. package/dist/logger/index.cjs +11 -11
  212. package/dist/logger/index.js +2 -2
  213. package/dist/logger/transport.d.ts +1 -1
  214. package/dist/logger/transport.d.ts.map +1 -1
  215. package/dist/loop/index.cjs +2 -2
  216. package/dist/loop/index.js +1 -1
  217. package/dist/loop/loop.d.ts.map +1 -1
  218. package/dist/loop/network/index.d.ts.map +1 -1
  219. package/dist/loop/test-utils/MastraLanguageModelV2Mock.d.ts +37 -0
  220. package/dist/loop/test-utils/MastraLanguageModelV2Mock.d.ts.map +1 -0
  221. package/dist/loop/test-utils/fullStream.d.ts.map +1 -1
  222. package/dist/loop/test-utils/generateText.d.ts.map +1 -1
  223. package/dist/loop/test-utils/options.d.ts.map +1 -1
  224. package/dist/loop/test-utils/resultObject.d.ts.map +1 -1
  225. package/dist/loop/test-utils/streamObject.d.ts.map +1 -1
  226. package/dist/loop/test-utils/textStream.d.ts.map +1 -1
  227. package/dist/loop/test-utils/toUIMessageStream.d.ts.map +1 -1
  228. package/dist/loop/test-utils/tools.d.ts.map +1 -1
  229. package/dist/loop/test-utils/utils.d.ts +1 -1
  230. package/dist/loop/test-utils/utils.d.ts.map +1 -1
  231. package/dist/loop/types.d.ts +22 -5
  232. package/dist/loop/types.d.ts.map +1 -1
  233. package/dist/loop/workflows/agentic-execution/index.d.ts +42 -42
  234. package/dist/loop/workflows/agentic-execution/index.d.ts.map +1 -1
  235. package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts +29 -29
  236. package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts.map +1 -1
  237. package/dist/loop/workflows/agentic-execution/llm-mapping-step.d.ts +14 -14
  238. package/dist/loop/workflows/agentic-execution/llm-mapping-step.d.ts.map +1 -1
  239. package/dist/loop/workflows/agentic-execution/tool-call-step.d.ts +1 -1
  240. package/dist/loop/workflows/agentic-execution/tool-call-step.d.ts.map +1 -1
  241. package/dist/loop/workflows/agentic-loop/index.d.ts +44 -43
  242. package/dist/loop/workflows/agentic-loop/index.d.ts.map +1 -1
  243. package/dist/loop/workflows/run-state.d.ts +2 -2
  244. package/dist/loop/workflows/run-state.d.ts.map +1 -1
  245. package/dist/loop/workflows/schema.d.ts +14 -14
  246. package/dist/loop/workflows/stream.d.ts +1 -1
  247. package/dist/loop/workflows/stream.d.ts.map +1 -1
  248. package/dist/mastra/index.cjs +2 -2
  249. package/dist/mastra/index.d.ts +377 -12
  250. package/dist/mastra/index.d.ts.map +1 -1
  251. package/dist/mastra/index.js +1 -1
  252. package/dist/mcp/index.cjs +4 -4
  253. package/dist/mcp/index.cjs.map +1 -1
  254. package/dist/mcp/index.d.ts +4 -4
  255. package/dist/mcp/index.d.ts.map +1 -1
  256. package/dist/mcp/index.js +2 -2
  257. package/dist/mcp/index.js.map +1 -1
  258. package/dist/mcp/types.d.ts +2 -2
  259. package/dist/mcp/types.d.ts.map +1 -1
  260. package/dist/memory/index.cjs +21 -327
  261. package/dist/memory/index.cjs.map +1 -1
  262. package/dist/memory/index.js +1 -327
  263. package/dist/memory/index.js.map +1 -1
  264. package/dist/memory/memory.d.ts +28 -18
  265. package/dist/memory/memory.d.ts.map +1 -1
  266. package/dist/memory/mock.d.ts +15 -14
  267. package/dist/memory/mock.d.ts.map +1 -1
  268. package/dist/memory/types.d.ts +69 -11
  269. package/dist/memory/types.d.ts.map +1 -1
  270. package/dist/models-dev-23RN2WHG.js +3 -0
  271. package/dist/{models-dev-DNBKXHT4.js.map → models-dev-23RN2WHG.js.map} +1 -1
  272. package/dist/models-dev-EO3SUIY2.cjs +12 -0
  273. package/dist/{models-dev-YBEEQIX6.cjs.map → models-dev-EO3SUIY2.cjs.map} +1 -1
  274. package/dist/netlify-GXJ5D5DD.js +3 -0
  275. package/dist/{netlify-7G2L5VSH.js.map → netlify-GXJ5D5DD.js.map} +1 -1
  276. package/dist/netlify-KJLY3GFS.cjs +12 -0
  277. package/dist/{netlify-GWNGSIRZ.cjs.map → netlify-KJLY3GFS.cjs.map} +1 -1
  278. package/dist/observability/index.cjs +16 -8
  279. package/dist/observability/index.js +1 -1
  280. package/dist/observability/types/tracing.d.ts +236 -13
  281. package/dist/observability/types/tracing.d.ts.map +1 -1
  282. package/dist/observability/utils.d.ts +47 -1
  283. package/dist/observability/utils.d.ts.map +1 -1
  284. package/dist/processors/index.cjs +35 -11
  285. package/dist/processors/index.d.ts +101 -23
  286. package/dist/processors/index.d.ts.map +1 -1
  287. package/dist/processors/index.js +1 -1
  288. package/dist/processors/memory/index.d.ts +7 -0
  289. package/dist/processors/memory/index.d.ts.map +1 -0
  290. package/dist/processors/memory/message-history.d.ts +43 -0
  291. package/dist/processors/memory/message-history.d.ts.map +1 -0
  292. package/dist/processors/memory/semantic-recall.d.ts +152 -0
  293. package/dist/processors/memory/semantic-recall.d.ts.map +1 -0
  294. package/dist/processors/memory/working-memory.d.ts +65 -0
  295. package/dist/processors/memory/working-memory.d.ts.map +1 -0
  296. package/dist/processors/processors/batch-parts.d.ts +1 -1
  297. package/dist/processors/processors/batch-parts.d.ts.map +1 -1
  298. package/dist/processors/processors/index.d.ts +2 -1
  299. package/dist/processors/processors/index.d.ts.map +1 -1
  300. package/dist/processors/processors/language-detector.d.ts +15 -1
  301. package/dist/processors/processors/language-detector.d.ts.map +1 -1
  302. package/dist/processors/processors/moderation.d.ts +15 -1
  303. package/dist/processors/processors/moderation.d.ts.map +1 -1
  304. package/dist/processors/processors/pii-detector.d.ts +15 -1
  305. package/dist/processors/processors/pii-detector.d.ts.map +1 -1
  306. package/dist/processors/processors/prompt-injection-detector.d.ts +15 -1
  307. package/dist/processors/processors/prompt-injection-detector.d.ts.map +1 -1
  308. package/dist/processors/processors/structured-output.d.ts +3 -2
  309. package/dist/processors/processors/structured-output.d.ts.map +1 -1
  310. package/dist/processors/processors/system-prompt-scrubber.d.ts +1 -1
  311. package/dist/processors/processors/system-prompt-scrubber.d.ts.map +1 -1
  312. package/dist/processors/processors/token-limiter.d.ts +22 -12
  313. package/dist/processors/processors/token-limiter.d.ts.map +1 -1
  314. package/dist/processors/processors/tool-call-filter.d.ts +28 -0
  315. package/dist/processors/processors/tool-call-filter.d.ts.map +1 -0
  316. package/dist/processors/processors/unicode-normalizer.d.ts +1 -1
  317. package/dist/processors/processors/unicode-normalizer.d.ts.map +1 -1
  318. package/dist/processors/runner.d.ts +35 -4
  319. package/dist/processors/runner.d.ts.map +1 -1
  320. package/dist/provider-registry-A7FILT6Q.cjs +40 -0
  321. package/dist/provider-registry-A7FILT6Q.cjs.map +1 -0
  322. package/dist/provider-registry-XM2YDI5X.js +3 -0
  323. package/dist/provider-registry-XM2YDI5X.js.map +1 -0
  324. package/dist/provider-registry.json +1038 -55
  325. package/dist/{registry-generator-MK63POJO.cjs → registry-generator-34SC4TAU.cjs} +23 -6
  326. package/dist/registry-generator-34SC4TAU.cjs.map +1 -0
  327. package/dist/{registry-generator-H4YNODDH.js → registry-generator-UMTNPBJX.js} +23 -7
  328. package/dist/registry-generator-UMTNPBJX.js.map +1 -0
  329. package/dist/relevance/index.cjs +2 -2
  330. package/dist/relevance/index.js +1 -1
  331. package/dist/request-context/index.cjs +10 -2
  332. package/dist/request-context/index.d.ts +26 -0
  333. package/dist/request-context/index.d.ts.map +1 -1
  334. package/dist/request-context/index.js +1 -1
  335. package/dist/server/auth.d.ts +11 -0
  336. package/dist/server/auth.d.ts.map +1 -1
  337. package/dist/server/base.d.ts +51 -0
  338. package/dist/server/base.d.ts.map +1 -0
  339. package/dist/server/composite-auth.d.ts +9 -0
  340. package/dist/server/composite-auth.d.ts.map +1 -0
  341. package/dist/server/index.cjs +124 -3
  342. package/dist/server/index.cjs.map +1 -1
  343. package/dist/server/index.d.ts +8 -0
  344. package/dist/server/index.d.ts.map +1 -1
  345. package/dist/server/index.js +121 -3
  346. package/dist/server/index.js.map +1 -1
  347. package/dist/server/simple-auth.d.ts +27 -0
  348. package/dist/server/simple-auth.d.ts.map +1 -0
  349. package/dist/storage/base.d.ts +76 -3
  350. package/dist/storage/base.d.ts.map +1 -1
  351. package/dist/storage/constants.d.ts +3 -1
  352. package/dist/storage/constants.d.ts.map +1 -1
  353. package/dist/storage/domains/agents/base.d.ts +49 -0
  354. package/dist/storage/domains/agents/base.d.ts.map +1 -0
  355. package/dist/storage/domains/agents/index.d.ts +3 -0
  356. package/dist/storage/domains/agents/index.d.ts.map +1 -0
  357. package/dist/storage/domains/agents/inmemory.d.ts +22 -0
  358. package/dist/storage/domains/agents/inmemory.d.ts.map +1 -0
  359. package/dist/storage/domains/index.d.ts +1 -0
  360. package/dist/storage/domains/index.d.ts.map +1 -1
  361. package/dist/storage/domains/memory/inmemory.d.ts.map +1 -1
  362. package/dist/storage/domains/operations/inmemory.d.ts.map +1 -1
  363. package/dist/storage/domains/scores/base.d.ts +2 -2
  364. package/dist/storage/domains/scores/base.d.ts.map +1 -1
  365. package/dist/storage/domains/scores/inmemory.d.ts +2 -2
  366. package/dist/storage/domains/scores/inmemory.d.ts.map +1 -1
  367. package/dist/storage/domains/workflows/base.d.ts +4 -0
  368. package/dist/storage/domains/workflows/base.d.ts.map +1 -1
  369. package/dist/storage/domains/workflows/inmemory.d.ts +5 -1
  370. package/dist/storage/domains/workflows/inmemory.d.ts.map +1 -1
  371. package/dist/storage/index.cjs +65 -29
  372. package/dist/storage/index.js +1 -1
  373. package/dist/storage/mock.d.ts +7 -2
  374. package/dist/storage/mock.d.ts.map +1 -1
  375. package/dist/storage/storageWithInit.d.ts.map +1 -1
  376. package/dist/storage/types.d.ts +85 -2
  377. package/dist/storage/types.d.ts.map +1 -1
  378. package/dist/storage/utils.d.ts +82 -0
  379. package/dist/storage/utils.d.ts.map +1 -1
  380. package/dist/stream/MastraAgentNetworkStream.d.ts +1 -1
  381. package/dist/stream/MastraAgentNetworkStream.d.ts.map +1 -1
  382. package/dist/stream/MastraWorkflowStream.d.ts +1 -1
  383. package/dist/stream/MastraWorkflowStream.d.ts.map +1 -1
  384. package/dist/stream/RunOutput.d.ts +2 -2
  385. package/dist/stream/RunOutput.d.ts.map +1 -1
  386. package/dist/stream/aisdk/v4/usage.d.ts +19 -0
  387. package/dist/stream/aisdk/v4/usage.d.ts.map +1 -0
  388. package/dist/stream/aisdk/v5/compat/prepare-tools.d.ts.map +1 -1
  389. package/dist/stream/aisdk/v5/execute.d.ts +8 -4
  390. package/dist/stream/aisdk/v5/execute.d.ts.map +1 -1
  391. package/dist/stream/aisdk/v5/input.d.ts +4 -1
  392. package/dist/stream/aisdk/v5/input.d.ts.map +1 -1
  393. package/dist/stream/aisdk/v5/output.d.ts +9 -9
  394. package/dist/stream/aisdk/v5/output.d.ts.map +1 -1
  395. package/dist/stream/aisdk/v5/transform.d.ts.map +1 -1
  396. package/dist/stream/base/base.d.ts +1 -1
  397. package/dist/stream/base/base.d.ts.map +1 -1
  398. package/dist/stream/base/input.d.ts +1 -1
  399. package/dist/stream/base/output-format-handlers.d.ts +14 -1
  400. package/dist/stream/base/output-format-handlers.d.ts.map +1 -1
  401. package/dist/stream/base/output.d.ts +3 -3
  402. package/dist/stream/base/output.d.ts.map +1 -1
  403. package/dist/stream/index.cjs +15 -11
  404. package/dist/stream/index.d.ts +2 -2
  405. package/dist/stream/index.d.ts.map +1 -1
  406. package/dist/stream/index.js +2 -2
  407. package/dist/stream/types.d.ts +48 -25
  408. package/dist/stream/types.d.ts.map +1 -1
  409. package/dist/test-utils/llm-mock.cjs +101 -30
  410. package/dist/test-utils/llm-mock.cjs.map +1 -1
  411. package/dist/test-utils/llm-mock.d.ts +7 -2
  412. package/dist/test-utils/llm-mock.d.ts.map +1 -1
  413. package/dist/test-utils/llm-mock.js +97 -30
  414. package/dist/test-utils/llm-mock.js.map +1 -1
  415. package/dist/tools/index.cjs +6 -6
  416. package/dist/tools/index.js +2 -2
  417. package/dist/tools/is-vercel-tool.cjs +2 -2
  418. package/dist/tools/is-vercel-tool.js +1 -1
  419. package/dist/tools/stream.d.ts +10 -4
  420. package/dist/tools/stream.d.ts.map +1 -1
  421. package/dist/tools/tool-builder/builder.d.ts +2 -0
  422. package/dist/tools/tool-builder/builder.d.ts.map +1 -1
  423. package/dist/tools/tool-stream-types.test-d.d.ts +2 -0
  424. package/dist/tools/tool-stream-types.test-d.d.ts.map +1 -0
  425. package/dist/tools/tool.d.ts +21 -8
  426. package/dist/tools/tool.d.ts.map +1 -1
  427. package/dist/tools/types.d.ts +33 -6
  428. package/dist/tools/types.d.ts.map +1 -1
  429. package/dist/tools/validation.d.ts +25 -1
  430. package/dist/tools/validation.d.ts.map +1 -1
  431. package/dist/tts/index.cjs +2 -2
  432. package/dist/tts/index.js +1 -1
  433. package/dist/types/zod-compat.d.ts +14 -1
  434. package/dist/types/zod-compat.d.ts.map +1 -1
  435. package/dist/utils.cjs +25 -21
  436. package/dist/utils.d.ts +9 -4
  437. package/dist/utils.d.ts.map +1 -1
  438. package/dist/utils.js +1 -1
  439. package/dist/vector/filter/index.cjs +7 -189
  440. package/dist/vector/filter/index.cjs.map +1 -1
  441. package/dist/vector/filter/index.js +1 -190
  442. package/dist/vector/filter/index.js.map +1 -1
  443. package/dist/vector/index.cjs +7 -2
  444. package/dist/vector/index.cjs.map +1 -1
  445. package/dist/vector/index.d.ts +1 -0
  446. package/dist/vector/index.d.ts.map +1 -1
  447. package/dist/vector/index.js +2 -1
  448. package/dist/vector/index.js.map +1 -1
  449. package/dist/vector/types.d.ts +86 -3
  450. package/dist/vector/types.d.ts.map +1 -1
  451. package/dist/vector/vector.d.ts +39 -2
  452. package/dist/vector/vector.d.ts.map +1 -1
  453. package/dist/voice/aisdk/index.d.ts +3 -0
  454. package/dist/voice/aisdk/index.d.ts.map +1 -0
  455. package/dist/voice/aisdk/speech.d.ts +23 -0
  456. package/dist/voice/aisdk/speech.d.ts.map +1 -0
  457. package/dist/voice/aisdk/transcription.d.ts +22 -0
  458. package/dist/voice/aisdk/transcription.d.ts.map +1 -0
  459. package/dist/voice/composite-voice.d.ts +4 -3
  460. package/dist/voice/composite-voice.d.ts.map +1 -1
  461. package/dist/voice/index.cjs +12 -4
  462. package/dist/voice/index.d.ts +1 -0
  463. package/dist/voice/index.d.ts.map +1 -1
  464. package/dist/voice/index.js +1 -1
  465. package/dist/workflows/default.d.ts +179 -270
  466. package/dist/workflows/default.d.ts.map +1 -1
  467. package/dist/workflows/evented/execution-engine.d.ts +3 -1
  468. package/dist/workflows/evented/execution-engine.d.ts.map +1 -1
  469. package/dist/workflows/evented/index.cjs +10 -10
  470. package/dist/workflows/evented/index.js +1 -1
  471. package/dist/workflows/evented/step-executor.d.ts +1 -1
  472. package/dist/workflows/evented/step-executor.d.ts.map +1 -1
  473. package/dist/workflows/evented/workflow-event-processor/index.d.ts +5 -4
  474. package/dist/workflows/evented/workflow-event-processor/index.d.ts.map +1 -1
  475. package/dist/workflows/evented/workflow-event-processor/loop.d.ts +1 -1
  476. package/dist/workflows/evented/workflow-event-processor/loop.d.ts.map +1 -1
  477. package/dist/workflows/evented/workflow-event-processor/parallel.d.ts +2 -2
  478. package/dist/workflows/evented/workflow-event-processor/parallel.d.ts.map +1 -1
  479. package/dist/workflows/evented/workflow-event-processor/sleep.d.ts +2 -2
  480. package/dist/workflows/evented/workflow-event-processor/sleep.d.ts.map +1 -1
  481. package/dist/workflows/evented/workflow.d.ts +2 -1
  482. package/dist/workflows/evented/workflow.d.ts.map +1 -1
  483. package/dist/workflows/execution-engine.d.ts +8 -6
  484. package/dist/workflows/execution-engine.d.ts.map +1 -1
  485. package/dist/workflows/handlers/control-flow.d.ts +133 -0
  486. package/dist/workflows/handlers/control-flow.d.ts.map +1 -0
  487. package/dist/workflows/handlers/entry.d.ts +43 -0
  488. package/dist/workflows/handlers/entry.d.ts.map +1 -0
  489. package/dist/workflows/handlers/sleep.d.ts +60 -0
  490. package/dist/workflows/handlers/sleep.d.ts.map +1 -0
  491. package/dist/workflows/handlers/step.d.ts +58 -0
  492. package/dist/workflows/handlers/step.d.ts.map +1 -0
  493. package/dist/workflows/index.cjs +36 -16
  494. package/dist/workflows/index.js +1 -1
  495. package/dist/workflows/step.d.ts +8 -6
  496. package/dist/workflows/step.d.ts.map +1 -1
  497. package/dist/workflows/types.d.ts +223 -10
  498. package/dist/workflows/types.d.ts.map +1 -1
  499. package/dist/workflows/utils.d.ts +36 -0
  500. package/dist/workflows/utils.d.ts.map +1 -1
  501. package/dist/workflows/workflow.d.ts +135 -54
  502. package/dist/workflows/workflow.d.ts.map +1 -1
  503. package/package.json +26 -30
  504. package/src/llm/model/provider-types.generated.d.ts +473 -24
  505. package/dist/chunk-2ZVKF4HP.cjs.map +0 -1
  506. package/dist/chunk-436FFEF6.js +0 -34
  507. package/dist/chunk-436FFEF6.js.map +0 -1
  508. package/dist/chunk-4CDL2QJT.js.map +0 -1
  509. package/dist/chunk-7AHYOMHJ.js +0 -149
  510. package/dist/chunk-7AHYOMHJ.js.map +0 -1
  511. package/dist/chunk-CB575O6L.cjs.map +0 -1
  512. package/dist/chunk-CD56CXVE.cjs.map +0 -1
  513. package/dist/chunk-CINNK34N.js.map +0 -1
  514. package/dist/chunk-DNEURYF3.cjs.map +0 -1
  515. package/dist/chunk-DSNPWVIG.cjs.map +0 -1
  516. package/dist/chunk-E7K4FTLN.cjs.map +0 -1
  517. package/dist/chunk-ECFXGXWO.cjs.map +0 -1
  518. package/dist/chunk-ET6UOTTU.cjs +0 -154
  519. package/dist/chunk-ET6UOTTU.cjs.map +0 -1
  520. package/dist/chunk-GGYKYORQ.cjs.map +0 -1
  521. package/dist/chunk-GRBGQ2GE.js.map +0 -1
  522. package/dist/chunk-H6CZGPZD.js.map +0 -1
  523. package/dist/chunk-HDJFSJCK.js +0 -2237
  524. package/dist/chunk-HDJFSJCK.js.map +0 -1
  525. package/dist/chunk-HGNRQ3OG.js +0 -58
  526. package/dist/chunk-HGNRQ3OG.js.map +0 -1
  527. package/dist/chunk-I4CXL4SR.js.map +0 -1
  528. package/dist/chunk-IQO7ANVS.cjs.map +0 -1
  529. package/dist/chunk-J7O6WENZ.cjs.map +0 -1
  530. package/dist/chunk-JPGVRWWL.js.map +0 -1
  531. package/dist/chunk-JUBFO5J3.js.map +0 -1
  532. package/dist/chunk-JV2KH24V.js.map +0 -1
  533. package/dist/chunk-KIZIOFZC.js.map +0 -1
  534. package/dist/chunk-KJ2SW6VA.js.map +0 -1
  535. package/dist/chunk-LJFJTTZQ.cjs +0 -4
  536. package/dist/chunk-LJFJTTZQ.cjs.map +0 -1
  537. package/dist/chunk-LRSB62Z6.cjs +0 -60
  538. package/dist/chunk-LRSB62Z6.cjs.map +0 -1
  539. package/dist/chunk-LWBQ4P4N.cjs +0 -2240
  540. package/dist/chunk-LWBQ4P4N.cjs.map +0 -1
  541. package/dist/chunk-MA7TEM62.cjs.map +0 -1
  542. package/dist/chunk-MSWTA73A.cjs.map +0 -1
  543. package/dist/chunk-MV7KHWUT.js.map +0 -1
  544. package/dist/chunk-QUKUN6NR.cjs.map +0 -1
  545. package/dist/chunk-TQTAMPSC.js.map +0 -1
  546. package/dist/chunk-UIZSWUKP.js.map +0 -1
  547. package/dist/chunk-V3VLOOSW.cjs +0 -36
  548. package/dist/chunk-V3VLOOSW.cjs.map +0 -1
  549. package/dist/chunk-VOQ3ULMT.js.map +0 -1
  550. package/dist/chunk-VOY2RXOC.cjs.map +0 -1
  551. package/dist/chunk-W7UH2PWL.js.map +0 -1
  552. package/dist/chunk-WM6CK2F3.cjs.map +0 -1
  553. package/dist/chunk-XEVG546F.js.map +0 -1
  554. package/dist/chunk-Y63IFHEZ.cjs.map +0 -1
  555. package/dist/chunk-ZV5CC35D.js +0 -3
  556. package/dist/chunk-ZV5CC35D.js.map +0 -1
  557. package/dist/models-dev-DNBKXHT4.js +0 -3
  558. package/dist/models-dev-YBEEQIX6.cjs +0 -12
  559. package/dist/netlify-7G2L5VSH.js +0 -3
  560. package/dist/netlify-GWNGSIRZ.cjs +0 -12
  561. package/dist/registry-generator-H4YNODDH.js.map +0 -1
  562. package/dist/registry-generator-MK63POJO.cjs.map +0 -1
@@ -1,15 +1,15 @@
1
1
  'use strict';
2
2
 
3
- var chunkDNEURYF3_cjs = require('./chunk-DNEURYF3.cjs');
4
- var chunkV3VLOOSW_cjs = require('./chunk-V3VLOOSW.cjs');
5
- var chunkBMAFVZ2D_cjs = require('./chunk-BMAFVZ2D.cjs');
3
+ var chunkBCRRHJGV_cjs = require('./chunk-BCRRHJGV.cjs');
4
+ var chunkT2VLUFGG_cjs = require('./chunk-T2VLUFGG.cjs');
6
5
  var chunk4D4KB75Y_cjs = require('./chunk-4D4KB75Y.cjs');
7
- var chunkCBAB7GOD_cjs = require('./chunk-CBAB7GOD.cjs');
6
+ var chunkSL7Q6IZF_cjs = require('./chunk-SL7Q6IZF.cjs');
7
+ var chunk6BJ7XHRH_cjs = require('./chunk-6BJ7XHRH.cjs');
8
8
  var chunkMR7ZWBL6_cjs = require('./chunk-MR7ZWBL6.cjs');
9
- var chunkE7K4FTLN_cjs = require('./chunk-E7K4FTLN.cjs');
9
+ var chunk72YCRTEX_cjs = require('./chunk-72YCRTEX.cjs');
10
10
  var chunkTWH4PTDG_cjs = require('./chunk-TWH4PTDG.cjs');
11
- var chunkY6ROD72V_cjs = require('./chunk-Y6ROD72V.cjs');
12
- var chunkDSNPWVIG_cjs = require('./chunk-DSNPWVIG.cjs');
11
+ var chunkUIGRFDO6_cjs = require('./chunk-UIGRFDO6.cjs');
12
+ var chunkAF74UXR5_cjs = require('./chunk-AF74UXR5.cjs');
13
13
  var crypto$1 = require('crypto');
14
14
  var EventEmitter = require('events');
15
15
  var pMap = require('p-map');
@@ -139,7 +139,7 @@ function createOnScorerHook(mastra) {
139
139
  };
140
140
  }
141
141
  async function validateAndSaveScore(storage, payload) {
142
- const payloadToSave = chunkBMAFVZ2D_cjs.saveScorePayloadSchema.parse(payload);
142
+ const payloadToSave = chunkT2VLUFGG_cjs.saveScorePayloadSchema.parse(payload);
143
143
  await storage?.saveScore(payloadToSave);
144
144
  }
145
145
  async function findScorer(mastra, entityId, entityType, scorerId) {
@@ -169,6 +169,17 @@ async function findScorer(mastra, entityId, entityType, scorerId) {
169
169
  }
170
170
 
171
171
  // src/mastra/index.ts
172
+ function createUndefinedPrimitiveError(type, value, key) {
173
+ const typeLabel = type === "mcp-server" ? "MCP server" : type;
174
+ const errorId = `MASTRA_ADD_${type.toUpperCase().replace("-", "_")}_UNDEFINED`;
175
+ return new chunkTWH4PTDG_cjs.MastraError({
176
+ id: errorId,
177
+ domain: "MASTRA" /* MASTRA */,
178
+ category: "USER" /* USER */,
179
+ text: `Cannot add ${typeLabel}: ${typeLabel} is ${value === null ? "null" : "undefined"}. This may occur if config was spread ({ ...config }) and the original object had getters or non-enumerable properties.`,
180
+ details: { status: 400, ...key && { key } }
181
+ });
182
+ }
172
183
  var Mastra = class {
173
184
  #vectors;
174
185
  #agents;
@@ -182,11 +193,14 @@ var Mastra = class {
182
193
  #scorers;
183
194
  #tools;
184
195
  #processors;
196
+ #memory;
185
197
  #server;
198
+ #serverAdapter;
186
199
  #mcpServers;
187
200
  #bundler;
188
201
  #idGenerator;
189
202
  #pubsub;
203
+ #gateways;
190
204
  #events = {};
191
205
  #internalMastraWorkflows = {};
192
206
  // This is only used internally for server handlers that require temporary persistence
@@ -285,7 +299,7 @@ var Mastra = class {
285
299
  * ```
286
300
  */
287
301
  constructor(config) {
288
- this.#serverCache = new chunkY6ROD72V_cjs.InMemoryServerCache();
302
+ this.#serverCache = new chunkUIGRFDO6_cjs.InMemoryServerCache();
289
303
  if (config?.pubsub) {
290
304
  this.#pubsub = config.pubsub;
291
305
  } else {
@@ -299,7 +313,7 @@ var Mastra = class {
299
313
  this.#events[topic] = config?.events?.[topic] ?? [];
300
314
  }
301
315
  }
302
- const workflowEventProcessor = new chunkDNEURYF3_cjs.WorkflowEventProcessor({ mastra: this });
316
+ const workflowEventProcessor = new chunkBCRRHJGV_cjs.WorkflowEventProcessor({ mastra: this });
303
317
  const workflowEventCb = async (event, cb) => {
304
318
  try {
305
319
  await workflowEventProcessor.process(event, cb);
@@ -314,20 +328,20 @@ var Mastra = class {
314
328
  }
315
329
  let logger;
316
330
  if (config?.logger === false) {
317
- logger = chunkCBAB7GOD_cjs.noopLogger;
331
+ logger = chunk6BJ7XHRH_cjs.noopLogger;
318
332
  } else {
319
333
  if (config?.logger) {
320
334
  logger = config.logger;
321
335
  } else {
322
- const levelOnEnv = process.env.NODE_ENV === "production" && process.env.MASTRA_DEV !== "true" ? chunkDSNPWVIG_cjs.LogLevel.WARN : chunkDSNPWVIG_cjs.LogLevel.INFO;
323
- logger = new chunkDSNPWVIG_cjs.ConsoleLogger({ name: "Mastra", level: levelOnEnv });
336
+ const levelOnEnv = process.env.NODE_ENV === "production" && process.env.MASTRA_DEV !== "true" ? chunkAF74UXR5_cjs.LogLevel.WARN : chunkAF74UXR5_cjs.LogLevel.INFO;
337
+ logger = new chunkAF74UXR5_cjs.ConsoleLogger({ name: "Mastra", level: levelOnEnv });
324
338
  }
325
339
  }
326
340
  this.#logger = logger;
327
341
  this.#idGenerator = config?.idGenerator;
328
342
  let storage = config?.storage;
329
343
  if (storage) {
330
- storage = chunkV3VLOOSW_cjs.augmentWithInit(storage);
344
+ storage = chunkSL7Q6IZF_cjs.augmentWithInit(storage);
331
345
  }
332
346
  if (config?.observability) {
333
347
  if (typeof config.observability.getDefaultInstance === "function") {
@@ -337,10 +351,10 @@ var Mastra = class {
337
351
  this.#logger?.warn(
338
352
  'Observability configuration error: Expected an Observability instance, but received a config object. Import and instantiate: import { Observability } from "@mastra/observability"; then pass: observability: new Observability({ default: { enabled: true } }). Observability has been disabled.'
339
353
  );
340
- this.#observability = new chunkE7K4FTLN_cjs.NoOpObservability();
354
+ this.#observability = new chunk72YCRTEX_cjs.NoOpObservability();
341
355
  }
342
356
  } else {
343
- this.#observability = new chunkE7K4FTLN_cjs.NoOpObservability();
357
+ this.#observability = new chunk72YCRTEX_cjs.NoOpObservability();
344
358
  }
345
359
  this.#storage = storage;
346
360
  this.#vectors = {};
@@ -350,45 +364,77 @@ var Mastra = class {
350
364
  this.#scorers = {};
351
365
  this.#tools = {};
352
366
  this.#processors = {};
367
+ this.#memory = {};
353
368
  this.#workflows = {};
369
+ this.#gateways = {};
354
370
  if (config?.tools) {
355
371
  Object.entries(config.tools).forEach(([key, tool]) => {
356
- this.addTool(tool, key);
372
+ if (tool != null) {
373
+ this.addTool(tool, key);
374
+ }
357
375
  });
358
376
  }
359
377
  if (config?.processors) {
360
378
  Object.entries(config.processors).forEach(([key, processor]) => {
361
- this.addProcessor(processor, key);
379
+ if (processor != null) {
380
+ this.addProcessor(processor, key);
381
+ }
382
+ });
383
+ }
384
+ if (config?.memory) {
385
+ Object.entries(config.memory).forEach(([key, memory]) => {
386
+ if (memory != null) {
387
+ this.addMemory(memory, key);
388
+ }
362
389
  });
363
390
  }
364
391
  if (config?.vectors) {
365
392
  Object.entries(config.vectors).forEach(([key, vector]) => {
366
- this.addVector(vector, key);
393
+ if (vector != null) {
394
+ this.addVector(vector, key);
395
+ }
367
396
  });
368
397
  }
369
398
  if (config?.scorers) {
370
399
  Object.entries(config.scorers).forEach(([key, scorer]) => {
371
- this.addScorer(scorer, key);
400
+ if (scorer != null) {
401
+ this.addScorer(scorer, key);
402
+ }
372
403
  });
373
404
  }
374
405
  if (config?.workflows) {
375
406
  Object.entries(config.workflows).forEach(([key, workflow]) => {
376
- this.addWorkflow(workflow, key);
407
+ if (workflow != null) {
408
+ this.addWorkflow(workflow, key);
409
+ }
410
+ });
411
+ }
412
+ if (config?.gateways) {
413
+ Object.entries(config.gateways).forEach(([key, gateway]) => {
414
+ if (gateway != null) {
415
+ this.addGateway(gateway, key);
416
+ }
377
417
  });
378
418
  }
379
419
  if (config?.mcpServers) {
380
420
  Object.entries(config.mcpServers).forEach(([key, server]) => {
381
- this.addMCPServer(server, key);
421
+ if (server != null) {
422
+ this.addMCPServer(server, key);
423
+ }
382
424
  });
383
425
  }
384
426
  if (config?.agents) {
385
427
  Object.entries(config.agents).forEach(([key, agent]) => {
386
- this.addAgent(agent, key);
428
+ if (agent != null) {
429
+ this.addAgent(agent, key);
430
+ }
387
431
  });
388
432
  }
389
433
  if (config?.tts) {
390
434
  Object.entries(config.tts).forEach(([key, tts]) => {
391
- this.#tts[key] = tts;
435
+ if (tts != null) {
436
+ this.#tts[key] = tts;
437
+ }
392
438
  });
393
439
  }
394
440
  if (config?.server) {
@@ -512,6 +558,241 @@ var Mastra = class {
512
558
  listAgents() {
513
559
  return this.#agents;
514
560
  }
561
+ async getStoredAgentById(id, options) {
562
+ const storage = this.#storage;
563
+ if (!storage) {
564
+ const error = new chunkTWH4PTDG_cjs.MastraError({
565
+ id: "MASTRA_GET_STORED_AGENT_STORAGE_NOT_CONFIGURED",
566
+ domain: "MASTRA" /* MASTRA */,
567
+ category: "USER" /* USER */,
568
+ text: "Storage is not configured",
569
+ details: { status: 400 }
570
+ });
571
+ this.#logger?.trackException(error);
572
+ throw error;
573
+ }
574
+ if (!storage.supports.agents) {
575
+ const error = new chunkTWH4PTDG_cjs.MastraError({
576
+ id: "MASTRA_GET_STORED_AGENT_NOT_SUPPORTED",
577
+ domain: "MASTRA" /* MASTRA */,
578
+ category: "USER" /* USER */,
579
+ text: "Storage does not support agents",
580
+ details: { status: 400 }
581
+ });
582
+ this.#logger?.trackException(error);
583
+ throw error;
584
+ }
585
+ const storedAgent = await storage.getAgentById({ id });
586
+ if (!storedAgent) {
587
+ return null;
588
+ }
589
+ if (options?.raw) {
590
+ return storedAgent;
591
+ }
592
+ return this.#createAgentFromStoredConfig(storedAgent);
593
+ }
594
+ async listStoredAgents(args) {
595
+ const storage = this.#storage;
596
+ if (!storage) {
597
+ const error = new chunkTWH4PTDG_cjs.MastraError({
598
+ id: "MASTRA_LIST_STORED_AGENTS_STORAGE_NOT_CONFIGURED",
599
+ domain: "MASTRA" /* MASTRA */,
600
+ category: "USER" /* USER */,
601
+ text: "Storage is not configured",
602
+ details: { status: 400 }
603
+ });
604
+ this.#logger?.trackException(error);
605
+ throw error;
606
+ }
607
+ if (!storage.supports.agents) {
608
+ const error = new chunkTWH4PTDG_cjs.MastraError({
609
+ id: "MASTRA_LIST_STORED_AGENTS_NOT_SUPPORTED",
610
+ domain: "MASTRA" /* MASTRA */,
611
+ category: "USER" /* USER */,
612
+ text: "Storage does not support agents",
613
+ details: { status: 400 }
614
+ });
615
+ this.#logger?.trackException(error);
616
+ throw error;
617
+ }
618
+ const result = await storage.listAgents({
619
+ page: args?.page,
620
+ perPage: args?.perPage,
621
+ orderBy: args?.orderBy
622
+ });
623
+ if (args?.raw) {
624
+ return result;
625
+ }
626
+ const agents = result.agents.map((storedAgent) => this.#createAgentFromStoredConfig(storedAgent));
627
+ return {
628
+ agents,
629
+ total: result.total,
630
+ page: result.page,
631
+ perPage: result.perPage,
632
+ hasMore: result.hasMore
633
+ };
634
+ }
635
+ /**
636
+ * Creates an Agent instance from a stored agent configuration.
637
+ * @private
638
+ */
639
+ #createAgentFromStoredConfig(storedAgent) {
640
+ const modelConfig = storedAgent.model;
641
+ if (!modelConfig.provider || !modelConfig.name) {
642
+ throw new chunkTWH4PTDG_cjs.MastraError({
643
+ id: "MASTRA_STORED_AGENT_INVALID_MODEL",
644
+ domain: "MASTRA" /* MASTRA */,
645
+ category: "USER" /* USER */,
646
+ text: `Stored agent "${storedAgent.id}" has invalid model configuration. Both provider and name are required.`,
647
+ details: { agentId: storedAgent.id, model: JSON.stringify(storedAgent.model) }
648
+ });
649
+ }
650
+ const model = `${modelConfig.provider}/${modelConfig.name}`;
651
+ const tools = this.#resolveStoredTools(storedAgent.tools);
652
+ const workflows = this.#resolveStoredWorkflows(storedAgent.workflows);
653
+ const agents = this.#resolveStoredAgents(storedAgent.agents);
654
+ const memory = this.#resolveStoredMemory(storedAgent.memory);
655
+ const scorers = this.#resolveStoredScorers(storedAgent.scorers);
656
+ const agent = new chunkSL7Q6IZF_cjs.Agent({
657
+ id: storedAgent.id,
658
+ name: storedAgent.name,
659
+ description: storedAgent.description,
660
+ instructions: storedAgent.instructions,
661
+ model,
662
+ tools,
663
+ workflows,
664
+ agents,
665
+ memory,
666
+ scorers,
667
+ defaultOptions: storedAgent.defaultOptions
668
+ });
669
+ agent.__setLogger(this.#logger);
670
+ agent.__registerMastra(this);
671
+ agent.__registerPrimitives({
672
+ logger: this.getLogger(),
673
+ storage: this.getStorage(),
674
+ agents: this.#agents,
675
+ tts: this.#tts,
676
+ vectors: this.#vectors
677
+ });
678
+ return agent;
679
+ }
680
+ /**
681
+ * Resolves tool references from stored configuration to actual tool instances.
682
+ * @private
683
+ */
684
+ #resolveStoredTools(storedTools) {
685
+ if (!storedTools || storedTools.length === 0) {
686
+ return {};
687
+ }
688
+ const resolvedTools = {};
689
+ const registeredTools = this.#tools;
690
+ for (const toolKey of storedTools) {
691
+ if (registeredTools && registeredTools[toolKey]) {
692
+ resolvedTools[toolKey] = registeredTools[toolKey];
693
+ } else {
694
+ this.#logger?.warn(`Tool "${toolKey}" referenced in stored agent but not registered in Mastra`);
695
+ }
696
+ }
697
+ return resolvedTools;
698
+ }
699
+ /**
700
+ * Resolves workflow references from stored configuration to actual workflow instances.
701
+ * @private
702
+ */
703
+ #resolveStoredWorkflows(storedWorkflows) {
704
+ if (!storedWorkflows || storedWorkflows.length === 0) {
705
+ return {};
706
+ }
707
+ const resolvedWorkflows = {};
708
+ for (const workflowKey of storedWorkflows) {
709
+ try {
710
+ const workflow = this.getWorkflow(workflowKey);
711
+ resolvedWorkflows[workflowKey] = workflow;
712
+ } catch {
713
+ try {
714
+ const workflow = this.getWorkflowById(workflowKey);
715
+ resolvedWorkflows[workflowKey] = workflow;
716
+ } catch {
717
+ this.#logger?.warn(`Workflow "${workflowKey}" referenced in stored agent but not registered in Mastra`);
718
+ }
719
+ }
720
+ }
721
+ return resolvedWorkflows;
722
+ }
723
+ /**
724
+ * Resolves agent references from stored configuration to actual agent instances.
725
+ * @private
726
+ */
727
+ #resolveStoredAgents(storedAgents) {
728
+ if (!storedAgents || storedAgents.length === 0) {
729
+ return {};
730
+ }
731
+ const resolvedAgents = {};
732
+ for (const agentKey of storedAgents) {
733
+ try {
734
+ const agent = this.getAgent(agentKey);
735
+ resolvedAgents[agentKey] = agent;
736
+ } catch {
737
+ try {
738
+ const agent = this.getAgentById(agentKey);
739
+ resolvedAgents[agentKey] = agent;
740
+ } catch {
741
+ this.#logger?.warn(`Agent "${agentKey}" referenced in stored agent but not registered in Mastra`);
742
+ }
743
+ }
744
+ }
745
+ return resolvedAgents;
746
+ }
747
+ /**
748
+ * Resolves memory reference from stored configuration to actual memory instance.
749
+ * @private
750
+ */
751
+ #resolveStoredMemory(storedMemory) {
752
+ if (!storedMemory) {
753
+ return void 0;
754
+ }
755
+ try {
756
+ return this.getMemory(storedMemory);
757
+ } catch {
758
+ try {
759
+ return this.getMemoryById(storedMemory);
760
+ } catch {
761
+ this.#logger?.warn(`Memory "${storedMemory}" referenced in stored agent but not registered in Mastra`);
762
+ }
763
+ }
764
+ return void 0;
765
+ }
766
+ /**
767
+ * Resolves scorer references from stored configuration to actual scorer instances.
768
+ * @private
769
+ */
770
+ #resolveStoredScorers(storedScorers) {
771
+ if (!storedScorers) {
772
+ return void 0;
773
+ }
774
+ const resolvedScorers = {};
775
+ for (const [scorerKey, scorerConfig] of Object.entries(storedScorers)) {
776
+ try {
777
+ const scorer = this.getScorer(scorerKey);
778
+ resolvedScorers[scorerKey] = {
779
+ scorer,
780
+ sampling: scorerConfig.sampling
781
+ };
782
+ } catch {
783
+ try {
784
+ const scorer = this.getScorerById(scorerKey);
785
+ resolvedScorers[scorerKey] = {
786
+ scorer,
787
+ sampling: scorerConfig.sampling
788
+ };
789
+ } catch {
790
+ this.#logger?.warn(`Scorer "${scorerKey}" referenced in stored agent but not registered in Mastra`);
791
+ }
792
+ }
793
+ }
794
+ return Object.keys(resolvedScorers).length > 0 ? resolvedScorers : void 0;
795
+ }
515
796
  /**
516
797
  * Adds a new agent to the Mastra instance.
517
798
  *
@@ -534,6 +815,9 @@ var Mastra = class {
534
815
  * ```
535
816
  */
536
817
  addAgent(agent, key) {
818
+ if (!agent) {
819
+ throw createUndefinedPrimitiveError("agent", agent, key);
820
+ }
537
821
  const agentKey = key || agent.id;
538
822
  const agents = this.#agents;
539
823
  if (agents[agentKey]) {
@@ -696,6 +980,9 @@ var Mastra = class {
696
980
  * ```
697
981
  */
698
982
  addVector(vector, key) {
983
+ if (!vector) {
984
+ throw createUndefinedPrimitiveError("vector", vector, key);
985
+ }
699
986
  const vectorKey = key || vector.id;
700
987
  const vectors = this.#vectors;
701
988
  if (vectors[vectorKey]) {
@@ -866,6 +1153,44 @@ var Mastra = class {
866
1153
  }
867
1154
  return workflow;
868
1155
  }
1156
+ async listActiveWorkflowRuns() {
1157
+ const storage = this.#storage;
1158
+ if (!storage) {
1159
+ this.#logger.debug("Cannot get active workflow runs. Mastra storage is not initialized");
1160
+ return { runs: [], total: 0 };
1161
+ }
1162
+ const defaultEngineWorkflows = Object.values(this.#workflows).filter((workflow) => workflow.engineType === "default");
1163
+ const allRuns = [];
1164
+ let allTotal = 0;
1165
+ for (const workflow of defaultEngineWorkflows) {
1166
+ const runningRuns = await workflow.listWorkflowRuns({ status: "running" });
1167
+ const waitingRuns = await workflow.listWorkflowRuns({ status: "waiting" });
1168
+ allRuns.push(...runningRuns.runs, ...waitingRuns.runs);
1169
+ allTotal += runningRuns.total + waitingRuns.total;
1170
+ }
1171
+ return {
1172
+ runs: allRuns,
1173
+ total: allTotal
1174
+ };
1175
+ }
1176
+ async restartAllActiveWorkflowRuns() {
1177
+ const activeRuns = await this.listActiveWorkflowRuns();
1178
+ if (activeRuns.runs.length > 0) {
1179
+ this.#logger.debug(
1180
+ `Restarting ${activeRuns.runs.length} active workflow run${activeRuns.runs.length > 1 ? "s" : ""}`
1181
+ );
1182
+ }
1183
+ for (const runSnapshot of activeRuns.runs) {
1184
+ const workflow = this.getWorkflowById(runSnapshot.workflowName);
1185
+ try {
1186
+ const run = await workflow.createRun({ runId: runSnapshot.runId });
1187
+ await run.restart();
1188
+ this.#logger.debug(`Restarted ${runSnapshot.workflowName} workflow run ${runSnapshot.runId}`);
1189
+ } catch (error) {
1190
+ this.#logger.error(`Failed to restart ${runSnapshot.workflowName} workflow run ${runSnapshot.runId}: ${error}`);
1191
+ }
1192
+ }
1193
+ }
869
1194
  /**
870
1195
  * Returns all registered scorers as a record keyed by their IDs.
871
1196
  *
@@ -914,6 +1239,9 @@ var Mastra = class {
914
1239
  * ```
915
1240
  */
916
1241
  addScorer(scorer, key) {
1242
+ if (!scorer) {
1243
+ throw createUndefinedPrimitiveError("scorer", scorer, key);
1244
+ }
917
1245
  const scorerKey = key || scorer.id;
918
1246
  const scorers = this.#scorers;
919
1247
  if (scorers[scorerKey]) {
@@ -921,6 +1249,7 @@ var Mastra = class {
921
1249
  logger.debug(`Scorer with key ${scorerKey} already exists. Skipping addition.`);
922
1250
  return;
923
1251
  }
1252
+ scorer.__registerMastra(this);
924
1253
  scorers[scorerKey] = scorer;
925
1254
  }
926
1255
  /**
@@ -1141,6 +1470,9 @@ var Mastra = class {
1141
1470
  * ```
1142
1471
  */
1143
1472
  addTool(tool, key) {
1473
+ if (!tool) {
1474
+ throw createUndefinedPrimitiveError("tool", tool, key);
1475
+ }
1144
1476
  const toolKey = key || tool.id;
1145
1477
  const tools = this.#tools;
1146
1478
  if (tools[toolKey]) {
@@ -1276,6 +1608,9 @@ var Mastra = class {
1276
1608
  * ```
1277
1609
  */
1278
1610
  addProcessor(processor, key) {
1611
+ if (!processor) {
1612
+ throw createUndefinedPrimitiveError("processor", processor, key);
1613
+ }
1279
1614
  const processorKey = key || processor.id;
1280
1615
  const processors = this.#processors;
1281
1616
  if (processors[processorKey]) {
@@ -1285,6 +1620,131 @@ var Mastra = class {
1285
1620
  }
1286
1621
  processors[processorKey] = processor;
1287
1622
  }
1623
+ /**
1624
+ * Retrieves a registered memory instance by its registration key.
1625
+ *
1626
+ * @throws {MastraError} When the memory instance with the specified key is not found
1627
+ *
1628
+ * @example
1629
+ * ```typescript
1630
+ * const mastra = new Mastra({
1631
+ * memory: {
1632
+ * chat: new Memory({ storage })
1633
+ * }
1634
+ * });
1635
+ *
1636
+ * const chatMemory = mastra.getMemory('chat');
1637
+ * ```
1638
+ */
1639
+ getMemory(name) {
1640
+ if (!this.#memory || !this.#memory[name]) {
1641
+ const error = new chunkTWH4PTDG_cjs.MastraError({
1642
+ id: "MASTRA_GET_MEMORY_BY_KEY_NOT_FOUND",
1643
+ domain: "MASTRA" /* MASTRA */,
1644
+ category: "USER" /* USER */,
1645
+ text: `Memory with key ${String(name)} not found`,
1646
+ details: {
1647
+ status: 404,
1648
+ memoryKey: String(name),
1649
+ memory: Object.keys(this.#memory ?? {}).join(", ")
1650
+ }
1651
+ });
1652
+ this.#logger?.trackException(error);
1653
+ throw error;
1654
+ }
1655
+ return this.#memory[name];
1656
+ }
1657
+ /**
1658
+ * Retrieves a registered memory instance by its ID.
1659
+ *
1660
+ * Searches through all registered memory instances and returns the one whose ID matches.
1661
+ *
1662
+ * @throws {MastraError} When no memory instance with the specified ID is found
1663
+ *
1664
+ * @example
1665
+ * ```typescript
1666
+ * const mastra = new Mastra({
1667
+ * memory: {
1668
+ * chat: new Memory({ id: 'chat-memory', storage })
1669
+ * }
1670
+ * });
1671
+ *
1672
+ * const memory = mastra.getMemoryById('chat-memory');
1673
+ * ```
1674
+ */
1675
+ getMemoryById(id) {
1676
+ const allMemory = this.#memory;
1677
+ if (allMemory) {
1678
+ for (const [, memory] of Object.entries(allMemory)) {
1679
+ if (memory.id === id) {
1680
+ return memory;
1681
+ }
1682
+ }
1683
+ }
1684
+ const error = new chunkTWH4PTDG_cjs.MastraError({
1685
+ id: "MASTRA_GET_MEMORY_BY_ID_NOT_FOUND",
1686
+ domain: "MASTRA" /* MASTRA */,
1687
+ category: "USER" /* USER */,
1688
+ text: `Memory with id ${id} not found`,
1689
+ details: {
1690
+ status: 404,
1691
+ memoryId: id,
1692
+ availableIds: Object.values(allMemory ?? {}).map((m) => m.id).join(", ")
1693
+ }
1694
+ });
1695
+ this.#logger?.trackException(error);
1696
+ throw error;
1697
+ }
1698
+ /**
1699
+ * Returns all registered memory instances as a record keyed by their names.
1700
+ *
1701
+ * @example
1702
+ * ```typescript
1703
+ * const mastra = new Mastra({
1704
+ * memory: {
1705
+ * chat: new Memory({ storage }),
1706
+ * longTerm: new Memory({ storage })
1707
+ * }
1708
+ * });
1709
+ *
1710
+ * const allMemory = mastra.listMemory();
1711
+ * console.log(Object.keys(allMemory)); // ['chat', 'longTerm']
1712
+ * ```
1713
+ */
1714
+ listMemory() {
1715
+ return this.#memory;
1716
+ }
1717
+ /**
1718
+ * Adds a new memory instance to the Mastra instance.
1719
+ *
1720
+ * This method allows dynamic registration of memory instances after the Mastra instance
1721
+ * has been created.
1722
+ *
1723
+ * @example
1724
+ * ```typescript
1725
+ * const mastra = new Mastra();
1726
+ * const chatMemory = new Memory({
1727
+ * id: 'chat-memory',
1728
+ * storage: mastra.getStorage()
1729
+ * });
1730
+ * mastra.addMemory(chatMemory); // Uses memory.id as key
1731
+ * // or
1732
+ * mastra.addMemory(chatMemory, 'customKey'); // Uses custom key
1733
+ * ```
1734
+ */
1735
+ addMemory(memory, key) {
1736
+ if (!memory) {
1737
+ throw createUndefinedPrimitiveError("memory", memory, key);
1738
+ }
1739
+ const memoryKey = key || memory.id;
1740
+ const memoryRegistry = this.#memory;
1741
+ if (memoryRegistry[memoryKey]) {
1742
+ const logger = this.getLogger();
1743
+ logger.debug(`Memory with key ${memoryKey} already exists. Skipping addition.`);
1744
+ return;
1745
+ }
1746
+ memoryRegistry[memoryKey] = memory;
1747
+ }
1288
1748
  /**
1289
1749
  * Returns all registered workflows as a record keyed by their IDs.
1290
1750
  *
@@ -1340,6 +1800,9 @@ var Mastra = class {
1340
1800
  * ```
1341
1801
  */
1342
1802
  addWorkflow(workflow, key) {
1803
+ if (!workflow) {
1804
+ throw createUndefinedPrimitiveError("workflow", workflow, key);
1805
+ }
1343
1806
  const workflowKey = key || workflow.id;
1344
1807
  const workflows = this.#workflows;
1345
1808
  if (workflows[workflowKey]) {
@@ -1352,6 +1815,9 @@ var Mastra = class {
1352
1815
  logger: this.getLogger(),
1353
1816
  storage: this.getStorage()
1354
1817
  });
1818
+ if (!workflow.committed) {
1819
+ workflow.commit();
1820
+ }
1355
1821
  workflows[workflowKey] = workflow;
1356
1822
  }
1357
1823
  /**
@@ -1375,7 +1841,7 @@ var Mastra = class {
1375
1841
  * ```
1376
1842
  */
1377
1843
  setStorage(storage) {
1378
- this.#storage = chunkV3VLOOSW_cjs.augmentWithInit(storage);
1844
+ this.#storage = chunkSL7Q6IZF_cjs.augmentWithInit(storage);
1379
1845
  }
1380
1846
  setLogger({ logger }) {
1381
1847
  this.#logger = logger;
@@ -1405,6 +1871,9 @@ var Mastra = class {
1405
1871
  this.#mcpServers?.[key]?.__setLogger(this.#logger);
1406
1872
  });
1407
1873
  }
1874
+ if (this.#serverAdapter) {
1875
+ this.#serverAdapter.__setLogger(this.#logger);
1876
+ }
1408
1877
  this.#observability.setLogger({ logger: this.#logger });
1409
1878
  }
1410
1879
  /**
@@ -1518,6 +1987,74 @@ var Mastra = class {
1518
1987
  getServer() {
1519
1988
  return this.#server;
1520
1989
  }
1990
+ /**
1991
+ * Sets the server adapter for this Mastra instance.
1992
+ *
1993
+ * The server adapter provides access to the underlying server app (e.g., Hono, Express)
1994
+ * and allows users to call routes directly via `app.fetch()` instead of making HTTP requests.
1995
+ *
1996
+ * This is typically called by `createHonoServer` or similar factory functions during
1997
+ * server initialization.
1998
+ *
1999
+ * @param adapter - The server adapter instance (e.g., MastraServer from @mastra/hono or @mastra/express)
2000
+ *
2001
+ * @example
2002
+ * ```typescript
2003
+ * const app = new Hono();
2004
+ * const adapter = new MastraServer({ app, mastra });
2005
+ * mastra.setMastraServer(adapter);
2006
+ * ```
2007
+ */
2008
+ setMastraServer(adapter) {
2009
+ if (this.#serverAdapter) {
2010
+ this.#logger?.debug(
2011
+ "Replacing existing server adapter. Only one adapter should be registered per Mastra instance."
2012
+ );
2013
+ }
2014
+ this.#serverAdapter = adapter;
2015
+ if (this.#logger) {
2016
+ adapter.__setLogger(this.#logger);
2017
+ }
2018
+ }
2019
+ /**
2020
+ * Gets the server adapter for this Mastra instance.
2021
+ *
2022
+ * @returns The server adapter, or undefined if not set
2023
+ *
2024
+ * @example
2025
+ * ```typescript
2026
+ * const adapter = mastra.getMastraServer();
2027
+ * if (adapter) {
2028
+ * const app = adapter.getApp<Hono>();
2029
+ * }
2030
+ * ```
2031
+ */
2032
+ getMastraServer() {
2033
+ return this.#serverAdapter;
2034
+ }
2035
+ /**
2036
+ * Gets the server app from the server adapter.
2037
+ *
2038
+ * This is a convenience method that calls `getMastraServer()?.getApp<T>()`.
2039
+ * Use this to access the underlying server framework's app instance (e.g., Hono, Express)
2040
+ * for direct operations like calling routes via `app.fetch()`.
2041
+ *
2042
+ * @template T - The expected type of the app (e.g., Hono, Express Application)
2043
+ * @returns The server app, or undefined if no adapter is set
2044
+ *
2045
+ * @example
2046
+ * ```typescript
2047
+ * // After createHonoServer() is called:
2048
+ * const app = mastra.getServerApp<Hono>();
2049
+ *
2050
+ * // Call routes directly without HTTP overhead
2051
+ * const response = await app?.fetch(new Request('http://localhost/health'));
2052
+ * const data = await response?.json();
2053
+ * ```
2054
+ */
2055
+ getServerApp() {
2056
+ return this.#serverAdapter?.getApp();
2057
+ }
1521
2058
  getBundlerConfig() {
1522
2059
  return this.#bundler;
1523
2060
  }
@@ -1641,6 +2178,9 @@ var Mastra = class {
1641
2178
  * ```
1642
2179
  */
1643
2180
  addMCPServer(server, key) {
2181
+ if (!server) {
2182
+ throw createUndefinedPrimitiveError("mcp-server", server, key);
2183
+ }
1644
2184
  if (key) {
1645
2185
  server.setId(key);
1646
2186
  }
@@ -1785,6 +2325,201 @@ var Mastra = class {
1785
2325
  }
1786
2326
  await this.#pubsub.flush();
1787
2327
  }
2328
+ /**
2329
+ * Retrieves a registered gateway by its key.
2330
+ *
2331
+ * @throws {MastraError} When the gateway with the specified key is not found
2332
+ *
2333
+ * @example
2334
+ * ```typescript
2335
+ * const mastra = new Mastra({
2336
+ * gateways: {
2337
+ * myGateway: new CustomGateway()
2338
+ * }
2339
+ * });
2340
+ *
2341
+ * const gateway = mastra.getGateway('myGateway');
2342
+ * ```
2343
+ */
2344
+ getGateway(key) {
2345
+ const gateway = this.#gateways?.[key];
2346
+ if (!gateway) {
2347
+ const error = new chunkTWH4PTDG_cjs.MastraError({
2348
+ id: "MASTRA_GET_GATEWAY_BY_KEY_NOT_FOUND",
2349
+ domain: "MASTRA" /* MASTRA */,
2350
+ category: "USER" /* USER */,
2351
+ text: `Gateway with key ${key} not found`,
2352
+ details: {
2353
+ status: 404,
2354
+ gatewayKey: key,
2355
+ gateways: Object.keys(this.#gateways ?? {}).join(", ")
2356
+ }
2357
+ });
2358
+ this.#logger?.trackException(error);
2359
+ throw error;
2360
+ }
2361
+ return gateway;
2362
+ }
2363
+ /**
2364
+ * Retrieves a registered gateway by its ID.
2365
+ *
2366
+ * Searches through all registered gateways and returns the one whose ID matches.
2367
+ * If a gateway doesn't have an explicit ID, its name is used as the ID.
2368
+ *
2369
+ * @throws {MastraError} When no gateway with the specified ID is found
2370
+ *
2371
+ * @example
2372
+ * ```typescript
2373
+ * class CustomGateway extends MastraModelGateway {
2374
+ * readonly id = 'custom-gateway-v1';
2375
+ * readonly name = 'Custom Gateway';
2376
+ * // ...
2377
+ * }
2378
+ *
2379
+ * const mastra = new Mastra({
2380
+ * gateways: {
2381
+ * myGateway: new CustomGateway()
2382
+ * }
2383
+ * });
2384
+ *
2385
+ * const gateway = mastra.getGatewayById('custom-gateway-v1');
2386
+ * ```
2387
+ */
2388
+ getGatewayById(id) {
2389
+ const gateways = this.#gateways ?? {};
2390
+ for (const gateway of Object.values(gateways)) {
2391
+ if (gateway.getId() === id) {
2392
+ return gateway;
2393
+ }
2394
+ }
2395
+ const error = new chunkTWH4PTDG_cjs.MastraError({
2396
+ id: "MASTRA_GET_GATEWAY_BY_ID_NOT_FOUND",
2397
+ domain: "MASTRA" /* MASTRA */,
2398
+ category: "USER" /* USER */,
2399
+ text: `Gateway with ID ${id} not found`,
2400
+ details: {
2401
+ status: 404,
2402
+ gatewayId: id,
2403
+ availableIds: Object.values(gateways).map((g) => g.getId()).join(", ")
2404
+ }
2405
+ });
2406
+ this.#logger?.trackException(error);
2407
+ throw error;
2408
+ }
2409
+ /**
2410
+ * Returns all registered gateways as a record keyed by their names.
2411
+ *
2412
+ * @example
2413
+ * ```typescript
2414
+ * const mastra = new Mastra({
2415
+ * gateways: {
2416
+ * netlify: new NetlifyGateway(),
2417
+ * custom: new CustomGateway()
2418
+ * }
2419
+ * });
2420
+ *
2421
+ * const allGateways = mastra.listGateways();
2422
+ * console.log(Object.keys(allGateways)); // ['netlify', 'custom']
2423
+ * ```
2424
+ */
2425
+ listGateways() {
2426
+ return this.#gateways;
2427
+ }
2428
+ /**
2429
+ * Adds a new gateway to the Mastra instance.
2430
+ *
2431
+ * This method allows dynamic registration of gateways after the Mastra instance
2432
+ * has been created. Gateways enable access to LLM providers through custom
2433
+ * authentication and routing logic.
2434
+ *
2435
+ * If no key is provided, the gateway's ID (or name if no ID is set) will be used as the key.
2436
+ *
2437
+ * @example
2438
+ * ```typescript
2439
+ * import { MastraModelGateway } from '@mastra/core';
2440
+ *
2441
+ * class CustomGateway extends MastraModelGateway {
2442
+ * readonly id = 'custom-gateway-v1'; // Optional, defaults to name
2443
+ * readonly name = 'custom';
2444
+ * readonly prefix = 'custom';
2445
+ *
2446
+ * async fetchProviders() {
2447
+ * return {
2448
+ * myProvider: {
2449
+ * name: 'My Provider',
2450
+ * models: ['model-1', 'model-2'],
2451
+ * apiKeyEnvVar: 'MY_API_KEY',
2452
+ * gateway: 'custom'
2453
+ * }
2454
+ * };
2455
+ * }
2456
+ *
2457
+ * buildUrl(modelId: string) {
2458
+ * return 'https://api.myprovider.com/v1';
2459
+ * }
2460
+ *
2461
+ * async getApiKey(modelId: string) {
2462
+ * return process.env.MY_API_KEY || '';
2463
+ * }
2464
+ *
2465
+ * async resolveLanguageModel({ modelId, providerId, apiKey }) {
2466
+ * const baseURL = this.buildUrl(`${providerId}/${modelId}`);
2467
+ * return createOpenAICompatible({
2468
+ * name: providerId,
2469
+ * apiKey,
2470
+ * baseURL,
2471
+ * supportsStructuredOutputs: true,
2472
+ * }).chatModel(modelId);
2473
+ * }
2474
+ * }
2475
+ *
2476
+ * const mastra = new Mastra();
2477
+ * const newGateway = new CustomGateway();
2478
+ * mastra.addGateway(newGateway); // Uses gateway.getId() as key (gateway.id)
2479
+ * // or
2480
+ * mastra.addGateway(newGateway, 'customKey'); // Uses custom key
2481
+ * ```
2482
+ */
2483
+ addGateway(gateway, key) {
2484
+ if (!gateway) {
2485
+ throw createUndefinedPrimitiveError("gateway", gateway, key);
2486
+ }
2487
+ const gatewayKey = key || gateway.getId();
2488
+ const gateways = this.#gateways;
2489
+ if (gateways[gatewayKey]) {
2490
+ const logger = this.getLogger();
2491
+ logger.debug(`Gateway with key ${gatewayKey} already exists. Skipping addition.`);
2492
+ return;
2493
+ }
2494
+ gateways[gatewayKey] = gateway;
2495
+ this.#syncGatewayRegistry();
2496
+ }
2497
+ /**
2498
+ * Sync custom gateways with the GatewayRegistry for type generation
2499
+ * @private
2500
+ */
2501
+ #syncGatewayRegistry() {
2502
+ try {
2503
+ if (process.env.MASTRA_DEV !== "true" && process.env.MASTRA_DEV !== "1") {
2504
+ return;
2505
+ }
2506
+ import('./provider-registry-A7FILT6Q.cjs').then(async ({ GatewayRegistry }) => {
2507
+ const registry = GatewayRegistry.getInstance();
2508
+ const customGateways = Object.values(this.#gateways || {});
2509
+ registry.registerCustomGateways(customGateways);
2510
+ const logger = this.getLogger();
2511
+ logger.info("\u{1F504} Syncing custom gateway types...");
2512
+ await registry.syncGateways(true);
2513
+ logger.info("\u2705 Custom gateway types synced! Restart your TypeScript server to see autocomplete.");
2514
+ }).catch((err) => {
2515
+ const logger = this.getLogger();
2516
+ logger.debug("Gateway registry sync skipped:", err);
2517
+ });
2518
+ } catch (err) {
2519
+ const logger = this.getLogger();
2520
+ logger.debug("Gateway registry sync failed:", err);
2521
+ }
2522
+ }
1788
2523
  /**
1789
2524
  * Gracefully shuts down the Mastra instance and cleans up all resources.
1790
2525
  *
@@ -1822,5 +2557,5 @@ var Mastra = class {
1822
2557
  };
1823
2558
 
1824
2559
  exports.Mastra = Mastra;
1825
- //# sourceMappingURL=chunk-MA7TEM62.cjs.map
1826
- //# sourceMappingURL=chunk-MA7TEM62.cjs.map
2560
+ //# sourceMappingURL=chunk-7THRV5KZ.cjs.map
2561
+ //# sourceMappingURL=chunk-7THRV5KZ.cjs.map