@mastra/core 1.0.0-beta.1 → 1.0.0-beta.11
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 +1218 -0
- package/dist/agent/agent-legacy.d.ts +35 -30
- 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 +24 -9
- package/dist/agent/agent.d.ts.map +1 -1
- package/dist/agent/agent.types.d.ts +17 -9
- 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 +61 -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 +38 -4
- package/dist/agent/trip-wire.d.ts.map +1 -1
- package/dist/agent/types.d.ts +46 -14
- package/dist/agent/types.d.ts.map +1 -1
- package/dist/agent/utils.d.ts +4 -5
- package/dist/agent/utils.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/index.d.ts +37 -13
- 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 +34 -11
- 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 +38 -15
- 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-JUBFO5J3.js → chunk-2ULLRN4Y.js} +16333 -11839
- package/dist/chunk-2ULLRN4Y.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-3E3ILV6T.cjs +518 -0
- package/dist/chunk-3E3ILV6T.cjs.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-MSWTA73A.cjs → chunk-52RSUALV.cjs} +16490 -11957
- package/dist/chunk-52RSUALV.cjs.map +1 -0
- package/dist/chunk-5PAEYE3Q.js +513 -0
- package/dist/chunk-5PAEYE3Q.js.map +1 -0
- package/dist/{chunk-ECFXGXWO.cjs → chunk-5Q6WAYEY.cjs} +695 -375
- package/dist/chunk-5Q6WAYEY.cjs.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-GRBGQ2GE.js → chunk-6TBWJV35.js} +5 -3
- 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-W7UH2PWL.js → chunk-7P6BNIJH.js} +1142 -331
- package/dist/chunk-7P6BNIJH.js.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-GGYKYORQ.cjs → chunk-BJXKH4LG.cjs} +407 -22
- package/dist/chunk-BJXKH4LG.cjs.map +1 -0
- package/dist/{chunk-2ZVKF4HP.cjs → chunk-BUKY6CTR.cjs} +1147 -334
- package/dist/chunk-BUKY6CTR.cjs.map +1 -0
- package/dist/chunk-BWYU7D33.js +192 -0
- package/dist/chunk-BWYU7D33.js.map +1 -0
- package/dist/{chunk-XEVG546F.js → chunk-C36YRTZ6.js} +178 -12
- package/dist/chunk-C36YRTZ6.js.map +1 -0
- package/dist/{chunk-CB575O6L.cjs → chunk-CZEJQSWB.cjs} +473 -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-4CDL2QJT.js → chunk-IVV5TOMD.js} +122 -37
- package/dist/chunk-IVV5TOMD.js.map +1 -0
- package/dist/{chunk-MV7KHWUT.js → chunk-JIGDJK2O.js} +391 -15
- package/dist/chunk-JIGDJK2O.js.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-KJ2SW6VA.js → chunk-NRUZYMHE.js} +4 -3
- package/dist/chunk-NRUZYMHE.js.map +1 -0
- package/dist/{chunk-CINNK34N.js → chunk-O2BJW7YA.js} +26 -11
- package/dist/chunk-O2BJW7YA.js.map +1 -0
- package/dist/chunk-OEIVMCWX.js +4959 -0
- package/dist/chunk-OEIVMCWX.js.map +1 -0
- package/dist/{chunk-WM6CK2F3.cjs → chunk-PG5H6QIO.cjs} +131 -49
- package/dist/chunk-PG5H6QIO.cjs.map +1 -0
- package/dist/{chunk-JPGVRWWL.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-VOY2RXOC.cjs → chunk-S73Z3PBJ.cjs} +182 -15
- package/dist/chunk-S73Z3PBJ.cjs.map +1 -0
- package/dist/{chunk-MA7TEM62.cjs → chunk-SCUWP4II.cjs} +769 -27
- package/dist/chunk-SCUWP4II.cjs.map +1 -0
- package/dist/{chunk-JV2KH24V.js → chunk-SXNQRJQD.js} +695 -375
- package/dist/chunk-SXNQRJQD.js.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-VOQ3ULMT.js → chunk-U3XOLEPX.js} +759 -17
- package/dist/chunk-U3XOLEPX.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-H6CZGPZD.js → chunk-US2U7ECW.js} +179 -38
- package/dist/chunk-US2U7ECW.js.map +1 -0
- package/dist/{chunk-J7O6WENZ.cjs → chunk-UVHSM2GU.cjs} +6 -2
- package/dist/chunk-UVHSM2GU.cjs.map +1 -0
- package/dist/{chunk-CD56CXVE.cjs → chunk-WTSZBHIZ.cjs} +32 -17
- package/dist/chunk-WTSZBHIZ.cjs.map +1 -0
- package/dist/{chunk-KIZIOFZC.js → chunk-Y36Y5MTD.js} +17 -3
- package/dist/chunk-Y36Y5MTD.js.map +1 -0
- package/dist/{chunk-DNEURYF3.cjs → chunk-YC6PJEPH.cjs} +206 -65
- package/dist/chunk-YC6PJEPH.cjs.map +1 -0
- package/dist/{chunk-IQO7ANVS.cjs → chunk-YWMMBIOM.cjs} +21 -20
- package/dist/chunk-YWMMBIOM.cjs.map +1 -0
- package/dist/{chunk-I4CXL4SR.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/base.types.d.ts +2 -2
- package/dist/llm/model/base.types.d.ts.map +1 -1
- 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 +4 -2
- 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 +489 -27
- 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 +17 -6
- 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 +42 -20
- package/dist/loop/types.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/index.d.ts +60 -42
- package/dist/loop/workflows/agentic-execution/index.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts +41 -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 +20 -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 +62 -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 +32 -15
- package/dist/loop/workflows/schema.d.ts.map +1 -1
- 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-DNBKXHT4.js.map → models-dev-23RN2WHG.js.map} +1 -1
- package/dist/models-dev-EO3SUIY2.cjs +12 -0
- package/dist/{models-dev-YBEEQIX6.cjs.map → models-dev-EO3SUIY2.cjs.map} +1 -1
- package/dist/netlify-GXJ5D5DD.js +3 -0
- package/dist/{netlify-7G2L5VSH.js.map → netlify-GXJ5D5DD.js.map} +1 -1
- package/dist/netlify-KJLY3GFS.cjs +12 -0
- package/dist/{netlify-GWNGSIRZ.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 +115 -11
- package/dist/processors/index.d.ts +246 -26
- 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/prepare-step.d.ts +12 -0
- package/dist/processors/processors/prepare-step.d.ts.map +1 -0
- 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 +7 -5
- 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 +83 -9
- package/dist/processors/runner.d.ts.map +1 -1
- package/dist/processors/step-schema.d.ts +49731 -0
- package/dist/processors/step-schema.d.ts.map +1 -0
- package/dist/provider-registry-3TG2KUD2.cjs +40 -0
- package/dist/provider-registry-3TG2KUD2.cjs.map +1 -0
- package/dist/provider-registry-F67Y6OF2.js +3 -0
- package/dist/provider-registry-F67Y6OF2.js.map +1 -0
- package/dist/provider-registry.json +1056 -61
- 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/server/types.d.ts +6 -0
- package/dist/server/types.d.ts.map +1 -1
- 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 +88 -5
- 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 +2 -2
- package/dist/stream/MastraAgentNetworkStream.d.ts.map +1 -1
- package/dist/stream/MastraWorkflowStream.d.ts +2 -2
- 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/transform.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 +9 -5
- 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-helpers.d.ts +5 -1
- package/dist/stream/aisdk/v5/output-helpers.d.ts.map +1 -1
- package/dist/stream/aisdk/v5/output.d.ts +11 -13
- package/dist/stream/aisdk/v5/output.d.ts.map +1 -1
- package/dist/stream/aisdk/v5/transform.d.ts +2 -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 +9 -14
- 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 +97 -32
- 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 +180 -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 +40 -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 +257 -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 +146 -55
- package/dist/workflows/workflow.d.ts.map +1 -1
- package/package.json +26 -30
- package/src/llm/model/provider-types.generated.d.ts +489 -27
- package/dist/chunk-2ZVKF4HP.cjs.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-CB575O6L.cjs.map +0 -1
- package/dist/chunk-CD56CXVE.cjs.map +0 -1
- package/dist/chunk-CINNK34N.js.map +0 -1
- package/dist/chunk-DNEURYF3.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-GGYKYORQ.cjs.map +0 -1
- package/dist/chunk-GRBGQ2GE.js.map +0 -1
- package/dist/chunk-H6CZGPZD.js.map +0 -1
- package/dist/chunk-HDJFSJCK.js +0 -2237
- package/dist/chunk-HDJFSJCK.js.map +0 -1
- package/dist/chunk-HGNRQ3OG.js +0 -58
- package/dist/chunk-HGNRQ3OG.js.map +0 -1
- package/dist/chunk-I4CXL4SR.js.map +0 -1
- package/dist/chunk-IQO7ANVS.cjs.map +0 -1
- package/dist/chunk-J7O6WENZ.cjs.map +0 -1
- package/dist/chunk-JPGVRWWL.js.map +0 -1
- package/dist/chunk-JUBFO5J3.js.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-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-LWBQ4P4N.cjs +0 -2240
- package/dist/chunk-LWBQ4P4N.cjs.map +0 -1
- package/dist/chunk-MA7TEM62.cjs.map +0 -1
- package/dist/chunk-MSWTA73A.cjs.map +0 -1
- package/dist/chunk-MV7KHWUT.js.map +0 -1
- package/dist/chunk-QUKUN6NR.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-VOQ3ULMT.js.map +0 -1
- package/dist/chunk-VOY2RXOC.cjs.map +0 -1
- package/dist/chunk-W7UH2PWL.js.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-ZV5CC35D.js +0 -3
- package/dist/chunk-ZV5CC35D.js.map +0 -1
- package/dist/models-dev-DNBKXHT4.js +0 -3
- package/dist/models-dev-YBEEQIX6.cjs +0 -12
- package/dist/netlify-7G2L5VSH.js +0 -3
- package/dist/netlify-GWNGSIRZ.cjs +0 -12
- 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-US2U7ECW.js';
|
|
2
|
+
import { saveScorePayloadSchema } from './chunk-ADADLFDR.js';
|
|
4
3
|
import { PubSub } from './chunk-BVUMKER5.js';
|
|
5
|
-
import {
|
|
4
|
+
import { augmentWithInit, Agent } from './chunk-2ULLRN4Y.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]) {
|
|
@@ -544,6 +828,13 @@ var Mastra = class {
|
|
|
544
828
|
vectors: this.#vectors
|
|
545
829
|
});
|
|
546
830
|
agents[agentKey] = agent;
|
|
831
|
+
agent.getConfiguredProcessorWorkflows().then((processorWorkflows) => {
|
|
832
|
+
for (const workflow of processorWorkflows) {
|
|
833
|
+
this.addWorkflow(workflow, workflow.id);
|
|
834
|
+
}
|
|
835
|
+
}).catch((err) => {
|
|
836
|
+
this.#logger?.debug(`Failed to register processor workflows for agent ${agentKey}:`, err);
|
|
837
|
+
});
|
|
547
838
|
}
|
|
548
839
|
/**
|
|
549
840
|
* Retrieves a registered vector store by its name.
|
|
@@ -689,6 +980,9 @@ var Mastra = class {
|
|
|
689
980
|
* ```
|
|
690
981
|
*/
|
|
691
982
|
addVector(vector, key) {
|
|
983
|
+
if (!vector) {
|
|
984
|
+
throw createUndefinedPrimitiveError("vector", vector, key);
|
|
985
|
+
}
|
|
692
986
|
const vectorKey = key || vector.id;
|
|
693
987
|
const vectors = this.#vectors;
|
|
694
988
|
if (vectors[vectorKey]) {
|
|
@@ -859,6 +1153,44 @@ var Mastra = class {
|
|
|
859
1153
|
}
|
|
860
1154
|
return workflow;
|
|
861
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
|
+
}
|
|
862
1194
|
/**
|
|
863
1195
|
* Returns all registered scorers as a record keyed by their IDs.
|
|
864
1196
|
*
|
|
@@ -907,6 +1239,9 @@ var Mastra = class {
|
|
|
907
1239
|
* ```
|
|
908
1240
|
*/
|
|
909
1241
|
addScorer(scorer, key) {
|
|
1242
|
+
if (!scorer) {
|
|
1243
|
+
throw createUndefinedPrimitiveError("scorer", scorer, key);
|
|
1244
|
+
}
|
|
910
1245
|
const scorerKey = key || scorer.id;
|
|
911
1246
|
const scorers = this.#scorers;
|
|
912
1247
|
if (scorers[scorerKey]) {
|
|
@@ -914,6 +1249,7 @@ var Mastra = class {
|
|
|
914
1249
|
logger.debug(`Scorer with key ${scorerKey} already exists. Skipping addition.`);
|
|
915
1250
|
return;
|
|
916
1251
|
}
|
|
1252
|
+
scorer.__registerMastra(this);
|
|
917
1253
|
scorers[scorerKey] = scorer;
|
|
918
1254
|
}
|
|
919
1255
|
/**
|
|
@@ -1134,6 +1470,9 @@ var Mastra = class {
|
|
|
1134
1470
|
* ```
|
|
1135
1471
|
*/
|
|
1136
1472
|
addTool(tool, key) {
|
|
1473
|
+
if (!tool) {
|
|
1474
|
+
throw createUndefinedPrimitiveError("tool", tool, key);
|
|
1475
|
+
}
|
|
1137
1476
|
const toolKey = key || tool.id;
|
|
1138
1477
|
const tools = this.#tools;
|
|
1139
1478
|
if (tools[toolKey]) {
|
|
@@ -1269,6 +1608,9 @@ var Mastra = class {
|
|
|
1269
1608
|
* ```
|
|
1270
1609
|
*/
|
|
1271
1610
|
addProcessor(processor, key) {
|
|
1611
|
+
if (!processor) {
|
|
1612
|
+
throw createUndefinedPrimitiveError("processor", processor, key);
|
|
1613
|
+
}
|
|
1272
1614
|
const processorKey = key || processor.id;
|
|
1273
1615
|
const processors = this.#processors;
|
|
1274
1616
|
if (processors[processorKey]) {
|
|
@@ -1278,6 +1620,131 @@ var Mastra = class {
|
|
|
1278
1620
|
}
|
|
1279
1621
|
processors[processorKey] = processor;
|
|
1280
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 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 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
|
+
}
|
|
1281
1748
|
/**
|
|
1282
1749
|
* Returns all registered workflows as a record keyed by their IDs.
|
|
1283
1750
|
*
|
|
@@ -1333,6 +1800,9 @@ var Mastra = class {
|
|
|
1333
1800
|
* ```
|
|
1334
1801
|
*/
|
|
1335
1802
|
addWorkflow(workflow, key) {
|
|
1803
|
+
if (!workflow) {
|
|
1804
|
+
throw createUndefinedPrimitiveError("workflow", workflow, key);
|
|
1805
|
+
}
|
|
1336
1806
|
const workflowKey = key || workflow.id;
|
|
1337
1807
|
const workflows = this.#workflows;
|
|
1338
1808
|
if (workflows[workflowKey]) {
|
|
@@ -1345,6 +1815,9 @@ var Mastra = class {
|
|
|
1345
1815
|
logger: this.getLogger(),
|
|
1346
1816
|
storage: this.getStorage()
|
|
1347
1817
|
});
|
|
1818
|
+
if (!workflow.committed) {
|
|
1819
|
+
workflow.commit();
|
|
1820
|
+
}
|
|
1348
1821
|
workflows[workflowKey] = workflow;
|
|
1349
1822
|
}
|
|
1350
1823
|
/**
|
|
@@ -1398,6 +1871,9 @@ var Mastra = class {
|
|
|
1398
1871
|
this.#mcpServers?.[key]?.__setLogger(this.#logger);
|
|
1399
1872
|
});
|
|
1400
1873
|
}
|
|
1874
|
+
if (this.#serverAdapter) {
|
|
1875
|
+
this.#serverAdapter.__setLogger(this.#logger);
|
|
1876
|
+
}
|
|
1401
1877
|
this.#observability.setLogger({ logger: this.#logger });
|
|
1402
1878
|
}
|
|
1403
1879
|
/**
|
|
@@ -1511,6 +1987,74 @@ var Mastra = class {
|
|
|
1511
1987
|
getServer() {
|
|
1512
1988
|
return this.#server;
|
|
1513
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
|
+
}
|
|
1514
2058
|
getBundlerConfig() {
|
|
1515
2059
|
return this.#bundler;
|
|
1516
2060
|
}
|
|
@@ -1634,6 +2178,9 @@ var Mastra = class {
|
|
|
1634
2178
|
* ```
|
|
1635
2179
|
*/
|
|
1636
2180
|
addMCPServer(server, key) {
|
|
2181
|
+
if (!server) {
|
|
2182
|
+
throw createUndefinedPrimitiveError("mcp-server", server, key);
|
|
2183
|
+
}
|
|
1637
2184
|
if (key) {
|
|
1638
2185
|
server.setId(key);
|
|
1639
2186
|
}
|
|
@@ -1778,6 +2325,201 @@ var Mastra = class {
|
|
|
1778
2325
|
}
|
|
1779
2326
|
await this.#pubsub.flush();
|
|
1780
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 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 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-F67Y6OF2.js').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
|
+
}
|
|
1781
2523
|
/**
|
|
1782
2524
|
* Gracefully shuts down the Mastra instance and cleans up all resources.
|
|
1783
2525
|
*
|
|
@@ -1815,5 +2557,5 @@ var Mastra = class {
|
|
|
1815
2557
|
};
|
|
1816
2558
|
|
|
1817
2559
|
export { Mastra };
|
|
1818
|
-
//# sourceMappingURL=chunk-
|
|
1819
|
-
//# sourceMappingURL=chunk-
|
|
2560
|
+
//# sourceMappingURL=chunk-U3XOLEPX.js.map
|
|
2561
|
+
//# sourceMappingURL=chunk-U3XOLEPX.js.map
|