@mastra/core 1.0.0-beta.0 → 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.
- package/CHANGELOG.md +1136 -0
- package/dist/agent/agent-legacy.d.ts +19 -22
- package/dist/agent/agent-legacy.d.ts.map +1 -1
- package/dist/agent/agent-types.test-d.d.ts +2 -0
- package/dist/agent/agent-types.test-d.d.ts.map +1 -0
- package/dist/agent/agent.d.ts +6 -6
- package/dist/agent/agent.d.ts.map +1 -1
- package/dist/agent/agent.types.d.ts +6 -4
- package/dist/agent/agent.types.d.ts.map +1 -1
- package/dist/agent/index.cjs +9 -9
- package/dist/agent/index.js +2 -2
- package/dist/agent/message-list/index.cjs +3 -3
- package/dist/agent/message-list/index.d.ts +60 -3
- package/dist/agent/message-list/index.d.ts.map +1 -1
- package/dist/agent/message-list/index.js +1 -1
- package/dist/agent/message-list/prompt/attachments-to-parts.d.ts.map +1 -1
- package/dist/agent/message-list/prompt/convert-file.d.ts +1 -1
- package/dist/agent/message-list/prompt/convert-file.d.ts.map +1 -1
- package/dist/agent/message-list/prompt/download-assets.d.ts.map +1 -1
- package/dist/agent/save-queue/index.d.ts +3 -1
- package/dist/agent/save-queue/index.d.ts.map +1 -1
- package/dist/agent/test-utils.d.ts +37 -0
- package/dist/agent/test-utils.d.ts.map +1 -1
- package/dist/agent/trip-wire.d.ts.map +1 -1
- package/dist/agent/types.d.ts +21 -6
- package/dist/agent/types.d.ts.map +1 -1
- package/dist/agent/utils.d.ts +3 -3
- package/dist/agent/utils.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/index.d.ts +9 -7
- package/dist/agent/workflows/prepare-stream/index.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/map-results-step.d.ts +3 -3
- package/dist/agent/workflows/prepare-stream/map-results-step.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/prepare-memory-step.d.ts +6 -5
- package/dist/agent/workflows/prepare-stream/prepare-memory-step.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/prepare-tools-step.d.ts +2 -1
- package/dist/agent/workflows/prepare-stream/prepare-tools-step.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/schema.d.ts +8 -8
- package/dist/agent/workflows/prepare-stream/schema.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/stream-step.d.ts +11 -1
- package/dist/agent/workflows/prepare-stream/stream-step.d.ts.map +1 -1
- package/dist/base.cjs +2 -2
- package/dist/base.js +1 -1
- package/dist/bundler/index.cjs +2 -2
- package/dist/bundler/index.js +1 -1
- package/dist/cache/index.cjs +3 -3
- package/dist/cache/index.js +1 -1
- package/dist/{chunk-4CDL2QJT.js → chunk-267YOF47.js} +121 -36
- package/dist/chunk-267YOF47.js.map +1 -0
- package/dist/{chunk-OJNJA5ZI.js → chunk-3CKZSDTQ.js} +3 -3
- package/dist/{chunk-OJNJA5ZI.js.map → chunk-3CKZSDTQ.js.map} +1 -1
- package/dist/{chunk-JV2KH24V.js → chunk-3GKKHF36.js} +693 -375
- package/dist/chunk-3GKKHF36.js.map +1 -0
- package/dist/{chunk-TQTAMPSC.js → chunk-3N3QE4ZK.js} +3 -3
- package/dist/chunk-3N3QE4ZK.js.map +1 -0
- package/dist/{chunk-QUKUN6NR.cjs → chunk-4JKEUSCC.cjs} +107 -7
- package/dist/chunk-4JKEUSCC.cjs.map +1 -0
- package/dist/{chunk-XEVG546F.js → chunk-4Q3Z6QRE.js} +178 -12
- package/dist/chunk-4Q3Z6QRE.js.map +1 -0
- package/dist/{chunk-CBAB7GOD.cjs → chunk-6BJ7XHRH.cjs} +2 -2
- package/dist/{chunk-CBAB7GOD.cjs.map → chunk-6BJ7XHRH.cjs.map} +1 -1
- package/dist/{chunk-26SQQNMU.js → chunk-6CYYFT4O.js} +11389 -8193
- package/dist/chunk-6CYYFT4O.js.map +1 -0
- package/dist/{chunk-32CTMD2C.js → chunk-6ONQWD6S.js} +1221 -347
- package/dist/chunk-6ONQWD6S.js.map +1 -0
- package/dist/{chunk-J7O6WENZ.cjs → chunk-6TBWJV35.js} +5 -5
- package/dist/chunk-6TBWJV35.js.map +1 -0
- package/dist/chunk-6XCINXZ7.cjs +194 -0
- package/dist/chunk-6XCINXZ7.cjs.map +1 -0
- package/dist/{chunk-E7K4FTLN.cjs → chunk-72YCRTEX.cjs} +18 -2
- package/dist/chunk-72YCRTEX.cjs.map +1 -0
- package/dist/{chunk-BXOL277H.cjs → chunk-7THRV5KZ.cjs} +762 -27
- package/dist/chunk-7THRV5KZ.cjs.map +1 -0
- package/dist/{chunk-76K3IYWM.js → chunk-ADADLFDR.js} +3 -3
- package/dist/{chunk-76K3IYWM.js.map → chunk-ADADLFDR.js.map} +1 -1
- package/dist/{chunk-DSNPWVIG.cjs → chunk-AF74UXR5.cjs} +4 -3
- package/dist/chunk-AF74UXR5.cjs.map +1 -0
- package/dist/{chunk-QCQLOMJM.cjs → chunk-BCRRHJGV.cjs} +206 -65
- package/dist/chunk-BCRRHJGV.cjs.map +1 -0
- package/dist/chunk-BWYU7D33.js +192 -0
- package/dist/chunk-BWYU7D33.js.map +1 -0
- package/dist/{chunk-MV7KHWUT.js → chunk-BXONP7HX.js} +391 -15
- package/dist/chunk-BXONP7HX.js.map +1 -0
- package/dist/chunk-CDRYT2A5.js +513 -0
- package/dist/chunk-CDRYT2A5.js.map +1 -0
- package/dist/{chunk-S5MJLXMG.cjs → chunk-CZEJQSWB.cjs} +481 -124
- package/dist/chunk-CZEJQSWB.cjs.map +1 -0
- package/dist/chunk-DD2VNRQM.js +62 -0
- package/dist/chunk-DD2VNRQM.js.map +1 -0
- package/dist/{chunk-KEXGB7FK.cjs → chunk-DGV2FWB4.cjs} +7 -7
- package/dist/{chunk-KEXGB7FK.cjs.map → chunk-DGV2FWB4.cjs.map} +1 -1
- package/dist/{chunk-Y63IFHEZ.cjs → chunk-EOPEDKLG.cjs} +4 -4
- package/dist/chunk-EOPEDKLG.cjs.map +1 -0
- package/dist/{chunk-UIZSWUKP.js → chunk-F2GAJSBI.js} +105 -7
- package/dist/chunk-F2GAJSBI.js.map +1 -0
- package/dist/{chunk-VOY2RXOC.cjs → chunk-G4IFCTL5.cjs} +182 -15
- package/dist/chunk-G4IFCTL5.cjs.map +1 -0
- package/dist/chunk-KJBMTK5B.cjs +64 -0
- package/dist/chunk-KJBMTK5B.cjs.map +1 -0
- package/dist/{chunk-S6URFGCZ.js → chunk-LSHPJWM5.js} +3 -3
- package/dist/{chunk-S6URFGCZ.js.map → chunk-LSHPJWM5.js.map} +1 -1
- package/dist/chunk-MGCGWPQJ.cjs +275 -0
- package/dist/chunk-MGCGWPQJ.cjs.map +1 -0
- package/dist/chunk-MRFUISXC.cjs +4981 -0
- package/dist/chunk-MRFUISXC.cjs.map +1 -0
- package/dist/chunk-MSZP3FNH.cjs +518 -0
- package/dist/chunk-MSZP3FNH.cjs.map +1 -0
- package/dist/{chunk-KJ2SW6VA.js → chunk-NRUZYMHE.js} +4 -3
- package/dist/chunk-NRUZYMHE.js.map +1 -0
- package/dist/{chunk-7SKXKUYT.js → chunk-NUA6TSRD.js} +752 -17
- package/dist/chunk-NUA6TSRD.js.map +1 -0
- package/dist/chunk-OEIVMCWX.js +4959 -0
- package/dist/chunk-OEIVMCWX.js.map +1 -0
- package/dist/{chunk-VJUZZB2I.js → chunk-OIDPIW42.js} +26 -11
- package/dist/chunk-OIDPIW42.js.map +1 -0
- package/dist/{chunk-QUZGDSWE.cjs → chunk-OYIDRI3A.cjs} +32 -17
- package/dist/chunk-OYIDRI3A.cjs.map +1 -0
- package/dist/{chunk-YIK3ASEG.cjs → chunk-P2D2VO2O.cjs} +1226 -350
- package/dist/chunk-P2D2VO2O.cjs.map +1 -0
- package/dist/{chunk-L7XKOKOW.js → chunk-PK2A5WBG.js} +472 -125
- package/dist/chunk-PK2A5WBG.js.map +1 -0
- package/dist/{chunk-X7JMA3IY.js → chunk-PSCMWPLC.js} +2 -2
- package/dist/{chunk-X7JMA3IY.js.map → chunk-PSCMWPLC.js.map} +1 -1
- package/dist/{chunk-WM6CK2F3.cjs → chunk-QD3UWFAV.cjs} +130 -48
- package/dist/chunk-QD3UWFAV.cjs.map +1 -0
- package/dist/{chunk-FD734TPS.cjs → chunk-SL7Q6IZF.cjs} +11425 -8211
- package/dist/chunk-SL7Q6IZF.cjs.map +1 -0
- package/dist/{chunk-ECFXGXWO.cjs → chunk-SSPUH2N7.cjs} +693 -375
- package/dist/chunk-SSPUH2N7.cjs.map +1 -0
- package/dist/{chunk-BMAFVZ2D.cjs → chunk-T2VLUFGG.cjs} +4 -4
- package/dist/{chunk-BMAFVZ2D.cjs.map → chunk-T2VLUFGG.cjs.map} +1 -1
- package/dist/chunk-THZTRBFS.js +268 -0
- package/dist/chunk-THZTRBFS.js.map +1 -0
- package/dist/{chunk-Y6ROD72V.cjs → chunk-UIGRFDO6.cjs} +4 -4
- package/dist/{chunk-Y6ROD72V.cjs.map → chunk-UIGRFDO6.cjs.map} +1 -1
- package/dist/{chunk-GRBGQ2GE.js → chunk-UVHSM2GU.cjs} +9 -3
- package/dist/chunk-UVHSM2GU.cjs.map +1 -0
- package/dist/{chunk-GGYKYORQ.cjs → chunk-WX2DLWXF.cjs} +407 -22
- package/dist/chunk-WX2DLWXF.cjs.map +1 -0
- package/dist/{chunk-P6APHXPZ.js → chunk-XRJQ5ZA7.js} +179 -38
- package/dist/chunk-XRJQ5ZA7.js.map +1 -0
- package/dist/{chunk-KIZIOFZC.js → chunk-Y36Y5MTD.js} +17 -3
- package/dist/chunk-Y36Y5MTD.js.map +1 -0
- package/dist/{chunk-VV753WCB.cjs → chunk-YWMMBIOM.cjs} +21 -20
- package/dist/chunk-YWMMBIOM.cjs.map +1 -0
- package/dist/{chunk-BU4IAJWF.js → chunk-Z57R5WS4.js} +16 -15
- package/dist/chunk-Z57R5WS4.js.map +1 -0
- package/dist/deployer/index.cjs +2 -2
- package/dist/deployer/index.js +1 -1
- package/dist/di/index.cjs +10 -2
- package/dist/di/index.d.ts +1 -1
- package/dist/di/index.d.ts.map +1 -1
- package/dist/di/index.js +1 -1
- package/dist/evals/base.d.ts +10 -2
- package/dist/evals/base.d.ts.map +1 -1
- package/dist/evals/base.test-utils.d.ts +25 -25
- package/dist/evals/index.cjs +9 -9
- package/dist/evals/index.js +2 -2
- package/dist/evals/scoreTraces/index.cjs +7 -6
- package/dist/evals/scoreTraces/index.cjs.map +1 -1
- package/dist/evals/scoreTraces/index.js +4 -3
- package/dist/evals/scoreTraces/index.js.map +1 -1
- package/dist/evals/scoreTraces/scoreTracesWorkflow.d.ts.map +1 -1
- package/dist/evals/types.d.ts +25 -24
- package/dist/evals/types.d.ts.map +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.js +1 -1
- package/dist/integration/index.cjs +2 -2
- package/dist/integration/index.js +1 -1
- package/dist/llm/index.cjs +30 -10
- package/dist/llm/index.d.ts +2 -0
- package/dist/llm/index.d.ts.map +1 -1
- package/dist/llm/index.js +5 -1
- package/dist/llm/model/aisdk/v5/model.d.ts +47 -0
- package/dist/llm/model/aisdk/v5/model.d.ts.map +1 -0
- package/dist/llm/model/gateway-resolver.d.ts.map +1 -1
- package/dist/llm/model/gateways/azure.d.ts +36 -0
- package/dist/llm/model/gateways/azure.d.ts.map +1 -0
- package/dist/llm/model/gateways/base.d.ts +9 -4
- package/dist/llm/model/gateways/base.d.ts.map +1 -1
- package/dist/llm/model/gateways/constants.d.ts.map +1 -1
- package/dist/llm/model/gateways/index.d.ts +4 -1
- package/dist/llm/model/gateways/index.d.ts.map +1 -1
- package/dist/llm/model/gateways/models-dev.d.ts +3 -2
- package/dist/llm/model/gateways/models-dev.d.ts.map +1 -1
- package/dist/llm/model/gateways/netlify.d.ts +4 -3
- package/dist/llm/model/gateways/netlify.d.ts.map +1 -1
- package/dist/llm/model/is-v2-model.d.ts +3 -0
- package/dist/llm/model/is-v2-model.d.ts.map +1 -0
- package/dist/llm/model/model-method-from-agent.d.ts +4 -0
- package/dist/llm/model/model-method-from-agent.d.ts.map +1 -0
- package/dist/llm/model/model.d.ts.map +1 -1
- package/dist/llm/model/model.loop.d.ts +2 -2
- package/dist/llm/model/model.loop.d.ts.map +1 -1
- package/dist/llm/model/model.loop.types.d.ts +2 -0
- package/dist/llm/model/model.loop.types.d.ts.map +1 -1
- package/dist/llm/model/provider-options.d.ts +4 -1
- package/dist/llm/model/provider-options.d.ts.map +1 -1
- package/dist/llm/model/provider-registry.d.ts +11 -1
- package/dist/llm/model/provider-registry.d.ts.map +1 -1
- package/dist/llm/model/provider-types.generated.d.ts +520 -33
- package/dist/llm/model/registry-generator.d.ts +12 -0
- package/dist/llm/model/registry-generator.d.ts.map +1 -1
- package/dist/llm/model/resolve-model.d.ts +1 -1
- package/dist/llm/model/resolve-model.d.ts.map +1 -1
- package/dist/llm/model/router.d.ts +12 -5
- package/dist/llm/model/router.d.ts.map +1 -1
- package/dist/llm/model/shared.types.d.ts +10 -4
- package/dist/llm/model/shared.types.d.ts.map +1 -1
- package/dist/logger/constants.d.ts +1 -0
- package/dist/logger/constants.d.ts.map +1 -1
- package/dist/logger/index.cjs +11 -11
- package/dist/logger/index.js +2 -2
- package/dist/logger/transport.d.ts +1 -1
- package/dist/logger/transport.d.ts.map +1 -1
- package/dist/loop/index.cjs +2 -2
- package/dist/loop/index.js +1 -1
- package/dist/loop/loop.d.ts.map +1 -1
- package/dist/loop/network/index.d.ts.map +1 -1
- package/dist/loop/test-utils/MastraLanguageModelV2Mock.d.ts +37 -0
- package/dist/loop/test-utils/MastraLanguageModelV2Mock.d.ts.map +1 -0
- package/dist/loop/test-utils/fullStream.d.ts.map +1 -1
- package/dist/loop/test-utils/generateText.d.ts.map +1 -1
- package/dist/loop/test-utils/options.d.ts.map +1 -1
- package/dist/loop/test-utils/resultObject.d.ts.map +1 -1
- package/dist/loop/test-utils/streamObject.d.ts.map +1 -1
- package/dist/loop/test-utils/textStream.d.ts.map +1 -1
- package/dist/loop/test-utils/toUIMessageStream.d.ts.map +1 -1
- package/dist/loop/test-utils/tools.d.ts.map +1 -1
- package/dist/loop/test-utils/utils.d.ts +1 -1
- package/dist/loop/test-utils/utils.d.ts.map +1 -1
- package/dist/loop/types.d.ts +22 -5
- package/dist/loop/types.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/index.d.ts +42 -42
- package/dist/loop/workflows/agentic-execution/index.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts +29 -29
- package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/llm-mapping-step.d.ts +14 -14
- package/dist/loop/workflows/agentic-execution/llm-mapping-step.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/tool-call-step.d.ts +1 -1
- package/dist/loop/workflows/agentic-execution/tool-call-step.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-loop/index.d.ts +44 -43
- package/dist/loop/workflows/agentic-loop/index.d.ts.map +1 -1
- package/dist/loop/workflows/run-state.d.ts +2 -2
- package/dist/loop/workflows/run-state.d.ts.map +1 -1
- package/dist/loop/workflows/schema.d.ts +14 -14
- package/dist/loop/workflows/stream.d.ts +1 -1
- package/dist/loop/workflows/stream.d.ts.map +1 -1
- package/dist/mastra/index.cjs +2 -2
- package/dist/mastra/index.d.ts +377 -12
- package/dist/mastra/index.d.ts.map +1 -1
- package/dist/mastra/index.js +1 -1
- package/dist/mcp/index.cjs +4 -4
- package/dist/mcp/index.cjs.map +1 -1
- package/dist/mcp/index.d.ts +4 -4
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +2 -2
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/types.d.ts +2 -2
- package/dist/mcp/types.d.ts.map +1 -1
- package/dist/memory/index.cjs +21 -327
- package/dist/memory/index.cjs.map +1 -1
- package/dist/memory/index.js +1 -327
- package/dist/memory/index.js.map +1 -1
- package/dist/memory/memory.d.ts +28 -18
- package/dist/memory/memory.d.ts.map +1 -1
- package/dist/memory/mock.d.ts +15 -14
- package/dist/memory/mock.d.ts.map +1 -1
- package/dist/memory/types.d.ts +69 -11
- package/dist/memory/types.d.ts.map +1 -1
- package/dist/models-dev-23RN2WHG.js +3 -0
- package/dist/{models-dev-7U4NRMM3.js.map → models-dev-23RN2WHG.js.map} +1 -1
- package/dist/models-dev-EO3SUIY2.cjs +12 -0
- package/dist/{models-dev-VKSAQPRK.cjs.map → models-dev-EO3SUIY2.cjs.map} +1 -1
- package/dist/netlify-GXJ5D5DD.js +3 -0
- package/dist/{netlify-42ZNWIDQ.js.map → netlify-GXJ5D5DD.js.map} +1 -1
- package/dist/netlify-KJLY3GFS.cjs +12 -0
- package/dist/{netlify-2IDXTNFW.cjs.map → netlify-KJLY3GFS.cjs.map} +1 -1
- package/dist/observability/index.cjs +16 -8
- package/dist/observability/index.js +1 -1
- package/dist/observability/types/tracing.d.ts +236 -13
- package/dist/observability/types/tracing.d.ts.map +1 -1
- package/dist/observability/utils.d.ts +47 -1
- package/dist/observability/utils.d.ts.map +1 -1
- package/dist/processors/index.cjs +35 -11
- package/dist/processors/index.d.ts +101 -23
- package/dist/processors/index.d.ts.map +1 -1
- package/dist/processors/index.js +1 -1
- package/dist/processors/memory/index.d.ts +7 -0
- package/dist/processors/memory/index.d.ts.map +1 -0
- package/dist/processors/memory/message-history.d.ts +43 -0
- package/dist/processors/memory/message-history.d.ts.map +1 -0
- package/dist/processors/memory/semantic-recall.d.ts +152 -0
- package/dist/processors/memory/semantic-recall.d.ts.map +1 -0
- package/dist/processors/memory/working-memory.d.ts +65 -0
- package/dist/processors/memory/working-memory.d.ts.map +1 -0
- package/dist/processors/processors/batch-parts.d.ts +1 -1
- package/dist/processors/processors/batch-parts.d.ts.map +1 -1
- package/dist/processors/processors/index.d.ts +2 -1
- package/dist/processors/processors/index.d.ts.map +1 -1
- package/dist/processors/processors/language-detector.d.ts +15 -1
- package/dist/processors/processors/language-detector.d.ts.map +1 -1
- package/dist/processors/processors/moderation.d.ts +15 -1
- package/dist/processors/processors/moderation.d.ts.map +1 -1
- package/dist/processors/processors/pii-detector.d.ts +15 -1
- package/dist/processors/processors/pii-detector.d.ts.map +1 -1
- package/dist/processors/processors/prompt-injection-detector.d.ts +15 -1
- package/dist/processors/processors/prompt-injection-detector.d.ts.map +1 -1
- package/dist/processors/processors/structured-output.d.ts +3 -2
- package/dist/processors/processors/structured-output.d.ts.map +1 -1
- package/dist/processors/processors/system-prompt-scrubber.d.ts +1 -1
- package/dist/processors/processors/system-prompt-scrubber.d.ts.map +1 -1
- package/dist/processors/processors/token-limiter.d.ts +22 -12
- package/dist/processors/processors/token-limiter.d.ts.map +1 -1
- package/dist/processors/processors/tool-call-filter.d.ts +28 -0
- package/dist/processors/processors/tool-call-filter.d.ts.map +1 -0
- package/dist/processors/processors/unicode-normalizer.d.ts +1 -1
- package/dist/processors/processors/unicode-normalizer.d.ts.map +1 -1
- package/dist/processors/runner.d.ts +35 -4
- package/dist/processors/runner.d.ts.map +1 -1
- package/dist/provider-registry-A7FILT6Q.cjs +40 -0
- package/dist/provider-registry-A7FILT6Q.cjs.map +1 -0
- package/dist/provider-registry-XM2YDI5X.js +3 -0
- package/dist/provider-registry-XM2YDI5X.js.map +1 -0
- package/dist/provider-registry.json +1135 -77
- package/dist/{registry-generator-MK63POJO.cjs → registry-generator-34SC4TAU.cjs} +23 -6
- package/dist/registry-generator-34SC4TAU.cjs.map +1 -0
- package/dist/{registry-generator-H4YNODDH.js → registry-generator-UMTNPBJX.js} +23 -7
- package/dist/registry-generator-UMTNPBJX.js.map +1 -0
- package/dist/relevance/index.cjs +2 -2
- package/dist/relevance/index.js +1 -1
- package/dist/request-context/index.cjs +10 -2
- package/dist/request-context/index.d.ts +26 -0
- package/dist/request-context/index.d.ts.map +1 -1
- package/dist/request-context/index.js +1 -1
- package/dist/server/auth.d.ts +11 -0
- package/dist/server/auth.d.ts.map +1 -1
- package/dist/server/base.d.ts +51 -0
- package/dist/server/base.d.ts.map +1 -0
- package/dist/server/composite-auth.d.ts +9 -0
- package/dist/server/composite-auth.d.ts.map +1 -0
- package/dist/server/index.cjs +124 -3
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.d.ts +8 -0
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +121 -3
- package/dist/server/index.js.map +1 -1
- package/dist/server/simple-auth.d.ts +27 -0
- package/dist/server/simple-auth.d.ts.map +1 -0
- package/dist/storage/base.d.ts +76 -3
- package/dist/storage/base.d.ts.map +1 -1
- package/dist/storage/constants.d.ts +3 -1
- package/dist/storage/constants.d.ts.map +1 -1
- package/dist/storage/domains/agents/base.d.ts +49 -0
- package/dist/storage/domains/agents/base.d.ts.map +1 -0
- package/dist/storage/domains/agents/index.d.ts +3 -0
- package/dist/storage/domains/agents/index.d.ts.map +1 -0
- package/dist/storage/domains/agents/inmemory.d.ts +22 -0
- package/dist/storage/domains/agents/inmemory.d.ts.map +1 -0
- package/dist/storage/domains/index.d.ts +1 -0
- package/dist/storage/domains/index.d.ts.map +1 -1
- package/dist/storage/domains/memory/inmemory.d.ts.map +1 -1
- package/dist/storage/domains/operations/inmemory.d.ts.map +1 -1
- package/dist/storage/domains/scores/base.d.ts +2 -2
- package/dist/storage/domains/scores/base.d.ts.map +1 -1
- package/dist/storage/domains/scores/inmemory.d.ts +2 -2
- package/dist/storage/domains/scores/inmemory.d.ts.map +1 -1
- package/dist/storage/domains/workflows/base.d.ts +4 -0
- package/dist/storage/domains/workflows/base.d.ts.map +1 -1
- package/dist/storage/domains/workflows/inmemory.d.ts +5 -1
- package/dist/storage/domains/workflows/inmemory.d.ts.map +1 -1
- package/dist/storage/index.cjs +65 -29
- package/dist/storage/index.js +1 -1
- package/dist/storage/mock.d.ts +7 -2
- package/dist/storage/mock.d.ts.map +1 -1
- package/dist/storage/storageWithInit.d.ts.map +1 -1
- package/dist/storage/types.d.ts +85 -2
- package/dist/storage/types.d.ts.map +1 -1
- package/dist/storage/utils.d.ts +82 -0
- package/dist/storage/utils.d.ts.map +1 -1
- package/dist/stream/MastraAgentNetworkStream.d.ts +1 -1
- package/dist/stream/MastraAgentNetworkStream.d.ts.map +1 -1
- package/dist/stream/MastraWorkflowStream.d.ts +1 -1
- package/dist/stream/MastraWorkflowStream.d.ts.map +1 -1
- package/dist/stream/RunOutput.d.ts +2 -2
- package/dist/stream/RunOutput.d.ts.map +1 -1
- package/dist/stream/aisdk/v4/usage.d.ts +19 -0
- package/dist/stream/aisdk/v4/usage.d.ts.map +1 -0
- package/dist/stream/aisdk/v5/compat/prepare-tools.d.ts.map +1 -1
- package/dist/stream/aisdk/v5/execute.d.ts +8 -4
- package/dist/stream/aisdk/v5/execute.d.ts.map +1 -1
- package/dist/stream/aisdk/v5/input.d.ts +4 -1
- package/dist/stream/aisdk/v5/input.d.ts.map +1 -1
- package/dist/stream/aisdk/v5/output.d.ts +9 -9
- package/dist/stream/aisdk/v5/output.d.ts.map +1 -1
- package/dist/stream/aisdk/v5/transform.d.ts.map +1 -1
- package/dist/stream/base/base.d.ts +1 -1
- package/dist/stream/base/base.d.ts.map +1 -1
- package/dist/stream/base/input.d.ts +1 -1
- package/dist/stream/base/output-format-handlers.d.ts +14 -1
- package/dist/stream/base/output-format-handlers.d.ts.map +1 -1
- package/dist/stream/base/output.d.ts +3 -3
- package/dist/stream/base/output.d.ts.map +1 -1
- package/dist/stream/index.cjs +15 -11
- package/dist/stream/index.d.ts +2 -2
- package/dist/stream/index.d.ts.map +1 -1
- package/dist/stream/index.js +2 -2
- package/dist/stream/types.d.ts +48 -25
- package/dist/stream/types.d.ts.map +1 -1
- package/dist/test-utils/llm-mock.cjs +101 -30
- package/dist/test-utils/llm-mock.cjs.map +1 -1
- package/dist/test-utils/llm-mock.d.ts +7 -2
- package/dist/test-utils/llm-mock.d.ts.map +1 -1
- package/dist/test-utils/llm-mock.js +97 -30
- package/dist/test-utils/llm-mock.js.map +1 -1
- package/dist/tools/index.cjs +6 -6
- package/dist/tools/index.js +2 -2
- package/dist/tools/is-vercel-tool.cjs +2 -2
- package/dist/tools/is-vercel-tool.js +1 -1
- package/dist/tools/stream.d.ts +10 -4
- package/dist/tools/stream.d.ts.map +1 -1
- package/dist/tools/tool-builder/builder.d.ts +2 -0
- package/dist/tools/tool-builder/builder.d.ts.map +1 -1
- package/dist/tools/tool-stream-types.test-d.d.ts +2 -0
- package/dist/tools/tool-stream-types.test-d.d.ts.map +1 -0
- package/dist/tools/tool.d.ts +21 -8
- package/dist/tools/tool.d.ts.map +1 -1
- package/dist/tools/types.d.ts +33 -6
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/tools/validation.d.ts +25 -1
- package/dist/tools/validation.d.ts.map +1 -1
- package/dist/tts/index.cjs +2 -2
- package/dist/tts/index.js +1 -1
- package/dist/types/zod-compat.d.ts +14 -1
- package/dist/types/zod-compat.d.ts.map +1 -1
- package/dist/utils.cjs +25 -21
- package/dist/utils.d.ts +9 -4
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +1 -1
- package/dist/vector/filter/index.cjs +7 -189
- package/dist/vector/filter/index.cjs.map +1 -1
- package/dist/vector/filter/index.js +1 -190
- package/dist/vector/filter/index.js.map +1 -1
- package/dist/vector/index.cjs +7 -2
- package/dist/vector/index.cjs.map +1 -1
- package/dist/vector/index.d.ts +1 -0
- package/dist/vector/index.d.ts.map +1 -1
- package/dist/vector/index.js +2 -1
- package/dist/vector/index.js.map +1 -1
- package/dist/vector/types.d.ts +86 -3
- package/dist/vector/types.d.ts.map +1 -1
- package/dist/vector/vector.d.ts +39 -2
- package/dist/vector/vector.d.ts.map +1 -1
- package/dist/voice/aisdk/index.d.ts +3 -0
- package/dist/voice/aisdk/index.d.ts.map +1 -0
- package/dist/voice/aisdk/speech.d.ts +23 -0
- package/dist/voice/aisdk/speech.d.ts.map +1 -0
- package/dist/voice/aisdk/transcription.d.ts +22 -0
- package/dist/voice/aisdk/transcription.d.ts.map +1 -0
- package/dist/voice/composite-voice.d.ts +4 -3
- package/dist/voice/composite-voice.d.ts.map +1 -1
- package/dist/voice/index.cjs +12 -4
- package/dist/voice/index.d.ts +1 -0
- package/dist/voice/index.d.ts.map +1 -1
- package/dist/voice/index.js +1 -1
- package/dist/workflows/default.d.ts +179 -270
- package/dist/workflows/default.d.ts.map +1 -1
- package/dist/workflows/evented/execution-engine.d.ts +3 -1
- package/dist/workflows/evented/execution-engine.d.ts.map +1 -1
- package/dist/workflows/evented/index.cjs +10 -10
- package/dist/workflows/evented/index.js +1 -1
- package/dist/workflows/evented/step-executor.d.ts +1 -1
- package/dist/workflows/evented/step-executor.d.ts.map +1 -1
- package/dist/workflows/evented/workflow-event-processor/index.d.ts +5 -4
- package/dist/workflows/evented/workflow-event-processor/index.d.ts.map +1 -1
- package/dist/workflows/evented/workflow-event-processor/loop.d.ts +1 -1
- package/dist/workflows/evented/workflow-event-processor/loop.d.ts.map +1 -1
- package/dist/workflows/evented/workflow-event-processor/parallel.d.ts +2 -2
- package/dist/workflows/evented/workflow-event-processor/parallel.d.ts.map +1 -1
- package/dist/workflows/evented/workflow-event-processor/sleep.d.ts +2 -2
- package/dist/workflows/evented/workflow-event-processor/sleep.d.ts.map +1 -1
- package/dist/workflows/evented/workflow.d.ts +2 -1
- package/dist/workflows/evented/workflow.d.ts.map +1 -1
- package/dist/workflows/execution-engine.d.ts +8 -6
- package/dist/workflows/execution-engine.d.ts.map +1 -1
- package/dist/workflows/handlers/control-flow.d.ts +133 -0
- package/dist/workflows/handlers/control-flow.d.ts.map +1 -0
- package/dist/workflows/handlers/entry.d.ts +43 -0
- package/dist/workflows/handlers/entry.d.ts.map +1 -0
- package/dist/workflows/handlers/sleep.d.ts +60 -0
- package/dist/workflows/handlers/sleep.d.ts.map +1 -0
- package/dist/workflows/handlers/step.d.ts +58 -0
- package/dist/workflows/handlers/step.d.ts.map +1 -0
- package/dist/workflows/index.cjs +36 -16
- package/dist/workflows/index.js +1 -1
- package/dist/workflows/step.d.ts +8 -6
- package/dist/workflows/step.d.ts.map +1 -1
- package/dist/workflows/types.d.ts +224 -10
- package/dist/workflows/types.d.ts.map +1 -1
- package/dist/workflows/utils.d.ts +36 -0
- package/dist/workflows/utils.d.ts.map +1 -1
- package/dist/workflows/workflow.d.ts +135 -54
- package/dist/workflows/workflow.d.ts.map +1 -1
- package/package.json +26 -29
- package/src/llm/model/provider-types.generated.d.ts +520 -33
- package/dist/chunk-26SQQNMU.js.map +0 -1
- package/dist/chunk-32CTMD2C.js.map +0 -1
- package/dist/chunk-436FFEF6.js +0 -34
- package/dist/chunk-436FFEF6.js.map +0 -1
- package/dist/chunk-4CDL2QJT.js.map +0 -1
- package/dist/chunk-7AHYOMHJ.js +0 -149
- package/dist/chunk-7AHYOMHJ.js.map +0 -1
- package/dist/chunk-7SKXKUYT.js.map +0 -1
- package/dist/chunk-BNBRQS7N.js +0 -910
- package/dist/chunk-BNBRQS7N.js.map +0 -1
- package/dist/chunk-BU4IAJWF.js.map +0 -1
- package/dist/chunk-BXOL277H.cjs.map +0 -1
- package/dist/chunk-DSNPWVIG.cjs.map +0 -1
- package/dist/chunk-E7K4FTLN.cjs.map +0 -1
- package/dist/chunk-ECFXGXWO.cjs.map +0 -1
- package/dist/chunk-ET6UOTTU.cjs +0 -154
- package/dist/chunk-ET6UOTTU.cjs.map +0 -1
- package/dist/chunk-FD734TPS.cjs.map +0 -1
- package/dist/chunk-GGYKYORQ.cjs.map +0 -1
- package/dist/chunk-GRBGQ2GE.js.map +0 -1
- package/dist/chunk-HGNRQ3OG.js +0 -58
- package/dist/chunk-HGNRQ3OG.js.map +0 -1
- package/dist/chunk-IU2SZXJQ.cjs +0 -913
- package/dist/chunk-IU2SZXJQ.cjs.map +0 -1
- package/dist/chunk-J7O6WENZ.cjs.map +0 -1
- package/dist/chunk-JV2KH24V.js.map +0 -1
- package/dist/chunk-KIZIOFZC.js.map +0 -1
- package/dist/chunk-KJ2SW6VA.js.map +0 -1
- package/dist/chunk-L7XKOKOW.js.map +0 -1
- package/dist/chunk-LJFJTTZQ.cjs +0 -4
- package/dist/chunk-LJFJTTZQ.cjs.map +0 -1
- package/dist/chunk-LRSB62Z6.cjs +0 -60
- package/dist/chunk-LRSB62Z6.cjs.map +0 -1
- package/dist/chunk-MV7KHWUT.js.map +0 -1
- package/dist/chunk-P6APHXPZ.js.map +0 -1
- package/dist/chunk-QCQLOMJM.cjs.map +0 -1
- package/dist/chunk-QUKUN6NR.cjs.map +0 -1
- package/dist/chunk-QUZGDSWE.cjs.map +0 -1
- package/dist/chunk-S5MJLXMG.cjs.map +0 -1
- package/dist/chunk-TQTAMPSC.js.map +0 -1
- package/dist/chunk-UIZSWUKP.js.map +0 -1
- package/dist/chunk-V3VLOOSW.cjs +0 -36
- package/dist/chunk-V3VLOOSW.cjs.map +0 -1
- package/dist/chunk-VJUZZB2I.js.map +0 -1
- package/dist/chunk-VOY2RXOC.cjs.map +0 -1
- package/dist/chunk-VV753WCB.cjs.map +0 -1
- package/dist/chunk-WM6CK2F3.cjs.map +0 -1
- package/dist/chunk-XEVG546F.js.map +0 -1
- package/dist/chunk-Y63IFHEZ.cjs.map +0 -1
- package/dist/chunk-YIK3ASEG.cjs.map +0 -1
- package/dist/chunk-ZV5CC35D.js +0 -3
- package/dist/chunk-ZV5CC35D.js.map +0 -1
- package/dist/models-dev-7U4NRMM3.js +0 -3
- package/dist/models-dev-VKSAQPRK.cjs +0 -12
- package/dist/netlify-2IDXTNFW.cjs +0 -12
- package/dist/netlify-42ZNWIDQ.js +0 -3
- package/dist/registry-generator-H4YNODDH.js.map +0 -1
- package/dist/registry-generator-MK63POJO.cjs.map +0 -1
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { WorkflowEventProcessor } from './chunk-
|
|
2
|
-
import {
|
|
3
|
-
import { saveScorePayloadSchema } from './chunk-76K3IYWM.js';
|
|
1
|
+
import { WorkflowEventProcessor } from './chunk-XRJQ5ZA7.js';
|
|
2
|
+
import { saveScorePayloadSchema } from './chunk-ADADLFDR.js';
|
|
4
3
|
import { PubSub } from './chunk-BVUMKER5.js';
|
|
5
|
-
import {
|
|
4
|
+
import { augmentWithInit, Agent } from './chunk-6CYYFT4O.js';
|
|
5
|
+
import { noopLogger } from './chunk-PSCMWPLC.js';
|
|
6
6
|
import { registerHook } from './chunk-L54GIUCB.js';
|
|
7
|
-
import { NoOpObservability } from './chunk-
|
|
7
|
+
import { NoOpObservability } from './chunk-Y36Y5MTD.js';
|
|
8
8
|
import { MastraError } from './chunk-JJ5O45LH.js';
|
|
9
|
-
import { InMemoryServerCache } from './chunk-
|
|
10
|
-
import { ConsoleLogger, LogLevel } from './chunk-
|
|
9
|
+
import { InMemoryServerCache } from './chunk-3CKZSDTQ.js';
|
|
10
|
+
import { ConsoleLogger, LogLevel } from './chunk-NRUZYMHE.js';
|
|
11
11
|
import { randomUUID } from 'crypto';
|
|
12
12
|
import EventEmitter from 'events';
|
|
13
13
|
import pMap from 'p-map';
|
|
@@ -162,6 +162,17 @@ async function findScorer(mastra, entityId, entityType, scorerId) {
|
|
|
162
162
|
}
|
|
163
163
|
|
|
164
164
|
// src/mastra/index.ts
|
|
165
|
+
function createUndefinedPrimitiveError(type, value, key) {
|
|
166
|
+
const typeLabel = type === "mcp-server" ? "MCP server" : type;
|
|
167
|
+
const errorId = `MASTRA_ADD_${type.toUpperCase().replace("-", "_")}_UNDEFINED`;
|
|
168
|
+
return new MastraError({
|
|
169
|
+
id: errorId,
|
|
170
|
+
domain: "MASTRA" /* MASTRA */,
|
|
171
|
+
category: "USER" /* USER */,
|
|
172
|
+
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.`,
|
|
173
|
+
details: { status: 400, ...key && { key } }
|
|
174
|
+
});
|
|
175
|
+
}
|
|
165
176
|
var Mastra = class {
|
|
166
177
|
#vectors;
|
|
167
178
|
#agents;
|
|
@@ -175,11 +186,14 @@ var Mastra = class {
|
|
|
175
186
|
#scorers;
|
|
176
187
|
#tools;
|
|
177
188
|
#processors;
|
|
189
|
+
#memory;
|
|
178
190
|
#server;
|
|
191
|
+
#serverAdapter;
|
|
179
192
|
#mcpServers;
|
|
180
193
|
#bundler;
|
|
181
194
|
#idGenerator;
|
|
182
195
|
#pubsub;
|
|
196
|
+
#gateways;
|
|
183
197
|
#events = {};
|
|
184
198
|
#internalMastraWorkflows = {};
|
|
185
199
|
// This is only used internally for server handlers that require temporary persistence
|
|
@@ -343,45 +357,77 @@ var Mastra = class {
|
|
|
343
357
|
this.#scorers = {};
|
|
344
358
|
this.#tools = {};
|
|
345
359
|
this.#processors = {};
|
|
360
|
+
this.#memory = {};
|
|
346
361
|
this.#workflows = {};
|
|
362
|
+
this.#gateways = {};
|
|
347
363
|
if (config?.tools) {
|
|
348
364
|
Object.entries(config.tools).forEach(([key, tool]) => {
|
|
349
|
-
|
|
365
|
+
if (tool != null) {
|
|
366
|
+
this.addTool(tool, key);
|
|
367
|
+
}
|
|
350
368
|
});
|
|
351
369
|
}
|
|
352
370
|
if (config?.processors) {
|
|
353
371
|
Object.entries(config.processors).forEach(([key, processor]) => {
|
|
354
|
-
|
|
372
|
+
if (processor != null) {
|
|
373
|
+
this.addProcessor(processor, key);
|
|
374
|
+
}
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
if (config?.memory) {
|
|
378
|
+
Object.entries(config.memory).forEach(([key, memory]) => {
|
|
379
|
+
if (memory != null) {
|
|
380
|
+
this.addMemory(memory, key);
|
|
381
|
+
}
|
|
355
382
|
});
|
|
356
383
|
}
|
|
357
384
|
if (config?.vectors) {
|
|
358
385
|
Object.entries(config.vectors).forEach(([key, vector]) => {
|
|
359
|
-
|
|
386
|
+
if (vector != null) {
|
|
387
|
+
this.addVector(vector, key);
|
|
388
|
+
}
|
|
360
389
|
});
|
|
361
390
|
}
|
|
362
391
|
if (config?.scorers) {
|
|
363
392
|
Object.entries(config.scorers).forEach(([key, scorer]) => {
|
|
364
|
-
|
|
393
|
+
if (scorer != null) {
|
|
394
|
+
this.addScorer(scorer, key);
|
|
395
|
+
}
|
|
365
396
|
});
|
|
366
397
|
}
|
|
367
398
|
if (config?.workflows) {
|
|
368
399
|
Object.entries(config.workflows).forEach(([key, workflow]) => {
|
|
369
|
-
|
|
400
|
+
if (workflow != null) {
|
|
401
|
+
this.addWorkflow(workflow, key);
|
|
402
|
+
}
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
if (config?.gateways) {
|
|
406
|
+
Object.entries(config.gateways).forEach(([key, gateway]) => {
|
|
407
|
+
if (gateway != null) {
|
|
408
|
+
this.addGateway(gateway, key);
|
|
409
|
+
}
|
|
370
410
|
});
|
|
371
411
|
}
|
|
372
412
|
if (config?.mcpServers) {
|
|
373
413
|
Object.entries(config.mcpServers).forEach(([key, server]) => {
|
|
374
|
-
|
|
414
|
+
if (server != null) {
|
|
415
|
+
this.addMCPServer(server, key);
|
|
416
|
+
}
|
|
375
417
|
});
|
|
376
418
|
}
|
|
377
419
|
if (config?.agents) {
|
|
378
420
|
Object.entries(config.agents).forEach(([key, agent]) => {
|
|
379
|
-
|
|
421
|
+
if (agent != null) {
|
|
422
|
+
this.addAgent(agent, key);
|
|
423
|
+
}
|
|
380
424
|
});
|
|
381
425
|
}
|
|
382
426
|
if (config?.tts) {
|
|
383
427
|
Object.entries(config.tts).forEach(([key, tts]) => {
|
|
384
|
-
|
|
428
|
+
if (tts != null) {
|
|
429
|
+
this.#tts[key] = tts;
|
|
430
|
+
}
|
|
385
431
|
});
|
|
386
432
|
}
|
|
387
433
|
if (config?.server) {
|
|
@@ -505,6 +551,241 @@ var Mastra = class {
|
|
|
505
551
|
listAgents() {
|
|
506
552
|
return this.#agents;
|
|
507
553
|
}
|
|
554
|
+
async getStoredAgentById(id, options) {
|
|
555
|
+
const storage = this.#storage;
|
|
556
|
+
if (!storage) {
|
|
557
|
+
const error = new MastraError({
|
|
558
|
+
id: "MASTRA_GET_STORED_AGENT_STORAGE_NOT_CONFIGURED",
|
|
559
|
+
domain: "MASTRA" /* MASTRA */,
|
|
560
|
+
category: "USER" /* USER */,
|
|
561
|
+
text: "Storage is not configured",
|
|
562
|
+
details: { status: 400 }
|
|
563
|
+
});
|
|
564
|
+
this.#logger?.trackException(error);
|
|
565
|
+
throw error;
|
|
566
|
+
}
|
|
567
|
+
if (!storage.supports.agents) {
|
|
568
|
+
const error = new MastraError({
|
|
569
|
+
id: "MASTRA_GET_STORED_AGENT_NOT_SUPPORTED",
|
|
570
|
+
domain: "MASTRA" /* MASTRA */,
|
|
571
|
+
category: "USER" /* USER */,
|
|
572
|
+
text: "Storage does not support agents",
|
|
573
|
+
details: { status: 400 }
|
|
574
|
+
});
|
|
575
|
+
this.#logger?.trackException(error);
|
|
576
|
+
throw error;
|
|
577
|
+
}
|
|
578
|
+
const storedAgent = await storage.getAgentById({ id });
|
|
579
|
+
if (!storedAgent) {
|
|
580
|
+
return null;
|
|
581
|
+
}
|
|
582
|
+
if (options?.raw) {
|
|
583
|
+
return storedAgent;
|
|
584
|
+
}
|
|
585
|
+
return this.#createAgentFromStoredConfig(storedAgent);
|
|
586
|
+
}
|
|
587
|
+
async listStoredAgents(args) {
|
|
588
|
+
const storage = this.#storage;
|
|
589
|
+
if (!storage) {
|
|
590
|
+
const error = new MastraError({
|
|
591
|
+
id: "MASTRA_LIST_STORED_AGENTS_STORAGE_NOT_CONFIGURED",
|
|
592
|
+
domain: "MASTRA" /* MASTRA */,
|
|
593
|
+
category: "USER" /* USER */,
|
|
594
|
+
text: "Storage is not configured",
|
|
595
|
+
details: { status: 400 }
|
|
596
|
+
});
|
|
597
|
+
this.#logger?.trackException(error);
|
|
598
|
+
throw error;
|
|
599
|
+
}
|
|
600
|
+
if (!storage.supports.agents) {
|
|
601
|
+
const error = new MastraError({
|
|
602
|
+
id: "MASTRA_LIST_STORED_AGENTS_NOT_SUPPORTED",
|
|
603
|
+
domain: "MASTRA" /* MASTRA */,
|
|
604
|
+
category: "USER" /* USER */,
|
|
605
|
+
text: "Storage does not support agents",
|
|
606
|
+
details: { status: 400 }
|
|
607
|
+
});
|
|
608
|
+
this.#logger?.trackException(error);
|
|
609
|
+
throw error;
|
|
610
|
+
}
|
|
611
|
+
const result = await storage.listAgents({
|
|
612
|
+
page: args?.page,
|
|
613
|
+
perPage: args?.perPage,
|
|
614
|
+
orderBy: args?.orderBy
|
|
615
|
+
});
|
|
616
|
+
if (args?.raw) {
|
|
617
|
+
return result;
|
|
618
|
+
}
|
|
619
|
+
const agents = result.agents.map((storedAgent) => this.#createAgentFromStoredConfig(storedAgent));
|
|
620
|
+
return {
|
|
621
|
+
agents,
|
|
622
|
+
total: result.total,
|
|
623
|
+
page: result.page,
|
|
624
|
+
perPage: result.perPage,
|
|
625
|
+
hasMore: result.hasMore
|
|
626
|
+
};
|
|
627
|
+
}
|
|
628
|
+
/**
|
|
629
|
+
* Creates an Agent instance from a stored agent configuration.
|
|
630
|
+
* @private
|
|
631
|
+
*/
|
|
632
|
+
#createAgentFromStoredConfig(storedAgent) {
|
|
633
|
+
const modelConfig = storedAgent.model;
|
|
634
|
+
if (!modelConfig.provider || !modelConfig.name) {
|
|
635
|
+
throw new MastraError({
|
|
636
|
+
id: "MASTRA_STORED_AGENT_INVALID_MODEL",
|
|
637
|
+
domain: "MASTRA" /* MASTRA */,
|
|
638
|
+
category: "USER" /* USER */,
|
|
639
|
+
text: `Stored agent "${storedAgent.id}" has invalid model configuration. Both provider and name are required.`,
|
|
640
|
+
details: { agentId: storedAgent.id, model: JSON.stringify(storedAgent.model) }
|
|
641
|
+
});
|
|
642
|
+
}
|
|
643
|
+
const model = `${modelConfig.provider}/${modelConfig.name}`;
|
|
644
|
+
const tools = this.#resolveStoredTools(storedAgent.tools);
|
|
645
|
+
const workflows = this.#resolveStoredWorkflows(storedAgent.workflows);
|
|
646
|
+
const agents = this.#resolveStoredAgents(storedAgent.agents);
|
|
647
|
+
const memory = this.#resolveStoredMemory(storedAgent.memory);
|
|
648
|
+
const scorers = this.#resolveStoredScorers(storedAgent.scorers);
|
|
649
|
+
const agent = new Agent({
|
|
650
|
+
id: storedAgent.id,
|
|
651
|
+
name: storedAgent.name,
|
|
652
|
+
description: storedAgent.description,
|
|
653
|
+
instructions: storedAgent.instructions,
|
|
654
|
+
model,
|
|
655
|
+
tools,
|
|
656
|
+
workflows,
|
|
657
|
+
agents,
|
|
658
|
+
memory,
|
|
659
|
+
scorers,
|
|
660
|
+
defaultOptions: storedAgent.defaultOptions
|
|
661
|
+
});
|
|
662
|
+
agent.__setLogger(this.#logger);
|
|
663
|
+
agent.__registerMastra(this);
|
|
664
|
+
agent.__registerPrimitives({
|
|
665
|
+
logger: this.getLogger(),
|
|
666
|
+
storage: this.getStorage(),
|
|
667
|
+
agents: this.#agents,
|
|
668
|
+
tts: this.#tts,
|
|
669
|
+
vectors: this.#vectors
|
|
670
|
+
});
|
|
671
|
+
return agent;
|
|
672
|
+
}
|
|
673
|
+
/**
|
|
674
|
+
* Resolves tool references from stored configuration to actual tool instances.
|
|
675
|
+
* @private
|
|
676
|
+
*/
|
|
677
|
+
#resolveStoredTools(storedTools) {
|
|
678
|
+
if (!storedTools || storedTools.length === 0) {
|
|
679
|
+
return {};
|
|
680
|
+
}
|
|
681
|
+
const resolvedTools = {};
|
|
682
|
+
const registeredTools = this.#tools;
|
|
683
|
+
for (const toolKey of storedTools) {
|
|
684
|
+
if (registeredTools && registeredTools[toolKey]) {
|
|
685
|
+
resolvedTools[toolKey] = registeredTools[toolKey];
|
|
686
|
+
} else {
|
|
687
|
+
this.#logger?.warn(`Tool "${toolKey}" referenced in stored agent but not registered in Mastra`);
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
return resolvedTools;
|
|
691
|
+
}
|
|
692
|
+
/**
|
|
693
|
+
* Resolves workflow references from stored configuration to actual workflow instances.
|
|
694
|
+
* @private
|
|
695
|
+
*/
|
|
696
|
+
#resolveStoredWorkflows(storedWorkflows) {
|
|
697
|
+
if (!storedWorkflows || storedWorkflows.length === 0) {
|
|
698
|
+
return {};
|
|
699
|
+
}
|
|
700
|
+
const resolvedWorkflows = {};
|
|
701
|
+
for (const workflowKey of storedWorkflows) {
|
|
702
|
+
try {
|
|
703
|
+
const workflow = this.getWorkflow(workflowKey);
|
|
704
|
+
resolvedWorkflows[workflowKey] = workflow;
|
|
705
|
+
} catch {
|
|
706
|
+
try {
|
|
707
|
+
const workflow = this.getWorkflowById(workflowKey);
|
|
708
|
+
resolvedWorkflows[workflowKey] = workflow;
|
|
709
|
+
} catch {
|
|
710
|
+
this.#logger?.warn(`Workflow "${workflowKey}" referenced in stored agent but not registered in Mastra`);
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
return resolvedWorkflows;
|
|
715
|
+
}
|
|
716
|
+
/**
|
|
717
|
+
* Resolves agent references from stored configuration to actual agent instances.
|
|
718
|
+
* @private
|
|
719
|
+
*/
|
|
720
|
+
#resolveStoredAgents(storedAgents) {
|
|
721
|
+
if (!storedAgents || storedAgents.length === 0) {
|
|
722
|
+
return {};
|
|
723
|
+
}
|
|
724
|
+
const resolvedAgents = {};
|
|
725
|
+
for (const agentKey of storedAgents) {
|
|
726
|
+
try {
|
|
727
|
+
const agent = this.getAgent(agentKey);
|
|
728
|
+
resolvedAgents[agentKey] = agent;
|
|
729
|
+
} catch {
|
|
730
|
+
try {
|
|
731
|
+
const agent = this.getAgentById(agentKey);
|
|
732
|
+
resolvedAgents[agentKey] = agent;
|
|
733
|
+
} catch {
|
|
734
|
+
this.#logger?.warn(`Agent "${agentKey}" referenced in stored agent but not registered in Mastra`);
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
return resolvedAgents;
|
|
739
|
+
}
|
|
740
|
+
/**
|
|
741
|
+
* Resolves memory reference from stored configuration to actual memory instance.
|
|
742
|
+
* @private
|
|
743
|
+
*/
|
|
744
|
+
#resolveStoredMemory(storedMemory) {
|
|
745
|
+
if (!storedMemory) {
|
|
746
|
+
return void 0;
|
|
747
|
+
}
|
|
748
|
+
try {
|
|
749
|
+
return this.getMemory(storedMemory);
|
|
750
|
+
} catch {
|
|
751
|
+
try {
|
|
752
|
+
return this.getMemoryById(storedMemory);
|
|
753
|
+
} catch {
|
|
754
|
+
this.#logger?.warn(`Memory "${storedMemory}" referenced in stored agent but not registered in Mastra`);
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
return void 0;
|
|
758
|
+
}
|
|
759
|
+
/**
|
|
760
|
+
* Resolves scorer references from stored configuration to actual scorer instances.
|
|
761
|
+
* @private
|
|
762
|
+
*/
|
|
763
|
+
#resolveStoredScorers(storedScorers) {
|
|
764
|
+
if (!storedScorers) {
|
|
765
|
+
return void 0;
|
|
766
|
+
}
|
|
767
|
+
const resolvedScorers = {};
|
|
768
|
+
for (const [scorerKey, scorerConfig] of Object.entries(storedScorers)) {
|
|
769
|
+
try {
|
|
770
|
+
const scorer = this.getScorer(scorerKey);
|
|
771
|
+
resolvedScorers[scorerKey] = {
|
|
772
|
+
scorer,
|
|
773
|
+
sampling: scorerConfig.sampling
|
|
774
|
+
};
|
|
775
|
+
} catch {
|
|
776
|
+
try {
|
|
777
|
+
const scorer = this.getScorerById(scorerKey);
|
|
778
|
+
resolvedScorers[scorerKey] = {
|
|
779
|
+
scorer,
|
|
780
|
+
sampling: scorerConfig.sampling
|
|
781
|
+
};
|
|
782
|
+
} catch {
|
|
783
|
+
this.#logger?.warn(`Scorer "${scorerKey}" referenced in stored agent but not registered in Mastra`);
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
return Object.keys(resolvedScorers).length > 0 ? resolvedScorers : void 0;
|
|
788
|
+
}
|
|
508
789
|
/**
|
|
509
790
|
* Adds a new agent to the Mastra instance.
|
|
510
791
|
*
|
|
@@ -527,6 +808,9 @@ var Mastra = class {
|
|
|
527
808
|
* ```
|
|
528
809
|
*/
|
|
529
810
|
addAgent(agent, key) {
|
|
811
|
+
if (!agent) {
|
|
812
|
+
throw createUndefinedPrimitiveError("agent", agent, key);
|
|
813
|
+
}
|
|
530
814
|
const agentKey = key || agent.id;
|
|
531
815
|
const agents = this.#agents;
|
|
532
816
|
if (agents[agentKey]) {
|
|
@@ -689,6 +973,9 @@ var Mastra = class {
|
|
|
689
973
|
* ```
|
|
690
974
|
*/
|
|
691
975
|
addVector(vector, key) {
|
|
976
|
+
if (!vector) {
|
|
977
|
+
throw createUndefinedPrimitiveError("vector", vector, key);
|
|
978
|
+
}
|
|
692
979
|
const vectorKey = key || vector.id;
|
|
693
980
|
const vectors = this.#vectors;
|
|
694
981
|
if (vectors[vectorKey]) {
|
|
@@ -859,6 +1146,44 @@ var Mastra = class {
|
|
|
859
1146
|
}
|
|
860
1147
|
return workflow;
|
|
861
1148
|
}
|
|
1149
|
+
async listActiveWorkflowRuns() {
|
|
1150
|
+
const storage = this.#storage;
|
|
1151
|
+
if (!storage) {
|
|
1152
|
+
this.#logger.debug("Cannot get active workflow runs. Mastra storage is not initialized");
|
|
1153
|
+
return { runs: [], total: 0 };
|
|
1154
|
+
}
|
|
1155
|
+
const defaultEngineWorkflows = Object.values(this.#workflows).filter((workflow) => workflow.engineType === "default");
|
|
1156
|
+
const allRuns = [];
|
|
1157
|
+
let allTotal = 0;
|
|
1158
|
+
for (const workflow of defaultEngineWorkflows) {
|
|
1159
|
+
const runningRuns = await workflow.listWorkflowRuns({ status: "running" });
|
|
1160
|
+
const waitingRuns = await workflow.listWorkflowRuns({ status: "waiting" });
|
|
1161
|
+
allRuns.push(...runningRuns.runs, ...waitingRuns.runs);
|
|
1162
|
+
allTotal += runningRuns.total + waitingRuns.total;
|
|
1163
|
+
}
|
|
1164
|
+
return {
|
|
1165
|
+
runs: allRuns,
|
|
1166
|
+
total: allTotal
|
|
1167
|
+
};
|
|
1168
|
+
}
|
|
1169
|
+
async restartAllActiveWorkflowRuns() {
|
|
1170
|
+
const activeRuns = await this.listActiveWorkflowRuns();
|
|
1171
|
+
if (activeRuns.runs.length > 0) {
|
|
1172
|
+
this.#logger.debug(
|
|
1173
|
+
`Restarting ${activeRuns.runs.length} active workflow run${activeRuns.runs.length > 1 ? "s" : ""}`
|
|
1174
|
+
);
|
|
1175
|
+
}
|
|
1176
|
+
for (const runSnapshot of activeRuns.runs) {
|
|
1177
|
+
const workflow = this.getWorkflowById(runSnapshot.workflowName);
|
|
1178
|
+
try {
|
|
1179
|
+
const run = await workflow.createRun({ runId: runSnapshot.runId });
|
|
1180
|
+
await run.restart();
|
|
1181
|
+
this.#logger.debug(`Restarted ${runSnapshot.workflowName} workflow run ${runSnapshot.runId}`);
|
|
1182
|
+
} catch (error) {
|
|
1183
|
+
this.#logger.error(`Failed to restart ${runSnapshot.workflowName} workflow run ${runSnapshot.runId}: ${error}`);
|
|
1184
|
+
}
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
862
1187
|
/**
|
|
863
1188
|
* Returns all registered scorers as a record keyed by their IDs.
|
|
864
1189
|
*
|
|
@@ -907,6 +1232,9 @@ var Mastra = class {
|
|
|
907
1232
|
* ```
|
|
908
1233
|
*/
|
|
909
1234
|
addScorer(scorer, key) {
|
|
1235
|
+
if (!scorer) {
|
|
1236
|
+
throw createUndefinedPrimitiveError("scorer", scorer, key);
|
|
1237
|
+
}
|
|
910
1238
|
const scorerKey = key || scorer.id;
|
|
911
1239
|
const scorers = this.#scorers;
|
|
912
1240
|
if (scorers[scorerKey]) {
|
|
@@ -914,6 +1242,7 @@ var Mastra = class {
|
|
|
914
1242
|
logger.debug(`Scorer with key ${scorerKey} already exists. Skipping addition.`);
|
|
915
1243
|
return;
|
|
916
1244
|
}
|
|
1245
|
+
scorer.__registerMastra(this);
|
|
917
1246
|
scorers[scorerKey] = scorer;
|
|
918
1247
|
}
|
|
919
1248
|
/**
|
|
@@ -1134,6 +1463,9 @@ var Mastra = class {
|
|
|
1134
1463
|
* ```
|
|
1135
1464
|
*/
|
|
1136
1465
|
addTool(tool, key) {
|
|
1466
|
+
if (!tool) {
|
|
1467
|
+
throw createUndefinedPrimitiveError("tool", tool, key);
|
|
1468
|
+
}
|
|
1137
1469
|
const toolKey = key || tool.id;
|
|
1138
1470
|
const tools = this.#tools;
|
|
1139
1471
|
if (tools[toolKey]) {
|
|
@@ -1269,6 +1601,9 @@ var Mastra = class {
|
|
|
1269
1601
|
* ```
|
|
1270
1602
|
*/
|
|
1271
1603
|
addProcessor(processor, key) {
|
|
1604
|
+
if (!processor) {
|
|
1605
|
+
throw createUndefinedPrimitiveError("processor", processor, key);
|
|
1606
|
+
}
|
|
1272
1607
|
const processorKey = key || processor.id;
|
|
1273
1608
|
const processors = this.#processors;
|
|
1274
1609
|
if (processors[processorKey]) {
|
|
@@ -1278,6 +1613,131 @@ var Mastra = class {
|
|
|
1278
1613
|
}
|
|
1279
1614
|
processors[processorKey] = processor;
|
|
1280
1615
|
}
|
|
1616
|
+
/**
|
|
1617
|
+
* Retrieves a registered memory instance by its registration key.
|
|
1618
|
+
*
|
|
1619
|
+
* @throws {MastraError} When the memory instance with the specified key is not found
|
|
1620
|
+
*
|
|
1621
|
+
* @example
|
|
1622
|
+
* ```typescript
|
|
1623
|
+
* const mastra = new Mastra({
|
|
1624
|
+
* memory: {
|
|
1625
|
+
* chat: new Memory({ storage })
|
|
1626
|
+
* }
|
|
1627
|
+
* });
|
|
1628
|
+
*
|
|
1629
|
+
* const chatMemory = mastra.getMemory('chat');
|
|
1630
|
+
* ```
|
|
1631
|
+
*/
|
|
1632
|
+
getMemory(name) {
|
|
1633
|
+
if (!this.#memory || !this.#memory[name]) {
|
|
1634
|
+
const error = new MastraError({
|
|
1635
|
+
id: "MASTRA_GET_MEMORY_BY_KEY_NOT_FOUND",
|
|
1636
|
+
domain: "MASTRA" /* MASTRA */,
|
|
1637
|
+
category: "USER" /* USER */,
|
|
1638
|
+
text: `Memory with key ${String(name)} not found`,
|
|
1639
|
+
details: {
|
|
1640
|
+
status: 404,
|
|
1641
|
+
memoryKey: String(name),
|
|
1642
|
+
memory: Object.keys(this.#memory ?? {}).join(", ")
|
|
1643
|
+
}
|
|
1644
|
+
});
|
|
1645
|
+
this.#logger?.trackException(error);
|
|
1646
|
+
throw error;
|
|
1647
|
+
}
|
|
1648
|
+
return this.#memory[name];
|
|
1649
|
+
}
|
|
1650
|
+
/**
|
|
1651
|
+
* Retrieves a registered memory instance by its ID.
|
|
1652
|
+
*
|
|
1653
|
+
* Searches through all registered memory instances and returns the one whose ID matches.
|
|
1654
|
+
*
|
|
1655
|
+
* @throws {MastraError} When no memory instance with the specified ID is found
|
|
1656
|
+
*
|
|
1657
|
+
* @example
|
|
1658
|
+
* ```typescript
|
|
1659
|
+
* const mastra = new Mastra({
|
|
1660
|
+
* memory: {
|
|
1661
|
+
* chat: new Memory({ id: 'chat-memory', storage })
|
|
1662
|
+
* }
|
|
1663
|
+
* });
|
|
1664
|
+
*
|
|
1665
|
+
* const memory = mastra.getMemoryById('chat-memory');
|
|
1666
|
+
* ```
|
|
1667
|
+
*/
|
|
1668
|
+
getMemoryById(id) {
|
|
1669
|
+
const allMemory = this.#memory;
|
|
1670
|
+
if (allMemory) {
|
|
1671
|
+
for (const [, memory] of Object.entries(allMemory)) {
|
|
1672
|
+
if (memory.id === id) {
|
|
1673
|
+
return memory;
|
|
1674
|
+
}
|
|
1675
|
+
}
|
|
1676
|
+
}
|
|
1677
|
+
const error = new MastraError({
|
|
1678
|
+
id: "MASTRA_GET_MEMORY_BY_ID_NOT_FOUND",
|
|
1679
|
+
domain: "MASTRA" /* MASTRA */,
|
|
1680
|
+
category: "USER" /* USER */,
|
|
1681
|
+
text: `Memory with id ${id} not found`,
|
|
1682
|
+
details: {
|
|
1683
|
+
status: 404,
|
|
1684
|
+
memoryId: id,
|
|
1685
|
+
availableIds: Object.values(allMemory ?? {}).map((m) => m.id).join(", ")
|
|
1686
|
+
}
|
|
1687
|
+
});
|
|
1688
|
+
this.#logger?.trackException(error);
|
|
1689
|
+
throw error;
|
|
1690
|
+
}
|
|
1691
|
+
/**
|
|
1692
|
+
* Returns all registered memory instances as a record keyed by their names.
|
|
1693
|
+
*
|
|
1694
|
+
* @example
|
|
1695
|
+
* ```typescript
|
|
1696
|
+
* const mastra = new Mastra({
|
|
1697
|
+
* memory: {
|
|
1698
|
+
* chat: new Memory({ storage }),
|
|
1699
|
+
* longTerm: new Memory({ storage })
|
|
1700
|
+
* }
|
|
1701
|
+
* });
|
|
1702
|
+
*
|
|
1703
|
+
* const allMemory = mastra.listMemory();
|
|
1704
|
+
* console.log(Object.keys(allMemory)); // ['chat', 'longTerm']
|
|
1705
|
+
* ```
|
|
1706
|
+
*/
|
|
1707
|
+
listMemory() {
|
|
1708
|
+
return this.#memory;
|
|
1709
|
+
}
|
|
1710
|
+
/**
|
|
1711
|
+
* Adds a new memory instance to the Mastra instance.
|
|
1712
|
+
*
|
|
1713
|
+
* This method allows dynamic registration of memory instances after the Mastra instance
|
|
1714
|
+
* has been created.
|
|
1715
|
+
*
|
|
1716
|
+
* @example
|
|
1717
|
+
* ```typescript
|
|
1718
|
+
* const mastra = new Mastra();
|
|
1719
|
+
* const chatMemory = new Memory({
|
|
1720
|
+
* id: 'chat-memory',
|
|
1721
|
+
* storage: mastra.getStorage()
|
|
1722
|
+
* });
|
|
1723
|
+
* mastra.addMemory(chatMemory); // Uses memory.id as key
|
|
1724
|
+
* // or
|
|
1725
|
+
* mastra.addMemory(chatMemory, 'customKey'); // Uses custom key
|
|
1726
|
+
* ```
|
|
1727
|
+
*/
|
|
1728
|
+
addMemory(memory, key) {
|
|
1729
|
+
if (!memory) {
|
|
1730
|
+
throw createUndefinedPrimitiveError("memory", memory, key);
|
|
1731
|
+
}
|
|
1732
|
+
const memoryKey = key || memory.id;
|
|
1733
|
+
const memoryRegistry = this.#memory;
|
|
1734
|
+
if (memoryRegistry[memoryKey]) {
|
|
1735
|
+
const logger = this.getLogger();
|
|
1736
|
+
logger.debug(`Memory with key ${memoryKey} already exists. Skipping addition.`);
|
|
1737
|
+
return;
|
|
1738
|
+
}
|
|
1739
|
+
memoryRegistry[memoryKey] = memory;
|
|
1740
|
+
}
|
|
1281
1741
|
/**
|
|
1282
1742
|
* Returns all registered workflows as a record keyed by their IDs.
|
|
1283
1743
|
*
|
|
@@ -1333,6 +1793,9 @@ var Mastra = class {
|
|
|
1333
1793
|
* ```
|
|
1334
1794
|
*/
|
|
1335
1795
|
addWorkflow(workflow, key) {
|
|
1796
|
+
if (!workflow) {
|
|
1797
|
+
throw createUndefinedPrimitiveError("workflow", workflow, key);
|
|
1798
|
+
}
|
|
1336
1799
|
const workflowKey = key || workflow.id;
|
|
1337
1800
|
const workflows = this.#workflows;
|
|
1338
1801
|
if (workflows[workflowKey]) {
|
|
@@ -1345,6 +1808,9 @@ var Mastra = class {
|
|
|
1345
1808
|
logger: this.getLogger(),
|
|
1346
1809
|
storage: this.getStorage()
|
|
1347
1810
|
});
|
|
1811
|
+
if (!workflow.committed) {
|
|
1812
|
+
workflow.commit();
|
|
1813
|
+
}
|
|
1348
1814
|
workflows[workflowKey] = workflow;
|
|
1349
1815
|
}
|
|
1350
1816
|
/**
|
|
@@ -1398,6 +1864,9 @@ var Mastra = class {
|
|
|
1398
1864
|
this.#mcpServers?.[key]?.__setLogger(this.#logger);
|
|
1399
1865
|
});
|
|
1400
1866
|
}
|
|
1867
|
+
if (this.#serverAdapter) {
|
|
1868
|
+
this.#serverAdapter.__setLogger(this.#logger);
|
|
1869
|
+
}
|
|
1401
1870
|
this.#observability.setLogger({ logger: this.#logger });
|
|
1402
1871
|
}
|
|
1403
1872
|
/**
|
|
@@ -1511,6 +1980,74 @@ var Mastra = class {
|
|
|
1511
1980
|
getServer() {
|
|
1512
1981
|
return this.#server;
|
|
1513
1982
|
}
|
|
1983
|
+
/**
|
|
1984
|
+
* Sets the server adapter for this Mastra instance.
|
|
1985
|
+
*
|
|
1986
|
+
* The server adapter provides access to the underlying server app (e.g., Hono, Express)
|
|
1987
|
+
* and allows users to call routes directly via `app.fetch()` instead of making HTTP requests.
|
|
1988
|
+
*
|
|
1989
|
+
* This is typically called by `createHonoServer` or similar factory functions during
|
|
1990
|
+
* server initialization.
|
|
1991
|
+
*
|
|
1992
|
+
* @param adapter - The server adapter instance (e.g., MastraServer from @mastra/hono or @mastra/express)
|
|
1993
|
+
*
|
|
1994
|
+
* @example
|
|
1995
|
+
* ```typescript
|
|
1996
|
+
* const app = new Hono();
|
|
1997
|
+
* const adapter = new MastraServer({ app, mastra });
|
|
1998
|
+
* mastra.setMastraServer(adapter);
|
|
1999
|
+
* ```
|
|
2000
|
+
*/
|
|
2001
|
+
setMastraServer(adapter) {
|
|
2002
|
+
if (this.#serverAdapter) {
|
|
2003
|
+
this.#logger?.debug(
|
|
2004
|
+
"Replacing existing server adapter. Only one adapter should be registered per Mastra instance."
|
|
2005
|
+
);
|
|
2006
|
+
}
|
|
2007
|
+
this.#serverAdapter = adapter;
|
|
2008
|
+
if (this.#logger) {
|
|
2009
|
+
adapter.__setLogger(this.#logger);
|
|
2010
|
+
}
|
|
2011
|
+
}
|
|
2012
|
+
/**
|
|
2013
|
+
* Gets the server adapter for this Mastra instance.
|
|
2014
|
+
*
|
|
2015
|
+
* @returns The server adapter, or undefined if not set
|
|
2016
|
+
*
|
|
2017
|
+
* @example
|
|
2018
|
+
* ```typescript
|
|
2019
|
+
* const adapter = mastra.getMastraServer();
|
|
2020
|
+
* if (adapter) {
|
|
2021
|
+
* const app = adapter.getApp<Hono>();
|
|
2022
|
+
* }
|
|
2023
|
+
* ```
|
|
2024
|
+
*/
|
|
2025
|
+
getMastraServer() {
|
|
2026
|
+
return this.#serverAdapter;
|
|
2027
|
+
}
|
|
2028
|
+
/**
|
|
2029
|
+
* Gets the server app from the server adapter.
|
|
2030
|
+
*
|
|
2031
|
+
* This is a convenience method that calls `getMastraServer()?.getApp<T>()`.
|
|
2032
|
+
* Use this to access the underlying server framework's app instance (e.g., Hono, Express)
|
|
2033
|
+
* for direct operations like calling routes via `app.fetch()`.
|
|
2034
|
+
*
|
|
2035
|
+
* @template T - The expected type of the app (e.g., Hono, Express Application)
|
|
2036
|
+
* @returns The server app, or undefined if no adapter is set
|
|
2037
|
+
*
|
|
2038
|
+
* @example
|
|
2039
|
+
* ```typescript
|
|
2040
|
+
* // After createHonoServer() is called:
|
|
2041
|
+
* const app = mastra.getServerApp<Hono>();
|
|
2042
|
+
*
|
|
2043
|
+
* // Call routes directly without HTTP overhead
|
|
2044
|
+
* const response = await app?.fetch(new Request('http://localhost/health'));
|
|
2045
|
+
* const data = await response?.json();
|
|
2046
|
+
* ```
|
|
2047
|
+
*/
|
|
2048
|
+
getServerApp() {
|
|
2049
|
+
return this.#serverAdapter?.getApp();
|
|
2050
|
+
}
|
|
1514
2051
|
getBundlerConfig() {
|
|
1515
2052
|
return this.#bundler;
|
|
1516
2053
|
}
|
|
@@ -1634,6 +2171,9 @@ var Mastra = class {
|
|
|
1634
2171
|
* ```
|
|
1635
2172
|
*/
|
|
1636
2173
|
addMCPServer(server, key) {
|
|
2174
|
+
if (!server) {
|
|
2175
|
+
throw createUndefinedPrimitiveError("mcp-server", server, key);
|
|
2176
|
+
}
|
|
1637
2177
|
if (key) {
|
|
1638
2178
|
server.setId(key);
|
|
1639
2179
|
}
|
|
@@ -1778,6 +2318,201 @@ var Mastra = class {
|
|
|
1778
2318
|
}
|
|
1779
2319
|
await this.#pubsub.flush();
|
|
1780
2320
|
}
|
|
2321
|
+
/**
|
|
2322
|
+
* Retrieves a registered gateway by its key.
|
|
2323
|
+
*
|
|
2324
|
+
* @throws {MastraError} When the gateway with the specified key is not found
|
|
2325
|
+
*
|
|
2326
|
+
* @example
|
|
2327
|
+
* ```typescript
|
|
2328
|
+
* const mastra = new Mastra({
|
|
2329
|
+
* gateways: {
|
|
2330
|
+
* myGateway: new CustomGateway()
|
|
2331
|
+
* }
|
|
2332
|
+
* });
|
|
2333
|
+
*
|
|
2334
|
+
* const gateway = mastra.getGateway('myGateway');
|
|
2335
|
+
* ```
|
|
2336
|
+
*/
|
|
2337
|
+
getGateway(key) {
|
|
2338
|
+
const gateway = this.#gateways?.[key];
|
|
2339
|
+
if (!gateway) {
|
|
2340
|
+
const error = new MastraError({
|
|
2341
|
+
id: "MASTRA_GET_GATEWAY_BY_KEY_NOT_FOUND",
|
|
2342
|
+
domain: "MASTRA" /* MASTRA */,
|
|
2343
|
+
category: "USER" /* USER */,
|
|
2344
|
+
text: `Gateway with key ${key} not found`,
|
|
2345
|
+
details: {
|
|
2346
|
+
status: 404,
|
|
2347
|
+
gatewayKey: key,
|
|
2348
|
+
gateways: Object.keys(this.#gateways ?? {}).join(", ")
|
|
2349
|
+
}
|
|
2350
|
+
});
|
|
2351
|
+
this.#logger?.trackException(error);
|
|
2352
|
+
throw error;
|
|
2353
|
+
}
|
|
2354
|
+
return gateway;
|
|
2355
|
+
}
|
|
2356
|
+
/**
|
|
2357
|
+
* Retrieves a registered gateway by its ID.
|
|
2358
|
+
*
|
|
2359
|
+
* Searches through all registered gateways and returns the one whose ID matches.
|
|
2360
|
+
* If a gateway doesn't have an explicit ID, its name is used as the ID.
|
|
2361
|
+
*
|
|
2362
|
+
* @throws {MastraError} When no gateway with the specified ID is found
|
|
2363
|
+
*
|
|
2364
|
+
* @example
|
|
2365
|
+
* ```typescript
|
|
2366
|
+
* class CustomGateway extends MastraModelGateway {
|
|
2367
|
+
* readonly id = 'custom-gateway-v1';
|
|
2368
|
+
* readonly name = 'Custom Gateway';
|
|
2369
|
+
* // ...
|
|
2370
|
+
* }
|
|
2371
|
+
*
|
|
2372
|
+
* const mastra = new Mastra({
|
|
2373
|
+
* gateways: {
|
|
2374
|
+
* myGateway: new CustomGateway()
|
|
2375
|
+
* }
|
|
2376
|
+
* });
|
|
2377
|
+
*
|
|
2378
|
+
* const gateway = mastra.getGatewayById('custom-gateway-v1');
|
|
2379
|
+
* ```
|
|
2380
|
+
*/
|
|
2381
|
+
getGatewayById(id) {
|
|
2382
|
+
const gateways = this.#gateways ?? {};
|
|
2383
|
+
for (const gateway of Object.values(gateways)) {
|
|
2384
|
+
if (gateway.getId() === id) {
|
|
2385
|
+
return gateway;
|
|
2386
|
+
}
|
|
2387
|
+
}
|
|
2388
|
+
const error = new MastraError({
|
|
2389
|
+
id: "MASTRA_GET_GATEWAY_BY_ID_NOT_FOUND",
|
|
2390
|
+
domain: "MASTRA" /* MASTRA */,
|
|
2391
|
+
category: "USER" /* USER */,
|
|
2392
|
+
text: `Gateway with ID ${id} not found`,
|
|
2393
|
+
details: {
|
|
2394
|
+
status: 404,
|
|
2395
|
+
gatewayId: id,
|
|
2396
|
+
availableIds: Object.values(gateways).map((g) => g.getId()).join(", ")
|
|
2397
|
+
}
|
|
2398
|
+
});
|
|
2399
|
+
this.#logger?.trackException(error);
|
|
2400
|
+
throw error;
|
|
2401
|
+
}
|
|
2402
|
+
/**
|
|
2403
|
+
* Returns all registered gateways as a record keyed by their names.
|
|
2404
|
+
*
|
|
2405
|
+
* @example
|
|
2406
|
+
* ```typescript
|
|
2407
|
+
* const mastra = new Mastra({
|
|
2408
|
+
* gateways: {
|
|
2409
|
+
* netlify: new NetlifyGateway(),
|
|
2410
|
+
* custom: new CustomGateway()
|
|
2411
|
+
* }
|
|
2412
|
+
* });
|
|
2413
|
+
*
|
|
2414
|
+
* const allGateways = mastra.listGateways();
|
|
2415
|
+
* console.log(Object.keys(allGateways)); // ['netlify', 'custom']
|
|
2416
|
+
* ```
|
|
2417
|
+
*/
|
|
2418
|
+
listGateways() {
|
|
2419
|
+
return this.#gateways;
|
|
2420
|
+
}
|
|
2421
|
+
/**
|
|
2422
|
+
* Adds a new gateway to the Mastra instance.
|
|
2423
|
+
*
|
|
2424
|
+
* This method allows dynamic registration of gateways after the Mastra instance
|
|
2425
|
+
* has been created. Gateways enable access to LLM providers through custom
|
|
2426
|
+
* authentication and routing logic.
|
|
2427
|
+
*
|
|
2428
|
+
* If no key is provided, the gateway's ID (or name if no ID is set) will be used as the key.
|
|
2429
|
+
*
|
|
2430
|
+
* @example
|
|
2431
|
+
* ```typescript
|
|
2432
|
+
* import { MastraModelGateway } from '@mastra/core';
|
|
2433
|
+
*
|
|
2434
|
+
* class CustomGateway extends MastraModelGateway {
|
|
2435
|
+
* readonly id = 'custom-gateway-v1'; // Optional, defaults to name
|
|
2436
|
+
* readonly name = 'custom';
|
|
2437
|
+
* readonly prefix = 'custom';
|
|
2438
|
+
*
|
|
2439
|
+
* async fetchProviders() {
|
|
2440
|
+
* return {
|
|
2441
|
+
* myProvider: {
|
|
2442
|
+
* name: 'My Provider',
|
|
2443
|
+
* models: ['model-1', 'model-2'],
|
|
2444
|
+
* apiKeyEnvVar: 'MY_API_KEY',
|
|
2445
|
+
* gateway: 'custom'
|
|
2446
|
+
* }
|
|
2447
|
+
* };
|
|
2448
|
+
* }
|
|
2449
|
+
*
|
|
2450
|
+
* buildUrl(modelId: string) {
|
|
2451
|
+
* return 'https://api.myprovider.com/v1';
|
|
2452
|
+
* }
|
|
2453
|
+
*
|
|
2454
|
+
* async getApiKey(modelId: string) {
|
|
2455
|
+
* return process.env.MY_API_KEY || '';
|
|
2456
|
+
* }
|
|
2457
|
+
*
|
|
2458
|
+
* async resolveLanguageModel({ modelId, providerId, apiKey }) {
|
|
2459
|
+
* const baseURL = this.buildUrl(`${providerId}/${modelId}`);
|
|
2460
|
+
* return createOpenAICompatible({
|
|
2461
|
+
* name: providerId,
|
|
2462
|
+
* apiKey,
|
|
2463
|
+
* baseURL,
|
|
2464
|
+
* supportsStructuredOutputs: true,
|
|
2465
|
+
* }).chatModel(modelId);
|
|
2466
|
+
* }
|
|
2467
|
+
* }
|
|
2468
|
+
*
|
|
2469
|
+
* const mastra = new Mastra();
|
|
2470
|
+
* const newGateway = new CustomGateway();
|
|
2471
|
+
* mastra.addGateway(newGateway); // Uses gateway.getId() as key (gateway.id)
|
|
2472
|
+
* // or
|
|
2473
|
+
* mastra.addGateway(newGateway, 'customKey'); // Uses custom key
|
|
2474
|
+
* ```
|
|
2475
|
+
*/
|
|
2476
|
+
addGateway(gateway, key) {
|
|
2477
|
+
if (!gateway) {
|
|
2478
|
+
throw createUndefinedPrimitiveError("gateway", gateway, key);
|
|
2479
|
+
}
|
|
2480
|
+
const gatewayKey = key || gateway.getId();
|
|
2481
|
+
const gateways = this.#gateways;
|
|
2482
|
+
if (gateways[gatewayKey]) {
|
|
2483
|
+
const logger = this.getLogger();
|
|
2484
|
+
logger.debug(`Gateway with key ${gatewayKey} already exists. Skipping addition.`);
|
|
2485
|
+
return;
|
|
2486
|
+
}
|
|
2487
|
+
gateways[gatewayKey] = gateway;
|
|
2488
|
+
this.#syncGatewayRegistry();
|
|
2489
|
+
}
|
|
2490
|
+
/**
|
|
2491
|
+
* Sync custom gateways with the GatewayRegistry for type generation
|
|
2492
|
+
* @private
|
|
2493
|
+
*/
|
|
2494
|
+
#syncGatewayRegistry() {
|
|
2495
|
+
try {
|
|
2496
|
+
if (process.env.MASTRA_DEV !== "true" && process.env.MASTRA_DEV !== "1") {
|
|
2497
|
+
return;
|
|
2498
|
+
}
|
|
2499
|
+
import('./provider-registry-XM2YDI5X.js').then(async ({ GatewayRegistry }) => {
|
|
2500
|
+
const registry = GatewayRegistry.getInstance();
|
|
2501
|
+
const customGateways = Object.values(this.#gateways || {});
|
|
2502
|
+
registry.registerCustomGateways(customGateways);
|
|
2503
|
+
const logger = this.getLogger();
|
|
2504
|
+
logger.info("\u{1F504} Syncing custom gateway types...");
|
|
2505
|
+
await registry.syncGateways(true);
|
|
2506
|
+
logger.info("\u2705 Custom gateway types synced! Restart your TypeScript server to see autocomplete.");
|
|
2507
|
+
}).catch((err) => {
|
|
2508
|
+
const logger = this.getLogger();
|
|
2509
|
+
logger.debug("Gateway registry sync skipped:", err);
|
|
2510
|
+
});
|
|
2511
|
+
} catch (err) {
|
|
2512
|
+
const logger = this.getLogger();
|
|
2513
|
+
logger.debug("Gateway registry sync failed:", err);
|
|
2514
|
+
}
|
|
2515
|
+
}
|
|
1781
2516
|
/**
|
|
1782
2517
|
* Gracefully shuts down the Mastra instance and cleans up all resources.
|
|
1783
2518
|
*
|
|
@@ -1815,5 +2550,5 @@ var Mastra = class {
|
|
|
1815
2550
|
};
|
|
1816
2551
|
|
|
1817
2552
|
export { Mastra };
|
|
1818
|
-
//# sourceMappingURL=chunk-
|
|
1819
|
-
//# sourceMappingURL=chunk-
|
|
2553
|
+
//# sourceMappingURL=chunk-NUA6TSRD.js.map
|
|
2554
|
+
//# sourceMappingURL=chunk-NUA6TSRD.js.map
|