@mastra/core 1.0.0-beta.21 → 1.0.0-beta.22
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 +356 -0
- package/dist/action/index.d.ts +7 -7
- package/dist/action/index.d.ts.map +1 -1
- package/dist/agent/agent-legacy.d.ts.map +1 -1
- package/dist/agent/agent.d.ts +100 -18
- package/dist/agent/agent.d.ts.map +1 -1
- package/dist/agent/agent.types.d.ts +22 -18
- package/dist/agent/agent.types.d.ts.map +1 -1
- package/dist/agent/index.cjs +13 -13
- package/dist/agent/index.d.ts +1 -1
- package/dist/agent/index.d.ts.map +1 -1
- package/dist/agent/index.js +2 -2
- package/dist/agent/message-list/adapters/AIV4Adapter.d.ts.map +1 -1
- package/dist/agent/message-list/index.cjs +18 -18
- package/dist/agent/message-list/index.js +1 -1
- package/dist/agent/message-list/message-list.d.ts +2 -1
- package/dist/agent/message-list/message-list.d.ts.map +1 -1
- package/dist/agent/trip-wire.d.ts +1 -2
- package/dist/agent/trip-wire.d.ts.map +1 -1
- package/dist/agent/types.d.ts +9 -10
- package/dist/agent/types.d.ts.map +1 -1
- package/dist/agent/utils.d.ts +7 -42
- package/dist/agent/utils.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/index.d.ts +6 -118
- package/dist/agent/workflows/prepare-stream/index.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/map-results-step.d.ts +7 -11
- 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 +4 -68
- 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 +3 -45
- package/dist/agent/workflows/prepare-stream/prepare-tools-step.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/schema.d.ts +10 -10
- package/dist/agent/workflows/prepare-stream/stream-step.d.ts +2 -8
- package/dist/agent/workflows/prepare-stream/stream-step.d.ts.map +1 -1
- package/dist/{chunk-HJXEZSNI.js → chunk-3XY64RAM.js} +5 -5
- package/dist/{chunk-HJXEZSNI.js.map → chunk-3XY64RAM.js.map} +1 -1
- package/dist/{chunk-XSJNTLM7.js → chunk-453NPBJ7.js} +479 -47
- package/dist/chunk-453NPBJ7.js.map +1 -0
- package/dist/{chunk-3CZ42NBZ.js → chunk-5UVSKF5L.js} +17 -14
- package/dist/chunk-5UVSKF5L.js.map +1 -0
- package/dist/{chunk-XKDVT3ZH.cjs → chunk-67ZKOPA4.cjs} +480 -48
- package/dist/chunk-67ZKOPA4.cjs.map +1 -0
- package/dist/{chunk-YLP5IWH2.js → chunk-7IYWOBLG.js} +4 -4
- package/dist/{chunk-YLP5IWH2.js.map → chunk-7IYWOBLG.js.map} +1 -1
- package/dist/{chunk-3RCMDLCG.cjs → chunk-ALQFYWAR.cjs} +12 -12
- package/dist/{chunk-3RCMDLCG.cjs.map → chunk-ALQFYWAR.cjs.map} +1 -1
- package/dist/{chunk-PC3FBUWH.js → chunk-C4CIC3LZ.js} +2 -2
- package/dist/chunk-C4CIC3LZ.js.map +1 -0
- package/dist/{chunk-7JGQWNV5.js → chunk-CPLRD2VP.js} +3 -3
- package/dist/{chunk-7JGQWNV5.js.map → chunk-CPLRD2VP.js.map} +1 -1
- package/dist/{chunk-AHN7K3VE.js → chunk-CQ2E577C.js} +5 -5
- package/dist/chunk-CQ2E577C.js.map +1 -0
- package/dist/{chunk-A4MCHA5L.cjs → chunk-CVLIEFWM.cjs} +100 -819
- package/dist/chunk-CVLIEFWM.cjs.map +1 -0
- package/dist/{chunk-XBZWAUZ3.js → chunk-IFPQ2MLB.js} +25 -12
- package/dist/chunk-IFPQ2MLB.js.map +1 -0
- package/dist/{chunk-DVJZZAZA.cjs → chunk-IHD36QFA.cjs} +7 -7
- package/dist/{chunk-DVJZZAZA.cjs.map → chunk-IHD36QFA.cjs.map} +1 -1
- package/dist/{chunk-WMJEP45F.cjs → chunk-J4KVR4DZ.cjs} +25 -18
- package/dist/chunk-J4KVR4DZ.cjs.map +1 -0
- package/dist/{chunk-3RFSIHFR.js → chunk-K2LPTKSY.js} +4 -720
- package/dist/chunk-K2LPTKSY.js.map +1 -0
- package/dist/{chunk-FY3PYSMK.cjs → chunk-KHO4KFXW.cjs} +5 -5
- package/dist/{chunk-FY3PYSMK.cjs.map → chunk-KHO4KFXW.cjs.map} +1 -1
- package/dist/{chunk-W7R7GPNN.cjs → chunk-MGPIVG2O.cjs} +9 -9
- package/dist/chunk-MGPIVG2O.cjs.map +1 -0
- package/dist/{chunk-KGE3KAM7.js → chunk-N3PAHTKU.js} +23 -3
- package/dist/chunk-N3PAHTKU.js.map +1 -0
- package/dist/{chunk-O4H44CMA.js → chunk-N7TDP7ZE.js} +586 -117
- package/dist/chunk-N7TDP7ZE.js.map +1 -0
- package/dist/{chunk-I5GMA5UM.cjs → chunk-NPIYNC5A.cjs} +9 -9
- package/dist/{chunk-I5GMA5UM.cjs.map → chunk-NPIYNC5A.cjs.map} +1 -1
- package/dist/{chunk-AW7FISLD.cjs → chunk-OZ75PBBK.cjs} +27 -7
- package/dist/chunk-OZ75PBBK.cjs.map +1 -0
- package/dist/{chunk-JMAPJWVG.cjs → chunk-OZCUIZRA.cjs} +2021 -1426
- package/dist/chunk-OZCUIZRA.cjs.map +1 -0
- package/dist/{chunk-6OPEMI2Q.cjs → chunk-PM3UIIBK.cjs} +2 -3
- package/dist/{chunk-6OPEMI2Q.cjs.map → chunk-PM3UIIBK.cjs.map} +1 -1
- package/dist/{chunk-CISH55FP.js → chunk-PSIJ6OSV.js} +16 -9
- package/dist/chunk-PSIJ6OSV.js.map +1 -0
- package/dist/{chunk-UOZ3GJY2.cjs → chunk-PTK74KG4.cjs} +2 -2
- package/dist/chunk-PTK74KG4.cjs.map +1 -0
- package/dist/{chunk-O5IPTMEH.cjs → chunk-Q5QQDMSD.cjs} +32 -29
- package/dist/chunk-Q5QQDMSD.cjs.map +1 -0
- package/dist/{chunk-UVHSM2GU.cjs → chunk-SMM2C4KH.cjs} +6 -4
- package/dist/chunk-SMM2C4KH.cjs.map +1 -0
- package/dist/{chunk-UXLQEGIN.cjs → chunk-SVPXZEU7.cjs} +35 -22
- package/dist/chunk-SVPXZEU7.cjs.map +1 -0
- package/dist/{chunk-SOSXN7X4.cjs → chunk-TU6MNGBB.cjs} +619 -151
- package/dist/chunk-TU6MNGBB.cjs.map +1 -0
- package/dist/{chunk-EK7E4ETB.js → chunk-TX5GUG5Q.js} +3 -3
- package/dist/{chunk-EK7E4ETB.js.map → chunk-TX5GUG5Q.js.map} +1 -1
- package/dist/{chunk-SQ7T6FWC.cjs → chunk-UAH236P2.cjs} +13 -13
- package/dist/{chunk-SQ7T6FWC.cjs.map → chunk-UAH236P2.cjs.map} +1 -1
- package/dist/{chunk-AIJ6HPJG.js → chunk-UL7TJCKA.js} +4 -4
- package/dist/{chunk-AIJ6HPJG.js.map → chunk-UL7TJCKA.js.map} +1 -1
- package/dist/{chunk-IC2MIQBW.js → chunk-UVOQLIWL.js} +1922 -1326
- package/dist/chunk-UVOQLIWL.js.map +1 -0
- package/dist/{chunk-IMLORTHO.js → chunk-WANKWENG.js} +5 -5
- package/dist/{chunk-IMLORTHO.js.map → chunk-WANKWENG.js.map} +1 -1
- package/dist/{chunk-ICU4Z5MO.cjs → chunk-X7DR353F.cjs} +8 -8
- package/dist/{chunk-ICU4Z5MO.cjs.map → chunk-X7DR353F.cjs.map} +1 -1
- package/dist/{chunk-6TBWJV35.js → chunk-Y22QMA7S.js} +6 -4
- package/dist/chunk-Y22QMA7S.js.map +1 -0
- package/dist/{chunk-FT7DFPAL.js → chunk-YYNZEEOO.js} +5 -5
- package/dist/{chunk-FT7DFPAL.js.map → chunk-YYNZEEOO.js.map} +1 -1
- package/dist/di/index.cjs +4 -4
- package/dist/di/index.js +1 -1
- package/dist/docs/README.md +6 -5
- package/dist/docs/SKILL.md +6 -5
- package/dist/docs/SOURCE_MAP.json +288 -293
- package/dist/docs/agents/01-overview.md +2 -2
- package/dist/docs/agents/02-using-tools.md +5 -0
- package/dist/docs/agents/04-structured-output.md +24 -4
- package/dist/docs/agents/06-processors.md +65 -1
- package/dist/docs/agents/08-agent-approval.md +5 -6
- package/dist/docs/agents/09-network-approval.md +274 -0
- package/dist/docs/agents/{10-reference.md → 11-reference.md} +1 -1
- package/dist/docs/ai-sdk/01-reference.md +1 -1
- package/dist/docs/cli/01-reference.md +1 -1
- package/dist/docs/client-js/01-reference.md +10 -5
- package/dist/docs/configuration.mdx/01-reference.md +750 -0
- package/dist/docs/core/01-reference.md +9 -35
- package/dist/docs/deployer/01-reference.md +19 -6
- package/dist/docs/evals/01-overview.md +5 -5
- package/dist/docs/evals/02-custom-scorers.md +49 -6
- package/dist/docs/evals/04-reference.md +10 -4
- package/dist/docs/mcp/01-overview.md +26 -16
- package/dist/docs/mcp/02-publishing-mcp-server.md +2 -2
- package/dist/docs/memory/01-overview.md +2 -2
- package/dist/docs/memory/02-storage.md +59 -25
- package/dist/docs/memory/03-working-memory.md +10 -6
- package/dist/docs/memory/04-semantic-recall.md +2 -4
- package/dist/docs/memory/05-memory-processors.md +2 -3
- package/dist/docs/memory/06-reference.md +2 -4
- package/dist/docs/observability/01-overview.md +1 -1
- package/dist/docs/observability/02-logging.md +4 -5
- package/dist/docs/observability/03-overview.md +69 -13
- package/dist/docs/observability/09-datadog.md +169 -0
- package/dist/docs/observability/10-laminar.md +95 -0
- package/dist/docs/observability/{11-otel.md → 13-otel.md} +12 -7
- package/dist/docs/observability/{13-reference.md → 15-reference.md} +125 -1
- package/dist/docs/processors/01-reference.md +23 -0
- package/dist/docs/rag/01-overview.md +1 -1
- package/dist/docs/rag/02-chunking-and-embedding.md +0 -1
- package/dist/docs/rag/03-vector-databases.md +10 -5
- package/dist/docs/rag/04-retrieval.md +5 -6
- package/dist/docs/rag/06-reference.md +4 -5
- package/dist/docs/server/01-mastra-server.md +32 -49
- package/dist/docs/server/02-custom-adapters.md +5 -2
- package/dist/docs/server/04-request-context.md +50 -11
- package/dist/docs/server/05-custom-api-routes.md +1 -1
- package/dist/docs/server/06-mastra-client.md +2 -2
- package/dist/docs/storage/01-reference.md +99 -23
- package/dist/docs/streaming/04-reference.md +6 -1
- package/dist/docs/tools/01-reference.md +380 -25
- package/dist/docs/tools-mcp/01-mcp-overview.md +10 -2
- package/dist/docs/tools-mcp/02-overview.md +4 -4
- package/dist/docs/vectors/01-reference.md +24 -11
- package/dist/docs/voice/01-overview.md +2 -2
- package/dist/docs/voice/05-reference.md +2 -2
- package/dist/docs/workflows/01-overview.md +5 -5
- package/dist/docs/workflows/04-agents-and-tools.md +4 -6
- package/dist/docs/workflows/06-suspend-and-resume.md +5 -7
- package/dist/docs/workflows/11-reference.md +1 -91
- package/dist/evals/base.d.ts.map +1 -1
- package/dist/evals/index.cjs +20 -20
- package/dist/evals/index.js +3 -3
- package/dist/evals/scoreTraces/index.cjs +5 -5
- package/dist/evals/scoreTraces/index.js +2 -2
- package/dist/evals/scoreTraces/scoreTracesWorkflow.d.ts +4 -67
- package/dist/evals/scoreTraces/scoreTracesWorkflow.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 +9 -9
- package/dist/llm/index.js +2 -2
- package/dist/llm/model/model.loop.d.ts +1 -2
- package/dist/llm/model/model.loop.d.ts.map +1 -1
- package/dist/llm/model/model.loop.types.d.ts +1 -2
- package/dist/llm/model/model.loop.types.d.ts.map +1 -1
- package/dist/llm/model/provider-types.generated.d.ts +224 -18
- package/dist/loop/index.cjs +12 -12
- package/dist/loop/index.js +1 -1
- package/dist/loop/loop.d.ts +1 -2
- package/dist/loop/loop.d.ts.map +1 -1
- package/dist/loop/network/index.d.ts +21 -80
- package/dist/loop/network/index.d.ts.map +1 -1
- package/dist/loop/network/run-command-tool.d.ts +14 -11
- package/dist/loop/network/run-command-tool.d.ts.map +1 -1
- package/dist/loop/network/validation.d.ts +3 -4
- package/dist/loop/network/validation.d.ts.map +1 -1
- package/dist/loop/test-utils/options.d.ts.map +1 -1
- package/dist/loop/types.d.ts +4 -5
- package/dist/loop/types.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/index.d.ts +31 -804
- package/dist/loop/workflows/agentic-execution/index.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts +22 -539
- 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 +13 -294
- 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 +2 -41
- package/dist/loop/workflows/agentic-execution/tool-call-step.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-loop/index.d.ts +32 -805
- package/dist/loop/workflows/agentic-loop/index.d.ts.map +1 -1
- package/dist/loop/workflows/schema.d.ts +90 -91
- package/dist/loop/workflows/schema.d.ts.map +1 -1
- package/dist/loop/workflows/stream.d.ts +1 -2
- package/dist/loop/workflows/stream.d.ts.map +1 -1
- package/dist/mastra/index.cjs +2 -2
- package/dist/mastra/index.d.ts +28 -9
- package/dist/mastra/index.d.ts.map +1 -1
- package/dist/mastra/index.js +1 -1
- package/dist/memory/index.cjs +11 -11
- package/dist/memory/index.js +1 -1
- package/dist/memory/memory.d.ts +4 -2
- package/dist/memory/memory.d.ts.map +1 -1
- package/dist/observability/index.cjs +11 -11
- package/dist/observability/index.js +1 -1
- package/dist/observability/types/tracing.d.ts +45 -7
- package/dist/observability/types/tracing.d.ts.map +1 -1
- package/dist/processors/index.cjs +38 -38
- package/dist/processors/index.d.ts +3 -3
- package/dist/processors/index.d.ts.map +1 -1
- package/dist/processors/index.js +1 -1
- package/dist/processors/memory/semantic-recall.d.ts +2 -0
- package/dist/processors/memory/semantic-recall.d.ts.map +1 -1
- package/dist/processors/processors/structured-output.d.ts +2 -2
- package/dist/processors/processors/structured-output.d.ts.map +1 -1
- package/dist/processors/processors/token-limiter.d.ts +16 -10
- package/dist/processors/processors/token-limiter.d.ts.map +1 -1
- package/dist/processors/runner.d.ts +4 -4
- package/dist/processors/runner.d.ts.map +1 -1
- package/dist/processors/step-schema.d.ts +66 -67
- package/dist/processors/step-schema.d.ts.map +1 -1
- package/dist/provider-registry-C3IAGLLU.js +3 -0
- package/dist/{provider-registry-6DWM3X3I.js.map → provider-registry-C3IAGLLU.js.map} +1 -1
- package/dist/provider-registry-YH4FCTT2.cjs +40 -0
- package/dist/{provider-registry-DCECMUCQ.cjs.map → provider-registry-YH4FCTT2.cjs.map} +1 -1
- package/dist/provider-registry.json +477 -45
- package/dist/relevance/index.cjs +3 -3
- package/dist/relevance/index.js +1 -1
- package/dist/request-context/index.cjs +4 -4
- package/dist/request-context/index.d.ts +10 -9
- package/dist/request-context/index.d.ts.map +1 -1
- package/dist/request-context/index.js +1 -1
- package/dist/server/types.d.ts +1 -1
- package/dist/storage/constants.cjs +14 -14
- package/dist/storage/constants.d.ts +1 -1
- package/dist/storage/constants.js +1 -1
- package/dist/storage/domains/observability/types.d.ts +90 -90
- package/dist/storage/domains/workflows/inmemory.d.ts.map +1 -1
- package/dist/storage/index.cjs +93 -93
- package/dist/storage/index.js +2 -2
- package/dist/stream/MastraAgentNetworkStream.d.ts +8 -12
- package/dist/stream/MastraAgentNetworkStream.d.ts.map +1 -1
- package/dist/stream/aisdk/v5/compat/prepare-tools.d.ts.map +1 -1
- package/dist/stream/aisdk/v5/execute.d.ts +2 -3
- package/dist/stream/aisdk/v5/execute.d.ts.map +1 -1
- package/dist/stream/aisdk/v5/transform.d.ts +2 -3
- package/dist/stream/aisdk/v5/transform.d.ts.map +1 -1
- package/dist/stream/base/output-format-handlers.d.ts +2 -2
- package/dist/stream/base/output-format-handlers.d.ts.map +1 -1
- package/dist/stream/base/output.d.ts +76 -50
- package/dist/stream/base/output.d.ts.map +1 -1
- package/dist/stream/base/schema.d.ts +7 -2
- package/dist/stream/base/schema.d.ts.map +1 -1
- package/dist/stream/index.cjs +11 -15
- 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 +72 -26
- package/dist/stream/types.d.ts.map +1 -1
- package/dist/test-utils/llm-mock.cjs +4 -4
- package/dist/test-utils/llm-mock.js +1 -1
- package/dist/tool-loop-agent/index.cjs +4 -4
- package/dist/tool-loop-agent/index.d.ts +1 -1
- package/dist/tool-loop-agent/index.d.ts.map +1 -1
- package/dist/tool-loop-agent/index.js +1 -1
- package/dist/tool-loop-agent/tool-loop-processor.d.ts +1 -2
- package/dist/tool-loop-agent/tool-loop-processor.d.ts.map +1 -1
- package/dist/tools/index.cjs +4 -4
- package/dist/tools/index.js +1 -1
- package/dist/tools/is-vercel-tool.cjs +2 -2
- package/dist/tools/is-vercel-tool.js +1 -1
- package/dist/tools/tool-builder/builder.d.ts.map +1 -1
- package/dist/tools/tool.d.ts +27 -14
- package/dist/tools/tool.d.ts.map +1 -1
- package/dist/tools/types.d.ts +76 -20
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/tools/ui-types.d.ts +3 -4
- package/dist/tools/ui-types.d.ts.map +1 -1
- package/dist/tools/validation.d.ts +4 -4
- package/dist/tools/validation.d.ts.map +1 -1
- package/dist/types/dynamic-argument.d.ts +61 -1
- package/dist/types/dynamic-argument.d.ts.map +1 -1
- package/dist/types/zod-compat.d.ts +3 -11
- package/dist/types/zod-compat.d.ts.map +1 -1
- package/dist/utils.cjs +22 -22
- package/dist/utils.d.ts +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +1 -1
- package/dist/vector/index.cjs +2 -2
- package/dist/vector/index.js +1 -1
- package/dist/voice/index.cjs +6 -6
- package/dist/voice/index.js +1 -1
- package/dist/workflows/default.d.ts +114 -2
- package/dist/workflows/default.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.map +1 -1
- package/dist/workflows/evented/workflow-event-processor/utils.d.ts +1 -1
- package/dist/workflows/evented/workflow.d.ts +74 -21
- package/dist/workflows/evented/workflow.d.ts.map +1 -1
- package/dist/workflows/handlers/control-flow.d.ts +2 -2
- package/dist/workflows/handlers/control-flow.d.ts.map +1 -1
- package/dist/workflows/handlers/sleep.d.ts.map +1 -1
- package/dist/workflows/handlers/step.d.ts +1 -1
- package/dist/workflows/handlers/step.d.ts.map +1 -1
- package/dist/workflows/index.cjs +23 -23
- package/dist/workflows/index.js +1 -1
- package/dist/workflows/step.d.ts +28 -24
- package/dist/workflows/step.d.ts.map +1 -1
- package/dist/workflows/types.d.ts +91 -54
- package/dist/workflows/types.d.ts.map +1 -1
- package/dist/workflows/workflow.d.ts +165 -118
- package/dist/workflows/workflow.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/llm/model/provider-types.generated.d.ts +224 -18
- package/dist/chunk-3CZ42NBZ.js.map +0 -1
- package/dist/chunk-3RFSIHFR.js.map +0 -1
- package/dist/chunk-6TBWJV35.js.map +0 -1
- package/dist/chunk-A4MCHA5L.cjs.map +0 -1
- package/dist/chunk-AHN7K3VE.js.map +0 -1
- package/dist/chunk-AW7FISLD.cjs.map +0 -1
- package/dist/chunk-CISH55FP.js.map +0 -1
- package/dist/chunk-IC2MIQBW.js.map +0 -1
- package/dist/chunk-JMAPJWVG.cjs.map +0 -1
- package/dist/chunk-KGE3KAM7.js.map +0 -1
- package/dist/chunk-O4H44CMA.js.map +0 -1
- package/dist/chunk-O5IPTMEH.cjs.map +0 -1
- package/dist/chunk-PC3FBUWH.js.map +0 -1
- package/dist/chunk-SOSXN7X4.cjs.map +0 -1
- package/dist/chunk-UOZ3GJY2.cjs.map +0 -1
- package/dist/chunk-UVHSM2GU.cjs.map +0 -1
- package/dist/chunk-UXLQEGIN.cjs.map +0 -1
- package/dist/chunk-W7R7GPNN.cjs.map +0 -1
- package/dist/chunk-WMJEP45F.cjs.map +0 -1
- package/dist/chunk-XBZWAUZ3.js.map +0 -1
- package/dist/chunk-XKDVT3ZH.cjs.map +0 -1
- package/dist/chunk-XSJNTLM7.js.map +0 -1
- package/dist/provider-registry-6DWM3X3I.js +0 -3
- package/dist/provider-registry-DCECMUCQ.cjs +0 -40
- package/dist/stream/aisdk/v5/output.d.ts +0 -121
- package/dist/stream/aisdk/v5/output.d.ts.map +0 -1
- /package/dist/docs/agents/{09-adding-voice.md → 10-adding-voice.md} +0 -0
- /package/dist/docs/observability/{09-langfuse.md → 11-langfuse.md} +0 -0
- /package/dist/docs/observability/{10-langsmith.md → 12-langsmith.md} +0 -0
- /package/dist/docs/observability/{12-posthog.md → 14-posthog.md} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Observability API Reference
|
|
2
2
|
|
|
3
|
-
> API reference for observability -
|
|
3
|
+
> API reference for observability - 8 entries
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
---
|
|
@@ -144,6 +144,118 @@ This format ensures compatibility with all OTEL-compatible backends and collecto
|
|
|
144
144
|
|
|
145
145
|
---
|
|
146
146
|
|
|
147
|
+
## Reference: DatadogExporter
|
|
148
|
+
|
|
149
|
+
> Datadog LLM Observability exporter for Tracing
|
|
150
|
+
|
|
151
|
+
Sends Tracing data to Datadog's LLM Observability product for monitoring and analytics.
|
|
152
|
+
|
|
153
|
+
## Constructor
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
new DatadogExporter(config: DatadogExporterConfig)
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## DatadogExporterConfig
|
|
160
|
+
|
|
161
|
+
```typescript
|
|
162
|
+
interface DatadogExporterConfig extends BaseExporterConfig {
|
|
163
|
+
apiKey?: string;
|
|
164
|
+
mlApp?: string;
|
|
165
|
+
site?: string;
|
|
166
|
+
service?: string;
|
|
167
|
+
env?: string;
|
|
168
|
+
agentless?: boolean;
|
|
169
|
+
integrationsEnabled?: boolean;
|
|
170
|
+
}
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
Extends `BaseExporterConfig`, which includes:
|
|
174
|
+
- `logger?: IMastraLogger` - Logger instance
|
|
175
|
+
- `logLevel?: LogLevel | 'debug' | 'info' | 'warn' | 'error'` - Log level (default: INFO)
|
|
176
|
+
|
|
177
|
+
## Methods
|
|
178
|
+
|
|
179
|
+
### exportTracingEvent
|
|
180
|
+
|
|
181
|
+
```typescript
|
|
182
|
+
async exportTracingEvent(event: TracingEvent): Promise<void>
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
Exports a tracing event to Datadog LLM Observability.
|
|
186
|
+
|
|
187
|
+
### shutdown
|
|
188
|
+
|
|
189
|
+
```typescript
|
|
190
|
+
async shutdown(): Promise<void>
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
Flushes pending data and shuts down the exporter. Cancels any pending cleanup timers and disables LLM Observability.
|
|
194
|
+
|
|
195
|
+
## Usage
|
|
196
|
+
|
|
197
|
+
### Zero-Config (using environment variables)
|
|
198
|
+
|
|
199
|
+
```typescript
|
|
200
|
+
import { DatadogExporter } from "@mastra/datadog";
|
|
201
|
+
|
|
202
|
+
// Reads from DD_LLMOBS_ML_APP, DD_API_KEY, DD_SITE, DD_ENV
|
|
203
|
+
const exporter = new DatadogExporter();
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### Explicit Configuration
|
|
207
|
+
|
|
208
|
+
```typescript
|
|
209
|
+
import { DatadogExporter } from "@mastra/datadog";
|
|
210
|
+
|
|
211
|
+
const exporter = new DatadogExporter({
|
|
212
|
+
mlApp: "my-llm-app",
|
|
213
|
+
apiKey: process.env.DD_API_KEY,
|
|
214
|
+
site: "datadoghq.com",
|
|
215
|
+
env: "production",
|
|
216
|
+
});
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### With Local Datadog Agent
|
|
220
|
+
|
|
221
|
+
```typescript
|
|
222
|
+
const exporter = new DatadogExporter({
|
|
223
|
+
mlApp: "my-llm-app",
|
|
224
|
+
agentless: false, // Use local Datadog Agent
|
|
225
|
+
env: "production",
|
|
226
|
+
});
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
## Span Mapping
|
|
230
|
+
|
|
231
|
+
Mastra span types are mapped to Datadog LLMObs span kinds:
|
|
232
|
+
|
|
233
|
+
| Mastra SpanType | Datadog Kind |
|
|
234
|
+
|-----------------|--------------|
|
|
235
|
+
| `AGENT_RUN` | `agent` |
|
|
236
|
+
| `MODEL_GENERATION` | `workflow` |
|
|
237
|
+
| `MODEL_STEP` | `llm` |
|
|
238
|
+
| `TOOL_CALL` | `tool` |
|
|
239
|
+
| `MCP_TOOL_CALL` | `tool` |
|
|
240
|
+
| `WORKFLOW_RUN` | `workflow` |
|
|
241
|
+
| All other types | `task` |
|
|
242
|
+
|
|
243
|
+
All unmapped span types (including `MODEL_CHUNK`, `WORKFLOW_STEP`, `GENERIC`, and future span types) automatically default to `task`.
|
|
244
|
+
|
|
245
|
+
## Environment Variables
|
|
246
|
+
|
|
247
|
+
The exporter reads configuration from these environment variables:
|
|
248
|
+
|
|
249
|
+
| Variable | Description |
|
|
250
|
+
|----------|-------------|
|
|
251
|
+
| `DD_API_KEY` | Datadog API key |
|
|
252
|
+
| `DD_LLMOBS_ML_APP` | ML application name |
|
|
253
|
+
| `DD_SITE` | Datadog site |
|
|
254
|
+
| `DD_ENV` | Environment name |
|
|
255
|
+
| `DD_LLMOBS_AGENTLESS_ENABLED` | Set to 'false' or '0' to use local agent |
|
|
256
|
+
|
|
257
|
+
---
|
|
258
|
+
|
|
147
259
|
## Reference: SensitiveDataFilter
|
|
148
260
|
|
|
149
261
|
> API reference for the SensitiveDataFilter processor
|
|
@@ -1305,6 +1417,18 @@ interface TracingOptions {
|
|
|
1305
1417
|
* Note: Tags are only applied to the root span of a trace.
|
|
1306
1418
|
*/
|
|
1307
1419
|
tags?: string[];
|
|
1420
|
+
|
|
1421
|
+
/**
|
|
1422
|
+
* When true, input data will be hidden from all spans in this trace.
|
|
1423
|
+
* Useful for protecting sensitive data from being logged.
|
|
1424
|
+
*/
|
|
1425
|
+
hideInput?: boolean;
|
|
1426
|
+
|
|
1427
|
+
/**
|
|
1428
|
+
* When true, output data will be hidden from all spans in this trace.
|
|
1429
|
+
* Useful for protecting sensitive data from being logged.
|
|
1430
|
+
*/
|
|
1431
|
+
hideOutput?: boolean;
|
|
1308
1432
|
}
|
|
1309
1433
|
```
|
|
1310
1434
|
|
|
@@ -87,6 +87,7 @@ import { Agent } from "@mastra/core/agent";
|
|
|
87
87
|
import { LanguageDetector } from "@mastra/core/processors";
|
|
88
88
|
|
|
89
89
|
export const agent = new Agent({
|
|
90
|
+
id: "multilingual-agent",
|
|
90
91
|
name: "multilingual-agent",
|
|
91
92
|
instructions: "You are a helpful assistant",
|
|
92
93
|
model: "openai/gpt-5.1",
|
|
@@ -827,6 +828,25 @@ const processor = new TokenLimiterProcessor({
|
|
|
827
828
|
|
|
828
829
|
## Returns
|
|
829
830
|
|
|
831
|
+
## Error behavior
|
|
832
|
+
|
|
833
|
+
When used as an input processor, `TokenLimiterProcessor` throws a `TripWire` error in the following cases:
|
|
834
|
+
|
|
835
|
+
- **Empty messages**: If there are no messages to process, a TripWire is thrown because you cannot send an LLM request with no messages.
|
|
836
|
+
- **System messages exceed limit**: If system messages alone exceed the token limit, a TripWire is thrown because you cannot send an LLM request with only system messages and no user/assistant messages.
|
|
837
|
+
|
|
838
|
+
```typescript
|
|
839
|
+
import { TripWire } from "@mastra/core/agent";
|
|
840
|
+
|
|
841
|
+
try {
|
|
842
|
+
await agent.generate("Hello");
|
|
843
|
+
} catch (error) {
|
|
844
|
+
if (error instanceof TripWire) {
|
|
845
|
+
console.log("Token limit error:", error.message);
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
```
|
|
849
|
+
|
|
830
850
|
## Extended usage example
|
|
831
851
|
|
|
832
852
|
### As an input processor (limit context window)
|
|
@@ -907,6 +927,7 @@ import { Agent } from "@mastra/core/agent";
|
|
|
907
927
|
import { UnicodeNormalizer } from "@mastra/core/processors";
|
|
908
928
|
|
|
909
929
|
export const agent = new Agent({
|
|
930
|
+
id: "normalized-agent",
|
|
910
931
|
name: "normalized-agent",
|
|
911
932
|
instructions: "You are a helpful assistant",
|
|
912
933
|
model: "openai/gpt-5.1",
|
|
@@ -1039,10 +1060,12 @@ import { PgVector } from "@mastra/pg";
|
|
|
1039
1060
|
import { openai } from "@ai-sdk/openai";
|
|
1040
1061
|
|
|
1041
1062
|
const storage = new PostgresStorage({
|
|
1063
|
+
id: 'pg-storage',
|
|
1042
1064
|
connectionString: process.env.DATABASE_URL,
|
|
1043
1065
|
});
|
|
1044
1066
|
|
|
1045
1067
|
const vector = new PgVector({
|
|
1068
|
+
id: 'pg-vector',
|
|
1046
1069
|
connectionString: process.env.DATABASE_URL,
|
|
1047
1070
|
});
|
|
1048
1071
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
> Overview of Retrieval-Augmented Generation (RAG) in Mastra, detailing its capabilities for enhancing LLM outputs with relevant context.
|
|
2
2
|
|
|
3
3
|
> **Code References:**
|
|
4
|
-
- `ModelRouterEmbeddingModel`: dist/llm/index.d.ts → dist/chunk-
|
|
4
|
+
- `ModelRouterEmbeddingModel`: dist/llm/index.d.ts → dist/chunk-YYNZEEOO.js:4790
|
|
5
5
|
|
|
6
6
|
# RAG (Retrieval-Augmented Generation) in Mastra
|
|
7
7
|
|
|
@@ -12,6 +12,7 @@ After generating embeddings, you need to store them in a database that supports
|
|
|
12
12
|
import { MongoDBVector } from "@mastra/mongodb";
|
|
13
13
|
|
|
14
14
|
const store = new MongoDBVector({
|
|
15
|
+
id: 'mongodb-vector',
|
|
15
16
|
uri: process.env.MONGODB_URI,
|
|
16
17
|
dbName: process.env.MONGODB_DATABASE,
|
|
17
18
|
});
|
|
@@ -144,6 +145,7 @@ await store.upsert({
|
|
|
144
145
|
import { AstraVector } from "@mastra/astra";
|
|
145
146
|
|
|
146
147
|
const store = new AstraVector({
|
|
148
|
+
id: 'astra-vector',
|
|
147
149
|
token: process.env.ASTRA_DB_TOKEN,
|
|
148
150
|
endpoint: process.env.ASTRA_DB_ENDPOINT,
|
|
149
151
|
keyspace: process.env.ASTRA_DB_KEYSPACE,
|
|
@@ -170,7 +172,7 @@ import { LibSQLVector } from "@mastra/core/vector/libsql";
|
|
|
170
172
|
|
|
171
173
|
const store = new LibSQLVector({
|
|
172
174
|
id: 'libsql-vector',
|
|
173
|
-
|
|
175
|
+
url: process.env.DATABASE_URL,
|
|
174
176
|
authToken: process.env.DATABASE_AUTH_TOKEN, // Optional: for Turso cloud databases
|
|
175
177
|
});
|
|
176
178
|
|
|
@@ -217,6 +219,7 @@ await store.upsert({
|
|
|
217
219
|
import { CloudflareVector } from "@mastra/vectorize";
|
|
218
220
|
|
|
219
221
|
const store = new CloudflareVector({
|
|
222
|
+
id: 'cloudflare-vector',
|
|
220
223
|
accountId: process.env.CF_ACCOUNT_ID,
|
|
221
224
|
apiToken: process.env.CF_API_TOKEN,
|
|
222
225
|
});
|
|
@@ -238,7 +241,7 @@ await store.upsert({
|
|
|
238
241
|
```ts title="vector-store.ts"
|
|
239
242
|
import { OpenSearchVector } from "@mastra/opensearch";
|
|
240
243
|
|
|
241
|
-
const store = new OpenSearchVector({
|
|
244
|
+
const store = new OpenSearchVector({ id: "opensearch", node: process.env.OPENSEARCH_URL });
|
|
242
245
|
|
|
243
246
|
await store.createIndex({
|
|
244
247
|
indexName: "my-collection",
|
|
@@ -259,7 +262,7 @@ await store.upsert({
|
|
|
259
262
|
```ts title="vector-store.ts"
|
|
260
263
|
import { ElasticSearchVector } from "@mastra/elasticsearch";
|
|
261
264
|
|
|
262
|
-
const store = new ElasticSearchVector({ url: process.env.ELASTICSEARCH_URL });
|
|
265
|
+
const store = new ElasticSearchVector({ id: 'elasticsearch-vector', url: process.env.ELASTICSEARCH_URL });
|
|
263
266
|
|
|
264
267
|
await store.createIndex({
|
|
265
268
|
indexName: "my-collection",
|
|
@@ -280,6 +283,7 @@ await store.upsert({
|
|
|
280
283
|
import { CouchbaseVector } from "@mastra/couchbase";
|
|
281
284
|
|
|
282
285
|
const store = new CouchbaseVector({
|
|
286
|
+
id: 'couchbase-vector',
|
|
283
287
|
connectionString: process.env.COUCHBASE_CONNECTION_STRING,
|
|
284
288
|
username: process.env.COUCHBASE_USERNAME,
|
|
285
289
|
password: process.env.COUCHBASE_PASSWORD,
|
|
@@ -331,6 +335,7 @@ For detailed setup instructions and best practices, see the [official LanceDB do
|
|
|
331
335
|
import { S3Vectors } from "@mastra/s3vectors";
|
|
332
336
|
|
|
333
337
|
const store = new S3Vectors({
|
|
338
|
+
id: 's3-vectors',
|
|
334
339
|
vectorBucketName: "my-vector-bucket",
|
|
335
340
|
clientConfig: {
|
|
336
341
|
region: "us-east-1",
|
|
@@ -373,7 +378,7 @@ The dimension size must match the output dimension of your chosen embedding mode
|
|
|
373
378
|
- Cohere embed-multilingual-v3: 1024 dimensions
|
|
374
379
|
- Google text-embedding-004: 768 dimensions (or custom)
|
|
375
380
|
|
|
376
|
-
|
|
381
|
+
> **Note:**
|
|
377
382
|
Index dimensions cannot be changed after creation. To use a different model, delete and recreate the index with the new dimension size.
|
|
378
383
|
|
|
379
384
|
### Naming Rules for Databases
|
|
@@ -537,7 +542,7 @@ The upsert operation:
|
|
|
537
542
|
|
|
538
543
|
Vector stores support rich metadata (any JSON-serializable fields) for filtering and organization. Since metadata is stored with no fixed schema, use consistent field naming to avoid unexpected query results.
|
|
539
544
|
|
|
540
|
-
|
|
545
|
+
> **Note:**
|
|
541
546
|
Metadata is crucial for vector storage - without it, you'd only have numerical embeddings with no way to return the original text or filter results. Always store at least the source text as metadata.
|
|
542
547
|
|
|
543
548
|
```ts
|
|
@@ -171,7 +171,7 @@ The Vector Query Tool supports database-specific configurations that enable you
|
|
|
171
171
|
> **Note:**
|
|
172
172
|
These configurations are for **query-time options** like namespaces, performance tuning, and filtering—not for database connection setup.
|
|
173
173
|
|
|
174
|
-
Connection credentials (URLs, auth tokens) are configured when you instantiate the vector store class (e.g., `new LibSQLVector({
|
|
174
|
+
Connection credentials (URLs, auth tokens) are configured when you instantiate the vector store class (e.g., `new LibSQLVector({ url: '...' })`).
|
|
175
175
|
|
|
176
176
|
```ts
|
|
177
177
|
import { createVectorQueryTool } from "@mastra/rag";
|
|
@@ -258,11 +258,10 @@ requestContext.set("databaseConfig", {
|
|
|
258
258
|
},
|
|
259
259
|
});
|
|
260
260
|
|
|
261
|
-
await pineconeQueryTool.execute(
|
|
262
|
-
|
|
263
|
-
mastra,
|
|
264
|
-
|
|
265
|
-
});
|
|
261
|
+
await pineconeQueryTool.execute(
|
|
262
|
+
{ queryText: "search query" },
|
|
263
|
+
{ mastra, requestContext }
|
|
264
|
+
);
|
|
266
265
|
```
|
|
267
266
|
|
|
268
267
|
For detailed configuration options and advanced usage, see the [Vector Query Tool Reference](https://mastra.ai/reference/v1/tools/vector-query-tool).
|
|
@@ -129,11 +129,10 @@ whereDocument: { "$contains": "API documentation" }
|
|
|
129
129
|
}
|
|
130
130
|
});
|
|
131
131
|
|
|
132
|
-
await vectorTool.execute(
|
|
133
|
-
|
|
134
|
-
mastra,
|
|
135
|
-
|
|
136
|
-
});
|
|
132
|
+
await vectorTool.execute(
|
|
133
|
+
{ queryText: 'search query' },
|
|
134
|
+
{ mastra, requestContext }
|
|
135
|
+
);
|
|
137
136
|
```
|
|
138
137
|
|
|
139
138
|
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
>
|
|
1
|
+
> Overview of the Mastra server, covering HTTP endpoints, middleware, authentication, and client integration.
|
|
2
2
|
|
|
3
|
-
# Server
|
|
3
|
+
# Server Overview
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Mastra runs as an HTTP server that exposes your agents, workflows, and other functionality as API endpoints. The server handles request routing, middleware execution, authentication, and streaming responses.
|
|
6
6
|
|
|
7
7
|
> **Note:**
|
|
8
8
|
|
|
9
|
-
This page covers the `server` configuration options passed to the `Mastra` constructor. For running Mastra with your own HTTP server (Hono, Express, etc.),
|
|
9
|
+
This page covers the [`server`](https://mastra.ai/reference/v1/configuration#server-options) configuration options passed to the `Mastra` constructor. For running Mastra with your own HTTP server (Hono, Express, etc.), visit [Server Adapters](https://mastra.ai/docs/v1/server/server-adapters).
|
|
10
10
|
|
|
11
11
|
## Server architecture
|
|
12
12
|
|
|
@@ -14,21 +14,15 @@ Mastra uses [Hono](https://hono.dev) as its underlying HTTP server framework. Wh
|
|
|
14
14
|
|
|
15
15
|
The server provides:
|
|
16
16
|
|
|
17
|
-
- API endpoints for all registered agents
|
|
18
|
-
- API
|
|
19
|
-
-
|
|
20
|
-
-
|
|
21
|
-
-
|
|
22
|
-
- Configuration of port
|
|
23
|
-
- Configuration of body limit
|
|
17
|
+
- API endpoints for all registered agents and workflows
|
|
18
|
+
- Custom API routes and middleware
|
|
19
|
+
- Authentication with multiple providers
|
|
20
|
+
- Request context for dynamic configuration
|
|
21
|
+
- Stream data redaction for secure responses
|
|
24
22
|
|
|
25
|
-
|
|
26
|
-
[Custom API Routes](https://mastra.ai/docs/v1/server/custom-api-routes) pages for details on
|
|
27
|
-
adding additional server behaviour.
|
|
23
|
+
## Configuration
|
|
28
24
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
You can configure server `port`, `host`, `studioBase`, and `timeout` in the Mastra instance.
|
|
25
|
+
Configure the server by passing a `server` object to the `Mastra` constructor:
|
|
32
26
|
|
|
33
27
|
```typescript title="src/mastra/index.ts"
|
|
34
28
|
import { Mastra } from "@mastra/core";
|
|
@@ -37,17 +31,33 @@ export const mastra = new Mastra({
|
|
|
37
31
|
server: {
|
|
38
32
|
port: 3000, // Defaults to 4111
|
|
39
33
|
host: "0.0.0.0", // Defaults to 'localhost'
|
|
40
|
-
studioBase: "/my-mastra-studio", // Sub-path for the studio (optional)
|
|
41
|
-
timeout: 10000, // Defaults to 3 * 60 * 1000 (3 minutes)
|
|
42
34
|
},
|
|
43
35
|
});
|
|
44
36
|
```
|
|
45
37
|
|
|
46
|
-
|
|
38
|
+
> **Note:**
|
|
39
|
+
|
|
40
|
+
Visit the [configuration reference](https://mastra.ai/reference/v1/configuration#server-options) for a full list of available server options.
|
|
41
|
+
|
|
42
|
+
## Server features
|
|
43
|
+
|
|
44
|
+
- **[Middleware](https://mastra.ai/docs/v1/server/middleware)**: Intercept requests for authentication, logging, CORS, or injecting request-specific context.
|
|
45
|
+
- **[Custom API Routes](https://mastra.ai/docs/v1/server/custom-api-routes)**: Extend the server with your own HTTP endpoints that have access to the Mastra instance.
|
|
46
|
+
- **[Request Context](https://mastra.ai/docs/v1/server/request-context)**: Pass request-specific values to agents, tools, and workflows based on runtime conditions.
|
|
47
|
+
- **[Server Adapters](https://mastra.ai/docs/v1/server/server-adapters)**: Run Mastra with Express, Hono, or your own HTTP server instead of the generated server.
|
|
48
|
+
- **[Custom Adapters](https://mastra.ai/docs/v1/server/custom-adapters)**: Build adapters for frameworks not officially supported.
|
|
49
|
+
- **[Mastra Client SDK](https://mastra.ai/docs/v1/server/mastra-client)**: Type-safe client for calling agents, workflows, and tools from browser or server environments.
|
|
50
|
+
- **[Authentication](https://mastra.ai/docs/v1/server/auth)**: Secure endpoints with JWT, Clerk, Supabase, Firebase, Auth0, or WorkOS.
|
|
51
|
+
|
|
52
|
+
## Stream data redaction
|
|
53
|
+
|
|
54
|
+
When streaming agent responses, the HTTP layer redacts system prompts, tool definitions, API keys, and similar data from each chunk before sending it to clients. This is enabled by default.
|
|
55
|
+
|
|
56
|
+
This behavior is only configurable by using [server adapters](https://mastra.ai/docs/v1/server/server-adapters#stream-data-redaction). For server adapters, stream data redaction is enabled by default, too.
|
|
47
57
|
|
|
48
58
|
## TypeScript configuration
|
|
49
59
|
|
|
50
|
-
Mastra requires `module` and `moduleResolution`
|
|
60
|
+
Mastra requires `module` and `moduleResolution` settings compatible with modern Node.js. Legacy options like `CommonJS` or `node` are not supported.
|
|
51
61
|
|
|
52
62
|
```json {4-5} title="tsconfig.json"
|
|
53
63
|
{
|
|
@@ -64,31 +74,4 @@ Mastra requires `module` and `moduleResolution` values that support modern Node.
|
|
|
64
74
|
},
|
|
65
75
|
"include": ["src/**/*"]
|
|
66
76
|
}
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
> This TypeScript configuration is optimized for Mastra projects, using modern module resolution and strict type checking.
|
|
70
|
-
|
|
71
|
-
## CORS configuration
|
|
72
|
-
|
|
73
|
-
Mastra allows you to configure CORS (Cross-Origin Resource Sharing) settings for your server.
|
|
74
|
-
|
|
75
|
-
```typescript title="src/mastra/index.ts"
|
|
76
|
-
import { Mastra } from "@mastra/core";
|
|
77
|
-
|
|
78
|
-
export const mastra = new Mastra({
|
|
79
|
-
server: {
|
|
80
|
-
cors: {
|
|
81
|
-
origin: ["https://example.com"], // Allow specific origins or '*' for all
|
|
82
|
-
allowMethods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"],
|
|
83
|
-
allowHeaders: ["Content-Type", "Authorization"],
|
|
84
|
-
credentials: false,
|
|
85
|
-
},
|
|
86
|
-
},
|
|
87
|
-
});
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
## Stream data redaction
|
|
91
|
-
|
|
92
|
-
When streaming agent responses, the HTTP streaming layer redacts system prompts, tool definitions, API keys, and similar data from each chunk before sending it to clients. This is enabled by default.
|
|
93
|
-
|
|
94
|
-
If you're using server adapters directly, you can configure redaction behavior. See [Stream data redaction](https://mastra.ai/docs/v1/server/server-adapters#stream-data-redaction) in the Server Adapters docs.
|
|
77
|
+
```
|
|
@@ -8,9 +8,12 @@ A custom adapter translates between Mastra's route definitions and your framewor
|
|
|
8
8
|
|
|
9
9
|
> **Note:**
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
Use any of these prebuilt server adapters:
|
|
12
|
+
|
|
12
13
|
- [@mastra/hono](https://mastra.ai/reference/v1/server/hono-adapter)
|
|
13
14
|
- [@mastra/express](https://mastra.ai/reference/v1/server/express-adapter)
|
|
15
|
+
- [@mastra/fastify](https://mastra.ai/reference/v1/server/fastify-adapter)
|
|
16
|
+
- [@mastra/koa](https://mastra.ai/reference/v1/server/koa-adapter)
|
|
14
17
|
|
|
15
18
|
## Abstract class
|
|
16
19
|
|
|
@@ -289,7 +292,7 @@ constructor(options: {
|
|
|
289
292
|
}
|
|
290
293
|
```
|
|
291
294
|
|
|
292
|
-
See [Server Adapters](https://mastra.ai/docs/v1/server/server-adapters
|
|
295
|
+
See [Server Adapters](https://mastra.ai/docs/v1/server/server-adapters) for full documentation on each option.
|
|
293
296
|
|
|
294
297
|
## Full example
|
|
295
298
|
|
|
@@ -6,7 +6,7 @@ Agents, tools, and workflows can all accept `RequestContext` as a parameter, mak
|
|
|
6
6
|
|
|
7
7
|
## When to use `RequestContext`
|
|
8
8
|
|
|
9
|
-
Use `RequestContext` when a primitive
|
|
9
|
+
Use `RequestContext` when a primitive's behavior should change based on runtime conditions. For example, you might switch models or storage backends based on user attributes, or adjust instructions and tool selection based on language.
|
|
10
10
|
|
|
11
11
|
> **Note:**
|
|
12
12
|
|
|
@@ -57,12 +57,10 @@ await run.resume({
|
|
|
57
57
|
requestContext,
|
|
58
58
|
});
|
|
59
59
|
|
|
60
|
-
await weatherTool.execute(
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
requestContext,
|
|
65
|
-
});
|
|
60
|
+
await weatherTool.execute(
|
|
61
|
+
{ location: "London" },
|
|
62
|
+
{ requestContext },
|
|
63
|
+
);
|
|
66
64
|
```
|
|
67
65
|
|
|
68
66
|
### Setting values based on request headers
|
|
@@ -152,7 +150,7 @@ Visit [createStep()](https://mastra.ai/reference/v1/workflows/step) for a full l
|
|
|
152
150
|
|
|
153
151
|
## Accessing values with tools
|
|
154
152
|
|
|
155
|
-
You can access the `requestContext` argument from a tool
|
|
153
|
+
You can access the `requestContext` argument from a tool's `execute` function. This function is `async`. Use the `.get()` method to read values from `requestContext`.
|
|
156
154
|
|
|
157
155
|
```typescript title="src/mastra/tools/weather-tool.ts"
|
|
158
156
|
export type UserTier = {
|
|
@@ -161,8 +159,8 @@ export type UserTier = {
|
|
|
161
159
|
|
|
162
160
|
export const weatherTool = createTool({
|
|
163
161
|
id: "weather-tool",
|
|
164
|
-
execute: async (
|
|
165
|
-
const userTier = requestContext
|
|
162
|
+
execute: async (inputData, context) => {
|
|
163
|
+
const userTier = context?.requestContext?.get("user-tier") as UserTier["user-tier"] | undefined;
|
|
166
164
|
|
|
167
165
|
if (userTier === "enterprise") {}
|
|
168
166
|
},
|
|
@@ -173,9 +171,50 @@ export const weatherTool = createTool({
|
|
|
173
171
|
|
|
174
172
|
Visit [createTool()](https://mastra.ai/reference/v1/tools/create-tool) for a full list of configuration options.
|
|
175
173
|
|
|
174
|
+
## TypeScript support
|
|
175
|
+
|
|
176
|
+
When you provide a type parameter to `RequestContext`, all methods are fully typed:
|
|
177
|
+
|
|
178
|
+
```typescript
|
|
179
|
+
import { RequestContext } from "@mastra/core/request-context";
|
|
180
|
+
|
|
181
|
+
type MyContext = {
|
|
182
|
+
userId: string;
|
|
183
|
+
maxTokens: number;
|
|
184
|
+
isPremium: boolean;
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
const ctx = new RequestContext<MyContext>();
|
|
188
|
+
|
|
189
|
+
// set() enforces correct value types
|
|
190
|
+
ctx.set("userId", "user-123"); // ✓ valid
|
|
191
|
+
ctx.set("maxTokens", 4096); // ✓ valid
|
|
192
|
+
ctx.set("maxTokens", "wrong"); // ✗ TypeScript error: expected number
|
|
193
|
+
|
|
194
|
+
// get() returns the correct type automatically
|
|
195
|
+
const tokens = ctx.get("maxTokens"); // inferred as number
|
|
196
|
+
const id = ctx.get("userId"); // inferred as string
|
|
197
|
+
|
|
198
|
+
// keys() returns typed keys
|
|
199
|
+
for (const key of ctx.keys()) {
|
|
200
|
+
// key is "userId" | "maxTokens" | "isPremium"
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// entries() supports type narrowing
|
|
204
|
+
for (const [key, value] of ctx.entries()) {
|
|
205
|
+
if (key === "maxTokens") {
|
|
206
|
+
// TypeScript knows value is number here
|
|
207
|
+
console.log(value.toFixed(2));
|
|
208
|
+
}
|
|
209
|
+
if (key === "userId") {
|
|
210
|
+
// TypeScript knows value is string here
|
|
211
|
+
console.log(value.toUpperCase());
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
```
|
|
215
|
+
|
|
176
216
|
## Related
|
|
177
217
|
|
|
178
218
|
- [Agent Request Context](https://mastra.ai/docs/v1/agents/overview#using-requestcontext)
|
|
179
219
|
- [Workflow Request Context](../workflows/overview#using-requestcontext)
|
|
180
|
-
- [Tool Request Context](../mcp/overview#using-requestcontext)
|
|
181
220
|
- [Server Middleware](https://mastra.ai/docs/v1/server/middleware)
|
|
@@ -17,7 +17,7 @@ export const mastra = new Mastra({
|
|
|
17
17
|
method: "GET",
|
|
18
18
|
handler: async (c) => {
|
|
19
19
|
const mastra = c.get("mastra");
|
|
20
|
-
const
|
|
20
|
+
const agent = await mastra.getAgent("my-agent");
|
|
21
21
|
|
|
22
22
|
return c.json({ message: "Custom route" });
|
|
23
23
|
},
|
|
@@ -102,7 +102,7 @@ const testAgent = async () => {
|
|
|
102
102
|
|
|
103
103
|
> **Note:**
|
|
104
104
|
|
|
105
|
-
Visit [.generate()](https://mastra.ai/reference/v1/client-js/agents#generate
|
|
105
|
+
Visit [.generate()](https://mastra.ai/reference/v1/client-js/agents#generate) for more information.
|
|
106
106
|
|
|
107
107
|
## Streaming responses
|
|
108
108
|
|
|
@@ -137,7 +137,7 @@ const testAgent = async () => {
|
|
|
137
137
|
|
|
138
138
|
> **Note:**
|
|
139
139
|
|
|
140
|
-
Visit [.stream()](https://mastra.ai/reference/v1/client-js/agents#stream
|
|
140
|
+
Visit [.stream()](https://mastra.ai/reference/v1/client-js/agents#stream) for more information.
|
|
141
141
|
|
|
142
142
|
## Configuration options
|
|
143
143
|
|